Compare commits

..

6 Commits

38 changed files with 987 additions and 66 deletions

3
.gitignore vendored
View File

@ -34,4 +34,5 @@ lerna-debug.log*
!.vscode/extensions.json
/config.yml
tsconfig.build.tsbuildinfo
tsconfig.build.tsbuildinfo
.eslintcache

1
.husky/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_

5
.husky/pre-commit Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
npm test

670
package-lock.json generated
View File

@ -24,6 +24,7 @@
"body-parser": "^1.19.0",
"class-transformer": "^0.3.2",
"class-validator": "^0.13.1",
"configuration": "file:../configuration",
"debug": "^4.3.1",
"graphql": "^15.5.0",
"graphql-tools": "^8.1.0",
@ -62,7 +63,9 @@
"eslint": "^7.12.1",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^7.0.2",
"jest": "^26.6.3",
"lint-staged": "^11.1.2",
"prettier": "^2.1.2",
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
@ -72,6 +75,24 @@
"typescript": "^4.0.5"
}
},
"../configuration": {
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"debug": "^4.3.2",
"etcd3": "^1.1.0",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.1",
"@types/debug": "^4.1.7",
"@types/js-yaml": "^4.0.3",
"@types/node": "^14.17.17",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.4"
}
},
"node_modules/@angular-devkit/core": {
"version": "11.2.6",
"resolved": "https://npm.ivanli.cc/@angular-devkit%2fcore/-/core-11.2.6.tgz",
@ -4281,8 +4302,8 @@
"version": "3.1.0",
"resolved": "https://npm.ivanli.cc/aggregate-error/-/aggregate-error-3.1.0.tgz",
"integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==",
"devOptional": true,
"license": "MIT",
"optional": true,
"dependencies": {
"clean-stack": "^2.0.0",
"indent-string": "^4.0.0"
@ -6071,8 +6092,8 @@
"version": "2.2.0",
"resolved": "https://npm.ivanli.cc/clean-stack/-/clean-stack-2.2.0.tgz",
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
"devOptional": true,
"license": "MIT",
"optional": true,
"engines": {
"node": ">=6"
}
@ -6252,6 +6273,63 @@
"node": ">=8.10.0"
}
},
"node_modules/cli-truncate": {
"version": "2.1.0",
"resolved": "https://npm.ivanli.cc/cli-truncate/-/cli-truncate-2.1.0.tgz",
"integrity": "sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==",
"dev": true,
"license": "MIT",
"dependencies": {
"slice-ansi": "^3.0.0",
"string-width": "^4.2.0"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/cli-truncate/node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/cli-truncate/node_modules/slice-ansi": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/slice-ansi/-/slice-ansi-3.0.0.tgz",
"integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
"astral-regex": "^2.0.0",
"is-fullwidth-code-point": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/cli-truncate/node_modules/string-width": {
"version": "4.2.2",
"resolved": "https://npm.ivanli.cc/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/cli-width": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/cli-width/-/cli-width-3.0.0.tgz",
@ -6417,9 +6495,9 @@
"license": "MIT"
},
"node_modules/colorette": {
"version": "1.2.2",
"resolved": "https://npm.ivanli.cc/colorette/-/colorette-1.2.2.tgz",
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
"version": "1.4.0",
"resolved": "https://npm.ivanli.cc/colorette/-/colorette-1.4.0.tgz",
"integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==",
"dev": true,
"license": "MIT"
},
@ -6521,6 +6599,10 @@
"safe-buffer": "~5.1.0"
}
},
"node_modules/configuration": {
"resolved": "../configuration",
"link": true
},
"node_modules/consola": {
"version": "2.15.3",
"resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz",
@ -8794,6 +8876,13 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-own-enumerable-property-symbols": {
"version": "3.0.2",
"resolved": "https://npm.ivanli.cc/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz",
"integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==",
"dev": true,
"license": "ISC"
},
"node_modules/get-package-type": {
"version": "0.1.0",
"resolved": "https://npm.ivanli.cc/get-package-type/-/get-package-type-0.1.0.tgz",
@ -9375,6 +9464,22 @@
"ms": "^2.0.0"
}
},
"node_modules/husky": {
"version": "7.0.2",
"resolved": "https://npm.ivanli.cc/husky/-/husky-7.0.2.tgz",
"integrity": "sha512-8yKEWNX4z2YsofXAMT7KvA1g8p+GxtB1ffV8XtpAEGuXNAbCV5wdNKH+qTpw8SM9fh4aMPDR+yQuKfgnreyZlg==",
"dev": true,
"license": "MIT",
"bin": {
"husky": "lib/bin.js"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/typicode"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://npm.ivanli.cc/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -9475,8 +9580,8 @@
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/indent-string/-/indent-string-4.0.0.tgz",
"integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==",
"devOptional": true,
"license": "MIT",
"optional": true,
"engines": {
"node": ">=8"
}
@ -9914,6 +10019,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-obj": {
"version": "1.0.1",
"resolved": "https://npm.ivanli.cc/is-obj/-/is-obj-1.0.1.tgz",
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-plain-object": {
"version": "2.0.4",
"resolved": "https://npm.ivanli.cc/is-plain-object/-/is-plain-object-2.0.4.tgz",
@ -9950,6 +10065,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-regexp": {
"version": "1.0.0",
"resolved": "https://npm.ivanli.cc/is-regexp/-/is-regexp-1.0.0.tgz",
"integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk=",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-set": {
"version": "2.0.2",
"resolved": "https://npm.ivanli.cc/is-set/-/is-set-2.0.2.tgz",
@ -11362,6 +11487,207 @@
"dev": true,
"license": "MIT"
},
"node_modules/lint-staged": {
"version": "11.1.2",
"resolved": "https://npm.ivanli.cc/lint-staged/-/lint-staged-11.1.2.tgz",
"integrity": "sha512-6lYpNoA9wGqkL6Hew/4n1H6lRqF3qCsujVT0Oq5Z4hiSAM7S6NksPJ3gnr7A7R52xCtiZMcEUNNQ6d6X5Bvh9w==",
"dev": true,
"license": "MIT",
"dependencies": {
"chalk": "^4.1.1",
"cli-truncate": "^2.1.0",
"commander": "^7.2.0",
"cosmiconfig": "^7.0.0",
"debug": "^4.3.1",
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"listr2": "^3.8.2",
"log-symbols": "^4.1.0",
"micromatch": "^4.0.4",
"normalize-path": "^3.0.0",
"please-upgrade-node": "^3.2.0",
"string-argv": "0.3.1",
"stringify-object": "^3.3.0"
},
"bin": {
"lint-staged": "bin/lint-staged.js"
},
"funding": {
"url": "https://opencollective.com/lint-staged"
}
},
"node_modules/lint-staged/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://npm.ivanli.cc/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/lint-staged/node_modules/commander": {
"version": "7.2.0",
"resolved": "https://npm.ivanli.cc/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 10"
}
},
"node_modules/lint-staged/node_modules/cosmiconfig": {
"version": "7.0.1",
"resolved": "https://npm.ivanli.cc/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
"integrity": "sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/parse-json": "^4.0.0",
"import-fresh": "^3.2.1",
"parse-json": "^5.0.0",
"path-type": "^4.0.0",
"yaml": "^1.10.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/lint-staged/node_modules/execa": {
"version": "5.1.1",
"resolved": "https://npm.ivanli.cc/execa/-/execa-5.1.1.tgz",
"integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==",
"dev": true,
"license": "MIT",
"dependencies": {
"cross-spawn": "^7.0.3",
"get-stream": "^6.0.0",
"human-signals": "^2.1.0",
"is-stream": "^2.0.0",
"merge-stream": "^2.0.0",
"npm-run-path": "^4.0.1",
"onetime": "^5.1.2",
"signal-exit": "^3.0.3",
"strip-final-newline": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sindresorhus/execa?sponsor=1"
}
},
"node_modules/lint-staged/node_modules/get-stream": {
"version": "6.0.1",
"resolved": "https://npm.ivanli.cc/get-stream/-/get-stream-6.0.1.tgz",
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/lint-staged/node_modules/human-signals": {
"version": "2.1.0",
"resolved": "https://npm.ivanli.cc/human-signals/-/human-signals-2.1.0.tgz",
"integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=10.17.0"
}
},
"node_modules/listr2": {
"version": "3.12.1",
"resolved": "https://npm.ivanli.cc/listr2/-/listr2-3.12.1.tgz",
"integrity": "sha512-oB1DlXlCzGPbvWhqYBZUQEPJKqsmebQWofXG6Mpbe3uIvoNl8mctBEojyF13ZyqwQ91clCWXpwsWp+t98K4FOQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"cli-truncate": "^2.1.0",
"colorette": "^1.4.0",
"log-update": "^4.0.0",
"p-map": "^4.0.0",
"rxjs": "^6.6.7",
"through": "^2.3.8",
"wrap-ansi": "^7.0.0"
},
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"enquirer": ">= 2.3.0 < 3"
}
},
"node_modules/listr2/node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/listr2/node_modules/p-map": {
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/p-map/-/p-map-4.0.0.tgz",
"integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"aggregate-error": "^3.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/listr2/node_modules/string-width": {
"version": "4.2.2",
"resolved": "https://npm.ivanli.cc/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/listr2/node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://npm.ivanli.cc/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/loader-runner": {
"version": "4.2.0",
"resolved": "https://npm.ivanli.cc/loader-runner/-/loader-runner-4.2.0.tgz",
@ -11532,6 +11858,25 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/log-update": {
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/log-update/-/log-update-4.0.0.tgz",
"integrity": "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-escapes": "^4.3.0",
"cli-cursor": "^3.1.0",
"slice-ansi": "^4.0.0",
"wrap-ansi": "^6.2.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/loglevel": {
"version": "1.7.1",
"resolved": "https://npm.ivanli.cc/loglevel/-/loglevel-1.7.1.tgz",
@ -13329,6 +13674,16 @@
"node": ">=8"
}
},
"node_modules/please-upgrade-node": {
"version": "3.2.0",
"resolved": "https://npm.ivanli.cc/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz",
"integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==",
"dev": true,
"license": "MIT",
"dependencies": {
"semver-compare": "^1.0.0"
}
},
"node_modules/pluralize": {
"version": "8.0.0",
"resolved": "https://npm.ivanli.cc/pluralize/-/pluralize-8.0.0.tgz",
@ -14723,6 +15078,13 @@
"node": ">=10"
}
},
"node_modules/semver-compare": {
"version": "1.0.0",
"resolved": "https://npm.ivanli.cc/semver-compare/-/semver-compare-1.0.0.tgz",
"integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=",
"dev": true,
"license": "MIT"
},
"node_modules/send": {
"version": "0.17.1",
"resolved": "https://npm.ivanli.cc/send/-/send-0.17.1.tgz",
@ -15602,6 +15964,16 @@
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"license": "MIT"
},
"node_modules/string-argv": {
"version": "0.3.1",
"resolved": "https://npm.ivanli.cc/string-argv/-/string-argv-0.3.1.tgz",
"integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.6.19"
}
},
"node_modules/string-length": {
"version": "4.0.2",
"resolved": "https://npm.ivanli.cc/string-length/-/string-length-4.0.2.tgz",
@ -15676,6 +16048,21 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/stringify-object": {
"version": "3.3.0",
"resolved": "https://npm.ivanli.cc/stringify-object/-/stringify-object-3.3.0.tgz",
"integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"get-own-enumerable-property-symbols": "^3.0.0",
"is-obj": "^1.0.1",
"is-regexp": "^1.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/strip-ansi": {
"version": "6.0.0",
"resolved": "https://npm.ivanli.cc/strip-ansi/-/strip-ansi-6.0.0.tgz",
@ -21149,7 +21536,7 @@
"version": "3.1.0",
"resolved": "https://npm.ivanli.cc/aggregate-error/-/aggregate-error-3.1.0.tgz",
"integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==",
"optional": true,
"devOptional": true,
"requires": {
"clean-stack": "^2.0.0",
"indent-string": "^4.0.0"
@ -22430,7 +22817,7 @@
"version": "2.2.0",
"resolved": "https://npm.ivanli.cc/clean-stack/-/clean-stack-2.2.0.tgz",
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
"optional": true
"devOptional": true
},
"cli-cursor": {
"version": "3.1.0",
@ -22549,6 +22936,46 @@
"chalk": "3.0.0"
}
},
"cli-truncate": {
"version": "2.1.0",
"resolved": "https://npm.ivanli.cc/cli-truncate/-/cli-truncate-2.1.0.tgz",
"integrity": "sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==",
"dev": true,
"requires": {
"slice-ansi": "^3.0.0",
"string-width": "^4.2.0"
},
"dependencies": {
"is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true
},
"slice-ansi": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/slice-ansi/-/slice-ansi-3.0.0.tgz",
"integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==",
"dev": true,
"requires": {
"ansi-styles": "^4.0.0",
"astral-regex": "^2.0.0",
"is-fullwidth-code-point": "^3.0.0"
}
},
"string-width": {
"version": "4.2.2",
"resolved": "https://npm.ivanli.cc/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"requires": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
}
}
}
},
"cli-width": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/cli-width/-/cli-width-3.0.0.tgz",
@ -22665,9 +23092,9 @@
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"colorette": {
"version": "1.2.2",
"resolved": "https://npm.ivanli.cc/colorette/-/colorette-1.2.2.tgz",
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
"version": "1.4.0",
"resolved": "https://npm.ivanli.cc/colorette/-/colorette-1.4.0.tgz",
"integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==",
"dev": true
},
"colors": {
@ -22748,6 +23175,21 @@
}
}
},
"configuration": {
"version": "file:../configuration",
"requires": {
"@tsconfig/node14": "^1.0.1",
"@types/debug": "^4.1.7",
"@types/js-yaml": "^4.0.3",
"@types/node": "^14.17.17",
"debug": "^4.3.2",
"etcd3": "^1.1.0",
"js-yaml": "^4.1.0",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.4"
}
},
"consola": {
"version": "2.15.3",
"resolved": "https://npm.ivanli.cc/consola/-/consola-2.15.3.tgz",
@ -24384,6 +24826,12 @@
"has-symbols": "^1.0.1"
}
},
"get-own-enumerable-property-symbols": {
"version": "3.0.2",
"resolved": "https://npm.ivanli.cc/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz",
"integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==",
"dev": true
},
"get-package-type": {
"version": "0.1.0",
"resolved": "https://npm.ivanli.cc/get-package-type/-/get-package-type-0.1.0.tgz",
@ -24793,6 +25241,12 @@
"ms": "^2.0.0"
}
},
"husky": {
"version": "7.0.2",
"resolved": "https://npm.ivanli.cc/husky/-/husky-7.0.2.tgz",
"integrity": "sha512-8yKEWNX4z2YsofXAMT7KvA1g8p+GxtB1ffV8XtpAEGuXNAbCV5wdNKH+qTpw8SM9fh4aMPDR+yQuKfgnreyZlg==",
"dev": true
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://npm.ivanli.cc/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -24850,7 +25304,7 @@
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/indent-string/-/indent-string-4.0.0.tgz",
"integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==",
"optional": true
"devOptional": true
},
"infer-owner": {
"version": "1.0.4",
@ -25132,6 +25586,12 @@
"resolved": "https://npm.ivanli.cc/is-number-object/-/is-number-object-1.0.5.tgz",
"integrity": "sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw=="
},
"is-obj": {
"version": "1.0.1",
"resolved": "https://npm.ivanli.cc/is-obj/-/is-obj-1.0.1.tgz",
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
"dev": true
},
"is-plain-object": {
"version": "2.0.4",
"resolved": "https://npm.ivanli.cc/is-plain-object/-/is-plain-object-2.0.4.tgz",
@ -25156,6 +25616,12 @@
"has-symbols": "^1.0.2"
}
},
"is-regexp": {
"version": "1.0.0",
"resolved": "https://npm.ivanli.cc/is-regexp/-/is-regexp-1.0.0.tgz",
"integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk=",
"dev": true
},
"is-set": {
"version": "2.0.2",
"resolved": "https://npm.ivanli.cc/is-set/-/is-set-2.0.2.tgz",
@ -26188,6 +26654,142 @@
"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=",
"dev": true
},
"lint-staged": {
"version": "11.1.2",
"resolved": "https://npm.ivanli.cc/lint-staged/-/lint-staged-11.1.2.tgz",
"integrity": "sha512-6lYpNoA9wGqkL6Hew/4n1H6lRqF3qCsujVT0Oq5Z4hiSAM7S6NksPJ3gnr7A7R52xCtiZMcEUNNQ6d6X5Bvh9w==",
"dev": true,
"requires": {
"chalk": "^4.1.1",
"cli-truncate": "^2.1.0",
"commander": "^7.2.0",
"cosmiconfig": "^7.0.0",
"debug": "^4.3.1",
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"listr2": "^3.8.2",
"log-symbols": "^4.1.0",
"micromatch": "^4.0.4",
"normalize-path": "^3.0.0",
"please-upgrade-node": "^3.2.0",
"string-argv": "0.3.1",
"stringify-object": "^3.3.0"
},
"dependencies": {
"chalk": {
"version": "4.1.2",
"resolved": "https://npm.ivanli.cc/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"commander": {
"version": "7.2.0",
"resolved": "https://npm.ivanli.cc/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
"dev": true
},
"cosmiconfig": {
"version": "7.0.1",
"resolved": "https://npm.ivanli.cc/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
"integrity": "sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==",
"dev": true,
"requires": {
"@types/parse-json": "^4.0.0",
"import-fresh": "^3.2.1",
"parse-json": "^5.0.0",
"path-type": "^4.0.0",
"yaml": "^1.10.0"
}
},
"execa": {
"version": "5.1.1",
"resolved": "https://npm.ivanli.cc/execa/-/execa-5.1.1.tgz",
"integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==",
"dev": true,
"requires": {
"cross-spawn": "^7.0.3",
"get-stream": "^6.0.0",
"human-signals": "^2.1.0",
"is-stream": "^2.0.0",
"merge-stream": "^2.0.0",
"npm-run-path": "^4.0.1",
"onetime": "^5.1.2",
"signal-exit": "^3.0.3",
"strip-final-newline": "^2.0.0"
}
},
"get-stream": {
"version": "6.0.1",
"resolved": "https://npm.ivanli.cc/get-stream/-/get-stream-6.0.1.tgz",
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
"dev": true
},
"human-signals": {
"version": "2.1.0",
"resolved": "https://npm.ivanli.cc/human-signals/-/human-signals-2.1.0.tgz",
"integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",
"dev": true
}
}
},
"listr2": {
"version": "3.12.1",
"resolved": "https://npm.ivanli.cc/listr2/-/listr2-3.12.1.tgz",
"integrity": "sha512-oB1DlXlCzGPbvWhqYBZUQEPJKqsmebQWofXG6Mpbe3uIvoNl8mctBEojyF13ZyqwQ91clCWXpwsWp+t98K4FOQ==",
"dev": true,
"requires": {
"cli-truncate": "^2.1.0",
"colorette": "^1.4.0",
"log-update": "^4.0.0",
"p-map": "^4.0.0",
"rxjs": "^6.6.7",
"through": "^2.3.8",
"wrap-ansi": "^7.0.0"
},
"dependencies": {
"is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://npm.ivanli.cc/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true
},
"p-map": {
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/p-map/-/p-map-4.0.0.tgz",
"integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
"dev": true,
"requires": {
"aggregate-error": "^3.0.0"
}
},
"string-width": {
"version": "4.2.2",
"resolved": "https://npm.ivanli.cc/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"requires": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
}
},
"wrap-ansi": {
"version": "7.0.0",
"resolved": "https://npm.ivanli.cc/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"dev": true,
"requires": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
}
}
}
},
"loader-runner": {
"version": "4.2.0",
"resolved": "https://npm.ivanli.cc/loader-runner/-/loader-runner-4.2.0.tgz",
@ -26316,6 +26918,18 @@
}
}
},
"log-update": {
"version": "4.0.0",
"resolved": "https://npm.ivanli.cc/log-update/-/log-update-4.0.0.tgz",
"integrity": "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==",
"dev": true,
"requires": {
"ansi-escapes": "^4.3.0",
"cli-cursor": "^3.1.0",
"slice-ansi": "^4.0.0",
"wrap-ansi": "^6.2.0"
}
},
"loglevel": {
"version": "1.7.1",
"resolved": "https://npm.ivanli.cc/loglevel/-/loglevel-1.7.1.tgz",
@ -27594,6 +28208,15 @@
"find-up": "^4.0.0"
}
},
"please-upgrade-node": {
"version": "3.2.0",
"resolved": "https://npm.ivanli.cc/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz",
"integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==",
"dev": true,
"requires": {
"semver-compare": "^1.0.0"
}
},
"pluralize": {
"version": "8.0.0",
"resolved": "https://npm.ivanli.cc/pluralize/-/pluralize-8.0.0.tgz",
@ -28578,6 +29201,12 @@
"lru-cache": "^6.0.0"
}
},
"semver-compare": {
"version": "1.0.0",
"resolved": "https://npm.ivanli.cc/semver-compare/-/semver-compare-1.0.0.tgz",
"integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=",
"dev": true
},
"send": {
"version": "0.17.1",
"resolved": "https://npm.ivanli.cc/send/-/send-0.17.1.tgz",
@ -29254,6 +29883,12 @@
"resolved": "https://npm.ivanli.cc/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"string-argv": {
"version": "0.3.1",
"resolved": "https://npm.ivanli.cc/string-argv/-/string-argv-0.3.1.tgz",
"integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==",
"dev": true
},
"string-length": {
"version": "4.0.2",
"resolved": "https://npm.ivanli.cc/string-length/-/string-length-4.0.2.tgz",
@ -29306,6 +29941,17 @@
"define-properties": "^1.1.3"
}
},
"stringify-object": {
"version": "3.3.0",
"resolved": "https://npm.ivanli.cc/stringify-object/-/stringify-object-3.3.0.tgz",
"integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==",
"dev": true,
"requires": {
"get-own-enumerable-property-symbols": "^3.0.0",
"is-obj": "^1.0.1",
"is-regexp": "^1.0.0"
}
},
"strip-ansi": {
"version": "6.0.0",
"resolved": "https://npm.ivanli.cc/strip-ansi/-/strip-ansi-6.0.0.tgz",

View File

@ -18,7 +18,8 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"prepare": "husky install"
},
"dependencies": {
"@golevelup/nestjs-rabbitmq": "^1.16.1",
@ -36,6 +37,7 @@
"body-parser": "^1.19.0",
"class-transformer": "^0.3.2",
"class-validator": "^0.13.1",
"configuration": "file:../configuration",
"debug": "^4.3.1",
"graphql": "^15.5.0",
"graphql-tools": "^8.1.0",
@ -74,7 +76,9 @@
"eslint": "^7.12.1",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^7.0.2",
"jest": "^26.6.3",
"lint-staged": "^11.1.2",
"prettier": "^2.1.2",
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
@ -102,5 +106,8 @@
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"lint-staged": {
"{src,apps,libs,test}/**/*.ts": "eslint --cache --fix"
}
}

