CLI
CLI
Generate type-safe TypeScript clients from .cerial schema files.
The Cerial CLI reads your .cerial schema files, parses them into an AST, and generates a fully typed TypeScript client. It's the primary tool for turning schema definitions into usable code.
bunx cerial <command> [options]Available Commands
| Command | Description |
|---|---|
generate | Generate TypeScript client from schema files |
format | Format .cerial schema files |
init | Create a config file for your project |
What Gets Generated
Running bunx cerial generate produces a complete client directory containing:
- Types and interfaces for every model, object, tuple, literal, and enum in your schema
- Query builder types (Create, Update, Where, Select, Include, OrderBy)
- Model registry with runtime metadata for the query engine
- Migration statements (DEFINE TABLE, DEFINE FIELD, DEFINE INDEX)
- Client class with a typed proxy for model access
# Generate with a config file (auto-discovered)
bunx cerial generate
# Or specify paths directly
bunx cerial generate -s ./schemas -o ./db-clientHow It Works
The generation process follows a pipeline:
- Schema discovery resolves which
.cerialfiles to process - Parsing converts each file into an AST
- Validation checks for correctness (relation targets, decorator rules, type consistency)
- Type generation produces TypeScript interfaces and derived types
- Model registry encodes runtime metadata for the query builder
- Migration generation creates SurrealQL DEFINE statements
- Client generation writes the
CerialClientclass with its typed proxy - Formatting runs Biome on all output files
- Stale file cleanup removes leftover files from previous generations
Configuration
Cerial supports three ways to tell the CLI where your schemas live and where to put the generated output:
- Config file (
cerial.config.tsorcerial.config.json) defines schema paths, output directories, and connection settings in one place. Best for projects that need repeatable builds. - CLI flags (
-sand-o) let you pass paths directly on the command line. Quick and good for one-off generation. - Convention markers (
schema.cerial,main.cerial, orindex.cerial) tell Cerial "this directory is a schema root" without any config at all.
These approaches can coexist. The configuration page covers the full priority chain and all available options.
Sections
- Generate - The
generatecommand and all its flags - Init - Create a config file with
cerial init - Configuration - Config file formats, schema discovery, defineConfig
- Generated Output - Structure and contents of the generated client
- Formatter - Format
.cerialfiles with configurable style and column alignment - Multi-Schema - Set up multiple independent schemas in one project
- Path Filtering - Control which
.cerialfiles are processed