Skip to main content

Documentation Index

Fetch the complete documentation index at: https://kubo-47e69177.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

defineAction

defineAction validates input/output at runtime and keeps static typing across server and client usage.

Signature

packages/core/src/defineAction.ts
export function defineAction<TInput, TOutput, TContext = unknown>(
  options: DefineActionOptions<TInput, TOutput, TContext>
): DefinedAction<TInput, TOutput>

Options

OptionTypeRequiredNotes
inputZodType<TInput>YesRuntime input validation
outputZodType<TOutput>NoRuntime output validation
namestringNoUsed by logger
tagsreadonly string[]NoPassed to revalidateTags
beforeAction(args) => void | Promise<void>NoRuns before handler
afterAction(args) => TOutput | void | Promise<TOutput | void>NoRuns after handler, may override result
handler({ input, ctx }) => Promise<TOutput>YesMain implementation

Example

app/actions.ts
import { defineAction } from "@zapaction/core";
import { z } from "zod";

export const updateTodo = defineAction({
  name: "updateTodo",
  input: z.object({ id: z.string(), done: z.boolean() }),
  output: z.object({ id: z.string(), done: z.boolean() }),
  tags: ["todos"],
  handler: async ({ input }) => ({
    id: input.id,
    done: input.done
  })
});

Failure modes

  • Missing context factory throws a runtime error from resolveActionContext.
  • Invalid input/output throws Zod validation errors.
  • Empty tags are ignored by server revalidation.