@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.
Files changed (126) hide show
  1. package/package.json +1 -1
  2. package/src/agent-control/inject.ts +4 -1
  3. package/src/agent-control/selection.ts +35 -20
  4. package/src/agent-control/shim.ts +302 -144
  5. package/src/bridge/direct.ts +1 -1
  6. package/src/bridge/generated/fields.ts +3 -2
  7. package/src/bridge/generated/protocol.ts +7 -3
  8. package/src/bridge/job.ts +4 -14
  9. package/src/bridge/loopback.ts +7 -25
  10. package/src/bridge/operation.ts +13 -43
  11. package/src/bridge/router.ts +10 -23
  12. package/src/bridge/runtime/connection.ts +77 -105
  13. package/src/bridge/runtime/policy.ts +8 -28
  14. package/src/bridge/runtime/retry.ts +6 -18
  15. package/src/bridge/session.ts +4 -14
  16. package/src/bridge/stream/connection.ts +16 -38
  17. package/src/bridge/stream/source.ts +2 -6
  18. package/src/bridge/stream/tracker.ts +7 -12
  19. package/src/bridge/supervision.ts +11 -26
  20. package/src/bridge/validation/base.ts +17 -39
  21. package/src/bridge/validation/jobs.ts +11 -25
  22. package/src/bridge/validation/negotiation.ts +27 -37
  23. package/src/bridge/validation/operations.ts +28 -52
  24. package/src/bridge/validation/streams.ts +3 -10
  25. package/src/commands/client.ts +21 -26
  26. package/src/commands/controller.ts +32 -47
  27. package/src/commands/generated/fields.ts +3 -2
  28. package/src/commands/generated/protocol.ts +4 -0
  29. package/src/commands/keyboard.ts +92 -89
  30. package/src/commands/ports.ts +6 -12
  31. package/src/commands/projectors.ts +50 -48
  32. package/src/commands/validation.ts +70 -97
  33. package/src/config/client.ts +6 -19
  34. package/src/config/generated/fields.ts +2 -2
  35. package/src/config/names.ts +6 -12
  36. package/src/config/validation/commands.ts +5 -17
  37. package/src/config/validation/outcomes.ts +31 -39
  38. package/src/config/validation/primitives.ts +36 -53
  39. package/src/config/validation/projection.ts +66 -94
  40. package/src/core/connection.ts +70 -61
  41. package/src/core/record.ts +4 -0
  42. package/src/core/transport.ts +4 -15
  43. package/src/core/wire-copy.ts +6 -0
  44. package/src/history/client.ts +6 -12
  45. package/src/history/controller.ts +46 -46
  46. package/src/history/direct.ts +1 -3
  47. package/src/history/generated/fields.ts +2 -2
  48. package/src/history/ports.ts +4 -6
  49. package/src/history/serialized.ts +9 -13
  50. package/src/history/validation.ts +71 -55
  51. package/src/history-tree/client.ts +87 -11
  52. package/src/history-tree/controller.ts +313 -70
  53. package/src/history-tree/direct.ts +3 -1
  54. package/src/history-tree/generated/fields.ts +2 -2
  55. package/src/history-tree/ports.ts +3 -1
  56. package/src/history-tree/serialized.ts +39 -11
  57. package/src/history-tree/validation.ts +262 -63
  58. package/src/layout/generated/protocol.ts +2 -2
  59. package/src/layout/ratio.ts +2 -8
  60. package/src/layout/validation.ts +10 -19
  61. package/src/layout/visibility.ts +1 -2
  62. package/src/licence/client.ts +44 -7
  63. package/src/licence/controller.ts +76 -40
  64. package/src/licence/direct.ts +3 -1
  65. package/src/licence/generated/fields.ts +2 -2
  66. package/src/licence/generated/key-conformance.json +28 -0
  67. package/src/licence/generated/protocol.ts +1 -1
  68. package/src/licence/key.ts +40 -12
  69. package/src/licence/ports.ts +3 -1
  70. package/src/licence/serialized.ts +32 -9
  71. package/src/licence/validation.ts +120 -36
  72. package/src/native-content/client.ts +178 -236
  73. package/src/native-content/generated/fields.ts +2 -2
  74. package/src/native-content/ports.ts +9 -15
  75. package/src/native-content/serialized.ts +12 -19
  76. package/src/native-content/validation/base.ts +57 -50
  77. package/src/native-content/validation/messages.ts +21 -35
  78. package/src/native-content/validation/state.ts +31 -33
  79. package/src/notifications/client.ts +87 -31
  80. package/src/notifications/controller.ts +215 -61
  81. package/src/notifications/direct.ts +3 -1
  82. package/src/notifications/generated/fields.ts +2 -2
  83. package/src/notifications/ports.ts +7 -3
  84. package/src/notifications/serialized.ts +11 -9
  85. package/src/notifications/validation.ts +147 -43
  86. package/src/operation/bridge.ts +117 -50
  87. package/src/operation/client.ts +38 -24
  88. package/src/operation/controller.ts +33 -42
  89. package/src/operation/direct.ts +1 -3
  90. package/src/operation/generated/fields.ts +2 -2
  91. package/src/operation/ports.ts +10 -9
  92. package/src/operation/serialized.ts +8 -9
  93. package/src/operation/validation.ts +152 -65
  94. package/src/settings/client.ts +11 -44
  95. package/src/settings/connection.ts +26 -40
  96. package/src/settings/generated/fields.ts +3 -3
  97. package/src/settings/generated/protocol.ts +9 -4
  98. package/src/settings/names.ts +2 -4
  99. package/src/settings/registry.ts +23 -25
  100. package/src/settings/validation/authority.ts +19 -17
  101. package/src/settings/validation/command.ts +17 -37
  102. package/src/settings/validation/error.ts +2 -8
  103. package/src/settings/validation/primitives.ts +26 -42
  104. package/src/settings/validation/projection.ts +8 -24
  105. package/src/settings/validation/registry.ts +25 -73
  106. package/src/surface-transfer/client.ts +6 -18
  107. package/src/surface-transfer/generated/fields.ts +2 -2
  108. package/src/surface-transfer/validation.ts +31 -49
  109. package/src/surfaces/client.ts +12 -22
  110. package/src/surfaces/generated/fields.ts +2 -2
  111. package/src/surfaces/validation.ts +40 -49
  112. package/src/transfer/client.ts +26 -60
  113. package/src/transfer/connection.ts +12 -20
  114. package/src/transfer/generated/fields.ts +5 -5
  115. package/src/transfer/generated/protocol.ts +4 -4
  116. package/src/transfer/payload.ts +13 -31
  117. package/src/transfer/validation.ts +39 -75
  118. package/src/update/client.ts +59 -9
  119. package/src/update/controller.ts +113 -48
  120. package/src/update/direct.ts +3 -1
  121. package/src/update/generated/fields.ts +3 -3
  122. package/src/update/generated/protocol.ts +7 -3
  123. package/src/update/generated/variant-fields.ts +1 -0
  124. package/src/update/ports.ts +6 -2
  125. package/src/update/serialized.ts +34 -10
  126. package/src/update/validation.ts +115 -35
