@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 { wireVariantFields } from "../../core/record.ts";
|
|
1
2
|
import {
|
|
2
3
|
CONFIG_VARIANT_FIELDS,
|
|
3
4
|
CONFIG_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
RESTORE_PLAN_STATUSES,
|
|
15
16
|
RESTORE_RECOVERY_STATUSES,
|
|
16
17
|
STORAGE_CLEANUP_STATUSES,
|
|
18
|
+
STORAGE_CLASSES,
|
|
19
|
+
STORAGE_PROFILE_IDS,
|
|
17
20
|
STORAGE_RECOVERY_STATUSES,
|
|
18
21
|
STORAGE_TRANSITION_EXECUTE_STATUSES,
|
|
19
22
|
STORAGE_TRANSITION_INSPECT_STATUSES,
|
|
@@ -33,6 +36,7 @@ import type {
|
|
|
33
36
|
StorageTransitionInspectOutcome,
|
|
34
37
|
} from "../generated/protocol.ts";
|
|
35
38
|
import {
|
|
39
|
+
assertBackupPublication,
|
|
36
40
|
assertValidConfigOperationsSnapshot,
|
|
37
41
|
assertRestoreAdapterReceipt,
|
|
38
42
|
assertRestoreExecutionReceipt,
|
|
@@ -41,26 +45,31 @@ import {
|
|
|
41
45
|
assertRestorePlan,
|
|
42
46
|
assertRestoreRecoveryReceipt,
|
|
43
47
|
} from "./projection.ts";
|
|
44
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
array,
|
|
50
|
+
boolean,
|
|
51
|
+
digest,
|
|
52
|
+
discriminant,
|
|
53
|
+
finiteNumber,
|
|
54
|
+
nullableDigest,
|
|
55
|
+
nullableString,
|
|
56
|
+
record,
|
|
57
|
+
string,
|
|
58
|
+
fail,
|
|
59
|
+
} from "./primitives.ts";
|
|
45
60
|
|
|
46
61
|
export function assertValidStorageTransitionInspectOutcome(
|
|
47
62
|
value: unknown,
|
|
48
63
|
): asserts value is StorageTransitionInspectOutcome {
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
const result = outcome(
|
|
65
|
+
value,
|
|
66
|
+
STORAGE_TRANSITION_INSPECT_STATUSES,
|
|
67
|
+
"$",
|
|
68
|
+
"StorageTransitionInspectOutcome",
|
|
69
|
+
);
|
|
51
70
|
if (result.status === "ready") {
|
|
52
71
|
finiteNumber(result.generation, "$.generation");
|
|
53
|
-
|
|
54
|
-
result.preview,
|
|
55
|
-
"$.preview",
|
|
56
|
-
CONFIG_FIELDS.StorageTransitionPreviewProjection,
|
|
57
|
-
);
|
|
58
|
-
["sourceLayoutDigest", "targetLayoutDigest", "evidenceDigest", "confirmationDigest"].forEach(
|
|
59
|
-
(key) => digest(preview[key], `$.preview.${key}`),
|
|
60
|
-
);
|
|
61
|
-
array(preview.domains, "$.preview.domains");
|
|
62
|
-
array(preview.unknownSourcePaths, "$.preview.unknownSourcePaths");
|
|
63
|
-
array(preview.conflicts, "$.preview.conflicts");
|
|
72
|
+
assertStorageTransitionPreview(result.preview);
|
|
64
73
|
} else {
|
|
65
74
|
rejection(result.rejection, "$.rejection");
|
|
66
75
|
}
|
|
@@ -74,44 +83,63 @@ export function assertValidStorageTransitionExecuteOutcome(
|
|
|
74
83
|
STORAGE_TRANSITION_EXECUTE_STATUSES,
|
|
75
84
|
"committed",
|
|
76
85
|
"StorageTransitionExecuteOutcome",
|
|
86
|
+
(result) => assertStorageTransitionReceipt(result.receipt),
|
|
77
87
|
);
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export function assertValidStorageRecoveryOutcome(
|
|
81
91
|
value: unknown,
|
|
82
92
|
): asserts value is StorageRecoveryOutcome {
|
|
83
|
-
mutationOutcome(
|
|
93
|
+
mutationOutcome(
|
|
94
|
+
value,
|
|
95
|
+
STORAGE_RECOVERY_STATUSES,
|
|
96
|
+
"recovered",
|
|
97
|
+
"StorageRecoveryOutcome",
|
|
98
|
+
(result) => assertStorageRecoveryReceipt(result.receipt),
|
|
99
|
+
);
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
export function assertValidStorageCleanupOutcome(
|
|
87
103
|
value: unknown,
|
|
88
104
|
): asserts value is StorageCleanupOutcome {
|
|
89
|
-
mutationOutcome(value, STORAGE_CLEANUP_STATUSES, "applied", "StorageCleanupOutcome")
|
|
105
|
+
mutationOutcome(value, STORAGE_CLEANUP_STATUSES, "applied", "StorageCleanupOutcome", (result) =>
|
|
106
|
+
assertStorageCleanupReceipt(result.receipt),
|
|
107
|
+
);
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
export function assertValidBackupCreateOutcome(
|
|
93
111
|
value: unknown,
|
|
94
112
|
): asserts value is BackupCreateOutcome {
|
|
95
|
-
mutationOutcome(value, BACKUP_CREATE_STATUSES, "published", "BackupCreateOutcome")
|
|
113
|
+
mutationOutcome(value, BACKUP_CREATE_STATUSES, "published", "BackupCreateOutcome", (result) => {
|
|
114
|
+
assertBackupCapture(result.capture);
|
|
115
|
+
assertBackupPublication(result.publication, "$.publication");
|
|
116
|
+
});
|
|
96
117
|
}
|
|
97
118
|
|
|
98
119
|
export function assertValidBackupExportOutcome(
|
|
99
120
|
value: unknown,
|
|
100
121
|
): asserts value is BackupExportOutcome {
|
|
101
|
-
mutationOutcome(value, BACKUP_EXPORT_STATUSES, "published", "BackupExportOutcome")
|
|
122
|
+
mutationOutcome(value, BACKUP_EXPORT_STATUSES, "published", "BackupExportOutcome", (result) =>
|
|
123
|
+
assertBackupPublication(result.publication, "$.publication"),
|
|
124
|
+
);
|
|
102
125
|
}
|
|
103
126
|
|
|
104
127
|
export function assertValidBackupRetentionApplyOutcome(
|
|
105
128
|
value: unknown,
|
|
106
129
|
): asserts value is BackupRetentionApplyOutcome {
|
|
107
|
-
mutationOutcome(
|
|
130
|
+
mutationOutcome(
|
|
131
|
+
value,
|
|
132
|
+
BACKUP_RETENTION_APPLY_STATUSES,
|
|
133
|
+
"applied",
|
|
134
|
+
"BackupRetentionApplyOutcome",
|
|
135
|
+
(result) => stringArray(result.deletedPaths, "$.deletedPaths"),
|
|
136
|
+
);
|
|
108
137
|
}
|
|
109
138
|
|
|
110
139
|
export function assertValidRestoreInspectOutcome(
|
|
111
140
|
value: unknown,
|
|
112
141
|
): asserts value is RestoreInspectOutcome {
|
|
113
|
-
outcome(value, RESTORE_INSPECT_STATUSES, "$", "RestoreInspectOutcome");
|
|
114
|
-
const result = record(value, "$");
|
|
142
|
+
const result = outcome(value, RESTORE_INSPECT_STATUSES, "$", "RestoreInspectOutcome");
|
|
115
143
|
if (result.status === "ready") {
|
|
116
144
|
finiteNumber(result.generation, "$.generation");
|
|
117
145
|
assertRestoreInspection(result.inspection, "$.inspection");
|
|
@@ -123,8 +151,7 @@ export function assertValidRestoreInspectOutcome(
|
|
|
123
151
|
}
|
|
124
152
|
|
|
125
153
|
export function assertValidRestorePlanOutcome(value: unknown): asserts value is RestorePlanOutcome {
|
|
126
|
-
outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
|
|
127
|
-
const result = record(value, "$");
|
|
154
|
+
const result = outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
|
|
128
155
|
if (result.status === "ready") {
|
|
129
156
|
finiteNumber(result.generation, "$.generation");
|
|
130
157
|
assertRestorePlan(result.plan, "$.plan");
|
|
@@ -136,8 +163,7 @@ export function assertValidRestorePlanOutcome(value: unknown): asserts value is
|
|
|
136
163
|
export function assertValidRestoreExecuteOutcome(
|
|
137
164
|
value: unknown,
|
|
138
165
|
): asserts value is RestoreExecuteOutcome {
|
|
139
|
-
outcome(value, RESTORE_EXECUTE_STATUSES, "$", "RestoreExecuteOutcome");
|
|
140
|
-
const result = record(value, "$");
|
|
166
|
+
const result = outcome(value, RESTORE_EXECUTE_STATUSES, "$", "RestoreExecuteOutcome");
|
|
141
167
|
if (result.status === "succeeded") {
|
|
142
168
|
assertRestoreExecutionReceipt(result.receipt, "$.receipt");
|
|
143
169
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
@@ -152,8 +178,12 @@ export function assertValidRestoreExecuteOutcome(
|
|
|
152
178
|
export function assertValidRestoreAdapterExecuteOutcome(
|
|
153
179
|
value: unknown,
|
|
154
180
|
): asserts value is RestoreAdapterExecuteOutcome {
|
|
155
|
-
|
|
156
|
-
|
|
181
|
+
const result = outcome(
|
|
182
|
+
value,
|
|
183
|
+
RESTORE_ADAPTER_EXECUTE_STATUSES,
|
|
184
|
+
"$",
|
|
185
|
+
"RestoreAdapterExecuteOutcome",
|
|
186
|
+
);
|
|
157
187
|
if (result.status === "completed") {
|
|
158
188
|
assertRestoreAdapterReceipt(result.receipt, "$.receipt");
|
|
159
189
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
@@ -165,8 +195,7 @@ export function assertValidRestoreAdapterExecuteOutcome(
|
|
|
165
195
|
export function assertValidRestoreRecoveryOutcome(
|
|
166
196
|
value: unknown,
|
|
167
197
|
): asserts value is RestoreRecoveryOutcomeProjection {
|
|
168
|
-
outcome(value, RESTORE_RECOVERY_STATUSES, "$", "RestoreRecoveryOutcomeProjection");
|
|
169
|
-
const result = record(value, "$");
|
|
198
|
+
const result = outcome(value, RESTORE_RECOVERY_STATUSES, "$", "RestoreRecoveryOutcomeProjection");
|
|
170
199
|
if (result.status === "recovered") {
|
|
171
200
|
assertRestoreRecoveryReceipt(result.receipt, "$.receipt");
|
|
172
201
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
@@ -183,10 +212,11 @@ function mutationOutcome(
|
|
|
183
212
|
variants: ReadonlyArray<string>,
|
|
184
213
|
success: string,
|
|
185
214
|
type: string,
|
|
215
|
+
checkSuccess: (result: Record<string, unknown>) => void,
|
|
186
216
|
): void {
|
|
187
|
-
outcome(value, variants, "$", type);
|
|
188
|
-
const result = record(value, "$");
|
|
217
|
+
const result = outcome(value, variants, "$", type);
|
|
189
218
|
if (result.status === success) {
|
|
219
|
+
checkSuccess(result);
|
|
190
220
|
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
191
221
|
} else {
|
|
192
222
|
rejection(result.rejection, "$.rejection");
|
|
@@ -207,29 +237,100 @@ function outcome(
|
|
|
207
237
|
variants: ReadonlyArray<string>,
|
|
208
238
|
path: string,
|
|
209
239
|
type: string,
|
|
210
|
-
):
|
|
240
|
+
): Record<string, unknown> {
|
|
211
241
|
const result = record(value, path);
|
|
212
242
|
discriminant(result.status, variants, `${path}.status`);
|
|
213
|
-
|
|
214
|
-
// generator failed rather than that a caller sent something odd.
|
|
215
|
-
record(result, path, variantKeys(type, result, path));
|
|
243
|
+
return record(result, path, variantKeys(type, result, path));
|
|
216
244
|
}
|
|
217
245
|
|
|
218
|
-
/**
|
|
219
|
-
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
220
|
-
* discriminant's name read from the map too. This domain tags on `status`,
|
|
221
|
-
* `state`, `kind` and `source`.
|
|
222
|
-
*/
|
|
223
246
|
function variantKeys(
|
|
224
247
|
type: string,
|
|
225
248
|
value: Record<string, unknown>,
|
|
226
249
|
path: string,
|
|
227
250
|
): ReadonlyArray<string> {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
return wireVariantFields(
|
|
252
|
+
CONFIG_VARIANT_FIELDS,
|
|
253
|
+
CONFIG_VARIANT_FIELDS_DISCRIMINANTS,
|
|
254
|
+
type,
|
|
255
|
+
value,
|
|
256
|
+
(discriminant) =>
|
|
257
|
+
fail("invalid_payload", path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function assertStorageTransitionPreview(value: unknown): void {
|
|
262
|
+
const path = "$.preview";
|
|
263
|
+
const preview = record(value, path, CONFIG_FIELDS.StorageTransitionPreviewProjection);
|
|
264
|
+
discriminant(preview.targetProfile, STORAGE_PROFILE_IDS, `${path}.targetProfile`);
|
|
265
|
+
for (const key of [
|
|
266
|
+
"sourceLayoutDigest",
|
|
267
|
+
"targetLayoutDigest",
|
|
268
|
+
"evidenceDigest",
|
|
269
|
+
"confirmationDigest",
|
|
270
|
+
]) {
|
|
271
|
+
digest(preview[key], `${path}.${key}`);
|
|
272
|
+
}
|
|
273
|
+
for (const [index, value] of array(preview.domains, `${path}.domains`).entries()) {
|
|
274
|
+
const domainPath = `${path}.domains[${index}]`;
|
|
275
|
+
const domain = record(value, domainPath, CONFIG_FIELDS.StorageTransitionDomainProjection);
|
|
276
|
+
string(domain.domainId, `${domainPath}.domainId`);
|
|
277
|
+
discriminant(domain.storageClass, STORAGE_CLASSES, `${domainPath}.storageClass`);
|
|
278
|
+
string(domain.action, `${domainPath}.action`);
|
|
279
|
+
nullableString(domain.sourcePath, `${domainPath}.sourcePath`);
|
|
280
|
+
nullableString(domain.targetPath, `${domainPath}.targetPath`);
|
|
281
|
+
nullableDigest(domain.sourceSha256, `${domainPath}.sourceSha256`);
|
|
282
|
+
}
|
|
283
|
+
stringArray(preview.unknownSourcePaths, `${path}.unknownSourcePaths`);
|
|
284
|
+
for (const [index, value] of array(preview.conflicts, `${path}.conflicts`).entries()) {
|
|
285
|
+
const conflictPath = `${path}.conflicts[${index}]`;
|
|
286
|
+
const conflict = record(value, conflictPath, CONFIG_FIELDS.StorageTransitionConflictProjection);
|
|
287
|
+
string(conflict.kind, `${conflictPath}.kind`);
|
|
288
|
+
nullableString(conflict.path, `${conflictPath}.path`);
|
|
289
|
+
string(conflict.detail, `${conflictPath}.detail`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function assertStorageTransitionReceipt(value: unknown): void {
|
|
294
|
+
const path = "$.receipt";
|
|
295
|
+
const receipt = record(value, path, CONFIG_FIELDS.StorageTransitionReceiptProjection);
|
|
296
|
+
string(receipt.transitionId, `${path}.transitionId`);
|
|
297
|
+
string(receipt.outcome, `${path}.outcome`);
|
|
298
|
+
digest(receipt.targetLayoutDigest, `${path}.targetLayoutDigest`);
|
|
299
|
+
digest(receipt.receiptDigest, `${path}.receiptDigest`);
|
|
300
|
+
stringArray(receipt.copiedDomainIds, `${path}.copiedDomainIds`);
|
|
301
|
+
stringArray(receipt.customDomainIds, `${path}.customDomainIds`);
|
|
302
|
+
stringArray(receipt.retainedSourcePaths, `${path}.retainedSourcePaths`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function assertStorageRecoveryReceipt(value: unknown): void {
|
|
306
|
+
const path = "$.receipt";
|
|
307
|
+
const receipt = record(value, path, CONFIG_FIELDS.StorageRecoveryReceiptProjection);
|
|
308
|
+
nullableString(receipt.transitionId, `${path}.transitionId`);
|
|
309
|
+
string(receipt.outcome, `${path}.outcome`);
|
|
310
|
+
digest(receipt.activeLayoutDigest, `${path}.activeLayoutDigest`);
|
|
311
|
+
string(receipt.detail, `${path}.detail`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function assertStorageCleanupReceipt(value: unknown): void {
|
|
315
|
+
const path = "$.receipt";
|
|
316
|
+
const receipt = record(value, path, CONFIG_FIELDS.StorageCleanupReceiptProjection);
|
|
317
|
+
string(receipt.transitionId, `${path}.transitionId`);
|
|
318
|
+
digest(receipt.transitionReceiptDigest, `${path}.transitionReceiptDigest`);
|
|
319
|
+
stringArray(receipt.removedPaths, `${path}.removedPaths`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function assertBackupCapture(value: unknown): void {
|
|
323
|
+
const path = "$.capture";
|
|
324
|
+
const receipt = record(value, path, CONFIG_FIELDS.BackupCaptureReceiptProjection);
|
|
325
|
+
const { flushedPendingPublication, ...counters } = receipt;
|
|
326
|
+
boolean(flushedPendingPublication, `${path}.flushedPendingPublication`);
|
|
327
|
+
for (const [key, count] of Object.entries(counters)) {
|
|
328
|
+
finiteNumber(count, `${path}.${key}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function stringArray(value: unknown, path: string): void {
|
|
333
|
+
for (const [index, item] of array(value, path).entries()) {
|
|
334
|
+
string(item, `${path}[${index}]`);
|
|
233
335
|
}
|
|
234
|
-
return keys;
|
|
235
336
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isOpaqueId } from "../../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord } from "../../core/record.ts";
|
|
3
3
|
import { CONFIG_OPERATIONS_PROTOCOL_VERSION } from "../generated/protocol.ts";
|
|
4
4
|
|
|
5
5
|
export type ConfigProtocolValidationCode =
|
|
@@ -40,42 +40,19 @@ export function protocol(value: unknown, path: string): void {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* Rejects a non-object, an unknown key, and a missing key.
|
|
45
|
-
*
|
|
46
|
-
* `allowed` comes from the generated field map, so the keys accepted are the
|
|
47
|
-
* Rust struct's and nothing else — contract 010's Boundary Validation Target.
|
|
48
|
-
* `path` is kept ahead of it because every existing caller passes one and it
|
|
49
|
-
* is what makes a rejection locatable in a nested document.
|
|
50
|
-
*
|
|
51
|
-
* Called without a list, this keeps shape-only behaviour. That is correct for
|
|
52
|
-
* a tagged union, whose allowed keys depend on its discriminant, and it is a
|
|
53
|
-
* gap anywhere else — the remaining untyped call sites are the work left.
|
|
54
|
-
*/
|
|
55
43
|
export function record(
|
|
56
44
|
value: unknown,
|
|
57
45
|
path: string,
|
|
58
46
|
allowed?: ReadonlyArray<string>,
|
|
59
47
|
): Record<string, unknown> {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const permitted = new Set(allowed);
|
|
69
|
-
for (const key of Object.keys(result)) {
|
|
70
|
-
if (!permitted.has(key)) {
|
|
71
|
-
fail("invalid_payload", `${path}.${key}`, "unknown field");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
for (const key of allowed) {
|
|
75
|
-
if (!(key in result)) {
|
|
76
|
-
fail("invalid_payload", `${path}.${key}`, "missing field");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
48
|
+
const result = readWireRecord(value, () => fail("invalid_payload", path, "expected object"));
|
|
49
|
+
checkWireFields(result, allowed, (code, key) =>
|
|
50
|
+
fail(
|
|
51
|
+
"invalid_payload",
|
|
52
|
+
`${path}.${key}`,
|
|
53
|
+
code === "unknown_field" ? "unknown field" : "missing field",
|
|
54
|
+
),
|
|
55
|
+
);
|
|
79
56
|
return result;
|
|
80
57
|
}
|
|
81
58
|
|
|
@@ -146,12 +123,7 @@ export function fail(code: ConfigProtocolValidationCode, path: string, message:
|
|
|
146
123
|
}
|
|
147
124
|
|
|
148
125
|
function opaqueId(value: unknown, path: string): asserts value is string {
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
value.length === 0 ||
|
|
152
|
-
value.length > CONFIG_MAXIMUM_OPAQUE_ID_BYTES ||
|
|
153
|
-
!/^[a-z0-9._:-]+$/.test(value)
|
|
154
|
-
) {
|
|
126
|
+
if (!isOpaqueId(value)) {
|
|
155
127
|
fail("invalid_payload", path, "expected bounded lowercase opaque id");
|
|
156
128
|
}
|
|
157
129
|
}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { CONFIG_FIELDS } from "../generated/fields.ts";
|
|
2
2
|
import {
|
|
3
3
|
BACKUP_ENCRYPTION_STATES,
|
|
4
|
+
BACKUP_CONSISTENCY_MODES,
|
|
5
|
+
BACKUP_KINDS,
|
|
6
|
+
BACKUP_SOURCE_STATES,
|
|
7
|
+
STORAGE_CLASSES,
|
|
8
|
+
BACKUP_INVENTORY_ENTRY_STATES,
|
|
4
9
|
BACKUP_PENDING_STATES,
|
|
10
|
+
BACKUP_PUBLICATION_DURABILITIES,
|
|
5
11
|
CONFIG_OPERATION_CAPABILITIES,
|
|
12
|
+
RESTORE_ADAPTER_OUTCOMES,
|
|
13
|
+
RESTORE_AUTHENTICITY_VALUES,
|
|
14
|
+
RESTORE_CONFLICT_CHOICES,
|
|
15
|
+
RESTORE_INTEGRITY_VALUES,
|
|
16
|
+
RESTORE_OPERATION_STATES,
|
|
17
|
+
STORAGE_LEAF_PROVENANCES,
|
|
18
|
+
STORAGE_PROFILE_IDS,
|
|
6
19
|
RESTORE_ADAPTER_PARTICIPATION_KINDS,
|
|
7
20
|
RESTORE_CURRENT_EVIDENCE_STATES,
|
|
8
21
|
RESTORE_DOMAIN_COMPATIBILITY_STATUSES,
|
|
22
|
+
RESTORE_EXECUTION_STAGES,
|
|
23
|
+
RESTORE_FAILURE_TERMINALS,
|
|
9
24
|
RESTORE_IDENTITY_STATUSES,
|
|
25
|
+
RESTORE_RECOVERY_RESULTS,
|
|
10
26
|
STORAGE_BOOTSTRAP_STATES,
|
|
11
27
|
} from "../generated/protocol.ts";
|
|
12
28
|
import type { ConfigOperationsSnapshot } from "../generated/protocol.ts";
|
|
@@ -24,13 +40,6 @@ import {
|
|
|
24
40
|
string,
|
|
25
41
|
} from "./primitives.ts";
|
|
26
42
|
|
|
27
|
-
const STORAGE_PROFILES = [
|
|
28
|
-
"platform-native-v1",
|
|
29
|
-
"unified-app-root-v1",
|
|
30
|
-
"shared-product-root-v1",
|
|
31
|
-
"portable-v1",
|
|
32
|
-
] as const;
|
|
33
|
-
|
|
34
43
|
export function assertValidConfigOperationsSnapshot(
|
|
35
44
|
value: unknown,
|
|
36
45
|
): asserts value is ConfigOperationsSnapshot {
|
|
@@ -54,15 +63,12 @@ export function assertValidConfigOperationsSnapshot(
|
|
|
54
63
|
export function assertRestoreInspection(value: unknown, path: string): void {
|
|
55
64
|
const inspection = record(value, path, CONFIG_FIELDS.RestoreInspectionProjection);
|
|
56
65
|
digest(inspection.archiveSha256, `${path}.archiveSha256`);
|
|
57
|
-
["archiveId", "createdAt", "
|
|
66
|
+
["archiveId", "createdAt", "applicationVersion", "producerVersion"].forEach((key) =>
|
|
58
67
|
nonempty(inspection[key], `${path}.${key}`),
|
|
59
68
|
);
|
|
60
|
-
discriminant(inspection.
|
|
61
|
-
discriminant(
|
|
62
|
-
|
|
63
|
-
["unauthenticated", "authenticated"],
|
|
64
|
-
`${path}.authenticity`,
|
|
65
|
-
);
|
|
69
|
+
discriminant(inspection.kind, BACKUP_KINDS, `${path}.kind`);
|
|
70
|
+
discriminant(inspection.integrity, RESTORE_INTEGRITY_VALUES, `${path}.integrity`);
|
|
71
|
+
discriminant(inspection.authenticity, RESTORE_AUTHENTICITY_VALUES, `${path}.authenticity`);
|
|
66
72
|
identity(
|
|
67
73
|
record(inspection.identity, `${path}.identity`, CONFIG_FIELDS.RestoreIdentityProjection),
|
|
68
74
|
`${path}.identity`,
|
|
@@ -70,7 +76,8 @@ export function assertRestoreInspection(value: unknown, path: string): void {
|
|
|
70
76
|
array(inspection.consistencyGroups, `${path}.consistencyGroups`).forEach((value, index) => {
|
|
71
77
|
const groupPath = `${path}.consistencyGroups[${index}]`;
|
|
72
78
|
const group = record(value, groupPath, CONFIG_FIELDS.RestoreConsistencyGroupProjection);
|
|
73
|
-
["id", "
|
|
79
|
+
["id", "authority"].forEach((key) => nonempty(group[key], `${groupPath}.${key}`));
|
|
80
|
+
discriminant(group.mode, BACKUP_CONSISTENCY_MODES, `${groupPath}.mode`);
|
|
74
81
|
});
|
|
75
82
|
array(inspection.domains, `${path}.domains`).forEach((value, index) =>
|
|
76
83
|
restoreDomain(value, `${path}.domains[${index}]`),
|
|
@@ -78,9 +85,8 @@ export function assertRestoreInspection(value: unknown, path: string): void {
|
|
|
78
85
|
array(inspection.exclusions, `${path}.exclusions`).forEach((value, index) => {
|
|
79
86
|
const exclusionPath = `${path}.exclusions[${index}]`;
|
|
80
87
|
const exclusion = record(value, exclusionPath, CONFIG_FIELDS.RestoreExclusionProjection);
|
|
81
|
-
["domainId", "
|
|
82
|
-
|
|
83
|
-
);
|
|
88
|
+
["domainId", "reason"].forEach((key) => nonempty(exclusion[key], `${exclusionPath}.${key}`));
|
|
89
|
+
discriminant(exclusion.storageClass, STORAGE_CLASSES, `${exclusionPath}.storageClass`);
|
|
84
90
|
boolean(exclusion.registered, `${exclusionPath}.registered`);
|
|
85
91
|
});
|
|
86
92
|
countReceipt(inspection.receipt, `${path}.receipt`, [
|
|
@@ -101,7 +107,7 @@ export function assertRestorePlan(value: unknown, path: string): void {
|
|
|
101
107
|
const entryPath = `${path}.entries[${index}]`;
|
|
102
108
|
const entry = record(value, entryPath, CONFIG_FIELDS.RestorePlanEntryProjection);
|
|
103
109
|
nonempty(entry.domainId, `${entryPath}.domainId`);
|
|
104
|
-
discriminant(entry.choice,
|
|
110
|
+
discriminant(entry.choice, RESTORE_CONFLICT_CHOICES, `${entryPath}.choice`);
|
|
105
111
|
nullableString(entry.action, `${entryPath}.action`);
|
|
106
112
|
if (entry.current !== null) {
|
|
107
113
|
currentEvidence(entry.current, `${entryPath}.current`);
|
|
@@ -128,7 +134,7 @@ export function assertRestoreExecutionReceipt(value: unknown, path: string): voi
|
|
|
128
134
|
"unchanged",
|
|
129
135
|
"totalDocumentBytes",
|
|
130
136
|
]);
|
|
131
|
-
|
|
137
|
+
assertBackupPublication(receipt.safetyBackup, `${path}.safetyBackup`);
|
|
132
138
|
[
|
|
133
139
|
"restoredDomainIds",
|
|
134
140
|
"deletedDomainIds",
|
|
@@ -141,19 +147,16 @@ export function assertRestoreExecutionReceipt(value: unknown, path: string): voi
|
|
|
141
147
|
|
|
142
148
|
export function assertRestoreFailure(value: unknown, path: string): void {
|
|
143
149
|
const failure = record(value, path, CONFIG_FIELDS.RestoreExecutionFailureProjection);
|
|
144
|
-
|
|
150
|
+
discriminant(failure.stage, RESTORE_EXECUTION_STAGES, `${path}.stage`);
|
|
145
151
|
nullableString(failure.domainId, `${path}.domainId`);
|
|
146
|
-
discriminant(
|
|
147
|
-
failure.terminal,
|
|
148
|
-
["noLiveMutation", "rolledBack", "recoveryRequired"],
|
|
149
|
-
`${path}.terminal`,
|
|
150
|
-
);
|
|
152
|
+
discriminant(failure.terminal, RESTORE_FAILURE_TERMINALS, `${path}.terminal`);
|
|
151
153
|
string(failure.detail, `${path}.detail`);
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
export function assertRestoreAdapterReceipt(value: unknown, path: string): void {
|
|
155
157
|
const receipt = record(value, path, CONFIG_FIELDS.RestoreAdapterReceiptProjection);
|
|
156
|
-
["domainId", "adapter"
|
|
158
|
+
["domainId", "adapter"].forEach((key) => nonempty(receipt[key], `${path}.${key}`));
|
|
159
|
+
discriminant(receipt.outcome, RESTORE_ADAPTER_OUTCOMES, `${path}.outcome`);
|
|
157
160
|
participation(receipt.participation, `${path}.participation`);
|
|
158
161
|
digest(receipt.confirmationDigest, `${path}.confirmationDigest`);
|
|
159
162
|
nullableDigest(receipt.evidence, `${path}.evidence`);
|
|
@@ -161,21 +164,18 @@ export function assertRestoreAdapterReceipt(value: unknown, path: string): void
|
|
|
161
164
|
|
|
162
165
|
export function assertRestoreRecoveryReceipt(value: unknown, path: string): void {
|
|
163
166
|
const receipt = record(value, path, CONFIG_FIELDS.RestoreRecoveryReceiptProjection);
|
|
164
|
-
discriminant(
|
|
165
|
-
receipt.outcome,
|
|
166
|
-
["noRecoveryNeeded", "rolledBack", "terminalCleanup"],
|
|
167
|
-
`${path}.outcome`,
|
|
168
|
-
);
|
|
167
|
+
discriminant(receipt.outcome, RESTORE_RECOVERY_RESULTS, `${path}.outcome`);
|
|
169
168
|
stringArray(receipt.domainIds, `${path}.domainIds`);
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
function storage(value: unknown, path: string): void {
|
|
173
172
|
const projection = record(value, path, CONFIG_FIELDS.StorageOperationsProjection);
|
|
174
173
|
const layout = record(projection.layout, `${path}.layout`, CONFIG_FIELDS.StorageLayoutProjection);
|
|
175
|
-
discriminant(layout.profile,
|
|
174
|
+
discriminant(layout.profile, STORAGE_PROFILE_IDS, `${path}.layout.profile`);
|
|
176
175
|
["platform", "canonicalApplicationId", "effectiveLeaf"].forEach((key) =>
|
|
177
176
|
nonempty(layout[key], `${path}.layout.${key}`),
|
|
178
177
|
);
|
|
178
|
+
discriminant(layout.leafProvenance, STORAGE_LEAF_PROVENANCES, `${path}.layout.leafProvenance`);
|
|
179
179
|
digest(layout.layoutDigest, `${path}.layout.layoutDigest`);
|
|
180
180
|
array(layout.roots, `${path}.layout.roots`).forEach((rootValue, index) => {
|
|
181
181
|
const root = record(
|
|
@@ -190,7 +190,7 @@ function storage(value: unknown, path: string): void {
|
|
|
190
190
|
const bootstrap = record(projection.bootstrap, `${path}.bootstrap`);
|
|
191
191
|
discriminant(bootstrap.state, STORAGE_BOOTSTRAP_STATES, `${path}.bootstrap.state`);
|
|
192
192
|
array(projection.availableProfiles, `${path}.availableProfiles`).forEach((profile, index) =>
|
|
193
|
-
discriminant(profile,
|
|
193
|
+
discriminant(profile, STORAGE_PROFILE_IDS, `${path}.availableProfiles[${index}]`),
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -205,9 +205,10 @@ function backup(value: unknown, path: string): void {
|
|
|
205
205
|
array(inventory.archives, `${path}.inventory.archives`).forEach((archiveValue, index) => {
|
|
206
206
|
const archivePath = `${path}.inventory.archives[${index}]`;
|
|
207
207
|
const archive = record(archiveValue, archivePath, CONFIG_FIELDS.BackupArchiveProjection);
|
|
208
|
-
["path", "archiveId", "createdAt"
|
|
208
|
+
["path", "archiveId", "createdAt"].forEach((key) =>
|
|
209
209
|
nonempty(archive[key], `${archivePath}.${key}`),
|
|
210
210
|
);
|
|
211
|
+
discriminant(archive.kind, BACKUP_KINDS, `${archivePath}.kind`);
|
|
211
212
|
digest(archive.archiveSha256, `${archivePath}.archiveSha256`);
|
|
212
213
|
});
|
|
213
214
|
array(inventory.entries, `${path}.inventory.entries`).forEach((entryValue, index) =>
|
|
@@ -234,7 +235,7 @@ function backup(value: unknown, path: string): void {
|
|
|
234
235
|
|
|
235
236
|
function restoreState(value: unknown, path: string): void {
|
|
236
237
|
const projection = record(value, path, CONFIG_FIELDS.RestoreOperationsProjection);
|
|
237
|
-
discriminant(projection.state,
|
|
238
|
+
discriminant(projection.state, RESTORE_OPERATION_STATES, `${path}.state`);
|
|
238
239
|
nullableDigest(projection.safetyBackupSha256, `${path}.safetyBackupSha256`);
|
|
239
240
|
}
|
|
240
241
|
|
|
@@ -252,9 +253,11 @@ function identity(value: Record<string, unknown>, path: string): void {
|
|
|
252
253
|
|
|
253
254
|
function restoreDomain(value: unknown, path: string): void {
|
|
254
255
|
const domain = record(value, path, CONFIG_FIELDS.RestoreDomainInspectionProjection);
|
|
255
|
-
["domainId", "
|
|
256
|
+
["domainId", "consistencyGroup", "adapter"].forEach((key) =>
|
|
256
257
|
nonempty(domain[key], `${path}.${key}`),
|
|
257
258
|
);
|
|
259
|
+
discriminant(domain.storageClass, STORAGE_CLASSES, `${path}.storageClass`);
|
|
260
|
+
discriminant(domain.sourceState, BACKUP_SOURCE_STATES, `${path}.sourceState`);
|
|
258
261
|
if (domain.sourceSchemaVersion !== null) {
|
|
259
262
|
finiteNumber(domain.sourceSchemaVersion, `${path}.sourceSchemaVersion`);
|
|
260
263
|
}
|
|
@@ -297,18 +300,15 @@ function currentEvidence(value: unknown, path: string): void {
|
|
|
297
300
|
|
|
298
301
|
function inventoryEntry(value: unknown, path: string): void {
|
|
299
302
|
const entry = record(value, path, CONFIG_FIELDS.BackupInventoryEntry);
|
|
300
|
-
discriminant(
|
|
301
|
-
entry.state,
|
|
302
|
-
["valid", "locked", "corrupt", "foreign", "unknown", "unreadable", "unmanaged"],
|
|
303
|
-
`${path}.state`,
|
|
304
|
-
);
|
|
303
|
+
discriminant(entry.state, BACKUP_INVENTORY_ENTRY_STATES, `${path}.state`);
|
|
305
304
|
nonempty(entry.diagnosticKind, `${path}.diagnosticKind`);
|
|
306
305
|
string(entry.detail, `${path}.detail`);
|
|
307
306
|
}
|
|
308
307
|
|
|
309
|
-
function
|
|
308
|
+
export function assertBackupPublication(value: unknown, path: string): void {
|
|
310
309
|
const receipt = record(value, path, CONFIG_FIELDS.BackupPublicationReceiptProjection);
|
|
311
|
-
["path", "destination"
|
|
310
|
+
["path", "destination"].forEach((key) => nonempty(receipt[key], `${path}.${key}`));
|
|
311
|
+
discriminant(receipt.durability, BACKUP_PUBLICATION_DURABILITIES, `${path}.durability`);
|
|
312
312
|
digest(receipt.archiveSha256, `${path}.archiveSha256`);
|
|
313
313
|
boolean(receipt.replacedExisting, `${path}.replacedExisting`);
|
|
314
314
|
}
|