@@ -2,47 +2,58 @@ import { AbstractPowerSyncDatabase, ILogger } from '@powersync/common';
2
2
import { AttachmentContext } from './AttachmentContext.js' ;
3
3
import { LocalStorageAdapter } from './LocalStorageAdapter.js' ;
4
4
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js' ;
5
- import { AttachmentRecord , AttachmentState } from './Schema.js' ;
5
+ import { ATTACHMENT_TABLE , AttachmentRecord , AttachmentState } from './Schema.js' ;
6
6
import { StorageService } from './StorageService.js' ;
7
7
import { WatchedAttachmentItem } from './WatchedAttachmentItem.js' ;
8
8
9
9
export class AttachmentQueue {
10
10
periodicSyncTimer ?: ReturnType < typeof setInterval > ;
11
- syncInterval : number = 30 * 1000 ;
12
11
context : AttachmentContext ;
13
12
storageService : StorageService ;
14
13
localStorage : LocalStorageAdapter ;
15
14
remoteStorage : RemoteStorageAdapter ;
15
+ attachmentsDirectory ?: string ;
16
+ tableName ?: string ;
17
+ logger ?: ILogger ;
18
+ syncInterval : number = 30 * 1000 ;
19
+ syncThrottleDuration : number ;
16
20
downloadAttachments : boolean = true ;
17
21
watchActiveAbortController ?: AbortController ;
22
+ archivedCacheLimit : number ;
18
23
19
24
constructor ( {
20
25
db,
21
26
localStorage,
22
27
remoteStorage,
23
28
watchAttachments,
24
- tableName,
25
29
logger,
26
- options
30
+ tableName = ATTACHMENT_TABLE ,
31
+ syncInterval = 30 * 1000 ,
32
+ syncThrottleDuration = 1000 ,
33
+ downloadAttachments = true ,
34
+ archivedCacheLimit = 100
27
35
} : {
28
36
db : AbstractPowerSyncDatabase ;
29
37
remoteStorage : RemoteStorageAdapter ;
30
38
localStorage : LocalStorageAdapter ;
31
- watchAttachments ? : ( onUpdate : ( attachement : WatchedAttachmentItem [ ] ) => void ) => void ;
39
+ watchAttachments : ( onUpdate : ( attachement : WatchedAttachmentItem [ ] ) => void ) => void ;
32
40
tableName ?: string ;
33
41
logger ?: ILogger ;
34
- options ?: { syncInterval ?: number ; downloadAttachments ?: boolean } ;
42
+ syncInterval ?: number ;
43
+ syncThrottleDuration ?: number ;
44
+ downloadAttachments ?: boolean ;
45
+ archivedCacheLimit ?: number ;
35
46
} ) {
36
47
this . context = new AttachmentContext ( db , tableName , logger ?? db . logger ) ;
48
+ this . remoteStorage = remoteStorage ;
49
+ this . localStorage = localStorage ;
50
+ this . watchAttachments = watchAttachments ;
51
+ this . tableName = tableName ;
37
52
this . storageService = new StorageService ( this . context , localStorage , remoteStorage , logger ?? db . logger ) ;
38
- if ( options ?. syncInterval != null ) {
39
- this . syncInterval = options . syncInterval ;
40
- }
41
- if ( options ?. downloadAttachments != null ) {
42
- this . downloadAttachments = options . downloadAttachments ;
43
- }
44
-
45
- this . watchAttachments = watchAttachments ?? this . watchAttachments ;
53
+ this . syncInterval = syncInterval ;
54
+ this . syncThrottleDuration = syncThrottleDuration ;
55
+ this . downloadAttachments = downloadAttachments ;
56
+ this . archivedCacheLimit = archivedCacheLimit ;
46
57
}
47
58
48
59
watchAttachments ( onUpdate : ( attachement : WatchedAttachmentItem [ ] ) => void ) : void {
0 commit comments