Skip to content

Commit 496e109

Browse files
committed
feat: Use mongodb v4.2.1
The following change in `mongodb` requires changes in the return types of `find*` methods to include `WithId`: - mongodb/node-mongodb-native#3039
1 parent f39003f commit 496e109

File tree

4 files changed

+54
-45
lines changed

4 files changed

+54
-45
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"jsdoc-api": "7.1.0",
7676
"jsdoc-parse": "6.0.0",
7777
"lint-staged": "12.1.2",
78-
"mongodb": "4.1.1",
78+
"mongodb": "4.2.1",
7979
"mongodb-memory-server": "8.0.0",
8080
"mongoose": "6.0.6",
8181
"prettier": "2.5.0",
@@ -85,7 +85,7 @@
8585
"typescript": "4.5.2"
8686
},
8787
"peerDependencies": {
88-
"mongodb": ">=4.1.1"
88+
"mongodb": ">=4.2.1"
8989
},
9090
"commitlint": {
9191
"extends": [

src/model.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface Model<TSchema extends BaseSchema, TDefaults extends Partial<TSc
115115
options?: UpdateOptions
116116
) => Promise<UpdateResult>;
117117

118-
upsert: (filter: Filter<TSchema>, update: UpdateFilter<TSchema>) => Promise<TSchema>;
118+
upsert: (filter: Filter<TSchema>, update: UpdateFilter<TSchema>) => Promise<WithId<TSchema>>;
119119
}
120120

121121
function abstractMethod(): void {
@@ -506,7 +506,7 @@ export function build<TSchema extends BaseSchema, TDefaults extends Partial<TSch
506506
...model.defaultOptions,
507507
...options,
508508
} as FindOptions<TSchema>)
509-
.toArray();
509+
.toArray() as unknown as ProjectionType<TSchema, Projection>[];
510510
}
511511
);
512512

@@ -872,7 +872,7 @@ export function build<TSchema extends BaseSchema, TDefaults extends Partial<TSch
872872
model.upsert = async function upsert(
873873
filter: Filter<TSchema>,
874874
update: UpdateFilter<TSchema>
875-
): Promise<TSchema> {
875+
): Promise<WithId<TSchema>> {
876876
const item = await model.findOneAndUpdate(filter, update, {
877877
upsert: true,
878878
});

src/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ObjectId } from 'mongodb';
1+
import { ObjectId, WithId } from 'mongodb';
22
import type { AnyBulkWriteOperation, OptionalId, UpdateFilter } from 'mongodb';
33
import { Hooks } from './hooks';
44

@@ -45,8 +45,8 @@ export type ProjectionType<
4545
TSchema extends BaseSchema,
4646
Projection extends Partial<Record<keyof TSchema, number>> | undefined
4747
> = undefined extends Projection
48-
? TSchema
49-
: Pick<TSchema, '_id'> & Pick<TSchema, keyof Projection & keyof TSchema>;
48+
? WithId<TSchema>
49+
: WithId<Pick<TSchema, keyof Projection & keyof TSchema>>;
5050

