node-persist-manager 1.0.6 → 1.0.8
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 +123 -121
- package/dist/nodeStorage.d.ts +2 -2
- package/dist/nodeStorage.d.ts.map +1 -1
- package/dist/nodeStorage.js +31 -12
- package/dist/nodeStorage.js.map +1 -1
- package/package.json +48 -23
- package/.gitattributes +0 -2
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,121 +1,123 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
- async
|
|
104
|
-
|
|
105
|
-
- async
|
|
106
|
-
|
|
107
|
-
- async
|
|
108
|
-
|
|
109
|
-
- async
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
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.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Simple and intuitive API for data storage and retrieval.
|
|
14
|
+
- Asynchronous data handling.
|
|
15
|
+
- Customizable storage directories for isolated storage contexts.
|
|
16
|
+
- Built-in logging capabilities for monitoring storage initialization and operations.
|
|
17
|
+
- Comprehensive test suite using Jest to ensure reliability and performance.
|
|
18
|
+
- Detailed documentation with JSDoc for better developer experience.
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
### Prerequisites
|
|
23
|
+
|
|
24
|
+
- Node.js installed on your machine.
|
|
25
|
+
- Basic knowledge of TypeScript and Node.js.
|
|
26
|
+
|
|
27
|
+
### Installation
|
|
28
|
+
|
|
29
|
+
To get started with NodeStorage in your package
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install node-persist-manager
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# Usage
|
|
36
|
+
|
|
37
|
+
## Initializing NodeStorageManager:
|
|
38
|
+
|
|
39
|
+
Create an instance of NodeStorageManager to manage your storage instances.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
const storageManager = new NodeStorageManager({
|
|
47
|
+
dir: 'path/to/storage/directory', // Optional: Customize the storage directory.
|
|
48
|
+
logging: true, // Optional: Enable logging.
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Creating a Storage Instance:
|
|
53
|
+
|
|
54
|
+
Use the manager to create a new storage context.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
const myStorage = await storageManager.createStorage('myStorageName');
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Using the Storage:
|
|
61
|
+
|
|
62
|
+
## Set a value:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
await myStorage.set('myKey', 'myValue');
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Get a value:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
const value = await myStorage.get('myKey');
|
|
72
|
+
console.log(value); // Outputs: 'myValue'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Remove a value:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
await myStorage.remove('myKey');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Clear the storage:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
await myStorage.clear();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
# API Reference
|
|
88
|
+
|
|
89
|
+
## NodeStorageManager methods:
|
|
90
|
+
|
|
91
|
+
- async createStorage(storageName: string): Promise<NodeStorage>
|
|
92
|
+
|
|
93
|
+
- async removeStorage(storageName: string): Promise<boolean>
|
|
94
|
+
|
|
95
|
+
- async logStorage(): Promise<void>
|
|
96
|
+
|
|
97
|
+
- async getStorageNames(): Promise<NodeStorageName[]>
|
|
98
|
+
|
|
99
|
+
- async logStorage(): Promise<void>
|
|
100
|
+
|
|
101
|
+
## NodeStorage methods:
|
|
102
|
+
|
|
103
|
+
- async set<T = any>(key: NodeStorageKey, value: T): Promise<void>
|
|
104
|
+
|
|
105
|
+
- async get<T = any>(key: NodeStorageKey, defaultValue?: T): Promise<T>
|
|
106
|
+
|
|
107
|
+
- async remove(key: NodeStorageKey): Promise<void>
|
|
108
|
+
|
|
109
|
+
- async clear(): Promise<void>
|
|
110
|
+
|
|
111
|
+
- async logStorage(): Promise<void>
|
|
112
|
+
|
|
113
|
+
# Contributing
|
|
114
|
+
|
|
115
|
+
Contributions to NodeStorage are welcome.
|
|
116
|
+
|
|
117
|
+
# License
|
|
118
|
+
|
|
119
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
120
|
+
|
|
121
|
+
# Acknowledgments
|
|
122
|
+
|
|
123
|
+
Thanks to node-persist for providing the underlying storage mechanism.
|
package/dist/nodeStorage.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare class NodeStorageManager {
|
|
|
49
49
|
/**
|
|
50
50
|
* Logs the names of all managed storages to the console.
|
|
51
51
|
*/
|
|
52
|
-
logStorage(): Promise<
|
|
52
|
+
logStorage(): Promise<number>;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Class representing a storage for nodes.
|
|
@@ -104,6 +104,6 @@ export declare class NodeStorage {
|
|
|
104
104
|
/**
|
|
105
105
|
* Logs the current storage state to the console.
|
|
106
106
|
*/
|
|
107
|
-
logStorage(): Promise<
|
|
107
|
+
logStorage(): Promise<number>;
|
|
108
108
|
}
|
|
109
109
|
//# 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;;;;;;;;;;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,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|
+
/* eslint-disable no-console */
|
|
1
2
|
/**
|
|
2
3
|
* This file contains the classes NodeStorageManager and NodeStorage
|
|
3
4
|
*
|
|
@@ -27,11 +28,17 @@ export class NodeStorageManager {
|
|
|
27
28
|
// Merge initOptions with default initOptions
|
|
28
29
|
this.initOptions = Object.assign({
|
|
29
30
|
dir: path.join(process.cwd(), 'node_storage'),
|
|
31
|
+
writeQueue: false,
|
|
32
|
+
expiredInterval: undefined,
|
|
30
33
|
logging: false,
|
|
31
34
|
}, initOptions);
|
|
32
35
|
// Create and initialize a new instace of LocalStorage
|
|
33
36
|
this.storage = NodePersist.create(this.initOptions);
|
|
34
37
|
this.storage.initSync(this.initOptions);
|
|
38
|
+
if (this.storage.options.writeQueue === false) {
|
|
39
|
+
clearInterval(this.storage._writeQueueInterval);
|
|
40
|
+
this.storage._writeQueueInterval = undefined;
|
|
41
|
+
}
|
|
35
42
|
if (this.initOptions.logging === true) {
|
|
36
43
|
console.log(`Storage manager initialized with options ${JSON.stringify(this.initOptions)}`);
|
|
37
44
|
}
|
|
@@ -46,7 +53,9 @@ export class NodeStorageManager {
|
|
|
46
53
|
*/
|
|
47
54
|
async close() {
|
|
48
55
|
this.storage.stopExpiredKeysInterval();
|
|
56
|
+
this.storage._expiredKeysInterval = undefined;
|
|
49
57
|
this.storage.stopWriteQueueInterval();
|
|
58
|
+
this.storage._writeQueueInterval = undefined;
|
|
50
59
|
}
|
|
51
60
|
/**
|
|
52
61
|
* Creates and initializes a new storage with a given name.
|
|
@@ -55,19 +64,24 @@ export class NodeStorageManager {
|
|
|
55
64
|
*/
|
|
56
65
|
async createStorage(storageName) {
|
|
57
66
|
const initOptions = {};
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
68
|
Object.assign(initOptions, this.initOptions, { dir: path.join(this.initOptions.dir, '.' + storageName) });
|
|
59
69
|
const storage = NodePersist.create(initOptions);
|
|
60
70
|
await storage.init(initOptions);
|
|
61
|
-
//console.log(`Created storage ${storageName} with options ${JSON.stringify(initOptions)}`);
|
|
71
|
+
// console.log(`Created storage ${storageName} with options ${JSON.stringify(initOptions)}`);
|
|
72
|
+
if (storage.options.writeQueue === false) {
|
|
73
|
+
clearInterval(storage._writeQueueInterval);
|
|
74
|
+
storage._writeQueueInterval = undefined;
|
|
75
|
+
}
|
|
62
76
|
// Update storageNames
|
|
63
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
64
|
-
//console.log('Storage list(1):', this.storageNames);
|
|
77
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
78
|
+
// console.log('Storage list(1):', this.storageNames);
|
|
65
79
|
if (!this.storageNames.includes(storageName)) {
|
|
66
80
|
this.storageNames.push(storageName);
|
|
67
81
|
}
|
|
68
|
-
//console.log('Storage list(2):', this.storageNames);
|
|
82
|
+
// console.log('Storage list(2):', this.storageNames);
|
|
69
83
|
await this.storage.set('storageNames', this.storageNames);
|
|
70
|
-
//console.log('Storage list(3):', await this.storage.get('storageNames') );
|
|
84
|
+
// console.log('Storage list(3):', await this.storage.get('storageNames') );
|
|
71
85
|
return new NodeStorage(storage, initOptions);
|
|
72
86
|
}
|
|
73
87
|
/**
|
|
@@ -76,22 +90,23 @@ export class NodeStorageManager {
|
|
|
76
90
|
* @returns {Promise<boolean>} A promise that resolves to true if the storage was successfully removed, otherwise false.
|
|
77
91
|
*/
|
|
78
92
|
async removeStorage(storageName) {
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
94
|
const dir = path.join(this.initOptions.dir, '.' + storageName);
|
|
80
95
|
try {
|
|
81
96
|
await rm(dir, { recursive: true });
|
|
82
|
-
//console.log('Storage removed');
|
|
97
|
+
// console.log('Storage removed');
|
|
83
98
|
// Update storageNames
|
|
84
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
99
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
85
100
|
const index = this.storageNames.indexOf(storageName);
|
|
86
101
|
if (index > -1) {
|
|
87
102
|
this.storageNames.splice(index, 1);
|
|
88
103
|
}
|
|
89
104
|
await this.storage.set('storageNames', this.storageNames);
|
|
90
|
-
//console.log('Storage list:', await this.storage.get('storageNames') );
|
|
105
|
+
// console.log('Storage list:', await this.storage.get('storageNames') );
|
|
91
106
|
return true;
|
|
92
107
|
}
|
|
93
108
|
catch (err) {
|
|
94
|
-
//console.error('Error removing storage:', err);
|
|
109
|
+
// console.error('Error removing storage:', err);
|
|
95
110
|
return false;
|
|
96
111
|
}
|
|
97
112
|
}
|
|
@@ -100,7 +115,7 @@ export class NodeStorageManager {
|
|
|
100
115
|
* @returns {Promise<NodeStorageName[]>} A promise that resolves to an array of storage names.
|
|
101
116
|
*/
|
|
102
117
|
async getStorageNames() {
|
|
103
|
-
this.storageNames = await this.storage.get('storageNames') ?? [];
|
|
118
|
+
this.storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
104
119
|
return this.storageNames;
|
|
105
120
|
}
|
|
106
121
|
/**
|
|
@@ -108,10 +123,11 @@ export class NodeStorageManager {
|
|
|
108
123
|
*/
|
|
109
124
|
async logStorage() {
|
|
110
125
|
console.log('This NodeStorageManager has these storages:');
|
|
111
|
-
const storageNames = await this.storage.get('storageNames') ?? [];
|
|
112
|
-
storageNames.forEach(name => {
|
|
126
|
+
const storageNames = (await this.storage.get('storageNames')) ?? [];
|
|
127
|
+
storageNames.forEach((name) => {
|
|
113
128
|
console.log(`- ${name}`);
|
|
114
129
|
});
|
|
130
|
+
return await this.storage.length();
|
|
115
131
|
}
|
|
116
132
|
}
|
|
117
133
|
/**
|
|
@@ -134,7 +150,9 @@ export class NodeStorage {
|
|
|
134
150
|
*/
|
|
135
151
|
async close() {
|
|
136
152
|
this.storage.stopExpiredKeysInterval();
|
|
153
|
+
this.storage._expiredKeysInterval = undefined;
|
|
137
154
|
this.storage.stopWriteQueueInterval();
|
|
155
|
+
this.storage._writeQueueInterval = undefined;
|
|
138
156
|
}
|
|
139
157
|
/**
|
|
140
158
|
* Sets a value for a given key in the storage.
|
|
@@ -193,6 +211,7 @@ export class NodeStorage {
|
|
|
193
211
|
for (const key of keys) {
|
|
194
212
|
console.log(`- ${key}: ${await this.storage.get(key)}`);
|
|
195
213
|
}
|
|
214
|
+
return await this.storage.length();
|
|
196
215
|
}
|
|
197
216
|
}
|
|
198
217
|
//# 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;;;;;;;;;;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,
|
|
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,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC;YAC7C,UAAU,EAAE,KAAK;YACjB,eAAe,EAAE,SAAS;YAC1B,OAAO,EAAE,KAAK;SACA,EAChB,WAAW,CACZ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AI,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,36 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-persist-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Asyncronous Node.js storage manager in type script",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/Luligu/node-persist-manager/blob/main/README.md",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/Luligu/node-persist-manager"
|
|
10
|
+
"url": "git+https://github.com/Luligu/node-persist-manager.git"
|
|
10
11
|
},
|
|
11
12
|
"bugs": {
|
|
12
13
|
"url": "https://github.com/Luligu/node-persist-manager/issues"
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
},
|
|
15
|
+
"funding": {
|
|
16
|
+
"type": "buymeacoffee",
|
|
17
|
+
"url": "https://www.buymeacoffee.com/luligugithub"
|
|
16
18
|
},
|
|
17
19
|
"type": "module",
|
|
18
20
|
"main": "dist/nodeStorage.js",
|
|
19
21
|
"types": "dist/nodeStorage.d.js",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.0.0"
|
|
24
|
+
},
|
|
20
25
|
"scripts": {
|
|
21
26
|
"build": "tsc",
|
|
22
27
|
"watch": "tsc --watch",
|
|
23
|
-
"test": "jest",
|
|
24
|
-
"test:verbose": "jest --verbose",
|
|
25
|
-
"test:
|
|
26
|
-
"
|
|
27
|
-
"lint
|
|
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",
|
|
32
|
+
"lint": "eslint --max-warnings=0 .",
|
|
33
|
+
"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}\"",
|
|
28
36
|
"clean": "rimraf tsconfig.tsbuildinfo ./dist",
|
|
29
|
-
"cleanBuild": "npm run clean &&
|
|
30
|
-
"deepClean": "rimraf tsconfig.tsbuildinfo package-lock.json ./dist ./node_modules
|
|
37
|
+
"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",
|
|
31
40
|
"prepublishOnly": "npm run lint && npm run cleanBuild",
|
|
32
41
|
"checkDependencies": "npx npm-check-updates",
|
|
33
|
-
"updateDependencies": "npx npm-check-updates -u"
|
|
42
|
+
"updateDependencies": "npx npm-check-updates -u && npm install & npm run cleanBuild",
|
|
43
|
+
"preversion": "npm run lint && npm run test && npm run build",
|
|
44
|
+
"postversion": "git push && git push --tags",
|
|
45
|
+
"version:patch": "npm version patch",
|
|
46
|
+
"version:minor": "npm version minor",
|
|
47
|
+
"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"
|
|
34
53
|
},
|
|
35
54
|
"keywords": [
|
|
36
55
|
"node-persist",
|
|
@@ -40,18 +59,24 @@
|
|
|
40
59
|
"NodeStorageManager",
|
|
41
60
|
"NodeStorage"
|
|
42
61
|
],
|
|
62
|
+
"overrides": {
|
|
63
|
+
"eslint": "latest"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"node-persist": "^4.0.2"
|
|
67
|
+
},
|
|
43
68
|
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^9.7.0",
|
|
70
|
+
"@types/eslint__js": "^8.42.3",
|
|
44
71
|
"@types/jest": "^29.5.12",
|
|
45
|
-
"@types/node": "^20.11.30",
|
|
46
72
|
"@types/node-persist": "^3.1.8",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"eslint": "^
|
|
73
|
+
"eslint-config-prettier": "^9.1.0",
|
|
74
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
75
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
50
76
|
"jest": "^29.7.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"node-persist": "^4.0.1"
|
|
77
|
+
"prettier": "^3.3.3",
|
|
78
|
+
"rimraf": "^6.0.1",
|
|
79
|
+
"ts-jest": "^29.2.3",
|
|
80
|
+
"typescript-eslint": "^7.17.0"
|
|
56
81
|
}
|
|
57
|
-
}
|
|
82
|
+
}
|
package/.gitattributes
DELETED