@inflatable-cookie/longhorn 0.4.3 → 0.6.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 (126) hide show
  1. package/package.json +1 -1
  2. package/src/agent-control/inject.ts +4 -1
  3. package/src/agent-control/selection.ts +35 -20
  4. package/src/agent-control/shim.ts +302 -144
  5. package/src/bridge/direct.ts +1 -1
  6. package/src/bridge/generated/fields.ts +3 -2
  7. package/src/bridge/generated/protocol.ts +7 -3
  8. package/src/bridge/job.ts +4 -14
  9. package/src/bridge/loopback.ts +7 -25
  10. package/src/bridge/operation.ts +13 -43
  11. package/src/bridge/router.ts +10 -23
  12. package/src/bridge/runtime/connection.ts +77 -105
  13. package/src/bridge/runtime/policy.ts +8 -28
  14. package/src/bridge/runtime/retry.ts +6 -18
  15. package/src/bridge/session.ts +4 -14
  16. package/src/bridge/stream/connection.ts +16 -38
  17. package/src/bridge/stream/source.ts +2 -6
  18. package/src/bridge/stream/tracker.ts +7 -12
  19. package/src/bridge/supervision.ts +11 -26
  20. package/src/bridge/validation/base.ts +17 -39
  21. package/src/bridge/validation/jobs.ts +11 -25
  22. package/src/bridge/validation/negotiation.ts +27 -37
  23. package/src/bridge/validation/operations.ts +28 -52
  24. package/src/bridge/validation/streams.ts +3 -10
  25. package/src/commands/client.ts +21 -26
  26. package/src/commands/controller.ts +32 -47
  27. package/src/commands/generated/fields.ts +3 -2
  28. package/src/commands/generated/protocol.ts +4 -0
  29. package/src/commands/keyboard.ts +92 -89
  30. package/src/commands/ports.ts +6 -12
  31. package/src/commands/projectors.ts +50 -48
  32. package/src/commands/validation.ts +70 -97
  33. package/src/config/client.ts +6 -19
  34. package/src/config/generated/fields.ts +2 -2
  35. package/src/config/names.ts +6 -12
  36. package/src/config/validation/commands.ts +5 -17
  37. package/src/config/validation/outcomes.ts +31 -39
  38. package/src/config/validation/primitives.ts +36 -53
  39. package/src/config/validation/projection.ts +66 -94
  40. package/src/core/connection.ts +70 -61
  41. package/src/core/record.ts +4 -0
  42. package/src/core/transport.ts +4 -15
  43. package/src/core/wire-copy.ts +6 -0
  44. package/src/history/client.ts +6 -12
  45. package/src/history/controller.ts +46 -46
  46. package/src/history/direct.ts +1 -3
  47. package/src/history/generated/fields.ts +2 -2
  48. package/src/history/ports.ts +4 -6
  49. package/src/history/serialized.ts +9 -13
  50. package/src/history/validation.ts +71 -55
  51. package/src/history-tree/client.ts +87 -11
  52. package/src/history-tree/controller.ts +313 -70
  53. package/src/history-tree/direct.ts +3 -1
  54. package/src/history-tree/generated/fields.ts +2 -2
  55. package/src/history-tree/ports.ts +3 -1
  56. package/src/history-tree/serialized.ts +39 -11
  57. package/src/history-tree/validation.ts +262 -63
  58. package/src/layout/generated/protocol.ts +2 -2
  59. package/src/layout/ratio.ts +2 -8
  60. package/src/layout/validation.ts +10 -19
  61. package/src/layout/visibility.ts +1 -2
  62. package/src/licence/client.ts +44 -7
  63. package/src/licence/controller.ts +76 -40
  64. package/src/licence/direct.ts +3 -1
  65. package/src/licence/generated/fields.ts +2 -2
  66. package/src/licence/generated/key-conformance.json +28 -0
  67. package/src/licence/generated/protocol.ts +1 -1
  68. package/src/licence/key.ts +40 -12
  69. package/src/licence/ports.ts +3 -1
  70. package/src/licence/serialized.ts +32 -9
  71. package/src/licence/validation.ts +120 -36
  72. package/src/native-content/client.ts +178 -236
  73. package/src/native-content/generated/fields.ts +2 -2
  74. package/src/native-content/ports.ts +9 -15
  75. package/src/native-content/serialized.ts +12 -19
  76. package/src/native-content/validation/base.ts +57 -50
  77. package/src/native-content/validation/messages.ts +21 -35
  78. package/src/native-content/validation/state.ts +31 -33
  79. package/src/notifications/client.ts +87 -31
  80. package/src/notifications/controller.ts +215 -61
  81. package/src/notifications/direct.ts +3 -1
  82. package/src/notifications/generated/fields.ts +2 -2
  83. package/src/notifications/ports.ts +7 -3
  84. package/src/notifications/serialized.ts +11 -9
  85. package/src/notifications/validation.ts +147 -43
  86. package/src/operation/bridge.ts +117 -50
  87. package/src/operation/client.ts +38 -24
  88. package/src/operation/controller.ts +33 -42
  89. package/src/operation/direct.ts +1 -3
  90. package/src/operation/generated/fields.ts +2 -2
  91. package/src/operation/ports.ts +10 -9
  92. package/src/operation/serialized.ts +8 -9
  93. package/src/operation/validation.ts +152 -65
  94. package/src/settings/client.ts +11 -44
  95. package/src/settings/connection.ts +26 -40
  96. package/src/settings/generated/fields.ts +3 -3
  97. package/src/settings/generated/protocol.ts +9 -4
  98. package/src/settings/names.ts +2 -4
  99. package/src/settings/registry.ts +23 -25
  100. package/src/settings/validation/authority.ts +19 -17
  101. package/src/settings/validation/command.ts +17 -37
  102. package/src/settings/validation/error.ts +2 -8
  103. package/src/settings/validation/primitives.ts +26 -42
  104. package/src/settings/validation/projection.ts +8 -24
  105. package/src/settings/validation/registry.ts +25 -73
  106. package/src/surface-transfer/client.ts +6 -18
  107. package/src/surface-transfer/generated/fields.ts +2 -2
  108. package/src/surface-transfer/validation.ts +31 -49
  109. package/src/surfaces/client.ts +12 -22
  110. package/src/surfaces/generated/fields.ts +2 -2
  111. package/src/surfaces/validation.ts +40 -49
  112. package/src/transfer/client.ts +26 -60
  113. package/src/transfer/connection.ts +12 -20
  114. package/src/transfer/generated/fields.ts +5 -5
  115. package/src/transfer/generated/protocol.ts +4 -4
  116. package/src/transfer/payload.ts +13 -31
  117. package/src/transfer/validation.ts +39 -75
  118. package/src/update/client.ts +59 -9
  119. package/src/update/controller.ts +113 -48
  120. package/src/update/direct.ts +3 -1
  121. package/src/update/generated/fields.ts +3 -3
  122. package/src/update/generated/protocol.ts +7 -3
  123. package/src/update/generated/variant-fields.ts +1 -0
  124. package/src/update/ports.ts +6 -2
  125. package/src/update/serialized.ts +34 -10
  126. package/src/update/validation.ts +115 -35