View File

@ -20,6 +20,7 @@ import { LoggerModule } from 'nestjs-pino';
import { EtcdModule } from 'nestjs-etcd';
import pinoPretty from 'pino-pretty';
import { fromPairs, map, pipe, toPairs } from 'ramda';
import { ConfigurationsModule } from './configurations/configurations.module';
@Module({
imports: [
@ -64,7 +65,7 @@ import { fromPairs, map, pipe, toPairs } from 'ramda';
playground: true,
autoSchemaFile: true,
installSubscriptionHandlers: true,
context: ({ req, connection, ...args }) => {
context: ({ req, connection }) => {
return connection ? { req: connection.context } : { req };
},
subscriptions: {
@ -106,6 +107,7 @@ import { fromPairs, map, pipe, toPairs } from 'ramda';
}),
WebhooksModule,
CommonsModule,
ConfigurationsModule,
],
controllers: [AppController],
providers: [AppService, AppResolver],

View File

@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { Global, Module } from '@nestjs/common';
import { PasswordConverter } from './services/password-converter';
import { RedisMutexModule } from './redis-mutex/redis-mutex.module';
import { AuthModule } from '@nestjs-lib/auth';
@Global()
@Module({
imports: [RedisMutexModule, AuthModule],
providers: [PasswordConverter],

View File

@ -13,9 +13,9 @@ export class ApplicationException extends Error {
this.error = message.error;
this.message = message.message as any;
} else if (typeof message === 'string') {
super((message as unknown) as any);
super(message as unknown as any);
} else {
super((message as unknown) as any);
super(message as unknown as any);
}
}

View File

@ -19,12 +19,16 @@ export class HttpExceptionFilter implements ExceptionFilter {
case 'graphql': {
const errorName = exception.message;
const extensions: Record<string, any> = {};
const err = exception.getResponse();
const err = exception.getResponse() as any;
if (typeof err === 'string') {
extensions.message = err;
} else {
Object.assign(extensions, (err as any).extension);
extensions.message = (err as any).message;
Object.assign(extensions, err.extension);
if (typeof err.message === 'string') {
extensions.message = err.message;
} else {
extensions.message = err.error;
}
}
extensions.error = errorName;
this.logger.error(extensions);

View File

@ -126,6 +126,7 @@ export class BaseDbService<Entity extends AppBaseEntity> extends TypeormHelper {
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async canYouRemoveWithIds(ids: string[]): Promise<void> {
return;
}

View File

@ -0,0 +1,11 @@
import { Configuration } from './entities/configuration.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import { ConfigurationsService } from './configurations.service';
import { ConfigurationsResolver } from './configurations.resolver';
@Module({
imports: [TypeOrmModule.forFeature([Configuration])],
providers: [ConfigurationsResolver, ConfigurationsService],
})
export class ConfigurationsModule {}

View File

@ -0,0 +1,30 @@
import { JwtService } from '@nestjs-lib/auth';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationsResolver } from './configurations.resolver';
import { ConfigurationsService } from './configurations.service';
describe('ConfigurationsResolver', () => {
let resolver: ConfigurationsResolver;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ConfigurationsResolver,
{
provide: ConfigurationsService,
useValue: {},
},
{
provide: JwtService,
useValue: {},
},
],
}).compile();
resolver = module.get<ConfigurationsResolver>(ConfigurationsResolver);
});
it('should be defined', () => {
expect(resolver).toBeDefined();
});
});

