@inflatable-cookie/longhorn 0.1.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/LICENSE +21 -0
- package/README.md +38 -0
- package/package.json +205 -0
- package/src/agent-control/index.ts +20 -0
- package/src/agent-control/inject.ts +4 -0
- package/src/agent-control/shim.ts +722 -0
- package/src/bridge/direct.ts +22 -0
- package/src/bridge/generated/fields.ts +32 -0
- package/src/bridge/generated/protocol.ts +218 -0
- package/src/bridge/generated/variant-fields.ts +10 -0
- package/src/bridge/index.ts +15 -0
- package/src/bridge/job.ts +51 -0
- package/src/bridge/loopback.ts +84 -0
- package/src/bridge/operation.ts +166 -0
- package/src/bridge/router.ts +71 -0
- package/src/bridge/runtime/connection.ts +318 -0
- package/src/bridge/runtime/policy.ts +89 -0
- package/src/bridge/runtime/retry.ts +60 -0
- package/src/bridge/runtime.ts +3 -0
- package/src/bridge/session.ts +67 -0
- package/src/bridge/stream/connection.ts +146 -0
- package/src/bridge/stream/source.ts +61 -0
- package/src/bridge/stream/tracker.ts +109 -0
- package/src/bridge/stream.ts +6 -0
- package/src/bridge/supervision.ts +204 -0
- package/src/bridge/validation/base.ts +164 -0
- package/src/bridge/validation/jobs.ts +105 -0
- package/src/bridge/validation/negotiation.ts +242 -0
- package/src/bridge/validation/operations.ts +213 -0
- package/src/bridge/validation/streams.ts +47 -0
- package/src/bridge/validation.ts +5 -0
- package/src/commands/client.ts +124 -0
- package/src/commands/controller.ts +411 -0
- package/src/commands/generated/fields.ts +43 -0
- package/src/commands/generated/protocol.ts +876 -0
- package/src/commands/generated/variant-fields.ts +88 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/keyboard.ts +361 -0
- package/src/commands/ports.ts +82 -0
- package/src/commands/projectors.ts +306 -0
- package/src/commands/validation.ts +444 -0
- package/src/config/client.ts +215 -0
- package/src/config/generated/base.ts +714 -0
- package/src/config/generated/fields.ts +54 -0
- package/src/config/generated/label-template.ts +14 -0
- package/src/config/generated/labels.ts +30 -0
- package/src/config/generated/protocol.ts +3 -0
- package/src/config/generated/restore.ts +658 -0
- package/src/config/generated/variant-fields.ts +129 -0
- package/src/config/index.ts +12 -0
- package/src/config/names.ts +19 -0
- package/src/config/validation/commands.ts +155 -0
- package/src/config/validation/outcomes.ts +243 -0
- package/src/config/validation/primitives.ts +174 -0
- package/src/config/validation/projection.ts +351 -0
- package/src/config/validation.ts +7 -0
- package/src/core/connection.ts +252 -0
- package/src/core/index.ts +2 -0
- package/src/core/transport.ts +24 -0
- package/src/history/client.ts +65 -0
- package/src/history/controller.ts +385 -0
- package/src/history/direct.ts +21 -0
- package/src/history/generated/fields.ts +18 -0
- package/src/history/generated/protocol.ts +389 -0
- package/src/history/generated/variant-fields.ts +27 -0
- package/src/history/index.ts +13 -0
- package/src/history/ports.ts +31 -0
- package/src/history/serialized.ts +38 -0
- package/src/history/validation.ts +334 -0
- package/src/history-tree/client.ts +16 -0
- package/src/history-tree/controller.ts +199 -0
- package/src/history-tree/direct.ts +3 -0
- package/src/history-tree/generated/fields.ts +26 -0
- package/src/history-tree/generated/protocol.ts +711 -0
- package/src/history-tree/generated/variant-fields.ts +39 -0
- package/src/history-tree/index.ts +13 -0
- package/src/history-tree/ports.ts +43 -0
- package/src/history-tree/serialized.ts +15 -0
- package/src/history-tree/validation.ts +269 -0
- package/src/layout/generated/protocol.ts +289 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/ratio.ts +22 -0
- package/src/layout/validation.ts +110 -0
- package/src/layout/visibility.ts +30 -0
- package/src/licence/client.ts +32 -0
- package/src/licence/controller.ts +301 -0
- package/src/licence/direct.ts +3 -0
- package/src/licence/generated/fields.ts +17 -0
- package/src/licence/generated/key-conformance.json +42 -0
- package/src/licence/generated/protocol.ts +249 -0
- package/src/licence/generated/variant-fields.ts +34 -0
- package/src/licence/index.ts +14 -0
- package/src/licence/key.ts +125 -0
- package/src/licence/ports.ts +39 -0
- package/src/licence/serialized.ts +13 -0
- package/src/licence/validation.ts +226 -0
- package/src/native-content/client.ts +474 -0
- package/src/native-content/direct.ts +16 -0
- package/src/native-content/generated/fields.ts +32 -0
- package/src/native-content/generated/protocol.ts +498 -0
- package/src/native-content/generated/variant-fields.ts +77 -0
- package/src/native-content/index.ts +12 -0
- package/src/native-content/ports.ts +46 -0
- package/src/native-content/serialized.ts +50 -0
- package/src/native-content/validation/base.ts +194 -0
- package/src/native-content/validation/messages.ts +192 -0
- package/src/native-content/validation/state.ts +404 -0
- package/src/native-content/validation.ts +7 -0
- package/src/notifications/client.ts +106 -0
- package/src/notifications/controller.ts +240 -0
- package/src/notifications/direct.ts +12 -0
- package/src/notifications/generated/fields.ts +19 -0
- package/src/notifications/generated/labels.ts +20 -0
- package/src/notifications/generated/protocol.ts +522 -0
- package/src/notifications/generated/variant-fields.ts +37 -0
- package/src/notifications/index.ts +16 -0
- package/src/notifications/ports.ts +22 -0
- package/src/notifications/serialized.ts +27 -0
- package/src/notifications/toast.ts +41 -0
- package/src/notifications/tone.ts +27 -0
- package/src/notifications/validation.ts +246 -0
- package/src/operation/bridge.ts +168 -0
- package/src/operation/client.ts +167 -0
- package/src/operation/controller.ts +321 -0
- package/src/operation/direct.ts +15 -0
- package/src/operation/generated/fields.ts +20 -0
- package/src/operation/generated/labels.ts +15 -0
- package/src/operation/generated/protocol.ts +762 -0
- package/src/operation/generated/variant-fields.ts +60 -0
- package/src/operation/index.ts +14 -0
- package/src/operation/ports.ts +29 -0
- package/src/operation/serialized.ts +39 -0
- package/src/operation/validation.ts +479 -0
- package/src/settings/client.ts +142 -0
- package/src/settings/connection.ts +246 -0
- package/src/settings/generated/fields.ts +34 -0
- package/src/settings/generated/protocol.ts +668 -0
- package/src/settings/generated/variant-fields.ts +26 -0
- package/src/settings/index.ts +12 -0
- package/src/settings/names.ts +8 -0
- package/src/settings/registry.ts +141 -0
- package/src/settings/validation/authority.ts +66 -0
- package/src/settings/validation/command.ts +165 -0
- package/src/settings/validation/error.ts +33 -0
- package/src/settings/validation/primitives.ts +203 -0
- package/src/settings/validation/projection.ts +50 -0
- package/src/settings/validation/registry.ts +170 -0
- package/src/settings/validation.ts +4 -0
- package/src/surface-transfer/client.ts +54 -0
- package/src/surface-transfer/generated/fields.ts +12 -0
- package/src/surface-transfer/generated/protocol.ts +61 -0
- package/src/surface-transfer/generated/variant-fields.ts +30 -0
- package/src/surface-transfer/index.ts +9 -0
- package/src/surface-transfer/validation.ts +209 -0
- package/src/surfaces/client.ts +140 -0
- package/src/surfaces/generated/fields.ts +19 -0
- package/src/surfaces/generated/protocol.ts +217 -0
- package/src/surfaces/generated/variant-fields.ts +42 -0
- package/src/surfaces/index.ts +9 -0
- package/src/surfaces/validation.ts +199 -0
- package/src/transfer/client.ts +133 -0
- package/src/transfer/connection.ts +87 -0
- package/src/transfer/generated/fields.ts +23 -0
- package/src/transfer/generated/protocol.ts +171 -0
- package/src/transfer/generated/variant-fields.ts +45 -0
- package/src/transfer/index.ts +11 -0
- package/src/transfer/payload.ts +71 -0
- package/src/transfer/validation.ts +282 -0
- package/src/update/client.ts +29 -0
- package/src/update/controller.ts +255 -0
- package/src/update/direct.ts +3 -0
- package/src/update/generated/fields.ts +14 -0
- package/src/update/generated/protocol.ts +238 -0
- package/src/update/generated/variant-fields.ts +44 -0
- package/src/update/index.ts +14 -0
- package/src/update/ports.ts +36 -0
- package/src/update/serialized.ts +12 -0
- package/src/update/validation.ts +191 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { NATIVE_CONTENT_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
NATIVE_CONTENT_ATTACHMENT_LIFECYCLES,
|
|
4
|
+
NATIVE_CONTENT_CHANGE_KINDS,
|
|
5
|
+
NATIVE_CONTENT_DESIRED_PRESENCE,
|
|
6
|
+
NATIVE_CONTENT_DESIRED_VISIBILITY_STATES,
|
|
7
|
+
NATIVE_CONTENT_DETACH_POLICIES,
|
|
8
|
+
NATIVE_CONTENT_EFFECTIVE_FOCUS_STATES,
|
|
9
|
+
NATIVE_CONTENT_EFFECTIVE_VISIBILITY_STATES,
|
|
10
|
+
NATIVE_CONTENT_FOCUS_INTENTS,
|
|
11
|
+
NATIVE_CONTENT_HOST_DESTROY_OUTCOMES,
|
|
12
|
+
NATIVE_CONTENT_INPUT_ROUTING_MODES,
|
|
13
|
+
NATIVE_CONTENT_MECHANISMS,
|
|
14
|
+
NATIVE_CONTENT_OBSERVED_GEOMETRY_KINDS,
|
|
15
|
+
NATIVE_CONTENT_OPERATION_KINDS,
|
|
16
|
+
NATIVE_CONTENT_OPERATION_OUTCOME_KINDS,
|
|
17
|
+
NATIVE_CONTENT_READINESS_STATES,
|
|
18
|
+
NATIVE_CONTENT_SIZE_DECISION_KINDS,
|
|
19
|
+
type ContentSizeDecision,
|
|
20
|
+
type ContentSizeProposal,
|
|
21
|
+
type DesiredUpdate,
|
|
22
|
+
type NativeContentChangedEvent,
|
|
23
|
+
type NativeContentCursor,
|
|
24
|
+
type NativeContentSnapshot,
|
|
25
|
+
} from "../generated/protocol.ts";
|
|
26
|
+
import {
|
|
27
|
+
array,
|
|
28
|
+
assertNativeContentProtocolVersion,
|
|
29
|
+
assertProductPayloadFree,
|
|
30
|
+
boolean,
|
|
31
|
+
exactKeys,
|
|
32
|
+
variantKeys,
|
|
33
|
+
exactObject,
|
|
34
|
+
fail,
|
|
35
|
+
finite,
|
|
36
|
+
member,
|
|
37
|
+
natural,
|
|
38
|
+
nullable,
|
|
39
|
+
opaqueId,
|
|
40
|
+
positive,
|
|
41
|
+
record,
|
|
42
|
+
} from "./base.ts";
|
|
43
|
+
|
|
44
|
+
export function assertValidNativeContentSnapshot(
|
|
45
|
+
value: unknown,
|
|
46
|
+
): asserts value is NativeContentSnapshot {
|
|
47
|
+
assertProductPayloadFree(value);
|
|
48
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentSnapshot);
|
|
49
|
+
assertNativeContentProtocolVersion(object.protocol_version);
|
|
50
|
+
cursor(object.cursor, "$.cursor");
|
|
51
|
+
desiredState(object.desired, "$.desired");
|
|
52
|
+
observedState(object.observed, "$.observed");
|
|
53
|
+
nullable(object.invalidated_generation, "$.invalidated_generation", positive);
|
|
54
|
+
const desired = object.desired as Record<string, unknown>;
|
|
55
|
+
const observed = object.observed as Record<string, unknown>;
|
|
56
|
+
const valueCursor = object.cursor as Record<string, unknown>;
|
|
57
|
+
if (
|
|
58
|
+
desired.island_id !== valueCursor.island_id ||
|
|
59
|
+
desired.generation !== valueCursor.attach_generation ||
|
|
60
|
+
desired.revision !== valueCursor.desired_revision ||
|
|
61
|
+
observed.revision !== valueCursor.observed_revision
|
|
62
|
+
) {
|
|
63
|
+
fail("$.cursor", "snapshot cursor does not match state");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function assertValidNativeContentChangedEvent(
|
|
68
|
+
value: unknown,
|
|
69
|
+
): asserts value is NativeContentChangedEvent {
|
|
70
|
+
assertProductPayloadFree(value);
|
|
71
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentChangedEvent);
|
|
72
|
+
assertNativeContentProtocolVersion(object.protocol_version);
|
|
73
|
+
cursor(object.cursor, "$.cursor");
|
|
74
|
+
change(object.change, "$.change");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function assertValidDesiredUpdate(
|
|
78
|
+
value: unknown,
|
|
79
|
+
): asserts value is DesiredUpdate {
|
|
80
|
+
desiredUpdate(value, "$", false);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function assertValidContentSizeProposal(
|
|
84
|
+
value: unknown,
|
|
85
|
+
): asserts value is ContentSizeProposal {
|
|
86
|
+
proposal(value, "$");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function assertValidContentSizeDecision(
|
|
90
|
+
value: unknown,
|
|
91
|
+
): asserts value is ContentSizeDecision {
|
|
92
|
+
decision(value, "$");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function cursor(value: unknown, path: string): asserts value is NativeContentCursor {
|
|
96
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.NativeContentCursor);
|
|
97
|
+
positive(object.authority_epoch, `${path}.authority_epoch`);
|
|
98
|
+
positive(object.client_epoch, `${path}.client_epoch`);
|
|
99
|
+
opaqueId(object.island_id, `${path}.island_id`);
|
|
100
|
+
positive(object.attach_generation, `${path}.attach_generation`);
|
|
101
|
+
natural(object.desired_revision, `${path}.desired_revision`);
|
|
102
|
+
natural(object.observed_revision, `${path}.observed_revision`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function proposal(
|
|
106
|
+
value: unknown,
|
|
107
|
+
path: string,
|
|
108
|
+
): asserts value is ContentSizeProposal {
|
|
109
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ContentSizeProposal);
|
|
110
|
+
positive(object.generation, `${path}.generation`);
|
|
111
|
+
natural(object.desired_revision, `${path}.desired_revision`);
|
|
112
|
+
clientSize(object.size, `${path}.size`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function decision(
|
|
116
|
+
value: unknown,
|
|
117
|
+
path: string,
|
|
118
|
+
): asserts value is ContentSizeDecision {
|
|
119
|
+
const object = record(value, path);
|
|
120
|
+
member(object.kind, NATIVE_CONTENT_SIZE_DECISION_KINDS, `${path}.kind`);
|
|
121
|
+
if (object.kind === "accepted") {
|
|
122
|
+
exactKeys(object, path, variantKeys("ContentSizeDecision", object, path));
|
|
123
|
+
} else if (object.kind === "constrained") {
|
|
124
|
+
exactKeys(object, path, variantKeys("ContentSizeDecision", object, path));
|
|
125
|
+
clientSize(object.size, `${path}.size`);
|
|
126
|
+
} else {
|
|
127
|
+
exactKeys(object, path, variantKeys("ContentSizeDecision", object, path));
|
|
128
|
+
opaqueId(object.code, `${path}.code`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function desiredUpdate(
|
|
133
|
+
value: unknown,
|
|
134
|
+
path: string,
|
|
135
|
+
includeIdentity: boolean,
|
|
136
|
+
): void {
|
|
137
|
+
const keys = [
|
|
138
|
+
"generation",
|
|
139
|
+
"host_window_id",
|
|
140
|
+
"viewport",
|
|
141
|
+
"scale",
|
|
142
|
+
"rounding",
|
|
143
|
+
"presence",
|
|
144
|
+
"visibility",
|
|
145
|
+
"focus",
|
|
146
|
+
"input_routing",
|
|
147
|
+
];
|
|
148
|
+
if (includeIdentity) keys.unshift("island_id", "kind_id", "capabilities", "revision");
|
|
149
|
+
const object = exactObject(value, path, keys);
|
|
150
|
+
if (includeIdentity) {
|
|
151
|
+
opaqueId(object.island_id, `${path}.island_id`);
|
|
152
|
+
opaqueId(object.kind_id, `${path}.kind_id`);
|
|
153
|
+
capabilities(object.capabilities, `${path}.capabilities`);
|
|
154
|
+
natural(object.revision, `${path}.revision`);
|
|
155
|
+
}
|
|
156
|
+
positive(object.generation, `${path}.generation`);
|
|
157
|
+
opaqueId(object.host_window_id, `${path}.host_window_id`);
|
|
158
|
+
clientRect(object.viewport, `${path}.viewport`);
|
|
159
|
+
positive(object.scale, `${path}.scale`);
|
|
160
|
+
member(object.rounding, ["floor", "ceil", "nearest"] as const, `${path}.rounding`);
|
|
161
|
+
member(object.presence, NATIVE_CONTENT_DESIRED_PRESENCE, `${path}.presence`);
|
|
162
|
+
desiredVisibility(object.visibility, `${path}.visibility`);
|
|
163
|
+
member(object.focus, NATIVE_CONTENT_FOCUS_INTENTS, `${path}.focus`);
|
|
164
|
+
member(object.input_routing, NATIVE_CONTENT_INPUT_ROUTING_MODES, `${path}.input_routing`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function desiredState(value: unknown, path: string): void {
|
|
168
|
+
desiredUpdate(value, path, true);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function capabilities(value: unknown, path: string): void {
|
|
172
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.MechanismCapabilities);
|
|
173
|
+
member(object.mechanism, NATIVE_CONTENT_MECHANISMS, `${path}.mechanism`);
|
|
174
|
+
member(object.active_input_routing, NATIVE_CONTENT_INPUT_ROUTING_MODES, `${path}.active_input_routing`);
|
|
175
|
+
boolean(object.accepts_content_size_requests, `${path}.accepts_content_size_requests`);
|
|
176
|
+
member(object.detach_policy, NATIVE_CONTENT_DETACH_POLICIES, `${path}.detach_policy`);
|
|
177
|
+
boolean(object.observes_visibility, `${path}.observes_visibility`);
|
|
178
|
+
boolean(object.observes_focus, `${path}.observes_focus`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function desiredVisibility(value: unknown, path: string): void {
|
|
182
|
+
const object = record(value, path);
|
|
183
|
+
member(object.state, NATIVE_CONTENT_DESIRED_VISIBILITY_STATES, `${path}.state`);
|
|
184
|
+
if (object.state === "visible") {
|
|
185
|
+
exactKeys(object, path, variantKeys("DesiredVisibility", object, path));
|
|
186
|
+
} else {
|
|
187
|
+
exactKeys(object, path, variantKeys("DesiredVisibility", object, path));
|
|
188
|
+
opaqueId(object.reason, `${path}.reason`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function observedState(value: unknown, path: string): void {
|
|
193
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ObservedState);
|
|
194
|
+
natural(object.revision, `${path}.revision`);
|
|
195
|
+
positive(object.generation, `${path}.generation`);
|
|
196
|
+
member(object.lifecycle, NATIVE_CONTENT_ATTACHMENT_LIFECYCLES, `${path}.lifecycle`);
|
|
197
|
+
member(object.readiness, NATIVE_CONTENT_READINESS_STATES, `${path}.readiness`);
|
|
198
|
+
member(object.visibility, NATIVE_CONTENT_EFFECTIVE_VISIBILITY_STATES, `${path}.visibility`);
|
|
199
|
+
member(object.focus, NATIVE_CONTENT_EFFECTIVE_FOCUS_STATES, `${path}.focus`);
|
|
200
|
+
observedGeometry(object.geometry, `${path}.geometry`);
|
|
201
|
+
nullable(object.input_routing, `${path}.input_routing`, (candidate, candidatePath) =>
|
|
202
|
+
member(candidate, NATIVE_CONTENT_INPUT_ROUTING_MODES, candidatePath)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function observedGeometry(value: unknown, path: string): void {
|
|
207
|
+
const object = record(value, path);
|
|
208
|
+
member(object.kind, NATIVE_CONTENT_OBSERVED_GEOMETRY_KINDS, `${path}.kind`);
|
|
209
|
+
switch (object.kind) {
|
|
210
|
+
case "unknown":
|
|
211
|
+
exactKeys(object, path, variantKeys("ObservedGeometry", object, path));
|
|
212
|
+
break;
|
|
213
|
+
case "child_bounds":
|
|
214
|
+
exactKeys(object, path, variantKeys("ObservedGeometry", object, path));
|
|
215
|
+
physicalRect(object.bounds, `${path}.bounds`);
|
|
216
|
+
break;
|
|
217
|
+
case "isolated_content":
|
|
218
|
+
exactKeys(object, path, variantKeys("ObservedGeometry", object, path));
|
|
219
|
+
physicalSize(object.size, `${path}.size`);
|
|
220
|
+
break;
|
|
221
|
+
case "backing_surface":
|
|
222
|
+
exactKeys(object, path, variantKeys("ObservedGeometry", object, path));
|
|
223
|
+
physicalRect(object.storage_bounds, `${path}.storage_bounds`);
|
|
224
|
+
physicalRect(object.clip, `${path}.clip`);
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function change(value: unknown, path: string): void {
|
|
230
|
+
const object = record(value, path);
|
|
231
|
+
member(object.kind, NATIVE_CONTENT_CHANGE_KINDS, `${path}.kind`);
|
|
232
|
+
switch (object.kind) {
|
|
233
|
+
case "desired_updated":
|
|
234
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
235
|
+
opaqueId(object.request_id, `${path}.request_id`);
|
|
236
|
+
desiredReceipt(object.receipt, `${path}.receipt`);
|
|
237
|
+
break;
|
|
238
|
+
case "observation_admitted":
|
|
239
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
240
|
+
nullable(object.request_id, `${path}.request_id`, opaqueId);
|
|
241
|
+
observationReceipt(object.receipt, `${path}.receipt`);
|
|
242
|
+
break;
|
|
243
|
+
case "content_size_proposed":
|
|
244
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
245
|
+
opaqueId(object.request_id, `${path}.request_id`);
|
|
246
|
+
proposal(object.proposal, `${path}.proposal`);
|
|
247
|
+
break;
|
|
248
|
+
case "content_size_decided":
|
|
249
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
250
|
+
opaqueId(object.request_id, `${path}.request_id`);
|
|
251
|
+
proposalReceipt(object.receipt, `${path}.receipt`);
|
|
252
|
+
break;
|
|
253
|
+
case "apply_completed":
|
|
254
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
255
|
+
opaqueId(object.request_id, `${path}.request_id`);
|
|
256
|
+
applyReceipt(object.receipt, `${path}.receipt`);
|
|
257
|
+
break;
|
|
258
|
+
case "host_destroyed":
|
|
259
|
+
exactKeys(object, path, variantKeys("NativeContentChangeProjection", object, path));
|
|
260
|
+
nullable(object.request_id, `${path}.request_id`, opaqueId);
|
|
261
|
+
hostDestroyReceipt(object.receipt, `${path}.receipt`);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function desiredReceipt(value: unknown, path: string): void {
|
|
267
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.DesiredUpdateReceipt);
|
|
268
|
+
natural(object.previous_revision, `${path}.previous_revision`);
|
|
269
|
+
natural(object.current_revision, `${path}.current_revision`);
|
|
270
|
+
positive(object.generation, `${path}.generation`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function proposalReceipt(value: unknown, path: string): void {
|
|
274
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ContentSizeProposalReceipt);
|
|
275
|
+
proposal(object.proposal, `${path}.proposal`);
|
|
276
|
+
decision(object.decision, `${path}.decision`);
|
|
277
|
+
nullable(object.accepted_size, `${path}.accepted_size`, clientSize);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function observationReceipt(value: unknown, path: string): void {
|
|
281
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ObservationReceipt);
|
|
282
|
+
natural(object.previous_revision, `${path}.previous_revision`);
|
|
283
|
+
natural(object.current_revision, `${path}.current_revision`);
|
|
284
|
+
positive(object.generation, `${path}.generation`);
|
|
285
|
+
member(object.lifecycle, NATIVE_CONTENT_ATTACHMENT_LIFECYCLES, `${path}.lifecycle`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function hostDestroyReceipt(value: unknown, path: string): void {
|
|
289
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.HostDestroyReceipt);
|
|
290
|
+
natural(object.previous_observed_revision, `${path}.previous_observed_revision`);
|
|
291
|
+
natural(object.current_observed_revision, `${path}.current_observed_revision`);
|
|
292
|
+
positive(object.generation, `${path}.generation`);
|
|
293
|
+
member(object.outcome, NATIVE_CONTENT_HOST_DESTROY_OUTCOMES, `${path}.outcome`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function applyReceipt(value: unknown, path: string): void {
|
|
297
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ApplyReceipt);
|
|
298
|
+
opaqueId(object.island_id, `${path}.island_id`);
|
|
299
|
+
natural(object.desired_revision, `${path}.desired_revision`);
|
|
300
|
+
natural(object.observed_revision, `${path}.observed_revision`);
|
|
301
|
+
positive(object.generation, `${path}.generation`);
|
|
302
|
+
const steps = array(object.steps, `${path}.steps`);
|
|
303
|
+
if (steps.length > 5) fail(`${path}.steps`, "apply receipt exceeds five steps");
|
|
304
|
+
steps.forEach((step, index) => stepReceipt(step, `${path}.steps[${index}]`));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function stepReceipt(value: unknown, path: string): void {
|
|
308
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.StepReceipt);
|
|
309
|
+
positive(object.step, `${path}.step`);
|
|
310
|
+
operation(object.operation, `${path}.operation`);
|
|
311
|
+
outcome(object.outcome, `${path}.outcome`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function operation(value: unknown, path: string): void {
|
|
315
|
+
const object = record(value, path);
|
|
316
|
+
member(object.kind, NATIVE_CONTENT_OPERATION_KINDS, `${path}.kind`);
|
|
317
|
+
switch (object.kind) {
|
|
318
|
+
case "attach":
|
|
319
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
320
|
+
opaqueId(object.host_window_id, `${path}.host_window_id`);
|
|
321
|
+
member(object.mechanism, NATIVE_CONTENT_MECHANISMS, `${path}.mechanism`);
|
|
322
|
+
break;
|
|
323
|
+
case "set_child_bounds":
|
|
324
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
325
|
+
physicalRect(object.bounds, `${path}.bounds`);
|
|
326
|
+
break;
|
|
327
|
+
case "set_isolated_content_size":
|
|
328
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
329
|
+
physicalSize(object.size, `${path}.size`);
|
|
330
|
+
break;
|
|
331
|
+
case "set_backing_viewport":
|
|
332
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
333
|
+
physicalRect(object.clip, `${path}.clip`);
|
|
334
|
+
break;
|
|
335
|
+
case "hide":
|
|
336
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
337
|
+
opaqueId(object.reason, `${path}.reason`);
|
|
338
|
+
break;
|
|
339
|
+
case "set_input_routing":
|
|
340
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
341
|
+
member(object.mode, NATIVE_CONTENT_INPUT_ROUTING_MODES, `${path}.mode`);
|
|
342
|
+
break;
|
|
343
|
+
case "detach":
|
|
344
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
345
|
+
member(object.policy, NATIVE_CONTENT_DETACH_POLICIES, `${path}.policy`);
|
|
346
|
+
break;
|
|
347
|
+
case "show":
|
|
348
|
+
case "request_focus":
|
|
349
|
+
case "release_focus_if_owned":
|
|
350
|
+
exactKeys(object, path, variantKeys("NativeContentOperation", object, path));
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function outcome(value: unknown, path: string): void {
|
|
356
|
+
const object = record(value, path);
|
|
357
|
+
member(object.kind, NATIVE_CONTENT_OPERATION_OUTCOME_KINDS, `${path}.kind`);
|
|
358
|
+
if (object.kind === "failed") {
|
|
359
|
+
exactKeys(object, path, variantKeys("OperationOutcome", object, path));
|
|
360
|
+
opaqueId(object.code, `${path}.code`);
|
|
361
|
+
} else if (object.kind === "dependency_skipped") {
|
|
362
|
+
exactKeys(object, path, variantKeys("OperationOutcome", object, path));
|
|
363
|
+
positive(object.blocked_by, `${path}.blocked_by`);
|
|
364
|
+
} else {
|
|
365
|
+
exactKeys(object, path, variantKeys("OperationOutcome", object, path));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function clientRect(value: unknown, path: string): void {
|
|
370
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ClientRect);
|
|
371
|
+
const origin = exactObject(object.origin, `${path}.origin`, NATIVE_CONTENT_FIELDS.ClientPoint);
|
|
372
|
+
finite(origin.x, `${path}.origin.x`);
|
|
373
|
+
finite(origin.y, `${path}.origin.y`);
|
|
374
|
+
clientSize(object.size, `${path}.size`);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function clientSize(value: unknown, path: string): void {
|
|
378
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ClientSize);
|
|
379
|
+
finite(object.width, `${path}.width`);
|
|
380
|
+
finite(object.height, `${path}.height`);
|
|
381
|
+
if ((object.width as number) < 0 || (object.height as number) < 0) {
|
|
382
|
+
fail(path, "contains negative extent");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function physicalRect(value: unknown, path: string): void {
|
|
387
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ClientRect);
|
|
388
|
+
const origin = exactObject(object.origin, `${path}.origin`, NATIVE_CONTENT_FIELDS.ClientPoint);
|
|
389
|
+
integer(origin.x, `${path}.origin.x`);
|
|
390
|
+
integer(origin.y, `${path}.origin.y`);
|
|
391
|
+
physicalSize(object.size, `${path}.size`);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function physicalSize(value: unknown, path: string): void {
|
|
395
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ClientSize);
|
|
396
|
+
natural(object.width, `${path}.width`);
|
|
397
|
+
natural(object.height, `${path}.height`);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function integer(value: unknown, path: string): void {
|
|
401
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
402
|
+
fail(path, "expected safe integer");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CheckedSnapshotConnection, type ConnectionFailure, type ConnectionFailureReporter } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
assertValidNotificationChangedEvent,
|
|
5
|
+
assertValidNotificationMutationCommand,
|
|
6
|
+
assertValidNotificationMutationResult,
|
|
7
|
+
assertValidNotificationSnapshotResponse,
|
|
8
|
+
} from "./validation.ts";
|
|
9
|
+
import {
|
|
10
|
+
NOTIFICATION_PROTOCOL_VERSION,
|
|
11
|
+
type NotificationChangedEvent,
|
|
12
|
+
type NotificationMutationCommand,
|
|
13
|
+
type NotificationMutationResult,
|
|
14
|
+
type NotificationSnapshot,
|
|
15
|
+
type NotificationSnapshotResponse,
|
|
16
|
+
} from "./generated/protocol.ts";
|
|
17
|
+
import type { NotificationPort } from "./ports.ts";
|
|
18
|
+
|
|
19
|
+
export interface NotificationSubscription {
|
|
20
|
+
readonly ready: Promise<void>;
|
|
21
|
+
current(): NotificationSnapshot | undefined;
|
|
22
|
+
failures(): readonly ConnectionFailure[];
|
|
23
|
+
dispose(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class NotificationClient {
|
|
27
|
+
constructor(readonly port: NotificationPort) {}
|
|
28
|
+
|
|
29
|
+
nextRequestId(): string { return this.port.nextRequestId(); }
|
|
30
|
+
|
|
31
|
+
async snapshot(offset = 0, limit = 100): Promise<NotificationSnapshotResponse> {
|
|
32
|
+
const requestId = this.port.nextRequestId();
|
|
33
|
+
const value = await this.port.snapshot({ protocolVersion: NOTIFICATION_PROTOCOL_VERSION, requestId, offset, limit });
|
|
34
|
+
assertValidNotificationSnapshotResponse(value);
|
|
35
|
+
assertCorrelation(value.requestId, requestId);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async mutate(command: NotificationMutationCommand): Promise<NotificationMutationResult> {
|
|
40
|
+
assertValidNotificationMutationCommand(command);
|
|
41
|
+
const value = await this.port.mutate(command);
|
|
42
|
+
assertValidNotificationMutationResult(value);
|
|
43
|
+
assertCorrelation(value.requestId, command.requestId);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
subscribe(listener: (snapshot: NotificationSnapshot) => void, onFailure?: ConnectionFailureReporter, limit = 100): NotificationSubscription {
|
|
48
|
+
return new CheckedNotificationSubscription(this, this.port, listener, onFailure, limit);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class NotificationResponseCorrelationError extends Error {
|
|
53
|
+
constructor(readonly expectedRequestId: string, readonly receivedRequestId: string) {
|
|
54
|
+
super(`notification response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`);
|
|
55
|
+
this.name = "NotificationResponseCorrelationError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class CheckedNotificationSubscription implements NotificationSubscription {
|
|
60
|
+
readonly ready: Promise<void>;
|
|
61
|
+
readonly connection: CheckedSnapshotConnection<NotificationSnapshot>;
|
|
62
|
+
|
|
63
|
+
constructor(client: NotificationClient, port: NotificationPort, listener: (snapshot: NotificationSnapshot) => void, onFailure: ConnectionFailureReporter | undefined, limit: number) {
|
|
64
|
+
this.connection = new CheckedSnapshotConnection({
|
|
65
|
+
listen: async (receive) => port.listen === undefined ? () => {} : port.listen(receive),
|
|
66
|
+
loadSnapshot: async () => (await client.snapshot(0, limit)).snapshot,
|
|
67
|
+
validateSnapshot: parseSnapshot,
|
|
68
|
+
handleEvent: notificationEventAction,
|
|
69
|
+
isNewer: isNewerNotificationSnapshot,
|
|
70
|
+
onSnapshot: listener,
|
|
71
|
+
onFailure,
|
|
72
|
+
});
|
|
73
|
+
this.ready = this.connection.ready.then(() => undefined);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
current(): NotificationSnapshot | undefined { return this.connection.current(); }
|
|
77
|
+
failures(): readonly ConnectionFailure[] { return this.connection.failures(); }
|
|
78
|
+
dispose(): Promise<void> { return this.connection.dispose(); }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function parseSnapshot(value: unknown): NotificationSnapshot {
|
|
82
|
+
const response = { requestId: "request:validation", snapshot: value };
|
|
83
|
+
assertValidNotificationSnapshotResponse(response);
|
|
84
|
+
return value as NotificationSnapshot;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function notificationEventAction(value: unknown, current: NotificationSnapshot | undefined): { kind: "ignore" } | { kind: "refresh" } {
|
|
88
|
+
assertValidNotificationChangedEvent(value);
|
|
89
|
+
const event = value as NotificationChangedEvent;
|
|
90
|
+
if (current === undefined) return { kind: "refresh" };
|
|
91
|
+
if (event.authority.authorityId !== current.authority.authorityId) return { kind: "ignore" };
|
|
92
|
+
if (event.authority.authorityEpoch < current.authority.authorityEpoch) return { kind: "ignore" };
|
|
93
|
+
if (event.authority.authorityEpoch === current.authority.authorityEpoch && event.committedLedgerRevision <= current.ledgerRevision) return { kind: "ignore" };
|
|
94
|
+
return { kind: "refresh" };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function isNewerNotificationSnapshot(candidate: NotificationSnapshot, current: NotificationSnapshot | undefined): boolean {
|
|
98
|
+
if (current === undefined) return true;
|
|
99
|
+
if (candidate.authority.authorityId !== current.authority.authorityId) return false;
|
|
100
|
+
if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
|
|
101
|
+
return candidate.ledgerRevision > current.ledgerRevision;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function assertCorrelation(received: string, expected: string): void {
|
|
105
|
+
if (received !== expected) throw new NotificationResponseCorrelationError(expected, received);
|
|
106
|
+
}
|