Schema
@flare-ts/lib validation primitives, model() DTOs, and JSON serialization.
@flare-ts/lib is Flare’s standard library for parsing, validating, and serializing JSON-shaped data. It ships one module today (./schema): leaf primitives, combinators, schema() and model() builders, and serializers. The package has zero third-party runtime dependencies, so you can use it in any TypeScript project or alongside @flare-ts/core in a Flare app. Core does not re-export schema symbols; import them from @flare-ts/lib or @flare-ts/lib/schema.
These pages teach the workflow. The API Reference owns symbol facts (str, safeParse, compileSerializer, and the rest).
Schema
Section titled “Schema”- Primitives and builders: Leaf primitives, combinators, and the schema() builder for objects, arrays, records, and unions.
- Models (DTOs): model() for named, extendable schema-token classes you reuse in contracts and tests.
- Define a DTO: How-to: define a shape once with model() and use it on bodies, responses, and standalone parse.
- Serialization: compileSerializer and toJsonSchema for fast JSON output and schema export.
Package exports
Section titled “Package exports”| Subpath | Use for |
|---|---|
. (default) | Primitives, schema(), model(), serializers, and related types |
./schema | The identical symbol set; prefer when the import path should name the module |
import { schema, str, int, compileSerializer } from "@flare-ts/lib/schema";Typical Flare usage
Section titled “Typical Flare usage”HTTP contracts and httpContract entries accept SchemaToken and ModelTokenBuilder values for body and response fields; route and query take maps of primitives (int, str, and friends). Inline handlers read parsed values from scope.input; controller methods with httpContract use this.ctx.extract(entry). See HTTP contracts and Tutorial: Your first app.
import { httpContract } from "@flare-ts/core";import { model, str } from "@flare-ts/lib/schema";
class CreateUser extends model({ name: str.min(1), email: str }) {}
const UserApi = httpContract({ create: { body: CreateUser },});