createCommand
createCommand<
TSchema,TBase>(schema,Base?):ZodCommandClass<TSchema,TBase>
Defined in: packages/pipeline-zod/src/create-zod-request.ts:264
Generates a strongly-typed CQRS Command class from a Zod schema.
Automatically marks the class with requestKind = 'command',
attaches the Zod schema as static _zodSchema, forwards Standard Schema metadata (~standard),
lists the fields marked with updatable as static updatableFields,
and preserves any Base class inheritance.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TBase extends AbstractConstructor<object> = AbstractConstructor<object>
Parameters
Section titled “Parameters”schema
Section titled “schema”TSchema
TBase
Returns
Section titled “Returns”ZodCommandClass<TSchema, TBase>
Examples
Section titled “Examples”Defining a Command with a base class
abstract class AppCommand { constructor(readonly actorId?: string) {}}
const CreateUserSchema = z.object({ username: z.string().min(3), email: z.email(),});
export class CreateUserCommand extends createCommand(CreateUserSchema, AppCommand) {}Declaring the fields an update command changes
export class UpdateRoleCommand extends createCommand( z.object({ id: z.uuid(), name: z.string().trim().apply(updatable).min(3) }),) {}
// The fields to pass to field-level authorization:UpdateRoleCommand.updatableFields; // ['name']