/**
 * Cloudflare D1 API
 *
 * Generated from Cloudflare TypeScript SDK.
 * DO NOT EDIT - regenerate with: bun scripts/generate.ts --service d1
 */
import * as Schema from "effect/Schema";
import * as API from "../client/api.js";
import * as T from "../traits.js";
import {} from "../errors.js";
// =============================================================================
// Errors
// =============================================================================
export class DatabaseAlreadyExists extends Schema.TaggedErrorClass()("DatabaseAlreadyExists", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(DatabaseAlreadyExists, [{ code: 7502 }]);
export class DatabaseNotFound extends Schema.TaggedErrorClass()("DatabaseNotFound", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(DatabaseNotFound, [{ code: 7404 }]);
export class InternalError extends Schema.TaggedErrorClass()("InternalError", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InternalError, [{ code: 7500 }]);
export class InvalidObjectIdentifier extends Schema.TaggedErrorClass()("InvalidObjectIdentifier", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidObjectIdentifier, [{ code: 7003 }]);
export class InvalidProperty extends Schema.TaggedErrorClass()("InvalidProperty", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidProperty, [{ code: 7400 }]);
export class InvalidRequest extends Schema.TaggedErrorClass()("InvalidRequest", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidRequest, [{ code: 7400 }]);
export class NoHistoryAvailable extends Schema.TaggedErrorClass()("NoHistoryAvailable", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(NoHistoryAvailable, [{ code: 7500 }]);
export class TimestampTooOld extends Schema.TaggedErrorClass()("TimestampTooOld", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(TimestampTooOld, [{ code: 7400 }]);
export class UnknownError extends Schema.TaggedErrorClass()("UnknownError", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(UnknownError, [{ code: 0 }]);
export const GetBookmarkDatabaseTimeTravelRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    timestamp: Schema.optional(Schema.String).pipe(T.HttpQuery("timestamp")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/d1/database/{databaseId}/time_travel/bookmark",
}));
export const GetBookmarkDatabaseTimeTravelResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    bookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
}).pipe(T.ResponsePath("result"));
export const getBookmarkDatabaseTimeTravel = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetBookmarkDatabaseTimeTravelRequest,
    output: GetBookmarkDatabaseTimeTravelResponse,
    errors: [
        InvalidObjectIdentifier,
        NoHistoryAvailable,
        TimestampTooOld,
        DatabaseNotFound,
    ],
}));
export const ListDatabasesRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    page: Schema.optional(Schema.Number).pipe(T.HttpQuery("page")),
    perPage: Schema.optional(Schema.Number).pipe(T.HttpQuery("per_page")),
    name: Schema.optional(Schema.String).pipe(T.HttpQuery("name")),
}).pipe(T.Http({ method: "GET", path: "/accounts/{account_id}/d1/database" }));
export const ListDatabasesResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    result: Schema.Array(Schema.Struct({
        createdAt: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
        name: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
        uuid: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
        version: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    }).pipe(Schema.encodeKeys({
        createdAt: "created_at",
        name: "name",
        uuid: "uuid",
        version: "version",
    }))),
    resultInfo: Schema.optional(Schema.Union([
        Schema.Struct({
            count: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
            page: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
            perPage: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
            totalCount: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
        }).pipe(Schema.encodeKeys({
            count: "count",
            page: "page",
            perPage: "per_page",
            totalCount: "total_count",
        })),
        Schema.Null,
    ])),
}).pipe(Schema.encodeKeys({ result: "result", resultInfo: "result_info" }));
export const listDatabases = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListDatabasesRequest,
    output: ListDatabasesResponse,
    errors: [],
    pagination: {
        mode: "page",
        inputToken: "page",
        outputToken: "resultInfo.page",
        items: "result",
        pageSize: "perPage",
    },
}));
export const GetDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/d1/database/{databaseId}",
}));
export const GetDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    createdAt: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    fileSize: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    name: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    numTables: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    readReplication: Schema.optional(Schema.Union([
        Schema.Struct({
            mode: Schema.Literals(["auto", "disabled"]),
        }),
        Schema.Null,
    ])),
    uuid: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    version: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    createdAt: "created_at",
    fileSize: "file_size",
    name: "name",
    numTables: "num_tables",
    readReplication: "read_replication",
    uuid: "uuid",
    version: "version",
}))
    .pipe(T.ResponsePath("result"));
