Skip to main content

Overview

@woltz/rich-domain-criteria-zod provides Zod schema builders for validating Criteria query parameters. It’s framework-agnostic and works with any HTTP framework that supports Zod validation (Fastify, Express, Hono, tRPC, etc.).

Peer Dependencies

Type-Safe Filters

Define filterable fields with their types and operators

Orderable Fields Whitelist

Control which fields can be used for ordering

Pagination Defaults

Configure default and max pagination values

Framework Agnostic

Works with Fastify, Express, Hono, tRPC, and more

Quick Start


defineFilters

Define which fields can be filtered and their types.

Field Types and Operators

Restricting Operators

You can limit which operators are available for a field:

CriteriaQuerySchema

Creates a complete query schema with filters, ordering, pagination, and search.

Why Whitelist for orderBy?

Not all filterable fields should be orderable:
  • Array fields can’t be ordered
  • Nested relations may not support ordering in your ORM
  • Non-indexed fields could cause performance issues

Query Format

The schema accepts query parameters in this format:
Or as JSON (for POST requests):

PaginatedResponseSchema

Creates a response schema that matches PaginatedResult.toJSON() output.

Framework Integration

Fastify

Express

Hono

tRPC


Complete Example


Type Utilities

InferCriteriaQuery

Extract TypeScript type from a query schema:

OrderEnum

Create order enum type from field names:

API Reference

defineFilters

CriteriaQuerySchema

PaginatedResponseSchema

QueryBuilder Methods