@inflatable-cookie/longhorn 0.5.0 → 0.6.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/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- 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 +77 -105
- 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 +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
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,37 @@ 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
|
+
async apply(command: UpdateApplyCommand): Promise<unknown> {
|
|
29
|
+
return wireCopy(await this.inner.apply(wireCopy(command)));
|
|
30
|
+
}
|
|
31
|
+
async cancel(command: UpdateCancelCommand): Promise<unknown> {
|
|
32
|
+
return wireCopy(await this.inner.cancel(wireCopy(command)));
|
|
33
|
+
}
|
|
34
|
+
async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
|
|
35
|
+
if (this.inner.listen === undefined) {
|
|
36
|
+
return () => {};
|
|
37
|
+
}
|
|
38
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
39
|
+
}
|
|
40
|
+
async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
|
|
41
|
+
if (this.inner.listenProgress === undefined) {
|
|
42
|
+
return () => {};
|
|
43
|
+
}
|
|
44
|
+
return this.inner.listenProgress((event) => listener(wireCopy(event)));
|
|
45
|
+
}
|
|
21
46
|
}
|
|
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 { isRecord } 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,9 @@ 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
|
+
}
|
|
72
77
|
assertUpdateSnapshot(root.snapshot);
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -106,7 +111,9 @@ export function assertUpdatePrepareCommand(value: unknown): asserts value is Upd
|
|
|
106
111
|
|
|
107
112
|
export function assertUpdateApplyCommand(value: unknown): asserts value is UpdateApplyCommand {
|
|
108
113
|
commandBase(value, UPDATE_FIELDS.UpdateApplyCommand);
|
|
109
|
-
|
|
114
|
+
const root = object(value, "$");
|
|
115
|
+
version(root.version, "$.version");
|
|
116
|
+
digest(root.digest, "$.digest");
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
export function assertUpdateCancelCommand(value: unknown): asserts value is UpdateCancelCommand {
|
|
@@ -138,7 +145,9 @@ export function assertUpdateInstallAuthorization(
|
|
|
138
145
|
const root = object(value, "$");
|
|
139
146
|
oneOf(root.status, "$.status", UPDATE_INSTALL_AUTHORIZATION_STATUSES);
|
|
140
147
|
exact(root, "$", variantFields("UpdateInstallAuthorizationProjection", root, "$"));
|
|
141
|
-
if (root.status === "deferred")
|
|
148
|
+
if (root.status === "deferred") {
|
|
149
|
+
cause(root.cause, "$.cause");
|
|
150
|
+
}
|
|
142
151
|
}
|
|
143
152
|
|
|
144
153
|
function availability(value: unknown, path: string): void {
|
|
@@ -158,7 +167,9 @@ function availability(value: unknown, path: string): void {
|
|
|
158
167
|
version(root.installed, `${path}.installed`);
|
|
159
168
|
version(root.channel, `${path}.channel`);
|
|
160
169
|
}
|
|
161
|
-
if (root.state === "withheldByRollout")
|
|
170
|
+
if (root.state === "withheldByRollout") {
|
|
171
|
+
version(root.version, `${path}.version`);
|
|
172
|
+
}
|
|
162
173
|
if (root.state === "managedElsewhere") {
|
|
163
174
|
version(root.version, `${path}.version`);
|
|
164
175
|
oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
|
|
@@ -194,7 +205,7 @@ function cause(value: unknown, path: string): void {
|
|
|
194
205
|
}
|
|
195
206
|
}
|
|
196
207
|
|
|
197
|
-
function commandBase(value: unknown, expected:
|
|
208
|
+
function commandBase(value: unknown, expected: ReadonlyArray<string>): void {
|
|
198
209
|
noPayload(value);
|
|
199
210
|
const root = object(value, "$");
|
|
200
211
|
exact(root, "$", expected);
|
|
@@ -213,35 +224,104 @@ function variantFields(
|
|
|
213
224
|
type: string,
|
|
214
225
|
value: Record<string, unknown>,
|
|
215
226
|
path: string,
|
|
216
|
-
):
|
|
227
|
+
): ReadonlyArray<string> {
|
|
217
228
|
const discriminant = value[UPDATE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
218
|
-
const fields =
|
|
219
|
-
|
|
229
|
+
const fields =
|
|
230
|
+
typeof discriminant === "string" ? UPDATE_VARIANT_FIELDS[type]?.[discriminant] : undefined;
|
|
231
|
+
if (fields === undefined) {
|
|
232
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
233
|
+
}
|
|
220
234
|
return fields;
|
|
221
235
|
}
|
|
222
236
|
|
|
223
237
|
function noPayload(value: unknown): void {
|
|
224
238
|
const visit = (candidate: unknown, path: string): void => {
|
|
225
|
-
if (Array.isArray(candidate))
|
|
226
|
-
|
|
239
|
+
if (Array.isArray(candidate)) {
|
|
240
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
241
|
+
}
|
|
242
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
227
243
|
for (const [key, child] of Object.entries(candidate)) {
|
|
228
|
-
if (key.toLocaleLowerCase().includes("payload"))
|
|
244
|
+
if (key.toLocaleLowerCase().includes("payload")) {
|
|
245
|
+
fail(`${path}.${key}`, "product payload field is forbidden");
|
|
246
|
+
}
|
|
229
247
|
visit(child, `${path}.${key}`);
|
|
230
248
|
}
|
|
249
|
+
}
|
|
231
250
|
};
|
|
232
251
|
visit(value, "$");
|
|
233
252
|
}
|
|
234
|
-
function object(value: unknown, path: string): Record<string, unknown> {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
254
|
+
if (!isRecord(value)) {
|
|
255
|
+
fail(path, "expected object");
|
|
256
|
+
}
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
function exact(
|
|
260
|
+
value: Record<string, unknown>,
|
|
261
|
+
path: string,
|
|
262
|
+
expected: ReadonlyArray<string>,
|
|
263
|
+
): void {
|
|
264
|
+
const actual = Object.keys(value).sort();
|
|
265
|
+
const wanted = [...expected].sort();
|
|
266
|
+
if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
|
|
267
|
+
fail(path, `unexpected keys: ${actual.join(",")}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function protocol(value: unknown, path: string): void {
|
|
271
|
+
if (value !== UPDATE_PROTOCOL_VERSION) {
|
|
272
|
+
fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function positive(value: unknown, path: string): void {
|
|
276
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
277
|
+
fail(path, "expected positive safe integer");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function count(value: unknown, path: string): void {
|
|
281
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
282
|
+
fail(path, "expected a non-negative safe byte count");
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function optionalCount(value: unknown, path: string): void {
|
|
286
|
+
if (value !== null) {
|
|
287
|
+
count(value, path);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function digest(value: unknown, path: string): void {
|
|
291
|
+
if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
|
|
292
|
+
fail(path, "expected 64 lowercase hex digits");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
296
|
+
if (typeof value !== "string") {
|
|
297
|
+
fail(path, "expected string");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function optionalString(value: unknown, path: string): void {
|
|
301
|
+
if (value !== null) {
|
|
302
|
+
string(value, path);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
243
305
|
/** Versions are strings on the wire, as `semver::Version` serialises them. */
|
|
244
|
-
function version(value: unknown, path: string): void {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
306
|
+
function version(value: unknown, path: string): void {
|
|
307
|
+
string(value, path);
|
|
308
|
+
if (value.length === 0) {
|
|
309
|
+
fail(path, "expected non-empty version");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function fraction(value: unknown, path: string): void {
|
|
313
|
+
if (value === null) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
|
|
317
|
+
fail(path, "expected a fraction between 0 and 1, or null");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
321
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
322
|
+
fail(path, "unsupported value");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function fail(path: string, message: string): never {
|
|
326
|
+
throw new UpdateValidationError(path, message);
|
|
327
|
+
}
|