export const getDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetDatabaseRequest,
    output: GetDatabaseResponse,
    errors: [InvalidObjectIdentifier, DatabaseNotFound, UnknownError],
}));
export const CreateDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    name: Schema.String,
    jurisdiction: Schema.optional(Schema.Literals(["eu", "fedramp"])),
    primaryLocationHint: Schema.optional(Schema.Literals(["wnam", "enam", "weur", "eeur", "apac", "oc"])),
}).pipe(Schema.encodeKeys({
    name: "name",
    jurisdiction: "jurisdiction",
    primaryLocationHint: "primary_location_hint",
}), T.Http({ method: "POST", path: "/accounts/{account_id}/d1/database" }));
export const CreateDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    createdAt: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    fileSize: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    name: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    numTables: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    readReplication: Schema.optional(Schema.Union([
        Schema.Struct({
            mode: Schema.Literals(["auto", "disabled"]),
        }),
        Schema.Null,
    ])),
    uuid: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    version: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    createdAt: "created_at",
    fileSize: "file_size",
    name: "name",
    numTables: "num_tables",
    readReplication: "read_replication",
    uuid: "uuid",
    version: "version",
}))
    .pipe(T.ResponsePath("result"));
export const createDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: CreateDatabaseRequest,
    output: CreateDatabaseResponse,
    errors: [InvalidObjectIdentifier, InvalidProperty, DatabaseAlreadyExists],
}));
export const UpdateDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    readReplication: Schema.Struct({
        mode: Schema.Literals(["auto", "disabled"]),
    }),
}).pipe(Schema.encodeKeys({ readReplication: "read_replication" }), T.Http({
    method: "PUT",
    path: "/accounts/{account_id}/d1/database/{databaseId}",
}));
export const UpdateDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    createdAt: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    fileSize: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    name: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    numTables: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    readReplication: Schema.optional(Schema.Union([
        Schema.Struct({
            mode: Schema.Literals(["auto", "disabled"]),
        }),
        Schema.Null,
    ])),
    uuid: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    version: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    createdAt: "created_at",
    fileSize: "file_size",
    name: "name",
    numTables: "num_tables",
    readReplication: "read_replication",
    uuid: "uuid",
    version: "version",
}))
    .pipe(T.ResponsePath("result"));
export const updateDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: UpdateDatabaseRequest,
    output: UpdateDatabaseResponse,
    errors: [InvalidObjectIdentifier, InternalError, DatabaseNotFound],
}));
export const PatchDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    readReplication: Schema.optional(Schema.Struct({
        mode: Schema.Literals(["auto", "disabled"]),
    })),
}).pipe(Schema.encodeKeys({ readReplication: "read_replication" }), T.Http({
    method: "PATCH",
    path: "/accounts/{account_id}/d1/database/{databaseId}",
}));
export const PatchDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    createdAt: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    fileSize: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    name: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    numTables: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    readReplication: Schema.optional(Schema.Union([
        Schema.Struct({
            mode: Schema.Literals(["auto", "disabled"]),
        }),
        Schema.Null,
    ])),
    uuid: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    version: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    createdAt: "created_at",
    fileSize: "file_size",
    name: "name",
    numTables: "num_tables",
    readReplication: "read_replication",
    uuid: "uuid",
    version: "version",
}))
    .pipe(T.ResponsePath("result"));
