import { type Resolver } from '@rocicorp/resolver';
import { ReplicacheImpl } from '../../../replicache/src/impl.ts';
import type { Puller } from '../../../replicache/src/puller.ts';
import type { Pusher } from '../../../replicache/src/pusher.ts';
import type { ClientGroupID, ClientID } from '../../../replicache/src/sync/ids.ts';
import type { MutatorDefs } from '../../../replicache/src/types.ts';
import type { DeepMerge } from '../../../shared/src/deep-merge.ts';
import type { Enum } from '../../../shared/src/enum.ts';
import { Subscribable } from '../../../shared/src/subscribable.ts';
import { type ClientSchema } from '../../../zero-protocol/src/client-schema.ts';
import type { DeleteClientsBody } from '../../../zero-protocol/src/delete-clients.ts';
import type { UpQueriesPatchOp } from '../../../zero-protocol/src/queries-patch.ts';
import type { NullableVersion } from '../../../zero-protocol/src/version.ts';
import { type Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
import type { ViewFactory } from '../../../zql/src/ivm/view.ts';
import type { QueryDelegate } from '../../../zql/src/query/query-delegate.ts';
import { type HumanReadable, type MaterializeOptions, type PreloadOptions, type Query, type QueryRowType, type QueryTable, type RunOptions } from '../../../zql/src/query/query.ts';
import type { TypedView } from '../../../zql/src/query/typed-view.ts';
import { ActiveClientsManager } from './active-clients-manager.ts';
import * as ConnectionState from './connection-state-enum.ts';
import { type BatchMutator, type DBMutator } from './crud.ts';
import type { CustomMutatorDefs, MakeCustomMutatorInterfaces } from './custom.ts';
import { DeleteClientsManager } from './delete-clients-manager.ts';
import { type HTTPString, type WSString } from './http-string.ts';
import { Inspector } from './inspector/inspector.ts';
import { type LogOptions } from './log-options.ts';
import type { ZeroOptions } from './options.ts';
import { QueryManager } from './query-manager.ts';
import { ZeroLogContext } from './zero-log-context.ts';
type ConnectionState = Enum<typeof ConnectionState>;
export type NoRelations = Record<string, never>;
export type MakeEntityQueriesFromSchema<S extends Schema> = {
    readonly [K in keyof S['tables'] & string]: Query<S, K>;
};
export type TestingContext = {
    puller: Puller;
    pusher: Pusher;
    setReload: (r: () => void) => void;
    logOptions: LogOptions;
    connectStart: () => number | undefined;
    socketResolver: () => Resolver<WebSocket>;
    connectionState: () => ConnectionState;
};
export declare const onSetConnectionStateSymbol: unique symbol;
export declare const exposedToTestingSymbol: unique symbol;
export declare const createLogOptionsSymbol: unique symbol;
export declare const RUN_LOOP_INTERVAL_MS = 5000;
/**
 * How frequently we should ping the server to keep the connection alive.
 */
export declare const PING_INTERVAL_MS = 5000;
/**
 * The amount of time we wait for a pong before we consider the ping timed out.
 */
export declare const PING_TIMEOUT_MS = 5000;
/**
 * The amount of time we wait for a pull response before we consider a pull
 * request timed out.
 */
export declare const PULL_TIMEOUT_MS = 5000;
export declare const DEFAULT_DISCONNECT_HIDDEN_DELAY_MS = 5000;
/**
 * The amount of time we wait for a connection to be established before we
 * consider it timed out.
 */
export declare const CONNECT_TIMEOUT_MS = 10000;
export interface ReplicacheInternalAPI {
    lastMutationID(): number;
}
export declare function getInternalReplicacheImplForTesting(z: object): ReplicacheImpl<MutatorDefs>;
export declare class Zero<const S extends Schema, MD extends CustomMutatorDefs | undefined = undefined> {
    #private;
    readonly version: string;
    readonly userID: string;
    readonly storageKey: string;
    readonly queryDelegate: QueryDelegate;
    readonly query: MakeEntityQueriesFromSchema<S>;
    /**
     * Constructs a new Zero client.
     */
    constructor(options: ZeroOptions<S, MD>);
    preload(query: Query<S, keyof S['tables'] & string, any>, options?: PreloadOptions | undefined): {
        cleanup: () => void;
        complete: Promise<void>;
    };
    run<Q>(query: Q, runOptions?: RunOptions | undefined): Promise<HumanReadable<QueryRowType<Q>>>;
    materialize<Q>(query: Q, options?: MaterializeOptions | undefined): TypedView<HumanReadable<QueryRowType<Q>>>;
    materialize<T, Q>(query: Q, factory: ViewFactory<S, QueryTable<Q>, QueryRowType<Q>, T>, options?: MaterializeOptions | undefined): T;
    /**
     * The server URL that this Zero instance is configured with.
     */
    get server(): HTTPString | null;
    /**
     * The name of the IndexedDB database in which the data of this
     * instance of Zero is stored.
     */
    get idbName(): string;
    /**
     * The schema version of the data understood by this application.
     * See [[ZeroOptions.schemaVersion]].
     */
    get schemaVersion(): string;
    /**
     * The client ID for this instance of Zero. Each instance
     * gets a unique client ID.
     */
    get clientID(): ClientID;
    get clientGroupID(): Promise<ClientGroupID>;
    /**
     * Provides simple "CRUD" mutations for the tables in the schema.
     *
     * Each table has `create`, `set`, `update`, and `delete` methods.
     *
     * ```ts
     * await zero.mutate.issue.create({id: '1', title: 'First issue', priority: 'high'});
     * await zero.mutate.comment.create({id: '1', text: 'First comment', issueID: '1'});
     * ```
     *
     * The `update` methods support partials. Unspecified or `undefined` fields
     * are left unchanged:
     *
     * ```ts
     * // Priority left unchanged.
     * await zero.mutate.issue.update({id: '1', title: 'Updated title'});
     * ```
     */
    readonly mutate: MD extends CustomMutatorDefs ? S['enableLegacyMutators'] extends false ? MakeCustomMutatorInterfaces<S, MD> : DeepMerge<DBMutator<S>, MakeCustomMutatorInterfaces<S, MD>> : DBMutator<S>;
    /**
     * Provides a way to batch multiple CRUD mutations together:
     *
     * ```ts
     * await zero.mutateBatch(m => {
     *   await m.issue.create({id: '1', title: 'First issue'});
     *   await m.comment.create({id: '1', text: 'First comment', issueID: '1'});
     * });
     * ```
     *
     * Batch sends all mutations in a single transaction. If one fails, all are
     * rolled back together. Batch can also be more efficient than making many
     * individual mutations.
     *
     * `mutateBatch` is not allowed inside another `mutateBatch` call. Doing so
     * will throw an error.
     */
    readonly mutateBatch: BatchMutator<S>;
    /**
     * Whether this Zero instance has been closed.
     *
     * Once a Zero instance has been closed it no longer syncs, you can no
     * longer query or mutate data with it, and its query views stop updating.
     */
    get closed(): boolean;
    /**
     * Closes this Zero instance.
     *
     * Once a Zero instance has been closed it no longer syncs, you can no
     * longer query or mutate data with it, and its query views stop updating.
     */
    close(): Promise<void>;
    /**
     * A rough heuristic for whether the client is currently online and
     * authenticated.
     */
    get online(): boolean;
    /**
     * Subscribe to online status changes.
     *
     * This is useful when you want to update state based on the online status.
     *
     * @param listener - The listener to subscribe to.
     * @returns A function to unsubscribe the listener.
     */
    onOnline: (listener: (online: boolean) => void) => (() => void);
    /**
     * `inspector` is an object that can be used to inspect the state of the
     * queries a Zero instance uses. It is intended for debugging purposes.
     */
    get inspector(): Inspector;
}
export declare class OnlineManager extends Subscribable<boolean> {
    #private;
    setOnline(online: boolean): void;
    get online(): boolean;
}
export declare function createSocket(rep: ReplicacheImpl, queryManager: QueryManager, deleteClientsManager: DeleteClientsManager, socketOrigin: WSString, baseCookie: NullableVersion, clientID: string, clientGroupID: string, clientSchema: ClientSchema, userID: string, auth: string | undefined, lmid: number, wsid: string, debugPerf: boolean, lc: ZeroLogContext, userPushURL: string | undefined, userQueryURL: string | undefined, additionalConnectParams: Record<string, string> | undefined, activeClientsManager: Pick<ActiveClientsManager, 'activeClients'>, maxHeaderLength?: number): Promise<[
    WebSocket,
    Map<string, UpQueriesPatchOp> | undefined,
    DeleteClientsBody | undefined
]>;
export {};
//# sourceMappingURL=zero.d.ts.map