diff --git a/.gitignore b/.gitignore index 95dc41e..10d1af2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ out/ !.yarn/sdks !.yarn/versions .retype/ -coverage/ \ No newline at end of file +coverage/ +tmp/ diff --git a/package.json b/package.json index f2a117a..b57322f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,10 @@ "build-api-docs": "node ./scripts/build-docs.js", "build-docs": "cd docs && npx retype build" }, + "files": [ + "src", + "typings" + ], "repository": { "type": "git", "url": "git+https://github.com/eslachance/enmap.git" diff --git a/src/index.js b/src/index.js index 1295505..5cd50b5 100644 --- a/src/index.js +++ b/src/index.js @@ -148,6 +148,8 @@ class Enmap { }); } + // MARK: Set Methods + /** * Sets a value in Enmap. If the key already has a value, overwrites the data (or the value in a path, if provided). * @param {string} key Required. The location in which the data should be saved. @@ -391,7 +393,7 @@ class Enmap { this.set(key, data, path); } - // AWESOME MATHEMATICAL METHODS + // MARK: Math Methods /** * Executes a mathematical operation on a value and saves it in the enmap. @@ -657,7 +659,11 @@ class Enmap { for (const entry of parsedData.keys) { const { key, value } = entry; if (!overwrite && this.has(key)) continue; - this.#set(key, value); + this.#db + .prepare( + `INSERT OR REPLACE INTO ${this.#name} (key, value) VALUES (?, ?)`, + ) + .run(key, value); } } @@ -995,7 +1001,7 @@ class Enmap { return results; } - // INTERNAL METHODS + // MARK: Internal Methods /* * Internal method used to insert or update a key in the database without circular calls to ensure() or others. @@ -1046,8 +1052,6 @@ class Enmap { return parsed; } - /* INTERNAL METHOD */ - #keycheck(key, type = 'key') { if (!NAME_REGEX.test(key)) { throw new Error( diff --git a/test/index.spec.js b/test/index.spec.js index fa55dce..4e9f6db 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,9 +1,6 @@ import { describe, - beforeAll, test, - beforeEach, - afterEach, expect, vi, } from 'vitest'; @@ -58,22 +55,22 @@ describe('Enmap', () => { }); test('should create a persistent Enmap w/ dir', async () => { - await mkdir('/tmp/data').catch(() => {}); + await mkdir('./tmp').catch(() => {}); - const enmap = new Enmap({ name: 'test', dataDir: '/tmp/data' }); + const enmap = new Enmap({ name: 'test', dataDir: './tmp' }); expect(enmap).toBeInstanceOf(Enmap); }); test('should load a persistent Enmap w/ dir', () => { - const enmap = new Enmap({ name: 'test', dataDir: '/tmp/data' }); + const enmap = new Enmap({ name: 'test', dataDir: './tmp' }); expect(enmap).toBeInstanceOf(Enmap); }); test('should fail to create a persistent Enmap w/o dir', async () => { expect( - () => new Enmap({ name: 'test', dataDir: '/tmp/data-not-found' }), + () => new Enmap({ name: 'test', dataDir: './data-not-found' }), ).toThrow(TypeError); });