@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
@@ -1,46 +1,19 @@
1
- // SmartDB - MongoDB Wire Protocol compatible in-memory database server
2
- // Use the official MongoDB driver to connect to SmartdbServer
3
-
4
- // Re-export plugins for external use
5
- import * as plugins from './plugins.js';
6
- export { plugins };
7
-
8
- // Export BSON types for convenience
9
- export { ObjectId, Binary, Timestamp, Long, Decimal128, UUID } from 'bson';
10
-
11
- // Export all types
12
- export * from './types/interfaces.js';
13
-
14
- // Export errors
15
- export * from './errors/SmartdbErrors.js';
16
-
17
- // Export storage adapters
18
- export type { IStorageAdapter } from './storage/IStorageAdapter.js';
19
- export { MemoryStorageAdapter } from './storage/MemoryStorageAdapter.js';
20
- export { FileStorageAdapter } from './storage/FileStorageAdapter.js';
21
- export { OpLog } from './storage/OpLog.js';
22
- export { WAL } from './storage/WAL.js';
23
- export type { IWalEntry, TWalOperation } from './storage/WAL.js';
24
-
25
- // Export engines
26
- export { QueryEngine } from './engine/QueryEngine.js';
27
- export { UpdateEngine } from './engine/UpdateEngine.js';
28
- export { AggregationEngine } from './engine/AggregationEngine.js';
29
- export { IndexEngine } from './engine/IndexEngine.js';
30
- export { TransactionEngine } from './engine/TransactionEngine.js';
31
- export { QueryPlanner } from './engine/QueryPlanner.js';
32
- export type { IQueryPlan, TQueryPlanType } from './engine/QueryPlanner.js';
33
- export { SessionEngine } from './engine/SessionEngine.js';
34
- export type { ISession, ISessionEngineOptions } from './engine/SessionEngine.js';
1
+ // SmartDB - Wire protocol compatible embedded database server
35
2
 
36
3
  // Export server (the main entry point for using SmartDB)
37
4
  export { SmartdbServer } from './server/SmartdbServer.js';
38
5
  export type { ISmartdbServerOptions } from './server/SmartdbServer.js';
39
6
 
40
- // Export wire protocol utilities (for advanced usage)
41
- export { WireProtocol } from './server/WireProtocol.js';
42
- export { CommandRouter } from './server/CommandRouter.js';
43
- export type { ICommandHandler, IHandlerContext, ICursorState } from './server/CommandRouter.js';
44
-
45
- // Export utilities
46
- export * from './utils/checksum.js';
7
+ // Export bridge for advanced usage
8
+ export { RustDbBridge } from './rust-db-bridge.js';
9
+
10
+ // Export oplog / debug types
11
+ export type {
12
+ IOpLogEntry,
13
+ IOpLogResult,
14
+ IOpLogStats,
15
+ IRevertResult,
16
+ ICollectionInfo,
17
+ IDocumentsResult,
18
+ ISmartDbMetrics,
19
+ } from './rust-db-bridge.js';
@@ -1,17 +1,4 @@
1
1
  // @push.rocks scope
2
- import * as smartfs from '@push.rocks/smartfs';
3
- import * as smartpath from '@push.rocks/smartpath';
4
- import * as smartpromise from '@push.rocks/smartpromise';
5
- import * as smartrx from '@push.rocks/smartrx';
2
+ import * as smartrust from '@push.rocks/smartrust';
6
3
 
