@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,174 @@
|
|
|
1
|
+
import { CONFIG_MAXIMUM_OPAQUE_ID_BYTES } from "../generated/base.ts";
|
|
2
|
+
import { CONFIG_OPERATIONS_PROTOCOL_VERSION } from "../generated/protocol.ts";
|
|
3
|
+
|
|
4
|
+
export type ConfigProtocolValidationCode =
|
|
5
|
+
| "invalid_payload"
|
|
6
|
+
| "unsupported_protocol"
|
|
7
|
+
| "unknown_discriminant";
|
|
8
|
+
|
|
9
|
+
export class ConfigProtocolValidationError extends Error {
|
|
10
|
+
readonly code: ConfigProtocolValidationCode;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
code: ConfigProtocolValidationCode,
|
|
15
|
+
path: string,
|
|
16
|
+
message: string,
|
|
17
|
+
) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "ConfigProtocolValidationError";
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.path = path;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function baseCommand(
|
|
26
|
+
value: unknown,
|
|
27
|
+
path: string,
|
|
28
|
+
allowed?: readonly string[],
|
|
29
|
+
): Record<string, unknown> {
|
|
30
|
+
const command = record(value, path, allowed);
|
|
31
|
+
protocol(command.protocolVersion, `${path}.protocolVersion`);
|
|
32
|
+
opaqueId(command.requestId, `${path}.requestId`);
|
|
33
|
+
return command;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function protocol(value: unknown, path: string): void {
|
|
37
|
+
if (value !== CONFIG_OPERATIONS_PROTOCOL_VERSION) {
|
|
38
|
+
fail(
|
|
39
|
+
"unsupported_protocol",
|
|
40
|
+
path,
|
|
41
|
+
`expected config protocol ${CONFIG_OPERATIONS_PROTOCOL_VERSION}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Rejects a non-object, an unknown key, and a missing key.
|
|
48
|
+
*
|
|
49
|
+
* `allowed` comes from the generated field map, so the keys accepted are the
|
|
50
|
+
* Rust struct's and nothing else — contract 010's Boundary Validation Target.
|
|
51
|
+
* `path` is kept ahead of it because every existing caller passes one and it
|
|
52
|
+
* is what makes a rejection locatable in a nested document.
|
|
53
|
+
*
|
|
54
|
+
* Called without a list, this keeps shape-only behaviour. That is correct for
|
|
55
|
+
* a tagged union, whose allowed keys depend on its discriminant, and it is a
|
|
56
|
+
* gap anywhere else — the remaining untyped call sites are the work left.
|
|
57
|
+
*/
|
|
58
|
+
export function record(
|
|
59
|
+
value: unknown,
|
|
60
|
+
path: string,
|
|
61
|
+
allowed?: readonly string[],
|
|
62
|
+
): Record<string, unknown> {
|
|
63
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
64
|
+
fail("invalid_payload", path, "expected object");
|
|
65
|
+
}
|
|
66
|
+
const result = value as Record<string, unknown>;
|
|
67
|
+
if (allowed === undefined) return result;
|
|
68
|
+
|
|
69
|
+
const permitted = new Set(allowed);
|
|
70
|
+
for (const key of Object.keys(result)) {
|
|
71
|
+
if (!permitted.has(key)) {
|
|
72
|
+
fail("invalid_payload", `${path}.${key}`, "unknown field");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const key of allowed) {
|
|
76
|
+
if (!(key in result)) {
|
|
77
|
+
fail("invalid_payload", `${path}.${key}`, "missing field");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function array(value: unknown, path: string): unknown[] {
|
|
84
|
+
if (!Array.isArray(value)) fail("invalid_payload", path, "expected array");
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function string(
|
|
89
|
+
value: unknown,
|
|
90
|
+
path: string,
|
|
91
|
+
): asserts value is string {
|
|
92
|
+
if (typeof value !== "string") {
|
|
93
|
+
fail("invalid_payload", path, "expected string");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function nonempty(
|
|
98
|
+
value: unknown,
|
|
99
|
+
path: string,
|
|
100
|
+
): asserts value is string {
|
|
101
|
+
string(value, path);
|
|
102
|
+
if (value.length === 0) {
|
|
103
|
+
fail("invalid_payload", path, "expected nonempty string");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function nullableString(value: unknown, path: string): void {
|
|
108
|
+
if (value !== null) string(value, path);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function digest(
|
|
112
|
+
value: unknown,
|
|
113
|
+
path: string,
|
|
114
|
+
): asserts value is string {
|
|
115
|
+
string(value, path);
|
|
116
|
+
if (!/^[0-9a-f]{64}$/.test(value)) {
|
|
117
|
+
fail("invalid_payload", path, "expected lowercase SHA-256 digest");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function nullableDigest(value: unknown, path: string): void {
|
|
122
|
+
if (value !== null) digest(value, path);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function opaqueId(
|
|
126
|
+
value: unknown,
|
|
127
|
+
path: string,
|
|
128
|
+
): asserts value is string {
|
|
129
|
+
string(value, path);
|
|
130
|
+
if (
|
|
131
|
+
value.length === 0 ||
|
|
132
|
+
value.length > CONFIG_MAXIMUM_OPAQUE_ID_BYTES ||
|
|
133
|
+
!/^[a-z0-9._:-]+$/.test(value)
|
|
134
|
+
) {
|
|
135
|
+
fail("invalid_payload", path, "expected bounded lowercase opaque id");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function finiteNumber(
|
|
140
|
+
value: unknown,
|
|
141
|
+
path: string,
|
|
142
|
+
): asserts value is number {
|
|
143
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
144
|
+
fail("invalid_payload", path, "expected non-negative safe integer");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function boolean(
|
|
149
|
+
value: unknown,
|
|
150
|
+
path: string,
|
|
151
|
+
): asserts value is boolean {
|
|
152
|
+
if (typeof value !== "boolean") {
|
|
153
|
+
fail("invalid_payload", path, "expected boolean");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function discriminant(
|
|
158
|
+
value: unknown,
|
|
159
|
+
variants: readonly string[],
|
|
160
|
+
path: string,
|
|
161
|
+
): asserts value is string {
|
|
162
|
+
string(value, path);
|
|
163
|
+
if (!variants.includes(value)) {
|
|
164
|
+
fail("unknown_discriminant", path, `unknown value ${JSON.stringify(value)}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function fail(
|
|
169
|
+
code: ConfigProtocolValidationCode,
|
|
170
|
+
path: string,
|
|
171
|
+
message: string,
|
|
172
|
+
): never {
|
|
173
|
+
throw new ConfigProtocolValidationError(code, path, message);
|
|
174
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { CONFIG_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
BACKUP_ENCRYPTION_STATES,
|
|
4
|
+
BACKUP_PENDING_STATES,
|
|
5
|
+
CONFIG_OPERATION_CAPABILITIES,
|
|
6
|
+
RESTORE_ADAPTER_PARTICIPATION_KINDS,
|
|
7
|
+
RESTORE_CURRENT_EVIDENCE_STATES,
|
|
8
|
+
RESTORE_DOMAIN_COMPATIBILITY_STATUSES,
|
|
9
|
+
RESTORE_IDENTITY_STATUSES,
|
|
10
|
+
STORAGE_BOOTSTRAP_STATES,
|
|
11
|
+
type ConfigOperationsSnapshot,
|
|
12
|
+
} from "../generated/protocol.ts";
|
|
13
|
+
import {
|
|
14
|
+
array,
|
|
15
|
+
boolean,
|
|
16
|
+
digest,
|
|
17
|
+
discriminant,
|
|
18
|
+
finiteNumber,
|
|
19
|
+
nonempty,
|
|
20
|
+
nullableDigest,
|
|
21
|
+
nullableString,
|
|
22
|
+
protocol,
|
|
23
|
+
record,
|
|
24
|
+
string,
|
|
25
|
+
} from "./primitives.ts";
|
|
26
|
+
|
|
27
|
+
const STORAGE_PROFILES = [
|
|
28
|
+
"platform-native-v1",
|
|
29
|
+
"unified-app-root-v1",
|
|
30
|
+
"shared-product-root-v1",
|
|
31
|
+
"portable-v1",
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
export function assertValidConfigOperationsSnapshot(
|
|
35
|
+
value: unknown,
|
|
36
|
+
): asserts value is ConfigOperationsSnapshot {
|
|
37
|
+
const snapshot = record(value, "$", CONFIG_FIELDS.ConfigOperationsSnapshot);
|
|
38
|
+
protocol(snapshot.protocolVersion, "$.protocolVersion");
|
|
39
|
+
finiteNumber(snapshot.generation, "$.generation");
|
|
40
|
+
array(snapshot.capabilities, "$.capabilities").forEach((capability, index) =>
|
|
41
|
+
discriminant(
|
|
42
|
+
capability,
|
|
43
|
+
CONFIG_OPERATION_CAPABILITIES,
|
|
44
|
+
`$.capabilities[${index}]`,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
if (snapshot.storage !== null) storage(snapshot.storage, "$.storage");
|
|
48
|
+
if (snapshot.backup !== null) backup(snapshot.backup, "$.backup");
|
|
49
|
+
if (snapshot.restore !== null) restoreState(snapshot.restore, "$.restore");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function assertRestoreInspection(value: unknown, path: string): void {
|
|
53
|
+
const inspection = record(value, path, CONFIG_FIELDS.RestoreInspectionProjection);
|
|
54
|
+
digest(inspection.archiveSha256, `${path}.archiveSha256`);
|
|
55
|
+
[
|
|
56
|
+
"archiveId",
|
|
57
|
+
"createdAt",
|
|
58
|
+
"kind",
|
|
59
|
+
"applicationVersion",
|
|
60
|
+
"producerVersion",
|
|
61
|
+
].forEach((key) => nonempty(inspection[key], `${path}.${key}`));
|
|
62
|
+
discriminant(inspection.integrity, ["verified"], `${path}.integrity`);
|
|
63
|
+
discriminant(
|
|
64
|
+
inspection.authenticity,
|
|
65
|
+
["unauthenticated", "authenticated"],
|
|
66
|
+
`${path}.authenticity`,
|
|
67
|
+
);
|
|
68
|
+
identity(
|
|
69
|
+
record(
|
|
70
|
+
inspection.identity,
|
|
71
|
+
`${path}.identity`,
|
|
72
|
+
CONFIG_FIELDS.RestoreIdentityProjection,
|
|
73
|
+
),
|
|
74
|
+
`${path}.identity`,
|
|
75
|
+
);
|
|
76
|
+
array(inspection.consistencyGroups, `${path}.consistencyGroups`).forEach(
|
|
77
|
+
(value, index) => {
|
|
78
|
+
const groupPath = `${path}.consistencyGroups[${index}]`;
|
|
79
|
+
const group = record(value, groupPath, CONFIG_FIELDS.RestoreConsistencyGroupProjection);
|
|
80
|
+
["id", "mode", "authority"].forEach((key) =>
|
|
81
|
+
nonempty(group[key], `${groupPath}.${key}`),
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
array(inspection.domains, `${path}.domains`).forEach((value, index) =>
|
|
86
|
+
restoreDomain(value, `${path}.domains[${index}]`),
|
|
87
|
+
);
|
|
88
|
+
array(inspection.exclusions, `${path}.exclusions`).forEach((value, index) => {
|
|
89
|
+
const exclusionPath = `${path}.exclusions[${index}]`;
|
|
90
|
+
const exclusion = record(value, exclusionPath, CONFIG_FIELDS.RestoreExclusionProjection);
|
|
91
|
+
["domainId", "storageClass", "reason"].forEach((key) =>
|
|
92
|
+
nonempty(exclusion[key], `${exclusionPath}.${key}`),
|
|
93
|
+
);
|
|
94
|
+
boolean(exclusion.registered, `${exclusionPath}.registered`);
|
|
95
|
+
});
|
|
96
|
+
countReceipt(inspection.receipt, `${path}.receipt`, [
|
|
97
|
+
"manifestDomains",
|
|
98
|
+
"exclusions",
|
|
99
|
+
"restorable",
|
|
100
|
+
"migrations",
|
|
101
|
+
"adapterRestorable",
|
|
102
|
+
"blocked",
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function assertRestorePlan(value: unknown, path: string): void {
|
|
107
|
+
const plan = record(value, path, CONFIG_FIELDS.RestorePlanProjection);
|
|
108
|
+
digest(plan.archiveSha256, `${path}.archiveSha256`);
|
|
109
|
+
digest(plan.confirmationDigest, `${path}.confirmationDigest`);
|
|
110
|
+
array(plan.entries, `${path}.entries`).forEach((value, index) => {
|
|
111
|
+
const entryPath = `${path}.entries[${index}]`;
|
|
112
|
+
const entry = record(value, entryPath, CONFIG_FIELDS.RestorePlanEntryProjection);
|
|
113
|
+
nonempty(entry.domainId, `${entryPath}.domainId`);
|
|
114
|
+
discriminant(
|
|
115
|
+
entry.choice,
|
|
116
|
+
["useArchive", "keepCurrent"],
|
|
117
|
+
`${entryPath}.choice`,
|
|
118
|
+
);
|
|
119
|
+
nullableString(entry.action, `${entryPath}.action`);
|
|
120
|
+
if (entry.current !== null) currentEvidence(entry.current, `${entryPath}.current`);
|
|
121
|
+
});
|
|
122
|
+
countReceipt(plan.receipt, `${path}.receipt`, [
|
|
123
|
+
"selected",
|
|
124
|
+
"skipped",
|
|
125
|
+
"creates",
|
|
126
|
+
"replaces",
|
|
127
|
+
"deletes",
|
|
128
|
+
"migrations",
|
|
129
|
+
"unchanged",
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function assertRestoreExecutionReceipt(
|
|
134
|
+
value: unknown,
|
|
135
|
+
path: string,
|
|
136
|
+
): void {
|
|
137
|
+
const receipt = record(value, path, CONFIG_FIELDS.RestoreExecutionReceiptProjection);
|
|
138
|
+
digest(receipt.confirmationDigest, `${path}.confirmationDigest`);
|
|
139
|
+
countReceipt(receipt.staging, `${path}.staging`, [
|
|
140
|
+
"selected",
|
|
141
|
+
"documents",
|
|
142
|
+
"deletions",
|
|
143
|
+
"unchanged",
|
|
144
|
+
"totalDocumentBytes",
|
|
145
|
+
]);
|
|
146
|
+
publication(receipt.safetyBackup, `${path}.safetyBackup`);
|
|
147
|
+
[
|
|
148
|
+
"restoredDomainIds",
|
|
149
|
+
"deletedDomainIds",
|
|
150
|
+
"migratedDomainIds",
|
|
151
|
+
"unchangedDomainIds",
|
|
152
|
+
"skippedDomainIds",
|
|
153
|
+
"excludedDomainIds",
|
|
154
|
+
].forEach((key) => stringArray(receipt[key], `${path}.${key}`));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function assertRestoreFailure(value: unknown, path: string): void {
|
|
158
|
+
const failure = record(value, path, CONFIG_FIELDS.RestoreExecutionFailureProjection);
|
|
159
|
+
nonempty(failure.stage, `${path}.stage`);
|
|
160
|
+
nullableString(failure.domainId, `${path}.domainId`);
|
|
161
|
+
discriminant(
|
|
162
|
+
failure.terminal,
|
|
163
|
+
["noLiveMutation", "rolledBack", "recoveryRequired"],
|
|
164
|
+
`${path}.terminal`,
|
|
165
|
+
);
|
|
166
|
+
string(failure.detail, `${path}.detail`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function assertRestoreAdapterReceipt(
|
|
170
|
+
value: unknown,
|
|
171
|
+
path: string,
|
|
172
|
+
): void {
|
|
173
|
+
const receipt = record(value, path, CONFIG_FIELDS.RestoreAdapterReceiptProjection);
|
|
174
|
+
["domainId", "adapter", "outcome"].forEach((key) =>
|
|
175
|
+
nonempty(receipt[key], `${path}.${key}`),
|
|
176
|
+
);
|
|
177
|
+
participation(receipt.participation, `${path}.participation`);
|
|
178
|
+
digest(receipt.confirmationDigest, `${path}.confirmationDigest`);
|
|
179
|
+
nullableDigest(receipt.evidence, `${path}.evidence`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function assertRestoreRecoveryReceipt(
|
|
183
|
+
value: unknown,
|
|
184
|
+
path: string,
|
|
185
|
+
): void {
|
|
186
|
+
const receipt = record(value, path, CONFIG_FIELDS.RestoreRecoveryReceiptProjection);
|
|
187
|
+
discriminant(
|
|
188
|
+
receipt.outcome,
|
|
189
|
+
["noRecoveryNeeded", "rolledBack", "terminalCleanup"],
|
|
190
|
+
`${path}.outcome`,
|
|
191
|
+
);
|
|
192
|
+
stringArray(receipt.domainIds, `${path}.domainIds`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function assertPublication(value: unknown, path: string): void {
|
|
196
|
+
publication(value, path);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function storage(value: unknown, path: string): void {
|
|
200
|
+
const projection = record(value, path, CONFIG_FIELDS.StorageOperationsProjection);
|
|
201
|
+
const layout = record(projection.layout, `${path}.layout`, CONFIG_FIELDS.StorageLayoutProjection);
|
|
202
|
+
discriminant(layout.profile, STORAGE_PROFILES, `${path}.layout.profile`);
|
|
203
|
+
["platform", "canonicalApplicationId", "effectiveLeaf"].forEach((key) =>
|
|
204
|
+
nonempty(layout[key], `${path}.layout.${key}`),
|
|
205
|
+
);
|
|
206
|
+
digest(layout.layoutDigest, `${path}.layout.layoutDigest`);
|
|
207
|
+
array(layout.roots, `${path}.layout.roots`).forEach((rootValue, index) => {
|
|
208
|
+
const root = record(rootValue, `${path}.layout.roots[${index}]`, CONFIG_FIELDS.StorageRootProjection);
|
|
209
|
+
["kind", "path", "provenance"].forEach((key) =>
|
|
210
|
+
nonempty(root[key], `${path}.layout.roots[${index}].${key}`),
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
const bootstrap = record(projection.bootstrap, `${path}.bootstrap`);
|
|
214
|
+
discriminant(bootstrap.state, STORAGE_BOOTSTRAP_STATES, `${path}.bootstrap.state`);
|
|
215
|
+
array(projection.availableProfiles, `${path}.availableProfiles`).forEach(
|
|
216
|
+
(profile, index) =>
|
|
217
|
+
discriminant(profile, STORAGE_PROFILES, `${path}.availableProfiles[${index}]`),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function backup(value: unknown, path: string): void {
|
|
222
|
+
const projection = record(value, path, CONFIG_FIELDS.BackupOperationsProjection);
|
|
223
|
+
const inventory = record(projection.inventory, `${path}.inventory`, CONFIG_FIELDS.BackupInventoryProjection);
|
|
224
|
+
nonempty(inventory.root, `${path}.inventory.root`);
|
|
225
|
+
array(inventory.archives, `${path}.inventory.archives`).forEach(
|
|
226
|
+
(archiveValue, index) => {
|
|
227
|
+
const archivePath = `${path}.inventory.archives[${index}]`;
|
|
228
|
+
const archive = record(archiveValue, archivePath, CONFIG_FIELDS.BackupArchiveProjection);
|
|
229
|
+
["path", "archiveId", "createdAt", "kind"].forEach((key) =>
|
|
230
|
+
nonempty(archive[key], `${archivePath}.${key}`),
|
|
231
|
+
);
|
|
232
|
+
digest(archive.archiveSha256, `${archivePath}.archiveSha256`);
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
array(inventory.entries, `${path}.inventory.entries`).forEach(
|
|
236
|
+
(entryValue, index) =>
|
|
237
|
+
inventoryEntry(entryValue, `${path}.inventory.entries[${index}]`),
|
|
238
|
+
);
|
|
239
|
+
boolean(inventory.complete, `${path}.inventory.complete`);
|
|
240
|
+
const pending = record(projection.pending, `${path}.pending`);
|
|
241
|
+
discriminant(pending.state, BACKUP_PENDING_STATES, `${path}.pending.state`);
|
|
242
|
+
const encryption = record(projection.encryption, `${path}.encryption`);
|
|
243
|
+
discriminant(encryption.state, BACKUP_ENCRYPTION_STATES, `${path}.encryption.state`);
|
|
244
|
+
if (projection.retention !== null) {
|
|
245
|
+
const retention = record(projection.retention, `${path}.retention`, CONFIG_FIELDS.BackupRetentionProjection);
|
|
246
|
+
stringArray(retention.deletionPaths, `${path}.retention.deletionPaths`);
|
|
247
|
+
digest(retention.confirmationDigest, `${path}.retention.confirmationDigest`);
|
|
248
|
+
array(retention.diagnostics, `${path}.retention.diagnostics`).forEach(
|
|
249
|
+
(entryValue, index) =>
|
|
250
|
+
inventoryEntry(entryValue, `${path}.retention.diagnostics[${index}]`),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function restoreState(value: unknown, path: string): void {
|
|
256
|
+
const projection = record(value, path, CONFIG_FIELDS.RestoreOperationsProjection);
|
|
257
|
+
discriminant(
|
|
258
|
+
projection.state,
|
|
259
|
+
["inactive", "active", "recoveryRequired"],
|
|
260
|
+
`${path}.state`,
|
|
261
|
+
);
|
|
262
|
+
nullableDigest(projection.safetyBackupSha256, `${path}.safetyBackupSha256`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function identity(value: Record<string, unknown>, path: string): void {
|
|
266
|
+
["application", "producer"].forEach((key) => {
|
|
267
|
+
const statusPath = `${path}.${key}`;
|
|
268
|
+
const status = record(value[key], statusPath);
|
|
269
|
+
discriminant(status.status, RESTORE_IDENTITY_STATUSES, `${statusPath}.status`);
|
|
270
|
+
if (status.status === "mismatch") {
|
|
271
|
+
nonempty(status.expected, `${statusPath}.expected`);
|
|
272
|
+
nonempty(status.archive, `${statusPath}.archive`);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function restoreDomain(value: unknown, path: string): void {
|
|
278
|
+
const domain = record(value, path, CONFIG_FIELDS.RestoreDomainInspectionProjection);
|
|
279
|
+
["domainId", "storageClass", "consistencyGroup", "adapter", "sourceState"].forEach(
|
|
280
|
+
(key) => nonempty(domain[key], `${path}.${key}`),
|
|
281
|
+
);
|
|
282
|
+
if (domain.sourceSchemaVersion !== null) {
|
|
283
|
+
finiteNumber(domain.sourceSchemaVersion, `${path}.sourceSchemaVersion`);
|
|
284
|
+
}
|
|
285
|
+
if (domain.targetSchemaVersion !== null) {
|
|
286
|
+
finiteNumber(domain.targetSchemaVersion, `${path}.targetSchemaVersion`);
|
|
287
|
+
}
|
|
288
|
+
const compatibility = record(domain.compatibility, `${path}.compatibility`);
|
|
289
|
+
discriminant(
|
|
290
|
+
compatibility.status,
|
|
291
|
+
RESTORE_DOMAIN_COMPATIBILITY_STATUSES,
|
|
292
|
+
`${path}.compatibility.status`,
|
|
293
|
+
);
|
|
294
|
+
if (compatibility.status === "migrationRequired") {
|
|
295
|
+
finiteNumber(compatibility.from, `${path}.compatibility.from`);
|
|
296
|
+
finiteNumber(compatibility.to, `${path}.compatibility.to`);
|
|
297
|
+
}
|
|
298
|
+
if (compatibility.status === "customAdapterReady") {
|
|
299
|
+
nonempty(compatibility.adapter, `${path}.compatibility.adapter`);
|
|
300
|
+
participation(compatibility.participation, `${path}.compatibility.participation`);
|
|
301
|
+
digest(compatibility.confirmationDigest, `${path}.compatibility.confirmationDigest`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function participation(value: unknown, path: string): void {
|
|
306
|
+
const projection = record(value, path);
|
|
307
|
+
discriminant(
|
|
308
|
+
projection.kind,
|
|
309
|
+
RESTORE_ADAPTER_PARTICIPATION_KINDS,
|
|
310
|
+
`${path}.kind`,
|
|
311
|
+
);
|
|
312
|
+
if (projection.kind === "excluded") nonempty(projection.reason, `${path}.reason`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function currentEvidence(value: unknown, path: string): void {
|
|
316
|
+
const evidence = record(value, path);
|
|
317
|
+
discriminant(evidence.state, RESTORE_CURRENT_EVIDENCE_STATES, `${path}.state`);
|
|
318
|
+
if (evidence.state === "present") {
|
|
319
|
+
finiteNumber(evidence.byteLength, `${path}.byteLength`);
|
|
320
|
+
digest(evidence.sha256, `${path}.sha256`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function inventoryEntry(value: unknown, path: string): void {
|
|
325
|
+
const entry = record(value, path, CONFIG_FIELDS.BackupInventoryEntry);
|
|
326
|
+
discriminant(
|
|
327
|
+
entry.state,
|
|
328
|
+
["valid", "locked", "corrupt", "foreign", "unknown", "unreadable", "unmanaged"],
|
|
329
|
+
`${path}.state`,
|
|
330
|
+
);
|
|
331
|
+
nonempty(entry.diagnosticKind, `${path}.diagnosticKind`);
|
|
332
|
+
string(entry.detail, `${path}.detail`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function publication(value: unknown, path: string): void {
|
|
336
|
+
const receipt = record(value, path, CONFIG_FIELDS.BackupPublicationReceiptProjection);
|
|
337
|
+
["path", "destination", "durability"].forEach((key) =>
|
|
338
|
+
nonempty(receipt[key], `${path}.${key}`),
|
|
339
|
+
);
|
|
340
|
+
digest(receipt.archiveSha256, `${path}.archiveSha256`);
|
|
341
|
+
boolean(receipt.replacedExisting, `${path}.replacedExisting`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function countReceipt(value: unknown, path: string, keys: string[]): void {
|
|
345
|
+
const receipt = record(value, path);
|
|
346
|
+
keys.forEach((key) => finiteNumber(receipt[key], `${path}.${key}`));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function stringArray(value: unknown, path: string): void {
|
|
350
|
+
array(value, path).forEach((item, index) => nonempty(item, `${path}[${index}]`));
|
|
351
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ConfigProtocolValidationError,
|
|
3
|
+
type ConfigProtocolValidationCode,
|
|
4
|
+
} from "./validation/primitives.ts";
|
|
5
|
+
export * from "./validation/commands.ts";
|
|
6
|
+
export * from "./validation/outcomes.ts";
|
|
7
|
+
export { assertValidConfigOperationsSnapshot } from "./validation/projection.ts";
|