@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,4 +1,4 @@
1
- // @generated by `effigy generate:update`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per tagged-union variant, from the Rust enums.
3
3
  // Keyed by type, then by discriminant. The discriminant itself is in
4
4
  // each list, because `exact()` compares every key.
@@ -12,7 +12,9 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
12
12
  "installFailed": ["cause", "detail"],
13
13
  },
14
14
  "UpdateAvailabilityProjection": {
15
+ "notChecked": ["state"],
15
16
  "offer": ["state", "version", "reason", "notes"],
17
+ "unavailableForTarget": ["state", "version"],
16
18
  "upToDate": ["state"],
17
19
  "aheadOfChannel": ["state", "installed", "channel"],
18
20
  "withheldByRollout": ["state", "version"],
@@ -31,7 +33,7 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
31
33
  },
32
34
  "UpdateOutcomeProjection": {
33
35
  "committed": ["status", "snapshot"],
34
- "rejected": ["status", "code", "snapshot"],
36
+ "rejected": ["status", "code", "detail", "snapshot"],
35
37
  },
36
38
  };
37
39
 
@@ -1,3 +1,5 @@
1
+ import type { ConnectionFailureReporter } from "../core/connection.ts";
2
+ import type { Unlisten } from "../core/transport.ts";
1
3
  import type {
2
4
  UpdateApplyCommand,
3
5
  UpdateCancelCommand,
@@ -6,12 +8,11 @@ import type {
6
8
  UpdateDeferCommand,
7
9
  UpdateOutcomeProjection,
8
10
  UpdatePrepareCommand,
9
- UpdateProgressEvent,
10
11
  UpdateSelectChannelCommand,
11
12
  UpdateSnapshot,
12
13
  } from "./generated/protocol.ts";
13
14
 
14
- export type UpdateUnlisten = () => void | Promise<void>;
15
+ export type UpdateUnlisten = Unlisten;
15
16
 
16
17
  /**
17
18
  * The raw seam.
@@ -25,10 +26,15 @@ export interface UpdatePort {
25
26
  selectChannel(command: UpdateSelectChannelCommand): Promise<unknown>;
26
27
  defer(command: UpdateDeferCommand): Promise<unknown>;
27
28
  prepare(command: UpdatePrepareCommand): Promise<unknown>;
29
+ /** Reports from this prepare invocation only. */
30
+ prepareWithProgress?:
31
+ | ((command: UpdatePrepareCommand, listener: (event: unknown) => void) => Promise<unknown>)
32
+ | undefined;
28
33
  apply(command: UpdateApplyCommand): Promise<unknown>;
29
34
  cancel(command: UpdateCancelCommand): Promise<unknown>;
30
- listen?(listener: (event: unknown) => void): UpdateUnlisten | Promise<UpdateUnlisten>;
31
- listenProgress?(listener: (event: unknown) => void): UpdateUnlisten | Promise<UpdateUnlisten>;
35
+ listen?:
36
+ | ((listener: (event: unknown) => void) => UpdateUnlisten | Promise<UpdateUnlisten>)
37
+ | undefined;
32
38
  }
33
39
 
34
40
  /** The same seam after validation. */
@@ -40,6 +46,8 @@ export interface CheckedUpdatePort {
40
46
  prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection>;
41
47
  apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection>;
42
48
  cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection>;
43
- listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten>;
44
- listenProgress(listener: (event: UpdateProgressEvent) => void): Promise<UpdateUnlisten>;
49
+ listen(
50
+ listener: (event: UpdateChangedEvent) => void,
51
+ onFailure?: ConnectionFailureReporter,
52
+ ): Promise<UpdateUnlisten>;
45
53
  }
