UNPKG

@rivetkit/cloudflare-workers

Version:

_Lightweight Libraries for Backends_

174 lines (168 loc) 8.76 kB
import * as hono_types from 'hono/types'; import * as hono from 'hono'; import { Hono } from 'hono'; import * as _rivetkit_core_utils from '@rivetkit/core/utils'; import * as _rivetkit_core_driver_helpers from '@rivetkit/core/driver-helpers'; import * as _rivetkit_core from '@rivetkit/core'; import { ActorKey, Registry } from '@rivetkit/core'; import { z } from 'zod'; import { Client } from '@rivetkit/core/client'; import { DurableObject } from 'cloudflare:workers'; interface DriverContext { state: DurableObjectState; } declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{ driver: z.ZodDefault<z.ZodOptional<z.ZodObject<{ name: z.ZodString; manager: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver>; actor: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver>; }, "strip", z.ZodTypeAny, { name: string; actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver; manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver; }, { name: string; actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver; manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver; }>>>; getUpgradeWebSocket: z.ZodOptional<z.ZodType<() => _rivetkit_core_utils.UpgradeWebSocket, z.ZodTypeDef, () => _rivetkit_core_utils.UpgradeWebSocket>>; cors: z.ZodOptional<z.ZodType<{ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }, z.ZodTypeDef, { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }>>; maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>; studio: z.ZodDefault<z.ZodOptional<z.ZodObject<{ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; cors: z.ZodDefault<z.ZodOptional<z.ZodType<{ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }, z.ZodTypeDef, { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }>>>; token: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>>>; defaultEndpoint: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { enabled: boolean; cors: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }; token: (...args: unknown[]) => string; defaultEndpoint?: string | undefined; }, { enabled?: boolean | undefined; cors?: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; } | undefined; token?: ((...args: unknown[]) => string) | undefined; defaultEndpoint?: string | undefined; }>>>; basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>; }, "driver" | "getUpgradeWebSocket"> & { app: z.ZodOptional<z.ZodType<Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">, z.ZodTypeDef, Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">>>; }, "strip", z.ZodTypeAny, { maxIncomingMessageSize: number; studio: { enabled: boolean; cors: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; }; token: (...args: unknown[]) => string; defaultEndpoint?: string | undefined; }; basePath: string; cors?: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; } | undefined; app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined; }, { cors?: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; } | undefined; maxIncomingMessageSize?: number | undefined; studio?: { enabled?: boolean | undefined; cors?: { origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null); allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]); allowHeaders?: string[]; maxAge?: number; credentials?: boolean; exposeHeaders?: string[]; } | undefined; token?: ((...args: unknown[]) => string) | undefined; defaultEndpoint?: string | undefined; } | undefined; basePath?: string | undefined; app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined; }>>; type InputConfig = z.input<typeof ConfigSchema>; interface ActorHandlerInterface extends DurableObject { initialize(req: ActorInitRequest): Promise<void>; } interface ActorInitRequest { name: string; key: ActorKey; input?: unknown; } type DurableObjectConstructor = new (...args: ConstructorParameters<typeof DurableObject<Bindings>>) => DurableObject<Bindings>; /** Cloudflare Workers env */ interface Bindings { ACTOR_KV: KVNamespace; ACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>; } interface Handler { handler: ExportedHandler<Bindings>; ActorHandler: DurableObjectConstructor; } interface SetupOutput<A extends Registry<any>> { client: Client<A>; createHandler: (hono?: Hono) => Handler; } declare function createServerHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): Handler; declare function createServer<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): SetupOutput<R>; export { type Bindings, type InputConfig as Config, type DriverContext, createServer, createServerHandler };