datanautics 1.1.2 → 2.0.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 +7 -0
- package/README.md +3 -13
- package/dist/constants/default-datanautics-options.js +0 -2
- package/dist/constants/default-datanautics-options.js.map +1 -1
- package/dist/constants/index.d.ts +0 -1
- package/dist/constants/index.js +0 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/datanautics.d.ts +1 -4
- package/dist/datanautics.js +15 -29
- package/dist/datanautics.js.map +1 -1
- package/dist/options/datanautics-options.d.ts +0 -1
- package/package.json +1 -1
- package/dist/constants/default-dump-interval.d.ts +0 -1
- package/dist/constants/default-dump-interval.js +0 -5
- package/dist/constants/default-dump-interval.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ 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.0.0] - 2025-05-17 (**Breaking changes!**)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Instead of background storing entire object store each key-value eventually
|
|
12
|
+
- Replaced dumpInterval from options
|
|
13
|
+
|
|
14
|
+
---
|
|
8
15
|
## [1.1.2] - 2025-05-17
|
|
9
16
|
|
|
10
17
|
### Fixed
|
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 and persistent dumps to disk.
|
|
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 files for durability.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -30,8 +30,7 @@ npm install datanautics
|
|
|
30
30
|
const { Datanautics } = require('datanautics');
|
|
31
31
|
|
|
32
32
|
const store = new Datanautics({
|
|
33
|
-
dumpPath: './data
|
|
34
|
-
dumpInterval: 1000, // every 1 second
|
|
33
|
+
dumpPath: './data',
|
|
35
34
|
verbose: true,
|
|
36
35
|
logger: console
|
|
37
36
|
});
|
|
@@ -49,7 +48,6 @@ You can pass the following options to the constructor:
|
|
|
49
48
|
| Option | Type | Description | Default |
|
|
50
49
|
|----------------|---------------------|------------------------------------------------------|-------------------------------------------|
|
|
51
50
|
| `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
51
|
| `verbose` | `boolean`, optional | Log errors during reading/writing | `false` |
|
|
54
52
|
| `logger` | `object`, optional | Custom logger (`console`, `winston`, etc.) | `console` |
|
|
55
53
|
|
|
@@ -71,14 +69,6 @@ Returns `undefined` if the path does not exist or is non-evaluable.
|
|
|
71
69
|
|
|
72
70
|
---
|
|
73
71
|
|
|
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
|
-
|
|
82
72
|
## ✅ Requirements
|
|
83
73
|
|
|
84
74
|
- Node.js 14+
|
|
@@ -26,9 +26,7 @@ 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");
|
|
30
29
|
exports.defaultDatanauticsOptions = {
|
|
31
|
-
dumpInterval: default_dump_interval_1.DEFAULT_DUMP_INTERVAL,
|
|
32
30
|
verbose: true,
|
|
33
31
|
logger: console,
|
|
34
32
|
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;AAIlB,QAAA,yBAAyB,GAAuB;IAC3D,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,sBAAsB,CAAC;CACrD,CAAC"}
|
package/dist/constants/index.js
CHANGED
|
@@ -14,7 +14,6 @@ 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);
|
|
18
17
|
__exportStar(require("./dump-event"), exports);
|
|
19
18
|
__exportStar(require("./default-datanautics-options"), exports);
|
|
20
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,gEAA8C"}
|
package/dist/datanautics.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
1
|
import { DatanauticsOptions } from './options';
|
|
4
2
|
export declare class Datanautics {
|
|
5
3
|
protected options: DatanauticsOptions;
|
|
6
4
|
protected data: Record<string, any>;
|
|
7
|
-
protected eventEmitter: EventEmitter;
|
|
8
5
|
constructor(options?: DatanauticsOptions);
|
|
9
|
-
protected
|
|
6
|
+
protected store(key: string): void;
|
|
10
7
|
protected useDump(): void;
|
|
11
8
|
set(key: string, value: any): boolean;
|
|
12
9
|
get(key: string): any;
|
package/dist/datanautics.js
CHANGED
|
@@ -3,18 +3,14 @@ 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");
|
|
7
6
|
const property_accessor_1 = require("property-accessor");
|
|
8
7
|
const _const_1 = require("./constants");
|
|
9
8
|
class Datanautics {
|
|
10
9
|
options;
|
|
11
10
|
data;
|
|
12
|
-
eventEmitter;
|
|
13
11
|
constructor(options) {
|
|
14
12
|
this.options = Object.assign(_const_1.defaultDatanauticsOptions, options || {});
|
|
15
13
|
this.data = {};
|
|
16
|
-
this.eventEmitter = new events_1.EventEmitter();
|
|
17
|
-
this.eventEmitter = new events_1.EventEmitter();
|
|
18
14
|
if (!(0, fs_1.existsSync)(this.options.dumpPath)) {
|
|
19
15
|
(0, fs_1.mkdirSync)(this.options.dumpPath, { recursive: true });
|
|
20
16
|
}
|
|
@@ -26,46 +22,36 @@ class Datanautics {
|
|
|
26
22
|
this.options.logger.error(e);
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
|
-
this.eventEmitter.on(_const_1.DUMP_EVENT, () => {
|
|
30
|
-
this.createDump();
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
this.eventEmitter.emit(_const_1.DUMP_EVENT);
|
|
33
|
-
}, this.options.dumpInterval);
|
|
34
|
-
});
|
|
35
|
-
this.eventEmitter.emit(_const_1.DUMP_EVENT);
|
|
36
25
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
}
|
|
26
|
+
store(key) {
|
|
27
|
+
const value = property_accessor_1.PropertyAccessor.get(key, this.data);
|
|
28
|
+
if (value !== undefined) {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
(0, child_process_1.exec)(`echo ${value.toString()} > ${this.options.dumpPath}/${key}`, () => { });
|
|
31
|
+
}, 0);
|
|
53
32
|
}
|
|
54
33
|
}
|
|
55
34
|
useDump() {
|
|
56
35
|
const files = (0, fs_1.readdirSync)(this.options.dumpPath);
|
|
57
36
|
for (const file of files) {
|
|
58
37
|
if (file !== '.gitkeep') {
|
|
59
|
-
let value = (0, fs_1.readFileSync)(`${this.options.dumpPath}/${file}`).toString();
|
|
38
|
+
let value = (0, fs_1.readFileSync)(`${this.options.dumpPath}/${file}`).toString().replace(/\n/g, '');
|
|
60
39
|
if (/^[+-]?\d+(\.\d+)?$/.test(value)) {
|
|
61
40
|
value = /^[+-]?\d+$/.test(value) ? parseInt(value, 10) : parseFloat(value);
|
|
62
41
|
}
|
|
42
|
+
else if (/^false|true$/.test(value)) {
|
|
43
|
+
value = /^true$/.test(value);
|
|
44
|
+
}
|
|
63
45
|
property_accessor_1.PropertyAccessor.set(file, value, this.data);
|
|
64
46
|
}
|
|
65
47
|
}
|
|
66
48
|
}
|
|
67
49
|
set(key, value) {
|
|
68
|
-
|
|
50
|
+
const set = property_accessor_1.PropertyAccessor.set(key, value, this.data);
|
|
51
|
+
if (set) {
|
|
52
|
+
this.store(key);
|
|
53
|
+
}
|
|
54
|
+
return set;
|
|
69
55
|
}
|
|
70
56
|
get(key) {
|
|
71
57
|
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,iDAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"datanautics.js","sourceRoot":"","sources":["../src/datanautics.ts"],"names":[],"mappings":";;;AAAA,2BAAsE;AACtE,iDAAoC;AACpC,yDAAqD;AAErD,mCAAmD;AAGnD,MAAa,WAAW;IACZ,OAAO,CAAqB;IAC5B,IAAI,CAAsB;IAEpC,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,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,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAES,KAAK,CAAC,GAAW;QACzB,MAAM,KAAK,GAAG,oCAAg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EAAE,KAAU;QAChC,MAAM,GAAG,GAAI,oCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,GAAG,CAAC,GAAW;QACpB,OAAO,oCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF;AAtDD,kCAsDC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_DUMP_INTERVAL: number;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-dump-interval.js","sourceRoot":"","sources":["../../src/constants/default-dump-interval.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAW,IAAI,CAAC"}
|