@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,142 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectionFailureReporter,
|
|
3
|
+
EventTransport,
|
|
4
|
+
} from "@inflatable-cookie/longhorn/core";
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
SettingsApplyCommand,
|
|
8
|
+
SettingsLoadCommand,
|
|
9
|
+
SettingsLoadOutcome,
|
|
10
|
+
SettingsMutationResult,
|
|
11
|
+
SettingsRegistrySnapshot,
|
|
12
|
+
SettingsResetCommand,
|
|
13
|
+
SettingsScopeSnapshot,
|
|
14
|
+
} from "./generated/protocol.ts";
|
|
15
|
+
import {
|
|
16
|
+
assertValidSettingsApplyCommand,
|
|
17
|
+
assertValidSettingsLoadCommand,
|
|
18
|
+
assertValidSettingsLoadOutcome,
|
|
19
|
+
assertValidSettingsMutationResult,
|
|
20
|
+
assertValidSettingsRegistrySnapshot,
|
|
21
|
+
assertValidSettingsResetCommand,
|
|
22
|
+
} from "./validation.ts";
|
|
23
|
+
import {
|
|
24
|
+
connectSettingsRegistry,
|
|
25
|
+
connectSettingsScope,
|
|
26
|
+
SettingsAuthorityConsistencyError,
|
|
27
|
+
type SettingsScopeConnectionOptions,
|
|
28
|
+
type SettingsSubscription,
|
|
29
|
+
} from "./connection.ts";
|
|
30
|
+
import {
|
|
31
|
+
SETTINGS_APPLY_COMMAND,
|
|
32
|
+
SETTINGS_LOAD_COMMAND,
|
|
33
|
+
SETTINGS_REGISTRY_COMMAND,
|
|
34
|
+
SETTINGS_RESET_COMMAND,
|
|
35
|
+
} from "./names.ts";
|
|
36
|
+
|
|
37
|
+
export class SettingsClient {
|
|
38
|
+
readonly #transport: EventTransport;
|
|
39
|
+
|
|
40
|
+
constructor(transport: EventTransport) {
|
|
41
|
+
this.#transport = transport;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async registry(): Promise<SettingsRegistrySnapshot> {
|
|
45
|
+
const value = await this.#transport.invoke(
|
|
46
|
+
SETTINGS_REGISTRY_COMMAND,
|
|
47
|
+
{},
|
|
48
|
+
);
|
|
49
|
+
assertValidSettingsRegistrySnapshot(value);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async load(
|
|
54
|
+
registry: SettingsRegistrySnapshot,
|
|
55
|
+
command: SettingsLoadCommand,
|
|
56
|
+
): Promise<SettingsLoadOutcome> {
|
|
57
|
+
assertValidSettingsLoadCommand(command);
|
|
58
|
+
assertRegistryGeneration(registry, command.registryGeneration);
|
|
59
|
+
const value = await this.#transport.invoke(SETTINGS_LOAD_COMMAND, {
|
|
60
|
+
command,
|
|
61
|
+
});
|
|
62
|
+
assertValidSettingsLoadOutcome(
|
|
63
|
+
value,
|
|
64
|
+
registry.limits.maximumOpaqueValueBytes,
|
|
65
|
+
);
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async apply(
|
|
70
|
+
registry: SettingsRegistrySnapshot,
|
|
71
|
+
command: SettingsApplyCommand,
|
|
72
|
+
): Promise<SettingsMutationResult> {
|
|
73
|
+
assertValidSettingsApplyCommand(
|
|
74
|
+
command,
|
|
75
|
+
registry.limits.maximumOpaqueValueBytes,
|
|
76
|
+
);
|
|
77
|
+
assertRegistryGeneration(
|
|
78
|
+
registry,
|
|
79
|
+
command.authority.registryGeneration,
|
|
80
|
+
);
|
|
81
|
+
const value = await this.#transport.invoke(SETTINGS_APPLY_COMMAND, {
|
|
82
|
+
command,
|
|
83
|
+
});
|
|
84
|
+
assertValidSettingsMutationResult(
|
|
85
|
+
value,
|
|
86
|
+
registry.limits.maximumOpaqueValueBytes,
|
|
87
|
+
);
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async reset(
|
|
92
|
+
registry: SettingsRegistrySnapshot,
|
|
93
|
+
command: SettingsResetCommand,
|
|
94
|
+
): Promise<SettingsMutationResult> {
|
|
95
|
+
assertValidSettingsResetCommand(command);
|
|
96
|
+
assertRegistryGeneration(
|
|
97
|
+
registry,
|
|
98
|
+
command.authority.registryGeneration,
|
|
99
|
+
);
|
|
100
|
+
const value = await this.#transport.invoke(SETTINGS_RESET_COMMAND, {
|
|
101
|
+
command,
|
|
102
|
+
});
|
|
103
|
+
assertValidSettingsMutationResult(
|
|
104
|
+
value,
|
|
105
|
+
registry.limits.maximumOpaqueValueBytes,
|
|
106
|
+
);
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
connectRegistry(
|
|
111
|
+
listener?: (snapshot: SettingsRegistrySnapshot) => void,
|
|
112
|
+
onFailure?: ConnectionFailureReporter,
|
|
113
|
+
): SettingsSubscription<SettingsRegistrySnapshot> {
|
|
114
|
+
return connectSettingsRegistry(
|
|
115
|
+
this.#transport,
|
|
116
|
+
() => this.registry(),
|
|
117
|
+
listener,
|
|
118
|
+
onFailure,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
connectScope(
|
|
123
|
+
options: SettingsScopeConnectionOptions,
|
|
124
|
+
): SettingsSubscription<SettingsScopeSnapshot> {
|
|
125
|
+
return connectSettingsScope(
|
|
126
|
+
this.#transport,
|
|
127
|
+
(command) => this.load(options.registry, command),
|
|
128
|
+
options,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function assertRegistryGeneration(
|
|
134
|
+
registry: SettingsRegistrySnapshot,
|
|
135
|
+
generation: number,
|
|
136
|
+
): void {
|
|
137
|
+
if (generation !== registry.generation) {
|
|
138
|
+
throw new SettingsAuthorityConsistencyError(
|
|
139
|
+
"settings command registry generation does not match its registry",
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CheckedSnapshotConnection,
|
|
3
|
+
type ConnectionFailure,
|
|
4
|
+
type ConnectionFailureReporter,
|
|
5
|
+
type EventTransport,
|
|
6
|
+
} from "@inflatable-cookie/longhorn/core";
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
SettingsLoadCommand,
|
|
10
|
+
SettingsLoadOutcome,
|
|
11
|
+
SettingsRegistryChangedEvent,
|
|
12
|
+
SettingsRegistrySnapshot,
|
|
13
|
+
SettingsRequestId,
|
|
14
|
+
SettingsScopeChangedEvent,
|
|
15
|
+
SettingsScopeId,
|
|
16
|
+
SettingsScopeSnapshot,
|
|
17
|
+
} from "./generated/protocol.ts";
|
|
18
|
+
import {
|
|
19
|
+
assertValidSettingsRegistryChangedEvent,
|
|
20
|
+
assertValidSettingsRegistrySnapshot,
|
|
21
|
+
assertValidSettingsScopeChangedEvent,
|
|
22
|
+
assertValidSettingsScopeSnapshot,
|
|
23
|
+
} from "./validation.ts";
|
|
24
|
+
import {
|
|
25
|
+
SETTINGS_REGISTRY_CHANGED_EVENT,
|
|
26
|
+
SETTINGS_SCOPE_CHANGED_EVENT,
|
|
27
|
+
} from "./names.ts";
|
|
28
|
+
|
|
29
|
+
export interface SettingsSubscription<Snapshot> {
|
|
30
|
+
readonly ready: Promise<Snapshot>;
|
|
31
|
+
current(): Snapshot | undefined;
|
|
32
|
+
failures(): readonly ConnectionFailure[];
|
|
33
|
+
dispose(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SettingsScopeConnectionOptions {
|
|
37
|
+
readonly registry: SettingsRegistrySnapshot;
|
|
38
|
+
readonly scopeId: SettingsScopeId;
|
|
39
|
+
readonly nextRequestId: () => SettingsRequestId;
|
|
40
|
+
readonly onSnapshot?: (snapshot: SettingsScopeSnapshot) => void;
|
|
41
|
+
readonly onFailure?: ConnectionFailureReporter;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function connectSettingsRegistry(
|
|
45
|
+
transport: EventTransport,
|
|
46
|
+
load: () => Promise<SettingsRegistrySnapshot>,
|
|
47
|
+
listener?: (snapshot: SettingsRegistrySnapshot) => void,
|
|
48
|
+
onFailure?: ConnectionFailureReporter,
|
|
49
|
+
): SettingsSubscription<SettingsRegistrySnapshot> {
|
|
50
|
+
return requiredSubscription(
|
|
51
|
+
new CheckedSnapshotConnection({
|
|
52
|
+
listen: (receive) =>
|
|
53
|
+
transport.listen(SETTINGS_REGISTRY_CHANGED_EVENT, receive),
|
|
54
|
+
loadSnapshot: load,
|
|
55
|
+
validateSnapshot: parseRegistry,
|
|
56
|
+
handleEvent: registryEventAction,
|
|
57
|
+
isNewer: isNewerRegistry,
|
|
58
|
+
onSnapshot: listener,
|
|
59
|
+
onFailure,
|
|
60
|
+
disposedBeforeReadyError: () =>
|
|
61
|
+
new SettingsConnectionDisposedError("registry"),
|
|
62
|
+
}),
|
|
63
|
+
"registry",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function connectSettingsScope(
|
|
68
|
+
transport: EventTransport,
|
|
69
|
+
load: (command: SettingsLoadCommand) => Promise<SettingsLoadOutcome>,
|
|
70
|
+
options: SettingsScopeConnectionOptions,
|
|
71
|
+
): SettingsSubscription<SettingsScopeSnapshot> {
|
|
72
|
+
let current: SettingsScopeSnapshot | undefined;
|
|
73
|
+
const maximum = options.registry.limits.maximumOpaqueValueBytes;
|
|
74
|
+
const connection = new CheckedSnapshotConnection<SettingsScopeSnapshot>({
|
|
75
|
+
listen: (receive) =>
|
|
76
|
+
transport.listen(SETTINGS_SCOPE_CHANGED_EVENT, receive),
|
|
77
|
+
loadSnapshot: async () => {
|
|
78
|
+
const outcome = await load({
|
|
79
|
+
protocolVersion: 1,
|
|
80
|
+
requestId: options.nextRequestId(),
|
|
81
|
+
registryGeneration: options.registry.generation,
|
|
82
|
+
scopeId: options.scopeId,
|
|
83
|
+
knownAuthority: current?.authority ?? null,
|
|
84
|
+
});
|
|
85
|
+
if (outcome.status === "rejected") {
|
|
86
|
+
throw new SettingsLoadRejectedError(outcome);
|
|
87
|
+
}
|
|
88
|
+
return outcome.snapshot;
|
|
89
|
+
},
|
|
90
|
+
validateSnapshot: (value) => {
|
|
91
|
+
assertValidSettingsScopeSnapshot(value, maximum);
|
|
92
|
+
validateScopeIdentity(value, options);
|
|
93
|
+
return value;
|
|
94
|
+
},
|
|
95
|
+
handleEvent: (value, snapshot) =>
|
|
96
|
+
scopeEventAction(value, snapshot, options),
|
|
97
|
+
isNewer: (candidate, snapshot) => {
|
|
98
|
+
const accepted = isNewerScope(candidate, snapshot);
|
|
99
|
+
if (accepted) {
|
|
100
|
+
current = candidate;
|
|
101
|
+
}
|
|
102
|
+
return accepted;
|
|
103
|
+
},
|
|
104
|
+
onSnapshot: options.onSnapshot,
|
|
105
|
+
onFailure: options.onFailure,
|
|
106
|
+
disposedBeforeReadyError: () =>
|
|
107
|
+
new SettingsConnectionDisposedError(options.scopeId),
|
|
108
|
+
});
|
|
109
|
+
return requiredSubscription(connection, options.scopeId);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export class SettingsConnectionDisposedError extends Error {
|
|
113
|
+
constructor(target: string) {
|
|
114
|
+
super(`settings ${target} connection was disposed during registration`);
|
|
115
|
+
this.name = "SettingsConnectionDisposedError";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class SettingsLoadRejectedError extends Error {
|
|
120
|
+
readonly outcome: SettingsLoadOutcome;
|
|
121
|
+
|
|
122
|
+
constructor(outcome: SettingsLoadOutcome) {
|
|
123
|
+
super("settings scope load was rejected");
|
|
124
|
+
this.name = "SettingsLoadRejectedError";
|
|
125
|
+
this.outcome = outcome;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class SettingsAuthorityConsistencyError extends Error {
|
|
130
|
+
constructor(message: string) {
|
|
131
|
+
super(message);
|
|
132
|
+
this.name = "SettingsAuthorityConsistencyError";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function requiredSubscription<Snapshot>(
|
|
137
|
+
connection: CheckedSnapshotConnection<Snapshot>,
|
|
138
|
+
target: string,
|
|
139
|
+
): SettingsSubscription<Snapshot> {
|
|
140
|
+
return {
|
|
141
|
+
ready: connection.ready.then((snapshot) => {
|
|
142
|
+
if (snapshot === undefined) {
|
|
143
|
+
throw new SettingsConnectionDisposedError(target);
|
|
144
|
+
}
|
|
145
|
+
return snapshot;
|
|
146
|
+
}),
|
|
147
|
+
current: () => connection.current(),
|
|
148
|
+
failures: () => connection.failures(),
|
|
149
|
+
dispose: () => connection.dispose(),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function parseRegistry(value: unknown): SettingsRegistrySnapshot {
|
|
154
|
+
assertValidSettingsRegistrySnapshot(value);
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function registryEventAction(
|
|
159
|
+
value: unknown,
|
|
160
|
+
current: SettingsRegistrySnapshot | undefined,
|
|
161
|
+
): { kind: "ignore" } | { kind: "refresh" } {
|
|
162
|
+
assertValidSettingsRegistryChangedEvent(value);
|
|
163
|
+
const event = value as SettingsRegistryChangedEvent;
|
|
164
|
+
return current !== undefined &&
|
|
165
|
+
event.registryGeneration <= current.generation
|
|
166
|
+
? { kind: "ignore" }
|
|
167
|
+
: { kind: "refresh" };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function scopeEventAction(
|
|
171
|
+
value: unknown,
|
|
172
|
+
current: SettingsScopeSnapshot | undefined,
|
|
173
|
+
options: SettingsScopeConnectionOptions,
|
|
174
|
+
): { kind: "ignore" } | { kind: "refresh" } {
|
|
175
|
+
assertValidSettingsScopeChangedEvent(value);
|
|
176
|
+
const event = value as SettingsScopeChangedEvent;
|
|
177
|
+
if (event.scopeId !== options.scopeId) {
|
|
178
|
+
return { kind: "ignore" };
|
|
179
|
+
}
|
|
180
|
+
const authority = current?.authority;
|
|
181
|
+
return authority !== undefined &&
|
|
182
|
+
(event.registryGeneration < authority.registryGeneration ||
|
|
183
|
+
(event.registryGeneration === authority.registryGeneration &&
|
|
184
|
+
event.scopeRevision <= authority.scopeRevision))
|
|
185
|
+
? { kind: "ignore" }
|
|
186
|
+
: { kind: "refresh" };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isNewerRegistry(
|
|
190
|
+
candidate: SettingsRegistrySnapshot,
|
|
191
|
+
current: SettingsRegistrySnapshot | undefined,
|
|
192
|
+
): boolean {
|
|
193
|
+
if (current === undefined || candidate.generation > current.generation) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (
|
|
197
|
+
candidate.generation === current.generation &&
|
|
198
|
+
candidate.digest !== current.digest
|
|
199
|
+
) {
|
|
200
|
+
throw new SettingsAuthorityConsistencyError(
|
|
201
|
+
"one settings registry generation produced multiple digests",
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isNewerScope(
|
|
208
|
+
candidate: SettingsScopeSnapshot,
|
|
209
|
+
current: SettingsScopeSnapshot | undefined,
|
|
210
|
+
): boolean {
|
|
211
|
+
if (current === undefined) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const next = candidate.authority;
|
|
215
|
+
const previous = current.authority;
|
|
216
|
+
if (next.registryGeneration !== previous.registryGeneration) {
|
|
217
|
+
return next.registryGeneration > previous.registryGeneration;
|
|
218
|
+
}
|
|
219
|
+
if (next.scopeRevision !== previous.scopeRevision) {
|
|
220
|
+
return next.scopeRevision > previous.scopeRevision;
|
|
221
|
+
}
|
|
222
|
+
if (next.authorityToken !== previous.authorityToken) {
|
|
223
|
+
throw new SettingsAuthorityConsistencyError(
|
|
224
|
+
"one settings scope revision produced multiple authority tokens",
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function validateScopeIdentity(
|
|
231
|
+
snapshot: SettingsScopeSnapshot,
|
|
232
|
+
options: SettingsScopeConnectionOptions,
|
|
233
|
+
): void {
|
|
234
|
+
if (snapshot.scopeId !== options.scopeId) {
|
|
235
|
+
throw new SettingsAuthorityConsistencyError(
|
|
236
|
+
`loaded scope ${snapshot.scopeId}; expected ${options.scopeId}`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (
|
|
240
|
+
snapshot.authority.registryGeneration !== options.registry.generation
|
|
241
|
+
) {
|
|
242
|
+
throw new SettingsAuthorityConsistencyError(
|
|
243
|
+
"scope snapshot registry generation does not match the connection",
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @generated by `effigy generate:settings`; 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 SETTINGS_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"SettingsLimits": ["maximumModules", "maximumSections", "maximumPages", "maximumRenderers", "maximumScopes", "maximumApplyUnits", "maximumCapabilities", "maximumAnchorsPerPage", "maximumKeywordsPerPage", "maximumLabelBytes", "maximumKeywordBytes", "maximumOpaqueValueBytes"],
|
|
8
|
+
"SettingsOpaqueValue": ["codecVersion", "value"],
|
|
9
|
+
"SettingsModuleDefinition": ["id", "label", "order"],
|
|
10
|
+
"SettingsSectionDefinition": ["id", "moduleId", "label", "order"],
|
|
11
|
+
"SettingsRendererDefinition": ["id", "moduleId"],
|
|
12
|
+
"SettingsScopeDefinition": ["id", "moduleId"],
|
|
13
|
+
"SettingsCapabilityDefinition": ["id", "moduleId"],
|
|
14
|
+
"SettingsApplyUnitDefinition": ["id", "moduleId", "scopeId", "timing", "resetSupported"],
|
|
15
|
+
"SettingsAnchorDefinition": ["id", "label", "order"],
|
|
16
|
+
"SettingsPageFeatures": ["reset", "import", "backup", "restore", "confirmation"],
|
|
17
|
+
"SettingsPageDefinition": ["id", "moduleId", "sectionId", "rendererId", "label", "keywords", "order", "anchors", "requiredCapabilities", "readableScopeIds", "writableApplyUnitIds", "features"],
|
|
18
|
+
"SettingsPolicyProjection": ["sourceId", "effect", "constraints"],
|
|
19
|
+
"SettingsSourceDiagnostic": ["code", "detail"],
|
|
20
|
+
"SettingsValueProjection": ["entryId", "configured", "effective", "compiledDefault", "effectiveSource", "policy", "editability", "sourceDiagnostics"],
|
|
21
|
+
"SettingsRecoveryState": ["code", "diagnostic"],
|
|
22
|
+
"SettingsActivationRequirement": ["targetId", "state"],
|
|
23
|
+
"SettingsAuthorityExpectation": ["registryGeneration", "scopeRevision", "authorityToken"],
|
|
24
|
+
"SettingsScopeSnapshot": ["protocolVersion", "scopeId", "authority", "values", "recovery", "activationRequirements"],
|
|
25
|
+
"SettingsRegistrySnapshot": ["protocolVersion", "generation", "digest", "limits", "composedCapabilities", "modules", "sections", "pages", "renderers", "scopes", "applyUnits", "capabilities"],
|
|
26
|
+
"SettingsRegistryChangedEvent": ["protocolVersion", "registryGeneration"],
|
|
27
|
+
"SettingsScopeChangedEvent": ["protocolVersion", "registryGeneration", "scopeId", "scopeRevision"],
|
|
28
|
+
"SettingsLoadCommand": ["protocolVersion", "requestId", "registryGeneration", "scopeId", "knownAuthority"],
|
|
29
|
+
"SettingsApplyCommand": ["protocolVersion", "requestId", "pageId", "applyUnitId", "scopeId", "authority", "intent"],
|
|
30
|
+
"SettingsResetCommand": ["protocolVersion", "requestId", "pageId", "applyUnitId", "scopeId", "authority", "entryIds"],
|
|
31
|
+
"SettingsMutationReceipt": ["requestId", "pageId", "applyUnitId", "scopeId", "previousAuthority", "committedAuthority", "outcome", "durability", "activationRequirements"],
|
|
32
|
+
"SettingsConflict": ["expected", "actual"],
|
|
33
|
+
"SettingsRejection": ["code", "diagnostic"],
|
|
34
|
+
};
|