@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,9 @@
1
- import { HISTORY_TREE_VARIANT_FIELDS, HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS } from "./generated/variant-fields.ts";
1
+ import { isOpaqueId } from "../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
3
+ import {
4
+ HISTORY_TREE_VARIANT_FIELDS,
5
+ HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
6
+ } from "./generated/variant-fields.ts";
2
7
  import {
3
8
  FORK_HISTORY_CHANGED_KINDS,
4
9
  FORK_HISTORY_ENTRY_POSITIONS,
@@ -8,27 +13,35 @@ import {
8
13
  FORK_HISTORY_PATH_FLOORS,
9
14
  FORK_HISTORY_PATH_TARGETS,
10
15
  FORK_HISTORY_PRUNE_STATUSES,
16
+ FORK_HISTORY_DELETE_STATUSES,
17
+ FORK_HISTORY_RETENTION_REJECTION_CODES,
11
18
  FORK_HISTORY_PROTOCOL_VERSION,
12
19
  MAXIMUM_FORK_HISTORY_PAGE_SIZE,
13
- type ForkBranchPageCommand,
14
- type ForkBranchPageSnapshot,
15
- type ForkContinuationPageCommand,
16
- type ForkContinuationPageSnapshot,
17
- type ForkDeleteContinuationCommand,
18
- type ForkPruneCommand,
19
- type ForkPruneResult,
20
- type ForkRemovalReceiptProjection,
21
- type ForkChangedEvent,
22
- type ForkNavigationCommand,
23
- type ForkNavigationResult,
24
- type ForkPathPageCommand,
25
- type ForkPathPageSnapshot,
26
- type ForkSnapshot,
20
+ } from "./generated/protocol.ts";
21
+ import type {
22
+ ForkBranchPageCommand,
23
+ ForkBranchPageSnapshot,
24
+ ForkContinuationPageCommand,
25
+ ForkContinuationPageSnapshot,
26
+ ForkDeleteContinuationCommand,
27
+ ForkPruneCommand,
28
+ ForkPruneResult,
29
+ ForkDeleteResult,
30
+ ForkRemovalReceiptProjection,
31
+ ForkChangedEvent,
32
+ ForkNavigationCommand,
33
+ ForkNavigationResult,
34
+ ForkPathPageCommand,
35
+ ForkPathPageSnapshot,
36
+ ForkSnapshot,
27
37
  } from "./generated/protocol.ts";
28
38
  import { HISTORY_TREE_FIELDS } from "./generated/fields.ts";
29
39
 
30
40
  export class ForkHistoryValidationError extends Error {
31
- constructor(readonly path: string, message: string) {
41
+ constructor(
42
+ readonly path: string,
43
+ message: string,
44
+ ) {
32
45
  super(`${path}: ${message}`);
33
46
  this.name = "ForkHistoryValidationError";
34
47
  }
@@ -46,7 +59,16 @@ export function assertForkSnapshot(value: unknown): asserts value is ForkSnapsho
46
59
  integer(summary.revision, "$.summary.revision");
47
60
  id(summary.currentBranchId, "$.summary.currentBranchId");
48
61
  optionalId(summary.currentEntryId, "$.summary.currentEntryId");
49
- for (const key of ["undoDepth", "redoDepth", "retainedEntryCount", "retainedEncodedWeight", "branchCount", "alternatePathCount"] as const) integer(summary[key], `$.summary.${key}`);
62
+ for (const key of [
63
+ "undoDepth",
64
+ "redoDepth",
65
+ "retainedEntryCount",
66
+ "retainedEncodedWeight",
67
+ "branchCount",
68
+ "alternatePathCount",
69
+ ] as const) {
70
+ integer(summary[key], `$.summary.${key}`);
71
+ }
50
72
  optionalString(summary.nextUndoLabel, "$.summary.nextUndoLabel");
51
73
  optionalString(summary.nextRedoLabel, "$.summary.nextRedoLabel");
52
74
  }
@@ -56,8 +78,12 @@ export function assertForkPathCommand(value: unknown): asserts value is ForkPath
56
78
  const target = object(object(value, "$").target, "$.target");
57
79
  oneOf(target.kind, "$.target.kind", FORK_HISTORY_PATH_TARGETS);
58
80
  exact(target, "$.target", variantFields("ForkPathTargetProjection", target, "$.target"));
59
- if (target.kind === "branch") id(target.branchId, "$.target.branchId");
60
- if (target.kind === "continuation") id(target.fromEntryId, "$.target.fromEntryId");
81
+ if (target.kind === "branch") {
82
+ id(target.branchId, "$.target.branchId");
83
+ }
84
+ if (target.kind === "continuation") {
85
+ id(target.fromEntryId, "$.target.fromEntryId");
86
+ }
61
87
  }
62
88
 
63
89
  export function assertForkBranchCommand(value: unknown): asserts value is ForkBranchPageCommand {
@@ -72,14 +98,17 @@ export function assertForkPathPage(value: unknown): asserts value is ForkPathPag
72
98
  optionalId(root.branchId, "$.branchId");
73
99
  optionalId(root.headEntryId, "$.headEntryId");
74
100
  integer(root.precedingContinuationCount, "$.precedingContinuationCount");
75
- // Card 191. The floor tells a renderer whether to draw an origin row; a
76
- // nested run says `anchor` and means "draw nothing, it is already above".
101
+ // An anchor floor refers to the entry already drawn above a nested run.
77
102
  const floor = object(root.floor, "$.floor");
78
103
  oneOf(floor.kind, "$.floor.kind", FORK_HISTORY_PATH_FLOORS);
79
104
  exact(floor, "$.floor", variantFields("ForkPathFloorProjection", floor, "$.floor"));
80
- if (floor.kind === "anchor") id(floor.entryId, "$.floor.entryId");
105
+ if (floor.kind === "anchor") {
106
+ id(floor.entryId, "$.floor.entryId");
107
+ }
81
108
  integer(root.totalEntries, "$.totalEntries");
82
- array(root.entries, "$.entries").forEach((entry, index) => entryRecord(entry, `$.entries[${index}]`));
109
+ array(root.entries, "$.entries").forEach((entry, index) =>
110
+ entryRecord(entry, `$.entries[${index}]`),
111
+ );
83
112
  boolean(root.truncatedBefore, "$.truncatedBefore");
84
113
  boolean(root.truncatedAfter, "$.truncatedAfter");
85
114
  }
@@ -106,66 +135,215 @@ export function assertForkBranchPage(value: unknown): asserts value is ForkBranc
106
135
  boolean(root.truncatedAfter, "$.truncatedAfter");
107
136
  }
