@inflatable-cookie/longhorn 0.6.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 (133) 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/selection.ts +10 -8
  6. package/src/agent-control/shim.ts +149 -77
  7. package/src/bridge/generated/fields.ts +1 -1
  8. package/src/bridge/generated/protocol.ts +55 -4
  9. package/src/bridge/generated/variant-fields.ts +1 -1
  10. package/src/bridge/job.ts +49 -2
  11. package/src/bridge/runtime/connection.ts +11 -14
  12. package/src/bridge/stream/connection.ts +14 -23
  13. package/src/bridge/stream/tracker.ts +5 -0
  14. package/src/bridge/supervision.ts +102 -80
  15. package/src/bridge/validation/base.ts +7 -27
  16. package/src/bridge/validation/negotiation.ts +1 -6
  17. package/src/bridge/validation/operations.ts +2 -14
  18. package/src/commands/client.ts +16 -2
  19. package/src/commands/controller.ts +96 -58
  20. package/src/commands/generated/fields.ts +4 -4
  21. package/src/commands/generated/protocol.ts +24 -1
  22. package/src/commands/generated/variant-fields.ts +1 -1
  23. package/src/commands/keyboard.ts +4 -13
  24. package/src/commands/physical-code.ts +11 -0
  25. package/src/commands/ports.ts +2 -1
  26. package/src/commands/projectors.ts +52 -29
  27. package/src/commands/validation.ts +408 -188
  28. package/src/config/client.ts +3 -3
  29. package/src/config/generated/base.ts +22 -6
  30. package/src/config/generated/fields.ts +2 -1
  31. package/src/config/generated/label-template.ts +1 -1
  32. package/src/config/generated/labels.ts +1 -1
  33. package/src/config/generated/protocol.ts +1 -1
  34. package/src/config/generated/restore.ts +35 -12
  35. package/src/config/generated/variant-fields.ts +1 -1
  36. package/src/config/validation/commands.ts +11 -13
  37. package/src/config/validation/outcomes.ts +147 -46
  38. package/src/config/validation/primitives.ts +11 -39
  39. package/src/config/validation/projection.ts +44 -44
  40. package/src/core/connection.ts +124 -29
  41. package/src/core/controller-lifecycle.ts +144 -0
  42. package/src/core/generated/identifiers.ts +4 -0
  43. package/src/core/identifiers.ts +40 -0
  44. package/src/core/index.ts +10 -1
  45. package/src/core/json-value.ts +58 -0
  46. package/src/core/listeners.ts +35 -0
  47. package/src/core/record.ts +76 -0
  48. package/src/core/transport.ts +10 -1
  49. package/src/core/wire-copy.ts +1 -0
  50. package/src/history/client.ts +11 -7
  51. package/src/history/controller.ts +72 -74
  52. package/src/history/generated/fields.ts +2 -1
  53. package/src/history/generated/protocol.ts +8 -5
  54. package/src/history/generated/variant-fields.ts +1 -1
  55. package/src/history/ports.ts +7 -2
  56. package/src/history/validation.ts +15 -37
  57. package/src/history-tree/client.ts +15 -13
  58. package/src/history-tree/controller.ts +131 -90
  59. package/src/history-tree/generated/fields.ts +3 -1
  60. package/src/history-tree/generated/protocol.ts +43 -7
  61. package/src/history-tree/generated/variant-fields.ts +7 -1
  62. package/src/history-tree/ports.ts +9 -4
  63. package/src/history-tree/validation.ts +44 -35
  64. package/src/layout/generated/protocol.ts +2 -1
  65. package/src/layout/generated/variant-fields.ts +47 -0
  66. package/src/layout/index.ts +1 -1
  67. package/src/layout/ratio.ts +9 -2
  68. package/src/layout/validation.ts +88 -13
  69. package/src/licence/client.ts +11 -7
  70. package/src/licence/controller.ts +64 -43
  71. package/src/licence/generated/fields.ts +2 -1
  72. package/src/licence/generated/protocol.ts +8 -4
  73. package/src/licence/generated/variant-fields.ts +1 -1
  74. package/src/licence/key.ts +2 -6
  75. package/src/licence/ports.ts +7 -2
  76. package/src/licence/validation.ts +27 -20
  77. package/src/native-content/client.ts +32 -1
  78. package/src/native-content/generated/fields.ts +4 -4
  79. package/src/native-content/generated/protocol.ts +16 -5
  80. package/src/native-content/generated/variant-fields.ts +1 -1
  81. package/src/native-content/ports.ts +2 -1
  82. package/src/native-content/validation/base.ts +16 -46
  83. package/src/native-content/validation/messages.ts +3 -0
  84. package/src/notifications/client.ts +17 -39
  85. package/src/notifications/controller.ts +266 -165
  86. package/src/notifications/generated/fields.ts +2 -1
  87. package/src/notifications/generated/labels.ts +1 -1
  88. package/src/notifications/generated/protocol.ts +5 -1
  89. package/src/notifications/generated/variant-fields.ts +1 -1
  90. package/src/notifications/ports.ts +2 -1
  91. package/src/notifications/tone.ts +1 -1
  92. package/src/notifications/validation.ts +41 -51
  93. package/src/operation/bridge.ts +79 -19
  94. package/src/operation/client.ts +17 -45
  95. package/src/operation/controller.ts +38 -59
  96. package/src/operation/generated/fields.ts +2 -1
  97. package/src/operation/generated/labels.ts +1 -1
  98. package/src/operation/generated/protocol.ts +5 -1
  99. package/src/operation/generated/variant-fields.ts +1 -1
  100. package/src/operation/ports.ts +2 -1
  101. package/src/operation/validation.ts +48 -50
  102. package/src/settings/connection.ts +10 -14
  103. package/src/settings/generated/fields.ts +2 -1
  104. package/src/settings/generated/protocol.ts +5 -1
  105. package/src/settings/generated/variant-fields.ts +1 -1
  106. package/src/settings/validation/authority.ts +2 -2
  107. package/src/settings/validation/command.ts +5 -4
  108. package/src/settings/validation/primitives.ts +32 -67
  109. package/src/settings/validation/registry.ts +13 -11
  110. package/src/surface-transfer/generated/fields.ts +1 -1
  111. package/src/surface-transfer/generated/protocol.ts +3 -3
  112. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  113. package/src/surface-transfer/validation.ts +76 -53
  114. package/src/surfaces/client.ts +26 -38
  115. package/src/surfaces/generated/fields.ts +1 -1
  116. package/src/surfaces/generated/protocol.ts +1 -1
  117. package/src/surfaces/generated/variant-fields.ts +1 -1
  118. package/src/surfaces/validation.ts +198 -61
  119. package/src/transfer/connection.ts +25 -39
  120. package/src/transfer/generated/fields.ts +2 -1
  121. package/src/transfer/generated/protocol.ts +9 -1
  122. package/src/transfer/generated/variant-fields.ts +1 -1
  123. package/src/transfer/index.ts +8 -1
  124. package/src/transfer/payload.ts +12 -9
  125. package/src/transfer/validation.ts +146 -60
  126. package/src/update/client.ts +43 -16
  127. package/src/update/controller.ts +187 -104
  128. package/src/update/generated/fields.ts +2 -1
  129. package/src/update/generated/protocol.ts +19 -7
  130. package/src/update/generated/variant-fields.ts +3 -2
  131. package/src/update/ports.ts +11 -7
  132. package/src/update/serialized.ts +8 -6
  133. package/src/update/validation.ts +18 -28