@@ -1,4 +1,8 @@
1
- import { HISTORY_TREE_VARIANT_FIELDS, HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS } from "./generated/variant-fields.ts";
1
+ import { isRecord } from "../core/record.ts";
2
+ import {
3
+ HISTORY_TREE_VARIANT_FIELDS,
4
+ HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
5
+ } from "./generated/variant-fields.ts";
2
6
  import {
3
7
  FORK_HISTORY_CHANGED_KINDS,
4
8
  FORK_HISTORY_ENTRY_POSITIONS,
@@ -10,25 +14,30 @@ import {
10
14
  FORK_HISTORY_PRUNE_STATUSES,
11
15
  FORK_HISTORY_PROTOCOL_VERSION,
12
16
  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,
17
+ } from "./generated/protocol.ts";
18
+ import type {
19
+ ForkBranchPageCommand,
20
+ ForkBranchPageSnapshot,
21
+ ForkContinuationPageCommand,
22
+ ForkContinuationPageSnapshot,
23
+ ForkDeleteContinuationCommand,
24
+ ForkPruneCommand,
25
+ ForkPruneResult,
26
+ ForkRemovalReceiptProjection,
27
+ ForkChangedEvent,
28
+ ForkNavigationCommand,
29
+ ForkNavigationResult,
30
+ ForkPathPageCommand,
31
+ ForkPathPageSnapshot,
32
+ ForkSnapshot,
27
33
  } from "./generated/protocol.ts";
28
34
  import { HISTORY_TREE_FIELDS } from "./generated/fields.ts";
29
35
 
30
36
  export class ForkHistoryValidationError extends Error {
31
- constructor(readonly path: string, message: string) {
37
+ constructor(
38
+ readonly path: string,
39
+ message: string,
40
+ ) {
32
41
  super(`${path}: ${message}`);
33
42
  this.name = "ForkHistoryValidationError";
34
43
  }
@@ -46,7 +55,16 @@ export function assertForkSnapshot(value: unknown): asserts value is ForkSnapsho
46
55
  integer(summary.revision, "$.summary.revision");
47
56
  id(summary.currentBranchId, "$.summary.currentBranchId");
48
57
  optionalId(summary.currentEntryId, "$.summary.currentEntryId");
49
- for (const key of ["undoDepth", "redoDepth", "retainedEntryCount", "retainedEncodedWeight", "branchCount", "alternatePathCount"] as const) integer(summary[key], `$.summary.${key}`);
58
+ for (const key of [
59
+ "undoDepth",
60
+ "redoDepth",
61
+ "retainedEntryCount",
62
+ "retainedEncodedWeight",
63
+ "branchCount",
64
+ "alternatePathCount",
65
+ ] as const) {
66
+ integer(summary[key], `$.summary.${key}`);
67
+ }
50
68
  optionalString(summary.nextUndoLabel, "$.summary.nextUndoLabel");
51
69
  optionalString(summary.nextRedoLabel, "$.summary.nextRedoLabel");
52
70
  }
@@ -56,8 +74,12 @@ export function assertForkPathCommand(value: unknown): asserts value is ForkPath
56
74
  const target = object(object(value, "$").target, "$.target");
57
75
  oneOf(target.kind, "$.target.kind", FORK_HISTORY_PATH_TARGETS);
58
76
  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");
77
+ if (target.kind === "branch") {
78
+ id(target.branchId, "$.target.branchId");
79
+ }
80
+ if (target.kind === "continuation") {
81
+ id(target.fromEntryId, "$.target.fromEntryId");
82
+ }
61
83
  }
62
84
 
63
85
  export function assertForkBranchCommand(value: unknown): asserts value is ForkBranchPageCommand {
@@ -77,9 +99,13 @@ export function assertForkPathPage(value: unknown): asserts value is ForkPathPag
77
99
  const floor = object(root.floor, "$.floor");
78
100
  oneOf(floor.kind, "$.floor.kind", FORK_HISTORY_PATH_FLOORS);
79
101
  exact(floor, "$.floor", variantFields("ForkPathFloorProjection", floor, "$.floor"));
80
- if (floor.kind === "anchor") id(floor.entryId, "$.floor.entryId");
102
+ if (floor.kind === "anchor") {
103
+ id(floor.entryId, "$.floor.entryId");
104
+ }
81
105
  integer(root.totalEntries, "$.totalEntries");
82
- array(root.entries, "$.entries").forEach((entry, index) => entryRecord(entry, `$.entries[${index}]`));
106
+ array(root.entries, "$.entries").forEach((entry, index) =>
107
+ entryRecord(entry, `$.entries[${index}]`),
108
+ );
83
109
  boolean(root.truncatedBefore, "$.truncatedBefore");
84
110
  boolean(root.truncatedAfter, "$.truncatedAfter");
85
111
  }
@@ -106,66 +132,220 @@ export function assertForkBranchPage(value: unknown): asserts value is ForkBranc
106
132
  boolean(root.truncatedAfter, "$.truncatedAfter");
107
133
  }
