@push.rocks/smartdb 1.0.1 → 2.1.1
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/.smartconfig.json +18 -4
- package/dist_rust/rustdb_linux_amd64 +0 -0
- package/dist_rust/rustdb_linux_arm64 +0 -0
- package/dist_ts/00_commitinfo_data.js +3 -3
- package/dist_ts/index.d.ts +1 -0
- package/dist_ts/ts_local/classes.localsmartdb.d.ts +5 -5
- package/dist_ts/ts_local/classes.localsmartdb.js +7 -9
- package/dist_ts/ts_local/plugins.d.ts +1 -2
- package/dist_ts/ts_local/plugins.js +3 -3
- package/dist_ts/ts_smartdb/index.d.ts +2 -24
- package/dist_ts/ts_smartdb/index.js +4 -29
- package/dist_ts/ts_smartdb/plugins.d.ts +2 -10
- package/dist_ts/ts_smartdb/plugins.js +3 -13
- package/dist_ts/ts_smartdb/rust-db-bridge.d.ts +122 -0
- package/dist_ts/ts_smartdb/rust-db-bridge.js +113 -0
- package/dist_ts/ts_smartdb/server/SmartdbServer.d.ts +39 -37
- package/dist_ts/ts_smartdb/server/SmartdbServer.js +87 -206
- package/dist_ts/ts_smartdb/server/index.d.ts +0 -4
- package/dist_ts/ts_smartdb/server/index.js +1 -5
- package/dist_ts_debugserver/bundled.d.ts +4 -0
- package/dist_ts_debugserver/bundled.js +12 -0
- package/dist_ts_debugserver/classes.debugserver.d.ts +36 -0
- package/dist_ts_debugserver/classes.debugserver.js +95 -0
- package/dist_ts_debugserver/index.d.ts +2 -0
- package/dist_ts_debugserver/index.js +2 -0
- package/dist_ts_debugserver/plugins.d.ts +2 -0
- package/dist_ts_debugserver/plugins.js +3 -0
- package/dist_ts_debugui/index.d.ts +2 -0
- package/dist_ts_debugui/index.js +2 -0
- package/dist_ts_debugui/plugins.d.ts +1 -0
- package/dist_ts_debugui/plugins.js +2 -0
- package/dist_ts_debugui/smartdb-debugui.d.ts +62 -0
- package/dist_ts_debugui/smartdb-debugui.js +1132 -0
- package/license +3 -1
- package/package.json +14 -13
- package/readme.md +209 -177
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/index.ts +11 -0
- package/ts/ts_local/classes.localsmartdb.ts +5 -6
- package/ts/ts_local/plugins.ts +1 -3
- package/ts/ts_smartdb/index.ts +14 -41
- package/ts/ts_smartdb/plugins.ts +2 -15
- package/ts/ts_smartdb/rust-db-bridge.ts +262 -0
- package/ts/ts_smartdb/server/SmartdbServer.ts +115 -246
- package/ts/ts_smartdb/server/index.ts +0 -7
- package/dist_ts/ts_smartdb/engine/AggregationEngine.d.ts +0 -66
- package/dist_ts/ts_smartdb/engine/AggregationEngine.js +0 -189
- package/dist_ts/ts_smartdb/engine/IndexEngine.d.ts +0 -97
- package/dist_ts/ts_smartdb/engine/IndexEngine.js +0 -678
- package/dist_ts/ts_smartdb/engine/QueryEngine.d.ts +0 -54
- package/dist_ts/ts_smartdb/engine/QueryEngine.js +0 -271
- package/dist_ts/ts_smartdb/engine/QueryPlanner.d.ts +0 -64
- package/dist_ts/ts_smartdb/engine/QueryPlanner.js +0 -308
- package/dist_ts/ts_smartdb/engine/SessionEngine.d.ts +0 -117
- package/dist_ts/ts_smartdb/engine/SessionEngine.js +0 -232
- package/dist_ts/ts_smartdb/engine/TransactionEngine.d.ts +0 -85
- package/dist_ts/ts_smartdb/engine/TransactionEngine.js +0 -287
- package/dist_ts/ts_smartdb/engine/UpdateEngine.d.ts +0 -47
- package/dist_ts/ts_smartdb/engine/UpdateEngine.js +0 -461
- package/dist_ts/ts_smartdb/errors/SmartdbErrors.d.ts +0 -100
- package/dist_ts/ts_smartdb/errors/SmartdbErrors.js +0 -155
- package/dist_ts/ts_smartdb/server/CommandRouter.d.ts +0 -87
- package/dist_ts/ts_smartdb/server/CommandRouter.js +0 -222
- package/dist_ts/ts_smartdb/server/WireProtocol.d.ts +0 -117
- package/dist_ts/ts_smartdb/server/WireProtocol.js +0 -298
- package/dist_ts/ts_smartdb/server/handlers/AdminHandler.d.ts +0 -100
- package/dist_ts/ts_smartdb/server/handlers/AdminHandler.js +0 -668
- package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.d.ts +0 -31
- package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.js +0 -277
- package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.d.ts +0 -8
- package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.js +0 -95
- package/dist_ts/ts_smartdb/server/handlers/FindHandler.d.ts +0 -31
- package/dist_ts/ts_smartdb/server/handlers/FindHandler.js +0 -291
- package/dist_ts/ts_smartdb/server/handlers/HelloHandler.d.ts +0 -11
- package/dist_ts/ts_smartdb/server/handlers/HelloHandler.js +0 -62
- package/dist_ts/ts_smartdb/server/handlers/IndexHandler.d.ts +0 -20
- package/dist_ts/ts_smartdb/server/handlers/IndexHandler.js +0 -183
- package/dist_ts/ts_smartdb/server/handlers/InsertHandler.d.ts +0 -8
- package/dist_ts/ts_smartdb/server/handlers/InsertHandler.js +0 -79
- package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.d.ts +0 -24
- package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.js +0 -296
- package/dist_ts/ts_smartdb/server/handlers/index.d.ts +0 -8
- package/dist_ts/ts_smartdb/server/handlers/index.js +0 -10
- package/dist_ts/ts_smartdb/storage/FileStorageAdapter.d.ts +0 -85
- package/dist_ts/ts_smartdb/storage/FileStorageAdapter.js +0 -465
- package/dist_ts/ts_smartdb/storage/IStorageAdapter.d.ts +0 -145
- package/dist_ts/ts_smartdb/storage/IStorageAdapter.js +0 -2
- package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.d.ts +0 -67
- package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.js +0 -378
- package/dist_ts/ts_smartdb/storage/OpLog.d.ts +0 -93
- package/dist_ts/ts_smartdb/storage/OpLog.js +0 -221
- package/dist_ts/ts_smartdb/storage/WAL.d.ts +0 -117
- package/dist_ts/ts_smartdb/storage/WAL.js +0 -286
- package/dist_ts/ts_smartdb/types/interfaces.d.ts +0 -363
- package/dist_ts/ts_smartdb/types/interfaces.js +0 -2
- package/dist_ts/ts_smartdb/utils/checksum.d.ts +0 -30
- package/dist_ts/ts_smartdb/utils/checksum.js +0 -77
- package/dist_ts/ts_smartdb/utils/index.d.ts +0 -1
- package/dist_ts/ts_smartdb/utils/index.js +0 -2
- package/ts/ts_smartdb/engine/AggregationEngine.ts +0 -283
- package/ts/ts_smartdb/engine/IndexEngine.ts +0 -798
- package/ts/ts_smartdb/engine/QueryEngine.ts +0 -301
- package/ts/ts_smartdb/engine/QueryPlanner.ts +0 -393
- package/ts/ts_smartdb/engine/SessionEngine.ts +0 -292
- package/ts/ts_smartdb/engine/TransactionEngine.ts +0 -351
- package/ts/ts_smartdb/engine/UpdateEngine.ts +0 -506
- package/ts/ts_smartdb/errors/SmartdbErrors.ts +0 -181
- package/ts/ts_smartdb/server/CommandRouter.ts +0 -289
- package/ts/ts_smartdb/server/WireProtocol.ts +0 -416
- package/ts/ts_smartdb/server/handlers/AdminHandler.ts +0 -719
- package/ts/ts_smartdb/server/handlers/AggregateHandler.ts +0 -342
- package/ts/ts_smartdb/server/handlers/DeleteHandler.ts +0 -115
- package/ts/ts_smartdb/server/handlers/FindHandler.ts +0 -330
- package/ts/ts_smartdb/server/handlers/HelloHandler.ts +0 -78
- package/ts/ts_smartdb/server/handlers/IndexHandler.ts +0 -207
- package/ts/ts_smartdb/server/handlers/InsertHandler.ts +0 -97
- package/ts/ts_smartdb/server/handlers/UpdateHandler.ts +0 -344
- package/ts/ts_smartdb/server/handlers/index.ts +0 -10
- package/ts/ts_smartdb/storage/FileStorageAdapter.ts +0 -562
- package/ts/ts_smartdb/storage/IStorageAdapter.ts +0 -208
- package/ts/ts_smartdb/storage/MemoryStorageAdapter.ts +0 -455
- package/ts/ts_smartdb/storage/OpLog.ts +0 -282
- package/ts/ts_smartdb/storage/WAL.ts +0 -375
- package/ts/ts_smartdb/types/interfaces.ts +0 -433
- package/ts/ts_smartdb/utils/checksum.ts +0 -88
- package/ts/ts_smartdb/utils/index.ts +0 -1
package/license
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Task Venture Capital GmbH
|
|
2
4
|
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartdb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./dist_ts/index.js"
|
|
7
|
+
".": "./dist_ts/index.js",
|
|
8
|
+
"./debugui": "./dist_ts_debugui/index.js",
|
|
9
|
+
"./debugserver": "./dist_ts_debugserver/index.js"
|
|
8
10
|
},
|
|
9
11
|
"type": "module",
|
|
10
12
|
"author": "Task Venture Capital GmbH",
|
|
11
13
|
"license": "MIT",
|
|
12
14
|
"scripts": {
|
|
15
|
+
"test:before": "(tsrust)",
|
|
13
16
|
"test": "(tstest test/. --verbose --logfile --timeout 60)",
|
|
14
|
-
"build": "(tsbuild tsfolders)",
|
|
17
|
+
"build": "(tsbundle) && (tsbuild tsfolders) && (tsrust)",
|
|
15
18
|
"buildDocs": "tsdoc"
|
|
16
19
|
},
|
|
17
20
|
"devDependencies": {
|
|
18
21
|
"@git.zone/tsbuild": "^4.4.0",
|
|
19
22
|
"@git.zone/tsbundle": "^2.10.0",
|
|
20
23
|
"@git.zone/tsrun": "^2.0.2",
|
|
24
|
+
"@git.zone/tsrust": "^1.3.2",
|
|
21
25
|
"@git.zone/tstest": "^3.6.1",
|
|
22
26
|
"@types/node": "^25.5.0",
|
|
23
27
|
"mongodb": "^7.1.1"
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@push.rocks/
|
|
29
|
-
"@push.rocks/smartrx": "^3.0.10",
|
|
30
|
-
"bson": "^7.2.0",
|
|
31
|
-
"mingo": "^7.2.0"
|
|
30
|
+
"@api.global/typedserver": "^8.0.0",
|
|
31
|
+
"@design.estate/dees-element": "^2.0.0",
|
|
32
|
+
"@push.rocks/smartrust": "^1.3.2"
|
|
32
33
|
},
|
|
33
34
|
"browserslist": [
|
|
34
35
|
"last 1 chrome versions"
|
|
@@ -46,14 +47,14 @@
|
|
|
46
47
|
"readme.md"
|
|
47
48
|
],
|
|
48
49
|
"keywords": [
|
|
49
|
-
"mongodb",
|
|
50
|
+
"mongodb-compatible",
|
|
50
51
|
"wire protocol",
|
|
51
|
-
"
|
|
52
|
+
"embedded database",
|
|
52
53
|
"in-memory database",
|
|
53
54
|
"testing",
|
|
54
55
|
"local database",
|
|
55
56
|
"database server",
|
|
56
|
-
"
|
|
57
|
+
"rust"
|
|
57
58
|
],
|
|
58
59
|
"homepage": "https://code.foss.global/push.rocks/smartdb#readme",
|
|
59
60
|
"repository": {
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @push.rocks/smartdb
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A MongoDB-compatible embedded database server powered by Rust 🦀⚡ — use the official `mongodb` driver and it just works. No binary downloads, instant startup, zero config. Features a built-in **operation log** with **point-in-time revert** and a web-based **debug dashboard**.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -14,24 +14,74 @@ npm install @push.rocks/smartdb
|
|
|
14
14
|
|
|
15
15
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
|
16
16
|
|
|
17
|
+
---
|
|
18
|
+
|
|
17
19
|
## What It Does
|
|
18
20
|
|
|
19
|
-
`@push.rocks/smartdb` is a **real database server**
|
|
21
|
+
`@push.rocks/smartdb` is a **real database server** that speaks the wire protocol used by MongoDB drivers. The core engine is written in Rust for high performance, with a thin TypeScript orchestration layer. Connect with the standard `mongodb` Node.js driver — no mocks, no stubs, no external binaries required.
|
|
20
22
|
|
|
21
23
|
### Why SmartDB?
|
|
22
24
|
|
|
23
|
-
| | SmartDB |
|
|
25
|
+
| | SmartDB | External DB Server |
|
|
24
26
|
|---|---|---|
|
|
25
|
-
| **Startup time** | ~
|
|
26
|
-
| **Binary download** |
|
|
27
|
-
| **
|
|
27
|
+
| **Startup time** | ~30ms | ~2-5s |
|
|
28
|
+
| **Binary download** | Bundled (~7MB) | ~200MB+ |
|
|
29
|
+
| **Install** | `pnpm add` | System package / Docker |
|
|
28
30
|
| **Persistence** | Memory or file-based | Full disk engine |
|
|
29
|
-
| **
|
|
31
|
+
| **Debug UI** | Built-in 🖥️ | External tooling |
|
|
32
|
+
| **Point-in-time revert** | Built-in ⏪ | Requires oplog tailing |
|
|
33
|
+
| **Perfect for** | Unit tests, CI/CD, prototyping, local dev, embedded | Production at scale |
|
|
30
34
|
|
|
31
|
-
###
|
|
35
|
+
### Three Ways to Use It
|
|
32
36
|
|
|
37
|
+
- 🎯 **`LocalSmartDb`** — Zero-config convenience. Give it a folder path, get a persistent database over a Unix socket. Done.
|
|
33
38
|
- 🏗️ **`SmartdbServer`** — Full control. Configure port, host, storage backend, Unix sockets. Great for test fixtures or custom setups.
|
|
34
|
-
-
|
|
39
|
+
- 🖥️ **`SmartdbDebugServer`** — Launch a web dashboard to visually browse collections, inspect the operation log, and revert to any point in time.
|
|
40
|
+
|
|
41
|
+
### Architecture: TypeScript + Rust 🦀
|
|
42
|
+
|
|
43
|
+
SmartDB uses a **sidecar binary** pattern — TypeScript handles lifecycle, Rust handles all database operations:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
47
|
+
│ Your Application │
|
|
48
|
+
│ (TypeScript / Node.js) │
|
|
49
|
+
│ ┌─────────────────┐ ┌───────────────────────────┐ │
|
|
50
|
+
│ │ SmartdbServer │────▶│ RustDbBridge (IPC) │ │
|
|
51
|
+
│ │ or LocalSmartDb │ │ @push.rocks/smartrust │ │
|
|
52
|
+
│ └─────────────────┘ └───────────┬───────────────┘ │
|
|
53
|
+
└──────────────────────────────────────┼───────────────────────┘
|
|
54
|
+
│ spawn + JSON IPC
|
|
55
|
+
▼
|
|
56
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
57
|
+
│ rustdb binary 🦀 │
|
|
58
|
+
│ │
|
|
59
|
+
│ ┌──────────────┐ ┌──────────────┐ ┌───────────────┐ │
|
|
60
|
+
│ │ Wire Protocol│→ │Command Router│→ │ Handlers │ │
|
|
61
|
+
│ │ (OP_MSG) │ │ (40+ cmds) │ │ Find,Insert.. │ │
|
|
62
|
+
│ └──────────────┘ └──────────────┘ └───────┬───────┘ │
|
|
63
|
+
│ │ │
|
|
64
|
+
│ ┌─────────┐ ┌────────┐ ┌───────────┐ ┌──────┴──────┐ │
|
|
65
|
+
│ │ Query │ │ Update │ │Aggregation│ │ Index │ │
|
|
66
|
+
│ │ Matcher │ │ Engine │ │ Engine │ │ Engine │ │
|
|
67
|
+
│ └─────────┘ └────────┘ └───────────┘ └─────────────┘ │
|
|
68
|
+
│ │
|
|
69
|
+
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────┐ │
|
|
70
|
+
│ │ MemoryStorage │ │ FileStorage │ │ OpLog │ │
|
|
71
|
+
│ └──────────────────┘ └──────────────────┘ └──────────┘ │
|
|
72
|
+
└──────────────────────────────────────────────────────────────┘
|
|
73
|
+
▲
|
|
74
|
+
│ TCP / Unix Socket (wire protocol)
|
|
75
|
+
│
|
|
76
|
+
┌─────────────┴────────────────────────────────────────────────┐
|
|
77
|
+
│ MongoClient (mongodb npm driver) │
|
|
78
|
+
│ Connects directly to Rust binary │
|
|
79
|
+
└──────────────────────────────────────────────────────────────┘
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The TypeScript layer handles **lifecycle only** (start/stop/configure via IPC). All database operations flow directly from the `MongoClient` to the Rust binary over TCP or Unix sockets — **zero per-query IPC overhead**.
|
|
83
|
+
|
|
84
|
+
---
|
|
35
85
|
|
|
36
86
|
## Quick Start
|
|
37
87
|
|
|
@@ -47,11 +97,11 @@ import { MongoClient } from 'mongodb';
|
|
|
47
97
|
const db = new LocalSmartDb({ folderPath: './my-data' });
|
|
48
98
|
const { connectionUri } = await db.start();
|
|
49
99
|
|
|
50
|
-
// Connect with the standard
|
|
100
|
+
// Connect with the standard driver
|
|
51
101
|
const client = new MongoClient(connectionUri, { directConnection: true });
|
|
52
102
|
await client.connect();
|
|
53
103
|
|
|
54
|
-
// Use
|
|
104
|
+
// Use it like any wire-protocol-compatible database
|
|
55
105
|
const users = client.db('myapp').collection('users');
|
|
56
106
|
await users.insertOne({ name: 'Alice', email: 'alice@example.com' });
|
|
57
107
|
const user = await users.findOne({ name: 'Alice' });
|
|
@@ -83,13 +133,94 @@ await client.close();
|
|
|
83
133
|
await server.stop();
|
|
84
134
|
```
|
|
85
135
|
|
|
136
|
+
### Option 3: Debug Server (Visual Dashboard) 🖥️
|
|
137
|
+
|
|
138
|
+
Launch a web-based dashboard to inspect your database in real time:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { SmartdbServer } from '@push.rocks/smartdb';
|
|
142
|
+
import { SmartdbDebugServer } from '@push.rocks/smartdb/debugserver';
|
|
143
|
+
|
|
144
|
+
const server = new SmartdbServer({ storage: 'memory' });
|
|
145
|
+
await server.start();
|
|
146
|
+
|
|
147
|
+
const debugServer = new SmartdbDebugServer(server, { port: 4000 });
|
|
148
|
+
await debugServer.start();
|
|
149
|
+
// Open http://localhost:4000 in your browser 🚀
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The debug dashboard gives you:
|
|
153
|
+
- 📊 **Dashboard** — server status, uptime, database/collection counts, operation breakdown
|
|
154
|
+
- 📁 **Collection Browser** — browse databases, collections, and documents interactively
|
|
155
|
+
- 📝 **OpLog Timeline** — every insert, update, and delete with expandable field-level diffs
|
|
156
|
+
- ⏪ **Point-in-Time Revert** — select any oplog sequence, preview what will be undone, and execute
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 📝 Operation Log & Point-in-Time Revert
|
|
161
|
+
|
|
162
|
+
Every write operation (insert, update, delete) is automatically recorded in an in-memory **operation log (OpLog)** with full before/after document snapshots. This enables:
|
|
163
|
+
|
|
164
|
+
- **Change tracking** — see exactly what changed, when, and in which collection
|
|
165
|
+
- **Field-level diffs** — compare previous and new document states
|
|
166
|
+
- **Point-in-time revert** — undo operations back to any sequence number
|
|
167
|
+
- **Dry-run preview** — see what would be reverted before executing
|
|
168
|
+
|
|
169
|
+
### Programmatic OpLog API
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { SmartdbServer } from '@push.rocks/smartdb';
|
|
173
|
+
|
|
174
|
+
const server = new SmartdbServer({ port: 27017 });
|
|
175
|
+
await server.start();
|
|
176
|
+
|
|
177
|
+
// ... perform some CRUD operations via MongoClient ...
|
|
178
|
+
|
|
179
|
+
// Get oplog entries
|
|
180
|
+
const oplog = await server.getOpLog({ limit: 50 });
|
|
181
|
+
console.log(oplog.entries);
|
|
182
|
+
// [{ seq: 1, op: 'insert', db: 'myapp', collection: 'users', document: {...}, previousDocument: null }, ...]
|
|
183
|
+
|
|
184
|
+
// Get aggregate stats
|
|
185
|
+
const stats = await server.getOpLogStats();
|
|
186
|
+
console.log(stats);
|
|
187
|
+
// { currentSeq: 42, totalEntries: 42, entriesByOp: { insert: 20, update: 15, delete: 7 } }
|
|
188
|
+
|
|
189
|
+
// Preview a revert (dry run)
|
|
190
|
+
const preview = await server.revertToSeq(30, true);
|
|
191
|
+
console.log(`Would undo ${preview.reverted} operations`);
|
|
192
|
+
|
|
193
|
+
// Execute the revert — undoes all operations after seq 30
|
|
194
|
+
const result = await server.revertToSeq(30, false);
|
|
195
|
+
console.log(`Reverted ${result.reverted} operations`);
|
|
196
|
+
|
|
197
|
+
// Browse collections programmatically
|
|
198
|
+
const collections = await server.getCollections();
|
|
199
|
+
const docs = await server.getDocuments('myapp', 'users', 50, 0);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### OpLog Entry Structure
|
|
203
|
+
|
|
204
|
+
Each entry contains:
|
|
205
|
+
|
|
206
|
+
| Field | Type | Description |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| `seq` | `number` | Monotonically increasing sequence number |
|
|
209
|
+
| `timestampMs` | `number` | Unix timestamp in milliseconds |
|
|
210
|
+
| `op` | `'insert' \| 'update' \| 'delete'` | Operation type |
|
|
211
|
+
| `db` | `string` | Database name |
|
|
212
|
+
| `collection` | `string` | Collection name |
|
|
213
|
+
| `documentId` | `string` | Document `_id` as hex string |
|
|
214
|
+
| `document` | `object \| null` | New document state (null for deletes) |
|
|
215
|
+
| `previousDocument` | `object \| null` | Previous document state (null for inserts) |
|
|
216
|
+
|
|
86
217
|
---
|
|
87
218
|
|
|
88
219
|
## API Reference
|
|
89
220
|
|
|
90
221
|
### SmartdbServer
|
|
91
222
|
|
|
92
|
-
The core server class.
|
|
223
|
+
The core server class. Manages the Rust database engine and exposes connection details.
|
|
93
224
|
|
|
94
225
|
#### Constructor Options (`ISmartdbServerOptions`)
|
|
95
226
|
|
|
@@ -123,15 +254,19 @@ const server = new SmartdbServer({
|
|
|
123
254
|
|
|
124
255
|
| Method / Property | Type | Description |
|
|
125
256
|
|---|---|---|
|
|
126
|
-
| `start()` | `Promise<void>` | Start the server |
|
|
257
|
+
| `start()` | `Promise<void>` | Start the server (spawns Rust binary) |
|
|
127
258
|
| `stop()` | `Promise<void>` | Stop the server and clean up |
|
|
128
|
-
| `getConnectionUri()` | `string` | Get the
|
|
259
|
+
| `getConnectionUri()` | `string` | Get the `mongodb://` connection URI |
|
|
129
260
|
| `running` | `boolean` | Whether the server is currently running |
|
|
130
|
-
| `port` | `number` |
|
|
131
|
-
| `host` | `string` |
|
|
132
|
-
| `socketPath` | `string` | Socket path (socket mode) |
|
|
133
|
-
| `
|
|
134
|
-
| `
|
|
261
|
+
| `port` | `number` | Configured port (TCP mode) |
|
|
262
|
+
| `host` | `string` | Configured host (TCP mode) |
|
|
263
|
+
| `socketPath` | `string \| undefined` | Socket path (socket mode) |
|
|
264
|
+
| `getMetrics()` | `Promise<ISmartDbMetrics>` | Server metrics (db/collection counts, uptime) |
|
|
265
|
+
| `getOpLog(params?)` | `Promise<IOpLogResult>` | Query oplog entries with optional filters |
|
|
266
|
+
| `getOpLogStats()` | `Promise<IOpLogStats>` | Aggregate oplog statistics |
|
|
267
|
+
| `revertToSeq(seq, dryRun?)` | `Promise<IRevertResult>` | Revert to a specific oplog sequence |
|
|
268
|
+
| `getCollections(db?)` | `Promise<ICollectionInfo[]>` | List all collections with counts |
|
|
269
|
+
| `getDocuments(db, coll, limit?, skip?)` | `Promise<IDocumentsResult>` | Browse documents with pagination |
|
|
135
270
|
|
|
136
271
|
### LocalSmartDb
|
|
137
272
|
|
|
@@ -155,24 +290,45 @@ const db = new LocalSmartDb({
|
|
|
155
290
|
| `start()` | `Promise<ILocalSmartDbConnectionInfo>` | Start and return connection info |
|
|
156
291
|
| `stop()` | `Promise<void>` | Stop the server |
|
|
157
292
|
| `getConnectionInfo()` | `ILocalSmartDbConnectionInfo` | Get current connection info |
|
|
158
|
-
| `getConnectionUri()` | `string` | Get the
|
|
293
|
+
| `getConnectionUri()` | `string` | Get the connection URI |
|
|
159
294
|
| `getServer()` | `SmartdbServer` | Access the underlying server |
|
|
160
295
|
| `running` | `boolean` | Whether the server is running |
|
|
161
296
|
|
|
162
|
-
|
|
297
|
+
### SmartdbDebugServer
|
|
298
|
+
|
|
299
|
+
Web-based debug dashboard served via `@api.global/typedserver`. Import from the `debugserver` subpath:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { SmartdbDebugServer } from '@push.rocks/smartdb/debugserver';
|
|
303
|
+
|
|
304
|
+
const debugServer = new SmartdbDebugServer(server, { port: 4000 });
|
|
305
|
+
await debugServer.start();
|
|
306
|
+
// Dashboard at http://localhost:4000
|
|
307
|
+
|
|
308
|
+
await debugServer.stop();
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
The UI is bundled as base64-encoded content (via `@git.zone/tsbundle`) and served from memory — no static file directory needed.
|
|
312
|
+
|
|
313
|
+
### SmartdbDebugUi (Web Component)
|
|
314
|
+
|
|
315
|
+
For embedding the debug UI directly into your own web application, import the `<smartdb-debugui>` web component:
|
|
163
316
|
|
|
164
317
|
```typescript
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
318
|
+
import { SmartdbDebugUi } from '@push.rocks/smartdb/debugui';
|
|
319
|
+
|
|
320
|
+
// In your HTML/lit template:
|
|
321
|
+
// <smartdb-debugui .server=${mySmartdbServer}></smartdb-debugui>
|
|
322
|
+
//
|
|
323
|
+
// Or in HTTP mode (when served by SmartdbDebugServer):
|
|
324
|
+
// <smartdb-debugui apiBaseUrl=""></smartdb-debugui>
|
|
169
325
|
```
|
|
170
326
|
|
|
171
327
|
---
|
|
172
328
|
|
|
173
|
-
## Supported
|
|
329
|
+
## Supported Operations
|
|
174
330
|
|
|
175
|
-
SmartDB supports the core
|
|
331
|
+
SmartDB supports the core operations through the wire protocol. Use the standard `mongodb` driver — these all work:
|
|
176
332
|
|
|
177
333
|
### CRUD
|
|
178
334
|
|
|
@@ -258,7 +414,7 @@ const results = await collection.aggregate([
|
|
|
258
414
|
]).toArray();
|
|
259
415
|
```
|
|
260
416
|
|
|
261
|
-
**Supported stages:** `$match`, `$project`, `$group`, `$sort`, `$limit`, `$skip`, `$unwind`, `$lookup`, `$addFields`, `$count`, `$facet`, `$replaceRoot`, `$set`, `$
|
|
417
|
+
**Supported stages:** `$match`, `$project`, `$group`, `$sort`, `$limit`, `$skip`, `$unwind`, `$lookup`, `$addFields`, `$count`, `$facet`, `$replaceRoot`, `$set`, `$unionWith`, `$out`, `$merge`
|
|
262
418
|
|
|
263
419
|
**Group accumulators:** `$sum`, `$avg`, `$min`, `$max`, `$first`, `$last`, `$push`, `$addToSet`, `$count`
|
|
264
420
|
|
|
@@ -316,148 +472,34 @@ const names = await collection.distinct('name');
|
|
|
316
472
|
| **CRUD** | `find`, `insert`, `update`, `delete`, `findAndModify`, `getMore`, `killCursors` |
|
|
317
473
|
| **Aggregation** | `aggregate`, `count`, `distinct` |
|
|
318
474
|
| **Indexes** | `createIndexes`, `dropIndexes`, `listIndexes` |
|
|
319
|
-
| **
|
|
320
|
-
| **
|
|
321
|
-
| **Admin** | `ping`, `listDatabases`, `listCollections`, `drop`, `dropDatabase`, `create`, `serverStatus`, `buildInfo`, `dbStats`, `collStats`, `connectionStatus`, `currentOp`, `
|
|
475
|
+
| **Sessions** | `startSession`, `endSessions` |
|
|
476
|
+
| **Transactions** | `commitTransaction`, `abortTransaction` |
|
|
477
|
+
| **Admin** | `ping`, `listDatabases`, `listCollections`, `drop`, `dropDatabase`, `create`, `serverStatus`, `buildInfo`, `dbStats`, `collStats`, `connectionStatus`, `currentOp`, `renameCollection` |
|
|
322
478
|
|
|
323
|
-
Compatible with
|
|
479
|
+
Compatible with wire protocol versions 0–21 (driver versions 3.6 through 7.0).
|
|
324
480
|
|
|
325
481
|
---
|
|
326
482
|
|
|
327
|
-
## Architecture
|
|
328
|
-
|
|
329
|
-
```
|
|
330
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
331
|
-
│ Official MongoDB Driver │
|
|
332
|
-
│ (mongodb npm) │
|
|
333
|
-
└─────────────────────────┬───────────────────────────────────┘
|
|
334
|
-
│ TCP / Unix Socket + OP_MSG / BSON
|
|
335
|
-
▼
|
|
336
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
337
|
-
│ SmartdbServer │
|
|
338
|
-
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
|
|
339
|
-
│ │ WireProtocol │→ │CommandRouter │→ │ Handlers │ │
|
|
340
|
-
│ │ (OP_MSG) │ │ │ │ (Find, Insert..) │ │
|
|
341
|
-
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
|
|
342
|
-
└─────────────────────────┬───────────────────────────────────┘
|
|
343
|
-
│
|
|
344
|
-
▼
|
|
345
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
346
|
-
│ Engines │
|
|
347
|
-
│ ┌─────────┐ ┌────────┐ ┌───────────┐ ┌───────┐ ┌───────┐ │
|
|
348
|
-
│ │ Query │ │ Update │ │Aggregation│ │ Index │ │Session│ │
|
|
349
|
-
│ │ Planner │ │ Engine │ │ Engine │ │Engine │ │Engine │ │
|
|
350
|
-
│ └─────────┘ └────────┘ └───────────┘ └───────┘ └───────┘ │
|
|
351
|
-
│ ┌──────────────────────┐ │
|
|
352
|
-
│ │ Transaction Engine │ │
|
|
353
|
-
│ └──────────────────────┘ │
|
|
354
|
-
└─────────────────────────┬───────────────────────────────────┘
|
|
355
|
-
│
|
|
356
|
-
▼
|
|
357
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
358
|
-
│ Storage Layer │
|
|
359
|
-
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────┐ │
|
|
360
|
-
│ │ MemoryStorage │ │ FileStorage │ │ WAL │ │
|
|
361
|
-
│ │ │ │ (+ Checksums) │ │ │ │
|
|
362
|
-
│ └──────────────────┘ └──────────────────┘ └──────────┘ │
|
|
363
|
-
└─────────────────────────────────────────────────────────────┘
|
|
364
|
-
```
|
|
483
|
+
## Rust Crate Architecture 🦀
|
|
365
484
|
|
|
366
|
-
|
|
485
|
+
The Rust engine is organized as a Cargo workspace with 8 focused crates:
|
|
367
486
|
|
|
368
|
-
|
|
|
487
|
+
| Crate | Purpose |
|
|
369
488
|
|---|---|
|
|
370
|
-
|
|
|
371
|
-
|
|
|
372
|
-
|
|
|
373
|
-
|
|
|
374
|
-
|
|
|
375
|
-
|
|
|
376
|
-
|
|
|
377
|
-
|
|
|
378
|
-
| **SessionEngine** | Client session tracking with automatic timeouts |
|
|
379
|
-
| **WAL** | Write-ahead logging with CRC32 checksums for crash recovery |
|
|
489
|
+
| `rustdb` | Binary entry point: TCP/Unix listener, management IPC, CLI |
|
|
490
|
+
| `rustdb-config` | Server configuration types (serde, camelCase JSON) |
|
|
491
|
+
| `rustdb-wire` | Wire protocol parser/encoder (OP_MSG, OP_QUERY, OP_REPLY) |
|
|
492
|
+
| `rustdb-query` | Query matcher, update engine, aggregation, sort, projection |
|
|
493
|
+
| `rustdb-storage` | Storage backends (memory, file), OpLog with point-in-time replay |
|
|
494
|
+
| `rustdb-index` | B-tree/hash indexes, query planner (IXSCAN/COLLSCAN) |
|
|
495
|
+
| `rustdb-txn` | Transaction + session management with snapshot isolation |
|
|
496
|
+
| `rustdb-commands` | 40+ command handlers wiring everything together |
|
|
380
497
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
## Advanced Usage
|
|
384
|
-
|
|
385
|
-
### Storage Adapters
|
|
386
|
-
|
|
387
|
-
```typescript
|
|
388
|
-
import { SmartdbServer } from '@push.rocks/smartdb';
|
|
389
|
-
|
|
390
|
-
// In-memory (default) — fast, data lost on stop
|
|
391
|
-
const server = new SmartdbServer({ storage: 'memory' });
|
|
392
|
-
|
|
393
|
-
// In-memory with periodic persistence
|
|
394
|
-
const server = new SmartdbServer({
|
|
395
|
-
storage: 'memory',
|
|
396
|
-
persistPath: './data/snapshot.json',
|
|
397
|
-
persistIntervalMs: 30000,
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// File-based — persistent storage with CRC32 checksums
|
|
401
|
-
const server = new SmartdbServer({
|
|
402
|
-
storage: 'file',
|
|
403
|
-
storagePath: './data/smartdb',
|
|
404
|
-
});
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
### Query Planner (Debugging)
|
|
408
|
-
|
|
409
|
-
```typescript
|
|
410
|
-
import { QueryPlanner, IndexEngine, MemoryStorageAdapter } from '@push.rocks/smartdb';
|
|
411
|
-
|
|
412
|
-
const storage = new MemoryStorageAdapter();
|
|
413
|
-
await storage.initialize();
|
|
414
|
-
const indexEngine = new IndexEngine('mydb', 'mycoll', storage);
|
|
415
|
-
const planner = new QueryPlanner(indexEngine);
|
|
416
|
-
|
|
417
|
-
const plan = await planner.plan({ age: { $gte: 18 } });
|
|
418
|
-
console.log(plan);
|
|
419
|
-
// { type: 'IXSCAN_RANGE', indexName: 'age_1', selectivity: 0.3, usesRange: true, ... }
|
|
420
|
-
|
|
421
|
-
const explain = await planner.explain({ age: 18 });
|
|
422
|
-
// Returns winning plan, rejected plans, and detailed analysis
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### Data Integrity Checksums
|
|
426
|
-
|
|
427
|
-
```typescript
|
|
428
|
-
import { calculateDocumentChecksum, addChecksum, verifyChecksum, removeChecksum } from '@push.rocks/smartdb';
|
|
429
|
-
|
|
430
|
-
const doc = { name: 'Alice', age: 30 };
|
|
431
|
-
|
|
432
|
-
const protected = addChecksum(doc); // Adds _checksum field
|
|
433
|
-
const valid = verifyChecksum(protected); // true
|
|
434
|
-
protected.age = 31; // Tamper!
|
|
435
|
-
const still = verifyChecksum(protected); // false
|
|
436
|
-
const clean = removeChecksum(protected); // Removes _checksum
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
### Write-Ahead Logging
|
|
440
|
-
|
|
441
|
-
```typescript
|
|
442
|
-
import { WAL } from '@push.rocks/smartdb';
|
|
443
|
-
|
|
444
|
-
const wal = new WAL('./data/wal.log', { checkpointInterval: 100 });
|
|
445
|
-
await wal.initialize();
|
|
446
|
-
|
|
447
|
-
// Entries include: LSN, timestamp, operation, BSON data, CRC32 checksum
|
|
448
|
-
const lsn = await wal.logInsert('mydb', 'users', doc);
|
|
449
|
-
const entries = wal.getEntriesAfter(lastCheckpoint);
|
|
450
|
-
const recovered = wal.recoverDocument(entry);
|
|
451
|
-
|
|
452
|
-
await wal.checkpoint();
|
|
453
|
-
await wal.close();
|
|
454
|
-
```
|
|
498
|
+
Cross-compiled for `linux_amd64` and `linux_arm64` via [@git.zone/tsrust](https://www.npmjs.com/package/@git.zone/tsrust).
|
|
455
499
|
|
|
456
500
|
---
|
|
457
501
|
|
|
458
|
-
## Testing
|
|
459
|
-
|
|
460
|
-
### Unit Tests with @git.zone/tstest
|
|
502
|
+
## Testing Example
|
|
461
503
|
|
|
462
504
|
```typescript
|
|
463
505
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
|
@@ -481,6 +523,12 @@ tap.test('should insert and find', async () => {
|
|
|
481
523
|
expect(item?.price).toEqual(9.99);
|
|
482
524
|
});
|
|
483
525
|
|
|
526
|
+
tap.test('should track changes in oplog', async () => {
|
|
527
|
+
const oplog = await server.getOpLog();
|
|
528
|
+
expect(oplog.entries.length).toBeGreaterThan(0);
|
|
529
|
+
expect(oplog.entries[0].op).toEqual('insert');
|
|
530
|
+
});
|
|
531
|
+
|
|
484
532
|
tap.test('teardown', async () => {
|
|
485
533
|
await client.close();
|
|
486
534
|
await server.stop();
|
|
@@ -489,23 +537,7 @@ tap.test('teardown', async () => {
|
|
|
489
537
|
export default tap.start();
|
|
490
538
|
```
|
|
491
539
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
```typescript
|
|
495
|
-
import { LocalSmartDb } from '@push.rocks/smartdb';
|
|
496
|
-
import { MongoClient } from 'mongodb';
|
|
497
|
-
|
|
498
|
-
const db = new LocalSmartDb({ folderPath: './test-data' });
|
|
499
|
-
const { connectionUri } = await db.start();
|
|
500
|
-
|
|
501
|
-
const client = new MongoClient(connectionUri, { directConnection: true });
|
|
502
|
-
await client.connect();
|
|
503
|
-
|
|
504
|
-
// Tests here — data persists between test runs!
|
|
505
|
-
|
|
506
|
-
await client.close();
|
|
507
|
-
await db.stop();
|
|
508
|
-
```
|
|
540
|
+
---
|
|
509
541
|
|
|
510
542
|
## License and Legal Information
|
|
511
543
|
|
|
@@ -521,7 +553,7 @@ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark G
|
|
|
521
553
|
|
|
522
554
|
### Company Information
|
|
523
555
|
|
|
524
|
-
Task Venture Capital GmbH
|
|
556
|
+
Task Venture Capital GmbH
|
|
525
557
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
526
558
|
|
|
527
559
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartdb',
|
|
6
|
-
version: '1.
|
|
7
|
-
description: 'A
|
|
6
|
+
version: '2.1.1',
|
|
7
|
+
description: 'A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.'
|
|
8
8
|
}
|
package/ts/index.ts
CHANGED
|
@@ -9,3 +9,14 @@ export type { ILocalSmartDbOptions, ILocalSmartDbConnectionInfo } from './ts_loc
|
|
|
9
9
|
|
|
10
10
|
// Export commitinfo
|
|
11
11
|
export { commitinfo };
|
|
12
|
+
|
|
13
|
+
// Re-export oplog / debug types for convenience
|
|
14
|
+
export type {
|
|
15
|
+
IOpLogEntry,
|
|
16
|
+
IOpLogResult,
|
|
17
|
+
IOpLogStats,
|
|
18
|
+
IRevertResult,
|
|
19
|
+
ICollectionInfo,
|
|
20
|
+
IDocumentsResult,
|
|
21
|
+
ISmartDbMetrics,
|
|
22
|
+
} from './ts_smartdb/index.js';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as plugins from './plugins.js';
|
|
2
1
|
import * as crypto from 'crypto';
|
|
3
2
|
import * as path from 'path';
|
|
4
3
|
import * as os from 'os';
|
|
@@ -10,7 +9,7 @@ import { SmartdbServer } from '../ts_smartdb/index.js';
|
|
|
10
9
|
export interface ILocalSmartDbConnectionInfo {
|
|
11
10
|
/** The Unix socket file path */
|
|
12
11
|
socketPath: string;
|
|
13
|
-
/**
|
|
12
|
+
/** Connection URI (mongodb:// scheme) ready for MongoClient */
|
|
14
13
|
connectionUri: string;
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -25,8 +24,8 @@ export interface ILocalSmartDbOptions {
|
|
|
25
24
|
* LocalSmartDb - Lightweight local MongoDB-compatible database using Unix sockets
|
|
26
25
|
*
|
|
27
26
|
* This class wraps SmartdbServer and provides a simple interface for
|
|
28
|
-
* starting a local file-based
|
|
29
|
-
* info that you can use with
|
|
27
|
+
* starting a local file-based database server. Returns connection
|
|
28
|
+
* info that you can use with any compatible driver instance.
|
|
30
29
|
*
|
|
31
30
|
* @example
|
|
32
31
|
* ```typescript
|
|
@@ -36,11 +35,11 @@ export interface ILocalSmartDbOptions {
|
|
|
36
35
|
* const db = new LocalSmartDb({ folderPath: './data' });
|
|
37
36
|
* const { connectionUri } = await db.start();
|
|
38
37
|
*
|
|
39
|
-
* // Connect with
|
|
38
|
+
* // Connect with the driver
|
|
40
39
|
* const client = new MongoClient(connectionUri, { directConnection: true });
|
|
41
40
|
* await client.connect();
|
|
42
41
|
*
|
|
43
|
-
* // Use the
|
|
42
|
+
* // Use the client
|
|
44
43
|
* const collection = client.db('mydb').collection('users');
|
|
45
44
|
* await collection.insertOne({ name: 'Alice' });
|
|
46
45
|
*
|
package/ts/ts_local/plugins.ts
CHANGED