From 8a39bfc451ebd8595a5c560bbdc641919df0a94c Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Mon, 10 Jun 2024 20:11:53 -0700 Subject: [PATCH 01/10] npm install mongoose@6 The goal is to get to v8, the current version. But [1] advises to go major version by major version instead of making an abrupt jump. mongoose@6 needs mongodb@4, but this requirement is already satisfied. [1]: https://mongoosejs.com/docs/migrating_to_6.html --- package-lock.json | 278 +++++++--------------------------------------- package.json | 2 +- 2 files changed, 43 insertions(+), 237 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32b36716..8ab106f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "lusca": "^1.7.0", "markdown-it": "^14.1.0", "markdown-it-texmath": "^1.0.0", - "mongoose": "^5.13.20", + "mongoose": "^6.13.0", "nodemailer": "^6.9.9", "path": "0.12.7", "sjcl": "1.0.7", @@ -2224,14 +2224,6 @@ "@types/node": "*" } }, - "node_modules/@types/bson": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.5.tgz", - "integrity": "sha512-vVLwMUqhYJSQ/WKcE60eFqcyuWse5fGH+NMAXHuKrUAPoryq3ATxk5o4bgYNtg5aOM4APVg7Hnb3ASqUYG0PKg==", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/chai": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz", @@ -2392,15 +2384,6 @@ "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==", "dev": true }, - "node_modules/@types/mongodb": { - "version": "3.6.20", - "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.6.20.tgz", - "integrity": "sha512-WcdpPJCakFzcWWD9juKoZbRtQxKIMYF/JIAM4JrNHrMcnJL6/a2NWjXxW7fo9hxboxxkg+icff8d7+WIEvKgYQ==", - "dependencies": { - "@types/bson": "*", - "@types/node": "*" - } - }, "node_modules/@types/mongoose": { "version": "5.11.97", "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.11.97.tgz", @@ -3856,11 +3839,6 @@ "url": "https://opencollective.com/webpack" } }, - "node_modules/core-util-is": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" - }, "node_modules/cp-file": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/cp-file/-/cp-file-6.2.0.tgz", @@ -3999,14 +3977,6 @@ "node": ">=4" } }, - "node_modules/denque": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", - "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", - "engines": { - "node": ">=0.10" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -5641,11 +5611,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -5990,9 +5955,12 @@ } }, "node_modules/kareem": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.2.tgz", - "integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ==" + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==", + "engines": { + "node": ">=12.0.0" + } }, "node_modules/katex": { "version": "0.16.10", @@ -6607,9 +6575,9 @@ } }, "node_modules/mongodb": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.1.tgz", - "integrity": "sha512-MBuyYiPUPRTqfH2dV0ya4dcr2E5N52ocBuZ8Sgg/M030nGF78v855B3Z27mZJnp8PxjnUquEnAtjOsphgMZOlQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.2.tgz", + "integrity": "sha512-mLV7SEiov2LHleRJPMPrK2PMyhXFZt2UQLC4VD4pnth3jMjYKHhtqfwwkkvS/NXuo/Fp3vbhaNcXrIDaLRb9Tg==", "dependencies": { "bson": "^4.7.2", "mongodb-connection-string-url": "^2.6.0", @@ -6705,153 +6673,50 @@ "dev": true }, "node_modules/mongoose": { - "version": "5.13.20", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.20.tgz", - "integrity": "sha512-TjGFa/XnJYt+wLmn8y9ssjyO2OhBMeEBtOHb9iJM16EWu2Du6L1Q6zSiEK2ziyYQM8agb4tumNIQFzqbxId7MA==", - "dependencies": { - "@types/bson": "1.x || 4.0.x", - "@types/mongodb": "^3.5.27", - "bson": "^1.1.4", - "kareem": "2.3.2", - "mongodb": "3.7.4", - "mongoose-legacy-pluralize": "1.0.2", - "mpath": "0.8.4", - "mquery": "3.2.5", - "ms": "2.1.2", - "optional-require": "1.0.x", - "regexp-clone": "1.0.0", - "safe-buffer": "5.2.1", - "sift": "13.5.2", - "sliced": "1.0.1" + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.13.0.tgz", + "integrity": "sha512-mieZBTtRIqA2xCGgl9Hlcr6fXU+AKNSOdeKfMYrb/IgdL3M/bDO4kYftsItIy86XyAoT5xV28alfCbMocFG8oA==", + "dependencies": { + "bson": "^4.7.2", + "kareem": "2.5.1", + "mongodb": "4.17.2", + "mpath": "0.9.0", + "mquery": "4.0.3", + "ms": "2.1.3", + "sift": "16.0.1" }, "engines": { - "node": ">=4.0.0" + "node": ">=12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/mongoose" } }, - "node_modules/mongoose-legacy-pluralize": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", - "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==", - "peerDependencies": { - "mongoose": "*" - } - }, - "node_modules/mongoose/node_modules/bl": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", - "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", - "dependencies": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" - } - }, - "node_modules/mongoose/node_modules/bson": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", - "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", - "engines": { - "node": ">=0.6.19" - } - }, - "node_modules/mongoose/node_modules/mongodb": { - "version": "3.7.4", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.4.tgz", - "integrity": "sha512-K5q8aBqEXMwWdVNh94UQTwZ6BejVbFhh1uB6c5FKtPE9eUMZPUO3sRZdgIEcHSrAWmxzpG/FeODDKL388sqRmw==", - "dependencies": { - "bl": "^2.2.1", - "bson": "^1.1.4", - "denque": "^1.4.1", - "optional-require": "^1.1.8", - "safe-buffer": "^5.1.2" - }, - "engines": { - "node": ">=4" - }, - "optionalDependencies": { - "saslprep": "^1.0.0" - }, - "peerDependenciesMeta": { - "aws4": { - "optional": true - }, - "bson-ext": { - "optional": true - }, - "kerberos": { - "optional": true - }, - "mongodb-client-encryption": { - "optional": true - }, - "mongodb-extjson": { - "optional": true - }, - "snappy": { - "optional": true - } - } - }, - "node_modules/mongoose/node_modules/mongodb/node_modules/optional-require": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", - "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", - "dependencies": { - "require-at": "^1.0.6" - }, - "engines": { - "node": ">=4" - } + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/mpath": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz", - "integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", "engines": { "node": ">=4.0.0" } }, "node_modules/mquery": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", - "integrity": "sha512-VjOKHHgU84wij7IUoZzFRU07IAxd5kWJaDmyUzQlbjHjyoeK5TNeeo8ZsFDtTYnSgpW6n/nMNIHvE3u8Lbrf4A==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.3.tgz", + "integrity": "sha512-J5heI+P08I6VJ2Ky3+33IpCdAvlYGTSUjwTPxkAr8i8EoduPMBX2OY/wa3IKZIQl7MU4SbFk8ndgSKyB/cl1zA==", "dependencies": { - "bluebird": "3.5.1", - "debug": "3.1.0", - "regexp-clone": "^1.0.0", - "safe-buffer": "5.1.2", - "sliced": "1.0.1" + "debug": "4.x" }, "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/mquery/node_modules/bluebird": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", - "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" - }, - "node_modules/mquery/node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dependencies": { - "ms": "2.0.0" + "node": ">=12.0.0" } }, - "node_modules/mquery/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" - }, - "node_modules/mquery/node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -7288,14 +7153,6 @@ "wrappy": "1" } }, - "node_modules/optional-require": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.0.3.tgz", - "integrity": "sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==", - "engines": { - "node": ">=4" - } - }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -7588,11 +7445,6 @@ "node": ">= 0.6.0" } }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -7815,25 +7667,6 @@ "node": ">=4" } }, - "node_modules/readable-stream": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", - "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", - "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "node_modules/readable-stream/node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -7858,11 +7691,6 @@ "node": ">= 10.13.0" } }, - "node_modules/regexp-clone": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", - "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" - }, "node_modules/release-zalgo": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", @@ -7875,14 +7703,6 @@ "node": ">=4" } }, - "node_modules/require-at": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", - "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==", - "engines": { - "node": ">=4" - } - }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -8032,18 +7852,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "node_modules/saslprep": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", - "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", - "optional": true, - "dependencies": { - "sparse-bitfield": "^3.0.3" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -8175,9 +7983,9 @@ } }, "node_modules/sift": { - "version": "13.5.2", - "resolved": "https://registry.npmjs.org/sift/-/sift-13.5.2.tgz", - "integrity": "sha512-+gxdEOMA2J+AI+fVsCqeNn7Tgx3M9ZN9jdi95939l1IJ8cZsqS8sqpJyOkic2SJk+1+98Uwryt/gL6XDaV+UZA==" + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz", + "integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ==" }, "node_modules/signal-exit": { "version": "3.0.7", @@ -8205,11 +8013,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/sliced": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", - "integrity": "sha512-VZBmZP8WU3sMOZm1bdgTadsQbcscK0UM8oKxKVBs4XAhUo2Xxzm/OFMGBkPusxw9xL3Uy8LrzEqGqJhclsr0yA==" - }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -8390,6 +8193,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -8397,7 +8201,8 @@ "node_modules/string_decoder/node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true }, "node_modules/string-width": { "version": "4.2.3", @@ -9218,7 +9023,8 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true }, "node_modules/util/node_modules/inherits": { "version": "2.0.3", diff --git a/package.json b/package.json index 8318a50e..c5df8fc0 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "lusca": "^1.7.0", "markdown-it": "^14.1.0", "markdown-it-texmath": "^1.0.0", - "mongoose": "^5.13.20", + "mongoose": "^6.13.0", "nodemailer": "^6.9.9", "path": "0.12.7", "sjcl": "1.0.7", From 0a8624d193d447e80f7c3a1765290009e491487b Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 06:26:11 -0700 Subject: [PATCH 02/10] [Mongoose] Fix Card.findOne typing Resolves this build error: ```log src/models/CardsMongoDB.ts:86:23 - error TS2769: No overload matches this call. Overload 1 of 3, '(filter?: FilterQuery | undefined, projection?: ProjectionType | null | undefined, options?: QueryOptions | null | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. Type 'Partial' is not assignable to type 'RootQuerySelector'. Types of property '$where' are incompatible. Type 'Record | undefined' is not assignable to type 'string | Function | undefined'. Type 'Record' is not assignable to type 'string | Function | undefined'. Type 'Record' is missing the following properties from type 'Function': apply, call, bind, prototype, and 5 more. Overload 2 of 3, '(filter?: FilterQuery | undefined, projection?: ProjectionType | null | undefined, callback?: Callback<(Document & Omit<...>) | null> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. Overload 3 of 3, '(filter?: FilterQuery | undefined, callback?: Callback<(Document & Omit, never>) | null> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. 86 return Card.findOne(query).select(projection).exec(); ~~~~~ ``` --- src/models/CardsMongoDB.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/CardsMongoDB.ts b/src/models/CardsMongoDB.ts index 0d65ae6b..fa259eaf 100644 --- a/src/models/CardsMongoDB.ts +++ b/src/models/CardsMongoDB.ts @@ -81,7 +81,7 @@ export function read( "title description descriptionHTML tags urgency createdById isPublic", ): Promise { payload = sanitizeQuery(payload); - const query: Partial = { createdById: payload.userIDInApp }; + const query: FilterQuery = { createdById: payload.userIDInApp }; if (payload.cardID) { query._id = payload.cardID; } return Card.findOne(query).select(projection).exec(); } From f5ba28cbf268c0119c61bf4e4aa560eb4c03ce83 Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 06:42:41 -0700 Subject: [PATCH 03/10] [Mongoose] Stronger typing for Card.sort object Fixes this build error: ```log src/models/CardsMongoDB.ts:260:11 - error TS2345: Argument of type 'object' is not assignable to parameter of type 'string | { [key: string]: SortOrder | { $meta: "textScore"; }; } | [string, SortOrder][] | null | undefined'. 260 .sort(queryObject.sortCriteria) ~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- src/models/CardsMongoDB.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/models/CardsMongoDB.ts b/src/models/CardsMongoDB.ts index fa259eaf..fbd0901b 100644 --- a/src/models/CardsMongoDB.ts +++ b/src/models/CardsMongoDB.ts @@ -6,7 +6,7 @@ * @module */ -import { FilterQuery } from "mongoose"; +import { FilterQuery, SortOrder } from "mongoose"; import { BaseResponse } from "../types"; import * as MetadataDB from "./MetadataMongoDB"; import { Card, ICard, ICardRaw } from "./mongoose_models/CardSchema"; @@ -135,11 +135,15 @@ interface ServerAddedSearchCardParams { isPublic?: boolean; } +interface SortCriteria { + [key: string]: SortOrder | { $meta: "textScore" }; +} + interface CardQuery { filter: FilterQuery; projection: string; limit: number; - sortCriteria: object; + sortCriteria: SortCriteria; } const kCardsSearchProjection = "title tags urgency"; @@ -234,7 +238,7 @@ function computeInternalQueryFromClientQuery( mandatoryFields.push({ createdAt: dateQuery }); } - const sortCriteria = clientQuery.queryString + const sortCriteria: SortCriteria = clientQuery.queryString ? { score: { $meta: "textScore" } } : {}; From 09a4cbd37c5dc8672943372c225c689d1f9ba95e Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 06:54:03 -0700 Subject: [PATCH 04/10] [Mongoose] Pass `unique: true` instead of `unique: [true, "x must be unique"]` Fixes these errors: ```log src/models/mongoose_models/Token.ts:19:5 - error TS2322: Type '{ type: StringConstructor; required: true; unique: (string | true)[]; }' is not assignable to type 'SchemaDefinitionProperty | undefined'. Types of property 'unique' are incompatible. Type '(string | true)[]' is not assignable to type 'number | boolean | undefined'. 19 token_id: { ~~~~~~~~ src/models/mongoose_models/UserSchema.ts:28:5 - error TS2322: Type '{ type: StringConstructor; required: true; unique: (string | true)[]; immutable: true; match: RegExp; }' is not assignable to type 'SchemaDefinitionProperty | undefined'. Types of property 'unique' are incompatible. Type '(string | true)[]' is not assignable to type 'number | boolean | undefined'. 28 username: { ~~~~~~~~ ``` AFAICT, the custom string doesn't seem like it was ever supported in v5 [1]. [1]: https://mongoosejs.com/docs/5.x/docs/validation.html#the-unique-option-is-not-a-validator --- src/models/mongoose_models/Token.ts | 2 +- src/models/mongoose_models/UserSchema.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/mongoose_models/Token.ts b/src/models/mongoose_models/Token.ts index 2922c7a2..36d94337 100644 --- a/src/models/mongoose_models/Token.ts +++ b/src/models/mongoose_models/Token.ts @@ -19,7 +19,7 @@ const tokenSchema = new Schema( token_id: { type: String, required: true, - unique: [true, "This token already exists"], + unique: true, }, userIDInApp: { type: Number, immutable: true }, username: { type: String, immutable: true }, diff --git a/src/models/mongoose_models/UserSchema.ts b/src/models/mongoose_models/UserSchema.ts index bf1dabc0..6f8447a6 100644 --- a/src/models/mongoose_models/UserSchema.ts +++ b/src/models/mongoose_models/UserSchema.ts @@ -28,7 +28,7 @@ const userSchema = new Schema( username: { type: String, required: true, - unique: [true, "This username is already taken"], + unique: true, immutable: true, match: /[_\-A-Za-z0-9]+/, }, From 5dbb4c71d169a94b3f6281b269f609f1c7b9bcab Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 06:57:39 -0700 Subject: [PATCH 05/10] [Mongoose] Fix Metadata.findOne typing ```log src/models/MetadataMongoDB.ts:117:46 - error TS2769: No overload matches this call. Overload 1 of 3, '(filter?: FilterQuery | undefined, projection?: ProjectionType | null | undefined, options?: QueryOptions<...> | ... 1 more ... | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. Type 'Partial' is not assignable to type 'RootQuerySelector'. Types of property '$where' are incompatible. Type 'Record | undefined' is not assignable to type 'string | Function | undefined'. Overload 2 of 3, '(filter?: FilterQuery | undefined, projection?: ProjectionType | null | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. Overload 3 of 3, '(filter?: FilterQuery | undefined, callback?: Callback<(Document & Omit) | null> | undefined): Query<...>', gave the following error. Argument of type 'Partial' is not assignable to parameter of type 'FilterQuery'. 117 const metadataDoc = await Metadata.findOne(metadataQuery).exec(); ~~~~~~~~~~~~~ ``` --- src/models/MetadataMongoDB.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/MetadataMongoDB.ts b/src/models/MetadataMongoDB.ts index 0ad9700a..381787ee 100644 --- a/src/models/MetadataMongoDB.ts +++ b/src/models/MetadataMongoDB.ts @@ -8,6 +8,7 @@ import * as fs from "fs/promises"; +import { FilterQuery } from "mongoose"; import { PUBLIC_USER_USERNAME } from "../config"; import { BaseResponse } from "../types"; import { Card, ICard } from "./mongoose_models/CardSchema"; @@ -94,7 +95,7 @@ type SavedCardParams = { */ export async function update( savedCards: SavedCardParams[], - metadataQuery: Partial | null = null, + metadataQuery: FilterQuery | null = null, attributeName: SortableCardAttribute = "urgency", ): Promise { /* From 46a3e1463c08742e50d26901faf59333531075ca Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 07:05:55 -0700 Subject: [PATCH 06/10] [ES] npm install mongodb@4 This package already existed but as a dependency of Mongoose. This commit brings it to the top-level dependencies so that we can take advantage of MongoDB's TS types. [1] We had not used @types/mongodb, so removing that package isn't applicable to us. [1]: https://github.com/mongodb/node-mongodb-native/blob/4.0/docs/CHANGES_4.0.0.md#typescript --- package-lock.json | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index 8ab106f9..5744a9ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "lusca": "^1.7.0", "markdown-it": "^14.1.0", "markdown-it-texmath": "^1.0.0", + "mongodb": "^4.17.2", "mongoose": "^6.13.0", "nodemailer": "^6.9.9", "path": "0.12.7", diff --git a/package.json b/package.json index c5df8fc0..4104e177 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "lusca": "^1.7.0", "markdown-it": "^14.1.0", "markdown-it-texmath": "^1.0.0", + "mongodb": "^4.17.2", "mongoose": "^6.13.0", "nodemailer": "^6.9.9", "path": "0.12.7", From 3dc965ade7058cf0ae95da7920ac20ba5eb513a8 Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 07:15:28 -0700 Subject: [PATCH 07/10] [Mongo] Fix return typing for Metadata.deleteMany ```log src/models/MetadataMongoDB.ts:204:3 - error TS2322: Type 'Promise' is not assignable to type 'Promise'. Type 'DeleteResult' is not assignable to type 'void'. 204 return Metadata.deleteMany({ createdById: payload.userIDInApp }).exec(); ~~~~~~ ``` [1]: https://mongoosejs.com/docs/6.x/docs/migrating_to_6.html#mongodb-driver-40 --- src/models/MetadataMongoDB.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/MetadataMongoDB.ts b/src/models/MetadataMongoDB.ts index 381787ee..00df8fd5 100644 --- a/src/models/MetadataMongoDB.ts +++ b/src/models/MetadataMongoDB.ts @@ -8,6 +8,7 @@ import * as fs from "fs/promises"; +import { DeleteResult } from "mongodb"; import { FilterQuery } from "mongoose"; import { PUBLIC_USER_USERNAME } from "../config"; import { BaseResponse } from "../types"; @@ -199,7 +200,7 @@ export async function updatePublicUserMetadata( */ export function deleteAllMetadata( payload: Pick, -): Promise { +): Promise { payload = sanitizeQuery(payload); return Metadata.deleteMany({ createdById: payload.userIDInApp }).exec(); } From bd571b4adafdb951d4eca2d7eb7165c6064855db Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Tue, 11 Jun 2024 07:51:16 -0700 Subject: [PATCH 08/10] [Mongoose] Fix typings for IStreak ```log src/models/mongoose_models/MetadataCardSchema.ts:47:5 - error TS2322: Type '{ type: MapConstructor; default: { cardIDs: never[]; length: number; dailyTarget: number; timeStamp: () => number; }; }' is not assignable to type 'SchemaDefinitionProperty | undefined'. Type '{ type: MapConstructor; default: { cardIDs: never[]; length: number; dailyTarget: number; timeStamp: () => number; }; }' is not assignable to type 'undefined'. 47 streak: { ~~~~~~ ``` --- src/models/DailyTasks.ts | 16 ++++++++++------ src/models/mongoose_models/MetadataCardSchema.ts | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/models/DailyTasks.ts b/src/models/DailyTasks.ts index 647950bb..d6da4c16 100644 --- a/src/models/DailyTasks.ts +++ b/src/models/DailyTasks.ts @@ -9,7 +9,11 @@ import * as mongoDB from "mongodb"; import { FilterQuery, UpdateQuery } from "mongoose"; -import { IMetadata, Metadata } from "./mongoose_models/MetadataCardSchema"; +import { + IMetadata, + IStreakRaw, + Metadata, +} from "./mongoose_models/MetadataCardSchema"; import { closeMongooseConnection } from "./MongooseClient"; /** @@ -27,11 +31,11 @@ async function resetStreaks(): Promise { const metadataDocs = await Metadata.find({ metadataIndex: 0 }).exec(); for (const metadataDoc of metadataDocs) { - const streakObj = { - timeStamp: metadataDoc.streak.get("timeStamp"), - cardIDs: metadataDoc.streak.get("cardIDs"), - length: metadataDoc.streak.get("length"), - dailyTarget: metadataDoc.streak.get("dailyTarget"), + const streakObj: IStreakRaw = { + cardIDs: metadataDoc.streak.get("cardIDs") || [], + length: metadataDoc.streak.get("length") || 0, + dailyTarget: metadataDoc.streak.get("dailyTarget") || 25, + timeStamp: metadataDoc.streak.get("timeStamp") || Date.now(), }; const timeStampDate = (new Date(streakObj.timeStamp)).toDateString(); if (todaysDate !== timeStampDate) { diff --git a/src/models/mongoose_models/MetadataCardSchema.ts b/src/models/mongoose_models/MetadataCardSchema.ts index b3ea2d43..a016205b 100644 --- a/src/models/mongoose_models/MetadataCardSchema.ts +++ b/src/models/mongoose_models/MetadataCardSchema.ts @@ -5,13 +5,15 @@ */ import { Document, model, Schema } from "mongoose"; -export interface IStreak extends Map { +export interface IStreakRaw { cardIDs: Array; length: number; dailyTarget: number; timeStamp: number; } +export type IStreak = IStreakRaw & Map; + interface IMetadataNodeInformationEntry { [id: string]: { urgency: number }; } @@ -47,10 +49,10 @@ const metadataSchema = new Schema( streak: { type: Map, default: { - cardIDs: [], + cardIDs: new Array(), length: 0, dailyTarget: 25, - timeStamp: Date.now, + timeStamp: Date.now(), }, }, cardsAreByDefaultPrivate: { type: Boolean, default: true }, From b58136520a0b501e7cfd4e07c263617b4cc76f36 Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Sat, 15 Jun 2024 10:13:00 -0700 Subject: [PATCH 09/10] [Mongo] Fix typings for setting IStreakRaw ```log src/models/DailyTasks.ts:57:29 - error TS2345: Argument of type '{ updateOne: { filter?: FilterQuery | undefined; update?: UpdateQuery | undefined; }; }[]' is not assignable to parameter of type 'AnyBulkWriteOperation[]'. Type '{ updateOne: { filter?: FilterQuery | undefined; update?: UpdateQuery | undefined; }; }' is not assignable to type 'AnyBulkWriteOperation'. Type '{ updateOne: { filter?: FilterQuery | undefined; update?: UpdateQuery | undefined; }; }' is not assignable to type '{ updateOne: UpdateOneModel; }'. The types of 'updateOne.filter' are incompatible between these types. Type 'FilterQuery | undefined' is not assignable to type 'Filter'. Type 'undefined' is not assignable to type 'Filter'. 57 return Metadata.bulkWrite(bulkWriteOps); ~~~~~~~~~~~~ ``` --- src/models/DailyTasks.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/models/DailyTasks.ts b/src/models/DailyTasks.ts index d6da4c16..5da9abc1 100644 --- a/src/models/DailyTasks.ts +++ b/src/models/DailyTasks.ts @@ -8,9 +8,8 @@ import * as mongoDB from "mongodb"; -import { FilterQuery, UpdateQuery } from "mongoose"; import { - IMetadata, + IMetadataRaw, IStreakRaw, Metadata, } from "./mongoose_models/MetadataCardSchema"; @@ -20,12 +19,7 @@ import { closeMongooseConnection } from "./MongooseClient"; * @description Reset the daily card review streaks. */ async function resetStreaks(): Promise { - const bulkWriteOps: { - updateOne: { - filter?: FilterQuery; - update?: UpdateQuery; - }; - }[] = []; + const bulkWriteOps: mongoDB.AnyBulkWriteOperation[] = []; const currentTimeStamp = Date.now(); const todaysDate = (new Date(currentTimeStamp)).toDateString(); @@ -50,7 +44,14 @@ async function resetStreaks(): Promise { bulkWriteOps.push({ updateOne: { filter: { _id: metadataDoc._id }, - update: { $set: { streak: streakObj } }, + update: { + $set: { + "streak.cardIDs": streakObj.cardIDs, + "streak.length": streakObj.length, + "streak.timeStamp": streakObj.timeStamp, + "streak.dailyTarget": streakObj.dailyTarget, + }, + }, }, }); } From 8c140dd4f6cbe5e2d128a5978572e37adf6d1e62 Mon Sep 17 00:00:00 2001 From: Chege Gitau Date: Sat, 15 Jun 2024 10:19:39 -0700 Subject: [PATCH 10/10] [Mongoose] Fix calls to connect `useNewUrlParser` is `true` by default and should not be specified in client code. [1] `poolSize` has been replaced with `maxPoolSize` which defaults to `100`. [2] [1]: https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options [2]: https://mongoosejs.com/docs/migrating_to_6.html#mongodb-driver-40 --- src/models/MongooseClient.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/models/MongooseClient.ts b/src/models/MongooseClient.ts index 082cabb4..b3d1c044 100644 --- a/src/models/MongooseClient.ts +++ b/src/models/MongooseClient.ts @@ -19,15 +19,14 @@ import { connect, connection, disconnect } from "mongoose"; import { IS_DEV, MONGO_URI } from "../config"; // Already 5 by default, but I might need to increase it one day... -const connectionOptions = { poolSize: 12, useNewUrlParser: true }; let mongoServer: MongoMemoryServer | null = null; if (IS_DEV) { (async () => { mongoServer = await MongoMemoryServer.create(); - await connect(mongoServer.getUri(), connectionOptions); + await connect(mongoServer.getUri()); })(); } else { - connect(MONGO_URI, connectionOptions); + connect(MONGO_URI); } // Get the default connection (this will be registered on mongoose)