# @imqueue/validation 1.1.0 · API reference

Source: https://imqueue.org/api/validation/latest/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/validation 1.1.0 — generated reference, not hand-written

Zod-backed input validation for `@imqueue` services, expressed as native (TC39) decorators rather than as a schema kept alongside the class it describes.

Declare the rules on the input class itself — [validate()](https://imqueue.org/api/validation/latest/validation.validate/) on each field, [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) on the class to seal them — and then either guard a service method's arguments with [validated()](https://imqueue.org/api/validation/latest/validation.validated/) or fetch the assembled schema with [schemaOf()](https://imqueue.org/api/validation/latest/validation.schemaof/) and parse by hand. It is used by `@imqueue/rpc` services and by the model code `@imqueue/pg-prisma` generates.

## Remarks

Two things about the decorators are worth knowing before you rely on them.

[validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) is not optional bookkeeping. Field validators are buffered until a class decorator claims them, so a class that uses [validate()](https://imqueue.org/api/validation/latest/validation.validate/) without it hands its fields to the next class that is sealed — which then rejects valid input over properties it does not declare, while the class with the real mistake validates nothing. Seal every class that carries field validators.

[validated()](https://imqueue.org/api/validation/latest/validation.validated/) checks arguments without replacing them. The method body receives exactly what the caller passed, so transforming schemas — `z.coerce.number()`, `.trim()`, `.default(...)` — validate as expected and change nothing that reaches the method.

Failures throw Zod's own `ZodError`, unwrapped — but only in-process. Over RPC it does not arrive as an exception at all: `@imqueue/rpc` converts whatever a method throws into its own error payload, so the remote caller sees the code `IMQ_RPC_CALL_ERROR` (a `ZodError` carries no code of its own) with Zod's issue list as the message string, and `instanceof ZodError` never holds there. Zod is the single runtime dependency.

## Example


```typescript
import { z } from 'zod';
import { validatable, validate, validated } from '@imqueue/validation';

@validatable()
class Credentials {
    @validate(z.string().email())
    email!: string;

    @validate(z.string().min(8))
    password!: string;
}

class AuthService {
    @validated(Credentials)
    async signIn(creds: Credentials): Promise<string> {
        return `token-for-${creds.email}`;
    }
}
```

## Functions


| Function | Description |
| --- | --- |
| [schemaOf(target)](https://imqueue.org/api/validation/latest/validation.schemaof/) | The assembled Zod object schema for a [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) class, or `null` when the class contributes no validated fields. |
| [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) | Class decorator that seals the [validate()](https://imqueue.org/api/validation/latest/validation.validate/) fields declared in this class, making them retrievable through [schemaOf()](https://imqueue.org/api/validation/latest/validation.schemaof/). |
| [validate(validator)](https://imqueue.org/api/validation/latest/validation.validate/) | Field decorator that records a validator for one class field, sitting beside `@property` on an `@imqueue/rpc` input class. |
| [validated(validators)](https://imqueue.org/api/validation/latest/validation.validated/) | Method decorator that checks a method's positional arguments before the method body runs — the usual way to validate an `@imqueue/rpc` service method's input. |


## Type Aliases


| Type Alias | Description |
| --- | --- |
| [Ctor](https://imqueue.org/api/validation/latest/validation.ctor/) | Any class constructor, abstract ones included. |
| [Validator](https://imqueue.org/api/validation/latest/validation.validator/) | What [validate()](https://imqueue.org/api/validation/latest/validation.validate/) and [validated()](https://imqueue.org/api/validation/latest/validation.validated/) accept for a single value: a Zod schema, a [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) class whose own field schemas should be used, or `null`/`undefined` to skip validation at that position. |

