@serfab/cadre-core 1.19.1 → 1.21.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 (103) hide show
  1. package/dist/cadre-node.d.ts +53 -14
  2. package/dist/cadre-node.js +97 -30
  3. package/dist/cadre-node.js.map +1 -1
  4. package/dist/control-database.d.ts +2 -1
  5. package/dist/control-database.js +146 -135
  6. package/dist/control-database.js.map +1 -1
  7. package/dist/control-protocol-guard.js +3 -2
  8. package/dist/control-protocol-guard.js.map +1 -1
  9. package/dist/control-stream.js +2 -1
  10. package/dist/control-stream.js.map +1 -1
  11. package/dist/describe-thrown.d.ts +12 -0
  12. package/dist/describe-thrown.js +59 -0
  13. package/dist/describe-thrown.js.map +1 -0
  14. package/dist/edge-node/dissolve.d.ts +1 -1
  15. package/dist/edge-node/dissolve.js +1 -1
  16. package/dist/edge-node/dissolve.js.map +1 -1
  17. package/dist/edge-node/edge-join.js +2 -1
  18. package/dist/edge-node/edge-join.js.map +1 -1
  19. package/dist/edge-node/edge-node.js +2 -1
  20. package/dist/edge-node/edge-node.js.map +1 -1
  21. package/dist/edge-node/strand-move.d.ts +0 -2
  22. package/dist/edge-node/strand-move.js +1 -4
  23. package/dist/edge-node/strand-move.js.map +1 -1
  24. package/dist/edge-node/strands.js +2 -1
  25. package/dist/edge-node/strands.js.map +1 -1
  26. package/dist/enrollment.js +2 -1
  27. package/dist/enrollment.js.map +1 -1
  28. package/dist/index.d.ts +3 -1
  29. package/dist/index.js +3 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/member-redemption.js +3 -9
  32. package/dist/member-redemption.js.map +1 -1
  33. package/dist/node-local-snapshot.js +2 -1
  34. package/dist/node-local-snapshot.js.map +1 -1
  35. package/dist/peer-dial.js +3 -2
  36. package/dist/peer-dial.js.map +1 -1
  37. package/dist/pending-join-runner.d.ts +29 -2
  38. package/dist/pending-join-runner.js +60 -20
  39. package/dist/pending-join-runner.js.map +1 -1
  40. package/dist/push-notifier-apns.js +8 -7
  41. package/dist/push-notifier-apns.js.map +1 -1
  42. package/dist/push-notifier-fcm.js +6 -5
  43. package/dist/push-notifier-fcm.js.map +1 -1
  44. package/dist/push-notifier-shared.d.ts +0 -2
  45. package/dist/push-notifier-shared.js +4 -4
  46. package/dist/push-notifier-shared.js.map +1 -1
  47. package/dist/relay-reservation.js +24 -4
  48. package/dist/relay-reservation.js.map +1 -1
  49. package/dist/strand-addr-protocol.js +2 -1
  50. package/dist/strand-addr-protocol.js.map +1 -1
  51. package/dist/strand-app-schema-report.d.ts +56 -0
  52. package/dist/strand-app-schema-report.js +83 -0
  53. package/dist/strand-app-schema-report.js.map +1 -0
  54. package/dist/strand-database.d.ts +9 -5
  55. package/dist/strand-database.js +12 -6
  56. package/dist/strand-database.js.map +1 -1
  57. package/dist/strand-first-sync-gate.js +4 -3
  58. package/dist/strand-first-sync-gate.js.map +1 -1
  59. package/dist/strand-formation-protocol.js +4 -3
  60. package/dist/strand-formation-protocol.js.map +1 -1
  61. package/dist/strand-instance-manager.d.ts +8 -2
  62. package/dist/strand-instance-manager.js +8 -6
  63. package/dist/strand-instance-manager.js.map +1 -1
  64. package/dist/strand-membership-reconciler.js +9 -11
  65. package/dist/strand-membership-reconciler.js.map +1 -1
  66. package/dist/strand-move.js +4 -6
  67. package/dist/strand-move.js.map +1 -1
  68. package/dist/strand-offline.d.ts +10 -39
  69. package/dist/strand-offline.js +9 -54
  70. package/dist/strand-offline.js.map +1 -1
  71. package/dist/types.d.ts +8 -5
  72. package/dist/types.js.map +1 -1
  73. package/package.json +8 -8
  74. package/src/cadre-node.ts +11528 -11456
  75. package/src/control-database.ts +5603 -5592
  76. package/src/control-protocol-guard.ts +3 -2
  77. package/src/control-stream.ts +2 -1
  78. package/src/describe-thrown.ts +60 -0
  79. package/src/edge-node/dissolve.ts +2 -1
  80. package/src/edge-node/edge-join.ts +1 -1
  81. package/src/edge-node/edge-node.ts +2 -1
  82. package/src/edge-node/strand-move.ts +1 -5
  83. package/src/edge-node/strands.ts +74 -73
  84. package/src/enrollment.ts +2 -1
  85. package/src/index.ts +924 -917
  86. package/src/member-redemption.ts +3 -9
  87. package/src/node-local-snapshot.ts +2 -1
  88. package/src/peer-dial.ts +605 -604
  89. package/src/pending-join-runner.ts +68 -22
  90. package/src/push-notifier-apns.ts +8 -7
  91. package/src/push-notifier-fcm.ts +6 -5
  92. package/src/push-notifier-shared.ts +5 -5
  93. package/src/relay-reservation.ts +1239 -1211
  94. package/src/strand-addr-protocol.ts +2 -1
  95. package/src/strand-app-schema-report.ts +122 -0
  96. package/src/strand-database.ts +474 -466
  97. package/src/strand-first-sync-gate.ts +600 -599
  98. package/src/strand-formation-protocol.ts +4 -3
  99. package/src/strand-instance-manager.ts +2219 -2210
  100. package/src/strand-membership-reconciler.ts +942 -945
  101. package/src/strand-move.ts +594 -597
  102. package/src/strand-offline.ts +11 -80
  103. package/src/types.ts +2963 -2960
