From a0df731bc0194a07b853019e11240da8f86cc636 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sun, 1 Feb 2026 14:34:07 +0000 Subject: [PATCH] BREAKING CHANGE(tsmdb): rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports --- changelog.md | 9 ++ readme.hints.md | 19 ++- readme.md | 50 ++++---- test/{test.congodb.ts => test.tsmdb.ts} | 110 +++++++++--------- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 4 +- .../engine/AggregationEngine.ts | 2 +- ts/{congodb => tsmdb}/engine/IndexEngine.ts | 14 +-- ts/{congodb => tsmdb}/engine/QueryEngine.ts | 2 +- .../engine/TransactionEngine.ts | 24 ++-- ts/{congodb => tsmdb}/engine/UpdateEngine.ts | 2 +- .../errors/TsmdbErrors.ts} | 68 +++++------ ts/{congodb => tsmdb}/index.ts | 14 +-- ts/{congodb => tsmdb}/server/CommandRouter.ts | 10 +- .../server/TsmdbServer.ts} | 16 +-- ts/{congodb => tsmdb}/server/WireProtocol.ts | 2 +- .../server/handlers/AdminHandler.ts | 12 +- .../server/handlers/AggregateHandler.ts | 2 +- .../server/handlers/DeleteHandler.ts | 2 +- .../server/handlers/FindHandler.ts | 2 +- .../server/handlers/HelloHandler.ts | 2 +- .../server/handlers/IndexHandler.ts | 2 +- .../server/handlers/InsertHandler.ts | 2 +- .../server/handlers/UpdateHandler.ts | 2 +- .../server/handlers/index.ts | 0 ts/{congodb => tsmdb}/server/index.ts | 4 +- .../storage/FileStorageAdapter.ts | 4 +- .../storage/IStorageAdapter.ts | 4 +- .../storage/MemoryStorageAdapter.ts | 4 +- ts/{congodb => tsmdb}/storage/OpLog.ts | 2 +- .../tsmdb.plugins.ts} | 0 ts/{congodb => tsmdb}/types/interfaces.ts | 6 +- 32 files changed, 201 insertions(+), 197 deletions(-) rename test/{test.congodb.ts => test.tsmdb.ts} (81%) rename ts/{congodb => tsmdb}/engine/AggregationEngine.ts (99%) rename ts/{congodb => tsmdb}/engine/IndexEngine.ts (97%) rename ts/{congodb => tsmdb}/engine/QueryEngine.ts (99%) rename ts/{congodb => tsmdb}/engine/TransactionEngine.ts (92%) rename ts/{congodb => tsmdb}/engine/UpdateEngine.ts (99%) rename ts/{congodb/errors/CongoErrors.ts => tsmdb/errors/TsmdbErrors.ts} (64%) rename ts/{congodb => tsmdb}/index.ts (73%) rename ts/{congodb => tsmdb}/server/CommandRouter.ts (96%) rename ts/{congodb/server/CongoServer.ts => tsmdb/server/TsmdbServer.ts} (94%) rename ts/{congodb => tsmdb}/server/WireProtocol.ts (99%) rename ts/{congodb => tsmdb}/server/handlers/AdminHandler.ts (98%) rename ts/{congodb => tsmdb}/server/handlers/AggregateHandler.ts (99%) rename ts/{congodb => tsmdb}/server/handlers/DeleteHandler.ts (98%) rename ts/{congodb => tsmdb}/server/handlers/FindHandler.ts (99%) rename ts/{congodb => tsmdb}/server/handlers/HelloHandler.ts (97%) rename ts/{congodb => tsmdb}/server/handlers/IndexHandler.ts (99%) rename ts/{congodb => tsmdb}/server/handlers/InsertHandler.ts (97%) rename ts/{congodb => tsmdb}/server/handlers/UpdateHandler.ts (99%) rename ts/{congodb => tsmdb}/server/handlers/index.ts (100%) rename ts/{congodb => tsmdb}/server/index.ts (71%) rename ts/{congodb => tsmdb}/storage/FileStorageAdapter.ts (99%) rename ts/{congodb => tsmdb}/storage/IStorageAdapter.ts (98%) rename ts/{congodb => tsmdb}/storage/MemoryStorageAdapter.ts (99%) rename ts/{congodb => tsmdb}/storage/OpLog.ts (99%) rename ts/{congodb/congodb.plugins.ts => tsmdb/tsmdb.plugins.ts} (100%) rename ts/{congodb => tsmdb}/types/interfaces.ts (99%) diff --git a/changelog.md b/changelog.md index 1a07742..2b8b3d6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2026-02-01 - 3.0.0 - BREAKING CHANGE(tsmdb) +rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports + +- Project refactor renames the in-memory wire-protocol server from CongoDB -> TsmDB (identifiers, files and namespaces changed). +- ts/index.ts now exports tsmdb instead of congodb (public API change; consumers must update imports). +- All congodb sources under ts/congodb were removed and equivalent implementations added under ts/tsmdb (errors, engines, storage adapters, server, handlers, WireProtocol, types). +- Readme and usage examples updated to reference TsmDB/tsmdb and example code updated accordingly. +- Tests renamed/updated from test.congodb.ts -> test.tsmdb.ts to exercise the new tsmdb export and server. + ## 2026-01-31 - 2.2.0 - feat(readme) update README with expanded documentation covering CongoDB and SmartMongo, installation, quick start examples, architecture, usage examples, and legal/company information diff --git a/readme.hints.md b/readme.hints.md index f7bb771..456d7ff 100644 --- a/readme.hints.md +++ b/readme.hints.md @@ -9,21 +9,21 @@ - **Why:** Deno wraps CommonJS exports in a `default` property, so default imports are required - Fixed in version 2.0.13 (changed from `import * as mongoPlugin`) -## CongoDB - MongoDB Wire Protocol Server +## TsmDB - MongoDB Wire Protocol Server ### Architecture -CongoDB implements the MongoDB binary wire protocol (OP_MSG, OP_QUERY) allowing official MongoDB drivers to connect directly. +TsmDB implements the MongoDB binary wire protocol (OP_MSG, OP_QUERY) allowing official MongoDB drivers to connect directly. ``` -Official MongoClient → TCP (wire protocol) → CongoServer → Engines → Storage +Official MongoClient → TCP (wire protocol) → TsmdbServer → Engines → Storage (mongodb npm) OP_MSG/BSON (port) ``` ### Module Structure ``` -ts/congodb/ +ts/tsmdb/ ├── server/ # Wire protocol server -│ ├── CongoServer.ts # TCP server, connection handling +│ ├── TsmdbServer.ts # TCP server, connection handling │ ├── WireProtocol.ts # OP_MSG/OP_QUERY parsing & encoding │ ├── CommandRouter.ts # Route commands to handlers │ └── handlers/ # Command implementations @@ -53,11 +53,11 @@ ts/congodb/ ### Usage Example ```typescript -import { CongoServer } from '@push.rocks/smartmongo/congodb'; +import { TsmdbServer } from '@push.rocks/smartmongo/tsmdb'; import { MongoClient } from 'mongodb'; // Start server -const server = new CongoServer({ port: 27117 }); +const server = new TsmdbServer({ port: 27117 }); await server.start(); // Connect with official MongoDB driver @@ -82,8 +82,3 @@ await server.stop(); - **Aggregation**: aggregate, count, distinct - **Indexes**: createIndexes, dropIndexes, listIndexes - **Admin**: ping, listDatabases, listCollections, drop, dropDatabase, create, serverStatus, buildInfo - -### Notes -- The old CongoClient/CongoDb/CongoCollection classes have been removed -- Use the official `mongodb` npm package's MongoClient instead -- Server supports MongoDB wire protocol versions 0-21 (MongoDB 3.6 through 7.0 compatible) diff --git a/readme.md b/readme.md index 6fcbfc1..a52c617 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # @push.rocks/smartmongo -A powerful MongoDB toolkit for testing and development — featuring both a real MongoDB memory server (**SmartMongo**) and an ultra-fast, lightweight wire-protocol-compatible in-memory database server (**CongoDB**). 🚀 +A powerful MongoDB toolkit for testing and development — featuring both a real MongoDB memory server (**SmartMongo**) and an ultra-fast, lightweight wire-protocol-compatible in-memory database server (**TsmDB**). 🚀 ## Install @@ -18,7 +18,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community `@push.rocks/smartmongo` provides two powerful approaches for MongoDB in testing and development: -| Feature | SmartMongo | CongoDB | +| Feature | SmartMongo | TsmDB | |---------|------------|---------| | **Type** | Real MongoDB (memory server) | Pure TypeScript wire protocol server | | **Speed** | ~2-5s startup | ⚡ Instant startup (~5ms) | @@ -51,16 +51,16 @@ console.log(descriptor.mongoDbUrl); // mongodb://127.0.0.1:xxxxx/... await mongo.stop(); ``` -### Option 2: CongoDB (Wire Protocol Server) +### Option 2: TsmDB (Wire Protocol Server) A lightweight, pure TypeScript MongoDB-compatible server that speaks the wire protocol — use the official `mongodb` driver directly! ```typescript -import { congodb } from '@push.rocks/smartmongo'; +import { tsmdb } from '@push.rocks/smartmongo'; import { MongoClient } from 'mongodb'; -// Start CongoDB server -const server = new congodb.CongoServer({ port: 27017 }); +// Start TsmDB server +const server = new tsmdb.TsmdbServer({ port: 27017 }); await server.start(); // Connect with the official MongoDB driver! @@ -116,14 +116,14 @@ await mongo.stopAndDumpToDir('./test-data'); await mongo.stopAndDumpToDir('./test-data', (doc) => `${doc.collection}-${doc._id}.bson`); ``` -## 🔧 CongoDB API +## 🔧 TsmDB API ### Server Configuration ```typescript -import { congodb } from '@push.rocks/smartmongo'; +import { tsmdb } from '@push.rocks/smartmongo'; -const server = new congodb.CongoServer({ +const server = new tsmdb.TsmdbServer({ port: 27017, // Default MongoDB port host: '127.0.0.1', // Bind address storage: 'memory', // 'memory' or 'file' @@ -143,7 +143,7 @@ await server.stop(); ### Supported MongoDB Operations -CongoDB supports the core MongoDB operations via the wire protocol: +TsmDB supports the core MongoDB operations via the wire protocol: #### 🔹 CRUD Operations ```typescript @@ -279,23 +279,23 @@ console.log(result.deletedCount); // 1 ### Storage Adapters -CongoDB supports pluggable storage: +TsmDB supports pluggable storage: ```typescript // In-memory (default) - fast, data lost on stop -const server = new congodb.CongoServer({ storage: 'memory' }); +const server = new tsmdb.TsmdbServer({ storage: 'memory' }); // In-memory with persistence - periodic snapshots to disk -const server = new congodb.CongoServer({ +const server = new tsmdb.TsmdbServer({ storage: 'memory', persistPath: './data/snapshot.json', persistIntervalMs: 30000 // Save every 30 seconds }); // File-based - persistent storage -const server = new congodb.CongoServer({ +const server = new tsmdb.TsmdbServer({ storage: 'file', - storagePath: './data/congodb' + storagePath: './data/tsmdb' }); ``` @@ -309,22 +309,22 @@ const server = new congodb.CongoServer({ | **Indexes** | `createIndexes`, `dropIndexes`, `listIndexes` | | **Admin** | `ping`, `listDatabases`, `listCollections`, `drop`, `dropDatabase`, `create`, `serverStatus`, `buildInfo` | -CongoDB supports MongoDB wire protocol versions 0-21, compatible with MongoDB 3.6 through 7.0 drivers. +TsmDB supports MongoDB wire protocol versions 0-21, compatible with MongoDB 3.6 through 7.0 drivers. ## 🧪 Testing Examples -### Jest/Mocha with CongoDB +### Jest/Mocha with TsmDB ```typescript -import { congodb } from '@push.rocks/smartmongo'; +import { tsmdb } from '@push.rocks/smartmongo'; import { MongoClient } from 'mongodb'; -let server: congodb.CongoServer; +let server: tsmdb.TsmdbServer; let client: MongoClient; let db: Db; beforeAll(async () => { - server = new congodb.CongoServer({ port: 27117 }); + server = new tsmdb.TsmdbServer({ port: 27117 }); await server.start(); client = new MongoClient('mongodb://127.0.0.1:27117'); @@ -355,14 +355,14 @@ test('should insert and find user', async () => { ```typescript import { expect, tap } from '@git.zone/tstest/tapbundle'; -import { congodb } from '@push.rocks/smartmongo'; +import { tsmdb } from '@push.rocks/smartmongo'; import { MongoClient } from 'mongodb'; -let server: congodb.CongoServer; +let server: tsmdb.TsmdbServer; let client: MongoClient; tap.test('setup', async () => { - server = new congodb.CongoServer({ port: 27117 }); + server = new tsmdb.TsmdbServer({ port: 27117 }); await server.start(); client = new MongoClient('mongodb://127.0.0.1:27117'); await client.connect(); @@ -401,7 +401,7 @@ export default tap.start(); ## 🏗️ Architecture -### CongoDB Wire Protocol Stack +### TsmDB Wire Protocol Stack ``` ┌─────────────────────────────────────────────────────────────┐ @@ -411,7 +411,7 @@ export default tap.start(); │ TCP + OP_MSG/BSON ▼ ┌─────────────────────────────────────────────────────────────┐ -│ CongoServer │ +│ TsmdbServer │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │ │ │ WireProtocol │→ │CommandRouter │→ │ Handlers │ │ │ │ (OP_MSG) │ │ │ │ (Find, Insert..) │ │ diff --git a/test/test.congodb.ts b/test/test.tsmdb.ts similarity index 81% rename from test/test.congodb.ts rename to test/test.tsmdb.ts index b1c17d1..3e0e7fd 100644 --- a/test/test.congodb.ts +++ b/test/test.tsmdb.ts @@ -2,9 +2,9 @@ import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as smartmongo from '../ts/index.js'; import { MongoClient, Db, Collection } from 'mongodb'; -const { congodb } = smartmongo; +const { tsmdb } = smartmongo; -let server: smartmongo.congodb.CongoServer; +let server: smartmongo.tsmdb.TsmdbServer; let client: MongoClient; let db: Db; @@ -12,13 +12,13 @@ let db: Db; // Server Startup // ============================================================================ -tap.test('congodb: should start the server', async () => { - server = new congodb.CongoServer({ port: 27117 }); // Use non-standard port for tests +tap.test('tsmdb: should start the server', async () => { + server = new tsmdb.TsmdbServer({ port: 27117 }); // Use non-standard port for tests await server.start(); expect(server.running).toBeTrue(); }); -tap.test('congodb: should connect with official MongoClient', async () => { +tap.test('tsmdb: should connect with official MongoClient', async () => { client = new MongoClient('mongodb://127.0.0.1:27117', { directConnection: true, serverSelectionTimeoutMS: 5000, @@ -27,7 +27,7 @@ tap.test('congodb: should connect with official MongoClient', async () => { expect(client).toBeTruthy(); }); -tap.test('congodb: should get a database instance', async () => { +tap.test('tsmdb: should get a database instance', async () => { db = client.db('testdb'); expect(db).toBeTruthy(); expect(db.databaseName).toEqual('testdb'); @@ -37,7 +37,7 @@ tap.test('congodb: should get a database instance', async () => { // Basic CRUD Tests // ============================================================================ -tap.test('congodb: insertOne - should insert a document', async () => { +tap.test('tsmdb: insertOne - should insert a document', async () => { const collection = db.collection('users'); const result = await collection.insertOne({ name: 'John Doe', @@ -49,7 +49,7 @@ tap.test('congodb: insertOne - should insert a document', async () => { expect(result.insertedId).toBeTruthy(); }); -tap.test('congodb: insertMany - should insert multiple documents', async () => { +tap.test('tsmdb: insertMany - should insert multiple documents', async () => { const collection = db.collection('users'); const result = await collection.insertMany([ { name: 'Jane Doe', email: 'jane@example.com', age: 25 }, @@ -62,7 +62,7 @@ tap.test('congodb: insertMany - should insert multiple documents', async () => { expect(Object.keys(result.insertedIds).length).toEqual(3); }); -tap.test('congodb: findOne - should find a single document', async () => { +tap.test('tsmdb: findOne - should find a single document', async () => { const collection = db.collection('users'); const doc = await collection.findOne({ name: 'John Doe' }); @@ -71,14 +71,14 @@ tap.test('congodb: findOne - should find a single document', async () => { expect(doc!.email).toEqual('john@example.com'); }); -tap.test('congodb: find - should find multiple documents', async () => { +tap.test('tsmdb: find - should find multiple documents', async () => { const collection = db.collection('users'); const docs = await collection.find({ age: { $gte: 28 } }).toArray(); expect(docs.length).toEqual(3); }); -tap.test('congodb: updateOne - should update a single document', async () => { +tap.test('tsmdb: updateOne - should update a single document', async () => { const collection = db.collection('users'); const result = await collection.updateOne( { name: 'John Doe' }, @@ -93,7 +93,7 @@ tap.test('congodb: updateOne - should update a single document', async () => { expect(updated!.age).toEqual(31); }); -tap.test('congodb: updateMany - should update multiple documents', async () => { +tap.test('tsmdb: updateMany - should update multiple documents', async () => { const collection = db.collection('users'); const result = await collection.updateMany( { age: { $gte: 30 } }, @@ -105,7 +105,7 @@ tap.test('congodb: updateMany - should update multiple documents', async () => { expect(result.modifiedCount).toEqual(2); }); -tap.test('congodb: deleteOne - should delete a single document', async () => { +tap.test('tsmdb: deleteOne - should delete a single document', async () => { const collection = db.collection('users'); const result = await collection.deleteOne({ name: 'Bob Smith' }); @@ -113,7 +113,7 @@ tap.test('congodb: deleteOne - should delete a single document', async () => { expect(result.deletedCount).toEqual(1); }); -tap.test('congodb: deleteMany - should delete multiple documents', async () => { +tap.test('tsmdb: deleteMany - should delete multiple documents', async () => { const collection = db.collection('users'); // First add some test docs to delete @@ -132,32 +132,32 @@ tap.test('congodb: deleteMany - should delete multiple documents', async () => { // Query Operator Tests // ============================================================================ -tap.test('congodb: query - $eq operator', async () => { +tap.test('tsmdb: query - $eq operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ name: { $eq: 'Jane Doe' } }).toArray(); expect(docs.length).toEqual(1); expect(docs[0].name).toEqual('Jane Doe'); }); -tap.test('congodb: query - $ne operator', async () => { +tap.test('tsmdb: query - $ne operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ name: { $ne: 'Jane Doe' } }).toArray(); expect(docs.every(d => d.name !== 'Jane Doe')).toBeTrue(); }); -tap.test('congodb: query - $gt and $lt operators', async () => { +tap.test('tsmdb: query - $gt and $lt operators', async () => { const collection = db.collection('users'); const docs = await collection.find({ age: { $gt: 25, $lt: 35 } }).toArray(); expect(docs.every(d => d.age > 25 && d.age < 35)).toBeTrue(); }); -tap.test('congodb: query - $in operator', async () => { +tap.test('tsmdb: query - $in operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ name: { $in: ['Jane Doe', 'Alice Johnson'] } }).toArray(); expect(docs.length).toEqual(2); }); -tap.test('congodb: query - $or operator', async () => { +tap.test('tsmdb: query - $or operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ $or: [ @@ -168,7 +168,7 @@ tap.test('congodb: query - $or operator', async () => { expect(docs.length).toBeGreaterThanOrEqual(1); }); -tap.test('congodb: query - $and operator', async () => { +tap.test('tsmdb: query - $and operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ $and: [ @@ -179,7 +179,7 @@ tap.test('congodb: query - $and operator', async () => { expect(docs.every(d => d.age >= 25 && d.age <= 30)).toBeTrue(); }); -tap.test('congodb: query - $exists operator', async () => { +tap.test('tsmdb: query - $exists operator', async () => { const collection = db.collection('users'); const docs = await collection.find({ senior: { $exists: true } }).toArray(); expect(docs.every(d => 'senior' in d)).toBeTrue(); @@ -189,7 +189,7 @@ tap.test('congodb: query - $exists operator', async () => { // Update Operator Tests // ============================================================================ -tap.test('congodb: update - $inc operator', async () => { +tap.test('tsmdb: update - $inc operator', async () => { const collection = db.collection('users'); await collection.updateOne( { name: 'Jane Doe' }, @@ -200,7 +200,7 @@ tap.test('congodb: update - $inc operator', async () => { expect(updated!.age).toEqual(26); }); -tap.test('congodb: update - $unset operator', async () => { +tap.test('tsmdb: update - $unset operator', async () => { const collection = db.collection('users'); await collection.updateOne( { name: 'Jane Doe' }, @@ -211,7 +211,7 @@ tap.test('congodb: update - $unset operator', async () => { expect('senior' in updated!).toBeFalse(); }); -tap.test('congodb: update - $push operator', async () => { +tap.test('tsmdb: update - $push operator', async () => { const collection = db.collection('users'); await collection.updateOne( { name: 'Jane Doe' }, @@ -227,7 +227,7 @@ tap.test('congodb: update - $push operator', async () => { expect(updated!.tags).toContain('tester'); }); -tap.test('congodb: update - $pull operator', async () => { +tap.test('tsmdb: update - $pull operator', async () => { const collection = db.collection('users'); await collection.updateOne( { name: 'Jane Doe' }, @@ -238,7 +238,7 @@ tap.test('congodb: update - $pull operator', async () => { expect(updated!.tags).not.toContain('tester'); }); -tap.test('congodb: update - upsert creates new document', async () => { +tap.test('tsmdb: update - upsert creates new document', async () => { const collection = db.collection('users'); const result = await collection.updateOne( { name: 'New User' }, @@ -258,7 +258,7 @@ tap.test('congodb: update - upsert creates new document', async () => { // Cursor Tests // ============================================================================ -tap.test('congodb: cursor - sort', async () => { +tap.test('tsmdb: cursor - sort', async () => { const collection = db.collection('users'); const docs = await collection.find({}).sort({ age: -1 }).toArray(); @@ -269,13 +269,13 @@ tap.test('congodb: cursor - sort', async () => { } }); -tap.test('congodb: cursor - limit', async () => { +tap.test('tsmdb: cursor - limit', async () => { const collection = db.collection('users'); const docs = await collection.find({}).limit(2).toArray(); expect(docs.length).toBeLessThanOrEqual(2); }); -tap.test('congodb: cursor - skip', async () => { +tap.test('tsmdb: cursor - skip', async () => { const collection = db.collection('users'); const allDocs = await collection.find({}).toArray(); const skippedDocs = await collection.find({}).skip(1).toArray(); @@ -283,7 +283,7 @@ tap.test('congodb: cursor - skip', async () => { expect(skippedDocs.length).toEqual(Math.max(0, allDocs.length - 1)); }); -tap.test('congodb: cursor - project', async () => { +tap.test('tsmdb: cursor - project', async () => { const collection = db.collection('users'); const docs = await collection.find({}).project({ name: 1, _id: 0 }).toArray(); @@ -296,7 +296,7 @@ tap.test('congodb: cursor - project', async () => { // FindOneAnd* Tests // ============================================================================ -tap.test('congodb: findOneAndUpdate - returns updated document', async () => { +tap.test('tsmdb: findOneAndUpdate - returns updated document', async () => { const collection = db.collection('users'); const result = await collection.findOneAndUpdate( { name: 'Jane Doe' }, @@ -308,7 +308,7 @@ tap.test('congodb: findOneAndUpdate - returns updated document', async () => { expect(result!.status).toEqual('active'); }); -tap.test('congodb: findOneAndDelete - returns deleted document', async () => { +tap.test('tsmdb: findOneAndDelete - returns deleted document', async () => { const collection = db.collection('users'); // Insert a temp doc to delete @@ -328,19 +328,19 @@ tap.test('congodb: findOneAndDelete - returns deleted document', async () => { // Count and Distinct Tests // ============================================================================ -tap.test('congodb: countDocuments - counts matching documents', async () => { +tap.test('tsmdb: countDocuments - counts matching documents', async () => { const collection = db.collection('users'); const count = await collection.countDocuments({ age: { $gte: 25 } }); expect(count).toBeGreaterThan(0); }); -tap.test('congodb: estimatedDocumentCount - returns total count', async () => { +tap.test('tsmdb: estimatedDocumentCount - returns total count', async () => { const collection = db.collection('users'); const count = await collection.estimatedDocumentCount(); expect(count).toBeGreaterThan(0); }); -tap.test('congodb: distinct - returns unique values', async () => { +tap.test('tsmdb: distinct - returns unique values', async () => { const collection = db.collection('users'); const names = await collection.distinct('name'); @@ -353,7 +353,7 @@ tap.test('congodb: distinct - returns unique values', async () => { // Index Tests // ============================================================================ -tap.test('congodb: createIndex - creates a single index', async () => { +tap.test('tsmdb: createIndex - creates a single index', async () => { const collection = db.collection('users'); const indexName = await collection.createIndex({ email: 1 }); @@ -361,14 +361,14 @@ tap.test('congodb: createIndex - creates a single index', async () => { expect(indexName).toContain('email'); }); -tap.test('congodb: createIndex - creates compound index', async () => { +tap.test('tsmdb: createIndex - creates compound index', async () => { const collection = db.collection('users'); const indexName = await collection.createIndex({ name: 1, age: -1 }); expect(indexName).toBeTruthy(); }); -tap.test('congodb: listIndexes - lists all indexes', async () => { +tap.test('tsmdb: listIndexes - lists all indexes', async () => { const collection = db.collection('users'); const indexes = await collection.listIndexes().toArray(); @@ -376,7 +376,7 @@ tap.test('congodb: listIndexes - lists all indexes', async () => { expect(indexes.some(i => i.name === '_id_')).toBeTrue(); }); -tap.test('congodb: dropIndex - drops an index', async () => { +tap.test('tsmdb: dropIndex - drops an index', async () => { const collection = db.collection('users'); const indexName = await collection.createIndex({ toDropField: 1 }); @@ -390,7 +390,7 @@ tap.test('congodb: dropIndex - drops an index', async () => { // Aggregation Tests // ============================================================================ -tap.test('congodb: aggregate - $match stage', async () => { +tap.test('tsmdb: aggregate - $match stage', async () => { const collection = db.collection('users'); const results = await collection.aggregate([ { $match: { age: { $gte: 25 } } } @@ -400,7 +400,7 @@ tap.test('congodb: aggregate - $match stage', async () => { expect(results.every(d => d.age >= 25)).toBeTrue(); }); -tap.test('congodb: aggregate - $project stage', async () => { +tap.test('tsmdb: aggregate - $project stage', async () => { const collection = db.collection('users'); const results = await collection.aggregate([ { $project: { name: 1, _id: 0 } } @@ -411,7 +411,7 @@ tap.test('congodb: aggregate - $project stage', async () => { expect(results[0].email).toBeUndefined(); }); -tap.test('congodb: aggregate - $sort stage', async () => { +tap.test('tsmdb: aggregate - $sort stage', async () => { const collection = db.collection('users'); const results = await collection.aggregate([ { $match: { age: { $exists: true } } }, @@ -423,7 +423,7 @@ tap.test('congodb: aggregate - $sort stage', async () => { } }); -tap.test('congodb: aggregate - $group stage', async () => { +tap.test('tsmdb: aggregate - $group stage', async () => { const collection = db.collection('users'); // Add some categorized data @@ -445,7 +445,7 @@ tap.test('congodb: aggregate - $group stage', async () => { expect(groupB!.total).toEqual(30); }); -tap.test('congodb: aggregate - $limit and $skip stages', async () => { +tap.test('tsmdb: aggregate - $limit and $skip stages', async () => { const collection = db.collection('users'); const results = await collection.aggregate([ { $skip: 1 }, @@ -459,7 +459,7 @@ tap.test('congodb: aggregate - $limit and $skip stages', async () => { // Bulk Operations Tests // ============================================================================ -tap.test('congodb: bulkWrite - executes multiple operations', async () => { +tap.test('tsmdb: bulkWrite - executes multiple operations', async () => { const collection = db.collection('bulktest'); const result = await collection.bulkWrite([ @@ -476,18 +476,18 @@ tap.test('congodb: bulkWrite - executes multiple operations', async () => { // Database Operations Tests // ============================================================================ -tap.test('congodb: listCollections - lists all collections', async () => { +tap.test('tsmdb: listCollections - lists all collections', async () => { const collections = await db.listCollections().toArray(); expect(collections.length).toBeGreaterThan(0); }); -tap.test('congodb: createCollection - creates a new collection', async () => { +tap.test('tsmdb: createCollection - creates a new collection', async () => { await db.createCollection('newcollection'); const collections = await db.listCollections().toArray(); expect(collections.some(c => c.name === 'newcollection')).toBeTrue(); }); -tap.test('congodb: dropCollection - drops a collection', async () => { +tap.test('tsmdb: dropCollection - drops a collection', async () => { await db.createCollection('todrop'); await db.dropCollection('todrop'); const collections = await db.listCollections().toArray(); @@ -498,20 +498,20 @@ tap.test('congodb: dropCollection - drops a collection', async () => { // Admin Tests // ============================================================================ -tap.test('congodb: admin - listDatabases', async () => { +tap.test('tsmdb: admin - listDatabases', async () => { const admin = client.db().admin(); const result = await admin.listDatabases(); expect(result.ok).toEqual(1); expect(result.databases).toBeArray(); }); -tap.test('congodb: admin - serverStatus', async () => { +tap.test('tsmdb: admin - serverStatus', async () => { const admin = client.db().admin(); const status = await admin.serverStatus(); expect(status.ok).toEqual(1); }); -tap.test('congodb: admin - ping', async () => { +tap.test('tsmdb: admin - ping', async () => { const admin = client.db().admin(); const result = await admin.ping(); expect(result.ok).toEqual(1); @@ -521,7 +521,7 @@ tap.test('congodb: admin - ping', async () => { // Replace Operations Tests // ============================================================================ -tap.test('congodb: replaceOne - replaces entire document', async () => { +tap.test('tsmdb: replaceOne - replaces entire document', async () => { const collection = db.collection('replacetest'); await collection.insertOne({ name: 'Original', field1: 'value1', field2: 'value2' }); @@ -540,7 +540,7 @@ tap.test('congodb: replaceOne - replaces entire document', async () => { expect(replaced!.field2).toBeUndefined(); }); -tap.test('congodb: findOneAndReplace - returns replaced document', async () => { +tap.test('tsmdb: findOneAndReplace - returns replaced document', async () => { const collection = db.collection('replacetest'); await collection.insertOne({ name: 'ToReplace', data: 'old' }); @@ -558,12 +558,12 @@ tap.test('congodb: findOneAndReplace - returns replaced document', async () => { // Cleanup // ============================================================================ -tap.test('congodb: cleanup - drop database', async () => { +tap.test('tsmdb: cleanup - drop database', async () => { const result = await db.dropDatabase(); expect(result).toBeTrue(); }); -tap.test('congodb: cleanup - close client and server', async () => { +tap.test('tsmdb: cleanup - close client and server', async () => { await client.close(); await server.stop(); expect(server.running).toBeFalse(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index c144319..a0a638b 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartmongo', - version: '2.2.0', + version: '3.0.0', description: 'A module for creating and managing a local MongoDB instance for testing purposes.' } diff --git a/ts/index.ts b/ts/index.ts index 6321697..fb57f62 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,8 +1,8 @@ import { commitinfo } from './00_commitinfo_data.js'; import * as plugins from './smartmongo.plugins.js'; -// Export CongoDB module -export * as congodb from './congodb/index.js'; +// Export TsmDB module +export * as tsmdb from './tsmdb/index.js'; export class SmartMongo { // STATIC diff --git a/ts/congodb/engine/AggregationEngine.ts b/ts/tsmdb/engine/AggregationEngine.ts similarity index 99% rename from ts/congodb/engine/AggregationEngine.ts rename to ts/tsmdb/engine/AggregationEngine.ts index c6dc2d1..ec5f663 100644 --- a/ts/congodb/engine/AggregationEngine.ts +++ b/ts/tsmdb/engine/AggregationEngine.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { Document, IStoredDocument, IAggregateOptions } from '../types/interfaces.js'; // Import mingo Aggregator diff --git a/ts/congodb/engine/IndexEngine.ts b/ts/tsmdb/engine/IndexEngine.ts similarity index 97% rename from ts/congodb/engine/IndexEngine.ts rename to ts/tsmdb/engine/IndexEngine.ts index 7af8994..4c2228a 100644 --- a/ts/congodb/engine/IndexEngine.ts +++ b/ts/tsmdb/engine/IndexEngine.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from '../storage/IStorageAdapter.js'; import type { Document, @@ -7,7 +7,7 @@ import type { IIndexInfo, ICreateIndexOptions, } from '../types/interfaces.js'; -import { CongoDuplicateKeyError, CongoIndexError } from '../errors/CongoErrors.js'; +import { TsmdbDuplicateKeyError, TsmdbIndexError } from '../errors/TsmdbErrors.js'; import { QueryEngine } from './QueryEngine.js'; /** @@ -116,7 +116,7 @@ export class IndexEngine { const keyStr = JSON.stringify(keyValue); if (indexData.unique && indexData.entries.has(keyStr)) { - throw new CongoDuplicateKeyError( + throw new TsmdbDuplicateKeyError( `E11000 duplicate key error index: ${this.dbName}.${this.collName}.$${name}`, key as Record, keyValue @@ -148,11 +148,11 @@ export class IndexEngine { await this.initialize(); if (name === '_id_') { - throw new CongoIndexError('cannot drop _id index'); + throw new TsmdbIndexError('cannot drop _id index'); } if (!this.indexes.has(name)) { - throw new CongoIndexError(`index not found: ${name}`); + throw new TsmdbIndexError(`index not found: ${name}`); } this.indexes.delete(name); @@ -215,7 +215,7 @@ export class IndexEngine { if (indexData.unique) { const existing = indexData.entries.get(keyStr); if (existing && existing.size > 0) { - throw new CongoDuplicateKeyError( + throw new TsmdbDuplicateKeyError( `E11000 duplicate key error collection: ${this.dbName}.${this.collName} index: ${name}`, indexData.key as Record, keyValue @@ -260,7 +260,7 @@ export class IndexEngine { if (indexData.unique) { const existing = indexData.entries.get(newKeyStr); if (existing && existing.size > 0) { - throw new CongoDuplicateKeyError( + throw new TsmdbDuplicateKeyError( `E11000 duplicate key error collection: ${this.dbName}.${this.collName} index: ${name}`, indexData.key as Record, newKeyValue diff --git a/ts/congodb/engine/QueryEngine.ts b/ts/tsmdb/engine/QueryEngine.ts similarity index 99% rename from ts/congodb/engine/QueryEngine.ts rename to ts/tsmdb/engine/QueryEngine.ts index cb0d657..d290876 100644 --- a/ts/congodb/engine/QueryEngine.ts +++ b/ts/tsmdb/engine/QueryEngine.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { Document, IStoredDocument, ISortSpecification, ISortDirection } from '../types/interfaces.js'; // Import mingo Query class diff --git a/ts/congodb/engine/TransactionEngine.ts b/ts/tsmdb/engine/TransactionEngine.ts similarity index 92% rename from ts/congodb/engine/TransactionEngine.ts rename to ts/tsmdb/engine/TransactionEngine.ts index 3683cc4..c3f19f2 100644 --- a/ts/congodb/engine/TransactionEngine.ts +++ b/ts/tsmdb/engine/TransactionEngine.ts @@ -1,7 +1,7 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from '../storage/IStorageAdapter.js'; import type { Document, IStoredDocument, ITransactionOptions } from '../types/interfaces.js'; -import { CongoTransactionError, CongoWriteConflictError } from '../errors/CongoErrors.js'; +import { TsmdbTransactionError, TsmdbWriteConflictError } from '../errors/TsmdbErrors.js'; /** * Transaction state @@ -70,7 +70,7 @@ export class TransactionEngine { async getSnapshot(txnId: string, dbName: string, collName: string): Promise { const txn = this.transactions.get(txnId); if (!txn || txn.status !== 'active') { - throw new CongoTransactionError('Transaction is not active'); + throw new TsmdbTransactionError('Transaction is not active'); } const ns = `${dbName}.${collName}`; @@ -148,7 +148,7 @@ export class TransactionEngine { recordInsert(txnId: string, dbName: string, collName: string, doc: IStoredDocument): void { const txn = this.transactions.get(txnId); if (!txn || txn.status !== 'active') { - throw new CongoTransactionError('Transaction is not active'); + throw new TsmdbTransactionError('Transaction is not active'); } const ns = `${dbName}.${collName}`; @@ -174,7 +174,7 @@ export class TransactionEngine { ): void { const txn = this.transactions.get(txnId); if (!txn || txn.status !== 'active') { - throw new CongoTransactionError('Transaction is not active'); + throw new TsmdbTransactionError('Transaction is not active'); } const ns = `${dbName}.${collName}`; @@ -203,7 +203,7 @@ export class TransactionEngine { recordDelete(txnId: string, dbName: string, collName: string, doc: IStoredDocument): void { const txn = this.transactions.get(txnId); if (!txn || txn.status !== 'active') { - throw new CongoTransactionError('Transaction is not active'); + throw new TsmdbTransactionError('Transaction is not active'); } const ns = `${dbName}.${collName}`; @@ -231,10 +231,10 @@ export class TransactionEngine { async commitTransaction(txnId: string): Promise { const txn = this.transactions.get(txnId); if (!txn) { - throw new CongoTransactionError('Transaction not found'); + throw new TsmdbTransactionError('Transaction not found'); } if (txn.status !== 'active') { - throw new CongoTransactionError(`Cannot commit transaction in state: ${txn.status}`); + throw new TsmdbTransactionError(`Cannot commit transaction in state: ${txn.status}`); } // Check for write conflicts @@ -245,7 +245,7 @@ export class TransactionEngine { const hasConflicts = await this.storage.hasConflicts(dbName, collName, ids, txn.startTime); if (hasConflicts) { txn.status = 'aborted'; - throw new CongoWriteConflictError(); + throw new TsmdbWriteConflictError(); } } @@ -281,7 +281,7 @@ export class TransactionEngine { async abortTransaction(txnId: string): Promise { const txn = this.transactions.get(txnId); if (!txn) { - throw new CongoTransactionError('Transaction not found'); + throw new TsmdbTransactionError('Transaction not found'); } if (txn.status !== 'active') { // Already committed or aborted, just return @@ -336,7 +336,7 @@ export class TransactionEngine { await this.abortTransaction(txnId); this.endTransaction(txnId); - if (error instanceof CongoWriteConflictError && attempt < maxRetries - 1) { + if (error instanceof TsmdbWriteConflictError && attempt < maxRetries - 1) { // Retry on write conflict lastError = error; continue; @@ -346,6 +346,6 @@ export class TransactionEngine { } } - throw lastError || new CongoTransactionError('Transaction failed after max retries'); + throw lastError || new TsmdbTransactionError('Transaction failed after max retries'); } } diff --git a/ts/congodb/engine/UpdateEngine.ts b/ts/tsmdb/engine/UpdateEngine.ts similarity index 99% rename from ts/congodb/engine/UpdateEngine.ts rename to ts/tsmdb/engine/UpdateEngine.ts index 1b6b419..aef6699 100644 --- a/ts/congodb/engine/UpdateEngine.ts +++ b/ts/tsmdb/engine/UpdateEngine.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { Document, IStoredDocument } from '../types/interfaces.js'; import { QueryEngine } from './QueryEngine.js'; diff --git a/ts/congodb/errors/CongoErrors.ts b/ts/tsmdb/errors/TsmdbErrors.ts similarity index 64% rename from ts/congodb/errors/CongoErrors.ts rename to ts/tsmdb/errors/TsmdbErrors.ts index 1dc172f..20bd691 100644 --- a/ts/congodb/errors/CongoErrors.ts +++ b/ts/tsmdb/errors/TsmdbErrors.ts @@ -1,14 +1,14 @@ /** - * Base error class for all CongoDB errors + * Base error class for all TsmDB errors * Mirrors MongoDB driver error hierarchy */ -export class CongoError extends Error { +export class TsmdbError extends Error { public code?: number; public codeName?: string; constructor(message: string, code?: number, codeName?: string) { super(message); - this.name = 'CongoError'; + this.name = 'TsmdbError'; this.code = code; this.codeName = codeName; Object.setPrototypeOf(this, new.target.prototype); @@ -18,33 +18,33 @@ export class CongoError extends Error { /** * Error thrown during connection issues */ -export class CongoConnectionError extends CongoError { +export class TsmdbConnectionError extends TsmdbError { constructor(message: string) { super(message); - this.name = 'CongoConnectionError'; + this.name = 'TsmdbConnectionError'; } } /** * Error thrown when an operation times out */ -export class CongoTimeoutError extends CongoError { +export class TsmdbTimeoutError extends TsmdbError { constructor(message: string) { super(message, 50, 'MaxTimeMSExpired'); - this.name = 'CongoTimeoutError'; + this.name = 'TsmdbTimeoutError'; } } /** * Error thrown during write operations */ -export class CongoWriteError extends CongoError { +export class TsmdbWriteError extends TsmdbError { public writeErrors?: IWriteError[]; public result?: any; constructor(message: string, code?: number, writeErrors?: IWriteError[]) { super(message, code); - this.name = 'CongoWriteError'; + this.name = 'TsmdbWriteError'; this.writeErrors = writeErrors; } } @@ -52,13 +52,13 @@ export class CongoWriteError extends CongoError { /** * Error thrown for duplicate key violations */ -export class CongoDuplicateKeyError extends CongoWriteError { +export class TsmdbDuplicateKeyError extends TsmdbWriteError { public keyPattern?: Record; public keyValue?: Record; constructor(message: string, keyPattern?: Record, keyValue?: Record) { super(message, 11000); - this.name = 'CongoDuplicateKeyError'; + this.name = 'TsmdbDuplicateKeyError'; this.codeName = 'DuplicateKey'; this.keyPattern = keyPattern; this.keyValue = keyValue; @@ -68,13 +68,13 @@ export class CongoDuplicateKeyError extends CongoWriteError { /** * Error thrown for bulk write failures */ -export class CongoBulkWriteError extends CongoError { +export class TsmdbBulkWriteError extends TsmdbError { public writeErrors: IWriteError[]; public result: any; constructor(message: string, writeErrors: IWriteError[], result: any) { super(message, 65); - this.name = 'CongoBulkWriteError'; + this.name = 'TsmdbBulkWriteError'; this.writeErrors = writeErrors; this.result = result; } @@ -83,20 +83,20 @@ export class CongoBulkWriteError extends CongoError { /** * Error thrown during transaction operations */ -export class CongoTransactionError extends CongoError { +export class TsmdbTransactionError extends TsmdbError { constructor(message: string, code?: number) { super(message, code); - this.name = 'CongoTransactionError'; + this.name = 'TsmdbTransactionError'; } } /** * Error thrown when a transaction is aborted due to conflict */ -export class CongoWriteConflictError extends CongoTransactionError { +export class TsmdbWriteConflictError extends TsmdbTransactionError { constructor(message: string = 'Write conflict during transaction') { super(message, 112); - this.name = 'CongoWriteConflictError'; + this.name = 'TsmdbWriteConflictError'; this.codeName = 'WriteConflict'; } } @@ -104,20 +104,20 @@ export class CongoWriteConflictError extends CongoTransactionError { /** * Error thrown for invalid arguments */ -export class CongoArgumentError extends CongoError { +export class TsmdbArgumentError extends TsmdbError { constructor(message: string) { super(message); - this.name = 'CongoArgumentError'; + this.name = 'TsmdbArgumentError'; } } /** * Error thrown when an operation is not supported */ -export class CongoNotSupportedError extends CongoError { +export class TsmdbNotSupportedError extends TsmdbError { constructor(message: string) { super(message, 115); - this.name = 'CongoNotSupportedError'; + this.name = 'TsmdbNotSupportedError'; this.codeName = 'CommandNotSupported'; } } @@ -125,20 +125,20 @@ export class CongoNotSupportedError extends CongoError { /** * Error thrown when cursor is exhausted or closed */ -export class CongoCursorError extends CongoError { +export class TsmdbCursorError extends TsmdbError { constructor(message: string) { super(message); - this.name = 'CongoCursorError'; + this.name = 'TsmdbCursorError'; } } /** * Error thrown when a namespace (database.collection) is invalid */ -export class CongoNamespaceError extends CongoError { +export class TsmdbNamespaceError extends TsmdbError { constructor(message: string) { super(message, 73); - this.name = 'CongoNamespaceError'; + this.name = 'TsmdbNamespaceError'; this.codeName = 'InvalidNamespace'; } } @@ -146,10 +146,10 @@ export class CongoNamespaceError extends CongoError { /** * Error thrown when an index operation fails */ -export class CongoIndexError extends CongoError { +export class TsmdbIndexError extends TsmdbError { constructor(message: string, code?: number) { super(message, code || 86); - this.name = 'CongoIndexError'; + this.name = 'TsmdbIndexError'; } } @@ -164,18 +164,18 @@ export interface IWriteError { } /** - * Convert any error to a CongoError + * Convert any error to a TsmdbError */ -export function toCongoError(error: any): CongoError { - if (error instanceof CongoError) { +export function toTsmdbError(error: any): TsmdbError { + if (error instanceof TsmdbError) { return error; } - const congoError = new CongoError(error.message || String(error)); + const tsmdbError = new TsmdbError(error.message || String(error)); if (error.code) { - congoError.code = error.code; + tsmdbError.code = error.code; } if (error.codeName) { - congoError.codeName = error.codeName; + tsmdbError.codeName = error.codeName; } - return congoError; + return tsmdbError; } diff --git a/ts/congodb/index.ts b/ts/tsmdb/index.ts similarity index 73% rename from ts/congodb/index.ts rename to ts/tsmdb/index.ts index 1514338..78bf1db 100644 --- a/ts/congodb/index.ts +++ b/ts/tsmdb/index.ts @@ -1,8 +1,8 @@ -// CongoDB - MongoDB Wire Protocol compatible in-memory database server -// Use the official MongoDB driver to connect to CongoServer +// TsmDB - MongoDB Wire Protocol compatible in-memory database server +// Use the official MongoDB driver to connect to TsmdbServer // Re-export plugins for external use -import * as plugins from './congodb.plugins.js'; +import * as plugins from './tsmdb.plugins.js'; export { plugins }; // Export BSON types for convenience @@ -12,7 +12,7 @@ export { ObjectId, Binary, Timestamp, Long, Decimal128, UUID } from 'bson'; export * from './types/interfaces.js'; // Export errors -export * from './errors/CongoErrors.js'; +export * from './errors/TsmdbErrors.js'; // Export storage adapters export type { IStorageAdapter } from './storage/IStorageAdapter.js'; @@ -27,9 +27,9 @@ export { AggregationEngine } from './engine/AggregationEngine.js'; export { IndexEngine } from './engine/IndexEngine.js'; export { TransactionEngine } from './engine/TransactionEngine.js'; -// Export server (the main entry point for using CongoDB) -export { CongoServer } from './server/CongoServer.js'; -export type { ICongoServerOptions } from './server/CongoServer.js'; +// Export server (the main entry point for using TsmDB) +export { TsmdbServer } from './server/TsmdbServer.js'; +export type { ITsmdbServerOptions } from './server/TsmdbServer.js'; // Export wire protocol utilities (for advanced usage) export { WireProtocol } from './server/WireProtocol.js'; diff --git a/ts/congodb/server/CommandRouter.ts b/ts/tsmdb/server/CommandRouter.ts similarity index 96% rename from ts/congodb/server/CommandRouter.ts rename to ts/tsmdb/server/CommandRouter.ts index 2268e87..222d3c6 100644 --- a/ts/congodb/server/CommandRouter.ts +++ b/ts/tsmdb/server/CommandRouter.ts @@ -1,7 +1,7 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from '../storage/IStorageAdapter.js'; import type { IParsedCommand } from './WireProtocol.js'; -import type { CongoServer } from './CongoServer.js'; +import type { TsmdbServer } from './TsmdbServer.js'; // Import handlers import { HelloHandler } from './handlers/HelloHandler.js'; @@ -18,7 +18,7 @@ import { AdminHandler } from './handlers/AdminHandler.js'; */ export interface IHandlerContext { storage: IStorageAdapter; - server: CongoServer; + server: TsmdbServer; database: string; command: plugins.bson.Document; documentSequences?: Map; @@ -36,14 +36,14 @@ export interface ICommandHandler { */ export class CommandRouter { private storage: IStorageAdapter; - private server: CongoServer; + private server: TsmdbServer; private handlers: Map = new Map(); // Cursor state for getMore operations private cursors: Map = new Map(); private cursorIdCounter: bigint = BigInt(1); - constructor(storage: IStorageAdapter, server: CongoServer) { + constructor(storage: IStorageAdapter, server: TsmdbServer) { this.storage = storage; this.server = server; this.registerHandlers(); diff --git a/ts/congodb/server/CongoServer.ts b/ts/tsmdb/server/TsmdbServer.ts similarity index 94% rename from ts/congodb/server/CongoServer.ts rename to ts/tsmdb/server/TsmdbServer.ts index d781a1c..f8fda01 100644 --- a/ts/congodb/server/CongoServer.ts +++ b/ts/tsmdb/server/TsmdbServer.ts @@ -1,5 +1,5 @@ import * as net from 'net'; -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import { WireProtocol, OP_QUERY } from './WireProtocol.js'; import { CommandRouter } from './CommandRouter.js'; import { MemoryStorageAdapter } from '../storage/MemoryStorageAdapter.js'; @@ -9,7 +9,7 @@ import type { IStorageAdapter } from '../storage/IStorageAdapter.js'; /** * Server configuration options */ -export interface ICongoServerOptions { +export interface ITsmdbServerOptions { /** Port to listen on (default: 27017) */ port?: number; /** Host to bind to (default: 127.0.0.1) */ @@ -36,25 +36,25 @@ interface IConnectionState { } /** - * CongoServer - MongoDB Wire Protocol compatible server + * TsmdbServer - MongoDB Wire Protocol compatible server * * This server implements the MongoDB wire protocol (OP_MSG) to allow * official MongoDB drivers to connect and perform operations. * * @example * ```typescript - * import { CongoServer } from '@push.rocks/smartmongo/congodb'; + * import { TsmdbServer } from '@push.rocks/smartmongo/tsmdb'; * import { MongoClient } from 'mongodb'; * - * const server = new CongoServer({ port: 27017 }); + * const server = new TsmdbServer({ port: 27017 }); * await server.start(); * * const client = new MongoClient('mongodb://127.0.0.1:27017'); * await client.connect(); * ``` */ -export class CongoServer { - private options: Required; +export class TsmdbServer { + private options: Required; private server: net.Server | null = null; private storage: IStorageAdapter; private commandRouter: CommandRouter; @@ -63,7 +63,7 @@ export class CongoServer { private isRunning = false; private startTime: Date = new Date(); - constructor(options: ICongoServerOptions = {}) { + constructor(options: ITsmdbServerOptions = {}) { this.options = { port: options.port ?? 27017, host: options.host ?? '127.0.0.1', diff --git a/ts/congodb/server/WireProtocol.ts b/ts/tsmdb/server/WireProtocol.ts similarity index 99% rename from ts/congodb/server/WireProtocol.ts rename to ts/tsmdb/server/WireProtocol.ts index 30f4a09..3162038 100644 --- a/ts/congodb/server/WireProtocol.ts +++ b/ts/tsmdb/server/WireProtocol.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; /** * MongoDB Wire Protocol Implementation diff --git a/ts/congodb/server/handlers/AdminHandler.ts b/ts/tsmdb/server/handlers/AdminHandler.ts similarity index 98% rename from ts/congodb/server/handlers/AdminHandler.ts rename to ts/tsmdb/server/handlers/AdminHandler.ts index f2deb8e..b7f1bc0 100644 --- a/ts/congodb/server/handlers/AdminHandler.ts +++ b/ts/tsmdb/server/handlers/AdminHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; /** @@ -246,7 +246,7 @@ export class AdminHandler implements ICommandHandler { ok: 1, host: `${server.host}:${server.port}`, version: '7.0.0', - process: 'congodb', + process: 'tsmdb', pid: process.pid, uptime, uptimeMillis: uptime * 1000, @@ -269,7 +269,7 @@ export class AdminHandler implements ICommandHandler { numRequests: 0, }, storageEngine: { - name: 'congodb', + name: 'tsmdb', supportsCommittedReads: true, persistent: false, }, @@ -283,7 +283,7 @@ export class AdminHandler implements ICommandHandler { return { ok: 1, version: '7.0.0', - gitVersion: 'congodb', + gitVersion: 'tsmdb', modules: [], allocator: 'system', javascriptEngine: 'none', @@ -294,7 +294,7 @@ export class AdminHandler implements ICommandHandler { compiled: 'disabled', }, buildEnvironment: { - distmod: 'congodb', + distmod: 'tsmdb', distarch: process.arch, cc: '', ccflags: '', @@ -307,7 +307,7 @@ export class AdminHandler implements ICommandHandler { bits: 64, debug: false, maxBsonObjectSize: 16777216, - storageEngines: ['congodb'], + storageEngines: ['tsmdb'], }; } diff --git a/ts/congodb/server/handlers/AggregateHandler.ts b/ts/tsmdb/server/handlers/AggregateHandler.ts similarity index 99% rename from ts/congodb/server/handlers/AggregateHandler.ts rename to ts/tsmdb/server/handlers/AggregateHandler.ts index 0cd04fa..9f93f6c 100644 --- a/ts/congodb/server/handlers/AggregateHandler.ts +++ b/ts/tsmdb/server/handlers/AggregateHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext, ICursorState } from '../CommandRouter.js'; import { AggregationEngine } from '../../engine/AggregationEngine.js'; diff --git a/ts/congodb/server/handlers/DeleteHandler.ts b/ts/tsmdb/server/handlers/DeleteHandler.ts similarity index 98% rename from ts/congodb/server/handlers/DeleteHandler.ts rename to ts/tsmdb/server/handlers/DeleteHandler.ts index 2d172f3..4f21ea6 100644 --- a/ts/congodb/server/handlers/DeleteHandler.ts +++ b/ts/tsmdb/server/handlers/DeleteHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; import { QueryEngine } from '../../engine/QueryEngine.js'; diff --git a/ts/congodb/server/handlers/FindHandler.ts b/ts/tsmdb/server/handlers/FindHandler.ts similarity index 99% rename from ts/congodb/server/handlers/FindHandler.ts rename to ts/tsmdb/server/handlers/FindHandler.ts index e3f916a..a6655e2 100644 --- a/ts/congodb/server/handlers/FindHandler.ts +++ b/ts/tsmdb/server/handlers/FindHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext, ICursorState } from '../CommandRouter.js'; import { QueryEngine } from '../../engine/QueryEngine.js'; diff --git a/ts/congodb/server/handlers/HelloHandler.ts b/ts/tsmdb/server/handlers/HelloHandler.ts similarity index 97% rename from ts/congodb/server/handlers/HelloHandler.ts rename to ts/tsmdb/server/handlers/HelloHandler.ts index 274d940..77ac972 100644 --- a/ts/congodb/server/handlers/HelloHandler.ts +++ b/ts/tsmdb/server/handlers/HelloHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; /** diff --git a/ts/congodb/server/handlers/IndexHandler.ts b/ts/tsmdb/server/handlers/IndexHandler.ts similarity index 99% rename from ts/congodb/server/handlers/IndexHandler.ts rename to ts/tsmdb/server/handlers/IndexHandler.ts index 7f3f43d..d69d748 100644 --- a/ts/congodb/server/handlers/IndexHandler.ts +++ b/ts/tsmdb/server/handlers/IndexHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; import { IndexEngine } from '../../engine/IndexEngine.js'; diff --git a/ts/congodb/server/handlers/InsertHandler.ts b/ts/tsmdb/server/handlers/InsertHandler.ts similarity index 97% rename from ts/congodb/server/handlers/InsertHandler.ts rename to ts/tsmdb/server/handlers/InsertHandler.ts index a3577df..f2275c1 100644 --- a/ts/congodb/server/handlers/InsertHandler.ts +++ b/ts/tsmdb/server/handlers/InsertHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; /** diff --git a/ts/congodb/server/handlers/UpdateHandler.ts b/ts/tsmdb/server/handlers/UpdateHandler.ts similarity index 99% rename from ts/congodb/server/handlers/UpdateHandler.ts rename to ts/tsmdb/server/handlers/UpdateHandler.ts index c4958b2..846b447 100644 --- a/ts/congodb/server/handlers/UpdateHandler.ts +++ b/ts/tsmdb/server/handlers/UpdateHandler.ts @@ -1,4 +1,4 @@ -import * as plugins from '../../congodb.plugins.js'; +import * as plugins from '../../tsmdb.plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; import { QueryEngine } from '../../engine/QueryEngine.js'; import { UpdateEngine } from '../../engine/UpdateEngine.js'; diff --git a/ts/congodb/server/handlers/index.ts b/ts/tsmdb/server/handlers/index.ts similarity index 100% rename from ts/congodb/server/handlers/index.ts rename to ts/tsmdb/server/handlers/index.ts diff --git a/ts/congodb/server/index.ts b/ts/tsmdb/server/index.ts similarity index 71% rename from ts/congodb/server/index.ts rename to ts/tsmdb/server/index.ts index a792bd0..df2df28 100644 --- a/ts/congodb/server/index.ts +++ b/ts/tsmdb/server/index.ts @@ -1,7 +1,7 @@ // Server module exports -export { CongoServer } from './CongoServer.js'; -export type { ICongoServerOptions } from './CongoServer.js'; +export { TsmdbServer } from './TsmdbServer.js'; +export type { ITsmdbServerOptions } from './TsmdbServer.js'; export { WireProtocol } from './WireProtocol.js'; export { CommandRouter } from './CommandRouter.js'; export type { ICommandHandler, IHandlerContext, ICursorState } from './CommandRouter.js'; diff --git a/ts/congodb/storage/FileStorageAdapter.ts b/ts/tsmdb/storage/FileStorageAdapter.ts similarity index 99% rename from ts/congodb/storage/FileStorageAdapter.ts rename to ts/tsmdb/storage/FileStorageAdapter.ts index c7c01dc..61aa258 100644 --- a/ts/congodb/storage/FileStorageAdapter.ts +++ b/ts/tsmdb/storage/FileStorageAdapter.ts @@ -1,9 +1,9 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from './IStorageAdapter.js'; import type { IStoredDocument, IOpLogEntry, Document } from '../types/interfaces.js'; /** - * File-based storage adapter for CongoDB + * File-based storage adapter for TsmDB * Stores data in JSON files on disk for persistence */ export class FileStorageAdapter implements IStorageAdapter { diff --git a/ts/congodb/storage/IStorageAdapter.ts b/ts/tsmdb/storage/IStorageAdapter.ts similarity index 98% rename from ts/congodb/storage/IStorageAdapter.ts rename to ts/tsmdb/storage/IStorageAdapter.ts index 1dee845..280cdcc 100644 --- a/ts/congodb/storage/IStorageAdapter.ts +++ b/ts/tsmdb/storage/IStorageAdapter.ts @@ -1,8 +1,8 @@ -import type * as plugins from '../congodb.plugins.js'; +import type * as plugins from '../tsmdb.plugins.js'; import type { IStoredDocument, IOpLogEntry, Document } from '../types/interfaces.js'; /** - * Storage adapter interface for CongoDB + * Storage adapter interface for TsmDB * Implementations can provide different storage backends (memory, file, etc.) */ export interface IStorageAdapter { diff --git a/ts/congodb/storage/MemoryStorageAdapter.ts b/ts/tsmdb/storage/MemoryStorageAdapter.ts similarity index 99% rename from ts/congodb/storage/MemoryStorageAdapter.ts rename to ts/tsmdb/storage/MemoryStorageAdapter.ts index 92d8661..fe67e4e 100644 --- a/ts/congodb/storage/MemoryStorageAdapter.ts +++ b/ts/tsmdb/storage/MemoryStorageAdapter.ts @@ -1,9 +1,9 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from './IStorageAdapter.js'; import type { IStoredDocument, IOpLogEntry, Document } from '../types/interfaces.js'; /** - * In-memory storage adapter for CongoDB + * In-memory storage adapter for TsmDB * Optionally supports persistence to a file */ export class MemoryStorageAdapter implements IStorageAdapter { diff --git a/ts/congodb/storage/OpLog.ts b/ts/tsmdb/storage/OpLog.ts similarity index 99% rename from ts/congodb/storage/OpLog.ts rename to ts/tsmdb/storage/OpLog.ts index bddcfa5..cbabeee 100644 --- a/ts/congodb/storage/OpLog.ts +++ b/ts/tsmdb/storage/OpLog.ts @@ -1,4 +1,4 @@ -import * as plugins from '../congodb.plugins.js'; +import * as plugins from '../tsmdb.plugins.js'; import type { IStorageAdapter } from './IStorageAdapter.js'; import type { IOpLogEntry, Document, IResumeToken, ChangeStreamOperationType } from '../types/interfaces.js'; diff --git a/ts/congodb/congodb.plugins.ts b/ts/tsmdb/tsmdb.plugins.ts similarity index 100% rename from ts/congodb/congodb.plugins.ts rename to ts/tsmdb/tsmdb.plugins.ts diff --git a/ts/congodb/types/interfaces.ts b/ts/tsmdb/types/interfaces.ts similarity index 99% rename from ts/congodb/types/interfaces.ts rename to ts/tsmdb/types/interfaces.ts index f9abe28..7ae2b5b 100644 --- a/ts/congodb/types/interfaces.ts +++ b/ts/tsmdb/types/interfaces.ts @@ -1,4 +1,4 @@ -import type * as plugins from '../congodb.plugins.js'; +import type * as plugins from '../tsmdb.plugins.js'; // ============================================================================ // Document Types @@ -14,7 +14,7 @@ export interface WithId { // Client Options // ============================================================================ -export interface ICongoClientOptions { +export interface ITsmdbClientOptions { /** Storage adapter type: 'memory' or 'file' */ storageType?: 'memory' | 'file'; /** Path for file-based storage */ @@ -30,7 +30,7 @@ export interface ICongoClientOptions { // ============================================================================ export interface IParsedConnectionString { - protocol: 'congo'; + protocol: 'tsmdb'; storageType: 'memory' | 'file'; options: { persist?: string;