@signe/room 2.10.0 → 3.0.1

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/chunk-EUXUH3YW.js +15 -0
  3. package/dist/chunk-EUXUH3YW.js.map +1 -0
  4. package/dist/cloudflare/index.d.ts +71 -0
  5. package/dist/cloudflare/index.js +320 -0
  6. package/dist/cloudflare/index.js.map +1 -0
  7. package/dist/index.d.ts +87 -188
  8. package/dist/index.js +860 -114
  9. package/dist/index.js.map +1 -1
  10. package/dist/node/index.d.ts +164 -0
  11. package/dist/node/index.js +786 -0
  12. package/dist/node/index.js.map +1 -0
  13. package/dist/party-dNs-hqkq.d.ts +175 -0
  14. package/examples/cloudflare/README.md +62 -0
  15. package/examples/cloudflare/node_modules/.bin/tsc +17 -0
  16. package/examples/cloudflare/node_modules/.bin/tsserver +17 -0
  17. package/examples/cloudflare/node_modules/.bin/wrangler +17 -0
  18. package/examples/cloudflare/node_modules/.bin/wrangler2 +17 -0
  19. package/examples/cloudflare/package.json +24 -0
  20. package/examples/cloudflare/public/index.html +443 -0
  21. package/examples/cloudflare/src/index.ts +28 -0
  22. package/examples/cloudflare/src/room.ts +44 -0
  23. package/examples/cloudflare/tsconfig.json +10 -0
  24. package/examples/cloudflare/wrangler.jsonc +25 -0
  25. package/examples/node/README.md +57 -0
  26. package/examples/node/node_modules/.bin/tsc +17 -0
  27. package/examples/node/node_modules/.bin/tsserver +17 -0
  28. package/examples/node/node_modules/.bin/tsx +17 -0
  29. package/examples/node/package.json +23 -0
  30. package/examples/node/public/index.html +443 -0
  31. package/examples/node/room.ts +44 -0
  32. package/examples/node/server.sqlite.ts +52 -0
  33. package/examples/node/server.ts +51 -0
  34. package/examples/node/tsconfig.json +10 -0
  35. package/examples/node-game/README.md +66 -0
  36. package/examples/node-game/package.json +23 -0
  37. package/examples/node-game/public/index.html +705 -0
  38. package/examples/node-game/room.ts +145 -0
  39. package/examples/node-game/server.sqlite.ts +54 -0
  40. package/examples/node-game/server.ts +53 -0
  41. package/examples/node-game/tsconfig.json +10 -0
  42. package/examples/node-shard/README.md +32 -0
  43. package/examples/node-shard/dev.ts +39 -0
  44. package/examples/node-shard/package.json +24 -0
  45. package/examples/node-shard/public/index.html +777 -0
  46. package/examples/node-shard/room-server.ts +68 -0
  47. package/examples/node-shard/room.ts +105 -0
  48. package/examples/node-shard/shared.ts +6 -0
  49. package/examples/node-shard/tsconfig.json +14 -0
  50. package/examples/node-shard/world-server.ts +169 -0
  51. package/package.json +14 -5
  52. package/readme.md +418 -4
  53. package/src/cloudflare/index.ts +474 -0
  54. package/src/index.ts +2 -2
  55. package/src/jwt.ts +1 -5
  56. package/src/mock.ts +29 -7
  57. package/src/node/index.ts +1112 -0
  58. package/src/server.ts +781 -60
  59. package/src/session.guard.ts +6 -2
  60. package/src/shard.ts +91 -23
  61. package/src/storage.ts +29 -5
  62. package/src/testing.ts +4 -3
  63. package/src/types/party.ts +30 -1
  64. package/src/world.guard.ts +23 -4
  65. package/src/world.ts +121 -21
  66. package/tests/storage-restore.spec.ts +122 -0
  67. package/examples/game/.vscode/launch.json +0 -11
  68. package/examples/game/.vscode/settings.json +0 -11
  69. package/examples/game/README.md +0 -40
  70. package/examples/game/app/client.tsx +0 -15
  71. package/examples/game/app/components/Admin.tsx +0 -1089
  72. package/examples/game/app/components/Room.tsx +0 -162
  73. package/examples/game/app/styles.css +0 -31
  74. package/examples/game/package-lock.json +0 -225
  75. package/examples/game/package.json +0 -20
  76. package/examples/game/party/game.room.ts +0 -32
  77. package/examples/game/party/server.ts +0 -10
  78. package/examples/game/party/shard.ts +0 -5
  79. package/examples/game/partykit.json +0 -14
  80. package/examples/game/public/favicon.ico +0 -0
  81. package/examples/game/public/index.html +0 -27
  82. package/examples/game/public/normalize.css +0 -351
  83. package/examples/game/shared/room.schema.ts +0 -14
  84. package/examples/game/tsconfig.json +0 -109
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @signe/room
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Add multi-world room support, shard authorization, enhanced world stats, and stable session handling across reconnects and multiple tabs.
8
+ - Add Cloudflare Durable Object, Node shard, and Node game examples for the 3.0 room runtime.
9
+
3
10
  ## 2.10.0
