@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,170 @@
|
|
|
1
|
+
import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
SETTINGS_MUTATION_TIMINGS,
|
|
4
|
+
type SettingsRegistrySnapshot,
|
|
5
|
+
} from "../generated/protocol.ts";
|
|
6
|
+
import { incompatible } from "./error.ts";
|
|
7
|
+
import {
|
|
8
|
+
arraysOfIdentities,
|
|
9
|
+
boolean,
|
|
10
|
+
boundedArray,
|
|
11
|
+
definition,
|
|
12
|
+
identity,
|
|
13
|
+
integer,
|
|
14
|
+
known,
|
|
15
|
+
positive,
|
|
16
|
+
protocolVersion,
|
|
17
|
+
record,
|
|
18
|
+
text,
|
|
19
|
+
unsigned,
|
|
20
|
+
HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
21
|
+
} from "./primitives.ts";
|
|
22
|
+
|
|
23
|
+
const DIGEST = /^[a-f0-9]{64}$/;
|
|
24
|
+
|
|
25
|
+
export function assertValidSettingsRegistrySnapshot(
|
|
26
|
+
value: unknown,
|
|
27
|
+
): asserts value is SettingsRegistrySnapshot {
|
|
28
|
+
const registry = record(value, SETTINGS_FIELDS.SettingsRegistrySnapshot);
|
|
29
|
+
protocolVersion(registry.protocolVersion);
|
|
30
|
+
unsigned(registry.generation, "invalid_revision");
|
|
31
|
+
if (typeof registry.digest !== "string" || !DIGEST.test(registry.digest)) {
|
|
32
|
+
incompatible("invalid_registry", registry.digest);
|
|
33
|
+
}
|
|
34
|
+
const limits = settingsLimits(registry.limits);
|
|
35
|
+
const modules = boundedArray(
|
|
36
|
+
registry.modules,
|
|
37
|
+
limits.maximumModules,
|
|
38
|
+
"invalid_registry",
|
|
39
|
+
);
|
|
40
|
+
const sections = boundedArray(
|
|
41
|
+
registry.sections,
|
|
42
|
+
limits.maximumSections,
|
|
43
|
+
"invalid_registry",
|
|
44
|
+
);
|
|
45
|
+
const pages = boundedArray(
|
|
46
|
+
registry.pages,
|
|
47
|
+
limits.maximumPages,
|
|
48
|
+
"invalid_registry",
|
|
49
|
+
);
|
|
50
|
+
const renderers = boundedArray(
|
|
51
|
+
registry.renderers,
|
|
52
|
+
limits.maximumRenderers,
|
|
53
|
+
"invalid_registry",
|
|
54
|
+
);
|
|
55
|
+
const scopes = boundedArray(
|
|
56
|
+
registry.scopes,
|
|
57
|
+
limits.maximumScopes,
|
|
58
|
+
"invalid_registry",
|
|
59
|
+
);
|
|
60
|
+
const applyUnits = boundedArray(
|
|
61
|
+
registry.applyUnits,
|
|
62
|
+
limits.maximumApplyUnits,
|
|
63
|
+
"invalid_registry",
|
|
64
|
+
);
|
|
65
|
+
const capabilities = boundedArray(
|
|
66
|
+
registry.capabilities,
|
|
67
|
+
limits.maximumCapabilities,
|
|
68
|
+
"invalid_registry",
|
|
69
|
+
);
|
|
70
|
+
boundedArray(
|
|
71
|
+
registry.composedCapabilities,
|
|
72
|
+
limits.maximumCapabilities,
|
|
73
|
+
"invalid_registry",
|
|
74
|
+
).forEach(identity);
|
|
75
|
+
|
|
76
|
+
modules.forEach((value) => {
|
|
77
|
+
const module = record(value, SETTINGS_FIELDS.SettingsModuleDefinition);
|
|
78
|
+
identity(module.id);
|
|
79
|
+
text(module.label, limits.maximumLabelBytes);
|
|
80
|
+
integer(module.order);
|
|
81
|
+
});
|
|
82
|
+
sections.forEach((value) => {
|
|
83
|
+
const section = record(value, SETTINGS_FIELDS.SettingsSectionDefinition);
|
|
84
|
+
identity(section.id);
|
|
85
|
+
identity(section.moduleId);
|
|
86
|
+
text(section.label, limits.maximumLabelBytes);
|
|
87
|
+
integer(section.order);
|
|
88
|
+
});
|
|
89
|
+
renderers.forEach(definition);
|
|
90
|
+
scopes.forEach(definition);
|
|
91
|
+
capabilities.forEach(definition);
|
|
92
|
+
applyUnits.forEach((value) => {
|
|
93
|
+
const unit = record(value, SETTINGS_FIELDS.SettingsApplyUnitDefinition);
|
|
94
|
+
identity(unit.id);
|
|
95
|
+
identity(unit.moduleId);
|
|
96
|
+
identity(unit.scopeId);
|
|
97
|
+
known(unit.timing, SETTINGS_MUTATION_TIMINGS);
|
|
98
|
+
boolean(unit.resetSupported);
|
|
99
|
+
});
|
|
100
|
+
pages.forEach((value) => validatePage(value, limits));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function validatePage(
|
|
104
|
+
value: unknown,
|
|
105
|
+
limits: Record<string, number>,
|
|
106
|
+
): void {
|
|
107
|
+
const page = record(value, SETTINGS_FIELDS.SettingsPageDefinition);
|
|
108
|
+
identity(page.id);
|
|
109
|
+
identity(page.moduleId);
|
|
110
|
+
identity(page.sectionId);
|
|
111
|
+
identity(page.rendererId);
|
|
112
|
+
text(page.label, limits.maximumLabelBytes!);
|
|
113
|
+
integer(page.order);
|
|
114
|
+
boundedArray(
|
|
115
|
+
page.keywords,
|
|
116
|
+
limits.maximumKeywordsPerPage!,
|
|
117
|
+
"invalid_registry",
|
|
118
|
+
).forEach((keyword) => text(keyword, limits.maximumKeywordBytes!));
|
|
119
|
+
boundedArray(
|
|
120
|
+
page.anchors,
|
|
121
|
+
limits.maximumAnchorsPerPage!,
|
|
122
|
+
"invalid_registry",
|
|
123
|
+
).forEach((value) => {
|
|
124
|
+
const anchor = record(value, SETTINGS_FIELDS.SettingsAnchorDefinition);
|
|
125
|
+
identity(anchor.id);
|
|
126
|
+
if (anchor.label !== null) {
|
|
127
|
+
text(anchor.label, limits.maximumLabelBytes!);
|
|
128
|
+
}
|
|
129
|
+
integer(anchor.order);
|
|
130
|
+
});
|
|
131
|
+
arraysOfIdentities(
|
|
132
|
+
page.requiredCapabilities,
|
|
133
|
+
page.readableScopeIds,
|
|
134
|
+
page.writableApplyUnitIds,
|
|
135
|
+
);
|
|
136
|
+
const features = record(page.features, SETTINGS_FIELDS.SettingsPageFeatures);
|
|
137
|
+
boolean(features.reset);
|
|
138
|
+
boolean(features.import);
|
|
139
|
+
boolean(features.backup);
|
|
140
|
+
boolean(features.restore);
|
|
141
|
+
boolean(features.confirmation);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function settingsLimits(value: unknown): Record<string, number> {
|
|
145
|
+
const limits = record(value, SETTINGS_FIELDS.SettingsLimits);
|
|
146
|
+
const names = [
|
|
147
|
+
"maximumModules",
|
|
148
|
+
"maximumSections",
|
|
149
|
+
"maximumPages",
|
|
150
|
+
"maximumRenderers",
|
|
151
|
+
"maximumScopes",
|
|
152
|
+
"maximumApplyUnits",
|
|
153
|
+
"maximumCapabilities",
|
|
154
|
+
"maximumAnchorsPerPage",
|
|
155
|
+
"maximumKeywordsPerPage",
|
|
156
|
+
"maximumLabelBytes",
|
|
157
|
+
"maximumKeywordBytes",
|
|
158
|
+
"maximumOpaqueValueBytes",
|
|
159
|
+
] as const;
|
|
160
|
+
for (const name of names) {
|
|
161
|
+
positive(limits[name], "invalid_registry");
|
|
162
|
+
}
|
|
163
|
+
if (
|
|
164
|
+
(limits.maximumOpaqueValueBytes as number) >
|
|
165
|
+
HARD_MAXIMUM_OPAQUE_VALUE_BYTES
|
|
166
|
+
) {
|
|
167
|
+
incompatible("invalid_registry", limits.maximumOpaqueValueBytes);
|
|
168
|
+
}
|
|
169
|
+
return limits as Record<(typeof names)[number], number>;
|
|
170
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import {
|
|
3
|
+
assertValidTransferCommitSelector,
|
|
4
|
+
assertTransferProtocolVersion,
|
|
5
|
+
} from "@inflatable-cookie/longhorn/transfer";
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
SurfaceSessionResponse,
|
|
9
|
+
SurfaceSessionStartRequest,
|
|
10
|
+
SurfaceTransferCommand,
|
|
11
|
+
SurfaceTransferResponse,
|
|
12
|
+
} from "./generated/protocol.ts";
|
|
13
|
+
import {
|
|
14
|
+
assertValidSurfaceSessionResponse,
|
|
15
|
+
assertValidSurfaceTransferResponse,
|
|
16
|
+
} from "./validation.ts";
|
|
17
|
+
|
|
18
|
+
export const TRANSFER_START_SURFACE_COMMAND =
|
|
19
|
+
"longhorn_transfer_start_surface";
|
|
20
|
+
export const TRANSFER_COMMIT_SURFACE_COMMAND =
|
|
21
|
+
"longhorn_transfer_commit_surface";
|
|
22
|
+
|
|
23
|
+
export class SurfaceTransferClient {
|
|
24
|
+
readonly #transport: InvokeTransport;
|
|
25
|
+
|
|
26
|
+
constructor(transport: InvokeTransport) {
|
|
27
|
+
this.#transport = transport;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async start(
|
|
31
|
+
request: SurfaceSessionStartRequest,
|
|
32
|
+
): Promise<SurfaceSessionResponse> {
|
|
33
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
34
|
+
const value = await this.#transport.invoke(
|
|
35
|
+
TRANSFER_START_SURFACE_COMMAND,
|
|
36
|
+
{ request },
|
|
37
|
+
);
|
|
38
|
+
assertValidSurfaceSessionResponse(value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async commit(
|
|
43
|
+
request: SurfaceTransferCommand,
|
|
44
|
+
): Promise<SurfaceTransferResponse> {
|
|
45
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
46
|
+
assertValidTransferCommitSelector(request.selector);
|
|
47
|
+
const value = await this.#transport.invoke(
|
|
48
|
+
TRANSFER_COMMIT_SURFACE_COMMAND,
|
|
49
|
+
{ request },
|
|
50
|
+
);
|
|
51
|
+
assertValidSurfaceTransferResponse(value);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @generated by `effigy generate:surface-transfer`; do not edit.
|
|
2
|
+
// Allowed field names per protocol type, from the Rust structs.
|
|
3
|
+
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
|
+
// contract 010's Boundary Validation Target.
|
|
5
|
+
|
|
6
|
+
export const SURFACE_TRANSFER_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"SurfaceSessionStartRequest": ["protocol_version", "request_id", "surface_id"],
|
|
8
|
+
"SurfaceTransferCommand": ["protocol_version", "request_id", "session_id", "selector"],
|
|
9
|
+
"SurfaceProvisioningCompletion": ["window_id", "host_binding_id", "display_id"],
|
|
10
|
+
"SurfaceTransferCompletion": ["protocol_version", "request_id", "session_id", "source_host_binding_id", "target_host_binding_id", "previous_revision", "committed_revision", "authoritative_document", "target"],
|
|
11
|
+
"SurfaceTransferAbort": ["protocol_version", "request_id", "source", "surface_code", "message", "retryable", "session_consumed", "reconciliation_required"],
|
|
12
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @generated by `effigy generate:surface-transfer`; do not edit.
|
|
2
|
+
// Rust serde types are the wire authority.
|
|
3
|
+
|
|
4
|
+
import type { SurfaceDocument, SurfaceId, SurfaceMutationRejectionCode, SurfaceRevision } from "@inflatable-cookie/longhorn/surfaces";
|
|
5
|
+
import type { DragSessionId, TransferCommitSelector, TransferCommittedTarget, TransferErrorCode, TransferHostBindingId, TransferProtocolVersion, TransferRequestId, TransferSessionStarted, WindowId } from "@inflatable-cookie/longhorn/transfer";
|
|
6
|
+
|
|
7
|
+
export const SURFACE_TRANSFER_TARGET_KINDS = ["existing","provisioned"] as const;
|
|
8
|
+
export const SURFACE_TRANSFER_ABORT_DOMAINS = ["transfer","surface_transfer"] as const;
|
|
9
|
+
export const SURFACE_SESSION_RESPONSE_STATUSES = ["started","aborted"] as const;
|
|
10
|
+
export const SURFACE_TRANSFER_RESPONSE_STATUSES = ["committed","aborted"] as const;
|
|
11
|
+
export const SURFACE_TRANSFER_ERROR_CODES = ["invalid_binding_snapshot","unknown_host_binding","stale_host_binding","surface_load_failed","surface_unavailable","unknown_surface","source_changed","unsupported_source","unsupported_target","cross_document","stale_surface_revision","ineligible_target","target_changed","invalid_insertion_position","empty_display_disabled","no_empty_display_target","ambiguous_empty_display_target","provision_failed","provision_receipt_mismatch","surface_mutation_rejected","publication_failed","host_reconciliation_required","transfer_rejected"] as const;
|
|
12
|
+
|
|
13
|
+
export type DisplayId = string;
|
|
14
|
+
|
|
15
|
+
export type SurfaceTransferErrorCode = "invalid_binding_snapshot" | "unknown_host_binding" | "stale_host_binding" | "surface_load_failed" | "surface_unavailable" | "unknown_surface" | "source_changed" | "unsupported_source" | "unsupported_target" | "cross_document" | "stale_surface_revision" | "ineligible_target" | "target_changed" | "invalid_insertion_position" | "empty_display_disabled" | "no_empty_display_target" | "ambiguous_empty_display_target" | "provision_failed" | "provision_receipt_mismatch" | "surface_mutation_rejected" | "publication_failed" | "host_reconciliation_required" | "transfer_rejected";
|
|
16
|
+
|
|
17
|
+
export type SurfaceSessionStartRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, surface_id: SurfaceId, };
|
|
18
|
+
|
|
19
|
+
export type SurfaceTransferCommand = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, selector: TransferCommitSelector, };
|
|
20
|
+
|
|
21
|
+
export type SurfaceProvisioningCompletion = { window_id: WindowId, host_binding_id: TransferHostBindingId, display_id: DisplayId, };
|
|
22
|
+
|
|
23
|
+
export type SurfaceTransferTarget = { "kind": "existing",
|
|
24
|
+
/**
|
|
25
|
+
* Complete shared target evidence.
|
|
26
|
+
*/
|
|
27
|
+
target: TransferCommittedTarget, } | { "kind": "provisioned",
|
|
28
|
+
/**
|
|
29
|
+
* Fresh screen-DIP point outside all managed windows.
|
|
30
|
+
*/
|
|
31
|
+
drop_point: { x: number; y: number },
|
|
32
|
+
/**
|
|
33
|
+
* Completed host lifecycle evidence.
|
|
34
|
+
*/
|
|
35
|
+
provisioning: SurfaceProvisioningCompletion, };
|
|
36
|
+
|
|
37
|
+
export type SurfaceTransferCompletion = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, source_host_binding_id: TransferHostBindingId, target_host_binding_id: TransferHostBindingId, previous_revision: SurfaceRevision, committed_revision: SurfaceRevision, authoritative_document: SurfaceDocument, target: SurfaceTransferTarget, };
|
|
38
|
+
|
|
39
|
+
export type SurfaceTransferAbortSource = { "domain": "transfer", "code": TransferErrorCode } | { "domain": "surface_transfer", "code": SurfaceTransferErrorCode };
|
|
40
|
+
|
|
41
|
+
export type SurfaceTransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: SurfaceTransferAbortSource, surface_code: SurfaceMutationRejectionCode | null, message: string, retryable: boolean, session_consumed: boolean, reconciliation_required: boolean, };
|
|
42
|
+
|
|
43
|
+
export type SurfaceSessionResponse = { "status": "started",
|
|
44
|
+
/**
|
|
45
|
+
* Renderer-visible id-only session evidence.
|
|
46
|
+
*/
|
|
47
|
+
session: TransferSessionStarted, } | { "status": "aborted",
|
|
48
|
+
/**
|
|
49
|
+
* Typed rejection.
|
|
50
|
+
*/
|
|
51
|
+
abort: SurfaceTransferAbort, };
|
|
52
|
+
|
|
53
|
+
export type SurfaceTransferResponse = { "status": "committed",
|
|
54
|
+
/**
|
|
55
|
+
* Current Surface snapshot and target evidence.
|
|
56
|
+
*/
|
|
57
|
+
completion: SurfaceTransferCompletion, } | { "status": "aborted",
|
|
58
|
+
/**
|
|
59
|
+
* Typed rejection and reconciliation evidence.
|
|
60
|
+
*/
|
|
61
|
+
abort: SurfaceTransferAbort, };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @generated by `effigy generate:surface-transfer`; do not edit.
|
|
2
|
+
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
|
+
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
|
+
// each list, because `exact()` compares every key.
|
|
5
|
+
|
|
6
|
+
export const SURFACE_TRANSFER_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"SurfaceTransferTarget": {
|
|
8
|
+
"existing": ["kind", "target"],
|
|
9
|
+
"provisioned": ["kind", "drop_point", "provisioning"],
|
|
10
|
+
},
|
|
11
|
+
"SurfaceTransferAbortSource": {
|
|
12
|
+
"transfer": ["domain", "code"],
|
|
13
|
+
"surface_transfer": ["domain", "code"],
|
|
14
|
+
},
|
|
15
|
+
"SurfaceSessionResponse": {
|
|
16
|
+
"started": ["status", "session"],
|
|
17
|
+
"aborted": ["status", "abort"],
|
|
18
|
+
},
|
|
19
|
+
"SurfaceTransferResponse": {
|
|
20
|
+
"committed": ["status", "completion"],
|
|
21
|
+
"aborted": ["status", "abort"],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const SURFACE_TRANSFER_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
26
|
+
"SurfaceTransferTarget": "kind",
|
|
27
|
+
"SurfaceTransferAbortSource": "domain",
|
|
28
|
+
"SurfaceSessionResponse": "status",
|
|
29
|
+
"SurfaceTransferResponse": "status",
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./generated/protocol.ts";
|
|
2
|
+
// The generated field map is public API. A consumer that mirrors these
|
|
3
|
+
// types structurally -- Poodle does, because it may not depend on Longhorn --
|
|
4
|
+
// has no compile-time link to them, so a field added here is silent on their
|
|
5
|
+
// side. Whoever sees both can assert their shape against this map and fail
|
|
6
|
+
// when it drifts.
|
|
7
|
+
export * from "./generated/fields.ts";
|
|
8
|
+
export * from "./validation.ts";
|
|
9
|
+
export * from "./client.ts";
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SURFACE_TRANSFER_VARIANT_FIELDS,
|
|
3
|
+
SURFACE_TRANSFER_VARIANT_FIELDS_DISCRIMINANTS,
|
|
4
|
+
} from "./generated/variant-fields.ts";
|
|
5
|
+
import {
|
|
6
|
+
SURFACE_SESSION_RESPONSE_STATUSES,
|
|
7
|
+
SURFACE_TRANSFER_ABORT_DOMAINS,
|
|
8
|
+
SURFACE_TRANSFER_ERROR_CODES,
|
|
9
|
+
SURFACE_TRANSFER_RESPONSE_STATUSES,
|
|
10
|
+
SURFACE_TRANSFER_TARGET_KINDS,
|
|
11
|
+
type SurfaceSessionResponse,
|
|
12
|
+
type SurfaceTransferAbort,
|
|
13
|
+
type SurfaceTransferResponse,
|
|
14
|
+
type SurfaceTransferTarget,
|
|
15
|
+
} from "./generated/protocol.ts";
|
|
16
|
+
import { SURFACE_TRANSFER_FIELDS } from "./generated/fields.ts";
|
|
17
|
+
import {
|
|
18
|
+
TRANSFER_ERROR_CODES,
|
|
19
|
+
assertValidTransferTargetBinding,
|
|
20
|
+
assertTransferProtocolVersion,
|
|
21
|
+
} from "@inflatable-cookie/longhorn/transfer";
|
|
22
|
+
import {
|
|
23
|
+
assertValidSurfaceMutationRejectionCode,
|
|
24
|
+
} from "@inflatable-cookie/longhorn/surfaces";
|
|
25
|
+
|
|
26
|
+
export type SurfaceTransferProtocolValidationCode =
|
|
27
|
+
| "unknown_target"
|
|
28
|
+
| "unknown_abort_domain"
|
|
29
|
+
| "unknown_surface_transfer_error_code"
|
|
30
|
+
| "unknown_transfer_error_code"
|
|
31
|
+
| "unknown_response_status"
|
|
32
|
+
| "invalid_object"
|
|
33
|
+
| "unknown_field"
|
|
34
|
+
| "missing_field";
|
|
35
|
+
|
|
36
|
+
export class SurfaceTransferProtocolValidationError extends Error {
|
|
37
|
+
readonly code: SurfaceTransferProtocolValidationCode;
|
|
38
|
+
readonly received: unknown;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
code: SurfaceTransferProtocolValidationCode,
|
|
42
|
+
received: unknown,
|
|
43
|
+
) {
|
|
44
|
+
super(`incompatible Surface transfer protocol: ${code}`);
|
|
45
|
+
this.name = "SurfaceTransferProtocolValidationError";
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.received = received;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function assertValidSurfaceTransferTarget(
|
|
52
|
+
value: unknown,
|
|
53
|
+
): asserts value is SurfaceTransferTarget {
|
|
54
|
+
// The flat field map skips unions, because a union's allowed keys depend on
|
|
55
|
+
// its discriminant and one list is wrong for every variant. That used to
|
|
56
|
+
// mean no key check at all here; the generated per-variant map supplies one.
|
|
57
|
+
const target = record(value);
|
|
58
|
+
assertKnown(
|
|
59
|
+
target.kind,
|
|
60
|
+
SURFACE_TRANSFER_TARGET_KINDS,
|
|
61
|
+
"unknown_target",
|
|
62
|
+
);
|
|
63
|
+
record(target, variantKeys("SurfaceTransferTarget", target));
|
|
64
|
+
if (target.kind === "existing") {
|
|
65
|
+
assertValidTransferTargetBinding(
|
|
66
|
+
record(record(target.target).binding),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function assertValidSurfaceTransferAbort(
|
|
72
|
+
value: unknown,
|
|
73
|
+
): asserts value is SurfaceTransferAbort {
|
|
74
|
+
const abort = record(value, SURFACE_TRANSFER_FIELDS.SurfaceTransferAbort);
|
|
75
|
+
assertTransferProtocolVersion(abort.protocol_version);
|
|
76
|
+
const source = record(abort.source);
|
|
77
|
+
assertKnown(
|
|
78
|
+
source.domain,
|
|
79
|
+
SURFACE_TRANSFER_ABORT_DOMAINS,
|
|
80
|
+
"unknown_abort_domain",
|
|
81
|
+
);
|
|
82
|
+
record(source, variantKeys("SurfaceTransferAbortSource", source));
|
|
83
|
+
if (source.domain === "transfer") {
|
|
84
|
+
assertKnown(
|
|
85
|
+
source.code,
|
|
86
|
+
TRANSFER_ERROR_CODES,
|
|
87
|
+
"unknown_transfer_error_code",
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
assertKnown(
|
|
91
|
+
source.code,
|
|
92
|
+
SURFACE_TRANSFER_ERROR_CODES,
|
|
93
|
+
"unknown_surface_transfer_error_code",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (abort.surface_code !== null) {
|
|
97
|
+
assertValidSurfaceMutationRejectionCode(abort.surface_code);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function assertValidSurfaceSessionResponse(
|
|
102
|
+
value: unknown,
|
|
103
|
+
): asserts value is SurfaceSessionResponse {
|
|
104
|
+
const response = responseWithStatus(
|
|
105
|
+
value,
|
|
106
|
+
SURFACE_SESSION_RESPONSE_STATUSES,
|
|
107
|
+
"SurfaceSessionResponse",
|
|
108
|
+
);
|
|
109
|
+
if (response.status === "started") {
|
|
110
|
+
const session = record(response.session);
|
|
111
|
+
assertTransferProtocolVersion(session.protocol_version);
|
|
112
|
+
assertTransferProtocolVersion(record(session.payload).protocol_version);
|
|
113
|
+
} else {
|
|
114
|
+
assertValidSurfaceTransferAbort(response.abort);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function assertValidSurfaceTransferResponse(
|
|
119
|
+
value: unknown,
|
|
120
|
+
): asserts value is SurfaceTransferResponse {
|
|
121
|
+
const response = responseWithStatus(
|
|
122
|
+
value,
|
|
123
|
+
SURFACE_TRANSFER_RESPONSE_STATUSES,
|
|
124
|
+
"SurfaceTransferResponse",
|
|
125
|
+
);
|
|
126
|
+
if (response.status === "committed") {
|
|
127
|
+
const completion = record(response.completion, SURFACE_TRANSFER_FIELDS.SurfaceTransferCompletion);
|
|
128
|
+
assertTransferProtocolVersion(completion.protocol_version);
|
|
129
|
+
assertValidSurfaceTransferTarget(completion.target);
|
|
130
|
+
} else {
|
|
131
|
+
assertValidSurfaceTransferAbort(response.abort);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function responseWithStatus(
|
|
136
|
+
value: unknown,
|
|
137
|
+
statuses: readonly string[],
|
|
138
|
+
type: string,
|
|
139
|
+
): Record<string, unknown> {
|
|
140
|
+
const response = record(value);
|
|
141
|
+
assertKnown(response.status, statuses, "unknown_response_status");
|
|
142
|
+
record(response, variantKeys(type, response));
|
|
143
|
+
return response;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
148
|
+
* discriminant's name read from the map too. This domain uses three: `kind`,
|
|
149
|
+
* `status`, and `domain` on the abort source.
|
|
150
|
+
*
|
|
151
|
+
* A missing entry means the generator failed to read the union — every caller
|
|
152
|
+
* runs `assertKnown` over the discriminant above this.
|
|
153
|
+
*/
|
|
154
|
+
function variantKeys(
|
|
155
|
+
type: string,
|
|
156
|
+
value: Record<string, unknown>,
|
|
157
|
+
): readonly string[] {
|
|
158
|
+
const discriminant = value[SURFACE_TRANSFER_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
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;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function assertKnown(
|
|
170
|
+
value: unknown,
|
|
171
|
+
known: readonly string[],
|
|
172
|
+
code: SurfaceTransferProtocolValidationCode,
|
|
173
|
+
): asserts value is string {
|
|
174
|
+
if (typeof value !== "string" || !known.includes(value)) {
|
|
175
|
+
throw new SurfaceTransferProtocolValidationError(code, value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Rejects a non-object, an unknown key, and a missing key.
|
|
181
|
+
*
|
|
182
|
+
* `allowed` comes from the generated field map, so the keys accepted are the
|
|
183
|
+
* Rust struct's and nothing else — contract 010's Boundary Validation Target.
|
|
184
|
+
* Passing no list keeps shape-only behaviour for the tagged unions, whose
|
|
185
|
+
* allowed keys depend on their discriminant and so are not one flat set.
|
|
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 });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CheckedSnapshotConnection,
|
|
3
|
+
type ConnectionFailure,
|
|
4
|
+
type ConnectionFailureReporter,
|
|
5
|
+
type EventTransport,
|
|
6
|
+
} from "@inflatable-cookie/longhorn/core";
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
SurfaceChangedEvent,
|
|
10
|
+
SurfaceMutationRequest,
|
|
11
|
+
SurfaceMutationResponse,
|
|
12
|
+
SurfaceSnapshot,
|
|
13
|
+
} from "./generated/protocol.ts";
|
|
14
|
+
import {
|
|
15
|
+
assertValidSurfaceChangedEvent,
|
|
16
|
+
assertValidSurfaceMutationCommand,
|
|
17
|
+
assertValidSurfaceMutationResponse,
|
|
18
|
+
assertValidSurfaceSnapshot,
|
|
19
|
+
} from "./validation.ts";
|
|
20
|
+
|
|
21
|
+
export const SURFACE_SNAPSHOT_COMMAND = "longhorn_surfaces_snapshot";
|
|
22
|
+
export const SURFACE_MUTATE_COMMAND = "longhorn_surfaces_mutate";
|
|
23
|
+
export const SURFACE_CHANGED_EVENT = "longhorn://surfaces/changed";
|
|
24
|
+
|
|
25
|
+
export interface SurfaceSubscription {
|
|
26
|
+
readonly ready: Promise<void>;
|
|
27
|
+
current(): SurfaceSnapshot | undefined;
|
|
28
|
+
failures(): readonly ConnectionFailure[];
|
|
29
|
+
dispose(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class SurfaceClient {
|
|
33
|
+
readonly #transport: EventTransport;
|
|
34
|
+
|
|
35
|
+
constructor(transport: EventTransport) {
|
|
36
|
+
this.#transport = transport;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async snapshot(): Promise<SurfaceSnapshot> {
|
|
40
|
+
const value = await this.#transport.invoke(SURFACE_SNAPSHOT_COMMAND, {});
|
|
41
|
+
return parseSurfaceSnapshot(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async mutate(
|
|
45
|
+
request: SurfaceMutationRequest,
|
|
46
|
+
): Promise<SurfaceMutationResponse> {
|
|
47
|
+
assertValidSurfaceMutationCommand(request.command);
|
|
48
|
+
const value = await this.#transport.invoke(SURFACE_MUTATE_COMMAND, {
|
|
49
|
+
request,
|
|
50
|
+
});
|
|
51
|
+
assertValidSurfaceMutationResponse(value);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
subscribe(
|
|
56
|
+
listener: (snapshot: SurfaceSnapshot) => void,
|
|
57
|
+
onFailure?: ConnectionFailureReporter,
|
|
58
|
+
): SurfaceSubscription {
|
|
59
|
+
return new SurfaceSnapshotSubscription(
|
|
60
|
+
this,
|
|
61
|
+
this.#transport,
|
|
62
|
+
listener,
|
|
63
|
+
onFailure,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
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
|
+
function parseSurfaceSnapshot(value: unknown): SurfaceSnapshot {
|
|
105
|
+
assertValidSurfaceSnapshot(value);
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function surfaceEventAction(
|
|
110
|
+
value: unknown,
|
|
111
|
+
current: SurfaceSnapshot | undefined,
|
|
112
|
+
): { kind: "ignore" } | { kind: "refresh" } {
|
|
113
|
+
assertValidSurfaceChangedEvent(value);
|
|
114
|
+
if (current === undefined) {
|
|
115
|
+
return { kind: "refresh" };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const event = value as SurfaceChangedEvent;
|
|
119
|
+
if (
|
|
120
|
+
event.epoch < current.epoch ||
|
|
121
|
+
(event.epoch === current.epoch &&
|
|
122
|
+
event.revision <= current.revision)
|
|
123
|
+
) {
|
|
124
|
+
return { kind: "ignore" };
|
|
125
|
+
}
|
|
126
|
+
return { kind: "refresh" };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isNewerSurfaceSnapshot(
|
|
130
|
+
candidate: SurfaceSnapshot,
|
|
131
|
+
current: SurfaceSnapshot | undefined,
|
|
132
|
+
): boolean {
|
|
133
|
+
if (current === undefined) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (candidate.epoch !== current.epoch) {
|
|
137
|
+
return candidate.epoch > current.epoch;
|
|
138
|
+
}
|
|
139
|
+
return candidate.revision > current.revision;
|
|
140
|
+
}
|