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
| Method | Default Operators |
|---|---|
f.string() | equals, notEquals, contains, startsWith, endsWith, in, notIn, isNull, isNotNull |
f.number() | equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, in, notIn, between, isNull, isNotNull |
f.date() | Same as number |
f.boolean() | equals, notEquals, isNull, isNotNull |
f.array.* | in, notIn, isNull, isNotNull |
f.enum() | Set yours custom string value |
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:PaginatedResponseSchema
Creates a response schema that matchesPaginatedResult.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
| Method | Description | Operators |
|---|---|---|
f.string() | String field | equals, notEquals, contains, startsWith, endsWith, in, notIn, isNull, isNotNull |
f.number() | Number field | equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, in, notIn, between, isNull, isNotNull |
f.date() | Date field | Same as number |
f.boolean() | Boolean field | equals, notEquals, isNull, isNotNull |
f.enum() | Enum values | Array with string values |
f.array.string() | String array | in, notIn, isNull, isNotNull |
f.array.number() | Number array | in, notIn, isNull, isNotNull |
f.array.boolean() | Boolean array | in, notIn, isNull, isNotNull |
f.array.date() | Date array | in, notIn, isNull, isNotNull |
f.array.enum(values) | Enum array | in, notIn, isNull, isNotNull |
f.array.of(schema) | Custom schema array | in, notIn, isNull, isNotNull |