From 3c9005adfa84987ba3338c8a113152e063f16a32 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Wed, 1 Dec 2021 20:30:13 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20apply=20tell-don=E2=80=99t-ask=20pr?= =?UTF-8?q?inciple=20(#371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-and-build.yaml | 2 +- package-lock.json | 246 ++++++++--------- package.json | 14 +- src/language/mongoDBService.ts | 2 + src/language/visitor.ts | 381 ++++++++++---------------- 5 files changed, 273 insertions(+), 372 deletions(-) diff --git a/.github/workflows/test-and-build.yaml b/.github/workflows/test-and-build.yaml index 11dcf6fb7..4f3537eae 100644 --- a/.github/workflows/test-and-build.yaml +++ b/.github/workflows/test-and-build.yaml @@ -49,7 +49,7 @@ jobs: if: ${{ runner.os == 'Windows' }} shell: powershell run: | - npm install --global node-gyp@latest + npm install --global node-gyp@7.1.2 npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"} - name: Install Dependencies diff --git a/package-lock.json b/package-lock.json index c7722c48e..56a38cd2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,10 +18,10 @@ "@iconify/react": "^1.1.4", "@leafygreen-ui/logo": "^6.1.0", "@leafygreen-ui/toggle": "^7.0.4", - "@mongosh/browser-runtime-electron": "^1.1.2", - "@mongosh/i18n": "^1.1.2", - "@mongosh/service-provider-server": "^1.1.2", - "@mongosh/shell-api": "^1.1.2", + "@mongosh/browser-runtime-electron": "^1.1.4", + "@mongosh/i18n": "^1.1.4", + "@mongosh/service-provider-server": "^1.1.4", + "@mongosh/shell-api": "^1.1.4", "analytics-node": "^5.1.2", "bson": "^4.5.4", "bson-transpilers": "^1.2.0", @@ -66,7 +66,7 @@ "@types/react-dom": "^17.0.11", "@types/sinon": "^9.0.11", "@types/uuid": "^8.3.3", - "@types/vscode": "^1.62.0", + "@types/vscode": "^1.58.1", "@types/ws": "^7.4.7", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", @@ -1556,9 +1556,9 @@ } }, "node_modules/@mongosh/async-rewriter2": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/async-rewriter2/-/async-rewriter2-1.1.2.tgz", - "integrity": "sha512-byV3O19CPSAhjpZUPEZlYT8mTvLd4wm942ttyoWmayMKbbpr2MZ3l+ZIhYjNRdVtZ+0MOsYZBrcgyx4qmDfEUQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/async-rewriter2/-/async-rewriter2-1.1.4.tgz", + "integrity": "sha512-KDIaBBZSABrXemy7QLtnCaF+SsMDnEIFbsO+YnZAftxpwuhnf7d1m8lknhfwntTmgFeAhnPndUFrUNcPPrML+w==", "dependencies": { "@babel/core": "^7.14.8", "@babel/plugin-transform-destructuring": "^7.14.7", @@ -1572,11 +1572,11 @@ } }, "node_modules/@mongosh/autocomplete": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/autocomplete/-/autocomplete-1.1.2.tgz", - "integrity": "sha512-nIlWZnJ3qxmCx2bxm8lBGpHm93AUk7XtwDOLCyzYapPGAZkHDyiUxhKFZ/zu1X2LU+QVWT7isTGzC44KgLJRYw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/autocomplete/-/autocomplete-1.1.4.tgz", + "integrity": "sha512-638qvxdvzJbigfaSLSqJT6Dypyift9G+QNLJmMq7sq7zGbP3fzOuMC4jQyaU8qfn4MRmPWNd20+CRQPePqPBEg==", "dependencies": { - "@mongosh/shell-api": "1.1.2", + "@mongosh/shell-api": "1.1.4", "mongodb-ace-autocompleter": "^0.8.0", "semver": "^7.3.2" }, @@ -1585,44 +1585,44 @@ } }, "node_modules/@mongosh/browser-runtime-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-core/-/browser-runtime-core-1.1.2.tgz", - "integrity": "sha512-oCXZfH2QG43O8Nk/uYZHmuZ5lbJSMqlTyvE9fH+RkU3qCu3CjGl81zp8TQmWSb8avuhxhZSSYEE0xTG+6xFwCQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-core/-/browser-runtime-core-1.1.4.tgz", + "integrity": "sha512-co3Dx8llTU28WeYxU6LuJVz+YAAolAoTILQqQDxQYS/xeTECwRaT1QKhZcupQxjmF+BWfV7c1CbVUfkxQmDIug==", "dependencies": { - "@mongosh/autocomplete": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/shell-api": "1.1.2", - "@mongosh/shell-evaluator": "1.1.2" + "@mongosh/autocomplete": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/shell-api": "1.1.4", + "@mongosh/shell-evaluator": "1.1.4" }, "engines": { "node": ">=12.4.0" } }, "node_modules/@mongosh/browser-runtime-electron": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-electron/-/browser-runtime-electron-1.1.2.tgz", - "integrity": "sha512-pY8tx+sKfh8WDg++XZorqY9dgf4/SWDxiWw1EKO6GJOA8qeI88MUYr0EH9qjU9g2Mq3B1DdC2DHjS8+RvGzqfg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-electron/-/browser-runtime-electron-1.1.4.tgz", + "integrity": "sha512-Um5kSa9GKbzDm026GKifQVTjXaF/CY/K17XmSWd61UI+84X7K+r2z2jdbua9qNhzXd1XHOcr3Ugh152xnkrteA==", "dependencies": { - "@mongosh/browser-runtime-core": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/types": "1.1.2" + "@mongosh/browser-runtime-core": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/types": "1.1.4" }, "engines": { "node": ">=12.4.0" } }, "node_modules/@mongosh/errors": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/errors/-/errors-1.1.2.tgz", - "integrity": "sha512-UvsR9gUFvi1nugkKMcxj2tjrpoU0eJDdVkZGUNp7rvQqFASiBIF4n/jNn/EE9chWYUiQdRGdwWRAvu5KZkNR5Q==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/errors/-/errors-1.1.4.tgz", + "integrity": "sha512-Y3+Cje0OktTKgffUWvUSQ8JJLrtV0GkBvAvSGIJIFOU8wi9JtvDW39DLT3fKuOX4gMalYmxEYGvtf3DPGeOTBA==", "engines": { "node": ">=12.4.0" } }, "node_modules/@mongosh/history": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/history/-/history-1.1.2.tgz", - "integrity": "sha512-COqzzOA0cp32195gQ5fylf/e5EncNlCihV6ubxWydZfFv8ix7XF1V4Lnwse9U01jdnuue80DCmiOg8ogocJkbw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/history/-/history-1.1.4.tgz", + "integrity": "sha512-fNtwFhuuICf4dYOyNUxOWWYJo2AXg/k5fIiLxDHdt4FHj7FsfxbaYd6f2RCxaaxmG5TAFc290WDXCaTKuZYDiQ==", "dependencies": { "mongodb-redact": "^0.2.2" }, @@ -1631,11 +1631,11 @@ } }, "node_modules/@mongosh/i18n": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/i18n/-/i18n-1.1.2.tgz", - "integrity": "sha512-4fuZNwEskWOSgW7rV7LE1wva4bmaRSrmvWjW3sCzhQfzp3fGAMHnBA0YD5QLxuMupQZRuw++r4j24XuxoGc7bw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/i18n/-/i18n-1.1.4.tgz", + "integrity": "sha512-2Nrg8bEqlWv/Utgv6G1E+BGLhx1vCYF0i43MP5hOepWdMoL04jkt9489u8tY2yyqWSUxG18NMOK6aC/EOX7d3g==", "dependencies": { - "@mongosh/errors": "1.1.2", + "@mongosh/errors": "1.1.4", "mustache": "^4.0.0" }, "engines": { @@ -1643,16 +1643,16 @@ } }, "node_modules/@mongosh/service-provider-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/service-provider-core/-/service-provider-core-1.1.2.tgz", - "integrity": "sha512-mXYWxIVY7sH2q++61ujTZ8hYUgH91TDJJ3bPWo/xzQA2GOilvpMzI6yPKQWefqy/568vfcuZSA6KeH6TZcvWCg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/service-provider-core/-/service-provider-core-1.1.4.tgz", + "integrity": "sha512-P7LMdnvHmXQD1kOKYL5uQh/r0BV/a+a14AAp3PzejKdpQc7t/mvaBEuipw4r8/O77dmKurmK76gWk/Pu11bhpg==", "dependencies": { - "@mongosh/errors": "1.1.2", - "@mongosh/i18n": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/i18n": "1.1.4", "bson": "^4.5.4", "mongodb": "^4.1.4", "mongodb-build-info": "^1.2.0", - "mongodb-connection-string-url": "^2.0.0" + "mongodb-connection-string-url": "^2.2.0" }, "engines": { "node": ">=12.4.0" @@ -1702,17 +1702,17 @@ } }, "node_modules/@mongosh/service-provider-server": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/service-provider-server/-/service-provider-server-1.1.2.tgz", - "integrity": "sha512-xbc8YxiXeYCQiI7T07HFrNEC0TL1vcFtA8jp9y0t0Lgid5r1q/1Suks2XwP8LFkz8k+ovM8+h19a59q8Mux1Gg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/service-provider-server/-/service-provider-server-1.1.4.tgz", + "integrity": "sha512-YtGtK8AeozLj3zN2l0GvDuyIlPauv+XyRCTVFA9MPPWx6+EfUZjeuZz8SU0Xs9Mv5FL1YXzdYcL8+YoGXVfIBQ==", "dependencies": { - "@mongosh/errors": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/types": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/types": "1.1.4", "@types/sinon-chai": "^3.2.3", "aws4": "^1.11.0", "mongodb": "^4.1.4", - "mongodb-connection-string-url": "^2.0.0", + "mongodb-connection-string-url": "^2.2.0", "saslprep": "github:mongodb-js/saslprep#v1.0.4" }, "engines": { @@ -1766,14 +1766,14 @@ } }, "node_modules/@mongosh/shell-api": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/shell-api/-/shell-api-1.1.2.tgz", - "integrity": "sha512-q00xY0F13H6OotBXy/NE/J7KK8fNi9g1p8t9ShK5C4I0eJY8utOYzOcGrdKNt2+Qw+5ESVycF4z6jbYmcCy56A==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/shell-api/-/shell-api-1.1.4.tgz", + "integrity": "sha512-LEwdVj+WNEmWpU2DFiwsTuIrrrqY3OSjOz7adfRG/IzhKJCS7a0E0ytke5fssvAaAxjGhYRHrmLiRBt6CSqRWg==", "dependencies": { - "@mongosh/errors": "1.1.2", - "@mongosh/history": "1.1.2", - "@mongosh/i18n": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/history": "1.1.4", + "@mongosh/i18n": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", "mongodb-redact": "^0.2.2" }, "engines": { @@ -1781,22 +1781,22 @@ } }, "node_modules/@mongosh/shell-evaluator": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/shell-evaluator/-/shell-evaluator-1.1.2.tgz", - "integrity": "sha512-JLDs0Jgobs88Is0YN1ClQSUYiYQYRmEDXROVEwGvHk+bRqhRLKHbaGiZWJ9brhdnkTpTaG77OyJMehTvv71m5w==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/shell-evaluator/-/shell-evaluator-1.1.4.tgz", + "integrity": "sha512-d/653asx4HcCs+cwofT8nbp8YnDPeGLz4FtE9Yb7639C2z+s4X217OuBLSM65Hzq8cky2XRb90mDe42sa6egzQ==", "dependencies": { - "@mongosh/async-rewriter2": "1.1.2", - "@mongosh/history": "1.1.2", - "@mongosh/shell-api": "1.1.2" + "@mongosh/async-rewriter2": "1.1.4", + "@mongosh/history": "1.1.4", + "@mongosh/shell-api": "1.1.4" }, "engines": { "node": ">=12.4.0" } }, "node_modules/@mongosh/types": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/types/-/types-1.1.2.tgz", - "integrity": "sha512-Jqla3Jav6UNwIbqlX27hWnMAeacbEDAm/m3udR1tCwhW672roXO/P2sVpb0yXw4UH0Nx31HY5Y6zP+ktJbQbfA==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/types/-/types-1.1.4.tgz", + "integrity": "sha512-+NCZXM6oFpZ7BHn3Tfsp6yX3g17+/QIziy78O3rAJ9TsPLkRoS6yW+d5PqH6LFqXG7iYbZJxH2EMrPnCW5pNTQ==", "engines": { "node": ">=12.4.0" } @@ -25867,9 +25867,9 @@ } }, "@mongosh/async-rewriter2": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/async-rewriter2/-/async-rewriter2-1.1.2.tgz", - "integrity": "sha512-byV3O19CPSAhjpZUPEZlYT8mTvLd4wm942ttyoWmayMKbbpr2MZ3l+ZIhYjNRdVtZ+0MOsYZBrcgyx4qmDfEUQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/async-rewriter2/-/async-rewriter2-1.1.4.tgz", + "integrity": "sha512-KDIaBBZSABrXemy7QLtnCaF+SsMDnEIFbsO+YnZAftxpwuhnf7d1m8lknhfwntTmgFeAhnPndUFrUNcPPrML+w==", "requires": { "@babel/core": "^7.14.8", "@babel/plugin-transform-destructuring": "^7.14.7", @@ -25880,70 +25880,70 @@ } }, "@mongosh/autocomplete": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/autocomplete/-/autocomplete-1.1.2.tgz", - "integrity": "sha512-nIlWZnJ3qxmCx2bxm8lBGpHm93AUk7XtwDOLCyzYapPGAZkHDyiUxhKFZ/zu1X2LU+QVWT7isTGzC44KgLJRYw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/autocomplete/-/autocomplete-1.1.4.tgz", + "integrity": "sha512-638qvxdvzJbigfaSLSqJT6Dypyift9G+QNLJmMq7sq7zGbP3fzOuMC4jQyaU8qfn4MRmPWNd20+CRQPePqPBEg==", "requires": { - "@mongosh/shell-api": "1.1.2", + "@mongosh/shell-api": "1.1.4", "mongodb-ace-autocompleter": "^0.8.0", "semver": "^7.3.2" } }, "@mongosh/browser-runtime-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-core/-/browser-runtime-core-1.1.2.tgz", - "integrity": "sha512-oCXZfH2QG43O8Nk/uYZHmuZ5lbJSMqlTyvE9fH+RkU3qCu3CjGl81zp8TQmWSb8avuhxhZSSYEE0xTG+6xFwCQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-core/-/browser-runtime-core-1.1.4.tgz", + "integrity": "sha512-co3Dx8llTU28WeYxU6LuJVz+YAAolAoTILQqQDxQYS/xeTECwRaT1QKhZcupQxjmF+BWfV7c1CbVUfkxQmDIug==", "requires": { - "@mongosh/autocomplete": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/shell-api": "1.1.2", - "@mongosh/shell-evaluator": "1.1.2" + "@mongosh/autocomplete": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/shell-api": "1.1.4", + "@mongosh/shell-evaluator": "1.1.4" } }, "@mongosh/browser-runtime-electron": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-electron/-/browser-runtime-electron-1.1.2.tgz", - "integrity": "sha512-pY8tx+sKfh8WDg++XZorqY9dgf4/SWDxiWw1EKO6GJOA8qeI88MUYr0EH9qjU9g2Mq3B1DdC2DHjS8+RvGzqfg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/browser-runtime-electron/-/browser-runtime-electron-1.1.4.tgz", + "integrity": "sha512-Um5kSa9GKbzDm026GKifQVTjXaF/CY/K17XmSWd61UI+84X7K+r2z2jdbua9qNhzXd1XHOcr3Ugh152xnkrteA==", "requires": { - "@mongosh/browser-runtime-core": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/types": "1.1.2" + "@mongosh/browser-runtime-core": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/types": "1.1.4" } }, "@mongosh/errors": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/errors/-/errors-1.1.2.tgz", - "integrity": "sha512-UvsR9gUFvi1nugkKMcxj2tjrpoU0eJDdVkZGUNp7rvQqFASiBIF4n/jNn/EE9chWYUiQdRGdwWRAvu5KZkNR5Q==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/errors/-/errors-1.1.4.tgz", + "integrity": "sha512-Y3+Cje0OktTKgffUWvUSQ8JJLrtV0GkBvAvSGIJIFOU8wi9JtvDW39DLT3fKuOX4gMalYmxEYGvtf3DPGeOTBA==" }, "@mongosh/history": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/history/-/history-1.1.2.tgz", - "integrity": "sha512-COqzzOA0cp32195gQ5fylf/e5EncNlCihV6ubxWydZfFv8ix7XF1V4Lnwse9U01jdnuue80DCmiOg8ogocJkbw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/history/-/history-1.1.4.tgz", + "integrity": "sha512-fNtwFhuuICf4dYOyNUxOWWYJo2AXg/k5fIiLxDHdt4FHj7FsfxbaYd6f2RCxaaxmG5TAFc290WDXCaTKuZYDiQ==", "requires": { "mongodb-redact": "^0.2.2" } }, "@mongosh/i18n": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/i18n/-/i18n-1.1.2.tgz", - "integrity": "sha512-4fuZNwEskWOSgW7rV7LE1wva4bmaRSrmvWjW3sCzhQfzp3fGAMHnBA0YD5QLxuMupQZRuw++r4j24XuxoGc7bw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/i18n/-/i18n-1.1.4.tgz", + "integrity": "sha512-2Nrg8bEqlWv/Utgv6G1E+BGLhx1vCYF0i43MP5hOepWdMoL04jkt9489u8tY2yyqWSUxG18NMOK6aC/EOX7d3g==", "requires": { - "@mongosh/errors": "1.1.2", + "@mongosh/errors": "1.1.4", "mustache": "^4.0.0" } }, "@mongosh/service-provider-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/service-provider-core/-/service-provider-core-1.1.2.tgz", - "integrity": "sha512-mXYWxIVY7sH2q++61ujTZ8hYUgH91TDJJ3bPWo/xzQA2GOilvpMzI6yPKQWefqy/568vfcuZSA6KeH6TZcvWCg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/service-provider-core/-/service-provider-core-1.1.4.tgz", + "integrity": "sha512-P7LMdnvHmXQD1kOKYL5uQh/r0BV/a+a14AAp3PzejKdpQc7t/mvaBEuipw4r8/O77dmKurmK76gWk/Pu11bhpg==", "requires": { - "@mongosh/errors": "1.1.2", - "@mongosh/i18n": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/i18n": "1.1.4", "bson": "^4.5.4", "mongodb": "^4.1.4", "mongodb-build-info": "^1.2.0", "mongodb-client-encryption": "^2.0.0-beta.0", - "mongodb-connection-string-url": "^2.0.0" + "mongodb-connection-string-url": "^2.2.0" }, "dependencies": { "mongodb-connection-string-url": { @@ -25980,19 +25980,19 @@ } }, "@mongosh/service-provider-server": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/service-provider-server/-/service-provider-server-1.1.2.tgz", - "integrity": "sha512-xbc8YxiXeYCQiI7T07HFrNEC0TL1vcFtA8jp9y0t0Lgid5r1q/1Suks2XwP8LFkz8k+ovM8+h19a59q8Mux1Gg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/service-provider-server/-/service-provider-server-1.1.4.tgz", + "integrity": "sha512-YtGtK8AeozLj3zN2l0GvDuyIlPauv+XyRCTVFA9MPPWx6+EfUZjeuZz8SU0Xs9Mv5FL1YXzdYcL8+YoGXVfIBQ==", "requires": { - "@mongosh/errors": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", - "@mongosh/types": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", + "@mongosh/types": "1.1.4", "@types/sinon-chai": "^3.2.3", "aws4": "^1.11.0", "kerberos": "^2.0.0-beta.0", "mongodb": "^4.1.4", "mongodb-client-encryption": "^2.0.0-beta.0", - "mongodb-connection-string-url": "^2.0.0", + "mongodb-connection-string-url": "^2.2.0", "os-dns-native": "^1.0.3", "resolve-mongodb-srv": "^1.1.0", "saslprep": "github:mongodb-js/saslprep#v1.0.4" @@ -26032,31 +26032,31 @@ } }, "@mongosh/shell-api": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/shell-api/-/shell-api-1.1.2.tgz", - "integrity": "sha512-q00xY0F13H6OotBXy/NE/J7KK8fNi9g1p8t9ShK5C4I0eJY8utOYzOcGrdKNt2+Qw+5ESVycF4z6jbYmcCy56A==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/shell-api/-/shell-api-1.1.4.tgz", + "integrity": "sha512-LEwdVj+WNEmWpU2DFiwsTuIrrrqY3OSjOz7adfRG/IzhKJCS7a0E0ytke5fssvAaAxjGhYRHrmLiRBt6CSqRWg==", "requires": { - "@mongosh/errors": "1.1.2", - "@mongosh/history": "1.1.2", - "@mongosh/i18n": "1.1.2", - "@mongosh/service-provider-core": "1.1.2", + "@mongosh/errors": "1.1.4", + "@mongosh/history": "1.1.4", + "@mongosh/i18n": "1.1.4", + "@mongosh/service-provider-core": "1.1.4", "mongodb-redact": "^0.2.2" } }, "@mongosh/shell-evaluator": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/shell-evaluator/-/shell-evaluator-1.1.2.tgz", - "integrity": "sha512-JLDs0Jgobs88Is0YN1ClQSUYiYQYRmEDXROVEwGvHk+bRqhRLKHbaGiZWJ9brhdnkTpTaG77OyJMehTvv71m5w==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/shell-evaluator/-/shell-evaluator-1.1.4.tgz", + "integrity": "sha512-d/653asx4HcCs+cwofT8nbp8YnDPeGLz4FtE9Yb7639C2z+s4X217OuBLSM65Hzq8cky2XRb90mDe42sa6egzQ==", "requires": { - "@mongosh/async-rewriter2": "1.1.2", - "@mongosh/history": "1.1.2", - "@mongosh/shell-api": "1.1.2" + "@mongosh/async-rewriter2": "1.1.4", + "@mongosh/history": "1.1.4", + "@mongosh/shell-api": "1.1.4" } }, "@mongosh/types": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mongosh/types/-/types-1.1.2.tgz", - "integrity": "sha512-Jqla3Jav6UNwIbqlX27hWnMAeacbEDAm/m3udR1tCwhW672roXO/P2sVpb0yXw4UH0Nx31HY5Y6zP+ktJbQbfA==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongosh/types/-/types-1.1.4.tgz", + "integrity": "sha512-+NCZXM6oFpZ7BHn3Tfsp6yX3g17+/QIziy78O3rAJ9TsPLkRoS6yW+d5PqH6LFqXG7iYbZJxH2EMrPnCW5pNTQ==" }, "@nodelib/fs.scandir": { "version": "2.1.4", diff --git a/package.json b/package.json index f6c8030f8..223edfc11 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "release-draft": "node ./scripts/release-draft.js" }, "engines": { - "vscode": "^1.62.0", + "vscode": "^1.58.1", "node": "^14.17.3", "npm": "^7.19.0" }, @@ -839,7 +839,7 @@ "items": { "type": "string" }, - "description": "Files and folders to exclude while searching for playgrounds in the the current workspace.", + "description": "Files and folders to exclude while searching for playgrounds in the current workspace.", "default": [ "**/.*", "**/_output/**", @@ -910,10 +910,10 @@ "@iconify/react": "^1.1.4", "@leafygreen-ui/logo": "^6.1.0", "@leafygreen-ui/toggle": "^7.0.4", - "@mongosh/browser-runtime-electron": "^1.1.2", - "@mongosh/i18n": "^1.1.2", - "@mongosh/service-provider-server": "^1.1.2", - "@mongosh/shell-api": "^1.1.2", + "@mongosh/browser-runtime-electron": "^1.1.4", + "@mongosh/i18n": "^1.1.4", + "@mongosh/service-provider-server": "^1.1.4", + "@mongosh/shell-api": "^1.1.4", "analytics-node": "^5.1.2", "bson": "^4.5.4", "bson-transpilers": "^1.2.0", @@ -958,7 +958,7 @@ "@types/react-dom": "^17.0.11", "@types/sinon": "^9.0.11", "@types/uuid": "^8.3.3", - "@types/vscode": "^1.62.0", + "@types/vscode": "^1.58.1", "@types/ws": "^7.4.7", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", diff --git a/src/language/mongoDBService.ts b/src/language/mongoDBService.ts index e12b5bc97..621628fea 100644 --- a/src/language/mongoDBService.ts +++ b/src/language/mongoDBService.ts @@ -445,6 +445,8 @@ export default class MongoDBService { getExportToLanguageMode(params: PlaygroundTextAndSelection): ExportToLanguageMode { const state = this._visitor.parseAST(params); + this._connection.console.log(`EXPORT TO LANGUAGE state: ${util.inspect(state)}`); + if (state.isArray) { return ExportToLanguageMode.AGGREGATION; } diff --git a/src/language/visitor.ts b/src/language/visitor.ts index d8371ff32..06946e84c 100644 --- a/src/language/visitor.ts +++ b/src/language/visitor.ts @@ -19,7 +19,6 @@ export interface VisitorTextAndSelection { export interface CompletionState { databaseName: string | null; collectionName: string | null; - selectionType: string | null; isObject: boolean; isArray: boolean; isObjectKey: boolean; @@ -45,97 +44,56 @@ export class Visitor { this._console = console; } - _checkIsObjectSelection(node: babel.types.Node): boolean { - return (this._checkIsBSONSelection(node) && this._state.selectionType === 'ObjectExpression'); - } - - _checkIsArraySelection(node: babel.types.Node): boolean { - return (this._checkIsBSONSelection(node) && this._state.selectionType === 'ArrayExpression'); - } - - _visitCallExpression(node: babel.types.CallExpression): void { - if (this._checkIsObjectSelection(node)) { - this._state.isObject = true; + _visitCallExpression(node: babel.types.Node): void { + if (node.type !== 'CallExpression') { + return; } - if (this._checkIsArraySelection(node)) { - this._state.isArray = true; - } - - if (this._checkIsUseCall(node)) { - this._state.isUseCallExpression = true; - } - - if (this._checkIsCollectionName(node)) { - this._state.isCollectionName = true; - } - - if (this._checkHasDatabaseName(node)) { - this._state.databaseName = (node.arguments[0] as babel.types.StringLiteral).value; - } + this._checkIsBSONSelection(node); + this._checkIsUseCall(node); + this._checkIsCollectionName(node); + this._checkHasDatabaseName(node); } - _visitMemberExpression(node: babel.types.MemberExpression): void { - if (this._checkHasAggregationCall(node)) { - this._state.isAggregationCursor = true; - } - - if (this._checkHasFindCall(node)) { - this._state.isFindCursor = true; - } - - if (this._checkIsShellMethod(node)) { - this._state.isShellMethod = true; - } - - if (this._checkIsCollectionName(node)) { - this._state.isCollectionName = true; + _visitMemberExpression(node: babel.types.Node): void { + if (node.type !== 'MemberExpression') { + return; } - if (this._checkHasCollectionName(node)) { - this._state.collectionName = ((node.object as babel.types.MemberExpression).property as babel.types.Identifier).name; - } + this._checkHasAggregationCall(node); + this._checkHasFindCall(node); + this._checkIsShellMethod(node); + this._checkIsCollectionName(node); + this._checkHasCollectionName(node); } - _visitExpressionStatement(node: babel.types.ExpressionStatement): void { - if (this._checkIsDbCall(node)) { - this._state.isDbCallExpression = true; + _visitExpressionStatement(node: babel.types.Node): void { + if (node.type === 'ExpressionStatement') { + this._checkIsDbCall(node); } } - _visitObjectExpression(node: babel.types.ObjectExpression): void { - if (this._checkIsObjectKey(node)) { - this._state.isObjectKey = true; + _visitObjectExpression(node: babel.types.Node): void { + if (node.type === 'ObjectExpression') { + this._checkIsObjectKey(node); } } - _visitArrayExpression(node: babel.types.ArrayExpression): void { - if (this._checkIsObjectSelection(node)) { - this._state.isObject = true; - } - - if (this._checkIsArraySelection(node)) { - this._state.isArray = true; + _visitArrayExpression(node: babel.types.Node): void { + if (node.type === 'ArrayExpression') { + this._checkIsBSONSelection(node); } } - _visitVariableDeclarator(node: babel.types.VariableDeclarator): void { - if (this._checkIsObjectSelection(node)) { - this._state.isObject = true; - } - - if (this._checkIsArraySelection(node)) { - this._state.isArray = true; + _visitVariableDeclarator(node: babel.types.Node): void { + if (node.type === 'VariableDeclarator') { + this._checkIsBSONSelection(node); } } - _visitObjectProperty(node: babel.types.ObjectProperty): void { - if (this._checkIsObjectSelection(node)) { - this._state.isObject = true; - } - - if (this._checkIsArraySelection(node)) { - this._state.isArray = true; + _visitObjectProperty(node: babel.types.Node): void { + if (node.type === 'ObjectProperty') { + this._checkIsBSONSelection(node); } } @@ -195,31 +153,13 @@ export class Visitor { traverse(ast, { enter: (path: babel.NodePath) => { - switch (path.node.type) { - case 'CallExpression': - this._visitCallExpression(path.node); - break; - case 'MemberExpression': - this._visitMemberExpression(path.node); - break; - case 'ExpressionStatement': - this._visitExpressionStatement(path.node); - break; - case 'ObjectExpression': - this._visitObjectExpression(path.node); - break; - case 'ArrayExpression': - this._visitArrayExpression(path.node); - break; - case 'VariableDeclarator': - this._visitVariableDeclarator(path.node); - break; - case 'ObjectProperty': - this._visitObjectProperty(path.node); - break; - default: - break; - } + this._visitCallExpression(path.node); + this._visitMemberExpression(path.node); + this._visitExpressionStatement(path.node); + this._visitObjectExpression(path.node); + this._visitArrayExpression(path.node); + this._visitVariableDeclarator(path.node); + this._visitObjectProperty(path.node); } }); @@ -230,7 +170,6 @@ export class Visitor { return { databaseName: null, collectionName: null, - selectionType: null, isObject: false, isArray: false, isObjectKey: false, @@ -243,54 +182,55 @@ export class Visitor { }; } - // eslint-disable-next-line complexity - _checkIsUseCall(node: babel.types.CallExpression): boolean { + _checkIsUseCallAsSimpleString(node: babel.types.CallExpression): void { if ( - (node.callee.type === 'Identifier' && - node.callee.name === 'use' && - node.arguments && - node.arguments.length === 1 && - node.arguments[0].type === 'StringLiteral' && - node.arguments[0].value.includes(PLACEHOLDER)) || - (node.arguments && - node.arguments.length === 1 && - node.arguments[0].type === 'TemplateLiteral' && - node.arguments[0].quasis && - node.arguments[0].quasis.length === 1 && - node.arguments[0].quasis[0].value?.raw && - node.arguments[0].quasis[0].value?.raw.includes(PLACEHOLDER)) + node.callee.type === 'Identifier' && + node.callee.name === 'use' && + node.arguments && + node.arguments.length === 1 && + node.arguments[0].type === 'StringLiteral' && + node.arguments[0].value.includes(PLACEHOLDER) ) { - return true; + this._state.isUseCallExpression = true; } - - return false; } - _checkIsDbCall(node: babel.types.ExpressionStatement): boolean { + _checkIsUseCallAsTemplate(node: babel.types.CallExpression): void { if ( - node.expression.type === 'MemberExpression' && - node.expression.object.type === 'Identifier' && - node.expression.object.name === 'db' + node.arguments && + node.arguments.length === 1 && + node.arguments[0].type === 'TemplateLiteral' && + node.arguments[0].quasis && + node.arguments[0].quasis.length === 1 && + node.arguments[0].quasis[0].value?.raw && + node.arguments[0].quasis[0].value?.raw.includes(PLACEHOLDER) ) { - return true; + this._state.isUseCallExpression = true; } + } - return false; + _checkIsUseCall(node: babel.types.CallExpression): void { + this._checkIsUseCallAsSimpleString(node); + this._checkIsUseCallAsTemplate(node); } - _checkIsObjectKey(node: babel.types.ObjectExpression): boolean { + _checkIsDbCall(node: babel.types.ExpressionStatement): void { if ( - node.properties.find( - (item: any) => !!(item.key.name && item.key.name.includes(PLACEHOLDER)) - ) + node.expression.type === 'MemberExpression' && + node.expression.object.type === 'Identifier' && + node.expression.object.name === 'db' ) { - return true; + this._state.isDbCallExpression = true; } + } - return false; + _checkIsObjectKey(node: babel.types.ObjectExpression): void { + this._state.isObjectKey = !!node.properties.find( + (item: any) => !!(item.key.name && item.key.name.includes(PLACEHOLDER)) + ); } - _checkIsAroundSelection(node: babel.types.Node): boolean { + _isParentAroundSelection(node: babel.types.Node): boolean { if ( node.loc?.start?.line && ( @@ -309,7 +249,7 @@ export class Visitor { return false; } - _checkIsObjectPropBeforeSelection(node: babel.types.ObjectProperty): boolean { + _isObjectPropBeforeSelection(node: babel.types.ObjectProperty): boolean { if ( node.key.loc?.end && ( @@ -326,7 +266,7 @@ export class Visitor { return false; } - _checkIsVariableIdentifierBeforeSelection(node: babel.types.VariableDeclarator): boolean { + _isVariableIdentifierBeforeSelection(node: babel.types.VariableDeclarator): boolean { if ( node.id.loc?.end && ( @@ -343,24 +283,7 @@ export class Visitor { return false; } - _checkIsAfterSelection(node: babel.types.ObjectExpression): boolean { - if ( - node.loc?.start && - ( - node.loc?.start.line - 1 > this._selection.start?.line || - ( - node.loc?.start.line - 1 === this._selection.start?.line && - node.loc?.start.column > this._selection.start?.character - ) - ) - ) { - return true; - } - - return false; - } - - _checkIsWithinSelection(node: babel.types.Node): boolean { + _isWithinSelection(node: babel.types.Node): boolean { if ( node.loc?.start?.line && node.loc.start.line - 1 === this._selection.start?.line && @@ -371,113 +294,99 @@ export class Visitor { node.loc?.end?.column && node.loc.end.column <= this._selection.end?.character ) { - this._state.selectionType = node.type; return true; } return false; } - _checkIsSelectionInArray(node: babel.types.Node) { - if ( - node.type === 'ArrayExpression' && - node.elements && - this._checkIsAroundSelection(node) && - node.elements.find((item) => { - return item && this._checkIsWithinSelection(item); - }) - ) { - return true; + _checkIsArrayWithinSelection(node: babel.types.Node): void { + if (node.type === 'ArrayExpression' && this._isWithinSelection(node)) { + this._state.isArray = true; } + } - return false; + _checkIsObjectWithinSelection(node: babel.types.Node): void { + if (node.type === 'ObjectExpression' && this._isWithinSelection(node)) { + this._state.isObject = true; + } } - _checkIsSelectionInFunction(node: babel.types.Node) { - if ( - node.type === 'CallExpression' && - node.arguments && - this._checkIsAroundSelection(node) && - node.arguments.find((item) => { - return item && this._checkIsWithinSelection(item); - }) - ) { - return true; + _checkIsBSONSelectionInArray(node: babel.types.Node): void { + if (node.type === 'ArrayExpression' && node.elements && this._isParentAroundSelection(node)) { + node.elements.forEach((item) => { + if (item) { + this._checkIsObjectWithinSelection(item); + this._checkIsArrayWithinSelection(item); + } + }); } + } - return false; + _checkIsBSONSelectionInFunction(node: babel.types.Node): void { + if (node.type === 'CallExpression' && node.arguments && this._isParentAroundSelection(node)) { + node.arguments.forEach((item) => { + if (item) { + this._checkIsObjectWithinSelection(item); + this._checkIsArrayWithinSelection(item); + } + }); + } } - _checkIsSelectionInVariable(node: babel.types.VariableDeclarator) { + _checkIsBSONSelectionInVariable(node: babel.types.Node) { if ( + node.type === 'VariableDeclarator' && node.init && - ( - node.init.type === 'ObjectExpression' || - node.init.type === 'ArrayExpression' - ) && - this._checkIsVariableIdentifierBeforeSelection(node) && - this._checkIsWithinSelection(node.init) + this._isVariableIdentifierBeforeSelection(node) ) { - return true; + this._checkIsObjectWithinSelection(node.init); + this._checkIsArrayWithinSelection(node.init); } - - return false; } - _checkIsSelectionInObject(node: babel.types.ObjectProperty) { + _checkIsBSONSelectionInObject(node: babel.types.Node) { if ( + node.type === 'ObjectProperty' && node.value && - ( - node.value.type === 'ObjectExpression' || - node.value.type === 'ArrayExpression' - ) && - this._checkIsObjectPropBeforeSelection(node) && - this._checkIsWithinSelection(node.value) + this._isObjectPropBeforeSelection(node) ) { - return true; + this._checkIsObjectWithinSelection(node.value); + this._checkIsArrayWithinSelection(node.value); } - - return false; } - _checkIsBSONSelection(node: babel.types.Node): boolean { - if (node.type === 'CallExpression') { - return this._checkIsSelectionInFunction(node); - } - - if (node.type === 'ArrayExpression') { - return this._checkIsSelectionInArray(node); - } - - if (node.type === 'VariableDeclarator') { - return this._checkIsSelectionInVariable(node); - } - - if (node.type === 'ObjectProperty') { - return this._checkIsSelectionInObject(node); - } - - return false; + _checkIsBSONSelection(node: babel.types.Node): void { + this._checkIsBSONSelectionInFunction(node); + this._checkIsBSONSelectionInArray(node); + this._checkIsBSONSelectionInVariable(node); + this._checkIsBSONSelectionInObject(node); } - _checkIsCollectionName(node: babel.types.CallExpression | babel.types.MemberExpression): boolean { + _checkIsCollectionNameAsMemberExpression(node: babel.types.Node): void { if ( - (node.type === 'MemberExpression' && - node.object.type === 'Identifier' && - node.object.name === 'db' && - node.property.type === 'Identifier' && - node.property.name.includes(PLACEHOLDER)) || - (node.type === 'CallExpression' && - node.callee.type === 'MemberExpression' && - this._checkIsCollectionName(node.callee)) + node.type === 'MemberExpression' && + node.object.type === 'Identifier' && + node.object.name === 'db' && + node.property.type === 'Identifier' && + node.property.name.includes(PLACEHOLDER) ) { - return true; + this._state.isCollectionName = true; } + } - return false; + _checkIsCollectionNameAsCallExpression(node: babel.types.Node): void { + if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') { + this._checkIsCollectionName(node.callee); + } + } + + _checkIsCollectionName(node: babel.types.CallExpression | babel.types.MemberExpression): void { + this._checkIsCollectionNameAsMemberExpression(node); + this._checkIsCollectionNameAsCallExpression(node); } - _checkHasAggregationCall(node: babel.types.MemberExpression): boolean { + _checkHasAggregationCall(node: babel.types.MemberExpression): void { if ( node.object.type === 'CallExpression' && node.property.type === 'Identifier' && @@ -487,13 +396,11 @@ export class Visitor { node.object.callee.property.type === 'Identifier' && node.object.callee.property.name === 'aggregate' ) { - return true; + this._state.isAggregationCursor = true; } - - return false; } - _checkHasFindCall(node: babel.types.MemberExpression): boolean { + _checkHasFindCall(node: babel.types.MemberExpression): void { if ( node.object.type === 'CallExpression' && node.property.type === 'Identifier' && @@ -503,13 +410,11 @@ export class Visitor { node.object.callee.property.type === 'Identifier' && node.object.callee.property.name === 'find' ) { - return true; + this._state.isFindCursor = true; } - - return false; } - _checkHasDatabaseName(node: babel.types.CallExpression): boolean { + _checkHasDatabaseName(node: babel.types.CallExpression): void { if ( node.callee.type === 'Identifier' && node.callee.name === 'use' && @@ -521,25 +426,21 @@ export class Visitor { (this._selection.start.line === node.loc.end.line - 1 && this._selection.start.character >= node.loc.end.column)) ) { - return true; + this._state.databaseName = node.arguments[0].value; } - - return false; } - _checkHasCollectionName(node: babel.types.MemberExpression): boolean { + _checkHasCollectionName(node: babel.types.MemberExpression): void { if ( node.object.type === 'MemberExpression' && node.object.object.type === 'Identifier' && node.object.object.name === 'db' ) { - return true; + this._state.collectionName = (node.object.property as babel.types.Identifier).name; } - - return false; } - _checkIsShellMethod(node: babel.types.MemberExpression): boolean { + _checkIsShellMethod(node: babel.types.MemberExpression): void { if ( node.object.type === 'MemberExpression' && node.object.object.type === 'Identifier' && @@ -547,9 +448,7 @@ export class Visitor { node.property.type === 'Identifier' && node.property.name.includes(PLACEHOLDER) ) { - return true; + this._state.isShellMethod = true; } - - return false; } }