@@ -1,11 +1,6 @@
1
- import debug from 'debug';
2
1
  import { EntryNotDiscardableError, UnknownEntryError } from '@optimystic/db-core';
3
2
  import type { IKVStore } from '@optimystic/db-p2p';
4
- import type {
5
- AppSchemaOutcome, OfflineModeState, QueuedTransactionStatus, SereusPluginResult, StrandOfflineController,
6
- } from '@serfab/quereus-plugin-sereus';
7
-
8
- const log = debug('sereus:cadre:strand-offline');
3
+ import type { OfflineModeState, QueuedTransactionStatus, StrandOfflineController } from '@serfab/quereus-plugin-sereus';
9
4
 
10
5
  /**
11
6
  * Which acknowledgement a strand's transactions get from the moment it is set: `'offline'`, a
@@ -38,13 +33,6 @@ export interface StrandOfflineConfig {
38
33
  export type StrandOfflineQueue = Pick<StrandOfflineController,
39
34
  'queueState' | 'entries' | 'status' | 'outcomes' | 'acknowledge' | 'discard' | 'whenDrained' | 'onStatus' | 'onQueueState'>;
40
35
 
41
- /**
42
- * `StrandDatabase.appSchemaState()`: whether the database runs the `App` schema its launch was
43
- * given. `'waiting-for-queue'` while queued transactions hold the apply back (the database runs the
44
- * earlier schema); `'failed'` when a later retry failed for another reason.
45
- */
46
- export type StrandAppSchemaState = 'applied' | 'waiting-for-queue' | 'failed';
47
-
48
36
  /** `strand:offline-status`: one status of one queued transaction. */
