From 4166c97ba8a76f58a901456069f6ea1a4deee785 Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Sat, 17 Oct 2020 19:08:55 -0400 Subject: [PATCH] Linting / formatting and general clean-up of package. Still a lot left in the original implementation to clean up further --- package-lock.json | 302 +++++++++++++++++++++++- package.json | 9 +- src/builder/context.ts | 20 +- src/builder/entity-type.ts | 6 +- src/builder/index.ts | 35 +-- src/builder/intent.ts | 16 +- src/builder/message.ts | 2 +- src/builder/parts.ts | 3 +- src/builder/training-phrases.ts | 19 +- src/builder/types.ts | 21 ++ src/converter/cli.ts | 4 +- src/diff/diff.ts | 46 ++++ src/diff/fields.ts | 20 ++ src/diff/index.ts | 55 +---- src/diff/intent.ts | 35 +-- src/diff/types.ts | 6 + src/sample/index.ts | 19 +- src/services/agents.ts | 8 +- src/services/context.ts | 8 +- src/services/dialogflow.ts | 4 +- src/services/entity-type.ts | 12 +- src/services/intent.ts | 8 +- src/services/logger.ts | 14 +- src/services/mapping.ts | 2 +- src/sync/index.ts | 26 +- src/sync/stage.ts | 4 +- src/test-maker/common/dac-test-error.ts | 2 +- src/test-maker/common/logger.ts | 2 +- src/test-suite/cli.ts | 2 +- src/test-suite/common/dac-test-error.ts | 2 +- src/util/index.ts | 8 +- 31 files changed, 509 insertions(+), 211 deletions(-) create mode 100644 src/builder/types.ts create mode 100644 src/diff/diff.ts create mode 100644 src/diff/fields.ts create mode 100644 src/diff/types.ts diff --git a/package-lock.json b/package-lock.json index 42df114..7c0f031 100644 --- a/package-lock.json +++ b/package-lock.json @@ -483,6 +483,32 @@ "@types/yargs": "^13.0.0" } }, + "@nodelib/fs.scandir": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", + "integrity": "sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.3", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", + "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz", + "integrity": "sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.3", + "fastq": "^1.6.0" + } + }, "@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -772,6 +798,22 @@ "eslint-visitor-keys": "^1.0.0" } }, + "@typescript-eslint/scope-manager": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.4.1.tgz", + "integrity": "sha512-2oD/ZqD4Gj41UdFeWZxegH3cVEEH/Z6Bhr/XvwTtGv66737XkR4C9IqEkebCuqArqBJQSj4AgNHHiN1okzD/wQ==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.4.1", + "@typescript-eslint/visitor-keys": "4.4.1" + } + }, + "@typescript-eslint/types": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.4.1.tgz", + "integrity": "sha512-KNDfH2bCyax5db+KKIZT4rfA8rEk5N0EJ8P0T5AJjo5xrV26UAzaiqoJCxeaibqc0c/IvZxp7v2g3difn2Pn3w==", + "dev": true + }, "@typescript-eslint/typescript-estree": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.13.0.tgz", @@ -790,6 +832,24 @@ } } }, + "@typescript-eslint/visitor-keys": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.4.1.tgz", + "integrity": "sha512-H2JMWhLaJNeaylSnMSQFEhT/S/FsJbebQALmoJxMPMxLtlVAMy2uJP/Z543n9IizhjRayLSqoInehCeNW9rWcw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.4.1", + "eslint-visitor-keys": "^2.0.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true + } + } + }, "abab": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.3.tgz", @@ -964,6 +1024,12 @@ "integrity": "sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=", "dev": true }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, "array-unique": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", @@ -1776,6 +1842,23 @@ "integrity": "sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==", "dev": true }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + }, + "dependencies": { + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + } + } + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -1999,6 +2082,89 @@ "get-stdin": "^6.0.0" } }, + "eslint-plugin-jest": { + "version": "24.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.1.0.tgz", + "integrity": "sha512-827YJ+E8B9PvXu/0eiVSNFfxxndbKv+qE/3GSMhdorCaeaOehtqHGX2YDW9B85TEOre9n/zscledkFW/KbnyGg==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "^4.0.1" + }, + "dependencies": { + "@typescript-eslint/experimental-utils": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.4.1.tgz", + "integrity": "sha512-Nt4EVlb1mqExW9cWhpV6pd1a3DkUbX9DeyYsdoeziKOpIJ04S2KMVDO+SEidsXRH/XHDpbzXykKcMTLdTXH6cQ==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/scope-manager": "4.4.1", + "@typescript-eslint/types": "4.4.1", + "@typescript-eslint/typescript-estree": "4.4.1", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/typescript-estree": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.4.1.tgz", + "integrity": "sha512-wP/V7ScKzgSdtcY1a0pZYBoCxrCstLrgRQ2O9MmCUZDtmgxCO/TCqOTGRVwpP4/2hVfqMz/Vw1ZYrG8cVxvN3g==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.4.1", + "@typescript-eslint/visitor-keys": "4.4.1", + "debug": "^4.1.1", + "globby": "^11.0.1", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + } + }, + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, "eslint-plugin-prettier": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.3.tgz", @@ -2312,6 +2478,74 @@ "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", "dev": true }, + "fast-glob": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.4.tgz", + "integrity": "sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.0", + "merge2": "^1.3.0", + "micromatch": "^4.0.2", + "picomatch": "^2.2.1" + }, + "dependencies": { + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "micromatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.0.5" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -2329,6 +2563,15 @@ "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.2.tgz", "integrity": "sha512-5rQdinSsycpzvAoHga2EDn+LRX1d5xLFsuNG0Kg61JrAT/tASXcLL0nf/33v+sAxlQcfYmWbTURa1mmAf55jGw==" }, + "fastq": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.8.0.tgz", + "integrity": "sha512-SMIZoZdLh/fgofivvIkmknUXyPnvxRE3DhtZ5Me3Mrsk5gyPL42F0xr51TdRXskBxHfMp+07bcYzfsYEsSQA9Q==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, "fb-watchman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.1.tgz", @@ -2589,6 +2832,34 @@ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, + "globby": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.1.tgz", + "integrity": "sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.1.1", + "ignore": "^5.1.4", + "merge2": "^1.3.0", + "slash": "^3.0.0" + }, + "dependencies": { + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + } + } + }, "google-auth-library": { "version": "5.10.1", "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-5.10.1.tgz", @@ -4557,6 +4828,12 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -5108,6 +5385,12 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "picomatch": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", + "dev": true + }, "pify": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", @@ -5156,9 +5439,10 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", + "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", + "dev": true }, "prettier-linter-helpers": { "version": "1.0.0", @@ -5544,6 +5828,12 @@ "through2": "^3.0.1" } }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -5565,6 +5855,12 @@ "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==", "dev": true }, + "run-parallel": { + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", + "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", + "dev": true + }, "rxjs": { "version": "6.5.5", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.5.tgz", diff --git a/package.json b/package.json index cca53ef..d022a6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xc/dialogflow-as-code", - "version": "2.1.1", + "version": "3.0.0-beta1", "main": "dist/index.js", "scripts": { "convert": "TS_NODE_FILES=true ts-node src/converter/cli.ts", @@ -33,22 +33,24 @@ "devDependencies": { "@types/debug": "^4.1.4", "@types/dialogflow": "^0.9.4", + "@types/figlet": "^1.2.0", "@types/glob": "^7.1.1", "@types/jest": "^24.0.13", + "@types/joi": "^14.3.3", "@types/lodash": "^4.14.129", "@types/node": "^12.12.0", "@types/prettier": "^1.16.4", "@types/uuid": "^3.4.5", - "@types/figlet": "^1.2.0", - "@types/joi": "^14.3.3", "@typescript-eslint/eslint-plugin": "^1.7.0", "@typescript-eslint/parser": "^1.7.0", "eslint": "^5.16.0", "eslint-config-prettier": "^4.2.0", + "eslint-plugin-jest": "^24.1.0", "eslint-plugin-prettier": "^3.0.1", "jest": "^24.9.0", "jest-junit": "^6.4.0", "nodemon": "^1.19.0", + "prettier": "^2.1.2", "ts-jest": "^24.0.2", "ts-node": "^8.0.3", "typescript": "3.4.5" @@ -61,7 +63,6 @@ "googleapis": "^39.2.0", "joi": "^14.3.1", "lodash": "^4.17.11", - "prettier": "^1.16.4", "reflect-metadata": "^0.1.13", "typedi": "^0.8.0", "uuid": "^3.3.2" diff --git a/src/builder/context.ts b/src/builder/context.ts index 8df56d4..acf84a2 100644 --- a/src/builder/context.ts +++ b/src/builder/context.ts @@ -1,47 +1,47 @@ import { Context, Value } from "dialogflow"; -import { IBuilder } from "."; +import { IBuilder } from "./types"; export class ContextBuilder implements IBuilder { private _context: { [key: string]: any }; private _valid: number; - constructor() { + public constructor() { this._context = { parameters: {} }; this._valid = 0 | 1 | 2; } - build(): Context { + public build(): Context { if (!this.isContext(this._context)) { throw new Error("Context built unsuccessfully"); } return this._context; } - name(name: string): ContextBuilder { + public name(name: string): ContextBuilder { this._context.name = name; this._valid = this._valid | 4; return this; } - lifespan(count: number): ContextBuilder { + public lifespan(count: number): ContextBuilder { this._context.lifespanCount = count; this._valid = this._valid | 2; return this; } - parameter(field: string, param: Value): ContextBuilder { + public parameter(field: string, param: Value): ContextBuilder { this._context.parameters![field] = param; this._valid = this._valid | 1; return this; } // Short-hand - n(name: string): ContextBuilder { + public n(name: string): ContextBuilder { return this.name(name); } - lc(count: number): ContextBuilder { + public lc(count: number): ContextBuilder { return this.lifespan(count); } - p(field: string, param: Value): ContextBuilder { + public p(field: string, param: Value): ContextBuilder { return this.parameter(field, param); } - private isContext(obj: any): obj is Context { + private isContext(_obj: any): _obj is Context { return !(this._valid ^ 7); } } diff --git a/src/builder/entity-type.ts b/src/builder/entity-type.ts index e455064..dee8d83 100644 --- a/src/builder/entity-type.ts +++ b/src/builder/entity-type.ts @@ -5,7 +5,7 @@ import { EntityAutoExpansionMode, } from "dialogflow"; -import { IBuilder } from "."; +import { IBuilder } from "./types"; export const DEFAULT_ENTITY_TYPE = { displayName: "", @@ -34,7 +34,9 @@ export class EntityTypeBuilder implements IBuilder { } public entities(entities: (SynonymsBuilder | Entity)[]): EntityTypeBuilder { this._entityType.entities.push( - ...entities.map(et => (et instanceof SynonymsBuilder ? et.build() : et)), + ...entities.map((et) => + et instanceof SynonymsBuilder ? et.build() : et, + ), ); this._valid = this._valid | 8; return this; diff --git a/src/builder/index.ts b/src/builder/index.ts index 13f51b3..9739f0e 100644 --- a/src/builder/index.ts +++ b/src/builder/index.ts @@ -16,10 +16,10 @@ export class DialogflowBuilder { private _contexts: Context[] = []; public constructor() {} - // intents + public intents(bs: (IntentBuilder | Intent)[]): DialogflowBuilder { this._intents.push( - ...bs.map(b => { + ...bs.map((b) => { return b instanceof IntentBuilder ? b.build() : b; }), ); @@ -28,12 +28,12 @@ export class DialogflowBuilder { public its(bs: (IntentBuilder | Intent)[]): DialogflowBuilder { return this.intents(bs); } - // entity types + public entityTypes( bs: (EntityTypeBuilder | EntityType)[], ): DialogflowBuilder { this._entityTypes.push( - ...bs.map(b => { + ...bs.map((b) => { return b instanceof EntityTypeBuilder ? b.build() : b; }), ); @@ -42,10 +42,10 @@ export class DialogflowBuilder { public ets(bs: (EntityTypeBuilder | EntityType)[]): DialogflowBuilder { return this.entityTypes(bs); } - // contexts + public contexts(bs: (ContextBuilder | Context)[]): DialogflowBuilder { this._contexts.push( - ...bs.map(b => { + ...bs.map((b) => { return b instanceof ContextBuilder ? b.build() : b; }), ); @@ -54,6 +54,7 @@ export class DialogflowBuilder { public cxs(bs: (ContextBuilder | Context)[]): DialogflowBuilder { return this.contexts(bs); } + public build() { return { intents: this._intents, @@ -63,30 +64,8 @@ export class DialogflowBuilder { } } -export interface BuilderOptions { - entityTypes?: { - parameters?: { - mandatory?: boolean; - }; - }; - intents?: {}; - contexts?: {}; -} - export default DialogflowBuilder; -export interface Indexable { - [key: string]: any; -} - -export interface IBuilder { - build(): T; -} - -export function isBuilder(obj: any): obj is IBuilder { - return (obj as IBuilder).build !== undefined; -} - export * from "./defaults"; export * from "./entity-type"; export * from "./message"; diff --git a/src/builder/intent.ts b/src/builder/intent.ts index 446d390..df39bd5 100644 --- a/src/builder/intent.ts +++ b/src/builder/intent.ts @@ -1,7 +1,5 @@ import { Intent, Parameter, Message, Context } from "dialogflow"; -import _ from "lodash"; - -import { MessageBuilder } from "."; +import { MessageBuilder } from "./message"; import { ContextBuilder } from "./context"; import { TrainingPhraseBuilder } from "./training-phrases"; @@ -20,7 +18,7 @@ export class IntentBuilder { this._params = new Map(); } public build(): Intent { - this._params.forEach(p => { + this._params.forEach((p) => { this._intent.parameters!.push(p); }); return this._intent; @@ -55,9 +53,9 @@ export class IntentBuilder { bs: TrainingPhraseBuilder[], generateParams: boolean = true, ) { - bs.forEach(b => { + bs.forEach((b) => { if (generateParams) { - b.extractParameters().forEach(p => { + b.extractParameters().forEach((p) => { if (!this._params.has(p.displayName)) { this._params.set(p.displayName, p); } @@ -73,7 +71,7 @@ export class IntentBuilder { } public outputContexts(cxs: (Context | ContextBuilder)[]) { this._intent.outputContexts!.push( - ...cxs.map(cx => { + ...cxs.map((cx) => { return cx instanceof ContextBuilder ? cx.build() : cx; }), ); @@ -84,14 +82,14 @@ export class IntentBuilder { return this; } public parameters(ps: Parameter[]) { - ps.forEach(p => { + ps.forEach((p) => { this._params.set(p.displayName, p); }); return this; } public messages(ms: (Message | MessageBuilder)[]) { this._intent.messages!.push( - ...ms.map(m => { + ...ms.map((m) => { return m instanceof MessageBuilder ? m.build() : m; }), ); diff --git a/src/builder/message.ts b/src/builder/message.ts index b9df89f..c50988a 100644 --- a/src/builder/message.ts +++ b/src/builder/message.ts @@ -1,4 +1,4 @@ -import { IBuilder, Indexable } from "."; +import { IBuilder, Indexable } from "./types"; import { Message, Platform, diff --git a/src/builder/parts.ts b/src/builder/parts.ts index 89f55ee..bdca144 100644 --- a/src/builder/parts.ts +++ b/src/builder/parts.ts @@ -1,6 +1,7 @@ import { PartParamStruct } from "./defaults"; import { EntityType, Part, Parameter } from "dialogflow"; -import { IBuilder, retrieveText } from "."; +import { IBuilder } from "./types"; +import { retrieveText } from "./training-phrases"; export class PartBuilder implements IBuilder { private _part: Part[] = []; diff --git a/src/builder/training-phrases.ts b/src/builder/training-phrases.ts index ba19246..56533a7 100644 --- a/src/builder/training-phrases.ts +++ b/src/builder/training-phrases.ts @@ -1,14 +1,9 @@ -import { - IBuilder, - isBuilder, - PartParamStruct, - EntityTypeBuilder, - PartBuilder, -} from "."; - -import { TrainingPhrase, Parameter, Part, EntityType } from "dialogflow"; - +import { EntityType, Parameter, Part, TrainingPhrase } from "dialogflow"; import _ from "lodash"; +import { PartParamStruct } from "./defaults"; +import { EntityTypeBuilder } from "./entity-type"; +import { PartBuilder } from "./parts"; +import { IBuilder, isBuilder } from "./types"; export class TrainingPhraseBuilder implements IBuilder { private _trainingPhrase: TrainingPhrase; @@ -18,7 +13,7 @@ export class TrainingPhraseBuilder implements IBuilder { public constructor(phrases: TrainingPhraseInput[] = []) { const parts: (Part | Part[])[] = []; const newPhrases = fixSpacing(phrases); - newPhrases.forEach(phrase => { + newPhrases.forEach((phrase) => { if (typeof phrase === "string") { parts.push({ text: phrase }); } else { @@ -47,7 +42,7 @@ export class TrainingPhraseBuilder implements IBuilder { } private addToParams(...params: Parameter[]) { - params.forEach(param => { + params.forEach((param) => { if (!this._paramNames.has(param.displayName)) { this._paramNames.add(param.displayName); this._params.push(param); diff --git a/src/builder/types.ts b/src/builder/types.ts new file mode 100644 index 0000000..41b79d3 --- /dev/null +++ b/src/builder/types.ts @@ -0,0 +1,21 @@ +export interface BuilderOptions { + entityTypes?: { + parameters?: { + mandatory?: boolean; + }; + }; + intents?: {}; + contexts?: {}; +} + +export interface Indexable { + [key: string]: any; +} + +export interface IBuilder { + build(): T; +} + +export function isBuilder(obj: any): obj is IBuilder { + return (obj as IBuilder).build !== undefined; +} diff --git a/src/converter/cli.ts b/src/converter/cli.ts index dc46558..a5d24f9 100644 --- a/src/converter/cli.ts +++ b/src/converter/cli.ts @@ -33,10 +33,10 @@ function buildProgram() { const CLI = buildProgram(); -let outputDirectory: string = "./output"; +let outputDirectory = "./output"; if (CLI.output) outputDirectory = CLI.output; -let inputDirectory: string = "./input"; +let inputDirectory = "./input"; if (CLI.input) inputDirectory = CLI.input; main(inputDirectory, outputDirectory); diff --git a/src/diff/diff.ts b/src/diff/diff.ts new file mode 100644 index 0000000..e9c503f --- /dev/null +++ b/src/diff/diff.ts @@ -0,0 +1,46 @@ +import _ from "lodash"; +import Container from "typedi"; +import { LoggerService } from "../services/logger"; +import { Field, NestedDiff } from "./types"; + +export function nestedDiff( + newt: T, + oldt: T, + fields?: Field[], +): NestedDiff { + const diff: NestedDiff = {}; + const logger: LoggerService = Container.get(LoggerService); + logger.verbose(`New contains: ${JSON.stringify(newt)}`); + logger.verbose(`Old contains: ${JSON.stringify(oldt)}`); + + if (fields === undefined || fields.length === 0) { + const tmpFields = [ + ...new Set([ + ...(newt !== undefined ? Object.keys(newt) : []), + ...(oldt !== undefined ? Object.keys(oldt) : []), + ]), + ]; + logger.verbose(`Found the following fields: ${tmpFields}`); + fields = tmpFields.map((value) => ({ value })); + } + + if (fields.length === 0) { + logger.verbose(`No fields found, returning empty object`); + return {}; + } + + for (const field of fields) { + const newField = _.get(newt, field.value); + const oldField = _.get(oldt, field.value); + if (newField instanceof Object || oldField instanceof Object) { + _.set(diff, field.value, nestedDiff(newField, oldField, field.subfields)); + logger.verbose(`Recursively setting field: ${field.value}`); + } else if (!_.isEqual(newField, oldField)) { + _.set(diff, field.value, [newField, oldField]); + logger.verbose(`Setting field: ${field.value}`); + } else { + logger.verbose(`No diff found at field: ${field.value}`); + } + } + return diff; +} diff --git a/src/diff/fields.ts b/src/diff/fields.ts new file mode 100644 index 0000000..4ebabdd --- /dev/null +++ b/src/diff/fields.ts @@ -0,0 +1,20 @@ +import { Field } from "./types"; + +export const intentDiffFields: Field[] = [ + { value: "webhookState" }, + { value: "priority" }, + { value: "isFallback" }, + { value: "mlEnabled" }, + { + value: "trainingPhrases", + subfields: [ + { value: "name" }, + { + value: "parts", + subfields: [{ value: "text" }, { value: "entityType" }], + }, + ], + }, + { value: "inputContextNames" }, + { value: "events" }, +]; diff --git a/src/diff/index.ts b/src/diff/index.ts index 5e3223b..ae940a4 100644 --- a/src/diff/index.ts +++ b/src/diff/index.ts @@ -1,54 +1,3 @@ -import _ from "lodash"; -import Container from "typedi"; -import { LoggerService } from "../services/logger"; - -export function nestedDiff( - newt: T, - oldt: T, - fields?: Field[], -): NestedDiff { - const diff: NestedDiff = {}; - const logger: LoggerService = Container.get(LoggerService); - logger.verbose(`New contains: ${JSON.stringify(newt)}`); - logger.verbose(`Old contains: ${JSON.stringify(oldt)}`); - - if (fields === undefined || fields.length === 0) { - const tmpFields = [ - ...new Set([ - ...(newt !== undefined ? Object.keys(newt) : []), - ...(oldt !== undefined ? Object.keys(oldt) : []), - ]), - ]; - logger.verbose(`Found the following fields: ${tmpFields}`); - fields = tmpFields.map(value => ({ value })); - } - - if (fields.length === 0) { - logger.verbose(`No fields found, returning empty object`); - return {}; - } - - for (const field of fields) { - const newField = _.get(newt, field.value); - const oldField = _.get(oldt, field.value); - if (newField instanceof Object || oldField instanceof Object) { - _.set(diff, field.value, nestedDiff(newField, oldField, field.subfields)); - logger.verbose(`Recursively setting field: ${field.value}`); - } else if (!_.isEqual(newField, oldField)) { - _.set(diff, field.value, [newField, oldField]); - logger.verbose(`Setting field: ${field.value}`); - } else { - logger.verbose(`No diff found at field: ${field.value}`); - } - } - return diff; -} - -export type Diff = [Partial, Partial]; -export type NestedDiff = { [P in keyof T]?: [T[P], T[P]] }; -export interface Field { - value: string; - subfields?: Field[]; -} - +export * from "./diff"; export * from "./intent"; +export * from "./types"; diff --git a/src/diff/intent.ts b/src/diff/intent.ts index 230c492..6bb1510 100644 --- a/src/diff/intent.ts +++ b/src/diff/intent.ts @@ -1,8 +1,8 @@ import { Intent } from "dialogflow"; -import _ from "lodash"; import Container from "typedi"; import { LoggerService } from "../services/logger"; import { Field, NestedDiff, nestedDiff } from "."; +import { intentDiffFields } from "./fields"; export function diffIntents( newIntents: Intent[], @@ -11,20 +11,18 @@ export function diffIntents( ): NestedDiff[] { const logger: LoggerService = Container.get(LoggerService); logger.verbose( - `Started diffIntents: (New: ${newIntents.length}, Old: ${ - oldIntents.length - })`, + `Started diffIntents: (New: ${newIntents.length}, Old: ${oldIntents.length})`, ); logger.verbose( - `New intents display names: ${newIntents.map(i => i.displayName)}`, + `New intents display names: ${newIntents.map((i) => i.displayName)}`, ); logger.verbose( - `Old intents display names: ${oldIntents.map(i => i.displayName)}`, + `Old intents display names: ${oldIntents.map((i) => i.displayName)}`, ); const map: { [displayName: string]: { old?: Intent; new?: Intent } } = {}; - newIntents.forEach(intent => (map[intent.displayName] = { new: intent })); - oldIntents.forEach(intent => { + newIntents.forEach((intent) => (map[intent.displayName] = { new: intent })); + oldIntents.forEach((intent) => { if (map[intent.displayName] !== undefined) { logger.verbose(`Found key: ${intent.displayName}`); map[intent.displayName].old = intent; @@ -37,25 +35,6 @@ export function diffIntents( logger.verbose("Nested diff of found intents"); return Object.keys(map) - .map(name => nestedDiff(map[name].new!, map[name].old!, fields)) + .map((name) => nestedDiff(map[name].new!, map[name].old!, fields)) .filter((x: object) => Object.keys(x).length !== 0); } - -const intentDiffFields: Field[] = [ - { value: "webhookState" }, - { value: "priority" }, - { value: "isFallback" }, - { value: "mlEnabled" }, - { - value: "trainingPhrases", - subfields: [ - { value: "name" }, - { - value: "parts", - subfields: [{ value: "text" }, { value: "entityType" }], - }, - ], - }, - { value: "inputContextNames" }, - { value: "events" }, -]; diff --git a/src/diff/types.ts b/src/diff/types.ts new file mode 100644 index 0000000..2ae3eba --- /dev/null +++ b/src/diff/types.ts @@ -0,0 +1,6 @@ +export type Diff = [Partial, Partial]; +export type NestedDiff = { [P in keyof T]?: [T[P], T[P]] }; +export interface Field { + value: string; + subfields?: Field[]; +} diff --git a/src/sample/index.ts b/src/sample/index.ts index 7673470..5881e7c 100644 --- a/src/sample/index.ts +++ b/src/sample/index.ts @@ -1,18 +1,21 @@ import "reflect-metadata"; +import * as fs from "fs"; import Container from "typedi"; -import { KEY_FILENAME, DIALOGFLOW_CONFIG } from "../util"; -import { DialogflowServiceAccount } from "../config"; import { DialogflowBuilder } from "../builder"; -import { DialogflowCreator } from "../sync"; +import { DialogflowServiceAccount } from "../config"; import { IntentsService } from "../services"; -import { etSample, etFruit } from "./entities"; -import { ntFruitInfo, ntFruitReminder } from "./intents"; import { LoggerService, LogLevel } from "../services/logger"; +import { DialogflowCreator } from "../sync"; +import { DIALOGFLOW_CONFIG, KEY_FILENAME } from "../util"; +import { etFruit, etSample } from "./entities"; +import { ntFruitInfo, ntFruitReminder } from "./intents"; export async function sample(logLevel: LogLevel = 0) { - const svcAcctKeyJson: string = "service-account-key.json"; - const svcAcctConfig: DialogflowServiceAccount = require(`../../${svcAcctKeyJson}`); + const svcAcctKeyJson = "service-account-key.json"; + const svcAcctConfig: DialogflowServiceAccount = JSON.parse( + fs.readFileSync(`../../${svcAcctKeyJson}`, { encoding: "utf8" }), + ); Container.set(KEY_FILENAME, svcAcctKeyJson); Container.set(DIALOGFLOW_CONFIG, svcAcctConfig); @@ -32,7 +35,7 @@ export async function sample(logLevel: LogLevel = 0) { if (logger) { (await Container.get(IntentsService)) .getIntents() - .then(intents => + .then((intents) => logger.verbose(`Intents: ${JSON.stringify(intents, null, 2)}`), ); } diff --git a/src/services/agents.ts b/src/services/agents.ts index 86902e6..d00d9f5 100644 --- a/src/services/agents.ts +++ b/src/services/agents.ts @@ -7,16 +7,14 @@ class AgentsService { private agentsClients: AgentsClient; private projectId: string = ""; - constructor( - @Inject(KEY_FILENAME) keyFilename: string, - ) { + public constructor(@Inject(KEY_FILENAME) keyFilename: string) { this.agentsClients = new AgentsClient({ keyFilename: keyFilename }); - this.agentsClients.getProjectId().then(projectId => { + this.agentsClients.getProjectId().then((projectId) => { this.projectId = projectId; }); } - async getAgent(agentId: string = "") { + public async getAgent(agentId: string = "") { if (!agentId && !this.projectId) { return; } diff --git a/src/services/context.ts b/src/services/context.ts index 42b8881..7bde008 100644 --- a/src/services/context.ts +++ b/src/services/context.ts @@ -9,7 +9,7 @@ class ContextService { private sessionPath: string; // private contextPath: string; - constructor( + public constructor( @Inject(DIALOGFLOW_CONFIG) private svcAcctConfig: DialogflowServiceAccount, ) { this.contextsClient = new ContextsClient({ credentials: svcAcctConfig }); @@ -21,15 +21,15 @@ class ContextService { } // TODO: Implement contexts if necessary - async getContexts(): Promise { + public async getContexts(): Promise { return []; } - getSessionPath() { + public getSessionPath() { return this.sessionPath; } - setSessionPath(sessionName: string = "-") { + public setSessionPath(sessionName: string = "-") { this.sessionPath = this.contextsClient.sessionPath( this.svcAcctConfig.project_id, sessionName, diff --git a/src/services/dialogflow.ts b/src/services/dialogflow.ts index 6467291..f9da17b 100644 --- a/src/services/dialogflow.ts +++ b/src/services/dialogflow.ts @@ -7,9 +7,9 @@ class DialogflowService { @Inject(KEY_FILENAME) private keyFilename!: string; - constructor() {} + public constructor() {} - public getContextsClient(session: string, context: string): ContextsClient { + public getContextsClient(_session: string, _context: string): ContextsClient { return new ContextsClient({ keyFilename: this.keyFilename }); } diff --git a/src/services/entity-type.ts b/src/services/entity-type.ts index cd73e33..a634d8a 100644 --- a/src/services/entity-type.ts +++ b/src/services/entity-type.ts @@ -28,7 +28,7 @@ class EntityTypeService { private entityTypesClient: EntityTypesClient; private projectAgentPath: string; - constructor( + public constructor( @Inject(DIALOGFLOW_CONFIG) svcAcctConfig: DialogflowServiceAccount, @Inject(() => LoggerService) private logger: LoggerService, ) { @@ -53,16 +53,16 @@ class EntityTypeService { displayName: string, ): Promise { return this.getEntityTypes() - .then(entities => { + .then((entities) => { const matches = entities.filter( - entity => entity.displayName === displayName, + (entity) => entity.displayName === displayName, ); if (matches.length === 1) { return matches[0]; } return null; }) - .catch(err => { + .catch((err) => { throw err; }); } @@ -260,6 +260,8 @@ class EntityTypeService { } } -type EntityMap = { [displayName: string]: EntityType }; +interface EntityMap { + [displayName: string]: EntityType; +} export { EntityTypeService }; diff --git a/src/services/intent.ts b/src/services/intent.ts index 4a6308e..960ddc1 100644 --- a/src/services/intent.ts +++ b/src/services/intent.ts @@ -49,7 +49,7 @@ class IntentsService { } for (let intent of intents) { - this.logger.log(`Mapping ${intent.displayName} to ${intent.name}`) + this.logger.log(`Mapping ${intent.displayName} to ${intent.name}`); this.mapper.setName(intent.displayName, intent.name!); } @@ -76,8 +76,8 @@ class IntentsService { const name = this.mapper.getName(displayName); return name === null ? null - : this.getIntents().then(intents => { - const matches = intents.filter(x => x.displayName == displayName); + : this.getIntents().then((intents) => { + const matches = intents.filter((x) => x.displayName == displayName); if (matches.length === 1) { return matches[0]; } @@ -111,7 +111,7 @@ class IntentsService { if (name !== null) { return this.updateIntent({ ...intent, name }); } - return this.getIntentByDisplayName(displayName).then(existingIntent => { + return this.getIntentByDisplayName(displayName).then((existingIntent) => { if (existingIntent !== null) { return this.updateIntent({ ...intent, diff --git a/src/services/logger.ts b/src/services/logger.ts index 1508a76..1950a30 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -1,8 +1,14 @@ import { Service } from "typedi"; +export enum LogLevel { + SILENT, + NORMAL, + VERBOSE, +} + @Service() export class LoggerService { - constructor(private logLevel: LogLevel = LogLevel.SILENT) {} + public constructor(private logLevel: LogLevel = LogLevel.SILENT) {} public log(value: any) { if (this.logLevel >= LogLevel.NORMAL) { @@ -41,9 +47,3 @@ export class LoggerService { }; } } - -export enum LogLevel { - SILENT, - NORMAL, - VERBOSE, -} diff --git a/src/services/mapping.ts b/src/services/mapping.ts index be2cd03..c6c1a25 100644 --- a/src/services/mapping.ts +++ b/src/services/mapping.ts @@ -5,7 +5,7 @@ export class MappingService { private nameMap: { [displayName: string]: string } = {}; private inverseMap: { [name: string]: string } = {}; - constructor() {} + public constructor() {} public getName(displayName: string): string | null { if (displayName in this.nameMap) { diff --git a/src/sync/index.ts b/src/sync/index.ts index f67a3fb..6dc1712 100644 --- a/src/sync/index.ts +++ b/src/sync/index.ts @@ -79,7 +79,7 @@ export class DialogflowCreator { @ResourceStage("Parent Intent Creation") private async parentIntentCreate(inst: DialogflowInstructions) { const operations = _.chain(inst.intents.create) - .filter(i => i.parentFollowupIntentName === undefined) + .filter((i) => i.parentFollowupIntentName === undefined) .value(); if (operations.length === 0) { @@ -94,8 +94,8 @@ export class DialogflowCreator { await this.updateCache(); const operations = _.chain(inst.intents.create) - .filter(i => i.parentFollowupIntentName !== undefined) - .map(i => + .filter((i) => i.parentFollowupIntentName !== undefined) + .map((i) => this.mapFollowupParentNames(i, this.intentsService, this.mapper), ) .value(); @@ -110,7 +110,7 @@ export class DialogflowCreator { @ResourceStage("Parent Intent Update") private async parentIntentUpdate(inst: DialogflowInstructions) { const operations = _.chain(inst.intents.update) - .filter(i => i.parentFollowupIntentName === undefined) + .filter((i) => i.parentFollowupIntentName === undefined) .value(); if (operations.length === 0) { @@ -125,8 +125,8 @@ export class DialogflowCreator { await this.updateCache(); const operations = _.chain(inst.intents.update) - .filter(i => i.parentFollowupIntentName !== undefined) - .map(i => + .filter((i) => i.parentFollowupIntentName !== undefined) + .map((i) => this.mapFollowupParentNames(i, this.intentsService, this.mapper), ) .value(); @@ -146,7 +146,9 @@ export class DialogflowCreator { return; } - await this.intentsService.batchDeleteIntents(operations.map(i => i.name!)); + await this.intentsService.batchDeleteIntents( + operations.map((i) => i.name!), + ); } private async delayForTraining(inst: DialogflowInstructions) { @@ -161,7 +163,7 @@ export class DialogflowCreator { ms: number, message: string = "before deleting entity types...", ) { - return new Promise((res, rej) => { + return new Promise((res, _rej) => { this.logger.log(`Waiting ${ms}ms ${message}`); setTimeout(res, ms); }); @@ -170,7 +172,7 @@ export class DialogflowCreator { @ResourceStage("Entity Type Deletion") private async entityTypeDeletion(inst: DialogflowInstructions) { await this.entityTypesService.batchDeleteEntityTypes( - inst.entityTypes.delete.map(e => e.name!), + inst.entityTypes.delete.map((e) => e.name!), ); } @@ -201,13 +203,13 @@ export class DialogflowCreator { } private mapIntentsContexts(intents: Intent[]): Intent[] { - return intents.map(intent => { + return intents.map((intent) => { return { ...intent, - outputContexts: intent.outputContexts!.map(ctx => { + outputContexts: intent.outputContexts!.map((ctx) => { return { ...ctx, name: this.contextInPath(ctx.name!) }; }), - inputContextNames: intent.inputContextNames!.map(name => + inputContextNames: intent.inputContextNames!.map((name) => this.contextInPath(name), ), }; diff --git a/src/sync/stage.ts b/src/sync/stage.ts index a8d3653..dff1273 100644 --- a/src/sync/stage.ts +++ b/src/sync/stage.ts @@ -2,14 +2,14 @@ import Container from "typedi"; import { LoggerService } from "../services/logger"; export function ResourceStage(name: string) { - return function( + return function ( target: any, propertyKey: string, descriptor: PropertyDescriptor, ) { const logger: LoggerService = Container.get(LoggerService); const originalFunction = descriptor.value; - descriptor.value = async function(...args: any) { + descriptor.value = async function (...args: any) { logger.log(`Started phase: ${name}`); await originalFunction.apply(this, args); logger.log(`Successfully completed phase: ${name}`); diff --git a/src/test-maker/common/dac-test-error.ts b/src/test-maker/common/dac-test-error.ts index d8f61cf..4256ba2 100644 --- a/src/test-maker/common/dac-test-error.ts +++ b/src/test-maker/common/dac-test-error.ts @@ -1,7 +1,7 @@ import { StatusCode } from "./status-code"; export class DACTestError extends Error { public readonly code: StatusCode; - constructor(message: string, code: StatusCode) { + public constructor(message: string, code: StatusCode) { super(message); Object.setPrototypeOf(this, DACTestError.prototype); this.code = code; diff --git a/src/test-maker/common/logger.ts b/src/test-maker/common/logger.ts index 645e05c..e509576 100644 --- a/src/test-maker/common/logger.ts +++ b/src/test-maker/common/logger.ts @@ -6,7 +6,7 @@ export enum LogLevel { VERBOSE, } export class Logger { - constructor(private logLevel: LogLevel = LogLevel.NORMAL) {} + public constructor(private logLevel: LogLevel = LogLevel.NORMAL) {} public setLevel(logLevel: LogLevel): void { this.logLevel = logLevel; } diff --git a/src/test-suite/cli.ts b/src/test-suite/cli.ts index 77eb159..e2cdc0b 100644 --- a/src/test-suite/cli.ts +++ b/src/test-suite/cli.ts @@ -12,7 +12,7 @@ async function main(options: Options) { const runner = new TestRunner(options); const results: TestResults[] = await runner.runAllTests(options.tests); await Promise.all( - options.reporters.map(reporter => { + options.reporters.map((reporter) => { reporter.formatData(results); if (reporter.buildChart !== undefined) { reporter.buildChart(); diff --git a/src/test-suite/common/dac-test-error.ts b/src/test-suite/common/dac-test-error.ts index 8410dde..7df88a3 100644 --- a/src/test-suite/common/dac-test-error.ts +++ b/src/test-suite/common/dac-test-error.ts @@ -1,7 +1,7 @@ import { StatusCode } from "./status-code"; export class DACTestError extends Error { public readonly code: StatusCode; - constructor(message: string, code: StatusCode) { + public constructor(message: string, code: StatusCode) { super(message); Object.setPrototypeOf(this, DACTestError.prototype); this.code = code; diff --git a/src/util/index.ts b/src/util/index.ts index 7837ffb..534e7f9 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -2,7 +2,7 @@ import { EntityType } from "dialogflow"; import { LoggerService } from "../services/logger"; import Container from "typedi"; -export const intentNameRegex: RegExp = /^projects\/\w+-\w+\/agent\/intents\/w+$/; +export const intentNameRegex = /^projects\/\w+-\w+\/agent\/intents\/w+$/; export function toJson(err: Record) { return JSON.stringify(err, null, 2); @@ -18,14 +18,14 @@ export function entityLogger(entityType: EntityType) { export function processGrpc(p: Promise<[T]>, stage?: string): Promise { return p - .then(response => { + .then((response) => { if (response !== null && response.length > 0) { return response[0]; } throw new Error("Null value in gRPC response"); }) - .catch(err => { - (Container.get(LoggerService)).error( + .catch((err) => { + (Container.get(LoggerService) as LoggerService).error( `Error encountered: ${stage}`, ); throw err; -- 2.45.2