@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,141 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SettingsAnchorDefinition,
|
|
3
|
+
SettingsAnchorId,
|
|
4
|
+
SettingsModuleDefinition,
|
|
5
|
+
SettingsPageDefinition,
|
|
6
|
+
SettingsPageId,
|
|
7
|
+
SettingsRegistrySnapshot,
|
|
8
|
+
SettingsSectionDefinition,
|
|
9
|
+
} from "./generated/protocol.ts";
|
|
10
|
+
|
|
11
|
+
export interface SettingsNavigationModule {
|
|
12
|
+
readonly module: SettingsModuleDefinition;
|
|
13
|
+
readonly sections: readonly SettingsNavigationSection[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SettingsNavigationSection {
|
|
17
|
+
readonly section: SettingsSectionDefinition;
|
|
18
|
+
readonly pages: readonly SettingsPageDefinition[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SettingsRegistryProjection {
|
|
22
|
+
readonly generation: number;
|
|
23
|
+
readonly modules: readonly SettingsNavigationModule[];
|
|
24
|
+
readonly pages: readonly SettingsPageDefinition[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SettingsDeepLink {
|
|
28
|
+
readonly pageId: SettingsPageId;
|
|
29
|
+
readonly anchorId?: SettingsAnchorId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ResolvedSettingsDeepLink {
|
|
33
|
+
readonly page: SettingsPageDefinition;
|
|
34
|
+
readonly anchor: SettingsAnchorDefinition | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type SettingsSearchMatchKind = "page" | "anchor";
|
|
38
|
+
|
|
39
|
+
export interface SettingsSearchResult {
|
|
40
|
+
readonly kind: SettingsSearchMatchKind;
|
|
41
|
+
readonly page: SettingsPageDefinition;
|
|
42
|
+
readonly anchor: SettingsAnchorDefinition | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class SettingsDeepLinkResolutionError extends Error {
|
|
46
|
+
readonly link: SettingsDeepLink;
|
|
47
|
+
|
|
48
|
+
constructor(message: string, link: SettingsDeepLink) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "SettingsDeepLinkResolutionError";
|
|
51
|
+
this.link = link;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function projectSettingsRegistry(
|
|
56
|
+
registry: SettingsRegistrySnapshot,
|
|
57
|
+
): SettingsRegistryProjection {
|
|
58
|
+
const pagesBySection = new Map<string, SettingsPageDefinition[]>();
|
|
59
|
+
for (const page of registry.pages) {
|
|
60
|
+
const pages = pagesBySection.get(page.sectionId) ?? [];
|
|
61
|
+
pages.push(page);
|
|
62
|
+
pagesBySection.set(page.sectionId, pages);
|
|
63
|
+
}
|
|
64
|
+
const sectionsByModule = new Map<string, SettingsNavigationSection[]>();
|
|
65
|
+
for (const section of registry.sections) {
|
|
66
|
+
const pages = pagesBySection.get(section.id) ?? [];
|
|
67
|
+
if (pages.length === 0) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const sections = sectionsByModule.get(section.moduleId) ?? [];
|
|
71
|
+
sections.push({ section, pages });
|
|
72
|
+
sectionsByModule.set(section.moduleId, sections);
|
|
73
|
+
}
|
|
74
|
+
const modules = registry.modules.flatMap((module) => {
|
|
75
|
+
const sections = sectionsByModule.get(module.id) ?? [];
|
|
76
|
+
return sections.length === 0 ? [] : [{ module, sections }];
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
generation: registry.generation,
|
|
80
|
+
modules,
|
|
81
|
+
pages: registry.pages,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function searchSettingsRegistry(
|
|
86
|
+
registry: SettingsRegistrySnapshot,
|
|
87
|
+
query: string,
|
|
88
|
+
): readonly SettingsSearchResult[] {
|
|
89
|
+
const needle = normalize(query);
|
|
90
|
+
if (needle.length === 0) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const results: SettingsSearchResult[] = [];
|
|
94
|
+
for (const page of registry.pages) {
|
|
95
|
+
const pageMatch = [page.label, ...page.keywords]
|
|
96
|
+
.map(normalize)
|
|
97
|
+
.some((value) => value.includes(needle));
|
|
98
|
+
if (pageMatch) {
|
|
99
|
+
results.push({ kind: "page", page, anchor: undefined });
|
|
100
|
+
}
|
|
101
|
+
for (const anchor of page.anchors) {
|
|
102
|
+
if (
|
|
103
|
+
anchor.label !== null &&
|
|
104
|
+
normalize(anchor.label).includes(needle)
|
|
105
|
+
) {
|
|
106
|
+
results.push({ kind: "anchor", page, anchor });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function resolveSettingsDeepLink(
|
|
114
|
+
registry: SettingsRegistrySnapshot,
|
|
115
|
+
link: SettingsDeepLink,
|
|
116
|
+
): ResolvedSettingsDeepLink {
|
|
117
|
+
const page = registry.pages.find((candidate) => candidate.id === link.pageId);
|
|
118
|
+
if (page === undefined) {
|
|
119
|
+
throw new SettingsDeepLinkResolutionError(
|
|
120
|
+
`unknown settings page ${link.pageId}`,
|
|
121
|
+
link,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
if (link.anchorId === undefined) {
|
|
125
|
+
return { page, anchor: undefined };
|
|
126
|
+
}
|
|
127
|
+
const anchor = page.anchors.find(
|
|
128
|
+
(candidate) => candidate.id === link.anchorId,
|
|
129
|
+
);
|
|
130
|
+
if (anchor === undefined) {
|
|
131
|
+
throw new SettingsDeepLinkResolutionError(
|
|
132
|
+
`unknown settings anchor ${link.anchorId} on ${link.pageId}`,
|
|
133
|
+
link,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return { page, anchor };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function normalize(value: string): string {
|
|
140
|
+
return value.trim().toLocaleLowerCase("en-US");
|
|
141
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
SETTINGS_ACTIVATION_STATES,
|
|
4
|
+
SETTINGS_EDITABILITIES,
|
|
5
|
+
SETTINGS_EFFECTIVE_SOURCES,
|
|
6
|
+
SETTINGS_HARD_MAXIMUM_TEXT_BYTES,
|
|
7
|
+
SETTINGS_POLICY_EFFECTS,
|
|
8
|
+
SETTINGS_RECOVERY_CODES,
|
|
9
|
+
type SettingsScopeSnapshot,
|
|
10
|
+
} from "../generated/protocol.ts";
|
|
11
|
+
import {
|
|
12
|
+
activation,
|
|
13
|
+
policy,
|
|
14
|
+
recovery,
|
|
15
|
+
} from "./projection.ts";
|
|
16
|
+
import {
|
|
17
|
+
array,
|
|
18
|
+
authority,
|
|
19
|
+
HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
20
|
+
identity,
|
|
21
|
+
known,
|
|
22
|
+
opaque,
|
|
23
|
+
optionalOpaque,
|
|
24
|
+
protocolVersion,
|
|
25
|
+
record,
|
|
26
|
+
text,
|
|
27
|
+
} from "./primitives.ts";
|
|
28
|
+
|
|
29
|
+
export function assertValidSettingsScopeSnapshot(
|
|
30
|
+
value: unknown,
|
|
31
|
+
maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
32
|
+
): asserts value is SettingsScopeSnapshot {
|
|
33
|
+
const snapshot = record(value, SETTINGS_FIELDS.SettingsScopeSnapshot);
|
|
34
|
+
protocolVersion(snapshot.protocolVersion);
|
|
35
|
+
identity(snapshot.scopeId);
|
|
36
|
+
authority(snapshot.authority);
|
|
37
|
+
array(snapshot.values).forEach((value) => {
|
|
38
|
+
const projection = record(value, SETTINGS_FIELDS.SettingsValueProjection);
|
|
39
|
+
identity(projection.entryId);
|
|
40
|
+
optionalOpaque(projection.configured, maximumOpaqueValueBytes);
|
|
41
|
+
opaque(projection.effective, maximumOpaqueValueBytes);
|
|
42
|
+
opaque(projection.compiledDefault, maximumOpaqueValueBytes);
|
|
43
|
+
known(projection.effectiveSource, SETTINGS_EFFECTIVE_SOURCES);
|
|
44
|
+
known(projection.editability, SETTINGS_EDITABILITIES);
|
|
45
|
+
if (projection.policy !== null) {
|
|
46
|
+
policy(
|
|
47
|
+
projection.policy,
|
|
48
|
+
maximumOpaqueValueBytes,
|
|
49
|
+
SETTINGS_POLICY_EFFECTS,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
array(projection.sourceDiagnostics).forEach((value) => {
|
|
53
|
+
const diagnostic = record(value, SETTINGS_FIELDS.SettingsSourceDiagnostic);
|
|
54
|
+
text(diagnostic.code, SETTINGS_HARD_MAXIMUM_TEXT_BYTES);
|
|
55
|
+
optionalOpaque(diagnostic.detail, maximumOpaqueValueBytes);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
if (snapshot.recovery !== null) {
|
|
59
|
+
recovery(
|
|
60
|
+
snapshot.recovery,
|
|
61
|
+
maximumOpaqueValueBytes,
|
|
62
|
+
SETTINGS_RECOVERY_CODES,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
activation(snapshot.activationRequirements, SETTINGS_ACTIVATION_STATES);
|
|
66
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
SETTINGS_ACTIVATION_STATES,
|
|
4
|
+
SETTINGS_DURABILITY_KINDS,
|
|
5
|
+
SETTINGS_LOAD_OUTCOME_STATUSES,
|
|
6
|
+
SETTINGS_MUTATION_OUTCOMES,
|
|
7
|
+
SETTINGS_MUTATION_RESULT_STATUSES,
|
|
8
|
+
SETTINGS_REJECTION_CODES,
|
|
9
|
+
type SettingsApplyCommand,
|
|
10
|
+
type SettingsLoadCommand,
|
|
11
|
+
type SettingsLoadOutcome,
|
|
12
|
+
type SettingsMutationResult,
|
|
13
|
+
type SettingsRegistryChangedEvent,
|
|
14
|
+
type SettingsResetCommand,
|
|
15
|
+
type SettingsScopeChangedEvent,
|
|
16
|
+
} from "../generated/protocol.ts";
|
|
17
|
+
import { assertValidSettingsScopeSnapshot } from "./authority.ts";
|
|
18
|
+
import { activation, rejection } from "./projection.ts";
|
|
19
|
+
import {
|
|
20
|
+
array,
|
|
21
|
+
authority,
|
|
22
|
+
HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
23
|
+
identity,
|
|
24
|
+
known,
|
|
25
|
+
opaque,
|
|
26
|
+
optionalOpaque,
|
|
27
|
+
protocolVersion,
|
|
28
|
+
record,
|
|
29
|
+
unsigned,
|
|
30
|
+
variantKeys,
|
|
31
|
+
} from "./primitives.ts";
|
|
32
|
+
|
|
33
|
+
export function assertValidSettingsLoadCommand(
|
|
34
|
+
value: unknown,
|
|
35
|
+
): asserts value is SettingsLoadCommand {
|
|
36
|
+
const command = record(value, SETTINGS_FIELDS.SettingsLoadCommand);
|
|
37
|
+
protocolVersion(command.protocolVersion);
|
|
38
|
+
identity(command.requestId);
|
|
39
|
+
unsigned(command.registryGeneration, "invalid_revision");
|
|
40
|
+
identity(command.scopeId);
|
|
41
|
+
if (command.knownAuthority !== null) {
|
|
42
|
+
authority(command.knownAuthority);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function assertValidSettingsApplyCommand(
|
|
47
|
+
value: unknown,
|
|
48
|
+
maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
49
|
+
): asserts value is SettingsApplyCommand {
|
|
50
|
+
const command = mutationCommand(value, SETTINGS_FIELDS.SettingsApplyCommand);
|
|
51
|
+
opaque(command.intent, maximumOpaqueValueBytes);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function assertValidSettingsResetCommand(
|
|
55
|
+
value: unknown,
|
|
56
|
+
): asserts value is SettingsResetCommand {
|
|
57
|
+
const command = mutationCommand(value, SETTINGS_FIELDS.SettingsResetCommand);
|
|
58
|
+
array(command.entryIds).forEach(identity);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function assertValidSettingsLoadOutcome(
|
|
62
|
+
value: unknown,
|
|
63
|
+
maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
64
|
+
): asserts value is SettingsLoadOutcome {
|
|
65
|
+
const outcome = record(value);
|
|
66
|
+
known(outcome.status, SETTINGS_LOAD_OUTCOME_STATUSES);
|
|
67
|
+
record(outcome, variantKeys("SettingsLoadOutcome", outcome));
|
|
68
|
+
if (outcome.status === "loaded") {
|
|
69
|
+
assertValidSettingsScopeSnapshot(
|
|
70
|
+
outcome.snapshot,
|
|
71
|
+
maximumOpaqueValueBytes,
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
rejection(
|
|
75
|
+
outcome.rejection,
|
|
76
|
+
maximumOpaqueValueBytes,
|
|
77
|
+
SETTINGS_REJECTION_CODES,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function assertValidSettingsMutationResult(
|
|
83
|
+
value: unknown,
|
|
84
|
+
maximumOpaqueValueBytes = HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
85
|
+
): asserts value is SettingsMutationResult {
|
|
86
|
+
const result = record(value);
|
|
87
|
+
known(result.status, SETTINGS_MUTATION_RESULT_STATUSES);
|
|
88
|
+
record(result, variantKeys("SettingsMutationResult", result));
|
|
89
|
+
if (result.status === "applied") {
|
|
90
|
+
assertValidSettingsScopeSnapshot(
|
|
91
|
+
result.snapshot,
|
|
92
|
+
maximumOpaqueValueBytes,
|
|
93
|
+
);
|
|
94
|
+
receipt(result.receipt, maximumOpaqueValueBytes);
|
|
95
|
+
} else if (result.status === "conflict") {
|
|
96
|
+
const conflict = record(result.conflict, SETTINGS_FIELDS.SettingsConflict);
|
|
97
|
+
authority(conflict.expected);
|
|
98
|
+
authority(conflict.actual);
|
|
99
|
+
assertValidSettingsScopeSnapshot(
|
|
100
|
+
result.snapshot,
|
|
101
|
+
maximumOpaqueValueBytes,
|
|
102
|
+
);
|
|
103
|
+
} else {
|
|
104
|
+
rejection(
|
|
105
|
+
result.rejection,
|
|
106
|
+
maximumOpaqueValueBytes,
|
|
107
|
+
SETTINGS_REJECTION_CODES,
|
|
108
|
+
);
|
|
109
|
+
if (result.snapshot !== null) {
|
|
110
|
+
assertValidSettingsScopeSnapshot(
|
|
111
|
+
result.snapshot,
|
|
112
|
+
maximumOpaqueValueBytes,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function assertValidSettingsRegistryChangedEvent(
|
|
119
|
+
value: unknown,
|
|
120
|
+
): asserts value is SettingsRegistryChangedEvent {
|
|
121
|
+
const event = record(value, SETTINGS_FIELDS.SettingsRegistryChangedEvent);
|
|
122
|
+
protocolVersion(event.protocolVersion);
|
|
123
|
+
unsigned(event.registryGeneration, "invalid_revision");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function assertValidSettingsScopeChangedEvent(
|
|
127
|
+
value: unknown,
|
|
128
|
+
): asserts value is SettingsScopeChangedEvent {
|
|
129
|
+
const event = record(value, SETTINGS_FIELDS.SettingsScopeChangedEvent);
|
|
130
|
+
protocolVersion(event.protocolVersion);
|
|
131
|
+
unsigned(event.registryGeneration, "invalid_revision");
|
|
132
|
+
identity(event.scopeId);
|
|
133
|
+
unsigned(event.scopeRevision, "invalid_revision");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function mutationCommand(
|
|
137
|
+
value: unknown,
|
|
138
|
+
allowed?: readonly string[],
|
|
139
|
+
): Record<string, unknown> {
|
|
140
|
+
const command = record(value, allowed);
|
|
141
|
+
protocolVersion(command.protocolVersion);
|
|
142
|
+
identity(command.requestId);
|
|
143
|
+
identity(command.pageId);
|
|
144
|
+
identity(command.applyUnitId);
|
|
145
|
+
identity(command.scopeId);
|
|
146
|
+
authority(command.authority);
|
|
147
|
+
return command;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function receipt(value: unknown, maximum: number): void {
|
|
151
|
+
const receipt = record(value, SETTINGS_FIELDS.SettingsMutationReceipt);
|
|
152
|
+
identity(receipt.requestId);
|
|
153
|
+
identity(receipt.pageId);
|
|
154
|
+
identity(receipt.applyUnitId);
|
|
155
|
+
identity(receipt.scopeId);
|
|
156
|
+
authority(receipt.previousAuthority);
|
|
157
|
+
authority(receipt.committedAuthority);
|
|
158
|
+
known(receipt.outcome, SETTINGS_MUTATION_OUTCOMES);
|
|
159
|
+
const durability = record(receipt.durability);
|
|
160
|
+
known(durability.kind, SETTINGS_DURABILITY_KINDS);
|
|
161
|
+
if (durability.kind === "confirmed") {
|
|
162
|
+
optionalOpaque(durability.evidence, maximum);
|
|
163
|
+
}
|
|
164
|
+
activation(receipt.activationRequirements, SETTINGS_ACTIVATION_STATES);
|
|
165
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type SettingsProtocolValidationCode =
|
|
2
|
+
| "invalid_shape"
|
|
3
|
+
| "unsupported_protocol_version"
|
|
4
|
+
| "invalid_identity"
|
|
5
|
+
| "invalid_revision"
|
|
6
|
+
| "invalid_registry"
|
|
7
|
+
| "invalid_opaque_value"
|
|
8
|
+
| "opaque_value_too_large"
|
|
9
|
+
| "unknown_discriminant"
|
|
10
|
+
| "unknown_field"
|
|
11
|
+
| "missing_field";
|
|
12
|
+
|
|
13
|
+
export class SettingsProtocolValidationError extends Error {
|
|
14
|
+
readonly code: SettingsProtocolValidationCode;
|
|
15
|
+
readonly actual: unknown;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
code: SettingsProtocolValidationCode,
|
|
19
|
+
actual: unknown,
|
|
20
|
+
) {
|
|
21
|
+
super(`incompatible settings protocol: ${code}`);
|
|
22
|
+
this.name = "SettingsProtocolValidationError";
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.actual = actual;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function incompatible(
|
|
29
|
+
code: SettingsProtocolValidationCode,
|
|
30
|
+
actual: unknown,
|
|
31
|
+
): never {
|
|
32
|
+
throw new SettingsProtocolValidationError(code, actual);
|
|
33
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SETTINGS_VARIANT_FIELDS,
|
|
3
|
+
SETTINGS_VARIANT_FIELDS_DISCRIMINANTS,
|
|
4
|
+
} from "../generated/variant-fields.ts";
|
|
5
|
+
import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
6
|
+
import {
|
|
7
|
+
SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
|
|
8
|
+
SETTINGS_PROTOCOL_VERSION,
|
|
9
|
+
type SettingsOpaqueValue,
|
|
10
|
+
} from "../generated/protocol.ts";
|
|
11
|
+
import {
|
|
12
|
+
incompatible,
|
|
13
|
+
type SettingsProtocolValidationCode,
|
|
14
|
+
} from "./error.ts";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Kept under its original name so the twenty call sites do not churn, but the
|
|
18
|
+
* value is now the Rust `SettingsLimits::HARD_MAXIMUM_OPAQUE_VALUE_BYTES`
|
|
19
|
+
* rather than a literal that happened to match it.
|
|
20
|
+
*/
|
|
21
|
+
export const HARD_MAXIMUM_OPAQUE_VALUE_BYTES: number =
|
|
22
|
+
SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES;
|
|
23
|
+
const OPAQUE_ID = /^[a-z0-9][a-z0-9._:/-]{0,254}$/;
|
|
24
|
+
|
|
25
|
+
export function authority(value: unknown): void {
|
|
26
|
+
const valueRecord = record(value, SETTINGS_FIELDS.SettingsAuthorityExpectation);
|
|
27
|
+
unsigned(valueRecord.registryGeneration, "invalid_revision");
|
|
28
|
+
unsigned(valueRecord.scopeRevision, "invalid_revision");
|
|
29
|
+
identity(valueRecord.authorityToken);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function optionalOpaque(value: unknown, maximum: number): void {
|
|
33
|
+
if (value !== null) {
|
|
34
|
+
opaque(value, maximum);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function opaque(
|
|
39
|
+
value: unknown,
|
|
40
|
+
maximum: number,
|
|
41
|
+
): asserts value is SettingsOpaqueValue {
|
|
42
|
+
const envelope = record(value, SETTINGS_FIELDS.SettingsOpaqueValue);
|
|
43
|
+
positive(envelope.codecVersion, "invalid_opaque_value");
|
|
44
|
+
let encoded: string | undefined;
|
|
45
|
+
try {
|
|
46
|
+
encoded = JSON.stringify(envelope);
|
|
47
|
+
} catch {
|
|
48
|
+
incompatible("invalid_opaque_value", value);
|
|
49
|
+
}
|
|
50
|
+
if (encoded === undefined) {
|
|
51
|
+
incompatible("invalid_opaque_value", value);
|
|
52
|
+
}
|
|
53
|
+
const bytes = new TextEncoder().encode(encoded).byteLength;
|
|
54
|
+
if (bytes > maximum || bytes > HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
|
|
55
|
+
incompatible("opaque_value_too_large", bytes);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function definition(value: unknown): void {
|
|
60
|
+
const valueRecord = record(value);
|
|
61
|
+
identity(valueRecord.id);
|
|
62
|
+
identity(valueRecord.moduleId);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function arraysOfIdentities(...values: unknown[]): void {
|
|
66
|
+
values.forEach((value) => array(value).forEach(identity));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function identity(value: unknown): void {
|
|
70
|
+
if (typeof value !== "string" || !OPAQUE_ID.test(value)) {
|
|
71
|
+
incompatible("invalid_identity", value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function protocolVersion(value: unknown): void {
|
|
76
|
+
if (value !== SETTINGS_PROTOCOL_VERSION) {
|
|
77
|
+
incompatible("unsupported_protocol_version", value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function known(value: unknown, choices: readonly string[]): void {
|
|
82
|
+
if (typeof value !== "string" || !choices.includes(value)) {
|
|
83
|
+
incompatible("unknown_discriminant", value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function text(value: unknown, maximumBytes: number): void {
|
|
88
|
+
if (
|
|
89
|
+
typeof value !== "string" ||
|
|
90
|
+
value.length === 0 ||
|
|
91
|
+
new TextEncoder().encode(value).byteLength > maximumBytes
|
|
92
|
+
) {
|
|
93
|
+
incompatible("invalid_registry", value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function boolean(value: unknown): void {
|
|
98
|
+
if (typeof value !== "boolean") {
|
|
99
|
+
incompatible("invalid_shape", value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function integer(value: unknown): void {
|
|
104
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
105
|
+
incompatible("invalid_shape", value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function positive(
|
|
110
|
+
value: unknown,
|
|
111
|
+
code: SettingsProtocolValidationCode,
|
|
112
|
+
): void {
|
|
113
|
+
unsigned(value, code);
|
|
114
|
+
if (value === 0) {
|
|
115
|
+
incompatible(code, value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function unsigned(
|
|
120
|
+
value: unknown,
|
|
121
|
+
code: SettingsProtocolValidationCode,
|
|
122
|
+
): void {
|
|
123
|
+
if (
|
|
124
|
+
typeof value !== "number" ||
|
|
125
|
+
!Number.isSafeInteger(value) ||
|
|
126
|
+
value < 0
|
|
127
|
+
) {
|
|
128
|
+
incompatible(code, value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function boundedArray(
|
|
133
|
+
value: unknown,
|
|
134
|
+
maximum: number,
|
|
135
|
+
code: SettingsProtocolValidationCode,
|
|
136
|
+
): unknown[] {
|
|
137
|
+
const values = array(value);
|
|
138
|
+
if (values.length > maximum) {
|
|
139
|
+
incompatible(code, values.length);
|
|
140
|
+
}
|
|
141
|
+
return values;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function array(value: unknown): unknown[] {
|
|
145
|
+
if (!Array.isArray(value)) {
|
|
146
|
+
incompatible("invalid_shape", value);
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Rejects a non-object, an unknown key, and a missing key.
|
|
153
|
+
*
|
|
154
|
+
* `allowed` comes from the generated field map, so the keys accepted are the
|
|
155
|
+
* Rust struct's and nothing else — contract 010's Boundary Validation Target.
|
|
156
|
+
* Called without a list, this keeps shape-only behaviour, which is correct
|
|
157
|
+
* for a tagged union and a gap anywhere else.
|
|
158
|
+
*/
|
|
159
|
+
export function record(
|
|
160
|
+
value: unknown,
|
|
161
|
+
allowed?: readonly string[],
|
|
162
|
+
): Record<string, unknown> {
|
|
163
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
164
|
+
incompatible("invalid_shape", value);
|
|
165
|
+
}
|
|
166
|
+
const result = value as Record<string, unknown>;
|
|
167
|
+
if (allowed === undefined) return result;
|
|
168
|
+
|
|
169
|
+
const permitted = new Set(allowed);
|
|
170
|
+
for (const key of Object.keys(result)) {
|
|
171
|
+
if (!permitted.has(key)) {
|
|
172
|
+
incompatible("unknown_field", { key, value });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const key of allowed) {
|
|
176
|
+
if (!(key in result)) {
|
|
177
|
+
incompatible("missing_field", { key, value });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Allowed keys for one tagged-union variant, from the generated map.
|
|
185
|
+
*
|
|
186
|
+
* The discriminant's name comes from the map too: this domain tags
|
|
187
|
+
* `SettingsDurabilityEvidence` on `kind` and its two results on `status`, and
|
|
188
|
+
* a call site that has to name the right one is a per-site chance to name the
|
|
189
|
+
* wrong one.
|
|
190
|
+
*
|
|
191
|
+
* A missing entry means the generator failed to read the union, not that a
|
|
192
|
+
* caller sent something odd — every caller checks the discriminant with
|
|
193
|
+
* `known()` above this call.
|
|
194
|
+
*/
|
|
195
|
+
export function variantKeys(
|
|
196
|
+
type: string,
|
|
197
|
+
value: Record<string, unknown>,
|
|
198
|
+
): readonly string[] {
|
|
199
|
+
const discriminant = value[SETTINGS_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
200
|
+
const keys = SETTINGS_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
201
|
+
if (keys === undefined) incompatible("unknown_field", { type, discriminant });
|
|
202
|
+
return keys;
|
|
203
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SETTINGS_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
array,
|
|
4
|
+
identity,
|
|
5
|
+
known,
|
|
6
|
+
optionalOpaque,
|
|
7
|
+
record,
|
|
8
|
+
} from "./primitives.ts";
|
|
9
|
+
|
|
10
|
+
export function policy(
|
|
11
|
+
value: unknown,
|
|
12
|
+
maximum: number,
|
|
13
|
+
effects: readonly string[],
|
|
14
|
+
): void {
|
|
15
|
+
const valueRecord = record(value, SETTINGS_FIELDS.SettingsPolicyProjection);
|
|
16
|
+
identity(valueRecord.sourceId);
|
|
17
|
+
known(valueRecord.effect, effects);
|
|
18
|
+
optionalOpaque(valueRecord.constraints, maximum);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function recovery(
|
|
22
|
+
value: unknown,
|
|
23
|
+
maximum: number,
|
|
24
|
+
codes: readonly string[],
|
|
25
|
+
): void {
|
|
26
|
+
const valueRecord = record(value, SETTINGS_FIELDS.SettingsRecoveryState);
|
|
27
|
+
known(valueRecord.code, codes);
|
|
28
|
+
optionalOpaque(valueRecord.diagnostic, maximum);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function activation(
|
|
32
|
+
value: unknown,
|
|
33
|
+
states: readonly string[],
|
|
34
|
+
): void {
|
|
35
|
+
array(value).forEach((value) => {
|
|
36
|
+
const requirement = record(value, SETTINGS_FIELDS.SettingsActivationRequirement);
|
|
37
|
+
identity(requirement.targetId);
|
|
38
|
+
known(requirement.state, states);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function rejection(
|
|
43
|
+
value: unknown,
|
|
44
|
+
maximum: number,
|
|
45
|
+
codes: readonly string[],
|
|
46
|
+
): void {
|
|
47
|
+
const valueRecord = record(value, SETTINGS_FIELDS.SettingsRejection);
|
|
48
|
+
known(valueRecord.code, codes);
|
|
49
|
+
optionalOpaque(valueRecord.diagnostic, maximum);
|
|
50
|
+
}
|