@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.
- 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/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +78 -109
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- 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/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- 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 +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- 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 +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- 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 +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- 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 +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- 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 +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- 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 +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import type { SurfaceId, SurfaceDocument, SurfaceRevision, PanelInstanceId, RegionId } from "@inflatable-cookie/longhorn/layout";
|
|
4
|
+
import type { LayoutMutationRejectionCode, SurfaceId, SurfaceDocument, SurfaceRevision, PanelInstanceId, RegionId } from "@inflatable-cookie/longhorn/layout";
|
|
5
5
|
|
|
6
6
|
export const TRANSFER_PROTOCOL_VERSION = 1 as const;
|
|
7
7
|
export const TRANSFER_TARGET_BINDING_KINDS = ["panel_region","surface_window"] as const;
|
|
@@ -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
|
|
|
@@ -98,7 +102,7 @@ export type PanelSessionStartRequest = { protocol_version: TransferProtocolVersi
|
|
|
98
102
|
|
|
99
103
|
export type TransferCancelRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, };
|
|
100
104
|
|
|
101
|
-
export type ClientDropZone = { id: DropZoneId, bounds: ClientRect, insertion_position: InsertionPosition | null,
|
|
105
|
+
export type ClientDropZone = { id: DropZoneId, bounds: ClientRect, insertion_position: InsertionPosition | null, target: TransferTargetBinding, };
|
|
102
106
|
|
|
103
107
|
export type TransferLeaseRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, client_id: TransferClientId, client_epoch: ClientEpoch, generation: LeaseGeneration, zones: Array<ClientDropZone>, };
|
|
104
108
|
|
|
@@ -114,7 +118,7 @@ point: { x: number; y: number }, };
|
|
|
114
118
|
|
|
115
119
|
export type PanelTransferCommand = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, selector: TransferCommitSelector, };
|
|
116
120
|
|
|
117
|
-
export type TransferClientSnapshot = { protocol_version: TransferProtocolVersion, client_id: TransferClientId, client_epoch: ClientEpoch,
|
|
121
|
+
export type TransferClientSnapshot = { protocol_version: TransferProtocolVersion, client_id: TransferClientId, client_epoch: ClientEpoch, };
|
|
118
122
|
|
|
119
123
|
export type TransferSessionStarted = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, payload: TransferPayload, };
|
|
120
124
|
|
|
@@ -128,7 +132,7 @@ export type PanelTransferCompletion = { protocol_version: TransferProtocolVersio
|
|
|
128
132
|
|
|
129
133
|
export type TransferAbortSource = { "domain": "transfer", "code": TransferErrorCode } | { "domain": "panel", "code": PanelTransferErrorCode };
|
|
130
134
|
|
|
131
|
-
export type TransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: TransferAbortSource, message: string, retryable: boolean, session_consumed: boolean, };
|
|
135
|
+
export type TransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: TransferAbortSource, layout_code: LayoutMutationRejectionCode | null, message: string, retryable: boolean, session_consumed: boolean, };
|
|
132
136
|
|
|
133
137
|
export type TransferSessionResponse = { "status": "started",
|
|
134
138
|
/**
|
|
@@ -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,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./generated/protocol.ts";
|
|
1
|
+
import { checkWireFields, readWireRecord } from "../core/record.ts";
|
|
2
|
+
import { TRANSFER_FIELDS } from "./generated/fields.ts";
|
|
3
|
+
import { TRANSFER_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
4
|
+
import type { TransferPayload } from "./generated/protocol.ts";
|
|
5
5
|
|
|
6
|
-
export const LONGHORN_TRANSFER_MIME_TYPE =
|
|
7
|
-
"application/vnd.longhorn.transfer+json";
|
|
6
|
+
export const LONGHORN_TRANSFER_MIME_TYPE = "application/vnd.longhorn.transfer+json";
|
|
8
7
|
|
|
9
8
|
export class InvalidTransferPayloadError extends TypeError {
|
|
10
9
|
constructor(message: string) {
|
|
@@ -13,7 +12,8 @@ export class InvalidTransferPayloadError extends TypeError {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export function serializeTransferPayload(payload: TransferPayload)
|
|
15
|
+
export function serializeTransferPayload(payload: TransferPayload) {
|
|
16
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
|
|
17
17
|
assertTransferPayload(payload);
|
|
18
18
|
return JSON.stringify({
|
|
19
19
|
protocol_version: payload.protocol_version,
|
|
@@ -32,40 +32,25 @@ export function parseTransferPayload(value: string): TransferPayload {
|
|
|
32
32
|
return parsed;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function assertTransferPayload(
|
|
36
|
-
value
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value === null ||
|
|
41
|
-
Array.isArray(value)
|
|
42
|
-
) {
|
|
43
|
-
throw new InvalidTransferPayloadError(
|
|
44
|
-
"transfer payload must be an object",
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
const record = value as Record<string, unknown>;
|
|
48
|
-
const keys = Object.keys(record).sort();
|
|
49
|
-
if (
|
|
50
|
-
keys.length !== 2 ||
|
|
51
|
-
keys[0] !== "protocol_version" ||
|
|
52
|
-
keys[1] !== "session_id"
|
|
53
|
-
) {
|
|
35
|
+
export function assertTransferPayload(value: unknown): asserts value is TransferPayload {
|
|
36
|
+
const record = readWireRecord(value, () => {
|
|
37
|
+
throw new InvalidTransferPayloadError("transfer payload must be an object");
|
|
38
|
+
});
|
|
39
|
+
checkWireFields(record, TRANSFER_FIELDS.TransferPayload, () => {
|
|
54
40
|
throw new InvalidTransferPayloadError(
|
|
55
|
-
|
|
41
|
+
`transfer payload must contain only ${TRANSFER_FIELDS.TransferPayload.join(" and ")}`,
|
|
56
42
|
);
|
|
57
|
-
}
|
|
43
|
+
});
|
|
58
44
|
if (record.protocol_version !== TRANSFER_PROTOCOL_VERSION) {
|
|
59
|
-
throw new InvalidTransferPayloadError(
|
|
60
|
-
"transfer payload protocol version is unsupported",
|
|
61
|
-
);
|
|
45
|
+
throw new InvalidTransferPayloadError("transfer payload protocol version is unsupported");
|
|
62
46
|
}
|
|
63
|
-
if (
|
|
64
|
-
typeof record.session_id !== "string" ||
|
|
65
|
-
!/^[0-9a-f]{32}$/.test(record.session_id)
|
|
66
|
-
) {
|
|
47
|
+
if (!isTransferSessionId(record.session_id)) {
|
|
67
48
|
throw new InvalidTransferPayloadError(
|
|
68
49
|
"transfer session id must be 32 lowercase hexadecimal characters",
|
|
69
50
|
);
|
|
70
51
|
}
|
|
71
52
|
}
|
|
53
|
+
|
|
54
|
+
export function isTransferSessionId(value: unknown): boolean {
|
|
55
|
+
return typeof value === "string" && /^[0-9a-f]{32}$/.test(value);
|
|
56
|
+
}
|
|
@@ -1,3 +1,13 @@
|
|
|
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";
|
|
1
11
|
import {
|
|
2
12
|
TRANSFER_VARIANT_FIELDS,
|
|
3
13
|
TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -10,19 +20,30 @@ import {
|
|
|
10
20
|
TRANSFER_COMMIT_SELECTOR_KINDS,
|
|
11
21
|
TRANSFER_ERROR_CODES,
|
|
12
22
|
TRANSFER_LEASE_RESPONSE_STATUSES,
|
|
23
|
+
TRANSFER_PANEL_HOST_BINDING_KINDS,
|
|
13
24
|
TRANSFER_PROTOCOL_VERSION,
|
|
25
|
+
TRANSFER_SCREEN_POINT_FIELDS,
|
|
26
|
+
TRANSFER_SESSION_CANCELLATION_STATUSES,
|
|
14
27
|
TRANSFER_SESSION_RESPONSE_STATUSES,
|
|
15
28
|
TRANSFER_TARGET_BINDING_KINDS,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
TRANSFER_TARGET_RESOLUTION_PATHS,
|
|
30
|
+
} from "./generated/protocol.ts";
|
|
31
|
+
import type {
|
|
32
|
+
PanelTransferResponse,
|
|
33
|
+
TransferAbort,
|
|
34
|
+
TransferCancelResponse,
|
|
35
|
+
TransferClientSnapshot,
|
|
36
|
+
TransferCommitSelector,
|
|
37
|
+
TransferCommittedTarget,
|
|
38
|
+
TransferLeaseResponse,
|
|
39
|
+
TransferSessionResponse,
|
|
40
|
+
TransferSessionStarted,
|
|
41
|
+
TransferTargetBinding,
|
|
24
42
|
} from "./generated/protocol.ts";
|
|
43
|
+
import { isTransferSessionId } from "./payload.ts";
|
|
25
44
|
import { TRANSFER_FIELDS } from "./generated/fields.ts";
|
|
45
|
+
import { assertValidLayoutMutationRejectionCode } from "@inflatable-cookie/longhorn/layout";
|
|
46
|
+
import { assertValidSurfaceDocument } from "@inflatable-cookie/longhorn/surfaces";
|
|
26
47
|
|
|
27
48
|
export type TransferProtocolValidationCode =
|
|
28
49
|
| "unsupported_protocol_version"
|
|
@@ -53,10 +74,7 @@ export function assertTransferProtocolVersion(
|
|
|
53
74
|
version: unknown,
|
|
54
75
|
): asserts version is typeof TRANSFER_PROTOCOL_VERSION {
|
|
55
76
|
if (version !== TRANSFER_PROTOCOL_VERSION) {
|
|
56
|
-
throw new TransferProtocolValidationError(
|
|
57
|
-
"unsupported_protocol_version",
|
|
58
|
-
version,
|
|
59
|
-
);
|
|
77
|
+
throw new TransferProtocolValidationError("unsupported_protocol_version", version);
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
|
|
@@ -64,12 +82,16 @@ export function assertValidTransferTargetBinding(
|
|
|
64
82
|
value: unknown,
|
|
65
83
|
): asserts value is TransferTargetBinding {
|
|
66
84
|
const candidate = record(value);
|
|
67
|
-
assertKnown(
|
|
68
|
-
candidate.kind,
|
|
69
|
-
TRANSFER_TARGET_BINDING_KINDS,
|
|
70
|
-
"unknown_target_binding",
|
|
71
|
-
);
|
|
85
|
+
assertKnown(candidate.kind, TRANSFER_TARGET_BINDING_KINDS, "unknown_target_binding");
|
|
72
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
|
+
}
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
export function assertValidTransferClientSnapshot(
|
|
@@ -77,56 +99,77 @@ export function assertValidTransferClientSnapshot(
|
|
|
77
99
|
): asserts value is TransferClientSnapshot {
|
|
78
100
|
const snapshot = record(value, TRANSFER_FIELDS.TransferClientSnapshot);
|
|
79
101
|
assertTransferProtocolVersion(snapshot.protocol_version);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
) {
|
|
86
|
-
throw new TransferProtocolValidationError(
|
|
87
|
-
"invalid_client_snapshot",
|
|
88
|
-
value,
|
|
89
|
-
);
|
|
90
|
-
}
|
|
102
|
+
assertFields(
|
|
103
|
+
snapshot,
|
|
104
|
+
{ client_id: isOpaqueId, client_epoch: unsignedInteger },
|
|
105
|
+
"invalid_client_snapshot",
|
|
106
|
+
);
|
|
91
107
|
}
|
|
92
108
|
|
|
93
109
|
export function assertValidTransferCommitSelector(
|
|
94
110
|
value: unknown,
|
|
95
111
|
): asserts value is TransferCommitSelector {
|
|
96
112
|
const candidate = record(value);
|
|
97
|
-
assertKnown(
|
|
98
|
-
candidate.kind,
|
|
99
|
-
TRANSFER_COMMIT_SELECTOR_KINDS,
|
|
100
|
-
"unknown_commit_selector",
|
|
101
|
-
);
|
|
113
|
+
assertKnown(candidate.kind, TRANSFER_COMMIT_SELECTOR_KINDS, "unknown_commit_selector");
|
|
102
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
|
+
}
|
|
103
120
|
}
|
|
104
121
|
|
|
105
|
-
|
|
122
|
+
/** A Rust `ScreenPoint`: integral screen-DIP coordinates. */
|
|
123
|
+
export function assertValidTransferScreenPoint(
|
|
106
124
|
value: unknown,
|
|
107
|
-
): asserts value is
|
|
125
|
+
): asserts value is { x: number; y: number } {
|
|
126
|
+
assertFields(record(value, TRANSFER_SCREEN_POINT_FIELDS), { x: signed32, y: signed32 });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function assertValidTransferAbort(value: unknown): asserts value is TransferAbort {
|
|
108
130
|
const abort = record(value, TRANSFER_FIELDS.TransferAbort);
|
|
109
131
|
assertTransferProtocolVersion(abort.protocol_version);
|
|
132
|
+
assertFields(abort, {
|
|
133
|
+
request_id: isOpaqueId,
|
|
134
|
+
message: isString,
|
|
135
|
+
retryable: isBoolean,
|
|
136
|
+
session_consumed: isBoolean,
|
|
137
|
+
});
|
|
110
138
|
const source = record(abort.source);
|
|
111
|
-
assertKnown(
|
|
112
|
-
source.domain,
|
|
113
|
-
TRANSFER_ABORT_DOMAINS,
|
|
114
|
-
"unknown_abort_domain",
|
|
115
|
-
);
|
|
139
|
+
assertKnown(source.domain, TRANSFER_ABORT_DOMAINS, "unknown_abort_domain");
|
|
116
140
|
record(source, variantKeys("TransferAbortSource", source));
|
|
117
141
|
if (source.domain === "transfer") {
|
|
118
|
-
assertKnown(
|
|
119
|
-
source.code,
|
|
120
|
-
TRANSFER_ERROR_CODES,
|
|
121
|
-
"unknown_transfer_error_code",
|
|
122
|
-
);
|
|
142
|
+
assertKnown(source.code, TRANSFER_ERROR_CODES, "unknown_transfer_error_code");
|
|
123
143
|
} else {
|
|
124
|
-
assertKnown(
|
|
125
|
-
source.code,
|
|
126
|
-
PANEL_TRANSFER_ERROR_CODES,
|
|
127
|
-
"unknown_panel_error_code",
|
|
128
|
-
);
|
|
144
|
+
assertKnown(source.code, PANEL_TRANSFER_ERROR_CODES, "unknown_panel_error_code");
|
|
129
145
|
}
|
|
146
|
+
if (abort.layout_code !== null) {
|
|
147
|
+
assertValidLayoutMutationRejectionCode(abort.layout_code);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
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);
|
|
130
173
|
}
|
|
131
174
|
|
|
132
175
|
export function assertValidTransferSessionResponse(
|
|
@@ -138,9 +181,7 @@ export function assertValidTransferSessionResponse(
|
|
|
138
181
|
"TransferSessionResponse",
|
|
139
182
|
);
|
|
140
183
|
if (response.status === "started") {
|
|
141
|
-
|
|
142
|
-
assertTransferProtocolVersion(session.protocol_version);
|
|
143
|
-
assertTransferProtocolVersion(record(session.payload).protocol_version);
|
|
184
|
+
assertValidTransferSessionStarted(response.session);
|
|
144
185
|
} else {
|
|
145
186
|
assertValidTransferAbort(response.abort);
|
|
146
187
|
}
|
|
@@ -155,7 +196,15 @@ export function assertValidTransferLeaseResponse(
|
|
|
155
196
|
"TransferLeaseResponse",
|
|
156
197
|
);
|
|
157
198
|
if (response.status === "published") {
|
|
158
|
-
|
|
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
|
+
});
|
|
159
208
|
} else {
|
|
160
209
|
assertValidTransferAbort(response.abort);
|
|
161
210
|
}
|
|
@@ -170,9 +219,10 @@ export function assertValidTransferCancelResponse(
|
|
|
170
219
|
"TransferCancelResponse",
|
|
171
220
|
);
|
|
172
221
|
if (response.status === "cancelled") {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
);
|
|
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");
|
|
176
226
|
} else {
|
|
177
227
|
assertValidTransferAbort(response.abort);
|
|
178
228
|
}
|
|
@@ -187,19 +237,32 @@ export function assertValidPanelTransferResponse(
|
|
|
187
237
|
"PanelTransferResponse",
|
|
188
238
|
);
|
|
189
239
|
if (response.status === "committed") {
|
|
190
|
-
|
|
191
|
-
assertTransferProtocolVersion(completion.protocol_version);
|
|
192
|
-
assertValidTransferTargetBinding(
|
|
193
|
-
record(record(completion.target).binding),
|
|
194
|
-
);
|
|
240
|
+
assertPanelTransferCompletion(response.completion);
|
|
195
241
|
} else {
|
|
196
242
|
assertValidTransferAbort(response.abort);
|
|
197
243
|
}
|
|
198
244
|
}
|
|
199
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
|
+
|
|
200
263
|
function responseWithStatus(
|
|
201
264
|
value: unknown,
|
|
202
|
-
statuses:
|
|
265
|
+
statuses: ReadonlyArray<string>,
|
|
203
266
|
type: string,
|
|
204
267
|
): Record<string, unknown> {
|
|
205
268
|
const response = record(value);
|
|
@@ -208,32 +271,21 @@ function responseWithStatus(
|
|
|
208
271
|
return response;
|
|
209
272
|
}
|
|
210
273
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
value: Record<string, unknown>,
|
|
222
|
-
): readonly string[] {
|
|
223
|
-
const discriminant = value[TRANSFER_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
224
|
-
const keys = TRANSFER_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
225
|
-
if (keys === undefined) {
|
|
226
|
-
throw new TransferProtocolValidationError("unknown_response_status", {
|
|
227
|
-
type,
|
|
228
|
-
discriminant,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return keys;
|
|
274
|
+
function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
|
|
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
|
+
);
|
|
232
284
|
}
|
|
233
285
|
|
|
234
286
|
function assertKnown(
|
|
235
287
|
value: unknown,
|
|
236
|
-
known:
|
|
288
|
+
known: ReadonlyArray<string>,
|
|
237
289
|
code: TransferProtocolValidationCode,
|
|
238
290
|
): asserts value is string {
|
|
239
291
|
if (typeof value !== "string" || !known.includes(value)) {
|
|
@@ -241,42 +293,40 @@ function assertKnown(
|
|
|
241
293
|
}
|
|
242
294
|
}
|
|
243
295
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
function record(
|
|
253
|
-
value: unknown,
|
|
254
|
-
allowed?: readonly string[],
|
|
255
|
-
): Record<string, unknown> {
|
|
256
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
257
|
-
throw new TransferProtocolValidationError("invalid_object", value);
|
|
258
|
-
}
|
|
259
|
-
const result = value as Record<string, unknown>;
|
|
260
|
-
if (allowed === undefined) return result;
|
|
261
|
-
|
|
262
|
-
const permitted = new Set(allowed);
|
|
263
|
-
for (const key of Object.keys(result)) {
|
|
264
|
-
if (!permitted.has(key)) {
|
|
265
|
-
throw new TransferProtocolValidationError("unknown_field", { key, value });
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
for (const key of allowed) {
|
|
269
|
-
if (!(key in result)) {
|
|
270
|
-
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 });
|
|
271
304
|
}
|
|
272
305
|
}
|
|
273
|
-
return result;
|
|
274
306
|
}
|
|
275
307
|
|
|
276
|
-
function
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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;
|
|
282
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,
|
|
@@ -26,13 +28,88 @@ import {
|
|
|
26
28
|
|
|
27
29
|
export class UpdateClient implements CheckedUpdatePort {
|
|
28
30
|
constructor(readonly port: UpdatePort) {}
|
|
29
|
-
async snapshot(): Promise<UpdateSnapshot> {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
async
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
async snapshot(): Promise<UpdateSnapshot> {
|
|
32
|
+
const value = await this.port.snapshot();
|
|
33
|
+
assertUpdateSnapshot(value);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
async check(command: UpdateCheckCommand): Promise<UpdateOutcomeProjection> {
|
|
37
|
+
assertUpdateCheckCommand(command);
|
|
38
|
+
const value = await this.port.check(command);
|
|
39
|
+
assertUpdateOutcome(value);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
async selectChannel(command: UpdateSelectChannelCommand): Promise<UpdateOutcomeProjection> {
|
|
43
|
+
assertUpdateSelectChannelCommand(command);
|
|
44
|
+
const value = await this.port.selectChannel(command);
|
|
45
|
+
assertUpdateOutcome(value);
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
async defer(command: UpdateDeferCommand): Promise<UpdateOutcomeProjection> {
|
|
49
|
+
assertUpdateDeferCommand(command);
|
|
50
|
+
const value = await this.port.defer(command);
|
|
51
|
+
assertUpdateOutcome(value);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
async prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection> {
|
|
55
|
+
assertUpdatePrepareCommand(command);
|
|
56
|
+
const value = await this.port.prepare(command);
|
|
57
|
+
assertUpdateOutcome(value);
|
|
58
|
+
return value;
|
|
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
|
+
}
|
|
92
|
+
async apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection> {
|
|
93
|
+
assertUpdateApplyCommand(command);
|
|
94
|
+
const value = await this.port.apply(command);
|
|
95
|
+
assertUpdateOutcome(value);
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
async cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection> {
|
|
99
|
+
assertUpdateCancelCommand(command);
|
|
100
|
+
const value = await this.port.cancel(command);
|
|
101
|
+
assertUpdateOutcome(value);
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
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,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
38
115
|
}
|