From 496e109200c522e2b7c96ee06b0899869fc595cf Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Thu, 25 Nov 2021 12:42:55 +0100 Subject: [PATCH] feat: Use mongodb v4.2.1 The following change in `mongodb` requires changes in the return types of `find*` methods to include `WithId`: - https://github.com/mongodb/node-mongodb-native/pull/3039 --- package.json | 4 +-- src/model.ts | 6 ++-- src/utils.ts | 6 ++-- yarn.lock | 83 +++++++++++++++++++++++++++++----------------------- 4 files changed, 54 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 2bb9c0c9..596c16fc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -85,7 +85,7 @@ "typescript": "4.5.2" }, "peerDependencies": { - "mongodb": ">=4.1.1" + "mongodb": ">=4.2.1" }, "commitlint": { "extends": [ diff --git a/src/model.ts b/src/model.ts index fc799af3..3f9e9c86 100644 --- a/src/model.ts +++ b/src/model.ts @@ -115,7 +115,7 @@ export interface Model Promise; - upsert: (filter: Filter, update: UpdateFilter) => Promise; + upsert: (filter: Filter, update: UpdateFilter) => Promise>; } function abstractMethod(): void { @@ -506,7 +506,7 @@ export function build) - .toArray(); + .toArray() as unknown as ProjectionType[]; } ); @@ -872,7 +872,7 @@ export function build, update: UpdateFilter - ): Promise { + ): Promise> { const item = await model.findOneAndUpdate(filter, update, { upsert: true, }); diff --git a/src/utils.ts b/src/utils.ts index 23a973e6..320bd677 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { ObjectId } from 'mongodb'; +import { ObjectId, WithId } from 'mongodb'; import type { AnyBulkWriteOperation, OptionalId, UpdateFilter } from 'mongodb'; import { Hooks } from './hooks'; @@ -45,8 +45,8 @@ export type ProjectionType< TSchema extends BaseSchema, Projection extends Partial> | undefined > = undefined extends Projection - ? TSchema - : Pick & Pick; + ? WithId + : WithId>; export function getIds(ids: (string | ObjectId)[] | Set): ObjectId[] { return [...ids].map((id) => new ObjectId(id)); diff --git a/yarn.lock b/yarn.lock index f9bbc877..fa650d92 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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"