@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.
Files changed (126) hide show
  1. package/.smartconfig.json +18 -4
  2. package/dist_rust/rustdb_linux_amd64 +0 -0
  3. package/dist_rust/rustdb_linux_arm64 +0 -0
  4. package/dist_ts/00_commitinfo_data.js +3 -3
  5. package/dist_ts/index.d.ts +1 -0
  6. package/dist_ts/ts_local/classes.localsmartdb.d.ts +5 -5
  7. package/dist_ts/ts_local/classes.localsmartdb.js +7 -9
  8. package/dist_ts/ts_local/plugins.d.ts +1 -2
  9. package/dist_ts/ts_local/plugins.js +3 -3
  10. package/dist_ts/ts_smartdb/index.d.ts +2 -24
  11. package/dist_ts/ts_smartdb/index.js +4 -29
  12. package/dist_ts/ts_smartdb/plugins.d.ts +2 -10
  13. package/dist_ts/ts_smartdb/plugins.js +3 -13
  14. package/dist_ts/ts_smartdb/rust-db-bridge.d.ts +122 -0
  15. package/dist_ts/ts_smartdb/rust-db-bridge.js +113 -0
  16. package/dist_ts/ts_smartdb/server/SmartdbServer.d.ts +39 -37
  17. package/dist_ts/ts_smartdb/server/SmartdbServer.js +87 -206
  18. package/dist_ts/ts_smartdb/server/index.d.ts +0 -4
  19. package/dist_ts/ts_smartdb/server/index.js +1 -5
  20. package/dist_ts_debugserver/bundled.d.ts +4 -0
  21. package/dist_ts_debugserver/bundled.js +12 -0
  22. package/dist_ts_debugserver/classes.debugserver.d.ts +36 -0
  23. package/dist_ts_debugserver/classes.debugserver.js +95 -0
  24. package/dist_ts_debugserver/index.d.ts +2 -0
  25. package/dist_ts_debugserver/index.js +2 -0
  26. package/dist_ts_debugserver/plugins.d.ts +2 -0
  27. package/dist_ts_debugserver/plugins.js +3 -0
  28. package/dist_ts_debugui/index.d.ts +2 -0
  29. package/dist_ts_debugui/index.js +2 -0
  30. package/dist_ts_debugui/plugins.d.ts +1 -0
  31. package/dist_ts_debugui/plugins.js +2 -0
  32. package/dist_ts_debugui/smartdb-debugui.d.ts +62 -0
  33. package/dist_ts_debugui/smartdb-debugui.js +1132 -0
  34. package/license +3 -1
  35. package/package.json +14 -13
  36. package/readme.md +209 -177
  37. package/ts/00_commitinfo_data.ts +2 -2
  38. package/ts/index.ts +11 -0
  39. package/ts/ts_local/classes.localsmartdb.ts +5 -6
  40. package/ts/ts_local/plugins.ts +1 -3
  41. package/ts/ts_smartdb/index.ts +14 -41
  42. package/ts/ts_smartdb/plugins.ts +2 -15
  43. package/ts/ts_smartdb/rust-db-bridge.ts +262 -0
  44. package/ts/ts_smartdb/server/SmartdbServer.ts +115 -246
  45. package/ts/ts_smartdb/server/index.ts +0 -7
  46. package/dist_ts/ts_smartdb/engine/AggregationEngine.d.ts +0 -66
  47. package/dist_ts/ts_smartdb/engine/AggregationEngine.js +0 -189
  48. package/dist_ts/ts_smartdb/engine/IndexEngine.d.ts +0 -97
  49. package/dist_ts/ts_smartdb/engine/IndexEngine.js +0 -678
  50. package/dist_ts/ts_smartdb/engine/QueryEngine.d.ts +0 -54
  51. package/dist_ts/ts_smartdb/engine/QueryEngine.js +0 -271
  52. package/dist_ts/ts_smartdb/engine/QueryPlanner.d.ts +0 -64
  53. package/dist_ts/ts_smartdb/engine/QueryPlanner.js +0 -308
  54. package/dist_ts/ts_smartdb/engine/SessionEngine.d.ts +0 -117
  55. package/dist_ts/ts_smartdb/engine/SessionEngine.js +0 -232
  56. package/dist_ts/ts_smartdb/engine/TransactionEngine.d.ts +0 -85
  57. package/dist_ts/ts_smartdb/engine/TransactionEngine.js +0 -287
  58. package/dist_ts/ts_smartdb/engine/UpdateEngine.d.ts +0 -47
  59. package/dist_ts/ts_smartdb/engine/UpdateEngine.js +0 -461
  60. package/dist_ts/ts_smartdb/errors/SmartdbErrors.d.ts +0 -100
  61. package/dist_ts/ts_smartdb/errors/SmartdbErrors.js +0 -155
  62. package/dist_ts/ts_smartdb/server/CommandRouter.d.ts +0 -87
  63. package/dist_ts/ts_smartdb/server/CommandRouter.js +0 -222
  64. package/dist_ts/ts_smartdb/server/WireProtocol.d.ts +0 -117
  65. package/dist_ts/ts_smartdb/server/WireProtocol.js +0 -298
  66. package/dist_ts/ts_smartdb/server/handlers/AdminHandler.d.ts +0 -100
  67. package/dist_ts/ts_smartdb/server/handlers/AdminHandler.js +0 -668
  68. package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.d.ts +0 -31
  69. package/dist_ts/ts_smartdb/server/handlers/AggregateHandler.js +0 -277
  70. package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.d.ts +0 -8
  71. package/dist_ts/ts_smartdb/server/handlers/DeleteHandler.js +0 -95
  72. package/dist_ts/ts_smartdb/server/handlers/FindHandler.d.ts +0 -31
  73. package/dist_ts/ts_smartdb/server/handlers/FindHandler.js +0 -291
  74. package/dist_ts/ts_smartdb/server/handlers/HelloHandler.d.ts +0 -11
  75. package/dist_ts/ts_smartdb/server/handlers/HelloHandler.js +0 -62
  76. package/dist_ts/ts_smartdb/server/handlers/IndexHandler.d.ts +0 -20
  77. package/dist_ts/ts_smartdb/server/handlers/IndexHandler.js +0 -183
  78. package/dist_ts/ts_smartdb/server/handlers/InsertHandler.d.ts +0 -8
  79. package/dist_ts/ts_smartdb/server/handlers/InsertHandler.js +0 -79
  80. package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.d.ts +0 -24
  81. package/dist_ts/ts_smartdb/server/handlers/UpdateHandler.js +0 -296
  82. package/dist_ts/ts_smartdb/server/handlers/index.d.ts +0 -8
  83. package/dist_ts/ts_smartdb/server/handlers/index.js +0 -10
  84. package/dist_ts/ts_smartdb/storage/FileStorageAdapter.d.ts +0 -85
  85. package/dist_ts/ts_smartdb/storage/FileStorageAdapter.js +0 -465
  86. package/dist_ts/ts_smartdb/storage/IStorageAdapter.d.ts +0 -145
  87. package/dist_ts/ts_smartdb/storage/IStorageAdapter.js +0 -2
  88. package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.d.ts +0 -67
  89. package/dist_ts/ts_smartdb/storage/MemoryStorageAdapter.js +0 -378
  90. package/dist_ts/ts_smartdb/storage/OpLog.d.ts +0 -93
  91. package/dist_ts/ts_smartdb/storage/OpLog.js +0 -221
  92. package/dist_ts/ts_smartdb/storage/WAL.d.ts +0 -117
  93. package/dist_ts/ts_smartdb/storage/WAL.js +0 -286
  94. package/dist_ts/ts_smartdb/types/interfaces.d.ts +0 -363
  95. package/dist_ts/ts_smartdb/types/interfaces.js +0 -2
  96. package/dist_ts/ts_smartdb/utils/checksum.d.ts +0 -30
  97. package/dist_ts/ts_smartdb/utils/checksum.js +0 -77
  98. package/dist_ts/ts_smartdb/utils/index.d.ts +0 -1
  99. package/dist_ts/ts_smartdb/utils/index.js +0 -2
  100. package/ts/ts_smartdb/engine/AggregationEngine.ts +0 -283
  101. package/ts/ts_smartdb/engine/IndexEngine.ts +0 -798
  102. package/ts/ts_smartdb/engine/QueryEngine.ts +0 -301
  103. package/ts/ts_smartdb/engine/QueryPlanner.ts +0 -393
  104. package/ts/ts_smartdb/engine/SessionEngine.ts +0 -292
  105. package/ts/ts_smartdb/engine/TransactionEngine.ts +0 -351
  106. package/ts/ts_smartdb/engine/UpdateEngine.ts +0 -506
  107. package/ts/ts_smartdb/errors/SmartdbErrors.ts +0 -181
  108. package/ts/ts_smartdb/server/CommandRouter.ts +0 -289
  109. package/ts/ts_smartdb/server/WireProtocol.ts +0 -416
  110. package/ts/ts_smartdb/server/handlers/AdminHandler.ts +0 -719
  111. package/ts/ts_smartdb/server/handlers/AggregateHandler.ts +0 -342
  112. package/ts/ts_smartdb/server/handlers/DeleteHandler.ts +0 -115
  113. package/ts/ts_smartdb/server/handlers/FindHandler.ts +0 -330
  114. package/ts/ts_smartdb/server/handlers/HelloHandler.ts +0 -78
  115. package/ts/ts_smartdb/server/handlers/IndexHandler.ts +0 -207
  116. package/ts/ts_smartdb/server/handlers/InsertHandler.ts +0 -97
  117. package/ts/ts_smartdb/server/handlers/UpdateHandler.ts +0 -344
  118. package/ts/ts_smartdb/server/handlers/index.ts +0 -10
  119. package/ts/ts_smartdb/storage/FileStorageAdapter.ts +0 -562
  120. package/ts/ts_smartdb/storage/IStorageAdapter.ts +0 -208
  121. package/ts/ts_smartdb/storage/MemoryStorageAdapter.ts +0 -455
  122. package/ts/ts_smartdb/storage/OpLog.ts +0 -282
  123. package/ts/ts_smartdb/storage/WAL.ts +0 -375
  124. package/ts/ts_smartdb/types/interfaces.ts +0 -433
  125. package/ts/ts_smartdb/utils/checksum.ts +0 -88
  126. package/ts/ts_smartdb/utils/index.ts +0 -1
