@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.
Files changed (167) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -7
  3. package/src/agent-control/generated/protocol.ts +228 -0
  4. package/src/agent-control/index.ts +1 -5
  5. package/src/agent-control/inject.ts +4 -1
  6. package/src/agent-control/selection.ts +42 -25
  7. package/src/agent-control/shim.ts +428 -198
  8. package/src/bridge/direct.ts +1 -1
  9. package/src/bridge/generated/fields.ts +4 -3
  10. package/src/bridge/generated/protocol.ts +62 -7
  11. package/src/bridge/generated/variant-fields.ts +1 -1
  12. package/src/bridge/job.ts +49 -12
  13. package/src/bridge/loopback.ts +7 -25
  14. package/src/bridge/operation.ts +13 -43
  15. package/src/bridge/router.ts +10 -23
  16. package/src/bridge/runtime/connection.ts +78 -109
  17. package/src/bridge/runtime/policy.ts +8 -28
  18. package/src/bridge/runtime/retry.ts +6 -18
  19. package/src/bridge/session.ts +4 -14
  20. package/src/bridge/stream/connection.ts +24 -55
  21. package/src/bridge/stream/source.ts +2 -6
  22. package/src/bridge/stream/tracker.ts +12 -12
  23. package/src/bridge/supervision.ts +104 -97
  24. package/src/bridge/validation/base.ts +21 -63
  25. package/src/bridge/validation/jobs.ts +11 -25
  26. package/src/bridge/validation/negotiation.ts +28 -43
  27. package/src/bridge/validation/operations.ts +29 -65
  28. package/src/bridge/validation/streams.ts +3 -10
  29. package/src/commands/client.ts +37 -28
  30. package/src/commands/controller.ts +119 -96
  31. package/src/commands/generated/fields.ts +7 -6
  32. package/src/commands/generated/protocol.ts +28 -1
  33. package/src/commands/generated/variant-fields.ts +1 -1
  34. package/src/commands/keyboard.ts +94 -100
  35. package/src/commands/physical-code.ts +11 -0
  36. package/src/commands/ports.ts +8 -13
  37. package/src/commands/projectors.ts +100 -75
  38. package/src/commands/validation.ts +434 -241
  39. package/src/config/client.ts +9 -22
  40. package/src/config/generated/base.ts +22 -6
  41. package/src/config/generated/fields.ts +4 -3
  42. package/src/config/generated/label-template.ts +1 -1
  43. package/src/config/generated/labels.ts +1 -1
  44. package/src/config/generated/protocol.ts +1 -1
  45. package/src/config/generated/restore.ts +35 -12
  46. package/src/config/generated/variant-fields.ts +1 -1
  47. package/src/config/names.ts +6 -12
  48. package/src/config/validation/commands.ts +11 -25
  49. package/src/config/validation/outcomes.ts +163 -70
  50. package/src/config/validation/primitives.ts +35 -80
  51. package/src/config/validation/projection.ts +100 -128
  52. package/src/core/connection.ts +187 -83
  53. package/src/core/controller-lifecycle.ts +144 -0
  54. package/src/core/generated/identifiers.ts +4 -0
  55. package/src/core/identifiers.ts +40 -0
  56. package/src/core/index.ts +10 -1
  57. package/src/core/json-value.ts +58 -0
  58. package/src/core/listeners.ts +35 -0
  59. package/src/core/record.ts +80 -0
  60. package/src/core/transport.ts +9 -11
  61. package/src/core/wire-copy.ts +7 -0
  62. package/src/history/client.ts +11 -13
  63. package/src/history/controller.ts +106 -108
  64. package/src/history/direct.ts +1 -3
  65. package/src/history/generated/fields.ts +4 -3
  66. package/src/history/generated/protocol.ts +8 -5
  67. package/src/history/generated/variant-fields.ts +1 -1
  68. package/src/history/ports.ts +7 -4
  69. package/src/history/serialized.ts +9 -13
  70. package/src/history/validation.ts +69 -75
  71. package/src/history-tree/client.ts +89 -11
  72. package/src/history-tree/controller.ts +380 -96
  73. package/src/history-tree/direct.ts +3 -1
  74. package/src/history-tree/generated/fields.ts +5 -3
  75. package/src/history-tree/generated/protocol.ts +43 -7
  76. package/src/history-tree/generated/variant-fields.ts +7 -1
  77. package/src/history-tree/ports.ts +12 -5
  78. package/src/history-tree/serialized.ts +39 -11
  79. package/src/history-tree/validation.ts +286 -78
  80. package/src/layout/generated/protocol.ts +4 -3
  81. package/src/layout/generated/variant-fields.ts +47 -0
  82. package/src/layout/index.ts +1 -1
  83. package/src/layout/ratio.ts +10 -9
  84. package/src/layout/validation.ts +98 -32
  85. package/src/layout/visibility.ts +1 -2
  86. package/src/licence/client.ts +48 -7
  87. package/src/licence/controller.ts +127 -70
  88. package/src/licence/direct.ts +3 -1
  89. package/src/licence/generated/fields.ts +4 -3
  90. package/src/licence/generated/key-conformance.json +28 -0
  91. package/src/licence/generated/protocol.ts +9 -5
  92. package/src/licence/generated/variant-fields.ts +1 -1
  93. package/src/licence/key.ts +42 -18
  94. package/src/licence/ports.ts +10 -3
  95. package/src/licence/serialized.ts +32 -9
  96. package/src/licence/validation.ts +134 -43
  97. package/src/native-content/client.ts +207 -234
  98. package/src/native-content/generated/fields.ts +6 -6
  99. package/src/native-content/generated/protocol.ts +16 -5
  100. package/src/native-content/generated/variant-fields.ts +1 -1
  101. package/src/native-content/ports.ts +11 -16
  102. package/src/native-content/serialized.ts +12 -19
  103. package/src/native-content/validation/base.ts +57 -80
  104. package/src/native-content/validation/messages.ts +24 -35
  105. package/src/native-content/validation/state.ts +31 -33
  106. package/src/notifications/client.ts +85 -51
  107. package/src/notifications/controller.ts +400 -145
  108. package/src/notifications/direct.ts +3 -1
  109. package/src/notifications/generated/fields.ts +4 -3
  110. package/src/notifications/generated/labels.ts +1 -1
  111. package/src/notifications/generated/protocol.ts +5 -1
  112. package/src/notifications/generated/variant-fields.ts +1 -1
  113. package/src/notifications/ports.ts +9 -4
  114. package/src/notifications/serialized.ts +11 -9
  115. package/src/notifications/tone.ts +1 -1
  116. package/src/notifications/validation.ts +165 -71
  117. package/src/operation/bridge.ts +187 -60
  118. package/src/operation/client.ts +48 -62
  119. package/src/operation/controller.ts +67 -97
  120. package/src/operation/direct.ts +1 -3
  121. package/src/operation/generated/fields.ts +4 -3
  122. package/src/operation/generated/labels.ts +1 -1
  123. package/src/operation/generated/protocol.ts +5 -1
  124. package/src/operation/generated/variant-fields.ts +1 -1
  125. package/src/operation/ports.ts +12 -10
  126. package/src/operation/serialized.ts +8 -9
  127. package/src/operation/validation.ts +189 -104
  128. package/src/settings/client.ts +11 -44
  129. package/src/settings/connection.ts +35 -53
  130. package/src/settings/generated/fields.ts +5 -4
  131. package/src/settings/generated/protocol.ts +14 -5
  132. package/src/settings/generated/variant-fields.ts +1 -1
  133. package/src/settings/names.ts +2 -4
  134. package/src/settings/registry.ts +23 -25
  135. package/src/settings/validation/authority.ts +21 -19
  136. package/src/settings/validation/command.ts +22 -41
  137. package/src/settings/validation/error.ts +2 -8
  138. package/src/settings/validation/primitives.ts +46 -97
  139. package/src/settings/validation/projection.ts +8 -24
  140. package/src/settings/validation/registry.ts +33 -79
  141. package/src/surface-transfer/client.ts +6 -18
  142. package/src/surface-transfer/generated/fields.ts +3 -3
  143. package/src/surface-transfer/generated/protocol.ts +3 -3
  144. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  145. package/src/surface-transfer/validation.ts +91 -86
  146. package/src/surfaces/client.ts +33 -55
  147. package/src/surfaces/generated/fields.ts +3 -3
  148. package/src/surfaces/generated/protocol.ts +1 -1
  149. package/src/surfaces/generated/variant-fields.ts +1 -1
  150. package/src/surfaces/validation.ts +227 -99
  151. package/src/transfer/client.ts +26 -60
  152. package/src/transfer/connection.ts +29 -51
  153. package/src/transfer/generated/fields.ts +7 -6
  154. package/src/transfer/generated/protocol.ts +13 -5
  155. package/src/transfer/generated/variant-fields.ts +1 -1
  156. package/src/transfer/index.ts +8 -1
  157. package/src/transfer/payload.ts +20 -35
  158. package/src/transfer/validation.ts +169 -119
  159. package/src/update/client.ts +86 -9
  160. package/src/update/controller.ts +264 -116
  161. package/src/update/direct.ts +3 -1
  162. package/src/update/generated/fields.ts +5 -4
  163. package/src/update/generated/protocol.ts +25 -9
  164. package/src/update/generated/variant-fields.ts +4 -2
  165. package/src/update/ports.ts +14 -6
  166. package/src/update/serialized.ts +36 -10
  167. package/src/update/validation.ts +118 -48
