Installation
getValidator
Creates a validation function from a TypeBox schema.Parameters
TObject | TIntersect | TUnion<TObject[]> | TRecord
required
TypeBox schema definition
Ajv
required
AJV validator instance
Returns
Validator<T, R> - Async validation function that returns validated data or throws BadRequest
getDataValidator
Creates validation functions forcreate, update, and patch service methods.
Parameters
TObject | TDataSchemaMap
required
Single schema or map of schemas for each method
Ajv
required
AJV validator instance
Returns
DataValidatorMap - Object with create, update, and patch validators
Behavior
- If only
createis provided,updateuses the same schema patchusescreateschema with no required fields- Schemas are automatically given IDs with
UpdateandPatchsuffixes
StringEnum
Creates a string enum schema from an array of allowed values.Parameters
string[]
required
Array of allowed string values
{ default?: string }
Optional configuration with default value
Returns
TypeBox schema with string enum constraintQuery Syntax Utilities
Utilities to create Feathers query syntax schemas with operators like$gt, $in, etc.
queryProperty
Creates query syntax schema for a single property.TSchema
required
TypeBox schema for the property
{ [key: string]: TSchema }
default:"{}"
Additional query operators to support
$gt,$gte- Greater than (or equal)$lt,$lte- Less than (or equal)$ne- Not equal$in,$nin- In/not in array
queryProperties
Creates query syntax schemas for multiple properties.TObject
required
TypeBox object with properties to create queries for
{ [K in keyof T]?: { [key: string]: TSchema } }
default:"{}"
Per-property additional operators
querySyntax
Creates complete Feathers query schema including$limit, $skip, $sort, $select, $or, and $and.
TObject
required
TypeBox object defining queryable properties
{ [K in keyof T]?: { [key: string]: TSchema } }
default:"{}"
Additional operators per property
ObjectOptions
default:"{ additionalProperties: false }"
TypeBox object options
number
Maximum number of results (minimum: 0)
number
Number of results to skip (minimum: 0)
{ [K in keyof T]?: 1 | -1 }
Sort order for properties (1 = ascending, -1 = descending)
(keyof T)[]
Array of property names to include in results
Array<PropertyQuery>
Array of query objects (OR logic)
Array<PropertyQuery | { $or }>
Array of query objects (AND logic)
sortDefinition
Creates the$sort schema for an object.
TObject
required
TypeBox object to create sort schema for
ObjectIdSchema
Schema for MongoDB ObjectId that accepts string or object formats.objectid: true or object with additional properties
Complete Example
Type Inference
UseStatic from TypeBox for type inference: