@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.
- package/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/selection.ts +10 -8
- package/src/agent-control/shim.ts +149 -77
- package/src/bridge/generated/fields.ts +1 -1
- package/src/bridge/generated/protocol.ts +55 -4
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -2
- package/src/bridge/runtime/connection.ts +11 -14
- package/src/bridge/stream/connection.ts +14 -23
- package/src/bridge/stream/tracker.ts +5 -0
- package/src/bridge/supervision.ts +102 -80
- package/src/bridge/validation/base.ts +7 -27
- package/src/bridge/validation/negotiation.ts +1 -6
- package/src/bridge/validation/operations.ts +2 -14
- package/src/commands/client.ts +16 -2
- package/src/commands/controller.ts +96 -58
- package/src/commands/generated/fields.ts +4 -4
- package/src/commands/generated/protocol.ts +24 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +4 -13
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +2 -1
- package/src/commands/projectors.ts +52 -29
- package/src/commands/validation.ts +408 -188
- package/src/config/client.ts +3 -3
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +2 -1
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/validation/commands.ts +11 -13
- package/src/config/validation/outcomes.ts +147 -46
- package/src/config/validation/primitives.ts +11 -39
- package/src/config/validation/projection.ts +44 -44
- package/src/core/connection.ts +124 -29
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +76 -0
- package/src/core/transport.ts +10 -1
- package/src/core/wire-copy.ts +1 -0
- package/src/history/client.ts +11 -7
- package/src/history/controller.ts +72 -74
- package/src/history/generated/fields.ts +2 -1
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -2
- package/src/history/validation.ts +15 -37
- package/src/history-tree/client.ts +15 -13
- package/src/history-tree/controller.ts +131 -90
- package/src/history-tree/generated/fields.ts +3 -1
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +9 -4
- package/src/history-tree/validation.ts +44 -35
- package/src/layout/generated/protocol.ts +2 -1
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +9 -2
- package/src/layout/validation.ts +88 -13
- package/src/licence/client.ts +11 -7
- package/src/licence/controller.ts +64 -43
- package/src/licence/generated/fields.ts +2 -1
- package/src/licence/generated/protocol.ts +8 -4
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +2 -6
- package/src/licence/ports.ts +7 -2
- package/src/licence/validation.ts +27 -20
- package/src/native-content/client.ts +32 -1
- package/src/native-content/generated/fields.ts +4 -4
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +2 -1
- package/src/native-content/validation/base.ts +16 -46
- package/src/native-content/validation/messages.ts +3 -0
- package/src/notifications/client.ts +17 -39
- package/src/notifications/controller.ts +266 -165
- package/src/notifications/generated/fields.ts +2 -1
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +2 -1
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +41 -51
- package/src/operation/bridge.ts +79 -19
- package/src/operation/client.ts +17 -45
- package/src/operation/controller.ts +38 -59
- package/src/operation/generated/fields.ts +2 -1
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +2 -1
- package/src/operation/validation.ts +48 -50
- package/src/settings/connection.ts +10 -14
- package/src/settings/generated/fields.ts +2 -1
- package/src/settings/generated/protocol.ts +5 -1
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/validation/authority.ts +2 -2
- package/src/settings/validation/command.ts +5 -4
- package/src/settings/validation/primitives.ts +32 -67
- package/src/settings/validation/registry.ts +13 -11
- package/src/surface-transfer/generated/fields.ts +1 -1
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +76 -53
- package/src/surfaces/client.ts +26 -38
- package/src/surfaces/generated/fields.ts +1 -1
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +198 -61
- package/src/transfer/connection.ts +25 -39
- package/src/transfer/generated/fields.ts +2 -1
- package/src/transfer/generated/protocol.ts +9 -1
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +12 -9
- package/src/transfer/validation.ts +146 -60
- package/src/update/client.ts +43 -16
- package/src/update/controller.ts +187 -104
- package/src/update/generated/fields.ts +2 -1
- package/src/update/generated/protocol.ts +19 -7
- package/src/update/generated/variant-fields.ts +3 -2
- package/src/update/ports.ts +11 -7
- package/src/update/serialized.ts +8 -6
- package/src/update/validation.ts +18 -28
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
|
245
|
-
return typeof value === "
|
|
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
|
}
|
package/src/update/client.ts
CHANGED
|
@@ -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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
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
|
}
|