-
Notifications
You must be signed in to change notification settings - Fork 0
Decorators Matrix
awekrx edited this page May 21, 2026
·
1 revision
This page is intended for GitHub Wiki (copy as Decorators-Matrix).
Columns:
-
Decorator: public name -
Parameters: constructor/options signature with option fields -
Use When: practical usage guidance
| Decorator | Parameters | Use When |
|---|---|---|
autoBindMethods |
autoBindMethods(options?)options.exclude?: PropertyKey[]options.shouldIncludeOwnProperties?: boolean
|
You need stable this for class methods used as callbacks. |
classMetadata |
classMetadata(options)options.metadata: Record<string, unknown>options.symbol?: symbol
|
You want to attach/read static metadata on classes. |
classTrace |
classTrace(options?)options.logger?: { info(message, context?); error(message, context?) }options.shouldIncludeArgs?: boolean
|
You need constructor-level trace logging and diagnostics. |
constructMetrics |
constructMetrics(options?)options.enabled?: boolean | (() => boolean)options.reporter?: (report: { className: string; durationMs: number; success: boolean; error?: unknown }) => void
|
You want constructor timing/success metrics. |
featureGate |
featureGate(options)options.isEnabled: boolean | (() => boolean)options.featureName?: string
|
You need runtime feature toggling at class level. |
injectConfig |
injectConfig(options)options.config: Record<string, unknown>options.propertyKey?: PropertyKey
|
You want to inject config object into class instances. |
instanceLimit |
instanceLimit(options)options.maxInstances: numberoptions.message?: string
|
You must limit number of class instances. |
lifecycleHooks |
lifecycleHooks(options?)options.onInit?: PropertyKeyoptions.onDestroy?: PropertyKey
|
You want before/after lifecycle method hooks in classes. |
singleton |
singleton(options?)options.keyResolver?: (args: unknown[]) => stringoptions.store?: Map<string, InstanceType<ClassCtor>>
|
You need one shared class instance (or keyed singleton instances). |
| Decorator | Parameters | Use When |
|---|---|---|
benchmark |
benchmark(options?)options.enabled?: boolean | (() => boolean)options.now?: () => numberoptions.reporter?: (report: { args; durationMs; methodName; originalThis; success; error? }) => void
|
You need method latency reporting for sync/async methods. |
cache |
cache(options?)options.keyResolver?: (args) => stringoptions.ttlMs?: number
|
You want memoized method responses with optional TTL. |
debounce |
debounce(options)options.waitMs: numberoptions.cancelMessage?: stringoptions.keyResolver?: (args: unknown[]) => string
|
You need to suppress bursts and execute after quiet period. |
dedupe |
dedupe(options?)options.keyResolver?: (args) => string
|
You want to merge duplicate in-flight async calls by key. |
fallback |
fallback(options?)options.fallbackValue?: ReturnType<Fn>options.onError?: (error, args) => ReturnType<Fn>
|
You need fallback value/handler when method fails. |
idempotent |
idempotent(options?)options.keyResolver?: (args) => string
|
You want same in-flight promise for same key (idempotent async call). |
lock |
lock(options?)options.keyResolver?: (args) => stringoptions.message?: string
|
You need mutual exclusion around method execution. |
metrics |
metrics(options?)options.enabled?: boolean | (() => boolean)options.reporter?: (report: { name: PropertyKey; durationMs: number; success: boolean; error?: unknown }) => void
|
You need structured success/failure + duration metrics. |
rateLimit |
rateLimit(options)options.maxCalls: numberoptions.windowMs: numberoptions.keyResolver?: (args) => stringoptions.message?: string
|
You need to cap call frequency over a window. |
retry |
retry(options)options.attempts: numberoptions.delayMs?: numberoptions.shouldRetry?: (error, { args, attemptNumber }) => boolean
|
You need retry policy for transient errors. |
serialize |
serialize(options)options.serializer: (value, context) => unknowncontext = { args; methodName; originalThis }
|
You want to map method result into transport/DTO format. |
timeout |
timeout(options)options.ms: numberoptions.message?: string
|
You need hard upper bound for async execution time. |
trace |
trace(options?)options.reporter?: (event: { args; methodName; phase: 'start' | 'success' | 'error'; durationMs?; error? }) => void
|
You need execution tracing with args/result/error. |
transaction |
transaction(hooks)hooks.begin?: (context: { args; methodName; originalThis }) => TxState | Promise<TxState>hooks.commit?: (state: TxState, context) => void | Promise<void>hooks.rollback?: (state: TxState | undefined, error: unknown, context) => void | Promise<void>
|
You need begin/commit/rollback orchestration around a method. |
validateArgs |
validateArgs(options)options.schema: ZodType<Parameters<Fn>>
|
You need method argument validation before execution. |
debugFnArgs |
debugFnArgs(options?)options.formatArgs?: (args) => Primitiveoptions.enabled?: DebugFnEnabledoptions.label?: stringoptions.once?: booleanoptions.shouldHideDebugPrefix?: booleanoptions.shouldHideTime?: boolean
|
You want debug logging of method arguments. |
debugFnResponse |
debugFnResponse(options?)options.formatResponse?: (response) => Primitiveoptions.enabled?: DebugFnEnabledoptions.label?: stringoptions.once?: booleanoptions.shouldHideDebugPrefix?: booleanoptions.shouldHideTime?: boolean
|
You want debug logging of method responses/errors. |
| Decorator | Parameters | Use When |
|---|---|---|
clampParam |
clampParam(options)options.min: numberoptions.max: number
|
You need to clamp numeric input to min/max. |
coerce |
coerce(options)options.to: 'number' | 'boolean' | 'string' | 'date' | ((value: unknown) => unknown)
|
You want to convert input to target primitive type. |
defaultParam |
defaultParam(fallback, options?)fallback: unknownoptions.treatNullAsMissing?: boolean
|
You need fallback value for empty/undefined input. |
emailParam |
emailParam(options?)options.message?: stringoptions.normalize?: boolean
|
You need email format normalization/validation. |
enumParam |
enumParam(options)options.allowed: readonly unknown[]options.message?: string
|
You need to enforce value from allowed set. |
fromJson |
fromJson(options?)options.onlyStrings?: boolean
|
You need to parse JSON parameter safely. |
lowercase |
lowercase(options?)options.locale?: string
|
You need lowercase normalization. |
maskSensitive |
maskSensitive(options?)options.mask?: string
|
You need masked representation of sensitive data. |
rangeParam |
rangeParam(options)options.min: numberoptions.max: numberoptions.inclusive?: booleanoptions.message?: string
|
You need numeric range validation. |
requiredParam |
requiredParam(options?)options.message?: string
|
You need required argument enforcement. |
sanitize |
sanitize(options?)options.replacement?: stringoptions.rule?: RegExp | ((value: string) => string)
|
You need to sanitize unsafe input content. |
splitCsv |
splitCsv(options?)options.separator?: stringoptions.trimItems?: booleanoptions.filterEmpty?: boolean
|
You need CSV string to array conversion. |
trim |
trim(options?)options.collapseWhitespace?: boolean
|
You need whitespace trimming. |
uppercase |
uppercase(options?)options.locale?: string
|
You need uppercase normalization. |
uuidParam |
uuidParam(options?)options.message?: string
|
You need UUID format validation. |
validateSchema |
validateSchema(options)options.parse: (value: unknown) => unknownoptions.message?: string
|
You need schema-based parameter validation. |
| Decorator | Parameters | Use When |
|---|---|---|
defaultValue |
defaultValue(valueOrResolver)valueOrResolver: unknown | ((context) => unknown)
|
You need default value initialization for property. |
memoizedComputed |
memoizedComputed(compute)compute: (context) => unknown
|
You need cached computed property values. |
observable |
observable(onChange)onChange: ({ ...context, previousValue, nextValue }) => void
|
You need change notifications on property updates. |
persist |
persist(options)options.adapter: { get(key); set(key, value); delete?(key) }options.key?: string | ((context) => string)options.enabled?: boolean | ((context) => boolean)options.serialize?: (value: unknown) => unknownoptions.deserialize?: (value: unknown) => unknown
|
You need persistent property storage adapter behavior. |
transform |
transform(mapper)mapper: ({ ...context, value }) => unknown
|
You need value transformation on set/get. |
validate |
validate(predicate)predicate: ({ ...context, value }) => boolean | undefined
|
You need property-level validation on assignment. |