@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.
Files changed (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/package.json +205 -0
  4. package/src/agent-control/index.ts +20 -0
  5. package/src/agent-control/inject.ts +4 -0
  6. package/src/agent-control/shim.ts +722 -0
  7. package/src/bridge/direct.ts +22 -0
  8. package/src/bridge/generated/fields.ts +32 -0
  9. package/src/bridge/generated/protocol.ts +218 -0
  10. package/src/bridge/generated/variant-fields.ts +10 -0
  11. package/src/bridge/index.ts +15 -0
  12. package/src/bridge/job.ts +51 -0
  13. package/src/bridge/loopback.ts +84 -0
  14. package/src/bridge/operation.ts +166 -0
  15. package/src/bridge/router.ts +71 -0
  16. package/src/bridge/runtime/connection.ts +318 -0
  17. package/src/bridge/runtime/policy.ts +89 -0
  18. package/src/bridge/runtime/retry.ts +60 -0
  19. package/src/bridge/runtime.ts +3 -0
  20. package/src/bridge/session.ts +67 -0
  21. package/src/bridge/stream/connection.ts +146 -0
  22. package/src/bridge/stream/source.ts +61 -0
  23. package/src/bridge/stream/tracker.ts +109 -0
  24. package/src/bridge/stream.ts +6 -0
  25. package/src/bridge/supervision.ts +204 -0
  26. package/src/bridge/validation/base.ts +164 -0
  27. package/src/bridge/validation/jobs.ts +105 -0
  28. package/src/bridge/validation/negotiation.ts +242 -0
  29. package/src/bridge/validation/operations.ts +213 -0
  30. package/src/bridge/validation/streams.ts +47 -0
  31. package/src/bridge/validation.ts +5 -0
  32. package/src/commands/client.ts +124 -0
  33. package/src/commands/controller.ts +411 -0
  34. package/src/commands/generated/fields.ts +43 -0
  35. package/src/commands/generated/protocol.ts +876 -0
  36. package/src/commands/generated/variant-fields.ts +88 -0
  37. package/src/commands/index.ts +13 -0
  38. package/src/commands/keyboard.ts +361 -0
  39. package/src/commands/ports.ts +82 -0
  40. package/src/commands/projectors.ts +306 -0
  41. package/src/commands/validation.ts +444 -0
  42. package/src/config/client.ts +215 -0
  43. package/src/config/generated/base.ts +714 -0
  44. package/src/config/generated/fields.ts +54 -0
  45. package/src/config/generated/label-template.ts +14 -0
  46. package/src/config/generated/labels.ts +30 -0
  47. package/src/config/generated/protocol.ts +3 -0
  48. package/src/config/generated/restore.ts +658 -0
  49. package/src/config/generated/variant-fields.ts +129 -0
  50. package/src/config/index.ts +12 -0
  51. package/src/config/names.ts +19 -0
  52. package/src/config/validation/commands.ts +155 -0
  53. package/src/config/validation/outcomes.ts +243 -0
  54. package/src/config/validation/primitives.ts +174 -0
  55. package/src/config/validation/projection.ts +351 -0
  56. package/src/config/validation.ts +7 -0
  57. package/src/core/connection.ts +252 -0
  58. package/src/core/index.ts +2 -0
  59. package/src/core/transport.ts +24 -0
  60. package/src/history/client.ts +65 -0
  61. package/src/history/controller.ts +385 -0
  62. package/src/history/direct.ts +21 -0
  63. package/src/history/generated/fields.ts +18 -0
  64. package/src/history/generated/protocol.ts +389 -0
  65. package/src/history/generated/variant-fields.ts +27 -0
  66. package/src/history/index.ts +13 -0
  67. package/src/history/ports.ts +31 -0
  68. package/src/history/serialized.ts +38 -0
  69. package/src/history/validation.ts +334 -0
  70. package/src/history-tree/client.ts +16 -0
  71. package/src/history-tree/controller.ts +199 -0
  72. package/src/history-tree/direct.ts +3 -0
  73. package/src/history-tree/generated/fields.ts +26 -0
  74. package/src/history-tree/generated/protocol.ts +711 -0
  75. package/src/history-tree/generated/variant-fields.ts +39 -0
  76. package/src/history-tree/index.ts +13 -0
  77. package/src/history-tree/ports.ts +43 -0
  78. package/src/history-tree/serialized.ts +15 -0
  79. package/src/history-tree/validation.ts +269 -0
  80. package/src/layout/generated/protocol.ts +289 -0
  81. package/src/layout/index.ts +4 -0
  82. package/src/layout/ratio.ts +22 -0
  83. package/src/layout/validation.ts +110 -0
  84. package/src/layout/visibility.ts +30 -0
  85. package/src/licence/client.ts +32 -0
  86. package/src/licence/controller.ts +301 -0
  87. package/src/licence/direct.ts +3 -0
  88. package/src/licence/generated/fields.ts +17 -0
  89. package/src/licence/generated/key-conformance.json +42 -0
  90. package/src/licence/generated/protocol.ts +249 -0
  91. package/src/licence/generated/variant-fields.ts +34 -0
  92. package/src/licence/index.ts +14 -0
  93. package/src/licence/key.ts +125 -0
  94. package/src/licence/ports.ts +39 -0
  95. package/src/licence/serialized.ts +13 -0
  96. package/src/licence/validation.ts +226 -0
  97. package/src/native-content/client.ts +474 -0
  98. package/src/native-content/direct.ts +16 -0
  99. package/src/native-content/generated/fields.ts +32 -0
  100. package/src/native-content/generated/protocol.ts +498 -0
  101. package/src/native-content/generated/variant-fields.ts +77 -0
  102. package/src/native-content/index.ts +12 -0
  103. package/src/native-content/ports.ts +46 -0
  104. package/src/native-content/serialized.ts +50 -0
  105. package/src/native-content/validation/base.ts +194 -0
  106. package/src/native-content/validation/messages.ts +192 -0
  107. package/src/native-content/validation/state.ts +404 -0
  108. package/src/native-content/validation.ts +7 -0
  109. package/src/notifications/client.ts +106 -0
  110. package/src/notifications/controller.ts +240 -0
  111. package/src/notifications/direct.ts +12 -0
  112. package/src/notifications/generated/fields.ts +19 -0
  113. package/src/notifications/generated/labels.ts +20 -0
  114. package/src/notifications/generated/protocol.ts +522 -0
  115. package/src/notifications/generated/variant-fields.ts +37 -0
  116. package/src/notifications/index.ts +16 -0
  117. package/src/notifications/ports.ts +22 -0
  118. package/src/notifications/serialized.ts +27 -0
  119. package/src/notifications/toast.ts +41 -0
  120. package/src/notifications/tone.ts +27 -0
  121. package/src/notifications/validation.ts +246 -0
  122. package/src/operation/bridge.ts +168 -0
  123. package/src/operation/client.ts +167 -0
  124. package/src/operation/controller.ts +321 -0
  125. package/src/operation/direct.ts +15 -0
  126. package/src/operation/generated/fields.ts +20 -0
  127. package/src/operation/generated/labels.ts +15 -0
  128. package/src/operation/generated/protocol.ts +762 -0
  129. package/src/operation/generated/variant-fields.ts +60 -0
  130. package/src/operation/index.ts +14 -0
  131. package/src/operation/ports.ts +29 -0
  132. package/src/operation/serialized.ts +39 -0
  133. package/src/operation/validation.ts +479 -0
  134. package/src/settings/client.ts +142 -0
  135. package/src/settings/connection.ts +246 -0
  136. package/src/settings/generated/fields.ts +34 -0
  137. package/src/settings/generated/protocol.ts +668 -0
  138. package/src/settings/generated/variant-fields.ts +26 -0
  139. package/src/settings/index.ts +12 -0
  140. package/src/settings/names.ts +8 -0
  141. package/src/settings/registry.ts +141 -0
  142. package/src/settings/validation/authority.ts +66 -0
  143. package/src/settings/validation/command.ts +165 -0
  144. package/src/settings/validation/error.ts +33 -0
  145. package/src/settings/validation/primitives.ts +203 -0
  146. package/src/settings/validation/projection.ts +50 -0
  147. package/src/settings/validation/registry.ts +170 -0
  148. package/src/settings/validation.ts +4 -0
  149. package/src/surface-transfer/client.ts +54 -0
  150. package/src/surface-transfer/generated/fields.ts +12 -0
  151. package/src/surface-transfer/generated/protocol.ts +61 -0
  152. package/src/surface-transfer/generated/variant-fields.ts +30 -0
  153. package/src/surface-transfer/index.ts +9 -0
  154. package/src/surface-transfer/validation.ts +209 -0
  155. package/src/surfaces/client.ts +140 -0
  156. package/src/surfaces/generated/fields.ts +19 -0
  157. package/src/surfaces/generated/protocol.ts +217 -0
  158. package/src/surfaces/generated/variant-fields.ts +42 -0
  159. package/src/surfaces/index.ts +9 -0
  160. package/src/surfaces/validation.ts +199 -0
  161. package/src/transfer/client.ts +133 -0
  162. package/src/transfer/connection.ts +87 -0
  163. package/src/transfer/generated/fields.ts +23 -0
  164. package/src/transfer/generated/protocol.ts +171 -0
  165. package/src/transfer/generated/variant-fields.ts +45 -0
  166. package/src/transfer/index.ts +11 -0
  167. package/src/transfer/payload.ts +71 -0
  168. package/src/transfer/validation.ts +282 -0
  169. package/src/update/client.ts +29 -0
  170. package/src/update/controller.ts +255 -0
  171. package/src/update/direct.ts +3 -0
  172. package/src/update/generated/fields.ts +14 -0
  173. package/src/update/generated/protocol.ts +238 -0
  174. package/src/update/generated/variant-fields.ts +44 -0
  175. package/src/update/index.ts +14 -0
  176. package/src/update/ports.ts +36 -0
  177. package/src/update/serialized.ts +12 -0
  178. package/src/update/validation.ts +191 -0
@@ -0,0 +1,444 @@
1
+ import {
2
+ COMMAND_VARIANT_FIELDS,
3
+ COMMAND_VARIANT_FIELDS_DISCRIMINANTS,
4
+ } from "./generated/variant-fields.ts";
5
+ import {
6
+ COMMAND_KEYMAP_DURABILITIES,
7
+ COMMAND_KEYMAP_LOAD_ORIGINS,
8
+ COMMAND_KEYMAP_LOAD_STATUSES,
9
+ COMMAND_KEYMAP_MUTATION_OUTCOMES,
10
+ COMMAND_KEYMAP_MUTATION_STATUSES,
11
+ COMMAND_KEYMAP_OVERRIDE_KINDS,
12
+ COMMAND_KEYMAP_PREVIEW_STATUSES,
13
+ COMMAND_KEYMAP_PROTOCOL_VERSION,
14
+ COMMAND_KEYMAP_RECOVERY_CODES,
15
+ COMMAND_KEYMAP_REJECTION_CODES,
16
+ type CommandCatalogueSnapshot,
17
+ type CommandAvailabilitySnapshot,
18
+ type CommandCatalogueChangedEvent,
19
+ type CommandKeymapChangedEvent,
20
+ type CommandKeymapCommit,
21
+ type CommandKeymapLoadOutcome,
22
+ type CommandKeymapMutationResult,
23
+ type CommandKeymapPreview,
24
+ type CommandKeymapPreviewResult,
25
+ type CommandKeymapReset,
26
+ type CommandKeymapSnapshot,
27
+ } from "./generated/protocol.ts";
28
+ import { COMMANDS_FIELDS } from "./generated/fields.ts";
29
+
30
+ export class CommandProtocolValidationError extends Error {
31
+ readonly code = "command_protocol_incompatible";
32
+
33
+ constructor(readonly path: string, detail: string) {
34
+ super(`${path}: ${detail}`);
35
+ this.name = "CommandProtocolValidationError";
36
+ }
37
+ }
38
+
39
+ export function assertValidCommandCatalogue(
40
+ value: unknown,
41
+ ): asserts value is CommandCatalogueSnapshot {
42
+ const record = object(value, "$", COMMANDS_FIELDS.CommandCatalogueSnapshot);
43
+ version(record.protocolVersion, "$.protocolVersion");
44
+ finiteInteger(record.registryGeneration, "$.registryGeneration");
45
+ digest(record.registryDigest, "$.registryDigest");
46
+ array(record.commands, "$.commands").forEach((command, index) => {
47
+ const item = object(command, `$.commands[${index}]`);
48
+ text(item.id, `$.commands[${index}].id`);
49
+ text(item.label, `$.commands[${index}].label`);
50
+ argumentSchema(item.arguments, `$.commands[${index}].arguments`);
51
+ });
52
+ array(record.presets, "$.presets").forEach((preset, index) => {
53
+ const item = object(preset, `$.presets[${index}]`);
54
+ text(item.id, `$.presets[${index}].id`);
55
+ positiveInteger(item.version, `$.presets[${index}].version`);
56
+ });
57
+ }
58
+
59
+ export function assertValidCommandAvailabilitySnapshot(
60
+ value: unknown,
61
+ ): asserts value is CommandAvailabilitySnapshot {
62
+ const record = object(value, "$", COMMANDS_FIELDS.CommandAvailabilitySnapshot);
63
+ finiteInteger(record.registryGeneration, "$.registryGeneration");
64
+ finiteInteger(record.contextRevision, "$.contextRevision");
65
+ let previous = "";
66
+ array(record.records, "$.records").forEach((entry, index) => {
67
+ const item = object(entry, `$.records[${index}]`);
68
+ const commandId = text(item.commandId, `$.records[${index}].commandId`);
69
+ if (index > 0 && commandId <= previous) {
70
+ fail(
71
+ `$.records[${index}].commandId`,
72
+ "expected unique command-id order",
73
+ );
74
+ }
75
+ previous = commandId;
76
+ const availability = object(
77
+ item.availability,
78
+ `$.records[${index}].availability`,
79
+ );
80
+ member(
81
+ availability.state,
82
+ ["available", "unavailable", "hidden", "unsupported"],
83
+ `$.records[${index}].availability.state`,
84
+ );
85
+ if (
86
+ (availability.state === "available") !==
87
+ (availability.reason === null)
88
+ ) {
89
+ fail(
90
+ `$.records[${index}].availability.reason`,
91
+ "available requires no reason; every other state requires one",
92
+ );
93
+ }
94
+ if (availability.reason !== null) {
95
+ const reason = object(
96
+ availability.reason,
97
+ `$.records[${index}].availability.reason`,
98
+ );
99
+ if (reason.detail !== null) {
100
+ text(
101
+ reason.detail,
102
+ `$.records[${index}].availability.reason.detail`,
103
+ );
104
+ }
105
+ const code = object(
106
+ reason.code,
107
+ `$.records[${index}].availability.reason.code`,
108
+ );
109
+ member(
110
+ code.kind,
111
+ ["contextNotAllowed", "missingCapability", "consumer"],
112
+ `$.records[${index}].availability.reason.code.kind`,
113
+ );
114
+ if (code.kind === "consumer") {
115
+ text(
116
+ code.code,
117
+ `$.records[${index}].availability.reason.code.code`,
118
+ );
119
+ }
120
+ }
121
+ });
122
+ }
123
+
124
+ export function assertValidCommandCatalogueChangedEvent(
125
+ value: unknown,
126
+ ): asserts value is CommandCatalogueChangedEvent {
127
+ const record = object(value, "$", COMMANDS_FIELDS.CommandCatalogueChangedEvent);
128
+ version(record.protocolVersion, "$.protocolVersion");
129
+ finiteInteger(record.registryGeneration, "$.registryGeneration");
130
+ }
131
+
132
+ export function assertValidCommandKeymapChangedEvent(
133
+ value: unknown,
134
+ ): asserts value is CommandKeymapChangedEvent {
135
+ const record = object(value, "$", COMMANDS_FIELDS.CommandKeymapChangedEvent);
136
+ version(record.protocolVersion, "$.protocolVersion");
137
+ finiteInteger(record.registryGeneration, "$.registryGeneration");
138
+ finiteInteger(record.keymapRevision, "$.keymapRevision");
139
+ }
140
+
141
+ export function assertValidCommandKeymapSnapshot(
142
+ value: unknown,
143
+ ): asserts value is CommandKeymapSnapshot {
144
+ const record = object(value, "$", COMMANDS_FIELDS.CommandKeymapSnapshot);
145
+ version(record.protocolVersion, "$.protocolVersion");
146
+ finiteInteger(record.registryGeneration, "$.registryGeneration");
147
+ digest(record.registryDigest, "$.registryDigest");
148
+ const state = object(record.state, "$.state");
149
+ finiteInteger(state.revision, "$.state.revision");
150
+ text(state.activePresetId, "$.state.activePresetId");
151
+ array(state.overrides, "$.state.overrides").forEach((override, index) =>
152
+ keymapOverride(override, `$.state.overrides[${index}]`),
153
+ );
154
+ positiveInteger(record.activePresetVersion, "$.activePresetVersion");
155
+ array(record.bindings, "$.bindings").forEach((binding, index) =>
156
+ effectiveBinding(binding, `$.bindings[${index}]`),
157
+ );
158
+ array(record.conflicts, "$.conflicts");
159
+ const origin = object(record.origin, "$.origin");
160
+ member(origin.kind, COMMAND_KEYMAP_LOAD_ORIGINS, "$.origin.kind");
161
+ object(origin, "$.origin", variantKeys("CommandKeymapLoadOrigin", origin, "$.origin"));
162
+ if (origin.kind === "migrated") {
163
+ positiveInteger(origin.from, "$.origin.from");
164
+ positiveInteger(origin.to, "$.origin.to");
165
+ }
166
+ array(record.diagnostics, "$.diagnostics");
167
+ }
168
+
169
+ export function assertValidCommandKeymapPreview(
170
+ value: unknown,
171
+ ): asserts value is CommandKeymapPreview {
172
+ baseRequest(value, "$", COMMANDS_FIELDS.CommandKeymapPreview);
173
+ keymapPatch(object(value, "$").patch, "$.patch");
174
+ }
175
+
176
+ export function assertValidCommandKeymapCommit(
177
+ value: unknown,
178
+ ): asserts value is CommandKeymapCommit {
179
+ const record = object(value, "$", COMMANDS_FIELDS.CommandKeymapCommit);
180
+ text(record.requestId, "$.requestId");
181
+ const evidence = object(record.evidence, "$.evidence");
182
+ finiteInteger(evidence.registryGeneration, "$.evidence.registryGeneration");
183
+ finiteInteger(evidence.keymapRevision, "$.evidence.keymapRevision");
184
+ text(evidence.activePresetId, "$.evidence.activePresetId");
185
+ positiveInteger(
186
+ evidence.activePresetVersion,
187
+ "$.evidence.activePresetVersion",
188
+ );
189
+ digest(evidence.patchDigest, "$.evidence.patchDigest");
190
+ keymapPatch(record.patch, "$.patch");
191
+ }
192
+
193
+ export function assertValidCommandKeymapReset(
194
+ value: unknown,
195
+ ): asserts value is CommandKeymapReset {
196
+ const record = object(value, "$", COMMANDS_FIELDS.CommandKeymapReset);
197
+ text(record.requestId, "$.requestId");
198
+ baseRequest(value, "$");
199
+ }
200
+
201
+ export function assertValidCommandKeymapPreviewResult(
202
+ value: unknown,
203
+ ): asserts value is CommandKeymapPreviewResult {
204
+ const record = object(value, "$");
205
+ member(record.status, COMMAND_KEYMAP_PREVIEW_STATUSES, "$.status");
206
+ object(record, "$", variantKeys("CommandKeymapPreviewResult", record, "$"));
207
+ assertValidCommandKeymapSnapshot(record.snapshot);
208
+ if (record.status === "accepted") {
209
+ const evidence = object(record.evidence, "$.evidence");
210
+ digest(evidence.patchDigest, "$.evidence.patchDigest");
211
+ } else if (record.status === "rejected") {
212
+ rejection(record.rejection, "$.rejection");
213
+ array(record.conflicts, "$.conflicts");
214
+ }
215
+ }
216
+
217
+ export function assertValidCommandKeymapLoadOutcome(
218
+ value: unknown,
219
+ ): asserts value is CommandKeymapLoadOutcome {
220
+ const record = object(value, "$");
221
+ member(record.status, COMMAND_KEYMAP_LOAD_STATUSES, "$.status");
222
+ object(record, "$", variantKeys("CommandKeymapLoadOutcome", record, "$"));
223
+ if (record.status === "loaded") {
224
+ assertValidCommandKeymapSnapshot(record.snapshot);
225
+ } else if (record.status === "recovery") {
226
+ const recovery = object(record.recovery, "$.recovery");
227
+ member(recovery.code, COMMAND_KEYMAP_RECOVERY_CODES, "$.recovery.code");
228
+ } else {
229
+ text(record.detail, "$.detail");
230
+ }
231
+ }
232
+
233
+ export function assertValidCommandKeymapMutationResult(
234
+ value: unknown,
235
+ ): asserts value is CommandKeymapMutationResult {
236
+ const record = object(value, "$");
237
+ member(record.status, COMMAND_KEYMAP_MUTATION_STATUSES, "$.status");
238
+ object(record, "$", variantKeys("CommandKeymapMutationResult", record, "$"));
239
+ assertValidCommandKeymapSnapshot(record.snapshot);
240
+ if (record.status === "applied") {
241
+ const receipt = object(record.receipt, "$.receipt");
242
+ member(
243
+ receipt.outcome,
244
+ COMMAND_KEYMAP_MUTATION_OUTCOMES,
245
+ "$.receipt.outcome",
246
+ );
247
+ member(
248
+ receipt.durability,
249
+ COMMAND_KEYMAP_DURABILITIES,
250
+ "$.receipt.durability",
251
+ );
252
+ } else if (record.status === "rejected") {
253
+ rejection(record.rejection, "$.rejection");
254
+ array(record.conflicts, "$.conflicts");
255
+ }
256
+ }
257
+
258
+ function baseRequest(
259
+ value: unknown,
260
+ path: string,
261
+ allowed?: readonly string[],
262
+ ): void {
263
+ const record = object(value, path, allowed);
264
+ finiteInteger(record.registryGeneration, `${path}.registryGeneration`);
265
+ finiteInteger(record.keymapRevision, `${path}.keymapRevision`);
266
+ text(record.activePresetId, `${path}.activePresetId`);
267
+ positiveInteger(record.activePresetVersion, `${path}.activePresetVersion`);
268
+ }
269
+
270
+ function keymapPatch(value: unknown, path: string): void {
271
+ const record = object(value, path, COMMANDS_FIELDS.CommandKeymapPatch);
272
+ if (
273
+ record.activePresetId !== null &&
274
+ typeof record.activePresetId !== "string"
275
+ ) {
276
+ fail(`${path}.activePresetId`, "expected string or null");
277
+ }
278
+ if (typeof record.clearOverrides !== "boolean") {
279
+ fail(`${path}.clearOverrides`, "expected boolean");
280
+ }
281
+ array(record.removeBindingIds, `${path}.removeBindingIds`).forEach(
282
+ (id, index) => text(id, `${path}.removeBindingIds[${index}]`),
283
+ );
284
+ array(record.upsertOverrides, `${path}.upsertOverrides`).forEach(
285
+ (override, index) =>
286
+ keymapOverride(override, `${path}.upsertOverrides[${index}]`),
287
+ );
288
+ }
289
+
290
+ function keymapOverride(value: unknown, path: string): void {
291
+ const record = object(value, path);
292
+ member(record.kind, COMMAND_KEYMAP_OVERRIDE_KINDS, `${path}.kind`);
293
+ object(record, path, variantKeys("CommandKeymapOverride", record, path));
294
+ if (record.kind === "add") {
295
+ bindingDefinition(record.binding, `${path}.binding`);
296
+ } else {
297
+ text(record.bindingId, `${path}.bindingId`);
298
+ if (record.kind === "replace") {
299
+ bindingDefinition(record.replacement, `${path}.replacement`, false);
300
+ }
301
+ }
302
+ }
303
+
304
+ function bindingDefinition(
305
+ value: unknown,
306
+ path: string,
307
+ requireId = true,
308
+ ): void {
309
+ const record = object(value, path);
310
+ if (requireId) text(record.id, `${path}.id`);
311
+ text(record.commandId, `${path}.commandId`);
312
+ text(record.contextId, `${path}.contextId`);
313
+ const trigger = object(record.trigger, `${path}.trigger`);
314
+ text(trigger.code, `${path}.trigger.code`);
315
+ }
316
+
317
+ function effectiveBinding(value: unknown, path: string): void {
318
+ const record = object(value, path);
319
+ text(record.id, `${path}.id`);
320
+ const source = object(record.source, `${path}.source`);
321
+ member(source.kind, ["preset", "replacement", "addedOverride"], `${path}.source.kind`);
322
+ object(source, `${path}.source`, variantKeys("CommandBindingSource", source, `${path}.source`));
323
+ bindingDefinition(
324
+ {
325
+ ...record,
326
+ commandId: object(record.invocation, `${path}.invocation`).commandId,
327
+ },
328
+ path,
329
+ );
330
+ }
331
+
332
+ function argumentSchema(value: unknown, path: string): void {
333
+ const record = object(value, path);
334
+ member(record.shape, ["none", "object"], `${path}.shape`);
335
+ object(record, path, variantKeys("CommandArgumentSchema", record, path));
336
+ if (record.shape === "object") array(record.fields, `${path}.fields`);
337
+ }
338
+
339
+ function rejection(value: unknown, path: string): void {
340
+ const record = object(value, path);
341
+ member(record.code, COMMAND_KEYMAP_REJECTION_CODES, `${path}.code`);
342
+ text(record.detail, `${path}.detail`);
343
+ }
344
+
345
+ function version(value: unknown, path: string): void {
346
+ if (value !== COMMAND_KEYMAP_PROTOCOL_VERSION) {
347
+ fail(path, `expected protocol ${COMMAND_KEYMAP_PROTOCOL_VERSION}`);
348
+ }
349
+ }
350
+
351
+ function digest(value: unknown, path: string): void {
352
+ if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
353
+ fail(path, "expected lowercase SHA-256 digest");
354
+ }
355
+ }
356
+
357
+ function text(value: unknown, path: string): string {
358
+ if (typeof value !== "string" || value.length === 0) {
359
+ fail(path, "expected non-empty string");
360
+ }
361
+ return value;
362
+ }
363
+
364
+ function positiveInteger(value: unknown, path: string): void {
365
+ finiteInteger(value, path);
366
+ if ((value as number) < 1) fail(path, "expected positive integer");
367
+ }
368
+
369
+ function finiteInteger(value: unknown, path: string): void {
370
+ if (
371
+ typeof value !== "number" ||
372
+ !Number.isSafeInteger(value) ||
373
+ value < 0
374
+ ) {
375
+ fail(path, "expected non-negative safe integer");
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Rejects a non-object, an unknown key, and a missing key.
381
+ *
382
+ * `allowed` comes from the generated field map, so the keys accepted are the
383
+ * Rust struct's and nothing else — contract 010's Boundary Validation Target.
384
+ * Passing no list keeps shape-only behaviour for the tagged unions, whose
385
+ * allowed keys depend on their discriminant and so are not one flat set.
386
+ */
387
+ function object(
388
+ value: unknown,
389
+ path: string,
390
+ allowed?: readonly string[],
391
+ ): Record<string, unknown> {
392
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
393
+ fail(path, "expected object");
394
+ }
395
+ const record = value as Record<string, unknown>;
396
+ if (allowed === undefined) return record;
397
+
398
+ const permitted = new Set(allowed);
399
+ for (const key of Object.keys(record)) {
400
+ if (!permitted.has(key)) fail(`${path}.${key}`, "unknown field");
401
+ }
402
+ for (const key of allowed) {
403
+ if (!(key in record)) fail(`${path}.${key}`, "missing field");
404
+ }
405
+ return record;
406
+ }
407
+
408
+ function array(value: unknown, path: string): unknown[] {
409
+ if (!Array.isArray(value)) fail(path, "expected array");
410
+ return value;
411
+ }
412
+
413
+ function member<const T extends readonly string[]>(
414
+ value: unknown,
415
+ choices: T,
416
+ path: string,
417
+ ): asserts value is T[number] {
418
+ if (typeof value !== "string" || !choices.includes(value)) {
419
+ fail(path, `expected one of ${choices.join(", ")}`);
420
+ }
421
+ }
422
+
423
+ function fail(path: string, detail: string): never {
424
+ throw new CommandProtocolValidationError(path, detail);
425
+ }
426
+
427
+ /**
428
+ * Allowed keys for one tagged-union variant, from the generated map, with the
429
+ * discriminant's name read from the map too. This domain tags on `kind`,
430
+ * `shape` and `status`.
431
+ *
432
+ * A missing entry means the generator failed to read the union — every caller
433
+ * runs `member()` over the discriminant above this call.
434
+ */
435
+ function variantKeys(
436
+ type: string,
437
+ value: Record<string, unknown>,
438
+ path: string,
439
+ ): readonly string[] {
440
+ const discriminant = value[COMMAND_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
441
+ const keys = COMMAND_VARIANT_FIELDS[type]?.[discriminant as string];
442
+ if (keys === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
443
+ return keys;
444
+ }
@@ -0,0 +1,215 @@
1
+ import type { EventTransport } from "@inflatable-cookie/longhorn/core";
2
+
3
+ import type {
4
+ BackupCreateCommand,
5
+ BackupCreateOutcome,
6
+ BackupExportCommand,
7
+ BackupExportOutcome,
8
+ BackupRetentionApplyCommand,
9
+ BackupRetentionApplyOutcome,
10
+ ConfigOperationsSnapshot,
11
+ ConfigSnapshotCommand,
12
+ RestoreAdapterExecuteCommand,
13
+ RestoreAdapterExecuteOutcome,
14
+ RestoreExecuteCommand,
15
+ RestoreExecuteOutcome,
16
+ RestoreInspectCommand,
17
+ RestoreInspectOutcome,
18
+ RestorePlanCommand,
19
+ RestorePlanOutcome,
20
+ RestoreRecoveryCommand,
21
+ RestoreRecoveryOutcomeProjection,
22
+ StorageCleanupCommand,
23
+ StorageCleanupOutcome,
24
+ StorageRecoveryCommand,
25
+ StorageRecoveryOutcome,
26
+ StorageTransitionExecuteCommand,
27
+ StorageTransitionExecuteOutcome,
28
+ StorageTransitionInspectCommand,
29
+ StorageTransitionInspectOutcome,
30
+ } from "./generated/protocol.ts";
31
+ import {
32
+ assertValidBackupCreateCommand,
33
+ assertValidBackupCreateOutcome,
34
+ assertValidBackupExportCommand,
35
+ assertValidBackupExportOutcome,
36
+ assertValidBackupRetentionApplyCommand,
37
+ assertValidBackupRetentionApplyOutcome,
38
+ assertValidConfigOperationsSnapshot,
39
+ assertValidConfigSnapshotCommand,
40
+ assertValidRestoreAdapterExecuteCommand,
41
+ assertValidRestoreAdapterExecuteOutcome,
42
+ assertValidRestoreExecuteCommand,
43
+ assertValidRestoreExecuteOutcome,
44
+ assertValidRestoreInspectCommand,
45
+ assertValidRestoreInspectOutcome,
46
+ assertValidRestorePlanCommand,
47
+ assertValidRestorePlanOutcome,
48
+ assertValidRestoreRecoveryCommand,
49
+ assertValidRestoreRecoveryOutcome,
50
+ assertValidStorageCleanupCommand,
51
+ assertValidStorageCleanupOutcome,
52
+ assertValidStorageRecoveryCommand,
53
+ assertValidStorageRecoveryOutcome,
54
+ assertValidStorageTransitionExecuteCommand,
55
+ assertValidStorageTransitionExecuteOutcome,
56
+ assertValidStorageTransitionInspectCommand,
57
+ assertValidStorageTransitionInspectOutcome,
58
+ } from "./validation.ts";
59
+ import {
60
+ CONFIG_BACKUP_CREATE_COMMAND,
61
+ CONFIG_BACKUP_EXPORT_COMMAND,
62
+ CONFIG_BACKUP_RETENTION_COMMAND,
63
+ CONFIG_SNAPSHOT_COMMAND,
64
+ CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND,
65
+ CONFIG_RESTORE_EXECUTE_COMMAND,
66
+ CONFIG_RESTORE_INSPECT_COMMAND,
67
+ CONFIG_RESTORE_PLAN_COMMAND,
68
+ CONFIG_RESTORE_RECOVER_COMMAND,
69
+ CONFIG_STORAGE_CLEANUP_COMMAND,
70
+ CONFIG_STORAGE_EXECUTE_COMMAND,
71
+ CONFIG_STORAGE_INSPECT_COMMAND,
72
+ CONFIG_STORAGE_RECOVER_COMMAND,
73
+ } from "./names.ts";
74
+
75
+ export class ConfigOperationsClient {
76
+ readonly #transport: EventTransport;
77
+
78
+ constructor(transport: EventTransport) {
79
+ this.#transport = transport;
80
+ }
81
+
82
+ async snapshot(command: ConfigSnapshotCommand): Promise<ConfigOperationsSnapshot> {
83
+ assertValidConfigSnapshotCommand(command);
84
+ const value = await this.#transport.invoke(CONFIG_SNAPSHOT_COMMAND, { command });
85
+ assertValidConfigOperationsSnapshot(value);
86
+ return value;
87
+ }
88
+
89
+ async inspectStorageTransition(
90
+ command: StorageTransitionInspectCommand,
91
+ ): Promise<StorageTransitionInspectOutcome> {
92
+ assertValidStorageTransitionInspectCommand(command);
93
+ const value = await this.#transport.invoke(CONFIG_STORAGE_INSPECT_COMMAND, {
94
+ command,
95
+ });
96
+ assertValidStorageTransitionInspectOutcome(value);
97
+ return value;
98
+ }
99
+
100
+ async executeStorageTransition(
101
+ command: StorageTransitionExecuteCommand,
102
+ ): Promise<StorageTransitionExecuteOutcome> {
103
+ assertValidStorageTransitionExecuteCommand(command);
104
+ const value = await this.#transport.invoke(CONFIG_STORAGE_EXECUTE_COMMAND, {
105
+ command,
106
+ });
107
+ assertValidStorageTransitionExecuteOutcome(value);
108
+ return value;
109
+ }
110
+
111
+ async recoverStorage(
112
+ command: StorageRecoveryCommand,
113
+ ): Promise<StorageRecoveryOutcome> {
114
+ assertValidStorageRecoveryCommand(command);
115
+ const value = await this.#transport.invoke(CONFIG_STORAGE_RECOVER_COMMAND, {
116
+ command,
117
+ });
118
+ assertValidStorageRecoveryOutcome(value);
119
+ return value;
120
+ }
121
+
122
+ async cleanupStorage(
123
+ command: StorageCleanupCommand,
124
+ ): Promise<StorageCleanupOutcome> {
125
+ assertValidStorageCleanupCommand(command);
126
+ const value = await this.#transport.invoke(CONFIG_STORAGE_CLEANUP_COMMAND, {
127
+ command,
128
+ });
129
+ assertValidStorageCleanupOutcome(value);
130
+ return value;
131
+ }
132
+
133
+ async createBackup(command: BackupCreateCommand): Promise<BackupCreateOutcome> {
134
+ assertValidBackupCreateCommand(command);
135
+ const value = await this.#transport.invoke(CONFIG_BACKUP_CREATE_COMMAND, {
136
+ command,
137
+ });
138
+ assertValidBackupCreateOutcome(value);
139
+ return value;
140
+ }
141
+
142
+ async exportBackup(command: BackupExportCommand): Promise<BackupExportOutcome> {
143
+ assertValidBackupExportCommand(command);
144
+ const value = await this.#transport.invoke(CONFIG_BACKUP_EXPORT_COMMAND, {
145
+ command,
146
+ });
147
+ assertValidBackupExportOutcome(value);
148
+ return value;
149
+ }
150
+
151
+ async applyBackupRetention(
152
+ command: BackupRetentionApplyCommand,
153
+ ): Promise<BackupRetentionApplyOutcome> {
154
+ assertValidBackupRetentionApplyCommand(command);
155
+ const value = await this.#transport.invoke(CONFIG_BACKUP_RETENTION_COMMAND, {
156
+ command,
157
+ });
158
+ assertValidBackupRetentionApplyOutcome(value);
159
+ return value;
160
+ }
161
+
162
+ async inspectRestore(
163
+ command: RestoreInspectCommand,
164
+ ): Promise<RestoreInspectOutcome> {
165
+ assertValidRestoreInspectCommand(command);
166
+ const value = await this.#transport.invoke(CONFIG_RESTORE_INSPECT_COMMAND, {
167
+ command,
168
+ });
169
+ assertValidRestoreInspectOutcome(value);
170
+ return value;
171
+ }
172
+
173
+ async planRestore(command: RestorePlanCommand): Promise<RestorePlanOutcome> {
174
+ assertValidRestorePlanCommand(command);
175
+ const value = await this.#transport.invoke(CONFIG_RESTORE_PLAN_COMMAND, {
176
+ command,
177
+ });
178
+ assertValidRestorePlanOutcome(value);
179
+ return value;
180
+ }
181
+
182
+ async executeRestore(
183
+ command: RestoreExecuteCommand,
184
+ ): Promise<RestoreExecuteOutcome> {
185
+ assertValidRestoreExecuteCommand(command);
186
+ const value = await this.#transport.invoke(CONFIG_RESTORE_EXECUTE_COMMAND, {
187
+ command,
188
+ });
189
+ assertValidRestoreExecuteOutcome(value);
190
+ return value;
191
+ }
192
+
193
+ async executeAdapterRestore(
194
+ command: RestoreAdapterExecuteCommand,
195
+ ): Promise<RestoreAdapterExecuteOutcome> {
196
+ assertValidRestoreAdapterExecuteCommand(command);
197
+ const value = await this.#transport.invoke(
198
+ CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND,
199
+ { command },
200
+ );
201
+ assertValidRestoreAdapterExecuteOutcome(value);
202
+ return value;
203
+ }
204
+
205
+ async recoverRestore(
206
+ command: RestoreRecoveryCommand,
207
+ ): Promise<RestoreRecoveryOutcomeProjection> {
208
+ assertValidRestoreRecoveryCommand(command);
209
+ const value = await this.#transport.invoke(CONFIG_RESTORE_RECOVER_COMMAND, {
210
+ command,
211
+ });
212
+ assertValidRestoreRecoveryOutcome(value);
213
+ return value;
214
+ }
215
+ }