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