@graview/ship 0.1.2 → 0.1.4

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 (46) hide show
  1. package/README.md +312 -13
  2. package/dist/browser.d.ts +4 -4
  3. package/dist/browser.d.ts.map +1 -1
  4. package/dist/browser.js +2 -2
  5. package/dist/browser.js.map +1 -1
  6. package/dist/handler.d.ts +192 -26
  7. package/dist/handler.d.ts.map +1 -1
  8. package/dist/handler.js +383 -340
  9. package/dist/handler.js.map +1 -1
  10. package/dist/health.d.ts +12 -1
  11. package/dist/health.d.ts.map +1 -1
  12. package/dist/health.js +15 -4
  13. package/dist/health.js.map +1 -1
  14. package/dist/index.d.ts +7 -5
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/live-protocol.d.ts +451 -0
  19. package/dist/live-protocol.d.ts.map +1 -0
  20. package/dist/live-protocol.js +957 -0
  21. package/dist/live-protocol.js.map +1 -0
  22. package/dist/live.d.ts +156 -9
  23. package/dist/live.d.ts.map +1 -1
  24. package/dist/live.js +31 -1
  25. package/dist/live.js.map +1 -1
  26. package/dist/remote.d.ts +180 -5
  27. package/dist/remote.d.ts.map +1 -1
  28. package/dist/remote.js +793 -76
  29. package/dist/remote.js.map +1 -1
  30. package/dist/runtime.d.ts +7 -5
  31. package/dist/runtime.d.ts.map +1 -1
  32. package/dist/runtime.js +3 -2
  33. package/dist/runtime.js.map +1 -1
  34. package/dist/seat-headers.d.ts +6 -0
  35. package/dist/seat-headers.d.ts.map +1 -1
  36. package/dist/seat-headers.js +6 -0
  37. package/dist/seat-headers.js.map +1 -1
  38. package/dist/serve.d.ts +5 -3
  39. package/dist/serve.d.ts.map +1 -1
  40. package/dist/serve.js +18 -4
  41. package/dist/serve.js.map +1 -1
  42. package/dist/websocket.d.ts +1 -1
  43. package/dist/websocket.d.ts.map +1 -1
  44. package/dist/websocket.js +10 -2
  45. package/dist/websocket.js.map +1 -1
  46. package/package.json +3 -3
