BREAKING CHANGE(tsmdb): rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports

This commit is contained in:
2026-02-01 14:34:07 +00:00
parent 28e166ee35
commit a0df731bc0
32 changed files with 201 additions and 197 deletions

View File

@@ -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..) │ │