Skip to content

defineInput

defineInput<S>(schema): InputParser<{ [K in string | number | symbol]: S[K] extends InputField<V> ? V : never }>

Defined in: packages/actions/src/input-schema.ts:265

Builds a typed parser from a InputSchema. The returned function walks every field, collects errors, and either returns the typed object or throws InvalidInputError with all field errors at once.

S extends InputSchema<unknown>

S

InputParser<{ [K in string | number | symbol]: S[K] extends InputField<V> ? V : never }>

import { createAction, defineInput, z } from "@cfast/actions";
const moveCard = createAction({
input: defineInput({
cardId: z.string(),
position: z.integer(), // rejects NaN, fractional, missing
pinned: z.optional(z.boolean()),
}),
handler: (db, input, ctx) =>
db.update(cards).set({ position: input.position }).where(eq(cards.id, input.cardId)),
});