/** * @module postgres/sync * @description Real-time and scheduled sync engine for the SAP PostgreSQL * adapter. Provides cron-like periodic sync and WebSocket-based * live event streaming. * * @category Postgres * @since v0.1.0 * * @example * ```ts * import { SapSyncEngine } from "@synapse-sap/sdk/postgres"; * import { SapPostgres } from "@synapse-sap/sdk/postgres"; * import { SapClient } from "@synapse-sap/sdk"; * import { Pool } from "pg"; * * const pool = new Pool({ connectionString: process.env.DATABASE_URL }); * const sap = SapClient.from(provider); * const pg = new SapPostgres(pool, sap); * const sync = new SapSyncEngine(pg, sap); * * // One-shot full sync * await sync.run(); * * // Periodic sync (every 60 seconds) * sync.start(60_000); * * // Live event streaming via WebSocket * await sync.startEventStream(); * * // Graceful shutdown * await sync.stop(); * ``` */ import type { SapClient } from "../core/client"; import { type GeyserConfig } from "../events/geyser"; import type { SapPostgres, SyncAllResult } from "./adapter"; import type { SyncOptions } from "./types"; /** * @name SapSyncEngine * @description Orchestrates periodic and real-time sync between * Solana on-chain state and the PostgreSQL mirror. * * Two operational modes: * * 1. **Periodic sync** — polls all account types at a configurable * interval and upserts into PostgreSQL. * * 2. **Event streaming** — subscribes to SAP program logs via * WebSocket and inserts events in real-time. * * Both modes can run simultaneously. * * @category Postgres * @since v0.1.0 */ export declare class SapSyncEngine { private readonly pg; private readonly client; private readonly debug; private intervalId; private logSubId; private geyserStream; private running; constructor(pg: SapPostgres, client: SapClient, debug?: boolean); /** * @name run * @description Execute a single full sync cycle. * @param options - Optional sync configuration. * @returns Sync result summary. * @since v0.1.0 */ run(options?: SyncOptions): Promise; /** * @name start * @description Start periodic sync at the given interval. * Safe to call when already running — resets the interval. * * @param intervalMs - Sync interval in milliseconds (default: 60_000). * @param options - Optional sync configuration. * @since v0.1.0 * * @example * ```ts * // Sync every 30 seconds * sync.start(30_000); * ``` */ start(intervalMs?: number, options?: SyncOptions): void; /** * @name stop * @description Stop all sync activity (periodic + event stream). * @since v0.1.0 */ stop(): Promise; private stopInterval; /** * @name startEventStream * @description Subscribe to SAP program logs via WebSocket and * insert parsed events into the `sap_events` table in real-time. * * @since v0.1.0 * * @example * ```ts * // Start streaming events * await sync.startEventStream(); * * // Later, stop the stream * await sync.stopEventStream(); * ``` */ startEventStream(): Promise; /** * @name stopEventStream * @description Unsubscribe from the program log stream (WebSocket or Geyser). * @since v0.1.0 */ stopEventStream(): Promise; /** * @name startGeyserStream * @description Subscribe to SAP program transactions via Yellowstone gRPC * and insert parsed events into the `sap_events` table in real-time. * * Drop-in replacement for {@link startEventStream} with lower latency, * no missed events, and automatic reconnection. * * Requires `@triton-one/yellowstone-grpc` to be installed. * * @param geyserConfig - Yellowstone gRPC connection config. * @since v0.6.3 * * @example * ```ts * await sync.startGeyserStream({ * endpoint: "https://grpc.triton.one", * token: process.env.GEYSER_TOKEN!, * }); * ``` */ startGeyserStream(geyserConfig: GeyserConfig): Promise; /** * @name isRunning * @description Check whether the periodic sync is active. * @since v0.1.0 */ isRunning(): boolean; /** * @name isStreaming * @description Check whether the event stream is active (WebSocket or Geyser). * @since v0.1.0 */ isStreaming(): boolean; private log; } //# sourceMappingURL=sync.d.ts.map