import type { IToken } from "chevrotain";
import type { LixEngine } from "../../boot.js";
import { type CompoundSelectNode, type ExpressionNode, type RawFragmentNode, type SelectStatementNode } from "../sql-parser/nodes.js";
import type { CelEnvironment } from "../../cel-environment/cel-environment.js";
import type { LixSchemaDefinition } from "../../../schema-definition/definition.js";
export declare const escapeSqlString: (input: string) => string;
export declare const literal: (value: unknown) => string;
/**
 * Result emitted by entity view rewriters. When null is returned the
 * preprocessor should fall back to executing the original statement.
 */
export type RewriteResult = {
    sql: string;
};
export type ExpressionValue = {
    kind: "expression";
    sql: string;
};
export declare const isExpressionValue: (value: unknown) => value is ExpressionValue;
export declare function deserializeJsonParameter(value: unknown): unknown;
export declare function buildColumnValueMap(columns: readonly string[], values: readonly unknown[]): Map<string, unknown> | null;
export declare function buildColumnExpressionMap(columns: readonly string[], expressions: readonly string[]): Map<string, string> | null;
/**
 * Builds a map from lower-case property names to their canonical casing.
 *
 * @example
 * ```ts
 * const lookup = buildPropertyLookup(schema);
 * lookup.get("name"); // => "name"
 * ```
 */
export declare function buildPropertyLookup(schema: LixSchemaDefinition): Map<string, string>;
/**
 * Finds the index of a keyword in a token stream, starting at a given offset.
 */
export declare function findKeyword(tokens: IToken[], start: number, keyword: string): number;
/**
 * Extracts the SQL identifier name from either a quoted or unquoted token.
 */
export declare function extractIdentifier(token: IToken | undefined): string | null;
/**
 * Categorises an entity view by its suffix (base, _by_version, or _history).
 */
export type EntityViewVariant = "base" | "by_version" | "history";
export declare function classifyViewVariant(name: string): EntityViewVariant;
/**
 * Removes variant suffixes from a view name to recover the stored schema key.
 */
export declare function baseSchemaKey(name: string): string | null;
/**
 * Returns true if a specific view variant is enabled for the schema.
 */
export declare function isEntityViewVariantEnabled(schema: LixSchemaDefinition, variant: "base" | "by_version" | "history"): boolean;
export declare function resolveStoredSchemaKey(schema: LixSchemaDefinition, fallbackKey: string): string;
export declare function loadLixSchemaDefinition(engine: Pick<LixEngine, "executeSync" | "runtimeCacheRef" | "hooks">, schemaKey: string): LixSchemaDefinition | null;
/**
 * Extracts the lower-cased primary key fields from a stored schema.
 */
export interface PrimaryKeyDescriptor {
    readonly column: string;
    readonly rootColumn: string;
    readonly path: readonly string[];
}
export declare function extractPrimaryKeys(schema: LixSchemaDefinition): PrimaryKeyDescriptor[] | null;
export interface PointerColumnDescriptor {
    readonly alias: string;
    readonly path: readonly string[];
    readonly matchers: readonly string[];
}
/**
 * Derives column expressions for JSON pointers referenced by a schema's primary key.
 * These descriptors allow entity view rewrites to match WHERE clauses that target
 * nested structures using either the pointer name (e.g. `/value/x-lix-key`) or
 * friendly aliases such as `key`.
 *
 * @example
 * const columns = collectPointerColumnDescriptors({ schema });
 * // columns[0]?.alias === "key"
 * // columns[0]?.expression === `json_extract(snapshot_content, '$.value."x-lix-key"')`
 */
export declare function collectPointerColumnDescriptors(args: {
    schema: LixSchemaDefinition;
    primaryKeys?: PrimaryKeyDescriptor[] | null;
}): PointerColumnDescriptor[];
/**
 * Helper that returns an explicitly provided column value or a fallback default.
 */
export declare function getColumnOrDefault(columnMap: Map<string, unknown>, column: string, defaultValue: unknown): unknown;
/**
 * Evaluates metadata overrides defined via x-lix-override-lixcols. Values that are strings are treated
 * as CEL expressions; other primitive values are passed through unchanged.
 */
export declare function resolveMetadataDefaults(args: {
    defaults: unknown;
    cel: CelEnvironment | null;
    context?: Record<string, unknown>;
}): Map<string, unknown>;
export declare function normalizeOverrideValue(value: unknown): unknown;
export declare function buildSnapshotObjectExpression(args: {
    schema: LixSchemaDefinition;
    columnMap: Map<string, unknown>;
    columnExpressions: Map<string, string>;
    literal: (value: unknown) => string;
    cel: CelEnvironment | null;
    context: Record<string, unknown>;
    resolvedDefaults: Map<string, unknown>;
}): string;
export declare function buildCelContext(args: {
    columnMap: Map<string, unknown>;
    propertyLowerToActual: Map<string, string>;
}): Record<string, unknown>;
export declare function renderPointerExpression(args: {
    descriptor: PrimaryKeyDescriptor;
    columnMap: Map<string, unknown>;
    columnExpressions: Map<string, string>;
}): string | null;
export declare function renderDefaultSnapshotValue(args: {
    propertyName: string;
    definition: unknown;
    literal: (value: unknown) => string;
    cel: CelEnvironment | null;
    context: Record<string, unknown>;
    resolvedDefaults: Map<string, unknown>;
}): string;
export declare function renderSnapshotValue(args: {
    definition: unknown;
    value: unknown;
    expression: string | null;
}): string;
export declare function resolveSchemaDefinition(storedSchemas: Map<string, unknown>, viewName: string): LixSchemaDefinition | null;
export type ResolvedEntityView = {
    readonly schema: LixSchemaDefinition;
    readonly variant: Exclude<EntityViewVariant, "history">;
    readonly storedSchemaKey: string;
    readonly propertyLowerToActual: Map<string, string>;
};
export declare function resolveEntityView(args: {
    storedSchemas?: Map<string, unknown>;
    viewName: string | null;
    rejectImmutable?: boolean;
}): ResolvedEntityView | null;
export type EqualityCondition = {
    readonly column: string;
    readonly expression: ExpressionNode;
};
export declare function collectEqualityConditions(whereClause: ExpressionNode | RawFragmentNode | null): EqualityCondition[];
export declare function collectPrimaryKeyEqualityExpressions(args: {
    whereClause: ExpressionNode | RawFragmentNode | null;
    primaryKeys: PrimaryKeyDescriptor[] | null;
}): string[] | null;
export declare function buildEntityIdExpressionFromEquality(parts: readonly string[] | null): string | null;
export type PredicateRewriteResult = {
    expression: ExpressionNode | null;
    hasVersionReference: boolean;
    usesJsonProperty: boolean;
};
export declare function rewriteViewWhereClause(whereClause: ExpressionNode | RawFragmentNode | null, options: {
    propertyLowerToActual: Map<string, string>;
    stateTableAlias: string;
    pointerAliasToPath?: Map<string, readonly string[]>;
    pushdownableJsonProperties?: ReadonlySet<string>;
    rewriteSubqueryStatement?: (statement: SelectStatementNode | CompoundSelectNode) => SelectStatementNode | CompoundSelectNode;
}): PredicateRewriteResult | null;
export declare function combineWithAnd(left: ExpressionNode, right: ExpressionNode): ExpressionNode;
//# sourceMappingURL=shared.d.ts.map