@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:notifications`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Wording lives in Rust, on the enum that owns it. A label edited here is
3
3
  // a label that disagrees with the native surface.
4
4
 
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:notifications`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority. Executable actions are intentionally absent.
3
3
 
4
4
  export const NOTIFICATION_PROTOCOL_VERSION = 1 as const;
@@ -520,3 +520,7 @@ affectedNotificationIds: Array<NotificationId>,
520
520
  * Change source.
521
521
  */
522
522
  kind: NotificationChangedKind, };
523
+
524
+ export type NotificationHostErrorCode = "authorityUnavailable" | "authorityStateUnavailable" | "eventPublication";
525
+
526
+ export type NotificationHostError = { "code": NotificationHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:notifications`; 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,22 +1,27 @@
1
+ import type { Unlisten } from "../core/transport.ts";
1
2
  import type {
2
3
  NotificationChangedEvent,
3
4
  NotificationMutationCommand,
4
5
  NotificationRequestId,
5
6
  NotificationSnapshotQuery,
7
+ NotificationSnapshotResponse,
8
+ NotificationMutationResult,
6
9
  } from "./generated/protocol.ts";
7
10
 
8
- export type NotificationUnlisten = () => void | Promise<void>;
11
+ export type NotificationUnlisten = Unlisten;
9
12
 
10
13
  export interface NotificationPort {
11
14
  snapshot(query: NotificationSnapshotQuery): Promise<unknown>;
12
15
  mutate(command: NotificationMutationCommand): Promise<unknown>;
13
- listen?(listener: (event: unknown) => void): NotificationUnlisten | Promise<NotificationUnlisten>;
16
+ listen?:
17
+ | ((listener: (event: unknown) => void) => NotificationUnlisten | Promise<NotificationUnlisten>)
18
+ | undefined;
14
19
  nextRequestId(): NotificationRequestId;
15
20
  }
16
21
 
17
22
  export interface CheckedNotificationPort {
18
- snapshot(query: NotificationSnapshotQuery): Promise<import("./generated/protocol.ts").NotificationSnapshotResponse>;
19
- mutate(command: NotificationMutationCommand): Promise<import("./generated/protocol.ts").NotificationMutationResult>;
23
+ snapshot(query: NotificationSnapshotQuery): Promise<NotificationSnapshotResponse>;
24
+ mutate(command: NotificationMutationCommand): Promise<NotificationMutationResult>;
20
25
  listen?(listener: (event: NotificationChangedEvent) => void): Promise<NotificationUnlisten>;
21
26
  nextRequestId(): NotificationRequestId;
22
27
  }
@@ -1,27 +1,29 @@
1
- import type { NotificationMutationCommand, NotificationSnapshotQuery } from "./generated/protocol.ts";
1
+ import { wireCopy } from "../core/wire-copy.ts";
2
+ import type {
3
+ NotificationMutationCommand,
4
+ NotificationSnapshotQuery,
5
+ } from "./generated/protocol.ts";
2
6
  import type { NotificationPort, NotificationUnlisten } from "./ports.ts";
3
7
 
4
8
  export class SerializedNotificationPort implements NotificationPort {
5
9
  constructor(readonly inner: NotificationPort) {}
6
10
 
7
11
  async snapshot(query: NotificationSnapshotQuery): Promise<unknown> {
8
- return clone(await this.inner.snapshot(clone(query)));
12
+ return wireCopy(await this.inner.snapshot(wireCopy(query)));
9
13
  }
10
14
 
11
15
  async mutate(command: NotificationMutationCommand): Promise<unknown> {
12
- return clone(await this.inner.mutate(clone(command)));
16
+ return wireCopy(await this.inner.mutate(wireCopy(command)));
13
17
  }
14
18
 
15
19
  async listen(listener: (event: unknown) => void): Promise<NotificationUnlisten> {
16
- if (this.inner.listen === undefined) return () => {};
17
- return this.inner.listen((event) => listener(clone(event)));
20
+ if (this.inner.listen === undefined) {
21
+ return () => {};
22
+ }
23
+ return this.inner.listen((event) => listener(wireCopy(event)));
18
24
  }
19
25
 
20
26
  nextRequestId(): string {
21
27
  return this.inner.nextRequestId();
22
28
  }
23
29
  }
24
-
25
- function clone<Value>(value: Value): Value {
26
- return JSON.parse(JSON.stringify(value)) as Value;
27
- }
@@ -14,7 +14,7 @@ export type NotificationStatusTone = "info" | "success" | "warning" | "danger";
14
14
  * Lives here rather than in a projection tier because two places needed it —
15
15
  * `NotificationController.projectToast` and the Poodle projector — and a rule
16
16
  * stated twice is a rule that can drift. The cross-backend parity fixture
17
- * checks this one function, so a third copy would be unchecked. See card 171.
17
+ * checks this one function.
18
18
  *
19
19
  * The `error`/`critical` collapse is lossy and the tone cannot say so; a
20
20
  * surface that needs the distinction restores it in text, as the Rust toast
@@ -1,3 +1,5 @@
1
+ import { isOpaqueId } from "../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
1
3
  import {
2
4
  NOTIFICATION_VARIANT_FIELDS,
3
5
  NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS,
@@ -7,42 +9,56 @@ import {
7
9
  NOTIFICATION_CHANGED_KINDS,
8
10
  NOTIFICATION_MUTATION_KINDS,
9
11
  NOTIFICATION_MUTATION_STATUSES,
12
+ NOTIFICATION_CLEAR_TARGET_KINDS,
13
+ NOTIFICATION_RECEIPT_KINDS,
14
+ NOTIFICATION_REMOVAL_REASONS,
10
15
  NOTIFICATION_PROTOCOL_VERSION,
11
16
  NOTIFICATION_READ_STATES,
12
17
  NOTIFICATION_REJECTION_CODES,
13
18
  NOTIFICATION_RETENTION_CLASSES,
14
19
  NOTIFICATION_SEVERITIES,
15
- type NotificationChangedEvent,
16
- type NotificationMutationCommand,
17
- type NotificationMutationResult,
18
- type NotificationRecordProjection,
19
- type NotificationSnapshot,
20
- type NotificationSnapshotQuery,
21
- type NotificationSnapshotResponse,
20
+ } from "./generated/protocol.ts";
21
+ import type {
22
+ NotificationChangedEvent,
23
+ NotificationMutationCommand,
24
+ NotificationMutationResult,
25
+ NotificationRecordProjection,
26
+ NotificationSnapshot,
27
+ NotificationSnapshotQuery,
28
+ NotificationSnapshotResponse,
22
29
  } from "./generated/protocol.ts";
23
30
 
24
31
  export class NotificationProtocolValidationError extends Error {
25
- constructor(readonly path: string, message: string) {
32
+ constructor(
33
+ readonly path: string,
34
+ message: string,
35
+ ) {
26
36
  super(`incompatible notification protocol at ${path}: ${message}`);
27
37
  this.name = "NotificationProtocolValidationError";
28
38
  }
29
39
  }
30
40
 
31
- export function assertValidNotificationSnapshotQuery(value: unknown): asserts value is NotificationSnapshotQuery {
41
+ export function assertValidNotificationSnapshotQuery(
42
+ value: unknown,
43
+ ): asserts value is NotificationSnapshotQuery {
32
44
  const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotQuery);
33
45
  protocol(object.protocolVersion, "$.protocolVersion");
34
- text(object.requestId, "$.requestId");
46
+ opaqueId(object.requestId, "$.requestId");
35
47
  natural(object.offset, "$.offset");
36
48
  natural(object.limit, "$.limit");
37
49
  }
38
50
 
39
- export function assertValidNotificationSnapshotResponse(value: unknown): asserts value is NotificationSnapshotResponse {
51
+ export function assertValidNotificationSnapshotResponse(
52
+ value: unknown,
53
+ ): asserts value is NotificationSnapshotResponse {
40
54
  const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotResponse);
41
- text(object.requestId, "$.requestId");
55
+ opaqueId(object.requestId, "$.requestId");
42
56
  assertValidNotificationSnapshot(object.snapshot);
43
57
  }
44
58
 
45
- export function assertValidNotificationSnapshot(value: unknown): asserts value is NotificationSnapshot {
59
+ export function assertValidNotificationSnapshot(
60
+ value: unknown,
61
+ ): asserts value is NotificationSnapshot {
46
62
  const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshot);
47
63
  protocol(object.protocolVersion, "$.protocolVersion");
48
64
  authority(object.authority, "$.authority");
@@ -56,20 +72,24 @@ export function assertValidNotificationSnapshot(value: unknown): asserts value i
56
72
  natural(page.offset, "$.page.offset");
57
73
  natural(page.totalCount, "$.page.totalCount");
58
74
  boolean(page.hasMore, "$.page.hasMore");
59
- array(page.records, "$.page.records").forEach((item, index) => recordProjection(item, `$.page.records[${index}]`));
75
+ array(page.records, "$.page.records").forEach((item, index) =>
76
+ recordProjection(item, `$.page.records[${index}]`),
77
+ );
60
78
  }
61
79
 
62
- export function assertValidNotificationMutationCommand(value: unknown): asserts value is NotificationMutationCommand {
80
+ export function assertValidNotificationMutationCommand(
81
+ value: unknown,
82
+ ): asserts value is NotificationMutationCommand {
63
83
  const object = record(value, "$");
64
84
  member(object.kind, NOTIFICATION_MUTATION_KINDS, "$.kind");
65
85
  protocol(object.protocolVersion, "$.protocolVersion");
66
- text(object.requestId, "$.requestId");
86
+ opaqueId(object.requestId, "$.requestId");
67
87
  authority(object.authority, "$.authority");
68
88
  natural(object.expectedLedgerRevision, "$.expectedLedgerRevision");
69
89
  switch (object.kind) {
70
90
  case "add":
71
91
  exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
72
- text(object.notificationId, "$.notificationId");
92
+ opaqueId(object.notificationId, "$.notificationId");
73
93
  draft(object.draft, "$.draft");
74
94
  break;
75
95
  case "replace":
@@ -80,14 +100,22 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
80
100
  case "markSeen":
81
101
  case "dismiss":
82
102
  exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
83
- text(object.notificationId, "$.notificationId");
103
+ opaqueId(object.notificationId, "$.notificationId");
84
104
  break;
85
105
  case "clear": {
86
106
  exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
87
107
  const target = record(object.target, "$.target");
88
- member(target.kind, ["all", "records"] as const, "$.target.kind");
89
- exactKeys(target, "$.target", variantKeys("NotificationClearTargetProjection", target, "$.target"));
90
- if (target.kind === "records") array(target.notificationIds, "$.target.notificationIds").forEach((id, index) => text(id, `$.target.notificationIds[${index}]`));
108
+ member(target.kind, NOTIFICATION_CLEAR_TARGET_KINDS, "$.target.kind");
109
+ exactKeys(
110
+ target,
111
+ "$.target",
112
+ variantKeys("NotificationClearTargetProjection", target, "$.target"),
113
+ );
114
+ if (target.kind === "records") {
115
+ array(target.notificationIds, "$.target.notificationIds").forEach((id, index) =>
116
+ opaqueId(id, `$.target.notificationIds[${index}]`),
117
+ );
118
+ }
91
119
  break;
92
120
  }
93
121
  case "changeRetention":
@@ -97,37 +125,47 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
97
125
  }
98
126
  }
99
127
 
100
- export function assertValidNotificationMutationResult(value: unknown): asserts value is NotificationMutationResult {
128
+ export function assertValidNotificationMutationResult(
129
+ value: unknown,
130
+ ): asserts value is NotificationMutationResult {
101
131
  const object = record(value, "$");
102
132
  member(object.status, NOTIFICATION_MUTATION_STATUSES, "$.status");
103
- text(object.requestId, "$.requestId");
133
+ opaqueId(object.requestId, "$.requestId");
104
134
  assertValidNotificationSnapshot(object.snapshot);
105
135
  if (object.status === "committed") {
106
136
  exactKeys(object, "$", variantKeys("NotificationMutationResult", object, "$"));
107
137
  receipt(object.receipt, "$.receipt");
108
138
  } else {
109
139
  exactKeys(object, "$", variantKeys("NotificationMutationResult", object, "$"));
110
- const rejection = exact(object.rejection, "$.rejection", NOTIFICATIONS_FIELDS.NotificationRejection);
140
+ const rejection = exact(
141
+ object.rejection,
142
+ "$.rejection",
143
+ NOTIFICATIONS_FIELDS.NotificationRejection,
144
+ );
111
145
  member(rejection.code, NOTIFICATION_REJECTION_CODES, "$.rejection.code");
112
146
  text(rejection.detail, "$.rejection.detail");
113
147
  boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
114
148
  }
115
149
  }
116
150
 
117
- export function assertValidNotificationChangedEvent(value: unknown): asserts value is NotificationChangedEvent {
151
+ export function assertValidNotificationChangedEvent(
152
+ value: unknown,
153
+ ): asserts value is NotificationChangedEvent {
118
154
  const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationChangedEvent);
119
155
  protocol(object.protocolVersion, "$.protocolVersion");
120
- text(object.requestId, "$.requestId");
156
+ opaqueId(object.requestId, "$.requestId");
121
157
  authority(object.authority, "$.authority");
122
158
  natural(object.previousLedgerRevision, "$.previousLedgerRevision");
123
159
  natural(object.committedLedgerRevision, "$.committedLedgerRevision");
124
- array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) => text(id, `$.affectedNotificationIds[${index}]`));
160
+ array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) =>
161
+ opaqueId(id, `$.affectedNotificationIds[${index}]`),
162
+ );
125
163
  member(object.kind, NOTIFICATION_CHANGED_KINDS, "$.kind");
126
164
  }
127
165
 
128
166
  function authority(value: unknown, path: string): void {
129
167
  const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationAuthorityProjection);
130
- text(object.authorityId, `${path}.authorityId`);
168
+ opaqueId(object.authorityId, `${path}.authorityId`);
131
169
  positive(object.authorityEpoch, `${path}.authorityEpoch`);
132
170
  }
133
171
 
@@ -139,25 +177,34 @@ function limits(value: unknown, path: string): void {
139
177
 
140
178
  function draft(value: unknown, path: string): void {
141
179
  const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationDraftProjection);
142
- text(object.sourceId, `${path}.sourceId`);
180
+ opaqueId(object.sourceId, `${path}.sourceId`);
143
181
  member(object.severity, NOTIFICATION_SEVERITIES, `${path}.severity`);
144
182
  text(object.title, `${path}.title`);
145
183
  text(object.summary, `${path}.summary`);
146
- nullableText(object.causeId, `${path}.causeId`);
184
+ nullableOpaqueId(object.causeId, `${path}.causeId`);
147
185
  array(object.actions, `${path}.actions`).forEach((action, index) => {
148
- const item = exact(action, `${path}.actions[${index}]`, NOTIFICATIONS_FIELDS.NotificationActionProjection);
149
- text(item.referenceId, `${path}.actions[${index}].referenceId`);
186
+ const item = exact(
187
+ action,
188
+ `${path}.actions[${index}]`,
189
+ NOTIFICATIONS_FIELDS.NotificationActionProjection,
190
+ );
191
+ opaqueId(item.referenceId, `${path}.actions[${index}].referenceId`);
150
192
  text(item.label, `${path}.actions[${index}].label`);
151
193
  });
152
- nullableText(object.replacementKey, `${path}.replacementKey`);
153
- nullableText(object.producerToken, `${path}.producerToken`);
194
+ nullableOpaqueId(object.replacementKey, `${path}.replacementKey`);
195
+ nullableOpaqueId(object.producerToken, `${path}.producerToken`);
154
196
  member(object.retentionClass, NOTIFICATION_RETENTION_CLASSES, `${path}.retentionClass`);
155
- if (object.presentationTimeUnixMs !== null) integer(object.presentationTimeUnixMs, `${path}.presentationTimeUnixMs`);
197
+ if (object.presentationTimeUnixMs !== null) {
198
+ integer(object.presentationTimeUnixMs, `${path}.presentationTimeUnixMs`);
199
+ }
156
200
  }
157
201
 
158
- function recordProjection(value: unknown, path: string): asserts value is NotificationRecordProjection {
202
+ function recordProjection(
203
+ value: unknown,
204
+ path: string,
205
+ ): asserts value is NotificationRecordProjection {
159
206
  const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationRecordProjection);
160
- text(object.notificationId, `${path}.notificationId`);
207
+ opaqueId(object.notificationId, `${path}.notificationId`);
161
208
  draft(object.draft, `${path}.draft`);
162
209
  positive(object.sequence, `${path}.sequence`);
163
210
  positive(object.lastChangedLedgerRevision, `${path}.lastChangedLedgerRevision`);
@@ -167,7 +214,7 @@ function recordProjection(value: unknown, path: string): asserts value is Notifi
167
214
 
168
215
  function receipt(value: unknown, path: string): void {
169
216
  const object = record(value, path);
170
- member(object.kind, ["added", "replaced", "seen", "removed", "retentionChanged"] as const, `${path}.kind`);
217
+ member(object.kind, NOTIFICATION_RECEIPT_KINDS, `${path}.kind`);
171
218
  natural(object.previousLedgerRevision, `${path}.previousLedgerRevision`);
172
219
  natural(object.committedLedgerRevision, `${path}.committedLedgerRevision`);
173
220
  if (object.kind === "added" || object.kind === "replaced") {
@@ -190,57 +237,104 @@ function receipt(value: unknown, path: string): void {
190
237
 
191
238
  function removals(value: unknown, path: string): void {
192
239
  array(value, path).forEach((removal, index) => {
193
- const item = exact(removal, `${path}[${index}]`, NOTIFICATIONS_FIELDS.NotificationRemovalProjection);
240
+ const item = exact(
241
+ removal,
242
+ `${path}[${index}]`,
243
+ NOTIFICATIONS_FIELDS.NotificationRemovalProjection,
244
+ );
194
245
  recordProjection(item.record, `${path}[${index}].record`);
195
- member(item.reason, ["dismissed", "cleared", "pruned"] as const, `${path}[${index}].reason`);
246
+ member(item.reason, NOTIFICATION_REMOVAL_REASONS, `${path}[${index}].reason`);
196
247
  });
197
248
  }
198
249
 
199
250
  function protocol(value: unknown, path: string): void {
200
- if (value !== NOTIFICATION_PROTOCOL_VERSION) fail(path, `expected protocol ${NOTIFICATION_PROTOCOL_VERSION}`);
251
+ if (value !== NOTIFICATION_PROTOCOL_VERSION) {
252
+ fail(path, `expected protocol ${NOTIFICATION_PROTOCOL_VERSION}`);
253
+ }
201
254
  }
202
255
 
203
256
  function record(value: unknown, path: string): Record<string, unknown> {
204
- if (typeof value !== "object" || value === null || Array.isArray(value)) fail(path, "expected object");
205
- return value as Record<string, unknown>;
257
+ const result = readWireRecord(value, () => fail(path, "expected object"));
258
+ return result;
206
259
  }
207
260
 
208
- function exact(value: unknown, path: string, keys: readonly string[]): Record<string, unknown> {
261
+ function exact(value: unknown, path: string, keys: ReadonlyArray<string>): Record<string, unknown> {
209
262
  const object = record(value, path);
210
263
  exactKeys(object, path, keys);
211
264
  return object;
212
265
  }
213
266
 
214
- function exactKeys(object: Record<string, unknown>, path: string, keys: readonly string[]): void {
215
- const actual = Object.keys(object).sort();
216
- const expected = [...keys].sort();
217
- if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) fail(path, `expected keys ${expected.join(", ")}`);
267
+ function exactKeys(
268
+ object: Record<string, unknown>,
269
+ path: string,
270
+ keys: ReadonlyArray<string>,
271
+ ): void {
272
+ checkWireFields(object, keys, () => fail(path, `expected keys ${[...keys].sort().join(", ")}`));
218
273
  }
219
274
 
220
- function array(value: unknown, path: string): unknown[] {
221
- if (!Array.isArray(value)) fail(path, "expected array");
275
+ function array(value: unknown, path: string): Array<unknown> {
276
+ if (!Array.isArray(value)) {
277
+ fail(path, "expected array");
278
+ }
222
279
  return value;
223
280
  }
224
281
 
225
- function text(value: unknown, path: string): void { if (typeof value !== "string" || value.length === 0) fail(path, "expected nonempty string"); }
226
- function nullableText(value: unknown, path: string): void { if (value !== null) text(value, path); }
227
- function boolean(value: unknown, path: string): void { if (typeof value !== "boolean") fail(path, "expected boolean"); }
228
- function integer(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value)) fail(path, "expected safe integer"); }
229
- function natural(value: unknown, path: string): void { integer(value, path); if ((value as number) < 0) fail(path, "expected nonnegative integer"); }
230
- function positive(value: unknown, path: string): void { natural(value, path); if ((value as number) === 0) fail(path, "expected positive integer"); }
231
- function member(value: unknown, members: readonly string[], path: string): void { if (typeof value !== "string" || !members.includes(value)) fail(path, `expected one of ${members.join(", ")}`); }
232
- function fail(path: string, message: string): never { throw new NotificationProtocolValidationError(path, message); }
233
-
234
- /**
235
- * Allowed keys for one tagged-union variant, from the generated map, with the
236
- * discriminant's name read from the map too.
237
- *
238
- * A missing entry means the generator failed to read the union: every caller
239
- * checks the discriminant above this call.
240
- */
241
- function variantKeys(type: string, object: Record<string, unknown>, path: string): readonly string[] {
242
- const discriminant = object[NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
243
- const keys = NOTIFICATION_VARIANT_FIELDS[type]?.[discriminant as string];
244
- if (keys === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
245
- return keys;
282
+ function text(value: unknown, path: string): void {
283
+ if (typeof value !== "string" || value.length === 0) {
284
+ fail(path, "expected nonempty string");
285
+ }
286
+ }
287
+ function opaqueId(value: unknown, path: string): void {
288
+ if (!isOpaqueId(value)) {
289
+ fail(path, "expected bounded lowercase opaque id");
290
+ }
291
+ }
292
+ function nullableOpaqueId(value: unknown, path: string): void {
293
+ if (value !== null) {
294
+ opaqueId(value, path);
295
+ }
296
+ }
297
+ function boolean(value: unknown, path: string): void {
298
+ if (typeof value !== "boolean") {
299
+ fail(path, "expected boolean");
300
+ }
301
+ }
302
+ function integer(value: unknown, path: string): asserts value is number {
303
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) {
304
+ fail(path, "expected safe integer");
305
+ }
306
+ }
307
+ function natural(value: unknown, path: string): asserts value is number {
308
+ integer(value, path);
309
+ if (value < 0) {
310
+ fail(path, "expected nonnegative integer");
311
+ }
312
+ }
313
+ function positive(value: unknown, path: string): void {
314
+ natural(value, path);
315
+ if (value === 0) {
316
+ fail(path, "expected positive integer");
317
+ }
318
+ }
319
+ function member(value: unknown, members: ReadonlyArray<string>, path: string): void {
320
+ if (typeof value !== "string" || !members.includes(value)) {
321
+ fail(path, `expected one of ${members.join(", ")}`);
322
+ }
323
+ }
324
+ function fail(path: string, message: string): never {
325
+ throw new NotificationProtocolValidationError(path, message);
326
+ }
327
+
328
+ function variantKeys(
329
+ type: string,
330
+ object: Record<string, unknown>,
331
+ path: string,
332
+ ): ReadonlyArray<string> {
333
+ return wireVariantFields(
334
+ NOTIFICATION_VARIANT_FIELDS,
335
+ NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS,
336
+ type,
337
+ object,
338
+ (discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
339
+ );
246
340
  }