/**
 * Cloudflare KV API
 *
 * Generated from Cloudflare TypeScript SDK.
 * DO NOT EDIT - regenerate with: bun scripts/generate.ts --service kv
 */
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 InvalidExpirationTtl extends Schema.TaggedErrorClass()("InvalidExpirationTtl", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidExpirationTtl, [{ code: 10034 }]);
export class InvalidObjectIdentifier extends Schema.TaggedErrorClass()("InvalidObjectIdentifier", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidObjectIdentifier, [{ code: 7003 }]);
export class InvalidRequestBody extends Schema.TaggedErrorClass()("InvalidRequestBody", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(InvalidRequestBody, [{ code: 10012 }]);
export class KeyNotFound extends Schema.TaggedErrorClass()("KeyNotFound", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(KeyNotFound, [{ code: 10009 }]);
export class MethodNotAllowed extends Schema.TaggedErrorClass()("MethodNotAllowed", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(MethodNotAllowed, [
    { code: 10405, message: { includes: "not allowed" } },
    { code: 10000, message: { includes: "not allowed" } },
]);
export class MinimumKeysRequired extends Schema.TaggedErrorClass()("MinimumKeysRequired", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(MinimumKeysRequired, [{ code: 10029 }]);
export class NamespaceNotFound extends Schema.TaggedErrorClass()("NamespaceNotFound", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(NamespaceNotFound, [{ code: 10013 }]);
export class NamespaceTitleAlreadyExists extends Schema.TaggedErrorClass()("NamespaceTitleAlreadyExists", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(NamespaceTitleAlreadyExists, [{ code: 10014 }]);
export class TitleRequired extends Schema.TaggedErrorClass()("TitleRequired", { code: Schema.Number, message: Schema.String }) {
}
T.applyErrorMatchers(TitleRequired, [{ code: 10019 }]);
export const GetNamespaceRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}",
}));
export const GetNamespaceResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    id: Schema.String,
    title: Schema.String,
    supportsUrlEncoding: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    id: "id",
    title: "title",
    supportsUrlEncoding: "supports_url_encoding",
}))
    .pipe(T.ResponsePath("result"));
