Endpoints
Types
Field paths, the context, rows, views and summaries are typed from your schema and relations.
The resource types every field path it can reach, like status, customer.name or orderLines.product.category. The scope builder, request types and generated schemas all use them, so a typo is a type error.
Type a path below. The suggestions and errors are the ones TypeScript gives you.
The scope builder
f in query.scope only accepts paths from the resource's relations. Hover a path to see its type:
engine.defineResource("orders", {
relations: {
customer: true,
orderLines: { with: { product: true } },
},
query: {
scope: (f, ctx) => f.and([f.is("customer.orgId", ctx.orgId), f.isNot("status", "archived")]),
},
});
Completion through relations
Type a prefix and the editor offers the valid continuations:
engine.defineResource("orders", {
relations: {
customer: true,
orderLines: { with: { product: true } },
},
query: {
scope: (f, ctx) => f.is("orderLines.", ctx.orgId),
},
});
A path that doesn't exist
engine.defineResource("orders", {
relations: { customer: true },
query: {
scope: (f, ctx) => f.is("nonExistentField", ctx.orgId),
},
});
The context
.withContext<T>() types the context of every call and the ctx of the scope:
const engine = createQueryEngine({ db, schema, relations }).withContext<{
orgId: string;
userId: string;
}>();
engine.defineResource("orders", {
query: {
scope: (f, ctx) => f.is("status", ctx.orgId),
},
});
Types for your client
| Type | What it is |
|---|---|
typeof resource.$infer.views.<name> | The row type of a view. |
typeof resource.$infer.summary | The summary's result. |
QueryRequestInput | The request a client may send, with optional fields. |
z.infer<typeof responseSchema(...)> | The response, when you validate it with Zod. |
Export them from your server package, or share the request schema, so the client builds requests against the same contract. See the types reference.