Schema
API reference for the Schema class
Constructor
new Schema(config: SchemaConfig)
Throws SchemaError on invalid config (no version, no collections, empty collection,
index referencing nonexistent field).
Properties
schema.version: number
schema.collections: Readonly<Record<string, CollectionSchema>>
Methods
getIndexes()
getIndexes(collectionName: string): IndexDefinition[]
Returns the defined indexes for a collection, or [].
getRelations()
getRelations(collectionName: string): Record<string, RelationDefinition> | undefined
Returns relation definitions for a collection, or undefined.
getSearchableFields()
getSearchableFields(collectionName: string): string[]
Returns searchable field names for FTS, or [].
applyDefaults()
applyDefaults(collectionName: string, data: Record<string, unknown>): Record<string, unknown>
Fills in default values for missing fields. Defaults can be functions.
validate()
validate(collectionName: string, data: Record<string, unknown>): void
Throws ValidationError on:
- Missing required fields
- Type mismatch (including array item types)
- String exceeds maxLength
- Number below min or above max
- Invalid email/URL format
- Regex failure
- Undefined fields (not in schema)
The id field is exempt from the undefined-field check.
How is this guide?
Last updated on Jun 20, 2026