@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,3 +1,4 @@
1
+ import { wireCopy } from "../core/wire-copy.ts";
1
2
  import type {
2
3
  UpdateApplyCommand,
3
4
  UpdateCancelCommand,
@@ -9,14 +10,37 @@ import type {
9
10
  import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
10
11
  export class SerializedUpdatePort implements UpdatePort {
11
12
  constructor(readonly inner: UpdatePort) {}
12
- async snapshot(): Promise<unknown> { return clone(await this.inner.snapshot()); }
13
- async check(command: UpdateCheckCommand): Promise<unknown> { return clone(await this.inner.check(clone(command))); }
14
- async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> { return clone(await this.inner.selectChannel(clone(command))); }
15
- async defer(command: UpdateDeferCommand): Promise<unknown> { return clone(await this.inner.defer(clone(command))); }
16
- async prepare(command: UpdatePrepareCommand): Promise<unknown> { return clone(await this.inner.prepare(clone(command))); }
17
- async apply(command: UpdateApplyCommand): Promise<unknown> { return clone(await this.inner.apply(clone(command))); }
18
- async cancel(command: UpdateCancelCommand): Promise<unknown> { return clone(await this.inner.cancel(clone(command))); }
19
- async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listen === undefined) return () => {}; return this.inner.listen((event) => listener(clone(event))); }
20
- async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listenProgress === undefined) return () => {}; return this.inner.listenProgress((event) => listener(clone(event))); }
13
+ async snapshot(): Promise<unknown> {
14
+ return wireCopy(await this.inner.snapshot());
15
+ }
16
+ async check(command: UpdateCheckCommand): Promise<unknown> {
17
+ return wireCopy(await this.inner.check(wireCopy(command)));
18
+ }
19
+ async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> {
20
+ return wireCopy(await this.inner.selectChannel(wireCopy(command)));
21
+ }
22
+ async defer(command: UpdateDeferCommand): Promise<unknown> {
23
+ return wireCopy(await this.inner.defer(wireCopy(command)));
24
+ }
25
+ async prepare(command: UpdatePrepareCommand): Promise<unknown> {
26
+ return wireCopy(await this.inner.prepare(wireCopy(command)));
27
+ }
28
+ async apply(command: UpdateApplyCommand): Promise<unknown> {
29
+ return wireCopy(await this.inner.apply(wireCopy(command)));
30
+ }
31
+ async cancel(command: UpdateCancelCommand): Promise<unknown> {
32
+ return wireCopy(await this.inner.cancel(wireCopy(command)));
33
+ }
34
+ async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
35
+ if (this.inner.listen === undefined) {
36
+ return () => {};
37
+ }
38
+ return this.inner.listen((event) => listener(wireCopy(event)));
39
+ }
40
+ async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
41
+ if (this.inner.listenProgress === undefined) {
42
+ return () => {};
43
+ }
44
+ return this.inner.listenProgress((event) => listener(wireCopy(event)));
45
+ }
21
46
  }
22
- function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "../core/record.ts";
1
2
  import { UPDATE_FIELDS } from "./generated/fields.ts";
