keyv-dir-store 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +649 -0
  2. package/package.json +2 -1
package/dist/index.js ADDED
@@ -0,0 +1,649 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
17
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
+
19
+ // node_modules/crypt/crypt.js
20
+ var require_crypt = __commonJS((exports, module) => {
21
+ (function() {
22
+ var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt = {
23
+ rotl: function(n, b) {
24
+ return n << b | n >>> 32 - b;
25
+ },
26
+ rotr: function(n, b) {
27
+ return n << 32 - b | n >>> b;
28
+ },
29
+ endian: function(n) {
30
+ if (n.constructor == Number) {
31
+ return crypt.rotl(n, 8) & 16711935 | crypt.rotl(n, 24) & 4278255360;
32
+ }
33
+ for (var i = 0;i < n.length; i++)
34
+ n[i] = crypt.endian(n[i]);
35
+ return n;
36
+ },
37
+ randomBytes: function(n) {
38
+ for (var bytes = [];n > 0; n--)
39
+ bytes.push(Math.floor(Math.random() * 256));
40
+ return bytes;
41
+ },
42
+ bytesToWords: function(bytes) {
43
+ for (var words = [], i = 0, b = 0;i < bytes.length; i++, b += 8)
44
+ words[b >>> 5] |= bytes[i] << 24 - b % 32;
45
+ return words;
46
+ },
47
+ wordsToBytes: function(words) {
48
+ for (var bytes = [], b = 0;b < words.length * 32; b += 8)
49
+ bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255);
50
+ return bytes;
51
+ },
52
+ bytesToHex: function(bytes) {
53
+ for (var hex = [], i = 0;i < bytes.length; i++) {
54
+ hex.push((bytes[i] >>> 4).toString(16));
55
+ hex.push((bytes[i] & 15).toString(16));
56
+ }
57
+ return hex.join("");
58
+ },
59
+ hexToBytes: function(hex) {
60
+ for (var bytes = [], c = 0;c < hex.length; c += 2)
61
+ bytes.push(parseInt(hex.substr(c, 2), 16));
62
+ return bytes;
63
+ },
64
+ bytesToBase64: function(bytes) {
65
+ for (var base64 = [], i = 0;i < bytes.length; i += 3) {
66
+ var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
67
+ for (var j = 0;j < 4; j++)
68
+ if (i * 8 + j * 6 <= bytes.length * 8)
69
+ base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63));
70
+ else
71
+ base64.push("=");
72
+ }
73
+ return base64.join("");
74
+ },
75
+ base64ToBytes: function(base64) {
76
+ base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
77
+ for (var bytes = [], i = 0, imod4 = 0;i < base64.length; imod4 = ++i % 4) {
78
+ if (imod4 == 0)
79
+ continue;
80
+ bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2);
81
+ }
82
+ return bytes;
83
+ }
84
+ };
85
+ module.exports = crypt;
86
+ })();
87
+ });
88
+
89
+ // node_modules/charenc/charenc.js
90
+ var require_charenc = __commonJS((exports, module) => {
91
+ var charenc = {
92
+ utf8: {
93
+ stringToBytes: function(str) {
94
+ return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
95
+ },
96
+ bytesToString: function(bytes) {
97
+ return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
98
+ }
99
+ },
100
+ bin: {
101
+ stringToBytes: function(str) {
102
+ for (var bytes = [], i = 0;i < str.length; i++)
103
+ bytes.push(str.charCodeAt(i) & 255);
104
+ return bytes;
105
+ },
106
+ bytesToString: function(bytes) {
107
+ for (var str = [], i = 0;i < bytes.length; i++)
108
+ str.push(String.fromCharCode(bytes[i]));
109
+ return str.join("");
110
+ }
111
+ }
112
+ };
113
+ module.exports = charenc;
114
+ });
115
+
116
+ // node_modules/is-buffer/index.js
117
+ var require_is_buffer = __commonJS((exports, module) => {
118
+ var isBuffer = function(obj) {
119
+ return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
120
+ };
121
+ var isSlowBuffer = function(obj) {
122
+ return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0));
123
+ };
124
+ /*!
125
+ * Determine if an object is a Buffer
126
+ *
127
+ * @author Feross Aboukhadijeh <https://feross.org>
128
+ * @license MIT
129
+ */
130
+ module.exports = function(obj) {
131
+ return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
132
+ };
133
+ });
134
+
135
+ // node_modules/md5/md5.js
136
+ var require_md5 = __commonJS((exports, module) => {
137
+ (function() {
138
+ var crypt = require_crypt(), utf8 = require_charenc().utf8, isBuffer = require_is_buffer(), bin = require_charenc().bin, md5 = function(message, options) {
139
+ if (message.constructor == String)
140
+ if (options && options.encoding === "binary")
141
+ message = bin.stringToBytes(message);
142
+ else
143
+ message = utf8.stringToBytes(message);
144
+ else if (isBuffer(message))
145
+ message = Array.prototype.slice.call(message, 0);
146
+ else if (!Array.isArray(message) && message.constructor !== Uint8Array)
147
+ message = message.toString();
148
+ var m = crypt.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
149
+ for (var i = 0;i < m.length; i++) {
150
+ m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360;
151
+ }
152
+ m[l >>> 5] |= 128 << l % 32;
153
+ m[(l + 64 >>> 9 << 4) + 14] = l;
154
+ var { _ff: FF, _gg: GG, _hh: HH, _ii: II } = md5;
155
+ for (var i = 0;i < m.length; i += 16) {
156
+ var aa = a, bb = b, cc = c, dd = d;
157
+ a = FF(a, b, c, d, m[i + 0], 7, -680876936);
158
+ d = FF(d, a, b, c, m[i + 1], 12, -389564586);
159
+ c = FF(c, d, a, b, m[i + 2], 17, 606105819);
160
+ b = FF(b, c, d, a, m[i + 3], 22, -1044525330);
161
+ a = FF(a, b, c, d, m[i + 4], 7, -176418897);
162
+ d = FF(d, a, b, c, m[i + 5], 12, 1200080426);
163
+ c = FF(c, d, a, b, m[i + 6], 17, -1473231341);
164
+ b = FF(b, c, d, a, m[i + 7], 22, -45705983);
165
+ a = FF(a, b, c, d, m[i + 8], 7, 1770035416);
166
+ d = FF(d, a, b, c, m[i + 9], 12, -1958414417);
167
+ c = FF(c, d, a, b, m[i + 10], 17, -42063);
168
+ b = FF(b, c, d, a, m[i + 11], 22, -1990404162);
169
+ a = FF(a, b, c, d, m[i + 12], 7, 1804603682);
170
+ d = FF(d, a, b, c, m[i + 13], 12, -40341101);
171
+ c = FF(c, d, a, b, m[i + 14], 17, -1502002290);
172
+ b = FF(b, c, d, a, m[i + 15], 22, 1236535329);
173
+ a = GG(a, b, c, d, m[i + 1], 5, -165796510);
174
+ d = GG(d, a, b, c, m[i + 6], 9, -1069501632);
175
+ c = GG(c, d, a, b, m[i + 11], 14, 643717713);
176
+ b = GG(b, c, d, a, m[i + 0], 20, -373897302);
177
+ a = GG(a, b, c, d, m[i + 5], 5, -701558691);
178
+ d = GG(d, a, b, c, m[i + 10], 9, 38016083);
179
+ c = GG(c, d, a, b, m[i + 15], 14, -660478335);
180
+ b = GG(b, c, d, a, m[i + 4], 20, -405537848);
181
+ a = GG(a, b, c, d, m[i + 9], 5, 568446438);
182
+ d = GG(d, a, b, c, m[i + 14], 9, -1019803690);
183
+ c = GG(c, d, a, b, m[i + 3], 14, -187363961);
184
+ b = GG(b, c, d, a, m[i + 8], 20, 1163531501);
185
+ a = GG(a, b, c, d, m[i + 13], 5, -1444681467);
186
+ d = GG(d, a, b, c, m[i + 2], 9, -51403784);
187
+ c = GG(c, d, a, b, m[i + 7], 14, 1735328473);
188
+ b = GG(b, c, d, a, m[i + 12], 20, -1926607734);
189
+ a = HH(a, b, c, d, m[i + 5], 4, -378558);
190
+ d = HH(d, a, b, c, m[i + 8], 11, -2022574463);
191
+ c = HH(c, d, a, b, m[i + 11], 16, 1839030562);
192
+ b = HH(b, c, d, a, m[i + 14], 23, -35309556);
193
+ a = HH(a, b, c, d, m[i + 1], 4, -1530992060);
194
+ d = HH(d, a, b, c, m[i + 4], 11, 1272893353);
195
+ c = HH(c, d, a, b, m[i + 7], 16, -155497632);
196
+ b = HH(b, c, d, a, m[i + 10], 23, -1094730640);
197
+ a = HH(a, b, c, d, m[i + 13], 4, 681279174);
198
+ d = HH(d, a, b, c, m[i + 0], 11, -358537222);
199
+ c = HH(c, d, a, b, m[i + 3], 16, -722521979);
200
+ b = HH(b, c, d, a, m[i + 6], 23, 76029189);
201
+ a = HH(a, b, c, d, m[i + 9], 4, -640364487);
202
+ d = HH(d, a, b, c, m[i + 12], 11, -421815835);
203
+ c = HH(c, d, a, b, m[i + 15], 16, 530742520);
204
+ b = HH(b, c, d, a, m[i + 2], 23, -995338651);
205
+ a = II(a, b, c, d, m[i + 0], 6, -198630844);
206
+ d = II(d, a, b, c, m[i + 7], 10, 1126891415);
207
+ c = II(c, d, a, b, m[i + 14], 15, -1416354905);
208
+ b = II(b, c, d, a, m[i + 5], 21, -57434055);
209
+ a = II(a, b, c, d, m[i + 12], 6, 1700485571);
210
+ d = II(d, a, b, c, m[i + 3], 10, -1894986606);
211
+ c = II(c, d, a, b, m[i + 10], 15, -1051523);
212
+ b = II(b, c, d, a, m[i + 1], 21, -2054922799);
213
+ a = II(a, b, c, d, m[i + 8], 6, 1873313359);
214
+ d = II(d, a, b, c, m[i + 15], 10, -30611744);
215
+ c = II(c, d, a, b, m[i + 6], 15, -1560198380);
216
+ b = II(b, c, d, a, m[i + 13], 21, 1309151649);
217
+ a = II(a, b, c, d, m[i + 4], 6, -145523070);
218
+ d = II(d, a, b, c, m[i + 11], 10, -1120210379);
219
+ c = II(c, d, a, b, m[i + 2], 15, 718787259);
220
+ b = II(b, c, d, a, m[i + 9], 21, -343485551);
221
+ a = a + aa >>> 0;
222
+ b = b + bb >>> 0;
223
+ c = c + cc >>> 0;
224
+ d = d + dd >>> 0;
225
+ }
226
+ return crypt.endian([a, b, c, d]);
227
+ };
228
+ md5._ff = function(a, b, c, d, x, s, t) {
229
+ var n = a + (b & c | ~b & d) + (x >>> 0) + t;
230
+ return (n << s | n >>> 32 - s) + b;
231
+ };
232
+ md5._gg = function(a, b, c, d, x, s, t) {
233
+ var n = a + (b & d | c & ~d) + (x >>> 0) + t;
234
+ return (n << s | n >>> 32 - s) + b;
235
+ };
236
+ md5._hh = function(a, b, c, d, x, s, t) {
237
+ var n = a + (b ^ c ^ d) + (x >>> 0) + t;
238
+ return (n << s | n >>> 32 - s) + b;
239
+ };
240
+ md5._ii = function(a, b, c, d, x, s, t) {
241
+ var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
242
+ return (n << s | n >>> 32 - s) + b;
243
+ };
244
+ md5._blocksize = 16;
245
+ md5._digestsize = 16;
246
+ module.exports = function(message, options) {
247
+ if (message === undefined || message === null)
248
+ throw new Error("Illegal argument " + message);
249
+ var digestbytes = crypt.wordsToBytes(md5(message, options));
250
+ return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt.bytesToHex(digestbytes);
251
+ };
252
+ })();
253
+ });
254
+
255
+ // node_modules/truncate-utf8-bytes/lib/truncate.js
256
+ var require_truncate = __commonJS((exports, module) => {
257
+ var isHighSurrogate = function(codePoint) {
258
+ return codePoint >= 55296 && codePoint <= 56319;
259
+ };
260
+ var isLowSurrogate = function(codePoint) {
261
+ return codePoint >= 56320 && codePoint <= 57343;
262
+ };
263
+ module.exports = function truncate(getLength, string, byteLength) {
264
+ if (typeof string !== "string") {
265
+ throw new Error("Input must be string");
266
+ }
267
+ var charLength = string.length;
268
+ var curByteLength = 0;
269
+ var codePoint;
270
+ var segment;
271
+ for (var i = 0;i < charLength; i += 1) {
272
+ codePoint = string.charCodeAt(i);
273
+ segment = string[i];
274
+ if (isHighSurrogate(codePoint) && isLowSurrogate(string.charCodeAt(i + 1))) {
275
+ i += 1;
276
+ segment += string[i];
277
+ }
278
+ curByteLength += getLength(segment);
279
+ if (curByteLength === byteLength) {
280
+ return string.slice(0, i + 1);
281
+ } else if (curByteLength > byteLength) {
282
+ return string.slice(0, i - segment.length + 1);
283
+ }
284
+ }
285
+ return string;
286
+ };
287
+ });
288
+
289
+ // node_modules/utf8-byte-length/browser.js
290
+ var require_browser = __commonJS((exports, module) => {
291
+ var isHighSurrogate = function(codePoint) {
292
+ return codePoint >= 55296 && codePoint <= 56319;
293
+ };
294
+ var isLowSurrogate = function(codePoint) {
295
+ return codePoint >= 56320 && codePoint <= 57343;
296
+ };
297
+ module.exports = function getByteLength(string) {
298
+ if (typeof string !== "string") {
299
+ throw new Error("Input must be string");
300
+ }
301
+ var charLength = string.length;
302
+ var byteLength = 0;
303
+ var codePoint = null;
304
+ var prevCodePoint = null;
305
+ for (var i = 0;i < charLength; i++) {
306
+ codePoint = string.charCodeAt(i);
307
+ if (isLowSurrogate(codePoint)) {
308
+ if (prevCodePoint != null && isHighSurrogate(prevCodePoint)) {
309
+ byteLength += 1;
310
+ } else {
311
+ byteLength += 3;
312
+ }
313
+ } else if (codePoint <= 127) {
314
+ byteLength += 1;
315
+ } else if (codePoint >= 128 && codePoint <= 2047) {
316
+ byteLength += 2;
317
+ } else if (codePoint >= 2048 && codePoint <= 65535) {
318
+ byteLength += 3;
319
+ }
320
+ prevCodePoint = codePoint;
321
+ }
322
+ return byteLength;
323
+ };
324
+ });
325
+
326
+ // node_modules/truncate-utf8-bytes/browser.js
327
+ var require_browser2 = __commonJS((exports, module) => {
328
+ var truncate = require_truncate();
329
+ var getLength = require_browser();
330
+ module.exports = truncate.bind(null, getLength);
331
+ });
332
+
333
+ // node_modules/sanitize-filename/index.js
334
+ var require_sanitize_filename = __commonJS((exports, module) => {
335
+ var sanitize = function(input, replacement) {
336
+ if (typeof input !== "string") {
337
+ throw new Error("Input must be string");
338
+ }
339
+ var sanitized = input.replace(illegalRe, replacement).replace(controlRe, replacement).replace(reservedRe, replacement).replace(windowsReservedRe, replacement).replace(windowsTrailingRe, replacement);
340
+ return truncate(sanitized, 255);
341
+ };
342
+ var truncate = require_browser2();
343
+ var illegalRe = /[\/\?<>\\:\*\|"]/g;
344
+ var controlRe = /[\x00-\x1f\x80-\x9f]/g;
345
+ var reservedRe = /^\.+$/;
346
+ var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
347
+ var windowsTrailingRe = /[\. ]+$/;
348
+ module.exports = function(input, options) {
349
+ var replacement = options && options.replacement || "";
350
+ var output = sanitize(input, replacement);
351
+ if (replacement === "") {
352
+ return output;
353
+ }
354
+ return sanitize(output, "");
355
+ };
356
+ });
357
+
358
+ // index.ts
359
+ var import_md5 = __toESM(require_md5(), 1);
360
+ var import_sanitize_filename = __toESM(require_sanitize_filename(), 1);
361
+ var {stat} = (()=>({}));
362
+ var {writeFile} = (()=>({}));
363
+ var {rm} = (()=>({}));
364
+ var {readFile, mkdir} = (()=>({}));
365
+
366
+ // node:path
367
+ var L = Object.create;
368
+ var b = Object.defineProperty;
369
+ var z = Object.getOwnPropertyDescriptor;
370
+ var D = Object.getOwnPropertyNames;
371
+ var T = Object.getPrototypeOf;
372
+ var R = Object.prototype.hasOwnProperty;
373
+ var _ = (f, e) => () => (e || f((e = { exports: {} }).exports, e), e.exports);
374
+ var E = (f, e) => {
375
+ for (var r in e)
376
+ b(f, r, { get: e[r], enumerable: true });
377
+ };
378
+ var C = (f, e, r, l) => {
379
+ if (e && typeof e == "object" || typeof e == "function")
380
+ for (let i of D(e))
381
+ !R.call(f, i) && i !== r && b(f, i, { get: () => e[i], enumerable: !(l = z(e, i)) || l.enumerable });
382
+ return f;
383
+ };
384
+ var A = (f, e, r) => (C(f, e, "default"), r && C(r, e, "default"));
385
+ var y = (f, e, r) => (r = f != null ? L(T(f)) : {}, C(e || !f || !f.__esModule ? b(r, "default", { value: f, enumerable: true }) : r, f));
386
+ var h = _((F, S) => {
387
+ function c(f) {
388
+ if (typeof f != "string")
389
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(f));
390
+ }
391
+ function w(f, e) {
392
+ for (var r = "", l = 0, i = -1, s = 0, n, t = 0;t <= f.length; ++t) {
393
+ if (t < f.length)
394
+ n = f.charCodeAt(t);
395
+ else {
396
+ if (n === 47)
397
+ break;
398
+ n = 47;
399
+ }
400
+ if (n === 47) {
401
+ if (!(i === t - 1 || s === 1))
402
+ if (i !== t - 1 && s === 2) {
403
+ if (r.length < 2 || l !== 2 || r.charCodeAt(r.length - 1) !== 46 || r.charCodeAt(r.length - 2) !== 46) {
404
+ if (r.length > 2) {
405
+ var a = r.lastIndexOf("/");
406
+ if (a !== r.length - 1) {
407
+ a === -1 ? (r = "", l = 0) : (r = r.slice(0, a), l = r.length - 1 - r.lastIndexOf("/")), i = t, s = 0;
408
+ continue;
409
+ }
410
+ } else if (r.length === 2 || r.length === 1) {
411
+ r = "", l = 0, i = t, s = 0;
412
+ continue;
413
+ }
414
+ }
415
+ e && (r.length > 0 ? r += "/.." : r = "..", l = 2);
416
+ } else
417
+ r.length > 0 ? r += "/" + f.slice(i + 1, t) : r = f.slice(i + 1, t), l = t - i - 1;
418
+ i = t, s = 0;
419
+ } else
420
+ n === 46 && s !== -1 ? ++s : s = -1;
421
+ }
422
+ return r;
423
+ }
424
+ function J(f, e) {
425
+ var r = e.dir || e.root, l = e.base || (e.name || "") + (e.ext || "");
426
+ return r ? r === e.root ? r + l : r + f + l : l;
427
+ }
428
+ var g = { resolve: function() {
429
+ for (var e = "", r = false, l, i = arguments.length - 1;i >= -1 && !r; i--) {
430
+ var s;
431
+ i >= 0 ? s = arguments[i] : (l === undefined && (l = process.cwd()), s = l), c(s), s.length !== 0 && (e = s + "/" + e, r = s.charCodeAt(0) === 47);
432
+ }
433
+ return e = w(e, !r), r ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
434
+ }, normalize: function(e) {
435
+ if (c(e), e.length === 0)
436
+ return ".";
437
+ var r = e.charCodeAt(0) === 47, l = e.charCodeAt(e.length - 1) === 47;
438
+ return e = w(e, !r), e.length === 0 && !r && (e = "."), e.length > 0 && l && (e += "/"), r ? "/" + e : e;
439
+ }, isAbsolute: function(e) {
440
+ return c(e), e.length > 0 && e.charCodeAt(0) === 47;
441
+ }, join: function() {
442
+ if (arguments.length === 0)
443
+ return ".";
444
+ for (var e, r = 0;r < arguments.length; ++r) {
445
+ var l = arguments[r];
446
+ c(l), l.length > 0 && (e === undefined ? e = l : e += "/" + l);
447
+ }
448
+ return e === undefined ? "." : g.normalize(e);
449
+ }, relative: function(e, r) {
450
+ if (c(e), c(r), e === r || (e = g.resolve(e), r = g.resolve(r), e === r))
451
+ return "";
452
+ for (var l = 1;l < e.length && e.charCodeAt(l) === 47; ++l)
453
+ ;
454
+ for (var i = e.length, s = i - l, n = 1;n < r.length && r.charCodeAt(n) === 47; ++n)
455
+ ;
456
+ for (var t = r.length, a = t - n, v = s < a ? s : a, u = -1, o = 0;o <= v; ++o) {
457
+ if (o === v) {
458
+ if (a > v) {
459
+ if (r.charCodeAt(n + o) === 47)
460
+ return r.slice(n + o + 1);
461
+ if (o === 0)
462
+ return r.slice(n + o);
463
+ } else
464
+ s > v && (e.charCodeAt(l + o) === 47 ? u = o : o === 0 && (u = 0));
465
+ break;
466
+ }
467
+ var k = e.charCodeAt(l + o), P = r.charCodeAt(n + o);
468
+ if (k !== P)
469
+ break;
470
+ k === 47 && (u = o);
471
+ }
472
+ var d = "";
473
+ for (o = l + u + 1;o <= i; ++o)
474
+ (o === i || e.charCodeAt(o) === 47) && (d.length === 0 ? d += ".." : d += "/..");
475
+ return d.length > 0 ? d + r.slice(n + u) : (n += u, r.charCodeAt(n) === 47 && ++n, r.slice(n));
476
+ }, _makeLong: function(e) {
477
+ return e;
478
+ }, dirname: function(e) {
479
+ if (c(e), e.length === 0)
480
+ return ".";
481
+ for (var r = e.charCodeAt(0), l = r === 47, i = -1, s = true, n = e.length - 1;n >= 1; --n)
482
+ if (r = e.charCodeAt(n), r === 47) {
483
+ if (!s) {
484
+ i = n;
485
+ break;
486
+ }
487
+ } else
488
+ s = false;
489
+ return i === -1 ? l ? "/" : "." : l && i === 1 ? "//" : e.slice(0, i);
490
+ }, basename: function(e, r) {
491
+ if (r !== undefined && typeof r != "string")
492
+ throw new TypeError('"ext" argument must be a string');
493
+ c(e);
494
+ var l = 0, i = -1, s = true, n;
495
+ if (r !== undefined && r.length > 0 && r.length <= e.length) {
496
+ if (r.length === e.length && r === e)
497
+ return "";
498
+ var t = r.length - 1, a = -1;
499
+ for (n = e.length - 1;n >= 0; --n) {
500
+ var v = e.charCodeAt(n);
501
+ if (v === 47) {
502
+ if (!s) {
503
+ l = n + 1;
504
+ break;
505
+ }
506
+ } else
507
+ a === -1 && (s = false, a = n + 1), t >= 0 && (v === r.charCodeAt(t) ? --t === -1 && (i = n) : (t = -1, i = a));
508
+ }
509
+ return l === i ? i = a : i === -1 && (i = e.length), e.slice(l, i);
510
+ } else {
511
+ for (n = e.length - 1;n >= 0; --n)
512
+ if (e.charCodeAt(n) === 47) {
513
+ if (!s) {
514
+ l = n + 1;
515
+ break;
516
+ }
517
+ } else
518
+ i === -1 && (s = false, i = n + 1);
519
+ return i === -1 ? "" : e.slice(l, i);
520
+ }
521
+ }, extname: function(e) {
522
+ c(e);
523
+ for (var r = -1, l = 0, i = -1, s = true, n = 0, t = e.length - 1;t >= 0; --t) {
524
+ var a = e.charCodeAt(t);
525
+ if (a === 47) {
526
+ if (!s) {
527
+ l = t + 1;
528
+ break;
529
+ }
530
+ continue;
531
+ }
532
+ i === -1 && (s = false, i = t + 1), a === 46 ? r === -1 ? r = t : n !== 1 && (n = 1) : r !== -1 && (n = -1);
533
+ }
534
+ return r === -1 || i === -1 || n === 0 || n === 1 && r === i - 1 && r === l + 1 ? "" : e.slice(r, i);
535
+ }, format: function(e) {
536
+ if (e === null || typeof e != "object")
537
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof e);
538
+ return J("/", e);
539
+ }, parse: function(e) {
540
+ c(e);
541
+ var r = { root: "", dir: "", base: "", ext: "", name: "" };
542
+ if (e.length === 0)
543
+ return r;
544
+ var l = e.charCodeAt(0), i = l === 47, s;
545
+ i ? (r.root = "/", s = 1) : s = 0;
546
+ for (var n = -1, t = 0, a = -1, v = true, u = e.length - 1, o = 0;u >= s; --u) {
547
+ if (l = e.charCodeAt(u), l === 47) {
548
+ if (!v) {
549
+ t = u + 1;
550
+ break;
551
+ }
552
+ continue;
553
+ }
554
+ a === -1 && (v = false, a = u + 1), l === 46 ? n === -1 ? n = u : o !== 1 && (o = 1) : n !== -1 && (o = -1);
555
+ }
556
+ return n === -1 || a === -1 || o === 0 || o === 1 && n === a - 1 && n === t + 1 ? a !== -1 && (t === 0 && i ? r.base = r.name = e.slice(1, a) : r.base = r.name = e.slice(t, a)) : (t === 0 && i ? (r.name = e.slice(1, n), r.base = e.slice(1, a)) : (r.name = e.slice(t, n), r.base = e.slice(t, a)), r.ext = e.slice(n, a)), t > 0 ? r.dir = e.slice(0, t - 1) : i && (r.dir = "/"), r;
557
+ }, sep: "/", delimiter: ":", win32: null, posix: null };
558
+ g.posix = g;
559
+ S.exports = g;
560
+ });
561
+ var m = {};
562
+ E(m, { default: () => q });
563
+ A(m, y(h()));
564
+ var q = y(h());
565
+
566
+ // index.ts
567
+ var {utimes} = (()=>({}));
568
+
569
+ class KeyvDirStore {
570
+ #dir;
571
+ #cache;
572
+ #ready;
573
+ #path;
574
+ ext = ".json";
575
+ constructor(dir, {
576
+ cache = new Map,
577
+ path,
578
+ ext
579
+ } = {}) {
580
+ this.#ready = mkdir(dir, { recursive: true });
581
+ this.#cache = cache;
582
+ this.#dir = dir;
583
+ this.#path = path ?? this.#defaultPath;
584
+ this.ext = ext ?? this.ext;
585
+ }
586
+ #defaultPath(key) {
587
+ const readableName = import_sanitize_filename.default(key).slice(4, 16);
588
+ const hashName = import_md5.default(this.#dir + key).slice(0, 16);
589
+ const name = readableName + "-" + hashName + this.ext;
590
+ return q.join(this.#dir, name);
591
+ }
592
+ async get(key) {
593
+ const cached = this.#cache.get(key);
594
+ if (cached) {
595
+ if (cached.expires && cached.expires < Date.now()) {
596
+ await this.delete(key);
597
+ } else {
598
+ return cached.value;
599
+ }
600
+ }
601
+ const stats = await stat(this.#path(key)).catch(() => null);
602
+ if (!stats)
603
+ return;
604
+ const expires = +stats.mtime;
605
+ if (expires !== 0) {
606
+ const expired = +stats.mtime < +Date.now();
607
+ if (expired) {
608
+ await this.delete(key);
609
+ return;
610
+ }
611
+ }
612
+ return await readFile(this.#path(key), "utf8").catch(() => {
613
+ return;
614
+ });
615
+ }
616
+ async set(key, value, ttl) {
617
+ if (!value)
618
+ return await this.delete(key);
619
+ const expires = ttl ? Date.now() + ttl : 0;
620
+ this.#cache.set(key, { value, expires });
621
+ await this.#ready;
622
+ await writeFile(this.#path(key), value);
623
+ await utimes(this.#path(key), +new Date, new Date(expires ?? 0));
624
+ return true;
625
+ }
626
+ async delete(key) {
627
+ this.#cache.delete(key);
628
+ await rm(this.#path(key), { force: true });
629
+ return true;
630
+ }
631
+ async clear() {
632
+ await rm(this.#dir, { recursive: true }).catch(() => {
633
+ return;
634
+ });
635
+ await mkdir(this.#dir, { recursive: true });
636
+ }
637
+ async has(key) {
638
+ return await this.get(key) !== undefined;
639
+ }
640
+ static serialize({ value }) {
641
+ return JSON.stringify(value, null, 2);
642
+ }
643
+ static deserialize(str) {
644
+ return { value: JSON.parse(str), expires: undefined };
645
+ }
646
+ }
647
+ export {
648
+ KeyvDirStore
649
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv-dir-store",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "author": "snomiao <snomiao@gmail.com>",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,6 +14,7 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "build": "bun build index.ts --outdir=dist",
17
+ "prerelease": "bun run build && bun run test",
17
18
  "release": "bunx standard-version && git push --follow-tags && npm publish",
18
19
  "test": "bun test"
19
20
  },