export type SyncAppliedSequenceRow = { /** * - Resource identifier the change applied to. */ resourceId: string; /** * - Resource/model name the change applied to. */ resourceType: string; /** * - Highest applied server sequence for the resource. */ serverSequence: number; /** * - Physical store identity owning this row. */ storeIdentity: string; }; /** * Framework-owned local bookkeeping of the newest server change sequence * already applied to each record. * * The server change feed is at-least-once: a realtime push does not advance a * pull cursor, so the next pull re-delivers the same `serverSequence`, and a * resumed page can repeat a row. Applying such a duplicate after a newer local * provisional write used to let the older server payload win. Tracking the * highest applied sequence per record makes the applier idempotent: a change at * or below the recorded sequence is skipped, while any higher sequence still * applies. * * Backed by an auto-created `velocious_sync_applied_sequences` table on the * configured database, with a process-local memory fallback when no database is * configured (mirroring the scope store). */ export default class SyncAppliedSequenceStore { configuration: import("../configuration.js").default; databaseIdentifier: string; tenantHandle: import("../tenants/tenant-handle.js").default | undefined; storeIdentity: string; /** @type {Map} */ _memorySequences: Map; /** @type {Map>} */ _writeQueues: Map>; _isReady: boolean; /** @type {Promise | null} */ _readyPromise: Promise | null; /** @type {WeakMap, promise: Promise}>} */ _transactionReadyPromises: WeakMap; promise: Promise; }>; /** * Creates an applied-sequence store. * @param {object} args - Options. * @param {import("../configuration.js").default} args.configuration - Configuration owning the database. * @param {string} [args.databaseIdentifier] - Database identifier. * @param {import("../tenants/tenant-handle.js").default} [args.tenantHandle] - Immutable tenant handle owning the physical store. */ constructor({ configuration, databaseIdentifier, tenantHandle }: { configuration: import("../configuration.js").default; databaseIdentifier?: string; tenantHandle?: import("../tenants/tenant-handle.js").default; }); /** * Ensures the backing table exists. * @param {{operation?: import("../database/operation.js").default | null}} [args] - Optional caller-owned operation. * @returns {Promise} Resolves when ready. */ ensureReady({ operation }?: { operation?: import("../database/operation.js").default | null; }): Promise; /** * Returns the highest server sequence already applied to a record. * @param {{resourceType: string, resourceId: string, operation?: import("../database/operation.js").default | null}} identity - Resource identity and optional caller-owned operation. * @returns {Promise} Applied sequence, or null when none is recorded. */ lastAppliedSequence({ resourceId, resourceType, operation }: { resourceType: string; resourceId: string; operation?: import("../database/operation.js").default | null; }): Promise; /** * Records a successfully applied server sequence for a record, keeping only * the highest value. Writes for the same record are serialized in-process so * concurrent pull/realtime applies cannot move the watermark backwards. * @param {{resourceType: string, resourceId: string, serverSequence: number, operation?: import("../database/operation.js").default | null}} args - Applied change identity, sequence and optional caller-owned operation. * @returns {Promise} Resolves when recorded. */ recordAppliedSequence({ resourceId, resourceType, serverSequence, operation }: { resourceType: string; resourceId: string; serverSequence: number; operation?: import("../database/operation.js").default | null; }): Promise; /** * Applies one serialized watermark write. * @param {{identity: {resourceType: string, resourceId: string}, key: string, serverSequence: number, operation?: import("../database/operation.js").default | null}} args - Write args. * @returns {Promise} Resolves when written. */ _recordSequential({ identity, key, serverSequence, operation }: { identity: { resourceType: string; resourceId: string; }; key: string; serverSequence: number; operation?: import("../database/operation.js").default | null; }): Promise; /** * Coordinates durable and transaction-local readiness on one connection. * @param {import("../database/drivers/base.js").default} db - Database connection. * @returns {Promise} Resolves when this caller can use the table. */ _ensureReadyWithDb(db: import("../database/drivers/base.js").default): Promise; /** * Whether the store runs without a configured database. * @returns {boolean} Whether memory storage is used. */ _usesMemoryStorage(): boolean; /** * Runs a callback with a database connection. * * A caller that already owns an operation on this store's physical database * must hand it in: taking a second checkout from the same physical database * would queue behind the operation the caller is running inside and wait * behind itself. * @template Result * @param {(db: import("../database/drivers/base.js").default) => Promise} callback - Database callback. * @param {import("../database/operation.js").default | null} [operation] - Caller-owned operation to run on. * @returns {Promise} Callback result. */ _withDb(callback: (db: import("../database/drivers/base.js").default) => Promise, operation?: import("../database/operation.js").default | null): Promise; /** * Fails closed when a caller hands in an operation that does not belong to this store's database. * @param {import("../database/operation.js").default} operation - Caller-owned operation. * @returns {void} Nothing when the operation matches the store. * @throws {Error} When the operation belongs to another database or another physical tenant database. */ assertOperationOwnership(operation: import("../database/operation.js").default): void; /** * Ensures the applied-sequences table exists. * @param {import("../database/drivers/base.js").default} db - Database connection. * @returns {Promise} Whether the table had to be created. */ _ensureTable(db: import("../database/drivers/base.js").default): Promise; /** * Resolves the stored row for one resource identity. * @param {import("../database/drivers/base.js").default} db - Database connection. * @param {{resourceType: string, resourceId: string}} identity - Resource identity. * @returns {Promise} Stored row, or null. */ _rowByResource(db: import("../database/drivers/base.js").default, identity: { resourceType: string; resourceId: string; }): Promise; } //# sourceMappingURL=sync-applied-sequence-store.d.ts.map