@pol-studios/db 1.0.24 → 1.0.27
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-BnDyYvkg.d.ts → DataLayerContext-Dc7nF2IG.d.ts} +1 -1
- package/dist/auth/context.js +2 -2
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-WHJJDWFT.js → chunk-3LPQFO2S.js} +4 -4
- package/dist/{chunk-LABTYQOJ.js → chunk-66AGXIV5.js} +4 -4
- package/dist/{chunk-VZMZXL37.js → chunk-7ANPMUR5.js} +33 -7
- package/dist/chunk-7ANPMUR5.js.map +1 -0
- package/dist/{chunk-BXSOHOQ2.js → chunk-CNIGRBRE.js} +67 -34
- package/dist/chunk-CNIGRBRE.js.map +1 -0
- package/dist/{chunk-2DOYFTN4.js → chunk-EKUDGIQZ.js} +244 -205
- package/dist/chunk-EKUDGIQZ.js.map +1 -0
- package/dist/{chunk-VWPLASGY.js → chunk-H5T2DJ7G.js} +2 -2
- package/dist/{chunk-7OLNKLII.js → chunk-PHNBHM7X.js} +3 -3
- package/dist/{executor-CB4KHyYG.d.ts → executor-Br27YZvl.d.ts} +22 -1
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +1 -1
- package/dist/{index-B6xGmPRV.d.ts → index-CYFdO0iB.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -7
- package/dist/index.native.d.ts +6 -6
- package/dist/index.native.js +7 -7
- package/dist/index.web.d.ts +7 -7
- package/dist/index.web.js +6 -6
- 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/{useDbCount-Dn_1uI69.d.ts → useDbCount-Dk0yCKlT.d.ts} +1 -1
- package/dist/{useResolveFeedback-CBHY2Z1Q.d.ts → useResolveFeedback-C1KucfdQ.d.ts} +3 -3
- package/dist/with-auth/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-2DOYFTN4.js.map +0 -1
- package/dist/chunk-BXSOHOQ2.js.map +0 -1
- package/dist/chunk-VZMZXL37.js.map +0 -1
- /package/dist/{chunk-WHJJDWFT.js.map → chunk-3LPQFO2S.js.map} +0 -0
- /package/dist/{chunk-LABTYQOJ.js.map → chunk-66AGXIV5.js.map} +0 -0
- /package/dist/{chunk-VWPLASGY.js.map → chunk-H5T2DJ7G.js.map} +0 -0
- /package/dist/{chunk-7OLNKLII.js.map → chunk-PHNBHM7X.js.map} +0 -0
|
@@ -50,8 +50,22 @@ function useDataLayerOptional() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// src/hooks/useDbQuery.ts
|
|
53
|
-
import { useMemo, useEffect, useCallback } from "react";
|
|
53
|
+
import { useMemo, useEffect, useCallback, useRef } from "react";
|
|
54
54
|
import { useQuery } from "@tanstack/react-query";
|
|
55
|
+
|
|
56
|
+
// src/utils/dev-log.ts
|
|
57
|
+
function devLog(prefix, message) {
|
|
58
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
59
|
+
console.log(`[${prefix}] ${message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function devWarn(prefix, message) {
|
|
63
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
64
|
+
console.warn(`[${prefix}] ${message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/hooks/useDbQuery.ts
|
|
55
69
|
function buildQueryKey(table, options) {
|
|
56
70
|
return ["v3", "query", table, options.select ?? "*", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.limit, options.offset];
|
|
57
71
|
}
|
|
@@ -74,12 +88,10 @@ function useDbQuery(table, options = {}) {
|
|
|
74
88
|
const tableName = typeof table === "string" ? table : resolveTableName(table);
|
|
75
89
|
const {
|
|
76
90
|
registry,
|
|
77
|
-
queryClient
|
|
91
|
+
queryClient,
|
|
92
|
+
powerSync
|
|
78
93
|
} = useDataLayerCore();
|
|
79
|
-
const
|
|
80
|
-
status
|
|
81
|
-
} = useDataLayerStatus();
|
|
82
|
-
const isPowerSync = status.currentBackend === "powersync";
|
|
94
|
+
const isPowerSync = powerSync !== null;
|
|
83
95
|
const {
|
|
84
96
|
enabled = true,
|
|
85
97
|
staleTime = isPowerSync ? 0 : 3e4,
|
|
@@ -92,21 +104,21 @@ function useDbQuery(table, options = {}) {
|
|
|
92
104
|
...queryOptions
|
|
93
105
|
} = options;
|
|
94
106
|
const adapter = useMemo(() => {
|
|
95
|
-
if (!status.isInitialized) return null;
|
|
96
107
|
try {
|
|
97
108
|
return registry.getAdapter(tableName);
|
|
98
109
|
} catch {
|
|
99
110
|
return null;
|
|
100
111
|
}
|
|
101
|
-
}, [registry, tableName
|
|
102
|
-
const
|
|
112
|
+
}, [registry, tableName]);
|
|
113
|
+
const serializedOptions = useMemo(() => serializeQueryOptions(options), [options.select, options.where, options.orderBy, options.limit, options.offset]);
|
|
114
|
+
const queryKey = useMemo(() => buildQueryKey(tableName, options), [tableName, serializedOptions]);
|
|
103
115
|
const memoizedQueryOptions = useMemo(() => ({
|
|
104
116
|
select: queryOptions.select,
|
|
105
117
|
where: queryOptions.where,
|
|
106
118
|
orderBy: queryOptions.orderBy,
|
|
107
119
|
limit: queryOptions.limit,
|
|
108
120
|
offset: queryOptions.offset
|
|
109
|
-
}), [
|
|
121
|
+
}), [serializedOptions]);
|
|
110
122
|
const queryFn = useCallback(async () => {
|
|
111
123
|
if (!adapter) {
|
|
112
124
|
throw new Error(`Adapter not available for table: ${tableName}`);
|
|
@@ -117,14 +129,32 @@ function useDbQuery(table, options = {}) {
|
|
|
117
129
|
const query = useQuery({
|
|
118
130
|
queryKey,
|
|
119
131
|
queryFn,
|
|
120
|
-
enabled: enabled &&
|
|
132
|
+
enabled: enabled && adapter !== null,
|
|
121
133
|
staleTime,
|
|
122
134
|
gcTime,
|
|
123
135
|
refetchOnWindowFocus,
|
|
124
136
|
refetchOnMount
|
|
125
137
|
});
|
|
138
|
+
const invalidateTimeoutRef = useRef(null);
|
|
139
|
+
const debouncedInvalidate = useCallback(() => {
|
|
140
|
+
if (invalidateTimeoutRef.current) {
|
|
141
|
+
clearTimeout(invalidateTimeoutRef.current);
|
|
142
|
+
}
|
|
143
|
+
invalidateTimeoutRef.current = setTimeout(() => {
|
|
144
|
+
queryClient.invalidateQueries({
|
|
145
|
+
queryKey
|
|
146
|
+
});
|
|
147
|
+
}, 100);
|
|
148
|
+
}, [queryClient, queryKey]);
|
|
126
149
|
useEffect(() => {
|
|
127
|
-
|
|
150
|
+
return () => {
|
|
151
|
+
if (invalidateTimeoutRef.current) {
|
|
152
|
+
clearTimeout(invalidateTimeoutRef.current);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}, []);
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (!realtime || !adapter?.subscribe) {
|
|
128
158
|
return;
|
|
129
159
|
}
|
|
130
160
|
let isFirstCallback = true;
|
|
@@ -135,9 +165,7 @@ function useDbQuery(table, options = {}) {
|
|
|
135
165
|
}
|
|
136
166
|
const hasRelations = memoizedQueryOptions.select?.includes("(");
|
|
137
167
|
if (hasRelations) {
|
|
138
|
-
|
|
139
|
-
queryKey
|
|
140
|
-
});
|
|
168
|
+
debouncedInvalidate();
|
|
141
169
|
} else {
|
|
142
170
|
queryClient.setQueryData(queryKey, {
|
|
143
171
|
data,
|
|
@@ -148,7 +176,16 @@ function useDbQuery(table, options = {}) {
|
|
|
148
176
|
return () => {
|
|
149
177
|
unsubscribe();
|
|
150
178
|
};
|
|
151
|
-
}, [realtime, adapter, tableName, memoizedQueryOptions, queryClient, queryKey,
|
|
179
|
+
}, [realtime, adapter, tableName, memoizedQueryOptions, queryClient, queryKey, debouncedInvalidate]);
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
const adapterName = adapter?.name ?? "unknown";
|
|
182
|
+
if (query.isError && query.error) {
|
|
183
|
+
devWarn("useDbQuery", `${tableName} via ${adapterName}: Error - ${query.error.message}`);
|
|
184
|
+
}
|
|
185
|
+
if (query.isSuccess && query.data?.data?.length === 0) {
|
|
186
|
+
devLog("useDbQuery", `${tableName} via ${adapterName}: 0 results`);
|
|
187
|
+
}
|
|
188
|
+
}, [query.isError, query.error, query.isSuccess, query.data, tableName, adapter]);
|
|
152
189
|
const refetch = useCallback(async () => {
|
|
153
190
|
await query.refetch();
|
|
154
191
|
}, [query]);
|
|
@@ -170,7 +207,7 @@ function useDbQuery(table, options = {}) {
|
|
|
170
207
|
}
|
|
171
208
|
|
|
172
209
|
// src/hooks/useDbQueryById.ts
|
|
173
|
-
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
210
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
174
211
|
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
175
212
|
function buildQueryKey2(table, id, select) {
|
|
176
213
|
return ["v3", "queryById", table, id, select ?? "*"];
|
|
@@ -179,22 +216,18 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
179
216
|
const {
|
|
180
217
|
registry
|
|
181
218
|
} = useDataLayerCore();
|
|
182
|
-
const {
|
|
183
|
-
status
|
|
184
|
-
} = useDataLayerStatus();
|
|
185
219
|
const {
|
|
186
220
|
select,
|
|
187
221
|
enabled = id != null,
|
|
188
222
|
staleTime = 3e4
|
|
189
223
|
} = options;
|
|
190
224
|
const adapter = useMemo2(() => {
|
|
191
|
-
if (!status.isInitialized) return null;
|
|
192
225
|
try {
|
|
193
226
|
return registry.getAdapter(table);
|
|
194
227
|
} catch {
|
|
195
228
|
return null;
|
|
196
229
|
}
|
|
197
|
-
}, [registry, table
|
|
230
|
+
}, [registry, table]);
|
|
198
231
|
const queryKey = useMemo2(() => buildQueryKey2(table, id, select), [table, id, select]);
|
|
199
232
|
const queryFn = useCallback2(async () => {
|
|
200
233
|
if (!adapter) {
|
|
@@ -220,9 +253,18 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
220
253
|
const query = useQuery2({
|
|
221
254
|
queryKey,
|
|
222
255
|
queryFn,
|
|
223
|
-
enabled: enabled &&
|
|
256
|
+
enabled: enabled && adapter !== null && id != null,
|
|
224
257
|
staleTime
|
|
225
258
|
});
|
|
259
|
+
useEffect2(() => {
|
|
260
|
+
const adapterName = adapter?.name ?? "unknown";
|
|
261
|
+
if (query.isError && query.error) {
|
|
262
|
+
devWarn("useDbQueryById", `${table}(${id}) via ${adapterName}: Error - ${query.error.message}`);
|
|
263
|
+
}
|
|
264
|
+
if (query.isSuccess && query.data === null) {
|
|
265
|
+
devLog("useDbQueryById", `${table}(${id}) via ${adapterName}: not found`);
|
|
266
|
+
}
|
|
267
|
+
}, [query.isError, query.error, query.isSuccess, query.data, table, id, adapter]);
|
|
226
268
|
const refetch = useCallback2(async () => {
|
|
227
269
|
await query.refetch();
|
|
228
270
|
}, [query]);
|
|
@@ -237,7 +279,7 @@ function useDbQueryById(table, id, options = {}) {
|
|
|
237
279
|
}
|
|
238
280
|
|
|
239
281
|
// src/hooks/useAdvanceQuery.ts
|
|
240
|
-
import { useCallback as useCallback3, useMemo as useMemo3, useState, useEffect as
|
|
282
|
+
import { useCallback as useCallback3, useMemo as useMemo3, useState, useEffect as useEffect3 } from "react";
|
|
241
283
|
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
242
284
|
import { useSessionStorageState } from "@pol-studios/hooks/storage";
|
|
243
285
|
var createDefaultFilterState = () => ({
|
|
@@ -252,11 +294,9 @@ function useAdvanceQuery(table, options) {
|
|
|
252
294
|
const tableName = typeof table === "string" ? table : `${table.schema}.${table.table}`;
|
|
253
295
|
const {
|
|
254
296
|
registry,
|
|
255
|
-
queryClient
|
|
297
|
+
queryClient,
|
|
298
|
+
powerSync
|
|
256
299
|
} = useDataLayerCore();
|
|
257
|
-
const {
|
|
258
|
-
status
|
|
259
|
-
} = useDataLayerStatus();
|
|
260
300
|
const supabase = useSupabase();
|
|
261
301
|
const {
|
|
262
302
|
filterKey,
|
|
@@ -272,7 +312,7 @@ function useAdvanceQuery(table, options) {
|
|
|
272
312
|
offset,
|
|
273
313
|
...restOptions
|
|
274
314
|
} = options;
|
|
275
|
-
const isPowerSync =
|
|
315
|
+
const isPowerSync = powerSync !== null;
|
|
276
316
|
const realtimeEnabled = realtime ?? isPowerSync;
|
|
277
317
|
const defaultFilterState = useMemo3(
|
|
278
318
|
() => initialFilters ?? createDefaultFilterState(),
|
|
@@ -311,7 +351,7 @@ function useAdvanceQuery(table, options) {
|
|
|
311
351
|
// Enable watch() subscriptions for reactive updates
|
|
312
352
|
});
|
|
313
353
|
const [extraData, setExtraData] = useState({});
|
|
314
|
-
const edgeFunctionQueryKey = useMemo3(() => ["v3", "advance-query", tableName, select, JSON.stringify(where), JSON.stringify(filters)
|
|
354
|
+
const edgeFunctionQueryKey = useMemo3(() => ["v3", "advance-query", tableName, select, JSON.stringify(where), JSON.stringify(filters)], [tableName, select, where, filters]);
|
|
315
355
|
const edgeFunctionResult = useQuery3({
|
|
316
356
|
queryKey: edgeFunctionQueryKey,
|
|
317
357
|
queryFn: async ({
|
|
@@ -417,7 +457,7 @@ function useAdvanceQuery(table, options) {
|
|
|
417
457
|
refetchOnMount: true,
|
|
418
458
|
refetchOnWindowFocus: false
|
|
419
459
|
});
|
|
420
|
-
|
|
460
|
+
useEffect3(() => {
|
|
421
461
|
if (!realtimeEnabled || usePowerSyncPath || !enabled) {
|
|
422
462
|
return;
|
|
423
463
|
}
|
|
@@ -437,6 +477,16 @@ function useAdvanceQuery(table, options) {
|
|
|
437
477
|
supabase.removeChannel(channel);
|
|
438
478
|
};
|
|
439
479
|
}, [realtimeEnabled, usePowerSyncPath, enabled, supabase, tableName, filterKey, queryClient, edgeFunctionQueryKey]);
|
|
480
|
+
useEffect3(() => {
|
|
481
|
+
if (usePowerSyncPath) return;
|
|
482
|
+
const pathName = "EdgeFunction";
|
|
483
|
+
if (edgeFunctionResult.isError && edgeFunctionResult.error) {
|
|
484
|
+
devWarn("useAdvanceQuery", `${tableName} via ${pathName}: Error - ${edgeFunctionResult.error.message}`);
|
|
485
|
+
}
|
|
486
|
+
if (edgeFunctionResult.isSuccess && edgeFunctionResult.data?.data?.length === 0) {
|
|
487
|
+
devLog("useAdvanceQuery", `${tableName} via ${pathName}: 0 results`);
|
|
488
|
+
}
|
|
489
|
+
}, [usePowerSyncPath, edgeFunctionResult.isError, edgeFunctionResult.error, edgeFunctionResult.isSuccess, edgeFunctionResult.data, tableName]);
|
|
440
490
|
const result = useMemo3(() => {
|
|
441
491
|
if (usePowerSyncPath) {
|
|
442
492
|
return {
|
|
@@ -488,9 +538,6 @@ function useDbInsert(table, t0) {
|
|
|
488
538
|
const {
|
|
489
539
|
registry
|
|
490
540
|
} = useDataLayerCore();
|
|
491
|
-
const {
|
|
492
|
-
status
|
|
493
|
-
} = useDataLayerStatus();
|
|
494
541
|
const queryClient = useQueryClient();
|
|
495
542
|
const {
|
|
496
543
|
onSuccess,
|
|
@@ -508,25 +555,19 @@ function useDbInsert(table, t0) {
|
|
|
508
555
|
}
|
|
509
556
|
const invalidateTables = t3;
|
|
510
557
|
let t4;
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
$[5] = registry;
|
|
521
|
-
$[6] = table;
|
|
522
|
-
$[7] = t52;
|
|
523
|
-
} else {
|
|
524
|
-
t52 = $[7];
|
|
525
|
-
}
|
|
526
|
-
t4 = t52;
|
|
527
|
-
} catch {
|
|
528
|
-
t4 = null;
|
|
558
|
+
try {
|
|
559
|
+
let t52;
|
|
560
|
+
if ($[5] !== registry || $[6] !== table) {
|
|
561
|
+
t52 = registry.getAdapter(table);
|
|
562
|
+
$[5] = registry;
|
|
563
|
+
$[6] = table;
|
|
564
|
+
$[7] = t52;
|
|
565
|
+
} else {
|
|
566
|
+
t52 = $[7];
|
|
529
567
|
}
|
|
568
|
+
t4 = t52;
|
|
569
|
+
} catch {
|
|
570
|
+
t4 = null;
|
|
530
571
|
}
|
|
531
572
|
const adapter = t4;
|
|
532
573
|
let t5;
|
|
@@ -627,9 +668,6 @@ function useDbUpdate(table, t0) {
|
|
|
627
668
|
const {
|
|
628
669
|
registry
|
|
629
670
|
} = useDataLayerCore();
|
|
630
|
-
const {
|
|
631
|
-
status
|
|
632
|
-
} = useDataLayerStatus();
|
|
633
671
|
const queryClient = useQueryClient2();
|
|
634
672
|
const {
|
|
635
673
|
onSuccess,
|
|
@@ -649,25 +687,19 @@ function useDbUpdate(table, t0) {
|
|
|
649
687
|
const invalidateTables = t4;
|
|
650
688
|
const optimistic = t3 === void 0 ? false : t3;
|
|
651
689
|
let t5;
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
$[5] = registry;
|
|
662
|
-
$[6] = table;
|
|
663
|
-
$[7] = t62;
|
|
664
|
-
} else {
|
|
665
|
-
t62 = $[7];
|
|
666
|
-
}
|
|
667
|
-
t5 = t62;
|
|
668
|
-
} catch {
|
|
669
|
-
t5 = null;
|
|
690
|
+
try {
|
|
691
|
+
let t62;
|
|
692
|
+
if ($[5] !== registry || $[6] !== table) {
|
|
693
|
+
t62 = registry.getAdapter(table);
|
|
694
|
+
$[5] = registry;
|
|
695
|
+
$[6] = table;
|
|
696
|
+
$[7] = t62;
|
|
697
|
+
} else {
|
|
698
|
+
t62 = $[7];
|
|
670
699
|
}
|
|
700
|
+
t5 = t62;
|
|
701
|
+
} catch {
|
|
702
|
+
t5 = null;
|
|
671
703
|
}
|
|
672
704
|
const adapter = t5;
|
|
673
705
|
let t6;
|
|
@@ -798,9 +830,6 @@ function useDbUpsert(table, t0) {
|
|
|
798
830
|
const {
|
|
799
831
|
registry
|
|
800
832
|
} = useDataLayerCore();
|
|
801
|
-
const {
|
|
802
|
-
status
|
|
803
|
-
} = useDataLayerStatus();
|
|
804
833
|
const queryClient = useQueryClient3();
|
|
805
834
|
const {
|
|
806
835
|
onSuccess,
|
|
@@ -818,36 +847,29 @@ function useDbUpsert(table, t0) {
|
|
|
818
847
|
}
|
|
819
848
|
const invalidateTables = t3;
|
|
820
849
|
let t4;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
850
|
+
;
|
|
851
|
+
try {
|
|
852
|
+
let t62;
|
|
853
|
+
if ($[5] !== registry || $[6] !== table) {
|
|
854
|
+
t62 = registry.getAdapter(table);
|
|
855
|
+
$[5] = registry;
|
|
856
|
+
$[6] = table;
|
|
857
|
+
$[7] = t62;
|
|
858
|
+
} else {
|
|
859
|
+
t62 = $[7];
|
|
825
860
|
}
|
|
826
|
-
;
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
$[5] = registry;
|
|
832
|
-
$[6] = table;
|
|
833
|
-
$[7] = t62;
|
|
834
|
-
} else {
|
|
835
|
-
t62 = $[7];
|
|
836
|
-
}
|
|
837
|
-
const resolvedAdapter = t62;
|
|
838
|
-
t4 = resolvedAdapter;
|
|
839
|
-
} catch (t52) {
|
|
840
|
-
const error = t52;
|
|
841
|
-
if (__DEV__) {
|
|
842
|
-
console.warn(`[useDbUpsert] Failed to get adapter for table "${table}":`, error);
|
|
843
|
-
}
|
|
844
|
-
t4 = null;
|
|
861
|
+
t4 = t62;
|
|
862
|
+
} catch (t5) {
|
|
863
|
+
const error = t5;
|
|
864
|
+
if (__DEV__) {
|
|
865
|
+
console.warn(`[useDbUpsert] Failed to get adapter for table "${table}":`, error);
|
|
845
866
|
}
|
|
867
|
+
t4 = null;
|
|
846
868
|
}
|
|
847
869
|
const adapter = t4;
|
|
848
|
-
let
|
|
870
|
+
let t6;
|
|
849
871
|
if ($[8] !== adapter || $[9] !== table) {
|
|
850
|
-
|
|
872
|
+
t6 = async (data) => {
|
|
851
873
|
if (__DEV__) {
|
|
852
874
|
console.log(`[useDbUpsert] mutationFn called for table "${table}":`, {
|
|
853
875
|
adapterName: adapter?.name ?? "null",
|
|
@@ -869,14 +891,14 @@ function useDbUpsert(table, t0) {
|
|
|
869
891
|
};
|
|
870
892
|
$[8] = adapter;
|
|
871
893
|
$[9] = table;
|
|
872
|
-
$[10] =
|
|
894
|
+
$[10] = t6;
|
|
873
895
|
} else {
|
|
874
|
-
|
|
896
|
+
t6 = $[10];
|
|
875
897
|
}
|
|
876
|
-
const mutationFn =
|
|
877
|
-
let
|
|
898
|
+
const mutationFn = t6;
|
|
899
|
+
let t7;
|
|
878
900
|
if ($[11] !== invalidateTables || $[12] !== onSuccess || $[13] !== queryClient) {
|
|
879
|
-
|
|
901
|
+
t7 = (data_0) => {
|
|
880
902
|
invalidateTables.forEach((t) => {
|
|
881
903
|
queryClient.invalidateQueries({
|
|
882
904
|
predicate: (query) => query.queryKey[0] === "v3" && query.queryKey[2] === t
|
|
@@ -887,43 +909,43 @@ function useDbUpsert(table, t0) {
|
|
|
887
909
|
$[11] = invalidateTables;
|
|
888
910
|
$[12] = onSuccess;
|
|
889
911
|
$[13] = queryClient;
|
|
890
|
-
$[14] =
|
|
912
|
+
$[14] = t7;
|
|
891
913
|
} else {
|
|
892
|
-
|
|
914
|
+
t7 = $[14];
|
|
893
915
|
}
|
|
894
|
-
let
|
|
916
|
+
let t8;
|
|
895
917
|
if ($[15] !== onError) {
|
|
896
|
-
|
|
918
|
+
t8 = (error_0) => {
|
|
897
919
|
onError?.(error_0 instanceof Error ? error_0 : new Error(String(error_0)));
|
|
898
920
|
};
|
|
899
921
|
$[15] = onError;
|
|
900
|
-
$[16] =
|
|
922
|
+
$[16] = t8;
|
|
901
923
|
} else {
|
|
902
|
-
|
|
924
|
+
t8 = $[16];
|
|
903
925
|
}
|
|
904
|
-
let
|
|
905
|
-
if ($[17] !== mutationFn || $[18] !==
|
|
906
|
-
|
|
926
|
+
let t9;
|
|
927
|
+
if ($[17] !== mutationFn || $[18] !== t7 || $[19] !== t8) {
|
|
928
|
+
t9 = {
|
|
907
929
|
mutationFn,
|
|
908
|
-
onSuccess:
|
|
909
|
-
onError:
|
|
930
|
+
onSuccess: t7,
|
|
931
|
+
onError: t8
|
|
910
932
|
};
|
|
911
933
|
$[17] = mutationFn;
|
|
912
|
-
$[18] =
|
|
913
|
-
$[19] =
|
|
914
|
-
$[20] =
|
|
934
|
+
$[18] = t7;
|
|
935
|
+
$[19] = t8;
|
|
936
|
+
$[20] = t9;
|
|
915
937
|
} else {
|
|
916
|
-
|
|
938
|
+
t9 = $[20];
|
|
917
939
|
}
|
|
918
|
-
const mutation = useMutation3(
|
|
919
|
-
const
|
|
920
|
-
let
|
|
921
|
-
if ($[21] !== mutation.data || $[22] !== mutation.isPending || $[23] !== mutation.mutate || $[24] !== mutation.mutateAsync || $[25] !== mutation.reset || $[26] !==
|
|
922
|
-
|
|
940
|
+
const mutation = useMutation3(t9);
|
|
941
|
+
const t10 = mutation.error;
|
|
942
|
+
let t11;
|
|
943
|
+
if ($[21] !== mutation.data || $[22] !== mutation.isPending || $[23] !== mutation.mutate || $[24] !== mutation.mutateAsync || $[25] !== mutation.reset || $[26] !== t10) {
|
|
944
|
+
t11 = {
|
|
923
945
|
mutate: mutation.mutate,
|
|
924
946
|
mutateAsync: mutation.mutateAsync,
|
|
925
947
|
isPending: mutation.isPending,
|
|
926
|
-
error:
|
|
948
|
+
error: t10,
|
|
927
949
|
reset: mutation.reset,
|
|
928
950
|
data: mutation.data
|
|
929
951
|
};
|
|
@@ -932,12 +954,12 @@ function useDbUpsert(table, t0) {
|
|
|
932
954
|
$[23] = mutation.mutate;
|
|
933
955
|
$[24] = mutation.mutateAsync;
|
|
934
956
|
$[25] = mutation.reset;
|
|
935
|
-
$[26] =
|
|
936
|
-
$[27] =
|
|
957
|
+
$[26] = t10;
|
|
958
|
+
$[27] = t11;
|
|
937
959
|
} else {
|
|
938
|
-
|
|
960
|
+
t11 = $[27];
|
|
939
961
|
}
|
|
940
|
-
return
|
|
962
|
+
return t11;
|
|
941
963
|
}
|
|
942
964
|
|
|
943
965
|
// src/hooks/useDbDelete.ts
|
|
@@ -957,9 +979,6 @@ function useDbDelete(table, t0) {
|
|
|
957
979
|
const {
|
|
958
980
|
registry
|
|
959
981
|
} = useDataLayerCore();
|
|
960
|
-
const {
|
|
961
|
-
status
|
|
962
|
-
} = useDataLayerStatus();
|
|
963
982
|
const queryClient = useQueryClient4();
|
|
964
983
|
const {
|
|
965
984
|
onSuccess,
|
|
@@ -979,25 +998,19 @@ function useDbDelete(table, t0) {
|
|
|
979
998
|
const invalidateTables = t4;
|
|
980
999
|
const optimistic = t3 === void 0 ? false : t3;
|
|
981
1000
|
let t5;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
$[5] = registry;
|
|
992
|
-
$[6] = table;
|
|
993
|
-
$[7] = t62;
|
|
994
|
-
} else {
|
|
995
|
-
t62 = $[7];
|
|
996
|
-
}
|
|
997
|
-
t5 = t62;
|
|
998
|
-
} catch {
|
|
999
|
-
t5 = null;
|
|
1001
|
+
try {
|
|
1002
|
+
let t62;
|
|
1003
|
+
if ($[5] !== registry || $[6] !== table) {
|
|
1004
|
+
t62 = registry.getAdapter(table);
|
|
1005
|
+
$[5] = registry;
|
|
1006
|
+
$[6] = table;
|
|
1007
|
+
$[7] = t62;
|
|
1008
|
+
} else {
|
|
1009
|
+
t62 = $[7];
|
|
1000
1010
|
}
|
|
1011
|
+
t5 = t62;
|
|
1012
|
+
} catch {
|
|
1013
|
+
t5 = null;
|
|
1001
1014
|
}
|
|
1002
1015
|
const adapter = t5;
|
|
1003
1016
|
let t6;
|
|
@@ -1121,7 +1134,7 @@ function useDbDelete(table, t0) {
|
|
|
1121
1134
|
}
|
|
1122
1135
|
|
|
1123
1136
|
// src/hooks/useDbInfiniteQuery.ts
|
|
1124
|
-
import { useMemo as useMemo4, useCallback as useCallback4 } from "react";
|
|
1137
|
+
import { useMemo as useMemo4, useCallback as useCallback4, useEffect as useEffect4 } from "react";
|
|
1125
1138
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
1126
1139
|
function buildInfiniteQueryKey(table, options) {
|
|
1127
1140
|
return ["v3", "infinite-query", table, options.select ?? "*", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.pageSize ?? 50, options.searchText ?? "", JSON.stringify(options.searchFields ?? [])];
|
|
@@ -1163,9 +1176,6 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1163
1176
|
const {
|
|
1164
1177
|
registry
|
|
1165
1178
|
} = useDataLayerCore();
|
|
1166
|
-
const {
|
|
1167
|
-
status
|
|
1168
|
-
} = useDataLayerStatus();
|
|
1169
1179
|
const {
|
|
1170
1180
|
enabled = true,
|
|
1171
1181
|
staleTime = 3e4,
|
|
@@ -1176,14 +1186,14 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1176
1186
|
...queryOptions
|
|
1177
1187
|
} = options;
|
|
1178
1188
|
const adapter = useMemo4(() => {
|
|
1179
|
-
if (!status.isInitialized) return null;
|
|
1180
1189
|
try {
|
|
1181
1190
|
return registry.getAdapter(tableName);
|
|
1182
1191
|
} catch {
|
|
1183
1192
|
return null;
|
|
1184
1193
|
}
|
|
1185
|
-
}, [registry, tableName
|
|
1186
|
-
const
|
|
1194
|
+
}, [registry, tableName]);
|
|
1195
|
+
const serializedOptions = useMemo4(() => serializeInfiniteQueryOptions(options), [options.select, options.where, options.orderBy, options.pageSize, options.searchText, options.searchFields]);
|
|
1196
|
+
const queryKey = useMemo4(() => buildInfiniteQueryKey(tableName, options), [tableName, serializedOptions]);
|
|
1187
1197
|
const effectiveWhere = useMemo4(() => {
|
|
1188
1198
|
if (searchText && searchFields && searchFields.length > 0) {
|
|
1189
1199
|
return buildSearchWhereClause(searchText, searchFields, queryOptions.where);
|
|
@@ -1226,7 +1236,7 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1226
1236
|
}
|
|
1227
1237
|
return allPages.length + 1;
|
|
1228
1238
|
},
|
|
1229
|
-
enabled: enabled &&
|
|
1239
|
+
enabled: enabled && adapter !== null,
|
|
1230
1240
|
staleTime,
|
|
1231
1241
|
refetchOnWindowFocus
|
|
1232
1242
|
});
|
|
@@ -1246,6 +1256,15 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1246
1256
|
const refetch = useCallback4(async () => {
|
|
1247
1257
|
await infiniteQuery.refetch();
|
|
1248
1258
|
}, [infiniteQuery]);
|
|
1259
|
+
useEffect4(() => {
|
|
1260
|
+
const adapterName = adapter?.name ?? "unknown";
|
|
1261
|
+
if (infiniteQuery.isError && infiniteQuery.error) {
|
|
1262
|
+
devWarn("useDbInfiniteQuery", `${tableName} via ${adapterName}: Error - ${infiniteQuery.error.message}`);
|
|
1263
|
+
}
|
|
1264
|
+
if (infiniteQuery.isSuccess && flattenedData?.length === 0) {
|
|
1265
|
+
devLog("useDbInfiniteQuery", `${tableName} via ${adapterName}: 0 results`);
|
|
1266
|
+
}
|
|
1267
|
+
}, [infiniteQuery.isError, infiniteQuery.error, infiniteQuery.isSuccess, flattenedData, tableName, adapter]);
|
|
1249
1268
|
return {
|
|
1250
1269
|
data: flattenedData,
|
|
1251
1270
|
isLoading: infiniteQuery.isLoading,
|
|
@@ -1262,9 +1281,10 @@ function useDbInfiniteQuery(table, options = {}) {
|
|
|
1262
1281
|
|
|
1263
1282
|
// src/hooks/useDbCount.ts
|
|
1264
1283
|
import { c as _c5 } from "react/compiler-runtime";
|
|
1284
|
+
import { useEffect as useEffect5 } from "react";
|
|
1265
1285
|
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
1266
1286
|
function useDbCount(table, t0) {
|
|
1267
|
-
const $ = _c5(
|
|
1287
|
+
const $ = _c5(37);
|
|
1268
1288
|
let t1;
|
|
1269
1289
|
if ($[0] !== t0) {
|
|
1270
1290
|
t1 = t0 === void 0 ? {} : t0;
|
|
@@ -1277,9 +1297,6 @@ function useDbCount(table, t0) {
|
|
|
1277
1297
|
const {
|
|
1278
1298
|
registry
|
|
1279
1299
|
} = useDataLayerCore();
|
|
1280
|
-
const {
|
|
1281
|
-
status
|
|
1282
|
-
} = useDataLayerStatus();
|
|
1283
1300
|
const {
|
|
1284
1301
|
enabled: t2,
|
|
1285
1302
|
staleTime: t3,
|
|
@@ -1288,25 +1305,19 @@ function useDbCount(table, t0) {
|
|
|
1288
1305
|
const enabled = t2 === void 0 ? true : t2;
|
|
1289
1306
|
const staleTime = t3 === void 0 ? 3e4 : t3;
|
|
1290
1307
|
let t4;
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
$[2] = registry;
|
|
1301
|
-
$[3] = table;
|
|
1302
|
-
$[4] = t52;
|
|
1303
|
-
} else {
|
|
1304
|
-
t52 = $[4];
|
|
1305
|
-
}
|
|
1306
|
-
t4 = t52;
|
|
1307
|
-
} catch {
|
|
1308
|
-
t4 = null;
|
|
1308
|
+
try {
|
|
1309
|
+
let t52;
|
|
1310
|
+
if ($[2] !== registry || $[3] !== table) {
|
|
1311
|
+
t52 = registry.getAdapter(table);
|
|
1312
|
+
$[2] = registry;
|
|
1313
|
+
$[3] = table;
|
|
1314
|
+
$[4] = t52;
|
|
1315
|
+
} else {
|
|
1316
|
+
t52 = $[4];
|
|
1309
1317
|
}
|
|
1318
|
+
t4 = t52;
|
|
1319
|
+
} catch {
|
|
1320
|
+
t4 = null;
|
|
1310
1321
|
}
|
|
1311
1322
|
const adapter = t4;
|
|
1312
1323
|
let t5;
|
|
@@ -1347,7 +1358,7 @@ function useDbCount(table, t0) {
|
|
|
1347
1358
|
t7 = $[13];
|
|
1348
1359
|
}
|
|
1349
1360
|
const queryFn = t7;
|
|
1350
|
-
const t8 = enabled &&
|
|
1361
|
+
const t8 = enabled && adapter !== null;
|
|
1351
1362
|
let t9;
|
|
1352
1363
|
if ($[14] !== queryFn || $[15] !== queryKey || $[16] !== staleTime || $[17] !== t8) {
|
|
1353
1364
|
t9 = {
|
|
@@ -1366,41 +1377,69 @@ function useDbCount(table, t0) {
|
|
|
1366
1377
|
}
|
|
1367
1378
|
const query = useQuery4(t9);
|
|
1368
1379
|
let t10;
|
|
1369
|
-
if ($[19] !== query) {
|
|
1370
|
-
t10 =
|
|
1371
|
-
|
|
1380
|
+
if ($[19] !== adapter?.name || $[20] !== query.error || $[21] !== query.isError || $[22] !== table) {
|
|
1381
|
+
t10 = () => {
|
|
1382
|
+
if (query.isError && query.error) {
|
|
1383
|
+
const adapterName = adapter?.name ?? "unknown";
|
|
1384
|
+
devWarn("useDbCount", `${table} via ${adapterName}: Error - ${query.error.message}`);
|
|
1385
|
+
}
|
|
1372
1386
|
};
|
|
1373
|
-
$[19] =
|
|
1374
|
-
$[20] =
|
|
1387
|
+
$[19] = adapter?.name;
|
|
1388
|
+
$[20] = query.error;
|
|
1389
|
+
$[21] = query.isError;
|
|
1390
|
+
$[22] = table;
|
|
1391
|
+
$[23] = t10;
|
|
1375
1392
|
} else {
|
|
1376
|
-
t10 = $[
|
|
1393
|
+
t10 = $[23];
|
|
1377
1394
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1395
|
+
let t11;
|
|
1396
|
+
if ($[24] !== adapter || $[25] !== query.error || $[26] !== query.isError || $[27] !== table) {
|
|
1397
|
+
t11 = [query.isError, query.error, table, adapter];
|
|
1398
|
+
$[24] = adapter;
|
|
1399
|
+
$[25] = query.error;
|
|
1400
|
+
$[26] = query.isError;
|
|
1401
|
+
$[27] = table;
|
|
1402
|
+
$[28] = t11;
|
|
1403
|
+
} else {
|
|
1404
|
+
t11 = $[28];
|
|
1405
|
+
}
|
|
1406
|
+
useEffect5(t10, t11);
|
|
1380
1407
|
let t12;
|
|
1381
|
-
if ($[
|
|
1382
|
-
t12 = {
|
|
1408
|
+
if ($[29] !== query) {
|
|
1409
|
+
t12 = async () => {
|
|
1410
|
+
await query.refetch();
|
|
1411
|
+
};
|
|
1412
|
+
$[29] = query;
|
|
1413
|
+
$[30] = t12;
|
|
1414
|
+
} else {
|
|
1415
|
+
t12 = $[30];
|
|
1416
|
+
}
|
|
1417
|
+
const refetch = t12;
|
|
1418
|
+
const t13 = query.error;
|
|
1419
|
+
let t14;
|
|
1420
|
+
if ($[31] !== query.data || $[32] !== query.isFetching || $[33] !== query.isLoading || $[34] !== refetch || $[35] !== t13) {
|
|
1421
|
+
t14 = {
|
|
1383
1422
|
count: query.data,
|
|
1384
1423
|
isLoading: query.isLoading,
|
|
1385
1424
|
isFetching: query.isFetching,
|
|
1386
|
-
error:
|
|
1425
|
+
error: t13,
|
|
1387
1426
|
refetch
|
|
1388
1427
|
};
|
|
1389
|
-
$[
|
|
1390
|
-
$[
|
|
1391
|
-
$[
|
|
1392
|
-
$[
|
|
1393
|
-
$[
|
|
1394
|
-
$[
|
|
1428
|
+
$[31] = query.data;
|
|
1429
|
+
$[32] = query.isFetching;
|
|
1430
|
+
$[33] = query.isLoading;
|
|
1431
|
+
$[34] = refetch;
|
|
1432
|
+
$[35] = t13;
|
|
1433
|
+
$[36] = t14;
|
|
1395
1434
|
} else {
|
|
1396
|
-
|
|
1435
|
+
t14 = $[36];
|
|
1397
1436
|
}
|
|
1398
|
-
return
|
|
1437
|
+
return t14;
|
|
1399
1438
|
}
|
|
1400
1439
|
|
|
1401
1440
|
// src/hooks/useSyncStatus.ts
|
|
1402
1441
|
import { c as _c6 } from "react/compiler-runtime";
|
|
1403
|
-
import { useState as useState2, useEffect as
|
|
1442
|
+
import { useState as useState2, useEffect as useEffect6, useContext as useContext2 } from "react";
|
|
1404
1443
|
var defaultSyncStatus = {
|
|
1405
1444
|
isConnected: true,
|
|
1406
1445
|
// Supabase-only mode is always "connected" when online
|
|
@@ -1448,7 +1487,7 @@ function useSyncStatus() {
|
|
|
1448
1487
|
t0 = $[4];
|
|
1449
1488
|
t1 = $[5];
|
|
1450
1489
|
}
|
|
1451
|
-
|
|
1490
|
+
useEffect6(t0, t1);
|
|
1452
1491
|
return currentStatus;
|
|
1453
1492
|
}
|
|
1454
1493
|
|
|
@@ -1674,4 +1713,4 @@ export {
|
|
|
1674
1713
|
useSyncControl,
|
|
1675
1714
|
useOnlineStatus
|
|
1676
1715
|
};
|
|
1677
|
-
//# sourceMappingURL=chunk-
|
|
1716
|
+
//# sourceMappingURL=chunk-EKUDGIQZ.js.map
|