@push.rocks/smartmongo 4.0.0 β 4.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/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +2 -2
- package/readme.md +140 -17
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartmongo',
|
|
6
|
-
version: '4.
|
|
6
|
+
version: '4.1.1',
|
|
7
7
|
description: 'A module for creating and managing a local MongoDB instance for testing purposes.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLG1GQUFtRjtDQUNqRyxDQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartmongo",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A module for creating and managing a local MongoDB instance for testing purposes.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "Lossless GmbH",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "(tstest test
|
|
12
|
+
"test": "(tstest test/. --verbose --logfile --timeout 60)",
|
|
13
13
|
"build": "(tsbuild --web)",
|
|
14
14
|
"buildDocs": "tsdoc"
|
|
15
15
|
},
|
package/readme.md
CHANGED
|
@@ -134,8 +134,8 @@ await server.start();
|
|
|
134
134
|
console.log(server.getConnectionUri()); // mongodb://127.0.0.1:27017
|
|
135
135
|
|
|
136
136
|
// Server properties
|
|
137
|
-
console.log(server.running);
|
|
138
|
-
console.log(server.getUptime());
|
|
137
|
+
console.log(server.running); // true
|
|
138
|
+
console.log(server.getUptime()); // seconds
|
|
139
139
|
console.log(server.getConnectionCount()); // active connections
|
|
140
140
|
|
|
141
141
|
await server.stop();
|
|
@@ -279,7 +279,7 @@ console.log(result.deletedCount); // 1
|
|
|
279
279
|
|
|
280
280
|
### Storage Adapters
|
|
281
281
|
|
|
282
|
-
TsmDB supports pluggable storage:
|
|
282
|
+
TsmDB supports pluggable storage with data integrity features:
|
|
283
283
|
|
|
284
284
|
```typescript
|
|
285
285
|
// In-memory (default) - fast, data lost on stop
|
|
@@ -292,13 +292,118 @@ const server = new tsmdb.TsmdbServer({
|
|
|
292
292
|
persistIntervalMs: 30000 // Save every 30 seconds
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
-
// File-based - persistent storage
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
295
|
+
// File-based - persistent storage with optional checksums
|
|
296
|
+
import { FileStorageAdapter } from '@push.rocks/smartmongo/tsmdb';
|
|
297
|
+
|
|
298
|
+
const adapter = new FileStorageAdapter('./data/tsmdb', {
|
|
299
|
+
enableChecksums: true, // CRC32 checksums for data integrity
|
|
300
|
+
strictChecksums: false // Log warnings vs throw on mismatch
|
|
299
301
|
});
|
|
300
302
|
```
|
|
301
303
|
|
|
304
|
+
## β‘ Performance & Reliability Features
|
|
305
|
+
|
|
306
|
+
TsmDB includes enterprise-grade features for robustness:
|
|
307
|
+
|
|
308
|
+
### π Index-Accelerated Queries
|
|
309
|
+
|
|
310
|
+
Indexes are automatically used to accelerate queries. Instead of scanning all documents, TsmDB uses:
|
|
311
|
+
|
|
312
|
+
- **Hash indexes** for equality queries (`$eq`, `$in`)
|
|
313
|
+
- **B-tree indexes** for range queries (`$gt`, `$gte`, `$lt`, `$lte`)
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
// Create an index
|
|
317
|
+
await collection.createIndex({ email: 1 });
|
|
318
|
+
await collection.createIndex({ age: 1 });
|
|
319
|
+
|
|
320
|
+
// These queries will use the index (fast!)
|
|
321
|
+
await collection.findOne({ email: 'alice@example.com' }); // Uses hash lookup
|
|
322
|
+
await collection.find({ age: { $gte: 18, $lt: 65 } }); // Uses B-tree range scan
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### π Query Planner
|
|
326
|
+
|
|
327
|
+
TsmDB includes a query planner that analyzes queries and selects optimal execution strategies:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { tsmdb } from '@push.rocks/smartmongo';
|
|
331
|
+
|
|
332
|
+
// For debugging, you can access the query planner
|
|
333
|
+
const planner = new tsmdb.QueryPlanner(indexEngine);
|
|
334
|
+
const plan = planner.createPlan(filter);
|
|
335
|
+
|
|
336
|
+
console.log(plan);
|
|
337
|
+
// {
|
|
338
|
+
// type: 'IXSCAN', // or 'IXSCAN_RANGE', 'COLLSCAN'
|
|
339
|
+
// indexName: 'email_1',
|
|
340
|
+
// estimatedCost: 1,
|
|
341
|
+
// selectivity: 0.001
|
|
342
|
+
// }
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### π Write-Ahead Logging (WAL)
|
|
346
|
+
|
|
347
|
+
For durability, TsmDB supports write-ahead logging:
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { tsmdb } from '@push.rocks/smartmongo';
|
|
351
|
+
|
|
352
|
+
const wal = new tsmdb.WAL('./data/wal.log');
|
|
353
|
+
await wal.initialize();
|
|
354
|
+
|
|
355
|
+
// WAL entries include:
|
|
356
|
+
// - LSN (Log Sequence Number)
|
|
357
|
+
// - Timestamp
|
|
358
|
+
// - Operation type (insert, update, delete, checkpoint)
|
|
359
|
+
// - Document data (BSON serialized)
|
|
360
|
+
// - CRC32 checksum
|
|
361
|
+
|
|
362
|
+
// Recovery support
|
|
363
|
+
const entries = await wal.getEntriesAfter(lastCheckpointLsn);
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### π Session Management
|
|
367
|
+
|
|
368
|
+
TsmDB tracks client sessions with automatic timeout and transaction linking:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
// Sessions are automatically managed when using the MongoDB driver
|
|
372
|
+
const session = client.startSession();
|
|
373
|
+
|
|
374
|
+
try {
|
|
375
|
+
session.startTransaction();
|
|
376
|
+
await collection.insertOne({ name: 'Alice' }, { session });
|
|
377
|
+
await collection.updateOne({ name: 'Bob' }, { $inc: { balance: 100 } }, { session });
|
|
378
|
+
await session.commitTransaction();
|
|
379
|
+
} catch (error) {
|
|
380
|
+
await session.abortTransaction();
|
|
381
|
+
} finally {
|
|
382
|
+
session.endSession();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Session features:
|
|
386
|
+
// - Automatic session timeout (30 minutes default)
|
|
387
|
+
// - Transaction auto-abort on session expiry
|
|
388
|
+
// - Session activity tracking
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### β
Data Integrity Checksums
|
|
392
|
+
|
|
393
|
+
File-based storage supports CRC32 checksums to detect corruption:
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { FileStorageAdapter } from '@push.rocks/smartmongo/tsmdb';
|
|
397
|
+
|
|
398
|
+
const adapter = new FileStorageAdapter('./data', {
|
|
399
|
+
enableChecksums: true,
|
|
400
|
+
strictChecksums: true // Throw error on corruption (vs warning)
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Documents are checksummed on write, verified on read
|
|
404
|
+
// Checksums are automatically stripped before returning to client
|
|
405
|
+
```
|
|
406
|
+
|
|
302
407
|
### π Supported Wire Protocol Commands
|
|
303
408
|
|
|
304
409
|
| Category | Commands |
|
|
@@ -307,7 +412,9 @@ const server = new tsmdb.TsmdbServer({
|
|
|
307
412
|
| **CRUD** | `find`, `insert`, `update`, `delete`, `findAndModify`, `getMore`, `killCursors` |
|
|
308
413
|
| **Aggregation** | `aggregate`, `count`, `distinct` |
|
|
309
414
|
| **Indexes** | `createIndexes`, `dropIndexes`, `listIndexes` |
|
|
310
|
-
| **
|
|
415
|
+
| **Transactions** | `startTransaction`, `commitTransaction`, `abortTransaction` |
|
|
416
|
+
| **Sessions** | `startSession`, `endSessions` |
|
|
417
|
+
| **Admin** | `ping`, `listDatabases`, `listCollections`, `drop`, `dropDatabase`, `create`, `serverStatus`, `buildInfo`, `dbStats`, `collStats` |
|
|
311
418
|
|
|
312
419
|
TsmDB supports MongoDB wire protocol versions 0-21, compatible with MongoDB 3.6 through 7.0 drivers.
|
|
313
420
|
|
|
@@ -317,7 +424,7 @@ TsmDB supports MongoDB wire protocol versions 0-21, compatible with MongoDB 3.6
|
|
|
317
424
|
|
|
318
425
|
```typescript
|
|
319
426
|
import { tsmdb } from '@push.rocks/smartmongo';
|
|
320
|
-
import { MongoClient } from 'mongodb';
|
|
427
|
+
import { MongoClient, Db } from 'mongodb';
|
|
321
428
|
|
|
322
429
|
let server: tsmdb.TsmdbServer;
|
|
323
430
|
let client: MongoClient;
|
|
@@ -421,21 +528,37 @@ export default tap.start();
|
|
|
421
528
|
βΌ
|
|
422
529
|
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
423
530
|
β Engines β
|
|
424
|
-
β βββββββββββββ
|
|
425
|
-
β β
|
|
426
|
-
β β
|
|
427
|
-
β βββββββββββββ
|
|
531
|
+
β βββββββββββ ββββββββββ βββββββββββββ βββββββββ βββββββββ β
|
|
532
|
+
β β Query β β Update β βAggregationβ β Index β βSessionβ β
|
|
533
|
+
β β Planner β β Engine β β Engine β βEngine β βEngine β β
|
|
534
|
+
β βββββββββββ ββββββββββ βββββββββββββ βββββββββ βββββββββ β
|
|
535
|
+
β ββββββββββββββββββββββββ β
|
|
536
|
+
β β Transaction Engine β β
|
|
537
|
+
β ββββββββββββββββββββββββ β
|
|
428
538
|
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
|
|
429
539
|
β
|
|
430
540
|
βΌ
|
|
431
541
|
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
432
|
-
β Storage
|
|
433
|
-
β
|
|
434
|
-
β
|
|
435
|
-
β
|
|
542
|
+
β Storage Layer β
|
|
543
|
+
β ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββ β
|
|
544
|
+
β β MemoryStorage β β FileStorage β β WAL β β
|
|
545
|
+
β β β β (+ Checksums) β β β β
|
|
546
|
+
β ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββ β
|
|
436
547
|
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
437
548
|
```
|
|
438
549
|
|
|
550
|
+
### Key Components
|
|
551
|
+
|
|
552
|
+
| Component | Description |
|
|
553
|
+
|-----------|-------------|
|
|
554
|
+
| **WireProtocol** | Parses MongoDB OP_MSG binary protocol |
|
|
555
|
+
| **CommandRouter** | Routes commands to appropriate handlers |
|
|
556
|
+
| **QueryPlanner** | Analyzes queries and selects execution strategy |
|
|
557
|
+
| **IndexEngine** | Manages B-tree and hash indexes |
|
|
558
|
+
| **SessionEngine** | Tracks client sessions and timeouts |
|
|
559
|
+
| **TransactionEngine** | Handles ACID transaction semantics |
|
|
560
|
+
| **WAL** | Write-ahead logging for durability |
|
|
561
|
+
|
|
439
562
|
## License and Legal Information
|
|
440
563
|
|
|
441
564
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|