@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 } from "../core/identifiers.ts";
|
|
2
|
+
import { isUnicodeText } from "../core/json-value.ts";
|
|
3
|
+
import { isLayoutRatio } from "../layout/ratio.ts";
|
|
4
|
+
import {
|
|
5
|
+
checkWireFields,
|
|
6
|
+
readWireRecord,
|
|
7
|
+
unsigned32,
|
|
8
|
+
unsignedInteger,
|
|
9
|
+
wireVariantFields,
|
|
10
|
+
} from "../core/record.ts";
|
|
2
11
|
import {
|
|
3
12
|
SURFACE_VARIANT_FIELDS,
|
|
4
13
|
SURFACE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -11,6 +20,7 @@ import {
|
|
|
11
20
|
} from "./generated/protocol.ts";
|
|
12
21
|
import type {
|
|
13
22
|
SurfaceChangedEvent,
|
|
23
|
+
SurfaceDocument,
|
|
14
24
|
SurfaceMutationCommand,
|
|
15
25
|
SurfaceMutationOutcome,
|
|
16
26
|
SurfaceMutationRejectionCode,
|
|
@@ -25,6 +35,7 @@ export type SurfaceProtocolValidationCode =
|
|
|
25
35
|
| "unknown_outcome"
|
|
26
36
|
| "unknown_rejection_code"
|
|
27
37
|
| "unknown_response_status"
|
|
38
|
+
| "uncorrelated_response"
|
|
28
39
|
| "invalid_object"
|
|
29
40
|
| "unknown_field"
|
|
30
41
|
| "missing_field";
|
|
@@ -85,22 +96,30 @@ export function assertValidSurfaceMutationRejectionCode(
|
|
|
85
96
|
export function assertValidSurfaceMutationResponse(
|
|
86
97
|
value: unknown,
|
|
87
98
|
): asserts value is SurfaceMutationResponse {
|
|
88
|
-
// Was `record(value, SURFACE_FIELDS.SurfaceMutationResponse)`. The flat
|
|
89
|
-
// field map skips unions by design, so that lookup was `undefined` and
|
|
90
|
-
// `record` checked no keys at all -- a call that read as strict and was not.
|
|
91
99
|
const response = record(value);
|
|
92
100
|
switch (response.status) {
|
|
93
101
|
case "committed": {
|
|
94
102
|
record(response, variantKeys("SurfaceMutationResponse", response));
|
|
95
103
|
const receipt = record(response.receipt, SURFACE_FIELDS.SurfaceMutationReceipt);
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
assertFields(receipt, {
|
|
105
|
+
request_id: isOpaqueId,
|
|
106
|
+
previous_revision: unsignedInteger,
|
|
107
|
+
committed_revision: unsignedInteger,
|
|
108
|
+
});
|
|
109
|
+
assertValidSurfaceMutationOutcome(receipt.outcome);
|
|
110
|
+
assertValidSurfaceDocument(receipt.authoritative_document);
|
|
98
111
|
return;
|
|
99
112
|
}
|
|
100
113
|
case "rejected": {
|
|
101
114
|
record(response, variantKeys("SurfaceMutationResponse", response));
|
|
102
115
|
const rejection = record(response.rejection, SURFACE_FIELDS.SurfaceMutationRejection);
|
|
116
|
+
assertFields(rejection, {
|
|
117
|
+
request_id: isOpaqueId,
|
|
118
|
+
current_revision: unsignedInteger,
|
|
119
|
+
detail: isString,
|
|
120
|
+
});
|
|
103
121
|
assertValidSurfaceMutationRejectionCode(rejection.code);
|
|
122
|
+
assertValidSurfaceDocument(rejection.authoritative_document);
|
|
104
123
|
return;
|
|
105
124
|
}
|
|
106
125
|
default:
|
|
@@ -109,13 +128,161 @@ export function assertValidSurfaceMutationResponse(
|
|
|
109
128
|
}
|
|
110
129
|
|
|
111
130
|
export function assertValidSurfaceSnapshot(value: unknown): asserts value is SurfaceSnapshot {
|
|
112
|
-
|
|
131
|
+
const snapshot = record(value, SURFACE_FIELDS.SurfaceSnapshot);
|
|
132
|
+
assertSurfaceCursor(snapshot);
|
|
133
|
+
const document = snapshot.document;
|
|
134
|
+
assertValidSurfaceDocument(document);
|
|
135
|
+
if (document.revision !== snapshot.revision) {
|
|
136
|
+
throw new SurfaceProtocolValidationError("invalid_object", document);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The whole authoritative document a snapshot, receipt or transfer carries. */
|
|
141
|
+
export function assertValidSurfaceDocument(value: unknown): asserts value is SurfaceDocument {
|
|
142
|
+
const document = record(value, SURFACE_FIELDS.SurfaceDocument);
|
|
143
|
+
assertFields(document, { revision: unsignedInteger });
|
|
144
|
+
for (const entry of array(document.surfaces)) {
|
|
145
|
+
validateSurface(entry);
|
|
146
|
+
}
|
|
147
|
+
for (const entry of array(document.panel_instances)) {
|
|
148
|
+
assertFields(record(entry, SURFACE_FIELDS.PanelInstance), {
|
|
149
|
+
id: isOpaqueId,
|
|
150
|
+
definition_id: isOpaqueId,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
for (const entry of array(document.windows)) {
|
|
154
|
+
assertFields(record(entry, SURFACE_FIELDS.ParticipatingWindow), {
|
|
155
|
+
id: isOpaqueId,
|
|
156
|
+
active_surface_id: isNullableId,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
113
159
|
}
|
|
114
160
|
|
|
115
161
|
export function assertValidSurfaceChangedEvent(
|
|
116
162
|
value: unknown,
|
|
117
163
|
): asserts value is SurfaceChangedEvent {
|
|
118
|
-
|
|
164
|
+
assertSurfaceCursor(record(value, SURFACE_FIELDS.SurfaceChangedEvent));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function assertSurfaceCursor(value: Record<string, unknown>): void {
|
|
168
|
+
assertSurfaceProtocolVersion(value.protocol_version);
|
|
169
|
+
if (!unsignedInteger(value.epoch) || !unsignedInteger(value.revision)) {
|
|
170
|
+
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function validateSurface(value: unknown): void {
|
|
175
|
+
const surface = record(value, SURFACE_FIELDS.SurfaceRecord);
|
|
176
|
+
assertFields(surface, { id: isOpaqueId, schema_id: isOpaqueId, label: isNullableText });
|
|
177
|
+
validatePresentation(surface.presentation);
|
|
178
|
+
for (const entry of array(surface.regions)) {
|
|
179
|
+
const region = record(entry, SURFACE_FIELDS.RegionState);
|
|
180
|
+
assertFields(region, {
|
|
181
|
+
region_id: isOpaqueId,
|
|
182
|
+
active_panel_instance_id: isNullableId,
|
|
183
|
+
collapsed: isNullableBoolean,
|
|
184
|
+
});
|
|
185
|
+
assertIds(region.panel_instance_ids);
|
|
186
|
+
}
|
|
187
|
+
for (const entry of array(surface.sizing_slots)) {
|
|
188
|
+
assertFields(record(entry, SURFACE_FIELDS.SizingSlotState), {
|
|
189
|
+
sizing_slot_id: isOpaqueId,
|
|
190
|
+
ratio: isLayoutRatio,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
validateHostPreferences(surface.host_preferences);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function validatePresentation(value: unknown): void {
|
|
197
|
+
const presentation = record(value);
|
|
198
|
+
record(presentation, variantKeys("SurfacePresentation", presentation));
|
|
199
|
+
if (presentation.kind === "focused_panel") {
|
|
200
|
+
assertFields(presentation, { panel_definition_id: isOpaqueId });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function validateHostPreferences(value: unknown): void {
|
|
205
|
+
for (const entry of array(value)) {
|
|
206
|
+
assertFields(record(entry, SURFACE_FIELDS.SurfaceHostPreference), {
|
|
207
|
+
window_id: isOpaqueId,
|
|
208
|
+
order: unsigned32,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type MutationFields<Variant> = Variant extends { kind: string }
|
|
214
|
+
? Exclude<keyof Variant, "kind">
|
|
215
|
+
: never;
|
|
216
|
+
|
|
217
|
+
// Each check throws, and a new Rust variant field fails to typecheck until it
|
|
218
|
+
// has one.
|
|
219
|
+
const mutationFields = {
|
|
220
|
+
surface_id: field(isOpaqueId),
|
|
221
|
+
source_surface_id: field(isOpaqueId),
|
|
222
|
+
schema_id: field(isOpaqueId),
|
|
223
|
+
window_id: field(isOpaqueId),
|
|
224
|
+
source_window_id: field(isOpaqueId),
|
|
225
|
+
target_window_id: field(isOpaqueId),
|
|
226
|
+
previous_active_surface_id: field(isNullableId),
|
|
227
|
+
label: field(isNullableText),
|
|
228
|
+
insertion_index: field(unsigned32),
|
|
229
|
+
surface_ids: assertIds,
|
|
230
|
+
host_preferences: validateHostPreferences,
|
|
231
|
+
presentation: validatePresentation,
|
|
232
|
+
previous_presentation: validatePresentation,
|
|
233
|
+
} satisfies Record<
|
|
234
|
+
MutationFields<SurfaceMutationCommand | SurfaceMutationOutcome>,
|
|
235
|
+
(value: unknown) => void
|
|
236
|
+
>;
|
|
237
|
+
|
|
238
|
+
function field(admits: (value: unknown) => boolean): (value: unknown) => void {
|
|
239
|
+
return (value) => {
|
|
240
|
+
if (!admits(value)) {
|
|
241
|
+
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function assertFields(
|
|
247
|
+
value: Record<string, unknown>,
|
|
248
|
+
checks: Readonly<Record<string, (member: unknown) => boolean>>,
|
|
249
|
+
): void {
|
|
250
|
+
for (const [key, admits] of Object.entries(checks)) {
|
|
251
|
+
if (!admits(value[key])) {
|
|
252
|
+
throw new SurfaceProtocolValidationError("invalid_object", { key, value });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function assertIds(value: unknown): void {
|
|
258
|
+
for (const id of array(value)) {
|
|
259
|
+
if (!isOpaqueId(id)) {
|
|
260
|
+
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function isString(value: unknown): boolean {
|
|
266
|
+
return typeof value === "string";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isNullableText(value: unknown): boolean {
|
|
270
|
+
return value === null || (typeof value === "string" && isUnicodeText(value));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function isNullableId(value: unknown): boolean {
|
|
274
|
+
return value === null || isOpaqueId(value);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function isNullableBoolean(value: unknown): boolean {
|
|
278
|
+
return value === null || typeof value === "boolean";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function array(value: unknown): ReadonlyArray<unknown> {
|
|
282
|
+
if (!Array.isArray(value)) {
|
|
283
|
+
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
284
|
+
}
|
|
285
|
+
return value;
|
|
119
286
|
}
|
|
120
287
|
|
|
121
288
|
function assertKnownKind(
|
|
@@ -128,63 +295,33 @@ function assertKnownKind(
|
|
|
128
295
|
if (typeof candidate.kind !== "string" || !known.includes(candidate.kind)) {
|
|
129
296
|
throw new SurfaceProtocolValidationError(code, value);
|
|
130
297
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
298
|
+
const keys = variantKeys(type, candidate);
|
|
299
|
+
record(candidate, keys);
|
|
300
|
+
for (const [name, check] of Object.entries(mutationFields)) {
|
|
301
|
+
if (keys.includes(name)) {
|
|
302
|
+
check(candidate[name]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
134
305
|
}
|
|
135
306
|
|
|
136
|
-
/**
|
|
137
|
-
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
138
|
-
* discriminant's name read from the map too.
|
|
139
|
-
*/
|
|
140
307
|
function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
* `allowed` comes from the generated field map, so the keys this accepts are
|
|
154
|
-
* the Rust struct's and nothing else — contract 010's Boundary Validation
|
|
155
|
-
* Target. Passing no list keeps the old shape-only behaviour for the tagged
|
|
156
|
-
* unions, whose allowed keys depend on their discriminant and so are not one
|
|
157
|
-
* flat set.
|
|
158
|
-
*
|
|
159
|
-
* The non-object case used to throw `unknown_response_status`, because the
|
|
160
|
-
* incompatibility union had no code for it. It reported the wrong thing for
|
|
161
|
-
* every caller but one.
|
|
162
|
-
*/
|
|
308
|
+
return wireVariantFields(
|
|
309
|
+
SURFACE_VARIANT_FIELDS,
|
|
310
|
+
SURFACE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
311
|
+
type,
|
|
312
|
+
value,
|
|
313
|
+
(discriminant) => {
|
|
314
|
+
throw new SurfaceProtocolValidationError("unknown_outcome", { type, discriminant });
|
|
315
|
+
},
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
163
319
|
function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
|
|
164
|
-
|
|
320
|
+
const result = readWireRecord(value, () => {
|
|
165
321
|
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const permitted = new Set(allowed);
|
|
173
|
-
for (const key of Object.keys(result)) {
|
|
174
|
-
if (!permitted.has(key)) {
|
|
175
|
-
throw new SurfaceProtocolValidationError("unknown_field", {
|
|
176
|
-
key,
|
|
177
|
-
value,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
for (const key of allowed) {
|
|
182
|
-
if (!(key in result)) {
|
|
183
|
-
throw new SurfaceProtocolValidationError("missing_field", {
|
|
184
|
-
key,
|
|
185
|
-
value,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
322
|
+
});
|
|
323
|
+
checkWireFields(result, allowed, (code, key) => {
|
|
324
|
+
throw new SurfaceProtocolValidationError(code, { key, value });
|
|
325
|
+
});
|
|
189
326
|
return result;
|
|
190
327
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { CheckedSnapshotConnection } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type {
|
|
3
|
-
ConnectionFailure,
|
|
4
|
-
ConnectionFailureReporter,
|
|
5
|
-
EventTransport,
|
|
6
|
-
} from "@inflatable-cookie/longhorn/core";
|
|
1
|
+
import { CheckedSnapshotConnection, CheckedSubscription } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { ConnectionFailureReporter, EventTransport } from "@inflatable-cookie/longhorn/core";
|
|
7
3
|
|
|
8
4
|
import type { TransferClientSnapshot } from "./generated/protocol.ts";
|
|
9
5
|
import { assertValidTransferClientSnapshot } from "./validation.ts";
|
|
@@ -12,45 +8,35 @@ export const TRANSFER_CLIENT_CHANGED_EVENT = "longhorn://transfer/client-changed
|
|
|
12
8
|
|
|
13
9
|
export type TransferClientSnapshotListener = (snapshot: TransferClientSnapshot) => void;
|
|
14
10
|
|
|
15
|
-
export class TransferClientConnection
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
export class TransferClientConnection extends CheckedSubscription<
|
|
12
|
+
TransferClientSnapshot,
|
|
13
|
+
TransferClientSnapshot
|
|
14
|
+
> {
|
|
20
15
|
constructor(
|
|
21
16
|
transport: EventTransport,
|
|
22
17
|
loadSnapshot: () => Promise<TransferClientSnapshot>,
|
|
23
18
|
listener?: TransferClientSnapshotListener,
|
|
24
19
|
onFailure?: ConnectionFailureReporter,
|
|
25
20
|
) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return this.#connection.current();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
failures(): ReadonlyArray<ConnectionFailure> {
|
|
49
|
-
return this.#connection.failures();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
dispose(): Promise<void> {
|
|
53
|
-
return this.#connection.dispose();
|
|
21
|
+
super(
|
|
22
|
+
new CheckedSnapshotConnection({
|
|
23
|
+
listen: (receive) =>
|
|
24
|
+
transport.listen(TRANSFER_CLIENT_CHANGED_EVENT, receive, { scope: "current-webview" }),
|
|
25
|
+
loadSnapshot,
|
|
26
|
+
validateSnapshot: parseTransferClientSnapshot,
|
|
27
|
+
handleEvent: (value) => ({ kind: "snapshot", value }),
|
|
28
|
+
isNewer: isCurrentTransferClientSnapshot,
|
|
29
|
+
onSnapshot: listener,
|
|
30
|
+
onFailure,
|
|
31
|
+
disposedBeforeReadyError: () => new TransferClientConnectionDisposedError(),
|
|
32
|
+
}),
|
|
33
|
+
(snapshot) => {
|
|
34
|
+
if (snapshot === undefined) {
|
|
35
|
+
throw new TransferClientConnectionDisposedError();
|
|
36
|
+
}
|
|
37
|
+
return snapshot;
|
|
38
|
+
},
|
|
39
|
+
);
|
|
54
40
|
}
|
|
55
41
|
}
|
|
56
42
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
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.
|
|
@@ -20,4 +20,5 @@ export const TRANSFER_FIELDS = {
|
|
|
20
20
|
"TransferCommittedTarget": ["path", "window_id", "drop_zone_id", "insertion_position", "binding"],
|
|
21
21
|
"PanelTransferCompletion": ["protocol_version", "request_id", "session_id", "source_host_binding_id", "target_host_binding_id", "source_binding_kind", "target_binding_kind", "previous_revision", "committed_revision", "authoritative_document", "target"],
|
|
22
22
|
"TransferAbort": ["protocol_version", "request_id", "source", "layout_code", "message", "retryable", "session_consumed"],
|
|
23
|
+
"TransferHostError": ["code", "message", "retryable"],
|
|
23
24
|
} as const;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority.
|
|
3
3
|
|
|
4
4
|
import type { LayoutMutationRejectionCode, SurfaceId, SurfaceDocument, SurfaceRevision, PanelInstanceId, RegionId } from "@inflatable-cookie/longhorn/layout";
|
|
@@ -10,7 +10,11 @@ export const TRANSFER_ABORT_DOMAINS = ["transfer","panel"] as const;
|
|
|
10
10
|
export const TRANSFER_SESSION_RESPONSE_STATUSES = ["started","aborted"] as const;
|
|
11
11
|
export const TRANSFER_LEASE_RESPONSE_STATUSES = ["published","aborted"] as const;
|
|
12
12
|
export const TRANSFER_CANCEL_RESPONSE_STATUSES = ["cancelled","aborted"] as const;
|
|
13
|
+
export const TRANSFER_SESSION_CANCELLATION_STATUSES = ["cancelled","already_cancelled"] as const;
|
|
13
14
|
export const PANEL_TRANSFER_RESPONSE_STATUSES = ["committed","aborted"] as const;
|
|
15
|
+
export const TRANSFER_TARGET_RESOLUTION_PATHS = ["explicit_zone","screen_point"] as const;
|
|
16
|
+
export const TRANSFER_PANEL_HOST_BINDING_KINDS = ["direct_window","surface_container"] as const;
|
|
17
|
+
export const TRANSFER_SCREEN_POINT_FIELDS = ["x","y"] as const;
|
|
14
18
|
export const TRANSFER_ERROR_CODES = ["clock_regressed","invalid_lifetime","session_capacity","session_id_allocation","session_id_collision","unknown_session","session_expired","session_cancelled","session_replayed","source_window_destroyed","source_client_changed","client_window_capacity","unknown_client_epoch","stale_client_epoch","stale_lease_generation","lease_capacity","invalid_lease","lease_expired","invalid_live_windows","target_window_missing","stale_window_geometry","no_target","ambiguous_window","ambiguous_zone","ineligible_capability"] as const;
|
|
15
19
|
export const PANEL_TRANSFER_ERROR_CODES = ["invalid_binding_snapshot","unknown_host_binding","stale_host_binding","layout_load_failed","layout_unavailable","unknown_panel","panel_not_movable","source_changed","unsupported_source","unsupported_target","cross_document","copy_unsupported","stale_surface_revision","target_changed","ineligible_target","instance_policy_exceeded","invalid_insertion_position","layout_mutation_rejected","publication_failed","transfer_rejected"] as const;
|
|
16
20
|
|
|
@@ -169,3 +173,7 @@ completion: PanelTransferCompletion, } | { "status": "aborted",
|
|
|
169
173
|
* Typed rejection and consumption evidence.
|
|
170
174
|
*/
|
|
171
175
|
abort: TransferAbort, };
|
|
176
|
+
|
|
177
|
+
export type TransferHostErrorCode = "runtimeUnavailable" | "stateUnavailable" | "inactive" | "identityExhausted" | "invalidIssuedClientId" | "clientBinding" | "invalidCallerHandle";
|
|
178
|
+
|
|
179
|
+
export type TransferHostError = { "code": TransferHostErrorCode, "message": string, "retryable": boolean, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
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.
|
package/src/transfer/index.ts
CHANGED
|
@@ -8,4 +8,11 @@ export * from "./generated/fields.ts";
|
|
|
8
8
|
export * from "./validation.ts";
|
|
9
9
|
export * from "./client.ts";
|
|
10
10
|
export * from "./connection.ts";
|
|
11
|
-
export
|
|
11
|
+
export {
|
|
12
|
+
assertTransferPayload,
|
|
13
|
+
InvalidTransferPayloadError,
|
|
14
|
+
isTransferSessionId,
|
|
15
|
+
LONGHORN_TRANSFER_MIME_TYPE,
|
|
16
|
+
parseTransferPayload,
|
|
17
|
+
serializeTransferPayload,
|
|
18
|
+
} from "./payload.ts";
|
package/src/transfer/payload.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkWireFields, readWireRecord } from "../core/record.ts";
|
|
2
|
+
import { TRANSFER_FIELDS } from "./generated/fields.ts";
|
|
2
3
|
import { TRANSFER_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
3
4
|
import type { TransferPayload } from "./generated/protocol.ts";
|
|
4
5
|
|
|
@@ -32,22 +33,24 @@ export function parseTransferPayload(value: string): TransferPayload {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export function assertTransferPayload(value: unknown): asserts value is TransferPayload {
|
|
35
|
-
|
|
36
|
+
const record = readWireRecord(value, () => {
|
|
36
37
|
throw new InvalidTransferPayloadError("transfer payload must be an object");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const keys = Object.keys(record).sort();
|
|
40
|
-
if (keys.length !== 2 || keys[0] !== "protocol_version" || keys[1] !== "session_id") {
|
|
38
|
+
});
|
|
39
|
+
checkWireFields(record, TRANSFER_FIELDS.TransferPayload, () => {
|
|
41
40
|
throw new InvalidTransferPayloadError(
|
|
42
|
-
|
|
41
|
+
`transfer payload must contain only ${TRANSFER_FIELDS.TransferPayload.join(" and ")}`,
|
|
43
42
|
);
|
|
44
|
-
}
|
|
43
|
+
});
|
|
45
44
|
if (record.protocol_version !== TRANSFER_PROTOCOL_VERSION) {
|
|
46
45
|
throw new InvalidTransferPayloadError("transfer payload protocol version is unsupported");
|
|
47
46
|
}
|
|
48
|
-
if (
|
|
47
|
+
if (!isTransferSessionId(record.session_id)) {
|
|
49
48
|
throw new InvalidTransferPayloadError(
|
|
50
49
|
"transfer session id must be 32 lowercase hexadecimal characters",
|
|
51
50
|
);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
53
|
+
|
|
54
|
+
export function isTransferSessionId(value: unknown): boolean {
|
|
55
|
+
return typeof value === "string" && /^[0-9a-f]{32}$/.test(value);
|
|
56
|
+
}
|