@powersync/common 1.57.1 → 2.0.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 +6 -6
- package/lib/attachments/AttachmentQueue.js +9 -8
- 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/Schema.d.ts +2 -2
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +21 -6
- 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 +5 -21
- package/lib/index.js +5 -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 +15 -14
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/Schema.ts +2 -2
- package/src/attachments/SyncingService.ts +23 -9
- 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 +5 -21
- package/src/utils/BaseObserver.ts +1 -1
- package/src/utils/Logger.ts +80 -34
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -201
- package/dist/bundle.cjs +0 -14390
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14309
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -12021
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11940
- 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 -505
- 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 -705
- 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 -54
- 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 -644
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
- 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 -78
- 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
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase } from '../client/AbstractPowerSyncDatabase.js';
|
|
2
|
-
import { DEFAULT_WATCH_THROTTLE_MS } from '../client/watched/WatchedQuery.js';
|
|
3
1
|
import { DifferentialWatchedQuery } from '../client/watched/processors/DifferentialQueryProcessor.js';
|
|
4
2
|
import { Mutex } from '../utils/mutex.js';
|
|
3
|
+
import { LogLevels, PowerSyncLogger } from '../utils/Logger.js';
|
|
5
4
|
import { Transaction } from '../db/DBAdapter.js';
|
|
6
|
-
import { ILogger } from '../utils/Logger.js';
|
|
7
5
|
import { AttachmentContext } from './AttachmentContext.js';
|
|
8
6
|
import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
9
7
|
import { AttachmentService } from './AttachmentService.js';
|
|
@@ -12,6 +10,7 @@ import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
|
|
|
12
10
|
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema.js';
|
|
13
11
|
import { SyncingService } from './SyncingService.js';
|
|
14
12
|
import { WatchedAttachmentItem } from './WatchedAttachmentItem.js';
|
|
13
|
+
import { CommonPowerSyncDatabase } from '../client/CommonPowerSyncDatabase.js';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Configuration options for {@link AttachmentQueue}.
|
|
@@ -23,7 +22,7 @@ export interface AttachmentQueueOptions {
|
|
|
23
22
|
/**
|
|
24
23
|
* PowerSync database instance
|
|
25
24
|
*/
|
|
26
|
-
db:
|
|
25
|
+
db: CommonPowerSyncDatabase;
|
|
27
26
|
/**
|
|
28
27
|
* Remote storage adapter for upload/download operations
|
|
29
28
|
*/
|
|
@@ -43,7 +42,7 @@ export interface AttachmentQueueOptions {
|
|
|
43
42
|
/**
|
|
44
43
|
* Logger instance. Defaults to db.logger
|
|
45
44
|
*/
|
|
46
|
-
logger?:
|
|
45
|
+
logger?: PowerSyncLogger;
|
|
47
46
|
/**
|
|
48
47
|
* Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
49
48
|
*/
|
|
@@ -103,7 +102,7 @@ export class AttachmentQueue {
|
|
|
103
102
|
readonly tableName: string;
|
|
104
103
|
|
|
105
104
|
/** Logger instance for diagnostic information */
|
|
106
|
-
readonly logger:
|
|
105
|
+
readonly logger: PowerSyncLogger;
|
|
107
106
|
|
|
108
107
|
/** Interval in milliseconds between periodic sync operations. Acts as a polling timer to retry
|
|
109
108
|
* failed uploads/downloads, especially after the app goes offline. Default: 30000 (30 seconds) */
|
|
@@ -115,7 +114,7 @@ export class AttachmentQueue {
|
|
|
115
114
|
* quick succession (e.g., bulk inserts). This is distinct from syncIntervalMs — it controls
|
|
116
115
|
* how quickly the queue reacts to changes, while syncIntervalMs controls how often it polls
|
|
117
116
|
* for retries. Default: 30 (from DEFAULT_WATCH_THROTTLE_MS) */
|
|
118
|
-
readonly syncThrottleDuration
|
|
117
|
+
readonly syncThrottleDuration?: number;
|
|
119
118
|
|
|
120
119
|
/** Whether to automatically download remote attachments. Default: true */
|
|
121
120
|
readonly downloadAttachments: boolean = true;
|
|
@@ -127,7 +126,7 @@ export class AttachmentQueue {
|
|
|
127
126
|
private readonly attachmentService: AttachmentService;
|
|
128
127
|
|
|
129
128
|
/** PowerSync database instance */
|
|
130
|
-
private readonly db:
|
|
129
|
+
private readonly db: CommonPowerSyncDatabase;
|
|
131
130
|
|
|
132
131
|
/** Cleanup function for status change listener */
|
|
133
132
|
private statusListenerDispose?: () => void;
|
|
@@ -143,7 +142,7 @@ export class AttachmentQueue {
|
|
|
143
142
|
* processing don't take this lock and proceed in parallel via the
|
|
144
143
|
* `AttachmentService` mutex, which is acquired only briefly per row.
|
|
145
144
|
*/
|
|
146
|
-
private syncLoopMutex
|
|
145
|
+
private syncLoopMutex: Mutex;
|
|
147
146
|
|
|
148
147
|
/**
|
|
149
148
|
* Aborted by `stopSync()` to interrupt an in-flight batch within one
|
|
@@ -164,12 +163,13 @@ export class AttachmentQueue {
|
|
|
164
163
|
logger,
|
|
165
164
|
tableName = ATTACHMENT_TABLE,
|
|
166
165
|
syncIntervalMs = 30 * 1000,
|
|
167
|
-
syncThrottleDuration
|
|
166
|
+
syncThrottleDuration,
|
|
168
167
|
downloadAttachments = true,
|
|
169
168
|
archivedCacheLimit = 100,
|
|
170
169
|
errorHandler
|
|
171
170
|
}: AttachmentQueueOptions) {
|
|
172
171
|
this.db = db;
|
|
172
|
+
this.syncLoopMutex = db.createMutex();
|
|
173
173
|
this.remoteStorage = remoteStorage;
|
|
174
174
|
this.localStorage = localStorage;
|
|
175
175
|
this.watchAttachments = watchAttachments;
|
|
@@ -239,7 +239,7 @@ export class AttachmentQueue {
|
|
|
239
239
|
if (status.connected) {
|
|
240
240
|
// Device came online, process attachments immediately
|
|
241
241
|
this.syncStorage().catch((error) => {
|
|
242
|
-
this.logger.error
|
|
242
|
+
this.logger.log({ level: LogLevels.error, message: 'Error syncing storage on connection', error });
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -348,7 +348,8 @@ export class AttachmentQueue {
|
|
|
348
348
|
*/
|
|
349
349
|
async syncStorage(): Promise<void> {
|
|
350
350
|
const signal = this.syncAbortController?.signal;
|
|
351
|
-
|
|
351
|
+
// We have a signal from startSync() to stopSync(), so treat the absence of one like an aborted sync.
|
|
352
|
+
if (signal == null || signal?.aborted) return;
|
|
352
353
|
|
|
353
354
|
try {
|
|
354
355
|
await this.syncLoopMutex.runExclusive(async () => {
|
|
@@ -357,13 +358,13 @@ export class AttachmentQueue {
|
|
|
357
358
|
|
|
358
359
|
await this.syncingService.processAttachments(activeAttachments, { signal });
|
|
359
360
|
|
|
360
|
-
if (signal
|
|
361
|
+
if (signal.aborted) return;
|
|
361
362
|
|
|
362
363
|
await this.attachmentService.withContext((ctx) => this.syncingService.deleteArchivedAttachments(ctx));
|
|
363
364
|
}, signal);
|
|
364
365
|
} catch (error) {
|
|
365
366
|
// A queued batch's acquire rejects when `stopSync` aborts — expected, not an error.
|
|
366
|
-
if (signal
|
|
367
|
+
if (signal.aborted) return;
|
|
367
368
|
throw error;
|
|
368
369
|
}
|
|
369
370
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonPowerSyncDatabase } from '../client/CommonPowerSyncDatabase.js';
|
|
2
2
|
import { DifferentialWatchedQuery } from '../client/watched/processors/DifferentialQueryProcessor.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PowerSyncLogger, LogLevels } from '../utils/Logger.js';
|
|
4
4
|
import { Mutex } from '../utils/mutex.js';
|
|
5
5
|
import { AttachmentContext } from './AttachmentContext.js';
|
|
6
6
|
import { AttachmentRecord, AttachmentState } from './Schema.js';
|
|
@@ -11,15 +11,16 @@ import { AttachmentRecord, AttachmentState } from './Schema.js';
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
export class AttachmentService {
|
|
14
|
-
private mutex
|
|
14
|
+
private mutex: Mutex;
|
|
15
15
|
private context: AttachmentContext;
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
|
-
private db:
|
|
19
|
-
private logger:
|
|
18
|
+
private db: CommonPowerSyncDatabase,
|
|
19
|
+
private logger: PowerSyncLogger,
|
|
20
20
|
private tableName: string = 'attachments',
|
|
21
21
|
archivedCacheLimit: number = 100
|
|
22
22
|
) {
|
|
23
|
+
this.mutex = db.createMutex();
|
|
23
24
|
this.context = new AttachmentContext(db, tableName, logger, archivedCacheLimit);
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -28,7 +29,7 @@ export class AttachmentService {
|
|
|
28
29
|
* @returns Watch query that emits changes for queued uploads, downloads, and deletes
|
|
29
30
|
*/
|
|
30
31
|
watchActiveAttachments({ throttleMs }: { throttleMs?: number } = {}): DifferentialWatchedQuery<AttachmentRecord> {
|
|
31
|
-
this.logger.info
|
|
32
|
+
this.logger.log({ level: LogLevels.info, message: 'Watching active attachments...' });
|
|
32
33
|
const watch = this.db
|
|
33
34
|
.query<AttachmentRecord>({
|
|
34
35
|
sql: /* sql */ `
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { column } from '../db/schema/Column.js';
|
|
2
2
|
import { RowType, Table } from '../db/schema/Table.js';
|
|
3
|
-
import {
|
|
3
|
+
import { TableOptions } from '../db/schema/Table.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The default name of the local table storing attachment data.
|
|
@@ -64,7 +64,7 @@ export enum AttachmentState {
|
|
|
64
64
|
/**
|
|
65
65
|
* @alpha
|
|
66
66
|
*/
|
|
67
|
-
export interface AttachmentTableOptions extends Omit<
|
|
67
|
+
export interface AttachmentTableOptions extends Omit<TableOptions, 'name' | 'columns'> {}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* @alpha
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '../utils/Logger.js';
|
|
2
2
|
import { AttachmentService } from './AttachmentService.js';
|
|
3
3
|
import { LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
4
4
|
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
|
|
@@ -16,14 +16,14 @@ export class SyncingService {
|
|
|
16
16
|
private attachmentService: AttachmentService;
|
|
17
17
|
private localStorage: LocalStorageAdapter;
|
|
18
18
|
private remoteStorage: RemoteStorageAdapter;
|
|
19
|
-
private logger:
|
|
19
|
+
private logger: PowerSyncLogger;
|
|
20
20
|
private errorHandler?: AttachmentErrorHandler;
|
|
21
21
|
|
|
22
22
|
constructor(
|
|
23
23
|
attachmentService: AttachmentService,
|
|
24
24
|
localStorage: LocalStorageAdapter,
|
|
25
25
|
remoteStorage: RemoteStorageAdapter,
|
|
26
|
-
logger:
|
|
26
|
+
logger: PowerSyncLogger,
|
|
27
27
|
errorHandler?: AttachmentErrorHandler
|
|
28
28
|
) {
|
|
29
29
|
this.attachmentService = attachmentService;
|
|
@@ -56,11 +56,17 @@ export class SyncingService {
|
|
|
56
56
|
}
|
|
57
57
|
): Promise<void> {
|
|
58
58
|
const signal = options?.signal;
|
|
59
|
-
this.logger.
|
|
59
|
+
this.logger.log({
|
|
60
|
+
level: LogLevels.info,
|
|
61
|
+
message: `Starting processAttachments with ${attachments.length} attachments`
|
|
62
|
+
});
|
|
60
63
|
|
|
61
64
|
for (const attachment of attachments) {
|
|
62
65
|
if (signal?.aborted) {
|
|
63
|
-
this.logger.
|
|
66
|
+
this.logger.log({
|
|
67
|
+
level: LogLevels.info,
|
|
68
|
+
message: 'Sync cancelled; stopping iteration early'
|
|
69
|
+
});
|
|
64
70
|
return;
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -84,7 +90,11 @@ export class SyncingService {
|
|
|
84
90
|
|
|
85
91
|
await this.attachmentService.withContext((ctx) => ctx.saveAttachments([updated]));
|
|
86
92
|
} catch (error) {
|
|
87
|
-
this.logger.
|
|
93
|
+
this.logger.log({
|
|
94
|
+
level: LogLevels.warn,
|
|
95
|
+
message: `Error during sync for ${attachment.id}`,
|
|
96
|
+
error
|
|
97
|
+
});
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
100
|
}
|
|
@@ -98,7 +108,7 @@ export class SyncingService {
|
|
|
98
108
|
* @throws Error if the attachment has no localUri
|
|
99
109
|
*/
|
|
100
110
|
async uploadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord> {
|
|
101
|
-
this.logger.info
|
|
111
|
+
this.logger.log({ level: LogLevels.info, message: `Uploading attachment ${attachment.filename}` });
|
|
102
112
|
try {
|
|
103
113
|
if (attachment.localUri == null) {
|
|
104
114
|
throw new Error(`No localUri for attachment ${attachment.id}`);
|
|
@@ -134,7 +144,7 @@ export class SyncingService {
|
|
|
134
144
|
* @returns Updated attachment record with local URI and new state
|
|
135
145
|
*/
|
|
136
146
|
async downloadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord> {
|
|
137
|
-
this.logger.info
|
|
147
|
+
this.logger.log({ level: LogLevels.info, message: `Downloading attachment ${attachment.filename}` });
|
|
138
148
|
try {
|
|
139
149
|
const fileData = await this.remoteStorage.downloadFile(attachment);
|
|
140
150
|
|
|
@@ -206,7 +216,11 @@ export class SyncingService {
|
|
|
206
216
|
try {
|
|
207
217
|
await this.localStorage.deleteFile(attachment.localUri);
|
|
208
218
|
} catch (error) {
|
|
209
|
-
this.logger.
|
|
219
|
+
this.logger.log({
|
|
220
|
+
level: LogLevels.error,
|
|
221
|
+
message: 'Error deleting local file for archived attachment',
|
|
222
|
+
error
|
|
223
|
+
});
|
|
210
224
|
}
|
|
211
225
|
}
|
|
212
226
|
}
|