@orion-js/mongodb 3.3.13 → 3.3.15
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.
|
@@ -21,8 +21,10 @@ function default_1(collection) {
|
|
|
21
21
|
ids: options.values,
|
|
22
22
|
timeout: options.timeout,
|
|
23
23
|
load: async (values) => {
|
|
24
|
-
const query =
|
|
25
|
-
|
|
24
|
+
const query = {
|
|
25
|
+
...(0, cloneDeep_1.default)(options.match),
|
|
26
|
+
[options.key]: { $in: values }
|
|
27
|
+
};
|
|
26
28
|
const cursor = collection.find(query);
|
|
27
29
|
if (options.sort) {
|
|
28
30
|
cursor.sort(options.sort);
|
package/lib/types/index.d.ts
CHANGED
|
@@ -27,11 +27,10 @@ export interface CollectionIndex {
|
|
|
27
27
|
keys: MongoDB.IndexSpecification;
|
|
28
28
|
options?: MongoDB.CreateIndexesOptions;
|
|
29
29
|
}
|
|
30
|
-
declare type KeyOf<T extends object> = Extract<keyof T, string>;
|
|
31
30
|
export declare namespace DataLoader {
|
|
32
31
|
interface LoadDataOptionsBase<ModelClass extends ModelClassBase> {
|
|
33
|
-
key:
|
|
34
|
-
match?:
|
|
32
|
+
key: keyof ModelClass;
|
|
33
|
+
match?: MongoFilter<ModelClass>;
|
|
35
34
|
sort?: MongoDB.Sort;
|
|
36
35
|
project?: MongoDB.Document;
|
|
37
36
|
timeout?: number;
|
|
@@ -50,7 +49,10 @@ export declare namespace DataLoader {
|
|
|
50
49
|
export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass['_id']) => Promise<ModelClass>;
|
|
51
50
|
export {};
|
|
52
51
|
}
|
|
53
|
-
export declare type
|
|
52
|
+
export declare type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass> & {
|
|
53
|
+
_id?: ModelClass['_id'];
|
|
54
|
+
};
|
|
55
|
+
export declare type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass['_id'] | MongoFilter<ModelClass>;
|
|
54
56
|
export interface FindCursor<ModelClass> extends MongoDB.FindCursor {
|
|
55
57
|
toArray: () => Promise<Array<ModelClass>>;
|
|
56
58
|
}
|
package/lib/types/types.test.js
CHANGED
|
@@ -42,14 +42,14 @@ it('uses correctly typescript for collections', async () => {
|
|
|
42
42
|
__metadata("design:type", Object)
|
|
43
43
|
], User.prototype, "fullName", void 0);
|
|
44
44
|
User = __decorate([
|
|
45
|
-
(0, typed_model_1.
|
|
45
|
+
(0, typed_model_1.TypedSchema)()
|
|
46
46
|
], User);
|
|
47
|
-
const Users = (0, index_1.default)({ name: (0, helpers_1.generateId)(), model: User });
|
|
47
|
+
const Users = (0, index_1.default)({ name: (0, helpers_1.generateId)(), model: User, idPrefix: `userId-` });
|
|
48
48
|
const userId = await Users.insertOne({
|
|
49
49
|
firstName: 'Nico',
|
|
50
50
|
lastName: 'López'
|
|
51
51
|
});
|
|
52
|
-
const user1 = await Users.findOne(userId);
|
|
52
|
+
const user1 = await Users.findOne({ _id: userId });
|
|
53
53
|
expect(user1.firstName).toBe('Nico');
|
|
54
54
|
expect(await user1.fullName()).toBe('Nico López');
|
|
55
55
|
await Users.updateOne(userId, { $set: { firstName: 'Nicolás' } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.15",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"@orion-js/env": "^3.3.6",
|
|
21
21
|
"@orion-js/helpers": "^3.3.6",
|
|
22
22
|
"@orion-js/logger": "^3.3.6",
|
|
23
|
-
"@orion-js/models": "^3.3.
|
|
24
|
-
"@orion-js/resolvers": "^3.3.
|
|
25
|
-
"@orion-js/schema": "^3.3.
|
|
23
|
+
"@orion-js/models": "^3.3.14",
|
|
24
|
+
"@orion-js/resolvers": "^3.3.14",
|
|
25
|
+
"@orion-js/schema": "^3.3.14",
|
|
26
26
|
"@orion-js/services": "^3.3.6",
|
|
27
|
-
"@orion-js/typed-model": "^3.3.
|
|
27
|
+
"@orion-js/typed-model": "^3.3.14",
|
|
28
28
|
"dataloader": "2.1.0",
|
|
29
29
|
"dot-object": "2.1.4",
|
|
30
30
|
"mongodb": "4.5.0"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "e84cfa72f81b711debccaf6c174c04ce4c6d537a"
|
|
45
45
|
}
|