import type { PipeTransform } from '@nestjs/common'; import { z } from 'zod'; import { AppError } from './errors/app-error'; export class SchemaPipe implements PipeTransform { constructor(private readonly schema: z.ZodType) {} transform(value: unknown): T { const result = this.schema.safeParse(value); if (!result.success) { throw new AppError('REQUEST_INVALID', 'SCHEMA_REJECTED', [ ...new Set(result.error.issues.map((issue) => issue.path.join('.'))), ]); } return result.data; } }