@inflatable-cookie/longhorn 0.5.0 → 0.7.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/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- 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 +78 -109
- 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 +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,9 +1,36 @@
|
|
|
1
|
+
import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
|
|
1
2
|
import { ForkHistoryClient } from "./client.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
3
|
+
import {
|
|
4
|
+
FORK_HISTORY_PROTOCOL_VERSION,
|
|
5
|
+
MAXIMUM_FORK_HISTORY_PAGE_SIZE,
|
|
6
|
+
} from "./generated/protocol.ts";
|
|
7
|
+
import type {
|
|
8
|
+
ForkBranchId,
|
|
9
|
+
ForkBranchPageSnapshot,
|
|
10
|
+
ForkChangedEvent,
|
|
11
|
+
ForkContinuationPageSnapshot,
|
|
12
|
+
ForkEntryRecord,
|
|
13
|
+
ForkPruneResult,
|
|
14
|
+
ForkDeleteResult,
|
|
15
|
+
ForkNavigationResult,
|
|
16
|
+
ForkNavigationTargetProjection,
|
|
17
|
+
ForkPathPageSnapshot,
|
|
18
|
+
ForkPathTargetProjection,
|
|
19
|
+
ForkSnapshot,
|
|
20
|
+
} from "./generated/protocol.ts";
|
|
21
|
+
import type { ForkHistoryPort } from "./ports.ts";
|
|
4
22
|
|
|
5
|
-
export type ForkHistoryControllerStatus =
|
|
6
|
-
|
|
23
|
+
export type ForkHistoryControllerStatus =
|
|
24
|
+
| { readonly kind: "idle" }
|
|
25
|
+
| { readonly kind: "loading" }
|
|
26
|
+
| { readonly kind: "ready" }
|
|
27
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
28
|
+
export interface ForkHistoryControllerOptions {
|
|
29
|
+
readonly port: ForkHistoryPort;
|
|
30
|
+
readonly pathPageSize?: number;
|
|
31
|
+
readonly branchPageSize?: number;
|
|
32
|
+
readonly continuationPageSize?: number;
|
|
33
|
+
}
|
|
7
34
|
|
|
8
35
|
export class ForkHistoryController {
|
|
9
36
|
readonly #client: ForkHistoryClient;
|
|
@@ -12,46 +39,94 @@ export class ForkHistoryController {
|
|
|
12
39
|
readonly #branchPageSize: number;
|
|
13
40
|
readonly #continuationPageSize: number;
|
|
14
41
|
#status: ForkHistoryControllerStatus = { kind: "idle" };
|
|
15
|
-
#snapshot
|
|
16
|
-
#path
|
|
17
|
-
#branches
|
|
42
|
+
#snapshot: ForkSnapshot | undefined;
|
|
43
|
+
#path: ForkPathPageSnapshot | undefined;
|
|
44
|
+
#branches: ForkBranchPageSnapshot | undefined;
|
|
18
45
|
#pathTarget: ForkPathTargetProjection = { kind: "default" };
|
|
19
|
-
#
|
|
20
|
-
#lifecycle = 0;
|
|
46
|
+
readonly #lifecycle = new ControllerLifecycle();
|
|
21
47
|
#load = 0;
|
|
22
48
|
#navigation = 0;
|
|
23
49
|
#pending = false;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
get
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
get
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
|
|
51
|
+
constructor(options: ForkHistoryControllerOptions) {
|
|
52
|
+
this.#client = new ForkHistoryClient(options.port);
|
|
53
|
+
this.#pathPageSize = pageSize(options.pathPageSize ?? 50);
|
|
54
|
+
this.#branchPageSize = pageSize(options.branchPageSize ?? 50);
|
|
55
|
+
this.#continuationPageSize = pageSize(options.continuationPageSize ?? 50);
|
|
56
|
+
}
|
|
57
|
+
get status() {
|
|
58
|
+
return this.#lifecycle.eventFailure ?? this.#status;
|
|
59
|
+
}
|
|
60
|
+
get snapshot() {
|
|
61
|
+
return this.#snapshot;
|
|
62
|
+
}
|
|
63
|
+
get path() {
|
|
64
|
+
return this.#path;
|
|
65
|
+
}
|
|
66
|
+
get branches() {
|
|
67
|
+
return this.#branches;
|
|
68
|
+
}
|
|
69
|
+
get entries(): ReadonlyArray<ForkEntryRecord> {
|
|
70
|
+
return this.#path?.entries ?? [];
|
|
71
|
+
}
|
|
72
|
+
get navigationPending() {
|
|
73
|
+
return this.#pending;
|
|
74
|
+
}
|
|
75
|
+
get canUndo() {
|
|
76
|
+
return (this.#snapshot?.summary.undoDepth ?? 0) > 0;
|
|
77
|
+
}
|
|
78
|
+
get canRedo() {
|
|
79
|
+
return (this.#snapshot?.summary.redoDepth ?? 0) > 0;
|
|
80
|
+
}
|
|
81
|
+
observe(observer: () => void): () => void {
|
|
82
|
+
this.#observers.add(observer);
|
|
83
|
+
return () => this.#observers.delete(observer);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
start(): Promise<void> {
|
|
87
|
+
return this.#lifecycle.start({
|
|
88
|
+
loading: () => this.#setStatus({ kind: "loading" }),
|
|
89
|
+
connect: async ({ isCurrent, own, reportFailure }) => {
|
|
90
|
+
const unlisten = await this.#client.listen((event) => {
|
|
91
|
+
if (isCurrent()) {
|
|
92
|
+
this.#changed(event);
|
|
93
|
+
}
|
|
94
|
+
}, reportFailure);
|
|
95
|
+
await own(unlisten);
|
|
96
|
+
if (isCurrent()) {
|
|
97
|
+
await this.refresh();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
failed: (error) => this.#setStatus({ kind: "failed", error }),
|
|
101
|
+
});
|
|
45
102
|
}
|
|
46
103
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
104
|
+
/** Replaces the current subscription, including after a reported failure. */
|
|
105
|
+
restart(): Promise<void> {
|
|
106
|
+
return this.#lifecycle.restart(
|
|
107
|
+
this.status,
|
|
108
|
+
() => this.stop(),
|
|
109
|
+
() => this.start(),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
stop(): Promise<void> {
|
|
114
|
+
return this.#lifecycle.stop(() => {
|
|
115
|
+
this.#load += 1;
|
|
116
|
+
this.#navigation += 1;
|
|
117
|
+
this.#snapshot = undefined;
|
|
118
|
+
this.#path = undefined;
|
|
119
|
+
this.#branches = undefined;
|
|
120
|
+
this.#pathTarget = { kind: "default" };
|
|
121
|
+
this.#pending = false;
|
|
122
|
+
this.#setStatus({ kind: "idle" });
|
|
123
|
+
});
|
|
51
124
|
}
|
|
52
125
|
|
|
53
126
|
async refresh(): Promise<void> {
|
|
54
|
-
if (!this.#
|
|
127
|
+
if (!this.#lifecycle.active) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
55
130
|
const load = ++this.#load;
|
|
56
131
|
// The offset a consumer had paged to, so a refresh returns the page they
|
|
57
132
|
// were looking at rather than sending them back to the first one.
|
|
@@ -60,25 +135,39 @@ export class ForkHistoryController {
|
|
|
60
135
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
61
136
|
const snapshot = await this.#client.snapshot();
|
|
62
137
|
const path = await this.#client.path(this.#pathCommand(snapshot, this.#pathTarget));
|
|
63
|
-
if (!same(snapshot, path))
|
|
138
|
+
if (!same(snapshot, path)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
64
141
|
// Only for a consumer that asked for branches. Loading a page nobody
|
|
65
142
|
// wanted would make every refresh pay for a projection it will not use.
|
|
66
|
-
const branches =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
143
|
+
const branches =
|
|
144
|
+
branchOffset === undefined
|
|
145
|
+
? undefined
|
|
146
|
+
: await this.#client.branches(this.#branchCommand(snapshot, branchOffset));
|
|
147
|
+
if (branches !== undefined && !same(snapshot, branches)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (this.#lifecycle.active && load === this.#load) {
|
|
151
|
+
this.#install(snapshot, path, branches);
|
|
152
|
+
this.#setStatus({ kind: "ready" });
|
|
153
|
+
}
|
|
71
154
|
return;
|
|
72
155
|
}
|
|
73
156
|
throw new ForkHistoryProjectionGapError();
|
|
74
|
-
} catch (error) {
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (this.#lifecycle.active && load === this.#load) {
|
|
159
|
+
this.#setStatus({ kind: "failed", error });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
75
162
|
}
|
|
76
163
|
|
|
77
164
|
async loadBranches(offset = 0): Promise<ForkBranchPageSnapshot> {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.#branches = value;
|
|
165
|
+
const value = await this.#loadCurrent((snapshot) =>
|
|
166
|
+
this.#client.branches(this.#branchCommand(snapshot, offset)),
|
|
167
|
+
);
|
|
168
|
+
this.#branches = value;
|
|
169
|
+
this.#notify();
|
|
170
|
+
return value;
|
|
82
171
|
}
|
|
83
172
|
|
|
84
173
|
/**
|
|
@@ -91,22 +180,34 @@ export class ForkHistoryController {
|
|
|
91
180
|
* Not cached and not refreshed. A consumer asks when the operator opens an
|
|
92
181
|
* entry, and the revision check below tells them if it went stale meanwhile.
|
|
93
182
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
183
|
+
loadContinuations(
|
|
184
|
+
anchorEntryId: string | null,
|
|
185
|
+
offset = 0,
|
|
186
|
+
): Promise<ForkContinuationPageSnapshot> {
|
|
187
|
+
return this.#loadCurrent((snapshot) =>
|
|
188
|
+
this.#client.continuations({
|
|
189
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
190
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
191
|
+
historyId: snapshot.summary.historyId,
|
|
192
|
+
expectedRevision: snapshot.summary.revision,
|
|
193
|
+
anchorEntryId,
|
|
194
|
+
offset,
|
|
195
|
+
limit: this.#continuationPageSize,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
99
198
|
}
|
|
100
199
|
|
|
101
200
|
/**
|
|
102
201
|
* The flat run beginning at one entry. The same snapshot type as the main
|
|
103
202
|
* path, so a renderer draws a nested fork with the component it already has.
|
|
104
203
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
204
|
+
loadContinuationRun(fromEntryId: string, offset = 0): Promise<ForkPathPageSnapshot> {
|
|
205
|
+
return this.#loadCurrent((snapshot) =>
|
|
206
|
+
this.#client.path({
|
|
207
|
+
...this.#pathCommand(snapshot, { kind: "continuation", fromEntryId }),
|
|
208
|
+
offset,
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
110
211
|
}
|
|
111
212
|
|
|
112
213
|
/**
|
|
@@ -117,15 +218,23 @@ export class ForkHistoryController {
|
|
|
117
218
|
*
|
|
118
219
|
* It refuses four things rather than working around them: the entry the
|
|
119
220
|
* operator stands on or above, the active line, a pinned branch, and an
|
|
120
|
-
* entry that does not exist. A refusal
|
|
221
|
+
* entry that does not exist. A refusal is returned as a typed result.
|
|
121
222
|
*/
|
|
122
|
-
async deleteContinuation(entryId: string): Promise<
|
|
223
|
+
async deleteContinuation(entryId: string): Promise<ForkDeleteResult> {
|
|
123
224
|
const snapshot = this.#required();
|
|
124
|
-
const
|
|
225
|
+
const result = await this.#client.deleteContinuation({
|
|
226
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
227
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
228
|
+
historyId: snapshot.summary.historyId,
|
|
229
|
+
expectedRevision: snapshot.summary.revision,
|
|
230
|
+
entryId,
|
|
231
|
+
});
|
|
125
232
|
// Every page the consumer holds may name entries that no longer exist, so
|
|
126
233
|
// this refresh is not optional and is not left to the changed event.
|
|
127
|
-
|
|
128
|
-
|
|
234
|
+
if (result.status === "deleted" || result.rejection.refreshRequired) {
|
|
235
|
+
await this.refresh();
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
129
238
|
}
|
|
130
239
|
|
|
131
240
|
/**
|
|
@@ -142,18 +251,44 @@ export class ForkHistoryController {
|
|
|
142
251
|
*/
|
|
143
252
|
async prune(maximumEntries: number, maximumEncodedWeight: number): Promise<ForkPruneResult> {
|
|
144
253
|
const snapshot = this.#required();
|
|
145
|
-
const result = await this.#client.prune({
|
|
146
|
-
|
|
254
|
+
const result = await this.#client.prune({
|
|
255
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
256
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
257
|
+
historyId: snapshot.summary.historyId,
|
|
258
|
+
expectedRevision: snapshot.summary.revision,
|
|
259
|
+
maximumEntries,
|
|
260
|
+
maximumEncodedWeight,
|
|
261
|
+
});
|
|
262
|
+
if (
|
|
263
|
+
result.status === "pruned" ||
|
|
264
|
+
(result.status === "rejected" && result.rejection.refreshRequired)
|
|
265
|
+
) {
|
|
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,186 @@ 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.#lifecycle.active || 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.#
|
|
175
|
-
|
|
323
|
+
if (!this.#lifecycle.active || 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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
330
|
+
const branches =
|
|
331
|
+
branchOffset === undefined
|
|
332
|
+
? undefined
|
|
333
|
+
: await this.#client.branches(this.#branchCommand(result.snapshot, branchOffset));
|
|
334
|
+
if (!this.#lifecycle.active || 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
|
+
} catch (error) {
|
|
344
|
+
// A superseded navigation no longer owns the controller's status.
|
|
345
|
+
if (this.#lifecycle.active && navigation === this.#navigation) {
|
|
346
|
+
this.#setStatus({ kind: "failed", error });
|
|
347
|
+
}
|
|
348
|
+
throw error;
|
|
349
|
+
} finally {
|
|
350
|
+
if (navigation === this.#navigation) {
|
|
351
|
+
this.#pending = false;
|
|
352
|
+
this.#notify();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Loads one page against the held snapshot. The page is returned only while
|
|
359
|
+
* the same lifetime still holds the revision it was read at.
|
|
360
|
+
*/
|
|
361
|
+
async #loadCurrent<Page extends ForkPage>(
|
|
362
|
+
load: (snapshot: ForkSnapshot) => Promise<Page>,
|
|
363
|
+
): Promise<Page> {
|
|
364
|
+
const snapshot = this.#required();
|
|
365
|
+
const lifecycle = this.#lifecycle.revision;
|
|
366
|
+
const page = await load(snapshot);
|
|
367
|
+
if (!this.#lifecycle.isCurrent(lifecycle)) {
|
|
368
|
+
throw new ForkHistoryLateResultError();
|
|
369
|
+
}
|
|
370
|
+
const current = this.#snapshot;
|
|
371
|
+
if (!same(snapshot, page) || current === undefined || !same(current, page)) {
|
|
372
|
+
throw new ForkHistoryProjectionGapError();
|
|
373
|
+
}
|
|
374
|
+
return page;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
#pathCommand(snapshot: ForkSnapshot, target: ForkPathTargetProjection) {
|
|
378
|
+
return {
|
|
379
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
380
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
381
|
+
historyId: snapshot.summary.historyId,
|
|
382
|
+
expectedRevision: snapshot.summary.revision,
|
|
383
|
+
target,
|
|
384
|
+
offset: 0,
|
|
385
|
+
limit: this.#pathPageSize,
|
|
386
|
+
} as const;
|
|
387
|
+
}
|
|
388
|
+
#required(): ForkSnapshot {
|
|
389
|
+
if (!this.#lifecycle.active || this.#snapshot === undefined) {
|
|
390
|
+
throw new ForkHistoryUnavailableError();
|
|
391
|
+
}
|
|
392
|
+
return this.#snapshot;
|
|
393
|
+
}
|
|
394
|
+
#branchCommand(snapshot: ForkSnapshot, offset: number) {
|
|
395
|
+
return {
|
|
396
|
+
protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
|
|
397
|
+
authorityEpoch: snapshot.authorityEpoch,
|
|
398
|
+
historyId: snapshot.summary.historyId,
|
|
399
|
+
expectedRevision: snapshot.summary.revision,
|
|
400
|
+
offset,
|
|
401
|
+
limit: this.#branchPageSize,
|
|
402
|
+
} as const;
|
|
403
|
+
}
|
|
404
|
+
#install(
|
|
405
|
+
snapshot: ForkSnapshot,
|
|
406
|
+
path: ForkPathPageSnapshot,
|
|
407
|
+
branches?: ForkBranchPageSnapshot,
|
|
408
|
+
): void {
|
|
409
|
+
const current = this.#snapshot;
|
|
410
|
+
if (
|
|
411
|
+
current !== undefined &&
|
|
412
|
+
snapshot.authorityEpoch === current.authorityEpoch &&
|
|
413
|
+
snapshot.summary.historyId === current.summary.historyId &&
|
|
414
|
+
snapshot.summary.revision < current.summary.revision
|
|
415
|
+
) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
this.#snapshot = snapshot;
|
|
419
|
+
this.#path = path;
|
|
420
|
+
if (branches !== undefined) {
|
|
421
|
+
this.#branches = branches;
|
|
422
|
+
} else if (this.#branches !== undefined && !same(snapshot, this.#branches)) {
|
|
423
|
+
this.#branches = undefined;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
#changed(event: ForkChangedEvent): void {
|
|
427
|
+
const snapshot = this.#snapshot;
|
|
428
|
+
if (
|
|
429
|
+
!this.#lifecycle.active ||
|
|
430
|
+
snapshot === undefined ||
|
|
431
|
+
event.authorityEpoch !== snapshot.authorityEpoch ||
|
|
432
|
+
event.historyId !== snapshot.summary.historyId ||
|
|
433
|
+
event.committedRevision > snapshot.summary.revision
|
|
434
|
+
) {
|
|
435
|
+
void this.refresh();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
#setStatus(status: ForkHistoryControllerStatus): void {
|
|
439
|
+
this.#status = status;
|
|
440
|
+
this.#notify();
|
|
441
|
+
}
|
|
442
|
+
#notify(): void {
|
|
443
|
+
for (const observer of this.#observers) {
|
|
444
|
+
observer();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
193
447
|
}
|
|
194
448
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
449
|
+
type ForkPage = { authorityEpoch: number; historyId: string; revision: number };
|
|
450
|
+
|
|
451
|
+
function same(snapshot: ForkSnapshot, page: ForkPage): boolean {
|
|
452
|
+
return (
|
|
453
|
+
snapshot.authorityEpoch === page.authorityEpoch &&
|
|
454
|
+
snapshot.summary.historyId === page.historyId &&
|
|
455
|
+
snapshot.summary.revision === page.revision
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
function pageSize(value: number): number {
|
|
459
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
|
|
460
|
+
throw new RangeError(`fork-history page size must be 1..${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
|
|
461
|
+
}
|
|
462
|
+
return value;
|
|
463
|
+
}
|
|
464
|
+
export class ForkHistoryUnavailableError extends Error {
|
|
465
|
+
constructor(message = "fork-history controller is not ready") {
|
|
466
|
+
super(message);
|
|
467
|
+
this.name = "ForkHistoryUnavailableError";
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export class ForkHistoryProjectionGapError extends Error {
|
|
472
|
+
constructor(message = "fork-history projections do not share one authority revision") {
|
|
473
|
+
super(message);
|
|
474
|
+
this.name = "ForkHistoryProjectionGapError";
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export class ForkHistoryLateResultError extends Error {
|
|
479
|
+
constructor(message = "fork-history result arrived after the controller moved on") {
|
|
480
|
+
super(message);
|
|
481
|
+
this.name = "ForkHistoryLateResultError";
|
|
482
|
+
}
|
|
483
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per protocol type, from the Rust structs.
|
|
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"],
|
|
@@ -16,6 +16,7 @@ export const HISTORY_TREE_FIELDS: Record<string, readonly string[]> = {
|
|
|
16
16
|
"ForkContinuationPageCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "anchorEntryId", "offset", "limit"],
|
|
17
17
|
"ForkContinuationPageSnapshot": ["protocolVersion", "authorityEpoch", "historyId", "revision", "anchorEntryId", "offset", "totalContinuations", "continuations", "truncatedBefore", "truncatedAfter"],
|
|
18
18
|
"ForkDeleteContinuationCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "entryId"],
|
|
19
|
+
"ForkRetentionRejectionProjection": ["code", "detail", "refreshRequired"],
|
|
19
20
|
"ForkRemovedEntryRecord": ["entryId", "sequence", "encodedWeight"],
|
|
20
21
|
"ForkRemovalReceiptProjection": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "removedEntries", "removedBranches", "removedCheckpoints", "retainedEntryCount", "retainedEncodedWeight", "unprotectedEntryCount", "unprotectedEncodedWeight"],
|
|
21
22
|
"ForkPruneCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "maximumEntries", "maximumEncodedWeight"],
|
|
@@ -23,4 +24,5 @@ export const HISTORY_TREE_FIELDS: Record<string, readonly string[]> = {
|
|
|
23
24
|
"ForkNavigationReceiptProjection": ["historyId", "planId", "previousRevision", "committedRevision", "sourceEntryId", "targetEntryId", "targetBranchId", "movedEntryIds"],
|
|
24
25
|
"ForkNavigationRejectionProjection": ["code", "detail", "refreshRequired"],
|
|
25
26
|
"ForkChangedEvent": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "kind"],
|
|
26
|
-
|
|
27
|
+
"ForkHistoryHostError": ["code", "message", "retryable"],
|
|
28
|
+
} as const;
|