@@ -1,20 +1,26 @@
1
- import { isNewerNotificationSnapshot, NotificationClient, type NotificationSubscription } from "./client.ts";
2
- import {
3
- NOTIFICATION_PROTOCOL_VERSION,
4
- type NotificationActionProjection,
5
- type NotificationId,
6
- type NotificationMutationResult,
7
- type NotificationRecordProjection,
8
- type NotificationRejection,
9
- type NotificationRequestId,
10
- type NotificationSnapshot,
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, type NotificationStatusTone } from "./tone.ts";
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 = { readonly kind: "idle" } | { readonly kind: "loading" } | { readonly kind: "ready" } | { readonly kind: "failed"; readonly error: unknown };
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 { readonly rejection: NotificationRejection; }
27
- export interface NotificationCommandFailure extends NotificationPendingCommand { readonly error: unknown; }
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 { return this.records.find((record) => record.notificationId === this.selectedNotificationId); }
82
- get hasMore(): boolean { return this.snapshot?.page.hasMore ?? false; }
83
- get pendingCommands(): readonly NotificationPendingCommand[] { return [...this.pending.values()]; }
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 { this.observers.add(observer); return () => this.observers.delete(observer); }
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) return;
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) => { if (this.isCurrent(lifecycle)) this.install(snapshot); },
94
- ({ error }) => { if (this.isCurrent(lifecycle)) this.setStatus({ kind: "failed", error }); },
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)) this.setStatus({ kind: "ready" });
129
+ if (this.isCurrent(lifecycle)) {
130
+ this.setStatus({ kind: "ready" });
131
+ }
101
132
  } catch (error) {
102
- if (this.isCurrent(lifecycle)) this.setStatus({ kind: "failed", error });
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) await subscription.dispose();
152
+ if (subscription !== undefined) {
153
+ await subscription.dispose();
154
+ }
120
155
  }
121
156
 
122
157
  select(notificationId: NotificationId | undefined): void {
123
- if (notificationId !== undefined && !this.records.some((record) => record.notificationId === notificationId)) throw new NotificationControllerUnknownRecordError(notificationId);
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) return;
170
+ if (!current.page.hasMore) {
171
+ return;
172
+ }
131
173
  const next = (await this.client.snapshot(this.records.length, this.pageSize)).snapshot;
