@pol-studios/powersync 1.0.25 → 1.0.32

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.
Files changed (118) hide show
  1. package/README.md +0 -1
  2. package/dist/{CacheSettingsManager-uz-kbnRH.d.ts → CacheSettingsManager-0H_7thHW.d.ts} +21 -3
  3. package/dist/attachments/index.d.ts +30 -30
  4. package/dist/attachments/index.js +13 -4
  5. package/dist/{background-sync-ChCXW-EV.d.ts → background-sync-BujnI3IR.d.ts} +1 -1
  6. package/dist/{chunk-55DKCJV4.js → chunk-2RDWLXJW.js} +408 -78
  7. package/dist/chunk-2RDWLXJW.js.map +1 -0
  8. package/dist/{chunk-P4HZA6ZT.js → chunk-4665ZSE5.js} +2 -2
  9. package/dist/chunk-4665ZSE5.js.map +1 -0
  10. package/dist/{chunk-XOY2CJ67.js → chunk-4F5B5CZ7.js} +3 -3
  11. package/dist/chunk-5WRI5ZAA.js +31 -0
  12. package/dist/{chunk-BGBQYQV3.js → chunk-65A3SYJZ.js} +193 -299
  13. package/dist/chunk-65A3SYJZ.js.map +1 -0
  14. package/dist/chunk-6SZ64KCZ.js +755 -0
  15. package/dist/chunk-6SZ64KCZ.js.map +1 -0
  16. package/dist/{chunk-YSTEESEG.js → chunk-74TBHWJ4.js} +122 -11
  17. package/dist/chunk-74TBHWJ4.js.map +1 -0
  18. package/dist/chunk-ANXWYQEJ.js +1 -0
  19. package/dist/chunk-ANXWYQEJ.js.map +1 -0
  20. package/dist/{chunk-CAB26E6F.js → chunk-C4J4MLER.js} +29 -24
  21. package/dist/chunk-C4J4MLER.js.map +1 -0
  22. package/dist/{chunk-C5ODS3XH.js → chunk-EOW7JK7Q.js} +9 -16
  23. package/dist/chunk-EOW7JK7Q.js.map +1 -0
  24. package/dist/chunk-HRAVPIAZ.js +220 -0
  25. package/dist/chunk-HRAVPIAZ.js.map +1 -0
  26. package/dist/{chunk-XAEII4ZX.js → chunk-NUGQOTEM.js} +32 -4
  27. package/dist/chunk-NUGQOTEM.js.map +1 -0
  28. package/dist/chunk-OGUFUZSY.js +5415 -0
  29. package/dist/chunk-OGUFUZSY.js.map +1 -0
  30. package/dist/{chunk-VB737IVN.js → chunk-P4D6BQ4X.js} +328 -706
  31. package/dist/chunk-P4D6BQ4X.js.map +1 -0
  32. package/dist/{chunk-CACKC6XG.js → chunk-PGEDE6IM.js} +136 -89
  33. package/dist/chunk-PGEDE6IM.js.map +1 -0
  34. package/dist/{chunk-A4IBBWGO.js → chunk-RALHHPTU.js} +1 -1
  35. package/dist/chunk-RIDSPLE5.js +42 -0
  36. package/dist/chunk-RIDSPLE5.js.map +1 -0
  37. package/dist/{chunk-Z6VOBGTU.js → chunk-UOMHWUHV.js} +2 -12
  38. package/dist/chunk-UOMHWUHV.js.map +1 -0
  39. package/dist/{chunk-WGHNIAF7.js → chunk-YONQYTVH.js} +2 -2
  40. package/dist/chunk-ZAN22NGL.js +13 -0
  41. package/dist/chunk-ZAN22NGL.js.map +1 -0
  42. package/dist/config/index.d.ts +200 -0
  43. package/dist/config/index.js +23 -0
  44. package/dist/config/index.js.map +1 -0
  45. package/dist/connector/index.d.ts +23 -5
  46. package/dist/connector/index.js +4 -2
  47. package/dist/core/index.d.ts +2 -2
  48. package/dist/core/index.js +1 -0
  49. package/dist/error/index.js +1 -0
  50. package/dist/generator/index.js +2 -0
  51. package/dist/generator/index.js.map +1 -1
  52. package/dist/index.d.ts +19 -16
  53. package/dist/index.js +88 -46
  54. package/dist/index.native.d.ts +18 -14
  55. package/dist/index.native.js +93 -44
  56. package/dist/index.web.d.ts +17 -14
  57. package/dist/index.web.js +88 -46
  58. package/dist/maintenance/index.d.ts +2 -2
  59. package/dist/maintenance/index.js +3 -2
  60. package/dist/platform/index.d.ts +1 -1
  61. package/dist/platform/index.js +2 -0
  62. package/dist/platform/index.js.map +1 -1
  63. package/dist/platform/index.native.d.ts +1 -1
  64. package/dist/platform/index.native.js +1 -0
  65. package/dist/platform/index.web.d.ts +1 -1
  66. package/dist/platform/index.web.js +1 -0
  67. package/dist/pol-attachment-queue-DqBvLAEY.d.ts +255 -0
  68. package/dist/provider/index.d.ts +319 -124
  69. package/dist/provider/index.js +21 -16
  70. package/dist/provider/index.native.d.ts +108 -0
  71. package/dist/provider/index.native.js +121 -0
  72. package/dist/provider/index.native.js.map +1 -0
  73. package/dist/provider/index.web.d.ts +16 -0
  74. package/dist/provider/index.web.js +112 -0
  75. package/dist/provider/index.web.js.map +1 -0
  76. package/dist/react/index.d.ts +16 -65
  77. package/dist/react/index.js +2 -9
  78. package/dist/storage/index.d.ts +5 -4
  79. package/dist/storage/index.js +12 -9
  80. package/dist/storage/index.native.d.ts +5 -4
  81. package/dist/storage/index.native.js +8 -5
  82. package/dist/storage/index.web.d.ts +5 -4
  83. package/dist/storage/index.web.js +11 -8
  84. package/dist/storage/upload/index.d.ts +4 -3
  85. package/dist/storage/upload/index.js +4 -2
  86. package/dist/storage/upload/index.native.d.ts +4 -3
  87. package/dist/storage/upload/index.native.js +4 -2
  88. package/dist/storage/upload/index.web.d.ts +2 -1
  89. package/dist/storage/upload/index.web.js +4 -2
  90. package/dist/{supabase-connector-D2oIl2t8.d.ts → supabase-connector-HMxBA9Kg.d.ts} +23 -25
  91. package/dist/sync/index.d.ts +183 -11
  92. package/dist/sync/index.js +13 -3
  93. package/dist/{types-CyvBaAl8.d.ts → types-6QHGELuY.d.ts} +4 -1
  94. package/dist/{types-CDqWh56B.d.ts → types-B9MptP7E.d.ts} +13 -1
  95. package/dist/types-BhAEsJj-.d.ts +330 -0
  96. package/dist/{types-D0WcHrq6.d.ts → types-CGMibJKD.d.ts} +8 -0
  97. package/dist/{types-DiBvmGEi.d.ts → types-DqJnP50o.d.ts} +22 -24
  98. package/dist/{pol-attachment-queue-BE2HU3Us.d.ts → types-JCEhw2Lf.d.ts} +139 -346
  99. package/package.json +18 -4
  100. package/dist/chunk-24RDMMCL.js +0 -44
  101. package/dist/chunk-24RDMMCL.js.map +0 -1
  102. package/dist/chunk-55DKCJV4.js.map +0 -1
  103. package/dist/chunk-654ERHA7.js +0 -1
  104. package/dist/chunk-BGBQYQV3.js.map +0 -1
  105. package/dist/chunk-C5ODS3XH.js.map +0 -1
  106. package/dist/chunk-CAB26E6F.js.map +0 -1
  107. package/dist/chunk-CACKC6XG.js.map +0 -1
  108. package/dist/chunk-P4HZA6ZT.js.map +0 -1
  109. package/dist/chunk-TIFL2KWE.js +0 -358
  110. package/dist/chunk-TIFL2KWE.js.map +0 -1
  111. package/dist/chunk-VB737IVN.js.map +0 -1
  112. package/dist/chunk-XAEII4ZX.js.map +0 -1
  113. package/dist/chunk-YSTEESEG.js.map +0 -1
  114. package/dist/chunk-Z6VOBGTU.js.map +0 -1
  115. /package/dist/{chunk-XOY2CJ67.js.map → chunk-4F5B5CZ7.js.map} +0 -0
  116. /package/dist/{chunk-654ERHA7.js.map → chunk-5WRI5ZAA.js.map} +0 -0
  117. /package/dist/{chunk-A4IBBWGO.js.map → chunk-RALHHPTU.js.map} +0 -0
  118. /package/dist/{chunk-WGHNIAF7.js.map → chunk-YONQYTVH.js.map} +0 -0