@@ -1,4 +1,13 @@
1
- import { isRecord } from "../core/record.ts";
1
+ import { isOpaqueId, matchesDomainIdRule } from "../core/identifiers.ts";
2
+ import {
3
+ checkWireFields,
4
+ readWireRecord,
5
+ signed32,
6
+ unsigned32,
7
+ unsignedInteger,
8
+ wireVariantFields,
9
+ } from "../core/record.ts";
10
+ import { BRIDGE_DOMAIN_ID_RULE } from "../bridge/generated/protocol.ts";
2
11
  import {
3
12
  TRANSFER_VARIANT_FIELDS,
4
13
  TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
@@ -11,9 +20,13 @@ import {
11
20
  TRANSFER_COMMIT_SELECTOR_KINDS,
12
21
  TRANSFER_ERROR_CODES,
13
22
  TRANSFER_LEASE_RESPONSE_STATUSES,
23
+ TRANSFER_PANEL_HOST_BINDING_KINDS,
14
24
  TRANSFER_PROTOCOL_VERSION,
25
+ TRANSFER_SCREEN_POINT_FIELDS,
26
+ TRANSFER_SESSION_CANCELLATION_STATUSES,
15
27
  TRANSFER_SESSION_RESPONSE_STATUSES,
16
28
  TRANSFER_TARGET_BINDING_KINDS,
29
+ TRANSFER_TARGET_RESOLUTION_PATHS,
17
30
  } from "./generated/protocol.ts";
18
31
  import type {
19
32
  PanelTransferResponse,
@@ -21,12 +34,16 @@ import type {
21
34
  TransferCancelResponse,
22
35
  TransferClientSnapshot,
23
36
  TransferCommitSelector,
37
+ TransferCommittedTarget,
24
38
  TransferLeaseResponse,
25
39
  TransferSessionResponse,
40
+ TransferSessionStarted,
26
41
  TransferTargetBinding,
27
42
  } from "./generated/protocol.ts";
43
+ import { isTransferSessionId } from "./payload.ts";
28
44
  import { TRANSFER_FIELDS } from "./generated/fields.ts";
29
45
  import { assertValidLayoutMutationRejectionCode } from "@inflatable-cookie/longhorn/layout";
46
+ import { assertValidSurfaceDocument } from "@inflatable-cookie/longhorn/surfaces";
30
47
 
31
48
  export type TransferProtocolValidationCode =
32
49
  | "unsupported_protocol_version"
@@ -67,6 +84,14 @@ export function assertValidTransferTargetBinding(
67
84
  const candidate = record(value);
68
85
  assertKnown(candidate.kind, TRANSFER_TARGET_BINDING_KINDS, "unknown_target_binding");
69
86
  record(candidate, variantKeys("TransferTargetBinding", candidate));
87
+ assertFields(candidate, {
88
+ host_binding_id: isOpaqueId,
89
+ document_id: isDomainId,
90
+ revision: unsignedInteger,
91
+ });
92
+ if (candidate.kind === "panel_region") {
93
+ assertFields(candidate, { surface_id: isOpaqueId, region_id: isOpaqueId });
94
+ }
70
95
  }
71
96
 
72
97
  export function assertValidTransferClientSnapshot(
@@ -74,9 +99,11 @@ export function assertValidTransferClientSnapshot(
74
99
  ): asserts value is TransferClientSnapshot {
75
100
  const snapshot = record(value, TRANSFER_FIELDS.TransferClientSnapshot);
76
101
  assertTransferProtocolVersion(snapshot.protocol_version);
77
- if (typeof snapshot.client_id !== "string" || !unsignedInteger(snapshot.client_epoch)) {
78
- throw new TransferProtocolValidationError("invalid_client_snapshot", value);
79
- }
102
+ assertFields(
103
+ snapshot,
104
+ { client_id: isOpaqueId, client_epoch: unsignedInteger },
105
+ "invalid_client_snapshot",
106
+ );
80
107
  }
81
108
 
82
109
  export function assertValidTransferCommitSelector(
@@ -85,11 +112,29 @@ export function assertValidTransferCommitSelector(
85
112
  const candidate = record(value);
86
113
  assertKnown(candidate.kind, TRANSFER_COMMIT_SELECTOR_KINDS, "unknown_commit_selector");
87
114
  record(candidate, variantKeys("TransferCommitSelector", candidate));
115
+ if (candidate.kind === "explicit_zone") {
116
+ assertFields(candidate, { drop_zone_id: isOpaqueId });
117
+ } else {
118
+ assertValidTransferScreenPoint(candidate.point);
119
+ }
120
+ }
121
+
122
+ /** A Rust `ScreenPoint`: integral screen-DIP coordinates. */
123
+ export function assertValidTransferScreenPoint(
124
+ value: unknown,
125
+ ): asserts value is { x: number; y: number } {
126
+ assertFields(record(value, TRANSFER_SCREEN_POINT_FIELDS), { x: signed32, y: signed32 });
88
127
  }
89
128
 
90
129
  export function assertValidTransferAbort(value: unknown): asserts value is TransferAbort {
91
130
  const abort = record(value, TRANSFER_FIELDS.TransferAbort);
92
131
  assertTransferProtocolVersion(abort.protocol_version);
132
+ assertFields(abort, {
133
+ request_id: isOpaqueId,
134
+ message: isString,
135
+ retryable: isBoolean,
136
+ session_consumed: isBoolean,
137
+ });
93
138
  const source = record(abort.source);
94
139
  assertKnown(source.domain, TRANSFER_ABORT_DOMAINS, "unknown_abort_domain");
95
140
  record(source, variantKeys("TransferAbortSource", source));
@@ -103,6 +148,30 @@ export function assertValidTransferAbort(value: unknown): asserts value is Trans
103
148
  }
104
149
  }
105
150
 
151
+ export function assertValidTransferSessionStarted(
152
+ value: unknown,
153
+ ): asserts value is TransferSessionStarted {
154
+ const session = record(value, TRANSFER_FIELDS.TransferSessionStarted);
155
+ assertTransferProtocolVersion(session.protocol_version);
156
+ const payload = record(session.payload, TRANSFER_FIELDS.TransferPayload);
157
+ assertTransferProtocolVersion(payload.protocol_version);
158
+ assertFields(session, { request_id: isOpaqueId });
159
+ assertFields(payload, { session_id: isTransferSessionId });
160
+ }
161
+
162
+ export function assertValidTransferCommittedTarget(
163
+ value: unknown,
164
+ ): asserts value is TransferCommittedTarget {
165
+ const target = record(value, TRANSFER_FIELDS.TransferCommittedTarget);
166
+ assertKnown(target.path, TRANSFER_TARGET_RESOLUTION_PATHS, "invalid_object");
167
+ assertFields(target, {
168
+ window_id: isOpaqueId,
169
+ drop_zone_id: isOpaqueId,
170
+ insertion_position: isNullableUnsigned32,
171
+ });
172
+ assertValidTransferTargetBinding(target.binding);
173
+ }
174
+
106
175
  export function assertValidTransferSessionResponse(
107
176
  value: unknown,
108
177
  ): asserts value is TransferSessionResponse {
@@ -112,9 +181,7 @@ export function assertValidTransferSessionResponse(
112
181
  "TransferSessionResponse",
113
182
  );
114
183
  if (response.status === "started") {
115
- const session = record(response.session, TRANSFER_FIELDS.TransferSessionStarted);
116
- assertTransferProtocolVersion(session.protocol_version);
117
- assertTransferProtocolVersion(record(session.payload).protocol_version);
184
+ assertValidTransferSessionStarted(response.session);
118
185
  } else {
119
186
  assertValidTransferAbort(response.abort);
120
187
  }
@@ -129,7 +196,15 @@ export function assertValidTransferLeaseResponse(
129
196
  "TransferLeaseResponse",
130
197
  );
131
198
  if (response.status === "published") {
132
- assertTransferProtocolVersion(record(response.lease).protocol_version);
199
+ const lease = record(response.lease, TRANSFER_FIELDS.TransferLeaseReceipt);
200
+ assertTransferProtocolVersion(lease.protocol_version);
201
+ assertFields(lease, {
202
+ request_id: isOpaqueId,
203
+ client_id: isOpaqueId,
204
+ client_epoch: unsignedInteger,
205
+ generation: unsignedInteger,
206
+ zone_count: unsignedInteger,
207
+ });
133
208
  } else {
134
209
  assertValidTransferAbort(response.abort);
135
210
  }
@@ -144,7 +219,10 @@ export function assertValidTransferCancelResponse(
144
219
  "TransferCancelResponse",
145
220
  );
146
221
  if (response.status === "cancelled") {
147
- assertTransferProtocolVersion(record(response.cancellation).protocol_version);
222
+ const cancellation = record(response.cancellation, TRANSFER_FIELDS.TransferCancelReceipt);
223
+ assertTransferProtocolVersion(cancellation.protocol_version);
224
+ assertFields(cancellation, { request_id: isOpaqueId, session_id: isTransferSessionId });
225
+ assertKnown(cancellation.status, TRANSFER_SESSION_CANCELLATION_STATUSES, "invalid_object");
148
226
  } else {
149
227
  assertValidTransferAbort(response.abort);
150
228
  }
@@ -159,15 +237,29 @@ export function assertValidPanelTransferResponse(
159
237
  "PanelTransferResponse",
160
238
  );
161
239
  if (response.status === "committed") {
162
- const completion = record(response.completion, TRANSFER_FIELDS.PanelTransferCompletion);
163
- assertTransferProtocolVersion(completion.protocol_version);
164
- // oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
165
- assertValidTransferTargetBinding(record(record(completion.target).binding));
240
+ assertPanelTransferCompletion(response.completion);
166
241
  } else {
167
242
  assertValidTransferAbort(response.abort);
168
243
  }
169
244
  }
170
245
 
246
+ function assertPanelTransferCompletion(value: unknown): void {
247
+ const completion = record(value, TRANSFER_FIELDS.PanelTransferCompletion);
248
+ assertTransferProtocolVersion(completion.protocol_version);
249
+ assertFields(completion, {
250
+ request_id: isOpaqueId,
251
+ session_id: isTransferSessionId,
252
+ source_host_binding_id: isOpaqueId,
253
+ target_host_binding_id: isOpaqueId,
254
+ previous_revision: unsignedInteger,
255
+ committed_revision: unsignedInteger,
256
+ });
257
+ assertKnown(completion.source_binding_kind, TRANSFER_PANEL_HOST_BINDING_KINDS, "invalid_object");
258
+ assertKnown(completion.target_binding_kind, TRANSFER_PANEL_HOST_BINDING_KINDS, "invalid_object");
259
+ assertValidSurfaceDocument(completion.authoritative_document);
260
+ assertValidTransferCommittedTarget(completion.target);
261
+ }
262
+
171
263
  function responseWithStatus(
172
264
  value: unknown,
173
265
  statuses: ReadonlyArray<string>,
@@ -179,25 +271,16 @@ function responseWithStatus(
179
271
  return response;
180
272
  }
181
273
 
182
- /**
183
- * Allowed keys for one tagged-union variant, from the generated map, with the
184
- * discriminant's name read from the map too — this domain tags on `kind`,
185
- * `status` and `domain`.
186
- *
187
- * A missing entry means the generator failed to read the union; every caller
188
- * runs `assertKnown` over the discriminant above this.
189
- */
190
274
  function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
191
- const discriminant = value[TRANSFER_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
192
- const keys =
193
- typeof discriminant === "string" ? TRANSFER_VARIANT_FIELDS[type]?.[discriminant] : undefined;
194
- if (keys === undefined) {
195
- throw new TransferProtocolValidationError("unknown_response_status", {
196
- type,
197
- discriminant,
198
- });
199
- }
200
- return keys;
275
+ return wireVariantFields(
276
+ TRANSFER_VARIANT_FIELDS,
277
+ TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
278
+ type,
279
+ value,
280
+ (discriminant) => {
281
+ throw new TransferProtocolValidationError("unknown_response_status", { type, discriminant });
282
+ },
283
+ );
201
284
  }
202
285
 
203
286
  function assertKnown(
@@ -210,37 +293,40 @@ function assertKnown(
210
293
  }
211
294
  }
212
295
 
213
- /**
214
- * Rejects a non-object, an unknown key, and a missing key.
215
- *
216
- * `allowed` comes from the generated field map, so the keys accepted are the
217
- * Rust struct's and nothing else — contract 010's Boundary Validation Target.
218
- * Passing no list keeps shape-only behaviour for the tagged unions, whose
219
- * allowed keys depend on their discriminant and so are not one flat set.
220
- */
221
- function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
222
- if (!isRecord(value)) {
223
- throw new TransferProtocolValidationError("invalid_object", value);
224
- }
225
- const result = value;
226
- if (allowed === undefined) {
227
- return result;
228
- }
229
-
230
- const permitted = new Set(allowed);
231
- for (const key of Object.keys(result)) {
232
- if (!permitted.has(key)) {
233
- throw new TransferProtocolValidationError("unknown_field", { key, value });
234
- }
235
- }
236
- for (const key of allowed) {
237
- if (!(key in result)) {
238
- throw new TransferProtocolValidationError("missing_field", { key, value });
296
+ function assertFields(
297
+ value: Record<string, unknown>,
298
+ checks: Readonly<Record<string, (member: unknown) => boolean>>,
299
+ code: TransferProtocolValidationCode = "invalid_object",
300
+ ): void {
301
+ for (const [key, admits] of Object.entries(checks)) {
302
+ if (!admits(value[key])) {
303
+ throw new TransferProtocolValidationError(code, { key, value });
239
304
  }
240
305
  }
241
- return result;
242
306
  }
243
307
 
244
- function unsignedInteger(value: unknown): value is number {
245
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
308
+ function isString(value: unknown): boolean {
309
+ return typeof value === "string";
310
+ }
311
+
312
+ function isBoolean(value: unknown): boolean {
313
+ return typeof value === "boolean";
314
+ }
315
+
316
+ function isDomainId(value: unknown): boolean {
317
+ return matchesDomainIdRule(value, BRIDGE_DOMAIN_ID_RULE);
318
+ }
319
+
320
+ function isNullableUnsigned32(value: unknown): boolean {
321
+ return value === null || unsigned32(value);
322
+ }
323
+
324
+ function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
325
+ const result = readWireRecord(value, () => {
326
+ throw new TransferProtocolValidationError("invalid_object", value);
327
+ });
328
+ checkWireFields(result, allowed, (code, key) => {
329
+ throw new TransferProtocolValidationError(code, { key, value });
330
+ });
331
+ return result;
246
332
  }
@@ -1,3 +1,5 @@
1
+ import { listenChecked, reportFailure } from "../core/connection.ts";
2
+ import type { ConnectionFailureReporter } from "../core/connection.ts";
1
3
  import type {
2
4
  UpdateApplyCommand,
3
5
  UpdateCancelCommand,
@@ -55,6 +57,38 @@ export class UpdateClient implements CheckedUpdatePort {
55
57
  assertUpdateOutcome(value);
56
58
  return value;
57
59
  }
60
+ /**
61
+ * Prepares with live reports when the port can scope them to this invocation.
62
+ *
63
+ * A malformed report ends delivery for this invocation and is reported to
64
+ * `onFailure` with phase `event`; the prepare itself still settles.
65
+ */
66
+ async prepareWithProgress(
67
+ command: UpdatePrepareCommand,
68
+ listener: (event: UpdateProgressEvent) => void,
69
+ onFailure?: ConnectionFailureReporter,
70
+ ): Promise<UpdateOutcomeProjection> {
71
+ if (this.port.prepareWithProgress === undefined) {
72
+ return this.prepare(command);
73
+ }
74
+ assertUpdatePrepareCommand(command);
75
+ let malformed = false;
76
+ const value = await this.port.prepareWithProgress(command, (event) => {
77
+ if (malformed) {
78
+ return;
79
+ }
80
+ try {
81
+ assertUpdateProgressEvent(event);
82
+ } catch (error) {
83
+ malformed = true;
84
+ reportFailure(onFailure, { phase: "event", error });
85
+ return;
86
+ }
87
+ listener(event);
88
+ });
89
+ assertUpdateOutcome(value);
90
+ return value;
91
+ }
58
92
  async apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection> {
59
93
  assertUpdateApplyCommand(command);
60
94
  const value = await this.port.apply(command);
@@ -67,22 +101,15 @@ export class UpdateClient implements CheckedUpdatePort {
67
101
  assertUpdateOutcome(value);
68
102
  return value;
69
103
  }
70
- async listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten> {
71
- if (this.port.listen === undefined) {
72
- return () => {};
73
- }
74
- return this.port.listen((value) => {
75
- assertUpdateChangedEvent(value);
76
- listener(value);
77
- });
78
- }
79
- async listenProgress(listener: (event: UpdateProgressEvent) => void): Promise<UpdateUnlisten> {
80
- if (this.port.listenProgress === undefined) {
81
- return () => {};
82
- }
83
- return this.port.listenProgress((value) => {
84
- assertUpdateProgressEvent(value);
85
- listener(value);
104
+ listen(
105
+ listener: (event: UpdateChangedEvent) => void,
106
+ onFailure?: ConnectionFailureReporter,
107
+ ): Promise<UpdateUnlisten> {
108
+ return listenChecked({
109
+ listen: (receive) => this.port.listen?.(receive) ?? (() => {}),
110
+ validate: assertUpdateChangedEvent,
111
+ listener,
112
+ onFailure,
86
113
  });
87
114
  }
88
115
  }