108
137
 
109
- export function assertForkNavigationCommand(value: unknown): asserts value is ForkNavigationCommand {
138
+ export function assertForkNavigationCommand(
139
+ value: unknown,
140
+ ): asserts value is ForkNavigationCommand {
110
141
  noPayload(value);
111
142
  const root = object(value, "$");
112
143
  exact(root, "$", HISTORY_TREE_FIELDS.ForkNavigationCommand);
113
- protocol(root.protocolVersion, "$.protocolVersion"); positive(root.authorityEpoch, "$.authorityEpoch"); id(root.historyId, "$.historyId"); id(root.planId, "$.planId"); integer(root.expectedRevision, "$.expectedRevision");
114
- const target = object(root.target, "$.target"); oneOf(target.kind, "$.target.kind", FORK_HISTORY_NAVIGATION_TARGETS);
144
+ protocol(root.protocolVersion, "$.protocolVersion");
145
+ positive(root.authorityEpoch, "$.authorityEpoch");
146
+ id(root.historyId, "$.historyId");
147
+ id(root.planId, "$.planId");
148
+ integer(root.expectedRevision, "$.expectedRevision");
149
+ const target = object(root.target, "$.target");
150
+ oneOf(target.kind, "$.target.kind", FORK_HISTORY_NAVIGATION_TARGETS);
115
151
  exact(target, "$.target", variantFields("ForkNavigationTargetProjection", target, "$.target"));
116
- if (target.kind === "checkout") { id(target.branchId, "$.target.branchId"); id(target.entryId, "$.target.entryId"); }
117
- if (target.kind === "checkoutBranchRoot") id(target.branchId, "$.target.branchId");
118
- if (target.kind === "checkoutContinuation") id(target.entryId, "$.target.entryId");
152
+ if (target.kind === "checkout") {
153
+ id(target.branchId, "$.target.branchId");
154
+ id(target.entryId, "$.target.entryId");
155
+ }
156
+ if (target.kind === "checkoutBranchRoot") {
157
+ id(target.branchId, "$.target.branchId");
158
+ }
159
+ if (target.kind === "checkoutContinuation") {
160
+ id(target.entryId, "$.target.entryId");
161
+ }
119
162
  }
120
163
 
121
164
  export function assertForkNavigationResult(value: unknown): asserts value is ForkNavigationResult {
122
165
  noPayload(value);
123
- const root = object(value, "$"); oneOf(root.status, "$.status", FORK_HISTORY_NAVIGATION_STATUSES);
124
- exact(root, "$", root.status === "committed" ? ["status", "snapshot", "receipt"] : ["status", "snapshot", "rejection"]);
166
+ const root = object(value, "$");
167
+ oneOf(root.status, "$.status", FORK_HISTORY_NAVIGATION_STATUSES);
168
+ exact(
169
+ root,
170
+ "$",
171
+ root.status === "committed"
172
+ ? ["status", "snapshot", "receipt"]
173
+ : ["status", "snapshot", "rejection"],
174
+ );
125
175
  assertForkSnapshot(root.snapshot);
126
176
  if (root.status === "committed") {
127
177
  const receipt = object(root.receipt, "$.receipt");
128
178
  exact(receipt, "$.receipt", HISTORY_TREE_FIELDS.ForkNavigationReceiptProjection);
129
- id(receipt.historyId, "$.receipt.historyId"); id(receipt.planId, "$.receipt.planId"); integer(receipt.previousRevision, "$.receipt.previousRevision"); integer(receipt.committedRevision, "$.receipt.committedRevision"); optionalId(receipt.sourceEntryId, "$.receipt.sourceEntryId"); optionalId(receipt.targetEntryId, "$.receipt.targetEntryId"); id(receipt.targetBranchId, "$.receipt.targetBranchId"); array(receipt.movedEntryIds, "$.receipt.movedEntryIds").forEach((entry, index) => id(entry, `$.receipt.movedEntryIds[${index}]`));
179
+ id(receipt.historyId, "$.receipt.historyId");
180
+ id(receipt.planId, "$.receipt.planId");
181
+ integer(receipt.previousRevision, "$.receipt.previousRevision");
182
+ integer(receipt.committedRevision, "$.receipt.committedRevision");
183
+ optionalId(receipt.sourceEntryId, "$.receipt.sourceEntryId");
184
+ optionalId(receipt.targetEntryId, "$.receipt.targetEntryId");
185
+ id(receipt.targetBranchId, "$.receipt.targetBranchId");
186
+ array(receipt.movedEntryIds, "$.receipt.movedEntryIds").forEach((entry, index) =>
187
+ id(entry, `$.receipt.movedEntryIds[${index}]`),
188
+ );
130
189
  } else {
131
190
  const rejection = object(root.rejection, "$.rejection");
132
- exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection); oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_NAVIGATION_REJECTION_CODES); string(rejection.detail, "$.rejection.detail"); boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
191
+ exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
192
+ oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_NAVIGATION_REJECTION_CODES);
193
+ string(rejection.detail, "$.rejection.detail");
194
+ boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
133
195
  }
