datanautics 2.0.0 → 2.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/CHANGELOG.md +13 -0
- package/README.md +19 -9
- package/dist/constants/default-datanautics-options.js +2 -0
- package/dist/constants/default-datanautics-options.js.map +1 -1
- package/dist/constants/default-dump-interval.d.ts +1 -0
- package/dist/constants/default-dump-interval.js +5 -0
- package/dist/constants/default-dump-interval.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/datanautics.d.ts +4 -1
- package/dist/datanautics.js +31 -12
- package/dist/datanautics.js.map +1 -1
- package/dist/options/datanautics-options.d.ts +1 -0
- package/package.json +1 -1
- package/test/test.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,16 +5,27 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [2.1.0] - 2025-05-17 (**Breaking changes!**)
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Reverted changes since 2.0.0 failed
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
8
16
|
## [2.0.0] - 2025-05-17 (**Breaking changes!**)
|
|
9
17
|
|
|
10
18
|
### Added
|
|
19
|
+
|
|
11
20
|
- Instead of background storing entire object store each key-value eventually
|
|
12
21
|
- Replaced dumpInterval from options
|
|
13
22
|
|
|
14
23
|
---
|
|
24
|
+
|
|
15
25
|
## [1.1.2] - 2025-05-17
|
|
16
26
|
|
|
17
27
|
### Fixed
|
|
28
|
+
|
|
18
29
|
- Non-blocking storing
|
|
19
30
|
|
|
20
31
|
---
|
|
@@ -22,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
22
33
|
## [1.1.1] - 2025-05-17
|
|
23
34
|
|
|
24
35
|
### Fixed
|
|
36
|
+
|
|
25
37
|
- Replaced fs usage with child_process
|
|
26
38
|
|
|
27
39
|
---
|
|
@@ -29,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
29
41
|
## [1.1.0] - 2025-05-17
|
|
30
42
|
|
|
31
43
|
### Fixed
|
|
44
|
+
|
|
32
45
|
- Fixed storing to avoid RangeError when JSON.parse/JSON.stringify
|
|
33
46
|
|
|
34
47
|
---
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Datanautics
|
|
2
2
|
|
|
3
|
-
**Datanautics** is a lightweight key-value storage system with support for nested property access
|
|
3
|
+
**Datanautics** is a lightweight key-value storage system with support for nested property access, persistent dumps to disk, and configurable autosave intervals.
|
|
4
4
|
|
|
5
|
-
It uses string-based paths (like `user[0].profile.name`) to **get/set deeply nested data**, and periodically saves the current state to a
|
|
5
|
+
It uses string-based paths (like `user[0].profile.name`) to **get/set deeply nested data**, and periodically saves the current state to a JSON file for durability.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -30,9 +30,10 @@ npm install datanautics
|
|
|
30
30
|
const { Datanautics } = require('datanautics');
|
|
31
31
|
|
|
32
32
|
const store = new Datanautics({
|
|
33
|
-
dumpPath: './data',
|
|
33
|
+
dumpPath: './data.json',
|
|
34
|
+
dumpInterval: 1000, // every 1 second
|
|
34
35
|
verbose: true,
|
|
35
|
-
logger: console
|
|
36
|
+
logger: console,
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
store.set('users[0].name', 'Alice');
|
|
@@ -45,11 +46,12 @@ console.log(store.get('users[0].name')); // Output: Alice
|
|
|
45
46
|
|
|
46
47
|
You can pass the following options to the constructor:
|
|
47
48
|
|
|
48
|
-
| Option | Type | Description
|
|
49
|
-
|
|
50
|
-
| `dumpPath` | `string`, optional | Path to the JSON file for persistent data storage
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
49
|
+
| Option | Type | Description | Default |
|
|
50
|
+
| -------------- | ------------------- | ------------------------------------------------- | ----------------------------------------- |
|
|
51
|
+
| `dumpPath` | `string`, optional | Path to the JSON file for persistent data storage | `node_modules/datanautics/data/data.json` |
|
|
52
|
+
| `dumpInterval` | `number`, optional | Interval in milliseconds between auto-dumps | `1000` (1 second) |
|
|
53
|
+
| `verbose` | `boolean`, optional | Log errors during reading/writing | `false` |
|
|
54
|
+
| `logger` | `object`, optional | Custom logger (`console`, `winston`, etc.) | `console` |
|
|
53
55
|
|
|
54
56
|
---
|
|
55
57
|
|
|
@@ -69,6 +71,14 @@ Returns `undefined` if the path does not exist or is non-evaluable.
|
|
|
69
71
|
|
|
70
72
|
---
|
|
71
73
|
|
|
74
|
+
## 📂 Auto-Save Mechanism
|
|
75
|
+
|
|
76
|
+
- A background event loop triggers a dump to `options.dumpPath` every `options.dumpInterval` ms.
|
|
77
|
+
- All data is saved as a JSON file, preserving nested structures.
|
|
78
|
+
- On startup, the class will attempt to read and restore previous data from the file.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
72
82
|
## ✅ Requirements
|
|
73
83
|
|
|
74
84
|
- Node.js 14+
|
|
@@ -26,7 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.defaultDatanauticsOptions = void 0;
|
|
27
27
|
const console = __importStar(require("console"));
|
|
28
28
|
const path_1 = require("path");
|
|
29
|
+
const default_dump_interval_1 = require("./default-dump-interval");
|
|
29
30
|
exports.defaultDatanauticsOptions = {
|
|
31
|
+
dumpInterval: default_dump_interval_1.DEFAULT_DUMP_INTERVAL,
|
|
30
32
|
verbose: true,
|
|
31
33
|
logger: console,
|
|
32
34
|
dumpPath: (0, path_1.resolve)(__dirname, '../../data/data.json'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-datanautics-options.js","sourceRoot":"","sources":["../../src/constants/default-datanautics-options.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,+BAA+B;
|
|
1
|
+
{"version":3,"file":"default-datanautics-options.js","sourceRoot":"","sources":["../../src/constants/default-datanautics-options.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,+BAA+B;AAG/B,mEAAgE;AAEnD,QAAA,yBAAyB,GAAuB;IAC3D,YAAY,EAAE,6CAAqB;IACnC,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,sBAAsB,CAAC;CACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_DUMP_INTERVAL: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-dump-interval.js","sourceRoot":"","sources":["../../src/constants/default-dump-interval.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAW,IAAI,CAAC"}
|
package/dist/constants/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./default-dump-interval"), exports);
|
|
17
18
|
__exportStar(require("./dump-event"), exports);
|
|
18
19
|
__exportStar(require("./default-datanautics-options"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,gEAA8C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,+CAA6B;AAC7B,gEAA8C"}
|
package/dist/datanautics.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
1
3
|
import { DatanauticsOptions } from './options';
|
|
2
4
|
export declare class Datanautics {
|
|
3
5
|
protected options: DatanauticsOptions;
|
|
4
6
|
protected data: Record<string, any>;
|
|
7
|
+
protected eventEmitter: EventEmitter;
|
|
5
8
|
constructor(options?: DatanauticsOptions);
|
|
6
|
-
protected
|
|
9
|
+
protected createDump(): void;
|
|
7
10
|
protected useDump(): void;
|
|
8
11
|
set(key: string, value: any): boolean;
|
|
9
12
|
get(key: string): any;
|
package/dist/datanautics.js
CHANGED
|
@@ -3,14 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Datanautics = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
|
+
const events_1 = require("events");
|
|
6
7
|
const property_accessor_1 = require("property-accessor");
|
|
7
8
|
const _const_1 = require("./constants");
|
|
8
9
|
class Datanautics {
|
|
9
10
|
options;
|
|
10
11
|
data;
|
|
12
|
+
eventEmitter;
|
|
11
13
|
constructor(options) {
|
|
12
14
|
this.options = Object.assign(_const_1.defaultDatanauticsOptions, options || {});
|
|
13
15
|
this.data = {};
|
|
16
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
17
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
14
18
|
if (!(0, fs_1.existsSync)(this.options.dumpPath)) {
|
|
15
19
|
(0, fs_1.mkdirSync)(this.options.dumpPath, { recursive: true });
|
|
16
20
|
}
|
|
@@ -22,20 +26,39 @@ class Datanautics {
|
|
|
22
26
|
this.options.logger.error(e);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const value = property_accessor_1.PropertyAccessor.get(key, this.data);
|
|
28
|
-
if (value !== undefined) {
|
|
29
|
+
this.eventEmitter.on(_const_1.DUMP_EVENT, () => {
|
|
30
|
+
this.createDump();
|
|
29
31
|
setTimeout(() => {
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
+
this.eventEmitter.emit(_const_1.DUMP_EVENT);
|
|
33
|
+
}, this.options.dumpInterval);
|
|
34
|
+
});
|
|
35
|
+
this.eventEmitter.emit(_const_1.DUMP_EVENT);
|
|
36
|
+
}
|
|
37
|
+
createDump() {
|
|
38
|
+
try {
|
|
39
|
+
const flat = property_accessor_1.PropertyAccessor.flat(this.data);
|
|
40
|
+
for (const key in flat) {
|
|
41
|
+
const value = property_accessor_1.PropertyAccessor.get(key, this.data);
|
|
42
|
+
if (value !== undefined) {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
(0, child_process_1.exec)(`echo ${value.toString()} > ${this.options.dumpPath}/${key}`, () => { });
|
|
45
|
+
}, 0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (this.options.verbose) {
|
|
51
|
+
this.options.logger.error(e);
|
|
52
|
+
}
|
|
32
53
|
}
|
|
33
54
|
}
|
|
34
55
|
useDump() {
|
|
35
56
|
const files = (0, fs_1.readdirSync)(this.options.dumpPath);
|
|
36
57
|
for (const file of files) {
|
|
37
58
|
if (file !== '.gitkeep') {
|
|
38
|
-
let value = (0, fs_1.readFileSync)(`${this.options.dumpPath}/${file}`)
|
|
59
|
+
let value = (0, fs_1.readFileSync)(`${this.options.dumpPath}/${file}`)
|
|
60
|
+
.toString()
|
|
61
|
+
.replace(/\n/g, '');
|
|
39
62
|
if (/^[+-]?\d+(\.\d+)?$/.test(value)) {
|
|
40
63
|
value = /^[+-]?\d+$/.test(value) ? parseInt(value, 10) : parseFloat(value);
|
|
41
64
|
}
|
|
@@ -47,11 +70,7 @@ class Datanautics {
|
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
72
|
set(key, value) {
|
|
50
|
-
|
|
51
|
-
if (set) {
|
|
52
|
-
this.store(key);
|
|
53
|
-
}
|
|
54
|
-
return set;
|
|
73
|
+
return property_accessor_1.PropertyAccessor.set(key, value, this.data);
|
|
55
74
|
}
|
|
56
75
|
get(key) {
|
|
57
76
|
return property_accessor_1.PropertyAccessor.get(key, this.data);
|
package/dist/datanautics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datanautics.js","sourceRoot":"","sources":["../src/datanautics.ts"],"names":[],"mappings":";;;AAAA,2BAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"datanautics.js","sourceRoot":"","sources":["../src/datanautics.ts"],"names":[],"mappings":";;;AAAA,2BAAsE;AACtE,iDAAqC;AACrC,mCAAsC;AACtC,yDAAqD;AAErD,mCAA+D;AAG/D,MAAa,WAAW;IACZ,OAAO,CAAqB;IAC5B,IAAI,CAAsB;IAC1B,YAAY,CAAe;IAErC,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,kCAAyB,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAY,EAAE,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAY,EAAE,CAAC;QACvC,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,IAAA,cAAS,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CA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