@graview/ship 0.1.0 → 0.1.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.
Files changed (77) hide show
  1. package/README.md +165 -9
  2. package/dist/browser-adapter.d.ts +9 -9
  3. package/dist/browser-adapter.d.ts.map +1 -1
  4. package/dist/browser-adapter.js +6 -3
  5. package/dist/browser-adapter.js.map +1 -1
  6. package/dist/browser.d.ts +10 -6
  7. package/dist/browser.d.ts.map +1 -1
  8. package/dist/browser.js +4 -2
  9. package/dist/browser.js.map +1 -1
  10. package/dist/cli.d.ts +17 -7
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +41 -7
  13. package/dist/cli.js.map +1 -1
  14. package/dist/export.d.ts +27 -2
  15. package/dist/export.d.ts.map +1 -1
  16. package/dist/export.js +38 -5
  17. package/dist/export.js.map +1 -1
  18. package/dist/file-adapter.d.ts +8 -8
  19. package/dist/file-adapter.d.ts.map +1 -1
  20. package/dist/file-adapter.js +58 -8
  21. package/dist/file-adapter.js.map +1 -1
  22. package/dist/handler.d.ts +271 -0
  23. package/dist/handler.d.ts.map +1 -0
  24. package/dist/handler.js +581 -0
  25. package/dist/handler.js.map +1 -0
  26. package/dist/health.d.ts +9 -0
  27. package/dist/health.d.ts.map +1 -1
  28. package/dist/health.js +5 -1
  29. package/dist/health.js.map +1 -1
  30. package/dist/index.d.ts +14 -7
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +6 -3
  33. package/dist/index.js.map +1 -1
  34. package/dist/live-protocol.d.ts +208 -0
  35. package/dist/live-protocol.d.ts.map +1 -0
  36. package/dist/live-protocol.js +380 -0
  37. package/dist/live-protocol.js.map +1 -0
  38. package/dist/live.d.ts +266 -0
  39. package/dist/live.d.ts.map +1 -0
  40. package/dist/live.js +74 -0
  41. package/dist/live.js.map +1 -0
  42. package/dist/meta.d.ts +13 -0
  43. package/dist/meta.d.ts.map +1 -0
  44. package/dist/meta.js +2 -0
  45. package/dist/meta.js.map +1 -0
  46. package/dist/open-store.d.ts +56 -7
  47. package/dist/open-store.d.ts.map +1 -1
  48. package/dist/open-store.js +141 -12
  49. package/dist/open-store.js.map +1 -1
  50. package/dist/remote.d.ts +237 -13
  51. package/dist/remote.d.ts.map +1 -1
  52. package/dist/remote.js +1033 -88
  53. package/dist/remote.js.map +1 -1
  54. package/dist/runtime.d.ts +34 -0
  55. package/dist/runtime.d.ts.map +1 -0
  56. package/dist/runtime.js +22 -0
  57. package/dist/runtime.js.map +1 -0
  58. package/dist/seat-headers.d.ts +26 -0
  59. package/dist/seat-headers.d.ts.map +1 -0
  60. package/dist/seat-headers.js +26 -0
  61. package/dist/seat-headers.js.map +1 -0
  62. package/dist/serve.d.ts +16 -106
  63. package/dist/serve.d.ts.map +1 -1
  64. package/dist/serve.js +95 -217
  65. package/dist/serve.js.map +1 -1
  66. package/dist/source-edit.d.ts.map +1 -1
  67. package/dist/source-edit.js +6 -1
  68. package/dist/source-edit.js.map +1 -1
  69. package/dist/steps.d.ts +43 -0
  70. package/dist/steps.d.ts.map +1 -1
  71. package/dist/steps.js +69 -0
  72. package/dist/steps.js.map +1 -1
  73. package/dist/websocket.d.ts +14 -0
  74. package/dist/websocket.d.ts.map +1 -0
  75. package/dist/websocket.js +163 -0
  76. package/dist/websocket.js.map +1 -0
  77. package/package.json +6 -2
