@serfab/quereus-plugin-sereus 0.9.0 → 0.11.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/src/types.ts CHANGED
@@ -1,69 +1,106 @@
1
- import type { Libp2p } from '@libp2p/interface';
2
- import type { IRepo } from '@optimystic/db-core';
3
- import type { IRawStorage } from '@optimystic/db-p2p';
4
-
5
- export interface StrandConnectionOptions {
6
- /** UUID of the strand to connect to */
7
- strandId: string;
8
- /** Bootstrap multiaddrs for peer discovery */
9
- bootstrapNodes?: string[];
10
- /** sApp schema DDL to apply (optional - omit if schema already exists on strand) */
11
- schema?: string;
12
- /** sApp author public key */
13
- sAppId?: string;
14
- /** sApp version */
15
- sAppVersion?: string;
16
- /** libp2p listening port (default: 0 = random) */
17
- port?: number;
18
- /** Enable optimystic caching (default: true) */
19
- enableCache?: boolean;
20
- /** FRET profile (default: 'edge') */
21
- fretProfile?: 'edge' | 'core';
22
- /** Inject an existing libp2p node instead of creating one */
23
- libp2pNode?: Libp2p;
24
- /** Required when libp2pNode is provided */
25
- coordinatedRepo?: IRepo;
26
- /**
27
- * Lifecycle mode. `'networked'` (default) uses the network transactor and
28
- * is appropriate for multi-peer participation. `'bootstrap'` switches to a
29
- * local transactor so a solo node can apply schema and accept DML with no
30
- * peer round trips; pair it with a persistent `storage` to survive restart.
31
- */
32
- mode?: 'bootstrap' | 'networked';
33
- /**
34
- * Persistent raw storage. When provided:
35
- * - it is passed to `createLibp2pNode` as `storage` so the libp2p data path uses it,
36
- * - in `bootstrap` mode it is also handed to the optimystic plugin as
37
- * `rawStorageFactory: () => storage` so the local transactor persists DML
38
- * on the same instance (avoids cache divergence between the two consumers).
39
- *
40
- * The plugin treats `storage` as borrowed — it is NOT closed on `shutdown()`.
41
- */
42
- storage?: IRawStorage;
43
- /** @internal Override transactor type. Used by unit tests with `'test'`. When set, takes precedence only if `mode` is not specified. */
44
- transactor?: string;
45
- }
46
-
47
- export interface SereusPluginResult {
48
- vtables: [];
49
- functions: [];
50
- collations: [];
51
- /**
52
- * Catalog-hydration counts from the warm-restart hydrate that runs before
53
- * `apply schema App;`. On a cold start (empty storage) both are 0; on a warm
54
- * restart they report the persisted tables/indexes the catalog was primed
55
- * with — so a test can assert hydration actually ran. `undefined` only if
56
- * composition threw before hydrate.
57
- */
58
- hydrated?: { tables: number; indexes: number };
59
- /** Shuts down the libp2p node and collection factory. Call when done. */
60
- shutdown: () => Promise<void>;
61
- }
62
-
63
- /**
64
- * Extended Libp2p node type with coordinatedRepo attached by createLibp2pNode.
65
- * @internal
66
- */
67
- export interface Libp2pNodeWithRepo extends Libp2p {
68
- coordinatedRepo: IRepo;
69
- }
1
+ import type { Libp2p } from '@libp2p/interface';
2
+ import type { IRepo } from '@optimystic/db-core';
3
+ import type { IRawStorage } from '@optimystic/db-p2p';
4
+
5
+ /**
6
+ * Which Optimystic transactor a strand connection commits through — a choice of
7
+ * storage engine, nothing more. See {@link StrandConnectionOptions.transactor}.
8
+ *
9
+ * Deliberately a closed union, and narrower than what Optimystic's
10
+ * `collection-factory.ts` accepts: that factory also switches on `'mesh-test'`
11
+ * (its production transactor stack over a one-node mock mesh) and falls through
12
+ * to a host-registered custom transactor for any other name. Neither is offered
13
+ * here — `composeStrand`'s node gate special-cases only `'test'`, so
14
+ * `'mesh-test'` would get a real libp2p node it does not want, and nothing in
15
+ * this repo registers a custom transactor. A closed union lets `parseConfig`
16
+ * reject a typo (`'locl'`) instead of handing it downstream; widen it (and the
17
+ * node gate with it) when one of those values is actually needed.
18
+ */
19
+ export type StrandTransactor = 'local' | 'network' | 'test';
20
+
21
+ export interface StrandConnectionOptions {
22
+ /** UUID of the strand to connect to */
23
+ strandId: string;
24
+ /** Bootstrap multiaddrs for peer discovery */
25
+ bootstrapNodes?: string[];
26
+ /** sApp schema DDL to apply (optional - omit if schema already exists on strand) */
27
+ schema?: string;
28
+ /** sApp author public key */
29
+ sAppId?: string;
30
+ /** sApp version */
31
+ sAppVersion?: string;
32
+ /** libp2p listening port (default: 0 = random) */
33
+ port?: number;
34
+ /** Enable optimystic caching (default: true) */
35
+ enableCache?: boolean;
36
+ /** FRET profile (default: 'edge') */
37
+ fretProfile?: 'edge' | 'core';
38
+ /**
39
+ * Number of nodes Optimystic is told this strand's replication cluster should
40
+ * have. Ignored when {@link libp2pNode} is injected (the injected node was
41
+ * built with its own value). Every peer on the strand should use the same
42
+ * number — see `resolveStrandClusterSize`. Defaults to
43
+ * `DEFAULT_STRAND_CLUSTER_SIZE` (4 — the smallest breadth whose 0.75
44
+ * super-majority still commits with one holder offline).
45
+ */
46
+ clusterSize?: number;
47
+ /** Inject an existing libp2p node instead of creating one */
48
+ libp2pNode?: Libp2p;
49
+ /** Required when libp2pNode is provided */
50
+ coordinatedRepo?: IRepo;
51
+ /**
52
+ * Persistent raw storage. When provided:
53
+ * - it is passed to `createLibp2pNode` as `storage` so the libp2p data path uses it,
54
+ * - with `transactor: 'local'` it is also handed to the optimystic plugin as
55
+ * `rawStorageFactory: () => storage` so the local transactor persists DML
56
+ * on the same instance (avoids cache divergence between the two consumers).
57
+ *
58
+ * The plugin treats `storage` as borrowed — it is NOT closed on `shutdown()`.
59
+ */
60
+ storage?: IRawStorage;
61
+ /**
62
+ * Which Optimystic transactor writes and reads go through (default
63
+ * `'network'`):
64
+ *
65
+ * - `'network'` — transactions go through the strand's libp2p cohort. A node
66
+ * that is alone coordinates for itself, so this works with one peer or
67
+ * many; it is the only value an application should use.
68
+ * - `'local'` — transactions go straight to this process's raw storage, no
69
+ * peers consulted. For in-process tests and tooling; pair it with a
70
+ * persistent {@link storage} to survive restart.
71
+ * - `'test'` — Optimystic's in-memory fake. No libp2p node is created unless
72
+ * one is injected. Unit tests only.
73
+ */
74
+ transactor?: StrandTransactor;
75
+ }
76
+
77
+ export interface SereusPluginResult {
78
+ vtables: [];
79
+ functions: [];
80
+ collations: [];
81
+ /**
82
+ * Catalog-hydration counts from the warm-restart hydrate that runs before
83
+ * `apply schema App;`. On a cold start (empty storage) both are 0; on a warm
84
+ * restart they report the persisted tables/indexes the catalog was primed
85
+ * with — so a test can assert hydration actually ran. `undefined` only if
86
+ * composition threw before hydrate.
87
+ */
88
+ hydrated?: { tables: number; indexes: number };
89
+ /**
90
+ * The transactor this connection actually resolved to — the RESOLVED value,
91
+ * not the requested one, so a spec whose whole point is the arm it runs on can
92
+ * assert it rather than assume it. Equals `options.transactor` when one was
93
+ * given, `'network'` otherwise.
94
+ */
95
+ transactor: StrandTransactor;
96
+ /** Shuts down the libp2p node and collection factory. Call when done. */
97
+ shutdown: () => Promise<void>;
98
+ }
99
+
100
+ /**
101
+ * Extended Libp2p node type with coordinatedRepo attached by createLibp2pNode.
102
+ * @internal
103
+ */
104
+ export interface Libp2pNodeWithRepo extends Libp2p {
105
+ coordinatedRepo: IRepo;
106
+ }