diff --git a/package-lock.json b/package-lock.json index 95afce858..7aafbdba3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "eslint-import-resolver-typescript": "3.6.1", "eslint-plugin-import": "2.29.1", "eslint-plugin-prettier": "5.1.2", - "eslint-plugin-unicorn": "43.0.2", + "eslint-plugin-unicorn": "50.0.1", "fs-extra": "11.2.0", "globby": "11.0.4", "graphql": "15.8.0", @@ -9159,9 +9159,9 @@ } }, "node_modules/builtin-modules": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz", - "integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", "dev": true, "engines": { "node": ">=6" @@ -9498,9 +9498,9 @@ } }, "node_modules/ci-info": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", - "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.0.0.tgz", + "integrity": "sha512-TdHqgGf9odd8SXNuxtUBVx8Nv+qZOejE6qyqiy5NtbYYQOeFa6zmHkxlPzmaLxWWHsU6nJmB7AETdVPi+2NBUg==", "dev": true, "funding": [ { @@ -9919,6 +9919,19 @@ "url": "https://opencollective.com/core-js" } }, + "node_modules/core-js-compat": { + "version": "3.35.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.35.0.tgz", + "integrity": "sha512-5blwFAddknKeNgsjBzilkdQ0+YK8L1PfqPYq40NOYMYFSS38qj+hpTcLLWwpIwA2A5bje/x5jmVn2tzUMg9IVw==", + "dev": true, + "dependencies": { + "browserslist": "^4.22.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-js-pure": { "version": "3.21.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.21.1.tgz", @@ -11709,34 +11722,36 @@ } }, "node_modules/eslint-plugin-unicorn": { - "version": "43.0.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-43.0.2.tgz", - "integrity": "sha512-DtqZ5mf/GMlfWoz1abIjq5jZfaFuHzGBZYIeuJfEoKKGWRHr2JiJR+ea+BF7Wx2N1PPRoT/2fwgiK1NnmNE3Hg==", + "version": "50.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-50.0.1.tgz", + "integrity": "sha512-KxenCZxqSYW0GWHH18okDlOQcpezcitm5aOSz6EnobyJ6BIByiPDviQRjJIUAjG/tMN11958MxaQ+qCoU6lfDA==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", - "ci-info": "^3.3.2", + "@babel/helper-validator-identifier": "^7.22.20", + "@eslint-community/eslint-utils": "^4.4.0", + "@eslint/eslintrc": "^2.1.4", + "ci-info": "^4.0.0", "clean-regexp": "^1.0.0", - "eslint-utils": "^3.0.0", - "esquery": "^1.4.0", + "core-js-compat": "^3.34.0", + "esquery": "^1.5.0", "indent-string": "^4.0.0", - "is-builtin-module": "^3.1.0", - "lodash": "^4.17.21", + "is-builtin-module": "^3.2.1", + "jsesc": "^3.0.2", "pluralize": "^8.0.0", "read-pkg-up": "^7.0.1", - "regexp-tree": "^0.1.24", - "safe-regex": "^2.1.1", - "semver": "^7.3.7", + "regexp-tree": "^0.1.27", + "regjsparser": "^0.10.0", + "semver": "^7.5.4", "strip-indent": "^3.0.0" }, "engines": { - "node": ">=14.18" + "node": ">=16" }, "funding": { "url": "https://github.com/sindresorhus/eslint-plugin-unicorn?sponsor=1" }, "peerDependencies": { - "eslint": ">=8.18.0" + "eslint": ">=8.56.0" } }, "node_modules/eslint-plugin-unicorn/node_modules/find-up": { @@ -11752,6 +11767,18 @@ "node": ">=8" } }, + "node_modules/eslint-plugin-unicorn/node_modules/jsesc": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", + "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", + "dev": true, + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/eslint-plugin-unicorn/node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -14129,15 +14156,18 @@ } }, "node_modules/is-builtin-module": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.1.0.tgz", - "integrity": "sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", + "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", "dev": true, "dependencies": { - "builtin-modules": "^3.0.0" + "builtin-modules": "^3.3.0" }, "engines": { "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/is-callable": { @@ -19775,9 +19805,9 @@ "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==" }, "node_modules/regexp-tree": { - "version": "0.1.24", - "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.24.tgz", - "integrity": "sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==", + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", + "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", "dev": true, "bin": { "regexp-tree": "bin/regexp-tree" @@ -19835,6 +19865,27 @@ "node": ">=8" } }, + "node_modules/regjsparser": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.10.0.tgz", + "integrity": "sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==", + "dev": true, + "dependencies": { + "jsesc": "~0.5.0" + }, + "bin": { + "regjsparser": "bin/parser" + } + }, + "node_modules/regjsparser/node_modules/jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==", + "dev": true, + "bin": { + "jsesc": "bin/jsesc" + } + }, "node_modules/rehype-autolink-headings": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/rehype-autolink-headings/-/rehype-autolink-headings-6.1.1.tgz", @@ -20311,15 +20362,6 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, - "node_modules/safe-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", - "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", - "dev": true, - "dependencies": { - "regexp-tree": "~0.1.1" - } - }, "node_modules/safe-regex-test": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz", @@ -34003,9 +34045,9 @@ "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" }, "builtin-modules": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz", - "integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", "dev": true }, "busboy": { @@ -34251,9 +34293,9 @@ } }, "ci-info": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", - "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.0.0.tgz", + "integrity": "sha512-TdHqgGf9odd8SXNuxtUBVx8Nv+qZOejE6qyqiy5NtbYYQOeFa6zmHkxlPzmaLxWWHsU6nJmB7AETdVPi+2NBUg==", "dev": true }, "class-validator": { @@ -34573,6 +34615,15 @@ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.20.0.tgz", "integrity": "sha512-KjbKU7UEfg4YPpskMtMXPhUKn7m/1OdTHTVjy09ScR2LVaoUXe8Jh0UdvN2EKUR6iKTJph52SJP95mAB0MnVLQ==" }, + "core-js-compat": { + "version": "3.35.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.35.0.tgz", + "integrity": "sha512-5blwFAddknKeNgsjBzilkdQ0+YK8L1PfqPYq40NOYMYFSS38qj+hpTcLLWwpIwA2A5bje/x5jmVn2tzUMg9IVw==", + "dev": true, + "requires": { + "browserslist": "^4.22.2" + } + }, "core-js-pure": { "version": "3.21.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.21.1.tgz", @@ -35912,24 +35963,26 @@ "requires": {} }, "eslint-plugin-unicorn": { - "version": "43.0.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-43.0.2.tgz", - "integrity": "sha512-DtqZ5mf/GMlfWoz1abIjq5jZfaFuHzGBZYIeuJfEoKKGWRHr2JiJR+ea+BF7Wx2N1PPRoT/2fwgiK1NnmNE3Hg==", + "version": "50.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-50.0.1.tgz", + "integrity": "sha512-KxenCZxqSYW0GWHH18okDlOQcpezcitm5aOSz6EnobyJ6BIByiPDviQRjJIUAjG/tMN11958MxaQ+qCoU6lfDA==", "dev": true, "requires": { - "@babel/helper-validator-identifier": "^7.18.6", - "ci-info": "^3.3.2", + "@babel/helper-validator-identifier": "^7.22.20", + "@eslint-community/eslint-utils": "^4.4.0", + "@eslint/eslintrc": "^2.1.4", + "ci-info": "^4.0.0", "clean-regexp": "^1.0.0", - "eslint-utils": "^3.0.0", - "esquery": "^1.4.0", + "core-js-compat": "^3.34.0", + "esquery": "^1.5.0", "indent-string": "^4.0.0", - "is-builtin-module": "^3.1.0", - "lodash": "^4.17.21", + "is-builtin-module": "^3.2.1", + "jsesc": "^3.0.2", "pluralize": "^8.0.0", "read-pkg-up": "^7.0.1", - "regexp-tree": "^0.1.24", - "safe-regex": "^2.1.1", - "semver": "^7.3.7", + "regexp-tree": "^0.1.27", + "regjsparser": "^0.10.0", + "semver": "^7.5.4", "strip-indent": "^3.0.0" }, "dependencies": { @@ -35943,6 +35996,12 @@ "path-exists": "^4.0.0" } }, + "jsesc": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", + "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", + "dev": true + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -37654,12 +37713,12 @@ } }, "is-builtin-module": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.1.0.tgz", - "integrity": "sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", + "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", "dev": true, "requires": { - "builtin-modules": "^3.0.0" + "builtin-modules": "^3.3.0" } }, "is-callable": { @@ -41733,9 +41792,9 @@ "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==" }, "regexp-tree": { - "version": "0.1.24", - "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.24.tgz", - "integrity": "sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==", + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", + "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", "dev": true }, "regexp.prototype.flags": { @@ -41772,6 +41831,23 @@ "rc": "^1.2.8" } }, + "regjsparser": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.10.0.tgz", + "integrity": "sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==", + "dev": true, + "requires": { + "jsesc": "~0.5.0" + }, + "dependencies": { + "jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==", + "dev": true + } + } + }, "rehype-autolink-headings": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/rehype-autolink-headings/-/rehype-autolink-headings-6.1.1.tgz", @@ -42122,15 +42198,6 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, - "safe-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", - "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", - "dev": true, - "requires": { - "regexp-tree": "~0.1.1" - } - }, "safe-regex-test": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz", diff --git a/package.json b/package.json index 7fe28b6ab..7cf64c920 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "eslint-import-resolver-typescript": "3.6.1", "eslint-plugin-import": "2.29.1", "eslint-plugin-prettier": "5.1.2", - "eslint-plugin-unicorn": "43.0.2", + "eslint-plugin-unicorn": "50.0.1", "fs-extra": "11.2.0", "globby": "11.0.4", "graphql": "15.8.0", diff --git a/packages/backend/src/controllers/webhook.v1.ts b/packages/backend/src/controllers/webhook.v1.ts index 212e732aa..9befd0fb3 100644 --- a/packages/backend/src/controllers/webhook.v1.ts +++ b/packages/backend/src/controllers/webhook.v1.ts @@ -58,15 +58,15 @@ export const hook = (req: Request, res: Response): void => { let insightSyncTask: InsightSyncTask | null = null; if (req.headers['x-github-event'] !== undefined) { insightSyncTask = handleGitHub(webhook); - } else if (webhook.path !== undefined) { + } else if (webhook.path === undefined) { + res.status(400).send('Not Recognized'); + return; + } else { insightSyncTask = { repositoryType: RepositoryType.FILE, owner: 'local', repo: webhook.path }; - } else { - res.status(400).send('Not Recognized'); - return; } if (insightSyncTask == null) { diff --git a/packages/backend/src/lib/backends/base.sync.ts b/packages/backend/src/lib/backends/base.sync.ts index 78c8420c8..9714ca420 100644 --- a/packages/backend/src/lib/backends/base.sync.ts +++ b/packages/backend/src/lib/backends/base.sync.ts @@ -105,31 +105,13 @@ export abstract class BaseSync { // This key should be unchanging to avoid creating duplicates let existingDbInsight = await DbInsight.query().where('externalId', externalId).first(); - if (existingDbInsight != undefined) { - logger.trace('Insight does exist in database'); - await existingDbInsight.$query().patch({ - insightName: insight.fullName, - itemType: insight.itemType, - deletedAt: null, - repositoryData - }); - } else { + if (existingDbInsight == undefined) { logger.trace('Insight does not exist in database'); // Check to see if the fullName already exists, but with a different externalID existingDbInsight = await DbInsight.query().where('insightName', insight.fullName).first(); - if (existingDbInsight != undefined) { - // Assume the repo was deleted and recreated, and just update the external ID - // (We've already checked to ensure the external ID is unique) - logger.trace('Insight exists in database, but with a different externalId'); - await existingDbInsight.$query().patch({ - externalId, - itemType: insight.itemType, - deletedAt: null, - repositoryData - }); - } else { + if (existingDbInsight == undefined) { logger.trace('Insight does not exist in database'); existingDbInsight = await DbInsight.query().insert({ externalId, @@ -141,7 +123,25 @@ export abstract class BaseSync { repositoryData, itemType: insight.itemType }); + } else { + // Assume the repo was deleted and recreated, and just update the external ID + // (We've already checked to ensure the external ID is unique) + logger.trace('Insight exists in database, but with a different externalId'); + await existingDbInsight.$query().patch({ + externalId, + itemType: insight.itemType, + deletedAt: null, + repositoryData + }); } + } else { + logger.trace('Insight does exist in database'); + await existingDbInsight.$query().patch({ + insightName: insight.fullName, + itemType: insight.itemType, + deletedAt: null, + repositoryData + }); } logger.trace(JSON.stringify(existingDbInsight, null, 2)); diff --git a/packages/backend/src/lib/backends/file-system.sync.ts b/packages/backend/src/lib/backends/file-system.sync.ts index f86707fa0..72326e315 100644 --- a/packages/backend/src/lib/backends/file-system.sync.ts +++ b/packages/backend/src/lib/backends/file-system.sync.ts @@ -298,14 +298,15 @@ const getConversions = (insightFile: Omit): undefined | Insig switch (insightFile.mimeType) { case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': - case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': { return [ { mimeType: 'application/pdf', path: `.converted/${insightFile.path}.pdf` } ]; - case 'application/x-ipynb+json': + } + case 'application/x-ipynb+json': { return [ { mimeType: 'application/pdf', @@ -316,8 +317,10 @@ const getConversions = (insightFile: Omit): undefined | Insig path: `.converted/${insightFile.path}.html` } ]; - default: + } + default: { return undefined; + } } }; diff --git a/packages/backend/src/lib/backends/github.sync.ts b/packages/backend/src/lib/backends/github.sync.ts index c64130920..00cb6354d 100644 --- a/packages/backend/src/lib/backends/github.sync.ts +++ b/packages/backend/src/lib/backends/github.sync.ts @@ -426,14 +426,15 @@ const getConversions = (insightFile: Omit): undefined | Insig switch (insightFile.mimeType) { case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': - case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': { return [ { mimeType: 'application/pdf', path: `.converted/${insightFile.path}.pdf` } ]; - case 'application/x-ipynb+json': + } + case 'application/x-ipynb+json': { return [ { mimeType: 'application/pdf', @@ -444,8 +445,10 @@ const getConversions = (insightFile: Omit): undefined | Insig path: `.converted/${insightFile.path}.html` } ]; - default: + } + default: { return undefined; + } } }; diff --git a/packages/backend/src/lib/backends/github.ts b/packages/backend/src/lib/backends/github.ts index a2baad895..0c32a4fd3 100644 --- a/packages/backend/src/lib/backends/github.ts +++ b/packages/backend/src/lib/backends/github.ts @@ -50,7 +50,7 @@ export function makeGraphql(token: string = process.env.GITHUB_ACCESS_TOKEN!): g } return GQ.defaults({ - baseUrl: process.env.GITHUB_GRAPHQL_API_URL !== '' ? process.env.GITHUB_GRAPHQL_API_URL : undefined, + baseUrl: process.env.GITHUB_GRAPHQL_API_URL === '' ? undefined : process.env.GITHUB_GRAPHQL_API_URL, mediaType: { previews: ['bane'] }, @@ -72,7 +72,7 @@ export function makeOctokit(token: string = process.env.GITHUB_ACCESS_TOKEN!): O return new Octokit({ auth: token, userAgent: `iex ${process.env.IEX_VERSION || '0.0.0'}`, - baseUrl: process.env.GITHUB_REST_API_URL !== '' ? process.env.GITHUB_REST_API_URL : undefined, + baseUrl: process.env.GITHUB_REST_API_URL === '' ? undefined : process.env.GITHUB_REST_API_URL, log: { debug: logger.debug.bind(logger), info: logger.info.bind(logger), diff --git a/packages/backend/src/lib/backends/sync.ts b/packages/backend/src/lib/backends/sync.ts index d3b53b4d6..97566dfbb 100644 --- a/packages/backend/src/lib/backends/sync.ts +++ b/packages/backend/src/lib/backends/sync.ts @@ -31,14 +31,17 @@ export async function syncInsight(insightSyncTask: InsightSyncTask): Promise 0 ? edges[0].cursor : undefined, - endCursor: edges.length > 0 ? edges[edges.length - 1].cursor : undefined, + endCursor: edges.length > 0 ? edges.at(-1)?.cursor : undefined, // Unable to determine this hasNextPage: true, // Backwards cursor isn't supported diff --git a/packages/backend/src/lib/git-instance.ts b/packages/backend/src/lib/git-instance.ts index 9957bcac8..55462c390 100644 --- a/packages/backend/src/lib/git-instance.ts +++ b/packages/backend/src/lib/git-instance.ts @@ -218,7 +218,7 @@ export class GitInstance { async retrieveFileUtf8(filePath: string): Promise { const buffer = await this.retrieveFile(filePath); - return buffer != null ? buffer.toString('utf8') : null; + return buffer == null ? null : buffer.toString('utf8'); } // TODO: Only works for UTF-8 based-files diff --git a/packages/backend/src/lib/import.ts b/packages/backend/src/lib/import.ts index 27af0ee49..314ced9dd 100644 --- a/packages/backend/src/lib/import.ts +++ b/packages/backend/src/lib/import.ts @@ -184,7 +184,7 @@ export function convertToDraft(request: ImportRequest): DraftDataInput { `\n\n` + readmeFile.contents; - readmeFile.contents = readmeFile.contents.replace(/\u00A0/g, ' '); + readmeFile.contents = readmeFile.contents.replaceAll('\u00A0', ' '); } return combinedDraftData; diff --git a/packages/backend/src/resolvers/autocomplete.resolver.ts b/packages/backend/src/resolvers/autocomplete.resolver.ts index 74542cacd..f31854bef 100644 --- a/packages/backend/src/resolvers/autocomplete.resolver.ts +++ b/packages/backend/src/resolvers/autocomplete.resolver.ts @@ -113,11 +113,7 @@ export class AutocompleteResolver { // Combine both teams on Insights and Users const combined = [...publishedTeams, ...userTeams].reduce>((acc, v) => { - if (acc[v.value]) { - acc[v.value] = acc[v.value] + v.occurrences; - } else { - acc[v.value] = v.occurrences; - } + acc[v.value] = acc[v.value] ? acc[v.value] + v.occurrences : v.occurrences; return acc; }, {}); diff --git a/packages/backend/src/server.ts b/packages/backend/src/server.ts index e5e5d02c2..9fe505493 100644 --- a/packages/backend/src/server.ts +++ b/packages/backend/src/server.ts @@ -39,16 +39,19 @@ export async function createServer(): Promise { // Show routes called in console during development switch (process.env.NODE_ENV) { - case 'development': + case 'development': { logger.info('Loading development middleware'); app.use(security); break; - case 'production': + } + case 'production': { logger.info('Loading production middleware'); app.use(security); break; - default: + } + default: { logger.info('Actually ' + process.env.NODE_ENV); + } } app.use(compression()); diff --git a/packages/backend/src/services/activity.service.ts b/packages/backend/src/services/activity.service.ts index 08dbbb7f6..e3661c2cd 100644 --- a/packages/backend/src/services/activity.service.ts +++ b/packages/backend/src/services/activity.service.ts @@ -234,11 +234,13 @@ export class ActivityService { const cursor = toElasticsearchCursor( ...sort!.map((s) => { switch (s.field) { - case 'occurredAt': + case 'occurredAt': { // Special date handling return new Date(activity.occurredAt).getTime(); - case 'relevance': + } + case 'relevance': { return doc._score; + } } }) ); @@ -256,7 +258,7 @@ export class ActivityService { size: edges.length, total: elasticResponse.body.hits.total.value, startCursor: edges.length > 0 ? edges[0].cursor : undefined, - endCursor: edges.length > 0 ? edges[edges.length - 1].cursor : undefined, + endCursor: edges.length > 0 ? edges.at(-1)?.cursor : undefined, // Unable to determine this hasNextPage: true, // Backwards cursor isn't supported @@ -367,12 +369,15 @@ export class ActivityService { */ getSortField(field: string | undefined): string { switch (field) { - case undefined: + case undefined: { return this.defaultSort.field!; - case 'relevance': + } + case 'relevance': { return '_score'; - default: + } + default: { return field; + } } } } diff --git a/packages/backend/src/services/draft.service.ts b/packages/backend/src/services/draft.service.ts index 7d3f2e332..0c2c3b595 100644 --- a/packages/backend/src/services/draft.service.ts +++ b/packages/backend/src/services/draft.service.ts @@ -103,15 +103,15 @@ export class DraftService { draftRemains.insightId = dbInsightId; } - if (existingDraft != undefined) { - logger.trace('Draft does exist in database'); - return await existingDraft.$query().patchAndFetch(draftRemains); - } else { + if (existingDraft == undefined) { logger.trace('Draft does not exist in database'); return await Draft.query().insert({ ...draftRemains, createdByUserId: user?.userId }); + } else { + logger.trace('Draft does exist in database'); + return await existingDraft.$query().patchAndFetch(draftRemains); } } @@ -124,7 +124,9 @@ export class DraftService { async deleteDraft(draftKey: DraftKey, user: User): Promise { const existingDraft = await Draft.query().where('draftKey', draftKey).first(); - if (existingDraft != undefined) { + if (existingDraft == undefined) { + throw new Error('Draft not found by key: ' + draftKey); + } else { if (existingDraft.createdByUserId != user.userId && existingDraft.createdByUserId != null) { throw new Error('Not allowed'); } @@ -135,8 +137,6 @@ export class DraftService { throw new Error('Unexpectedly, Draft not deleted'); } return existingDraft; - } else { - throw new Error('Draft not found by key: ' + draftKey); } } diff --git a/packages/backend/src/services/insight.service.ts b/packages/backend/src/services/insight.service.ts index 0a53eb71d..7b99105be 100644 --- a/packages/backend/src/services/insight.service.ts +++ b/packages/backend/src/services/insight.service.ts @@ -183,13 +183,16 @@ export class InsightService { ); switch (permission) { - case 'ADMIN': + case 'ADMIN': { return RepositoryPermission.ADMIN; + } case 'MAINTAIN': - case 'WRITE': + case 'WRITE': { return RepositoryPermission.WRITE; - default: + } + default: { return RepositoryPermission.READ; + } } } @@ -448,7 +451,7 @@ export class InsightService { logger.info(`Updating Insight: ${insight.fullName}`); // Convert all tags to lower case - updatedYaml.tags = updatedYaml.tags?.map((tag) => tag.trim().toLowerCase().replace(/\s/g, '-')); + updatedYaml.tags = updatedYaml.tags?.map((tag) => tag.trim().toLowerCase().replaceAll(/\s/g, '-')); try { // Push changes to the git repository @@ -477,7 +480,7 @@ export class InsightService { } // Add/modify existing file with inline content - case InsightFileAction.MODIFY: + case InsightFileAction.MODIFY: { logger.debug(`Modifying file: ${file.path}`); if ( @@ -490,23 +493,27 @@ export class InsightService { } return gitInstance.putFile(file.path!, file.contents!); + } // Rename file only - case InsightFileAction.RENAME: + case InsightFileAction.RENAME: { logger.debug(`Renaming file: ${file.path}`); if (file.originalPath) { return gitInstance.renameFile(file.originalPath, file.path); } return; + } // Delete file - case InsightFileAction.DELETE: + case InsightFileAction.DELETE: { logger.debug(`Deleting file: ${file.path}`); return gitInstance.deleteFile(file.path); + } case InsightFileAction.NONE: - default: + default: { return; + } } }) ); @@ -818,14 +825,18 @@ export class InsightService { const perm = (() => { switch (permission) { - case undefined: + case undefined: { return; - case 'ADMIN': + } + case 'ADMIN': { return 'admin'; - case 'READ': + } + case 'READ': { return 'pull'; - default: + } + default: { return 'push'; + } } })(); diff --git a/packages/backend/src/services/oauth.service.ts b/packages/backend/src/services/oauth.service.ts index 47a509d02..0e4e7517b 100644 --- a/packages/backend/src/services/oauth.service.ts +++ b/packages/backend/src/services/oauth.service.ts @@ -42,8 +42,9 @@ export class OAuthService { return response.data.access_token; } - default: + default: { throw new Error('OAuth provider not supported'); + } } } } diff --git a/packages/backend/src/services/user.service.ts b/packages/backend/src/services/user.service.ts index 7528a334d..1c6b1f9fb 100644 --- a/packages/backend/src/services/user.service.ts +++ b/packages/backend/src/services/user.service.ts @@ -187,15 +187,18 @@ export class UserService { }; switch (updatedUser.defaultTemplateId) { - case '': + case '': { // Set the defaultTemplate back to NULL if empty userPatch.defaultTemplate = defaultKnex.raw('DEFAULT'); break; - case undefined: + } + case undefined: { break; - default: + } + default: { // Convert from global ID to database ID userPatch.defaultTemplate = fromGlobalId(updatedUser.defaultTemplateId)[1]; + } } const updated = await User.query().patchAndFetchById(user.userId, userPatch); diff --git a/packages/backend/src/shared/slugify.ts b/packages/backend/src/shared/slugify.ts index f3d553f60..cada44e6f 100644 --- a/packages/backend/src/shared/slugify.ts +++ b/packages/backend/src/shared/slugify.ts @@ -28,7 +28,7 @@ const logger = getLogger('slugify'); */ export function slugifyInsightName(name: string): string { const v1 = deburr(kebabCase(name.trim())); - const slug = v1.replace(/--/g, '-').replace(/'/g, ''); + const slug = v1.replaceAll('--', '-').replaceAll("'", ''); return slug; } diff --git a/packages/convertbot/src/server.ts b/packages/convertbot/src/server.ts index 92ae55f09..3267b5c21 100644 --- a/packages/convertbot/src/server.ts +++ b/packages/convertbot/src/server.ts @@ -37,16 +37,19 @@ app.set('env', process.env.NODE_ENV); // Show routes called in console during development switch (process.env.NODE_ENV) { - case 'development': + case 'development': { logger.info('Loading development middleware'); app.use(security); break; - case 'production': + } + case 'production': { logger.info('Loading production middleware'); app.use(security); break; - default: + } + default: { logger.info('Actually ' + process.env.NODE_ENV); + } } app.use(compression()); diff --git a/packages/frontend/src/components/activity-view/activity-view.tsx b/packages/frontend/src/components/activity-view/activity-view.tsx index 149b162cf..6acc2fc77 100644 --- a/packages/frontend/src/components/activity-view/activity-view.tsx +++ b/packages/frontend/src/components/activity-view/activity-view.tsx @@ -41,7 +41,7 @@ const DeletedBadge = () => deleted; const getActivityParts = (activity: Activity) => { switch (activity.activityType) { - case ActivityType.Login: + case ActivityType.Login: { return { icon: 'login', lead: ( @@ -52,6 +52,7 @@ const getActivityParts = (activity: Activity) => { ), details: null }; + } case ActivityType.CreateInsight: { const details = activity.details as InsightActivityDetails; @@ -60,7 +61,11 @@ const getActivityParts = (activity: Activity) => { lead: ( - {details.insight != null ? ( + {details.insight == null ? ( + + created a new + + ) : ( created a new {details.insight.itemType}{' '} @@ -70,10 +75,6 @@ const getActivityParts = (activity: Activity) => { {details.commitMessage && `: "${details.commitMessage}"`} - ) : ( - - created a new - )} ), @@ -90,7 +91,11 @@ const getActivityParts = (activity: Activity) => { lead: ( - {details.insight != null ? ( + {details.insight == null ? ( + + edited + + ) : ( edited{' '} @@ -100,10 +105,6 @@ const getActivityParts = (activity: Activity) => { {details.commitMessage && `: "${details.commitMessage}"`} - ) : ( - - edited - )} ), @@ -120,7 +121,11 @@ const getActivityParts = (activity: Activity) => { lead: ( - {details.insight != null ? ( + {details.insight == null ? ( + + deleted + + ) : ( deleted{' '} @@ -129,10 +134,6 @@ const getActivityParts = (activity: Activity) => { - ) : ( - - deleted - )} ), @@ -161,14 +162,14 @@ const getActivityParts = (activity: Activity) => { {verb}{' '} - {details.insight != null ? ( + {details.insight == null ? ( + + ) : ( {details.insight.name} - ) : ( - )} @@ -191,14 +192,14 @@ const getActivityParts = (activity: Activity) => { {verb}{' '} - {details.insight != null ? ( + {details.insight == null ? ( + + ) : ( {details.insight.name} - ) : ( - )} @@ -216,26 +217,31 @@ const getActivityParts = (activity: Activity) => { let verb = 'verb'; switch (activity.activityType) { - case ActivityType.CreateComment: + case ActivityType.CreateComment: { icon = 'comments'; verb = 'commented on'; break; - case ActivityType.EditComment: + } + case ActivityType.EditComment: { icon = 'comments'; verb = 'edited a comment on'; break; - case ActivityType.LikeComment: + } + case ActivityType.LikeComment: { icon = 'heartFilled'; verb = 'liked a comment on'; break; - case ActivityType.UnlikeComment: + } + case ActivityType.UnlikeComment: { icon = 'unlike'; verb = 'unliked a comment on'; break; - case ActivityType.DeleteComment: + } + case ActivityType.DeleteComment: { icon = 'trash'; verb = 'deleted a comment on'; break; + } } return { @@ -245,7 +251,9 @@ const getActivityParts = (activity: Activity) => { {verb}{' '} - {details?.comment != null ? ( + {details?.comment == null ? ( + + ) : ( { {details.comment.insight.name} - ) : ( - )} @@ -264,7 +270,7 @@ const getActivityParts = (activity: Activity) => { }; } - case ActivityType.UpdateProfile: + case ActivityType.UpdateProfile: { return { icon: 'profile', lead: ( @@ -279,6 +285,7 @@ const getActivityParts = (activity: Activity) => { ) }; + } case ActivityType.AddCollaborator: case ActivityType.RemoveCollaborator: { @@ -294,14 +301,14 @@ const getActivityParts = (activity: Activity) => { {added ? added : removed } {added ? ' to ' : ' from '} - {details.insight != null ? ( + {details.insight == null ? ( + + ) : ( {details.insight.name} - ) : ( - )} @@ -331,12 +338,12 @@ const getActivityParts = (activity: Activity) => { {verb} a news item: - {details.news !== null ? ( + {details.news === null ? ( + + ) : ( {details.news.summary} - ) : ( - )} @@ -345,8 +352,9 @@ const getActivityParts = (activity: Activity) => { }; } - default: + default: { return null; + } } }; diff --git a/packages/frontend/src/components/alert/alert.tsx b/packages/frontend/src/components/alert/alert.tsx index 19c2e771f..411f20001 100644 --- a/packages/frontend/src/components/alert/alert.tsx +++ b/packages/frontend/src/components/alert/alert.tsx @@ -56,9 +56,7 @@ export const Alert = ({ if (status === 'secure') { icon = iconFactory('secure'); derivedStatus = 'info'; - } else if (status != null) { - derivedStatus = status; - } else { + } else if (status == null) { // Auto-detect status from which variable was used if (error != null) { derivedMessage = getMessage(error); @@ -69,12 +67,14 @@ export const Alert = ({ } else if (info != null) { derivedMessage = getMessage(info); derivedStatus = 'info'; - } else if (success != null) { + } else if (success == null) { + derivedStatus = 'error'; + } else { derivedMessage = getMessage(success); derivedStatus = 'success'; - } else { - derivedStatus = 'error'; } + } else { + derivedStatus = status; } return ( diff --git a/packages/frontend/src/components/auth/auth-provider.tsx b/packages/frontend/src/components/auth/auth-provider.tsx index 55c35aefb..5a4ea74c5 100644 --- a/packages/frontend/src/components/auth/auth-provider.tsx +++ b/packages/frontend/src/components/auth/auth-provider.tsx @@ -28,15 +28,18 @@ export const AUTH_ERROR_PATH = '/auth/error'; const getAuthProviderComponent = (authProvider: string | undefined, children: any) => { switch (authProvider) { - case 'github': + case 'github': { return ; + } - case 'okta': + case 'okta': { return ; + } - default: + default: { // TODO: Handle other auth strategies return null; + } } }; diff --git a/packages/frontend/src/components/auth/okta-auth-provider/okta-auth-provider.tsx b/packages/frontend/src/components/auth/okta-auth-provider/okta-auth-provider.tsx index 4d3f5f1ac..321945ed0 100644 --- a/packages/frontend/src/components/auth/okta-auth-provider/okta-auth-provider.tsx +++ b/packages/frontend/src/components/auth/okta-auth-provider/okta-auth-provider.tsx @@ -56,16 +56,16 @@ const AuthWrapper = ({ children }: Props) => { return; } - if (!authState.isAuthenticated) { - // Trigger Okta Login - oktaAuth.signInWithRedirect({ originalUri: window.location.href }); - } else { + if (authState.isAuthenticated) { // Okta already logged in // Login against the IEX service if (authState.accessToken && loggingIn.current === false) { loggingIn.current = true; dispatch(login(authState.accessToken.accessToken)); } + } else { + // Trigger Okta Login + oktaAuth.signInWithRedirect({ originalUri: window.location.href }); } }, [authState, dispatch, requestingLogin, oktaAuth]); diff --git a/packages/frontend/src/components/file-browser/file-browser.tsx b/packages/frontend/src/components/file-browser/file-browser.tsx index aaf860b9c..e3711cee6 100644 --- a/packages/frontend/src/components/file-browser/file-browser.tsx +++ b/packages/frontend/src/components/file-browser/file-browser.tsx @@ -140,20 +140,22 @@ const FolderRenderer = ({ } switch (monitor.getItemType()) { - case NativeTypes.FILE: + case NativeTypes.FILE: { // Upload file and add to tree if (actions.onUpload) { actions.onUpload(droppedItem.files, item); onOpen(); } break; + } - case 'file': + case 'file': { // Move file to new location in tree if (actions.onMove) { actions.onMove(droppedItem, `${item.path}/${droppedItem.name}`); onOpen(); } + } } }, collect: (monitor) => ({ diff --git a/packages/frontend/src/components/file-viewer/file-viewer.tsx b/packages/frontend/src/components/file-viewer/file-viewer.tsx index da8075a93..37d02ba7e 100644 --- a/packages/frontend/src/components/file-viewer/file-viewer.tsx +++ b/packages/frontend/src/components/file-viewer/file-viewer.tsx @@ -39,7 +39,7 @@ import { VideoRenderer } from '../renderers/video-renderer/video-renderer'; const getHeaderStyles = (header: 'normal' | 'stealth' | 'none') => { switch (header) { - case 'normal': + case 'normal': { return [ { bg: 'gray.100', @@ -52,9 +52,11 @@ const getHeaderStyles = (header: 'normal' | 'stealth' | 'none') => { borderBottomRadius: '0.5rem' } ]; - case 'stealth': + } + case 'stealth': { return [{}, { borderRadius: '0.5rem' }]; - case 'none': + } + case 'none': { return [ { display: 'none' @@ -63,6 +65,7 @@ const getHeaderStyles = (header: 'normal' | 'stealth' | 'none') => { borderRadius: '0.5rem' } ]; + } } }; @@ -183,7 +186,7 @@ export const FileViewer = ({ if (mimeTypeDef) { switch (mimeTypeDef.viewer) { - case MIME_VIEWER.Markdown: + case MIME_VIEWER.Markdown: { unpause(); if (mode === 'rendered') { renderer = ( @@ -201,32 +204,37 @@ export const FileViewer = ({ canDisplayRaw = mode === 'rendered'; canDisplayRendered = !canDisplayRaw; break; + } - case MIME_VIEWER.PDF: + case MIME_VIEWER.PDF: { pause(); renderer = ; canDisplayRaw = canDisplayRendered = false; break; + } - case MIME_VIEWER.Code: + case MIME_VIEWER.Code: { unpause(); renderer = ; canDisplayRaw = canDisplayRendered = false; break; + } - case MIME_VIEWER.Image: + case MIME_VIEWER.Image: { pause(); renderer = ; canDisplayRaw = canDisplayRendered = false; break; + } - case MIME_VIEWER.Video: + case MIME_VIEWER.Video: { pause(); renderer = ; canDisplayRaw = canDisplayRendered = false; break; + } - case MIME_VIEWER.Html: + case MIME_VIEWER.Html: { unpause(); if (mode === 'rendered') { renderer = ; @@ -236,8 +244,9 @@ export const FileViewer = ({ canDisplayRaw = mode === 'rendered'; canDisplayRendered = !canDisplayRaw; break; + } - case MIME_VIEWER.Csv: + case MIME_VIEWER.Csv: { unpause(); if (mode === 'rendered') { renderer = ; @@ -247,8 +256,9 @@ export const FileViewer = ({ canDisplayRaw = mode === 'rendered'; canDisplayRendered = !canDisplayRaw; break; + } - case MIME_VIEWER.Json: + case MIME_VIEWER.Json: { unpause(); if (mode === 'rendered') { renderer = ; @@ -258,16 +268,19 @@ export const FileViewer = ({ canDisplayRaw = mode === 'rendered'; canDisplayRendered = !canDisplayRaw; break; + } - case MIME_VIEWER.None: + case MIME_VIEWER.None: { pause(); renderer = ; break; + } - default: + default: { unpause(); renderer = ; canDisplayRaw = canDisplayRendered = false; + } } } else { console.log(`Viewing unknown MIME type: ${mime}`); diff --git a/packages/frontend/src/components/insight-connection-card/insight-connection-card.tsx b/packages/frontend/src/components/insight-connection-card/insight-connection-card.tsx index a10c0ed74..a15b229e4 100644 --- a/packages/frontend/src/components/insight-connection-card/insight-connection-card.tsx +++ b/packages/frontend/src/components/insight-connection-card/insight-connection-card.tsx @@ -30,12 +30,15 @@ export interface InsightConnectionCardProps { export const InsightConnectionCard = ({ insightEdge, options, ...props }: InsightConnectionCardProps & BoxProps) => { switch (options.layout) { - case 'square': + case 'square': { return ; - case 'compact': + } + case 'compact': { return ; + } case 'default': - default: + default: { return ; + } } }; diff --git a/packages/frontend/src/components/insight-list/components/insight-list-skeleton/insight-list-skeleton.tsx b/packages/frontend/src/components/insight-list/components/insight-list-skeleton/insight-list-skeleton.tsx index 2dc1edbb0..52de3d6d7 100644 --- a/packages/frontend/src/components/insight-list/components/insight-list-skeleton/insight-list-skeleton.tsx +++ b/packages/frontend/src/components/insight-list/components/insight-list-skeleton/insight-list-skeleton.tsx @@ -44,7 +44,7 @@ export const InsightListSkeleton = ({ count = 3, options }) => { let layoutProps = {}; switch (options.layout) { - case 'square': + case 'square': { layoutProps = { height: { base: '16rem', md: '17rem', lg: '18rem', '2xl': '20rem' }, width: { base: '16rem', md: '17rem', lg: '18rem', '2xl': '20rem' }, @@ -52,16 +52,19 @@ export const InsightListSkeleton = ({ count = 3, options }) => { marginRight: '1rem' }; break; - case 'compact': + } + case 'compact': { layoutProps = { height: '3.1rem' }; break; + } case 'default': - default: + default: { layoutProps = { height: '7rem' }; + } } return ( diff --git a/packages/frontend/src/components/insight-list/insight-list.tsx b/packages/frontend/src/components/insight-list/insight-list.tsx index d4e46f386..34d59ddba 100644 --- a/packages/frontend/src/components/insight-list/insight-list.tsx +++ b/packages/frontend/src/components/insight-list/insight-list.tsx @@ -26,7 +26,7 @@ import { InsightListSkeleton } from './components/insight-list-skeleton/insight- const EdgeContainer = ({ edges, options }) => { switch (options.layout) { - case 'square': + case 'square': { return ( { ))} ); + } default: { const marginBottom = options.layout === 'compact' ? '0.5rem' : '1rem'; diff --git a/packages/frontend/src/components/link-overlay/link-overlay.tsx b/packages/frontend/src/components/link-overlay/link-overlay.tsx index e78f0659f..0752472ed 100644 --- a/packages/frontend/src/components/link-overlay/link-overlay.tsx +++ b/packages/frontend/src/components/link-overlay/link-overlay.tsx @@ -28,5 +28,5 @@ export const LinkOverlay = ({ underline = true, ...props }: { underline?: boolean } & RouterLinkProps & ChakraLinkOverlayProps) => ( - + ); diff --git a/packages/frontend/src/components/link/link.tsx b/packages/frontend/src/components/link/link.tsx index f26c4f3ea..adc123d1e 100644 --- a/packages/frontend/src/components/link/link.tsx +++ b/packages/frontend/src/components/link/link.tsx @@ -30,6 +30,6 @@ export const Link = forwardRef( { underline = true, ...props }: { underline?: boolean } & RouterLinkProps & ChakraLinkProps, ref: React.Ref ) => ( - + ) ); diff --git a/packages/frontend/src/components/markdown-container/chakra-ui-renderer.tsx b/packages/frontend/src/components/markdown-container/chakra-ui-renderer.tsx index c17d486a9..47a7891b8 100644 --- a/packages/frontend/src/components/markdown-container/chakra-ui-renderer.tsx +++ b/packages/frontend/src/components/markdown-container/chakra-ui-renderer.tsx @@ -242,7 +242,7 @@ export const ChakraUIRenderer = ( return ( {children} diff --git a/packages/frontend/src/components/renderers/xkcd-chart-renderer/xkcd-chart-renderer.tsx b/packages/frontend/src/components/renderers/xkcd-chart-renderer/xkcd-chart-renderer.tsx index 8f718bd75..99cf8f6cd 100644 --- a/packages/frontend/src/components/renderers/xkcd-chart-renderer/xkcd-chart-renderer.tsx +++ b/packages/frontend/src/components/renderers/xkcd-chart-renderer/xkcd-chart-renderer.tsx @@ -31,20 +31,27 @@ interface Props { const ChartPicker = ({ type, config }) => { switch (type.toLowerCase().trim()) { - case 'bar': + case 'bar': { return ; - case 'line': + } + case 'line': { return ; - case 'pie': + } + case 'pie': { return ; - case 'radar': + } + case 'radar': { return ; - case 'stackedbar': + } + case 'stackedbar': { return ; - case 'xy': + } + case 'xy': { return ; - default: + } + default: { return null; + } } }; diff --git a/packages/frontend/src/components/sidebar-stack/sidebar-stack.tsx b/packages/frontend/src/components/sidebar-stack/sidebar-stack.tsx index 0533fc69e..0b216f22c 100644 --- a/packages/frontend/src/components/sidebar-stack/sidebar-stack.tsx +++ b/packages/frontend/src/components/sidebar-stack/sidebar-stack.tsx @@ -26,7 +26,14 @@ interface SidebarStackProps { } export const SidebarStack = ({ children, heading, tooltip, ...boxProps }: SidebarStackProps & BoxProps) => { - if (tooltip != null) { + if (tooltip == null) { + return ( + + {heading && {heading}} + {children} + + ); + } else { return ( @@ -35,12 +42,5 @@ export const SidebarStack = ({ children, heading, tooltip, ...boxProps }: Sideba ); - } else { - return ( - - {heading && {heading}} - {children} - - ); } }; diff --git a/packages/frontend/src/pages/activity-page/components/activity-filter-sidebar/activity-filter-sidebar.tsx b/packages/frontend/src/pages/activity-page/components/activity-filter-sidebar/activity-filter-sidebar.tsx index 22bfe3a92..62fe5b994 100644 --- a/packages/frontend/src/pages/activity-page/components/activity-filter-sidebar/activity-filter-sidebar.tsx +++ b/packages/frontend/src/pages/activity-page/components/activity-filter-sidebar/activity-filter-sidebar.tsx @@ -177,11 +177,8 @@ export const ActivityFilterSidebar = ({ suggestedFilters, ...boxProps }: Props & }); if (existingIndex > -1) { - if (values.length === 1) { - searchClauses[existingIndex] = new SearchTerm(key, values[0]); - } else { - searchClauses[existingIndex] = new SearchMultiTerm(key, values); - } + searchClauses[existingIndex] = + values.length === 1 ? new SearchTerm(key, values[0]) : new SearchMultiTerm(key, values); dispatch(activitySlice.actions.setQuery(toSearchQuery(searchClauses))); } else { diff --git a/packages/frontend/src/pages/activity-page/components/activity-search-bar/activity-search-bar.tsx b/packages/frontend/src/pages/activity-page/components/activity-search-bar/activity-search-bar.tsx index c81f4884d..930f48f24 100644 --- a/packages/frontend/src/pages/activity-page/components/activity-search-bar/activity-search-bar.tsx +++ b/packages/frontend/src/pages/activity-page/components/activity-search-bar/activity-search-bar.tsx @@ -144,8 +144,8 @@ export const ActivitySearchBar = (): ReactElement => { ({ diff --git a/packages/frontend/src/pages/insight-editor/components/insight-file-editor/insight-file-editor.tsx b/packages/frontend/src/pages/insight-editor/components/insight-file-editor/insight-file-editor.tsx index 4ee8aabf8..b727827db 100644 --- a/packages/frontend/src/pages/insight-editor/components/insight-file-editor/insight-file-editor.tsx +++ b/packages/frontend/src/pages/insight-editor/components/insight-file-editor/insight-file-editor.tsx @@ -139,7 +139,7 @@ export const InsightFileEditor = ({ const mimeTypeDef = getMimeTypeDefinition(mime); switch (mimeTypeDef?.editor ?? MIME_EDITOR.Code) { - case MIME_EDITOR.Markdown: + case MIME_EDITOR.Markdown: { return ( ); break; + } - case MIME_EDITOR.Html: + case MIME_EDITOR.Html: { return ( ); break; + } - case MIME_EDITOR.Code: + case MIME_EDITOR.Code: { return ( ); + } } }; diff --git a/packages/frontend/src/pages/insight-editor/components/insight-metadata-editor/insight-tags.tsx b/packages/frontend/src/pages/insight-editor/components/insight-metadata-editor/insight-tags.tsx index 2356cee3c..749ebc6b3 100644 --- a/packages/frontend/src/pages/insight-editor/components/insight-metadata-editor/insight-tags.tsx +++ b/packages/frontend/src/pages/insight-editor/components/insight-metadata-editor/insight-tags.tsx @@ -71,7 +71,7 @@ export const InsightTags = ({ insight, form }) => { onChange={(event) => { let tags: string[] = []; if (event != null) { - tags = event.map((e) => e.value.trim().toLowerCase().replace(/\s/g, '-')); + tags = event.map((e) => e.value.trim().toLowerCase().replaceAll(/\s/g, '-')); } onChange(tags); }} diff --git a/packages/frontend/src/pages/insight-editor/insight-draft-switcher.tsx b/packages/frontend/src/pages/insight-editor/insight-draft-switcher.tsx index 8fa8c950e..dd4abaea7 100644 --- a/packages/frontend/src/pages/insight-editor/insight-draft-switcher.tsx +++ b/packages/frontend/src/pages/insight-editor/insight-draft-switcher.tsx @@ -182,7 +182,7 @@ export const InsightDraftSwitcher = ({ insight, onRefresh }) => { {!hasDraftKey && ( Info: You have {pendingDrafts.length} unpublished draft - {pendingDrafts.length > 1 ? 's' : ''} for {insight !== null ? 'this Insight' : 'a new Insight'}; do you + {pendingDrafts.length > 1 ? 's' : ''} for {insight === null ? 'a new Insight' : 'this Insight'}; do you want to resume editing an existing draft or create a new draft? )} diff --git a/packages/frontend/src/pages/insight-page/components/insight-viewer/item-type-viewer.tsx b/packages/frontend/src/pages/insight-page/components/insight-viewer/item-type-viewer.tsx index 77736a29c..6cbd492bc 100644 --- a/packages/frontend/src/pages/insight-page/components/insight-viewer/item-type-viewer.tsx +++ b/packages/frontend/src/pages/insight-page/components/insight-viewer/item-type-viewer.tsx @@ -32,11 +32,13 @@ export interface ItemTypeViewerProps { export const ItemTypeViewer = ({ ...props }: ItemTypeViewerProps) => { switch (props.insight.itemType) { - case 'page': + case 'page': { return ; + } case 'insight': case 'template': - default: + default: { return ; + } } }; diff --git a/packages/frontend/src/pages/main-page/components/header/components/news-drawer/components/news-item/news-item.tsx b/packages/frontend/src/pages/main-page/components/header/components/news-drawer/components/news-item/news-item.tsx index 54310e14c..403ee9668 100644 --- a/packages/frontend/src/pages/main-page/components/header/components/news-drawer/components/news-item/news-item.tsx +++ b/packages/frontend/src/pages/main-page/components/header/components/news-drawer/components/news-item/news-item.tsx @@ -75,7 +75,7 @@ const customComponents: Components = { {children} diff --git a/packages/frontend/src/pages/search-page/components/filter-sidebar/filter-sidebar.tsx b/packages/frontend/src/pages/search-page/components/filter-sidebar/filter-sidebar.tsx index bedd101b1..6cc7084e8 100644 --- a/packages/frontend/src/pages/search-page/components/filter-sidebar/filter-sidebar.tsx +++ b/packages/frontend/src/pages/search-page/components/filter-sidebar/filter-sidebar.tsx @@ -182,11 +182,8 @@ export const FilterSidebar = ({ suggestedFilters, ...boxProps }: Props & BoxProp }); if (existingIndex > -1) { - if (values.length === 1) { - searchClauses[existingIndex] = new SearchTerm(key, values[0]); - } else { - searchClauses[existingIndex] = new SearchMultiTerm(key, values); - } + searchClauses[existingIndex] = + values.length === 1 ? new SearchTerm(key, values[0]) : new SearchMultiTerm(key, values); dispatch(searchSlice.actions.setQuery(toSearchQuery(searchClauses))); } else { diff --git a/packages/frontend/src/pages/search-page/components/search-bar/search-bar.tsx b/packages/frontend/src/pages/search-page/components/search-bar/search-bar.tsx index 3740601a3..c130d400c 100644 --- a/packages/frontend/src/pages/search-page/components/search-bar/search-bar.tsx +++ b/packages/frontend/src/pages/search-page/components/search-bar/search-bar.tsx @@ -155,8 +155,8 @@ export const SearchBar = (): ReactElement => { { onChange={(e) => { let skills: string[] = []; if (e != null) { - skills = e.map((v) => v.value.trim().toLowerCase().replace(/\s/g, '-')); + skills = e.map((v) => v.value.trim().toLowerCase().replaceAll(/\s/g, '-')); } setValue('skills', skills); }} diff --git a/packages/frontend/src/shared/chat-icon.ts b/packages/frontend/src/shared/chat-icon.ts index e79881e4c..d22856f73 100644 --- a/packages/frontend/src/shared/chat-icon.ts +++ b/packages/frontend/src/shared/chat-icon.ts @@ -19,9 +19,11 @@ import { FaSlack } from 'react-icons/fa'; export const chatIcon = (provider: string) => { switch (provider) { - case 'slack': + case 'slack': { return FaSlack; - default: + } + default: { return BsChatDots; + } } }; diff --git a/packages/frontend/src/shared/file-tree.ts b/packages/frontend/src/shared/file-tree.ts index 79b3c56de..0149c423f 100644 --- a/packages/frontend/src/shared/file-tree.ts +++ b/packages/frontend/src/shared/file-tree.ts @@ -217,10 +217,10 @@ export function addFileToTree( if (remainingPathParts.length === 1) { // This is a file, push into the tree const existingFile = tree.find((f) => f.name === file.name); - if (existingFile !== undefined) { - Object.assign(existingFile, file); - } else { + if (existingFile === undefined) { tree.push(file); + } else { + Object.assign(existingFile, file); } // Sort this branch of the tree diff --git a/packages/frontend/src/shared/form-utils.ts b/packages/frontend/src/shared/form-utils.ts index 58744b65e..e4dac1f83 100644 --- a/packages/frontend/src/shared/form-utils.ts +++ b/packages/frontend/src/shared/form-utils.ts @@ -33,11 +33,14 @@ export const formatFormError = ( } switch (error.type) { - case 'maxLength': + case 'maxLength': { return 'This value is too long.'; - case 'required': + } + case 'required': { return 'This value is required.'; - default: + } + default: { return 'This field has an error.'; + } } }; diff --git a/packages/frontend/src/shared/gradient.ts b/packages/frontend/src/shared/gradient.ts index 11e23e135..373d82f36 100644 --- a/packages/frontend/src/shared/gradient.ts +++ b/packages/frontend/src/shared/gradient.ts @@ -24,9 +24,9 @@ export const getInsightGradient = (insight: Insight): string => { // Use a separate gradient color set for Pages if (insight.itemType === 'page') { - i = insight.id !== undefined ? (hashCode(insight.id) % 5) + 11 : getRandomInt(12, 15); + i = insight.id === undefined ? getRandomInt(12, 15) : (hashCode(insight.id) % 5) + 11; } else { - i = insight.id !== undefined ? (hashCode(insight.id) % 4) + 7 : getRandomInt(7, 11); + i = insight.id === undefined ? getRandomInt(7, 11) : (hashCode(insight.id) % 4) + 7; } return `linear(to-tr, nord${i}.100 0%, nord${i}.400 100%)`; diff --git a/packages/frontend/src/shared/item-type.ts b/packages/frontend/src/shared/item-type.ts index 36833d8f6..b680692c4 100644 --- a/packages/frontend/src/shared/item-type.ts +++ b/packages/frontend/src/shared/item-type.ts @@ -16,15 +16,18 @@ export const getItemType = (itemType: string) => { switch ((itemType ?? 'insight').toLowerCase()) { - case 'template': + case 'template': { return { iconKey: 'template', color: 'nord15.500' }; + } - case 'page': + case 'page': { return { iconKey: 'page', color: 'nord12.500' }; + } case 'insight': - default: + default: { return { iconKey: 'insight', color: 'nord14.500' }; + } } }; diff --git a/packages/frontend/src/shared/remark/remark-code-plus.ts b/packages/frontend/src/shared/remark/remark-code-plus.ts index 3d11f2a25..a4eab7c45 100644 --- a/packages/frontend/src/shared/remark/remark-code-plus.ts +++ b/packages/frontend/src/shared/remark/remark-code-plus.ts @@ -57,7 +57,7 @@ export const remarkCodePlus = ({ baseUrl = '', transformAssetUri }: Props) => { attributes.forEach((attribute) => { if (attribute instanceof KeyValueAttribute) { switch (attribute.key) { - case 'file': + case 'file': { if (isAbsoluteUrl(attribute.value)) { node.data.hProperties.uri = attribute.value; } else { @@ -66,16 +66,19 @@ export const remarkCodePlus = ({ baseUrl = '', transformAssetUri }: Props) => { : urljoin(baseUrl, attribute.value); } break; + } - case 'lines': + case 'lines': { node.data.hProperties.lines = attribute.value; break; + } } } else if (attribute instanceof KeyAttribute) { switch (attribute.key) { - case 'collapse': + case 'collapse': { node.data.hProperties.collapse = 'true'; break; + } } } }); diff --git a/packages/frontend/src/shared/remark/remark-iex.ts b/packages/frontend/src/shared/remark/remark-iex.ts index 593088d25..83a1a8fc5 100644 --- a/packages/frontend/src/shared/remark/remark-iex.ts +++ b/packages/frontend/src/shared/remark/remark-iex.ts @@ -30,12 +30,13 @@ export const remarkIex = (options) => { function textDirectives(node) { switch (node.name) { - case 'badge': + case 'badge': { node.data = { hName: 'badge', hProperties: node.attributes }; break; + } case 'image': { node.data = { @@ -74,11 +75,12 @@ export const remarkIex = (options) => { break; } - default: + default: { node.data = { hName: 'textdirective', hProperties: node }; + } } } @@ -108,11 +110,12 @@ export const remarkIex = (options) => { break; } - default: + default: { node.data = { hName: 'leafdirective', hProperties: node }; + } } } @@ -215,11 +218,12 @@ export const remarkIex = (options) => { break; } - default: + default: { node.data = { hName: 'containerdirective', hProperties: node }; + } } } diff --git a/packages/frontend/src/shared/search.ts b/packages/frontend/src/shared/search.ts index d15408ed7..f4fcaf518 100644 --- a/packages/frontend/src/shared/search.ts +++ b/packages/frontend/src/shared/search.ts @@ -28,28 +28,39 @@ import Parsimmon, { optWhitespace } from 'parsimmon'; */ function convertField(key: string): string { switch (key) { - case 'tag': + case 'tag': { return 'tags.keyword'; - case 'author': + } + case 'author': { return 'contributors.userName.keyword'; - case 'user': + } + case 'user': { return 'user.userName.keyword'; - case 'targetUser': + } + case 'targetUser': { return 'details.userName.keyword'; - case 'team': + } + case 'team': { return 'metadata.team.keyword'; - case 'createdDate': + } + case 'createdDate': { return 'createdAt'; - case 'updatedDate': + } + case 'updatedDate': { return 'updatedAt'; - case 'publishedDate': + } + case 'publishedDate': { return 'metadata.publishedDate'; - case 'itemType': + } + case 'itemType': { return 'itemType'; - case 'insight': + } + case 'insight': { return 'details.insightName.keyword'; - default: + } + default: { return key; + } } } @@ -60,16 +71,21 @@ function convertField(key: string): string { */ function convertOperation(operation: string): string { switch (operation) { - case '>': + case '>': { return 'gt'; - case '>=': + } + case '>=': { return 'gte'; - case '<': + } + case '<': { return 'lt'; - case '<=': + } + case '<=': { return 'lte'; - default: + } + default: { return operation; + } } } @@ -162,12 +178,15 @@ export class SearchTerm implements SearchClause { toString(): string { switch (this.key) { - case 'author': + case 'author': { return `@${this.value}`; - case 'tag': + } + case 'tag': { return `#${this.value}`; - default: + } + default: { return this.value.includes(' ') ? `${this.key}:"${this.value}"` : `${this.key}:${this.value}`; + } } } } diff --git a/packages/frontend/src/shared/useFetch.ts b/packages/frontend/src/shared/useFetch.ts index 732a3f1a9..f82da846e 100644 --- a/packages/frontend/src/shared/useFetch.ts +++ b/packages/frontend/src/shared/useFetch.ts @@ -62,12 +62,12 @@ export const useFetch = ({ url, contents, method = 'GET', paused = false }: Prop const response = await fetch(url, { method, signal }); const data = await response.text(); - if (!response.ok) { - setError(response.statusText); - setData(undefined); - } else { + if (response.ok) { setData(data); setError(undefined); + } else { + setError(response.statusText); + setData(undefined); } setFetching(false); } catch (error: any) { diff --git a/packages/frontend/src/shared/useLikedBy.ts b/packages/frontend/src/shared/useLikedBy.ts index a4d627ad8..4fcd80946 100644 --- a/packages/frontend/src/shared/useLikedBy.ts +++ b/packages/frontend/src/shared/useLikedBy.ts @@ -92,14 +92,18 @@ const NEWS_LIKED_BY_QUERY = gql` const selectQuery = (type: LikedByType): TypedDocumentNode => { switch (type) { - case 'insight': + case 'insight': { return INSIGHT_LIKED_BY_QUERY; - case 'comment': + } + case 'comment': { return COMMENT_LIKED_BY_QUERY; - case 'activity': + } + case 'activity': { return ACTIVITY_LIKED_BY_QUERY; - case 'news': + } + case 'news': { return NEWS_LIKED_BY_QUERY; + } } }; diff --git a/packages/frontend/src/shared/useUser.ts b/packages/frontend/src/shared/useUser.ts index 4fe9a506b..aef4a854d 100644 --- a/packages/frontend/src/shared/useUser.ts +++ b/packages/frontend/src/shared/useUser.ts @@ -160,10 +160,12 @@ const PROFILE_USER_QUERY = gql` const getQuery = (query: UserQuery) => { switch (query) { - case 'basic': + case 'basic': { return BASIC_USER_QUERY; - case 'profile': + } + case 'profile': { return PROFILE_USER_QUERY; + } } }; diff --git a/packages/frontend/src/store/activity.slice.ts b/packages/frontend/src/store/activity.slice.ts index 88e932615..abcab48a0 100644 --- a/packages/frontend/src/store/activity.slice.ts +++ b/packages/frontend/src/store/activity.slice.ts @@ -68,13 +68,15 @@ export const activitySlice = createSlice({ // Apply a specific direction for certain fields switch (action.payload) { - case 'name': + case 'name': { state.sort.direction = 'asc'; break; + } case 'relevance': - case 'occurredAt': + case 'occurredAt': { state.sort.direction = 'desc'; break; + } } }, setSortDirection(state, action: PayloadAction<'asc' | 'desc'>) { diff --git a/packages/frontend/src/store/search.slice.ts b/packages/frontend/src/store/search.slice.ts index e6ae44604..91bd9f04d 100644 --- a/packages/frontend/src/store/search.slice.ts +++ b/packages/frontend/src/store/search.slice.ts @@ -74,18 +74,20 @@ export const searchSlice = createSlice({ // Apply a specific direction for certain fields switch (action.payload) { - case 'name': + case 'name': { state.sort.direction = 'asc'; break; + } case 'relevance': case 'createdAt': case 'updatedAt': case 'publishedDate': case 'commentCount': case 'likeCount': - case 'viewCount': + case 'viewCount': { state.sort.direction = 'desc'; break; + } } }, setSortDirection(state, action: PayloadAction<'asc' | 'desc'>) { diff --git a/packages/shared/src/logger.ts b/packages/shared/src/logger.ts index ae33a56db..1d8f61335 100644 --- a/packages/shared/src/logger.ts +++ b/packages/shared/src/logger.ts @@ -35,9 +35,10 @@ export const initializeLogger = (): Logger => { }; switch (process.env.LOG_FORMAT) { - case 'json': + case 'json': { // Default break; + } case 'pretty': case 'default': { diff --git a/packages/shared/src/search.ts b/packages/shared/src/search.ts index e6df0a147..bcc2fe1e6 100644 --- a/packages/shared/src/search.ts +++ b/packages/shared/src/search.ts @@ -27,28 +27,39 @@ import Parsimmon, { optWhitespace } from 'parsimmon'; */ function convertField(key: string): string { switch (key) { - case 'tag': + case 'tag': { return 'tags.keyword'; - case 'author': + } + case 'author': { return 'contributors.userName.keyword'; - case 'user': + } + case 'user': { return 'user.userName.keyword'; - case 'targetUser': + } + case 'targetUser': { return 'details.userName.keyword'; - case 'team': + } + case 'team': { return 'metadata.team.keyword'; - case 'createdDate': + } + case 'createdDate': { return 'createdAt'; - case 'updatedDate': + } + case 'updatedDate': { return 'updatedAt'; - case 'publishedDate': + } + case 'publishedDate': { return 'metadata.publishedDate'; - case 'itemType': + } + case 'itemType': { return 'itemType'; - case 'insight': + } + case 'insight': { return 'details.insightName.keyword'; - default: + } + default: { return key; + } } } @@ -59,16 +70,21 @@ function convertField(key: string): string { */ function convertOperation(operation: string): string { switch (operation) { - case '>': + case '>': { return 'gt'; - case '>=': + } + case '>=': { return 'gte'; - case '<': + } + case '<': { return 'lt'; - case '<=': + } + case '<=': { return 'lte'; - default: + } + default: { return operation; + } } } @@ -198,12 +214,15 @@ export class SearchTerm implements SearchClause { toString(): string { switch (this.key) { - case 'author': + case 'author': { return this.value.includes(' ') ? `author:"${this.value}"` : `@${this.value}`; - case 'tag': + } + case 'tag': { return `#${this.value}`; - default: + } + default: { return this.value.includes(' ') ? `${this.key}:"${this.value}"` : `${this.key}:${this.value}`; + } } } } diff --git a/packages/shared/src/storage.ts b/packages/shared/src/storage.ts index 8e1a7ff90..29f8e7584 100644 --- a/packages/shared/src/storage.ts +++ b/packages/shared/src/storage.ts @@ -54,7 +54,7 @@ const defaultOptions: S3ClientConfig = { region: process.env.S3_REGION, maxAttempts: 4, - endpoint: process.env.S3_ENDPOINT !== '' ? process.env.S3_ENDPOINT : undefined, + endpoint: process.env.S3_ENDPOINT === '' ? undefined : process.env.S3_ENDPOINT, // S3 Path-style requests are deprecated // But some S3-compatible APIs may use them (e.g. Minio) @@ -122,7 +122,9 @@ export class Storage { const response = await this.s3Client.send(new PutObjectCommand({ Body: body, Bucket: bucket, Key: path })); this.logger.debug(`S3 file successfully uploaded with Etag: ${response.ETag} and URI: ${uri}`); - } else if (stream !== undefined) { + } else if (stream === undefined) { + throw new Error('Either body or stream options must be set.'); + } else { const uploadOptions: PutObjectCommandInput = { Body: stream, Bucket: bucket, Key: path }; if (fileSize !== undefined) { @@ -131,8 +133,6 @@ export class Storage { const response = await this.s3Client.send(new PutObjectCommand(uploadOptions)); this.logger.debug(`S3 file successfully streamed with Etag: ${response.ETag} and URI: ${uri}`); - } else { - throw new Error('Either body or stream options must be set.'); } return uri;