@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
package/dist/export.js CHANGED
@@ -1,15 +1,46 @@
1
+ import { assertReadable, formatStamp } from "@graview/core";
2
+ /*
3
+ * WHERE EACH OPENED STORE'S ARCHIVE IS (FR-23). `openStore` says, for a
4
+ * store over an adapter that keeps one, so a full export of that store can
5
+ * read what a normal open never loaded.
6
+ */
7
+ const ARCHIVES = new WeakMap();
8
+ /** Tells `exportBundle` where a store's archive is read from. `openStore` calls it. */
9
+ export function rememberArchive(store, load) {
10
+ ARCHIVES.set(store, load);
11
+ }
1
12
  export function exportBundle(app, store, options = {}) {
2
- return {
13
+ // The persisted log when the caller has one (it holds migration runs and
14
+ // prior sessions); the in-memory log otherwise.
15
+ const log = options.log ?? store.log.all();
16
+ const bundle = (log, horizon) => ({
3
17
  format: "graview-bundle",
4
18
  bundleVersion: 1,
5
19
  app: app.name,
6
20
  version: app.version ?? 1,
7
21
  exportedAt: (options.now ?? (() => new Date().toISOString()))(),
22
+ ...formatStamp(),
8
23
  snapshot: store.snapshot(),
9
- // The persisted log when the caller has one (it holds migration runs and
10
- // prior sessions); the in-memory log otherwise.
11
- log: options.log ?? store.log.all(),
12
- };
24
+ log,
25
+ ...(horizon > 0 ? { horizon } : {}),
26
+ });
27
+ const horizon = log[0]?.seq ?? store.log.horizon;
28
+ if (!options.full)
29
+ return bundle(log, horizon);
30
+ if (horizon === 0)
31
+ return Promise.resolve(bundle(log, 0));
32
+ const archive = ARCHIVES.get(store);
33
+ if (!archive) {
34
+ return Promise.reject(new Error(`This store's log was compacted at seq ${horizon} and its archive is not reachable from here: export the store openStore opened, whose adapter keeps the archive.`));
35
+ }
36
+ return archive().then((archived) => {
37
+ const before = archived.ops.filter((op) => op.seq < horizon);
38
+ const whole = [...before, ...log];
39
+ const gap = whole.findIndex((op, index) => op.seq !== index);
40
+ if (gap >= 0)
41
+ throw new Error(`The archive does not reach back to seq 0 without a gap: seq ${gap} is missing, so this export would not be the whole history.`);
42
+ return bundle(whole, 0);
43
+ });
13
44
  }
14
45
  /** Refuses a bundle for a different app or a newer format, plainly. */
