node-persist-manager 1.0.7 → 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/LICENSE +20 -20
- package/README.md +136 -124
- package/dist/nodeStorage.d.ts +67 -7
- package/dist/nodeStorage.d.ts.map +1 -1
- package/dist/nodeStorage.js +140 -25
- package/dist/nodeStorage.js.map +1 -1
- package/package.json +58 -22
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Luligu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Luligu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,124 +1,136 @@
|
|
|
1
|
-
# NodeStorageManager and NodeStorage
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/node-persist-manager)
|
|
4
|
-
[](https://www.npmjs.com/package/node-persist-manager)
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
##
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
await myStorage.
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
##
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
await myStorage.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
##
|
|
103
|
-
|
|
104
|
-
- async
|
|
105
|
-
|
|
106
|
-
- async
|
|
107
|
-
|
|
108
|
-
- async
|
|
109
|
-
|
|
110
|
-
- async
|
|
111
|
-
|
|
112
|
-
- async logStorage(): Promise<void>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
# NodeStorageManager and NodeStorage
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/node-persist-manager)
|
|
4
|
+
[](https://www.npmjs.com/package/node-persist-manager)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://codecov.io/gh/Luligu/node-persist-manager)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
NodeStorage is a lightweight, file-based storage management system for Node.js, built on top of `node-persist`. It allows for easy and intuitive handling of persistent key-value storage directly within your Node.js applications. This system is ideal for small to medium-sized projects requiring simple data persistence without the overhead of a database system.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Simple and intuitive API for data storage and retrieval.
|
|
16
|
+
- Asynchronous data handling.
|
|
17
|
+
- Customizable storage directories for isolated storage contexts.
|
|
18
|
+
- Built-in logging capabilities for monitoring storage initialization and operations.
|
|
19
|
+
- Comprehensive test suite using Jest to ensure reliability and performance.
|
|
20
|
+
- Detailed documentation with JSDoc for better developer experience.
|
|
21
|
+
|
|
22
|
+
## Getting Started
|
|
23
|
+
|
|
24
|
+
### Prerequisites
|
|
25
|
+
|
|
26
|
+
- Node.js installed on your machine.
|
|
27
|
+
- Basic knowledge of TypeScript and Node.js.
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
30
|
+
|
|
31
|
+
To get started with NodeStorage in your package
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install node-persist-manager
|
|
35
|
+
```
|
|
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
|
+
|
|
48
|
+
# Usage
|
|
49
|
+
|
|
50
|
+
## Initializing NodeStorageManager:
|
|
51
|
+
|
|
52
|
+
Create an instance of NodeStorageManager to manage your storage instances.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const storageManager = new NodeStorageManager({
|
|
60
|
+
dir: 'path/to/storage/directory', // Optional: Customize the storage directory.
|
|
61
|
+
logging: true, // Optional: Enable logging.
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Creating a Storage Instance:
|
|
66
|
+
|
|
67
|
+
Use the manager to create a new storage context.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const myStorage = await storageManager.createStorage('myStorageName');
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Using the Storage:
|
|
74
|
+
|
|
75
|
+
## Set a value:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
await myStorage.set('myKey', 'myValue');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Get a value:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const value = await myStorage.get('myKey');
|
|
85
|
+
console.log(value); // Outputs: 'myValue'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Remove a value:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
await myStorage.remove('myKey');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Clear the storage:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
await myStorage.clear();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# API Reference
|
|
101
|
+
|
|
102
|
+
## NodeStorageManager methods:
|
|
103
|
+
|
|
104
|
+
- async createStorage(storageName: string): Promise<NodeStorage>
|
|
105
|
+
|
|
106
|
+
- async removeStorage(storageName: string): Promise<boolean>
|
|
107
|
+
|
|
108
|
+
- async logStorage(): Promise<void>
|
|
109
|
+
|
|
110
|
+
- async getStorageNames(): Promise<NodeStorageName[]>
|
|
111
|
+
|
|
112
|
+
- async logStorage(): Promise<void>
|
|
113
|
+
|
|
114
|
+
## NodeStorage methods:
|
|
115
|
+
|
|
116
|
+
- async set<T = any>(key: NodeStorageKey, value: T): Promise<void>
|
|
117
|
+
|
|
118
|
+
- async get<T = any>(key: NodeStorageKey, defaultValue?: T): Promise<T>
|
|
119
|
+
|
|
120
|
+
- async remove(key: NodeStorageKey): Promise<void>
|
|
121
|
+
|
|
122
|
+
- async clear(): Promise<void>
|
|
123
|
+
|
|
124
|
+
- async logStorage(): Promise<void>
|
|
125
|
+
|
|
126
|
+
# Contributing
|
|
127
|
+
|
|
128
|
+
Contributions to NodeStorage are welcome.
|
|
129
|
+
|
|
130
|
+
# License
|
|
131
|
+
|
|
132
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
133
|
+
|
|
134
|
+
# Acknowledgments
|
|
135
|
+
|
|
136
|
+
Thanks to node-persist for providing the underlying storage mechanism.
|
package/dist/nodeStorage.d.ts
CHANGED
|
@@ -3,16 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @file nodeStorage.ts
|
|
5
5
|
* @author Luca Liguori
|
|
6
|
-
* @
|
|
6
|
+
* @created 2024-02-02
|
|
7
7
|
* @version 1.0.1
|
|
8
|
+
* @license Apache-2.0
|
|
8
9
|
*
|
|
9
|
-
*
|
|
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
|
|
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,25 +45,30 @@ 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
|
-
logStorage(): Promise<
|
|
71
|
+
logStorage(): Promise<number>;
|
|
53
72
|
}
|
|
54
73
|
/**
|
|
55
74
|
* Class representing a storage for nodes.
|
|
@@ -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,32 +99,71 @@ 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
|
-
logStorage(): Promise<
|
|
167
|
+
logStorage(): Promise<number>;
|
|
108
168
|
}
|
|
109
169
|
//# sourceMappingURL=nodeStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeStorage.d.ts","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodeStorage.d.ts","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACvC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,YAAY,CAA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AAI,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"}
|
package/dist/nodeStorage.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
/**
|
|
2
3
|
* This file contains the classes NodeStorageManager and NodeStorage
|
|
3
4
|
*
|
|
4
5
|
* @file nodeStorage.ts
|
|
5
6
|
* @author Luca Liguori
|
|
6
|
-
* @
|
|
7
|
+
* @created 2024-02-02
|
|
7
8
|
* @version 1.0.1
|
|
9
|
+
* @license Apache-2.0
|
|
8
10
|
*
|
|
9
|
-
*
|
|
11
|
+
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
10
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.
|
|
11
24
|
*/
|
|
25
|
+
import { rm } from 'node:fs/promises';
|
|
26
|
+
import path from 'node:path';
|
|
12
27
|
import NodePersist from 'node-persist';
|
|
13
|
-
import { rm } from 'fs/promises';
|
|
14
|
-
import path from 'path';
|
|
15
28
|
/**
|
|
16
29
|
* Class responsible for managing multiple node storages.
|
|
17
30
|
*/
|
|
@@ -21,97 +34,109 @@ export class NodeStorageManager {
|
|
|
21
34
|
storageNames = [];
|
|
22
35
|
/**
|
|
23
36
|
* Initializes a new instance of NodeStorageManager with optional initialization options.
|
|
37
|
+
*
|
|
24
38
|
* @param {InitOptions} [initOptions] - Optional initialization options to customize the storage.
|
|
25
39
|
*/
|
|
26
40
|
constructor(initOptions) {
|
|
27
41
|
// Merge initOptions with default initOptions
|
|
28
42
|
this.initOptions = Object.assign({
|
|
29
43
|
dir: path.join(process.cwd(), 'node_storage'),
|
|
44
|
+
writeQueue: false,
|
|
45
|
+
expiredInterval: undefined,
|
|
30
46
|
logging: false,
|
|
31
47
|
}, initOptions);
|
|
32
48
|
// Create and initialize a new instace of LocalStorage
|
|
33
49
|
this.storage = NodePersist.create(this.initOptions);
|
|
34
50
|
this.storage.initSync(this.initOptions);
|
|
51
|
+
if (this.storage.options.writeQueue === false) {
|
|
52
|
+
clearInterval(this.storage._writeQueueInterval);
|
|
53
|
+
this.storage._writeQueueInterval = undefined;
|
|
54
|
+
}
|
|
35
55
|
if (this.initOptions.logging === true) {
|
|
36
56
|
console.log(`Storage manager initialized with options ${JSON.stringify(this.initOptions)}`);
|
|
37
57
|
}
|
|
38
|
-
/*
|
|
39
|
-
this.get<Array<NodeStorageName>>('storageNames').then(storageNames => {
|
|
40
|
-
this.storageNames = storageNames;
|
|
41
|
-
});
|
|
42
|
-
*/
|
|
43
58
|
}
|
|
44
59
|
/**
|
|
45
60
|
* Closes the node storage manager by stopping the expired keys interval and the write queue interval.
|
|
46
61
|
*/
|
|
47
62
|
async close() {
|
|
48
63
|
this.storage.stopExpiredKeysInterval();
|
|
64
|
+
this.storage._expiredKeysInterval = undefined;
|
|
49
65
|
this.storage.stopWriteQueueInterval();
|
|
66
|
+
this.storage._writeQueueInterval = undefined;
|
|
50
67
|
}
|
|
51
68
|
/**
|
|
52
69
|
* Creates and initializes a new storage with a given name.
|
|
70
|
+
*
|
|
53
71
|
* @param {string} storageName - The name of the new storage to create.
|
|
54
72
|
* @returns {Promise<NodeStorage>} A promise that resolves to the newly created NodeStorage instance.
|
|
55
73
|
*/
|
|
56
74
|
async createStorage(storageName) {
|
|
57
75
|
const initOptions = {};
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
77
|
Object.assign(initOptions, this.initOptions, { dir: path.join(this.initOptions.dir, '.' + storageName) });
|
|
59
78
|
const storage = NodePersist.create(initOptions);
|
|
60
79
|
await storage.init(initOptions);
|
|
61
|
-
|
|
80
|
+
if (storage.options.writeQueue === false) {
|
|
81
|
+
clearInterval(storage._writeQueueInterval);
|
|
82
|
+
storage._writeQueueInterval = undefined;
|
|
83
|
+
}
|
|
62
84
|
// Update storageNames
|
|
63
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
64
|
-
//console.log('Storage list(1):', this.storageNames);
|
|
85
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
65
86
|
if (!this.storageNames.includes(storageName)) {
|
|
66
87
|
this.storageNames.push(storageName);
|
|
67
88
|
}
|
|
68
|
-
//console.log('Storage list(2):', this.storageNames);
|
|
69
89
|
await this.storage.set('storageNames', this.storageNames);
|
|
70
|
-
//console.log('Storage list(3):', await this.storage.get('storageNames') );
|
|
71
90
|
return new NodeStorage(storage, initOptions);
|
|
72
91
|
}
|
|
73
92
|
/**
|
|
74
93
|
* Removes a storage by its name.
|
|
94
|
+
*
|
|
75
95
|
* @param {string} storageName - The name of the storage to remove.
|
|
76
96
|
* @returns {Promise<boolean>} A promise that resolves to true if the storage was successfully removed, otherwise false.
|
|
77
97
|
*/
|
|
78
98
|
async removeStorage(storageName) {
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
100
|
const dir = path.join(this.initOptions.dir, '.' + storageName);
|
|
80
101
|
try {
|
|
81
102
|
await rm(dir, { recursive: true });
|
|
82
|
-
//console.log('Storage removed');
|
|
103
|
+
// console.log('Storage removed');
|
|
83
104
|
// Update storageNames
|
|
84
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
105
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
85
106
|
const index = this.storageNames.indexOf(storageName);
|
|
86
107
|
if (index > -1) {
|
|
87
108
|
this.storageNames.splice(index, 1);
|
|
88
109
|
}
|
|
89
110
|
await this.storage.set('storageNames', this.storageNames);
|
|
90
|
-
//console.log('Storage list:', await this.storage.get('storageNames') );
|
|
111
|
+
// console.log('Storage list:', await this.storage.get('storageNames') );
|
|
91
112
|
return true;
|
|
92
113
|
}
|
|
93
|
-
catch (
|
|
94
|
-
//console.error('Error removing storage:',
|
|
114
|
+
catch (_err) {
|
|
115
|
+
// console.error('Error removing storage:', _err);
|
|
95
116
|
return false;
|
|
96
117
|
}
|
|
97
118
|
}
|
|
98
119
|
/**
|
|
99
120
|
* Retrieves the names of all available storages.
|
|
121
|
+
*
|
|
100
122
|
* @returns {Promise<NodeStorageName[]>} A promise that resolves to an array of storage names.
|
|
101
123
|
*/
|
|
102
124
|
async getStorageNames() {
|
|
103
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
125
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
104
126
|
return this.storageNames;
|
|
105
127
|
}
|
|
106
128
|
/**
|
|
107
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.
|
|
108
132
|
*/
|
|
109
133
|
async logStorage() {
|
|
110
134
|
console.log('This NodeStorageManager has these storages:');
|
|
111
|
-
const storageNames = await this.storage.get('storageNames') ?? [];
|
|
112
|
-
storageNames.forEach(name => {
|
|
135
|
+
const storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
136
|
+
storageNames.forEach((name) => {
|
|
113
137
|
console.log(`- ${name}`);
|
|
114
138
|
});
|
|
139
|
+
return await this.storage.length();
|
|
115
140
|
}
|
|
116
141
|
}
|
|
117
142
|
/**
|
|
@@ -122,6 +147,7 @@ export class NodeStorage {
|
|
|
122
147
|
initOptions;
|
|
123
148
|
/**
|
|
124
149
|
* Creates an instance of NodeStorage.
|
|
150
|
+
*
|
|
125
151
|
* @param {LocalStorage} storage - The local storage instance.
|
|
126
152
|
* @param {InitOptions} initOptions - The initialization options.
|
|
127
153
|
*/
|
|
@@ -134,10 +160,13 @@ export class NodeStorage {
|
|
|
134
160
|
*/
|
|
135
161
|
async close() {
|
|
136
162
|
this.storage.stopExpiredKeysInterval();
|
|
163
|
+
this.storage._expiredKeysInterval = undefined;
|
|
137
164
|
this.storage.stopWriteQueueInterval();
|
|
165
|
+
this.storage._writeQueueInterval = undefined;
|
|
138
166
|
}
|
|
139
167
|
/**
|
|
140
168
|
* Sets a value for a given key in the storage.
|
|
169
|
+
*
|
|
141
170
|
* @template T - The type of the value to be stored.
|
|
142
171
|
* @param {NodeStorageKey} key - The key under which the value is stored.
|
|
143
172
|
* @param {T} value - The value to store.
|
|
@@ -150,6 +179,7 @@ export class NodeStorage {
|
|
|
150
179
|
/**
|
|
151
180
|
* Retrieves a value for a given key from the storage.
|
|
152
181
|
* If the key does not exist, returns a default value if provided.
|
|
182
|
+
*
|
|
153
183
|
* @template T - The type of the value to retrieve.
|
|
154
184
|
* @param {NodeStorageKey} key - The key of the value to retrieve.
|
|
155
185
|
* @param {T} [defaultValue] - The default value to return if the key is not found.
|
|
@@ -158,27 +188,109 @@ export class NodeStorage {
|
|
|
158
188
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
189
|
async get(key, defaultValue) {
|
|
160
190
|
const value = await this.storage.getItem(key);
|
|
161
|
-
|
|
191
|
+
if (value !== undefined) {
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
if (defaultValue !== undefined) {
|
|
195
|
+
return defaultValue;
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
162
198
|
}
|
|
163
199
|
/**
|
|
164
|
-
* Checks if the storage
|
|
200
|
+
* Checks if the storage has a given key.
|
|
201
|
+
*
|
|
165
202
|
* @param {NodeStorageKey} key - The key to check.
|
|
166
203
|
* @returns {Promise<boolean>} A promise that resolves with true if the key exists, otherwise false.
|
|
167
204
|
*/
|
|
168
|
-
async
|
|
205
|
+
async has(key) {
|
|
169
206
|
const keys = await this.storage.keys();
|
|
170
207
|
return keys.includes(key);
|
|
171
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
|
+
}
|
|
172
226
|
/**
|
|
173
227
|
* Removes a value for a given key from the storage.
|
|
228
|
+
*
|
|
174
229
|
* @param {NodeStorageKey} key - The key of the value to remove.
|
|
175
230
|
* @returns {Promise<NodePersist.DeleteFileResult>} A promise that resolves with the result of deleting the file.
|
|
176
231
|
*/
|
|
177
232
|
async remove(key) {
|
|
178
233
|
return await this.storage.removeItem(key);
|
|
179
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
|
+
}
|
|
180
291
|
/**
|
|
181
292
|
* Clears all entries from the storage.
|
|
293
|
+
*
|
|
182
294
|
* @returns {Promise<void>} A promise that resolves when the storage is cleared.
|
|
183
295
|
*/
|
|
184
296
|
async clear() {
|
|
@@ -186,6 +298,8 @@ export class NodeStorage {
|
|
|
186
298
|
}
|
|
187
299
|
/**
|
|
188
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.
|
|
189
303
|
*/
|
|
190
304
|
async logStorage() {
|
|
191
305
|
console.log(`This NodeStorage has ${await this.storage.length()} keys:`);
|
|
@@ -193,6 +307,7 @@ export class NodeStorage {
|
|
|
193
307
|
for (const key of keys) {
|
|
194
308
|
console.log(`- ${key}: ${await this.storage.get(key)}`);
|
|
195
309
|
}
|
|
310
|
+
return await this.storage.length();
|
|
196
311
|
}
|
|
197
312
|
}
|
|
198
313
|
//# sourceMappingURL=nodeStorage.js.map
|
package/dist/nodeStorage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeStorage.js","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nodeStorage.js","sourceRoot":"","sources":["../src/nodeStorage.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,WAA6B,MAAM,cAAc,CAAC;AAOzD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAe;IACtB,WAAW,CAAc;IAClC,YAAY,GAAsB,EAAE,CAAC;IAE7C;;;;OAIG;IACH,YAAY,WAAyB;QACnC,6CAA6C;QAC7C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAC9B;YACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,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2
|
"name": "node-persist-manager",
|
|
3
|
-
"version": "1.0
|
|
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",
|
|
@@ -11,31 +11,53 @@
|
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/Luligu/node-persist-manager/issues"
|
|
14
|
-
},
|
|
14
|
+
},
|
|
15
15
|
"funding": {
|
|
16
16
|
"type": "buymeacoffee",
|
|
17
17
|
"url": "https://www.buymeacoffee.com/luligugithub"
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"main": "dist/nodeStorage.js",
|
|
21
|
-
"types": "dist/nodeStorage.d.
|
|
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": "jest",
|
|
29
|
-
"test:verbose": "jest --verbose",
|
|
30
|
-
"test:watch": "jest --watch",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
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",
|
|
36
|
+
"lint": "eslint --max-warnings=0 .",
|
|
37
|
+
"lint:fix": "eslint --fix --max-warnings=0 .",
|
|
38
|
+
"format": "prettier --write .",
|
|
39
|
+
"format:check": "prettier --check .",
|
|
40
|
+
"clean": "npx shx rm -rf tsconfig.tsbuildinfo dist",
|
|
41
|
+
"cleanBuild": "npm run clean && npm run build",
|
|
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",
|
|
36
46
|
"prepublishOnly": "npm run lint && npm run cleanBuild",
|
|
37
47
|
"checkDependencies": "npx npm-check-updates",
|
|
38
|
-
"updateDependencies": "npx npm-check-updates -u"
|
|
48
|
+
"updateDependencies": "npx npm-check-updates -u && npm install & npm run cleanBuild",
|
|
49
|
+
"preversion": "npm run lint && npm run test && npm run build",
|
|
50
|
+
"postversion": "git push && git push --tags",
|
|
51
|
+
"version:patch": "npm version patch",
|
|
52
|
+
"version:minor": "npm version minor",
|
|
53
|
+
"version:major": "npm version major",
|
|
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"
|
|
39
61
|
},
|
|
40
62
|
"keywords": [
|
|
41
63
|
"node-persist",
|
|
@@ -46,17 +68,31 @@
|
|
|
46
68
|
"NodeStorage"
|
|
47
69
|
],
|
|
48
70
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
71
|
+
"@eslint/js": "^9.29.0",
|
|
72
|
+
"@jest/globals": "^30.0.2",
|
|
73
|
+
"@types/jest": "^30.0.0",
|
|
74
|
+
"@types/node": "^24.0.3",
|
|
51
75
|
"@types/node-persist": "^3.1.8",
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"eslint": "^
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
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",
|
|
88
|
+
"rimraf": "^6.0.1",
|
|
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"
|
|
58
94
|
},
|
|
59
95
|
"dependencies": {
|
|
60
|
-
"node-persist": "^4.0.
|
|
96
|
+
"node-persist": "^4.0.4"
|
|
61
97
|
}
|
|
62
98
|
}
|