134
196
  }
135
197
 
136
198
  export function assertForkChangedEvent(value: unknown): asserts value is ForkChangedEvent {
137
- noPayload(value); const root = object(value, "$");
199
+ noPayload(value);
200
+ const root = object(value, "$");
138
201
  exact(root, "$", HISTORY_TREE_FIELDS.ForkChangedEvent);
139
- protocol(root.protocolVersion, "$.protocolVersion"); positive(root.authorityEpoch, "$.authorityEpoch"); id(root.historyId, "$.historyId");
140
- if (root.previousRevision !== null) integer(root.previousRevision, "$.previousRevision");
141
- integer(root.committedRevision, "$.committedRevision"); oneOf(root.kind, "$.kind", FORK_HISTORY_CHANGED_KINDS);
202
+ protocol(root.protocolVersion, "$.protocolVersion");
203
+ positive(root.authorityEpoch, "$.authorityEpoch");
204
+ id(root.historyId, "$.historyId");
205
+ if (root.previousRevision !== null) {
206
+ integer(root.previousRevision, "$.previousRevision");
207
+ }
208
+ integer(root.committedRevision, "$.committedRevision");
209
+ oneOf(root.kind, "$.kind", FORK_HISTORY_CHANGED_KINDS);
142
210
  }
143
211
 