108
134
 
109
- export function assertForkNavigationCommand(value: unknown): asserts value is ForkNavigationCommand {
135
+ export function assertForkNavigationCommand(
136
+ value: unknown,
137
+ ): asserts value is ForkNavigationCommand {
110
138
  noPayload(value);
111
139
  const root = object(value, "$");
112
140
  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);
141
+ protocol(root.protocolVersion, "$.protocolVersion");
142
+ positive(root.authorityEpoch, "$.authorityEpoch");
143
+ id(root.historyId, "$.historyId");
144
+ id(root.planId, "$.planId");
145
+ integer(root.expectedRevision, "$.expectedRevision");
146
+ const target = object(root.target, "$.target");
147
+ oneOf(target.kind, "$.target.kind", FORK_HISTORY_NAVIGATION_TARGETS);
115
148
  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");
149
+ if (target.kind === "checkout") {
150
+ id(target.branchId, "$.target.branchId");
151
+ id(target.entryId, "$.target.entryId");
152
+ }
153
+ if (target.kind === "checkoutBranchRoot") {
154
+ id(target.branchId, "$.target.branchId");
155
+ }
156
+ if (target.kind === "checkoutContinuation") {
157
+ id(target.entryId, "$.target.entryId");
158
+ }
119
159
  }
120
160
 
