UNPKG

rivetkit

Version:

Lightweight libraries for building stateful actors on edge platforms

65 lines (62 loc) 3.01 kB
export { a as assertUnreachable, s as stringifyError } from './utils-fwx3o3K9.js'; import { Context, Handler } from 'hono'; import 'hono/utils/http-status'; declare const VERSION: string; declare function httpUserAgent(): string; type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler; type GetUpgradeWebSocket = () => UpgradeWebSocket; declare function getEnvUniversal(key: string): string | undefined; declare function dbg<T>(x: T): T; /** * Converts various ArrayBuffer-like types to Uint8Array. * Handles ArrayBuffer, ArrayBufferView (including typed arrays), and passes through existing Uint8Array. * * @param data - The ArrayBuffer or ArrayBufferView to convert * @returns A Uint8Array view of the data */ declare function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array; type LongTimeoutHandle = { abort: () => void; }; /** * Polyfill for Promise.withResolvers(). * * This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly. */ declare function promiseWithResolvers<T>(): { promise: Promise<T>; resolve: (value: T | PromiseLike<T>) => void; reject: (reason?: any) => void; }; declare function setLongTimeout(listener: () => void, after: number): LongTimeoutHandle; /** * A tiny utility that coalesces/enqueues async operations so only the latest * queued task runs per cycle, while callers receive a promise that resolves * when the task for the cycle they joined has completed. */ declare class SinglePromiseQueue { #private; /** The currently running promise of #drainLoop. Do not await this, instead await `pending` to await the current cycle. */ runningDrainLoop?: Promise<void>; /** Queue the next operation and return a promise that resolves when it flushes. */ enqueue(op: () => Promise<void>): Promise<void>; } declare function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer; /** * Properly combines a base URL endpoint with a path, preserving any base path in the endpoint. * * @example * combineUrlPath("http://localhost:8787/rivet", "/actors/action") * // Returns: "http://localhost:8787/rivet/actors/action" * * @example * combineUrlPath("http://localhost:8787/rivet", "/actors?type=foo", { namespace: "test" }) * // Returns: "http://localhost:8787/rivet/actors?type=foo&namespace=test" * * @param endpoint The base URL endpoint that may contain a path component * @param path The path to append to the endpoint (may include query parameters) * @param queryParams Optional additional query parameters to append * @returns The properly combined URL string */ declare function combineUrlPath(endpoint: string, path: string, queryParams?: Record<string, string | undefined>): string; export { type GetUpgradeWebSocket, type LongTimeoutHandle, SinglePromiseQueue, type UpgradeWebSocket, VERSION, bufferToArrayBuffer, combineUrlPath, dbg, getEnvUniversal, httpUserAgent, promiseWithResolvers, setLongTimeout, toUint8Array };