@serfab/quereus-plugin-sereus 0.8.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 +360 -0
- package/dist/compose-strand.d.ts +84 -0
- package/dist/compose-strand.js +194 -0
- package/dist/compose-strand.js.map +1 -0
- package/dist/connect-browser.d.ts +14 -0
- package/dist/connect-browser.js +45 -0
- package/dist/connect-browser.js.map +1 -0
- package/dist/connect.d.ts +10 -0
- package/dist/connect.js +31 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/parse-config.d.ts +7 -0
- package/dist/parse-config.js +47 -0
- package/dist/parse-config.js.map +1 -0
- package/dist/plugin-browser.d.ts +19 -0
- package/dist/plugin-browser.js +94664 -0
- package/dist/plugin-browser.js.map +7 -0
- package/dist/plugin.d.ts +17 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/dist/strand-schema.d.ts +30 -0
- package/dist/strand-schema.js +161 -0
- package/dist/strand-schema.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +145 -0
- package/src/compose-strand.ts +314 -0
- package/src/connect-browser.ts +56 -0
- package/src/connect.ts +37 -0
- package/src/index.ts +2 -0
- package/src/parse-config.ts +55 -0
- package/src/plugin-browser.ts +29 -0
- package/src/plugin.ts +39 -0
- package/src/strand-schema.ts +160 -0
- package/src/types.ts +69 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
2
|
+
import { createLibp2pNode } from '@optimystic/db-p2p/rn';
|
|
3
|
+
import { webSockets } from '@libp2p/websockets';
|
|
4
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
5
|
+
import { IndexedDBRawStorage, openOptimysticWebDb } from '@optimystic/db-p2p-storage-web';
|
|
6
|
+
import { composeStrand, applyRegistrations } from './compose-strand.js';
|
|
7
|
+
/**
|
|
8
|
+
* Connect a Quereus Database to a Sereus strand from a browser/worker.
|
|
9
|
+
*
|
|
10
|
+
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
11
|
+
* browser platform seams:
|
|
12
|
+
* - crypto registered inline (no runtime `@quereus/quereus` import, so the
|
|
13
|
+
* bundle does not duplicate the host's instance),
|
|
14
|
+
* - storage defaulting to `IndexedDBRawStorage` keyed by `sereus-strand-<id>`,
|
|
15
|
+
* - a node created via the TCP-free `@optimystic/db-p2p/rn` entry with explicit
|
|
16
|
+
* `webSockets()` + `circuitRelayTransport()` transports.
|
|
17
|
+
*/
|
|
18
|
+
export async function connectToStrandBrowser(db, options) {
|
|
19
|
+
return composeStrand(db, options, {
|
|
20
|
+
registerCrypto(database) {
|
|
21
|
+
applyRegistrations(database, cryptoPlugin(database, {}));
|
|
22
|
+
},
|
|
23
|
+
async resolveStorage({ strandId, resolvedTransactor, requestedStorage }) {
|
|
24
|
+
if (requestedStorage)
|
|
25
|
+
return requestedStorage;
|
|
26
|
+
// Browsers always default to IndexedDB so a reload survives; the
|
|
27
|
+
// unit-test fake transactor needs no storage.
|
|
28
|
+
if (resolvedTransactor === 'test')
|
|
29
|
+
return undefined;
|
|
30
|
+
const dbHandle = await openOptimysticWebDb(`sereus-strand-${strandId}`);
|
|
31
|
+
return new IndexedDBRawStorage(dbHandle);
|
|
32
|
+
},
|
|
33
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, storage }) {
|
|
34
|
+
return createLibp2pNode({
|
|
35
|
+
transports: [webSockets(), circuitRelayTransport()],
|
|
36
|
+
listenAddrs: [],
|
|
37
|
+
bootstrapNodes,
|
|
38
|
+
networkName,
|
|
39
|
+
fretProfile,
|
|
40
|
+
...(storage && { storage }),
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=connect-browser.js.map
|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AAE,EAAE;gBACf,cAAc;gBACd,WAAW;gBACX,WAAW;gBACX,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC3B,CAAoB,CAAC;QACvB,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Database } from '@quereus/quereus';
|
|
2
|
+
import type { StrandConnectionOptions, SereusPluginResult } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Connect a Quereus Database to a Sereus strand (Node).
|
|
5
|
+
*
|
|
6
|
+
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
7
|
+
* Node platform seams: crypto via `@quereus/quereus`'s `registerPlugin`, and a
|
|
8
|
+
* TCP libp2p node created (only when not injected) via `@optimystic/db-p2p`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function connectToStrand(db: Database, options: StrandConnectionOptions): Promise<SereusPluginResult>;
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { registerPlugin } from '@quereus/quereus';
|
|
2
|
+
import cryptoPlugin from '@optimystic/quereus-plugin-crypto/plugin';
|
|
3
|
+
import { composeStrand } from './compose-strand.js';
|
|
4
|
+
/**
|
|
5
|
+
* Connect a Quereus Database to a Sereus strand (Node).
|
|
6
|
+
*
|
|
7
|
+
* Thin adapter over the shared {@link composeStrand} composition, supplying the
|
|
8
|
+
* Node platform seams: crypto via `@quereus/quereus`'s `registerPlugin`, and a
|
|
9
|
+
* TCP libp2p node created (only when not injected) via `@optimystic/db-p2p`.
|
|
10
|
+
*/
|
|
11
|
+
export async function connectToStrand(db, options) {
|
|
12
|
+
return composeStrand(db, options, {
|
|
13
|
+
async registerCrypto(database) {
|
|
14
|
+
await registerPlugin(database, cryptoPlugin);
|
|
15
|
+
},
|
|
16
|
+
async createNode({ networkName, bootstrapNodes, fretProfile, port, storage }) {
|
|
17
|
+
// Dynamically import to keep the module cross-platform friendly: this
|
|
18
|
+
// pulls the Node-only `@optimystic/db-p2p` (TCP) entry, and is only
|
|
19
|
+
// reached when actually creating a node (never for injected nodes).
|
|
20
|
+
const { createLibp2pNode } = await import('@optimystic/db-p2p');
|
|
21
|
+
return createLibp2pNode({
|
|
22
|
+
port,
|
|
23
|
+
bootstrapNodes,
|
|
24
|
+
networkName,
|
|
25
|
+
fretProfile,
|
|
26
|
+
...(storage && { storage }),
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,YAAY,MAAM,0CAA0C,CAAC;AAGpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,EAAY,EACZ,OAAgC;IAEhC,OAAO,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE;QACjC,KAAK,CAAC,cAAc,CAAC,QAAQ;YAC5B,MAAM,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;YAC3E,sEAAsE;YACtE,oEAAoE;YACpE,oEAAoE;YACpE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;YAChE,OAAO,gBAAgB,CAAC;gBACvB,IAAI;gBACJ,cAAc;gBACd,WAAW;gBACX,WAAW;gBACX,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC3B,CAAoB,CAAC;QACvB,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SqlValue } from '@quereus/quereus';
|
|
2
|
+
import type { StrandConnectionOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parse the plugin-loader SqlValue config into typed StrandConnectionOptions.
|
|
5
|
+
* Shared by the Node (`plugin.ts`) and browser (`plugin-browser.ts`) entries.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseConfig(config: Record<string, SqlValue>): StrandConnectionOptions;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse the plugin-loader SqlValue config into typed StrandConnectionOptions.
|
|
3
|
+
* Shared by the Node (`plugin.ts`) and browser (`plugin-browser.ts`) entries.
|
|
4
|
+
*/
|
|
5
|
+
export function parseConfig(config) {
|
|
6
|
+
const strandId = config.strand_id;
|
|
7
|
+
if (typeof strandId !== 'string' || !strandId) {
|
|
8
|
+
throw new Error('quereus-plugin-sereus: strand_id is required');
|
|
9
|
+
}
|
|
10
|
+
const bootstrapNodesRaw = config.bootstrap_nodes;
|
|
11
|
+
const bootstrapNodes = typeof bootstrapNodesRaw === 'string' && bootstrapNodesRaw
|
|
12
|
+
? bootstrapNodesRaw.split(',').map(s => s.trim()).filter(Boolean)
|
|
13
|
+
: [];
|
|
14
|
+
const schema = typeof config.schema === 'string' ? config.schema : undefined;
|
|
15
|
+
const sAppId = typeof config.sapp_id === 'string' ? config.sapp_id : 'unknown';
|
|
16
|
+
const sAppVersion = typeof config.sapp_version === 'string' ? config.sapp_version : '1.0.0';
|
|
17
|
+
const port = typeof config.port === 'number' ? config.port : 0;
|
|
18
|
+
const enableCache = config.enable_cache !== false && config.enable_cache !== 0;
|
|
19
|
+
const fretProfile = config.fret_profile === 'core' ? 'core' : 'edge';
|
|
20
|
+
// Lifecycle mode: selects bootstrap (local transactor) vs networked. Only the
|
|
21
|
+
// two known values are honored; anything else falls through to the default.
|
|
22
|
+
const mode = config.mode === 'bootstrap' || config.mode === 'networked'
|
|
23
|
+
? config.mode
|
|
24
|
+
: undefined;
|
|
25
|
+
// Internal transactor override (e.g. `'test'`). Applies only when `mode` is
|
|
26
|
+
// unset — see `StrandConnectionOptions.transactor`.
|
|
27
|
+
const transactor = typeof config.transactor === 'string' && config.transactor
|
|
28
|
+
? config.transactor
|
|
29
|
+
: undefined;
|
|
30
|
+
// NOTE: persistent storage cannot ride a `Record<string, SqlValue>` — an
|
|
31
|
+
// `IRawStorage` is not an `SqlValue`. The Node loader (`plugin.ts`) reads the
|
|
32
|
+
// platform-only `storage_path` key directly and resolves it to a concrete
|
|
33
|
+
// `FileRawStorage`; it is intentionally NOT parsed into the typed options here.
|
|
34
|
+
return {
|
|
35
|
+
strandId,
|
|
36
|
+
bootstrapNodes,
|
|
37
|
+
schema,
|
|
38
|
+
sAppId,
|
|
39
|
+
sAppVersion,
|
|
40
|
+
port,
|
|
41
|
+
enableCache,
|
|
42
|
+
fretProfile,
|
|
43
|
+
...(mode && { mode }),
|
|
44
|
+
...(transactor && { transactor }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=parse-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-config.js","sourceRoot":"","sources":["../src/parse-config.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAAgC;IAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC;IAClC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,iBAAiB,GAAG,MAAM,CAAC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AAO,MAAM,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU;QAC5E,CAAC,CAAC,MAAM,CAAC,UAAU;QACnB,CAAC,CAAC,SAAS,CAAC;IAEb,yEAAyE;IACzE,8EAA8E;IAC9E,0EAA0E;IAC1E,gFAAgF;IAEhF,OAAO;QACN,QAAQ;QACR,cAAc;QACd,MAAM;QACN,MAAM;QACN,WAAW;QACX,IAAI;QACJ,WAAW;QACX,WAAW;QACX,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;QACrB,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC;KACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import type { Database, SqlValue } from '@quereus/quereus';
|
|
9
|
+
import { parseConfig } from './parse-config.js';
|
|
10
|
+
import type { SereusPluginResult } from './types.js';
|
|
11
|
+
export { parseConfig };
|
|
12
|
+
/**
|
|
13
|
+
* Default export: Quereus plugin registration function (browser).
|
|
14
|
+
*
|
|
15
|
+
* Note: the `storage_path` setting is Node-only (it resolves to a filesystem
|
|
16
|
+
* `FileRawStorage` in `./plugin`). The browser entry ignores it and defaults
|
|
17
|
+
* storage to IndexedDB via `connectToStrandBrowser`.
|
|
18
|
+
*/
|
|
19
|
+
export default function register(db: Database, config?: Record<string, SqlValue>): Promise<SereusPluginResult>;
|