@orion-js/mongodb 3.7.4 → 3.7.6
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/lib/createCollection/createIndexes.test.js +1 -1
- package/lib/createCollection/generateId.js +1 -1
- package/lib/createCollection/generateId.test.js +1 -1
- package/lib/createCollection/getMethods/cleanModifier.d.ts +1 -1
- package/lib/createCollection/getMethods/findOneAndUpdate.js +2 -2
- package/lib/createCollection/getMethods/insertOne.test.js +2 -8
- package/lib/createCollection/getMethods/updateItem.test.js +1 -1
- package/lib/types/index.d.ts +30 -30
- package/package.json +15 -14
|
@@ -55,7 +55,7 @@ describe('Test indexes', () => {
|
|
|
55
55
|
indexes: [{ keys: { a: 1 }, options: { unique: true } }]
|
|
56
56
|
});
|
|
57
57
|
const result = await collection2.createIndexesPromise;
|
|
58
|
-
expect(result[0]).
|
|
58
|
+
expect(result[0]).toContain('E11000');
|
|
59
59
|
expect(console.error).toHaveBeenCalled();
|
|
60
60
|
});
|
|
61
61
|
it('Should log indexes that have to be deleted', async () => {
|
|
@@ -22,7 +22,7 @@ it('generates a usable mongo objectId as string', async () => {
|
|
|
22
22
|
const userId = await Tests.insertOne({
|
|
23
23
|
name: 'Nico'
|
|
24
24
|
});
|
|
25
|
-
const objectId =
|
|
25
|
+
const objectId = bson_1.ObjectId.createFromHexString(userId);
|
|
26
26
|
expect(objectId.toString()).toBe(userId);
|
|
27
27
|
const diff = now.valueOf() - objectId.getTimestamp().valueOf();
|
|
28
28
|
expect(diff).toBeGreaterThan(0);
|
|
@@ -21,9 +21,9 @@ exports.default = (collection) => {
|
|
|
21
21
|
await (0, validateModifier_1.default)(schema, modifier);
|
|
22
22
|
}
|
|
23
23
|
const result = await collection.rawCollection.findOneAndUpdate(selector, modifier, options.mongoOptions);
|
|
24
|
-
if (!result
|
|
24
|
+
if (!result)
|
|
25
25
|
return null;
|
|
26
|
-
return collection.initItem(result
|
|
26
|
+
return collection.initItem(result);
|
|
27
27
|
};
|
|
28
28
|
return findOneAndUpdate;
|
|
29
29
|
};
|
|
@@ -97,14 +97,8 @@ describe('InsertOne', () => {
|
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|
|
99
99
|
expect(error.code).toBe('validationError');
|
|
100
|
-
expect(error.validationErrors).toHaveProperty('
|
|
101
|
-
expect(error.validationErrors.
|
|
102
|
-
/**
|
|
103
|
-
* This should work on a real db, but on memory-server it doesnt give the name of the index.
|
|
104
|
-
*/
|
|
105
|
-
// expect(error.code).toBe('validationError')
|
|
106
|
-
// expect(error.validationErrors).toHaveProperty('name')
|
|
107
|
-
// expect(error.validationErrors.name).toBe('notUnique')
|
|
100
|
+
expect(error.validationErrors).toHaveProperty('name');
|
|
101
|
+
expect(error.validationErrors.name).toBe('notUnique');
|
|
108
102
|
}
|
|
109
103
|
});
|
|
110
104
|
});
|
|
@@ -27,7 +27,7 @@ it('updates the item variable using updateItem', async () => {
|
|
|
27
27
|
__metadata("design:type", String)
|
|
28
28
|
], Item.prototype, "text", void 0);
|
|
29
29
|
Item = __decorate([
|
|
30
|
-
(0, typed_model_1.
|
|
30
|
+
(0, typed_model_1.TypedSchema)()
|
|
31
31
|
], Item);
|
|
32
32
|
const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)(), model: Item });
|
|
33
33
|
await Tests.insertOne({ text: 'hello' });
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,27 +2,27 @@ import * as MongoDB from 'mongodb';
|
|
|
2
2
|
import { Model } from '@orion-js/models';
|
|
3
3
|
import { Blackbox, Schema } from '@orion-js/schema';
|
|
4
4
|
import { OrionMongoClient } from '../connect/connections';
|
|
5
|
-
|
|
5
|
+
type RemoveFunctions<T extends ModelClassBase> = Pick<T, {
|
|
6
6
|
[Key in keyof T]-?: T[Key] extends Function ? never : Key;
|
|
7
7
|
}[keyof T]> & {
|
|
8
8
|
_id: ModelClassBase['_id'];
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type ModelClassBase = {
|
|
11
11
|
_id: string;
|
|
12
12
|
} & Blackbox;
|
|
13
|
-
export
|
|
13
|
+
export type DocumentWithIdOptional<T extends ModelClassBase> = Omit<T, '_id'> & {
|
|
14
14
|
/**
|
|
15
15
|
* The ID of the document
|
|
16
16
|
*/
|
|
17
17
|
_id?: T['_id'];
|
|
18
18
|
};
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
19
|
+
export type DocumentWithoutId<T> = Omit<T, '_id'>;
|
|
20
|
+
export type ModelToDocumentType<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
21
|
+
export type ModelToDocumentTypeWithId<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
22
|
+
export type ModelToDocumentTypeWithoutId<ModelClass extends ModelClassBase> = DocumentWithoutId<ModelToDocumentType<ModelClass>>;
|
|
23
|
+
export type ModelToDocumentTypeWithIdOptional<ModelClass extends ModelClassBase> = DocumentWithIdOptional<ModelToDocumentType<ModelClass>>;
|
|
24
|
+
export type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoSelector<ModelToDocumentType<ModelClass>>;
|
|
25
|
+
export type ModelToUpdateFilter<ModelClass extends ModelClassBase> = MongoDB.UpdateFilter<ModelToDocumentTypeWithoutId<ModelClass>> | Partial<ModelToDocumentTypeWithoutId<ModelClass>>;
|
|
26
26
|
export interface CollectionIndex {
|
|
27
27
|
keys: MongoDB.IndexSpecification;
|
|
28
28
|
options?: MongoDB.CreateIndexesOptions;
|
|
@@ -49,14 +49,14 @@ export declare namespace DataLoader {
|
|
|
49
49
|
export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass['_id']) => Promise<ModelClass>;
|
|
50
50
|
export {};
|
|
51
51
|
}
|
|
52
|
-
export
|
|
52
|
+
export type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass> & ({
|
|
53
53
|
_id?: ModelClass['_id'];
|
|
54
54
|
} | {
|
|
55
55
|
_id?: {
|
|
56
56
|
$in: ModelClass['_id'][];
|
|
57
57
|
};
|
|
58
58
|
});
|
|
59
|
-
export
|
|
59
|
+
export type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass['_id'] | MongoFilter<ModelClass>;
|
|
60
60
|
export interface FindCursor<ModelClass> extends MongoDB.FindCursor {
|
|
61
61
|
toArray: () => Promise<Array<ModelClass>>;
|
|
62
62
|
}
|
|
@@ -75,20 +75,20 @@ export interface InsertOptions {
|
|
|
75
75
|
validate?: boolean;
|
|
76
76
|
mongoOptions?: MongoDB.InsertOneOptions;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
79
|
-
export
|
|
80
|
-
export
|
|
81
|
-
export
|
|
82
|
-
export
|
|
83
|
-
export
|
|
84
|
-
export
|
|
85
|
-
export
|
|
86
|
-
export
|
|
87
|
-
export
|
|
88
|
-
export
|
|
89
|
-
export
|
|
90
|
-
export
|
|
91
|
-
export
|
|
78
|
+
export type InitItem<ModelClass extends ModelClassBase> = (doc: any) => ModelClass;
|
|
79
|
+
export type FindOne<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => Promise<ModelClass>;
|
|
80
|
+
export type Find<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => FindCursor<ModelClass>;
|
|
81
|
+
export type FindOneAndUpdate<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
82
|
+
export type UpdateAndFind<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
83
|
+
export type UpdateItem<ModelClass extends ModelClassBase> = (item: ModelClass, modifier: ModelToUpdateFilter<ModelClass>) => Promise<void>;
|
|
84
|
+
export type InsertOne<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass['_id']>;
|
|
85
|
+
export type InsertMany<ModelClass extends ModelClassBase> = (doc: Array<ModelToDocumentTypeWithIdOptional<ModelClass>>, options?: InsertOptions) => Promise<Array<ModelClass['_id']>>;
|
|
86
|
+
export type InsertAndFind<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass>;
|
|
87
|
+
export type DeleteMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
88
|
+
export type DeleteOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
89
|
+
export type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
90
|
+
export type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult | MongoDB.Document>;
|
|
91
|
+
export type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
92
92
|
export interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
93
93
|
/**
|
|
94
94
|
* The name of the collection on the Mongo Database
|
|
@@ -121,9 +121,9 @@ export interface CreateCollectionOptions<ModelClass extends ModelClassBase = Mod
|
|
|
121
121
|
*/
|
|
122
122
|
idPrefix?: ModelClass['_id'];
|
|
123
123
|
}
|
|
124
|
-
export
|
|
125
|
-
export
|
|
126
|
-
export
|
|
124
|
+
export type EstimatedDocumentCount<ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
|
|
125
|
+
export type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
|
|
126
|
+
export type CreateCollection = <ModelClass extends ModelClassBase = any>(options: CreateCollectionOptions<ModelClass>) => Collection<ModelClass>;
|
|
127
127
|
export interface Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
128
128
|
name: string;
|
|
129
129
|
connectionName?: string;
|
|
@@ -172,7 +172,7 @@ export interface Collection<ModelClass extends ModelClassBase = ModelClassBase>
|
|
|
172
172
|
createIndexesPromise: Promise<string[]>;
|
|
173
173
|
connectionPromise: Promise<MongoDB.MongoClient>;
|
|
174
174
|
}
|
|
175
|
-
export
|
|
175
|
+
export type DistinctDocumentId<DistinctId extends string> = string & {
|
|
176
176
|
__TYPE__: `DistinctDocumentId<${DistinctId}>`;
|
|
177
177
|
};
|
|
178
178
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -19,27 +19,28 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/env": "^3.7.4",
|
|
21
21
|
"@orion-js/helpers": "^3.7.4",
|
|
22
|
-
"@orion-js/logger": "^3.7.
|
|
23
|
-
"@orion-js/models": "^3.7.
|
|
22
|
+
"@orion-js/logger": "^3.7.6",
|
|
23
|
+
"@orion-js/models": "^3.7.6",
|
|
24
24
|
"@orion-js/resolvers": "^3.7.4",
|
|
25
25
|
"@orion-js/schema": "^3.7.4",
|
|
26
26
|
"@orion-js/services": "^3.7.4",
|
|
27
|
-
"@orion-js/typed-model": "^3.7.
|
|
28
|
-
"
|
|
27
|
+
"@orion-js/typed-model": "^3.7.6",
|
|
28
|
+
"bson": "^6.6.0",
|
|
29
|
+
"dataloader": "2.2.2",
|
|
29
30
|
"dot-object": "2.1.4",
|
|
30
|
-
"mongodb": "
|
|
31
|
+
"mongodb": "6.5.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@shelf/jest-mongodb": "^
|
|
34
|
-
"@types/dot-object": "^2.1.
|
|
35
|
-
"@types/jest": "^
|
|
36
|
-
"@types/lodash": "4.
|
|
37
|
-
"jest": "
|
|
38
|
-
"ts-jest": "
|
|
39
|
-
"typescript": "^4.
|
|
34
|
+
"@shelf/jest-mongodb": "^4.2.0",
|
|
35
|
+
"@types/dot-object": "^2.1.6",
|
|
36
|
+
"@types/jest": "^29.5.12",
|
|
37
|
+
"@types/lodash": "4.17.0",
|
|
38
|
+
"jest": "29.7.0",
|
|
39
|
+
"ts-jest": "29.1.2",
|
|
40
|
+
"typescript": "^5.4.5"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c1bb048206f0309f38d32796b0ca5729a2052ec6"
|
|
45
46
|
}
|