View File

@ -0,0 +1,39 @@
import { UnprocessableEntityException } from '@nestjs/common';
import { GetConfigurationArgs } from './dto/get-configuration.args';
import { SetConfigurationInput } from './dto/set-configuration.input';
import { Resolver, Mutation, Args, Query } from '@nestjs/graphql';
import { ConfigurationsService } from './configurations.service';
import { Configuration } from './entities/configuration.entity';
import { any, pipe, values } from 'ramda';
import { AccountRole, Roles } from '@nestjs-lib/auth';
@Roles(AccountRole.admin, AccountRole.super)
@Resolver(() => Configuration)
export class ConfigurationsResolver {
constructor(private readonly configurationsService: ConfigurationsService) {}
@Mutation(() => Configuration)
setConfiguration(
@Args('setConfigurationInput', { type: () => SetConfigurationInput })
setConfigurationInput: SetConfigurationInput,
) {
return this.configurationsService.setConfiguration(setConfigurationInput);
}
@Query(() => Configuration, { nullable: true })
getConfiguration(
@Args()
getConfigurationArgs: GetConfigurationArgs,
) {
if (
pipe(
values,
any((value) => !value),
)(getConfigurationArgs)
) {
throw new UnprocessableEntityException('Must pass a parameter');
}
return this.configurationsService.findOneByConditions(getConfigurationArgs);
}
}