export const patchDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: PatchDatabaseRequest,
    output: PatchDatabaseResponse,
    errors: [InvalidObjectIdentifier, InternalError, DatabaseNotFound],
}));
export const DeleteDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "DELETE",
    path: "/accounts/{account_id}/d1/database/{databaseId}",
}));
export const DeleteDatabaseResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Unknown.pipe(T.ResponsePath("result"));
export const deleteDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteDatabaseRequest,
    output: DeleteDatabaseResponse,
    errors: [InvalidObjectIdentifier, DatabaseNotFound, UnknownError],
}));
export const ExportDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    outputFormat: Schema.Literal("polling"),
    currentBookmark: Schema.optional(Schema.String),
    dumpOptions: Schema.optional(Schema.Struct({
        noData: Schema.optional(Schema.Boolean),
        noSchema: Schema.optional(Schema.Boolean),
        tables: Schema.optional(Schema.Array(Schema.String)),
    }).pipe(Schema.encodeKeys({
        noData: "no_data",
        noSchema: "no_schema",
        tables: "tables",
    }))),
}).pipe(Schema.encodeKeys({
    outputFormat: "output_format",
    currentBookmark: "current_bookmark",
    dumpOptions: "dump_options",
}), T.Http({
    method: "POST",
    path: "/accounts/{account_id}/d1/database/{databaseId}/export",
}));
export const ExportDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    atBookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    error: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    messages: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
    result: Schema.optional(Schema.Union([
        Schema.Struct({
            filename: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
            signedUrl: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
        }).pipe(Schema.encodeKeys({ filename: "filename", signedUrl: "signed_url" })),
        Schema.Null,
    ])),
    status: Schema.optional(Schema.Union([
        Schema.Literals(["complete", "error", "active"]),
        Schema.Null,
    ])),
    success: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
    type: Schema.optional(Schema.Union([Schema.Literal("export"), Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    atBookmark: "at_bookmark",
    error: "error",
    messages: "messages",
    result: "result",
    status: "status",
    success: "success",
    type: "type",
}))
    .pipe(T.ResponsePath("result"));
export const exportDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: ExportDatabaseRequest,
    output: ExportDatabaseResponse,
    errors: [InvalidObjectIdentifier, InvalidRequest, DatabaseNotFound],
}));
export const ImportDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    action: Schema.Literal("init"),
    etag: Schema.String,
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/d1/database/{databaseId}/import",
}));
export const ImportDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    atBookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    error: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    filename: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    messages: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
    result: Schema.optional(Schema.Union([
        Schema.Struct({
            finalBookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
            meta: Schema.optional(Schema.Union([
                Schema.Struct({
                    changedDb: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                    changes: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    duration: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    lastRowId: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    rowsRead: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    rowsWritten: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    servedByColo: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
                    servedByPrimary: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                    servedByRegion: Schema.optional(Schema.Union([
                        Schema.Literals([
                            "WNAM",
                            "ENAM",
                            "WEUR",
                            "EEUR",
                            "APAC",
                            "OC",
                        ]),
                        Schema.Null,
                    ])),
                    sizeAfter: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    timings: Schema.optional(Schema.Union([
                        Schema.Struct({
                            sqlDurationMs: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                        }).pipe(Schema.encodeKeys({ sqlDurationMs: "sql_duration_ms" })),
                        Schema.Null,
                    ])),
                }).pipe(Schema.encodeKeys({
                    changedDb: "changed_db",
                    changes: "changes",
                    duration: "duration",
                    lastRowId: "last_row_id",
                    rowsRead: "rows_read",
                    rowsWritten: "rows_written",
                    servedByColo: "served_by_colo",
                    servedByPrimary: "served_by_primary",
                    servedByRegion: "served_by_region",
                    sizeAfter: "size_after",
                    timings: "timings",
                })),
                Schema.Null,
            ])),
            numQueries: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
        }).pipe(Schema.encodeKeys({
            finalBookmark: "final_bookmark",
            meta: "meta",
            numQueries: "num_queries",
        })),
        Schema.Null,
    ])),
    status: Schema.optional(Schema.Union([Schema.Literals(["complete", "error"]), Schema.Null])),
    success: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
    type: Schema.optional(Schema.Union([Schema.Literal("import"), Schema.Null])),
    uploadUrl: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    atBookmark: "at_bookmark",
    error: "error",
    filename: "filename",
    messages: "messages",
    result: "result",
    status: "status",
    success: "success",
    type: "type",
    uploadUrl: "upload_url",
}))
    .pipe(T.ResponsePath("result"));
