import { LIVE_QUERY_INTERNAL, LiveQueryInternalUtils } from './internal.js';
import { WindowOptions } from '../compiler/index.js';
import { SchedulerContextId } from '../../scheduler.js';
import { CollectionSubscription } from '../../collection/subscription.js';
import { OrderByOptimizationInfo } from '../compiler/order-by.js';
import { Collection } from '../../collection/index.js';
import { CollectionConfigSingleRowOption, StringCollationConfig, SyncConfig, UtilsRecord } from '../../types.js';
import { Context, GetResult } from '../builder/types.js';
import { BasicExpression, QueryIR } from '../ir.js';
import { LazyCollectionCallbacks } from '../compiler/joins.js';
import { FullSyncState, LiveQueryCollectionConfig } from './types.js';
export type LiveQueryCollectionUtils = UtilsRecord & {
    /** Most recent subset-load failure observed by this live query. */
    readonly lastSubsetError: unknown | undefined;
    /**
     * Sets the offset and limit of an ordered query.
     * Is a no-op if the query is not ordered.
     *
     * @returns `true` if no subset loading was triggered, or `Promise<void>` that resolves when the subset has been loaded
     */
    setWindow: (options: WindowOptions) => true | Promise<void>;
    /**
     * Gets the current window (offset and limit) for an ordered query.
     *
     * @returns The current window settings, or `undefined` if the query is not windowed
     */
    getWindow: () => {
        offset: number;
        limit: number;
    } | undefined;
    [LIVE_QUERY_INTERNAL]: LiveQueryInternalUtils;
};
export declare class CollectionConfigBuilder<TContext extends Context, TResult extends object = GetResult<TContext>> {
    private readonly config;
    private readonly id;
    readonly query: QueryIR;
    private readonly collections;
    private readonly collectionSources;
    private readonly resultKeys;
    private readonly orderByIndices;
    private readonly compare?;
    private readonly compareOptions;
    readonly queryCompareOptions: StringCollationConfig;
    private isGraphRunning;
    private graphInputRevision;
    currentSyncConfig: Parameters<SyncConfig<TResult>[`sync`]>[0] | undefined;
    currentSyncState: FullSyncState | undefined;
    private isInErrorState;
    private fatalQueryError;
    private readonly erroredSourceIds;
    private lastSubsetError;
    liveQueryCollection?: Collection<TResult, any, any>;
    private windowFn;
    private readonly initialWindow;
    private currentWindow;
    private settledWindow;
    private activeWindowOperation;
    private maybeRunGraphFn;
    private loadMoreFn;
    private readonly builderDependencies;
    private graphCache;
    private inputsCache;
    private pipelineCache;
    sourceWhereClausesCache: Map<string, BasicExpression<boolean>> | undefined;
    private bucketFacadesCache;
    readonly subscriptions: Record<string, CollectionSubscription>;
    lazySourcesCallbacks: Record<string, LazyCollectionCallbacks>;
    readonly lazySources: Set<string>;
    private readonly activeDemands;
    private demandGeneration;
    private readonly pendingOrderedLoads;
    private orderedLoadFailed;
    private windowFailed;
    private syncRunGeneration;
    private windowOperationGeneration;
    optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>;
    constructor(config: LiveQueryCollectionConfig<TContext, TResult>);
    /** Direct lexical source Collections, including joins, unions, and includes. */
    getSourceCollections(): ReadonlyArray<Collection<any, any, any>>;
    /**
     * Recursively checks if a query or any of its subqueries contains joins
     */
    private hasJoins;
    getConfig(): CollectionConfigSingleRowOption<TResult> & {
        utils: LiveQueryCollectionUtils;
    };
    setWindow(options: WindowOptions): true | Promise<void>;
    getWindow(): {
        offset: number;
        limit: number;
    } | undefined;
    isLazySource(sourceId: string): boolean;
    beginDemand(planId: string, pending?: boolean): number;
    settleDemand(planId: string, generation: number): void;
    hasPendingJoinedWork(joinedSourceId: string): boolean;
    failDemand(planId: string, generation: number, error: unknown): void;
    recordSubsetError(error: unknown, fatalBeforeReady?: boolean): Error;
    trackSubsetLoadPromise(promise: Promise<unknown>): void;
    trackSubsetLoadOperationPromise(promise: Promise<unknown>): void;
    hasActiveWindowOperation(): boolean;
    getActiveWindowOperationGeneration(): number | undefined;
    scheduleGraphRunIfSyncRunCurrent(syncRunGeneration: number): void;
    trackOrderedLoadPromise(promise: Promise<unknown>, holdPublication?: boolean): void;
    retireDemand(planId: string): void;
    hasPendingSourceRecovery(): boolean;
    private pendingSourceRecovery;
    private hasFailedSourceRecovery;
    getSyncRunGeneration(): number;
    advanceGraphInputRevision(): void;
    getGraphInputRevision(): number;
    maybeRunGraph(): void;
    /**
     * Schedules a graph run with the transaction-scoped scheduler.
     * Ensures each builder runs at most once per transaction, with automatic dependency tracking
     * to run parent queries before child queries. Outside a transaction, runs immediately.
     *
     * Multiple calls during a transaction are coalesced into a single execution.
     * Dependencies are discovered from subscribed live queries.
     *
     * Uses the current sync run's config and syncState from instance properties.
     *
     * @param options - Optional scheduling configuration
     * @param options.contextId - Transaction ID to group work; defaults to active transaction
     */
    scheduleGraphRun(options?: {
        contextId?: SchedulerContextId;
    }): void;
    private getSyncConfig;
    private syncFn;
    private clearSyncRunState;
    /**
     * Compiles the query pipeline with all declared aliases.
     */
    private compileBasePipeline;
    private maybeCompileBasePipeline;
    private extendPipelineWithChangeProcessing;
    private applyChanges;
    /**
     * Handle status changes from source collections
     */
    private handleSourceStatusChange;
    private handleSourceCleanupStart;
    /**
     * Update the live query status based on source collection statuses
     */
    private updateLiveQueryStatus;
    /**
     * Transition the live query to error state
     */
    private transitionToError;
    private setErrorState;
    private allRequiredSourcesReady;
    /**
     * Creates one subscription per lexical collection source.
     * Each source gets independent filters, even when aliases or collections repeat.
     * Example: `{ employee: col, manager: col }` creates two separate subscriptions.
     */
    private subscribeToAllCollections;
}
