@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.
- package/README.md +165 -9
- package/dist/browser-adapter.d.ts +9 -9
- package/dist/browser-adapter.d.ts.map +1 -1
- package/dist/browser-adapter.js +6 -3
- package/dist/browser-adapter.js.map +1 -1
- package/dist/browser.d.ts +10 -6
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +4 -2
- package/dist/browser.js.map +1 -1
- package/dist/cli.d.ts +17 -7
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +41 -7
- package/dist/cli.js.map +1 -1
- package/dist/export.d.ts +27 -2
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +38 -5
- package/dist/export.js.map +1 -1
- package/dist/file-adapter.d.ts +8 -8
- package/dist/file-adapter.d.ts.map +1 -1
- package/dist/file-adapter.js +58 -8
- package/dist/file-adapter.js.map +1 -1
- package/dist/handler.d.ts +271 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +581 -0
- package/dist/handler.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.d.ts.map +1 -1
- package/dist/health.js +5 -1
- package/dist/health.js.map +1 -1
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/live-protocol.d.ts +208 -0
- package/dist/live-protocol.d.ts.map +1 -0
- package/dist/live-protocol.js +380 -0
- package/dist/live-protocol.js.map +1 -0
- package/dist/live.d.ts +266 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +74 -0
- package/dist/live.js.map +1 -0
- package/dist/meta.d.ts +13 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +2 -0
- package/dist/meta.js.map +1 -0
- package/dist/open-store.d.ts +56 -7
- package/dist/open-store.d.ts.map +1 -1
- package/dist/open-store.js +141 -12
- package/dist/open-store.js.map +1 -1
- package/dist/remote.d.ts +237 -13
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +1033 -88
- package/dist/remote.js.map +1 -1
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +22 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seat-headers.d.ts +26 -0
- package/dist/seat-headers.d.ts.map +1 -0
- package/dist/seat-headers.js +26 -0
- package/dist/seat-headers.js.map +1 -0
- package/dist/serve.d.ts +16 -106
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +95 -217
- package/dist/serve.js.map +1 -1
- package/dist/source-edit.d.ts.map +1 -1
- package/dist/source-edit.js +6 -1
- package/dist/source-edit.js.map +1 -1
- package/dist/steps.d.ts +43 -0
- package/dist/steps.d.ts.map +1 -1
- package/dist/steps.js +69 -0
- package/dist/steps.js.map +1 -1
- package/dist/websocket.d.ts +14 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +163 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +6 -2
package/dist/open-store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Store, } from "@graview/core";
|
|
1
|
+
import { assertReadable, formatStamp, OperationLog, snapshotHash, Store, } from "@graview/core";
|
|
2
|
+
import { rememberArchive } from "./export.js";
|
|
2
3
|
import { migrateSnapshot } from "./migrations.js";
|
|
3
4
|
export async function openStore(options) {
|
|
4
5
|
const { app, adapter } = options;
|
|
@@ -7,8 +8,23 @@ export async function openStore(options) {
|
|
|
7
8
|
await adapter.delete(scope);
|
|
8
9
|
const stored = (await adapter.load(scope));
|
|
9
10
|
const persisted = (await adapter.loadLog?.(scope)) ?? [];
|
|
10
|
-
|
|
11
|
+
const epochs = (await adapter.loadEpochs?.(scope)) ?? [];
|
|
12
|
+
/*
|
|
13
|
+
* A COMPACTED LOG BEGINS AT ITS HORIZON (FR-23): the adapter hands over
|
|
14
|
+
* the checkpoint and the ops from its seq on, and nothing older is read.
|
|
15
|
+
*/
|
|
16
|
+
const checkpoint = [...epochs].reverse().find((epoch) => epoch.horizon);
|
|
17
|
+
const horizon = checkpoint?.seq ?? 0;
|
|
18
|
+
let seq = horizon + persisted.length;
|
|
11
19
|
const meta = adapter.loadMeta?.(scope) ?? null;
|
|
20
|
+
/*
|
|
21
|
+
* A SNAPSHOT IN A NEWER FORMAT IS NOT FOLDED (FR-31). A rolled-back
|
|
22
|
+
* framework meeting what its successor wrote says so — the host refolds
|
|
23
|
+
* from the log or rolls forward — rather than reading a shape it does not
|
|
24
|
+
* know and writing its misreading back.
|
|
25
|
+
*/
|
|
26
|
+
if (stored !== null)
|
|
27
|
+
assertReadable(meta);
|
|
12
28
|
const target = app.version ?? 1;
|
|
13
29
|
/*
|
|
14
30
|
* THE LOG OUTRANKS THE META. A crash between writing the migrated
|
|
@@ -23,7 +39,8 @@ export async function openStore(options) {
|
|
|
23
39
|
.reduce((highest, version) => Math.max(highest, version), 0);
|
|
24
40
|
const storedVersion = stored === null
|
|
25
41
|
? target
|
|
26
|
-
:
|
|
42
|
+
: // A migration run behind the horizon is archived; the checkpoint still says the version it stood at.
|
|
43
|
+
Math.max(meta?.version ?? options.assumeVersion ?? target, migratedTo, checkpoint?.version ?? 0);
|
|
27
44
|
let snapshot = stored ?? options.seed ?? { nodes: [], edges: [] };
|
|
28
45
|
let migrated = [];
|
|
29
46
|
if (storedVersion < target) {
|
|
@@ -32,6 +49,40 @@ export async function openStore(options) {
|
|
|
32
49
|
migrated = run.ops.map((op) => ({ ...op, seq: seq++ }));
|
|
33
50
|
await adapter.appendOps?.(scope, migrated);
|
|
34
51
|
}
|
|
52
|
+
/*
|
|
53
|
+
* EACH DECLARATION VERSION BEGINS AN EPOCH (FR-27): a base graph and the
|
|
54
|
+
* seq the log folds onto it from. A new scope begins one at its seed,
|
|
55
|
+
* which was never an operation. A migration run begins one at the graph
|
|
56
|
+
* it left, naming the change, so the log verifies from there and undo
|
|
57
|
+
* does not reach back across it. A store from before epochs begins one
|
|
58
|
+
* at what it holds — from empty, when its whole log folds to it, since
|
|
59
|
+
* then the whole history is proof — and is verifiable from then on.
|
|
60
|
+
* Recorded straight after the migration's ops, before the snapshot: a
|
|
61
|
+
* crash between the two leaves a stale snapshot that verifying finds.
|
|
62
|
+
*/
|
|
63
|
+
const at = new Date().toISOString();
|
|
64
|
+
let epoch;
|
|
65
|
+
if (migrated.length > 0) {
|
|
66
|
+
epoch = { seq, base: snapshot, version: target, change: migrated.map((op) => op.intent).join("; "), at };
|
|
67
|
+
}
|
|
68
|
+
else if (stored === null) {
|
|
69
|
+
epoch = { seq, base: snapshot, version: target, at };
|
|
70
|
+
}
|
|
71
|
+
else if (epochs.length === 0 && adapter.saveEpochs) {
|
|
72
|
+
/*
|
|
73
|
+
* Adopted once, where it can be kept: folding the whole log and hashing
|
|
74
|
+
* it is the cost of proving a store from before epochs, and an adapter
|
|
75
|
+
* that cannot keep the result would pay it on every open — a page with
|
|
76
|
+
* two thousand talks did, and the gauntlet took five times as long.
|
|
77
|
+
*/
|
|
78
|
+
epoch = foldsFromEmpty(app.schema, persisted, stored)
|
|
79
|
+
? { seq: 0, base: { nodes: [], edges: [] }, version: storedVersion, at }
|
|
80
|
+
: { seq, base: stored, version: storedVersion, at };
|
|
81
|
+
}
|
|
82
|
+
if (epoch) {
|
|
83
|
+
epochs.push(epoch);
|
|
84
|
+
await adapter.saveEpochs?.(scope, epochs);
|
|
85
|
+
}
|
|
35
86
|
/*
|
|
36
87
|
* The store REOPENS WITH ITS HISTORY. The snapshot is the graph; the
|
|
37
88
|
* persisted log (plus the migration run just appended) is how it got
|
|
@@ -48,7 +99,8 @@ export async function openStore(options) {
|
|
|
48
99
|
* A supplied `ids` still wins.
|
|
49
100
|
*/
|
|
50
101
|
const taken = new Set(history.map((op) => op.id));
|
|
51
|
-
|
|
102
|
+
// Counting the archived ops too (FR-23): their ids are not here to collide with, but they are taken.
|
|
103
|
+
let n = horizon + history.length;
|
|
52
104
|
const ids = () => {
|
|
53
105
|
let id = `op${++n}`;
|
|
54
106
|
while (taken.has(id))
|
|
@@ -56,6 +108,9 @@ export async function openStore(options) {
|
|
|
56
108
|
taken.add(id);
|
|
57
109
|
return id;
|
|
58
110
|
};
|
|
111
|
+
/* A starting set given here is the host's word too, and is recorded below rather than assumed. */
|
|
112
|
+
const storeOptions = { ...(options.storeOptions ?? {}) };
|
|
113
|
+
delete storeOptions.enabledModules;
|
|
59
114
|
const store = new Store({
|
|
60
115
|
schema: app.schema,
|
|
61
116
|
mutations: app.mutations ?? [],
|
|
@@ -67,21 +122,48 @@ export async function openStore(options) {
|
|
|
67
122
|
...(app.intelligence ? { intelligence: app.intelligence } : {}),
|
|
68
123
|
snapshot,
|
|
69
124
|
log: history,
|
|
125
|
+
epochs,
|
|
70
126
|
ids,
|
|
71
127
|
// A stored history is read back later, so its timestamps are real ones.
|
|
72
128
|
now: () => new Date().toISOString(),
|
|
73
|
-
...
|
|
129
|
+
...storeOptions,
|
|
74
130
|
});
|
|
75
131
|
/*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
132
|
+
* A STORE OPENED TO VERIFY PROVES ITS GRAPH AGAINST ITS LOG (FR-20). A
|
|
133
|
+
* drifted snapshot — a write that landed without its ops, an edit by hand
|
|
134
|
+
* — is replaced by what the log folds to, which is the record, and the
|
|
135
|
+
* opening says what it did. A log that does not fold is not a record to
|
|
136
|
+
* rebuild from: nothing is replaced, and the open refuses.
|
|
137
|
+
*/
|
|
138
|
+
const verified = options.verify ? store.verify() : undefined;
|
|
139
|
+
let rebuilt;
|
|
140
|
+
if (verified && !verified.ok) {
|
|
141
|
+
let folded;
|
|
142
|
+
try {
|
|
143
|
+
const from = store.log.lastEpoch();
|
|
144
|
+
folded = store.log.fold(app.schema, { validate: options.storeOptions?.validate ?? true, ...(from ? { from } : {}) }).snapshot();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
throw new Error(`graview ship: "${scope}" does not verify, and its log cannot be rebuilt from. ${verified.reason} Nothing was rebuilt.`);
|
|
148
|
+
}
|
|
149
|
+
store.graph.load(folded);
|
|
150
|
+
rebuilt = {
|
|
151
|
+
from: verified.actual,
|
|
152
|
+
to: verified.expected,
|
|
153
|
+
...(verified.divergedAfter !== undefined ? { divergedAfter: verified.divergedAfter } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/*
|
|
157
|
+
* Write at open only when opening CHANGED something — a fresh scope, a
|
|
158
|
+
* rebuild or a migration run. A store opens over records that no longer
|
|
159
|
+
* fit and holds them exactly as stored (FR-28); writing them straight back
|
|
160
|
+
* would only churn the file, and `store.findings()` is how a host hears
|
|
161
|
+
* about them.
|
|
80
162
|
*/
|
|
81
|
-
if (stored === null || migrated.length > 0) {
|
|
163
|
+
if (stored === null || migrated.length > 0 || rebuilt) {
|
|
82
164
|
await adapter.save(scope, store.snapshot());
|
|
83
165
|
}
|
|
84
|
-
adapter.saveMeta?.(scope, { version: target });
|
|
166
|
+
adapter.saveMeta?.(scope, { version: target, ...formatStamp() });
|
|
85
167
|
/*
|
|
86
168
|
* Writes are SERIALISED: a second diff's ops never land before the
|
|
87
169
|
* first's snapshot, and a failure is reported rather than swallowed —
|
|
@@ -98,6 +180,53 @@ export async function openStore(options) {
|
|
|
98
180
|
})
|
|
99
181
|
.catch(report);
|
|
100
182
|
});
|
|
101
|
-
|
|
183
|
+
/* The host's word on modules, recorded where it changes the log's (FR-12). */
|
|
184
|
+
const enabledModules = options.enabledModules ?? options.storeOptions?.enabledModules;
|
|
185
|
+
if (enabledModules !== undefined)
|
|
186
|
+
store.setEnabledModules(enabledModules);
|
|
187
|
+
// A full export of this store reads what a normal open did not load (FR-23).
|
|
188
|
+
const loadArchive = adapter.loadArchive?.bind(adapter);
|
|
189
|
+
if (loadArchive)
|
|
190
|
+
rememberArchive(store, () => loadArchive(scope));
|
|
191
|
+
return {
|
|
192
|
+
store,
|
|
193
|
+
migrated,
|
|
194
|
+
...(epoch ? { epoch } : {}),
|
|
195
|
+
...(verified ? { verified } : {}),
|
|
196
|
+
...(rebuilt ? { rebuilt } : {}),
|
|
197
|
+
flush: () => writing,
|
|
198
|
+
close: unsubscribe,
|
|
199
|
+
compact: (compactOptions) => {
|
|
200
|
+
/*
|
|
201
|
+
* On the write chain, after every write accepted so far, and ARCHIVE
|
|
202
|
+
* FIRST: the adapter moves what is behind the checkpoint before the
|
|
203
|
+
* store lets go of it, so a failed write leaves a whole log on disk
|
|
204
|
+
* and a whole log in memory, never an archive that is missing ops.
|
|
205
|
+
*/
|
|
206
|
+
const done = writing.then(async () => {
|
|
207
|
+
if (!adapter.compact || !adapter.loadArchive) {
|
|
208
|
+
throw new Error(`The ${adapter.name} adapter keeps no archive, so its log cannot be compacted behind an undo horizon. ` +
|
|
209
|
+
"It keeps no epochs either, and a checkpoint is one: compaction is for an adapter that keeps both, as the memory, file and SQL adapters do.");
|
|
210
|
+
}
|
|
211
|
+
const made = store.checkpoint(compactOptions);
|
|
212
|
+
if (!made)
|
|
213
|
+
return { horizon: store.log.horizon, archived: 0 };
|
|
214
|
+
await adapter.compact(scope, made);
|
|
215
|
+
const archived = store.compact(made);
|
|
216
|
+
return { horizon: store.log.horizon, archived: archived.ops.length, checkpoint: made };
|
|
217
|
+
});
|
|
218
|
+
writing = done.then(() => undefined, () => undefined);
|
|
219
|
+
return done;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** Whether a log with no epochs folds from empty to exactly what is stored. */
|
|
224
|
+
function foldsFromEmpty(schema, ops, stored) {
|
|
225
|
+
try {
|
|
226
|
+
return snapshotHash(OperationLog.from(ops).fold(schema).snapshot()) === snapshotHash(stored);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
102
231
|
}
|
|
103
232
|
//# sourceMappingURL=open-store.js.map
|
package/dist/open-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-store.js","sourceRoot":"","sources":["../src/open-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"open-store.js","sourceRoot":"","sources":["../src/open-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,GASN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA+GlD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,OAA4B;IAE5B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC;IAExC,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAyB,CAAC;IACnE,MAAM,SAAS,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,MAAM,GAAY,CAAC,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAClE;;;OAGG;IACH,MAAM,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,IAAI,GAAG,GAAG,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;IAErC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,CAA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C,IAAI,CAAC,IAAI;oBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;gBAC9D,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;YACzF,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,IAAI,CAAC,IAAI,CACjB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,SAAS,cAAc,CAAC,MAAiB,EAAE,GAAyB,EAAE,MAAqB;IACzF,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC;IAC/F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/remote.d.ts
CHANGED
|
@@ -1,30 +1,57 @@
|
|
|
1
|
-
import { Store, type AnySchema, type GraviewApp, type MutationCall, type Operation, type PresenceChannel, type Principal } from "@graview/core";
|
|
1
|
+
import { Store, type AnySchema, type FieldConflict, type GraviewApp, type MutationCall, type Operation, type PresenceChannel, type Principal, type Via, type WireRefusal } from "@graview/core";
|
|
2
|
+
import type { StorageLike } from "./browser-adapter.js";
|
|
2
3
|
/**
|
|
3
4
|
* THE OTHER END OF THE WIRE: a store whose graph lives on a server.
|
|
4
5
|
*
|
|
5
6
|
* The browser still holds a real `Store` — the scene, the strip, the rules
|
|
6
7
|
* and the routed face all read it the way they always have — but it does not
|
|
7
8
|
* own the truth. A call goes to the server, which judges it under this
|
|
8
|
-
* seat's principal and answers with the op it produced; the op
|
|
9
|
-
*
|
|
10
|
-
* updates exactly as it does for a local
|
|
9
|
+
* seat's principal and answers with the op it produced; the op lands here by
|
|
10
|
+
* `store.rebase`, under whatever is still pending, with its own id, author
|
|
11
|
+
* and sequence, and the interface updates exactly as it does for a local
|
|
12
|
+
* change.
|
|
11
13
|
*
|
|
12
|
-
* Everyone else's ops arrive the same way
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* Everyone else's ops arrive the same way: on a poll, or — `live: true` —
|
|
15
|
+
* pushed down a WebSocket the moment they land (FR-05). Two browsers open on
|
|
16
|
+
* the same roster see each other at once, and neither of them has a second
|
|
17
|
+
* way to write the graph.
|
|
18
|
+
*
|
|
19
|
+
* A call carries the revision of every field it changes, as this client
|
|
20
|
+
* last saw it (FR-05). One that somebody else changed meanwhile comes back
|
|
21
|
+
* as a conflict, naming the field, theirs and yours, and the person
|
|
22
|
+
* chooses: keep theirs, or send theirs over with `useMine`. Nothing is
|
|
23
|
+
* overwritten without anybody knowing.
|
|
15
24
|
*
|
|
16
25
|
* Undo is the interesting case and it needed no special handling: `undo`
|
|
17
26
|
* produces ordinary calls, and they go down the same wire and are judged by
|
|
18
27
|
* the same policy — what you may undo is what you may have done, decided on
|
|
19
28
|
* the server rather than trusted from the client.
|
|
20
29
|
*/
|
|
30
|
+
/** As much of a WebSocket as the live wire needs: the platform's own, or a host's or a test's. */
|
|
31
|
+
export interface LiveSocketLike {
|
|
32
|
+
readonly readyState: number;
|
|
33
|
+
send(data: string): void;
|
|
34
|
+
close(code?: number, reason?: string): void;
|
|
35
|
+
onopen: ((event: unknown) => void) | null;
|
|
36
|
+
onmessage: ((event: {
|
|
37
|
+
readonly data: unknown;
|
|
38
|
+
}) => void) | null;
|
|
39
|
+
onclose: ((event: {
|
|
40
|
+
readonly code: number;
|
|
41
|
+
readonly reason: string;
|
|
42
|
+
}) => void) | null;
|
|
43
|
+
onerror: ((event: unknown) => void) | null;
|
|
44
|
+
}
|
|
21
45
|
export interface RemoteOptions<S extends AnySchema> {
|
|
22
46
|
readonly app: GraviewApp<S>;
|
|
23
47
|
/** Where the server is: `http://localhost:5196`, say. */
|
|
24
48
|
readonly url: string;
|
|
25
49
|
/** Who is at this keyboard. Sent with every call; the server judges by it. */
|
|
26
50
|
readonly principal?: Principal;
|
|
27
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* How often to ask for everybody else's ops, in milliseconds. 0 never asks.
|
|
53
|
+
* A live client polls only while its socket is down.
|
|
54
|
+
*/
|
|
28
55
|
readonly pollMs?: number;
|
|
29
56
|
readonly fetch?: typeof fetch;
|
|
30
57
|
readonly storeOptions?: Record<string, unknown>;
|
|
@@ -35,6 +62,125 @@ export interface RemoteOptions<S extends AnySchema> {
|
|
|
35
62
|
* where a hosted store's own auth goes without the framework knowing it.
|
|
36
63
|
*/
|
|
37
64
|
readonly headers?: Readonly<Record<string, string>>;
|
|
65
|
+
/**
|
|
66
|
+
* What the calls come through: `web` unless said (FR-06). Sent as
|
|
67
|
+
* `SEAT_HEADERS.via`, which a server believes exactly where it believes
|
|
68
|
+
* the seat headers; a server that asks its own `seatOf` says the channel
|
|
69
|
+
* itself (FR-52).
|
|
70
|
+
*/
|
|
71
|
+
readonly via?: Via;
|
|
72
|
+
/**
|
|
73
|
+
* THE LIVE WIRE (FR-05): hold a WebSocket to the server's `LIVE_PATH`,
|
|
74
|
+
* and have every op pushed down it as it lands. Calls go down it too.
|
|
75
|
+
* While it is down, the client polls and posts as it would without it,
|
|
76
|
+
* and reconnects, catching up from the last op it has.
|
|
77
|
+
*/
|
|
78
|
+
readonly live?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* How to open the socket: the platform's `WebSocket` by default, with the
|
|
81
|
+
* headers where the runtime can send them (Node 22 can; a page cannot,
|
|
82
|
+
* and its seat rides in the query, which only a store trusting seat
|
|
83
|
+
* headers reads).
|
|
84
|
+
*/
|
|
85
|
+
readonly socket?: (url: string, headers: Readonly<Record<string, string>>, protocols: readonly string[]) => LiveSocketLike;
|
|
86
|
+
/**
|
|
87
|
+
* ASK FOR SHIP'S CODEC BY NAME (FR-44): the platform socket sends
|
|
88
|
+
* `LIVE_SUBPROTOCOL` as its WebSocket subprotocol. Off by default,
|
|
89
|
+
* because a browser fails the handshake with a server that does not
|
|
90
|
+
* answer it; `serveStore` answers it, and a Worker answers it with
|
|
91
|
+
* `liveSubprotocol(request)`. A `socket` factory is handed the same
|
|
92
|
+
* list and decides itself. `hello.wire` names the codec either way.
|
|
93
|
+
*/
|
|
94
|
+
readonly subprotocol?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* THE DECLARATION A VERSION NAMES (FR-43). Told `{ t: "declaration" }`,
|
|
97
|
+
* or welcomed on a version other than the one it opened on, the client
|
|
98
|
+
* asks this for the app at the server's version and opens again on it:
|
|
99
|
+
* `onDeclaration` hands over the new remote store, and the calls still
|
|
100
|
+
* on the way are offered again under it, or refused in words. The host
|
|
101
|
+
* says how: a TS app imports its next declaration, a document-declared
|
|
102
|
+
* app fetches and compiles its document. Absent, the client reloads the
|
|
103
|
+
* page as `reload` does, carrying what it had not sent.
|
|
104
|
+
*/
|
|
105
|
+
readonly resolveApp?: (version: number) => GraviewApp<AnySchema> | Promise<GraviewApp<AnySchema>>;
|
|
106
|
+
/**
|
|
107
|
+
* THE HOST'S BUILD THIS PAGE RUNS (FR-44), an opaque string said in
|
|
108
|
+
* `hello`. A server on another build keeps serving it; `onBuild` is told
|
|
109
|
+
* once, so the page can offer a reload when it suits the person.
|
|
110
|
+
*/
|
|
111
|
+
readonly build?: string;
|
|
112
|
+
/**
|
|
113
|
+
* WHERE UNSENT CALLS WAIT ACROSS A RELOAD (FR-44). When the server
|
|
114
|
+
* answers `reload`, every call not yet answered is written to `storage`
|
|
115
|
+
* under `key`, and the next `openRemote` with the same key offers them
|
|
116
|
+
* again once it is open. `sessionStorage` in a page, a `Map` in a test.
|
|
117
|
+
* Without it they are refused in words before the page reloads.
|
|
118
|
+
*/
|
|
119
|
+
readonly carry?: {
|
|
120
|
+
readonly storage: StorageLike;
|
|
121
|
+
readonly key: string;
|
|
122
|
+
};
|
|
123
|
+
/** How to reload the page when the server asks: `location.reload()` in a page by default. */
|
|
124
|
+
readonly reloadPage?: () => void;
|
|
125
|
+
/** How long `openRemote({ live: true })` waits for the socket's welcome before it opens polling. 3000 by default. */
|
|
126
|
+
readonly openTimeoutMs?: number;
|
|
127
|
+
/**
|
|
128
|
+
* The modules on, for a server that does not say (FR-12). The server's
|
|
129
|
+
* word wins: its state names the set it serves, and an op of its that
|
|
130
|
+
* turns one off or on reaches this client like any other.
|
|
131
|
+
*/
|
|
132
|
+
readonly enabledModules?: readonly string[];
|
|
133
|
+
/**
|
|
134
|
+
* How long to wait before each attempt to open the socket again (FR-49):
|
|
135
|
+
* a function of the attempt (0 first, reset once a socket is welcomed)
|
|
136
|
+
* that answers in milliseconds, or `{ min, max, factor }` for the
|
|
137
|
+
* jittered exponential default — `min * factor ** attempt`, at most
|
|
138
|
+
* `max`, give or take a quarter. 250, 10000 and 2 unless said.
|
|
139
|
+
*/
|
|
140
|
+
readonly backoff?: RemoteBackoff;
|
|
141
|
+
/**
|
|
142
|
+
* How often the same presence is said again down the socket, in
|
|
143
|
+
* milliseconds (FR-49). A new place is said at once; an unchanged one, on
|
|
144
|
+
* the heartbeat, no oftener than this. Half of `PRESENCE_TTL_MS` unless
|
|
145
|
+
* said. A polling client says it with every poll, so `pollMs` paces it.
|
|
146
|
+
*/
|
|
147
|
+
readonly presenceEveryMs?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Whether anybody is looking (FR-49). While it answers false, this
|
|
150
|
+
* client's presence is not said — on the socket or the poll — and lapses
|
|
151
|
+
* where others see it. In a page it is `document.visibilityState` unless
|
|
152
|
+
* said; where there is no document, always true.
|
|
153
|
+
*/
|
|
154
|
+
readonly visible?: () => boolean;
|
|
155
|
+
}
|
|
156
|
+
/** How a client is reaching its server now (FR-49): not yet, yes, or not at the moment. */
|
|
157
|
+
export type RemoteStatus = "connecting" | "online" | "offline";
|
|
158
|
+
/** What happened to a client since it opened, as counts for a host's beacon (FR-49). */
|
|
159
|
+
export interface RemoteCounters {
|
|
160
|
+
/** Times it was offline and came back online. */
|
|
161
|
+
readonly reconnects: number;
|
|
162
|
+
/** Times the server's ops landed under calls of this client's still pending. */
|
|
163
|
+
readonly rebases: number;
|
|
164
|
+
/** Stale writes: calls of this client's refused because a field moved since it last saw it. */
|
|
165
|
+
readonly conflicts: number;
|
|
166
|
+
/** Times it could not catch up and took the server's whole state (FR-53). */
|
|
167
|
+
readonly resyncs: number;
|
|
168
|
+
}
|
|
169
|
+
/** A reconnect delay (FR-49): the attempt's own, in ms, or the bounds of the jittered default. */
|
|
170
|
+
export type RemoteBackoff = ((attempt: number) => number) | {
|
|
171
|
+
readonly min?: number;
|
|
172
|
+
readonly max?: number;
|
|
173
|
+
readonly factor?: number;
|
|
174
|
+
};
|
|
175
|
+
/** A stale write, as this client is told of it: the fields that moved, and the person's two answers. */
|
|
176
|
+
export interface RemoteConflict {
|
|
177
|
+
/** In words: "Ana changed label to “Book the church hall” while you were editing; yours was …" */
|
|
178
|
+
readonly sentence: string;
|
|
179
|
+
readonly conflicts: readonly FieldConflict[];
|
|
180
|
+
/** Leave it as they made it. Nothing more is sent. */
|
|
181
|
+
keepTheirs(): void;
|
|
182
|
+
/** Make the same change again, over theirs: the calls are applied and sent again without the old revisions. */
|
|
183
|
+
useMine(): void;
|
|
38
184
|
}
|
|
39
185
|
export interface RemoteStore<S extends AnySchema> {
|
|
40
186
|
readonly store: Store<S>;
|
|
@@ -51,9 +197,54 @@ export interface RemoteStore<S extends AnySchema> {
|
|
|
51
197
|
/**
|
|
52
198
|
* Told when the server refused something this browser had already shown.
|
|
53
199
|
* The change is taken back before the listener runs; what is left is
|
|
54
|
-
* saying so, in the policy's own words.
|
|
200
|
+
* saying so, in the policy's own words. A conflict nobody listens for
|
|
201
|
+
* with `onConflict` is told here too, in its sentence.
|
|
202
|
+
*
|
|
203
|
+
* The second argument says why as a code a program can branch on
|
|
204
|
+
* (FR-46): `forbidden`, `missing`, `invalid` or `limit`, with `wouldNeed`
|
|
205
|
+
* when the policy knows who could. Busy is never told here: a change the
|
|
206
|
+
* host asked to wait is kept, and sent again (FR-45).
|
|
207
|
+
*/
|
|
208
|
+
onRefusal(listener: (sentence: string, refusal: RemoteRefusal) => void): () => void;
|
|
209
|
+
/**
|
|
210
|
+
* Told when a change this browser had already shown was refused as a
|
|
211
|
+
* stale write (FR-05): somebody changed a field it changes since this
|
|
212
|
+
* browser last saw it. The change is taken back first — theirs stands —
|
|
213
|
+
* and the listener is handed the way to put yours over it.
|
|
214
|
+
*/
|
|
215
|
+
onConflict(listener: (conflict: RemoteConflict) => void): () => void;
|
|
216
|
+
/** The revision this client knows a field at: the seq of the op that last wrote it, or -1. */
|
|
217
|
+
revision(node: string, field: string): number;
|
|
218
|
+
/** The last op of the server's this client has. */
|
|
219
|
+
seq(): number;
|
|
220
|
+
/**
|
|
221
|
+
* THIS CLIENT'S OWN KEY in who is here, as the server built it from the
|
|
222
|
+
* seat (FR-47): said in the socket's welcome, or in the answer to a poll's
|
|
223
|
+
* `here`. Undefined until one of them has, or from a server before it.
|
|
224
|
+
* Who is here, as `presence` tells it, never includes it.
|
|
225
|
+
*/
|
|
226
|
+
participant(): string | undefined;
|
|
227
|
+
/** How everybody else's ops reach this client now: pushed down the socket, or on the poll. */
|
|
228
|
+
transport(): "socket" | "poll";
|
|
229
|
+
/**
|
|
230
|
+
* Whether the server is being reached (FR-49). `online` once a welcome or
|
|
231
|
+
* an answer has landed; `offline` while a socket that was welcomed is down
|
|
232
|
+
* and nothing has been heard since, or when a poll or a call does not
|
|
233
|
+
* reach the server. A live client is `connecting` until its socket is
|
|
234
|
+
* welcomed or its first poll lands. An answer that refuses is an answer:
|
|
235
|
+
* the server was reached.
|
|
55
236
|
*/
|
|
56
|
-
|
|
237
|
+
status(): RemoteStatus;
|
|
238
|
+
/** Told each time the status changes — the offline banner's switch. Returns the way to stop listening. */
|
|
239
|
+
onStatus(listener: (status: RemoteStatus) => void): () => void;
|
|
240
|
+
/** How often this client reconnected, rebased, met a conflict and resynced — counts only. */
|
|
241
|
+
counters(): RemoteCounters;
|
|
242
|
+
/**
|
|
243
|
+
* The calls sent and not yet answered: shown here and waiting for the
|
|
244
|
+
* server's verdict. A call made while the server cannot be reached counts
|
|
245
|
+
* here until it is back and has answered; it is not taken back meanwhile.
|
|
246
|
+
*/
|
|
247
|
+
pending(): number;
|
|
57
248
|
/**
|
|
58
249
|
* Resolves once every call sent so far has been answered — accepted and
|
|
59
250
|
* landed, or refused and taken back. A browser never waits for this; a
|
|
@@ -62,12 +253,45 @@ export interface RemoteStore<S extends AnySchema> {
|
|
|
62
253
|
*/
|
|
63
254
|
settled(): Promise<void>;
|
|
64
255
|
/**
|
|
65
|
-
* WHO IS HERE, over the same poll. Saying where you are
|
|
66
|
-
* heartbeat and the answer carries everybody else — no
|
|
67
|
-
* own, nothing written to the store, the adapter or
|
|
256
|
+
* WHO IS HERE, over the same poll — or the socket. Saying where you are
|
|
257
|
+
* rides on the next heartbeat and the answer carries everybody else — no
|
|
258
|
+
* round trip of its own, nothing written to the store, the adapter or
|
|
259
|
+
* the log.
|
|
68
260
|
*/
|
|
69
261
|
readonly presence: PresenceChannel;
|
|
262
|
+
/**
|
|
263
|
+
* THE DECLARATION CHANGED ON THE SERVER (FR-43): handed a new remote
|
|
264
|
+
* store, opened on the server's migrated state under the app
|
|
265
|
+
* `resolveApp` gave for `version`, with this one's unanswered calls
|
|
266
|
+
* offered again on it. This one is closed: mount the new one. A call
|
|
267
|
+
* that no longer fits is told on the new store's `onRefusal` (or this
|
|
268
|
+
* one's, when nobody listens there), in words.
|
|
269
|
+
*/
|
|
270
|
+
onDeclaration(listener: (next: RemoteStore<AnySchema>, version: number) => void): () => void;
|
|
271
|
+
/**
|
|
272
|
+
* THE SERVER RUNS ANOTHER BUILD (FR-44): told once, with its build, when
|
|
273
|
+
* its welcome names one other than `build`. A listener added after it
|
|
274
|
+
* was noticed is told at once. The client keeps working.
|
|
275
|
+
*/
|
|
276
|
+
onBuild(listener: (build: string) => void): () => void;
|
|
70
277
|
close(): void;
|
|
71
278
|
}
|
|
279
|
+
/** A refusal as the client is told it: the reason, the sentence and who could (FR-46). */
|
|
280
|
+
export type RemoteRefusal = WireRefusal;
|
|
281
|
+
/**
|
|
282
|
+
* WHAT `send` THROWS, AND WHAT A TAKEN-BACK CHANGE WAS REFUSED WITH: the
|
|
283
|
+
* server's sentence as the message, and `refusal` for a program to branch
|
|
284
|
+
* on (FR-46).
|
|
285
|
+
*/
|
|
286
|
+
export declare class RemoteRefusedError extends Error {
|
|
287
|
+
readonly refusal: RemoteRefusal;
|
|
288
|
+
constructor(refusal: RemoteRefusal);
|
|
289
|
+
}
|
|
72
290
|
export declare function openRemote<S extends AnySchema>(options: RemoteOptions<S>): Promise<RemoteStore<S>>;
|
|
291
|
+
/**
|
|
292
|
+
* A principal as the headers a TRUSTED server reads (`trustSeatHeaders`):
|
|
293
|
+
* who, as what, by what name, and for whom. A server that does not trust
|
|
294
|
+
* headers ignores every one of them and asks its own `seatOf`.
|
|
295
|
+
*/
|
|
296
|
+
export declare function seatHeaders(principal: Principal | undefined): Record<string, string>;
|
|
73
297
|
//# sourceMappingURL=remote.d.ts.map
|
package/dist/remote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,EAGL,KAAK,SAAS,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