nest-profiler-validator
API reference for @eleven-labs/nest-profiler-validator — validator-agnostic validation collector.
ValidatorCollectorModuleOptions
Options for ValidatorCollectorModule.forRoot().
Prop
Type
ValidationEntry
One entry per DTO validated during a request (both valid and invalid).
Prop
Type
ViolationEntry
One entry per property that failed validation.
Prop
Type
ValidationStatus
type ValidationStatus = 'valid' | 'invalid';ValidationSource
type ValidationSource = 'body' | 'query' | 'param' | 'custom';Corresponds to the NestJS parameter decorator used: @Body(), @Query(), @Param(), or a custom decorator.
ProfilerValidationPipe
Implements PipeTransform. Registered as the global APP_PIPE by ValidatorCollectorModule.forRoot(). It wraps an inner validation pipe (the one you configure) rather than performing validation itself: it delegates to the inner pipe, records a valid entry on success, and on failure runs the configured extractors over the thrown error to record an invalid entry — then always re-throws the original exception.
ValidationViolationExtractor
Strategy that turns a validator-specific error into the neutral ViolationEntry[] shape. Return null to defer to the next extractor in the chain.
Prop
Type
Built-in extractors, exported and used in this default order:
import { DEFAULT_EXTRACTORS } from '@eleven-labs/nest-profiler-validator';
// [classValidatorExtractor, zodExtractor, genericExtractor]classValidatorExtractor— recovers the rawValidationError[]attached bycreateClassValidatorPipe.zodExtractor— readsZodError.issues(via nestjs-zod'sgetZodError()or a bareZodError).genericExtractor— anyHttpExceptionexposing amessagestring/array (universal fallback).
createClassValidatorPipe
Builds a class-validator ValidationPipe instrumented for the profiler (it attaches the raw ValidationError[] to the thrown exception so the panel shows per-property constraints). Used as the default inner pipe when pipe is omitted.
import { createClassValidatorPipe } from '@eleven-labs/nest-profiler-validator';
const pipe = createClassValidatorPipe({ whitelist: true, transform: true });Requires class-validator and class-transformer to be installed.
Public exports
import {
ValidatorCollectorModule,
ProfilerValidationPipe,
ValidatorCollector,
createClassValidatorPipe,
DEFAULT_EXTRACTORS,
classValidatorExtractor,
zodExtractor,
genericExtractor,
} from '@eleven-labs/nest-profiler-validator';
import type {
ValidatorCollectorModuleOptions,
ValidationViolationExtractor,
ViolationExtractorContext,
ValidationEntry,
ViolationEntry,
ValidationStatus,
ValidationSource,
ValidationPipeOptions,
} from '@eleven-labs/nest-profiler-validator';Setup
class-validator (default)
// In AppModule — registers ProfilerValidationPipe as global APP_PIPE,
// wrapping a default class-validator pipe built from validationPipeOptions.
ValidatorCollectorModule.forRoot({
validationPipeOptions: { whitelist: true, transform: true },
});nestjs-zod
import { ZodValidationPipe } from 'nestjs-zod';
ValidatorCollectorModule.forRoot({ pipe: new ZodValidationPipe() });A NestJS app uses a single global validation strategy, so use one validator at a time.
Important: Use value imports (not import type) for DTO classes in controllers so that TypeScript emits reflect-metadata for the parameter type:
// ✓ value import — allows TypeScript to emit design:paramtypes
import { CreateArticleDto } from './dto/create-article.dto';
// ✗ type-only import — erases metadata, metatype shows as 'Function'
import type { CreateArticleDto } from './dto/create-article.dto';Prerequisite: install the validator you use (class-validator + class-transformer, or nestjs-zod + zod). For class-validator, emitDecoratorMetadata: true must be set in tsconfig.json.