json-database-st 2.0.2 → 3.1.4

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/README.md CHANGED
@@ -1,65 +1,88 @@
1
1
  # JSON Database ST
2
2
 
3
- [![NPM Version](https://badge.fury.io/js/json-database-st.svg)](https://badge.fury.io/js/json-database-st)
4
- [![NPM Downloads](https://img.shields.io/npm/dm/json-database-st.svg)](https://www.npmjs.com/package/json-database-st)
3
+ > High-performance, lightweight JSON-based database engine for Node.js & Bun.
4
+ > Powered by a **Rust** core for speed and reliability.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/json-database-st.svg)](https://www.npmjs.com/package/json-database-st)
5
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
8
 
7
- A high-performance, lightweight, and secure JSON-based database engine for Node.js. Designed for applications that need reliable data persistence, atomic operations, and encryption without the overhead of a full SQL server.
9
+ > **WARNING:** This library currently only works on **macOS** and **Windows**. Linux support is temporarily unavailable.
8
10
 
9
- ## 🚀 Key Features
11
+ ## 🚀 Features
10
12
 
11
- - **🔒 AES-256-GCM Encryption:** Military-grade security for your data at rest.
12
- - **⚡ O(1) Indexing:** Instant lookups, no matter how big the database gets.
13
- - **🛡️ Atomic Writes:** Zero corruption risk. Uses lockfiles and temp-write-swap strategy.
14
- - **🔢 Math Helpers:** Atomic `add` and `subtract` for financial/gaming logic.
15
- - **📄 Pagination:** Built-in support for handling large lists efficiently.
16
- - **📸 Snapshots:** One-line command to backup your entire database.
13
+ - **⚡ Blazing Fast:** Core logic written in **Rust** via N-API for native performance.
14
+ - **🛡️ Atomic Operations:** Uses Write-Ahead Logging (WAL) and atomic file swaps to prevent data corruption.
15
+ - **🔍 O(1) Indexing:** In-memory `Map` indices allow for instant lookups by field.
16
+ - **🔒 Encryption:** Optional AES-256-GCM encryption for data at rest.
17
+ - **📦 Zero Dependencies (Runtime):** Self-contained native binary; no heavy external DB servers required.
18
+ - **🔄 Middleware:** Support for `before` and `after` hooks on operations.
19
+ - **💾 JSON Compatible:** Stores data in a simple, portable JSON file.
17
20
 
18
21
  ## 📦 Installation
19
22
 
20
23
  ```bash
21
- npm install json-database-st lodash proper-lockfile
24
+ bun add json-database-st
25
+ # or
26
+ npm install json-database-st
22
27
  ```
23
28
 
24
- ## Quick Start
25
-
26
- ```javascript
27
- const JSONDatabase = require('json-database-st');
29
+ ## 🛠️ Usage
28
30
 
29
- const db = new JSONDatabase('data.json');
31
+ ### Basic Example
30
32
 
31
- async function run() {
32
- // 1. Set Data
33
- await db.set('user.name', 'Sethun');
34
-
35
- // 2. Atomic Math (New!)
36
- await db.set('user.balance', 1000);
37
- await db.add('user.balance', 500); // Balance is now 1500
38
-
39
- // 3. Arrays with Uniqueness
40
- await db.push('inventory', { id: 1, item: 'Laptop' });
33
+ ```javascript
34
+ const { JSONDatabase } = require('json-database-st');
35
+
36
+ const db = new JSONDatabase('mydb.json', {
37
+ encryptionKey: 'my-secret-key-123', // Optional: encrypts the file
38
+ indices: [
39
+ { name: 'email', path: 'users', field: 'email' } // O(1) lookup index
40
+ ]
41
+ });
42
+
43
+ async function main() {
44
+ // Write data
45
+ await db.set('users.u1', {
46
+ id: 1,
47
+ name: 'Alice',
48
+ email: 'alice@example.com'
49
+ });
50
+
51
+ // Read data
52
+ const user = await db.get('users.u1');
53
+ console.log(user);
54
+ // { id: 1, name: 'Alice', ... }
55
+
56
+ // O(1) Lookup by Index
57
+ const alice = await db.findByIndex('email', 'alice@example.com');
58
+ console.log(alice);
59
+ // { id: 1, name: 'Alice', ... }
41
60
 
42
- console.log(await db.get('user'));
61
+ // Atomic Math Operations
62
+ await db.add('stats.visits', 1);
43
63
  }
44
64
 
45
- run();
65
+ main();
46
66
  ```
47
67
 
68
+ ## ⚙️ Configuration
69
+
70
+ | Option | Type | Default | Description |
71
+ |os|--- |--- |--- |--- |
72
+ | `saveDelay` | `number` | `60` | Debounce time (ms) for writes. Higher = better batching, lower = faster disk commit. |
73
+ | `wal` | `boolean` | `true` | If true, uses Write-Ahead Logging for maximum durability. |
74
+
48
75
  ## 📖 Documentation
49
76
 
50
- Full documentation, API references, and benchmarks are available on the **[Home Page](https://sethunthunder111.github.io/json-database-st/)**.
77
+ Visit our full documentation site: [https://sethunthunder111.github.io/json-database-st/docs.html](https://sethunthunder111.github.io/json-database-st/docs.html)
78
+
51
79
 
52
- ## 🤝 Contributing
80
+ ## 📊 Benchmarks
53
81
 
54
- Built by **SethunThunder**.
82
+ *Running benchmarks on your local machine...*
55
83
 
56
- ## 🚀 Performance (v2.0)
84
+ > **Note:** Performance depends heavily on disk I/O speed (SSD recommended).
57
85
 
58
- | Operation | 10k Records | 1M Records |
59
- | :--- | :--- | :--- |
60
- | **Indexed Read** | 0.15 ms | 0.07 ms |
61
- | **Write (Ingest)** | 42,450 ops/sec | 57,845 ops/sec |
62
- | **Single Update** | 100 ms | 6.3 s |
86
+ ## 📄 License
63
87
 
64
- > **Fastest in Class:** Indexed reads are O(1). Updates are 1.5x faster than v1.0.
65
- > [View Full Benchmarks](./BENCHMARKS.md)
88
+ MIT
package/index.d.ts ADDED
File without changes
Binary file
package/index.js ADDED
@@ -0,0 +1,117 @@
1
+ const { platform, arch } = process
2
+
3
+ let nativeBinding = null
4
+ let loadError = null
5
+
6
+ switch (platform) {
7
+ case 'win32':
8
+ switch (arch) {
9
+ case 'x64':
10
+ try {
11
+ nativeBinding = require('./index.win32-x64-msvc.node')
12
+ } catch (e) {
13
+ loadError = e
14
+ }
15
+ break
16
+ case 'ia32':
17
+ try {
18
+ nativeBinding = require('./index.win32-ia32-msvc.node')
19
+ } catch (e) {
20
+ loadError = e
21
+ }
22
+ break
23
+ case 'arm64':
24
+ try {
25
+ nativeBinding = require('./index.win32-arm64-msvc.node')
26
+ } catch (e) {
27
+ loadError = e
28
+ }
29
+ break
30
+ default:
31
+ loadError = new Error(`Unsupported architecture on Windows: ${arch}`)
32
+ }
33
+ break
34
+ case 'darwin':
35
+ switch (arch) {
36
+ case 'x64':
37
+ try {
38
+ nativeBinding = require('./index.darwin-x64.node')
39
+ } catch (e) {
40
+ loadError = e
41
+ }
42
+ break
43
+ case 'arm64':
44
+ try {
45
+ nativeBinding = require('./index.darwin-arm64.node')
46
+ } catch (e) {
47
+ loadError = e
48
+ }
49
+ break
50
+ default:
51
+ loadError = new Error(`Unsupported architecture on macOS: ${arch}`)
52
+ }
53
+ break
54
+ case 'freebsd':
55
+ if (arch !== 'x64') {
56
+ loadError = new Error(`Unsupported architecture on FreeBSD: ${arch}`)
57
+ } else {
58
+ try {
59
+ nativeBinding = require('./index.freebsd-x64.node')
60
+ } catch (e) {
61
+ loadError = e
62
+ }
63
+ }
64
+ break
65
+ case 'linux':
66
+ switch (arch) {
67
+ case 'x64':
68
+ try {
69
+ nativeBinding = require('./index.linux-x64-gnu.node')
70
+ } catch (e) {
71
+ loadError = e
72
+ try {
73
+ nativeBinding = require('./index.linux-x64-musl.node')
74
+ loadError = null
75
+ } catch (e) {
76
+ loadError = e
77
+ }
78
+ }
79
+ break
80
+ case 'arm64':
81
+ try {
82
+ nativeBinding = require('./index.linux-arm64-gnu.node')
83
+ } catch (e) {
84
+ loadError = e
85
+ try {
86
+ nativeBinding = require('./index.linux-arm64-musl.node')
87
+ loadError = null
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ }
92
+ break
93
+ case 'arm':
94
+ try {
95
+ nativeBinding = require('./index.linux-arm-gnueabihf.node')
96
+ } catch (e) {
97
+ loadError = e
98
+ }
99
+ break
100
+ default:
101
+ loadError = new Error(`Unsupported architecture on Linux: ${arch}`)
102
+ }
103
+ break
104
+ default:
105
+ loadError = new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
106
+ }
107
+
108
+ if (!nativeBinding) {
109
+ if (loadError) {
110
+ throw loadError
111
+ }
112
+ throw new Error(`Failed to load native binding`)
113
+ }
114
+
115
+ const { DatabaseCore } = nativeBinding
116
+
117
+ module.exports.DatabaseCore = DatabaseCore
Binary file
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "json-database-st",
3
- "version": "2.0.02",
4
- "description": "A simple, promise-based JSON file database for Node.js with atomic operations and lodash integration.",
3
+ "version": "3.1.4",
4
+ "description": "High-performance JSON database with Rust core, ACID compliance (WAL), and MongoDB-style queries.",
5
5
  "main": "JSONDatabase.js",
6
+ "module": "JSONDatabase.ts",
6
7
  "types": "JSONDatabase.d.ts",
7
8
  "scripts": {
8
9
  "test": "jest",
9
- "benchmark": "node benchmark.js"
10
+ "benchmark": "node benchmark.js",
11
+ "build": "napi build --platform --release",
12
+ "build:debug": "napi build --platform",
13
+ "build:ts": "bun build JSONDatabase.ts --outfile JSONDatabase.js --target node --format cjs --external ./index",
14
+ "build:all": "bun run build && bun run build:ts"
10
15
  },
11
16
  "repository": {
12
17
  "type": "git",
@@ -30,7 +35,7 @@
30
35
  "bugs": {
31
36
  "url": "https://github.com/sethunthunder111/json-database-st/issues"
32
37
  },
33
- "homepage": "https://github.com/sethunthunder111/json-database-st#readme",
38
+ "homepage": "https://sethunthunder111.github.io/json-database-st/",
34
39
  "dependencies": {
35
40
  "lodash": "^4.17.21",
36
41
  "proper-lockfile": "^4.1.2"
@@ -40,11 +45,19 @@
40
45
  },
41
46
  "files": [
42
47
  "JSONDatabase.js",
48
+ "JSONDatabase.d.ts",
49
+ "JSONDatabase.legacy.js",
50
+ "index.js",
51
+ "index.d.ts",
52
+ "*.node",
43
53
  "LICENSE",
44
- "README.md",
45
- "JSONDatabase.d.ts"
54
+ "README.md"
46
55
  ],
47
56
  "devDependencies": {
57
+ "@napi-rs/cli": "^3.5.1",
48
58
  "jest": "^30.1.1"
59
+ },
60
+ "napi": {
61
+ "binaryName": "index"
49
62
  }
50
63
  }