createZodMapper
Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.
createZodMapper<
TInput,TOutput>(schema):ZodMapper<TInput,TOutput>
Defined in: packages/pipeline-zod/src/create-zod-mapper.ts:41
Creates a mapper that parses input through a Zod schema, typically turning a validated request body into a command at the HTTP edge.
It parses synchronously, so the schema must not use async refinements or transforms. A
failure throws ZodValidationError, whose details hold { formErrors, fieldErrors };
toHttpResponse of @cqrs-ddd/pipeline-zod/http answers it with HTTP 400.
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput
TOutput
Section titled “TOutput”TOutput
Parameters
Section titled “Parameters”schema
Section titled “schema”ZodType<TOutput, TInput>
Schema whose output is the mapped value.
Returns
Section titled “Returns”ZodMapper<TInput, TOutput>
A ZodMapper over schema.
Example
Section titled “Example”Map a request body to a command
export const CreateUserMapper = createZodMapper( CreateUserDtoSchema.transform( ({ name, email }) => new CreateUserCommand({ username: name, email }), ),);
app.post('/users', async (req, res) => { res.json(await commandBus.execute(CreateUserMapper.map(req.body)));});