@@ -1,3 +1,4 @@
1
+ import { wireCopy } from "../core/wire-copy.ts";
1
2
  import type {
2
3
  UpdateApplyCommand,
3
4
  UpdateCancelCommand,
@@ -9,14 +10,39 @@ import type {
9
10
  import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
10
11
  export class SerializedUpdatePort implements UpdatePort {
11
12
  constructor(readonly inner: UpdatePort) {}
12
- async snapshot(): Promise<unknown> { return clone(await this.inner.snapshot()); }
13
- async check(command: UpdateCheckCommand): Promise<unknown> { return clone(await this.inner.check(clone(command))); }
14
- async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> { return clone(await this.inner.selectChannel(clone(command))); }
15
- async defer(command: UpdateDeferCommand): Promise<unknown> { return clone(await this.inner.defer(clone(command))); }
16
- async prepare(command: UpdatePrepareCommand): Promise<unknown> { return clone(await this.inner.prepare(clone(command))); }
17
- async apply(command: UpdateApplyCommand): Promise<unknown> { return clone(await this.inner.apply(clone(command))); }
18
- async cancel(command: UpdateCancelCommand): Promise<unknown> { return clone(await this.inner.cancel(clone(command))); }
19
- async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listen === undefined) return () => {}; return this.inner.listen((event) => listener(clone(event))); }
20
- async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listenProgress === undefined) return () => {}; return this.inner.listenProgress((event) => listener(clone(event))); }
13
+ async snapshot(): Promise<unknown> {
14
+ return wireCopy(await this.inner.snapshot());
15
+ }
16
+ async check(command: UpdateCheckCommand): Promise<unknown> {
17
+ return wireCopy(await this.inner.check(wireCopy(command)));
18
+ }
19
+ async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> {
20
+ return wireCopy(await this.inner.selectChannel(wireCopy(command)));
21
+ }
22
+ async defer(command: UpdateDeferCommand): Promise<unknown> {
23
+ return wireCopy(await this.inner.defer(wireCopy(command)));
24
+ }
25
+ async prepare(command: UpdatePrepareCommand): Promise<unknown> {
26
+ return wireCopy(await this.inner.prepare(wireCopy(command)));
27
+ }
28
+ get prepareWithProgress(): UpdatePort["prepareWithProgress"] {
29
+ const prepare = this.inner.prepareWithProgress?.bind(this.inner);
30
+ if (prepare === undefined) {
31
+ return undefined;
32
+ }
33
+ return async (command, listener) =>
34
+ wireCopy(await prepare(wireCopy(command), (event) => listener(wireCopy(event))));
35
+ }
36
+ async apply(command: UpdateApplyCommand): Promise<unknown> {
37
+ return wireCopy(await this.inner.apply(wireCopy(command)));
38
+ }
39
+ async cancel(command: UpdateCancelCommand): Promise<unknown> {
40
+ return wireCopy(await this.inner.cancel(wireCopy(command)));
41
+ }
42
+ async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
43
+ if (this.inner.listen === undefined) {
44
+ return () => {};
45
+ }
46
+ return this.inner.listen((event) => listener(wireCopy(event)));
47
+ }
21
48
  }
22
- function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
@@ -1,3 +1,4 @@
1
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
1
2
  import { UPDATE_FIELDS } from "./generated/fields.ts";
