From 7b6222f5d3a8cdad6bb993206c30937845935ba8 Mon Sep 17 00:00:00 2001 From: Rhys Date: Mon, 27 Feb 2023 09:12:10 -0500 Subject: [PATCH] chore(deps): bump mongodb-schema, update usage to async await (#484) --- package-lock.json | 207 ++++++------------ package.json | 7 +- src/explorer/fieldTreeItem.ts | 2 +- src/explorer/schemaTreeItem.ts | 14 +- src/language/worker.ts | 7 +- .../suite/explorer/schemaTreeItem.test.ts | 2 +- 6 files changed, 86 insertions(+), 153 deletions(-) diff --git a/package-lock.json b/package-lock.json index 09533640a..64a679992 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,9 +36,8 @@ "mongodb-cloud-info": "^1.1.3", "mongodb-connection-string-url": "^2.5.3", "mongodb-data-service": "^22.1.1", - "mongodb-ns": "^2.4.0", "mongodb-query-parser": "^2.4.6", - "mongodb-schema": "^9.0.0", + "mongodb-schema": "^10.0.0", "numeral": "^2.0.6", "react": "^16.14.0", "react-dom": "^16.14.0", @@ -15402,7 +15401,7 @@ "node_modules/lodash.chunk": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", - "integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=", + "integrity": "sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w==", "optional": true }, "node_modules/lodash.defaults": { @@ -16765,9 +16764,9 @@ } }, "node_modules/mongodb-collection-sample": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/mongodb-collection-sample/-/mongodb-collection-sample-4.5.1.tgz", - "integrity": "sha512-tUCdRLToheOh2Tn+KVdhYtbLifxCo60+wVMf0zxtbZLKPYbZqQaYmyrYTsEunePNJyxIutBWdayX79VJ/Fb2hg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mongodb-collection-sample/-/mongodb-collection-sample-5.0.0.tgz", + "integrity": "sha512-osgcJRgembDXzoMeDVA+IVq/KMkSDdxQz8pPckISf3eHia74o488nIGx4LzdOElpizz97lm1z0tX2OyFXl2RNQ==", "optional": true, "dependencies": { "bson": "^4.0.3", @@ -16775,19 +16774,21 @@ "event-stream": "^4.0.1", "lodash.chunk": "^4.2.0", "lodash.defaults": "^4.2.0", - "mongodb-ns": "^2.2.0", "reservoir": "^0.1.2", - "semver": "^5.7.1", - "yargs": "^15.1.0" + "semver": "^5.7.1" }, "bin": { "mongodb-collection-sample": "bin/mongodb-collection-sample.js" + }, + "optionalDependencies": { + "mongodb-ns": "^2.2.0", + "yargs": "^15.1.0" } }, "node_modules/mongodb-collection-sample/node_modules/ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "optional": true, "engines": { "node": ">=8" @@ -16803,6 +16804,9 @@ }, "engines": { "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, "node_modules/mongodb-collection-sample/node_modules/cliui": { @@ -16890,26 +16894,26 @@ } }, "node_modules/mongodb-collection-sample/node_modules/string-width": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", - "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "optional": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.0" + "strip-ansi": "^6.0.1" }, "engines": { "node": ">=8" } }, "node_modules/mongodb-collection-sample/node_modules/strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "optional": true, "dependencies": { - "ansi-regex": "^5.0.0" + "ansi-regex": "^5.0.1" }, "engines": { "node": ">=8" @@ -16918,7 +16922,7 @@ "node_modules/mongodb-collection-sample/node_modules/which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==", "optional": true }, "node_modules/mongodb-collection-sample/node_modules/wrap-ansi": { @@ -16936,9 +16940,9 @@ } }, "node_modules/mongodb-collection-sample/node_modules/y18n": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", - "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "optional": true }, "node_modules/mongodb-collection-sample/node_modules/yargs": { @@ -17366,13 +17370,11 @@ } }, "node_modules/mongodb-schema": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/mongodb-schema/-/mongodb-schema-9.0.0.tgz", - "integrity": "sha512-anSDZOhZ67Kv6npMHDD0UiG1+5Q+NgMObYaK7FDGpvMTAJtp+yggcnom/g39q/IjmBVMnaaxdRROTu5wAKnzNQ==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/mongodb-schema/-/mongodb-schema-10.0.0.tgz", + "integrity": "sha512-7dRmwwB2g3a0qUDBafADkJv36aQPXW5Cf4ycFQqiABtU43Aj2eWOMYhP6lnoqQDwc7lWMg2q/TQs7piPzDAToA==", "dependencies": { - "async": "^3.2.0", - "event-stream": "^4.0.1", - "lodash": "^4.17.20", + "lodash": "^4.17.21", "progress": "^2.0.3", "reservoir": "^0.1.2" }, @@ -17380,12 +17382,12 @@ "mongodb-schema": "bin/mongodb-schema" }, "optionalDependencies": { + "bson": "^5.0.1", "cli-table": "^0.3.4", "js-yaml": "^4.0.0", - "mongodb": "^3.6.4", - "mongodb-collection-sample": "^4.4.2", - "mongodb-extended-json": "^1.6.2", - "mongodb-ns": "^2.0.0", + "mongodb": "^4.13.0", + "mongodb-collection-sample": "^5.0.0", + "mongodb-ns": "^2.4.0", "numeral": "^2.0.6", "stats-lite": "^2.0.0" } @@ -17396,18 +17398,13 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "optional": true }, - "node_modules/mongodb-schema/node_modules/async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" - }, "node_modules/mongodb-schema/node_modules/bson": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", - "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/bson/-/bson-5.0.1.tgz", + "integrity": "sha512-y09gBGusgHtinMon/GVbv1J6FrXhnr/+6hqLlSmEFzkz6PodqF6TxjyvfvY3AfO+oG1mgUtbC86xSbOlwvM62Q==", "optional": true, "engines": { - "node": ">=0.6.19" + "node": ">=14.20.1" } }, "node_modules/mongodb-schema/node_modules/js-yaml": { @@ -17422,45 +17419,6 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/mongodb-schema/node_modules/mongodb": { - "version": "3.6.9", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.9.tgz", - "integrity": "sha512-1nSCKgSunzn/CXwgOWgbPHUWOO5OfERcuOWISmqd610jn0s8BU9K4879iJVabqgpPPbA6hO7rG48eq+fGED3Mg==", - "optional": true, - "dependencies": { - "bl": "^2.2.1", - "bson": "^1.1.4", - "denque": "^1.4.1", - "optional-require": "^1.0.3", - "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/mongodb-tools": { "resolved": "git+ssh://git@github.com/mongodb-js/mongodb-tools.git#0d1a90f49796c41f6d47c7c7999fe384014a16a0", "dev": true, @@ -20533,7 +20491,7 @@ "node_modules/reservoir": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/reservoir/-/reservoir-0.1.2.tgz", - "integrity": "sha1-8I6sFWSVEjA5y8XuBvP1iXnkVgU=" + "integrity": "sha512-ysyw95gLBhMAzqIVrOHJ2yMrRQHAS+h97bS9r89Z7Ou10Jhl2k5KOsyjPqrxL+WfEanov0o5bAMVzQ7AKyENHA==" }, "node_modules/resolve": { "version": "1.20.0", @@ -36926,7 +36884,7 @@ "lodash.chunk": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", - "integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=", + "integrity": "sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w==", "optional": true }, "lodash.defaults": { @@ -38010,9 +37968,9 @@ } }, "mongodb-collection-sample": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/mongodb-collection-sample/-/mongodb-collection-sample-4.5.1.tgz", - "integrity": "sha512-tUCdRLToheOh2Tn+KVdhYtbLifxCo60+wVMf0zxtbZLKPYbZqQaYmyrYTsEunePNJyxIutBWdayX79VJ/Fb2hg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mongodb-collection-sample/-/mongodb-collection-sample-5.0.0.tgz", + "integrity": "sha512-osgcJRgembDXzoMeDVA+IVq/KMkSDdxQz8pPckISf3eHia74o488nIGx4LzdOElpizz97lm1z0tX2OyFXl2RNQ==", "optional": true, "requires": { "bson": "^4.0.3", @@ -38027,9 +37985,9 @@ }, "dependencies": { "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "optional": true }, "ansi-styles": { @@ -38108,29 +38066,29 @@ "optional": true }, "string-width": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", - "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "optional": true, "requires": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.0" + "strip-ansi": "^6.0.1" } }, "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "optional": true, "requires": { - "ansi-regex": "^5.0.0" + "ansi-regex": "^5.0.1" } }, "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==", "optional": true }, "wrap-ansi": { @@ -38145,9 +38103,9 @@ } }, "y18n": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", - "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "optional": true }, "yargs": { @@ -38516,19 +38474,17 @@ } }, "mongodb-schema": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/mongodb-schema/-/mongodb-schema-9.0.0.tgz", - "integrity": "sha512-anSDZOhZ67Kv6npMHDD0UiG1+5Q+NgMObYaK7FDGpvMTAJtp+yggcnom/g39q/IjmBVMnaaxdRROTu5wAKnzNQ==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/mongodb-schema/-/mongodb-schema-10.0.0.tgz", + "integrity": "sha512-7dRmwwB2g3a0qUDBafADkJv36aQPXW5Cf4ycFQqiABtU43Aj2eWOMYhP6lnoqQDwc7lWMg2q/TQs7piPzDAToA==", "requires": { - "async": "^3.2.0", + "bson": "^5.0.1", "cli-table": "^0.3.4", - "event-stream": "^4.0.1", "js-yaml": "^4.0.0", - "lodash": "^4.17.20", - "mongodb": "^3.6.4", - "mongodb-collection-sample": "^4.4.2", - "mongodb-extended-json": "^1.6.2", - "mongodb-ns": "^2.0.0", + "lodash": "^4.17.21", + "mongodb": "^4.13.0", + "mongodb-collection-sample": "^5.0.0", + "mongodb-ns": "^2.4.0", "numeral": "^2.0.6", "progress": "^2.0.3", "reservoir": "^0.1.2", @@ -38541,15 +38497,10 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "optional": true }, - "async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" - }, "bson": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", - "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/bson/-/bson-5.0.1.tgz", + "integrity": "sha512-y09gBGusgHtinMon/GVbv1J6FrXhnr/+6hqLlSmEFzkz6PodqF6TxjyvfvY3AfO+oG1mgUtbC86xSbOlwvM62Q==", "optional": true }, "js-yaml": { @@ -38560,20 +38511,6 @@ "requires": { "argparse": "^2.0.1" } - }, - "mongodb": { - "version": "3.6.9", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.9.tgz", - "integrity": "sha512-1nSCKgSunzn/CXwgOWgbPHUWOO5OfERcuOWISmqd610jn0s8BU9K4879iJVabqgpPPbA6hO7rG48eq+fGED3Mg==", - "optional": true, - "requires": { - "bl": "^2.2.1", - "bson": "^1.1.4", - "denque": "^1.4.1", - "optional-require": "^1.0.3", - "safe-buffer": "^5.1.2", - "saslprep": "^1.0.0" - } } } }, @@ -41013,7 +40950,7 @@ "reservoir": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/reservoir/-/reservoir-0.1.2.tgz", - "integrity": "sha1-8I6sFWSVEjA5y8XuBvP1iXnkVgU=" + "integrity": "sha512-ysyw95gLBhMAzqIVrOHJ2yMrRQHAS+h97bS9r89Z7Ou10Jhl2k5KOsyjPqrxL+WfEanov0o5bAMVzQ7AKyENHA==" }, "resolve": { "version": "1.20.0", diff --git a/package.json b/package.json index 2f9219f00..b9a6e5f51 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,8 @@ "test-webview": "jest", "posttest": "mongodb-runner stop --port=27018", "vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production", - "check": "npm run lint && npm run check-dependencies", - "check-dependencies": "depcheck", + "check": "npm run lint && npm run depcheck", + "depcheck": "depcheck", "package": "npm list --production --parseable --depth=99999 --loglevel=info || true && vsce package --githubBranch main", "local-install": "npm run package && code --install-extension ./mongodb-vscode-*.vsix", "check-vsix-size": "ts-node ./scripts/check-vsix-size.ts", @@ -1021,9 +1021,8 @@ "mongodb-cloud-info": "^1.1.3", "mongodb-connection-string-url": "^2.5.3", "mongodb-data-service": "^22.1.1", - "mongodb-ns": "^2.4.0", "mongodb-query-parser": "^2.4.6", - "mongodb-schema": "^9.0.0", + "mongodb-schema": "^10.0.0", "numeral": "^2.0.6", "react": "^16.14.0", "react-dom": "^16.14.0", diff --git a/src/explorer/fieldTreeItem.ts b/src/explorer/fieldTreeItem.ts index ff3ed09c7..20414c9e8 100644 --- a/src/explorer/fieldTreeItem.ts +++ b/src/explorer/fieldTreeItem.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -const path = require('path'); +import path from 'path'; import { getImagesPath } from '../extensionConstants'; import TreeItemParent from './treeItemParentInterface'; diff --git a/src/explorer/schemaTreeItem.ts b/src/explorer/schemaTreeItem.ts index 6b4b06d7a..a052f3320 100644 --- a/src/explorer/schemaTreeItem.ts +++ b/src/explorer/schemaTreeItem.ts @@ -1,6 +1,6 @@ import * as util from 'util'; import * as vscode from 'vscode'; -import parseSchema = require('mongodb-schema'); +import parseSchema from 'mongodb-schema'; import path from 'path'; import { createLogger } from '../logging'; @@ -96,7 +96,7 @@ export default class SchemaTreeItem return element; } - async getSchema(): Promise { + async getSchema(): Promise | undefined> { const namespace = `${this.databaseName}.${this.collectionName}`; let documents; try { @@ -112,18 +112,16 @@ export default class SchemaTreeItem void vscode.window.showErrorMessage( `Get schema failed: ${formatError(error).message}` ); - return []; + return; } log.info(`parsing schema for namespace ${namespace}`); if (!documents || documents.length === 0) { - return []; + return; } try { - const runParseSchema = util.promisify(parseSchema); - const schema = await runParseSchema(documents); - return schema; + return await parseSchema(documents); } catch (parseError) { throw new Error( `Unable to parse schema: ${(parseError as Error)?.message}` @@ -199,7 +197,7 @@ export default class SchemaTreeItem this.cacheIsUpToDate = true; - if (!schema || !schema.fields || schema.fields.length < 1) { + if (!schema?.fields || schema.fields.length < 1) { void vscode.window.showInformationMessage( 'No documents were found when attempting to parse schema.' ); diff --git a/src/language/worker.ts b/src/language/worker.ts index 5feda3d26..b1d25c94f 100644 --- a/src/language/worker.ts +++ b/src/language/worker.ts @@ -2,9 +2,9 @@ import { CliServiceProvider } from '@mongosh/service-provider-server'; import { CompletionItemKind } from 'vscode-languageserver/node'; import { EJSON, Document } from 'bson'; import { ElectronRuntime } from '@mongosh/browser-runtime-electron'; -import { promisify } from 'util'; -import parseSchema = require('mongodb-schema'); +import parseSchema from 'mongodb-schema'; import { parentPort, workerData } from 'worker_threads'; + import { PlaygroundResult, PlaygroundDebug, @@ -106,8 +106,7 @@ const findAndParse = async ( } try { - const runParseSchema = promisify(parseSchema); - const schema = await runParseSchema(documents); + const schema = await parseSchema(documents); if (!schema || !schema.fields) { return []; diff --git a/src/test/suite/explorer/schemaTreeItem.test.ts b/src/test/suite/explorer/schemaTreeItem.test.ts index 82ba2c0a7..cf7e3df6f 100644 --- a/src/test/suite/explorer/schemaTreeItem.test.ts +++ b/src/test/suite/explorer/schemaTreeItem.test.ts @@ -208,7 +208,7 @@ suite('SchemaTreeItem Test Suite', function () { assert(false, 'Didnt expect to succeed.'); } catch (error: any) { const expectedMessage = - 'Unable to parse schema: Unknown input type for `docs`. Must be an array, stream or MongoDB Cursor.'; + "Unable to parse schema: Cannot use 'in' operator to search for 'stream' in invalid schema to parse"; assert.strictEqual( error.message,