{"id":14978650,"url":"https://github.com/toss/nestjs-aop","last_synced_at":"2025-05-15T11:09:09.700Z","repository":{"id":64476965,"uuid":"572947313","full_name":"toss/nestjs-aop","owner":"toss","description":"A way to gracefully apply AOP to nestjs","archived":false,"fork":false,"pushed_at":"2025-01-02T08:43:03.000Z","size":228,"stargazers_count":236,"open_issues_count":3,"forks_count":28,"subscribers_count":9,"default_branch":"v2.x","last_synced_at":"2025-05-09T19:00:07.142Z","etag":null,"topics":["aop","nest","nestjs","nestjs-aop","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-01T11:25:33.000Z","updated_at":"2025-05-08T06:12:42.000Z","dependencies_parsed_at":"2023-02-10T20:31:35.469Z","dependency_job_id":"b30a7ee0-a675-418e-9fca-0356ab760b2c","html_url":"https://github.com/toss/nestjs-aop","commit_stats":{"total_commits":54,"total_committers":10,"mean_commits":5.4,"dds":0.2777777777777778,"last_synced_commit":"277fdf9fd4880a9fa7f2b02576116aafdd64ab56"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toss%2Fnestjs-aop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toss%2Fnestjs-aop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toss%2Fnestjs-aop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toss%2Fnestjs-aop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toss","download_url":"https://codeload.github.com/toss/nestjs-aop/tar.gz/refs/heads/v2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328386,"owners_count":22052632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aop","nest","nestjs","nestjs-aop","typescript"],"created_at":"2024-09-24T13:58:07.719Z","updated_at":"2025-05-15T11:09:09.672Z","avatar_url":"https://github.com/toss.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/toss/nestjs-aop\"\u003e\n    \u003cimg src=\"https://toss.tech/wp-content/uploads/2022/11/tech-article-nest-js-02.png\" alt=\"Logo\" height=\"200\"\u003e\n  \u003c/a\u003e\n\n  \u003ch2\u003e@toss/nestjs-aop \u0026middot; \u003ca href=\"https://badge.fury.io/js/@toss%2Fnestjs-aop\"\u003e\u003cimg src=\"https://badge.fury.io/js/@toss%2Fnestjs-aop.svg\" alt=\"npm version\" height=\"18\"\u003e\u003c/a\u003e\u003c/h2\u003e\n\n  \u003cp align=\"center\"\u003e\n    A way to gracefully apply AOP to nestjs\n    \u003cbr\u003e\n    Use nestjs managed instances in any decorators gracefully\n\u003c/a\u003e\u003c/h6\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\nEnglish | [한국어](https://github.com/toss/nestjs-aop/blob/v2.x/readme_kr.md) \n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#references\"\u003eReferences\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\n\n\u003c!-- INSTALLATION --\u003e\n## Installation\n\n```sh\nnpm install @toss/nestjs-aop\npnpm add @toss/nestjs-aop\nyarn add @toss/nestjs-aop\n```\n\n\n\u003c!-- USAGE EXAMPLES --\u003e\n## Usage\n\n#### 1. Import AopModule\n```typescript\n@Module({\n  imports: [\n    // ...\n    AopModule,\n  ],\n})\nexport class AppModule {}\n```\n\n#### 2. Create symbol for LazyDecorator\n```typescript\nexport const CACHE_DECORATOR = Symbol('CACHE_DECORATOR');\n```\n\n#### 3. Implement LazyDecorator using nestjs provider\n`metadata` is the second parameter of createDecorator.\n\n```typescript\n@Aspect(CACHE_DECORATOR)\nexport class CacheDecorator implements LazyDecorator\u003cany, CacheOptions\u003e {\n  constructor(private readonly cache: Cache) {}\n\n  wrap({ method, metadata: options }: WrapParams\u003cany, CacheOptions\u003e) {\n    return (...args: any) =\u003e {\n      let cachedValue = this.cache.get(...args);\n      if (!cachedValue) { \n        cachedValue = method(...args);\n        this.cache.set(cachedValue, ...args);\n      }\n      return cachedValue;\n    };\n  }\n}\n```\n\n#### 4. Add LazyDecoratorImpl to providers of module\n```typescript\n@Module({\n  providers: [CacheDecorator],\n})\nexport class CacheModule {}\n```\n\n#### 5. Create decorator that marks metadata of LazyDecorator\n`options` can be obtained from the warp method and used.\n\n```typescript\nexport const Cache = (options: CacheOptions) =\u003e createDecorator(CACHE_DECORATOR, options)\n```\n\n#### 6. Use it!\n```typescript\nexport class SomeService {\n  @Cache({\n    // ...options(metadata value)\n  })\n  some() {\n    // ...\n  }\n}\n```\n\n\n\u003c!-- REFERENCES --\u003e\n## References\n- https://toss.tech/article/nestjs-custom-decorator\n- https://youtu.be/VH1GTGIMHQw?t=2973\n\n\n\n\u003c!-- CONTRIBUTING --\u003e\n## Contributing\nWe welcome contribution from everyone in this project. Read [CONTRIBUTING.md](CONTRIBUTING.md) for detailed contribution guide.\n\n\n\n\u003c!-- LICENSE --\u003e\n## License\nMIT © Viva Republica, Inc. See [LICENSE](LICENSE) for details.\n\n\n\u003c!-- BOTTOM LOGO --\u003e\n\u003ca title=\"Toss\" href=\"https://toss.im\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://static.toss.im/logos/png/4x/logo-toss-reverse.png\"\u003e\n    \u003cimg alt=\"Toss\" src=\"https://static.toss.im/logos/png/4x/logo-toss.png\" width=\"100\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoss%2Fnestjs-aop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoss%2Fnestjs-aop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoss%2Fnestjs-aop/lists"}