@powersync/common 1.53.2 → 1.55.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 +922 -772
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +922 -772
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +923 -619
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +923 -619
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +749 -205
- 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 +82 -33
- 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 -60
- package/lib/client/AbstractPowerSyncDatabase.js +77 -74
- 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 +59 -27
- 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/async.d.ts +26 -0
- package/lib/utils/async.js +114 -27
- package/lib/utils/async.js.map +1 -1
- package/lib/utils/compatibility.d.ts +8 -0
- package/lib/utils/compatibility.js +9 -0
- package/lib/utils/compatibility.js.map +1 -0
- 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 -3
- package/src/attachments/AttachmentContext.ts +7 -6
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +93 -35
- 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 +135 -91
- 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 +76 -34
- 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/async.ts +136 -28
- package/src/utils/compatibility.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,68 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for {@link AttachmentQueue}.
|
|
17
|
+
*
|
|
18
|
+
* @experimental
|
|
19
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
20
|
+
*/
|
|
21
|
+
export interface AttachmentQueueOptions {
|
|
22
|
+
/**
|
|
23
|
+
* PowerSync database instance
|
|
24
|
+
*/
|
|
25
|
+
db: AbstractPowerSyncDatabase;
|
|
26
|
+
/**
|
|
27
|
+
* Remote storage adapter for upload/download operations
|
|
28
|
+
*/
|
|
29
|
+
remoteStorage: RemoteStorageAdapter;
|
|
30
|
+
/**
|
|
31
|
+
* Local storage adapter for file persistence
|
|
32
|
+
*/
|
|
33
|
+
localStorage: LocalStorageAdapter;
|
|
34
|
+
/**
|
|
35
|
+
* Callback for monitoring attachment changes in your data model
|
|
36
|
+
*/
|
|
37
|
+
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
40
|
+
*/
|
|
41
|
+
tableName?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Logger instance. Defaults to db.logger
|
|
44
|
+
*/
|
|
45
|
+
logger?: ILogger;
|
|
46
|
+
/**
|
|
47
|
+
* Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
|
|
48
|
+
*/
|
|
49
|
+
syncIntervalMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
|
|
52
|
+
*/
|
|
53
|
+
syncThrottleDuration?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to automatically download remote attachments. Default: true
|
|
56
|
+
*/
|
|
57
|
+
downloadAttachments?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Maximum archived attachments before cleanup. Default: 100
|
|
60
|
+
*/
|
|
61
|
+
archivedCacheLimit?: number;
|
|
62
|
+
|
|
63
|
+
/** Handler for upload, download and delete errors */
|
|
64
|
+
errorHandler?: AttachmentErrorHandler;
|
|
65
|
+
}
|
|
13
66
|
|
|
14
67
|
/**
|
|
15
68
|
* AttachmentQueue manages the lifecycle and synchronization of attachments
|
|
@@ -78,24 +131,14 @@ export class AttachmentQueue {
|
|
|
78
131
|
/** Cleanup function for status change listener */
|
|
79
132
|
private statusListenerDispose?: () => void;
|
|
80
133
|
|
|
81
|
-
private watchActiveAttachments
|
|
134
|
+
private watchActiveAttachments!: DifferentialWatchedQuery<AttachmentRecord>;
|
|
82
135
|
|
|
83
|
-
private watchAttachmentsAbortController
|
|
136
|
+
private watchAttachmentsAbortController!: AbortController;
|
|
84
137
|
|
|
85
138
|
/**
|
|
86
139
|
* Creates a new AttachmentQueue instance.
|
|
87
140
|
*
|
|
88
141
|
* @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
142
|
*/
|
|
100
143
|
constructor({
|
|
101
144
|
db,
|
|
@@ -109,19 +152,7 @@ export class AttachmentQueue {
|
|
|
109
152
|
downloadAttachments = true,
|
|
110
153
|
archivedCacheLimit = 100,
|
|
111
154
|
errorHandler
|
|
112
|
-
}: {
|
|
113
|
-
db: AbstractPowerSyncDatabase;
|
|
114
|
-
remoteStorage: RemoteStorageAdapter;
|
|
115
|
-
localStorage: LocalStorageAdapter;
|
|
116
|
-
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
117
|
-
tableName?: string;
|
|
118
|
-
logger?: ILogger;
|
|
119
|
-
syncIntervalMs?: number;
|
|
120
|
-
syncThrottleDuration?: number;
|
|
121
|
-
downloadAttachments?: boolean;
|
|
122
|
-
archivedCacheLimit?: number;
|
|
123
|
-
errorHandler?: AttachmentErrorHandler;
|
|
124
|
-
}) {
|
|
155
|
+
}: AttachmentQueueOptions) {
|
|
125
156
|
this.db = db;
|
|
126
157
|
this.remoteStorage = remoteStorage;
|
|
127
158
|
this.localStorage = localStorage;
|
|
@@ -228,6 +259,7 @@ export class AttachmentQueue {
|
|
|
228
259
|
state: AttachmentState.QUEUED_DOWNLOAD,
|
|
229
260
|
hasSynced: false,
|
|
230
261
|
metaData: watchedAttachment.metaData,
|
|
262
|
+
mediaType: watchedAttachment.mediaType,
|
|
231
263
|
timestamp: new Date().getTime()
|
|
232
264
|
});
|
|
233
265
|
continue;
|
|
@@ -321,17 +353,24 @@ export class AttachmentQueue {
|
|
|
321
353
|
}
|
|
322
354
|
}
|
|
323
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Provides an {@link AttachmentContext} to a callback.
|
|
358
|
+
*
|
|
359
|
+
* The callback runs while the attachment queue mutex is held. Do not call
|
|
360
|
+
* other {@link AttachmentQueue} methods from within the callback, as they may
|
|
361
|
+
* attempt to acquire the same mutex and block indefinitely.
|
|
362
|
+
*/
|
|
363
|
+
withAttachmentContext<T>(callback: (context: AttachmentContext) => Promise<T>): Promise<T> {
|
|
364
|
+
/**
|
|
365
|
+
* AttachmentService is internal and private in this class.
|
|
366
|
+
* We only need to expose its locking and context functionality for extending classes.
|
|
367
|
+
*/
|
|
368
|
+
return this.attachmentService.withContext(callback);
|
|
369
|
+
}
|
|
324
370
|
/**
|
|
325
371
|
* Saves a file to local storage and queues it for upload to remote storage.
|
|
326
372
|
*
|
|
327
373
|
* @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
374
|
* @returns Promise resolving to the created attachment record
|
|
336
375
|
*/
|
|
337
376
|
async saveFile({
|
|
@@ -342,11 +381,30 @@ export class AttachmentQueue {
|
|
|
342
381
|
id,
|
|
343
382
|
updateHook
|
|
344
383
|
}: {
|
|
384
|
+
/**
|
|
385
|
+
* The file data as ArrayBuffer, Blob, or base64 string
|
|
386
|
+
*/
|
|
345
387
|
data: AttachmentData;
|
|
388
|
+
/**
|
|
389
|
+
* File extension (e.g., 'jpg', 'pdf')
|
|
390
|
+
*/
|
|
346
391
|
fileExtension: string;
|
|
392
|
+
/**
|
|
393
|
+
* MIME type of the file (e.g., 'image/jpeg')
|
|
394
|
+
*/
|
|
347
395
|
mediaType?: string;
|
|
396
|
+
/**
|
|
397
|
+
* Optional metadata to associate with the attachment
|
|
398
|
+
*/
|
|
348
399
|
metaData?: string;
|
|
400
|
+
/**
|
|
401
|
+
* Optional custom ID. If not provided, a UUID will be generated
|
|
402
|
+
*/
|
|
349
403
|
id?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Optional callback to execute additional database operations within the same transaction as the attachment
|
|
406
|
+
* creation.
|
|
407
|
+
*/
|
|
350
408
|
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
351
409
|
}): Promise<AttachmentRecord> {
|
|
352
410
|
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
|
};
|