View File

@ -0,0 +1,49 @@
import { getRepositoryToken } from '@nestjs/typeorm';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationsService } from './configurations.service';
import { Configuration } from './entities/configuration.entity';
import { IsNull } from 'typeorm';
import { Etcd3 } from 'etcd3';
describe('ConfigurationsService', () => {
let service: ConfigurationsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ConfigurationsService,
{
provide: getRepositoryToken(Configuration),
useValue: {},
},
{
provide: Etcd3,
useValue: {},
},
],
}).compile();
service = module.get<ConfigurationsService>(ConfigurationsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('findOneByConditions', () => {
it('should select by projectId only', async () => {
const entity = new Configuration();
const findOne = jest.fn<any, [any]>(() => Promise.resolve(entity));
service['repository'].findOne = findOne;
await expect(
service.findOneByConditions({ projectId: 'uuid' }),
).resolves.toEqual(entity);
expect(findOne.mock.calls[0][0]).toMatchObject({
projectId: 'uuid',
pipelineId: IsNull(),
});
});
});
});

View File

@ -0,0 +1,55 @@
import { GetConfigurationArgs } from './dto/get-configuration.args';
import { BaseDbService } from './../commons/services/base-db.service';
import { Injectable } from '@nestjs/common';
import { Configuration } from './entities/configuration.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { FindConditions, IsNull, Repository } from 'typeorm';
import { SetConfigurationInput } from './dto/set-configuration.input';
import { pick } from 'ramda';
import { Etcd3 } from 'etcd3';
@Injectable()
export class ConfigurationsService extends BaseDbService<Configuration> {
constructor(
@InjectRepository(Configuration)
configurationRepository: Repository<Configuration>,
private readonly etcd: Etcd3,
) {
super(configurationRepository);
}
async setConfiguration(dto: SetConfigurationInput) {
let entity = await this.repository.findOne(
pick(['pipelineId', 'projectId'], dto),
);
if (!entity) {
entity = this.repository.create(dto);
}
entity = await this.repository.save(entity);
await this.syncToEtcd(entity);
return entity;
}
async findOneByConditions(dto: FindConditions<GetConfigurationArgs>) {
if (dto.projectId && !dto.pipelineId) {
dto.pipelineId = IsNull();
}
return await this.repository.findOne(dto);
}
async syncToEtcd({ pipelineId, id }: { pipelineId?: string; id?: string }) {
const config = await this.repository.findOneOrFail({
where: { pipelineId, id },
relations: ['pipeline', 'project'],
});
await this.etcd
.put(`share/config/${config.id}`)
.value(config.content)
.exec();
await this.etcd
.put(`share/config/${config.pipeline.environment}/${config.project.name}`)
.value(config.content)
.exec();
}
}