144
- function commandBase(value: unknown, allowed: readonly string[]): void { noPayload(value); const root = object(value, "$"); exact(root, "$", allowed); protocol(root.protocolVersion, "$.protocolVersion"); positive(root.authorityEpoch, "$.authorityEpoch"); id(root.historyId, "$.historyId"); integer(root.expectedRevision, "$.expectedRevision"); integer(root.offset, "$.offset"); positive(root.limit, "$.limit"); if ((root.limit as number) > MAXIMUM_FORK_HISTORY_PAGE_SIZE) fail("$.limit", `maximum is ${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`); }
145
- function snapshotBase(root: Record<string, unknown>): void { protocol(root.protocolVersion, "$.protocolVersion"); positive(root.authorityEpoch, "$.authorityEpoch"); id(root.historyId, "$.historyId"); integer(root.revision, "$.revision"); integer(root.offset, "$.offset"); }
146
- function entryRecord(value: unknown, path: string): void { const root = object(value, path); exact(root, path, HISTORY_TREE_FIELDS.ForkEntryRecord); id(root.entryId, `${path}.entryId`); string(root.label, `${path}.label`); optionalId(root.kindId, `${path}.kindId`); optionalId(root.groupId, `${path}.groupId`); optionalInteger(root.recordedAt, `${path}.recordedAt`); integer(root.continuationCount, `${path}.continuationCount`); positive(root.sequence, `${path}.sequence`); integer(root.committedRevision, `${path}.committedRevision`); integer(root.encodedWeight, `${path}.encodedWeight`); oneOf(root.position, `${path}.position`, FORK_HISTORY_ENTRY_POSITIONS); }
147
- function noPayload(value: unknown): void { const visit = (candidate: unknown, path: string): void => { if (Array.isArray(candidate)) return candidate.forEach((item, index) => visit(item, `${path}[${index}]`)); if (candidate !== null && typeof candidate === "object") for (const [key, child] of Object.entries(candidate)) { if (key.toLocaleLowerCase().includes("payload")) fail(`${path}.${key}`, "product payload field is forbidden"); visit(child, `${path}.${key}`); } }; visit(value, "$"); }
148
- 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>; }
149
- function array(value: unknown, path: string): unknown[] { if (!Array.isArray(value)) fail(path, "expected array"); return value; }
150
- 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(",")}`); }
151
- function protocol(value: unknown, path: string): void { if (value !== FORK_HISTORY_PROTOCOL_VERSION) fail(path, `expected exact protocol ${FORK_HISTORY_PROTOCOL_VERSION}`); }
152
- function integer(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected non-negative safe integer"); }
153
- function positive(value: unknown, path: string): void { integer(value, path); if (value === 0) fail(path, "expected positive integer"); }
154
- function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
155
- function id(value: unknown, path: string): void { string(value, path); if ((value as string).length === 0) fail(path, "expected non-empty id"); }
156
- function optionalId(value: unknown, path: string): void { if (value !== null) id(value, path); }
157
- function optionalString(value: unknown, path: string): void { if (value !== null) string(value, path); }
158
- function optionalInteger(value: unknown, path: string): void { if (value !== null) integer(value, path); }
159
- function boolean(value: unknown, path: string): void { if (typeof value !== "boolean") fail(path, "expected boolean"); }
160
- function oneOf(value: unknown, path: string, values: readonly string[]): void { if (typeof value !== "string" || !values.includes(value)) fail(path, "unsupported value"); }
161
- function fail(path: string, message: string): never { throw new ForkHistoryValidationError(path, message); }
212
+ function commandBase(value: unknown, allowed: ReadonlyArray<string>): void {
213
+ noPayload(value);
214
+ const root = object(value, "$");
215
+ exact(root, "$", allowed);
216
+ protocol(root.protocolVersion, "$.protocolVersion");
217
+ positive(root.authorityEpoch, "$.authorityEpoch");
218
+ id(root.historyId, "$.historyId");
219
+ integer(root.expectedRevision, "$.expectedRevision");
220
+ integer(root.offset, "$.offset");
221
+ positive(root.limit, "$.limit");
222
+ if (root.limit > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
223
+ fail("$.limit", `maximum is ${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
224
+ }
225
+ }
226
+ function snapshotBase(root: Record<string, unknown>): void {
227
+ protocol(root.protocolVersion, "$.protocolVersion");
228
+ positive(root.authorityEpoch, "$.authorityEpoch");
229
+ id(root.historyId, "$.historyId");
230
+ integer(root.revision, "$.revision");
231
+ integer(root.offset, "$.offset");
232
+ }
233
+ function entryRecord(value: unknown, path: string): void {
234
+ const root = object(value, path);
235
+ exact(root, path, HISTORY_TREE_FIELDS.ForkEntryRecord);
236
+ id(root.entryId, `${path}.entryId`);
237
+ string(root.label, `${path}.label`);
238
+ optionalId(root.kindId, `${path}.kindId`);
239
+ optionalId(root.groupId, `${path}.groupId`);
240
+ optionalInteger(root.recordedAt, `${path}.recordedAt`);
241
+ integer(root.continuationCount, `${path}.continuationCount`);
242
+ positive(root.sequence, `${path}.sequence`);
243
+ integer(root.committedRevision, `${path}.committedRevision`);
244
+ integer(root.encodedWeight, `${path}.encodedWeight`);
245
+ oneOf(root.position, `${path}.position`, FORK_HISTORY_ENTRY_POSITIONS);
246
+ }
247
+ function noPayload(value: unknown): void {
248
+ const visit = (candidate: unknown, path: string): void => {
249
+ if (Array.isArray(candidate)) {
250
+ return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
251
+ }
252
+ if (candidate !== null && typeof candidate === "object") {
253
+ for (const [key, child] of Object.entries(candidate)) {
254
+ if (key.toLocaleLowerCase().includes("payload")) {
255
+ fail(`${path}.${key}`, "product payload field is forbidden");
256
+ }
257
+ visit(child, `${path}.${key}`);
258
+ }
259
+ }
260
+ };
261
+ visit(value, "$");
262
+ }
263
+ function object(value: unknown, path: string): Record<string, unknown> {
264
+ const result = readWireRecord(value, () => fail(path, "expected object"));
265
+ return result;
266
+ }
267
+ function array(value: unknown, path: string): Array<unknown> {
268
+ if (!Array.isArray(value)) {
269
+ fail(path, "expected array");
270
+ }
271
+ return value;
272
+ }
273
+ function exact(
274
+ value: Record<string, unknown>,
275
+ path: string,
276
+ expected: ReadonlyArray<string>,
277
+ ): void {
278
+ checkWireFields(value, expected, () =>
279
+ fail(path, `unexpected keys: ${Object.keys(value).sort().join(",")}`),
280
+ );
281
+ }
282
+ function protocol(value: unknown, path: string): void {
283
+ if (value !== FORK_HISTORY_PROTOCOL_VERSION) {
284
+ fail(path, `expected exact protocol ${FORK_HISTORY_PROTOCOL_VERSION}`);
285
+ }
286
+ }
287
+ function integer(value: unknown, path: string): asserts value is number {
288
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
289
+ fail(path, "expected non-negative safe integer");
290
+ }
291
+ }
292
+ function positive(value: unknown, path: string): asserts value is number {
293
+ integer(value, path);
294
+ if (value === 0) {
295
+ fail(path, "expected positive integer");
296
+ }
297
+ }
298
+ function string(value: unknown, path: string): asserts value is string {
299
+ if (typeof value !== "string") {
300
+ fail(path, "expected string");
301
+ }
302
+ }
303
+ function id(value: unknown, path: string): void {
304
+ if (!isOpaqueId(value)) {
305
+ fail(path, "expected bounded lowercase opaque id");
306
+ }
307
+ }
308
+ function optionalId(value: unknown, path: string): void {
309
+ if (value !== null) {
310
+ id(value, path);
311
+ }
312
+ }
313
+ function optionalString(value: unknown, path: string): void {
314
+ if (value !== null) {
315
+ string(value, path);
316
+ }
317
+ }
318
+ function optionalInteger(value: unknown, path: string): void {
319
+ if (value !== null) {
320
+ integer(value, path);
321
+ }
322
+ }
323
+ function boolean(value: unknown, path: string): void {
324
+ if (typeof value !== "boolean") {
325
+ fail(path, "expected boolean");
326
+ }
327
+ }
328
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
329
+ if (typeof value !== "string" || !values.includes(value)) {
330
+ fail(path, "unsupported value");
331
+ }
332
+ }
333
+ function fail(path: string, message: string): never {
334
+ throw new ForkHistoryValidationError(path, message);
335
+ }
162
336
 
