Skip to content

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: a Record<tableName, Record<CrudAction, boolean>> map covering every table in the schema.
  • Each array value in data is annotated with a non-enumerable _tableName property matching the first table whose SQL name appears as the data key. This allows the client-side useCfastLoader hook to look up canAdd() for the correct table.

TData extends Record<string, unknown>

Grant[]

The user’s resolved permission grants.

SchemaMap

A schema map (e.g. import * as schema from "./schema").

TData

The loader data to wrap.

TData & object

A serializable object with _tablePerms embedded.

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 });
}