Skip to content

z

const z: 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.

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.

InputField<boolean>

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.

T

(raw) => T

InputField<T>

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: () => InputField<number> = integerField

Integer field. Same semantics as numberField but additionally rejects fractional values. Maps to Drizzle’s integer() columns.

InputField<number>

nullable: <T>(inner) => InputField<T | null> = nullableField

Wraps a field so missing values produce null instead of an error. Use for nullable database columns.

T

InputField<T>

InputField<T | null>

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")).

InputField<number>

optional: <T>(inner) => InputField<T | undefined> = optionalField

Wraps a field so missing values produce undefined instead of an error. Use for genuinely optional inputs.

T

InputField<T>

InputField<T | undefined>

string: () => InputField<string> = stringField

String field. Coerces FormDataEntryValue (which is File | string) to a string. Rejects missing values unless wrapped in optional.

InputField<string>