import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
import { type AST, type Condition, type Parameter, type SimpleOperator, type System } from '../../../zero-protocol/src/ast.ts';
import type { Schema } from '../../../zero-types/src/schema.ts';
import type { Format, ViewFactory } from '../ivm/view.ts';
import { type ExpressionFactory } from './expression.ts';
import type { CustomQueryID } from './named.ts';
import type { QueryDelegate } from './query-delegate.ts';
import { delegateSymbol, type ExistsOptions, type GetFilterType, type HumanReadable, type MaterializeOptions, type PreloadOptions, type PullRow, type Query, type QueryRowType, type QueryTable, type RunOptions } from './query.ts';
import { type TTL } from './ttl.ts';
import type { TypedView } from './typed-view.ts';
export type AnyQuery = Query<Schema, string, any>;
export declare function materialize<S extends Schema, T, Q>(query: Q, delegate: QueryDelegate, factoryOrOptions?: ViewFactory<S, QueryTable<Q>, QueryRowType<Q>, T> | MaterializeOptions | undefined, maybeOptions?: MaterializeOptions | undefined): T | TypedView<{
    [x: string]: any;
}>;
declare const astSymbol: unique symbol;
export declare function ast(query: AnyQuery): AST;
export declare function newQuery<TSchema extends Schema, TTable extends keyof TSchema['tables'] & string>(delegate: QueryDelegate | undefined, schema: TSchema, table: TTable): Query<TSchema, TTable>;
export declare const newQuerySymbol: unique symbol;
export declare abstract class AbstractQuery<TSchema extends Schema, TTable extends keyof TSchema['tables'] & string, TReturn = PullRow<TTable, TSchema>> implements Query<TSchema, TTable, TReturn> {
    #private;
    protected readonly _delegate: QueryDelegate | undefined;
    readonly _ast: AST;
    readonly format: Format;
    readonly customQueryID: CustomQueryID | undefined;
    constructor(delegate: QueryDelegate | undefined, schema: TSchema, tableName: TTable, ast: AST, format: Format, system: System, customQueryID: CustomQueryID | undefined, currentJunction?: string | undefined);
    [delegateSymbol](delegate: QueryDelegate): Query<TSchema, TTable, TReturn>;
    nameAndArgs(name: string, args: ReadonlyArray<ReadonlyJSONValue>): Query<TSchema, TTable, TReturn>;
    get [astSymbol](): AST;
    get ast(): AST;
    hash(): string;
    protected abstract [newQuerySymbol]<TSchema extends Schema, TTable extends keyof TSchema['tables'] & string, TReturn>(delegate: QueryDelegate | undefined, schema: TSchema, table: TTable, ast: AST, format: Format, customQueryID: CustomQueryID | undefined, currentJunction: string | undefined): AbstractQuery<TSchema, TTable, TReturn>;
    one: () => Query<TSchema, TTable, TReturn | undefined>;
    whereExists: (relationship: string, cbOrOptions?: ((q: AnyQuery) => AnyQuery) | ExistsOptions | undefined, options?: ExistsOptions | undefined) => Query<TSchema, TTable, TReturn>;
    related: (relationship: string, cb?: (q: AnyQuery) => AnyQuery) => AnyQuery;
    where: (fieldOrExpressionFactory: string | ExpressionFactory<TSchema, TTable>, opOrValue?: SimpleOperator | GetFilterType<any, any, any> | Parameter, value?: GetFilterType<any, any, any> | Parameter) => Query<TSchema, TTable, TReturn>;
    start: (row: Partial<PullRow<TTable, TSchema>>, opts?: {
        inclusive: boolean;
    } | undefined) => Query<TSchema, TTable, TReturn>;
    limit: (limit: number) => Query<TSchema, TTable, TReturn>;
    orderBy: <TSelector extends keyof TSchema["tables"][TTable]["columns"]>(field: TSelector, direction: "asc" | "desc") => Query<TSchema, TTable, TReturn>;
    protected _exists: (relationship: string, cb: ((query: AnyQuery) => AnyQuery) | undefined, options?: ExistsOptions | undefined) => Condition;
    protected _completeAst(): AST;
    abstract materialize(ttl?: TTL | undefined): TypedView<HumanReadable<TReturn>>;
    abstract materialize<T>(factory: ViewFactory<TSchema, TTable, TReturn, T>, ttl?: TTL | undefined): T;
    abstract run(options?: RunOptions): Promise<HumanReadable<TReturn>>;
    abstract preload(): {
        cleanup: () => void;
        complete: Promise<void>;
    };
}
declare const completedAstSymbol: unique symbol;
export declare function completedAST(q: Query<Schema, string, any>): AST;
export declare class QueryImpl<TSchema extends Schema, TTable extends keyof TSchema['tables'] & string, TReturn = PullRow<TTable, TSchema>> extends AbstractQuery<TSchema, TTable, TReturn> {
    #private;
    constructor(delegate: QueryDelegate | undefined, schema: TSchema, tableName: TTable, ast?: AST, format?: Format, system?: System, customQueryID?: CustomQueryID | undefined, currentJunction?: string | undefined);
    get [completedAstSymbol](): AST;
    protected [newQuerySymbol]<TSchema extends Schema, TTable extends string, TReturn>(delegate: QueryDelegate | undefined, schema: TSchema, tableName: TTable, ast: AST, format: Format, customQueryID: CustomQueryID | undefined, currentJunction: string | undefined): QueryImpl<TSchema, TTable, TReturn>;
    materialize<T>(factoryOrTTL?: ViewFactory<TSchema, TTable, TReturn, T> | TTL, ttl?: TTL): T;
    run(options?: RunOptions): Promise<HumanReadable<TReturn>>;
    preload(options?: PreloadOptions): {
        cleanup: () => void;
        complete: Promise<void>;
    };
}
export {};
//# sourceMappingURL=query-impl.d.ts.map