@converse/skeletor 3.1.0 → 3.1.1
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/dist/skeletor.d.ts +7 -0
- package/dist/skeletor.esm.js +9 -1
- package/dist/skeletor.esm.js.map +1 -1
- package/dist/skeletor.js +9 -1
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +4 -4
- package/dist/skeletor.node.js +3828 -3815
- package/dist/skeletor.node.mjs +3828 -3815
- package/package.json +4 -4
- package/src/index.node.ts +9 -1
- package/src/storage.ts +18 -1
package/package.json
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"contributors": [
|
|
37
37
|
"JC Brand"
|
|
38
38
|
],
|
|
39
|
-
"version": "3.1.
|
|
39
|
+
"version": "3.1.1",
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=22.0.0"
|
|
42
42
|
},
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"url": "https://github.com/conversejs/skeletor.git"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
|
-
"clean": "rm -rf dist",
|
|
50
|
-
"prebuild": "npm run clean && mkdir -p dist/defs",
|
|
51
49
|
"build": "npm run prebuild && npm run build:declarations && rollup -c",
|
|
52
|
-
"build:types": "tsc -p tsconfig.declarations.json",
|
|
53
50
|
"build:declarations": "npm run build:types && api-extractor run --local && rm -rf dist/defs",
|
|
51
|
+
"build:types": "tsc -p tsconfig.declarations.json",
|
|
54
52
|
"check": "npm run check:types && npm run test && npm run test:node && npm run lint",
|
|
55
53
|
"check:types": "tsc --noEmit",
|
|
54
|
+
"clean": "rm -rf dist",
|
|
56
55
|
"dev": "karma start --single-run=false",
|
|
57
56
|
"lint": "eslint src/*.ts test/*.ts",
|
|
57
|
+
"prebuild": "npm run clean && mkdir -p dist/defs",
|
|
58
58
|
"prettier": "prettier --write src/**/*.js test/**/*.js src/**/*.ts test/**/*.ts",
|
|
59
59
|
"test": "karma start && karma start --mocha-only",
|
|
60
60
|
"test:node": "tsx node_modules/mocha/bin/mocha.js 'test/nodeStorage.test.ts'"
|
package/src/index.node.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* Re-exports everything from the browser entry and additionally
|
|
4
4
|
* exports the NodeSQLiteStorage LocalForage implementation.
|
|
5
5
|
*/
|
|
6
|
+
import PersistentStorage from './storage';
|
|
7
|
+
import { NodeSQLiteStorage } from './drivers/nodeSQLiteStorage';
|
|
8
|
+
|
|
9
|
+
// Register the SQLite driver so `new PersistentStorage(id, 'node')` resolves it.
|
|
10
|
+
// The browser builds leave this unset, keeping the node-only driver out of
|
|
11
|
+
// their bundles entirely.
|
|
12
|
+
PersistentStorage.nodeStorage = NodeSQLiteStorage;
|
|
13
|
+
|
|
6
14
|
export * from './index';
|
|
7
15
|
export { default } from './index';
|
|
8
|
-
export { NodeSQLiteStorage }
|
|
16
|
+
export { NodeSQLiteStorage };
|
package/src/storage.ts
CHANGED
|
@@ -33,6 +33,12 @@ const weakInstances = new Set<WeakRef<PersistentStorage>>();
|
|
|
33
33
|
// same instance twice and make flushAll() flush it more than once.
|
|
34
34
|
const registered = new WeakSet<PersistentStorage>();
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Constructor for a Node.js-only storage driver. Registered by the
|
|
38
|
+
* `@converse/skeletor/node` entry point via {@link PersistentStorage.nodeStorage}.
|
|
39
|
+
*/
|
|
40
|
+
type NodeStorageConstructor = new (name: string) => StorageDriver;
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* @public
|
|
38
44
|
*/
|
|
@@ -49,6 +55,11 @@ class PersistentStorage {
|
|
|
49
55
|
static sessionStorageInitialized: Promise<void>;
|
|
50
56
|
static localForage: typeof localForage;
|
|
51
57
|
|
|
58
|
+
// The Node.js SQLite storage driver. Left null in browser builds so the
|
|
59
|
+
// node-only driver (and its `node:sqlite` import) never enters the browser
|
|
60
|
+
// bundle; the `@converse/skeletor/node` entry sets it.
|
|
61
|
+
static nodeStorage: NodeStorageConstructor | null = null;
|
|
62
|
+
|
|
52
63
|
/** Register a storage instance with a weak reference. @public */
|
|
53
64
|
static register(instance: PersistentStorage): void {
|
|
54
65
|
if (registered.has(instance)) return;
|
|
@@ -110,7 +121,13 @@ class PersistentStorage {
|
|
|
110
121
|
} else if (type === 'in_memory') {
|
|
111
122
|
await localForage.config({ 'driver': IN_MEMORY });
|
|
112
123
|
} else if (type === 'node') {
|
|
113
|
-
const
|
|
124
|
+
const NodeSQLiteStorage = PersistentStorage.nodeStorage;
|
|
125
|
+
if (!NodeSQLiteStorage) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
"Skeletor.storage: the 'node' storage type is only available in Node.js builds. " +
|
|
128
|
+
"Import from '@converse/skeletor/node' instead of '@converse/skeletor'."
|
|
129
|
+
);
|
|
130
|
+
}
|
|
114
131
|
this.store = new NodeSQLiteStorage(this.name);
|
|
115
132
|
if (batchedWrites) {
|
|
116
133
|
this.store.debouncedSetItems = mergebounce((items: Record<string, any>) => this.store.setItems!(items), 50, {
|