@inflatable-cookie/longhorn 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) 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/selection.ts +10 -8
  6. package/src/agent-control/shim.ts +149 -77
  7. package/src/bridge/generated/fields.ts +1 -1
  8. package/src/bridge/generated/protocol.ts +55 -4
  9. package/src/bridge/generated/variant-fields.ts +1 -1
  10. package/src/bridge/job.ts +49 -2
  11. package/src/bridge/runtime/connection.ts +11 -14
  12. package/src/bridge/stream/connection.ts +14 -23
  13. package/src/bridge/stream/tracker.ts +5 -0
  14. package/src/bridge/supervision.ts +102 -80
  15. package/src/bridge/validation/base.ts +7 -27
  16. package/src/bridge/validation/negotiation.ts +1 -6
  17. package/src/bridge/validation/operations.ts +2 -14
  18. package/src/commands/client.ts +16 -2
  19. package/src/commands/controller.ts +96 -58
  20. package/src/commands/generated/fields.ts +4 -4
  21. package/src/commands/generated/protocol.ts +24 -1
  22. package/src/commands/generated/variant-fields.ts +1 -1
  23. package/src/commands/keyboard.ts +4 -13
  24. package/src/commands/physical-code.ts +11 -0
  25. package/src/commands/ports.ts +2 -1
  26. package/src/commands/projectors.ts +52 -29
  27. package/src/commands/validation.ts +408 -188
  28. package/src/config/client.ts +3 -3
  29. package/src/config/generated/base.ts +22 -6
  30. package/src/config/generated/fields.ts +2 -1
  31. package/src/config/generated/label-template.ts +1 -1
  32. package/src/config/generated/labels.ts +1 -1
  33. package/src/config/generated/protocol.ts +1 -1
  34. package/src/config/generated/restore.ts +35 -12
  35. package/src/config/generated/variant-fields.ts +1 -1
  36. package/src/config/validation/commands.ts +11 -13
  37. package/src/config/validation/outcomes.ts +147 -46
  38. package/src/config/validation/primitives.ts +11 -39
  39. package/src/config/validation/projection.ts +44 -44
  40. package/src/core/connection.ts +124 -29
  41. package/src/core/controller-lifecycle.ts +144 -0
  42. package/src/core/generated/identifiers.ts +4 -0
  43. package/src/core/identifiers.ts +40 -0
  44. package/src/core/index.ts +10 -1
  45. package/src/core/json-value.ts +58 -0
  46. package/src/core/listeners.ts +35 -0
  47. package/src/core/record.ts +76 -0
  48. package/src/core/transport.ts +10 -1
  49. package/src/core/wire-copy.ts +1 -0
  50. package/src/history/client.ts +11 -7
  51. package/src/history/controller.ts +72 -74
  52. package/src/history/generated/fields.ts +2 -1
  53. package/src/history/generated/protocol.ts +8 -5
  54. package/src/history/generated/variant-fields.ts +1 -1
  55. package/src/history/ports.ts +7 -2
  56. package/src/history/validation.ts +15 -37
  57. package/src/history-tree/client.ts +15 -13
  58. package/src/history-tree/controller.ts +131 -90
  59. package/src/history-tree/generated/fields.ts +3 -1
  60. package/src/history-tree/generated/protocol.ts +43 -7
  61. package/src/history-tree/generated/variant-fields.ts +7 -1
  62. package/src/history-tree/ports.ts +9 -4
  63. package/src/history-tree/validation.ts +44 -35
  64. package/src/layout/generated/protocol.ts +2 -1
  65. package/src/layout/generated/variant-fields.ts +47 -0
  66. package/src/layout/index.ts +1 -1
  67. package/src/layout/ratio.ts +9 -2
  68. package/src/layout/validation.ts +88 -13
  69. package/src/licence/client.ts +11 -7
  70. package/src/licence/controller.ts +64 -43
  71. package/src/licence/generated/fields.ts +2 -1
  72. package/src/licence/generated/protocol.ts +8 -4
  73. package/src/licence/generated/variant-fields.ts +1 -1
  74. package/src/licence/key.ts +2 -6
  75. package/src/licence/ports.ts +7 -2
  76. package/src/licence/validation.ts +27 -20
  77. package/src/native-content/client.ts +32 -1
  78. package/src/native-content/generated/fields.ts +4 -4
  79. package/src/native-content/generated/protocol.ts +16 -5
  80. package/src/native-content/generated/variant-fields.ts +1 -1
  81. package/src/native-content/ports.ts +2 -1
  82. package/src/native-content/validation/base.ts +16 -46
  83. package/src/native-content/validation/messages.ts +3 -0
  84. package/src/notifications/client.ts +17 -39
  85. package/src/notifications/controller.ts +266 -165
  86. package/src/notifications/generated/fields.ts +2 -1
  87. package/src/notifications/generated/labels.ts +1 -1
  88. package/src/notifications/generated/protocol.ts +5 -1
  89. package/src/notifications/generated/variant-fields.ts +1 -1
  90. package/src/notifications/ports.ts +2 -1
  91. package/src/notifications/tone.ts +1 -1
  92. package/src/notifications/validation.ts +41 -51
  93. package/src/operation/bridge.ts +79 -19
  94. package/src/operation/client.ts +17 -45
  95. package/src/operation/controller.ts +38 -59
  96. package/src/operation/generated/fields.ts +2 -1
  97. package/src/operation/generated/labels.ts +1 -1
  98. package/src/operation/generated/protocol.ts +5 -1
  99. package/src/operation/generated/variant-fields.ts +1 -1
  100. package/src/operation/ports.ts +2 -1
  101. package/src/operation/validation.ts +48 -50
  102. package/src/settings/connection.ts +10 -14
  103. package/src/settings/generated/fields.ts +2 -1
  104. package/src/settings/generated/protocol.ts +5 -1
  105. package/src/settings/generated/variant-fields.ts +1 -1
  106. package/src/settings/validation/authority.ts +2 -2
  107. package/src/settings/validation/command.ts +5 -4
  108. package/src/settings/validation/primitives.ts +32 -67
  109. package/src/settings/validation/registry.ts +13 -11
  110. package/src/surface-transfer/generated/fields.ts +1 -1
  111. package/src/surface-transfer/generated/protocol.ts +3 -3
  112. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  113. package/src/surface-transfer/validation.ts +76 -53
  114. package/src/surfaces/client.ts +26 -38
  115. package/src/surfaces/generated/fields.ts +1 -1
  116. package/src/surfaces/generated/protocol.ts +1 -1
  117. package/src/surfaces/generated/variant-fields.ts +1 -1
  118. package/src/surfaces/validation.ts +198 -61
  119. package/src/transfer/connection.ts +25 -39
  120. package/src/transfer/generated/fields.ts +2 -1
  121. package/src/transfer/generated/protocol.ts +9 -1
  122. package/src/transfer/generated/variant-fields.ts +1 -1
  123. package/src/transfer/index.ts +8 -1
  124. package/src/transfer/payload.ts +12 -9
  125. package/src/transfer/validation.ts +146 -60
  126. package/src/update/client.ts +43 -16
  127. package/src/update/controller.ts +187 -104
  128. package/src/update/generated/fields.ts +2 -1
  129. package/src/update/generated/protocol.ts +19 -7
  130. package/src/update/generated/variant-fields.ts +3 -2
  131. package/src/update/ports.ts +11 -7
  132. package/src/update/serialized.ts +8 -6
  133. package/src/update/validation.ts +18 -28
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:operation`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority. Product payloads are intentionally absent.
3
3
 
4
4
  export const OPERATION_PROTOCOL_VERSION = 1 as const;
@@ -760,3 +760,7 @@ operationId: OperationId | null,
760
760
  * Change source.
761
761
  */
762
762
  kind: OperationChangedKind, };
763
+
764
+ export type OperationHostErrorCode = "authorityUnavailable" | "authorityStateUnavailable" | "executorStateUnavailable" | "eventPublication";
765
+
766
+ export type OperationHostError = { "code": OperationHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:operation`; 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.
@@ -1,3 +1,4 @@
1
+ import type { Unlisten } from "../core/transport.ts";
1
2
  import type {
2
3
  OperationCancellationCommand,
3
4
  OperationChangedEvent,
@@ -9,7 +10,7 @@ import type {
9
10
  OperationCancellationResult,
10
11
  } from "./generated/protocol.ts";
11
12
 
12
- export type OperationUnlisten = () => void | Promise<void>;
13
+ export type OperationUnlisten = Unlisten;
13
14
 
14
15
  export interface OperationPort {
15
16
  snapshot(query: OperationSnapshotQuery): Promise<unknown>;
@@ -1,4 +1,5 @@
1
- import { isRecord } from "../core/record.ts";
1
+ import { isOpaqueId } from "../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
2
3
  import { OPERATION_FIELDS } from "./generated/fields.ts";
3
4
  import {
4
5
  OPERATION_VARIANT_FIELDS,
@@ -46,7 +47,7 @@ export function assertValidOperationSnapshotQuery(
46
47
  ): asserts value is OperationSnapshotQuery {
47
48
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotQuery);
48
49
  protocol(object.protocolVersion, "$.protocolVersion");
49
- text(object.requestId, "$.requestId");
50
+ identifier(object.requestId, "$.requestId");
50
51
  }
51
52
 
52
53
  export function assertValidOperationSnapshotResponse(
@@ -54,7 +55,7 @@ export function assertValidOperationSnapshotResponse(
54
55
  ): asserts value is OperationSnapshotResponse {
55
56
  assertPayloadFree(value);
56
57
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotResponse);
57
- text(object.requestId, "$.requestId");
58
+ identifier(object.requestId, "$.requestId");
58
59
  assertValidOperationSnapshot(object.snapshot);
59
60
  }
60
61
 
@@ -90,15 +91,15 @@ export function assertValidOperationMutationCommand(
90
91
  const object = record(value, "$");
91
92
  member(object.kind, OPERATION_MUTATION_KINDS, "$.kind");
92
93
  protocol(object.protocolVersion, "$.protocolVersion");
93
- text(object.requestId, "$.requestId");
94
+ identifier(object.requestId, "$.requestId");
94
95
  authority(object.authority, "$.authority");
95
96
  switch (object.kind) {
96
97
  case "register":
97
98
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
98
99
  natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
99
- text(object.operationId, "$.operationId");
100
- text(object.kindId, "$.kindId");
101
- nullableText(object.scopeId, "$.scopeId");
100
+ identifier(object.operationId, "$.operationId");
101
+ identifier(object.kindId, "$.kindId");
102
+ nullableIdentifier(object.scopeId, "$.scopeId");
102
103
  text(object.label, "$.label");
103
104
  member(object.initialState, OPERATION_STATES, "$.initialState");
104
105
  member(
@@ -106,7 +107,7 @@ export function assertValidOperationMutationCommand(
106
107
  ["supported", "unsupported"] as const,
107
108
  "$.cancellationSupport",
108
109
  );
109
- nullableText(object.retryOf, "$.retryOf");
110
+ nullableIdentifier(object.retryOf, "$.retryOf");
110
111
  break;
111
112
  case "progress":
112
113
  exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
@@ -156,7 +157,7 @@ export function assertValidOperationCancellationCommand(
156
157
  ): asserts value is OperationCancellationCommand {
157
158
  assertPayloadFree(value);
158
159
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationCancellationCommand);
159
- text(object.requestId, "$.requestId");
160
+ identifier(object.requestId, "$.requestId");
160
161
  protocol(object.protocolVersion, "$.protocolVersion");
161
162
  authority(object.authority, "$.authority");
162
163
  operationTarget(object);
@@ -195,11 +196,11 @@ export function assertValidOperationChangedEvent(
195
196
  assertPayloadFree(value);
196
197
  const object = exactObject(value, "$", OPERATION_FIELDS.OperationChangedEvent);
197
198
  protocol(object.protocolVersion, "$.protocolVersion");
198
- text(object.requestId, "$.requestId");
199
+ identifier(object.requestId, "$.requestId");
199
200
  authority(object.authority, "$.authority");
200
201
  natural(object.previousCatalogueRevision, "$.previousCatalogueRevision");
201
202
  natural(object.committedCatalogueRevision, "$.committedCatalogueRevision");
202
- nullableText(object.operationId, "$.operationId");
203
+ nullableIdentifier(object.operationId, "$.operationId");
203
204
  member(object.kind, OPERATION_CHANGED_KINDS, "$.kind");
204
205
  }
205
206
 
@@ -211,7 +212,7 @@ function resultBase(value: unknown, statuses: ReadonlyArray<string>): Record<str
211
212
  assertPayloadFree(value);
212
213
  const object = record(value, "$");
213
214
  member(object.status, statuses, "$.status");
214
- text(object.requestId, "$.requestId");
215
+ identifier(object.requestId, "$.requestId");
215
216
  assertValidOperationSnapshot(object.snapshot);
216
217
  return object;
217
218
  }
@@ -219,16 +220,16 @@ function resultBase(value: unknown, statuses: ReadonlyArray<string>): Record<str
219
220
  function operationEntry(value: unknown, path: string): asserts value is OperationEntryProjection {
220
221
  const object = exactObject(value, path, OPERATION_FIELDS.OperationEntryProjection);
221
222
  authority(object.authority, `${path}.authority`);
222
- text(object.operationId, `${path}.operationId`);
223
- text(object.kindId, `${path}.kindId`);
224
- nullableText(object.scopeId, `${path}.scopeId`);
223
+ identifier(object.operationId, `${path}.operationId`);
224
+ identifier(object.kindId, `${path}.kindId`);
225
+ nullableIdentifier(object.scopeId, `${path}.scopeId`);
225
226
  text(object.label, `${path}.label`);
226
227
  member(
227
228
  object.cancellationSupport,
228
229
  ["supported", "unsupported"] as const,
229
230
  `${path}.cancellationSupport`,
230
231
  );
231
- nullableText(object.retryOf, `${path}.retryOf`);
232
+ nullableIdentifier(object.retryOf, `${path}.retryOf`);
232
233
  natural(object.sequence, `${path}.sequence`);
233
234
  natural(object.revision, `${path}.revision`);
234
235
  natural(object.lastChangedCatalogueRevision, `${path}.lastChangedCatalogueRevision`);
@@ -265,7 +266,7 @@ function progressOverall(value: unknown, path: string): void {
265
266
 
266
267
  function phase(value: unknown, path: string): void {
267
268
  const object = exactObject(value, path, OPERATION_FIELDS.OperationPhaseProgressProjection);
268
- text(object.phaseId, `${path}.phaseId`);
269
+ identifier(object.phaseId, `${path}.phaseId`);
269
270
  text(object.label, `${path}.label`);
270
271
  finite(object.completed, `${path}.completed`);
271
272
  finite(object.total, `${path}.total`);
@@ -281,7 +282,7 @@ function teardownResolution(value: unknown, path: string): void {
281
282
  exactKeys(object, path, variantKeys("OperationTeardownResolutionProjection", object, path));
282
283
  authority(object.targetAuthority, `${path}.targetAuthority`);
283
284
  }
284
- text(object.operationId, `${path}.operationId`);
285
+ identifier(object.operationId, `${path}.operationId`);
285
286
  natural(object.expectedOperationRevision, `${path}.expectedOperationRevision`);
286
287
  }
287
288
 
@@ -352,7 +353,7 @@ function mutationReceipt(value: unknown, path: string): void {
352
353
 
353
354
  function cancellationReceipt(value: unknown, path: string): void {
354
355
  const object = exactObject(value, path, OPERATION_FIELDS.OperationCancellationReceiptProjection);
355
- text(object.operationId, `${path}.operationId`);
356
+ identifier(object.operationId, `${path}.operationId`);
356
357
  member(object.outcome, OPERATION_CANCELLATION_OUTCOMES, `${path}.outcome`);
357
358
  member(object.previousState, OPERATION_STATES, `${path}.previousState`);
358
359
  member(object.committedState, OPERATION_STATES, `${path}.committedState`);
@@ -376,7 +377,7 @@ function executorDispatch(value: unknown, path: string): void {
376
377
 
377
378
  function removal(value: unknown, path: string): void {
378
379
  const object = exactObject(value, path, OPERATION_FIELDS.OperationRemovalProjection);
379
- text(object.operationId, `${path}.operationId`);
380
+ identifier(object.operationId, `${path}.operationId`);
380
381
  natural(object.sequence, `${path}.sequence`);
381
382
  natural(object.encodedWeight, `${path}.encodedWeight`);
382
383
  member(object.reason, ["evicted", "dismissed"] as const, `${path}.reason`);
@@ -396,7 +397,7 @@ function teardownOutcome(value: unknown, path: string): void {
396
397
  exactKeys(object, path, variantKeys("OperationTeardownOutcomeProjection", object, path));
397
398
  authority(object.targetAuthority, `${path}.targetAuthority`);
398
399
  }
399
- text(object.operationId, `${path}.operationId`);
400
+ identifier(object.operationId, `${path}.operationId`);
400
401
  natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
401
402
  if (object.kind === "completed") {
402
403
  natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
@@ -411,7 +412,7 @@ function limits(value: unknown, path: string): void {
411
412
  }
412
413
 
413
414
  function operationRevisionPair(object: Record<string, unknown>, path: string): void {
414
- text(object.operationId, `${path}.operationId`);
415
+ identifier(object.operationId, `${path}.operationId`);
415
416
  natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
416
417
  natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
417
418
  }
@@ -422,13 +423,13 @@ function catalogueRevisionPair(object: Record<string, unknown>, path: string): v
422
423
  }
423
424
 
424
425
  function operationTarget(object: Record<string, unknown>): void {
425
- text(object.operationId, "$.operationId");
426
+ identifier(object.operationId, "$.operationId");
426
427
  natural(object.expectedOperationRevision, "$.expectedOperationRevision");
427
428
  }
428
429
 
429
430
  function authority(value: unknown, path: string): void {
430
431
  const object = exactObject(value, path, OPERATION_FIELDS.OperationAuthorityProjection);
431
- text(object.authorityId, `${path}.authorityId`);
432
+ identifier(object.authorityId, `${path}.authorityId`);
432
433
  natural(object.authorityEpoch, `${path}.authorityEpoch`);
433
434
  if (object.authorityEpoch === 0) {
434
435
  fail(`${path}.authorityEpoch`, "must be nonzero");
@@ -457,18 +458,17 @@ function exactKeys(
457
458
  path: string,
458
459
  keys: ReadonlyArray<string>,
459
460
  ): void {
460
- const actual = Object.keys(object).sort();
461
- const expected = [...keys].sort();
462
- if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
463
- fail(path, `expected keys ${expected.join(",")}; received ${actual.join(",")}`);
464
- }
461
+ checkWireFields(object, keys, () =>
462
+ fail(
463
+ path,
464
+ `expected keys ${[...keys].sort().join(",")}; received ${Object.keys(object).sort().join(",")}`,
465
+ ),
466
+ );
465
467
  }
466
468
 
467
469
  function record(value: unknown, path: string): Record<string, unknown> {
468
- if (!isRecord(value)) {
469
- fail(path, "expected object");
470
- }
471
- return value;
470
+ const result = readWireRecord(value, () => fail(path, "expected object"));
471
+ return result;
472
472
  }
473
473
 
474
474
  function array(value: unknown, path: string): Array<unknown> {
@@ -484,9 +484,15 @@ function text(value: unknown, path: string): asserts value is string {
484
484
  }
485
485
  }
486
486
 
487
- function nullableText(value: unknown, path: string): void {
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 {
488
494
  if (value !== null) {
489
- text(value, path);
495
+ identifier(value, path);
490
496
  }
491
497
  }
492
498
 
@@ -543,24 +549,16 @@ function fail(path: string, message: string): never {
543
549
  throw new OperationProtocolValidationError(path, message);
544
550
  }
545
551
 
546
- /**
547
- * Allowed keys for one variant, from the generated map.
548
- *
549
- * A missing entry means the generator failed to read the union, not that a
550
- * caller sent something odd: every switch below runs `member()` over the
551
- * discriminant first. Failing loudly beats a hand-written list, which is what
552
- * these were and what drifted in `history-tree`.
553
- */
554
552
  function variantKeys(
555
553
  type: string,
556
554
  object: Record<string, unknown>,
557
555
  path: string,
558
556
  ): ReadonlyArray<string> {
559
- const discriminant = object[OPERATION_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
560
- const keys =
561
- typeof discriminant === "string" ? OPERATION_VARIANT_FIELDS[type]?.[discriminant] : undefined;
562
- if (keys === undefined) {
563
- fail(path, `no generated fields for ${type}.${String(discriminant)}`);
564
- }
565
- return keys;
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
+ );
566
564
  }
@@ -1,4 +1,4 @@
1
- import { CheckedSnapshotConnection } from "@inflatable-cookie/longhorn/core";
1
+ import { CheckedSnapshotConnection, CheckedSubscription } from "@inflatable-cookie/longhorn/core";
2
2
  import type {
3
3
  ConnectionFailure,
4
4
  ConnectionFailureReporter,
@@ -14,6 +14,7 @@ import type {
14
14
  SettingsScopeId,
15
15
  SettingsScopeSnapshot,
16
16
  } from "./generated/protocol.ts";
17
+ import { SETTINGS_PROTOCOL_VERSION } from "./generated/protocol.ts";
17
18
  import {
18
19
  assertValidSettingsRegistryChangedEvent,
19
20
  assertValidSettingsRegistrySnapshot,
@@ -70,7 +71,7 @@ export function connectSettingsScope(
70
71
  listen: (receive) => transport.listen(SETTINGS_SCOPE_CHANGED_EVENT, receive),
71
72
  loadSnapshot: async () => {
72
73
  const outcome = await load({
73
- protocolVersion: 1,
74
+ protocolVersion: SETTINGS_PROTOCOL_VERSION,
74
75
  requestId: options.nextRequestId(),
75
76
  registryGeneration: options.registry.generation,
76
77
  pageId: options.pageId,
@@ -129,17 +130,12 @@ function requiredSubscription<Snapshot>(
129
130
  connection: CheckedSnapshotConnection<Snapshot>,
130
131
  target: string,
131
132
  ): SettingsSubscription<Snapshot> {
132
- return {
133
- ready: connection.ready.then((snapshot) => {
134
- if (snapshot === undefined) {
135
- throw new SettingsConnectionDisposedError(target);
136
- }
137
- return snapshot;
138
- }),
139
- current: () => connection.current(),
140
- failures: () => connection.failures(),
141
- dispose: () => connection.dispose(),
142
- };
133
+ return new CheckedSubscription(connection, (snapshot) => {
134
+ if (snapshot === undefined) {
135
+ throw new SettingsConnectionDisposedError(target);
136
+ }
137
+ return snapshot;
138
+ });
143
139
  }
144
140
 
145
141
  function parseRegistry(value: unknown): SettingsRegistrySnapshot {
@@ -192,7 +188,7 @@ function isNewerRegistry(
192
188
  return false;
193
189
  }
194
190
 
195
- function isNewerScope(
191
+ export function isNewerScope(
196
192
  candidate: SettingsScopeSnapshot,
197
193
  current: SettingsScopeSnapshot | undefined,
198
194
  ): boolean {
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:settings`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per protocol type, from the Rust structs.
3
3
  // A `record()` given one of these rejects unknown and missing keys —
4
4
  // contract 010's Boundary Validation Target.
@@ -31,4 +31,5 @@ export const SETTINGS_FIELDS = {
31
31
  "SettingsMutationReceipt": ["requestId", "pageId", "applyUnitId", "scopeId", "previousAuthority", "committedAuthority", "outcome", "durability", "activationRequirements"],
32
32
  "SettingsConflict": ["expected", "actual"],
33
33
  "SettingsRejection": ["code", "diagnostic"],
34
+ "SettingsHostError": ["code", "message", "retryable"],
34
35
  } as const;
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:settings`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority.
3
3
 
4
4
  export const SETTINGS_PROTOCOL_VERSION = 1 as const;
@@ -671,3 +671,7 @@ snapshot: SettingsScopeSnapshot, } | { "status": "rejected",
671
671
  * Typed rejection.
672
672
  */
673
673
  rejection: SettingsRejection, };
674
+
675
+ export type SettingsHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
676
+
677
+ export type SettingsHostError = { "code": SettingsHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:settings`; 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.
@@ -3,6 +3,7 @@ import {
3
3
  SETTINGS_ACTIVATION_STATES,
4
4
  SETTINGS_EDITABILITIES,
5
5
  SETTINGS_EFFECTIVE_SOURCES,
6
+ SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
6
7
  SETTINGS_HARD_MAXIMUM_TEXT_BYTES,
7
8
  SETTINGS_POLICY_EFFECTS,
8
9
  SETTINGS_RECOVERY_CODES,
@@ -13,7 +14,6 @@ import { activation, hasPolicyOverride, recovery } from "./projection.ts";
13
14
  import {
14
15
  array,
15
16
  authority,
16
- HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
17
17
  identity,
18
18
  known,
19
19
  opaque,
@@ -25,7 +25,7 @@ import {
25
25
 
26
26
  export function assertValidSettingsScopeSnapshot(
27
27
  value: unknown,
28
- maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
28
+ maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
29
29
  ): asserts value is SettingsScopeSnapshot {
30
30
  const snapshot = record(value, SETTINGS_FIELDS.SettingsScopeSnapshot);
31
31
  protocolVersion(snapshot.protocolVersion);
@@ -2,6 +2,7 @@ import { SETTINGS_FIELDS } from "../generated/fields.ts";
2
2
  import {
3
3
  SETTINGS_ACTIVATION_STATES,
4
4
  SETTINGS_DURABILITY_KINDS,
5
+ SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
5
6
  SETTINGS_LOAD_OUTCOME_STATUSES,
6
7
  SETTINGS_MUTATION_OUTCOMES,
7
8
  SETTINGS_MUTATION_RESULT_STATUSES,
@@ -21,7 +22,6 @@ import { activation, rejection } from "./projection.ts";
21
22
  import {
22
23
  array,
23
24
  authority,
24
- HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
25
25
  identity,
26
26
  known,
27
27
  opaque,
@@ -48,7 +48,7 @@ export function assertValidSettingsLoadCommand(
48
48
 
49
49
  export function assertValidSettingsApplyCommand(
50
50
  value: unknown,
51
- maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
51
+ maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
52
52
  ): asserts value is SettingsApplyCommand {
53
53
  const command = mutationCommand(value, SETTINGS_FIELDS.SettingsApplyCommand);
54
54
  opaque(command.intent, maximumOpaqueValueBytes);
@@ -63,7 +63,7 @@ export function assertValidSettingsResetCommand(
63
63
 
64
64
  export function assertValidSettingsLoadOutcome(
65
65
  value: unknown,
66
- maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
66
+ maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
67
67
  ): asserts value is SettingsLoadOutcome {
68
68
  const outcome = record(value);
69
69
  known(outcome.status, SETTINGS_LOAD_OUTCOME_STATUSES);
@@ -77,7 +77,7 @@ export function assertValidSettingsLoadOutcome(
77
77
 
78
78
  export function assertValidSettingsMutationResult(
79
79
  value: unknown,
80
- maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
80
+ maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
81
81
  ): asserts value is SettingsMutationResult {
82
82
  const result = record(value);
83
83
  known(result.status, SETTINGS_MUTATION_RESULT_STATUSES);
@@ -138,6 +138,7 @@ function receipt(value: unknown, maximum: number): void {
138
138
  known(receipt.outcome, SETTINGS_MUTATION_OUTCOMES);
139
139
  const durability = record(receipt.durability);
140
140
  known(durability.kind, SETTINGS_DURABILITY_KINDS);
141
+ record(durability, variantKeys("SettingsDurabilityEvidence", durability));
141
142
  if (durability.kind === "confirmed") {
142
143
  optionalOpaque(durability.evidence, maximum);
143
144
  }
@@ -1,4 +1,12 @@
1
- import { isRecord } from "../../core/record.ts";
1
+ import { isOpaqueId } from "../../core/identifiers.ts";
2
+ import {
3
+ checkWireFields,
4
+ hasHole,
5
+ readWireRecord,
6
+ signed32,
7
+ unsigned32,
8
+ wireVariantFields,
9
+ } from "../../core/record.ts";
2
10
  import {
3
11
  SETTINGS_VARIANT_FIELDS,
4
12
  SETTINGS_VARIANT_FIELDS_DISCRIMINANTS,
@@ -12,14 +20,6 @@ import type { SettingsOpaqueValue } from "../generated/protocol.ts";
12
20
  import { incompatible } from "./error.ts";
13
21
  import type { SettingsProtocolValidationCode } from "./error.ts";
14
22
 
15
- /**
16
- * Kept under its original name so the twenty call sites do not churn, but the
17
- * value is now the Rust `SettingsLimits::HARD_MAXIMUM_OPAQUE_VALUE_BYTES`
18
- * rather than a literal that happened to match it.
19
- */
20
- export const HARD_MAXIMUM_OPAQUE_VALUE_BYTES: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES;
21
- const OPAQUE_ID = /^[a-z0-9][a-z0-9._:/-]{0,254}$/;
22
-
23
23
  export function authority(value: unknown): void {
24
24
  const valueRecord = record(value, SETTINGS_FIELDS.SettingsAuthorityExpectation);
25
25
  unsigned(valueRecord.registryGeneration, "invalid_revision");
@@ -35,7 +35,9 @@ export function optionalOpaque(value: unknown, maximum: number): void {
35
35
 
36
36
  export function opaque(value: unknown, maximum: number): asserts value is SettingsOpaqueValue {
37
37
  const envelope = record(value, SETTINGS_FIELDS.SettingsOpaqueValue);
38
- positive(envelope.codecVersion, "invalid_opaque_value");
38
+ if (!unsigned32(envelope.codecVersion) || envelope.codecVersion === 0) {
39
+ incompatible("invalid_opaque_value", envelope.codecVersion);
40
+ }
39
41
  let encoded: string | undefined;
40
42
  try {
41
43
  encoded = JSON.stringify(envelope);
@@ -46,13 +48,13 @@ export function opaque(value: unknown, maximum: number): asserts value is Settin
46
48
  incompatible("invalid_opaque_value", value);
47
49
  }
48
50
  const bytes = new TextEncoder().encode(encoded).byteLength;
49
- if (bytes > maximum || bytes > HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
51
+ if (bytes > maximum || bytes > SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
50
52
  incompatible("opaque_value_too_large", bytes);
51
53
  }
52
54
  }
53
55
 
54
- export function definition(value: unknown): void {
55
- const valueRecord = record(value);
56
+ export function definition(value: unknown, allowed: ReadonlyArray<string>): void {
57
+ const valueRecord = record(value, allowed);
56
58
  identity(valueRecord.id);
57
59
  identity(valueRecord.moduleId);
58
60
  }
@@ -62,7 +64,7 @@ export function arraysOfIdentities(...values: Array<unknown>): void {
62
64
  }
63
65
 
64
66
  export function identity(value: unknown): asserts value is string {
65
- if (typeof value !== "string" || !OPAQUE_ID.test(value)) {
67
+ if (!isOpaqueId(value)) {
66
68
  incompatible("invalid_identity", value);
67
69
  }
68
70
  }
@@ -95,8 +97,8 @@ export function boolean(value: unknown): void {
95
97
  }
96
98
  }
97
99
 
98
- export function integer(value: unknown): void {
99
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
100
+ export function order(value: unknown): void {
101
+ if (!signed32(value)) {
100
102
  incompatible("invalid_shape", value);
101
103
  }
102
104
  }
@@ -119,69 +121,32 @@ export function boundedArray(
119
121
  maximum: number,
120
122
  code: SettingsProtocolValidationCode,
121
123
  ): Array<unknown> {
122
- const values = array(value);
123
- if (values.length > maximum) {
124
- incompatible(code, values.length);
124
+ // Bounds land before work: an oversized list is refused unread.
125
+ if (Array.isArray(value) && value.length > maximum) {
126
+ incompatible(code, value.length);
125
127
  }
126
- return values;
128
+ return array(value);
127
129
  }
128
130
 
129
131
  export function array(value: unknown): Array<unknown> {
130
- if (!Array.isArray(value)) {
132
+ if (!Array.isArray(value) || hasHole(value)) {
131
133
  incompatible("invalid_shape", value);
132
134
  }
133
135
  return value;
134
136
  }
135
137
 
136
- /**
137
- * Rejects a non-object, an unknown key, and a missing key.
138
- *
139
- * `allowed` comes from the generated field map, so the keys accepted are the
140
- * Rust struct's and nothing else — contract 010's Boundary Validation Target.
141
- * Called without a list, this keeps shape-only behaviour, which is correct
142
- * for a tagged union and a gap anywhere else.
143
- */
144
138
  export function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
145
- if (!isRecord(value)) {
146
- incompatible("invalid_shape", value);
147
- }
148
- const result = value;
149
- if (allowed === undefined) {
150
- return result;
151
- }
152
-
153
- const permitted = new Set(allowed);
154
- for (const key of Object.keys(result)) {
155
- if (!permitted.has(key)) {
156
- incompatible("unknown_field", { key, value });
157
- }
158
- }
159
- for (const key of allowed) {
160
- if (!(key in result)) {
161
- incompatible("missing_field", { key, value });
162
- }
163
- }
139
+ const result = readWireRecord(value, () => incompatible("invalid_shape", value));
140
+ checkWireFields(result, allowed, (code, key) => incompatible(code, { key, value }));
164
141
  return result;
165
142
  }
166
143
 
167
- /**
168
- * Allowed keys for one tagged-union variant, from the generated map.
169
- *
170
- * The discriminant's name comes from the map too: this domain tags
171
- * `SettingsDurabilityEvidence` on `kind` and its two results on `status`, and
172
- * a call site that has to name the right one is a per-site chance to name the
173
- * wrong one.
174
- *
175
- * A missing entry means the generator failed to read the union, not that a
176
- * caller sent something odd — every caller checks the discriminant with
177
- * `known()` above this call.
178
- */
179
144
  export function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
180
- const discriminant = value[SETTINGS_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
181
- const keys =
182
- typeof discriminant === "string" ? SETTINGS_VARIANT_FIELDS[type]?.[discriminant] : undefined;
183
- if (keys === undefined) {
184
- incompatible("unknown_field", { type, discriminant });
185
- }
186
- return keys;
145
+ return wireVariantFields(
146
+ SETTINGS_VARIANT_FIELDS,
147
+ SETTINGS_VARIANT_FIELDS_DISCRIMINANTS,
148
+ type,
149
+ value,
150
+ (discriminant) => incompatible("unknown_field", { type, discriminant }),
151
+ );
187
152
  }