121
161
  export function assertForkNavigationResult(value: unknown): asserts value is ForkNavigationResult {
122
162
  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"]);
163
+ const root = object(value, "$");
164
+ oneOf(root.status, "$.status", FORK_HISTORY_NAVIGATION_STATUSES);
165
+ exact(
166
+ root,
167
+ "$",
168
+ root.status === "committed"
169
+ ? ["status", "snapshot", "receipt"]
170
+ : ["status", "snapshot", "rejection"],
171
+ );
125
172
  assertForkSnapshot(root.snapshot);
126
173
  if (root.status === "committed") {
127
174
  const receipt = object(root.receipt, "$.receipt");
128
175
  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}]`));
176
+ id(receipt.historyId, "$.receipt.historyId");
177
+ id(receipt.planId, "$.receipt.planId");
178
+ integer(receipt.previousRevision, "$.receipt.previousRevision");
179
+ integer(receipt.committedRevision, "$.receipt.committedRevision");
180
+ optionalId(receipt.sourceEntryId, "$.receipt.sourceEntryId");
181
+ optionalId(receipt.targetEntryId, "$.receipt.targetEntryId");
182
+ id(receipt.targetBranchId, "$.receipt.targetBranchId");
183
+ array(receipt.movedEntryIds, "$.receipt.movedEntryIds").forEach((entry, index) =>
184
+ id(entry, `$.receipt.movedEntryIds[${index}]`),
185
+ );
130
186
  } else {
131
187
  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");
188
+ exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
189
+ oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_NAVIGATION_REJECTION_CODES);
190
+ string(rejection.detail, "$.rejection.detail");
191
+ boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
133
192
  }
134
193
  }
135
194
 
136
195
  export function assertForkChangedEvent(value: unknown): asserts value is ForkChangedEvent {
137
- noPayload(value); const root = object(value, "$");
196
+ noPayload(value);
197
+ const root = object(value, "$");
138
198
  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);
199
+ protocol(root.protocolVersion, "$.protocolVersion");
200
+ positive(root.authorityEpoch, "$.authorityEpoch");
201
+ id(root.historyId, "$.historyId");
202
+ if (root.previousRevision !== null) {
203
+ integer(root.previousRevision, "$.previousRevision");
204
+ }
205
+ integer(root.committedRevision, "$.committedRevision");
206
+ oneOf(root.kind, "$.kind", FORK_HISTORY_CHANGED_KINDS);
142
207
  }
143
208
 
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); }
209
+ function commandBase(value: unknown, allowed: ReadonlyArray<string>): void {
210
+ noPayload(value);
211
+ const root = object(value, "$");
212
+ exact(root, "$", allowed);
213
+ protocol(root.protocolVersion, "$.protocolVersion");
214
+ positive(root.authorityEpoch, "$.authorityEpoch");
215
+ id(root.historyId, "$.historyId");
216
+ integer(root.expectedRevision, "$.expectedRevision");
217
+ integer(root.offset, "$.offset");
218
+ positive(root.limit, "$.limit");
219
+ if (root.limit > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
220
+ fail("$.limit", `maximum is ${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
221
+ }
222
+ }
223
+ function snapshotBase(root: Record<string, unknown>): void {
224
+ protocol(root.protocolVersion, "$.protocolVersion");
225
+ positive(root.authorityEpoch, "$.authorityEpoch");
226
+ id(root.historyId, "$.historyId");
227
+ integer(root.revision, "$.revision");
228
+ integer(root.offset, "$.offset");
229
+ }
230
+ function entryRecord(value: unknown, path: string): void {
231
+ const root = object(value, path);
232
+ exact(root, path, HISTORY_TREE_FIELDS.ForkEntryRecord);
233
+ id(root.entryId, `${path}.entryId`);
234
+ string(root.label, `${path}.label`);
235
+ optionalId(root.kindId, `${path}.kindId`);
236
+ optionalId(root.groupId, `${path}.groupId`);
237
+ optionalInteger(root.recordedAt, `${path}.recordedAt`);
238
+ integer(root.continuationCount, `${path}.continuationCount`);
239
+ positive(root.sequence, `${path}.sequence`);
240
+ integer(root.committedRevision, `${path}.committedRevision`);
241
+ integer(root.encodedWeight, `${path}.encodedWeight`);
242
+ oneOf(root.position, `${path}.position`, FORK_HISTORY_ENTRY_POSITIONS);
243
+ }
244
+ function noPayload(value: unknown): void {
245
+ const visit = (candidate: unknown, path: string): void => {
246
+ if (Array.isArray(candidate)) {
247
+ return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
248
+ }
249
+ if (candidate !== null && typeof candidate === "object") {
250
+ for (const [key, child] of Object.entries(candidate)) {
251
+ if (key.toLocaleLowerCase().includes("payload")) {
252
+ fail(`${path}.${key}`, "product payload field is forbidden");
253
+ }
254
+ visit(child, `${path}.${key}`);
255
+ }
256
+ }
257
+ };
258
+ visit(value, "$");
259
+ }
260
+ function object(value: unknown, path: string): Record<string, unknown> {
261
+ if (!isRecord(value)) {
262
+ fail(path, "expected object");
263
+ }
264
+ return value;
265
+ }
266
+ function array(value: unknown, path: string): Array<unknown> {
267
+ if (!Array.isArray(value)) {
268
+ fail(path, "expected array");
269
+ }
270
+ return value;
271
+ }
272
+ function exact(
273
+ value: Record<string, unknown>,
274
+ path: string,
275
+ expected: ReadonlyArray<string>,
276
+ ): void {
277
+ const actual = Object.keys(value).sort();
278
+ const wanted = [...expected].sort();
279
+ if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
280
+ fail(path, `unexpected keys: ${actual.join(",")}`);
281
+ }
282
+ }
283
+ function protocol(value: unknown, path: string): void {
284
+ if (value !== FORK_HISTORY_PROTOCOL_VERSION) {
285
+ fail(path, `expected exact protocol ${FORK_HISTORY_PROTOCOL_VERSION}`);
286
+ }
287
+ }
288
+ function integer(value: unknown, path: string): asserts value is number {
289
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
290
+ fail(path, "expected non-negative safe integer");
291
+ }
292
+ }
293
+ function positive(value: unknown, path: string): asserts value is number {
294
+ integer(value, path);
295
+ if (value === 0) {
296
+ fail(path, "expected positive integer");
297
+ }
298
+ }
299
+ function string(value: unknown, path: string): asserts value is string {
300
+ if (typeof value !== "string") {
301
+ fail(path, "expected string");
302
+ }
303
+ }
304
+ function id(value: unknown, path: string): void {
305
+ string(value, path);
306
+ if (value.length === 0) {
307
+ fail(path, "expected non-empty id");
308
+ }
309
+ }
310
+ function optionalId(value: unknown, path: string): void {
311
+ if (value !== null) {
312
+ id(value, path);
313
+ }
314
+ }
315
+ function optionalString(value: unknown, path: string): void {
316
+ if (value !== null) {
317
+ string(value, path);
318
+ }
319
+ }
320
+ function optionalInteger(value: unknown, path: string): void {
321
+ if (value !== null) {
322
+ integer(value, path);
323
+ }
324
+ }
325
+ function boolean(value: unknown, path: string): void {
326
+ if (typeof value !== "boolean") {
327
+ fail(path, "expected boolean");
328
+ }
329
+ }
330
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
331
+ if (typeof value !== "string" || !values.includes(value)) {
332
+ fail(path, "unsupported value");
333
+ }
334
+ }
335
+ function fail(path: string, message: string): never {
336
+ throw new ForkHistoryValidationError(path, message);
337
+ }
162
338
 
