/** * AST transform that applies a {@link RoleRouter}. * * Role identifiers surface in many statement forms. Most flow through a single * `RoleSpec` node (grantees, ownership `... OWNER TO`, `CREATE POLICY ... TO`, * `ALTER DEFAULT PRIVILEGES [FOR ROLE ...] ... TO`, `ALTER ROLE`, `DROP ROLE`, * role-membership grantees, `GRANTED BY`, `REASSIGN OWNED BY`), which the * traversal reaches automatically. Four positions carry a role name outside a * `RoleSpec` and are handled explicitly: * * - `CREATE ROLE ` — a bare string on `CreateRoleStmt.role`. * - `GRANT TO ...` — the *granted* roles are `AccessPriv.priv_name` * strings on `GrantRoleStmt.granted_roles` (not `RoleSpec`s). * - `SET ROLE` / `SET SESSION AUTHORIZATION` — the role is a string constant * in `VariableSetStmt.args`. * - `ALTER ROLE RENAME TO ` — `RenameStmt` with string * `subname`/`newname`. * * Reserved role specifications (`PUBLIC`, `CURRENT_USER`, `SESSION_USER`, ...) * carry no `rolename` and a non-`CSTRING` `roletype`, so they are never * rewritten. */ import type { RoleRouteSpec } from './role-router'; import { RoleRouter } from './role-router'; /** What a role transform changed: role name -> number of positions rewritten. */ export interface RoleTransformResult { rolesRenamed: Map; } export declare function createRoleResult(): RoleTransformResult; /** * Create a SQL AST visitor that renames role identifiers against a router. * Composable with the walkers used by the core transform. */ export declare function createRoleVisitor(router: RoleRouter, result: RoleTransformResult): { RoleSpec: (path: any) => void; CreateRoleStmt: (path: any) => void; GrantRoleStmt: (path: any) => void; VariableSetStmt: (path: any) => void; RenameStmt: (path: any) => void; }; /** * Apply role renaming to a SQL string: parse -> walk -> deparse. Role names in * PL/pgSQL / `LANGUAGE sql` bodies are string literals (e.g. inside dynamic * `EXECUTE`) and are intentionally not rewritten — see the module docs on why * arbitrary string contents are out of scope. */ export declare function transformRoles(sql: string, router: RoleRouter | RoleRouteSpec | Map): { sql: string; result: RoleTransformResult; };