@rivetkit/cloudflare-workers 0.0.0-sqlite-uds.37f9e48 → 0.0.0-sqlite-profiling-compat.4a9a623
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.js.map +1 -1
- package/package.json +9 -4
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/cloudflare-workers/dist/mod.js","../src/mod.ts","../src/websocket.ts"],"names":[],"mappings":"AAAA;ACAA,kHAA8B;AAC9B,iKAAuB;AACvB;AACC;AAGA;AAAS,oCACH;ADAP;AACA;AEGA,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EACpB,4BAAgB,WAAA,EAAa,EAAA;AAAA,EAC7B,6BAAgB,KAAA,EAAO,EAAA;AAAA,EACvB,6BAAgB,QAAA,EAAU,EAAA;AAAA,EAC1B,6BAAgB,OAAA,EAAS,EAAA;AAAA,iBAEzB,WAAA,EAAyB,cAAA;AAAA,kBACzB,OAAA,EAA0C,KAAA;AAAA,kBAC1C,UAAA,EAAoD,KAAA;AAAA,kBACpD,QAAA,EAAgD,KAAA;AAAA,kBAChD,QAAA,EAA2C,KAAA;AAAA,kBAC3C,WAAA,EAAa,eAAA,CAAe,WAAA;AAAA,EAC5B,CAAA,MAAA;AAAA,EACA,CAAA,QAAA,EAA0D,CAAC,CAAA;AAAA,EAE3D,WAAA,CAAY,GAAA,EAAa,SAAA,EAAoC;AAC5D,IAAA,KAAK,IAAA,CAAK,CAAA,OAAA,CAAS,GAAA,EAAK,SAAS,CAAA;AAAA,EAClC;AAAA,EAEA,MAAM,CAAA,OAAA,CAAS,GAAA,EAAa,SAAA,EAAoC;AA9BjE,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,IAAA,IAAI;AACH,MAAA,MAAM,aAAA,EAAe,KAAA,CAAM,OAAA,CAAQ,SAAS,EAAA,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EAAA;AACD;AFbA;AACA;AC/EA;AAcO;AAGN,EAAA;AAAwB,IAAA;AACd,IAAA;AAC6C,IAAA;AAC3C,IAAA;AACR,EAAA;AAEL;AA4BA;AA/DA,EAAA;AAoEC,EAAA;AACA,EAAA;AACC,IAAA;AAAsB,EAAA;AAEvB,EAAA;AACC,IAAA;AAAuB,EAAA;AAExB,EAAA;AACC,IAAA;AAAmB,EAAA;AAEpB,EAAA;AACC,IAAA;AAA2D,EAAA;AAE5D,EAAA;AACC,IAAA;AAAkE,EAAA;AAEpE;AAqBO;AAIN,EAAA;AACA,EAAA;AAIA,EAAA;AAEA,EAAA;AAAO,IAAA;AAEL,MAAA;AACC,QAAA;AAAA,UAAA;AACC,2BAAA;AACS,UAAA;AACT,QAAA;AAED,QAAA;AAAa,MAAA;AAGd,MAAA;AACA,MAAA;AAIC,QAAA;AAA+B,MAAA;AAGhC,MAAA;AACC,QAAA;AAAsC,MAAA;AAGvC,MAAA;AAAW,QAAA;AACV,MAAA;AACD,IAAA;AACD,EAAA;AAEF;ADGA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/cloudflare-workers/dist/mod.js","sourcesContent":[null,"import * as wasmBindings from \"@rivetkit/rivetkit-wasm\";\nimport wasmModule from \"@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm\";\nimport {\n\tRegistry,\n\ttype RegistryActors,\n\ttype RegistryConfigInput,\n\tsetup as rivetkitSetup,\n} from \"rivetkit\";\n// Installs the fetch-based `globalThis.WebSocket` shim required for the wasm\n// runtime's outbound tunnel to the Rivet engine. Imported for its side effect.\nimport \"./websocket\";\n\nconst DEFAULT_MANAGER_PATH = \"/api/rivet\";\n\n/** Config passed to `setup` / `createHandler`. The wasm runtime is wired automatically. */\nexport type CloudflareSetupConfig<A extends RegistryActors> = Omit<\n\tRegistryConfigInput<A>,\n\t\"runtime\" | \"wasm\"\n>;\n\n/**\n * Wraps rivetkit's `setup` with the Cloudflare Workers WebAssembly runtime wired\n * in. Returns a typed `Registry`, so you can derive a typed client with\n * `createClient<typeof registry>(...)` and pass the same registry to\n * `createHandler`.\n */\nexport function setup<A extends RegistryActors>(\n\tconfig: CloudflareSetupConfig<A>,\n): Registry<A> {\n\treturn rivetkitSetup<A>({\n\t\truntime: \"wasm\",\n\t\twasm: { bindings: wasmBindings, initInput: wasmModule },\n\t\tnoWelcome: true,\n\t\t...config,\n\t} as RegistryConfigInput<A>);\n}\n\nexport interface CreateHandlerOptions {\n\t/**\n\t * Path the Rivet manager API is mounted at. Defaults to `/api/rivet`.\n\t *\n\t * `rivet dev` and the engine poll `<managerPath>/metadata`, so changing this\n\t * also requires configuring the engine-side serverless runner URL to match.\n\t */\n\tmanagerPath?: string;\n\t/**\n\t * Handler for requests that fall outside the Rivet manager API path. Accepts\n\t * a plain `(request, env, ctx)` handler or a framework `fetch` such as\n\t * Hono's `app.fetch`.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: accept any fetch handler shape (e.g. Hono's app.fetch).\n\tfetch?: (request: Request, ...args: any[]) => Response | Promise<Response>;\n}\n\nexport interface CloudflareHandler {\n\tfetch(request: Request, env: unknown, ctx: unknown): Promise<Response>;\n}\n\ntype EnvRecord = Record<string, string | undefined>;\n\n// Fill connection config from the per-request `env` on first request. On\n// Cloudflare the env is not available at module scope, so values that were not\n// set explicitly in the config are sourced from `RIVET_*` Worker variables here.\nfunction applyEnv(\n\tregistry: Registry<RegistryActors>,\n\tenv: EnvRecord,\n\tmanagerPath: string,\n): void {\n\tconst config = registry.config as RegistryConfigInput<RegistryActors>;\n\tif (!config.endpoint && env.RIVET_ENDPOINT) {\n\t\tconfig.endpoint = env.RIVET_ENDPOINT;\n\t}\n\tif (!config.namespace && env.RIVET_NAMESPACE) {\n\t\tconfig.namespace = env.RIVET_NAMESPACE;\n\t}\n\tif (!config.token && env.RIVET_TOKEN) {\n\t\tconfig.token = env.RIVET_TOKEN;\n\t}\n\tif (env.RIVET_POOL && !config.envoy?.poolName) {\n\t\tconfig.envoy = { ...config.envoy, poolName: env.RIVET_POOL };\n\t}\n\tif (!config.serverless?.basePath) {\n\t\tconfig.serverless = { ...config.serverless, basePath: managerPath };\n\t}\n}\n\n/**\n * Creates a Cloudflare Workers handler that hosts Rivet Actors on the wasm\n * runtime. Accepts either a registry from this package's `setup` or a setup\n * config (which is wired through `setup` for you).\n *\n * The Rivet manager API is mounted at `managerPath` (default `/api/rivet`).\n * Requests outside that path are routed to `options.fetch` if provided, letting\n * you mount your own routes alongside Rivet. The engine endpoint is read from\n * `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)\n * unless set in the config.\n */\nexport function createHandler<A extends RegistryActors>(\n\tregistry: Registry<A>,\n\toptions?: CreateHandlerOptions,\n): CloudflareHandler;\nexport function createHandler<A extends RegistryActors>(\n\tconfig: CloudflareSetupConfig<A>,\n\toptions?: CreateHandlerOptions,\n): CloudflareHandler;\nexport function createHandler<A extends RegistryActors>(\n\tregistryOrConfig: Registry<A> | CloudflareSetupConfig<A>,\n\toptions: CreateHandlerOptions = {},\n): CloudflareHandler {\n\tconst managerPath = options.managerPath ?? DEFAULT_MANAGER_PATH;\n\tconst registry =\n\t\tregistryOrConfig instanceof Registry\n\t\t\t? registryOrConfig\n\t\t\t: setup(registryOrConfig);\n\tlet envApplied = false;\n\n\treturn {\n\t\tasync fetch(request, env, ctx) {\n\t\t\tif (!envApplied) {\n\t\t\t\tapplyEnv(\n\t\t\t\t\tregistry as Registry<RegistryActors>,\n\t\t\t\t\t(env ?? {}) as EnvRecord,\n\t\t\t\t\tmanagerPath,\n\t\t\t\t);\n\t\t\t\tenvApplied = true;\n\t\t\t}\n\n\t\t\tconst url = new URL(request.url);\n\t\t\tif (\n\t\t\t\turl.pathname === managerPath ||\n\t\t\t\turl.pathname.startsWith(`${managerPath}/`)\n\t\t\t) {\n\t\t\t\treturn registry.handler(request);\n\t\t\t}\n\n\t\t\tif (options.fetch) {\n\t\t\t\treturn options.fetch(request, env, ctx);\n\t\t\t}\n\n\t\t\treturn new Response(\n\t\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivet.dev\\n\",\n\t\t\t);\n\t\t},\n\t};\n}\n","// Cloudflare Workers do not implement an outbound `new WebSocket(url)` client\n// constructor, but the wasm actor runtime opens its tunnel to the Rivet engine\n// through `globalThis.WebSocket`. This shim translates that constructor into\n// Cloudflare's fetch-based upgrade (`fetch(url, { Upgrade })` + `response.webSocket`)\n// and installs itself on `globalThis` so both the wasm tunnel and the TypeScript\n// client path resolve a working implementation.\n\ntype WebSocketProtocolInput = string | string[] | undefined;\n\ntype CloudflareSocket = WebSocket & { accept(): void };\n\nclass FetchWebSocket {\n\tstatic readonly CONNECTING = 0;\n\tstatic readonly OPEN = 1;\n\tstatic readonly CLOSING = 2;\n\tstatic readonly CLOSED = 3;\n\n\tbinaryType: BinaryType = \"arraybuffer\";\n\tonopen: ((event: Event) => void) | null = null;\n\tonmessage: ((event: MessageEvent) => void) | null = null;\n\tonclose: ((event: CloseEvent) => void) | null = null;\n\tonerror: ((event: Event) => void) | null = null;\n\treadyState = FetchWebSocket.CONNECTING;\n\t#socket: CloudflareSocket | undefined;\n\t#pending: Array<string | ArrayBuffer | ArrayBufferView> = [];\n\n\tconstructor(url: string, protocols?: WebSocketProtocolInput) {\n\t\tvoid this.#connect(url, protocols);\n\t}\n\n\tasync #connect(url: string, protocols?: WebSocketProtocolInput) {\n\t\ttry {\n\t\t\tconst protocolList = Array.isArray(protocols)\n\t\t\t\t? protocols\n\t\t\t\t: protocols\n\t\t\t\t\t? [protocols]\n\t\t\t\t\t: [];\n\t\t\tconst headers = new Headers({ Upgrade: \"websocket\" });\n\t\t\tif (protocolList.length > 0) {\n\t\t\t\theaders.set(\"Sec-WebSocket-Protocol\", protocolList.join(\", \"));\n\t\t\t}\n\t\t\tconst response = await fetch(\n\t\t\t\turl.replace(/^ws:/, \"http:\").replace(/^wss:/, \"https:\"),\n\t\t\t\t{ headers },\n\t\t\t);\n\t\t\tconst socket = (\n\t\t\t\tresponse as unknown as { webSocket: CloudflareSocket | null }\n\t\t\t).webSocket;\n\t\t\tif (!socket) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`websocket upgrade failed with status ${response.status}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tsocket.accept();\n\t\t\tsocket.binaryType = this.binaryType;\n\t\t\tthis.#socket = socket;\n\t\t\tthis.readyState = FetchWebSocket.OPEN;\n\t\t\tsocket.addEventListener(\"message\", (event) => {\n\t\t\t\tthis.onmessage?.(event);\n\t\t\t});\n\t\t\tsocket.addEventListener(\"close\", (event) => {\n\t\t\t\tthis.readyState = FetchWebSocket.CLOSED;\n\t\t\t\tthis.onclose?.(event);\n\t\t\t});\n\t\t\tsocket.addEventListener(\"error\", (event) => {\n\t\t\t\tthis.onerror?.(event);\n\t\t\t});\n\t\t\tthis.onopen?.(new Event(\"open\"));\n\t\t\tfor (const data of this.#pending.splice(0)) {\n\t\t\t\tsocket.send(data);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"rivetkit cloudflare websocket shim failed\", error);\n\t\t\tthis.readyState = FetchWebSocket.CLOSED;\n\t\t\tthis.onerror?.(error instanceof Event ? error : new Event(\"error\"));\n\t\t\tthis.onclose?.(new CloseEvent(\"close\", { code: 1006 }));\n\t\t}\n\t}\n\n\tsend(data: string | ArrayBuffer | ArrayBufferView) {\n\t\tif (this.readyState === FetchWebSocket.CONNECTING) {\n\t\t\tthis.#pending.push(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.#socket?.send(data);\n\t}\n\n\tclose(code?: number, reason?: string) {\n\t\tthis.readyState = FetchWebSocket.CLOSING;\n\t\tthis.#socket?.close(code, reason);\n\t}\n}\n\nconst globalScope = globalThis as unknown as {\n\tWebSocket: typeof WebSocket;\n\t__RIVETKIT_CF_WEBSOCKET_INSTALLED__?: boolean;\n};\n\n// Install once per isolate.\nif (!globalScope.__RIVETKIT_CF_WEBSOCKET_INSTALLED__) {\n\tglobalScope.WebSocket = FetchWebSocket as unknown as typeof WebSocket;\n\tglobalScope.__RIVETKIT_CF_WEBSOCKET_INSTALLED__ = true;\n}\n\nexport { FetchWebSocket };\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/actors/actors/rivetkit-typescript/packages/cloudflare-workers/dist/mod.js","../src/mod.ts","../src/websocket.ts"],"names":[],"mappings":"AAAA;ACAA,kHAA8B;AAC9B,iKAAuB;AACvB;AACC;AAGA;AAAS,oCACH;ADAP;AACA;AEGA,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EACpB,4BAAgB,WAAA,EAAa,EAAA;AAAA,EAC7B,6BAAgB,KAAA,EAAO,EAAA;AAAA,EACvB,6BAAgB,QAAA,EAAU,EAAA;AAAA,EAC1B,6BAAgB,OAAA,EAAS,EAAA;AAAA,iBAEzB,WAAA,EAAyB,cAAA;AAAA,kBACzB,OAAA,EAA0C,KAAA;AAAA,kBAC1C,UAAA,EAAoD,KAAA;AAAA,kBACpD,QAAA,EAAgD,KAAA;AAAA,kBAChD,QAAA,EAA2C,KAAA;AAAA,kBAC3C,WAAA,EAAa,eAAA,CAAe,WAAA;AAAA,EAC5B,CAAA,MAAA;AAAA,EACA,CAAA,QAAA,EAA0D,CAAC,CAAA;AAAA,EAE3D,WAAA,CAAY,GAAA,EAAa,SAAA,EAAoC;AAC5D,IAAA,KAAK,IAAA,CAAK,CAAA,OAAA,CAAS,GAAA,EAAK,SAAS,CAAA;AAAA,EAClC;AAAA,EAEA,MAAM,CAAA,OAAA,CAAS,GAAA,EAAa,SAAA,EAAoC;AA9BjE,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,IAAA,IAAI;AACH,MAAA,MAAM,aAAA,EAAe,KAAA,CAAM,OAAA,CAAQ,SAAS,EAAA,EACzC,UAAA,EACA,UAAA,EACC,CAAC,SAAS,EAAA,EACV,CAAC,CAAA;AACL,MAAA,MAAM,QAAA,EAAU,IAAI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;AACR,EAAA;AAEL;AA4BA;AA/DA,EAAA;AAoEC,EAAA;AACA,EAAA;AACC,IAAA;AAAsB,EAAA;AAEvB,EAAA;AACC,IAAA;AAAuB,EAAA;AAExB,EAAA;AACC,IAAA;AAAmB,EAAA;AAEpB,EAAA;AACC,IAAA;AAA2D,EAAA;AAE5D,EAAA;AACC,IAAA;AAAkE,EAAA;AAEpE;AAqBO;AAIN,EAAA;AACA,EAAA;AAIA,EAAA;AAEA,EAAA;AAAO,IAAA;AAEL,MAAA;AACC,QAAA;AAAA,UAAA;AACC,2BAAA;AACS,UAAA;AACT,QAAA;AAED,QAAA;AAAa,MAAA;AAGd,MAAA;AACA,MAAA;AAIC,QAAA;AAA+B,MAAA;AAGhC,MAAA;AACC,QAAA;AAAsC,MAAA;AAGvC,MAAA;AAAW,QAAA;AACV,MAAA;AACD,IAAA;AACD,EAAA;AAEF;ADGA;AACA;AACA;AACA","file":"/home/runner/work/actors/actors/rivetkit-typescript/packages/cloudflare-workers/dist/mod.js","sourcesContent":[null,"import * as wasmBindings from \"@rivetkit/rivetkit-wasm\";\nimport wasmModule from \"@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm\";\nimport {\n\tRegistry,\n\ttype RegistryActors,\n\ttype RegistryConfigInput,\n\tsetup as rivetkitSetup,\n} from \"rivetkit\";\n// Installs the fetch-based `globalThis.WebSocket` shim required for the wasm\n// runtime's outbound tunnel to the Rivet engine. Imported for its side effect.\nimport \"./websocket\";\n\nconst DEFAULT_MANAGER_PATH = \"/api/rivet\";\n\n/** Config passed to `setup` / `createHandler`. The wasm runtime is wired automatically. */\nexport type CloudflareSetupConfig<A extends RegistryActors> = Omit<\n\tRegistryConfigInput<A>,\n\t\"runtime\" | \"wasm\"\n>;\n\n/**\n * Wraps rivetkit's `setup` with the Cloudflare Workers WebAssembly runtime wired\n * in. Returns a typed `Registry`, so you can derive a typed client with\n * `createClient<typeof registry>(...)` and pass the same registry to\n * `createHandler`.\n */\nexport function setup<A extends RegistryActors>(\n\tconfig: CloudflareSetupConfig<A>,\n): Registry<A> {\n\treturn rivetkitSetup<A>({\n\t\truntime: \"wasm\",\n\t\twasm: { bindings: wasmBindings, initInput: wasmModule },\n\t\tnoWelcome: true,\n\t\t...config,\n\t} as RegistryConfigInput<A>);\n}\n\nexport interface CreateHandlerOptions {\n\t/**\n\t * Path the Rivet manager API is mounted at. Defaults to `/api/rivet`.\n\t *\n\t * `rivet dev` and the engine poll `<managerPath>/metadata`, so changing this\n\t * also requires configuring the engine-side serverless runner URL to match.\n\t */\n\tmanagerPath?: string;\n\t/**\n\t * Handler for requests that fall outside the Rivet manager API path. Accepts\n\t * a plain `(request, env, ctx)` handler or a framework `fetch` such as\n\t * Hono's `app.fetch`.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: accept any fetch handler shape (e.g. Hono's app.fetch).\n\tfetch?: (request: Request, ...args: any[]) => Response | Promise<Response>;\n}\n\nexport interface CloudflareHandler {\n\tfetch(request: Request, env: unknown, ctx: unknown): Promise<Response>;\n}\n\ntype EnvRecord = Record<string, string | undefined>;\n\n// Fill connection config from the per-request `env` on first request. On\n// Cloudflare the env is not available at module scope, so values that were not\n// set explicitly in the config are sourced from `RIVET_*` Worker variables here.\nfunction applyEnv(\n\tregistry: Registry<RegistryActors>,\n\tenv: EnvRecord,\n\tmanagerPath: string,\n): void {\n\tconst config = registry.config as RegistryConfigInput<RegistryActors>;\n\tif (!config.endpoint && env.RIVET_ENDPOINT) {\n\t\tconfig.endpoint = env.RIVET_ENDPOINT;\n\t}\n\tif (!config.namespace && env.RIVET_NAMESPACE) {\n\t\tconfig.namespace = env.RIVET_NAMESPACE;\n\t}\n\tif (!config.token && env.RIVET_TOKEN) {\n\t\tconfig.token = env.RIVET_TOKEN;\n\t}\n\tif (env.RIVET_POOL && !config.envoy?.poolName) {\n\t\tconfig.envoy = { ...config.envoy, poolName: env.RIVET_POOL };\n\t}\n\tif (!config.serverless?.basePath) {\n\t\tconfig.serverless = { ...config.serverless, basePath: managerPath };\n\t}\n}\n\n/**\n * Creates a Cloudflare Workers handler that hosts Rivet Actors on the wasm\n * runtime. Accepts either a registry from this package's `setup` or a setup\n * config (which is wired through `setup` for you).\n *\n * The Rivet manager API is mounted at `managerPath` (default `/api/rivet`).\n * Requests outside that path are routed to `options.fetch` if provided, letting\n * you mount your own routes alongside Rivet. The engine endpoint is read from\n * `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)\n * unless set in the config.\n */\nexport function createHandler<A extends RegistryActors>(\n\tregistry: Registry<A>,\n\toptions?: CreateHandlerOptions,\n): CloudflareHandler;\nexport function createHandler<A extends RegistryActors>(\n\tconfig: CloudflareSetupConfig<A>,\n\toptions?: CreateHandlerOptions,\n): CloudflareHandler;\nexport function createHandler<A extends RegistryActors>(\n\tregistryOrConfig: Registry<A> | CloudflareSetupConfig<A>,\n\toptions: CreateHandlerOptions = {},\n): CloudflareHandler {\n\tconst managerPath = options.managerPath ?? DEFAULT_MANAGER_PATH;\n\tconst registry =\n\t\tregistryOrConfig instanceof Registry\n\t\t\t? registryOrConfig\n\t\t\t: setup(registryOrConfig);\n\tlet envApplied = false;\n\n\treturn {\n\t\tasync fetch(request, env, ctx) {\n\t\t\tif (!envApplied) {\n\t\t\t\tapplyEnv(\n\t\t\t\t\tregistry as Registry<RegistryActors>,\n\t\t\t\t\t(env ?? {}) as EnvRecord,\n\t\t\t\t\tmanagerPath,\n\t\t\t\t);\n\t\t\t\tenvApplied = true;\n\t\t\t}\n\n\t\t\tconst url = new URL(request.url);\n\t\t\tif (\n\t\t\t\turl.pathname === managerPath ||\n\t\t\t\turl.pathname.startsWith(`${managerPath}/`)\n\t\t\t) {\n\t\t\t\treturn registry.handler(request);\n\t\t\t}\n\n\t\t\tif (options.fetch) {\n\t\t\t\treturn options.fetch(request, env, ctx);\n\t\t\t}\n\n\t\t\treturn new Response(\n\t\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivet.dev\\n\",\n\t\t\t);\n\t\t},\n\t};\n}\n","// Cloudflare Workers do not implement an outbound `new WebSocket(url)` client\n// constructor, but the wasm actor runtime opens its tunnel to the Rivet engine\n// through `globalThis.WebSocket`. This shim translates that constructor into\n// Cloudflare's fetch-based upgrade (`fetch(url, { Upgrade })` + `response.webSocket`)\n// and installs itself on `globalThis` so both the wasm tunnel and the TypeScript\n// client path resolve a working implementation.\n\ntype WebSocketProtocolInput = string | string[] | undefined;\n\ntype CloudflareSocket = WebSocket & { accept(): void };\n\nclass FetchWebSocket {\n\tstatic readonly CONNECTING = 0;\n\tstatic readonly OPEN = 1;\n\tstatic readonly CLOSING = 2;\n\tstatic readonly CLOSED = 3;\n\n\tbinaryType: BinaryType = \"arraybuffer\";\n\tonopen: ((event: Event) => void) | null = null;\n\tonmessage: ((event: MessageEvent) => void) | null = null;\n\tonclose: ((event: CloseEvent) => void) | null = null;\n\tonerror: ((event: Event) => void) | null = null;\n\treadyState = FetchWebSocket.CONNECTING;\n\t#socket: CloudflareSocket | undefined;\n\t#pending: Array<string | ArrayBuffer | ArrayBufferView> = [];\n\n\tconstructor(url: string, protocols?: WebSocketProtocolInput) {\n\t\tvoid this.#connect(url, protocols);\n\t}\n\n\tasync #connect(url: string, protocols?: WebSocketProtocolInput) {\n\t\ttry {\n\t\t\tconst protocolList = Array.isArray(protocols)\n\t\t\t\t? protocols\n\t\t\t\t: protocols\n\t\t\t\t\t? [protocols]\n\t\t\t\t\t: [];\n\t\t\tconst headers = new Headers({ Upgrade: \"websocket\" });\n\t\t\tif (protocolList.length > 0) {\n\t\t\t\theaders.set(\"Sec-WebSocket-Protocol\", protocolList.join(\", \"));\n\t\t\t}\n\t\t\tconst response = await fetch(\n\t\t\t\turl.replace(/^ws:/, \"http:\").replace(/^wss:/, \"https:\"),\n\t\t\t\t{ headers },\n\t\t\t);\n\t\t\tconst socket = (\n\t\t\t\tresponse as unknown as { webSocket: CloudflareSocket | null }\n\t\t\t).webSocket;\n\t\t\tif (!socket) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`websocket upgrade failed with status ${response.status}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tsocket.accept();\n\t\t\tsocket.binaryType = this.binaryType;\n\t\t\tthis.#socket = socket;\n\t\t\tthis.readyState = FetchWebSocket.OPEN;\n\t\t\tsocket.addEventListener(\"message\", (event) => {\n\t\t\t\tthis.onmessage?.(event);\n\t\t\t});\n\t\t\tsocket.addEventListener(\"close\", (event) => {\n\t\t\t\tthis.readyState = FetchWebSocket.CLOSED;\n\t\t\t\tthis.onclose?.(event);\n\t\t\t});\n\t\t\tsocket.addEventListener(\"error\", (event) => {\n\t\t\t\tthis.onerror?.(event);\n\t\t\t});\n\t\t\tthis.onopen?.(new Event(\"open\"));\n\t\t\tfor (const data of this.#pending.splice(0)) {\n\t\t\t\tsocket.send(data);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"rivetkit cloudflare websocket shim failed\", error);\n\t\t\tthis.readyState = FetchWebSocket.CLOSED;\n\t\t\tthis.onerror?.(error instanceof Event ? error : new Event(\"error\"));\n\t\t\tthis.onclose?.(new CloseEvent(\"close\", { code: 1006 }));\n\t\t}\n\t}\n\n\tsend(data: string | ArrayBuffer | ArrayBufferView) {\n\t\tif (this.readyState === FetchWebSocket.CONNECTING) {\n\t\t\tthis.#pending.push(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.#socket?.send(data);\n\t}\n\n\tclose(code?: number, reason?: string) {\n\t\tthis.readyState = FetchWebSocket.CLOSING;\n\t\tthis.#socket?.close(code, reason);\n\t}\n}\n\nconst globalScope = globalThis as unknown as {\n\tWebSocket: typeof WebSocket;\n\t__RIVETKIT_CF_WEBSOCKET_INSTALLED__?: boolean;\n};\n\n// Install once per isolate.\nif (!globalScope.__RIVETKIT_CF_WEBSOCKET_INSTALLED__) {\n\tglobalScope.WebSocket = FetchWebSocket as unknown as typeof WebSocket;\n\tglobalScope.__RIVETKIT_CF_WEBSOCKET_INSTALLED__ = true;\n}\n\nexport { FetchWebSocket };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/cloudflare-workers",
|
|
3
|
-
"version": "0.0.0-sqlite-
|
|
3
|
+
"version": "0.0.0-sqlite-profiling-compat.4a9a623",
|
|
4
4
|
"description": "Cloudflare Workers integration for RivetKit actors",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -41,13 +41,18 @@
|
|
|
41
41
|
"check-types": "tsc --noEmit"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@rivetkit/rivetkit-wasm": "0.0.0-sqlite-
|
|
45
|
-
"rivetkit": "0.0.0-sqlite-
|
|
44
|
+
"@rivetkit/rivetkit-wasm": "0.0.0-sqlite-profiling-compat.4a9a623",
|
|
45
|
+
"rivetkit": "0.0.0-sqlite-profiling-compat.4a9a623"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^22.0.0",
|
|
49
49
|
"tsup": "^8.4.0",
|
|
50
50
|
"typescript": "^5.5.2"
|
|
51
51
|
},
|
|
52
|
-
"stableVersion": "0.8.0"
|
|
52
|
+
"stableVersion": "0.8.0",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/rivet-dev/actors.git",
|
|
56
|
+
"directory": "rivetkit-typescript/packages/cloudflare-workers"
|
|
57
|
+
}
|
|
53
58
|
}
|