@objectql/driver-mongo 4.0.3 → 4.0.4
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +42 -0
- package/dist/index.d.ts +44 -1
- package/dist/index.js +134 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +147 -12
- package/test/index.test.ts +15 -13
- package/test/integration.test.ts +10 -10
- package/test/tck.test.ts +73 -0
- package/tsconfig.tsbuildinfo +1 -1
package/test/index.test.ts
CHANGED
|
@@ -22,6 +22,7 @@ const mockCollection = {
|
|
|
22
22
|
insertedCount: 2
|
|
23
23
|
}),
|
|
24
24
|
updateOne: jest.fn().mockResolvedValue({ modifiedCount: 1 }),
|
|
25
|
+
findOneAndUpdate: jest.fn().mockResolvedValue({ value: { _id: '123', name: 'Updated' } }),
|
|
25
26
|
deleteOne: jest.fn().mockResolvedValue({ deletedCount: 1 }),
|
|
26
27
|
countDocuments: jest.fn().mockResolvedValue(10)
|
|
27
28
|
};
|
|
@@ -437,20 +438,19 @@ describe('MongoDriver', () => {
|
|
|
437
438
|
data: { name: 'Updated User' }
|
|
438
439
|
};
|
|
439
440
|
|
|
440
|
-
mockCollection.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
name: 'Updated User'
|
|
441
|
+
mockCollection.findOneAndUpdate.mockResolvedValue({
|
|
442
|
+
value: {
|
|
443
|
+
_id: '123',
|
|
444
|
+
name: 'Updated User',
|
|
445
|
+
updated_at: new Date().toISOString()
|
|
446
|
+
}
|
|
447
447
|
});
|
|
448
448
|
|
|
449
449
|
const result = await driver.executeCommand(command);
|
|
450
450
|
|
|
451
451
|
expect(result.success).toBe(true);
|
|
452
452
|
expect(result.affected).toBe(1);
|
|
453
|
-
expect(mockCollection.
|
|
453
|
+
expect(mockCollection.findOneAndUpdate).toHaveBeenCalled();
|
|
454
454
|
});
|
|
455
455
|
|
|
456
456
|
it('should execute delete command', async () => {
|
|
@@ -504,11 +504,13 @@ describe('MongoDriver', () => {
|
|
|
504
504
|
]
|
|
505
505
|
};
|
|
506
506
|
|
|
507
|
-
mockCollection.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
mockCollection.findOneAndUpdate.mockResolvedValue({
|
|
508
|
+
value: {
|
|
509
|
+
_id: '1',
|
|
510
|
+
name: 'Updated 1',
|
|
511
|
+
updated_at: new Date().toISOString()
|
|
512
|
+
}
|
|
513
|
+
});
|
|
512
514
|
|
|
513
515
|
const result = await driver.executeCommand(command);
|
|
514
516
|
|
package/test/integration.test.ts
CHANGED
|
@@ -299,12 +299,12 @@ describe('MongoDriver Integration Tests', () => {
|
|
|
299
299
|
await driver.create('users', { name: 'Bob', status: 'pending' });
|
|
300
300
|
await driver.create('users', { name: 'Charlie', status: 'active' });
|
|
301
301
|
|
|
302
|
-
const
|
|
302
|
+
const result = await driver.updateMany('users',
|
|
303
303
|
[['status', '=', 'pending']],
|
|
304
304
|
{ status: 'active' }
|
|
305
305
|
);
|
|
306
306
|
|
|
307
|
-
expect(modifiedCount).toBe(2);
|
|
307
|
+
expect(result.modifiedCount).toBe(2);
|
|
308
308
|
|
|
309
309
|
const results = await driver.find('users', {
|
|
310
310
|
filters: [['status', '=', 'active']]
|
|
@@ -318,12 +318,12 @@ describe('MongoDriver Integration Tests', () => {
|
|
|
318
318
|
await driver.create('users', { name: 'Bob', score: 20, active: true });
|
|
319
319
|
await driver.create('users', { name: 'Charlie', score: 30, active: false });
|
|
320
320
|
|
|
321
|
-
const
|
|
321
|
+
const result = await driver.updateMany('users',
|
|
322
322
|
[['active', '=', true]],
|
|
323
323
|
{ $inc: { score: 5 } }
|
|
324
324
|
);
|
|
325
325
|
|
|
326
|
-
expect(modifiedCount).toBe(2);
|
|
326
|
+
expect(result.modifiedCount).toBe(2);
|
|
327
327
|
|
|
328
328
|
const alice = await driver.findOne('users', null as any, {
|
|
329
329
|
filters: [['name', '=', 'Alice']]
|
|
@@ -337,11 +337,11 @@ describe('MongoDriver Integration Tests', () => {
|
|
|
337
337
|
await driver.create('users', { name: 'Bob', status: 'inactive' });
|
|
338
338
|
await driver.create('users', { name: 'Charlie', status: 'active' });
|
|
339
339
|
|
|
340
|
-
const
|
|
340
|
+
const result = await driver.deleteMany('users',
|
|
341
341
|
[['status', '=', 'inactive']]
|
|
342
342
|
);
|
|
343
343
|
|
|
344
|
-
expect(deletedCount).toBe(2);
|
|
344
|
+
expect(result.deletedCount).toBe(2);
|
|
345
345
|
|
|
346
346
|
const remaining = await driver.count('users', []);
|
|
347
347
|
expect(remaining).toBe(1);
|
|
@@ -352,16 +352,16 @@ describe('MongoDriver Integration Tests', () => {
|
|
|
352
352
|
const result = await driver.createMany('users', []);
|
|
353
353
|
expect(result).toBeDefined();
|
|
354
354
|
|
|
355
|
-
const
|
|
355
|
+
const updateResult = await driver.updateMany('users',
|
|
356
356
|
[['name', '=', 'nonexistent']],
|
|
357
357
|
{ status: 'updated' }
|
|
358
358
|
);
|
|
359
|
-
expect(
|
|
359
|
+
expect(updateResult.modifiedCount).toBe(0);
|
|
360
360
|
|
|
361
|
-
const
|
|
361
|
+
const deleteResult = await driver.deleteMany('users',
|
|
362
362
|
[['name', '=', 'nonexistent']]
|
|
363
363
|
);
|
|
364
|
-
expect(
|
|
364
|
+
expect(deleteResult.deletedCount).toBe(0);
|
|
365
365
|
});
|
|
366
366
|
});
|
|
367
367
|
|
package/test/tck.test.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectQL MongoDB Driver TCK Tests
|
|
3
|
+
* Copyright (c) 2026-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MongoDB Driver TCK (Technology Compatibility Kit) Tests
|
|
11
|
+
*
|
|
12
|
+
* This test suite verifies that the MongoDB driver passes all TCK requirements.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { runDriverTCK } from '@objectql/driver-tck';
|
|
16
|
+
import { MongoDriver } from '../src';
|
|
17
|
+
import { MongoMemoryReplSet } from 'mongodb-memory-server';
|
|
18
|
+
|
|
19
|
+
describe('MongoDriver TCK Compliance', () => {
|
|
20
|
+
let mongoServer: MongoMemoryReplSet;
|
|
21
|
+
let driver: MongoDriver;
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
// Start MongoDB Memory Server with replica set (required for transactions)
|
|
25
|
+
mongoServer = await MongoMemoryReplSet.create({
|
|
26
|
+
replSet: { count: 1, storageEngine: 'wiredTiger' }
|
|
27
|
+
});
|
|
28
|
+
}, 120000);
|
|
29
|
+
|
|
30
|
+
afterAll(async () => {
|
|
31
|
+
if (driver) {
|
|
32
|
+
await driver.disconnect();
|
|
33
|
+
}
|
|
34
|
+
if (mongoServer) {
|
|
35
|
+
await mongoServer.stop();
|
|
36
|
+
}
|
|
37
|
+
}, 60000);
|
|
38
|
+
|
|
39
|
+
runDriverTCK(
|
|
40
|
+
() => {
|
|
41
|
+
const uri = mongoServer.getUri();
|
|
42
|
+
driver = new MongoDriver({
|
|
43
|
+
url: uri,
|
|
44
|
+
dbName: 'tck_test'
|
|
45
|
+
});
|
|
46
|
+
return driver;
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
// MongoDB supports most features
|
|
50
|
+
skip: {
|
|
51
|
+
// No features to skip - MongoDB now supports transactions
|
|
52
|
+
},
|
|
53
|
+
timeout: 30000,
|
|
54
|
+
hooks: {
|
|
55
|
+
beforeEach: async () => {
|
|
56
|
+
// Wait for driver to connect
|
|
57
|
+
await driver['connected'];
|
|
58
|
+
|
|
59
|
+
// Clear all collections
|
|
60
|
+
if (driver && driver['db']) {
|
|
61
|
+
const collections = await driver['db'].listCollections().toArray();
|
|
62
|
+
for (const collection of collections) {
|
|
63
|
+
await driver['db'].collection(collection.name).deleteMany({});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
afterEach: async () => {
|
|
68
|
+
// Cleanup handled in beforeEach
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|