z
constz:object
Defined in: packages/actions/src/input-schema.ts:218
Minimal Zod-like field DSL exposed from @cfast/actions. Pair with
defineInput to build a typed parser for an action’s input.
Names match Zod (z.string, z.number, …) so callers familiar with
Zod can read the schema at a glance, but this is intentionally a
tiny standalone implementation so @cfast/actions doesn’t pull in
Zod’s bundle weight on the worker.
Type Declaration
Section titled “Type Declaration”boolean()
Section titled “boolean()”boolean: () =>
InputField<boolean> =booleanField
Boolean field. Accepts the form-typical strings ("true", "false",
"on", "off", "1", "0") plus native booleans from JSON bodies.
Rejects everything else so a typo doesn’t silently coerce to false.
Returns
Section titled “Returns”InputField<boolean>
custom()
Section titled “custom()”custom: <
T>(parser) =>InputField<T> =customField
Custom field — escape hatch for cases the built-in fields don’t cover (enums, regex matches, etc.). The callback receives the raw value and returns either the parsed result or throws to signal failure.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”parser
Section titled “parser”(raw) => T
Returns
Section titled “Returns”InputField<T>
Example
Section titled “Example”const slugField = z.custom<string>((raw) => { if (typeof raw !== "string") throw new Error("must be a string"); if (!/^[a-z0-9-]+$/.test(raw)) throw new Error("must be slug-safe"); return raw;});integer()
Section titled “integer()”integer: () =>
InputField<number> =integerField
Integer field. Same semantics as numberField but additionally
rejects fractional values. Maps to Drizzle’s integer() columns.
Returns
Section titled “Returns”InputField<number>
nullable()
Section titled “nullable()”nullable: <
T>(inner) =>InputField<T|null> =nullableField
Wraps a field so missing values produce null instead of an error.
Use for nullable database columns.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”InputField<T>
Returns
Section titled “Returns”InputField<T | null>
number()
Section titled “number()”number: () =>
InputField<number> =numberField
Number field. The core fix for #159: parses a numeric value and rejects
NaN, Infinity, and unparseable strings outright. Used by every action
handler that previously did Number(formData.get("x")).
Returns
Section titled “Returns”InputField<number>
optional()
Section titled “optional()”optional: <
T>(inner) =>InputField<T|undefined> =optionalField
Wraps a field so missing values produce undefined instead of an error.
Use for genuinely optional inputs.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”InputField<T>
Returns
Section titled “Returns”InputField<T | undefined>
string()
Section titled “string()”string: () =>
InputField<string> =stringField
String field. Coerces FormDataEntryValue (which is File | string) to a
string. Rejects missing values unless wrapped in optional.
Returns
Section titled “Returns”InputField<string>