@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,19 @@
|
|
|
1
|
+
// @generated by `effigy generate:surfaces`; 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_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"RegionState": ["region_id", "panel_instance_ids", "active_panel_instance_id", "collapsed"],
|
|
8
|
+
"SizingSlotState": ["sizing_slot_id", "ratio"],
|
|
9
|
+
"PanelInstance": ["id", "definition_id"],
|
|
10
|
+
"SurfaceHostPreference": ["window_id", "order"],
|
|
11
|
+
"SurfaceRecord": ["id", "schema_id", "label", "presentation", "regions", "sizing_slots", "host_preferences"],
|
|
12
|
+
"ParticipatingWindow": ["id", "active_surface_id"],
|
|
13
|
+
"SurfaceDocument": ["revision", "surfaces", "panel_instances", "windows"],
|
|
14
|
+
"SurfaceMutationRequest": ["request_id", "expected_revision", "command"],
|
|
15
|
+
"SurfaceMutationReceipt": ["request_id", "previous_revision", "committed_revision", "outcome", "authoritative_document"],
|
|
16
|
+
"SurfaceMutationRejection": ["request_id", "current_revision", "code", "detail", "authoritative_document"],
|
|
17
|
+
"SurfaceSnapshot": ["protocol_version", "epoch", "revision", "document"],
|
|
18
|
+
"SurfaceChangedEvent": ["protocol_version", "epoch", "revision"],
|
|
19
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// @generated by `effigy generate:surfaces`; do not edit.
|
|
2
|
+
// Rust serde types are the wire authority.
|
|
3
|
+
|
|
4
|
+
export const SURFACE_PROTOCOL_VERSION = 1 as const;
|
|
5
|
+
export const SURFACE_MUTATION_COMMAND_KINDS = ["create_surface","duplicate_surface","rename_surface","set_surface_presentation","activate_surface","reorder_window","move_surface","close_surface"] as const;
|
|
6
|
+
export const SURFACE_MUTATION_OUTCOME_KINDS = ["surface_created","surface_duplicated","surface_renamed","surface_presentation_set","surface_activated","window_reordered","surface_moved","surface_closed"] as const;
|
|
7
|
+
export const SURFACE_MUTATION_REJECTION_CODES = ["invalid_current_document","stale_revision","revision_overflow","unknown_surface","duplicate_surface","unknown_layout_schema","unknown_window","duplicate_host_preference","undeclared_target_window","move_target_unchanged","invalid_insertion_index","incomplete_reorder","duplicate_reorder_member","foreign_reorder_member","empty_window_not_allowed","invalid_candidate"] as const;
|
|
8
|
+
|
|
9
|
+
export type LayoutSchemaId = string;
|
|
10
|
+
|
|
11
|
+
export type RegionId = string;
|
|
12
|
+
|
|
13
|
+
export type SizingSlotId = string;
|
|
14
|
+
|
|
15
|
+
export type PanelInstanceId = string;
|
|
16
|
+
|
|
17
|
+
export type SurfaceId = string;
|
|
18
|
+
|
|
19
|
+
export type SurfaceRequestId = string;
|
|
20
|
+
|
|
21
|
+
export type WindowId = string;
|
|
22
|
+
|
|
23
|
+
export type SurfaceRevision = number;
|
|
24
|
+
|
|
25
|
+
export type SurfaceProtocolEpoch = number;
|
|
26
|
+
|
|
27
|
+
export type PanelDefinitionId = string;
|
|
28
|
+
|
|
29
|
+
export type LayoutRatio = number;
|
|
30
|
+
|
|
31
|
+
export type RegionState = { region_id: RegionId, panel_instance_ids: Array<PanelInstanceId>, active_panel_instance_id: PanelInstanceId | null, collapsed: boolean | null, };
|
|
32
|
+
|
|
33
|
+
export type SizingSlotState = { sizing_slot_id: SizingSlotId, ratio: LayoutRatio, };
|
|
34
|
+
|
|
35
|
+
export type PanelInstance = { id: PanelInstanceId, definition_id: PanelDefinitionId, };
|
|
36
|
+
|
|
37
|
+
export type SurfaceHostPreference = { window_id: WindowId, order: number, };
|
|
38
|
+
|
|
39
|
+
export type SurfacePresentation = { "kind": "regional" } | { "kind": "focused_panel",
|
|
40
|
+
/**
|
|
41
|
+
* The panel rendered for the whole Surface.
|
|
42
|
+
*/
|
|
43
|
+
panel_definition_id: PanelDefinitionId, };
|
|
44
|
+
|
|
45
|
+
export type SurfaceRecord = { id: SurfaceId, schema_id: LayoutSchemaId, label: string | null, presentation: SurfacePresentation, regions: Array<RegionState>, sizing_slots: Array<SizingSlotState>, host_preferences: Array<SurfaceHostPreference>, };
|
|
46
|
+
|
|
47
|
+
export type ParticipatingWindow = { id: WindowId, active_surface_id: SurfaceId | null, };
|
|
48
|
+
|
|
49
|
+
export type SurfaceDocument = { revision: SurfaceRevision, surfaces: Array<SurfaceRecord>, panel_instances: Array<PanelInstance>, windows: Array<ParticipatingWindow>, };
|
|
50
|
+
|
|
51
|
+
export type EmptyWindowPolicy = "allow" | "reject";
|
|
52
|
+
|
|
53
|
+
export type SurfaceMutationCommand = { "kind": "create_surface",
|
|
54
|
+
/**
|
|
55
|
+
* New durable Surface identity.
|
|
56
|
+
*/
|
|
57
|
+
surface_id: SurfaceId,
|
|
58
|
+
/**
|
|
59
|
+
* Registered layout schema the new Surface instantiates.
|
|
60
|
+
*/
|
|
61
|
+
schema_id: LayoutSchemaId,
|
|
62
|
+
/**
|
|
63
|
+
* Optional generic display label.
|
|
64
|
+
*/
|
|
65
|
+
label: string | null,
|
|
66
|
+
/**
|
|
67
|
+
* Complete candidate-host policy with explicit window orders.
|
|
68
|
+
*/
|
|
69
|
+
host_preferences: Array<SurfaceHostPreference>, } | { "kind": "duplicate_surface",
|
|
70
|
+
/**
|
|
71
|
+
* Existing generic metadata source.
|
|
72
|
+
*/
|
|
73
|
+
source_surface_id: SurfaceId,
|
|
74
|
+
/**
|
|
75
|
+
* New durable Surface identity.
|
|
76
|
+
*/
|
|
77
|
+
surface_id: SurfaceId, } | { "kind": "rename_surface",
|
|
78
|
+
/**
|
|
79
|
+
* Existing Surface identity.
|
|
80
|
+
*/
|
|
81
|
+
surface_id: SurfaceId,
|
|
82
|
+
/**
|
|
83
|
+
* New optional generic label.
|
|
84
|
+
*/
|
|
85
|
+
label: string | null, } | { "kind": "set_surface_presentation",
|
|
86
|
+
/**
|
|
87
|
+
* Existing Surface identity.
|
|
88
|
+
*/
|
|
89
|
+
surface_id: SurfaceId,
|
|
90
|
+
/**
|
|
91
|
+
* Regional layout, or one panel rendered full-surface.
|
|
92
|
+
*/
|
|
93
|
+
presentation: SurfacePresentation, } | { "kind": "activate_surface",
|
|
94
|
+
/**
|
|
95
|
+
* Participating window.
|
|
96
|
+
*/
|
|
97
|
+
window_id: WindowId,
|
|
98
|
+
/**
|
|
99
|
+
* Declared Surface member.
|
|
100
|
+
*/
|
|
101
|
+
surface_id: SurfaceId, } | { "kind": "reorder_window",
|
|
102
|
+
/**
|
|
103
|
+
* Participating window.
|
|
104
|
+
*/
|
|
105
|
+
window_id: WindowId,
|
|
106
|
+
/**
|
|
107
|
+
* Complete ordered permutation of declared members.
|
|
108
|
+
*/
|
|
109
|
+
surface_ids: Array<SurfaceId>, } | { "kind": "move_surface",
|
|
110
|
+
/**
|
|
111
|
+
* Existing Surface identity.
|
|
112
|
+
*/
|
|
113
|
+
surface_id: SurfaceId,
|
|
114
|
+
/**
|
|
115
|
+
* Declared target candidate window.
|
|
116
|
+
*/
|
|
117
|
+
target_window_id: WindowId,
|
|
118
|
+
/**
|
|
119
|
+
* Zero-based target-window insertion index.
|
|
120
|
+
*/
|
|
121
|
+
insertion_index: number, } | { "kind": "close_surface",
|
|
122
|
+
/**
|
|
123
|
+
* Existing Surface identity.
|
|
124
|
+
*/
|
|
125
|
+
surface_id: SurfaceId, };
|
|
126
|
+
|
|
127
|
+
export type SurfaceMutationRequest = { request_id: SurfaceRequestId, expected_revision: SurfaceRevision, command: SurfaceMutationCommand, };
|
|
128
|
+
|
|
129
|
+
export type SurfaceMutationOutcome = { "kind": "surface_created",
|
|
130
|
+
/**
|
|
131
|
+
* Created Surface identity.
|
|
132
|
+
*/
|
|
133
|
+
surface_id: SurfaceId, } | { "kind": "surface_duplicated",
|
|
134
|
+
/**
|
|
135
|
+
* Generic metadata source.
|
|
136
|
+
*/
|
|
137
|
+
source_surface_id: SurfaceId,
|
|
138
|
+
/**
|
|
139
|
+
* Created Surface identity.
|
|
140
|
+
*/
|
|
141
|
+
surface_id: SurfaceId, } | { "kind": "surface_renamed",
|
|
142
|
+
/**
|
|
143
|
+
* Renamed Surface identity.
|
|
144
|
+
*/
|
|
145
|
+
surface_id: SurfaceId, } | { "kind": "surface_presentation_set",
|
|
146
|
+
/**
|
|
147
|
+
* Affected Surface identity.
|
|
148
|
+
*/
|
|
149
|
+
surface_id: SurfaceId,
|
|
150
|
+
/**
|
|
151
|
+
* Committed presentation.
|
|
152
|
+
*/
|
|
153
|
+
presentation: SurfacePresentation,
|
|
154
|
+
/**
|
|
155
|
+
* Presentation replaced by this command.
|
|
156
|
+
*/
|
|
157
|
+
previous_presentation: SurfacePresentation, } | { "kind": "surface_activated",
|
|
158
|
+
/**
|
|
159
|
+
* Participating window.
|
|
160
|
+
*/
|
|
161
|
+
window_id: WindowId,
|
|
162
|
+
/**
|
|
163
|
+
* Newly active Surface.
|
|
164
|
+
*/
|
|
165
|
+
surface_id: SurfaceId,
|
|
166
|
+
/**
|
|
167
|
+
* Previous active member, when selected.
|
|
168
|
+
*/
|
|
169
|
+
previous_active_surface_id: SurfaceId | null, } | { "kind": "window_reordered",
|
|
170
|
+
/**
|
|
171
|
+
* Reordered participating window.
|
|
172
|
+
*/
|
|
173
|
+
window_id: WindowId,
|
|
174
|
+
/**
|
|
175
|
+
* Complete committed membership order.
|
|
176
|
+
*/
|
|
177
|
+
surface_ids: Array<SurfaceId>, } | { "kind": "surface_moved",
|
|
178
|
+
/**
|
|
179
|
+
* Moved Surface identity.
|
|
180
|
+
*/
|
|
181
|
+
surface_id: SurfaceId,
|
|
182
|
+
/**
|
|
183
|
+
* Former primary host.
|
|
184
|
+
*/
|
|
185
|
+
source_window_id: WindowId,
|
|
186
|
+
/**
|
|
187
|
+
* New primary host.
|
|
188
|
+
*/
|
|
189
|
+
target_window_id: WindowId,
|
|
190
|
+
/**
|
|
191
|
+
* Committed target membership index.
|
|
192
|
+
*/
|
|
193
|
+
insertion_index: number, } | { "kind": "surface_closed",
|
|
194
|
+
/**
|
|
195
|
+
* Closed Surface identity.
|
|
196
|
+
*/
|
|
197
|
+
surface_id: SurfaceId, };
|
|
198
|
+
|
|
199
|
+
export type SurfaceMutationReceipt = { request_id: SurfaceRequestId, previous_revision: SurfaceRevision, committed_revision: SurfaceRevision, outcome: SurfaceMutationOutcome, authoritative_document: SurfaceDocument, };
|
|
200
|
+
|
|
201
|
+
export type SurfaceMutationRejectionCode = "invalid_current_document" | "stale_revision" | "revision_overflow" | "unknown_surface" | "duplicate_surface" | "unknown_layout_schema" | "unknown_window" | "duplicate_host_preference" | "undeclared_target_window" | "move_target_unchanged" | "invalid_insertion_index" | "incomplete_reorder" | "duplicate_reorder_member" | "foreign_reorder_member" | "empty_window_not_allowed" | "invalid_candidate";
|
|
202
|
+
|
|
203
|
+
export type SurfaceMutationRejection = { request_id: SurfaceRequestId, current_revision: SurfaceRevision, code: SurfaceMutationRejectionCode, detail: string, authoritative_document: SurfaceDocument, };
|
|
204
|
+
|
|
205
|
+
export type SurfaceMutationResponse = { "status": "committed",
|
|
206
|
+
/**
|
|
207
|
+
* Complete authoritative mutation receipt.
|
|
208
|
+
*/
|
|
209
|
+
receipt: SurfaceMutationReceipt, } | { "status": "rejected",
|
|
210
|
+
/**
|
|
211
|
+
* Typed unchanged-state rejection.
|
|
212
|
+
*/
|
|
213
|
+
rejection: SurfaceMutationRejection, };
|
|
214
|
+
|
|
215
|
+
export type SurfaceSnapshot = { protocol_version: number, epoch: SurfaceProtocolEpoch, revision: SurfaceRevision, document: SurfaceDocument, };
|
|
216
|
+
|
|
217
|
+
export type SurfaceChangedEvent = { protocol_version: number, epoch: SurfaceProtocolEpoch, revision: SurfaceRevision, };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @generated by `effigy generate:surfaces`; 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_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"SurfacePresentation": {
|
|
8
|
+
"regional": ["kind"],
|
|
9
|
+
"focused_panel": ["kind", "panel_definition_id"],
|
|
10
|
+
},
|
|
11
|
+
"SurfaceMutationCommand": {
|
|
12
|
+
"create_surface": ["kind", "surface_id", "schema_id", "label", "host_preferences"],
|
|
13
|
+
"duplicate_surface": ["kind", "source_surface_id", "surface_id"],
|
|
14
|
+
"rename_surface": ["kind", "surface_id", "label"],
|
|
15
|
+
"set_surface_presentation": ["kind", "surface_id", "presentation"],
|
|
16
|
+
"activate_surface": ["kind", "window_id", "surface_id"],
|
|
17
|
+
"reorder_window": ["kind", "window_id", "surface_ids"],
|
|
18
|
+
"move_surface": ["kind", "surface_id", "target_window_id", "insertion_index"],
|
|
19
|
+
"close_surface": ["kind", "surface_id"],
|
|
20
|
+
},
|
|
21
|
+
"SurfaceMutationOutcome": {
|
|
22
|
+
"surface_created": ["kind", "surface_id"],
|
|
23
|
+
"surface_duplicated": ["kind", "source_surface_id", "surface_id"],
|
|
24
|
+
"surface_renamed": ["kind", "surface_id"],
|
|
25
|
+
"surface_presentation_set": ["kind", "surface_id", "presentation", "previous_presentation"],
|
|
26
|
+
"surface_activated": ["kind", "window_id", "surface_id", "previous_active_surface_id"],
|
|
27
|
+
"window_reordered": ["kind", "window_id", "surface_ids"],
|
|
28
|
+
"surface_moved": ["kind", "surface_id", "source_window_id", "target_window_id", "insertion_index"],
|
|
29
|
+
"surface_closed": ["kind", "surface_id"],
|
|
30
|
+
},
|
|
31
|
+
"SurfaceMutationResponse": {
|
|
32
|
+
"committed": ["status", "receipt"],
|
|
33
|
+
"rejected": ["status", "rejection"],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const SURFACE_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
38
|
+
"SurfacePresentation": "kind",
|
|
39
|
+
"SurfaceMutationCommand": "kind",
|
|
40
|
+
"SurfaceMutationOutcome": "kind",
|
|
41
|
+
"SurfaceMutationResponse": "status",
|
|
42
|
+
};
|
|
@@ -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,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SURFACE_VARIANT_FIELDS,
|
|
3
|
+
SURFACE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
4
|
+
} from "./generated/variant-fields.ts";
|
|
5
|
+
import {
|
|
6
|
+
SURFACE_MUTATION_COMMAND_KINDS,
|
|
7
|
+
SURFACE_MUTATION_OUTCOME_KINDS,
|
|
8
|
+
SURFACE_MUTATION_REJECTION_CODES,
|
|
9
|
+
SURFACE_PROTOCOL_VERSION,
|
|
10
|
+
type SurfaceChangedEvent,
|
|
11
|
+
type SurfaceMutationCommand,
|
|
12
|
+
type SurfaceMutationOutcome,
|
|
13
|
+
type SurfaceMutationRejectionCode,
|
|
14
|
+
type SurfaceMutationResponse,
|
|
15
|
+
type SurfaceSnapshot,
|
|
16
|
+
} from "./generated/protocol.ts";
|
|
17
|
+
import { SURFACE_FIELDS } from "./generated/fields.ts";
|
|
18
|
+
|
|
19
|
+
export type SurfaceProtocolValidationCode =
|
|
20
|
+
| "unsupported_protocol_version"
|
|
21
|
+
| "unknown_command"
|
|
22
|
+
| "unknown_outcome"
|
|
23
|
+
| "unknown_rejection_code"
|
|
24
|
+
| "unknown_response_status"
|
|
25
|
+
| "invalid_object"
|
|
26
|
+
| "unknown_field"
|
|
27
|
+
| "missing_field";
|
|
28
|
+
|
|
29
|
+
export class SurfaceProtocolValidationError extends Error {
|
|
30
|
+
readonly code: SurfaceProtocolValidationCode;
|
|
31
|
+
readonly received: unknown;
|
|
32
|
+
|
|
33
|
+
constructor(code: SurfaceProtocolValidationCode, received: unknown) {
|
|
34
|
+
super(`incompatible Surface protocol: ${code}`);
|
|
35
|
+
this.name = "SurfaceProtocolValidationError";
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.received = received;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function assertSurfaceProtocolVersion(
|
|
42
|
+
version: unknown,
|
|
43
|
+
): asserts version is typeof SURFACE_PROTOCOL_VERSION {
|
|
44
|
+
if (version !== SURFACE_PROTOCOL_VERSION) {
|
|
45
|
+
throw new SurfaceProtocolValidationError(
|
|
46
|
+
"unsupported_protocol_version",
|
|
47
|
+
version,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function assertValidSurfaceMutationCommand(
|
|
53
|
+
value: unknown,
|
|
54
|
+
): asserts value is SurfaceMutationCommand {
|
|
55
|
+
assertKnownKind(value, SURFACE_MUTATION_COMMAND_KINDS, "unknown_command", "SurfaceMutationCommand");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function assertValidSurfaceMutationOutcome(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): asserts value is SurfaceMutationOutcome {
|
|
61
|
+
assertKnownKind(value, SURFACE_MUTATION_OUTCOME_KINDS, "unknown_outcome", "SurfaceMutationOutcome");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function assertValidSurfaceMutationRejectionCode(
|
|
65
|
+
value: unknown,
|
|
66
|
+
): asserts value is SurfaceMutationRejectionCode {
|
|
67
|
+
if (
|
|
68
|
+
typeof value !== "string" ||
|
|
69
|
+
!SURFACE_MUTATION_REJECTION_CODES.includes(
|
|
70
|
+
value as (typeof SURFACE_MUTATION_REJECTION_CODES)[number],
|
|
71
|
+
)
|
|
72
|
+
) {
|
|
73
|
+
throw new SurfaceProtocolValidationError(
|
|
74
|
+
"unknown_rejection_code",
|
|
75
|
+
value,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function assertValidSurfaceMutationResponse(
|
|
81
|
+
value: unknown,
|
|
82
|
+
): asserts value is SurfaceMutationResponse {
|
|
83
|
+
// Was `record(value, SURFACE_FIELDS.SurfaceMutationResponse)`. The flat
|
|
84
|
+
// field map skips unions by design, so that lookup was `undefined` and
|
|
85
|
+
// `record` checked no keys at all -- a call that read as strict and was not.
|
|
86
|
+
const response = record(value);
|
|
87
|
+
switch (response.status) {
|
|
88
|
+
case "committed": {
|
|
89
|
+
record(response, variantKeys("SurfaceMutationResponse", response));
|
|
90
|
+
const receipt = record(response.receipt, SURFACE_FIELDS.SurfaceMutationReceipt);
|
|
91
|
+
assertValidSurfaceMutationOutcome(record(receipt.outcome));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
case "rejected": {
|
|
95
|
+
record(response, variantKeys("SurfaceMutationResponse", response));
|
|
96
|
+
const rejection = record(response.rejection, SURFACE_FIELDS.SurfaceMutationRejection);
|
|
97
|
+
assertValidSurfaceMutationRejectionCode(rejection.code);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
throw new SurfaceProtocolValidationError(
|
|
102
|
+
"unknown_response_status",
|
|
103
|
+
response.status,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function assertValidSurfaceSnapshot(
|
|
109
|
+
value: unknown,
|
|
110
|
+
): asserts value is SurfaceSnapshot {
|
|
111
|
+
assertSurfaceProtocolVersion(
|
|
112
|
+
record(value, SURFACE_FIELDS.SurfaceSnapshot).protocol_version,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function assertValidSurfaceChangedEvent(
|
|
117
|
+
value: unknown,
|
|
118
|
+
): asserts value is SurfaceChangedEvent {
|
|
119
|
+
assertSurfaceProtocolVersion(
|
|
120
|
+
record(value, SURFACE_FIELDS.SurfaceChangedEvent).protocol_version,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function assertKnownKind(
|
|
125
|
+
value: unknown,
|
|
126
|
+
known: readonly string[],
|
|
127
|
+
code: "unknown_command" | "unknown_outcome",
|
|
128
|
+
type: string,
|
|
129
|
+
): asserts value is Record<"kind", string> {
|
|
130
|
+
const candidate = record(value);
|
|
131
|
+
if (
|
|
132
|
+
typeof candidate.kind !== "string" ||
|
|
133
|
+
!known.includes(candidate.kind)
|
|
134
|
+
) {
|
|
135
|
+
throw new SurfaceProtocolValidationError(code, value);
|
|
136
|
+
}
|
|
137
|
+
// The discriminant is checked above, so a missing map entry here means the
|
|
138
|
+
// generator failed rather than that a caller sent something odd.
|
|
139
|
+
record(candidate, variantKeys(type, candidate));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
144
|
+
* discriminant's name read from the map too.
|
|
145
|
+
*/
|
|
146
|
+
function variantKeys(
|
|
147
|
+
type: string,
|
|
148
|
+
value: Record<string, unknown>,
|
|
149
|
+
): readonly string[] {
|
|
150
|
+
const discriminant = value[SURFACE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
151
|
+
const keys = SURFACE_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
152
|
+
if (keys === undefined) {
|
|
153
|
+
throw new SurfaceProtocolValidationError("unknown_outcome", { type, discriminant });
|
|
154
|
+
}
|
|
155
|
+
return keys;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Rejects a non-object, an unknown key, and a missing key.
|
|
160
|
+
*
|
|
161
|
+
* `allowed` comes from the generated field map, so the keys this accepts are
|
|
162
|
+
* the Rust struct's and nothing else — contract 010's Boundary Validation
|
|
163
|
+
* Target. Passing no list keeps the old shape-only behaviour for the tagged
|
|
164
|
+
* unions, whose allowed keys depend on their discriminant and so are not one
|
|
165
|
+
* flat set.
|
|
166
|
+
*
|
|
167
|
+
* The non-object case used to throw `unknown_response_status`, because the
|
|
168
|
+
* incompatibility union had no code for it. It reported the wrong thing for
|
|
169
|
+
* every caller but one.
|
|
170
|
+
*/
|
|
171
|
+
function record(
|
|
172
|
+
value: unknown,
|
|
173
|
+
allowed?: readonly string[],
|
|
174
|
+
): Record<string, unknown> {
|
|
175
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
176
|
+
throw new SurfaceProtocolValidationError("invalid_object", value);
|
|
177
|
+
}
|
|
178
|
+
const result = value as Record<string, unknown>;
|
|
179
|
+
if (allowed === undefined) return result;
|
|
180
|
+
|
|
181
|
+
const permitted = new Set(allowed);
|
|
182
|
+
for (const key of Object.keys(result)) {
|
|
183
|
+
if (!permitted.has(key)) {
|
|
184
|
+
throw new SurfaceProtocolValidationError("unknown_field", {
|
|
185
|
+
key,
|
|
186
|
+
value,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const key of allowed) {
|
|
191
|
+
if (!(key in result)) {
|
|
192
|
+
throw new SurfaceProtocolValidationError("missing_field", {
|
|
193
|
+
key,
|
|
194
|
+
value,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEventTransport,
|
|
3
|
+
type ConnectionFailureReporter,
|
|
4
|
+
type InvokeTransport,
|
|
5
|
+
} from "@inflatable-cookie/longhorn/core";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type PanelSessionStartRequest,
|
|
9
|
+
type PanelTransferCommand,
|
|
10
|
+
type PanelTransferResponse,
|
|
11
|
+
type TransferCancelRequest,
|
|
12
|
+
type TransferCancelResponse,
|
|
13
|
+
type TransferClientSnapshot,
|
|
14
|
+
type TransferLeaseRequest,
|
|
15
|
+
type TransferLeaseResponse,
|
|
16
|
+
type TransferSessionResponse,
|
|
17
|
+
} from "./generated/protocol.ts";
|
|
18
|
+
import {
|
|
19
|
+
assertValidPanelTransferResponse,
|
|
20
|
+
assertValidTransferClientSnapshot,
|
|
21
|
+
assertValidTransferCancelResponse,
|
|
22
|
+
assertValidTransferCommitSelector,
|
|
23
|
+
assertValidTransferLeaseResponse,
|
|
24
|
+
assertValidTransferSessionResponse,
|
|
25
|
+
assertValidTransferTargetBinding,
|
|
26
|
+
assertTransferProtocolVersion,
|
|
27
|
+
} from "./validation.ts";
|
|
28
|
+
import {
|
|
29
|
+
TransferClientConnection,
|
|
30
|
+
type TransferClientSnapshotListener,
|
|
31
|
+
} from "./connection.ts";
|
|
32
|
+
|
|
33
|
+
export const TRANSFER_SNAPSHOT_COMMAND = "longhorn_transfer_snapshot";
|
|
34
|
+
export const TRANSFER_START_PANEL_COMMAND =
|
|
35
|
+
"longhorn_transfer_start_panel";
|
|
36
|
+
export const TRANSFER_PUBLISH_LEASE_COMMAND =
|
|
37
|
+
"longhorn_transfer_publish_lease";
|
|
38
|
+
export const TRANSFER_COMMIT_PANEL_COMMAND =
|
|
39
|
+
"longhorn_transfer_commit_panel";
|
|
40
|
+
export const TRANSFER_CANCEL_COMMAND = "longhorn_transfer_cancel";
|
|
41
|
+
|
|
42
|
+
export class TransferClient {
|
|
43
|
+
readonly #transport: InvokeTransport;
|
|
44
|
+
|
|
45
|
+
constructor(transport: InvokeTransport) {
|
|
46
|
+
this.#transport = transport;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async snapshot(): Promise<TransferClientSnapshot> {
|
|
50
|
+
const value = await this.#transport.invoke(TRANSFER_SNAPSHOT_COMMAND, {});
|
|
51
|
+
assertValidTransferClientSnapshot(value);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
connect(
|
|
56
|
+
listener?: TransferClientSnapshotListener,
|
|
57
|
+
onFailure?: ConnectionFailureReporter,
|
|
58
|
+
): TransferClientConnection {
|
|
59
|
+
if (!isEventTransport(this.#transport)) {
|
|
60
|
+
throw new TypeError(
|
|
61
|
+
"transfer connection requires an event-capable transport",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return new TransferClientConnection(
|
|
65
|
+
this.#transport,
|
|
66
|
+
() => this.snapshot(),
|
|
67
|
+
listener,
|
|
68
|
+
onFailure,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async startPanel(
|
|
73
|
+
request: PanelSessionStartRequest,
|
|
74
|
+
): Promise<TransferSessionResponse> {
|
|
75
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
76
|
+
return this.#invoke(
|
|
77
|
+
TRANSFER_START_PANEL_COMMAND,
|
|
78
|
+
request,
|
|
79
|
+
assertValidTransferSessionResponse,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async publishLease(
|
|
84
|
+
request: TransferLeaseRequest,
|
|
85
|
+
): Promise<TransferLeaseResponse> {
|
|
86
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
87
|
+
for (const zone of request.zones) {
|
|
88
|
+
assertValidTransferTargetBinding(zone.target);
|
|
89
|
+
}
|
|
90
|
+
return this.#invoke(
|
|
91
|
+
TRANSFER_PUBLISH_LEASE_COMMAND,
|
|
92
|
+
request,
|
|
93
|
+
assertValidTransferLeaseResponse,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async commitPanel(
|
|
98
|
+
request: PanelTransferCommand,
|
|
99
|
+
): Promise<PanelTransferResponse> {
|
|
100
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
101
|
+
assertValidTransferCommitSelector(request.selector);
|
|
102
|
+
return this.#invoke(
|
|
103
|
+
TRANSFER_COMMIT_PANEL_COMMAND,
|
|
104
|
+
request,
|
|
105
|
+
assertValidPanelTransferResponse,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async cancel(
|
|
110
|
+
request: TransferCancelRequest,
|
|
111
|
+
): Promise<TransferCancelResponse> {
|
|
112
|
+
assertTransferProtocolVersion(request.protocol_version);
|
|
113
|
+
return this.#invoke(
|
|
114
|
+
TRANSFER_CANCEL_COMMAND,
|
|
115
|
+
request,
|
|
116
|
+
assertValidTransferCancelResponse,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async #invoke<T>(
|
|
121
|
+
command: string,
|
|
122
|
+
request:
|
|
123
|
+
| PanelSessionStartRequest
|
|
124
|
+
| TransferLeaseRequest
|
|
125
|
+
| PanelTransferCommand
|
|
126
|
+
| TransferCancelRequest,
|
|
127
|
+
guard: (value: unknown) => asserts value is T,
|
|
128
|
+
): Promise<T> {
|
|
129
|
+
const value = await this.#transport.invoke(command, { request });
|
|
130
|
+
guard(value);
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
}
|