@@ -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,23 +15,28 @@ 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,
20
- type BackupCreateOutcome,
21
- type BackupExportOutcome,
22
- type BackupRetentionApplyOutcome,
23
- type RestoreAdapterExecuteOutcome,
24
- type RestoreExecuteOutcome,
25
- type RestoreInspectOutcome,
26
- type RestorePlanOutcome,
27
- type RestoreRecoveryOutcomeProjection,
28
- type StorageCleanupOutcome,
29
- type StorageRecoveryOutcome,
30
- type StorageTransitionExecuteOutcome,
31
- type StorageTransitionInspectOutcome,
23
+ } from "../generated/protocol.ts";
24
+ import type {
25
+ BackupCreateOutcome,
26
+ BackupExportOutcome,
27
+ BackupRetentionApplyOutcome,
28
+ RestoreAdapterExecuteOutcome,
29
+ RestoreExecuteOutcome,
30
+ RestoreInspectOutcome,
31
+ RestorePlanOutcome,
32
+ RestoreRecoveryOutcomeProjection,
33
+ StorageCleanupOutcome,
34
+ StorageRecoveryOutcome,
35
+ StorageTransitionExecuteOutcome,
36
+ StorageTransitionInspectOutcome,
32
37
  } from "../generated/protocol.ts";
