@powersync/common 1.57.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attachments/AttachmentContext.d.ts +5 -5
- package/lib/attachments/AttachmentContext.js +6 -2
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentQueue.d.ts +85 -47
- package/lib/attachments/AttachmentQueue.js +55 -18
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.js.map +1 -1
- package/lib/attachments/AttachmentTransportAdapter.d.ts +47 -0
- package/lib/attachments/AttachmentTransportAdapter.js +2 -0
- package/lib/attachments/AttachmentTransportAdapter.js.map +1 -0
- package/lib/attachments/BufferedAttachmentTransport.d.ts +24 -0
- package/lib/attachments/BufferedAttachmentTransport.js +32 -0
- package/lib/attachments/BufferedAttachmentTransport.js.map +1 -0
- package/lib/attachments/LocalStorageAdapter.d.ts +19 -0
- package/lib/attachments/Schema.d.ts +2 -2
- package/lib/attachments/SyncingService.d.ts +8 -5
- package/lib/attachments/SyncingService.js +31 -15
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/SQLOpenFactory.d.ts +35 -13
- package/lib/client/SQLOpenFactory.js +1 -25
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +2 -2
- package/lib/client/compilableQueryWatch.js +1 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
- package/lib/client/runOnSchemaChange.d.ts +2 -2
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
- package/lib/client/sync/bucket/CrudEntry.js +0 -99
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/sync-streams.d.ts +1 -1
- package/lib/client/triggers/TriggerManager.d.ts +9 -38
- package/lib/client/watched/GetAllQuery.d.ts +3 -3
- package/lib/client/watched/GetAllQuery.js +1 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +2 -10
- package/lib/client/watched/WatchedQuery.js +0 -11
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +72 -154
- package/lib/db/DBAdapter.js +70 -108
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +1 -13
- package/lib/db/crud/SyncProgress.js +1 -62
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +32 -66
- package/lib/db/crud/SyncStatus.js +1 -253
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +0 -7
- package/lib/db/schema/Column.js +0 -7
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +2 -6
- package/lib/db/schema/Index.js +1 -4
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +2 -6
- package/lib/db/schema/IndexedColumn.js +1 -4
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/Schema.d.ts +4 -28
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +50 -96
- package/lib/db/schema/Table.js +83 -91
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -21
- package/lib/index.js +6 -22
- package/lib/index.js.map +1 -1
- package/lib/utils/BaseObserver.d.ts +1 -1
- package/lib/utils/BaseObserver.js +1 -1
- package/lib/utils/Logger.d.ts +52 -23
- package/lib/utils/Logger.js +35 -33
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -53
- package/lib/utils/mutex.js +1 -156
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +8 -45
- package/src/attachments/AttachmentContext.ts +11 -10
- package/src/attachments/AttachmentQueue.ts +129 -70
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/AttachmentTransportAdapter.ts +49 -0
- package/src/attachments/BufferedAttachmentTransport.ts +37 -0
- package/src/attachments/LocalStorageAdapter.ts +20 -0
- package/src/attachments/Schema.ts +2 -2
- package/src/attachments/SyncingService.ts +34 -20
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/SQLOpenFactory.ts +38 -22
- package/src/client/compilableQueryWatch.ts +3 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
- package/src/client/runOnSchemaChange.ts +2 -2
- package/src/client/sync/bucket/CrudEntry.ts +4 -104
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/sync-streams.ts +1 -1
- package/src/client/triggers/TriggerManager.ts +10 -41
- package/src/client/watched/GetAllQuery.ts +3 -3
- package/src/client/watched/WatchedQuery.ts +2 -15
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
- package/src/db/DBAdapter.ts +141 -226
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +2 -42
- package/src/db/crud/SyncStatus.ts +45 -220
- package/src/db/schema/Column.ts +0 -8
- package/src/db/schema/Index.ts +3 -6
- package/src/db/schema/IndexedColumn.ts +3 -6
- package/src/db/schema/Schema.ts +4 -4
- package/src/db/schema/Table.ts +111 -186
- package/src/index.ts +6 -21
- package/src/utils/BaseObserver.ts +1 -1
- package/src/utils/Logger.ts +80 -42
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -201
- package/dist/bundle.cjs +0 -14398
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14317
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -12029
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11948
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4651
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -990
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -115
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -4
- package/lib/client/constants.js +0 -5
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
- package/lib/client/sync/stream/AbstractRemote.js +0 -508
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -706
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -77
- package/lib/client/sync/stream/core-instruction.js +0 -30
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -410
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -12
- package/lib/db/ConnectionClosedError.js +0 -23
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -11
- package/lib/db/schema/TableV2.js +0 -11
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -11
- package/lib/utils/AbortOperation.js +0 -21
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -31
- package/lib/utils/ControlledExecutor.js +0 -58
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -46
- package/lib/utils/async.js +0 -147
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/compatibility.d.ts +0 -8
- package/lib/utils/compatibility.js +0 -9
- package/lib/utils/compatibility.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -12
- package/lib/utils/parseQuery.js +0 -20
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -41
- package/lib/utils/stream_transform.js +0 -211
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
- package/src/client/ConnectionManager.ts +0 -405
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -4
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
- package/src/client/sync/stream/AbstractRemote.ts +0 -648
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -971
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
- package/src/client/sync/stream/core-instruction.ts +0 -109
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -501
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -25
- package/src/db/schema/TableV2.ts +0 -11
- package/src/utils/AbortOperation.ts +0 -19
- package/src/utils/ControlledExecutor.ts +0 -81
- package/src/utils/async.ts +0 -185
- package/src/utils/compatibility.ts +0 -9
- package/src/utils/parseQuery.ts +0 -31
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -260
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default {@link AttachmentTransportAdapter}, composing the local and remote
|
|
3
|
+
* storage adapters.
|
|
4
|
+
*
|
|
5
|
+
* The full file body is materialized as an `ArrayBuffer` in JS memory between the
|
|
6
|
+
* two adapter calls. This is fine for small files but can cause memory pressure on
|
|
7
|
+
* large ones — environments that support native transfer should provide a custom
|
|
8
|
+
* transport instead.
|
|
9
|
+
*
|
|
10
|
+
* @experimental
|
|
11
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
12
|
+
*/
|
|
13
|
+
export class BufferedAttachmentTransport {
|
|
14
|
+
localStorage;
|
|
15
|
+
remoteStorage;
|
|
16
|
+
constructor(localStorage, remoteStorage) {
|
|
17
|
+
this.localStorage = localStorage;
|
|
18
|
+
this.remoteStorage = remoteStorage;
|
|
19
|
+
}
|
|
20
|
+
async upload(attachment) {
|
|
21
|
+
const fileData = await this.localStorage.readFile(attachment.localUri);
|
|
22
|
+
await this.remoteStorage.uploadFile(fileData, attachment);
|
|
23
|
+
}
|
|
24
|
+
async download(attachment) {
|
|
25
|
+
const fileData = await this.remoteStorage.downloadFile(attachment);
|
|
26
|
+
await this.localStorage.saveFile(attachment.localUri, fileData);
|
|
27
|
+
}
|
|
28
|
+
async delete(attachment) {
|
|
29
|
+
await this.remoteStorage.deleteFile(attachment);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=BufferedAttachmentTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferedAttachmentTransport.js","sourceRoot":"","sources":["../../src/attachments/BufferedAttachmentTransport.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,2BAA2B;IAE5B;IACA;IAFV,YACU,YAAiC,EACjC,aAAmC;QADnC,iBAAY,GAAZ,YAAY,CAAqB;QACjC,kBAAa,GAAb,aAAa,CAAsB;IAC1C,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,UAAmC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,UAAmC;QAChD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAA4B;QACvC,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -66,3 +66,22 @@ export interface LocalStorageAdapter {
|
|
|
66
66
|
*/
|
|
67
67
|
getLocalUri(filename: string): string;
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* A {@link LocalStorageAdapter} that can relocate a file into managed storage without
|
|
71
|
+
* loading it into memory. Required for {@link AttachmentQueue.saveFileFromUri}; only
|
|
72
|
+
* queues configured with a streaming-capable local adapter expose that method.
|
|
73
|
+
*
|
|
74
|
+
* @experimental
|
|
75
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
76
|
+
*/
|
|
77
|
+
export interface StreamingLocalStorageAdapter extends LocalStorageAdapter {
|
|
78
|
+
/**
|
|
79
|
+
* Moves a file into managed storage without loading it into memory.
|
|
80
|
+
* Overwrites any existing file at the target. When source and target are the same
|
|
81
|
+
* path, this is a no-op that just reports the size.
|
|
82
|
+
* @param sourceUri - Path of the existing file
|
|
83
|
+
* @param targetUri - Destination path within managed storage
|
|
84
|
+
* @returns Number of bytes in the moved file
|
|
85
|
+
*/
|
|
86
|
+
moveFile(sourceUri: string, targetUri: string): Promise<number>;
|
|
87
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowType, Table } from '../db/schema/Table.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TableOptions } from '../db/schema/Table.js';
|
|
3
3
|
/**
|
|
4
4
|
* The default name of the local table storing attachment data.
|
|
5
5
|
*
|
|
@@ -46,7 +46,7 @@ export declare enum AttachmentState {
|
|
|
46
46
|
/**
|
|
47
47
|
* @alpha
|
|
48
48
|
*/
|
|
49
|
-
export interface AttachmentTableOptions extends Omit<
|
|
49
|
+
export interface AttachmentTableOptions extends Omit<TableOptions, 'name' | 'columns'> {
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* @alpha
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PowerSyncLogger } from '../utils/Logger.js';
|
|
2
2
|
import { AttachmentService } from './AttachmentService.js';
|
|
3
|
+
import { AttachmentTransportAdapter } from './AttachmentTransportAdapter.js';
|
|
3
4
|
import { LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
4
|
-
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
|
|
5
5
|
import { AttachmentRecord } from './Schema.js';
|
|
6
6
|
import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
7
7
|
import { AttachmentContext } from './AttachmentContext.js';
|
|
@@ -9,15 +9,18 @@ import { AttachmentContext } from './AttachmentContext.js';
|
|
|
9
9
|
* Orchestrates attachment synchronization between local and remote storage.
|
|
10
10
|
* Handles uploads, downloads, deletions, and state transitions.
|
|
11
11
|
*
|
|
12
|
+
* Remote operations (upload/download/delete) go through the {@link AttachmentTransportAdapter};
|
|
13
|
+
* local file operations use the {@link LocalStorageAdapter}.
|
|
14
|
+
*
|
|
12
15
|
* @internal
|
|
13
16
|
*/
|
|
14
17
|
export declare class SyncingService {
|
|
15
18
|
private attachmentService;
|
|
16
19
|
private localStorage;
|
|
17
|
-
private
|
|
20
|
+
private transport;
|
|
18
21
|
private logger;
|
|
19
22
|
private errorHandler?;
|
|
20
|
-
constructor(attachmentService: AttachmentService, localStorage: LocalStorageAdapter,
|
|
23
|
+
constructor(attachmentService: AttachmentService, localStorage: LocalStorageAdapter, transport: AttachmentTransportAdapter, logger: PowerSyncLogger, errorHandler?: AttachmentErrorHandler);
|
|
21
24
|
/**
|
|
22
25
|
* Processes attachments based on their state (upload, download, or delete).
|
|
23
26
|
*
|
|
@@ -48,7 +51,7 @@ export declare class SyncingService {
|
|
|
48
51
|
uploadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
|
|
49
52
|
/**
|
|
50
53
|
* Downloads an attachment from remote storage to local storage.
|
|
51
|
-
*
|
|
54
|
+
* The destination `localUri` is assigned here and the transport writes the file to it.
|
|
52
55
|
* On success, marks as SYNCED. On failure, defers to error handler or archives.
|
|
53
56
|
*
|
|
54
57
|
* @param attachment - The attachment record to download
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { LogLevels } from '../utils/Logger.js';
|
|
1
2
|
import { AttachmentState } from './Schema.js';
|
|
2
3
|
/**
|
|
3
4
|
* Orchestrates attachment synchronization between local and remote storage.
|
|
4
5
|
* Handles uploads, downloads, deletions, and state transitions.
|
|
5
6
|
*
|
|
7
|
+
* Remote operations (upload/download/delete) go through the {@link AttachmentTransportAdapter};
|
|
8
|
+
* local file operations use the {@link LocalStorageAdapter}.
|
|
9
|
+
*
|
|
6
10
|
* @internal
|
|
7
11
|
*/
|
|
8
12
|
export class SyncingService {
|
|
9
13
|
attachmentService;
|
|
10
14
|
localStorage;
|
|
11
|
-
|
|
15
|
+
transport;
|
|
12
16
|
logger;
|
|
13
17
|
errorHandler;
|
|
14
|
-
constructor(attachmentService, localStorage,
|
|
18
|
+
constructor(attachmentService, localStorage, transport, logger, errorHandler) {
|
|
15
19
|
this.attachmentService = attachmentService;
|
|
16
20
|
this.localStorage = localStorage;
|
|
17
|
-
this.
|
|
21
|
+
this.transport = transport;
|
|
18
22
|
this.logger = logger;
|
|
19
23
|
this.errorHandler = errorHandler;
|
|
20
24
|
}
|
|
@@ -36,10 +40,16 @@ export class SyncingService {
|
|
|
36
40
|
*/
|
|
37
41
|
async processAttachments(attachments, options) {
|
|
38
42
|
const signal = options?.signal;
|
|
39
|
-
this.logger.
|
|
43
|
+
this.logger.log({
|
|
44
|
+
level: LogLevels.info,
|
|
45
|
+
message: `Starting processAttachments with ${attachments.length} attachments`
|
|
46
|
+
});
|
|
40
47
|
for (const attachment of attachments) {
|
|
41
48
|
if (signal?.aborted) {
|
|
42
|
-
this.logger.
|
|
49
|
+
this.logger.log({
|
|
50
|
+
level: LogLevels.info,
|
|
51
|
+
message: 'Sync cancelled; stopping iteration early'
|
|
52
|
+
});
|
|
43
53
|
return;
|
|
44
54
|
}
|
|
45
55
|
try {
|
|
@@ -62,7 +72,11 @@ export class SyncingService {
|
|
|
62
72
|
await this.attachmentService.withContext((ctx) => ctx.saveAttachments([updated]));
|
|
63
73
|
}
|
|
64
74
|
catch (error) {
|
|
65
|
-
this.logger.
|
|
75
|
+
this.logger.log({
|
|
76
|
+
level: LogLevels.warn,
|
|
77
|
+
message: `Error during sync for ${attachment.id}`,
|
|
78
|
+
error
|
|
79
|
+
});
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
82
|
}
|
|
@@ -75,13 +89,12 @@ export class SyncingService {
|
|
|
75
89
|
* @throws Error if the attachment has no localUri
|
|
76
90
|
*/
|
|
77
91
|
async uploadAttachment(attachment) {
|
|
78
|
-
this.logger.info
|
|
92
|
+
this.logger.log({ level: LogLevels.info, message: `Uploading attachment ${attachment.filename}` });
|
|
79
93
|
try {
|
|
80
94
|
if (attachment.localUri == null) {
|
|
81
95
|
throw new Error(`No localUri for attachment ${attachment.id}`);
|
|
82
96
|
}
|
|
83
|
-
|
|
84
|
-
await this.remoteStorage.uploadFile(fileBlob, attachment);
|
|
97
|
+
await this.transport.upload({ ...attachment, localUri: attachment.localUri });
|
|
85
98
|
return {
|
|
86
99
|
...attachment,
|
|
87
100
|
state: AttachmentState.SYNCED,
|
|
@@ -101,18 +114,17 @@ export class SyncingService {
|
|
|
101
114
|
}
|
|
102
115
|
/**
|
|
103
116
|
* Downloads an attachment from remote storage to local storage.
|
|
104
|
-
*
|
|
117
|
+
* The destination `localUri` is assigned here and the transport writes the file to it.
|
|
105
118
|
* On success, marks as SYNCED. On failure, defers to error handler or archives.
|
|
106
119
|
*
|
|
107
120
|
* @param attachment - The attachment record to download
|
|
108
121
|
* @returns Updated attachment record with local URI and new state
|
|
109
122
|
*/
|
|
110
123
|
async downloadAttachment(attachment) {
|
|
111
|
-
this.logger.info
|
|
124
|
+
this.logger.log({ level: LogLevels.info, message: `Downloading attachment ${attachment.filename}` });
|
|
112
125
|
try {
|
|
113
|
-
const fileData = await this.remoteStorage.downloadFile(attachment);
|
|
114
126
|
const localUri = this.localStorage.getLocalUri(attachment.filename);
|
|
115
|
-
await this.
|
|
127
|
+
await this.transport.download({ ...attachment, localUri });
|
|
116
128
|
return {
|
|
117
129
|
...attachment,
|
|
118
130
|
state: AttachmentState.SYNCED,
|
|
@@ -142,7 +154,7 @@ export class SyncingService {
|
|
|
142
154
|
*/
|
|
143
155
|
async deleteAttachment(attachment, context) {
|
|
144
156
|
try {
|
|
145
|
-
await this.
|
|
157
|
+
await this.transport.delete(attachment);
|
|
146
158
|
if (attachment.localUri) {
|
|
147
159
|
await this.localStorage.deleteFile(attachment.localUri);
|
|
148
160
|
}
|
|
@@ -175,7 +187,11 @@ export class SyncingService {
|
|
|
175
187
|
await this.localStorage.deleteFile(attachment.localUri);
|
|
176
188
|
}
|
|
177
189
|
catch (error) {
|
|
178
|
-
this.logger.
|
|
190
|
+
this.logger.log({
|
|
191
|
+
level: LogLevels.error,
|
|
192
|
+
message: 'Error deleting local file for archived attachment',
|
|
193
|
+
error
|
|
194
|
+
});
|
|
179
195
|
}
|
|
180
196
|
}
|
|
181
197
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncingService.js","sourceRoot":"","sources":["../../src/attachments/SyncingService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SyncingService.js","sourceRoot":"","sources":["../../src/attachments/SyncingService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,oBAAoB,CAAC;AAIhE,OAAO,EAAoB,eAAe,EAAE,MAAM,aAAa,CAAC;AAIhE;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IACjB,iBAAiB,CAAoB;IACrC,YAAY,CAAsB;IAClC,SAAS,CAA6B;IACtC,MAAM,CAAkB;IACxB,YAAY,CAA0B;IAE9C,YACE,iBAAoC,EACpC,YAAiC,EACjC,SAAqC,EACrC,MAAuB,EACvB,YAAqC;QAErC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,kBAAkB,CACtB,WAA+B,EAC/B,OAEC;QAED,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACd,KAAK,EAAE,SAAS,CAAC,IAAI;YACrB,OAAO,EAAE,oCAAoC,WAAW,CAAC,MAAM,cAAc;SAC9E,CAAC,CAAC;QAEH,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;oBACd,KAAK,EAAE,SAAS,CAAC,IAAI;oBACrB,OAAO,EAAE,0CAA0C;iBACpD,CAAC,CAAC;gBACH,OA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