163
- export function assertForkContinuationCommand(value: unknown): asserts value is ForkContinuationPageCommand {
339
+ export function assertForkContinuationCommand(
340
+ value: unknown,
341
+ ): asserts value is ForkContinuationPageCommand {
164
342
  commandBase(value, HISTORY_TREE_FIELDS.ForkContinuationPageCommand);
165
343
  optionalId(object(value, "$").anchorEntryId, "$.anchorEntryId");
166
344
  }
167
345
 
168
- export function assertForkContinuationPage(value: unknown): asserts value is ForkContinuationPageSnapshot {
346
+ export function assertForkContinuationPage(
347
+ value: unknown,
348
+ ): asserts value is ForkContinuationPageSnapshot {
169
349
  noPayload(value);
170
350
  const root = object(value, "$");
171
351
  exact(root, "$", HISTORY_TREE_FIELDS.ForkContinuationPageSnapshot);
@@ -194,7 +374,9 @@ export function assertForkContinuationPage(value: unknown): asserts value is For
194
374
  * silently tolerated `offset` and `limit` would accept a caller who thought
195
375
  * this was a paged read.
196
376
  */
197
- export function assertForkDeleteCommand(value: unknown): asserts value is ForkDeleteContinuationCommand {
377
+ export function assertForkDeleteCommand(
378
+ value: unknown,
379
+ ): asserts value is ForkDeleteContinuationCommand {
198
380
  noPayload(value);
199
381
  const root = object(value, "$");
200
382
  exact(root, "$", HISTORY_TREE_FIELDS.ForkDeleteContinuationCommand);
@@ -205,7 +387,9 @@ export function assertForkDeleteCommand(value: unknown): asserts value is ForkDe
205
387
  id(root.entryId, "$.entryId");
206
388
  }
207
389
 
208
- export function assertForkRemovalReceipt(value: unknown): asserts value is ForkRemovalReceiptProjection {
390
+ export function assertForkRemovalReceipt(
391
+ value: unknown,
392
+ ): asserts value is ForkRemovalReceiptProjection {
209
393
  noPayload(value);
210
394
  const root = object(value, "$");
211
395
  exact(root, "$", HISTORY_TREE_FIELDS.ForkRemovalReceiptProjection);
@@ -222,8 +406,12 @@ export function assertForkRemovalReceipt(value: unknown): asserts value is ForkR
222
406
  positive(entry.sequence, `${at}.sequence`);
223
407
  integer(entry.encodedWeight, `${at}.encodedWeight`);
224
408
  });
225
- array(root.removedBranches, "$.removedBranches").forEach((branch, index) => id(branch, `$.removedBranches[${index}]`));
226
- array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) => id(checkpoint, `$.removedCheckpoints[${index}]`));
409
+ array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
410
+ id(branch, `$.removedBranches[${index}]`),
411
+ );
412
+ array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) =>
413
+ id(checkpoint, `$.removedCheckpoints[${index}]`),
414
+ );
227
415
  integer(root.retainedEntryCount, "$.retainedEntryCount");
