@inflatable-cookie/longhorn 0.5.0 → 0.7.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 (167) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -7
  3. package/src/agent-control/generated/protocol.ts +228 -0
  4. package/src/agent-control/index.ts +1 -5
  5. package/src/agent-control/inject.ts +4 -1
  6. package/src/agent-control/selection.ts +42 -25
  7. package/src/agent-control/shim.ts +428 -198
  8. package/src/bridge/direct.ts +1 -1
  9. package/src/bridge/generated/fields.ts +4 -3
  10. package/src/bridge/generated/protocol.ts +62 -7
  11. package/src/bridge/generated/variant-fields.ts +1 -1
  12. package/src/bridge/job.ts +49 -12
  13. package/src/bridge/loopback.ts +7 -25
  14. package/src/bridge/operation.ts +13 -43
  15. package/src/bridge/router.ts +10 -23
  16. package/src/bridge/runtime/connection.ts +78 -109
  17. package/src/bridge/runtime/policy.ts +8 -28
  18. package/src/bridge/runtime/retry.ts +6 -18
  19. package/src/bridge/session.ts +4 -14
  20. package/src/bridge/stream/connection.ts +24 -55
  21. package/src/bridge/stream/source.ts +2 -6
  22. package/src/bridge/stream/tracker.ts +12 -12
  23. package/src/bridge/supervision.ts +104 -97
  24. package/src/bridge/validation/base.ts +21 -63
  25. package/src/bridge/validation/jobs.ts +11 -25
  26. package/src/bridge/validation/negotiation.ts +28 -43
  27. package/src/bridge/validation/operations.ts +29 -65
  28. package/src/bridge/validation/streams.ts +3 -10
  29. package/src/commands/client.ts +37 -28
  30. package/src/commands/controller.ts +119 -96
  31. package/src/commands/generated/fields.ts +7 -6
  32. package/src/commands/generated/protocol.ts +28 -1
  33. package/src/commands/generated/variant-fields.ts +1 -1
  34. package/src/commands/keyboard.ts +94 -100
  35. package/src/commands/physical-code.ts +11 -0
  36. package/src/commands/ports.ts +8 -13
  37. package/src/commands/projectors.ts +100 -75
  38. package/src/commands/validation.ts +434 -241
  39. package/src/config/client.ts +9 -22
  40. package/src/config/generated/base.ts +22 -6
  41. package/src/config/generated/fields.ts +4 -3
  42. package/src/config/generated/label-template.ts +1 -1
  43. package/src/config/generated/labels.ts +1 -1
  44. package/src/config/generated/protocol.ts +1 -1
  45. package/src/config/generated/restore.ts +35 -12
  46. package/src/config/generated/variant-fields.ts +1 -1
  47. package/src/config/names.ts +6 -12
  48. package/src/config/validation/commands.ts +11 -25
  49. package/src/config/validation/outcomes.ts +163 -70
  50. package/src/config/validation/primitives.ts +35 -80
  51. package/src/config/validation/projection.ts +100 -128
  52. package/src/core/connection.ts +187 -83
  53. package/src/core/controller-lifecycle.ts +144 -0
  54. package/src/core/generated/identifiers.ts +4 -0
  55. package/src/core/identifiers.ts +40 -0
  56. package/src/core/index.ts +10 -1
  57. package/src/core/json-value.ts +58 -0
  58. package/src/core/listeners.ts +35 -0
  59. package/src/core/record.ts +80 -0
  60. package/src/core/transport.ts +9 -11
  61. package/src/core/wire-copy.ts +7 -0
  62. package/src/history/client.ts +11 -13
  63. package/src/history/controller.ts +106 -108
  64. package/src/history/direct.ts +1 -3
  65. package/src/history/generated/fields.ts +4 -3
  66. package/src/history/generated/protocol.ts +8 -5
  67. package/src/history/generated/variant-fields.ts +1 -1
  68. package/src/history/ports.ts +7 -4
  69. package/src/history/serialized.ts +9 -13
  70. package/src/history/validation.ts +69 -75
  71. package/src/history-tree/client.ts +89 -11
  72. package/src/history-tree/controller.ts +380 -96
  73. package/src/history-tree/direct.ts +3 -1
  74. package/src/history-tree/generated/fields.ts +5 -3
  75. package/src/history-tree/generated/protocol.ts +43 -7
  76. package/src/history-tree/generated/variant-fields.ts +7 -1
  77. package/src/history-tree/ports.ts +12 -5
  78. package/src/history-tree/serialized.ts +39 -11
  79. package/src/history-tree/validation.ts +286 -78
  80. package/src/layout/generated/protocol.ts +4 -3
  81. package/src/layout/generated/variant-fields.ts +47 -0
  82. package/src/layout/index.ts +1 -1
  83. package/src/layout/ratio.ts +10 -9
  84. package/src/layout/validation.ts +98 -32
  85. package/src/layout/visibility.ts +1 -2
  86. package/src/licence/client.ts +48 -7
  87. package/src/licence/controller.ts +127 -70
  88. package/src/licence/direct.ts +3 -1
  89. package/src/licence/generated/fields.ts +4 -3
  90. package/src/licence/generated/key-conformance.json +28 -0
  91. package/src/licence/generated/protocol.ts +9 -5
  92. package/src/licence/generated/variant-fields.ts +1 -1
  93. package/src/licence/key.ts +42 -18
  94. package/src/licence/ports.ts +10 -3
  95. package/src/licence/serialized.ts +32 -9
  96. package/src/licence/validation.ts +134 -43
  97. package/src/native-content/client.ts +207 -234
  98. package/src/native-content/generated/fields.ts +6 -6
  99. package/src/native-content/generated/protocol.ts +16 -5
  100. package/src/native-content/generated/variant-fields.ts +1 -1
  101. package/src/native-content/ports.ts +11 -16
  102. package/src/native-content/serialized.ts +12 -19
  103. package/src/native-content/validation/base.ts +57 -80
  104. package/src/native-content/validation/messages.ts +24 -35
  105. package/src/native-content/validation/state.ts +31 -33
  106. package/src/notifications/client.ts +85 -51
  107. package/src/notifications/controller.ts +400 -145
  108. package/src/notifications/direct.ts +3 -1
  109. package/src/notifications/generated/fields.ts +4 -3
  110. package/src/notifications/generated/labels.ts +1 -1
  111. package/src/notifications/generated/protocol.ts +5 -1
  112. package/src/notifications/generated/variant-fields.ts +1 -1
  113. package/src/notifications/ports.ts +9 -4
  114. package/src/notifications/serialized.ts +11 -9
  115. package/src/notifications/tone.ts +1 -1
  116. package/src/notifications/validation.ts +165 -71
  117. package/src/operation/bridge.ts +187 -60
  118. package/src/operation/client.ts +48 -62
  119. package/src/operation/controller.ts +67 -97
  120. package/src/operation/direct.ts +1 -3
  121. package/src/operation/generated/fields.ts +4 -3
  122. package/src/operation/generated/labels.ts +1 -1
  123. package/src/operation/generated/protocol.ts +5 -1
  124. package/src/operation/generated/variant-fields.ts +1 -1
  125. package/src/operation/ports.ts +12 -10
  126. package/src/operation/serialized.ts +8 -9
  127. package/src/operation/validation.ts +189 -104
  128. package/src/settings/client.ts +11 -44
  129. package/src/settings/connection.ts +35 -53
  130. package/src/settings/generated/fields.ts +5 -4
  131. package/src/settings/generated/protocol.ts +14 -5
  132. package/src/settings/generated/variant-fields.ts +1 -1
  133. package/src/settings/names.ts +2 -4
  134. package/src/settings/registry.ts +23 -25
  135. package/src/settings/validation/authority.ts +21 -19
  136. package/src/settings/validation/command.ts +22 -41
  137. package/src/settings/validation/error.ts +2 -8
  138. package/src/settings/validation/primitives.ts +46 -97
  139. package/src/settings/validation/projection.ts +8 -24
  140. package/src/settings/validation/registry.ts +33 -79
  141. package/src/surface-transfer/client.ts +6 -18
  142. package/src/surface-transfer/generated/fields.ts +3 -3
  143. package/src/surface-transfer/generated/protocol.ts +3 -3
  144. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  145. package/src/surface-transfer/validation.ts +91 -86
  146. package/src/surfaces/client.ts +33 -55
  147. package/src/surfaces/generated/fields.ts +3 -3
  148. package/src/surfaces/generated/protocol.ts +1 -1
  149. package/src/surfaces/generated/variant-fields.ts +1 -1
  150. package/src/surfaces/validation.ts +227 -99
  151. package/src/transfer/client.ts +26 -60
  152. package/src/transfer/connection.ts +29 -51
  153. package/src/transfer/generated/fields.ts +7 -6
  154. package/src/transfer/generated/protocol.ts +13 -5
  155. package/src/transfer/generated/variant-fields.ts +1 -1
  156. package/src/transfer/index.ts +8 -1
  157. package/src/transfer/payload.ts +20 -35
  158. package/src/transfer/validation.ts +169 -119
  159. package/src/update/client.ts +86 -9
  160. package/src/update/controller.ts +264 -116
  161. package/src/update/direct.ts +3 -1
  162. package/src/update/generated/fields.ts +5 -4
  163. package/src/update/generated/protocol.ts +25 -9
  164. package/src/update/generated/variant-fields.ts +4 -2
  165. package/src/update/ports.ts +14 -6
  166. package/src/update/serialized.ts +36 -10
  167. package/src/update/validation.ts +118 -48