15
46
  export function assertBundle(app, bundle) {
@@ -19,6 +50,8 @@ export function assertBundle(app, bundle) {
19
50
  if (bundle.bundleVersion > 1) {
20
51
  throw new Error(`Bundle format ${bundle.bundleVersion} is newer than this ship understands (1). Upgrade @graview/ship, then import.`);
21
52
  }
53
+ // A snapshot or ops in a newer format than this framework reads: said, never misread (FR-31).
54
+ assertReadable(bundle);
22
55
  if (bundle.app !== app.name) {
23
56
  throw new Error(`This bundle is for "${bundle.app}", not "${app.name}"`);
24
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts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,MAAM,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,iBAAiB,MAAM,CAAC,aAAa,+EAA+E,CACrH,CAAC;IACJ,CAAC;IACD,8FAA8F;IAC9F,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,GAAG,WAAW,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,CAAC,OAAO,mCAAmC,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI;YAC3F,+BAA+B,CAClC,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -1,20 +1,20 @@
1
1
  import type { PersistenceAdapter } from "@graview/core";
2
+ import type { StoredMeta } from "./meta.js";
2
3
  /**
3
4
  * Persistence a self-hoster can READ: a directory per scope holding
4
5
  * `snapshot.json` (the current graph), `log.jsonl` (one operation per line,
5
- * append-only — history as plain lines a person can grep), and `meta.json`
6
- * (the stored schema version the migration engine compares against).
6
+ * append-only — history as plain lines a person can grep), `meta.json`
7
+ * (the stored schema version the migration engine compares against),
8
+ * `epochs.json` (the base graphs the log folds from, FR-27), and, once the
9
+ * log has been compacted behind an undo horizon (FR-23), `archive/` with
10
+ * the ops and epochs from before it, as `log.jsonl` and `epochs.json` again.
7
11
  *
8
12
  * Deliberately boring. The core's sqlite adapter exists for scale; this one
9
13
  * exists so "where is my data" has an answer anyone can open.
10
14
  */
11
15
  export interface FileAdapter extends PersistenceAdapter<string> {
12
- loadMeta(scope: string): {
13
- version: number;
14
- } | null;
15
- saveMeta(scope: string, meta: {
16
- version: number;
17
- }): void;
16
+ loadMeta(scope: string): StoredMeta | null;
17
+ saveMeta(scope: string, meta: StoredMeta): void;
18
18
  /**
19
19
  * The directory it writes into.
20
20
  *
@@ -1 +1 @@
1
- {"version":3,"file":"file-adapter.d.ts","sourceRoot":"","sources":["../src/file-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnE;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAY,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACzD;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CA4C3D"}
1
+ {"version":3,"file":"file-adapter.d.ts","sourceRoot":"","sources":["../src/file-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgC,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAY,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CA6F3D"}
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readFileSync, rmSync, writeFileSync, appendFileSync, existsSync } from "node:fs";
1
+ import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, appendFileSync, existsSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  export function createFileAdapter(root) {
4
4
  const place = (scope, file) => join(root, scope, file);
@@ -11,6 +11,26 @@ export function createFileAdapter(root) {
11
11
  mkdirSync(dirname(path), { recursive: true });
12
12
  writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
13
13
  };
14
+ /** Written whole and moved into place, so a crash leaves the old file or the new one. */
15
+ const replace = (path, text) => {
16
+ mkdirSync(dirname(path), { recursive: true });
17
+ writeFileSync(`${path}.tmp`, text);
18
+ renameSync(`${path}.tmp`, path);
19
+ };
20
+ const lines = (path) => existsSync(path)
21
+ ? readFileSync(path, "utf8")
22
+ .split("\n")
23
+ .filter((line) => line.trim().length > 0)
24
+ .map((line) => JSON.parse(line))
25
+ : [];
26
+ const jsonl = (ops) => ops.map((op) => `${JSON.stringify(op)}\n`).join("");
27
+ const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
28
+ /** The seq the log begins at: its checkpoint's, once compacted (FR-23). */
29
+ const horizonOf = (scope) => [...(read(place(scope, "epochs.json")) ?? [])].reverse().find((epoch) => epoch.horizon)?.seq ?? 0;
30
+ const archiveOf = (scope) => ({
31
+ ops: lines(place(scope, join("archive", "log.jsonl"))),
32
+ epochs: read(place(scope, join("archive", "epochs.json"))) ?? [],
33
+ });
14
34
  return {
15
35
  name: "file",
16
36
  root,
@@ -24,13 +44,15 @@ export function createFileAdapter(root) {
24
44
  rmSync(join(root, scope), { recursive: true, force: true });
25
45
  },
26
46
  async loadLog(scope) {
27
- const path = place(scope, "log.jsonl");
28
- if (!existsSync(path))
29
- return [];
30
- return readFileSync(path, "utf8")
31
- .split("\n")
32
- .filter((line) => line.trim().length > 0)
33
- .map((line) => JSON.parse(line));
47
+ /*
48
+ * From the horizon on. A compaction writes the archive, then the
49
+ * checkpoint, then the tail: a crash before the tail is rewritten
50
+ * leaves ops behind the checkpoint here, already archived, and they
51
+ * are not loaded twice.
52
+ */
53
+ const horizon = horizonOf(scope);
54
+ const ops = lines(place(scope, "log.jsonl"));
55
+ return horizon > 0 ? ops.filter((op) => op.seq >= horizon) : ops;
34
56
  },
35
57
  async appendOps(scope, ops) {
36
58
  if (ops.length === 0)
@@ -39,6 +61,34 @@ export function createFileAdapter(root) {
39
61
  mkdirSync(dirname(path), { recursive: true });
40
62
  appendFileSync(path, ops.map((op) => JSON.stringify(op)).join("\n") + "\n");
41
63
  },
64
+ async loadEpochs(scope) {
65
+ return read(place(scope, "epochs.json")) ?? [];
66
+ },
67
+ async saveEpochs(scope, epochs) {
68
+ write(place(scope, "epochs.json"), epochs);
69
+ },
70
+ async compact(scope, checkpoint) {
71
+ const at = checkpoint.seq;
72
+ const ops = lines(place(scope, "log.jsonl"));
73
+ const epochs = read(place(scope, "epochs.json")) ?? [];
74
+ const held = archiveOf(scope);
75
+ // Keyed, so a compaction run again after a crash archives nothing twice.
76
+ const archivedOps = new Map(held.ops.map((op) => [op.seq, op]));
77
+ for (const op of ops)
78
+ if (op.seq < at)
79
+ archivedOps.set(op.seq, op);
80
+ const archivedEpochs = new Map(held.epochs.map((epoch) => [JSON.stringify(epoch), epoch]));
81
+ for (const epoch of epochs)
82
+ if (epoch.seq < at)
83
+ archivedEpochs.set(JSON.stringify(epoch), epoch);
84
+ replace(place(scope, join("archive", "log.jsonl")), jsonl([...archivedOps.values()].sort((a, b) => a.seq - b.seq)));
85
+ replace(place(scope, join("archive", "epochs.json")), json([...archivedEpochs.values()]));
86
+ replace(place(scope, "epochs.json"), json([{ ...checkpoint, horizon: true }, ...epochs.filter((epoch) => epoch.seq > at)]));
87
+ replace(place(scope, "log.jsonl"), jsonl(ops.filter((op) => op.seq >= at)));
88
+ },
89
+ async loadArchive(scope) {
90
+ return archiveOf(scope);
91
+ },
42
92
  loadMeta(scope) {
43
93
  return read(place(scope, "meta.json"));
44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AK;YACrB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,QAAQ,CAAC,KAAK;YACZ,OAAO,IAAI,CAAa,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,QAAQ,CAAC,KAAK,EAAE,IAAI;YAClB,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,271 @@
1
+ import { type AnySchema, type GraviewApp, type PersistenceAdapter, type Presence, type Principal, type Store } from "@graview/core";
2
+ import { type Limit, type LiveConnection, type LiveSocket } from "./live.js";
3
+ import { presenceSeenBy, type LiveProtocol, type LiveSocketState } from "./live-protocol.js";
4
+ import { type OpenedStore } from "./open-store.js";
5
+ import { SEAT_HEADERS } from "./seat-headers.js";
6
+ import type { GraphSnapshot } from "./snapshot.js";
7
+ /**
8
+ * THE STORE, BEHIND ANY RUNTIME'S FETCH — and the op log is the wire (FR-09).
9
+ *
10
+ * Every route is one function from a `Request` to a `Response`, which is
11
+ * what a Cloudflare Worker, a Durable Object, Deno, Bun and a service worker
12
+ * all call a handler. `serveStore` is a thin `node:http` wrapper around it;
13
+ * nothing in this module reaches a `node:` builtin, so a host that runs
14
+ * somewhere other than Node serves the same wire without a fork.
15
+ *
16
+ * What is deliberately NOT here: a second way to change the graph. A client
17
+ * sends CALLS, not primitives; the handler applies them through an ordinary
18
+ * `Store` under the principal the request carries, so the policy judges
19
+ * them exactly as it judges them in a browser, the invariants run, and the
20
+ * op that comes back is the same shape the browser would have made. A
21
+ * client that could post primitives would be a client that could write past
22
+ * every rule the app declares.
23
+ *
24
+ * The protocol is four routes:
25
+ *
26
+ * GET /graview/state the graph, the log, the stored version and the modules on
27
+ * POST /graview/ops calls in, the ops they produced out — or `undo`, batches to take back
28
+ * GET /graview/since?seq=N the ops appended after N — everyone else's
29
+ * GET /graview/health ship's own report, plus where the data is
30
+ *
31
+ * And three for WHO IS HERE, which is not the op log and never touches it:
32
+ *
33
+ * POST /graview/here say where you are; answers with who else is, and the ops since `seq`
34
+ * GET /graview/who who is here right now
35
+ * POST /graview/leave say you have gone
36
+ *
37
+ * Presence lives in a map inside this closure with a time to live — not in
38
+ * the store, not in the adapter, not in the log. A tab that dies without a
39
+ * word is gone after three missed heartbeats.
40
+ *
41
+ * Polling is the floor, on purpose: a poll is a thing a person can
42
+ * reproduce with `curl`, and a thing every runtime can answer. Beside it,
43
+ * `connect` serves the live wire (FR-05, `./live.ts`) to whatever socket a
44
+ * host hands it, and `GET /graview/live` names it on the wire. The live
45
+ * protocol itself is `liveProtocol` (`./live-protocol.ts`), over state a
46
+ * host may hold instead of this closure (FR-41).
47
+ */
48
+ /**
49
+ * THE WIRE, AS A CONTRACT. Every route the handler answers, in one place a
50
+ * test pins and a README repeats: what a host in front of this — Graview
51
+ * Cloud, or anybody's — must keep answering for `openRemote`, `graview mcp
52
+ * --remote-url` and `graview apply --remote-url` to work unchanged. What a
53
+ * host adds (who a bearer token is, which tenant, how much) goes in
54
+ * `seatOf` and around these routes, never inside them.
55
+ */
56
+ export declare const WIRE: readonly [{
57
+ readonly method: "GET";
58
+ readonly path: "/graview/state";
59
+ readonly says: "the graph, the log, the stored version and the modules on";
60
+ }, {
61
+ readonly method: "POST";
62
+ readonly path: "/graview/ops";
63
+ readonly 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";
64
+ }, {
65
+ readonly method: "GET";
66
+ readonly path: "/graview/since";
67
+ readonly says: "the ops appended after ?seq=N — everyone else's";
68
+ }, {
69
+ readonly method: "GET";
70
+ readonly path: "/graview/health";
71
+ readonly says: "ship's own report, plus where the data is";
72
+ }, {
73
+ readonly method: "GET";
74
+ readonly path: "/graview/export";
75
+ readonly says: "the whole store as one bundle, the way out";
76
+ }, {
77
+ readonly method: "POST";
78
+ readonly path: "/graview/here";
79
+ readonly says: "say where you are; answers with who else is, the ops since `seq`, and the `participant` key you are held under";
80
+ }, {
81
+ readonly method: "GET";
82
+ readonly path: "/graview/who";
83
+ readonly says: "who is here right now";
84
+ }, {
85
+ readonly method: "POST";
86
+ readonly path: "/graview/leave";
87
+ readonly says: "say you have gone — only ever yourself";
88
+ }, {
89
+ readonly method: "GET";
90
+ readonly path: "/graview/live";
91
+ readonly 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";
92
+ }];
93
+ export { presenceSeenBy, SEAT_HEADERS };
94
+ /** What every handler takes, whoever holds the store. */
95
+ interface HandlerOptions<S extends AnySchema> {
96
+ readonly app: GraviewApp<S>;
97
+ /**
98
+ * Who a request is. The host's to say — from a session, a bearer token,
99
+ * whatever it authenticates with — and the store judges every call under
100
+ * the principal it returns. It may answer a promise, for a host that
101
+ * verifies a token with `crypto.subtle`.
102
+ */
103
+ readonly seatOf?: (request: Request) => Principal | Promise<Principal>;
104
+ /**
105
+ * WHAT THE CALLS CAME THROUGH (FR-52): the host's word, recorded as `via`
106
+ * on every op a request or a socket makes — `web`, `api`, `mcp:Claude`.
107
+ * Handed the request (the upgrade, for a socket) and the seat `seatOf`
108
+ * said. A client's own `via` is never read: a browser could otherwise
109
+ * record its edit as Claude's. Absent, or answering nothing, a socket's
110
+ * calls are `web` and an HTTP request's `api` — unless the host trusts
111
+ * the seat headers, when `SEAT_HEADERS.via` says it as they say the seat.
112
+ */
113
+ readonly viaOf?: (request: Request, seat: Principal) => string | undefined | Promise<string | undefined>;
114
+ /**
115
+ * BELIEVE THE SEAT HEADERS (`SEAT_HEADERS`) — off by default (FR-06).
116
+ *
117
+ * A header is a claim, and anyone who could reach a served store used to
118
+ * claim any seat by sending one, and every remote agent was recorded as
119
+ * a person. A store that neither trusts headers nor is given a `seatOf`
120
+ * answers 401: it cannot say who is asking. `graview serve` turns this on
121
+ * for a server bound to loopback only, and says so.
122
+ */
123
+ readonly trustSeatHeaders?: boolean;
124
+ /** Where the data is, for the health report to say out loud. */
125
+ readonly where?: string;
126
+ /** How long a presence stands after its last word. Three heartbeats by default. */
127
+ readonly presenceTtlMs?: number;
128
+ /**
129
+ * AN AGENT THAT ACTS IS IN THE ROOM (FR-47). Every op an agent seat lands
130
+ * in the store — through `POST /graview/ops`, an MCP handler over the
131
+ * same store, the host's own loop — announces it to who is here, as the
132
+ * agent and for whom, standing over what it wrote, for this long after
133
+ * its last op: `VISITOR_PRESENCE_TTL_MS` when `true` or unsaid, the
134
+ * number of ms when one is given, never when `false`. An agent seat that
135
+ * holds a socket of its own is there already, and is not announced twice.
136
+ */
137
+ readonly announceAgents?: boolean | number;
138
+ /**
139
+ * THE HOST'S LIMITS (FR-45, FR-46): asked of every change — a socket's
140
+ * `call` or `undo`, a `POST /graview/ops` — before it is judged.
141
+ * `{ retryAfter }` is BUSY: the socket says `busy`, HTTP answers 429 with
142
+ * `Retry-After`, and the client sends the change again after the wait.
143
+ * `{ refuse }` is a hard cap: refused with reason `limit` (413 over
144
+ * HTTP), and the client takes the change back.
145
+ */
146
+ readonly limit?: Limit;
147
+ /**
148
+ * THE HOST'S BUILD (FR-44), an opaque string said in every welcome. A
149
+ * client on another build keeps working and is told once, so a person
150
+ * can reload when it suits them.
151
+ */
152
+ readonly build?: string;
153
+ /**
154
+ * THE LOWEST LIVE PROTOCOL SERVED (FR-44). A socket whose hello says an
155
+ * older one is answered `reload`: its client keeps what it had not sent,
156
+ * reloads onto a build that speaks this one, and offers it again there.
157
+ * Absent, every protocol is served.
158
+ */
159
+ readonly minProtocol?: number;
160
+ }
161
+ /**
162
+ * THE DECLARATION THE HOST NOW SERVES (FR-43), handed to
163
+ * `declarationChanged`. Over a store the host holds, `store` is the one it
164
+ * migrated to `app` (with `flush` and `migrated` as at the start); over an
165
+ * adapter, the handler opens it again itself with `openStore`, which
166
+ * migrates what is stored.
167
+ */
168
+ export interface DeclarationChange {
169
+ readonly app: GraviewApp<AnySchema>;
170
+ readonly store?: Store<AnySchema>;
171
+ readonly flush?: () => Promise<void>;
172
+ readonly migrated?: readonly string[];
173
+ }
174
+ /** The handler opens its own store from an adapter: one declaration plus one adapter is a running deployment. */
175
+ export interface AdapterStoreHandlerOptions<S extends AnySchema> extends HandlerOptions<S> {
176
+ /** Where the graph lives: any `PersistenceAdapter` — a file, SQLite, Durable Object storage. */
177
+ readonly adapter: PersistenceAdapter<string>;
178
+ readonly store?: never;
179
+ /** What to put in an empty store on first start. */
180
+ readonly seed?: GraphSnapshot;
181
+ readonly scope?: string;
182
+ /**
183
+ * THE MODULES THIS WORKSPACE HAS ON (FR-12) — usually what it pays for.
184
+ * Handed to `openStore`, which records a change from what the store's
185
+ * log last said as an op; absent, the log's word stands (every module,
186
+ * when it never said one). A module off has its acts refused and its
187
+ * kinds kept from every route, as a sight keeps a record.
188
+ */
189
+ readonly enabledModules?: readonly string[];
190
+ }
191
+ /**
192
+ * THE HANDLER OVER A STORE THE HOST ALREADY HOLDS (FR-42). A host with its
193
+ * own durability — a ledger of snapshots in parts, epochs, quarantine and
194
+ * restore, its own meter — opens, migrates and heals its `Store` itself,
195
+ * and the wire is served from that instance. Closing the handler does not
196
+ * close the store: it is the host's.
197
+ */
198
+ export interface HeldStoreHandlerOptions<S extends AnySchema> extends HandlerOptions<S> {
199
+ readonly store: Store<S>;
200
+ readonly adapter?: never;
201
+ /** Resolves once what landed is durable: a call's answer waits for it. Absent, the answer goes at once. */
202
+ readonly flush?: () => Promise<void>;
203
+ /** What opening the store migrated, in the migrations' own words: said in the state, as `openStore`'s would be. */
204
+ readonly migrated?: readonly string[];
205
+ }
206
+ export type StoreHandlerOptions<S extends AnySchema> = AdapterStoreHandlerOptions<S> | HeldStoreHandlerOptions<S>;
207
+ export interface StoreHandler<S extends AnySchema> {
208
+ readonly store: Store<S>;
209
+ /** The open `openStore` made, when the handler opened the store from an adapter; absent over a store the host holds. */
210
+ readonly opened?: OpenedStore<S>;
211
+ /** Every WIRE route: a `Request` in, a `Response` out. Bound, so it can be handed on as it is. */
212
+ readonly handle: (request: Request) => Promise<Response>;
213
+ /**
214
+ * THE LIVE WIRE, ON ANY SOCKET (FR-05). Hand it the upgrade `Request`
215
+ * (the seat is read from it, as on every route) and a way to send text
216
+ * down the socket; it answers with the connection to hand each message
217
+ * the client sends and the close, or with the `Response` refusing it (a
218
+ * 401 when it cannot say who is asking). A Worker attaches a
219
+ * `WebSocketPair`'s server end here; `serveStore` attaches Node's
220
+ * upgrade. A host that hibernates holds each socket's state itself
221
+ * instead: `seatFor` and `protocol`.
222
+ */
223
+ readonly connect: (request: Request, socket: LiveSocket) => Promise<LiveConnection | Response>;
224
+ /**
225
+ * THE STATE A SOCKET STARTS WITH (FR-41): its seat, read by `seatOf`
226
+ * from the upgrade, and its channel, said by `viaOf` (FR-52) — or the
227
+ * `Response` refusing it. A hibernating host keeps it in the socket's
228
+ * attachment and hands it, with each message, to `protocol.receive`.
229
+ */
230
+ readonly seatFor: (request: Request) => Promise<LiveSocketState | Response>;
231
+ /** The live protocol over this handler's store, for a host that holds its sockets' state itself (FR-41). Made again when the declaration changes. */
232
+ readonly protocol: LiveProtocol<S>;
233
+ /**
234
+ * THE DECLARATION CHANGED (FR-43). The handler serves `change.app` from
235
+ * now on, over the store migrated to it — the host's, or the one it opens
236
+ * again from its adapter — and every open socket is told
237
+ * `{ t: "declaration", version }`. A client of `openRemote` then opens on
238
+ * the new declaration without reloading the page. While the change is
239
+ * made, every request and message waits for it, so nothing lands on the
240
+ * store being let go. `store`, `opened` and `protocol` are the new ones
241
+ * afterwards.
242
+ */
243
+ declarationChanged(change: DeclarationChange): Promise<void>;
244
+ /**
245
+ * SOMEBODY HERE WITHOUT A SOCKET (FR-47): an agent acting over MCP or an
246
+ * RPC, a polling tab. Told to every socket and every poll at once, as
247
+ * each seat may see them, and gone `ttlMs` after (30 s unsaid) unless
248
+ * announced again. The host builds the presence — `visitorPresence(seat)`
249
+ * — because it is the host who knows who the seat is.
250
+ */
251
+ announce(presence: Presence, ttlMs?: number): void;
252
+ /** Writes what is pending and lets the adapter go — or, over a store the host holds, writes what is pending and leaves the store open. */
253
+ close(): Promise<void>;
254
+ }
255
+ /** A seat read from a request's headers — only ever when the host trusts them. */
256
+ export declare function seatFromHeaders(request: Request): Principal;
257
+ /**
258
+ * Open the store and answer the wire for it. The migration runs HERE, once,
259
+ * against the stored graph — which is the whole reason a server is the
260
+ * honest place for it. A browser that migrates its own copy migrates it once
261
+ * per browser; a server that migrates the roster migrates the roster.
262
+ *
263
+ * Or answer the wire for a store the host opened itself (FR-42): the
264
+ * adapter form is that, over the store `openStore` hands back.
265
+ */
266
+ export declare function createStoreHandler<S extends AnySchema>(options: AdapterStoreHandlerOptions<S>): Promise<StoreHandler<S> & {
267
+ readonly opened: OpenedStore<S>;
268
+ }>;
269
+ export declare function createStoreHandler<S extends AnySchema>(options: HeldStoreHandlerOptions<S>): Promise<StoreHandler<S>>;
270
+ export declare function createStoreHandler<S extends AnySchema>(options: StoreHandlerOptions<S>): Promise<StoreHandler<S>>;
271
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EAEd,KAAK,UAAU,EAGf,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAwC,KAAK,KAAK,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACnH,OAAO,EAIL,cAAc,EAId,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,K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