@dovetail-ts/protocol 0.0.0-stage → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @dovetail-ts/protocol
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 480744b: First release of Dovetail: real-time and offline sync for Ember.
8
+
9
+ - `@dovetail-ts/core`: the connection life cycle, live store subscriptions, the optimistic ledger with rebase and rollback, the offline write queue in IndexedDB with a leader tab and dead letters, `DocSession` and `PresenceRoom`.
10
+ - `@dovetail-ts/warp-drive`: the store feed into WarpDrive.
11
+ - `@dovetail-ts/crdt`, `crdt-yjs`, `crdt-loro` and `crdt-automerge`: one `DocEngine` interface with three engines.
12
+ - `@dovetail-ts/tiptap`: co-editing in Tiptap 3 with carets, per-user undo, versions and comment threads.
13
+ - `@dovetail-ts/ember`, `notifications` and `inspector`: presence and status components, the inbox, toasts and activity feeds, and a dev panel.
14
+ - `@dovetail-ts/server`, the transports (`transport-ws`, `transport-sse`, `transport-cable`) and `conformance`: a Node server and one wire protocol that the Rails gems also pass.
15
+ - Adapters for Hocuspocus, Liveblocks, PartyKit and Supabase, and integrations for Switchyard, Millwork, Benchdog and Lattice. The Neon adapter is not in 1.0: it waits for a stable Neon Realtime client (1.1).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @dovetail-ts/protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Wire message types, version negotiation and the message validator. No runtime dependency.
4
+
5
+ Part of [Dovetail](https://joegaudet.com/dovetail/). Not released yet.
@@ -0,0 +1,4 @@
1
+ /** Encodes bytes as standard base64. */
2
+ export declare function toBase64(bytes: Uint8Array): string;
3
+ /** Decodes standard base64. Throws on text that is not base64. */
4
+ export declare function fromBase64(text: string): Uint8Array;
@@ -0,0 +1,9 @@
1
+ export { fromBase64, toBase64 } from './base64';
2
+ export { CLIENT_TYPES, ERROR_CODES, SERVER_TYPES, encodeMessage } from './messages';
3
+ export type { AckMessage, AwarenessMessage, ClientMessage, DocSyncMessage, DocUpdateMessage, ErrorCode, ErrorMessage, FeedMessage, HelloMessage, JoinMessage, JsonApiDocument, JsonApiError, JsonObject, JsonValue, LeaveMessage, Message, PingMessage, PongMessage, RejectMessage, Relationship, Resource, ResourceIdentifier, ServerMessage, StoreOp, WelcomeMessage, WriteMessage, } from './messages';
4
+ export { NOTIFICATION_TYPE, isUserRoom, userRoom } from './notifications';
5
+ export type { NotificationAttributes, NotificationResource } from './notifications';
6
+ export { DEFAULT_LIMITS, parseMessage } from './parse';
7
+ export type { Limits, ParseError, ParseOptions, ParseResult } from './parse';
8
+ export type { ClientTransport, CloseInfo, ServerTransport, Transport } from './transport';
9
+ export { PROTOCOL_VERSION, SUPPORTED_VERSIONS, negotiateVersion } from './version';
package/dist/index.js ADDED
@@ -0,0 +1,363 @@
1
+ // src/base64.ts
2
+ function toBase64(bytes) {
3
+ let binary = "";
4
+ for (let i = 0; i < bytes.length; i += 32768) {
5
+ binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
6
+ }
7
+ return btoa(binary);
8
+ }
9
+ function fromBase64(text) {
10
+ let binary;
11
+ try {
12
+ binary = atob(text);
13
+ } catch {
14
+ throw new Error("fromBase64: the text is not base64");
15
+ }
16
+ return Uint8Array.from(binary, (char) => char.charCodeAt(0));
17
+ }
18
+
19
+ // src/messages.ts
20
+ var ERROR_CODES = [
21
+ "invalid-message",
22
+ "too-large",
23
+ "unsupported-version",
24
+ "unauthorized",
25
+ "forbidden",
26
+ "not-joined",
27
+ "rate-limited",
28
+ "internal"
29
+ ];
30
+ var CLIENT_TYPES = [
31
+ "hello",
32
+ "join",
33
+ "leave",
34
+ "write",
35
+ "ping",
36
+ "doc-update",
37
+ "doc-sync",
38
+ "awareness"
39
+ ];
40
+ var SERVER_TYPES = [
41
+ "welcome",
42
+ "ack",
43
+ "reject",
44
+ "error",
45
+ "feed",
46
+ "pong",
47
+ "doc-update",
48
+ "doc-sync",
49
+ "awareness"
50
+ ];
51
+ function encodeMessage(message) {
52
+ return JSON.stringify(message);
53
+ }
54
+
55
+ // src/notifications.ts
56
+ var NOTIFICATION_TYPE = "notification";
57
+ var USER_ROOM_PREFIX = "user:";
58
+ function userRoom(userId) {
59
+ if (userId.length === 0) throw new Error("userRoom needs a user id");
60
+ return `${USER_ROOM_PREFIX}${userId}`;
61
+ }
62
+ function isUserRoom(room) {
63
+ return room.startsWith(USER_ROOM_PREFIX) && room.length > USER_ROOM_PREFIX.length;
64
+ }
65
+ var DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
66
+ function checkNotification(c, resource, path, partial = false) {
67
+ if (partial && resource["attributes"] === void 0) return;
68
+ const attributes = c.object(resource["attributes"], `${path}.attributes`);
69
+ if (!partial || attributes["verb"] !== void 0)
70
+ c.name(attributes["verb"], `${path}.attributes.verb`);
71
+ const dateTime = (key, nullable) => {
72
+ const value = attributes[key];
73
+ if (partial && value === void 0) return;
74
+ if (nullable && (value === null || key === "archivedAt" && value === void 0)) return;
75
+ const text = c.string(value, `${path}.attributes.${key}`);
76
+ if (!DATE_TIME.test(text) || Number.isNaN(Date.parse(text))) {
77
+ c.fail(`${path}.attributes.${key}`, "must be an ISO 8601 date-time");
78
+ }
79
+ };
80
+ dateTime("createdAt", false);
81
+ dateTime("readAt", true);
82
+ dateTime("seenAt", true);
83
+ dateTime("archivedAt", true);
84
+ if (partial && resource["relationships"] === void 0) return;
85
+ const relationships = c.object(resource["relationships"], `${path}.relationships`);
86
+ for (const name of ["actor", "target"]) {
87
+ const relationship = c.object(relationships[name], `${path}.relationships.${name}`);
88
+ c.identifier(relationship["data"], `${path}.relationships.${name}.data`);
89
+ }
90
+ }
91
+
92
+ // src/parse.ts
93
+ var DEFAULT_LIMITS = Object.freeze({
94
+ maxMessageBytes: 1024 * 1024,
95
+ maxNameLength: 256,
96
+ maxOps: 1e3,
97
+ maxDepth: 32
98
+ });
99
+ var Failure = class extends Error {
100
+ constructor(code, path, message) {
101
+ super(message);
102
+ this.code = code;
103
+ this.path = path;
104
+ }
105
+ code;
106
+ path;
107
+ };
108
+ var join = (path, key) => typeof key === "number" ? `${path}[${key}]` : path ? `${path}.${key}` : key;
109
+ var BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
110
+ var isRecord = (value) => {
111
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
112
+ const proto = Object.getPrototypeOf(value);
113
+ return proto === Object.prototype || proto === null;
114
+ };
115
+ var Checker = class {
116
+ constructor(limits) {
117
+ this.limits = limits;
118
+ }
119
+ limits;
120
+ /** True in a client write to a per-user room: a notification can be partial there. */
121
+ partialNotifications = false;
122
+ fail(path, message, code = "invalid-message") {
123
+ throw new Failure(code, path, message);
124
+ }
125
+ object(value, path) {
126
+ if (!isRecord(value)) this.fail(path, "must be an object");
127
+ return value;
128
+ }
129
+ string(value, path) {
130
+ if (typeof value !== "string") this.fail(path, "must be a string");
131
+ return value;
132
+ }
133
+ /** A name: a non-empty string within `maxNameLength`. */
134
+ name(value, path) {
135
+ const text = this.string(value, path);
136
+ if (text.length === 0) this.fail(path, "must not be empty");
137
+ if (text.length > this.limits.maxNameLength) {
138
+ this.fail(path, `is longer than ${this.limits.maxNameLength}`, "too-large");
139
+ }
140
+ return text;
141
+ }
142
+ optionalName(record, key, path) {
143
+ if (record[key] !== void 0) this.name(record[key], join(path, key));
144
+ }
145
+ base64(value, path) {
146
+ if (!BASE64.test(this.string(value, path))) this.fail(path, "must be base64");
147
+ }
148
+ integer(value, path) {
149
+ if (typeof value !== "number" || !Number.isInteger(value)) this.fail(path, "must be an integer");
150
+ return value;
151
+ }
152
+ array(value, path) {
153
+ if (!Array.isArray(value)) this.fail(path, "must be an array");
154
+ return value;
155
+ }
156
+ /** Any JSON value, within `maxDepth`. A cycle is deeper than any limit. */
157
+ json(value, path, depth = 0) {
158
+ if (value === null || typeof value === "string" || typeof value === "boolean") return;
159
+ if (typeof value === "number") {
160
+ if (!Number.isFinite(value)) this.fail(path, "must be a finite number");
161
+ return;
162
+ }
163
+ if (depth >= this.limits.maxDepth) {
164
+ this.fail(path, `is nested deeper than ${this.limits.maxDepth}`, "too-large");
165
+ }
166
+ if (Array.isArray(value)) {
167
+ value.forEach((item, index) => this.json(item, join(path, index), depth + 1));
168
+ return;
169
+ }
170
+ if (!isRecord(value)) this.fail(path, "must be a JSON value");
171
+ for (const [key, item] of Object.entries(value)) this.json(item, join(path, key), depth + 1);
172
+ }
173
+ jsonObject(value, path) {
174
+ this.object(value, path);
175
+ this.json(value, path);
176
+ }
177
+ optionalJsonObject(record, key, path) {
178
+ if (record[key] !== void 0) this.jsonObject(record[key], join(path, key));
179
+ }
180
+ identifier(value, path) {
181
+ const ref = this.object(value, path);
182
+ this.name(ref["type"], join(path, "type"));
183
+ this.name(ref["id"], join(path, "id"));
184
+ }
185
+ resource(value, path) {
186
+ const resource = this.object(value, path);
187
+ const type = this.name(resource["type"], join(path, "type"));
188
+ this.name(resource["id"], join(path, "id"));
189
+ this.optionalJsonObject(resource, "attributes", path);
190
+ if (resource["relationships"] !== void 0) {
191
+ const relationships = this.object(resource["relationships"], join(path, "relationships"));
192
+ for (const [name, relationship] of Object.entries(relationships)) {
193
+ const at = join(join(path, "relationships"), name);
194
+ const data = this.object(relationship, at)["data"];
195
+ if (Array.isArray(data))
196
+ data.forEach((ref, i) => this.identifier(ref, join(join(at, "data"), i)));
197
+ else if (data !== null) this.identifier(data, join(at, "data"));
198
+ this.json(relationship, at);
199
+ }
200
+ }
201
+ this.optionalJsonObject(resource, "links", path);
202
+ this.optionalJsonObject(resource, "meta", path);
203
+ if (type === NOTIFICATION_TYPE)
204
+ checkNotification(this, resource, path, this.partialNotifications);
205
+ }
206
+ document(value, path) {
207
+ const document = this.object(value, path);
208
+ if (!("data" in document)) this.fail(join(path, "data"), "is required");
209
+ const data = document["data"];
210
+ if (Array.isArray(data))
211
+ data.forEach((item, i) => this.resource(item, join(join(path, "data"), i)));
212
+ else if (data !== null) this.resource(data, join(path, "data"));
213
+ if (document["included"] !== void 0) {
214
+ const included = this.array(document["included"], join(path, "included"));
215
+ included.forEach((item, i) => this.resource(item, join(join(path, "included"), i)));
216
+ }
217
+ this.optionalJsonObject(document, "meta", path);
218
+ }
219
+ storeOp(value, path) {
220
+ const op = this.object(value, path);
221
+ if (op["op"] === "upsert") this.document(op["document"], join(path, "document"));
222
+ else if (op["op"] === "delete") this.identifier(op["ref"], join(path, "ref"));
223
+ else this.fail(join(path, "op"), "must be 'upsert' or 'delete'");
224
+ }
225
+ apiError(value, path) {
226
+ const error = this.object(value, path);
227
+ for (const key of ["id", "status", "code", "title", "detail"]) {
228
+ if (error[key] !== void 0) this.string(error[key], join(path, key));
229
+ }
230
+ if (error["source"] !== void 0) {
231
+ const source = this.object(error["source"], join(path, "source"));
232
+ for (const [key, item] of Object.entries(source))
233
+ this.string(item, join(join(path, "source"), key));
234
+ }
235
+ this.optionalJsonObject(error, "meta", path);
236
+ }
237
+ };
238
+ var BODIES = {
239
+ hello(c, m) {
240
+ c.array(m["versions"], "versions").forEach((v, i) => c.integer(v, join("versions", i)));
241
+ if (m["token"] !== void 0) c.string(m["token"], "token");
242
+ if (m["client"] !== void 0) {
243
+ const client = c.object(m["client"], "client");
244
+ c.name(client["name"], "client.name");
245
+ c.name(client["version"], "client.version");
246
+ }
247
+ },
248
+ join(c, m) {
249
+ c.name(m["id"], "id");
250
+ c.name(m["room"], "room");
251
+ c.optionalName(m, "since", "");
252
+ },
253
+ leave(c, m) {
254
+ c.name(m["id"], "id");
255
+ c.name(m["room"], "room");
256
+ },
257
+ write(c, m) {
258
+ c.name(m["id"], "id");
259
+ c.partialNotifications = isUserRoom(c.name(m["room"], "room"));
260
+ c.storeOp(m["op"], "op");
261
+ },
262
+ ping(c, m) {
263
+ c.name(m["id"], "id");
264
+ },
265
+ "doc-update"(c, m) {
266
+ c.name(m["room"], "room");
267
+ c.name(m["doc"], "doc");
268
+ c.base64(m["update"], "update");
269
+ c.optionalName(m, "origin", "");
270
+ },
271
+ "doc-sync"(c, m) {
272
+ c.name(m["room"], "room");
273
+ c.name(m["doc"], "doc");
274
+ if (m["step"] === 1) c.base64(m["stateVector"], "stateVector");
275
+ else if (m["step"] === 2) c.base64(m["update"], "update");
276
+ else c.fail("step", "must be 1 or 2");
277
+ },
278
+ awareness(c, m) {
279
+ c.name(m["room"], "room");
280
+ c.optionalName(m, "clientId", "");
281
+ if (m["state"] !== null) c.jsonObject(m["state"], "state");
282
+ },
283
+ welcome(c, m) {
284
+ c.integer(m["version"], "version");
285
+ c.name(m["session"], "session");
286
+ if (m["user"] !== void 0) c.name(c.object(m["user"], "user")["id"], "user.id");
287
+ },
288
+ ack(c, m) {
289
+ c.name(m["ref"], "ref");
290
+ c.optionalName(m, "cursor", "");
291
+ if (m["reset"] !== void 0 && typeof m["reset"] !== "boolean")
292
+ c.fail("reset", "must be a boolean");
293
+ if (m["document"] !== void 0) c.document(m["document"], "document");
294
+ },
295
+ reject(c, m) {
296
+ c.name(m["ref"], "ref");
297
+ const status = c.integer(m["status"], "status");
298
+ if (status < 400 || status > 499) c.fail("status", "must be a 4xx status");
299
+ c.array(m["errors"], "errors").forEach((e, i) => c.apiError(e, join("errors", i)));
300
+ },
301
+ error(c, m) {
302
+ c.optionalName(m, "ref", "");
303
+ if (!ERROR_CODES.includes(m["code"]))
304
+ c.fail("code", "is not a known code");
305
+ c.string(m["message"], "message");
306
+ },
307
+ feed(c, m) {
308
+ c.name(m["room"], "room");
309
+ c.name(m["cursor"], "cursor");
310
+ const ops = c.array(m["ops"], "ops");
311
+ if (ops.length > c.limits.maxOps)
312
+ c.fail("ops", `has more than ${c.limits.maxOps} ops`, "too-large");
313
+ ops.forEach((op, i) => c.storeOp(op, join("ops", i)));
314
+ },
315
+ pong(c, m) {
316
+ c.name(m["ref"], "ref");
317
+ }
318
+ };
319
+ var encoder = new TextEncoder();
320
+ function parseMessage(input, options = {}) {
321
+ const checker = new Checker({ ...DEFAULT_LIMITS, ...options.limits });
322
+ try {
323
+ let value = input;
324
+ if (typeof input === "string") {
325
+ if (encoder.encode(input).length > checker.limits.maxMessageBytes) {
326
+ checker.fail("", `is larger than ${checker.limits.maxMessageBytes} bytes`, "too-large");
327
+ }
328
+ try {
329
+ value = JSON.parse(input);
330
+ } catch {
331
+ checker.fail("", "is not JSON");
332
+ }
333
+ }
334
+ const message = checker.object(value, "");
335
+ const type = message["type"];
336
+ const types = options.from === "client" ? CLIENT_TYPES : options.from === "server" ? SERVER_TYPES : Object.keys(BODIES);
337
+ const body = typeof type === "string" && types.includes(type) ? BODIES[type] : void 0;
338
+ if (body === void 0) checker.fail("type", `is not a ${options.from ?? "known"} message type`);
339
+ body(checker, message);
340
+ return { ok: true, message: value };
341
+ } catch (error) {
342
+ if (error instanceof Failure) {
343
+ const where = error.path === "" ? "the message" : error.path;
344
+ return {
345
+ ok: false,
346
+ error: { code: error.code, path: error.path, message: `${where} ${error.message}` }
347
+ };
348
+ }
349
+ throw error;
350
+ }
351
+ }
352
+
353
+ // src/version.ts
354
+ var PROTOCOL_VERSION = 1;
355
+ var SUPPORTED_VERSIONS = Object.freeze([1]);
356
+ function negotiateVersion(clientVersions, serverVersions) {
357
+ const common = clientVersions.filter((version) => serverVersions.includes(version));
358
+ return common.length === 0 ? null : Math.max(...common);
359
+ }
360
+
361
+ export { CLIENT_TYPES, DEFAULT_LIMITS, ERROR_CODES, NOTIFICATION_TYPE, PROTOCOL_VERSION, SERVER_TYPES, SUPPORTED_VERSIONS, encodeMessage, fromBase64, isUserRoom, negotiateVersion, parseMessage, toBase64, userRoom };
362
+ //# sourceMappingURL=index.js.map
363
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/base64.ts","../src/messages.ts","../src/notifications.ts","../src/parse.ts","../src/version.ts"],"names":[],"mappings":";AAGO,SAAS,SAAS,KAAA,EAA2B;AAClD,EAAA,IAAI,MAAA,GAAS,EAAA;AAEb,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,MAAA,EAAQ,KAAK,KAAA,EAAQ;AAC7C,IAAA,MAAA,IAAU,MAAA,CAAO,aAAa,GAAG,KAAA,CAAM,SAAS,CAAA,EAAG,CAAA,GAAI,KAAM,CAAC,CAAA;AAAA,EAChE;AACA,EAAA,OAAO,KAAK,MAAM,CAAA;AACpB;AAGO,SAAS,WAAW,IAAA,EAA0B;AACnD,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,M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CAAA,SAAA,EAAY,OAAA,CAAQ,IAAA,IAAQ,OAAO,CAAA,aAAA,CAAe,CAAA;AAC/F,IAAA,IAAA,CAAK,SAAS,OAAO,CAAA;AAErB,IAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,OAAA,EAAS,KAAA,EAAiB;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,iBAAiB,OAAA,EAAS;AAC5B,MAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,KAAS,EAAA,GAAK,gBAAgB,KAAA,CAAM,IAAA;AACxD,MAAA,OAAO;AAAA,QACL,EAAA,EAAI,KAAA;AAAA,QACJ,KAAA,EAAO,EAAE,IAAA,EAAM,KAAA,CAAM,MAAM,IAAA,EAAM,KAAA,CAAM,IAAA,EAAM,OAAA,EAAS,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,KAAA,CAAM,OAAO,CAAA,CAAA;AAAG,OACpF;AAAA,IACF;AACA,IAAA,MAAM,KAAA;AAAA,EACR;AACF;;;AC9UO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,kBAAA,GAAwC,MAAA,CAAO,MAAA,CAAO,CAAC,CAAC,CAAC;AAM/D,SAAS,gBAAA,CACd,gBACA,cAAA,EACe;AACf,EAAA,MAAM,SAAS,cAAA,CAAe,MAAA,CAAO,aAAW,cAAA,CAAe,QAAA,CAAS,OAAO,CAAC,CAAA;AAChF,EAAA,OAAO,OAAO,MAAA,KAAW,CAAA,GAAI,OAAO,IAAA,CAAK,GAAA,CAAI,GAAG,MAAM,CAAA;AACxD","file":"index.js","sourcesContent":["// CRDT updates and state vectors are bytes. The protocol carries them as standard base64 text.\n\n/** Encodes bytes as standard base64. */\nexport function toBase64(bytes: Uint8Array): string {\n let binary = ''\n // In chunks: `String.fromCharCode` takes each byte as an argument.\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000))\n }\n return btoa(binary)\n}\n\n/** Decodes standard base64. Throws on text that is not base64. */\nexport function fromBase64(text: string): Uint8Array {\n let binary: string\n try {\n binary = atob(text)\n } catch {\n throw new Error('fromBase64: the text is not base64')\n }\n return Uint8Array.from(binary, char => char.charCodeAt(0))\n}\n","// The messages of the Dovetail wire protocol, version 1. docs/protocol.md is the spec.\n\n/** A value that JSON can carry. */\nexport type JsonValue =\n string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }\n\n/** A JSON object. */\nexport type JsonObject = { [key: string]: JsonValue }\n\n/** The type and the id of one JSON:API resource. */\nexport interface ResourceIdentifier {\n type: string\n id: string\n}\n\n/** A JSON:API relationship. Dovetail reads only `data`. */\nexport interface Relationship {\n data: ResourceIdentifier | ResourceIdentifier[] | null\n links?: JsonObject\n meta?: JsonObject\n}\n\n/** A JSON:API resource object. */\nexport interface Resource {\n type: string\n id: string\n attributes?: JsonObject\n relationships?: { [name: string]: Relationship }\n links?: JsonObject\n meta?: JsonObject\n}\n\n/** A JSON:API document with primary data, as `store.push` takes it. */\nexport interface JsonApiDocument {\n data: Resource | Resource[] | null\n included?: Resource[]\n meta?: JsonObject\n}\n\n/** A JSON:API error object. */\nexport interface JsonApiError {\n id?: string\n status?: string\n code?: string\n title?: string\n detail?: string\n source?: { pointer?: string; parameter?: string; header?: string }\n meta?: JsonObject\n}\n\n/** One change to the store: put a document in it, or remove one record. */\nexport type StoreOp =\n { op: 'upsert'; document: JsonApiDocument } | { op: 'delete'; ref: ResourceIdentifier }\n\n/** The codes of an `error` message. A new code needs a new protocol version. */\nexport const ERROR_CODES = [\n 'invalid-message',\n 'too-large',\n 'unsupported-version',\n 'unauthorized',\n 'forbidden',\n 'not-joined',\n 'rate-limited',\n 'internal',\n] as const\n\nexport type ErrorCode = (typeof ERROR_CODES)[number]\n\n// Client to server.\n\n/** The first message of a connection. It names the protocol versions that the client knows. */\nexport interface HelloMessage {\n type: 'hello'\n versions: number[]\n /** The token from the host `getToken()` hook (ADR 0007). */\n token?: string\n client?: { name: string; version: string }\n}\n\n/** Joins a room. `since` is the last feed cursor that the client has, to get the changes after it. */\nexport interface JoinMessage {\n type: 'join'\n id: string\n room: string\n since?: string\n}\n\n/** Leaves a room. */\nexport interface LeaveMessage {\n type: 'leave'\n id: string\n room: string\n}\n\n/** A store write from the optimistic ledger. The server answers `ack` or `reject`. */\nexport interface WriteMessage {\n type: 'write'\n id: string\n room: string\n op: StoreOp\n}\n\n/** Asks the server for a `pong`. */\nexport interface PingMessage {\n type: 'ping'\n id: string\n}\n\n// Both directions. The server relays these to the other members of the room.\n\n/** A CRDT update of one document in a room, as base64. */\nexport interface DocUpdateMessage {\n type: 'doc-update'\n room: string\n doc: string\n update: string\n /** The session that made the update. The server sets it when it relays the update. */\n origin?: string\n}\n\n/**\n * The sync handshake of one document. Step 1 sends a state vector. Step 2 answers with the\n * update that the other side does not have.\n */\nexport type DocSyncMessage =\n | { type: 'doc-sync'; room: string; doc: string; step: 1; stateVector: string }\n | { type: 'doc-sync'; room: string; doc: string; step: 2; update: string }\n\n/** The awareness state of one client in a room: user, status, cursor, typing. Null removes it. */\nexport interface AwarenessMessage {\n type: 'awareness'\n room: string\n /** The session of the client. The server sets it when it relays the state. */\n clientId?: string\n state: JsonObject | null\n}\n\n// Server to client.\n\n/** The answer to `hello`: the version that both sides use, and the session id. */\nexport interface WelcomeMessage {\n type: 'welcome'\n version: number\n session: string\n user?: { id: string }\n}\n\n/** The request `ref` is done. A write ack can carry the server state of the record. */\nexport interface AckMessage {\n type: 'ack'\n ref: string\n cursor?: string\n /**\n * On the ack of a join with `since`: the server cannot send the changes after `since` (its\n * history is shorter, or it restarted). It sends no feed, and `cursor` is the current cursor.\n * The client must load the data of the room again. A client that does not know it ignores it.\n */\n reset?: boolean\n document?: JsonApiDocument\n}\n\n/** The server refused the write `ref`. The client rolls it back (ADR 0004). */\nexport interface RejectMessage {\n type: 'reject'\n ref: string\n /** An HTTP 4xx status. A 4xx write goes to the dead-letter list (ADR 0005). */\n status: number\n errors: JsonApiError[]\n}\n\n/** A protocol error. With `ref`, it is the answer to that request. */\nexport interface ErrorMessage {\n type: 'error'\n ref?: string\n code: ErrorCode\n message: string\n}\n\n/** Store changes for a room, in server order. `cursor` marks the position after them. */\nexport interface FeedMessage {\n type: 'feed'\n room: string\n cursor: string\n ops: StoreOp[]\n}\n\n/** The answer to `ping`. */\nexport interface PongMessage {\n type: 'pong'\n ref: string\n}\n\nexport type ClientMessage =\n | HelloMessage\n | JoinMessage\n | LeaveMessage\n | WriteMessage\n | PingMessage\n | DocUpdateMessage\n | DocSyncMessage\n | AwarenessMessage\n\nexport type ServerMessage =\n | WelcomeMessage\n | AckMessage\n | RejectMessage\n | ErrorMessage\n | FeedMessage\n | PongMessage\n | DocUpdateMessage\n | DocSyncMessage\n | AwarenessMessage\n\nexport type Message = ClientMessage | ServerMessage\n\n/** The types that a client sends. */\nexport const CLIENT_TYPES = [\n 'hello',\n 'join',\n 'leave',\n 'write',\n 'ping',\n 'doc-update',\n 'doc-sync',\n 'awareness',\n] as const\n\n/** The types that a server sends. */\nexport const SERVER_TYPES = [\n 'welcome',\n 'ack',\n 'reject',\n 'error',\n 'feed',\n 'pong',\n 'doc-update',\n 'doc-sync',\n 'awareness',\n] as const\n\n/** The text form of a message on the wire. */\nexport function encodeMessage(message: Message): string {\n return JSON.stringify(message)\n}\n","// Notifications (ADR 0009). A notification is a JSON:API resource of type `notification`. The\n// server sends it on the store feed of the per-user room, so it enters the store like any record.\nimport type { JsonObject, Resource, ResourceIdentifier } from './messages'\nimport type { Checker } from './parse'\n\nexport const NOTIFICATION_TYPE = 'notification'\n\nconst USER_ROOM_PREFIX = 'user:'\n\n/** The per-user room of `userId`. The server sends the notifications of the user to it. */\nexport function userRoom(userId: string): string {\n if (userId.length === 0) throw new Error('userRoom needs a user id')\n return `${USER_ROOM_PREFIX}${userId}`\n}\n\n/** True when `room` is a per-user room. */\nexport function isUserRoom(room: string): boolean {\n return room.startsWith(USER_ROOM_PREFIX) && room.length > USER_ROOM_PREFIX.length\n}\n\n/** The attributes of a notification. The times are ISO 8601 date-times. */\nexport interface NotificationAttributes extends JsonObject {\n verb: string\n createdAt: string\n readAt: string | null\n seenAt: string | null\n archivedAt: string | null\n}\n\n/** A notification: an actor, a verb, a target, a time, and the read and seen state. */\nexport interface NotificationResource extends Resource {\n type: typeof NOTIFICATION_TYPE\n attributes: NotificationAttributes\n relationships: {\n actor: { data: ResourceIdentifier }\n target: { data: ResourceIdentifier }\n }\n}\n\nconst DATE_TIME = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/\n\n/**\n * The notification checks of parseMessage, for a resource of type `notification`. A `partial`\n * resource (a client write to the per-user room) can leave out each field. It has only the times\n * that change, and the server takes only `readAt`, `seenAt` and `archivedAt` from it.\n */\nexport function checkNotification(\n c: Checker,\n resource: Record<string, unknown>,\n path: string,\n partial = false,\n): void {\n if (partial && resource['attributes'] === undefined) return\n const attributes = c.object(resource['attributes'], `${path}.attributes`)\n if (!partial || attributes['verb'] !== undefined)\n c.name(attributes['verb'], `${path}.attributes.verb`)\n const dateTime = (key: string, nullable: boolean) => {\n const value = attributes[key]\n if (partial && value === undefined) return\n if (nullable && (value === null || (key === 'archivedAt' && value === undefined))) return\n const text = c.string(value, `${path}.attributes.${key}`)\n if (!DATE_TIME.test(text) || Number.isNaN(Date.parse(text))) {\n c.fail(`${path}.attributes.${key}`, 'must be an ISO 8601 date-time')\n }\n }\n dateTime('createdAt', false)\n dateTime('readAt', true)\n dateTime('seenAt', true)\n dateTime('archivedAt', true)\n if (partial && resource['relationships'] === undefined) return\n const relationships = c.object(resource['relationships'], `${path}.relationships`)\n for (const name of ['actor', 'target']) {\n const relationship = c.object(relationships[name], `${path}.relationships.${name}`)\n c.identifier(relationship['data'], `${path}.relationships.${name}.data`)\n }\n}\n","// parseMessage: the trust boundary of the protocol. Each server and each transport calls it on\n// every message that arrives, before the message goes anywhere else.\nimport { CLIENT_TYPES, ERROR_CODES, SERVER_TYPES } from './messages'\nimport type { ClientMessage, Message, ServerMessage } from './messages'\nimport { checkNotification, isUserRoom, NOTIFICATION_TYPE } from './notifications'\n\n/** The limits that parseMessage applies. */\nexport interface Limits {\n /** The maximum size of a message as text, in UTF-8 bytes. */\n maxMessageBytes: number\n /** The maximum length of a name: a room, a request id, a document, a cursor, a type or an id. */\n maxNameLength: number\n /** The maximum number of ops in one feed message. */\n maxOps: number\n /** The maximum depth of nested JSON objects and arrays. */\n maxDepth: number\n}\n\nexport const DEFAULT_LIMITS: Limits = Object.freeze({\n maxMessageBytes: 1024 * 1024,\n maxNameLength: 256,\n maxOps: 1000,\n maxDepth: 32,\n})\n\nexport interface ParseOptions {\n /** The side that sent the message. A message type of the other side is invalid. */\n from?: 'client' | 'server'\n limits?: Partial<Limits>\n}\n\nexport interface ParseError {\n code: 'invalid-message' | 'too-large'\n /** The path of the wrong field, as `ops[0].document.data.type`. Empty for the message itself. */\n path: string\n message: string\n}\n\nexport type ParseResult<T> = { ok: true; message: T } | { ok: false; error: ParseError }\n\nclass Failure extends Error {\n constructor(\n readonly code: ParseError['code'],\n readonly path: string,\n message: string,\n ) {\n super(message)\n }\n}\n\nconst join = (path: string, key: string | number) =>\n typeof key === 'number' ? `${path}[${key}]` : path ? `${path}.${key}` : key\n\nconst BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const proto = Object.getPrototypeOf(value) as unknown\n return proto === Object.prototype || proto === null\n}\n\n/** The checks of one message, with the limits and the path of each field. */\nclass Checker {\n /** True in a client write to a per-user room: a notification can be partial there. */\n partialNotifications = false\n\n constructor(readonly limits: Limits) {}\n\n fail(path: string, message: string, code: ParseError['code'] = 'invalid-message'): never {\n throw new Failure(code, path, message)\n }\n\n object(value: unknown, path: string): Record<string, unknown> {\n if (!isRecord(value)) this.fail(path, 'must be an object')\n return value\n }\n\n string(value: unknown, path: string): string {\n if (typeof value !== 'string') this.fail(path, 'must be a string')\n return value\n }\n\n /** A name: a non-empty string within `maxNameLength`. */\n name(value: unknown, path: string): string {\n const text = this.string(value, path)\n if (text.length === 0) this.fail(path, 'must not be empty')\n if (text.length > this.limits.maxNameLength) {\n this.fail(path, `is longer than ${this.limits.maxNameLength}`, 'too-large')\n }\n return text\n }\n\n optionalName(record: Record<string, unknown>, key: string, path: string): void {\n if (record[key] !== undefined) this.name(record[key], join(path, key))\n }\n\n base64(value: unknown, path: string): void {\n if (!BASE64.test(this.string(value, path))) this.fail(path, 'must be base64')\n }\n\n integer(value: unknown, path: string): number {\n if (typeof value !== 'number' || !Number.isInteger(value)) this.fail(path, 'must be an integer')\n return value\n }\n\n array(value: unknown, path: string): unknown[] {\n if (!Array.isArray(value)) this.fail(path, 'must be an array')\n return value\n }\n\n /** Any JSON value, within `maxDepth`. A cycle is deeper than any limit. */\n json(value: unknown, path: string, depth = 0): void {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) this.fail(path, 'must be a finite number')\n return\n }\n if (depth >= this.limits.maxDepth) {\n this.fail(path, `is nested deeper than ${this.limits.maxDepth}`, 'too-large')\n }\n if (Array.isArray(value)) {\n value.forEach((item, index) => this.json(item, join(path, index), depth + 1))\n return\n }\n if (!isRecord(value)) this.fail(path, 'must be a JSON value')\n for (const [key, item] of Object.entries(value)) this.json(item, join(path, key), depth + 1)\n }\n\n jsonObject(value: unknown, path: string): void {\n this.object(value, path)\n this.json(value, path)\n }\n\n optionalJsonObject(record: Record<string, unknown>, key: string, path: string): void {\n if (record[key] !== undefined) this.jsonObject(record[key], join(path, key))\n }\n\n identifier(value: unknown, path: string): void {\n const ref = this.object(value, path)\n this.name(ref['type'], join(path, 'type'))\n this.name(ref['id'], join(path, 'id'))\n }\n\n resource(value: unknown, path: string): void {\n const resource = this.object(value, path)\n const type = this.name(resource['type'], join(path, 'type'))\n this.name(resource['id'], join(path, 'id'))\n this.optionalJsonObject(resource, 'attributes', path)\n if (resource['relationships'] !== undefined) {\n const relationships = this.object(resource['relationships'], join(path, 'relationships'))\n for (const [name, relationship] of Object.entries(relationships)) {\n const at = join(join(path, 'relationships'), name)\n const data = this.object(relationship, at)['data']\n if (Array.isArray(data))\n data.forEach((ref, i) => this.identifier(ref, join(join(at, 'data'), i)))\n else if (data !== null) this.identifier(data, join(at, 'data'))\n this.json(relationship, at)\n }\n }\n this.optionalJsonObject(resource, 'links', path)\n this.optionalJsonObject(resource, 'meta', path)\n if (type === NOTIFICATION_TYPE)\n checkNotification(this, resource, path, this.partialNotifications)\n }\n\n document(value: unknown, path: string): void {\n const document = this.object(value, path)\n if (!('data' in document)) this.fail(join(path, 'data'), 'is required')\n const data = document['data']\n if (Array.isArray(data))\n data.forEach((item, i) => this.resource(item, join(join(path, 'data'), i)))\n else if (data !== null) this.resource(data, join(path, 'data'))\n if (document['included'] !== undefined) {\n const included = this.array(document['included'], join(path, 'included'))\n included.forEach((item, i) => this.resource(item, join(join(path, 'included'), i)))\n }\n this.optionalJsonObject(document, 'meta', path)\n }\n\n storeOp(value: unknown, path: string): void {\n const op = this.object(value, path)\n if (op['op'] === 'upsert') this.document(op['document'], join(path, 'document'))\n else if (op['op'] === 'delete') this.identifier(op['ref'], join(path, 'ref'))\n else this.fail(join(path, 'op'), \"must be 'upsert' or 'delete'\")\n }\n\n apiError(value: unknown, path: string): void {\n const error = this.object(value, path)\n for (const key of ['id', 'status', 'code', 'title', 'detail']) {\n if (error[key] !== undefined) this.string(error[key], join(path, key))\n }\n if (error['source'] !== undefined) {\n const source = this.object(error['source'], join(path, 'source'))\n for (const [key, item] of Object.entries(source))\n this.string(item, join(join(path, 'source'), key))\n }\n this.optionalJsonObject(error, 'meta', path)\n }\n}\n\n/** The checks of each message type, after `type`. */\nconst BODIES: Record<string, (c: Checker, m: Record<string, unknown>) => void> = {\n hello(c, m) {\n c.array(m['versions'], 'versions').forEach((v, i) => c.integer(v, join('versions', i)))\n if (m['token'] !== undefined) c.string(m['token'], 'token')\n if (m['client'] !== undefined) {\n const client = c.object(m['client'], 'client')\n c.name(client['name'], 'client.name')\n c.name(client['version'], 'client.version')\n }\n },\n join(c, m) {\n c.name(m['id'], 'id')\n c.name(m['room'], 'room')\n c.optionalName(m, 'since', '')\n },\n leave(c, m) {\n c.name(m['id'], 'id')\n c.name(m['room'], 'room')\n },\n write(c, m) {\n c.name(m['id'], 'id')\n c.partialNotifications = isUserRoom(c.name(m['room'], 'room'))\n c.storeOp(m['op'], 'op')\n },\n ping(c, m) {\n c.name(m['id'], 'id')\n },\n 'doc-update'(c, m) {\n c.name(m['room'], 'room')\n c.name(m['doc'], 'doc')\n c.base64(m['update'], 'update')\n c.optionalName(m, 'origin', '')\n },\n 'doc-sync'(c, m) {\n c.name(m['room'], 'room')\n c.name(m['doc'], 'doc')\n if (m['step'] === 1) c.base64(m['stateVector'], 'stateVector')\n else if (m['step'] === 2) c.base64(m['update'], 'update')\n else c.fail('step', 'must be 1 or 2')\n },\n awareness(c, m) {\n c.name(m['room'], 'room')\n c.optionalName(m, 'clientId', '')\n if (m['state'] !== null) c.jsonObject(m['state'], 'state')\n },\n welcome(c, m) {\n c.integer(m['version'], 'version')\n c.name(m['session'], 'session')\n if (m['user'] !== undefined) c.name(c.object(m['user'], 'user')['id'], 'user.id')\n },\n ack(c, m) {\n c.name(m['ref'], 'ref')\n c.optionalName(m, 'cursor', '')\n if (m['reset'] !== undefined && typeof m['reset'] !== 'boolean')\n c.fail('reset', 'must be a boolean')\n if (m['document'] !== undefined) c.document(m['document'], 'document')\n },\n reject(c, m) {\n c.name(m['ref'], 'ref')\n const status = c.integer(m['status'], 'status')\n if (status < 400 || status > 499) c.fail('status', 'must be a 4xx status')\n c.array(m['errors'], 'errors').forEach((e, i) => c.apiError(e, join('errors', i)))\n },\n error(c, m) {\n c.optionalName(m, 'ref', '')\n if (!(ERROR_CODES as readonly unknown[]).includes(m['code']))\n c.fail('code', 'is not a known code')\n c.string(m['message'], 'message')\n },\n feed(c, m) {\n c.name(m['room'], 'room')\n c.name(m['cursor'], 'cursor')\n const ops = c.array(m['ops'], 'ops')\n if (ops.length > c.limits.maxOps)\n c.fail('ops', `has more than ${c.limits.maxOps} ops`, 'too-large')\n ops.forEach((op, i) => c.storeOp(op, join('ops', i)))\n },\n pong(c, m) {\n c.name(m['ref'], 'ref')\n },\n}\n\nconst encoder = new TextEncoder()\n\n/**\n * Checks that `input` is a valid protocol message, as text (a frame from the wire) or as a\n * value. It never throws. A server answers a failure with an `error` message of the same code.\n */\nexport function parseMessage(\n input: unknown,\n options: ParseOptions & { from: 'client' },\n): ParseResult<ClientMessage>\nexport function parseMessage(\n input: unknown,\n options: ParseOptions & { from: 'server' },\n): ParseResult<ServerMessage>\nexport function parseMessage(input: unknown, options?: ParseOptions): ParseResult<Message>\nexport function parseMessage(input: unknown, options: ParseOptions = {}): ParseResult<Message> {\n const checker: Checker = new Checker({ ...DEFAULT_LIMITS, ...options.limits })\n try {\n let value = input\n if (typeof input === 'string') {\n if (encoder.encode(input).length > checker.limits.maxMessageBytes) {\n checker.fail('', `is larger than ${checker.limits.maxMessageBytes} bytes`, 'too-large')\n }\n try {\n value = JSON.parse(input)\n } catch {\n checker.fail('', 'is not JSON')\n }\n }\n const message = checker.object(value, '')\n const type = message['type']\n const types: readonly unknown[] =\n options.from === 'client'\n ? CLIENT_TYPES\n : options.from === 'server'\n ? SERVER_TYPES\n : Object.keys(BODIES)\n const body = typeof type === 'string' && types.includes(type) ? BODIES[type] : undefined\n if (body === undefined) checker.fail('type', `is not a ${options.from ?? 'known'} message type`)\n body(checker, message)\n // Each field of the message passed its check above.\n return { ok: true, message: value as Message }\n } catch (error) {\n if (error instanceof Failure) {\n const where = error.path === '' ? 'the message' : error.path\n return {\n ok: false,\n error: { code: error.code, path: error.path, message: `${where} ${error.message}` },\n }\n }\n throw error\n }\n}\n\nexport type { Checker }\n","/** The newest protocol version. */\nexport const PROTOCOL_VERSION = 1\n\n/** The protocol versions that this package can speak, newest last. */\nexport const SUPPORTED_VERSIONS: readonly number[] = Object.freeze([1])\n\n/**\n * The version for a connection: the highest version in both lists, or null. The server sends\n * it in `welcome`. With null, the server sends an `unsupported-version` error and closes.\n */\nexport function negotiateVersion(\n clientVersions: readonly number[],\n serverVersions: readonly number[],\n): number | null {\n const common = clientVersions.filter(version => serverVersions.includes(version))\n return common.length === 0 ? null : Math.max(...common)\n}\n"]}
@@ -0,0 +1,189 @@
1
+ /** A value that JSON can carry. */
2
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ /** A JSON object. */
6
+ export type JsonObject = {
7
+ [key: string]: JsonValue;
8
+ };
9
+ /** The type and the id of one JSON:API resource. */
10
+ export interface ResourceIdentifier {
11
+ type: string;
12
+ id: string;
13
+ }
14
+ /** A JSON:API relationship. Dovetail reads only `data`. */
15
+ export interface Relationship {
16
+ data: ResourceIdentifier | ResourceIdentifier[] | null;
17
+ links?: JsonObject;
18
+ meta?: JsonObject;
19
+ }
20
+ /** A JSON:API resource object. */
21
+ export interface Resource {
22
+ type: string;
23
+ id: string;
24
+ attributes?: JsonObject;
25
+ relationships?: {
26
+ [name: string]: Relationship;
27
+ };
28
+ links?: JsonObject;
29
+ meta?: JsonObject;
30
+ }
31
+ /** A JSON:API document with primary data, as `store.push` takes it. */
32
+ export interface JsonApiDocument {
33
+ data: Resource | Resource[] | null;
34
+ included?: Resource[];
35
+ meta?: JsonObject;
36
+ }
37
+ /** A JSON:API error object. */
38
+ export interface JsonApiError {
39
+ id?: string;
40
+ status?: string;
41
+ code?: string;
42
+ title?: string;
43
+ detail?: string;
44
+ source?: {
45
+ pointer?: string;
46
+ parameter?: string;
47
+ header?: string;
48
+ };
49
+ meta?: JsonObject;
50
+ }
51
+ /** One change to the store: put a document in it, or remove one record. */
52
+ export type StoreOp = {
53
+ op: 'upsert';
54
+ document: JsonApiDocument;
55
+ } | {
56
+ op: 'delete';
57
+ ref: ResourceIdentifier;
58
+ };
59
+ /** The codes of an `error` message. A new code needs a new protocol version. */
60
+ export declare const ERROR_CODES: readonly ["invalid-message", "too-large", "unsupported-version", "unauthorized", "forbidden", "not-joined", "rate-limited", "internal"];
61
+ export type ErrorCode = (typeof ERROR_CODES)[number];
62
+ /** The first message of a connection. It names the protocol versions that the client knows. */
63
+ export interface HelloMessage {
64
+ type: 'hello';
65
+ versions: number[];
66
+ /** The token from the host `getToken()` hook (ADR 0007). */
67
+ token?: string;
68
+ client?: {
69
+ name: string;
70
+ version: string;
71
+ };
72
+ }
73
+ /** Joins a room. `since` is the last feed cursor that the client has, to get the changes after it. */
74
+ export interface JoinMessage {
75
+ type: 'join';
76
+ id: string;
77
+ room: string;
78
+ since?: string;
79
+ }
80
+ /** Leaves a room. */
81
+ export interface LeaveMessage {
82
+ type: 'leave';
83
+ id: string;
84
+ room: string;
85
+ }
86
+ /** A store write from the optimistic ledger. The server answers `ack` or `reject`. */
87
+ export interface WriteMessage {
88
+ type: 'write';
89
+ id: string;
90
+ room: string;
91
+ op: StoreOp;
92
+ }
93
+ /** Asks the server for a `pong`. */
94
+ export interface PingMessage {
95
+ type: 'ping';
96
+ id: string;
97
+ }
98
+ /** A CRDT update of one document in a room, as base64. */
99
+ export interface DocUpdateMessage {
100
+ type: 'doc-update';
101
+ room: string;
102
+ doc: string;
103
+ update: string;
104
+ /** The session that made the update. The server sets it when it relays the update. */
105
+ origin?: string;
106
+ }
107
+ /**
108
+ * The sync handshake of one document. Step 1 sends a state vector. Step 2 answers with the
109
+ * update that the other side does not have.
110
+ */
111
+ export type DocSyncMessage = {
112
+ type: 'doc-sync';
113
+ room: string;
114
+ doc: string;
115
+ step: 1;
116
+ stateVector: string;
117
+ } | {
118
+ type: 'doc-sync';
119
+ room: string;
120
+ doc: string;
121
+ step: 2;
122
+ update: string;
123
+ };
124
+ /** The awareness state of one client in a room: user, status, cursor, typing. Null removes it. */
125
+ export interface AwarenessMessage {
126
+ type: 'awareness';
127
+ room: string;
128
+ /** The session of the client. The server sets it when it relays the state. */
129
+ clientId?: string;
130
+ state: JsonObject | null;
131
+ }
132
+ /** The answer to `hello`: the version that both sides use, and the session id. */
133
+ export interface WelcomeMessage {
134
+ type: 'welcome';
135
+ version: number;
136
+ session: string;
137
+ user?: {
138
+ id: string;
139
+ };
140
+ }
141
+ /** The request `ref` is done. A write ack can carry the server state of the record. */
142
+ export interface AckMessage {
143
+ type: 'ack';
144
+ ref: string;
145
+ cursor?: string;
146
+ /**
147
+ * On the ack of a join with `since`: the server cannot send the changes after `since` (its
148
+ * history is shorter, or it restarted). It sends no feed, and `cursor` is the current cursor.
149
+ * The client must load the data of the room again. A client that does not know it ignores it.
150
+ */
151
+ reset?: boolean;
152
+ document?: JsonApiDocument;
153
+ }
154
+ /** The server refused the write `ref`. The client rolls it back (ADR 0004). */
155
+ export interface RejectMessage {
156
+ type: 'reject';
157
+ ref: string;
158
+ /** An HTTP 4xx status. A 4xx write goes to the dead-letter list (ADR 0005). */
159
+ status: number;
160
+ errors: JsonApiError[];
161
+ }
162
+ /** A protocol error. With `ref`, it is the answer to that request. */
163
+ export interface ErrorMessage {
164
+ type: 'error';
165
+ ref?: string;
166
+ code: ErrorCode;
167
+ message: string;
168
+ }
169
+ /** Store changes for a room, in server order. `cursor` marks the position after them. */
170
+ export interface FeedMessage {
171
+ type: 'feed';
172
+ room: string;
173
+ cursor: string;
174
+ ops: StoreOp[];
175
+ }
176
+ /** The answer to `ping`. */
177
+ export interface PongMessage {
178
+ type: 'pong';
179
+ ref: string;
180
+ }
181
+ export type ClientMessage = HelloMessage | JoinMessage | LeaveMessage | WriteMessage | PingMessage | DocUpdateMessage | DocSyncMessage | AwarenessMessage;
182
+ export type ServerMessage = WelcomeMessage | AckMessage | RejectMessage | ErrorMessage | FeedMessage | PongMessage | DocUpdateMessage | DocSyncMessage | AwarenessMessage;
183
+ export type Message = ClientMessage | ServerMessage;
184
+ /** The types that a client sends. */
185
+ export declare const CLIENT_TYPES: readonly ["hello", "join", "leave", "write", "ping", "doc-update", "doc-sync", "awareness"];
186
+ /** The types that a server sends. */
187
+ export declare const SERVER_TYPES: readonly ["welcome", "ack", "reject", "error", "feed", "pong", "doc-update", "doc-sync", "awareness"];
188
+ /** The text form of a message on the wire. */
189
+ export declare function encodeMessage(message: Message): string;
@@ -0,0 +1,34 @@
1
+ import type { JsonObject, Resource, ResourceIdentifier } from './messages';
2
+ import type { Checker } from './parse';
3
+ export declare const NOTIFICATION_TYPE = "notification";
4
+ /** The per-user room of `userId`. The server sends the notifications of the user to it. */
5
+ export declare function userRoom(userId: string): string;
6
+ /** True when `room` is a per-user room. */
7
+ export declare function isUserRoom(room: string): boolean;
8
+ /** The attributes of a notification. The times are ISO 8601 date-times. */
9
+ export interface NotificationAttributes extends JsonObject {
10
+ verb: string;
11
+ createdAt: string;
12
+ readAt: string | null;
13
+ seenAt: string | null;
14
+ archivedAt: string | null;
15
+ }
16
+ /** A notification: an actor, a verb, a target, a time, and the read and seen state. */
17
+ export interface NotificationResource extends Resource {
18
+ type: typeof NOTIFICATION_TYPE;
19
+ attributes: NotificationAttributes;
20
+ relationships: {
21
+ actor: {
22
+ data: ResourceIdentifier;
23
+ };
24
+ target: {
25
+ data: ResourceIdentifier;
26
+ };
27
+ };
28
+ }
29
+ /**
30
+ * The notification checks of parseMessage, for a resource of type `notification`. A `partial`
31
+ * resource (a client write to the per-user room) can leave out each field. It has only the times
32
+ * that change, and the server takes only `readAt`, `seenAt` and `archivedAt` from it.
33
+ */
34
+ export declare function checkNotification(c: Checker, resource: Record<string, unknown>, path: string, partial?: boolean): void;
@@ -0,0 +1,68 @@
1
+ import type { ClientMessage, Message, ServerMessage } from './messages';
2
+ /** The limits that parseMessage applies. */
3
+ export interface Limits {
4
+ /** The maximum size of a message as text, in UTF-8 bytes. */
5
+ maxMessageBytes: number;
6
+ /** The maximum length of a name: a room, a request id, a document, a cursor, a type or an id. */
7
+ maxNameLength: number;
8
+ /** The maximum number of ops in one feed message. */
9
+ maxOps: number;
10
+ /** The maximum depth of nested JSON objects and arrays. */
11
+ maxDepth: number;
12
+ }
13
+ export declare const DEFAULT_LIMITS: Limits;
14
+ export interface ParseOptions {
15
+ /** The side that sent the message. A message type of the other side is invalid. */
16
+ from?: 'client' | 'server';
17
+ limits?: Partial<Limits>;
18
+ }
19
+ export interface ParseError {
20
+ code: 'invalid-message' | 'too-large';
21
+ /** The path of the wrong field, as `ops[0].document.data.type`. Empty for the message itself. */
22
+ path: string;
23
+ message: string;
24
+ }
25
+ export type ParseResult<T> = {
26
+ ok: true;
27
+ message: T;
28
+ } | {
29
+ ok: false;
30
+ error: ParseError;
31
+ };
32
+ /** The checks of one message, with the limits and the path of each field. */
33
+ declare class Checker {
34
+ readonly limits: Limits;
35
+ /** True in a client write to a per-user room: a notification can be partial there. */
36
+ partialNotifications: boolean;
37
+ constructor(limits: Limits);
38
+ fail(path: string, message: string, code?: ParseError['code']): never;
39
+ object(value: unknown, path: string): Record<string, unknown>;
40
+ string(value: unknown, path: string): string;
41
+ /** A name: a non-empty string within `maxNameLength`. */
42
+ name(value: unknown, path: string): string;
43
+ optionalName(record: Record<string, unknown>, key: string, path: string): void;
44
+ base64(value: unknown, path: string): void;
45
+ integer(value: unknown, path: string): number;
46
+ array(value: unknown, path: string): unknown[];
47
+ /** Any JSON value, within `maxDepth`. A cycle is deeper than any limit. */
48
+ json(value: unknown, path: string, depth?: number): void;
49
+ jsonObject(value: unknown, path: string): void;
50
+ optionalJsonObject(record: Record<string, unknown>, key: string, path: string): void;
51
+ identifier(value: unknown, path: string): void;
52
+ resource(value: unknown, path: string): void;
53
+ document(value: unknown, path: string): void;
54
+ storeOp(value: unknown, path: string): void;
55
+ apiError(value: unknown, path: string): void;
56
+ }
57
+ /**
58
+ * Checks that `input` is a valid protocol message, as text (a frame from the wire) or as a
59
+ * value. It never throws. A server answers a failure with an `error` message of the same code.
60
+ */
61
+ export declare function parseMessage(input: unknown, options: ParseOptions & {
62
+ from: 'client';
63
+ }): ParseResult<ClientMessage>;
64
+ export declare function parseMessage(input: unknown, options: ParseOptions & {
65
+ from: 'server';
66
+ }): ParseResult<ServerMessage>;
67
+ export declare function parseMessage(input: unknown, options?: ParseOptions): ParseResult<Message>;
68
+ export type { Checker };
@@ -0,0 +1,27 @@
1
+ import type { ClientMessage, ServerMessage } from './messages';
2
+ /** Why a connection closed. The codes are the WebSocket close codes. */
3
+ export interface CloseInfo {
4
+ code: number;
5
+ reason: string;
6
+ /** False when the network or the server dropped the connection. */
7
+ wasClean: boolean;
8
+ }
9
+ /** A connection that sends messages of type `Out` and receives messages of type `In`. */
10
+ export interface Transport<Out = ClientMessage, In = ServerMessage> {
11
+ /** Opens the connection. Resolves when the transport can send. Rejects when it cannot open. */
12
+ open(): Promise<void>;
13
+ /** Sends one message. Throws when the transport is not open. */
14
+ send(message: Out): void;
15
+ /** Closes the connection. */
16
+ close(code?: number, reason?: string): void;
17
+ /** True from the end of `open()` to the close. */
18
+ readonly isOpen: boolean;
19
+ /** Calls `listener` for each valid message that arrives. Returns a function that stops it. */
20
+ onMessage(listener: (message: In) => void): () => void;
21
+ /** Calls `listener` when the connection closes. Returns a function that stops it. */
22
+ onClose(listener: (info: CloseInfo) => void): () => void;
23
+ }
24
+ /** The client end of a connection. */
25
+ export type ClientTransport = Transport<ClientMessage, ServerMessage>;
26
+ /** The server end of one client connection. */
27
+ export type ServerTransport = Transport<ServerMessage, ClientMessage>;
@@ -0,0 +1,9 @@
1
+ /** The newest protocol version. */
2
+ export declare const PROTOCOL_VERSION = 1;
3
+ /** The protocol versions that this package can speak, newest last. */
4
+ export declare const SUPPORTED_VERSIONS: readonly number[];
5
+ /**
6
+ * The version for a connection: the highest version in both lists, or null. The server sends
7
+ * it in `welcome`. With null, the server sends an `unsupported-version` error and closes.
8
+ */
9
+ export declare function negotiateVersion(clientVersions: readonly number[], serverVersions: readonly number[]): number | null;
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@dovetail-ts/protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Wire message types, version negotiation and the message validator. No runtime dependency.",
5
+ "license": "MIT",
6
+ "author": "Joe Gaudet <joe@joegaudet.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/joegaudet/dovetail.git",
10
+ "directory": "packages/protocol"
11
+ },
12
+ "homepage": "https://joegaudet.com/dovetail/",
13
+ "bugs": "https://github.com/joegaudet/dovetail/issues",
14
+ "keywords": [
15
+ "realtime",
16
+ "offline",
17
+ "sync",
18
+ "crdt"
19
+ ],
20
+ "type": "module",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "CHANGELOG.md",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "devDependencies": {
37
+ "tsup": "^8.5.1"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "engines": {
43
+ "node": ">=22.12.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc --build --force && tsup"
47
+ }
6
48
  }