flat-cache 6.1.12 → 6.1.14

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 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(`${cacheDir ?? this._cacheDir}/${cacheId ?? this._cacheId}`);
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, { expire: items[key].expires });
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, { expire: items[key].expires });
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();
@@ -242,10 +248,11 @@ var FlatCache = class extends import_hookified.Hookified {
242
248
  return result;
243
249
  }
244
250
  /**
245
- * Returns an array with all the items in the cache { key, value, ttl }
251
+ * Returns an array with all the items in the cache { key, value, expires }
246
252
  * @method items
247
253
  * @returns {Array}
248
254
  */
255
+ // biome-ignore lint/suspicious/noExplicitAny: cache items can store any value
249
256
  get items() {
250
257
  return [...this._cache.items];
251
258
  }
@@ -279,6 +286,7 @@ var FlatCache = class extends import_hookified.Hookified {
279
286
  * @param key {string} the key to set
280
287
  * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
281
288
  */
289
+ // biome-ignore lint/suspicious/noExplicitAny: type format
282
290
  setKey(key, value, ttl) {
283
291
  this.set(key, value, ttl);
284
292
  }
@@ -289,6 +297,7 @@ var FlatCache = class extends import_hookified.Hookified {
289
297
  * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
290
298
  * @param [ttl] {number} the time to live in milliseconds
291
299
  */
300
+ // biome-ignore lint/suspicious/noExplicitAny: type format
292
301
  set(key, value, ttl) {
293
302
  this._cache.set(key, value, ttl);
294
303
  this._changesSinceLastSave = true;
@@ -312,11 +321,11 @@ var FlatCache = class extends import_hookified.Hookified {
312
321
  this.emit("delete" /* DELETE */, key);
313
322
  }
314
323
  /**
315
- * (Legacy) Return the value of the provided key. This method will be deprecated in the future
316
- * @method getKey<T>
317
- * @param key {String} the name of the key to retrieve
318
- * @returns {*} at T the value from the key
319
- */
324
+ * (Legacy) Return the value of the provided key. This method will be deprecated in the future
325
+ * @method getKey<T>
326
+ * @param key {String} the name of the key to retrieve
327
+ * @returns {*} at T the value from the key
328
+ */
320
329
  getKey(key) {
321
330
  return this.get(key);
322
331
  }
package/dist/index.d.cts CHANGED
@@ -110,15 +110,15 @@ declare class FlatCache extends Hookified {
110
110
  */
111
111
  all(): Record<string, any>;
112
112
  /**
113
- * Returns an array with all the items in the cache { key, value, ttl }
113
+ * Returns an array with all the items in the cache { key, value, expires }
114
114
  * @method items
115
115
  * @returns {Array}
116
116
  */
117
- get items(): {
117
+ get items(): Array<{
118
118
  key: string;
119
119
  value: any;
120
120
  expires?: number;
121
- }[];
121
+ }>;
122
122
  /**
123
123
  * Returns the path to the file where the cache is persisted
124
124
  * @method cacheFilePath
@@ -165,11 +165,11 @@ declare class FlatCache extends Hookified {
165
165
  */
166
166
  delete(key: string): void;
167
167
  /**
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
- */
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
@@ -110,15 +110,15 @@ declare class FlatCache extends Hookified {
110
110
  */
111
111
  all(): Record<string, any>;
112
112
  /**
113
- * Returns an array with all the items in the cache { key, value, ttl }
113
+ * Returns an array with all the items in the cache { key, value, expires }
114
114
  * @method items
115
115
  * @returns {Array}
116
116
  */
117
- get items(): {
117
+ get items(): Array<{
118
118
  key: string;
119
119
  value: any;
120
120
  expires?: number;
121
- }[];
121
+ }>;
122
122
  /**
123
123
  * Returns the path to the file where the cache is persisted
124
124
  * @method cacheFilePath
@@ -165,11 +165,11 @@ declare class FlatCache extends Hookified {
165
165
  */
166
166
  delete(key: string): void;
167
167
  /**
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
- */
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(`${cacheDir ?? this._cacheDir}/${cacheId ?? this._cacheId}`);
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, { expire: items[key].expires });
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, { expire: items[key].expires });
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();
@@ -202,10 +208,11 @@ var FlatCache = class extends Hookified {
202
208
  return result;
203
209
  }
204
210
  /**
205
- * Returns an array with all the items in the cache { key, value, ttl }
211
+ * Returns an array with all the items in the cache { key, value, expires }
206
212
  * @method items
207
213
  * @returns {Array}
208
214
  */
215
+ // biome-ignore lint/suspicious/noExplicitAny: cache items can store any value
209
216
  get items() {
210
217
  return [...this._cache.items];
211
218
  }
@@ -239,6 +246,7 @@ var FlatCache = class extends Hookified {
239
246
  * @param key {string} the key to set
240
247
  * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
241
248
  */
249
+ // biome-ignore lint/suspicious/noExplicitAny: type format
242
250
  setKey(key, value, ttl) {
243
251
  this.set(key, value, ttl);
244
252
  }
@@ -249,6 +257,7 @@ var FlatCache = class extends Hookified {
249
257
  * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
250
258
  * @param [ttl] {number} the time to live in milliseconds
251
259
  */
260
+ // biome-ignore lint/suspicious/noExplicitAny: type format
252
261
  set(key, value, ttl) {
253
262
  this._cache.set(key, value, ttl);
254
263
  this._changesSinceLastSave = true;
@@ -272,11 +281,11 @@ var FlatCache = class extends Hookified {
272
281
  this.emit("delete" /* DELETE */, key);
273
282
  }
274
283
  /**
275
- * (Legacy) Return the value of the provided key. This method will be deprecated in the future
276
- * @method getKey<T>
277
- * @param key {String} the name of the key to retrieve
278
- * @returns {*} at T the value from the key
279
- */
284
+ * (Legacy) Return the value of the provided key. This method will be deprecated in the future
285
+ * @method getKey<T>
286
+ * @param key {String} the name of the key to retrieve
287
+ * @returns {*} at T the value from the key
288
+ */
280
289
  getKey(key) {
281
290
  return this.get(key);
282
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flat-cache",
3
- "version": "6.1.12",
3
+ "version": "6.1.14",
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
- "@faker-js/faker": "^9.9.0",
56
- "@types/node": "^24.1.0",
55
+ "@biomejs/biome": "^2.2.4",
56
+ "@faker-js/faker": "^10.0.0",
57
+ "@types/node": "^24.5.0",
57
58
  "@vitest/coverage-v8": "^3.2.4",
58
59
  "rimraf": "^6.0.1",
59
60
  "tsup": "^8.5.0",
60
- "typescript": "^5.8.3",
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.10.0",
67
- "cacheable": "^1.10.3"
66
+ "hookified": "^1.12.0",
67
+ "cacheable": "^2.0.1"
68
68
  },
69
69
  "files": [
70
70
  "dist",
@@ -73,8 +73,9 @@
73
73
  "scripts": {
74
74
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
75
75
  "prepublish": "pnpm build",
76
- "test": "xo --fix && vitest run --coverage",
77
- "test:ci": "xo && vitest run --coverage",
76
+ "lint": "biome check --write --error-on-warnings",
77
+ "test": "pnpm lint && vitest run --coverage",
78
+ "test:ci": "biome check --error-on-warnings && vitest run --coverage",
78
79
  "clean": "rimraf ./dist ./coverage ./node_modules"
79
80
  }
80
81
  }