Skip to main content

Documentation 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.

The v namespace, imported from baseflare/values, is Baseflare’s validator system. Validators serve three roles: they define the shape of table fields in defineTable(), they declare the argument contracts of server functions in query(), mutation(), and action(), and they specify the expected return value shape via the returns option. At runtime, every value that enters or leaves a Baseflare function is passed through its validator and rejected with a typed ValidationError if it does not conform.

Primitive Validators

ValidatorTypeScript TypeNotes
v.string()stringAny UTF-8 string
v.number()numberMust be finite and non-NaN
v.boolean()booleantrue or false
v.bytes()Uint8ArrayRaw binary data
v.null()nullExactly null
v.any()unknownPasses through any value without validation

Reference Validators

v.id(tableName) validates that a value is a well-formed UUIDv7 string. The TypeScript type is the branded Id<'tableName'>, which prevents accidental cross-table ID usage at compile time.
v.id('todos')   // Id<'todos'>
v.id('users')   // Id<'users'>
The validator checks both UUIDv7 format and that the embedded timestamp is extractable. It does not perform a database round-trip to confirm the document exists.

Composite Validators

ValidatorTypeScript TypeNotes
v.array(inner)T[]Validates every element with inner
v.object(shape)Typed objectRejects unknown keys not in shape
v.record(valueValidator)Record<string, T>Any string keys, values validated by valueValidator
v.union(...members)Union typeTries each member in order; first match wins
v.literal(value)Exact valueAccepts only that specific string, number, or boolean
v.enum([...values])Union of string literalsShorthand for a union of string literals
v.vector({ dimensions })number[]Fixed-length array of finite numbers
v.object strictly validates the set of keys — any key present in the input that is not declared in the shape will cause a validation error. v.record is the right choice when the key set is dynamic. v.union accepts individual validators as spread arguments:
v.union(v.string(), v.number(), v.null())
v.vector requires a dimensions option and validates that the array contains exactly that many finite numbers:
v.vector({ dimensions: 1536 })  // OpenAI ada-002 embedding size

Modifier Methods

Validators expose chainable modifier methods. All modifiers return a new validator — they do not mutate the original.
MethodApplies ToEffect
.optional()AllMakes the field optional in both input and output (T | undefined)
.default(value)AllField is optional in input but always present in output (uses value when undefined)
.min(n)string, number, array, bytes, vectorMinimum length (for strings/arrays/bytes/vectors) or minimum value (for numbers)
.max(n)string, number, array, bytes, vectorMaximum length or maximum value
.searchable()AllMarks the field for full-text search (sets searchable: true in the validator definition)
.integer()number onlyValue must pass Number.isSafeInteger
v.string().min(1).max(280)          // non-empty string, max 280 chars
v.number().min(0).integer()         // non-negative safe integer
v.boolean().default(false)          // optional in input, always present in output
v.array(v.string()).default([])     // defaults to empty array
v.string().optional()               // input and output may be undefined
.default(value) makes the field optional in the input (callers may omit it) but guarantees the field is always present in the output with the provided default when omitted. .optional() makes the field optional in both input and output, meaning the value may be undefined after validation.
Validators are composable — chain .optional(), .default(), .min(), .max() in any order on supported types. For example, v.number().integer().min(0).max(100) is a valid non-negative integer capped at 100.

Using Validators in Functions

The same v namespace is used for both schema field definitions and server function signatures. Pass a ValidatorShape (an object of validators) to args, and an optional single validator to returns:
import { query } from 'baseflare/server'
import { v } from 'baseflare/values'

export const getUser = query({
  args: { id: v.id('users') },
  returns: v.object({ name: v.string(), email: v.string() }),
  async handler(ctx, args) {
    return await ctx.db.get('users', args.id)
  },
})
When returns is provided, Baseflare validates the handler’s return value before sending it to the client. For mutations, if the return value fails validation, the pending writes are not committed. Omitting returns bypasses return-value validation — the value is passed through as unknown.

Build docs developers (and LLMs) love