@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,129 @@
|
|
|
1
|
+
// @generated by `effigy generate:config`; do not edit.
|
|
2
|
+
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
|
+
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
|
+
// each list, because `exact()` compares every key.
|
|
5
|
+
|
|
6
|
+
export const CONFIG_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"StorageBootstrapProjection": {
|
|
8
|
+
"selected": ["state", "origin", "locatorPath", "transitionId", "lastCommittedLayoutDigest"],
|
|
9
|
+
"recoveryRequired": ["state", "kind", "detail", "locatorPath", "journalPath"],
|
|
10
|
+
},
|
|
11
|
+
"BackupPendingState": {
|
|
12
|
+
"clear": ["state"],
|
|
13
|
+
"pending": ["state", "domainCount", "domainIds"],
|
|
14
|
+
},
|
|
15
|
+
"BackupEncryptionState": {
|
|
16
|
+
"unavailable": ["state"],
|
|
17
|
+
"available": ["state", "provider"],
|
|
18
|
+
"interactionRequired": ["state", "provider"],
|
|
19
|
+
"failed": ["state", "provider", "detail"],
|
|
20
|
+
},
|
|
21
|
+
"StorageTransitionInspectOutcome": {
|
|
22
|
+
"ready": ["status", "generation", "preview"],
|
|
23
|
+
"rejected": ["status", "rejection"],
|
|
24
|
+
},
|
|
25
|
+
"StorageTransitionExecuteOutcome": {
|
|
26
|
+
"committed": ["status", "receipt", "snapshot"],
|
|
27
|
+
"rejected": ["status", "rejection"],
|
|
28
|
+
},
|
|
29
|
+
"StorageRecoveryOutcome": {
|
|
30
|
+
"recovered": ["status", "receipt", "snapshot"],
|
|
31
|
+
"rejected": ["status", "rejection"],
|
|
32
|
+
},
|
|
33
|
+
"StorageCleanupOutcome": {
|
|
34
|
+
"applied": ["status", "receipt", "snapshot"],
|
|
35
|
+
"rejected": ["status", "rejection"],
|
|
36
|
+
},
|
|
37
|
+
"BackupCreateOutcome": {
|
|
38
|
+
"published": ["status", "capture", "publication", "snapshot"],
|
|
39
|
+
"rejected": ["status", "rejection"],
|
|
40
|
+
},
|
|
41
|
+
"BackupExportOutcome": {
|
|
42
|
+
"published": ["status", "publication", "snapshot"],
|
|
43
|
+
"rejected": ["status", "rejection"],
|
|
44
|
+
},
|
|
45
|
+
"BackupRetentionApplyOutcome": {
|
|
46
|
+
"applied": ["status", "deletedPaths", "snapshot"],
|
|
47
|
+
"rejected": ["status", "rejection"],
|
|
48
|
+
},
|
|
49
|
+
"RestoreArchiveSelection": {
|
|
50
|
+
"inventory": ["source", "archiveSha256"],
|
|
51
|
+
"hostPicker": ["source"],
|
|
52
|
+
},
|
|
53
|
+
"RestoreIdentityStatusProjection": {
|
|
54
|
+
"compatible": ["status"],
|
|
55
|
+
"mismatch": ["status", "expected", "archive"],
|
|
56
|
+
},
|
|
57
|
+
"RestoreDomainCompatibilityProjection": {
|
|
58
|
+
"ready": ["status"],
|
|
59
|
+
"migrationRequired": ["status", "from", "to"],
|
|
60
|
+
"unknownDomain": ["status"],
|
|
61
|
+
"descriptorMismatch": ["status"],
|
|
62
|
+
"domainCodeUnavailable": ["status"],
|
|
63
|
+
"policyExcluded": ["status", "reason"],
|
|
64
|
+
"customAdapterUnavailable": ["status", "adapter"],
|
|
65
|
+
"customAdapterReady": ["status", "adapter", "participation", "confirmationDigest"],
|
|
66
|
+
"customAdapterRejected": ["status", "adapter", "detail"],
|
|
67
|
+
"targetUnavailable": ["status", "reason"],
|
|
68
|
+
"sourcePreserved": ["status", "issue"],
|
|
69
|
+
"sourceRejected": ["status", "issue"],
|
|
70
|
+
"targetPreparationFailed": ["status", "detail"],
|
|
71
|
+
},
|
|
72
|
+
"RestoreAdapterParticipationProjection": {
|
|
73
|
+
"excluded": ["kind", "reason"],
|
|
74
|
+
"separate": ["kind"],
|
|
75
|
+
"failureAtomic": ["kind"],
|
|
76
|
+
"groupedFailureAtomic": ["kind"],
|
|
77
|
+
},
|
|
78
|
+
"RestoreInspectOutcome": {
|
|
79
|
+
"ready": ["status", "generation", "inspection"],
|
|
80
|
+
"locked": ["status", "detail"],
|
|
81
|
+
"rejected": ["status", "rejection"],
|
|
82
|
+
},
|
|
83
|
+
"RestoreCurrentEvidenceProjection": {
|
|
84
|
+
"absent": ["state"],
|
|
85
|
+
"present": ["state", "byteLength", "sha256"],
|
|
86
|
+
},
|
|
87
|
+
"RestorePlanOutcome": {
|
|
88
|
+
"ready": ["status", "generation", "plan"],
|
|
89
|
+
"rejected": ["status", "rejection"],
|
|
90
|
+
},
|
|
91
|
+
"RestoreExecuteOutcome": {
|
|
92
|
+
"succeeded": ["status", "receipt", "snapshot"],
|
|
93
|
+
"rolledBack": ["status", "failure", "snapshot"],
|
|
94
|
+
"recoveryRequired": ["status", "failure", "snapshot"],
|
|
95
|
+
"rejected": ["status", "rejection"],
|
|
96
|
+
},
|
|
97
|
+
"RestoreAdapterExecuteOutcome": {
|
|
98
|
+
"completed": ["status", "receipt", "snapshot"],
|
|
99
|
+
"rejected": ["status", "rejection"],
|
|
100
|
+
},
|
|
101
|
+
"RestoreRecoveryOutcomeProjection": {
|
|
102
|
+
"recovered": ["status", "receipt", "snapshot"],
|
|
103
|
+
"recoveryRequired": ["status", "failure", "snapshot"],
|
|
104
|
+
"rejected": ["status", "rejection"],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const CONFIG_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
109
|
+
"StorageBootstrapProjection": "state",
|
|
110
|
+
"BackupPendingState": "state",
|
|
111
|
+
"BackupEncryptionState": "state",
|
|
112
|
+
"StorageTransitionInspectOutcome": "status",
|
|
113
|
+
"StorageTransitionExecuteOutcome": "status",
|
|
114
|
+
"StorageRecoveryOutcome": "status",
|
|
115
|
+
"StorageCleanupOutcome": "status",
|
|
116
|
+
"BackupCreateOutcome": "status",
|
|
117
|
+
"BackupExportOutcome": "status",
|
|
118
|
+
"BackupRetentionApplyOutcome": "status",
|
|
119
|
+
"RestoreArchiveSelection": "source",
|
|
120
|
+
"RestoreIdentityStatusProjection": "status",
|
|
121
|
+
"RestoreDomainCompatibilityProjection": "status",
|
|
122
|
+
"RestoreAdapterParticipationProjection": "kind",
|
|
123
|
+
"RestoreInspectOutcome": "status",
|
|
124
|
+
"RestoreCurrentEvidenceProjection": "state",
|
|
125
|
+
"RestorePlanOutcome": "status",
|
|
126
|
+
"RestoreExecuteOutcome": "status",
|
|
127
|
+
"RestoreAdapterExecuteOutcome": "status",
|
|
128
|
+
"RestoreRecoveryOutcomeProjection": "status",
|
|
129
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./generated/protocol.ts";
|
|
2
|
+
// The generated field map is public API. A consumer that mirrors these
|
|
3
|
+
// types structurally -- Poodle does, because it may not depend on Longhorn --
|
|
4
|
+
// has no compile-time link to them, so a field added here is silent on their
|
|
5
|
+
// side. Whoever sees both can assert their shape against this map and fail
|
|
6
|
+
// when it drifts.
|
|
7
|
+
export * from "./generated/fields.ts";
|
|
8
|
+
export * from "./generated/labels.ts";
|
|
9
|
+
export * from "./generated/label-template.ts";
|
|
10
|
+
export * from "./client.ts";
|
|
11
|
+
export * from "./validation.ts";
|
|
12
|
+
export * from "./names.ts";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const CONFIG_SNAPSHOT_COMMAND = "longhorn_config_snapshot";
|
|
2
|
+
export const CONFIG_STORAGE_INSPECT_COMMAND =
|
|
3
|
+
"longhorn_config_storage_inspect";
|
|
4
|
+
export const CONFIG_STORAGE_EXECUTE_COMMAND =
|
|
5
|
+
"longhorn_config_storage_execute";
|
|
6
|
+
export const CONFIG_STORAGE_RECOVER_COMMAND =
|
|
7
|
+
"longhorn_config_storage_recover";
|
|
8
|
+
export const CONFIG_STORAGE_CLEANUP_COMMAND =
|
|
9
|
+
"longhorn_config_storage_cleanup";
|
|
10
|
+
export const CONFIG_BACKUP_CREATE_COMMAND = "longhorn_config_backup_create";
|
|
11
|
+
export const CONFIG_BACKUP_EXPORT_COMMAND = "longhorn_config_backup_export";
|
|
12
|
+
export const CONFIG_BACKUP_RETENTION_COMMAND =
|
|
13
|
+
"longhorn_config_backup_retention";
|
|
14
|
+
export const CONFIG_RESTORE_INSPECT_COMMAND = "longhorn_config_restore_inspect";
|
|
15
|
+
export const CONFIG_RESTORE_PLAN_COMMAND = "longhorn_config_restore_plan";
|
|
16
|
+
export const CONFIG_RESTORE_EXECUTE_COMMAND = "longhorn_config_restore_execute";
|
|
17
|
+
export const CONFIG_RESTORE_ADAPTER_EXECUTE_COMMAND =
|
|
18
|
+
"longhorn_config_restore_adapter_execute";
|
|
19
|
+
export const CONFIG_RESTORE_RECOVER_COMMAND = "longhorn_config_restore_recover";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { CONFIG_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import type {
|
|
3
|
+
BackupCreateCommand,
|
|
4
|
+
BackupExportCommand,
|
|
5
|
+
BackupRetentionApplyCommand,
|
|
6
|
+
ConfigSnapshotCommand,
|
|
7
|
+
RestoreAdapterExecuteCommand,
|
|
8
|
+
RestoreExecuteCommand,
|
|
9
|
+
RestoreInspectCommand,
|
|
10
|
+
RestorePlanCommand,
|
|
11
|
+
RestoreRecoveryCommand,
|
|
12
|
+
StorageCleanupCommand,
|
|
13
|
+
StorageRecoveryCommand,
|
|
14
|
+
StorageTransitionExecuteCommand,
|
|
15
|
+
StorageTransitionInspectCommand,
|
|
16
|
+
} from "../generated/protocol.ts";
|
|
17
|
+
import {
|
|
18
|
+
RESTORE_ARCHIVE_SELECTION_SOURCES,
|
|
19
|
+
} from "../generated/protocol.ts";
|
|
20
|
+
import {
|
|
21
|
+
array,
|
|
22
|
+
baseCommand,
|
|
23
|
+
boolean,
|
|
24
|
+
digest,
|
|
25
|
+
discriminant,
|
|
26
|
+
finiteNumber,
|
|
27
|
+
nonempty,
|
|
28
|
+
record,
|
|
29
|
+
} from "./primitives.ts";
|
|
30
|
+
|
|
31
|
+
const STORAGE_PROFILES = [
|
|
32
|
+
"platform-native-v1",
|
|
33
|
+
"unified-app-root-v1",
|
|
34
|
+
"shared-product-root-v1",
|
|
35
|
+
"portable-v1",
|
|
36
|
+
] as const;
|
|
37
|
+
const RESTORE_CHOICES = ["useArchive", "keepCurrent"] as const;
|
|
38
|
+
|
|
39
|
+
export function assertValidConfigSnapshotCommand(
|
|
40
|
+
value: unknown,
|
|
41
|
+
): asserts value is ConfigSnapshotCommand {
|
|
42
|
+
baseCommand(value, "$", CONFIG_FIELDS.ConfigSnapshotCommand);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function assertValidStorageTransitionInspectCommand(
|
|
46
|
+
value: unknown,
|
|
47
|
+
): asserts value is StorageTransitionInspectCommand {
|
|
48
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.StorageTransitionInspectCommand);
|
|
49
|
+
discriminant(command.targetProfile, STORAGE_PROFILES, "$.targetProfile");
|
|
50
|
+
boolean(command.includeLogs, "$.includeLogs");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function assertValidStorageTransitionExecuteCommand(
|
|
54
|
+
value: unknown,
|
|
55
|
+
): asserts value is StorageTransitionExecuteCommand {
|
|
56
|
+
generationConfirmationCommand(value, CONFIG_FIELDS.StorageTransitionExecuteCommand);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function assertValidStorageRecoveryCommand(
|
|
60
|
+
value: unknown,
|
|
61
|
+
): asserts value is StorageRecoveryCommand {
|
|
62
|
+
baseCommand(value, "$", CONFIG_FIELDS.StorageRecoveryCommand);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function assertValidStorageCleanupCommand(
|
|
66
|
+
value: unknown,
|
|
67
|
+
): asserts value is StorageCleanupCommand {
|
|
68
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.StorageCleanupCommand);
|
|
69
|
+
nonempty(command.transitionId, "$.transitionId");
|
|
70
|
+
digest(command.transitionReceiptDigest, "$.transitionReceiptDigest");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function assertValidBackupCreateCommand(
|
|
74
|
+
value: unknown,
|
|
75
|
+
): asserts value is BackupCreateCommand {
|
|
76
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.BackupCreateCommand);
|
|
77
|
+
discriminant(command.pendingPolicy, ["refuse", "flush"], "$.pendingPolicy");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function assertValidBackupExportCommand(
|
|
81
|
+
value: unknown,
|
|
82
|
+
): asserts value is BackupExportCommand {
|
|
83
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.BackupExportCommand);
|
|
84
|
+
digest(command.archiveSha256, "$.archiveSha256");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function assertValidBackupRetentionApplyCommand(
|
|
88
|
+
value: unknown,
|
|
89
|
+
): asserts value is BackupRetentionApplyCommand {
|
|
90
|
+
generationConfirmationCommand(value, CONFIG_FIELDS.BackupRetentionApplyCommand);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function assertValidRestoreInspectCommand(
|
|
94
|
+
value: unknown,
|
|
95
|
+
): asserts value is RestoreInspectCommand {
|
|
96
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.RestoreInspectCommand);
|
|
97
|
+
const selection = record(command.selection, "$.selection");
|
|
98
|
+
discriminant(
|
|
99
|
+
selection.source,
|
|
100
|
+
RESTORE_ARCHIVE_SELECTION_SOURCES,
|
|
101
|
+
"$.selection.source",
|
|
102
|
+
);
|
|
103
|
+
if (selection.source === "inventory") {
|
|
104
|
+
digest(selection.archiveSha256, "$.selection.archiveSha256");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function assertValidRestorePlanCommand(
|
|
109
|
+
value: unknown,
|
|
110
|
+
): asserts value is RestorePlanCommand {
|
|
111
|
+
const command = baseCommand(value, "$", CONFIG_FIELDS.RestorePlanCommand);
|
|
112
|
+
finiteNumber(command.generation, "$.generation");
|
|
113
|
+
digest(command.archiveSha256, "$.archiveSha256");
|
|
114
|
+
array(command.choices, "$.choices").forEach((choiceValue, index) => {
|
|
115
|
+
const path = `$.choices[${index}]`;
|
|
116
|
+
const choice = record(choiceValue, path, CONFIG_FIELDS.RestoreDomainChoice);
|
|
117
|
+
nonempty(choice.domainId, `${path}.domainId`);
|
|
118
|
+
discriminant(choice.choice, RESTORE_CHOICES, `${path}.choice`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function assertValidRestoreExecuteCommand(
|
|
123
|
+
value: unknown,
|
|
124
|
+
): asserts value is RestoreExecuteCommand {
|
|
125
|
+
generationConfirmationCommand(value, CONFIG_FIELDS.RestoreExecuteCommand);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function assertValidRestoreAdapterExecuteCommand(
|
|
129
|
+
value: unknown,
|
|
130
|
+
): asserts value is RestoreAdapterExecuteCommand {
|
|
131
|
+
const command = generationConfirmationCommand(value, CONFIG_FIELDS.RestoreAdapterExecuteCommand);
|
|
132
|
+
digest(command.archiveSha256, "$.archiveSha256");
|
|
133
|
+
nonempty(command.domainId, "$.domainId");
|
|
134
|
+
discriminant(
|
|
135
|
+
command.requirement,
|
|
136
|
+
["failureAtomic", "allowSeparate"],
|
|
137
|
+
"$.requirement",
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function assertValidRestoreRecoveryCommand(
|
|
142
|
+
value: unknown,
|
|
143
|
+
): asserts value is RestoreRecoveryCommand {
|
|
144
|
+
baseCommand(value, "$", CONFIG_FIELDS.RestoreRecoveryCommand);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function generationConfirmationCommand(
|
|
148
|
+
value: unknown,
|
|
149
|
+
allowed?: readonly string[],
|
|
150
|
+
): Record<string, unknown> {
|
|
151
|
+
const command = baseCommand(value, "$", allowed);
|
|
152
|
+
finiteNumber(command.generation, "$.generation");
|
|
153
|
+
digest(command.confirmationDigest, "$.confirmationDigest");
|
|
154
|
+
return command;
|
|
155
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONFIG_VARIANT_FIELDS,
|
|
3
|
+
CONFIG_VARIANT_FIELDS_DISCRIMINANTS,
|
|
4
|
+
} from "../generated/variant-fields.ts";
|
|
5
|
+
import { CONFIG_FIELDS } from "../generated/fields.ts";
|
|
6
|
+
import {
|
|
7
|
+
BACKUP_CREATE_STATUSES,
|
|
8
|
+
BACKUP_EXPORT_STATUSES,
|
|
9
|
+
BACKUP_RETENTION_APPLY_STATUSES,
|
|
10
|
+
CONFIG_OPERATION_REJECTION_CODES,
|
|
11
|
+
RESTORE_ADAPTER_EXECUTE_STATUSES,
|
|
12
|
+
RESTORE_EXECUTE_STATUSES,
|
|
13
|
+
RESTORE_INSPECT_STATUSES,
|
|
14
|
+
RESTORE_PLAN_STATUSES,
|
|
15
|
+
RESTORE_RECOVERY_STATUSES,
|
|
16
|
+
STORAGE_CLEANUP_STATUSES,
|
|
17
|
+
STORAGE_RECOVERY_STATUSES,
|
|
18
|
+
STORAGE_TRANSITION_EXECUTE_STATUSES,
|
|
19
|
+
STORAGE_TRANSITION_INSPECT_STATUSES,
|
|
20
|
+
type BackupCreateOutcome,
|
|
21
|
+
type BackupExportOutcome,
|
|
22
|
+
type BackupRetentionApplyOutcome,
|
|
23
|
+
type RestoreAdapterExecuteOutcome,
|
|
24
|
+
type RestoreExecuteOutcome,
|
|
25
|
+
type RestoreInspectOutcome,
|
|
26
|
+
type RestorePlanOutcome,
|
|
27
|
+
type RestoreRecoveryOutcomeProjection,
|
|
28
|
+
type StorageCleanupOutcome,
|
|
29
|
+
type StorageRecoveryOutcome,
|
|
30
|
+
type StorageTransitionExecuteOutcome,
|
|
31
|
+
type StorageTransitionInspectOutcome,
|
|
32
|
+
} from "../generated/protocol.ts";
|
|
33
|
+
import {
|
|
34
|
+
assertValidConfigOperationsSnapshot,
|
|
35
|
+
assertRestoreAdapterReceipt,
|
|
36
|
+
assertRestoreExecutionReceipt,
|
|
37
|
+
assertRestoreFailure,
|
|
38
|
+
assertRestoreInspection,
|
|
39
|
+
assertRestorePlan,
|
|
40
|
+
assertRestoreRecoveryReceipt,
|
|
41
|
+
} from "./projection.ts";
|
|
42
|
+
import {
|
|
43
|
+
array,
|
|
44
|
+
digest,
|
|
45
|
+
discriminant,
|
|
46
|
+
finiteNumber,
|
|
47
|
+
record,
|
|
48
|
+
string,
|
|
49
|
+
fail,
|
|
50
|
+
} from "./primitives.ts";
|
|
51
|
+
|
|
52
|
+
export function assertValidStorageTransitionInspectOutcome(
|
|
53
|
+
value: unknown,
|
|
54
|
+
): asserts value is StorageTransitionInspectOutcome {
|
|
55
|
+
outcome(value, STORAGE_TRANSITION_INSPECT_STATUSES, "$", "StorageTransitionInspectOutcome");
|
|
56
|
+
const result = record(value, "$");
|
|
57
|
+
if (result.status === "ready") {
|
|
58
|
+
finiteNumber(result.generation, "$.generation");
|
|
59
|
+
const preview = record(
|
|
60
|
+
result.preview,
|
|
61
|
+
"$.preview",
|
|
62
|
+
CONFIG_FIELDS.StorageTransitionPreviewProjection,
|
|
63
|
+
);
|
|
64
|
+
[
|
|
65
|
+
"sourceLayoutDigest",
|
|
66
|
+
"targetLayoutDigest",
|
|
67
|
+
"evidenceDigest",
|
|
68
|
+
"confirmationDigest",
|
|
69
|
+
].forEach((key) => digest(preview[key], `$.preview.${key}`));
|
|
70
|
+
array(preview.domains, "$.preview.domains");
|
|
71
|
+
array(preview.unknownSourcePaths, "$.preview.unknownSourcePaths");
|
|
72
|
+
array(preview.conflicts, "$.preview.conflicts");
|
|
73
|
+
} else {
|
|
74
|
+
rejection(result.rejection, "$.rejection");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function assertValidStorageTransitionExecuteOutcome(
|
|
79
|
+
value: unknown,
|
|
80
|
+
): asserts value is StorageTransitionExecuteOutcome {
|
|
81
|
+
mutationOutcome(value, STORAGE_TRANSITION_EXECUTE_STATUSES, "committed", "StorageTransitionExecuteOutcome");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function assertValidStorageRecoveryOutcome(
|
|
85
|
+
value: unknown,
|
|
86
|
+
): asserts value is StorageRecoveryOutcome {
|
|
87
|
+
mutationOutcome(value, STORAGE_RECOVERY_STATUSES, "recovered", "StorageRecoveryOutcome");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function assertValidStorageCleanupOutcome(
|
|
91
|
+
value: unknown,
|
|
92
|
+
): asserts value is StorageCleanupOutcome {
|
|
93
|
+
mutationOutcome(value, STORAGE_CLEANUP_STATUSES, "applied", "StorageCleanupOutcome");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function assertValidBackupCreateOutcome(
|
|
97
|
+
value: unknown,
|
|
98
|
+
): asserts value is BackupCreateOutcome {
|
|
99
|
+
mutationOutcome(value, BACKUP_CREATE_STATUSES, "published", "BackupCreateOutcome");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function assertValidBackupExportOutcome(
|
|
103
|
+
value: unknown,
|
|
104
|
+
): asserts value is BackupExportOutcome {
|
|
105
|
+
mutationOutcome(value, BACKUP_EXPORT_STATUSES, "published", "BackupExportOutcome");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function assertValidBackupRetentionApplyOutcome(
|
|
109
|
+
value: unknown,
|
|
110
|
+
): asserts value is BackupRetentionApplyOutcome {
|
|
111
|
+
mutationOutcome(value, BACKUP_RETENTION_APPLY_STATUSES, "applied", "BackupRetentionApplyOutcome");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function assertValidRestoreInspectOutcome(
|
|
115
|
+
value: unknown,
|
|
116
|
+
): asserts value is RestoreInspectOutcome {
|
|
117
|
+
outcome(value, RESTORE_INSPECT_STATUSES, "$", "RestoreInspectOutcome");
|
|
118
|
+
const result = record(value, "$");
|
|
119
|
+
if (result.status === "ready") {
|
|
120
|
+
finiteNumber(result.generation, "$.generation");
|
|
121
|
+
assertRestoreInspection(result.inspection, "$.inspection");
|
|
122
|
+
} else if (result.status === "locked") {
|
|
123
|
+
string(result.detail, "$.detail");
|
|
124
|
+
} else {
|
|
125
|
+
rejection(result.rejection, "$.rejection");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function assertValidRestorePlanOutcome(
|
|
130
|
+
value: unknown,
|
|
131
|
+
): asserts value is RestorePlanOutcome {
|
|
132
|
+
outcome(value, RESTORE_PLAN_STATUSES, "$", "RestorePlanOutcome");
|
|
133
|
+
const result = record(value, "$");
|
|
134
|
+
if (result.status === "ready") {
|
|
135
|
+
finiteNumber(result.generation, "$.generation");
|
|
136
|
+
assertRestorePlan(result.plan, "$.plan");
|
|
137
|
+
} else {
|
|
138
|
+
rejection(result.rejection, "$.rejection");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function assertValidRestoreExecuteOutcome(
|
|
143
|
+
value: unknown,
|
|
144
|
+
): asserts value is RestoreExecuteOutcome {
|
|
145
|
+
outcome(value, RESTORE_EXECUTE_STATUSES, "$", "RestoreExecuteOutcome");
|
|
146
|
+
const result = record(value, "$");
|
|
147
|
+
if (result.status === "succeeded") {
|
|
148
|
+
assertRestoreExecutionReceipt(result.receipt, "$.receipt");
|
|
149
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
150
|
+
} else if (
|
|
151
|
+
result.status === "rolledBack" ||
|
|
152
|
+
result.status === "recoveryRequired"
|
|
153
|
+
) {
|
|
154
|
+
assertRestoreFailure(result.failure, "$.failure");
|
|
155
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
156
|
+
} else {
|
|
157
|
+
rejection(result.rejection, "$.rejection");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function assertValidRestoreAdapterExecuteOutcome(
|
|
162
|
+
value: unknown,
|
|
163
|
+
): asserts value is RestoreAdapterExecuteOutcome {
|
|
164
|
+
outcome(value, RESTORE_ADAPTER_EXECUTE_STATUSES, "$", "RestoreAdapterExecuteOutcome");
|
|
165
|
+
const result = record(value, "$");
|
|
166
|
+
if (result.status === "completed") {
|
|
167
|
+
assertRestoreAdapterReceipt(result.receipt, "$.receipt");
|
|
168
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
169
|
+
} else {
|
|
170
|
+
rejection(result.rejection, "$.rejection");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function assertValidRestoreRecoveryOutcome(
|
|
175
|
+
value: unknown,
|
|
176
|
+
): asserts value is RestoreRecoveryOutcomeProjection {
|
|
177
|
+
outcome(value, RESTORE_RECOVERY_STATUSES, "$", "RestoreRecoveryOutcomeProjection");
|
|
178
|
+
const result = record(value, "$");
|
|
179
|
+
if (result.status === "recovered") {
|
|
180
|
+
assertRestoreRecoveryReceipt(result.receipt, "$.receipt");
|
|
181
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
182
|
+
} else if (result.status === "recoveryRequired") {
|
|
183
|
+
assertRestoreFailure(result.failure, "$.failure");
|
|
184
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
185
|
+
} else {
|
|
186
|
+
rejection(result.rejection, "$.rejection");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function mutationOutcome(
|
|
191
|
+
value: unknown,
|
|
192
|
+
variants: readonly string[],
|
|
193
|
+
success: string,
|
|
194
|
+
type: string,
|
|
195
|
+
): void {
|
|
196
|
+
outcome(value, variants, "$", type);
|
|
197
|
+
const result = record(value, "$");
|
|
198
|
+
if (result.status === success) {
|
|
199
|
+
assertValidConfigOperationsSnapshot(result.snapshot);
|
|
200
|
+
} else {
|
|
201
|
+
rejection(result.rejection, "$.rejection");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function rejection(value: unknown, path: string): void {
|
|
206
|
+
const refused = record(value, path, CONFIG_FIELDS.ConfigOperationRejection);
|
|
207
|
+
discriminant(refused.code, CONFIG_OPERATION_REJECTION_CODES, `${path}.code`);
|
|
208
|
+
string(refused.detail, `${path}.detail`);
|
|
209
|
+
if (refused.snapshot !== null) {
|
|
210
|
+
assertValidConfigOperationsSnapshot(refused.snapshot);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function outcome(
|
|
215
|
+
value: unknown,
|
|
216
|
+
variants: readonly string[],
|
|
217
|
+
path: string,
|
|
218
|
+
type: string,
|
|
219
|
+
): void {
|
|
220
|
+
const result = record(value, path);
|
|
221
|
+
discriminant(result.status, variants, `${path}.status`);
|
|
222
|
+
// The discriminant is checked above, so a missing map entry means the
|
|
223
|
+
// generator failed rather than that a caller sent something odd.
|
|
224
|
+
record(result, path, variantKeys(type, result, path));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
229
|
+
* discriminant's name read from the map too. This domain tags on `status`,
|
|
230
|
+
* `state`, `kind` and `source`.
|
|
231
|
+
*/
|
|
232
|
+
function variantKeys(
|
|
233
|
+
type: string,
|
|
234
|
+
value: Record<string, unknown>,
|
|
235
|
+
path: string,
|
|
236
|
+
): readonly string[] {
|
|
237
|
+
const discriminant = value[CONFIG_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "status"];
|
|
238
|
+
const keys = CONFIG_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
239
|
+
if (keys === undefined) {
|
|
240
|
+
fail("invalid_payload", path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
241
|
+
}
|
|
242
|
+
return keys;
|
|
243
|
+
}
|