package/license CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2021 Task Venture Capital GmbH (hello@task.vc)
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.0.1",
3
+ "version": "2.1.1",
4
4
  "private": false,
5
- "description": "A pure TypeScript MongoDB wire-protocol-compatible database server with pluggable storage, indexing, transactions, and zero external binary dependencies.",
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
- "@push.rocks/smartfs": "^1.5.0",
27
- "@push.rocks/smartpath": "^6.0.0",
28
- "@push.rocks/smartpromise": "^4.2.3",
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
- "typescript database",
52
+ "embedded database",
52
53
  "in-memory database",
53
54
  "testing",
54
55
  "local database",
55
56
  "database server",
56
- "typescript"
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 pure TypeScript MongoDB wire-protocol-compatible database server. Zero binary dependencies, instant startup, pluggable storage — use the official MongoDB driver and it just works.
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** written entirely in TypeScript that speaks the MongoDB binary wire protocol. Connect with the official `mongodb` Node.js driver — no mocks, no stubs, no MongoDB binary required.
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 | Real MongoDB |
25
+ | | SmartDB | External DB Server |
24
26
  |---|---|---|
25
- | **Startup time** | ~5ms | ~2-5s |
26
- | **Binary download** | None | ~200MB |
27
- | **Node.js only** | | |
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
- | **Perfect for** | Unit tests, CI/CD, prototyping, local dev | Production |
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
- ### Two Ways to Use It
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
- - 🎯 **`LocalSmartDb`** — Zero-config convenience. Give it a folder path, get a persistent MongoDB-compatible database over a Unix socket. Done.
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 MongoDB driver
100
+ // Connect with the standard driver
51
101
  const client = new MongoClient(connectionUri, { directConnection: true });
