@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,411 @@
|
|
|
1
|
+
import { CommandClient } from "./client.ts";
|
|
2
|
+
import type {
|
|
3
|
+
CommandArguments,
|
|
4
|
+
CommandInvocation,
|
|
5
|
+
CommandKeymapMutationResult,
|
|
6
|
+
CommandKeymapPatch,
|
|
7
|
+
CommandKeymapSnapshot,
|
|
8
|
+
CommandPlatform,
|
|
9
|
+
CommandSearchHit,
|
|
10
|
+
} from "./generated/protocol.ts";
|
|
11
|
+
import type {
|
|
12
|
+
CommandDispatch,
|
|
13
|
+
CommandExecutionOutcome,
|
|
14
|
+
CommandExecutionSource,
|
|
15
|
+
CommandPorts,
|
|
16
|
+
CommandUnlisten,
|
|
17
|
+
} from "./ports.ts";
|
|
18
|
+
import {
|
|
19
|
+
joinCommandState,
|
|
20
|
+
projectCommandSurfaces,
|
|
21
|
+
searchCommands,
|
|
22
|
+
type CommandJoinedState,
|
|
23
|
+
type CommandSurfaceProjection,
|
|
24
|
+
} from "./projectors.ts";
|
|
25
|
+
|
|
26
|
+
export type CommandControllerStatus =
|
|
27
|
+
| { readonly kind: "idle" }
|
|
28
|
+
| { readonly kind: "loading" }
|
|
29
|
+
| { readonly kind: "ready" }
|
|
30
|
+
| {
|
|
31
|
+
readonly kind: "recovery";
|
|
32
|
+
readonly recovery: {
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly detail: string;
|
|
35
|
+
readonly sourcePreserved: boolean;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
| { readonly kind: "unavailable"; readonly detail: string }
|
|
39
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
40
|
+
|
|
41
|
+
export type CommandMutationStatus =
|
|
42
|
+
| { readonly kind: "idle" }
|
|
43
|
+
| { readonly kind: "dirty" }
|
|
44
|
+
| { readonly kind: "previewing" }
|
|
45
|
+
| { readonly kind: "committing" }
|
|
46
|
+
| { readonly kind: "saved" }
|
|
47
|
+
| { readonly kind: "conflict"; readonly detail: string }
|
|
48
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
49
|
+
|
|
50
|
+
export interface CommandControllerOptions {
|
|
51
|
+
readonly ports: CommandPorts;
|
|
52
|
+
readonly platform: CommandPlatform;
|
|
53
|
+
readonly search?: (
|
|
54
|
+
records: CommandJoinedState["catalogue"]["commands"],
|
|
55
|
+
query: string,
|
|
56
|
+
) => Promise<readonly CommandSearchHit[]>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class CommandController {
|
|
60
|
+
readonly #client: CommandClient;
|
|
61
|
+
readonly #platform: CommandPlatform;
|
|
62
|
+
readonly #search;
|
|
63
|
+
readonly #observers = new Set<() => void>();
|
|
64
|
+
#status: CommandControllerStatus = { kind: "idle" };
|
|
65
|
+
#mutation: CommandMutationStatus = { kind: "idle" };
|
|
66
|
+
#model: CommandJoinedState | undefined;
|
|
67
|
+
#projection: CommandSurfaceProjection | undefined;
|
|
68
|
+
#searchHits: readonly CommandSearchHit[] = [];
|
|
69
|
+
#query = "";
|
|
70
|
+
#draft: CommandKeymapPatch | undefined;
|
|
71
|
+
#unlisten: CommandUnlisten[] = [];
|
|
72
|
+
#lifecycleRevision = 0;
|
|
73
|
+
#loadRevision = 0;
|
|
74
|
+
#searchRevision = 0;
|
|
75
|
+
#started = false;
|
|
76
|
+
|
|
77
|
+
constructor(options: CommandControllerOptions) {
|
|
78
|
+
this.#client = new CommandClient(options.ports);
|
|
79
|
+
this.#platform = options.platform;
|
|
80
|
+
this.#search =
|
|
81
|
+
options.search ??
|
|
82
|
+
(async (records, query) => searchCommands(records, query));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get status(): CommandControllerStatus {
|
|
86
|
+
return this.#status;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get mutation(): CommandMutationStatus {
|
|
90
|
+
return this.#mutation;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get model(): CommandJoinedState | undefined {
|
|
94
|
+
return this.#model;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get projection(): CommandSurfaceProjection | undefined {
|
|
98
|
+
return this.#projection;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get query(): string {
|
|
102
|
+
return this.#query;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get searchHits(): readonly CommandSearchHit[] {
|
|
106
|
+
return this.#searchHits;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get draft(): CommandKeymapPatch | undefined {
|
|
110
|
+
return this.#draft;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get dirty(): boolean {
|
|
114
|
+
return this.#draft !== undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
observe(observer: () => void): () => void {
|
|
118
|
+
this.#observers.add(observer);
|
|
119
|
+
return () => this.#observers.delete(observer);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async start(): Promise<void> {
|
|
123
|
+
if (this.#started) return;
|
|
124
|
+
this.#started = true;
|
|
125
|
+
const lifecycleRevision = ++this.#lifecycleRevision;
|
|
126
|
+
this.#setStatus({ kind: "loading" });
|
|
127
|
+
try {
|
|
128
|
+
const unlisten = await this.#client.listen(() => {
|
|
129
|
+
void this.refresh();
|
|
130
|
+
});
|
|
131
|
+
if (
|
|
132
|
+
!this.#started ||
|
|
133
|
+
lifecycleRevision !== this.#lifecycleRevision
|
|
134
|
+
) {
|
|
135
|
+
await disposeAll(unlisten);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.#unlisten.push(...unlisten);
|
|
139
|
+
await this.refresh();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (
|
|
142
|
+
this.#started &&
|
|
143
|
+
lifecycleRevision === this.#lifecycleRevision
|
|
144
|
+
) {
|
|
145
|
+
this.#setStatus({ kind: "failed", error });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async stop(): Promise<void> {
|
|
151
|
+
this.#started = false;
|
|
152
|
+
this.#lifecycleRevision += 1;
|
|
153
|
+
this.#loadRevision += 1;
|
|
154
|
+
this.#searchRevision += 1;
|
|
155
|
+
const unlisten = this.#unlisten.splice(0);
|
|
156
|
+
await disposeAll(unlisten);
|
|
157
|
+
this.#model = undefined;
|
|
158
|
+
this.#projection = undefined;
|
|
159
|
+
this.#searchHits = [];
|
|
160
|
+
this.#query = "";
|
|
161
|
+
this.#draft = undefined;
|
|
162
|
+
this.#mutation = { kind: "idle" };
|
|
163
|
+
this.#setStatus({ kind: "idle" });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async refresh(): Promise<void> {
|
|
167
|
+
const revision = ++this.#loadRevision;
|
|
168
|
+
try {
|
|
169
|
+
const loaded = await this.#client.load();
|
|
170
|
+
if (!this.#started || revision !== this.#loadRevision) return;
|
|
171
|
+
if (loaded.keymap.status === "recovery") {
|
|
172
|
+
this.#model = undefined;
|
|
173
|
+
this.#projection = undefined;
|
|
174
|
+
this.#setStatus({
|
|
175
|
+
kind: "recovery",
|
|
176
|
+
recovery: loaded.keymap.recovery,
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (loaded.keymap.status === "unavailable") {
|
|
181
|
+
this.#model = undefined;
|
|
182
|
+
this.#projection = undefined;
|
|
183
|
+
this.#setStatus({
|
|
184
|
+
kind: "unavailable",
|
|
185
|
+
detail: loaded.keymap.detail,
|
|
186
|
+
});
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.#install(
|
|
190
|
+
joinCommandState(
|
|
191
|
+
loaded.catalogue,
|
|
192
|
+
loaded.keymap.snapshot,
|
|
193
|
+
loaded.availability,
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
this.#setStatus({ kind: "ready" });
|
|
197
|
+
await this.search(this.#query);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (this.#started && revision === this.#loadRevision) {
|
|
200
|
+
this.#setStatus({ kind: "failed", error });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async search(query: string): Promise<readonly CommandSearchHit[]> {
|
|
206
|
+
this.#query = query;
|
|
207
|
+
const model = this.#model;
|
|
208
|
+
const revision = ++this.#searchRevision;
|
|
209
|
+
if (model === undefined) {
|
|
210
|
+
this.#searchHits = [];
|
|
211
|
+
this.#notify();
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
const hits = await this.#search(model.catalogue.commands, query);
|
|
215
|
+
if (revision !== this.#searchRevision || model !== this.#model) {
|
|
216
|
+
return hits;
|
|
217
|
+
}
|
|
218
|
+
const visible = new Set(this.#projection?.palette.map(({ id }) => id));
|
|
219
|
+
this.#searchHits = hits.filter(({ record }) => visible.has(record.id));
|
|
220
|
+
this.#notify();
|
|
221
|
+
return this.#searchHits;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async dispatch(dispatch: CommandDispatch): Promise<CommandExecutionOutcome> {
|
|
225
|
+
return this.dispatchInvocation(
|
|
226
|
+
{
|
|
227
|
+
commandId: dispatch.commandId,
|
|
228
|
+
arguments: dispatch.arguments ?? {},
|
|
229
|
+
},
|
|
230
|
+
dispatch.source,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async dispatchInvocation(
|
|
235
|
+
invocation: CommandInvocation,
|
|
236
|
+
source: CommandExecutionSource,
|
|
237
|
+
): Promise<CommandExecutionOutcome> {
|
|
238
|
+
const model = this.#requiredModel();
|
|
239
|
+
return this.#client.execute({
|
|
240
|
+
requestId: this.#client.nextRequestId(),
|
|
241
|
+
registryGeneration: model.catalogue.registryGeneration,
|
|
242
|
+
observedContextRevision: model.availability.contextRevision,
|
|
243
|
+
invocation,
|
|
244
|
+
source,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
stageKeymapPatch(patch: CommandKeymapPatch): void {
|
|
249
|
+
this.#draft = patch;
|
|
250
|
+
this.#mutation = { kind: "dirty" };
|
|
251
|
+
this.#notify();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
cancelKeymapDraft(): void {
|
|
255
|
+
this.#draft = undefined;
|
|
256
|
+
this.#mutation = { kind: "idle" };
|
|
257
|
+
this.#notify();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async applyKeymapDraft(): Promise<boolean> {
|
|
261
|
+
const model = this.#requiredModel();
|
|
262
|
+
const patch = this.#draft;
|
|
263
|
+
if (patch === undefined) return true;
|
|
264
|
+
const base = model.keymap;
|
|
265
|
+
const operationRevision = ++this.#loadRevision;
|
|
266
|
+
this.#mutation = { kind: "previewing" };
|
|
267
|
+
this.#notify();
|
|
268
|
+
try {
|
|
269
|
+
const preview = await this.#client.preview({
|
|
270
|
+
registryGeneration: model.catalogue.registryGeneration,
|
|
271
|
+
keymapRevision: base.state.revision,
|
|
272
|
+
activePresetId: base.state.activePresetId,
|
|
273
|
+
activePresetVersion: base.activePresetVersion,
|
|
274
|
+
patch,
|
|
275
|
+
});
|
|
276
|
+
if (operationRevision !== this.#loadRevision || patch !== this.#draft) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (preview.status !== "accepted") {
|
|
280
|
+
this.#applyMutationSnapshot(preview.snapshot);
|
|
281
|
+
this.#mutation = {
|
|
282
|
+
kind: "conflict",
|
|
283
|
+
detail:
|
|
284
|
+
preview.status === "rejected"
|
|
285
|
+
? preview.rejection.detail
|
|
286
|
+
: "Keybindings changed elsewhere",
|
|
287
|
+
};
|
|
288
|
+
this.#notify();
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
this.#mutation = { kind: "committing" };
|
|
292
|
+
this.#notify();
|
|
293
|
+
const result = await this.#client.commit({
|
|
294
|
+
requestId: this.#client.nextRequestId(),
|
|
295
|
+
evidence: preview.evidence,
|
|
296
|
+
patch,
|
|
297
|
+
});
|
|
298
|
+
if (operationRevision !== this.#loadRevision || patch !== this.#draft) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return this.#finishMutation(result);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (operationRevision === this.#loadRevision) {
|
|
304
|
+
this.#mutation = { kind: "failed", error };
|
|
305
|
+
this.#notify();
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async resetKeymap(): Promise<boolean> {
|
|
312
|
+
const model = this.#requiredModel();
|
|
313
|
+
const base = model.keymap;
|
|
314
|
+
const operationRevision = ++this.#loadRevision;
|
|
315
|
+
this.#mutation = { kind: "committing" };
|
|
316
|
+
this.#notify();
|
|
317
|
+
try {
|
|
318
|
+
const result = await this.#client.reset({
|
|
319
|
+
requestId: this.#client.nextRequestId(),
|
|
320
|
+
registryGeneration: model.catalogue.registryGeneration,
|
|
321
|
+
keymapRevision: base.state.revision,
|
|
322
|
+
activePresetId: base.state.activePresetId,
|
|
323
|
+
activePresetVersion: base.activePresetVersion,
|
|
324
|
+
});
|
|
325
|
+
if (operationRevision !== this.#loadRevision) return false;
|
|
326
|
+
return this.#finishMutation(result);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (operationRevision === this.#loadRevision) {
|
|
329
|
+
this.#mutation = { kind: "failed", error };
|
|
330
|
+
this.#notify();
|
|
331
|
+
}
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
#finishMutation(result: CommandKeymapMutationResult): boolean {
|
|
337
|
+
this.#applyMutationSnapshot(result.snapshot);
|
|
338
|
+
if (result.status === "applied") {
|
|
339
|
+
this.#draft = undefined;
|
|
340
|
+
this.#mutation = { kind: "saved" };
|
|
341
|
+
this.#notify();
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
this.#mutation = {
|
|
345
|
+
kind: "conflict",
|
|
346
|
+
detail:
|
|
347
|
+
result.status === "rejected"
|
|
348
|
+
? result.rejection.detail
|
|
349
|
+
: "Keybindings changed elsewhere",
|
|
350
|
+
};
|
|
351
|
+
this.#notify();
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#applyMutationSnapshot(snapshot: CommandKeymapSnapshot): void {
|
|
356
|
+
const model = this.#requiredModel();
|
|
357
|
+
if (snapshot.registryGeneration !== model.catalogue.registryGeneration) {
|
|
358
|
+
void this.refresh();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
this.#install(
|
|
362
|
+
joinCommandState(model.catalogue, snapshot, model.availability),
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#install(model: CommandJoinedState): void {
|
|
367
|
+
const current = this.#model;
|
|
368
|
+
if (
|
|
369
|
+
current !== undefined &&
|
|
370
|
+
(model.catalogue.registryGeneration <
|
|
371
|
+
current.catalogue.registryGeneration ||
|
|
372
|
+
(model.catalogue.registryGeneration ===
|
|
373
|
+
current.catalogue.registryGeneration &&
|
|
374
|
+
(model.keymap.state.revision < current.keymap.state.revision ||
|
|
375
|
+
model.availability.contextRevision <
|
|
376
|
+
current.availability.contextRevision)))
|
|
377
|
+
) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this.#model = model;
|
|
381
|
+
this.#projection = projectCommandSurfaces(model, this.#platform);
|
|
382
|
+
this.#notify();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#requiredModel(): CommandJoinedState {
|
|
386
|
+
if (this.#model === undefined) {
|
|
387
|
+
throw new CommandControllerUnavailableError();
|
|
388
|
+
}
|
|
389
|
+
return this.#model;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
#setStatus(status: CommandControllerStatus): void {
|
|
393
|
+
this.#status = status;
|
|
394
|
+
this.#notify();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
#notify(): void {
|
|
398
|
+
for (const observer of this.#observers) observer();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export class CommandControllerUnavailableError extends Error {
|
|
403
|
+
constructor() {
|
|
404
|
+
super("command controller has no joined authoritative state");
|
|
405
|
+
this.name = "CommandControllerUnavailableError";
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function disposeAll(unlisten: readonly CommandUnlisten[]): Promise<void> {
|
|
410
|
+
await Promise.allSettled(unlisten.map((dispose) => dispose()));
|
|
411
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @generated by `effigy generate:commands`; 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 COMMANDS_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"CommandArgumentField": ["id", "required", "default", "kind"],
|
|
8
|
+
"CommandVisibility": ["hidden", "palette", "menu", "shortcut", "settings", "help"],
|
|
9
|
+
"CommandDiscoveryRecord": ["id", "label", "description", "categoryPath", "keywords", "icon", "visibility", "textInputPolicy", "arguments"],
|
|
10
|
+
"CommandAvailabilityReason": ["code", "detail"],
|
|
11
|
+
"CommandAvailability": ["state", "reason"],
|
|
12
|
+
"CommandAvailabilityRecord": ["commandId", "availability"],
|
|
13
|
+
"CommandAvailabilitySnapshot": ["registryGeneration", "contextRevision", "records"],
|
|
14
|
+
"CommandSearchHit": ["record", "score"],
|
|
15
|
+
"CommandModifiers": ["control", "alt", "shift", "meta"],
|
|
16
|
+
"CommandTriggerModifiers": ["primary", "control", "alt", "shift", "meta"],
|
|
17
|
+
"CommandKeyTrigger": ["code", "modifiers"],
|
|
18
|
+
"CommandKeyChord": ["code", "modifiers"],
|
|
19
|
+
"CommandKeyboardInput": ["chord", "repeat", "composing", "editableText"],
|
|
20
|
+
"CommandBindingDefinition": ["id", "platform", "trigger", "contextId", "commandId", "arguments"],
|
|
21
|
+
"CommandBindingReplacement": ["platform", "trigger", "contextId", "commandId", "arguments"],
|
|
22
|
+
"CommandInvocation": ["commandId", "arguments"],
|
|
23
|
+
"CommandEffectiveBinding": ["id", "source", "platform", "trigger", "contextId", "invocation"],
|
|
24
|
+
"CommandShortcutRecord": ["bindingId", "source", "contextId", "chord", "label"],
|
|
25
|
+
"CommandBindingCandidate": ["bindingId", "source", "matchedContextId", "specificity", "invocation", "disposition"],
|
|
26
|
+
"CommandBindingWinner": ["bindingId", "matchedContextId", "invocation"],
|
|
27
|
+
"CommandKeymapConflict": ["platform", "chord", "contextId", "bindingIds", "invocations"],
|
|
28
|
+
"CommandKeymapPresetRecord": ["id", "version"],
|
|
29
|
+
"CommandCatalogueSnapshot": ["protocolVersion", "registryGeneration", "registryDigest", "commands", "presets"],
|
|
30
|
+
"CommandCatalogueChangedEvent": ["protocolVersion", "registryGeneration"],
|
|
31
|
+
"CommandKeymapState": ["revision", "activePresetId", "overrides"],
|
|
32
|
+
"CommandKeymapPatch": ["activePresetId", "clearOverrides", "removeBindingIds", "upsertOverrides"],
|
|
33
|
+
"CommandKeymapCommitEvidence": ["registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion", "patchDigest"],
|
|
34
|
+
"CommandKeymapPreview": ["registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion", "patch"],
|
|
35
|
+
"CommandKeymapCommit": ["requestId", "evidence", "patch"],
|
|
36
|
+
"CommandKeymapReset": ["requestId", "registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion"],
|
|
37
|
+
"CommandKeymapDiagnostic": ["code", "detail"],
|
|
38
|
+
"CommandKeymapSnapshot": ["protocolVersion", "registryGeneration", "registryDigest", "state", "activePresetVersion", "bindings", "conflicts", "origin", "diagnostics"],
|
|
39
|
+
"CommandKeymapChangedEvent": ["protocolVersion", "registryGeneration", "keymapRevision"],
|
|
40
|
+
"CommandKeymapRejection": ["code", "detail"],
|
|
41
|
+
"CommandKeymapRecovery": ["code", "detail", "sourcePreserved"],
|
|
42
|
+
"CommandKeymapMutationReceipt": ["requestId", "previousRevision", "committedRevision", "outcome", "durability", "patchDigest"],
|
|
43
|
+
};
|