@pol-studios/powersync 1.0.4 → 1.0.7
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/CacheSettingsManager-1exbOC6S.d.ts +261 -0
- package/dist/attachments/index.d.ts +65 -355
- package/dist/attachments/index.js +24 -6
- package/dist/{types-Cd7RhNqf.d.ts → background-sync-ChCXW-EV.d.ts} +53 -2
- package/dist/chunk-4C3RY5SU.js +204 -0
- package/dist/chunk-4C3RY5SU.js.map +1 -0
- package/dist/{chunk-3AYXHQ4W.js → chunk-53WH2JJV.js} +111 -47
- package/dist/chunk-53WH2JJV.js.map +1 -0
- package/dist/chunk-A4IBBWGO.js +377 -0
- package/dist/chunk-A4IBBWGO.js.map +1 -0
- package/dist/chunk-BREGB4WL.js +1768 -0
- package/dist/chunk-BREGB4WL.js.map +1 -0
- package/dist/{chunk-EJ23MXPQ.js → chunk-CGL33PL4.js} +3 -1
- package/dist/chunk-CGL33PL4.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DHYUBVP7.js +131 -0
- package/dist/chunk-DHYUBVP7.js.map +1 -0
- package/dist/chunk-FV2HXEIY.js +124 -0
- package/dist/chunk-FV2HXEIY.js.map +1 -0
- package/dist/chunk-GKF7TOMT.js +1 -0
- package/dist/{chunk-OTJXIRWX.js → chunk-H772V6XQ.js} +304 -51
- package/dist/chunk-H772V6XQ.js.map +1 -0
- package/dist/{chunk-C2RSTGDC.js → chunk-HFOFLW5F.js} +525 -87
- package/dist/chunk-HFOFLW5F.js.map +1 -0
- package/dist/chunk-KGSFAE5B.js +1 -0
- package/dist/chunk-LNL64IJZ.js +1 -0
- package/dist/chunk-MKD2VCX3.js +32 -0
- package/dist/chunk-MKD2VCX3.js.map +1 -0
- package/dist/{chunk-7EMDVIZX.js → chunk-N75DEF5J.js} +19 -1
- package/dist/chunk-N75DEF5J.js.map +1 -0
- package/dist/chunk-P6WOZO7H.js +49 -0
- package/dist/chunk-P6WOZO7H.js.map +1 -0
- package/dist/chunk-TGBT5XBE.js +1 -0
- package/dist/chunk-TGBT5XBE.js.map +1 -0
- package/dist/chunk-UEYRTLKE.js +72 -0
- package/dist/chunk-UEYRTLKE.js.map +1 -0
- package/dist/chunk-WGHNIAF7.js +329 -0
- package/dist/chunk-WGHNIAF7.js.map +1 -0
- package/dist/chunk-WQ5MPAVC.js +449 -0
- package/dist/chunk-WQ5MPAVC.js.map +1 -0
- package/dist/{chunk-FPTDATY5.js → chunk-XQAJM2MW.js} +22 -11
- package/dist/chunk-XQAJM2MW.js.map +1 -0
- package/dist/chunk-YSTEESEG.js +676 -0
- package/dist/chunk-YSTEESEG.js.map +1 -0
- package/dist/chunk-ZEOKPWUC.js +1165 -0
- package/dist/chunk-ZEOKPWUC.js.map +1 -0
- package/dist/connector/index.d.ts +182 -2
- package/dist/connector/index.js +14 -3
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +5 -2
- package/dist/error/index.d.ts +54 -0
- package/dist/error/index.js +8 -0
- package/dist/error/index.js.map +1 -0
- package/dist/index.d.ts +237 -11
- package/dist/index.js +183 -27
- package/dist/index.native.d.ts +20 -9
- package/dist/index.native.js +183 -28
- package/dist/index.web.d.ts +20 -9
- package/dist/index.web.js +184 -28
- package/dist/maintenance/index.d.ts +118 -0
- package/dist/maintenance/index.js +17 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/platform/index.d.ts +16 -1
- package/dist/platform/index.js +2 -0
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/index.native.d.ts +2 -2
- package/dist/platform/index.native.js +2 -1
- package/dist/platform/index.web.d.ts +1 -1
- package/dist/platform/index.web.js +2 -1
- package/dist/pol-attachment-queue-C7YNXXhK.d.ts +676 -0
- package/dist/provider/index.d.ts +693 -12
- package/dist/provider/index.js +57 -12
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.js +28 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.native.d.ts +6 -0
- package/dist/storage/index.native.js +26 -0
- package/dist/storage/index.native.js.map +1 -0
- package/dist/storage/index.web.d.ts +6 -0
- package/dist/storage/index.web.js +26 -0
- package/dist/storage/index.web.js.map +1 -0
- package/dist/storage/upload/index.d.ts +55 -0
- package/dist/storage/upload/index.js +15 -0
- package/dist/storage/upload/index.js.map +1 -0
- package/dist/storage/upload/index.native.d.ts +57 -0
- package/dist/storage/upload/index.native.js +14 -0
- package/dist/storage/upload/index.native.js.map +1 -0
- package/dist/storage/upload/index.web.d.ts +5 -0
- package/dist/storage/upload/index.web.js +14 -0
- package/dist/storage/upload/index.web.js.map +1 -0
- package/dist/{index-Cb-NI0Ct.d.ts → supabase-connector-qLm-WHkM.d.ts} +146 -10
- package/dist/sync/index.d.ts +288 -22
- package/dist/sync/index.js +23 -5
- package/dist/types-BVacP54t.d.ts +52 -0
- package/dist/types-Bgvx7-E8.d.ts +187 -0
- package/dist/{types-afHtE1U_.d.ts → types-CDqWh56B.d.ts} +2 -0
- package/package.json +72 -2
- package/dist/chunk-32OLICZO.js +0 -1
- package/dist/chunk-3AYXHQ4W.js.map +0 -1
- package/dist/chunk-7EMDVIZX.js.map +0 -1
- package/dist/chunk-7JQZBZ5N.js +0 -1
- package/dist/chunk-C2RSTGDC.js.map +0 -1
- package/dist/chunk-EJ23MXPQ.js.map +0 -1
- package/dist/chunk-FPTDATY5.js.map +0 -1
- package/dist/chunk-GMFDCVMZ.js +0 -1285
- package/dist/chunk-GMFDCVMZ.js.map +0 -1
- package/dist/chunk-OLHGI472.js +0 -1
- package/dist/chunk-OTJXIRWX.js.map +0 -1
- package/dist/chunk-V6LJ6MR2.js +0 -740
- package/dist/chunk-V6LJ6MR2.js.map +0 -1
- package/dist/chunk-VJCL2SWD.js +0 -1
- /package/dist/{chunk-32OLICZO.js.map → chunk-DGUM43GV.js.map} +0 -0
- /package/dist/{chunk-7JQZBZ5N.js.map → chunk-GKF7TOMT.js.map} +0 -0
- /package/dist/{chunk-OLHGI472.js.map → chunk-KGSFAE5B.js.map} +0 -0
- /package/dist/{chunk-VJCL2SWD.js.map → chunk-LNL64IJZ.js.map} +0 -0
|
@@ -1,399 +1,109 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as AttachmentStorageAdapter } from '../pol-attachment-queue-C7YNXXhK.js';
|
|
2
|
+
export { t as AttachmentRecord, A as AttachmentSourceConfig, q as AttachmentStatsRow, p as AttachmentSyncStats, o as AttachmentSyncStatus, h as CacheConfig, r as CacheFileRow, s as CachedSizeRow, C as CompressionConfig, i as DEFAULT_CACHE_CONFIG, D as DEFAULT_COMPRESSION_CONFIG, f as DEFAULT_UPLOAD_CONFIG, k as DownloadPhase, l as DownloadStatus, E as EvictRow, I as IdRow, P as PolAttachmentQueue, j as PolAttachmentQueueConfig, a as PolAttachmentQueueOptions, d as PolAttachmentRecord, b as PolAttachmentState, U as UploadConfig, g as UploadHandler, m as UploadPhase, n as UploadStatus, c as createPolAttachmentQueue } from '../pol-attachment-queue-C7YNXXhK.js';
|
|
3
|
+
import { StorageAdapter, EncodingType } from '@powersync/attachments';
|
|
4
|
+
export { ATTACHMENT_TABLE, AbstractAttachmentQueue, AttachmentState, AttachmentTable, AttachmentTableOptions, AttachmentQueueOptions as BaseAttachmentQueueOptions, DEFAULT_ATTACHMENT_QUEUE_OPTIONS, EncodingType, AttachmentRecord as OfficialAttachmentRecord, StorageAdapter } from '@powersync/attachments';
|
|
2
5
|
import { PlatformAdapter } from '../platform/index.js';
|
|
6
|
+
import '@powersync/common';
|
|
7
|
+
import '../types-CDqWh56B.js';
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* POL Storage Adapter
|
|
6
11
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
declare enum AttachmentState {
|
|
15
|
-
/** Waiting to be downloaded */
|
|
16
|
-
QUEUED_DOWNLOAD = 0,
|
|
17
|
-
/** Waiting for initial sync */
|
|
18
|
-
QUEUED_SYNC = 1,
|
|
19
|
-
/** Waiting to be uploaded */
|
|
20
|
-
QUEUED_UPLOAD = 2,
|
|
21
|
-
/** Fully synced (downloaded or uploaded) */
|
|
22
|
-
SYNCED = 3,
|
|
23
|
-
/** Archived (removed from sync but record kept) */
|
|
24
|
-
ARCHIVED = 4
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Record representing an attachment in the queue database.
|
|
28
|
-
*/
|
|
29
|
-
interface AttachmentRecord {
|
|
30
|
-
/** Unique identifier (typically storage path) */
|
|
31
|
-
id: string;
|
|
32
|
-
/** Filename for display and type inference */
|
|
33
|
-
filename: string;
|
|
34
|
-
/** MIME type of the file */
|
|
35
|
-
media_type: string;
|
|
36
|
-
/** Current state in the queue */
|
|
37
|
-
state: AttachmentState;
|
|
38
|
-
/** Local file URI (set after download) */
|
|
39
|
-
local_uri?: string | null;
|
|
40
|
-
/** File size in bytes */
|
|
41
|
-
size?: number;
|
|
42
|
-
/** Timestamp when the attachment was created */
|
|
43
|
-
timestamp?: number;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Configuration for the source table that contains attachment references.
|
|
47
|
-
* This makes the attachment queue reusable across different tables/projects.
|
|
48
|
-
*/
|
|
49
|
-
interface AttachmentSourceConfig {
|
|
50
|
-
/**
|
|
51
|
-
* Table name containing attachment references.
|
|
52
|
-
* @example "EquipmentUnitMediaContent"
|
|
53
|
-
*/
|
|
54
|
-
table: string;
|
|
55
|
-
/**
|
|
56
|
-
* Column containing the storage path / attachment ID.
|
|
57
|
-
* @example "storagePath"
|
|
58
|
-
*/
|
|
59
|
-
idColumn: string;
|
|
60
|
-
/**
|
|
61
|
-
* Column to order by for "newest first" downloads.
|
|
62
|
-
* Set to null to skip ordering.
|
|
63
|
-
* @example "takenOn"
|
|
64
|
-
*/
|
|
65
|
-
orderByColumn: string | null;
|
|
66
|
-
/**
|
|
67
|
-
* Optional filter config to exclude attachments from archived/unsynced projects.
|
|
68
|
-
* When set, the attachment query JOINs through intermediary tables to ensure
|
|
69
|
-
* only attachments belonging to synced projects are downloaded.
|
|
70
|
-
*/
|
|
71
|
-
projectFilter?: {
|
|
72
|
-
/** Foreign key column in the source table (e.g., "equipmentUnitId") */
|
|
73
|
-
foreignKey: string;
|
|
74
|
-
/** Intermediary table to JOIN through (e.g., "EquipmentFixtureUnit") */
|
|
75
|
-
intermediaryTable: string;
|
|
76
|
-
/** Column in intermediary table that links to ProjectDatabase (e.g., "projectDatabaseId") */
|
|
77
|
-
projectForeignKey: string;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Interface for attachment storage operations (e.g., Supabase Storage).
|
|
12
|
+
* Implements the official @powersync/attachments StorageAdapter interface,
|
|
13
|
+
* bridging our PlatformAdapter file system and remote storage adapters.
|
|
14
|
+
*
|
|
15
|
+
* This adapter combines:
|
|
16
|
+
* - Local file operations via PlatformAdapter.fileSystem
|
|
17
|
+
* - Remote upload/download via AttachmentStorageAdapter (e.g., Supabase)
|
|
82
18
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* Download a file from remote storage.
|
|
86
|
-
* @param filePath - The storage path of the file
|
|
87
|
-
* @returns The file data as a Blob or base64 string
|
|
88
|
-
*/
|
|
89
|
-
downloadFile(filePath: string): Promise<Blob | string>;
|
|
19
|
+
|
|
20
|
+
interface PolStorageAdapterOptions {
|
|
90
21
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @param filePath - The storage path to upload to
|
|
93
|
-
* @param data - The file data to upload
|
|
22
|
+
* Platform adapter for local file system operations.
|
|
94
23
|
*/
|
|
95
|
-
|
|
24
|
+
platform: PlatformAdapter;
|
|
96
25
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param filePath - The storage path of the file
|
|
26
|
+
* Remote storage adapter for upload/download operations.
|
|
99
27
|
*/
|
|
100
|
-
|
|
28
|
+
remoteStorage: AttachmentStorageAdapter;
|
|
101
29
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @param filePath - The file path to resolve
|
|
105
|
-
* @returns The bucket name
|
|
30
|
+
* Base directory name for attachments within the cache directory.
|
|
31
|
+
* Defaults to 'attachments'.
|
|
106
32
|
*/
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Configuration for image compression.
|
|
111
|
-
*/
|
|
112
|
-
interface CompressionConfig {
|
|
113
|
-
/** Enable compression (default: true) */
|
|
114
|
-
enabled: boolean;
|
|
115
|
-
/** Compression quality 0.0-1.0 (default: 0.7) */
|
|
116
|
-
quality: number;
|
|
117
|
-
/** Max width before resizing (default: 2048) */
|
|
118
|
-
maxWidth: number;
|
|
119
|
-
/** Skip files under this size in bytes (default: 100KB) */
|
|
120
|
-
skipSizeBytes: number;
|
|
121
|
-
/** Skip if already under this size in bytes (default: 300KB) */
|
|
122
|
-
targetSizeBytes: number;
|
|
33
|
+
attachmentDirectoryName?: string;
|
|
123
34
|
}
|
|
124
35
|
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
declare const DEFAULT_COMPRESSION_CONFIG: CompressionConfig;
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for the download engine.
|
|
130
|
-
*/
|
|
131
|
-
interface DownloadConfig {
|
|
132
|
-
/** Maximum concurrent downloads (default: 50) */
|
|
133
|
-
concurrency: number;
|
|
134
|
-
/** Download timeout per file in ms (default: 60000) */
|
|
135
|
-
timeoutMs: number;
|
|
136
|
-
/** Retry delay between batches in ms (default: 5000) */
|
|
137
|
-
retryDelayMs: number;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Default download configuration.
|
|
141
|
-
*/
|
|
142
|
-
declare const DEFAULT_DOWNLOAD_CONFIG: DownloadConfig;
|
|
143
|
-
/**
|
|
144
|
-
* Configuration for cache management.
|
|
145
|
-
*/
|
|
146
|
-
interface CacheConfig {
|
|
147
|
-
/** Maximum cache size in bytes (default: 5GB) */
|
|
148
|
-
maxSize: number;
|
|
149
|
-
/** Stop downloads at this percentage of max (default: 0.95 = 95%) */
|
|
150
|
-
downloadStopThreshold: number;
|
|
151
|
-
/** Trigger eviction at this percentage (default: 1.0 = 100%) */
|
|
152
|
-
evictionTriggerThreshold: number;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Default cache configuration.
|
|
156
|
-
*/
|
|
157
|
-
declare const DEFAULT_CACHE_CONFIG: CacheConfig;
|
|
158
|
-
/**
|
|
159
|
-
* Full configuration for the attachment queue.
|
|
160
|
-
*/
|
|
161
|
-
interface AttachmentQueueConfig {
|
|
162
|
-
/** Source table configuration */
|
|
163
|
-
source: AttachmentSourceConfig;
|
|
164
|
-
/** Storage adapter for downloading files */
|
|
165
|
-
storage: AttachmentStorageAdapter;
|
|
166
|
-
/** Table name for storing attachment records (default: "photo_attachments") */
|
|
167
|
-
attachmentTableName?: string;
|
|
168
|
-
/** Perform initial sync on initialization (default: true) */
|
|
169
|
-
performInitialSync?: boolean;
|
|
170
|
-
/** Download configuration */
|
|
171
|
-
download?: Partial<DownloadConfig>;
|
|
172
|
-
/** Cache configuration */
|
|
173
|
-
cache?: Partial<CacheConfig>;
|
|
174
|
-
/** Compression configuration */
|
|
175
|
-
compression?: Partial<CompressionConfig>;
|
|
176
|
-
/**
|
|
177
|
-
* Called when a download fails.
|
|
178
|
-
* Return { retry: true } to retry, { retry: false } to skip.
|
|
179
|
-
*/
|
|
180
|
-
onDownloadError?: (attachment: AttachmentRecord, error: Error) => Promise<{
|
|
181
|
-
retry: boolean;
|
|
182
|
-
}>;
|
|
183
|
-
/**
|
|
184
|
-
* Called when sync progress changes.
|
|
185
|
-
*/
|
|
186
|
-
onProgress?: (stats: AttachmentSyncStats) => void;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Current phase of a download operation.
|
|
190
|
-
*/
|
|
191
|
-
type DownloadPhase = 'downloading' | 'compressing' | 'complete' | 'error';
|
|
192
|
-
/**
|
|
193
|
-
* Status of an individual download.
|
|
194
|
-
*/
|
|
195
|
-
interface DownloadStatus {
|
|
196
|
-
/** Attachment ID */
|
|
197
|
-
id: string;
|
|
198
|
-
/** Filename being downloaded */
|
|
199
|
-
filename: string;
|
|
200
|
-
/** Current phase */
|
|
201
|
-
phase: DownloadPhase;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Why downloads are stopped (if not actively syncing).
|
|
205
|
-
*/
|
|
206
|
-
type AttachmentSyncStatus = 'syncing' | 'paused' | 'cache_full' | 'complete';
|
|
207
|
-
/**
|
|
208
|
-
* Statistics about the attachment sync progress.
|
|
209
|
-
*/
|
|
210
|
-
interface AttachmentSyncStats {
|
|
211
|
-
/** Number of attachments that have been downloaded */
|
|
212
|
-
syncedCount: number;
|
|
213
|
-
/** Total size of synced attachments in bytes */
|
|
214
|
-
syncedSize: number;
|
|
215
|
-
/** Number of attachments waiting to be downloaded */
|
|
216
|
-
pendingCount: number;
|
|
217
|
-
/** Total expected attachments (synced + pending) */
|
|
218
|
-
totalExpected: number;
|
|
219
|
-
/** Maximum cache size in bytes */
|
|
220
|
-
maxCacheSize: number;
|
|
221
|
-
/** Current compression quality (0.1 to 1.0) */
|
|
222
|
-
compressionQuality: number;
|
|
223
|
-
/** Current sync status */
|
|
224
|
-
status: AttachmentSyncStatus;
|
|
225
|
-
/** Whether downloads are paused */
|
|
226
|
-
isPaused: boolean;
|
|
227
|
-
/** Whether currently processing downloads */
|
|
228
|
-
isProcessing: boolean;
|
|
229
|
-
/** Currently active downloads */
|
|
230
|
-
activeDownloads: DownloadStatus[];
|
|
231
|
-
}
|
|
232
|
-
/** Row from stats query */
|
|
233
|
-
interface AttachmentStatsRow {
|
|
234
|
-
state: number;
|
|
235
|
-
cnt: number;
|
|
236
|
-
sz: number;
|
|
237
|
-
}
|
|
238
|
-
/** Row for cache file operations */
|
|
239
|
-
interface CacheFileRow {
|
|
240
|
-
id: string;
|
|
241
|
-
local_uri: string;
|
|
242
|
-
}
|
|
243
|
-
/** Row for eviction operations */
|
|
244
|
-
interface EvictRow {
|
|
245
|
-
id: string;
|
|
246
|
-
local_uri: string;
|
|
247
|
-
size: number;
|
|
248
|
-
}
|
|
249
|
-
/** Row for cached size queries */
|
|
250
|
-
interface CachedSizeRow {
|
|
251
|
-
total: number;
|
|
252
|
-
}
|
|
253
|
-
/** Row for ID queries */
|
|
254
|
-
interface IdRow {
|
|
255
|
-
id: string;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Attachment Queue for @pol-studios/powersync
|
|
36
|
+
* Storage adapter that implements the official @powersync/attachments interface.
|
|
260
37
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* - Cache management with eviction
|
|
264
|
-
* - Image compression
|
|
265
|
-
* - Pause/resume functionality
|
|
266
|
-
* - Progress tracking
|
|
267
|
-
*/
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Platform-agnostic attachment queue for offline file caching.
|
|
38
|
+
* Combines local file system operations (via PlatformAdapter) with remote
|
|
39
|
+
* storage operations (via AttachmentStorageAdapter like Supabase).
|
|
271
40
|
*
|
|
272
41
|
* @example
|
|
273
42
|
* ```typescript
|
|
274
|
-
* const
|
|
275
|
-
* powersync: db,
|
|
43
|
+
* const storageAdapter = new PolStorageAdapter({
|
|
276
44
|
* platform: platformAdapter,
|
|
277
|
-
*
|
|
278
|
-
* source: {
|
|
279
|
-
* table: 'EquipmentUnitMediaContent',
|
|
280
|
-
* idColumn: 'storagePath',
|
|
281
|
-
* orderByColumn: 'takenOn',
|
|
282
|
-
* },
|
|
283
|
-
* storage: storageAdapter,
|
|
284
|
-
* },
|
|
45
|
+
* remoteStorage: supabaseStorageAdapter,
|
|
285
46
|
* });
|
|
286
|
-
*
|
|
287
|
-
* await queue.init();
|
|
288
47
|
* ```
|
|
289
48
|
*/
|
|
290
|
-
declare class
|
|
291
|
-
private readonly powersync;
|
|
49
|
+
declare class PolStorageAdapter implements StorageAdapter {
|
|
292
50
|
private readonly platform;
|
|
293
|
-
private readonly
|
|
294
|
-
private readonly
|
|
295
|
-
private readonly
|
|
296
|
-
|
|
297
|
-
private readonly downloadTimeoutMs;
|
|
298
|
-
private readonly retryDelayMs;
|
|
299
|
-
private readonly downloadStopThreshold;
|
|
300
|
-
private readonly evictionTriggerThreshold;
|
|
301
|
-
private _initialized;
|
|
302
|
-
private _paused;
|
|
303
|
-
private _processing;
|
|
304
|
-
private _cacheFull;
|
|
305
|
-
private _resumeRequested;
|
|
306
|
-
private _maxCacheSize;
|
|
307
|
-
private _compressionQuality;
|
|
308
|
-
private _abort;
|
|
309
|
-
private _downloads;
|
|
310
|
-
private _cachedSize;
|
|
311
|
-
private _cachedSizeTimestamp;
|
|
312
|
-
private _cachedStats;
|
|
313
|
-
private _cachedStatsTimestamp;
|
|
314
|
-
private _lastNotifyTime;
|
|
315
|
-
private _notifyTimer;
|
|
316
|
-
private _progressCallbacks;
|
|
317
|
-
private _watcherInterval;
|
|
318
|
-
constructor(options: {
|
|
319
|
-
powersync: AbstractPowerSyncDatabase;
|
|
320
|
-
platform: PlatformAdapter;
|
|
321
|
-
config: AttachmentQueueConfig;
|
|
322
|
-
});
|
|
323
|
-
/**
|
|
324
|
-
* Initialize the attachment queue.
|
|
325
|
-
* Creates the attachment table if needed and starts watching for downloads.
|
|
326
|
-
*/
|
|
327
|
-
init(): Promise<void>;
|
|
328
|
-
/**
|
|
329
|
-
* Dispose the attachment queue.
|
|
330
|
-
*/
|
|
331
|
-
dispose(): void;
|
|
51
|
+
private readonly remoteStorage;
|
|
52
|
+
private readonly attachmentDirectoryName;
|
|
53
|
+
private readonly userStorageDirectory;
|
|
54
|
+
constructor(options: PolStorageAdapterOptions);
|
|
332
55
|
/**
|
|
333
|
-
*
|
|
334
|
-
* Returns an unsubscribe function.
|
|
56
|
+
* Upload a file to remote storage.
|
|
335
57
|
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
/** Whether currently processing downloads */
|
|
340
|
-
get processing(): boolean;
|
|
58
|
+
uploadFile(filePath: string, data: ArrayBuffer, options?: {
|
|
59
|
+
mediaType?: string;
|
|
60
|
+
}): Promise<void>;
|
|
341
61
|
/**
|
|
342
|
-
*
|
|
62
|
+
* Download a file from remote storage.
|
|
343
63
|
*/
|
|
344
|
-
|
|
64
|
+
downloadFile(filePath: string): Promise<Blob>;
|
|
345
65
|
/**
|
|
346
|
-
*
|
|
66
|
+
* Write data to a local file.
|
|
347
67
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
68
|
+
writeFile(fileUri: string, base64Data: string, options?: {
|
|
69
|
+
encoding?: EncodingType;
|
|
70
|
+
}): Promise<void>;
|
|
351
71
|
/**
|
|
352
|
-
*
|
|
72
|
+
* Read a local file's contents.
|
|
353
73
|
*/
|
|
354
|
-
|
|
74
|
+
readFile(fileUri: string, options?: {
|
|
75
|
+
encoding?: EncodingType;
|
|
76
|
+
mediaType?: string;
|
|
77
|
+
}): Promise<ArrayBuffer>;
|
|
355
78
|
/**
|
|
356
|
-
*
|
|
79
|
+
* Delete a local file.
|
|
357
80
|
*/
|
|
358
|
-
|
|
81
|
+
deleteFile(uri: string, _options?: {
|
|
82
|
+
filename?: string;
|
|
83
|
+
}): Promise<void>;
|
|
359
84
|
/**
|
|
360
|
-
*
|
|
85
|
+
* Check if a local file exists.
|
|
361
86
|
*/
|
|
362
|
-
|
|
87
|
+
fileExists(fileUri: string): Promise<boolean>;
|
|
363
88
|
/**
|
|
364
|
-
*
|
|
89
|
+
* Create a directory (with intermediate directories).
|
|
365
90
|
*/
|
|
366
|
-
|
|
91
|
+
makeDir(uri: string): Promise<void>;
|
|
367
92
|
/**
|
|
368
|
-
*
|
|
93
|
+
* Copy a file from source to destination.
|
|
369
94
|
*/
|
|
370
|
-
|
|
95
|
+
copyFile(sourceUri: string, targetUri: string): Promise<void>;
|
|
371
96
|
/**
|
|
372
|
-
* Get the
|
|
97
|
+
* Get the user's storage directory for attachments.
|
|
98
|
+
* Returns the cache directory path ending with '/'.
|
|
373
99
|
*/
|
|
374
|
-
|
|
100
|
+
getUserStorageDirectory(): string;
|
|
375
101
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* into the cache directory and marking it as SYNCED.
|
|
102
|
+
* Warning 8: Optimized base64 encoding using batch processing.
|
|
103
|
+
* Processes in chunks of 1024 bytes for better performance with large files.
|
|
379
104
|
*/
|
|
380
|
-
|
|
381
|
-
private
|
|
382
|
-
private _syncAttachmentIds;
|
|
383
|
-
private _startDownloads;
|
|
384
|
-
private _downloadOne;
|
|
385
|
-
private _batchUpdateSizes;
|
|
386
|
-
private _getIdsToDownload;
|
|
387
|
-
private _evictIfNeeded;
|
|
388
|
-
private _compressImage;
|
|
389
|
-
private _isImage;
|
|
390
|
-
private _getStatus;
|
|
391
|
-
private _getCachedSizeWithCache;
|
|
392
|
-
private _orderByNewest;
|
|
393
|
-
private _sleep;
|
|
394
|
-
private _withTimeout;
|
|
395
|
-
private _blobToBase64;
|
|
396
|
-
private _notify;
|
|
105
|
+
private _arrayBufferToBase64;
|
|
106
|
+
private _base64ToArrayBuffer;
|
|
397
107
|
}
|
|
398
108
|
|
|
399
|
-
export {
|
|
109
|
+
export { AttachmentStorageAdapter, PolStorageAdapter, type PolStorageAdapterOptions };
|
|
@@ -1,16 +1,34 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-GKF7TOMT.js";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
ATTACHMENT_TABLE,
|
|
4
|
+
AbstractAttachmentQueue,
|
|
4
5
|
AttachmentState,
|
|
6
|
+
AttachmentTable,
|
|
7
|
+
DEFAULT_ATTACHMENT_QUEUE_OPTIONS,
|
|
5
8
|
DEFAULT_CACHE_CONFIG,
|
|
6
9
|
DEFAULT_COMPRESSION_CONFIG,
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
DEFAULT_UPLOAD_CONFIG,
|
|
11
|
+
EncodingType,
|
|
12
|
+
PolAttachmentQueue,
|
|
13
|
+
PolAttachmentState,
|
|
14
|
+
PolStorageAdapter,
|
|
15
|
+
createPolAttachmentQueue
|
|
16
|
+
} from "../chunk-ZEOKPWUC.js";
|
|
17
|
+
import "../chunk-FV2HXEIY.js";
|
|
18
|
+
import "../chunk-DGUM43GV.js";
|
|
9
19
|
export {
|
|
10
|
-
|
|
20
|
+
ATTACHMENT_TABLE,
|
|
21
|
+
AbstractAttachmentQueue,
|
|
11
22
|
AttachmentState,
|
|
23
|
+
AttachmentTable,
|
|
24
|
+
DEFAULT_ATTACHMENT_QUEUE_OPTIONS,
|
|
12
25
|
DEFAULT_CACHE_CONFIG,
|
|
13
26
|
DEFAULT_COMPRESSION_CONFIG,
|
|
14
|
-
|
|
27
|
+
DEFAULT_UPLOAD_CONFIG,
|
|
28
|
+
EncodingType,
|
|
29
|
+
PolAttachmentQueue,
|
|
30
|
+
PolAttachmentState,
|
|
31
|
+
PolStorageAdapter,
|
|
32
|
+
createPolAttachmentQueue
|
|
15
33
|
};
|
|
16
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SyncStatus, S as SyncMode, e as SyncMetrics, b as ConnectionHealth, f as SyncError } from './types-
|
|
1
|
+
import { a as SyncStatus, S as SyncMode, e as SyncMetrics, b as ConnectionHealth, f as SyncError } from './types-CDqWh56B.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Sync Module Types for @pol-studios/powersync
|
|
@@ -221,4 +221,55 @@ type SyncEventListener = (event: SyncEvent) => void;
|
|
|
221
221
|
*/
|
|
222
222
|
type Unsubscribe = () => void;
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
interface BackgroundSyncOptions {
|
|
225
|
+
/** Task name (default: "powersync-background-sync") */
|
|
226
|
+
taskName?: string;
|
|
227
|
+
/** Minimum interval in minutes (default: 15) */
|
|
228
|
+
minimumInterval?: number;
|
|
229
|
+
/** Called when background sync starts */
|
|
230
|
+
onSyncStart?: () => Promise<void>;
|
|
231
|
+
/** Called when background sync completes */
|
|
232
|
+
onSyncComplete?: () => void;
|
|
233
|
+
/** Called on error */
|
|
234
|
+
onError?: (error: Error) => void;
|
|
235
|
+
}
|
|
236
|
+
interface BackgroundSyncSystem {
|
|
237
|
+
/** Initialize PowerSync and connect */
|
|
238
|
+
init: () => Promise<void>;
|
|
239
|
+
/** Disconnect PowerSync */
|
|
240
|
+
disconnect: () => Promise<void>;
|
|
241
|
+
/** Check if PowerSync is connected */
|
|
242
|
+
isConnected: () => boolean;
|
|
243
|
+
/** Get the PowerSync database instance */
|
|
244
|
+
getDatabase: () => any;
|
|
245
|
+
/** Register status change listener, returns unsubscribe function (REQUIRED) */
|
|
246
|
+
onStatusChange: (callback: (status: {
|
|
247
|
+
lastSyncedAt?: Date;
|
|
248
|
+
downloading: boolean;
|
|
249
|
+
uploading: boolean;
|
|
250
|
+
}) => void) => () => void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Define the background sync task.
|
|
254
|
+
* Must be called at module load time (outside of components).
|
|
255
|
+
*/
|
|
256
|
+
declare function defineBackgroundSyncTask(getSystem: () => BackgroundSyncSystem | null, options?: BackgroundSyncOptions): string;
|
|
257
|
+
/**
|
|
258
|
+
* Initialize background sync with AppState management.
|
|
259
|
+
* Registers task when app goes to background, unregisters when active.
|
|
260
|
+
*/
|
|
261
|
+
declare function initializeBackgroundSync(appReadyPromise: Promise<void>, options?: BackgroundSyncOptions): Promise<() => void>;
|
|
262
|
+
/**
|
|
263
|
+
* Manually register the background sync task.
|
|
264
|
+
*/
|
|
265
|
+
declare function registerBackgroundSync(options?: BackgroundSyncOptions): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Manually unregister the background sync task.
|
|
268
|
+
*/
|
|
269
|
+
declare function unregisterBackgroundSync(taskName?: string): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Check if background sync task is registered.
|
|
272
|
+
*/
|
|
273
|
+
declare function isBackgroundSyncRegistered(taskName?: string): Promise<boolean>;
|
|
274
|
+
|
|
275
|
+
export { type BackgroundSyncOptions as B, type HealthMonitorOptions as H, type MetricsCollectorOptions as M, type PowerSyncRawStatus as P, type SyncScope as S, type Unsubscribe as U, type SyncStatusState as a, type SyncStatusTrackerOptions as b, type SyncControlActions as c, type SyncOperationData as d, type HealthCheckResult as e, type SyncEvent as f, type SyncEventListener as g, type BackgroundSyncSystem as h, defineBackgroundSyncTask as i, initializeBackgroundSync as j, isBackgroundSyncRegistered as k, registerBackgroundSync as r, unregisterBackgroundSync as u };
|