@serfab/quereus-plugin-sereus 0.10.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/README.md +367 -361
- package/dist/cached-storage.d.ts +66 -0
- package/dist/cached-storage.js +103 -0
- package/dist/cached-storage.js.map +1 -0
- package/dist/compose-strand.d.ts +2 -2
- package/dist/compose-strand.js +18 -22
- package/dist/compose-strand.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/parse-config.js +23 -11
- package/dist/parse-config.js.map +1 -1
- package/dist/plugin-browser.js +15040 -11647
- package/dist/plugin-browser.js.map +4 -4
- package/dist/strand-schema.js +503 -503
- package/dist/types.d.ts +37 -10
- package/package.json +8 -8
- package/src/cached-storage.ts +107 -0
- package/src/cluster-size.ts +248 -248
- package/src/compose-strand.ts +21 -23
- package/src/connect-browser.ts +57 -57
- package/src/connect.ts +38 -38
- package/src/index.ts +2 -1
- package/src/parse-config.ts +70 -55
- package/src/plugin-browser.ts +29 -29
- package/src/plugin.ts +39 -39
- package/src/strand-schema.ts +533 -533
- package/src/types.ts +106 -78
package/src/connect-browser.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import type { Database, VTablePluginInfo, FunctionPluginInfo, CollationPluginInfo } from '@quereus/quereus';
|
|
2
|
-
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
3
|
-
import { createLibp2pNode } from '@optimystic/db-p2p/rn';
|
|
4
|
-
import { webSockets } from '@libp2p/websockets';
|
|
5
|
-
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
6
|
-
import { IndexedDBRawStorage, openOptimysticWebDb } from '@optimystic/db-p2p-storage-web';
|
|
7
|
-
import type { Libp2p } from '@libp2p/interface';
|
|
8
|
-
import type { StrandConnectionOptions, SereusPluginResult } from './types.js';
|
|
9
|
-
import { composeStrand, applyRegistrations } from './compose-strand.js';
|
|
10
|
-
|
|
11
|
-
/** The subset of the crypto plugin result we register inline in the browser. */
|
|
12
|
-
interface CryptoPluginResult {
|
|
13
|
-
vtables: VTablePluginInfo[];
|
|
14
|
-
functions: FunctionPluginInfo[];
|
|
15
|
-
collations: CollationPluginInfo[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Connect a Quereus Database to a Sereus strand from a browser/worker.
|
|
20
|
-
*
|
|
21
|
-
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
22
|
-
* browser platform seams:
|
|
23
|
-
* - crypto registered inline (no runtime `@quereus/quereus` import, so the
|
|
24
|
-
* bundle does not duplicate the host's instance),
|
|
25
|
-
* - storage defaulting to `IndexedDBRawStorage` keyed by `sereus-strand-<id>`,
|
|
26
|
-
* - a node created via the TCP-free `@optimystic/db-p2p/rn` entry with explicit
|
|
27
|
-
* `webSockets()` + `circuitRelayTransport()` transports.
|
|
28
|
-
*/
|
|
29
|
-
export async function connectToStrandBrowser(
|
|
30
|
-
db: Database,
|
|
31
|
-
options: StrandConnectionOptions,
|
|
32
|
-
): Promise<SereusPluginResult> {
|
|
33
|
-
return composeStrand(db, options, {
|
|
34
|
-
registerCrypto(database) {
|
|
35
|
-
applyRegistrations(database, cryptoPlugin(database, {}) as unknown as CryptoPluginResult);
|
|
36
|
-
},
|
|
37
|
-
async resolveStorage({ strandId, resolvedTransactor, requestedStorage }) {
|
|
38
|
-
if (requestedStorage) return requestedStorage;
|
|
39
|
-
// Browsers always default to IndexedDB so a reload survives; the
|
|
40
|
-
// unit-test fake transactor needs no storage.
|
|
41
|
-
if (resolvedTransactor === 'test') return undefined;
|
|
42
|
-
const dbHandle = await openOptimysticWebDb(`sereus-strand-${strandId}`);
|
|
43
|
-
return new IndexedDBRawStorage(dbHandle);
|
|
44
|
-
},
|
|
45
|
-
async createNode({ networkName, bootstrapNodes, fretProfile, clusterSize, storage }) {
|
|
46
|
-
return createLibp2pNode({
|
|
47
|
-
transports: [webSockets(), circuitRelayTransport()],
|
|
48
|
-
listenAddrs: [],
|
|
49
|
-
bootstrapNodes,
|
|
50
|
-
networkName,
|
|
51
|
-
fretProfile,
|
|
52
|
-
clusterSize,
|
|
53
|
-
...(storage && { storage }),
|
|
54
|
-
}) as Promise<Libp2p>;
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
1
|
+
import type { Database, VTablePluginInfo, FunctionPluginInfo, CollationPluginInfo } from '@quereus/quereus';
|
|
2
|
+
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
3
|
+
import { createLibp2pNode } from '@optimystic/db-p2p/rn';
|
|
4
|
+
import { webSockets } from '@libp2p/websockets';
|
|
5
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
6
|
+
import { IndexedDBRawStorage, openOptimysticWebDb } from '@optimystic/db-p2p-storage-web';
|
|
7
|
+
import type { Libp2p } from '@libp2p/interface';
|
|
8
|
+
import type { StrandConnectionOptions, SereusPluginResult } from './types.js';
|
|
9
|
+
import { composeStrand, applyRegistrations } from './compose-strand.js';
|
|
10
|
+
|
|
11
|
+
/** The subset of the crypto plugin result we register inline in the browser. */
|
|
12
|
+
interface CryptoPluginResult {
|
|
13
|
+
vtables: VTablePluginInfo[];
|
|
14
|
+
functions: FunctionPluginInfo[];
|
|
15
|
+
collations: CollationPluginInfo[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Connect a Quereus Database to a Sereus strand from a browser/worker.
|
|
20
|
+
*
|
|
21
|
+
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
22
|
+
* browser platform seams:
|
|
23
|
+
* - crypto registered inline (no runtime `@quereus/quereus` import, so the
|
|
24
|
+
* bundle does not duplicate the host's instance),
|
|
25
|
+
* - storage defaulting to `IndexedDBRawStorage` keyed by `sereus-strand-<id>`,
|
|
26
|
+
* - a node created via the TCP-free `@optimystic/db-p2p/rn` entry with explicit
|
|
27
|
+
* `webSockets()` + `circuitRelayTransport()` transports.
|
|
28
|
+
*/
|
|
29
|
+
export async function connectToStrandBrowser(
|
|
30
|
+
db: Database,
|
|
31
|
+
options: StrandConnectionOptions,
|
|
32
|
+
): Promise<SereusPluginResult> {
|
|
33
|
+
return composeStrand(db, options, {
|
|
34
|
+
registerCrypto(database) {
|
|
35
|
+
applyRegistrations(database, cryptoPlugin(database, {}) as unknown as CryptoPluginResult);
|
|
36
|
+
},
|
|
37
|
+
async resolveStorage({ strandId, resolvedTransactor, requestedStorage }) {
|
|
38
|
+
if (requestedStorage) return requestedStorage;
|
|
39
|
+
// Browsers always default to IndexedDB so a reload survives; the
|
|
40
|
+
// unit-test fake transactor needs no storage.
|
|
41
|
+
if (resolvedTransactor === 'test') return undefined;
|
|
42
|
+
const dbHandle = await openOptimysticWebDb(`sereus-strand-${strandId}`);
|
|
43
|
+
return new IndexedDBRawStorage(dbHandle);
|
|
44
|
+
},
|
|
45
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, clusterSize, storage }) {
|
|
46
|
+
return createLibp2pNode({
|
|
47
|
+
transports: [webSockets(), circuitRelayTransport()],
|
|
48
|
+
listenAddrs: [],
|
|
49
|
+
bootstrapNodes,
|
|
50
|
+
networkName,
|
|
51
|
+
fretProfile,
|
|
52
|
+
clusterSize,
|
|
53
|
+
...(storage && { storage }),
|
|
54
|
+
}) as Promise<Libp2p>;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
package/src/connect.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import type { Database } from '@quereus/quereus';
|
|
2
|
-
import { registerPlugin } from '@quereus/quereus';
|
|
3
|
-
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
4
|
-
import type { Libp2p } from '@libp2p/interface';
|
|
5
|
-
import type { StrandConnectionOptions, SereusPluginResult } from './types.js';
|
|
6
|
-
import { composeStrand } from './compose-strand.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Connect a Quereus Database to a Sereus strand (Node).
|
|
10
|
-
*
|
|
11
|
-
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
12
|
-
* Node platform seams: crypto via `@quereus/quereus`'s `registerPlugin`, and a
|
|
13
|
-
* TCP libp2p node created (only when not injected) via `@optimystic/db-p2p`.
|
|
14
|
-
*/
|
|
15
|
-
export async function connectToStrand(
|
|
16
|
-
db: Database,
|
|
17
|
-
options: StrandConnectionOptions,
|
|
18
|
-
): Promise<SereusPluginResult> {
|
|
19
|
-
return composeStrand(db, options, {
|
|
20
|
-
async registerCrypto(database) {
|
|
21
|
-
await registerPlugin(database, cryptoPlugin);
|
|
22
|
-
},
|
|
23
|
-
async createNode({ networkName, bootstrapNodes, fretProfile, port, clusterSize, storage }) {
|
|
24
|
-
// Dynamically import to keep the module cross-platform friendly: this
|
|
25
|
-
// pulls the Node-only `@optimystic/db-p2p` (TCP) entry, and is only
|
|
26
|
-
// reached when actually creating a node (never for injected nodes).
|
|
27
|
-
const { createLibp2pNode } = await import('@optimystic/db-p2p');
|
|
28
|
-
return createLibp2pNode({
|
|
29
|
-
port,
|
|
30
|
-
bootstrapNodes,
|
|
31
|
-
networkName,
|
|
32
|
-
fretProfile,
|
|
33
|
-
clusterSize,
|
|
34
|
-
...(storage && { storage }),
|
|
35
|
-
}) as Promise<Libp2p>;
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
1
|
+
import type { Database } from '@quereus/quereus';
|
|
2
|
+
import { registerPlugin } from '@quereus/quereus';
|
|
3
|
+
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
4
|
+
import type { Libp2p } from '@libp2p/interface';
|
|
5
|
+
import type { StrandConnectionOptions, SereusPluginResult } from './types.js';
|
|
6
|
+
import { composeStrand } from './compose-strand.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connect a Quereus Database to a Sereus strand (Node).
|
|
10
|
+
*
|
|
11
|
+
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
12
|
+
* Node platform seams: crypto via `@quereus/quereus`'s `registerPlugin`, and a
|
|
13
|
+
* TCP libp2p node created (only when not injected) via `@optimystic/db-p2p`.
|
|
14
|
+
*/
|
|
15
|
+
export async function connectToStrand(
|
|
16
|
+
db: Database,
|
|
17
|
+
options: StrandConnectionOptions,
|
|
18
|
+
): Promise<SereusPluginResult> {
|
|
19
|
+
return composeStrand(db, options, {
|
|
20
|
+
async registerCrypto(database) {
|
|
21
|
+
await registerPlugin(database, cryptoPlugin);
|
|
22
|
+
},
|
|
23
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, port, clusterSize, storage }) {
|
|
24
|
+
// Dynamically import to keep the module cross-platform friendly: this
|
|
25
|
+
// pulls the Node-only `@optimystic/db-p2p` (TCP) entry, and is only
|
|
26
|
+
// reached when actually creating a node (never for injected nodes).
|
|
27
|
+
const { createLibp2pNode } = await import('@optimystic/db-p2p');
|
|
28
|
+
return createLibp2pNode({
|
|
29
|
+
port,
|
|
30
|
+
bootstrapNodes,
|
|
31
|
+
networkName,
|
|
32
|
+
fretProfile,
|
|
33
|
+
clusterSize,
|
|
34
|
+
...(storage && { storage }),
|
|
35
|
+
}) as Promise<Libp2p>;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,4 +7,5 @@ export {
|
|
|
7
7
|
STRAND_CLUSTER_POLICY,
|
|
8
8
|
resolveStrandClusterSize
|
|
9
9
|
} from './cluster-size.js';
|
|
10
|
-
export
|
|
10
|
+
export { wrapStorageWithCache, disposeStorageCache } from './cached-storage.js';
|
|
11
|
+
export type { StrandConnectionOptions, SereusPluginResult, StrandTransactor } from './types.js';
|
package/src/parse-config.ts
CHANGED
|
@@ -1,55 +1,70 @@
|
|
|
1
|
-
import type { SqlValue } from '@quereus/quereus';
|
|
2
|
-
import type { StrandConnectionOptions } from './types.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
import type { SqlValue } from '@quereus/quereus';
|
|
2
|
+
import type { StrandConnectionOptions, StrandTransactor } from './types.js';
|
|
3
|
+
|
|
4
|
+
const STRAND_TRANSACTORS: readonly StrandTransactor[] = ['local', 'network', 'test'];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Read the optional `transactor` key. Unlike `fret_profile` (whose unknown
|
|
8
|
+
* values fall back to the default), an unrecognised transactor throws: silently
|
|
9
|
+
* running on the network when the caller asked for local storage is the kind of
|
|
10
|
+
* mistake that only surfaces as a mysterious hang on a machine with no peers.
|
|
11
|
+
*/
|
|
12
|
+
function parseTransactor(raw: SqlValue): StrandTransactor | undefined {
|
|
13
|
+
if (raw === undefined || raw === null || raw === '') return undefined;
|
|
14
|
+
if (typeof raw !== 'string' || !STRAND_TRANSACTORS.includes(raw as StrandTransactor)) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`quereus-plugin-sereus: transactor must be one of ${STRAND_TRANSACTORS.join(', ')} (got ${JSON.stringify(raw)})`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return raw as StrandTransactor;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse the plugin-loader SqlValue config into typed StrandConnectionOptions.
|
|
24
|
+
* Shared by the Node (`plugin.ts`) and browser (`plugin-browser.ts`) entries.
|
|
25
|
+
*/
|
|
26
|
+
export function parseConfig(config: Record<string, SqlValue>): StrandConnectionOptions {
|
|
27
|
+
const strandId = config.strand_id;
|
|
28
|
+
if (typeof strandId !== 'string' || !strandId) {
|
|
29
|
+
throw new Error('quereus-plugin-sereus: strand_id is required');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const bootstrapNodesRaw = config.bootstrap_nodes;
|
|
33
|
+
const bootstrapNodes = typeof bootstrapNodesRaw === 'string' && bootstrapNodesRaw
|
|
34
|
+
? bootstrapNodesRaw.split(',').map(s => s.trim()).filter(Boolean)
|
|
35
|
+
: [];
|
|
36
|
+
|
|
37
|
+
const schema = typeof config.schema === 'string' ? config.schema : undefined;
|
|
38
|
+
const sAppId = typeof config.sapp_id === 'string' ? config.sapp_id : 'unknown';
|
|
39
|
+
const sAppVersion = typeof config.sapp_version === 'string' ? config.sapp_version : '1.0.0';
|
|
40
|
+
const port = typeof config.port === 'number' ? config.port : 0;
|
|
41
|
+
const enableCache = config.enable_cache !== false && config.enable_cache !== 0;
|
|
42
|
+
const fretProfile = config.fret_profile === 'core' ? 'core' as const : 'edge' as const;
|
|
43
|
+
|
|
44
|
+
// Storage engine — see `StrandConnectionOptions.transactor`. Left out entirely
|
|
45
|
+
// when unset so `composeStrand` applies its own default.
|
|
46
|
+
const transactor = parseTransactor(config.transactor);
|
|
47
|
+
|
|
48
|
+
// NOTE: `parseConfig` reads the keys it knows and ignores every other key in
|
|
49
|
+
// the map — there is no allowlist, so a misspelled or retired setting (e.g.
|
|
50
|
+
// the `mode` this package used to carry) is silently dropped rather than
|
|
51
|
+
// rejected. Deliberate: the plugin loader hands through whatever the host's
|
|
52
|
+
// settings file holds.
|
|
53
|
+
|
|
54
|
+
// NOTE: persistent storage cannot ride a `Record<string, SqlValue>` — an
|
|
55
|
+
// `IRawStorage` is not an `SqlValue`. The Node loader (`plugin.ts`) reads the
|
|
56
|
+
// platform-only `storage_path` key directly and resolves it to a concrete
|
|
57
|
+
// `FileRawStorage`; it is intentionally NOT parsed into the typed options here.
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
strandId,
|
|
61
|
+
bootstrapNodes,
|
|
62
|
+
schema,
|
|
63
|
+
sAppId,
|
|
64
|
+
sAppVersion,
|
|
65
|
+
port,
|
|
66
|
+
enableCache,
|
|
67
|
+
fretProfile,
|
|
68
|
+
...(transactor && { transactor }),
|
|
69
|
+
};
|
|
70
|
+
}
|
package/src/plugin-browser.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Quereus plugin entry point for Sereus strand connections (browser/worker).
|
|
3
|
-
*
|
|
4
|
-
* This is the ESM-bundled counterpart to `./plugin`. Load via Quoomb-web's
|
|
5
|
-
* plugin URL field or `plugins[].source` in `quoomb.config.json`. Defaults
|
|
6
|
-
* storage to IndexedDB and uses WebSockets + circuit-relay transports.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Database, SqlValue } from '@quereus/quereus';
|
|
10
|
-
import { connectToStrandBrowser } from './connect-browser.js';
|
|
11
|
-
import { parseConfig } from './parse-config.js';
|
|
12
|
-
import type { SereusPluginResult } from './types.js';
|
|
13
|
-
|
|
14
|
-
export { parseConfig };
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Default export: Quereus plugin registration function (browser).
|
|
18
|
-
*
|
|
19
|
-
* Note: the `storage_path` setting is Node-only (it resolves to a filesystem
|
|
20
|
-
* `FileRawStorage` in `./plugin`). The browser entry ignores it and defaults
|
|
21
|
-
* storage to IndexedDB via `connectToStrandBrowser`.
|
|
22
|
-
*/
|
|
23
|
-
export default async function register(
|
|
24
|
-
db: Database,
|
|
25
|
-
config: Record<string, SqlValue> = {},
|
|
26
|
-
): Promise<SereusPluginResult> {
|
|
27
|
-
const options = parseConfig(config);
|
|
28
|
-
return connectToStrandBrowser(db, options);
|
|
29
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Quereus plugin entry point for Sereus strand connections (browser/worker).
|
|
3
|
+
*
|
|
4
|
+
* This is the ESM-bundled counterpart to `./plugin`. Load via Quoomb-web's
|
|
5
|
+
* plugin URL field or `plugins[].source` in `quoomb.config.json`. Defaults
|
|
6
|
+
* storage to IndexedDB and uses WebSockets + circuit-relay transports.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Database, SqlValue } from '@quereus/quereus';
|
|
10
|
+
import { connectToStrandBrowser } from './connect-browser.js';
|
|
11
|
+
import { parseConfig } from './parse-config.js';
|
|
12
|
+
import type { SereusPluginResult } from './types.js';
|
|
13
|
+
|
|
14
|
+
export { parseConfig };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default export: Quereus plugin registration function (browser).
|
|
18
|
+
*
|
|
19
|
+
* Note: the `storage_path` setting is Node-only (it resolves to a filesystem
|
|
20
|
+
* `FileRawStorage` in `./plugin`). The browser entry ignores it and defaults
|
|
21
|
+
* storage to IndexedDB via `connectToStrandBrowser`.
|
|
22
|
+
*/
|
|
23
|
+
export default async function register(
|
|
24
|
+
db: Database,
|
|
25
|
+
config: Record<string, SqlValue> = {},
|
|
26
|
+
): Promise<SereusPluginResult> {
|
|
27
|
+
const options = parseConfig(config);
|
|
28
|
+
return connectToStrandBrowser(db, options);
|
|
29
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Quereus plugin entry point for Sereus strand connections (Node).
|
|
3
|
-
*
|
|
4
|
-
* Loaded via Quoomb's `.plugin install` or config file, or via `registerPlugin()`.
|
|
5
|
-
* Parses SqlValue config and delegates to `connectToStrand`.
|
|
6
|
-
*
|
|
7
|
-
* Browser/Worker consumers should load `./plugin-browser` instead, which uses
|
|
8
|
-
* the TCP-free libp2p entry and IndexedDB-backed default storage.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { Database, SqlValue } from '@quereus/quereus';
|
|
12
|
-
import { connectToStrand } from './connect.js';
|
|
13
|
-
import { parseConfig } from './parse-config.js';
|
|
14
|
-
import type { SereusPluginResult } from './types.js';
|
|
15
|
-
|
|
16
|
-
export { parseConfig };
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Default export: Quereus plugin registration function.
|
|
20
|
-
*/
|
|
21
|
-
export default async function register(
|
|
22
|
-
db: Database,
|
|
23
|
-
config: Record<string, SqlValue> = {},
|
|
24
|
-
): Promise<SereusPluginResult> {
|
|
25
|
-
const options = parseConfig(config);
|
|
26
|
-
|
|
27
|
-
// `storage_path` is a Node-only loader convenience: a `Record<string, SqlValue>`
|
|
28
|
-
// cannot carry an `IRawStorage`, so the path is resolved to a concrete
|
|
29
|
-
// `FileRawStorage` here (not in the platform-agnostic `parseConfig`). The
|
|
30
|
-
// dynamic import keeps `@optimystic/db-p2p-storage-fs` (and its `node:fs`
|
|
31
|
-
// dependency) out of the browser/RN module graph.
|
|
32
|
-
const storagePath = config.storage_path;
|
|
33
|
-
if (typeof storagePath === 'string' && storagePath) {
|
|
34
|
-
const { FileRawStorage } = await import('@optimystic/db-p2p-storage-fs');
|
|
35
|
-
options.storage = new FileRawStorage(storagePath);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return connectToStrand(db, options);
|
|
39
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Quereus plugin entry point for Sereus strand connections (Node).
|
|
3
|
+
*
|
|
4
|
+
* Loaded via Quoomb's `.plugin install` or config file, or via `registerPlugin()`.
|
|
5
|
+
* Parses SqlValue config and delegates to `connectToStrand`.
|
|
6
|
+
*
|
|
7
|
+
* Browser/Worker consumers should load `./plugin-browser` instead, which uses
|
|
8
|
+
* the TCP-free libp2p entry and IndexedDB-backed default storage.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Database, SqlValue } from '@quereus/quereus';
|
|
12
|
+
import { connectToStrand } from './connect.js';
|
|
13
|
+
import { parseConfig } from './parse-config.js';
|
|
14
|
+
import type { SereusPluginResult } from './types.js';
|
|
15
|
+
|
|
16
|
+
export { parseConfig };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Default export: Quereus plugin registration function.
|
|
20
|
+
*/
|
|
21
|
+
export default async function register(
|
|
22
|
+
db: Database,
|
|
23
|
+
config: Record<string, SqlValue> = {},
|
|
24
|
+
): Promise<SereusPluginResult> {
|
|
25
|
+
const options = parseConfig(config);
|
|
26
|
+
|
|
27
|
+
// `storage_path` is a Node-only loader convenience: a `Record<string, SqlValue>`
|
|
28
|
+
// cannot carry an `IRawStorage`, so the path is resolved to a concrete
|
|
29
|
+
// `FileRawStorage` here (not in the platform-agnostic `parseConfig`). The
|
|
30
|
+
// dynamic import keeps `@optimystic/db-p2p-storage-fs` (and its `node:fs`
|
|
31
|
+
// dependency) out of the browser/RN module graph.
|
|
32
|
+
const storagePath = config.storage_path;
|
|
33
|
+
if (typeof storagePath === 'string' && storagePath) {
|
|
34
|
+
const { FileRawStorage } = await import('@optimystic/db-p2p-storage-fs');
|
|
35
|
+
options.storage = new FileRawStorage(storagePath);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return connectToStrand(db, options);
|
|
39
|
+
}
|