View File

@ -0,0 +1,17 @@
import { ArgsType } from '@nestjs/graphql';
import { IsUUID, IsOptional } from 'class-validator';
@ArgsType()
export class GetConfigurationArgs {
@IsUUID()
@IsOptional()
pipelineId?: string;
@IsUUID()
@IsOptional()
projectId?: string;
@IsUUID()
@IsOptional()
id?: string;
}

View File

@ -0,0 +1,26 @@
import { ConfigurationLanguage } from './../enums/configuration-language.enum';
import { IsEnum, IsString, IsUUID, Length, IsOptional } from 'class-validator';
import { InputType } from '@nestjs/graphql';
@InputType()
export class SetConfigurationInput {
@IsOptional()
@IsUUID()
id?: string;
@IsUUID()
pipelineId: string;
@IsUUID()
projectId: string;
@IsString()
content: string;
@IsEnum(ConfigurationLanguage)
language: ConfigurationLanguage;
@Length(0, 100)
@IsOptional()
name = 'Default Configuration';
}

View File

@ -0,0 +1,35 @@
import { Project } from './../../projects/project.entity';
import { ConfigurationLanguage } from './../enums/configuration-language.enum';
import { Pipeline } from './../../pipelines/pipeline.entity';
import { AppBaseEntity } from './../../commons/entities/app-base-entity';
import { ObjectType } from '@nestjs/graphql';
import { Column, Entity, ManyToOne } from 'typeorm';
@Entity()
@ObjectType()
export class Configuration extends AppBaseEntity {
@ManyToOne(() => Pipeline)
pipeline: Pipeline;
@Column({ unique: true, nullable: true })
pipelineId: string;
@ManyToOne(() => Project)
project: Project;
@Column()
projectId: string;
@Column({ comment: 'language defined in type field.' })
content: string;
@Column({ comment: '配置名称' })
name: string;
@Column({
type: 'enum',
enum: ConfigurationLanguage,
comment: 'configuration content language',
})
language: ConfigurationLanguage;
}