4
11
 
5
12
  ### Minor Changes
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
12
+ export {
13
+ __decorateClass
14
+ };
15
+ //# sourceMappingURL=chunk-EUXUH3YW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,71 @@
1
+ import * as _cloudflare_workers_types from '@cloudflare/workers-types';
2
+ import { DurableObjectState, WebSocket } from '@cloudflare/workers-types';
3
+ import { S as Server, a as Room, c as Storage, e as Context, C as Connection, f as ConnectionState, g as ConnectionSetStateFn } from '../party-dNs-hqkq.js';
4
+
5
+ type CloudflareRoomServerConstructor<TServer extends Server = Server> = {
6
+ new (room: Room): TServer;
7
+ };
8
+ type CloudflareRoomWorkerOptions = {
9
+ binding: string;
10
+ partiesPath?: string;
11
+ env?: Record<string, unknown>;
12
+ rooms?: Record<string, CloudflareRoomServerConstructor>;
13
+ };
14
+ type CloudflareRoomEnv = Record<string, unknown>;
15
+ declare function createCloudflareRoomWorker<TServer extends Server>(ServerClass: CloudflareRoomServerConstructor<TServer>, options: CloudflareRoomWorkerOptions): {
16
+ fetch(request: Request, env: CloudflareRoomEnv, ctx: unknown): Promise<Response>;
17
+ };
18
+ declare function dispatchCloudflareRoomRequest(request: Request, env: CloudflareRoomEnv, _ctx?: unknown): Promise<Response>;
19
+ declare class SigneRoomDurableObject {
20
+ private readonly ctx;
21
+ private readonly env;
22
+ private recordPromise?;
23
+ constructor(ctx: DurableObjectState, env: CloudflareRoomEnv);
24
+ fetch(request: Request): Promise<Response>;
25
+ alarm(): Promise<void>;
26
+ private acceptWebSocket;
27
+ private getRecord;
28
+ private createRecord;
29
+ }
30
+ declare class CloudflareRoom implements Room {
31
+ readonly id: string;
32
+ readonly internalID: string;
33
+ readonly name: string;
34
+ readonly env: Record<string, unknown>;
35
+ readonly storage: Storage;
36
+ readonly context: Context;
37
+ readonly connections: Map<string, Connection<unknown>>;
38
+ readonly parties: Context["parties"];
39
+ readonly analytics: _cloudflare_workers_types.AnalyticsEngineDataset;
40
+ constructor(options: {
41
+ id: string;
42
+ name: string;
43
+ env: Record<string, unknown>;
44
+ state: DurableObjectState;
45
+ binding: string;
46
+ partiesPath: string;
47
+ });
48
+ blockConcurrencyWhile: Room["blockConcurrencyWhile"];
49
+ broadcast(msg: string | ArrayBuffer | ArrayBufferView, without?: string[]): void;
50
+ getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
51
+ getConnections<TState = unknown>(): Iterable<Connection<TState>>;
52
+ addConnection(connection: CloudflareConnection): void;
53
+ deleteConnection(id: string, connection?: CloudflareConnection): void;
54
+ }
55
+ declare class CloudflareConnection<TState = unknown> {
56
+ private readonly webSocket;
57
+ readonly id: string;
58
+ readonly sessionId: string;
59
+ readonly socket: this;
60
+ readonly uri: string;
61
+ state: ConnectionState<TState> | TState | null;
62
+ private attachment;
63
+ constructor(webSocket: WebSocket, uri: string, sessionId?: string);
64
+ send(data: string | ArrayBuffer | ArrayBufferView): void;
65
+ close(code?: number, reason?: string): void;
66
+ setState(state: TState | ConnectionSetStateFn<TState> | null): { readonly [K in keyof TState]: TState[K] extends infer T ? T extends TState[K] ? T extends string | number | boolean ? T : T extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T extends Set<infer M> ? ReadonlySet<any> : { readonly [K_3 in keyof T]: T[K_3] extends infer T_1 ? T_1 extends T[K_3] ? T_1 extends string | number | boolean ? T_1 : T_1 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_1 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_1 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_4 in keyof T_1]: T_1[K_4] extends infer T_2 ? T_2 extends T_1[K_4] ? T_2 extends string | number | boolean ? T_2 : T_2 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_2 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_2 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_5 in keyof T_2]: T_2[K_5] extends infer T_3 ? T_3 extends T_2[K_5] ? T_3 extends string | number | boolean ? T_3 : T_3 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_3 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_3 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_6 in keyof T_3]: T_3[K_6] extends infer T_4 ? T_4 extends T_3[K_6] ? T_4 extends string | number | boolean ? T_4 : T_4 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_4 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_4 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_7 in keyof T_4]: T_4[K_7] extends infer T_5 ? T_5 extends T_4[K_7] ? T_5 extends string | number | boolean ? T_5 : T_5 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_5 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_5 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_8 in keyof T_5]: T_5[K_8] extends infer T_6 ? T_6 extends T_5[K_8] ? T_6 extends string | number | boolean ? T_6 : T_6 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_6 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_6 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_9 in keyof T_6]: T_6[K_9] extends infer T_7 ? T_7 extends T_6[K_9] ? T_7 extends string | number | boolean ? T_7 : T_7 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_7 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_7 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_10 in keyof T_7]: T_7[K_10] extends infer T_8 ? T_8 extends T_7[K_10] ? T_8 extends string | number | boolean ? T_8 : T_8 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_8 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_8 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_11 in keyof T_8]: T_8[K_11] extends infer T_9 ? T_9 extends T_8[K_11] ? T_9 extends string | number | boolean ? T_9 : T_9 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_9 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_9 extends Set<infer M> ? ReadonlySet<any> : { readonly [K_12 in keyof T_9]: T_9[K_12] extends infer T_10 ? T_10 extends T_9[K_12] ? T_10 extends string | number | boolean ? T_10 : T_10 extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly (U extends string | number | boolean ? U : U extends (infer U)[] ? readonly any[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : U extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : U extends Set<infer M> ? ReadonlySet<any> : { readonly [K_2 in keyof U]: any; })[] : T_10 extends Map<infer K_1, infer V> ? ReadonlyMap<any, any> : T_10 extends Set<infer M> ? ReadonlySet<any> : any : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; };
67
+ serializeAttachment<T = unknown>(attachment: T): void;
68
+ deserializeAttachment<T = unknown>(): T | null;
69
+ }
70
+
71
+ export { CloudflareConnection, CloudflareRoom, type CloudflareRoomEnv, type CloudflareRoomServerConstructor, type CloudflareRoomWorkerOptions, SigneRoomDurableObject, createCloudflareRoomWorker, dispatchCloudflareRoomRequest };
@@ -0,0 +1,320 @@
1
+ import "../chunk-EUXUH3YW.js";
2
+
3
+ // src/cloudflare/index.ts
4
+ var DEFAULT_PARTIES_PATH = "/parties/main";
5
+ var WEBSOCKET_OPEN = 1;
6
+ var runtimeConfig;
7
+ function createCloudflareRoomWorker(ServerClass, options) {
8
+ runtimeConfig = createRuntimeConfig(ServerClass, options);
9
+ return {
10
+ async fetch(request, env, ctx) {
11
+ return dispatchCloudflareRoomRequest(request, env, ctx);
12
+ }
13
+ };
14
+ }
15
+ async function dispatchCloudflareRoomRequest(request, env, _ctx) {
16
+ const config = getRuntimeConfig();
17
+ const parsed = parsePartyRequest(request.url, config.partiesPath);
18
+ if (!parsed) {
19
+ return new Response("Not Found", { status: 404 });
20
+ }
21
+ const namespace = getNamespace(env, config.binding);
22
+ const stub = namespace.get(namespace.idFromName(parsed.roomId));
23
+ return fetchDurableObjectStub(stub, request);
24
+ }
25
+ var SigneRoomDurableObject = class {
26
+ constructor(ctx, env) {
27
+ this.ctx = ctx;
28
+ this.env = env;
29
+ }
30
+ async fetch(request) {
31
+ const config = getRuntimeConfig();
32
+ const parsed = parsePartyRequest(request.url, config.partiesPath);
33
+ if (!parsed) {
34
+ return new Response("Not Found", { status: 404 });
35
+ }
36
+ if (isWebSocketUpgrade(request)) {
37
+ return this.acceptWebSocket(request, parsed);
38
+ }
39
+ const record = await this.getRecord(parsed);
40
+ return record.server.onRequest?.(request) ?? new Response("Not Found", { status: 404 });
41
+ }
42
+ async alarm() {
43
+ const record = await this.recordPromise;
44
+ await record?.server.onAlarm?.();
45
+ }
46
+ async acceptWebSocket(request, parsed) {
47
+ const pair = new WebSocketPair();
48
+ const [client, server] = Object.values(pair);
49
+ const record = await this.getRecord(parsed);
50
+ const connection = new CloudflareConnection(
51
+ server,
52
+ request.url,
53
+ getConnectionIdFromUrl(request.url)
54
+ );
55
+ server.accept();
56
+ await record.server.onConnect?.(connection, {
57
+ request
58
+ });
59
+ server.addEventListener("message", (event) => {
60
+ void record.server.onMessage?.(
61
+ normalizeWebSocketMessage(event.data),
62
+ connection
63
+ );
64
+ });
65
+ server.addEventListener("close", () => {
66
+ record.room.deleteConnection(connection.id, connection);
67
+ void record.server.onClose?.(connection);
68
+ });
69
+ server.addEventListener("error", (event) => {
70
+ const errorData = event.error;
71
+ const error = errorData instanceof Error ? errorData : new Error(event.message ?? "Cloudflare WebSocket error");
72
+ void record.server.onError?.(connection, error);
73
+ });
74
+ record.room.addConnection(connection);
75
+ return new Response(null, {
76
+ status: 101,
77
+ webSocket: client
78
+ });
79
+ }
80
+ async getRecord(parsed) {
81
+ if (!this.recordPromise) {
82
+ this.recordPromise = this.createRecord(parsed);
83
+ }
84
+ return this.recordPromise;
85
+ }
86
+ async createRecord(parsed) {
87
+ const config = getRuntimeConfig();
88
+ const ServerClass = config.rooms[parsed.namespace] ?? config.ServerClass;
89
+ const room = new CloudflareRoom({
90
+ id: parsed.roomId,
91
+ name: parsed.namespace,
92
+ env: {
93
+ ...config.env,
94
+ ...this.env
95
+ },
96
+ state: this.ctx,
97
+ binding: config.binding,
98
+ partiesPath: config.partiesPath
99
+ });
100
+ const server = new ServerClass(room);
101
+ const record = {
102
+ room,
103
+ server,
104
+ started: Promise.resolve(server.onStart?.()).then(() => void 0)
105
+ };
106
+ await record.started;
107
+ return record;
108
+ }
109
+ };
110
+ var CloudflareRoom = class {
111
+ constructor(options) {
112
+ this.connections = /* @__PURE__ */ new Map();
113
+ this.analytics = {};
114
+ this.id = options.id;
115
+ this.internalID = `${options.name}:${options.id}`;
116
+ this.name = options.name;
117
+ this.env = options.env;
118
+ this.storage = options.state.storage;
119
+ this.parties = createPartiesContext(options.env, options.binding, options.partiesPath);
120
+ this.context = {
121
+ parties: this.parties,
122
+ ai: {},
123
+ vectorize: {},
124
+ analytics: this.analytics,
125
+ assets: {
126
+ fetch: async () => null
127
+ },
128
+ bindings: {
129
+ r2: {},
130
+ kv: {}
131
+ }
132
+ };
133
+ this.blockConcurrencyWhile = options.state.blockConcurrencyWhile.bind(options.state);
134
+ }
135
+ broadcast(msg, without = []) {
136
+ for (const connection of this.connections.values()) {
137
+ if (!without.includes(connection.id)) {
138
+ connection.send(msg);
139
+ }
140
+ }
141
+ }
142
+ getConnection(id) {
143
+ let connection;
144
+ for (const current of this.connections.values()) {
145
+ if (current.id === id || current.sessionId === id) {
146
+ connection = current;
147
+ }
148
+ }
149
+ return connection;
150
+ }
151
+ getConnections() {
152
+ return Array.from(this.connections.values());
153
+ }
154
+ addConnection(connection) {
155
+ this.connections.set(connection.id, connection);
156
+ }
157
+ deleteConnection(id, connection) {
158
+ if (connection) {
159
+ this.connections.delete(connection.id);
160
+ return;
161
+ }
162
+ for (const [connectionKey, current] of this.connections) {
163
+ if (current.id === id || current.sessionId === id) {
164
+ this.connections.delete(connectionKey);
165
+ }
166
+ }
167
+ }
168
+ };
169
+ var CloudflareConnection = class {
170
+ constructor(webSocket, uri, sessionId) {
171
+ this.webSocket = webSocket;
172
+ this.id = createConnectionId();
173
+ this.socket = this;
174
+ this.state = null;
175
+ this.attachment = null;
176
+ this.sessionId = sessionId || this.id;
177
+ this.uri = uri;
178
+ }
179
+ send(data) {
180
+ if (this.webSocket.readyState === void 0 || this.webSocket.readyState === WEBSOCKET_OPEN) {
181
+ this.webSocket.send(data);
182
+ }
183
+ }
184
+ close(code, reason) {
185
+ this.webSocket.close(code, reason);
186
+ }
187
+ setState(state) {
188
+ this.state = typeof state === "function" ? state(this.state) : state;
189
+ return this.state;
190
+ }
191
+ serializeAttachment(attachment) {
192
+ this.attachment = attachment;
193
+ }
194
+ deserializeAttachment() {
195
+ return this.attachment;
196
+ }
197
+ };
198
+ function createRuntimeConfig(ServerClass, options) {
199
+ return {
200
+ ServerClass,
201
+ binding: options.binding,
202
+ partiesPath: normalizePath(options.partiesPath ?? DEFAULT_PARTIES_PATH),
203
+ env: options.env ?? {},
204
+ rooms: {
205
+ main: ServerClass,
206
+ ...options.rooms ?? {}
207
+ }
208
+ };
209
+ }
210
+ function getRuntimeConfig() {
211
+ if (!runtimeConfig) {
212
+ throw new Error(
213
+ "createCloudflareRoomWorker() must be called before using SigneRoomDurableObject."
214
+ );
215
+ }
216
+ return runtimeConfig;
217
+ }
218
+ function createPartiesContext(env, binding, partiesPath) {
219
+ return new Proxy({}, {
220
+ get(_target, namespace) {
221
+ return {
222
+ get(roomId) {
223
+ return {
224
+ connect: () => {
225
+ throw new Error("Party stub connect() is not implemented by @signe/room/cloudflare");
226
+ },
227
+ socket: async () => {
228
+ throw new Error("Party stub socket() is not implemented by @signe/room/cloudflare");
229
+ },
230
+ fetch(pathOrInit, init) {
231
+ const namespaceBinding = getNamespace(env, binding);
232
+ const stub = namespaceBinding.get(namespaceBinding.idFromName(roomId));
233
+ if (pathOrInit instanceof Request) {
234
+ return fetchDurableObjectStub(stub, pathOrInit);
235
+ }
236
+ const path = typeof pathOrInit === "string" ? pathOrInit : "/";
237
+ const requestInit = typeof pathOrInit === "string" ? init : pathOrInit;
238
+ return fetchDurableObjectStub(
239
+ stub,
240
+ toLocalUrl(`${getNamespacePath(partiesPath, namespace, roomId)}${normalizeStubPath(path)}`),
241
+ requestInit
242
+ );
243
+ }
244
+ };
245
+ }
246
+ };
247
+ }
248
+ });
249
+ }
250
+ function getNamespace(env, binding) {
251
+ const namespace = env[binding];
252
+ if (!namespace) {
253
+ throw new Error(`Missing Durable Object binding: ${binding}`);
254
+ }
255
+ return namespace;
256
+ }
257
+ function fetchDurableObjectStub(stub, input, init) {
258
+ return stub.fetch(input, init);
259
+ }
260
+ function parsePartyRequest(url, partiesPath) {
261
+ const requestUrl = new URL(url);
262
+ const segments = trimSlashes(requestUrl.pathname).split("/");
263
+ const configuredSegments = trimSlashes(partiesPath).split("/");
264
+ const baseSegments = configuredSegments.slice(0, -1);
265
+ if (segments.length < baseSegments.length + 2) {
266
+ return null;
267
+ }
268
+ for (let index = 0; index < baseSegments.length; index++) {
269
+ if (segments[index] !== baseSegments[index]) {
270
+ return null;
271
+ }
272
+ }
273
+ return {
274
+ namespace: decodeURIComponent(segments[baseSegments.length]),
275
+ roomId: decodeURIComponent(segments[baseSegments.length + 1])
276
+ };
277
+ }
278
+ function getNamespacePath(partiesPath, namespace, roomId) {
279
+ const baseSegments = trimSlashes(partiesPath).split("/").slice(0, -1);
280
+ return `/${[...baseSegments, namespace, encodeURIComponent(roomId)].join("/")}`;
281
+ }
282
+ function isWebSocketUpgrade(request) {
283
+ return request.headers.get("Upgrade")?.toLowerCase() === "websocket";
284
+ }
285
+ function normalizeWebSocketMessage(data) {
286
+ if (typeof data === "string" || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
287
+ return data;
288
+ }
289
+ return String(data);
290
+ }
291
+ function normalizePath(path) {
292
+ return `/${trimSlashes(path)}`;
293
+ }
294
+ function toLocalUrl(path) {
295
+ return path.startsWith("http://") || path.startsWith("https://") ? path : `http://localhost${path.startsWith("/") ? path : `/${path}`}`;
296
+ }
297
+ function normalizeStubPath(path) {
298
+ if (!path || path === "/") {
299
+ return "";
300
+ }
301
+ return path.startsWith("/") ? path : `/${path}`;
302
+ }
303
+ function getConnectionIdFromUrl(url) {
304
+ const requestedId = new URL(url).searchParams.get("id")?.trim();
305
+ return requestedId || void 0;
306
+ }
307
+ function trimSlashes(value) {
308
+ return value.replace(/^\/+|\/+$/g, "");
309
+ }
310
+ function createConnectionId() {
311
+ return Math.random().toString(36).slice(2, 12);
312
+ }
313
+ export {
314
+ CloudflareConnection,
315
+ CloudflareRoom,
316
+ SigneRoomDurableObject,
317
+ createCloudflareRoomWorker,
318
+ dispatchCloudflareRoomRequest
319
+ };
320
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cloudflare/index.ts"],"sourcesContent":["import type {\n DurableObjectNamespace,\n DurableObjectState,\n WebSocket as CloudflareWebSocket,\n} from \"@cloudflare/workers-types\";\nimport type * as Party from \"../types/party\";\n\nexport type CloudflareRoomServerConstructor<TServer extends Party.Server = Party.Server> = {\n new (room: Party.Room): TServer;\n};\n\nexport type CloudflareRoomWorkerOptions = {\n binding: string;\n partiesPath?: string;\n env?: Record<string, unknown>;\n rooms?: Record<string, CloudflareRoomServerConstructor>;\n};\n\nexport type CloudflareRoomEnv = Record<string, unknown>;\n\ntype ParsedPartyPath = {\n namespace: string;\n roomId: string;\n};\n\ntype CloudflareRoomRecord = {\n room: CloudflareRoom;\n server: Party.Server;\n started: Promise<void>;\n};\n\ntype CloudflareRuntimeConfig = Required<Pick<CloudflareRoomWorkerOptions, \"binding\" | \"partiesPath\">> & {\n ServerClass: CloudflareRoomServerConstructor;\n env: Record<string, unknown>;\n rooms: Record<string, CloudflareRoomServerConstructor>;\n};\n\nconst DEFAULT_PARTIES_PATH = \"/parties/main\";\nconst WEBSOCKET_OPEN = 1;\n\nlet runtimeConfig: CloudflareRuntimeConfig | undefined;\n\nexport function createCloudflareRoomWorker<TServer extends Party.Server>(\n ServerClass: CloudflareRoomServerConstructor<TServer>,\n options: CloudflareRoomWorkerOptions\n) {\n runtimeConfig = createRuntimeConfig(ServerClass, options);\n\n return {\n async fetch(\n request: Request,\n env: CloudflareRoomEnv,\n ctx: unknown\n ): Promise<Response> {\n return dispatchCloudflareRoomRequest(request, env, ctx);\n },\n };\n}\n\nexport async function dispatchCloudflareRoomRequest(\n request: Request,\n env: CloudflareRoomEnv,\n _ctx?: unknown\n): Promise<Response> {\n const config = getRuntimeConfig();\n const parsed = parsePartyRequest(request.url, config.partiesPath);\n\n if (!parsed) {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n const namespace = getNamespace(env, config.binding);\n const stub = namespace.get(namespace.idFromName(parsed.roomId));\n return fetchDurableObjectStub(stub, request);\n}\n\nexport class SigneRoomDurableObject {\n private recordPromise?: Promise<CloudflareRoomRecord>;\n\n constructor(\n private readonly ctx: DurableObjectState,\n private readonly env: CloudflareRoomEnv\n ) {}\n\n async fetch(request: Request): Promise<Response> {\n const config = getRuntimeConfig();\n const parsed = parsePartyRequest(request.url, config.partiesPath);\n\n if (!parsed) {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n if (isWebSocketUpgrade(request)) {\n return this.acceptWebSocket(request, parsed);\n }\n\n const record = await this.getRecord(parsed);\n return record.server.onRequest?.(request as unknown as Party.Request)\n ?? new Response(\"Not Found\", { status: 404 });\n }\n\n async alarm(): Promise<void> {\n const record = await this.recordPromise;\n await record?.server.onAlarm?.();\n }\n\n private async acceptWebSocket(\n request: Request,\n parsed: ParsedPartyPath\n ): Promise<Response> {\n const pair = new WebSocketPair();\n const [client, server] = Object.values(pair) as [\n CloudflareWebSocket,\n CloudflareWebSocket,\n ];\n const record = await this.getRecord(parsed);\n const connection = new CloudflareConnection(\n server,\n request.url,\n getConnectionIdFromUrl(request.url)\n );\n\n server.accept();\n\n await record.server.onConnect?.(connection as unknown as Party.Connection, {\n request: request as unknown as Party.Request,\n });\n\n server.addEventListener(\"message\", (event) => {\n void record.server.onMessage?.(\n normalizeWebSocketMessage(event.data),\n connection as unknown as Party.Connection\n );\n });\n server.addEventListener(\"close\", () => {\n record.room.deleteConnection(connection.id, connection);\n void record.server.onClose?.(connection as unknown as Party.Connection);\n });\n server.addEventListener(\"error\", (event) => {\n const errorData = (event as { error?: unknown; message?: string }).error;\n const error = errorData instanceof Error\n ? errorData\n : new Error((event as { message?: string }).message ?? \"Cloudflare WebSocket error\");\n void record.server.onError?.(connection as unknown as Party.Connection, error);\n });\n record.room.addConnection(connection);\n\n return new Response(null, {\n status: 101,\n webSocket: client,\n } as ResponseInit & { webSocket: CloudflareWebSocket });\n }\n\n private async getRecord(parsed: ParsedPartyPath): Promise<CloudflareRoomRecord> {\n if (!this.recordPromise) {\n this.recordPromise = this.createRecord(parsed);\n }\n\n return this.recordPromise;\n }\n\n private async createRecord(parsed: ParsedPartyPath): Promise<CloudflareRoomRecord> {\n const config = getRuntimeConfig();\n const ServerClass = config.rooms[parsed.namespace] ?? config.ServerClass;\n const room = new CloudflareRoom({\n id: parsed.roomId,\n name: parsed.namespace,\n env: {\n ...config.env,\n ...this.env,\n },\n state: this.ctx,\n binding: config.binding,\n partiesPath: config.partiesPath,\n });\n const server = new ServerClass(room as Party.Room);\n const record: CloudflareRoomRecord = {\n room,\n server,\n started: Promise.resolve(server.onStart?.()).then(() => undefined),\n };\n\n await record.started;\n return record;\n }\n}\n\nexport class CloudflareRoom implements Party.Room {\n readonly id: string;\n readonly internalID: string;\n readonly name: string;\n readonly env: Record<string, unknown>;\n readonly storage: Party.Storage;\n readonly context: Party.Context;\n readonly connections = new Map<string, Party.Connection>();\n readonly parties: Party.Context[\"parties\"];\n readonly analytics = {} as Party.Room[\"analytics\"];\n\n constructor(options: {\n id: string;\n name: string;\n env: Record<string, unknown>;\n state: DurableObjectState;\n binding: string;\n partiesPath: string;\n }) {\n this.id = options.id;\n this.internalID = `${options.name}:${options.id}`;\n this.name = options.name;\n this.env = options.env;\n this.storage = options.state.storage as Party.Storage;\n this.parties = createPartiesContext(options.env, options.binding, options.partiesPath);\n this.context = {\n parties: this.parties,\n ai: {},\n vectorize: {},\n analytics: this.analytics,\n assets: {\n fetch: async () => null,\n },\n bindings: {\n r2: {},\n kv: {},\n },\n } as Party.Context;\n this.blockConcurrencyWhile = options.state.blockConcurrencyWhile.bind(options.state);\n }\n\n blockConcurrencyWhile: Party.Room[\"blockConcurrencyWhile\"];\n\n broadcast(msg: string | ArrayBuffer | ArrayBufferView, without: string[] = []) {\n for (const connection of this.connections.values()) {\n if (!without.includes(connection.id)) {\n connection.send(msg);\n }\n }\n }\n\n getConnection<TState = unknown>(id: string): Party.Connection<TState> | undefined {\n let connection: Party.Connection | undefined;\n for (const current of this.connections.values()) {\n if (current.id === id || current.sessionId === id) {\n connection = current;\n }\n }\n return connection as Party.Connection<TState> | undefined;\n }\n\n getConnections<TState = unknown>(): Iterable<Party.Connection<TState>> {\n return Array.from(this.connections.values()) as Party.Connection<TState>[];\n }\n\n addConnection(connection: CloudflareConnection) {\n this.connections.set(connection.id, connection as unknown as Party.Connection);\n }\n\n deleteConnection(id: string, connection?: CloudflareConnection) {\n if (connection) {\n this.connections.delete(connection.id);\n return;\n }\n\n for (const [connectionKey, current] of this.connections) {\n if (current.id === id || current.sessionId === id) {\n this.connections.delete(connectionKey);\n }\n }\n }\n}\n\nexport class CloudflareConnection<TState = unknown> {\n readonly id = createConnectionId();\n readonly sessionId: string;\n readonly socket: this = this;\n readonly uri: string;\n state: Party.ConnectionState<TState> | TState | null = null;\n private attachment: unknown = null;\n\n constructor(\n private readonly webSocket: CloudflareWebSocket,\n uri: string,\n sessionId?: string\n ) {\n this.sessionId = sessionId || this.id;\n this.uri = uri;\n }\n\n send(data: string | ArrayBuffer | ArrayBufferView) {\n if (\n this.webSocket.readyState === undefined ||\n this.webSocket.readyState === WEBSOCKET_OPEN\n ) {\n this.webSocket.send(data);\n }\n }\n\n close(code?: number, reason?: string) {\n this.webSocket.close(code, reason);\n }\n\n setState(state: TState | Party.ConnectionSetStateFn<TState> | null) {\n this.state = typeof state === \"function\"\n ? (state as Party.ConnectionSetStateFn<TState>)(this.state as Party.ConnectionState<TState>)\n : state;\n return this.state as Party.ConnectionState<TState>;\n }\n\n serializeAttachment<T = unknown>(attachment: T): void {\n this.attachment = attachment;\n }\n\n deserializeAttachment<T = unknown>(): T | null {\n return this.attachment as T | null;\n }\n}\n\nfunction createRuntimeConfig<TServer extends Party.Server>(\n ServerClass: CloudflareRoomServerConstructor<TServer>,\n options: CloudflareRoomWorkerOptions\n): CloudflareRuntimeConfig {\n return {\n ServerClass: ServerClass as CloudflareRoomServerConstructor,\n binding: options.binding,\n partiesPath: normalizePath(options.partiesPath ?? DEFAULT_PARTIES_PATH),\n env: options.env ?? {},\n rooms: {\n main: ServerClass as CloudflareRoomServerConstructor,\n ...(options.rooms ?? {}),\n },\n };\n}\n\nfunction getRuntimeConfig(): CloudflareRuntimeConfig {\n if (!runtimeConfig) {\n throw new Error(\n \"createCloudflareRoomWorker() must be called before using SigneRoomDurableObject.\"\n );\n }\n\n return runtimeConfig;\n}\n\nfunction createPartiesContext(\n env: Record<string, unknown>,\n binding: string,\n partiesPath: string\n): Party.Context[\"parties\"] {\n return new Proxy({}, {\n get(_target, namespace: string) {\n return {\n get(roomId: string) {\n return {\n connect: () => {\n throw new Error(\"Party stub connect() is not implemented by @signe/room/cloudflare\");\n },\n socket: async () => {\n throw new Error(\"Party stub socket() is not implemented by @signe/room/cloudflare\");\n },\n fetch(pathOrInit?: string | RequestInit | Request, init?: RequestInit) {\n const namespaceBinding = getNamespace(env, binding);\n const stub = namespaceBinding.get(namespaceBinding.idFromName(roomId));\n if (pathOrInit instanceof Request) {\n return fetchDurableObjectStub(stub, pathOrInit);\n }\n const path = typeof pathOrInit === \"string\" ? pathOrInit : \"/\";\n const requestInit = typeof pathOrInit === \"string\" ? init : pathOrInit;\n return fetchDurableObjectStub(\n stub,\n toLocalUrl(`${getNamespacePath(partiesPath, namespace, roomId)}${normalizeStubPath(path)}`),\n requestInit as RequestInit | undefined\n );\n },\n };\n },\n };\n },\n }) as Party.Context[\"parties\"];\n}\n\nfunction getNamespace(env: Record<string, unknown>, binding: string) {\n const namespace = env[binding] as DurableObjectNamespace | undefined;\n\n if (!namespace) {\n throw new Error(`Missing Durable Object binding: ${binding}`);\n }\n\n return namespace;\n}\n\nfunction fetchDurableObjectStub(\n stub: unknown,\n input: Request | string | URL,\n init?: RequestInit\n): Promise<Response> {\n return (stub as {\n fetch(request: Request | string | URL, init?: RequestInit): Promise<Response>;\n }).fetch(input, init);\n}\n\nfunction parsePartyRequest(url: string, partiesPath: string): ParsedPartyPath | null {\n const requestUrl = new URL(url);\n const segments = trimSlashes(requestUrl.pathname).split(\"/\");\n const configuredSegments = trimSlashes(partiesPath).split(\"/\");\n const baseSegments = configuredSegments.slice(0, -1);\n\n if (segments.length < baseSegments.length + 2) {\n return null;\n }\n\n for (let index = 0; index < baseSegments.length; index++) {\n if (segments[index] !== baseSegments[index]) {\n return null;\n }\n }\n\n return {\n namespace: decodeURIComponent(segments[baseSegments.length]),\n roomId: decodeURIComponent(segments[baseSegments.length + 1]),\n };\n}\n\nfunction getNamespacePath(partiesPath: string, namespace: string, roomId: string) {\n const baseSegments = trimSlashes(partiesPath).split(\"/\").slice(0, -1);\n return `/${[...baseSegments, namespace, encodeURIComponent(roomId)].join(\"/\")}`;\n}\n\nfunction isWebSocketUpgrade(request: Request) {\n return request.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\";\n}\n\nfunction normalizeWebSocketMessage(data: unknown): string | ArrayBuffer | ArrayBufferView {\n if (typeof data === \"string\" || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {\n return data;\n }\n\n return String(data);\n}\n\nfunction normalizePath(path: string) {\n return `/${trimSlashes(path)}`;\n}\n\nfunction toLocalUrl(path: string) {\n return path.startsWith(\"http://\") || path.startsWith(\"https://\")\n ? path\n : `http://localhost${path.startsWith(\"/\") ? path : `/${path}`}`;\n}\n\nfunction normalizeStubPath(path: string) {\n if (!path || path === \"/\") {\n return \"\";\n }\n return path.startsWith(\"/\") ? path : `/${path}`;\n}\n\nfunction getConnectionIdFromUrl(url: string) {\n const requestedId = new URL(url).searchParams.get(\"id\")?.trim();\n return requestedId || undefined;\n}\n\nfunction trimSlashes(value: string) {\n return value.replace(/^\\/+|\\/+$/g, \"\");\n}\n\nfunction createConnectionId() {\n return Math.random().toString(36).slice(2, 12);\n}\n\ndeclare const WebSocketPair: {\n new (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