@pol-studios/db 1.0.9 → 1.0.11

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 (113) hide show
  1. package/dist/DataLayerContext-CL6alnkb.d.ts +755 -0
  2. package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
  3. package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
  4. package/dist/auth/context.d.ts +3 -2
  5. package/dist/auth/context.js +22 -12786
  6. package/dist/auth/context.js.map +1 -1
  7. package/dist/auth/guards.js +12 -7640
  8. package/dist/auth/guards.js.map +1 -1
  9. package/dist/auth/hooks.d.ts +3 -3
  10. package/dist/auth/hooks.js +26 -10591
  11. package/dist/auth/hooks.js.map +1 -1
  12. package/dist/auth/index.d.ts +3 -2
  13. package/dist/auth/index.js +45 -13008
  14. package/dist/auth/index.js.map +1 -1
  15. package/dist/{canvas-UVNDA54X.node → canvas-C4TBBDUL.node} +0 -0
  16. package/dist/canvas-ZQNCL7JL.js +1541 -0
  17. package/dist/canvas-ZQNCL7JL.js.map +1 -0
  18. package/dist/chunk-3PJTNH2L.js +2778 -0
  19. package/dist/chunk-3PJTNH2L.js.map +1 -0
  20. package/dist/chunk-5EFDS7SR.js +205 -0
  21. package/dist/chunk-5EFDS7SR.js.map +1 -0
  22. package/dist/chunk-7SCJNYTE.js +1459 -0
  23. package/dist/chunk-7SCJNYTE.js.map +1 -0
  24. package/dist/chunk-DJ6VLEAL.js +247 -0
  25. package/dist/chunk-DJ6VLEAL.js.map +1 -0
  26. package/dist/chunk-GC3TBUWE.js +14 -0
  27. package/dist/chunk-GC3TBUWE.js.map +1 -0
  28. package/dist/chunk-H3LNH2NT.js +611 -0
  29. package/dist/chunk-H3LNH2NT.js.map +1 -0
  30. package/dist/chunk-H6365JPC.js +1858 -0
  31. package/dist/chunk-H6365JPC.js.map +1 -0
  32. package/dist/chunk-HAWJTZCK.js +86 -0
  33. package/dist/chunk-HAWJTZCK.js.map +1 -0
  34. package/dist/chunk-J4ZVCXZ4.js +1 -0
  35. package/dist/chunk-J4ZVCXZ4.js.map +1 -0
  36. package/dist/chunk-JAATANS3.js +429 -0
  37. package/dist/chunk-JAATANS3.js.map +1 -0
  38. package/dist/chunk-LNJ3WF7V.js +470 -0
  39. package/dist/chunk-LNJ3WF7V.js.map +1 -0
  40. package/dist/chunk-N26IEHZT.js +79 -0
  41. package/dist/chunk-N26IEHZT.js.map +1 -0
  42. package/dist/chunk-NSIAAYW3.js +1 -0
  43. package/dist/chunk-NSIAAYW3.js.map +1 -0
  44. package/dist/chunk-NZON56CB.js +3864 -0
  45. package/dist/chunk-NZON56CB.js.map +1 -0
  46. package/dist/chunk-OQ7U6EQ3.js +7550 -0
  47. package/dist/chunk-OQ7U6EQ3.js.map +1 -0
  48. package/dist/chunk-P4UZ7IXC.js +42 -0
  49. package/dist/chunk-P4UZ7IXC.js.map +1 -0
  50. package/dist/chunk-SM73S2DY.js +11 -0
  51. package/dist/chunk-SM73S2DY.js.map +1 -0
  52. package/dist/chunk-TKWR5AAY.js +415 -0
  53. package/dist/chunk-TKWR5AAY.js.map +1 -0
  54. package/dist/chunk-U5UNPBKB.js +501 -0
  55. package/dist/chunk-U5UNPBKB.js.map +1 -0
  56. package/dist/chunk-WGDJ4IXR.js +921 -0
  57. package/dist/chunk-WGDJ4IXR.js.map +1 -0
  58. package/dist/chunk-WVF7RUW5.js +186 -0
  59. package/dist/chunk-WVF7RUW5.js.map +1 -0
  60. package/dist/chunk-X3HZLNBV.js +2129 -0
  61. package/dist/chunk-X3HZLNBV.js.map +1 -0
  62. package/dist/chunk-XU3SBFAG.js +5205 -0
  63. package/dist/chunk-XU3SBFAG.js.map +1 -0
  64. package/dist/chunk-ZVBHWU7O.js +1412 -0
  65. package/dist/chunk-ZVBHWU7O.js.map +1 -0
  66. package/dist/client/index.d.ts +1 -1
  67. package/dist/client/index.js +54 -163
  68. package/dist/client/index.js.map +1 -1
  69. package/dist/core/index.d.ts +19 -0
  70. package/dist/{index-BFu5_dS8.d.ts → database.types-ChFCG-4M.d.ts} +1 -177
  71. package/dist/dist-NDNRSNOG.js +521 -0
  72. package/dist/dist-NDNRSNOG.js.map +1 -0
  73. package/dist/gen/index.js +188 -1280
  74. package/dist/gen/index.js.map +1 -1
  75. package/dist/hooks/index.d.ts +10 -3
  76. package/dist/hooks/index.js +20 -8695
  77. package/dist/hooks/index.js.map +1 -1
  78. package/dist/index-CQLyNG6A.d.ts +433 -0
  79. package/dist/index.d.ts +12 -8
  80. package/dist/index.js +447 -47848
  81. package/dist/index.js.map +1 -1
  82. package/dist/index.native.d.ts +373 -33
  83. package/dist/index.native.js +432 -25048
  84. package/dist/index.native.js.map +1 -1
  85. package/dist/index.web.d.ts +10 -7
  86. package/dist/index.web.js +585 -43773
  87. package/dist/index.web.js.map +1 -1
  88. package/dist/mutation/index.d.ts +2 -2
  89. package/dist/mutation/index.js +331 -4777
  90. package/dist/mutation/index.js.map +1 -1
  91. package/dist/parser/index.js +45 -3697
  92. package/dist/parser/index.js.map +1 -1
  93. package/dist/pdf-PHXP7RHD.js +20336 -0
  94. package/dist/pdf-PHXP7RHD.js.map +1 -0
  95. package/dist/powersync-bridge/index.d.ts +284 -0
  96. package/dist/powersync-bridge/index.js +22 -0
  97. package/dist/powersync-bridge/index.js.map +1 -0
  98. package/dist/query/index.js +31 -13175
  99. package/dist/query/index.js.map +1 -1
  100. package/dist/realtime/index.js +279 -12541
  101. package/dist/realtime/index.js.map +1 -1
  102. package/dist/{UserMetadataContext-BYYqA6LI.d.ts → setupAuthContext-Kv-THH-h.d.ts} +1 -29
  103. package/dist/types/index.d.ts +5 -1
  104. package/dist/types/index.js +14 -0
  105. package/dist/{useBatchUpsert-CSQVX7w8.d.ts → useBatchUpsert-9OYjibLh.d.ts} +1 -1
  106. package/dist/{useDbCount-RGCuHmHp.d.ts → useDbCount-BG356T9i.d.ts} +3 -719
  107. package/dist/{useReceiptAI-Bn0czE7C.d.ts → useReceiptAI-6HkRpRml.d.ts} +1 -1
  108. package/dist/{useResolveFeedback-CpZPP8Pw.d.ts → useResolveFeedback-BWmatBlE.d.ts} +26 -45
  109. package/dist/{useSupabase-pPhUZHcl.d.ts → useSupabase-DvWVuHHE.d.ts} +2 -1
  110. package/dist/with-auth/index.d.ts +704 -0
  111. package/dist/with-auth/index.js +1221 -0
  112. package/dist/with-auth/index.js.map +1 -0
  113. package/package.json +25 -10
