@menapo/query
v0.2.0
Published
Server data for kit apps: query("/path") and mutation("METHOD /path") typed from the app's API, cached, deduplicated and refreshed by REST convention, read with useQuery in every framework
Maintainers
Readme
@menapo/query
Server data for kit apps: query("/projects/:id") and
mutation("PATCH /projects/:id") name the app's API by its URLs, typed from
its @menapo/api operations, cached, deduplicated and refreshed by REST
convention, and read with useQuery and useMutation in React, Preact,
Vue, Svelte, Solid and plain code.
Status: built, private until 1.0. The core, mutations with the refresh
convention and optimistic rollback, the types over api's routes,
/server's withClient, the plugin (names, defaults in keys, the generated
Register, the setClient() check, glue for six frameworks), infinite
lists, live, /test and the DevTools panel are implemented and tested;
examples/query-react drives the worked example in Chromium. The release
waits on the owner's review.
// main.ts, step 1: where requests go, with which fetch and headers
setClient(client<App>("/api", { init: { credentials: "include" } }));
// data/projects.ts: no client, no keys
export const project = query("/projects/:id");
export const projects = query("/projects", { previous: true });
export const rename = mutation("PATCH /projects/:id"); // refreshes project { id } and projectsconst { data, error, loading } = useQuery(project, { id });
const { run, pending } = useMutation(rename);- Guide: getting started, then mutations, lists, live data, servers, tests and DevTools.
- Plan: the design, its decisions and measurements.
- Benchmarks:
vp run --filter @menapo/bench bench:query(bench/README.md).
For agents
Entries: @menapo/query (query, mutation, infinite, live, setClient,
useQuery, useMutation, clearQueries, HttpError, inspect),
@menapo/query/server (withClient), @menapo/query/test (testQueries),
@menapo/query/vite (the plugin, required).
Rules most likely to be broken:
- Define
query,infiniteandmutationonce, at the top level of a data module; never inside a component. setClient()once, first, in the browser entry; on a server usewithClient(clientAs(app, request, env), fn).- Import
useQueryanduseMutationfrom@menapo/querywith the Vite plugin installed; the plugin picks the framework. - A route query input holds strings, numbers, booleans and arrays of them; a function query input holds plain JSON-like data.
- A mutation refreshes by URL convention; a sibling path or a function mutation
needs
refresh: [queries].
Read next: Start here, Cookbook, Reference, Troubleshooting.