132
- if (next.authority.authorityId !== current.authority.authorityId || next.authority.authorityEpoch !== current.authority.authorityEpoch || next.ledgerRevision !== current.ledgerRevision) {
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 = [...this.records, ...next.page.records.filter((record) => !known.has(record.notificationId))];
138
- this.snapshot = { ...current, page: { ...current.page, hasMore: next.page.hasMore, records: [...this.records] } };
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> { return this.mutateRecord(notificationId, "markSeen"); }
143
- dismiss(notificationId: NotificationId): Promise<NotificationMutationResult> { return this.mutateRecord(notificationId, "dismiss"); }
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) return;
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) throw new NotificationControllerUnknownActionError(notificationId, referenceId);
156
- if (this.actionExecutor === undefined) throw new NotificationControllerActionUnavailableError();
157
- const pending = { requestId: this.client.nextRequestId(), notificationId, kind: "action" as const };
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({ notificationId, sourceId: record.draft.sourceId, referenceId: action.referenceId });
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((item) => item.notificationId === notificationId && item.kind === kind);
234
+ return [...this.pending.values()].some(
235
+ (item) => item.notificationId === notificationId && item.kind === kind,
236
+ );
165
237
  }
166
238
 
167
- private async mutateRecord(notificationId: NotificationId, kind: "markSeen" | "dismiss"): Promise<NotificationMutationResult> {
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") this.commandRejection = { requestId: command.requestId, notificationId, kind, rejection: result.rejection };
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>(pending: NotificationPendingCommand, run: () => Promise<Result>): Promise<Result> {
187
- if (this.isPending(pending.notificationId, pending.kind)) throw new NotificationControllerCommandPendingError(pending.notificationId, pending.kind);
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 { return await run(); }
194
- catch (error) {
195
- if (this.isCurrent(lifecycle)) this.commandFailure = { ...pending, error };
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)) { this.pending.delete(pending.requestId); this.notify(); }
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)) return;
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((record) => record.readState === "unseen" && record.lastChangedLedgerRevision > previous.ledgerRevision && this.toastSelector?.(record) === true && !existing.has(record.notificationId));
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)) this.selectedNotificationId = undefined;
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 { if (!this.started || this.snapshot === undefined) throw new NotificationControllerUnavailableError(); return this.snapshot; }
230
- private requireRecord(id: NotificationId): NotificationRecordProjection { const record = this.records.find((candidate) => candidate.notificationId === id); if (record === undefined) throw new NotificationControllerUnknownRecordError(id); return record; }
231
- private isCurrent(revision: number): boolean { return this.started && this.lifecycleRevision === revision; }
232
- private setStatus(status: NotificationControllerStatus): void { this.status = status; this.notify(); }
233
- private notify(): void { for (const observer of this.observers) observer(); }
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 { constructor() { super("notification controller is not ready"); this.name = "NotificationControllerUnavailableError"; } }
237
- export class NotificationControllerUnknownRecordError extends Error { constructor(readonly notificationId: string) { super(`unknown notification: ${notificationId}`); this.name = "NotificationControllerUnknownRecordError"; } }
238
- export class NotificationControllerUnknownActionError extends Error { constructor(readonly notificationId: string, readonly referenceId: string) { super(`unknown notification action ${referenceId} on ${notificationId}`); this.name = "NotificationControllerUnknownActionError"; } }
239
- export class NotificationControllerActionUnavailableError extends Error { constructor() { super("notification action executor is not configured"); this.name = "NotificationControllerActionUnavailableError"; } }
240
- export class NotificationControllerCommandPendingError extends Error { constructor(readonly notificationId: string, readonly kind: NotificationPendingKind) { super(`notification ${kind} already pending for ${notificationId}`); this.name = "NotificationControllerCommandPendingError"; } }
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(handlers: DirectNotificationHandlers): NotificationPort {
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: Record<string, readonly string[]> = {
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?(listener: (event: unknown) => void): NotificationUnlisten | Promise<NotificationUnlisten>;
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<import("./generated/protocol.ts").NotificationSnapshotResponse>;
19
- mutate(command: NotificationMutationCommand): Promise<import("./generated/protocol.ts").NotificationMutationResult>;
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 type { NotificationMutationCommand, NotificationSnapshotQuery } from "./generated/protocol.ts";
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 clone(await this.inner.snapshot(clone(query)));
12
+ return wireCopy(await this.inner.snapshot(wireCopy(query)));
9
13
  }
10
14
 
11
15
  async mutate(command: NotificationMutationCommand): Promise<unknown> {
12
- return clone(await this.inner.mutate(clone(command)));
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) return () => {};
17
- return this.inner.listen((event) => listener(clone(event)));
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
- }