2
3
  import {
3
4
  UPDATE_AVAILABILITY_STATES,
@@ -11,17 +12,19 @@ import {
11
12
  UPDATE_PROGRESS_STATES,
12
13
  UPDATE_PROTOCOL_VERSION,
13
14
  UPDATE_REJECTION_CODES,
14
- type UpdateApplyCommand,
15
- type UpdateCancelCommand,
16
- type UpdateChangedEvent,
17
- type UpdateCheckCommand,
18
- type UpdateDeferCommand,
19
- type UpdateInstallAuthorizationProjection,
20
- type UpdateOutcomeProjection,
21
- type UpdatePrepareCommand,
22
- type UpdateProgressEvent,
23
- type UpdateSelectChannelCommand,
24
- type UpdateSnapshot,
15
+ } from "./generated/protocol.ts";
16
+ import type {
17
+ UpdateApplyCommand,
18
+ UpdateCancelCommand,
19
+ UpdateChangedEvent,
20
+ UpdateCheckCommand,
21
+ UpdateDeferCommand,
22
+ UpdateInstallAuthorizationProjection,
23
+ UpdateOutcomeProjection,
24
+ UpdatePrepareCommand,
25
+ UpdateProgressEvent,
26
+ UpdateSelectChannelCommand,
27
+ UpdateSnapshot,
25
28
  } from "./generated/protocol.ts";
26
29
  import {
27
30
  UPDATE_VARIANT_FIELDS,
@@ -68,7 +71,10 @@ export function assertUpdateOutcome(value: unknown): asserts value is UpdateOutc
68
71
  const root = object(value, "$");
69
72
  oneOf(root.status, "$.status", UPDATE_OUTCOME_STATUSES);
70
73
  exact(root, "$", variantFields("UpdateOutcomeProjection", root, "$"));
71
- if (root.status === "rejected") oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
74
+ if (root.status === "rejected") {
75
+ oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
76
+ optionalString(root.detail, "$.detail");
77
+ }
72
78
  assertUpdateSnapshot(root.snapshot);
73
79
  }
74
80
 
@@ -106,7 +112,9 @@ export function assertUpdatePrepareCommand(value: unknown): asserts value is Upd
106
112
 
107
113
  export function assertUpdateApplyCommand(value: unknown): asserts value is UpdateApplyCommand {
108
114
  commandBase(value, UPDATE_FIELDS.UpdateApplyCommand);
109
- version(object(value, "$").version, "$.version");
115
+ const root = object(value, "$");
116
+ version(root.version, "$.version");
117
+ digest(root.digest, "$.digest");
110
118
  }
111
119
 
112
120
  export function assertUpdateCancelCommand(value: unknown): asserts value is UpdateCancelCommand {
@@ -138,7 +146,9 @@ export function assertUpdateInstallAuthorization(
138
146
  const root = object(value, "$");
139
147
  oneOf(root.status, "$.status", UPDATE_INSTALL_AUTHORIZATION_STATUSES);
140
148
  exact(root, "$", variantFields("UpdateInstallAuthorizationProjection", root, "$"));
141
- if (root.status === "deferred") cause(root.cause, "$.cause");
149
+ if (root.status === "deferred") {
150
+ cause(root.cause, "$.cause");
151
+ }
142
152
  }
143
153
 
144
154
  function availability(value: unknown, path: string): void {
@@ -150,15 +160,17 @@ function availability(value: unknown, path: string): void {
150
160
  oneOf(root.reason, `${path}.reason`, UPDATE_OFFER_REASONS);
151
161
  optionalString(root.notes, `${path}.notes`);
152
162
  }
153
- // Ahead-of-channel is the one state whose fields a surface must be able to
154
- // read to say anything useful: "you are on 1.3.0-nightly.4 and production
155
- // publishes 1.2.9" is the whole message, and Card 154 calls it the single
156
- // most likely support question the feature generates.
163
+ // The surface needs both versions to explain why the channel has no offer.
157
164
  if (root.state === "aheadOfChannel") {
158
165
  version(root.installed, `${path}.installed`);
159
166
  version(root.channel, `${path}.channel`);
160
167
  }
161
- if (root.state === "withheldByRollout") version(root.version, `${path}.version`);
168
+ if (root.state === "unavailableForTarget") {
169
+ version(root.version, `${path}.version`);
170
+ }
171
+ if (root.state === "withheldByRollout") {
172
+ version(root.version, `${path}.version`);
173
+ }
162
174
  if (root.state === "managedElsewhere") {
163
175
  version(root.version, `${path}.version`);
164
176
  oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
@@ -194,7 +206,7 @@ function cause(value: unknown, path: string): void {
194
206
  }
195
207
  }
196
208
 
197
- function commandBase(value: unknown, expected: readonly string[]): void {
209
+ function commandBase(value: unknown, expected: ReadonlyArray<string>): void {
198
210
  noPayload(value);
199
211
  const root = object(value, "$");
200
212
  exact(root, "$", expected);
@@ -202,46 +214,104 @@ function commandBase(value: unknown, expected: readonly string[]): void {
202
214
  positive(root.authorityEpoch, "$.authorityEpoch");
203
215
  }
204
216
 
205
- /**
206
- * Allowed keys for one variant, from the generated map.
207
- *
208
- * A missing entry means the generator failed to read the union, not that a
209
- * consumer sent something odd — every caller runs `oneOf` over the
210
- * discriminant first, so an unknown one is already rejected by then.
211
- */
212
217
  function variantFields(
213
218
  type: string,
214
219
  value: Record<string, unknown>,
215
220
  path: string,
216
- ): readonly string[] {
217
- const discriminant = value[UPDATE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
218
- const fields = UPDATE_VARIANT_FIELDS[type]?.[discriminant as string];
219
- if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
220
- return fields;
221
+ ): ReadonlyArray<string> {
222
+ return wireVariantFields(
223
+ UPDATE_VARIANT_FIELDS,
224
+ UPDATE_VARIANT_FIELDS_DISCRIMINANTS,
225
+ type,
226
+ value,
227
+ (discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
228
+ );
221
229
  }
222
230
 
223
231
  function noPayload(value: unknown): void {
224
232
  const visit = (candidate: unknown, path: string): void => {
225
- if (Array.isArray(candidate)) return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
226
- if (candidate !== null && typeof candidate === "object")
233
+ if (Array.isArray(candidate)) {
234
+ return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
235
+ }
236
+ if (candidate !== null && typeof candidate === "object") {
227
237
  for (const [key, child] of Object.entries(candidate)) {
228
- if (key.toLocaleLowerCase().includes("payload")) fail(`${path}.${key}`, "product payload field is forbidden");
238
+ if (key.toLocaleLowerCase().includes("payload")) {
239
+ fail(`${path}.${key}`, "product payload field is forbidden");
240
+ }
229
241
  visit(child, `${path}.${key}`);
230
242
  }
243
+ }
231
244
  };
232
245
  visit(value, "$");
233
246
  }
234
- function object(value: unknown, path: string): Record<string, unknown> { if (value === null || typeof value !== "object" || Array.isArray(value)) fail(path, "expected object"); return value as Record<string, unknown>; }
235
- function exact(value: Record<string, unknown>, path: string, expected: readonly string[]): void { const actual = Object.keys(value).sort(); const wanted = [...expected].sort(); if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) fail(path, `unexpected keys: ${actual.join(",")}`); }
236
- function protocol(value: unknown, path: string): void { if (value !== UPDATE_PROTOCOL_VERSION) fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`); }
237
- function positive(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail(path, "expected positive safe integer"); }
238
- function count(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected a non-negative safe byte count"); }
239
- function optionalCount(value: unknown, path: string): void { if (value !== null) count(value, path); }
240
- function digest(value: unknown, path: string): void { if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) fail(path, "expected 64 lowercase hex digits"); }
241
- function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
242
- function optionalString(value: unknown, path: string): void { if (value !== null) string(value, path); }
247
+ function object(value: unknown, path: string): Record<string, unknown> {
248
+ const result = readWireRecord(value, () => fail(path, "expected object"));
249
+ return result;
250
+ }
251
+ function exact(
252
+ value: Record<string, unknown>,
253
+ path: string,
254
+ expected: ReadonlyArray<string>,
255
+ ): void {
256
+ checkWireFields(value, expected, () =>
257
+ fail(path, `unexpected keys: ${Object.keys(value).sort().join(",")}`),
258
+ );
259
+ }
260
+ function protocol(value: unknown, path: string): void {
261
+ if (value !== UPDATE_PROTOCOL_VERSION) {
262
+ fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`);
263
+ }
264
+ }
265
+ function positive(value: unknown, path: string): void {
266
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
267
+ fail(path, "expected positive safe integer");
268
+ }
269
+ }
270
+ function count(value: unknown, path: string): void {
271
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
272
+ fail(path, "expected a non-negative safe byte count");
273
+ }
274
+ }
275
+ function optionalCount(value: unknown, path: string): void {
276
+ if (value !== null) {
277
+ count(value, path);
278
+ }
279
+ }
280
+ function digest(value: unknown, path: string): void {
281
+ if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
282
+ fail(path, "expected 64 lowercase hex digits");
283
+ }
284
+ }
285
+ function string(value: unknown, path: string): asserts value is string {
286
+ if (typeof value !== "string") {
287
+ fail(path, "expected string");
288
+ }
289
+ }
290
+ function optionalString(value: unknown, path: string): void {
291
+ if (value !== null) {
292
+ string(value, path);
293
+ }
294
+ }
243
295
  /** Versions are strings on the wire, as `semver::Version` serialises them. */
244
- function version(value: unknown, path: string): void { string(value, path); if ((value as string).length === 0) fail(path, "expected non-empty version"); }
245
- function fraction(value: unknown, path: string): void { if (value === null) return; if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) fail(path, "expected a fraction between 0 and 1, or null"); }
246
- function oneOf(value: unknown, path: string, values: readonly string[]): void { if (typeof value !== "string" || !values.includes(value)) fail(path, "unsupported value"); }
247
- function fail(path: string, message: string): never { throw new UpdateValidationError(path, message); }
296
+ function version(value: unknown, path: string): void {
297
+ string(value, path);
298
+ if (value.length === 0) {
299
+ fail(path, "expected non-empty version");
300
+ }
301
+ }
302
+ function fraction(value: unknown, path: string): void {
303
+ if (value === null) {
304
+ return;
305
+ }
306
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
307
+ fail(path, "expected a fraction between 0 and 1, or null");
308
+ }
309
+ }
310
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
311
+ if (typeof value !== "string" || !values.includes(value)) {
312
+ fail(path, "unsupported value");
313
+ }
314
+ }
315
+ function fail(path: string, message: string): never {
316
+ throw new UpdateValidationError(path, message);
317
+ }