View File

@ -0,0 +1,10 @@
import { registerEnumType } from '@nestjs/graphql';
export enum ConfigurationLanguage {
JavaScript = 'JavaScript',
YAML = 'YAML',
}
registerEnumType(ConfigurationLanguage, {
name: 'ConfigurationLanguage',
});

View File

@ -5,6 +5,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './commons/filters/all.exception-filter';
import { SanitizePipe } from './commons/pipes/sanitize.pipe';
import { ServiceRegister } from 'configuration';
async function bootstrap() {
const app = await NestFactory.create(AppModule, { bodyParser: false });
@ -17,6 +18,10 @@ async function bootstrap() {
);
const httpExceptionFilterLogger = await app.resolve(PinoLogger);
app.useGlobalFilters(new HttpExceptionFilter(httpExceptionFilterLogger));
await app.listen(configService.get<number>('http.port'));
const server = await app.listen(configService.get<number>('http.port', 0));
const port = server.address().port;
const register = new ServiceRegister({ etcd: { hosts: 'http://rpi:2379' } });
register.register('fennec/api', `http://localhost:${port}`);
register.register('api.fennec', `http://localhost:${port}`);
}
bootstrap();

View File

@ -1,4 +1,4 @@
import { Field, InputType } from '@nestjs/graphql';
import { InputType } from '@nestjs/graphql';
import { PipelineUnits } from '../enums/pipeline-units.enum';
@InputType()

