{order.error.message}
} )} ``` `order.loading` and `zip.loading` are independent. Multi-step forms and most [workflows](https://asasvirtuais.com/docs/workflows.md) are built this way: each step is a form, and its result opens the next. ## Table forms For database operations, use the table forms from `asasvirtuais/forms`. They work like `Form`, run against a table, and update the reactive index when they resolve: - `CreateForm`: creates a row. - `UpdateForm`: updates a row. It sends only the fields in its state (`defaults` plus what `setField` changed), so a one-column, one-click update is just `form.callback({ done: true })`. - `FilterForm`: lists rows from the client, for searches and pagination. It keeps its `result` local. See [The interface](https://asasvirtuais.com/docs/interface.md). --- Source: https://asasvirtuais.com/docs/interface Markdown: https://asasvirtuais.com/docs/interface.md # The interface The interface is how the parts of an asasvirtuais app connect: forms, server actions, table middleware, the database and Zod schemas all interface with one another through the same five operations, `find`, `list`, `create`, `update` and `remove`, typed by the schema. Their results land in a reactive index, and every view of a table follows it. Most of an app is forms on top of tables. ## Schema Each table has a `readable` schema (what the database returns) and a `writable` schema (what a user may send). ```ts // packages/todos/schema.ts import z from 'zod' export const readable = z.object({ id: z.string(), title: z.string(), done: z.boolean(), project: z.string() }) export const writable = readable.pick({ title: true, done: true, project: true }) export const schema = { readable, writable } ``` ```ts // app/schema.ts export const schema = { projects, todos } ``` ## The interface file `app/actions.ts` exposes the database to the forms. Until the [table middleware](https://asasvirtuais.com/docs/middleware.md) is written, it passes straight to the raw interface in `app/db.ts`: ```ts // app/actions.ts 'use server' import { action } from '@/lib/action' import { db } from './db' export const find = action(db.find) export const list = action(db.list) export const create = action(db.create) export const update = action(db.update) export const remove = action(db.remove) ``` Each method receives the `table` it was called for, along with `{ id }`, `{ query }`, `{ data }` or `{ id, data }`, and works on that table only. The row it returns is what lands in the index. ## Errors Next.js hides the message of an error a server action throws in production. So server actions catch it and return `{ error: message }`, and the client throws it again so the forms can show it: ```ts // lib/action.ts import { unstable_rethrow } from 'next/navigation' type Failure = { error: string } export function action(fn: (...args: A) => Promise