@inflatable-cookie/longhorn 0.4.3 → 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,20 +1,26 @@
|
|
|
1
|
-
import { isNewerNotificationSnapshot, NotificationClient
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { isNewerNotificationSnapshot, NotificationClient } from "./client.ts";
|
|
2
|
+
import type { NotificationSubscription } from "./client.ts";
|
|
3
|
+
import { NOTIFICATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
4
|
+
import type {
|
|
5
|
+
NotificationActionProjection,
|
|
6
|
+
NotificationId,
|
|
7
|
+
NotificationMutationResult,
|
|
8
|
+
NotificationRecordProjection,
|
|
9
|
+
NotificationRejection,
|
|
10
|
+
NotificationRequestId,
|
|
11
|
+
NotificationSnapshot,
|
|
11
12
|
} from "./generated/protocol.ts";
|
|
12
|
-
import { notificationSeverityTone
|
|
13
|
+
import { notificationSeverityTone } from "./tone.ts";
|
|
14
|
+
import type { NotificationStatusTone } from "./tone.ts";
|
|
13
15
|
import { toastAction, toastTitle } from "./toast.ts";
|
|
14
16
|
|
|
15
17
|
import type { NotificationPort } from "./ports.ts";
|
|
16
18
|
|
|
17
|
-
export type NotificationControllerStatus =
|
|
19
|
+
export type NotificationControllerStatus =
|
|
20
|
+
| { readonly kind: "idle" }
|
|
21
|
+
| { readonly kind: "loading" }
|
|
22
|
+
| { readonly kind: "ready" }
|
|
23
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
18
24
|
export type NotificationPendingKind = "markSeen" | "dismiss" | "action";
|
|
19
25
|
|
|
20
26
|
export interface NotificationPendingCommand {
|
|
@@ -23,8 +29,12 @@ export interface NotificationPendingCommand {
|
|
|
23
29
|
readonly kind: NotificationPendingKind;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
export interface NotificationCommandRejection extends NotificationPendingCommand {
|
|
27
|
-
|
|
32
|
+
export interface NotificationCommandRejection extends NotificationPendingCommand {
|
|
33
|
+
readonly rejection: NotificationRejection;
|
|
34
|
+
}
|
|
35
|
+
export interface NotificationCommandFailure extends NotificationPendingCommand {
|
|
36
|
+
readonly error: unknown;
|
|
37
|
+
}
|
|
28
38
|
|
|
29
39
|
export interface NotificationActionInvocation {
|
|
30
40
|
readonly notificationId: NotificationId;
|
|
@@ -42,7 +52,7 @@ export interface NotificationToastProjection {
|
|
|
42
52
|
readonly title: string;
|
|
43
53
|
readonly description: string;
|
|
44
54
|
readonly tone: NotificationStatusTone;
|
|
45
|
-
readonly action?: NotificationActionProjection;
|
|
55
|
+
readonly action?: NotificationActionProjection | undefined;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
export interface NotificationControllerOptions {
|
|
@@ -61,8 +71,8 @@ export class NotificationController {
|
|
|
61
71
|
readonly actionExecutor: NotificationActionExecutor | undefined;
|
|
62
72
|
status: NotificationControllerStatus = { kind: "idle" };
|
|
63
73
|
snapshot: NotificationSnapshot | undefined;
|
|
64
|
-
records: NotificationRecordProjection
|
|
65
|
-
toasts: NotificationToastProjection
|
|
74
|
+
records: Array<NotificationRecordProjection> = [];
|
|
75
|
+
toasts: Array<NotificationToastProjection> = [];
|
|
66
76
|
selectedNotificationId: NotificationId | undefined;
|
|
67
77
|
commandRejection: NotificationCommandRejection | undefined;
|
|
68
78
|
commandFailure: NotificationCommandFailure | undefined;
|
|
@@ -78,28 +88,51 @@ export class NotificationController {
|
|
|
78
88
|
this.actionExecutor = options.actions;
|
|
79
89
|
}
|
|
80
90
|
|
|
81
|
-
get selected(): NotificationRecordProjection | undefined {
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
get selected(): NotificationRecordProjection | undefined {
|
|
92
|
+
return this.records.find((record) => record.notificationId === this.selectedNotificationId);
|
|
93
|
+
}
|
|
94
|
+
get hasMore(): boolean {
|
|
95
|
+
return this.snapshot?.page.hasMore ?? false;
|
|
96
|
+
}
|
|
97
|
+
get pendingCommands(): ReadonlyArray<NotificationPendingCommand> {
|
|
98
|
+
return [...this.pending.values()];
|
|
99
|
+
}
|
|
84
100
|
|
|
85
|
-
observe(observer: () => void): () => void {
|
|
101
|
+
observe(observer: () => void): () => void {
|
|
102
|
+
this.observers.add(observer);
|
|
103
|
+
return () => this.observers.delete(observer);
|
|
104
|
+
}
|
|
86
105
|
|
|
87
106
|
async start(): Promise<void> {
|
|
88
|
-
if (this.started)
|
|
107
|
+
if (this.started) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
89
110
|
this.started = true;
|
|
90
111
|
const lifecycle = ++this.lifecycleRevision;
|
|
91
112
|
this.setStatus({ kind: "loading" });
|
|
92
113
|
const subscription = this.client.subscribe(
|
|
93
|
-
(snapshot) => {
|
|
94
|
-
|
|
114
|
+
(snapshot) => {
|
|
115
|
+
if (this.isCurrent(lifecycle)) {
|
|
116
|
+
this.install(snapshot);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
({ error }) => {
|
|
120
|
+
if (this.isCurrent(lifecycle)) {
|
|
121
|
+
this.setStatus({ kind: "failed", error });
|
|
122
|
+
}
|
|
123
|
+
},
|
|
95
124
|
this.pageSize,
|
|
96
125
|
);
|
|
97
126
|
this.subscription = subscription;
|
|
98
127
|
try {
|
|
99
128
|
await subscription.ready;
|
|
100
|
-
if (this.isCurrent(lifecycle))
|
|
129
|
+
if (this.isCurrent(lifecycle)) {
|
|
130
|
+
this.setStatus({ kind: "ready" });
|
|
131
|
+
}
|
|
101
132
|
} catch (error) {
|
|
102
|
-
if (this.isCurrent(lifecycle))
|
|
133
|
+
if (this.isCurrent(lifecycle)) {
|
|
134
|
+
this.setStatus({ kind: "failed", error });
|
|
135
|
+
}
|
|
103
136
|
}
|
|
104
137
|
}
|
|
105
138
|
|
|
@@ -116,35 +149,60 @@ export class NotificationController {
|
|
|
116
149
|
this.commandFailure = undefined;
|
|
117
150
|
this.commandRejection = undefined;
|
|
118
151
|
this.setStatus({ kind: "idle" });
|
|
119
|
-
if (subscription !== undefined)
|
|
152
|
+
if (subscription !== undefined) {
|
|
153
|
+
await subscription.dispose();
|
|
154
|
+
}
|
|
120
155
|
}
|
|
121
156
|
|
|
122
157
|
select(notificationId: NotificationId | undefined): void {
|
|
123
|
-
if (
|
|
158
|
+
if (
|
|
159
|
+
notificationId !== undefined &&
|
|
160
|
+
!this.records.some((record) => record.notificationId === notificationId)
|
|
161
|
+
) {
|
|
162
|
+
throw new NotificationControllerUnknownRecordError(notificationId);
|
|
163
|
+
}
|
|
124
164
|
this.selectedNotificationId = notificationId;
|
|
125
165
|
this.notify();
|
|
126
166
|
}
|
|
127
167
|
|
|
128
168
|
async loadMore(): Promise<void> {
|
|
129
169
|
const current = this.requireSnapshot();
|
|
130
|
-
if (!current.page.hasMore)
|
|
170
|
+
if (!current.page.hasMore) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
131
173
|
const next = (await this.client.snapshot(this.records.length, this.pageSize)).snapshot;
|
|
132
|
-
if (
|
|
174
|
+
if (
|
|
175
|
+
next.authority.authorityId !== current.authority.authorityId ||
|
|
176
|
+
next.authority.authorityEpoch !== current.authority.authorityEpoch ||
|
|
177
|
+
next.ledgerRevision !== current.ledgerRevision
|
|
178
|
+
) {
|
|
133
179
|
this.install(next);
|
|
134
180
|
return;
|
|
135
181
|
}
|
|
136
182
|
const known = new Set(this.records.map((record) => record.notificationId));
|
|
137
|
-
this.records = [
|
|
138
|
-
|
|
183
|
+
this.records = [
|
|
184
|
+
...this.records,
|
|
185
|
+
...next.page.records.filter((record) => !known.has(record.notificationId)),
|
|
186
|
+
];
|
|
187
|
+
this.snapshot = {
|
|
188
|
+
...current,
|
|
189
|
+
page: { ...current.page, hasMore: next.page.hasMore, records: [...this.records] },
|
|
190
|
+
};
|
|
139
191
|
this.notify();
|
|
140
192
|
}
|
|
141
193
|
|
|
142
|
-
markSeen(notificationId: NotificationId): Promise<NotificationMutationResult> {
|
|
143
|
-
|
|
194
|
+
markSeen(notificationId: NotificationId): Promise<NotificationMutationResult> {
|
|
195
|
+
return this.mutateRecord(notificationId, "markSeen");
|
|
196
|
+
}
|
|
197
|
+
dismiss(notificationId: NotificationId): Promise<NotificationMutationResult> {
|
|
198
|
+
return this.mutateRecord(notificationId, "dismiss");
|
|
199
|
+
}
|
|
144
200
|
|
|
145
201
|
dismissToast(id: string): void {
|
|
146
202
|
const next = this.toasts.filter((toast) => toast.id !== id);
|
|
147
|
-
if (next.length === this.toasts.length)
|
|
203
|
+
if (next.length === this.toasts.length) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
148
206
|
this.toasts = next;
|
|
149
207
|
this.notify();
|
|
150
208
|
}
|
|
@@ -152,19 +210,36 @@ export class NotificationController {
|
|
|
152
210
|
async invokeAction(notificationId: NotificationId, referenceId: string): Promise<void> {
|
|
153
211
|
const record = this.requireRecord(notificationId);
|
|
154
212
|
const action = record.draft.actions.find((candidate) => candidate.referenceId === referenceId);
|
|
155
|
-
if (action === undefined)
|
|
156
|
-
|
|
157
|
-
|
|
213
|
+
if (action === undefined) {
|
|
214
|
+
throw new NotificationControllerUnknownActionError(notificationId, referenceId);
|
|
215
|
+
}
|
|
216
|
+
if (this.actionExecutor === undefined) {
|
|
217
|
+
throw new NotificationControllerActionUnavailableError();
|
|
218
|
+
}
|
|
219
|
+
const pending = {
|
|
220
|
+
requestId: this.client.nextRequestId(),
|
|
221
|
+
notificationId,
|
|
222
|
+
kind: "action" as const,
|
|
223
|
+
};
|
|
158
224
|
await this.runPending(pending, async () => {
|
|
159
|
-
await this.actionExecutor?.admitAndExecute({
|
|
225
|
+
await this.actionExecutor?.admitAndExecute({
|
|
226
|
+
notificationId,
|
|
227
|
+
sourceId: record.draft.sourceId,
|
|
228
|
+
referenceId: action.referenceId,
|
|
229
|
+
});
|
|
160
230
|
});
|
|
161
231
|
}
|
|
162
232
|
|
|
163
233
|
isPending(notificationId: NotificationId, kind: NotificationPendingKind): boolean {
|
|
164
|
-
return [...this.pending.values()].some(
|
|
234
|
+
return [...this.pending.values()].some(
|
|
235
|
+
(item) => item.notificationId === notificationId && item.kind === kind,
|
|
236
|
+
);
|
|
165
237
|
}
|
|
166
238
|
|
|
167
|
-
private async mutateRecord(
|
|
239
|
+
private async mutateRecord(
|
|
240
|
+
notificationId: NotificationId,
|
|
241
|
+
kind: "markSeen" | "dismiss",
|
|
242
|
+
): Promise<NotificationMutationResult> {
|
|
168
243
|
const snapshot = this.requireSnapshot();
|
|
169
244
|
this.requireRecord(notificationId);
|
|
170
245
|
const command = {
|
|
@@ -178,40 +253,68 @@ export class NotificationController {
|
|
|
178
253
|
return this.runPending({ requestId: command.requestId, notificationId, kind }, async () => {
|
|
179
254
|
const result = await this.client.mutate(command);
|
|
180
255
|
this.install(result.snapshot);
|
|
181
|
-
if (result.status === "rejected")
|
|
256
|
+
if (result.status === "rejected") {
|
|
257
|
+
this.commandRejection = {
|
|
258
|
+
requestId: command.requestId,
|
|
259
|
+
notificationId,
|
|
260
|
+
kind,
|
|
261
|
+
rejection: result.rejection,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
182
264
|
return result;
|
|
183
265
|
});
|
|
184
266
|
}
|
|
185
267
|
|
|
186
|
-
private async runPending<Result>(
|
|
187
|
-
|
|
268
|
+
private async runPending<Result>(
|
|
269
|
+
pending: NotificationPendingCommand,
|
|
270
|
+
run: () => Promise<Result>,
|
|
271
|
+
): Promise<Result> {
|
|
272
|
+
if (this.isPending(pending.notificationId, pending.kind)) {
|
|
273
|
+
throw new NotificationControllerCommandPendingError(pending.notificationId, pending.kind);
|
|
274
|
+
}
|
|
188
275
|
const lifecycle = this.lifecycleRevision;
|
|
189
276
|
this.pending.set(pending.requestId, pending);
|
|
190
277
|
this.commandFailure = undefined;
|
|
191
278
|
this.commandRejection = undefined;
|
|
192
279
|
this.notify();
|
|
193
|
-
try {
|
|
194
|
-
|
|
195
|
-
|
|
280
|
+
try {
|
|
281
|
+
return await run();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (this.isCurrent(lifecycle)) {
|
|
284
|
+
this.commandFailure = { ...pending, error };
|
|
285
|
+
}
|
|
196
286
|
throw error;
|
|
197
287
|
} finally {
|
|
198
|
-
if (this.isCurrent(lifecycle)) {
|
|
288
|
+
if (this.isCurrent(lifecycle)) {
|
|
289
|
+
this.pending.delete(pending.requestId);
|
|
290
|
+
this.notify();
|
|
291
|
+
}
|
|
199
292
|
}
|
|
200
293
|
}
|
|
201
294
|
|
|
202
295
|
private install(candidate: NotificationSnapshot): void {
|
|
203
|
-
if (!isNewerNotificationSnapshot(candidate, this.snapshot))
|
|
296
|
+
if (!isNewerNotificationSnapshot(candidate, this.snapshot)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
204
299
|
const previous = this.snapshot;
|
|
205
300
|
this.snapshot = candidate;
|
|
206
301
|
this.records = [...candidate.page.records];
|
|
207
302
|
if (previous !== undefined && this.toastSelector !== undefined) {
|
|
208
303
|
const existing = new Set(this.toasts.map((toast) => toast.notificationId));
|
|
209
|
-
const fresh = candidate.page.records.filter(
|
|
304
|
+
const fresh = candidate.page.records.filter(
|
|
305
|
+
(record) =>
|
|
306
|
+
record.readState === "unseen" &&
|
|
307
|
+
record.lastChangedLedgerRevision > previous.ledgerRevision &&
|
|
308
|
+
this.toastSelector?.(record) === true &&
|
|
309
|
+
!existing.has(record.notificationId),
|
|
310
|
+
);
|
|
210
311
|
this.toasts = [...this.toasts, ...fresh.map((record) => this.projectToast(record))];
|
|
211
312
|
}
|
|
212
313
|
const retained = new Set(this.records.map((record) => record.notificationId));
|
|
213
314
|
this.toasts = this.toasts.filter((toast) => retained.has(toast.notificationId));
|
|
214
|
-
if (this.selectedNotificationId !== undefined && !retained.has(this.selectedNotificationId))
|
|
315
|
+
if (this.selectedNotificationId !== undefined && !retained.has(this.selectedNotificationId)) {
|
|
316
|
+
this.selectedNotificationId = undefined;
|
|
317
|
+
}
|
|
215
318
|
this.notify();
|
|
216
319
|
}
|
|
217
320
|
|
|
@@ -226,15 +329,66 @@ export class NotificationController {
|
|
|
226
329
|
};
|
|
227
330
|
}
|
|
228
331
|
|
|
229
|
-
private requireSnapshot(): NotificationSnapshot {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
332
|
+
private requireSnapshot(): NotificationSnapshot {
|
|
333
|
+
if (!this.started || this.snapshot === undefined) {
|
|
334
|
+
throw new NotificationControllerUnavailableError();
|
|
335
|
+
}
|
|
336
|
+
return this.snapshot;
|
|
337
|
+
}
|
|
338
|
+
private requireRecord(id: NotificationId): NotificationRecordProjection {
|
|
339
|
+
const record = this.records.find((candidate) => candidate.notificationId === id);
|
|
340
|
+
if (record === undefined) {
|
|
341
|
+
throw new NotificationControllerUnknownRecordError(id);
|
|
342
|
+
}
|
|
343
|
+
return record;
|
|
344
|
+
}
|
|
345
|
+
private isCurrent(revision: number): boolean {
|
|
346
|
+
return this.started && this.lifecycleRevision === revision;
|
|
347
|
+
}
|
|
348
|
+
private setStatus(status: NotificationControllerStatus): void {
|
|
349
|
+
this.status = status;
|
|
350
|
+
this.notify();
|
|
351
|
+
}
|
|
352
|
+
private notify(): void {
|
|
353
|
+
for (const observer of this.observers) {
|
|
354
|
+
observer();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
234
357
|
}
|
|
235
358
|
|
|
236
|
-
export class NotificationControllerUnavailableError extends Error {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
359
|
+
export class NotificationControllerUnavailableError extends Error {
|
|
360
|
+
constructor() {
|
|
361
|
+
super("notification controller is not ready");
|
|
362
|
+
this.name = "NotificationControllerUnavailableError";
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
export class NotificationControllerUnknownRecordError extends Error {
|
|
366
|
+
constructor(readonly notificationId: string) {
|
|
367
|
+
super(`unknown notification: ${notificationId}`);
|
|
368
|
+
this.name = "NotificationControllerUnknownRecordError";
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
export class NotificationControllerUnknownActionError extends Error {
|
|
372
|
+
constructor(
|
|
373
|
+
readonly notificationId: string,
|
|
374
|
+
readonly referenceId: string,
|
|
375
|
+
) {
|
|
376
|
+
super(`unknown notification action ${referenceId} on ${notificationId}`);
|
|
377
|
+
this.name = "NotificationControllerUnknownActionError";
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
export class NotificationControllerActionUnavailableError extends Error {
|
|
381
|
+
constructor() {
|
|
382
|
+
super("notification action executor is not configured");
|
|
383
|
+
this.name = "NotificationControllerActionUnavailableError";
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
export class NotificationControllerCommandPendingError extends Error {
|
|
387
|
+
constructor(
|
|
388
|
+
readonly notificationId: string,
|
|
389
|
+
readonly kind: NotificationPendingKind,
|
|
390
|
+
) {
|
|
391
|
+
super(`notification ${kind} already pending for ${notificationId}`);
|
|
392
|
+
this.name = "NotificationControllerCommandPendingError";
|
|
393
|
+
}
|
|
394
|
+
}
|
|
@@ -7,6 +7,8 @@ export interface DirectNotificationHandlers {
|
|
|
7
7
|
readonly nextRequestId: NotificationPort["nextRequestId"];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function createDirectNotificationPort(
|
|
10
|
+
export function createDirectNotificationPort(
|
|
11
|
+
handlers: DirectNotificationHandlers,
|
|
12
|
+
): NotificationPort {
|
|
11
13
|
return { ...handlers };
|
|
12
14
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
5
5
|
|
|
6
|
-
export const NOTIFICATIONS_FIELDS
|
|
6
|
+
export const NOTIFICATIONS_FIELDS = {
|
|
7
7
|
"NotificationAuthorityProjection": ["authorityId", "authorityEpoch"],
|
|
8
8
|
"NotificationActionProjection": ["referenceId", "label"],
|
|
9
9
|
"NotificationDraftProjection": ["sourceId", "severity", "title", "summary", "causeId", "actions", "replacementKey", "producerToken", "retentionClass", "presentationTimeUnixMs"],
|
|
@@ -16,4 +16,4 @@ export const NOTIFICATIONS_FIELDS: Record<string, readonly string[]> = {
|
|
|
16
16
|
"NotificationRemovalProjection": ["record", "reason"],
|
|
17
17
|
"NotificationRejection": ["code", "detail", "refreshRequired"],
|
|
18
18
|
"NotificationChangedEvent": ["protocolVersion", "requestId", "authority", "previousLedgerRevision", "committedLedgerRevision", "affectedNotificationIds", "kind"],
|
|
19
|
-
};
|
|
19
|
+
} as const;
|
|
@@ -3,6 +3,8 @@ import type {
|
|
|
3
3
|
NotificationMutationCommand,
|
|
4
4
|
NotificationRequestId,
|
|
5
5
|
NotificationSnapshotQuery,
|
|
6
|
+
NotificationSnapshotResponse,
|
|
7
|
+
NotificationMutationResult,
|
|
6
8
|
} from "./generated/protocol.ts";
|
|
7
9
|
|
|
8
10
|
export type NotificationUnlisten = () => void | Promise<void>;
|
|
@@ -10,13 +12,15 @@ export type NotificationUnlisten = () => void | Promise<void>;
|
|
|
10
12
|
export interface NotificationPort {
|
|
11
13
|
snapshot(query: NotificationSnapshotQuery): Promise<unknown>;
|
|
12
14
|
mutate(command: NotificationMutationCommand): Promise<unknown>;
|
|
13
|
-
listen
|
|
15
|
+
listen?:
|
|
16
|
+
| ((listener: (event: unknown) => void) => NotificationUnlisten | Promise<NotificationUnlisten>)
|
|
17
|
+
| undefined;
|
|
14
18
|
nextRequestId(): NotificationRequestId;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export interface CheckedNotificationPort {
|
|
18
|
-
snapshot(query: NotificationSnapshotQuery): Promise<
|
|
19
|
-
mutate(command: NotificationMutationCommand): Promise<
|
|
22
|
+
snapshot(query: NotificationSnapshotQuery): Promise<NotificationSnapshotResponse>;
|
|
23
|
+
mutate(command: NotificationMutationCommand): Promise<NotificationMutationResult>;
|
|
20
24
|
listen?(listener: (event: NotificationChangedEvent) => void): Promise<NotificationUnlisten>;
|
|
21
25
|
nextRequestId(): NotificationRequestId;
|
|
22
26
|
}
|
|
@@ -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
|
-
}
|