datanautics 1.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 ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [1.0.0] - 2025-05-02
9
+
10
+ ### Added
11
+
12
+ Basic package implementation
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ (The MIT License)
2
+ Copyright (c) 2024 Pavlo Lazunko <pavlo@databikers.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
+ and associated documentation files (the "Software"), to deal in the Software without restriction,
6
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice
11
+ shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Datanautics
2
+
3
+ **Datanautics** is a lightweight key-value storage system with support for nested property access, persistent dumps to disk, and configurable autosave intervals.
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 JSON file for durability.
6
+
7
+ ---
8
+
9
+ ## ✨ Features
10
+
11
+ - Dot/bracket notation access (`a.b[0]['c']`)
12
+ - Persistent JSON file storage (auto-saves at configurable intervals)
13
+ - Configurable verbosity and custom logger
14
+ - Simple API: `.get(key)`, `.set(key, value)`
15
+ - Built on top of [`property-accessor`](https://npmjs.com/package/property-accessor)
16
+
17
+ ---
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install datanautics
23
+ ```
24
+
25
+ ---
26
+
27
+ ## 🛠 Usage
28
+
29
+ ```ts
30
+ const { Datanautics } = require('datanautics');
31
+
32
+ const store = new Datanautics({
33
+ dumpPath: './data.json',
34
+ dumpInterval: 1000, // every 1 second
35
+ verbose: true,
36
+ logger: console
37
+ });
38
+
39
+ store.set('users[0].name', 'Alice');
40
+ console.log(store.get('users[0].name')); // Output: Alice
41
+ ```
42
+
43
+ ---
44
+
45
+ ## ⚙️ Configuration Options
46
+
47
+ You can pass the following options to the constructor:
48
+
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` |
55
+
56
+ ---
57
+
58
+ ## 🔧 Methods
59
+
60
+ ### `set(key: string, value: any): boolean`
61
+
62
+ Sets a value in the internal store using a path-based key.
63
+
64
+ Returns `true` on success, `false` if the key is invalid.
65
+
66
+ ### `get(key: string): any`
67
+
68
+ Retrieves the value at the specified path.
69
+
70
+ Returns `undefined` if the path does not exist or is non-evaluable.
71
+
72
+ ---
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
+
82
+ ## ✅ Requirements
83
+
84
+ - Node.js 14+
85
+
86
+ ---
87
+
88
+ ## 📚 Dependencies
89
+
90
+ - [`property-accessor`](https://npmjs.com/package/property-accessor) – Used for safe deep get/set operations
91
+
92
+ ---
93
+
94
+ ## 📄 [License](./LICENSE) MIT
package/ROADMAP.md ADDED
File without changes
package/data/.gitkeep ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ import { DatanauticsOptions } from '../options';
2
+ export declare const defaultDatanauticsOptions: DatanauticsOptions;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.defaultDatanauticsOptions = void 0;
27
+ const console = __importStar(require("console"));
28
+ const path_1 = require("path");
29
+ const default_dump_interval_1 = require("./default-dump-interval");
30
+ exports.defaultDatanauticsOptions = {
31
+ dumpInterval: default_dump_interval_1.DEFAULT_DUMP_INTERVAL,
32
+ verbose: true,
33
+ logger: console,
34
+ dumpPath: (0, path_1.resolve)(__dirname, '../../data/data.json'),
35
+ };
36
+ //# sourceMappingURL=default-datanautics-options.js.map
@@ -0,0 +1 @@
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,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_DUMP_INTERVAL = void 0;
4
+ exports.DEFAULT_DUMP_INTERVAL = 1000;
5
+ //# sourceMappingURL=default-dump-interval.js.map
@@ -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"}
@@ -0,0 +1 @@
1
+ export declare const DUMP_EVENT: string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DUMP_EVENT = void 0;
4
+ exports.DUMP_EVENT = 'dump';
5
+ //# sourceMappingURL=dump-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dump-event.js","sourceRoot":"","sources":["../../src/constants/dump-event.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAW,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './default-dump-interval';
2
+ export * from './dump-event';
3
+ export * from './default-datanautics-options';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default-dump-interval"), exports);
18
+ __exportStar(require("./dump-event"), exports);
19
+ __exportStar(require("./default-datanautics-options"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,+CAA6B;AAC7B,gEAA8C"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { DatanauticsOptions } from './options';
4
+ export declare class Datanautics {
5
+ protected options: DatanauticsOptions;
6
+ protected data: Record<string, any>;
7
+ protected eventEmitter: EventEmitter;
8
+ constructor(options?: DatanauticsOptions);
9
+ protected createDump(): void;
10
+ set(key: string, value: any): boolean;
11
+ get(key: string): any;
12
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Datanautics = void 0;
4
+ const fs_1 = require("fs");
5
+ const events_1 = require("events");
6
+ const property_accessor_1 = require("property-accessor");
7
+ const _const_1 = require("./constants");
8
+ class Datanautics {
9
+ options;
10
+ data;
11
+ eventEmitter;
12
+ constructor(options) {
13
+ this.options = Object.assign(_const_1.defaultDatanauticsOptions, options || {});
14
+ this.data = {};
15
+ this.eventEmitter = new events_1.EventEmitter();
16
+ this.eventEmitter = new events_1.EventEmitter();
17
+ if ((0, fs_1.existsSync)(this.options.dumpPath)) {
18
+ try {
19
+ this.data = JSON.parse((0, fs_1.readFileSync)(this.options.dumpPath).toString());
20
+ }
21
+ catch (e) {
22
+ if (this.options.verbose) {
23
+ this.options.logger.error(e);
24
+ }
25
+ }
26
+ }
27
+ this.eventEmitter.on(_const_1.DUMP_EVENT, () => {
28
+ this.createDump();
29
+ setTimeout(() => {
30
+ this.eventEmitter.emit(_const_1.DUMP_EVENT);
31
+ }, this.options.dumpInterval);
32
+ });
33
+ this.eventEmitter.emit(_const_1.DUMP_EVENT);
34
+ }
35
+ createDump() {
36
+ try {
37
+ (0, fs_1.writeFileSync)(this.options.dumpPath, JSON.stringify(this.data, null, 2), 'utf8');
38
+ }
39
+ catch (e) {
40
+ if (this.options.verbose) {
41
+ this.options.logger.error(e);
42
+ }
43
+ }
44
+ }
45
+ set(key, value) {
46
+ return property_accessor_1.PropertyAccessor.set(key, value, this.data);
47
+ }
48
+ get(key) {
49
+ return property_accessor_1.PropertyAccessor.get(key, this.data);
50
+ }
51
+ }
52
+ exports.Datanautics = Datanautics;
53
+ //# sourceMappingURL=datanautics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datanautics.js","sourceRoot":"","sources":["../src/datanautics.ts"],"names":[],"mappings":";;;AAAA,2BAA6D;AAC7D,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,C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,CAAC;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAEM,GAAG,CAAC,GAAW,EAAE,KAAU;QAChC,OAAO,oCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAEM,GAAG,CAAC,GAAW;QACpB,OAAO,oCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF;AA7CD,kCA6CC"}
@@ -0,0 +1,2 @@
1
+ export { DatanauticsOptions } from './options';
2
+ export { Datanautics } from './datanautics';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Datanautics = void 0;
4
+ var datanautics_1 = require("./datanautics");
5
+ Object.defineProperty(exports, "Datanautics", { enumerable: true, get: function () { return datanautics_1.Datanautics; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
@@ -0,0 +1,11 @@
1
+ interface Logger {
2
+ log(...args: any[]): void;
3
+ error(...args: any[]): void;
4
+ }
5
+ export type DatanauticsOptions = {
6
+ dumpPath: string;
7
+ dumpInterval?: number;
8
+ verbose?: boolean;
9
+ logger?: Logger;
10
+ };
11
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=datanautics-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datanautics-options.js","sourceRoot":"","sources":["../../src/options/datanautics-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from './datanautics-options';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./datanautics-options"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "datanautics",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "data store",
7
+ "local db",
8
+ "nested data",
9
+ "evaluate path"
10
+ ],
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "author": "Pavlo Lazunko",
14
+ "license": "MIT",
15
+ "scripts": {
16
+ "build": "rm -rf dist && tsc && tsc-alias && eslint src/**/*.ts{,x}",
17
+ "eslint": "eslint src --ext .ts",
18
+ "prettier-check": "prettier . --check",
19
+ "prettier-write": "prettier . --write",
20
+ "test": "node test/test.js",
21
+ "runtime": "node dist/index.js"
22
+ },
23
+ "dependencies": {
24
+ "property-accessor": "^2.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "20.10.6",
28
+ "@types/prettier": "2.6.0",
29
+ "@types/uuid": "10.0.0",
30
+ "@typescript-eslint/eslint-plugin": "6.17.0",
31
+ "@typescript-eslint/parser": "6.17.0",
32
+ "eslint": "8.47.0",
33
+ "husky": "3.0.0",
34
+ "prettier": "3.3.3",
35
+ "prettier-plugin-multiline-arrays": "3.0.6",
36
+ "ts-node": "10.9.2",
37
+ "tsc-alias": "1.8.10",
38
+ "typescript": "5.3.3"
39
+ },
40
+ "husky": {
41
+ "hooks": {
42
+ "pre-commit": "npm run eslint"
43
+ }
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git@github.com:Paul-Lazunko/datanautics.git"
48
+ },
49
+ "engines": {
50
+ "node": ">=14.0.0"
51
+ }
52
+ }
package/test/test.js ADDED
@@ -0,0 +1,23 @@
1
+ const assert = require('assert');
2
+ const { resolve } = require('path');
3
+ const { readFileSync, unlinkSync } = require('fs');
4
+
5
+ const { Datanautics } = require('../dist');
6
+ const { setTimeout } = require('timers');
7
+
8
+ const dumpPath = resolve(__dirname, './data.json');
9
+ const data = { user: { firstname: 'John', lastname: 'Doe' }, score: [27] };
10
+
11
+ const db = new Datanautics({ dumpPath, dumpInterval: 0 });
12
+
13
+ assert.equal(db.set('user.firstname', data.user.firstname), true);
14
+ assert.equal(db.set('user.lastname', data.user.lastname), true);
15
+ assert.equal(db.set('score[0]', data.score[0]), true);
16
+
17
+ setTimeout(() => {
18
+ const storedData = readFileSync(dumpPath).toString();
19
+ assert.equal(storedData, JSON.stringify(data, null, 2));
20
+ unlinkSync(dumpPath);
21
+ console.log('tests passed');
22
+ process.exit(0)
23
+ });