@quereus/plugin-leveldb 0.2.2 → 0.2.3
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/src/index.d.ts +33 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/plugin.d.ts +38 -0
- package/dist/src/plugin.d.ts.map +1 -0
- package/dist/src/plugin.js +29 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/provider.d.ts +51 -0
- package/dist/src/provider.d.ts.map +1 -0
- package/dist/src/provider.js +84 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/store.d.ts +28 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +127 -0
- package/dist/src/store.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB storage plugin for Quereus.
|
|
3
|
+
*
|
|
4
|
+
* Provides LevelDB-based persistent storage for Node.js environments.
|
|
5
|
+
*
|
|
6
|
+
* @example Using as a plugin (recommended)
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Database, registerPlugin } from '@quereus/quereus';
|
|
9
|
+
* import leveldbPlugin from '@quereus/plugin-leveldb/plugin';
|
|
10
|
+
*
|
|
11
|
+
* const db = new Database();
|
|
12
|
+
* await registerPlugin(db, leveldbPlugin, { basePath: './data' });
|
|
13
|
+
*
|
|
14
|
+
* await db.exec(`
|
|
15
|
+
* create table users (id integer primary key, name text)
|
|
16
|
+
* using store
|
|
17
|
+
* `);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Using the provider directly
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createLevelDBProvider } from '@quereus/plugin-leveldb';
|
|
23
|
+
* import { StoreModule } from '@quereus/store';
|
|
24
|
+
*
|
|
25
|
+
* const provider = createLevelDBProvider({ basePath: './data' });
|
|
26
|
+
* const storeModule = new StoreModule(provider);
|
|
27
|
+
* db.registerVtabModule('store', storeModule);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export { LevelDBStore } from './store.js';
|
|
31
|
+
export { LevelDBProvider, createLevelDBProvider, type LevelDBProviderOptions } from './provider.js';
|
|
32
|
+
export { default as plugin, type LevelDBPluginConfig } from './plugin.js';
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB storage plugin for Quereus.
|
|
3
|
+
*
|
|
4
|
+
* Provides LevelDB-based persistent storage for Node.js environments.
|
|
5
|
+
*
|
|
6
|
+
* @example Using as a plugin (recommended)
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Database, registerPlugin } from '@quereus/quereus';
|
|
9
|
+
* import leveldbPlugin from '@quereus/plugin-leveldb/plugin';
|
|
10
|
+
*
|
|
11
|
+
* const db = new Database();
|
|
12
|
+
* await registerPlugin(db, leveldbPlugin, { basePath: './data' });
|
|
13
|
+
*
|
|
14
|
+
* await db.exec(`
|
|
15
|
+
* create table users (id integer primary key, name text)
|
|
16
|
+
* using store
|
|
17
|
+
* `);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Using the provider directly
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createLevelDBProvider } from '@quereus/plugin-leveldb';
|
|
23
|
+
* import { StoreModule } from '@quereus/store';
|
|
24
|
+
*
|
|
25
|
+
* const provider = createLevelDBProvider({ basePath: './data' });
|
|
26
|
+
* const storeModule = new StoreModule(provider);
|
|
27
|
+
* db.registerVtabModule('store', storeModule);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export { LevelDBStore } from './store.js';
|
|
31
|
+
export { LevelDBProvider, createLevelDBProvider } from './provider.js';
|
|
32
|
+
export { default as plugin } from './plugin.js';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAA+B,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,OAAO,IAAI,MAAM,EAA4B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB plugin for Quereus.
|
|
3
|
+
*
|
|
4
|
+
* Registers a StoreModule backed by LevelDB for Node.js environments.
|
|
5
|
+
*/
|
|
6
|
+
import type { Database, SqlValue } from '@quereus/quereus';
|
|
7
|
+
import { StoreModule } from '@quereus/store';
|
|
8
|
+
/**
|
|
9
|
+
* Plugin configuration options.
|
|
10
|
+
*/
|
|
11
|
+
export interface LevelDBPluginConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Base path for all LevelDB stores.
|
|
14
|
+
* Each table gets a subdirectory under this path.
|
|
15
|
+
* @default './data'
|
|
16
|
+
*/
|
|
17
|
+
basePath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Create directories if they don't exist.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
createIfMissing?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Module name to register. Tables are created with `USING <moduleName>`.
|
|
25
|
+
* @default 'store'
|
|
26
|
+
*/
|
|
27
|
+
moduleName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Register the LevelDB plugin with a database.
|
|
31
|
+
*/
|
|
32
|
+
export default function register(_db: Database, config?: Record<string, SqlValue>): {
|
|
33
|
+
vtables: {
|
|
34
|
+
name: string;
|
|
35
|
+
module: StoreModule;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,GAAG,EAAE,QAAQ,EACb,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAM;;;;;EAqBtC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB plugin for Quereus.
|
|
3
|
+
*
|
|
4
|
+
* Registers a StoreModule backed by LevelDB for Node.js environments.
|
|
5
|
+
*/
|
|
6
|
+
import { StoreModule } from '@quereus/store';
|
|
7
|
+
import { LevelDBProvider } from './provider.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register the LevelDB plugin with a database.
|
|
10
|
+
*/
|
|
11
|
+
export default function register(_db, config = {}) {
|
|
12
|
+
const basePath = config.basePath ?? './data';
|
|
13
|
+
const createIfMissing = config.createIfMissing !== false;
|
|
14
|
+
const moduleName = config.moduleName ?? 'store';
|
|
15
|
+
const provider = new LevelDBProvider({
|
|
16
|
+
basePath,
|
|
17
|
+
createIfMissing,
|
|
18
|
+
});
|
|
19
|
+
const storeModule = new StoreModule(provider);
|
|
20
|
+
return {
|
|
21
|
+
vtables: [
|
|
22
|
+
{
|
|
23
|
+
name: moduleName,
|
|
24
|
+
module: storeModule,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA0BhD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,GAAa,EACb,SAAmC,EAAE;IAErC,MAAM,QAAQ,GAAI,MAAM,CAAC,QAAmB,IAAI,QAAQ,CAAC;IACzD,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,KAAK,KAAK,CAAC;IACzD,MAAM,UAAU,GAAI,MAAM,CAAC,UAAqB,IAAI,OAAO,CAAC;IAE5D,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC;QACnC,QAAQ;QACR,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,WAAW;aACpB;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB KVStore provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Manages LevelDB stores for the StoreModule.
|
|
5
|
+
*/
|
|
6
|
+
import type { KVStore, KVStoreProvider } from '@quereus/store';
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating a LevelDB provider.
|
|
9
|
+
*/
|
|
10
|
+
export interface LevelDBProviderOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Base path for all LevelDB stores.
|
|
13
|
+
* Each table gets a subdirectory under this path.
|
|
14
|
+
*/
|
|
15
|
+
basePath: string;
|
|
16
|
+
/**
|
|
17
|
+
* Create directories if they don't exist.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
createIfMissing?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* LevelDB implementation of KVStoreProvider.
|
|
24
|
+
*
|
|
25
|
+
* Creates separate LevelDB databases for each table, stored
|
|
26
|
+
* in subdirectories under the configured base path.
|
|
27
|
+
*/
|
|
28
|
+
export declare class LevelDBProvider implements KVStoreProvider {
|
|
29
|
+
private basePath;
|
|
30
|
+
private createIfMissing;
|
|
31
|
+
private stores;
|
|
32
|
+
private catalogStore;
|
|
33
|
+
constructor(options: LevelDBProviderOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Get the storage path for a table.
|
|
36
|
+
*/
|
|
37
|
+
private getStorePath;
|
|
38
|
+
/**
|
|
39
|
+
* Get the key for the store cache.
|
|
40
|
+
*/
|
|
41
|
+
private getStoreKey;
|
|
42
|
+
getStore(schemaName: string, tableName: string, options?: Record<string, unknown>): Promise<KVStore>;
|
|
43
|
+
getCatalogStore(): Promise<KVStore>;
|
|
44
|
+
closeStore(schemaName: string, tableName: string): Promise<void>;
|
|
45
|
+
closeAll(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a LevelDB provider with the given options.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createLevelDBProvider(options: LevelDBProviderOptions): LevelDBProvider;
|
|
51
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAG/D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,eAAe;IACrD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,YAAY,CAA6B;gBAErC,OAAO,EAAE,sBAAsB;IAK3C;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;OAEG;IACH,OAAO,CAAC,WAAW;IAIb,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBpG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAWnC,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAWhC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAEtF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB KVStore provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Manages LevelDB stores for the StoreModule.
|
|
5
|
+
*/
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { LevelDBStore } from './store.js';
|
|
8
|
+
/**
|
|
9
|
+
* LevelDB implementation of KVStoreProvider.
|
|
10
|
+
*
|
|
11
|
+
* Creates separate LevelDB databases for each table, stored
|
|
12
|
+
* in subdirectories under the configured base path.
|
|
13
|
+
*/
|
|
14
|
+
export class LevelDBProvider {
|
|
15
|
+
basePath;
|
|
16
|
+
createIfMissing;
|
|
17
|
+
stores = new Map();
|
|
18
|
+
catalogStore = null;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.basePath = options.basePath;
|
|
21
|
+
this.createIfMissing = options.createIfMissing ?? true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the storage path for a table.
|
|
25
|
+
*/
|
|
26
|
+
getStorePath(schemaName, tableName) {
|
|
27
|
+
return path.join(this.basePath, schemaName, tableName);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the key for the store cache.
|
|
31
|
+
*/
|
|
32
|
+
getStoreKey(schemaName, tableName) {
|
|
33
|
+
return `${schemaName}.${tableName}`.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
async getStore(schemaName, tableName, options) {
|
|
36
|
+
const key = this.getStoreKey(schemaName, tableName);
|
|
37
|
+
let store = this.stores.get(key);
|
|
38
|
+
if (!store) {
|
|
39
|
+
// Use custom path if provided, otherwise use default
|
|
40
|
+
const storePath = options?.path || this.getStorePath(schemaName, tableName);
|
|
41
|
+
store = await LevelDBStore.open({
|
|
42
|
+
path: storePath,
|
|
43
|
+
createIfMissing: this.createIfMissing,
|
|
44
|
+
});
|
|
45
|
+
this.stores.set(key, store);
|
|
46
|
+
}
|
|
47
|
+
return store;
|
|
48
|
+
}
|
|
49
|
+
async getCatalogStore() {
|
|
50
|
+
if (!this.catalogStore) {
|
|
51
|
+
const catalogPath = path.join(this.basePath, '__catalog__');
|
|
52
|
+
this.catalogStore = await LevelDBStore.open({
|
|
53
|
+
path: catalogPath,
|
|
54
|
+
createIfMissing: this.createIfMissing,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return this.catalogStore;
|
|
58
|
+
}
|
|
59
|
+
async closeStore(schemaName, tableName) {
|
|
60
|
+
const key = this.getStoreKey(schemaName, tableName);
|
|
61
|
+
const store = this.stores.get(key);
|
|
62
|
+
if (store) {
|
|
63
|
+
await store.close();
|
|
64
|
+
this.stores.delete(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async closeAll() {
|
|
68
|
+
for (const store of this.stores.values()) {
|
|
69
|
+
await store.close();
|
|
70
|
+
}
|
|
71
|
+
this.stores.clear();
|
|
72
|
+
if (this.catalogStore) {
|
|
73
|
+
await this.catalogStore.close();
|
|
74
|
+
this.catalogStore = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a LevelDB provider with the given options.
|
|
80
|
+
*/
|
|
81
|
+
export function createLevelDBProvider(options) {
|
|
82
|
+
return new LevelDBProvider(options);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAmB1C;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAClB,QAAQ,CAAS;IACjB,eAAe,CAAU;IACzB,MAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;IACzC,YAAY,GAAwB,IAAI,CAAC;IAEjD,YAAY,OAA+B;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC;IACzD,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,UAAkB,EAAE,SAAiB;QACxD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,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G,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB-based KVStore implementation for Node.js.
|
|
3
|
+
*
|
|
4
|
+
* Uses classic-level for LevelDB bindings.
|
|
5
|
+
*/
|
|
6
|
+
import type { KVStore, KVEntry, WriteBatch, IterateOptions, KVStoreOptions } from '@quereus/store';
|
|
7
|
+
/**
|
|
8
|
+
* LevelDB implementation of KVStore.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LevelDBStore implements KVStore {
|
|
11
|
+
private db;
|
|
12
|
+
private closed;
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Open a LevelDB store.
|
|
16
|
+
*/
|
|
17
|
+
static open(options: KVStoreOptions): Promise<LevelDBStore>;
|
|
18
|
+
get(key: Uint8Array): Promise<Uint8Array | undefined>;
|
|
19
|
+
put(key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
20
|
+
delete(key: Uint8Array): Promise<void>;
|
|
21
|
+
has(key: Uint8Array): Promise<boolean>;
|
|
22
|
+
iterate(options?: IterateOptions): AsyncIterable<KVEntry>;
|
|
23
|
+
batch(): WriteBatch;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
approximateCount(options?: IterateOptions): Promise<number>;
|
|
26
|
+
private checkOpen;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnG;;GAEG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,OAAO,CAAC,EAAE,CAAuC;IACjD,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO;IAIP;;OAEG;WACU,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAY3D,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAMrD,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAOrC,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC;IA0BhE,KAAK,IAAI,UAAU;IAKb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,gBAAgB,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAWjE,OAAO,CAAC,SAAS;CAKlB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LevelDB-based KVStore implementation for Node.js.
|
|
3
|
+
*
|
|
4
|
+
* Uses classic-level for LevelDB bindings.
|
|
5
|
+
*/
|
|
6
|
+
import { ClassicLevel } from 'classic-level';
|
|
7
|
+
/**
|
|
8
|
+
* LevelDB implementation of KVStore.
|
|
9
|
+
*/
|
|
10
|
+
export class LevelDBStore {
|
|
11
|
+
db;
|
|
12
|
+
closed = false;
|
|
13
|
+
constructor(db) {
|
|
14
|
+
this.db = db;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Open a LevelDB store.
|
|
18
|
+
*/
|
|
19
|
+
static async open(options) {
|
|
20
|
+
const db = new ClassicLevel(options.path, {
|
|
21
|
+
keyEncoding: 'view',
|
|
22
|
+
valueEncoding: 'view',
|
|
23
|
+
createIfMissing: options.createIfMissing ?? true,
|
|
24
|
+
errorIfExists: options.errorIfExists ?? false,
|
|
25
|
+
});
|
|
26
|
+
await db.open();
|
|
27
|
+
return new LevelDBStore(db);
|
|
28
|
+
}
|
|
29
|
+
async get(key) {
|
|
30
|
+
this.checkOpen();
|
|
31
|
+
// classic-level returns undefined for missing keys (doesn't throw)
|
|
32
|
+
return await this.db.get(key);
|
|
33
|
+
}
|
|
34
|
+
async put(key, value) {
|
|
35
|
+
this.checkOpen();
|
|
36
|
+
await this.db.put(key, value);
|
|
37
|
+
}
|
|
38
|
+
async delete(key) {
|
|
39
|
+
this.checkOpen();
|
|
40
|
+
await this.db.del(key);
|
|
41
|
+
}
|
|
42
|
+
async has(key) {
|
|
43
|
+
this.checkOpen();
|
|
44
|
+
// classic-level returns undefined for missing keys
|
|
45
|
+
const value = await this.db.get(key);
|
|
46
|
+
return value !== undefined;
|
|
47
|
+
}
|
|
48
|
+
async *iterate(options) {
|
|
49
|
+
this.checkOpen();
|
|
50
|
+
const iteratorOptions = {
|
|
51
|
+
keys: true,
|
|
52
|
+
values: true,
|
|
53
|
+
};
|
|
54
|
+
if (options?.gte)
|
|
55
|
+
iteratorOptions.gte = options.gte;
|
|
56
|
+
if (options?.gt)
|
|
57
|
+
iteratorOptions.gt = options.gt;
|
|
58
|
+
if (options?.lte)
|
|
59
|
+
iteratorOptions.lte = options.lte;
|
|
60
|
+
if (options?.lt)
|
|
61
|
+
iteratorOptions.lt = options.lt;
|
|
62
|
+
if (options?.reverse)
|
|
63
|
+
iteratorOptions.reverse = true;
|
|
64
|
+
if (options?.limit !== undefined)
|
|
65
|
+
iteratorOptions.limit = options.limit;
|
|
66
|
+
const iterator = this.db.iterator(iteratorOptions);
|
|
67
|
+
try {
|
|
68
|
+
for await (const [key, value] of iterator) {
|
|
69
|
+
yield { key, value };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await iterator.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
batch() {
|
|
77
|
+
this.checkOpen();
|
|
78
|
+
return new LevelDBWriteBatch(this.db);
|
|
79
|
+
}
|
|
80
|
+
async close() {
|
|
81
|
+
if (!this.closed) {
|
|
82
|
+
this.closed = true;
|
|
83
|
+
await this.db.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async approximateCount(options) {
|
|
87
|
+
this.checkOpen();
|
|
88
|
+
// LevelDB doesn't have a native count, so we iterate and count
|
|
89
|
+
// For large datasets, this could be optimized with sampling
|
|
90
|
+
let count = 0;
|
|
91
|
+
for await (const _ of this.iterate(options)) {
|
|
92
|
+
count++;
|
|
93
|
+
}
|
|
94
|
+
return count;
|
|
95
|
+
}
|
|
96
|
+
checkOpen() {
|
|
97
|
+
if (this.closed) {
|
|
98
|
+
throw new Error('LevelDBStore is closed');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* WriteBatch implementation for LevelDB.
|
|
104
|
+
*/
|
|
105
|
+
class LevelDBWriteBatch {
|
|
106
|
+
db;
|
|
107
|
+
ops = [];
|
|
108
|
+
constructor(db) {
|
|
109
|
+
this.db = db;
|
|
110
|
+
}
|
|
111
|
+
put(key, value) {
|
|
112
|
+
this.ops.push({ type: 'put', key, value });
|
|
113
|
+
}
|
|
114
|
+
delete(key) {
|
|
115
|
+
this.ops.push({ type: 'del', key });
|
|
116
|
+
}
|
|
117
|
+
async write() {
|
|
118
|
+
if (this.ops.length > 0) {
|
|
119
|
+
await this.db.batch(this.ops);
|
|
120
|
+
this.ops = [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
clear() {
|
|
124
|
+
this.ops = [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,EAAE,CAAuC;IACzC,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAoB,EAAwC;QAC1D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAuB;QACvC,MAAM,EAAE,GAAG,IAAI,YAAY,CAAyB,OAAO,CAAC,IAAI,EAAE;YAChE,WAAW,EAAE,MAAM;YACnB,aAAa,EAAE,MAAM;YACrB,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;YAChD,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,KAAK;SAC9C,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI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