163
- export function assertForkContinuationCommand(value: unknown): asserts value is ForkContinuationPageCommand {
337
+ export function assertForkContinuationCommand(
338
+ value: unknown,
339
+ ): asserts value is ForkContinuationPageCommand {
164
340
  commandBase(value, HISTORY_TREE_FIELDS.ForkContinuationPageCommand);
165
341
  optionalId(object(value, "$").anchorEntryId, "$.anchorEntryId");
166
342
  }
167
343
 
168
- export function assertForkContinuationPage(value: unknown): asserts value is ForkContinuationPageSnapshot {
344
+ export function assertForkContinuationPage(
345
+ value: unknown,
346
+ ): asserts value is ForkContinuationPageSnapshot {
169
347
  noPayload(value);
170
348
  const root = object(value, "$");
171
349
  exact(root, "$", HISTORY_TREE_FIELDS.ForkContinuationPageSnapshot);
@@ -194,7 +372,9 @@ export function assertForkContinuationPage(value: unknown): asserts value is For
194
372
  * silently tolerated `offset` and `limit` would accept a caller who thought
195
373
  * this was a paged read.
196
374
  */
197
- export function assertForkDeleteCommand(value: unknown): asserts value is ForkDeleteContinuationCommand {
375
+ export function assertForkDeleteCommand(
376
+ value: unknown,
377
+ ): asserts value is ForkDeleteContinuationCommand {
198
378
  noPayload(value);
199
379
  const root = object(value, "$");
200
380
  exact(root, "$", HISTORY_TREE_FIELDS.ForkDeleteContinuationCommand);
@@ -205,7 +385,9 @@ export function assertForkDeleteCommand(value: unknown): asserts value is ForkDe
205
385
  id(root.entryId, "$.entryId");
206
386
  }
207
387
 
208
- export function assertForkRemovalReceipt(value: unknown): asserts value is ForkRemovalReceiptProjection {
388
+ export function assertForkRemovalReceipt(
389
+ value: unknown,
390
+ ): asserts value is ForkRemovalReceiptProjection {
209
391
  noPayload(value);
210
392
  const root = object(value, "$");
211
393
  exact(root, "$", HISTORY_TREE_FIELDS.ForkRemovalReceiptProjection);
@@ -222,8 +404,12 @@ export function assertForkRemovalReceipt(value: unknown): asserts value is ForkR
222
404
  positive(entry.sequence, `${at}.sequence`);
223
405
  integer(entry.encodedWeight, `${at}.encodedWeight`);
224
406
  });
225
- array(root.removedBranches, "$.removedBranches").forEach((branch, index) => id(branch, `$.removedBranches[${index}]`));
226
- array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) => id(checkpoint, `$.removedCheckpoints[${index}]`));
407
+ array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
408
+ id(branch, `$.removedBranches[${index}]`),
409
+ );
410
+ array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) =>
411
+ id(checkpoint, `$.removedCheckpoints[${index}]`),
412
+ );
227
413
  integer(root.retainedEntryCount, "$.retainedEntryCount");