@@ -1,17 +1,14 @@
1
- import {
2
- isNewerOperationSnapshot,
3
- OperationClient,
4
- type OperationSubscription,
5
- } from "./client.ts";
6
- import {
7
- OPERATION_PROTOCOL_VERSION,
8
- type OperationCancellationResult,
9
- type OperationEntryProjection,
10
- type OperationId,
11
- type OperationMutationResult,
12
- type OperationRejection,
13
- type OperationRequestId,
14
- type OperationSnapshot,
1
+ import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
2
+ import { isNewerOperationSnapshot, OperationClient } from "./client.ts";
3
+ import { OPERATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
4
+ import type {
5
+ OperationCancellationResult,
6
+ OperationEntryProjection,
7
+ OperationId,
8
+ OperationMutationResult,
9
+ OperationRejection,
10
+ OperationRequestId,
11
+ OperationSnapshot,
15
12
  } from "./generated/protocol.ts";
16
13
  import type { OperationPort } from "./ports.ts";
17
14
 
@@ -50,9 +47,7 @@ export class OperationController {
50
47
  #selectedOperationId: OperationId | undefined;
51
48
  #commandRejection: OperationCommandRejection | undefined;
52
49
  #commandFailure: OperationCommandFailure | undefined;
53
- #subscription: OperationSubscription | undefined;
54
- #started = false;
55
- #lifecycleRevision = 0;
50
+ readonly #lifecycle = new ControllerLifecycle();
56
51
  #commandRevision = 0;
57
52
 
58
53
  constructor(options: OperationControllerOptions) {
@@ -60,18 +55,18 @@ export class OperationController {
60
55
  }
61
56
 
62
57
  get status(): OperationControllerStatus {
63
- return this.#status;
58
+ return this.#lifecycle.eventFailure ?? this.#status;
64
59
  }
65
60
 
66
61
  get snapshot(): OperationSnapshot | undefined {
67
62
  return this.#snapshot;
68
63
  }
69
64
 
70
- get active(): readonly OperationEntryProjection[] {
65
+ get active(): ReadonlyArray<OperationEntryProjection> {
71
66
  return this.#snapshot?.active ?? [];
72
67
  }
73
68
 
74
- get recent(): readonly OperationEntryProjection[] {
69
+ get recent(): ReadonlyArray<OperationEntryProjection> {
75
70
  return this.#snapshot?.recent ?? [];
76
71
  }
77
72
 
@@ -80,11 +75,13 @@ export class OperationController {
80
75
  }
81
76
 
82
77
  get selected(): OperationEntryProjection | undefined {
83
- if (this.#selectedOperationId === undefined) return undefined;
78
+ if (this.#selectedOperationId === undefined) {
79
+ return undefined;
80
+ }
84
81
  return this.#entry(this.#selectedOperationId);
85
82
  }
86
83
 
87
- get pendingCommands(): readonly OperationPendingCommand[] {
84
+ get pendingCommands(): ReadonlyArray<OperationPendingCommand> {
88
85
  return [...this.#pending.values()];
89
86
  }
90
87
 
@@ -101,53 +98,40 @@ export class OperationController {
101
98
  return () => this.#observers.delete(observer);
102
99
  }
103
100
 
104
- async start(): Promise<void> {
105
- if (this.#started) return;
106
- this.#started = true;
107
- const lifecycleRevision = ++this.#lifecycleRevision;
108
- this.#setStatus({ kind: "loading" });
109
-
110
- const subscription = this.#client.subscribe(
111
- (snapshot) => {
112
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
113
- this.#install(snapshot);
114
- }
101
+ start(): Promise<void> {
102
+ return this.#lifecycle.start({
103
+ loading: () => this.#setStatus({ kind: "loading" }),
104
+ connect: ({ isCurrent, reportFailure, watch }) => {
105
+ const subscription = this.#client.subscribe((snapshot) => {
106
+ if (isCurrent()) {
107
+ this.#install(snapshot);
108
+ }
109
+ }, reportFailure);
110
+ return watch(subscription, () => this.#setStatus({ kind: "ready" }));
115
111
  },
116
- ({ error }) => {
117
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
118
- this.#setStatus({ kind: "failed", error });
119
- }
120
- },
121
- );
122
- this.#subscription = subscription;
112
+ failed: (error) => this.#setStatus({ kind: "failed", error }),
113
+ });
114
+ }
123
115
 
124
- try {
125
- await subscription.ready;
126
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
127
- this.#setStatus({ kind: "ready" });
128
- }
129
- } catch (error) {
130
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
131
- this.#setStatus({ kind: "failed", error });
132
- }
133
- }
116
+ /** Replaces the current subscription, including after a reported failure. */
117
+ restart(): Promise<void> {
118
+ return this.#lifecycle.restart(
119
+ this.status,
120
+ () => this.stop(),
121
+ () => this.start(),
122
+ );
134
123
  }
135
124
 
136
- async stop(): Promise<void> {
137
- this.#started = false;
138
- this.#lifecycleRevision += 1;
139
- this.#commandRevision += 1;
140
- const subscription = this.#subscription;
141
- this.#subscription = undefined;
142
- this.#snapshot = undefined;
143
- this.#selectedOperationId = undefined;
144
- this.#pending.clear();
145
- this.#commandRejection = undefined;
146
- this.#commandFailure = undefined;
147
- this.#setStatus({ kind: "idle" });
148
- if (subscription !== undefined) {
149
- await subscription.dispose();
150
- }
125
+ stop(): Promise<void> {
126
+ return this.#lifecycle.stop(() => {
127
+ this.#commandRevision += 1;
128
+ this.#snapshot = undefined;
129
+ this.#selectedOperationId = undefined;
130
+ this.#pending.clear();
131
+ this.#commandRejection = undefined;
132
+ this.#commandFailure = undefined;
133
+ this.#setStatus({ kind: "idle" });
134
+ });
151
135
  }
152
136
 
153
137
  select(operationId: OperationId | undefined): void {
@@ -191,25 +175,19 @@ export class OperationController {
191
175
  operationId,
192
176
  expectedOperationRevision: operation.revision,
193
177
  } as const;
194
- return this.#runCommand(
195
- { requestId: command.requestId, operationId, kind: "dismissal" },
196
- () => this.#client.mutate(command),
178
+ return this.#runCommand({ requestId: command.requestId, operationId, kind: "dismissal" }, () =>
179
+ this.#client.mutate(command),
197
180
  );
198
181
  }
199
182
 
200
- async #runCommand<
201
- Result extends OperationCancellationResult | OperationMutationResult,
202
- >(
183
+ async #runCommand<Result extends OperationCancellationResult | OperationMutationResult>(
203
184
  pending: OperationPendingCommand,
204
185
  run: () => Promise<Result>,
205
186
  ): Promise<Result> {
206
187
  if (this.#hasPending(pending.operationId, pending.kind)) {
207
- throw new OperationControllerCommandPendingError(
208
- pending.operationId,
209
- pending.kind,
210
- );
188
+ throw new OperationControllerCommandPendingError(pending.operationId, pending.kind);
211
189
  }
212
- const lifecycleRevision = this.#lifecycleRevision;
190
+ const lifecycleRevision = this.#lifecycle.revision;
213
191
  const commandRevision = ++this.#commandRevision;
214
192
  this.#pending.set(pending.requestId, pending);
215
193
  this.#commandFailure = undefined;
@@ -218,26 +196,23 @@ export class OperationController {
218
196
 
219
197
  try {
220
198
  const result = await run();
221
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
199
+ if (this.#lifecycle.isCurrent(lifecycleRevision)) {
222
200
  this.#install(result.snapshot);
223
- if (
224
- commandRevision === this.#commandRevision &&
225
- result.status === "rejected"
226
- ) {
201
+ if (commandRevision === this.#commandRevision && result.status === "rejected") {
227
202
  this.#commandRejection = { ...pending, rejection: result.rejection };
228
203
  }
229
204
  }
230
205
  return result;
231
206
  } catch (error) {
232
207
  if (
233
- this.#isCurrentLifecycle(lifecycleRevision) &&
208
+ this.#lifecycle.isCurrent(lifecycleRevision) &&
234
209
  commandRevision === this.#commandRevision
235
210
  ) {
236
211
  this.#commandFailure = { ...pending, error };
237
212
  }
238
213
  throw error;
239
214
  } finally {
240
- if (this.#isCurrentLifecycle(lifecycleRevision)) {
215
+ if (this.#lifecycle.isCurrent(lifecycleRevision)) {
241
216
  this.#pending.delete(pending.requestId);
242
217
  this.#notify();
243
218
  }
@@ -245,7 +220,7 @@ export class OperationController {
245
220
  }
246
221
 
247
222
  #requireAvailableEntry(operationId: OperationId): OperationEntryProjection {
248
- if (!this.#started || this.#snapshot === undefined) {
223
+ if (!this.#lifecycle.active || this.#snapshot === undefined) {
249
224
  throw new OperationControllerUnavailableError();
250
225
  }
251
226
  const operation = this.#entry(operationId);
@@ -256,22 +231,19 @@ export class OperationController {
256
231
  }
257
232
 
258
233
  #entry(operationId: OperationId): OperationEntryProjection | undefined {
259
- return [...this.active, ...this.recent].find(
260
- (entry) => entry.operationId === operationId,
261
- );
234
+ return [...this.active, ...this.recent].find((entry) => entry.operationId === operationId);
262
235
  }
263
236
 
264
- #hasPending(
265
- operationId: OperationId,
266
- kind: OperationPendingCommandKind,
267
- ): boolean {
237
+ #hasPending(operationId: OperationId, kind: OperationPendingCommandKind): boolean {
268
238
  return [...this.#pending.values()].some(
269
239
  (pending) => pending.operationId === operationId && pending.kind === kind,
270
240
  );
271
241
  }
272
242
 
273
243
  #install(snapshot: OperationSnapshot): void {
274
- if (!isNewerOperationSnapshot(snapshot, this.#snapshot)) return;
244
+ if (!isNewerOperationSnapshot(snapshot, this.#snapshot)) {
245
+ return;
246
+ }
275
247
  this.#snapshot = snapshot;
276
248
  if (
277
249
  this.#selectedOperationId !== undefined &&
@@ -282,17 +254,15 @@ export class OperationController {
282
254
  this.#notify();
283
255
  }
284
256
 
285
- #isCurrentLifecycle(revision: number): boolean {
286
- return this.#started && revision === this.#lifecycleRevision;
287
- }
288
-
289
257
  #setStatus(status: OperationControllerStatus): void {
290
258
  this.#status = status;
291
259
  this.#notify();
292
260
  }
293
261
 
294
262
  #notify(): void {
295
- for (const observer of this.#observers) observer();
263
+ for (const observer of this.#observers) {
264
+ observer();
265
+ }
296
266
  }
297
267
  }
298
268
 
@@ -8,8 +8,6 @@ export interface DirectOperationHandlers {
8
8
  readonly nextRequestId: OperationPort["nextRequestId"];
9
9
  }
10
10
 
11
- export function createDirectOperationPort(
12
- handlers: DirectOperationHandlers,
13
- ): OperationPort {
11
+ export function createDirectOperationPort(handlers: DirectOperationHandlers): OperationPort {
14
12
  return { ...handlers };
15
13
  }
@@ -1,9 +1,9 @@
1
- // @generated by `effigy generate:operation`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per protocol type, from the Rust structs.
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 OPERATION_FIELDS: Record<string, readonly string[]> = {
6
+ export const OPERATION_FIELDS = {
7
7
  "OperationAuthorityProjection": ["authorityId", "authorityEpoch"],
8
8
  "OperationPhaseProgressProjection": ["phaseId", "label", "completed", "total"],
9
9
  "OperationProgressProjection": ["sequence", "overall", "phase"],
@@ -17,4 +17,5 @@ export const OPERATION_FIELDS: Record<string, readonly string[]> = {
17
17
  "OperationRejection": ["code", "detail", "refreshRequired"],
18
18
  "OperationCancellationReceiptProjection": ["operationId", "outcome", "previousState", "committedState", "previousOperationRevision", "committedOperationRevision", "previousCatalogueRevision", "committedCatalogueRevision", "evicted"],
19
19
  "OperationChangedEvent": ["protocolVersion", "requestId", "authority", "previousCatalogueRevision", "committedCatalogueRevision", "operationId", "kind"],
20
- };
20
+ "OperationHostError": ["code", "message", "retryable"],
21
+ } as const;
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:operation`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Wording lives in Rust, on the enum that owns it. A label edited here is
3
3
  // a label that disagrees with the native surface.
4
4
 
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:operation`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority. Product payloads are intentionally absent.
3
3
 
4
4
  export const OPERATION_PROTOCOL_VERSION = 1 as const;
@@ -760,3 +760,7 @@ operationId: OperationId | null,
760
760
  * Change source.
761
761
  */
762
762
  kind: OperationChangedKind, };
763
+
764
+ export type OperationHostErrorCode = "authorityUnavailable" | "authorityStateUnavailable" | "executorStateUnavailable" | "eventPublication";
765
+
766
+ export type OperationHostError = { "code": OperationHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:operation`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per tagged-union variant, from the Rust enums.
3
3
  // Keyed by type, then by discriminant. The discriminant itself is in
4
4
  // each list, because `exact()` compares every key.
@@ -1,29 +1,31 @@
1
+ import type { Unlisten } from "../core/transport.ts";
1
2
  import type {
2
3
  OperationCancellationCommand,
3
4
  OperationChangedEvent,
4
5
  OperationMutationCommand,
5
6
  OperationRequestId,
6
7
  OperationSnapshotQuery,
8
+ OperationSnapshotResponse,
9
+ OperationMutationResult,
10
+ OperationCancellationResult,
7
11
  } from "./generated/protocol.ts";
8
12
 
9
- export type OperationUnlisten = () => void | Promise<void>;
13
+ export type OperationUnlisten = Unlisten;
10
14
 
11
15
  export interface OperationPort {
12
16
  snapshot(query: OperationSnapshotQuery): Promise<unknown>;
13
17
  mutate(command: OperationMutationCommand): Promise<unknown>;
14
18
  cancel(command: OperationCancellationCommand): Promise<unknown>;
15
- listen?(
16
- listener: (event: unknown) => void,
17
- ): OperationUnlisten | Promise<OperationUnlisten>;
19
+ listen?:
20
+ | ((listener: (event: unknown) => void) => OperationUnlisten | Promise<OperationUnlisten>)
21
+ | undefined;
18
22
  nextRequestId(): OperationRequestId;
19
23
  }
20
24
 
21
25
  export interface CheckedOperationPort {
22
- snapshot(query: OperationSnapshotQuery): Promise<import("./generated/protocol.ts").OperationSnapshotResponse>;
23
- mutate(command: OperationMutationCommand): Promise<import("./generated/protocol.ts").OperationMutationResult>;
24
- cancel(command: OperationCancellationCommand): Promise<import("./generated/protocol.ts").OperationCancellationResult>;
25
- listen?(
26
- listener: (event: OperationChangedEvent) => void,
27
- ): Promise<OperationUnlisten>;
26
+ snapshot(query: OperationSnapshotQuery): Promise<OperationSnapshotResponse>;
27
+ mutate(command: OperationMutationCommand): Promise<OperationMutationResult>;
28
+ cancel(command: OperationCancellationCommand): Promise<OperationCancellationResult>;
29
+ listen?(listener: (event: OperationChangedEvent) => void): Promise<OperationUnlisten>;
28
30
  nextRequestId(): OperationRequestId;
29
31
  }
@@ -1,3 +1,4 @@
1
+ import { wireCopy } from "../core/wire-copy.ts";
1
2
  import type {
2
3
  OperationCancellationCommand,
3
4
  OperationMutationCommand,
@@ -13,27 +14,25 @@ export class SerializedOperationPort implements OperationPort {
13
14
  }
14
15
 
15
16
  async snapshot(query: OperationSnapshotQuery): Promise<unknown> {
16
- return clone(await this.#inner.snapshot(clone(query)));
17
+ return wireCopy(await this.#inner.snapshot(wireCopy(query)));
17
18
  }
18
19
 
19
20
  async mutate(command: OperationMutationCommand): Promise<unknown> {
20
- return clone(await this.#inner.mutate(clone(command)));
21
+ return wireCopy(await this.#inner.mutate(wireCopy(command)));
21
22
  }
22
23
 
23
24
  async cancel(command: OperationCancellationCommand): Promise<unknown> {
24
- return clone(await this.#inner.cancel(clone(command)));
25
+ return wireCopy(await this.#inner.cancel(wireCopy(command)));
25
26
  }
26
27
 
27
28
  async listen(listener: (event: unknown) => void): Promise<OperationUnlisten> {
28
- if (this.#inner.listen === undefined) return () => {};
29
- return this.#inner.listen((event) => listener(clone(event)));
29
+ if (this.#inner.listen === undefined) {
30
+ return () => {};
31
+ }
32
+ return this.#inner.listen((event) => listener(wireCopy(event)));
30
33
  }
31
34
 
32
35
  nextRequestId(): string {
33
36
  return this.#inner.nextRequestId();
34
37
  }
35
38
  }
36
-
37
- function clone<Value>(value: Value): Value {
38
- return JSON.parse(JSON.stringify(value)) as Value;
39
- }