@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
|
// Rust serde types are the wire authority. Executable actions are intentionally absent.
|
|
3
3
|
|
|
4
4
|
export const NOTIFICATION_PROTOCOL_VERSION = 1 as const;
|
|
@@ -520,3 +520,7 @@ affectedNotificationIds: Array<NotificationId>,
|
|
|
520
520
|
* Change source.
|
|
521
521
|
*/
|
|
522
522
|
kind: NotificationChangedKind, };
|
|
523
|
+
|
|
524
|
+
export type NotificationHostErrorCode = "authorityUnavailable" | "authorityStateUnavailable" | "eventPublication";
|
|
525
|
+
|
|
526
|
+
export type NotificationHostError = { "code": NotificationHostErrorCode, "message": string, "retryable": boolean, };
|
|
@@ -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.
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
2
|
import type {
|
|
2
3
|
NotificationChangedEvent,
|
|
3
4
|
NotificationMutationCommand,
|
|
4
5
|
NotificationRequestId,
|
|
5
6
|
NotificationSnapshotQuery,
|
|
7
|
+
NotificationSnapshotResponse,
|
|
8
|
+
NotificationMutationResult,
|
|
6
9
|
} from "./generated/protocol.ts";
|
|
7
10
|
|
|
8
|
-
export type NotificationUnlisten =
|
|
11
|
+
export type NotificationUnlisten = Unlisten;
|
|
9
12
|
|
|
10
13
|
export interface NotificationPort {
|
|
11
14
|
snapshot(query: NotificationSnapshotQuery): Promise<unknown>;
|
|
12
15
|
mutate(command: NotificationMutationCommand): Promise<unknown>;
|
|
13
|
-
listen
|
|
16
|
+
listen?:
|
|
17
|
+
| ((listener: (event: unknown) => void) => NotificationUnlisten | Promise<NotificationUnlisten>)
|
|
18
|
+
| undefined;
|
|
14
19
|
nextRequestId(): NotificationRequestId;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface CheckedNotificationPort {
|
|
18
|
-
snapshot(query: NotificationSnapshotQuery): Promise<
|
|
19
|
-
mutate(command: NotificationMutationCommand): Promise<
|
|
23
|
+
snapshot(query: NotificationSnapshotQuery): Promise<NotificationSnapshotResponse>;
|
|
24
|
+
mutate(command: NotificationMutationCommand): Promise<NotificationMutationResult>;
|
|
20
25
|
listen?(listener: (event: NotificationChangedEvent) => void): Promise<NotificationUnlisten>;
|
|
21
26
|
nextRequestId(): NotificationRequestId;
|
|
22
27
|
}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
2
|
+
import type {
|
|
3
|
+
NotificationMutationCommand,
|
|
4
|
+
NotificationSnapshotQuery,
|
|
5
|
+
} from "./generated/protocol.ts";
|
|
2
6
|
import type { NotificationPort, NotificationUnlisten } from "./ports.ts";
|
|
3
7
|
|
|
4
8
|
export class SerializedNotificationPort implements NotificationPort {
|
|
5
9
|
constructor(readonly inner: NotificationPort) {}
|
|
6
10
|
|
|
7
11
|
async snapshot(query: NotificationSnapshotQuery): Promise<unknown> {
|
|
8
|
-
return
|
|
12
|
+
return wireCopy(await this.inner.snapshot(wireCopy(query)));
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
async mutate(command: NotificationMutationCommand): Promise<unknown> {
|
|
12
|
-
return
|
|
16
|
+
return wireCopy(await this.inner.mutate(wireCopy(command)));
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
async listen(listener: (event: unknown) => void): Promise<NotificationUnlisten> {
|
|
16
|
-
if (this.inner.listen === undefined)
|
|
17
|
-
|
|
20
|
+
if (this.inner.listen === undefined) {
|
|
21
|
+
return () => {};
|
|
22
|
+
}
|
|
23
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
nextRequestId(): string {
|
|
21
27
|
return this.inner.nextRequestId();
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
function clone<Value>(value: Value): Value {
|
|
26
|
-
return JSON.parse(JSON.stringify(value)) as Value;
|
|
27
|
-
}
|
|
@@ -14,7 +14,7 @@ export type NotificationStatusTone = "info" | "success" | "warning" | "danger";
|
|
|
14
14
|
* Lives here rather than in a projection tier because two places needed it —
|
|
15
15
|
* `NotificationController.projectToast` and the Poodle projector — and a rule
|
|
16
16
|
* stated twice is a rule that can drift. The cross-backend parity fixture
|
|
17
|
-
* checks this one function
|
|
17
|
+
* checks this one function.
|
|
18
18
|
*
|
|
19
19
|
* The `error`/`critical` collapse is lossy and the tone cannot say so; a
|
|
20
20
|
* surface that needs the distinction restores it in text, as the Rust toast
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
1
3
|
import {
|
|
2
4
|
NOTIFICATION_VARIANT_FIELDS,
|
|
3
5
|
NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -7,42 +9,56 @@ import {
|
|
|
7
9
|
NOTIFICATION_CHANGED_KINDS,
|
|
8
10
|
NOTIFICATION_MUTATION_KINDS,
|
|
9
11
|
NOTIFICATION_MUTATION_STATUSES,
|
|
12
|
+
NOTIFICATION_CLEAR_TARGET_KINDS,
|
|
13
|
+
NOTIFICATION_RECEIPT_KINDS,
|
|
14
|
+
NOTIFICATION_REMOVAL_REASONS,
|
|
10
15
|
NOTIFICATION_PROTOCOL_VERSION,
|
|
11
16
|
NOTIFICATION_READ_STATES,
|
|
12
17
|
NOTIFICATION_REJECTION_CODES,
|
|
13
18
|
NOTIFICATION_RETENTION_CLASSES,
|
|
14
19
|
NOTIFICATION_SEVERITIES,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
} from "./generated/protocol.ts";
|
|
21
|
+
import type {
|
|
22
|
+
NotificationChangedEvent,
|
|
23
|
+
NotificationMutationCommand,
|
|
24
|
+
NotificationMutationResult,
|
|
25
|
+
NotificationRecordProjection,
|
|
26
|
+
NotificationSnapshot,
|
|
27
|
+
NotificationSnapshotQuery,
|
|
28
|
+
NotificationSnapshotResponse,
|
|
22
29
|
} from "./generated/protocol.ts";
|
|
23
30
|
|
|
24
31
|
export class NotificationProtocolValidationError extends Error {
|
|
25
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
readonly path: string,
|
|
34
|
+
message: string,
|
|
35
|
+
) {
|
|
26
36
|
super(`incompatible notification protocol at ${path}: ${message}`);
|
|
27
37
|
this.name = "NotificationProtocolValidationError";
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
export function assertValidNotificationSnapshotQuery(
|
|
41
|
+
export function assertValidNotificationSnapshotQuery(
|
|
42
|
+
value: unknown,
|
|
43
|
+
): asserts value is NotificationSnapshotQuery {
|
|
32
44
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotQuery);
|
|
33
45
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
34
|
-
|
|
46
|
+
opaqueId(object.requestId, "$.requestId");
|
|
35
47
|
natural(object.offset, "$.offset");
|
|
36
48
|
natural(object.limit, "$.limit");
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
export function assertValidNotificationSnapshotResponse(
|
|
51
|
+
export function assertValidNotificationSnapshotResponse(
|
|
52
|
+
value: unknown,
|
|
53
|
+
): asserts value is NotificationSnapshotResponse {
|
|
40
54
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshotResponse);
|
|
41
|
-
|
|
55
|
+
opaqueId(object.requestId, "$.requestId");
|
|
42
56
|
assertValidNotificationSnapshot(object.snapshot);
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
export function assertValidNotificationSnapshot(
|
|
59
|
+
export function assertValidNotificationSnapshot(
|
|
60
|
+
value: unknown,
|
|
61
|
+
): asserts value is NotificationSnapshot {
|
|
46
62
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationSnapshot);
|
|
47
63
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
48
64
|
authority(object.authority, "$.authority");
|
|
@@ -56,20 +72,24 @@ export function assertValidNotificationSnapshot(value: unknown): asserts value i
|
|
|
56
72
|
natural(page.offset, "$.page.offset");
|
|
57
73
|
natural(page.totalCount, "$.page.totalCount");
|
|
58
74
|
boolean(page.hasMore, "$.page.hasMore");
|
|
59
|
-
array(page.records, "$.page.records").forEach((item, index) =>
|
|
75
|
+
array(page.records, "$.page.records").forEach((item, index) =>
|
|
76
|
+
recordProjection(item, `$.page.records[${index}]`),
|
|
77
|
+
);
|
|
60
78
|
}
|
|
61
79
|
|
|
62
|
-
export function assertValidNotificationMutationCommand(
|
|
80
|
+
export function assertValidNotificationMutationCommand(
|
|
81
|
+
value: unknown,
|
|
82
|
+
): asserts value is NotificationMutationCommand {
|
|
63
83
|
const object = record(value, "$");
|
|
64
84
|
member(object.kind, NOTIFICATION_MUTATION_KINDS, "$.kind");
|
|
65
85
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
66
|
-
|
|
86
|
+
opaqueId(object.requestId, "$.requestId");
|
|
67
87
|
authority(object.authority, "$.authority");
|
|
68
88
|
natural(object.expectedLedgerRevision, "$.expectedLedgerRevision");
|
|
69
89
|
switch (object.kind) {
|
|
70
90
|
case "add":
|
|
71
91
|
exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
|
|
72
|
-
|
|
92
|
+
opaqueId(object.notificationId, "$.notificationId");
|
|
73
93
|
draft(object.draft, "$.draft");
|
|
74
94
|
break;
|
|
75
95
|
case "replace":
|
|
@@ -80,14 +100,22 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
|
|
|
80
100
|
case "markSeen":
|
|
81
101
|
case "dismiss":
|
|
82
102
|
exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
|
|
83
|
-
|
|
103
|
+
opaqueId(object.notificationId, "$.notificationId");
|
|
84
104
|
break;
|
|
85
105
|
case "clear": {
|
|
86
106
|
exactKeys(object, "$", variantKeys("NotificationMutationCommand", object, "$"));
|
|
87
107
|
const target = record(object.target, "$.target");
|
|
88
|
-
member(target.kind,
|
|
89
|
-
exactKeys(
|
|
90
|
-
|
|
108
|
+
member(target.kind, NOTIFICATION_CLEAR_TARGET_KINDS, "$.target.kind");
|
|
109
|
+
exactKeys(
|
|
110
|
+
target,
|
|
111
|
+
"$.target",
|
|
112
|
+
variantKeys("NotificationClearTargetProjection", target, "$.target"),
|
|
113
|
+
);
|
|
114
|
+
if (target.kind === "records") {
|
|
115
|
+
array(target.notificationIds, "$.target.notificationIds").forEach((id, index) =>
|
|
116
|
+
opaqueId(id, `$.target.notificationIds[${index}]`),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
91
119
|
break;
|
|
92
120
|
}
|
|
93
121
|
case "changeRetention":
|
|
@@ -97,37 +125,47 @@ export function assertValidNotificationMutationCommand(value: unknown): asserts
|
|
|
97
125
|
}
|
|
98
126
|
}
|
|
99
127
|
|
|
100
|
-
export function assertValidNotificationMutationResult(
|
|
128
|
+
export function assertValidNotificationMutationResult(
|
|
129
|
+
value: unknown,
|
|
130
|
+
): asserts value is NotificationMutationResult {
|
|
101
131
|
const object = record(value, "$");
|
|
102
132
|
member(object.status, NOTIFICATION_MUTATION_STATUSES, "$.status");
|
|
103
|
-
|
|
133
|
+
opaqueId(object.requestId, "$.requestId");
|
|
104
134
|
assertValidNotificationSnapshot(object.snapshot);
|
|
105
135
|
if (object.status === "committed") {
|
|
106
136
|
exactKeys(object, "$", variantKeys("NotificationMutationResult", object, "$"));
|
|
107
137
|
receipt(object.receipt, "$.receipt");
|
|
108
138
|
} else {
|
|
109
139
|
exactKeys(object, "$", variantKeys("NotificationMutationResult", object, "$"));
|
|
110
|
-
const rejection = exact(
|
|
140
|
+
const rejection = exact(
|
|
141
|
+
object.rejection,
|
|
142
|
+
"$.rejection",
|
|
143
|
+
NOTIFICATIONS_FIELDS.NotificationRejection,
|
|
144
|
+
);
|
|
111
145
|
member(rejection.code, NOTIFICATION_REJECTION_CODES, "$.rejection.code");
|
|
112
146
|
text(rejection.detail, "$.rejection.detail");
|
|
113
147
|
boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
|
|
114
148
|
}
|
|
115
149
|
}
|
|
116
150
|
|
|
117
|
-
export function assertValidNotificationChangedEvent(
|
|
151
|
+
export function assertValidNotificationChangedEvent(
|
|
152
|
+
value: unknown,
|
|
153
|
+
): asserts value is NotificationChangedEvent {
|
|
118
154
|
const object = exact(value, "$", NOTIFICATIONS_FIELDS.NotificationChangedEvent);
|
|
119
155
|
protocol(object.protocolVersion, "$.protocolVersion");
|
|
120
|
-
|
|
156
|
+
opaqueId(object.requestId, "$.requestId");
|
|
121
157
|
authority(object.authority, "$.authority");
|
|
122
158
|
natural(object.previousLedgerRevision, "$.previousLedgerRevision");
|
|
123
159
|
natural(object.committedLedgerRevision, "$.committedLedgerRevision");
|
|
124
|
-
array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) =>
|
|
160
|
+
array(object.affectedNotificationIds, "$.affectedNotificationIds").forEach((id, index) =>
|
|
161
|
+
opaqueId(id, `$.affectedNotificationIds[${index}]`),
|
|
162
|
+
);
|
|
125
163
|
member(object.kind, NOTIFICATION_CHANGED_KINDS, "$.kind");
|
|
126
164
|
}
|
|
127
165
|
|
|
128
166
|
function authority(value: unknown, path: string): void {
|
|
129
167
|
const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationAuthorityProjection);
|
|
130
|
-
|
|
168
|
+
opaqueId(object.authorityId, `${path}.authorityId`);
|
|
131
169
|
positive(object.authorityEpoch, `${path}.authorityEpoch`);
|
|
132
170
|
}
|
|
133
171
|
|
|
@@ -139,25 +177,34 @@ function limits(value: unknown, path: string): void {
|
|
|
139
177
|
|
|
140
178
|
function draft(value: unknown, path: string): void {
|
|
141
179
|
const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationDraftProjection);
|
|
142
|
-
|
|
180
|
+
opaqueId(object.sourceId, `${path}.sourceId`);
|
|
143
181
|
member(object.severity, NOTIFICATION_SEVERITIES, `${path}.severity`);
|
|
144
182
|
text(object.title, `${path}.title`);
|
|
145
183
|
text(object.summary, `${path}.summary`);
|
|
146
|
-
|
|
184
|
+
nullableOpaqueId(object.causeId, `${path}.causeId`);
|
|
147
185
|
array(object.actions, `${path}.actions`).forEach((action, index) => {
|
|
148
|
-
const item = exact(
|
|
149
|
-
|
|
186
|
+
const item = exact(
|
|
187
|
+
action,
|
|
188
|
+
`${path}.actions[${index}]`,
|
|
189
|
+
NOTIFICATIONS_FIELDS.NotificationActionProjection,
|
|
190
|
+
);
|
|
191
|
+
opaqueId(item.referenceId, `${path}.actions[${index}].referenceId`);
|
|
150
192
|
text(item.label, `${path}.actions[${index}].label`);
|
|
151
193
|
});
|
|
152
|
-
|
|
153
|
-
|
|
194
|
+
nullableOpaqueId(object.replacementKey, `${path}.replacementKey`);
|
|
195
|
+
nullableOpaqueId(object.producerToken, `${path}.producerToken`);
|
|
154
196
|
member(object.retentionClass, NOTIFICATION_RETENTION_CLASSES, `${path}.retentionClass`);
|
|
155
|
-
if (object.presentationTimeUnixMs !== null)
|
|
197
|
+
if (object.presentationTimeUnixMs !== null) {
|
|
198
|
+
integer(object.presentationTimeUnixMs, `${path}.presentationTimeUnixMs`);
|
|
199
|
+
}
|
|
156
200
|
}
|
|
157
201
|
|
|
158
|
-
function recordProjection(
|
|
202
|
+
function recordProjection(
|
|
203
|
+
value: unknown,
|
|
204
|
+
path: string,
|
|
205
|
+
): asserts value is NotificationRecordProjection {
|
|
159
206
|
const object = exact(value, path, NOTIFICATIONS_FIELDS.NotificationRecordProjection);
|
|
160
|
-
|
|
207
|
+
opaqueId(object.notificationId, `${path}.notificationId`);
|
|
161
208
|
draft(object.draft, `${path}.draft`);
|
|
162
209
|
positive(object.sequence, `${path}.sequence`);
|
|
163
210
|
positive(object.lastChangedLedgerRevision, `${path}.lastChangedLedgerRevision`);
|
|
@@ -167,7 +214,7 @@ function recordProjection(value: unknown, path: string): asserts value is Notifi
|
|
|
167
214
|
|
|
168
215
|
function receipt(value: unknown, path: string): void {
|
|
169
216
|
const object = record(value, path);
|
|
170
|
-
member(object.kind,
|
|
217
|
+
member(object.kind, NOTIFICATION_RECEIPT_KINDS, `${path}.kind`);
|
|
171
218
|
natural(object.previousLedgerRevision, `${path}.previousLedgerRevision`);
|
|
172
219
|
natural(object.committedLedgerRevision, `${path}.committedLedgerRevision`);
|
|
173
220
|
if (object.kind === "added" || object.kind === "replaced") {
|
|
@@ -190,57 +237,104 @@ 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
|
-
member(item.reason,
|
|
246
|
+
member(item.reason, NOTIFICATION_REMOVAL_REASONS, `${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
|
-
|
|
205
|
-
return
|
|
257
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
258
|
+
return result;
|
|
206
259
|
}
|
|
207
260
|
|
|
208
|
-
function exact(value: unknown, path: string, keys:
|
|
261
|
+
function exact(value: unknown, path: string, keys: ReadonlyArray<string>): Record<string, unknown> {
|
|
209
262
|
const object = record(value, path);
|
|
210
263
|
exactKeys(object, path, keys);
|
|
211
264
|
return object;
|
|
212
265
|
}
|
|
213
266
|
|
|
214
|
-
function exactKeys(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
267
|
+
function exactKeys(
|
|
268
|
+
object: Record<string, unknown>,
|
|
269
|
+
path: string,
|
|
270
|
+
keys: ReadonlyArray<string>,
|
|
271
|
+
): void {
|
|
272
|
+
checkWireFields(object, keys, () => fail(path, `expected keys ${[...keys].sort().join(", ")}`));
|
|
218
273
|
}
|
|
219
274
|
|
|
220
|
-
function array(value: unknown, path: string): unknown
|
|
221
|
-
if (!Array.isArray(value))
|
|
275
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
276
|
+
if (!Array.isArray(value)) {
|
|
277
|
+
fail(path, "expected array");
|
|
278
|
+
}
|
|
222
279
|
return value;
|
|
223
280
|
}
|
|
224
281
|
|
|
225
|
-
function text(value: unknown, path: string): void {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
282
|
+
function text(value: unknown, path: string): void {
|
|
283
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
284
|
+
fail(path, "expected nonempty string");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function opaqueId(value: unknown, path: string): void {
|
|
288
|
+
if (!isOpaqueId(value)) {
|
|
289
|
+
fail(path, "expected bounded lowercase opaque id");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function nullableOpaqueId(value: unknown, path: string): void {
|
|
293
|
+
if (value !== null) {
|
|
294
|
+
opaqueId(value, path);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function boolean(value: unknown, path: string): void {
|
|
298
|
+
if (typeof value !== "boolean") {
|
|
299
|
+
fail(path, "expected boolean");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function integer(value: unknown, path: string): asserts value is number {
|
|
303
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
304
|
+
fail(path, "expected safe integer");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function natural(value: unknown, path: string): asserts value is number {
|
|
308
|
+
integer(value, path);
|
|
309
|
+
if (value < 0) {
|
|
310
|
+
fail(path, "expected nonnegative integer");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function positive(value: unknown, path: string): void {
|
|
314
|
+
natural(value, path);
|
|
315
|
+
if (value === 0) {
|
|
316
|
+
fail(path, "expected positive integer");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function member(value: unknown, members: ReadonlyArray<string>, path: string): void {
|
|
320
|
+
if (typeof value !== "string" || !members.includes(value)) {
|
|
321
|
+
fail(path, `expected one of ${members.join(", ")}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function fail(path: string, message: string): never {
|
|
325
|
+
throw new NotificationProtocolValidationError(path, message);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function variantKeys(
|
|
329
|
+
type: string,
|
|
330
|
+
object: Record<string, unknown>,
|
|
331
|
+
path: string,
|
|
332
|
+
): ReadonlyArray<string> {
|
|
333
|
+
return wireVariantFields(
|
|
334
|
+
NOTIFICATION_VARIANT_FIELDS,
|
|
335
|
+
NOTIFICATION_VARIANT_FIELDS_DISCRIMINANTS,
|
|
336
|
+
type,
|
|
337
|
+
object,
|
|
338
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
339
|
+
);
|
|
246
340
|
}
|