@pol-studios/powersync 1.0.30 → 1.0.33

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 (116) hide show
  1. package/dist/{CacheSettingsManager-uz-kbnRH.d.ts → CacheSettingsManager-0H_7thHW.d.ts} +21 -3
  2. package/dist/attachments/index.d.ts +30 -30
  3. package/dist/attachments/index.js +13 -4
  4. package/dist/{background-sync-CVR3PkFi.d.ts → background-sync-BujnI3IR.d.ts} +1 -1
  5. package/dist/{chunk-RE5HWLCB.js → chunk-2RDWLXJW.js} +322 -103
  6. package/dist/chunk-2RDWLXJW.js.map +1 -0
  7. package/dist/{chunk-P4HZA6ZT.js → chunk-4665ZSE5.js} +2 -2
  8. package/dist/chunk-4665ZSE5.js.map +1 -0
  9. package/dist/{chunk-XOY2CJ67.js → chunk-4F5B5CZ7.js} +3 -3
  10. package/dist/chunk-5WRI5ZAA.js +31 -0
  11. package/dist/{chunk-BC2SRII2.js → chunk-65A3SYJZ.js} +14 -1
  12. package/dist/chunk-65A3SYJZ.js.map +1 -0
  13. package/dist/chunk-6SZ64KCZ.js +755 -0
  14. package/dist/chunk-6SZ64KCZ.js.map +1 -0
  15. package/dist/{chunk-C2ACBYBZ.js → chunk-74TBHWJ4.js} +10 -96
  16. package/dist/{chunk-C2ACBYBZ.js.map → chunk-74TBHWJ4.js.map} +1 -1
  17. package/dist/chunk-ANXWYQEJ.js +1 -0
  18. package/dist/chunk-ANXWYQEJ.js.map +1 -0
  19. package/dist/{chunk-CAB26E6F.js → chunk-C4J4MLER.js} +29 -24
  20. package/dist/chunk-C4J4MLER.js.map +1 -0
  21. package/dist/{chunk-C5ODS3XH.js → chunk-EOW7JK7Q.js} +9 -16
  22. package/dist/chunk-EOW7JK7Q.js.map +1 -0
  23. package/dist/chunk-HRAVPIAZ.js +220 -0
  24. package/dist/chunk-HRAVPIAZ.js.map +1 -0
  25. package/dist/{chunk-XAEII4ZX.js → chunk-NUGQOTEM.js} +32 -4
  26. package/dist/chunk-NUGQOTEM.js.map +1 -0
  27. package/dist/chunk-OGUFUZSY.js +5415 -0
  28. package/dist/chunk-OGUFUZSY.js.map +1 -0
  29. package/dist/{chunk-JCGOZVWL.js → chunk-P4D6BQ4X.js} +115 -576
  30. package/dist/chunk-P4D6BQ4X.js.map +1 -0
  31. package/dist/{chunk-CACKC6XG.js → chunk-PGEDE6IM.js} +136 -89
  32. package/dist/chunk-PGEDE6IM.js.map +1 -0
  33. package/dist/{chunk-A4IBBWGO.js → chunk-RALHHPTU.js} +1 -1
  34. package/dist/chunk-RIDSPLE5.js +42 -0
  35. package/dist/chunk-RIDSPLE5.js.map +1 -0
  36. package/dist/{chunk-Z6VOBGTU.js → chunk-UOMHWUHV.js} +2 -12
  37. package/dist/chunk-UOMHWUHV.js.map +1 -0
  38. package/dist/{chunk-QREWE3NR.js → chunk-YONQYTVH.js} +2 -2
  39. package/dist/chunk-ZAN22NGL.js +13 -0
  40. package/dist/chunk-ZAN22NGL.js.map +1 -0
  41. package/dist/config/index.d.ts +200 -0
  42. package/dist/config/index.js +23 -0
  43. package/dist/config/index.js.map +1 -0
  44. package/dist/connector/index.d.ts +23 -5
  45. package/dist/connector/index.js +4 -1
  46. package/dist/core/index.d.ts +2 -2
  47. package/dist/core/index.js +1 -0
  48. package/dist/error/index.js +1 -0
  49. package/dist/generator/index.js +2 -0
  50. package/dist/generator/index.js.map +1 -1
  51. package/dist/index.d.ts +19 -16
  52. package/dist/index.js +68 -36
  53. package/dist/index.native.d.ts +18 -14
  54. package/dist/index.native.js +73 -34
  55. package/dist/index.web.d.ts +17 -14
  56. package/dist/index.web.js +68 -36
  57. package/dist/maintenance/index.d.ts +2 -2
  58. package/dist/maintenance/index.js +3 -2
  59. package/dist/platform/index.d.ts +1 -1
  60. package/dist/platform/index.js +2 -0
  61. package/dist/platform/index.js.map +1 -1
  62. package/dist/platform/index.native.d.ts +1 -1
  63. package/dist/platform/index.native.js +1 -0
  64. package/dist/platform/index.web.d.ts +1 -1
  65. package/dist/platform/index.web.js +1 -0
  66. package/dist/pol-attachment-queue-DqBvLAEY.d.ts +255 -0
  67. package/dist/provider/index.d.ts +149 -114
  68. package/dist/provider/index.js +9 -14
  69. package/dist/provider/index.native.d.ts +108 -0
  70. package/dist/provider/index.native.js +121 -0
  71. package/dist/provider/index.native.js.map +1 -0
  72. package/dist/provider/index.web.d.ts +16 -0
  73. package/dist/provider/index.web.js +112 -0
  74. package/dist/provider/index.web.js.map +1 -0
  75. package/dist/react/index.d.ts +16 -65
  76. package/dist/react/index.js +2 -9
  77. package/dist/storage/index.d.ts +5 -4
  78. package/dist/storage/index.js +12 -9
  79. package/dist/storage/index.native.d.ts +5 -4
  80. package/dist/storage/index.native.js +8 -5
  81. package/dist/storage/index.web.d.ts +5 -4
  82. package/dist/storage/index.web.js +11 -8
  83. package/dist/storage/upload/index.d.ts +4 -3
  84. package/dist/storage/upload/index.js +4 -2
  85. package/dist/storage/upload/index.native.d.ts +4 -3
  86. package/dist/storage/upload/index.native.js +4 -2
  87. package/dist/storage/upload/index.web.d.ts +2 -1
  88. package/dist/storage/upload/index.web.js +4 -2
  89. package/dist/{supabase-connector-C4YpH_l3.d.ts → supabase-connector-HMxBA9Kg.d.ts} +2 -2
  90. package/dist/sync/index.d.ts +155 -20
  91. package/dist/sync/index.js +13 -3
  92. package/dist/{types-CyvBaAl8.d.ts → types-6QHGELuY.d.ts} +4 -1
  93. package/dist/{types-Dv1uf0LZ.d.ts → types-B9MptP7E.d.ts} +7 -10
  94. package/dist/types-BhAEsJj-.d.ts +330 -0
  95. package/dist/{types-D0WcHrq6.d.ts → types-CGMibJKD.d.ts} +8 -0
  96. package/dist/{types-CpM2_LhU.d.ts → types-DqJnP50o.d.ts} +6 -1
  97. package/dist/{pol-attachment-queue-BE2HU3Us.d.ts → types-JCEhw2Lf.d.ts} +139 -346
  98. package/package.json +18 -4
  99. package/dist/chunk-654ERHA7.js +0 -1
  100. package/dist/chunk-BC2SRII2.js.map +0 -1
  101. package/dist/chunk-C5ODS3XH.js.map +0 -1
  102. package/dist/chunk-CAB26E6F.js.map +0 -1
  103. package/dist/chunk-CACKC6XG.js.map +0 -1
  104. package/dist/chunk-FNYQFILT.js +0 -44
  105. package/dist/chunk-FNYQFILT.js.map +0 -1
  106. package/dist/chunk-JCGOZVWL.js.map +0 -1
  107. package/dist/chunk-P4HZA6ZT.js.map +0 -1
  108. package/dist/chunk-RBPWEOIV.js +0 -358
  109. package/dist/chunk-RBPWEOIV.js.map +0 -1
  110. package/dist/chunk-RE5HWLCB.js.map +0 -1
  111. package/dist/chunk-XAEII4ZX.js.map +0 -1
  112. package/dist/chunk-Z6VOBGTU.js.map +0 -1
  113. /package/dist/{chunk-XOY2CJ67.js.map → chunk-4F5B5CZ7.js.map} +0 -0
  114. /package/dist/{chunk-654ERHA7.js.map → chunk-5WRI5ZAA.js.map} +0 -0
  115. /package/dist/{chunk-A4IBBWGO.js.map → chunk-RALHHPTU.js.map} +0 -0
  116. /package/dist/{chunk-QREWE3NR.js.map → chunk-YONQYTVH.js.map} +0 -0
