@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,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
HistoryPageCommand,
|
|
4
|
-
} from "./generated/protocol.ts";
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
2
|
+
import type { HistoryNavigationCommand, HistoryPageCommand } from "./generated/protocol.ts";
|
|
5
3
|
import type { HistoryPort, HistoryUnlisten } from "./ports.ts";
|
|
6
4
|
|
|
7
5
|
export class SerializedHistoryPort implements HistoryPort {
|
|
@@ -12,27 +10,25 @@ export class SerializedHistoryPort implements HistoryPort {
|
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
async snapshot(): Promise<unknown> {
|
|
15
|
-
return
|
|
13
|
+
return wireCopy(await this.#inner.snapshot());
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
async page(command: HistoryPageCommand): Promise<unknown> {
|
|
19
|
-
return
|
|
17
|
+
return wireCopy(await this.#inner.page(wireCopy(command)));
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
async navigate(command: HistoryNavigationCommand): Promise<unknown> {
|
|
23
|
-
return
|
|
21
|
+
return wireCopy(await this.#inner.navigate(wireCopy(command)));
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
async listen(listener: (event: unknown) => void): Promise<HistoryUnlisten> {
|
|
27
|
-
if (this.#inner.listen === undefined)
|
|
28
|
-
|
|
25
|
+
if (this.#inner.listen === undefined) {
|
|
26
|
+
return () => {};
|
|
27
|
+
}
|
|
28
|
+
return this.#inner.listen((event) => listener(wireCopy(event)));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
nextPlanId(): string {
|
|
32
32
|
return this.#inner.nextPlanId();
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
function clone<Value>(value: Value): Value {
|
|
37
|
-
return JSON.parse(JSON.stringify(value)) as Value;
|
|
38
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
1
3
|
import {
|
|
2
|
-
HISTORY_MAXIMUM_OPAQUE_ID_BYTES,
|
|
3
4
|
HISTORY_CHANGED_KINDS,
|
|
4
5
|
HISTORY_ENTRY_POSITIONS,
|
|
5
6
|
HISTORY_PAGE_FLOORS,
|
|
@@ -9,12 +10,14 @@ import {
|
|
|
9
10
|
HISTORY_NAVIGATION_STATUSES,
|
|
10
11
|
HISTORY_NAVIGATION_TARGETS,
|
|
11
12
|
HISTORY_PROTOCOL_VERSION,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
} from "./generated/protocol.ts";
|
|
14
|
+
import type {
|
|
15
|
+
HistoryChangedEvent,
|
|
16
|
+
HistoryNavigationCommand,
|
|
17
|
+
HistoryNavigationResult,
|
|
18
|
+
HistoryPageCommand,
|
|
19
|
+
HistoryPageSnapshot,
|
|
20
|
+
HistorySnapshot,
|
|
18
21
|
} from "./generated/protocol.ts";
|
|
19
22
|
import { HISTORY_FIELDS } from "./generated/fields.ts";
|
|
20
23
|
import {
|
|
@@ -23,15 +26,16 @@ import {
|
|
|
23
26
|
} from "./generated/variant-fields.ts";
|
|
24
27
|
|
|
25
28
|
export class HistoryProtocolValidationError extends Error {
|
|
26
|
-
constructor(
|
|
29
|
+
constructor(
|
|
30
|
+
readonly path: string,
|
|
31
|
+
message: string,
|
|
32
|
+
) {
|
|
27
33
|
super(`${path}: ${message}`);
|
|
28
34
|
this.name = "HistoryProtocolValidationError";
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
export function assertValidHistorySnapshot(
|
|
33
|
-
value: unknown,
|
|
34
|
-
): asserts value is HistorySnapshot {
|
|
38
|
+
export function assertValidHistorySnapshot(value: unknown): asserts value is HistorySnapshot {
|
|
35
39
|
assertNoPayload(value, "$");
|
|
36
40
|
const record = object(value, "$");
|
|
37
41
|
keys(record, "$", HISTORY_FIELDS.HistorySnapshot);
|
|
@@ -40,9 +44,7 @@ export function assertValidHistorySnapshot(
|
|
|
40
44
|
summary(record.summary, "$.summary");
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
export function assertValidHistoryPageCommand(
|
|
44
|
-
value: unknown,
|
|
45
|
-
): asserts value is HistoryPageCommand {
|
|
47
|
+
export function assertValidHistoryPageCommand(value: unknown): asserts value is HistoryPageCommand {
|
|
46
48
|
assertNoPayload(value, "$");
|
|
47
49
|
const record = object(value, "$");
|
|
48
50
|
keys(record, "$", HISTORY_FIELDS.HistoryPageCommand);
|
|
@@ -173,10 +175,7 @@ function receipt(value: unknown, path: string): void {
|
|
|
173
175
|
id(entry, `${path}.movedEntryIds[${index}]`),
|
|
174
176
|
);
|
|
175
177
|
navigationPosition(record.sourcePosition, `${path}.sourcePosition`);
|
|
176
|
-
navigationPosition(
|
|
177
|
-
record.authoritativePosition,
|
|
178
|
-
`${path}.authoritativePosition`,
|
|
179
|
-
);
|
|
178
|
+
navigationPosition(record.authoritativePosition, `${path}.authoritativePosition`);
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
function navigationPosition(value: unknown, path: string): void {
|
|
@@ -193,11 +192,7 @@ function navigationPosition(value: unknown, path: string): void {
|
|
|
193
192
|
function rejection(value: unknown, path: string): void {
|
|
194
193
|
const record = object(value, path);
|
|
195
194
|
keys(record, path, HISTORY_FIELDS.HistoryNavigationRejectionProjection);
|
|
196
|
-
oneOf(
|
|
197
|
-
record.code,
|
|
198
|
-
`${path}.code`,
|
|
199
|
-
HISTORY_NAVIGATION_REJECTION_CODES,
|
|
200
|
-
);
|
|
195
|
+
oneOf(record.code, `${path}.code`, HISTORY_NAVIGATION_REJECTION_CODES);
|
|
201
196
|
string(record.detail, `${path}.detail`);
|
|
202
197
|
boolean(record.refreshRequired, `${path}.refreshRequired`);
|
|
203
198
|
}
|
|
@@ -209,83 +204,76 @@ function protocol(value: unknown, path: string): void {
|
|
|
209
204
|
}
|
|
210
205
|
|
|
211
206
|
function object(value: unknown, path: string): Record<string, unknown> {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return value as Record<string, unknown>;
|
|
207
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
208
|
+
return result;
|
|
216
209
|
}
|
|
217
210
|
|
|
218
|
-
function array(value: unknown, path: string):
|
|
219
|
-
if (!Array.isArray(value))
|
|
211
|
+
function array(value: unknown, path: string): ReadonlyArray<unknown> {
|
|
212
|
+
if (!Array.isArray(value)) {
|
|
213
|
+
fail(path, "expected array");
|
|
214
|
+
}
|
|
220
215
|
return value;
|
|
221
216
|
}
|
|
222
217
|
|
|
223
|
-
function keys(
|
|
224
|
-
value
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
): void {
|
|
228
|
-
const allowedSet = new Set(allowed);
|
|
229
|
-
for (const key of Object.keys(value)) {
|
|
230
|
-
if (!allowedSet.has(key)) fail(`${path}.${key}`, "unknown field");
|
|
231
|
-
}
|
|
232
|
-
for (const key of allowed) {
|
|
233
|
-
if (!(key in value)) fail(`${path}.${key}`, "missing field");
|
|
234
|
-
}
|
|
218
|
+
function keys(value: Record<string, unknown>, path: string, allowed: ReadonlyArray<string>): void {
|
|
219
|
+
checkWireFields(value, allowed, (code, key) =>
|
|
220
|
+
fail(`${path}.${key}`, code === "unknown_field" ? "unknown field" : "missing field"),
|
|
221
|
+
);
|
|
235
222
|
}
|
|
236
223
|
|
|
237
|
-
function oneOf(
|
|
238
|
-
value: unknown,
|
|
239
|
-
path: string,
|
|
240
|
-
values: readonly string[],
|
|
241
|
-
): void {
|
|
224
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
242
225
|
if (typeof value !== "string" || !values.includes(value)) {
|
|
243
226
|
fail(path, `expected one of ${values.join(", ")}`);
|
|
244
227
|
}
|
|
245
228
|
}
|
|
246
229
|
|
|
247
230
|
function id(value: unknown, path: string): void {
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
(value as string).length === 0 ||
|
|
251
|
-
(value as string).length > HISTORY_MAXIMUM_OPAQUE_ID_BYTES ||
|
|
252
|
-
!/^[a-z0-9._:-]+$/.test(value as string)
|
|
253
|
-
) {
|
|
231
|
+
if (!isOpaqueId(value)) {
|
|
254
232
|
fail(path, "expected bounded lowercase opaque id");
|
|
255
233
|
}
|
|
256
234
|
}
|
|
257
235
|
|
|
258
236
|
function optionalId(value: unknown, path: string): void {
|
|
259
|
-
if (value !== null)
|
|
237
|
+
if (value !== null) {
|
|
238
|
+
id(value, path);
|
|
239
|
+
}
|
|
260
240
|
}
|
|
261
241
|
|
|
262
|
-
function string(value: unknown, path: string):
|
|
242
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
263
243
|
if (typeof value !== "string" || value.length === 0) {
|
|
264
244
|
fail(path, "expected nonempty string");
|
|
265
245
|
}
|
|
266
246
|
}
|
|
267
247
|
|
|
268
248
|
function optionalString(value: unknown, path: string): void {
|
|
269
|
-
if (value !== null)
|
|
249
|
+
if (value !== null) {
|
|
250
|
+
string(value, path);
|
|
251
|
+
}
|
|
270
252
|
}
|
|
271
253
|
|
|
272
|
-
function integer(value: unknown, path: string):
|
|
273
|
-
if (!Number.isSafeInteger(value) ||
|
|
254
|
+
function integer(value: unknown, path: string): asserts value is number {
|
|
255
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
274
256
|
fail(path, "expected nonnegative safe integer");
|
|
275
257
|
}
|
|
276
258
|
}
|
|
277
259
|
|
|
278
260
|
function positiveInteger(value: unknown, path: string): void {
|
|
279
261
|
integer(value, path);
|
|
280
|
-
if (
|
|
262
|
+
if (value === 0) {
|
|
263
|
+
fail(path, "expected nonzero integer");
|
|
264
|
+
}
|
|
281
265
|
}
|
|
282
266
|
|
|
283
267
|
function optionalInteger(value: unknown, path: string): void {
|
|
284
|
-
if (value !== null)
|
|
268
|
+
if (value !== null) {
|
|
269
|
+
integer(value, path);
|
|
270
|
+
}
|
|
285
271
|
}
|
|
286
272
|
|
|
287
273
|
function boolean(value: unknown, path: string): void {
|
|
288
|
-
if (typeof value !== "boolean")
|
|
274
|
+
if (typeof value !== "boolean") {
|
|
275
|
+
fail(path, "expected boolean");
|
|
276
|
+
}
|
|
289
277
|
}
|
|
290
278
|
|
|
291
279
|
function assertNoPayload(value: unknown, path: string): void {
|
|
@@ -293,9 +281,13 @@ function assertNoPayload(value: unknown, path: string): void {
|
|
|
293
281
|
value.forEach((entry, index) => assertNoPayload(entry, `${path}[${index}]`));
|
|
294
282
|
return;
|
|
295
283
|
}
|
|
296
|
-
if (typeof value !== "object" || value === null)
|
|
284
|
+
if (typeof value !== "object" || value === null) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
297
287
|
for (const [key, child] of Object.entries(value)) {
|
|
298
|
-
if (key === "payload")
|
|
288
|
+
if (key === "payload") {
|
|
289
|
+
fail(`${path}.payload`, "product payload is forbidden");
|
|
290
|
+
}
|
|
299
291
|
assertNoPayload(child, `${path}.${key}`);
|
|
300
292
|
}
|
|
301
293
|
}
|
|
@@ -316,19 +308,21 @@ function floor(value: unknown, path: string): void {
|
|
|
316
308
|
const record = object(value, path);
|
|
317
309
|
oneOf(record.kind, `${path}.kind`, HISTORY_PAGE_FLOORS);
|
|
318
310
|
keys(record, path, variantKeys("HistoryPageFloorProjection", record, path));
|
|
319
|
-
if (record.kind === "baseline")
|
|
311
|
+
if (record.kind === "baseline") {
|
|
312
|
+
integer(record.prunedEntryCount, `${path}.prunedEntryCount`);
|
|
313
|
+
}
|
|
320
314
|
}
|
|
321
315
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
316
|
+
function variantKeys(
|
|
317
|
+
type: string,
|
|
318
|
+
record: Record<string, unknown>,
|
|
319
|
+
path: string,
|
|
320
|
+
): ReadonlyArray<string> {
|
|
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
|
+
);
|
|
334
328
|
}
|
|
@@ -1,16 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { listenChecked } from "../core/connection.ts";
|
|
2
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
3
|
+
import {
|
|
4
|
+
assertForkBranchCommand,
|
|
5
|
+
assertForkBranchPage,
|
|
6
|
+
assertForkContinuationCommand,
|
|
7
|
+
assertForkContinuationPage,
|
|
8
|
+
assertForkDeleteCommand,
|
|
9
|
+
assertForkDeleteResult,
|
|
10
|
+
assertForkPruneCommand,
|
|
11
|
+
assertForkPruneResult,
|
|
12
|
+
assertForkChangedEvent,
|
|
13
|
+
assertForkNavigationCommand,
|
|
14
|
+
assertForkNavigationResult,
|
|
15
|
+
assertForkPathCommand,
|
|
16
|
+
assertForkPathPage,
|
|
17
|
+
assertForkSnapshot,
|
|
18
|
+
} from "./validation.ts";
|
|
19
|
+
import type {
|
|
20
|
+
ForkBranchPageCommand,
|
|
21
|
+
ForkBranchPageSnapshot,
|
|
22
|
+
ForkChangedEvent,
|
|
23
|
+
ForkContinuationPageCommand,
|
|
24
|
+
ForkContinuationPageSnapshot,
|
|
25
|
+
ForkDeleteContinuationCommand,
|
|
26
|
+
ForkPruneCommand,
|
|
27
|
+
ForkPruneResult,
|
|
28
|
+
ForkDeleteResult,
|
|
29
|
+
ForkNavigationCommand,
|
|
30
|
+
ForkNavigationResult,
|
|
31
|
+
ForkPathPageCommand,
|
|
32
|
+
ForkPathPageSnapshot,
|
|
33
|
+
ForkSnapshot,
|
|
34
|
+
} from "./generated/protocol.ts";
|
|
3
35
|
import type { CheckedForkHistoryPort, ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
|
|
4
36
|
|
|
5
37
|
export class ForkHistoryClient implements CheckedForkHistoryPort {
|
|
6
38
|
constructor(readonly port: ForkHistoryPort) {}
|
|
7
|
-
nextPlanId(): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async
|
|
39
|
+
nextPlanId(): string {
|
|
40
|
+
return this.port.nextPlanId();
|
|
41
|
+
}
|
|
42
|
+
async snapshot(): Promise<ForkSnapshot> {
|
|
43
|
+
const value = await this.port.snapshot();
|
|
44
|
+
assertForkSnapshot(value);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
async path(command: ForkPathPageCommand): Promise<ForkPathPageSnapshot> {
|
|
48
|
+
assertForkPathCommand(command);
|
|
49
|
+
const value = await this.port.path(command);
|
|
50
|
+
assertForkPathPage(value);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
async branches(command: ForkBranchPageCommand): Promise<ForkBranchPageSnapshot> {
|
|
54
|
+
assertForkBranchCommand(command);
|
|
55
|
+
const value = await this.port.branches(command);
|
|
56
|
+
assertForkBranchPage(value);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
async continuations(command: ForkContinuationPageCommand): Promise<ForkContinuationPageSnapshot> {
|
|
60
|
+
assertForkContinuationCommand(command);
|
|
61
|
+
const value = await this.port.continuations(command);
|
|
62
|
+
assertForkContinuationPage(value);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
async deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkDeleteResult> {
|
|
66
|
+
assertForkDeleteCommand(command);
|
|
67
|
+
const value = await this.port.deleteContinuation(command);
|
|
68
|
+
assertForkDeleteResult(value);
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
async prune(command: ForkPruneCommand): Promise<ForkPruneResult> {
|
|
72
|
+
assertForkPruneCommand(command);
|
|
73
|
+
const value = await this.port.prune(command);
|
|
74
|
+
assertForkPruneResult(value);
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
async navigate(command: ForkNavigationCommand): Promise<ForkNavigationResult> {
|
|
78
|
+
assertForkNavigationCommand(command);
|
|
79
|
+
const value = await this.port.navigate(command);
|
|
80
|
+
assertForkNavigationResult(value);
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
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,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
16
94
|
}
|