Skip to content

resolveTablePermissions

resolveTablePermissions(grants, schema): Record<string, Record<CrudAction, boolean>>

Defined in: packages/permissions/src/resolve-table-permissions.ts:30

Resolves table-level CRUD permissions for every table in a schema.

Iterates each key in the schema map, extracts its table name, and calls can for each of the four CRUD actions (read, create, update, delete). Returns a flat, serializable map suitable for embedding in loader data and sending to the client.

This is a pure grant-structural check — no database access, no SQL. Row-level where clauses on grants are ignored; the result reflects whether the user has any grant for the action on the table.

Grant[]

The user’s resolved permission grants.

SchemaMap

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

Record<string, Record<CrudAction, boolean>>

A record keyed by SQL table name, each mapping CRUD actions to booleans.

import { resolveTablePermissions } from "@cfast/permissions";
import * as schema from "../db/schema";
const perms = resolveTablePermissions(grants, schema);
// { posts: { read: true, create: true, update: false, delete: false }, ... }