actor-kit
Version:
Actor Kit is a library for running state machines in Cloudflare Workers, leveraging XState for robust state management. It provides a framework for managing the logic, lifecycle, persistence, synchronization, and access control of actors in a distributed
65 lines (64 loc) • 2.81 kB
text/typescript
import { O as MachineServerOptions, S as EnvFromMachine, _ as Caller, c as ActorServer, j as ScreamingSnakeToKebab, r as ActorKitEnv, u as AnyActorKitStateMachine, v as CallerSnapshotFrom } from "./types-C31KX9CW.mjs";
import { z } from "zod";
import { Operation } from "fast-json-patch";
import * as xstate from "xstate";
import { AnyEventObject } from "xstate";
//#region src/createActorKitRouter.d.ts
declare const createActorKitRouter: <Env extends ActorKitEnv>(routes: Array<ScreamingSnakeToKebab<Extract<keyof Env, string>>>) => (request: Request, env: Env, _ctx?: unknown) => Promise<Response>;
//#endregion
//#region src/createMachineServer.d.ts
declare const createMachineServer: <TClientEvent extends AnyEventObject, TServiceEvent extends AnyEventObject, TInputSchema extends z.ZodObject<z.ZodRawShape>, TMachine extends AnyActorKitStateMachine>({
machine,
schemas,
options
}: {
machine: TMachine;
schemas: {
clientEvent: z.ZodSchema<TClientEvent>;
serviceEvent: z.ZodSchema<TServiceEvent>;
inputProps: TInputSchema;
};
options?: MachineServerOptions;
}) => new (state: DurableObjectState, env: EnvFromMachine<TMachine>) => ActorServer<TMachine>;
//#endregion
//#region src/fromActorKit.d.ts
type KebabToScreamingSnake<S extends string> = string extends S ? string : S extends `${infer Head}-${infer Tail}` ? `${Uppercase<Head>}_${KebabToScreamingSnake<Tail>}` : Uppercase<S>;
type FromActorKitEmitted<TActorType extends string, TMachine extends AnyActorKitStateMachine> = {
type: `${KebabToScreamingSnake<TActorType>}_UPDATED`;
actorType: TActorType;
actorId: string;
snapshot: CallerSnapshotFrom<TMachine>;
operations: Operation[];
} | {
type: `${KebabToScreamingSnake<TActorType>}_ERROR`;
actorType: TActorType;
actorId: string;
error: Error;
};
interface ActorKitNamespaceLike {
idFromName(name: string): unknown;
get(id: unknown): {
fetch(request: Request): Promise<Response>;
spawn?(props: {
actorType: string;
actorId: string;
caller: Caller;
input: Record<string, unknown>;
}): Promise<void> | void;
[key: string]: unknown;
};
}
interface FromActorKitInput<TEventSchema extends z.ZodTypeAny = z.ZodTypeAny> {
server: ActorKitNamespaceLike;
actorId: string;
actorInput: Record<string, unknown>;
caller: Caller;
signingKey: string;
eventSchema: TEventSchema;
}
declare function fromActorKit<TMachine extends AnyActorKitStateMachine, TActorType extends string = string>(actorType: TActorType): xstate.CallbackActorLogic<Record<string, unknown> & {
type: string;
}, FromActorKitInput<z.ZodTypeAny>, xstate.EventObject>;
//#endregion
export { type FromActorKitEmitted, type FromActorKitInput, createActorKitRouter, createMachineServer, fromActorKit };
//# sourceMappingURL=worker.d.mts.map