You have built this CRUD screen before. Declare it this time.
Give defineFeature a name, a Zod schema and a REST path. You get the list, detail and search queries, create, update and delete mutations that refresh the list, a validated form that saves itself, a table with columns from the schema, and a store, all wired to Pyreon's query, form, table and store packages.
bun add @pyreon/feature - you write
- name · schema · api
defineFeature({ name: 'posts', schema, api: '/api/posts' }). - you get
- 9 hooks, 2 components
useList…useStore, plus<Posts.Field>and<Posts.Table>. - REST shape
GET·POST·PUT /:id·DELETE /:idEvery mutation refreshes the list.- schemas
- Zod, or any Standard SchemaValibot, ArkType,
@pyreon/validatevalidate; fields and columns are read from Zod.
- 1 declaration for list, detail, search, create, update, delete, form, table and storepackages/fundamentals/feature/src/types.ts, Feature interface
- 3 requests for a create, and the list on screen is current: GET, POST, GET.scratch/app/feat.ts, mock fetcher log
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →The resource boilerplate, generated from the schema you already wrote.
One declaration, the whole resource
Posts.useList(),useById(id),useSearch(term),useCreate(),useUpdate(),useDelete(),useForm(),useTable(),useStore(), typed fromz.inferof your schema.The list never goes stale
Create, update and delete invalidate the
['posts']query on success. Add a post and everyuseList()on screen refetches:GET,POST,GET.A form that knows where to send itself
Posts.useForm()starts from the schema's defaults, validates with it, andPOSTs on submit.useForm({ mode: 'edit', id })loads the record first andPUTs instead.Generated, not hidden
Each hook is the real
@pyreon/query,@pyreon/form,@pyreon/tableor@pyreon/storeobject. Take one generated piece and hand-write the next;<Posts.Field>renders one field, so your layout stays yours.
The same screen, before and after.
Query keys, fetchers, invalidation and a resolver, per resource. Then update and delete, the same again.
const PostSchema = z.object({
title: z.string().min(1), body: z.string(), published: z.boolean(),
})
export const usePosts = () =>
useQuery({ queryKey: ['posts'], queryFn: () => fetch('/api/posts').then(json) })
export function useCreatePost() {
const qc = useQueryClient()
return useMutation({
mutationFn: (data: z.infer<typeof PostSchema>) =>
fetch('/api/posts', { method: 'POST', body: JSON.stringify(data) }).then(json),
onSuccess: () => qc.invalidateQueries({ queryKey: ['posts'] }),
})
}
// …usePost, useUpdatePost, useDeletePost
function NewPost() {
const create = useCreatePost()
const { register, handleSubmit, formState: { errors } } = useForm({
resolver: zodResolver(PostSchema),
defaultValues: { title: '', body: '', published: false },
})
return (
<form onSubmit={handleSubmit((v) => create.mutate(v))}>
<input {...register('title')} />
{errors.title && <p>{errors.title.message}</p>}
<textarea {...register('body')} />
<input type="checkbox" {...register('published')} />
<button disabled={create.isPending}>Create</button>
</form>
)
}One declaration. The form validates, posts and refreshes the list on its own.
import { defineFeature } from '@pyreon/feature'
import { z } from 'zod'
export const Posts = defineFeature({
name: 'posts',
api: '/api/posts',
schema: z.object({
title: z.string().min(1), body: z.string(), published: z.boolean(),
}),
})
const NewPost = () => {
const form = Posts.useForm() // POST /api/posts, then the list refetches
return (
<form onSubmit={form.handleSubmit}>
<Posts.Field form={form} name="title" />
<Posts.Field form={form} name="body" />
<Posts.Field form={form} name="published" />
<button disabled={() => form.isSubmitting()}>Create</button>
</form>
)
}What one declaration gives you.
Click a generated member to see what it does. The table on the right uses useList, useCreate and useDelete: add a row and the list refetches.
posts = defineFeature(…)
posts.useCreate · Create mutation (POST /api/posts); invalidates the list on success.
- GET /api/posts0
- POST /api/posts0
- DELETE /api/posts/:id0
| title | published | actions |
|---|
Try an empty title, or one that exists: the schema and the server answer.
What one defineFeature returns.
useList({ page, pageSize, params })A@pyreon/querylist query;pagecan be a signal.useById(id)One record fromGET /api/posts/:id.useSearch(term)Pass a signal; it refetches with?q=when the term changes and waits while it is empty.useCreate/useUpdate/useDeleteMutations that invalidate the feature's queries on success.useForm({ mode, id })A@pyreon/formstate with schema validation; create posts, edit loads the record and puts.useTable(data, { columns })A TanStack Table v9 instance from@pyreon/table, columns from the schema.useStore()A@pyreon/storewith cached items, selection and loading.<Posts.Field>/<Posts.Table>Label, typed control and error for one field; a sortable table with per-column cell overrides.reference(Users)Mark a foreign key to another feature.fields,extractFields,defaultInitialValuesThe schema introspection, for building your own UI.
Things to build with it.
The generated table, a search box bound to useSearch, and a delete button that refreshes the list when it succeeds.
const PostsAdmin = () => {
const term = signal('')
const all = Posts.useList()
const found = Posts.useSearch(term)
const remove = Posts.useDelete()
const rows = () => (term() ? found.data() : all.data()) ?? []
const view = Posts.useTable(rows, { columns: ['title', 'published'] })
return (
<>
<input placeholder="Search" onInput={(e) => term.set(e.currentTarget.value)} />
<Posts.Table
of={view}
cell={{
title: (ctx) => (
<>
{ctx.row.title}
<button onClick={() => remove.mutate((ctx.row as typeof ctx.row & { id: number }).id)}>Delete</button>
</>
),
}}
empty="No posts yet"
/>
</>
)
}Edit mode loads the record, refuses to submit until it has arrived (so blank defaults never overwrite it), and sends PUT /api/posts/:id on save.
const EditPost = (props: { id: number }) => {
const form = Posts.useForm({
mode: 'edit',
id: props.id,
onSuccess: () => toast.success('Saved'),
})
return (
<Show when={() => !form.isLoading()} fallback={<p>Loading…</p>}>
<form onSubmit={form.handleSubmit}>
<Posts.Field form={form} name="title" />
<Posts.Field form={form} name="body" />
<button disabled={() => form.isSubmitting()}>Save</button>
</form>
</Show>
)
}A small surface that generates a large one.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- defineFeature
- reference
- isReference
- useList
- useById
- useSearch
- useCreate
- useUpdate
- useDelete
- useForm
- useTable
- useStore
- queryKey
- Field
- Table
- extractFields
- defaultInitialValues
- createFieldComponent
- createTableComponent
- featureTableFeatures
- Feature
- FeatureConfig
- FeatureFormOptions
- FeatureFormState
- FeatureStore
- FeatureTableOptions
- FeatureTableResult
- InferSchemaValues
- ListOptions
- FieldInfo
- FieldType
Good to know before you start.
Conventional REST under one path
The routes are derived from api: GET /, GET /:id, POST /, PUT /:id, DELETE /:id. Other shapes need a custom fetcher, or the underlying @pyreon/query hooks directly.
Fields and columns come from Zod
Valibot, ArkType and @pyreon/validate schemas validate, but auto form fields, columns and create defaults are read from Zod only. With another schema, pass initialValues and columns; a one-time dev warning says so.
Needs a QueryClientProvider
The generated queries and mutations are @pyreon/query hooks, so mount a QueryClient above them.
On native, the declaration crosses
With a literal field map, iOS and Android get a Codable struct and initialValues. An inline z.object of scalars, with on-device safeParse, follows in the next release. The generated hooks stay web. Native targets are experimental.
What people ask first.
Is this a code generator?
No files are written. defineFeature runs at import time and returns an object whose members are the real query, form, table and store hooks, typed from your schema.
Can I customise one piece?
Yes. Use Posts.useForm() with your own markup, replace one <Posts.Field> with a hand-written input, or skip the generated table and call @pyreon/table with the data from Posts.useList(). Nothing is all-or-nothing.
What about auth headers or a different backend?
Pass fetcher, any function with the fetch signature, to add headers, a base URL or a different transport.
Does it work with Valibot or ArkType?
For validation, yes, through the Standard Schema bridge in @pyreon/validation. For auto fields and columns, use Zod or pass them yourself.
Fifty lines per resource, times every resource. Or one call each.
bun add @pyreon/feature