Server API
Client components receive serializable data; everything that reads or writes
the database lives in this entry point. @dashild/core never imports it, so
the client bundle stays small.
import { createDashildRuntime, resolvePolicy, withDashildScope,} from "@dashild/core/server";Runtime
Section titled “Runtime”createDashildRuntime(options) returns the object the panel uses. It needs the
app’s Prisma client, the generated metadata, the resources, the policies, and
(optionally) the action handlers:
export const runtime = createDashildRuntime({ prisma, metadata, resources: panel.resources, policies, locale: panel.locale, actions: resourceActions,});| Method | What it does |
|---|---|
list(resource, raw, user) |
Applies the whitelist, the scope, and the DTO. Returns { rows, total, params }. |
record(resource, id, user) |
One row, scoped and converted, or null. |
formOptions(resource, user, recordId?) |
Enum values and relation options for the form. |
filterOptions(resource, user) |
Enum values and relation labels for the filter bar. |
exportCsv(resource, raw, user) |
CSV of the current view (5,000-row cap). |
importCsv(resource, csv, user) |
Creates rows from CSV (1,000-row cap). |
save({ slug, id?, values }, user) |
Validates, writes, and maps Prisma errors. |
remove({ slug, id }, user) |
Deletes through the policy. |
runAction({ slug, name, id?, values?, data? }, user) |
Runs a declared action handler. |
relationManagers(parent, id, user) |
Loads child tables for the detail page. |
relationAction(input, user) |
Attach, detach, associate, dissociate, delete. |
client(user) |
Prisma extended with the user’s scope; typed unknown. |
client(user) is unknown so core does not depend on your generated client.
Cast it once in app code:
const client = runtime.client(user) as typeof prisma;Policies
Section titled “Policies”| Function | Result |
|---|---|
resolvePolicy(resource, policies, user) |
{ ok: true, policy } or { ok: false, reason }. Reasons: no-policy, no-policies, no-resource-policy, scope-denied. |
canPerform(policy, operation, values?) |
Permission-predicate defaults: create needs an explicit predicate when the scope is not empty; other operations are allowed without one. Authentication and policy resolution still apply. |
canRunAction(policy, action) |
Deny by default when requires has no matching predicate. |
PolicyDeniedError |
Page-loading operations can throw this for denied resources; the panel turns it into a 404. Mutation/action methods may instead return { ok: false }. |
Scoping Prisma
Section titled “Scoping Prisma”import { withDashildScope } from "@dashild/core/server";
const client = prisma.$extends( withDashildScope({ resources, policies, user }),);It applies the resource scope to top-level reads, updates, and deletes. Inserts
and relation includes are not covered; use runtime.client(user) in custom
server code so the policy is applied once per request.
| Function | Purpose |
|---|---|
normalizeListParams(resource, raw) |
Whitelists page, sort, search, and filters. |
buildListQuery(resource, model, params) |
Builds where, orderBy, skip, take, and include from the resource. |
toDTO(row, model, resource, context) |
Applies each field’s dto and flattens relations to { id, display }. |
listContext(metadata, locale) |
The mapping context used by the DTO. |
Writes
Section titled “Writes”| Function | Purpose |
|---|---|
buildWriteSchema(resource, model, context, operation) |
Zod schema from the form fields, rules, and metadata. |
parseWriteInput(resource, model, context, input, operation) |
Returns { ok: true, data } or { ok: false, fieldErrors }. |
toPrismaData(resource, model, context, values, operation) |
Converts values (BigInt, Decimal, DateTime, connect/disconnect). |
flattenZodError(error) |
Field-indexed messages for the form. |
coerceRecordId(field, value) |
Casts a route id to the model’s id type. |
formatPrismaError(error, locale) |
Maps P2002 unique conflicts, P2003 relation conflicts, and P2025 missing records to field errors or a message; other codes use the generic write error. |
DashboardRuntimeOptions, DashboardRuntime, ResolvedPolicy,
PolicyResolution, NormalizedListParams, ListQuery, FormOption,
RelationManagerData, RelationActionInput, RuntimeSaveResult, and
WriteError are exported from the same entry point.