@xyo-network/xl1-driver-lmdb 2.0.11

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/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ [![logo][]](https://xyo.network)
2
+
3
+ # @xyo-network/xl1-driver-lmdb
4
+
5
+ [![npm-badge][]][npm-link]
6
+ [![license-badge][]][license-link]
7
+
8
+ > LMDB-backed map driver for XL1 protocol storage — a synchronous, embedded `SyncMap` implementation for Node.
9
+
10
+ ## About
11
+
12
+ XL1 SDK components persist data through the `MapType` (`SyncMap | AsyncMap`) abstraction. This package provides `SynchronousLmdbMap`, a synchronous [LMDB](https://github.com/kriszyp/lmdb-js)-backed `SyncMap` for Node, plus helpers (`getLocalPersistentMap`, `deleteLocalPersistentMap`, `getStoreDirectory`) for convention-based on-disk stores. A single LMDB environment supports multiple named stores for multi-tenancy.
13
+
14
+ Inject it wherever an SDK component accepts a `MapType` to back that store with durable, embedded, file-based storage — no external database process required.
15
+
16
+ ## Install
17
+
18
+ Using npm:
19
+
20
+ ```sh
21
+ npm i --save @xyo-network/xl1-driver-lmdb
22
+ ```
23
+
24
+ Using yarn:
25
+
26
+ ```sh
27
+ yarn add @xyo-network/xl1-driver-lmdb
28
+ ```
29
+
30
+ Using pnpm:
31
+
32
+ ```sh
33
+ pnpm add @xyo-network/xl1-driver-lmdb
34
+ ```
35
+
36
+ Using bun:
37
+
38
+ ```sh
39
+ bun add @xyo-network/xl1-driver-lmdb
40
+ ```
41
+
42
+ > `lmdb` is an optional peer dependency — install it in the consuming application. This package is Node-only.
43
+
44
+ ## What's Inside
45
+
46
+ - **`SynchronousLmdbMap`** — a synchronous LMDB-backed `SyncMap<K, V>`: `get`/`set`/`has`/`getMany`/`setMany`/`delete`/`clear`/`all`, with multi-store support inside one environment.
47
+ - **`getLocalPersistentMap` / `deleteLocalPersistentMap`** — create/remove a convention-based local store.
48
+ - **`getStoreDirectory`**, **`StoreKind`**, **`LmdbMapParams`** — store path and configuration helpers.
49
+
50
+ ## Building Locally
51
+
52
+ ```sh
53
+ xy build @xyo-network/xl1-driver-lmdb
54
+ xy test @xyo-network/xl1-driver-lmdb
55
+ xy lint @xyo-network/xl1-driver-lmdb
56
+ ```
57
+
58
+ ## Maintainers
59
+
60
+ <table>
61
+ <tr>
62
+ <td align="center" valign="top" width="120">
63
+ <a href="https://github.com/arietrouw">
64
+ <img src="https://github.com/arietrouw.png" width="80" height="80" alt="Arie Trouw" /><br />
65
+ <sub><b>Arie Trouw</b></sub>
66
+ </a>
67
+ <br />
68
+ <a href="https://arietrouw.com">arietrouw.com</a>
69
+ </td>
70
+ <td align="center" valign="top" width="120">
71
+ <a href="https://github.com/jonesmac">
72
+ <img src="https://github.com/jonesmac.png" width="80" height="80" alt="Matt Jones" /><br />
73
+ <sub><b>Matt Jones</b></sub>
74
+ </a>
75
+ </td>
76
+ <td align="center" valign="top" width="120">
77
+ <a href="https://github.com/JoelBCarter">
78
+ <img src="https://github.com/JoelBCarter.png" width="80" height="80" alt="Joel Carter" /><br />
79
+ <sub><b>Joel Carter</b></sub>
80
+ </a>
81
+ </td>
82
+ </tr>
83
+ </table>
84
+
85
+ ## License
86
+
87
+ See the [LICENSE](./LICENSE) file (LGPL-3.0-only).
88
+
89
+ ## Credits
90
+
91
+ [Made with 🔥 and ❄️ by XYO Foundation](https://xyo.network)
92
+
93
+ [npm-badge]: https://img.shields.io/npm/v/@xyo-network/xl1-driver-lmdb.svg
94
+ [npm-link]: https://www.npmjs.com/package/@xyo-network/xl1-driver-lmdb
95
+ [license-badge]: https://img.shields.io/npm/l/@xyo-network/xl1-driver-lmdb.svg
96
+ [license-link]: ./LICENSE
97
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -0,0 +1,7 @@
1
+ import type { CreatableParams } from '@xylabs/sdk-js';
2
+ export interface LmdbMapParams extends CreatableParams {
3
+ dbName: string;
4
+ location: string;
5
+ storeName: string;
6
+ }
7
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB"}
@@ -0,0 +1,2 @@
1
+ export type StoreKind = 'lmdb';
2
+ //# sourceMappingURL=StoreKind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoreKind.d.ts","sourceRoot":"","sources":["../../src/StoreKind.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { AbstractCreatable } from '@xylabs/sdk-js';
2
+ import type { SyncMap } from '@xyo-network/xl1-protocol-lib';
3
+ import type { Database, Key, RootDatabase } from 'lmdb';
4
+ import type { LmdbMapParams } from './Params.ts';
5
+ /**
6
+ * A synchronous LMDB-backed Map implementation.
7
+ * This class provides a synchronous interface to an LMDB database, allowing for key-value storage.
8
+ * It allows for multi-tenancy within a single LMDB environment by using a root database (located
9
+ * at this.folderPath) and a specific DB within the environment (specified by this.params.storeName).
10
+ * @template K - The type of keys in the map.
11
+ * @template V - The type of values in the map.
12
+ */
13
+ export declare class SynchronousLmdbMap<K extends Key, V> extends AbstractCreatable<LmdbMapParams> implements SyncMap<K, V> {
14
+ protected db: Database<V, K>;
15
+ protected rootDatabase: RootDatabase;
16
+ /**
17
+ * The path to the LMDB folder where the database is stored.
18
+ * This is constructed from the location and dbName parameters
19
+ * allowing for multiple DBs within the root (by specifying a
20
+ * different storeName).
21
+ * @returns The folder path for the LMDB database.
22
+ */
23
+ get folderPath(): string;
24
+ all(): V[];
25
+ clear(): void;
26
+ delete(id: K): boolean;
27
+ get(id: K): V | undefined;
28
+ getMany(ids: K[]): V[];
29
+ has(id: K): boolean;
30
+ set(id: K, data: V): void;
31
+ setMany(entries: [K, V][]): void;
32
+ startHandler(): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=SynchronousLmdbMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SynchronousLmdbMap.d.ts","sourceRoot":"","sources":["../../src/SynchronousLmdbMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAa,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EACV,QAAQ,EAAE,GAAG,EAAE,YAAY,EAC5B,MAAM,MAAM,CAAA;AAGb,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;;;GAOG;AACH,qBACa,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAAE,SAAQ,iBAAiB,CAAC,aAAa,CAAE,YAAW,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACjH,SAAS,CAAC,EAAE,EAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7B,SAAS,CAAC,YAAY,EAAG,YAAY,CAAA;IAErC;;;;;;OAMG;IACH,IAAI,UAAU,WAEb;IAED,GAAG,IAAI,CAAC,EAAE;IAIV,KAAK,IAAI,IAAI;IAIb,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO;IAItB,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAIzB,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE;IAWtB,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO;IAInB,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAIzB,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI;IAMjB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7C"}
@@ -0,0 +1,10 @@
1
+ import type { StoreKind } from './StoreKind.ts';
2
+ /**
3
+ * Creates a convention-based directory path for an archivist store
4
+ * @param name The name of the archivist
5
+ * @param storageRoot The root directory for storage
6
+ * @param kind The kind of the archivist (optional)
7
+ * @returns The directory path for the archivist store
8
+ */
9
+ export declare const getStoreDirectory: (name: string, storageRoot: string, kind?: StoreKind) => string;
10
+ //# sourceMappingURL=getStoreDirectory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStoreDirectory.d.ts","sourceRoot":"","sources":["../../src/getStoreDirectory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,aAAa,MAAM,EAAE,OAAO,SAAS,KAAG,MAEvF,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './getStoreDirectory.ts';
2
+ export * from './localPersistentMap.ts';
3
+ export * from './Params.ts';
4
+ export * from './StoreKind.ts';
5
+ export * from './SynchronousLmdbMap.ts';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,116 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
12
+ // src/getStoreDirectory.ts
13
+ import Path from "node:path";
14
+ var getStoreDirectory = (name, storageRoot, kind) => {
15
+ return kind === void 0 ? Path.join(storageRoot, name) : Path.join(storageRoot, kind, name);
16
+ };
17
+
18
+ // src/localPersistentMap.ts
19
+ import { rm } from "node:fs/promises";
20
+ import Path2 from "node:path";
21
+
22
+ // src/SynchronousLmdbMap.ts
23
+ import { AbstractCreatable, creatable } from "@xylabs/sdk-js";
24
+ import { open } from "lmdb";
25
+ var SynchronousLmdbMap = class extends AbstractCreatable {
26
+ db;
27
+ rootDatabase;
28
+ /**
29
+ * The path to the LMDB folder where the database is stored.
30
+ * This is constructed from the location and dbName parameters
31
+ * allowing for multiple DBs within the root (by specifying a
32
+ * different storeName).
33
+ * @returns The folder path for the LMDB database.
34
+ */
35
+ get folderPath() {
36
+ return `${this.params.location}/${this.params.storeName}`;
37
+ }
38
+ all() {
39
+ return [...this.db.getRange({})].map((entry) => entry.value);
40
+ }
41
+ clear() {
42
+ this.db.clearSync();
43
+ }
44
+ delete(id) {
45
+ return this.db.removeSync(id);
46
+ }
47
+ get(id) {
48
+ return this.db.get(id);
49
+ }
50
+ getMany(ids) {
51
+ const results = [];
52
+ for (const id of ids) {
53
+ const value = this.db.get(id);
54
+ if (value !== void 0) {
55
+ results.push(value);
56
+ }
57
+ }
58
+ return results;
59
+ }
60
+ has(id) {
61
+ return this.db.doesExist(id);
62
+ }
63
+ set(id, data) {
64
+ this.db.putSync(id, data);
65
+ }
66
+ setMany(entries) {
67
+ for (const [key, value] of entries) {
68
+ this.set(key, value);
69
+ }
70
+ }
71
+ async startHandler() {
72
+ await super.startHandler();
73
+ this.rootDatabase = open({ path: this.folderPath, name: this.params.dbName });
74
+ this.db = this.rootDatabase.openDB({ name: this.params.storeName, cache: true });
75
+ }
76
+ };
77
+ SynchronousLmdbMap = __decorateClass([
78
+ creatable()
79
+ ], SynchronousLmdbMap);
80
+
81
+ // src/localPersistentMap.ts
82
+ var DEFAULT_STORAGE_ROOT = Path2.join(process.cwd(), ".store");
83
+ var getLocalPersistentMap = async (dbName, storeName, storageRoot, kind = "lmdb") => {
84
+ switch (kind) {
85
+ case "lmdb": {
86
+ const root = storageRoot ?? DEFAULT_STORAGE_ROOT;
87
+ const location = getStoreDirectory(dbName, root, "lmdb");
88
+ const store = await SynchronousLmdbMap.create({
89
+ location,
90
+ dbName,
91
+ storeName
92
+ });
93
+ await store.start();
94
+ return store;
95
+ }
96
+ }
97
+ };
98
+ var deleteLocalPersistentMap = async (dbName, storageRoot, kind = "lmdb") => {
99
+ await Promise.resolve();
100
+ let location = "";
101
+ switch (kind) {
102
+ case "lmdb": {
103
+ const root = storageRoot ?? DEFAULT_STORAGE_ROOT;
104
+ location = getStoreDirectory(dbName, root, "lmdb");
105
+ break;
106
+ }
107
+ }
108
+ await rm(location, { recursive: true, force: true });
109
+ };
110
+ export {
111
+ SynchronousLmdbMap,
112
+ deleteLocalPersistentMap,
113
+ getLocalPersistentMap,
114
+ getStoreDirectory
115
+ };
116
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/getStoreDirectory.ts", "../../src/localPersistentMap.ts", "../../src/SynchronousLmdbMap.ts"],
4
+ "sourcesContent": ["import Path from 'node:path'\n\nimport type { StoreKind } from './StoreKind.ts'\n\n/**\n * Creates a convention-based directory path for an archivist store\n * @param name The name of the archivist\n * @param storageRoot The root directory for storage\n * @param kind The kind of the archivist (optional)\n * @returns The directory path for the archivist store\n */\nexport const getStoreDirectory = (name: string, storageRoot: string, kind?: StoreKind): string => {\n return (kind === undefined) ? Path.join(storageRoot, name) : Path.join(storageRoot, kind, name)\n}\n", "import { rm } from 'node:fs/promises'\nimport Path from 'node:path'\n\nimport type { MapType } from '@xyo-network/xl1-protocol-lib'\n\nimport { getStoreDirectory } from './getStoreDirectory.ts'\nimport type { StoreKind } from './StoreKind.ts'\nimport { SynchronousLmdbMap } from './SynchronousLmdbMap.ts'\n\nconst DEFAULT_STORAGE_ROOT = Path.join(process.cwd(), '.store')\n\n/**\n * Returns a local persistent map\n * @param dbName The name of the database\n * @param storeName The name of the store\n * @param storageRoot The root directory for storage (default is '.store' in the current working directory)\n * @param kind The kind of the map\n * @returns a map\n */\nexport const getLocalPersistentMap = async <TId, TData>(\n dbName: string,\n storeName: string,\n storageRoot?: string,\n kind: StoreKind = 'lmdb'): Promise<MapType<TId, TData>> => {\n switch (kind) {\n case 'lmdb': {\n const root = storageRoot ?? DEFAULT_STORAGE_ROOT\n const location = getStoreDirectory(dbName, root, 'lmdb')\n const store = await SynchronousLmdbMap.create({\n location, dbName, storeName,\n })\n await store.start()\n return store as unknown as MapType<TId, TData>\n }\n }\n}\n\nexport const deleteLocalPersistentMap = async (\n dbName: string,\n storageRoot?: string,\n kind: StoreKind = 'lmdb',\n): Promise<void> => {\n await Promise.resolve()\n let location = ''\n switch (kind) {\n case 'lmdb': {\n const root = storageRoot ?? DEFAULT_STORAGE_ROOT\n location = getStoreDirectory(dbName, root, 'lmdb')\n break\n }\n }\n await rm(location, { recursive: true, force: true })\n}\n", "import { AbstractCreatable, creatable } from '@xylabs/sdk-js'\nimport type { SyncMap } from '@xyo-network/xl1-protocol-lib'\nimport type {\n Database, Key, RootDatabase,\n} from 'lmdb'\nimport { open } from 'lmdb'\n\nimport type { LmdbMapParams } from './Params.ts'\n\n// TODO: Abstract creatable instead of service?\n/**\n * A synchronous LMDB-backed Map implementation.\n * This class provides a synchronous interface to an LMDB database, allowing for key-value storage.\n * It allows for multi-tenancy within a single LMDB environment by using a root database (located\n * at this.folderPath) and a specific DB within the environment (specified by this.params.storeName).\n * @template K - The type of keys in the map.\n * @template V - The type of values in the map.\n */\n@creatable()\nexport class SynchronousLmdbMap<K extends Key, V> extends AbstractCreatable<LmdbMapParams> implements SyncMap<K, V> {\n protected db!: Database<V, K>\n protected rootDatabase!: RootDatabase\n\n /**\n * The path to the LMDB folder where the database is stored.\n * This is constructed from the location and dbName parameters\n * allowing for multiple DBs within the root (by specifying a\n * different storeName).\n * @returns The folder path for the LMDB database.\n */\n get folderPath() {\n return `${this.params.location}/${this.params.storeName}`\n }\n\n all(): V[] {\n return [...this.db.getRange({})].map(entry => entry.value)\n }\n\n clear(): void {\n this.db.clearSync()\n }\n\n delete(id: K): boolean {\n return this.db.removeSync(id)\n }\n\n get(id: K): V | undefined {\n return this.db.get(id)\n }\n\n getMany(ids: K[]): V[] {\n const results: V[] = []\n for (const id of ids) {\n const value = this.db.get(id)\n if (value !== undefined) {\n results.push(value)\n }\n }\n return results\n }\n\n has(id: K): boolean {\n return this.db.doesExist(id)\n }\n\n set(id: K, data: V): void {\n this.db.putSync(id, data)\n }\n\n setMany(entries: [K, V][]): void {\n for (const [key, value] of entries) {\n this.set(key, value)\n }\n }\n\n override async startHandler(): Promise<void> {\n await super.startHandler()\n // Initialize the DB Environment (opens the default LMDB database)\n this.rootDatabase = open({ path: this.folderPath, name: this.params.dbName })\n // Open the desired DB (using the store name)\n this.db = this.rootDatabase.openDB<V, K>({ name: this.params.storeName, cache: true })\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;AAAA,OAAO,UAAU;AAWV,IAAM,oBAAoB,CAAC,MAAc,aAAqB,SAA6B;AAChG,SAAQ,SAAS,SAAa,KAAK,KAAK,aAAa,IAAI,IAAI,KAAK,KAAK,aAAa,MAAM,IAAI;AAChG;;;ACbA,SAAS,UAAU;AACnB,OAAOA,WAAU;;;ACDjB,SAAS,mBAAmB,iBAAiB;AAK7C,SAAS,YAAY;AAcd,IAAM,qBAAN,cAAmD,kBAA0D;AAAA,EACxG;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASV,IAAI,aAAa;AACf,WAAO,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,SAAS;AAAA,EACzD;AAAA,EAEA,MAAW;AACT,WAAO,CAAC,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,WAAS,MAAM,KAAK;AAAA,EAC3D;AAAA,EAEA,QAAc;AACZ,SAAK,GAAG,UAAU;AAAA,EACpB;AAAA,EAEA,OAAO,IAAgB;AACrB,WAAO,KAAK,GAAG,WAAW,EAAE;AAAA,EAC9B;AAAA,EAEA,IAAI,IAAsB;AACxB,WAAO,KAAK,GAAG,IAAI,EAAE;AAAA,EACvB;AAAA,EAEA,QAAQ,KAAe;AACrB,UAAM,UAAe,CAAC;AACtB,eAAW,MAAM,KAAK;AACpB,YAAM,QAAQ,KAAK,GAAG,IAAI,EAAE;AAC5B,UAAI,UAAU,QAAW;AACvB,gBAAQ,KAAK,KAAK;AAAA,MACpB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,IAAgB;AAClB,WAAO,KAAK,GAAG,UAAU,EAAE;AAAA,EAC7B;AAAA,EAEA,IAAI,IAAO,MAAe;AACxB,SAAK,GAAG,QAAQ,IAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,QAAQ,SAAyB;AAC/B,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,WAAK,IAAI,KAAK,KAAK;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,MAAe,eAA8B;AAC3C,UAAM,MAAM,aAAa;AAEzB,SAAK,eAAe,KAAK,EAAE,MAAM,KAAK,YAAY,MAAM,KAAK,OAAO,OAAO,CAAC;AAE5E,SAAK,KAAK,KAAK,aAAa,OAAa,EAAE,MAAM,KAAK,OAAO,WAAW,OAAO,KAAK,CAAC;AAAA,EACvF;AACF;AA/Da,qBAAN;AAAA,EADN,UAAU;AAAA,GACE;;;ADVb,IAAM,uBAAuBC,MAAK,KAAK,QAAQ,IAAI,GAAG,QAAQ;AAUvD,IAAM,wBAAwB,OACnC,QACA,WACA,aACA,OAAkB,WAAyC;AAC3D,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,YAAM,OAAO,eAAe;AAC5B,YAAM,WAAW,kBAAkB,QAAQ,MAAM,MAAM;AACvD,YAAM,QAAQ,MAAM,mBAAmB,OAAO;AAAA,QAC5C;AAAA,QAAU;AAAA,QAAQ;AAAA,MACpB,CAAC;AACD,YAAM,MAAM,MAAM;AAClB,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,2BAA2B,OACtC,QACA,aACA,OAAkB,WACA;AAClB,QAAM,QAAQ,QAAQ;AACtB,MAAI,WAAW;AACf,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,YAAM,OAAO,eAAe;AAC5B,iBAAW,kBAAkB,QAAQ,MAAM,MAAM;AACjD;AAAA,IACF;AAAA,EACF;AACA,QAAM,GAAG,UAAU,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AACrD;",
6
+ "names": ["Path", "Path"]
7
+ }
@@ -0,0 +1,13 @@
1
+ import type { MapType } from '@xyo-network/xl1-protocol-lib';
2
+ import type { StoreKind } from './StoreKind.ts';
3
+ /**
4
+ * Returns a local persistent map
5
+ * @param dbName The name of the database
6
+ * @param storeName The name of the store
7
+ * @param storageRoot The root directory for storage (default is '.store' in the current working directory)
8
+ * @param kind The kind of the map
9
+ * @returns a map
10
+ */
11
+ export declare const getLocalPersistentMap: <TId, TData>(dbName: string, storeName: string, storageRoot?: string, kind?: StoreKind) => Promise<MapType<TId, TData>>;
12
+ export declare const deleteLocalPersistentMap: (dbName: string, storageRoot?: string, kind?: StoreKind) => Promise<void>;
13
+ //# sourceMappingURL=localPersistentMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localPersistentMap.d.ts","sourceRoot":"","sources":["../../src/localPersistentMap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAG5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK/C;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAU,GAAG,EAAE,KAAK,EACpD,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,cAAc,MAAM,EACpB,OAAM,SAAkB,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAYvD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,EACd,cAAc,MAAM,EACpB,OAAM,SAAkB,KACvB,OAAO,CAAC,IAAI,CAWd,CAAA"}
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "$schema": "http://json.schemastore.org/package.json",
3
+ "name": "@xyo-network/xl1-driver-lmdb",
4
+ "version": "2.0.11",
5
+ "description": "XYO Layer One SDK Protocol LMDB Driver",
6
+ "homepage": "https://xylabs.com",
7
+ "bugs": {
8
+ "url": "https://github.com/XYOracleNetwork/xl1-protocol/issues",
9
+ "email": "support@xylabs.com"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/XYOracleNetwork/xl1-protocol.git"
14
+ },
15
+ "license": "LGPL-3.0-only",
16
+ "author": {
17
+ "name": "XY Labs Development Team",
18
+ "email": "support@xylabs.com",
19
+ "url": "https://xylabs.com"
20
+ },
21
+ "sideEffects": false,
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/node/index.d.ts",
26
+ "default": "./dist/node/index.mjs"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "!**/*.bench.*",
33
+ "!**/*.spec.*",
34
+ "!**/*.test.*",
35
+ "README.md"
36
+ ],
37
+ "dependencies": {
38
+ "@xyo-network/xl1-protocol-lib": "~2.0.11"
39
+ },
40
+ "devDependencies": {
41
+ "@bitauth/libauth": "~3.0",
42
+ "@metamask/providers": "^22.1",
43
+ "@noble/post-quantum": "~0.6.1",
44
+ "@opentelemetry/api": "^1.9",
45
+ "@opentelemetry/sdk-trace-base": "^2.7",
46
+ "@scure/base": "~2.2",
47
+ "@scure/bip39": "~2.2",
48
+ "@xylabs/geo": "^6.0",
49
+ "@xylabs/sdk-js": "^6.0.10",
50
+ "@xylabs/threads": "~6.0",
51
+ "@xylabs/toolchain": "~8.1.18",
52
+ "@xylabs/tsconfig": "~8.1.18",
53
+ "@xyo-network/address": "^6.0",
54
+ "@xyo-network/sdk-js": "^6.0",
55
+ "@xyo-network/sdk-protocol-js": "~6.0",
56
+ "ajv": "^8.20",
57
+ "async-mutex": "^0.5",
58
+ "bn.js": "^5.2",
59
+ "buffer": "^6.0",
60
+ "debug": "~4.4",
61
+ "eslint": "^10.4.1",
62
+ "ethers": "^6.16",
63
+ "hash-wasm": "~4.12",
64
+ "idb": "^8.0",
65
+ "lmdb": "^3.5.5",
66
+ "lru-cache": "^11.3",
67
+ "observable-fns": "~0.6",
68
+ "typescript": "~6.0.3",
69
+ "webextension-polyfill": "^0.12",
70
+ "zod": "~4.4"
71
+ },
72
+ "peerDependencies": {
73
+ "@bitauth/libauth": "~3.0",
74
+ "@metamask/providers": "^22.1",
75
+ "@noble/post-quantum": "~0.6.1",
76
+ "@opentelemetry/api": "^1.9",
77
+ "@opentelemetry/sdk-trace-base": "^2.7",
78
+ "@scure/base": "~2.2",
79
+ "@scure/bip39": "~2.2",
80
+ "@xylabs/geo": "^6.0",
81
+ "@xylabs/sdk-js": "^6.0",
82
+ "@xylabs/threads": "~6.0",
83
+ "@xyo-network/address": "^6.0",
84
+ "@xyo-network/sdk-js": "^6.0",
85
+ "@xyo-network/sdk-protocol-js": "~6.0",
86
+ "ajv": "^8.20",
87
+ "async-mutex": "^0.5",
88
+ "bn.js": "^5.2",
89
+ "buffer": "^6.0",
90
+ "debug": "~4.4",
91
+ "ethers": "^6.16",
92
+ "hash-wasm": "~4.12",
93
+ "idb": "^8.0",
94
+ "lmdb": "^3.5",
95
+ "lru-cache": "^11.3",
96
+ "observable-fns": "~0.6",
97
+ "webextension-polyfill": "^0.12",
98
+ "zod": "~4.4"
99
+ },
100
+ "peerDependenciesMeta": {
101
+ "lmdb": {
102
+ "optional": true
103
+ }
104
+ },
105
+ "engines": {
106
+ "node": ">=22.3"
107
+ },
108
+ "engineStrict": true,
109
+ "publishConfig": {
110
+ "access": "public"
111
+ }
112
+ }