What this prompt does
This prompt generates a library of custom TypeScript decorators for a NestJS [app_type]. It specifies nine concrete decorators — @Auth(roles), @Cacheable(ttl, key) backed by [cache_backend], @Validate(schema), @Log(level), @RateLimit(max, window), @Retry(attempts, backoff) for [retry_targets], @Timeout(ms), and @Audit(action) — plus correct decorator composition and unit tests for each using NestJS testing utilities.
The structure works because cross-cutting concerns like auth, caching, and logging clutter business logic when handled inline. Decorators move that noise to the method signature, but they are easy to get subtly wrong: execution order when several stack on one method, and TypeScript metadata reflection setup, are the two failure points. By demanding composition tests and explicit reflection configuration, the prompt forces the output to confront exactly those pitfalls rather than producing decorators that work alone but break together.
When to use it
- When building a NestJS
[app_type]and you want auth and caching out of controllers - When the same cross-cutting logic is copy-pasted across many service methods
- When you need method-level caching against
[cache_backend]with clean invalidation - When external calls in
[retry_targets]need consistent retry-with-backoff behavior - When you want an audit trail recorded declaratively rather than by hand each time
- When standardizing logging, timeouts, and rate limits across a growing team
- When you want method-level concerns expressed declaratively at the signature instead of buried inside each handler
Example output
Expect a set of TypeScript decorator implementations using factory patterns and reflect-metadata, each with a usage example and a NestJS unit test. You get @Auth, @Cacheable backed by [cache_backend], @Validate, @Log, @RateLimit, @Retry scoped to [retry_targets], @Timeout, and @Audit, plus the compiler configuration that makes decorator metadata available at runtime. The output includes the metadata reflection setup and at least one composition test showing the correct execution order when multiple decorators stack on a single method, rather than isolated snippets that work alone but break when combined in a real [app_type] controller.
Pro tips
- Pin down
[cache_backend]early; Redis-backed@Cacheableneeds an invalidation story, so ask the prompt to show how cached entries are cleared - Treat the composition tests as non-negotiable — getting
@Auth,@RateLimit, and@Cacheableto stack in the right order is the part teams get wrong - Scope
[retry_targets]precisely; retrying non-idempotent database writes can double-apply side effects, so be explicit about what is safe to retry - Confirm the output enables
emitDecoratorMetadataandexperimentalDecoratorsand importsreflect-metadataonce at the entry point - Keep
@Validate(schema)using Zod as specified so DTO validation stays type-safe end to end - Iterate decorator by decorator; generating all nine at once tends to produce shallow tests, so refine each with its own edge cases