@furystack/mongodb-store 7.0.10 → 7.0.11
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb-store.spec.d.ts","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TextEncoder, TextDecoder } from 'util';
|
|
2
|
+
global.TextEncoder = TextEncoder;
|
|
3
|
+
global.TextDecoder = TextDecoder;
|
|
4
|
+
import { Injector } from '@furystack/inject';
|
|
5
|
+
import { StoreManager } from '@furystack/core';
|
|
6
|
+
import { useMongoDb } from './store-manager-helpers.js';
|
|
7
|
+
import { MongoClientFactory } from './mongo-client-factory.js';
|
|
8
|
+
import { usingAsync } from '@furystack/utils';
|
|
9
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
import { createStoreTest, TestClass } from '@furystack/core/create-physical-store-tests';
|
|
11
|
+
class TestClassWithId {
|
|
12
|
+
_id;
|
|
13
|
+
value;
|
|
14
|
+
}
|
|
15
|
+
let storeCount = 0;
|
|
16
|
+
const mongoDbUrl = process?.env?.MONGODB_URL || 'mongodb://localhost:27017';
|
|
17
|
+
describe('MongoDB Store', () => {
|
|
18
|
+
let dbIdx = 0;
|
|
19
|
+
const getMongoOptions = (injector) => ({
|
|
20
|
+
injector,
|
|
21
|
+
model: TestClass,
|
|
22
|
+
primaryKey: 'id',
|
|
23
|
+
collection: `furystack-mongo-store-tests-${storeCount++}`,
|
|
24
|
+
db: `furystack-mongo-store-tests-${dbIdx++}`,
|
|
25
|
+
url: mongoDbUrl,
|
|
26
|
+
options: {},
|
|
27
|
+
});
|
|
28
|
+
createStoreTest({
|
|
29
|
+
typeName: 'mongodb-store',
|
|
30
|
+
skipStringTests: true,
|
|
31
|
+
createStore: (i) => {
|
|
32
|
+
const mongoOptions = getMongoOptions(i);
|
|
33
|
+
useMongoDb(mongoOptions);
|
|
34
|
+
const store = i.getInstance(StoreManager).getStoreFor(TestClass, 'id');
|
|
35
|
+
const oldDispose = i.dispose;
|
|
36
|
+
i.dispose = async () => {
|
|
37
|
+
const client = await i.getInstance(MongoClientFactory).getClientFor(mongoOptions.url, mongoOptions.options);
|
|
38
|
+
const db = client.db(mongoOptions.db);
|
|
39
|
+
await db.dropDatabase();
|
|
40
|
+
oldDispose.call(i);
|
|
41
|
+
};
|
|
42
|
+
return store;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
it('Should retrieve an entity with its id', async () => {
|
|
46
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
47
|
+
useMongoDb({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
48
|
+
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
49
|
+
const { created } = await store.add({ value: 'value1' });
|
|
50
|
+
expect(typeof created[0]._id).toBe('string');
|
|
51
|
+
const retrieved = await store.get(created[0]._id);
|
|
52
|
+
expect(retrieved).toEqual(created[0]);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it('Should retrieve more entities with theis ids', async () => {
|
|
56
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
57
|
+
useMongoDb({ ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' });
|
|
58
|
+
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
59
|
+
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' });
|
|
60
|
+
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } });
|
|
61
|
+
expect(retrieved.length).toBe(3);
|
|
62
|
+
expect(retrieved).toEqual(created);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=mongodb-store.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb-store.spec.js","sourceRoot":"","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|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/mongodb-store",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.11",
|
|
4
4
|
"description": "MongoDB Store implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/furystack/furystack",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@furystack/core": "^12.0.
|
|
41
|
-
"@furystack/inject": "^8.1.
|
|
42
|
-
"@furystack/utils": "^4.0.
|
|
43
|
-
"mongodb": "
|
|
40
|
+
"@furystack/core": "^12.0.11",
|
|
41
|
+
"@furystack/inject": "^8.1.1",
|
|
42
|
+
"@furystack/utils": "^4.0.10",
|
|
43
|
+
"mongodb": "6.2.0",
|
|
44
44
|
"semaphore-async-await": "^1.5.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^20.
|
|
47
|
+
"@types/node": "^20.8.10",
|
|
48
48
|
"typescript": "^5.2.2",
|
|
49
|
-
"vitest": "^0.34.
|
|
49
|
+
"vitest": "^0.34.6"
|
|
50
50
|
},
|
|
51
51
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
52
52
|
}
|
|
@@ -5,8 +5,8 @@ global.TextDecoder = TextDecoder as any
|
|
|
5
5
|
|
|
6
6
|
import { Injector } from '@furystack/inject'
|
|
7
7
|
import { StoreManager } from '@furystack/core'
|
|
8
|
-
import { useMongoDb } from './store-manager-helpers'
|
|
9
|
-
import { MongoClientFactory } from './mongo-client-factory'
|
|
8
|
+
import { useMongoDb } from './store-manager-helpers.js'
|
|
9
|
+
import { MongoClientFactory } from './mongo-client-factory.js'
|
|
10
10
|
import { usingAsync } from '@furystack/utils'
|
|
11
11
|
import { describe, it, expect } from 'vitest'
|
|
12
12
|
import { createStoreTest, TestClass } from '@furystack/core/create-physical-store-tests'
|