@cardonjs/realtime-do 0.0.0-stage → 0.2.3
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/LICENSE +21 -0
- package/README.md +558 -2
- package/dist/client.d.ts +56 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +286 -0
- package/dist/client.js.map +1 -0
- package/dist/connect.d.ts +27 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +82 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/presence.d.ts +68 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +88 -0
- package/dist/presence.js.map +1 -0
- package/dist/protocol.d.ts +50 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +86 -0
- package/dist/protocol.js.map +1 -0
- package/dist/publisher.d.ts +39 -0
- package/dist/publisher.d.ts.map +1 -0
- package/dist/publisher.js +101 -0
- package/dist/publisher.js.map +1 -0
- package/dist/room.d.ts +58 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +400 -0
- package/dist/room.js.map +1 -0
- package/dist/testing.d.ts +65 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +99 -0
- package/dist/testing.js.map +1 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +106 -0
- package/dist/validation.js.map +1 -0
- package/llms.txt +189 -0
- package/package.json +58 -3
package/dist/room.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room: a plain Durable Object class (no `cloudflare:workers` import, no RPC) that holds
|
|
3
|
+
* hibernating WebSockets. The Worker talks to it with `stub.fetch` on internal URLs.
|
|
4
|
+
*
|
|
5
|
+
* Nothing about a connection lives in instance memory: channels and the identity (hashed) are
|
|
6
|
+
* the socket's tags, everything else is in its attachment, and revocation markers are in
|
|
7
|
+
* Durable Object storage, so the room behaves the same after the runtime evicts the instance
|
|
8
|
+
* and wakes it again for the next event. The only in-memory value is a cache (the earliest
|
|
9
|
+
* expiry), rebuilt by a full sweep after a wake-up.
|
|
10
|
+
*/
|
|
11
|
+
import { presenceRecord, selectPresence, validPresenceQuery, } from "./presence.js";
|
|
12
|
+
import { CLOSE_DISCONNECTED, CLOSE_PROTOCOL, CLOSE_REAUTHENTICATE, CONNECT_HEADER, IDENTITY_TAG_PREFIX, identityTag, PATH, validIdentity, } from "./protocol.js";
|
|
13
|
+
import { assertValidChannels, assertValidRoom, DEFAULT_MAX_EVENT_BYTES, eventFrame, MAX_EVENT_BYTES_LIMIT, validEvent, } from "./validation.js";
|
|
14
|
+
const OPEN = 1;
|
|
15
|
+
/** Cloudflare's limit of hibernatable WebSockets per object. */
|
|
16
|
+
const MAX_CONNECTIONS_LIMIT = 32_768;
|
|
17
|
+
const MAX_AGE_LIMIT = 604_800;
|
|
18
|
+
/** How long `disconnect` refuses new connections of the identity. */
|
|
19
|
+
const REVOCATION_WINDOW_MS = 60_000;
|
|
20
|
+
/** Storage key prefix of revocation markers; the rest is the identity tag (a hash). */
|
|
21
|
+
const REVOKED_PREFIX = "revoked:";
|
|
22
|
+
/** `storage.delete` takes at most 128 keys. */
|
|
23
|
+
const DELETE_BATCH = 128;
|
|
24
|
+
function integerOption(name, value, fallback, min, max) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return fallback;
|
|
27
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
28
|
+
throw new TypeError(`defineRoom: ${name} must be an integer from ${min} to ${max}.`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function hookOption(name, value) {
|
|
33
|
+
if (value !== undefined && typeof value !== "function") {
|
|
34
|
+
throw new TypeError(`defineRoom: ${name} must be a function.`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function validConfig(options) {
|
|
39
|
+
if (options !== undefined && (typeof options !== "object" || options === null)) {
|
|
40
|
+
throw new TypeError("defineRoom: options must be an object.");
|
|
41
|
+
}
|
|
42
|
+
const o = options ?? {};
|
|
43
|
+
const maxConnections = integerOption("maxConnections", o.maxConnections, 1000, 1, MAX_CONNECTIONS_LIMIT);
|
|
44
|
+
return {
|
|
45
|
+
maxConnections,
|
|
46
|
+
maxConnectionsPerIdentity: integerOption("maxConnectionsPerIdentity", o.maxConnectionsPerIdentity, Math.min(5, maxConnections), 1, maxConnections),
|
|
47
|
+
maxEventBytes: integerOption("maxEventBytes", o.maxEventBytes, DEFAULT_MAX_EVENT_BYTES, 256, MAX_EVENT_BYTES_LIMIT),
|
|
48
|
+
maxAgeMs: integerOption("maxConnectionAgeSeconds", o.maxConnectionAgeSeconds, 3600, 1, MAX_AGE_LIMIT) *
|
|
49
|
+
1000,
|
|
50
|
+
onConnect: hookOption("onConnect", o.onConnect),
|
|
51
|
+
onDisconnect: hookOption("onDisconnect", o.onDisconnect),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function readAttachment(ws) {
|
|
55
|
+
try {
|
|
56
|
+
const value = ws.deserializeAttachment();
|
|
57
|
+
if (value === null || typeof value !== "object" || value.v !== 1)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (typeof value.exp !== "number")
|
|
60
|
+
return undefined;
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function closeQuietly(ws, code, reason) {
|
|
68
|
+
try {
|
|
69
|
+
ws.close(code, reason);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Already closed.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function json(body, status = 200) {
|
|
76
|
+
return Response.json(body, { status });
|
|
77
|
+
}
|
|
78
|
+
const notFound = () => new Response(null, { status: 404 });
|
|
79
|
+
const badRequest = () => new Response(null, { status: 400 });
|
|
80
|
+
async function readJson(request) {
|
|
81
|
+
try {
|
|
82
|
+
const body = (await request.json());
|
|
83
|
+
return typeof body === "object" && body !== null
|
|
84
|
+
? body
|
|
85
|
+
: undefined;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Logs a hook failure without the identity or the error message (they may hold personal data). */
|
|
92
|
+
function logHookFailure(hook, error) {
|
|
93
|
+
const name = error instanceof Error ? error.name : typeof error;
|
|
94
|
+
console.error(`realtime-do: the ${hook} hook failed (${name}).`);
|
|
95
|
+
}
|
|
96
|
+
/** Returns the Durable Object class the project exports from its Worker entry. */
|
|
97
|
+
export function defineRoom(options) {
|
|
98
|
+
const config = validConfig(options);
|
|
99
|
+
return class Room {
|
|
100
|
+
#state;
|
|
101
|
+
#env;
|
|
102
|
+
/**
|
|
103
|
+
* Cache: no open socket expires before this time (epoch ms). `undefined` after a wake-up,
|
|
104
|
+
* which forces one full sweep. Correctness never depends on it: it only skips sweeps.
|
|
105
|
+
*/
|
|
106
|
+
#nextExpiry;
|
|
107
|
+
constructor(state, env) {
|
|
108
|
+
this.#state = state;
|
|
109
|
+
this.#env = env;
|
|
110
|
+
// Answered by the runtime without waking the object.
|
|
111
|
+
state.setWebSocketAutoResponse(new WebSocketRequestResponsePair("ping", "pong"));
|
|
112
|
+
}
|
|
113
|
+
async fetch(request) {
|
|
114
|
+
const { pathname } = new URL(request.url);
|
|
115
|
+
if (request.method === "GET" && pathname === PATH.connect)
|
|
116
|
+
return this.#connect(request);
|
|
117
|
+
if (request.method === "POST" && pathname === PATH.publish)
|
|
118
|
+
return this.#publish(request);
|
|
119
|
+
if (request.method === "GET" && pathname === PATH.count) {
|
|
120
|
+
this.#expire();
|
|
121
|
+
return json({ count: this.#open().length });
|
|
122
|
+
}
|
|
123
|
+
if (request.method === "POST" && pathname === PATH.disconnect) {
|
|
124
|
+
return this.#disconnect(request);
|
|
125
|
+
}
|
|
126
|
+
if (request.method === "POST" && pathname === PATH.presence)
|
|
127
|
+
return this.#presence(request);
|
|
128
|
+
return notFound();
|
|
129
|
+
}
|
|
130
|
+
/** Clients only send `"ping"` (answered by the auto-response); anything else is a violation. */
|
|
131
|
+
async webSocketMessage(ws, _message) {
|
|
132
|
+
closeQuietly(ws, CLOSE_PROTOCOL, "Unexpected message");
|
|
133
|
+
}
|
|
134
|
+
async webSocketClose(ws) {
|
|
135
|
+
await this.#gone(ws);
|
|
136
|
+
}
|
|
137
|
+
async webSocketError(ws) {
|
|
138
|
+
await this.#gone(ws);
|
|
139
|
+
}
|
|
140
|
+
/** The identity tag the socket was accepted with, if the runtime can still tell. */
|
|
141
|
+
#identityTagOf(ws) {
|
|
142
|
+
try {
|
|
143
|
+
return this.#state.getTags(ws).find((tag) => tag.startsWith(IDENTITY_TAG_PREFIX));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Open sockets: what `count()` and the hooks report, and what receives events. */
|
|
150
|
+
#open(tag) {
|
|
151
|
+
return this.#state.getWebSockets(tag).filter((ws) => ws.readyState === OPEN);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Lazy expiry (there is no alarm): sockets past their age must re-authenticate. Skipped
|
|
155
|
+
* while no socket can have expired yet; a full sweep rebuilds that bound.
|
|
156
|
+
*/
|
|
157
|
+
#expire() {
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
if (this.#nextExpiry !== undefined && now < this.#nextExpiry)
|
|
160
|
+
return;
|
|
161
|
+
let next = Number.POSITIVE_INFINITY;
|
|
162
|
+
for (const ws of this.#open()) {
|
|
163
|
+
const attachment = readAttachment(ws);
|
|
164
|
+
if (attachment === undefined || attachment.exp <= now) {
|
|
165
|
+
closeQuietly(ws, CLOSE_REAUTHENTICATE, "Re-authenticate");
|
|
166
|
+
}
|
|
167
|
+
else if (attachment.exp < next) {
|
|
168
|
+
next = attachment.exp;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.#nextExpiry = next;
|
|
172
|
+
}
|
|
173
|
+
/** True while a `disconnect` of this identity is less than the window old. */
|
|
174
|
+
async #revoked(tag) {
|
|
175
|
+
const key = REVOKED_PREFIX + tag;
|
|
176
|
+
const at = await this.#state.storage.get(key);
|
|
177
|
+
if (at === undefined)
|
|
178
|
+
return false;
|
|
179
|
+
if (typeof at === "number" && Date.now() - at < REVOCATION_WINDOW_MS)
|
|
180
|
+
return true;
|
|
181
|
+
// Expired: delete it lazily. Not awaited, so the caller's checks and accept follow the
|
|
182
|
+
// read with no other await in between (writes apply to the storage cache at once).
|
|
183
|
+
this.#state.storage.delete(key).catch(() => undefined);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
async #connect(request) {
|
|
187
|
+
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket")
|
|
188
|
+
return badRequest();
|
|
189
|
+
let room;
|
|
190
|
+
let identity;
|
|
191
|
+
let channels;
|
|
192
|
+
try {
|
|
193
|
+
const raw = JSON.parse(request.headers.get(CONNECT_HEADER) ?? "");
|
|
194
|
+
assertValidRoom(raw?.room);
|
|
195
|
+
assertValidChannels(raw?.channels);
|
|
196
|
+
room = raw.room;
|
|
197
|
+
identity = validIdentity(raw?.identity);
|
|
198
|
+
channels = [...raw.channels];
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return badRequest();
|
|
202
|
+
}
|
|
203
|
+
const tag = await identityTag(identity);
|
|
204
|
+
if (await this.#revoked(tag))
|
|
205
|
+
return json({ error: "limit" }, 429);
|
|
206
|
+
// No await from here to the accept, so the checks and the accept run as one step: no
|
|
207
|
+
// other connect or disconnect of this room can run in between.
|
|
208
|
+
this.#expire();
|
|
209
|
+
// The caps count every socket the runtime still holds, open or closing: a peer that never
|
|
210
|
+
// answers a close frame must not be able to pile up sockets.
|
|
211
|
+
if (this.#state.getWebSockets().length >= config.maxConnections ||
|
|
212
|
+
this.#state.getWebSockets(tag).length >= config.maxConnectionsPerIdentity) {
|
|
213
|
+
return json({ error: "limit" }, 429);
|
|
214
|
+
}
|
|
215
|
+
const connections = this.#open().length + 1;
|
|
216
|
+
const identityConnections = this.#open(tag).length + 1;
|
|
217
|
+
const pair = new WebSocketPair();
|
|
218
|
+
const server = pair[1];
|
|
219
|
+
// At most 8 channels + 1 identity tag (74 ASCII characters): within the platform's 10
|
|
220
|
+
// tags of up to 256 bytes.
|
|
221
|
+
this.#state.acceptWebSocket(server, [...channels, tag]);
|
|
222
|
+
const at = Date.now();
|
|
223
|
+
// Jittered age in [90 %, 100 %] of the maximum, never above it.
|
|
224
|
+
const exp = at + Math.floor(config.maxAgeMs * (0.9 + Math.random() * 0.1));
|
|
225
|
+
const attachment = {
|
|
226
|
+
v: 1,
|
|
227
|
+
room,
|
|
228
|
+
id: identity.id,
|
|
229
|
+
kind: identity.kind,
|
|
230
|
+
channels,
|
|
231
|
+
at,
|
|
232
|
+
exp,
|
|
233
|
+
};
|
|
234
|
+
server.serializeAttachment(attachment);
|
|
235
|
+
if (this.#nextExpiry !== undefined)
|
|
236
|
+
this.#nextExpiry = Math.min(this.#nextExpiry, exp);
|
|
237
|
+
if (config.onConnect) {
|
|
238
|
+
try {
|
|
239
|
+
await config.onConnect({
|
|
240
|
+
room,
|
|
241
|
+
identity,
|
|
242
|
+
channels: Object.freeze([...channels]),
|
|
243
|
+
connectedAt: new Date(at),
|
|
244
|
+
connections,
|
|
245
|
+
identityConnections,
|
|
246
|
+
env: this.#env,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
logHookFailure("onConnect", error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return new Response(null, { status: 101, webSocket: pair[0] });
|
|
254
|
+
}
|
|
255
|
+
async #publish(request) {
|
|
256
|
+
const body = await readJson(request);
|
|
257
|
+
let frame;
|
|
258
|
+
let channel;
|
|
259
|
+
try {
|
|
260
|
+
const event = validEvent(body?.event, config.maxEventBytes);
|
|
261
|
+
frame = eventFrame(event);
|
|
262
|
+
channel = event.channel;
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return badRequest();
|
|
266
|
+
}
|
|
267
|
+
this.#expire();
|
|
268
|
+
let delivered = 0;
|
|
269
|
+
for (const ws of this.#open(channel)) {
|
|
270
|
+
try {
|
|
271
|
+
ws.send(frame);
|
|
272
|
+
delivered++;
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// One failed socket does not stop the others; its close event will follow.
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return json({ delivered });
|
|
279
|
+
}
|
|
280
|
+
async #disconnect(request) {
|
|
281
|
+
const body = await readJson(request);
|
|
282
|
+
let identity;
|
|
283
|
+
try {
|
|
284
|
+
identity = validIdentity(body?.identity);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return badRequest();
|
|
288
|
+
}
|
|
289
|
+
const tag = await identityTag(identity);
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
// The marker first, then the close, with no await between: a connect of this identity
|
|
292
|
+
// either was accepted already (and is closed here) or sees the marker.
|
|
293
|
+
const written = this.#state.storage.put(REVOKED_PREFIX + tag, now);
|
|
294
|
+
let closed = 0;
|
|
295
|
+
for (const ws of this.#open(tag)) {
|
|
296
|
+
closeQuietly(ws, CLOSE_DISCONNECTED, "Disconnected");
|
|
297
|
+
closed++;
|
|
298
|
+
}
|
|
299
|
+
await written;
|
|
300
|
+
await this.#pruneMarkers(now);
|
|
301
|
+
return json({ closed });
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Open connections with their identity, channels, connect time and last answered `"ping"`.
|
|
305
|
+
* Read from the attachments and the runtime's auto-response timestamps: nothing is stored.
|
|
306
|
+
*/
|
|
307
|
+
async #presence(request) {
|
|
308
|
+
const body = await readJson(request);
|
|
309
|
+
if (body === undefined || Array.isArray(body))
|
|
310
|
+
return badRequest();
|
|
311
|
+
let query;
|
|
312
|
+
try {
|
|
313
|
+
query = validPresenceQuery(body.query);
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return badRequest();
|
|
317
|
+
}
|
|
318
|
+
// The identity tag narrows the listing to that identity's few sockets; the channel tag
|
|
319
|
+
// otherwise. The expiry below may still sweep the whole room (bounded by maxConnections).
|
|
320
|
+
const tag = query.identity !== undefined ? await identityTag(query.identity) : query.channel;
|
|
321
|
+
// No await from here on: what is listed is one consistent view of the room.
|
|
322
|
+
this.#expire();
|
|
323
|
+
const now = Date.now();
|
|
324
|
+
const records = [];
|
|
325
|
+
for (const ws of this.#open(tag)) {
|
|
326
|
+
const attachment = readAttachment(ws);
|
|
327
|
+
if (attachment === undefined || attachment.done)
|
|
328
|
+
continue;
|
|
329
|
+
const pinged = this.#state.getWebSocketAutoResponseTimestamp(ws)?.getTime();
|
|
330
|
+
try {
|
|
331
|
+
// Checked like the publisher checks the answer (identity, channels, times), so one
|
|
332
|
+
// malformed attachment is skipped instead of making the whole answer invalid.
|
|
333
|
+
records.push(presenceRecord({
|
|
334
|
+
identity: { id: attachment.id, kind: attachment.kind },
|
|
335
|
+
channels: attachment.channels,
|
|
336
|
+
connectedAt: attachment.at,
|
|
337
|
+
lastSeenAt: typeof pinged === "number" && typeof attachment.at === "number"
|
|
338
|
+
? Math.max(attachment.at, pinged)
|
|
339
|
+
: attachment.at,
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
// Not listed. Never logged: the attachment holds the identity id.
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// The shared selection applies both filters (so `identity` with `channel` intersect),
|
|
347
|
+
// the activity window, the order and the limit.
|
|
348
|
+
const selected = selectPresence(records, query, now);
|
|
349
|
+
return json({ connections: selected.records, total: selected.total });
|
|
350
|
+
}
|
|
351
|
+
/** Deletes revocation markers older than the window (other identities' included). */
|
|
352
|
+
async #pruneMarkers(now) {
|
|
353
|
+
const markers = await this.#state.storage.list({ prefix: REVOKED_PREFIX });
|
|
354
|
+
const expired = [];
|
|
355
|
+
for (const [key, at] of markers) {
|
|
356
|
+
if (typeof at !== "number" || now - at >= REVOCATION_WINDOW_MS)
|
|
357
|
+
expired.push(key);
|
|
358
|
+
}
|
|
359
|
+
for (let i = 0; i < expired.length; i += DELETE_BATCH) {
|
|
360
|
+
await this.#state.storage.delete(expired.slice(i, i + DELETE_BATCH));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async #gone(ws) {
|
|
364
|
+
closeQuietly(ws, 1000, "");
|
|
365
|
+
const attachment = readAttachment(ws);
|
|
366
|
+
if (attachment === undefined || attachment.done)
|
|
367
|
+
return;
|
|
368
|
+
try {
|
|
369
|
+
ws.serializeAttachment({ ...attachment, done: true });
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
// Some runtimes refuse writes on a closed socket; the hook may then run twice at most.
|
|
373
|
+
}
|
|
374
|
+
if (!config.onDisconnect)
|
|
375
|
+
return;
|
|
376
|
+
const identity = Object.freeze({ id: attachment.id, kind: attachment.kind });
|
|
377
|
+
// The socket's own identity tag, read synchronously so both counts are one view of the
|
|
378
|
+
// room; hashed again only if the runtime cannot give the tags of a closed socket.
|
|
379
|
+
const tag = this.#identityTagOf(ws) ?? (await identityTag(identity));
|
|
380
|
+
const others = (list) => list.filter((other) => other !== ws).length;
|
|
381
|
+
const connections = others(this.#open());
|
|
382
|
+
const identityConnections = others(this.#open(tag));
|
|
383
|
+
try {
|
|
384
|
+
await config.onDisconnect({
|
|
385
|
+
room: attachment.room,
|
|
386
|
+
identity,
|
|
387
|
+
channels: Object.freeze([...attachment.channels]),
|
|
388
|
+
connectedAt: new Date(attachment.at),
|
|
389
|
+
connections,
|
|
390
|
+
identityConnections,
|
|
391
|
+
env: this.#env,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
logHookFailure("onDisconnect", error);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=room.js.map
|
package/dist/room.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.js","sourceRoot":"","sources":["../src/room.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,IAAI,EAEJ,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,qBAAqB,EACrB,UAAU,GACX,MAAM,iBAAiB,CAAC;AAgEzB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,uFAAuF;AACvF,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,+CAA+C;AAC/C,MAAM,YAAY,GAAG,GAAG,CAAC;AAWzB,SAAS,aAAa,CACpB,IAAY,EACZ,KAAc,EACd,QAAgB,EAChB,GAAW,EACX,GAAW;IAEX,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QACxF,MAAM,IAAI,SAAS,CAAC,eAAe,IAAI,4BAA4B,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,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AAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only in-memory publisher. Never use it in production: nothing is delivered anywhere.
|
|
3
|
+
* Import it from `@cardonjs/realtime-do/testing`.
|
|
4
|
+
*/
|
|
5
|
+
import { type PresenceQuery } from "./presence.js";
|
|
6
|
+
import { type RoomIdentity } from "./protocol.js";
|
|
7
|
+
import type { RealtimePublisher } from "./publisher.js";
|
|
8
|
+
import { type RealtimeEvent } from "./validation.js";
|
|
9
|
+
export type { PresenceQuery } from "./presence.js";
|
|
10
|
+
export interface PublishedEvent {
|
|
11
|
+
readonly room: string;
|
|
12
|
+
readonly event: RealtimeEvent;
|
|
13
|
+
}
|
|
14
|
+
export interface DisconnectCall {
|
|
15
|
+
readonly room: string;
|
|
16
|
+
/** Only `id` and `kind`, frozen. */
|
|
17
|
+
readonly identity: RoomIdentity;
|
|
18
|
+
}
|
|
19
|
+
export interface PresenceQueryCall {
|
|
20
|
+
readonly room: string;
|
|
21
|
+
/**
|
|
22
|
+
* The validated query (frozen): only the options given, the identity as `id` and `kind`, and
|
|
23
|
+
* `limit` filled in (default 100).
|
|
24
|
+
*/
|
|
25
|
+
readonly query: PresenceQuery;
|
|
26
|
+
}
|
|
27
|
+
/** A connection the fake reports through `presence` (see `setPresence`). */
|
|
28
|
+
export interface FakeConnection {
|
|
29
|
+
readonly identity: RoomIdentity;
|
|
30
|
+
readonly channels: readonly string[];
|
|
31
|
+
readonly connectedAt: Date;
|
|
32
|
+
/** Default `connectedAt` (no `"ping"` answered yet). Not before `connectedAt`, not after now. */
|
|
33
|
+
readonly lastSeenAt?: Date;
|
|
34
|
+
}
|
|
35
|
+
export interface MemoryRealtime extends RealtimePublisher {
|
|
36
|
+
/** Every publish, in order, with the validated (frozen) event. */
|
|
37
|
+
readonly published: readonly PublishedEvent[];
|
|
38
|
+
/** Every disconnect, in order. */
|
|
39
|
+
readonly disconnected: readonly DisconnectCall[];
|
|
40
|
+
/** Every presence query, in order (only the valid ones). */
|
|
41
|
+
readonly presenceQueries: readonly PresenceQueryCall[];
|
|
42
|
+
/** What `count(room)` resolves with, and what `publish` reports as delivered. Default 0. */
|
|
43
|
+
setCount(room: string, count: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* The open connections `presence(room)` sees, replacing any set before. `presence` applies the
|
|
46
|
+
* same filters, order and limit as the room, with `activeWithinSeconds` measured against
|
|
47
|
+
* `Date.now()` (fake timers apply). Independent of `setCount`. Times after `Date.now()` are
|
|
48
|
+
* rejected: the room never reports them.
|
|
49
|
+
*/
|
|
50
|
+
setPresence(room: string, connections: readonly FakeConnection[]): void;
|
|
51
|
+
/** Forgets the recorded calls (presence queries included), counts and connections. */
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
54
|
+
export interface MemoryRealtimeOptions {
|
|
55
|
+
/** The room's `maxEventBytes`. Default 16 384. */
|
|
56
|
+
readonly maxEventBytes?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* **Test-only.** A `RealtimePublisher` that validates every call with the same rules as the
|
|
60
|
+
* real one and records it. There are no real connections or channels: `publish` reports the
|
|
61
|
+
* room's count (set with `setCount`) as delivered, `disconnect` reports 0 closed, and `presence`
|
|
62
|
+
* lists what `setPresence` set.
|
|
63
|
+
*/
|
|
64
|
+
export declare function memoryRealtime(options?: MemoryRealtimeOptions): MemoryRealtime;
|
|
65
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,iBAAiB,CAAC;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D;IAClD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAkFlF"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only in-memory publisher. Never use it in production: nothing is delivered anywhere.
|
|
3
|
+
* Import it from `@cardonjs/realtime-do/testing`.
|
|
4
|
+
*/
|
|
5
|
+
import { isTime, presenceConnection, selectPresence, validPresenceQuery, } from "./presence.js";
|
|
6
|
+
import { validIdentity } from "./protocol.js";
|
|
7
|
+
import { assertValidChannels, assertValidRoom, DEFAULT_MAX_EVENT_BYTES, validEvent, } from "./validation.js";
|
|
8
|
+
/**
|
|
9
|
+
* **Test-only.** A `RealtimePublisher` that validates every call with the same rules as the
|
|
10
|
+
* real one and records it. There are no real connections or channels: `publish` reports the
|
|
11
|
+
* room's count (set with `setCount`) as delivered, `disconnect` reports 0 closed, and `presence`
|
|
12
|
+
* lists what `setPresence` set.
|
|
13
|
+
*/
|
|
14
|
+
export function memoryRealtime(options = {}) {
|
|
15
|
+
const maxEventBytes = options.maxEventBytes ?? DEFAULT_MAX_EVENT_BYTES;
|
|
16
|
+
const published = [];
|
|
17
|
+
const disconnected = [];
|
|
18
|
+
const presenceQueries = [];
|
|
19
|
+
const counts = new Map();
|
|
20
|
+
const connections = new Map();
|
|
21
|
+
return {
|
|
22
|
+
published,
|
|
23
|
+
disconnected,
|
|
24
|
+
presenceQueries,
|
|
25
|
+
async publish(room, event) {
|
|
26
|
+
assertValidRoom(room);
|
|
27
|
+
const valid = validEvent(event, maxEventBytes);
|
|
28
|
+
published.push(Object.freeze({ room, event: valid }));
|
|
29
|
+
return { delivered: counts.get(room) ?? 0 };
|
|
30
|
+
},
|
|
31
|
+
async count(room) {
|
|
32
|
+
assertValidRoom(room);
|
|
33
|
+
return counts.get(room) ?? 0;
|
|
34
|
+
},
|
|
35
|
+
async disconnect(room, identity) {
|
|
36
|
+
assertValidRoom(room);
|
|
37
|
+
const valid = validIdentity(identity);
|
|
38
|
+
disconnected.push(Object.freeze({ room, identity: valid }));
|
|
39
|
+
return { closed: 0 };
|
|
40
|
+
},
|
|
41
|
+
async presence(room, options) {
|
|
42
|
+
assertValidRoom(room);
|
|
43
|
+
const query = validPresenceQuery(options);
|
|
44
|
+
presenceQueries.push(Object.freeze({ room, query }));
|
|
45
|
+
const selected = selectPresence(connections.get(room) ?? [], query, Date.now());
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
connections: Object.freeze(selected.records.map(presenceConnection)),
|
|
48
|
+
total: selected.total,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
setPresence(room, list) {
|
|
52
|
+
assertValidRoom(room);
|
|
53
|
+
if (!Array.isArray(list)) {
|
|
54
|
+
throw new TypeError("memoryRealtime: connections must be an array.");
|
|
55
|
+
}
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
const records = list.map((connection) => {
|
|
58
|
+
if (typeof connection !== "object" || connection === null) {
|
|
59
|
+
throw new TypeError("memoryRealtime: each connection must be an object.");
|
|
60
|
+
}
|
|
61
|
+
const identity = validIdentity(connection.identity);
|
|
62
|
+
assertValidChannels(connection.channels);
|
|
63
|
+
const connectedAt = timeOf(connection.connectedAt);
|
|
64
|
+
const lastSeenAt = connection.lastSeenAt === undefined ? connectedAt : timeOf(connection.lastSeenAt);
|
|
65
|
+
if (connectedAt === undefined || lastSeenAt === undefined || lastSeenAt < connectedAt) {
|
|
66
|
+
throw new TypeError("memoryRealtime: connectedAt must be a valid Date and lastSeenAt one not before it.");
|
|
67
|
+
}
|
|
68
|
+
if (lastSeenAt > now) {
|
|
69
|
+
// lastSeenAt >= connectedAt, so this covers both. The room never reports a future time,
|
|
70
|
+
// and one would pass every activeWithinSeconds filter.
|
|
71
|
+
throw new TypeError("memoryRealtime: connectedAt and lastSeenAt must not be after now.");
|
|
72
|
+
}
|
|
73
|
+
return { identity, channels: [...connection.channels], connectedAt, lastSeenAt };
|
|
74
|
+
});
|
|
75
|
+
connections.set(room, records);
|
|
76
|
+
},
|
|
77
|
+
setCount(room, count) {
|
|
78
|
+
assertValidRoom(room);
|
|
79
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
80
|
+
throw new TypeError("memoryRealtime: count must be a non-negative integer.");
|
|
81
|
+
}
|
|
82
|
+
counts.set(room, count);
|
|
83
|
+
},
|
|
84
|
+
clear() {
|
|
85
|
+
published.length = 0;
|
|
86
|
+
disconnected.length = 0;
|
|
87
|
+
presenceQueries.length = 0;
|
|
88
|
+
counts.clear();
|
|
89
|
+
connections.clear();
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function timeOf(value) {
|
|
94
|
+
if (!(value instanceof Date))
|
|
95
|
+
return undefined;
|
|
96
|
+
const time = value.getTime();
|
|
97
|
+
return isTime(time) ? time : undefined;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,MAAM,EAGN,kBAAkB,EAClB,cAAc,EACd,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqB,aAAa,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EAEvB,UAAU,GACX,MAAM,iBAAiB,CAAC;AA0DzB;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAO,GAA0B,EAAE;IAChE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,uBAAuB,CAAC;IACvE,MAAM,SAAS,GAAqB,EAAE,CAAC;IACvC,MAAM,YAAY,GAAqB,EAAE,CAAC;IAC1C,MAAM,eAAe,GAAwB,EAAE,CAAC;IAChD,MAAM,MAAM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|
1
|
+
/**
|
|
2
|
+
* Names and events, validated the same way by the room, the publisher, the fake and the client.
|
|
3
|
+
* No imports and no runtime-specific APIs: this module also ships in the browser client.
|
|
4
|
+
*
|
|
5
|
+
* Every failure is a programming error (the values are built by the server), so it is a plain
|
|
6
|
+
* `TypeError` whose message never includes the value.
|
|
7
|
+
*/
|
|
8
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
9
|
+
[key: string]: JsonValue;
|
|
10
|
+
};
|
|
11
|
+
/** What a client receives. The WebSocket only signals "something changed"; reload the data. */
|
|
12
|
+
export interface RealtimeEvent {
|
|
13
|
+
readonly channel: string;
|
|
14
|
+
/** e.g. `"order.updated"`. */
|
|
15
|
+
readonly type: string;
|
|
16
|
+
/** A small hint (ids), never the record itself. */
|
|
17
|
+
readonly data?: JsonValue;
|
|
18
|
+
}
|
|
19
|
+
/** Room and channel names. */
|
|
20
|
+
export declare const NAME_PATTERN: RegExp;
|
|
21
|
+
/** Event types. */
|
|
22
|
+
export declare const EVENT_TYPE_PATTERN: RegExp;
|
|
23
|
+
/** Channels a connection may join. */
|
|
24
|
+
export declare const MAX_CHANNELS = 8;
|
|
25
|
+
/** Default and smallest-common size of a serialized frame, in UTF-8 bytes. */
|
|
26
|
+
export declare const DEFAULT_MAX_EVENT_BYTES = 16384;
|
|
27
|
+
/** Upper bound for `maxEventBytes` (the frame also travels in a request to the room). */
|
|
28
|
+
export declare const MAX_EVENT_BYTES_LIMIT = 1048576;
|
|
29
|
+
export declare function assertValidRoom(room: unknown): asserts room is string;
|
|
30
|
+
export declare function assertValidChannel(channel: unknown): asserts channel is string;
|
|
31
|
+
export declare function assertValidChannels(channels: unknown): asserts channels is readonly string[];
|
|
32
|
+
/** The frame sent to clients: `{"channel":…,"type":…,"data":…}`, `data` omitted when absent. */
|
|
33
|
+
export declare function eventFrame(event: RealtimeEvent): string;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a frozen, validated copy of `event` (only `channel`, `type` and `data` are kept).
|
|
36
|
+
* The serialized frame must be at most `maxEventBytes` UTF-8 bytes (default 16 384).
|
|
37
|
+
*/
|
|
38
|
+
export declare function validEvent(event: unknown, maxEventBytes?: number): RealtimeEvent;
|
|
39
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC,+FAA+F;AAC/F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,8BAA8B;AAC9B,eAAO,MAAM,YAAY,QAAwC,CAAC;AAClE,mBAAmB;AACnB,eAAO,MAAM,kBAAkB,QAAiC,CAAC;AACjE,sCAAsC;AACtC,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,8EAA8E;AAC9E,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,yFAAyF;AACzF,eAAO,MAAM,qBAAqB,UAAY,CAAC;AAK/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,CAMrE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAM9E;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,IAAI,SAAS,MAAM,EAAE,CAQ5F;AA8CD,gGAAgG;AAChG,wBAAgB,UAAU,C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