Skip to content

Commit

Permalink
feat: Use mongodb v4.2.1
Browse files Browse the repository at this point in the history
The following change in `mongodb` requires changes in the return types of
`find*` methods to include `WithId`:

- mongodb/node-mongodb-native#3039
  • Loading branch information
avaly committed Dec 1, 2021
1 parent f39003f commit 496e109
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"jsdoc-api": "7.1.0",
"jsdoc-parse": "6.0.0",
"lint-staged": "12.1.2",
"mongodb": "4.1.1",
"mongodb": "4.2.1",
"mongodb-memory-server": "8.0.0",
"mongoose": "6.0.6",
"prettier": "2.5.0",
Expand All @@ -85,7 +85,7 @@
"typescript": "4.5.2"
},
"peerDependencies": {
"mongodb": ">=4.1.1"
"mongodb": ">=4.2.1"
},
"commitlint": {
"extends": [
Expand Down
6 changes: 3 additions & 3 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface Model<TSchema extends BaseSchema, TDefaults extends Partial<TSc
options?: UpdateOptions
) => Promise<UpdateResult>;

upsert: (filter: Filter<TSchema>, update: UpdateFilter<TSchema>) => Promise<TSchema>;
upsert: (filter: Filter<TSchema>, update: UpdateFilter<TSchema>) => Promise<WithId<TSchema>>;
}

function abstractMethod(): void {
Expand Down Expand Up @@ -506,7 +506,7 @@ export function build<TSchema extends BaseSchema, TDefaults extends Partial<TSch
...model.defaultOptions,
...options,
} as FindOptions<TSchema>)
.toArray();
.toArray() as unknown as ProjectionType<TSchema, Projection>[];
}
);