49
37
  export interface StrandOfflineStatus {
50
38
  readonly strandId: string;
@@ -57,23 +45,13 @@ export interface StrandQueueState {
57
45
  readonly state: OfflineModeState;
58
46
  }
59
47
 
60
- /** `strand:app-schema-deferred`: the queued transactions that held the `App` schema apply back. */
61
- export interface StrandAppSchemaDeferred {
62
- readonly strandId: string;
63
- readonly transactionIds: readonly string[];
64
- }
65
-
66
48
  /**
67
- * Where a strand database reports its offline queue and its app-schema apply. Retained with the
68
- * launch config and handed to every database built for the launch, so the reports outlive
69
- * hibernation and every other rebuild.
49
+ * Where a strand database reports its offline queue. Retained with the launch config and handed to
50
+ * every database built for the launch, so the reports outlive hibernation and every other rebuild.
70
51
  */
71
52
  export interface StrandOfflineListeners {
72
53
  onOfflineStatus?: (event: StrandOfflineStatus) => void;
73
54
  onQueueState?: (event: StrandQueueState) => void;
74
- onAppSchemaDeferred?: (event: StrandAppSchemaDeferred) => void;
75
- onAppSchemaApplied?: (event: { strandId: string }) => void;
76
- onAppSchemaFailed?: (event: { strandId: string; error: Error }) => void;
77
55
  }
78
56
 
79
57
  /** Thrown by `CadreNode.setStrandOfflineMode` on a node configured without `strandOffline`. */
@@ -159,17 +137,12 @@ export function isSendingStatus(status: QueuedTransactionStatus): boolean {
159
137
  }
160
138
 
161
139
  /**
162
- * What one strand database reports about its offline queue and its app-schema apply. Built once
163
- * `connectToStrand` has returned (a restored transaction's `queued` status was delivered during its
164
- * `hydrate`, before this subscribes: {@link published} reports the queue's state for that reason)
165
- * and released first when the database closes, so nothing from a closing connection reaches the app.
166
- *
167
- * App-schema events begin at publication, when the app gets the database: a retry that landed
168
- * before then is not announced, and one that failed before then is announced at publication.
140
+ * What one strand database reports about its offline queue. Built once `connectToStrand` has
141
+ * returned (a restored transaction's `queued` status was delivered during its `hydrate`, before this
142
+ * subscribes: {@link published} reports the queue's state for that reason) and released first when
143
+ * the database closes, so nothing from a closing connection reaches the app.
169
144
  */
170
145
  export class StrandOfflineReport {
171
- private appSchema: StrandAppSchemaState;
172
- private appSchemaError: Error | undefined;
173
146
  private wasPublished = false;
174
147
  private released = false;
175
148
  private readonly unsubscribe: () => void;
@@ -177,42 +150,24 @@ export class StrandOfflineReport {
177
150
  constructor(
178
151
  private readonly strandId: string,
179
152
  private readonly listeners: StrandOfflineListeners,
180
- private readonly result: Pick<SereusPluginResult, 'offline' | 'appSchema' | 'appSchemaDeferredBy'>
153
+ private readonly queue: StrandOfflineController | undefined
181
154
  ) {
182
- // `appSchema` is absent without an `App` schema (a storage replica), which has nothing to defer.
183
- this.appSchema = result.appSchemaDeferredBy ? 'waiting-for-queue' : 'applied';
184
- const queue = result.offline;
185
155
  const unsubscribeStatus = queue?.onStatus((status) => listeners.onOfflineStatus?.({ strandId, status }));
186
156
  const unsubscribeState = queue?.onQueueState((state) => listeners.onQueueState?.({ strandId, state }));
187
157
  this.unsubscribe = () => {
188
158
  unsubscribeStatus?.();
189
159
  unsubscribeState?.();
190
160
  };
191
- if (result.appSchemaDeferredBy) {
192
- void result.appSchema?.then((outcome) => this.settleAppSchema(outcome)).catch((error: unknown) => {
193
- log('strand %s: reporting the deferred app schema apply failed: %O', strandId, error);
194
- });
195
- }
196
- }
197
-
198
- appSchemaState(): StrandAppSchemaState {
199
- return this.appSchema;
200
161
  }
201
162
 
202
- /** The database was handed to the app: report the queue's state, and an apply still waiting or already failed. */
163
+ /** The database was handed to the app: report the queue's state. */
203
164
  published(): void {
204
165
  if (this.released || this.wasPublished) {
205
166
  return;
206
167
  }
207
168
  this.wasPublished = true;
208
- const queue = this.result.offline;
209
- if (queue) {
210
- this.listeners.onQueueState?.({ strandId: this.strandId, state: queue.queueState() });
211
- }
212
- if (this.appSchema === 'waiting-for-queue') {
213
- this.listeners.onAppSchemaDeferred?.({ strandId: this.strandId, transactionIds: this.result.appSchemaDeferredBy ?? [] });
214
- } else if (this.appSchemaError) {
215
- this.reportAppSchemaFailed(this.appSchemaError);
169
+ if (this.queue) {
170
+ this.listeners.onQueueState?.({ strandId: this.strandId, state: this.queue.queueState() });
216
171
  }
217
172
  }
218
173
 
@@ -220,28 +175,4 @@ export class StrandOfflineReport {
220
175
  this.released = true;
221
176
  this.unsubscribe();
222
177
  }
223
-
224
- /** A cancelled retry (the database closed first) reports nothing. */
225
- private settleAppSchema(outcome: AppSchemaOutcome): void {
226
- if (this.released || outcome.state === 'cancelled') {
227
- return;
228
- }
229
- if (outcome.state === 'applied') {
230
- this.appSchema = 'applied';
231
- if (this.wasPublished) {
232
- this.listeners.onAppSchemaApplied?.({ strandId: this.strandId });
233
- }
234
- return;
235
- }
236
- this.appSchema = 'failed';
237
- this.appSchemaError = outcome.error instanceof Error ? outcome.error : new Error(String(outcome.error));
238
- log('strand %s: the deferred app schema apply failed; the database keeps the earlier schema: %O', this.strandId, outcome.error);
239
- if (this.wasPublished) {
240
- this.reportAppSchemaFailed(this.appSchemaError);
241
- }
242
- }
243
-
244
- private reportAppSchemaFailed(error: Error): void {
245
- this.listeners.onAppSchemaFailed?.({ strandId: this.strandId, error });
246
- }
247
178
  }