@@ -0,0 +1,451 @@
1
+ import { type AnySchema, type Author, type FieldConflict, type MutationCall, type Operation, type PlannedChange, type Presence, type Principal, type Store, type WireRefusal } from "@graview/core";
2
+ import { type Limit, type LimitAnswer, type LimitAsked } from "./live.js";
3
+ /**
4
+ * THE LIVE WIRE AS FUNCTIONS OVER STATE THE HOST HOLDS (FR-41, FR-42).
5
+ *
6
+ * `connect()` used to keep everything about a socket in a closure: who it
7
+ * is, the last seq it was sent, where it said it stood. A Durable Object
8
+ * that hibernates wakes on the next message with no closure left, so it
9
+ * could not serve ship's wire without staying awake. Here the protocol is
10
+ * a handful of functions over two things a host already keeps:
11
+ *
12
+ * - a `Store` it opened, migrates, heals and meters itself, and
13
+ * - one `LiveSocketState` per socket, plain JSON — what a Durable Object
14
+ * puts in `serializeAttachment` and reads back on a wake.
15
+ *
16
+ * Everything else `liveProtocol` holds is derived from the store and may
17
+ * be thrown away at any moment: make it again on the wake and the next
18
+ * message is answered exactly as it would have been.
19
+ *
20
+ * `createStoreHandler`'s `connect` is this, with the state in memory: one
21
+ * implementation, two ways to hold it.
22
+ */
23
+ /**
24
+ * ONE SOCKET, AS A HOST KEEPS IT BETWEEN MESSAGES. Plain JSON on purpose:
25
+ * it survives `JSON.stringify` and `JSON.parse` unchanged, which is all a
26
+ * hibernating host can promise.
27
+ */
28
+ export interface LiveSocketState {
29
+ /**
30
+ * Who this socket is: read once, from its upgrade, by the host's `seatOf`
31
+ * — the principal itself, or a host's key for it (a string), which the
32
+ * protocol's `seatOf` resolves on every message. A key keeps the state
33
+ * small: a seat with fifty roles is most of a Durable Object's 2,048-byte
34
+ * attachment on its own.
35
+ */
36
+ readonly seat: Principal | string;
37
+ /** What its calls come through, recorded on every op they make: the host's word, never the client's (FR-52). */
38
+ readonly via: string;
39
+ /** The last seq this socket has been sent. Absent until it says hello: a call before that is refused. */
40
+ cursor?: number;
41
+ /**
42
+ * Its presence key: built from the seat at hello (or at its first `here`),
43
+ * said back in the welcome, and the key every later `here` on this
44
+ * socket is held under — never taken from the client (FR-47).
45
+ */
46
+ participant?: string;
47
+ /** The build its hello said it runs (FR-44): the client's word, kept for the host to count, never judged. */
48
+ build?: string;
49
+ /**
50
+ * THE HOST'S BUILD THIS SOCKET IS SERVED BY (FR-44), said at `open` —
51
+ * for a host that learns it per upgrade, as a worker carrying the socket
52
+ * says which shell it serves. Said in the welcome over the protocol's
53
+ * own `build`.
54
+ */
55
+ readonly hostBuild?: string;
56
+ /**
57
+ * The call this socket was told is busy (FR-45), and when (epoch ms) it
58
+ * may come again. Every other call is busy too until it does, so nothing
59
+ * made after it overtakes it.
60
+ */
61
+ held?: {
62
+ readonly cid: string;
63
+ readonly until: number;
64
+ };
65
+ }
66
+ /**
67
+ * A SOCKET AS A HOST'S JUDGEMENT IS HANDED IT (`build`, `viaOf`): its
68
+ * seat resolved to the principal, its channel, and the host's build it
69
+ * was opened under.
70
+ */
71
+ export interface ServedSocket {
72
+ readonly seat: Principal;
73
+ readonly via: string;
74
+ readonly hostBuild?: string;
75
+ }
76
+ /** A socket as the protocol is handed it: its state, a way to send it text, and — when the host can — a way to close it. */
77
+ export interface LivePeer extends LiveSocketState {
78
+ send(text: string): void;
79
+ /**
80
+ * Closes the socket. Called only when the socket's seat key is one the
81
+ * host no longer resolves, after it is told so (`{ t: "error", reopen:
82
+ * true }`), with code 4000: a client of any release then opens a new one.
83
+ */
84
+ close?(code?: number, reason?: string): void;
85
+ }
86
+ /** What one message did, for the host to keep and pass on. */
87
+ export interface LiveReceived {
88
+ /** The socket's cursor now; the protocol has also set it on the peer it was handed. Absent before hello. */
89
+ readonly cursor?: number;
90
+ /**
91
+ * The socket said where it is (`here`): its presence as the server built
92
+ * it, for the host to hold and tell the others; or `null` — it said
93
+ * `bye`, and the host forgets it. Absent: nothing changed.
94
+ */
95
+ readonly presence?: Presence | null;
96
+ /** The ops this message landed in the store, unredacted, for the host to `publish` to every other socket. */
97
+ readonly landed?: readonly Operation[];
98
+ }
99
+ export interface LiveProtocolOptions<S extends AnySchema> {
100
+ /** The store the wire serves: the host's own (FR-42). */
101
+ readonly store: Store<S>;
102
+ /**
103
+ * THE DECLARATION'S VERSION (FR-43): the host's own monotonic number for
104
+ * the declaration it serves — `app.version`, or a host's document version
105
+ * (Graview Cloud's `documentVersion`) — said in every welcome, in the
106
+ * state, on every route's answer, and in the `declaration` push. A client
107
+ * hands it to its `resolveApp(version)` to get the app at that version,
108
+ * so it names one declaration and only ever grows. A `declaration` push,
109
+ * or a welcome, with the number the client already serves is ignored:
110
+ * nothing reopens. 1 when unsaid.
111
+ */
112
+ readonly version?: number;
113
+ /** What opening the store migrated, said in a welcome's state. */
114
+ readonly migrated?: readonly string[];
115
+ /**
116
+ * MAKES WHAT LANDED DURABLE: an ack, and a post's answer, wait for it.
117
+ * Handed every op the protocol landed that is not durable yet, in seq
118
+ * order — the ones that just landed, after any a failed flush left — so
119
+ * a host that writes ops (a ledger) writes exactly these. Flushes run one
120
+ * at a time. One that rejects is not silence: the client is refused
121
+ * `unavailable` in words and keeps the change, the socket's cursor does
122
+ * not move, and the ops stay in the store but are held back from every
123
+ * socket until a later flush holds them — the change sent again, or the
124
+ * next one, which is handed them first. So a change sent again after a
125
+ * failed flush is never made twice, and never acked before it is durable.
126
+ * A flush may be handed an op again after it rejected: one it already
127
+ * holds, it skips.
128
+ */
129
+ readonly flush?: (landed: readonly Operation[]) => Promise<void>;
130
+ /**
131
+ * The host's build, an opaque string said in every welcome (FR-44): a
132
+ * client on another one is told once and keeps working. One string for
133
+ * every socket, or a function of the socket for a host whose build
134
+ * differs per upgrade; a socket opened with its own (`open(seat, via,
135
+ * { build })`) is welcomed with that. A route answers with its request's
136
+ * `build`, else this.
137
+ */
138
+ readonly build?: string | ((peer: ServedSocket) => string | undefined);
139
+ /**
140
+ * THE KEY A WITHHELD OP'S OPAQUE BATCH IS MINTED UNDER. A withheld op is
141
+ * served under `withheld:<16 hex>`, a keyed hash of its batch, so a seat
142
+ * cannot tell which session made a change it may not see. Without one,
143
+ * a key is drawn once per store held — the same opaque batch on every
144
+ * route and socket over that store, until a host that wakes holds a new
145
+ * one; a host that wants it the same across wakes gives a secret of its
146
+ * own, never sent to a client.
147
+ */
148
+ readonly withheldKey?: string;
149
+ /**
150
+ * THE LOWEST HOST PROTOCOL SERVED (FR-44): the host's own number for its
151
+ * half of the wire — its routing, its auth, its shell — beside ship's
152
+ * `WIRE_PROTOCOL`, which a host does not move. A hello whose
153
+ * `hostProtocol` is below it (absent is 0) is answered `reload` with
154
+ * `hostProtocol` and nothing else, so the page reloads onto a build that
155
+ * speaks it, carrying its unsent calls (`openRemote({ hostProtocol })`).
156
+ */
157
+ readonly minHostProtocol?: number;
158
+ /**
159
+ * WHAT A CHANGE CAME THROUGH, WHEN THE CLIENT CLAIMS IT (FR-52). A call
160
+ * or an undo may carry `via` — `openRemote` sends the one a call was
161
+ * applied with, as a guest view's `view:<name>` — and this judges it:
162
+ * handed the socket (or the route's `WireAsked`) and the claim, it
163
+ * answers the via to record. Asked of every change, with `claimed`
164
+ * undefined when there is none; answering nothing records the host's
165
+ * own. Absent, a claim is never read: what a change came through is the
166
+ * host's word, and a browser could otherwise record its edit as Claude's.
167
+ */
168
+ readonly viaOf?: (peer: ServedSocket, claimed: string | undefined) => string | undefined;
169
+ /**
170
+ * THE SEAT A HOST'S KEY NAMES. A socket opened with a key —
171
+ * `open("user:6b3f…", "web")` — keeps only the key in its state, and is
172
+ * judged on every message as the principal this answers. Keep what it
173
+ * reads somewhere a wake does not empty (a Durable Object's storage, not
174
+ * a map in memory), and make the key from the seat, never its session:
175
+ * every tab of one seat holds one key, and `publish` makes one view of
176
+ * it. Answering nothing, the host has lost the seat: the socket is told
177
+ * to open again (`{ t: "error", reopen: true }`), closed when the peer
178
+ * can be, and served nothing more; `openRemote` opens a new socket, whose
179
+ * upgrade the host reads the seat from again. Called at most once per
180
+ * key in one `publish` or `tell`.
181
+ */
182
+ readonly seatOf?: (key: string) => Principal | undefined;
183
+ /**
184
+ * A REFUSAL IN THE HOST'S WORDS (FR-46). Handed what the store threw, the
185
+ * calls that were refused and the socket (or the route's asker), it
186
+ * answers the refusal to send — reason, sentence, `wouldNeed` — or
187
+ * nothing for ship's own: invalid arguments said field by field in the
188
+ * form's words, an act the app does not have named as the seat named it
189
+ * and no other, and the policy's sentence as the policy said it.
190
+ */
191
+ readonly refusal?: (error: unknown, calls: readonly MutationCall[], peer: ServedSocket) => WireRefusal | undefined;
192
+ /**
193
+ * THE LOWEST PROTOCOL SERVED (FR-44). A hello on an older one is answered
194
+ * `reload` and nothing else: its calls are refused until it says hello
195
+ * on one served. Absent, every protocol is served.
196
+ */
197
+ readonly minProtocol?: number;
198
+ /**
199
+ * THE HOST'S LIMITS (FR-45, FR-46), asked of every call and undo before
200
+ * it is judged: busy (`{ retryAfter }`, try again), refused at a hard cap
201
+ * (`{ refuse }`, reason `limit`), or nothing.
202
+ */
203
+ readonly limit?: Limit;
204
+ /**
205
+ * THE HOST'S CAPS ON WHAT A CHANGE WOULD DO. `limit` is asked before a
206
+ * change is compiled, so it cannot count what the change would do; this
207
+ * is asked after — the calls (or the undo) compiled and applied by the
208
+ * store, nothing kept yet — with `limit`'s `asked` and the store's own
209
+ * plan (`PlannedChange`: the ops and primitives, the records and links
210
+ * added, removed and changed, how many records the store would hold).
211
+ * Its answers mean what `limit`'s do: `{ refuse }` is refused `limit`
212
+ * (413 over HTTP), `{ retryAfter }` busy (429), `{ unavailable }`
213
+ * refused `unavailable` (503); and a change it answers is not kept,
214
+ * flushed or sent to anybody. Answering nothing keeps it. Synchronous:
215
+ * the store waits on it with the change applied.
216
+ */
217
+ readonly admit?: (asked: LimitAsked, planned: PlannedChange) => LimitAnswer | undefined;
218
+ }
219
+ export interface LiveProtocol<S extends AnySchema> {
220
+ readonly store: Store<S>;
221
+ /**
222
+ * The state a socket starts with: its seat and its channel, and no
223
+ * cursor until it says hello — and the host's `build` for this socket,
224
+ * when the host learns it per upgrade.
225
+ */
226
+ open(seat: Principal | string, via: string, options?: {
227
+ readonly build?: string;
228
+ }): LiveSocketState;
229
+ /**
230
+ * Hand it one message the client sent. It answers down `peer.send`,
231
+ * moves `peer.cursor` (and `peer.participant`) as it goes, and says what
232
+ * the host should keep and pass on. `who` is everybody the host has
233
+ * here, for the presence a welcome is followed by.
234
+ *
235
+ * Messages on one socket are handed in the order they came, each after
236
+ * the one before has resolved. A host that publishes while a receive
237
+ * awaits its flush reads the cursor off the same peer object, or
238
+ * leaves the receiving socket out: its ops reach it in the ack.
239
+ *
240
+ * `landed` is what became durable: the call's ops, and any a failed
241
+ * flush had held back before them. When the flush fails, nothing has:
242
+ * `landed` is absent, the cursor is where it was, and the client was
243
+ * refused `unavailable`.
244
+ *
245
+ * `peers` is every socket the host holds, for the same presence: one a
246
+ * socket holds is said `held: "socket"` whatever the host built (as in
247
+ * `tell`). Unsaid, only this socket's own is known to be held.
248
+ */
249
+ receive(peer: LivePeer, text: string, who?: readonly Presence[], peers?: Iterable<LiveSocketState>): Promise<LiveReceived>;
250
+ /**
251
+ * Ops that landed, down every socket that has said hello and has not had
252
+ * them, each as its own seat may see them (FR-02, FR-16): in seq order,
253
+ * none skipped, caught up from the peer's own cursor. Sets each peer's
254
+ * cursor; the host keeps it. Each seat's view is made once however many
255
+ * sockets it holds: its key resolved once, each run of ops redacted and
256
+ * written once.
257
+ */
258
+ publish(ops: readonly Operation[], peers: Iterable<LivePeer>): void;
259
+ /**
260
+ * Who is here, told to every socket that has said hello: as its seat may
261
+ * be told it, and without itself. A presence whose participant one of
262
+ * `peers` holds is said `held: "socket"` — it stands while that socket
263
+ * does, with no heartbeat — whatever the host built it with, so a host
264
+ * that rebuilds presences from its own records cannot drop the stamp; a
265
+ * visitor's `until` is said as the host gave it.
266
+ */
267
+ tell(who: readonly Presence[], peers: Iterable<LivePeer>): void;
268
+ /**
269
+ * `POST /graview/ops`, FOR A HOST THAT ROUTES ITS OWN REQUESTS. Hand it
270
+ * the request's body as text and who is asking; it answers the status,
271
+ * the JSON body and the headers to send, exactly as `createStoreHandler`
272
+ * answers the route — which is this — and `landed`, the ops it put in
273
+ * the store, unredacted, for the host to `publish` to its sockets:
274
+ *
275
+ * - a batch the asking seat already landed: 200 with the ops it made;
276
+ * somebody else's, or not a client's shape: 409, `invalid`;
277
+ * - the host's `limit`: 429 with `Retry-After` (busy), 413 `limit`,
278
+ * 503 `unavailable`;
279
+ * - a field that moved since the call's `base`: 409 with `conflict`;
280
+ * - refused by the store: 409 with its sentence and `reason`;
281
+ * - landed: 200 with the ops as the seat may see them, once `flush`
282
+ * says they are durable.
283
+ *
284
+ * Every answer but busy says the declaration `version` and the `build`.
285
+ */
286
+ post(body: string, asked: WireAsked): Promise<WireAnswer & {
287
+ readonly landed?: readonly Operation[];
288
+ }>;
289
+ /** `GET /graview/state`: the store as the asking seat sees it — snapshot, log, migrations, modules, horizon. */
290
+ state(asked: WireAsked): WireAnswer;
291
+ /** `GET /graview/since?seq=N`: the ops after `seq`, as the asking seat sees them. */
292
+ since(seq: number, asked: WireAsked): WireAnswer;
293
+ /**
294
+ * THE DECLARATION CHANGED (FR-43), and this protocol is the one over the
295
+ * store migrated to it. Every socket that has said hello is told
296
+ * `{ t: "declaration", version }` and its cursor is forgotten: a seq of
297
+ * the old store means nothing on the new one, so nothing is pushed and
298
+ * no call is served until it says hello again. The host keeps the
299
+ * cursors as it keeps them after `receive`.
300
+ */
301
+ declared(peers: Iterable<LivePeer>): void;
302
+ }
303
+ /**
304
+ * WHO ASKS A ROUTE, as the host's own routing says it: the seat its
305
+ * credential names, what the request came through (FR-52), and — for a
306
+ * host whose build differs per request — the build that answers it (FR-44).
307
+ */
308
+ export interface WireAsked {
309
+ readonly seat: Principal;
310
+ readonly via: string;
311
+ /** The host's build answering this request; the protocol's `build` when absent. */
312
+ readonly build?: string;
313
+ }
314
+ /** A route's answer, for the host to send: a status, a JSON body, and the headers that carry meaning (`Retry-After`). */
315
+ export interface WireAnswer {
316
+ readonly status: number;
317
+ readonly body: Readonly<Record<string, unknown>>;
318
+ readonly headers: Readonly<Record<string, string>>;
319
+ }
320
+ /**
321
+ * A STORE'S REFUSAL, SAID TO A PERSON (FR-46). The store's own sentences
322
+ * were written for a developer: `Invalid arguments for mutation "add"
323
+ * label: Too small…`, and an unknown act listed every act the app has.
324
+ * Arguments are said field by field in the words the form asked in, and
325
+ * an unknown act by the name the call gave; anything else is the
326
+ * refusal's own sentence, the policy's among them.
327
+ */
328
+ export declare function wireRefusalOf(store: Store<AnySchema>, error: unknown): WireRefusal;
329
+ /**
330
+ * A PRESENCE AS THE SERVER BUILDS IT. Keyed by the seat — a client cannot
331
+ * claim to be somebody else — with only the session taken from what it
332
+ * said, and stamped with the server's clock. What it is, and for whom it
333
+ * acts, are the seat's (FR-47): a claimed `kind`, `onBehalfOf`, `until` or
334
+ * `held` is dropped, and the seat's name stands over a claimed one. `participant`
335
+ * is the key the server already gave this socket (its welcome said it):
336
+ * given, the claimed key is not read at all.
337
+ */
338
+ export declare function presenceFrom(told: Presence, seat: Principal, now?: Date, participant?: string): Presence;
339
+ /**
340
+ * A VISITOR WITHOUT A SOCKET, as a host announces it (FR-47): an agent
341
+ * acting over MCP or an RPC, a polling tab. Built from the author the host
342
+ * already trusts — what it is, what it is called, for whom — keyed
343
+ * `kind:id:visit` unless a session is given, so every call by one agent
344
+ * refreshes one figure rather than adding another.
345
+ */
346
+ export declare function visitorPresence(author: Author, options?: {
347
+ readonly session?: string;
348
+ readonly stop?: string;
349
+ readonly over?: string | null;
350
+ readonly hue?: number;
351
+ readonly now?: Date;
352
+ }): Presence;
353
+ /**
354
+ * WHO IS HERE, WITH ONE MORE (FR-47) — for a host that holds `who` itself,
355
+ * as a hibernating one does. The visitor is stamped now and stands until
356
+ * `ttlMs` from now; the same participant announced again replaces it, and
357
+ * anybody whose announced time has passed is dropped. Pure: keep what it
358
+ * answers, and hand it to `receive` and `tell`.
359
+ */
360
+ export declare function announcePresence(who: readonly Presence[], presence: Presence, ttlMs?: number, now?: number): Presence[];
361
+ /**
362
+ * WHO IS HERE, AS ONE SEAT MAY BE TOLD (FR-02). Somebody whose own record
363
+ * the seat may not see is not shown to it at all; anybody else is, without
364
+ * where they stand or what they hover when that names a record the seat
365
+ * may not see. A participant whose id is no record is shown as they are.
366
+ */
367
+ export declare function presenceSeenBy(who: readonly Presence[], sees: (id: string) => boolean): Presence[];
368
+ /** Whether a client may name this batch: `batch:<tag>:<n>` or `undo:<tag>:<n>`, as a `Store` mints them. */
369
+ export declare function isClientBatch(batch: unknown): batch is string;
370
+ /**
371
+ * BATCH IDS NO CLIENT CAN NAME FIRST: `served:<kind>:<tag>:<n>`, outside
372
+ * the shape `isClientBatch` accepts. Hand it to the host's own store —
373
+ * `new Store({ batchIds: serverBatchIds() })`, or `openStore`'s
374
+ * `storeOptions` — so what the host lands itself (an agent's RPC, a
375
+ * migration, a seed) is in a batch no client could have claimed.
376
+ * `createStoreHandler` mints its own this way, and `liveProtocol` mints
377
+ * one for a call that names none.
378
+ */
379
+ export declare function serverBatchIds(): (kind: "batch" | "undo") => string;
380
+ /**
381
+ * THE SAME SEAT. An op is the asking seat's own when its author is the
382
+ * same kind and id — and, for an agent, acts for the same person: Claude
383
+ * for Ada is not Claude for Bo.
384
+ */
385
+ export declare function authoredBy(author: Author, seat: Principal): boolean;
386
+ /**
387
+ * WHAT A BATCH A CHANGE NAMES IS: answered already (`answered`, the ops it
388
+ * made), refused (`refusal`), or free to land in (neither).
389
+ */
390
+ export type BatchClaim = {
391
+ readonly answered: readonly Operation[];
392
+ readonly refusal?: undefined;
393
+ } | {
394
+ readonly refusal: WireRefusal;
395
+ readonly answered?: undefined;
396
+ } | {
397
+ readonly answered?: undefined;
398
+ readonly refusal?: undefined;
399
+ };
400
+ /**
401
+ * THE STORE AS EACH SEAT SEES IT, on the wire — shared by the HTTP routes
402
+ * and the socket, so the two can never disagree. Internal: everything in
403
+ * it is derived from the store, and kept only to save reading the log
404
+ * again; a field's revisions are caught up from the log as it grew, so a
405
+ * wake that made this again reads the same revisions the sleeper had.
406
+ */
407
+ export interface Wire<S extends AnySchema> {
408
+ readonly store: Store<S>;
409
+ lastSeq(): number;
410
+ /** Kept from a seat: what its sight does not reach (FR-02), and the kinds of a module that is off (FR-12). */
411
+ sighted(principal: Principal): boolean;
412
+ /** Ops as the seat may see them, withheld in place (FR-16). */
413
+ shown(principal: Principal, ops: readonly Operation[]): Operation[];
414
+ /** The ops after `seq`, as the seat sees them. */
415
+ since(principal: Principal, seq: number): Operation[];
416
+ /** The store as the seat sees it. */
417
+ seenFor(principal: Principal): Store<S>;
418
+ /** The store's log as the seat sees it: every op in place, withheld ones under an opaque batch. */
419
+ seenLog(principal: Principal): Operation[];
420
+ whoFor(principal: Principal, who: readonly Presence[]): Presence[];
421
+ /** The fields a call would write that moved since the caller's base: a stale write (FR-05). */
422
+ conflictsOf(author: Principal, calls: readonly MutationCall[], base: unknown): FieldConflict[];
423
+ /**
424
+ * SENT TWICE, ANSWERED ONCE: what the batch a call or an undo names is,
425
+ * for the seat that names it. A client that never heard the answer sends
426
+ * again under the same batch — down the socket or over HTTP — and is
427
+ * answered with what it made the first time (FR-49): only ever its own
428
+ * ops. A batch that holds somebody else's, or one a client may not name
429
+ * (`isClientBatch`), is refused `invalid`.
430
+ */
431
+ claim(batch: unknown, seat: Principal): BatchClaim;
432
+ /** `{ horizon }` when the log was compacted (FR-23); nothing otherwise. */
433
+ horizonOf(): {
434
+ horizon?: number;
435
+ };
436
+ enabledModules(): string[];
437
+ }
438
+ export declare function wireOf<S extends AnySchema>(store: Store<S>, withheldKey?: string): Wire<S>;
439
+ /**
440
+ * A SEAT, NOT ITS TAB: the principal without its session — and without the
441
+ * session of the person an agent acts for. What a seat is served never
442
+ * depends on which tab asks, so its key never does either: the key a
443
+ * handler asks a host for (`seatKey`), and the one a sight is kept under.
444
+ */
445
+ export declare function seatOfTab(seat: Principal): Principal;
446
+ /**
447
+ * THE PROTOCOL OVER A STORE. Cheap to make, and safe to make again on
448
+ * every wake: what it keeps is derived from the store.
449
+ */
450
+ export declare function liveProtocol<S extends AnySchema>(options: LiveProtocolOptions<S>): LiveProtocol<S>;
451
+ //# sourceMappingURL=live-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-protocol.d.ts","sourceRoot":"","sources":["../src/live-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAkBL,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,aAAa,EAElB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAwC,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAkD,MAAM,WAAW,CAAC;AAEhK;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IAClC,gHAAgH;IAChH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yGAAyG;IACzG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6GAA6G;IAC7G,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACzD;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,S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