Skip to content

DSL Reference

Daniele Zucchelli edited this page Aug 16, 2026 · 3 revisions

This page reflects the exported types in the supplied repository snapshot.

Entry point

compile(db, request, user, role, structure, options?): Promise<CompileResult>
Parameter Type Meaning
db Database | Transaction Supported Drizzle database or transaction
request Request Single structured query or phase collection
user any Application-provided session context
role string Role key used to select permissions
structure Structure Table, endpoint, and policy map
options BuildWhereOptions Currently includes disable_triggers?

Structure

type Structure = Record<string, TableStructure>;

type TableStructure = {
  endpoints: Endpoint[];
  table: any;
};

Endpoint

type EndpointType = "GET" | "PUT" | "POST" | "DELETE";

type Endpoint = {
  type: EndpointType;
  triggers?: TriggerStructure[];
  [role: string]: RolePermissions | typeof NONE | any;
};

Role permissions

type RolePermissions = {
  allowed: FieldPermission;       // alias: allow
  disallowed?: FieldPermission;   // alias: deny
  limit?: number;
  order_by?: string[] | string;
  group_by?: string[] | string;
  returning?: /* field permission object */;
};
type FieldPermission =
  | string
  | string[]
  | { field: string | string[]; where?: WhereCondition };

Presets:

ALL = { allowed: ["*"], disallowed: [] }
ALL_EXCEPT_ID = { allowed: ["*"], disallowed: ["id"] }
NONE = { allowed: [], disallowed: [] }

Request

type Request = StructuredQuery | { phases: QueryPhase[] };

type StructuredQuery = {
  table: keyof Structure;
  type: EndpointType;
  select?: string[] | string;
  join?: Join[];
  where?: WhereCondition;
  data?: Record<string, any> | Record<string, any>[];
  group_by?: string[] | string;
  order_by?: string[] | string;
  returning?: string[] | string;
  limit?: number;
};

Join

type Join = {
  table: keyof Structure;
  type: "INNER" | "LEFT";
  on: Record<string, string> | WhereCondition;
};

Nested conditions

{ and: [condition, condition] }
{ or: [condition, condition] }
{ not: condition }
{ if: { when: condition, do: condition | boolean, else: condition | boolean } }

do and else also accept structured queries or functions in the exported type, but function and structured-query actions are rejected when used as a SQL where condition. Treat action context carefully.

Query phases

type QueryPhase = {
  mode: "TRANSACTION" | "QUERY";
  queries: StructuredQuery[];
};

See Operators, Errors and Results, and Triggers and Extensibility.

← Recipes · Operators →

Clone this wiki locally