Expand Down Expand Up @@ -872,7 +872,7 @@ export function build<TSchema extends BaseSchema, TDefaults extends Partial<TSch
model.upsert = async function upsert(
filter: Filter<TSchema>,
update: UpdateFilter<TSchema>
): Promise<TSchema> {
): Promise<WithId<TSchema>> {
const item = await model.findOneAndUpdate(filter, update, {
upsert: true,
});
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from 'mongodb';
import { ObjectId, WithId } from 'mongodb';
import type { AnyBulkWriteOperation, OptionalId, UpdateFilter } from 'mongodb';
import { Hooks } from './hooks';

Expand Down Expand Up @@ -45,8 +45,8 @@ export type ProjectionType<
TSchema extends BaseSchema,
Projection extends Partial<Record<keyof TSchema, number>> | undefined
> = undefined extends Projection
? TSchema
: Pick<TSchema, '_id'> & Pick<TSchema, keyof Projection & keyof TSchema>;
? WithId<TSchema>
: WithId<Pick<TSchema, keyof Projection & keyof TSchema>>;

export function getIds(ids: (string | ObjectId)[] | Set<string>): ObjectId[] {
return [...ids].map((id) => new ObjectId(id));
Expand Down
83 changes: 46 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2154,24 +2154,17 @@ bser@2.1.1:
dependencies:
node-int64 "^0.4.0"

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

bson@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.1.tgz#02e9d649ce017ab14ed258737756c11809963d6c"
integrity sha512-XqFP74pbTVLyLy5KFxVfTUyRrC1mgOlmu/iXHfXqfCKT59jyP9lwbotGfbN59cHBRbJSamZNkrSopjv+N0SqAA==
dependencies:
buffer "^5.6.0"

bson@^4.5.2:
version "4.5.3"
resolved "https://registry.yarnpkg.com/bson/-/bson-4.5.3.tgz#de3783b357a407d935510beb1fbb285fef43bb06"
integrity sha512-qVX7LX79Mtj7B3NPLzCfBiCP6RAsjiV8N63DjlaVVpZW+PFoDTxQ4SeDbSpcqgE6mXksM5CAwZnXxxxn/XwC0g==
bson@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-4.6.0.tgz#15c3b39ba3940c3d915a0c44d51459f4b4fbf1b2"
integrity sha512-8jw1NU1hglS+Da1jDOUYuNcBJ4cNHCFIqzlwoFNnsTOg2R/ox0aTYcTiBN4dzRa9q7Cvy6XErh3L8ReTEb9AQQ==
dependencies:
buffer "^5.6.0"

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

mongodb-connection-string-url@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.0.0.tgz#72cea65084ffa45655670070efb57bb0a5da46bc"
integrity sha512-M0I1vyLoq5+HQTuPSJWbt+hIXsMCfE8sS1fS5mvP9R2DOMoi2ZD32yWqgBIITyu0dFu4qtS50erxKjvUeBiyog==
mongodb-connection-string-url@^2.0.0, mongodb-connection-string-url@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.2.0.tgz#e2422bae91a953dc4ae5882e401301f5be39a227"
integrity sha512-U0cDxLUrQrl7DZA828CA+o69EuWPWEJTwdMPozyd7cy/dbtncUZczMw7wRHcwMD7oKOn0NM2tF9jdf5FFVW9CA==
dependencies:
"@types/whatwg-url" "^8.2.1"
whatwg-url "^9.1.0"
whatwg-url "^11.0.0"

mongodb-memory-server-core@8.0.0:
version "8.0.0"
Expand Down Expand Up @@ -5734,14 +5727,25 @@ mongodb@4.1.1:
optionalDependencies:
saslprep "^1.0.0"

mongodb@4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.2.1.tgz#c167db158ab0bf6552b3f9c91b396cb4100c2f04"
integrity sha512-nDC+ulM/Ea3Q2VG5eemuGfB7T4ORwrtKegH2XW9OLlUBgQF6OTNrzFCS1Z3SJGVA+T0Sr1xBYV6DMnp0A7us0g==
dependencies:
bson "^4.6.0"
denque "^2.0.1"
mongodb-connection-string-url "^2.2.0"
optionalDependencies:
saslprep "^1.0.3"

mongodb@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.1.3.tgz#8bf24d782ba3f3833201f4e60b0307d87980ba71"
integrity sha512-lHvTqODBiSpuqjpCj48DOyYWS6Iq6ElJNUiH9HWdQtONyOfjgsKzJULipWduMGsSzaNO4nFi/kmlMFCLvjox/Q==
version "4.2.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.2.0.tgz#7ef94ab0613a2fd890763260fdac20cd099d0d7f"
integrity sha512-lg3MJ9dAKxhogRnIB6/j63gfD7JryZwRC0nNzZ82RhENw4nCmscZVqRfOmNzTvSNndJx9ZhxZpm9JvnKuH/GTA==
dependencies:
bson "^4.5.2"
bson "^4.5.4"
denque "^2.0.1"
mongodb-connection-string-url "^2.0.0"
mongodb-connection-string-url "^2.2.0"
optionalDependencies:
saslprep "^1.0.3"

Expand Down Expand Up @@ -7402,10 +7406,10 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"

tr46@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240"
integrity sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==
tr46@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-3.0.0.tgz#555c4e297a950617e8eeddef633c87d4d9d6cbf9"
integrity sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==
dependencies:
punycode "^2.1.1"

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

webidl-conversions@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"
integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==

whatwg-encoding@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"
Expand All @@ -7755,6 +7764,14 @@ whatwg-mimetype@^2.3.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==

whatwg-url@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-11.0.0.tgz#0a849eebb5faf2119b901bb76fd795c2848d4018"
integrity sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==
dependencies:
tr46 "^3.0.0"
webidl-conversions "^7.0.0"

whatwg-url@^8.0.0, whatwg-url@^8.5.0:
version "8.5.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.5.0.tgz#7752b8464fc0903fec89aa9846fc9efe07351fd3"
Expand All @@ -7764,14 +7781,6 @@ whatwg-url@^8.0.0, whatwg-url@^8.5.0:
tr46 "^2.0.2"
webidl-conversions "^6.1.0"

whatwg-url@^9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-9.1.0.tgz#1b112cf237d72cd64fa7882b9c3f6234a1c3050d"
integrity sha512-CQ0UcrPHyomtlOCot1TL77WyMIm/bCwrJ2D6AOKGwEczU9EpyoqAokfqrf/MioU9kHcMsmJZcg1egXix2KYEsA==
dependencies:
tr46 "^2.1.0"
webidl-conversions "^6.1.0"

which-boxed-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"
Expand Down

0 comments on commit 496e109

Please sign in to comment.