View File

@ -1,6 +1,6 @@
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { IsInstance, isInstance, ValidateNested } from 'class-validator';
import { IsInstance, ValidateNested } from 'class-validator';
import { WorkUnit } from './work-unit.model';
@InputType('WorkUnitMetadataInput')

View File

@ -16,12 +16,10 @@ import {
} from './pipeline-tasks.constants';
import { PipelineTaskLogger } from './pipeline-task.logger';
import { PipelineTaskFlushService } from './pipeline-task-flush.service';
import { CommonsModule } from '../commons/commons.module';
import { DeployByPm2Service } from './runners/deploy-by-pm2/deploy-by-pm2.service';
@Module({
imports: [
CommonsModule,
TypeOrmModule.forFeature([PipelineTask, Pipeline]),
RedisModule,
ReposModule,

View File

@ -35,15 +35,6 @@ export class PipelineTasksResolver {
);
}
@Subscription(() => PipelineTask, {
resolve: (value) => {
return value;
},
})
async pipelineTaskChanged(@Args('id') id: string) {
// return await this.service.watchTaskUpdated(id);
}
@Query(() => [PipelineTask])
async listPipelineTaskByPipelineId(@Args('pipelineId') pipelineId: string) {
return await this.service.listTasksByPipelineId(pipelineId);

View File

@ -12,7 +12,6 @@ describe('PipelineTasksService', () => {
let service: PipelineTasksService;
let module: TestingModule;
let taskRepository: Repository<PipelineTask>;
let pipelineRepository: Repository<Pipeline>;
beforeEach(async () => {
module = await Test.createTestingModule({
@ -43,7 +42,6 @@ describe('PipelineTasksService', () => {
service = module.get<PipelineTasksService>(PipelineTasksService);
taskRepository = module.get(getRepositoryToken(PipelineTask));
pipelineRepository = module.get(getRepositoryToken(Pipeline));
jest
.spyOn(taskRepository, 'save')
.mockImplementation(async (data: any) => data);

View File

@ -4,7 +4,6 @@ import { PipelineTask } from './pipeline-task.entity';
import { Repository } from 'typeorm';
import { CreatePipelineTaskInput } from './dtos/create-pipeline-task.input';
import { Pipeline } from '../pipelines/pipeline.entity';
import debug from 'debug';
import { AmqpConnection, RabbitRPC } from '@golevelup/nestjs-rabbitmq';
import {
EXCHANGE_PIPELINE_TASK_TOPIC,
@ -19,8 +18,6 @@ import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
import { ROUTE_PIPELINE_TASK_KILL } from './pipeline-tasks.constants';
const log = debug('fennec:pipeline-tasks:service');
@Injectable()
export class PipelineTasksService {
constructor(

View File

@ -28,4 +28,8 @@ export class CreatePipelineInput {
@ValidateNested()
@IsInstance(WorkUnitMetadata)
workUnitMetadata: WorkUnitMetadata;
@IsString()
@MaxLength(100)
environment: string;
}

View File

@ -12,7 +12,7 @@ export class Pipeline extends AppBaseEntity {
@Column()
projectId: string;
@Column({ comment: 'eg: remotes/origin/master' })
@Column({ comment: 'E.g., remotes/origin/master' })
branch: string;
@Column()
@ -20,4 +20,7 @@ export class Pipeline extends AppBaseEntity {
@Column({ type: 'jsonb' })
workUnitMetadata: WorkUnitMetadata;
@Column()
environment: string;
}

View File

@ -5,14 +5,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { Pipeline } from './pipeline.entity';
import { CommitLogsResolver } from './commit-logs.resolver';
import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
import { ReposModule } from '../repos/repos.module';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { CommonsModule } from '../commons/commons.module';
@Module({
imports: [
CommonsModule,
TypeOrmModule.forFeature([Pipeline]),
PipelineTasksModule,
RabbitMQModule.forRootAsync(RabbitMQModule, {

View File

@ -2,13 +2,11 @@ import { Test, TestingModule } from '@nestjs/testing';
import { PipelinesService } from './pipelines.service';
import { Pipeline } from './pipeline.entity';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from '../projects/project.entity';
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
describe('PipelinesService', () => {
let service: PipelinesService;
let repository: Repository<Pipeline>;
let pipeline: Pipeline;
beforeEach(async () => {
@ -40,7 +38,6 @@ describe('PipelinesService', () => {
}).compile();
service = module.get<PipelinesService>(PipelinesService);
repository = module.get(getRepositoryToken(Pipeline));
});
it('should be defined', () => {

View File

@ -19,7 +19,9 @@ import { plainToClass } from 'class-transformer';
@Injectable()
export class PipelinesService extends BaseDbService<Pipeline> {
readonly uniqueFields: Array<Array<keyof Pipeline>> = [['projectId', 'name']];
readonly uniqueFields: Array<Array<keyof Pipeline>> = [
['projectId', 'name', 'environment'],
];
constructor(
@InjectRepository(Pipeline)
readonly repository: Repository<Pipeline>,

View File

@ -1,5 +1,5 @@
import { ObjectType } from '@nestjs/graphql';
import { Entity, Column, DeleteDateColumn } from 'typeorm';
import { Entity, Column } from 'typeorm';
import { AppBaseEntity } from '../commons/entities/app-base-entity';
@ObjectType()

View File

@ -6,11 +6,9 @@ import { Project } from './project.entity';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { EXCHANGE_PROJECT_FANOUT } from './projects.constants';
import { CommonsModule } from '../commons/commons.module';
@Module({
imports: [
CommonsModule,
TypeOrmModule.forFeature([Project]),
RabbitMQModule.forRootAsync(RabbitMQModule, {
imports: [ConfigModule],

View File

@ -1,10 +1,5 @@
import { ObjectType, Field } from '@nestjs/graphql';
import {
LogResult,
DefaultLogFields,
BranchSummary,
BranchSummaryBranch,
} from 'simple-git';
import { BranchSummaryBranch } from 'simple-git';
@ObjectType()
export class Branch implements BranchSummaryBranch {

View File

@ -7,14 +7,12 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { ProjectsModule } from '../projects/projects.module';
import { EXCHANGE_REPO } from './repos.constants';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { CommonsModule } from '../commons/commons.module';
@Module({
imports: [
TypeOrmModule.forFeature([Project]),
ConfigModule,
ProjectsModule,
CommonsModule,
RabbitMQModule.forRootAsync(RabbitMQModule, {
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({

View File

@ -161,7 +161,7 @@ describe('ReposService', () => {
const project = new Project();
const pipeline = new Pipeline();
pipeline.branch = 'test';
const fetch = jest.fn((_: any) => Promise.resolve());
const fetch = jest.fn<any, [any]>(() => Promise.resolve());
pipeline.project = project;
const getGit = jest.spyOn(service, 'getGit').mockImplementation(() =>
Promise.resolve({
@ -182,7 +182,7 @@ describe('ReposService', () => {
const project = new Project();
const pipeline = new Pipeline();
pipeline.branch = 'test';
const fetch = jest.fn((_: any) => Promise.resolve());
const fetch = jest.fn<any, [any]>(() => Promise.resolve());
pipeline.project = project;
const getGit = jest
.spyOn(service, 'getGit')
@ -196,7 +196,7 @@ describe('ReposService', () => {
const project = new Project();
const pipeline = new Pipeline();
pipeline.branch = 'test';
const fetch = jest.fn((_: any) => Promise.reject('error'));
const fetch = jest.fn<any, [any]>(() => Promise.reject('error'));
pipeline.project = project;
const getGit = jest.spyOn(service, 'getGit').mockImplementation(() =>
Promise.resolve({

View File

@ -1,4 +1,4 @@
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
import { GiteaWebhooksController } from './gitea-webhooks.controller';
@ -10,5 +10,4 @@ import { WebhooksService } from './webhooks.service';
controllers: [GiteaWebhooksController],
providers: [WebhooksService],
})
export class WebhooksModule {
}
export class WebhooksModule {}

View File

@ -10,7 +10,6 @@
"lib": ["ES2021"],
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": "./",
},
}