@serfab/quereus-plugin-sereus 1.20.0 → 1.22.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/README.md +1 -1
- package/dist/app-schema.d.ts +22 -2
- package/dist/app-schema.js +152 -23
- package/dist/app-schema.js.map +1 -1
- package/dist/compose-strand.js +19 -8
- package/dist/compose-strand.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin-browser.js +28 -28
- package/dist/plugin-browser.js.map +4 -4
- package/dist/types.d.ts +13 -5
- package/package.json +8 -8
- package/src/app-schema.ts +397 -263
- package/src/compose-strand.ts +26 -9
- package/src/index.ts +30 -30
- package/src/types.ts +14 -6
package/src/compose-strand.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Database, VTablePluginInfo, FunctionPluginInfo, CollationPluginInf
|
|
|
3
3
|
import optimysticPlugin from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
4
4
|
import type { SqlCommitDurabilityListener, CommitFullyHeldListener, OfflineConfig, OfflineMode } from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
5
5
|
import type { Libp2p } from '@libp2p/interface';
|
|
6
|
-
import type { IRepo } from '@optimystic/db-core';
|
|
6
|
+
import type { ICohortReachability, IRepo } from '@optimystic/db-core';
|
|
7
7
|
import type { IKVStore, IRawStorage, NodeOptions } from '@optimystic/db-p2p';
|
|
8
8
|
import type {
|
|
9
9
|
StrandConnectionOptions, SereusPluginResult, StrandTransactor, Libp2pNodeWithRepo,
|
|
@@ -39,6 +39,11 @@ export function offlineControllerOf(db: Database): StrandOfflineController | und
|
|
|
39
39
|
*/
|
|
40
40
|
interface CollectionFactory {
|
|
41
41
|
registerLibp2pNode(networkName: string, node: Libp2p, coordinatedRepo: IRepo): void;
|
|
42
|
+
/**
|
|
43
|
+
* Register the reachability gate for the transactor under `key` (`${transactor}:${keyNetwork}`),
|
|
44
|
+
* replacing the node's own, which the network transactor registers unless one is here first.
|
|
45
|
+
*/
|
|
46
|
+
registerCohortReachability(key: string, reachability: ICohortReachability): void;
|
|
42
47
|
/** Releases the read caches and network watches; leaves every registered node running. */
|
|
43
48
|
dispose(): Promise<void>;
|
|
44
49
|
/** {@link dispose}, after stopping every registered node. */
|
|
@@ -64,8 +69,8 @@ async function releaseOptimysticPlugin(plugin: OptimysticPluginResult, createdNo
|
|
|
64
69
|
await plugin.offline.dispose();
|
|
65
70
|
// NOTE: the bridge's follower re-subscribes at the start of any transaction, so a write begun on
|
|
66
71
|
// this `Database` after release (before its owner closes it) subscribes again and nothing
|
|
67
|
-
// releases it. cadre-core
|
|
68
|
-
//
|
|
72
|
+
// releases it. cadre-core awaits `db.close()` before releasing, so no write can begin; the leak
|
|
73
|
+
// remains only for a host that releases first. If one shows it, have that host close first.
|
|
69
74
|
plugin.txnBridge.dispose();
|
|
70
75
|
const { collectionFactory } = plugin;
|
|
71
76
|
if (!createdNode) {
|
|
@@ -355,6 +360,14 @@ export async function composeStrand(
|
|
|
355
360
|
log('Registered libp2p node with collection factory');
|
|
356
361
|
}
|
|
357
362
|
|
|
363
|
+
// The caller's reachability gate, under the key the factory derives from the vtab args set
|
|
364
|
+
// in step 4 (`${transactor}:${keyNetwork}`). Before hydrate, so no table opens on the node's
|
|
365
|
+
// own gate first.
|
|
366
|
+
if (options.cohortReachability) {
|
|
367
|
+
collectionFactory.registerCohortReachability(`${resolvedTransactor}:libp2p`, options.cohortReachability);
|
|
368
|
+
log('Registered the caller\'s cohort reachability gate for strand %s', strandId);
|
|
369
|
+
}
|
|
370
|
+
|
|
358
371
|
// 4. Set optimystic as default vtab so `declare schema` tables use it.
|
|
359
372
|
db.setDefaultVtabName('optimystic');
|
|
360
373
|
db.setDefaultVtabArgs({
|
|
@@ -421,9 +434,8 @@ export async function composeStrand(
|
|
|
421
434
|
// is a note for whoever first ships a migration that does.
|
|
422
435
|
//
|
|
423
436
|
// The exception: an apply refused by queued offline transactions, or because the strand's
|
|
424
|
-
// cohort could not be reached, does not fail the connect
|
|
425
|
-
//
|
|
426
|
-
// `applyAppSchemaOrDefer`).
|
|
437
|
+
// cohort could not be reached, does not fail the connect, and is retried as the queue drains
|
|
438
|
+
// or when a peer connects. See `applyAppSchemaOrDefer`, including what `db` holds meanwhile.
|
|
427
439
|
if (schema) {
|
|
428
440
|
log('Applying sApp schema for strand %s', strandId);
|
|
429
441
|
appSchemaApply = await applyAppSchemaOrDefer(db, schema, { queue: pluginResult.offline, peers }, released.signal);
|
|
@@ -452,9 +464,11 @@ export async function composeStrand(
|
|
|
452
464
|
...appSchemaApply,
|
|
453
465
|
async shutdown() {
|
|
454
466
|
log('Shutting down strand connection %s', strandId);
|
|
455
|
-
// NOTE: a deferred sApp schema apply already running is not awaited
|
|
456
|
-
//
|
|
457
|
-
// that
|
|
467
|
+
// NOTE: a deferred sApp schema apply already running is not awaited. A host that closes the
|
|
468
|
+
// `Database` first (cadre-core) has stopped it there, and `appSchema` settles `failed`; for one
|
|
469
|
+
// that does not, it runs on against the released plugin, Quereus unwinds it when it fails, and
|
|
470
|
+
// `appSchema` settles `cancelled`. If that ever leaves a catalog write landing after close,
|
|
471
|
+
// await `appSchema` here first.
|
|
458
472
|
released.abort();
|
|
459
473
|
offlineControllers.delete(db);
|
|
460
474
|
await releaseOptimysticPlugin(pluginResult, createdNode);
|
|
@@ -515,6 +529,9 @@ async function registerStrandPlugins(
|
|
|
515
529
|
const storage = strand.storage;
|
|
516
530
|
pluginConfig.rawStorageFactory = () => storage;
|
|
517
531
|
}
|
|
532
|
+
// NOTE: `cost_profile` is left at upstream's default, `distributed` on the network transactor. A
|
|
533
|
+
// strand keeps each block on `DEFAULT_STRAND_CLUSTER_SIZE` machines, so in a larger party a read
|
|
534
|
+
// can leave the machine; a smaller one pays planner overhead, never a wrong result.
|
|
518
535
|
// NOTE: `networkCommitTimeoutMs` is left at upstream's default (five minutes); nothing was
|
|
519
536
|
// measured to choose another. A network-acknowledged commit made while transactions are queued
|
|
520
537
|
// (any `Strand` write, all of them tagged 'network') waits that long behind them holding
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export { connectToStrand } from './connect.js';
|
|
2
|
-
export { offlineControllerOf } from './compose-strand.js';
|
|
3
|
-
export { applyAppSchema } from './app-schema.js';
|
|
4
|
-
export { createEmptyCollections, type CollectionRegistrySource } from './empty-collections.js';
|
|
5
|
-
export {
|
|
6
|
-
MIN_CLUSTER_SIZE,
|
|
7
|
-
COHORT_READ_DEADLINE_MS,
|
|
8
|
-
CONTROL_REPLICATION_BREADTH,
|
|
9
|
-
CONTROL_CLUSTER_POLICY,
|
|
10
|
-
DEFAULT_STRAND_CLUSTER_SIZE,
|
|
11
|
-
STRAND_CLUSTER_POLICY,
|
|
12
|
-
resolveStrandClusterSize,
|
|
13
|
-
resolveRepairYardstick,
|
|
14
|
-
controlClusterPolicy,
|
|
15
|
-
strandClusterPolicy
|
|
16
|
-
} from './cluster-size.js';
|
|
17
|
-
export { wrapStorageWithCache, disposeStorageCache } from './cached-storage.js';
|
|
18
|
-
export type {
|
|
19
|
-
StrandConnectionOptions, SereusPluginResult, StrandTransactor, StrandOfflineOptions, StrandOfflineController, AppSchemaOutcome, AppSchemaWait,
|
|
20
|
-
} from './types.js';
|
|
21
|
-
export type { SqlCommitDurability, CommitFullyHeld } from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
22
|
-
export {
|
|
23
|
-
OfflineCommitTimeoutError,
|
|
24
|
-
QueuedEntriesBlockSchemaChangeError,
|
|
25
|
-
EntryNotDiscardableError,
|
|
26
|
-
UnknownEntryError,
|
|
27
|
-
QueueDisposedError,
|
|
28
|
-
OfflineJournalError,
|
|
29
|
-
} from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
30
|
-
export type { QueuedTransactionStatus, OfflineModeState, CommitOutlook } from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
1
|
+
export { connectToStrand } from './connect.js';
|
|
2
|
+
export { offlineControllerOf } from './compose-strand.js';
|
|
3
|
+
export { applyAppSchema, AppSchemaRefusedError, appSchemaRefusalOf } from './app-schema.js';
|
|
4
|
+
export { createEmptyCollections, type CollectionRegistrySource } from './empty-collections.js';
|
|
5
|
+
export {
|
|
6
|
+
MIN_CLUSTER_SIZE,
|
|
7
|
+
COHORT_READ_DEADLINE_MS,
|
|
8
|
+
CONTROL_REPLICATION_BREADTH,
|
|
9
|
+
CONTROL_CLUSTER_POLICY,
|
|
10
|
+
DEFAULT_STRAND_CLUSTER_SIZE,
|
|
11
|
+
STRAND_CLUSTER_POLICY,
|
|
12
|
+
resolveStrandClusterSize,
|
|
13
|
+
resolveRepairYardstick,
|
|
14
|
+
controlClusterPolicy,
|
|
15
|
+
strandClusterPolicy
|
|
16
|
+
} from './cluster-size.js';
|
|
17
|
+
export { wrapStorageWithCache, disposeStorageCache } from './cached-storage.js';
|
|
18
|
+
export type {
|
|
19
|
+
StrandConnectionOptions, SereusPluginResult, StrandTransactor, StrandOfflineOptions, StrandOfflineController, AppSchemaOutcome, AppSchemaWait,
|
|
20
|
+
} from './types.js';
|
|
21
|
+
export type { SqlCommitDurability, CommitFullyHeld } from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
22
|
+
export {
|
|
23
|
+
OfflineCommitTimeoutError,
|
|
24
|
+
QueuedEntriesBlockSchemaChangeError,
|
|
25
|
+
EntryNotDiscardableError,
|
|
26
|
+
UnknownEntryError,
|
|
27
|
+
QueueDisposedError,
|
|
28
|
+
OfflineJournalError,
|
|
29
|
+
} from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
30
|
+
export type { QueuedTransactionStatus, OfflineModeState, CommitOutlook } from '@optimystic/quereus-plugin-optimystic/plugin';
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Libp2p } from '@libp2p/interface';
|
|
2
|
-
import type { IRepo } from '@optimystic/db-core';
|
|
2
|
+
import type { ICohortReachability, IRepo } from '@optimystic/db-core';
|
|
3
3
|
import type { IRawStorage } from '@optimystic/db-p2p';
|
|
4
4
|
import type { SqlCommitDurabilityListener, CommitFullyHeldListener, OfflineConfig, OfflineMode } from '@optimystic/quereus-plugin-optimystic/plugin';
|
|
5
5
|
|
|
@@ -79,6 +79,14 @@ export interface StrandConnectionOptions {
|
|
|
79
79
|
* {@link SereusPluginResult.offline}. Programmatic only — the SQL plugin config cannot carry it.
|
|
80
80
|
*/
|
|
81
81
|
offline?: StrandOfflineOptions;
|
|
82
|
+
/**
|
|
83
|
+
* The gate this connection's offline queue and offline live reads ask, in place of the node's
|
|
84
|
+
* own `cohortReachability` (Optimystic's `docs/offline-sync.md` → "When to submit"). Registered
|
|
85
|
+
* with the collection factory before any table opens, so every table takes it. cadre-core passes
|
|
86
|
+
* a gate that also waits for the party's own machines (docs/strands.md → "Waiting for the party's
|
|
87
|
+
* own machines"). Absent: the node's gate, or the always-open one on a transactor without a cohort.
|
|
88
|
+
*/
|
|
89
|
+
cohortReachability?: ICohortReachability;
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
/**
|
|
@@ -97,6 +105,9 @@ export type StrandOfflineController = Pick<OfflineMode,
|
|
|
97
105
|
'enter' | 'exit' | 'isEntered' | 'whenDrained' | 'onStatus' | 'onQueueState' | 'queueState'
|
|
98
106
|
| 'entries' | 'status' | 'discard' | 'outcomes' | 'acknowledge'>;
|
|
99
107
|
|
|
108
|
+
/** What a deferred sApp schema apply waits for (see {@link SereusPluginResult.appSchemaWaitingFor}). */
|
|
109
|
+
export type AppSchemaWait = 'queue' | 'cohort';
|
|
110
|
+
|
|
100
111
|
/**
|
|
101
112
|
* How a connection's sApp schema apply ended (see {@link SereusPluginResult.appSchema}):
|
|
102
113
|
*
|
|
@@ -106,9 +117,6 @@ export type StrandOfflineController = Pick<OfflineMode,
|
|
|
106
117
|
* before.
|
|
107
118
|
* - `cancelled` — the connection shut down before a deferred retry landed.
|
|
108
119
|
*/
|
|
109
|
-
/** What a deferred sApp schema apply waits for (see {@link SereusPluginResult.appSchemaWaitingFor}). */
|
|
110
|
-
export type AppSchemaWait = 'queue' | 'cohort';
|
|
111
|
-
|
|
112
120
|
export type AppSchemaOutcome =
|
|
113
121
|
| { state: 'applied'; deferred?: true }
|
|
114
122
|
| { state: 'failed'; error: unknown }
|
|
@@ -167,8 +175,8 @@ export interface SereusPluginResult {
|
|
|
167
175
|
* Present when {@link StrandConnectionOptions.schema} was given; never rejects. Resolves
|
|
168
176
|
* `{ state: 'applied' }` at once when the apply succeeded at connect. When queued offline
|
|
169
177
|
* transactions refused it, or the strand's cohort could not be reached, the connection comes up
|
|
170
|
-
*
|
|
171
|
-
*
|
|
178
|
+
* anyway and retries ({@link appSchemaWaitingFor}); this settles when a retry lands, fails
|
|
179
|
+
* otherwise, or {@link shutdown} runs first.
|
|
172
180
|
*/
|
|
173
181
|
appSchema?: Promise<AppSchemaOutcome>;
|
|
174
182
|
/**
|