Skip to content

Decorators Matrix

awekrx edited this page May 21, 2026 · 1 revision

Decorators Matrix

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

Class Decorators

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: number
options.message?: string
You must limit number of class instances.
lifecycleHooks lifecycleHooks(options?)
options.onInit?: PropertyKey
options.onDestroy?: PropertyKey
You want before/after lifecycle method hooks in classes.
singleton singleton(options?)
options.keyResolver?: (args: unknown[]) => string
options.store?: Map<string, InstanceType<ClassCtor>>
You need one shared class instance (or keyed singleton instances).

Method Decorators

Decorator Parameters Use When
benchmark benchmark(options?)
options.enabled?: boolean | (() => boolean)
options.now?: () => number
options.reporter?: (report: { args; durationMs; methodName; originalThis; success; error? }) => void
You need method latency reporting for sync/async methods.
cache cache(options?)
options.keyResolver?: (args) => string
options.ttlMs?: number
You want memoized method responses with optional TTL.
debounce debounce(options)
options.waitMs: number
options.cancelMessage?: string
options.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) => string
options.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: number
options.windowMs: number
options.keyResolver?: (args) => string
options.message?: string
You need to cap call frequency over a window.
retry retry(options)
options.attempts: number
options.delayMs?: number
options.shouldRetry?: (error, { args, attemptNumber }) => boolean
You need retry policy for transient errors.
serialize serialize(options)
options.serializer: (value, context) => unknown
context = { args; methodName; originalThis }
You want to map method result into transport/DTO format.
timeout timeout(options)
options.ms: number
options.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) => Primitive
options.enabled?: DebugFnEnabled
options.label?: string
options.once?: boolean
options.shouldHideDebugPrefix?: boolean
options.shouldHideTime?: boolean
You want debug logging of method arguments.
debugFnResponse debugFnResponse(options?)
options.formatResponse?: (response) => Primitive
options.enabled?: DebugFnEnabled
options.label?: string
options.once?: boolean
options.shouldHideDebugPrefix?: boolean
options.shouldHideTime?: boolean
You want debug logging of method responses/errors.

Parameter Decorators

Decorator Parameters Use When
clampParam clampParam(options)
options.min: number
options.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: unknown
options.treatNullAsMissing?: boolean
You need fallback value for empty/undefined input.
emailParam emailParam(options?)
options.message?: string
options.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: number
options.max: number
options.inclusive?: boolean
options.message?: string
You need numeric range validation.
requiredParam requiredParam(options?)
options.message?: string
You need required argument enforcement.
sanitize sanitize(options?)
options.replacement?: string
options.rule?: RegExp | ((value: string) => string)
You need to sanitize unsafe input content.
splitCsv splitCsv(options?)
options.separator?: string
options.trimItems?: boolean
options.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) => unknown
options.message?: string
You need schema-based parameter validation.

Property Decorators

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) => unknown
options.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.

Clone this wiki locally