@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,5 +1,10 @@
1
+ import { isOpaqueId } from "../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
1
3
  import { OPERATION_FIELDS } from "./generated/fields.ts";
2
- import { OPERATION_VARIANT_FIELDS, OPERATION_VARIANT_FIELDS_DISCRIMINANTS } from "./generated/variant-fields.ts";
4
+ import {
5
+ OPERATION_VARIANT_FIELDS,
6
+ OPERATION_VARIANT_FIELDS_DISCRIMINANTS,
7
+ } from "./generated/variant-fields.ts";
3
8
  import {
4
9
  OPERATION_CANCELLATION_OUTCOMES,
5
10
  OPERATION_CANCELLATION_STATUSES,
@@ -12,27 +17,26 @@ import {
12
17
  OPERATION_PROTOCOL_VERSION,
13
18
  OPERATION_REJECTION_CODES,
14
19
  OPERATION_STATES,
15
- type OperationCancellationCommand,
16
- type OperationCancellationResult,
17
- type OperationChangedEvent,
18
- type OperationEntryProjection,
19
- type OperationMutationCommand,
20
- type OperationMutationResult,
21
- type OperationSnapshot,
22
- type OperationSnapshotQuery,
23
- type OperationSnapshotResponse,
20
+ } from "./generated/protocol.ts";
21
+ import type {
22
+ OperationCancellationCommand,
23
+ OperationCancellationResult,
24
+ OperationChangedEvent,
25
+ OperationEntryProjection,
26
+ OperationMutationCommand,
27
+ OperationMutationResult,
28
+ OperationSnapshot,
29
+ OperationSnapshotQuery,
30
+ OperationSnapshotResponse,
24
31
  } from "./generated/protocol.ts";
25
32
 
26
- const FORBIDDEN_PAYLOAD_KEYS = new Set([
27
- "payload",
28
- "result",
29
- "artifact",
30
- "report",
31
- "log",
32
- ]);
33
+ const FORBIDDEN_PAYLOAD_KEYS = new Set(["payload", "result", "artifact", "report", "log"]);
33
34
 
34
35
  export class OperationProtocolValidationError extends Error {
35
- constructor(readonly path: string, message: string) {
36
+ constructor(
37
+ readonly path: string,
38
+ message: string,
39
+ ) {
36
40
  super(`incompatible operation protocol at ${path}: ${message}`);
37
41
  this.name = "OperationProtocolValidationError";
38
42
  }
@@ -43,7 +47,7 @@ export function assertValidOperationSnapshotQuery(
43
47
  ): asserts value is OperationSnapshotQuery {
44
48
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotQuery);
45
49
  protocol(object.protocolVersion, "$.protocolVersion");
46
- text(object.requestId, "$.requestId");
50
+ identifier(object.requestId, "$.requestId");
47
51
  }
48
52
 
49
53
  export function assertValidOperationSnapshotResponse(
@@ -51,30 +55,32 @@ export function assertValidOperationSnapshotResponse(
51
55
  ): asserts value is OperationSnapshotResponse {
52
56
  assertPayloadFree(value);
53
57
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotResponse);
54
- text(object.requestId, "$.requestId");
58
+ identifier(object.requestId, "$.requestId");
55
59
  assertValidOperationSnapshot(object.snapshot);
56
60
  }
57
61
 
58
- export function assertValidOperationSnapshot(
59
- value: unknown,
60
- ): asserts value is OperationSnapshot {
62
+ export function assertValidOperationSnapshot(value: unknown): asserts value is OperationSnapshot {
61
63
  assertPayloadFree(value);
62
64
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshot);
63
65
  protocol(object.protocolVersion, "$.protocolVersion");
64
66
  authority(object.authority, "$.authority");
65
67
  natural(object.catalogueRevision, "$.catalogueRevision");
66
68
  boolean(object.closed, "$.closed");
67
- const limits = exactObject(object.limits, "$.limits", OPERATION_FIELDS.OperationCatalogueLimitsProjection);
69
+ const limits = exactObject(
70
+ object.limits,
71
+ "$.limits",
72
+ OPERATION_FIELDS.OperationCatalogueLimitsProjection,
73
+ );
68
74
  natural(limits.maximumActiveOperations, "$.limits.maximumActiveOperations");
69
75
  natural(limits.maximumTerminalOperations, "$.limits.maximumTerminalOperations");
70
76
  natural(limits.maximumTerminalEncodedWeight, "$.limits.maximumTerminalEncodedWeight");
71
77
  natural(object.terminalEvictionCount, "$.terminalEvictionCount");
72
78
  natural(object.retainedTerminalEncodedWeight, "$.retainedTerminalEncodedWeight");
73
79
  array(object.active, "$.active").forEach((entry, index) =>
74
- operationEntry(entry, `$.active[${index}]`)
80
+ operationEntry(entry, `$.active[${index}]`),
75
81
  );
76
82
  array(object.recent, "$.recent").forEach((entry, index) =>
77
- operationEntry(entry, `$.recent[${index}]`)
83
+ operationEntry(entry, `$.recent[${index}]`),
78
84
  );
79
85
  }
80
86
 
@@ -85,25 +91,31 @@ export function assertValidOperationMutationCommand(
85
91
  const object = record(value, "$");
86
92
  member(object.kind, OPERATION_MUTATION_KINDS, "$.kind");
87
93
  protocol(object.protocolVersion, "$.protocolVersion");
88
- text(object.requestId, "$.requestId");
94
+ identifier(object.requestId, "$.requestId");
89
95
  authority(object.authority, "$.authority");
90
96
  switch (object.kind) {
91
97
  case "register":
92
98
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
93
99
  natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
94
- text(object.operationId, "$.operationId");
95
- text(object.kindId, "$.kindId");
96
- nullableText(object.scopeId, "$.scopeId");
100
+ identifier(object.operationId, "$.operationId");
101
+ identifier(object.kindId, "$.kindId");
102
+ nullableIdentifier(object.scopeId, "$.scopeId");
97
103
  text(object.label, "$.label");
98
104
  member(object.initialState, OPERATION_STATES, "$.initialState");
99
- member(object.cancellationSupport, ["supported", "unsupported"] as const, "$.cancellationSupport");
100
- nullableText(object.retryOf, "$.retryOf");
105
+ member(
106
+ object.cancellationSupport,
107
+ ["supported", "unsupported"] as const,
108
+ "$.cancellationSupport",
109
+ );
110
+ nullableIdentifier(object.retryOf, "$.retryOf");
101
111
  break;
102
112
  case "progress":
103
113
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
104
114
  operationTarget(object);
105
115
  progressOverall(object.overall, "$.overall");
106
- if (object.phase !== null) phase(object.phase, "$.phase");
116
+ if (object.phase !== null) {
117
+ phase(object.phase, "$.phase");
118
+ }
107
119
  break;
108
120
  case "transition":
109
121
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
@@ -113,10 +125,17 @@ export function assertValidOperationMutationCommand(
113
125
  case "changeRetention":
114
126
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
115
127
  natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
128
+ // oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
116
129
  assertValidOperationSnapshot({
117
- protocolVersion: 1, authority: object.authority, catalogueRevision: 0,
118
- closed: false, limits: object.limits, terminalEvictionCount: 0,
119
- retainedTerminalEncodedWeight: 0, active: [], recent: [],
130
+ protocolVersion: 1,
131
+ authority: object.authority,
132
+ catalogueRevision: 0,
133
+ closed: false,
134
+ limits: object.limits,
135
+ terminalEvictionCount: 0,
136
+ retainedTerminalEncodedWeight: 0,
137
+ active: [],
138
+ recent: [],
120
139
  });
121
140
  break;
122
141
  case "dismiss":
@@ -126,7 +145,9 @@ export function assertValidOperationMutationCommand(
126
145
  case "teardown":
127
146
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
128
147
  natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
129
- array(object.resolutions, "$.resolutions").forEach((resolution, index) => teardownResolution(resolution, `$.resolutions[${index}]`));
148
+ array(object.resolutions, "$.resolutions").forEach((resolution, index) =>
149
+ teardownResolution(resolution, `$.resolutions[${index}]`),
150
+ );
130
151
  break;
131
152
  }
132
153
  }
@@ -136,7 +157,7 @@ export function assertValidOperationCancellationCommand(
136
157
  ): asserts value is OperationCancellationCommand {
137
158
  assertPayloadFree(value);
138
159
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationCancellationCommand);
139
- text(object.requestId, "$.requestId");
160
+ identifier(object.requestId, "$.requestId");
140
161
  protocol(object.protocolVersion, "$.protocolVersion");
141
162
  authority(object.authority, "$.authority");
142
163
  operationTarget(object);
@@ -145,8 +166,7 @@ export function assertValidOperationCancellationCommand(
145
166
  export function assertValidOperationMutationResult(
146
167
  value: unknown,
147
168
  ): asserts value is OperationMutationResult {
148
- resultBase(value, OPERATION_MUTATION_STATUSES);
149
- const object = value as Record<string, unknown>;
169
+ const object = resultBase(value, OPERATION_MUTATION_STATUSES);
150
170
  if (object.status === "committed") {
151
171
  exactKeys(object, "$", variantKeys("OperationMutationResult", object, "$"));
152
172
  mutationReceipt(object.receipt, "$.receipt");
@@ -159,8 +179,7 @@ export function assertValidOperationMutationResult(
159
179
  export function assertValidOperationCancellationResult(
160
180
  value: unknown,
161
181
  ): asserts value is OperationCancellationResult {
162
- resultBase(value, OPERATION_CANCELLATION_STATUSES);
163
- const object = value as Record<string, unknown>;
182
+ const object = resultBase(value, OPERATION_CANCELLATION_STATUSES);
164
183
  if (object.status === "committed") {
165
184
  exactKeys(object, "$", variantKeys("OperationCancellationResult", object, "$"));
166
185
  cancellationReceipt(object.receipt, "$.receipt");
@@ -177,11 +196,11 @@ export function assertValidOperationChangedEvent(
177
196
  assertPayloadFree(value);
178
197
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationChangedEvent);
179
198
  protocol(object.protocolVersion, "$.protocolVersion");
180
- text(object.requestId, "$.requestId");
199
+ identifier(object.requestId, "$.requestId");
181
200
  authority(object.authority, "$.authority");
182
201
  natural(object.previousCatalogueRevision, "$.previousCatalogueRevision");
183
202
  natural(object.committedCatalogueRevision, "$.committedCatalogueRevision");
184
- nullableText(object.operationId, "$.operationId");
203
+ nullableIdentifier(object.operationId, "$.operationId");
185
204
  member(object.kind, OPERATION_CHANGED_KINDS, "$.kind");
186
205
  }
187
206
 
@@ -189,38 +208,51 @@ export function assertPayloadFree(value: unknown): void {
189
208
  visit(value, "$", new Set());
190
209
  }
191
210
 
192
- function resultBase(value: unknown, statuses: readonly string[]): void {
211
+ function resultBase(value: unknown, statuses: ReadonlyArray<string>): Record<string, unknown> {
193
212
  assertPayloadFree(value);
194
213
  const object = record(value, "$");
195
214
  member(object.status, statuses, "$.status");
196
- text(object.requestId, "$.requestId");
215
+ identifier(object.requestId, "$.requestId");
197
216
  assertValidOperationSnapshot(object.snapshot);
217
+ return object;
198
218
  }
199
219
 
200
220
  function operationEntry(value: unknown, path: string): asserts value is OperationEntryProjection {
201
221
  const object = exactObject(value, path, OPERATION_FIELDS.OperationEntryProjection);
202
222
  authority(object.authority, `${path}.authority`);
203
- text(object.operationId, `${path}.operationId`);
204
- text(object.kindId, `${path}.kindId`);
205
- nullableText(object.scopeId, `${path}.scopeId`);
223
+ identifier(object.operationId, `${path}.operationId`);
224
+ identifier(object.kindId, `${path}.kindId`);
225
+ nullableIdentifier(object.scopeId, `${path}.scopeId`);
206
226
  text(object.label, `${path}.label`);
207
- member(object.cancellationSupport, ["supported", "unsupported"] as const, `${path}.cancellationSupport`);
208
- nullableText(object.retryOf, `${path}.retryOf`);
227
+ member(
228
+ object.cancellationSupport,
229
+ ["supported", "unsupported"] as const,
230
+ `${path}.cancellationSupport`,
231
+ );
232
+ nullableIdentifier(object.retryOf, `${path}.retryOf`);
209
233
  natural(object.sequence, `${path}.sequence`);
210
234
  natural(object.revision, `${path}.revision`);
211
235
  natural(object.lastChangedCatalogueRevision, `${path}.lastChangedCatalogueRevision`);
212
236
  member(object.state, OPERATION_STATES, `${path}.state`);
213
- const progress = exactObject(object.progress, `${path}.progress`, OPERATION_FIELDS.OperationProgressProjection);
237
+ const progress = exactObject(
238
+ object.progress,
239
+ `${path}.progress`,
240
+ OPERATION_FIELDS.OperationProgressProjection,
241
+ );
214
242
  natural(progress.sequence, `${path}.progress.sequence`);
215
243
  progressOverall(progress.overall, `${path}.progress.overall`);
216
- if (progress.phase !== null) phase(progress.phase, `${path}.progress.phase`);
244
+ if (progress.phase !== null) {
245
+ phase(progress.phase, `${path}.progress.phase`);
246
+ }
217
247
  natural(object.encodedMetadataWeight, `${path}.encodedMetadataWeight`);
218
248
  }
219
249
 
220
250
  function progressOverall(value: unknown, path: string): void {
221
251
  const object = record(value, path);
222
252
  member(object.kind, OPERATION_PROGRESS_KINDS, `${path}.kind`);
223
- if (object.kind === "indeterminate") exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
253
+ if (object.kind === "indeterminate") {
254
+ exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
255
+ }
224
256
  if (object.kind === "units") {
225
257
  exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
226
258
  finite(object.completed, `${path}.completed`);
@@ -234,7 +266,7 @@ function progressOverall(value: unknown, path: string): void {
234
266
 
235
267
  function phase(value: unknown, path: string): void {
236
268
  const object = exactObject(value, path, OPERATION_FIELDS.OperationPhaseProgressProjection);
237
- text(object.phaseId, `${path}.phaseId`);
269
+ identifier(object.phaseId, `${path}.phaseId`);
238
270
  text(object.label, `${path}.label`);
239
271
  finite(object.completed, `${path}.completed`);
240
272
  finite(object.total, `${path}.total`);
@@ -250,7 +282,7 @@ function teardownResolution(value: unknown, path: string): void {
250
282
  exactKeys(object, path, variantKeys("OperationTeardownResolutionProjection", object, path));
251
283
  authority(object.targetAuthority, `${path}.targetAuthority`);
252
284
  }
253
- text(object.operationId, `${path}.operationId`);
285
+ identifier(object.operationId, `${path}.operationId`);
254
286
  natural(object.expectedOperationRevision, `${path}.expectedOperationRevision`);
255
287
  }
256
288
 
@@ -270,16 +302,23 @@ function mutationReceipt(value: unknown, path: string): void {
270
302
  operationEntry(object.operation, `${path}.operation`);
271
303
  catalogueRevisionPair(object, path);
272
304
  break;
273
- case "progressed":
305
+ case "progressed": {
274
306
  exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
275
307
  operationRevisionPair(object, path);
276
308
  natural(object.previousProgressSequence, `${path}.previousProgressSequence`);
277
- const progress = exactObject(object.committedProgress, `${path}.committedProgress`, OPERATION_FIELDS.OperationProgressProjection);
309
+ const progress = exactObject(
310
+ object.committedProgress,
311
+ `${path}.committedProgress`,
312
+ OPERATION_FIELDS.OperationProgressProjection,
313
+ );
278
314
  natural(progress.sequence, `${path}.committedProgress.sequence`);
279
315
  progressOverall(progress.overall, `${path}.committedProgress.overall`);
280
- if (progress.phase !== null) phase(progress.phase, `${path}.committedProgress.phase`);
316
+ if (progress.phase !== null) {
317
+ phase(progress.phase, `${path}.committedProgress.phase`);
318
+ }
281
319
  catalogueRevisionPair(object, path);
282
320
  break;
321
+ }
283
322
  case "transitioned":
284
323
  exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
285
324
  member(object.previousState, OPERATION_STATES, `${path}.previousState`);
@@ -304,7 +343,9 @@ function mutationReceipt(value: unknown, path: string): void {
304
343
  case "tornDown":
305
344
  exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
306
345
  catalogueRevisionPair(object, path);
307
- array(object.outcomes, `${path}.outcomes`).forEach((outcome, index) => teardownOutcome(outcome, `${path}.outcomes[${index}]`));
346
+ array(object.outcomes, `${path}.outcomes`).forEach((outcome, index) =>
347
+ teardownOutcome(outcome, `${path}.outcomes[${index}]`),
348
+ );
308
349
  removals(object.evicted, `${path}.evicted`);
309
350
  break;
310
351
  }
@@ -312,7 +353,7 @@ function mutationReceipt(value: unknown, path: string): void {
312
353
 
313
354
  function cancellationReceipt(value: unknown, path: string): void {
314
355
  const object = exactObject(value, path, OPERATION_FIELDS.OperationCancellationReceiptProjection);
315
- text(object.operationId, `${path}.operationId`);
356
+ identifier(object.operationId, `${path}.operationId`);
316
357
  member(object.outcome, OPERATION_CANCELLATION_OUTCOMES, `${path}.outcome`);
317
358
  member(object.previousState, OPERATION_STATES, `${path}.previousState`);
318
359
  member(object.committedState, OPERATION_STATES, `${path}.committedState`);
@@ -336,7 +377,7 @@ function executorDispatch(value: unknown, path: string): void {
336
377
 
337
378
  function removal(value: unknown, path: string): void {
338
379
  const object = exactObject(value, path, OPERATION_FIELDS.OperationRemovalProjection);
339
- text(object.operationId, `${path}.operationId`);
380
+ identifier(object.operationId, `${path}.operationId`);
340
381
  natural(object.sequence, `${path}.sequence`);
341
382
  natural(object.encodedWeight, `${path}.encodedWeight`);
342
383
  member(object.reason, ["evicted", "dismissed"] as const, `${path}.reason`);
@@ -356,9 +397,11 @@ function teardownOutcome(value: unknown, path: string): void {
356
397
  exactKeys(object, path, variantKeys("OperationTeardownOutcomeProjection", object, path));
357
398
  authority(object.targetAuthority, `${path}.targetAuthority`);
358
399
  }
359
- text(object.operationId, `${path}.operationId`);
400
+ identifier(object.operationId, `${path}.operationId`);
360
401
  natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
361
- if (object.kind === "completed") natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
402
+ if (object.kind === "completed") {
403
+ natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
404
+ }
362
405
  }
363
406
 
364
407
  function limits(value: unknown, path: string): void {
@@ -369,7 +412,7 @@ function limits(value: unknown, path: string): void {
369
412
  }
370
413
 
371
414
  function operationRevisionPair(object: Record<string, unknown>, path: string): void {
372
- text(object.operationId, `${path}.operationId`);
415
+ identifier(object.operationId, `${path}.operationId`);
373
416
  natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
374
417
  natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
375
418
  }
@@ -380,79 +423,122 @@ function catalogueRevisionPair(object: Record<string, unknown>, path: string): v
380
423
  }
381
424
 
382
425
  function operationTarget(object: Record<string, unknown>): void {
383
- text(object.operationId, "$.operationId");
426
+ identifier(object.operationId, "$.operationId");
384
427
  natural(object.expectedOperationRevision, "$.expectedOperationRevision");
385
428
  }
386
429
 
387
430
  function authority(value: unknown, path: string): void {
388
431
  const object = exactObject(value, path, OPERATION_FIELDS.OperationAuthorityProjection);
389
- text(object.authorityId, `${path}.authorityId`);
432
+ identifier(object.authorityId, `${path}.authorityId`);
390
433
  natural(object.authorityEpoch, `${path}.authorityEpoch`);
391
- if (object.authorityEpoch === 0) fail(`${path}.authorityEpoch`, "must be nonzero");
434
+ if (object.authorityEpoch === 0) {
435
+ fail(`${path}.authorityEpoch`, "must be nonzero");
436
+ }
392
437
  }
393
438
 
394
439
  function protocol(value: unknown, path: string): void {
395
440
  natural(value, path);
396
- if (value !== OPERATION_PROTOCOL_VERSION) fail(path, `expected ${OPERATION_PROTOCOL_VERSION}`);
441
+ if (value !== OPERATION_PROTOCOL_VERSION) {
442
+ fail(path, `expected ${OPERATION_PROTOCOL_VERSION}`);
443
+ }
397
444
  }
398
445
 
399
- function exactObject(value: unknown, path: string, keys: readonly string[]): Record<string, unknown> {
446
+ function exactObject(
447
+ value: unknown,
448
+ path: string,
449
+ keys: ReadonlyArray<string>,
450
+ ): Record<string, unknown> {
400
451
  const object = record(value, path);
401
452
  exactKeys(object, path, keys);
402
453
  return object;
403
454
  }
404
455
 
405
- function exactKeys(object: Record<string, unknown>, path: string, keys: readonly string[]): void {
406
- const actual = Object.keys(object).sort();
407
- const expected = [...keys].sort();
408
- if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
409
- fail(path, `expected keys ${expected.join(",")}; received ${actual.join(",")}`);
410
- }
456
+ function exactKeys(
457
+ object: Record<string, unknown>,
458
+ path: string,
459
+ keys: ReadonlyArray<string>,
460
+ ): void {
461
+ checkWireFields(object, keys, () =>
462
+ fail(
463
+ path,
464
+ `expected keys ${[...keys].sort().join(",")}; received ${Object.keys(object).sort().join(",")}`,
465
+ ),
466
+ );
411
467
  }
412
468
 
413
469
  function record(value: unknown, path: string): Record<string, unknown> {
414
- if (typeof value !== "object" || value === null || Array.isArray(value)) fail(path, "expected object");
415
- return value as Record<string, unknown>;
470
+ const result = readWireRecord(value, () => fail(path, "expected object"));
471
+ return result;
416
472
  }
417
473
 
418
- function array(value: unknown, path: string): unknown[] {
419
- if (!Array.isArray(value)) fail(path, "expected array");
474
+ function array(value: unknown, path: string): Array<unknown> {
475
+ if (!Array.isArray(value)) {
476
+ fail(path, "expected array");
477
+ }
420
478
  return value;
421
479
  }
422
480
 
423
481
  function text(value: unknown, path: string): asserts value is string {
424
- if (typeof value !== "string" || value.length === 0) fail(path, "expected non-empty string");
482
+ if (typeof value !== "string" || value.length === 0) {
483
+ fail(path, "expected non-empty string");
484
+ }
425
485
  }
426
486
 
427
- function nullableText(value: unknown, path: string): void {
428
- if (value !== null) text(value, path);
487
+ function identifier(value: unknown, path: string): asserts value is string {
488
+ if (!isOpaqueId(value)) {
489
+ fail(path, "expected bounded lowercase opaque id");
490
+ }
491
+ }
492
+
493
+ function nullableIdentifier(value: unknown, path: string): void {
494
+ if (value !== null) {
495
+ identifier(value, path);
496
+ }
429
497
  }
430
498
 
431
499
  function natural(value: unknown, path: string): asserts value is number {
432
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected non-negative safe integer");
500
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
501
+ fail(path, "expected non-negative safe integer");
502
+ }
433
503
  }
434
504
 
435
505
  function finite(value: unknown, path: string): asserts value is number {
436
- if (typeof value !== "number" || !Number.isFinite(value)) fail(path, "expected finite number");
506
+ if (typeof value !== "number" || !Number.isFinite(value)) {
507
+ fail(path, "expected finite number");
508
+ }
437
509
  }
438
510
 
439
511
  function boolean(value: unknown, path: string): asserts value is boolean {
440
- if (typeof value !== "boolean") fail(path, "expected boolean");
512
+ if (typeof value !== "boolean") {
513
+ fail(path, "expected boolean");
514
+ }
441
515
  }
442
516
 
443
- function member(value: unknown, values: readonly string[], path: string): asserts value is string {
444
- if (typeof value !== "string" || !values.includes(value)) fail(path, `expected one of ${values.join(",")}`);
517
+ function member(
518
+ value: unknown,
519
+ values: ReadonlyArray<string>,
520
+ path: string,
521
+ ): asserts value is string {
522
+ if (typeof value !== "string" || !values.includes(value)) {
523
+ fail(path, `expected one of ${values.join(",")}`);
524
+ }
445
525
  }
446
526
 
447
527
  function visit(value: unknown, path: string, seen: Set<object>): void {
448
- if (typeof value !== "object" || value === null) return;
449
- if (seen.has(value)) fail(path, "cyclic value");
528
+ if (typeof value !== "object" || value === null) {
529
+ return;
530
+ }
531
+ if (seen.has(value)) {
532
+ fail(path, "cyclic value");
533
+ }
450
534
  seen.add(value);
451
535
  if (Array.isArray(value)) {
452
536
  value.forEach((entry, index) => visit(entry, `${path}[${index}]`, seen));
453
537
  } else {
454
538
  for (const [key, entry] of Object.entries(value)) {
455
- if (FORBIDDEN_PAYLOAD_KEYS.has(key)) fail(`${path}.${key}`, "product payload field is forbidden");
539
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) {
540
+ fail(`${path}.${key}`, "product payload field is forbidden");
541
+ }
456
542
  visit(entry, `${path}.${key}`, seen);
457
543
  }
458
544
  }
@@ -463,17 +549,16 @@ function fail(path: string, message: string): never {
463
549
  throw new OperationProtocolValidationError(path, message);
464
550
  }
465
551
 
466
- /**
467
- * Allowed keys for one variant, from the generated map.
468
- *
469
- * A missing entry means the generator failed to read the union, not that a
470
- * caller sent something odd: every switch below runs `member()` over the
471
- * discriminant first. Failing loudly beats a hand-written list, which is what
472
- * these were and what drifted in `history-tree`.
473
- */
474
- function variantKeys(type: string, object: Record<string, unknown>, path: string): readonly string[] {
475
- const discriminant = object[OPERATION_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
476
- const keys = OPERATION_VARIANT_FIELDS[type]?.[discriminant as string];
477
- if (keys === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
478
- return keys;
552
+ function variantKeys(
553
+ type: string,
554
+ object: Record<string, unknown>,
555
+ path: string,
556
+ ): ReadonlyArray<string> {
557
+ return wireVariantFields(
558
+ OPERATION_VARIANT_FIELDS,
559
+ OPERATION_VARIANT_FIELDS_DISCRIMINANTS,
560
+ type,
561
+ object,
562
+ (discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
563
+ );
479
564
  }
@@ -1,7 +1,4 @@
1
- import type {
2
- ConnectionFailureReporter,
3
- EventTransport,
4
- } from "@inflatable-cookie/longhorn/core";
1
+ import type { ConnectionFailureReporter, EventTransport } from "@inflatable-cookie/longhorn/core";
5
2
 
6
3
  import type {
7
4
  SettingsApplyCommand,
@@ -24,9 +21,8 @@ import {
24
21
  connectSettingsRegistry,
25
22
  connectSettingsScope,
26
23
  SettingsAuthorityConsistencyError,
27
- type SettingsScopeConnectionOptions,
28
- type SettingsSubscription,
29
24
  } from "./connection.ts";
25
+ import type { SettingsScopeConnectionOptions, SettingsSubscription } from "./connection.ts";
30
26
  import {
31
27
  SETTINGS_APPLY_COMMAND,
32
28
  SETTINGS_LOAD_COMMAND,
@@ -42,10 +38,7 @@ export class SettingsClient {
42
38
  }
43
39
 
44
40
  async registry(): Promise<SettingsRegistrySnapshot> {
45
- const value = await this.#transport.invoke(
46
- SETTINGS_REGISTRY_COMMAND,
47
- {},
48
- );
41
+ const value = await this.#transport.invoke(SETTINGS_REGISTRY_COMMAND, {});
49
42
  assertValidSettingsRegistrySnapshot(value);
50
43
  return value;
51
44
  }
@@ -59,10 +52,7 @@ export class SettingsClient {
59
52
  const value = await this.#transport.invoke(SETTINGS_LOAD_COMMAND, {
60
53
  command,
61
54
  });
62
- assertValidSettingsLoadOutcome(
63
- value,
64
- registry.limits.maximumOpaqueValueBytes,
65
- );
55
+ assertValidSettingsLoadOutcome(value, registry.limits.maximumOpaqueValueBytes);
66
56
  return value;
67
57
  }
68
58
 
@@ -70,21 +60,12 @@ export class SettingsClient {
70
60
  registry: SettingsRegistrySnapshot,
71
61
  command: SettingsApplyCommand,
72
62
  ): Promise<SettingsMutationResult> {
73
- assertValidSettingsApplyCommand(
74
- command,
75
- registry.limits.maximumOpaqueValueBytes,
76
- );
77
- assertRegistryGeneration(
78
- registry,
79
- command.authority.registryGeneration,
80
- );
63
+ assertValidSettingsApplyCommand(command, registry.limits.maximumOpaqueValueBytes);
64
+ assertRegistryGeneration(registry, command.authority.registryGeneration);
81
65
  const value = await this.#transport.invoke(SETTINGS_APPLY_COMMAND, {
82
66
  command,
83
67
  });
84
- assertValidSettingsMutationResult(
85
- value,
86
- registry.limits.maximumOpaqueValueBytes,
87
- );
68
+ assertValidSettingsMutationResult(value, registry.limits.maximumOpaqueValueBytes);
88
69
  return value;
89
70
  }
90
71
 
@@ -93,17 +74,11 @@ export class SettingsClient {
93
74
  command: SettingsResetCommand,
94
75
  ): Promise<SettingsMutationResult> {
95
76
  assertValidSettingsResetCommand(command);
96
- assertRegistryGeneration(
97
- registry,
98
- command.authority.registryGeneration,
99
- );
77
+ assertRegistryGeneration(registry, command.authority.registryGeneration);
100
78
  const value = await this.#transport.invoke(SETTINGS_RESET_COMMAND, {
101
79
  command,
102
80
  });
103
- assertValidSettingsMutationResult(
104
- value,
105
- registry.limits.maximumOpaqueValueBytes,
106
- );
81
+ assertValidSettingsMutationResult(value, registry.limits.maximumOpaqueValueBytes);
107
82
  return value;
108
83
  }
109
84
 
@@ -111,12 +86,7 @@ export class SettingsClient {
111
86
  listener?: (snapshot: SettingsRegistrySnapshot) => void,
112
87
  onFailure?: ConnectionFailureReporter,
113
88
  ): SettingsSubscription<SettingsRegistrySnapshot> {
114
- return connectSettingsRegistry(
115
- this.#transport,
116
- () => this.registry(),
117
- listener,
118
- onFailure,
119
- );
89
+ return connectSettingsRegistry(this.#transport, () => this.registry(), listener, onFailure);
120
90
  }
121
91
 
122
92
  connectScope(
@@ -130,10 +100,7 @@ export class SettingsClient {
130
100
  }
131
101
  }
132
102
 
133
- function assertRegistryGeneration(
134
- registry: SettingsRegistrySnapshot,
135
- generation: number,
136
- ): void {
103
+ function assertRegistryGeneration(registry: SettingsRegistrySnapshot, generation: number): void {
137
104
  if (generation !== registry.generation) {
138
105
  throw new SettingsAuthorityConsistencyError(
139
106
  "settings command registry generation does not match its registry",