@inflatable-cookie/longhorn 0.5.0 → 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,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
1
2
|
import {
|
|
2
3
|
COMMAND_VARIANT_FIELDS,
|
|
3
4
|
COMMAND_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -13,24 +14,29 @@ import {
|
|
|
13
14
|
COMMAND_KEYMAP_PROTOCOL_VERSION,
|
|
14
15
|
COMMAND_KEYMAP_RECOVERY_CODES,
|
|
15
16
|
COMMAND_KEYMAP_REJECTION_CODES,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
} from "./generated/protocol.ts";
|
|
18
|
+
import type {
|
|
19
|
+
CommandCatalogueSnapshot,
|
|
20
|
+
CommandAvailabilitySnapshot,
|
|
21
|
+
CommandCatalogueChangedEvent,
|
|
22
|
+
CommandKeymapChangedEvent,
|
|
23
|
+
CommandKeymapCommit,
|
|
24
|
+
CommandKeymapLoadOutcome,
|
|
25
|
+
CommandKeymapMutationResult,
|
|
26
|
+
CommandKeymapPreview,
|
|
27
|
+
CommandKeymapPreviewResult,
|
|
28
|
+
CommandKeymapReset,
|
|
29
|
+
CommandKeymapSnapshot,
|
|
27
30
|
} from "./generated/protocol.ts";
|
|
28
31
|
import { COMMANDS_FIELDS } from "./generated/fields.ts";
|
|
29
32
|
|
|
30
33
|
export class CommandProtocolValidationError extends Error {
|
|
31
34
|
readonly code = "command_protocol_incompatible";
|
|
32
35
|
|
|
33
|
-
constructor(
|
|
36
|
+
constructor(
|
|
37
|
+
readonly path: string,
|
|
38
|
+
detail: string,
|
|
39
|
+
) {
|
|
34
40
|
super(`${path}: ${detail}`);
|
|
35
41
|
this.name = "CommandProtocolValidationError";
|
|
36
42
|
}
|
|
@@ -67,55 +73,34 @@ export function assertValidCommandAvailabilitySnapshot(
|
|
|
67
73
|
const item = object(entry, `$.records[${index}]`);
|
|
68
74
|
const commandId = text(item.commandId, `$.records[${index}].commandId`);
|
|
69
75
|
if (index > 0 && commandId <= previous) {
|
|
70
|
-
fail(
|
|
71
|
-
`$.records[${index}].commandId`,
|
|
72
|
-
"expected unique command-id order",
|
|
73
|
-
);
|
|
76
|
+
fail(`$.records[${index}].commandId`, "expected unique command-id order");
|
|
74
77
|
}
|
|
75
78
|
previous = commandId;
|
|
76
|
-
const availability = object(
|
|
77
|
-
item.availability,
|
|
78
|
-
`$.records[${index}].availability`,
|
|
79
|
-
);
|
|
79
|
+
const availability = object(item.availability, `$.records[${index}].availability`);
|
|
80
80
|
member(
|
|
81
81
|
availability.state,
|
|
82
82
|
["available", "unavailable", "hidden", "unsupported"],
|
|
83
83
|
`$.records[${index}].availability.state`,
|
|
84
84
|
);
|
|
85
|
-
if (
|
|
86
|
-
(availability.state === "available") !==
|
|
87
|
-
(availability.reason === null)
|
|
88
|
-
) {
|
|
85
|
+
if ((availability.state === "available") !== (availability.reason === null)) {
|
|
89
86
|
fail(
|
|
90
87
|
`$.records[${index}].availability.reason`,
|
|
91
88
|
"available requires no reason; every other state requires one",
|
|
92
89
|
);
|
|
93
90
|
}
|
|
94
91
|
if (availability.reason !== null) {
|
|
95
|
-
const reason = object(
|
|
96
|
-
availability.reason,
|
|
97
|
-
`$.records[${index}].availability.reason`,
|
|
98
|
-
);
|
|
92
|
+
const reason = object(availability.reason, `$.records[${index}].availability.reason`);
|
|
99
93
|
if (reason.detail !== null) {
|
|
100
|
-
text(
|
|
101
|
-
reason.detail,
|
|
102
|
-
`$.records[${index}].availability.reason.detail`,
|
|
103
|
-
);
|
|
94
|
+
text(reason.detail, `$.records[${index}].availability.reason.detail`);
|
|
104
95
|
}
|
|
105
|
-
const code = object(
|
|
106
|
-
reason.code,
|
|
107
|
-
`$.records[${index}].availability.reason.code`,
|
|
108
|
-
);
|
|
96
|
+
const code = object(reason.code, `$.records[${index}].availability.reason.code`);
|
|
109
97
|
member(
|
|
110
98
|
code.kind,
|
|
111
99
|
["contextNotAllowed", "missingCapability", "consumer"],
|
|
112
100
|
`$.records[${index}].availability.reason.code.kind`,
|
|
113
101
|
);
|
|
114
102
|
if (code.kind === "consumer") {
|
|
115
|
-
text(
|
|
116
|
-
code.code,
|
|
117
|
-
`$.records[${index}].availability.reason.code.code`,
|
|
118
|
-
);
|
|
103
|
+
text(code.code, `$.records[${index}].availability.reason.code.code`);
|
|
119
104
|
}
|
|
120
105
|
}
|
|
121
106
|
});
|
|
@@ -182,17 +167,12 @@ export function assertValidCommandKeymapCommit(
|
|
|
182
167
|
finiteInteger(evidence.registryGeneration, "$.evidence.registryGeneration");
|
|
183
168
|
finiteInteger(evidence.keymapRevision, "$.evidence.keymapRevision");
|
|
184
169
|
text(evidence.activePresetId, "$.evidence.activePresetId");
|
|
185
|
-
positiveInteger(
|
|
186
|
-
evidence.activePresetVersion,
|
|
187
|
-
"$.evidence.activePresetVersion",
|
|
188
|
-
);
|
|
170
|
+
positiveInteger(evidence.activePresetVersion, "$.evidence.activePresetVersion");
|
|
189
171
|
digest(evidence.patchDigest, "$.evidence.patchDigest");
|
|
190
172
|
keymapPatch(record.patch, "$.patch");
|
|
191
173
|
}
|
|
192
174
|
|
|
193
|
-
export function assertValidCommandKeymapReset(
|
|
194
|
-
value: unknown,
|
|
195
|
-
): asserts value is CommandKeymapReset {
|
|
175
|
+
export function assertValidCommandKeymapReset(value: unknown): asserts value is CommandKeymapReset {
|
|
196
176
|
const record = object(value, "$", COMMANDS_FIELDS.CommandKeymapReset);
|
|
197
177
|
text(record.requestId, "$.requestId");
|
|
198
178
|
baseRequest(value, "$");
|
|
@@ -239,27 +219,15 @@ export function assertValidCommandKeymapMutationResult(
|
|
|
239
219
|
assertValidCommandKeymapSnapshot(record.snapshot);
|
|
240
220
|
if (record.status === "applied") {
|
|
241
221
|
const receipt = object(record.receipt, "$.receipt");
|
|
242
|
-
member(
|
|
243
|
-
|
|
244
|
-
COMMAND_KEYMAP_MUTATION_OUTCOMES,
|
|
245
|
-
"$.receipt.outcome",
|
|
246
|
-
);
|
|
247
|
-
member(
|
|
248
|
-
receipt.durability,
|
|
249
|
-
COMMAND_KEYMAP_DURABILITIES,
|
|
250
|
-
"$.receipt.durability",
|
|
251
|
-
);
|
|
222
|
+
member(receipt.outcome, COMMAND_KEYMAP_MUTATION_OUTCOMES, "$.receipt.outcome");
|
|
223
|
+
member(receipt.durability, COMMAND_KEYMAP_DURABILITIES, "$.receipt.durability");
|
|
252
224
|
} else if (record.status === "rejected") {
|
|
253
225
|
rejection(record.rejection, "$.rejection");
|
|
254
226
|
array(record.conflicts, "$.conflicts");
|
|
255
227
|
}
|
|
256
228
|
}
|
|
257
229
|
|
|
258
|
-
function baseRequest(
|
|
259
|
-
value: unknown,
|
|
260
|
-
path: string,
|
|
261
|
-
allowed?: readonly string[],
|
|
262
|
-
): void {
|
|
230
|
+
function baseRequest(value: unknown, path: string, allowed?: ReadonlyArray<string>): void {
|
|
263
231
|
const record = object(value, path, allowed);
|
|
264
232
|
finiteInteger(record.registryGeneration, `${path}.registryGeneration`);
|
|
265
233
|
finiteInteger(record.keymapRevision, `${path}.keymapRevision`);
|
|
@@ -269,21 +237,17 @@ function baseRequest(
|
|
|
269
237
|
|
|
270
238
|
function keymapPatch(value: unknown, path: string): void {
|
|
271
239
|
const record = object(value, path, COMMANDS_FIELDS.CommandKeymapPatch);
|
|
272
|
-
if (
|
|
273
|
-
record.activePresetId !== null &&
|
|
274
|
-
typeof record.activePresetId !== "string"
|
|
275
|
-
) {
|
|
240
|
+
if (record.activePresetId !== null && typeof record.activePresetId !== "string") {
|
|
276
241
|
fail(`${path}.activePresetId`, "expected string or null");
|
|
277
242
|
}
|
|
278
243
|
if (typeof record.clearOverrides !== "boolean") {
|
|
279
244
|
fail(`${path}.clearOverrides`, "expected boolean");
|
|
280
245
|
}
|
|
281
|
-
array(record.removeBindingIds, `${path}.removeBindingIds`).forEach(
|
|
282
|
-
|
|
246
|
+
array(record.removeBindingIds, `${path}.removeBindingIds`).forEach((id, index) =>
|
|
247
|
+
text(id, `${path}.removeBindingIds[${index}]`),
|
|
283
248
|
);
|
|
284
|
-
array(record.upsertOverrides, `${path}.upsertOverrides`).forEach(
|
|
285
|
-
(override, index)
|
|
286
|
-
keymapOverride(override, `${path}.upsertOverrides[${index}]`),
|
|
249
|
+
array(record.upsertOverrides, `${path}.upsertOverrides`).forEach((override, index) =>
|
|
250
|
+
keymapOverride(override, `${path}.upsertOverrides[${index}]`),
|
|
287
251
|
);
|
|
288
252
|
}
|
|
289
253
|
|
|
@@ -301,13 +265,11 @@ function keymapOverride(value: unknown, path: string): void {
|
|
|
301
265
|
}
|
|
302
266
|
}
|
|
303
267
|
|
|
304
|
-
function bindingDefinition(
|
|
305
|
-
value: unknown,
|
|
306
|
-
path: string,
|
|
307
|
-
requireId = true,
|
|
308
|
-
): void {
|
|
268
|
+
function bindingDefinition(value: unknown, path: string, requireId = true): void {
|
|
309
269
|
const record = object(value, path);
|
|
310
|
-
if (requireId)
|
|
270
|
+
if (requireId) {
|
|
271
|
+
text(record.id, `${path}.id`);
|
|
272
|
+
}
|
|
311
273
|
text(record.commandId, `${path}.commandId`);
|
|
312
274
|
text(record.contextId, `${path}.contextId`);
|
|
313
275
|
const trigger = object(record.trigger, `${path}.trigger`);
|
|
@@ -333,7 +295,9 @@ function argumentSchema(value: unknown, path: string): void {
|
|
|
333
295
|
const record = object(value, path);
|
|
334
296
|
member(record.shape, ["none", "object"], `${path}.shape`);
|
|
335
297
|
object(record, path, variantKeys("CommandArgumentSchema", record, path));
|
|
336
|
-
if (record.shape === "object")
|
|
298
|
+
if (record.shape === "object") {
|
|
299
|
+
array(record.fields, `${path}.fields`);
|
|
300
|
+
}
|
|
337
301
|
}
|
|
338
302
|
|
|
339
303
|
function rejection(value: unknown, path: string): void {
|
|
@@ -363,15 +327,13 @@ function text(value: unknown, path: string): string {
|
|
|
363
327
|
|
|
364
328
|
function positiveInteger(value: unknown, path: string): void {
|
|
365
329
|
finiteInteger(value, path);
|
|
366
|
-
if (
|
|
330
|
+
if (value < 1) {
|
|
331
|
+
fail(path, "expected positive integer");
|
|
332
|
+
}
|
|
367
333
|
}
|
|
368
334
|
|
|
369
|
-
function finiteInteger(value: unknown, path: string):
|
|
370
|
-
if (
|
|
371
|
-
typeof value !== "number" ||
|
|
372
|
-
!Number.isSafeInteger(value) ||
|
|
373
|
-
value < 0
|
|
374
|
-
) {
|
|
335
|
+
function finiteInteger(value: unknown, path: string): asserts value is number {
|
|
336
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
375
337
|
fail(path, "expected non-negative safe integer");
|
|
376
338
|
}
|
|
377
339
|
}
|
|
@@ -387,30 +349,38 @@ function finiteInteger(value: unknown, path: string): void {
|
|
|
387
349
|
function object(
|
|
388
350
|
value: unknown,
|
|
389
351
|
path: string,
|
|
390
|
-
allowed?:
|
|
352
|
+
allowed?: ReadonlyArray<string>,
|
|
391
353
|
): Record<string, unknown> {
|
|
392
|
-
if (
|
|
354
|
+
if (!isRecord(value)) {
|
|
393
355
|
fail(path, "expected object");
|
|
394
356
|
}
|
|
395
|
-
const record = value
|
|
396
|
-
if (allowed === undefined)
|
|
357
|
+
const record = value;
|
|
358
|
+
if (allowed === undefined) {
|
|
359
|
+
return record;
|
|
360
|
+
}
|
|
397
361
|
|
|
398
362
|
const permitted = new Set(allowed);
|
|
399
363
|
for (const key of Object.keys(record)) {
|
|
400
|
-
if (!permitted.has(key))
|
|
364
|
+
if (!permitted.has(key)) {
|
|
365
|
+
fail(`${path}.${key}`, "unknown field");
|
|
366
|
+
}
|
|
401
367
|
}
|
|
402
368
|
for (const key of allowed) {
|
|
403
|
-
if (!(key in record))
|
|
369
|
+
if (!(key in record)) {
|
|
370
|
+
fail(`${path}.${key}`, "missing field");
|
|
371
|
+
}
|
|
404
372
|
}
|
|
405
373
|
return record;
|
|
406
374
|
}
|
|
407
375
|
|
|
408
|
-
function array(value: unknown, path: string): unknown
|
|
409
|
-
if (!Array.isArray(value))
|
|
376
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
377
|
+
if (!Array.isArray(value)) {
|
|
378
|
+
fail(path, "expected array");
|
|
379
|
+
}
|
|
410
380
|
return value;
|
|
411
381
|
}
|
|
412
382
|
|
|
413
|
-
function member<const T extends
|
|
383
|
+
function member<const T extends ReadonlyArray<string>>(
|
|
414
384
|
value: unknown,
|
|
415
385
|
choices: T,
|
|
416
386
|
path: string,
|
|
@@ -436,9 +406,12 @@ function variantKeys(
|
|
|
436
406
|
type: string,
|
|
437
407
|
value: Record<string, unknown>,
|
|
438
408
|
path: string,
|
|
439
|
-
):
|
|
409
|
+
): ReadonlyArray<string> {
|
|
440
410
|
const discriminant = value[COMMAND_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
441
|
-
const keys =
|
|
442
|
-
|
|
411
|
+
const keys =
|
|
412
|
+
typeof discriminant === "string" ? COMMAND_VARIANT_FIELDS[type]?.[discriminant] : undefined;
|
|
413
|
+
if (keys === undefined) {
|
|
414
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
415
|
+
}
|
|
443
416
|
return keys;
|
|
444
417
|
}
|
package/src/config/client.ts
CHANGED
|
@@ -108,9 +108,7 @@ export class ConfigOperationsClient {
|
|
|
108
108
|
return value;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async recoverStorage(
|
|
112
|
-
command: StorageRecoveryCommand,
|
|
113
|
-
): Promise<StorageRecoveryOutcome> {
|
|
111
|
+
async recoverStorage(command: StorageRecoveryCommand): Promise<StorageRecoveryOutcome> {
|
|
114
112
|
assertValidStorageRecoveryCommand(command);
|
|
115
113
|
const value = await this.#transport.invoke(CONFIG_STORAGE_RECOVER_COMMAND, {
|
|
116
114
|
command,
|
|
@@ -119,9 +117,7 @@ export class ConfigOperationsClient {
|
|
|
119
117
|
return value;
|
|
120
118
|
}
|
|
121
119
|
|
|
122
|
-
async cleanupStorage(
|
|
123
|
-
command: StorageCleanupCommand,
|
|
124
|
-
): Promise<StorageCleanupOutcome> {
|
|
120
|
+
async cleanupStorage(command: StorageCleanupCommand): Promise<StorageCleanupOutcome> {
|
|
125
121
|
assertValidStorageCleanupCommand(command);
|
|
126
122
|
const value = await this.#transport.invoke(CONFIG_STORAGE_CLEANUP_COMMAND, {
|
|
127
123
|
command,
|
|
@@ -159,9 +155,7 @@ export class ConfigOperationsClient {
|
|
|
159
155
|
return value;
|
|
160
156
|
}
|
|
161
157
|
|
|
162
|
-
async inspectRestore(
|
|
163
|
-
command: RestoreInspectCommand,
|
|
164
|
-
): Promise<RestoreInspectOutcome> {
|
|
158
|
+
async inspectRestore(command: RestoreInspectCommand): Promise<RestoreInspectOutcome> {
|
|
165
159
|
assertValidRestoreInspectCommand(command);
|
|
166
160
|
const value = await this.#transport.invoke(CONFIG_RESTORE_INSPECT_COMMAND, {
|
|
167
161
|
command,
|
|
@@ -179,9 +173,7 @@ export class ConfigOperationsClient {
|
|
|
179
173
|
return value;
|
|
180
174
|
}
|
|
181
175
|
|
|
182
|
-
async executeRestore(
|
|
183
|
-
command: RestoreExecuteCommand,
|
|
184
|
-
): Promise<RestoreExecuteOutcome> {
|
|
176
|
+
async executeRestore(command: RestoreExecuteCommand): Promise<RestoreExecuteOutcome> {
|
|
185
177
|
assertValidRestoreExecuteCommand(command);
|
|
186
178
|
const value = await this.#transport.invoke(CONFIG_RESTORE_EXECUTE_COMMAND, {
|
|
187
179
|
command,
|
|
@@ -194,17 +186,12 @@ export class ConfigOperationsClient {
|
|
|
194
186
|
command: RestoreAdapterExecuteCommand,
|
|
195
187
|
): Promise<RestoreAdapterExecuteOutcome> {
|
|
196
188
|
assertValidRestoreAdapterExecuteCommand(command);
|
|
197
|
-
const value = await this.#transport.invoke(
|
|
198
|
-
CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND,
|
|
199
|
-
{ command },
|
|
200
|
-
);
|
|
189
|
+
const value = await this.#transport.invoke(CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND, { command });
|
|
201
190
|
assertValidRestoreAdapterExecuteOutcome(value);
|
|
202
191
|
return value;
|
|
203
192
|
}
|
|
204
193
|
|
|
205
|
-
async recoverRestore(
|
|
206
|
-
command: RestoreRecoveryCommand,
|
|
207
|
-
): Promise<RestoreRecoveryOutcomeProjection> {
|
|
194
|
+
async recoverRestore(command: RestoreRecoveryCommand): Promise<RestoreRecoveryOutcomeProjection> {
|
|
208
195
|
assertValidRestoreRecoveryCommand(command);
|
|
209
196
|
const value = await this.#transport.invoke(CONFIG_RESTORE_RECOVER_COMMAND, {
|
|
210
197
|
command,
|
|
@@ -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 CONFIG_FIELDS
|
|
6
|
+
export const CONFIG_FIELDS = {
|
|
7
7
|
"StorageRootProjection": ["kind", "path", "provenance"],
|
|
8
8
|
"StorageLayoutProjection": ["profile", "platform", "canonicalApplicationId", "effectiveLeaf", "leafProvenance", "roots", "warnings", "layoutDigest"],
|
|
9
9
|
"StorageOperationsProjection": ["layout", "bootstrap", "availableProfiles"],
|
|
@@ -51,4 +51,4 @@ export const CONFIG_FIELDS: Record<string, readonly string[]> = {
|
|
|
51
51
|
"RestoreAdapterReceiptProjection": ["domainId", "adapter", "participation", "confirmationDigest", "outcome", "evidence"],
|
|
52
52
|
"RestoreRecoveryCommand": ["protocolVersion", "requestId"],
|
|
53
53
|
"RestoreRecoveryReceiptProjection": ["outcome", "domainIds"],
|
|
54
|
-
};
|
|
54
|
+
} as const;
|
package/src/config/names.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
export const CONFIG_SNAPSHOT_COMMAND = "longhorn_config_snapshot";
|
|
2
|
-
export const CONFIG_STORAGE_INSPECT_COMMAND =
|
|
3
|
-
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
export const CONFIG_STORAGE_RECOVER_COMMAND =
|
|
7
|
-
"longhorn_config_storage_recover";
|
|
8
|
-
export const CONFIG_STORAGE_CLEANUP_COMMAND =
|
|
9
|
-
"longhorn_config_storage_cleanup";
|
|
2
|
+
export const CONFIG_STORAGE_INSPECT_COMMAND = "longhorn_config_storage_inspect";
|
|
3
|
+
export const CONFIG_STORAGE_EXECUTE_COMMAND = "longhorn_config_storage_execute";
|
|
4
|
+
export const CONFIG_STORAGE_RECOVER_COMMAND = "longhorn_config_storage_recover";
|
|
5
|
+
export const CONFIG_STORAGE_CLEANUP_COMMAND = "longhorn_config_storage_cleanup";
|
|
10
6
|
export const CONFIG_BACKUP_CREATE_COMMAND = "longhorn_config_backup_create";
|
|
11
7
|
export const CONFIG_BACKUP_EXPORT_COMMAND = "longhorn_config_backup_export";
|
|
12
|
-
export const CONFIG_BACKUP_RETENTION_COMMAND =
|
|
13
|
-
"longhorn_config_backup_retention";
|
|
8
|
+
export const CONFIG_BACKUP_RETENTION_COMMAND = "longhorn_config_backup_retention";
|
|
14
9
|
export const CONFIG_RESTORE_INSPECT_COMMAND = "longhorn_config_restore_inspect";
|
|
15
10
|
export const CONFIG_RESTORE_PLAN_COMMAND = "longhorn_config_restore_plan";
|
|
16
11
|
export const CONFIG_RESTORE_EXECUTE_COMMAND = "longhorn_config_restore_execute";
|
|
17
|
-
export const CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND =
|
|
18
|
-
"longhorn_config_restore_adapter_execute";
|
|
12
|
+
export const CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND = "longhorn_config_restore_adapter_execute";
|
|
19
13
|
export const CONFIG_RESTORE_RECOVER_COMMAND = "longhorn_config_restore_recover";
|
|
@@ -14,9 +14,7 @@ import type {
|
|
|
14
14
|
StorageTransitionExecuteCommand,
|
|
15
15
|
StorageTransitionInspectCommand,
|
|
16
16
|
} from "../generated/protocol.ts";
|
|
17
|
-
import {
|
|
18
|
-
RESTORE_ARCHIVE_SELECTION_SOURCES,
|
|
19
|
-
} from "../generated/protocol.ts";
|
|
17
|
+
import { RESTORE_ARCHIVE_SELECTION_SOURCES } from "../generated/protocol.ts";
|
|
20
18
|
import {
|
|
21
19
|
array,
|
|
22
20
|
baseCommand,
|
|
@@ -95,19 +93,13 @@ export function assertValidRestoreInspectCommand(
|
|
|
95
93
|
): asserts value is RestoreInspectCommand {
|
|
96
94
|
const command = baseCommand(value, "$", CONFIG_FIELDS.RestoreInspectCommand);
|
|
97
95
|
const selection = record(command.selection, "$.selection");
|
|
98
|
-
discriminant(
|
|
99
|
-
selection.source,
|
|
100
|
-
RESTORE_ARCHIVE_SELECTION_SOURCES,
|
|
101
|
-
"$.selection.source",
|
|
102
|
-
);
|
|
96
|
+
discriminant(selection.source, RESTORE_ARCHIVE_SELECTION_SOURCES, "$.selection.source");
|
|
103
97
|
if (selection.source === "inventory") {
|
|
104
98
|
digest(selection.archiveSha256, "$.selection.archiveSha256");
|
|
105
99
|
}
|
|
106
100
|
}
|
|
107
101
|
|
|
108
|
-
export function assertValidRestorePlanCommand(
|
|
109
|
-
value: unknown,
|
|
110
|
-
): asserts value is RestorePlanCommand {
|
|
102
|
+
export function assertValidRestorePlanCommand(value: unknown): asserts value is RestorePlanCommand {
|
|
111
103
|
const command = baseCommand(value, "$", CONFIG_FIELDS.RestorePlanCommand);
|
|
112
104
|
finiteNumber(command.generation, "$.generation");
|
|
113
105
|
digest(command.archiveSha256, "$.archiveSha256");
|
|
@@ -131,11 +123,7 @@ export function assertValidRestoreAdapterExecuteCommand(
|
|
|
131
123
|
const command = generationConfirmationCommand(value, CONFIG_FIELDS.RestoreAdapterExecuteCommand);
|
|
132
124
|
digest(command.archiveSha256, "$.archiveSha256");
|
|
133
125
|
nonempty(command.domainId, "$.domainId");
|
|
134
|
-
discriminant(
|
|
135
|
-
command.requirement,
|
|
136
|
-
["failureAtomic", "allowSeparate"],
|
|
137
|
-
"$.requirement",
|
|
138
|
-
);
|
|
126
|
+
discriminant(command.requirement, ["failureAtomic", "allowSeparate"], "$.requirement");
|
|
139
127
|
}
|
|
140
128
|
|
|
141
129
|
export function assertValidRestoreRecoveryCommand(
|
|
@@ -146,7 +134,7 @@ export function assertValidRestoreRecoveryCommand(
|
|
|
146
134
|
|
|
147
135
|
function generationConfirmationCommand(
|
|
148
136
|
value: unknown,
|
|
149
|
-
allowed?:
|
|
137
|
+
allowed?: ReadonlyArray<string>,
|
|
150
138
|
): Record<string, unknown> {
|
|
151
139
|
const command = baseCommand(value, "$", allowed);
|
|
152
140
|
finiteNumber(command.generation, "$.generation");
|
|
@@ -17,18 +17,20 @@ import {
|
|
|
17
17
|
STORAGE_RECOVERY_STATUSES,
|
|
18
18
|
STORAGE_TRANSITION_EXECUTE_STATUSES,
|
|
19
19
|
STORAGE_TRANSITION_INSPECT_STATUSES,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
} from "../generated/protocol.ts";
|
|
21
|
+
import type {
|
|
22
|
+
BackupCreateOutcome,
|
|
23
|
+
BackupExportOutcome,
|
|
24
|
+
BackupRetentionApplyOutcome,
|
|
25
|
+
RestoreAdapterExecuteOutcome,
|
|
26
|
+
RestoreExecuteOutcome,
|
|
27
|
+
RestoreInspectOutcome,
|
|
28
|
+
RestorePlanOutcome,
|
|
29
|
+
RestoreRecoveryOutcomeProjection,
|
|
30
|
+
StorageCleanupOutcome,
|
|
31
|
+
StorageRecoveryOutcome,
|
|
32
|
+
StorageTransitionExecuteOutcome,
|
|
33
|
+
StorageTransitionInspectOutcome,
|
|
32
34
|
} from "../generated/protocol.ts";
|
|
33
35
|
import {
|
|
34
36
|
assertValidConfigOperationsSnapshot,
|
|
@@ -39,15 +41,7 @@ import {
|
|
|
39
41
|
assertRestorePlan,
|
|
40
42
|
assertRestoreRecoveryReceipt,
|
|
41
43
|
} from "./projection.ts";
|
|
42
|
-
import {
|
|
43
|
-
array,
|
|
44
|
-
digest,
|
|
45
|
-
discriminant,
|
|
46
|
-
finiteNumber,
|
|
47
|
-
record,
|
|
48
|
-
string,
|
|
49
|
-
fail,
|
|
50
|
-
} from "./primitives.ts";
|
|
44
|
+
import { array, digest, discriminant, finiteNumber, record, string, fail } from "./primitives.ts";
|
|
51
45
|
|
|
52
46
|
export function assertValidStorageTransitionInspectOutcome(
|
|
53
47
|
value: unknown,
|
|
@@ -61,12 +55,9 @@ export function assertValidStorageTransitionInspectOutcome(
|
|
|
61
55
|
"$.preview",
|
|
62
56
|
CONFIG_FIELDS.StorageTransitionPreviewProjection,
|
|
63
57
|
);
|
|
64
|
-
[
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"evidenceDigest",
|
|
68
|
-
"confirmationDigest",
|
|
69
|
-
].forEach((key) => digest(preview[key], `$.preview.${key}`));
|
|
58
|
+
["sourceLayoutDigest", "targetLayoutDigest", "evidenceDigest", "confirmationDigest"].forEach(
|
|
59
|
+
(key) => digest(preview[key], `$.preview.${key}`),
|
|
60
|
+
);
|
|
70
61
|
array(preview.domains, "$.preview.domains");
|
|
71
62
|
array(preview.unknownSourcePaths, "$.preview.unknownSourcePaths");
|
|
72
63
|
array(preview.conflicts, "$.preview.conflicts");
|
|
@@ -78,7 +69,12 @@ export function assertValidStorageTransitionInspectOutcome(
|
|
|
78
69
|
export function assertValidStorageTransitionExecuteOutcome(
|
|
79
70
|
value: unknown,
|
|
80
71
|
): asserts value is StorageTransitionExecuteOutcome {
|
|
81
|
-
mutationOutcome(
|
|
72
|
+
mutationOutcome(
|
|
73
|
+
value,
|
|
74
|
+
STORAGE_TRANSITION_EXECUTE_STATUSES,
|
|
75
|
+
"committed",
|
|
76
|
+
"StorageTransitionExecuteOutcome",
|
|
77
|
+
);
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
export function assertValidStorageRecoveryOutcome(
|
|
@@ -126,9 +122,7 @@ export function assertValidRestoreInspectOutcome(
|
|
|
126
122
|
}
|
|
127
123
|
}
|
|
128
124
|
|
|
129
|
-
export function assertValidRestorePlanOutcome(
|
|
130
|
-
value: unknown,
|
|
131
|
-
): asserts value is RestorePlanOutcome {
|
|
125
|
+
export function assertValidRestorePlanOutcome(value: unknown): asserts value is RestorePlanOutcome {
|
|
132
126
|
outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
|
|
133
127
|
const result = record(value, "$");
|
|
134
128
|
if (result.status === "ready") {
|
|
@@ -147,10 +141,7 @@ export function assertValidRestoreExecuteOutcome(
|
|
|
147
141
|
if (result.status === "succeeded") {
|
|
148
142
|
assertRestoreExecutionReceipt(result.receipt, "$.receipt");
|
|
149
143
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
150
|
-
} else if (
|
|
151
|
-
result.status === "rolledBack" ||
|
|
152
|
-
result.status === "recoveryRequired"
|
|
153
|
-
) {
|
|
144
|
+
} else if (result.status === "rolledBack" || result.status === "recoveryRequired") {
|
|
154
145
|
assertRestoreFailure(result.failure, "$.failure");
|
|
155
146
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
156
147
|
} else {
|
|
@@ -189,7 +180,7 @@ export function assertValidRestoreRecoveryOutcome(
|
|
|
189
180
|
|
|
190
181
|
function mutationOutcome(
|
|
191
182
|
value: unknown,
|
|
192
|
-
variants:
|
|
183
|
+
variants: ReadonlyArray<string>,
|
|
193
184
|
success: string,
|
|
194
185
|
type: string,
|
|
195
186
|
): void {
|
|
@@ -213,7 +204,7 @@ function rejection(value: unknown, path: string): void {
|
|
|
213
204
|
|
|
214
205
|
function outcome(
|
|
215
206
|
value: unknown,
|
|
216
|
-
variants:
|
|
207
|
+
variants: ReadonlyArray<string>,
|
|
217
208
|
path: string,
|
|
218
209
|
type: string,
|
|
219
210
|
): void {
|
|
@@ -233,9 +224,10 @@ function variantKeys(
|
|
|
233
224
|
type: string,
|
|
234
225
|
value: Record<string, unknown>,
|
|
235
226
|
path: string,
|
|
236
|
-
):
|
|
227
|
+
): ReadonlyArray<string> {
|
|
237
228
|
const discriminant = value[CONFIG_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "status"];
|
|
238
|
-
const keys =
|
|
229
|
+
const keys =
|
|
230
|
+
typeof discriminant === "string" ? CONFIG_VARIANT_FIELDS[type]?.[discriminant] : undefined;
|
|
239
231
|
if (keys === undefined) {
|
|
240
232
|
fail("invalid_payload", path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
241
233
|
}
|