import { PowerSyncLogger } from '../utils/Logger.js'; import { AttachmentService } from './AttachmentService.js'; import { AttachmentTransportAdapter } from './AttachmentTransportAdapter.js'; import { LocalStorageAdapter } from './LocalStorageAdapter.js'; import { AttachmentRecord } from './Schema.js'; import { AttachmentErrorHandler } from './AttachmentErrorHandler.js'; import { AttachmentContext } from './AttachmentContext.js'; /** * Orchestrates attachment synchronization between local and remote storage. * Handles uploads, downloads, deletions, and state transitions. * * Remote operations (upload/download/delete) go through the {@link AttachmentTransportAdapter}; * local file operations use the {@link LocalStorageAdapter}. * * @internal */ export declare class SyncingService { private attachmentService; private localStorage; private transport; private logger; private errorHandler?; constructor(attachmentService: AttachmentService, localStorage: LocalStorageAdapter, transport: AttachmentTransportAdapter, logger: PowerSyncLogger, errorHandler?: AttachmentErrorHandler); /** * Processes attachments based on their state (upload, download, or delete). * * Each attachment's I/O runs outside the attachment-service mutex, and the row's * state transition is persisted immediately after it completes. This keeps the * mutex available to concurrent `saveFile` / `deleteFile` / watched-attachment * processing while a batch is in flight, and means consumer queries against the * attachments queue see incremental progress instead of one atomic commit at the * end of the batch. * * @param attachments - Array of attachment records to process * @param options - Optional controls. Pass `signal` (an `AbortSignal`) to interrupt * the batch: it is checked between attachments and, once aborted, the * loop exits early — letting `stopSync` stop a running batch within * one attachment's processing time. */ processAttachments(attachments: AttachmentRecord[], options?: { signal?: AbortSignal; }): Promise; /** * Uploads an attachment from local storage to remote storage. * On success, marks as SYNCED. On failure, defers to error handler or archives. * * @param attachment - The attachment record to upload * @returns Updated attachment record with new state * @throws Error if the attachment has no localUri */ uploadAttachment(attachment: AttachmentRecord): Promise; /** * Downloads an attachment from remote storage to local storage. * The destination `localUri` is assigned here and the transport writes the file to it. * On success, marks as SYNCED. On failure, defers to error handler or archives. * * @param attachment - The attachment record to download * @returns Updated attachment record with local URI and new state */ downloadAttachment(attachment: AttachmentRecord): Promise; /** * Deletes an attachment from both remote and local storage. * Removes the remote file, local file (if exists), and the attachment record. * On failure, defers to error handler or archives. * * @param attachment - The attachment record to delete * @param context - Attachment context for database operations * @returns Updated attachment record */ deleteAttachment(attachment: AttachmentRecord, context: AttachmentContext): Promise; /** * Performs cleanup of archived attachments by removing their local files and records. * Errors during local file deletion are logged but do not prevent record deletion. */ deleteArchivedAttachments(context: AttachmentContext): Promise; }