cfastJson
cfastJson<
TData>(grants,schema,data):TData&object
Defined in: packages/actions/src/cfast-json.ts:36
Server-side loader helper that wraps data with table-level permission metadata and serializes dates.
Replaces the manual pattern of calling can() per table and toJSON()
separately. The returned object contains:
- All fields from
data, with Dates converted to ISO strings. _tablePerms: aRecord<tableName, Record<CrudAction, boolean>>map covering every table in the schema.- Each array value in
datais annotated with a non-enumerable_tableNameproperty matching the first table whose SQL name appears as the data key. This allows the client-sideuseCfastLoaderhook to look upcanAdd()for the correct table.
Type Parameters
Section titled “Type Parameters”TData extends Record<string, unknown>
Parameters
Section titled “Parameters”grants
Section titled “grants”Grant[]
The user’s resolved permission grants.
schema
Section titled “schema”A schema map (e.g. import * as schema from "./schema").
TData
The loader data to wrap.
Returns
Section titled “Returns”TData & object
A serializable object with _tablePerms embedded.
Example
Section titled “Example”import { cfastJson } from "@cfast/actions";import * as schema from "../db/schema";
export async function loader({ context }) { const documents = await db.query(documentsTable).findMany().run(); return cfastJson(ctx.auth.grants, schema, { documents });}