@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
|
@@ -1,79 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as fs from 'fs/promises';
|
|
3
|
-
import * as plugins from '../plugins.js';
|
|
4
|
-
import { WireProtocol, OP_QUERY } from './WireProtocol.js';
|
|
5
|
-
import { CommandRouter } from './CommandRouter.js';
|
|
6
|
-
import { MemoryStorageAdapter } from '../storage/MemoryStorageAdapter.js';
|
|
7
|
-
import { FileStorageAdapter } from '../storage/FileStorageAdapter.js';
|
|
1
|
+
import { RustDbBridge } from '../rust-db-bridge.js';
|
|
8
2
|
/**
|
|
9
|
-
* SmartdbServer -
|
|
3
|
+
* SmartdbServer - Wire protocol compatible database server backed by Rust
|
|
10
4
|
*
|
|
11
|
-
* This server implements the
|
|
12
|
-
*
|
|
5
|
+
* This server implements the wire protocol to allow official drivers to
|
|
6
|
+
* connect and perform operations. The core engine runs as a Rust sidecar
|
|
7
|
+
* binary managed via @push.rocks/smartrust IPC.
|
|
13
8
|
*
|
|
14
9
|
* @example
|
|
15
10
|
* ```typescript
|
|
16
|
-
* import { SmartdbServer } from '@push.rocks/
|
|
11
|
+
* import { SmartdbServer } from '@push.rocks/smartdb';
|
|
17
12
|
* import { MongoClient } from 'mongodb';
|
|
18
13
|
*
|
|
19
14
|
* const server = new SmartdbServer({ port: 27017 });
|
|
20
15
|
* await server.start();
|
|
21
16
|
*
|
|
22
|
-
* const client = new MongoClient(
|
|
17
|
+
* const client = new MongoClient(server.getConnectionUri());
|
|
23
18
|
* await client.connect();
|
|
24
19
|
* ```
|
|
25
20
|
*/
|
|
26
21
|
export class SmartdbServer {
|
|
27
|
-
options;
|
|
28
|
-
server = null;
|
|
29
|
-
storage;
|
|
30
|
-
commandRouter;
|
|
31
|
-
connections = new Map();
|
|
32
|
-
connectionIdCounter = 0;
|
|
33
|
-
isRunning = false;
|
|
34
|
-
startTime = new Date();
|
|
35
|
-
useSocket;
|
|
36
22
|
constructor(options = {}) {
|
|
37
|
-
this.
|
|
23
|
+
this.isRunning = false;
|
|
24
|
+
this.resolvedConnectionUri = '';
|
|
38
25
|
this.options = {
|
|
39
26
|
port: options.port ?? 27017,
|
|
40
27
|
host: options.host ?? '127.0.0.1',
|
|
41
|
-
socketPath: options.socketPath
|
|
28
|
+
socketPath: options.socketPath,
|
|
42
29
|
storage: options.storage ?? 'memory',
|
|
43
30
|
storagePath: options.storagePath ?? './data',
|
|
44
|
-
persistPath: options.persistPath
|
|
31
|
+
persistPath: options.persistPath,
|
|
45
32
|
persistIntervalMs: options.persistIntervalMs ?? 60000,
|
|
46
33
|
};
|
|
47
|
-
|
|
48
|
-
if (this.options.storage === 'file') {
|
|
49
|
-
this.storage = new FileStorageAdapter(this.options.storagePath);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.storage = new MemoryStorageAdapter({
|
|
53
|
-
persistPath: this.options.persistPath || undefined,
|
|
54
|
-
persistIntervalMs: this.options.persistPath ? this.options.persistIntervalMs : undefined,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// Create command router
|
|
58
|
-
this.commandRouter = new CommandRouter(this.storage, this);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get the storage adapter (for testing/debugging)
|
|
62
|
-
*/
|
|
63
|
-
getStorage() {
|
|
64
|
-
return this.storage;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get server uptime in seconds
|
|
68
|
-
*/
|
|
69
|
-
getUptime() {
|
|
70
|
-
return Math.floor((Date.now() - this.startTime.getTime()) / 1000);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get current connection count
|
|
74
|
-
*/
|
|
75
|
-
getConnectionCount() {
|
|
76
|
-
return this.connections.size;
|
|
34
|
+
this.bridge = new RustDbBridge();
|
|
77
35
|
}
|
|
78
36
|
/**
|
|
79
37
|
* Start the server
|
|
@@ -82,180 +40,65 @@ export class SmartdbServer {
|
|
|
82
40
|
if (this.isRunning) {
|
|
83
41
|
throw new Error('Server is already running');
|
|
84
42
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await fs.unlink(this.options.socketPath);
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
// Ignore ENOENT (file doesn't exist)
|
|
94
|
-
if (err.code !== 'ENOENT') {
|
|
95
|
-
throw err;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
43
|
+
const spawned = await this.bridge.spawn();
|
|
44
|
+
if (!spawned) {
|
|
45
|
+
throw new Error('smartdb Rust binary not found. Set SMARTDB_RUST_BINARY env var, ' +
|
|
46
|
+
'install the platform package, or build locally with `tsrust`.');
|
|
98
47
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.server.on('error', (err) => {
|
|
104
|
-
if (!this.isRunning) {
|
|
105
|
-
reject(err);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
console.error('Server error:', err);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
if (this.useSocket && this.options.socketPath) {
|
|
112
|
-
// Listen on Unix socket
|
|
113
|
-
this.server.listen(this.options.socketPath, () => {
|
|
114
|
-
this.isRunning = true;
|
|
115
|
-
this.startTime = new Date();
|
|
116
|
-
resolve();
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// Listen on TCP
|
|
121
|
-
this.server.listen(this.options.port, this.options.host, () => {
|
|
122
|
-
this.isRunning = true;
|
|
123
|
-
this.startTime = new Date();
|
|
124
|
-
resolve();
|
|
125
|
-
});
|
|
48
|
+
// Forward unexpected exit
|
|
49
|
+
this.bridge.on('exit', (code, signal) => {
|
|
50
|
+
if (this.isRunning) {
|
|
51
|
+
console.error(`smartdb Rust process exited unexpectedly (code=${code}, signal=${signal})`);
|
|
126
52
|
}
|
|
127
53
|
});
|
|
54
|
+
// Send config, get back connectionUri
|
|
55
|
+
const result = await this.bridge.startDb({
|
|
56
|
+
port: this.options.port,
|
|
57
|
+
host: this.options.host,
|
|
58
|
+
socketPath: this.options.socketPath,
|
|
59
|
+
storage: this.options.storage ?? 'memory',
|
|
60
|
+
storagePath: this.options.storagePath,
|
|
61
|
+
persistPath: this.options.persistPath,
|
|
62
|
+
persistIntervalMs: this.options.persistIntervalMs,
|
|
63
|
+
});
|
|
64
|
+
this.resolvedConnectionUri = result.connectionUri;
|
|
65
|
+
this.isRunning = true;
|
|
128
66
|
}
|
|
129
67
|
/**
|
|
130
68
|
* Stop the server
|
|
131
69
|
*/
|
|
132
70
|
async stop() {
|
|
133
|
-
if (!this.isRunning
|
|
71
|
+
if (!this.isRunning) {
|
|
134
72
|
return;
|
|
135
73
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
conn.socket.destroy();
|
|
74
|
+
try {
|
|
75
|
+
await this.bridge.stopDb();
|
|
139
76
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this.commandRouter.close();
|
|
143
|
-
// Close storage
|
|
144
|
-
await this.storage.close();
|
|
145
|
-
return new Promise((resolve) => {
|
|
146
|
-
this.server.close(async () => {
|
|
147
|
-
this.isRunning = false;
|
|
148
|
-
this.server = null;
|
|
149
|
-
// Clean up socket file if using Unix socket
|
|
150
|
-
if (this.useSocket && this.options.socketPath) {
|
|
151
|
-
try {
|
|
152
|
-
await fs.unlink(this.options.socketPath);
|
|
153
|
-
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
// Ignore ENOENT (file doesn't exist)
|
|
156
|
-
if (err.code !== 'ENOENT') {
|
|
157
|
-
console.error('Failed to remove socket file:', err);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
resolve();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Handle a new client connection
|
|
167
|
-
*/
|
|
168
|
-
handleConnection(socket) {
|
|
169
|
-
const connectionId = ++this.connectionIdCounter;
|
|
170
|
-
const state = {
|
|
171
|
-
id: connectionId,
|
|
172
|
-
socket,
|
|
173
|
-
buffer: Buffer.alloc(0),
|
|
174
|
-
authenticated: true, // No auth required for now
|
|
175
|
-
database: 'test',
|
|
176
|
-
};
|
|
177
|
-
this.connections.set(connectionId, state);
|
|
178
|
-
socket.on('data', (data) => {
|
|
179
|
-
this.handleData(state, Buffer.isBuffer(data) ? data : Buffer.from(data));
|
|
180
|
-
});
|
|
181
|
-
socket.on('close', () => {
|
|
182
|
-
this.connections.delete(connectionId);
|
|
183
|
-
});
|
|
184
|
-
socket.on('error', (err) => {
|
|
185
|
-
// Connection errors are expected when clients disconnect
|
|
186
|
-
this.connections.delete(connectionId);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Handle incoming data from a client
|
|
191
|
-
*/
|
|
192
|
-
handleData(state, data) {
|
|
193
|
-
// Append new data to buffer
|
|
194
|
-
state.buffer = Buffer.concat([state.buffer, data]);
|
|
195
|
-
// Process messages from buffer
|
|
196
|
-
this.processMessages(state);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Process complete messages from the buffer
|
|
200
|
-
*/
|
|
201
|
-
async processMessages(state) {
|
|
202
|
-
while (state.buffer.length >= 16) {
|
|
203
|
-
try {
|
|
204
|
-
const result = WireProtocol.parseMessage(state.buffer);
|
|
205
|
-
if (!result) {
|
|
206
|
-
// Not enough data for a complete message
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
const { command, bytesConsumed } = result;
|
|
210
|
-
// Remove processed bytes from buffer
|
|
211
|
-
state.buffer = state.buffer.subarray(bytesConsumed);
|
|
212
|
-
// Process the command
|
|
213
|
-
const response = await this.commandRouter.route(command);
|
|
214
|
-
// Encode and send response
|
|
215
|
-
let responseBuffer;
|
|
216
|
-
if (command.opCode === OP_QUERY) {
|
|
217
|
-
// Legacy OP_QUERY gets OP_REPLY response
|
|
218
|
-
responseBuffer = WireProtocol.encodeOpReplyResponse(command.requestID, [response]);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// OP_MSG gets OP_MSG response
|
|
222
|
-
responseBuffer = WireProtocol.encodeOpMsgResponse(command.requestID, response);
|
|
223
|
-
}
|
|
224
|
-
if (!state.socket.destroyed) {
|
|
225
|
-
state.socket.write(responseBuffer);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
// Send error response
|
|
230
|
-
const errorResponse = WireProtocol.encodeErrorResponse(0, // We don't have the requestID at this point
|
|
231
|
-
1, error.message || 'Internal error');
|
|
232
|
-
if (!state.socket.destroyed) {
|
|
233
|
-
state.socket.write(errorResponse);
|
|
234
|
-
}
|
|
235
|
-
// Clear buffer on parse errors to avoid infinite loops
|
|
236
|
-
if (error.message?.includes('opCode') || error.message?.includes('section')) {
|
|
237
|
-
state.buffer = Buffer.alloc(0);
|
|
238
|
-
}
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
77
|
+
catch {
|
|
78
|
+
// Bridge may already be dead
|
|
241
79
|
}
|
|
80
|
+
this.bridge.kill();
|
|
81
|
+
this.isRunning = false;
|
|
242
82
|
}
|
|
243
83
|
/**
|
|
244
84
|
* Get the connection URI for this server
|
|
245
85
|
*/
|
|
246
86
|
getConnectionUri() {
|
|
247
|
-
if (this.
|
|
248
|
-
|
|
87
|
+
if (this.resolvedConnectionUri) {
|
|
88
|
+
return this.resolvedConnectionUri;
|
|
89
|
+
}
|
|
90
|
+
// Fallback: compute from options
|
|
91
|
+
if (this.options.socketPath) {
|
|
249
92
|
const encodedPath = encodeURIComponent(this.options.socketPath);
|
|
250
93
|
return `mongodb://${encodedPath}`;
|
|
251
94
|
}
|
|
252
|
-
return `mongodb://${this.options.host}:${this.options.port}`;
|
|
95
|
+
return `mongodb://${this.options.host ?? '127.0.0.1'}:${this.options.port ?? 27017}`;
|
|
253
96
|
}
|
|
254
97
|
/**
|
|
255
98
|
* Get the socket path (if using Unix socket mode)
|
|
256
99
|
*/
|
|
257
100
|
get socketPath() {
|
|
258
|
-
return this.
|
|
101
|
+
return this.options.socketPath;
|
|
259
102
|
}
|
|
260
103
|
/**
|
|
261
104
|
* Check if the server is running
|
|
@@ -267,13 +110,51 @@ export class SmartdbServer {
|
|
|
267
110
|
* Get the port the server is listening on
|
|
268
111
|
*/
|
|
269
112
|
get port() {
|
|
270
|
-
return this.options.port;
|
|
113
|
+
return this.options.port ?? 27017;
|
|
271
114
|
}
|
|
272
115
|
/**
|
|
273
116
|
* Get the host the server is bound to
|
|
274
117
|
*/
|
|
275
118
|
get host() {
|
|
276
|
-
return this.options.host;
|
|
119
|
+
return this.options.host ?? '127.0.0.1';
|
|
120
|
+
}
|
|
121
|
+
// --- OpLog / Debug API ---
|
|
122
|
+
/**
|
|
123
|
+
* Get oplog entries, optionally filtered.
|
|
124
|
+
*/
|
|
125
|
+
async getOpLog(params = {}) {
|
|
126
|
+
return this.bridge.getOpLog(params);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get aggregate oplog statistics.
|
|
130
|
+
*/
|
|
131
|
+
async getOpLogStats() {
|
|
132
|
+
return this.bridge.getOpLogStats();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Revert database state to a specific oplog sequence number.
|
|
136
|
+
* Use dryRun=true to preview which entries would be reverted.
|
|
137
|
+
*/
|
|
138
|
+
async revertToSeq(seq, dryRun = false) {
|
|
139
|
+
return this.bridge.revertToSeq(seq, dryRun);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* List all collections across all databases, with document counts.
|
|
143
|
+
*/
|
|
144
|
+
async getCollections(db) {
|
|
145
|
+
return this.bridge.getCollections(db);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get documents from a collection with pagination.
|
|
149
|
+
*/
|
|
150
|
+
async getDocuments(db, collection, limit = 50, skip = 0) {
|
|
151
|
+
return this.bridge.getDocuments(db, collection, limit, skip);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get server metrics including database/collection counts and oplog info.
|
|
155
|
+
*/
|
|
156
|
+
async getMetrics() {
|
|
157
|
+
return this.bridge.getMetrics();
|
|
277
158
|
}
|
|
278
159
|
}
|
|
279
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
160
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU21hcnRkYlNlcnZlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3RzL3RzX3NtYXJ0ZGIvc2VydmVyL1NtYXJ0ZGJTZXJ2ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBK0JwRDs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBa0JHO0FBQ0gsTUFBTSxPQUFPLGFBQWE7SUFNeEIsWUFBWSxVQUFpQyxFQUFFO1FBSHZDLGNBQVMsR0FBRyxLQUFLLENBQUM7UUFDbEIsMEJBQXFCLEdBQUcsRUFBRSxDQUFDO1FBR2pDLElBQUksQ0FBQyxPQUFPLEdBQUc7WUFDYixJQUFJLEVBQUUsT0FBTyxDQUFDLElBQUksSUFBSSxLQUFLO1lBQzNCLElBQUksRUFBRSxPQUFPLENBQUMsSUFBSSxJQUFJLFdBQVc7WUFDakMsVUFBVSxFQUFFLE9BQU8sQ0FBQyxVQUFVO1lBQzlCLE9BQU8sRUFBRSxPQUFPLENBQUMsT0FBTyxJQUFJLFFBQVE7WUFDcEMsV0FBVyxFQUFFLE9BQU8sQ0FBQyxXQUFXLElBQUksUUFBUTtZQUM1QyxXQUFXLEVBQUUsT0FBTyxDQUFDLFdBQVc7WUFDaEMsaUJBQWlCLEVBQUUsT0FBTyxDQUFDLGlCQUFpQixJQUFJLEtBQUs7U0FDdEQsQ0FBQztRQUNGLElBQUksQ0FBQyxN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FDSCxLQUFLLENBQUMsY0FBYyxDQUFDLEVBQVc7UUFDOUIsT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLGNBQWMsQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUN4QyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxLQUFLLENBQUMsWUFBWSxDQUNoQixFQUFVLEVBQ1YsVUFBa0IsRUFDbEIsS0FBSyxHQUFHLEVBQUUsRUFDVixJQUFJLEdBQUcsQ0FBQztRQUVSLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQyxZQUFZLENBQUMsRUFBRSxFQUFFLFVBQVUsRUFBRSxLQUFLLEVBQUUsSUFBSSxDQUFDLENBQUM7SUFDL0QsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSyxDQUFDLFVBQVU7UUFDZCxPQUFPLElBQUksQ0FBQyxNQUFNLENBQUMsVUFBVSxFQUFFLENBQUM7SUFDbEMsQ0FBQztDQUNGIn0=
|
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
export { SmartdbServer } from './SmartdbServer.js';
|
|
2
2
|
export type { ISmartdbServerOptions } from './SmartdbServer.js';
|
|
3
|
-
export { WireProtocol } from './WireProtocol.js';
|
|
4
|
-
export { CommandRouter } from './CommandRouter.js';
|
|
5
|
-
export type { ICommandHandler, IHandlerContext, ICursorState } from './CommandRouter.js';
|
|
6
|
-
export * from './handlers/index.js';
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
// Server module exports
|
|
2
2
|
export { SmartdbServer } from './SmartdbServer.js';
|
|
3
|
-
|
|
4
|
-
export { CommandRouter } from './CommandRouter.js';
|
|
5
|
-
// Export handlers
|
|
6
|
-
export * from './handlers/index.js';
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy90c19zbWFydGRiL3NlcnZlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx3QkFBd0I7QUFFeEIsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBRW5ELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNqRCxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFHbkQsa0JBQWtCO0FBQ2xCLGNBQWMscUJBQXFCLENBQUMifQ==
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy90c19zbWFydGRiL3NlcnZlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx3QkFBd0I7QUFDeEIsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG9CQUFvQixDQUFDIn0=
|