y-partyserver 1.0.0 → 2.0.0
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/server/index.js +137 -145
- package/dist/server/index.js.map +1 -1
- package/package.json +3 -3
package/dist/server/index.js
CHANGED
|
@@ -18,6 +18,27 @@ if (!("OPEN" in WebSocket)) {
|
|
|
18
18
|
Object.assign(WebSocket, WebSocketStatus);
|
|
19
19
|
Object.assign(WebSocket.prototype, WebSocketStatus);
|
|
20
20
|
}
|
|
21
|
+
function tryGetPartyServerMeta(ws) {
|
|
22
|
+
try {
|
|
23
|
+
const attachment = WebSocket.prototype.deserializeAttachment.call(ws);
|
|
24
|
+
if (!attachment || typeof attachment !== "object") return null;
|
|
25
|
+
if (!("__pk" in attachment)) return null;
|
|
26
|
+
const pk = attachment.__pk;
|
|
27
|
+
if (!pk || typeof pk !== "object") return null;
|
|
28
|
+
const { id, server, tags } = pk;
|
|
29
|
+
if (typeof id !== "string" || typeof server !== "string") return null;
|
|
30
|
+
return {
|
|
31
|
+
id,
|
|
32
|
+
server,
|
|
33
|
+
tags: Array.isArray(tags) ? tags : []
|
|
34
|
+
};
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function isPartyServerWebSocket(ws) {
|
|
40
|
+
return tryGetPartyServerMeta(ws) !== null;
|
|
41
|
+
}
|
|
21
42
|
/**
|
|
22
43
|
* Cache websocket attachments to avoid having to rehydrate them on every property access.
|
|
23
44
|
*/
|
|
@@ -60,29 +81,44 @@ const createLazyConnection = (ws) => {
|
|
|
60
81
|
server: { get() {
|
|
61
82
|
return attachments.get(ws).__pk.server;
|
|
62
83
|
} },
|
|
84
|
+
tags: { get() {
|
|
85
|
+
return attachments.get(ws).__pk.tags ?? [];
|
|
86
|
+
} },
|
|
63
87
|
socket: { get() {
|
|
64
88
|
return ws;
|
|
65
89
|
} },
|
|
66
|
-
state: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
state: {
|
|
91
|
+
configurable: true,
|
|
92
|
+
get() {
|
|
93
|
+
return ws.deserializeAttachment();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
setState: {
|
|
97
|
+
configurable: true,
|
|
98
|
+
value: function setState(setState$1) {
|
|
99
|
+
let state;
|
|
100
|
+
if (setState$1 instanceof Function) state = setState$1(this.state);
|
|
101
|
+
else state = setState$1;
|
|
102
|
+
ws.serializeAttachment(state);
|
|
103
|
+
return state;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
deserializeAttachment: {
|
|
107
|
+
configurable: true,
|
|
108
|
+
value: function deserializeAttachment() {
|
|
109
|
+
return attachments.get(ws).__user ?? null;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
serializeAttachment: {
|
|
113
|
+
configurable: true,
|
|
114
|
+
value: function serializeAttachment(attachment) {
|
|
115
|
+
const setting = {
|
|
116
|
+
...attachments.get(ws),
|
|
117
|
+
__user: attachment ?? null
|
|
118
|
+
};
|
|
119
|
+
attachments.set(ws, setting);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
86
122
|
});
|
|
87
123
|
if (initialState) connection.setState(initialState);
|
|
88
124
|
connections.add(connection);
|
|
@@ -101,10 +137,13 @@ var HibernatingConnectionIterator = class {
|
|
|
101
137
|
next() {
|
|
102
138
|
const sockets = this.sockets ?? (this.sockets = this.state.getWebSockets(this.tag));
|
|
103
139
|
let socket;
|
|
104
|
-
while (socket = sockets[this.index++]) if (socket.readyState === WebSocket.READY_STATE_OPEN)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
140
|
+
while (socket = sockets[this.index++]) if (socket.readyState === WebSocket.READY_STATE_OPEN) {
|
|
141
|
+
if (!isPartyServerWebSocket(socket)) continue;
|
|
142
|
+
return {
|
|
143
|
+
done: false,
|
|
144
|
+
value: createLazyConnection(socket)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
108
147
|
return {
|
|
109
148
|
done: true,
|
|
110
149
|
value: void 0
|
|
@@ -112,6 +151,20 @@ var HibernatingConnectionIterator = class {
|
|
|
112
151
|
}
|
|
113
152
|
};
|
|
114
153
|
/**
|
|
154
|
+
* Deduplicate and validate connection tags.
|
|
155
|
+
* Returns the final tag array (always includes the connection id as the first tag).
|
|
156
|
+
*/
|
|
157
|
+
function prepareTags(connectionId, userTags) {
|
|
158
|
+
const tags = [connectionId, ...userTags.filter((t) => t !== connectionId)];
|
|
159
|
+
if (tags.length > 10) throw new Error("A connection can only have 10 tags, including the default id tag.");
|
|
160
|
+
for (const tag of tags) {
|
|
161
|
+
if (typeof tag !== "string") throw new Error(`A connection tag must be a string. Received: ${tag}`);
|
|
162
|
+
if (tag === "") throw new Error("A connection tag must not be an empty string.");
|
|
163
|
+
if (tag.length > 256) throw new Error("A connection tag must not exceed 256 characters");
|
|
164
|
+
}
|
|
165
|
+
return tags;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
115
168
|
* When not using hibernation, we track active connections manually.
|
|
116
169
|
*/
|
|
117
170
|
var InMemoryConnectionManager = class {
|
|
@@ -132,8 +185,13 @@ var InMemoryConnectionManager = class {
|
|
|
132
185
|
}
|
|
133
186
|
accept(connection, options) {
|
|
134
187
|
connection.accept();
|
|
188
|
+
const tags = prepareTags(connection.id, options.tags);
|
|
135
189
|
this.#connections.set(connection.id, connection);
|
|
136
|
-
this.tags.set(connection,
|
|
190
|
+
this.tags.set(connection, tags);
|
|
191
|
+
Object.defineProperty(connection, "tags", {
|
|
192
|
+
get: () => tags,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
137
195
|
const removeConnection = () => {
|
|
138
196
|
this.#connections.delete(connection.id);
|
|
139
197
|
connection.removeEventListener("close", removeConnection);
|
|
@@ -152,30 +210,29 @@ var HibernatingConnectionManager = class {
|
|
|
152
210
|
this.controller = controller;
|
|
153
211
|
}
|
|
154
212
|
getCount() {
|
|
155
|
-
|
|
213
|
+
let count = 0;
|
|
214
|
+
for (const ws of this.controller.getWebSockets()) if (isPartyServerWebSocket(ws)) count++;
|
|
215
|
+
return count;
|
|
156
216
|
}
|
|
157
217
|
getConnection(id) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
218
|
+
const matching = this.controller.getWebSockets(id).filter((ws) => {
|
|
219
|
+
return tryGetPartyServerMeta(ws)?.id === id;
|
|
220
|
+
});
|
|
221
|
+
if (matching.length === 0) return void 0;
|
|
222
|
+
if (matching.length === 1) return createLazyConnection(matching[0]);
|
|
161
223
|
throw new Error(`More than one connection found for id ${id}. Did you mean to use getConnections(tag) instead?`);
|
|
162
224
|
}
|
|
163
225
|
getConnections(tag) {
|
|
164
226
|
return new HibernatingConnectionIterator(this.controller, tag);
|
|
165
227
|
}
|
|
166
228
|
accept(connection, options) {
|
|
167
|
-
const tags =
|
|
168
|
-
if (tags.length > 10) throw new Error("A connection can only have 10 tags, including the default id tag.");
|
|
169
|
-
for (const tag of tags) {
|
|
170
|
-
if (typeof tag !== "string") throw new Error(`A connection tag must be a string. Received: ${tag}`);
|
|
171
|
-
if (tag === "") throw new Error("A connection tag must not be an empty string.");
|
|
172
|
-
if (tag.length > 256) throw new Error("A connection tag must not exceed 256 characters");
|
|
173
|
-
}
|
|
229
|
+
const tags = prepareTags(connection.id, options.tags);
|
|
174
230
|
this.controller.acceptWebSocket(connection, tags);
|
|
175
231
|
connection.serializeAttachment({
|
|
176
232
|
__pk: {
|
|
177
233
|
id: connection.id,
|
|
178
|
-
server: options.server
|
|
234
|
+
server: options.server,
|
|
235
|
+
tags
|
|
179
236
|
},
|
|
180
237
|
__user: null
|
|
181
238
|
});
|
|
@@ -211,32 +268,17 @@ var Server = class extends DurableObject {
|
|
|
211
268
|
* Handle incoming requests to the server.
|
|
212
269
|
*/
|
|
213
270
|
async fetch(request) {
|
|
214
|
-
const props = request.headers.get("x-partykit-props");
|
|
215
|
-
if (props) try {
|
|
216
|
-
this.#_props = JSON.parse(props);
|
|
217
|
-
} catch {
|
|
218
|
-
console.error("Internal error parsing context props.");
|
|
219
|
-
}
|
|
220
|
-
if (!this.#_name) {
|
|
221
|
-
const room = request.headers.get("x-partykit-room");
|
|
222
|
-
if (!room) throw new Error(`Missing namespace or room headers when connecting to ${this.#ParentClass.name}.
|
|
223
|
-
Did you try connecting directly to this Durable Object? Try using getServerByName(namespace, id) instead.`);
|
|
224
|
-
await this.setName(room);
|
|
225
|
-
}
|
|
226
271
|
try {
|
|
272
|
+
const props = request.headers.get("x-partykit-props");
|
|
273
|
+
if (props) this.#_props = JSON.parse(props);
|
|
274
|
+
if (!this.#_name) {
|
|
275
|
+
const room = request.headers.get("x-partykit-room");
|
|
276
|
+
if (!room) throw new Error(`Missing namespace or room headers when connecting to ${this.#ParentClass.name}.
|
|
277
|
+
Did you try connecting directly to this Durable Object? Try using getServerByName(namespace, id) instead.`);
|
|
278
|
+
await this.setName(room);
|
|
279
|
+
} else if (this.#status !== "started") await this.#initialize();
|
|
227
280
|
const url = new URL(request.url);
|
|
228
281
|
if (url.pathname === "/cdn-cgi/partyserver/set-name/") return Response.json({ ok: true });
|
|
229
|
-
if (url.pathname === "/cdn-cgi/partyserver/keep-alive/") {
|
|
230
|
-
if (request.headers.get("Upgrade")?.toLowerCase() === "websocket") {
|
|
231
|
-
const { 0: client, 1: server } = new WebSocketPair();
|
|
232
|
-
this.ctx.acceptWebSocket(server, ["partyserver-keepalive"]);
|
|
233
|
-
return new Response(null, {
|
|
234
|
-
status: 101,
|
|
235
|
-
webSocket: client
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return new Response("WebSocket required", { status: 426 });
|
|
239
|
-
}
|
|
240
282
|
if (request.headers.get("Upgrade")?.toLowerCase() !== "websocket") return await this.onRequest(request);
|
|
241
283
|
else {
|
|
242
284
|
const { 0: clientWebSocket, 1: serverWebSocket } = new WebSocketPair();
|
|
@@ -245,6 +287,7 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
|
|
|
245
287
|
let connection = Object.assign(serverWebSocket, {
|
|
246
288
|
id: connectionId,
|
|
247
289
|
server: this.name,
|
|
290
|
+
tags: [],
|
|
248
291
|
state: null,
|
|
249
292
|
setState(setState) {
|
|
250
293
|
let state;
|
|
@@ -268,7 +311,7 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
|
|
|
268
311
|
});
|
|
269
312
|
}
|
|
270
313
|
} catch (err) {
|
|
271
|
-
console.error(`Error in ${this.#ParentClass.name}:${this
|
|
314
|
+
console.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? "<unnamed>"} fetch:`, err);
|
|
272
315
|
if (!(err instanceof Error)) throw err;
|
|
273
316
|
if (request.headers.get("Upgrade") === "websocket") {
|
|
274
317
|
const pair = new WebSocketPair();
|
|
@@ -283,35 +326,48 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
|
|
|
283
326
|
}
|
|
284
327
|
}
|
|
285
328
|
async webSocketMessage(ws, message) {
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
329
|
+
if (!isPartyServerWebSocket(ws)) return;
|
|
330
|
+
try {
|
|
331
|
+
const connection = createLazyConnection(ws);
|
|
332
|
+
await this.setName(connection.server);
|
|
333
|
+
return this.onMessage(connection, message);
|
|
334
|
+
} catch (e) {
|
|
335
|
+
console.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? "<unnamed>"} webSocketMessage:`, e);
|
|
289
336
|
}
|
|
290
|
-
const connection = createLazyConnection(ws);
|
|
291
|
-
await this.setName(connection.server);
|
|
292
|
-
if (this.#status !== "started") await this.#initialize();
|
|
293
|
-
return this.onMessage(connection, message);
|
|
294
337
|
}
|
|
295
338
|
async webSocketClose(ws, code, reason, wasClean) {
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
339
|
+
if (!isPartyServerWebSocket(ws)) return;
|
|
340
|
+
try {
|
|
341
|
+
const connection = createLazyConnection(ws);
|
|
342
|
+
await this.setName(connection.server);
|
|
343
|
+
return this.onClose(connection, code, reason, wasClean);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
console.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? "<unnamed>"} webSocketClose:`, e);
|
|
346
|
+
}
|
|
301
347
|
}
|
|
302
348
|
async webSocketError(ws, error) {
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
349
|
+
if (!isPartyServerWebSocket(ws)) return;
|
|
350
|
+
try {
|
|
351
|
+
const connection = createLazyConnection(ws);
|
|
352
|
+
await this.setName(connection.server);
|
|
353
|
+
return this.onError(connection, error);
|
|
354
|
+
} catch (e) {
|
|
355
|
+
console.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? "<unnamed>"} webSocketError:`, e);
|
|
356
|
+
}
|
|
308
357
|
}
|
|
309
358
|
async #initialize() {
|
|
359
|
+
let error;
|
|
310
360
|
await this.ctx.blockConcurrencyWhile(async () => {
|
|
311
361
|
this.#status = "starting";
|
|
312
|
-
|
|
313
|
-
|
|
362
|
+
try {
|
|
363
|
+
await this.onStart(this.#_props);
|
|
364
|
+
this.#status = "started";
|
|
365
|
+
} catch (e) {
|
|
366
|
+
this.#status = "zero";
|
|
367
|
+
error = e;
|
|
368
|
+
}
|
|
314
369
|
});
|
|
370
|
+
if (error) throw error;
|
|
315
371
|
}
|
|
316
372
|
#attachSocketEventHandlers(connection) {
|
|
317
373
|
const handleMessageFromClient = (event) => {
|
|
@@ -353,9 +409,7 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
|
|
|
353
409
|
if (!name) throw new Error("A name is required.");
|
|
354
410
|
if (this.#_name && this.#_name !== name) throw new Error(`This server already has a name: ${this.#_name}, attempting to set to: ${name}`);
|
|
355
411
|
this.#_name = name;
|
|
356
|
-
if (this.#status !== "started") await this
|
|
357
|
-
await this.#initialize();
|
|
358
|
-
});
|
|
412
|
+
if (this.#status !== "started") await this.#initialize();
|
|
359
413
|
}
|
|
360
414
|
#sendMessageToConnection(connection, message) {
|
|
361
415
|
try {
|
|
@@ -386,68 +440,6 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
|
|
|
386
440
|
getConnectionTags(connection, context) {
|
|
387
441
|
return [];
|
|
388
442
|
}
|
|
389
|
-
/**
|
|
390
|
-
* Execute a long-running async function while keeping the Durable Object alive.
|
|
391
|
-
*
|
|
392
|
-
* Durable Objects normally terminate 70-140s after the last network request.
|
|
393
|
-
* This method keeps the DO alive by establishing a WebSocket connection to itself
|
|
394
|
-
* and sending periodic ping messages.
|
|
395
|
-
*
|
|
396
|
-
* @experimental This API is experimental and may change in future versions.
|
|
397
|
-
*
|
|
398
|
-
* @param fn - The async function to execute
|
|
399
|
-
* @param timeoutMs - Maximum time to keep the DO alive (default: 30 minutes)
|
|
400
|
-
* @returns The result of the async function
|
|
401
|
-
*
|
|
402
|
-
* @remarks
|
|
403
|
-
* Requires the `enable_ctx_exports` compatibility flag in wrangler.jsonc:
|
|
404
|
-
* ```json
|
|
405
|
-
* {
|
|
406
|
-
* "compatibility_flags": ["enable_ctx_exports"]
|
|
407
|
-
* }
|
|
408
|
-
* ```
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* ```typescript
|
|
412
|
-
* const result = await this.experimental_waitUntil(async () => {
|
|
413
|
-
* // Long-running operation
|
|
414
|
-
* await processLargeDataset();
|
|
415
|
-
* return { success: true };
|
|
416
|
-
* }, 60 * 60 * 1000); // 1 hour timeout
|
|
417
|
-
* ```
|
|
418
|
-
*/
|
|
419
|
-
async experimental_waitUntil(fn, timeoutMs = 1800 * 1e3) {
|
|
420
|
-
const exports = this.ctx.exports;
|
|
421
|
-
if (!exports) throw new Error("waitUntil requires the 'enable_ctx_exports' compatibility flag. Add it to your wrangler.jsonc: { \"compatibility_flags\": [\"enable_ctx_exports\"] }");
|
|
422
|
-
const namespace = exports[this.#ParentClass.name];
|
|
423
|
-
if (!namespace) throw new Error(`Could not find namespace for ${this.#ParentClass.name} in ctx.exports. Make sure the class name matches your Durable Object binding.`);
|
|
424
|
-
const ws = (await namespace.get(this.ctx.id).fetch("http://dummy-example.cloudflare.com/cdn-cgi/partyserver/keep-alive/", { headers: {
|
|
425
|
-
Upgrade: "websocket",
|
|
426
|
-
"x-partykit-room": this.name
|
|
427
|
-
} })).webSocket;
|
|
428
|
-
if (!ws) throw new Error("Failed to establish keep-alive WebSocket connection");
|
|
429
|
-
ws.accept();
|
|
430
|
-
const pingInterval = setInterval(() => {
|
|
431
|
-
try {
|
|
432
|
-
ws.send("ping");
|
|
433
|
-
} catch {}
|
|
434
|
-
}, 1e4);
|
|
435
|
-
let timeoutId;
|
|
436
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
437
|
-
timeoutId = setTimeout(() => {
|
|
438
|
-
reject(/* @__PURE__ */ new Error(`experimental_waitUntil timed out after ${timeoutMs}ms`));
|
|
439
|
-
}, timeoutMs);
|
|
440
|
-
});
|
|
441
|
-
try {
|
|
442
|
-
return await Promise.race([fn(), timeoutPromise]);
|
|
443
|
-
} finally {
|
|
444
|
-
clearTimeout(timeoutId);
|
|
445
|
-
clearInterval(pingInterval);
|
|
446
|
-
try {
|
|
447
|
-
ws.close(1e3, "Complete");
|
|
448
|
-
} catch {}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
443
|
#_props;
|
|
452
444
|
/**
|
|
453
445
|
* Called when the server is started for the first time.
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#cache","#connections","#ParentClass","#_props","#_name","#connectionManager","#attachSocketEventHandlers","#status","#initialize","#_longErrorAboutNameThrown","#sendMessageToConnection","YDoc","controlledIds: Set<number>","#ParentClass","encoder"],"sources":["../../../partyserver/dist/index.js","../../src/server/index.ts"],"sourcesContent":["import { DurableObject, env } from \"cloudflare:workers\";\nimport { nanoid } from \"nanoid\";\n\n//#region src/connection.ts\nif (!(\"OPEN\" in WebSocket)) {\n\tconst WebSocketStatus = {\n\t\tCONNECTING: WebSocket.READY_STATE_CONNECTING,\n\t\tOPEN: WebSocket.READY_STATE_OPEN,\n\t\tCLOSING: WebSocket.READY_STATE_CLOSING,\n\t\tCLOSED: WebSocket.READY_STATE_CLOSED\n\t};\n\tObject.assign(WebSocket, WebSocketStatus);\n\tObject.assign(WebSocket.prototype, WebSocketStatus);\n}\n/**\n* Cache websocket attachments to avoid having to rehydrate them on every property access.\n*/\nvar AttachmentCache = class {\n\t#cache = /* @__PURE__ */ new WeakMap();\n\tget(ws) {\n\t\tlet attachment = this.#cache.get(ws);\n\t\tif (!attachment) {\n\t\t\tattachment = WebSocket.prototype.deserializeAttachment.call(ws);\n\t\t\tif (attachment !== void 0) this.#cache.set(ws, attachment);\n\t\t\telse throw new Error(\"Missing websocket attachment. This is most likely an issue in PartyServer, please open an issue at https://github.com/cloudflare/partykit/issues\");\n\t\t}\n\t\treturn attachment;\n\t}\n\tset(ws, attachment) {\n\t\tthis.#cache.set(ws, attachment);\n\t\tWebSocket.prototype.serializeAttachment.call(ws, attachment);\n\t}\n};\nconst attachments = new AttachmentCache();\nconst connections = /* @__PURE__ */ new WeakSet();\nconst isWrapped = (ws) => {\n\treturn connections.has(ws);\n};\n/**\n* Wraps a WebSocket with Connection fields that rehydrate the\n* socket attachments lazily only when requested.\n*/\nconst createLazyConnection = (ws) => {\n\tif (isWrapped(ws)) return ws;\n\tlet initialState;\n\tif (\"state\" in ws) {\n\t\tinitialState = ws.state;\n\t\tdelete ws.state;\n\t}\n\tconst connection = Object.defineProperties(ws, {\n\t\tid: { get() {\n\t\t\treturn attachments.get(ws).__pk.id;\n\t\t} },\n\t\tserver: { get() {\n\t\t\treturn attachments.get(ws).__pk.server;\n\t\t} },\n\t\tsocket: { get() {\n\t\t\treturn ws;\n\t\t} },\n\t\tstate: { get() {\n\t\t\treturn ws.deserializeAttachment();\n\t\t} },\n\t\tsetState: { value: function setState(setState$1) {\n\t\t\tlet state;\n\t\t\tif (setState$1 instanceof Function) state = setState$1(this.state);\n\t\t\telse state = setState$1;\n\t\t\tws.serializeAttachment(state);\n\t\t\treturn state;\n\t\t} },\n\t\tdeserializeAttachment: { value: function deserializeAttachment() {\n\t\t\treturn attachments.get(ws).__user ?? null;\n\t\t} },\n\t\tserializeAttachment: { value: function serializeAttachment(attachment) {\n\t\t\tconst setting = {\n\t\t\t\t...attachments.get(ws),\n\t\t\t\t__user: attachment ?? null\n\t\t\t};\n\t\t\tattachments.set(ws, setting);\n\t\t} }\n\t});\n\tif (initialState) connection.setState(initialState);\n\tconnections.add(connection);\n\treturn connection;\n};\nvar HibernatingConnectionIterator = class {\n\tindex = 0;\n\tsockets;\n\tconstructor(state, tag) {\n\t\tthis.state = state;\n\t\tthis.tag = tag;\n\t}\n\t[Symbol.iterator]() {\n\t\treturn this;\n\t}\n\tnext() {\n\t\tconst sockets = this.sockets ?? (this.sockets = this.state.getWebSockets(this.tag));\n\t\tlet socket;\n\t\twhile (socket = sockets[this.index++]) if (socket.readyState === WebSocket.READY_STATE_OPEN) return {\n\t\t\tdone: false,\n\t\t\tvalue: createLazyConnection(socket)\n\t\t};\n\t\treturn {\n\t\t\tdone: true,\n\t\t\tvalue: void 0\n\t\t};\n\t}\n};\n/**\n* When not using hibernation, we track active connections manually.\n*/\nvar InMemoryConnectionManager = class {\n\t#connections = /* @__PURE__ */ new Map();\n\ttags = /* @__PURE__ */ new WeakMap();\n\tgetCount() {\n\t\treturn this.#connections.size;\n\t}\n\tgetConnection(id) {\n\t\treturn this.#connections.get(id);\n\t}\n\t*getConnections(tag) {\n\t\tif (!tag) {\n\t\t\tyield* this.#connections.values().filter((c) => c.readyState === WebSocket.READY_STATE_OPEN);\n\t\t\treturn;\n\t\t}\n\t\tfor (const connection of this.#connections.values()) if ((this.tags.get(connection) ?? []).includes(tag)) yield connection;\n\t}\n\taccept(connection, options) {\n\t\tconnection.accept();\n\t\tthis.#connections.set(connection.id, connection);\n\t\tthis.tags.set(connection, [connection.id, ...options.tags.filter((t) => t !== connection.id)]);\n\t\tconst removeConnection = () => {\n\t\t\tthis.#connections.delete(connection.id);\n\t\t\tconnection.removeEventListener(\"close\", removeConnection);\n\t\t\tconnection.removeEventListener(\"error\", removeConnection);\n\t\t};\n\t\tconnection.addEventListener(\"close\", removeConnection);\n\t\tconnection.addEventListener(\"error\", removeConnection);\n\t\treturn connection;\n\t}\n};\n/**\n* When opting into hibernation, the platform tracks connections for us.\n*/\nvar HibernatingConnectionManager = class {\n\tconstructor(controller) {\n\t\tthis.controller = controller;\n\t}\n\tgetCount() {\n\t\treturn Number(this.controller.getWebSockets().length);\n\t}\n\tgetConnection(id) {\n\t\tconst sockets = this.controller.getWebSockets(id);\n\t\tif (sockets.length === 0) return void 0;\n\t\tif (sockets.length === 1) return createLazyConnection(sockets[0]);\n\t\tthrow new Error(`More than one connection found for id ${id}. Did you mean to use getConnections(tag) instead?`);\n\t}\n\tgetConnections(tag) {\n\t\treturn new HibernatingConnectionIterator(this.controller, tag);\n\t}\n\taccept(connection, options) {\n\t\tconst tags = [connection.id, ...options.tags.filter((t) => t !== connection.id)];\n\t\tif (tags.length > 10) throw new Error(\"A connection can only have 10 tags, including the default id tag.\");\n\t\tfor (const tag of tags) {\n\t\t\tif (typeof tag !== \"string\") throw new Error(`A connection tag must be a string. Received: ${tag}`);\n\t\t\tif (tag === \"\") throw new Error(\"A connection tag must not be an empty string.\");\n\t\t\tif (tag.length > 256) throw new Error(\"A connection tag must not exceed 256 characters\");\n\t\t}\n\t\tthis.controller.acceptWebSocket(connection, tags);\n\t\tconnection.serializeAttachment({\n\t\t\t__pk: {\n\t\t\t\tid: connection.id,\n\t\t\t\tserver: options.server\n\t\t\t},\n\t\t\t__user: null\n\t\t});\n\t\treturn createLazyConnection(connection);\n\t}\n};\n\n//#endregion\n//#region src/index.ts\nconst serverMapCache = /* @__PURE__ */ new WeakMap();\n/**\n* For a given server namespace, create a server with a name.\n*/\nasync function getServerByName(serverNamespace, name, options) {\n\tif (options?.jurisdiction) serverNamespace = serverNamespace.jurisdiction(options.jurisdiction);\n\tconst id = serverNamespace.idFromName(name);\n\tconst stub = serverNamespace.get(id, options);\n\tconst req = new Request(\"http://dummy-example.cloudflare.com/cdn-cgi/partyserver/set-name/\");\n\treq.headers.set(\"x-partykit-room\", name);\n\tif (options?.props) req.headers.set(\"x-partykit-props\", JSON.stringify(options?.props));\n\tawait stub.fetch(req).then((res) => res.text()).catch((e) => {\n\t\tconsole.error(\"Could not set server name:\", e);\n\t});\n\treturn stub;\n}\nfunction camelCaseToKebabCase(str) {\n\tif (str === str.toUpperCase() && str !== str.toLowerCase()) return str.toLowerCase().replace(/_/g, \"-\");\n\tlet kebabified = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\tkebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n\treturn kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n/**\n* A utility function for PartyKit style routing.\n*/\nasync function routePartykitRequest(req, env$1 = env, options) {\n\tif (!serverMapCache.has(env$1)) serverMapCache.set(env$1, Object.entries(env$1).reduce((acc, [k, v]) => {\n\t\tif (v && typeof v === \"object\" && \"idFromName\" in v && typeof v.idFromName === \"function\") {\n\t\t\tObject.assign(acc, { [camelCaseToKebabCase(k)]: v });\n\t\t\treturn acc;\n\t\t}\n\t\treturn acc;\n\t}, {}));\n\tconst map = serverMapCache.get(env$1);\n\tconst prefixParts = (options?.prefix || \"parties\").split(\"/\");\n\tconst parts = new URL(req.url).pathname.split(\"/\").filter(Boolean);\n\tif (!prefixParts.every((part, index) => parts[index] === part) || parts.length < prefixParts.length + 2) return null;\n\tconst namespace = parts[prefixParts.length];\n\tconst name = parts[prefixParts.length + 1];\n\tif (name && namespace) {\n\t\tif (!map[namespace]) {\n\t\t\tif (namespace === \"main\") {\n\t\t\t\tconsole.warn(\"You appear to be migrating a PartyKit project to PartyServer.\");\n\t\t\t\tconsole.warn(`PartyServer doesn't have a \"main\" party by default. Try adding this to your PartySocket client:\\n \nparty: \"${camelCaseToKebabCase(Object.keys(map)[0])}\"`);\n\t\t\t} else console.error(`The url ${req.url} with namespace \"${namespace}\" and name \"${name}\" does not match any server namespace. \nDid you forget to add a durable object binding to the class ${namespace[0].toUpperCase() + namespace.slice(1)} in your wrangler.jsonc?`);\n\t\t\treturn new Response(\"Invalid request\", { status: 400 });\n\t\t}\n\t\tlet doNamespace = map[namespace];\n\t\tif (options?.jurisdiction) doNamespace = doNamespace.jurisdiction(options.jurisdiction);\n\t\tconst id = doNamespace.idFromName(name);\n\t\tconst stub = doNamespace.get(id, options);\n\t\treq = new Request(req);\n\t\treq.headers.set(\"x-partykit-room\", name);\n\t\treq.headers.set(\"x-partykit-namespace\", namespace);\n\t\tif (options?.jurisdiction) req.headers.set(\"x-partykit-jurisdiction\", options.jurisdiction);\n\t\tif (options?.props) req.headers.set(\"x-partykit-props\", JSON.stringify(options?.props));\n\t\tif (req.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\") {\n\t\t\tif (options?.onBeforeConnect) {\n\t\t\t\tconst reqOrRes = await options.onBeforeConnect(req, {\n\t\t\t\t\tparty: namespace,\n\t\t\t\t\tname\n\t\t\t\t});\n\t\t\t\tif (reqOrRes instanceof Request) req = reqOrRes;\n\t\t\t\telse if (reqOrRes instanceof Response) return reqOrRes;\n\t\t\t}\n\t\t} else if (options?.onBeforeRequest) {\n\t\t\tconst reqOrRes = await options.onBeforeRequest(req, {\n\t\t\t\tparty: namespace,\n\t\t\t\tname\n\t\t\t});\n\t\t\tif (reqOrRes instanceof Request) req = reqOrRes;\n\t\t\telse if (reqOrRes instanceof Response) return reqOrRes;\n\t\t}\n\t\treturn stub.fetch(req);\n\t} else return null;\n}\nvar Server = class extends DurableObject {\n\tstatic options = { hibernate: false };\n\t#status = \"zero\";\n\t#ParentClass = Object.getPrototypeOf(this).constructor;\n\t#connectionManager = this.#ParentClass.options.hibernate ? new HibernatingConnectionManager(this.ctx) : new InMemoryConnectionManager();\n\t/**\n\t* Execute SQL queries against the Server's database\n\t* @template T Type of the returned rows\n\t* @param strings SQL query template strings\n\t* @param values Values to be inserted into the query\n\t* @returns Array of query results\n\t*/\n\tsql(strings, ...values) {\n\t\tlet query = \"\";\n\t\ttry {\n\t\t\tquery = strings.reduce((acc, str, i) => acc + str + (i < values.length ? \"?\" : \"\"), \"\");\n\t\t\treturn [...this.ctx.storage.sql.exec(query, ...values)];\n\t\t} catch (e) {\n\t\t\tconsole.error(`failed to execute sql query: ${query}`, e);\n\t\t\tthrow this.onException(e);\n\t\t}\n\t}\n\tconstructor(ctx, env$1) {\n\t\tsuper(ctx, env$1);\n\t}\n\t/**\n\t* Handle incoming requests to the server.\n\t*/\n\tasync fetch(request) {\n\t\tconst props = request.headers.get(\"x-partykit-props\");\n\t\tif (props) try {\n\t\t\tthis.#_props = JSON.parse(props);\n\t\t} catch {\n\t\t\tconsole.error(\"Internal error parsing context props.\");\n\t\t}\n\t\tif (!this.#_name) {\n\t\t\tconst room = request.headers.get(\"x-partykit-room\");\n\t\t\tif (!room) throw new Error(`Missing namespace or room headers when connecting to ${this.#ParentClass.name}.\nDid you try connecting directly to this Durable Object? Try using getServerByName(namespace, id) instead.`);\n\t\t\tawait this.setName(room);\n\t\t}\n\t\ttry {\n\t\t\tconst url = new URL(request.url);\n\t\t\tif (url.pathname === \"/cdn-cgi/partyserver/set-name/\") return Response.json({ ok: true });\n\t\t\tif (url.pathname === \"/cdn-cgi/partyserver/keep-alive/\") {\n\t\t\t\tif (request.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\") {\n\t\t\t\t\tconst { 0: client, 1: server } = new WebSocketPair();\n\t\t\t\t\tthis.ctx.acceptWebSocket(server, [\"partyserver-keepalive\"]);\n\t\t\t\t\treturn new Response(null, {\n\t\t\t\t\t\tstatus: 101,\n\t\t\t\t\t\twebSocket: client\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn new Response(\"WebSocket required\", { status: 426 });\n\t\t\t}\n\t\t\tif (request.headers.get(\"Upgrade\")?.toLowerCase() !== \"websocket\") return await this.onRequest(request);\n\t\t\telse {\n\t\t\t\tconst { 0: clientWebSocket, 1: serverWebSocket } = new WebSocketPair();\n\t\t\t\tlet connectionId = url.searchParams.get(\"_pk\");\n\t\t\t\tif (!connectionId) connectionId = nanoid();\n\t\t\t\tlet connection = Object.assign(serverWebSocket, {\n\t\t\t\t\tid: connectionId,\n\t\t\t\t\tserver: this.name,\n\t\t\t\t\tstate: null,\n\t\t\t\t\tsetState(setState) {\n\t\t\t\t\t\tlet state;\n\t\t\t\t\t\tif (setState instanceof Function) state = setState(this.state);\n\t\t\t\t\t\telse state = setState;\n\t\t\t\t\t\tthis.state = state;\n\t\t\t\t\t\treturn this.state;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconst ctx = { request };\n\t\t\t\tconst tags = await this.getConnectionTags(connection, ctx);\n\t\t\t\tconnection = this.#connectionManager.accept(connection, {\n\t\t\t\t\ttags,\n\t\t\t\t\tserver: this.name\n\t\t\t\t});\n\t\t\t\tif (!this.#ParentClass.options.hibernate) this.#attachSocketEventHandlers(connection);\n\t\t\t\tawait this.onConnect(connection, ctx);\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 101,\n\t\t\t\t\twebSocket: clientWebSocket\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(`Error in ${this.#ParentClass.name}:${this.name} fetch:`, err);\n\t\t\tif (!(err instanceof Error)) throw err;\n\t\t\tif (request.headers.get(\"Upgrade\") === \"websocket\") {\n\t\t\t\tconst pair = new WebSocketPair();\n\t\t\t\tpair[1].accept();\n\t\t\t\tpair[1].send(JSON.stringify({ error: err.stack }));\n\t\t\t\tpair[1].close(1011, \"Uncaught exception during session setup\");\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 101,\n\t\t\t\t\twebSocket: pair[0]\n\t\t\t\t});\n\t\t\t} else return new Response(err.stack, { status: 500 });\n\t\t}\n\t}\n\tasync webSocketMessage(ws, message) {\n\t\tif (this.ctx.getTags(ws).includes(\"partyserver-keepalive\")) {\n\t\t\tif (message === \"ping\") ws.send(\"pong\");\n\t\t\treturn;\n\t\t}\n\t\tconst connection = createLazyConnection(ws);\n\t\tawait this.setName(connection.server);\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t\treturn this.onMessage(connection, message);\n\t}\n\tasync webSocketClose(ws, code, reason, wasClean) {\n\t\tif (this.ctx.getTags(ws).includes(\"partyserver-keepalive\")) return;\n\t\tconst connection = createLazyConnection(ws);\n\t\tawait this.setName(connection.server);\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t\treturn this.onClose(connection, code, reason, wasClean);\n\t}\n\tasync webSocketError(ws, error) {\n\t\tif (this.ctx.getTags(ws).includes(\"partyserver-keepalive\")) return;\n\t\tconst connection = createLazyConnection(ws);\n\t\tawait this.setName(connection.server);\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t\treturn this.onError(connection, error);\n\t}\n\tasync #initialize() {\n\t\tawait this.ctx.blockConcurrencyWhile(async () => {\n\t\t\tthis.#status = \"starting\";\n\t\t\tawait this.onStart(this.#_props);\n\t\t\tthis.#status = \"started\";\n\t\t});\n\t}\n\t#attachSocketEventHandlers(connection) {\n\t\tconst handleMessageFromClient = (event) => {\n\t\t\tthis.onMessage(connection, event.data)?.catch((e) => {\n\t\t\t\tconsole.error(\"onMessage error:\", e);\n\t\t\t});\n\t\t};\n\t\tconst handleCloseFromClient = (event) => {\n\t\t\tconnection.removeEventListener(\"message\", handleMessageFromClient);\n\t\t\tconnection.removeEventListener(\"close\", handleCloseFromClient);\n\t\t\tthis.onClose(connection, event.code, event.reason, event.wasClean)?.catch((e) => {\n\t\t\t\tconsole.error(\"onClose error:\", e);\n\t\t\t});\n\t\t};\n\t\tconst handleErrorFromClient = (e) => {\n\t\t\tconnection.removeEventListener(\"message\", handleMessageFromClient);\n\t\t\tconnection.removeEventListener(\"error\", handleErrorFromClient);\n\t\t\tthis.onError(connection, e.error)?.catch((e$1) => {\n\t\t\t\tconsole.error(\"onError error:\", e$1);\n\t\t\t});\n\t\t};\n\t\tconnection.addEventListener(\"close\", handleCloseFromClient);\n\t\tconnection.addEventListener(\"error\", handleErrorFromClient);\n\t\tconnection.addEventListener(\"message\", handleMessageFromClient);\n\t}\n\t#_name;\n\t#_longErrorAboutNameThrown = false;\n\t/**\n\t* The name for this server. Write-once-only.\n\t*/\n\tget name() {\n\t\tif (!this.#_name) if (!this.#_longErrorAboutNameThrown) {\n\t\t\tthis.#_longErrorAboutNameThrown = true;\n\t\t\tthrow new Error(`Attempting to read .name on ${this.#ParentClass.name} before it was set. The name can be set by explicitly calling .setName(name) on the stub, or by using routePartyKitRequest(). This is a known issue and will be fixed soon. Follow https://github.com/cloudflare/workerd/issues/2240 for more updates.`);\n\t\t} else throw new Error(`Attempting to read .name on ${this.#ParentClass.name} before it was set.`);\n\t\treturn this.#_name;\n\t}\n\tasync setName(name) {\n\t\tif (!name) throw new Error(\"A name is required.\");\n\t\tif (this.#_name && this.#_name !== name) throw new Error(`This server already has a name: ${this.#_name}, attempting to set to: ${name}`);\n\t\tthis.#_name = name;\n\t\tif (this.#status !== \"started\") await this.ctx.blockConcurrencyWhile(async () => {\n\t\t\tawait this.#initialize();\n\t\t});\n\t}\n\t#sendMessageToConnection(connection, message) {\n\t\ttry {\n\t\t\tconnection.send(message);\n\t\t} catch (_e) {\n\t\t\tconnection.close(1011, \"Unexpected error\");\n\t\t}\n\t}\n\t/** Send a message to all connected clients, except connection ids listed in `without` */\n\tbroadcast(msg, without) {\n\t\tfor (const connection of this.#connectionManager.getConnections()) if (!without || !without.includes(connection.id)) this.#sendMessageToConnection(connection, msg);\n\t}\n\t/** Get a connection by connection id */\n\tgetConnection(id) {\n\t\treturn this.#connectionManager.getConnection(id);\n\t}\n\t/**\n\t* Get all connections. Optionally, you can provide a tag to filter returned connections.\n\t* Use `Server#getConnectionTags` to tag the connection on connect.\n\t*/\n\tgetConnections(tag) {\n\t\treturn this.#connectionManager.getConnections(tag);\n\t}\n\t/**\n\t* You can tag a connection to filter them in Server#getConnections.\n\t* Each connection supports up to 9 tags, each tag max length is 256 characters.\n\t*/\n\tgetConnectionTags(connection, context) {\n\t\treturn [];\n\t}\n\t/**\n\t* Execute a long-running async function while keeping the Durable Object alive.\n\t*\n\t* Durable Objects normally terminate 70-140s after the last network request.\n\t* This method keeps the DO alive by establishing a WebSocket connection to itself\n\t* and sending periodic ping messages.\n\t*\n\t* @experimental This API is experimental and may change in future versions.\n\t*\n\t* @param fn - The async function to execute\n\t* @param timeoutMs - Maximum time to keep the DO alive (default: 30 minutes)\n\t* @returns The result of the async function\n\t*\n\t* @remarks\n\t* Requires the `enable_ctx_exports` compatibility flag in wrangler.jsonc:\n\t* ```json\n\t* {\n\t* \"compatibility_flags\": [\"enable_ctx_exports\"]\n\t* }\n\t* ```\n\t*\n\t* @example\n\t* ```typescript\n\t* const result = await this.experimental_waitUntil(async () => {\n\t* // Long-running operation\n\t* await processLargeDataset();\n\t* return { success: true };\n\t* }, 60 * 60 * 1000); // 1 hour timeout\n\t* ```\n\t*/\n\tasync experimental_waitUntil(fn, timeoutMs = 1800 * 1e3) {\n\t\tconst exports = this.ctx.exports;\n\t\tif (!exports) throw new Error(\"waitUntil requires the 'enable_ctx_exports' compatibility flag. Add it to your wrangler.jsonc: { \\\"compatibility_flags\\\": [\\\"enable_ctx_exports\\\"] }\");\n\t\tconst namespace = exports[this.#ParentClass.name];\n\t\tif (!namespace) throw new Error(`Could not find namespace for ${this.#ParentClass.name} in ctx.exports. Make sure the class name matches your Durable Object binding.`);\n\t\tconst ws = (await namespace.get(this.ctx.id).fetch(\"http://dummy-example.cloudflare.com/cdn-cgi/partyserver/keep-alive/\", { headers: {\n\t\t\tUpgrade: \"websocket\",\n\t\t\t\"x-partykit-room\": this.name\n\t\t} })).webSocket;\n\t\tif (!ws) throw new Error(\"Failed to establish keep-alive WebSocket connection\");\n\t\tws.accept();\n\t\tconst pingInterval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tws.send(\"ping\");\n\t\t\t} catch {}\n\t\t}, 1e4);\n\t\tlet timeoutId;\n\t\tconst timeoutPromise = new Promise((_, reject) => {\n\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\treject(/* @__PURE__ */ new Error(`experimental_waitUntil timed out after ${timeoutMs}ms`));\n\t\t\t}, timeoutMs);\n\t\t});\n\t\ttry {\n\t\t\treturn await Promise.race([fn(), timeoutPromise]);\n\t\t} finally {\n\t\t\tclearTimeout(timeoutId);\n\t\t\tclearInterval(pingInterval);\n\t\t\ttry {\n\t\t\t\tws.close(1e3, \"Complete\");\n\t\t\t} catch {}\n\t\t}\n\t}\n\t#_props;\n\t/**\n\t* Called when the server is started for the first time.\n\t*/\n\tonStart(props) {}\n\t/**\n\t* Called when a new connection is made to the server.\n\t*/\n\tonConnect(connection, ctx) {\n\t\tconsole.log(`Connection ${connection.id} connected to ${this.#ParentClass.name}:${this.name}`);\n\t}\n\t/**\n\t* Called when a message is received from a connection.\n\t*/\n\tonMessage(connection, message) {\n\t\tconsole.log(`Received message on connection ${this.#ParentClass.name}:${connection.id}`);\n\t\tconsole.info(`Implement onMessage on ${this.#ParentClass.name} to handle this message.`);\n\t}\n\t/**\n\t* Called when a connection is closed.\n\t*/\n\tonClose(connection, code, reason, wasClean) {}\n\t/**\n\t* Called when an error occurs on a connection.\n\t*/\n\tonError(connection, error) {\n\t\tconsole.error(`Error on connection ${connection.id} in ${this.#ParentClass.name}:${this.name}:`, error);\n\t\tconsole.info(`Implement onError on ${this.#ParentClass.name} to handle this error.`);\n\t}\n\t/**\n\t* Called when a request is made to the server.\n\t*/\n\tonRequest(request) {\n\t\tconsole.warn(`onRequest hasn't been implemented on ${this.#ParentClass.name}:${this.name} responding to ${request.url}`);\n\t\treturn new Response(\"Not implemented\", { status: 404 });\n\t}\n\t/**\n\t* Called when an exception occurs.\n\t* @param error - The error that occurred.\n\t*/\n\tonException(error) {\n\t\tconsole.error(`Exception in ${this.#ParentClass.name}:${this.name}:`, error);\n\t\tconsole.info(`Implement onException on ${this.#ParentClass.name} to handle this error.`);\n\t}\n\tonAlarm() {\n\t\tconsole.log(`Implement onAlarm on ${this.#ParentClass.name} to handle alarms.`);\n\t}\n\tasync alarm() {\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t\tawait this.onAlarm();\n\t}\n};\n\n//#endregion\nexport { Server, getServerByName, routePartykitRequest };\n//# sourceMappingURL=index.js.map","import * as decoding from \"lib0/decoding\";\nimport * as encoding from \"lib0/encoding\";\nimport debounce from \"lodash.debounce\";\nimport type { Connection, ConnectionContext, WSMessage } from \"partyserver\";\nimport { Server } from \"partyserver\";\nimport * as awarenessProtocol from \"y-protocols/awareness\";\nimport * as syncProtocol from \"y-protocols/sync\";\nimport {\n applyUpdate,\n Doc as YDoc,\n encodeStateAsUpdate,\n encodeStateVector,\n UndoManager,\n XmlText,\n XmlElement,\n XmlFragment\n} from \"yjs\";\n\nconst snapshotOrigin = Symbol(\"snapshot-origin\");\ntype YjsRootType =\n | \"Text\"\n | \"Map\"\n | \"Array\"\n | \"XmlText\"\n | \"XmlElement\"\n | \"XmlFragment\";\n\nconst wsReadyStateConnecting = 0;\nconst wsReadyStateOpen = 1;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst wsReadyStateClosing = 2;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst wsReadyStateClosed = 3;\n\nconst messageSync = 0;\nconst messageAwareness = 1;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst messageAuth = 2;\n\nfunction updateHandler(update: Uint8Array, _origin: unknown, doc: WSSharedDoc) {\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageSync);\n syncProtocol.writeUpdate(encoder, update);\n const message = encoding.toUint8Array(encoder);\n doc.conns.forEach((_, conn) => {\n send(doc, conn, message);\n });\n}\n\nclass WSSharedDoc extends YDoc {\n conns: Map<Connection, Set<number>>;\n awareness: awarenessProtocol.Awareness;\n\n constructor() {\n super({ gc: true });\n\n /**\n * Maps from conn to set of controlled user ids. Delete all user ids from awareness when this conn is closed\n */\n this.conns = new Map();\n\n this.awareness = new awarenessProtocol.Awareness(this);\n this.awareness.setLocalState(null);\n\n const awarenessChangeHandler = (\n {\n added,\n updated,\n removed\n }: {\n added: Array<number>;\n updated: Array<number>;\n removed: Array<number>;\n },\n conn: Connection | null // Origin is the connection that made the change\n ) => {\n const changedClients = added.concat(updated, removed);\n if (conn !== null) {\n const connControlledIDs =\n /** @type {Set<number>} */ this.conns.get(conn);\n if (connControlledIDs !== undefined) {\n added.forEach((clientID) => {\n connControlledIDs.add(clientID);\n });\n removed.forEach((clientID) => {\n connControlledIDs.delete(clientID);\n });\n }\n }\n // broadcast awareness update\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageAwareness);\n encoding.writeVarUint8Array(\n encoder,\n awarenessProtocol.encodeAwarenessUpdate(this.awareness, changedClients)\n );\n const buff = encoding.toUint8Array(encoder);\n this.conns.forEach((_, c) => {\n send(this, c, buff);\n });\n };\n this.awareness.on(\"update\", awarenessChangeHandler);\n // @ts-expect-error - TODO: fix this\n this.on(\"update\", updateHandler);\n }\n}\n\nconst CALLBACK_DEFAULTS = {\n debounceWait: 2000,\n debounceMaxWait: 10000,\n timeout: 5000\n};\n\nfunction readSyncMessage(\n decoder: decoding.Decoder,\n encoder: encoding.Encoder,\n doc: YDoc,\n transactionOrigin: Connection,\n readOnly = false\n) {\n const messageType = decoding.readVarUint(decoder);\n switch (messageType) {\n case syncProtocol.messageYjsSyncStep1:\n syncProtocol.readSyncStep1(decoder, encoder, doc);\n break;\n case syncProtocol.messageYjsSyncStep2:\n if (!readOnly)\n syncProtocol.readSyncStep2(decoder, doc, transactionOrigin);\n break;\n case syncProtocol.messageYjsUpdate:\n if (!readOnly) syncProtocol.readUpdate(decoder, doc, transactionOrigin);\n break;\n default:\n throw new Error(\"Unknown message type\");\n }\n return messageType;\n}\n\nfunction closeConn(doc: WSSharedDoc, conn: Connection): void {\n if (doc.conns.has(conn)) {\n const controlledIds: Set<number> = doc.conns.get(conn)!;\n doc.conns.delete(conn);\n awarenessProtocol.removeAwarenessStates(\n doc.awareness,\n Array.from(controlledIds),\n null\n );\n }\n try {\n conn.close();\n } catch (e) {\n console.warn(\"failed to close connection\", e);\n }\n}\n\nfunction send(doc: WSSharedDoc, conn: Connection, m: Uint8Array) {\n if (\n conn.readyState !== undefined &&\n conn.readyState !== wsReadyStateConnecting &&\n conn.readyState !== wsReadyStateOpen\n ) {\n closeConn(doc, conn);\n }\n try {\n conn.send(m);\n } catch (_e) {\n closeConn(doc, conn);\n }\n}\n\nexport interface CallbackOptions {\n debounceWait?: number;\n debounceMaxWait?: number;\n timeout?: number;\n}\n\nexport class YServer<\n Env extends Cloudflare.Env = Cloudflare.Env\n> extends Server<Env> {\n static callbackOptions: CallbackOptions = {};\n\n #ParentClass: typeof YServer = Object.getPrototypeOf(this).constructor;\n readonly document: WSSharedDoc = new WSSharedDoc();\n\n async onLoad(): Promise<void> {\n // to be implemented by the user\n return;\n }\n\n async onSave(): Promise<void> {\n // to be implemented by the user\n }\n\n /**\n * Replaces the document with a different state using Yjs UndoManager key remapping.\n *\n * @param snapshotUpdate - The snapshot update to replace the document with.\n * @param getMetadata (optional) - A function that returns the type of the root for a given key.\n */\n unstable_replaceDocument(\n snapshotUpdate: Uint8Array,\n getMetadata: (key: string) => YjsRootType = () => \"Map\"\n ): void {\n try {\n const doc = this.document;\n const snapshotDoc = new YDoc();\n applyUpdate(snapshotDoc, snapshotUpdate, snapshotOrigin);\n\n const currentStateVector = encodeStateVector(doc);\n const snapshotStateVector = encodeStateVector(snapshotDoc);\n\n const changesSinceSnapshotUpdate = encodeStateAsUpdate(\n doc,\n snapshotStateVector\n );\n\n const undoManager = new UndoManager(\n [...snapshotDoc.share.keys()].map((key) => {\n const type = getMetadata(key);\n if (type === \"Text\") {\n return snapshotDoc.getText(key);\n } else if (type === \"Map\") {\n return snapshotDoc.getMap(key);\n } else if (type === \"Array\") {\n return snapshotDoc.getArray(key);\n } else if (type === \"XmlText\") {\n return snapshotDoc.get(key, XmlText);\n } else if (type === \"XmlElement\") {\n return snapshotDoc.get(key, XmlElement);\n } else if (type === \"XmlFragment\") {\n return snapshotDoc.get(key, XmlFragment);\n }\n throw new Error(`Unknown root type: ${type} for key: ${key}`);\n }),\n {\n trackedOrigins: new Set([snapshotOrigin])\n }\n );\n\n applyUpdate(snapshotDoc, changesSinceSnapshotUpdate, snapshotOrigin);\n undoManager.undo();\n\n const documentChangesSinceSnapshotUpdate = encodeStateAsUpdate(\n snapshotDoc,\n currentStateVector\n );\n\n applyUpdate(this.document, documentChangesSinceSnapshotUpdate);\n } catch (error) {\n throw new Error(\n `Failed to replace document: ${error instanceof Error ? error.message : \"Unknown error\"}`\n );\n }\n }\n\n async onStart(): Promise<void> {\n const src = await this.onLoad();\n if (src != null) {\n const state = encodeStateAsUpdate(src);\n applyUpdate(this.document, state);\n }\n\n this.document.on(\n \"update\",\n debounce(\n (_update: Uint8Array, _origin: Connection, _doc: YDoc) => {\n try {\n this.onSave().catch((err) => {\n console.error(\"failed to persist:\", err);\n });\n } catch (err) {\n console.error(\"failed to persist:\", err);\n }\n },\n this.#ParentClass.callbackOptions.debounceWait ||\n CALLBACK_DEFAULTS.debounceWait,\n {\n maxWait:\n this.#ParentClass.callbackOptions.debounceMaxWait ||\n CALLBACK_DEFAULTS.debounceMaxWait\n }\n )\n );\n }\n\n // biome-ignore lint/correctness/noUnusedFunctionParameters: so autocomplete works\n isReadOnly(connection: Connection): boolean {\n // to be implemented by the user\n return false;\n }\n\n /**\n * Handle custom string messages from the client.\n * Override this method to implement custom message handling.\n * @param connection - The connection that sent the message\n * @param message - The custom message string (without the __YPS: prefix)\n */\n // biome-ignore lint/correctness/noUnusedFunctionParameters: so autocomplete works\n onCustomMessage(connection: Connection, message: string): void {\n // to be implemented by the user\n console.warn(\n `Received custom message but onCustomMessage is not implemented in ${this.#ParentClass.name}:`,\n message\n );\n }\n\n /**\n * Send a custom string message to a specific connection.\n * @param connection - The connection to send the message to\n * @param message - The custom message string to send\n */\n sendCustomMessage(connection: Connection, message: string): void {\n if (\n connection.readyState !== undefined &&\n connection.readyState !== wsReadyStateConnecting &&\n connection.readyState !== wsReadyStateOpen\n ) {\n return;\n }\n try {\n connection.send(`__YPS:${message}`);\n } catch (e) {\n console.warn(\"Failed to send custom message\", e);\n }\n }\n\n /**\n * Broadcast a custom string message to all connected clients.\n * @param message - The custom message string to broadcast\n * @param excludeConnection - Optional connection to exclude from the broadcast\n */\n broadcastCustomMessage(\n message: string,\n excludeConnection?: Connection\n ): void {\n const formattedMessage = `__YPS:${message}`;\n this.document.conns.forEach((_, conn) => {\n if (excludeConnection && conn === excludeConnection) {\n return;\n }\n if (\n conn.readyState !== undefined &&\n conn.readyState !== wsReadyStateConnecting &&\n conn.readyState !== wsReadyStateOpen\n ) {\n return;\n }\n try {\n conn.send(formattedMessage);\n } catch (e) {\n console.warn(\"Failed to broadcast custom message\", e);\n }\n });\n }\n\n handleMessage(connection: Connection, message: WSMessage) {\n if (typeof message === \"string\") {\n // Handle custom messages with __YPS: prefix\n if (message.startsWith(\"__YPS:\")) {\n const customMessage = message.slice(6); // Remove __YPS: prefix\n this.onCustomMessage(connection, customMessage);\n return;\n }\n console.warn(\n `Received non-prefixed string message. Custom messages should be sent using sendMessage() on the provider.`\n );\n return;\n }\n try {\n const encoder = encoding.createEncoder();\n // Convert ArrayBuffer to Uint8Array if needed (ArrayBufferView like Uint8Array can be used directly)\n const uint8Array =\n message instanceof Uint8Array\n ? message\n : message instanceof ArrayBuffer\n ? new Uint8Array(message)\n : new Uint8Array(\n message.buffer,\n message.byteOffset,\n message.byteLength\n );\n const decoder = decoding.createDecoder(uint8Array);\n const messageType = decoding.readVarUint(decoder);\n switch (messageType) {\n case messageSync:\n encoding.writeVarUint(encoder, messageSync);\n readSyncMessage(\n decoder,\n encoder,\n this.document,\n connection,\n this.isReadOnly(connection)\n );\n\n // If the `encoder` only contains the type of reply message and no\n // message, there is no need to send the message. When `encoder` only\n // contains the type of reply, its length is 1.\n if (encoding.length(encoder) > 1) {\n send(this.document, connection, encoding.toUint8Array(encoder));\n }\n break;\n case messageAwareness: {\n awarenessProtocol.applyAwarenessUpdate(\n this.document.awareness,\n decoding.readVarUint8Array(decoder),\n connection\n );\n break;\n }\n }\n } catch (err) {\n console.error(err);\n // @ts-expect-error - TODO: fix this\n this.document.emit(\"error\", [err]);\n }\n }\n\n onMessage(conn: Connection, message: WSMessage) {\n this.handleMessage(conn, message);\n }\n\n onClose(\n connection: Connection<unknown>,\n _code: number,\n _reason: string,\n _wasClean: boolean\n ): void | Promise<void> {\n closeConn(this.document, connection);\n }\n\n // TODO: explore why onError gets triggered when a connection closes\n\n onConnect(\n conn: Connection<unknown>,\n _ctx: ConnectionContext\n ): void | Promise<void> {\n // conn.binaryType = \"arraybuffer\"; // from y-websocket, breaks in our runtime\n\n this.document.conns.set(conn, new Set());\n\n // send sync step 1\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageSync);\n syncProtocol.writeSyncStep1(encoder, this.document);\n send(this.document, conn, encoding.toUint8Array(encoder));\n const awarenessStates = this.document.awareness.getStates();\n if (awarenessStates.size > 0) {\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageAwareness);\n encoding.writeVarUint8Array(\n encoder,\n awarenessProtocol.encodeAwarenessUpdate(\n this.document.awareness,\n Array.from(awarenessStates.keys())\n )\n );\n send(this.document, conn, encoding.toUint8Array(encoder));\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAIA,IAAI,EAAE,UAAU,YAAY;CAC3B,MAAM,kBAAkB;EACvB,YAAY,UAAU;EACtB,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,QAAQ,EACnC,WACD;AACD;;WAGG,KAAK;AACZ,WAAQ,MAAM,IAAI;AAElB,QAAK,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC;;;CAItC,UAAU,MAAkB,SAAoB;AAC9C,OAAK,cAAc,MAAM,QAAQ;;CAGnC,QACE,YACA,OACA,SACA,WACsB;AACtB,YAAU,KAAK,UAAU,WAAW;;CAKtC,UACE,MACA,MACsB;AAGtB,OAAK,SAAS,MAAM,IAAI,sBAAM,IAAI,KAAK,CAAC;EAGxC,MAAM,UAAU,SAAS,eAAe;AACxC,WAAS,aAAa,SAAS,YAAY;AAC3C,eAAa,eAAe,SAAS,KAAK,SAAS;AACnD,OAAK,KAAK,UAAU,MAAM,SAAS,aAAa,QAAQ,CAAC;EACzD,MAAM,kBAAkB,KAAK,SAAS,UAAU,WAAW;AAC3D,MAAI,gBAAgB,OAAO,GAAG;GAC5B,MAAMC,YAAU,SAAS,eAAe;AACxC,YAAS,aAAaA,WAAS,iBAAiB;AAChD,YAAS,mBACPA,WACA,kBAAkB,sBAChB,KAAK,SAAS,WACd,MAAM,KAAK,gBAAgB,MAAM,CAAC,CACnC,CACF;AACD,QAAK,KAAK,UAAU,MAAM,SAAS,aAAaA,UAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#cache","#connections","#ParentClass","#_props","#_name","#status","#initialize","#connectionManager","#attachSocketEventHandlers","#_longErrorAboutNameThrown","#sendMessageToConnection","YDoc","controlledIds: Set<number>","#ParentClass","encoder"],"sources":["../../../partyserver/dist/index.js","../../src/server/index.ts"],"sourcesContent":["import { DurableObject, env } from \"cloudflare:workers\";\nimport { nanoid } from \"nanoid\";\n\n//#region src/connection.ts\nif (!(\"OPEN\" in WebSocket)) {\n\tconst WebSocketStatus = {\n\t\tCONNECTING: WebSocket.READY_STATE_CONNECTING,\n\t\tOPEN: WebSocket.READY_STATE_OPEN,\n\t\tCLOSING: WebSocket.READY_STATE_CLOSING,\n\t\tCLOSED: WebSocket.READY_STATE_CLOSED\n\t};\n\tObject.assign(WebSocket, WebSocketStatus);\n\tObject.assign(WebSocket.prototype, WebSocketStatus);\n}\nfunction tryGetPartyServerMeta(ws) {\n\ttry {\n\t\tconst attachment = WebSocket.prototype.deserializeAttachment.call(ws);\n\t\tif (!attachment || typeof attachment !== \"object\") return null;\n\t\tif (!(\"__pk\" in attachment)) return null;\n\t\tconst pk = attachment.__pk;\n\t\tif (!pk || typeof pk !== \"object\") return null;\n\t\tconst { id, server, tags } = pk;\n\t\tif (typeof id !== \"string\" || typeof server !== \"string\") return null;\n\t\treturn {\n\t\t\tid,\n\t\t\tserver,\n\t\t\ttags: Array.isArray(tags) ? tags : []\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\nfunction isPartyServerWebSocket(ws) {\n\treturn tryGetPartyServerMeta(ws) !== null;\n}\n/**\n* Cache websocket attachments to avoid having to rehydrate them on every property access.\n*/\nvar AttachmentCache = class {\n\t#cache = /* @__PURE__ */ new WeakMap();\n\tget(ws) {\n\t\tlet attachment = this.#cache.get(ws);\n\t\tif (!attachment) {\n\t\t\tattachment = WebSocket.prototype.deserializeAttachment.call(ws);\n\t\t\tif (attachment !== void 0) this.#cache.set(ws, attachment);\n\t\t\telse throw new Error(\"Missing websocket attachment. This is most likely an issue in PartyServer, please open an issue at https://github.com/cloudflare/partykit/issues\");\n\t\t}\n\t\treturn attachment;\n\t}\n\tset(ws, attachment) {\n\t\tthis.#cache.set(ws, attachment);\n\t\tWebSocket.prototype.serializeAttachment.call(ws, attachment);\n\t}\n};\nconst attachments = new AttachmentCache();\nconst connections = /* @__PURE__ */ new WeakSet();\nconst isWrapped = (ws) => {\n\treturn connections.has(ws);\n};\n/**\n* Wraps a WebSocket with Connection fields that rehydrate the\n* socket attachments lazily only when requested.\n*/\nconst createLazyConnection = (ws) => {\n\tif (isWrapped(ws)) return ws;\n\tlet initialState;\n\tif (\"state\" in ws) {\n\t\tinitialState = ws.state;\n\t\tdelete ws.state;\n\t}\n\tconst connection = Object.defineProperties(ws, {\n\t\tid: { get() {\n\t\t\treturn attachments.get(ws).__pk.id;\n\t\t} },\n\t\tserver: { get() {\n\t\t\treturn attachments.get(ws).__pk.server;\n\t\t} },\n\t\ttags: { get() {\n\t\t\treturn attachments.get(ws).__pk.tags ?? [];\n\t\t} },\n\t\tsocket: { get() {\n\t\t\treturn ws;\n\t\t} },\n\t\tstate: {\n\t\t\tconfigurable: true,\n\t\t\tget() {\n\t\t\t\treturn ws.deserializeAttachment();\n\t\t\t}\n\t\t},\n\t\tsetState: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: function setState(setState$1) {\n\t\t\t\tlet state;\n\t\t\t\tif (setState$1 instanceof Function) state = setState$1(this.state);\n\t\t\t\telse state = setState$1;\n\t\t\t\tws.serializeAttachment(state);\n\t\t\t\treturn state;\n\t\t\t}\n\t\t},\n\t\tdeserializeAttachment: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: function deserializeAttachment() {\n\t\t\t\treturn attachments.get(ws).__user ?? null;\n\t\t\t}\n\t\t},\n\t\tserializeAttachment: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: function serializeAttachment(attachment) {\n\t\t\t\tconst setting = {\n\t\t\t\t\t...attachments.get(ws),\n\t\t\t\t\t__user: attachment ?? null\n\t\t\t\t};\n\t\t\t\tattachments.set(ws, setting);\n\t\t\t}\n\t\t}\n\t});\n\tif (initialState) connection.setState(initialState);\n\tconnections.add(connection);\n\treturn connection;\n};\nvar HibernatingConnectionIterator = class {\n\tindex = 0;\n\tsockets;\n\tconstructor(state, tag) {\n\t\tthis.state = state;\n\t\tthis.tag = tag;\n\t}\n\t[Symbol.iterator]() {\n\t\treturn this;\n\t}\n\tnext() {\n\t\tconst sockets = this.sockets ?? (this.sockets = this.state.getWebSockets(this.tag));\n\t\tlet socket;\n\t\twhile (socket = sockets[this.index++]) if (socket.readyState === WebSocket.READY_STATE_OPEN) {\n\t\t\tif (!isPartyServerWebSocket(socket)) continue;\n\t\t\treturn {\n\t\t\t\tdone: false,\n\t\t\t\tvalue: createLazyConnection(socket)\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tdone: true,\n\t\t\tvalue: void 0\n\t\t};\n\t}\n};\n/**\n* Deduplicate and validate connection tags.\n* Returns the final tag array (always includes the connection id as the first tag).\n*/\nfunction prepareTags(connectionId, userTags) {\n\tconst tags = [connectionId, ...userTags.filter((t) => t !== connectionId)];\n\tif (tags.length > 10) throw new Error(\"A connection can only have 10 tags, including the default id tag.\");\n\tfor (const tag of tags) {\n\t\tif (typeof tag !== \"string\") throw new Error(`A connection tag must be a string. Received: ${tag}`);\n\t\tif (tag === \"\") throw new Error(\"A connection tag must not be an empty string.\");\n\t\tif (tag.length > 256) throw new Error(\"A connection tag must not exceed 256 characters\");\n\t}\n\treturn tags;\n}\n/**\n* When not using hibernation, we track active connections manually.\n*/\nvar InMemoryConnectionManager = class {\n\t#connections = /* @__PURE__ */ new Map();\n\ttags = /* @__PURE__ */ new WeakMap();\n\tgetCount() {\n\t\treturn this.#connections.size;\n\t}\n\tgetConnection(id) {\n\t\treturn this.#connections.get(id);\n\t}\n\t*getConnections(tag) {\n\t\tif (!tag) {\n\t\t\tyield* this.#connections.values().filter((c) => c.readyState === WebSocket.READY_STATE_OPEN);\n\t\t\treturn;\n\t\t}\n\t\tfor (const connection of this.#connections.values()) if ((this.tags.get(connection) ?? []).includes(tag)) yield connection;\n\t}\n\taccept(connection, options) {\n\t\tconnection.accept();\n\t\tconst tags = prepareTags(connection.id, options.tags);\n\t\tthis.#connections.set(connection.id, connection);\n\t\tthis.tags.set(connection, tags);\n\t\tObject.defineProperty(connection, \"tags\", {\n\t\t\tget: () => tags,\n\t\t\tconfigurable: true\n\t\t});\n\t\tconst removeConnection = () => {\n\t\t\tthis.#connections.delete(connection.id);\n\t\t\tconnection.removeEventListener(\"close\", removeConnection);\n\t\t\tconnection.removeEventListener(\"error\", removeConnection);\n\t\t};\n\t\tconnection.addEventListener(\"close\", removeConnection);\n\t\tconnection.addEventListener(\"error\", removeConnection);\n\t\treturn connection;\n\t}\n};\n/**\n* When opting into hibernation, the platform tracks connections for us.\n*/\nvar HibernatingConnectionManager = class {\n\tconstructor(controller) {\n\t\tthis.controller = controller;\n\t}\n\tgetCount() {\n\t\tlet count = 0;\n\t\tfor (const ws of this.controller.getWebSockets()) if (isPartyServerWebSocket(ws)) count++;\n\t\treturn count;\n\t}\n\tgetConnection(id) {\n\t\tconst matching = this.controller.getWebSockets(id).filter((ws) => {\n\t\t\treturn tryGetPartyServerMeta(ws)?.id === id;\n\t\t});\n\t\tif (matching.length === 0) return void 0;\n\t\tif (matching.length === 1) return createLazyConnection(matching[0]);\n\t\tthrow new Error(`More than one connection found for id ${id}. Did you mean to use getConnections(tag) instead?`);\n\t}\n\tgetConnections(tag) {\n\t\treturn new HibernatingConnectionIterator(this.controller, tag);\n\t}\n\taccept(connection, options) {\n\t\tconst tags = prepareTags(connection.id, options.tags);\n\t\tthis.controller.acceptWebSocket(connection, tags);\n\t\tconnection.serializeAttachment({\n\t\t\t__pk: {\n\t\t\t\tid: connection.id,\n\t\t\t\tserver: options.server,\n\t\t\t\ttags\n\t\t\t},\n\t\t\t__user: null\n\t\t});\n\t\treturn createLazyConnection(connection);\n\t}\n};\n\n//#endregion\n//#region src/index.ts\nconst serverMapCache = /* @__PURE__ */ new WeakMap();\nconst bindingNameCache = /* @__PURE__ */ new WeakMap();\n/**\n* For a given server namespace, create a server with a name.\n*/\nasync function getServerByName(serverNamespace, name, options) {\n\tif (options?.jurisdiction) serverNamespace = serverNamespace.jurisdiction(options.jurisdiction);\n\tconst id = serverNamespace.idFromName(name);\n\tconst stub = serverNamespace.get(id, options);\n\tconst req = new Request(\"http://dummy-example.cloudflare.com/cdn-cgi/partyserver/set-name/\");\n\treq.headers.set(\"x-partykit-room\", name);\n\tif (options?.props) req.headers.set(\"x-partykit-props\", JSON.stringify(options?.props));\n\tawait stub.fetch(req).then((res) => res.text());\n\treturn stub;\n}\nfunction camelCaseToKebabCase(str) {\n\tif (str === str.toUpperCase() && str !== str.toLowerCase()) return str.toLowerCase().replace(/_/g, \"-\");\n\tlet kebabified = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\tkebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n\treturn kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n/**\n* Resolve CORS options into a concrete headers object (or null if CORS is disabled).\n*/\nfunction resolveCorsHeaders(cors) {\n\tif (cors === true) return {\n\t\t\"Access-Control-Allow-Origin\": \"*\",\n\t\t\"Access-Control-Allow-Methods\": \"GET, POST, HEAD, OPTIONS\",\n\t\t\"Access-Control-Allow-Headers\": \"*\",\n\t\t\"Access-Control-Max-Age\": \"86400\"\n\t};\n\tif (cors && typeof cors === \"object\") {\n\t\tconst h = new Headers(cors);\n\t\tconst record = {};\n\t\th.forEach((value, key) => {\n\t\t\trecord[key] = value;\n\t\t});\n\t\treturn record;\n\t}\n\treturn null;\n}\nasync function routePartykitRequest(req, env$1 = env, options) {\n\tif (!serverMapCache.has(env$1)) {\n\t\tconst namespaceMap = {};\n\t\tconst bindingNames$1 = {};\n\t\tfor (const [k, v] of Object.entries(env$1)) if (v && typeof v === \"object\" && \"idFromName\" in v && typeof v.idFromName === \"function\") {\n\t\t\tconst kebab = camelCaseToKebabCase(k);\n\t\t\tnamespaceMap[kebab] = v;\n\t\t\tbindingNames$1[kebab] = k;\n\t\t}\n\t\tserverMapCache.set(env$1, namespaceMap);\n\t\tbindingNameCache.set(env$1, bindingNames$1);\n\t}\n\tconst map = serverMapCache.get(env$1);\n\tconst bindingNames = bindingNameCache.get(env$1);\n\tconst prefixParts = (options?.prefix || \"parties\").split(\"/\");\n\tconst parts = new URL(req.url).pathname.split(\"/\").filter(Boolean);\n\tif (!prefixParts.every((part, index) => parts[index] === part) || parts.length < prefixParts.length + 2) return null;\n\tconst namespace = parts[prefixParts.length];\n\tconst name = parts[prefixParts.length + 1];\n\tif (name && namespace) {\n\t\tif (!map[namespace]) {\n\t\t\tif (namespace === \"main\") {\n\t\t\t\tconsole.warn(\"You appear to be migrating a PartyKit project to PartyServer.\");\n\t\t\t\tconsole.warn(`PartyServer doesn't have a \"main\" party by default. Try adding this to your PartySocket client:\\n \nparty: \"${camelCaseToKebabCase(Object.keys(map)[0])}\"`);\n\t\t\t} else console.error(`The url ${req.url} with namespace \"${namespace}\" and name \"${name}\" does not match any server namespace. \nDid you forget to add a durable object binding to the class ${namespace[0].toUpperCase() + namespace.slice(1)} in your wrangler.jsonc?`);\n\t\t\treturn new Response(\"Invalid request\", { status: 400 });\n\t\t}\n\t\tconst corsHeaders = resolveCorsHeaders(options?.cors);\n\t\tconst isWebSocket = req.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\";\n\t\tfunction withCorsHeaders(response) {\n\t\t\tif (!corsHeaders || isWebSocket) return response;\n\t\t\tconst newResponse = new Response(response.body, response);\n\t\t\tfor (const [key, value] of Object.entries(corsHeaders)) newResponse.headers.set(key, value);\n\t\t\treturn newResponse;\n\t\t}\n\t\tif (req.method === \"OPTIONS\" && corsHeaders) return new Response(null, { headers: corsHeaders });\n\t\tlet doNamespace = map[namespace];\n\t\tif (options?.jurisdiction) doNamespace = doNamespace.jurisdiction(options.jurisdiction);\n\t\tconst id = doNamespace.idFromName(name);\n\t\tconst stub = doNamespace.get(id, options);\n\t\treq = new Request(req);\n\t\treq.headers.set(\"x-partykit-room\", name);\n\t\treq.headers.set(\"x-partykit-namespace\", namespace);\n\t\tif (options?.jurisdiction) req.headers.set(\"x-partykit-jurisdiction\", options.jurisdiction);\n\t\tif (options?.props) req.headers.set(\"x-partykit-props\", JSON.stringify(options?.props));\n\t\tconst className = bindingNames[namespace];\n\t\tlet partyDeprecationWarned = false;\n\t\tconst lobby = {\n\t\t\tget party() {\n\t\t\t\tif (!partyDeprecationWarned) {\n\t\t\t\t\tpartyDeprecationWarned = true;\n\t\t\t\t\tconsole.warn(\"lobby.party is deprecated and currently returns the kebab-case namespace (e.g. \\\"my-agent\\\"). Use lobby.className instead to get the Durable Object class name (e.g. \\\"MyAgent\\\"). In the next major version, lobby.party will return the class name.\");\n\t\t\t\t}\n\t\t\t\treturn namespace;\n\t\t\t},\n\t\t\tclassName,\n\t\t\tname\n\t\t};\n\t\tif (isWebSocket) {\n\t\t\tif (options?.onBeforeConnect) {\n\t\t\t\tconst reqOrRes = await options.onBeforeConnect(req, lobby);\n\t\t\t\tif (reqOrRes instanceof Request) req = reqOrRes;\n\t\t\t\telse if (reqOrRes instanceof Response) return reqOrRes;\n\t\t\t}\n\t\t} else if (options?.onBeforeRequest) {\n\t\t\tconst reqOrRes = await options.onBeforeRequest(req, lobby);\n\t\t\tif (reqOrRes instanceof Request) req = reqOrRes;\n\t\t\telse if (reqOrRes instanceof Response) return withCorsHeaders(reqOrRes);\n\t\t}\n\t\treturn withCorsHeaders(await stub.fetch(req));\n\t} else return null;\n}\nvar Server = class extends DurableObject {\n\tstatic options = { hibernate: false };\n\t#status = \"zero\";\n\t#ParentClass = Object.getPrototypeOf(this).constructor;\n\t#connectionManager = this.#ParentClass.options.hibernate ? new HibernatingConnectionManager(this.ctx) : new InMemoryConnectionManager();\n\t/**\n\t* Execute SQL queries against the Server's database\n\t* @template T Type of the returned rows\n\t* @param strings SQL query template strings\n\t* @param values Values to be inserted into the query\n\t* @returns Array of query results\n\t*/\n\tsql(strings, ...values) {\n\t\tlet query = \"\";\n\t\ttry {\n\t\t\tquery = strings.reduce((acc, str, i) => acc + str + (i < values.length ? \"?\" : \"\"), \"\");\n\t\t\treturn [...this.ctx.storage.sql.exec(query, ...values)];\n\t\t} catch (e) {\n\t\t\tconsole.error(`failed to execute sql query: ${query}`, e);\n\t\t\tthrow this.onException(e);\n\t\t}\n\t}\n\tconstructor(ctx, env$1) {\n\t\tsuper(ctx, env$1);\n\t}\n\t/**\n\t* Handle incoming requests to the server.\n\t*/\n\tasync fetch(request) {\n\t\ttry {\n\t\t\tconst props = request.headers.get(\"x-partykit-props\");\n\t\t\tif (props) this.#_props = JSON.parse(props);\n\t\t\tif (!this.#_name) {\n\t\t\t\tconst room = request.headers.get(\"x-partykit-room\");\n\t\t\t\tif (!room) throw new Error(`Missing namespace or room headers when connecting to ${this.#ParentClass.name}.\nDid you try connecting directly to this Durable Object? Try using getServerByName(namespace, id) instead.`);\n\t\t\t\tawait this.setName(room);\n\t\t\t} else if (this.#status !== \"started\") await this.#initialize();\n\t\t\tconst url = new URL(request.url);\n\t\t\tif (url.pathname === \"/cdn-cgi/partyserver/set-name/\") return Response.json({ ok: true });\n\t\t\tif (request.headers.get(\"Upgrade\")?.toLowerCase() !== \"websocket\") return await this.onRequest(request);\n\t\t\telse {\n\t\t\t\tconst { 0: clientWebSocket, 1: serverWebSocket } = new WebSocketPair();\n\t\t\t\tlet connectionId = url.searchParams.get(\"_pk\");\n\t\t\t\tif (!connectionId) connectionId = nanoid();\n\t\t\t\tlet connection = Object.assign(serverWebSocket, {\n\t\t\t\t\tid: connectionId,\n\t\t\t\t\tserver: this.name,\n\t\t\t\t\ttags: [],\n\t\t\t\t\tstate: null,\n\t\t\t\t\tsetState(setState) {\n\t\t\t\t\t\tlet state;\n\t\t\t\t\t\tif (setState instanceof Function) state = setState(this.state);\n\t\t\t\t\t\telse state = setState;\n\t\t\t\t\t\tthis.state = state;\n\t\t\t\t\t\treturn this.state;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconst ctx = { request };\n\t\t\t\tconst tags = await this.getConnectionTags(connection, ctx);\n\t\t\t\tconnection = this.#connectionManager.accept(connection, {\n\t\t\t\t\ttags,\n\t\t\t\t\tserver: this.name\n\t\t\t\t});\n\t\t\t\tif (!this.#ParentClass.options.hibernate) this.#attachSocketEventHandlers(connection);\n\t\t\t\tawait this.onConnect(connection, ctx);\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 101,\n\t\t\t\t\twebSocket: clientWebSocket\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? \"<unnamed>\"} fetch:`, err);\n\t\t\tif (!(err instanceof Error)) throw err;\n\t\t\tif (request.headers.get(\"Upgrade\") === \"websocket\") {\n\t\t\t\tconst pair = new WebSocketPair();\n\t\t\t\tpair[1].accept();\n\t\t\t\tpair[1].send(JSON.stringify({ error: err.stack }));\n\t\t\t\tpair[1].close(1011, \"Uncaught exception during session setup\");\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 101,\n\t\t\t\t\twebSocket: pair[0]\n\t\t\t\t});\n\t\t\t} else return new Response(err.stack, { status: 500 });\n\t\t}\n\t}\n\tasync webSocketMessage(ws, message) {\n\t\tif (!isPartyServerWebSocket(ws)) return;\n\t\ttry {\n\t\t\tconst connection = createLazyConnection(ws);\n\t\t\tawait this.setName(connection.server);\n\t\t\treturn this.onMessage(connection, message);\n\t\t} catch (e) {\n\t\t\tconsole.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? \"<unnamed>\"} webSocketMessage:`, e);\n\t\t}\n\t}\n\tasync webSocketClose(ws, code, reason, wasClean) {\n\t\tif (!isPartyServerWebSocket(ws)) return;\n\t\ttry {\n\t\t\tconst connection = createLazyConnection(ws);\n\t\t\tawait this.setName(connection.server);\n\t\t\treturn this.onClose(connection, code, reason, wasClean);\n\t\t} catch (e) {\n\t\t\tconsole.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? \"<unnamed>\"} webSocketClose:`, e);\n\t\t}\n\t}\n\tasync webSocketError(ws, error) {\n\t\tif (!isPartyServerWebSocket(ws)) return;\n\t\ttry {\n\t\t\tconst connection = createLazyConnection(ws);\n\t\t\tawait this.setName(connection.server);\n\t\t\treturn this.onError(connection, error);\n\t\t} catch (e) {\n\t\t\tconsole.error(`Error in ${this.#ParentClass.name}:${this.#_name ?? \"<unnamed>\"} webSocketError:`, e);\n\t\t}\n\t}\n\tasync #initialize() {\n\t\tlet error;\n\t\tawait this.ctx.blockConcurrencyWhile(async () => {\n\t\t\tthis.#status = \"starting\";\n\t\t\ttry {\n\t\t\t\tawait this.onStart(this.#_props);\n\t\t\t\tthis.#status = \"started\";\n\t\t\t} catch (e) {\n\t\t\t\tthis.#status = \"zero\";\n\t\t\t\terror = e;\n\t\t\t}\n\t\t});\n\t\tif (error) throw error;\n\t}\n\t#attachSocketEventHandlers(connection) {\n\t\tconst handleMessageFromClient = (event) => {\n\t\t\tthis.onMessage(connection, event.data)?.catch((e) => {\n\t\t\t\tconsole.error(\"onMessage error:\", e);\n\t\t\t});\n\t\t};\n\t\tconst handleCloseFromClient = (event) => {\n\t\t\tconnection.removeEventListener(\"message\", handleMessageFromClient);\n\t\t\tconnection.removeEventListener(\"close\", handleCloseFromClient);\n\t\t\tthis.onClose(connection, event.code, event.reason, event.wasClean)?.catch((e) => {\n\t\t\t\tconsole.error(\"onClose error:\", e);\n\t\t\t});\n\t\t};\n\t\tconst handleErrorFromClient = (e) => {\n\t\t\tconnection.removeEventListener(\"message\", handleMessageFromClient);\n\t\t\tconnection.removeEventListener(\"error\", handleErrorFromClient);\n\t\t\tthis.onError(connection, e.error)?.catch((e$1) => {\n\t\t\t\tconsole.error(\"onError error:\", e$1);\n\t\t\t});\n\t\t};\n\t\tconnection.addEventListener(\"close\", handleCloseFromClient);\n\t\tconnection.addEventListener(\"error\", handleErrorFromClient);\n\t\tconnection.addEventListener(\"message\", handleMessageFromClient);\n\t}\n\t#_name;\n\t#_longErrorAboutNameThrown = false;\n\t/**\n\t* The name for this server. Write-once-only.\n\t*/\n\tget name() {\n\t\tif (!this.#_name) if (!this.#_longErrorAboutNameThrown) {\n\t\t\tthis.#_longErrorAboutNameThrown = true;\n\t\t\tthrow new Error(`Attempting to read .name on ${this.#ParentClass.name} before it was set. The name can be set by explicitly calling .setName(name) on the stub, or by using routePartyKitRequest(). This is a known issue and will be fixed soon. Follow https://github.com/cloudflare/workerd/issues/2240 for more updates.`);\n\t\t} else throw new Error(`Attempting to read .name on ${this.#ParentClass.name} before it was set.`);\n\t\treturn this.#_name;\n\t}\n\tasync setName(name) {\n\t\tif (!name) throw new Error(\"A name is required.\");\n\t\tif (this.#_name && this.#_name !== name) throw new Error(`This server already has a name: ${this.#_name}, attempting to set to: ${name}`);\n\t\tthis.#_name = name;\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t}\n\t#sendMessageToConnection(connection, message) {\n\t\ttry {\n\t\t\tconnection.send(message);\n\t\t} catch (_e) {\n\t\t\tconnection.close(1011, \"Unexpected error\");\n\t\t}\n\t}\n\t/** Send a message to all connected clients, except connection ids listed in `without` */\n\tbroadcast(msg, without) {\n\t\tfor (const connection of this.#connectionManager.getConnections()) if (!without || !without.includes(connection.id)) this.#sendMessageToConnection(connection, msg);\n\t}\n\t/** Get a connection by connection id */\n\tgetConnection(id) {\n\t\treturn this.#connectionManager.getConnection(id);\n\t}\n\t/**\n\t* Get all connections. Optionally, you can provide a tag to filter returned connections.\n\t* Use `Server#getConnectionTags` to tag the connection on connect.\n\t*/\n\tgetConnections(tag) {\n\t\treturn this.#connectionManager.getConnections(tag);\n\t}\n\t/**\n\t* You can tag a connection to filter them in Server#getConnections.\n\t* Each connection supports up to 9 tags, each tag max length is 256 characters.\n\t*/\n\tgetConnectionTags(connection, context) {\n\t\treturn [];\n\t}\n\t#_props;\n\t/**\n\t* Called when the server is started for the first time.\n\t*/\n\tonStart(props) {}\n\t/**\n\t* Called when a new connection is made to the server.\n\t*/\n\tonConnect(connection, ctx) {\n\t\tconsole.log(`Connection ${connection.id} connected to ${this.#ParentClass.name}:${this.name}`);\n\t}\n\t/**\n\t* Called when a message is received from a connection.\n\t*/\n\tonMessage(connection, message) {\n\t\tconsole.log(`Received message on connection ${this.#ParentClass.name}:${connection.id}`);\n\t\tconsole.info(`Implement onMessage on ${this.#ParentClass.name} to handle this message.`);\n\t}\n\t/**\n\t* Called when a connection is closed.\n\t*/\n\tonClose(connection, code, reason, wasClean) {}\n\t/**\n\t* Called when an error occurs on a connection.\n\t*/\n\tonError(connection, error) {\n\t\tconsole.error(`Error on connection ${connection.id} in ${this.#ParentClass.name}:${this.name}:`, error);\n\t\tconsole.info(`Implement onError on ${this.#ParentClass.name} to handle this error.`);\n\t}\n\t/**\n\t* Called when a request is made to the server.\n\t*/\n\tonRequest(request) {\n\t\tconsole.warn(`onRequest hasn't been implemented on ${this.#ParentClass.name}:${this.name} responding to ${request.url}`);\n\t\treturn new Response(\"Not implemented\", { status: 404 });\n\t}\n\t/**\n\t* Called when an exception occurs.\n\t* @param error - The error that occurred.\n\t*/\n\tonException(error) {\n\t\tconsole.error(`Exception in ${this.#ParentClass.name}:${this.name}:`, error);\n\t\tconsole.info(`Implement onException on ${this.#ParentClass.name} to handle this error.`);\n\t}\n\tonAlarm() {\n\t\tconsole.log(`Implement onAlarm on ${this.#ParentClass.name} to handle alarms.`);\n\t}\n\tasync alarm() {\n\t\tif (this.#status !== \"started\") await this.#initialize();\n\t\tawait this.onAlarm();\n\t}\n};\n\n//#endregion\nexport { Server, getServerByName, routePartykitRequest };\n//# sourceMappingURL=index.js.map","import * as decoding from \"lib0/decoding\";\nimport * as encoding from \"lib0/encoding\";\nimport debounce from \"lodash.debounce\";\nimport type { Connection, ConnectionContext, WSMessage } from \"partyserver\";\nimport { Server } from \"partyserver\";\nimport * as awarenessProtocol from \"y-protocols/awareness\";\nimport * as syncProtocol from \"y-protocols/sync\";\nimport {\n applyUpdate,\n Doc as YDoc,\n encodeStateAsUpdate,\n encodeStateVector,\n UndoManager,\n XmlText,\n XmlElement,\n XmlFragment\n} from \"yjs\";\n\nconst snapshotOrigin = Symbol(\"snapshot-origin\");\ntype YjsRootType =\n | \"Text\"\n | \"Map\"\n | \"Array\"\n | \"XmlText\"\n | \"XmlElement\"\n | \"XmlFragment\";\n\nconst wsReadyStateConnecting = 0;\nconst wsReadyStateOpen = 1;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst wsReadyStateClosing = 2;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst wsReadyStateClosed = 3;\n\nconst messageSync = 0;\nconst messageAwareness = 1;\n// biome-ignore lint/correctness/noUnusedVariables: it's fine\nconst messageAuth = 2;\n\nfunction updateHandler(update: Uint8Array, _origin: unknown, doc: WSSharedDoc) {\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageSync);\n syncProtocol.writeUpdate(encoder, update);\n const message = encoding.toUint8Array(encoder);\n doc.conns.forEach((_, conn) => {\n send(doc, conn, message);\n });\n}\n\nclass WSSharedDoc extends YDoc {\n conns: Map<Connection, Set<number>>;\n awareness: awarenessProtocol.Awareness;\n\n constructor() {\n super({ gc: true });\n\n /**\n * Maps from conn to set of controlled user ids. Delete all user ids from awareness when this conn is closed\n */\n this.conns = new Map();\n\n this.awareness = new awarenessProtocol.Awareness(this);\n this.awareness.setLocalState(null);\n\n const awarenessChangeHandler = (\n {\n added,\n updated,\n removed\n }: {\n added: Array<number>;\n updated: Array<number>;\n removed: Array<number>;\n },\n conn: Connection | null // Origin is the connection that made the change\n ) => {\n const changedClients = added.concat(updated, removed);\n if (conn !== null) {\n const connControlledIDs =\n /** @type {Set<number>} */ this.conns.get(conn);\n if (connControlledIDs !== undefined) {\n added.forEach((clientID) => {\n connControlledIDs.add(clientID);\n });\n removed.forEach((clientID) => {\n connControlledIDs.delete(clientID);\n });\n }\n }\n // broadcast awareness update\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageAwareness);\n encoding.writeVarUint8Array(\n encoder,\n awarenessProtocol.encodeAwarenessUpdate(this.awareness, changedClients)\n );\n const buff = encoding.toUint8Array(encoder);\n this.conns.forEach((_, c) => {\n send(this, c, buff);\n });\n };\n this.awareness.on(\"update\", awarenessChangeHandler);\n // @ts-expect-error - TODO: fix this\n this.on(\"update\", updateHandler);\n }\n}\n\nconst CALLBACK_DEFAULTS = {\n debounceWait: 2000,\n debounceMaxWait: 10000,\n timeout: 5000\n};\n\nfunction readSyncMessage(\n decoder: decoding.Decoder,\n encoder: encoding.Encoder,\n doc: YDoc,\n transactionOrigin: Connection,\n readOnly = false\n) {\n const messageType = decoding.readVarUint(decoder);\n switch (messageType) {\n case syncProtocol.messageYjsSyncStep1:\n syncProtocol.readSyncStep1(decoder, encoder, doc);\n break;\n case syncProtocol.messageYjsSyncStep2:\n if (!readOnly)\n syncProtocol.readSyncStep2(decoder, doc, transactionOrigin);\n break;\n case syncProtocol.messageYjsUpdate:\n if (!readOnly) syncProtocol.readUpdate(decoder, doc, transactionOrigin);\n break;\n default:\n throw new Error(\"Unknown message type\");\n }\n return messageType;\n}\n\nfunction closeConn(doc: WSSharedDoc, conn: Connection): void {\n if (doc.conns.has(conn)) {\n const controlledIds: Set<number> = doc.conns.get(conn)!;\n doc.conns.delete(conn);\n awarenessProtocol.removeAwarenessStates(\n doc.awareness,\n Array.from(controlledIds),\n null\n );\n }\n try {\n conn.close();\n } catch (e) {\n console.warn(\"failed to close connection\", e);\n }\n}\n\nfunction send(doc: WSSharedDoc, conn: Connection, m: Uint8Array) {\n if (\n conn.readyState !== undefined &&\n conn.readyState !== wsReadyStateConnecting &&\n conn.readyState !== wsReadyStateOpen\n ) {\n closeConn(doc, conn);\n }\n try {\n conn.send(m);\n } catch (_e) {\n closeConn(doc, conn);\n }\n}\n\nexport interface CallbackOptions {\n debounceWait?: number;\n debounceMaxWait?: number;\n timeout?: number;\n}\n\nexport class YServer<\n Env extends Cloudflare.Env = Cloudflare.Env\n> extends Server<Env> {\n static callbackOptions: CallbackOptions = {};\n\n #ParentClass: typeof YServer = Object.getPrototypeOf(this).constructor;\n readonly document: WSSharedDoc = new WSSharedDoc();\n\n async onLoad(): Promise<void> {\n // to be implemented by the user\n return;\n }\n\n async onSave(): Promise<void> {\n // to be implemented by the user\n }\n\n /**\n * Replaces the document with a different state using Yjs UndoManager key remapping.\n *\n * @param snapshotUpdate - The snapshot update to replace the document with.\n * @param getMetadata (optional) - A function that returns the type of the root for a given key.\n */\n unstable_replaceDocument(\n snapshotUpdate: Uint8Array,\n getMetadata: (key: string) => YjsRootType = () => \"Map\"\n ): void {\n try {\n const doc = this.document;\n const snapshotDoc = new YDoc();\n applyUpdate(snapshotDoc, snapshotUpdate, snapshotOrigin);\n\n const currentStateVector = encodeStateVector(doc);\n const snapshotStateVector = encodeStateVector(snapshotDoc);\n\n const changesSinceSnapshotUpdate = encodeStateAsUpdate(\n doc,\n snapshotStateVector\n );\n\n const undoManager = new UndoManager(\n [...snapshotDoc.share.keys()].map((key) => {\n const type = getMetadata(key);\n if (type === \"Text\") {\n return snapshotDoc.getText(key);\n } else if (type === \"Map\") {\n return snapshotDoc.getMap(key);\n } else if (type === \"Array\") {\n return snapshotDoc.getArray(key);\n } else if (type === \"XmlText\") {\n return snapshotDoc.get(key, XmlText);\n } else if (type === \"XmlElement\") {\n return snapshotDoc.get(key, XmlElement);\n } else if (type === \"XmlFragment\") {\n return snapshotDoc.get(key, XmlFragment);\n }\n throw new Error(`Unknown root type: ${type} for key: ${key}`);\n }),\n {\n trackedOrigins: new Set([snapshotOrigin])\n }\n );\n\n applyUpdate(snapshotDoc, changesSinceSnapshotUpdate, snapshotOrigin);\n undoManager.undo();\n\n const documentChangesSinceSnapshotUpdate = encodeStateAsUpdate(\n snapshotDoc,\n currentStateVector\n );\n\n applyUpdate(this.document, documentChangesSinceSnapshotUpdate);\n } catch (error) {\n throw new Error(\n `Failed to replace document: ${error instanceof Error ? error.message : \"Unknown error\"}`\n );\n }\n }\n\n async onStart(): Promise<void> {\n const src = await this.onLoad();\n if (src != null) {\n const state = encodeStateAsUpdate(src);\n applyUpdate(this.document, state);\n }\n\n this.document.on(\n \"update\",\n debounce(\n (_update: Uint8Array, _origin: Connection, _doc: YDoc) => {\n try {\n this.onSave().catch((err) => {\n console.error(\"failed to persist:\", err);\n });\n } catch (err) {\n console.error(\"failed to persist:\", err);\n }\n },\n this.#ParentClass.callbackOptions.debounceWait ||\n CALLBACK_DEFAULTS.debounceWait,\n {\n maxWait:\n this.#ParentClass.callbackOptions.debounceMaxWait ||\n CALLBACK_DEFAULTS.debounceMaxWait\n }\n )\n );\n }\n\n // biome-ignore lint/correctness/noUnusedFunctionParameters: so autocomplete works\n isReadOnly(connection: Connection): boolean {\n // to be implemented by the user\n return false;\n }\n\n /**\n * Handle custom string messages from the client.\n * Override this method to implement custom message handling.\n * @param connection - The connection that sent the message\n * @param message - The custom message string (without the __YPS: prefix)\n */\n // biome-ignore lint/correctness/noUnusedFunctionParameters: so autocomplete works\n onCustomMessage(connection: Connection, message: string): void {\n // to be implemented by the user\n console.warn(\n `Received custom message but onCustomMessage is not implemented in ${this.#ParentClass.name}:`,\n message\n );\n }\n\n /**\n * Send a custom string message to a specific connection.\n * @param connection - The connection to send the message to\n * @param message - The custom message string to send\n */\n sendCustomMessage(connection: Connection, message: string): void {\n if (\n connection.readyState !== undefined &&\n connection.readyState !== wsReadyStateConnecting &&\n connection.readyState !== wsReadyStateOpen\n ) {\n return;\n }\n try {\n connection.send(`__YPS:${message}`);\n } catch (e) {\n console.warn(\"Failed to send custom message\", e);\n }\n }\n\n /**\n * Broadcast a custom string message to all connected clients.\n * @param message - The custom message string to broadcast\n * @param excludeConnection - Optional connection to exclude from the broadcast\n */\n broadcastCustomMessage(\n message: string,\n excludeConnection?: Connection\n ): void {\n const formattedMessage = `__YPS:${message}`;\n this.document.conns.forEach((_, conn) => {\n if (excludeConnection && conn === excludeConnection) {\n return;\n }\n if (\n conn.readyState !== undefined &&\n conn.readyState !== wsReadyStateConnecting &&\n conn.readyState !== wsReadyStateOpen\n ) {\n return;\n }\n try {\n conn.send(formattedMessage);\n } catch (e) {\n console.warn(\"Failed to broadcast custom message\", e);\n }\n });\n }\n\n handleMessage(connection: Connection, message: WSMessage) {\n if (typeof message === \"string\") {\n // Handle custom messages with __YPS: prefix\n if (message.startsWith(\"__YPS:\")) {\n const customMessage = message.slice(6); // Remove __YPS: prefix\n this.onCustomMessage(connection, customMessage);\n return;\n }\n console.warn(\n `Received non-prefixed string message. Custom messages should be sent using sendMessage() on the provider.`\n );\n return;\n }\n try {\n const encoder = encoding.createEncoder();\n // Convert ArrayBuffer to Uint8Array if needed (ArrayBufferView like Uint8Array can be used directly)\n const uint8Array =\n message instanceof Uint8Array\n ? message\n : message instanceof ArrayBuffer\n ? new Uint8Array(message)\n : new Uint8Array(\n message.buffer,\n message.byteOffset,\n message.byteLength\n );\n const decoder = decoding.createDecoder(uint8Array);\n const messageType = decoding.readVarUint(decoder);\n switch (messageType) {\n case messageSync:\n encoding.writeVarUint(encoder, messageSync);\n readSyncMessage(\n decoder,\n encoder,\n this.document,\n connection,\n this.isReadOnly(connection)\n );\n\n // If the `encoder` only contains the type of reply message and no\n // message, there is no need to send the message. When `encoder` only\n // contains the type of reply, its length is 1.\n if (encoding.length(encoder) > 1) {\n send(this.document, connection, encoding.toUint8Array(encoder));\n }\n break;\n case messageAwareness: {\n awarenessProtocol.applyAwarenessUpdate(\n this.document.awareness,\n decoding.readVarUint8Array(decoder),\n connection\n );\n break;\n }\n }\n } catch (err) {\n console.error(err);\n // @ts-expect-error - TODO: fix this\n this.document.emit(\"error\", [err]);\n }\n }\n\n onMessage(conn: Connection, message: WSMessage) {\n this.handleMessage(conn, message);\n }\n\n onClose(\n connection: Connection<unknown>,\n _code: number,\n _reason: string,\n _wasClean: boolean\n ): void | Promise<void> {\n closeConn(this.document, connection);\n }\n\n // TODO: explore why onError gets triggered when a connection closes\n\n onConnect(\n conn: Connection<unknown>,\n _ctx: ConnectionContext\n ): void | Promise<void> {\n // conn.binaryType = \"arraybuffer\"; // from y-websocket, breaks in our runtime\n\n this.document.conns.set(conn, new Set());\n\n // send sync step 1\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageSync);\n syncProtocol.writeSyncStep1(encoder, this.document);\n send(this.document, conn, encoding.toUint8Array(encoder));\n const awarenessStates = this.document.awareness.getStates();\n if (awarenessStates.size > 0) {\n const encoder = encoding.createEncoder();\n encoding.writeVarUint(encoder, messageAwareness);\n encoding.writeVarUint8Array(\n encoder,\n awarenessProtocol.encodeAwarenessUpdate(\n this.document.awareness,\n Array.from(awarenessStates.keys())\n )\n );\n send(this.document, conn, encoding.toUint8Array(encoder));\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAIA,IAAI,EAAE,UAAU,YAAY;CAC3B,MAAM,kBAAkB;EACvB,YAAY,UAAU;EACtB,MAAM,UAAU;EAChB,SAAS,UAAU;EACnB,QAAQ,UAAU;EAClB;AACD,QAAO,OAAO,WAAW,gBAAgB;AACzC,QAAO,OAAO,UAAU,WAAW,gBAAgB;;AAEpD,SAAS,sBAAsB,IAAI;AAClC,KAAI;EACH,MAAM,aAAa,UAAU,UAAU,sBAAsB,KAAK,GAAG;AACrE,MAAI,CAAC,cAAc,OAAO,eAAe,SAAU,QAAO;AAC1D,MAAI,EAAE,UAAU,YAAa,QAAO;EACpC,MAAM,KAAK,WAAW;AACtB,MAAI,CAAC,MAAM,OAAO,OAAO,SAAU,QAAO;EAC1C,MAAM,EAAE,IAAI,QAAQ,SAAS;AAC7B,MAAI,OAAO,OAAO,YAAY,OAAO,WAAW,SAAU,QAAO;AACjE,SAAO;GACN;GACA;GACA,MAAM,MAAM,QAAQ,KAAK,GAAG,OAAO,EAAE;GACrC;SACM;AACP,SAAO;;;AAGT,SAAS,uBAAuB,IAAI;AACnC,QAAO,sBAAsB,GAAG,KAAK;;;;;AAKtC,IAAI,kBAAkB,MAAM;CAC3B,yBAAyB,IAAI,SAAS;CACtC,IAAI,IAAI;EACP,IAAI,aAAa,MAAKA,MAAO,IAAI,GAAG;AACpC,MAAI,CAAC,YAAY;AAChB,gBAAa,UAAU,UAAU,sBAAsB,KAAK,GAAG;AAC/D,OAAI,eAAe,KAAK,EAAG,OAAKA,MAAO,IAAI,IAAI,WAAW;OACrD,OAAM,IAAI,MAAM,mJAAmJ;;AAEzK,SAAO;;CAER,IAAI,IAAI,YAAY;AACnB,QAAKA,MAAO,IAAI,IAAI,WAAW;AAC/B,YAAU,UAAU,oBAAoB,KAAK,IAAI,WAAW;;;AAG9D,MAAM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,EACnC,WACD;AACD;;WAGG,KAAK;AACZ,WAAQ,MAAM,IAAI;AAElB,QAAK,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC;;;CAItC,UAAU,MAAkB,SAAoB;AAC9C,OAAK,cAAc,MAAM,QAAQ;;CAGnC,QACE,YACA,OACA,SACA,WACsB;AACtB,YAAU,KAAK,UAAU,WAAW;;CAKtC,UACE,MACA,MACsB;AAGtB,OAAK,SAAS,MAAM,IAAI,sBAAM,IAAI,KAAK,CAAC;EAGxC,MAAM,UAAU,SAAS,eAAe;AACxC,WAAS,aAAa,SAAS,YAAY;AAC3C,eAAa,eAAe,SAAS,KAAK,SAAS;AACnD,OAAK,KAAK,UAAU,MAAM,SAAS,aAAa,QAAQ,CAAC;EACzD,MAAM,kBAAkB,KAAK,SAAS,UAAU,WAAW;AAC3D,MAAI,gBAAgB,OAAO,GAAG;GAC5B,MAAMC,YAAU,SAAS,eAAe;AACxC,YAAS,aAAaA,WAAS,iBAAiB;AAChD,YAAS,mBACPA,WACA,kBAAkB,sBAChB,KAAK,SAAS,WACd,MAAM,KAAK,gBAAgB,MAAM,CAAC,CACnC,CACF;AACD,QAAK,KAAK,UAAU,MAAM,SAAS,aAAaA,UAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "y-partyserver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git://github.com/cloudflare/partykit.git"
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@cloudflare/workers-types": "^4.20240729.0",
|
|
50
|
-
"partyserver": "^0.
|
|
50
|
+
"partyserver": "^0.2.0",
|
|
51
51
|
"yjs": "^13.6.14"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@cloudflare/workers-types": "^4.20251218.0",
|
|
55
55
|
"@types/lodash.debounce": "^4.0.9",
|
|
56
|
-
"partyserver": "^0.
|
|
56
|
+
"partyserver": "^0.2.0",
|
|
57
57
|
"ws": "^8.18.3",
|
|
58
58
|
"yjs": "^13.6.28"
|
|
59
59
|
}
|