@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,3 +1,10 @@
|
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import {
|
|
3
|
+
checkWireFields,
|
|
4
|
+
readWireRecord,
|
|
5
|
+
unsignedInteger,
|
|
6
|
+
wireVariantFields,
|
|
7
|
+
} from "../core/record.ts";
|
|
1
8
|
import {
|
|
2
9
|
SURFACE_TRANSFER_VARIANT_FIELDS,
|
|
3
10
|
SURFACE_TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -8,18 +15,24 @@ import {
|
|
|
8
15
|
SURFACE_TRANSFER_ERROR_CODES,
|
|
9
16
|
SURFACE_TRANSFER_RESPONSE_STATUSES,
|
|
10
17
|
SURFACE_TRANSFER_TARGET_KINDS,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
} from "./generated/protocol.ts";
|
|
19
|
+
import type {
|
|
20
|
+
SurfaceSessionResponse,
|
|
21
|
+
SurfaceTransferAbort,
|
|
22
|
+
SurfaceTransferResponse,
|
|
23
|
+
SurfaceTransferTarget,
|
|
15
24
|
} from "./generated/protocol.ts";
|
|
16
25
|
import { SURFACE_TRANSFER_FIELDS } from "./generated/fields.ts";
|
|
17
26
|
import {
|
|
18
27
|
TRANSFER_ERROR_CODES,
|
|
19
|
-
assertValidTransferTargetBinding,
|
|
20
28
|
assertTransferProtocolVersion,
|
|
29
|
+
assertValidTransferCommittedTarget,
|
|
30
|
+
assertValidTransferScreenPoint,
|
|
31
|
+
assertValidTransferSessionStarted,
|
|
32
|
+
isTransferSessionId,
|
|
21
33
|
} from "@inflatable-cookie/longhorn/transfer";
|
|
22
34
|
import {
|
|
35
|
+
assertValidSurfaceDocument,
|
|
23
36
|
assertValidSurfaceMutationRejectionCode,
|
|
24
37
|
} from "@inflatable-cookie/longhorn/surfaces";
|
|
25
38
|
|
|
@@ -37,10 +50,7 @@ export class SurfaceTransferProtocolValidationError extends Error {
|
|
|
37
50
|
readonly code: SurfaceTransferProtocolValidationCode;
|
|
38
51
|
readonly received: unknown;
|
|
39
52
|
|
|
40
|
-
constructor(
|
|
41
|
-
code: SurfaceTransferProtocolValidationCode,
|
|
42
|
-
received: unknown,
|
|
43
|
-
) {
|
|
53
|
+
constructor(code: SurfaceTransferProtocolValidationCode, received: unknown) {
|
|
44
54
|
super(`incompatible Surface transfer protocol: ${code}`);
|
|
45
55
|
this.name = "SurfaceTransferProtocolValidationError";
|
|
46
56
|
this.code = code;
|
|
@@ -55,17 +65,18 @@ export function assertValidSurfaceTransferTarget(
|
|
|
55
65
|
// its discriminant and one list is wrong for every variant. That used to
|
|
56
66
|
// mean no key check at all here; the generated per-variant map supplies one.
|
|
57
67
|
const target = record(value);
|
|
58
|
-
assertKnown(
|
|
59
|
-
target.kind,
|
|
60
|
-
SURFACE_TRANSFER_TARGET_KINDS,
|
|
61
|
-
"unknown_target",
|
|
62
|
-
);
|
|
68
|
+
assertKnown(target.kind, SURFACE_TRANSFER_TARGET_KINDS, "unknown_target");
|
|
63
69
|
record(target, variantKeys("SurfaceTransferTarget", target));
|
|
64
70
|
if (target.kind === "existing") {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
71
|
+
assertValidTransferCommittedTarget(target.target);
|
|
72
|
+
return;
|
|
68
73
|
}
|
|
74
|
+
assertValidTransferScreenPoint(target.drop_point);
|
|
75
|
+
assertFields(record(target.provisioning, SURFACE_TRANSFER_FIELDS.SurfaceProvisioningCompletion), {
|
|
76
|
+
window_id: isOpaqueId,
|
|
77
|
+
host_binding_id: isOpaqueId,
|
|
78
|
+
display_id: isOpaqueId,
|
|
79
|
+
});
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
export function assertValidSurfaceTransferAbort(
|
|
@@ -73,25 +84,20 @@ export function assertValidSurfaceTransferAbort(
|
|
|
73
84
|
): asserts value is SurfaceTransferAbort {
|
|
74
85
|
const abort = record(value, SURFACE_TRANSFER_FIELDS.SurfaceTransferAbort);
|
|
75
86
|
assertTransferProtocolVersion(abort.protocol_version);
|
|
87
|
+
assertFields(abort, {
|
|
88
|
+
request_id: isOpaqueId,
|
|
89
|
+
message: isString,
|
|
90
|
+
retryable: isBoolean,
|
|
91
|
+
session_consumed: isBoolean,
|
|
92
|
+
reconciliation_required: isBoolean,
|
|
93
|
+
});
|
|
76
94
|
const source = record(abort.source);
|
|
77
|
-
assertKnown(
|
|
78
|
-
source.domain,
|
|
79
|
-
SURFACE_TRANSFER_ABORT_DOMAINS,
|
|
80
|
-
"unknown_abort_domain",
|
|
81
|
-
);
|
|
95
|
+
assertKnown(source.domain, SURFACE_TRANSFER_ABORT_DOMAINS, "unknown_abort_domain");
|
|
82
96
|
record(source, variantKeys("SurfaceTransferAbortSource", source));
|
|
83
97
|
if (source.domain === "transfer") {
|
|
84
|
-
assertKnown(
|
|
85
|
-
source.code,
|
|
86
|
-
TRANSFER_ERROR_CODES,
|
|
87
|
-
"unknown_transfer_error_code",
|
|
88
|
-
);
|
|
98
|
+
assertKnown(source.code, TRANSFER_ERROR_CODES, "unknown_transfer_error_code");
|
|
89
99
|
} else {
|
|
90
|
-
assertKnown(
|
|
91
|
-
source.code,
|
|
92
|
-
SURFACE_TRANSFER_ERROR_CODES,
|
|
93
|
-
"unknown_surface_transfer_error_code",
|
|
94
|
-
);
|
|
100
|
+
assertKnown(source.code, SURFACE_TRANSFER_ERROR_CODES, "unknown_surface_transfer_error_code");
|
|
95
101
|
}
|
|
96
102
|
if (abort.surface_code !== null) {
|
|
97
103
|
assertValidSurfaceMutationRejectionCode(abort.surface_code);
|
|
@@ -107,9 +113,7 @@ export function assertValidSurfaceSessionResponse(
|
|
|
107
113
|
"SurfaceSessionResponse",
|
|
108
114
|
);
|
|
109
115
|
if (response.status === "started") {
|
|
110
|
-
|
|
111
|
-
assertTransferProtocolVersion(session.protocol_version);
|
|
112
|
-
assertTransferProtocolVersion(record(session.payload).protocol_version);
|
|
116
|
+
assertValidTransferSessionStarted(response.session);
|
|
113
117
|
} else {
|
|
114
118
|
assertValidSurfaceTransferAbort(response.abort);
|
|
115
119
|
}
|
|
@@ -124,8 +128,20 @@ export function assertValidSurfaceTransferResponse(
|
|
|
124
128
|
"SurfaceTransferResponse",
|
|
125
129
|
);
|
|
126
130
|
if (response.status === "committed") {
|
|
127
|
-
const completion = record(
|
|
131
|
+
const completion = record(
|
|
132
|
+
response.completion,
|
|
133
|
+
SURFACE_TRANSFER_FIELDS.SurfaceTransferCompletion,
|
|
134
|
+
);
|
|
128
135
|
assertTransferProtocolVersion(completion.protocol_version);
|
|
136
|
+
assertFields(completion, {
|
|
137
|
+
request_id: isOpaqueId,
|
|
138
|
+
session_id: isTransferSessionId,
|
|
139
|
+
source_host_binding_id: isOpaqueId,
|
|
140
|
+
target_host_binding_id: isOpaqueId,
|
|
141
|
+
previous_revision: unsignedInteger,
|
|
142
|
+
committed_revision: unsignedInteger,
|
|
143
|
+
});
|
|
144
|
+
assertValidSurfaceDocument(completion.authoritative_document);
|
|
129
145
|
assertValidSurfaceTransferTarget(completion.target);
|
|
130
146
|
} else {
|
|
131
147
|
assertValidSurfaceTransferAbort(response.abort);
|
|
@@ -134,7 +150,7 @@ export function assertValidSurfaceTransferResponse(
|
|
|
134
150
|
|
|
135
151
|
function responseWithStatus(
|
|
136
152
|
value: unknown,
|
|
137
|
-
statuses:
|
|
153
|
+
statuses: ReadonlyArray<string>,
|
|
138
154
|
type: string,
|
|
139
155
|
): Record<string, unknown> {
|
|
140
156
|
const response = record(value);
|
|
@@ -143,32 +159,24 @@ function responseWithStatus(
|
|
|
143
159
|
return response;
|
|
144
160
|
}
|
|
145
161
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const keys = SURFACE_TRANSFER_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
160
|
-
if (keys === undefined) {
|
|
161
|
-
throw new SurfaceTransferProtocolValidationError("unknown_response_status", {
|
|
162
|
-
type,
|
|
163
|
-
discriminant,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return keys;
|
|
162
|
+
function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
|
|
163
|
+
return wireVariantFields(
|
|
164
|
+
SURFACE_TRANSFER_VARIANT_FIELDS,
|
|
165
|
+
SURFACE_TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
|
|
166
|
+
type,
|
|
167
|
+
value,
|
|
168
|
+
(discriminant) => {
|
|
169
|
+
throw new SurfaceTransferProtocolValidationError("unknown_response_status", {
|
|
170
|
+
type,
|
|
171
|
+
discriminant,
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
);
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
function assertKnown(
|
|
170
178
|
value: unknown,
|
|
171
|
-
known:
|
|
179
|
+
known: ReadonlyArray<string>,
|
|
172
180
|
code: SurfaceTransferProtocolValidationCode,
|
|
173
181
|
): asserts value is string {
|
|
174
182
|
if (typeof value !== "string" || !known.includes(value)) {
|
|
@@ -176,34 +184,31 @@ function assertKnown(
|
|
|
176
184
|
}
|
|
177
185
|
}
|
|
178
186
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*/
|
|
187
|
-
function record(
|
|
188
|
-
value: unknown,
|
|
189
|
-
allowed?: readonly string[],
|
|
190
|
-
): Record<string, unknown> {
|
|
191
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
192
|
-
throw new SurfaceTransferProtocolValidationError("invalid_object", value);
|
|
193
|
-
}
|
|
194
|
-
const result = value as Record<string, unknown>;
|
|
195
|
-
if (allowed === undefined) return result;
|
|
196
|
-
|
|
197
|
-
const permitted = new Set(allowed);
|
|
198
|
-
for (const key of Object.keys(result)) {
|
|
199
|
-
if (!permitted.has(key)) {
|
|
200
|
-
throw new SurfaceTransferProtocolValidationError("unknown_field", { key, value });
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
for (const key of allowed) {
|
|
204
|
-
if (!(key in result)) {
|
|
205
|
-
throw new SurfaceTransferProtocolValidationError("missing_field", { key, value });
|
|
187
|
+
function assertFields(
|
|
188
|
+
value: Record<string, unknown>,
|
|
189
|
+
checks: Readonly<Record<string, (member: unknown) => boolean>>,
|
|
190
|
+
): void {
|
|
191
|
+
for (const [key, admits] of Object.entries(checks)) {
|
|
192
|
+
if (!admits(value[key])) {
|
|
193
|
+
throw new SurfaceTransferProtocolValidationError("invalid_object", { key, value });
|
|
206
194
|
}
|
|
207
195
|
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isString(value: unknown): boolean {
|
|
199
|
+
return typeof value === "string";
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function isBoolean(value: unknown): boolean {
|
|
203
|
+
return typeof value === "boolean";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
|
|
207
|
+
const result = readWireRecord(value, () => {
|
|
208
|
+
throw new SurfaceTransferProtocolValidationError("invalid_object", value);
|
|
209
|
+
});
|
|
210
|
+
checkWireFields(result, allowed, (code, key) => {
|
|
211
|
+
throw new SurfaceTransferProtocolValidationError(code, { key, value });
|
|
212
|
+
});
|
|
208
213
|
return result;
|
|
209
214
|
}
|
package/src/surfaces/client.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CheckedSnapshotConnection, CheckedSubscription } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type {
|
|
3
|
+
ConnectionFailure,
|
|
4
|
+
ConnectionFailureReporter,
|
|
5
|
+
EventTransport,
|
|
6
6
|
} from "@inflatable-cookie/longhorn/core";
|
|
7
7
|
|
|
8
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
8
9
|
import type {
|
|
9
|
-
SurfaceChangedEvent,
|
|
10
10
|
SurfaceMutationRequest,
|
|
11
11
|
SurfaceMutationResponse,
|
|
12
12
|
SurfaceSnapshot,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
assertValidSurfaceMutationCommand,
|
|
17
17
|
assertValidSurfaceMutationResponse,
|
|
18
18
|
assertValidSurfaceSnapshot,
|
|
19
|
+
SurfaceProtocolValidationError,
|
|
19
20
|
} from "./validation.ts";
|
|
20
21
|
|
|
21
22
|
export const SURFACE_SNAPSHOT_COMMAND = "longhorn_surfaces_snapshot";
|
|
@@ -25,7 +26,7 @@ export const SURFACE_CHANGED_EVENT = "longhorn://surfaces/changed";
|
|
|
25
26
|
export interface SurfaceSubscription {
|
|
26
27
|
readonly ready: Promise<void>;
|
|
27
28
|
current(): SurfaceSnapshot | undefined;
|
|
28
|
-
failures():
|
|
29
|
+
failures(): ReadonlyArray<ConnectionFailure>;
|
|
29
30
|
dispose(): Promise<void>;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -41,14 +42,21 @@ export class SurfaceClient {
|
|
|
41
42
|
return parseSurfaceSnapshot(value);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
async mutate(
|
|
45
|
-
request: SurfaceMutationRequest,
|
|
46
|
-
): Promise<SurfaceMutationResponse> {
|
|
45
|
+
async mutate(request: SurfaceMutationRequest): Promise<SurfaceMutationResponse> {
|
|
47
46
|
assertValidSurfaceMutationCommand(request.command);
|
|
47
|
+
// The caller keeps its object and a transport may serialize later, so send
|
|
48
|
+
// a copy taken now and correlate against the id it was sent with.
|
|
49
|
+
const dispatched = wireCopy(request);
|
|
50
|
+
const requestId = dispatched.request_id;
|
|
48
51
|
const value = await this.#transport.invoke(SURFACE_MUTATE_COMMAND, {
|
|
49
|
-
request,
|
|
52
|
+
request: dispatched,
|
|
50
53
|
});
|
|
51
54
|
assertValidSurfaceMutationResponse(value);
|
|
55
|
+
const echoed =
|
|
56
|
+
value.status === "committed" ? value.receipt.request_id : value.rejection.request_id;
|
|
57
|
+
if (echoed !== requestId) {
|
|
58
|
+
throw new SurfaceProtocolValidationError("uncorrelated_response", value);
|
|
59
|
+
}
|
|
52
60
|
return value;
|
|
53
61
|
}
|
|
54
62
|
|
|
@@ -56,51 +64,22 @@ export class SurfaceClient {
|
|
|
56
64
|
listener: (snapshot: SurfaceSnapshot) => void,
|
|
57
65
|
onFailure?: ConnectionFailureReporter,
|
|
58
66
|
): SurfaceSubscription {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const transport = this.#transport;
|
|
68
|
+
return new CheckedSubscription(
|
|
69
|
+
new CheckedSnapshotConnection({
|
|
70
|
+
listen: (receive) => transport.listen(SURFACE_CHANGED_EVENT, receive),
|
|
71
|
+
loadSnapshot: () => this.snapshot(),
|
|
72
|
+
validateSnapshot: parseSurfaceSnapshot,
|
|
73
|
+
handleEvent: surfaceEventAction,
|
|
74
|
+
isNewer: isNewerSurfaceSnapshot,
|
|
75
|
+
onSnapshot: listener,
|
|
76
|
+
onFailure,
|
|
77
|
+
}),
|
|
78
|
+
() => {},
|
|
64
79
|
);
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
82
|
|
|
68
|
-
class SurfaceSnapshotSubscription implements SurfaceSubscription {
|
|
69
|
-
readonly ready: Promise<void>;
|
|
70
|
-
readonly #connection: CheckedSnapshotConnection<SurfaceSnapshot>;
|
|
71
|
-
|
|
72
|
-
constructor(
|
|
73
|
-
client: SurfaceClient,
|
|
74
|
-
transport: EventTransport,
|
|
75
|
-
listener: (snapshot: SurfaceSnapshot) => void,
|
|
76
|
-
onFailure?: ConnectionFailureReporter,
|
|
77
|
-
) {
|
|
78
|
-
this.#connection = new CheckedSnapshotConnection({
|
|
79
|
-
listen: (receive) =>
|
|
80
|
-
transport.listen(SURFACE_CHANGED_EVENT, receive),
|
|
81
|
-
loadSnapshot: () => client.snapshot(),
|
|
82
|
-
validateSnapshot: parseSurfaceSnapshot,
|
|
83
|
-
handleEvent: surfaceEventAction,
|
|
84
|
-
isNewer: isNewerSurfaceSnapshot,
|
|
85
|
-
onSnapshot: listener,
|
|
86
|
-
onFailure,
|
|
87
|
-
});
|
|
88
|
-
this.ready = this.#connection.ready.then(() => undefined);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
current(): SurfaceSnapshot | undefined {
|
|
92
|
-
return this.#connection.current();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
failures(): readonly ConnectionFailure[] {
|
|
96
|
-
return this.#connection.failures();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
dispose(): Promise<void> {
|
|
100
|
-
return this.#connection.dispose();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
83
|
function parseSurfaceSnapshot(value: unknown): SurfaceSnapshot {
|
|
105
84
|
assertValidSurfaceSnapshot(value);
|
|
106
85
|
return value;
|
|
@@ -115,11 +94,10 @@ function surfaceEventAction(
|
|
|
115
94
|
return { kind: "refresh" };
|
|
116
95
|
}
|
|
117
96
|
|
|
118
|
-
const event = value
|
|
97
|
+
const event = value;
|
|
119
98
|
if (
|
|
120
99
|
event.epoch < current.epoch ||
|
|
121
|
-
(event.epoch === current.epoch &&
|
|
122
|
-
event.revision <= current.revision)
|
|
100
|
+
(event.epoch === current.epoch && event.revision <= current.revision)
|
|
123
101
|
) {
|
|
124
102
|
return { kind: "ignore" };
|
|
125
103
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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.
|
|
5
5
|
|
|
6
|
-
export const SURFACE_FIELDS
|
|
6
|
+
export const SURFACE_FIELDS = {
|
|
7
7
|
"RegionState": ["region_id", "panel_instance_ids", "active_panel_instance_id", "collapsed"],
|
|
8
8
|
"SizingSlotState": ["sizing_slot_id", "ratio"],
|
|
9
9
|
"PanelInstance": ["id", "definition_id"],
|
|
@@ -16,4 +16,4 @@ export const SURFACE_FIELDS: Record<string, readonly string[]> = {
|
|
|
16
16
|
"SurfaceMutationRejection": ["request_id", "current_revision", "code", "detail", "authoritative_document"],
|
|
17
17
|
"SurfaceSnapshot": ["protocol_version", "epoch", "revision", "document"],
|
|
18
18
|
"SurfaceChangedEvent": ["protocol_version", "epoch", "revision"],
|
|
19
|
-
};
|
|
19
|
+
} as const;
|
|
@@ -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.
|