import { a as ClivlyEntitiesConfig } from "./entity-config-OhC4Otkz.cjs"; //#region src/view-compiler.d.ts export declare const DEFAULT_VIEW_PREFIX = "crm_src_"; export interface CompileOptions { /** * Optional tenant-scoping predicate ANDed into every view's WHERE, e.g. * `{ column: "workspace_id", value: "ws_123" }`. Column must exist on the * entity's source table (the compiler does not verify that — validate first). */ orgScope?: { column: string; value: string | number; }; /** * Restrict `runSync` to a single entity's view, for a "test with one * record" dry run. See `runSync`'s `sample` option in `sync-engine.ts`. */ sample?: { entityKey: string; }; /** * Emit views `WITH (security_invoker = true)` so they run with the querying * role's privileges instead of the (owner's) definer privileges — the * default Postgres behaviour, which bypasses the caller's RLS. Defaults to * `true`: the security boundary the product promises. Set `false` only for * hosts on Postgres < 15, which lacks the option. */ securityInvoker?: boolean; /** View name prefix. Defaults to `crm_src_`. */ viewPrefix?: string; } export interface CompiledView { /** Output column names in SELECT order (`id`, mapped fields, then `_ref`s). */ columns: string[]; concept: string; /** `DROP VIEW IF EXISTS …` statement (for teardown / reconfiguration). */ dropSql: string; entityKey: string; /** Resolved role — the entity's `role` or `"primary"`. */ role: string; sourceTable: string; /** `CREATE OR REPLACE VIEW … AS …` statement. */ sql: string; viewName: string; } /** * Translate a driver error from executing a compiled view into something * actionable, or `undefined` when it is not one we recognise (caller rethrows). * * The case that matters: `WITH (security_invoker = true)` needs Postgres 15, * and PG 14 rejects it with sqlstate 22023 naming a Postgres internal * (`reloptions.c`) — no mention of Clivly, the option, or the version. The * compiler cannot catch this itself because the host executes the SQL. */ export declare function explainViewExecutionError(error: unknown): string | undefined; export declare function compileEntityView(config: ClivlyEntitiesConfig, entityKey: string, options?: CompileOptions): CompiledView; /** Compile every entity in the config into its view, in declaration order. */ export declare function compileEntityViews(config: ClivlyEntitiesConfig, options?: CompileOptions): CompiledView[]; /** The outcome of dry-running one entity's compiled view against the host. */ export interface ExplainResult { entityKey: string; /** The runner's error message when `ok` is false. */ error?: string; ok: boolean; /** The compiled view SQL that was run. */ sql: string; } /** * Dry-run each entity's compiled view against the host DB via a caller-provided * `run` function, so `$raw` filter/join fragments — which skip schema validation * (see `validateEntitiesConfig`) — fail loudly *before* the first sync instead of * at sync time. Never throws: each view's outcome is collected into an * `ExplainResult`, so a mapping UI or CLI can show every problem at once. * * `run` should execute the SQL somewhere side-effect-free — e.g. inside a * transaction it rolls back, or by `EXPLAIN`-ing the statement — since the * compiled SQL is a `CREATE OR REPLACE VIEW`. */ export declare function explainEntitiesConfig(config: ClivlyEntitiesConfig, run: (sql: string) => Promise, options?: CompileOptions): Promise; //#endregion