import { ObjectQueryParser, type Condition } from "@ucast/core"; import * as instructions from "./instructions.js"; import { createPrismaInterpreter } from "./interpreter.js"; import * as interpreters from "./interpreters.js"; export type Options = { translations?: Record>; }; export function ucastToPrisma( ucast: Record, primary: string, { translations }: Options = {} ): Record { const parsed = "type" in ucast && "value" in ucast && "operator" in ucast ? (ucast as Condition) : new ObjectQueryParser(instructions).parse(ucast); return createPrismaInterpreter(primary, { interpreters, translate: (tbl: string, col: string): [string, string] => { const tbl0 = translations?.[tbl]?.$self || tbl; const col0 = translations?.[tbl]?.[col] || col; return [tbl0, col0]; }, })(parsed); }