@serfab/cadre-core 1.19.1 → 1.20.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/dist/cadre-node.d.ts +53 -14
- package/dist/cadre-node.js +97 -30
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +2 -1
- package/dist/control-database.js +128 -126
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.js +3 -2
- package/dist/control-protocol-guard.js.map +1 -1
- package/dist/control-stream.js +2 -1
- package/dist/control-stream.js.map +1 -1
- package/dist/describe-thrown.d.ts +12 -0
- package/dist/describe-thrown.js +59 -0
- package/dist/describe-thrown.js.map +1 -0
- package/dist/edge-node/dissolve.d.ts +1 -1
- package/dist/edge-node/dissolve.js +1 -1
- package/dist/edge-node/dissolve.js.map +1 -1
- package/dist/edge-node/edge-join.js +2 -1
- package/dist/edge-node/edge-join.js.map +1 -1
- package/dist/edge-node/edge-node.js +2 -1
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/strand-move.d.ts +0 -2
- package/dist/edge-node/strand-move.js +1 -4
- package/dist/edge-node/strand-move.js.map +1 -1
- package/dist/edge-node/strands.js +2 -1
- package/dist/edge-node/strands.js.map +1 -1
- package/dist/enrollment.js +2 -1
- package/dist/enrollment.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/member-redemption.js +3 -9
- package/dist/member-redemption.js.map +1 -1
- package/dist/node-local-snapshot.js +2 -1
- package/dist/node-local-snapshot.js.map +1 -1
- package/dist/peer-dial.js +3 -2
- package/dist/peer-dial.js.map +1 -1
- package/dist/pending-join-runner.d.ts +29 -2
- package/dist/pending-join-runner.js +60 -20
- package/dist/pending-join-runner.js.map +1 -1
- package/dist/push-notifier-apns.js +8 -7
- package/dist/push-notifier-apns.js.map +1 -1
- package/dist/push-notifier-fcm.js +6 -5
- package/dist/push-notifier-fcm.js.map +1 -1
- package/dist/push-notifier-shared.d.ts +0 -2
- package/dist/push-notifier-shared.js +4 -4
- package/dist/push-notifier-shared.js.map +1 -1
- package/dist/relay-reservation.js +4 -3
- package/dist/relay-reservation.js.map +1 -1
- package/dist/strand-addr-protocol.js +2 -1
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +53 -0
- package/dist/strand-app-schema-report.js +77 -0
- package/dist/strand-app-schema-report.js.map +1 -0
- package/dist/strand-database.d.ts +9 -5
- package/dist/strand-database.js +12 -6
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.js +4 -3
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-protocol.js +4 -3
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +8 -2
- package/dist/strand-instance-manager.js +8 -6
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.js +9 -11
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-move.js +4 -6
- package/dist/strand-move.js.map +1 -1
- package/dist/strand-offline.d.ts +10 -39
- package/dist/strand-offline.js +9 -54
- package/dist/strand-offline.js.map +1 -1
- package/dist/types.d.ts +7 -5
- package/dist/types.js.map +1 -1
- package/package.json +8 -8
- package/src/cadre-node.ts +11528 -11456
- package/src/control-database.ts +5594 -5592
- package/src/control-protocol-guard.ts +3 -2
- package/src/control-stream.ts +2 -1
- package/src/describe-thrown.ts +60 -0
- package/src/edge-node/dissolve.ts +2 -1
- package/src/edge-node/edge-join.ts +1 -1
- package/src/edge-node/edge-node.ts +2 -1
- package/src/edge-node/strand-move.ts +1 -5
- package/src/edge-node/strands.ts +74 -73
- package/src/enrollment.ts +2 -1
- package/src/index.ts +924 -917
- package/src/member-redemption.ts +3 -9
- package/src/node-local-snapshot.ts +2 -1
- package/src/peer-dial.ts +605 -604
- package/src/pending-join-runner.ts +68 -22
- package/src/push-notifier-apns.ts +8 -7
- package/src/push-notifier-fcm.ts +6 -5
- package/src/push-notifier-shared.ts +5 -5
- package/src/relay-reservation.ts +1212 -1211
- package/src/strand-addr-protocol.ts +2 -1
- package/src/strand-app-schema-report.ts +115 -0
- package/src/strand-database.ts +474 -466
- package/src/strand-first-sync-gate.ts +600 -599
- package/src/strand-formation-protocol.ts +4 -3
- package/src/strand-instance-manager.ts +2219 -2210
- package/src/strand-membership-reconciler.ts +942 -945
- package/src/strand-move.ts +594 -597
- package/src/strand-offline.ts +11 -80
- package/src/types.ts +2962 -2960
package/src/strand-offline.ts
CHANGED
|
@@ -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
|
|
68
|
-
*
|
|
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
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
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
|
|
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
|
|
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
|
-
|
|
209
|
-
|
|
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
|
}
|