@inflatable-cookie/longhorn 0.5.0 → 0.6.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/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- 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 +77 -105
- 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 +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
1
2
|
import {
|
|
2
3
|
SURFACE_VARIANT_FIELDS,
|
|
3
4
|
SURFACE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -7,12 +8,14 @@ import {
|
|
|
7
8
|
SURFACE_MUTATION_OUTCOME_KINDS,
|
|
8
9
|
SURFACE_MUTATION_REJECTION_CODES,
|
|
9
10
|
SURFACE_PROTOCOL_VERSION,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
} from "./generated/protocol.ts";
|
|
12
|
+
import type {
|
|
13
|
+
SurfaceChangedEvent,
|
|
14
|
+
SurfaceMutationCommand,
|
|
15
|
+
SurfaceMutationOutcome,
|
|
16
|
+
SurfaceMutationRejectionCode,
|
|
17
|
+
SurfaceMutationResponse,
|
|
18
|
+
SurfaceSnapshot,
|
|
16
19
|
} from "./generated/protocol.ts";
|
|
17
20
|
import { SURFACE_FIELDS } from "./generated/fields.ts";
|
|
18
21
|
|
|
@@ -42,23 +45,30 @@ export function assertSurfaceProtocolVersion(
|
|
|
42
45
|
version: unknown,
|
|
43
46
|
): asserts version is typeof SURFACE_PROTOCOL_VERSION {
|
|
44
47
|
if (version !== SURFACE_PROTOCOL_VERSION) {
|
|
45
|
-
throw new SurfaceProtocolValidationError(
|
|
46
|
-
"unsupported_protocol_version",
|
|
47
|
-
version,
|
|
48
|
-
);
|
|
48
|
+
throw new SurfaceProtocolValidationError("unsupported_protocol_version", version);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function assertValidSurfaceMutationCommand(
|
|
53
53
|
value: unknown,
|
|
54
54
|
): asserts value is SurfaceMutationCommand {
|
|
55
|
-
assertKnownKind(
|
|
55
|
+
assertKnownKind(
|
|
56
|
+
value,
|
|
57
|
+
SURFACE_MUTATION_COMMAND_KINDS,
|
|
58
|
+
"unknown_command",
|
|
59
|
+
"SurfaceMutationCommand",
|
|
60
|
+
);
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export function assertValidSurfaceMutationOutcome(
|
|
59
64
|
value: unknown,
|
|
60
65
|
): asserts value is SurfaceMutationOutcome {
|
|
61
|
-
assertKnownKind(
|
|
66
|
+
assertKnownKind(
|
|
67
|
+
value,
|
|
68
|
+
SURFACE_MUTATION_OUTCOME_KINDS,
|
|
69
|
+
"unknown_outcome",
|
|
70
|
+
"SurfaceMutationOutcome",
|
|
71
|
+
);
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
export function assertValidSurfaceMutationRejectionCode(
|
|
@@ -66,14 +76,9 @@ export function assertValidSurfaceMutationRejectionCode(
|
|
|
66
76
|
): asserts value is SurfaceMutationRejectionCode {
|
|
67
77
|
if (
|
|
68
78
|
typeof value !== "string" ||
|
|
69
|
-
!SURFACE_MUTATION_REJECTION_CODES.
|
|
70
|
-
value as (typeof SURFACE_MUTATION_REJECTION_CODES)[number],
|
|
71
|
-
)
|
|
79
|
+
!SURFACE_MUTATION_REJECTION_CODES.some((code) => code === value)
|
|
72
80
|
) {
|
|
73
|
-
throw new SurfaceProtocolValidationError(
|
|
74
|
-
"unknown_rejection_code",
|
|
75
|
-
value,
|
|
76
|
-
);
|
|
81
|
+
throw new SurfaceProtocolValidationError("unknown_rejection_code", value);
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
84
|
|
|
@@ -88,6 +93,7 @@ export function assertValidSurfaceMutationResponse(
|
|
|
88
93
|
case "committed": {
|
|
89
94
|
record(response, variantKeys("SurfaceMutationResponse", response));
|
|
90
95
|
const receipt = record(response.receipt, SURFACE_FIELDS.SurfaceMutationReceipt);
|
|
96
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
|
|
91
97
|
assertValidSurfaceMutationOutcome(record(receipt.outcome));
|
|
92
98
|
return;
|
|
93
99
|
}
|
|
@@ -98,40 +104,28 @@ export function assertValidSurfaceMutationResponse(
|
|
|
98
104
|
return;
|
|
99
105
|
}
|
|
100
106
|
default:
|
|
101
|
-
throw new SurfaceProtocolValidationError(
|
|
102
|
-
"unknown_response_status",
|
|
103
|
-
response.status,
|
|
104
|
-
);
|
|
107
|
+
throw new SurfaceProtocolValidationError("unknown_response_status", response.status);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
export function assertValidSurfaceSnapshot(
|
|
109
|
-
value
|
|
110
|
-
): asserts value is SurfaceSnapshot {
|
|
111
|
-
assertSurfaceProtocolVersion(
|
|
112
|
-
record(value, SURFACE_FIELDS.SurfaceSnapshot).protocol_version,
|
|
113
|
-
);
|
|
111
|
+
export function assertValidSurfaceSnapshot(value: unknown): asserts value is SurfaceSnapshot {
|
|
112
|
+
assertSurfaceProtocolVersion(record(value, SURFACE_FIELDS.SurfaceSnapshot).protocol_version);
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
export function assertValidSurfaceChangedEvent(
|
|
117
116
|
value: unknown,
|
|
118
117
|
): asserts value is SurfaceChangedEvent {
|
|
119
|
-
assertSurfaceProtocolVersion(
|
|
120
|
-
record(value, SURFACE_FIELDS.SurfaceChangedEvent).protocol_version,
|
|
121
|
-
);
|
|
118
|
+
assertSurfaceProtocolVersion(record(value, SURFACE_FIELDS.SurfaceChangedEvent).protocol_version);
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
function assertKnownKind(
|
|
125
122
|
value: unknown,
|
|
126
|
-
known:
|
|
123
|
+
known: ReadonlyArray<string>,
|
|
127
124
|
code: "unknown_command" | "unknown_outcome",
|
|
128
125
|
type: string,
|
|
129
126
|
): asserts value is Record<"kind", string> {
|
|
130
127
|
const candidate = record(value);
|
|
131
|
-
if (
|
|
132
|
-
typeof candidate.kind !== "string" ||
|
|
133
|
-
!known.includes(candidate.kind)
|
|
134
|
-
) {
|
|
128
|
+
if (typeof candidate.kind !== "string" || !known.includes(candidate.kind)) {
|
|
135
129
|
throw new SurfaceProtocolValidationError(code, value);
|
|
136
130
|
}
|
|
137
131
|
// The discriminant is checked above, so a missing map entry here means the
|
|
@@ -143,12 +137,10 @@ function assertKnownKind(
|
|
|
143
137
|
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
144
138
|
* discriminant's name read from the map too.
|
|
145
139
|
*/
|
|
146
|
-
function variantKeys(
|
|
147
|
-
type: string,
|
|
148
|
-
value: Record<string, unknown>,
|
|
149
|
-
): readonly string[] {
|
|
140
|
+
function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
|
|
150
141
|
const discriminant = value[SURFACE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
151
|
-
const keys =
|
|
142
|
+
const keys =
|
|
143
|
+
typeof discriminant === "string" ? SURFACE_VARIANT_FIELDS[type]?.[discriminant] : undefined;
|
|
152
144
|
if (keys === undefined) {
|
|
153
145
|
throw new SurfaceProtocolValidationError("unknown_outcome", { type, discriminant });
|
|
154
146
|
}
|
|
@@ -168,15 +160,14 @@ function variantKeys(
|
|
|
168
160
|
* incompatibility union had no code for it. It reported the wrong thing for
|
|
169
161
|
* every caller but one.
|
|
170
162
|
*/
|
|
171
|
-
function record(
|
|
172
|
-
value
|
|
173
|
-
allowed?: readonly string[],
|
|
174
|
-
): Record<string, unknown> {
|
|
175
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
163
|
+
function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
|
|
164
|
+
if (!isRecord(value)) {
|
|
176
165
|
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
177
166
|
}
|
|
178
|
-
const result = value
|
|
179
|
-
if (allowed === undefined)
|
|
167
|
+
const result = value;
|
|
168
|
+
if (allowed === undefined) {
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
180
171
|
|
|
181
172
|
const permitted = new Set(allowed);
|
|
182
173
|
for (const key of Object.keys(result)) {
|
package/src/transfer/client.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type ConnectionFailureReporter,
|
|
4
|
-
type InvokeTransport,
|
|
5
|
-
} from "@inflatable-cookie/longhorn/core";
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { ConnectionFailureReporter, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
6
3
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
import type {
|
|
5
|
+
PanelSessionStartRequest,
|
|
6
|
+
PanelTransferCommand,
|
|
7
|
+
PanelTransferResponse,
|
|
8
|
+
TransferCancelRequest,
|
|
9
|
+
TransferCancelResponse,
|
|
10
|
+
TransferClientSnapshot,
|
|
11
|
+
TransferLeaseRequest,
|
|
12
|
+
TransferLeaseResponse,
|
|
13
|
+
TransferSessionResponse,
|
|
17
14
|
} from "./generated/protocol.ts";
|
|
18
15
|
import {
|
|
19
16
|
assertValidPanelTransferResponse,
|
|
@@ -25,18 +22,13 @@ import {
|
|
|
25
22
|
assertValidTransferTargetBinding,
|
|
26
23
|
assertTransferProtocolVersion,
|
|
27
24
|
} from "./validation.ts";
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
type TransferClientSnapshotListener,
|
|
31
|
-
} from "./connection.ts";
|
|
25
|
+
import { TransferClientConnection } from "./connection.ts";
|
|
26
|
+
import type { TransferClientSnapshotListener } from "./connection.ts";
|
|
32
27
|
|
|
33
28
|
export const TRANSFER_SNAPSHOT_COMMAND = "longhorn_transfer_snapshot";
|
|
34
|
-
export const TRANSFER_START_PANEL_COMMAND =
|
|
35
|
-
|
|
36
|
-
export const
|
|
37
|
-
"longhorn_transfer_publish_lease";
|
|
38
|
-
export const TRANSFER_COMMIT_PANEL_COMMAND =
|
|
39
|
-
"longhorn_transfer_commit_panel";
|
|
29
|
+
export const TRANSFER_START_PANEL_COMMAND = "longhorn_transfer_start_panel";
|
|
30
|
+
export const TRANSFER_PUBLISH_LEASE_COMMAND = "longhorn_transfer_publish_lease";
|
|
31
|
+
export const TRANSFER_COMMIT_PANEL_COMMAND = "longhorn_transfer_commit_panel";
|
|
40
32
|
export const TRANSFER_CANCEL_COMMAND = "longhorn_transfer_cancel";
|
|
41
33
|
|
|
42
34
|
export class TransferClient {
|
|
@@ -57,9 +49,7 @@ export class TransferClient {
|
|
|
57
49
|
onFailure?: ConnectionFailureReporter,
|
|
58
50
|
): TransferClientConnection {
|
|
59
51
|
if (!isEventTransport(this.#transport)) {
|
|
60
|
-
throw new TypeError(
|
|
61
|
-
"transfer connection requires an event-capable transport",
|
|
62
|
-
);
|
|
52
|
+
throw new TypeError("transfer connection requires an event-capable transport");
|
|
63
53
|
}
|
|
64
54
|
return new TransferClientConnection(
|
|
65
55
|
this.#transport,
|
|
@@ -69,52 +59,28 @@ export class TransferClient {
|
|
|
69
59
|
);
|
|
70
60
|
}
|
|
71
61
|
|
|
72
|
-
async startPanel(
|
|
73
|
-
request: PanelSessionStartRequest,
|
|
74
|
-
): Promise<TransferSessionResponse> {
|
|
62
|
+
async startPanel(request: PanelSessionStartRequest): Promise<TransferSessionResponse> {
|
|
75
63
|
assertTransferProtocolVersion(request.protocol_version);
|
|
76
|
-
return this.#invoke(
|
|
77
|
-
TRANSFER_START_PANEL_COMMAND,
|
|
78
|
-
request,
|
|
79
|
-
assertValidTransferSessionResponse,
|
|
80
|
-
);
|
|
64
|
+
return this.#invoke(TRANSFER_START_PANEL_COMMAND, request, assertValidTransferSessionResponse);
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
async publishLease(
|
|
84
|
-
request: TransferLeaseRequest,
|
|
85
|
-
): Promise<TransferLeaseResponse> {
|
|
67
|
+
async publishLease(request: TransferLeaseRequest): Promise<TransferLeaseResponse> {
|
|
86
68
|
assertTransferProtocolVersion(request.protocol_version);
|
|
87
69
|
for (const zone of request.zones) {
|
|
88
70
|
assertValidTransferTargetBinding(zone.target);
|
|
89
71
|
}
|
|
90
|
-
return this.#invoke(
|
|
91
|
-
TRANSFER_PUBLISH_LEASE_COMMAND,
|
|
92
|
-
request,
|
|
93
|
-
assertValidTransferLeaseResponse,
|
|
94
|
-
);
|
|
72
|
+
return this.#invoke(TRANSFER_PUBLISH_LEASE_COMMAND, request, assertValidTransferLeaseResponse);
|
|
95
73
|
}
|
|
96
74
|
|
|
97
|
-
async commitPanel(
|
|
98
|
-
request: PanelTransferCommand,
|
|
99
|
-
): Promise<PanelTransferResponse> {
|
|
75
|
+
async commitPanel(request: PanelTransferCommand): Promise<PanelTransferResponse> {
|
|
100
76
|
assertTransferProtocolVersion(request.protocol_version);
|
|
101
77
|
assertValidTransferCommitSelector(request.selector);
|
|
102
|
-
return this.#invoke(
|
|
103
|
-
TRANSFER_COMMIT_PANEL_COMMAND,
|
|
104
|
-
request,
|
|
105
|
-
assertValidPanelTransferResponse,
|
|
106
|
-
);
|
|
78
|
+
return this.#invoke(TRANSFER_COMMIT_PANEL_COMMAND, request, assertValidPanelTransferResponse);
|
|
107
79
|
}
|
|
108
80
|
|
|
109
|
-
async cancel(
|
|
110
|
-
request: TransferCancelRequest,
|
|
111
|
-
): Promise<TransferCancelResponse> {
|
|
81
|
+
async cancel(request: TransferCancelRequest): Promise<TransferCancelResponse> {
|
|
112
82
|
assertTransferProtocolVersion(request.protocol_version);
|
|
113
|
-
return this.#invoke(
|
|
114
|
-
TRANSFER_CANCEL_COMMAND,
|
|
115
|
-
request,
|
|
116
|
-
assertValidTransferCancelResponse,
|
|
117
|
-
);
|
|
83
|
+
return this.#invoke(TRANSFER_CANCEL_COMMAND, request, assertValidTransferCancelResponse);
|
|
118
84
|
}
|
|
119
85
|
|
|
120
86
|
async #invoke<T>(
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CheckedSnapshotConnection } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type {
|
|
3
|
+
ConnectionFailure,
|
|
4
|
+
ConnectionFailureReporter,
|
|
5
|
+
EventTransport,
|
|
6
6
|
} from "@inflatable-cookie/longhorn/core";
|
|
7
7
|
|
|
8
8
|
import type { TransferClientSnapshot } from "./generated/protocol.ts";
|
|
9
9
|
import { assertValidTransferClientSnapshot } from "./validation.ts";
|
|
10
10
|
|
|
11
|
-
export const TRANSFER_CLIENT_CHANGED_EVENT =
|
|
12
|
-
"longhorn://transfer/client-changed";
|
|
11
|
+
export const TRANSFER_CLIENT_CHANGED_EVENT = "longhorn://transfer/client-changed";
|
|
13
12
|
|
|
14
|
-
export type TransferClientSnapshotListener = (
|
|
15
|
-
snapshot: TransferClientSnapshot,
|
|
16
|
-
) => void;
|
|
13
|
+
export type TransferClientSnapshotListener = (snapshot: TransferClientSnapshot) => void;
|
|
17
14
|
|
|
18
15
|
export class TransferClientConnection {
|
|
19
16
|
readonly ready: Promise<TransferClientSnapshot>;
|
|
@@ -27,16 +24,14 @@ export class TransferClientConnection {
|
|
|
27
24
|
onFailure?: ConnectionFailureReporter,
|
|
28
25
|
) {
|
|
29
26
|
this.#connection = new CheckedSnapshotConnection({
|
|
30
|
-
listen: (receive) =>
|
|
31
|
-
transport.listen(TRANSFER_CLIENT_CHANGED_EVENT, receive),
|
|
27
|
+
listen: (receive) => transport.listen(TRANSFER_CLIENT_CHANGED_EVENT, receive),
|
|
32
28
|
loadSnapshot,
|
|
33
29
|
validateSnapshot: parseTransferClientSnapshot,
|
|
34
30
|
handleEvent: (value) => ({ kind: "snapshot", value }),
|
|
35
31
|
isNewer: isCurrentTransferClientSnapshot,
|
|
36
32
|
onSnapshot: listener,
|
|
37
33
|
onFailure,
|
|
38
|
-
disposedBeforeReadyError: () =>
|
|
39
|
-
new TransferClientConnectionDisposedError(),
|
|
34
|
+
disposedBeforeReadyError: () => new TransferClientConnectionDisposedError(),
|
|
40
35
|
});
|
|
41
36
|
this.ready = this.#connection.ready.then((snapshot) => {
|
|
42
37
|
if (snapshot === undefined) {
|
|
@@ -50,7 +45,7 @@ export class TransferClientConnection {
|
|
|
50
45
|
return this.#connection.current();
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
failures():
|
|
48
|
+
failures(): ReadonlyArray<ConnectionFailure> {
|
|
54
49
|
return this.#connection.failures();
|
|
55
50
|
}
|
|
56
51
|
|
|
@@ -66,9 +61,7 @@ export class TransferClientConnectionDisposedError extends Error {
|
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
function parseTransferClientSnapshot(
|
|
70
|
-
value: unknown,
|
|
71
|
-
): TransferClientSnapshot {
|
|
64
|
+
function parseTransferClientSnapshot(value: unknown): TransferClientSnapshot {
|
|
72
65
|
assertValidTransferClientSnapshot(value);
|
|
73
66
|
return value;
|
|
74
67
|
}
|
|
@@ -81,7 +74,6 @@ function isCurrentTransferClientSnapshot(
|
|
|
81
74
|
return true;
|
|
82
75
|
}
|
|
83
76
|
return (
|
|
84
|
-
candidate.client_epoch === current.client_epoch &&
|
|
85
|
-
candidate.client_id === current.client_id
|
|
77
|
+
candidate.client_epoch === current.client_epoch && candidate.client_id === current.client_id
|
|
86
78
|
);
|
|
87
79
|
}
|
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
5
5
|
|
|
6
|
-
export const TRANSFER_FIELDS
|
|
6
|
+
export const TRANSFER_FIELDS = {
|
|
7
7
|
"ClientPoint": ["x", "y"],
|
|
8
8
|
"ClientSize": ["width", "height"],
|
|
9
9
|
"ClientRect": ["origin", "size"],
|
|
10
10
|
"TransferPayload": ["protocol_version", "session_id"],
|
|
11
11
|
"PanelSessionStartRequest": ["protocol_version", "request_id", "panel_instance_id"],
|
|
12
12
|
"TransferCancelRequest": ["protocol_version", "request_id", "session_id"],
|
|
13
|
-
"ClientDropZone": ["id", "bounds", "insertion_position", "
|
|
13
|
+
"ClientDropZone": ["id", "bounds", "insertion_position", "target"],
|
|
14
14
|
"TransferLeaseRequest": ["protocol_version", "request_id", "client_id", "client_epoch", "generation", "zones"],
|
|
15
15
|
"PanelTransferCommand": ["protocol_version", "request_id", "session_id", "selector"],
|
|
16
|
-
"TransferClientSnapshot": ["protocol_version", "client_id", "client_epoch"
|
|
16
|
+
"TransferClientSnapshot": ["protocol_version", "client_id", "client_epoch"],
|
|
17
17
|
"TransferSessionStarted": ["protocol_version", "request_id", "payload"],
|
|
18
18
|
"TransferLeaseReceipt": ["protocol_version", "request_id", "client_id", "client_epoch", "generation", "zone_count"],
|
|
19
19
|
"TransferCancelReceipt": ["protocol_version", "request_id", "session_id", "status"],
|
|
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
|
-
"TransferAbort": ["protocol_version", "request_id", "source", "message", "retryable", "session_consumed"],
|
|
23
|
-
};
|
|
22
|
+
"TransferAbort": ["protocol_version", "request_id", "source", "layout_code", "message", "retryable", "session_consumed"],
|
|
23
|
+
} as const;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @generated by `effigy generate:transfer`; 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;
|
|
@@ -98,7 +98,7 @@ export type PanelSessionStartRequest = { protocol_version: TransferProtocolVersi
|
|
|
98
98
|
|
|
99
99
|
export type TransferCancelRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, };
|
|
100
100
|
|
|
101
|
-
export type ClientDropZone = { id: DropZoneId, bounds: ClientRect, insertion_position: InsertionPosition | null,
|
|
101
|
+
export type ClientDropZone = { id: DropZoneId, bounds: ClientRect, insertion_position: InsertionPosition | null, target: TransferTargetBinding, };
|
|
102
102
|
|
|
103
103
|
export type TransferLeaseRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, client_id: TransferClientId, client_epoch: ClientEpoch, generation: LeaseGeneration, zones: Array<ClientDropZone>, };
|
|
104
104
|
|
|
@@ -114,7 +114,7 @@ point: { x: number; y: number }, };
|
|
|
114
114
|
|
|
115
115
|
export type PanelTransferCommand = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, selector: TransferCommitSelector, };
|
|
116
116
|
|
|
117
|
-
export type TransferClientSnapshot = { protocol_version: TransferProtocolVersion, client_id: TransferClientId, client_epoch: ClientEpoch,
|
|
117
|
+
export type TransferClientSnapshot = { protocol_version: TransferProtocolVersion, client_id: TransferClientId, client_epoch: ClientEpoch, };
|
|
118
118
|
|
|
119
119
|
export type TransferSessionStarted = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, payload: TransferPayload, };
|
|
120
120
|
|
|
@@ -128,7 +128,7 @@ export type PanelTransferCompletion = { protocol_version: TransferProtocolVersio
|
|
|
128
128
|
|
|
129
129
|
export type TransferAbortSource = { "domain": "transfer", "code": TransferErrorCode } | { "domain": "panel", "code": PanelTransferErrorCode };
|
|
130
130
|
|
|
131
|
-
export type TransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: TransferAbortSource, message: string, retryable: boolean, session_consumed: boolean, };
|
|
131
|
+
export type TransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: TransferAbortSource, layout_code: LayoutMutationRejectionCode | null, message: string, retryable: boolean, session_consumed: boolean, };
|
|
132
132
|
|
|
133
133
|
export type TransferSessionResponse = { "status": "started",
|
|
134
134
|
/**
|
package/src/transfer/payload.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./generated/protocol.ts";
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
2
|
+
import { TRANSFER_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
3
|
+
import type { TransferPayload } from "./generated/protocol.ts";
|
|
5
4
|
|
|
6
|
-
export const LONGHORN_TRANSFER_MIME_TYPE =
|
|
7
|
-
"application/vnd.longhorn.transfer+json";
|
|
5
|
+
export const LONGHORN_TRANSFER_MIME_TYPE = "application/vnd.longhorn.transfer+json";
|
|
8
6
|
|
|
9
7
|
export class InvalidTransferPayloadError extends TypeError {
|
|
10
8
|
constructor(message: string) {
|
|
@@ -13,7 +11,8 @@ export class InvalidTransferPayloadError extends TypeError {
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export function serializeTransferPayload(payload: TransferPayload)
|
|
14
|
+
export function serializeTransferPayload(payload: TransferPayload) {
|
|
15
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
|
|
17
16
|
assertTransferPayload(payload);
|
|
18
17
|
return JSON.stringify({
|
|
19
18
|
protocol_version: payload.protocol_version,
|
|
@@ -32,38 +31,21 @@ export function parseTransferPayload(value: string): TransferPayload {
|
|
|
32
31
|
return parsed;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export function assertTransferPayload(
|
|
36
|
-
value
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
typeof value !== "object" ||
|
|
40
|
-
value === null ||
|
|
41
|
-
Array.isArray(value)
|
|
42
|
-
) {
|
|
43
|
-
throw new InvalidTransferPayloadError(
|
|
44
|
-
"transfer payload must be an object",
|
|
45
|
-
);
|
|
34
|
+
export function assertTransferPayload(value: unknown): asserts value is TransferPayload {
|
|
35
|
+
if (!isRecord(value)) {
|
|
36
|
+
throw new InvalidTransferPayloadError("transfer payload must be an object");
|
|
46
37
|
}
|
|
47
|
-
const record = value
|
|
38
|
+
const record = value;
|
|
48
39
|
const keys = Object.keys(record).sort();
|
|
49
|
-
if (
|
|
50
|
-
keys.length !== 2 ||
|
|
51
|
-
keys[0] !== "protocol_version" ||
|
|
52
|
-
keys[1] !== "session_id"
|
|
53
|
-
) {
|
|
40
|
+
if (keys.length !== 2 || keys[0] !== "protocol_version" || keys[1] !== "session_id") {
|
|
54
41
|
throw new InvalidTransferPayloadError(
|
|
55
42
|
"transfer payload must contain only protocol_version and session_id",
|
|
56
43
|
);
|
|
57
44
|
}
|
|
58
45
|
if (record.protocol_version !== TRANSFER_PROTOCOL_VERSION) {
|
|
59
|
-
throw new InvalidTransferPayloadError(
|
|
60
|
-
"transfer payload protocol version is unsupported",
|
|
61
|
-
);
|
|
46
|
+
throw new InvalidTransferPayloadError("transfer payload protocol version is unsupported");
|
|
62
47
|
}
|
|
63
|
-
if (
|
|
64
|
-
typeof record.session_id !== "string" ||
|
|
65
|
-
!/^[0-9a-f]{32}$/.test(record.session_id)
|
|
66
|
-
) {
|
|
48
|
+
if (typeof record.session_id !== "string" || !/^[0-9a-f]{32}$/.test(record.session_id)) {
|
|
67
49
|
throw new InvalidTransferPayloadError(
|
|
68
50
|
"transfer session id must be 32 lowercase hexadecimal characters",
|
|
69
51
|
);
|