import { type Resolver } from '@rocicorp/resolver'; import type { Cookie } from '../../../replicache/src/cookies.ts'; import { ReplicacheImpl } from '../../../replicache/src/impl.ts'; import type { Puller } from '../../../replicache/src/puller.ts'; import type { Pusher, PusherResult } from '../../../replicache/src/pusher.ts'; import type { ClientGroupID, ClientID } from '../../../replicache/src/sync/ids.ts'; import type { PushRequest } from '../../../replicache/src/sync/push.ts'; import type { MutatorDefs, PokeInternal } from '../../../replicache/src/types.ts'; import type { DeepMerge } from '../../../shared/src/deep-merge.ts'; import type { ReadonlyJSONValue } from '../../../shared/src/json.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 QueryReturn, 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; export type NoRelations = Record; export type MakeEntityQueriesFromSchema = { readonly [K in keyof S['tables'] & string]: Query; }; export type TestingContext = { puller: Puller; pusher: Pusher; setReload: (r: () => void) => void; logOptions: LogOptions; connectStart: () => number | undefined; socketResolver: () => Resolver; 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; export declare class Zero { #private; readonly version: string; readonly userID: string; readonly storageKey: string; readonly queryDelegate: QueryDelegate; /** Resolves after the persisted local DAG has populated the in-memory IVM. */ readonly localHydrationComplete: Promise; readonly query: MakeEntityQueriesFromSchema; /** * Constructs a new Zero client. */ constructor(options: ZeroOptions); preload(query: Query, options?: PreloadOptions | undefined): { cleanup: () => void; complete: Promise; }; run(query: Q, runOptions?: RunOptions | undefined): Promise>>; materialize(query: Q, options?: MaterializeOptions | undefined): TypedView>>; materialize(query: Q, factory: ViewFactory, QueryReturn, 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; /** * 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 : DeepMerge, MakeCustomMutatorInterfaces> : DBMutator; /** * 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; /** * 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; /** * Directly poke data into the Replicache store. This is used by adapters * (e.g., ConvexSyncAdapter) to feed data from an external source of truth * into Zero's local store without going through the WebSocket protocol. */ pokeDirect(poke: PokeInternal): Promise; /** Resolves when every persist queued by pokeDirect so far has landed. */ persistPending(): Promise; /** Refresh this instance from the latest persisted shared-IDB head. */ refresh(): Promise; /** Read adapter-owned metadata stored in the same durable DAG as rows. */ readLocalValue(key: string): Promise; /** * Tell client queries that Convex has authoritatively reconciled these * tables. Local hydration alone deliberately does not imply completeness. */ markTablesReady(tables: readonly (keyof S['tables'] & string)[]): void; /** * Trigger the push loop to send all pending mutations to the server. * Returns a promise that resolves when the push completes. * Used by adapters (e.g., ConvexSyncAdapter) to flush pending mutations * before fetching server state, ensuring the fetch returns up-to-date data. */ push(options?: { now?: boolean; }): Promise; /** * Set an interceptor for the pusher. When set, mutations will be routed * through this interceptor instead of the default WebSocket push logic. * This allows adapters to intercept CRUD operations and route them to * an external backend (e.g., Convex). */ setPusherInterceptor(interceptor: (req: PushRequest, requestID: string) => Promise): void; /** * Get the current cookie from the Replicache store. * Used by adapters to track sync state for poke operations. */ get currentCookie(): Promise; /** * The DURABLE last-mutation-IDs of this client's client group. * * An adapter that supplies its own pokes MUST floor every * `lastMutationIDChanges` entry with this. A poke naming any client — * especially a SIBLING TAB — at a value below what is already durable * wedges `persist` permanently: see `ReplicacheImpl.lastMutationIDs` * for the full mechanism. Session-local bookkeeping cannot substitute, * because it starts empty after every reload and never learns what a * sibling made durable. */ get currentLastMutationIDs(): Promise>; /** * 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 disabled in production builds for security. * It was previously used for debugging but exposed internal table names * and query details that should not be visible to end users. * * @deprecated Inspector is disabled for security reasons. * @throws Error when accessed */ get inspector(): Inspector; } export declare class OnlineManager extends Subscribable { #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 | undefined, activeClientsManager: Pick, maxHeaderLength?: number, connectionSecret?: string | undefined): Promise<[ WebSocket, Map | undefined, DeleteClientsBody | undefined ]>; export {}; //# sourceMappingURL=zero.d.ts.map