validate() function

Field decorator that records a validator for one class field, sitting beside @property on an @imqueue/rpc input class.

Signature:

export declare function validate(validator: Validator): (_value: undefined, context: ClassFieldDecoratorContext) => void;

Parameters

Parameter

Type

Description

validator

Validator

A Zod schema, a validatable() class for a nested input object, or null/undefined to record nothing for this field.

Returns:

(_value: undefined, context: ClassFieldDecoratorContext) => void

The TC39 field decorator that records validator against the field.

Exceptions

Error if applied to anything other than a class field.

Remarks

The class itself must also carry validatable(), and getting that wrong is worse than it sounds. A field decorated here is buffered until a class decorator claims it, and nothing flushes the buffer when a class body simply ends — so a class that uses validate() without validatable() leaves its fields behind for whichever class is sealed next. That class then demands properties it does not declare and rejects input that was perfectly valid, while the class with the actual mistake still validates nothing. The error surfaces on the innocent one, so treat an unexplained missing-property failure as a missing validatable() somewhere above it.

The field name becomes the key in the assembled object schema verbatim, so it has to match the property name the caller sends.

Example

import { z } from 'zod';
import { validatable, validate } from '@imqueue/validation';

@validatable()
class Credentials {
    @validate(z.string().email())
    email!: string;

    @validate(z.string().min(8))
    password!: string;
}

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.