@@ -0,0 +1,255 @@
1
+ import { AbstractAttachmentQueue, AttachmentQueueOptions, AttachmentRecord } from '@powersync/attachments';
2
+ import { AbstractPowerSyncDatabase } from '@powersync/common';
3
+ import { PlatformAdapter } from './platform/index.js';
4
+ import { e as AttachmentStorageAdapter, c as AttachmentSourceConfig, h as UploadHandler, U as UploadConfig, i as DownloadConfig, a as PolAttachmentRecord, f as CompressionConfig, k as CacheConfig, t as UploadStatus, v as AttachmentSyncStats, d as AttachmentConfig } from './types-JCEhw2Lf.js';
5
+
6
+ /**
7
+ * POL Attachment Queue
8
+ *
9
+ * Extends the official @powersync/attachments AbstractAttachmentQueue with
10
+ * POL-specific features:
11
+ * - Reactive watchPaths callback for attachment path sources
12
+ * - Durable upload queue with exponential backoff retry
13
+ * - FAILED_PERMANENT state for unrecoverable upload errors
14
+ * - Image compression integration
15
+ * - Upload callbacks (onUploadComplete, onUploadFailed)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const queue = new PolAttachmentQueue({
20
+ * powersync: db,
21
+ * storage: storageAdapter,
22
+ * source: {
23
+ * source: { type: 'supabase-bucket', bucket: 'project-assets' },
24
+ * watchPaths: (db, supabase, onUpdate) => {
25
+ * db.watch(
26
+ * // Filter in the query - only emit paths you want to download
27
+ * `SELECT storagePath FROM photos
28
+ * WHERE storagePath IS NOT NULL
29
+ * AND mediaType NOT LIKE 'video/%'`,
30
+ * [],
31
+ * { onResult: (r) => onUpdate(r.rows._array.map(row => row.storagePath)) }
32
+ * );
33
+ * },
34
+ * },
35
+ * });
36
+ *
37
+ * await queue.init();
38
+ * ```
39
+ */
40
+
41
+ /**
42
+ * Options for PolAttachmentQueue that extend the official AttachmentQueueOptions.
43
+ */
44
+ interface PolAttachmentQueueOptions extends AttachmentQueueOptions {
45
+ platform: PlatformAdapter;
46
+ remoteStorage: AttachmentStorageAdapter;
47
+ /** Attachment source configuration with reactive watchPaths callback */
48
+ source: AttachmentSourceConfig;
49
+ /**
50
+ * Supabase client for passing to watchPaths callback.
51
+ * Required when using watchPaths (new API).
52
+ */
53
+ supabaseClient?: unknown;
54
+ uploadHandler?: UploadHandler;
55
+ uploadConfig?: Partial<UploadConfig>;
56
+ /** Download configuration for concurrency tuning */
57
+ downloadConfig?: Partial<DownloadConfig>;
58
+ onUploadComplete?: (record: PolAttachmentRecord) => Promise<void>;
59
+ onUploadFailed?: (record: PolAttachmentRecord, error: Error) => void;
60
+ compression?: Partial<CompressionConfig>;
61
+ cache?: Partial<CacheConfig>;
62
+ }
63
+ /**
64
+ * POL Attachment Queue that extends the official AbstractAttachmentQueue.
65
+ */
66
+ declare class PolAttachmentQueue extends AbstractAttachmentQueue<PolAttachmentQueueOptions> {
67
+ private readonly platform;
68
+ private readonly polLogger;
69
+ private readonly source;
70
+ private readonly remoteStorage;
71
+ private readonly supabaseClient?;
72
+ private readonly uploadHandler?;
73
+ private readonly uploadConfig;
74
+ private readonly downloadConfig;
75
+ private readonly compressionConfig;
76
+ private readonly cacheConfig;
77
+ private _uploadState;
78
+ private _disposed;
79
+ private _initialized;
80
+ private _watchGeneration;
81
+ private _watchCleanup;
82
+ private _watchMutex;
83
+ private _networkListenerCleanup;
84
+ private _wasConnected;
85
+ private _cacheCapacityRetries;
86
+ private _progressCallbacks;
87
+ private _lastNotifyTime;
88
+ private _notifyTimer;
89
+ private _cachedStats;
90
+ private _cachedStatsTimestamp;
91
+ constructor(options: PolAttachmentQueueOptions);
92
+ watchUploads(): void;
93
+ /**
94
+ * Override parent's expireCache to disable count-based cache eviction.
95
+ *
96
+ * The parent implementation deletes SYNCED/ARCHIVED records beyond cacheLimit,
97
+ * which caused a bug where downloads would reset because:
98
+ * 1. expireCache deleted records beyond cacheLimit (default 100)
99
+ * 2. watchPaths still emitted those IDs
100
+ * 3. They got re-created as QUEUED_DOWNLOAD
101
+ * 4. Downloads restarted in an infinite loop
102
+ *
103
+ * Our implementation uses size-based cache limits only (via clearCache/cacheConfig.maxSize).
104
+ */
105
+ expireCache(): Promise<void>;
106
+ /**
107
+ * Override parent's watchDownloads to use concurrent downloads.
108
+ *
109
+ * The parent implementation downloads one file at a time.
110
+ * This override processes downloads in parallel batches for faster sync.
111
+ */
112
+ watchDownloads(): void;
113
+ /**
114
+ * Process pending downloads with concurrency control.
115
+ * Downloads multiple files in parallel based on downloadConfig.concurrency.
116
+ * Enforces cache size limits after each batch completes.
117
+ */
118
+ private _downloadRecordsConcurrent;
119
+ uploadAttachment(record: {
120
+ id: string;
121
+ }): Promise<boolean>;
122
+ watchAttachmentIds(): Promise<void>;
123
+ saveToQueue(record: Omit<AttachmentRecord, 'timestamp'>): Promise<AttachmentRecord>;
124
+ onAttachmentIdsChange(onUpdate: (ids: string[]) => void): void;
125
+ downloadRecord(record: AttachmentRecord): Promise<boolean>;
126
+ newAttachmentRecord(record?: Partial<AttachmentRecord>): Promise<AttachmentRecord>;
127
+ init(): Promise<void>;
128
+ /**
129
+ * Dispose the attachment queue and clean up resources.
130
+ * This method is synchronous to ensure callers don't need to await it,
131
+ * but it fires off async cleanup in the background for graceful shutdown.
132
+ */
133
+ dispose(): void;
134
+ /**
135
+ * Async cleanup that runs in the background after dispose().
136
+ * Waits for active upload promises to settle gracefully.
137
+ */
138
+ private _asyncCleanup;
139
+ queueUpload(options: {
140
+ storagePath: string;
141
+ sourceUri: string;
142
+ filename: string;
143
+ mediaType: string;
144
+ bucketId?: string;
145
+ metadata?: Record<string, unknown>;
146
+ }): Promise<void>;
147
+ getPendingUploads(): Promise<PolAttachmentRecord[]>;
148
+ getSoonestRetryTime(): Promise<number | null>;
149
+ getFailedPermanentUploads(): Promise<PolAttachmentRecord[]>;
150
+ getStaleUploads(): Promise<PolAttachmentRecord[]>;
151
+ getSyncedUploadsWithPendingCallback(): Promise<PolAttachmentRecord[]>;
152
+ clearUploadCallback(id: string): Promise<void>;
153
+ retryUpload(id: string): Promise<void>;
154
+ /**
155
+ * Reset all uploads in QUEUED_UPLOAD state so they retry immediately.
156
+ * This clears retry counts and errors, allowing uploads to be retried fresh.
157
+ *
158
+ * @returns The number of uploads that were reset
159
+ */
160
+ resetUploadRetries(): Promise<number>;
161
+ /**
162
+ * Trigger immediate retry of uploads WITHOUT resetting their retry count.
163
+ * This preserves backoff state for truly failing uploads while allowing
164
+ * uploads that were waiting for network to retry immediately.
165
+ *
166
+ * Only affects uploads that:
167
+ * - Are past their retry time (upload_next_retry_at <= now), OR
168
+ * - Have no retry time set (upload_next_retry_at IS NULL)
169
+ *
170
+ * @returns The number of uploads that will be retried
171
+ */
172
+ retryUploads(): Promise<number>;
173
+ deleteUpload(id: string): Promise<void>;
174
+ /**
175
+ * Re-queue an upload for an orphaned attachment.
176
+ * Use this when a database record exists with a storagePath but the file was never uploaded.
177
+ *
178
+ * This handles the case where:
179
+ * - User took a photo and the database record was created with a storagePath
180
+ * - The attachment queue record was created but disappeared before upload completed
181
+ * - The photo shows locally but was never uploaded to storage
182
+ *
183
+ * @param options.storagePath - The storage path (e.g., "projectId/fileId.jpg")
184
+ * @param options.localFileUri - URI to the local file to upload
185
+ * @param options.mediaType - MIME type of the file
186
+ * @param options.bucketId - Optional bucket ID for multi-bucket setups
187
+ * @returns true if upload was queued, false if already exists in valid state
188
+ */
189
+ requeueOrphanedUpload(options: {
190
+ storagePath: string;
191
+ localFileUri: string;
192
+ mediaType: string;
193
+ bucketId?: string;
194
+ }): Promise<boolean>;
195
+ getRecord(id: string): Promise<PolAttachmentRecord | null>;
196
+ getFailedUploads(): Promise<PolAttachmentRecord[]>;
197
+ retryFailedUpload(id: string): Promise<void>;
198
+ deleteFailedUpload(id: string): Promise<void>;
199
+ get activeUploads(): UploadStatus[];
200
+ pauseUploads(): void;
201
+ resumeUploads(): void;
202
+ clearCache(): Promise<void>;
203
+ cacheLocalFile(storagePath: string, sourceUri: string): Promise<void>;
204
+ getLocalUriForStoragePath(storagePath: string): Promise<string | null>;
205
+ /**
206
+ * Purge attachments by their IDs.
207
+ * Archives and deletes local files for the specified attachment IDs.
208
+ * Useful for edge cases where external code needs to force-remove attachments.
209
+ *
210
+ * @param ids - Array of attachment IDs to purge
211
+ */
212
+ purgeAttachments(ids: string[]): Promise<void>;
213
+ onProgress(callback: (stats: AttachmentSyncStats) => void): () => void;
214
+ getStats(): Promise<AttachmentSyncStats>;
215
+ /**
216
+ * Repair attachment sizes for synced records that have size=0.
217
+ * This backfills sizes from the actual file system for existing downloads.
218
+ * @returns Number of records repaired
219
+ */
220
+ repairAttachmentSizes(): Promise<number>;
221
+ private _getDownloadManagerDeps;
222
+ private _getUploadManagerDeps;
223
+ private _getCacheManagerDeps;
224
+ private _startUploadProcessing;
225
+ private _createTableIfNotExists;
226
+ private _migrateUploadColumns;
227
+ private _invalidateStatsCache;
228
+ private _getStatus;
229
+ private _notify;
230
+ }
231
+ /**
232
+ * Factory function options that combine AttachmentConfig with required runtime dependencies.
233
+ */
234
+ interface CreateAttachmentQueueOptions extends AttachmentConfig {
235
+ /** Remote storage adapter for downloading/uploading files */
236
+ remoteStorage: AttachmentStorageAdapter;
237
+ /**
238
+ * Supabase client for passing to watchPaths callback.
239
+ * Required when using watchPaths (new API).
240
+ */
241
+ supabaseClient?: unknown;
242
+ /** Upload handler for processing uploads */
243
+ uploadHandler?: UploadHandler;
244
+ /** Upload configuration */
245
+ uploadConfig?: Partial<UploadConfig>;
246
+ /** Download configuration (concurrency, timeout) */
247
+ downloadConfig?: Partial<DownloadConfig>;
248
+ /** Compression configuration */
249
+ compression?: Partial<CompressionConfig>;
250
+ /** Cache configuration */
251
+ cache?: Partial<CacheConfig>;
252
+ }
253
+ declare function createPolAttachmentQueue(powersync: AbstractPowerSyncDatabase, platform: PlatformAdapter, config: CreateAttachmentQueueOptions): PolAttachmentQueue;
254
+
255
+ export { PolAttachmentQueue as P, type PolAttachmentQueueOptions as a, createPolAttachmentQueue as c };