7
- export { smartfs, smartpath, smartpromise, smartrx };
8
-
9
- // thirdparty
10
- import * as bson from 'bson';
11
- import * as mingo from 'mingo';
12
-
13
- export { bson, mingo };
14
-
15
- // Re-export commonly used mingo classes
16
- export { Query } from 'mingo';
17
- export { Aggregator } from 'mingo';
4
+ export { smartrust };
@@ -0,0 +1,262 @@
1
+ import * as plugins from './plugins.js';
2
+ import * as path from 'path';
3
+ import * as url from 'url';
4
+ import { EventEmitter } from 'events';
5
+
6
+ /**
7
+ * A single oplog entry returned from the Rust engine.
8
+ */
9
+ export interface IOpLogEntry {
10
+ seq: number;
11
+ timestampMs: number;
12
+ op: 'insert' | 'update' | 'delete';
13
+ db: string;
14
+ collection: string;
15
+ documentId: string;
16
+ document: Record<string, any> | null;
17
+ previousDocument: Record<string, any> | null;
18
+ }
19
+
20
+ /**
21
+ * Aggregate oplog statistics.
22
+ */
23
+ export interface IOpLogStats {
24
+ currentSeq: number;
25
+ totalEntries: number;
26
+ oldestSeq: number;
27
+ entriesByOp: {
28
+ insert: number;
29
+ update: number;
30
+ delete: number;
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Result of a getOpLog query.
36
+ */
37
+ export interface IOpLogResult {
38
+ entries: IOpLogEntry[];
39
+ currentSeq: number;
40
+ totalEntries: number;
41
+ }
42
+
43
+ /**
44
+ * Result of a revertToSeq command.
45
+ */
46
+ export interface IRevertResult {
47
+ dryRun: boolean;
48
+ reverted: number;
49
+ targetSeq?: number;
50
+ entries?: IOpLogEntry[];
51
+ errors?: string[];
52
+ }
53
+
54
+ /**
55
+ * A collection info entry.
56
+ */
57
+ export interface ICollectionInfo {
58
+ db: string;
59
+ name: string;
60
+ count: number;
61
+ }
62
+
63
+ /**
64
+ * Result of a getDocuments query.
65
+ */
66
+ export interface IDocumentsResult {
67
+ documents: Record<string, any>[];
68
+ total: number;
69
+ }
70
+
71
+ /**
72
+ * Server metrics.
73
+ */
74
+ export interface ISmartDbMetrics {
75
+ databases: number;
76
+ collections: number;
77
+ oplogEntries: number;
78
+ oplogCurrentSeq: number;
79
+ uptimeSeconds: number;
80
+ }
81
+
82
+ /**
83
+ * Type-safe command definitions for the RustDb IPC protocol.
84
+ */
85
+ type TSmartDbCommands = {
86
+ start: { params: { config: ISmartDbRustConfig }; result: { connectionUri: string } };
87
+ stop: { params: Record<string, never>; result: void };
88
+ getStatus: { params: Record<string, never>; result: { running: boolean } };
89
+ getMetrics: { params: Record<string, never>; result: ISmartDbMetrics };
90
+ getOpLog: {
91
+ params: { sinceSeq?: number; limit?: number; db?: string; collection?: string };
92
+ result: IOpLogResult;
93
+ };
94
+ getOpLogStats: { params: Record<string, never>; result: IOpLogStats };
95
+ revertToSeq: {
96
+ params: { seq: number; dryRun?: boolean };
97
+ result: IRevertResult;
98
+ };
99
+ getCollections: {
100
+ params: { db?: string };
101
+ result: { collections: ICollectionInfo[] };
102
+ };
103
+ getDocuments: {
104
+ params: { db: string; collection: string; limit?: number; skip?: number };
105
+ result: IDocumentsResult;
106
+ };
107
+ };
108
+
109
+ /**
110
+ * Configuration sent to the Rust binary on start.
111
+ */
112
+ interface ISmartDbRustConfig {
113
+ port?: number;
114
+ host?: string;
115
+ socketPath?: string;
116
+ storage: 'memory' | 'file';
117
+ storagePath?: string;
118
+ persistPath?: string;
119
+ persistIntervalMs?: number;
120
+ }
121
+
122
+ /**
123
+ * Get the package root directory using import.meta.url.
124
+ * This file is at ts/ts_smartdb/, so package root is 2 levels up.
125
+ */
126
+ function getPackageRoot(): string {
127
+ const thisDir = path.dirname(url.fileURLToPath(import.meta.url));
128
+ return path.resolve(thisDir, '..', '..');
129
+ }
130
+
131
+ /**
132
+ * Map Node.js process.platform/process.arch to tsrust's friendly name suffix.
133
+ * tsrust names cross-compiled binaries as: rustdb_linux_amd64, rustdb_linux_arm64, etc.
134
+ */
135
+ function getTsrustPlatformSuffix(): string | null {
136
+ const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' };
137
+ const osMap: Record<string, string> = { linux: 'linux', darwin: 'macos' };
138
+ const os = osMap[process.platform];
139
+ const arch = archMap[process.arch];
140
+ if (os && arch) {
141
+ return `${os}_${arch}`;
142
+ }
143
+ return null;
144
+ }
145
+
146
+ /**
147
+ * Build local search paths for the Rust binary, including dist_rust/ candidates
148
+ * (built by tsrust) and local development build paths.
149
+ */
150
+ function buildLocalPaths(): string[] {
151
+ const packageRoot = getPackageRoot();
152
+ const suffix = getTsrustPlatformSuffix();
153
+ const paths: string[] = [];
154
+
155
+ // dist_rust/ candidates (tsrust cross-compiled output)
156
+ if (suffix) {
157
+ paths.push(path.join(packageRoot, 'dist_rust', `rustdb_${suffix}`));
158
+ }
159
+ paths.push(path.join(packageRoot, 'dist_rust', 'rustdb'));
160
+
161
+ // Local dev build paths
162
+ paths.push(path.resolve(process.cwd(), 'rust', 'target', 'release', 'rustdb'));
163
+ paths.push(path.resolve(process.cwd(), 'rust', 'target', 'debug', 'rustdb'));
164
+
165
+ return paths;
166
+ }
167
+
168
+ /**
169
+ * Bridge between TypeScript SmartdbServer and the Rust binary.
170
+ * Wraps @push.rocks/smartrust's RustBridge with type-safe command definitions.
171
+ */
172
+ export class RustDbBridge extends EventEmitter {
173
+ private bridge: plugins.smartrust.RustBridge<TSmartDbCommands>;
174
+
175
+ constructor() {
176
+ super();
177
+
178
+ this.bridge = new plugins.smartrust.RustBridge<TSmartDbCommands>({
179
+ binaryName: 'rustdb',
180
+ envVarName: 'SMARTDB_RUST_BINARY',
181
+ platformPackagePrefix: '@push.rocks/smartdb',
182
+ localPaths: buildLocalPaths(),
183
+ maxPayloadSize: 10 * 1024 * 1024, // 10 MB
184
+ });
185
+
186
+ // Forward events from the inner bridge
187
+ this.bridge.on('exit', (code: number | null, signal: string | null) => {
188
+ this.emit('exit', code, signal);
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Spawn the Rust binary in management mode.
194
+ * Returns true if the binary was found and spawned successfully.
195
+ */
196
+ public async spawn(): Promise<boolean> {
197
+ return this.bridge.spawn();
198
+ }
199
+
200
+ /**
201
+ * Kill the Rust process and clean up.
202
+ */
203
+ public kill(): void {
204
+ this.bridge.kill();
205
+ }
206
+
207
+ /**
208
+ * Whether the bridge is currently running.
209
+ */
210
+ public get running(): boolean {
211
+ return this.bridge.running;
212
+ }
213
+
214
+ // --- Convenience methods for each management command ---
215
+
216
+ public async startDb(config: ISmartDbRustConfig): Promise<{ connectionUri: string }> {
217
+ return await this.bridge.sendCommand('start', { config }) as { connectionUri: string };
218
+ }
219
+
220
+ public async stopDb(): Promise<void> {
221
+ await this.bridge.sendCommand('stop', {} as Record<string, never>);
222
+ }
223
+
224
+ public async getStatus(): Promise<{ running: boolean }> {
225
+ return await this.bridge.sendCommand('getStatus', {} as Record<string, never>) as { running: boolean };
226
+ }
227
+
228
+ public async getMetrics(): Promise<ISmartDbMetrics> {
229
+ return this.bridge.sendCommand('getMetrics', {} as Record<string, never>) as Promise<ISmartDbMetrics>;
230
+ }
231
+
232
+ public async getOpLog(params: {
233
+ sinceSeq?: number;
234
+ limit?: number;
235
+ db?: string;
236
+ collection?: string;
237
+ } = {}): Promise<IOpLogResult> {
238
+ return this.bridge.sendCommand('getOpLog', params) as Promise<IOpLogResult>;
239
+ }
240
+
241
+ public async getOpLogStats(): Promise<IOpLogStats> {
242
+ return this.bridge.sendCommand('getOpLogStats', {} as Record<string, never>) as Promise<IOpLogStats>;
243
+ }
244
+
245
+ public async revertToSeq(seq: number, dryRun = false): Promise<IRevertResult> {
246
+ return this.bridge.sendCommand('revertToSeq', { seq, dryRun }) as Promise<IRevertResult>;
247
+ }
248
+
249
+ public async getCollections(db?: string): Promise<ICollectionInfo[]> {
250
+ const result = await this.bridge.sendCommand('getCollections', db ? { db } : {}) as { collections: ICollectionInfo[] };
251
+ return result.collections;
252
+ }
253
+
254
+ public async getDocuments(
255
+ db: string,
256
+ collection: string,
257
+ limit = 50,
258
+ skip = 0,
259
+ ): Promise<IDocumentsResult> {
260
+ return this.bridge.sendCommand('getDocuments', { db, collection, limit, skip }) as Promise<IDocumentsResult>;
261
+ }
262
+ }