@@ -0,0 +1,330 @@
1
+ import { Schema } from '@powersync/react-native';
2
+ import { h as UploadErrorMiddleware } from './types-DqJnP50o.js';
3
+ import { A as AttachmentSource } from './types-JCEhw2Lf.js';
4
+
5
+ /**
6
+ * Unified Configuration Types for @pol-studios/powersync
7
+ *
8
+ * This module defines the types for the `definePolConfig` API which provides
9
+ * a streamlined way to configure PowerSync with automatic schema generation.
10
+ */
11
+
12
+ interface MinimalPowerSyncDatabase {
13
+ watch(sql: string, params: unknown[], callbacks: {
14
+ onResult: (results: {
15
+ rows?: {
16
+ _array?: unknown[];
17
+ };
18
+ }) => void;
19
+ onError?: (error: Error) => void;
20
+ }, options?: {
21
+ signal?: AbortSignal;
22
+ tables?: string[];
23
+ throttleMs?: number;
24
+ }): void;
25
+ }
26
+ /**
27
+ * Table specification for PowerSync sync.
28
+ *
29
+ * Can be either:
30
+ * - A string for public schema tables (e.g., "Project")
31
+ * - An object for custom schemas or additional options
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Simple - public schema
36
+ * powersync: ["Project", "Task"]
37
+ *
38
+ * // Custom schema
39
+ * powersync: [
40
+ * "Project",
41
+ * { table: "Profile", schema: "core" },
42
+ * { table: "Comment", schema: "core", trackMetadata: true }
43
+ * ]
44
+ * ```
45
+ */
46
+ type TableSpec = string | {
47
+ /** Table name */
48
+ table: string;
49
+ /** Schema name (default: "public") */
50
+ schema?: string;
51
+ /** Track sync metadata for this table (default: false) */
52
+ trackMetadata?: boolean;
53
+ };
54
+
55
+ /**
56
+ * Configuration for attachment sync.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * attachments: {
61
+ * source: { type: 'supabase-bucket', bucket: 'photos', signed: true },
62
+ * watchPaths: (db, supabase, onUpdate) => {
63
+ * const abort = new AbortController();
64
+ * db.watch(
65
+ * // Filter directly in the query - only emit paths you want to download
66
+ * `SELECT storagePath FROM photos
67
+ * WHERE storagePath IS NOT NULL
68
+ * AND storagePath NOT LIKE '%.mp4'`,
69
+ * [],
70
+ * { onResult: (r) => onUpdate(r.rows._array.map(row => row.storagePath)) },
71
+ * { signal: abort.signal }
72
+ * );
73
+ * return () => abort.abort();
74
+ * },
75
+ * }
76
+ * ```
77
+ */
78
+ interface PolConfigAttachments {
79
+ /**
80
+ * Attachment storage source configuration.
81
+ * Supports Supabase Storage buckets or custom backends.
82
+ */
83
+ source?: AttachmentSource;
84
+ /**
85
+ * Reactive source of attachment paths.
86
+ *
87
+ * Called once during initialization. Should set up a reactive subscription
88
+ * that calls `onUpdate` whenever the set of attachment paths changes.
89
+ *
90
+ * Filtering should happen in this callback - only emit paths you want to download.
91
+ *
92
+ * @param db - PowerSync database instance
93
+ * @param supabase - Supabase client for additional queries if needed
94
+ * @param onUpdate - Callback to emit current set of attachment paths
95
+ * @returns Optional cleanup function
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * watchPaths: (db, supabase, onUpdate) => {
100
+ * const abort = new AbortController();
101
+ * db.watch(
102
+ * // Filter out videos directly in the query
103
+ * `SELECT storagePath FROM photos
104
+ * WHERE storagePath IS NOT NULL
105
+ * AND storagePath NOT LIKE '%.mp4'`,
106
+ * [],
107
+ * { onResult: (r) => onUpdate(r.rows._array.map(row => row.storagePath)) },
108
+ * { signal: abort.signal }
109
+ * );
110
+ * return () => abort.abort();
111
+ * }
112
+ * ```
113
+ */
114
+ watchPaths?: (db: MinimalPowerSyncDatabase, supabase: unknown, onUpdate: (paths: string[]) => void) => (() => void) | void;
115
+ }
116
+ /**
117
+ * Connector configuration for CRUD upload handling.
118
+ */
119
+ interface PolConfigConnector {
120
+ /**
121
+ * Enable version-based conflict detection.
122
+ * @default false
123
+ */
124
+ conflictDetection?: boolean;
125
+ /**
126
+ * Middleware chain for classifying upload errors.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * uploadErrorMiddleware: [
131
+ * idempotentTables(['ReadReceipt', 'Like']),
132
+ * discardOrphaned(),
133
+ * ]
134
+ * ```
135
+ */
136
+ uploadErrorMiddleware?: UploadErrorMiddleware[];
137
+ }
138
+ /**
139
+ * Sync behavior configuration.
140
+ */
141
+ interface PolConfigSync {
142
+ /**
143
+ * Automatically connect when the provider mounts.
144
+ * @default true
145
+ */
146
+ autoConnect?: boolean;
147
+ /**
148
+ * Background sync configuration.
149
+ */
150
+ backgroundSync?: {
151
+ /** Enable background sync */
152
+ enabled: boolean;
153
+ /** Minimum interval between background syncs in minutes */
154
+ minimumInterval?: number;
155
+ };
156
+ /**
157
+ * Enable health monitoring.
158
+ * @default true
159
+ */
160
+ enableHealthMonitoring?: boolean;
161
+ /**
162
+ * Enable metrics collection.
163
+ * @default true
164
+ */
165
+ enableMetrics?: boolean;
166
+ }
167
+ /**
168
+ * Unified configuration for @pol-studios/powersync.
169
+ *
170
+ * This configuration is processed by `definePolConfig` to generate:
171
+ * - PowerSync Schema from the database schema
172
+ * - Table strategies for DataLayer routing
173
+ * - Attachment queue configuration
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * import { definePolConfig } from '@pol-studios/powersync/config';
178
+ * import { databaseSchema } from './databaseSchema';
179
+ *
180
+ * export const polConfig = definePolConfig({
181
+ * powerSyncUrl: process.env.EXPO_PUBLIC_POWERSYNC_URL,
182
+ * databaseSchema,
183
+ *
184
+ * // Tables to sync via PowerSync
185
+ * powersync: [
186
+ * "Project",
187
+ * "Task",
188
+ * { table: "Profile", schema: "core" },
189
+ * ],
190
+ *
191
+ * attachments: {
192
+ * source: { type: 'supabase-bucket', bucket: 'photos' },
193
+ * watchPaths: (db, supabase, onUpdate) => {
194
+ * const abort = new AbortController();
195
+ * db.watch('SELECT storagePath FROM photos WHERE storagePath IS NOT NULL', [], {
196
+ * onResult: (r) => onUpdate(r.rows._array.map(x => x.storagePath)),
197
+ * }, { signal: abort.signal });
198
+ * return () => abort.abort();
199
+ * },
200
+ * },
201
+ * });
202
+ * ```
203
+ */
204
+ interface PolConfig {
205
+ /**
206
+ * PowerSync service URL.
207
+ * If not provided, runs in online-only mode (Supabase direct).
208
+ *
209
+ * @example "https://your-instance.powersync.journeyapps.com"
210
+ */
211
+ powerSyncUrl?: string;
212
+ /**
213
+ * The database schema object (from generated types).
214
+ * Used to auto-generate the PowerSync schema at runtime.
215
+ *
216
+ * This is the schema object exported from your generated databaseSchema.ts,
217
+ * which contains table definitions with columns and types.
218
+ */
219
+ databaseSchema: DatabaseSchemaObject;
220
+ /**
221
+ * Tables to sync via PowerSync (offline-first).
222
+ *
223
+ * Tables listed here will be synced to the local SQLite database.
224
+ * Tables NOT listed here will query Supabase directly (online-only).
225
+ */
226
+ powersync: TableSpec[];
227
+ /**
228
+ * Connector configuration for CRUD upload handling.
229
+ */
230
+ connector?: PolConfigConnector;
231
+ /**
232
+ * Attachment configuration for offline file caching.
233
+ */
234
+ attachments?: PolConfigAttachments;
235
+ /**
236
+ * Sync behavior configuration.
237
+ */
238
+ sync?: PolConfigSync;
239
+ /**
240
+ * Database filename for the local SQLite database.
241
+ * @default "powersync.db"
242
+ */
243
+ dbFilename?: string;
244
+ }
245
+ /**
246
+ * Table strategy for routing queries.
247
+ */
248
+ type TableStrategyType = 'powersync' | 'supabase';
249
+ /**
250
+ * Processed table strategy info.
251
+ */
252
+ interface ProcessedTableStrategy {
253
+ /** Which backend to use */
254
+ strategy: TableStrategyType;
255
+ /** Original schema name */
256
+ schema: string;
257
+ /** Table name */
258
+ table: string;
259
+ /** PowerSync SQLite alias (e.g., CoreUserGroup for core.UserGroup) */
260
+ alias: string;
261
+ }
262
+ /**
263
+ * Processed configuration returned by `definePolConfig`.
264
+ *
265
+ * Contains the original config plus generated artifacts:
266
+ * - `__generatedSchema`: PowerSync Schema ready to use
267
+ * - `__tableStrategies`: Lookup map for table routing
268
+ * - `__schemaRouter`: Function to resolve table schema
269
+ */
270
+ interface ProcessedPolConfig extends PolConfig {
271
+ /**
272
+ * Generated PowerSync Schema.
273
+ * Pass this to PowerSyncProvider or OfflineDataProvider.
274
+ */
275
+ __generatedSchema: Schema;
276
+ /**
277
+ * Table strategy lookup map.
278
+ * Used by DataLayerProvider to route queries to the correct backend.
279
+ */
280
+ __tableStrategies: Record<string, ProcessedTableStrategy>;
281
+ /**
282
+ * Schema router function.
283
+ * Returns the Supabase schema for a given table name.
284
+ *
285
+ * @param table - Table name (may include schema prefix like "core.Profile")
286
+ * @returns The schema name
287
+ */
288
+ __schemaRouter: (table: string) => string;
289
+ /**
290
+ * List of tables configured for PowerSync sync.
291
+ * Useful for deriving DataLayerConfig.
292
+ */
293
+ __powersyncTables: string[];
294
+ }
295
+ /**
296
+ * Column definition in the database schema.
297
+ */
298
+ interface DatabaseColumnDef {
299
+ name: string;
300
+ /** Column type - accepts any string but common values are: 'string', 'number', 'boolean', 'date', 'enum', 'json' */
301
+ type: string;
302
+ isOptional: boolean;
303
+ isEnum?: boolean;
304
+ enumValues?: string[];
305
+ }
306
+ /**
307
+ * Table definition in the database schema.
308
+ */
309
+ interface DatabaseTableDef {
310
+ name: string;
311
+ columns: DatabaseColumnDef[];
312
+ relationships?: Array<{
313
+ foreignKey: string;
314
+ referencedTable: string;
315
+ referencedColumn: string;
316
+ }>;
317
+ }
318
+ /**
319
+ * Schema definition structure (matches databaseSchema.ts export).
320
+ */
321
+ interface DatabaseSchemaObject {
322
+ schemas: {
323
+ [schemaName: string]: {
324
+ tables: Record<string, DatabaseTableDef>;
325
+ views?: Record<string, DatabaseTableDef>;
326
+ };
327
+ };
328
+ }
329
+
330
+ export type { DatabaseSchemaObject as D, PolConfig as P, TableSpec as T, ProcessedPolConfig as a, ProcessedTableStrategy as b, PolConfigAttachments as c, PolConfigConnector as d, PolConfigSync as e, DatabaseTableDef as f, DatabaseColumnDef as g };
@@ -188,6 +188,14 @@ interface SupabaseClient {
188
188
  } | null;
