@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,14 +1,14 @@
1
1
  import { LicenceClient } from "./client.ts";
2
- import {
3
- LICENCE_PROTOCOL_VERSION,
4
- type HeldLicenceProjection,
5
- type LicenceCredentialProjection,
6
- type LicenceOutcomeProjection,
7
- type LicenceRejectionCode,
8
- type LicenceSeatProjection,
9
- type LicenceSnapshot,
10
- type LicenceTrustBasisProjection,
11
- type LicenceUsabilityProjection,
2
+ import { LICENCE_PROTOCOL_VERSION } from "./generated/protocol.ts";
3
+ import type {
4
+ HeldLicenceProjection,
5
+ LicenceCredentialProjection,
6
+ LicenceOutcomeProjection,
7
+ LicenceRejectionCode,
8
+ LicenceSeatProjection,
9
+ LicenceSnapshot,
10
+ LicenceTrustBasisProjection,
11
+ LicenceUsabilityProjection,
12
12
  } from "./generated/protocol.ts";
13
13
  import type { LicencePort, LicenceUnlisten } from "./ports.ts";
14
14
 
@@ -59,28 +59,44 @@ export class LicenceController {
59
59
  readonly #observers = new Set<() => void>();
60
60
  #status: LicenceControllerStatus = { kind: "idle" };
61
61
  #snapshot?: LicenceSnapshot;
62
- #lastRejection?: LicenceRejectionCode;
62
+ #lastRejection: LicenceRejectionCode | undefined;
63
63
  #started = false;
64
64
  #lifecycle = 0;
65
65
  #commandSequence = 0;
66
66
  #pending = false;
67
- #unlisten: LicenceUnlisten[] = [];
67
+ #unlisten: Array<LicenceUnlisten> = [];
68
68
 
69
69
  constructor(options: LicenceControllerOptions) {
70
70
  this.#client = new LicenceClient(options.port);
71
71
  }
72
72
 
73
- get status(): LicenceControllerStatus { return this.#status; }
74
- get snapshot(): LicenceSnapshot | undefined { return this.#snapshot; }
75
- get licence(): HeldLicenceProjection | undefined { return this.#snapshot?.licence ?? undefined; }
76
- get usability(): LicenceUsabilityProjection | undefined { return this.licence?.usability; }
77
- get trustBasis(): LicenceTrustBasisProjection | undefined { return this.licence?.trustBasis; }
78
- get pending(): boolean { return this.#pending; }
73
+ get status(): LicenceControllerStatus {
74
+ return this.#status;
75
+ }
76
+ get snapshot(): LicenceSnapshot | undefined {
77
+ return this.#snapshot;
78
+ }
79
+ get licence(): HeldLicenceProjection | undefined {
80
+ return this.#snapshot?.licence ?? undefined;
81
+ }
82
+ get usability(): LicenceUsabilityProjection | undefined {
83
+ return this.licence?.usability;
84
+ }
85
+ get trustBasis(): LicenceTrustBasisProjection | undefined {
86
+ return this.licence?.trustBasis;
87
+ }
88
+ get pending(): boolean {
89
+ return this.#pending;
90
+ }
79
91
  /** The latest refusal, cleared as soon as the next command starts. */
80
- get lastRejection(): LicenceRejectionCode | undefined { return this.#lastRejection; }
92
+ get lastRejection(): LicenceRejectionCode | undefined {
93
+ return this.#lastRejection;
94
+ }
81
95
 
82
96
  /** Whether a licence is held at all. Absence is not a usability state. */
83
- get activated(): boolean { return this.licence !== undefined; }
97
+ get activated(): boolean {
98
+ return this.licence !== undefined;
99
+ }
84
100
 
85
101
  /** Whether the software may be used. Grace counts, which is its point. */
86
102
  get usable(): boolean {
@@ -96,11 +112,15 @@ export class LicenceController {
96
112
  * are not the same message, and conflating them on a perpetual licence reads
97
113
  * as the application breaking.
98
114
  */
99
- get useUntil(): number | undefined { return this.licence?.useUntil ?? undefined; }
100
- get updateUntil(): number | undefined { return this.licence?.updateUntil ?? undefined; }
115
+ get useUntil(): number | undefined {
116
+ return this.licence?.useUntil ?? undefined;
117
+ }
118
+ get updateUntil(): number | undefined {
119
+ return this.licence?.updateUntil ?? undefined;
120
+ }
101
121
 
102
122
  /** Entitlement ids held, opaque by design. Longhorn enumerates no features. */
103
- get entitlements(): readonly string[] {
123
+ get entitlements(): ReadonlyArray<string> {
104
124
  return this.licence?.entitlements.map((entitlement) => entitlement.id) ?? [];
105
125
  }
106
126
 
@@ -111,7 +131,9 @@ export class LicenceController {
111
131
 
112
132
  /** The bound on an entitlement, or `undefined` for unlimited or unheld. */
113
133
  limit(id: string): number | undefined {
114
- return this.licence?.entitlements.find((entitlement) => entitlement.id === id)?.atMost ?? undefined;
134
+ return (
135
+ this.licence?.entitlements.find((entitlement) => entitlement.id === id)?.atMost ?? undefined
136
+ );
115
137
  }
116
138
 
117
139
  /**
@@ -127,7 +149,9 @@ export class LicenceController {
127
149
  * to buy something they already own.
128
150
  */
129
151
  get attention(): LicenceAttention {
130
- if (!this.activated) return "actionable";
152
+ if (!this.activated) {
153
+ return "actionable";
154
+ }
131
155
  switch (this.usability?.state) {
132
156
  case "active":
133
157
  case "inGrace":
@@ -151,7 +175,9 @@ export class LicenceController {
151
175
  }
152
176
 
153
177
  async start(): Promise<void> {
154
- if (this.#started) return;
178
+ if (this.#started) {
179
+ return;
180
+ }
155
181
  this.#started = true;
156
182
  const lifecycle = ++this.#lifecycle;
157
183
  this.#setStatus({ kind: "loading" });
@@ -164,7 +190,9 @@ export class LicenceController {
164
190
  this.#unlisten.push(unlisten);
165
191
  await this.refresh();
166
192
  } catch (error) {
167
- if (this.#started && lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
193
+ if (this.#started && lifecycle === this.#lifecycle) {
194
+ this.#setStatus({ kind: "failed", error });
195
+ }
168
196
  }
169
197
  }
170
198
 
@@ -173,7 +201,9 @@ export class LicenceController {
173
201
  this.#lifecycle += 1;
174
202
  const unlisten = this.#unlisten;
175
203
  this.#unlisten = [];
176
- for (const stop of unlisten) await stop();
204
+ for (const stop of unlisten) {
205
+ await stop();
206
+ }
177
207
  this.#setStatus({ kind: "idle" });
178
208
  }
179
209
 
@@ -181,11 +211,15 @@ export class LicenceController {
181
211
  const lifecycle = this.#lifecycle;
182
212
  try {
183
213
  const snapshot = await this.#client.snapshot();
184
- if (lifecycle !== this.#lifecycle) return;
214
+ if (lifecycle !== this.#lifecycle) {
215
+ return;
216
+ }
185
217
  this.#snapshot = snapshot;
186
218
  this.#setStatus({ kind: "ready" });
187
219
  } catch (error) {
188
- if (lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
220
+ if (lifecycle === this.#lifecycle) {
221
+ this.#setStatus({ kind: "failed", error });
222
+ }
189
223
  }
190
224
  }
191
225
 
@@ -195,10 +229,12 @@ export class LicenceController {
195
229
  * Empty when the authority does not account for seats, which is a different
196
230
  * state from a licence with one seat.
197
231
  */
198
- get seats(): readonly LicenceSeatProjection[] { return this.licence?.seats ?? []; }
232
+ get seats(): ReadonlyArray<LicenceSeatProjection> {
233
+ return this.licence?.seats ?? [];
234
+ }
199
235
 
200
236
  /** The seats that are not this machine — the ones a release would free. */
201
- get otherSeats(): readonly LicenceSeatProjection[] {
237
+ get otherSeats(): ReadonlyArray<LicenceSeatProjection> {
202
238
  return this.seats.filter((seat) => !seat.thisMachine);
203
239
  }
204
240
 
@@ -271,10 +307,7 @@ export class LicenceController {
271
307
  }
272
308
 
273
309
  async #command(
274
- run: (
275
- client: LicenceClient,
276
- epoch: number,
277
- ) => Promise<LicenceOutcomeProjection>,
310
+ run: (client: LicenceClient, epoch: number) => Promise<LicenceOutcomeProjection>,
278
311
  ): Promise<LicenceCommandOutcome> {
279
312
  const commandSequence = ++this.#commandSequence;
280
313
  this.#lastRejection = undefined;
@@ -291,9 +324,10 @@ export class LicenceController {
291
324
  this.#notify();
292
325
  try {
293
326
  const outcome = await run(this.#client, epoch);
294
- const result: LicenceCommandOutcome = outcome.status === "rejected"
295
- ? { status: "rejected", snapshot: outcome.snapshot, code: outcome.code }
296
- : { status: "committed", snapshot: outcome.snapshot };
327
+ const result: LicenceCommandOutcome =
328
+ outcome.status === "rejected"
329
+ ? { status: "rejected", snapshot: outcome.snapshot, code: outcome.code }
330
+ : { status: "committed", snapshot: outcome.snapshot };
297
331
  if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
298
332
  this.#snapshot = outcome.snapshot;
299
333
  this.#lastRejection = result.status === "rejected" ? result.code : undefined;
@@ -319,6 +353,8 @@ export class LicenceController {
319
353
  }
320
354
 
321
355
  #notify(): void {
322
- for (const observer of this.#observers) observer();
356
+ for (const observer of this.#observers) {
357
+ observer();
358
+ }
323
359
  }
324
360
  }
@@ -1,3 +1,5 @@
1
1
  import type { LicencePort } from "./ports.ts";
2
2
  export type DirectLicenceHandlers = LicencePort;
3
- export function createDirectLicencePort(handlers: DirectLicenceHandlers): LicencePort { return handlers; }
3
+ export function createDirectLicencePort(handlers: DirectLicenceHandlers): LicencePort {
4
+ return handlers;
5
+ }
@@ -3,7 +3,7 @@
3
3
  // A `record()` given one of these rejects unknown and missing keys —
4
4
  // contract 010's Boundary Validation Target.
5
5
 
6
- export const LICENCE_FIELDS: Record<string, readonly string[]> = {
6
+ export const LICENCE_FIELDS = {
7
7
  "LicenceEntitlementProjection": ["id", "atMost"],
8
8
  "LicenceSeatProjection": ["machineId", "label", "thisMachine"],
9
9
  "HeldLicenceProjection": ["product", "usability", "trustBasis", "entitlements", "useUntil", "updateUntil", "seats"],
@@ -14,4 +14,4 @@ export const LICENCE_FIELDS: Record<string, readonly string[]> = {
14
14
  "LicenceReleaseSeatCommand": ["protocolVersion", "authorityEpoch", "machineId"],
15
15
  "LicenceRenameSeatCommand": ["protocolVersion", "authorityEpoch", "machineId", "label"],
16
16
  "LicenceChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
17
- };
17
+ } as const;
@@ -38,5 +38,33 @@
38
38
  {
39
39
  "input": "ABCDE!2345FGHJK6789X",
40
40
  "outcome": "unexpectedSymbol:!"
41
+ },
42
+ {
43
+ "input": "*BCDE12345FGHJK6789Z",
44
+ "outcome": "unexpectedSymbol:*"
45
+ },
46
+ {
47
+ "input": "ABCDEu2345FGHJK6789Z",
48
+ "outcome": "unexpectedSymbol:u"
49
+ },
50
+ {
51
+ "input": "000000000000000000V*",
52
+ "outcome": "ok:00000-00000-00000-000V*"
53
+ },
54
+ {
55
+ "input": "0000000000000000020u",
56
+ "outcome": "ok:00000-00000-00000-0020U"
57
+ },
58
+ {
59
+ "input": "ſBCDE12345FGHJK67894",
60
+ "outcome": "unexpectedSymbol:ſ"
61
+ },
62
+ {
63
+ "input": "…ABCDE-12345-FGHJK-67894…",
64
+ "outcome": "ok:ABCDE-12345-FGHJK-67894"
65
+ },
66
+ {
67
+ "input": "ABCDE12345FGHJK67894",
68
+ "outcome": "unexpectedSymbol:"
41
69
  }
42
70
  ]
@@ -24,7 +24,7 @@ until: Timestamp, } | { "state": "useWindowExpired",
24
24
  */
25
25
  at: Timestamp, } | { "state": "leaseLapsed",
26
26
  /**
27
- * When grace ran out.
27
+ * When grace ran out, or when the unleased remote assertion was checked.
28
28
  */
29
29
  at: Timestamp, } | { "state": "clockRefused" };
30
30
 
@@ -68,7 +68,9 @@ export function isProbablyATypo(problem: LicenceKeyProblem): boolean {
68
68
  */
69
69
  export function parseLicenceKey(input: string): LicenceKeyResult {
70
70
  const normalized = normalize(input);
71
- if (!normalized.ok) return normalized;
71
+ if (!normalized.ok) {
72
+ return normalized;
73
+ }
72
74
 
73
75
  const value = normalized.value;
74
76
  if (value.length < MINIMUM_KEY_SYMBOLS) {
@@ -87,22 +89,45 @@ export function parseLicenceKey(input: string): LicenceKeyResult {
87
89
 
88
90
  /** Renders a normalized key as `XXXXX-XXXXX-…`. */
89
91
  export function group(key: string): string {
90
- const groups: string[] = [];
91
- for (let at = 0; at < key.length; at += GROUP) groups.push(key.slice(at, at + GROUP));
92
+ const groups: Array<string> = [];
93
+ for (let at = 0; at < key.length; at += GROUP) {
94
+ groups.push(key.slice(at, at + GROUP));
95
+ }
92
96
  return groups.join("-");
93
97
  }
94
98
 
99
+ /** Matches Rust's `char::is_whitespace` (Unicode `White_Space`: includes U+0085, excludes U+FEFF). */
100
+ const UNICODE_WHITESPACE = /\p{White_Space}/u;
101
+
102
+ /** Matches Rust's `char::to_ascii_uppercase` so non-ASCII letters like U+017F never fold into ASCII. */
103
+ function toAsciiUpper(character: string): string {
104
+ const code = character.charCodeAt(0);
105
+ if (code >= 0x61 && code <= 0x7a) {
106
+ return String.fromCharCode(code - 0x20);
107
+ }
108
+ return character;
109
+ }
110
+
95
111
  function normalize(
96
112
  input: string,
97
- ): { readonly ok: true; readonly value: string } | { readonly ok: false; readonly problem: LicenceKeyProblem } {
98
- let output = "";
113
+ ):
114
+ | { readonly ok: true; readonly value: string }
115
+ | { readonly ok: false; readonly problem: LicenceKeyProblem } {
116
+ const symbols: Array<{ readonly original: string; readonly mapped: string }> = [];
99
117
  for (const character of input) {
100
- if (character === "-" || /\s/u.test(character)) continue;
101
- const upper = character.toUpperCase();
118
+ if (character === "-" || UNICODE_WHITESPACE.test(character)) {
119
+ continue;
120
+ }
121
+ const upper = toAsciiUpper(character);
102
122
  // The confusions Crockford excluded the symbols to avoid.
103
123
  const mapped = upper === "I" || upper === "L" ? "1" : upper === "O" ? "0" : upper;
104
- if (!CHECK_ALPHABET.includes(mapped) || mapped.length !== 1) {
105
- return { ok: false, problem: { kind: "unexpectedSymbol", symbol: character } };
124
+ symbols.push({ original: character, mapped });
125
+ }
126
+ let output = "";
127
+ for (const [index, { original, mapped }] of symbols.entries()) {
128
+ const alphabet = index + 1 < symbols.length ? ALPHABET : CHECK_ALPHABET;
129
+ if (mapped.length !== 1 || !alphabet.includes(mapped)) {
130
+ return { ok: false, problem: { kind: "unexpectedSymbol", symbol: original } };
106
131
  }
107
132
  output += mapped;
108
133
  }
@@ -118,8 +143,11 @@ function normalize(
118
143
  function checkSymbol(body: string): string {
119
144
  let sum = 0;
120
145
  for (let index = 0; index < body.length; index += 1) {
121
- const value = ALPHABET.indexOf(body[index]!);
122
- sum += (value === -1 ? 0 : value) * (index + 1);
146
+ const value = ALPHABET.indexOf(body.charAt(index));
147
+ if (value === -1) {
148
+ throw new Error(`normalized key body contains unexpected symbol: ${body[index]}`);
149
+ }
150
+ sum += value * (index + 1);
123
151
  }
124
- return CHECK_ALPHABET[sum % 37]!;
152
+ return CHECK_ALPHABET.charAt(sum % 37);
125
153
  }
@@ -24,7 +24,9 @@ export interface LicencePort {
24
24
  refresh(command: LicenceRefreshCommand): Promise<unknown>;
25
25
  releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown>;
26
26
  renameSeat(command: LicenceRenameSeatCommand): Promise<unknown>;
27
- listen?(listener: (event: unknown) => void): LicenceUnlisten | Promise<LicenceUnlisten>;
27
+ listen?:
28
+ | ((listener: (event: unknown) => void) => LicenceUnlisten | Promise<LicenceUnlisten>)
29
+ | undefined;
28
30
  }
29
31
 
30
32
  /** The same seam after validation. */
@@ -1,13 +1,36 @@
1
- import type { LicenceActivateCommand, LicenceDeactivateCommand, LicenceRefreshCommand, LicenceReleaseSeatCommand, LicenceRenameSeatCommand } from "./generated/protocol.ts";
1
+ import { wireCopy } from "../core/wire-copy.ts";
2
+ import type {
3
+ LicenceActivateCommand,
4
+ LicenceDeactivateCommand,
5
+ LicenceRefreshCommand,
6
+ LicenceReleaseSeatCommand,
7
+ LicenceRenameSeatCommand,
8
+ } from "./generated/protocol.ts";
2
9
  import type { LicencePort, LicenceUnlisten } from "./ports.ts";
3
10
  export class SerializedLicencePort implements LicencePort {
4
11
  constructor(readonly inner: LicencePort) {}
5
- async snapshot(): Promise<unknown> { return clone(await this.inner.snapshot()); }
6
- async activate(command: LicenceActivateCommand): Promise<unknown> { return clone(await this.inner.activate(clone(command))); }
7
- async deactivate(command: LicenceDeactivateCommand): Promise<unknown> { return clone(await this.inner.deactivate(clone(command))); }
8
- async refresh(command: LicenceRefreshCommand): Promise<unknown> { return clone(await this.inner.refresh(clone(command))); }
9
- async releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown> { return clone(await this.inner.releaseSeat(clone(command))); }
10
- async renameSeat(command: LicenceRenameSeatCommand): Promise<unknown> { return clone(await this.inner.renameSeat(clone(command))); }
11
- async listen(listener: (event: unknown) => void): Promise<LicenceUnlisten> { if (this.inner.listen === undefined) return () => {}; return this.inner.listen((event) => listener(clone(event))); }
12
+ async snapshot(): Promise<unknown> {
13
+ return wireCopy(await this.inner.snapshot());
14
+ }
15
+ async activate(command: LicenceActivateCommand): Promise<unknown> {
16
+ return wireCopy(await this.inner.activate(wireCopy(command)));
17
+ }
18
+ async deactivate(command: LicenceDeactivateCommand): Promise<unknown> {
19
+ return wireCopy(await this.inner.deactivate(wireCopy(command)));
20
+ }
21
+ async refresh(command: LicenceRefreshCommand): Promise<unknown> {
22
+ return wireCopy(await this.inner.refresh(wireCopy(command)));
23
+ }
24
+ async releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown> {
25
+ return wireCopy(await this.inner.releaseSeat(wireCopy(command)));
26
+ }
27
+ async renameSeat(command: LicenceRenameSeatCommand): Promise<unknown> {
28
+ return wireCopy(await this.inner.renameSeat(wireCopy(command)));
29
+ }
30
+ async listen(listener: (event: unknown) => void): Promise<LicenceUnlisten> {
31
+ if (this.inner.listen === undefined) {
32
+ return () => {};
33
+ }
34
+ return this.inner.listen((event) => listener(wireCopy(event)));
35
+ }
12
36
  }
13
- function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }