@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
1
2
|
import {
|
|
2
3
|
NOTIFICATION_VARIANT_FIELDS,
|
|
3
4
|
NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -12,23 +13,30 @@ import {
|
|
|
12
13
|
NOTIFICATION_REJECTION_CODES,
|
|
13
14
|
NOTIFICATION_RETENTION_CLASSES,
|
|
14
15
|
NOTIFICATION_SEVERITIES,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
} from "./generated/protocol.ts";
|
|
17
|
+
import type {
|
|
18
|
+
NotificationChangedEvent,
|
|
19
|
+
NotificationMutationCommand,
|
|
20
|
+
NotificationMutationResult,
|
|
21
|
+
NotificationRecordProjection,
|
|
22
|
+
NotificationSnapshot,
|
|
23
|
+
NotificationSnapshotQuery,
|
|
24
|
+
NotificationSnapshotResponse,
|
|
22
25
|
} from "./generated/protocol.ts";
|
|
23
26
|
|
|
24
27
|
export class NotificationProtocolValidationError extends Error {
|
|
25
|
-
constructor(
|
|
28
|
+
constructor(
|
|
29
|
+
readonly path: string,
|
|
30
|
+
message: string,
|
|
31
|
+
) {
|
|
26
32
|
super(`incompatible notification protocol at ${path}: ${message}`);
|
|
27
33
|
this.name = "NotificationProtocolValidationError";
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
export function assertValidNotificationSnapshotQuery(
|
|
37
|
+
export function assertValidNotificationSnapshotQuery(
|
|
38
|
+
value: unknown,
|
|
39
|
+
): asserts value is NotificationSnapshotQuery {
|
|
32
40
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotQuery);
|
|
33
41
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
34
42
|
text(object.requestId, "$.requestId");
|
|
@@ -36,13 +44,17 @@ export function assertValidNotificationSnapshotQuery(value: unknown): asserts va
|
|
|
36
44
|
natural(object.limit, "$.limit");
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
export function assertValidNotificationSnapshotResponse(
|
|
47
|
+
export function assertValidNotificationSnapshotResponse(
|
|
48
|
+
value: unknown,
|
|
49
|
+
): asserts value is NotificationSnapshotResponse {
|
|
40
50
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotResponse);
|
|
41
51
|
text(object.requestId, "$.requestId");
|
|
42
52
|
assertValidNotificationSnapshot(object.snapshot);
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
export function assertValidNotificationSnapshot(
|
|
55
|
+
export function assertValidNotificationSnapshot(
|
|
56
|
+
value: unknown,
|
|
57
|
+
): asserts value is NotificationSnapshot {
|
|
46
58
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshot);
|
|
47
59
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
48
60
|
authority(object.authority, "$.authority");
|
|
@@ -56,10 +68,14 @@ export function assertValidNotificationSnapshot(value: unknown): asserts value i
|
|
|
56
68
|
natural(page.offset, "$.page.offset");
|
|
57
69
|
natural(page.totalCount, "$.page.totalCount");
|
|
58
70
|
boolean(page.hasMore, "$.page.hasMore");
|
|
59
|
-
array(page.records, "$.page.records").forEach((item, index) =>
|
|
71
|
+
array(page.records, "$.page.records").forEach((item, index) =>
|
|
72
|
+
recordProjection(item, `$.page.records[${index}]`),
|
|
73
|
+
);
|
|
60
74
|
}
|
|
61
75
|
|
|
62
|
-
export function assertValidNotificationMutationCommand(
|
|
76
|
+
export function assertValidNotificationMutationCommand(
|
|
77
|
+
value: unknown,
|
|
78
|
+
): asserts value is NotificationMutationCommand {
|
|
63
79
|
const object = record(value, "$");
|
|
64
80
|
member(object.kind, NOTIFICATION_MUTATION_KINDS, "$.kind");
|
|
65
81
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
@@ -86,8 +102,16 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
|
|
|
86
102
|
exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
|
|
87
103
|
const target = record(object.target, "$.target");
|
|
88
104
|
member(target.kind, ["all", "records"] as const, "$.target.kind");
|
|
89
|
-
exactKeys(
|
|
90
|
-
|
|
105
|
+
exactKeys(
|
|
106
|
+
target,
|
|
107
|
+
"$.target",
|
|
108
|
+
variantKeys("NotificationClearTargetProjection", target, "$.target"),
|
|
109
|
+
);
|
|
110
|
+
if (target.kind === "records") {
|
|
111
|
+
array(target.notificationIds, "$.target.notificationIds").forEach((id, index) =>
|
|
112
|
+
text(id, `$.target.notificationIds[${index}]`),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
91
115
|
break;
|
|
92
116
|
}
|
|
93
117
|
case "changeRetention":
|
|
@@ -97,7 +121,9 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
|
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
123
|
|
|
100
|
-
export function assertValidNotificationMutationResult(
|
|
124
|
+
export function assertValidNotificationMutationResult(
|
|
125
|
+
value: unknown,
|
|
126
|
+
): asserts value is NotificationMutationResult {
|
|
101
127
|
const object = record(value, "$");
|
|
102
128
|
member(object.status, NOTIFICATION_MUTATION_STATUSES, "$.status");
|
|
103
129
|
text(object.requestId, "$.requestId");
|
|
@@ -107,21 +133,29 @@ export function assertValidNotificationMutationResult(value: unknown): asserts v
|
|
|
107
133
|
receipt(object.receipt, "$.receipt");
|
|
108
134
|
} else {
|
|
109
135
|
exactKeys(object, "$", variantKeys("NotificationMutationResult", object, "$"));
|
|
110
|
-
const rejection = exact(
|
|
136
|
+
const rejection = exact(
|
|
137
|
+
object.rejection,
|
|
138
|
+
"$.rejection",
|
|
139
|
+
NOTIFICATIONS_FIELDS.NotificationRejection,
|
|
140
|
+
);
|
|
111
141
|
member(rejection.code, NOTIFICATION_REJECTION_CODES, "$.rejection.code");
|
|
112
142
|
text(rejection.detail, "$.rejection.detail");
|
|
113
143
|
boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
|
|
114
144
|
}
|
|
115
145
|
}
|
|
116
146
|
|
|
117
|
-
export function assertValidNotificationChangedEvent(
|
|
147
|
+
export function assertValidNotificationChangedEvent(
|
|
148
|
+
value: unknown,
|
|
149
|
+
): asserts value is NotificationChangedEvent {
|
|
118
150
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationChangedEvent);
|
|
119
151
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
120
152
|
text(object.requestId, "$.requestId");
|
|
121
153
|
authority(object.authority, "$.authority");
|
|
122
154
|
natural(object.previousLedgerRevision, "$.previousLedgerRevision");
|
|
123
155
|
natural(object.committedLedgerRevision, "$.committedLedgerRevision");
|
|
124
|
-
array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) =>
|
|
156
|
+
array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) =>
|
|
157
|
+
text(id, `$.affectedNotificationIds[${index}]`),
|
|
158
|
+
);
|
|
125
159
|
member(object.kind, NOTIFICATION_CHANGED_KINDS, "$.kind");
|
|
126
160
|
}
|
|
127
161
|
|
|
@@ -145,17 +179,26 @@ function draft(value: unknown, path: string): void {
|
|
|
145
179
|
text(object.summary, `${path}.summary`);
|
|
146
180
|
nullableText(object.causeId, `${path}.causeId`);
|
|
147
181
|
array(object.actions, `${path}.actions`).forEach((action, index) => {
|
|
148
|
-
const item = exact(
|
|
182
|
+
const item = exact(
|
|
183
|
+
action,
|
|
184
|
+
`${path}.actions[${index}]`,
|
|
185
|
+
NOTIFICATIONS_FIELDS.NotificationActionProjection,
|
|
186
|
+
);
|
|
149
187
|
text(item.referenceId, `${path}.actions[${index}].referenceId`);
|
|
150
188
|
text(item.label, `${path}.actions[${index}].label`);
|
|
151
189
|
});
|
|
152
190
|
nullableText(object.replacementKey, `${path}.replacementKey`);
|
|
153
191
|
nullableText(object.producerToken, `${path}.producerToken`);
|
|
154
192
|
member(object.retentionClass, NOTIFICATION_RETENTION_CLASSES, `${path}.retentionClass`);
|
|
155
|
-
if (object.presentationTimeUnixMs !== null)
|
|
193
|
+
if (object.presentationTimeUnixMs !== null) {
|
|
194
|
+
integer(object.presentationTimeUnixMs, `${path}.presentationTimeUnixMs`);
|
|
195
|
+
}
|
|
156
196
|
}
|
|
157
197
|
|
|
158
|
-
function recordProjection(
|
|
198
|
+
function recordProjection(
|
|
199
|
+
value: unknown,
|
|
200
|
+
path: string,
|
|
201
|
+
): asserts value is NotificationRecordProjection {
|
|
159
202
|
const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationRecordProjection);
|
|
160
203
|
text(object.notificationId, `${path}.notificationId`);
|
|
161
204
|
draft(object.draft, `${path}.draft`);
|
|
@@ -167,7 +210,11 @@ function recordProjection(value: unknown, path: string): asserts value is Notifi
|
|
|
167
210
|
|
|
168
211
|
function receipt(value: unknown, path: string): void {
|
|
169
212
|
const object = record(value, path);
|
|
170
|
-
member(
|
|
213
|
+
member(
|
|
214
|
+
object.kind,
|
|
215
|
+
["added", "replaced", "seen", "removed", "retentionChanged"] as const,
|
|
216
|
+
`${path}.kind`,
|
|
217
|
+
);
|
|
171
218
|
natural(object.previousLedgerRevision, `${path}.previousLedgerRevision`);
|
|
172
219
|
natural(object.committedLedgerRevision, `${path}.committedLedgerRevision`);
|
|
173
220
|
if (object.kind === "added" || object.kind === "replaced") {
|
|
@@ -190,46 +237,94 @@ function receipt(value: unknown, path: string): void {
|
|
|
190
237
|
|
|
191
238
|
function removals(value: unknown, path: string): void {
|
|
192
239
|
array(value, path).forEach((removal, index) => {
|
|
193
|
-
const item = exact(
|
|
240
|
+
const item = exact(
|
|
241
|
+
removal,
|
|
242
|
+
`${path}[${index}]`,
|
|
243
|
+
NOTIFICATIONS_FIELDS.NotificationRemovalProjection,
|
|
244
|
+
);
|
|
194
245
|
recordProjection(item.record, `${path}[${index}].record`);
|
|
195
246
|
member(item.reason, ["dismissed", "cleared", "pruned"] as const, `${path}[${index}].reason`);
|
|
196
247
|
});
|
|
197
248
|
}
|
|
198
249
|
|
|
199
250
|
function protocol(value: unknown, path: string): void {
|
|
200
|
-
if (value !== NOTIFICATION_PROTOCOL_VERSION)
|
|
251
|
+
if (value !== NOTIFICATION_PROTOCOL_VERSION) {
|
|
252
|
+
fail(path, `expected protocol ${NOTIFICATION_PROTOCOL_VERSION}`);
|
|
253
|
+
}
|
|
201
254
|
}
|
|
202
255
|
|
|
203
256
|
function record(value: unknown, path: string): Record<string, unknown> {
|
|
204
|
-
if (
|
|
205
|
-
|
|
257
|
+
if (!isRecord(value)) {
|
|
258
|
+
fail(path, "expected object");
|
|
259
|
+
}
|
|
260
|
+
return value;
|
|
206
261
|
}
|
|
207
262
|
|
|
208
|
-
function exact(value: unknown, path: string, keys:
|
|
263
|
+
function exact(value: unknown, path: string, keys: ReadonlyArray<string>): Record<string, unknown> {
|
|
209
264
|
const object = record(value, path);
|
|
210
265
|
exactKeys(object, path, keys);
|
|
211
266
|
return object;
|
|
212
267
|
}
|
|
213
268
|
|
|
214
|
-
function exactKeys(
|
|
269
|
+
function exactKeys(
|
|
270
|
+
object: Record<string, unknown>,
|
|
271
|
+
path: string,
|
|
272
|
+
keys: ReadonlyArray<string>,
|
|
273
|
+
): void {
|
|
215
274
|
const actual = Object.keys(object).sort();
|
|
216
275
|
const expected = [...keys].sort();
|
|
217
|
-
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index]))
|
|
276
|
+
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
277
|
+
fail(path, `expected keys ${expected.join(", ")}`);
|
|
278
|
+
}
|
|
218
279
|
}
|
|
219
280
|
|
|
220
|
-
function array(value: unknown, path: string): unknown
|
|
221
|
-
if (!Array.isArray(value))
|
|
281
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
282
|
+
if (!Array.isArray(value)) {
|
|
283
|
+
fail(path, "expected array");
|
|
284
|
+
}
|
|
222
285
|
return value;
|
|
223
286
|
}
|
|
224
287
|
|
|
225
|
-
function text(value: unknown, path: string): void {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
function
|
|
231
|
-
|
|
232
|
-
|
|
288
|
+
function text(value: unknown, path: string): void {
|
|
289
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
290
|
+
fail(path, "expected nonempty string");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function nullableText(value: unknown, path: string): void {
|
|
294
|
+
if (value !== null) {
|
|
295
|
+
text(value, path);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function boolean(value: unknown, path: string): void {
|
|
299
|
+
if (typeof value !== "boolean") {
|
|
300
|
+
fail(path, "expected boolean");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function integer(value: unknown, path: string): asserts value is number {
|
|
304
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
305
|
+
fail(path, "expected safe integer");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function natural(value: unknown, path: string): asserts value is number {
|
|
309
|
+
integer(value, path);
|
|
310
|
+
if (value < 0) {
|
|
311
|
+
fail(path, "expected nonnegative integer");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function positive(value: unknown, path: string): void {
|
|
315
|
+
natural(value, path);
|
|
316
|
+
if (value === 0) {
|
|
317
|
+
fail(path, "expected positive integer");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function member(value: unknown, members: ReadonlyArray<string>, path: string): void {
|
|
321
|
+
if (typeof value !== "string" || !members.includes(value)) {
|
|
322
|
+
fail(path, `expected one of ${members.join(", ")}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function fail(path: string, message: string): never {
|
|
326
|
+
throw new NotificationProtocolValidationError(path, message);
|
|
327
|
+
}
|
|
233
328
|
|
|
234
329
|
/**
|
|
235
330
|
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
@@ -238,9 +333,18 @@ function fail(path: string, message: string): never { throw new NotificationProt
|
|
|
238
333
|
* A missing entry means the generator failed to read the union: every caller
|
|
239
334
|
* checks the discriminant above this call.
|
|
240
335
|
*/
|
|
241
|
-
function variantKeys(
|
|
336
|
+
function variantKeys(
|
|
337
|
+
type: string,
|
|
338
|
+
object: Record<string, unknown>,
|
|
339
|
+
path: string,
|
|
340
|
+
): ReadonlyArray<string> {
|
|
242
341
|
const discriminant = object[NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
243
|
-
const keys =
|
|
244
|
-
|
|
342
|
+
const keys =
|
|
343
|
+
typeof discriminant === "string"
|
|
344
|
+
? NOTIFICATION_VARIANT_FIELDS[type]?.[discriminant]
|
|
345
|
+
: undefined;
|
|
346
|
+
if (keys === undefined) {
|
|
347
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
348
|
+
}
|
|
245
349
|
return keys;
|
|
246
350
|
}
|
package/src/operation/bridge.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BridgeJobTracker,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
bridgeCodec,
|
|
4
|
+
parseBridgeCommandEnvelope,
|
|
5
|
+
parseBridgeCommandReply,
|
|
6
|
+
parseBridgeQueryEnvelope,
|
|
7
|
+
parseBridgeQueryReply,
|
|
8
|
+
} from "@inflatable-cookie/longhorn/bridge";
|
|
9
|
+
import type {
|
|
10
|
+
BridgeCommandEnvelope,
|
|
11
|
+
BridgeCommandReply,
|
|
12
|
+
BridgeDomainClient,
|
|
13
|
+
BridgeJobId,
|
|
14
|
+
BridgeJobTerminalEvent,
|
|
15
|
+
BridgeOperationDescriptor,
|
|
16
|
+
BridgeProgressEvent,
|
|
17
|
+
BridgeQueryEnvelope,
|
|
18
|
+
BridgeQueryReply,
|
|
19
|
+
BridgeRequestContext,
|
|
20
|
+
BridgeRequestId,
|
|
21
|
+
DomainId,
|
|
15
22
|
} from "@inflatable-cookie/longhorn/bridge";
|
|
16
23
|
|
|
17
24
|
import {
|
|
@@ -63,15 +70,21 @@ async function executeQuery(options: BridgeOperationPortOptions, query: Operatio
|
|
|
63
70
|
return reply.outcome.success;
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
async function executeCommand(
|
|
73
|
+
async function executeCommand(
|
|
74
|
+
options: BridgeOperationPortOptions,
|
|
75
|
+
command: OperationMutationCommand,
|
|
76
|
+
) {
|
|
67
77
|
const context = nextContext(options);
|
|
68
78
|
const descriptor = commandDescriptor(options.domainId);
|
|
69
79
|
const reply = await options.client.execute(descriptor, {
|
|
70
80
|
context,
|
|
71
81
|
authorityEpoch: options.authorityEpoch,
|
|
72
|
-
expectedRevision:
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
expectedRevision:
|
|
83
|
+
command.kind === "register" ||
|
|
84
|
+
command.kind === "changeRetention" ||
|
|
85
|
+
command.kind === "teardown"
|
|
86
|
+
? command.expectedCatalogueRevision
|
|
87
|
+
: null,
|
|
75
88
|
idempotencyKey: context.requestId,
|
|
76
89
|
payload: command,
|
|
77
90
|
});
|
|
@@ -81,7 +94,10 @@ async function executeCommand(options: BridgeOperationPortOptions, command: Oper
|
|
|
81
94
|
return reply.outcome.applied;
|
|
82
95
|
}
|
|
83
96
|
|
|
84
|
-
async function executeCancellation(
|
|
97
|
+
async function executeCancellation(
|
|
98
|
+
options: BridgeOperationPortOptions,
|
|
99
|
+
command: OperationCancellationCommand,
|
|
100
|
+
) {
|
|
85
101
|
const context = nextContext(options);
|
|
86
102
|
const descriptor = cancellationDescriptor(options.domainId);
|
|
87
103
|
const reply = await options.client.execute(descriptor, { context, payload: command });
|
|
@@ -92,49 +108,84 @@ async function executeCancellation(options: BridgeOperationPortOptions, command:
|
|
|
92
108
|
}
|
|
93
109
|
|
|
94
110
|
function nextContext(options: BridgeOperationPortOptions): BridgeRequestContext {
|
|
95
|
-
return {
|
|
111
|
+
return {
|
|
112
|
+
requestId: options.nextBridgeRequestId(),
|
|
113
|
+
sessionId: options.sessionId,
|
|
114
|
+
domainId: options.domainId,
|
|
115
|
+
};
|
|
96
116
|
}
|
|
97
117
|
|
|
98
|
-
function codec<Value>(assertValue: (value: unknown) =>
|
|
99
|
-
return
|
|
118
|
+
function codec<Value>(assertValue: (value: unknown) => asserts value is Value) {
|
|
119
|
+
return bridgeCodec((value) => {
|
|
120
|
+
assertValue(value);
|
|
121
|
+
return value;
|
|
122
|
+
});
|
|
100
123
|
}
|
|
101
124
|
|
|
102
|
-
|
|
125
|
+
const noDetails = bridgeCodec((value): null => {
|
|
126
|
+
if (value !== null) {
|
|
127
|
+
throw new Error("operation bridge failure details must be null");
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
function queryDescriptor(
|
|
133
|
+
domainId: DomainId,
|
|
134
|
+
): BridgeOperationDescriptor<
|
|
135
|
+
BridgeQueryEnvelope<OperationSnapshotQuery>,
|
|
136
|
+
BridgeQueryReply<OperationSnapshotResponse, null>
|
|
137
|
+
> {
|
|
103
138
|
return {
|
|
104
|
-
route: "longhorn.operation.snapshot",
|
|
139
|
+
route: "longhorn.operation.snapshot",
|
|
140
|
+
domainId,
|
|
141
|
+
kind: "query",
|
|
105
142
|
requiredCapability: "longhorn.operation.read",
|
|
106
|
-
request:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if ("success" in outcome) assertValidOperationSnapshotResponse(outcome.success);
|
|
113
|
-
}),
|
|
143
|
+
request: bridgeCodec((value) =>
|
|
144
|
+
parseBridgeQueryEnvelope(value, codec(assertValidOperationSnapshotQuery)),
|
|
145
|
+
),
|
|
146
|
+
reply: bridgeCodec((value) =>
|
|
147
|
+
parseBridgeQueryReply(value, codec(assertValidOperationSnapshotResponse), noDetails),
|
|
148
|
+
),
|
|
114
149
|
};
|
|
115
150
|
}
|
|
116
151
|
|
|
117
|
-
function commandDescriptor(
|
|
152
|
+
function commandDescriptor(
|
|
153
|
+
domainId: DomainId,
|
|
154
|
+
): BridgeOperationDescriptor<
|
|
155
|
+
BridgeCommandEnvelope<OperationMutationCommand>,
|
|
156
|
+
BridgeCommandReply<OperationMutationResult, null>
|
|
157
|
+
> {
|
|
118
158
|
return {
|
|
119
|
-
route: "longhorn.operation.mutate",
|
|
159
|
+
route: "longhorn.operation.mutate",
|
|
160
|
+
domainId,
|
|
161
|
+
kind: "command",
|
|
120
162
|
requiredCapability: "longhorn.operation.manage",
|
|
121
|
-
request:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
163
|
+
request: bridgeCodec((value) =>
|
|
164
|
+
parseBridgeCommandEnvelope(value, codec(assertValidOperationMutationCommand)),
|
|
165
|
+
),
|
|
166
|
+
reply: bridgeCodec((value) =>
|
|
167
|
+
parseBridgeCommandReply(value, codec(assertValidOperationMutationResult), noDetails),
|
|
168
|
+
),
|
|
126
169
|
};
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
function cancellationDescriptor(
|
|
172
|
+
function cancellationDescriptor(
|
|
173
|
+
domainId: DomainId,
|
|
174
|
+
): BridgeOperationDescriptor<
|
|
175
|
+
BridgeQueryEnvelope<OperationCancellationCommand>,
|
|
176
|
+
BridgeQueryReply<OperationCancellationResult, null>
|
|
177
|
+
> {
|
|
130
178
|
return {
|
|
131
|
-
route: "longhorn.operation.cancel",
|
|
179
|
+
route: "longhorn.operation.cancel",
|
|
180
|
+
domainId,
|
|
181
|
+
kind: "cancellation",
|
|
132
182
|
requiredCapability: "longhorn.operation.cancel",
|
|
133
|
-
request:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
183
|
+
request: bridgeCodec((value) =>
|
|
184
|
+
parseBridgeQueryEnvelope(value, codec(assertValidOperationCancellationCommand)),
|
|
185
|
+
),
|
|
186
|
+
reply: bridgeCodec((value) =>
|
|
187
|
+
parseBridgeQueryReply(value, codec(assertValidOperationCancellationResult), noDetails),
|
|
188
|
+
),
|
|
138
189
|
};
|
|
139
190
|
}
|
|
140
191
|
|
|
@@ -153,16 +204,32 @@ export class BridgeOperationJobCorrelation {
|
|
|
153
204
|
this.#operationId = correlation.operationId;
|
|
154
205
|
}
|
|
155
206
|
|
|
156
|
-
acceptProgress(
|
|
157
|
-
|
|
207
|
+
acceptProgress(
|
|
208
|
+
event: BridgeProgressEvent<OperationChangedEvent>,
|
|
209
|
+
): OperationChangedEvent | undefined {
|
|
210
|
+
if (this.#tracker.classifyProgress(event) !== "accept") {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
158
213
|
assertValidOperationChangedEvent(event.progress);
|
|
159
214
|
return event.progress.operationId === this.#operationId ? event.progress : undefined;
|
|
160
215
|
}
|
|
161
216
|
|
|
162
|
-
acceptTerminal(
|
|
163
|
-
|
|
164
|
-
|
|
217
|
+
acceptTerminal(
|
|
218
|
+
event: BridgeJobTerminalEvent<OperationChangedEvent, null>,
|
|
219
|
+
): OperationChangedEvent | undefined {
|
|
220
|
+
if (this.#tracker.classifyTerminal(event) !== "accept") {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
if (
|
|
224
|
+
typeof event.outcome !== "object" ||
|
|
225
|
+
event.outcome === null ||
|
|
226
|
+
!("succeeded" in event.outcome)
|
|
227
|
+
) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
165
230
|
assertValidOperationChangedEvent(event.outcome.succeeded);
|
|
166
|
-
return event.outcome.succeeded.operationId === this.#operationId
|
|
231
|
+
return event.outcome.succeeded.operationId === this.#operationId
|
|
232
|
+
? event.outcome.succeeded
|
|
233
|
+
: undefined;
|
|
167
234
|
}
|
|
168
235
|
}
|
package/src/operation/client.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { CheckedSnapshotConnection } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type {
|
|
3
|
+
ConnectionFailure,
|
|
4
|
+
ConnectionFailureReporter,
|
|
5
5
|
} from "@inflatable-cookie/longhorn/core";
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -12,22 +12,21 @@ import {
|
|
|
12
12
|
assertValidOperationMutationResult,
|
|
13
13
|
assertValidOperationSnapshotResponse,
|
|
14
14
|
} from "./validation.ts";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type OperationSnapshotResponse,
|
|
15
|
+
import { OPERATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
16
|
+
import type {
|
|
17
|
+
OperationCancellationCommand,
|
|
18
|
+
OperationCancellationResult,
|
|
19
|
+
OperationMutationCommand,
|
|
20
|
+
OperationMutationResult,
|
|
21
|
+
OperationSnapshot,
|
|
22
|
+
OperationSnapshotResponse,
|
|
24
23
|
} from "./generated/protocol.ts";
|
|
25
24
|
import type { OperationPort } from "./ports.ts";
|
|
26
25
|
|
|
27
26
|
export interface OperationSubscription {
|
|
28
27
|
readonly ready: Promise<void>;
|
|
29
28
|
current(): OperationSnapshot | undefined;
|
|
30
|
-
failures():
|
|
29
|
+
failures(): ReadonlyArray<ConnectionFailure>;
|
|
31
30
|
dispose(): Promise<void>;
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -78,14 +77,21 @@ export class OperationClient {
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export class OperationResponseCorrelationError extends Error {
|
|
81
|
-
constructor(
|
|
82
|
-
|
|
80
|
+
constructor(
|
|
81
|
+
readonly expectedRequestId: string,
|
|
82
|
+
readonly receivedRequestId: string,
|
|
83
|
+
) {
|
|
84
|
+
super(
|
|
85
|
+
`operation response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`,
|
|
86
|
+
);
|
|
83
87
|
this.name = "OperationResponseCorrelationError";
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
function assertResponseCorrelation(received: string, expected: string): void {
|
|
88
|
-
if (received !== expected)
|
|
92
|
+
if (received !== expected) {
|
|
93
|
+
throw new OperationResponseCorrelationError(expected, received);
|
|
94
|
+
}
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
class CheckedOperationSubscription implements OperationSubscription {
|
|
@@ -100,7 +106,9 @@ class CheckedOperationSubscription implements OperationSubscription {
|
|
|
100
106
|
) {
|
|
101
107
|
this.#connection = new CheckedSnapshotConnection({
|
|
102
108
|
listen: async (receive) => {
|
|
103
|
-
if (port.listen === undefined)
|
|
109
|
+
if (port.listen === undefined) {
|
|
110
|
+
return () => {};
|
|
111
|
+
}
|
|
104
112
|
return port.listen(receive);
|
|
105
113
|
},
|
|
106
114
|
loadSnapshot: async () => (await client.snapshot()).snapshot,
|
|
@@ -117,7 +125,7 @@ class CheckedOperationSubscription implements OperationSubscription {
|
|
|
117
125
|
return this.#connection.current();
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
failures():
|
|
128
|
+
failures(): ReadonlyArray<ConnectionFailure> {
|
|
121
129
|
return this.#connection.failures();
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -129,7 +137,7 @@ class CheckedOperationSubscription implements OperationSubscription {
|
|
|
129
137
|
function parseSnapshot(value: unknown): OperationSnapshot {
|
|
130
138
|
const response = { requestId: "request:validation", snapshot: value };
|
|
131
139
|
assertValidOperationSnapshotResponse(response);
|
|
132
|
-
return
|
|
140
|
+
return response.snapshot;
|
|
133
141
|
}
|
|
134
142
|
|
|
135
143
|
export function operationEventAction(
|
|
@@ -137,8 +145,10 @@ export function operationEventAction(
|
|
|
137
145
|
current: OperationSnapshot | undefined,
|
|
138
146
|
): { kind: "ignore" } | { kind: "refresh" } {
|
|
139
147
|
assertValidOperationChangedEvent(value);
|
|
140
|
-
const event = value
|
|
141
|
-
if (current === undefined)
|
|
148
|
+
const event = value;
|
|
149
|
+
if (current === undefined) {
|
|
150
|
+
return { kind: "refresh" };
|
|
151
|
+
}
|
|
142
152
|
if (event.authority.authorityId !== current.authority.authorityId) {
|
|
143
153
|
return { kind: "ignore" };
|
|
144
154
|
}
|
|
@@ -158,8 +168,12 @@ export function isNewerOperationSnapshot(
|
|
|
158
168
|
candidate: OperationSnapshot,
|
|
159
169
|
current: OperationSnapshot | undefined,
|
|
160
170
|
): boolean {
|
|
161
|
-
if (current === undefined)
|
|
162
|
-
|
|
171
|
+
if (current === undefined) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
if (candidate.authority.authorityId !== current.authority.authorityId) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
163
177
|
if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) {
|
|
164
178
|
return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
|
|
165
179
|
}
|