@pol-studios/db 1.0.33 → 1.0.35
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/UserMetadataContext-QLIv-mfF.d.ts +171 -0
- package/dist/auth/context.d.ts +52 -4
- package/dist/auth/context.js +26 -1
- package/dist/auth/hooks.d.ts +107 -3
- package/dist/auth/hooks.js +9 -2
- package/dist/auth/index.d.ts +5 -5
- package/dist/auth/index.js +40 -9
- package/dist/chunk-5HJLTYRA.js +355 -0
- package/dist/chunk-5HJLTYRA.js.map +1 -0
- package/dist/chunk-6KN7KLEG.js +1 -0
- package/dist/{chunk-PNC6CG5U.js → chunk-7NFMEDJW.js} +42 -9
- package/dist/chunk-7NFMEDJW.js.map +1 -0
- package/dist/{chunk-4EJ6LUH7.js → chunk-HFIGNQ7T.js} +6 -4
- package/dist/{chunk-4EJ6LUH7.js.map → chunk-HFIGNQ7T.js.map} +1 -1
- package/dist/{chunk-3XCW225W.js → chunk-NP34C3O3.js} +53 -256
- package/dist/chunk-NP34C3O3.js.map +1 -0
- package/dist/{chunk-E64B4PJZ.js → chunk-QHXN6BNL.js} +3 -3
- package/dist/{chunk-OUCPYEKC.js → chunk-U4BZKCBH.js} +4 -4
- package/dist/chunk-UBHORKBS.js +215 -0
- package/dist/chunk-UBHORKBS.js.map +1 -0
- package/dist/{chunk-E6JL3RUF.js → chunk-YQUNORJD.js} +176 -85
- package/dist/chunk-YQUNORJD.js.map +1 -0
- package/dist/hooks/index.js +9 -7
- package/dist/index.js +18 -15
- package/dist/index.native.js +18 -15
- package/dist/index.web.js +13 -10
- package/dist/index.web.js.map +1 -1
- package/dist/with-auth/index.js +7 -5
- package/dist/with-auth/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/UserMetadataContext-yLZQu24J.d.ts +0 -33
- package/dist/chunk-3XCW225W.js.map +0 -1
- package/dist/chunk-E6JL3RUF.js.map +0 -1
- package/dist/chunk-NSIAAYW3.js +0 -1
- package/dist/chunk-PNC6CG5U.js.map +0 -1
- /package/dist/{chunk-NSIAAYW3.js.map → chunk-6KN7KLEG.js.map} +0 -0
- /package/dist/{chunk-E64B4PJZ.js.map → chunk-QHXN6BNL.js.map} +0 -0
- /package/dist/{chunk-OUCPYEKC.js.map → chunk-U4BZKCBH.js.map} +0 -0
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataLayerCoreContext,
|
|
3
|
+
DataLayerStatusContext,
|
|
4
|
+
devLog,
|
|
5
|
+
devWarn,
|
|
6
|
+
useDataLayerCore,
|
|
7
|
+
useDataLayerStatus,
|
|
8
|
+
useDbQuery
|
|
9
|
+
} from "./chunk-UBHORKBS.js";
|
|
1
10
|
import {
|
|
2
11
|
getSupabaseUrl
|
|
3
12
|
} from "./chunk-GC3TBUWE.js";
|
|
@@ -5,213 +14,10 @@ import {
|
|
|
5
14
|
useSupabase
|
|
6
15
|
} from "./chunk-DMVUEJG2.js";
|
|
7
16
|
|
|
8
|
-
// src/hooks/useDataLayer.ts
|
|
9
|
-
import { useContext } from "react";
|
|
10
|
-
|
|
11
|
-
// src/providers/DataLayerContext.ts
|
|
12
|
-
import { createContext } from "react";
|
|
13
|
-
var DataLayerCoreContext = createContext(null);
|
|
14
|
-
DataLayerCoreContext.displayName = "DataLayerCoreContext";
|
|
15
|
-
var DataLayerStatusContext = createContext(null);
|
|
16
|
-
DataLayerStatusContext.displayName = "DataLayerStatusContext";
|
|
17
|
-
var DataLayerContext = createContext(null);
|
|
18
|
-
DataLayerContext.displayName = "DataLayerContext";
|
|
19
|
-
|
|
20
|
-
// src/hooks/useDataLayer.ts
|
|
21
|
-
function useDataLayerCore() {
|
|
22
|
-
const context = useContext(DataLayerCoreContext);
|
|
23
|
-
if (!context) {
|
|
24
|
-
throw new Error("useDataLayerCore must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.");
|
|
25
|
-
}
|
|
26
|
-
return context;
|
|
27
|
-
}
|
|
28
|
-
function useDataLayerCoreOptional() {
|
|
29
|
-
return useContext(DataLayerCoreContext);
|
|
30
|
-
}
|
|
31
|
-
function useDataLayerStatus() {
|
|
32
|
-
const context = useContext(DataLayerStatusContext);
|
|
33
|
-
if (!context) {
|
|
34
|
-
throw new Error("useDataLayerStatus must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.");
|
|
35
|
-
}
|
|
36
|
-
return context;
|
|
37
|
-
}
|
|
38
|
-
function useDataLayer() {
|
|
39
|
-
const context = useContext(DataLayerContext);
|
|
40
|
-
if (!context) {
|
|
41
|
-
throw new Error("useDataLayer must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.");
|
|
42
|
-
}
|
|
43
|
-
return context;
|
|
44
|
-
}
|
|
45
|
-
function useDataLayerOptional() {
|
|
46
|
-
return useContext(DataLayerContext);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/hooks/useDbQuery.ts
|
|
50
|
-
import { useMemo, useEffect, useCallback, useRef } from "react";
|
|
51
|
-
import { useQuery } from "@tanstack/react-query";
|
|
52
|
-
|
|
53
|
-
// src/utils/dev-log.ts
|
|
54
|
-
function devLog(prefix, message) {
|
|
55
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
56
|
-
console.log(`[${prefix}] ${message}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function devWarn(prefix, message) {
|
|
60
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
61
|
-
console.warn(`[${prefix}] ${message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/hooks/useDbQuery.ts
|
|
66
|
-
function buildQueryKey(table, options) {
|
|
67
|
-
return ["v3", "query", table, options.select ?? "*", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.limit, options.offset];
|
|
68
|
-
}
|
|
69
|
-
function serializeQueryOptions(options) {
|
|
70
|
-
return JSON.stringify({
|
|
71
|
-
select: options.select,
|
|
72
|
-
where: options.where,
|
|
73
|
-
orderBy: options.orderBy,
|
|
74
|
-
limit: options.limit,
|
|
75
|
-
offset: options.offset
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function resolveTableName(table) {
|
|
79
|
-
if (typeof table === "string") {
|
|
80
|
-
return table;
|
|
81
|
-
}
|
|
82
|
-
return `${table.schema}.${table.table}`;
|
|
83
|
-
}
|
|
84
|
-
function useDbQuery(table, options = {}) {
|
|
85
|
-
const tableName = typeof table === "string" ? table : resolveTableName(table);
|
|
86
|
-
const {
|
|
87
|
-
registry,
|
|
88
|
-
queryClient,
|
|
89
|
-
powerSync
|
|
90
|
-
} = useDataLayerCore();
|
|
91
|
-
const isPowerSync = powerSync !== null;
|
|
92
|
-
const {
|
|
93
|
-
enabled = true,
|
|
94
|
-
staleTime = isPowerSync ? 0 : 3e4,
|
|
95
|
-
gcTime = 3e5,
|
|
96
|
-
// 5 minutes - keep in memory for instant display while refetching
|
|
97
|
-
refetchOnWindowFocus = true,
|
|
98
|
-
refetchOnMount = isPowerSync ? "always" : true,
|
|
99
|
-
realtime = isPowerSync,
|
|
100
|
-
// Enable real-time subscriptions by default for PowerSync
|
|
101
|
-
...queryOptions
|
|
102
|
-
} = options;
|
|
103
|
-
const adapter = useMemo(() => {
|
|
104
|
-
try {
|
|
105
|
-
return registry.getAdapter(tableName);
|
|
106
|
-
} catch {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
}, [registry, tableName]);
|
|
110
|
-
const serializedOptions = useMemo(() => serializeQueryOptions(options), [options.select, options.where, options.orderBy, options.limit, options.offset]);
|
|
111
|
-
const queryKey = useMemo(() => buildQueryKey(tableName, options), [tableName, serializedOptions]);
|
|
112
|
-
const memoizedQueryOptions = useMemo(() => ({
|
|
113
|
-
select: queryOptions.select,
|
|
114
|
-
where: queryOptions.where,
|
|
115
|
-
orderBy: queryOptions.orderBy,
|
|
116
|
-
limit: queryOptions.limit,
|
|
117
|
-
offset: queryOptions.offset
|
|
118
|
-
}), [serializedOptions]);
|
|
119
|
-
const queryFn = useCallback(async () => {
|
|
120
|
-
const currentAdapter = registry.getAdapter(tableName);
|
|
121
|
-
const result = await currentAdapter.query(tableName, memoizedQueryOptions);
|
|
122
|
-
return result;
|
|
123
|
-
}, [registry, tableName, memoizedQueryOptions]);
|
|
124
|
-
const query = useQuery({
|
|
125
|
-
queryKey,
|
|
126
|
-
queryFn,
|
|
127
|
-
enabled: enabled && adapter !== null,
|
|
128
|
-
staleTime,
|
|
129
|
-
gcTime,
|
|
130
|
-
refetchOnWindowFocus,
|
|
131
|
-
refetchOnMount
|
|
132
|
-
});
|
|
133
|
-
const invalidateTimeoutRef = useRef(null);
|
|
134
|
-
const debouncedInvalidate = useCallback(() => {
|
|
135
|
-
if (invalidateTimeoutRef.current) {
|
|
136
|
-
clearTimeout(invalidateTimeoutRef.current);
|
|
137
|
-
}
|
|
138
|
-
invalidateTimeoutRef.current = setTimeout(() => {
|
|
139
|
-
queryClient.invalidateQueries({
|
|
140
|
-
queryKey
|
|
141
|
-
});
|
|
142
|
-
}, 100);
|
|
143
|
-
}, [queryClient, queryKey]);
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
return () => {
|
|
146
|
-
if (invalidateTimeoutRef.current) {
|
|
147
|
-
clearTimeout(invalidateTimeoutRef.current);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}, []);
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
let currentAdapter_0;
|
|
153
|
-
try {
|
|
154
|
-
currentAdapter_0 = registry.getAdapter(tableName);
|
|
155
|
-
} catch {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (!realtime || !currentAdapter_0?.subscribe) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const isPowerSyncAdapter = currentAdapter_0.name === "powersync";
|
|
162
|
-
let isFirstCallback = isPowerSyncAdapter;
|
|
163
|
-
const unsubscribe = currentAdapter_0.subscribe(tableName, memoizedQueryOptions, (data) => {
|
|
164
|
-
if (isFirstCallback) {
|
|
165
|
-
isFirstCallback = false;
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const hasRelations = memoizedQueryOptions.select?.includes("(");
|
|
169
|
-
if (hasRelations) {
|
|
170
|
-
debouncedInvalidate();
|
|
171
|
-
} else {
|
|
172
|
-
queryClient.setQueryData(queryKey, {
|
|
173
|
-
data,
|
|
174
|
-
count: data.length
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return () => {
|
|
179
|
-
unsubscribe?.();
|
|
180
|
-
};
|
|
181
|
-
}, [realtime, registry, tableName, memoizedQueryOptions, queryClient, queryKey, debouncedInvalidate]);
|
|
182
|
-
useEffect(() => {
|
|
183
|
-
const adapterName = adapter?.name ?? "unknown";
|
|
184
|
-
if (query.isError && query.error) {
|
|
185
|
-
devWarn("useDbQuery", `${tableName} via ${adapterName}: Error - ${query.error.message}`);
|
|
186
|
-
}
|
|
187
|
-
if (query.isSuccess && query.data?.data?.length === 0) {
|
|
188
|
-
devLog("useDbQuery", `${tableName} via ${adapterName}: 0 results`);
|
|
189
|
-
}
|
|
190
|
-
}, [query.isError, query.error, query.isSuccess, query.data, tableName, adapter]);
|
|
191
|
-
const refetch = useCallback(async () => {
|
|
192
|
-
await query.refetch();
|
|
193
|
-
}, [query]);
|
|
194
|
-
return {
|
|
195
|
-
data: query.data?.data,
|
|
196
|
-
isLoading: query.isLoading,
|
|
197
|
-
isPending: query.isPending,
|
|
198
|
-
isFetching: query.isFetching,
|
|
199
|
-
isRefetching: query.isFetching,
|
|
200
|
-
// Alias for V2 compatibility
|
|
201
|
-
isSuccess: query.isSuccess,
|
|
202
|
-
isError: query.isError,
|
|
203
|
-
error: query.error,
|
|
204
|
-
refetch,
|
|
205
|
-
count: query.data?.count,
|
|
206
|
-
isStale: query.isStale,
|
|
207
|
-
dataUpdatedAt: query.dataUpdatedAt ?? null
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
17
|
// src/hooks/useDbQueryById.ts
|
|
212
|
-
import { useCallback
|
|
213
|
-
import { useQuery
|
|
214
|
-
function
|
|
18
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
19
|
+
import { useQuery } from "@tanstack/react-query";
|
|
20
|
+
function buildQueryKey(table, id, select) {
|
|
215
21
|
return ["v3", "queryById", table, id, select ?? "*"];
|
|
216
22
|
}
|
|
217
23
|
function useDbQueryById(table, id, options = {}) {
|
|
@@ -223,15 +29,15 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
223
29
|
enabled = id != null,
|
|
224
30
|
staleTime = 3e4
|
|
225
31
|
} = options;
|
|
226
|
-
const adapter =
|
|
32
|
+
const adapter = useMemo(() => {
|
|
227
33
|
try {
|
|
228
34
|
return registry.getAdapter(table);
|
|
229
35
|
} catch {
|
|
230
36
|
return null;
|
|
231
37
|
}
|
|
232
38
|
}, [registry, table]);
|
|
233
|
-
const queryKey =
|
|
234
|
-
const queryFn =
|
|
39
|
+
const queryKey = useMemo(() => buildQueryKey(table, id, select), [table, id, select]);
|
|
40
|
+
const queryFn = useCallback(async () => {
|
|
235
41
|
if (!adapter) {
|
|
236
42
|
throw new Error(`Adapter not available for table: ${table}`);
|
|
237
43
|
}
|
|
@@ -252,13 +58,13 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
252
58
|
});
|
|
253
59
|
return result.data[0] ?? null;
|
|
254
60
|
}, [adapter, table, id, select]);
|
|
255
|
-
const query =
|
|
61
|
+
const query = useQuery({
|
|
256
62
|
queryKey,
|
|
257
63
|
queryFn,
|
|
258
64
|
enabled: enabled && adapter !== null && id != null,
|
|
259
65
|
staleTime
|
|
260
66
|
});
|
|
261
|
-
|
|
67
|
+
useEffect(() => {
|
|
262
68
|
const adapterName = adapter?.name ?? "unknown";
|
|
263
69
|
if (query.isError && query.error) {
|
|
264
70
|
devWarn("useDbQueryById", `${table}(${id}) via ${adapterName}: Error - ${query.error.message}`);
|
|
@@ -267,7 +73,7 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
267
73
|
devLog("useDbQueryById", `${table}(${id}) via ${adapterName}: not found`);
|
|
268
74
|
}
|
|
269
75
|
}, [query.isError, query.error, query.isSuccess, query.data, table, id, adapter]);
|
|
270
|
-
const refetch =
|
|
76
|
+
const refetch = useCallback(async () => {
|
|
271
77
|
await query.refetch();
|
|
272
78
|
}, [query]);
|
|
273
79
|
return {
|
|
@@ -281,8 +87,8 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
281
87
|
}
|
|
282
88
|
|
|
283
89
|
// src/hooks/useAdvanceQuery.ts
|
|
284
|
-
import { useCallback as
|
|
285
|
-
import { useQuery as
|
|
90
|
+
import { useCallback as useCallback2, useMemo as useMemo2, useState, useEffect as useEffect2 } from "react";
|
|
91
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
286
92
|
import { useSessionStorageState } from "@pol-studios/hooks/storage";
|
|
287
93
|
import { omit } from "@pol-studios/utils";
|
|
288
94
|
var createDefaultFilterState = () => ({
|
|
@@ -317,7 +123,7 @@ function useAdvanceQuery(table, options) {
|
|
|
317
123
|
} = options;
|
|
318
124
|
const isPowerSync = powerSync !== null;
|
|
319
125
|
const realtimeEnabled = realtime ?? isPowerSync;
|
|
320
|
-
const defaultFilterState =
|
|
126
|
+
const defaultFilterState = useMemo2(
|
|
321
127
|
() => initialFilters ?? createDefaultFilterState(),
|
|
322
128
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
323
129
|
[]
|
|
@@ -325,16 +131,16 @@ function useAdvanceQuery(table, options) {
|
|
|
325
131
|
);
|
|
326
132
|
const [filtersRaw, setFiltersRaw] = useSessionStorageState(filterKey, defaultFilterState);
|
|
327
133
|
const filters = filtersRaw ?? defaultFilterState;
|
|
328
|
-
const setFilters =
|
|
134
|
+
const setFilters = useCallback2((action) => {
|
|
329
135
|
if (typeof action === "function") {
|
|
330
136
|
setFiltersRaw((prev) => action(prev ?? defaultFilterState));
|
|
331
137
|
} else {
|
|
332
138
|
setFiltersRaw(action);
|
|
333
139
|
}
|
|
334
140
|
}, [setFiltersRaw, defaultFilterState]);
|
|
335
|
-
const hasAdvancedFilters =
|
|
141
|
+
const hasAdvancedFilters = useMemo2(() => (filters?.filters?.length ?? 0) > 0 || !!filters?.naturalLanguageQuery, [filters?.filters?.length, filters?.naturalLanguageQuery]);
|
|
336
142
|
const usePowerSyncPath = !hasAdvancedFilters;
|
|
337
|
-
const powerSyncOrderBy =
|
|
143
|
+
const powerSyncOrderBy = useMemo2(() => {
|
|
338
144
|
if (filters?.sort && filters.sort.length > 0) {
|
|
339
145
|
return filters.sort.map((s) => ({
|
|
340
146
|
field: s.field,
|
|
@@ -354,8 +160,8 @@ function useAdvanceQuery(table, options) {
|
|
|
354
160
|
// Enable watch() subscriptions for reactive updates
|
|
355
161
|
});
|
|
356
162
|
const [extraData, setExtraData] = useState({});
|
|
357
|
-
const edgeFunctionQueryKey =
|
|
358
|
-
const edgeFunctionResult =
|
|
163
|
+
const edgeFunctionQueryKey = useMemo2(() => ["v3", "advance-query", tableName, select, JSON.stringify(where), JSON.stringify(filters)], [tableName, select, where, filters]);
|
|
164
|
+
const edgeFunctionResult = useQuery2({
|
|
359
165
|
queryKey: edgeFunctionQueryKey,
|
|
360
166
|
queryFn: async ({
|
|
361
167
|
signal
|
|
@@ -460,7 +266,7 @@ function useAdvanceQuery(table, options) {
|
|
|
460
266
|
refetchOnMount: true,
|
|
461
267
|
refetchOnWindowFocus: false
|
|
462
268
|
});
|
|
463
|
-
|
|
269
|
+
useEffect2(() => {
|
|
464
270
|
if (!realtimeEnabled || usePowerSyncPath || !enabled) {
|
|
465
271
|
return;
|
|
466
272
|
}
|
|
@@ -480,7 +286,7 @@ function useAdvanceQuery(table, options) {
|
|
|
480
286
|
supabase.removeChannel(channel);
|
|
481
287
|
};
|
|
482
288
|
}, [realtimeEnabled, usePowerSyncPath, enabled, supabase, tableName, filterKey, queryClient, edgeFunctionQueryKey]);
|
|
483
|
-
|
|
289
|
+
useEffect2(() => {
|
|
484
290
|
if (usePowerSyncPath) return;
|
|
485
291
|
const pathName = "EdgeFunction";
|
|
486
292
|
if (edgeFunctionResult.isError && edgeFunctionResult.error) {
|
|
@@ -490,7 +296,7 @@ function useAdvanceQuery(table, options) {
|
|
|
490
296
|
devLog("useAdvanceQuery", `${tableName} via ${pathName}: 0 results`);
|
|
491
297
|
}
|
|
492
298
|
}, [usePowerSyncPath, edgeFunctionResult.isError, edgeFunctionResult.error, edgeFunctionResult.isSuccess, edgeFunctionResult.data, tableName]);
|
|
493
|
-
const result =
|
|
299
|
+
const result = useMemo2(() => {
|
|
494
300
|
if (usePowerSyncPath) {
|
|
495
301
|
return {
|
|
496
302
|
data: powerSyncResult.data,
|
|
@@ -1046,7 +852,7 @@ function useDbDelete(table, t0) {
|
|
|
1046
852
|
}
|
|
1047
853
|
|
|
1048
854
|
// src/hooks/useDbInfiniteQuery.ts
|
|
1049
|
-
import { useMemo as
|
|
855
|
+
import { useMemo as useMemo3, useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
1050
856
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
1051
857
|
function buildInfiniteQueryKey(table, options) {
|
|
1052
858
|
return ["v3", "infinite-query", table, options.select ?? "*", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.pageSize ?? 50, options.searchText ?? "", JSON.stringify(options.searchFields ?? [])];
|
|
@@ -1061,7 +867,7 @@ function serializeInfiniteQueryOptions(options) {
|
|
|
1061
867
|
searchFields: options.searchFields
|
|
1062
868
|
});
|
|
1063
869
|
}
|
|
1064
|
-
function
|
|
870
|
+
function resolveTableName(table) {
|
|
1065
871
|
if (typeof table === "string") {
|
|
1066
872
|
return table;
|
|
1067
873
|
}
|
|
@@ -1084,7 +890,7 @@ function buildSearchWhereClause(searchText, searchFields, existingWhere) {
|
|
|
1084
890
|
};
|
|
1085
891
|
}
|
|
1086
892
|
function useDbInfiniteQuery(table, options = {}) {
|
|
1087
|
-
const tableName =
|
|
893
|
+
const tableName = resolveTableName(table);
|
|
1088
894
|
const {
|
|
1089
895
|
registry
|
|
1090
896
|
} = useDataLayerCore();
|
|
@@ -1097,22 +903,22 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1097
903
|
searchFields,
|
|
1098
904
|
...queryOptions
|
|
1099
905
|
} = options;
|
|
1100
|
-
const adapter =
|
|
906
|
+
const adapter = useMemo3(() => {
|
|
1101
907
|
try {
|
|
1102
908
|
return registry.getAdapter(tableName);
|
|
1103
909
|
} catch {
|
|
1104
910
|
return null;
|
|
1105
911
|
}
|
|
1106
912
|
}, [registry, tableName]);
|
|
1107
|
-
const serializedOptions =
|
|
1108
|
-
const queryKey =
|
|
1109
|
-
const effectiveWhere =
|
|
913
|
+
const serializedOptions = useMemo3(() => serializeInfiniteQueryOptions(options), [options.select, options.where, options.orderBy, options.pageSize, options.searchText, options.searchFields]);
|
|
914
|
+
const queryKey = useMemo3(() => buildInfiniteQueryKey(tableName, options), [tableName, serializedOptions]);
|
|
915
|
+
const effectiveWhere = useMemo3(() => {
|
|
1110
916
|
if (searchText && searchFields && searchFields.length > 0) {
|
|
1111
917
|
return buildSearchWhereClause(searchText, searchFields, queryOptions.where);
|
|
1112
918
|
}
|
|
1113
919
|
return queryOptions.where;
|
|
1114
920
|
}, [searchText, searchFields, queryOptions.where]);
|
|
1115
|
-
const memoizedQueryOptions =
|
|
921
|
+
const memoizedQueryOptions = useMemo3(() => ({
|
|
1116
922
|
select: queryOptions.select,
|
|
1117
923
|
where: effectiveWhere,
|
|
1118
924
|
orderBy: queryOptions.orderBy
|
|
@@ -1152,23 +958,23 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1152
958
|
staleTime,
|
|
1153
959
|
refetchOnWindowFocus
|
|
1154
960
|
});
|
|
1155
|
-
const flattenedData =
|
|
961
|
+
const flattenedData = useMemo3(() => {
|
|
1156
962
|
if (!infiniteQuery.data?.pages) return void 0;
|
|
1157
963
|
return infiniteQuery.data.pages.flatMap((page_0) => page_0.data);
|
|
1158
964
|
}, [infiniteQuery.data?.pages]);
|
|
1159
|
-
const count =
|
|
965
|
+
const count = useMemo3(() => {
|
|
1160
966
|
if (!infiniteQuery.data?.pages || infiniteQuery.data.pages.length === 0) {
|
|
1161
967
|
return void 0;
|
|
1162
968
|
}
|
|
1163
969
|
return infiniteQuery.data.pages[infiniteQuery.data.pages.length - 1].count;
|
|
1164
970
|
}, [infiniteQuery.data?.pages]);
|
|
1165
|
-
const fetchNextPage =
|
|
971
|
+
const fetchNextPage = useCallback3(async () => {
|
|
1166
972
|
await infiniteQuery.fetchNextPage();
|
|
1167
973
|
}, [infiniteQuery]);
|
|
1168
|
-
const refetch =
|
|
974
|
+
const refetch = useCallback3(async () => {
|
|
1169
975
|
await infiniteQuery.refetch();
|
|
1170
976
|
}, [infiniteQuery]);
|
|
1171
|
-
|
|
977
|
+
useEffect3(() => {
|
|
1172
978
|
const adapterName = adapter?.name ?? "unknown";
|
|
1173
979
|
if (infiniteQuery.isError && infiniteQuery.error) {
|
|
1174
980
|
devWarn("useDbInfiniteQuery", `${tableName} via ${adapterName}: Error - ${infiniteQuery.error.message}`);
|
|
@@ -1193,8 +999,8 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1193
999
|
|
|
1194
1000
|
// src/hooks/useDbCount.ts
|
|
1195
1001
|
import { c as _c5 } from "react/compiler-runtime";
|
|
1196
|
-
import { useEffect as
|
|
1197
|
-
import { useQuery as
|
|
1002
|
+
import { useEffect as useEffect4 } from "react";
|
|
1003
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
1198
1004
|
function useDbCount(table, t0) {
|
|
1199
1005
|
const $ = _c5(37);
|
|
1200
1006
|
let t1;
|
|
@@ -1287,7 +1093,7 @@ function useDbCount(table, t0) {
|
|
|
1287
1093
|
} else {
|
|
1288
1094
|
t9 = $[18];
|
|
1289
1095
|
}
|
|
1290
|
-
const query =
|
|
1096
|
+
const query = useQuery3(t9);
|
|
1291
1097
|
let t10;
|
|
1292
1098
|
if ($[19] !== adapter?.name || $[20] !== query.error || $[21] !== query.isError || $[22] !== table) {
|
|
1293
1099
|
t10 = () => {
|
|
@@ -1315,7 +1121,7 @@ function useDbCount(table, t0) {
|
|
|
1315
1121
|
} else {
|
|
1316
1122
|
t11 = $[28];
|
|
1317
1123
|
}
|
|
1318
|
-
|
|
1124
|
+
useEffect4(t10, t11);
|
|
1319
1125
|
let t12;
|
|
1320
1126
|
if ($[29] !== query) {
|
|
1321
1127
|
t12 = async () => {
|
|
@@ -1351,7 +1157,7 @@ function useDbCount(table, t0) {
|
|
|
1351
1157
|
|
|
1352
1158
|
// src/hooks/useSyncStatus.ts
|
|
1353
1159
|
import { c as _c6 } from "react/compiler-runtime";
|
|
1354
|
-
import { useState as useState2, useEffect as
|
|
1160
|
+
import { useState as useState2, useEffect as useEffect5, useContext } from "react";
|
|
1355
1161
|
var defaultSyncStatus = {
|
|
1356
1162
|
isConnected: true,
|
|
1357
1163
|
// Supabase-only mode is always "connected" when online
|
|
@@ -1362,8 +1168,8 @@ var defaultSyncStatus = {
|
|
|
1362
1168
|
};
|
|
1363
1169
|
function useSyncStatus() {
|
|
1364
1170
|
const $ = _c6(6);
|
|
1365
|
-
const statusContext =
|
|
1366
|
-
const coreContext =
|
|
1171
|
+
const statusContext = useContext(DataLayerStatusContext);
|
|
1172
|
+
const coreContext = useContext(DataLayerCoreContext);
|
|
1367
1173
|
if (!statusContext || !coreContext) {
|
|
1368
1174
|
throw new Error("useSyncStatus must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.");
|
|
1369
1175
|
}
|
|
@@ -1399,16 +1205,16 @@ function useSyncStatus() {
|
|
|
1399
1205
|
t0 = $[4];
|
|
1400
1206
|
t1 = $[5];
|
|
1401
1207
|
}
|
|
1402
|
-
|
|
1208
|
+
useEffect5(t0, t1);
|
|
1403
1209
|
return currentStatus;
|
|
1404
1210
|
}
|
|
1405
1211
|
|
|
1406
1212
|
// src/hooks/useSyncControl.ts
|
|
1407
1213
|
import { c as _c7 } from "react/compiler-runtime";
|
|
1408
|
-
import { useContext as
|
|
1214
|
+
import { useContext as useContext2 } from "react";
|
|
1409
1215
|
function useSyncControl() {
|
|
1410
1216
|
const $ = _c7(1);
|
|
1411
|
-
const coreContext =
|
|
1217
|
+
const coreContext = useContext2(DataLayerCoreContext);
|
|
1412
1218
|
if (!coreContext) {
|
|
1413
1219
|
throw new Error("useSyncControl must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.");
|
|
1414
1220
|
}
|
|
@@ -1498,15 +1304,6 @@ function useOnlineStatus() {
|
|
|
1498
1304
|
}
|
|
1499
1305
|
|
|
1500
1306
|
export {
|
|
1501
|
-
DataLayerCoreContext,
|
|
1502
|
-
DataLayerStatusContext,
|
|
1503
|
-
DataLayerContext,
|
|
1504
|
-
useDataLayerCore,
|
|
1505
|
-
useDataLayerCoreOptional,
|
|
1506
|
-
useDataLayerStatus,
|
|
1507
|
-
useDataLayer,
|
|
1508
|
-
useDataLayerOptional,
|
|
1509
|
-
useDbQuery,
|
|
1510
1307
|
useDbQueryById,
|
|
1511
1308
|
useAdvanceQuery,
|
|
1512
1309
|
useDbInsert,
|
|
@@ -1519,4 +1316,4 @@ export {
|
|
|
1519
1316
|
useSyncControl,
|
|
1520
1317
|
useOnlineStatus
|
|
1521
1318
|
};
|
|
1522
|
-
//# sourceMappingURL=chunk-
|
|
1319
|
+
//# sourceMappingURL=chunk-NP34C3O3.js.map
|