ZodValidationBehavior
Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.
Defined in: packages/pipeline-zod/src/zod-validation.behavior.ts:112
Pipeline behavior that parses the incoming request (command, query, or event)
with a Zod schema when one is attached to the request class via the _zodSchema
static property (set automatically by createCommand(), createQuery(), or createZodRequest()).
How it works:
- If
context.requestType._zodSchemais aZodType, the behavior runsschema.safeParseAsync(context.request). - On failure it throws ZodValidationError;
toHttpResponse()from@cqrs-ddd/pipeline-zod/httpmaps it to an HTTP 400. - On success, the parsed result must be a plain object because pipeline request identity is preserved in-place. Keys omitted by the schema are deleted and parsed/coerced/defaulted values are assigned before the handler runs. A top-level transform to an array, primitive, Date, or other non-record shape is rejected rather than corrupting the request instance.
- If no schema is attached (e.g. a plain event class), the behavior is a transparent
no-op and simply calls
next().
Registration — globally for all request kinds:
createPipeline({ globalBehaviors: { scope: 'all', before: [ZodValidationBehavior], },});Registration — per handler only:
class CreateUserHandler { @pipeline.wrap({ kind: 'command' }, ZodValidationBehavior) async handle(command: CreateUserCommand) {}}Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ZodValidationBehavior():
ZodValidationBehavior
Returns
Section titled “Returns”ZodValidationBehavior
Methods
Section titled “Methods”handle()
Section titled “handle()”handle(
context,next):Promise<unknown>
Defined in: packages/pipeline-zod/src/zod-validation.behavior.ts:113
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”Promise<unknown>