@inflatable-cookie/longhorn 0.6.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/selection.ts +10 -8
- package/src/agent-control/shim.ts +149 -77
- package/src/bridge/generated/fields.ts +1 -1
- package/src/bridge/generated/protocol.ts +55 -4
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -2
- package/src/bridge/runtime/connection.ts +11 -14
- package/src/bridge/stream/connection.ts +14 -23
- package/src/bridge/stream/tracker.ts +5 -0
- package/src/bridge/supervision.ts +102 -80
- package/src/bridge/validation/base.ts +7 -27
- package/src/bridge/validation/negotiation.ts +1 -6
- package/src/bridge/validation/operations.ts +2 -14
- package/src/commands/client.ts +16 -2
- package/src/commands/controller.ts +96 -58
- package/src/commands/generated/fields.ts +4 -4
- package/src/commands/generated/protocol.ts +24 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +4 -13
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +2 -1
- package/src/commands/projectors.ts +52 -29
- package/src/commands/validation.ts +408 -188
- package/src/config/client.ts +3 -3
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +2 -1
- 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/validation/commands.ts +11 -13
- package/src/config/validation/outcomes.ts +147 -46
- package/src/config/validation/primitives.ts +11 -39
- package/src/config/validation/projection.ts +44 -44
- package/src/core/connection.ts +124 -29
- 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 +76 -0
- package/src/core/transport.ts +10 -1
- package/src/core/wire-copy.ts +1 -0
- package/src/history/client.ts +11 -7
- package/src/history/controller.ts +72 -74
- package/src/history/generated/fields.ts +2 -1
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -2
- package/src/history/validation.ts +15 -37
- package/src/history-tree/client.ts +15 -13
- package/src/history-tree/controller.ts +131 -90
- package/src/history-tree/generated/fields.ts +3 -1
- 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 +9 -4
- package/src/history-tree/validation.ts +44 -35
- package/src/layout/generated/protocol.ts +2 -1
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +9 -2
- package/src/layout/validation.ts +88 -13
- package/src/licence/client.ts +11 -7
- package/src/licence/controller.ts +64 -43
- package/src/licence/generated/fields.ts +2 -1
- package/src/licence/generated/protocol.ts +8 -4
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +2 -6
- package/src/licence/ports.ts +7 -2
- package/src/licence/validation.ts +27 -20
- package/src/native-content/client.ts +32 -1
- package/src/native-content/generated/fields.ts +4 -4
- 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 +2 -1
- package/src/native-content/validation/base.ts +16 -46
- package/src/native-content/validation/messages.ts +3 -0
- package/src/notifications/client.ts +17 -39
- package/src/notifications/controller.ts +266 -165
- package/src/notifications/generated/fields.ts +2 -1
- 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 +2 -1
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +41 -51
- package/src/operation/bridge.ts +79 -19
- package/src/operation/client.ts +17 -45
- package/src/operation/controller.ts +38 -59
- package/src/operation/generated/fields.ts +2 -1
- 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 +2 -1
- package/src/operation/validation.ts +48 -50
- package/src/settings/connection.ts +10 -14
- package/src/settings/generated/fields.ts +2 -1
- package/src/settings/generated/protocol.ts +5 -1
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/validation/authority.ts +2 -2
- package/src/settings/validation/command.ts +5 -4
- package/src/settings/validation/primitives.ts +32 -67
- package/src/settings/validation/registry.ts +13 -11
- package/src/surface-transfer/generated/fields.ts +1 -1
- 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 +76 -53
- package/src/surfaces/client.ts +26 -38
- package/src/surfaces/generated/fields.ts +1 -1
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +198 -61
- package/src/transfer/connection.ts +25 -39
- package/src/transfer/generated/fields.ts +2 -1
- package/src/transfer/generated/protocol.ts +9 -1
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +12 -9
- package/src/transfer/validation.ts +146 -60
- package/src/update/client.ts +43 -16
- package/src/update/controller.ts +187 -104
- package/src/update/generated/fields.ts +2 -1
- package/src/update/generated/protocol.ts +19 -7
- package/src/update/generated/variant-fields.ts +3 -2
- package/src/update/ports.ts +11 -7
- package/src/update/serialized.ts +8 -6
- package/src/update/validation.ts +18 -28
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
|
|
1
2
|
import { HistoryClient } from "./client.ts";
|
|
2
3
|
import { HISTORY_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
3
4
|
import type {
|
|
@@ -11,7 +12,7 @@ import type {
|
|
|
11
12
|
HistorySnapshot,
|
|
12
13
|
} from "./generated/protocol.ts";
|
|
13
14
|
import { HISTORY_MAXIMUM_PROJECTION_PAGE_SIZE } from "./generated/protocol.ts";
|
|
14
|
-
import type { HistoryPort
|
|
15
|
+
import type { HistoryPort } from "./ports.ts";
|
|
15
16
|
|
|
16
17
|
export type HistoryControllerStatus =
|
|
17
18
|
| { readonly kind: "idle" }
|
|
@@ -24,6 +25,12 @@ export interface HistoryControllerOptions {
|
|
|
24
25
|
readonly pageSize?: number;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
interface HistoryProjection {
|
|
29
|
+
readonly snapshot: HistorySnapshot;
|
|
30
|
+
readonly page: HistoryPageSnapshot;
|
|
31
|
+
readonly pageNumber: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
export class HistoryController {
|
|
28
35
|
readonly #client: HistoryClient;
|
|
29
36
|
readonly #observers = new Set<() => void>();
|
|
@@ -35,11 +42,9 @@ export class HistoryController {
|
|
|
35
42
|
#page = 1;
|
|
36
43
|
#pageSize: number;
|
|
37
44
|
#navigationPending = false;
|
|
38
|
-
#
|
|
39
|
-
#lifecycleRevision = 0;
|
|
45
|
+
readonly #lifecycle = new ControllerLifecycle();
|
|
40
46
|
#loadRevision = 0;
|
|
41
47
|
#navigationRevision = 0;
|
|
42
|
-
#unlisten: Array<HistoryUnlisten> = [];
|
|
43
48
|
|
|
44
49
|
constructor(options: HistoryControllerOptions) {
|
|
45
50
|
this.#client = new HistoryClient(options.port);
|
|
@@ -47,7 +52,7 @@ export class HistoryController {
|
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
get status(): HistoryControllerStatus {
|
|
50
|
-
return this.#status;
|
|
55
|
+
return this.#lifecycle.eventFailure ?? this.#status;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
get snapshot(): HistorySnapshot | undefined {
|
|
@@ -108,60 +113,61 @@ export class HistoryController {
|
|
|
108
113
|
return () => this.#observers.delete(observer);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
await this.refresh();
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (this.#isCurrentLifecycle(lifecycleRevision)) {
|
|
130
|
-
this.#setStatus({ kind: "failed", error });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
116
|
+
start(): Promise<void> {
|
|
117
|
+
return this.#lifecycle.start({
|
|
118
|
+
loading: () => this.#setStatus({ kind: "loading" }),
|
|
119
|
+
connect: async ({ isCurrent, own, reportFailure }) => {
|
|
120
|
+
const unlisten = await this.#client.listen((event) => {
|
|
121
|
+
if (isCurrent()) {
|
|
122
|
+
this.#handleChanged(event);
|
|
123
|
+
}
|
|
124
|
+
}, reportFailure);
|
|
125
|
+
await own(unlisten);
|
|
126
|
+
if (isCurrent()) {
|
|
127
|
+
await this.refresh();
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
failed: (error) => this.#setStatus({ kind: "failed", error }),
|
|
131
|
+
});
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.#
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.#
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
/** Replaces the current subscription, including after a reported failure. */
|
|
135
|
+
restart(): Promise<void> {
|
|
136
|
+
return this.#lifecycle.restart(
|
|
137
|
+
this.status,
|
|
138
|
+
() => this.stop(),
|
|
139
|
+
() => this.start(),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
stop(): Promise<void> {
|
|
144
|
+
return this.#lifecycle.stop(() => {
|
|
145
|
+
this.#loadRevision += 1;
|
|
146
|
+
this.#navigationRevision += 1;
|
|
147
|
+
this.#snapshot = undefined;
|
|
148
|
+
this.#pageSnapshot = undefined;
|
|
149
|
+
this.#rejection = undefined;
|
|
150
|
+
this.#filter = "";
|
|
151
|
+
this.#page = 1;
|
|
152
|
+
this.#navigationPending = false;
|
|
153
|
+
this.#setStatus({ kind: "idle" });
|
|
154
|
+
});
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
async refresh(): Promise<void> {
|
|
152
|
-
if (!this.#
|
|
158
|
+
if (!this.#lifecycle.active) {
|
|
153
159
|
return;
|
|
154
160
|
}
|
|
155
161
|
const revision = ++this.#loadRevision;
|
|
156
162
|
try {
|
|
157
163
|
const state = await this.#readAuthoritativeState();
|
|
158
|
-
if (!this.#
|
|
164
|
+
if (!this.#lifecycle.active || revision !== this.#loadRevision) {
|
|
159
165
|
return;
|
|
160
166
|
}
|
|
161
|
-
this.#install(state
|
|
167
|
+
this.#install(state);
|
|
162
168
|
this.#setStatus({ kind: "ready" });
|
|
163
169
|
} catch (error) {
|
|
164
|
-
if (this.#
|
|
170
|
+
if (this.#lifecycle.active && revision === this.#loadRevision) {
|
|
165
171
|
this.#setStatus({ kind: "failed", error });
|
|
166
172
|
}
|
|
167
173
|
}
|
|
@@ -209,7 +215,7 @@ export class HistoryController {
|
|
|
209
215
|
|
|
210
216
|
async #navigate(target: HistoryNavigationTargetProjection): Promise<HistoryNavigationResult> {
|
|
211
217
|
const snapshot = this.#snapshot;
|
|
212
|
-
if (!this.#
|
|
218
|
+
if (!this.#lifecycle.active || snapshot === undefined) {
|
|
213
219
|
throw new HistoryControllerUnavailableError();
|
|
214
220
|
}
|
|
215
221
|
const revision = ++this.#navigationRevision;
|
|
@@ -225,20 +231,20 @@ export class HistoryController {
|
|
|
225
231
|
expectedRevision: snapshot.summary.revision,
|
|
226
232
|
target,
|
|
227
233
|
});
|
|
228
|
-
if (!this.#
|
|
234
|
+
if (!this.#lifecycle.active || revision !== this.#navigationRevision) {
|
|
229
235
|
throw new HistoryLateResultError();
|
|
230
236
|
}
|
|
231
237
|
this.#rejection = result.status === "rejected" ? result.rejection : undefined;
|
|
232
|
-
const
|
|
233
|
-
if (!this.#
|
|
238
|
+
const projection = await this.#readPageForSnapshot(result.snapshot);
|
|
239
|
+
if (!this.#lifecycle.active || revision !== this.#navigationRevision) {
|
|
234
240
|
throw new HistoryLateResultError();
|
|
235
241
|
}
|
|
236
|
-
this.#install(
|
|
242
|
+
this.#install(projection);
|
|
237
243
|
this.#setStatus({ kind: "ready" });
|
|
238
244
|
return result;
|
|
239
245
|
} catch (error) {
|
|
240
246
|
if (
|
|
241
|
-
this.#
|
|
247
|
+
this.#lifecycle.active &&
|
|
242
248
|
revision === this.#navigationRevision &&
|
|
243
249
|
!(error instanceof HistoryLateResultError)
|
|
244
250
|
) {
|
|
@@ -253,37 +259,33 @@ export class HistoryController {
|
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
async #readAuthoritativeState(): Promise<{
|
|
257
|
-
snapshot: HistorySnapshot;
|
|
258
|
-
page: HistoryPageSnapshot;
|
|
259
|
-
}> {
|
|
262
|
+
async #readAuthoritativeState(): Promise<HistoryProjection> {
|
|
260
263
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
261
264
|
const snapshot = await this.#client.snapshot();
|
|
262
|
-
const
|
|
263
|
-
if (sameAuthority(snapshot, page)) {
|
|
264
|
-
return
|
|
265
|
+
const projection = await this.#readPageForSnapshot(snapshot);
|
|
266
|
+
if (sameAuthority(snapshot, projection.page)) {
|
|
267
|
+
return projection;
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
270
|
throw new HistoryProjectionGapError();
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
async #readPageForSnapshot(snapshot: HistorySnapshot): Promise<
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.#page = Math.min(this.#page, maximumPage);
|
|
276
|
-
return this.#client.page({
|
|
273
|
+
async #readPageForSnapshot(snapshot: HistorySnapshot): Promise<HistoryProjection> {
|
|
274
|
+
const pageSize = this.#pageSize;
|
|
275
|
+
const maximumPage = Math.max(1, Math.ceil(snapshot.summary.retainedEntryCount / pageSize));
|
|
276
|
+
const pageNumber = Math.min(this.#page, maximumPage);
|
|
277
|
+
const page = await this.#client.page({
|
|
277
278
|
protocolVersion: HISTORY_PROTOCOL_VERSION,
|
|
278
279
|
authorityEpoch: snapshot.authorityEpoch,
|
|
279
280
|
historyId: snapshot.summary.historyId,
|
|
280
281
|
expectedRevision: snapshot.summary.revision,
|
|
281
|
-
offset: (
|
|
282
|
-
limit:
|
|
282
|
+
offset: (pageNumber - 1) * pageSize,
|
|
283
|
+
limit: pageSize,
|
|
283
284
|
});
|
|
285
|
+
return { snapshot, page, pageNumber };
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
#install(snapshot
|
|
288
|
+
#install({ snapshot, page, pageNumber }: HistoryProjection): void {
|
|
287
289
|
if (!sameAuthority(snapshot, page)) {
|
|
288
290
|
throw new HistoryProjectionGapError();
|
|
289
291
|
}
|
|
@@ -298,11 +300,11 @@ export class HistoryController {
|
|
|
298
300
|
}
|
|
299
301
|
this.#snapshot = snapshot;
|
|
300
302
|
this.#pageSnapshot = page;
|
|
301
|
-
this.#
|
|
303
|
+
this.#page = pageNumber;
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
#handleChanged(event: HistoryChangedEvent): void {
|
|
305
|
-
if (!this.#
|
|
307
|
+
if (!this.#lifecycle.active) {
|
|
306
308
|
return;
|
|
307
309
|
}
|
|
308
310
|
const snapshot = this.#snapshot;
|
|
@@ -323,10 +325,6 @@ export class HistoryController {
|
|
|
323
325
|
void this.refresh();
|
|
324
326
|
}
|
|
325
327
|
|
|
326
|
-
#isCurrentLifecycle(revision: number): boolean {
|
|
327
|
-
return this.#started && revision === this.#lifecycleRevision;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
328
|
#setStatus(status: HistoryControllerStatus): void {
|
|
331
329
|
this.#status = status;
|
|
332
330
|
this.#notify();
|
|
@@ -1,4 +1,4 @@
|
|
|
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.
|
|
@@ -15,4 +15,5 @@ export const HISTORY_FIELDS = {
|
|
|
15
15
|
"HistoryNavigationReceiptProjection": ["historyId", "planId", "previousRevision", "committedRevision", "direction", "movedEntryIds", "sourcePosition", "authoritativePosition"],
|
|
16
16
|
"HistoryNavigationRejectionProjection": ["code", "detail", "refreshRequired"],
|
|
17
17
|
"HistoryChangedEvent": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "kind"],
|
|
18
|
+
"HistoryHostError": ["code", "message", "retryable"],
|
|
18
19
|
} as const;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority. Product payloads are intentionally absent.
|
|
3
3
|
|
|
4
4
|
export const HISTORY_PROTOCOL_VERSION = 1 as const;
|
|
5
|
-
export const HISTORY_MAXIMUM_OPAQUE_ID_BYTES = 128 as const;
|
|
6
5
|
export const HISTORY_MAXIMUM_PROJECTION_PAGE_SIZE = 4096 as const;
|
|
7
6
|
export const HISTORY_MODES = ["linear"] as const;
|
|
8
7
|
export const HISTORY_ENTRY_POSITIONS = ["past","current","future"] as const;
|
|
@@ -151,7 +150,7 @@ encodedWeight: number,
|
|
|
151
150
|
*/
|
|
152
151
|
position: HistoryProjectionPosition, };
|
|
153
152
|
|
|
154
|
-
export type HistoryPageFloorProjection = { "kind": "origin" } | { "kind": "baseline",
|
|
153
|
+
export type HistoryPageFloorProjection = { "kind": "origin", } | { "kind": "baseline",
|
|
155
154
|
/**
|
|
156
155
|
* How many entries were pruned before the oldest retained one.
|
|
157
156
|
*/
|
|
@@ -232,11 +231,11 @@ retainedBaseline: HistoryBaselineProjection,
|
|
|
232
231
|
*/
|
|
233
232
|
floor: HistoryPageFloorProjection, };
|
|
234
233
|
|
|
235
|
-
export type HistoryNavigationTargetProjection = { "kind": "undo" } | { "kind": "redo" } | { "kind": "checkout",
|
|
234
|
+
export type HistoryNavigationTargetProjection = { "kind": "undo", } | { "kind": "redo", } | { "kind": "checkout",
|
|
236
235
|
/**
|
|
237
236
|
* Stable entry identity, never a presentation index.
|
|
238
237
|
*/
|
|
239
|
-
entryId: HistoryEntryId, } | { "kind": "checkoutRoot" };
|
|
238
|
+
entryId: HistoryEntryId, } | { "kind": "checkoutRoot", };
|
|
240
239
|
|
|
241
240
|
export type HistoryNavigationCommand = {
|
|
242
241
|
/**
|
|
@@ -387,3 +386,7 @@ committedRevision: HistoryRevision,
|
|
|
387
386
|
* Coarse transition category.
|
|
388
387
|
*/
|
|
389
388
|
kind: HistoryChangedKind, };
|
|
389
|
+
|
|
390
|
+
export type HistoryHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
|
|
391
|
+
|
|
392
|
+
export type HistoryHostError = { "code": HistoryHostErrorCode, "message": string, "retryable": boolean, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
3
|
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
4
|
// each list, because `exact()` compares every key.
|
package/src/history/ports.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
2
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
3
|
import type {
|
|
2
4
|
HistoryChangedEvent,
|
|
3
5
|
HistoryNavigationCommand,
|
|
@@ -8,7 +10,7 @@ import type {
|
|
|
8
10
|
HistorySnapshot,
|
|
9
11
|
} from "./generated/protocol.ts";
|
|
10
12
|
|
|
11
|
-
export type HistoryUnlisten =
|
|
13
|
+
export type HistoryUnlisten = Unlisten;
|
|
12
14
|
|
|
13
15
|
export interface HistoryPort {
|
|
14
16
|
snapshot(): Promise<unknown>;
|
|
@@ -24,6 +26,9 @@ export interface CheckedHistoryPort {
|
|
|
24
26
|
snapshot(): Promise<HistorySnapshot>;
|
|
25
27
|
page(command: HistoryPageCommand): Promise<HistoryPageSnapshot>;
|
|
26
28
|
navigate(command: HistoryNavigationCommand): Promise<HistoryNavigationResult>;
|
|
27
|
-
listen?(
|
|
29
|
+
listen?(
|
|
30
|
+
listener: (event: HistoryChangedEvent) => void,
|
|
31
|
+
onFailure?: ConnectionFailureReporter,
|
|
32
|
+
): Promise<HistoryUnlisten>;
|
|
28
33
|
nextPlanId(): HistoryPlanId;
|
|
29
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
2
3
|
import {
|
|
3
|
-
HISTORY_MAXIMUM_OPAQUE_ID_BYTES,
|
|
4
4
|
HISTORY_CHANGED_KINDS,
|
|
5
5
|
HISTORY_ENTRY_POSITIONS,
|
|
6
6
|
HISTORY_PAGE_FLOORS,
|
|
@@ -204,10 +204,8 @@ function protocol(value: unknown, path: string): void {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
function object(value: unknown, path: string): Record<string, unknown> {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
return value;
|
|
207
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
208
|
+
return result;
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
function array(value: unknown, path: string): ReadonlyArray<unknown> {
|
|
@@ -218,17 +216,9 @@ function array(value: unknown, path: string): ReadonlyArray<unknown> {
|
|
|
218
216
|
}
|
|
219
217
|
|
|
220
218
|
function keys(value: Record<string, unknown>, path: string, allowed: ReadonlyArray<string>): void {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
fail(`${path}.${key}`, "unknown field");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
for (const key of allowed) {
|
|
228
|
-
if (!(key in value)) {
|
|
229
|
-
fail(`${path}.${key}`, "missing field");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
219
|
+
checkWireFields(value, allowed, (code, key) =>
|
|
220
|
+
fail(`${path}.${key}`, code === "unknown_field" ? "unknown field" : "missing field"),
|
|
221
|
+
);
|
|
232
222
|
}
|
|
233
223
|
|
|
234
224
|
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
@@ -238,12 +228,7 @@ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): voi
|
|
|
238
228
|
}
|
|
239
229
|
|
|
240
230
|
function id(value: unknown, path: string): void {
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
value.length === 0 ||
|
|
244
|
-
value.length > HISTORY_MAXIMUM_OPAQUE_ID_BYTES ||
|
|
245
|
-
!/^[a-z0-9._:-]+$/.test(value)
|
|
246
|
-
) {
|
|
231
|
+
if (!isOpaqueId(value)) {
|
|
247
232
|
fail(path, "expected bounded lowercase opaque id");
|
|
248
233
|
}
|
|
249
234
|
}
|
|
@@ -328,23 +313,16 @@ function floor(value: unknown, path: string): void {
|
|
|
328
313
|
}
|
|
329
314
|
}
|
|
330
315
|
|
|
331
|
-
/**
|
|
332
|
-
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
333
|
-
* discriminant's name read from the map too.
|
|
334
|
-
*
|
|
335
|
-
* A missing entry means the generator failed to read the union: every caller
|
|
336
|
-
* checks the discriminant above this call.
|
|
337
|
-
*/
|
|
338
316
|
function variantKeys(
|
|
339
317
|
type: string,
|
|
340
318
|
record: Record<string, unknown>,
|
|
341
319
|
path: string,
|
|
342
320
|
): ReadonlyArray<string> {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
321
|
+
return wireVariantFields(
|
|
322
|
+
HISTORY_VARIANT_FIELDS,
|
|
323
|
+
HISTORY_VARIANT_FIELDS_DISCRIMINANTS,
|
|
324
|
+
type,
|
|
325
|
+
record,
|
|
326
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
327
|
+
);
|
|
350
328
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { listenChecked } from "../core/connection.ts";
|
|
2
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
1
3
|
import {
|
|
2
4
|
assertForkBranchCommand,
|
|
3
5
|
assertForkBranchPage,
|
|
4
6
|
assertForkContinuationCommand,
|
|
5
7
|
assertForkContinuationPage,
|
|
6
8
|
assertForkDeleteCommand,
|
|
9
|
+
assertForkDeleteResult,
|
|
7
10
|
assertForkPruneCommand,
|
|
8
11
|
assertForkPruneResult,
|
|
9
|
-
assertForkRemovalReceipt,
|
|
10
12
|
assertForkChangedEvent,
|
|
11
13
|
assertForkNavigationCommand,
|
|
12
14
|
assertForkNavigationResult,
|
|
@@ -23,7 +25,7 @@ import type {
|
|
|
23
25
|
ForkDeleteContinuationCommand,
|
|
24
26
|
ForkPruneCommand,
|
|
25
27
|
ForkPruneResult,
|
|
26
|
-
|
|
28
|
+
ForkDeleteResult,
|
|
27
29
|
ForkNavigationCommand,
|
|
28
30
|
ForkNavigationResult,
|
|
29
31
|
ForkPathPageCommand,
|
|
@@ -60,12 +62,10 @@ export class ForkHistoryClient implements CheckedForkHistoryPort {
|
|
|
60
62
|
assertForkContinuationPage(value);
|
|
61
63
|
return value;
|
|
62
64
|
}
|
|
63
|
-
async deleteContinuation(
|
|
64
|
-
command: ForkDeleteContinuationCommand,
|
|
65
|
-
): Promise<ForkRemovalReceiptProjection> {
|
|
65
|
+
async deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkDeleteResult> {
|
|
66
66
|
assertForkDeleteCommand(command);
|
|
67
67
|
const value = await this.port.deleteContinuation(command);
|
|
68
|
-
|
|
68
|
+
assertForkDeleteResult(value);
|
|
69
69
|
return value;
|
|
70
70
|
}
|
|
71
71
|
async prune(command: ForkPruneCommand): Promise<ForkPruneResult> {
|
|
@@ -80,13 +80,15 @@ export class ForkHistoryClient implements CheckedForkHistoryPort {
|
|
|
80
80
|
assertForkNavigationResult(value);
|
|
81
81
|
return value;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
listen(
|
|
84
|
+
listener: (event: ForkChangedEvent) => void,
|
|
85
|
+
onFailure?: ConnectionFailureReporter,
|
|
86
|
+
): Promise<ForkHistoryUnlisten> {
|
|
87
|
+
return listenChecked({
|
|
88
|
+
listen: (receive) => this.port.listen?.(receive) ?? (() => {}),
|
|
89
|
+
validate: assertForkChangedEvent,
|
|
90
|
+
listener,
|
|
91
|
+
onFailure,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
}
|