@inflatable-cookie/longhorn 0.5.0 → 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,3 +1,4 @@
1
+ import { isRecord } from "../core/record.ts";
1
2
  import {
2
3
  HISTORY_MAXIMUM_OPAQUE_ID_BYTES,
3
4
  HISTORY_CHANGED_KINDS,
@@ -9,12 +10,14 @@ import {
9
10
  HISTORY_NAVIGATION_STATUSES,
10
11
  HISTORY_NAVIGATION_TARGETS,
11
12
  HISTORY_PROTOCOL_VERSION,
12
- type HistoryChangedEvent,
13
- type HistoryNavigationCommand,
14
- type HistoryNavigationResult,
15
- type HistoryPageCommand,
16
- type HistoryPageSnapshot,
17
- type HistorySnapshot,
13
+ } from "./generated/protocol.ts";
14
+ import type {
15
+ HistoryChangedEvent,
16
+ HistoryNavigationCommand,
17
+ HistoryNavigationResult,
18
+ HistoryPageCommand,
19
+ HistoryPageSnapshot,
20
+ HistorySnapshot,
18
21
  } from "./generated/protocol.ts";
19
22
  import { HISTORY_FIELDS } from "./generated/fields.ts";
20
23
  import {
@@ -23,15 +26,16 @@ import {
23
26
  } from "./generated/variant-fields.ts";
24
27
 
25
28
  export class HistoryProtocolValidationError extends Error {
26
- constructor(readonly path: string, message: string) {
29
+ constructor(
30
+ readonly path: string,
31
+ message: string,
32
+ ) {
27
33
  super(`${path}: ${message}`);
28
34
  this.name = "HistoryProtocolValidationError";
29
35
  }
30
36
  }
31
37
 
32
- export function assertValidHistorySnapshot(
33
- value: unknown,
34
- ): asserts value is HistorySnapshot {
38
+ export function assertValidHistorySnapshot(value: unknown): asserts value is HistorySnapshot {
35
39
  assertNoPayload(value, "$");
36
40
  const record = object(value, "$");
37
41
  keys(record, "$", HISTORY_FIELDS.HistorySnapshot);
@@ -40,9 +44,7 @@ export function assertValidHistorySnapshot(
40
44
  summary(record.summary, "$.summary");
41
45
  }
42
46
 
43
- export function assertValidHistoryPageCommand(
44
- value: unknown,
45
- ): asserts value is HistoryPageCommand {
47
+ export function assertValidHistoryPageCommand(value: unknown): asserts value is HistoryPageCommand {
46
48
  assertNoPayload(value, "$");
47
49
  const record = object(value, "$");
48
50
  keys(record, "$", HISTORY_FIELDS.HistoryPageCommand);
@@ -173,10 +175,7 @@ function receipt(value: unknown, path: string): void {
173
175
  id(entry, `${path}.movedEntryIds[${index}]`),
174
176
  );
175
177
  navigationPosition(record.sourcePosition, `${path}.sourcePosition`);
176
- navigationPosition(
177
- record.authoritativePosition,
178
- `${path}.authoritativePosition`,
179
- );
178
+ navigationPosition(record.authoritativePosition, `${path}.authoritativePosition`);
180
179
  }
181
180
 
182
181
  function navigationPosition(value: unknown, path: string): void {
@@ -193,11 +192,7 @@ function navigationPosition(value: unknown, path: string): void {
193
192
  function rejection(value: unknown, path: string): void {
194
193
  const record = object(value, path);
195
194
  keys(record, path, HISTORY_FIELDS.HistoryNavigationRejectionProjection);
196
- oneOf(
197
- record.code,
198
- `${path}.code`,
199
- HISTORY_NAVIGATION_REJECTION_CODES,
200
- );
195
+ oneOf(record.code, `${path}.code`, HISTORY_NAVIGATION_REJECTION_CODES);
201
196
  string(record.detail, `${path}.detail`);
202
197
  boolean(record.refreshRequired, `${path}.refreshRequired`);
203
198
  }
@@ -209,36 +204,34 @@ function protocol(value: unknown, path: string): void {
209
204
  }
210
205
 
211
206
  function object(value: unknown, path: string): Record<string, unknown> {
212
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
207
+ if (!isRecord(value)) {
213
208
  fail(path, "expected object");
214
209
  }
215
- return value as Record<string, unknown>;
210
+ return value;
216
211
  }
217
212
 
218
- function array(value: unknown, path: string): readonly unknown[] {
219
- if (!Array.isArray(value)) fail(path, "expected array");
213
+ function array(value: unknown, path: string): ReadonlyArray<unknown> {
214
+ if (!Array.isArray(value)) {
215
+ fail(path, "expected array");
216
+ }
220
217
  return value;
221
218
  }
222
219
 
223
- function keys(
224
- value: Record<string, unknown>,
225
- path: string,
226
- allowed: readonly string[],
227
- ): void {
220
+ function keys(value: Record<string, unknown>, path: string, allowed: ReadonlyArray<string>): void {
228
221
  const allowedSet = new Set(allowed);
229
222
  for (const key of Object.keys(value)) {
230
- if (!allowedSet.has(key)) fail(`${path}.${key}`, "unknown field");
223
+ if (!allowedSet.has(key)) {
224
+ fail(`${path}.${key}`, "unknown field");
225
+ }
231
226
  }
232
227
  for (const key of allowed) {
233
- if (!(key in value)) fail(`${path}.${key}`, "missing field");
228
+ if (!(key in value)) {
229
+ fail(`${path}.${key}`, "missing field");
230
+ }
234
231
  }
235
232
  }
236
233
 
237
- function oneOf(
238
- value: unknown,
239
- path: string,
240
- values: readonly string[],
241
- ): void {
234
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
242
235
  if (typeof value !== "string" || !values.includes(value)) {
243
236
  fail(path, `expected one of ${values.join(", ")}`);
244
237
  }
@@ -247,45 +240,55 @@ function oneOf(
247
240
  function id(value: unknown, path: string): void {
248
241
  string(value, path);
249
242
  if (
250
- (value as string).length === 0 ||
251
- (value as string).length > HISTORY_MAXIMUM_OPAQUE_ID_BYTES ||
252
- !/^[a-z0-9._:-]+$/.test(value as string)
243
+ value.length === 0 ||
244
+ value.length > HISTORY_MAXIMUM_OPAQUE_ID_BYTES ||
245
+ !/^[a-z0-9._:-]+$/.test(value)
253
246
  ) {
254
247
  fail(path, "expected bounded lowercase opaque id");
255
248
  }
256
249
  }
257
250
 
258
251
  function optionalId(value: unknown, path: string): void {
259
- if (value !== null) id(value, path);
252
+ if (value !== null) {
253
+ id(value, path);
254
+ }
260
255
  }
261
256
 
262
- function string(value: unknown, path: string): void {
257
+ function string(value: unknown, path: string): asserts value is string {
263
258
  if (typeof value !== "string" || value.length === 0) {
264
259
  fail(path, "expected nonempty string");
265
260
  }
266
261
  }
267
262
 
268
263
  function optionalString(value: unknown, path: string): void {
269
- if (value !== null) string(value, path);
264
+ if (value !== null) {
265
+ string(value, path);
266
+ }
270
267
  }
271
268
 
272
- function integer(value: unknown, path: string): void {
273
- if (!Number.isSafeInteger(value) || (value as number) < 0) {
269
+ function integer(value: unknown, path: string): asserts value is number {
270
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
274
271
  fail(path, "expected nonnegative safe integer");
275
272
  }
276
273
  }
277
274
 
278
275
  function positiveInteger(value: unknown, path: string): void {
279
276
  integer(value, path);
280
- if ((value as number) === 0) fail(path, "expected nonzero integer");
277
+ if (value === 0) {
278
+ fail(path, "expected nonzero integer");
279
+ }
281
280
  }
282
281
 
283
282
  function optionalInteger(value: unknown, path: string): void {
284
- if (value !== null) integer(value, path);
283
+ if (value !== null) {
284
+ integer(value, path);
285
+ }
285
286
  }
286
287
 
287
288
  function boolean(value: unknown, path: string): void {
288
- if (typeof value !== "boolean") fail(path, "expected boolean");
289
+ if (typeof value !== "boolean") {
290
+ fail(path, "expected boolean");
291
+ }
289
292
  }
290
293
 
291
294
  function assertNoPayload(value: unknown, path: string): void {
@@ -293,9 +296,13 @@ function assertNoPayload(value: unknown, path: string): void {
293
296
  value.forEach((entry, index) => assertNoPayload(entry, `${path}[${index}]`));
294
297
  return;
295
298
  }
296
- if (typeof value !== "object" || value === null) return;
299
+ if (typeof value !== "object" || value === null) {
300
+ return;
301
+ }
297
302
  for (const [key, child] of Object.entries(value)) {
298
- if (key === "payload") fail(`${path}.payload`, "product payload is forbidden");
303
+ if (key === "payload") {
304
+ fail(`${path}.payload`, "product payload is forbidden");
305
+ }
299
306
  assertNoPayload(child, `${path}.${key}`);
300
307
  }
301
308
  }
@@ -316,7 +323,9 @@ function floor(value: unknown, path: string): void {
316
323
  const record = object(value, path);
317
324
  oneOf(record.kind, `${path}.kind`, HISTORY_PAGE_FLOORS);
318
325
  keys(record, path, variantKeys("HistoryPageFloorProjection", record, path));
319
- if (record.kind === "baseline") integer(record.prunedEntryCount, `${path}.prunedEntryCount`);
326
+ if (record.kind === "baseline") {
327
+ integer(record.prunedEntryCount, `${path}.prunedEntryCount`);
328
+ }
320
329
  }
321
330
 
322
331
  /**
@@ -326,9 +335,16 @@ function floor(value: unknown, path: string): void {
326
335
  * A missing entry means the generator failed to read the union: every caller
327
336
  * checks the discriminant above this call.
328
337
  */
329
- function variantKeys(type: string, record: Record<string, unknown>, path: string): readonly string[] {
338
+ function variantKeys(
339
+ type: string,
340
+ record: Record<string, unknown>,
341
+ path: string,
342
+ ): ReadonlyArray<string> {
330
343
  const discriminant = record[HISTORY_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
331
- const allowed = HISTORY_VARIANT_FIELDS[type]?.[discriminant as string];
332
- if (allowed === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
344
+ const allowed =
345
+ typeof discriminant === "string" ? HISTORY_VARIANT_FIELDS[type]?.[discriminant] : undefined;
346
+ if (allowed === undefined) {
347
+ fail(path, `no generated fields for ${type}.${String(discriminant)}`);
348
+ }
333
349
  return allowed;
334
350
  }
@@ -1,16 +1,92 @@
1
- import { assertForkBranchCommand, assertForkBranchPage, assertForkContinuationCommand, assertForkContinuationPage, assertForkDeleteCommand, assertForkPruneCommand, assertForkPruneResult, assertForkRemovalReceipt, assertForkChangedEvent, assertForkNavigationCommand, assertForkNavigationResult, assertForkPathCommand, assertForkPathPage, assertForkSnapshot } from "./validation.ts";
2
- import type { ForkBranchPageCommand, ForkBranchPageSnapshot, ForkChangedEvent, ForkContinuationPageCommand, ForkContinuationPageSnapshot, ForkDeleteContinuationCommand, ForkPruneCommand, ForkPruneResult, ForkRemovalReceiptProjection, ForkNavigationCommand, ForkNavigationResult, ForkPathPageCommand, ForkPathPageSnapshot, ForkSnapshot } from "./generated/protocol.ts";
1
+ import {
2
+ assertForkBranchCommand,
3
+ assertForkBranchPage,
4
+ assertForkContinuationCommand,
5
+ assertForkContinuationPage,
6
+ assertForkDeleteCommand,
7
+ assertForkPruneCommand,
8
+ assertForkPruneResult,
9
+ assertForkRemovalReceipt,
10
+ assertForkChangedEvent,
11
+ assertForkNavigationCommand,
12
+ assertForkNavigationResult,
13
+ assertForkPathCommand,
14
+ assertForkPathPage,
15
+ assertForkSnapshot,
16
+ } from "./validation.ts";
17
+ import type {
18
+ ForkBranchPageCommand,
19
+ ForkBranchPageSnapshot,
20
+ ForkChangedEvent,
21
+ ForkContinuationPageCommand,
22
+ ForkContinuationPageSnapshot,
23
+ ForkDeleteContinuationCommand,
24
+ ForkPruneCommand,
25
+ ForkPruneResult,
26
+ ForkRemovalReceiptProjection,
27
+ ForkNavigationCommand,
28
+ ForkNavigationResult,
29
+ ForkPathPageCommand,
30
+ ForkPathPageSnapshot,
31
+ ForkSnapshot,
32
+ } from "./generated/protocol.ts";
3
33
  import type { CheckedForkHistoryPort, ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
4
34
 
5
35
  export class ForkHistoryClient implements CheckedForkHistoryPort {
6
36
  constructor(readonly port: ForkHistoryPort) {}
7
- nextPlanId(): string { return this.port.nextPlanId(); }
8
- async snapshot(): Promise<ForkSnapshot> { const value = await this.port.snapshot(); assertForkSnapshot(value); return value; }
9
- async path(command: ForkPathPageCommand): Promise<ForkPathPageSnapshot> { assertForkPathCommand(command); const value = await this.port.path(command); assertForkPathPage(value); return value; }
10
- async branches(command: ForkBranchPageCommand): Promise<ForkBranchPageSnapshot> { assertForkBranchCommand(command); const value = await this.port.branches(command); assertForkBranchPage(value); return value; }
11
- async continuations(command: ForkContinuationPageCommand): Promise<ForkContinuationPageSnapshot> { assertForkContinuationCommand(command); const value = await this.port.continuations(command); assertForkContinuationPage(value); return value; }
12
- async deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkRemovalReceiptProjection> { assertForkDeleteCommand(command); const value = await this.port.deleteContinuation(command); assertForkRemovalReceipt(value); return value; }
13
- async prune(command: ForkPruneCommand): Promise<ForkPruneResult> { assertForkPruneCommand(command); const value = await this.port.prune(command); assertForkPruneResult(value); return value; }
14
- async navigate(command: ForkNavigationCommand): Promise<ForkNavigationResult> { assertForkNavigationCommand(command); const value = await this.port.navigate(command); assertForkNavigationResult(value); return value; }
15
- async listen(listener: (event: ForkChangedEvent) => void): Promise<ForkHistoryUnlisten> { if (this.port.listen === undefined) return () => {}; return this.port.listen((value) => { assertForkChangedEvent(value); listener(value); }); }
37
+ nextPlanId(): string {
38
+ return this.port.nextPlanId();
39
+ }
40
+ async snapshot(): Promise<ForkSnapshot> {
41
+ const value = await this.port.snapshot();
42
+ assertForkSnapshot(value);
43
+ return value;
44
+ }
45
+ async path(command: ForkPathPageCommand): Promise<ForkPathPageSnapshot> {
46
+ assertForkPathCommand(command);
47
+ const value = await this.port.path(command);
48
+ assertForkPathPage(value);
49
+ return value;
50
+ }
51
+ async branches(command: ForkBranchPageCommand): Promise<ForkBranchPageSnapshot> {
52
+ assertForkBranchCommand(command);
53
+ const value = await this.port.branches(command);
54
+ assertForkBranchPage(value);
55
+ return value;
56
+ }
57
+ async continuations(command: ForkContinuationPageCommand): Promise<ForkContinuationPageSnapshot> {
58
+ assertForkContinuationCommand(command);
59
+ const value = await this.port.continuations(command);
60
+ assertForkContinuationPage(value);
61
+ return value;
62
+ }
63
+ async deleteContinuation(
64
+ command: ForkDeleteContinuationCommand,
65
+ ): Promise<ForkRemovalReceiptProjection> {
66
+ assertForkDeleteCommand(command);
67
+ const value = await this.port.deleteContinuation(command);
68
+ assertForkRemovalReceipt(value);
69
+ return value;
70
+ }
71
+ async prune(command: ForkPruneCommand): Promise<ForkPruneResult> {
72
+ assertForkPruneCommand(command);
73
+ const value = await this.port.prune(command);
74
+ assertForkPruneResult(value);
75
+ return value;
76
+ }
77
+ async navigate(command: ForkNavigationCommand): Promise<ForkNavigationResult> {
78
+ assertForkNavigationCommand(command);
79
+ const value = await this.port.navigate(command);
80
+ assertForkNavigationResult(value);
81
+ return value;
82
+ }
83
+ async listen(listener: (event: ForkChangedEvent) => void): Promise<ForkHistoryUnlisten> {
84
+ if (this.port.listen === undefined) {
85
+ return () => {};
86
+ }
87
+ return this.port.listen((value) => {
88
+ assertForkChangedEvent(value);
89
+ listener(value);
90
+ });
91
+ }
16
92
  }