@serfab/quereus-plugin-sereus 0.10.0 → 0.12.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 +95 -0
- package/dist/cached-storage.js +156 -0
- package/dist/cached-storage.js.map +1 -0
- package/dist/compose-strand.d.ts +16 -3
- package/dist/compose-strand.js +96 -50
- package/dist/compose-strand.js.map +1 -1
- package/dist/connect-browser.js +2 -1
- package/dist/connect-browser.js.map +1 -1
- package/dist/connect.js +2 -1
- package/dist/connect.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 +77326 -74471
- package/dist/plugin-browser.js.map +4 -4
- package/dist/strand-schema.d.ts +1 -1
- package/dist/strand-schema.js +544 -503
- package/dist/strand-schema.js.map +1 -1
- package/dist/types.d.ts +37 -10
- package/package.json +8 -8
- package/src/cached-storage.ts +178 -0
- package/src/cluster-size.ts +248 -248
- package/src/compose-strand.ts +396 -325
- package/src/connect-browser.ts +2 -1
- package/src/connect.ts +2 -1
- 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 +574 -533
- package/src/types.ts +106 -78
package/src/connect-browser.ts
CHANGED
|
@@ -42,7 +42,7 @@ export async function connectToStrandBrowser(
|
|
|
42
42
|
const dbHandle = await openOptimysticWebDb(`sereus-strand-${strandId}`);
|
|
43
43
|
return new IndexedDBRawStorage(dbHandle);
|
|
44
44
|
},
|
|
45
|
-
async createNode({ networkName, bootstrapNodes, fretProfile, clusterSize, storage }) {
|
|
45
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, clusterSize, clusterPolicy, storage }) {
|
|
46
46
|
return createLibp2pNode({
|
|
47
47
|
transports: [webSockets(), circuitRelayTransport()],
|
|
48
48
|
listenAddrs: [],
|
|
@@ -50,6 +50,7 @@ export async function connectToStrandBrowser(
|
|
|
50
50
|
networkName,
|
|
51
51
|
fretProfile,
|
|
52
52
|
clusterSize,
|
|
53
|
+
clusterPolicy,
|
|
53
54
|
...(storage && { storage }),
|
|
54
55
|
}) as Promise<Libp2p>;
|
|
55
56
|
},
|
package/src/connect.ts
CHANGED
|
@@ -20,7 +20,7 @@ export async function connectToStrand(
|
|
|
20
20
|
async registerCrypto(database) {
|
|
21
21
|
await registerPlugin(database, cryptoPlugin);
|
|
22
22
|
},
|
|
23
|
-
async createNode({ networkName, bootstrapNodes, fretProfile, port, clusterSize, storage }) {
|
|
23
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, port, clusterSize, clusterPolicy, storage }) {
|
|
24
24
|
// Dynamically import to keep the module cross-platform friendly: this
|
|
25
25
|
// pulls the Node-only `@optimystic/db-p2p` (TCP) entry, and is only
|
|
26
26
|
// reached when actually creating a node (never for injected nodes).
|
|
@@ -31,6 +31,7 @@ export async function connectToStrand(
|
|
|
31
31
|
networkName,
|
|
32
32
|
fretProfile,
|
|
33
33
|
clusterSize,
|
|
34
|
+
clusterPolicy,
|
|
34
35
|
...(storage && { storage }),
|
|
35
36
|
}) as Promise<Libp2p>;
|
|
36
37
|
},
|
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
|
+
}
|