52
102
  await client.connect();
53
103
 
54
- // Use exactly like MongoDB
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. Speaks MongoDB wire protocol over TCP or Unix sockets.
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 MongoDB connection URI |
259
+ | `getConnectionUri()` | `string` | Get the `mongodb://` connection URI |
129
260
  | `running` | `boolean` | Whether the server is currently running |
130
- | `port` | `number` | Bound port (TCP mode) |
131
- | `host` | `string` | Bound host (TCP mode) |
132
- | `socketPath` | `string` | Socket path (socket mode) |
133
- | `getUptime()` | `number` | Seconds since start |
134
- | `getConnectionCount()` | `number` | Active client connections |
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 MongoDB URI |
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
- #### Connection Info (`ILocalSmartDbConnectionInfo`)
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
- interface ILocalSmartDbConnectionInfo {
166
- socketPath: string; // e.g., /tmp/smartdb-abc123.sock
167
- connectionUri: string; // e.g., mongodb://%2Ftmp%2Fsmartdb-abc123.sock
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 MongoDB Operations
329
+ ## Supported Operations
174
330
 
175
- SmartDB supports the core MongoDB operations through the wire protocol. Use the standard `mongodb` driver — these all work:
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`, `$unset`
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
- | **Transactions** | `startTransaction`, `commitTransaction`, `abortTransaction` |
320
- | **Sessions** | `startSession`, `endSessions`, `refreshSessions` |
321
- | **Admin** | `ping`, `listDatabases`, `listCollections`, `drop`, `dropDatabase`, `create`, `serverStatus`, `buildInfo`, `dbStats`, `collStats`, `connectionStatus`, `currentOp`, `collMod`, `renameCollection` |
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 MongoDB wire protocol versions 0–21 (MongoDB 3.6 through 7.0 drivers).
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
- ### Key Components
485
+ The Rust engine is organized as a Cargo workspace with 8 focused crates:
367
486
 
368
- | Component | What It Does |
487
+ | Crate | Purpose |
369
488
  |---|---|
370
- | **WireProtocol** | Parses/encodes MongoDB OP_MSG binary frames |
371
- | **CommandRouter** | Routes parsed commands to the right handler |
372
- | **QueryPlanner** | Picks COLLSCAN vs IXSCAN based on available indexes |
373
- | **QueryEngine** | Filter matching powered by [mingo](https://github.com/kofrasa/mingo) |
374
- | **UpdateEngine** | Processes `$set`, `$inc`, `$push`, and all update operators |
375
- | **AggregationEngine** | Runs aggregation pipelines via mingo |
376
- | **IndexEngine** | B-tree (range) and hash (equality) indexes |
377
- | **TransactionEngine** | ACID transactions with snapshot isolation |
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 Examples
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
- ### With LocalSmartDb (Persistent Tests)
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.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartdb',
6
- version: '1.0.1',
7
- description: 'A pure TypeScript MongoDB wire-protocol-compatible database server with pluggable storage, indexing, transactions, and zero external binary dependencies.'
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
- /** MongoDB connection URI ready for MongoClient */
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 MongoDB-compatible server. Returns connection
29
- * info that you can use with your own MongoDB driver instance.
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 your own MongoDB client
38
+ * // Connect with the driver
40
39
  * const client = new MongoClient(connectionUri, { directConnection: true });
41
40
  * await client.connect();
42
41
  *
43
- * // Use the MongoDB client
42
+ * // Use the client
44
43
  * const collection = client.db('mydb').collection('users');
45
44
  * await collection.insertOne({ name: 'Alice' });
46
45
  *
@@ -1,3 +1 @@
1
- import * as smartpromise from '@push.rocks/smartpromise';
2
-
3
- export { smartpromise };
1
+ // Local module plugins - currently no external dependencies needed