import type { Bindings } from 'worktop/cfw'; import type { WebSocket } from 'worktop/cfw.ws'; import type { Dict, Promisable } from 'worktop/utils'; export namespace Durable { export interface Namespace { get(id: ObjectID): Object; idFromName(name: string): ObjectID; idFromString(hex: string): ObjectID; newUniqueId(options?: { jurisdiction: 'eu'; }): ObjectID; } export interface ObjectID { name?: string; toString(): string; } export interface Object { id: ObjectID; fetch: typeof fetch; name?: string; } export interface State { id: ObjectID; storage: Storage; waitUntil(f: any): void; blockConcurrencyWhile(f: () => Promisable): Promise; } export namespace Storage { export namespace Options { export interface Get { /** Bypass in-memory cache management */ noCache?: boolean; /** Opt out of race-condition protections */ allowConcurrency?: boolean; } export interface Put { /** Bypass in-memory cache management */ noCache?: boolean; /** Do not wait for disk flush */ allowUnconfirmed?: boolean; } export interface List extends Options.Get { /** begin listing results from this key, inclusive */ start?: string; /** stop listing results at this key, exclusive */ end?: string; /** only include results if key begins with prefix */ prefix?: string; /** if true, results given in descending lexicographic order */ reverse?: boolean; /** maximum number of results to return */ limit?: number; } } } export interface Storage { get(key: string, options?: Storage.Options.Get): Promise; get(keys: string[], options?: Storage.Options.Get): Promise>; put(entries: Dict, options?: Storage.Options.Put): Promise; put(key: string, value: T, options?: Storage.Options.Put): Promise; delete(key: string, options?: Storage.Options.Put): Promise; delete(keys: string[], options?: Storage.Options.Put): Promise; deleteAll(options?: Storage.Options.Put): Promise; list(options?: Storage.Options.List): Promise>; } } export abstract class Actor { public DEBUG: boolean; constructor(state: Durable.State, bindings: Bindings); setup?(state: Durable.State, bindings: Bindings): Promise | void; abstract receive(req: Request): Promise | Response; fetch(input: RequestInfo, init?: RequestInit): Promise; onconnect?(req: Request, ws: WebSocket): Promise | void; connect(req: Request): Promise; } export const DataGroup: Durable.Object; // @private // type CacheOptions = { // /** seconds */ // cacheTtl?: number; // /** custom cache identifier; ideal for multi-key scenarios */ // cacheKey?: string; // }; // export class Database { // constructor(namespace: Durable.Namespace); // get(shard: string, key: string, options?: Durable.Storage.Options.Get & CacheOptions): Promise; // get(shard: string, keys: string[], options?: Durable.Storage.Options.Get & CacheOptions): Promise>; // put(shard: string, entries: Dict, options?: { overwrite?: boolean } & Durable.Storage.Options.Put & CacheOptions): Promise; // put(shard: string, key: string, value: T, options?: { overwrite?: boolean } & Durable.Storage.Options.Put & CacheOptions): Promise; // delete(shard: string, key: string, options?: Durable.Storage.Options.Put & CacheOptions): Promise; // delete(shard: string, key: string[], options?: Durable.Storage.Options.Put & CacheOptions): Promise; // list(shard: string, options?: Durable.Storage.Options.List): Promise>; // }