@inflatable-cookie/longhorn 0.4.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +77 -105
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import { ForkHistoryClient } from "./client.ts";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
FORK_HISTORY_PROTOCOL_VERSION,
|
|
4
|
+
MAXIMUM_FORK_HISTORY_PAGE_SIZE,
|
|
5
|
+
} from "./generated/protocol.ts";
|
|
6
|
+
import type {
|
|
7
|
+
ForkBranchId,
|
|
8
|
+
ForkBranchPageSnapshot,
|
|
9
|
+
ForkChangedEvent,
|
|
10
|
+
ForkContinuationPageSnapshot,
|
|
11
|
+
ForkEntryRecord,
|
|
12
|
+
ForkPruneResult,
|
|
13
|
+
ForkRemovalReceiptProjection,
|
|
14
|
+
ForkNavigationResult,
|
|
15
|
+
ForkNavigationTargetProjection,
|
|
16
|
+
ForkPathPageSnapshot,
|
|
17
|
+
ForkPathTargetProjection,
|
|
18
|
+
ForkSnapshot,
|
|
19
|
+
} from "./generated/protocol.ts";
|
|
3
20
|
import type { ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
|
|
4
21
|
|
|
5
|
-
export type ForkHistoryControllerStatus =
|
|
6
|
-
|
|
22
|
+
export type ForkHistoryControllerStatus =
|
|
23
|
+
| { readonly kind: "idle" }
|
|
24
|
+
| { readonly kind: "loading" }
|
|
25
|
+
| { readonly kind: "ready" }
|
|
26
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
27
|
+
export interface ForkHistoryControllerOptions {
|
|
28
|
+
readonly port: ForkHistoryPort;
|
|
29
|
+
readonly pathPageSize?: number;
|
|
30
|
+
readonly branchPageSize?: number;
|
|
31
|
+
readonly continuationPageSize?: number;
|
|
32
|
+
}
|
|
7
33
|
|
|
8
34
|
export class ForkHistoryController {
|
|
9
35
|
readonly #client: ForkHistoryClient;
|
|
@@ -12,46 +38,92 @@ export class ForkHistoryController {
|
|
|
12
38
|
readonly #branchPageSize: number;
|
|
13
39
|
readonly #continuationPageSize: number;
|
|
14
40
|
#status: ForkHistoryControllerStatus = { kind: "idle" };
|
|
15
|
-
#snapshot
|
|
16
|
-
#path
|
|
17
|
-
#branches
|
|
41
|
+
#snapshot: ForkSnapshot | undefined;
|
|
42
|
+
#path: ForkPathPageSnapshot | undefined;
|
|
43
|
+
#branches: ForkBranchPageSnapshot | undefined;
|
|
18
44
|
#pathTarget: ForkPathTargetProjection = { kind: "default" };
|
|
19
45
|
#started = false;
|
|
20
46
|
#lifecycle = 0;
|
|
21
47
|
#load = 0;
|
|
22
48
|
#navigation = 0;
|
|
23
49
|
#pending = false;
|
|
24
|
-
#unlisten: ForkHistoryUnlisten
|
|
50
|
+
#unlisten: Array<ForkHistoryUnlisten> = [];
|
|
25
51
|
|
|
26
|
-
constructor(options: ForkHistoryControllerOptions) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
get
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
52
|
+
constructor(options: ForkHistoryControllerOptions) {
|
|
53
|
+
this.#client = new ForkHistoryClient(options.port);
|
|
54
|
+
this.#pathPageSize = pageSize(options.pathPageSize ?? 50);
|
|
55
|
+
this.#branchPageSize = pageSize(options.branchPageSize ?? 50);
|
|
56
|
+
this.#continuationPageSize = pageSize(options.continuationPageSize ?? 50);
|
|
57
|
+
}
|
|
58
|
+
get status() {
|
|
59
|
+
return this.#status;
|
|
60
|
+
}
|
|
61
|
+
get snapshot() {
|
|
62
|
+
return this.#snapshot;
|
|
63
|
+
}
|
|
64
|
+
get path() {
|
|
65
|
+
return this.#path;
|
|
66
|
+
}
|
|
67
|
+
get branches() {
|
|
68
|
+
return this.#branches;
|
|
69
|
+
}
|
|
70
|
+
get entries(): ReadonlyArray<ForkEntryRecord> {
|
|
71
|
+
return this.#path?.entries ?? [];
|
|
72
|
+
}
|
|
73
|
+
get navigationPending() {
|
|
74
|
+
return this.#pending;
|
|
75
|
+
}
|
|
76
|
+
get canUndo() {
|
|
77
|
+
return (this.#snapshot?.summary.undoDepth ?? 0) > 0;
|
|
78
|
+
}
|
|
79
|
+
get canRedo() {
|
|
80
|
+
return (this.#snapshot?.summary.redoDepth ?? 0) > 0;
|
|
81
|
+
}
|
|
82
|
+
observe(observer: () => void): () => void {
|
|
83
|
+
this.#observers.add(observer);
|
|
84
|
+
return () => this.#observers.delete(observer);
|
|
85
|
+
}
|
|
36
86
|
|
|
37
87
|
async start(): Promise<void> {
|
|
38
|
-
if (this.#started)
|
|
39
|
-
|
|
88
|
+
if (this.#started) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.#started = true;
|
|
92
|
+
const lifecycle = ++this.#lifecycle;
|
|
93
|
+
this.#setStatus({ kind: "loading" });
|
|
40
94
|
try {
|
|
41
95
|
const unlisten = await this.#client.listen((event) => this.#changed(event));
|
|
42
|
-
if (!this.#started || lifecycle !== this.#lifecycle) {
|
|
43
|
-
|
|
44
|
-
|
|
96
|
+
if (!this.#started || lifecycle !== this.#lifecycle) {
|
|
97
|
+
await unlisten();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.#unlisten.push(unlisten);
|
|
101
|
+
await this.refresh();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (this.#started && lifecycle === this.#lifecycle) {
|
|
104
|
+
this.#setStatus({ kind: "failed", error });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
45
107
|
}
|
|
46
108
|
|
|
47
109
|
async stop(): Promise<void> {
|
|
48
|
-
this.#started = false;
|
|
110
|
+
this.#started = false;
|
|
111
|
+
this.#lifecycle += 1;
|
|
112
|
+
this.#load += 1;
|
|
113
|
+
this.#navigation += 1;
|
|
49
114
|
await Promise.allSettled(this.#unlisten.splice(0).map((dispose) => dispose()));
|
|
50
|
-
this.#snapshot = undefined;
|
|
115
|
+
this.#snapshot = undefined;
|
|
116
|
+
this.#path = undefined;
|
|
117
|
+
this.#branches = undefined;
|
|
118
|
+
this.#pathTarget = { kind: "default" };
|
|
119
|
+
this.#pending = false;
|
|
120
|
+
this.#setStatus({ kind: "idle" });
|
|
51
121
|
}
|
|
52
122
|
|
|
53
123
|
async refresh(): Promise<void> {
|
|
54
|
-
if (!this.#started)
|
|
124
|
+
if (!this.#started) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
55
127
|
const load = ++this.#load;
|
|
56
128
|
// The offset a consumer had paged to, so a refresh returns the page they
|
|
57
129
|
// were looking at rather than sending them back to the first one.
|
|
@@ -60,25 +132,41 @@ export class ForkHistoryController {
|
|
|
60
132
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
61
133
|
const snapshot = await this.#client.snapshot();
|
|
62
134
|
const path = await this.#client.path(this.#pathCommand(snapshot, this.#pathTarget));
|
|
63
|
-
if (!same(snapshot, path))
|
|
135
|
+
if (!same(snapshot, path)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
64
138
|
// Only for a consumer that asked for branches. Loading a page nobody
|
|
65
139
|
// wanted would make every refresh pay for a projection it will not use.
|
|
66
|
-
const branches =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
140
|
+
const branches =
|
|
141
|
+
branchOffset === undefined
|
|
142
|
+
? undefined
|
|
143
|
+
: await this.#client.branches(this.#branchCommand(snapshot, branchOffset));
|
|
144
|
+
if (branches !== undefined && !same(snapshot, branches)) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (this.#started && load === this.#load) {
|
|
148
|
+
this.#install(snapshot, path, branches);
|
|
149
|
+
this.#setStatus({ kind: "ready" });
|
|
150
|
+
}
|
|
71
151
|
return;
|
|
72
152
|
}
|
|
73
153
|
throw new ForkHistoryProjectionGapError();
|
|
74
|
-
} catch (error) {
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (this.#started && load === this.#load) {
|
|
156
|
+
this.#setStatus({ kind: "failed", error });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
75
159
|
}
|
|
76
160
|
|
|
77
161
|
async loadBranches(offset = 0): Promise<ForkBranchPageSnapshot> {
|
|
78
162
|
const snapshot = this.#required();
|
|
79
163
|
const value = await this.#client.branches(this.#branchCommand(snapshot, offset));
|
|
80
|
-
if (!same(snapshot, value))
|
|
81
|
-
|
|
164
|
+
if (!same(snapshot, value)) {
|
|
165
|
+
throw new ForkHistoryProjectionGapError();
|
|
166
|
+
}
|
|
167
|
+
this.#branches = value;
|
|
168
|
+
this.#notify();
|
|
169
|
+
return value;
|
|
82
170
|
}
|
|
83
171
|
|
|
84
172
|
/**
|
|
@@ -91,10 +179,23 @@ export class ForkHistoryController {
|
|
|
91
179
|
* Not cached and not refreshed. A consumer asks when the operator opens an
|
|
92
180
|
* entry, and the revision check below tells them if it went stale meanwhile.
|
|
93
181
|
*/
|
|
94
|
-
async loadContinuations(
|
|
182
|
+
async loadContinuations(
|
|
183
|
+
anchorEntryId: string | null,
|
|
184
|
+
offset = 0,
|
|
185
|
+
): Promise<ForkContinuationPageSnapshot> {
|
|
95
186
|
const snapshot = this.#required();
|
|
96
|
-
const value = await this.#client.continuations({
|
|
97
|
-
|
|
187
|
+
const value = await this.#client.continuations({
|
|
188
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
189
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
190
|
+
historyId: snapshot.summary.historyId,
|
|
191
|
+
expectedRevision: snapshot.summary.revision,
|
|
192
|
+
anchorEntryId,
|
|
193
|
+
offset,
|
|
194
|
+
limit: this.#continuationPageSize,
|
|
195
|
+
});
|
|
196
|
+
if (!same(snapshot, value)) {
|
|
197
|
+
throw new ForkHistoryProjectionGapError();
|
|
198
|
+
}
|
|
98
199
|
return value;
|
|
99
200
|
}
|
|
100
201
|
|
|
@@ -104,8 +205,13 @@ export class ForkHistoryController {
|
|
|
104
205
|
*/
|
|
105
206
|
async loadContinuationRun(fromEntryId: string, offset = 0): Promise<ForkPathPageSnapshot> {
|
|
106
207
|
const snapshot = this.#required();
|
|
107
|
-
const value = await this.#client.path({
|
|
108
|
-
|
|
208
|
+
const value = await this.#client.path({
|
|
209
|
+
...this.#pathCommand(snapshot, { kind: "continuation", fromEntryId }),
|
|
210
|
+
offset,
|
|
211
|
+
});
|
|
212
|
+
if (!same(snapshot, value)) {
|
|
213
|
+
throw new ForkHistoryProjectionGapError();
|
|
214
|
+
}
|
|
109
215
|
return value;
|
|
110
216
|
}
|
|
111
217
|
|
|
@@ -121,7 +227,13 @@ export class ForkHistoryController {
|
|
|
121
227
|
*/
|
|
122
228
|
async deleteContinuation(entryId: string): Promise<ForkRemovalReceiptProjection> {
|
|
123
229
|
const snapshot = this.#required();
|
|
124
|
-
const receipt = await this.#client.deleteContinuation({
|
|
230
|
+
const receipt = await this.#client.deleteContinuation({
|
|
231
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
232
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
233
|
+
historyId: snapshot.summary.historyId,
|
|
234
|
+
expectedRevision: snapshot.summary.revision,
|
|
235
|
+
entryId,
|
|
236
|
+
});
|
|
125
237
|
// Every page the consumer holds may name entries that no longer exist, so
|
|
126
238
|
// this refresh is not optional and is not left to the changed event.
|
|
127
239
|
await this.refresh();
|
|
@@ -142,18 +254,41 @@ export class ForkHistoryController {
|
|
|
142
254
|
*/
|
|
143
255
|
async prune(maximumEntries: number, maximumEncodedWeight: number): Promise<ForkPruneResult> {
|
|
144
256
|
const snapshot = this.#required();
|
|
145
|
-
const result = await this.#client.prune({
|
|
146
|
-
|
|
257
|
+
const result = await this.#client.prune({
|
|
258
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
259
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
260
|
+
historyId: snapshot.summary.historyId,
|
|
261
|
+
expectedRevision: snapshot.summary.revision,
|
|
262
|
+
maximumEntries,
|
|
263
|
+
maximumEncodedWeight,
|
|
264
|
+
});
|
|
265
|
+
if (result.status === "pruned") {
|
|
266
|
+
await this.refresh();
|
|
267
|
+
}
|
|
147
268
|
return result;
|
|
148
269
|
}
|
|
149
270
|
|
|
150
|
-
async selectDefaultPath(): Promise<void> {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
271
|
+
async selectDefaultPath(): Promise<void> {
|
|
272
|
+
this.#pathTarget = { kind: "default" };
|
|
273
|
+
await this.refresh();
|
|
274
|
+
}
|
|
275
|
+
async selectBranchPath(branchId: ForkBranchId): Promise<void> {
|
|
276
|
+
this.#pathTarget = { kind: "branch", branchId };
|
|
277
|
+
await this.refresh();
|
|
278
|
+
}
|
|
279
|
+
undo(): Promise<ForkNavigationResult> {
|
|
280
|
+
return this.#navigate({ kind: "undo" });
|
|
281
|
+
}
|
|
282
|
+
redo(): Promise<ForkNavigationResult> {
|
|
283
|
+
return this.#navigate({ kind: "redo" });
|
|
284
|
+
}
|
|
285
|
+
checkout(branchId: ForkBranchId, entryId: string): Promise<ForkNavigationResult> {
|
|
286
|
+
return this.#navigate({ kind: "checkout", branchId, entryId });
|
|
287
|
+
}
|
|
155
288
|
/** Move to a branch's root, the position before its first entry. */
|
|
156
|
-
checkoutBranchRoot(branchId: ForkBranchId): Promise<ForkNavigationResult> {
|
|
289
|
+
checkoutBranchRoot(branchId: ForkBranchId): Promise<ForkNavigationResult> {
|
|
290
|
+
return this.#navigate({ kind: "checkoutBranchRoot", branchId });
|
|
291
|
+
}
|
|
157
292
|
/**
|
|
158
293
|
* Check out the run beginning at one entry: it becomes the current line,
|
|
159
294
|
* and the previous line becomes a fork at the same entry. No delta of it is
|
|
@@ -163,37 +298,145 @@ export class ForkHistoryController {
|
|
|
163
298
|
* This commits. Browsing the forks does not — use `loadContinuationRun` to
|
|
164
299
|
* show a fork's entries without choosing it.
|
|
165
300
|
*/
|
|
166
|
-
checkoutContinuation(entryId: string): Promise<ForkNavigationResult> {
|
|
301
|
+
checkoutContinuation(entryId: string): Promise<ForkNavigationResult> {
|
|
302
|
+
return this.#navigate({ kind: "checkoutContinuation", entryId });
|
|
303
|
+
}
|
|
167
304
|
|
|
168
305
|
async #navigate(target: ForkNavigationTargetProjection): Promise<ForkNavigationResult> {
|
|
169
|
-
const snapshot = this.#required();
|
|
306
|
+
const snapshot = this.#required();
|
|
307
|
+
const navigation = ++this.#navigation;
|
|
308
|
+
this.#pending = true;
|
|
309
|
+
this.#notify();
|
|
170
310
|
try {
|
|
171
|
-
const result = await this.#client.navigate({
|
|
172
|
-
|
|
311
|
+
const result = await this.#client.navigate({
|
|
312
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
313
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
314
|
+
historyId: snapshot.summary.historyId,
|
|
315
|
+
planId: this.#client.nextPlanId(),
|
|
316
|
+
expectedRevision: snapshot.summary.revision,
|
|
317
|
+
target,
|
|
318
|
+
});
|
|
319
|
+
if (!this.#started || navigation !== this.#navigation) {
|
|
320
|
+
throw new ForkHistoryLateResultError();
|
|
321
|
+
}
|
|
173
322
|
const path = await this.#client.path(this.#pathCommand(result.snapshot, this.#pathTarget));
|
|
174
|
-
if (!this.#started || navigation !== this.#navigation)
|
|
175
|
-
|
|
323
|
+
if (!this.#started || navigation !== this.#navigation) {
|
|
324
|
+
throw new ForkHistoryLateResultError();
|
|
325
|
+
}
|
|
326
|
+
if (!same(result.snapshot, path)) {
|
|
327
|
+
throw new ForkHistoryProjectionGapError();
|
|
328
|
+
}
|
|
176
329
|
const branchOffset = this.#branches?.offset;
|
|
177
|
-
const branches =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
330
|
+
const branches =
|
|
331
|
+
branchOffset === undefined
|
|
332
|
+
? undefined
|
|
333
|
+
: await this.#client.branches(this.#branchCommand(result.snapshot, branchOffset));
|
|
334
|
+
if (!this.#started || navigation !== this.#navigation) {
|
|
335
|
+
throw new ForkHistoryLateResultError();
|
|
336
|
+
}
|
|
337
|
+
if (branches !== undefined && !same(result.snapshot, branches)) {
|
|
338
|
+
throw new ForkHistoryProjectionGapError();
|
|
339
|
+
}
|
|
340
|
+
this.#install(result.snapshot, path, branches);
|
|
341
|
+
this.#setStatus({ kind: "ready" });
|
|
342
|
+
return result;
|
|
343
|
+
} finally {
|
|
344
|
+
if (navigation === this.#navigation) {
|
|
345
|
+
this.#pending = false;
|
|
346
|
+
this.#notify();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
184
349
|
}
|
|
185
350
|
|
|
186
|
-
#pathCommand(snapshot: ForkSnapshot, target: ForkPathTargetProjection) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
351
|
+
#pathCommand(snapshot: ForkSnapshot, target: ForkPathTargetProjection) {
|
|
352
|
+
return {
|
|
353
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
354
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
355
|
+
historyId: snapshot.summary.historyId,
|
|
356
|
+
expectedRevision: snapshot.summary.revision,
|
|
357
|
+
target,
|
|
358
|
+
offset: 0,
|
|
359
|
+
limit: this.#pathPageSize,
|
|
360
|
+
} as const;
|
|
361
|
+
}
|
|
362
|
+
#required(): ForkSnapshot {
|
|
363
|
+
if (!this.#started || this.#snapshot === undefined) {
|
|
364
|
+
throw new ForkHistoryUnavailableError();
|
|
365
|
+
}
|
|
366
|
+
return this.#snapshot;
|
|
367
|
+
}
|
|
368
|
+
#branchCommand(snapshot: ForkSnapshot, offset: number) {
|
|
369
|
+
return {
|
|
370
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
371
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
372
|
+
historyId: snapshot.summary.historyId,
|
|
373
|
+
expectedRevision: snapshot.summary.revision,
|
|
374
|
+
offset,
|
|
375
|
+
limit: this.#branchPageSize,
|
|
376
|
+
} as const;
|
|
377
|
+
}
|
|
378
|
+
#install(
|
|
379
|
+
snapshot: ForkSnapshot,
|
|
380
|
+
path: ForkPathPageSnapshot,
|
|
381
|
+
branches?: ForkBranchPageSnapshot,
|
|
382
|
+
): void {
|
|
383
|
+
const current = this.#snapshot;
|
|
384
|
+
if (
|
|
385
|
+
current !== undefined &&
|
|
386
|
+
snapshot.authorityEpoch === current.authorityEpoch &&
|
|
387
|
+
snapshot.summary.historyId === current.summary.historyId &&
|
|
388
|
+
snapshot.summary.revision < current.summary.revision
|
|
389
|
+
) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
this.#snapshot = snapshot;
|
|
393
|
+
this.#path = path;
|
|
394
|
+
if (branches !== undefined) {
|
|
395
|
+
this.#branches = branches;
|
|
396
|
+
} else if (this.#branches !== undefined && !same(snapshot, this.#branches)) {
|
|
397
|
+
this.#branches = undefined;
|
|
398
|
+
}
|
|
399
|
+
this.#notify();
|
|
400
|
+
}
|
|
401
|
+
#changed(event: ForkChangedEvent): void {
|
|
402
|
+
const snapshot = this.#snapshot;
|
|
403
|
+
if (
|
|
404
|
+
!this.#started ||
|
|
405
|
+
snapshot === undefined ||
|
|
406
|
+
event.authorityEpoch !== snapshot.authorityEpoch ||
|
|
407
|
+
event.historyId !== snapshot.summary.historyId ||
|
|
408
|
+
event.committedRevision > snapshot.summary.revision
|
|
409
|
+
) {
|
|
410
|
+
void this.refresh();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
#setStatus(status: ForkHistoryControllerStatus): void {
|
|
414
|
+
this.#status = status;
|
|
415
|
+
this.#notify();
|
|
416
|
+
}
|
|
417
|
+
#notify(): void {
|
|
418
|
+
for (const observer of this.#observers) {
|
|
419
|
+
observer();
|
|
420
|
+
}
|
|
421
|
+
}
|
|
193
422
|
}
|
|
194
423
|
|
|
195
|
-
function same(
|
|
196
|
-
|
|
424
|
+
function same(
|
|
425
|
+
snapshot: ForkSnapshot,
|
|
426
|
+
page: { authorityEpoch: number; historyId: string; revision: number },
|
|
427
|
+
): boolean {
|
|
428
|
+
return (
|
|
429
|
+
snapshot.authorityEpoch === page.authorityEpoch &&
|
|
430
|
+
snapshot.summary.historyId === page.historyId &&
|
|
431
|
+
snapshot.summary.revision === page.revision
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
function pageSize(value: number): number {
|
|
435
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
|
|
436
|
+
throw new RangeError(`fork-history page size must be 1..${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
|
|
437
|
+
}
|
|
438
|
+
return value;
|
|
439
|
+
}
|
|
197
440
|
export class ForkHistoryUnavailableError extends Error {}
|
|
198
441
|
export class ForkHistoryProjectionGapError extends Error {}
|
|
199
442
|
export class ForkHistoryLateResultError extends Error {}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { ForkHistoryPort } from "./ports.ts";
|
|
2
2
|
export type DirectForkHistoryHandlers = ForkHistoryPort;
|
|
3
|
-
export function createDirectForkHistoryPort(handlers: DirectForkHistoryHandlers): ForkHistoryPort {
|
|
3
|
+
export function createDirectForkHistoryPort(handlers: DirectForkHistoryHandlers): ForkHistoryPort {
|
|
4
|
+
return handlers;
|
|
5
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
5
5
|
|
|
6
|
-
export const HISTORY_TREE_FIELDS
|
|
6
|
+
export const HISTORY_TREE_FIELDS = {
|
|
7
7
|
"ForkSummaryProjection": ["historyId", "revision", "currentBranchId", "currentEntryId", "undoDepth", "redoDepth", "nextUndoLabel", "nextRedoLabel", "retainedEntryCount", "retainedEncodedWeight", "branchCount", "alternatePathCount"],
|
|
8
8
|
"ForkSnapshot": ["protocolVersion", "authorityEpoch", "summary"],
|
|
9
9
|
"ForkEntryRecord": ["entryId", "label", "kindId", "recordedAt", "groupId", "sequence", "committedRevision", "encodedWeight", "position", "continuationCount"],
|
|
@@ -23,4 +23,4 @@ export const HISTORY_TREE_FIELDS: Record<string, readonly string[]> = {
|
|
|
23
23
|
"ForkNavigationReceiptProjection": ["historyId", "planId", "previousRevision", "committedRevision", "sourceEntryId", "targetEntryId", "targetBranchId", "movedEntryIds"],
|
|
24
24
|
"ForkNavigationRejectionProjection": ["code", "detail", "refreshRequired"],
|
|
25
25
|
"ForkChangedEvent": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "kind"],
|
|
26
|
-
};
|
|
26
|
+
} as const;
|
|
@@ -26,7 +26,9 @@ export interface ForkHistoryPort {
|
|
|
26
26
|
deleteContinuation(command: ForkDeleteContinuationCommand): Promise<unknown>;
|
|
27
27
|
prune(command: ForkPruneCommand): Promise<unknown>;
|
|
28
28
|
navigate(command: ForkNavigationCommand): Promise<unknown>;
|
|
29
|
-
listen
|
|
29
|
+
listen?:
|
|
30
|
+
| ((listener: (event: unknown) => void) => ForkHistoryUnlisten | Promise<ForkHistoryUnlisten>)
|
|
31
|
+
| undefined;
|
|
30
32
|
nextPlanId(): HistoryPlanId;
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -1,15 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
2
|
+
import type {
|
|
3
|
+
ForkBranchPageCommand,
|
|
4
|
+
ForkContinuationPageCommand,
|
|
5
|
+
ForkDeleteContinuationCommand,
|
|
6
|
+
ForkNavigationCommand,
|
|
7
|
+
ForkPathPageCommand,
|
|
8
|
+
ForkPruneCommand,
|
|
9
|
+
} from "./generated/protocol.ts";
|
|
2
10
|
import type { ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
|
|
3
11
|
export class SerializedForkHistoryPort implements ForkHistoryPort {
|
|
4
12
|
constructor(readonly inner: ForkHistoryPort) {}
|
|
5
|
-
async snapshot(): Promise<unknown> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
async snapshot(): Promise<unknown> {
|
|
14
|
+
return wireCopy(await this.inner.snapshot());
|
|
15
|
+
}
|
|
16
|
+
async path(command: ForkPathPageCommand): Promise<unknown> {
|
|
17
|
+
return wireCopy(await this.inner.path(wireCopy(command)));
|
|
18
|
+
}
|
|
19
|
+
async branches(command: ForkBranchPageCommand): Promise<unknown> {
|
|
20
|
+
return wireCopy(await this.inner.branches(wireCopy(command)));
|
|
21
|
+
}
|
|
22
|
+
async continuations(command: ForkContinuationPageCommand): Promise<unknown> {
|
|
23
|
+
return wireCopy(await this.inner.continuations(wireCopy(command)));
|
|
24
|
+
}
|
|
25
|
+
async deleteContinuation(command: ForkDeleteContinuationCommand): Promise<unknown> {
|
|
26
|
+
return wireCopy(await this.inner.deleteContinuation(wireCopy(command)));
|
|
27
|
+
}
|
|
28
|
+
async prune(command: ForkPruneCommand): Promise<unknown> {
|
|
29
|
+
return wireCopy(await this.inner.prune(wireCopy(command)));
|
|
30
|
+
}
|
|
31
|
+
async navigate(command: ForkNavigationCommand): Promise<unknown> {
|
|
32
|
+
return wireCopy(await this.inner.navigate(wireCopy(command)));
|
|
33
|
+
}
|
|
34
|
+
async listen(listener: (event: unknown) => void): Promise<ForkHistoryUnlisten> {
|
|
35
|
+
if (this.inner.listen === undefined) {
|
|
36
|
+
return () => {};
|
|
37
|
+
}
|
|
38
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
39
|
+
}
|
|
40
|
+
nextPlanId(): string {
|
|
41
|
+
return this.inner.nextPlanId();
|
|
42
|
+
}
|
|
14
43
|
}
|
|
15
|
-
function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
|