@inflatable-cookie/longhorn 0.5.0 → 0.7.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/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +78 -109
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
1
3
|
import { OPERATION_FIELDS } from "./generated/fields.ts";
|
|
2
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
OPERATION_VARIANT_FIELDS,
|
|
6
|
+
OPERATION_VARIANT_FIELDS_DISCRIMINANTS,
|
|
7
|
+
} from "./generated/variant-fields.ts";
|
|
3
8
|
import {
|
|
4
9
|
OPERATION_CANCELLATION_OUTCOMES,
|
|
5
10
|
OPERATION_CANCELLATION_STATUSES,
|
|
@@ -12,27 +17,26 @@ import {
|
|
|
12
17
|
OPERATION_PROTOCOL_VERSION,
|
|
13
18
|
OPERATION_REJECTION_CODES,
|
|
14
19
|
OPERATION_STATES,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
} from "./generated/protocol.ts";
|
|
21
|
+
import type {
|
|
22
|
+
OperationCancellationCommand,
|
|
23
|
+
OperationCancellationResult,
|
|
24
|
+
OperationChangedEvent,
|
|
25
|
+
OperationEntryProjection,
|
|
26
|
+
OperationMutationCommand,
|
|
27
|
+
OperationMutationResult,
|
|
28
|
+
OperationSnapshot,
|
|
29
|
+
OperationSnapshotQuery,
|
|
30
|
+
OperationSnapshotResponse,
|
|
24
31
|
} from "./generated/protocol.ts";
|
|
25
32
|
|
|
26
|
-
const FORBIDDEN_PAYLOAD_KEYS = new Set([
|
|
27
|
-
"payload",
|
|
28
|
-
"result",
|
|
29
|
-
"artifact",
|
|
30
|
-
"report",
|
|
31
|
-
"log",
|
|
32
|
-
]);
|
|
33
|
+
const FORBIDDEN_PAYLOAD_KEYS = new Set(["payload", "result", "artifact", "report", "log"]);
|
|
33
34
|
|
|
34
35
|
export class OperationProtocolValidationError extends Error {
|
|
35
|
-
constructor(
|
|
36
|
+
constructor(
|
|
37
|
+
readonly path: string,
|
|
38
|
+
message: string,
|
|
39
|
+
) {
|
|
36
40
|
super(`incompatible operation protocol at ${path}: ${message}`);
|
|
37
41
|
this.name = "OperationProtocolValidationError";
|
|
38
42
|
}
|
|
@@ -43,7 +47,7 @@ export function assertValidOperationSnapshotQuery(
|
|
|
43
47
|
): asserts value is OperationSnapshotQuery {
|
|
44
48
|
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotQuery);
|
|
45
49
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
46
|
-
|
|
50
|
+
identifier(object.requestId, "$.requestId");
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export function assertValidOperationSnapshotResponse(
|
|
@@ -51,30 +55,32 @@ export function assertValidOperationSnapshotResponse(
|
|
|
51
55
|
): asserts value is OperationSnapshotResponse {
|
|
52
56
|
assertPayloadFree(value);
|
|
53
57
|
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshotResponse);
|
|
54
|
-
|
|
58
|
+
identifier(object.requestId, "$.requestId");
|
|
55
59
|
assertValidOperationSnapshot(object.snapshot);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
export function assertValidOperationSnapshot(
|
|
59
|
-
value: unknown,
|
|
60
|
-
): asserts value is OperationSnapshot {
|
|
62
|
+
export function assertValidOperationSnapshot(value: unknown): asserts value is OperationSnapshot {
|
|
61
63
|
assertPayloadFree(value);
|
|
62
64
|
const object = exactObject(value, "$", OPERATION_FIELDS.OperationSnapshot);
|
|
63
65
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
64
66
|
authority(object.authority, "$.authority");
|
|
65
67
|
natural(object.catalogueRevision, "$.catalogueRevision");
|
|
66
68
|
boolean(object.closed, "$.closed");
|
|
67
|
-
const limits = exactObject(
|
|
69
|
+
const limits = exactObject(
|
|
70
|
+
object.limits,
|
|
71
|
+
"$.limits",
|
|
72
|
+
OPERATION_FIELDS.OperationCatalogueLimitsProjection,
|
|
73
|
+
);
|
|
68
74
|
natural(limits.maximumActiveOperations, "$.limits.maximumActiveOperations");
|
|
69
75
|
natural(limits.maximumTerminalOperations, "$.limits.maximumTerminalOperations");
|
|
70
76
|
natural(limits.maximumTerminalEncodedWeight, "$.limits.maximumTerminalEncodedWeight");
|
|
71
77
|
natural(object.terminalEvictionCount, "$.terminalEvictionCount");
|
|
72
78
|
natural(object.retainedTerminalEncodedWeight, "$.retainedTerminalEncodedWeight");
|
|
73
79
|
array(object.active, "$.active").forEach((entry, index) =>
|
|
74
|
-
operationEntry(entry, `$.active[${index}]`)
|
|
80
|
+
operationEntry(entry, `$.active[${index}]`),
|
|
75
81
|
);
|
|
76
82
|
array(object.recent, "$.recent").forEach((entry, index) =>
|
|
77
|
-
operationEntry(entry, `$.recent[${index}]`)
|
|
83
|
+
operationEntry(entry, `$.recent[${index}]`),
|
|
78
84
|
);
|
|
79
85
|
}
|
|
80
86
|
|
|
@@ -85,25 +91,31 @@ export function assertValidOperationMutationCommand(
|
|
|
85
91
|
const object = record(value, "$");
|
|
86
92
|
member(object.kind, OPERATION_MUTATION_KINDS, "$.kind");
|
|
87
93
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
88
|
-
|
|
94
|
+
identifier(object.requestId, "$.requestId");
|
|
89
95
|
authority(object.authority, "$.authority");
|
|
90
96
|
switch (object.kind) {
|
|
91
97
|
case "register":
|
|
92
98
|
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
93
99
|
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
identifier(object.operationId, "$.operationId");
|
|
101
|
+
identifier(object.kindId, "$.kindId");
|
|
102
|
+
nullableIdentifier(object.scopeId, "$.scopeId");
|
|
97
103
|
text(object.label, "$.label");
|
|
98
104
|
member(object.initialState, OPERATION_STATES, "$.initialState");
|
|
99
|
-
member(
|
|
100
|
-
|
|
105
|
+
member(
|
|
106
|
+
object.cancellationSupport,
|
|
107
|
+
["supported", "unsupported"] as const,
|
|
108
|
+
"$.cancellationSupport",
|
|
109
|
+
);
|
|
110
|
+
nullableIdentifier(object.retryOf, "$.retryOf");
|
|
101
111
|
break;
|
|
102
112
|
case "progress":
|
|
103
113
|
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
104
114
|
operationTarget(object);
|
|
105
115
|
progressOverall(object.overall, "$.overall");
|
|
106
|
-
if (object.phase !== null)
|
|
116
|
+
if (object.phase !== null) {
|
|
117
|
+
phase(object.phase, "$.phase");
|
|
118
|
+
}
|
|
107
119
|
break;
|
|
108
120
|
case "transition":
|
|
109
121
|
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
@@ -113,10 +125,17 @@ export function assertValidOperationMutationCommand(
|
|
|
113
125
|
case "changeRetention":
|
|
114
126
|
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
115
127
|
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
128
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- Runtime validation also covers structurally typed callers and untrusted wire values.
|
|
116
129
|
assertValidOperationSnapshot({
|
|
117
|
-
protocolVersion: 1,
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
protocolVersion: 1,
|
|
131
|
+
authority: object.authority,
|
|
132
|
+
catalogueRevision: 0,
|
|
133
|
+
closed: false,
|
|
134
|
+
limits: object.limits,
|
|
135
|
+
terminalEvictionCount: 0,
|
|
136
|
+
retainedTerminalEncodedWeight: 0,
|
|
137
|
+
active: [],
|
|
138
|
+
recent: [],
|
|
120
139
|
});
|
|
121
140
|
break;
|
|
122
141
|
case "dismiss":
|
|
@@ -126,7 +145,9 @@ export function assertValidOperationMutationCommand(
|
|
|
126
145
|
case "teardown":
|
|
127
146
|
exactKeys(object, "$", variantKeys("OperationMutationCommand", object, "$"));
|
|
128
147
|
natural(object.expectedCatalogueRevision, "$.expectedCatalogueRevision");
|
|
129
|
-
array(object.resolutions, "$.resolutions").forEach((resolution, index) =>
|
|
148
|
+
array(object.resolutions, "$.resolutions").forEach((resolution, index) =>
|
|
149
|
+
teardownResolution(resolution, `$.resolutions[${index}]`),
|
|
150
|
+
);
|
|
130
151
|
break;
|
|
131
152
|
}
|
|
132
153
|
}
|
|
@@ -136,7 +157,7 @@ export function assertValidOperationCancellationCommand(
|
|
|
136
157
|
): asserts value is OperationCancellationCommand {
|
|
137
158
|
assertPayloadFree(value);
|
|
138
159
|
const object = exactObject(value, "$", OPERATION_FIELDS.OperationCancellationCommand);
|
|
139
|
-
|
|
160
|
+
identifier(object.requestId, "$.requestId");
|
|
140
161
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
141
162
|
authority(object.authority, "$.authority");
|
|
142
163
|
operationTarget(object);
|
|
@@ -145,8 +166,7 @@ export function assertValidOperationCancellationCommand(
|
|
|
145
166
|
export function assertValidOperationMutationResult(
|
|
146
167
|
value: unknown,
|
|
147
168
|
): asserts value is OperationMutationResult {
|
|
148
|
-
resultBase(value, OPERATION_MUTATION_STATUSES);
|
|
149
|
-
const object = value as Record<string, unknown>;
|
|
169
|
+
const object = resultBase(value, OPERATION_MUTATION_STATUSES);
|
|
150
170
|
if (object.status === "committed") {
|
|
151
171
|
exactKeys(object, "$", variantKeys("OperationMutationResult", object, "$"));
|
|
152
172
|
mutationReceipt(object.receipt, "$.receipt");
|
|
@@ -159,8 +179,7 @@ export function assertValidOperationMutationResult(
|
|
|
159
179
|
export function assertValidOperationCancellationResult(
|
|
160
180
|
value: unknown,
|
|
161
181
|
): asserts value is OperationCancellationResult {
|
|
162
|
-
resultBase(value, OPERATION_CANCELLATION_STATUSES);
|
|
163
|
-
const object = value as Record<string, unknown>;
|
|
182
|
+
const object = resultBase(value, OPERATION_CANCELLATION_STATUSES);
|
|
164
183
|
if (object.status === "committed") {
|
|
165
184
|
exactKeys(object, "$", variantKeys("OperationCancellationResult", object, "$"));
|
|
166
185
|
cancellationReceipt(object.receipt, "$.receipt");
|
|
@@ -177,11 +196,11 @@ export function assertValidOperationChangedEvent(
|
|
|
177
196
|
assertPayloadFree(value);
|
|
178
197
|
const object = exactObject(value, "$", OPERATION_FIELDS.OperationChangedEvent);
|
|
179
198
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
180
|
-
|
|
199
|
+
identifier(object.requestId, "$.requestId");
|
|
181
200
|
authority(object.authority, "$.authority");
|
|
182
201
|
natural(object.previousCatalogueRevision, "$.previousCatalogueRevision");
|
|
183
202
|
natural(object.committedCatalogueRevision, "$.committedCatalogueRevision");
|
|
184
|
-
|
|
203
|
+
nullableIdentifier(object.operationId, "$.operationId");
|
|
185
204
|
member(object.kind, OPERATION_CHANGED_KINDS, "$.kind");
|
|
186
205
|
}
|
|
187
206
|
|
|
@@ -189,38 +208,51 @@ export function assertPayloadFree(value: unknown): void {
|
|
|
189
208
|
visit(value, "$", new Set());
|
|
190
209
|
}
|
|
191
210
|
|
|
192
|
-
function resultBase(value: unknown, statuses:
|
|
211
|
+
function resultBase(value: unknown, statuses: ReadonlyArray<string>): Record<string, unknown> {
|
|
193
212
|
assertPayloadFree(value);
|
|
194
213
|
const object = record(value, "$");
|
|
195
214
|
member(object.status, statuses, "$.status");
|
|
196
|
-
|
|
215
|
+
identifier(object.requestId, "$.requestId");
|
|
197
216
|
assertValidOperationSnapshot(object.snapshot);
|
|
217
|
+
return object;
|
|
198
218
|
}
|
|
199
219
|
|
|
200
220
|
function operationEntry(value: unknown, path: string): asserts value is OperationEntryProjection {
|
|
201
221
|
const object = exactObject(value, path, OPERATION_FIELDS.OperationEntryProjection);
|
|
202
222
|
authority(object.authority, `${path}.authority`);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
223
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
224
|
+
identifier(object.kindId, `${path}.kindId`);
|
|
225
|
+
nullableIdentifier(object.scopeId, `${path}.scopeId`);
|
|
206
226
|
text(object.label, `${path}.label`);
|
|
207
|
-
member(
|
|
208
|
-
|
|
227
|
+
member(
|
|
228
|
+
object.cancellationSupport,
|
|
229
|
+
["supported", "unsupported"] as const,
|
|
230
|
+
`${path}.cancellationSupport`,
|
|
231
|
+
);
|
|
232
|
+
nullableIdentifier(object.retryOf, `${path}.retryOf`);
|
|
209
233
|
natural(object.sequence, `${path}.sequence`);
|
|
210
234
|
natural(object.revision, `${path}.revision`);
|
|
211
235
|
natural(object.lastChangedCatalogueRevision, `${path}.lastChangedCatalogueRevision`);
|
|
212
236
|
member(object.state, OPERATION_STATES, `${path}.state`);
|
|
213
|
-
const progress = exactObject(
|
|
237
|
+
const progress = exactObject(
|
|
238
|
+
object.progress,
|
|
239
|
+
`${path}.progress`,
|
|
240
|
+
OPERATION_FIELDS.OperationProgressProjection,
|
|
241
|
+
);
|
|
214
242
|
natural(progress.sequence, `${path}.progress.sequence`);
|
|
215
243
|
progressOverall(progress.overall, `${path}.progress.overall`);
|
|
216
|
-
if (progress.phase !== null)
|
|
244
|
+
if (progress.phase !== null) {
|
|
245
|
+
phase(progress.phase, `${path}.progress.phase`);
|
|
246
|
+
}
|
|
217
247
|
natural(object.encodedMetadataWeight, `${path}.encodedMetadataWeight`);
|
|
218
248
|
}
|
|
219
249
|
|
|
220
250
|
function progressOverall(value: unknown, path: string): void {
|
|
221
251
|
const object = record(value, path);
|
|
222
252
|
member(object.kind, OPERATION_PROGRESS_KINDS, `${path}.kind`);
|
|
223
|
-
if (object.kind === "indeterminate")
|
|
253
|
+
if (object.kind === "indeterminate") {
|
|
254
|
+
exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
|
|
255
|
+
}
|
|
224
256
|
if (object.kind === "units") {
|
|
225
257
|
exactKeys(object, path, variantKeys("OperationOverallProgressProjection", object, path));
|
|
226
258
|
finite(object.completed, `${path}.completed`);
|
|
@@ -234,7 +266,7 @@ function progressOverall(value: unknown, path: string): void {
|
|
|
234
266
|
|
|
235
267
|
function phase(value: unknown, path: string): void {
|
|
236
268
|
const object = exactObject(value, path, OPERATION_FIELDS.OperationPhaseProgressProjection);
|
|
237
|
-
|
|
269
|
+
identifier(object.phaseId, `${path}.phaseId`);
|
|
238
270
|
text(object.label, `${path}.label`);
|
|
239
271
|
finite(object.completed, `${path}.completed`);
|
|
240
272
|
finite(object.total, `${path}.total`);
|
|
@@ -250,7 +282,7 @@ function teardownResolution(value: unknown, path: string): void {
|
|
|
250
282
|
exactKeys(object, path, variantKeys("OperationTeardownResolutionProjection", object, path));
|
|
251
283
|
authority(object.targetAuthority, `${path}.targetAuthority`);
|
|
252
284
|
}
|
|
253
|
-
|
|
285
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
254
286
|
natural(object.expectedOperationRevision, `${path}.expectedOperationRevision`);
|
|
255
287
|
}
|
|
256
288
|
|
|
@@ -270,16 +302,23 @@ function mutationReceipt(value: unknown, path: string): void {
|
|
|
270
302
|
operationEntry(object.operation, `${path}.operation`);
|
|
271
303
|
catalogueRevisionPair(object, path);
|
|
272
304
|
break;
|
|
273
|
-
case "progressed":
|
|
305
|
+
case "progressed": {
|
|
274
306
|
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
275
307
|
operationRevisionPair(object, path);
|
|
276
308
|
natural(object.previousProgressSequence, `${path}.previousProgressSequence`);
|
|
277
|
-
const progress = exactObject(
|
|
309
|
+
const progress = exactObject(
|
|
310
|
+
object.committedProgress,
|
|
311
|
+
`${path}.committedProgress`,
|
|
312
|
+
OPERATION_FIELDS.OperationProgressProjection,
|
|
313
|
+
);
|
|
278
314
|
natural(progress.sequence, `${path}.committedProgress.sequence`);
|
|
279
315
|
progressOverall(progress.overall, `${path}.committedProgress.overall`);
|
|
280
|
-
if (progress.phase !== null)
|
|
316
|
+
if (progress.phase !== null) {
|
|
317
|
+
phase(progress.phase, `${path}.committedProgress.phase`);
|
|
318
|
+
}
|
|
281
319
|
catalogueRevisionPair(object, path);
|
|
282
320
|
break;
|
|
321
|
+
}
|
|
283
322
|
case "transitioned":
|
|
284
323
|
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
285
324
|
member(object.previousState, OPERATION_STATES, `${path}.previousState`);
|
|
@@ -304,7 +343,9 @@ function mutationReceipt(value: unknown, path: string): void {
|
|
|
304
343
|
case "tornDown":
|
|
305
344
|
exactKeys(object, path, variantKeys("OperationMutationReceiptProjection", object, path));
|
|
306
345
|
catalogueRevisionPair(object, path);
|
|
307
|
-
array(object.outcomes, `${path}.outcomes`).forEach((outcome, index) =>
|
|
346
|
+
array(object.outcomes, `${path}.outcomes`).forEach((outcome, index) =>
|
|
347
|
+
teardownOutcome(outcome, `${path}.outcomes[${index}]`),
|
|
348
|
+
);
|
|
308
349
|
removals(object.evicted, `${path}.evicted`);
|
|
309
350
|
break;
|
|
310
351
|
}
|
|
@@ -312,7 +353,7 @@ function mutationReceipt(value: unknown, path: string): void {
|
|
|
312
353
|
|
|
313
354
|
function cancellationReceipt(value: unknown, path: string): void {
|
|
314
355
|
const object = exactObject(value, path, OPERATION_FIELDS.OperationCancellationReceiptProjection);
|
|
315
|
-
|
|
356
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
316
357
|
member(object.outcome, OPERATION_CANCELLATION_OUTCOMES, `${path}.outcome`);
|
|
317
358
|
member(object.previousState, OPERATION_STATES, `${path}.previousState`);
|
|
318
359
|
member(object.committedState, OPERATION_STATES, `${path}.committedState`);
|
|
@@ -336,7 +377,7 @@ function executorDispatch(value: unknown, path: string): void {
|
|
|
336
377
|
|
|
337
378
|
function removal(value: unknown, path: string): void {
|
|
338
379
|
const object = exactObject(value, path, OPERATION_FIELDS.OperationRemovalProjection);
|
|
339
|
-
|
|
380
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
340
381
|
natural(object.sequence, `${path}.sequence`);
|
|
341
382
|
natural(object.encodedWeight, `${path}.encodedWeight`);
|
|
342
383
|
member(object.reason, ["evicted", "dismissed"] as const, `${path}.reason`);
|
|
@@ -356,9 +397,11 @@ function teardownOutcome(value: unknown, path: string): void {
|
|
|
356
397
|
exactKeys(object, path, variantKeys("OperationTeardownOutcomeProjection", object, path));
|
|
357
398
|
authority(object.targetAuthority, `${path}.targetAuthority`);
|
|
358
399
|
}
|
|
359
|
-
|
|
400
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
360
401
|
natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
|
|
361
|
-
if (object.kind === "completed")
|
|
402
|
+
if (object.kind === "completed") {
|
|
403
|
+
natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
|
|
404
|
+
}
|
|
362
405
|
}
|
|
363
406
|
|
|
364
407
|
function limits(value: unknown, path: string): void {
|
|
@@ -369,7 +412,7 @@ function limits(value: unknown, path: string): void {
|
|
|
369
412
|
}
|
|
370
413
|
|
|
371
414
|
function operationRevisionPair(object: Record<string, unknown>, path: string): void {
|
|
372
|
-
|
|
415
|
+
identifier(object.operationId, `${path}.operationId`);
|
|
373
416
|
natural(object.previousOperationRevision, `${path}.previousOperationRevision`);
|
|
374
417
|
natural(object.committedOperationRevision, `${path}.committedOperationRevision`);
|
|
375
418
|
}
|
|
@@ -380,79 +423,122 @@ function catalogueRevisionPair(object: Record<string, unknown>, path: string): v
|
|
|
380
423
|
}
|
|
381
424
|
|
|
382
425
|
function operationTarget(object: Record<string, unknown>): void {
|
|
383
|
-
|
|
426
|
+
identifier(object.operationId, "$.operationId");
|
|
384
427
|
natural(object.expectedOperationRevision, "$.expectedOperationRevision");
|
|
385
428
|
}
|
|
386
429
|
|
|
387
430
|
function authority(value: unknown, path: string): void {
|
|
388
431
|
const object = exactObject(value, path, OPERATION_FIELDS.OperationAuthorityProjection);
|
|
389
|
-
|
|
432
|
+
identifier(object.authorityId, `${path}.authorityId`);
|
|
390
433
|
natural(object.authorityEpoch, `${path}.authorityEpoch`);
|
|
391
|
-
if (object.authorityEpoch === 0)
|
|
434
|
+
if (object.authorityEpoch === 0) {
|
|
435
|
+
fail(`${path}.authorityEpoch`, "must be nonzero");
|
|
436
|
+
}
|
|
392
437
|
}
|
|
393
438
|
|
|
394
439
|
function protocol(value: unknown, path: string): void {
|
|
395
440
|
natural(value, path);
|
|
396
|
-
if (value !== OPERATION_PROTOCOL_VERSION)
|
|
441
|
+
if (value !== OPERATION_PROTOCOL_VERSION) {
|
|
442
|
+
fail(path, `expected ${OPERATION_PROTOCOL_VERSION}`);
|
|
443
|
+
}
|
|
397
444
|
}
|
|
398
445
|
|
|
399
|
-
function exactObject(
|
|
446
|
+
function exactObject(
|
|
447
|
+
value: unknown,
|
|
448
|
+
path: string,
|
|
449
|
+
keys: ReadonlyArray<string>,
|
|
450
|
+
): Record<string, unknown> {
|
|
400
451
|
const object = record(value, path);
|
|
401
452
|
exactKeys(object, path, keys);
|
|
402
453
|
return object;
|
|
403
454
|
}
|
|
404
455
|
|
|
405
|
-
function exactKeys(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
456
|
+
function exactKeys(
|
|
457
|
+
object: Record<string, unknown>,
|
|
458
|
+
path: string,
|
|
459
|
+
keys: ReadonlyArray<string>,
|
|
460
|
+
): void {
|
|
461
|
+
checkWireFields(object, keys, () =>
|
|
462
|
+
fail(
|
|
463
|
+
path,
|
|
464
|
+
`expected keys ${[...keys].sort().join(",")}; received ${Object.keys(object).sort().join(",")}`,
|
|
465
|
+
),
|
|
466
|
+
);
|
|
411
467
|
}
|
|
412
468
|
|
|
413
469
|
function record(value: unknown, path: string): Record<string, unknown> {
|
|
414
|
-
|
|
415
|
-
return
|
|
470
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
471
|
+
return result;
|
|
416
472
|
}
|
|
417
473
|
|
|
418
|
-
function array(value: unknown, path: string): unknown
|
|
419
|
-
if (!Array.isArray(value))
|
|
474
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
475
|
+
if (!Array.isArray(value)) {
|
|
476
|
+
fail(path, "expected array");
|
|
477
|
+
}
|
|
420
478
|
return value;
|
|
421
479
|
}
|
|
422
480
|
|
|
423
481
|
function text(value: unknown, path: string): asserts value is string {
|
|
424
|
-
if (typeof value !== "string" || value.length === 0)
|
|
482
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
483
|
+
fail(path, "expected non-empty string");
|
|
484
|
+
}
|
|
425
485
|
}
|
|
426
486
|
|
|
427
|
-
function
|
|
428
|
-
if (value
|
|
487
|
+
function identifier(value: unknown, path: string): asserts value is string {
|
|
488
|
+
if (!isOpaqueId(value)) {
|
|
489
|
+
fail(path, "expected bounded lowercase opaque id");
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function nullableIdentifier(value: unknown, path: string): void {
|
|
494
|
+
if (value !== null) {
|
|
495
|
+
identifier(value, path);
|
|
496
|
+
}
|
|
429
497
|
}
|
|
430
498
|
|
|
431
499
|
function natural(value: unknown, path: string): asserts value is number {
|
|
432
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)
|
|
500
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
501
|
+
fail(path, "expected non-negative safe integer");
|
|
502
|
+
}
|
|
433
503
|
}
|
|
434
504
|
|
|
435
505
|
function finite(value: unknown, path: string): asserts value is number {
|
|
436
|
-
if (typeof value !== "number" || !Number.isFinite(value))
|
|
506
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
507
|
+
fail(path, "expected finite number");
|
|
508
|
+
}
|
|
437
509
|
}
|
|
438
510
|
|
|
439
511
|
function boolean(value: unknown, path: string): asserts value is boolean {
|
|
440
|
-
if (typeof value !== "boolean")
|
|
512
|
+
if (typeof value !== "boolean") {
|
|
513
|
+
fail(path, "expected boolean");
|
|
514
|
+
}
|
|
441
515
|
}
|
|
442
516
|
|
|
443
|
-
function member(
|
|
444
|
-
|
|
517
|
+
function member(
|
|
518
|
+
value: unknown,
|
|
519
|
+
values: ReadonlyArray<string>,
|
|
520
|
+
path: string,
|
|
521
|
+
): asserts value is string {
|
|
522
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
523
|
+
fail(path, `expected one of ${values.join(",")}`);
|
|
524
|
+
}
|
|
445
525
|
}
|
|
446
526
|
|
|
447
527
|
function visit(value: unknown, path: string, seen: Set<object>): void {
|
|
448
|
-
if (typeof value !== "object" || value === null)
|
|
449
|
-
|
|
528
|
+
if (typeof value !== "object" || value === null) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (seen.has(value)) {
|
|
532
|
+
fail(path, "cyclic value");
|
|
533
|
+
}
|
|
450
534
|
seen.add(value);
|
|
451
535
|
if (Array.isArray(value)) {
|
|
452
536
|
value.forEach((entry, index) => visit(entry, `${path}[${index}]`, seen));
|
|
453
537
|
} else {
|
|
454
538
|
for (const [key, entry] of Object.entries(value)) {
|
|
455
|
-
if (FORBIDDEN_PAYLOAD_KEYS.has(key))
|
|
539
|
+
if (FORBIDDEN_PAYLOAD_KEYS.has(key)) {
|
|
540
|
+
fail(`${path}.${key}`, "product payload field is forbidden");
|
|
541
|
+
}
|
|
456
542
|
visit(entry, `${path}.${key}`, seen);
|
|
457
543
|
}
|
|
458
544
|
}
|
|
@@ -463,17 +549,16 @@ function fail(path: string, message: string): never {
|
|
|
463
549
|
throw new OperationProtocolValidationError(path, message);
|
|
464
550
|
}
|
|
465
551
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return keys;
|
|
552
|
+
function variantKeys(
|
|
553
|
+
type: string,
|
|
554
|
+
object: Record<string, unknown>,
|
|
555
|
+
path: string,
|
|
556
|
+
): ReadonlyArray<string> {
|
|
557
|
+
return wireVariantFields(
|
|
558
|
+
OPERATION_VARIANT_FIELDS,
|
|
559
|
+
OPERATION_VARIANT_FIELDS_DISCRIMINANTS,
|
|
560
|
+
type,
|
|
561
|
+
object,
|
|
562
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
563
|
+
);
|
|
479
564
|
}
|
package/src/settings/client.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ConnectionFailureReporter,
|
|
3
|
-
EventTransport,
|
|
4
|
-
} from "@inflatable-cookie/longhorn/core";
|
|
1
|
+
import type { ConnectionFailureReporter, EventTransport } from "@inflatable-cookie/longhorn/core";
|
|
5
2
|
|
|
6
3
|
import type {
|
|
7
4
|
SettingsApplyCommand,
|
|
@@ -24,9 +21,8 @@ import {
|
|
|
24
21
|
connectSettingsRegistry,
|
|
25
22
|
connectSettingsScope,
|
|
26
23
|
SettingsAuthorityConsistencyError,
|
|
27
|
-
type SettingsScopeConnectionOptions,
|
|
28
|
-
type SettingsSubscription,
|
|
29
24
|
} from "./connection.ts";
|
|
25
|
+
import type { SettingsScopeConnectionOptions, SettingsSubscription } from "./connection.ts";
|
|
30
26
|
import {
|
|
31
27
|
SETTINGS_APPLY_COMMAND,
|
|
32
28
|
SETTINGS_LOAD_COMMAND,
|
|
@@ -42,10 +38,7 @@ export class SettingsClient {
|
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
async registry(): Promise<SettingsRegistrySnapshot> {
|
|
45
|
-
const value = await this.#transport.invoke(
|
|
46
|
-
SETTINGS_REGISTRY_COMMAND,
|
|
47
|
-
{},
|
|
48
|
-
);
|
|
41
|
+
const value = await this.#transport.invoke(SETTINGS_REGISTRY_COMMAND, {});
|
|
49
42
|
assertValidSettingsRegistrySnapshot(value);
|
|
50
43
|
return value;
|
|
51
44
|
}
|
|
@@ -59,10 +52,7 @@ export class SettingsClient {
|
|
|
59
52
|
const value = await this.#transport.invoke(SETTINGS_LOAD_COMMAND, {
|
|
60
53
|
command,
|
|
61
54
|
});
|
|
62
|
-
assertValidSettingsLoadOutcome(
|
|
63
|
-
value,
|
|
64
|
-
registry.limits.maximumOpaqueValueBytes,
|
|
65
|
-
);
|
|
55
|
+
assertValidSettingsLoadOutcome(value, registry.limits.maximumOpaqueValueBytes);
|
|
66
56
|
return value;
|
|
67
57
|
}
|
|
68
58
|
|
|
@@ -70,21 +60,12 @@ export class SettingsClient {
|
|
|
70
60
|
registry: SettingsRegistrySnapshot,
|
|
71
61
|
command: SettingsApplyCommand,
|
|
72
62
|
): Promise<SettingsMutationResult> {
|
|
73
|
-
assertValidSettingsApplyCommand(
|
|
74
|
-
|
|
75
|
-
registry.limits.maximumOpaqueValueBytes,
|
|
76
|
-
);
|
|
77
|
-
assertRegistryGeneration(
|
|
78
|
-
registry,
|
|
79
|
-
command.authority.registryGeneration,
|
|
80
|
-
);
|
|
63
|
+
assertValidSettingsApplyCommand(command, registry.limits.maximumOpaqueValueBytes);
|
|
64
|
+
assertRegistryGeneration(registry, command.authority.registryGeneration);
|
|
81
65
|
const value = await this.#transport.invoke(SETTINGS_APPLY_COMMAND, {
|
|
82
66
|
command,
|
|
83
67
|
});
|
|
84
|
-
assertValidSettingsMutationResult(
|
|
85
|
-
value,
|
|
86
|
-
registry.limits.maximumOpaqueValueBytes,
|
|
87
|
-
);
|
|
68
|
+
assertValidSettingsMutationResult(value, registry.limits.maximumOpaqueValueBytes);
|
|
88
69
|
return value;
|
|
89
70
|
}
|
|
90
71
|
|
|
@@ -93,17 +74,11 @@ export class SettingsClient {
|
|
|
93
74
|
command: SettingsResetCommand,
|
|
94
75
|
): Promise<SettingsMutationResult> {
|
|
95
76
|
assertValidSettingsResetCommand(command);
|
|
96
|
-
assertRegistryGeneration(
|
|
97
|
-
registry,
|
|
98
|
-
command.authority.registryGeneration,
|
|
99
|
-
);
|
|
77
|
+
assertRegistryGeneration(registry, command.authority.registryGeneration);
|
|
100
78
|
const value = await this.#transport.invoke(SETTINGS_RESET_COMMAND, {
|
|
101
79
|
command,
|
|
102
80
|
});
|
|
103
|
-
assertValidSettingsMutationResult(
|
|
104
|
-
value,
|
|
105
|
-
registry.limits.maximumOpaqueValueBytes,
|
|
106
|
-
);
|
|
81
|
+
assertValidSettingsMutationResult(value, registry.limits.maximumOpaqueValueBytes);
|
|
107
82
|
return value;
|
|
108
83
|
}
|
|
109
84
|
|
|
@@ -111,12 +86,7 @@ export class SettingsClient {
|
|
|
111
86
|
listener?: (snapshot: SettingsRegistrySnapshot) => void,
|
|
112
87
|
onFailure?: ConnectionFailureReporter,
|
|
113
88
|
): SettingsSubscription<SettingsRegistrySnapshot> {
|
|
114
|
-
return connectSettingsRegistry(
|
|
115
|
-
this.#transport,
|
|
116
|
-
() => this.registry(),
|
|
117
|
-
listener,
|
|
118
|
-
onFailure,
|
|
119
|
-
);
|
|
89
|
+
return connectSettingsRegistry(this.#transport, () => this.registry(), listener, onFailure);
|
|
120
90
|
}
|
|
121
91
|
|
|
122
92
|
connectScope(
|
|
@@ -130,10 +100,7 @@ export class SettingsClient {
|
|
|
130
100
|
}
|
|
131
101
|
}
|
|
132
102
|
|
|
133
|
-
function assertRegistryGeneration(
|
|
134
|
-
registry: SettingsRegistrySnapshot,
|
|
135
|
-
generation: number,
|
|
136
|
-
): void {
|
|
103
|
+
function assertRegistryGeneration(registry: SettingsRegistrySnapshot, generation: number): void {
|
|
137
104
|
if (generation !== registry.generation) {
|
|
138
105
|
throw new SettingsAuthorityConsistencyError(
|
|
139
106
|
"settings command registry generation does not match its registry",
|