BREAKING CHANGE(tsmdb): rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user