228
416
  integer(root.retainedEncodedWeight, "$.retainedEncodedWeight");
229
417
  integer(root.unprotectedEntryCount, "$.unprotectedEntryCount");
@@ -249,7 +437,9 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
249
437
  const root = object(value, "$");
250
438
  oneOf(root.status, "$.status", FORK_HISTORY_PRUNE_STATUSES);
251
439
  exact(root, "$", variantFields("ForkPruneResult", root, "$"));
252
- if (root.status === "pruned") assertForkRemovalReceipt(root.receipt);
440
+ if (root.status === "pruned") {
441
+ assertForkRemovalReceipt(root.receipt);
442
+ }
253
443
  }
254
444
 
255
445
  /**
@@ -261,9 +451,18 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
261
451
  * loudly beats defaulting to a key list, which is how `checkoutBranchRoot`
262
452
  * shipped rejecting its own `branchId`.
263
453
  */
264
- function variantFields(type: string, object: Record<string, unknown>, path: string): readonly string[] {
454
+ function variantFields(
455
+ type: string,
456
+ object: Record<string, unknown>,
457
+ path: string,
458
+ ): ReadonlyArray<string> {
265
459
  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)}`);
460
+ const fields =
461
+ typeof discriminant === "string"
462
+ ? HISTORY_TREE_VARIANT_FIELDS[type]?.[discriminant]
463
+ : undefined;
464
+ if (fields === undefined) {
465
+ fail(path, `no generated fields for ${type}.${String(discriminant)}`);
466
+ }
268
467
  return fields;
269
468
  }
@@ -26,7 +26,7 @@ export type SurfaceRevision = number;
26
26
 
27
27
  export type LayoutRatio = number;
28
28
 
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, };
29
+ 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
30
 
31
31
  export type EmptyRegionPolicy = "keep_visible" | "hide_when_empty";
32
32
 
@@ -38,7 +38,7 @@ export type LayoutSchemaDefinition = { id: LayoutSchemaId, regions: Array<Region
38
38
 
39
39
  export type PlacementSelector = { "kind": "region", "id": RegionId } | { "kind": "family", "id": RegionFamilyId };
40
40
 
41
- export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_container" } | { "kind": "bounded",
41
+ export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_surface" } | { "kind": "bounded",
42
42
  /**
43
43
  * Maximum instances in the complete document.
44
44
  */
@@ -3,11 +3,7 @@ import type { LayoutRatio } from "./generated/protocol.ts";
3
3
  export const LAYOUT_RATIO_ONE_MILLIONTHS = 1_000_000;
4
4
 
5
5
  export function layoutRatioFromMillionths(value: number): LayoutRatio {
6
- if (
7
- !Number.isSafeInteger(value) ||
8
- value < 0 ||
9
- value > LAYOUT_RATIO_ONE_MILLIONTHS
10
- ) {
6
+ if (!Number.isSafeInteger(value) || value < 0 || value > LAYOUT_RATIO_ONE_MILLIONTHS) {
11
7
  throw new RangeError(
12
8
  `layout ratio must be an integer from 0 through ${LAYOUT_RATIO_ONE_MILLIONTHS}; received ${String(value)}`,
13
9
  );
@@ -16,7 +12,5 @@ export function layoutRatioFromMillionths(value: number): LayoutRatio {
16
12
  }
17
13
 
18
14
  export function layoutRatioToUnitInterval(value: LayoutRatio): number {
19
- return (
20
- layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS
21
- );
15
+ return layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS;
22
16
  }
@@ -3,9 +3,11 @@ import {
3
3
  LAYOUT_MUTATION_OUTCOME_KINDS,
4
4
  LAYOUT_MUTATION_REJECTION_CODES,
5
5
  LAYOUT_PROTOCOL_VERSION,
6
- type LayoutMutationCommand,
7
- type LayoutMutationOutcome,
8
- type LayoutMutationRejectionCode,
6
+ } from "./generated/protocol.ts";
7
+ import type {
8
+ LayoutMutationCommand,
9
+ LayoutMutationOutcome,
10
+ LayoutMutationRejectionCode,
9
11
  } from "./generated/protocol.ts";
10
12
 
11
13
  export type LayoutProtocolValidationCode =
@@ -30,10 +32,7 @@ export function assertLayoutProtocolVersion(
30
32
  version: unknown,
31
33
  ): asserts version is typeof LAYOUT_PROTOCOL_VERSION {
32
34
  if (version !== LAYOUT_PROTOCOL_VERSION) {
33
- throw new LayoutProtocolValidationError(
34
- "unsupported_protocol_version",
35
- version,
36
- );
35
+ throw new LayoutProtocolValidationError("unsupported_protocol_version", version);
37
36
  }
38
37
  }
39
38
 
@@ -54,20 +53,15 @@ export function assertValidLayoutMutationRejectionCode(
54
53
  ): asserts value is LayoutMutationRejectionCode {
55
54
  if (
56
55
  typeof value !== "string" ||
57
- !LAYOUT_MUTATION_REJECTION_CODES.includes(
58
- value as (typeof LAYOUT_MUTATION_REJECTION_CODES)[number],
59
- )
56
+ !LAYOUT_MUTATION_REJECTION_CODES.some((code) => code === value)
60
57
  ) {
61
- throw new LayoutProtocolValidationError(
62
- "unknown_rejection_code",
63
- value,
64
- );
58
+ throw new LayoutProtocolValidationError("unknown_rejection_code", value);
65
59
  }
66
60
  }
67
61
 
68
62
  function assertKnownKind(
69
63
  value: unknown,
70
- known: readonly string[],
64
+ known: ReadonlyArray<string>,
71
65
  code: "unknown_command" | "unknown_outcome",
72
66
  ): asserts value is Record<"kind", string> {
73
67
  if (
@@ -81,10 +75,7 @@ function assertKnownKind(
81
75
  }
82
76
  }
83
77
 
84
- function message(
85
- code: LayoutProtocolValidationCode,
86
- received: unknown,
87
- ): string {
78
+ function message(code: LayoutProtocolValidationCode, received: unknown): string {
88
79
  switch (code) {
89
80
  case "unsupported_protocol_version":
90
81
  return `unsupported layout protocol version ${String(received)}; expected ${LAYOUT_PROTOCOL_VERSION}`;
@@ -18,8 +18,7 @@ export function projectOrdinaryRegionVisibility(
18
18
  return {
19
19
  region_id: definition.id,
20
20
  state:
21
- state.panel_instance_ids.length > 0 ||
22
- definition.empty_policy === "keep_visible"
21
+ state.panel_instance_ids.length > 0 || definition.empty_policy === "keep_visible"
23
22
  ? "visible"
24
23
  : "hidden",
25
24
  };
@@ -22,11 +22,48 @@ import {
22
22
 
23
23
  export class LicenceClient implements CheckedLicencePort {
24
24
  constructor(readonly port: LicencePort) {}
25
- async snapshot(): Promise<LicenceSnapshot> { const value = await this.port.snapshot(); assertLicenceSnapshot(value); return value; }
26
- async activate(command: LicenceActivateCommand): Promise<LicenceOutcomeProjection> { assertLicenceActivateCommand(command); const value = await this.port.activate(command); assertLicenceOutcome(value); return value; }
27
- async deactivate(command: LicenceDeactivateCommand): Promise<LicenceOutcomeProjection> { assertLicenceDeactivateCommand(command); const value = await this.port.deactivate(command); assertLicenceOutcome(value); return value; }
28
- async refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection> { assertLicenceRefreshCommand(command); const value = await this.port.refresh(command); assertLicenceOutcome(value); return value; }
29
- async releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection> { assertLicenceReleaseSeatCommand(command); const value = await this.port.releaseSeat(command); assertLicenceOutcome(value); return value; }
30
- async renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection> { assertLicenceRenameSeatCommand(command); const value = await this.port.renameSeat(command); assertLicenceOutcome(value); return value; }
31
- async listen(listener: (event: LicenceChangedEvent) => void): Promise<LicenceUnlisten> { if (this.port.listen === undefined) return () => {}; return this.port.listen((value) => { assertLicenceChangedEvent(value); listener(value); }); }
25
+ async snapshot(): Promise<LicenceSnapshot> {
26
+ const value = await this.port.snapshot();
27
+ assertLicenceSnapshot(value);
28
+ return value;
29
+ }
30
+ async activate(command: LicenceActivateCommand): Promise<LicenceOutcomeProjection> {
31
+ assertLicenceActivateCommand(command);
32
+ const value = await this.port.activate(command);
33
+ assertLicenceOutcome(value);
34
+ return value;
35
+ }
36
+ async deactivate(command: LicenceDeactivateCommand): Promise<LicenceOutcomeProjection> {
37
+ assertLicenceDeactivateCommand(command);
38
+ const value = await this.port.deactivate(command);
39
+ assertLicenceOutcome(value);
40
+ return value;
41
+ }
42
+ async refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection> {
43
+ assertLicenceRefreshCommand(command);
44
+ const value = await this.port.refresh(command);
45
+ assertLicenceOutcome(value);
46
+ return value;
47
+ }
48
+ async releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection> {
49
+ assertLicenceReleaseSeatCommand(command);
50
+ const value = await this.port.releaseSeat(command);
51
+ assertLicenceOutcome(value);
52
+ return value;
53
+ }
54
+ async renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection> {
55
+ assertLicenceRenameSeatCommand(command);
56
+ const value = await this.port.renameSeat(command);
57
+ assertLicenceOutcome(value);
58
+ return value;
59
+ }
60
+ async listen(listener: (event: LicenceChangedEvent) => void): Promise<LicenceUnlisten> {
61
+ if (this.port.listen === undefined) {
62
+ return () => {};
63
+ }
64
+ return this.port.listen((value) => {
65
+ assertLicenceChangedEvent(value);
66
+ listener(value);
67
+ });
68
+ }
32
69
  }