5151
export function getIds(ids: (string | ObjectId)[] | Set<string>): ObjectId[] {
5252
return [...ids].map((id) => new ObjectId(id));

yarn.lock

+46-37
Original file line numberDiff line numberDiff line change
@@ -2154,24 +2154,17 @@ [email protected]:
21542154
dependencies:
21552155
node-int64 "^0.4.0"
21562156

2157-
bson@^4.2.2:
2158-
version "4.5.2"
2159-
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.2.tgz#567b4ee94372d5284a4d6c47fb6e1cc711ae76ba"
2160-
integrity sha512-8CEMJpwc7qlQtrn2rney38jQSEeMar847lz0LyitwRmVknAW8iHXrzW4fTjHfyWm0E3sukyD/zppdH+QU1QefA==
2157+
bson@^4.2.2, bson@^4.5.1, bson@^4.5.4:
2158+
version "4.5.4"
2159+
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.4.tgz#5f74f1e11f743ea8aec30b5e24bfddae82846873"
2160+
integrity sha512-wIt0bPACnx8Ju9r6IsS2wVtGDHBr9Dxb+U29A1YED2pu8XOhS8aKjOnLZ8sxyXkPwanoK7iWWVhS1+coxde6xA==
21612161
dependencies:
21622162
buffer "^5.6.0"
21632163

2164-
bson@^4.5.1:
2165-
version "4.5.1"
2166-
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.1.tgz#02e9d649ce017ab14ed258737756c11809963d6c"
2167-
integrity sha512-XqFP74pbTVLyLy5KFxVfTUyRrC1mgOlmu/iXHfXqfCKT59jyP9lwbotGfbN59cHBRbJSamZNkrSopjv+N0SqAA==
2168-
dependencies:
2169-
buffer "^5.6.0"
2170-
2171-
bson@^4.5.2:
2172-
version "4.5.3"
2173-
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.3.tgz#de3783b357a407d935510beb1fbb285fef43bb06"
2174-
integrity sha512-qVX7LX79Mtj7B3NPLzCfBiCP6RAsjiV8N63DjlaVVpZW+PFoDTxQ4SeDbSpcqgE6mXksM5CAwZnXxxxn/XwC0g==
2164+
bson@^4.6.0:
2165+
version "4.6.0"
2166+
resolved "https://registry.yarnpkg.com/bson/-/bson-4.6.0.tgz#15c3b39ba3940c3d915a0c44d51459f4b4fbf1b2"
2167+
integrity sha512-8jw1NU1hglS+Da1jDOUYuNcBJ4cNHCFIqzlwoFNnsTOg2R/ox0aTYcTiBN4dzRa9q7Cvy6XErh3L8ReTEb9AQQ==
21752168
dependencies:
21762169
buffer "^5.6.0"
21772170

@@ -5685,13 +5678,13 @@ modify-values@^1.0.0:
56855678
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022"
56865679
integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==
56875680

5688-
mongodb-connection-string-url@^2.0.0:
5689-
version "2.0.0"
5690-
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.0.0.tgz#72cea65084ffa45655670070efb57bb0a5da46bc"
5691-
integrity sha512-M0I1vyLoq5+HQTuPSJWbt+hIXsMCfE8sS1fS5mvP9R2DOMoi2ZD32yWqgBIITyu0dFu4qtS50erxKjvUeBiyog==
5681+
mongodb-connection-string-url@^2.0.0, mongodb-connection-string-url@^2.2.0:
5682+
version "2.2.0"
5683+
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.2.0.tgz#e2422bae91a953dc4ae5882e401301f5be39a227"
5684+
integrity sha512-U0cDxLUrQrl7DZA828CA+o69EuWPWEJTwdMPozyd7cy/dbtncUZczMw7wRHcwMD7oKOn0NM2tF9jdf5FFVW9CA==
56925685
dependencies:
56935686
"@types/whatwg-url" "^8.2.1"
5694-
whatwg-url "^9.1.0"
5687+
whatwg-url "^11.0.0"
56955688

56965689
56975690
version "8.0.0"
@@ -5734,14 +5727,25 @@ [email protected]:
57345727
optionalDependencies:
57355728
saslprep "^1.0.0"
57365729

5730+
5731+
version "4.2.1"
5732+
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.2.1.tgz#c167db158ab0bf6552b3f9c91b396cb4100c2f04"
5733+
integrity sha512-nDC+ulM/Ea3Q2VG5eemuGfB7T4ORwrtKegH2XW9OLlUBgQF6OTNrzFCS1Z3SJGVA+T0Sr1xBYV6DMnp0A7us0g==
5734+
dependencies:
5735+
bson "^4.6.0"
5736+
denque "^2.0.1"
5737+
mongodb-connection-string-url "^2.2.0"
5738+
optionalDependencies:
5739+
saslprep "^1.0.3"
5740+
57375741
mongodb@^4.1.3:
5738-
version "4.1.3"
5739-
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.1.3.tgz#8bf24d782ba3f3833201f4e60b0307d87980ba71"
5740-
integrity sha512-lHvTqODBiSpuqjpCj48DOyYWS6Iq6ElJNUiH9HWdQtONyOfjgsKzJULipWduMGsSzaNO4nFi/kmlMFCLvjox/Q==
5742+
version "4.2.0"
5743+
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.2.0.tgz#7ef94ab0613a2fd890763260fdac20cd099d0d7f"
5744+
integrity sha512-lg3MJ9dAKxhogRnIB6/j63gfD7JryZwRC0nNzZ82RhENw4nCmscZVqRfOmNzTvSNndJx9ZhxZpm9JvnKuH/GTA==
57415745
dependencies:
5742-
bson "^4.5.2"
5746+
bson "^4.5.4"
57435747
denque "^2.0.1"
5744-
mongodb-connection-string-url "^2.0.0"
5748+
mongodb-connection-string-url "^2.2.0"
57455749
optionalDependencies:
57465750
saslprep "^1.0.3"
57475751

@@ -7402,10 +7406,10 @@ tr46@^2.0.2:
74027406
dependencies:
74037407
punycode "^2.1.1"
74047408

7405-
tr46@^2.1.0:
7406-
version "2.1.0"
7407-
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240"
7408-
integrity sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==
7409+
tr46@^3.0.0:
7410+
version "3.0.0"
7411+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-3.0.0.tgz#555c4e297a950617e8eeddef633c87d4d9d6cbf9"
7412+
integrity sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==
74097413
dependencies:
74107414
punycode "^2.1.1"
74117415

@@ -7743,6 +7747,11 @@ webidl-conversions@^6.1.0:
77437747
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
77447748
integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==
77457749

7750+
webidl-conversions@^7.0.0:
7751+
version "7.0.0"
7752+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"
7753+
integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==
7754+
77467755
whatwg-encoding@^1.0.5:
77477756
version "1.0.5"
77487757
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"
@@ -7755,6 +7764,14 @@ whatwg-mimetype@^2.3.0:
77557764
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
77567765
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
77577766

7767+
whatwg-url@^11.0.0:
7768+
version "11.0.0"
7769+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-11.0.0.tgz#0a849eebb5faf2119b901bb76fd795c2848d4018"
7770+
integrity sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==
7771+
dependencies:
7772+
tr46 "^3.0.0"
7773+
webidl-conversions "^7.0.0"
7774+
77587775
whatwg-url@^8.0.0, whatwg-url@^8.5.0:
77597776
version "8.5.0"
77607777
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.5.0.tgz#7752b8464fc0903fec89aa9846fc9efe07351fd3"
@@ -7764,14 +7781,6 @@ whatwg-url@^8.0.0, whatwg-url@^8.5.0:
77647781
tr46 "^2.0.2"
77657782
webidl-conversions "^6.1.0"
77667783

7767-
whatwg-url@^9.1.0:
7768-
version "9.1.0"
7769-
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-9.1.0.tgz#1b112cf237d72cd64fa7882b9c3f6234a1c3050d"
7770-
integrity sha512-CQ0UcrPHyomtlOCot1TL77WyMIm/bCwrJ2D6AOKGwEczU9EpyoqAokfqrf/MioU9kHcMsmJZcg1egXix2KYEsA==
7771-
dependencies:
7772-
tr46 "^2.1.0"
7773-
webidl-conversions "^6.1.0"
7774-
77757784
which-boxed-primitive@^1.0.2:
77767785
version "1.0.2"
77777786
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"

0 commit comments

Comments
 (0)