AttachmentQueue constructor

AttachmentQueue({
  1. required PowerSyncDatabase db,
  2. required RemoteStorage remoteStorage,
  3. required Stream<List<WatchedAttachmentItem>> watchAttachments(),
  4. required LocalStorage localStorage,
  5. String attachmentsQueueTableName = AttachmentsQueueTable.defaultTableName,
  6. AttachmentErrorHandler? errorHandler,
  7. Duration syncInterval = const Duration(seconds: 30),
  8. int archivedCacheLimit = 100,
  9. Duration syncThrottleDuration = const Duration(seconds: 1),
  10. bool downloadAttachments = true,
  11. Logger? logger,
})

Creates a new attachment queue.

Parameters:

  • db: PowerSync database client.
  • remoteStorage: Adapter which interfaces with the remote storage backend.
  • watchAttachments: A stream generator for the current state of local attachments.
  • localStorage: Provides access to local filesystem storage methods.
  • attachmentsQueueTableName: SQLite table where attachment state will be recorded.
  • errorHandler: Attachment operation error handler. Specifies if failed attachment operations should be retried.
  • syncInterval: Periodic interval to trigger attachment sync operations.
  • archivedCacheLimit: Defines how many archived records are retained as a cache.
  • syncThrottleDuration: Throttles remote sync operations triggering.
  • downloadAttachments: Should attachments be downloaded.
  • logger: Logging interface used for all log operations.

Implementation

factory AttachmentQueue({
  required PowerSyncDatabase db,
  required RemoteStorage remoteStorage,
  required Stream<List<WatchedAttachmentItem>> Function() watchAttachments,
  required LocalStorage localStorage,
  String attachmentsQueueTableName = AttachmentsQueueTable.defaultTableName,
  AttachmentErrorHandler? errorHandler,
  Duration syncInterval = const Duration(seconds: 30),
  int archivedCacheLimit = 100,
  Duration syncThrottleDuration = const Duration(seconds: 1),
  bool downloadAttachments = true,
  Logger? logger,
}) {
  final resolvedLogger = logger ?? db.logger;

  final attachmentsService = AttachmentService(
    db: db,
    logger: resolvedLogger,
    maxArchivedCount: archivedCacheLimit,
    attachmentsQueueTableName: attachmentsQueueTableName,
  );
  final syncingService = SyncingService(
    remoteStorage: remoteStorage,
    localStorage: localStorage,
    attachmentsService: attachmentsService,
    errorHandler: errorHandler,
    syncThrottle: syncThrottleDuration,
    period: syncInterval,
    logger: resolvedLogger,
  );

  return AttachmentQueue._(
    db: db,
    watchAttachments: watchAttachments,
    localStorage: localStorage,
    downloadAttachments: downloadAttachments,
    logger: resolvedLogger,
    attachmentsService: attachmentsService,
    syncingService: syncingService,
  );
}