@powersync/common 1.53.2 → 1.54.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/dist/bundle.cjs +548 -345
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +548 -345
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +548 -345
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +548 -345
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +727 -189
- package/lib/attachments/AttachmentContext.d.ts +7 -6
- package/lib/attachments/AttachmentContext.js +2 -1
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +61 -20
- package/lib/attachments/AttachmentQueue.js +16 -18
- package/lib/attachments/AttachmentQueue.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 +12 -4
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/AbstractPowerSyncDatabase.d.ts +110 -58
- package/lib/client/AbstractPowerSyncDatabase.js +59 -48
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +6 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js +3 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -1
- package/lib/client/ConnectionManager.d.ts +4 -1
- package/lib/client/ConnectionManager.js +1 -1
- package/lib/client/ConnectionManager.js.map +1 -1
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +12 -0
- package/lib/client/SQLOpenFactory.js +6 -0
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +6 -0
- package/lib/client/compilableQueryWatch.js +3 -0
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -0
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/constants.d.ts +3 -0
- package/lib/client/constants.js +3 -0
- package/lib/client/constants.js.map +1 -1
- package/lib/client/runOnSchemaChange.d.ts +3 -0
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +12 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js +6 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.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 -0
- package/lib/client/sync/bucket/CrudEntry.js +4 -0
- 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/bucket/SqliteBucketStorage.d.ts +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js +3 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +30 -1
- package/lib/client/sync/stream/AbstractRemote.js +15 -1
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +55 -5
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +32 -4
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js +2 -1
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -1
- package/lib/client/sync/sync-streams.d.ts +22 -7
- package/lib/client/triggers/TriggerManager.d.ts +19 -18
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
- package/lib/client/triggers/TriggerManagerImpl.js +3 -3
- package/lib/client/triggers/TriggerManagerImpl.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 +4 -0
- package/lib/client/watched/GetAllQuery.js +2 -0
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +24 -2
- package/lib/client/watched/WatchedQuery.js +9 -0
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +20 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +4 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -0
- 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/ConnectionClosedError.d.ts +2 -0
- package/lib/db/ConnectionClosedError.js +2 -0
- package/lib/db/ConnectionClosedError.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +56 -6
- package/lib/db/DBAdapter.js +15 -3
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/crud/SyncProgress.d.ts +6 -1
- package/lib/db/crud/SyncProgress.js +2 -0
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +36 -38
- package/lib/db/crud/SyncStatus.js +19 -14
- 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 +28 -0
- package/lib/db/schema/Column.js +16 -3
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +9 -0
- package/lib/db/schema/Index.js +6 -0
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +9 -0
- package/lib/db/schema/IndexedColumn.js +6 -0
- 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 +6 -1
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +27 -3
- package/lib/db/schema/Table.js +9 -0
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/db/schema/TableV2.d.ts +2 -0
- package/lib/db/schema/TableV2.js +2 -0
- package/lib/db/schema/TableV2.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/AbortOperation.d.ts +2 -0
- package/lib/utils/AbortOperation.js +2 -0
- package/lib/utils/AbortOperation.js.map +1 -1
- 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/ControlledExecutor.d.ts +6 -0
- package/lib/utils/ControlledExecutor.js +3 -0
- package/lib/utils/ControlledExecutor.js.map +1 -1
- package/lib/utils/Logger.d.ts +9 -0
- package/lib/utils/Logger.js +6 -0
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/mutex.d.ts +8 -0
- package/lib/utils/mutex.js +3 -0
- package/lib/utils/mutex.js.map +1 -1
- package/lib/utils/parseQuery.d.ts +6 -0
- package/lib/utils/parseQuery.js +3 -0
- package/lib/utils/parseQuery.js.map +1 -1
- package/lib/utils/stream_transform.d.ts +3 -1
- package/lib/utils/stream_transform.js.map +1 -1
- package/package.json +3 -2
- package/src/attachments/AttachmentContext.ts +7 -6
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +71 -23
- 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 +12 -4
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/AbstractPowerSyncDatabase.ts +117 -62
- package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
- package/src/client/ConnectionManager.ts +4 -1
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +12 -0
- package/src/client/compilableQueryWatch.ts +6 -0
- package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/constants.ts +3 -0
- package/src/client/runOnSchemaChange.ts +3 -0
- package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +9 -0
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
- package/src/client/sync/stream/AbstractRemote.ts +30 -1
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +55 -5
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
- package/src/client/sync/sync-streams.ts +22 -9
- package/src/client/triggers/TriggerManager.ts +19 -18
- package/src/client/triggers/TriggerManagerImpl.ts +5 -5
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +5 -1
- package/src/client/watched/WatchedQuery.ts +24 -2
- package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/ConnectionClosedError.ts +2 -0
- package/src/db/DBAdapter.ts +58 -6
- package/src/db/crud/SyncProgress.ts +6 -1
- package/src/db/crud/SyncStatus.ts +40 -21
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +28 -3
- package/src/db/schema/Index.ts +9 -0
- package/src/db/schema/IndexedColumn.ts +9 -0
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +8 -3
- package/src/db/schema/Table.ts +30 -5
- package/src/db/schema/TableV2.ts +2 -0
- package/src/index.ts +1 -1
- package/src/types/types.ts +6 -0
- package/src/utils/AbortOperation.ts +2 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/ControlledExecutor.ts +6 -0
- package/src/utils/Logger.ts +9 -0
- package/src/utils/mutex.ts +12 -0
- package/src/utils/parseQuery.ts +6 -0
- package/src/utils/stream_transform.ts +3 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AbstractPowerSyncDatabase } from '../client/AbstractPowerSyncDatabase.js';
|
|
2
2
|
import { DEFAULT_WATCH_THROTTLE_MS } from '../client/watched/WatchedQuery.js';
|
|
3
3
|
import { DifferentialWatchedQuery } from '../client/watched/processors/DifferentialQueryProcessor.js';
|
|
4
|
-
import { ILogger } from '../utils/Logger.js';
|
|
5
4
|
import { Transaction } from '../db/DBAdapter.js';
|
|
5
|
+
import { ILogger } from '../utils/Logger.js';
|
|
6
|
+
import { AttachmentContext } from './AttachmentContext.js';
|
|
7
|
+
import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
8
|
+
import { AttachmentService } from './AttachmentService.js';
|
|
6
9
|
import { AttachmentData, LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
7
10
|
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
|
|
8
11
|
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema.js';
|
|
9
12
|
import { SyncingService } from './SyncingService.js';
|
|
10
13
|
import { WatchedAttachmentItem } from './WatchedAttachmentItem.js';
|
|
11
|
-
import { AttachmentService } from './AttachmentService.js';
|
|
12
|
-
import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* AttachmentQueue manages the lifecycle and synchronization of attachments
|
|
@@ -20,7 +21,7 @@ import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
|
|
|
20
21
|
* @experimental
|
|
21
22
|
* @alpha This is currently experimental and may change without a major version bump.
|
|
22
23
|
*/
|
|
23
|
-
export class AttachmentQueue {
|
|
24
|
+
export class AttachmentQueue implements AttachmentQueue {
|
|
24
25
|
/** Timer for periodic synchronization operations */
|
|
25
26
|
private periodicSyncTimer?: ReturnType<typeof setInterval>;
|
|
26
27
|
|
|
@@ -78,24 +79,14 @@ export class AttachmentQueue {
|
|
|
78
79
|
/** Cleanup function for status change listener */
|
|
79
80
|
private statusListenerDispose?: () => void;
|
|
80
81
|
|
|
81
|
-
private watchActiveAttachments
|
|
82
|
+
private watchActiveAttachments!: DifferentialWatchedQuery<AttachmentRecord>;
|
|
82
83
|
|
|
83
|
-
private watchAttachmentsAbortController
|
|
84
|
+
private watchAttachmentsAbortController!: AbortController;
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* Creates a new AttachmentQueue instance.
|
|
87
88
|
*
|
|
88
89
|
* @param options - Configuration options
|
|
89
|
-
* @param options.db - PowerSync database instance
|
|
90
|
-
* @param options.remoteStorage - Remote storage adapter for upload/download operations
|
|
91
|
-
* @param options.localStorage - Local storage adapter for file persistence
|
|
92
|
-
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
|
|
93
|
-
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
94
|
-
* @param options.logger - Logger instance. Defaults to db.logger
|
|
95
|
-
* @param options.syncIntervalMs - Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
96
|
-
* @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
|
|
97
|
-
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
|
|
98
|
-
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
|
|
99
90
|
*/
|
|
100
91
|
constructor({
|
|
101
92
|
db,
|
|
@@ -110,15 +101,45 @@ export class AttachmentQueue {
|
|
|
110
101
|
archivedCacheLimit = 100,
|
|
111
102
|
errorHandler
|
|
112
103
|
}: {
|
|
104
|
+
/**
|
|
105
|
+
* PowerSync database instance
|
|
106
|
+
*/
|
|
113
107
|
db: AbstractPowerSyncDatabase;
|
|
108
|
+
/**
|
|
109
|
+
* Remote storage adapter for upload/download operations
|
|
110
|
+
*/
|
|
114
111
|
remoteStorage: RemoteStorageAdapter;
|
|
112
|
+
/**
|
|
113
|
+
* Local storage adapter for file persistence
|
|
114
|
+
*/
|
|
115
115
|
localStorage: LocalStorageAdapter;
|
|
116
|
+
/**
|
|
117
|
+
* Callback for monitoring attachment changes in your data model
|
|
118
|
+
*/
|
|
116
119
|
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
122
|
+
*/
|
|
117
123
|
tableName?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Logger instance. Defaults to db.logger
|
|
126
|
+
*/
|
|
118
127
|
logger?: ILogger;
|
|
128
|
+
/**
|
|
129
|
+
* Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
130
|
+
*/
|
|
119
131
|
syncIntervalMs?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
134
|
+
*/
|
|
120
135
|
syncThrottleDuration?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Whether to automatically download remote attachments. Default: true
|
|
138
|
+
*/
|
|
121
139
|
downloadAttachments?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Maximum archived attachments before cleanup. Default: 100
|
|
142
|
+
*/
|
|
122
143
|
archivedCacheLimit?: number;
|
|
123
144
|
errorHandler?: AttachmentErrorHandler;
|
|
124
145
|
}) {
|
|
@@ -228,6 +249,7 @@ export class AttachmentQueue {
|
|
|
228
249
|
state: AttachmentState.QUEUED_DOWNLOAD,
|
|
229
250
|
hasSynced: false,
|
|
230
251
|
metaData: watchedAttachment.metaData,
|
|
252
|
+
mediaType: watchedAttachment.mediaType,
|
|
231
253
|
timestamp: new Date().getTime()
|
|
232
254
|
});
|
|
233
255
|
continue;
|
|
@@ -321,17 +343,24 @@ export class AttachmentQueue {
|
|
|
321
343
|
}
|
|
322
344
|
}
|
|
323
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Provides an {@link AttachmentContext} to a callback.
|
|
348
|
+
*
|
|
349
|
+
* The callback runs while the attachment queue mutex is held. Do not call
|
|
350
|
+
* other {@link AttachmentQueue} methods from within the callback, as they may
|
|
351
|
+
* attempt to acquire the same mutex and block indefinitely.
|
|
352
|
+
*/
|
|
353
|
+
withAttachmentContext<T>(callback: (context: AttachmentContext) => Promise<T>): Promise<T> {
|
|
354
|
+
/**
|
|
355
|
+
* AttachmentService is internal and private in this class.
|
|
356
|
+
* We only need to expose its locking and context functionality for extending classes.
|
|
357
|
+
*/
|
|
358
|
+
return this.attachmentService.withContext(callback);
|
|
359
|
+
}
|
|
324
360
|
/**
|
|
325
361
|
* Saves a file to local storage and queues it for upload to remote storage.
|
|
326
362
|
*
|
|
327
363
|
* @param options - File save options
|
|
328
|
-
* @param options.data - The file data as ArrayBuffer, Blob, or base64 string
|
|
329
|
-
* @param options.fileExtension - File extension (e.g., 'jpg', 'pdf')
|
|
330
|
-
* @param options.mediaType - MIME type of the file (e.g., 'image/jpeg')
|
|
331
|
-
* @param options.metaData - Optional metadata to associate with the attachment
|
|
332
|
-
* @param options.id - Optional custom ID. If not provided, a UUID will be generated
|
|
333
|
-
* @param options.updateHook - Optional callback to execute additional database operations
|
|
334
|
-
* within the same transaction as the attachment creation
|
|
335
364
|
* @returns Promise resolving to the created attachment record
|
|
336
365
|
*/
|
|
337
366
|
async saveFile({
|
|
@@ -342,11 +371,30 @@ export class AttachmentQueue {
|
|
|
342
371
|
id,
|
|
343
372
|
updateHook
|
|
344
373
|
}: {
|
|
374
|
+
/**
|
|
375
|
+
* The file data as ArrayBuffer, Blob, or base64 string
|
|
376
|
+
*/
|
|
345
377
|
data: AttachmentData;
|
|
378
|
+
/**
|
|
379
|
+
* File extension (e.g., 'jpg', 'pdf')
|
|
380
|
+
*/
|
|
346
381
|
fileExtension: string;
|
|
382
|
+
/**
|
|
383
|
+
* MIME type of the file (e.g., 'image/jpeg')
|
|
384
|
+
*/
|
|
347
385
|
mediaType?: string;
|
|
386
|
+
/**
|
|
387
|
+
* Optional metadata to associate with the attachment
|
|
388
|
+
*/
|
|
348
389
|
metaData?: string;
|
|
390
|
+
/**
|
|
391
|
+
* Optional custom ID. If not provided, a UUID will be generated
|
|
392
|
+
*/
|
|
349
393
|
id?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Optional callback to execute additional database operations within the same transaction as the attachment
|
|
396
|
+
* creation.
|
|
397
|
+
*/
|
|
350
398
|
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
351
399
|
}): Promise<AttachmentRecord> {
|
|
352
400
|
const resolvedId = id ?? (await this.generateAttachmentId());
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @alpha
|
|
3
|
+
*/
|
|
1
4
|
export type AttachmentData = ArrayBuffer | string;
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
3
9
|
export enum EncodingType {
|
|
4
10
|
UTF8 = 'utf8',
|
|
5
11
|
Base64 = 'base64'
|
|
@@ -15,41 +21,41 @@ export enum EncodingType {
|
|
|
15
21
|
export interface LocalStorageAdapter {
|
|
16
22
|
/**
|
|
17
23
|
* Saves data to a local file.
|
|
18
|
-
* @param filePath Path where the file will be stored
|
|
19
|
-
* @param data Data to store (ArrayBuffer, Blob, or string)
|
|
24
|
+
* @param filePath - Path where the file will be stored
|
|
25
|
+
* @param data - Data to store (ArrayBuffer, Blob, or string)
|
|
20
26
|
* @returns Number of bytes written
|
|
21
27
|
*/
|
|
22
28
|
saveFile(filePath: string, data: AttachmentData): Promise<number>;
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Retrieves file data as an ArrayBuffer.
|
|
26
|
-
* @param filePath Path where the file is stored
|
|
32
|
+
* @param filePath - Path where the file is stored
|
|
27
33
|
* @returns ArrayBuffer containing the file data
|
|
28
34
|
*/
|
|
29
35
|
readFile(filePath: string): Promise<ArrayBuffer>;
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
38
|
* Deletes the file at the given path.
|
|
33
|
-
* @param filePath Path where the file is stored
|
|
39
|
+
* @param filePath - Path where the file is stored
|
|
34
40
|
*/
|
|
35
41
|
deleteFile(filePath: string): Promise<void>;
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
44
|
* Checks if a file exists at the given path.
|
|
39
|
-
* @param filePath Path where the file is stored
|
|
45
|
+
* @param filePath - Path where the file is stored
|
|
40
46
|
* @returns True if the file exists, false otherwise
|
|
41
47
|
*/
|
|
42
48
|
fileExists(filePath: string): Promise<boolean>;
|
|
43
49
|
|
|
44
50
|
/**
|
|
45
51
|
* Creates a directory at the specified path.
|
|
46
|
-
* @param path The full path to the directory
|
|
52
|
+
* @param path - The full path to the directory
|
|
47
53
|
*/
|
|
48
54
|
makeDir(path: string): Promise<void>;
|
|
49
55
|
|
|
50
56
|
/**
|
|
51
57
|
* Removes a directory at the specified path.
|
|
52
|
-
* @param path The full path to the directory
|
|
58
|
+
* @param path - The full path to the directory
|
|
53
59
|
*/
|
|
54
60
|
rmDir(path: string): Promise<void>;
|
|
55
61
|
|
|
@@ -65,7 +71,7 @@ export interface LocalStorageAdapter {
|
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
73
|
* Returns the file path for the provided filename in the storage directory.
|
|
68
|
-
* @param filename The filename to get the path for
|
|
74
|
+
* @param filename - The filename to get the path for
|
|
69
75
|
* @returns The full file path
|
|
70
76
|
*/
|
|
71
77
|
getLocalUri(filename: string): string;
|
|
@@ -427,10 +427,12 @@ type WatchedAttachmentItem = {
|
|
|
427
427
|
id: string;
|
|
428
428
|
fileExtension: string; // e.g., 'jpg', 'pdf'
|
|
429
429
|
metaData?: string;
|
|
430
|
+
mediaType?: string; // e.g., 'image/jpeg'
|
|
430
431
|
} | {
|
|
431
432
|
id: string;
|
|
432
433
|
filename: string; // e.g., 'document.pdf'
|
|
433
434
|
metaData?: string;
|
|
435
|
+
mediaType?: string; // e.g., 'application/pdf'
|
|
434
436
|
};
|
|
435
437
|
```
|
|
436
438
|
|
|
@@ -10,21 +10,21 @@ import { AttachmentRecord } from './Schema.js';
|
|
|
10
10
|
export interface RemoteStorageAdapter {
|
|
11
11
|
/**
|
|
12
12
|
* Uploads a file to remote storage.
|
|
13
|
-
* @param fileData The binary content of the file to upload
|
|
14
|
-
* @param attachment The associated attachment metadata
|
|
13
|
+
* @param fileData - The binary content of the file to upload
|
|
14
|
+
* @param attachment - The associated attachment metadata
|
|
15
15
|
*/
|
|
16
16
|
uploadFile(fileData: ArrayBuffer, attachment: AttachmentRecord): Promise<void>;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Downloads a file from remote storage.
|
|
20
|
-
* @param attachment The attachment describing the file to download
|
|
20
|
+
* @param attachment - The attachment describing the file to download
|
|
21
21
|
* @returns The binary data of the downloaded file
|
|
22
22
|
*/
|
|
23
23
|
downloadFile(attachment: AttachmentRecord): Promise<ArrayBuffer>;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Deletes a file from remote storage.
|
|
27
|
-
* @param attachment The attachment describing the file to delete
|
|
27
|
+
* @param attachment - The attachment describing the file to delete
|
|
28
28
|
*/
|
|
29
29
|
deleteFile(attachment: AttachmentRecord): Promise<void>;
|
|
30
30
|
}
|
|
@@ -2,12 +2,17 @@ import { column } from '../db/schema/Column.js';
|
|
|
2
2
|
import { Table } from '../db/schema/Table.js';
|
|
3
3
|
import { TableV2Options } from '../db/schema/Table.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The default name of the local table storing attachment data.
|
|
7
|
+
*
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
5
10
|
export const ATTACHMENT_TABLE = 'attachments';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* AttachmentRecord represents an attachment in the local database.
|
|
9
14
|
*
|
|
10
|
-
* @
|
|
15
|
+
* @alpha
|
|
11
16
|
*/
|
|
12
17
|
export interface AttachmentRecord {
|
|
13
18
|
id: string;
|
|
@@ -27,7 +32,7 @@ export interface AttachmentRecord {
|
|
|
27
32
|
* @param row - The database row object
|
|
28
33
|
* @returns The corresponding AttachmentRecord
|
|
29
34
|
*
|
|
30
|
-
* @
|
|
35
|
+
* @alpha
|
|
31
36
|
*/
|
|
32
37
|
export function attachmentFromSql(row: any): AttachmentRecord {
|
|
33
38
|
return {
|
|
@@ -46,7 +51,7 @@ export function attachmentFromSql(row: any): AttachmentRecord {
|
|
|
46
51
|
/**
|
|
47
52
|
* AttachmentState represents the current synchronization state of an attachment.
|
|
48
53
|
*
|
|
49
|
-
* @
|
|
54
|
+
* @alpha
|
|
50
55
|
*/
|
|
51
56
|
export enum AttachmentState {
|
|
52
57
|
QUEUED_UPLOAD = 0, // Attachment to be uploaded
|
|
@@ -56,12 +61,15 @@ export enum AttachmentState {
|
|
|
56
61
|
ARCHIVED = 4 // Attachment has been orphaned, i.e. the associated record has been deleted
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
59
67
|
export interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {}
|
|
60
68
|
|
|
61
69
|
/**
|
|
62
70
|
* AttachmentTable defines the schema for the attachment queue table.
|
|
63
71
|
*
|
|
64
|
-
* @
|
|
72
|
+
* @alpha
|
|
65
73
|
*/
|
|
66
74
|
export class AttachmentTable extends Table {
|
|
67
75
|
constructor(options?: AttachmentTableOptions) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WatchedAttachmentItem represents an attachment reference in your application's data model.
|
|
3
3
|
* Use either filename OR fileExtension (not both).
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
5
|
+
* @alpha
|
|
6
6
|
*/
|
|
7
7
|
export type WatchedAttachmentItem =
|
|
8
8
|
| {
|
|
@@ -10,10 +10,12 @@ export type WatchedAttachmentItem =
|
|
|
10
10
|
filename: string;
|
|
11
11
|
fileExtension?: never;
|
|
12
12
|
metaData?: string;
|
|
13
|
+
mediaType?: string;
|
|
13
14
|
}
|
|
14
15
|
| {
|
|
15
16
|
id: string;
|
|
16
17
|
fileExtension: string;
|
|
17
18
|
filename?: never;
|
|
18
19
|
metaData?: string;
|
|
20
|
+
mediaType?: string;
|
|
19
21
|
};
|