@pol-studios/db 1.0.57 → 1.0.59
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/DataLayerContext-V5FotiSk.d.ts +563 -0
- package/dist/auth/context.js +2 -2
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-YRIPM2AN.js → chunk-4PZ744G2.js} +207 -6
- package/dist/chunk-4PZ744G2.js.map +1 -0
- package/dist/{chunk-6SDH7M7J.js → chunk-ARALLEDJ.js} +2 -2
- package/dist/{chunk-Z456IHCB.js → chunk-F4HW4NT5.js} +1 -1
- package/dist/chunk-F4HW4NT5.js.map +1 -0
- package/dist/{chunk-VSJKGPRI.js → chunk-K46TGKB2.js} +323 -379
- package/dist/chunk-K46TGKB2.js.map +1 -0
- package/dist/{chunk-GWYTROSD.js → chunk-L4DFVMTS.js} +335 -4
- package/dist/chunk-L4DFVMTS.js.map +1 -0
- package/dist/{chunk-MEBT5YHA.js → chunk-SNPZMRBC.js} +2 -2
- package/dist/{chunk-DDL63KLQ.js → chunk-VADZSRHY.js} +16 -337
- package/dist/chunk-VADZSRHY.js.map +1 -0
- package/dist/{chunk-4EO55YV2.js → chunk-VSY6766U.js} +4 -4
- package/dist/{chunk-VYFAMTHI.js → chunk-WY6MNB6K.js} +2 -2
- package/dist/core/index.d.ts +1 -1
- package/dist/{executor-D15yjeMo.d.ts → executor-Bu1OlqCl.d.ts} +43 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +2 -2
- package/dist/{index-CFUuTzXO.d.ts → index-vwVJ0BWj.d.ts} +1 -9
- package/dist/index.d.ts +5 -5
- package/dist/index.js +20 -12
- package/dist/index.native.d.ts +77 -76
- package/dist/index.native.js +20 -12
- package/dist/index.web.d.ts +21 -44
- package/dist/index.web.js +215 -149
- package/dist/index.web.js.map +1 -1
- package/dist/powersync-bridge/index.d.ts +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +1 -1
- package/dist/{useDbCount-Ckb-FhZk.d.ts → useDbCount-dCkdaBpP.d.ts} +41 -83
- package/dist/{useResolveFeedback-CuUkdHoR.d.ts → useResolveFeedback-thFi-4h8.d.ts} +429 -5
- package/dist/with-auth/index.js +5 -5
- package/package.json +1 -1
- package/dist/DataLayerContext-BYZtDD0g.d.ts +0 -946
- package/dist/chunk-DDL63KLQ.js.map +0 -1
- package/dist/chunk-GWYTROSD.js.map +0 -1
- package/dist/chunk-VSJKGPRI.js.map +0 -1
- package/dist/chunk-YRIPM2AN.js.map +0 -1
- package/dist/chunk-Z456IHCB.js.map +0 -1
- /package/dist/{chunk-6SDH7M7J.js.map → chunk-ARALLEDJ.js.map} +0 -0
- /package/dist/{chunk-MEBT5YHA.js.map → chunk-SNPZMRBC.js.map} +0 -0
- /package/dist/{chunk-4EO55YV2.js.map → chunk-VSY6766U.js.map} +0 -0
- /package/dist/{chunk-VYFAMTHI.js.map → chunk-WY6MNB6K.js.map} +0 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { P as PowerSyncDatabase } from './executor-Bu1OlqCl.js';
|
|
5
|
+
import { QueryOptions, DatabaseSchema, TableStrategy, DataLayerConfig, SyncControl, SyncStatus } from './core/index.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 PowerSync database reference.
|
|
297
|
+
* Called when PowerSync becomes available after initial construction.
|
|
298
|
+
*
|
|
299
|
+
* @param db - PowerSync database instance or null
|
|
300
|
+
*/
|
|
301
|
+
setPowerSyncDb(db: PowerSyncDatabase | null): void;
|
|
302
|
+
/**
|
|
303
|
+
* Update the sync status from PowerSync.
|
|
304
|
+
* Called when sync status changes to re-evaluate backend recommendation.
|
|
305
|
+
*
|
|
306
|
+
* @param status - Current sync status or null if not available
|
|
307
|
+
*/
|
|
308
|
+
updateSyncStatus(status: SyncStatusInfo | null): void;
|
|
309
|
+
/**
|
|
310
|
+
* Get current sync status.
|
|
311
|
+
* @returns Current sync status or null
|
|
312
|
+
*/
|
|
313
|
+
getSyncStatus(): SyncStatusInfo | null;
|
|
314
|
+
/**
|
|
315
|
+
* Detect backend availability and recommend best option.
|
|
316
|
+
*
|
|
317
|
+
* The detection logic follows this priority:
|
|
318
|
+
* 1. If preferPowerSync is true and PowerSync is available, use PowerSync
|
|
319
|
+
* 2. If PowerSync is initializing and online with Supabase available, use Supabase temporarily
|
|
320
|
+
* 3. If online with Supabase available, use Supabase
|
|
321
|
+
* 4. If offline but PowerSync available, use PowerSync (offline mode)
|
|
322
|
+
* 5. If offline and PowerSync exists (even if initializing), use PowerSync local data
|
|
323
|
+
* 6. Default to Supabase as fallback
|
|
324
|
+
*
|
|
325
|
+
* @returns Detection result with recommendation and reasoning
|
|
326
|
+
*/
|
|
327
|
+
detect(): AutoDetectionResult;
|
|
328
|
+
/**
|
|
329
|
+
* Detect backend availability WITHOUT notifying listeners.
|
|
330
|
+
*
|
|
331
|
+
* This method is safe to call during React's render phase because it does not
|
|
332
|
+
* trigger state updates in other components. Use this method when you need to
|
|
333
|
+
* check backend status synchronously during render (e.g., in getAdapter()).
|
|
334
|
+
*
|
|
335
|
+
* The regular detect() method with listener notifications should only be called
|
|
336
|
+
* from useEffect or event handlers to avoid the React warning:
|
|
337
|
+
* "Cannot update a component while rendering a different component"
|
|
338
|
+
*
|
|
339
|
+
* @returns Detection result with recommendation and reasoning
|
|
340
|
+
*/
|
|
341
|
+
detectSilent(): AutoDetectionResult;
|
|
342
|
+
/**
|
|
343
|
+
* Internal detection logic shared by detect() and detectSilent().
|
|
344
|
+
* @private
|
|
345
|
+
*/
|
|
346
|
+
private performDetection;
|
|
347
|
+
/**
|
|
348
|
+
* Check if PowerSync is available.
|
|
349
|
+
*
|
|
350
|
+
* PowerSync status depends on:
|
|
351
|
+
* 1. Database instance exists
|
|
352
|
+
* 2. If useOnlineUntilSynced is true, also checks if initial sync completed
|
|
353
|
+
*
|
|
354
|
+
* @returns PowerSync backend status
|
|
355
|
+
*/
|
|
356
|
+
detectPowerSyncStatus(): BackendStatus;
|
|
357
|
+
/**
|
|
358
|
+
* Check if Supabase is available.
|
|
359
|
+
*
|
|
360
|
+
* Supabase is considered available if we have a client instance.
|
|
361
|
+
* The actual network connectivity is checked separately via checkOnlineStatus().
|
|
362
|
+
*
|
|
363
|
+
* @returns Supabase backend status
|
|
364
|
+
*/
|
|
365
|
+
detectSupabaseStatus(): BackendStatus;
|
|
366
|
+
/**
|
|
367
|
+
* Check if device is online.
|
|
368
|
+
*
|
|
369
|
+
* Prefers the sync status's isOnline property if available (from React Native NetInfo).
|
|
370
|
+
* Falls back to navigator.onLine in browser environments.
|
|
371
|
+
* Returns false by default for non-browser environments (React Native, Node.js, etc.)
|
|
372
|
+
* to ensure offline-first behavior works correctly.
|
|
373
|
+
*
|
|
374
|
+
* @returns Whether the device has network connectivity
|
|
375
|
+
*/
|
|
376
|
+
checkOnlineStatus(): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Update PowerSync instance (e.g., when it becomes available).
|
|
379
|
+
*
|
|
380
|
+
* @param db - New PowerSync database instance or null
|
|
381
|
+
*/
|
|
382
|
+
setPowerSync(db: PowerSyncDatabase | null): void;
|
|
383
|
+
/**
|
|
384
|
+
* Update Supabase instance.
|
|
385
|
+
*
|
|
386
|
+
* @param supabase - New Supabase client instance or null
|
|
387
|
+
*/
|
|
388
|
+
setSupabase(supabase: SupabaseClient | null): void;
|
|
389
|
+
/**
|
|
390
|
+
* Get current PowerSync instance.
|
|
391
|
+
*
|
|
392
|
+
* @returns Current PowerSync database instance or null
|
|
393
|
+
*/
|
|
394
|
+
getPowerSync(): PowerSyncDatabase | null;
|
|
395
|
+
/**
|
|
396
|
+
* Get current Supabase instance.
|
|
397
|
+
*
|
|
398
|
+
* @returns Current Supabase client instance or null
|
|
399
|
+
*/
|
|
400
|
+
getSupabase(): SupabaseClient | null;
|
|
401
|
+
/**
|
|
402
|
+
* Update detector options.
|
|
403
|
+
*
|
|
404
|
+
* @param options - New options to merge with existing
|
|
405
|
+
*/
|
|
406
|
+
setOptions(options: Partial<AutoDetectorOptions>): void;
|
|
407
|
+
/**
|
|
408
|
+
* Get current detector options.
|
|
409
|
+
*
|
|
410
|
+
* @returns Current detector options
|
|
411
|
+
*/
|
|
412
|
+
getOptions(): Required<AutoDetectorOptions>;
|
|
413
|
+
/**
|
|
414
|
+
* Add a listener for backend change events.
|
|
415
|
+
*
|
|
416
|
+
* @param listener - Callback to invoke when detection result changes
|
|
417
|
+
* @returns Function to remove the listener
|
|
418
|
+
*/
|
|
419
|
+
addListener(listener: BackendChangeListener): () => void;
|
|
420
|
+
/**
|
|
421
|
+
* Remove a listener for backend change events.
|
|
422
|
+
*
|
|
423
|
+
* @param listener - Listener to remove
|
|
424
|
+
*/
|
|
425
|
+
removeListener(listener: BackendChangeListener): void;
|
|
426
|
+
/**
|
|
427
|
+
* Get the last detection result.
|
|
428
|
+
*
|
|
429
|
+
* @returns Last detection result or null if never detected
|
|
430
|
+
*/
|
|
431
|
+
getLastResult(): AutoDetectionResult | null;
|
|
432
|
+
/**
|
|
433
|
+
* Check if the detection result has changed from the last result.
|
|
434
|
+
*/
|
|
435
|
+
private hasResultChanged;
|
|
436
|
+
/**
|
|
437
|
+
* Notify all listeners of a detection result change.
|
|
438
|
+
*/
|
|
439
|
+
private notifyListeners;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create an AdapterAutoDetector instance.
|
|
443
|
+
*
|
|
444
|
+
* @param powerSyncDb - PowerSync database instance or null
|
|
445
|
+
* @param supabase - Supabase client instance or null
|
|
446
|
+
* @param options - Detection options
|
|
447
|
+
* @returns New AdapterAutoDetector instance
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* const detector = createAdapterAutoDetector(powerSyncDb, supabaseClient, {
|
|
452
|
+
* preferPowerSync: true,
|
|
453
|
+
* statusCheckTimeout: 2000,
|
|
454
|
+
* });
|
|
455
|
+
*
|
|
456
|
+
* const { recommendedBackend, reason } = detector.detect();
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
declare function createAdapterAutoDetector(powerSyncDb: PowerSyncDatabase | null, supabase: SupabaseClient | null, options?: AutoDetectorOptions): AdapterAutoDetector;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Status type for the data layer
|
|
463
|
+
*/
|
|
464
|
+
interface DataLayerStatus {
|
|
465
|
+
isInitialized: boolean;
|
|
466
|
+
currentBackend: "powersync" | "supabase" | null;
|
|
467
|
+
powerSyncStatus: BackendStatus;
|
|
468
|
+
isOnline: boolean;
|
|
469
|
+
lastDetection: AutoDetectionResult | null;
|
|
470
|
+
error: Error | null;
|
|
471
|
+
hasSynced: boolean;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Simplified adapter registry interface.
|
|
475
|
+
*
|
|
476
|
+
* This provides the same interface as the old AdapterRegistry class
|
|
477
|
+
* but is implemented inline in the provider.
|
|
478
|
+
*/
|
|
479
|
+
interface SimpleAdapterRegistry {
|
|
480
|
+
/** Get adapter for a specific table */
|
|
481
|
+
getAdapter: (table: string, operation?: 'read' | 'write') => TableDataAdapter;
|
|
482
|
+
/** Get strategy for a table */
|
|
483
|
+
getTableStrategy: (table: string) => TableStrategy | undefined;
|
|
484
|
+
/** Check if table uses PowerSync */
|
|
485
|
+
usesPowerSync: (table: string) => boolean;
|
|
486
|
+
/** Get all PowerSync table names */
|
|
487
|
+
getPowerSyncTables: () => string[];
|
|
488
|
+
/** Get PowerSync alias for a table */
|
|
489
|
+
getTableAlias: (table: string) => string;
|
|
490
|
+
/** Get debug info */
|
|
491
|
+
getDebugInfo: () => {
|
|
492
|
+
isInitialized: boolean;
|
|
493
|
+
hasPowerSync: boolean;
|
|
494
|
+
hasSupabase: boolean;
|
|
495
|
+
configuredTableCount: number;
|
|
496
|
+
powerSyncTables: string[];
|
|
497
|
+
};
|
|
498
|
+
/** Config reference */
|
|
499
|
+
config: DataLayerConfig;
|
|
500
|
+
/** Whether registry is initialized */
|
|
501
|
+
isInitialized: boolean;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Core context value - stable values that don't change after initialization.
|
|
505
|
+
*
|
|
506
|
+
* Supports lazy init: start with Supabase, automatically switch to PowerSync when available.
|
|
507
|
+
*/
|
|
508
|
+
interface DataLayerCoreContextValue {
|
|
509
|
+
/** Simplified registry for adapter access */
|
|
510
|
+
registry: SimpleAdapterRegistry;
|
|
511
|
+
/** Get adapter for a table - simple: PowerSync if offline table, else Supabase */
|
|
512
|
+
getAdapter: (table: string, operation?: 'read' | 'write') => TableDataAdapter;
|
|
513
|
+
/** PowerSync database instance (null if not using offline-first) */
|
|
514
|
+
powerSync: PowerSyncDatabase | null;
|
|
515
|
+
/** Supabase client (always available) */
|
|
516
|
+
supabase: SupabaseClient;
|
|
517
|
+
/** React Query client */
|
|
518
|
+
queryClient: QueryClient;
|
|
519
|
+
/** Database schema */
|
|
520
|
+
schema: DatabaseSchema;
|
|
521
|
+
/** Sync controls (no-op functions when PowerSync not available) */
|
|
522
|
+
syncControl: SyncControl;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Status context value - dynamic values that change during runtime.
|
|
526
|
+
*/
|
|
527
|
+
interface DataLayerStatusContextValue {
|
|
528
|
+
/** Current status */
|
|
529
|
+
status: DataLayerStatus;
|
|
530
|
+
/** Sync status (for PowerSync, default values for Supabase-only) */
|
|
531
|
+
syncStatus: SyncStatus;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Combined context value for backward compatibility.
|
|
535
|
+
* Combines core and status values.
|
|
536
|
+
*
|
|
537
|
+
* @deprecated Prefer using useDataLayerCore() for queries/mutations
|
|
538
|
+
* and useDataLayerStatus() for status display components.
|
|
539
|
+
*/
|
|
540
|
+
interface DataLayerContextValue extends DataLayerCoreContextValue, DataLayerStatusContextValue {
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Main data layer context (combined).
|
|
544
|
+
* For backward compatibility - use DataLayerCoreContext for better performance.
|
|
545
|
+
*/
|
|
546
|
+
declare const DataLayerContext: react.Context<DataLayerContextValue>;
|
|
547
|
+
/**
|
|
548
|
+
* Core context - stable values that don't change after initialization.
|
|
549
|
+
* Components using useDataLayerCore() will NOT re-render on status changes.
|
|
550
|
+
*/
|
|
551
|
+
declare const DataLayerCoreContext: react.Context<DataLayerCoreContextValue>;
|
|
552
|
+
/**
|
|
553
|
+
* Status context - dynamic values that change during runtime.
|
|
554
|
+
* Components using useDataLayerStatus() WILL re-render on status changes.
|
|
555
|
+
*/
|
|
556
|
+
declare const DataLayerStatusContext: react.Context<DataLayerStatusContextValue>;
|
|
557
|
+
/**
|
|
558
|
+
* Nesting detection context.
|
|
559
|
+
* Warns if DataLayerProvider is accidentally nested.
|
|
560
|
+
*/
|
|
561
|
+
declare const DataLayerNestingContext: react.Context<boolean>;
|
|
562
|
+
|
|
563
|
+
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, AdapterAutoDetector as g, createAdapterAutoDetector as h, type AutoDetectionResult as i, type AutoDetectorOptions as j, type BackendChangeListener as k, DataLayerCoreContext as l, DataLayerStatusContext as m, DataLayerNestingContext as n, type DataLayerContextValue as o, type DataLayerCoreContextValue as p, type DataLayerStatusContextValue as q, type DataLayerStatus as r, type SimpleAdapterRegistry as s };
|
package/dist/auth/context.js
CHANGED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
useUserMetadataState,
|
|
12
12
|
useUserMetadataValue,
|
|
13
13
|
userMetadataContext
|
|
14
|
-
} from "../chunk-
|
|
15
|
-
import "../chunk-
|
|
14
|
+
} from "../chunk-ARALLEDJ.js";
|
|
15
|
+
import "../chunk-L4DFVMTS.js";
|
|
16
16
|
import "../chunk-W7PERM66.js";
|
|
17
17
|
import "../chunk-QYAFI34Q.js";
|
|
18
18
|
import "../chunk-J4ZVCXZ4.js";
|
package/dist/auth/hooks.js
CHANGED
|
@@ -11,14 +11,14 @@ import {
|
|
|
11
11
|
usePermissionLoading,
|
|
12
12
|
usePermissionsBatch,
|
|
13
13
|
useSetupAuth
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-SNPZMRBC.js";
|
|
15
15
|
import {
|
|
16
16
|
useSetUserMetadata,
|
|
17
17
|
useUserMetadata,
|
|
18
18
|
useUserMetadataState,
|
|
19
19
|
useUserMetadataValue
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import "../chunk-
|
|
20
|
+
} from "../chunk-ARALLEDJ.js";
|
|
21
|
+
import "../chunk-L4DFVMTS.js";
|
|
22
22
|
import "../chunk-W7PERM66.js";
|
|
23
23
|
import "../chunk-QYAFI34Q.js";
|
|
24
24
|
import "../chunk-J4ZVCXZ4.js";
|
package/dist/auth/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
usePermissionLoading,
|
|
13
13
|
usePermissionsBatch,
|
|
14
14
|
useSetupAuth
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-SNPZMRBC.js";
|
|
16
16
|
import {
|
|
17
17
|
AuthProvider,
|
|
18
18
|
PermissionProvider,
|
|
@@ -26,8 +26,8 @@ import {
|
|
|
26
26
|
useUserMetadataState,
|
|
27
27
|
useUserMetadataValue,
|
|
28
28
|
userMetadataContext
|
|
29
|
-
} from "../chunk-
|
|
30
|
-
import "../chunk-
|
|
29
|
+
} from "../chunk-ARALLEDJ.js";
|
|
30
|
+
import "../chunk-L4DFVMTS.js";
|
|
31
31
|
import {
|
|
32
32
|
hasAccess,
|
|
33
33
|
hasAllAccess,
|