@serfab/cadre-core 1.19.0 → 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 +118 -16
- package/dist/cadre-node.js +210 -31
- 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-read-retry.d.ts +19 -16
- package/dist/control-read-retry.js +22 -54
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-retry.d.ts +50 -6
- package/dist/control-retry.js +53 -6
- package/dist/control-retry.js.map +1 -1
- package/dist/control-stream.js +2 -1
- package/dist/control-stream.js.map +1 -1
- package/dist/control-write-retry.d.ts +24 -16
- package/dist/control-write-retry.js +58 -30
- package/dist/control-write-retry.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/config.d.ts +8 -2
- package/dist/edge-node/config.js +5 -1
- package/dist/edge-node/config.js.map +1 -1
- 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 +4 -1
- package/dist/edge-node/edge-join.js.map +1 -1
- package/dist/edge-node/edge-node.d.ts +10 -0
- package/dist/edge-node/edge-node.js +54 -9
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/options.d.ts +11 -2
- package/dist/edge-node/options.js +11 -4
- package/dist/edge-node/options.js.map +1 -1
- package/dist/edge-node/platform.d.ts +15 -3
- 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 +5 -3
- 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 +6 -2
- package/dist/index.js +9 -1
- 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 +60 -0
- package/dist/strand-database.js +93 -0
- 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 +73 -2
- package/dist/strand-instance-manager.js +112 -9
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +13 -1
- package/dist/strand-membership-reconciler.js +25 -16
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +16 -2
- package/dist/strand-membership-writer.js +54 -8
- package/dist/strand-membership-writer.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 +102 -0
- package/dist/strand-offline.js +97 -0
- package/dist/strand-offline.js.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.js.map +1 -1
- package/package.json +8 -8
- package/src/cadre-node.ts +230 -31
- package/src/control-database.ts +5594 -5592
- package/src/control-protocol-guard.ts +3 -2
- package/src/control-read-retry.ts +22 -58
- package/src/control-retry.ts +54 -6
- package/src/control-stream.ts +2 -1
- package/src/control-write-retry.ts +58 -30
- package/src/describe-thrown.ts +60 -0
- package/src/edge-node/config.ts +11 -2
- package/src/edge-node/dissolve.ts +2 -1
- package/src/edge-node/edge-join.ts +2 -1
- package/src/edge-node/edge-node.ts +57 -7
- package/src/edge-node/options.ts +20 -4
- package/src/edge-node/platform.ts +15 -3
- package/src/edge-node/strand-move.ts +1 -5
- package/src/edge-node/strands.ts +74 -72
- package/src/enrollment.ts +2 -1
- package/src/index.ts +27 -1
- 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 +123 -1
- package/src/strand-first-sync-gate.ts +600 -599
- package/src/strand-formation-protocol.ts +4 -3
- package/src/strand-instance-manager.ts +137 -10
- package/src/strand-membership-reconciler.ts +942 -928
- package/src/strand-membership-writer.ts +61 -14
- package/src/strand-move.ts +594 -597
- package/src/strand-offline.ts +178 -0
- package/src/types.ts +36 -0
|
@@ -3,6 +3,7 @@ import { toString as uint8ArrayToString } from 'uint8arrays';
|
|
|
3
3
|
import { TransactionActiveError } from '@quereus/quereus';
|
|
4
4
|
import type { Database, SqlValue } from '@quereus/quereus';
|
|
5
5
|
import { digest, sign, verify, generatePrivateKey, getPublicKey, randomBytes } from '@optimystic/quereus-plugin-crypto';
|
|
6
|
+
import { offlineControllerOf } from '@serfab/quereus-plugin-sereus';
|
|
6
7
|
import type { SAppConfig } from './types.js';
|
|
7
8
|
import type { Ed25519KeyPair } from './ed25519-key.js';
|
|
8
9
|
import { canonicalDatetime } from './canonical-datetime.js';
|
|
@@ -146,6 +147,31 @@ export class StrandTransactionBusyError extends Error {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
/**
|
|
151
|
+
* A membership write refused because the strand's offline queue holds transactions its members
|
|
152
|
+
* have not taken yet (docs/strands.md → "Offline mode"). Every `Strand` table is network-acknowledged, and a
|
|
153
|
+
* network-acknowledged commit made while transactions are queued waits for them to settle while
|
|
154
|
+
* holding Quereus's execution lock, so every other statement on the strand database, the app's
|
|
155
|
+
* included, would wait with it for up to the plugin's `networkCommitTimeoutMs`. Nothing was
|
|
156
|
+
* written. Raised whether or not the write would have joined an open transaction: joining would
|
|
157
|
+
* make the app's own commit wait the same way.
|
|
158
|
+
*/
|
|
159
|
+
export class StrandOfflineQueueBusyError extends Error {
|
|
160
|
+
/** The queued transactions the write would have waited behind, in queue order. */
|
|
161
|
+
readonly transactionIds: readonly string[];
|
|
162
|
+
|
|
163
|
+
constructor(transactionIds: readonly string[]) {
|
|
164
|
+
super(
|
|
165
|
+
`The strand's offline queue holds ${transactionIds.length} transaction(s) its members have not taken yet `
|
|
166
|
+
+ `(${transactionIds.join(', ')}). A membership write is acknowledged by the strand's members and would `
|
|
167
|
+
+ 'wait behind them, holding the strand database, so nothing was written; await '
|
|
168
|
+
+ 'strand.database.offline.whenDrained() and retry.',
|
|
169
|
+
);
|
|
170
|
+
this.name = 'StrandOfflineQueueBusyError';
|
|
171
|
+
this.transactionIds = transactionIds;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
149
175
|
/** Options every transactional membership writer accepts. */
|
|
150
176
|
export interface StrandWriteOptions {
|
|
151
177
|
/**
|
|
@@ -207,6 +233,8 @@ function combineStatements(...fragments: StrandStatements[]): StrandStatements {
|
|
|
207
233
|
* autocommit statement is merely in flight, which would make a background writer refuse
|
|
208
234
|
* spuriously and a composing caller run its statements as separate autocommits.
|
|
209
235
|
*
|
|
236
|
+
* - The strand's offline queue holds transactions: {@link StrandOfflineQueueBusyError}, before
|
|
237
|
+
* anything runs, every writer and every option alike (see {@link refuseBehindOfflineQueue}).
|
|
210
238
|
* - No transaction was open: the batch commits or fails as a unit, leaving nothing open.
|
|
211
239
|
* - One was already open, so the batch refuses with `TransactionActiveError` having run
|
|
212
240
|
* nothing. With `joinOpenTransaction: false` that becomes a
|
|
@@ -219,6 +247,7 @@ async function execStrandTransaction(
|
|
|
219
247
|
statements: StrandStatements,
|
|
220
248
|
options?: StrandWriteOptions,
|
|
221
249
|
): Promise<void> {
|
|
250
|
+
refuseBehindOfflineQueue(db);
|
|
222
251
|
try {
|
|
223
252
|
await db.exec(statements.sql, statements.params, { transaction: true });
|
|
224
253
|
return;
|
|
@@ -244,6 +273,24 @@ async function execStrandTransaction(
|
|
|
244
273
|
await db.exec(statements.sql, statements.params);
|
|
245
274
|
}
|
|
246
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Throw {@link StrandOfflineQueueBusyError} while the strand's offline queue lists any
|
|
278
|
+
* transaction. `entries()` also lists the journaled ones a restore has not put back yet, and a
|
|
279
|
+
* network-acknowledged commit waits behind those too.
|
|
280
|
+
*
|
|
281
|
+
* NOTE: racy by nature: an app commit queued between this check and the batch's `exec` makes the
|
|
282
|
+
* membership commit wait behind it, for up to `networkCommitTimeoutMs`, holding the execution
|
|
283
|
+
* lock. That is upstream's bounded wait in the rare case. If a frozen strand database is ever
|
|
284
|
+
* traced to a membership write that slipped past this check, hold the app's writes during
|
|
285
|
+
* membership commits instead.
|
|
286
|
+
*/
|
|
287
|
+
function refuseBehindOfflineQueue(db: Database): void {
|
|
288
|
+
const queued = offlineControllerOf(db)?.entries() ?? [];
|
|
289
|
+
if (queued.length > 0) {
|
|
290
|
+
throw new StrandOfflineQueueBusyError(queued.map((entry) => entry.transactionId));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
247
294
|
/**
|
|
248
295
|
* The `Strand.Revocation` tombstone insert that retires a deleted row's StampId.
|
|
249
296
|
*
|
|
@@ -736,12 +783,12 @@ export async function issueInvite(db: Database, params: IssueInviteParams): Prom
|
|
|
736
783
|
const managerSignature = signStrandPayload(payload, managerKeyPair.privateKeyB64);
|
|
737
784
|
const inviteSignature = signStrandPayload(payload, invitePrivateKey);
|
|
738
785
|
|
|
739
|
-
await db
|
|
740
|
-
`insert into Strand.Invite (Key, Expiration)
|
|
741
|
-
with context ManagerKey =
|
|
742
|
-
values (
|
|
743
|
-
|
|
744
|
-
);
|
|
786
|
+
await execStrandTransaction(db, {
|
|
787
|
+
sql: `insert into Strand.Invite (Key, Expiration)
|
|
788
|
+
with context ManagerKey = :managerKey, ManagerSignature = :managerSignature, InviteSignature = :inviteSignature
|
|
789
|
+
values (:inviteKey, :expiration);`,
|
|
790
|
+
params: { managerKey: managerKeyPair.publicKeyB64, managerSignature, inviteSignature, inviteKey, expiration: expirationColumn },
|
|
791
|
+
});
|
|
745
792
|
log('Issued invite %s (expires=%s)', inviteKey, expirationColumn ?? 'never');
|
|
746
793
|
|
|
747
794
|
return { inviteKey, invitePrivateKey };
|
|
@@ -937,8 +984,8 @@ export interface CancelInviteParams {
|
|
|
937
984
|
* `digest('Strand.CancelledInvite', 'cancel', InviteKey)`. The digest binds the exact
|
|
938
985
|
* invite key, so an approval minted for one invitation cannot cancel another.
|
|
939
986
|
*
|
|
940
|
-
* One row, one statement
|
|
941
|
-
*
|
|
987
|
+
* One row, one statement. `CancelledInvite.Authorized` is a deferred (subquery-bearing)
|
|
988
|
+
* check, so it fires at the batch's commit, or at the caller's when it joins an open one.
|
|
942
989
|
*
|
|
943
990
|
* Insert-if-absent, matching {@link registerMemberPeer}'s and {@link revokeMember}'s
|
|
944
991
|
* restart-safe shape: a repeat cancellation logs and returns rather than throwing on the
|
|
@@ -973,12 +1020,12 @@ export async function cancelInvite(db: Database, params: CancelInviteParams): Pr
|
|
|
973
1020
|
['Strand.CancelledInvite', 'cancel', inviteKey],
|
|
974
1021
|
managerKeyPair.privateKeyB64,
|
|
975
1022
|
);
|
|
976
|
-
await db
|
|
977
|
-
`insert into Strand.CancelledInvite (InviteKey)
|
|
978
|
-
with context ManagerKey =
|
|
979
|
-
values (
|
|
980
|
-
|
|
981
|
-
);
|
|
1023
|
+
await execStrandTransaction(db, {
|
|
1024
|
+
sql: `insert into Strand.CancelledInvite (InviteKey)
|
|
1025
|
+
with context ManagerKey = :managerKey, ManagerSignature = :managerSignature
|
|
1026
|
+
values (:inviteKey);`,
|
|
1027
|
+
params: { managerKey: managerKeyPair.publicKeyB64, managerSignature: signature, inviteKey },
|
|
1028
|
+
});
|
|
982
1029
|
log('Cancelled invite %s by manager %s', inviteKey, managerKeyPair.publicKeyB64);
|
|
983
1030
|
}
|
|
984
1031
|
|