@furystack/mongodb-store 10.0.38 → 10.0.40
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/CHANGELOG.md +12 -0
- package/README.md +2 -0
- package/esm/mongodb-store.spec.js +19 -14
- package/esm/mongodb-store.spec.js.map +1 -1
- package/package.json +2 -2
- package/src/mongodb-store.spec.ts +20 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [10.0.40] - 2026-02-26
|
|
4
|
+
|
|
5
|
+
### 📝 Documentation
|
|
6
|
+
|
|
7
|
+
- Added tip about wrapping the physical store with a Repository DataSet for application-level data access
|
|
8
|
+
|
|
9
|
+
## [10.0.39] - 2026-02-22
|
|
10
|
+
|
|
11
|
+
### ⬆️ Dependencies
|
|
12
|
+
|
|
13
|
+
- Updated `@furystack/core` dependency
|
|
14
|
+
|
|
3
15
|
## [10.0.38] - 2026-02-19
|
|
4
16
|
|
|
5
17
|
### ⬆️ Dependencies
|
package/README.md
CHANGED
|
@@ -34,3 +34,5 @@ useMongoDb({
|
|
|
34
34
|
|
|
35
35
|
const myMongoStore = myInjector.getInstance(StoreManager).getStoreFor(TestEntry, '_id')
|
|
36
36
|
```
|
|
37
|
+
|
|
38
|
+
> **Tip:** For application-level data access, wrap the physical store with a Repository DataSet using `getRepository(injector).createDataSet(Model, 'primaryKey')` and then use `getDataSetFor(injector, Model, 'primaryKey')` from `@furystack/repository`. This ensures authorization, hooks, and entity sync events are properly triggered.
|
|
@@ -37,10 +37,21 @@ describe('MongoDB Store', () => {
|
|
|
37
37
|
return store;
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
|
+
const createTestClassWithIdStore = (injector) => {
|
|
41
|
+
const mongoOptions = { ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' };
|
|
42
|
+
useMongoDb(mongoOptions);
|
|
43
|
+
const oldDispose = injector[Symbol.asyncDispose];
|
|
44
|
+
injector[Symbol.asyncDispose] = async () => {
|
|
45
|
+
const client = injector.getInstance(MongoClientFactory).getClientFor(mongoOptions.url, mongoOptions.options);
|
|
46
|
+
const db = client.db(mongoOptions.db);
|
|
47
|
+
await db.dropDatabase();
|
|
48
|
+
await oldDispose.call(injector);
|
|
49
|
+
};
|
|
50
|
+
return injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
51
|
+
};
|
|
40
52
|
it('Should retrieve an entity with its id', async () => {
|
|
41
53
|
await usingAsync(new Injector(), async (injector) => {
|
|
42
|
-
|
|
43
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
54
|
+
const store = createTestClassWithIdStore(injector);
|
|
44
55
|
const { created } = await store.add({ value: 'value1' });
|
|
45
56
|
expect(typeof created[0]._id).toBe('string');
|
|
46
57
|
const retrieved = await store.get(created[0]._id);
|
|
@@ -49,8 +60,7 @@ describe('MongoDB Store', () => {
|
|
|
49
60
|
});
|
|
50
61
|
it('Should retrieve more entities with theis ids', async () => {
|
|
51
62
|
await usingAsync(new Injector(), async (injector) => {
|
|
52
|
-
|
|
53
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
63
|
+
const store = createTestClassWithIdStore(injector);
|
|
54
64
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' });
|
|
55
65
|
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } });
|
|
56
66
|
expect(retrieved.length).toBe(3);
|
|
@@ -59,8 +69,7 @@ describe('MongoDB Store', () => {
|
|
|
59
69
|
});
|
|
60
70
|
it('Should filter by _id as a string', async () => {
|
|
61
71
|
await usingAsync(new Injector(), async (injector) => {
|
|
62
|
-
|
|
63
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
72
|
+
const store = createTestClassWithIdStore(injector);
|
|
64
73
|
const { created } = await store.add({ value: 'value1' });
|
|
65
74
|
const retrieved = await store.find({ filter: { _id: { $eq: created[0]._id } } });
|
|
66
75
|
expect(retrieved.length).toBe(1);
|
|
@@ -69,8 +78,7 @@ describe('MongoDB Store', () => {
|
|
|
69
78
|
});
|
|
70
79
|
it('Should filter by _id.$eq as a string', async () => {
|
|
71
80
|
await usingAsync(new Injector(), async (injector) => {
|
|
72
|
-
|
|
73
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
81
|
+
const store = createTestClassWithIdStore(injector);
|
|
74
82
|
const { created } = await store.add({ value: 'value1' });
|
|
75
83
|
const retrieved = await store.find({ filter: { _id: { $eq: created[0]._id } } });
|
|
76
84
|
expect(retrieved.length).toBe(1);
|
|
@@ -79,8 +87,7 @@ describe('MongoDB Store', () => {
|
|
|
79
87
|
});
|
|
80
88
|
it('Should filter by _id.$in as array of strings', async () => {
|
|
81
89
|
await usingAsync(new Injector(), async (injector) => {
|
|
82
|
-
|
|
83
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
90
|
+
const store = createTestClassWithIdStore(injector);
|
|
84
91
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' });
|
|
85
92
|
const ids = created.map((c) => c._id);
|
|
86
93
|
const retrieved = await store.find({ filter: { _id: { $in: ids } } });
|
|
@@ -90,8 +97,7 @@ describe('MongoDB Store', () => {
|
|
|
90
97
|
});
|
|
91
98
|
it('Should filter by _id.$nin as array of strings', async () => {
|
|
92
99
|
await usingAsync(new Injector(), async (injector) => {
|
|
93
|
-
|
|
94
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
100
|
+
const store = createTestClassWithIdStore(injector);
|
|
95
101
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' });
|
|
96
102
|
const ids = created.map((c) => c._id);
|
|
97
103
|
const retrieved = await store.find({ filter: { _id: { $nin: [ids[0]] } } });
|
|
@@ -101,8 +107,7 @@ describe('MongoDB Store', () => {
|
|
|
101
107
|
});
|
|
102
108
|
it('Should filter by a non-_id field', async () => {
|
|
103
109
|
await usingAsync(new Injector(), async (injector) => {
|
|
104
|
-
|
|
105
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id');
|
|
110
|
+
const store = createTestClassWithIdStore(injector);
|
|
106
111
|
await store.add({ value: 'value1' }, { value: 'value2' });
|
|
107
112
|
const retrieved = await store.find({ filter: { value: { $eq: 'value2' } } });
|
|
108
113
|
expect(retrieved.length).toBe(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-store.spec.js","sourceRoot":"","sources":["../src/mongodb-store.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,MAAM,eAAe;CAGpB;AAED,IAAI,UAAU,GAAG,CAAC,CAAA;AAElB,MAAM,UAAU,GAAG,OAAO,EAAE,GAAG,EAAE,WAAW,IAAI,2BAA2B,CAAA;AAE3E,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC;QAC/C,QAAQ;QACR,KAAK,EAAE,SAAS;QAChB,UAAU,EAAE,IAAa;QACzB,UAAU,EAAE,+BAA+B,UAAU,EAAE,EAAE;QACzD,EAAE,EAAE,+BAA+B,KAAK,EAA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;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/mongodb-store",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.40",
|
|
4
4
|
"description": "MongoDB Store implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/furystack/furystack",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@furystack/core": "^15.1
|
|
41
|
+
"@furystack/core": "^15.2.1",
|
|
42
42
|
"@furystack/inject": "^12.0.30",
|
|
43
43
|
"@furystack/utils": "^8.1.10",
|
|
44
44
|
"mongodb": "7.1.0"
|
|
@@ -45,10 +45,22 @@ describe('MongoDB Store', () => {
|
|
|
45
45
|
},
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
+
const createTestClassWithIdStore = (injector: Injector) => {
|
|
49
|
+
const mongoOptions = { ...getMongoOptions(injector), model: TestClassWithId, primaryKey: '_id' as const }
|
|
50
|
+
useMongoDb(mongoOptions)
|
|
51
|
+
const oldDispose = injector[Symbol.asyncDispose]
|
|
52
|
+
injector[Symbol.asyncDispose] = async () => {
|
|
53
|
+
const client = injector.getInstance(MongoClientFactory).getClientFor(mongoOptions.url, mongoOptions.options)
|
|
54
|
+
const db = client.db(mongoOptions.db)
|
|
55
|
+
await db.dropDatabase()
|
|
56
|
+
await oldDispose.call(injector)
|
|
57
|
+
}
|
|
58
|
+
return injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
59
|
+
}
|
|
60
|
+
|
|
48
61
|
it('Should retrieve an entity with its id', async () => {
|
|
49
62
|
await usingAsync(new Injector(), async (injector) => {
|
|
50
|
-
|
|
51
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
63
|
+
const store = createTestClassWithIdStore(injector)
|
|
52
64
|
const { created } = await store.add({ value: 'value1' })
|
|
53
65
|
|
|
54
66
|
expect(typeof created[0]._id).toBe('string')
|
|
@@ -60,8 +72,7 @@ describe('MongoDB Store', () => {
|
|
|
60
72
|
|
|
61
73
|
it('Should retrieve more entities with theis ids', async () => {
|
|
62
74
|
await usingAsync(new Injector(), async (injector) => {
|
|
63
|
-
|
|
64
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
75
|
+
const store = createTestClassWithIdStore(injector)
|
|
65
76
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' }, { value: 'value3' })
|
|
66
77
|
const retrieved = await store.find({ filter: { _id: { $in: created.map((c) => c._id) } } })
|
|
67
78
|
expect(retrieved.length).toBe(3)
|
|
@@ -71,8 +82,7 @@ describe('MongoDB Store', () => {
|
|
|
71
82
|
|
|
72
83
|
it('Should filter by _id as a string', async () => {
|
|
73
84
|
await usingAsync(new Injector(), async (injector) => {
|
|
74
|
-
|
|
75
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
85
|
+
const store = createTestClassWithIdStore(injector)
|
|
76
86
|
const { created } = await store.add({ value: 'value1' })
|
|
77
87
|
const retrieved = await store.find({ filter: { _id: { $eq: created[0]._id } } })
|
|
78
88
|
expect(retrieved.length).toBe(1)
|
|
@@ -82,8 +92,7 @@ describe('MongoDB Store', () => {
|
|
|
82
92
|
|
|
83
93
|
it('Should filter by _id.$eq as a string', async () => {
|
|
84
94
|
await usingAsync(new Injector(), async (injector) => {
|
|
85
|
-
|
|
86
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
95
|
+
const store = createTestClassWithIdStore(injector)
|
|
87
96
|
const { created } = await store.add({ value: 'value1' })
|
|
88
97
|
const retrieved = await store.find({ filter: { _id: { $eq: created[0]._id } } })
|
|
89
98
|
expect(retrieved.length).toBe(1)
|
|
@@ -93,8 +102,7 @@ describe('MongoDB Store', () => {
|
|
|
93
102
|
|
|
94
103
|
it('Should filter by _id.$in as array of strings', async () => {
|
|
95
104
|
await usingAsync(new Injector(), async (injector) => {
|
|
96
|
-
|
|
97
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
105
|
+
const store = createTestClassWithIdStore(injector)
|
|
98
106
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' })
|
|
99
107
|
const ids = created.map((c) => c._id)
|
|
100
108
|
const retrieved = await store.find({ filter: { _id: { $in: ids } } })
|
|
@@ -105,8 +113,7 @@ describe('MongoDB Store', () => {
|
|
|
105
113
|
|
|
106
114
|
it('Should filter by _id.$nin as array of strings', async () => {
|
|
107
115
|
await usingAsync(new Injector(), async (injector) => {
|
|
108
|
-
|
|
109
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
116
|
+
const store = createTestClassWithIdStore(injector)
|
|
110
117
|
const { created } = await store.add({ value: 'value1' }, { value: 'value2' })
|
|
111
118
|
const ids = created.map((c) => c._id)
|
|
112
119
|
const retrieved = await store.find({ filter: { _id: { $nin: [ids[0]] } } })
|
|
@@ -117,8 +124,7 @@ describe('MongoDB Store', () => {
|
|
|
117
124
|
|
|
118
125
|
it('Should filter by a non-_id field', async () => {
|
|
119
126
|
await usingAsync(new Injector(), async (injector) => {
|
|
120
|
-
|
|
121
|
-
const store = injector.getInstance(StoreManager).getStoreFor(TestClassWithId, '_id')
|
|
127
|
+
const store = createTestClassWithIdStore(injector)
|
|
122
128
|
await store.add({ value: 'value1' }, { value: 'value2' })
|
|
123
129
|
const retrieved = await store.find({ filter: { value: { $eq: 'value2' } } })
|
|
124
130
|
expect(retrieved.length).toBe(1)
|