@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,60 @@
|
|
|
1
|
+
// @generated by `effigy generate:operation`; 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 OPERATION_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"OperationOverallProgressProjection": {
|
|
8
|
+
"indeterminate": ["kind"],
|
|
9
|
+
"units": ["kind", "completed", "total"],
|
|
10
|
+
"normalized": ["kind", "value"],
|
|
11
|
+
},
|
|
12
|
+
"OperationTeardownResolutionProjection": {
|
|
13
|
+
"complete": ["kind", "operationId", "expectedOperationRevision", "state"],
|
|
14
|
+
"transfer": ["kind", "operationId", "expectedOperationRevision", "targetAuthority"],
|
|
15
|
+
},
|
|
16
|
+
"OperationMutationCommand": {
|
|
17
|
+
"register": ["kind", "requestId", "protocolVersion", "authority", "expectedCatalogueRevision", "operationId", "kindId", "scopeId", "label", "initialState", "cancellationSupport", "retryOf"],
|
|
18
|
+
"progress": ["kind", "requestId", "protocolVersion", "authority", "operationId", "expectedOperationRevision", "overall", "phase"],
|
|
19
|
+
"transition": ["kind", "requestId", "protocolVersion", "authority", "operationId", "expectedOperationRevision", "nextState"],
|
|
20
|
+
"changeRetention": ["kind", "requestId", "protocolVersion", "authority", "expectedCatalogueRevision", "limits"],
|
|
21
|
+
"dismiss": ["kind", "requestId", "protocolVersion", "authority", "operationId", "expectedOperationRevision"],
|
|
22
|
+
"teardown": ["kind", "requestId", "protocolVersion", "authority", "expectedCatalogueRevision", "resolutions"],
|
|
23
|
+
},
|
|
24
|
+
"OperationMutationReceiptProjection": {
|
|
25
|
+
"registered": ["kind", "operation", "previousCatalogueRevision", "committedCatalogueRevision"],
|
|
26
|
+
"progressed": ["kind", "operationId", "previousOperationRevision", "committedOperationRevision", "previousProgressSequence", "committedProgress", "previousCatalogueRevision", "committedCatalogueRevision"],
|
|
27
|
+
"transitioned": ["kind", "operationId", "previousState", "committedState", "previousOperationRevision", "committedOperationRevision", "previousCatalogueRevision", "committedCatalogueRevision", "evicted"],
|
|
28
|
+
"retentionChanged": ["kind", "previousLimits", "committedLimits", "previousCatalogueRevision", "committedCatalogueRevision", "evicted", "retainedTerminalEncodedWeight"],
|
|
29
|
+
"dismissed": ["kind", "removed", "previousCatalogueRevision", "committedCatalogueRevision"],
|
|
30
|
+
"tornDown": ["kind", "previousCatalogueRevision", "committedCatalogueRevision", "outcomes", "evicted"],
|
|
31
|
+
},
|
|
32
|
+
"OperationTeardownOutcomeProjection": {
|
|
33
|
+
"completed": ["kind", "operationId", "state", "previousOperationRevision", "committedOperationRevision"],
|
|
34
|
+
"transferred": ["kind", "operationId", "previousOperationRevision", "targetAuthority"],
|
|
35
|
+
},
|
|
36
|
+
"OperationMutationResult": {
|
|
37
|
+
"committed": ["status", "requestId", "snapshot", "receipt"],
|
|
38
|
+
"rejected": ["status", "requestId", "snapshot", "rejection"],
|
|
39
|
+
},
|
|
40
|
+
"OperationExecutorDispatchProjection": {
|
|
41
|
+
"notRequired": ["kind"],
|
|
42
|
+
"requested": ["kind"],
|
|
43
|
+
"failed": ["kind", "code", "message", "retryable"],
|
|
44
|
+
},
|
|
45
|
+
"OperationCancellationResult": {
|
|
46
|
+
"committed": ["status", "requestId", "snapshot", "receipt", "executorDispatch"],
|
|
47
|
+
"rejected": ["status", "requestId", "snapshot", "rejection"],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const OPERATION_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
52
|
+
"OperationOverallProgressProjection": "kind",
|
|
53
|
+
"OperationTeardownResolutionProjection": "kind",
|
|
54
|
+
"OperationMutationCommand": "kind",
|
|
55
|
+
"OperationMutationReceiptProjection": "kind",
|
|
56
|
+
"OperationTeardownOutcomeProjection": "kind",
|
|
57
|
+
"OperationMutationResult": "status",
|
|
58
|
+
"OperationExecutorDispatchProjection": "kind",
|
|
59
|
+
"OperationCancellationResult": "status",
|
|
60
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 "./validation.ts";
|
|
10
|
+
export * from "./ports.ts";
|
|
11
|
+
export * from "./client.ts";
|
|
12
|
+
export * from "./controller.ts";
|
|
13
|
+
export * from "./direct.ts";
|
|
14
|
+
export * from "./serialized.ts";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
OperationCancellationCommand,
|
|
3
|
+
OperationChangedEvent,
|
|
4
|
+
OperationMutationCommand,
|
|
5
|
+
OperationRequestId,
|
|
6
|
+
OperationSnapshotQuery,
|
|
7
|
+
} from "./generated/protocol.ts";
|
|
8
|
+
|
|
9
|
+
export type OperationUnlisten = () => void | Promise<void>;
|
|
10
|
+
|
|
11
|
+
export interface OperationPort {
|
|
12
|
+
snapshot(query: OperationSnapshotQuery): Promise<unknown>;
|
|
13
|
+
mutate(command: OperationMutationCommand): Promise<unknown>;
|
|
14
|
+
cancel(command: OperationCancellationCommand): Promise<unknown>;
|
|
15
|
+
listen?(
|
|
16
|
+
listener: (event: unknown) => void,
|
|
17
|
+
): OperationUnlisten | Promise<OperationUnlisten>;
|
|
18
|
+
nextRequestId(): OperationRequestId;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CheckedOperationPort {
|
|
22
|
+
snapshot(query: OperationSnapshotQuery): Promise<import("./generated/protocol.ts").OperationSnapshotResponse>;
|
|
23
|
+
mutate(command: OperationMutationCommand): Promise<import("./generated/protocol.ts").OperationMutationResult>;
|
|
24
|
+
cancel(command: OperationCancellationCommand): Promise<import("./generated/protocol.ts").OperationCancellationResult>;
|
|
25
|
+
listen?(
|
|
26
|
+
listener: (event: OperationChangedEvent) => void,
|
|
27
|
+
): Promise<OperationUnlisten>;
|
|
28
|
+
nextRequestId(): OperationRequestId;
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
OperationCancellationCommand,
|
|
3
|
+
OperationMutationCommand,
|
|
4
|
+
OperationSnapshotQuery,
|
|
5
|
+
} from "./generated/protocol.ts";
|
|
6
|
+
import type { OperationPort, OperationUnlisten } from "./ports.ts";
|
|
7
|
+
|
|
8
|
+
export class SerializedOperationPort implements OperationPort {
|
|
9
|
+
readonly #inner: OperationPort;
|
|
10
|
+
|
|
11
|
+
constructor(inner: OperationPort) {
|
|
12
|
+
this.#inner = inner;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async snapshot(query: OperationSnapshotQuery): Promise<unknown> {
|
|
16
|
+
return clone(await this.#inner.snapshot(clone(query)));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async mutate(command: OperationMutationCommand): Promise<unknown> {
|
|
20
|
+
return clone(await this.#inner.mutate(clone(command)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async cancel(command: OperationCancellationCommand): Promise<unknown> {
|
|
24
|
+
return clone(await this.#inner.cancel(clone(command)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async listen(listener: (event: unknown) => void): Promise<OperationUnlisten> {
|
|
28
|
+
if (this.#inner.listen === undefined) return () => {};
|
|
29
|
+
return this.#inner.listen((event) => listener(clone(event)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
nextRequestId(): string {
|
|
33
|
+
return this.#inner.nextRequestId();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function clone<Value>(value: Value): Value {
|
|
38
|
+
return JSON.parse(JSON.stringify(value)) as Value;
|
|
39
|
+
}
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import { OPERATION_FIELDS } from "./generated/fields.ts";
|
|
2
|
+
import { OPERATION_VARIANT_FIELDS, OPERATION_VARIANT_FIELDS_DISCRIMINANTS } from "./generated/variant-fields.ts";
|
|
3
|
+
import {
|
|
4
|
+
OPERATION_CANCELLATION_OUTCOMES,
|
|
5
|
+
OPERATION_CANCELLATION_STATUSES,
|
|
6
|
+
OPERATION_CHANGED_KINDS,
|
|
7
|
+
OPERATION_EXECUTOR_DISPATCH_KINDS,
|
|
8
|
+
OPERATION_MUTATION_KINDS,
|
|
9
|
+
OPERATION_MUTATION_RECEIPT_KINDS,
|
|
10
|
+
OPERATION_MUTATION_STATUSES,
|
|
11
|
+
OPERATION_PROGRESS_KINDS,
|
|
12
|
+
OPERATION_PROTOCOL_VERSION,
|
|
13
|
+
OPERATION_REJECTION_CODES,
|
|
14
|
+
OPERATION_STATES,
|
|
15
|
+
type OperationCancellationCommand,
|
|
16
|
+
type OperationCancellationResult,
|
|
17
|
+
type OperationChangedEvent,
|
|
18
|
+
type OperationEntryProjection,
|
|
19
|
+
type OperationMutationCommand,
|
|
20
|
+
type OperationMutationResult,
|
|
21
|
+
type OperationSnapshot,
|
|
22
|
+
type OperationSnapshotQuery,
|
|
23
|
+
type OperationSnapshotResponse,
|
|
24
|
+
} from "./generated/protocol.ts";
|
|
25
|
+
|
|
26
|
+
const FORBIDDEN_PAYLOAD_KEYS = new Set([
|
|
27
|
+
"payload",
|
|
28
|
+
"result",
|
|
29
|
+
"artifact",
|
|
30
|
+
"report",
|
|
31
|
+
"log",
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export class OperationProtocolValidationError extends Error {
|
|
35
|
+
constructor(readonly path: string, message: string) {
|
|
36
|
+
super(`incompatible operation protocol at ${path}: ${message}`);
|
|
37
|
+
this.name = "OperationProtocolValidationError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function assertValidOperationSnapshotQuery(
|
|
42
|
+
value: unknown,
|
|
43
|
+
): asserts value is OperationSnapshotQuery {
|
|
44
|
+
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotQuery);
|
|
45
|
+
protocol(object.protocolVersion, "$.protocolVersion");
|
|
46
|
+
text(object.requestId, "$.requestId");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function assertValidOperationSnapshotResponse(
|
|
50
|
+
value: unknown,
|
|
51
|
+
): asserts value is OperationSnapshotResponse {
|
|
52
|
+
assertPayloadFree(value);
|
|
53
|
+
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotResponse);
|
|
54
|
+
text(object.requestId, "$.requestId");
|
|
55
|
+
assertValidOperationSnapshot(object.snapshot);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function assertValidOperationSnapshot(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): asserts value is OperationSnapshot {
|
|
61
|
+
assertPayloadFree(value);
|
|
62
|
+
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshot);
|
|
63
|
+
protocol(object.protocolVersion, "$.protocolVersion");
|
|
64
|
+
authority(object.authority, "$.authority");
|
|
65
|
+
natural(object.catalogueRevision, "$.catalogueRevision");
|
|
66
|
+
boolean(object.closed, "$.closed");
|
|
67
|
+
const limits = exactObject(object.limits, "$.limits", OPERATION_FIELDS.OperationCatalogueLimitsProjection);
|
|
68
|
+
natural(limits.maximumActiveOperations, "$.limits.maximumActiveOperations");
|
|
69
|
+
natural(limits.maximumTerminalOperations, "$.limits.maximumTerminalOperations");
|
|
70
|
+
natural(limits.maximumTerminalEncodedWeight, "$.limits.maximumTerminalEncodedWeight");
|
|
71
|
+
natural(object.terminalEvictionCount, "$.terminalEvictionCount");
|
|
72
|
+
natural(object.retainedTerminalEncodedWeight, "$.retainedTerminalEncodedWeight");
|
|
73
|
+
array(object.active, "$.active").forEach((entry, index) =>
|
|
74
|
+
operationEntry(entry, `$.active[${index}]`)
|
|
75
|
+
);
|
|
76
|
+
array(object.recent, "$.recent").forEach((entry, index) =>
|
|
77
|
+
operationEntry(entry, `$.recent[${index}]`)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function assertValidOperationMutationCommand(
|
|
82
|
+
value: unknown,
|
|
83
|
+
): asserts value is OperationMutationCommand {
|
|
84
|
+
assertPayloadFree(value);
|
|
85
|
+
const object = record(value, "$");
|
|
86
|
+
member(object.kind, OPERATION_MUTATION_KINDS, "$.kind");
|
|
87
|
+
protocol(object.protocolVersion, "$.protocolVersion");
|
|
88
|
+
text(object.requestId, "$.requestId");
|
|
89
|
+
authority(object.authority, "$.authority");
|
|
90
|
+
switch (object.kind) {
|
|
91
|
+
case "register":
|
|
92
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
93
|
+
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
94
|
+
text(object.operationId, "$.operationId");
|
|
95
|
+
text(object.kindId, "$.kindId");
|
|
96
|
+
nullableText(object.scopeId, "$.scopeId");
|
|
97
|
+
text(object.label, "$.label");
|
|
98
|
+
member(object.initialState, OPERATION_STATES, "$.initialState");
|
|
99
|
+
member(object.cancellationSupport, ["supported", "unsupported"] as const, "$.cancellationSupport");
|
|
100
|
+
nullableText(object.retryOf, "$.retryOf");
|
|
101
|
+
break;
|
|
102
|
+
case "progress":
|
|
103
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
104
|
+
operationTarget(object);
|
|
105
|
+
progressOverall(object.overall, "$.overall");
|
|
106
|
+
if (object.phase !== null) phase(object.phase, "$.phase");
|
|
107
|
+
break;
|
|
108
|
+
case "transition":
|
|
109
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
110
|
+
operationTarget(object);
|
|
111
|
+
member(object.nextState, OPERATION_STATES, "$.nextState");
|
|
112
|
+
break;
|
|
113
|
+
case "changeRetention":
|
|
114
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
115
|
+
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
116
|
+
assertValidOperationSnapshot({
|
|
117
|
+
protocolVersion: 1, authority: object.authority, catalogueRevision: 0,
|
|
118
|
+
closed: false, limits: object.limits, terminalEvictionCount: 0,
|
|
119
|
+
retainedTerminalEncodedWeight: 0, active: [], recent: [],
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case "dismiss":
|
|
123
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
124
|
+
operationTarget(object);
|
|
125
|
+
break;
|
|
126
|
+
case "teardown":
|
|
127
|
+
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
128
|
+
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
129
|
+
array(object.resolutions, "$.resolutions").forEach((resolution, index) => teardownResolution(resolution, `$.resolutions[${index}]`));
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function assertValidOperationCancellationCommand(
|
|
135
|
+
value: unknown,
|
|
136
|
+
): asserts value is OperationCancellationCommand {
|
|
137
|
+
assertPayloadFree(value);
|
|
138
|
+
const object = exactObject(value, "$", OPERATION_FIELDS.OperationCancellationCommand);
|
|
139
|
+
text(object.requestId, "$.requestId");
|
|
140
|
+
protocol(object.protocolVersion, "$.protocolVersion");
|
|
141
|
+
authority(object.authority, "$.authority");
|
|
142
|
+
operationTarget(object);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function assertValidOperationMutationResult(
|
|
146
|
+
value: unknown,
|
|
147
|
+
): asserts value is OperationMutationResult {
|
|
148
|
+
resultBase(value, OPERATION_MUTATION_STATUSES);
|
|
149
|
+
const object = value as Record<string, unknown>;
|
|
150
|
+
if (object.status === "committed") {
|
|
151
|
+
exactKeys(object, "$", variantKeys("OperationMutationResult", object, "$"));
|
|
152
|
+
mutationReceipt(object.receipt, "$.receipt");
|
|
153
|
+
} else {
|
|
154
|
+
exactKeys(object, "$", variantKeys("OperationMutationResult", object, "$"));
|
|
155
|
+
rejection(object.rejection, "$.rejection");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function assertValidOperationCancellationResult(
|
|
160
|
+
value: unknown,
|
|
161
|
+
): asserts value is OperationCancellationResult {
|
|
162
|
+
resultBase(value, OPERATION_CANCELLATION_STATUSES);
|
|
163
|
+
const object = value as Record<string, unknown>;
|
|
164
|
+
if (object.status === "committed") {
|
|
165
|
+
exactKeys(object, "$", variantKeys("OperationCancellationResult", object, "$"));
|
|
166
|
+
cancellationReceipt(object.receipt, "$.receipt");
|
|
167
|
+
executorDispatch(object.executorDispatch, "$.executorDispatch");
|
|
168
|
+
} else {
|
|
169
|
+
exactKeys(object, "$", variantKeys("OperationCancellationResult", object, "$"));
|
|
170
|
+
rejection(object.rejection, "$.rejection");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function assertValidOperationChangedEvent(
|
|
175
|
+
value: unknown,
|
|
176
|
+
): asserts value is OperationChangedEvent {
|
|
177
|
+
assertPayloadFree(value);
|
|
178
|
+
const object = exactObject(value, "$", OPERATION_FIELDS.OperationChangedEvent);
|
|
179
|
+
protocol(object.protocolVersion, "$.protocolVersion");
|
|
180
|
+
text(object.requestId, "$.requestId");
|
|
181
|
+
authority(object.authority, "$.authority");
|
|
182
|
+
natural(object.previousCatalogueRevision, "$.previousCatalogueRevision");
|
|
183
|
+
natural(object.committedCatalogueRevision, "$.committedCatalogueRevision");
|
|
184
|
+
nullableText(object.operationId, "$.operationId");
|
|
185
|
+
member(object.kind, OPERATION_CHANGED_KINDS, "$.kind");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function assertPayloadFree(value: unknown): void {
|
|
189
|
+
visit(value, "$", new Set());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function resultBase(value: unknown, statuses: readonly string[]): void {
|
|
193
|
+
assertPayloadFree(value);
|
|
194
|
+
const object = record(value, "$");
|
|
195
|
+
member(object.status, statuses, "$.status");
|
|
196
|
+
text(object.requestId, "$.requestId");
|
|
197
|
+
assertValidOperationSnapshot(object.snapshot);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function operationEntry(value: unknown, path: string): asserts value is OperationEntryProjection {
|
|
201
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationEntryProjection);
|
|
202
|
+
authority(object.authority, `${path}.authority`);
|
|
203
|
+
text(object.operationId, `${path}.operationId`);
|
|
204
|
+
text(object.kindId, `${path}.kindId`);
|
|
205
|
+
nullableText(object.scopeId, `${path}.scopeId`);
|
|
206
|
+
text(object.label, `${path}.label`);
|
|
207
|
+
member(object.cancellationSupport, ["supported", "unsupported"] as const, `${path}.cancellationSupport`);
|
|
208
|
+
nullableText(object.retryOf, `${path}.retryOf`);
|
|
209
|
+
natural(object.sequence, `${path}.sequence`);
|
|
210
|
+
natural(object.revision, `${path}.revision`);
|
|
211
|
+
natural(object.lastChangedCatalogueRevision, `${path}.lastChangedCatalogueRevision`);
|
|
212
|
+
member(object.state, OPERATION_STATES, `${path}.state`);
|
|
213
|
+
const progress = exactObject(object.progress, `${path}.progress`, OPERATION_FIELDS.OperationProgressProjection);
|
|
214
|
+
natural(progress.sequence, `${path}.progress.sequence`);
|
|
215
|
+
progressOverall(progress.overall, `${path}.progress.overall`);
|
|
216
|
+
if (progress.phase !== null) phase(progress.phase, `${path}.progress.phase`);
|
|
217
|
+
natural(object.encodedMetadataWeight, `${path}.encodedMetadataWeight`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function progressOverall(value: unknown, path: string): void {
|
|
221
|
+
const object = record(value, path);
|
|
222
|
+
member(object.kind, OPERATION_PROGRESS_KINDS, `${path}.kind`);
|
|
223
|
+
if (object.kind === "indeterminate") exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
|
|
224
|
+
if (object.kind === "units") {
|
|
225
|
+
exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
|
|
226
|
+
finite(object.completed, `${path}.completed`);
|
|
227
|
+
finite(object.total, `${path}.total`);
|
|
228
|
+
}
|
|
229
|
+
if (object.kind === "normalized") {
|
|
230
|
+
exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
|
|
231
|
+
finite(object.value, `${path}.value`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function phase(value: unknown, path: string): void {
|
|
236
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationPhaseProgressProjection);
|
|
237
|
+
text(object.phaseId, `${path}.phaseId`);
|
|
238
|
+
text(object.label, `${path}.label`);
|
|
239
|
+
finite(object.completed, `${path}.completed`);
|
|
240
|
+
finite(object.total, `${path}.total`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function teardownResolution(value: unknown, path: string): void {
|
|
244
|
+
const object = record(value, path);
|
|
245
|
+
member(object.kind, ["complete", "transfer"] as const, `${path}.kind`);
|
|
246
|
+
if (object.kind === "complete") {
|
|
247
|
+
exactKeys(object, path, variantKeys("OperationTeardownResolutionProjection", object, path));
|
|
248
|
+
member(object.state, OPERATION_STATES, `${path}.state`);
|
|
249
|
+
} else {
|
|
250
|
+
exactKeys(object, path, variantKeys("OperationTeardownResolutionProjection", object, path));
|
|
251
|
+
authority(object.targetAuthority, `${path}.targetAuthority`);
|
|
252
|
+
}
|
|
253
|
+
text(object.operationId, `${path}.operationId`);
|
|
254
|
+
natural(object.expectedOperationRevision, `${path}.expectedOperationRevision`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function rejection(value: unknown, path: string): void {
|
|
258
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationRejection);
|
|
259
|
+
member(object.code, OPERATION_REJECTION_CODES, `${path}.code`);
|
|
260
|
+
text(object.detail, `${path}.detail`);
|
|
261
|
+
boolean(object.refreshRequired, `${path}.refreshRequired`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function mutationReceipt(value: unknown, path: string): void {
|
|
265
|
+
const object = record(value, path);
|
|
266
|
+
member(object.kind, OPERATION_MUTATION_RECEIPT_KINDS, `${path}.kind`);
|
|
267
|
+
switch (object.kind) {
|
|
268
|
+
case "registered":
|
|
269
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
270
|
+
operationEntry(object.operation, `${path}.operation`);
|
|
271
|
+
catalogueRevisionPair(object, path);
|
|
272
|
+
break;
|
|
273
|
+
case "progressed":
|
|
274
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
275
|
+
operationRevisionPair(object, path);
|
|
276
|
+
natural(object.previousProgressSequence, `${path}.previousProgressSequence`);
|
|
277
|
+
const progress = exactObject(object.committedProgress, `${path}.committedProgress`, OPERATION_FIELDS.OperationProgressProjection);
|
|
278
|
+
natural(progress.sequence, `${path}.committedProgress.sequence`);
|
|
279
|
+
progressOverall(progress.overall, `${path}.committedProgress.overall`);
|
|
280
|
+
if (progress.phase !== null) phase(progress.phase, `${path}.committedProgress.phase`);
|
|
281
|
+
catalogueRevisionPair(object, path);
|
|
282
|
+
break;
|
|
283
|
+
case "transitioned":
|
|
284
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
285
|
+
member(object.previousState, OPERATION_STATES, `${path}.previousState`);
|
|
286
|
+
member(object.committedState, OPERATION_STATES, `${path}.committedState`);
|
|
287
|
+
operationRevisionPair(object, path);
|
|
288
|
+
catalogueRevisionPair(object, path);
|
|
289
|
+
removals(object.evicted, `${path}.evicted`);
|
|
290
|
+
break;
|
|
291
|
+
case "retentionChanged":
|
|
292
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
293
|
+
limits(object.previousLimits, `${path}.previousLimits`);
|
|
294
|
+
limits(object.committedLimits, `${path}.committedLimits`);
|
|
295
|
+
catalogueRevisionPair(object, path);
|
|
296
|
+
removals(object.evicted, `${path}.evicted`);
|
|
297
|
+
natural(object.retainedTerminalEncodedWeight, `${path}.retainedTerminalEncodedWeight`);
|
|
298
|
+
break;
|
|
299
|
+
case "dismissed":
|
|
300
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
301
|
+
removal(object.removed, `${path}.removed`);
|
|
302
|
+
catalogueRevisionPair(object, path);
|
|
303
|
+
break;
|
|
304
|
+
case "tornDown":
|
|
305
|
+
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
306
|
+
catalogueRevisionPair(object, path);
|
|
307
|
+
array(object.outcomes, `${path}.outcomes`).forEach((outcome, index) => teardownOutcome(outcome, `${path}.outcomes[${index}]`));
|
|
308
|
+
removals(object.evicted, `${path}.evicted`);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function cancellationReceipt(value: unknown, path: string): void {
|
|
314
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationCancellationReceiptProjection);
|
|
315
|
+
text(object.operationId, `${path}.operationId`);
|
|
316
|
+
member(object.outcome, OPERATION_CANCELLATION_OUTCOMES, `${path}.outcome`);
|
|
317
|
+
member(object.previousState, OPERATION_STATES, `${path}.previousState`);
|
|
318
|
+
member(object.committedState, OPERATION_STATES, `${path}.committedState`);
|
|
319
|
+
operationRevisionPair(object, path);
|
|
320
|
+
catalogueRevisionPair(object, path);
|
|
321
|
+
removals(object.evicted, `${path}.evicted`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function executorDispatch(value: unknown, path: string): void {
|
|
325
|
+
const object = record(value, path);
|
|
326
|
+
member(object.kind, OPERATION_EXECUTOR_DISPATCH_KINDS, `${path}.kind`);
|
|
327
|
+
if (object.kind === "failed") {
|
|
328
|
+
exactKeys(object, path, variantKeys("OperationExecutorDispatchProjection", object, path));
|
|
329
|
+
text(object.code, `${path}.code`);
|
|
330
|
+
text(object.message, `${path}.message`);
|
|
331
|
+
boolean(object.retryable, `${path}.retryable`);
|
|
332
|
+
} else {
|
|
333
|
+
exactKeys(object, path, variantKeys("OperationExecutorDispatchProjection", object, path));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function removal(value: unknown, path: string): void {
|
|
338
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationRemovalProjection);
|
|
339
|
+
text(object.operationId, `${path}.operationId`);
|
|
340
|
+
natural(object.sequence, `${path}.sequence`);
|
|
341
|
+
natural(object.encodedWeight, `${path}.encodedWeight`);
|
|
342
|
+
member(object.reason, ["evicted", "dismissed"] as const, `${path}.reason`);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function removals(value: unknown, path: string): void {
|
|
346
|
+
array(value, path).forEach((entry, index) => removal(entry, `${path}[${index}]`));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function teardownOutcome(value: unknown, path: string): void {
|
|
350
|
+
const object = record(value, path);
|
|
351
|
+
member(object.kind, ["completed", "transferred"] as const, `${path}.kind`);
|
|
352
|
+
if (object.kind === "completed") {
|
|
353
|
+
exactKeys(object, path, variantKeys("OperationTeardownOutcomeProjection", object, path));
|
|
354
|
+
member(object.state, OPERATION_STATES, `${path}.state`);
|
|
355
|
+
} else {
|
|
356
|
+
exactKeys(object, path, variantKeys("OperationTeardownOutcomeProjection", object, path));
|
|
357
|
+
authority(object.targetAuthority, `${path}.targetAuthority`);
|
|
358
|
+
}
|
|
359
|
+
text(object.operationId, `${path}.operationId`);
|
|
360
|
+
natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
|
|
361
|
+
if (object.kind === "completed") natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function limits(value: unknown, path: string): void {
|
|
365
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationCatalogueLimitsProjection);
|
|
366
|
+
natural(object.maximumActiveOperations, `${path}.maximumActiveOperations`);
|
|
367
|
+
natural(object.maximumTerminalOperations, `${path}.maximumTerminalOperations`);
|
|
368
|
+
natural(object.maximumTerminalEncodedWeight, `${path}.maximumTerminalEncodedWeight`);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function operationRevisionPair(object: Record<string, unknown>, path: string): void {
|
|
372
|
+
text(object.operationId, `${path}.operationId`);
|
|
373
|
+
natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
|
|
374
|
+
natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function catalogueRevisionPair(object: Record<string, unknown>, path: string): void {
|
|
378
|
+
natural(object.previousCatalogueRevision, `${path}.previousCatalogueRevision`);
|
|
379
|
+
natural(object.committedCatalogueRevision, `${path}.committedCatalogueRevision`);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function operationTarget(object: Record<string, unknown>): void {
|
|
383
|
+
text(object.operationId, "$.operationId");
|
|
384
|
+
natural(object.expectedOperationRevision, "$.expectedOperationRevision");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function authority(value: unknown, path: string): void {
|
|
388
|
+
const object = exactObject(value, path, OPERATION_FIELDS.OperationAuthorityProjection);
|
|
389
|
+
text(object.authorityId, `${path}.authorityId`);
|
|
390
|
+
natural(object.authorityEpoch, `${path}.authorityEpoch`);
|
|
391
|
+
if (object.authorityEpoch === 0) fail(`${path}.authorityEpoch`, "must be nonzero");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function protocol(value: unknown, path: string): void {
|
|
395
|
+
natural(value, path);
|
|
396
|
+
if (value !== OPERATION_PROTOCOL_VERSION) fail(path, `expected ${OPERATION_PROTOCOL_VERSION}`);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function exactObject(value: unknown, path: string, keys: readonly string[]): Record<string, unknown> {
|
|
400
|
+
const object = record(value, path);
|
|
401
|
+
exactKeys(object, path, keys);
|
|
402
|
+
return object;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function exactKeys(object: Record<string, unknown>, path: string, keys: readonly string[]): void {
|
|
406
|
+
const actual = Object.keys(object).sort();
|
|
407
|
+
const expected = [...keys].sort();
|
|
408
|
+
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
409
|
+
fail(path, `expected keys ${expected.join(",")}; received ${actual.join(",")}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function record(value: unknown, path: string): Record<string, unknown> {
|
|
414
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail(path, "expected object");
|
|
415
|
+
return value as Record<string, unknown>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function array(value: unknown, path: string): unknown[] {
|
|
419
|
+
if (!Array.isArray(value)) fail(path, "expected array");
|
|
420
|
+
return value;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function text(value: unknown, path: string): asserts value is string {
|
|
424
|
+
if (typeof value !== "string" || value.length === 0) fail(path, "expected non-empty string");
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function nullableText(value: unknown, path: string): void {
|
|
428
|
+
if (value !== null) text(value, path);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function natural(value: unknown, path: string): asserts value is number {
|
|
432
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected non-negative safe integer");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function finite(value: unknown, path: string): asserts value is number {
|
|
436
|
+
if (typeof value !== "number" || !Number.isFinite(value)) fail(path, "expected finite number");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function boolean(value: unknown, path: string): asserts value is boolean {
|
|
440
|
+
if (typeof value !== "boolean") fail(path, "expected boolean");
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function member(value: unknown, values: readonly string[], path: string): asserts value is string {
|
|
444
|
+
if (typeof value !== "string" || !values.includes(value)) fail(path, `expected one of ${values.join(",")}`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function visit(value: unknown, path: string, seen: Set<object>): void {
|
|
448
|
+
if (typeof value !== "object" || value === null) return;
|
|
449
|
+
if (seen.has(value)) fail(path, "cyclic value");
|
|
450
|
+
seen.add(value);
|
|
451
|
+
if (Array.isArray(value)) {
|
|
452
|
+
value.forEach((entry, index) => visit(entry, `${path}[${index}]`, seen));
|
|
453
|
+
} else {
|
|
454
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
455
|
+
if (FORBIDDEN_PAYLOAD_KEYS.has(key)) fail(`${path}.${key}`, "product payload field is forbidden");
|
|
456
|
+
visit(entry, `${path}.${key}`, seen);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
seen.delete(value);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function fail(path: string, message: string): never {
|
|
463
|
+
throw new OperationProtocolValidationError(path, message);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Allowed keys for one variant, from the generated map.
|
|
468
|
+
*
|
|
469
|
+
* A missing entry means the generator failed to read the union, not that a
|
|
470
|
+
* caller sent something odd: every switch below runs `member()` over the
|
|
471
|
+
* discriminant first. Failing loudly beats a hand-written list, which is what
|
|
472
|
+
* these were and what drifted in `history-tree`.
|
|
473
|
+
*/
|
|
474
|
+
function variantKeys(type: string, object: Record<string, unknown>, path: string): readonly string[] {
|
|
475
|
+
const discriminant = object[OPERATION_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
476
|
+
const keys = OPERATION_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
477
|
+
if (keys === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
478
|
+
return keys;
|
|
479
|
+
}
|