228
414
  integer(root.retainedEncodedWeight, "$.retainedEncodedWeight");
229
415
  integer(root.unprotectedEntryCount, "$.unprotectedEntryCount");
@@ -240,8 +426,28 @@ export function assertForkPruneCommand(value: unknown): asserts value is ForkPru
240
426
  integer(root.expectedRevision, "$.expectedRevision");
241
427
  // The budget bounds the unprotected share, and a zero budget is rejected by
242
428
  // the authority rather than treated as "remove everything unprotected".
243
- positive(root.maximumEntries, "$.maximumEntries");
244
- positive(root.maximumEncodedWeight, "$.maximumEncodedWeight");
429
+ integer(root.maximumEntries, "$.maximumEntries");
430
+ integer(root.maximumEncodedWeight, "$.maximumEncodedWeight");
431
+ }
432
+
433
+ function assertRetentionRejection(value: unknown): void {
434
+ const rejection = object(value, "$.rejection");
435
+ exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkRetentionRejectionProjection);
436
+ oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_RETENTION_REJECTION_CODES);
437
+ string(rejection.detail, "$.rejection.detail");
438
+ boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
439
+ }
440
+
441
+ export function assertForkDeleteResult(value: unknown): asserts value is ForkDeleteResult {
442
+ noPayload(value);
443
+ const root = object(value, "$");
444
+ oneOf(root.status, "$.status", FORK_HISTORY_DELETE_STATUSES);
445
+ exact(root, "$", variantFields("ForkDeleteResult", root, "$"));
446
+ if (root.status === "deleted") {
447
+ assertForkRemovalReceipt(root.receipt);
448
+ } else {
449
+ assertRetentionRejection(root.rejection);
450
+ }
245
451
  }
