@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,283 +0,0 @@
1
- import * as plugins from '../plugins.js';
2
- import type { Document, IStoredDocument, IAggregateOptions } from '../types/interfaces.js';
3
-
4
- // Import mingo Aggregator
5
- import { Aggregator } from 'mingo';
6
-
7
- /**
8
- * Aggregation engine using mingo for MongoDB-compatible aggregation pipeline execution
9
- */
10
- export class AggregationEngine {
11
- /**
12
- * Execute an aggregation pipeline on a collection of documents
13
- */
14
- static aggregate(
15
- documents: IStoredDocument[],
16
- pipeline: Document[],
17
- options?: IAggregateOptions
18
- ): Document[] {
19
- if (!pipeline || pipeline.length === 0) {
20
- return documents;
21
- }
22
-
23
- // Create mingo aggregator with the pipeline
24
- const aggregator = new Aggregator(pipeline, {
25
- collation: options?.collation as any,
26
- });
27
-
28
- // Run the aggregation
29
- const result = aggregator.run(documents);
30
-
31
- return Array.isArray(result) ? result : [];
32
- }
33
-
34
- /**
35
- * Execute aggregation and return an iterator for lazy evaluation
36
- */
37
- static *aggregateIterator(
38
- documents: IStoredDocument[],
39
- pipeline: Document[],
40
- options?: IAggregateOptions
41
- ): Generator<Document> {
42
- const aggregator = new Aggregator(pipeline, {
43
- collation: options?.collation as any,
44
- });
45
-
46
- // Get the cursor from mingo
47
- const cursor = aggregator.stream(documents);
48
-
49
- for (const doc of cursor) {
50
- yield doc as Document;
51
- }
52
- }
53
-
54
- /**
55
- * Execute a $lookup stage manually (for cross-collection lookups)
56
- * This is used when the lookup references another collection in the same database
57
- */
58
- static executeLookup(
59
- documents: IStoredDocument[],
60
- lookupSpec: {
61
- from: string;
62
- localField: string;
63
- foreignField: string;
64
- as: string;
65
- },
66
- foreignCollection: IStoredDocument[]
67
- ): Document[] {
68
- const { localField, foreignField, as } = lookupSpec;
69
-
70
- return documents.map(doc => {
71
- const localValue = this.getNestedValue(doc, localField);
72
- const matches = foreignCollection.filter(foreignDoc => {
73
- const foreignValue = this.getNestedValue(foreignDoc, foreignField);
74
- return this.valuesMatch(localValue, foreignValue);
75
- });
76
-
77
- return {
78
- ...doc,
79
- [as]: matches,
80
- };
81
- });
82
- }
83
-
84
- /**
85
- * Execute a $graphLookup stage manually
86
- */
87
- static executeGraphLookup(
88
- documents: IStoredDocument[],
89
- graphLookupSpec: {
90
- from: string;
91
- startWith: string | Document;
92
- connectFromField: string;
93
- connectToField: string;
94
- as: string;
95
- maxDepth?: number;
96
- depthField?: string;
97
- restrictSearchWithMatch?: Document;
98
- },
99
- foreignCollection: IStoredDocument[]
100
- ): Document[] {
101
- const {
102
- startWith,
103
- connectFromField,
104
- connectToField,
105
- as,
106
- maxDepth = 10,
107
- depthField,
108
- restrictSearchWithMatch,
109
- } = graphLookupSpec;
110
-
111
- return documents.map(doc => {
112
- const startValue = typeof startWith === 'string' && startWith.startsWith('$')
113
- ? this.getNestedValue(doc, startWith.slice(1))
114
- : startWith;
115
-
116
- const results: Document[] = [];
117
- const visited = new Set<string>();
118
- const queue: Array<{ value: any; depth: number }> = [];
119
-
120
- // Initialize with start value(s)
121
- const startValues = Array.isArray(startValue) ? startValue : [startValue];
122
- for (const val of startValues) {
123
- queue.push({ value: val, depth: 0 });
124
- }
125
-
126
- while (queue.length > 0) {
127
- const { value, depth } = queue.shift()!;
128
- if (depth > maxDepth) continue;
129
-
130
- const valueKey = JSON.stringify(value);
131
- if (visited.has(valueKey)) continue;
132
- visited.add(valueKey);
133
-
134
- // Find matching documents
135
- for (const foreignDoc of foreignCollection) {
136
- const foreignValue = this.getNestedValue(foreignDoc, connectToField);
137
-
138
- if (this.valuesMatch(value, foreignValue)) {
139
- // Check restrictSearchWithMatch
140
- if (restrictSearchWithMatch) {
141
- const matchQuery = new plugins.mingo.Query(restrictSearchWithMatch);
142
- if (!matchQuery.test(foreignDoc)) continue;
143
- }
144
-
145
- const resultDoc = depthField
146
- ? { ...foreignDoc, [depthField]: depth }
147
- : { ...foreignDoc };
148
-
149
- // Avoid duplicates in results
150
- const docKey = foreignDoc._id.toHexString();
151
- if (!results.some(r => r._id?.toHexString?.() === docKey)) {
152
- results.push(resultDoc);
153
-
154
- // Add connected values to queue
155
- const nextValue = this.getNestedValue(foreignDoc, connectFromField);
156
- if (nextValue !== undefined) {
157
- const nextValues = Array.isArray(nextValue) ? nextValue : [nextValue];
158
- for (const nv of nextValues) {
159
- queue.push({ value: nv, depth: depth + 1 });
160
- }
161
- }
162
- }
163
- }
164
- }
165
- }
166
-
167
- return {
168
- ...doc,
169
- [as]: results,
170
- };
171
- });
172
- }
173
-
174
- /**
175
- * Execute a $facet stage manually
176
- */
177
- static executeFacet(
178
- documents: IStoredDocument[],
179
- facetSpec: Record<string, Document[]>
180
- ): Document {
181
- const result: Document = {};
182
-
183
- for (const [facetName, pipeline] of Object.entries(facetSpec)) {
184
- result[facetName] = this.aggregate(documents, pipeline);
185
- }
186
-
187
- return result;
188
- }
189
-
190
- /**
191
- * Execute a $unionWith stage
192
- */
193
- static executeUnionWith(
194
- documents: IStoredDocument[],
195
- otherDocuments: IStoredDocument[],
196
- pipeline?: Document[]
197
- ): Document[] {
198
- let unionDocs: Document[] = otherDocuments;
199
- if (pipeline && pipeline.length > 0) {
200
- unionDocs = this.aggregate(otherDocuments, pipeline);
201
- }
202
- return [...documents, ...unionDocs];
203
- }
204
-
205
- /**
206
- * Execute a $merge stage (output to another collection)
207
- * Returns the documents that would be inserted/updated
208
- */
209
- static prepareMerge(
210
- documents: Document[],
211
- mergeSpec: {
212
- into: string;
213
- on?: string | string[];
214
- whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Document[];
215
- whenNotMatched?: 'insert' | 'discard' | 'fail';
216
- }
217
- ): {
218
- toInsert: Document[];
219
- toUpdate: Array<{ filter: Document; update: Document }>;
220
- onField: string | string[];
221
- whenMatched: string | Document[];
222
- whenNotMatched: string;
223
- } {
224
- const onField = mergeSpec.on || '_id';
225
- const whenMatched = mergeSpec.whenMatched || 'merge';
226
- const whenNotMatched = mergeSpec.whenNotMatched || 'insert';
227
-
228
- return {
229
- toInsert: [],
230
- toUpdate: [],
231
- onField,
232
- whenMatched,
233
- whenNotMatched,
234
- };
235
- }
236
-
237
- // ============================================================================
238
- // Helper Methods
239
- // ============================================================================
240
-
241
- private static getNestedValue(obj: any, path: string): any {
242
- const parts = path.split('.');
243
- let current = obj;
244
-
245
- for (const part of parts) {
246
- if (current === null || current === undefined) {
247
- return undefined;
248
- }
249
- current = current[part];
250
- }
251
-
252
- return current;
253
- }
254
-
255
- private static valuesMatch(a: any, b: any): boolean {
256
- if (a === b) return true;
257
-
258
- // Handle ObjectId comparison
259
- if (a instanceof plugins.bson.ObjectId && b instanceof plugins.bson.ObjectId) {
260
- return a.equals(b);
261
- }
262
-
263
- // Handle array contains check
264
- if (Array.isArray(a)) {
265
- return a.some(item => this.valuesMatch(item, b));
266
- }
267
- if (Array.isArray(b)) {
268
- return b.some(item => this.valuesMatch(a, item));
269
- }
270
-
271
- // Handle Date comparison
272
- if (a instanceof Date && b instanceof Date) {
273
- return a.getTime() === b.getTime();
274
- }
275
-
276
- // Handle object comparison
277
- if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) {
278
- return JSON.stringify(a) === JSON.stringify(b);
279
- }
280
-
281
- return false;
282
- }
283
- }