@inflatable-cookie/longhorn 0.5.0 → 0.7.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/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- 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 +78 -109
- 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 +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CheckedSnapshotConnection, CheckedSubscription } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type {
|
|
3
|
+
ConnectionFailure,
|
|
4
|
+
ConnectionFailureReporter,
|
|
5
|
+
EventTransport,
|
|
6
6
|
} from "@inflatable-cookie/longhorn/core";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
SettingsLoadCommand,
|
|
10
10
|
SettingsLoadOutcome,
|
|
11
|
-
|
|
11
|
+
SettingsPageId,
|
|
12
12
|
SettingsRegistrySnapshot,
|
|
13
13
|
SettingsRequestId,
|
|
14
|
-
SettingsScopeChangedEvent,
|
|
15
14
|
SettingsScopeId,
|
|
16
15
|
SettingsScopeSnapshot,
|
|
17
16
|
} from "./generated/protocol.ts";
|
|
17
|
+
import { SETTINGS_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
18
18
|
import {
|
|
19
19
|
assertValidSettingsRegistryChangedEvent,
|
|
20
20
|
assertValidSettingsRegistrySnapshot,
|
|
21
21
|
assertValidSettingsScopeChangedEvent,
|
|
22
22
|
assertValidSettingsScopeSnapshot,
|
|
23
23
|
} from "./validation.ts";
|
|
24
|
-
import {
|
|
25
|
-
SETTINGS_REGISTRY_CHANGED_EVENT,
|
|
26
|
-
SETTINGS_SCOPE_CHANGED_EVENT,
|
|
27
|
-
} from "./names.ts";
|
|
24
|
+
import { SETTINGS_REGISTRY_CHANGED_EVENT, SETTINGS_SCOPE_CHANGED_EVENT } from "./names.ts";
|
|
28
25
|
|
|
29
26
|
export interface SettingsSubscription<Snapshot> {
|
|
30
27
|
readonly ready: Promise<Snapshot>;
|
|
31
28
|
current(): Snapshot | undefined;
|
|
32
|
-
failures():
|
|
29
|
+
failures(): ReadonlyArray<ConnectionFailure>;
|
|
33
30
|
dispose(): Promise<void>;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
export interface SettingsScopeConnectionOptions {
|
|
37
34
|
readonly registry: SettingsRegistrySnapshot;
|
|
35
|
+
readonly pageId: SettingsPageId;
|
|
38
36
|
readonly scopeId: SettingsScopeId;
|
|
39
37
|
readonly nextRequestId: () => SettingsRequestId;
|
|
40
38
|
readonly onSnapshot?: (snapshot: SettingsScopeSnapshot) => void;
|
|
@@ -49,16 +47,14 @@ export function connectSettingsRegistry(
|
|
|
49
47
|
): SettingsSubscription<SettingsRegistrySnapshot> {
|
|
50
48
|
return requiredSubscription(
|
|
51
49
|
new CheckedSnapshotConnection({
|
|
52
|
-
listen: (receive) =>
|
|
53
|
-
transport.listen(SETTINGS_REGISTRY_CHANGED_EVENT, receive),
|
|
50
|
+
listen: (receive) => transport.listen(SETTINGS_REGISTRY_CHANGED_EVENT, receive),
|
|
54
51
|
loadSnapshot: load,
|
|
55
52
|
validateSnapshot: parseRegistry,
|
|
56
53
|
handleEvent: registryEventAction,
|
|
57
54
|
isNewer: isNewerRegistry,
|
|
58
55
|
onSnapshot: listener,
|
|
59
56
|
onFailure,
|
|
60
|
-
disposedBeforeReadyError: () =>
|
|
61
|
-
new SettingsConnectionDisposedError("registry"),
|
|
57
|
+
disposedBeforeReadyError: () => new SettingsConnectionDisposedError("registry"),
|
|
62
58
|
}),
|
|
63
59
|
"registry",
|
|
64
60
|
);
|
|
@@ -72,13 +68,13 @@ export function connectSettingsScope(
|
|
|
72
68
|
let current: SettingsScopeSnapshot | undefined;
|
|
73
69
|
const maximum = options.registry.limits.maximumOpaqueValueBytes;
|
|
74
70
|
const connection = new CheckedSnapshotConnection<SettingsScopeSnapshot>({
|
|
75
|
-
listen: (receive) =>
|
|
76
|
-
transport.listen(SETTINGS_SCOPE_CHANGED_EVENT, receive),
|
|
71
|
+
listen: (receive) => transport.listen(SETTINGS_SCOPE_CHANGED_EVENT, receive),
|
|
77
72
|
loadSnapshot: async () => {
|
|
78
73
|
const outcome = await load({
|
|
79
|
-
protocolVersion:
|
|
74
|
+
protocolVersion: SETTINGS_PROTOCOL_VERSION,
|
|
80
75
|
requestId: options.nextRequestId(),
|
|
81
76
|
registryGeneration: options.registry.generation,
|
|
77
|
+
pageId: options.pageId,
|
|
82
78
|
scopeId: options.scopeId,
|
|
83
79
|
knownAuthority: current?.authority ?? null,
|
|
84
80
|
});
|
|
@@ -92,19 +88,16 @@ export function connectSettingsScope(
|
|
|
92
88
|
validateScopeIdentity(value, options);
|
|
93
89
|
return value;
|
|
94
90
|
},
|
|
95
|
-
handleEvent: (value, snapshot) =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return accepted;
|
|
91
|
+
handleEvent: (value, snapshot) => scopeEventAction(value, snapshot, options),
|
|
92
|
+
isNewer: isNewerScope,
|
|
93
|
+
// Recorded here, once the connection has accepted the snapshot, so the
|
|
94
|
+
// predicate itself stays a pure comparison.
|
|
95
|
+
onSnapshot: (snapshot) => {
|
|
96
|
+
current = snapshot;
|
|
97
|
+
options.onSnapshot?.(snapshot);
|
|
103
98
|
},
|
|
104
|
-
onSnapshot: options.onSnapshot,
|
|
105
99
|
onFailure: options.onFailure,
|
|
106
|
-
disposedBeforeReadyError: () =>
|
|
107
|
-
new SettingsConnectionDisposedError(options.scopeId),
|
|
100
|
+
disposedBeforeReadyError: () => new SettingsConnectionDisposedError(options.scopeId),
|
|
108
101
|
});
|
|
109
102
|
return requiredSubscription(connection, options.scopeId);
|
|
110
103
|
}
|
|
@@ -137,17 +130,12 @@ function requiredSubscription<Snapshot>(
|
|
|
137
130
|
connection: CheckedSnapshotConnection<Snapshot>,
|
|
138
131
|
target: string,
|
|
139
132
|
): SettingsSubscription<Snapshot> {
|
|
140
|
-
return {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}),
|
|
147
|
-
current: () => connection.current(),
|
|
148
|
-
failures: () => connection.failures(),
|
|
149
|
-
dispose: () => connection.dispose(),
|
|
150
|
-
};
|
|
133
|
+
return new CheckedSubscription(connection, (snapshot) => {
|
|
134
|
+
if (snapshot === undefined) {
|
|
135
|
+
throw new SettingsConnectionDisposedError(target);
|
|
136
|
+
}
|
|
137
|
+
return snapshot;
|
|
138
|
+
});
|
|
151
139
|
}
|
|
152
140
|
|
|
153
141
|
function parseRegistry(value: unknown): SettingsRegistrySnapshot {
|
|
@@ -160,9 +148,8 @@ function registryEventAction(
|
|
|
160
148
|
current: SettingsRegistrySnapshot | undefined,
|
|
161
149
|
): { kind: "ignore" } | { kind: "refresh" } {
|
|
162
150
|
assertValidSettingsRegistryChangedEvent(value);
|
|
163
|
-
const event = value
|
|
164
|
-
return current !== undefined &&
|
|
165
|
-
event.registryGeneration <= current.generation
|
|
151
|
+
const event = value;
|
|
152
|
+
return current !== undefined && event.registryGeneration <= current.generation
|
|
166
153
|
? { kind: "ignore" }
|
|
167
154
|
: { kind: "refresh" };
|
|
168
155
|
}
|
|
@@ -173,7 +160,7 @@ function scopeEventAction(
|
|
|
173
160
|
options: SettingsScopeConnectionOptions,
|
|
174
161
|
): { kind: "ignore" } | { kind: "refresh" } {
|
|
175
162
|
assertValidSettingsScopeChangedEvent(value);
|
|
176
|
-
const event = value
|
|
163
|
+
const event = value;
|
|
177
164
|
if (event.scopeId !== options.scopeId) {
|
|
178
165
|
return { kind: "ignore" };
|
|
179
166
|
}
|
|
@@ -193,10 +180,7 @@ function isNewerRegistry(
|
|
|
193
180
|
if (current === undefined || candidate.generation > current.generation) {
|
|
194
181
|
return true;
|
|
195
182
|
}
|
|
196
|
-
if (
|
|
197
|
-
candidate.generation === current.generation &&
|
|
198
|
-
candidate.digest !== current.digest
|
|
199
|
-
) {
|
|
183
|
+
if (candidate.generation === current.generation && candidate.digest !== current.digest) {
|
|
200
184
|
throw new SettingsAuthorityConsistencyError(
|
|
201
185
|
"one settings registry generation produced multiple digests",
|
|
202
186
|
);
|
|
@@ -204,7 +188,7 @@ function isNewerRegistry(
|
|
|
204
188
|
return false;
|
|
205
189
|
}
|
|
206
190
|
|
|
207
|
-
function isNewerScope(
|
|
191
|
+
export function isNewerScope(
|
|
208
192
|
candidate: SettingsScopeSnapshot,
|
|
209
193
|
current: SettingsScopeSnapshot | undefined,
|
|
210
194
|
): boolean {
|
|
@@ -236,9 +220,7 @@ function validateScopeIdentity(
|
|
|
236
220
|
`loaded scope ${snapshot.scopeId}; expected ${options.scopeId}`,
|
|
237
221
|
);
|
|
238
222
|
}
|
|
239
|
-
if (
|
|
240
|
-
snapshot.authority.registryGeneration !== options.registry.generation
|
|
241
|
-
) {
|
|
223
|
+
if (snapshot.authority.registryGeneration !== options.registry.generation) {
|
|
242
224
|
throw new SettingsAuthorityConsistencyError(
|
|
243
225
|
"scope snapshot registry generation does not match the connection",
|
|
244
226
|
);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per protocol type, from the Rust structs.
|
|
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 SETTINGS_FIELDS
|
|
6
|
+
export const SETTINGS_FIELDS = {
|
|
7
7
|
"SettingsLimits": ["maximumModules", "maximumSections", "maximumPages", "maximumRenderers", "maximumScopes", "maximumApplyUnits", "maximumCapabilities", "maximumAnchorsPerPage", "maximumKeywordsPerPage", "maximumLabelBytes", "maximumKeywordBytes", "maximumOpaqueValueBytes"],
|
|
8
8
|
"SettingsOpaqueValue": ["codecVersion", "value"],
|
|
9
9
|
"SettingsModuleDefinition": ["id", "label", "order"],
|
|
@@ -25,10 +25,11 @@ export const SETTINGS_FIELDS: Record<string, readonly string[]> = {
|
|
|
25
25
|
"SettingsRegistrySnapshot": ["protocolVersion", "generation", "digest", "limits", "composedCapabilities", "modules", "sections", "pages", "renderers", "scopes", "applyUnits", "capabilities"],
|
|
26
26
|
"SettingsRegistryChangedEvent": ["protocolVersion", "registryGeneration"],
|
|
27
27
|
"SettingsScopeChangedEvent": ["protocolVersion", "registryGeneration", "scopeId", "scopeRevision"],
|
|
28
|
-
"SettingsLoadCommand": ["protocolVersion", "requestId", "registryGeneration", "scopeId", "knownAuthority"],
|
|
28
|
+
"SettingsLoadCommand": ["protocolVersion", "requestId", "registryGeneration", "pageId", "scopeId", "knownAuthority"],
|
|
29
29
|
"SettingsApplyCommand": ["protocolVersion", "requestId", "pageId", "applyUnitId", "scopeId", "authority", "intent"],
|
|
30
30
|
"SettingsResetCommand": ["protocolVersion", "requestId", "pageId", "applyUnitId", "scopeId", "authority", "entryIds"],
|
|
31
31
|
"SettingsMutationReceipt": ["requestId", "pageId", "applyUnitId", "scopeId", "previousAuthority", "committedAuthority", "outcome", "durability", "activationRequirements"],
|
|
32
32
|
"SettingsConflict": ["expected", "actual"],
|
|
33
33
|
"SettingsRejection": ["code", "diagnostic"],
|
|
34
|
-
|
|
34
|
+
"SettingsHostError": ["code", "message", "retryable"],
|
|
35
|
+
} as const;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority.
|
|
3
3
|
|
|
4
4
|
export const SETTINGS_PROTOCOL_VERSION = 1 as const;
|
|
@@ -487,19 +487,24 @@ export type SettingsLoadCommand = {
|
|
|
487
487
|
*/
|
|
488
488
|
protocolVersion: SettingsProtocolVersion,
|
|
489
489
|
/**
|
|
490
|
-
*
|
|
490
|
+
* Correlation identity. Reusing it does not deduplicate commands.
|
|
491
491
|
*/
|
|
492
492
|
requestId: SettingsRequestId,
|
|
493
493
|
/**
|
|
494
494
|
* Registry generation expected by the client.
|
|
495
495
|
*/
|
|
496
496
|
registryGeneration: SettingsRegistryGeneration,
|
|
497
|
+
/**
|
|
498
|
+
* Admitted page requesting access to the scope.
|
|
499
|
+
*/
|
|
500
|
+
pageId: SettingsPageId,
|
|
497
501
|
/**
|
|
498
502
|
* Scope to project.
|
|
499
503
|
*/
|
|
500
504
|
scopeId: SettingsScopeId,
|
|
501
505
|
/**
|
|
502
|
-
* Previously checked authority
|
|
506
|
+
* Previously checked authority, if available. An advisory hint only.
|
|
507
|
+
* A successful load still returns a complete snapshot.
|
|
503
508
|
*/
|
|
504
509
|
knownAuthority: SettingsAuthorityExpectation | null, };
|
|
505
510
|
|
|
@@ -509,7 +514,7 @@ export type SettingsApplyCommand = {
|
|
|
509
514
|
*/
|
|
510
515
|
protocolVersion: SettingsProtocolVersion,
|
|
511
516
|
/**
|
|
512
|
-
*
|
|
517
|
+
* Correlation identity. Reusing it does not deduplicate commands.
|
|
513
518
|
*/
|
|
514
519
|
requestId: SettingsRequestId,
|
|
515
520
|
/**
|
|
@@ -539,7 +544,7 @@ export type SettingsResetCommand = {
|
|
|
539
544
|
*/
|
|
540
545
|
protocolVersion: SettingsProtocolVersion,
|
|
541
546
|
/**
|
|
542
|
-
*
|
|
547
|
+
* Correlation identity. Reusing it does not deduplicate commands.
|
|
543
548
|
*/
|
|
544
549
|
requestId: SettingsRequestId,
|
|
545
550
|
/**
|
|
@@ -666,3 +671,7 @@ snapshot: SettingsScopeSnapshot, } | { "status": "rejected",
|
|
|
666
671
|
* Typed rejection.
|
|
667
672
|
*/
|
|
668
673
|
rejection: SettingsRejection, };
|
|
674
|
+
|
|
675
|
+
export type SettingsHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
|
|
676
|
+
|
|
677
|
+
export type SettingsHostError = { "code": SettingsHostErrorCode, "message": string, "retryable": boolean, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
3
|
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
4
|
// each list, because `exact()` compares every key.
|
package/src/settings/names.ts
CHANGED
|
@@ -2,7 +2,5 @@ export const SETTINGS_REGISTRY_COMMAND = "longhorn_settings_registry";
|
|
|
2
2
|
export const SETTINGS_LOAD_COMMAND = "longhorn_settings_load";
|
|
3
3
|
export const SETTINGS_APPLY_COMMAND = "longhorn_settings_apply";
|
|
4
4
|
export const SETTINGS_RESET_COMMAND = "longhorn_settings_reset";
|
|
5
|
-
export const SETTINGS_REGISTRY_CHANGED_EVENT =
|
|
6
|
-
|
|
7
|
-
export const SETTINGS_SCOPE_CHANGED_EVENT =
|
|
8
|
-
"longhorn://settings/scope-changed";
|
|
5
|
+
export const SETTINGS_REGISTRY_CHANGED_EVENT = "longhorn://settings/registry-changed";
|
|
6
|
+
export const SETTINGS_SCOPE_CHANGED_EVENT = "longhorn://settings/scope-changed";
|
package/src/settings/registry.ts
CHANGED
|
@@ -10,18 +10,18 @@ import type {
|
|
|
10
10
|
|
|
11
11
|
export interface SettingsNavigationModule {
|
|
12
12
|
readonly module: SettingsModuleDefinition;
|
|
13
|
-
readonly sections:
|
|
13
|
+
readonly sections: ReadonlyArray<SettingsNavigationSection>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface SettingsNavigationSection {
|
|
17
17
|
readonly section: SettingsSectionDefinition;
|
|
18
|
-
readonly pages:
|
|
18
|
+
readonly pages: ReadonlyArray<SettingsPageDefinition>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface SettingsRegistryProjection {
|
|
22
22
|
readonly generation: number;
|
|
23
|
-
readonly modules:
|
|
24
|
-
readonly pages:
|
|
23
|
+
readonly modules: ReadonlyArray<SettingsNavigationModule>;
|
|
24
|
+
readonly pages: ReadonlyArray<SettingsPageDefinition>;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface SettingsDeepLink {
|
|
@@ -55,13 +55,13 @@ export class SettingsDeepLinkResolutionError extends Error {
|
|
|
55
55
|
export function projectSettingsRegistry(
|
|
56
56
|
registry: SettingsRegistrySnapshot,
|
|
57
57
|
): SettingsRegistryProjection {
|
|
58
|
-
const pagesBySection = new Map<string, SettingsPageDefinition
|
|
58
|
+
const pagesBySection = new Map<string, Array<SettingsPageDefinition>>();
|
|
59
59
|
for (const page of registry.pages) {
|
|
60
60
|
const pages = pagesBySection.get(page.sectionId) ?? [];
|
|
61
61
|
pages.push(page);
|
|
62
62
|
pagesBySection.set(page.sectionId, pages);
|
|
63
63
|
}
|
|
64
|
-
const sectionsByModule = new Map<string, SettingsNavigationSection
|
|
64
|
+
const sectionsByModule = new Map<string, Array<SettingsNavigationSection>>();
|
|
65
65
|
for (const section of registry.sections) {
|
|
66
66
|
const pages = pagesBySection.get(section.id) ?? [];
|
|
67
67
|
if (pages.length === 0) {
|
|
@@ -82,27 +82,34 @@ export function projectSettingsRegistry(
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Case folding for search, supplied by the host. This is the TypeScript
|
|
87
|
+
* counterpart of Rust's `HostServices::fold_case`: the host names the locale,
|
|
88
|
+
* and nothing in search guesses one. Used for matching only, never for display.
|
|
89
|
+
*/
|
|
90
|
+
export interface SettingsSearchHostServices {
|
|
91
|
+
foldCase(value: string): string;
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
export function searchSettingsRegistry(
|
|
86
95
|
registry: SettingsRegistrySnapshot,
|
|
87
96
|
query: string,
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
services: SettingsSearchHostServices,
|
|
98
|
+
): ReadonlyArray<SettingsSearchResult> {
|
|
99
|
+
const needle = services.foldCase(query.trim());
|
|
90
100
|
if (needle.length === 0) {
|
|
91
101
|
return [];
|
|
92
102
|
}
|
|
93
|
-
const results: SettingsSearchResult
|
|
103
|
+
const results: Array<SettingsSearchResult> = [];
|
|
94
104
|
for (const page of registry.pages) {
|
|
95
105
|
const pageMatch = [page.label, ...page.keywords]
|
|
96
|
-
.map(
|
|
106
|
+
.map((value) => services.foldCase(value))
|
|
97
107
|
.some((value) => value.includes(needle));
|
|
98
108
|
if (pageMatch) {
|
|
99
109
|
results.push({ kind: "page", page, anchor: undefined });
|
|
100
110
|
}
|
|
101
111
|
for (const anchor of page.anchors) {
|
|
102
|
-
if (
|
|
103
|
-
anchor.label !== null &&
|
|
104
|
-
normalize(anchor.label).includes(needle)
|
|
105
|
-
) {
|
|
112
|
+
if (anchor.label !== null && services.foldCase(anchor.label).includes(needle)) {
|
|
106
113
|
results.push({ kind: "anchor", page, anchor });
|
|
107
114
|
}
|
|
108
115
|
}
|
|
@@ -116,17 +123,12 @@ export function resolveSettingsDeepLink(
|
|
|
116
123
|
): ResolvedSettingsDeepLink {
|
|
117
124
|
const page = registry.pages.find((candidate) => candidate.id === link.pageId);
|
|
118
125
|
if (page === undefined) {
|
|
119
|
-
throw new SettingsDeepLinkResolutionError(
|
|
120
|
-
`unknown settings page ${link.pageId}`,
|
|
121
|
-
link,
|
|
122
|
-
);
|
|
126
|
+
throw new SettingsDeepLinkResolutionError(`unknown settings page ${link.pageId}`, link);
|
|
123
127
|
}
|
|
124
128
|
if (link.anchorId === undefined) {
|
|
125
129
|
return { page, anchor: undefined };
|
|
126
130
|
}
|
|
127
|
-
const anchor = page.anchors.find(
|
|
128
|
-
(candidate) => candidate.id === link.anchorId,
|
|
129
|
-
);
|
|
131
|
+
const anchor = page.anchors.find((candidate) => candidate.id === link.anchorId);
|
|
130
132
|
if (anchor === undefined) {
|
|
131
133
|
throw new SettingsDeepLinkResolutionError(
|
|
132
134
|
`unknown settings anchor ${link.anchorId} on ${link.pageId}`,
|
|
@@ -135,7 +137,3 @@ export function resolveSettingsDeepLink(
|
|
|
135
137
|
}
|
|
136
138
|
return { page, anchor };
|
|
137
139
|
}
|
|
138
|
-
|
|
139
|
-
function normalize(value: string): string {
|
|
140
|
-
return value.trim().toLocaleLowerCase("en-US");
|
|
141
|
-
}
|
|
@@ -3,20 +3,17 @@ import {
|
|
|
3
3
|
SETTINGS_ACTIVATION_STATES,
|
|
4
4
|
SETTINGS_EDITABILITIES,
|
|
5
5
|
SETTINGS_EFFECTIVE_SOURCES,
|
|
6
|
+
SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
6
7
|
SETTINGS_HARD_MAXIMUM_TEXT_BYTES,
|
|
7
8
|
SETTINGS_POLICY_EFFECTS,
|
|
8
9
|
SETTINGS_RECOVERY_CODES,
|
|
9
|
-
type SettingsScopeSnapshot,
|
|
10
10
|
} from "../generated/protocol.ts";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
recovery,
|
|
15
|
-
} from "./projection.ts";
|
|
11
|
+
import type { SettingsScopeSnapshot } from "../generated/protocol.ts";
|
|
12
|
+
import { incompatible } from "./error.ts";
|
|
13
|
+
import { activation, hasPolicyOverride, recovery } from "./projection.ts";
|
|
16
14
|
import {
|
|
17
15
|
array,
|
|
18
16
|
authority,
|
|
19
|
-
HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
20
17
|
identity,
|
|
21
18
|
known,
|
|
22
19
|
opaque,
|
|
@@ -28,26 +25,35 @@ import {
|
|
|
28
25
|
|
|
29
26
|
export function assertValidSettingsScopeSnapshot(
|
|
30
27
|
value: unknown,
|
|
31
|
-
maximumOpaqueValueBytes =
|
|
28
|
+
maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
32
29
|
): asserts value is SettingsScopeSnapshot {
|
|
33
30
|
const snapshot = record(value, SETTINGS_FIELDS.SettingsScopeSnapshot);
|
|
34
31
|
protocolVersion(snapshot.protocolVersion);
|
|
35
32
|
identity(snapshot.scopeId);
|
|
36
33
|
authority(snapshot.authority);
|
|
34
|
+
const entries = new Set<string>();
|
|
37
35
|
array(snapshot.values).forEach((value) => {
|
|
38
36
|
const projection = record(value, SETTINGS_FIELDS.SettingsValueProjection);
|
|
39
37
|
identity(projection.entryId);
|
|
38
|
+
if (entries.has(projection.entryId)) {
|
|
39
|
+
incompatible("invalid_shape", projection.entryId);
|
|
40
|
+
}
|
|
41
|
+
entries.add(projection.entryId);
|
|
40
42
|
optionalOpaque(projection.configured, maximumOpaqueValueBytes);
|
|
41
43
|
opaque(projection.effective, maximumOpaqueValueBytes);
|
|
42
44
|
opaque(projection.compiledDefault, maximumOpaqueValueBytes);
|
|
43
45
|
known(projection.effectiveSource, SETTINGS_EFFECTIVE_SOURCES);
|
|
44
46
|
known(projection.editability, SETTINGS_EDITABILITIES);
|
|
45
|
-
|
|
46
|
-
policy
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
const hasOverride =
|
|
48
|
+
projection.policy !== null &&
|
|
49
|
+
hasPolicyOverride(projection.policy, maximumOpaqueValueBytes, SETTINGS_POLICY_EFFECTS);
|
|
50
|
+
const managed = projection.effectiveSource === "managedPolicy";
|
|
51
|
+
if (
|
|
52
|
+
hasOverride !== managed ||
|
|
53
|
+
(managed && projection.editability === "editable") ||
|
|
54
|
+
(projection.effectiveSource === "userConfiguration" && projection.configured === null)
|
|
55
|
+
) {
|
|
56
|
+
incompatible("invalid_shape", projection);
|
|
51
57
|
}
|
|
52
58
|
array(projection.sourceDiagnostics).forEach((value) => {
|
|
53
59
|
const diagnostic = record(value, SETTINGS_FIELDS.SettingsSourceDiagnostic);
|
|
@@ -56,11 +62,7 @@ export function assertValidSettingsScopeSnapshot(
|
|
|
56
62
|
});
|
|
57
63
|
});
|
|
58
64
|
if (snapshot.recovery !== null) {
|
|
59
|
-
recovery(
|
|
60
|
-
snapshot.recovery,
|
|
61
|
-
maximumOpaqueValueBytes,
|
|
62
|
-
SETTINGS_RECOVERY_CODES,
|
|
63
|
-
);
|
|
65
|
+
recovery(snapshot.recovery, maximumOpaqueValueBytes, SETTINGS_RECOVERY_CODES);
|
|
64
66
|
}
|
|
65
67
|
activation(snapshot.activationRequirements, SETTINGS_ACTIVATION_STATES);
|
|
66
68
|
}
|
|
@@ -2,24 +2,26 @@ import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
|
2
2
|
import {
|
|
3
3
|
SETTINGS_ACTIVATION_STATES,
|
|
4
4
|
SETTINGS_DURABILITY_KINDS,
|
|
5
|
+
SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
5
6
|
SETTINGS_LOAD_OUTCOME_STATUSES,
|
|
6
7
|
SETTINGS_MUTATION_OUTCOMES,
|
|
7
8
|
SETTINGS_MUTATION_RESULT_STATUSES,
|
|
8
9
|
SETTINGS_REJECTION_CODES,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
} from "../generated/protocol.ts";
|
|
11
|
+
import type {
|
|
12
|
+
SettingsApplyCommand,
|
|
13
|
+
SettingsLoadCommand,
|
|
14
|
+
SettingsLoadOutcome,
|
|
15
|
+
SettingsMutationResult,
|
|
16
|
+
SettingsRegistryChangedEvent,
|
|
17
|
+
SettingsResetCommand,
|
|
18
|
+
SettingsScopeChangedEvent,
|
|
16
19
|
} from "../generated/protocol.ts";
|
|
17
20
|
import { assertValidSettingsScopeSnapshot } from "./authority.ts";
|
|
18
21
|
import { activation, rejection } from "./projection.ts";
|
|
19
22
|
import {
|
|
20
23
|
array,
|
|
21
24
|
authority,
|
|
22
|
-
HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
23
25
|
identity,
|
|
24
26
|
known,
|
|
25
27
|
opaque,
|
|
@@ -37,6 +39,7 @@ export function assertValidSettingsLoadCommand(
|
|
|
37
39
|
protocolVersion(command.protocolVersion);
|
|
38
40
|
identity(command.requestId);
|
|
39
41
|
unsigned(command.registryGeneration, "invalid_revision");
|
|
42
|
+
identity(command.pageId);
|
|
40
43
|
identity(command.scopeId);
|
|
41
44
|
if (command.knownAuthority !== null) {
|
|
42
45
|
authority(command.knownAuthority);
|
|
@@ -45,7 +48,7 @@ export function assertValidSettingsLoadCommand(
|
|
|
45
48
|
|
|
46
49
|
export function assertValidSettingsApplyCommand(
|
|
47
50
|
value: unknown,
|
|
48
|
-
maximumOpaqueValueBytes =
|
|
51
|
+
maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
49
52
|
): asserts value is SettingsApplyCommand {
|
|
50
53
|
const command = mutationCommand(value, SETTINGS_FIELDS.SettingsApplyCommand);
|
|
51
54
|
opaque(command.intent, maximumOpaqueValueBytes);
|
|
@@ -60,57 +63,37 @@ export function assertValidSettingsResetCommand(
|
|
|
60
63
|
|
|
61
64
|
export function assertValidSettingsLoadOutcome(
|
|
62
65
|
value: unknown,
|
|
63
|
-
maximumOpaqueValueBytes =
|
|
66
|
+
maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
64
67
|
): asserts value is SettingsLoadOutcome {
|
|
65
68
|
const outcome = record(value);
|
|
66
69
|
known(outcome.status, SETTINGS_LOAD_OUTCOME_STATUSES);
|
|
67
70
|
record(outcome, variantKeys("SettingsLoadOutcome", outcome));
|
|
68
71
|
if (outcome.status === "loaded") {
|
|
69
|
-
assertValidSettingsScopeSnapshot(
|
|
70
|
-
outcome.snapshot,
|
|
71
|
-
maximumOpaqueValueBytes,
|
|
72
|
-
);
|
|
72
|
+
assertValidSettingsScopeSnapshot(outcome.snapshot, maximumOpaqueValueBytes);
|
|
73
73
|
} else {
|
|
74
|
-
rejection(
|
|
75
|
-
outcome.rejection,
|
|
76
|
-
maximumOpaqueValueBytes,
|
|
77
|
-
SETTINGS_REJECTION_CODES,
|
|
78
|
-
);
|
|
74
|
+
rejection(outcome.rejection, maximumOpaqueValueBytes, SETTINGS_REJECTION_CODES);
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
export function assertValidSettingsMutationResult(
|
|
83
79
|
value: unknown,
|
|
84
|
-
maximumOpaqueValueBytes =
|
|
80
|
+
maximumOpaqueValueBytes: number = SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
85
81
|
): asserts value is SettingsMutationResult {
|
|
86
82
|
const result = record(value);
|
|
87
83
|
known(result.status, SETTINGS_MUTATION_RESULT_STATUSES);
|
|
88
84
|
record(result, variantKeys("SettingsMutationResult", result));
|
|
89
85
|
if (result.status === "applied") {
|
|
90
|
-
assertValidSettingsScopeSnapshot(
|
|
91
|
-
result.snapshot,
|
|
92
|
-
maximumOpaqueValueBytes,
|
|
93
|
-
);
|
|
86
|
+
assertValidSettingsScopeSnapshot(result.snapshot, maximumOpaqueValueBytes);
|
|
94
87
|
receipt(result.receipt, maximumOpaqueValueBytes);
|
|
95
88
|
} else if (result.status === "conflict") {
|
|
96
89
|
const conflict = record(result.conflict, SETTINGS_FIELDS.SettingsConflict);
|
|
97
90
|
authority(conflict.expected);
|
|
98
91
|
authority(conflict.actual);
|
|
99
|
-
assertValidSettingsScopeSnapshot(
|
|
100
|
-
result.snapshot,
|
|
101
|
-
maximumOpaqueValueBytes,
|
|
102
|
-
);
|
|
92
|
+
assertValidSettingsScopeSnapshot(result.snapshot, maximumOpaqueValueBytes);
|
|
103
93
|
} else {
|
|
104
|
-
rejection(
|
|
105
|
-
result.rejection,
|
|
106
|
-
maximumOpaqueValueBytes,
|
|
107
|
-
SETTINGS_REJECTION_CODES,
|
|
108
|
-
);
|
|
94
|
+
rejection(result.rejection, maximumOpaqueValueBytes, SETTINGS_REJECTION_CODES);
|
|
109
95
|
if (result.snapshot !== null) {
|
|
110
|
-
assertValidSettingsScopeSnapshot(
|
|
111
|
-
result.snapshot,
|
|
112
|
-
maximumOpaqueValueBytes,
|
|
113
|
-
);
|
|
96
|
+
assertValidSettingsScopeSnapshot(result.snapshot, maximumOpaqueValueBytes);
|
|
114
97
|
}
|
|
115
98
|
}
|
|
116
99
|
}
|
|
@@ -133,10 +116,7 @@ export function assertValidSettingsScopeChangedEvent(
|
|
|
133
116
|
unsigned(event.scopeRevision, "invalid_revision");
|
|
134
117
|
}
|
|
135
118
|
|
|
136
|
-
function mutationCommand(
|
|
137
|
-
value: unknown,
|
|
138
|
-
allowed?: readonly string[],
|
|
139
|
-
): Record<string, unknown> {
|
|
119
|
+
function mutationCommand(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
|
|
140
120
|
const command = record(value, allowed);
|
|
141
121
|
protocolVersion(command.protocolVersion);
|
|
142
122
|
identity(command.requestId);
|
|
@@ -158,6 +138,7 @@ function receipt(value: unknown, maximum: number): void {
|
|
|
158
138
|
known(receipt.outcome, SETTINGS_MUTATION_OUTCOMES);
|
|
159
139
|
const durability = record(receipt.durability);
|
|
160
140
|
known(durability.kind, SETTINGS_DURABILITY_KINDS);
|
|
141
|
+
record(durability, variantKeys("SettingsDurabilityEvidence", durability));
|
|
161
142
|
if (durability.kind === "confirmed") {
|
|
162
143
|
optionalOpaque(durability.evidence, maximum);
|
|
163
144
|
}
|
|
@@ -14,10 +14,7 @@ export class SettingsProtocolValidationError extends Error {
|
|
|
14
14
|
readonly code: SettingsProtocolValidationCode;
|
|
15
15
|
readonly actual: unknown;
|
|
16
16
|
|
|
17
|
-
constructor(
|
|
18
|
-
code: SettingsProtocolValidationCode,
|
|
19
|
-
actual: unknown,
|
|
20
|
-
) {
|
|
17
|
+
constructor(code: SettingsProtocolValidationCode, actual: unknown) {
|
|
21
18
|
super(`incompatible settings protocol: ${code}`);
|
|
22
19
|
this.name = "SettingsProtocolValidationError";
|
|
23
20
|
this.code = code;
|
|
@@ -25,9 +22,6 @@ export class SettingsProtocolValidationError extends Error {
|
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
export function incompatible(
|
|
29
|
-
code: SettingsProtocolValidationCode,
|
|
30
|
-
actual: unknown,
|
|
31
|
-
): never {
|
|
25
|
+
export function incompatible(code: SettingsProtocolValidationCode, actual: unknown): never {
|
|
32
26
|
throw new SettingsProtocolValidationError(code, actual);
|
|
33
27
|
}
|