33
38
  import {
39
+ assertBackupPublication,
34
40
  assertValidConfigOperationsSnapshot,
35
41
  assertRestoreAdapterReceipt,
36
42
  assertRestoreExecutionReceipt,
@@ -41,9 +47,12 @@ import {
41
47
  } from "./projection.ts";
42
48
  import {
43
49
  array,
50
+ boolean,
44
51
  digest,
45
52
  discriminant,
46
53
  finiteNumber,
54
+ nullableDigest,
55
+ nullableString,
47
56
  record,
48
57
  string,
49
58
  fail,
@@ -52,24 +61,15 @@ import {
52
61
  export function assertValidStorageTransitionInspectOutcome(
53
62
  value: unknown,
54
63
  ): asserts value is StorageTransitionInspectOutcome {
55
- outcome(value, STORAGE_TRANSITION_INSPECT_STATUSES, "$", "StorageTransitionInspectOutcome");
56
- const result = record(value, "$");
64
+ const result = outcome(
65
+ value,
66
+ STORAGE_TRANSITION_INSPECT_STATUSES,
67
+ "$",
68
+ "StorageTransitionInspectOutcome",
69
+ );
57
70
  if (result.status === "ready") {
58
71
  finiteNumber(result.generation, "$.generation");
59
- const preview = record(
60
- result.preview,
61
- "$.preview",
62
- CONFIG_FIELDS.StorageTransitionPreviewProjection,
63
- );
64
- [
65
- "sourceLayoutDigest",
66
- "targetLayoutDigest",
67
- "evidenceDigest",
68
- "confirmationDigest",
69
- ].forEach((key) => digest(preview[key], `$.preview.${key}`));
70
- array(preview.domains, "$.preview.domains");
71
- array(preview.unknownSourcePaths, "$.preview.unknownSourcePaths");
72
- array(preview.conflicts, "$.preview.conflicts");
72
+ assertStorageTransitionPreview(result.preview);
73
73
  } else {
74
74
  rejection(result.rejection, "$.rejection");
75
75
  }
@@ -78,44 +78,68 @@ export function assertValidStorageTransitionInspectOutcome(
78
78
  export function assertValidStorageTransitionExecuteOutcome(
79
79
  value: unknown,
80
80
  ): asserts value is StorageTransitionExecuteOutcome {
81
- mutationOutcome(value, STORAGE_TRANSITION_EXECUTE_STATUSES, "committed", "StorageTransitionExecuteOutcome");
81
+ mutationOutcome(
82
+ value,
83
+ STORAGE_TRANSITION_EXECUTE_STATUSES,
84
+ "committed",
85
+ "StorageTransitionExecuteOutcome",
86
+ (result) => assertStorageTransitionReceipt(result.receipt),
87
+ );
82
88
  }
83
89
 
84
90
  export function assertValidStorageRecoveryOutcome(
85
91
  value: unknown,
86
92
  ): asserts value is StorageRecoveryOutcome {
87
- mutationOutcome(value, STORAGE_RECOVERY_STATUSES, "recovered", "StorageRecoveryOutcome");
93
+ mutationOutcome(
94
+ value,
95
+ STORAGE_RECOVERY_STATUSES,
96
+ "recovered",
97
+ "StorageRecoveryOutcome",
98
+ (result) => assertStorageRecoveryReceipt(result.receipt),
99
+ );
88
100
  }
89
101
 
90
102
  export function assertValidStorageCleanupOutcome(
91
103
  value: unknown,
92
104
  ): asserts value is StorageCleanupOutcome {
93
- mutationOutcome(value, STORAGE_CLEANUP_STATUSES, "applied", "StorageCleanupOutcome");
105
+ mutationOutcome(value, STORAGE_CLEANUP_STATUSES, "applied", "StorageCleanupOutcome", (result) =>
106
+ assertStorageCleanupReceipt(result.receipt),
107
+ );
94
108
  }
95
109
 
96
110
  export function assertValidBackupCreateOutcome(
97
111
  value: unknown,
98
112
  ): asserts value is BackupCreateOutcome {
99
- 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
+ });
100
117
  }
101
118
 
102
119
  export function assertValidBackupExportOutcome(
103
120
  value: unknown,
104
121
  ): asserts value is BackupExportOutcome {
105
- mutationOutcome(value, BACKUP_EXPORT_STATUSES, "published", "BackupExportOutcome");
122
+ mutationOutcome(value, BACKUP_EXPORT_STATUSES, "published", "BackupExportOutcome", (result) =>
123
+ assertBackupPublication(result.publication, "$.publication"),
124
+ );
106
125
  }
107
126
 
108
127
  export function assertValidBackupRetentionApplyOutcome(
109
128
  value: unknown,
110
129
  ): asserts value is BackupRetentionApplyOutcome {
111
- mutationOutcome(value, BACKUP_RETENTION_APPLY_STATUSES, "applied", "BackupRetentionApplyOutcome");
130
+ mutationOutcome(
131
+ value,
132
+ BACKUP_RETENTION_APPLY_STATUSES,
133
+ "applied",
134
+ "BackupRetentionApplyOutcome",
135
+ (result) => stringArray(result.deletedPaths, "$.deletedPaths"),
136
+ );
112
137
  }
113
138
 
114
139
  export function assertValidRestoreInspectOutcome(
115
140
  value: unknown,
116
141
  ): asserts value is RestoreInspectOutcome {
117
- outcome(value, RESTORE_INSPECT_STATUSES, "$", "RestoreInspectOutcome");
118
- const result = record(value, "$");
142
+ const result = outcome(value, RESTORE_INSPECT_STATUSES, "$", "RestoreInspectOutcome");
119
143
  if (result.status === "ready") {
120
144
  finiteNumber(result.generation, "$.generation");
121
145
  assertRestoreInspection(result.inspection, "$.inspection");
@@ -126,11 +150,8 @@ export function assertValidRestoreInspectOutcome(
126
150
  }
127
151
  }
128
152
 
129
- export function assertValidRestorePlanOutcome(
130
- value: unknown,
131
- ): asserts value is RestorePlanOutcome {
132
- outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
133
- const result = record(value, "$");
153
+ export function assertValidRestorePlanOutcome(value: unknown): asserts value is RestorePlanOutcome {
154
+ const result = outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
134
155
  if (result.status === "ready") {
135
156
  finiteNumber(result.generation, "$.generation");
136
157
  assertRestorePlan(result.plan, "$.plan");
@@ -142,15 +163,11 @@ export function assertValidRestorePlanOutcome(
142
163
  export function assertValidRestoreExecuteOutcome(
143
164
  value: unknown,
144
165
  ): asserts value is RestoreExecuteOutcome {
145
- outcome(value, RESTORE_EXECUTE_STATUSES, "$", "RestoreExecuteOutcome");
146
- const result = record(value, "$");
166
+ const result = outcome(value, RESTORE_EXECUTE_STATUSES, "$", "RestoreExecuteOutcome");
147
167
  if (result.status === "succeeded") {
148
168
  assertRestoreExecutionReceipt(result.receipt, "$.receipt");
149
169
  assertValidConfigOperationsSnapshot(result.snapshot);
150
- } else if (
151
- result.status === "rolledBack" ||
152
- result.status === "recoveryRequired"
153
- ) {
170
+ } else if (result.status === "rolledBack" || result.status === "recoveryRequired") {
154
171
  assertRestoreFailure(result.failure, "$.failure");
155
172
  assertValidConfigOperationsSnapshot(result.snapshot);
156
173
  } else {
@@ -161,8 +178,12 @@ export function assertValidRestoreExecuteOutcome(
161
178
  export function assertValidRestoreAdapterExecuteOutcome(
162
179
  value: unknown,
163
180
  ): asserts value is RestoreAdapterExecuteOutcome {
164
- outcome(value, RESTORE_ADAPTER_EXECUTE_STATUSES, "$", "RestoreAdapterExecuteOutcome");
165
- const result = record(value, "$");
181
+ const result = outcome(
182
+ value,
183
+ RESTORE_ADAPTER_EXECUTE_STATUSES,
184
+ "$",
185
+ "RestoreAdapterExecuteOutcome",
186
+ );
166
187
  if (result.status === "completed") {
167
188
  assertRestoreAdapterReceipt(result.receipt, "$.receipt");
168
189
  assertValidConfigOperationsSnapshot(result.snapshot);
@@ -174,8 +195,7 @@ export function assertValidRestoreAdapterExecuteOutcome(
174
195
  export function assertValidRestoreRecoveryOutcome(
175
196
  value: unknown,
176
197
  ): asserts value is RestoreRecoveryOutcomeProjection {
177
- outcome(value, RESTORE_RECOVERY_STATUSES, "$", "RestoreRecoveryOutcomeProjection");
178
- const result = record(value, "$");
198
+ const result = outcome(value, RESTORE_RECOVERY_STATUSES, "$", "RestoreRecoveryOutcomeProjection");
179
199
  if (result.status === "recovered") {
180
200
  assertRestoreRecoveryReceipt(result.receipt, "$.receipt");
181
201
  assertValidConfigOperationsSnapshot(result.snapshot);
@@ -189,13 +209,14 @@ export function assertValidRestoreRecoveryOutcome(
189
209
 
190
210
  function mutationOutcome(
191
211
  value: unknown,
192
- variants: readonly string[],
212
+ variants: ReadonlyArray<string>,
193
213
  success: string,
194
214
  type: string,
215
+ checkSuccess: (result: Record<string, unknown>) => void,
195
216
  ): void {
196
- outcome(value, variants, "$", type);
197
- const result = record(value, "$");
217
+ const result = outcome(value, variants, "$", type);
198
218
  if (result.status === success) {
219
+ checkSuccess(result);
199
220
  assertValidConfigOperationsSnapshot(result.snapshot);
200
221
  } else {
201
222
  rejection(result.rejection, "$.rejection");
@@ -213,31 +234,103 @@ function rejection(value: unknown, path: string): void {
213
234
 
214
235
  function outcome(
215
236
  value: unknown,
216
- variants: readonly string[],
237
+ variants: ReadonlyArray<string>,
217
238
  path: string,
218
239
  type: string,
219
- ): void {
240
+ ): Record<string, unknown> {
220
241
  const result = record(value, path);
221
242
  discriminant(result.status, variants, `${path}.status`);
222
- // The discriminant is checked above, so a missing map entry means the
223
- // generator failed rather than that a caller sent something odd.
224
- record(result, path, variantKeys(type, result, path));
243
+ return record(result, path, variantKeys(type, result, path));
225
244
  }
226
245
 
227
- /**
228
- * Allowed keys for one tagged-union variant, from the generated map, with the
229
- * discriminant's name read from the map too. This domain tags on `status`,
230
- * `state`, `kind` and `source`.
231
- */
232
246
  function variantKeys(
233
247
  type: string,
234
248
  value: Record<string, unknown>,
235
249
  path: string,
236
- ): readonly string[] {
237
- const discriminant = value[CONFIG_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "status"];
238
- const keys = CONFIG_VARIANT_FIELDS[type]?.[discriminant as string];
239
- if (keys === undefined) {
240
- fail("invalid_payload", path, `no generated fields for ${type}.${String(discriminant)}`);
250
+ ): ReadonlyArray<string> {
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}]`);
241
335
  }
242
- return keys;
243
336
  }
@@ -1,4 +1,5 @@
1
- import { CONFIG_MAXIMUM_OPAQUE_ID_BYTES } from "../generated/base.ts";
1
+ import { isOpaqueId } from "../../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord } from "../../core/record.ts";
2
3
  import { CONFIG_OPERATIONS_PROTOCOL_VERSION } from "../generated/protocol.ts";
3
4
 
4
5
  export type ConfigProtocolValidationCode =
@@ -10,11 +11,7 @@ export class ConfigProtocolValidationError extends Error {
10
11
  readonly code: ConfigProtocolValidationCode;
11
12
  readonly path: string;
12
13
 
13
- constructor(
14
- code: ConfigProtocolValidationCode,
15
- path: string,
16
- message: string,
17
- ) {
14
+ constructor(code: ConfigProtocolValidationCode, path: string, message: string) {
18
15
  super(message);
19
16
  this.name = "ConfigProtocolValidationError";
20
17
  this.code = code;
@@ -25,7 +22,7 @@ export class ConfigProtocolValidationError extends Error {
25
22
  export function baseCommand(
26
23
  value: unknown,
27
24
  path: string,
28
- allowed?: readonly string[],
25
+ allowed?: ReadonlyArray<string>,
29
26
  ): Record<string, unknown> {
30
27
  const command = record(value, path, allowed);
31
28
  protocol(command.protocolVersion, `${path}.protocolVersion`);
@@ -43,61 +40,36 @@ export function protocol(value: unknown, path: string): void {
43
40
  }
44
41
  }
45
42
 
46
- /**
47
- * Rejects a non-object, an unknown key, and a missing key.
48
- *
49
- * `allowed` comes from the generated field map, so the keys accepted are the
50
- * Rust struct's and nothing else — contract 010's Boundary Validation Target.
51
- * `path` is kept ahead of it because every existing caller passes one and it
52
- * is what makes a rejection locatable in a nested document.
53
- *
54
- * Called without a list, this keeps shape-only behaviour. That is correct for
55
- * a tagged union, whose allowed keys depend on its discriminant, and it is a
56
- * gap anywhere else — the remaining untyped call sites are the work left.
57
- */
58
43
  export function record(
59
44
  value: unknown,
60
45
  path: string,
61
- allowed?: readonly string[],
46
+ allowed?: ReadonlyArray<string>,
62
47
  ): Record<string, unknown> {
63
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
64
- fail("invalid_payload", path, "expected object");
65
- }
66
- const result = value as Record<string, unknown>;
67
- if (allowed === undefined) return result;
68
-
69
- const permitted = new Set(allowed);
70
- for (const key of Object.keys(result)) {
71
- if (!permitted.has(key)) {
72
- fail("invalid_payload", `${path}.${key}`, "unknown field");
73
- }
74
- }
75
- for (const key of allowed) {
76
- if (!(key in result)) {
77
- fail("invalid_payload", `${path}.${key}`, "missing field");
78
- }
79
- }
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
+ );
80
56
  return result;
81
57
  }
82
58
 
83
- export function array(value: unknown, path: string): unknown[] {
84
- if (!Array.isArray(value)) fail("invalid_payload", path, "expected array");
59
+ export function array(value: unknown, path: string): Array<unknown> {
60
+ if (!Array.isArray(value)) {
61
+ fail("invalid_payload", path, "expected array");
62
+ }
85
63
  return value;
86
64
  }
87
65
 
88
- export function string(
89
- value: unknown,
90
- path: string,
91
- ): asserts value is string {
66
+ export function string(value: unknown, path: string): asserts value is string {
92
67
  if (typeof value !== "string") {
93
68
  fail("invalid_payload", path, "expected string");
94
69
  }
95
70
  }
96
71
 
97
- export function nonempty(
98
- value: unknown,
99
- path: string,
100
- ): asserts value is string {
72
+ export function nonempty(value: unknown, path: string): asserts value is string {
101
73
  string(value, path);
102
74
  if (value.length === 0) {
103
75
  fail("invalid_payload", path, "expected nonempty string");
@@ -105,13 +77,12 @@ export function nonempty(
105
77
  }
106
78
 
107
79
  export function nullableString(value: unknown, path: string): void {
108
- if (value !== null) string(value, path);
80
+ if (value !== null) {
81
+ string(value, path);
82
+ }
109
83
  }
110
84
 
111
- export function digest(
112
- value: unknown,
113
- path: string,
114
- ): asserts value is string {
85
+ export function digest(value: unknown, path: string): asserts value is string {
115
86
  string(value, path);
116
87
  if (!/^[0-9a-f]{64}$/.test(value)) {
117
88
  fail("invalid_payload", path, "expected lowercase SHA-256 digest");
@@ -119,36 +90,18 @@ export function digest(
119
90
  }
120
91
 
121
92
  export function nullableDigest(value: unknown, path: string): void {
122
- if (value !== null) digest(value, path);
123
- }
124
-
125
- export function opaqueId(
126
- value: unknown,
127
- path: string,
128
- ): asserts value is string {
129
- string(value, path);
130
- if (
131
- value.length === 0 ||
132
- value.length > CONFIG_MAXIMUM_OPAQUE_ID_BYTES ||
133
- !/^[a-z0-9._:-]+$/.test(value)
134
- ) {
135
- fail("invalid_payload", path, "expected bounded lowercase opaque id");
93
+ if (value !== null) {
94
+ digest(value, path);
136
95
  }
137
96
  }
138
97
 
139
- export function finiteNumber(
140
- value: unknown,
141
- path: string,
142
- ): asserts value is number {
98
+ export function finiteNumber(value: unknown, path: string): asserts value is number {
143
99
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
144
100
  fail("invalid_payload", path, "expected non-negative safe integer");
145
101
  }
146
102
  }
147
103
 
148
- export function boolean(
149
- value: unknown,
150
- path: string,
151
- ): asserts value is boolean {
104
+ export function boolean(value: unknown, path: string): asserts value is boolean {
152
105
  if (typeof value !== "boolean") {
153
106
  fail("invalid_payload", path, "expected boolean");
154
107
  }
@@ -156,7 +109,7 @@ export function boolean(
156
109
 
157
110
  export function discriminant(
158
111
  value: unknown,
159
- variants: readonly string[],
112
+ variants: ReadonlyArray<string>,
160
113
  path: string,
161
114
  ): asserts value is string {
162
115
  string(value, path);
@@ -165,10 +118,12 @@ export function discriminant(
165
118
  }
166
119
  }
167
120
 
168
- export function fail(
169
- code: ConfigProtocolValidationCode,
170
- path: string,
171
- message: string,
172
- ): never {
121
+ export function fail(code: ConfigProtocolValidationCode, path: string, message: string): never {
173
122
  throw new ConfigProtocolValidationError(code, path, message);
174
123
  }
124
+
125
+ function opaqueId(value: unknown, path: string): asserts value is string {
126
+ if (!isOpaqueId(value)) {
127
+ fail("invalid_payload", path, "expected bounded lowercase opaque id");
128
+ }
129
+ }