@dev-suite/decorators
v0.1.1
Published
Collection of reusable TypeScript decorators for classes and methods
Downloads
334
Maintainers
Readme
@dev-suite/decorators
Framework-agnostic TypeScript decorators for classes, methods, properties, and parameters.
Installation
npm i @dev-suite/decorators
# or
yarn add @dev-suite/decorators
# or
pnpm add @dev-suite/decoratorsQuick Example
import { dedupe, retry, timeout, serialize } from '@dev-suite/decorators';
class ApiClient {
@dedupe()
@retry({ attempts: 3, delayMs: 100 })
@timeout({ ms: 3000 })
@serialize({ serializer: (value) => ({ data: value }) })
async fetchUser(id: string) {
return { id, name: 'John' };
}
}API Overview
Class decorators
autoBindMethodsclassMetadataclassTraceconstructMetricsfeatureGateinjectConfiginstanceLimitlifecycleHookssingleton
Method decorators
benchmarkcachedebouncededupefallbackidempotentlockmetricsrateLimitretryserializetimeouttracetransactionvalidateArgsdebugFnArgsdebugFnResponse
Parameter decorators
clampParamcoercedefaultParamemailParamenumParamfromJsonlowercasemaskSensitiverangeParamrequiredParamsanitizesplitCsvtrimuppercaseuuidParamvalidateSchema
Property decorators
defaultValuememoizedComputedobservablepersisttransformvalidate
Full Decorator Matrix
For all decorators with parameters and "where to use" guidance:
Subpath Imports
You can import specific decorators directly:
import { retry } from '@dev-suite/decorators/retry';
import { transaction } from '@dev-suite/decorators/transaction';Development
yarn workspace @dev-suite/decorators build
yarn workspace @dev-suite/decorators test
yarn workspace @dev-suite/decorators sync-exportsContributing
- Keep 100% test coverage for touched code paths.
- Add or update tests together with behavior changes.
- Keep changes framework-agnostic and backward-compatible unless explicitly discussed.
Compatibility
- Node.js:
>=18.18.0 - TypeScript declaration files: included (
dist/index.d.ts)
License
MIT
