TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
v namespace is exported from baseflare/values and is the primary validator toolkit used throughout Baseflare. You use it in defineTable() to declare field types, in query(), mutation(), and action() argument shapes to validate incoming data, and in return value contracts to enforce outgoing types. Every validator enforces its constraints at runtime — calling .validate() either returns a typed output or throws a ValidationError — and simultaneously carries full TypeScript type information so your handlers receive correctly-typed arguments without any extra casting.
Import
Primitive Validators
v.string()
Validates that a value is a JavaScript string.
| Type | |
|---|---|
| Input | string |
| Output | string |
.min(n), .max(n), .searchable()
v.number()
Validates that a value is a finite, non-NaN JavaScript number. Rejects Infinity, -Infinity, and NaN.
| Type | |
|---|---|
| Input | number |
| Output | number |
.min(n), .max(n), .integer()
v.boolean()
Validates that a value is a JavaScript boolean (true or false).
| Type | |
|---|---|
| Input | boolean |
| Output | boolean |
v.bytes()
Validates that a value is a Uint8Array. Suitable for binary blobs, hashes, or encrypted payloads.
| Type | |
|---|---|
| Input | Uint8Array |
| Output | Uint8Array |
.min(n), .max(n) (measured in bytes via .byteLength)
v.null()
Validates the exact value null. Commonly used inside v.union() to create nullable fields.
| Type | |
|---|---|
| Input | null |
| Output | null |
v.any()
Accepts any value without type-checking. The TypeScript output type is unknown, so you must narrow the type yourself before using the value.
| Type | |
|---|---|
| Input | unknown |
| Output | unknown |
Prefer a specific validator over
v.any() wherever possible. v.any() disables both runtime validation and TypeScript type narrowing for that field.ID Validator
v.id(tableName)
Validates that a value is a valid UUIDv7 string and brands the TypeScript type with the given table name. The branded Id<TTableName> type prevents accidentally passing an ID from one table where an ID from a different table is expected.
| Type | |
|---|---|
| Input | Id<TTableName> |
| Output | Id<TTableName> |
The name of the table this ID belongs to. Used for the TypeScript brand only — not checked against the schema at runtime.
Composite Validators
v.array(item)
Validates that a value is a JavaScript array where every element passes the given item validator. Each element is validated in order; the error path includes the array index (e.g., value[2]).
| Type | |
|---|---|
| Input | InputOf<TItem>[] |
| Output | OutputOf<TItem>[] |
.min(n), .max(n) (measured in array .length)
The validator to apply to each element of the array.
v.object(shape)
Validates a plain JavaScript object whose keys exactly match shape. Unknown keys are rejected — any key present on the input that is not declared in shape throws a ValidationError. Each value is validated by its corresponding validator in shape.
| Type | |
|---|---|
| Input | ObjectInput<TShape> (required keys required, optional keys optional) |
| Output | ObjectOutput<TShape> |
An object mapping field names to validators.
v.record(valueValidator)
Validates a plain JavaScript object treated as a Record<string, T> — any string keys are allowed, but each value must pass valueValidator. Unlike v.object(), no specific keys are required or checked.
| Type | |
|---|---|
| Input | Record<string, InputOf<TValue>> |
| Output | Record<string, OutputOf<TValue>> |
The validator applied to every value in the record.
v.union(...members)
Validates that a value matches at least one of the given member validators. Members are tried in order; the first one that succeeds wins. If all members fail, a ValidationError is thrown listing all failure reasons.
| Type | |
|---|---|
| Input | InputOf<TMembers[number]> |
| Output | OutputOf<TMembers[number]> |
v.literal(value)
Validates that the value is exactly equal (===) to the given literal. The TypeScript output type is the narrowed literal type.
| Type | |
|---|---|
| Input | TValue (the literal itself) |
| Output | TValue |
The exact value to match. Must be a primitive.
v.enum(values)
Validates that a value is a string matching one of the entries in values. Prefer v.enum() over v.union(v.literal(...), ...) when all variants are strings — it produces a cleaner error message and stores the allowed values in the schema definition.
| Type | |
|---|---|
| Input | TValues[number] |
| Output | TValues[number] |
A non-empty tuple of allowed string values.
v.vector({ dimensions })
Validates a number[] of exactly dimensions elements where every element is a finite, non-NaN number. Used for storing embedding vectors (e.g., from OpenAI or Workers AI) in a Baseflare table.
| Type | |
|---|---|
| Input | number[] |
| Output | number[] |
.min(n), .max(n) (vector lengths are fixed by dimensions, so these are rarely needed)
The exact required length of the vector array.
Optional Helper
v.optional(validator)
Shorthand for validator.optional(). Makes the field optional — the input may be undefined, and the output type becomes T | undefined.
Modifier Methods
All validators expose these chainable modifier methods. Not every modifier is supported by every validator kind — unsupported combinations throw aSchemaError at definition time.
Makes the field optional in input. The output type becomes
T | undefined. When the field is absent, undefined is returned without error.Provides a fallback value when the field is absent from input. Makes the field optional in input but guarantees the output is always
T (never undefined).Validates a minimum. Supported kinds and what is measured:
| Kind | Measured |
|---|---|
string | .length (character count) |
number | numeric value |
array | .length (element count) |
bytes | .byteLength |
vector | .length (element count) |
Validates a maximum, following the same per-kind rules as
.min(n).Schema-level hint that marks a
string field for inclusion in a SQLite FTS5 full-text search index. Has no effect at runtime validation — the hint is read by the schema differ when creating or migrating tables.Available on
v.number() only. Validates that the number passes Number.isSafeInteger(). Combine with .min() and .max() to constrain integer ranges.Validator<TInput, TOutput> Interface
Every value returned by the v namespace implements the Validator interface. The full generic signature is:
Runs the validator against
value. Returns TOutput on success, or throws a ValidationError on failure. The optional path argument is used in the error message to identify where in a nested structure the failure occurred (e.g., "args.address.zip"). Defaults to "value" when called directly.The schema definition object carrying the validator’s kind, constraints (
min, max, integer, searchable), and structural metadata (shape, item, members, etc.). This is read by Baseflare’s schema differ to compute migrations and by the query engine to enforce schema constraints.Exported Utility Types
The following TypeScript types are exported frombaseflare/values alongside the v namespace and Validator interface.
Extracts the output TypeScript type of a validator. Equivalent to
OutputOf<TValidator>. Use this to derive a type from a validator definition without duplicating the type manually.Extracts the input TypeScript type accepted by a validator — i.e., the type that
.validate() takes as its first argument. For optional or default-carrying validators this may be wider than the output type (e.g., string | undefined).Extracts the output TypeScript type produced by a validator on a successful
.validate() call. Identical to Infer<TValidator>.The widest validator type:
Validator<unknown, unknown, ValidatorKind, boolean, boolean>. Used in generic code that accepts any validator regardless of its specific input/output types.The specialised validator interface returned by
v.number(). Extends Validator with the extra .integer() method, and ensures that .min(), .max(), .optional(), .default(), and .searchable() all return a NumberValidator rather than the base Validator type.A string union of all recognised validator kinds:
"string" | "number" | "boolean" | "bytes" | "null" | "id" | "array" | "object" | "record" | "union" | "literal" | "enum" | "vector" | "any".Record<string, AnyValidator> — the type of the shape argument to v.object().The plain-object schema representation stored on
validator.definition. Carries kind, optional, hasDefault, searchable, and optional constraint fields (min, max, integer, dimensions, tableName, value, values, item, members, shape, recordValue).Derives the input object type from a
ValidatorShape. Required keys are those whose validators do not accept undefined; optional keys are those with optional or default validators.Derives the output object type from a
ValidatorShape. Keys backed by an .optional() validator are optional in the output; all others are required.string | number | boolean | null — the set of JavaScript primitives accepted by v.literal().