@inflatable-cookie/longhorn 0.4.3 → 0.6.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/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +77 -105
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -17,15 +17,17 @@ import {
|
|
|
17
17
|
BRIDGE_PROTOCOL_VERSION,
|
|
18
18
|
BRIDGE_READ_AUTHORITIES,
|
|
19
19
|
BRIDGE_WRITE_AUTHORITIES,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
} from "../generated/protocol.ts";
|
|
21
|
+
import type {
|
|
22
|
+
BridgeConnectionReason,
|
|
23
|
+
BridgeConnectionState,
|
|
24
|
+
BridgeConnectionStatus,
|
|
25
|
+
BridgeDiagnostic,
|
|
26
|
+
BridgeHelloRequest,
|
|
27
|
+
BridgeHostDescriptor,
|
|
28
|
+
BridgeNegotiationReceipt,
|
|
29
|
+
DomainAuthorityDescriptor,
|
|
30
|
+
DomainCapabilityDescriptor,
|
|
29
31
|
} from "../generated/protocol.ts";
|
|
30
32
|
import {
|
|
31
33
|
array,
|
|
@@ -48,7 +50,9 @@ export function assertBridgeProtocolVersion(value: unknown): asserts value is 1
|
|
|
48
50
|
export function parseBridgeHelloRequest(value: unknown): BridgeHelloRequest {
|
|
49
51
|
const source = record(value, BRIDGE_FIELDS.BridgeHelloRequest);
|
|
50
52
|
assertBridgeProtocolVersion(source.protocolVersion);
|
|
51
|
-
const requestedDomains = array(source.requestedDomains, BRIDGE_MAXIMUM_REQUESTED_DOMAINS).map(
|
|
53
|
+
const requestedDomains = array(source.requestedDomains, BRIDGE_MAXIMUM_REQUESTED_DOMAINS).map(
|
|
54
|
+
domainId,
|
|
55
|
+
);
|
|
52
56
|
unique(requestedDomains, String);
|
|
53
57
|
return {
|
|
54
58
|
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
@@ -80,9 +84,7 @@ export function parseBridgeNegotiationReceipt(
|
|
|
80
84
|
unique(authorities, (item) => item.domainId);
|
|
81
85
|
unique(diagnostics, (item) => item.diagnosticId);
|
|
82
86
|
|
|
83
|
-
const capabilityDomains = new Set(
|
|
84
|
-
capabilities.map((item) => item.domainId),
|
|
85
|
-
);
|
|
87
|
+
const capabilityDomains = new Set(capabilities.map((item) => item.domainId));
|
|
86
88
|
const writerScopes = new Set<string>();
|
|
87
89
|
for (const authority of authorities) {
|
|
88
90
|
if (!capabilityDomains.has(authority.domainId)) {
|
|
@@ -131,17 +133,9 @@ function parseHost(value: unknown): BridgeHostDescriptor {
|
|
|
131
133
|
|
|
132
134
|
function parseConnectionStatus(value: unknown): BridgeConnectionStatus {
|
|
133
135
|
const source = record(value, BRIDGE_FIELDS.BridgeConnectionStatus);
|
|
134
|
-
const state = oneOf(
|
|
135
|
-
source.state,
|
|
136
|
-
BRIDGE_CONNECTION_STATES,
|
|
137
|
-
"unknown_connection_state",
|
|
138
|
-
);
|
|
136
|
+
const state = oneOf(source.state, BRIDGE_CONNECTION_STATES, "unknown_connection_state");
|
|
139
137
|
const reason = nullable(source.reason, (candidate) =>
|
|
140
|
-
oneOf(
|
|
141
|
-
candidate,
|
|
142
|
-
BRIDGE_CONNECTION_REASONS,
|
|
143
|
-
"invalid_connection_status",
|
|
144
|
-
)
|
|
138
|
+
oneOf(candidate, BRIDGE_CONNECTION_REASONS, "invalid_connection_status"),
|
|
145
139
|
);
|
|
146
140
|
if (!validConnectionReason(state, reason)) {
|
|
147
141
|
incompatible("invalid_connection_status", value);
|
|
@@ -164,7 +158,9 @@ function validConnectionReason(
|
|
|
164
158
|
|
|
165
159
|
function parseDomainCapability(value: unknown): DomainCapabilityDescriptor {
|
|
166
160
|
const source = record(value, BRIDGE_FIELDS.DomainCapabilityDescriptor);
|
|
167
|
-
const capabilities = array(source.capabilities, BRIDGE_MAXIMUM_CAPABILITIES_PER_DOMAIN).map(
|
|
161
|
+
const capabilities = array(source.capabilities, BRIDGE_MAXIMUM_CAPABILITIES_PER_DOMAIN).map(
|
|
162
|
+
opaqueId,
|
|
163
|
+
);
|
|
168
164
|
if (capabilities.length === 0) {
|
|
169
165
|
incompatible("invalid_array", value);
|
|
170
166
|
}
|
|
@@ -197,18 +193,13 @@ function parseDomainAuthority(value: unknown): DomainAuthorityDescriptor {
|
|
|
197
193
|
BRIDGE_EXECUTION_AUTHORITIES,
|
|
198
194
|
"unknown_execution_authority",
|
|
199
195
|
);
|
|
200
|
-
const authoritativeRevision = nullable(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
writeAuthority !== "none" ||
|
|
206
|
-
executionAuthority !== "none";
|
|
207
|
-
const revisionIsAuthoritative = readAuthority === "authoritative" ||
|
|
208
|
-
writeAuthority === "authoritative";
|
|
196
|
+
const authoritativeRevision = nullable(source.authoritativeRevision, integer);
|
|
197
|
+
const ownsAnything =
|
|
198
|
+
readAuthority !== "none" || writeAuthority !== "none" || executionAuthority !== "none";
|
|
199
|
+
const revisionIsAuthoritative =
|
|
200
|
+
readAuthority === "authoritative" || writeAuthority === "authoritative";
|
|
209
201
|
if (
|
|
210
|
-
(availability === "offline" &&
|
|
211
|
-
(ownsAnything || authoritativeRevision !== null)) ||
|
|
202
|
+
(availability === "offline" && (ownsAnything || authoritativeRevision !== null)) ||
|
|
212
203
|
(authoritativeRevision !== null && !revisionIsAuthoritative)
|
|
213
204
|
) {
|
|
214
205
|
incompatible("invalid_authority_descriptor", value);
|
|
@@ -230,8 +221,7 @@ function parseDiagnostic(value: unknown): BridgeDiagnostic {
|
|
|
230
221
|
if (
|
|
231
222
|
typeof source.message !== "string" ||
|
|
232
223
|
source.message.length === 0 ||
|
|
233
|
-
new TextEncoder().encode(source.message).length >
|
|
234
|
-
BRIDGE_MAXIMUM_DIAGNOSTIC_MESSAGE_BYTES
|
|
224
|
+
new TextEncoder().encode(source.message).length > BRIDGE_MAXIMUM_DIAGNOSTIC_MESSAGE_BYTES
|
|
235
225
|
) {
|
|
236
226
|
incompatible("invalid_message", source.message);
|
|
237
227
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../../core/record.ts";
|
|
1
2
|
import { BRIDGE_FIELDS } from "../generated/fields.ts";
|
|
2
3
|
import {
|
|
3
4
|
BRIDGE_MAXIMUM_DEDUPLICATION_ENTRIES,
|
|
@@ -5,28 +6,21 @@ import {
|
|
|
5
6
|
BRIDGE_MAXIMUM_OPAQUE_ID_BYTES,
|
|
6
7
|
BRIDGE_FAILURE_PHASES,
|
|
7
8
|
BRIDGE_RETRY_CLASSES,
|
|
8
|
-
type BridgeCancellationRequest,
|
|
9
|
-
type BridgeCommandEnvelope,
|
|
10
|
-
type BridgeCommandReply,
|
|
11
|
-
type BridgeDeduplicationSupport,
|
|
12
|
-
type BridgeFailure,
|
|
13
|
-
type BridgeQueryEnvelope,
|
|
14
|
-
type BridgeQueryReply,
|
|
15
|
-
type BridgeRequestContext,
|
|
16
9
|
} from "../generated/protocol.ts";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
import type {
|
|
11
|
+
BridgeCancellationRequest,
|
|
12
|
+
BridgeCommandEnvelope,
|
|
13
|
+
BridgeCommandReply,
|
|
14
|
+
BridgeDeduplicationSupport,
|
|
15
|
+
BridgeFailure,
|
|
16
|
+
BridgeQueryEnvelope,
|
|
17
|
+
BridgeQueryReply,
|
|
18
|
+
BridgeRequestContext,
|
|
19
|
+
} from "../generated/protocol.ts";
|
|
20
|
+
import { incompatible, integer, nullable, oneOf, opaqueId, record } from "./base.ts";
|
|
21
|
+
import type { BridgeCodec } from "./base.ts";
|
|
26
22
|
|
|
27
|
-
export function parseBridgeRequestContext(
|
|
28
|
-
value: unknown,
|
|
29
|
-
): BridgeRequestContext {
|
|
23
|
+
export function parseBridgeRequestContext(value: unknown): BridgeRequestContext {
|
|
30
24
|
const source = record(value, BRIDGE_FIELDS.BridgeRequestContext);
|
|
31
25
|
return {
|
|
32
26
|
requestId: opaqueId(source.requestId),
|
|
@@ -60,9 +54,7 @@ export function parseBridgeCommandEnvelope<P>(
|
|
|
60
54
|
};
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
export function parseBridgeCancellationRequest(
|
|
64
|
-
value: unknown,
|
|
65
|
-
): BridgeCancellationRequest {
|
|
57
|
+
export function parseBridgeCancellationRequest(value: unknown): BridgeCancellationRequest {
|
|
66
58
|
const source = record(value, BRIDGE_FIELDS.BridgeCancellationRequest);
|
|
67
59
|
return {
|
|
68
60
|
context: parseBridgeRequestContext(source.context),
|
|
@@ -71,39 +63,25 @@ export function parseBridgeCancellationRequest(
|
|
|
71
63
|
};
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
export function parseBridgeFailure<D>(
|
|
75
|
-
value: unknown,
|
|
76
|
-
details: BridgeCodec<D>,
|
|
77
|
-
): BridgeFailure<D> {
|
|
66
|
+
export function parseBridgeFailure<D>(value: unknown, details: BridgeCodec<D>): BridgeFailure<D> {
|
|
78
67
|
const source = record(value, BRIDGE_FIELDS.BridgeFailure);
|
|
79
68
|
if (
|
|
80
69
|
typeof source.message !== "string" ||
|
|
81
70
|
source.message.length === 0 ||
|
|
82
|
-
new TextEncoder().encode(source.message).length >
|
|
83
|
-
BRIDGE_MAXIMUM_FAILURE_MESSAGE_BYTES
|
|
71
|
+
new TextEncoder().encode(source.message).length > BRIDGE_MAXIMUM_FAILURE_MESSAGE_BYTES
|
|
84
72
|
) {
|
|
85
73
|
incompatible("invalid_message", source.message);
|
|
86
74
|
}
|
|
87
75
|
return {
|
|
88
76
|
code: opaqueId(source.code),
|
|
89
77
|
message: source.message,
|
|
90
|
-
retryClass: oneOf(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"unknown_retry_class",
|
|
94
|
-
),
|
|
95
|
-
phase: oneOf(
|
|
96
|
-
source.phase,
|
|
97
|
-
BRIDGE_FAILURE_PHASES,
|
|
98
|
-
"unknown_failure_phase",
|
|
99
|
-
),
|
|
100
|
-
details: nullable(source.details, details.parse),
|
|
78
|
+
retryClass: oneOf(source.retryClass, BRIDGE_RETRY_CLASSES, "unknown_retry_class"),
|
|
79
|
+
phase: oneOf(source.phase, BRIDGE_FAILURE_PHASES, "unknown_failure_phase"),
|
|
80
|
+
details: nullable(source.details, (payload) => details.parse(payload)),
|
|
101
81
|
};
|
|
102
82
|
}
|
|
103
83
|
|
|
104
|
-
export function parseBridgeDeduplicationSupport(
|
|
105
|
-
value: unknown,
|
|
106
|
-
): BridgeDeduplicationSupport {
|
|
84
|
+
export function parseBridgeDeduplicationSupport(value: unknown): BridgeDeduplicationSupport {
|
|
107
85
|
if (value === "unsupported") {
|
|
108
86
|
return value;
|
|
109
87
|
}
|
|
@@ -116,7 +94,7 @@ export function parseBridgeDeduplicationSupport(
|
|
|
116
94
|
) {
|
|
117
95
|
incompatible("unknown_deduplication_support", value);
|
|
118
96
|
}
|
|
119
|
-
const source = value
|
|
97
|
+
const source = value;
|
|
120
98
|
const capacity = integer(source.finite, 1);
|
|
121
99
|
if (capacity > BRIDGE_MAXIMUM_DEDUPLICATION_ENTRIES) {
|
|
122
100
|
incompatible("unknown_deduplication_support", value);
|
|
@@ -144,10 +122,7 @@ export function parseBridgeCommandReply<S, D>(
|
|
|
144
122
|
const source = record(value, BRIDGE_FIELDS.BridgeCommandReply);
|
|
145
123
|
return {
|
|
146
124
|
requestId: opaqueId(source.requestId),
|
|
147
|
-
authoritativeRevision: nullable(
|
|
148
|
-
source.authoritativeRevision,
|
|
149
|
-
integer,
|
|
150
|
-
),
|
|
125
|
+
authoritativeRevision: nullable(source.authoritativeRevision, integer),
|
|
151
126
|
outcome: parseCommandOutcome(source.outcome, success, details),
|
|
152
127
|
};
|
|
153
128
|
}
|
|
@@ -187,15 +162,16 @@ function parseCommandOutcome<S, D>(
|
|
|
187
162
|
|
|
188
163
|
function variant(
|
|
189
164
|
value: unknown,
|
|
190
|
-
|
|
165
|
+
variants: ReadonlyArray<string>,
|
|
191
166
|
code: "unknown_query_outcome" | "unknown_command_outcome",
|
|
192
167
|
): Record<string, unknown> {
|
|
193
|
-
if (
|
|
168
|
+
if (!isRecord(value)) {
|
|
194
169
|
incompatible(code, value);
|
|
195
170
|
}
|
|
196
|
-
const source = value
|
|
171
|
+
const source = value;
|
|
197
172
|
const present = Object.keys(source);
|
|
198
|
-
|
|
173
|
+
const [key] = present;
|
|
174
|
+
if (present.length !== 1 || key === undefined || !variants.includes(key)) {
|
|
199
175
|
incompatible(code, value);
|
|
200
176
|
}
|
|
201
177
|
return source;
|
|
@@ -4,17 +4,10 @@ import type {
|
|
|
4
4
|
BridgeSnapshotEnvelope,
|
|
5
5
|
BridgeStreamCursor,
|
|
6
6
|
} from "../generated/protocol.ts";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
domainId,
|
|
10
|
-
integer,
|
|
11
|
-
opaqueId,
|
|
12
|
-
record,
|
|
13
|
-
} from "./base.ts";
|
|
7
|
+
import { domainId, integer, opaqueId, record } from "./base.ts";
|
|
8
|
+
import type { BridgeCodec } from "./base.ts";
|
|
14
9
|
|
|
15
|
-
export function parseBridgeStreamCursor(
|
|
16
|
-
value: unknown,
|
|
17
|
-
): BridgeStreamCursor {
|
|
10
|
+
export function parseBridgeStreamCursor(value: unknown): BridgeStreamCursor {
|
|
18
11
|
const source = record(value, BRIDGE_FIELDS.BridgeStreamCursor);
|
|
19
12
|
return {
|
|
20
13
|
sessionId: opaqueId(source.sessionId),
|
package/src/commands/client.ts
CHANGED
|
@@ -54,13 +54,9 @@ export class CommandClient {
|
|
|
54
54
|
return { catalogue, keymap, availability };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
async listen(invalidate: () => void): Promise<
|
|
57
|
+
async listen(invalidate: () => void): Promise<ReadonlyArray<CommandUnlisten>> {
|
|
58
58
|
const results = await Promise.allSettled(
|
|
59
|
-
[
|
|
60
|
-
this.#ports.catalogue,
|
|
61
|
-
this.#ports.keymap,
|
|
62
|
-
this.#ports.availability,
|
|
63
|
-
].flatMap((port) =>
|
|
59
|
+
[this.#ports.catalogue, this.#ports.keymap, this.#ports.availability].flatMap((port) =>
|
|
64
60
|
port.listen === undefined ? [] : [port.listen(invalidate)],
|
|
65
61
|
),
|
|
66
62
|
);
|
|
@@ -68,8 +64,7 @@ export class CommandClient {
|
|
|
68
64
|
result.status === "fulfilled" ? [result.value] : [],
|
|
69
65
|
);
|
|
70
66
|
const failure = results.find(
|
|
71
|
-
(result): result is PromiseRejectedResult =>
|
|
72
|
-
result.status === "rejected",
|
|
67
|
+
(result): result is PromiseRejectedResult => result.status === "rejected",
|
|
73
68
|
);
|
|
74
69
|
if (failure !== undefined) {
|
|
75
70
|
await Promise.allSettled(unlisten.map((dispose) => dispose()));
|
|
@@ -82,35 +77,35 @@ export class CommandClient {
|
|
|
82
77
|
return this.#ports.executor.execute(intent);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
async preview(
|
|
86
|
-
request: CommandKeymapPreview,
|
|
87
|
-
): Promise<CommandKeymapPreviewResult> {
|
|
80
|
+
async preview(request: CommandKeymapPreview): Promise<CommandKeymapPreviewResult> {
|
|
88
81
|
assertValidCommandKeymapPreview(request);
|
|
89
|
-
const
|
|
90
|
-
if (preview === undefined)
|
|
91
|
-
|
|
82
|
+
const keymap = this.#ports.keymap;
|
|
83
|
+
if (keymap.preview === undefined) {
|
|
84
|
+
throw new CommandKeymapReadOnlyError();
|
|
85
|
+
}
|
|
86
|
+
const result = await keymap.preview(request);
|
|
92
87
|
assertValidCommandKeymapPreviewResult(result);
|
|
93
88
|
return result;
|
|
94
89
|
}
|
|
95
90
|
|
|
96
|
-
async commit(
|
|
97
|
-
request: CommandKeymapCommit,
|
|
98
|
-
): Promise<CommandKeymapMutationResult> {
|
|
91
|
+
async commit(request: CommandKeymapCommit): Promise<CommandKeymapMutationResult> {
|
|
99
92
|
assertValidCommandKeymapCommit(request);
|
|
100
|
-
const
|
|
101
|
-
if (commit === undefined)
|
|
102
|
-
|
|
93
|
+
const keymap = this.#ports.keymap;
|
|
94
|
+
if (keymap.commit === undefined) {
|
|
95
|
+
throw new CommandKeymapReadOnlyError();
|
|
96
|
+
}
|
|
97
|
+
const result = await keymap.commit(request);
|
|
103
98
|
assertValidCommandKeymapMutationResult(result);
|
|
104
99
|
return result;
|
|
105
100
|
}
|
|
106
101
|
|
|
107
|
-
async reset(
|
|
108
|
-
request: CommandKeymapReset,
|
|
109
|
-
): Promise<CommandKeymapMutationResult> {
|
|
102
|
+
async reset(request: CommandKeymapReset): Promise<CommandKeymapMutationResult> {
|
|
110
103
|
assertValidCommandKeymapReset(request);
|
|
111
|
-
const
|
|
112
|
-
if (reset === undefined)
|
|
113
|
-
|
|
104
|
+
const keymap = this.#ports.keymap;
|
|
105
|
+
if (keymap.reset === undefined) {
|
|
106
|
+
throw new CommandKeymapReadOnlyError();
|
|
107
|
+
}
|
|
108
|
+
const result = await keymap.reset(request);
|
|
114
109
|
assertValidCommandKeymapMutationResult(result);
|
|
115
110
|
return result;
|
|
116
111
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CommandClient } from "./client.ts";
|
|
2
2
|
import type {
|
|
3
|
-
CommandArguments,
|
|
4
3
|
CommandInvocation,
|
|
5
4
|
CommandKeymapMutationResult,
|
|
6
5
|
CommandKeymapPatch,
|
|
@@ -15,13 +14,8 @@ import type {
|
|
|
15
14
|
CommandPorts,
|
|
16
15
|
CommandUnlisten,
|
|
17
16
|
} from "./ports.ts";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
projectCommandSurfaces,
|
|
21
|
-
searchCommands,
|
|
22
|
-
type CommandJoinedState,
|
|
23
|
-
type CommandSurfaceProjection,
|
|
24
|
-
} from "./projectors.ts";
|
|
17
|
+
import { joinCommandState, projectCommandSurfaces, searchCommands } from "./projectors.ts";
|
|
18
|
+
import type { CommandJoinedState, CommandSurfaceProjection } from "./projectors.ts";
|
|
25
19
|
|
|
26
20
|
export type CommandControllerStatus =
|
|
27
21
|
| { readonly kind: "idle" }
|
|
@@ -53,7 +47,7 @@ export interface CommandControllerOptions {
|
|
|
53
47
|
readonly search?: (
|
|
54
48
|
records: CommandJoinedState["catalogue"]["commands"],
|
|
55
49
|
query: string,
|
|
56
|
-
) => Promise<
|
|
50
|
+
) => Promise<ReadonlyArray<CommandSearchHit>>;
|
|
57
51
|
}
|
|
58
52
|
|
|
59
53
|
export class CommandController {
|
|
@@ -65,10 +59,10 @@ export class CommandController {
|
|
|
65
59
|
#mutation: CommandMutationStatus = { kind: "idle" };
|
|
66
60
|
#model: CommandJoinedState | undefined;
|
|
67
61
|
#projection: CommandSurfaceProjection | undefined;
|
|
68
|
-
#searchHits:
|
|
62
|
+
#searchHits: ReadonlyArray<CommandSearchHit> = [];
|
|
69
63
|
#query = "";
|
|
70
64
|
#draft: CommandKeymapPatch | undefined;
|
|
71
|
-
#unlisten: CommandUnlisten
|
|
65
|
+
#unlisten: Array<CommandUnlisten> = [];
|
|
72
66
|
#lifecycleRevision = 0;
|
|
73
67
|
#loadRevision = 0;
|
|
74
68
|
#searchRevision = 0;
|
|
@@ -77,9 +71,7 @@ export class CommandController {
|
|
|
77
71
|
constructor(options: CommandControllerOptions) {
|
|
78
72
|
this.#client = new CommandClient(options.ports);
|
|
79
73
|
this.#platform = options.platform;
|
|
80
|
-
this.#search =
|
|
81
|
-
options.search ??
|
|
82
|
-
(async (records, query) => searchCommands(records, query));
|
|
74
|
+
this.#search = options.search ?? (async (records, query) => searchCommands(records, query));
|
|
83
75
|
}
|
|
84
76
|
|
|
85
77
|
get status(): CommandControllerStatus {
|
|
@@ -102,7 +94,7 @@ export class CommandController {
|
|
|
102
94
|
return this.#query;
|
|
103
95
|
}
|
|
104
96
|
|
|
105
|
-
get searchHits():
|
|
97
|
+
get searchHits(): ReadonlyArray<CommandSearchHit> {
|
|
106
98
|
return this.#searchHits;
|
|
107
99
|
}
|
|
108
100
|
|
|
@@ -120,7 +112,9 @@ export class CommandController {
|
|
|
120
112
|
}
|
|
121
113
|
|
|
122
114
|
async start(): Promise<void> {
|
|
123
|
-
if (this.#started)
|
|
115
|
+
if (this.#started) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
124
118
|
this.#started = true;
|
|
125
119
|
const lifecycleRevision = ++this.#lifecycleRevision;
|
|
126
120
|
this.#setStatus({ kind: "loading" });
|
|
@@ -128,20 +122,14 @@ export class CommandController {
|
|
|
128
122
|
const unlisten = await this.#client.listen(() => {
|
|
129
123
|
void this.refresh();
|
|
130
124
|
});
|
|
131
|
-
if (
|
|
132
|
-
!this.#started ||
|
|
133
|
-
lifecycleRevision !== this.#lifecycleRevision
|
|
134
|
-
) {
|
|
125
|
+
if (!this.#started || lifecycleRevision !== this.#lifecycleRevision) {
|
|
135
126
|
await disposeAll(unlisten);
|
|
136
127
|
return;
|
|
137
128
|
}
|
|
138
129
|
this.#unlisten.push(...unlisten);
|
|
139
130
|
await this.refresh();
|
|
140
131
|
} catch (error) {
|
|
141
|
-
if (
|
|
142
|
-
this.#started &&
|
|
143
|
-
lifecycleRevision === this.#lifecycleRevision
|
|
144
|
-
) {
|
|
132
|
+
if (this.#started && lifecycleRevision === this.#lifecycleRevision) {
|
|
145
133
|
this.#setStatus({ kind: "failed", error });
|
|
146
134
|
}
|
|
147
135
|
}
|
|
@@ -167,7 +155,9 @@ export class CommandController {
|
|
|
167
155
|
const revision = ++this.#loadRevision;
|
|
168
156
|
try {
|
|
169
157
|
const loaded = await this.#client.load();
|
|
170
|
-
if (!this.#started || revision !== this.#loadRevision)
|
|
158
|
+
if (!this.#started || revision !== this.#loadRevision) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
171
161
|
if (loaded.keymap.status === "recovery") {
|
|
172
162
|
this.#model = undefined;
|
|
173
163
|
this.#projection = undefined;
|
|
@@ -187,11 +177,7 @@ export class CommandController {
|
|
|
187
177
|
return;
|
|
188
178
|
}
|
|
189
179
|
this.#install(
|
|
190
|
-
joinCommandState(
|
|
191
|
-
loaded.catalogue,
|
|
192
|
-
loaded.keymap.snapshot,
|
|
193
|
-
loaded.availability,
|
|
194
|
-
),
|
|
180
|
+
joinCommandState(loaded.catalogue, loaded.keymap.snapshot, loaded.availability),
|
|
195
181
|
);
|
|
196
182
|
this.#setStatus({ kind: "ready" });
|
|
197
183
|
await this.search(this.#query);
|
|
@@ -202,7 +188,7 @@ export class CommandController {
|
|
|
202
188
|
}
|
|
203
189
|
}
|
|
204
190
|
|
|
205
|
-
async search(query: string): Promise<
|
|
191
|
+
async search(query: string): Promise<ReadonlyArray<CommandSearchHit>> {
|
|
206
192
|
this.#query = query;
|
|
207
193
|
const model = this.#model;
|
|
208
194
|
const revision = ++this.#searchRevision;
|
|
@@ -260,7 +246,9 @@ export class CommandController {
|
|
|
260
246
|
async applyKeymapDraft(): Promise<boolean> {
|
|
261
247
|
const model = this.#requiredModel();
|
|
262
248
|
const patch = this.#draft;
|
|
263
|
-
if (patch === undefined)
|
|
249
|
+
if (patch === undefined) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
264
252
|
const base = model.keymap;
|
|
265
253
|
const operationRevision = ++this.#loadRevision;
|
|
266
254
|
this.#mutation = { kind: "previewing" };
|
|
@@ -322,7 +310,9 @@ export class CommandController {
|
|
|
322
310
|
activePresetId: base.state.activePresetId,
|
|
323
311
|
activePresetVersion: base.activePresetVersion,
|
|
324
312
|
});
|
|
325
|
-
if (operationRevision !== this.#loadRevision)
|
|
313
|
+
if (operationRevision !== this.#loadRevision) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
326
316
|
return this.#finishMutation(result);
|
|
327
317
|
} catch (error) {
|
|
328
318
|
if (operationRevision === this.#loadRevision) {
|
|
@@ -344,9 +334,7 @@ export class CommandController {
|
|
|
344
334
|
this.#mutation = {
|
|
345
335
|
kind: "conflict",
|
|
346
336
|
detail:
|
|
347
|
-
result.status === "rejected"
|
|
348
|
-
? result.rejection.detail
|
|
349
|
-
: "Keybindings changed elsewhere",
|
|
337
|
+
result.status === "rejected" ? result.rejection.detail : "Keybindings changed elsewhere",
|
|
350
338
|
};
|
|
351
339
|
this.#notify();
|
|
352
340
|
return false;
|
|
@@ -358,22 +346,17 @@ export class CommandController {
|
|
|
358
346
|
void this.refresh();
|
|
359
347
|
return;
|
|
360
348
|
}
|
|
361
|
-
this.#install(
|
|
362
|
-
joinCommandState(model.catalogue, snapshot, model.availability),
|
|
363
|
-
);
|
|
349
|
+
this.#install(joinCommandState(model.catalogue, snapshot, model.availability));
|
|
364
350
|
}
|
|
365
351
|
|
|
366
352
|
#install(model: CommandJoinedState): void {
|
|
367
353
|
const current = this.#model;
|
|
368
354
|
if (
|
|
369
355
|
current !== undefined &&
|
|
370
|
-
(model.catalogue.registryGeneration <
|
|
371
|
-
current.catalogue.registryGeneration
|
|
372
|
-
(model.catalogue.registryGeneration ===
|
|
373
|
-
current.catalogue.registryGeneration &&
|
|
356
|
+
(model.catalogue.registryGeneration < current.catalogue.registryGeneration ||
|
|
357
|
+
(model.catalogue.registryGeneration === current.catalogue.registryGeneration &&
|
|
374
358
|
(model.keymap.state.revision < current.keymap.state.revision ||
|
|
375
|
-
model.availability.contextRevision <
|
|
376
|
-
current.availability.contextRevision)))
|
|
359
|
+
model.availability.contextRevision < current.availability.contextRevision)))
|
|
377
360
|
) {
|
|
378
361
|
return;
|
|
379
362
|
}
|
|
@@ -395,7 +378,9 @@ export class CommandController {
|
|
|
395
378
|
}
|
|
396
379
|
|
|
397
380
|
#notify(): void {
|
|
398
|
-
for (const observer of this.#observers)
|
|
381
|
+
for (const observer of this.#observers) {
|
|
382
|
+
observer();
|
|
383
|
+
}
|
|
399
384
|
}
|
|
400
385
|
}
|
|
401
386
|
|
|
@@ -406,6 +391,6 @@ export class CommandControllerUnavailableError extends Error {
|
|
|
406
391
|
}
|
|
407
392
|
}
|
|
408
393
|
|
|
409
|
-
async function disposeAll(unlisten:
|
|
394
|
+
async function disposeAll(unlisten: ReadonlyArray<CommandUnlisten>): Promise<void> {
|
|
410
395
|
await Promise.allSettled(unlisten.map((dispose) => dispose()));
|
|
411
396
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
5
5
|
|
|
6
|
-
export const COMMANDS_FIELDS
|
|
6
|
+
export const COMMANDS_FIELDS = {
|
|
7
7
|
"CommandArgumentField": ["id", "required", "default", "kind"],
|
|
8
8
|
"CommandVisibility": ["hidden", "palette", "menu", "shortcut", "settings", "help"],
|
|
9
9
|
"CommandDiscoveryRecord": ["id", "label", "description", "categoryPath", "keywords", "icon", "visibility", "textInputPolicy", "arguments"],
|
|
@@ -40,4 +40,5 @@ export const COMMANDS_FIELDS: Record<string, readonly string[]> = {
|
|
|
40
40
|
"CommandKeymapRejection": ["code", "detail"],
|
|
41
41
|
"CommandKeymapRecovery": ["code", "detail", "sourcePreserved"],
|
|
42
42
|
"CommandKeymapMutationReceipt": ["requestId", "previousRevision", "committedRevision", "outcome", "durability", "patchDigest"],
|
|
43
|
-
|
|
43
|
+
"CommandHostError": ["code", "message", "retryable"],
|
|
44
|
+
} as const;
|
|
@@ -874,3 +874,7 @@ snapshot: CommandKeymapSnapshot,
|
|
|
874
874
|
* Proposed conflicts when available.
|
|
875
875
|
*/
|
|
876
876
|
conflicts: Array<CommandKeymapConflict>, };
|
|
877
|
+
|
|
878
|
+
export type CommandHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
|
|
879
|
+
|
|
880
|
+
export type CommandHostError = { "code": CommandHostErrorCode, "message": string, "retryable": boolean, };
|