Skip to content

Commit 46fac0f

Browse files
committed
refactor: AttachmentQueue options as immutable config and improve logger assignment
1 parent 4946f37 commit 46fac0f

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

packages/common/src/attachments/AttachmentQueue.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
2121
*/
2222
export class AttachmentQueue {
2323
/** Timer for periodic synchronization operations */
24-
periodicSyncTimer?: ReturnType<typeof setInterval>;
24+
readonly periodicSyncTimer?: ReturnType<typeof setInterval>;
2525

2626
/** Context for managing attachment records in the database */
27-
context: AttachmentContext;
27+
readonly context: AttachmentContext;
2828

2929
/** Service for synchronizing attachments between local and remote storage */
30-
syncingService: SyncingService;
30+
readonly syncingService: SyncingService;
3131

3232
/** Adapter for local file storage operations */
33-
localStorage: LocalStorageAdapter;
33+
readonly localStorage: LocalStorageAdapter;
3434

3535
/** Adapter for remote file storage operations */
36-
remoteStorage: RemoteStorageAdapter;
36+
readonly remoteStorage: RemoteStorageAdapter;
3737

3838
/**
3939
* Callback function to watch for changes in attachment references in your data model.
@@ -42,31 +42,31 @@ export class AttachmentQueue {
4242
* data that reference attachments. When attachments are added, removed, or modified,
4343
* this callback should trigger the onUpdate function with the current set of attachments.
4444
*/
45-
watchAttachments: (
45+
readonly watchAttachments: (
4646
onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>,
4747
signal: AbortSignal
4848
) => void;
4949

5050
/** Name of the database table storing attachment records */
51-
tableName?: string;
51+
readonly tableName?: string;
5252

5353
/** Logger instance for diagnostic information */
54-
logger?: ILogger;
54+
readonly logger: ILogger;
5555

5656
/** Interval in milliseconds between periodic sync operations. Default: 30000 (30 seconds) */
57-
syncIntervalMs: number = 30 * 1000;
57+
readonly syncIntervalMs: number = 30 * 1000;
5858

5959
/** Duration in milliseconds to throttle sync operations */
60-
syncThrottleDuration: number;
60+
readonly syncThrottleDuration: number;
6161

6262
/** Whether to automatically download remote attachments. Default: true */
63-
downloadAttachments: boolean = true;
63+
readonly downloadAttachments: boolean = true;
6464

6565
/** Maximum number of archived attachments to keep before cleanup. Default: 100 */
66-
archivedCacheLimit: number;
66+
readonly archivedCacheLimit: number;
6767

6868
/** Service for managing attachment-related database operations */
69-
attachmentService: AttachmentService;
69+
readonly attachmentService: AttachmentService;
7070

7171
watchActiveAttachments: DifferentialWatchedQuery<AttachmentRecord>;
7272

@@ -120,16 +120,10 @@ export class AttachmentQueue {
120120
this.syncThrottleDuration = syncThrottleDuration;
121121
this.archivedCacheLimit = archivedCacheLimit;
122122
this.downloadAttachments = downloadAttachments;
123-
this.context = new AttachmentContext(db, tableName, logger ?? db.logger, archivedCacheLimit);
124-
this.attachmentService = new AttachmentService(db, logger ?? db.logger, tableName);
125-
this.syncingService = new SyncingService(
126-
this.context,
127-
localStorage,
128-
remoteStorage,
129-
logger ?? db.logger,
130-
errorHandler
131-
);
132123
this.logger = logger ?? db.logger;
124+
this.context = new AttachmentContext(db, tableName, this.logger, archivedCacheLimit);
125+
this.attachmentService = new AttachmentService(db, this.logger, tableName);
126+
this.syncingService = new SyncingService(this.context, localStorage, remoteStorage, this.logger, errorHandler);
133127
}
134128

135129
/**

0 commit comments

Comments
 (0)