@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630144038
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 +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- 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/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.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/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- 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 +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -22
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- 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 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +9 -46
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +6 -22
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- 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 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- 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 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- 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 -405
- 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 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- 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 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ILogger } from '../utils/Logger.js';
|
|
1
|
+
import { PowerSyncLogger } from '../utils/Logger.js';
|
|
3
2
|
import { Transaction } from '../db/DBAdapter.js';
|
|
4
3
|
import { AttachmentRecord } from './Schema.js';
|
|
4
|
+
import { CommonPowerSyncDatabase } from '../client/CommonPowerSyncDatabase.js';
|
|
5
5
|
/**
|
|
6
6
|
* AttachmentContext provides database operations for managing attachment records.
|
|
7
7
|
*
|
|
8
8
|
* Provides methods to query, insert, update, and delete attachment records with
|
|
9
9
|
* proper transaction management through PowerSync.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @experimental
|
|
12
|
+
* @alpha
|
|
12
13
|
*/
|
|
13
14
|
export declare class AttachmentContext {
|
|
14
15
|
/** PowerSync database instance for executing queries */
|
|
15
|
-
db:
|
|
16
|
+
readonly db: CommonPowerSyncDatabase;
|
|
16
17
|
/** Name of the database table storing attachment records */
|
|
17
|
-
tableName: string;
|
|
18
|
+
readonly tableName: string;
|
|
18
19
|
/** Logger instance for diagnostic information */
|
|
19
|
-
logger:
|
|
20
|
+
readonly logger: PowerSyncLogger;
|
|
20
21
|
/** Maximum number of archived attachments to keep before cleanup */
|
|
21
|
-
archivedCacheLimit: number;
|
|
22
|
+
readonly archivedCacheLimit: number;
|
|
22
23
|
/**
|
|
23
24
|
* Creates a new AttachmentContext instance.
|
|
24
25
|
*
|
|
@@ -26,7 +27,7 @@ export declare class AttachmentContext {
|
|
|
26
27
|
* @param tableName - Name of the table storing attachment records. Default: 'attachments'
|
|
27
28
|
* @param logger - Logger instance for diagnostic output
|
|
28
29
|
*/
|
|
29
|
-
constructor(db:
|
|
30
|
+
constructor(db: CommonPowerSyncDatabase, tableName: string | undefined, logger: PowerSyncLogger, archivedCacheLimit: number);
|
|
30
31
|
/**
|
|
31
32
|
* Retrieves all active attachments that require synchronization.
|
|
32
33
|
* Active attachments include those queued for upload, download, or delete.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogLevels } from '../utils/Logger.js';
|
|
1
2
|
import { AttachmentState, attachmentFromSql } from './Schema.js';
|
|
2
3
|
/**
|
|
3
4
|
* AttachmentContext provides database operations for managing attachment records.
|
|
@@ -5,7 +6,8 @@ import { AttachmentState, attachmentFromSql } from './Schema.js';
|
|
|
5
6
|
* Provides methods to query, insert, update, and delete attachment records with
|
|
6
7
|
* proper transaction management through PowerSync.
|
|
7
8
|
*
|
|
8
|
-
* @
|
|
9
|
+
* @experimental
|
|
10
|
+
* @alpha
|
|
9
11
|
*/
|
|
10
12
|
export class AttachmentContext {
|
|
11
13
|
/** PowerSync database instance for executing queries */
|
|
@@ -190,7 +192,10 @@ export class AttachmentContext {
|
|
|
190
192
|
if (archivedAttachments.length === 0)
|
|
191
193
|
return false;
|
|
192
194
|
await callback?.(archivedAttachments);
|
|
193
|
-
this.logger.
|
|
195
|
+
this.logger.log({
|
|
196
|
+
level: LogLevels.info,
|
|
197
|
+
message: `Deleting ${archivedAttachments.length} archived attachments. Archived attachment exceeds cache archiveCacheLimit of ${this.archivedCacheLimit}.`
|
|
198
|
+
});
|
|
194
199
|
const ids = archivedAttachments.map((attachment) => attachment.id);
|
|
195
200
|
await this.db.execute(
|
|
196
201
|
/* sql */
|
|
@@ -204,7 +209,7 @@ export class AttachmentContext {
|
|
|
204
209
|
json_each (?)
|
|
205
210
|
);
|
|
206
211
|
`, [JSON.stringify(ids)]);
|
|
207
|
-
this.logger.info
|
|
212
|
+
this.logger.log({ level: LogLevels.info, message: `Deleted ${archivedAttachments.length} archived attachments` });
|
|
208
213
|
return archivedAttachments.length < limit;
|
|
209
214
|
}
|
|
210
215
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentContext.js","sourceRoot":"","sources":["../../src/attachments/AttachmentContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AttachmentContext.js","sourceRoot":"","sources":["../../src/attachments/AttachmentContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,oBAAoB,C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AmB,CAAC,MAAM,uBAAuB,EAAE,CAAC,CAAC;QAClH,OAAO,mBAAmB,CAAC,MAAM,GAAG,KAAK,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,eAAe,CAAC,WAA+B;QACnD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAC1C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACrC,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -9,22 +9,22 @@ import { AttachmentRecord } from './Schema.js';
|
|
|
9
9
|
export interface AttachmentErrorHandler {
|
|
10
10
|
/**
|
|
11
11
|
* Handles a download error for a specific attachment.
|
|
12
|
-
* @param attachment The attachment that failed to download
|
|
13
|
-
* @param error The error encountered during the download
|
|
12
|
+
* @param attachment - The attachment that failed to download
|
|
13
|
+
* @param error - The error encountered during the download
|
|
14
14
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
15
15
|
*/
|
|
16
16
|
onDownloadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
17
17
|
/**
|
|
18
18
|
* Handles an upload error for a specific attachment.
|
|
19
|
-
* @param attachment The attachment that failed to upload
|
|
20
|
-
* @param error The error encountered during the upload
|
|
19
|
+
* @param attachment - The attachment that failed to upload
|
|
20
|
+
* @param error - The error encountered during the upload
|
|
21
21
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
22
22
|
*/
|
|
23
23
|
onUploadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
24
24
|
/**
|
|
25
25
|
* Handles a delete error for a specific attachment.
|
|
26
|
-
* @param attachment The attachment that failed to delete
|
|
27
|
-
* @param error The error encountered during the delete
|
|
26
|
+
* @param attachment - The attachment that failed to delete
|
|
27
|
+
* @param error - The error encountered during the delete
|
|
28
28
|
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
29
29
|
*/
|
|
30
30
|
onDeleteError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
@@ -1,11 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ILogger } from '../utils/Logger.js';
|
|
1
|
+
import { PowerSyncLogger } from '../utils/Logger.js';
|
|
3
2
|
import { Transaction } from '../db/DBAdapter.js';
|
|
3
|
+
import { AttachmentContext } from './AttachmentContext.js';
|
|
4
|
+
import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
4
5
|
import { AttachmentData, LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
5
6
|
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
|
|
6
7
|
import { AttachmentRecord } from './Schema.js';
|
|
7
8
|
import { WatchedAttachmentItem } from './WatchedAttachmentItem.js';
|
|
8
|
-
import {
|
|
9
|
+
import { CommonPowerSyncDatabase } from '../client/CommonPowerSyncDatabase.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for {@link AttachmentQueue}.
|
|
12
|
+
*
|
|
13
|
+
* @experimental
|
|
14
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
15
|
+
*/
|
|
16
|
+
export interface AttachmentQueueOptions {
|
|
17
|
+
/**
|
|
18
|
+
* PowerSync database instance
|
|
19
|
+
*/
|
|
20
|
+
db: CommonPowerSyncDatabase;
|
|
21
|
+
/**
|
|
22
|
+
* Remote storage adapter for upload/download operations
|
|
23
|
+
*/
|
|
24
|
+
remoteStorage: RemoteStorageAdapter;
|
|
25
|
+
/**
|
|
26
|
+
* Local storage adapter for file persistence
|
|
27
|
+
*/
|
|
28
|
+
localStorage: LocalStorageAdapter;
|
|
29
|
+
/**
|
|
30
|
+
* Callback for monitoring attachment changes in your data model
|
|
31
|
+
*/
|
|
32
|
+
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
35
|
+
*/
|
|
36
|
+
tableName?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Logger instance. Defaults to db.logger
|
|
39
|
+
*/
|
|
40
|
+
logger?: PowerSyncLogger;
|
|
41
|
+
/**
|
|
42
|
+
* Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
43
|
+
*/
|
|
44
|
+
syncIntervalMs?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
47
|
+
*/
|
|
48
|
+
syncThrottleDuration?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to automatically download remote attachments. Default: true
|
|
51
|
+
*/
|
|
52
|
+
downloadAttachments?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Maximum archived attachments before cleanup. Default: 100
|
|
55
|
+
*/
|
|
56
|
+
archivedCacheLimit?: number;
|
|
57
|
+
/** Handler for upload, download and delete errors */
|
|
58
|
+
errorHandler?: AttachmentErrorHandler;
|
|
59
|
+
}
|
|
9
60
|
/**
|
|
10
61
|
* AttachmentQueue manages the lifecycle and synchronization of attachments
|
|
11
62
|
* between local and remote storage.
|
|
@@ -35,7 +86,7 @@ export declare class AttachmentQueue {
|
|
|
35
86
|
/** Name of the database table storing attachment records */
|
|
36
87
|
readonly tableName: string;
|
|
37
88
|
/** Logger instance for diagnostic information */
|
|
38
|
-
readonly logger:
|
|
89
|
+
readonly logger: PowerSyncLogger;
|
|
39
90
|
/** Interval in milliseconds between periodic sync operations. Acts as a polling timer to retry
|
|
40
91
|
* failed uploads/downloads, especially after the app goes offline. Default: 30000 (30 seconds) */
|
|
41
92
|
readonly syncIntervalMs: number;
|
|
@@ -45,7 +96,7 @@ export declare class AttachmentQueue {
|
|
|
45
96
|
* quick succession (e.g., bulk inserts). This is distinct from syncIntervalMs — it controls
|
|
46
97
|
* how quickly the queue reacts to changes, while syncIntervalMs controls how often it polls
|
|
47
98
|
* for retries. Default: 30 (from DEFAULT_WATCH_THROTTLE_MS) */
|
|
48
|
-
readonly syncThrottleDuration
|
|
99
|
+
readonly syncThrottleDuration?: number;
|
|
49
100
|
/** Whether to automatically download remote attachments. Default: true */
|
|
50
101
|
readonly downloadAttachments: boolean;
|
|
51
102
|
/** Maximum number of archived attachments to keep before cleanup. Default: 100 */
|
|
@@ -62,30 +113,8 @@ export declare class AttachmentQueue {
|
|
|
62
113
|
* Creates a new AttachmentQueue instance.
|
|
63
114
|
*
|
|
64
115
|
* @param options - Configuration options
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param options.localStorage - Local storage adapter for file persistence
|
|
68
|
-
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
|
|
69
|
-
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
70
|
-
* @param options.logger - Logger instance. Defaults to db.logger
|
|
71
|
-
* @param options.syncIntervalMs - Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
72
|
-
* @param options.syncThrottleDuration - Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
73
|
-
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
|
|
74
|
-
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
|
|
75
|
-
*/
|
|
76
|
-
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName, syncIntervalMs, syncThrottleDuration, downloadAttachments, archivedCacheLimit, errorHandler }: {
|
|
77
|
-
db: AbstractPowerSyncDatabase;
|
|
78
|
-
remoteStorage: RemoteStorageAdapter;
|
|
79
|
-
localStorage: LocalStorageAdapter;
|
|
80
|
-
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
81
|
-
tableName?: string;
|
|
82
|
-
logger?: ILogger;
|
|
83
|
-
syncIntervalMs?: number;
|
|
84
|
-
syncThrottleDuration?: number;
|
|
85
|
-
downloadAttachments?: boolean;
|
|
86
|
-
archivedCacheLimit?: number;
|
|
87
|
-
errorHandler?: AttachmentErrorHandler;
|
|
88
|
-
});
|
|
116
|
+
*/
|
|
117
|
+
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName, syncIntervalMs, syncThrottleDuration, downloadAttachments, archivedCacheLimit, errorHandler }: AttachmentQueueOptions);
|
|
89
118
|
/**
|
|
90
119
|
* Generates a new attachment ID using a SQLite UUID function.
|
|
91
120
|
*
|
|
@@ -116,25 +145,45 @@ export declare class AttachmentQueue {
|
|
|
116
145
|
* Clears the periodic sync timer and closes all active attachment watchers.
|
|
117
146
|
*/
|
|
118
147
|
stopSync(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Provides an {@link AttachmentContext} to a callback.
|
|
150
|
+
*
|
|
151
|
+
* The callback runs while the attachment queue mutex is held. Do not call
|
|
152
|
+
* other {@link AttachmentQueue} methods from within the callback, as they may
|
|
153
|
+
* attempt to acquire the same mutex and block indefinitely.
|
|
154
|
+
*/
|
|
155
|
+
withAttachmentContext<T>(callback: (context: AttachmentContext) => Promise<T>): Promise<T>;
|
|
119
156
|
/**
|
|
120
157
|
* Saves a file to local storage and queues it for upload to remote storage.
|
|
121
158
|
*
|
|
122
159
|
* @param options - File save options
|
|
123
|
-
* @param options.data - The file data as ArrayBuffer, Blob, or base64 string
|
|
124
|
-
* @param options.fileExtension - File extension (e.g., 'jpg', 'pdf')
|
|
125
|
-
* @param options.mediaType - MIME type of the file (e.g., 'image/jpeg')
|
|
126
|
-
* @param options.metaData - Optional metadata to associate with the attachment
|
|
127
|
-
* @param options.id - Optional custom ID. If not provided, a UUID will be generated
|
|
128
|
-
* @param options.updateHook - Optional callback to execute additional database operations
|
|
129
|
-
* within the same transaction as the attachment creation
|
|
130
160
|
* @returns Promise resolving to the created attachment record
|
|
131
161
|
*/
|
|
132
162
|
saveFile({ data, fileExtension, mediaType, metaData, id, updateHook }: {
|
|
163
|
+
/**
|
|
164
|
+
* The file data as ArrayBuffer, Blob, or base64 string
|
|
165
|
+
*/
|
|
133
166
|
data: AttachmentData;
|
|
167
|
+
/**
|
|
168
|
+
* File extension (e.g., 'jpg', 'pdf')
|
|
169
|
+
*/
|
|
134
170
|
fileExtension: string;
|
|
171
|
+
/**
|
|
172
|
+
* MIME type of the file (e.g., 'image/jpeg')
|
|
173
|
+
*/
|
|
135
174
|
mediaType?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Optional metadata to associate with the attachment
|
|
177
|
+
*/
|
|
136
178
|
metaData?: string;
|
|
179
|
+
/**
|
|
180
|
+
* Optional custom ID. If not provided, a UUID will be generated
|
|
181
|
+
*/
|
|
137
182
|
id?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Optional callback to execute additional database operations within the same transaction as the attachment
|
|
185
|
+
* creation.
|
|
186
|
+
*/
|
|
138
187
|
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
139
188
|
}): Promise<AttachmentRecord>;
|
|
140
189
|
deleteFile({ id, updateHook }: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevels } from '../utils/Logger.js';
|
|
2
|
+
import { AttachmentService } from './AttachmentService.js';
|
|
2
3
|
import { ATTACHMENT_TABLE, AttachmentState } from './Schema.js';
|
|
3
4
|
import { SyncingService } from './SyncingService.js';
|
|
4
|
-
import { AttachmentService } from './AttachmentService.js';
|
|
5
5
|
/**
|
|
6
6
|
* AttachmentQueue manages the lifecycle and synchronization of attachments
|
|
7
7
|
* between local and remote storage.
|
|
@@ -58,18 +58,8 @@ export class AttachmentQueue {
|
|
|
58
58
|
* Creates a new AttachmentQueue instance.
|
|
59
59
|
*
|
|
60
60
|
* @param options - Configuration options
|
|
61
|
-
* @param options.db - PowerSync database instance
|
|
62
|
-
* @param options.remoteStorage - Remote storage adapter for upload/download operations
|
|
63
|
-
* @param options.localStorage - Local storage adapter for file persistence
|
|
64
|
-
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
|
|
65
|
-
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
66
|
-
* @param options.logger - Logger instance. Defaults to db.logger
|
|
67
|
-
* @param options.syncIntervalMs - Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
68
|
-
* @param options.syncThrottleDuration - Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
69
|
-
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
|
|
70
|
-
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
|
|
71
61
|
*/
|
|
72
|
-
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName = ATTACHMENT_TABLE, syncIntervalMs = 30 * 1000, syncThrottleDuration
|
|
62
|
+
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName = ATTACHMENT_TABLE, syncIntervalMs = 30 * 1000, syncThrottleDuration, downloadAttachments = true, archivedCacheLimit = 100, errorHandler }) {
|
|
73
63
|
this.db = db;
|
|
74
64
|
this.remoteStorage = remoteStorage;
|
|
75
65
|
this.localStorage = localStorage;
|
|
@@ -124,7 +114,7 @@ export class AttachmentQueue {
|
|
|
124
114
|
if (status.connected) {
|
|
125
115
|
// Device came online, process attachments immediately
|
|
126
116
|
this.syncStorage().catch((error) => {
|
|
127
|
-
this.logger.error
|
|
117
|
+
this.logger.log({ level: LogLevels.error, message: 'Error syncing storage on connection', error });
|
|
128
118
|
});
|
|
129
119
|
}
|
|
130
120
|
}
|
|
@@ -156,6 +146,7 @@ export class AttachmentQueue {
|
|
|
156
146
|
state: AttachmentState.QUEUED_DOWNLOAD,
|
|
157
147
|
hasSynced: false,
|
|
158
148
|
metaData: watchedAttachment.metaData,
|
|
149
|
+
mediaType: watchedAttachment.mediaType,
|
|
159
150
|
timestamp: new Date().getTime()
|
|
160
151
|
});
|
|
161
152
|
continue;
|
|
@@ -243,17 +234,24 @@ export class AttachmentQueue {
|
|
|
243
234
|
this.statusListenerDispose = undefined;
|
|
244
235
|
}
|
|
245
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Provides an {@link AttachmentContext} to a callback.
|
|
239
|
+
*
|
|
240
|
+
* The callback runs while the attachment queue mutex is held. Do not call
|
|
241
|
+
* other {@link AttachmentQueue} methods from within the callback, as they may
|
|
242
|
+
* attempt to acquire the same mutex and block indefinitely.
|
|
243
|
+
*/
|
|
244
|
+
withAttachmentContext(callback) {
|
|
245
|
+
/**
|
|
246
|
+
* AttachmentService is internal and private in this class.
|
|
247
|
+
* We only need to expose its locking and context functionality for extending classes.
|
|
248
|
+
*/
|
|
249
|
+
return this.attachmentService.withContext(callback);
|
|
250
|
+
}
|
|
246
251
|
/**
|
|
247
252
|
* Saves a file to local storage and queues it for upload to remote storage.
|
|
248
253
|
*
|
|
249
254
|
* @param options - File save options
|
|
250
|
-
* @param options.data - The file data as ArrayBuffer, Blob, or base64 string
|
|
251
|
-
* @param options.fileExtension - File extension (e.g., 'jpg', 'pdf')
|
|
252
|
-
* @param options.mediaType - MIME type of the file (e.g., 'image/jpeg')
|
|
253
|
-
* @param options.metaData - Optional metadata to associate with the attachment
|
|
254
|
-
* @param options.id - Optional custom ID. If not provided, a UUID will be generated
|
|
255
|
-
* @param options.updateHook - Optional callback to execute additional database operations
|
|
256
|
-
* within the same transaction as the attachment creation
|
|
257
255
|
* @returns Promise resolving to the created attachment record
|
|
258
256
|
*/
|
|
259
257
|
async saveFile({ data, fileExtension, mediaType, metaData, id, updateHook }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentQueue.js","sourceRoot":"","sources":["../../src/attachments/AttachmentQueue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
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AAC;oBACX,mCAAmC;oBACnC,SAAS;gBACX,CAAC;gBAED,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBACvE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;gBAClE,IAAI,SAAS,EAAE,CAAC;oBACd,oEAAoE;oBACpE,OAAO,CAAC,IAAI,CAAC;wBACX,GAAG,UAAU;wBACb,QAAQ,EAAE,WAAW;qBACtB,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,kCAAkC;oBAClC,IAAI,UAAU,CAAC,KAAK,KAAK,eAAe,CAAC,MAAM,EAAE,CAAC;wBAChD,yEAAyE;wBACzE,uBAAuB;wBACvB,OAAO,CAAC,IAAI,CAAC;4BACX,GAAG,UAAU;4BACb,KAAK,EAAE,eAAe,CAAC,eAAe;4BACtC,QAAQ,EAAE,SAAS;yBACpB,CAAC,CAAC;oBACL,CAAC;yBAAM,CAAC;wBACN,uEAAuE;wBACvE,OAAO,CAAC,IAAI,CAAC;4BACX,GAAG,UAAU;4BACb,KAAK,EAAE,eAAe,CAAC,QAAQ;4BAC/B,QAAQ,EAAE,SAAS,CAAC,mBAAmB;yBACxC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;YAED,MAAM,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -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 } from '../utils/Logger.js';
|
|
4
4
|
import { AttachmentContext } from './AttachmentContext.js';
|
|
5
5
|
import { AttachmentRecord } from './Schema.js';
|
|
6
6
|
/**
|
|
@@ -14,7 +14,7 @@ export declare class AttachmentService {
|
|
|
14
14
|
private tableName;
|
|
15
15
|
private mutex;
|
|
16
16
|
private context;
|
|
17
|
-
constructor(db:
|
|
17
|
+
constructor(db: CommonPowerSyncDatabase, logger: PowerSyncLogger, tableName?: string, archivedCacheLimit?: number);
|
|
18
18
|
/**
|
|
19
19
|
* Creates a differential watch query for active attachments requiring synchronization.
|
|
20
20
|
* @returns Watch query that emits changes for queued uploads, downloads, and deletes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevels } from '../utils/Logger.js';
|
|
2
2
|
import { AttachmentContext } from './AttachmentContext.js';
|
|
3
3
|
import { AttachmentState } from './Schema.js';
|
|
4
4
|
/**
|
|
@@ -10,12 +10,13 @@ export class AttachmentService {
|
|
|
10
10
|
db;
|
|
11
11
|
logger;
|
|
12
12
|
tableName;
|
|
13
|
-
mutex
|
|
13
|
+
mutex;
|
|
14
14
|
context;
|
|
15
15
|
constructor(db, logger, tableName = 'attachments', archivedCacheLimit = 100) {
|
|
16
16
|
this.db = db;
|
|
17
17
|
this.logger = logger;
|
|
18
18
|
this.tableName = tableName;
|
|
19
|
+
this.mutex = db.createMutex();
|
|
19
20
|
this.context = new AttachmentContext(db, tableName, logger, archivedCacheLimit);
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
@@ -23,7 +24,7 @@ export class AttachmentService {
|
|
|
23
24
|
* @returns Watch query that emits changes for queued uploads, downloads, and deletes
|
|
24
25
|
*/
|
|
25
26
|
watchActiveAttachments({ throttleMs } = {}) {
|
|
26
|
-
this.logger.info
|
|
27
|
+
this.logger.log({ level: LogLevels.info, message: 'Watching active attachments...' });
|
|
27
28
|
const watch = this.db
|
|
28
29
|
.query({
|
|
29
30
|
sql: /* sql */ `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentService.js","sourceRoot":"","sources":["../../src/attachments/AttachmentService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AttachmentService.js","sourceRoot":"","sources":["../../src/attachments/AttachmentService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAoB,eAAe,EAAE,MAAM,aAAa,CAAC;AAEhE;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAKlB;IACA;IACA;IANF,KAAK,CAAQ;IACb,OAAO,CAAoB;IAEnC,YACU,EAA2B,EAC3B,MAAuB,EACvB,YAAoB,aAAa,EACzC,qBAA6B,GAAG;QAHxB,OAAE,GAAF,EAAE,CAAyB;QAC3B,WAAM,GAAN,MAAM,CAAiB;QACvB,cAAS,GAAT,SAAS,CAAwB;QAGzC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAClF,CAAC;IAED;;;OAGG;IACH,sBAAsB,CAAC,EAAE,UAAU,KAA8B,EAAE;QACjE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC,CAAC;QACtF,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE;aAClB,KAAK,CAAmB;YACvB,GAAG,EAAE,SAAS,CAAC;;;;cAIT,IAAI,CAAC,SAAS;;;;;;;SAOnB;YACD,UAAU,EAAE,CAAC,eAAe,CAAC,aAAa,EAAE,eAAe,CAAC,eAAe,EAAE,eAAe,CAAC,aAAa,CAAC;SAC5G,CAAC;aACD,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;QAErC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAI,QAAoD;QACvE,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;YACxC,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @alpha
|
|
3
|
+
*/
|
|
1
4
|
export type AttachmentData = ArrayBuffer | string;
|
|
5
|
+
/**
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
2
8
|
export declare enum EncodingType {
|
|
3
9
|
UTF8 = "utf8",
|
|
4
10
|
Base64 = "base64"
|
|
@@ -13,36 +19,36 @@ export declare enum EncodingType {
|
|
|
13
19
|
export interface LocalStorageAdapter {
|
|
14
20
|
/**
|
|
15
21
|
* Saves data to a local file.
|
|
16
|
-
* @param filePath Path where the file will be stored
|
|
17
|
-
* @param data Data to store (ArrayBuffer, Blob, or string)
|
|
22
|
+
* @param filePath - Path where the file will be stored
|
|
23
|
+
* @param data - Data to store (ArrayBuffer, Blob, or string)
|
|
18
24
|
* @returns Number of bytes written
|
|
19
25
|
*/
|
|
20
26
|
saveFile(filePath: string, data: AttachmentData): Promise<number>;
|
|
21
27
|
/**
|
|
22
28
|
* Retrieves file data as an ArrayBuffer.
|
|
23
|
-
* @param filePath Path where the file is stored
|
|
29
|
+
* @param filePath - Path where the file is stored
|
|
24
30
|
* @returns ArrayBuffer containing the file data
|
|
25
31
|
*/
|
|
26
32
|
readFile(filePath: string): Promise<ArrayBuffer>;
|
|
27
33
|
/**
|
|
28
34
|
* Deletes the file at the given path.
|
|
29
|
-
* @param filePath Path where the file is stored
|
|
35
|
+
* @param filePath - Path where the file is stored
|
|
30
36
|
*/
|
|
31
37
|
deleteFile(filePath: string): Promise<void>;
|
|
32
38
|
/**
|
|
33
39
|
* Checks if a file exists at the given path.
|
|
34
|
-
* @param filePath Path where the file is stored
|
|
40
|
+
* @param filePath - Path where the file is stored
|
|
35
41
|
* @returns True if the file exists, false otherwise
|
|
36
42
|
*/
|
|
37
43
|
fileExists(filePath: string): Promise<boolean>;
|
|
38
44
|
/**
|
|
39
45
|
* Creates a directory at the specified path.
|
|
40
|
-
* @param path The full path to the directory
|
|
46
|
+
* @param path - The full path to the directory
|
|
41
47
|
*/
|
|
42
48
|
makeDir(path: string): Promise<void>;
|
|
43
49
|
/**
|
|
44
50
|
* Removes a directory at the specified path.
|
|
45
|
-
* @param path The full path to the directory
|
|
51
|
+
* @param path - The full path to the directory
|
|
46
52
|
*/
|
|
47
53
|
rmDir(path: string): Promise<void>;
|
|
48
54
|
/**
|
|
@@ -55,7 +61,7 @@ export interface LocalStorageAdapter {
|
|
|
55
61
|
clear(): Promise<void>;
|
|
56
62
|
/**
|
|
57
63
|
* Returns the file path for the provided filename in the storage directory.
|
|
58
|
-
* @param filename The filename to get the path for
|
|
64
|
+
* @param filename - The filename to get the path for
|
|
59
65
|
* @returns The full file path
|
|
60
66
|
*/
|
|
61
67
|
getLocalUri(filename: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalStorageAdapter.js","sourceRoot":"","sources":["../../src/attachments/LocalStorageAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LocalStorageAdapter.js","sourceRoot":"","sources":["../../src/attachments/LocalStorageAdapter.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,iCAAiB,CAAA;AACnB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB"}
|
|
@@ -9,19 +9,19 @@ import { AttachmentRecord } from './Schema.js';
|
|
|
9
9
|
export interface RemoteStorageAdapter {
|
|
10
10
|
/**
|
|
11
11
|
* Uploads a file to remote storage.
|
|
12
|
-
* @param fileData The binary content of the file to upload
|
|
13
|
-
* @param attachment The associated attachment metadata
|
|
12
|
+
* @param fileData - The binary content of the file to upload
|
|
13
|
+
* @param attachment - The associated attachment metadata
|
|
14
14
|
*/
|
|
15
15
|
uploadFile(fileData: ArrayBuffer, attachment: AttachmentRecord): Promise<void>;
|
|
16
16
|
/**
|
|
17
17
|
* Downloads a file from remote storage.
|
|
18
|
-
* @param attachment The attachment describing the file to download
|
|
18
|
+
* @param attachment - The attachment describing the file to download
|
|
19
19
|
* @returns The binary data of the downloaded file
|
|
20
20
|
*/
|
|
21
21
|
downloadFile(attachment: AttachmentRecord): Promise<ArrayBuffer>;
|
|
22
22
|
/**
|
|
23
23
|
* Deletes a file from remote storage.
|
|
24
|
-
* @param attachment The attachment describing the file to delete
|
|
24
|
+
* @param attachment - The attachment describing the file to delete
|
|
25
25
|
*/
|
|
26
26
|
deleteFile(attachment: AttachmentRecord): Promise<void>;
|
|
27
27
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Table } from '../db/schema/Table.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TableOptions } from '../db/schema/Table.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default name of the local table storing attachment data.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
3
8
|
export declare const ATTACHMENT_TABLE = "attachments";
|
|
4
9
|
/**
|
|
5
10
|
* AttachmentRecord represents an attachment in the local database.
|
|
6
11
|
*
|
|
7
|
-
* @
|
|
12
|
+
* @alpha
|
|
8
13
|
*/
|
|
9
14
|
export interface AttachmentRecord {
|
|
10
15
|
id: string;
|
|
@@ -23,13 +28,13 @@ export interface AttachmentRecord {
|
|
|
23
28
|
* @param row - The database row object
|
|
24
29
|
* @returns The corresponding AttachmentRecord
|
|
25
30
|
*
|
|
26
|
-
* @
|
|
31
|
+
* @alpha
|
|
27
32
|
*/
|
|
28
33
|
export declare function attachmentFromSql(row: any): AttachmentRecord;
|
|
29
34
|
/**
|
|
30
35
|
* AttachmentState represents the current synchronization state of an attachment.
|
|
31
36
|
*
|
|
32
|
-
* @
|
|
37
|
+
* @alpha
|
|
33
38
|
*/
|
|
34
39
|
export declare enum AttachmentState {
|
|
35
40
|
QUEUED_UPLOAD = 0,// Attachment to be uploaded
|
|
@@ -38,12 +43,15 @@ export declare enum AttachmentState {
|
|
|
38
43
|
SYNCED = 3,// Attachment has been synced
|
|
39
44
|
ARCHIVED = 4
|
|
40
45
|
}
|
|
41
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @alpha
|
|
48
|
+
*/
|
|
49
|
+
export interface AttachmentTableOptions extends Omit<TableOptions, 'name' | 'columns'> {
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* AttachmentTable defines the schema for the attachment queue table.
|
|
45
53
|
*
|
|
46
|
-
* @
|
|
54
|
+
* @alpha
|
|
47
55
|
*/
|
|
48
56
|
export declare class AttachmentTable extends Table {
|
|
49
57
|
constructor(options?: AttachmentTableOptions);
|