@pol-studios/powersync 1.0.7 → 1.0.10
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/README.md +933 -0
- package/dist/CacheSettingsManager-uz-kbnRH.d.ts +461 -0
- package/dist/attachments/index.d.ts +709 -6
- package/dist/attachments/index.js +133 -5
- package/dist/chunk-24RDMMCL.js +44 -0
- package/dist/chunk-24RDMMCL.js.map +1 -0
- package/dist/chunk-4TXTAEF2.js +2060 -0
- package/dist/chunk-4TXTAEF2.js.map +1 -0
- package/dist/chunk-63PXSPIN.js +358 -0
- package/dist/chunk-63PXSPIN.js.map +1 -0
- package/dist/chunk-654ERHA7.js +1 -0
- package/dist/{chunk-BREGB4WL.js → chunk-BRXQNASY.js} +287 -335
- package/dist/chunk-BRXQNASY.js.map +1 -0
- package/dist/{chunk-DHYUBVP7.js → chunk-CAB26E6F.js} +20 -9
- package/dist/chunk-CAB26E6F.js.map +1 -0
- package/dist/{chunk-H772V6XQ.js → chunk-CUCAYK7Z.js} +7 -43
- package/dist/chunk-CUCAYK7Z.js.map +1 -0
- package/dist/{chunk-4C3RY5SU.js → chunk-HWSNV45P.js} +76 -1
- package/dist/chunk-HWSNV45P.js.map +1 -0
- package/dist/{chunk-HFOFLW5F.js → chunk-KN2IZERF.js} +139 -6
- package/dist/chunk-KN2IZERF.js.map +1 -0
- package/dist/{chunk-UEYRTLKE.js → chunk-P4HZA6ZT.js} +20 -9
- package/dist/chunk-P4HZA6ZT.js.map +1 -0
- package/dist/chunk-T4AO7JIG.js +1 -0
- package/dist/{chunk-XQAJM2MW.js → chunk-VACPAAQZ.js} +33 -2
- package/dist/{chunk-XQAJM2MW.js.map → chunk-VACPAAQZ.js.map} +1 -1
- package/dist/{chunk-53WH2JJV.js → chunk-WN5ZJ3E2.js} +5 -8
- package/dist/chunk-WN5ZJ3E2.js.map +1 -0
- package/dist/chunk-XAEII4ZX.js +456 -0
- package/dist/chunk-XAEII4ZX.js.map +1 -0
- package/dist/chunk-XOY2CJ67.js +289 -0
- package/dist/chunk-XOY2CJ67.js.map +1 -0
- package/dist/chunk-YHTZ7VMV.js +1 -0
- package/dist/{chunk-MKD2VCX3.js → chunk-Z6VOBGTU.js} +8 -8
- package/dist/chunk-Z6VOBGTU.js.map +1 -0
- package/dist/chunk-ZM4ENYMF.js +230 -0
- package/dist/chunk-ZM4ENYMF.js.map +1 -0
- package/dist/connector/index.d.ts +56 -3
- package/dist/connector/index.js +8 -5
- package/dist/core/index.d.ts +12 -1
- package/dist/core/index.js +3 -2
- package/dist/error/index.js +0 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.js +191 -29
- package/dist/index.native.d.ts +11 -9
- package/dist/index.native.js +191 -29
- package/dist/index.web.d.ts +11 -9
- package/dist/index.web.js +191 -29
- package/dist/maintenance/index.js +0 -1
- package/dist/platform/index.js +0 -2
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/index.native.js +1 -2
- package/dist/platform/index.web.js +0 -1
- package/dist/pol-attachment-queue-BVAIueoP.d.ts +817 -0
- package/dist/provider/index.d.ts +38 -34
- package/dist/provider/index.js +11 -12
- package/dist/react/index.d.ts +372 -0
- package/dist/react/index.js +25 -0
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.js +22 -8
- package/dist/storage/index.native.d.ts +3 -3
- package/dist/storage/index.native.js +21 -7
- package/dist/storage/index.web.d.ts +3 -3
- package/dist/storage/index.web.js +21 -7
- package/dist/storage/upload/index.d.ts +7 -8
- package/dist/storage/upload/index.js +3 -3
- package/dist/storage/upload/index.native.d.ts +7 -8
- package/dist/storage/upload/index.native.js +4 -3
- package/dist/storage/upload/index.web.d.ts +1 -4
- package/dist/storage/upload/index.web.js +3 -3
- package/dist/supabase-connector-T9vHq_3i.d.ts +202 -0
- package/dist/sync/index.js +3 -3
- package/dist/{supabase-connector-qLm-WHkM.d.ts → types-B212hgfA.d.ts} +48 -170
- package/dist/{types-BVacP54t.d.ts → types-CyvBaAl8.d.ts} +12 -4
- package/dist/types-D0WcHrq6.d.ts +234 -0
- package/package.json +18 -4
- package/dist/CacheSettingsManager-1exbOC6S.d.ts +0 -261
- package/dist/chunk-4C3RY5SU.js.map +0 -1
- package/dist/chunk-53WH2JJV.js.map +0 -1
- package/dist/chunk-BREGB4WL.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DHYUBVP7.js.map +0 -1
- package/dist/chunk-GKF7TOMT.js +0 -1
- package/dist/chunk-H772V6XQ.js.map +0 -1
- package/dist/chunk-HFOFLW5F.js.map +0 -1
- package/dist/chunk-KGSFAE5B.js +0 -1
- package/dist/chunk-LNL64IJZ.js +0 -1
- package/dist/chunk-MKD2VCX3.js.map +0 -1
- package/dist/chunk-UEYRTLKE.js.map +0 -1
- package/dist/chunk-WQ5MPAVC.js +0 -449
- package/dist/chunk-WQ5MPAVC.js.map +0 -1
- package/dist/chunk-ZEOKPWUC.js +0 -1165
- package/dist/chunk-ZEOKPWUC.js.map +0 -1
- package/dist/pol-attachment-queue-C7YNXXhK.d.ts +0 -676
- package/dist/types-Bgvx7-E8.d.ts +0 -187
- /package/dist/{chunk-DGUM43GV.js.map → chunk-654ERHA7.js.map} +0 -0
- /package/dist/{chunk-GKF7TOMT.js.map → chunk-T4AO7JIG.js.map} +0 -0
- /package/dist/{chunk-KGSFAE5B.js.map → chunk-YHTZ7VMV.js.map} +0 -0
- /package/dist/{chunk-LNL64IJZ.js.map → react/index.js.map} +0 -0
|
@@ -1,676 +0,0 @@
|
|
|
1
|
-
import { AbstractAttachmentQueue, AttachmentQueueOptions, AttachmentRecord as AttachmentRecord$1 } from '@powersync/attachments';
|
|
2
|
-
import { AbstractPowerSyncDatabase } from '@powersync/common';
|
|
3
|
-
import { PlatformAdapter } from './platform/index.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Attachment Queue Types for @pol-studios/powersync
|
|
7
|
-
*
|
|
8
|
-
* This module re-exports types from the official @powersync/attachments package
|
|
9
|
-
* and extends them with POL-specific features like:
|
|
10
|
-
* - FAILED_PERMANENT state for permanent upload failures
|
|
11
|
-
* - Upload metadata fields for retry tracking
|
|
12
|
-
* - Source table configuration for flexible attachment watching
|
|
13
|
-
* - Image compression configuration
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: The official AttachmentState enum has different numeric values:
|
|
16
|
-
* Official: QUEUED_SYNC=0, QUEUED_UPLOAD=1, QUEUED_DOWNLOAD=2, SYNCED=3, ARCHIVED=4
|
|
17
|
-
*
|
|
18
|
-
* We extend this with FAILED_PERMANENT=5 for permanent upload failures.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Extended attachment state that includes permanent failure state.
|
|
23
|
-
*
|
|
24
|
-
* Values 0-4 match the official @powersync/attachments AttachmentState.
|
|
25
|
-
* Value 5 (FAILED_PERMANENT) is our extension for uploads that have
|
|
26
|
-
* exhausted retries or encountered unrecoverable errors.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { AttachmentState } from '@powersync/attachments';
|
|
31
|
-
* import { PolAttachmentState } from '@pol-studios/powersync/attachments';
|
|
32
|
-
*
|
|
33
|
-
* // Use official states
|
|
34
|
-
* const queued = AttachmentState.QUEUED_UPLOAD;
|
|
35
|
-
*
|
|
36
|
-
* // Use our extension
|
|
37
|
-
* const failed = PolAttachmentState.FAILED_PERMANENT;
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare enum PolAttachmentState {
|
|
41
|
-
/** Check if the attachment needs to be uploaded or downloaded */
|
|
42
|
-
QUEUED_SYNC = 0,
|
|
43
|
-
/** Attachment to be uploaded */
|
|
44
|
-
QUEUED_UPLOAD = 1,
|
|
45
|
-
/** Attachment to be downloaded */
|
|
46
|
-
QUEUED_DOWNLOAD = 2,
|
|
47
|
-
/** Attachment has been synced */
|
|
48
|
-
SYNCED = 3,
|
|
49
|
-
/** Attachment has been orphaned, i.e. the associated record has been deleted */
|
|
50
|
-
ARCHIVED = 4,
|
|
51
|
-
/** Permanently failed (exhausted retries or unrecoverable error) - POL extension */
|
|
52
|
-
FAILED_PERMANENT = 5
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extended attachment record with POL-specific upload tracking fields.
|
|
56
|
-
*
|
|
57
|
-
* Extends the official AttachmentRecord with fields for:
|
|
58
|
-
* - Upload retry tracking
|
|
59
|
-
* - Error information
|
|
60
|
-
* - Upload metadata for onComplete callbacks
|
|
61
|
-
*/
|
|
62
|
-
interface PolAttachmentRecord {
|
|
63
|
-
/** Unique identifier (typically storage path) */
|
|
64
|
-
id: string;
|
|
65
|
-
/** Filename for display and type inference */
|
|
66
|
-
filename: string;
|
|
67
|
-
/** Local file URI (set after download/upload) */
|
|
68
|
-
local_uri?: string | null;
|
|
69
|
-
/** File size in bytes */
|
|
70
|
-
size?: number;
|
|
71
|
-
/** MIME type of the file */
|
|
72
|
-
media_type?: string;
|
|
73
|
-
/** Timestamp when the attachment was created/modified */
|
|
74
|
-
timestamp?: number;
|
|
75
|
-
/** Current state in the queue */
|
|
76
|
-
state: number;
|
|
77
|
-
/** Local file URI in managed cache (for uploads) */
|
|
78
|
-
upload_source_uri?: string | null;
|
|
79
|
-
/** Last upload error message */
|
|
80
|
-
upload_error?: string | null;
|
|
81
|
-
/** HTTP status or error code */
|
|
82
|
-
upload_error_code?: string | null;
|
|
83
|
-
/** Number of upload retry attempts */
|
|
84
|
-
upload_retry_count?: number;
|
|
85
|
-
/** Timestamp for next retry */
|
|
86
|
-
upload_next_retry_at?: number;
|
|
87
|
-
/** JSON-serialized entity metadata for onComplete */
|
|
88
|
-
upload_metadata?: string | null;
|
|
89
|
-
/** Target storage bucket ID */
|
|
90
|
-
upload_bucket_id?: string | null;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Configuration for the source table that contains attachment references.
|
|
94
|
-
* This makes the attachment queue reusable across different tables/projects.
|
|
95
|
-
*/
|
|
96
|
-
interface AttachmentSourceConfig {
|
|
97
|
-
/**
|
|
98
|
-
* Table name containing attachment references.
|
|
99
|
-
* @example "EquipmentUnitMediaContent"
|
|
100
|
-
*/
|
|
101
|
-
table: string;
|
|
102
|
-
/**
|
|
103
|
-
* Column containing the storage path / attachment ID.
|
|
104
|
-
* @example "storagePath"
|
|
105
|
-
*/
|
|
106
|
-
idColumn: string;
|
|
107
|
-
/**
|
|
108
|
-
* Column to order by for "newest first" downloads.
|
|
109
|
-
* Set to null to skip ordering.
|
|
110
|
-
* @example "takenOn"
|
|
111
|
-
*/
|
|
112
|
-
orderByColumn?: string | null;
|
|
113
|
-
/**
|
|
114
|
-
* Optional filter config to exclude attachments from archived/unsynced projects.
|
|
115
|
-
* When set, the attachment query JOINs through intermediary tables to ensure
|
|
116
|
-
* only attachments belonging to synced projects are downloaded.
|
|
117
|
-
*/
|
|
118
|
-
projectFilter?: {
|
|
119
|
-
/** Foreign key column in the source table (e.g., "equipmentUnitId") */
|
|
120
|
-
foreignKey: string;
|
|
121
|
-
/** Intermediary table to JOIN through (e.g., "EquipmentFixtureUnit") */
|
|
122
|
-
intermediaryTable: string;
|
|
123
|
-
/** Column in intermediary table that links to ProjectDatabase (e.g., "projectDatabaseId") */
|
|
124
|
-
projectForeignKey: string;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Interface for remote attachment storage operations (e.g., Supabase Storage).
|
|
129
|
-
*
|
|
130
|
-
* This is used by PolStorageAdapter to handle remote file operations.
|
|
131
|
-
* For local file operations, we use PlatformAdapter.fileSystem.
|
|
132
|
-
*/
|
|
133
|
-
interface AttachmentStorageAdapter {
|
|
134
|
-
/**
|
|
135
|
-
* Download a file from remote storage.
|
|
136
|
-
* @param filePath - The storage path of the file
|
|
137
|
-
* @returns The file data as a Blob or base64 string
|
|
138
|
-
*/
|
|
139
|
-
downloadFile(filePath: string): Promise<Blob | string>;
|
|
140
|
-
/**
|
|
141
|
-
* Upload a file to remote storage (optional - not all queues need upload).
|
|
142
|
-
* @param filePath - The storage path to upload to
|
|
143
|
-
* @param data - The file data to upload (base64 string or Blob)
|
|
144
|
-
*/
|
|
145
|
-
uploadFile?(filePath: string, data: Blob | string): Promise<void>;
|
|
146
|
-
/**
|
|
147
|
-
* Delete a file from remote storage (optional).
|
|
148
|
-
* @param filePath - The storage path of the file
|
|
149
|
-
*/
|
|
150
|
-
deleteFile?(filePath: string): Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* Resolve the storage bucket for a file path.
|
|
153
|
-
* Allows routing different files to different buckets.
|
|
154
|
-
* @param filePath - The file path to resolve
|
|
155
|
-
* @returns The bucket name
|
|
156
|
-
*/
|
|
157
|
-
resolveBucket?(filePath: string): string;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Configuration for image compression.
|
|
161
|
-
*/
|
|
162
|
-
interface CompressionConfig {
|
|
163
|
-
/** Enable compression (default: true) */
|
|
164
|
-
enabled: boolean;
|
|
165
|
-
/** Compression quality 0.0-1.0 (default: 0.7) */
|
|
166
|
-
quality: number;
|
|
167
|
-
/** Max width before resizing (default: 2048) */
|
|
168
|
-
maxWidth: number;
|
|
169
|
-
/** Skip files under this size in bytes (default: 100KB) */
|
|
170
|
-
skipSizeBytes: number;
|
|
171
|
-
/** Skip if already under this size in bytes (default: 300KB) */
|
|
172
|
-
targetSizeBytes: number;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Default compression configuration.
|
|
176
|
-
*/
|
|
177
|
-
declare const DEFAULT_COMPRESSION_CONFIG: CompressionConfig;
|
|
178
|
-
/**
|
|
179
|
-
* Configuration for the upload engine.
|
|
180
|
-
*/
|
|
181
|
-
interface UploadConfig {
|
|
182
|
-
/** Maximum concurrent uploads (default: 3) */
|
|
183
|
-
concurrency: number;
|
|
184
|
-
/** Upload timeout per file in ms (default: 120000) */
|
|
185
|
-
timeoutMs: number;
|
|
186
|
-
/** Base retry delay in ms (default: 5000) */
|
|
187
|
-
baseRetryDelayMs: number;
|
|
188
|
-
/** Maximum retry delay in ms (default: 3600000 = 1 hour) */
|
|
189
|
-
maxRetryDelayMs: number;
|
|
190
|
-
/** Days before marking upload as stale (default: 7) */
|
|
191
|
-
staleDaysThreshold: number;
|
|
192
|
-
/** Maximum number of retry attempts before marking as FAILED_PERMANENT (default: 100) */
|
|
193
|
-
maxRetryCount: number;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Default upload configuration.
|
|
197
|
-
*
|
|
198
|
-
* Note: baseRetryDelayMs is set to 30s (not 5s) to reduce battery consumption.
|
|
199
|
-
* The exponential backoff sequence will be: 30s, 60s, 2min, 4min, 8min, 16min, 32min, 1hr (capped).
|
|
200
|
-
*/
|
|
201
|
-
declare const DEFAULT_UPLOAD_CONFIG: UploadConfig;
|
|
202
|
-
/**
|
|
203
|
-
* Interface for handling file uploads to remote storage.
|
|
204
|
-
* Separate from AttachmentStorageAdapter to allow different implementations.
|
|
205
|
-
*/
|
|
206
|
-
interface UploadHandler {
|
|
207
|
-
/**
|
|
208
|
-
* Upload a file to remote storage.
|
|
209
|
-
* @param storagePath - The storage path to upload to
|
|
210
|
-
* @param localFileUri - Local file URI to upload from
|
|
211
|
-
* @param mediaType - MIME type of the file
|
|
212
|
-
* @param signal - Optional AbortSignal for cancellation support
|
|
213
|
-
*/
|
|
214
|
-
uploadFile(storagePath: string, localFileUri: string, mediaType: string, signal?: AbortSignal): Promise<void>;
|
|
215
|
-
/**
|
|
216
|
-
* Optional: resolve the storage bucket for a file path.
|
|
217
|
-
* @param storagePath - The file path to resolve
|
|
218
|
-
* @returns The bucket name
|
|
219
|
-
*/
|
|
220
|
-
resolveBucket?(storagePath: string): string;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Configuration for cache management.
|
|
224
|
-
*/
|
|
225
|
-
interface CacheConfig {
|
|
226
|
-
/** Maximum cache size in bytes (default: 5GB) */
|
|
227
|
-
maxSize: number;
|
|
228
|
-
/** Stop downloads at this percentage of max (default: 0.95 = 95%) */
|
|
229
|
-
downloadStopThreshold: number;
|
|
230
|
-
/** Trigger eviction at this percentage (default: 1.0 = 100%) */
|
|
231
|
-
evictionTriggerThreshold: number;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Default cache configuration.
|
|
235
|
-
*/
|
|
236
|
-
declare const DEFAULT_CACHE_CONFIG: CacheConfig;
|
|
237
|
-
/**
|
|
238
|
-
* Configuration for the POL attachment queue.
|
|
239
|
-
* Extends the official @powersync/attachments options with our features.
|
|
240
|
-
*/
|
|
241
|
-
interface PolAttachmentQueueConfig {
|
|
242
|
-
/** Source table configuration for watching attachment IDs */
|
|
243
|
-
source: AttachmentSourceConfig;
|
|
244
|
-
/** Remote storage adapter for downloading files */
|
|
245
|
-
remoteStorage: AttachmentStorageAdapter;
|
|
246
|
-
/** Table name for storing attachment records (default: "attachments") */
|
|
247
|
-
attachmentTableName?: string;
|
|
248
|
-
/** Perform initial sync on initialization (default: true) */
|
|
249
|
-
performInitialSync?: boolean;
|
|
250
|
-
/** Cache configuration */
|
|
251
|
-
cache?: Partial<CacheConfig>;
|
|
252
|
-
/** Compression configuration */
|
|
253
|
-
compression?: Partial<CompressionConfig>;
|
|
254
|
-
/**
|
|
255
|
-
* Called when a download fails.
|
|
256
|
-
* Return { retry: true } to retry, { retry: false } to skip.
|
|
257
|
-
*/
|
|
258
|
-
onDownloadError?: (attachment: PolAttachmentRecord, error: Error) => Promise<{
|
|
259
|
-
retry: boolean;
|
|
260
|
-
}>;
|
|
261
|
-
/**
|
|
262
|
-
* Called when sync progress changes.
|
|
263
|
-
*/
|
|
264
|
-
onProgress?: (stats: AttachmentSyncStats) => void;
|
|
265
|
-
/** Upload configuration (optional - enables upload queue) */
|
|
266
|
-
upload?: {
|
|
267
|
-
handler: UploadHandler;
|
|
268
|
-
config?: Partial<UploadConfig>;
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* Called when an upload completes successfully.
|
|
272
|
-
* Use this to create CRUD records after file upload.
|
|
273
|
-
*/
|
|
274
|
-
onUploadComplete?: (record: PolAttachmentRecord) => Promise<void>;
|
|
275
|
-
/**
|
|
276
|
-
* Called when an upload fails permanently.
|
|
277
|
-
*/
|
|
278
|
-
onUploadFailed?: (record: PolAttachmentRecord, error: Error) => void;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Current phase of a download operation.
|
|
282
|
-
*/
|
|
283
|
-
type DownloadPhase = 'downloading' | 'compressing' | 'complete' | 'error';
|
|
284
|
-
/**
|
|
285
|
-
* Status of an individual download.
|
|
286
|
-
*/
|
|
287
|
-
interface DownloadStatus {
|
|
288
|
-
/** Attachment ID */
|
|
289
|
-
id: string;
|
|
290
|
-
/** Filename being downloaded */
|
|
291
|
-
filename: string;
|
|
292
|
-
/** Current phase */
|
|
293
|
-
phase: DownloadPhase;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Current phase of an upload operation.
|
|
297
|
-
*/
|
|
298
|
-
type UploadPhase = 'uploading' | 'waiting' | 'complete' | 'error' | 'permanent_failure';
|
|
299
|
-
/**
|
|
300
|
-
* Status of an individual upload.
|
|
301
|
-
*/
|
|
302
|
-
interface UploadStatus {
|
|
303
|
-
/** Attachment ID */
|
|
304
|
-
id: string;
|
|
305
|
-
/** Filename being uploaded */
|
|
306
|
-
filename: string;
|
|
307
|
-
/** Current phase */
|
|
308
|
-
phase: UploadPhase;
|
|
309
|
-
/** Upload progress (0-100) */
|
|
310
|
-
progress?: number;
|
|
311
|
-
/** Error message if failed */
|
|
312
|
-
error?: string;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Why downloads are stopped (if not actively syncing).
|
|
316
|
-
*/
|
|
317
|
-
type AttachmentSyncStatus = 'syncing' | 'paused' | 'cache_full' | 'complete';
|
|
318
|
-
/**
|
|
319
|
-
* Statistics about the attachment sync progress.
|
|
320
|
-
*/
|
|
321
|
-
interface AttachmentSyncStats {
|
|
322
|
-
/** Number of attachments that have been downloaded */
|
|
323
|
-
syncedCount: number;
|
|
324
|
-
/** Total size of synced attachments in bytes */
|
|
325
|
-
syncedSize: number;
|
|
326
|
-
/** Number of attachments waiting to be downloaded */
|
|
327
|
-
pendingCount: number;
|
|
328
|
-
/** Total expected attachments (synced + pending) */
|
|
329
|
-
totalExpected: number;
|
|
330
|
-
/** Maximum cache size in bytes */
|
|
331
|
-
maxCacheSize: number;
|
|
332
|
-
/** Current compression quality (0.1 to 1.0) */
|
|
333
|
-
compressionQuality: number;
|
|
334
|
-
/** Current sync status */
|
|
335
|
-
status: AttachmentSyncStatus;
|
|
336
|
-
/** Whether downloads are paused */
|
|
337
|
-
isPaused: boolean;
|
|
338
|
-
/** Whether currently processing downloads */
|
|
339
|
-
isProcessing: boolean;
|
|
340
|
-
/** Currently active downloads */
|
|
341
|
-
activeDownloads: DownloadStatus[];
|
|
342
|
-
/** Number of uploads waiting to be processed */
|
|
343
|
-
pendingUploadCount: number;
|
|
344
|
-
/** Number of permanently failed uploads */
|
|
345
|
-
failedPermanentCount: number;
|
|
346
|
-
/** Number of uploads failing > staleDaysThreshold */
|
|
347
|
-
staleUploadCount: number;
|
|
348
|
-
/** Currently active uploads */
|
|
349
|
-
activeUploads: UploadStatus[];
|
|
350
|
-
}
|
|
351
|
-
/** Row from stats query */
|
|
352
|
-
interface AttachmentStatsRow {
|
|
353
|
-
state: number;
|
|
354
|
-
cnt: number;
|
|
355
|
-
sz: number;
|
|
356
|
-
}
|
|
357
|
-
/** Row for cache file operations */
|
|
358
|
-
interface CacheFileRow {
|
|
359
|
-
id: string;
|
|
360
|
-
local_uri: string;
|
|
361
|
-
}
|
|
362
|
-
/** Row for eviction operations */
|
|
363
|
-
interface EvictRow {
|
|
364
|
-
id: string;
|
|
365
|
-
local_uri: string;
|
|
366
|
-
size: number;
|
|
367
|
-
}
|
|
368
|
-
/** Row for cached size queries */
|
|
369
|
-
interface CachedSizeRow {
|
|
370
|
-
total: number;
|
|
371
|
-
}
|
|
372
|
-
/** Row for ID queries */
|
|
373
|
-
interface IdRow {
|
|
374
|
-
id: string;
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Alias for PolAttachmentRecord.
|
|
378
|
-
* Use PolAttachmentRecord for new code. The official @powersync/attachments
|
|
379
|
-
* AttachmentRecord is exported as OfficialAttachmentRecord.
|
|
380
|
-
*/
|
|
381
|
-
type AttachmentRecord = PolAttachmentRecord;
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* POL Attachment Queue
|
|
385
|
-
*
|
|
386
|
-
* Extends the official @powersync/attachments AbstractAttachmentQueue with
|
|
387
|
-
* POL-specific features:
|
|
388
|
-
* - Configurable source table watching for attachment IDs
|
|
389
|
-
* - Project filtering for multi-tenant scenarios
|
|
390
|
-
* - Durable upload queue with exponential backoff retry
|
|
391
|
-
* - FAILED_PERMANENT state for unrecoverable upload errors
|
|
392
|
-
* - Image compression integration
|
|
393
|
-
* - Upload callbacks (onUploadComplete, onUploadFailed)
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```typescript
|
|
397
|
-
* const queue = new PolAttachmentQueue({
|
|
398
|
-
* powersync: db,
|
|
399
|
-
* storage: storageAdapter,
|
|
400
|
-
* source: {
|
|
401
|
-
* table: 'EquipmentUnitMediaContent',
|
|
402
|
-
* idColumn: 'storagePath',
|
|
403
|
-
* orderByColumn: 'takenOn',
|
|
404
|
-
* },
|
|
405
|
-
* });
|
|
406
|
-
*
|
|
407
|
-
* await queue.init();
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Options for PolAttachmentQueue that extend the official AttachmentQueueOptions.
|
|
413
|
-
*/
|
|
414
|
-
interface PolAttachmentQueueOptions extends AttachmentQueueOptions {
|
|
415
|
-
/**
|
|
416
|
-
* Platform adapter for file system and other platform operations.
|
|
417
|
-
*/
|
|
418
|
-
platform: PlatformAdapter;
|
|
419
|
-
/**
|
|
420
|
-
* Remote storage adapter for upload/download operations.
|
|
421
|
-
*/
|
|
422
|
-
remoteStorage: AttachmentStorageAdapter;
|
|
423
|
-
/**
|
|
424
|
-
* Source table configuration for watching attachment IDs.
|
|
425
|
-
*/
|
|
426
|
-
source: AttachmentSourceConfig;
|
|
427
|
-
/**
|
|
428
|
-
* Upload handler for uploading files to remote storage.
|
|
429
|
-
*/
|
|
430
|
-
uploadHandler?: UploadHandler;
|
|
431
|
-
/**
|
|
432
|
-
* Upload configuration.
|
|
433
|
-
*/
|
|
434
|
-
uploadConfig?: Partial<UploadConfig>;
|
|
435
|
-
/**
|
|
436
|
-
* Called when an upload completes successfully.
|
|
437
|
-
*/
|
|
438
|
-
onUploadComplete?: (record: PolAttachmentRecord) => Promise<void>;
|
|
439
|
-
/**
|
|
440
|
-
* Called when an upload fails permanently.
|
|
441
|
-
*/
|
|
442
|
-
onUploadFailed?: (record: PolAttachmentRecord, error: Error) => void;
|
|
443
|
-
/**
|
|
444
|
-
* Compression configuration.
|
|
445
|
-
*/
|
|
446
|
-
compression?: Partial<CompressionConfig>;
|
|
447
|
-
/**
|
|
448
|
-
* Cache configuration.
|
|
449
|
-
*/
|
|
450
|
-
cache?: Partial<CacheConfig>;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* POL Attachment Queue that extends the official AbstractAttachmentQueue.
|
|
454
|
-
*
|
|
455
|
-
* This class adds:
|
|
456
|
-
* - Configurable source table watching (not hardcoded to a single table)
|
|
457
|
-
* - Project filtering for multi-tenant scenarios
|
|
458
|
-
* - Durable upload queue with exponential backoff
|
|
459
|
-
* - FAILED_PERMANENT state for permanent upload failures
|
|
460
|
-
* - Image compression integration
|
|
461
|
-
*/
|
|
462
|
-
declare class PolAttachmentQueue extends AbstractAttachmentQueue<PolAttachmentQueueOptions> {
|
|
463
|
-
/**
|
|
464
|
-
* Override parent's watchUploads to prevent dual upload engines.
|
|
465
|
-
* POL uses custom _startUploadProcessing() for uploads with:
|
|
466
|
-
* - Exponential backoff retry
|
|
467
|
-
* - Compression support
|
|
468
|
-
* - Custom metadata handling
|
|
469
|
-
*
|
|
470
|
-
* The parent's simple upload watcher would conflict and fail
|
|
471
|
-
* because POL records use upload_source_uri instead of local_uri.
|
|
472
|
-
*/
|
|
473
|
-
watchUploads(): void;
|
|
474
|
-
/**
|
|
475
|
-
* Override parent's uploadAttachment to prevent misuse.
|
|
476
|
-
* POL uploads use upload_source_uri, not local_uri.
|
|
477
|
-
* External code should use queueUpload() instead.
|
|
478
|
-
*/
|
|
479
|
-
uploadAttachment(record: {
|
|
480
|
-
id: string;
|
|
481
|
-
}): Promise<boolean>;
|
|
482
|
-
private readonly platform;
|
|
483
|
-
private readonly polLogger;
|
|
484
|
-
private readonly source;
|
|
485
|
-
private readonly uploadHandler?;
|
|
486
|
-
private readonly uploadConfig;
|
|
487
|
-
private readonly compressionConfig;
|
|
488
|
-
private readonly cacheConfig;
|
|
489
|
-
private _uploadProcessing;
|
|
490
|
-
private _uploadPaused;
|
|
491
|
-
private _uploadAbort;
|
|
492
|
-
private _activeUploads;
|
|
493
|
-
private _watchInterval;
|
|
494
|
-
private _disposed;
|
|
495
|
-
private _initialized;
|
|
496
|
-
private _progressCallbacks;
|
|
497
|
-
private _lastNotifyTime;
|
|
498
|
-
private _notifyTimer;
|
|
499
|
-
private _cachedStats;
|
|
500
|
-
private _cachedStatsTimestamp;
|
|
501
|
-
constructor(options: PolAttachmentQueueOptions);
|
|
502
|
-
/**
|
|
503
|
-
* Validate that a string is a safe SQL identifier (Warning 5).
|
|
504
|
-
* Prevents SQL injection via config values.
|
|
505
|
-
*/
|
|
506
|
-
private _validateSqlIdentifier;
|
|
507
|
-
/**
|
|
508
|
-
* Watch the source table for attachment IDs and notify when they change.
|
|
509
|
-
*
|
|
510
|
-
* This implementation uses our configurable source table pattern rather
|
|
511
|
-
* than a hardcoded query, supporting project filtering for multi-tenant apps.
|
|
512
|
-
*/
|
|
513
|
-
onAttachmentIdsChange(onUpdate: (ids: string[]) => void): void;
|
|
514
|
-
/**
|
|
515
|
-
* Create a new attachment record with POL-specific defaults.
|
|
516
|
-
*/
|
|
517
|
-
newAttachmentRecord(record?: Partial<AttachmentRecord$1>): Promise<AttachmentRecord$1>;
|
|
518
|
-
/**
|
|
519
|
-
* Initialize the attachment queue.
|
|
520
|
-
*
|
|
521
|
-
* Extends parent init() to also:
|
|
522
|
-
* - Create the attachment table (since we don't use AttachmentTable in Schema)
|
|
523
|
-
* - Add upload-specific columns to the table
|
|
524
|
-
* - Start upload processing if handler is configured
|
|
525
|
-
*/
|
|
526
|
-
init(): Promise<void>;
|
|
527
|
-
/**
|
|
528
|
-
* Create the attachment table if it doesn't exist.
|
|
529
|
-
* This creates a REAL SQLite table (not a view) that supports all SQL operations.
|
|
530
|
-
*/
|
|
531
|
-
private _createTableIfNotExists;
|
|
532
|
-
/**
|
|
533
|
-
* Dispose the attachment queue, cleaning up all resources.
|
|
534
|
-
*/
|
|
535
|
-
dispose(): void;
|
|
536
|
-
/**
|
|
537
|
-
* Queue a file for upload.
|
|
538
|
-
*
|
|
539
|
-
* The file is immediately copied to managed cache for durability.
|
|
540
|
-
* Upload will retry indefinitely for transient errors until marked
|
|
541
|
-
* as FAILED_PERMANENT for unrecoverable errors.
|
|
542
|
-
*/
|
|
543
|
-
queueUpload(options: {
|
|
544
|
-
storagePath: string;
|
|
545
|
-
sourceUri: string;
|
|
546
|
-
filename: string;
|
|
547
|
-
mediaType: string;
|
|
548
|
-
bucketId?: string;
|
|
549
|
-
metadata?: Record<string, unknown>;
|
|
550
|
-
}): Promise<void>;
|
|
551
|
-
/**
|
|
552
|
-
* Get pending uploads that need retry.
|
|
553
|
-
*/
|
|
554
|
-
getPendingUploads(): Promise<PolAttachmentRecord[]>;
|
|
555
|
-
/**
|
|
556
|
-
* Get the soonest retry time for all uploads currently in backoff.
|
|
557
|
-
* Returns null if there are no uploads waiting for retry.
|
|
558
|
-
*/
|
|
559
|
-
getSoonestRetryTime(): Promise<number | null>;
|
|
560
|
-
/**
|
|
561
|
-
* Get uploads that have permanently failed.
|
|
562
|
-
*/
|
|
563
|
-
getFailedPermanentUploads(): Promise<PolAttachmentRecord[]>;
|
|
564
|
-
/**
|
|
565
|
-
* Get stale uploads (failing for > staleDaysThreshold).
|
|
566
|
-
*/
|
|
567
|
-
getStaleUploads(): Promise<PolAttachmentRecord[]>;
|
|
568
|
-
/**
|
|
569
|
-
* Get SYNCED uploads that have pending onComplete callbacks.
|
|
570
|
-
* Used by useQueuedUpload to recover callbacks after unmount/remount.
|
|
571
|
-
*
|
|
572
|
-
* Records are identified by having 'onCompleteCallback' flag in their upload_metadata.
|
|
573
|
-
* Once the callback is invoked, the hook should call clearUploadCallback() to remove the flag.
|
|
574
|
-
*/
|
|
575
|
-
getSyncedUploadsWithPendingCallback(): Promise<PolAttachmentRecord[]>;
|
|
576
|
-
/**
|
|
577
|
-
* Clear the onCompleteCallback flag from a record's metadata after callback invocation.
|
|
578
|
-
*/
|
|
579
|
-
clearUploadCallback(id: string): Promise<void>;
|
|
580
|
-
/**
|
|
581
|
-
* Retry a failed upload.
|
|
582
|
-
*/
|
|
583
|
-
retryUpload(id: string): Promise<void>;
|
|
584
|
-
/**
|
|
585
|
-
* Delete an upload from the queue.
|
|
586
|
-
*/
|
|
587
|
-
deleteUpload(id: string): Promise<void>;
|
|
588
|
-
/**
|
|
589
|
-
* Alias for record() for backward compatibility.
|
|
590
|
-
* Returns an attachment record by ID.
|
|
591
|
-
*/
|
|
592
|
-
getRecord(id: string): Promise<PolAttachmentRecord | null>;
|
|
593
|
-
/**
|
|
594
|
-
* Alias for getFailedPermanentUploads() for backward compatibility.
|
|
595
|
-
*/
|
|
596
|
-
getFailedUploads(): Promise<PolAttachmentRecord[]>;
|
|
597
|
-
/**
|
|
598
|
-
* Alias for retryUpload() for backward compatibility.
|
|
599
|
-
*/
|
|
600
|
-
retryFailedUpload(id: string): Promise<void>;
|
|
601
|
-
/**
|
|
602
|
-
* Alias for deleteUpload() for backward compatibility.
|
|
603
|
-
*/
|
|
604
|
-
deleteFailedUpload(id: string): Promise<void>;
|
|
605
|
-
/**
|
|
606
|
-
* Get currently active uploads.
|
|
607
|
-
*/
|
|
608
|
-
get activeUploads(): UploadStatus[];
|
|
609
|
-
/**
|
|
610
|
-
* Pause upload processing.
|
|
611
|
-
*/
|
|
612
|
-
pauseUploads(): void;
|
|
613
|
-
/**
|
|
614
|
-
* Resume upload processing.
|
|
615
|
-
*/
|
|
616
|
-
resumeUploads(): void;
|
|
617
|
-
/**
|
|
618
|
-
* Clear all cached files and re-queue for download.
|
|
619
|
-
*/
|
|
620
|
-
clearCache(): Promise<void>;
|
|
621
|
-
/**
|
|
622
|
-
* Cache a local file (e.g., one just uploaded) into the attachment cache.
|
|
623
|
-
* This avoids a redundant download by copying the source file directly
|
|
624
|
-
* into the cache directory and marking it as SYNCED.
|
|
625
|
-
*/
|
|
626
|
-
cacheLocalFile(storagePath: string, sourceUri: string): Promise<void>;
|
|
627
|
-
/**
|
|
628
|
-
* Get the local file URI for a storage path.
|
|
629
|
-
* Checks both downloaded files (SYNCED state, local_uri) and
|
|
630
|
-
* pending uploads (QUEUED_UPLOAD state, upload_source_uri).
|
|
631
|
-
*
|
|
632
|
-
* @param storagePath - The storage path (e.g., "14/uuid.jpg")
|
|
633
|
-
* @returns Full file:// URI if available locally, null otherwise
|
|
634
|
-
*/
|
|
635
|
-
getLocalUriForStoragePath(storagePath: string): Promise<string | null>;
|
|
636
|
-
/**
|
|
637
|
-
* Subscribe to real-time progress updates.
|
|
638
|
-
* Returns an unsubscribe function.
|
|
639
|
-
*/
|
|
640
|
-
onProgress(callback: (stats: AttachmentSyncStats) => void): () => void;
|
|
641
|
-
/**
|
|
642
|
-
* Get current sync statistics.
|
|
643
|
-
*/
|
|
644
|
-
getStats(): Promise<AttachmentSyncStats>;
|
|
645
|
-
private _startUploadProcessing;
|
|
646
|
-
private _uploadOne;
|
|
647
|
-
private _isPermanentError;
|
|
648
|
-
/**
|
|
649
|
-
* Extract HTTP status code from error message.
|
|
650
|
-
* Uses specific patterns to avoid false positives from numbers in other contexts.
|
|
651
|
-
*/
|
|
652
|
-
private _extractErrorCode;
|
|
653
|
-
private _markUploadSynced;
|
|
654
|
-
private _markUploadPermanentFailure;
|
|
655
|
-
private _scheduleUploadRetry;
|
|
656
|
-
private _startPolling;
|
|
657
|
-
private _migrateUploadColumns;
|
|
658
|
-
private _copyToManagedCache;
|
|
659
|
-
private _getStatus;
|
|
660
|
-
private _notify;
|
|
661
|
-
private _sleep;
|
|
662
|
-
/**
|
|
663
|
-
* Warning 6: Enhanced timeout that supports AbortSignal for actual cancellation.
|
|
664
|
-
* When signal is provided and aborts, the promise rejects with an AbortError.
|
|
665
|
-
*/
|
|
666
|
-
private _withTimeout;
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Create a PolAttachmentQueue from a simplified config.
|
|
670
|
-
*
|
|
671
|
-
* This is a convenience factory that converts from the user-friendly
|
|
672
|
-
* PolAttachmentQueueConfig to the options required by PolAttachmentQueue.
|
|
673
|
-
*/
|
|
674
|
-
declare function createPolAttachmentQueue(powersync: AbstractPowerSyncDatabase, platform: PlatformAdapter, config: PolAttachmentQueueConfig): PolAttachmentQueue;
|
|
675
|
-
|
|
676
|
-
export { type AttachmentSourceConfig as A, type CompressionConfig as C, DEFAULT_COMPRESSION_CONFIG as D, type EvictRow as E, type IdRow as I, PolAttachmentQueue as P, type UploadConfig as U, type PolAttachmentQueueOptions as a, PolAttachmentState as b, createPolAttachmentQueue as c, type PolAttachmentRecord as d, type AttachmentStorageAdapter as e, DEFAULT_UPLOAD_CONFIG as f, type UploadHandler as g, type CacheConfig as h, DEFAULT_CACHE_CONFIG as i, type PolAttachmentQueueConfig as j, type DownloadPhase as k, type DownloadStatus as l, type UploadPhase as m, type UploadStatus as n, type AttachmentSyncStatus as o, type AttachmentSyncStats as p, type AttachmentStatsRow as q, type CacheFileRow as r, type CachedSizeRow as s, type AttachmentRecord as t };
|