@@ -0,0 +1,755 @@
1
+ import * as react from 'react';
2
+ import { SupabaseClient } from '@supabase/supabase-js';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import { DatabaseSchema, QueryOptions, DataLayerConfig, TableStrategy, SyncStatus, SyncControl } from './core/index.js';
5
+ import { P as PowerSyncDatabase } from './executor-CB4KHyYG.js';
6
+
7
+ /**
8
+ * V3 Data Layer Adapter Types
9
+ *
10
+ * Extended types for the adapter layer that complement the core DataAdapter interface.
11
+ * These types support the Strategy pattern for routing queries to different backends.
12
+ */
13
+
14
+ /**
15
+ * Result from adapter query operations.
16
+ * Extends the basic array with optional count for pagination.
17
+ */
18
+ interface AdapterQueryResult<T> {
19
+ /** The queried data */
20
+ data: T[];
21
+ /** Total count of matching records (for pagination) */
22
+ count?: number;
23
+ }
24
+ /**
25
+ * Extended adapter interface that accepts table name for multi-table routing.
26
+ *
27
+ * This interface is used by the AdapterRegistry to provide table-aware adapters
28
+ * that can handle multiple tables with a single adapter instance.
29
+ *
30
+ * Differences from core DataAdapter:
31
+ * - Includes table name parameter in all methods
32
+ * - Returns AdapterQueryResult with optional count
33
+ * - Supports optional subscribe method for reactivity
34
+ */
35
+ interface TableDataAdapter {
36
+ /**
37
+ * Unique identifier for the adapter type
38
+ */
39
+ readonly name: string;
40
+ /**
41
+ * Execute a query and return results
42
+ *
43
+ * @param table - The table name to query
44
+ * @param options - Query options (select, where, orderBy, limit, offset)
45
+ * @returns Promise resolving to query results with optional count
46
+ */
47
+ query<T>(table: string, options: QueryOptions): Promise<AdapterQueryResult<T>>;
48
+ /**
49
+ * Query a single record by ID
50
+ *
51
+ * @param table - The table name to query
52
+ * @param id - The record ID
53
+ * @param options - Optional query options (mainly for select)
54
+ * @returns Promise resolving to the record or null if not found
55
+ */
56
+ queryById?<T>(table: string, id: string, options?: Pick<QueryOptions, "select">): Promise<T | null>;
57
+ /**
58
+ * Subscribe to real-time changes on a query.
59
+ * Not all adapters support this - it's optional.
60
+ *
61
+ * @param table - The table name to watch
62
+ * @param options - Query options to filter what to watch
63
+ * @param callback - Function called with updated data
64
+ * @returns Unsubscribe function
65
+ */
66
+ subscribe?<T>(table: string, options: QueryOptions, callback: (data: T[]) => void): () => void;
67
+ /**
68
+ * Insert a new record
69
+ *
70
+ * @param table - The table name
71
+ * @param data - The data to insert
72
+ * @returns Promise resolving to the inserted record
73
+ */
74
+ insert<T>(table: string, data: Partial<T>): Promise<T>;
75
+ /**
76
+ * Update an existing record by ID
77
+ *
78
+ * @param table - The table name
79
+ * @param id - The record ID to update
80
+ * @param data - The data to update
81
+ * @returns Promise resolving to the updated record
82
+ */
83
+ update<T>(table: string, id: string, data: Partial<T>): Promise<T>;
84
+ /**
85
+ * Upsert (insert or update) a record
86
+ * If the record has an ID and exists, it will be updated.
87
+ * Otherwise, a new record will be inserted.
88
+ *
89
+ * @param table - The table name
90
+ * @param data - The data to upsert
91
+ * @returns Promise resolving to the upserted record
92
+ */
93
+ upsert<T>(table: string, data: Partial<T>): Promise<T>;
94
+ /**
95
+ * Delete a record by ID
96
+ *
97
+ * @param table - The table name
98
+ * @param id - The record ID to delete
99
+ * @returns Promise that resolves when deletion is complete
100
+ */
101
+ delete(table: string, id: string): Promise<void>;
102
+ }
103
+ /**
104
+ * Configuration for creating an adapter
105
+ */
106
+ interface AdapterConfig {
107
+ /**
108
+ * The strategy type to create
109
+ */
110
+ strategy: "powersync" | "supabase" | "cached" | "hybrid";
111
+ /**
112
+ * Additional strategy-specific configuration
113
+ */
114
+ [key: string]: unknown;
115
+ }
116
+ /**
117
+ * Factory interface for creating adapters
118
+ */
119
+ interface AdapterFactory {
120
+ /**
121
+ * Create a new adapter instance based on configuration
122
+ *
123
+ * @param config - Adapter configuration
124
+ * @returns The created adapter instance
125
+ */
126
+ create(config: AdapterConfig): TableDataAdapter;
127
+ }
128
+ /**
129
+ * Describes the capabilities of an adapter
130
+ */
131
+ interface AdapterCapabilities {
132
+ /**
133
+ * Whether the adapter supports real-time subscriptions
134
+ */
135
+ supportsSubscribe: boolean;
136
+ /**
137
+ * Whether the adapter works offline
138
+ */
139
+ supportsOffline: boolean;
140
+ /**
141
+ * Whether the adapter caches data locally
142
+ */
143
+ supportsCache: boolean;
144
+ /**
145
+ * Whether the adapter syncs data bidirectionally
146
+ */
147
+ supportsSync: boolean;
148
+ }
149
+ /**
150
+ * Extended adapter interface with capability reporting
151
+ */
152
+ interface CapableDataAdapter extends TableDataAdapter {
153
+ /**
154
+ * Get the capabilities of this adapter
155
+ */
156
+ readonly capabilities: AdapterCapabilities;
157
+ }
158
+ /**
159
+ * Dependencies required to initialize adapters.
160
+ * Uses 'unknown' type for external dependencies to allow proper typing
161
+ * when concrete implementations are provided.
162
+ */
163
+ interface AdapterDependencies {
164
+ /**
165
+ * PowerSync database instance
166
+ * Will be typed as PowerSyncDatabase when PowerSync is integrated
167
+ */
168
+ powerSync: unknown;
169
+ /**
170
+ * Supabase client instance
171
+ * Will be typed as SupabaseClient when imported
172
+ */
173
+ supabase: unknown;
174
+ /**
175
+ * TanStack Query client for caching
176
+ * Will be typed as QueryClient when imported
177
+ */
178
+ queryClient: unknown;
179
+ /**
180
+ * Database schema for relationship resolution
181
+ */
182
+ schema: DatabaseSchema;
183
+ }
184
+ /**
185
+ * String literals for adapter strategy types
186
+ */
187
+ declare const ADAPTER_STRATEGIES: {
188
+ readonly POWERSYNC: "powersync";
189
+ readonly SUPABASE: "supabase";
190
+ readonly CACHED: "cached";
191
+ readonly HYBRID: "hybrid";
192
+ readonly AUTO: "auto";
193
+ };
194
+
195
+ /**
196
+ * Type for adapter strategy values
197
+ */
198
+ type AdapterStrategyType = (typeof ADAPTER_STRATEGIES)[keyof typeof ADAPTER_STRATEGIES];
199
+
200
+ /**
201
+ * Adapter Auto-Detector
202
+ *
203
+ * Detects available backends (PowerSync, Supabase) at runtime and recommends
204
+ * the best one to use based on availability and configuration preferences.
205
+ *
206
+ * This enables the V3 data layer to automatically select the optimal backend
207
+ * for offline-first or online-first experiences.
208
+ */
209
+
210
+ /**
211
+ * Status of a backend adapter
212
+ */
213
+ declare enum BackendStatus {
214
+ /** Backend is available and ready to use */
215
+ AVAILABLE = "available",
216
+ /** Backend is initializing (e.g., PowerSync syncing) */
217
+ INITIALIZING = "initializing",
218
+ /** Backend is not available */
219
+ UNAVAILABLE = "unavailable"
220
+ }
221
+ /**
222
+ * Result of auto-detection
223
+ */
224
+ interface AutoDetectionResult {
225
+ /** PowerSync availability status */
226
+ powerSyncStatus: BackendStatus;
227
+ /** Supabase availability status */
228
+ supabaseStatus: BackendStatus;
229
+ /** Recommended backend to use */
230
+ recommendedBackend: "powersync" | "supabase";
231
+ /** Whether device is online */
232
+ isOnline: boolean;
233
+ /** Reason for recommendation */
234
+ reason: string;
235
+ }
236
+ /**
237
+ * Sync status information from PowerSync
238
+ */
239
+ interface SyncStatusInfo {
240
+ /** Whether PowerSync has completed at least one full sync */
241
+ hasSynced: boolean;
242
+ /** Whether connected to PowerSync service */
243
+ connected: boolean;
244
+ /** Whether currently connecting */
245
+ connecting: boolean;
246
+ /** Network connectivity status from platform adapter (NetInfo on React Native) */
247
+ isOnline?: boolean;
248
+ }
249
+ /**
250
+ * Options for auto-detection
251
+ */
252
+ interface AutoDetectorOptions {
253
+ /** Prefer PowerSync when available (default: true) */
254
+ preferPowerSync?: boolean;
255
+ /** Timeout for status checks in ms (default: 1000) */
256
+ statusCheckTimeout?: number;
257
+ /**
258
+ * Use Supabase for queries until PowerSync completes initial sync.
259
+ * When true, queries return online data while syncing.
260
+ * @default true
261
+ */
262
+ useOnlineUntilSynced?: boolean;
263
+ }
264
+ /**
265
+ * Listener for backend change events
266
+ */
267
+ type BackendChangeListener = (result: AutoDetectionResult) => void;
268
+ /**
269
+ * Detects available backends and recommends the best one to use.
270
+ *
271
+ * The auto-detector checks for PowerSync and Supabase availability and
272
+ * makes intelligent recommendations based on:
273
+ * - Backend availability
274
+ * - Network connectivity
275
+ * - User preferences (preferPowerSync option)
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const detector = new AdapterAutoDetector(powerSyncDb, supabaseClient, {
280
+ * preferPowerSync: true,
281
+ * });
282
+ *
283
+ * const result = detector.detect();
284
+ * console.log(`Using ${result.recommendedBackend}: ${result.reason}`);
285
+ * ```
286
+ */
287
+ declare class AdapterAutoDetector {
288
+ private powerSyncDb;
289
+ private supabase;
290
+ private options;
291
+ private listeners;
292
+ private lastResult;
293
+ private syncStatus;
294
+ constructor(powerSyncDb: PowerSyncDatabase | null, supabase: SupabaseClient | null, options?: AutoDetectorOptions);
295
+ /**
296
+ * Update the sync status from PowerSync.
297
+ * Called when sync status changes to re-evaluate backend recommendation.
298
+ *
299
+ * @param status - Current sync status or null if not available
300
+ */
301
+ updateSyncStatus(status: SyncStatusInfo | null): void;
302
+ /**
303
+ * Get current sync status.
304
+ * @returns Current sync status or null
305
+ */
306
+ getSyncStatus(): SyncStatusInfo | null;
307
+ /**
308
+ * Detect backend availability and recommend best option.
309
+ *
310
+ * The detection logic follows this priority:
311
+ * 1. If preferPowerSync is true and PowerSync is available, use PowerSync
312
+ * 2. If PowerSync is initializing and online with Supabase available, use Supabase temporarily
313
+ * 3. If online with Supabase available, use Supabase
314
+ * 4. If offline but PowerSync available, use PowerSync (offline mode)
315
+ * 5. If offline and PowerSync exists (even if initializing), use PowerSync local data
316
+ * 6. Default to Supabase as fallback
317
+ *
318
+ * @returns Detection result with recommendation and reasoning
319
+ */
320
+ detect(): AutoDetectionResult;
321
+ /**
322
+ * Check if PowerSync is available.
323
+ *
324
+ * PowerSync status depends on:
325
+ * 1. Database instance exists
326
+ * 2. If useOnlineUntilSynced is true, also checks if initial sync completed
327
+ *
328
+ * @returns PowerSync backend status
329
+ */
330
+ detectPowerSyncStatus(): BackendStatus;
331
+ /**
332
+ * Check if Supabase is available.
333
+ *
334
+ * Supabase is considered available if we have a client instance.
335
+ * The actual network connectivity is checked separately via checkOnlineStatus().
336
+ *
337
+ * @returns Supabase backend status
338
+ */
339
+ detectSupabaseStatus(): BackendStatus;
340
+ /**
341
+ * Check if device is online.
342
+ *
343
+ * Prefers the sync status's isOnline property if available (from React Native NetInfo).
344
+ * Falls back to navigator.onLine in browser environments.
345
+ * Returns true by default for other environments.
346
+ *
347
+ * @returns Whether the device has network connectivity
348
+ */
349
+ checkOnlineStatus(): boolean;
350
+ /**
351
+ * Update PowerSync instance (e.g., when it becomes available).
352
+ *
353
+ * @param db - New PowerSync database instance or null
354
+ */
355
+ setPowerSync(db: PowerSyncDatabase | null): void;
356
+ /**
357
+ * Update Supabase instance.
358
+ *
359
+ * @param supabase - New Supabase client instance or null
360
+ */
361
+ setSupabase(supabase: SupabaseClient | null): void;
362
+ /**
363
+ * Get current PowerSync instance.
364
+ *
365
+ * @returns Current PowerSync database instance or null
366
+ */
367
+ getPowerSync(): PowerSyncDatabase | null;
368
+ /**
369
+ * Get current Supabase instance.
370
+ *
371
+ * @returns Current Supabase client instance or null
372
+ */
373
+ getSupabase(): SupabaseClient | null;
374
+ /**
375
+ * Update detector options.
376
+ *
377
+ * @param options - New options to merge with existing
378
+ */
379
+ setOptions(options: Partial<AutoDetectorOptions>): void;
380
+ /**
381
+ * Get current detector options.
382
+ *
383
+ * @returns Current detector options
384
+ */
385
+ getOptions(): Required<AutoDetectorOptions>;
386
+ /**
387
+ * Add a listener for backend change events.
388
+ *
389
+ * @param listener - Callback to invoke when detection result changes
390
+ * @returns Function to remove the listener
391
+ */
392
+ addListener(listener: BackendChangeListener): () => void;
393
+ /**
394
+ * Remove a listener for backend change events.
395
+ *
396
+ * @param listener - Listener to remove
397
+ */
398
+ removeListener(listener: BackendChangeListener): void;
399
+ /**
400
+ * Get the last detection result.
401
+ *
402
+ * @returns Last detection result or null if never detected
403
+ */
404
+ getLastResult(): AutoDetectionResult | null;
405
+ /**
406
+ * Check if the detection result has changed from the last result.
407
+ */
408
+ private hasResultChanged;
409
+ /**
410
+ * Notify all listeners of a detection result change.
411
+ */
412
+ private notifyListeners;
413
+ }
414
+ /**
415
+ * Create an AdapterAutoDetector instance.
416
+ *
417
+ * @param powerSyncDb - PowerSync database instance or null
418
+ * @param supabase - Supabase client instance or null
419
+ * @param options - Detection options
420
+ * @returns New AdapterAutoDetector instance
421
+ *
422
+ * @example
423
+ * ```typescript
424
+ * const detector = createAdapterAutoDetector(powerSyncDb, supabaseClient, {
425
+ * preferPowerSync: true,
426
+ * statusCheckTimeout: 2000,
427
+ * });
428
+ *
429
+ * const { recommendedBackend, reason } = detector.detect();
430
+ * ```
431
+ */
432
+ declare function createAdapterAutoDetector(powerSyncDb: PowerSyncDatabase | null, supabase: SupabaseClient | null, options?: AutoDetectorOptions): AdapterAutoDetector;
433
+
434
+ /**
435
+ * V3 Data Layer Adapter Registry
436
+ *
437
+ * Factory that creates and manages adapter instances based on table configuration.
438
+ * Uses lazy initialization to create adapters on first access.
439
+ */
440
+
441
+ /**
442
+ * Registry that manages and provides adapters based on table configuration.
443
+ *
444
+ * The registry:
445
+ * - Stores configuration for table strategies
446
+ * - Lazily creates adapters when first accessed
447
+ * - Caches created adapters for reuse
448
+ * - Provides default fallback for unconfigured tables
449
+ *
450
+ * Usage:
451
+ * ```typescript
452
+ * const registry = createAdapterRegistry(config);
453
+ *
454
+ * // Later, when providers initialize:
455
+ * registry.setPowerSyncAdapter(powerSyncAdapter);
456
+ * registry.setSupabaseAdapter(supabaseAdapter);
457
+ *
458
+ * // Get adapter for a table:
459
+ * const adapter = registry.getAdapter("Project");
460
+ * ```
461
+ */
462
+ declare class AdapterRegistry {
463
+ private config;
464
+ /**
465
+ * Cache of created adapters by table name
466
+ */
467
+ private adapters;
468
+ /**
469
+ * PowerSync adapter instance (set during initialization)
470
+ */
471
+ private powerSyncAdapter;
472
+ /**
473
+ * Supabase adapter instance (set during initialization)
474
+ */
475
+ private supabaseAdapter;
476
+ /**
477
+ * Cached adapter instance (wraps Supabase with TanStack Query)
478
+ */
479
+ private cachedAdapter;
480
+ /**
481
+ * Dependencies for creating adapters
482
+ */
483
+ private deps;
484
+ /**
485
+ * Whether the registry has been initialized with adapters
486
+ */
487
+ private _isInitialized;
488
+ /**
489
+ * Auto-detector instance for automatic backend selection
490
+ */
491
+ private autoDetector;
492
+ /**
493
+ * Listeners for backend change events
494
+ */
495
+ private backendChangeListeners;
496
+ /**
497
+ * Last auto-detection result for debugging and status
498
+ */
499
+ private lastDetectionResult;
500
+ /**
501
+ * Create a new adapter registry
502
+ *
503
+ * @param config - Data layer configuration with table strategies
504
+ */
505
+ constructor(config: DataLayerConfig);
506
+ /**
507
+ * Check if the registry has been initialized
508
+ */
509
+ get isInitialized(): boolean;
510
+ /**
511
+ * Initialize the registry with dependencies.
512
+ * Called by DataLayerProvider when PowerSync and Supabase are ready.
513
+ *
514
+ * @param deps - Dependencies needed to create adapters
515
+ */
516
+ initialize(deps: AdapterDependencies): void;
517
+ /**
518
+ * Set the PowerSync adapter instance
519
+ *
520
+ * @param adapter - PowerSync adapter implementation
521
+ */
522
+ setPowerSyncAdapter(adapter: TableDataAdapter): void;
523
+ /**
524
+ * Set the Supabase adapter instance
525
+ *
526
+ * @param adapter - Supabase adapter implementation
527
+ */
528
+ setSupabaseAdapter(adapter: TableDataAdapter): void;
529
+ /**
530
+ * Set the Cached adapter instance
531
+ *
532
+ * @param adapter - Cached adapter implementation
533
+ */
534
+ setCachedAdapter(adapter: TableDataAdapter): void;
535
+ /**
536
+ * Initialize auto-detection with a detector instance
537
+ *
538
+ * @param detector - The auto-detector to use
539
+ */
540
+ initializeAutoDetection(detector: AdapterAutoDetector): void;
541
+ /**
542
+ * Get the appropriate adapter for a table based on configuration.
543
+ *
544
+ * The adapter is selected based on the table's strategy in config.tables:
545
+ * - "powersync": Returns PowerSyncAdapter
546
+ * - "supabase": Returns SupabaseAdapter
547
+ * - "cached": Returns CachedAdapter (wrapping Supabase)
548
+ * - "hybrid": Returns HybridAdapter (combining PowerSync + Cached)
549
+ * - "auto": Uses auto-detection to select the best backend
550
+ *
551
+ * For tables not in config, defaults to auto-detection if available,
552
+ * otherwise falls back to SupabaseAdapter.
553
+ *
554
+ * @param table - The table name
555
+ * @returns The appropriate adapter for the table
556
+ * @throws Error if adapters are not initialized
557
+ */
558
+ getAdapter(table: string): TableDataAdapter;
559
+ /**
560
+ * Get the PowerSync adapter directly
561
+ *
562
+ * @returns PowerSync adapter or null if not initialized
563
+ */
564
+ getPowerSyncAdapter(): TableDataAdapter | null;
565
+ /**
566
+ * Get the Supabase adapter directly
567
+ *
568
+ * @returns Supabase adapter or null if not initialized
569
+ */
570
+ getSupabaseAdapter(): TableDataAdapter | null;
571
+ /**
572
+ * Get the Cached adapter directly
573
+ *
574
+ * @returns Cached adapter or null if not initialized
575
+ */
576
+ getCachedAdapter(): TableDataAdapter | null;
577
+ /**
578
+ * Get all configured table names
579
+ *
580
+ * @returns Array of table names with explicit strategy configuration
581
+ */
582
+ getConfiguredTables(): string[];
583
+ /**
584
+ * Get the strategy for a specific table
585
+ *
586
+ * @param table - The table name
587
+ * @returns The table strategy or undefined if not configured
588
+ */
589
+ getTableStrategy(table: string): TableStrategy | undefined;
590
+ /**
591
+ * Check if a table uses PowerSync strategy
592
+ *
593
+ * @param table - The table name
594
+ * @returns True if table uses PowerSync or Hybrid strategy
595
+ */
596
+ usesPowerSync(table: string): boolean;
597
+ /**
598
+ * Get all tables that use PowerSync
599
+ *
600
+ * @returns Array of table names using PowerSync or Hybrid strategy
601
+ */
602
+ getPowerSyncTables(): string[];
603
+ /**
604
+ * Get adapter using auto-detection
605
+ *
606
+ * @param strategy - Optional auto strategy configuration
607
+ * @returns The automatically selected adapter
608
+ */
609
+ private getAutoAdapter;
610
+ /**
611
+ * Subscribe to backend changes
612
+ *
613
+ * @param callback - Function called when recommended backend changes
614
+ * @returns Unsubscribe function
615
+ */
616
+ onBackendChange(callback: (backend: "powersync" | "supabase") => void): () => void;
617
+ /**
618
+ * Notify listeners of backend change
619
+ *
620
+ * @param backend - The new recommended backend
621
+ */
622
+ private notifyBackendChange;
623
+ /**
624
+ * Get the last auto-detection result
625
+ *
626
+ * @returns Last detection result or null if never detected
627
+ */
628
+ getLastDetectionResult(): AutoDetectionResult | null;
629
+ /**
630
+ * Get the auto-detector instance
631
+ *
632
+ * @returns Auto-detector instance or null if not initialized
633
+ */
634
+ getAutoDetector(): AdapterAutoDetector | null;
635
+ /**
636
+ * Create an adapter based on the strategy type
637
+ *
638
+ * @param strategy - The table strategy configuration
639
+ * @returns The created adapter
640
+ * @throws Error if the required base adapter is not initialized
641
+ */
642
+ private createAdapter;
643
+ /**
644
+ * Clear all cached adapters.
645
+ * Useful when configuration changes and adapters need to be recreated.
646
+ */
647
+ clearCache(): void;
648
+ /**
649
+ * Reset the registry to uninitialized state.
650
+ * Used during cleanup or testing.
651
+ */
652
+ reset(): void;
653
+ /**
654
+ * Dispose all adapters and clean up resources.
655
+ * Called when the DataLayerProvider unmounts.
656
+ */
657
+ dispose(): void;
658
+ /**
659
+ * Get debug information about the registry state
660
+ */
661
+ getDebugInfo(): {
662
+ isInitialized: boolean;
663
+ hasPowerSync: boolean;
664
+ hasSupabase: boolean;
665
+ hasCached: boolean;
666
+ cachedAdapterCount: number;
667
+ configuredTableCount: number;
668
+ powerSyncTables: string[];
669
+ hasAutoDetector: boolean;
670
+ lastDetectionResult: AutoDetectionResult | null;
671
+ };
672
+ }
673
+ /**
674
+ * Create a new adapter registry
675
+ *
676
+ * @param config - Data layer configuration
677
+ * @returns A new AdapterRegistry instance
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * const config: DataLayerConfig = {
682
+ * schema: databaseSchema,
683
+ * connections: { ... },
684
+ * tables: {
685
+ * Project: { strategy: "powersync", syncScope: "activeProject" },
686
+ * AuditLog: { strategy: "supabase" },
687
+ * Report: { strategy: "cached", cacheTime: 60000 },
688
+ * },
689
+ * scopes: { ... },
690
+ * defaults: { syncMode: "live" },
691
+ * };
692
+ *
693
+ * const registry = createAdapterRegistry(config);
694
+ *
695
+ * // In provider:
696
+ * registry.setPowerSyncAdapter(new PowerSyncAdapter(db, schema));
697
+ * registry.setSupabaseAdapter(new SupabaseAdapter(supabase));
698
+ *
699
+ * // In hooks:
700
+ * const adapter = registry.getAdapter("Project"); // Returns PowerSyncAdapter
701
+ * ```
702
+ */
703
+ declare function createAdapterRegistry(config: DataLayerConfig): AdapterRegistry;
704
+
705
+ /**
706
+ * Status of the data layer initialization
707
+ */
708
+ interface DataLayerStatus {
709
+ /** Whether the data layer is fully initialized */
710
+ isInitialized: boolean;
711
+ /** Current active backend */
712
+ currentBackend: "powersync" | "supabase" | null;
713
+ /** PowerSync connection status */
714
+ powerSyncStatus: BackendStatus;
715
+ /** Whether device is online */
716
+ isOnline: boolean;
717
+ /** Last auto-detection result */
718
+ lastDetection: AutoDetectionResult | null;
719
+ /** Initialization error if any */
720
+ error: Error | null;
721
+ /** Whether initial sync has completed (from PowerSync) */
722
+ hasSynced: boolean;
723
+ }
724
+ /**
725
+ * Context value for the data layer
726
+ */
727
+ interface DataLayerContextValue {
728
+ /** Adapter registry for getting table adapters */
729
+ registry: AdapterRegistry;
730
+ /** Get adapter for a specific table */
731
+ getAdapter: (table: string) => TableDataAdapter;
732
+ /** PowerSync database instance (null when not available) */
733
+ powerSync: PowerSyncDatabase | null;
734
+ /** Supabase client (always available) */
735
+ supabase: SupabaseClient;
736
+ /** React Query client */
737
+ queryClient: QueryClient;
738
+ /** Database schema */
739
+ schema: DatabaseSchema;
740
+ /** Current status */
741
+ status: DataLayerStatus;
742
+ /** Sync status (for PowerSync, no-op for Supabase-only) */
743
+ syncStatus: SyncStatus;
744
+ /** Sync controls (for PowerSync, no-op for Supabase-only) */
745
+ syncControl: SyncControl;
746
+ }
747
+ /**
748
+ * Data layer context
749
+ *
750
+ * Provides access to the V3 data layer throughout the React component tree.
751
+ * Must be accessed via the useDataLayer hook or similar consumer.
752
+ */
753
+ declare const DataLayerContext: react.Context<DataLayerContextValue>;
754
+
755
+ export { type AdapterQueryResult as A, BackendStatus as B, type CapableDataAdapter as C, DataLayerContext as D, type SyncStatusInfo as S, type TableDataAdapter as T, type AdapterConfig as a, type AdapterFactory as b, type AdapterCapabilities as c, type AdapterDependencies as d, type AdapterStrategyType as e, ADAPTER_STRATEGIES as f, AdapterRegistry as g, createAdapterRegistry as h, AdapterAutoDetector as i, createAdapterAutoDetector as j, type AutoDetectionResult as k, type AutoDetectorOptions as l, type BackendChangeListener as m, type DataLayerContextValue as n, type DataLayerStatus as o };