import { Data, Effect, Exit, Option, Schema as S } from "effect";
/** Supported primitive value types for Durable Object SQL APIs. */
export type SqlStorageValue = globalThis.SqlStorageValue;
/** Error type used when a storage operation throws or rejects. */
export class StorageOperationError extends Data.TaggedError("StorageOperationError")<{
readonly operation: string;
readonly cause: unknown;
}> {}
type StorageEffect = Effect.Effect;
/**
* Effect wrapper for Cloudflare SQL cursor operations.
*/
export interface SqlCursor> {
next(): StorageEffect<{ done?: false; value: T } | { done: true; value?: never }>;
toArray(): StorageEffect>;
one(): StorageEffect;
raw>(): StorageEffect>;
readonly columnNames: Array;
readonly rowsRead: StorageEffect;
readonly rowsWritten: StorageEffect;
}
/**
* Effect wrapper for Durable Object SQLite APIs.
*/
export interface SqlStorage {
/** Executes a SQL statement and returns a typed cursor. */
exec>(
query: string,
...bindings: Array
): StorageEffect>;
readonly databaseSize: number;
}
/**
* Schema pair used by `SyncKvStorage.schema(...)`.
*/
export interface SyncKvDefinition {
readonly key: S.Codec;
readonly value: S.Codec;
}
/**
* Sync KV wrapper that transparently encodes keys/values through Effect Schema.
*/
export interface SchemaBackedSyncKvStorage {
get(key: Key): Effect.Effect, unknown>;
put(key: Key, value: Value): Effect.Effect;
delete(key: Key): Effect.Effect;
list(options?: globalThis.SyncKvListOptions): Effect.Effect, unknown>;
}
/**
* Effect wrapper for synchronous KV attached to Durable Object SQLite storage.
*/
export interface SyncKvStorage {
get(key: string): StorageEffect;
put(key: string, value: T): StorageEffect;
delete(key: string): StorageEffect;
list(options?: globalThis.SyncKvListOptions): StorageEffect>;
schema(
definition: SyncKvDefinition,
): SchemaBackedSyncKvStorage;
}
/**
* Effect wrapper around Cloudflare transaction callbacks.
*/
export interface DurableObjectTransaction {
get(
key: string,
options?: globalThis.DurableObjectGetOptions,
): StorageEffect;
get(
keys: Array,
options?: globalThis.DurableObjectGetOptions,
): StorageEffect