node-persist-manager 1.0.8 → 1.1.0

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/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![npm version](https://img.shields.io/npm/v/node-persist-manager.svg)](https://www.npmjs.com/package/node-persist-manager)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/node-persist-manager.svg)](https://www.npmjs.com/package/node-persist-manager)
5
5
  ![Node.js CI](https://github.com/Luligu/node-persist-manager/actions/workflows/build.yml/badge.svg)
6
+ ![CodeQL](https://github.com/Luligu/node-persist-manager/actions/workflows/codeql.yml/badge.svg)
7
+ [![codecov](https://codecov.io/gh/Luligu/node-persist-manager/branch/main/graph/badge.svg)](https://codecov.io/gh/Luligu/node-persist-manager)
6
8
 
7
9
  ---
8
10
 
@@ -32,17 +34,28 @@ To get started with NodeStorage in your package
32
34
  npm install node-persist-manager
33
35
  ```
34
36
 
37
+ ### TypeScript & ESM Support
38
+
39
+ This package is written in **TypeScript** and distributed as an **ECMAScript module (ESM)**. You should use `import` statements to use it in your project:
40
+
41
+ ```typescript
42
+ import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
43
+ ```
44
+
45
+ - If you are using CommonJS, consider using dynamic `import()` or transpiling your code to ESM.
46
+ - Type definitions are included out of the box for TypeScript users.
47
+
35
48
  # Usage
36
49
 
37
50
  ## Initializing NodeStorageManager:
38
51
 
39
52
  Create an instance of NodeStorageManager to manage your storage instances.
40
53
 
41
- ```
54
+ ```typescript
42
55
  import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
43
56
  ```
44
57
 
45
- ```
58
+ ```typescript
46
59
  const storageManager = new NodeStorageManager({
47
60
  dir: 'path/to/storage/directory', // Optional: Customize the storage directory.
48
61
  logging: true, // Optional: Enable logging.
@@ -53,7 +66,7 @@ const storageManager = new NodeStorageManager({
53
66
 
54
67
  Use the manager to create a new storage context.
55
68
 
56
- ```
69
+ ```typescript
57
70
  const myStorage = await storageManager.createStorage('myStorageName');
58
71
  ```
59
72
 
@@ -61,26 +74,26 @@ Using the Storage:
61
74
 
62
75
  ## Set a value:
63
76
 
64
- ```
77
+ ```typescript
65
78
  await myStorage.set('myKey', 'myValue');
66
79
  ```
67
80
 
68
81
  ## Get a value:
69
82
 
70
- ```
83
+ ```typescript
71
84
  const value = await myStorage.get('myKey');
72
85
  console.log(value); // Outputs: 'myValue'
73
86
  ```
74
87
 
75
88
  ## Remove a value:
76
89
 
77
- ```
90
+ ```typescript
78
91
  await myStorage.remove('myKey');
79
92
  ```
80
93
 
81
94
  ## Clear the storage:
82
95
 
83
- ```
96
+ ```typescript
84
97
  await myStorage.clear();
85
98
  ```
86
99
 
@@ -3,16 +3,29 @@
3
3
  *
4
4
  * @file nodeStorage.ts
5
5
  * @author Luca Liguori
6
- * @date 2024-02-02
6
+ * @created 2024-02-02
7
7
  * @version 1.0.1
8
+ * @license Apache-2.0
8
9
  *
9
- * All rights reserved.
10
+ * Copyright 2024, 2025, 2026 Luca Liguori.
10
11
  *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
11
23
  */
12
- import NodePersist, { LocalStorage, InitOptions } from 'node-persist';
24
+ import NodePersist, { LocalStorage } from 'node-persist';
25
+ import type { InitOptions } from 'node-persist';
13
26
  export type NodeStorageKey = string;
27
+ export type NodeStorageValue = unknown;
14
28
  export type NodeStorageName = string;
15
- export { InitOptions } from 'node-persist';
16
29
  /**
17
30
  * Class responsible for managing multiple node storages.
18
31
  */
@@ -22,6 +35,7 @@ export declare class NodeStorageManager {
22
35
  private storageNames;
23
36
  /**
24
37
  * Initializes a new instance of NodeStorageManager with optional initialization options.
38
+ *
25
39
  * @param {InitOptions} [initOptions] - Optional initialization options to customize the storage.
26
40
  */
27
41
  constructor(initOptions?: InitOptions);
@@ -31,23 +45,28 @@ export declare class NodeStorageManager {
31
45
  close(): Promise<void>;
32
46
  /**
33
47
  * Creates and initializes a new storage with a given name.
48
+ *
34
49
  * @param {string} storageName - The name of the new storage to create.
35
50
  * @returns {Promise<NodeStorage>} A promise that resolves to the newly created NodeStorage instance.
36
51
  */
37
52
  createStorage(storageName: string): Promise<NodeStorage>;
38
53
  /**
39
54
  * Removes a storage by its name.
55
+ *
40
56
  * @param {string} storageName - The name of the storage to remove.
41
57
  * @returns {Promise<boolean>} A promise that resolves to true if the storage was successfully removed, otherwise false.
42
58
  */
43
59
  removeStorage(storageName: string): Promise<boolean>;
44
60
  /**
45
61
  * Retrieves the names of all available storages.
62
+ *
46
63
  * @returns {Promise<NodeStorageName[]>} A promise that resolves to an array of storage names.
47
64
  */
48
65
  getStorageNames(): Promise<NodeStorageName[]>;
49
66
  /**
50
67
  * Logs the names of all managed storages to the console.
68
+ *
69
+ * @returns {Promise<number>} A promise that resolves to the number of storages managed by this NodeStorageManager.
51
70
  */
52
71
  logStorage(): Promise<number>;
53
72
  }
@@ -59,6 +78,7 @@ export declare class NodeStorage {
59
78
  private readonly initOptions;
60
79
  /**
61
80
  * Creates an instance of NodeStorage.
81
+ *
62
82
  * @param {LocalStorage} storage - The local storage instance.
63
83
  * @param {InitOptions} initOptions - The initialization options.
64
84
  */
@@ -69,6 +89,7 @@ export declare class NodeStorage {
69
89
  close(): Promise<void>;
70
90
  /**
71
91
  * Sets a value for a given key in the storage.
92
+ *
72
93
  * @template T - The type of the value to be stored.
73
94
  * @param {NodeStorageKey} key - The key under which the value is stored.
74
95
  * @param {T} value - The value to store.
@@ -78,31 +99,70 @@ export declare class NodeStorage {
78
99
  /**
79
100
  * Retrieves a value for a given key from the storage.
80
101
  * If the key does not exist, returns a default value if provided.
102
+ *
81
103
  * @template T - The type of the value to retrieve.
82
104
  * @param {NodeStorageKey} key - The key of the value to retrieve.
83
105
  * @param {T} [defaultValue] - The default value to return if the key is not found.
84
106
  * @returns {Promise<T>} A promise that resolves with the value.
85
107
  */
86
- get<T = any>(key: NodeStorageKey, defaultValue?: T): Promise<T>;
108
+ get<T = any>(key: NodeStorageKey, defaultValue?: T): Promise<T | undefined>;
109
+ /**
110
+ * Checks if the storage has a given key.
111
+ *
112
+ * @param {NodeStorageKey} key - The key to check.
113
+ * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
114
+ */
115
+ has(key: NodeStorageKey): Promise<boolean>;
87
116
  /**
88
117
  * Checks if the storage includes a given key.
118
+ *
89
119
  * @param {NodeStorageKey} key - The key to check.
90
120
  * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
91
121
  */
92
122
  includes(key: NodeStorageKey): Promise<boolean>;
123
+ /**
124
+ * Checks if the storage includes a given key.
125
+ *
126
+ * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
127
+ */
128
+ size(): Promise<number>;
93
129
  /**
94
130
  * Removes a value for a given key from the storage.
131
+ *
95
132
  * @param {NodeStorageKey} key - The key of the value to remove.
96
133
  * @returns {Promise<NodePersist.DeleteFileResult>} A promise that resolves with the result of deleting the file.
97
134
  */
98
135
  remove(key: NodeStorageKey): Promise<NodePersist.DeleteFileResult>;
136
+ /**
137
+ * Retrieves all data from the storage as a record.
138
+ *
139
+ * @returns {Promise<Record<NodeStorageKey, NodeStorageValue>>} A promise that resolves with the data in the storage.
140
+ */
141
+ data(): Promise<Record<NodeStorageKey, NodeStorageValue>>;
142
+ /**
143
+ * Retrieves the keys of the entries in the storage.
144
+ *
145
+ * @returns {Promise<number>} A promise that resolves with the keys of the entries in the storage.
146
+ */
147
+ keys(): Promise<NodeStorageKey[]>;
148
+ /**
149
+ * Retrieves the values of the entries in the storage.
150
+ *
151
+ * @template T - The type of the values to retrieve.
152
+ * @returns {Promise<T[]>} A promise that resolves with an array of values.
153
+ */
154
+ values<T = unknown>(): Promise<T[]>;
155
+ static healthCheck(storage: NodePersist.LocalStorage): Promise<boolean>;
99
156
  /**
100
157
  * Clears all entries from the storage.
158
+ *
101
159
  * @returns {Promise<void>} A promise that resolves when the storage is cleared.
102
160
  */
103
161
  clear(): Promise<void>;
104
162
  /**
105
163
  * Logs the current storage state to the console.
164
+ *
165
+ * @returns {Promise<number>} A promise that resolves with the number of keys in the storage.
106
166
  */
107
167
  logStorage(): Promise<number>;
108
168
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nodeStorage.d.ts","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAEH,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAItE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,YAAY,CAAyB;IAE7C;;;OAGG;gBACS,WAAW,CAAC,EAAE,WAAW;IA6BrC;;OAEG;IACG,KAAK;IAOX;;;;OAIG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAyB9D;;;;OAIG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuB1D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAKnD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAQpC;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,Q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;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAS/D;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIvC;;;;;OAKG;IACG,MAAM,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC;WAI5B,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAsB7E;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAQpC"}
@@ -4,15 +4,27 @@
4
4
  *
5
5
  * @file nodeStorage.ts
6
6
  * @author Luca Liguori
7
- * @date 2024-02-02
7
+ * @created 2024-02-02
8
8
  * @version 1.0.1
9
+ * @license Apache-2.0
9
10
  *
10
- * All rights reserved.
11
+ * Copyright 2024, 2025, 2026 Luca Liguori.
11
12
  *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
12
24
  */
25
+ import { rm } from 'node:fs/promises';
26
+ import path from 'node:path';
13
27
  import NodePersist from 'node-persist';
14
- import { rm } from 'fs/promises';
15
- import path from 'path';
16
28
  /**
17
29
  * Class responsible for managing multiple node storages.
18
30
  */
@@ -22,6 +34,7 @@ export class NodeStorageManager {
22
34
  storageNames = [];
23
35
  /**
24
36
  * Initializes a new instance of NodeStorageManager with optional initialization options.
37
+ *
25
38
  * @param {InitOptions} [initOptions] - Optional initialization options to customize the storage.
26
39
  */
27
40
  constructor(initOptions) {
@@ -42,11 +55,6 @@ export class NodeStorageManager {
42
55
  if (this.initOptions.logging === true) {
43
56
  console.log(`Storage manager initialized with options ${JSON.stringify(this.initOptions)}`);
44
57
  }
45
- /*
46
- this.get<Array<NodeStorageName>>('storageNames').then(storageNames => {
47
- this.storageNames = storageNames;
48
- });
49
- */
50
58
  }
51
59
  /**
52
60
  * Closes the node storage manager by stopping the expired keys interval and the write queue interval.
@@ -59,6 +67,7 @@ export class NodeStorageManager {
59
67
  }
60
68
  /**
61
69
  * Creates and initializes a new storage with a given name.
70
+ *
62
71
  * @param {string} storageName - The name of the new storage to create.
63
72
  * @returns {Promise<NodeStorage>} A promise that resolves to the newly created NodeStorage instance.
64
73
  */
@@ -68,24 +77,21 @@ export class NodeStorageManager {
68
77
  Object.assign(initOptions, this.initOptions, { dir: path.join(this.initOptions.dir, '.' + storageName) });
69
78
  const storage = NodePersist.create(initOptions);
70
79
  await storage.init(initOptions);
71
- // console.log(`Created storage ${storageName} with options ${JSON.stringify(initOptions)}`);
72
80
  if (storage.options.writeQueue === false) {
73
81
  clearInterval(storage._writeQueueInterval);
74
82
  storage._writeQueueInterval = undefined;
75
83
  }
76
84
  // Update storageNames
77
85
  this.storageNames = (await this.storage.get('storageNames')) ?? [];
78
- // console.log('Storage list(1):', this.storageNames);
79
86
  if (!this.storageNames.includes(storageName)) {
80
87
  this.storageNames.push(storageName);
81
88
  }
82
- // console.log('Storage list(2):', this.storageNames);
83
89
  await this.storage.set('storageNames', this.storageNames);
84
- // console.log('Storage list(3):', await this.storage.get('storageNames') );
85
90
  return new NodeStorage(storage, initOptions);
86
91
  }
87
92
  /**
88
93
  * Removes a storage by its name.
94
+ *
89
95
  * @param {string} storageName - The name of the storage to remove.
90
96
  * @returns {Promise<boolean>} A promise that resolves to true if the storage was successfully removed, otherwise false.
91
97
  */
@@ -105,13 +111,14 @@ export class NodeStorageManager {
105
111
  // console.log('Storage list:', await this.storage.get('storageNames') );
106
112
  return true;
107
113
  }
108
- catch (err) {
109
- // console.error('Error removing storage:', err);
114
+ catch (_err) {
115
+ // console.error('Error removing storage:', _err);
110
116
  return false;
111
117
  }
112
118
  }
113
119
  /**
114
120
  * Retrieves the names of all available storages.
121
+ *
115
122
  * @returns {Promise<NodeStorageName[]>} A promise that resolves to an array of storage names.
116
123
  */
117
124
  async getStorageNames() {
@@ -120,6 +127,8 @@ export class NodeStorageManager {
120
127
  }
121
128
  /**
122
129
  * Logs the names of all managed storages to the console.
130
+ *
131
+ * @returns {Promise<number>} A promise that resolves to the number of storages managed by this NodeStorageManager.
123
132
  */
124
133
  async logStorage() {
125
134
  console.log('This NodeStorageManager has these storages:');
@@ -138,6 +147,7 @@ export class NodeStorage {
138
147
  initOptions;
139
148
  /**
140
149
  * Creates an instance of NodeStorage.
150
+ *
141
151
  * @param {LocalStorage} storage - The local storage instance.
142
152
  * @param {InitOptions} initOptions - The initialization options.
143
153
  */
@@ -156,6 +166,7 @@ export class NodeStorage {
156
166
  }
157
167
  /**
158
168
  * Sets a value for a given key in the storage.
169
+ *
159
170
  * @template T - The type of the value to be stored.
160
171
  * @param {NodeStorageKey} key - The key under which the value is stored.
161
172
  * @param {T} value - The value to store.
@@ -168,6 +179,7 @@ export class NodeStorage {
168
179
  /**
169
180
  * Retrieves a value for a given key from the storage.
170
181
  * If the key does not exist, returns a default value if provided.
182
+ *
171
183
  * @template T - The type of the value to retrieve.
172
184
  * @param {NodeStorageKey} key - The key of the value to retrieve.
173
185
  * @param {T} [defaultValue] - The default value to return if the key is not found.
@@ -176,27 +188,109 @@ export class NodeStorage {
176
188
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
189
  async get(key, defaultValue) {
178
190
  const value = await this.storage.getItem(key);
179
- return value !== undefined ? value : defaultValue;
191
+ if (value !== undefined) {
192
+ return value;
193
+ }
194
+ if (defaultValue !== undefined) {
195
+ return defaultValue;
196
+ }
197
+ return undefined;
180
198
  }
181
199
  /**
182
- * Checks if the storage includes a given key.
200
+ * Checks if the storage has a given key.
201
+ *
183
202
  * @param {NodeStorageKey} key - The key to check.
184
203
  * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
185
204
  */
186
- async includes(key) {
205
+ async has(key) {
187
206
  const keys = await this.storage.keys();
188
207
  return keys.includes(key);
189
208
  }
209
+ /**
210
+ * Checks if the storage includes a given key.
211
+ *
212
+ * @param {NodeStorageKey} key - The key to check.
213
+ * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
214
+ */
215
+ async includes(key) {
216
+ return this.has(key);
217
+ }
218
+ /**
219
+ * Checks if the storage includes a given key.
220
+ *
221
+ * @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
222
+ */
223
+ async size() {
224
+ return this.storage.length();
225
+ }
190
226
  /**
191
227
  * Removes a value for a given key from the storage.
228
+ *
192
229
  * @param {NodeStorageKey} key - The key of the value to remove.
193
230
  * @returns {Promise<NodePersist.DeleteFileResult>} A promise that resolves with the result of deleting the file.
194
231
  */
195
232
  async remove(key) {
196
233
  return await this.storage.removeItem(key);
197
234
  }
235
+ /**
236
+ * Retrieves all data from the storage as a record.
237
+ *
238
+ * @returns {Promise<Record<NodeStorageKey, NodeStorageValue>>} A promise that resolves with the data in the storage.
239
+ */
240
+ async data() {
241
+ const map = new Map();
242
+ const data = await this.storage.data();
243
+ for (const datum of data) {
244
+ map.set(datum.key, datum.value);
245
+ }
246
+ return Object.fromEntries(map);
247
+ }
248
+ /**
249
+ * Retrieves the keys of the entries in the storage.
250
+ *
251
+ * @returns {Promise<number>} A promise that resolves with the keys of the entries in the storage.
252
+ */
253
+ async keys() {
254
+ return await this.storage.keys();
255
+ }
256
+ /**
257
+ * Retrieves the values of the entries in the storage.
258
+ *
259
+ * @template T - The type of the values to retrieve.
260
+ * @returns {Promise<T[]>} A promise that resolves with an array of values.
261
+ */
262
+ async values() {
263
+ return (await this.storage.values());
264
+ }
265
+ static async healthCheck(storage) {
266
+ try {
267
+ // Attempt to get data and keys, and access the first key
268
+ const data = await storage.data();
269
+ for (const datum of data) {
270
+ if (!datum || !datum.key) {
271
+ if (storage.options.logging)
272
+ console.error(`Health check failed for invalid data: ${JSON.stringify(datum)}`);
273
+ return false; // Ensure datum is valid
274
+ }
275
+ await storage.getItem(datum.key); // Use getItem to ensure we can access the value
276
+ }
277
+ const keys = await storage.keys();
278
+ if (keys.length !== data.length)
279
+ return false; // Ensure keys match data length
280
+ const values = await storage.values();
281
+ if (values.length !== data.length)
282
+ return false; // Ensure values match data length
283
+ return true; // Storage is healthy
284
+ }
285
+ catch (error) {
286
+ if (storage.options.logging)
287
+ console.error('Health check failed:', error);
288
+ return false; // Storage is not healthy
289
+ }
290
+ }
198
291
  /**
199
292
  * Clears all entries from the storage.
293
+ *
200
294
  * @returns {Promise<void>} A promise that resolves when the storage is cleared.
201
295
  */
202
296
  async clear() {
@@ -204,6 +298,8 @@ export class NodeStorage {
204
298
  }
205
299
  /**
206
300
  * Logs the current storage state to the console.
301
+ *
302
+ * @returns {Promise<number>} A promise that resolves with the number of keys in the storage.
207
303
  */
208
304
  async logStorage() {
209
305
  console.log(`This NodeStorage has ${await this.storage.length()} keys:`);
@@ -1 +1 @@
1
- {"version":3,"file":"nodeStorage.js","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;GAUG;AAEH,OAAO,WAA0C,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAe;IACtB,WAAW,CAAc;IAClC,YAAY,GAAsB,EAAE,CAAC;IAE7C;;;OAGG;IACH,YAAY,WAAyB;QACnC,6CAA6C;QAC7C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAC9B;YACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,OA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M,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;gBAAE,OAAO,KAAK,CAAC,CAAC,kCAAkC;YACnF,OAAO,IAAI,CAAC,CAAC,qBAAqB;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;YAC1E,OAAO,KAAK,CAAC,CAAC,yBAAyB;QACzC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,CAAC,GAAG,CAAC,wBAAwB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACzE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-persist-manager",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Asyncronous Node.js storage manager in type script",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "MIT",
@@ -18,25 +18,31 @@
18
18
  },
19
19
  "type": "module",
20
20
  "main": "dist/nodeStorage.js",
21
- "types": "dist/nodeStorage.d.js",
21
+ "types": "dist/nodeStorage.d.ts",
22
22
  "engines": {
23
- "node": ">=18.0.0"
23
+ "node": ">=18.0.0 <19.0.0 || >=20.0.0 <21.0.0 || >=22.0.0 <23.0.0 || >=24.0.0 <25.0.0"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsc",
27
27
  "watch": "tsc --watch",
28
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand",
29
- "test:verbose": "node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --verbose",
30
- "test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --verbose --coverage",
31
- "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --verbose --watch",
28
+ "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
29
+ "test:verbose": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --verbose",
30
+ "test:watch": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --watch -verbose",
31
+ "test:coverage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --coverage",
32
+ "test:vitest": "vitest run",
33
+ "test:vitest:watch": "vitest --reporter verbose",
34
+ "test:vitest:verbose": "vitest run --reporter verbose",
35
+ "test:vitest:coverage": "vitest run --reporter verbose --coverage",
32
36
  "lint": "eslint --max-warnings=0 .",
33
37
  "lint:fix": "eslint --fix --max-warnings=0 .",
34
- "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
35
- "format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
36
- "clean": "rimraf tsconfig.tsbuildinfo ./dist",
38
+ "format": "prettier --write .",
39
+ "format:check": "prettier --check .",
40
+ "clean": "npx shx rm -rf tsconfig.tsbuildinfo dist",
37
41
  "cleanBuild": "npm run clean && npm run build",
38
- "deepClean": "rimraf tsconfig.tsbuildinfo package-lock.json ./dist ./node_modules",
39
- "deepCleanRebuild": "npm run deepClean && npm install && npm run build && npm ls eslint rimraf inflight glob",
42
+ "deepClean": "npx shx rm -rf coverage dist jest temp package-lock.json npm-shrinkwrap.json tsconfig.tsbuildinfo node_modules/* node_modules/.[!.]* node_modules/..?*",
43
+ "deepCleanRebuild": "npm run deepClean && npm install && npm run build",
44
+ "reset": "npm run deepClean && npm install && npm run build",
45
+ "runMeBeforePublish": "npm run lint && npm run format && npm run build && npm run test",
40
46
  "prepublishOnly": "npm run lint && npm run cleanBuild",
41
47
  "checkDependencies": "npx npm-check-updates",
42
48
  "updateDependencies": "npx npm-check-updates -u && npm install & npm run cleanBuild",
@@ -45,11 +51,13 @@
45
51
  "version:patch": "npm version patch",
46
52
  "version:minor": "npm version minor",
47
53
  "version:major": "npm version major",
48
- "install:dependencies": "npm install node-persist && npm install --save-dev @types/node-persist rimraf",
49
- "install:typescript": "npm install --save-dev @types/node typescript && npm run build",
50
- "install:eslint": "npm install --save-dev @eslint/js @types/eslint__js typescript-eslint",
51
- "install:prettier": "npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier",
52
- "install:jest": "npm install --save-dev jest ts-jest @types/jest eslint-plugin-jest"
54
+ "install:scripts": "npm install --save-dev npm-check-updates rimraf shx",
55
+ "install:dependencies": "npm install node-persist && npm install --save-dev @types/node-persist",
56
+ "install:typescript": "npm install --save-dev typescript @types/node",
57
+ "install:eslint": "npm install --save-dev @eslint/js typescript-eslint eslint-plugin-import eslint-plugin-n eslint-plugin-promise eslint-plugin-jsdoc",
58
+ "install:jest": "npm install --save-dev jest ts-jest @types/jest @jest/globals eslint-plugin-jest",
59
+ "install:vitest": "npm install --save-dev vitest @vitest/coverage-v8 @vitest/eslint-plugin",
60
+ "install:prettier": "npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier"
53
61
  },
54
62
  "keywords": [
55
63
  "node-persist",
@@ -59,24 +67,32 @@
59
67
  "NodeStorageManager",
60
68
  "NodeStorage"
61
69
  ],
62
- "overrides": {
63
- "eslint": "latest"
64
- },
65
- "dependencies": {
66
- "node-persist": "^4.0.2"
67
- },
68
70
  "devDependencies": {
69
- "@eslint/js": "^9.7.0",
70
- "@types/eslint__js": "^8.42.3",
71
- "@types/jest": "^29.5.12",
71
+ "@eslint/js": "^9.29.0",
72
+ "@jest/globals": "^30.0.2",
73
+ "@types/jest": "^30.0.0",
74
+ "@types/node": "^24.0.3",
72
75
  "@types/node-persist": "^3.1.8",
73
- "eslint-config-prettier": "^9.1.0",
74
- "eslint-plugin-jest": "^28.6.0",
75
- "eslint-plugin-prettier": "^5.2.1",
76
- "jest": "^29.7.0",
77
- "prettier": "^3.3.3",
76
+ "@vitest/coverage-v8": "^3.2.4",
77
+ "@vitest/eslint-plugin": "^1.2.7",
78
+ "eslint-config-prettier": "^10.1.5",
79
+ "eslint-plugin-import": "^2.32.0",
80
+ "eslint-plugin-jest": "^29.0.1",
81
+ "eslint-plugin-jsdoc": "^51.1.1",
82
+ "eslint-plugin-n": "^17.20.0",
83
+ "eslint-plugin-prettier": "^5.5.0",
84
+ "eslint-plugin-promise": "^7.2.1",
85
+ "jest": "^30.0.2",
86
+ "npm-check-updates": "^18.0.1",
87
+ "prettier": "^3.5.3",
78
88
  "rimraf": "^6.0.1",
79
- "ts-jest": "^29.2.3",
80
- "typescript-eslint": "^7.17.0"
89
+ "shx": "^0.4.0",
90
+ "ts-jest": "^29.4.0",
91
+ "typescript": "^5.8.3",
92
+ "typescript-eslint": "^8.34.1",
93
+ "vitest": "^3.2.4"
94
+ },
95
+ "dependencies": {
96
+ "node-persist": "^4.0.4"
81
97
  }
82
- }
98
+ }