@pol-studios/db 1.0.21 → 1.0.23
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/auth/context.js +2 -2
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-R5B2XMN5.js → chunk-3L4HOEXV.js} +1614 -2141
- package/dist/chunk-3L4HOEXV.js.map +1 -0
- package/dist/{chunk-72WV3ALS.js → chunk-3UYBZHEV.js} +2 -2
- package/dist/{chunk-X3HZLNBV.js → chunk-BXSOHOQ2.js} +54 -985
- package/dist/chunk-BXSOHOQ2.js.map +1 -0
- package/dist/{chunk-N26IEHZT.js → chunk-FZF26ZRB.js} +18 -2
- package/dist/{chunk-N26IEHZT.js.map → chunk-FZF26ZRB.js.map} +1 -1
- package/dist/chunk-HTJ2FQW5.js +963 -0
- package/dist/chunk-HTJ2FQW5.js.map +1 -0
- package/dist/{chunk-2T6WTCP4.js → chunk-KDORWXGS.js} +69 -154
- package/dist/chunk-KDORWXGS.js.map +1 -0
- package/dist/{chunk-36DVUMQD.js → chunk-MBU4KE3V.js} +2 -2
- package/dist/{chunk-YERWPV6B.js → chunk-Q7WJEOQ5.js} +150 -19
- package/dist/chunk-Q7WJEOQ5.js.map +1 -0
- package/dist/{chunk-RMRYGICS.js → chunk-TSXQTYUG.js} +4 -4
- package/dist/core/index.d.ts +30 -1
- package/dist/hooks/index.d.ts +20 -1
- package/dist/hooks/index.js +1 -1
- package/dist/{index-BNKhgDdC.d.ts → index-2YySlz7X.d.ts} +3 -3
- package/dist/index.d.ts +11 -12
- package/dist/index.js +14 -95
- package/dist/index.native.d.ts +12 -30
- package/dist/index.native.js +17 -96
- package/dist/index.web.d.ts +132 -15
- package/dist/index.web.js +585 -46
- package/dist/index.web.js.map +1 -1
- package/dist/powersync-bridge/index.d.ts +1 -1
- package/dist/powersync-bridge/index.js +1 -1
- package/dist/query/index.js +10 -8
- package/dist/types/index.d.ts +1 -1
- package/dist/{useDbCount-Id14x_1P.d.ts → useDbCount-s-aR9YeV.d.ts} +1 -1
- package/dist/{useResolveFeedback-Ca2rh_Bs.d.ts → useResolveFeedback-DTGcHpCs.d.ts} +275 -390
- package/dist/with-auth/index.js +4 -4
- package/package.json +13 -12
- package/dist/chunk-2T6WTCP4.js.map +0 -1
- package/dist/chunk-R5B2XMN5.js.map +0 -1
- package/dist/chunk-X3HZLNBV.js.map +0 -1
- package/dist/chunk-YERWPV6B.js.map +0 -1
- /package/dist/{chunk-72WV3ALS.js.map → chunk-3UYBZHEV.js.map} +0 -0
- /package/dist/{chunk-36DVUMQD.js.map → chunk-MBU4KE3V.js.map} +0 -0
- /package/dist/{chunk-RMRYGICS.js.map → chunk-TSXQTYUG.js.map} +0 -0
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getSupabaseUrl
|
|
3
|
-
} from "./chunk-GC3TBUWE.js";
|
|
4
|
-
import {
|
|
5
|
-
PostgrestParser
|
|
6
|
-
} from "./chunk-TKWR5AAY.js";
|
|
7
|
-
import {
|
|
8
|
-
isNullOrWhitespace,
|
|
9
|
-
isUsable,
|
|
10
|
-
omit
|
|
11
|
-
} from "./chunk-OQ7U6EQ3.js";
|
|
12
|
-
import {
|
|
13
|
-
encode,
|
|
14
|
-
useQuery
|
|
15
|
-
} from "./chunk-H6365JPC.js";
|
|
16
|
-
import {
|
|
17
|
-
generateUUID,
|
|
18
|
-
useSupabase
|
|
19
|
-
} from "./chunk-5EFDS7SR.js";
|
|
20
|
-
|
|
21
1
|
// src/query/select-parser.ts
|
|
22
2
|
function tokenizeTopLevel(input) {
|
|
23
3
|
const tokens = [];
|
|
@@ -690,14 +670,17 @@ var ResultJoiner = class {
|
|
|
690
670
|
return baseRecords;
|
|
691
671
|
}
|
|
692
672
|
if (relationship.type === "one-to-many") {
|
|
693
|
-
|
|
673
|
+
const groupedByFK = /* @__PURE__ */ new Map();
|
|
674
|
+
for (const r of relatedRecords) {
|
|
675
|
+
const fkValue = r[relationship.foreignKey];
|
|
676
|
+
if (!groupedByFK.has(fkValue)) groupedByFK.set(fkValue, []);
|
|
677
|
+
groupedByFK.get(fkValue).push(r);
|
|
678
|
+
}
|
|
679
|
+
for (const base of baseRecords) {
|
|
694
680
|
const baseId = base[relationship.referencedColumn];
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
[relationName]: related
|
|
699
|
-
};
|
|
700
|
-
});
|
|
681
|
+
base[relationName] = groupedByFK.get(baseId) ?? [];
|
|
682
|
+
}
|
|
683
|
+
return baseRecords;
|
|
701
684
|
} else {
|
|
702
685
|
const relatedMap = /* @__PURE__ */ new Map();
|
|
703
686
|
for (const r of relatedRecords) {
|
|
@@ -706,14 +689,11 @@ var ResultJoiner = class {
|
|
|
706
689
|
relatedMap.set(refValue, r);
|
|
707
690
|
}
|
|
708
691
|
}
|
|
709
|
-
|
|
692
|
+
for (const base of baseRecords) {
|
|
710
693
|
const fkValue = base[relationship.foreignKey];
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
[relationName]: related
|
|
715
|
-
};
|
|
716
|
-
});
|
|
694
|
+
base[relationName] = fkValue != null ? relatedMap.get(fkValue) ?? null : null;
|
|
695
|
+
}
|
|
696
|
+
return baseRecords;
|
|
717
697
|
}
|
|
718
698
|
}
|
|
719
699
|
/**
|
|
@@ -1102,27 +1082,56 @@ var QueryExecutor = class {
|
|
|
1102
1082
|
* @returns Parent records with relations attached
|
|
1103
1083
|
*/
|
|
1104
1084
|
async queryAndJoinRelations(parentTable, parentRecords, relations) {
|
|
1105
|
-
|
|
1106
|
-
for (const relation of relations) {
|
|
1085
|
+
const relationResults = await Promise.all(relations.map(async (relation) => {
|
|
1107
1086
|
const resolved = this.resolver.resolve(parentTable, relation.name);
|
|
1108
1087
|
if (!resolved) {
|
|
1109
1088
|
console.warn(`Could not resolve relationship: ${parentTable} -> ${relation.name}`);
|
|
1110
|
-
|
|
1089
|
+
return {
|
|
1090
|
+
relation,
|
|
1091
|
+
resolved: null,
|
|
1092
|
+
records: []
|
|
1093
|
+
};
|
|
1111
1094
|
}
|
|
1112
1095
|
const parentIds = this.getParentIdsForRelation(parentRecords, resolved);
|
|
1113
1096
|
if (parentIds.length === 0) {
|
|
1097
|
+
return {
|
|
1098
|
+
relation,
|
|
1099
|
+
resolved,
|
|
1100
|
+
records: []
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const relQuery = this.buildRelatedQuery(relation, resolved, parentIds);
|
|
1104
|
+
let records = await this.db.getAll(relQuery.sql, relQuery.params);
|
|
1105
|
+
if (relation.relations.length > 0 && records.length > 0) {
|
|
1106
|
+
records = await this.queryAndJoinRelations(relation.name, records, relation.relations);
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
relation,
|
|
1110
|
+
resolved,
|
|
1111
|
+
records
|
|
1112
|
+
};
|
|
1113
|
+
}));
|
|
1114
|
+
let result = [...parentRecords];
|
|
1115
|
+
for (const {
|
|
1116
|
+
relation,
|
|
1117
|
+
resolved,
|
|
1118
|
+
records
|
|
1119
|
+
} of relationResults) {
|
|
1120
|
+
if (!resolved) {
|
|
1114
1121
|
result = result.map((r) => ({
|
|
1115
1122
|
...r,
|
|
1116
|
-
[relation.alias ?? relation.name]:
|
|
1123
|
+
[relation.alias ?? relation.name]: null
|
|
1117
1124
|
}));
|
|
1118
1125
|
continue;
|
|
1119
1126
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1127
|
+
if (records.length === 0) {
|
|
1128
|
+
result = result.map((r) => ({
|
|
1129
|
+
...r,
|
|
1130
|
+
[relation.alias ?? relation.name]: resolved.type === "one-to-many" ? [] : null
|
|
1131
|
+
}));
|
|
1132
|
+
continue;
|
|
1124
1133
|
}
|
|
1125
|
-
result = this.joiner.join(result,
|
|
1134
|
+
result = this.joiner.join(result, records, resolved, relation.alias ?? relation.name);
|
|
1126
1135
|
}
|
|
1127
1136
|
return result;
|
|
1128
1137
|
}
|
|
@@ -1169,940 +1178,6 @@ function createQueryExecutor(db, schema) {
|
|
|
1169
1178
|
return new QueryExecutor(db, schema);
|
|
1170
1179
|
}
|
|
1171
1180
|
|
|
1172
|
-
// src/query/useQuery.ts
|
|
1173
|
-
import { c as _c } from "react/compiler-runtime";
|
|
1174
|
-
import { useDelayedValue } from "@pol-studios/hooks/state";
|
|
1175
|
-
function useQuery2(query, config) {
|
|
1176
|
-
const $ = _c(5);
|
|
1177
|
-
let t0;
|
|
1178
|
-
if ($[0] !== query) {
|
|
1179
|
-
const queryKey = encode(query, false);
|
|
1180
|
-
t0 = queryKey.join("-");
|
|
1181
|
-
$[0] = query;
|
|
1182
|
-
$[1] = t0;
|
|
1183
|
-
} else {
|
|
1184
|
-
t0 = $[1];
|
|
1185
|
-
}
|
|
1186
|
-
const queryKeyString = t0;
|
|
1187
|
-
const debouncedKeyString = useDelayedValue(queryKeyString, 50);
|
|
1188
|
-
const isKeyStable = queryKeyString === debouncedKeyString;
|
|
1189
|
-
const effectiveEnabled = config?.enabled !== false && isKeyStable;
|
|
1190
|
-
let t1;
|
|
1191
|
-
if ($[2] !== config || $[3] !== effectiveEnabled) {
|
|
1192
|
-
t1 = omit({
|
|
1193
|
-
retry: 1,
|
|
1194
|
-
...config,
|
|
1195
|
-
enabled: effectiveEnabled
|
|
1196
|
-
}, ["queryKey"]);
|
|
1197
|
-
$[2] = config;
|
|
1198
|
-
$[3] = effectiveEnabled;
|
|
1199
|
-
$[4] = t1;
|
|
1200
|
-
} else {
|
|
1201
|
-
t1 = $[4];
|
|
1202
|
-
}
|
|
1203
|
-
const request = useQuery(query, t1);
|
|
1204
|
-
return request;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
// src/query/usePartialQuery.ts
|
|
1208
|
-
import { c as _c2 } from "react/compiler-runtime";
|
|
1209
|
-
import { useSessionStorageState } from "@pol-studios/hooks/storage";
|
|
1210
|
-
function usePartialQuery(query, itemCountPerPage, config) {
|
|
1211
|
-
const $ = _c2(28);
|
|
1212
|
-
let t0;
|
|
1213
|
-
if ($[0] !== query) {
|
|
1214
|
-
t0 = encode(query, false);
|
|
1215
|
-
$[0] = query;
|
|
1216
|
-
$[1] = t0;
|
|
1217
|
-
} else {
|
|
1218
|
-
t0 = $[1];
|
|
1219
|
-
}
|
|
1220
|
-
const initialQuery = t0;
|
|
1221
|
-
let t1;
|
|
1222
|
-
if ($[2] !== initialQuery[7] || $[3] !== initialQuery[8]) {
|
|
1223
|
-
t1 = [initialQuery[7], initialQuery[8]];
|
|
1224
|
-
$[2] = initialQuery[7];
|
|
1225
|
-
$[3] = initialQuery[8];
|
|
1226
|
-
$[4] = t1;
|
|
1227
|
-
} else {
|
|
1228
|
-
t1 = $[4];
|
|
1229
|
-
}
|
|
1230
|
-
const id = t1.join("-");
|
|
1231
|
-
const [currentPage, setCurrentPage] = useSessionStorageState(id, 1);
|
|
1232
|
-
const page = currentPage ?? 1;
|
|
1233
|
-
const t2 = query;
|
|
1234
|
-
let t3;
|
|
1235
|
-
if ($[5] !== itemCountPerPage || $[6] !== page || $[7] !== t2) {
|
|
1236
|
-
t3 = t2.range((page - 1) * itemCountPerPage, page * itemCountPerPage - 1);
|
|
1237
|
-
$[5] = itemCountPerPage;
|
|
1238
|
-
$[6] = page;
|
|
1239
|
-
$[7] = t2;
|
|
1240
|
-
$[8] = t3;
|
|
1241
|
-
} else {
|
|
1242
|
-
t3 = $[8];
|
|
1243
|
-
}
|
|
1244
|
-
const rangedQuery = t3;
|
|
1245
|
-
const baseQuery = useQuery2(rangedQuery, config);
|
|
1246
|
-
let t4;
|
|
1247
|
-
if ($[9] !== setCurrentPage) {
|
|
1248
|
-
t4 = () => {
|
|
1249
|
-
setCurrentPage(_temp);
|
|
1250
|
-
};
|
|
1251
|
-
$[9] = setCurrentPage;
|
|
1252
|
-
$[10] = t4;
|
|
1253
|
-
} else {
|
|
1254
|
-
t4 = $[10];
|
|
1255
|
-
}
|
|
1256
|
-
const safeFetchNextPage = t4;
|
|
1257
|
-
let t5;
|
|
1258
|
-
if ($[11] !== setCurrentPage) {
|
|
1259
|
-
t5 = () => {
|
|
1260
|
-
setCurrentPage(_temp2);
|
|
1261
|
-
};
|
|
1262
|
-
$[11] = setCurrentPage;
|
|
1263
|
-
$[12] = t5;
|
|
1264
|
-
} else {
|
|
1265
|
-
t5 = $[12];
|
|
1266
|
-
}
|
|
1267
|
-
const fetchPreviousPage = t5;
|
|
1268
|
-
const pageCount = Math.max(Math.ceil((baseQuery.count ?? 0) / itemCountPerPage), 1);
|
|
1269
|
-
let t6;
|
|
1270
|
-
if ($[13] !== baseQuery.count || $[14] !== baseQuery.data || $[15] !== currentPage || $[16] !== itemCountPerPage) {
|
|
1271
|
-
t6 = baseQuery.data ? toPagedResponse(baseQuery.data, currentPage, baseQuery.count ?? baseQuery.data.length, itemCountPerPage) : null;
|
|
1272
|
-
$[13] = baseQuery.count;
|
|
1273
|
-
$[14] = baseQuery.data;
|
|
1274
|
-
$[15] = currentPage;
|
|
1275
|
-
$[16] = itemCountPerPage;
|
|
1276
|
-
$[17] = t6;
|
|
1277
|
-
} else {
|
|
1278
|
-
t6 = $[17];
|
|
1279
|
-
}
|
|
1280
|
-
const t7 = currentPage < pageCount;
|
|
1281
|
-
const t8 = currentPage > 1;
|
|
1282
|
-
let t9;
|
|
1283
|
-
if ($[18] !== baseQuery || $[19] !== currentPage || $[20] !== fetchPreviousPage || $[21] !== pageCount || $[22] !== safeFetchNextPage || $[23] !== setCurrentPage || $[24] !== t6 || $[25] !== t7 || $[26] !== t8) {
|
|
1284
|
-
t9 = {
|
|
1285
|
-
...baseQuery,
|
|
1286
|
-
fetchPreviousPage,
|
|
1287
|
-
fetchNextPage: safeFetchNextPage,
|
|
1288
|
-
currentPage,
|
|
1289
|
-
setCurrentPage,
|
|
1290
|
-
data: t6,
|
|
1291
|
-
pageCount,
|
|
1292
|
-
hasNextPage: t7,
|
|
1293
|
-
hasPreviousPage: t8
|
|
1294
|
-
};
|
|
1295
|
-
$[18] = baseQuery;
|
|
1296
|
-
$[19] = currentPage;
|
|
1297
|
-
$[20] = fetchPreviousPage;
|
|
1298
|
-
$[21] = pageCount;
|
|
1299
|
-
$[22] = safeFetchNextPage;
|
|
1300
|
-
$[23] = setCurrentPage;
|
|
1301
|
-
$[24] = t6;
|
|
1302
|
-
$[25] = t7;
|
|
1303
|
-
$[26] = t8;
|
|
1304
|
-
$[27] = t9;
|
|
1305
|
-
} else {
|
|
1306
|
-
t9 = $[27];
|
|
1307
|
-
}
|
|
1308
|
-
return t9;
|
|
1309
|
-
}
|
|
1310
|
-
function _temp2(currentPage_1) {
|
|
1311
|
-
return currentPage_1 - 1;
|
|
1312
|
-
}
|
|
1313
|
-
function _temp(currentPage_0) {
|
|
1314
|
-
return currentPage_0 + 1;
|
|
1315
|
-
}
|
|
1316
|
-
function toPagedResponse(results, currentPage, totalCount, itemPerPage) {
|
|
1317
|
-
const newPage = {
|
|
1318
|
-
Items: results,
|
|
1319
|
-
CurrentPage: currentPage,
|
|
1320
|
-
ItemCount: totalCount,
|
|
1321
|
-
MaxCountPerPage: itemPerPage,
|
|
1322
|
-
PageCount: Math.max(Math.ceil(totalCount / itemPerPage), 1)
|
|
1323
|
-
};
|
|
1324
|
-
return newPage;
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
// src/query/useAdvancedQuery.ts
|
|
1328
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
1329
|
-
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
1330
|
-
import { useSessionStorageState as useSessionStorageState2 } from "@pol-studios/hooks/storage";
|
|
1331
|
-
var normalizeFilter = (filter) => {
|
|
1332
|
-
const groupOp = filter.op || filter.operator;
|
|
1333
|
-
if (groupOp && (groupOp === "AND" || groupOp === "OR") && filter.filters) {
|
|
1334
|
-
return {
|
|
1335
|
-
id: filter.id || generateUUID(),
|
|
1336
|
-
op: groupOp,
|
|
1337
|
-
not: filter.not || filter.inverted,
|
|
1338
|
-
// Support both 'not' and legacy 'inverted' for groups
|
|
1339
|
-
filters: filter.filters.map(normalizeFilter).filter(Boolean)
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
let operator = filter.op || filter.condition;
|
|
1343
|
-
let shouldNegate = filter.not || filter.inverted || false;
|
|
1344
|
-
if (operator === "\u220B") operator = "in";
|
|
1345
|
-
if (operator === "\u2260" || operator === "!=") {
|
|
1346
|
-
operator = "=";
|
|
1347
|
-
shouldNegate = true;
|
|
1348
|
-
}
|
|
1349
|
-
if (operator === "like") operator = "contains";
|
|
1350
|
-
if (operator === "regex" || operator === "regex_i" || operator === "similar_to") {
|
|
1351
|
-
operator = "contains";
|
|
1352
|
-
}
|
|
1353
|
-
if (!operator) {
|
|
1354
|
-
console.error("Filter has undefined operator:", JSON.stringify(filter, null, 2));
|
|
1355
|
-
return null;
|
|
1356
|
-
}
|
|
1357
|
-
if (filter.propertyName) {
|
|
1358
|
-
return {
|
|
1359
|
-
id: filter.id || generateUUID(),
|
|
1360
|
-
field: filter.propertyName,
|
|
1361
|
-
op: operator,
|
|
1362
|
-
value: filter.value,
|
|
1363
|
-
not: shouldNegate,
|
|
1364
|
-
display: filter.display || filter.propertyName
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1367
|
-
return {
|
|
1368
|
-
id: filter.id || generateUUID(),
|
|
1369
|
-
field: filter.field || "",
|
|
1370
|
-
op: operator,
|
|
1371
|
-
value: filter.value,
|
|
1372
|
-
not: shouldNegate,
|
|
1373
|
-
similarity: filter.similarity,
|
|
1374
|
-
where: filter.where,
|
|
1375
|
-
display: filter.display || filter.field || ""
|
|
1376
|
-
};
|
|
1377
|
-
};
|
|
1378
|
-
function useAdvancedFilterQuery(query, config) {
|
|
1379
|
-
const filterKey = useMemo(() => config?.filterKey ?? window.location?.pathname, [config?.filterKey]);
|
|
1380
|
-
const [filterLayer, setFilterLayer] = useSessionStorageState2(filterKey, {
|
|
1381
|
-
id: "root",
|
|
1382
|
-
op: "AND",
|
|
1383
|
-
filters: [],
|
|
1384
|
-
pagination: void 0,
|
|
1385
|
-
sort: [],
|
|
1386
|
-
isReady: isUsable(config?.searchByDefault) ? config.searchByDefault ? false : true : true
|
|
1387
|
-
});
|
|
1388
|
-
const parser = useMemo(() => new PostgrestParser(query), [query, config?.key]);
|
|
1389
|
-
useEffect(() => {
|
|
1390
|
-
const searchParam = parser.searchParams.get("order");
|
|
1391
|
-
if (searchParam) {
|
|
1392
|
-
const orderColumns = searchParam.split(",");
|
|
1393
|
-
const orders = [];
|
|
1394
|
-
orderColumns.forEach((x) => {
|
|
1395
|
-
const values = x.split(".");
|
|
1396
|
-
orders.push({
|
|
1397
|
-
field: values[0],
|
|
1398
|
-
direction: values[1] === "asc" ? "asc" : "desc"
|
|
1399
|
-
});
|
|
1400
|
-
});
|
|
1401
|
-
setFilterLayer((pre) => {
|
|
1402
|
-
if (!pre) {
|
|
1403
|
-
return {
|
|
1404
|
-
id: "root",
|
|
1405
|
-
op: "AND",
|
|
1406
|
-
filters: [],
|
|
1407
|
-
isReady: true,
|
|
1408
|
-
sort: orders
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
return {
|
|
1412
|
-
...pre,
|
|
1413
|
-
id: pre.id || "root",
|
|
1414
|
-
op: pre.op || "AND",
|
|
1415
|
-
filters: pre.filters || [],
|
|
1416
|
-
isReady: pre.isReady ?? true,
|
|
1417
|
-
sort: [...(pre.sort || []).filter((old) => orders.some((o) => o.field === old.field) === false), ...orders]
|
|
1418
|
-
};
|
|
1419
|
-
});
|
|
1420
|
-
}
|
|
1421
|
-
}, [JSON.stringify(parser.searchParams), config?.key]);
|
|
1422
|
-
const encodedQueryKeyRef = useRef([]);
|
|
1423
|
-
const encodedQueryKey = useMemo(() => {
|
|
1424
|
-
const newEncoded = encode(query, false);
|
|
1425
|
-
const newEncodedString = JSON.stringify(newEncoded);
|
|
1426
|
-
const oldEncodedString = JSON.stringify(encodedQueryKeyRef.current);
|
|
1427
|
-
if (newEncodedString !== oldEncodedString) {
|
|
1428
|
-
encodedQueryKeyRef.current = newEncoded;
|
|
1429
|
-
}
|
|
1430
|
-
return encodedQueryKeyRef.current;
|
|
1431
|
-
}, [query, parser.offset, parser.limit]);
|
|
1432
|
-
const filterLayerStringRef = useRef("");
|
|
1433
|
-
const currentFilterString = JSON.stringify(filterLayer, (key, value) => key === "id" ? "redacted" : value);
|
|
1434
|
-
if (filterLayerStringRef.current !== currentFilterString) {
|
|
1435
|
-
filterLayerStringRef.current = currentFilterString;
|
|
1436
|
-
}
|
|
1437
|
-
const queryKeyRef = useRef([]);
|
|
1438
|
-
const newKey = [encodedQueryKey[0], encodedQueryKey[1], encodedQueryKey[2], encodedQueryKey[3], encodedQueryKey[4], encodedQueryKey[5], "count=" + (config?.count ?? ""), encodedQueryKey[7], encodedQueryKey[8], filterLayerStringRef.current];
|
|
1439
|
-
const newKeyString = JSON.stringify(newKey);
|
|
1440
|
-
const oldKeyString = JSON.stringify(queryKeyRef.current);
|
|
1441
|
-
if (oldKeyString !== newKeyString) {
|
|
1442
|
-
queryKeyRef.current = newKey;
|
|
1443
|
-
}
|
|
1444
|
-
const queryKey = queryKeyRef.current;
|
|
1445
|
-
const [previousKey, setPreviousKey] = useState(queryKey);
|
|
1446
|
-
useEffect(() => {
|
|
1447
|
-
if (filterLayer?.isReady) {
|
|
1448
|
-
setPreviousKey(queryKey);
|
|
1449
|
-
}
|
|
1450
|
-
}, [...queryKey]);
|
|
1451
|
-
const loadingKey = filterLayer?.isReady ? queryKey : previousKey ?? queryKey;
|
|
1452
|
-
const supabase = useSupabase();
|
|
1453
|
-
const isEnabled = config?.enabled == null || config?.enabled === void 0 ? true : config.enabled;
|
|
1454
|
-
const [extraData, setExtraData] = useState({});
|
|
1455
|
-
const queryResponse = useQuery3({
|
|
1456
|
-
...omit({
|
|
1457
|
-
retry: 0,
|
|
1458
|
-
// Changed from 1 to 0 to prevent retries
|
|
1459
|
-
...config ?? {},
|
|
1460
|
-
// Override any config settings to prevent multiple executions
|
|
1461
|
-
refetchOnMount: false,
|
|
1462
|
-
refetchOnWindowFocus: false,
|
|
1463
|
-
refetchOnReconnect: false,
|
|
1464
|
-
structuralSharing: false,
|
|
1465
|
-
enabled: filterLayer?.isReady && isEnabled
|
|
1466
|
-
}, ["queryKey", "persister", "initialData"]),
|
|
1467
|
-
queryKey: loadingKey,
|
|
1468
|
-
queryFn: async (props) => {
|
|
1469
|
-
if (!filterLayer) {
|
|
1470
|
-
throw new Error("Filter layer is not initialized");
|
|
1471
|
-
}
|
|
1472
|
-
try {
|
|
1473
|
-
const searchParams = Array.from(parser.searchParams.entries());
|
|
1474
|
-
const body = {
|
|
1475
|
-
...filterLayer,
|
|
1476
|
-
filters: [...filterLayer.filters],
|
|
1477
|
-
pagination: {
|
|
1478
|
-
...filterLayer.pagination
|
|
1479
|
-
},
|
|
1480
|
-
sort: [...filterLayer.sort || []]
|
|
1481
|
-
};
|
|
1482
|
-
const currentKey = `${parser.schema}${parser.table}${parser.select}${JSON.stringify(omit(body, "pagination"))}`;
|
|
1483
|
-
const requiresEdgeForOrdering = false;
|
|
1484
|
-
const hasNaturalLanguageQuery = !!filterLayer.naturalLanguageQuery;
|
|
1485
|
-
if (filterLayer.filters.length == 0 && requiresEdgeForOrdering === false && !hasNaturalLanguageQuery) {
|
|
1486
|
-
const result = await executeSupabaseQuery(supabase, body, parser, extraData, props.signal, config?.count);
|
|
1487
|
-
setExtraData((pre_0) => ({
|
|
1488
|
-
...omit(result, "data"),
|
|
1489
|
-
count: result.count ? result.count : pre_0.count,
|
|
1490
|
-
key: currentKey
|
|
1491
|
-
}));
|
|
1492
|
-
return result;
|
|
1493
|
-
}
|
|
1494
|
-
searchParams.forEach(([k, v]) => {
|
|
1495
|
-
if (k.includes("offset")) {
|
|
1496
|
-
body.pagination.offset = Number(v);
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
if (k.includes("limit")) {
|
|
1500
|
-
body.pagination.limit = Number(v);
|
|
1501
|
-
return;
|
|
1502
|
-
}
|
|
1503
|
-
if (k.includes("order")) {
|
|
1504
|
-
return;
|
|
1505
|
-
}
|
|
1506
|
-
if (k === "or") {
|
|
1507
|
-
return;
|
|
1508
|
-
}
|
|
1509
|
-
if (v.includes(".") === false) return;
|
|
1510
|
-
const values_0 = v.split(".");
|
|
1511
|
-
const column = k;
|
|
1512
|
-
let rawCondition = values_0[0];
|
|
1513
|
-
let condition = "";
|
|
1514
|
-
let value_0 = values_0[1];
|
|
1515
|
-
const inverted = values_0[0] === "not";
|
|
1516
|
-
if (column == "select") return;
|
|
1517
|
-
if (rawCondition === "not") {
|
|
1518
|
-
rawCondition = values_0[1];
|
|
1519
|
-
value_0 = values_0[2];
|
|
1520
|
-
}
|
|
1521
|
-
switch (rawCondition) {
|
|
1522
|
-
case "eq":
|
|
1523
|
-
condition = "=";
|
|
1524
|
-
break;
|
|
1525
|
-
case "in":
|
|
1526
|
-
condition = "in";
|
|
1527
|
-
value_0 = value_0.slice(1, value_0.length - 1).split(",").filter((x_0) => isNullOrWhitespace(x_0) === false);
|
|
1528
|
-
break;
|
|
1529
|
-
case "lt":
|
|
1530
|
-
condition = "<";
|
|
1531
|
-
break;
|
|
1532
|
-
case "gt":
|
|
1533
|
-
condition = ">";
|
|
1534
|
-
break;
|
|
1535
|
-
case "lte":
|
|
1536
|
-
condition = "<=";
|
|
1537
|
-
break;
|
|
1538
|
-
case "gte":
|
|
1539
|
-
condition = ">=";
|
|
1540
|
-
break;
|
|
1541
|
-
case "is":
|
|
1542
|
-
condition = "is";
|
|
1543
|
-
if (value_0 == "null") {
|
|
1544
|
-
value_0 = null;
|
|
1545
|
-
}
|
|
1546
|
-
break;
|
|
1547
|
-
}
|
|
1548
|
-
body.filters = [{
|
|
1549
|
-
id: `filter_${column}_${Date.now()}`,
|
|
1550
|
-
field: column,
|
|
1551
|
-
op: condition,
|
|
1552
|
-
value: value_0,
|
|
1553
|
-
not: inverted,
|
|
1554
|
-
display: column
|
|
1555
|
-
}, {
|
|
1556
|
-
filters: [...body.filters],
|
|
1557
|
-
op: body.op ?? "AND",
|
|
1558
|
-
id: "filterstate"
|
|
1559
|
-
}];
|
|
1560
|
-
body.op = "AND";
|
|
1561
|
-
const bodyCopy = JSON.parse(JSON.stringify(body));
|
|
1562
|
-
bodyCopy.pagination = {
|
|
1563
|
-
page: 0,
|
|
1564
|
-
pageSize: 50
|
|
1565
|
-
};
|
|
1566
|
-
bodyCopy.isReady = true;
|
|
1567
|
-
});
|
|
1568
|
-
const {
|
|
1569
|
-
data: {
|
|
1570
|
-
session
|
|
1571
|
-
}
|
|
1572
|
-
} = await supabase.auth.getSession();
|
|
1573
|
-
if (!session?.access_token) {
|
|
1574
|
-
throw new Error("No active session");
|
|
1575
|
-
}
|
|
1576
|
-
const controller = new AbortController();
|
|
1577
|
-
props.signal.addEventListener("abort", () => {
|
|
1578
|
-
controller.abort();
|
|
1579
|
-
});
|
|
1580
|
-
const timeout = setTimeout(() => controller.abort(), config?.timeout ?? 15e3);
|
|
1581
|
-
let result_0 = null;
|
|
1582
|
-
let response = {
|
|
1583
|
-
error: null,
|
|
1584
|
-
data: null
|
|
1585
|
-
};
|
|
1586
|
-
try {
|
|
1587
|
-
const UI_ONLY_KEYS = /* @__PURE__ */ new Set(["info", "options", "display"]);
|
|
1588
|
-
const filteredBody = JSON.parse(JSON.stringify(body, (key_0, value_1) => {
|
|
1589
|
-
if (UI_ONLY_KEYS.has(key_0)) {
|
|
1590
|
-
return void 0;
|
|
1591
|
-
}
|
|
1592
|
-
return value_1;
|
|
1593
|
-
}));
|
|
1594
|
-
filteredBody.filters = filteredBody.filters.map(normalizeFilter).filter(Boolean);
|
|
1595
|
-
const orParam = parser.searchParams.get("or");
|
|
1596
|
-
if (orParam) {
|
|
1597
|
-
const cleanedOrParam = orParam.replace(/^\(|\)$/g, "");
|
|
1598
|
-
const orConditions = cleanedOrParam.split(",");
|
|
1599
|
-
const orFilters = orConditions.map((condition_0, idx) => {
|
|
1600
|
-
const match = condition_0.match(/^(.+?)\.([^.]+)\.(.+)$/);
|
|
1601
|
-
if (match) {
|
|
1602
|
-
const [_, field, rawOp, value_2] = match;
|
|
1603
|
-
let op = rawOp.trim();
|
|
1604
|
-
switch (op) {
|
|
1605
|
-
case "eq":
|
|
1606
|
-
op = "=";
|
|
1607
|
-
break;
|
|
1608
|
-
case "neq":
|
|
1609
|
-
op = "!=";
|
|
1610
|
-
break;
|
|
1611
|
-
case "gt":
|
|
1612
|
-
op = ">";
|
|
1613
|
-
break;
|
|
1614
|
-
case "gte":
|
|
1615
|
-
op = ">=";
|
|
1616
|
-
break;
|
|
1617
|
-
case "lt":
|
|
1618
|
-
op = "<";
|
|
1619
|
-
break;
|
|
1620
|
-
case "lte":
|
|
1621
|
-
op = "<=";
|
|
1622
|
-
break;
|
|
1623
|
-
case "like":
|
|
1624
|
-
op = "contains";
|
|
1625
|
-
break;
|
|
1626
|
-
case "ilike":
|
|
1627
|
-
op = "contains";
|
|
1628
|
-
break;
|
|
1629
|
-
case "in":
|
|
1630
|
-
op = "in";
|
|
1631
|
-
break;
|
|
1632
|
-
}
|
|
1633
|
-
return {
|
|
1634
|
-
id: `or-${idx}`,
|
|
1635
|
-
field: field.trim(),
|
|
1636
|
-
op,
|
|
1637
|
-
value: value_2.trim()
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
return null;
|
|
1641
|
-
}).filter(Boolean);
|
|
1642
|
-
if (orFilters.length > 0) {
|
|
1643
|
-
filteredBody.filters = [...filteredBody.filters, {
|
|
1644
|
-
id: "base-or-group",
|
|
1645
|
-
op: "OR",
|
|
1646
|
-
filters: orFilters,
|
|
1647
|
-
pagination: void 0,
|
|
1648
|
-
sort: void 0,
|
|
1649
|
-
isReady: true
|
|
1650
|
-
}];
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
const res = await fetch(`${getSupabaseUrl()}/functions/v1/query?forceDenoVersion=2`, {
|
|
1654
|
-
method: "POST",
|
|
1655
|
-
headers: {
|
|
1656
|
-
"Content-Type": "application/json",
|
|
1657
|
-
"Authorization": `Bearer ${session.access_token}`
|
|
1658
|
-
},
|
|
1659
|
-
body: JSON.stringify({
|
|
1660
|
-
table: parser.table,
|
|
1661
|
-
schema: parser.schema,
|
|
1662
|
-
select: parser.select,
|
|
1663
|
-
filters: {
|
|
1664
|
-
id: filteredBody.id || "root",
|
|
1665
|
-
op: filteredBody.op || filteredBody.operator || "AND",
|
|
1666
|
-
not: filteredBody.not || filteredBody.inverted,
|
|
1667
|
-
// Support both 'not' and legacy 'inverted'
|
|
1668
|
-
filters: filteredBody.filters || []
|
|
1669
|
-
},
|
|
1670
|
-
pagination: filteredBody.pagination,
|
|
1671
|
-
sort: filteredBody.sort,
|
|
1672
|
-
distinctOn: filteredBody.distinctOn,
|
|
1673
|
-
naturalLanguageQuery: filteredBody.naturalLanguageQuery,
|
|
1674
|
-
count: currentKey === extraData.key ? "" : config?.count ?? "",
|
|
1675
|
-
debug: true
|
|
1676
|
-
}),
|
|
1677
|
-
signal: controller.signal
|
|
1678
|
-
});
|
|
1679
|
-
if (!res.ok) {
|
|
1680
|
-
const errorData = await res.json();
|
|
1681
|
-
const errorMessage_0 = typeof errorData?.error === "string" ? errorData.error : errorData?.error?.message || errorData?.message || "An error occurred while processing your request";
|
|
1682
|
-
throw new Error(errorMessage_0);
|
|
1683
|
-
}
|
|
1684
|
-
const data = await res.json();
|
|
1685
|
-
if (data.clarification) {
|
|
1686
|
-
return {
|
|
1687
|
-
data: [],
|
|
1688
|
-
// Empty data array
|
|
1689
|
-
count: 0,
|
|
1690
|
-
clarification: data.clarification,
|
|
1691
|
-
error: void 0
|
|
1692
|
-
};
|
|
1693
|
-
}
|
|
1694
|
-
result_0 = data;
|
|
1695
|
-
response = {
|
|
1696
|
-
error: null,
|
|
1697
|
-
data
|
|
1698
|
-
};
|
|
1699
|
-
} catch (err) {
|
|
1700
|
-
if (err.name === "AbortError") {
|
|
1701
|
-
console.error("Fetch aborted/time-out");
|
|
1702
|
-
response = {
|
|
1703
|
-
error: new Error("This query timed out"),
|
|
1704
|
-
data: null
|
|
1705
|
-
};
|
|
1706
|
-
} else if (err instanceof Error) {
|
|
1707
|
-
response = {
|
|
1708
|
-
error: err,
|
|
1709
|
-
data: null
|
|
1710
|
-
};
|
|
1711
|
-
} else {
|
|
1712
|
-
const errorMessage = err?.error || err?.message || String(err);
|
|
1713
|
-
response = {
|
|
1714
|
-
error: new Error(errorMessage),
|
|
1715
|
-
data: null
|
|
1716
|
-
};
|
|
1717
|
-
}
|
|
1718
|
-
} finally {
|
|
1719
|
-
clearTimeout(timeout);
|
|
1720
|
-
}
|
|
1721
|
-
if (response.error) {
|
|
1722
|
-
throw response.error;
|
|
1723
|
-
} else if (response.data?.error) {
|
|
1724
|
-
throw new Error(response.data.error);
|
|
1725
|
-
}
|
|
1726
|
-
if (result_0.clarification) {
|
|
1727
|
-
return {
|
|
1728
|
-
data: [],
|
|
1729
|
-
count: 0,
|
|
1730
|
-
clarification: result_0.clarification,
|
|
1731
|
-
error: void 0
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
setExtraData((pre_1) => ({
|
|
1735
|
-
...omit(result_0, "data"),
|
|
1736
|
-
count: pre_1.key === currentKey ? pre_1.count : result_0.count,
|
|
1737
|
-
key: currentKey
|
|
1738
|
-
}));
|
|
1739
|
-
return {
|
|
1740
|
-
...result_0,
|
|
1741
|
-
statusText: "",
|
|
1742
|
-
status: result_0.data?.length > result_0.count ? 206 : 200,
|
|
1743
|
-
error: response.data?.error ?? null,
|
|
1744
|
-
hasMore: result_0.data?.length < result_0.count ? true : false
|
|
1745
|
-
};
|
|
1746
|
-
} catch (error) {
|
|
1747
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
1748
|
-
console.log("Fetch aborted");
|
|
1749
|
-
} else {
|
|
1750
|
-
console.error("Error fetching data:", error);
|
|
1751
|
-
}
|
|
1752
|
-
if (error instanceof Error && error.message === "Failed to send a request to the Edge Function") {
|
|
1753
|
-
throw new Error("Could not contact query server");
|
|
1754
|
-
}
|
|
1755
|
-
throw error;
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
});
|
|
1759
|
-
const response_0 = {
|
|
1760
|
-
...queryResponse,
|
|
1761
|
-
data: queryResponse.data?.data,
|
|
1762
|
-
count: extraData.count,
|
|
1763
|
-
clarification: queryResponse.data?.clarification
|
|
1764
|
-
};
|
|
1765
|
-
useEffect(() => {
|
|
1766
|
-
if (queryResponse.isFetched && response_0.count == null) {
|
|
1767
|
-
queryResponse.refetch();
|
|
1768
|
-
}
|
|
1769
|
-
}, [response_0.count]);
|
|
1770
|
-
useEffect(() => {
|
|
1771
|
-
if (queryResponse.data?.error == null) return;
|
|
1772
|
-
if (queryResponse.data?.error?.message?.includes(" does not exist")) {
|
|
1773
|
-
setFilterLayer({
|
|
1774
|
-
id: "root",
|
|
1775
|
-
op: "AND",
|
|
1776
|
-
filters: [],
|
|
1777
|
-
pagination: void 0,
|
|
1778
|
-
sort: [],
|
|
1779
|
-
isReady: isUsable(config?.searchByDefault) ? config.searchByDefault ? false : true : true
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
}, [queryResponse.data?.error]);
|
|
1783
|
-
return [response_0, filterLayer, setFilterLayer];
|
|
1784
|
-
}
|
|
1785
|
-
function isSearchableColumn(columnName) {
|
|
1786
|
-
return true;
|
|
1787
|
-
}
|
|
1788
|
-
async function executeSupabaseQuery(supabase, body, parser, extraData, signal, count) {
|
|
1789
|
-
const searchParams = Array.from(parser.searchParams.entries());
|
|
1790
|
-
const currentKey = `${parser.schema}${parser.table}${parser.select}${JSON.stringify(omit(body, "pagination"))}`;
|
|
1791
|
-
const query = supabase.schema(parser.schema).from(parser.table).select(parser.select, {
|
|
1792
|
-
count: currentKey === extraData.key ? void 0 : count || void 0
|
|
1793
|
-
});
|
|
1794
|
-
if (body.sort && Array.isArray(body.sort)) {
|
|
1795
|
-
body.sort.forEach((s) => {
|
|
1796
|
-
query.order(s.field, {
|
|
1797
|
-
ascending: s.direction === "asc"
|
|
1798
|
-
});
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
const from = searchParams.find((x) => x[0].includes("offset"))?.[1];
|
|
1802
|
-
const to = searchParams.find((x) => x[0].includes("limit"))?.[1];
|
|
1803
|
-
searchParams.forEach(([k, v]) => {
|
|
1804
|
-
if (k.includes("offset") && isUsable(v)) {
|
|
1805
|
-
body.pagination.from = Number(v);
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
if (k.includes("limit") && isUsable(v)) {
|
|
1809
|
-
body.pagination.to = Number(from) + Number(v) - 1;
|
|
1810
|
-
return;
|
|
1811
|
-
}
|
|
1812
|
-
if (k === "or") {
|
|
1813
|
-
query.or(v.slice(1, v.length - 1));
|
|
1814
|
-
return;
|
|
1815
|
-
}
|
|
1816
|
-
const values = v.split(".");
|
|
1817
|
-
const column = k;
|
|
1818
|
-
let rawCondition = values[0];
|
|
1819
|
-
let value = values[1];
|
|
1820
|
-
if (column == "select") return;
|
|
1821
|
-
if (column == "order") return;
|
|
1822
|
-
if (v.includes(".") === false) return;
|
|
1823
|
-
if (rawCondition === "ilike" && !isSearchableColumn(column)) {
|
|
1824
|
-
return;
|
|
1825
|
-
}
|
|
1826
|
-
if (rawCondition === "not") {
|
|
1827
|
-
rawCondition = values[1];
|
|
1828
|
-
value = values[2];
|
|
1829
|
-
query.not(column, rawCondition, value);
|
|
1830
|
-
} else {
|
|
1831
|
-
query.filter(column, rawCondition, value);
|
|
1832
|
-
}
|
|
1833
|
-
});
|
|
1834
|
-
if (body.pagination.from !== null && body.pagination.from !== void 0 && body.pagination.to !== null && body.pagination.to !== void 0 && isNaN(body.pagination.from) === false && isNaN(body.pagination.to) === false) {
|
|
1835
|
-
query.range(body.pagination.from, body.pagination.to);
|
|
1836
|
-
}
|
|
1837
|
-
const result = await query.abortSignal(signal);
|
|
1838
|
-
const dataLength = result.data?.length ?? 0;
|
|
1839
|
-
const totalCount = result.count ?? 0;
|
|
1840
|
-
return {
|
|
1841
|
-
...result,
|
|
1842
|
-
statusText: "",
|
|
1843
|
-
status: dataLength > totalCount ? 206 : 200,
|
|
1844
|
-
error: result.error,
|
|
1845
|
-
hasMore: dataLength < totalCount
|
|
1846
|
-
};
|
|
1847
|
-
}
|
|
1848
|
-
var useAdvancedQuery = useAdvancedFilterQuery;
|
|
1849
|
-
|
|
1850
|
-
// src/query/useInfiniteQuery.ts
|
|
1851
|
-
import { useInfiniteQuery as useTanstackInfiniteQuery } from "@tanstack/react-query";
|
|
1852
|
-
import { useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
1853
|
-
function useInfiniteQuery(query, countPerLoad, config) {
|
|
1854
|
-
const initialQueryKey = encode(query, false).join("-");
|
|
1855
|
-
const lastKnownQuery = useRef2(initialQueryKey);
|
|
1856
|
-
const currentPageNumber = useRef2(1);
|
|
1857
|
-
if (lastKnownQuery.current != initialQueryKey) {
|
|
1858
|
-
lastKnownQuery.current = initialQueryKey;
|
|
1859
|
-
currentPageNumber.current = 1;
|
|
1860
|
-
}
|
|
1861
|
-
const isFetching = useRef2(false);
|
|
1862
|
-
const queryKey = useMemo2(() => encode(query, false), [initialQueryKey, config?.crossOrganization]);
|
|
1863
|
-
const getQuery = useTanstackInfiniteQuery({
|
|
1864
|
-
...config,
|
|
1865
|
-
queryKey,
|
|
1866
|
-
queryFn: async ({
|
|
1867
|
-
pageParam,
|
|
1868
|
-
signal
|
|
1869
|
-
}) => {
|
|
1870
|
-
let adjustableQuery = query;
|
|
1871
|
-
const pageNumber = pageParam;
|
|
1872
|
-
if (config?.onQuery && config?.enableOnQuery) {
|
|
1873
|
-
config?.onQuery({
|
|
1874
|
-
query: adjustableQuery,
|
|
1875
|
-
pageParam: pageNumber
|
|
1876
|
-
});
|
|
1877
|
-
} else {
|
|
1878
|
-
adjustableQuery = adjustableQuery.range((pageNumber - 1) * countPerLoad, pageNumber * countPerLoad - 1);
|
|
1879
|
-
}
|
|
1880
|
-
adjustableQuery = adjustableQuery.abortSignal(signal);
|
|
1881
|
-
updatedCache.current = false;
|
|
1882
|
-
const response = await adjustableQuery;
|
|
1883
|
-
currentPageNumber.current = pageNumber;
|
|
1884
|
-
if (response.error) {
|
|
1885
|
-
throw response.error;
|
|
1886
|
-
} else {
|
|
1887
|
-
return response;
|
|
1888
|
-
}
|
|
1889
|
-
},
|
|
1890
|
-
initialPageParam: 1,
|
|
1891
|
-
getNextPageParam: (response_0, allResponses, lastParam) => {
|
|
1892
|
-
const pageParam_0 = lastParam;
|
|
1893
|
-
const resp = response_0;
|
|
1894
|
-
if (allResponses.length * countPerLoad >= (resp?.count ?? 0)) {
|
|
1895
|
-
return void 0;
|
|
1896
|
-
}
|
|
1897
|
-
return pageParam_0 + 1;
|
|
1898
|
-
}
|
|
1899
|
-
});
|
|
1900
|
-
const updatedCache = useRef2(true);
|
|
1901
|
-
return useMemo2(() => {
|
|
1902
|
-
const pages = getQuery.data?.pages;
|
|
1903
|
-
return {
|
|
1904
|
-
...getQuery,
|
|
1905
|
-
count: pages?.[pages.length - 1]?.count,
|
|
1906
|
-
data: pages?.flatMap((x) => x.data ?? [])
|
|
1907
|
-
};
|
|
1908
|
-
}, [getQuery.data, currentPageNumber.current]);
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
// src/query/usePartialAdvancedQuery.ts
|
|
1912
|
-
import { c as _c3 } from "react/compiler-runtime";
|
|
1913
|
-
import { useLayoutEffect, useState as useState2 } from "react";
|
|
1914
|
-
import { useSessionStorageState as useSessionStorageState3 } from "@pol-studios/hooks/storage";
|
|
1915
|
-
function usePartialAdvancedQuery(query, itemCountPerPage, config) {
|
|
1916
|
-
const $ = _c3(54);
|
|
1917
|
-
const initialQuery = encode(query, false);
|
|
1918
|
-
const [id, setId] = useState2(window.location.pathname);
|
|
1919
|
-
const [currentPage, setCurrentPage] = useSessionStorageState3(`${id}-currentPage`, 1);
|
|
1920
|
-
const page = currentPage ?? 1;
|
|
1921
|
-
const t0 = query;
|
|
1922
|
-
let t1;
|
|
1923
|
-
if ($[0] !== itemCountPerPage || $[1] !== page || $[2] !== t0) {
|
|
1924
|
-
t1 = t0.range((page - 1) * itemCountPerPage, page * itemCountPerPage - 1);
|
|
1925
|
-
$[0] = itemCountPerPage;
|
|
1926
|
-
$[1] = page;
|
|
1927
|
-
$[2] = t0;
|
|
1928
|
-
$[3] = t1;
|
|
1929
|
-
} else {
|
|
1930
|
-
t1 = $[3];
|
|
1931
|
-
}
|
|
1932
|
-
const rangedQuery = t1;
|
|
1933
|
-
const t2 = config?.filterKey;
|
|
1934
|
-
const t3 = currentPage ?? 1;
|
|
1935
|
-
let t4;
|
|
1936
|
-
if ($[4] !== t3) {
|
|
1937
|
-
t4 = t3.toString();
|
|
1938
|
-
$[4] = t3;
|
|
1939
|
-
$[5] = t4;
|
|
1940
|
-
} else {
|
|
1941
|
-
t4 = $[5];
|
|
1942
|
-
}
|
|
1943
|
-
let t5;
|
|
1944
|
-
if ($[6] !== config || $[7] !== t2 || $[8] !== t4) {
|
|
1945
|
-
t5 = {
|
|
1946
|
-
...config,
|
|
1947
|
-
filterKey: t2,
|
|
1948
|
-
count: "exact",
|
|
1949
|
-
key: t4
|
|
1950
|
-
};
|
|
1951
|
-
$[6] = config;
|
|
1952
|
-
$[7] = t2;
|
|
1953
|
-
$[8] = t4;
|
|
1954
|
-
$[9] = t5;
|
|
1955
|
-
} else {
|
|
1956
|
-
t5 = $[9];
|
|
1957
|
-
}
|
|
1958
|
-
const [baseQuery, filter, setFilters] = useAdvancedFilterQuery(rangedQuery, t5);
|
|
1959
|
-
let t6;
|
|
1960
|
-
if ($[10] !== filter) {
|
|
1961
|
-
t6 = JSON.stringify(omit(filter, ["pagination"]));
|
|
1962
|
-
$[10] = filter;
|
|
1963
|
-
$[11] = t6;
|
|
1964
|
-
} else {
|
|
1965
|
-
t6 = $[11];
|
|
1966
|
-
}
|
|
1967
|
-
const filterKey = t6;
|
|
1968
|
-
const select = initialQuery[4].split("&").find(_temp4);
|
|
1969
|
-
let t7;
|
|
1970
|
-
if ($[12] !== filterKey || $[13] !== id || $[14] !== initialQuery[3] || $[15] !== initialQuery[5] || $[16] !== initialQuery[6] || $[17] !== initialQuery[7] || $[18] !== initialQuery[8] || $[19] !== select || $[20] !== setId) {
|
|
1971
|
-
t7 = () => {
|
|
1972
|
-
const newId = [initialQuery[3], select, initialQuery[5], initialQuery[6], initialQuery[7], initialQuery[8], filterKey].join("-");
|
|
1973
|
-
console.log({
|
|
1974
|
-
newId,
|
|
1975
|
-
id
|
|
1976
|
-
});
|
|
1977
|
-
setId(newId);
|
|
1978
|
-
};
|
|
1979
|
-
$[12] = filterKey;
|
|
1980
|
-
$[13] = id;
|
|
1981
|
-
$[14] = initialQuery[3];
|
|
1982
|
-
$[15] = initialQuery[5];
|
|
1983
|
-
$[16] = initialQuery[6];
|
|
1984
|
-
$[17] = initialQuery[7];
|
|
1985
|
-
$[18] = initialQuery[8];
|
|
1986
|
-
$[19] = select;
|
|
1987
|
-
$[20] = setId;
|
|
1988
|
-
$[21] = t7;
|
|
1989
|
-
} else {
|
|
1990
|
-
t7 = $[21];
|
|
1991
|
-
}
|
|
1992
|
-
let t8;
|
|
1993
|
-
if ($[22] !== filterKey || $[23] !== initialQuery[3] || $[24] !== initialQuery[5] || $[25] !== initialQuery[6] || $[26] !== initialQuery[7] || $[27] !== initialQuery[8] || $[28] !== select) {
|
|
1994
|
-
t8 = [initialQuery[3], select, initialQuery[5], initialQuery[6], initialQuery[7], initialQuery[8], filterKey];
|
|
1995
|
-
$[22] = filterKey;
|
|
1996
|
-
$[23] = initialQuery[3];
|
|
1997
|
-
$[24] = initialQuery[5];
|
|
1998
|
-
$[25] = initialQuery[6];
|
|
1999
|
-
$[26] = initialQuery[7];
|
|
2000
|
-
$[27] = initialQuery[8];
|
|
2001
|
-
$[28] = select;
|
|
2002
|
-
$[29] = t8;
|
|
2003
|
-
} else {
|
|
2004
|
-
t8 = $[29];
|
|
2005
|
-
}
|
|
2006
|
-
useLayoutEffect(t7, t8);
|
|
2007
|
-
let t9;
|
|
2008
|
-
if ($[30] !== setCurrentPage) {
|
|
2009
|
-
t9 = () => {
|
|
2010
|
-
setCurrentPage(_temp22);
|
|
2011
|
-
};
|
|
2012
|
-
$[30] = setCurrentPage;
|
|
2013
|
-
$[31] = t9;
|
|
2014
|
-
} else {
|
|
2015
|
-
t9 = $[31];
|
|
2016
|
-
}
|
|
2017
|
-
const safeFetchNextPage = t9;
|
|
2018
|
-
let t10;
|
|
2019
|
-
if ($[32] !== setCurrentPage) {
|
|
2020
|
-
t10 = () => {
|
|
2021
|
-
setCurrentPage(_temp3);
|
|
2022
|
-
};
|
|
2023
|
-
$[32] = setCurrentPage;
|
|
2024
|
-
$[33] = t10;
|
|
2025
|
-
} else {
|
|
2026
|
-
t10 = $[33];
|
|
2027
|
-
}
|
|
2028
|
-
const fetchPreviousPage = t10;
|
|
2029
|
-
const pageCount = Math.max(Math.ceil((baseQuery.count ?? 0) / itemCountPerPage), 1);
|
|
2030
|
-
let t11;
|
|
2031
|
-
if ($[34] !== baseQuery.count || $[35] !== baseQuery.data || $[36] !== currentPage || $[37] !== itemCountPerPage) {
|
|
2032
|
-
t11 = baseQuery.data ? toPagedResponse2(baseQuery.data, currentPage ?? 1, baseQuery.count ?? baseQuery.data.length, itemCountPerPage) : null;
|
|
2033
|
-
$[34] = baseQuery.count;
|
|
2034
|
-
$[35] = baseQuery.data;
|
|
2035
|
-
$[36] = currentPage;
|
|
2036
|
-
$[37] = itemCountPerPage;
|
|
2037
|
-
$[38] = t11;
|
|
2038
|
-
} else {
|
|
2039
|
-
t11 = $[38];
|
|
2040
|
-
}
|
|
2041
|
-
const t12 = (currentPage ?? 1) < pageCount;
|
|
2042
|
-
const t13 = (currentPage ?? 1) > 1;
|
|
2043
|
-
const t14 = baseQuery.count ?? baseQuery.data?.length;
|
|
2044
|
-
let t15;
|
|
2045
|
-
if ($[39] !== baseQuery || $[40] !== currentPage || $[41] !== fetchPreviousPage || $[42] !== pageCount || $[43] !== safeFetchNextPage || $[44] !== setCurrentPage || $[45] !== t11 || $[46] !== t12 || $[47] !== t13 || $[48] !== t14) {
|
|
2046
|
-
t15 = {
|
|
2047
|
-
...baseQuery,
|
|
2048
|
-
clarification: baseQuery.clarification,
|
|
2049
|
-
fetchPreviousPage,
|
|
2050
|
-
fetchNextPage: safeFetchNextPage,
|
|
2051
|
-
currentPage,
|
|
2052
|
-
setCurrentPage,
|
|
2053
|
-
data: t11,
|
|
2054
|
-
pageCount,
|
|
2055
|
-
hasNextPage: t12,
|
|
2056
|
-
hasPreviousPage: t13,
|
|
2057
|
-
count: t14
|
|
2058
|
-
};
|
|
2059
|
-
$[39] = baseQuery;
|
|
2060
|
-
$[40] = currentPage;
|
|
2061
|
-
$[41] = fetchPreviousPage;
|
|
2062
|
-
$[42] = pageCount;
|
|
2063
|
-
$[43] = safeFetchNextPage;
|
|
2064
|
-
$[44] = setCurrentPage;
|
|
2065
|
-
$[45] = t11;
|
|
2066
|
-
$[46] = t12;
|
|
2067
|
-
$[47] = t13;
|
|
2068
|
-
$[48] = t14;
|
|
2069
|
-
$[49] = t15;
|
|
2070
|
-
} else {
|
|
2071
|
-
t15 = $[49];
|
|
2072
|
-
}
|
|
2073
|
-
const request = t15;
|
|
2074
|
-
let t16;
|
|
2075
|
-
if ($[50] !== filter || $[51] !== request || $[52] !== setFilters) {
|
|
2076
|
-
t16 = [request, filter, setFilters];
|
|
2077
|
-
$[50] = filter;
|
|
2078
|
-
$[51] = request;
|
|
2079
|
-
$[52] = setFilters;
|
|
2080
|
-
$[53] = t16;
|
|
2081
|
-
} else {
|
|
2082
|
-
t16 = $[53];
|
|
2083
|
-
}
|
|
2084
|
-
return t16;
|
|
2085
|
-
}
|
|
2086
|
-
function _temp3(currentPage_1) {
|
|
2087
|
-
return (currentPage_1 ?? 1) - 1;
|
|
2088
|
-
}
|
|
2089
|
-
function _temp22(currentPage_0) {
|
|
2090
|
-
return (currentPage_0 ?? 1) + 1;
|
|
2091
|
-
}
|
|
2092
|
-
function _temp4(x) {
|
|
2093
|
-
return x.startsWith("select=");
|
|
2094
|
-
}
|
|
2095
|
-
function toPagedResponse2(results, currentPage, totalCount, itemPerPage) {
|
|
2096
|
-
const newPage = {
|
|
2097
|
-
Items: results,
|
|
2098
|
-
CurrentPage: currentPage,
|
|
2099
|
-
ItemCount: totalCount,
|
|
2100
|
-
MaxCountPerPage: itemPerPage,
|
|
2101
|
-
PageCount: Math.max(Math.ceil(totalCount / itemPerPage), 1)
|
|
2102
|
-
};
|
|
2103
|
-
return newPage;
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
1181
|
export {
|
|
2107
1182
|
tokenizeTopLevel,
|
|
2108
1183
|
parseSelect,
|
|
@@ -2118,12 +1193,6 @@ export {
|
|
|
2118
1193
|
ResultJoiner,
|
|
2119
1194
|
createResultJoiner,
|
|
2120
1195
|
QueryExecutor,
|
|
2121
|
-
createQueryExecutor
|
|
2122
|
-
useQuery2 as useQuery,
|
|
2123
|
-
usePartialQuery,
|
|
2124
|
-
useAdvancedFilterQuery,
|
|
2125
|
-
useAdvancedQuery,
|
|
2126
|
-
useInfiniteQuery,
|
|
2127
|
-
usePartialAdvancedQuery
|
|
1196
|
+
createQueryExecutor
|
|
2128
1197
|
};
|
|
2129
|
-
//# sourceMappingURL=chunk-
|
|
1198
|
+
//# sourceMappingURL=chunk-BXSOHOQ2.js.map
|