2
3
  import {
3
4
  UPDATE_AVAILABILITY_STATES,
@@ -11,17 +12,19 @@ import {
11
12
  UPDATE_PROGRESS_STATES,
12
13
  UPDATE_PROTOCOL_VERSION,
13
14
  UPDATE_REJECTION_CODES,
14
- type UpdateApplyCommand,
15
- type UpdateCancelCommand,
16
- type UpdateChangedEvent,
17
- type UpdateCheckCommand,
18
- type UpdateDeferCommand,
19
- type UpdateInstallAuthorizationProjection,
20
- type UpdateOutcomeProjection,
21
- type UpdatePrepareCommand,
22
- type UpdateProgressEvent,
23
- type UpdateSelectChannelCommand,
24
- type UpdateSnapshot,
15
+ } from "./generated/protocol.ts";
16
+ import type {
17
+ UpdateApplyCommand,
18
+ UpdateCancelCommand,
19
+ UpdateChangedEvent,
20
+ UpdateCheckCommand,
21
+ UpdateDeferCommand,
22
+ UpdateInstallAuthorizationProjection,
23
+ UpdateOutcomeProjection,
24
+ UpdatePrepareCommand,
25
+ UpdateProgressEvent,
26
+ UpdateSelectChannelCommand,
27
+ UpdateSnapshot,
25
28
  } from "./generated/protocol.ts";
26
29
  import {
27
30
  UPDATE_VARIANT_FIELDS,
@@ -68,7 +71,9 @@ export function assertUpdateOutcome(value: unknown): asserts value is UpdateOutc
68
71
  const root = object(value, "$");
69
72
  oneOf(root.status, "$.status", UPDATE_OUTCOME_STATUSES);
70
73
  exact(root, "$", variantFields("UpdateOutcomeProjection", root, "$"));
71
- if (root.status === "rejected") oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
74
+ if (root.status === "rejected") {
75
+ oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
76
+ }
72
77
  assertUpdateSnapshot(root.snapshot);
73
78
  }
74
79
 
@@ -106,7 +111,9 @@ export function assertUpdatePrepareCommand(value: unknown): asserts value is Upd
106
111
 
107
112
  export function assertUpdateApplyCommand(value: unknown): asserts value is UpdateApplyCommand {
108
113
  commandBase(value, UPDATE_FIELDS.UpdateApplyCommand);
109
- version(object(value, "$").version, "$.version");
114
+ const root = object(value, "$");
115
+ version(root.version, "$.version");
116
+ digest(root.digest, "$.digest");
110
117
  }
111
118
 
112
119
  export function assertUpdateCancelCommand(value: unknown): asserts value is UpdateCancelCommand {
@@ -138,7 +145,9 @@ export function assertUpdateInstallAuthorization(
138
145
  const root = object(value, "$");
139
146
  oneOf(root.status, "$.status", UPDATE_INSTALL_AUTHORIZATION_STATUSES);
140
147
  exact(root, "$", variantFields("UpdateInstallAuthorizationProjection", root, "$"));
141
- if (root.status === "deferred") cause(root.cause, "$.cause");
148
+ if (root.status === "deferred") {
149
+ cause(root.cause, "$.cause");
150
+ }
142
151
  }
143
152
 
144
153
  function availability(value: unknown, path: string): void {
@@ -158,7 +167,9 @@ function availability(value: unknown, path: string): void {
158
167
  version(root.installed, `${path}.installed`);
159
168
  version(root.channel, `${path}.channel`);
160
169
  }
161
- if (root.state === "withheldByRollout") version(root.version, `${path}.version`);
170
+ if (root.state === "withheldByRollout") {
171
+ version(root.version, `${path}.version`);
172
+ }
162
173
  if (root.state === "managedElsewhere") {
163
174
  version(root.version, `${path}.version`);
164
175
  oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
@@ -194,7 +205,7 @@ function cause(value: unknown, path: string): void {
194
205
  }
195
206
  }
196
207
 
197
- function commandBase(value: unknown, expected: readonly string[]): void {
208
+ function commandBase(value: unknown, expected: ReadonlyArray<string>): void {
198
209
  noPayload(value);
199
210
  const root = object(value, "$");
200
211
  exact(root, "$", expected);
@@ -213,35 +224,104 @@ function variantFields(
213
224
  type: string,
214
225
  value: Record<string, unknown>,
215
226
  path: string,
216
- ): readonly string[] {
227
+ ): ReadonlyArray<string> {
217
228
  const discriminant = value[UPDATE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
218
- const fields = UPDATE_VARIANT_FIELDS[type]?.[discriminant as string];
219
- if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
229
+ const fields =
230
+ typeof discriminant === "string" ? UPDATE_VARIANT_FIELDS[type]?.[discriminant] : undefined;
231
+ if (fields === undefined) {
232
+ fail(path, `no generated fields for ${type}.${String(discriminant)}`);
233
+ }
220
234
  return fields;
221
235
  }
222
236
 
223
237
  function noPayload(value: unknown): void {
224
238
  const visit = (candidate: unknown, path: string): void => {
225
- if (Array.isArray(candidate)) return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
226
- if (candidate !== null && typeof candidate === "object")
239
+ if (Array.isArray(candidate)) {
240
+ return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
241
+ }
242
+ if (candidate !== null && typeof candidate === "object") {
227
243
  for (const [key, child] of Object.entries(candidate)) {
228
- if (key.toLocaleLowerCase().includes("payload")) fail(`${path}.${key}`, "product payload field is forbidden");
244
+ if (key.toLocaleLowerCase().includes("payload")) {
245
+ fail(`${path}.${key}`, "product payload field is forbidden");
246
+ }
229
247
  visit(child, `${path}.${key}`);
230
248
  }
249
+ }
231
250
  };
232
251
  visit(value, "$");
233
252
  }
234
- 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>; }
235
- 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(",")}`); }
236
- function protocol(value: unknown, path: string): void { if (value !== UPDATE_PROTOCOL_VERSION) fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`); }
237
- function positive(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail(path, "expected positive safe integer"); }
238
- function count(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected a non-negative safe byte count"); }
239
- function optionalCount(value: unknown, path: string): void { if (value !== null) count(value, path); }
240
- function digest(value: unknown, path: string): void { if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) fail(path, "expected 64 lowercase hex digits"); }
241
- function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
242
- function optionalString(value: unknown, path: string): void { if (value !== null) string(value, path); }
253
+ function object(value: unknown, path: string): Record<string, unknown> {
254
+ if (!isRecord(value)) {
255
+ fail(path, "expected object");
256
+ }
257
+ return value;
258
+ }
259
+ function exact(
260
+ value: Record<string, unknown>,
261
+ path: string,
262
+ expected: ReadonlyArray<string>,
263
+ ): void {
264
+ const actual = Object.keys(value).sort();
265
+ const wanted = [...expected].sort();
266
+ if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
267
+ fail(path, `unexpected keys: ${actual.join(",")}`);
268
+ }
269
+ }
270
+ function protocol(value: unknown, path: string): void {
271
+ if (value !== UPDATE_PROTOCOL_VERSION) {
272
+ fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`);
273
+ }
274
+ }
275
+ function positive(value: unknown, path: string): void {
276
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
277
+ fail(path, "expected positive safe integer");
278
+ }
279
+ }
280
+ function count(value: unknown, path: string): void {
281
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
282
+ fail(path, "expected a non-negative safe byte count");
283
+ }
284
+ }
285
+ function optionalCount(value: unknown, path: string): void {
286
+ if (value !== null) {
287
+ count(value, path);
288
+ }
289
+ }
290
+ function digest(value: unknown, path: string): void {
291
+ if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
292
+ fail(path, "expected 64 lowercase hex digits");
293
+ }
294
+ }
295
+ function string(value: unknown, path: string): asserts value is string {
296
+ if (typeof value !== "string") {
297
+ fail(path, "expected string");
298
+ }
299
+ }
300
+ function optionalString(value: unknown, path: string): void {
301
+ if (value !== null) {
302
+ string(value, path);
303
+ }
304
+ }
243
305
  /** Versions are strings on the wire, as `semver::Version` serialises them. */
244
- function version(value: unknown, path: string): void { string(value, path); if ((value as string).length === 0) fail(path, "expected non-empty version"); }
245
- function fraction(value: unknown, path: string): void { if (value === null) return; if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) fail(path, "expected a fraction between 0 and 1, or null"); }
246
- function oneOf(value: unknown, path: string, values: readonly string[]): void { if (typeof value !== "string" || !values.includes(value)) fail(path, "unsupported value"); }
247
- function fail(path: string, message: string): never { throw new UpdateValidationError(path, message); }
306
+ function version(value: unknown, path: string): void {
307
+ string(value, path);
308
+ if (value.length === 0) {
309
+ fail(path, "expected non-empty version");
310
+ }
311
+ }
312
+ function fraction(value: unknown, path: string): void {
313
+ if (value === null) {
314
+ return;
315
+ }
316
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
317
+ fail(path, "expected a fraction between 0 and 1, or null");
318
+ }
319
+ }
320
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
321
+ if (typeof value !== "string" || !values.includes(value)) {
322
+ fail(path, "unsupported value");
323
+ }
324
+ }
325
+ function fail(path: string, message: string): never {
326
+ throw new UpdateValidationError(path, message);
327
+ }