export const getNamespace = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetNamespaceRequest,
    output: GetNamespaceResponse,
    errors: [NamespaceNotFound, InvalidObjectIdentifier],
}));
export const ListNamespacesRequest = /*@__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")),
    direction: Schema.optional(Schema.Literals(["asc", "desc"])).pipe(T.HttpQuery("direction")),
    order: Schema.optional(Schema.Literals(["id", "title"])).pipe(T.HttpQuery("order")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/storage/kv/namespaces",
}));
export const ListNamespacesResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    result: Schema.Array(Schema.Struct({
        id: Schema.String,
        title: Schema.String,
        supportsUrlEncoding: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
    }).pipe(Schema.encodeKeys({
        id: "id",
        title: "title",
        supportsUrlEncoding: "supports_url_encoding",
    }))),
    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 listNamespaces = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListNamespacesRequest,
    output: ListNamespacesResponse,
    errors: [],
    pagination: {
        mode: "page",
        inputToken: "page",
        outputToken: "resultInfo.page",
        items: "result",
        pageSize: "perPage",
    },
}));
export const CreateNamespaceRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    title: Schema.String,
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/storage/kv/namespaces",
}));
export const CreateNamespaceResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    id: Schema.String,
    title: Schema.String,
    supportsUrlEncoding: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    id: "id",
    title: "title",
    supportsUrlEncoding: "supports_url_encoding",
}))
    .pipe(T.ResponsePath("result"));
export const createNamespace = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: CreateNamespaceRequest,
    output: CreateNamespaceResponse,
    errors: [TitleRequired, InvalidObjectIdentifier, NamespaceTitleAlreadyExists],
}));
export const UpdateNamespaceRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    title: Schema.String,
}).pipe(T.Http({
    method: "PUT",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}",
}));
export const UpdateNamespaceResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    id: Schema.String,
    title: Schema.String,
    supportsUrlEncoding: Schema.optional(Schema.Union([Schema.Boolean, Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    id: "id",
    title: "title",
    supportsUrlEncoding: "supports_url_encoding",
}))
    .pipe(T.ResponsePath("result"));
export const updateNamespace = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: UpdateNamespaceRequest,
    output: UpdateNamespaceResponse,
    errors: [
        NamespaceNotFound,
        TitleRequired,
        InvalidObjectIdentifier,
        NamespaceTitleAlreadyExists,
    ],
}));
export const DeleteNamespaceRequest = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "DELETE",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}",
}));
export const DeleteNamespaceResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({}).pipe(T.ResponsePath("result"));
export const deleteNamespace = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteNamespaceRequest,
    output: DeleteNamespaceResponse,
    errors: [MethodNotAllowed, NamespaceNotFound, InvalidObjectIdentifier],
}));
export const BulkGetNamespacesRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    keys: Schema.Array(Schema.String),
    type: Schema.optional(Schema.Literals(["text", "json"])),
    withMetadata: Schema.optional(Schema.Boolean),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk/get",
}));
export const BulkGetNamespacesResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    values: Schema.optional(Schema.Union([Schema.Record(Schema.String, Schema.Unknown), Schema.Null])),
}).pipe(T.ResponsePath("result"));
export const bulkGetNamespaces = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkGetNamespacesRequest,
    output: BulkGetNamespacesResponse,
    errors: [
        InvalidRequestBody,
        MinimumKeysRequired,
        NamespaceNotFound,
        InvalidObjectIdentifier,
    ],
}));
export const BulkDeleteNamespacesRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    body: Schema.Array(Schema.String).pipe(T.HttpBody()),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk/delete",
}));
export const BulkDeleteNamespacesResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    successfulKeyCount: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    unsuccessfulKeys: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    successfulKeyCount: "successful_key_count",
    unsuccessfulKeys: "unsuccessful_keys",
}))
    .pipe(T.ResponsePath("result"));
export const bulkDeleteNamespaces = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkDeleteNamespacesRequest,
    output: BulkDeleteNamespacesResponse,
    errors: [NamespaceNotFound, InvalidRequestBody, InvalidObjectIdentifier],
}));
export const ListNamespaceKeysRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    cursor: Schema.optional(Schema.String).pipe(T.HttpQuery("cursor")),
    limit: Schema.optional(Schema.Number).pipe(T.HttpQuery("limit")),
    prefix: Schema.optional(Schema.String).pipe(T.HttpQuery("prefix")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/keys",
}));
export const ListNamespaceKeysResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    result: Schema.Array(Schema.Struct({
        name: Schema.String,
        expiration: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
        metadata: Schema.optional(Schema.Union([Schema.Unknown, Schema.Null])),
    })),
    resultInfo: Schema.optional(Schema.Union([
        Schema.Struct({
            cursors: Schema.optional(Schema.Union([
                Schema.Struct({
                    after: Schema.optional(Schema.Union([Schema.String, Schema.Null])),
                }),
                Schema.Null,
            ])),
        }),
        Schema.Null,
    ])),
}).pipe(Schema.encodeKeys({ result: "result", resultInfo: "result_info" }));
export const listNamespaceKeys = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListNamespaceKeysRequest,
    output: ListNamespaceKeysResponse,
    errors: [],
    pagination: {
        mode: "cursor",
        inputToken: "cursor",
        outputToken: "resultInfo.cursors.after",
        items: "result",
    },
}));
export const BulkGetNamespaceKeysRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    keys: Schema.Array(Schema.String),
    type: Schema.optional(Schema.Literals(["text", "json"])),
    withMetadata: Schema.optional(Schema.Boolean),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk/get",
}));
export const BulkGetNamespaceKeysResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    values: Schema.optional(Schema.Union([Schema.Record(Schema.String, Schema.Unknown), Schema.Null])),
}).pipe(T.ResponsePath("result"));
export const bulkGetNamespaceKeys = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkGetNamespaceKeysRequest,
    output: BulkGetNamespaceKeysResponse,
    errors: [InvalidRequestBody, NamespaceNotFound, InvalidObjectIdentifier],
}));
export const BulkDeleteNamespaceKeysRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    body: Schema.Array(Schema.String).pipe(T.HttpBody()),
}).pipe(T.Http({
    method: "POST",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk/delete",
}));
export const BulkDeleteNamespaceKeysResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    successfulKeyCount: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    unsuccessfulKeys: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    successfulKeyCount: "successful_key_count",
    unsuccessfulKeys: "unsuccessful_keys",
}))
    .pipe(T.ResponsePath("result"));
export const bulkDeleteNamespaceKeys = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkDeleteNamespaceKeysRequest,
    output: BulkDeleteNamespaceKeysResponse,
    errors: [NamespaceNotFound, InvalidRequestBody, InvalidObjectIdentifier],
}));
export const GetNamespaceMetadataRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    keyName: Schema.String.pipe(T.HttpPath("keyName")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/metadata/{keyName}",
}));
export const GetNamespaceMetadataResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Unknown.pipe(T.ResponsePath("result"));
export const getNamespaceMetadata = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetNamespaceMetadataRequest,
    output: GetNamespaceMetadataResponse,
    errors: [KeyNotFound, NamespaceNotFound, InvalidObjectIdentifier],
}));
export const GetNamespaceValueRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    keyName: Schema.String.pipe(T.HttpPath("keyName")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "GET",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/values/{keyName}",
}));
export const GetNamespaceValueResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Unknown;
export const getNamespaceValue = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetNamespaceValueRequest,
    output: GetNamespaceValueResponse,
    errors: [KeyNotFound, NamespaceNotFound, InvalidObjectIdentifier],
}));
export const PutNamespaceValueRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    keyName: Schema.String.pipe(T.HttpPath("keyName")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    expiration: Schema.optional(Schema.Number).pipe(T.HttpQuery("expiration")),
    expirationTtl: Schema.optional(Schema.Number).pipe(T.HttpQuery("expiration_ttl")),
    value: Schema.String,
    metadata: Schema.optional(Schema.Unknown),
}).pipe(T.Http({
    method: "PUT",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/values/{keyName}",
    contentType: "multipart",
}));
export const PutNamespaceValueResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({}).pipe(T.ResponsePath("result"));
export const putNamespaceValue = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: PutNamespaceValueRequest,
    output: PutNamespaceValueResponse,
    errors: [NamespaceNotFound, InvalidObjectIdentifier, InvalidExpirationTtl],
}));
export const DeleteNamespaceValueRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    keyName: Schema.String.pipe(T.HttpPath("keyName")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
}).pipe(T.Http({
    method: "DELETE",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/values/{keyName}",
}));
export const DeleteNamespaceValueResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({}).pipe(T.ResponsePath("result"));
export const deleteNamespaceValue = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteNamespaceValueRequest,
    output: DeleteNamespaceValueResponse,
    errors: [NamespaceNotFound, InvalidObjectIdentifier],
}));
export const BulkPutNamespacesRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    body: Schema.Array(Schema.Struct({
        key: Schema.String,
        value: Schema.String,
        base64: Schema.optional(Schema.Boolean),
        expiration: Schema.optional(Schema.Number),
        expirationTtl: Schema.optional(Schema.Number),
        metadata: Schema.optional(Schema.Unknown),
    }).pipe(Schema.encodeKeys({
        key: "key",
        value: "value",
        base64: "base64",
        expiration: "expiration",
        expirationTtl: "expiration_ttl",
        metadata: "metadata",
    }))).pipe(T.HttpBody()),
}).pipe(T.Http({
    method: "PUT",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk",
}));
export const BulkPutNamespacesResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    successfulKeyCount: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    unsuccessfulKeys: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    successfulKeyCount: "successful_key_count",
    unsuccessfulKeys: "unsuccessful_keys",
}))
    .pipe(T.ResponsePath("result"));
export const bulkPutNamespaces = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkPutNamespacesRequest,
    output: BulkPutNamespacesResponse,
    errors: [InvalidRequestBody, NamespaceNotFound, InvalidObjectIdentifier],
}));
export const BulkPutNamespaceKeysRequest = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    namespaceId: Schema.String.pipe(T.HttpPath("namespaceId")),
    accountId: Schema.String.pipe(T.HttpPath("account_id")),
    body: Schema.Array(Schema.Struct({
        key: Schema.String,
        value: Schema.String,
        base64: Schema.optional(Schema.Boolean),
        expiration: Schema.optional(Schema.Number),
        expirationTtl: Schema.optional(Schema.Number),
        metadata: Schema.optional(Schema.Unknown),
    }).pipe(Schema.encodeKeys({
        key: "key",
        value: "value",
        base64: "base64",
        expiration: "expiration",
        expirationTtl: "expiration_ttl",
        metadata: "metadata",
    }))).pipe(T.HttpBody()),
}).pipe(T.Http({
    method: "PUT",
    path: "/accounts/{account_id}/storage/kv/namespaces/{namespaceId}/bulk",
}));
export const BulkPutNamespaceKeysResponse = 
/*@__PURE__*/ /*#__PURE__*/ Schema.Struct({
    successfulKeyCount: Schema.optional(Schema.Union([Schema.Number, Schema.Null])),
    unsuccessfulKeys: Schema.optional(Schema.Union([Schema.Array(Schema.String), Schema.Null])),
})
    .pipe(Schema.encodeKeys({
    successfulKeyCount: "successful_key_count",
    unsuccessfulKeys: "unsuccessful_keys",
}))
    .pipe(T.ResponsePath("result"));
export const bulkPutNamespaceKeys = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BulkPutNamespaceKeysRequest,
    output: BulkPutNamespaceKeysResponse,
    errors: [InvalidRequestBody, NamespaceNotFound, InvalidObjectIdentifier],
}));
//# sourceMappingURL=kv.js.map