keyv-dir-store 0.0.3 → 0.0.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ### [0.0.5](https://github.com/snomiao/keyv-dir-store/compare/v0.0.4...v0.0.5) (2024-06-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **main:** sanitize ([ae7b162](https://github.com/snomiao/keyv-dir-store/commit/ae7b162cb8835bccda3c81769009ac0a78c7fac0))
11
+ * **main:** stage ([86d9193](https://github.com/snomiao/keyv-dir-store/commit/86d9193f5aa095ac77d006f081a3b0e801c1327e))
12
+
13
+ ### [0.0.4](https://github.com/snomiao/keyv-dir-store/compare/v0.0.3...v0.0.4) (2024-06-26)
14
+
15
+ ### [0.0.3](https://github.com/snomiao/keyv-dir-store/compare/v0.0.2...v0.0.3) (2024-06-12)
16
+
17
+
18
+ ### Features
19
+
20
+ * **kds:** init ([7ef5f68](https://github.com/snomiao/keyv-dir-store/commit/7ef5f68430657a81dcace597148c7641032ed6ab))
21
+
22
+ ### [0.0.2](https://github.com/snomiao/keyv-dir-store/compare/v0.0.1...v0.0.2) (2024-06-12)
23
+
24
+ ### 0.0.1 (2024-06-12)
package/dist/index.js CHANGED
@@ -329,24 +329,27 @@ class KeyvDirStore {
329
329
  #dir;
330
330
  #cache;
331
331
  #ready;
332
- #path;
332
+ #filename;
333
333
  ext = ".json";
334
334
  constructor(dir, {
335
335
  cache = new Map,
336
- path: path2,
336
+ filename,
337
337
  ext
338
338
  } = {}) {
339
339
  this.#ready = mkdir(dir, { recursive: true });
340
340
  this.#cache = cache;
341
341
  this.#dir = dir;
342
- this.#path = path2 ?? this.#defaultPath;
342
+ this.#filename = filename ?? this.#defaultFilename;
343
343
  this.ext = ext ?? this.ext;
344
344
  }
345
- #defaultPath(key) {
345
+ #defaultFilename(key) {
346
346
  const readableName = import_sanitize_filename.default(key).slice(4, 16);
347
- const hashName = import_md5.default(this.#dir + key).slice(0, 16);
348
- const name = readableName + "-" + hashName + this.ext;
349
- return path.join(this.#dir, name);
347
+ const hashName = import_md5.default(key + "+SALT-poS1djRa4M2jXsWi").slice(0, 16);
348
+ const name = `${readableName}-${hashName}`;
349
+ return name;
350
+ }
351
+ #path(key) {
352
+ return path.join(this.#dir, import_sanitize_filename.default(this.#filename(key) + this.ext));
350
353
  }
351
354
  async get(key) {
352
355
  const cached = this.#cache.get(key);
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { mkdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
2
1
  import type { DeserializedData, default as Keyv } from "keyv";
3
2
  import md5 from "md5";
3
+ import { mkdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
4
4
  import path from "path";
5
5
  import sanitizeFilename from "sanitize-filename";
6
6
  type Value = any;
@@ -22,32 +22,38 @@ export class KeyvDirStore implements Keyv.Store<string> {
22
22
  #dir: string;
23
23
  #cache: CacheMap<Value>;
24
24
  #ready: Promise<unknown>;
25
- #path: (key: string) => string;
25
+ #filename: (key: string) => string;
26
26
  ext = ".json";
27
27
  constructor(
28
28
  dir: string,
29
29
  {
30
30
  cache = new Map(),
31
- path,
31
+ filename,
32
32
  ext,
33
33
  }: {
34
34
  cache?: CacheMap<Value>;
35
- path?: (key: string) => string;
35
+ filename?: (key: string) => string;
36
36
  ext?: string;
37
37
  } = {}
38
38
  ) {
39
39
  this.#ready = mkdir(dir, { recursive: true });
40
40
  this.#cache = cache;
41
41
  this.#dir = dir;
42
- this.#path = path ?? this.#defaultPath;
42
+ this.#filename = filename ?? this.#defaultFilename;
43
43
  this.ext = ext ?? this.ext;
44
44
  }
45
- #defaultPath(key: string) {
45
+ #defaultFilename(key: string) {
46
46
  // use dir as hash salt to avoid collisions
47
47
  const readableName = sanitizeFilename(key).slice(4, 16);
48
- const hashName = md5(this.#dir + key).slice(0, 16);
49
- const name = readableName + "-" + hashName + this.ext;
50
- return path.join(this.#dir, name);
48
+ const hashName = md5(key + "+SALT-poS1djRa4M2jXsWi").slice(0, 16);
49
+ const name = `${readableName}-${hashName}`;
50
+ return name;
51
+ }
52
+ #path(key: string) {
53
+ return path.join(
54
+ this.#dir,
55
+ sanitizeFilename(this.#filename(key) + this.ext)
56
+ );
51
57
  }
52
58
  async get(key: string) {
53
59
  // read memory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv-dir-store",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "author": "snomiao <snomiao@gmail.com>",
5
5
  "type": "module",
6
6
  "exports": {
@@ -8,6 +8,7 @@
8
8
  "types": "./index.ts"
9
9
  },
10
10
  "module": "index.ts",
11
+ "types": "./index.ts",
11
12
  "files": [
12
13
  "*.ts",
13
14
  "dist"