@@ -0,0 +1,581 @@
1
+ import { foldPresence, PRESENCE_TTL_MS, refusalOf, VISITOR_PRESENCE_TTL_MS, } from "@graview/core";
2
+ import { exportBundle } from "./export.js";
3
+ import { health } from "./health.js";
4
+ import { bytesOf, conflictSentence, LIVE_PATH } from "./live.js";
5
+ import { announcePresence, liveProtocol, presenceFrom, presenceSeenBy, visitorPresence, wireOf, } from "./live-protocol.js";
6
+ import { openStore } from "./open-store.js";
7
+ import { SEAT_HEADERS } from "./seat-headers.js";
8
+ /**
9
+ * THE STORE, BEHIND ANY RUNTIME'S FETCH — and the op log is the wire (FR-09).
10
+ *
11
+ * Every route is one function from a `Request` to a `Response`, which is
12
+ * what a Cloudflare Worker, a Durable Object, Deno, Bun and a service worker
13
+ * all call a handler. `serveStore` is a thin `node:http` wrapper around it;
14
+ * nothing in this module reaches a `node:` builtin, so a host that runs
15
+ * somewhere other than Node serves the same wire without a fork.
16
+ *
17
+ * What is deliberately NOT here: a second way to change the graph. A client
18
+ * sends CALLS, not primitives; the handler applies them through an ordinary
19
+ * `Store` under the principal the request carries, so the policy judges
20
+ * them exactly as it judges them in a browser, the invariants run, and the
21
+ * op that comes back is the same shape the browser would have made. A
22
+ * client that could post primitives would be a client that could write past
23
+ * every rule the app declares.
24
+ *
25
+ * The protocol is four routes:
26
+ *
27
+ * GET /graview/state the graph, the log, the stored version and the modules on
28
+ * POST /graview/ops calls in, the ops they produced out — or `undo`, batches to take back
29
+ * GET /graview/since?seq=N the ops appended after N — everyone else's
30
+ * GET /graview/health ship's own report, plus where the data is
31
+ *
32
+ * And three for WHO IS HERE, which is not the op log and never touches it:
33
+ *
34
+ * POST /graview/here say where you are; answers with who else is, and the ops since `seq`
35
+ * GET /graview/who who is here right now
36
+ * POST /graview/leave say you have gone
37
+ *
38
+ * Presence lives in a map inside this closure with a time to live — not in
39
+ * the store, not in the adapter, not in the log. A tab that dies without a
40
+ * word is gone after three missed heartbeats.
41
+ *
42
+ * Polling is the floor, on purpose: a poll is a thing a person can
43
+ * reproduce with `curl`, and a thing every runtime can answer. Beside it,
44
+ * `connect` serves the live wire (FR-05, `./live.ts`) to whatever socket a
45
+ * host hands it, and `GET /graview/live` names it on the wire. The live
46
+ * protocol itself is `liveProtocol` (`./live-protocol.ts`), over state a
47
+ * host may hold instead of this closure (FR-41).
48
+ */
49
+ /**
50
+ * THE WIRE, AS A CONTRACT. Every route the handler answers, in one place a
51
+ * test pins and a README repeats: what a host in front of this — Graview
52
+ * Cloud, or anybody's — must keep answering for `openRemote`, `graview mcp
53
+ * --remote-url` and `graview apply --remote-url` to work unchanged. What a
54
+ * host adds (who a bearer token is, which tenant, how much) goes in
55
+ * `seatOf` and around these routes, never inside them.
56
+ */
57
+ export const WIRE = [
58
+ { method: "GET", path: "/graview/state", says: "the graph, the log, the stored version and the modules on" },
59
+ { method: "POST", path: "/graview/ops", says: "calls in, the ops they produced out — or `undo`, batches to take back; a `batch` already in the log is answered with the ops it made; 409 with the policy's sentence and a `reason` when refused, 429 with `Retry-After` when the host is busy" },
60
+ { method: "GET", path: "/graview/since", says: "the ops appended after ?seq=N — everyone else's" },
61
+ { method: "GET", path: "/graview/health", says: "ship's own report, plus where the data is" },
62
+ { method: "GET", path: "/graview/export", says: "the whole store as one bundle, the way out" },
63
+ { method: "POST", path: "/graview/here", says: "say where you are; answers with who else is, the ops since `seq`, and the `participant` key you are held under" },
64
+ { method: "GET", path: "/graview/who", says: "who is here right now" },
65
+ { method: "POST", path: "/graview/leave", says: "say you have gone — only ever yourself" },
66
+ { method: "GET", path: LIVE_PATH, says: "the live wire: a WebSocket of hello/welcome, call/undo/ack/refused/conflict/busy, ops and presence, declaration and reload; 426 to a plain request" },
67
+ ];
68
+ export { presenceSeenBy, SEAT_HEADERS };
69
+ const KINDS = new Set(["human", "agent", "rule", "system"]);
70
+ const list = (value) => (value ? value.split(",").filter(Boolean) : undefined);
71
+ const decoded = (value) => (value ? decodeURIComponent(value) : undefined);
72
+ /** A seat read from a request's headers — only ever when the host trusts them. */
73
+ export function seatFromHeaders(request) {
74
+ const header = (name) => request.headers.get(name);
75
+ const id = header(SEAT_HEADERS.seat);
76
+ const roles = list(header(SEAT_HEADERS.roles));
77
+ const kind = header(SEAT_HEADERS.kind);
78
+ const name = decoded(header(SEAT_HEADERS.name));
79
+ const forId = header(SEAT_HEADERS.for);
80
+ const forRoles = list(header(SEAT_HEADERS.forRoles));
81
+ const forName = decoded(header(SEAT_HEADERS.forName));
82
+ return {
83
+ kind: (kind && KINDS.has(kind) ? kind : "human"),
84
+ ...(id ? { id } : {}),
85
+ ...(roles ? { roles } : {}),
86
+ ...(name ? { name } : {}),
87
+ ...(forId ? { onBehalfOf: { kind: "human", id: forId, ...(forRoles ? { roles: forRoles } : {}), ...(forName ? { name: forName } : {}) } } : {}),
88
+ };
89
+ }
90
+ /** A browser on another origin is the ordinary case for an embed. */
91
+ const CORS = {
92
+ "access-control-allow-origin": "*",
93
+ "access-control-allow-headers": ["content-type", "authorization", ...Object.values(SEAT_HEADERS)].join(", "),
94
+ "access-control-allow-methods": "GET, POST, OPTIONS",
95
+ };
96
+ function send(status, body, headers = {}) {
97
+ return new Response(JSON.stringify(body), { status, headers: { ...CORS, "content-type": "application/json", ...headers } });
98
+ }
99
+ async function read(request) {
100
+ const text = await request.text();
101
+ return text.length === 0 ? {} : JSON.parse(text);
102
+ }
103
+ /** "Who is asking" refused: the reason a program reads beside the sentence (FR-46). */
104
+ const unknownSeat = (error) => send(401, { error, reason: "forbidden" });
105
+ const CANNOT_TELL = "This store cannot tell who is asking: the host gives serveStore a seatOf, or trusts the seat headers (trustSeatHeaders) on a server only it can reach.";
106
+ export async function createStoreHandler(options) {
107
+ if (options.store) {
108
+ const { handler, swap } = storeHandler(options);
109
+ return {
110
+ ...handler,
111
+ get store() {
112
+ return handler.store;
113
+ },
114
+ get protocol() {
115
+ return handler.protocol;
116
+ },
117
+ async declarationChanged(change) {
118
+ const { store } = change;
119
+ if (!store)
120
+ throw new Error("A handler over a store the host holds is handed the store migrated to the new declaration: declarationChanged({ app, store }).");
121
+ await swap(change.app, async () => ({ store, ...(change.flush ? { flush: change.flush } : {}), migrated: change.migrated ?? [] }));
122
+ },
123
+ };
124
+ }
125
+ const scope = options.scope ?? options.app.name;
126
+ const opening = (app) => openStore({
127
+ app,
128
+ adapter: options.adapter,
129
+ scope,
130
+ ...(options.seed ? { seed: options.seed } : {}),
131
+ ...(options.enabledModules ? { enabledModules: options.enabledModules } : {}),
132
+ });
133
+ let opened = (await opening(options.app));
134
+ const { adapter, seed: _seed, scope: _scope, enabledModules: _modules, ...rest } = options;
135
+ const { handler, swap } = storeHandler({
136
+ ...rest,
137
+ store: opened.store,
138
+ flush: () => opened.flush(),
139
+ migrated: opened.migrated.map((op) => op.intent),
140
+ // Said by the adapter where it knows, because it is the only thing
141
+ // that does; `where` is for a caller with a better name for it.
142
+ where: options.where ?? adapter.root ?? scope,
143
+ }, adapter.name);
144
+ return {
145
+ ...handler,
146
+ get store() {
147
+ return handler.store;
148
+ },
149
+ get protocol() {
150
+ return handler.protocol;
151
+ },
152
+ get opened() {
153
+ return opened;
154
+ },
155
+ /*
156
+ * OPENED AGAIN, ON THE NEW DECLARATION. What is pending is written
157
+ * first, then the adapter is read again by `openStore`, which runs the
158
+ * migrations between the stored version and the new one — here, once,
159
+ * as it did at the start — while every request and message waits.
160
+ */
161
+ async declarationChanged(change) {
162
+ await swap(change.app, async () => {
163
+ if (change.store)
164
+ return { store: change.store, ...(change.flush ? { flush: change.flush } : {}), migrated: change.migrated ?? [] };
165
+ await opened.flush();
166
+ opened.close();
167
+ opened = await opening(change.app);
168
+ return { store: opened.store, flush: () => opened.flush(), migrated: opened.migrated.map((op) => op.intent) };
169
+ });
170
+ },
171
+ async close() {
172
+ await handler.close();
173
+ opened.close();
174
+ },
175
+ };
176
+ }
177
+ function storeHandler(options, adapterName = "held by the host") {
178
+ const seatOf = options.seatOf ?? (options.trustSeatHeaders ? seatFromHeaders : undefined);
179
+ const flush = async () => {
180
+ await serving.flush?.();
181
+ };
182
+ const serve = (app, store, flushing, migrated) => ({
183
+ app,
184
+ store,
185
+ flush: flushing,
186
+ migrated: [...migrated],
187
+ wire: wireOf(store),
188
+ protocol: liveProtocol({
189
+ store,
190
+ version: app.version ?? 1,
191
+ migrated,
192
+ flush,
193
+ ...(options.build ? { build: options.build } : {}),
194
+ ...(options.minProtocol !== undefined ? { minProtocol: options.minProtocol } : {}),
195
+ ...(options.limit ? { limit: options.limit } : {}),
196
+ }),
197
+ });
198
+ let serving = serve(options.app, options.store, options.flush, options.migrated ?? []);
199
+ /** Set while the declaration is being changed: every request and message waits for it. */
200
+ let changing;
201
+ /*
202
+ * THE CHANNEL IS THE HOST'S WORD (FR-52). `viaOf` when the host gave
203
+ * one; the via header when it trusts the seat headers; else what the
204
+ * route is. Never the client's body or message.
205
+ */
206
+ const viaFor = async (request, seat, otherwise) => {
207
+ const said = options.viaOf ? await options.viaOf(request, seat) : undefined;
208
+ if (typeof said === "string" && said.length > 0)
209
+ return said;
210
+ const header = options.trustSeatHeaders ? request.headers.get(SEAT_HEADERS.via) : null;
211
+ return header && header.length > 0 ? header : otherwise;
212
+ };
213
+ /*
214
+ * WHO IS HERE. Keyed by participant, named by the seat the request
215
+ * carries — a poster cannot claim to be somebody else's seat — and
216
+ * stamped with the handler's clock, so expiry does not depend on two
217
+ * browsers agreeing what time it is.
218
+ */
219
+ const ttl = options.presenceTtlMs ?? PRESENCE_TTL_MS;
220
+ let here = new Map();
221
+ const alive = () => {
222
+ here = foldPresence(here, [], Date.now(), ttl);
223
+ return [...here.values()];
224
+ };
225
+ const arrive = (presence) => {
226
+ here = foldPresence(here, [presence], Date.now(), ttl);
227
+ };
228
+ const forget = (participant) => {
229
+ here = new Map(here);
230
+ here.delete(participant);
231
+ };
232
+ const announce = (presence, ttlMs = VISITOR_PRESENCE_TTL_MS) => {
233
+ const now = Date.now();
234
+ here = foldPresence(here, announcePresence([], presence, ttlMs, now), now, ttl);
235
+ tellWhoIsHere();
236
+ };
237
+ async function route(request) {
238
+ if (request.method === "OPTIONS")
239
+ return new Response(null, { status: 204, headers: CORS });
240
+ const url = new URL(request.url, "http://localhost");
241
+ // Answered from the declaration served once any change under way is made (FR-43).
242
+ while (changing)
243
+ await changing;
244
+ const { store, wire, app, migrated } = serving;
245
+ /*
246
+ * WHICH DECLARATION, AND WHICH BUILD, ANSWERED (FR-43, FR-44): on every
247
+ * answer a poll reads, so a client without a socket learns the
248
+ * declaration changed — or that it runs another build — on its next one.
249
+ */
250
+ const answering = { version: app.version ?? 1, ...(options.build ? { build: options.build } : {}) };
251
+ /*
252
+ * WHO IS ASKING, OR NOTHING. Health is the only route a stranger gets:
253
+ * it says whether the store is well, not what is in it.
254
+ */
255
+ if (!seatOf && url.pathname !== "/graview/health")
256
+ return unknownSeat(CANNOT_TELL);
257
+ const seat = async () => seatOf(request);
258
+ if (url.pathname === LIVE_PATH) {
259
+ return send(426, { error: `${LIVE_PATH} is a WebSocket: open one, say hello, and the store's ops come to you. A plain request polls /graview/since instead.` });
260
+ }
261
+ /*
262
+ * WHAT A SEAT MAY SEE NEVER LEAVES THE STORE (FR-02). Every read below is
263
+ * of the store as the asking seat sees it: its graph without what the
264
+ * policy keeps from it, and its log with every op in its place and the
265
+ * ones that touched what it may not see withheld (FR-16).
266
+ */
267
+ if (url.pathname === "/graview/state") {
268
+ const seen = wire.seenFor(await seat());
269
+ return send(200, {
270
+ ...answering,
271
+ snapshot: seen.snapshot(),
272
+ log: seen.log.all(),
273
+ migrated,
274
+ enabledModules: wire.enabledModules(),
275
+ ...wire.horizonOf(),
276
+ });
277
+ }
278
+ if (url.pathname === "/graview/since") {
279
+ const seq = Number(url.searchParams.get("seq") ?? "-1");
280
+ return send(200, { ops: wire.since(await seat(), seq), ...answering });
281
+ }
282
+ if (url.pathname === "/graview/who")
283
+ return send(200, { who: wire.whoFor(await seat(), alive()) });
284
+ if (url.pathname === "/graview/here" && request.method === "POST") {
285
+ const body = (await read(request));
286
+ if (!body.presence || typeof body.presence.participant !== "string" || typeof body.presence.stop !== "string") {
287
+ return send(400, { error: "A presence is a participant and a stop.", reason: "invalid" });
288
+ }
289
+ const asking = await seat();
290
+ const mine = presenceFrom(body.presence, asking);
291
+ arrive(mine);
292
+ tellWhoIsHere();
293
+ // Folded into the poll: the heartbeat carries back everybody else AND
294
+ // the ops since, so being here costs no round trip of its own.
295
+ // `participant` is the key the server holds this poller under, so it can leave itself out (FR-47).
296
+ return send(200, {
297
+ participant: mine.participant,
298
+ who: wire.whoFor(asking, alive().filter((presence) => presence.participant !== mine.participant)),
299
+ ...(typeof body.seq === "number" ? { ops: wire.since(asking, body.seq) } : {}),
300
+ ...answering,
301
+ });
302
+ }
303
+ if (url.pathname === "/graview/leave" && request.method === "POST") {
304
+ const body = (await read(request));
305
+ const asking = await seat();
306
+ // Only your own: a seat says it has gone, never that somebody else has.
307
+ const own = asking.id ? `${asking.kind}:${asking.id}:` : "";
308
+ if (typeof body.participant === "string" && body.participant.startsWith(own)) {
309
+ forget(body.participant);
310
+ tellWhoIsHere();
311
+ }
312
+ return send(200, { who: wire.whoFor(asking, alive()) });
313
+ }
314
+ if (url.pathname === "/graview/health") {
315
+ return send(200, {
316
+ ...health(store, app),
317
+ where: options.where ?? app.name,
318
+ adapter: adapterName,
319
+ });
320
+ }
321
+ if (url.pathname === "/graview/export")
322
+ return send(200, exportBundle(app, wire.seenFor(await seat())));
323
+ if (url.pathname === "/graview/ops" && request.method === "POST") {
324
+ const text = await request.text();
325
+ const body = (text.length === 0 ? {} : JSON.parse(text));
326
+ const calls = body.calls ?? [];
327
+ const author = await seat();
328
+ // What the calls came through is the host's to say, never the body's (FR-52).
329
+ const via = await viaFor(request, author, "api");
330
+ // A batch already in the log is a call sent again after its answer was lost — or offered again on a new declaration, or after a reload (FR-43, FR-44): answered with what it made, as on the socket (FR-49).
331
+ const already = wire.answered(body.batch);
332
+ if (already.length > 0)
333
+ return send(200, { ops: wire.shown(author, already), batch: body.batch, ...answering });
334
+ /*
335
+ * THE HOST'S LIMITS, BEFORE ANYTHING IS JUDGED. Busy is 429 and the
336
+ * change is kept to send again (FR-45); a hard cap is refused, `limit`,
337
+ * and the change is taken back (FR-46).
338
+ */
339
+ const limited = options.limit
340
+ ? await options.limit({ seat: author, via, t: body.undo ? "undo" : "call", bytes: bytesOf(text), calls: body.undo ? [] : calls })
341
+ : undefined;
342
+ if (limited && "refuse" in limited)
343
+ return send(413, { error: limited.refuse, refused: true, reason: "limit", ...answering });
344
+ if (limited) {
345
+ const retryAfter = Math.max(0, Math.ceil(limited.retryAfter));
346
+ return send(429, { error: limited.sentence ?? `The store is busy: send it again in ${retryAfter} ms.`, busy: true, retryAfter }, { "retry-after": String(Math.ceil(retryAfter / 1000)) });
347
+ }
348
+ /*
349
+ * A STALE WRITE IS A CONFLICT, NOT A LOSS (FR-05). A field that moved
350
+ * since the caller read it is refused by name — theirs and yours —
351
+ * and nothing is written: what to do about it is the person's call.
352
+ */
353
+ const conflicts = body.undo ? [] : wire.conflictsOf(author, calls, body.base);
354
+ if (conflicts.length > 0)
355
+ return send(409, { error: conflictSentence(conflicts), refused: true, conflict: true, conflicts, ...answering });
356
+ try {
357
+ /*
358
+ * Through the STORE, under the requester's own seat. The policy
359
+ * refuses here exactly what it refuses in the browser — and the
360
+ * refusal comes back with the policy's own sentence rather than a
361
+ * bare 403, because that sentence is the product.
362
+ */
363
+ const applying = { author, via, ...(body.intent ? { intent: body.intent } : {}), ...(body.batch ? { batch: body.batch } : {}) };
364
+ const result = body.undo ? store.undo(body.undo, applying) : store.applyAll(calls, applying);
365
+ await flush();
366
+ // An act may make what its own seat may not see: that op goes back withheld, as it would on a poll.
367
+ return send(200, { ops: wire.shown(author, result.ops), batch: result.batch, ...answering });
368
+ }
369
+ catch (error) {
370
+ const { sentence, ...why } = refusalOf(error);
371
+ return send(409, { error: sentence, refused: true, ...why, ...answering });
372
+ }
373
+ }
374
+ return send(404, { error: `Nothing at ${url.pathname}`, reason: "missing" });
375
+ }
376
+ const sockets = new Set();
377
+ const agentsFor = options.announceAgents === false ? 0 : typeof options.announceAgents === "number" ? options.announceAgents : VISITOR_PRESENCE_TTL_MS;
378
+ const watch = (store) => store.subscribe((_diff, ops) => {
379
+ serving.protocol.publish(ops, [...sockets].filter((live) => !live.answering));
380
+ if (agentsFor > 0)
381
+ agentsWereHere(ops);
382
+ });
383
+ let unsubscribe = watch(serving.store);
384
+ /*
385
+ * AN AGENT THAT ACTED IS IN THE ROOM (FR-47), standing over the last
386
+ * thing it wrote: once per agent per change, and not at all for one that
387
+ * holds a socket here, which is in the room as itself already.
388
+ */
389
+ function agentsWereHere(ops) {
390
+ const last = new Map();
391
+ for (const op of ops)
392
+ if (op.author.kind === "agent")
393
+ last.set(`${op.author.id ?? ""}`, op);
394
+ let told = false;
395
+ for (const op of last.values()) {
396
+ const author = op.author;
397
+ if ([...sockets].some((live) => live.seat.kind === "agent" && live.seat.id === author.id))
398
+ continue;
399
+ const now = Date.now();
400
+ here = foldPresence(here, announcePresence([], visitorPresence(author, { over: op.writes[0] ?? null, now: new Date(now) }), agentsFor, now), now, ttl);
401
+ told = true;
402
+ }
403
+ if (told)
404
+ tellWhoIsHere();
405
+ }
406
+ /*
407
+ * A socket's presence stands while the socket does; the TTL is for a
408
+ * poller that went quiet, and a socket that went quiet is closed.
409
+ */
410
+ const standing = () => {
411
+ const now = new Date().toISOString();
412
+ const held = [];
413
+ for (const live of sockets) {
414
+ const presence = live.participant ? here.get(live.participant) : undefined;
415
+ if (presence)
416
+ held.push({ ...presence, at: now });
417
+ }
418
+ if (held.length > 0)
419
+ here = foldPresence(here, held, Date.now(), ttl);
420
+ return alive();
421
+ };
422
+ function tellWhoIsHere() {
423
+ if (sockets.size === 0)
424
+ return;
425
+ serving.protocol.tell(standing(), sockets);
426
+ }
427
+ /*
428
+ * A page cannot set headers on a WebSocket. A store that trusts the seat
429
+ * headers — loopback only — reads them from the upgrade's query instead,
430
+ * under the same names; one that asks its own `seatOf` is handed the
431
+ * request as it came.
432
+ */
433
+ const seatRequest = (request) => {
434
+ if (options.seatOf || !options.trustSeatHeaders || request.headers.has(SEAT_HEADERS.seat))
435
+ return request;
436
+ const query = new URL(request.url, "http://localhost").searchParams;
437
+ const headers = new Headers(request.headers);
438
+ let found = false;
439
+ for (const name of Object.values(SEAT_HEADERS)) {
440
+ const value = query.get(name);
441
+ if (value !== null) {
442
+ headers.set(name, value);
443
+ found = true;
444
+ }
445
+ }
446
+ return found ? new Request(request.url, { headers }) : request;
447
+ };
448
+ async function seatFor(request) {
449
+ if (!seatOf)
450
+ return unknownSeat(CANNOT_TELL);
451
+ const asked = seatRequest(request);
452
+ try {
453
+ const seat = await seatOf(asked);
454
+ return serving.protocol.open(seat, await viaFor(asked, seat, "web"));
455
+ }
456
+ catch (error) {
457
+ return unknownSeat(error instanceof Error ? error.message : String(error));
458
+ }
459
+ }
460
+ async function connect(request, socket) {
461
+ const state = await seatFor(request);
462
+ if (state instanceof Response)
463
+ return state;
464
+ const live = {
465
+ ...state,
466
+ socket,
467
+ answering: false,
468
+ open: true,
469
+ send: (text) => {
470
+ if (live.open)
471
+ socket.send(text);
472
+ },
473
+ };
474
+ const hear = async (text) => {
475
+ const was = live.participant;
476
+ live.answering = true;
477
+ let received;
478
+ try {
479
+ // A message that came while the declaration was changing is answered under the new one (FR-43).
480
+ while (changing)
481
+ await changing;
482
+ received = await serving.protocol.receive(live, text, standing());
483
+ }
484
+ finally {
485
+ live.answering = false;
486
+ }
487
+ if (live.cursor !== undefined) {
488
+ sockets.add(live);
489
+ // What landed while this socket's own answer waited for its flush, after its ack.
490
+ serving.protocol.publish([], [live]);
491
+ }
492
+ if (received.presence) {
493
+ arrive(received.presence);
494
+ tellWhoIsHere();
495
+ }
496
+ else if (received.presence === null && was) {
497
+ forget(was);
498
+ tellWhoIsHere();
499
+ }
500
+ };
501
+ /*
502
+ * One message at a time, in the order they came: a call waits for the
503
+ * one before it, so an ack never overtakes the push or ack before it.
504
+ */
505
+ let queue = Promise.resolve();
506
+ return {
507
+ receive(text) {
508
+ queue = queue.then(() => hear(text)).catch(() => { });
509
+ },
510
+ close() {
511
+ live.open = false;
512
+ sockets.delete(live);
513
+ if (live.participant) {
514
+ forget(live.participant);
515
+ delete live.participant;
516
+ tellWhoIsHere();
517
+ }
518
+ },
519
+ };
520
+ }
521
+ /*
522
+ * THE DECLARATION CHANGED (FR-43). What is pending on the old store is
523
+ * written, the new store is opened (or handed over), and every socket is
524
+ * told by the protocol over the new one, which forgets their cursors: a
525
+ * seq of the old store means nothing on the new one. Meanwhile every
526
+ * request and message waits, so nothing lands on the store let go.
527
+ */
528
+ const swap = async (app, open) => {
529
+ while (changing)
530
+ await changing;
531
+ let done = () => { };
532
+ changing = new Promise((resolve) => (done = resolve));
533
+ try {
534
+ await flush();
535
+ const next = await open();
536
+ unsubscribe();
537
+ serving = serve(app, next.store, next.flush ?? serving.flush, next.migrated);
538
+ unsubscribe = watch(serving.store);
539
+ serving.protocol.declared(sockets);
540
+ }
541
+ finally {
542
+ changing = undefined;
543
+ done();
544
+ }
545
+ };
546
+ const handler = {
547
+ get store() {
548
+ return serving.store;
549
+ },
550
+ get protocol() {
551
+ return serving.protocol;
552
+ },
553
+ connect,
554
+ seatFor,
555
+ announce,
556
+ handle: async (request) => {
557
+ try {
558
+ return await route(request);
559
+ }
560
+ catch (error) {
561
+ return send(500, { error: error instanceof Error ? error.message : String(error) });
562
+ }
563
+ },
564
+ async close() {
565
+ for (const live of sockets) {
566
+ live.open = false;
567
+ try {
568
+ live.socket.close?.(1001, "The store is closing.");
569
+ }
570
+ catch {
571
+ // Already gone.
572
+ }
573
+ }
574
+ sockets.clear();
575
+ unsubscribe();
576
+ await flush();
577
+ },
578
+ };
579
+ return { handler, swap };
580
+ }
581
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,eAAe,EACf,SAAS,EACT,uBAAuB,GAUxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAoD,MAAM,WAAW,CAAC;AACnH,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,eAAe,EACf,MAAM,GAKP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,E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M,KAAK,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtF,CAAC;QACH,CAAC;QACD,KAAK,CAAC,KAAK;YACT,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;gBAClB,IAAI,CAAC;oBACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;gBACrD,CAAC;gBAAC,MAAM,CAAC;oBACP,gBAAgB;gBAClB,CAAC;YACH,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,WAAW,EAAE,CAAC;YACd,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
package/dist/health.d.ts CHANGED
@@ -10,7 +10,16 @@ export interface HealthReport {
10
10
  readonly nodes: number;
11
11
  readonly edges: number;
12
12
  readonly violations: number;
13
+ /** Of those, rules that threw rather than judged — counted apart, never matched by message. */
14
+ readonly couldNotJudge: number;
15
+ /** Of those, rules that would have read more of the graph than their budget. */
16
+ readonly overBudget: number;
13
17
  readonly danglingEdges: readonly string[];
18
+ /**
19
+ * What no longer fits the declaration (`store.findings()`, FR-21): records
20
+ * and links a repair could fix, and the rules that could not be judged.
21
+ */
22
+ readonly findings: number;
14
23
  readonly at: string;
15
24
  }
16
25
  export declare function health<S extends AnySchema>(store: Store<S>, options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,E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