Skip to main content

validate

@rotorsoft/act-root


@rotorsoft/act-root / act/src / validate

Function: validate()

validate<S>(target, payload, schema?): Readonly<S>

Defined in: libs/act/src/utils.ts:90

Validates a payload against a Zod schema, throwing a ValidationError on failure.

Type Parameters

S

S

Parameters

target

string

The name of the target (for error reporting)

payload

Readonly<S>

The payload to validate

schema?

ZodType<S, unknown, $ZodTypeInternals<S, unknown>>

(Optional) The Zod schema to validate against

Returns

Readonly<S>

The validated payload

Throws

ValidationError if validation fails

Example

const valid = validate("User", userPayload, userSchema);