flat-cache 6.1.12 → 6.1.13
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/index.cjs +17 -9
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +17 -9
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -39,8 +39,8 @@ __export(index_exports, {
|
|
|
39
39
|
default: () => FlatCacheDefault
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
43
42
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
43
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
44
44
|
var import_cacheable = require("cacheable");
|
|
45
45
|
var import_flatted = require("flatted");
|
|
46
46
|
var import_hookified = require("hookified");
|
|
@@ -172,7 +172,9 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
172
172
|
*/
|
|
173
173
|
load(cacheId, cacheDir) {
|
|
174
174
|
try {
|
|
175
|
-
const filePath = import_node_path.default.resolve(
|
|
175
|
+
const filePath = import_node_path.default.resolve(
|
|
176
|
+
`${cacheDir ?? this._cacheDir}/${cacheId ?? this._cacheId}`
|
|
177
|
+
);
|
|
176
178
|
this.loadFile(filePath);
|
|
177
179
|
this.emit("load" /* LOAD */);
|
|
178
180
|
} catch (error) {
|
|
@@ -189,7 +191,9 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
189
191
|
const data = import_node_fs.default.readFileSync(pathToFile, "utf8");
|
|
190
192
|
const items = this._parse(data);
|
|
191
193
|
for (const key of Object.keys(items)) {
|
|
192
|
-
this._cache.set(items[key].key, items[key].value, {
|
|
194
|
+
this._cache.set(items[key].key, items[key].value, {
|
|
195
|
+
expire: items[key].expires
|
|
196
|
+
});
|
|
193
197
|
}
|
|
194
198
|
this._changesSinceLastSave = true;
|
|
195
199
|
}
|
|
@@ -209,7 +213,9 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
209
213
|
readStream.on("end", () => {
|
|
210
214
|
const items = this._parse(streamData);
|
|
211
215
|
for (const key of Object.keys(items)) {
|
|
212
|
-
this._cache.set(items[key].key, items[key].value, {
|
|
216
|
+
this._cache.set(items[key].key, items[key].value, {
|
|
217
|
+
expire: items[key].expires
|
|
218
|
+
});
|
|
213
219
|
}
|
|
214
220
|
this._changesSinceLastSave = true;
|
|
215
221
|
onEnd();
|
|
@@ -279,6 +285,7 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
279
285
|
* @param key {string} the key to set
|
|
280
286
|
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
281
287
|
*/
|
|
288
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
282
289
|
setKey(key, value, ttl) {
|
|
283
290
|
this.set(key, value, ttl);
|
|
284
291
|
}
|
|
@@ -289,6 +296,7 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
289
296
|
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
290
297
|
* @param [ttl] {number} the time to live in milliseconds
|
|
291
298
|
*/
|
|
299
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
292
300
|
set(key, value, ttl) {
|
|
293
301
|
this._cache.set(key, value, ttl);
|
|
294
302
|
this._changesSinceLastSave = true;
|
|
@@ -312,11 +320,11 @@ var FlatCache = class extends import_hookified.Hookified {
|
|
|
312
320
|
this.emit("delete" /* DELETE */, key);
|
|
313
321
|
}
|
|
314
322
|
/**
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
323
|
+
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
|
|
324
|
+
* @method getKey<T>
|
|
325
|
+
* @param key {String} the name of the key to retrieve
|
|
326
|
+
* @returns {*} at T the value from the key
|
|
327
|
+
*/
|
|
320
328
|
getKey(key) {
|
|
321
329
|
return this.get(key);
|
|
322
330
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -165,11 +165,11 @@ declare class FlatCache extends Hookified {
|
|
|
165
165
|
*/
|
|
166
166
|
delete(key: string): void;
|
|
167
167
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
|
|
169
|
+
* @method getKey<T>
|
|
170
|
+
* @param key {String} the name of the key to retrieve
|
|
171
|
+
* @returns {*} at T the value from the key
|
|
172
|
+
*/
|
|
173
173
|
getKey<T>(key: string): T;
|
|
174
174
|
/**
|
|
175
175
|
* Return the value of the provided key
|
package/dist/index.d.ts
CHANGED
|
@@ -165,11 +165,11 @@ declare class FlatCache extends Hookified {
|
|
|
165
165
|
*/
|
|
166
166
|
delete(key: string): void;
|
|
167
167
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
|
|
169
|
+
* @method getKey<T>
|
|
170
|
+
* @param key {String} the name of the key to retrieve
|
|
171
|
+
* @returns {*} at T the value from the key
|
|
172
|
+
*/
|
|
173
173
|
getKey<T>(key: string): T;
|
|
174
174
|
/**
|
|
175
175
|
* Return the value of the provided key
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import path from "path";
|
|
3
2
|
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
4
|
import { CacheableMemory } from "cacheable";
|
|
5
5
|
import { parse, stringify } from "flatted";
|
|
6
6
|
import { Hookified } from "hookified";
|
|
@@ -132,7 +132,9 @@ var FlatCache = class extends Hookified {
|
|
|
132
132
|
*/
|
|
133
133
|
load(cacheId, cacheDir) {
|
|
134
134
|
try {
|
|
135
|
-
const filePath = path.resolve(
|
|
135
|
+
const filePath = path.resolve(
|
|
136
|
+
`${cacheDir ?? this._cacheDir}/${cacheId ?? this._cacheId}`
|
|
137
|
+
);
|
|
136
138
|
this.loadFile(filePath);
|
|
137
139
|
this.emit("load" /* LOAD */);
|
|
138
140
|
} catch (error) {
|
|
@@ -149,7 +151,9 @@ var FlatCache = class extends Hookified {
|
|
|
149
151
|
const data = fs.readFileSync(pathToFile, "utf8");
|
|
150
152
|
const items = this._parse(data);
|
|
151
153
|
for (const key of Object.keys(items)) {
|
|
152
|
-
this._cache.set(items[key].key, items[key].value, {
|
|
154
|
+
this._cache.set(items[key].key, items[key].value, {
|
|
155
|
+
expire: items[key].expires
|
|
156
|
+
});
|
|
153
157
|
}
|
|
154
158
|
this._changesSinceLastSave = true;
|
|
155
159
|
}
|
|
@@ -169,7 +173,9 @@ var FlatCache = class extends Hookified {
|
|
|
169
173
|
readStream.on("end", () => {
|
|
170
174
|
const items = this._parse(streamData);
|
|
171
175
|
for (const key of Object.keys(items)) {
|
|
172
|
-
this._cache.set(items[key].key, items[key].value, {
|
|
176
|
+
this._cache.set(items[key].key, items[key].value, {
|
|
177
|
+
expire: items[key].expires
|
|
178
|
+
});
|
|
173
179
|
}
|
|
174
180
|
this._changesSinceLastSave = true;
|
|
175
181
|
onEnd();
|
|
@@ -239,6 +245,7 @@ var FlatCache = class extends Hookified {
|
|
|
239
245
|
* @param key {string} the key to set
|
|
240
246
|
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
241
247
|
*/
|
|
248
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
242
249
|
setKey(key, value, ttl) {
|
|
243
250
|
this.set(key, value, ttl);
|
|
244
251
|
}
|
|
@@ -249,6 +256,7 @@ var FlatCache = class extends Hookified {
|
|
|
249
256
|
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
250
257
|
* @param [ttl] {number} the time to live in milliseconds
|
|
251
258
|
*/
|
|
259
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
252
260
|
set(key, value, ttl) {
|
|
253
261
|
this._cache.set(key, value, ttl);
|
|
254
262
|
this._changesSinceLastSave = true;
|
|
@@ -272,11 +280,11 @@ var FlatCache = class extends Hookified {
|
|
|
272
280
|
this.emit("delete" /* DELETE */, key);
|
|
273
281
|
}
|
|
274
282
|
/**
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
|
|
284
|
+
* @method getKey<T>
|
|
285
|
+
* @param key {String} the name of the key to retrieve
|
|
286
|
+
* @returns {*} at T the value from the key
|
|
287
|
+
*/
|
|
280
288
|
getKey(key) {
|
|
281
289
|
return this.get(key);
|
|
282
290
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-cache",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.13",
|
|
4
4
|
"description": "A simple key/value storage using files to persist the data",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"file-system-cache"
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@biomejs/biome": "^2.2.0",
|
|
55
56
|
"@faker-js/faker": "^9.9.0",
|
|
56
|
-
"@types/node": "^24.
|
|
57
|
+
"@types/node": "^24.3.0",
|
|
57
58
|
"@vitest/coverage-v8": "^3.2.4",
|
|
58
59
|
"rimraf": "^6.0.1",
|
|
59
60
|
"tsup": "^8.5.0",
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"vitest": "^3.2.4"
|
|
62
|
-
"xo": "^1.2.1"
|
|
61
|
+
"typescript": "^5.9.2",
|
|
62
|
+
"vitest": "^3.2.4"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"flatted": "^3.3.3",
|
|
66
|
-
"hookified": "^1.
|
|
67
|
-
"cacheable": "^1.10.
|
|
66
|
+
"hookified": "^1.11.0",
|
|
67
|
+
"cacheable": "^1.10.4"
|
|
68
68
|
},
|
|
69
69
|
"files": [
|
|
70
70
|
"dist",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
75
75
|
"prepublish": "pnpm build",
|
|
76
|
-
"test": "
|
|
77
|
-
"test:ci": "
|
|
76
|
+
"test": "biome check --write && vitest run --coverage",
|
|
77
|
+
"test:ci": "biome check && vitest run --coverage",
|
|
78
78
|
"clean": "rimraf ./dist ./coverage ./node_modules"
|
|
79
79
|
}
|
|
80
80
|
}
|