diff --git a/README.MD b/README.MD index 485482a..1a6685a 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,6 @@ # Vodyani core -👩🏻‍🚀 "core" is the top-level design package for vodyani scaffolding, providing a single responsibility module registrar for the different tiers. +👩🏻‍🚀 Vodyani core 是 vodyani 脚手架的顶层设计,包含:按层级划分的单一职责模块注册装饰器、异步提供者注入装饰器。 [![Npm](https://img.shields.io/npm/v/@vodyani/core/latest.svg)](https://www.npmjs.com/package/@vodyani/core) [![Npm](https://img.shields.io/npm/v/@vodyani/core/beta.svg)](https://www.npmjs.com/package/@vodyani/core) @@ -13,20 +13,18 @@ ## Installation -```bash +```sh npm install @vodyani/core ``` -## Usage +## Getting started -|Features|Type|Description| -|:-:|:-:|:-:| -|InfrastructureRegister|class decorator|Used to replace the **@Module** from **Nest.js** and provide a single responsible `infrastructure module` registrar.| -|DomainRegister|class decorator|Used to replace the **@Module** from **Nest.js** and provide a single responsible `domain module` registrar.| -|ApiRegister|class decorator|Used to replace the **@Module** from **Nest.js** and provide a single responsible `application interface module` registrar.| -|ContainerRegister|class decorator|Used to replace the **@Module** from **Nest.js** and provide a single responsible `application container module` registrar.| -|InstanceContainer|class|The Structure for storing multiple instances.| -|AsyncProviderFactory|interface|The factory class for implementing to create a `Nest.js` factory providers.| +- [使用文档 📚](https://vodyani.vercel.app/docs/other/core) +- [Documentation 📚](https://vodyani.vercel.app/en/docs/other/core) + +## Questions + +- [Discussions 🧐](https://github.com/vodyani/core/discussions) ## Team diff --git a/package-lock.json b/package-lock.json index d2bda00..67d1c89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1329,9 +1329,9 @@ } }, "node_modules/@nestjs/core": { - "version": "8.4.4", - "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.4.4.tgz", - "integrity": "sha512-Ef3yJPuzAttpNfehnGqIV5kHIL9SHptB5F4ERxoU7pT61H3xiYpZw6hSjx68cJO7cc6rm7/N+b4zeuJvFHtvBg==", + "version": "8.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.4.7.tgz", + "integrity": "sha512-XB9uexHqzr2xkPo6QSiQWJJttyYYLmvQ5My64cFvWFi7Wk2NIus0/xUNInwX3kmFWB6pF1ab5Y2ZBvWdPwGBhw==", "dev": true, "hasInstallScript": true, "peer": true, @@ -1341,7 +1341,7 @@ "iterare": "1.2.1", "object-hash": "3.0.0", "path-to-regexp": "3.2.0", - "tslib": "2.3.1", + "tslib": "2.4.0", "uuid": "8.3.2" }, "funding": { @@ -1368,6 +1368,13 @@ } } }, + "node_modules/@nestjs/core/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "dev": true, + "peer": true + }, "node_modules/@nestjs/platform-express": { "version": "8.4.3", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-8.4.3.tgz", @@ -2430,7 +2437,7 @@ "node_modules/append-field": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", - "integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY=", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", "dev": true }, "node_modules/arg": { @@ -2457,7 +2464,7 @@ "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "dev": true }, "node_modules/array-ify": { @@ -2686,7 +2693,7 @@ "node_modules/body-parser/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "node_modules/body-parser/node_modules/qs": { @@ -2794,7 +2801,7 @@ "node_modules/busboy": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz", - "integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=", + "integrity": "sha512-InWFDomvlkEj+xWLBfU3AvnbVYqeTWmQopiW0tWWEy5yehYm2YkGEc59sUmw/4ty5Zj/b0WHGs1LgecuBSBGrg==", "dev": true, "dependencies": { "dicer": "0.2.5", @@ -2807,13 +2814,13 @@ "node_modules/busboy/node_modules/isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", "dev": true }, "node_modules/busboy/node_modules/readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==", "dev": true, "dependencies": { "core-util-is": "~1.0.0", @@ -2825,7 +2832,7 @@ "node_modules/busboy/node_modules/string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==", "dev": true }, "node_modules/bytes": { @@ -3266,7 +3273,7 @@ "node_modules/cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "dev": true }, "node_modules/cookiejar": { @@ -3559,7 +3566,7 @@ "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "dev": true, "engines": { "node": ">= 0.6" @@ -3574,7 +3581,7 @@ "node_modules/destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", + "integrity": "sha512-3NdhDuEXnfun/z7x9GOElY49LoqVHoGScmOKwmxhsS8N5Y+Z8KyPPDnaSzqWgYt/ji4mqwfTS34Htrk0zPIXVg==", "dev": true }, "node_modules/detect-newline": { @@ -3599,7 +3606,7 @@ "node_modules/dicer": { "version": "0.2.5", "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz", - "integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=", + "integrity": "sha512-FDvbtnq7dzlPz0wyYlOExifDEZcu8h+rErEXgfxqmLfRfC/kJidEFh4+effJRO3P0xmfqyPbSMG0LveNRfTKVg==", "dev": true, "dependencies": { "readable-stream": "1.1.x", @@ -3612,13 +3619,13 @@ "node_modules/dicer/node_modules/isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", "dev": true }, "node_modules/dicer/node_modules/readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==", "dev": true, "dependencies": { "core-util-is": "~1.0.0", @@ -3630,7 +3637,7 @@ "node_modules/dicer/node_modules/string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==", "dev": true }, "node_modules/diff": { @@ -3744,7 +3751,7 @@ "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", "dev": true }, "node_modules/electron-to-chromium": { @@ -3774,7 +3781,7 @@ "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", "dev": true, "engines": { "node": ">= 0.8" @@ -3866,7 +3873,7 @@ "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", "dev": true }, "node_modules/escape-string-regexp": { @@ -4365,7 +4372,7 @@ "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", "dev": true, "engines": { "node": ">= 0.6" @@ -4471,13 +4478,13 @@ "node_modules/express/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "node_modules/express/node_modules/path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", "dev": true }, "node_modules/express/node_modules/qs": { @@ -4660,7 +4667,7 @@ "node_modules/finalhandler/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "node_modules/find-up": { @@ -4785,7 +4792,7 @@ "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", "dev": true, "engines": { "node": ">= 0.6" @@ -6984,7 +6991,7 @@ "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", "dev": true, "engines": { "node": ">= 0.6" @@ -7030,7 +7037,7 @@ "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==", "dev": true }, "node_modules/merge-stream": { @@ -7153,6 +7160,18 @@ "node": ">= 6" } }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/modify-values": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz", @@ -7172,6 +7191,7 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.4.tgz", "integrity": "sha512-2wY2+xD4udX612aMqMcB8Ws2Voq6NIUPEtD1be6m411T4uDH/VtL9i//xvcyFlTVfRdaBsk7hV5tgrGQqhuBiw==", + "deprecated": "Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.", "dev": true, "dependencies": { "append-field": "^1.0.0", @@ -7187,18 +7207,6 @@ "node": ">= 0.10.0" } }, - "node_modules/multer/node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -9855,7 +9863,7 @@ "node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", "dev": true, "dependencies": { "ee-first": "1.1.1" @@ -10966,7 +10974,7 @@ "node_modules/send/node_modules/debug/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "node_modules/send/node_modules/mime": { @@ -11260,7 +11268,7 @@ "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "dev": true, "engines": { "node": ">= 0.6" @@ -11303,7 +11311,7 @@ "node_modules/streamsearch": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz", - "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=", + "integrity": "sha512-jos8u++JKm0ARcSUTAZXOVC0mSox7Bhn6sBgty73P1f3JGf7yG2clTbBNHUdde/kdvP2FESam+vM6l8jBrNxHA==", "dev": true, "engines": { "node": ">=0.8.0" @@ -11932,7 +11940,7 @@ "node_modules/typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", "dev": true }, "node_modules/typedarray-to-buffer": { @@ -12015,7 +12023,7 @@ "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", "dev": true, "engines": { "node": ">= 0.8" @@ -12045,7 +12053,7 @@ "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", "dev": true, "engines": { "node": ">= 0.4.0" @@ -13386,9 +13394,9 @@ } }, "@nestjs/core": { - "version": "8.4.4", - "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.4.4.tgz", - "integrity": "sha512-Ef3yJPuzAttpNfehnGqIV5kHIL9SHptB5F4ERxoU7pT61H3xiYpZw6hSjx68cJO7cc6rm7/N+b4zeuJvFHtvBg==", + "version": "8.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.4.7.tgz", + "integrity": "sha512-XB9uexHqzr2xkPo6QSiQWJJttyYYLmvQ5My64cFvWFi7Wk2NIus0/xUNInwX3kmFWB6pF1ab5Y2ZBvWdPwGBhw==", "dev": true, "peer": true, "requires": { @@ -13397,8 +13405,17 @@ "iterare": "1.2.1", "object-hash": "3.0.0", "path-to-regexp": "3.2.0", - "tslib": "2.3.1", + "tslib": "2.4.0", "uuid": "8.3.2" + }, + "dependencies": { + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "dev": true, + "peer": true + } } }, "@nestjs/platform-express": { @@ -14214,7 +14231,7 @@ "append-field": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", - "integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY=", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", "dev": true }, "arg": { @@ -14241,7 +14258,7 @@ "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "dev": true }, "array-ify": { @@ -14425,7 +14442,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "qs": { @@ -14507,7 +14524,7 @@ "busboy": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz", - "integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=", + "integrity": "sha512-InWFDomvlkEj+xWLBfU3AvnbVYqeTWmQopiW0tWWEy5yehYm2YkGEc59sUmw/4ty5Zj/b0WHGs1LgecuBSBGrg==", "dev": true, "requires": { "dicer": "0.2.5", @@ -14517,13 +14534,13 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", "dev": true }, "readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==", "dev": true, "requires": { "core-util-is": "~1.0.0", @@ -14535,7 +14552,7 @@ "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==", "dev": true } } @@ -14882,7 +14899,7 @@ "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "dev": true }, "cookiejar": { @@ -15107,7 +15124,7 @@ "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "dev": true }, "deprecation": { @@ -15119,7 +15136,7 @@ "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", + "integrity": "sha512-3NdhDuEXnfun/z7x9GOElY49LoqVHoGScmOKwmxhsS8N5Y+Z8KyPPDnaSzqWgYt/ji4mqwfTS34Htrk0zPIXVg==", "dev": true }, "detect-newline": { @@ -15141,7 +15158,7 @@ "dicer": { "version": "0.2.5", "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz", - "integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=", + "integrity": "sha512-FDvbtnq7dzlPz0wyYlOExifDEZcu8h+rErEXgfxqmLfRfC/kJidEFh4+effJRO3P0xmfqyPbSMG0LveNRfTKVg==", "dev": true, "requires": { "readable-stream": "1.1.x", @@ -15151,13 +15168,13 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", "dev": true }, "readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==", "dev": true, "requires": { "core-util-is": "~1.0.0", @@ -15169,7 +15186,7 @@ "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==", "dev": true } } @@ -15268,7 +15285,7 @@ "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", "dev": true }, "electron-to-chromium": { @@ -15292,7 +15309,7 @@ "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", "dev": true }, "env-ci": { @@ -15363,7 +15380,7 @@ "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", "dev": true }, "escape-string-regexp": { @@ -15744,7 +15761,7 @@ "etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", "dev": true }, "execa": { @@ -15832,13 +15849,13 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", "dev": true }, "qs": { @@ -15983,7 +16000,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true } } @@ -16068,7 +16085,7 @@ "fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", "dev": true }, "from2": { @@ -17714,7 +17731,7 @@ "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", "dev": true }, "meow": { @@ -17747,7 +17764,7 @@ "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==", "dev": true }, "merge-stream": { @@ -17837,6 +17854,15 @@ "kind-of": "^6.0.3" } }, + "mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "requires": { + "minimist": "^1.2.6" + } + }, "modify-values": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz", @@ -17863,17 +17889,6 @@ "on-finished": "^2.3.0", "type-is": "^1.6.4", "xtend": "^4.0.0" - }, - "dependencies": { - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - } } }, "natural-compare": { @@ -19747,7 +19762,7 @@ "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", "dev": true, "requires": { "ee-first": "1.1.1" @@ -20565,7 +20580,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true } } @@ -20814,7 +20829,7 @@ "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "dev": true }, "stream-combiner2": { @@ -20856,7 +20871,7 @@ "streamsearch": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz", - "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=", + "integrity": "sha512-jos8u++JKm0ARcSUTAZXOVC0mSox7Bhn6sBgty73P1f3JGf7yG2clTbBNHUdde/kdvP2FESam+vM6l8jBrNxHA==", "dev": true }, "string_decoder": { @@ -21304,7 +21319,7 @@ "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", "dev": true }, "typedarray-to-buffer": { @@ -21365,7 +21380,7 @@ "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", "dev": true }, "uri-js": { @@ -21392,7 +21407,7 @@ "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", "dev": true }, "uuid": { diff --git a/src/base.ts b/src/base.ts deleted file mode 100644 index 8763726..0000000 --- a/src/base.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * A container that uses a Map structure to store instances. - */ -export class InstanceContainer { - /** - * Instances store map. - */ - private readonly store: Map = new Map(); - /** - * Set an instance to the container map. - * - * @param key instance token. - * @param value instance. - * - * @publicApi - */ - public set(key: K, value: V) { - this.store.set(key, value); - } - /** - * Get instance. - * - * @param key instance token. - * - * @publicApi - */ - public get(key: K) { - return this.store.get(key) || null; - } -} diff --git a/src/common/index.ts b/src/common/index.ts new file mode 100644 index 0000000..37d0601 --- /dev/null +++ b/src/common/index.ts @@ -0,0 +1 @@ +export * from './interface'; diff --git a/src/common.ts b/src/common/interface.ts similarity index 70% rename from src/common.ts rename to src/common/interface.ts index ad3c51d..3921511 100644 --- a/src/common.ts +++ b/src/common/interface.ts @@ -1,4 +1,8 @@ -import { FactoryProvider, InjectionToken, ModuleMetadata } from '@nestjs/common'; +import { FactoryProvider, ModuleMetadata } from '@nestjs/common'; + +export interface Class extends Function { + new (...args: any[]): T; +} /** * Infrastructure Module Registration Options. */ @@ -6,11 +10,11 @@ export interface InfrastructureRegisterOptions { /** * Other modules that need to be imported. */ - imports?: ModuleMetadata['imports']; + import?: ModuleMetadata['imports']; /** * Providers to be exported in the current module. */ - exports?: ModuleMetadata['exports']; + export?: ModuleMetadata['exports']; /** * Providers in the current module. * @@ -25,7 +29,7 @@ export interface DomainRegisterOptions { /** * Other modules that need to be imported. */ - imports?: ModuleMetadata['imports']; + import?: ModuleMetadata['imports']; /** * Service entry for the domain module. * @@ -44,10 +48,6 @@ export interface DomainRegisterOptions { * Infrastructure module call and wrapper provider for domain modules. */ provider?: ModuleMetadata['providers']; - /** - * Entity for domain modules. - */ - entity?: ModuleMetadata['providers']; } /** * Api Module Registration Options. @@ -56,7 +56,7 @@ export interface ApiRegisterOptions { /** * Other modules that need to be imported. */ - imports: ModuleMetadata['imports']; + import?: ModuleMetadata['imports']; /** * Controller for api modules. */ @@ -77,7 +77,7 @@ export interface ContainerRegisterOptions { /** * Api modules that need to be imported. */ - api: ModuleMetadata['imports']; + api?: ModuleMetadata['imports']; /** * Infrastructure modules that need to be imported. */ @@ -88,24 +88,18 @@ export interface ContainerRegisterOptions { aop?: ModuleMetadata['providers']; } /** - * Asynchronous provider factory for creating [factory provider objects](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory). + * Asynchronous provider factory for creating + * + * @see: [factory provider objects](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory) */ export interface AsyncProviderFactory { - /** - * Get dependency injection `token` for factory providers. - * - * @returns InjectionToken - * - * @publicApi - */ - getToken: () => InjectionToken; /** * Create a factory provider by specifying the creation parameters externally. * - * @param ...args Arbitrary length, arbitrary type of parameters * @returns FactoryProvider * * @publicApi */ - createProvider: (...args: any[]) => FactoryProvider; + create: (...args: any[]) => FactoryProvider; } + diff --git a/src/decorator/async-inject.ts b/src/decorator/async-inject.ts new file mode 100644 index 0000000..574ad8b --- /dev/null +++ b/src/decorator/async-inject.ts @@ -0,0 +1,27 @@ +import { Inject } from '@nestjs/common'; + +import { StaticStore } from '../structs'; +import { getToken } from '../method'; +import { AsyncProviderFactory, Class } from '../common'; + +/** + * Use this decorator to handle dependency management for asynchronous provider factory classes. + * + * @param target The asynchronous provider factory class. + * + * @publicApi + */ +export function AsyncInjectable(target: Class) { + StaticStore.set(target.name); +} +/** + * Use this decorator to inject the asynchronous provider into the class instantiation process. + * + * @param target The asynchronous provider factory class. + * + * @publicApi + */ +export function AsyncInject(target: Class) { + const token = getToken(target); + return Inject(token); +} diff --git a/src/decorator/index.ts b/src/decorator/index.ts new file mode 100644 index 0000000..77cf7ca --- /dev/null +++ b/src/decorator/index.ts @@ -0,0 +1,2 @@ +export * from './async-inject'; +export * from './module'; diff --git a/src/decorator.ts b/src/decorator/module.ts similarity index 64% rename from src/decorator.ts rename to src/decorator/module.ts index 12c9c13..086225f 100644 --- a/src/decorator.ts +++ b/src/decorator/module.ts @@ -5,7 +5,7 @@ import { ContainerRegisterOptions, DomainRegisterOptions, InfrastructureRegisterOptions, -} from './common'; +} from '../common'; /** * Decorator of Infrastructure Module Register. @@ -17,13 +17,11 @@ import { * * @publicApi */ -export function InfrastructureRegister(options: InfrastructureRegisterOptions) { - const { imports, exports, provider } = options; - +export function Infrastructure(options: InfrastructureRegisterOptions) { return Module({ - imports, - exports: exports || [], - providers: provider || [], + imports: options.import || [], + exports: options.export || [], + providers: options.provider, }); } /** @@ -36,18 +34,15 @@ export function InfrastructureRegister(options: InfrastructureRegisterOptions) { * * @publicApi */ -export function DomainRegister(options: DomainRegisterOptions) { - const { imports, service, manager, repository, provider, entity } = options; - +export function Domain(options: DomainRegisterOptions) { return Module({ - imports, - exports: service, + imports: options.import || [], + exports: options.service, providers: [ - ...service, - ...(manager || []), - ...(repository || []), - ...(provider || []), - ...(entity || []), + ...options.service, + ...(options.manager || []), + ...(options.repository || []), + ...(options.provider || []), ], }); } @@ -61,15 +56,13 @@ export function DomainRegister(options: DomainRegisterOptions) { * * @publicApi */ -export function ApiRegister(options: ApiRegisterOptions) { - const { imports, aop, consumer, controller } = options; - +export function Api(options: ApiRegisterOptions) { return Module({ - imports, - controllers: controller, + imports: options.import || [], + controllers: options.controller, providers: [ - ...(aop || []), - ...(consumer || []), + ...(options.aop || []), + ...(options.consumer || []), ], }); } @@ -83,12 +76,12 @@ export function ApiRegister(options: ApiRegisterOptions) { * * @publicApi */ -export function ContainerRegister(options: ContainerRegisterOptions) { +export function Container(options: ContainerRegisterOptions) { const { aop, api, infrastructure } = options; return Module({ imports: [ - ...api, + ...(api || []), ...(infrastructure || []), ], providers: aop || [], diff --git a/src/index.ts b/src/index.ts index 58e4b4a..c77ea3b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export * from './base'; export * from './common'; export * from './decorator'; +export * from './method'; diff --git a/src/method/async-inject.ts b/src/method/async-inject.ts new file mode 100644 index 0000000..85a18c4 --- /dev/null +++ b/src/method/async-inject.ts @@ -0,0 +1,15 @@ +import { AsyncProviderFactory, Class } from '../common'; +import { StaticStore } from '../structs'; + +/** + * The corresponding injected token value is obtained by passing in the asynchronous provider factory class. + * + * @param target The asynchronous provider factory class. + * @returns token (symbol) + * + * @publicApi + */ +export function getToken(target: Class) { + const token = StaticStore.get(target.name); + return token; +} diff --git a/src/method/index.ts b/src/method/index.ts new file mode 100644 index 0000000..566d842 --- /dev/null +++ b/src/method/index.ts @@ -0,0 +1 @@ +export * from './async-inject'; diff --git a/src/structs/index.ts b/src/structs/index.ts new file mode 100644 index 0000000..c4e4371 --- /dev/null +++ b/src/structs/index.ts @@ -0,0 +1 @@ +export * from './store'; diff --git a/src/structs/store.ts b/src/structs/store.ts new file mode 100644 index 0000000..3ab8396 --- /dev/null +++ b/src/structs/store.ts @@ -0,0 +1,11 @@ +export class StaticStore { + private static readonly map = new Map(); + + public static get(key: string) { + return StaticStore.map.get(key); + } + + public static set(key: string) { + StaticStore.map.set(key, Symbol(key)); + } +} diff --git a/test/base.spec.ts b/test/base.spec.ts deleted file mode 100644 index 31d3335..0000000 --- a/test/base.spec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { describe, it, expect } from '@jest/globals'; - -import { InstanceContainer } from '../src'; - -describe('InstanceContainer', () => { - it('test', async () => { - const instance = new InstanceContainer(); - - expect(instance.get('none')).toBe(null); - expect(instance.set('name', 'vodyani')).toBe(undefined); - expect(instance.get('name')).toBe('vodyani'); - }); -}); diff --git a/test/decorator.spec.ts b/test/decorator.spec.ts index 695cdf9..c90c83f 100644 --- a/test/decorator.spec.ts +++ b/test/decorator.spec.ts @@ -1,32 +1,64 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/ban-ts-comment */ + import * as request from 'supertest'; import { Test } from '@nestjs/testing'; import { Controller, Get, Injectable } from '@nestjs/common'; import { describe, it, expect, beforeEach } from '@jest/globals'; import { - ApiRegister, - ContainerRegister, - DomainRegister, - InfrastructureRegister, + Api, + Container, + Domain, + Infrastructure, + AsyncInject, + AsyncInjectable, + AsyncProviderFactory, + getToken, } from '../src'; + +@AsyncInjectable +// @ts-ignore +class AsyncNameProvider implements AsyncProviderFactory { + public create = () => ({ + inject: [NameInfrastructureProvider], + provide: getToken(AsyncNameProvider), + useFactory: (provider: NameInfrastructureProvider) => { + return provider; + }, + }); +} + @Injectable() // @ts-ignore -class NameInfrastructureProvider { public get() { return 'InfrastructureProvider' }} +class NameInfrastructureProvider { + public get() { return 'InfrastructureProvider' } +} -@InfrastructureRegister({ exports: [NameInfrastructureProvider], provider: [NameInfrastructureProvider] }) +@Infrastructure({ + export: [NameInfrastructureProvider], + provider: [NameInfrastructureProvider], +}) // @ts-ignore class NameInfrastructure {} @Injectable() // @ts-ignore class NameProvider { - constructor(private readonly name: NameInfrastructureProvider) {} + constructor( + private readonly name: NameInfrastructureProvider, + // @ts-ignore + @AsyncInject(AsyncNameProvider) private readonly asyncName: any, + ) {} public get() { return this.name.get(); } + + public getAsyncName() { + return this.asyncName.get(); + } } @Injectable() @@ -35,11 +67,18 @@ class NameService { constructor(private readonly name: NameProvider) {} public get() { - return this.name.get(); + return { + name: this.name.get(), + asyncName: this.name.getAsyncName(), + }; } } -@DomainRegister({ imports: [NameInfrastructure], service: [NameService], provider: [NameProvider] }) +@Domain({ + import: [NameInfrastructure], + service: [NameService], + provider: [NameProvider, new AsyncNameProvider().create()], +}) // @ts-ignore class NameDomain {} @@ -52,18 +91,26 @@ class NameController { @Get() // @ts-ignore get() { - return { name: this.name.get() }; + return { data: this.name.get() }; } } -@ApiRegister({ imports: [NameDomain], controller: [NameController] }) +@Api({ import: [NameDomain], controller: [NameController] }) // @ts-ignore class NameApi {} -@ContainerRegister({ api: [NameApi] }) +@Container({ api: [NameApi] }) // @ts-ignore class AppModule {} + +@Container({}) +@Api({ controller: [] }) +@Domain({ service: [] }) +@Infrastructure({ provider: [] }) +// @ts-ignore +class Demo {} + let app: any; beforeEach(async () => { @@ -77,7 +124,8 @@ describe('decorator', () => { const data = await request(app.getHttpServer()).get('/name'); expect(data.statusCode).toBe(200); - expect(data.body.name).toBe('InfrastructureProvider'); + expect(data.body.data.name).toBe('InfrastructureProvider'); + expect(data.body.data.asyncName).toBe('InfrastructureProvider'); await app.close(); });