@serfab/quereus-plugin-sereus 1.21.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 +20 -2
- package/dist/app-schema.js +87 -12
- package/dist/app-schema.js.map +1 -1
- package/dist/compose-strand.js +14 -5
- 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 +9 -1
- package/package.json +8 -8
- package/src/app-schema.ts +397 -318
- package/src/compose-strand.ts +21 -6
- package/src/index.ts +30 -30
- package/src/types.ts +9 -1
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({
|
|
@@ -451,9 +464,11 @@ export async function composeStrand(
|
|
|
451
464
|
...appSchemaApply,
|
|
452
465
|
async shutdown() {
|
|
453
466
|
log('Shutting down strand connection %s', strandId);
|
|
454
|
-
// NOTE: a deferred sApp schema apply already running is not awaited
|
|
455
|
-
//
|
|
456
|
-
// 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.
|
|
457
472
|
released.abort();
|
|
458
473
|
offlineControllers.delete(db);
|
|
459
474
|
await releaseOptimysticPlugin(pluginResult, createdNode);
|
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
|
/**
|