189
189
  error: Error | null;
190
190
  }>;
191
+ getPublicUrl(path: string, options?: {
192
+ download?: string | boolean;
193
+ transform?: SupabaseTransformOptions;
194
+ }): {
195
+ data: {
196
+ publicUrl: string;
197
+ };
198
+ };
191
199
  upload(path: string, file: Blob | ArrayBuffer | FormData, options?: {
192
200
  contentType?: string;
193
201
  upsert?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
- import { C as CrudEntry, i as ClassifiedError } from './types-Dv1uf0LZ.js';
2
+ import { C as CrudEntry, i as ClassifiedError } from './types-B9MptP7E.js';
3
3
  import { LoggerAdapter } from './platform/index.js';
4
4
 
5
5
  /**
@@ -280,6 +280,11 @@ interface ConnectorConfig {
280
280
  * @deprecated No longer used. PowerSync SDK handles all retries.
281
281
  */
282
282
  retryConfig?: Partial<RetryConfig>;
283
+ /**
284
+ * Optional: Middleware chain for classifying upload errors.
285
+ * Passed to SupabaseConnector for error handling decisions.
286
+ */
287
+ uploadErrorMiddleware?: UploadErrorMiddleware[];
283
288
  }
284
289
  /**
285
290
  * Function that determines which Supabase schema a table belongs to.