246
452
 
247
453
  export function assertForkPruneResult(value: unknown): asserts value is ForkPruneResult {
@@ -249,21 +455,23 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
249
455
  const root = object(value, "$");
250
456
  oneOf(root.status, "$.status", FORK_HISTORY_PRUNE_STATUSES);
251
457
  exact(root, "$", variantFields("ForkPruneResult", root, "$"));
252
- if (root.status === "pruned") assertForkRemovalReceipt(root.receipt);
458
+ if (root.status === "pruned") {
459
+ assertForkRemovalReceipt(root.receipt);
460
+ } else if (root.status === "rejected") {
461
+ assertRetentionRejection(root.rejection);
462
+ }
253
463
  }
254
464
 
255
- /**
256
- * Allowed keys for one variant, from the generated map.
257
- *
258
- * A missing entry means the generator failed to read the union, not that a
259
- * consumer sent something odd — every caller runs `oneOf` over the
260
- * discriminant first, so an unknown one is already rejected by then. Failing
261
- * loudly beats defaulting to a key list, which is how `checkoutBranchRoot`
262
- * shipped rejecting its own `branchId`.
263
- */
264
- function variantFields(type: string, object: Record<string, unknown>, path: string): readonly string[] {
265
- const discriminant = object[HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
266
- const fields = HISTORY_TREE_VARIANT_FIELDS[type]?.[discriminant as string];
267
- if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
268
- return fields;
465
+ function variantFields(
466
+ type: string,
467
+ object: Record<string, unknown>,
468
+ path: string,
469
+ ): ReadonlyArray<string> {
470
+ return wireVariantFields(
471
+ HISTORY_TREE_VARIANT_FIELDS,
472
+ HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
473
+ type,
474
+ object,
475
+ (discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
476
+ );
269
477
  }
@@ -1,6 +1,7 @@
1
- // @generated by `effigy generate:layout`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority.
3
3
 
4
+ export const LAYOUT_RATIO_ONE_MILLIONTHS = 1000000 as const;
4
5
  export const LAYOUT_PROTOCOL_VERSION = 1 as const;
5
6
  export const LAYOUT_MUTATION_COMMAND_KINDS = ["create_panel","close_panel","activate_panel","reorder_region","move_panel","set_sizing_slot","set_region_collapsed"] as const;
6
7
  export const LAYOUT_MUTATION_OUTCOME_KINDS = ["panel_created","panel_closed","panel_activated","region_reordered","panel_moved","sizing_slot_set","region_collapsed_set"] as const;
@@ -26,7 +27,7 @@ export type SurfaceRevision = number;
26
27
 
27
28
  export type LayoutRatio = number;
28
29
 
29
- export type LayoutLimits = { maximum_schemas: number, maximum_regions_per_schema: number, maximum_sizing_slots_per_schema: number, maximum_panel_definitions: number, maximum_surfaces: number, maximum_panel_instances: number, maximum_panel_instances_per_region: number, };
30
+ export type SurfaceLimits = { maximum_schemas: number, maximum_regions_per_schema: number, maximum_sizing_slots_per_schema: number, maximum_panel_definitions: number, maximum_surfaces: number, maximum_windows: number, maximum_host_preferences_per_surface: number, maximum_label_bytes: number, maximum_panel_instances: number, maximum_panel_instances_per_region: number, };
30
31
 
31
32
  export type EmptyRegionPolicy = "keep_visible" | "hide_when_empty";
32
33
 
@@ -38,7 +39,7 @@ export type LayoutSchemaDefinition = { id: LayoutSchemaId, regions: Array<Region
38
39
 
39
40
  export type PlacementSelector = { "kind": "region", "id": RegionId } | { "kind": "family", "id": RegionFamilyId };
40
41
 
41
- export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_container" } | { "kind": "bounded",
42
+ export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_surface" } | { "kind": "bounded",
42
43
  /**
43
44
  * Maximum instances in the complete document.
44
45
  */
@@ -0,0 +1,47 @@
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
+ // Allowed field names per tagged-union variant, from the Rust enums.
3
+ // Keyed by type, then by discriminant. The discriminant itself is in
4
+ // each list, because `exact()` compares every key.
5
+
6
+ export const LAYOUT_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
7
+ "PlacementSelector": {
8
+ "region": ["kind", "id"],
9
+ "family": ["kind", "id"],
10
+ },
11
+ "PanelInstancePolicy": {
12
+ "singleton": ["kind"],
13
+ "one_per_surface": ["kind"],
14
+ "bounded": ["kind", "maximum_per_document", "maximum_per_surface"],
15
+ "multiple": ["kind"],
16
+ },
17
+ "SurfacePresentation": {
18
+ "regional": ["kind"],
19
+ "focused_panel": ["kind", "panel_definition_id"],
20
+ },
21
+ "LayoutMutationCommand": {
22
+ "create_panel": ["kind", "panel_instance_id", "panel_definition_id", "surface_id", "region_id", "insertion_index"],
23
+ "close_panel": ["kind", "panel_instance_id"],
24
+ "activate_panel": ["kind", "panel_instance_id"],
25
+ "reorder_region": ["kind", "surface_id", "region_id", "panel_instance_ids"],
26
+ "move_panel": ["kind", "panel_instance_id", "target_surface_id", "target_region_id", "insertion_index"],
27
+ "set_sizing_slot": ["kind", "surface_id", "sizing_slot_id", "ratio"],
28
+ "set_region_collapsed": ["kind", "surface_id", "region_id", "collapsed"],
29
+ },
30
+ "LayoutMutationOutcome": {
31
+ "panel_created": ["kind", "panel_instance_id", "surface_id", "region_id", "insertion_index"],
32
+ "panel_closed": ["kind", "panel_instance_id", "surface_id", "region_id", "former_index"],
33
+ "panel_activated": ["kind", "panel_instance_id", "surface_id", "region_id", "previous_active_panel_instance_id"],
34
+ "region_reordered": ["kind", "surface_id", "region_id", "panel_instance_ids"],
35
+ "panel_moved": ["kind", "panel_instance_id", "source_surface_id", "source_region_id", "former_index", "target_surface_id", "target_region_id", "insertion_index"],
36
+ "sizing_slot_set": ["kind", "surface_id", "sizing_slot_id", "previous_ratio", "committed_ratio"],
37
+ "region_collapsed_set": ["kind", "surface_id", "region_id", "previous_collapsed", "committed_collapsed"],
38
+ },
39
+ };
40
+
41
+ export const LAYOUT_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
42
+ "PlacementSelector": "kind",
43
+ "PanelInstancePolicy": "kind",
44
+ "SurfacePresentation": "kind",
45
+ "LayoutMutationCommand": "kind",
46
+ "LayoutMutationOutcome": "kind",
47
+ };
@@ -1,4 +1,4 @@
1
1
  export * from "./generated/protocol.ts";
2
2
  export * from "./validation.ts";
3
- export * from "./ratio.ts";
3
+ export { layoutRatioFromMillionths, layoutRatioToUnitInterval } from "./ratio.ts";
4
4
  export * from "./visibility.ts";
@@ -1,13 +1,12 @@
1
+ import { LAYOUT_RATIO_ONE_MILLIONTHS } from "./generated/protocol.ts";
1
2
  import type { LayoutRatio } from "./generated/protocol.ts";
2
3
 
3
- export const LAYOUT_RATIO_ONE_MILLIONTHS = 1_000_000;
4
+ export function isLayoutRatio(value: unknown): value is LayoutRatio {
5
+ return typeof value === "number" && ratioInRange(value);
6
+ }
4
7
 
5
8
  export function layoutRatioFromMillionths(value: number): LayoutRatio {
6
- if (
7
- !Number.isSafeInteger(value) ||
8
- value < 0 ||
9
- value > LAYOUT_RATIO_ONE_MILLIONTHS
10
- ) {
9
+ if (!ratioInRange(value)) {
11
10
  throw new RangeError(
12
11
  `layout ratio must be an integer from 0 through ${LAYOUT_RATIO_ONE_MILLIONTHS}; received ${String(value)}`,
13
12
  );
@@ -16,7 +15,9 @@ export function layoutRatioFromMillionths(value: number): LayoutRatio {
16
15
  }
17
16
 
18
17
  export function layoutRatioToUnitInterval(value: LayoutRatio): number {
19
- return (
20
- layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS
21
- );
18
+ return layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS;
19
+ }
20
+
21
+ function ratioInRange(value: number): boolean {
22
+ return Number.isSafeInteger(value) && value >= 0 && value <= LAYOUT_RATIO_ONE_MILLIONTHS;
22
23
  }