Skip to main content
The TypeBox integration provides type-safe schema definitions with Feathers-specific utilities for query syntax and validation.

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 for create, update, and patch service methods.

Parameters

TObject | TDataSchemaMap
required
Single schema or map of schemas for each method
Ajv
required
AJV validator instance
TDataSchemaMap:

Returns

DataValidatorMap - Object with create, update, and patch validators

Behavior

  • If only create is provided, update uses the same schema
  • patch uses create schema with no required fields
  • Schemas are automatically given IDs with Update and Patch suffixes

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 constraint

Query 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
Returns: Optional union of direct value or operators object Supported operators:
  • $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
Returns: Optional object with query syntax for each property

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
Returns: TypeBox intersection with query operators and property queries Query operators:
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
Returns: Object schema with optional integer properties (values: -1 or 1)

ObjectIdSchema

Schema for MongoDB ObjectId that accepts string or object formats.
Returns: Union of string with objectid: true or object with additional properties

Complete Example

Type Inference

Use Static from TypeBox for type inference:

Re-exports

All TypeBox types and utilities are re-exported: