import { AdapterError, AdapterConfigurationError, QueryFilter, ListOptions, DbAdapter } from '@geenius/adapters'; export { AuthContractError, AuthIdentitySchema, AuthProviderAdapter, AuthSessionContractSchema, CacheAdapter, CacheContractError, CacheEntrySchema, DeployAdapter, DeployContractError, DeploymentResultSchema, DeploymentTargetSchema, EventEnvelopeSchema, EventsAdapter, EventsContractError, PaymentCheckoutInputSchema, PaymentPlanContractSchema, PaymentSubscriptionContractSchema, PaymentsContractError, PaymentsProviderAdapter, QueueAdapter, QueueContractError, QueueJobSchema, StorageAdapter, StorageContractError, StorageObjectSchema } from '@geenius/adapters'; /** * @module index * @package @geenius/adapters/cloudflareKV * @description Implements the launch Cloudflare Workers KV provider contract * as a key/value DB adapter without importing Workers runtime SDKs. */ /** * Domain key parts addressed by the Cloudflare KV adapter's key builders. * Exported so consumers writing custom Workers KV inspection tooling can * reuse the same domain vocabulary the adapter validates against. */ type CloudflareKvKeyPart = "collection" | "field" | "id" | "keyPrefix"; /** * Builds the collection-index key the adapter writes under * `{keyPrefix}:{collection}:__index`. Each part is URI-encoded so user-provided * collection names cannot break the `:` delimiter convention. * * Use this when reading or invalidating an index entry from outside the * adapter — never hand-roll the key string, since the encoding rules may * tighten over time. * * @param keyPrefix Domain prefix configured on `createCloudflareKvDbAdapter` * @param collection Logical collection name (URI-encoded into the key) */ declare function buildCloudflareKvCollectionIndexKey(keyPrefix: string, collection: string): string; /** * Builds the `namespace.list({ prefix })` value used to scan every record key * for a collection. Produces `{keyPrefix}:{collection}:` (trailing colon * intentional — paired with `recordKey()` whose id segment follows). * * @param keyPrefix Domain prefix configured on `createCloudflareKvDbAdapter` * @param collection Logical collection name (URI-encoded into the prefix) */ declare function buildCloudflareKvCollectionRecordPrefix(keyPrefix: string, collection: string): string; /** * Builds the fully-qualified record key written for a single document: * `{keyPrefix}:{collection}:{id}`. Each segment is URI-encoded. * * @param keyPrefix Domain prefix configured on `createCloudflareKvDbAdapter` * @param collection Logical collection name * @param id Record id */ declare function buildCloudflareKvRecordKey(keyPrefix: string, collection: string, id: string): string; /** * Key/value DB adapter surface implemented by the Cloudflare Workers KV * contract package. */ interface CloudflareKvDbAdapter { count(collection: string, filter?: QueryFilter): Promise; create>(collection: string, data: Omit): Promise; delete(collection: string, id: string): Promise; get(collection: string, id: string): Promise; join(): Promise; list(collection: string, options?: ListOptions): Promise; query(collection: string, filter: QueryFilter): Promise; sql(): Promise; transaction(): Promise; update>(collection: string, id: string, data: Partial): Promise; } /** Options forwarded to Workers KV writes when record or index TTL is enabled. */ interface CloudflareKvPutOptions { expirationTtl?: number; } /** Options forwarded to Workers KV prefix listing. */ interface CloudflareKvListOptions { cursor?: string; limit?: number; prefix?: string; } /** Key metadata returned by Workers KV prefix listing. */ interface CloudflareKvListKey { name: string; } /** Result returned by Workers KV prefix listing. */ interface CloudflareKvListResult { cursor?: string; keys: CloudflareKvListKey[]; list_complete: boolean; } /** Minimal Workers KV namespace contract consumed by the adapter factory. */ interface CloudflareKvNamespace { get(key: string): Promise; put(key: string, value: string, options?: CloudflareKvPutOptions): Promise; delete(key: string): Promise; list?(options?: CloudflareKvListOptions): Promise; } /** Configuration accepted by {@link createCloudflareKvDbAdapter}. */ interface CloudflareKvDbAdapterOptions { namespace: CloudflareKvNamespace; /** * TTL applied to record payloads. Collection indexes persist by default so * record refreshes cannot make live rows unreachable from list/query/count. */ defaultTtlSeconds?: number; idFactory?: () => string; /** * Optional TTL for collection indexes when the whole collection should expire. * Requires record TTL and must be greater than or equal to record TTL so * collection indexes cannot expire before live records. */ indexTtlSeconds?: number; keyPrefix?: string; /** * Maximum record payloads that filtered query/count scans may read. KV is a * key/value backend, so larger filtered scans should move to Convex/Neon. */ maxScanRecords?: number; } /** * Binding wrapper accepted by {@link withCloudflareKvDb} when downstream code * already constructed a DB adapter and wants Cloudflare KV contract validation. */ interface CloudflareKvDbAdapterBinding { adapter: DbAdapter; } /** * Accepted input for binding an existing DB adapter or constructing a new * Cloudflare KV-backed adapter. */ type CloudflareKvDbAdapterInput = DbAdapter | CloudflareKvDbAdapterBinding | CloudflareKvDbAdapterOptions; /** Error thrown when Cloudflare KV adapter configuration is invalid. */ declare class CloudflareKvBindingError extends AdapterConfigurationError { readonly cloudflareCode = "INVALID_CLOUDFLARE_KV_ADAPTER"; /** * Creates a typed Cloudflare KV binding error. * * @param message Human-readable validation failure. * @param cause Optional original error that triggered the failure. */ constructor(message: string, cause?: unknown); } /** Error thrown when callers request relational operations unsupported by KV. */ declare class AdapterUnsupportedError extends AdapterError { readonly name = "AdapterUnsupportedError"; /** * Creates an unsupported-operation adapter error for the DB domain. * * @param message Human-readable unsupported-operation message. * @param cause Optional original error that triggered the failure. */ constructor(message: string, cause?: unknown); } /** * Creates a Cloudflare Workers KV-backed DB adapter for key/value workloads. * * Workers KV is eventually consistent. Direct `get()` reads target record keys, * while `list()`, `query()`, and `count()` prefer Workers KV prefix listing * when the namespace exposes it and fall back to the collection index key for * minimal test namespaces. Use Convex or Neon for transactional or query-heavy * workloads. * * @param options KV namespace, key prefix, TTL, and id factory configuration. * @returns A DB adapter implementing CRUD, list, query, and count with KV storage. */ declare function createCloudflareKvDbAdapter(options: CloudflareKvDbAdapterOptions): CloudflareKvDbAdapter; /** * Normalizes Cloudflare KV adapter input into a shared DB adapter instance. * * @param config Existing DB adapter, adapter binding, or KV adapter options. * @returns A DB adapter suitable for the shared adapters contract. */ declare function withCloudflareKvDb(config: CloudflareKvDbAdapterInput): DbAdapter; export { AdapterUnsupportedError, CloudflareKvBindingError, type CloudflareKvDbAdapter, type CloudflareKvDbAdapterBinding, type CloudflareKvDbAdapterInput, type CloudflareKvDbAdapterOptions, type CloudflareKvKeyPart, type CloudflareKvListKey, type CloudflareKvListOptions, type CloudflareKvListResult, type CloudflareKvNamespace, type CloudflareKvPutOptions, buildCloudflareKvCollectionIndexKey, buildCloudflareKvCollectionRecordPrefix, buildCloudflareKvRecordKey, createCloudflareKvDbAdapter, withCloudflareKvDb };