@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 { isRecord } from "../core/record.ts";
1
2
  import { LICENCE_FIELDS } from "./generated/fields.ts";
2
3
  import {
3
4
  LICENCE_CHANGED_KINDS,
@@ -7,14 +8,16 @@ import {
7
8
  LICENCE_REJECTION_CODES,
8
9
  LICENCE_TRUST_BASIS_KINDS,
9
10
  LICENCE_USABILITY_STATES,
10
- type LicenceActivateCommand,
11
- type LicenceChangedEvent,
12
- type LicenceDeactivateCommand,
13
- type LicenceOutcomeProjection,
14
- type LicenceRefreshCommand,
15
- type LicenceReleaseSeatCommand,
16
- type LicenceRenameSeatCommand,
17
- type LicenceSnapshot,
11
+ } from "./generated/protocol.ts";
12
+ import type {
13
+ LicenceActivateCommand,
14
+ LicenceChangedEvent,
15
+ LicenceDeactivateCommand,
16
+ LicenceOutcomeProjection,
17
+ LicenceRefreshCommand,
18
+ LicenceReleaseSeatCommand,
19
+ LicenceRenameSeatCommand,
20
+ LicenceSnapshot,
18
21
  } from "./generated/protocol.ts";
19
22
  import {
20
23
  LICENCE_VARIANT_FIELDS,
@@ -39,7 +42,9 @@ export function assertLicenceSnapshot(value: unknown): asserts value is LicenceS
39
42
  positive(root.authorityEpoch, "$.authorityEpoch");
40
43
  // Absent means unlicensed, which is the absence of a licence rather than a
41
44
  // licence that cannot be used. Card 193 kept those apart deliberately.
42
- if (root.licence !== null) held(root.licence, "$.licence");
45
+ if (root.licence !== null) {
46
+ held(root.licence, "$.licence");
47
+ }
43
48
  }
44
49
 
45
50
  export function assertLicenceOutcome(value: unknown): asserts value is LicenceOutcomeProjection {
@@ -47,7 +52,9 @@ export function assertLicenceOutcome(value: unknown): asserts value is LicenceOu
47
52
  const root = object(value, "$");
48
53
  oneOf(root.status, "$.status", LICENCE_OUTCOME_STATUSES);
49
54
  exact(root, "$", variantFields("LicenceOutcomeProjection", root, "$"));
50
- if (root.status === "rejected") oneOf(root.code, "$.code", LICENCE_REJECTION_CODES);
55
+ if (root.status === "rejected") {
56
+ oneOf(root.code, "$.code", LICENCE_REJECTION_CODES);
57
+ }
51
58
  assertLicenceSnapshot(root.snapshot);
52
59
  }
53
60
 
@@ -74,14 +81,20 @@ export function assertLicenceActivateCommand(
74
81
  // The one place credential material crosses, and it crosses inward only.
75
82
  // Checked for shape, never echoed: `noCredential` runs on everything coming
76
83
  // back and would reject a projection that returned any of this.
77
- if (credential.kind === "key") nonEmpty(credential.key, "$.credential.key");
78
- if (credential.kind === "accountToken") nonEmpty(credential.token, "$.credential.token");
84
+ if (credential.kind === "key") {
85
+ nonEmpty(credential.key, "$.credential.key");
86
+ }
87
+ if (credential.kind === "accountToken") {
88
+ nonEmpty(credential.token, "$.credential.token");
89
+ }
79
90
  if (credential.kind === "licenceFile") {
80
91
  nonEmpty(credential.contentsBase64, "$.credential.contentsBase64");
81
92
  }
82
93
  // The label a customer gives this machine, asked for at the only moment it
83
94
  // can be without inventing a settings screen. Absent is fine.
84
- if (root.label !== null) nonEmpty(root.label, "$.label");
95
+ if (root.label !== null) {
96
+ nonEmpty(root.label, "$.label");
97
+ }
85
98
  }
86
99
 
87
100
  export function assertLicenceDeactivateCommand(
@@ -110,7 +123,9 @@ export function assertLicenceRenameSeatCommand(
110
123
  nonEmpty(root.machineId, "$.machineId");
111
124
  // Null clears the label back to unnamed; an empty string is a mistake
112
125
  // wearing null's clothes and is refused rather than stored.
113
- if (root.label !== null) nonEmpty(root.label, "$.label");
126
+ if (root.label !== null) {
127
+ nonEmpty(root.label, "$.label");
128
+ }
114
129
  }
115
130
 
116
131
  function held(value: unknown, path: string): void {
@@ -131,7 +146,9 @@ function held(value: unknown, path: string): void {
131
146
  // checks it is present and never what it says, because anything derived
132
147
  // from the host would be a different value wearing the same field.
133
148
  nonEmpty(seat.machineId, `${at}.machineId`);
134
- if (seat.label !== null) nonEmpty(seat.label, `${at}.label`);
149
+ if (seat.label !== null) {
150
+ nonEmpty(seat.label, `${at}.label`);
151
+ }
135
152
  boolean(seat.thisMachine, `${at}.thisMachine`);
136
153
  });
137
154
  array(licence.entitlements, `${path}.entitlements`).forEach((entry, index) => {
@@ -141,7 +158,9 @@ function held(value: unknown, path: string): void {
141
158
  // Opaque by design: Longhorn enumerates no features, so this checks that
142
159
  // an id is present and never what it says.
143
160
  nonEmpty(entitlement.id, `${at}.id`);
144
- if (entitlement.atMost !== null) positive(entitlement.atMost, `${at}.atMost`);
161
+ if (entitlement.atMost !== null) {
162
+ positive(entitlement.atMost, `${at}.atMost`);
163
+ }
145
164
  });
146
165
  }
147
166
 
@@ -152,7 +171,9 @@ function usability(value: unknown, path: string): void {
152
171
  // `clockRefused` carries no timestamp on purpose: a licence refused because
153
172
  // the machine clock moved is not expired, and giving it a date would invite
154
173
  // a surface to render it as one.
155
- if (root.state === "inGrace") timestamp(root.until, `${path}.until`);
174
+ if (root.state === "inGrace") {
175
+ timestamp(root.until, `${path}.until`);
176
+ }
156
177
  if (root.state === "useWindowExpired" || root.state === "leaseLapsed") {
157
178
  timestamp(root.at, `${path}.at`);
158
179
  }
@@ -162,10 +183,12 @@ function trustBasis(value: unknown, path: string): void {
162
183
  const root = object(value, path);
163
184
  oneOf(root.kind, `${path}.kind`, LICENCE_TRUST_BASIS_KINDS);
164
185
  exact(root, path, variantFields("LicenceTrustBasisProjection", root, path));
165
- if (root.kind === "remoteAssertion") timestamp(root.checked, `${path}.checked`);
186
+ if (root.kind === "remoteAssertion") {
187
+ timestamp(root.checked, `${path}.checked`);
188
+ }
166
189
  }
167
190
 
168
- function commandBase(value: unknown, expected: readonly string[]): Record<string, unknown> {
191
+ function commandBase(value: unknown, expected: ReadonlyArray<string>): Record<string, unknown> {
169
192
  const root = object(value, "$");
170
193
  exact(root, "$", expected);
171
194
  protocol(root.protocolVersion, "$.protocolVersion");
@@ -187,8 +210,10 @@ function commandBase(value: unknown, expected: readonly string[]): Record<string
187
210
  function noCredential(value: unknown): void {
188
211
  const forbidden = ["credential", "secret", "signature", "token", "privatekey", "keyid"];
189
212
  const visit = (candidate: unknown, path: string): void => {
190
- if (Array.isArray(candidate)) return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
191
- if (candidate !== null && typeof candidate === "object")
213
+ if (Array.isArray(candidate)) {
214
+ return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
215
+ }
216
+ if (candidate !== null && typeof candidate === "object") {
192
217
  for (const [key, child] of Object.entries(candidate)) {
193
218
  const lowered = key.toLocaleLowerCase();
194
219
  if (forbidden.some((needle) => lowered.includes(needle))) {
@@ -196,6 +221,7 @@ function noCredential(value: unknown): void {
196
221
  }
197
222
  visit(child, `${path}.${key}`);
198
223
  }
224
+ }
199
225
  };
200
226
  visit(value, "$");
201
227
  }
@@ -204,23 +230,81 @@ function variantFields(
204
230
  type: string,
205
231
  value: Record<string, unknown>,
206
232
  path: string,
207
- ): readonly string[] {
233
+ ): ReadonlyArray<string> {
208
234
  const discriminant = value[LICENCE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
209
- const fields = LICENCE_VARIANT_FIELDS[type]?.[discriminant as string];
210
- if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
235
+ const fields =
236
+ typeof discriminant === "string" ? LICENCE_VARIANT_FIELDS[type]?.[discriminant] : undefined;
237
+ if (fields === undefined) {
238
+ fail(path, `no generated fields for ${type}.${String(discriminant)}`);
239
+ }
211
240
  return fields;
212
241
  }
213
242
 
214
- 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>; }
215
- function array(value: unknown, path: string): unknown[] { if (!Array.isArray(value)) fail(path, "expected array"); return value; }
216
- 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(",")}`); }
217
- function protocol(value: unknown, path: string): void { if (value !== LICENCE_PROTOCOL_VERSION) fail(path, `expected exact protocol ${LICENCE_PROTOCOL_VERSION}`); }
218
- function positive(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail(path, "expected positive safe integer"); }
219
- function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
220
- function nonEmpty(value: unknown, path: string): void { string(value, path); if ((value as string).length === 0) fail(path, "expected a non-empty string"); }
243
+ function object(value: unknown, path: string): Record<string, unknown> {
244
+ if (!isRecord(value)) {
245
+ fail(path, "expected object");
246
+ }
247
+ return value;
248
+ }
249
+ function array(value: unknown, path: string): Array<unknown> {
250
+ if (!Array.isArray(value)) {
251
+ fail(path, "expected array");
252
+ }
253
+ return value;
254
+ }
255
+ function exact(
256
+ value: Record<string, unknown>,
257
+ path: string,
258
+ expected: ReadonlyArray<string>,
259
+ ): void {
260
+ const actual = Object.keys(value).sort();
261
+ const wanted = [...expected].sort();
262
+ if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
263
+ fail(path, `unexpected keys: ${actual.join(",")}`);
264
+ }
265
+ }
266
+ function protocol(value: unknown, path: string): void {
267
+ if (value !== LICENCE_PROTOCOL_VERSION) {
268
+ fail(path, `expected exact protocol ${LICENCE_PROTOCOL_VERSION}`);
269
+ }
270
+ }
271
+ function positive(value: unknown, path: string): void {
272
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
273
+ fail(path, "expected positive safe integer");
274
+ }
275
+ }
276
+ function string(value: unknown, path: string): asserts value is string {
277
+ if (typeof value !== "string") {
278
+ fail(path, "expected string");
279
+ }
280
+ }
281
+ function nonEmpty(value: unknown, path: string): void {
282
+ string(value, path);
283
+ if (value.length === 0) {
284
+ fail(path, "expected a non-empty string");
285
+ }
286
+ }
221
287
  /** Unix seconds, and negative is a real point in time. */
222
- function timestamp(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value)) fail(path, "expected a unix-second timestamp"); }
223
- function optionalTimestamp(value: unknown, path: string): void { if (value !== null) timestamp(value, path); }
224
- function boolean(value: unknown, path: string): void { if (typeof value !== "boolean") fail(path, "expected boolean"); }
225
- function oneOf(value: unknown, path: string, values: readonly string[]): void { if (typeof value !== "string" || !values.includes(value)) fail(path, "unsupported value"); }
226
- function fail(path: string, message: string): never { throw new LicenceValidationError(path, message); }
288
+ function timestamp(value: unknown, path: string): void {
289
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) {
290
+ fail(path, "expected a unix-second timestamp");
291
+ }
292
+ }
293
+ function optionalTimestamp(value: unknown, path: string): void {
294
+ if (value !== null) {
295
+ timestamp(value, path);
296
+ }
297
+ }
298
+ function boolean(value: unknown, path: string): void {
299
+ if (typeof value !== "boolean") {
300
+ fail(path, "expected boolean");
301
+ }
302
+ }
303
+ function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
304
+ if (typeof value !== "string" || !values.includes(value)) {
305
+ fail(path, "unsupported value");
306
+ }
307
+ }
308
+ function fail(path: string, message: string): never {
309
+ throw new LicenceValidationError(path, message);
310
+ }