Translate an ownership formula to a PostgreSQL RLS USING expression by
recursively transpiling the acorn AST to SQL. Returns null for any JS
construct that has no direct SQL equivalent (function calls, template
literals, etc.), which causes the caller to fall back to disabling RLS.
Magic variable bindings:
user.X → (SELECT "X" FROM "users" WHERE "id" = curUserId)
row.X → "X" (column reference — RLS evaluates per-row implicitly)
id → "id"
a.b (FK traversal, needs fields)
→ "a" IN (SELECT "id" FROM reftable WHERE "b" = curUserId)
Translate an ownership formula to a PostgreSQL RLS USING expression by recursively transpiling the acorn AST to SQL. Returns null for any JS construct that has no direct SQL equivalent (function calls, template literals, etc.), which causes the caller to fall back to disabling RLS.
Magic variable bindings: user.X → (SELECT "X" FROM "users" WHERE "id" = curUserId) row.X → "X" (column reference — RLS evaluates per-row implicitly) id → "id" a.b (FK traversal, needs fields) → "a" IN (SELECT "id" FROM reftable WHERE "b" = curUserId)