export const importDatabase = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: ImportDatabaseRequest,
    output: ImportDatabaseResponse,
    errors: [InvalidObjectIdentifier],
}));
export const QueryDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    sql: Schema.String,
    params: Schema.optional(Schema.Array(Schema.String)),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/d1/database/{databaseId}/query",
}));
export const QueryDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    result: Schema.Array(Schema.Struct({
        meta: Schema.optional(Schema.Union([
            Schema.Struct({
                changedDb: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                changes: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                duration: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                lastRowId: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                rowsRead: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                rowsWritten: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                servedByColo: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
                servedByPrimary: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                servedByRegion: Schema.optional(Schema.Union([
                    Schema.Literals(["WNAM", "ENAM", "WEUR", "EEUR", "APAC", "OC"]),
                    Schema.Null,
                ])),
                sizeAfter: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                timings: Schema.optional(Schema.Union([
                    Schema.Struct({
                        sqlDurationMs: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    }).pipe(Schema.encodeKeys({ sqlDurationMs: "sql_duration_ms" })),
                    Schema.Null,
                ])),
            }).pipe(Schema.encodeKeys({
                changedDb: "changed_db",
                changes: "changes",
                duration: "duration",
                lastRowId: "last_row_id",
                rowsRead: "rows_read",
                rowsWritten: "rows_written",
                servedByColo: "served_by_colo",
                servedByPrimary: "served_by_primary",
                servedByRegion: "served_by_region",
                sizeAfter: "size_after",
                timings: "timings",
            })),
            Schema.Null,
        ])),
        results: Schema.optional(Schema.Union([Schema.Array(Schema.Unknown), Schema.Null])),
        success: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
    })),
});
export const queryDatabase = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: QueryDatabaseRequest,
    output: QueryDatabaseResponse,
    errors: [],
    pagination: {
        mode: "single",
        items: "result",
    },
}));
export const RawDatabaseRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    sql: Schema.String,
    params: Schema.optional(Schema.Array(Schema.String)),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/d1/database/{databaseId}/raw",
}));
export const RawDatabaseResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    result: Schema.Array(Schema.Struct({
        meta: Schema.optional(Schema.Union([
            Schema.Struct({
                changedDb: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                changes: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                duration: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                lastRowId: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                rowsRead: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                rowsWritten: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                servedByColo: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
                servedByPrimary: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
                servedByRegion: Schema.optional(Schema.Union([
                    Schema.Literals(["WNAM", "ENAM", "WEUR", "EEUR", "APAC", "OC"]),
                    Schema.Null,
                ])),
                sizeAfter: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                timings: Schema.optional(Schema.Union([
                    Schema.Struct({
                        sqlDurationMs: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
                    }).pipe(Schema.encodeKeys({ sqlDurationMs: "sql_duration_ms" })),
                    Schema.Null,
                ])),
            }).pipe(Schema.encodeKeys({
                changedDb: "changed_db",
                changes: "changes",
                duration: "duration",
                lastRowId: "last_row_id",
                rowsRead: "rows_read",
                rowsWritten: "rows_written",
                servedByColo: "served_by_colo",
                servedByPrimary: "served_by_primary",
                servedByRegion: "served_by_region",
                sizeAfter: "size_after",
                timings: "timings",
            })),
            Schema.Null,
        ])),
        results: Schema.optional(Schema.Union([
            Schema.Struct({
                columns: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
                rows: Schema.optional(Schema.Union([
                    Schema.Array(Schema.Array(Schema.Union([Schema.Number, Schema.String]))),
                    Schema.Null,
                ])),
            }),
            Schema.Null,
        ])),
        success: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
    })),
});
export const rawDatabase = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: RawDatabaseRequest,
    output: RawDatabaseResponse,
    errors: [],
    pagination: {
        mode: "single",
        items: "result",
    },
}));
export const RestoreDatabaseTimeTravelRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    databaseId: Schema.String.pipe(T.HttpPath("databaseId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    bookmark: Schema.optional(Schema.String).pipe(T.HttpQuery("bookmark")),
    timestamp: Schema.optional(Schema.String).pipe(T.HttpQuery("timestamp")),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/d1/database/{databaseId}/time_travel/restore",
}));
export const RestoreDatabaseTimeTravelResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    bookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    message: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
    previousBookmark: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    bookmark: "bookmark",
    message: "message",
    previousBookmark: "previous_bookmark",
}))
    .pipe(T.ResponsePath("result"));
export const restoreDatabaseTimeTravel = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: RestoreDatabaseTimeTravelRequest,
    output: RestoreDatabaseTimeTravelResponse,
    errors: [
        InvalidObjectIdentifier,
        NoHistoryAvailable,
        DatabaseNotFound,
        InvalidProperty,
    ],
}));
//# sourceMappingURL=d1.js.map