@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,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
3
|
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
4
|
// each list, because `exact()` compares every key.
|
|
@@ -12,7 +12,9 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
|
|
|
12
12
|
"installFailed": ["cause", "detail"],
|
|
13
13
|
},
|
|
14
14
|
"UpdateAvailabilityProjection": {
|
|
15
|
+
"notChecked": ["state"],
|
|
15
16
|
"offer": ["state", "version", "reason", "notes"],
|
|
17
|
+
"unavailableForTarget": ["state", "version"],
|
|
16
18
|
"upToDate": ["state"],
|
|
17
19
|
"aheadOfChannel": ["state", "installed", "channel"],
|
|
18
20
|
"withheldByRollout": ["state", "version"],
|
|
@@ -31,7 +33,7 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
|
|
|
31
33
|
},
|
|
32
34
|
"UpdateOutcomeProjection": {
|
|
33
35
|
"committed": ["status", "snapshot"],
|
|
34
|
-
"rejected": ["status", "code", "snapshot"],
|
|
36
|
+
"rejected": ["status", "code", "detail", "snapshot"],
|
|
35
37
|
},
|
|
36
38
|
};
|
|
37
39
|
|
package/src/update/ports.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
2
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
3
|
import type {
|
|
2
4
|
UpdateApplyCommand,
|
|
3
5
|
UpdateCancelCommand,
|
|
@@ -6,12 +8,11 @@ import type {
|
|
|
6
8
|
UpdateDeferCommand,
|
|
7
9
|
UpdateOutcomeProjection,
|
|
8
10
|
UpdatePrepareCommand,
|
|
9
|
-
UpdateProgressEvent,
|
|
10
11
|
UpdateSelectChannelCommand,
|
|
11
12
|
UpdateSnapshot,
|
|
12
13
|
} from "./generated/protocol.ts";
|
|
13
14
|
|
|
14
|
-
export type UpdateUnlisten =
|
|
15
|
+
export type UpdateUnlisten = Unlisten;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* The raw seam.
|
|
@@ -25,10 +26,15 @@ export interface UpdatePort {
|
|
|
25
26
|
selectChannel(command: UpdateSelectChannelCommand): Promise<unknown>;
|
|
26
27
|
defer(command: UpdateDeferCommand): Promise<unknown>;
|
|
27
28
|
prepare(command: UpdatePrepareCommand): Promise<unknown>;
|
|
29
|
+
/** Reports from this prepare invocation only. */
|
|
30
|
+
prepareWithProgress?:
|
|
31
|
+
| ((command: UpdatePrepareCommand, listener: (event: unknown) => void) => Promise<unknown>)
|
|
32
|
+
| undefined;
|
|
28
33
|
apply(command: UpdateApplyCommand): Promise<unknown>;
|
|
29
34
|
cancel(command: UpdateCancelCommand): Promise<unknown>;
|
|
30
|
-
listen
|
|
31
|
-
|
|
35
|
+
listen?:
|
|
36
|
+
| ((listener: (event: unknown) => void) => UpdateUnlisten | Promise<UpdateUnlisten>)
|
|
37
|
+
| undefined;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/** The same seam after validation. */
|
|
@@ -40,6 +46,8 @@ export interface CheckedUpdatePort {
|
|
|
40
46
|
prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection>;
|
|
41
47
|
apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection>;
|
|
42
48
|
cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection>;
|
|
43
|
-
listen(
|
|
44
|
-
|
|
49
|
+
listen(
|
|
50
|
+
listener: (event: UpdateChangedEvent) => void,
|
|
51
|
+
onFailure?: ConnectionFailureReporter,
|
|
52
|
+
): Promise<UpdateUnlisten>;
|
|
45
53
|
}
|
package/src/update/serialized.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
1
2
|
import type {
|
|
2
3
|
UpdateApplyCommand,
|
|
3
4
|
UpdateCancelCommand,
|
|
@@ -9,14 +10,39 @@ import type {
|
|
|
9
10
|
import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
|
|
10
11
|
export class SerializedUpdatePort implements UpdatePort {
|
|
11
12
|
constructor(readonly inner: UpdatePort) {}
|
|
12
|
-
async snapshot(): Promise<unknown> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
async snapshot(): Promise<unknown> {
|
|
14
|
+
return wireCopy(await this.inner.snapshot());
|
|
15
|
+
}
|
|
16
|
+
async check(command: UpdateCheckCommand): Promise<unknown> {
|
|
17
|
+
return wireCopy(await this.inner.check(wireCopy(command)));
|
|
18
|
+
}
|
|
19
|
+
async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> {
|
|
20
|
+
return wireCopy(await this.inner.selectChannel(wireCopy(command)));
|
|
21
|
+
}
|
|
22
|
+
async defer(command: UpdateDeferCommand): Promise<unknown> {
|
|
23
|
+
return wireCopy(await this.inner.defer(wireCopy(command)));
|
|
24
|
+
}
|
|
25
|
+
async prepare(command: UpdatePrepareCommand): Promise<unknown> {
|
|
26
|
+
return wireCopy(await this.inner.prepare(wireCopy(command)));
|
|
27
|
+
}
|
|
28
|
+
get prepareWithProgress(): UpdatePort["prepareWithProgress"] {
|
|
29
|
+
const prepare = this.inner.prepareWithProgress?.bind(this.inner);
|
|
30
|
+
if (prepare === undefined) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return async (command, listener) =>
|
|
34
|
+
wireCopy(await prepare(wireCopy(command), (event) => listener(wireCopy(event))));
|
|
35
|
+
}
|
|
36
|
+
async apply(command: UpdateApplyCommand): Promise<unknown> {
|
|
37
|
+
return wireCopy(await this.inner.apply(wireCopy(command)));
|
|
38
|
+
}
|
|
39
|
+
async cancel(command: UpdateCancelCommand): Promise<unknown> {
|
|
40
|
+
return wireCopy(await this.inner.cancel(wireCopy(command)));
|
|
41
|
+
}
|
|
42
|
+
async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
|
|
43
|
+
if (this.inner.listen === undefined) {
|
|
44
|
+
return () => {};
|
|
45
|
+
}
|
|
46
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
47
|
+
}
|
|
21
48
|
}
|
|
22
|
-
function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
|
package/src/update/validation.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
1
2
|
import { UPDATE_FIELDS } from "./generated/fields.ts";
|
|
2
3
|
import {
|
|
3
4
|
UPDATE_AVAILABILITY_STATES,
|
|
@@ -11,17 +12,19 @@ import {
|
|
|
11
12
|
UPDATE_PROGRESS_STATES,
|
|
12
13
|
UPDATE_PROTOCOL_VERSION,
|
|
13
14
|
UPDATE_REJECTION_CODES,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
} from "./generated/protocol.ts";
|
|
16
|
+
import type {
|
|
17
|
+
UpdateApplyCommand,
|
|
18
|
+
UpdateCancelCommand,
|
|
19
|
+
UpdateChangedEvent,
|
|
20
|
+
UpdateCheckCommand,
|
|
21
|
+
UpdateDeferCommand,
|
|
22
|
+
UpdateInstallAuthorizationProjection,
|
|
23
|
+
UpdateOutcomeProjection,
|
|
24
|
+
UpdatePrepareCommand,
|
|
25
|
+
UpdateProgressEvent,
|
|
26
|
+
UpdateSelectChannelCommand,
|
|
27
|
+
UpdateSnapshot,
|
|
25
28
|
} from "./generated/protocol.ts";
|
|
26
29
|
import {
|
|
27
30
|
UPDATE_VARIANT_FIELDS,
|
|
@@ -68,7 +71,10 @@ export function assertUpdateOutcome(value: unknown): asserts value is UpdateOutc
|
|
|
68
71
|
const root = object(value, "$");
|
|
69
72
|
oneOf(root.status, "$.status", UPDATE_OUTCOME_STATUSES);
|
|
70
73
|
exact(root, "$", variantFields("UpdateOutcomeProjection", root, "$"));
|
|
71
|
-
if (root.status === "rejected")
|
|
74
|
+
if (root.status === "rejected") {
|
|
75
|
+
oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
|
|
76
|
+
optionalString(root.detail, "$.detail");
|
|
77
|
+
}
|
|
72
78
|
assertUpdateSnapshot(root.snapshot);
|
|
73
79
|
}
|
|
74
80
|
|
|
@@ -106,7 +112,9 @@ export function assertUpdatePrepareCommand(value: unknown): asserts value is Upd
|
|
|
106
112
|
|
|
107
113
|
export function assertUpdateApplyCommand(value: unknown): asserts value is UpdateApplyCommand {
|
|
108
114
|
commandBase(value, UPDATE_FIELDS.UpdateApplyCommand);
|
|
109
|
-
|
|
115
|
+
const root = object(value, "$");
|
|
116
|
+
version(root.version, "$.version");
|
|
117
|
+
digest(root.digest, "$.digest");
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
export function assertUpdateCancelCommand(value: unknown): asserts value is UpdateCancelCommand {
|
|
@@ -138,7 +146,9 @@ export function assertUpdateInstallAuthorization(
|
|
|
138
146
|
const root = object(value, "$");
|
|
139
147
|
oneOf(root.status, "$.status", UPDATE_INSTALL_AUTHORIZATION_STATUSES);
|
|
140
148
|
exact(root, "$", variantFields("UpdateInstallAuthorizationProjection", root, "$"));
|
|
141
|
-
if (root.status === "deferred")
|
|
149
|
+
if (root.status === "deferred") {
|
|
150
|
+
cause(root.cause, "$.cause");
|
|
151
|
+
}
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
function availability(value: unknown, path: string): void {
|
|
@@ -150,15 +160,17 @@ function availability(value: unknown, path: string): void {
|
|
|
150
160
|
oneOf(root.reason, `${path}.reason`, UPDATE_OFFER_REASONS);
|
|
151
161
|
optionalString(root.notes, `${path}.notes`);
|
|
152
162
|
}
|
|
153
|
-
//
|
|
154
|
-
// read to say anything useful: "you are on 1.3.0-nightly.4 and production
|
|
155
|
-
// publishes 1.2.9" is the whole message, and Card 154 calls it the single
|
|
156
|
-
// most likely support question the feature generates.
|
|
163
|
+
// The surface needs both versions to explain why the channel has no offer.
|
|
157
164
|
if (root.state === "aheadOfChannel") {
|
|
158
165
|
version(root.installed, `${path}.installed`);
|
|
159
166
|
version(root.channel, `${path}.channel`);
|
|
160
167
|
}
|
|
161
|
-
if (root.state === "
|
|
168
|
+
if (root.state === "unavailableForTarget") {
|
|
169
|
+
version(root.version, `${path}.version`);
|
|
170
|
+
}
|
|
171
|
+
if (root.state === "withheldByRollout") {
|
|
172
|
+
version(root.version, `${path}.version`);
|
|
173
|
+
}
|
|
162
174
|
if (root.state === "managedElsewhere") {
|
|
163
175
|
version(root.version, `${path}.version`);
|
|
164
176
|
oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
|
|
@@ -194,7 +206,7 @@ function cause(value: unknown, path: string): void {
|
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
|
|
197
|
-
function commandBase(value: unknown, expected:
|
|
209
|
+
function commandBase(value: unknown, expected: ReadonlyArray<string>): void {
|
|
198
210
|
noPayload(value);
|
|
199
211
|
const root = object(value, "$");
|
|
200
212
|
exact(root, "$", expected);
|
|
@@ -202,46 +214,104 @@ function commandBase(value: unknown, expected: readonly string[]): void {
|
|
|
202
214
|
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
203
215
|
}
|
|
204
216
|
|
|
205
|
-
/**
|
|
206
|
-
* Allowed keys for one variant, from the generated map.
|
|
207
|
-
*
|
|
208
|
-
* A missing entry means the generator failed to read the union, not that a
|
|
209
|
-
* consumer sent something odd — every caller runs `oneOf` over the
|
|
210
|
-
* discriminant first, so an unknown one is already rejected by then.
|
|
211
|
-
*/
|
|
212
217
|
function variantFields(
|
|
213
218
|
type: string,
|
|
214
219
|
value: Record<string, unknown>,
|
|
215
220
|
path: string,
|
|
216
|
-
):
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
): ReadonlyArray<string> {
|
|
222
|
+
return wireVariantFields(
|
|
223
|
+
UPDATE_VARIANT_FIELDS,
|
|
224
|
+
UPDATE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
225
|
+
type,
|
|
226
|
+
value,
|
|
227
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
228
|
+
);
|
|
221
229
|
}
|
|
222
230
|
|
|
223
231
|
function noPayload(value: unknown): void {
|
|
224
232
|
const visit = (candidate: unknown, path: string): void => {
|
|
225
|
-
if (Array.isArray(candidate))
|
|
226
|
-
|
|
233
|
+
if (Array.isArray(candidate)) {
|
|
234
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
235
|
+
}
|
|
236
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
227
237
|
for (const [key, child] of Object.entries(candidate)) {
|
|
228
|
-
if (key.toLocaleLowerCase().includes("payload"))
|
|
238
|
+
if (key.toLocaleLowerCase().includes("payload")) {
|
|
239
|
+
fail(`${path}.${key}`, "product payload field is forbidden");
|
|
240
|
+
}
|
|
229
241
|
visit(child, `${path}.${key}`);
|
|
230
242
|
}
|
|
243
|
+
}
|
|
231
244
|
};
|
|
232
245
|
visit(value, "$");
|
|
233
246
|
}
|
|
234
|
-
function object(value: unknown, path: string): Record<string, unknown> {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
247
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
248
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
function exact(
|
|
252
|
+
value: Record<string, unknown>,
|
|
253
|
+
path: string,
|
|
254
|
+
expected: ReadonlyArray<string>,
|
|
255
|
+
): void {
|
|
256
|
+
checkWireFields(value, expected, () =>
|
|
257
|
+
fail(path, `unexpected keys: ${Object.keys(value).sort().join(",")}`),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function protocol(value: unknown, path: string): void {
|
|
261
|
+
if (value !== UPDATE_PROTOCOL_VERSION) {
|
|
262
|
+
fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function positive(value: unknown, path: string): void {
|
|
266
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
267
|
+
fail(path, "expected positive safe integer");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function count(value: unknown, path: string): void {
|
|
271
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
272
|
+
fail(path, "expected a non-negative safe byte count");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function optionalCount(value: unknown, path: string): void {
|
|
276
|
+
if (value !== null) {
|
|
277
|
+
count(value, path);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function digest(value: unknown, path: string): void {
|
|
281
|
+
if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
|
|
282
|
+
fail(path, "expected 64 lowercase hex digits");
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
286
|
+
if (typeof value !== "string") {
|
|
287
|
+
fail(path, "expected string");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function optionalString(value: unknown, path: string): void {
|
|
291
|
+
if (value !== null) {
|
|
292
|
+
string(value, path);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
243
295
|
/** Versions are strings on the wire, as `semver::Version` serialises them. */
|
|
244
|
-
function version(value: unknown, path: string): void {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
296
|
+
function version(value: unknown, path: string): void {
|
|
297
|
+
string(value, path);
|
|
298
|
+
if (value.length === 0) {
|
|
299
|
+
fail(path, "expected non-empty version");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function fraction(value: unknown, path: string): void {
|
|
303
|
+
if (value === null) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
|
|
307
|
+
fail(path, "expected a fraction between 0 and 1, or null");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
311
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
312
|
+
fail(path, "unsupported value");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function fail(path: string, message: string): never {
|
|
316
|
+
throw new UpdateValidationError(path, message);
|
|
317
|
+
}
|