rivetkit
Version:
Lightweight libraries for building stateful actors on edge platforms
122 lines (113 loc) • 6.13 kB
text/typescript
import { U as UniversalWebSocket, R as RivetEvent, a as RivetCloseEvent, b as RivetMessageEvent, A as ActorDriver, c as RunnerConfig, E as Encoding, d as AnyDatabaseProvider, e as Actions, f as ActorConfigInput, g as ActorDefinition, D as DriverConfig } from './conn-Cc9WHuN4.cjs';
export { n as ActionContext, r as ActionContextOf, z as ActorConfig, x as ActorConfigSchema, q as ActorContext, s as ActorContextOf, m as ActorKey, l as ActorQuery, w as ActorTypes, t as AnyActorDefinition, v as AnyActorInstance, j as AnyClient, y as AuthIntent, C as Client, o as Conn, p as ConnectionStatus, I as InitContext, O as OnConnectOptions, K as Registry, G as RegistryActors, F as RegistryConfig, J as RegistryConfigSchema, H as RunConfigInput, S as ServerlessActorDriverBuilder, k as createClientWithDriver, h as generateConnId, i as generateConnToken, u as lookupInRegistry, L as setup, B as test } from './conn-Cc9WHuN4.cjs';
import { WSContext } from 'hono/ws';
export { n as noopNext } from './utils-fwx3o3K9.cjs';
export { toUint8Array } from './utils.cjs';
export { A as ALLOWED_PUBLIC_HEADERS, P as PATH_CONNECT_WEBSOCKET, a as PATH_RAW_WEBSOCKET_PREFIX } from './actor-router-consts-B3Lu87yJ.cjs';
export { UserError, UserErrorOptions } from './actor/errors.cjs';
import { Hono } from 'hono';
import 'hono/streaming';
import 'zod';
import 'pino';
import 'nanoevents';
import 'zod/v4';
import 'hono/utils/http-status';
interface UniversalEvent {
type: string;
target?: any;
currentTarget?: any;
}
interface UniversalMessageEvent extends UniversalEvent {
data: string;
lastEventId: string;
origin: string;
}
interface UniversalErrorEvent extends UniversalEvent {
message: string;
filename?: string;
lineno?: number;
colno?: number;
error?: any;
}
/**
* Common EventSource interface that can be implemented by different EventSource-like classes
* This is compatible with the standard EventSource API but allows for custom implementations
*/
interface UniversalEventSource {
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSED: 2;
readonly readyState: 0 | 1 | 2;
readonly url: string;
readonly withCredentials: boolean;
close(): void;
addEventListener(type: string, listener: (event: any) => void): void;
removeEventListener(type: string, listener: (event: any) => void): void;
dispatchEvent(event: UniversalEvent): boolean;
onopen?: ((event: UniversalEvent) => void) | null;
onmessage?: ((event: UniversalMessageEvent) => void) | null;
onerror?: ((event: UniversalErrorEvent) => void) | null;
}
interface UpgradeWebSocketArgs {
onOpen: (event: any, ws: WSContext) => void;
onMessage: (event: any, ws: WSContext) => void;
onClose: (event: any, ws: WSContext) => void;
onError: (error: any, ws: WSContext) => void;
}
/**
* InlineWebSocketAdapter implements a WebSocket-like interface
* that connects to a UpgradeWebSocketArgs handler
*/
declare class InlineWebSocketAdapter2 implements UniversalWebSocket {
#private;
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;
constructor(handler: UpgradeWebSocketArgs);
get readyState(): 0 | 1 | 2 | 3;
get binaryType(): "arraybuffer" | "blob";
set binaryType(value: "arraybuffer" | "blob");
get bufferedAmount(): number;
get extensions(): string;
get protocol(): string;
get url(): string;
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
/**
* Closes the connection
*/
close(code?: number, reason?: string): void;
addEventListener(type: string, listener: (ev: any) => void): void;
removeEventListener(type: string, listener: (ev: any) => void): void;
dispatchEvent(event: RivetEvent): boolean;
get onopen(): ((event: RivetEvent) => void) | null;
set onopen(handler: ((event: RivetEvent) => void) | null);
get onclose(): ((event: RivetCloseEvent) => void) | null;
set onclose(handler: ((event: RivetCloseEvent) => void) | null);
get onerror(): ((event: RivetEvent) => void) | null;
set onerror(handler: ((event: RivetEvent) => void) | null);
get onmessage(): ((event: RivetMessageEvent) => void) | null;
set onmessage(handler: ((event: RivetMessageEvent) => void) | null);
}
/**
* Creates a WebSocket connection handler
*/
declare function handleWebSocketConnect(req: Request | undefined, runConfig: RunnerConfig, actorDriver: ActorDriver, actorId: string, encoding: Encoding, parameters: unknown, connId?: string, connToken?: string): Promise<UpgradeWebSocketArgs>;
declare function handleRawWebSocketHandler(req: Request | undefined, path: string, actorDriver: ActorDriver, actorId: string): Promise<UpgradeWebSocketArgs>;
interface ActorRouterBindings {
actorId: string;
}
type ActorRouter = Hono<{
Bindings: ActorRouterBindings;
}>;
/**
* Creates a router that runs on the partitioned instance.
*/
declare function createActorRouter(runConfig: RunnerConfig, actorDriver: ActorDriver, isTest: boolean): ActorRouter;
declare function actor<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>(input: ActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TActions>): ActorDefinition<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TActions>;
declare function createEngineDriver(): DriverConfig;
declare function createFileSystemDriver(opts?: {
path?: string;
}): DriverConfig;
declare function createMemoryDriver(): DriverConfig;
export { Actions, ActorConfigInput, ActorDefinition, type ActorRouter, DriverConfig, Encoding, InlineWebSocketAdapter2, RivetCloseEvent, RivetEvent, RivetMessageEvent, RunnerConfig as RunConfig, type UniversalErrorEvent, type UniversalEvent, type UniversalEventSource, type UniversalMessageEvent, UniversalWebSocket, type UpgradeWebSocketArgs, actor, createActorRouter, createEngineDriver, createFileSystemDriver, createMemoryDriver, handleRawWebSocketHandler, handleWebSocketConnect };