@pol-studios/db 1.0.8 → 1.0.10
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 +21 -12786
- package/dist/auth/context.js.map +1 -1
- package/dist/auth/guards.js +12 -7640
- package/dist/auth/guards.js.map +1 -1
- package/dist/auth/hooks.js +25 -10591
- package/dist/auth/hooks.js.map +1 -1
- package/dist/auth/index.js +43 -13008
- package/dist/auth/index.js.map +1 -1
- package/dist/canvas-75Y7XMF3.js +1541 -0
- package/dist/canvas-75Y7XMF3.js.map +1 -0
- package/dist/chunk-2IFGILT3.js +532 -0
- package/dist/chunk-2IFGILT3.js.map +1 -0
- package/dist/chunk-3M2U6TXH.js +928 -0
- package/dist/chunk-3M2U6TXH.js.map +1 -0
- package/dist/chunk-3PJTNH2L.js +2778 -0
- package/dist/chunk-3PJTNH2L.js.map +1 -0
- package/dist/chunk-5ZYAEGCJ.js +416 -0
- package/dist/chunk-5ZYAEGCJ.js.map +1 -0
- package/dist/chunk-7HG6G25H.js +710 -0
- package/dist/chunk-7HG6G25H.js.map +1 -0
- package/dist/chunk-7XT7K4QT.js +2687 -0
- package/dist/chunk-7XT7K4QT.js.map +1 -0
- package/dist/chunk-AWFMICFV.js +158 -0
- package/dist/chunk-AWFMICFV.js.map +1 -0
- package/dist/chunk-BRTW7CO5.js +1467 -0
- package/dist/chunk-BRTW7CO5.js.map +1 -0
- package/dist/chunk-EL45Z26M.js +4194 -0
- package/dist/chunk-EL45Z26M.js.map +1 -0
- package/dist/chunk-ERGF2FCE.js +903 -0
- package/dist/chunk-ERGF2FCE.js.map +1 -0
- package/dist/chunk-GK7B66LY.js +135 -0
- package/dist/chunk-GK7B66LY.js.map +1 -0
- package/dist/chunk-GQI6WJGI.js +172 -0
- package/dist/chunk-GQI6WJGI.js.map +1 -0
- package/dist/chunk-H6365JPC.js +1858 -0
- package/dist/chunk-H6365JPC.js.map +1 -0
- package/dist/chunk-J4ZVCXZ4.js +1 -0
- package/dist/chunk-J4ZVCXZ4.js.map +1 -0
- package/dist/chunk-JUVE3DWY.js +433 -0
- package/dist/chunk-JUVE3DWY.js.map +1 -0
- package/dist/chunk-O3K7R32P.js +7555 -0
- package/dist/chunk-O3K7R32P.js.map +1 -0
- package/dist/chunk-P4UZ7IXC.js +42 -0
- package/dist/chunk-P4UZ7IXC.js.map +1 -0
- package/dist/chunk-SEY5UO2T.js +89 -0
- package/dist/chunk-SEY5UO2T.js.map +1 -0
- package/dist/chunk-USJYMRUO.js +86 -0
- package/dist/chunk-USJYMRUO.js.map +1 -0
- package/dist/chunk-XX3IWSPM.js +189 -0
- package/dist/chunk-XX3IWSPM.js.map +1 -0
- package/dist/chunk-Y3INY2CS.js +14 -0
- package/dist/chunk-Y3INY2CS.js.map +1 -0
- package/dist/chunk-ZTSBF536.js +1927 -0
- package/dist/chunk-ZTSBF536.js.map +1 -0
- package/dist/client/index.js +13 -141
- package/dist/client/index.js.map +1 -1
- package/dist/dist-NDNRSNOG.js +521 -0
- package/dist/dist-NDNRSNOG.js.map +1 -0
- package/dist/gen/index.js +186 -1280
- package/dist/gen/index.js.map +1 -1
- package/dist/hooks/index.js +21 -8694
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js +403 -47848
- package/dist/index.js.map +1 -1
- package/dist/index.native.js +400 -25048
- package/dist/index.native.js.map +1 -1
- package/dist/index.web.js +576 -43769
- package/dist/index.web.js.map +1 -1
- package/dist/mutation/index.js +44 -4675
- package/dist/mutation/index.js.map +1 -1
- package/dist/parser/index.js +45 -3697
- package/dist/parser/index.js.map +1 -1
- package/dist/pdf-3TIGQRLA.js +20336 -0
- package/dist/pdf-3TIGQRLA.js.map +1 -0
- package/dist/query/index.js +31 -13175
- package/dist/query/index.js.map +1 -1
- package/dist/realtime/index.js +45 -12431
- package/dist/realtime/index.js.map +1 -1
- package/dist/types/index.js +9 -0
- package/package.json +3 -3
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSupabaseUrl
|
|
3
|
+
} from "./chunk-Y3INY2CS.js";
|
|
4
|
+
import {
|
|
5
|
+
PostgrestParser
|
|
6
|
+
} from "./chunk-JUVE3DWY.js";
|
|
7
|
+
import {
|
|
8
|
+
isNullOrWhitespace,
|
|
9
|
+
isUsable,
|
|
10
|
+
omit
|
|
11
|
+
} from "./chunk-O3K7R32P.js";
|
|
12
|
+
import {
|
|
13
|
+
encode
|
|
14
|
+
} from "./chunk-H6365JPC.js";
|
|
15
|
+
import {
|
|
16
|
+
generateUUID,
|
|
17
|
+
useSupabase
|
|
18
|
+
} from "./chunk-AWFMICFV.js";
|
|
19
|
+
|
|
20
|
+
// src/database.types.ts
|
|
21
|
+
var Constants = {
|
|
22
|
+
core: {
|
|
23
|
+
Enums: {
|
|
24
|
+
AdvanceQueryChangeType: [
|
|
25
|
+
"Removed",
|
|
26
|
+
"Deleted",
|
|
27
|
+
"Created",
|
|
28
|
+
"Updated",
|
|
29
|
+
"Added"
|
|
30
|
+
],
|
|
31
|
+
NotificationType: ["App", "Email", "Push"],
|
|
32
|
+
OperationType: ["Insert", "Update", "Delete"],
|
|
33
|
+
PriorityLevel: ["Lowest", "Low", "Medium", "High", "Highest"],
|
|
34
|
+
ProcessStatus: ["Pending", "Executing", "Completed", "Failed"],
|
|
35
|
+
PropertyType: ["String", "Number", "Options", "Date", "Boolean"]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
public: {
|
|
39
|
+
Enums: {
|
|
40
|
+
AdvanceQueryChangeType: [
|
|
41
|
+
"Removed",
|
|
42
|
+
"Deleted",
|
|
43
|
+
"Created",
|
|
44
|
+
"Updated",
|
|
45
|
+
"Added"
|
|
46
|
+
],
|
|
47
|
+
BillableItemType: ["TimeActivity", "Expense", "Service", "Retainage"],
|
|
48
|
+
BillingStatus: [
|
|
49
|
+
"Unknown",
|
|
50
|
+
"NotBillable",
|
|
51
|
+
"Billable",
|
|
52
|
+
"AddedToInvoice",
|
|
53
|
+
"HasBeenBilled",
|
|
54
|
+
"BilledElsewhere",
|
|
55
|
+
"LumpSum"
|
|
56
|
+
],
|
|
57
|
+
ControlType: [
|
|
58
|
+
"Unknown",
|
|
59
|
+
"DMX",
|
|
60
|
+
"ACN",
|
|
61
|
+
"ArtNet",
|
|
62
|
+
"None",
|
|
63
|
+
"DMXPT",
|
|
64
|
+
"PWR",
|
|
65
|
+
"SA",
|
|
66
|
+
"KiNET",
|
|
67
|
+
"ZTTV"
|
|
68
|
+
],
|
|
69
|
+
ExpenseReportStatus: [
|
|
70
|
+
"Pending",
|
|
71
|
+
"Open",
|
|
72
|
+
"Submitted",
|
|
73
|
+
"UnderReview",
|
|
74
|
+
"Approved",
|
|
75
|
+
"Reimbursed",
|
|
76
|
+
"Closed"
|
|
77
|
+
],
|
|
78
|
+
HighlightStatus: ["Queued", "Executed", "Failed", "Cleared"],
|
|
79
|
+
InvoiceStatus: [
|
|
80
|
+
"Created",
|
|
81
|
+
"ReadyToReview",
|
|
82
|
+
"Reviewed",
|
|
83
|
+
"ReadyToSend",
|
|
84
|
+
"Sent",
|
|
85
|
+
"Rejected",
|
|
86
|
+
"Paid"
|
|
87
|
+
],
|
|
88
|
+
MediaContentStatus: [
|
|
89
|
+
"Unknown",
|
|
90
|
+
"Required",
|
|
91
|
+
"Preferred",
|
|
92
|
+
"NotRequired",
|
|
93
|
+
"Retake",
|
|
94
|
+
"Taken"
|
|
95
|
+
],
|
|
96
|
+
NotificationType: ["App", "Email", "Push"],
|
|
97
|
+
OperationType: ["Insert", "Update", "Delete"],
|
|
98
|
+
PhaseBillingType: [
|
|
99
|
+
"TBD",
|
|
100
|
+
"NotBillable",
|
|
101
|
+
"LumpSum",
|
|
102
|
+
"TimeAndMaterials",
|
|
103
|
+
"Expenses"
|
|
104
|
+
],
|
|
105
|
+
Platform: ["Web", "Mobile"],
|
|
106
|
+
pricing_plan_interval: ["day", "week", "month", "year"],
|
|
107
|
+
pricing_type: ["one_time", "recurring"],
|
|
108
|
+
PriorityLevel: ["Lowest", "Low", "Medium", "High", "Highest"],
|
|
109
|
+
ProcessingStatus: ["None", "Processing", "Error"],
|
|
110
|
+
ProjectDocumentType: ["Proposal", "Directive", "Contract"],
|
|
111
|
+
ProjectStatus: ["Active", "Inactive", "Archived"],
|
|
112
|
+
PublicAccessType: [
|
|
113
|
+
"Public",
|
|
114
|
+
"Unlisted",
|
|
115
|
+
"InviteOnly",
|
|
116
|
+
"Private",
|
|
117
|
+
"Internal"
|
|
118
|
+
],
|
|
119
|
+
PunchListItemStatus: ["NotStarted", "InProgress", "Finished"],
|
|
120
|
+
RevitChangeType: ["Unknown", "Added", "Modified", "Deleted"],
|
|
121
|
+
subscription_status: [
|
|
122
|
+
"trialing",
|
|
123
|
+
"active",
|
|
124
|
+
"canceled",
|
|
125
|
+
"incomplete",
|
|
126
|
+
"incomplete_expired",
|
|
127
|
+
"past_due",
|
|
128
|
+
"unpaid"
|
|
129
|
+
],
|
|
130
|
+
TaskRunStatus: [
|
|
131
|
+
"PENDING",
|
|
132
|
+
"EXECUTING",
|
|
133
|
+
"WAITING_TO_RESUME",
|
|
134
|
+
"RETRYING_AFTER_FAILURE",
|
|
135
|
+
"PAUSED",
|
|
136
|
+
"CANCELED",
|
|
137
|
+
"COMPLETED_SUCCESSFULLY",
|
|
138
|
+
"COMPLETED_WITH_ERRORS",
|
|
139
|
+
"INTERRUPTED",
|
|
140
|
+
"SYSTEM_FAILURE",
|
|
141
|
+
"CRASHED",
|
|
142
|
+
"WAITING_FOR_DEPLOY",
|
|
143
|
+
"DELAYED",
|
|
144
|
+
"EXPIRED"
|
|
145
|
+
],
|
|
146
|
+
TicketCommentParentType: ["Ticket", "TicketComment"],
|
|
147
|
+
TicketStatus: ["Open", "Closed"],
|
|
148
|
+
TicketType: ["Issue", "Feedback"],
|
|
149
|
+
TimeBankEffect: ["Accrues", "Consumes", "Neutral"],
|
|
150
|
+
UnitMediaType: ["FocusPhoto", "Attachment"],
|
|
151
|
+
UnitOfMass: ["Pounds", "Kilograms"],
|
|
152
|
+
UnitOfMeasurement: ["Inches", "Millimeters"],
|
|
153
|
+
UserAccess: ["ReadOnly", "ReadWrite", "Admin"],
|
|
154
|
+
WorkingPhaseStatus: ["Pending", "Active", "Closed"]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/useDbAdvanceQuery.ts
|
|
160
|
+
import {
|
|
161
|
+
useEffect,
|
|
162
|
+
useMemo,
|
|
163
|
+
useRef,
|
|
164
|
+
useState
|
|
165
|
+
} from "react";
|
|
166
|
+
import {
|
|
167
|
+
useQuery
|
|
168
|
+
} from "@tanstack/react-query";
|
|
169
|
+
import { useSessionStorageState } from "@pol-studios/hooks/storage";
|
|
170
|
+
var normalizeFilter = (filter) => {
|
|
171
|
+
const groupOp = filter.op || filter.operator;
|
|
172
|
+
if (groupOp && (groupOp === "AND" || groupOp === "OR") && filter.filters) {
|
|
173
|
+
return {
|
|
174
|
+
id: filter.id || generateUUID(),
|
|
175
|
+
op: groupOp,
|
|
176
|
+
not: filter.not || filter.inverted,
|
|
177
|
+
// Support both 'not' and legacy 'inverted' for groups
|
|
178
|
+
filters: filter.filters.map(normalizeFilter).filter(
|
|
179
|
+
Boolean
|
|
180
|
+
)
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
let operator = filter.op || filter.condition;
|
|
184
|
+
let shouldNegate = filter.not || filter.inverted || false;
|
|
185
|
+
if (operator === "\u220B") operator = "in";
|
|
186
|
+
if (operator === "\u2260" || operator === "!=") {
|
|
187
|
+
operator = "=";
|
|
188
|
+
shouldNegate = true;
|
|
189
|
+
}
|
|
190
|
+
if (operator === "like") operator = "contains";
|
|
191
|
+
if (operator === "regex" || operator === "regex_i" || operator === "similar_to") {
|
|
192
|
+
operator = "contains";
|
|
193
|
+
}
|
|
194
|
+
if (!operator) {
|
|
195
|
+
console.error(
|
|
196
|
+
"Filter has undefined operator:",
|
|
197
|
+
JSON.stringify(filter, null, 2)
|
|
198
|
+
);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
if (filter.propertyName) {
|
|
202
|
+
return {
|
|
203
|
+
id: filter.id,
|
|
204
|
+
field: filter.propertyName,
|
|
205
|
+
op: operator,
|
|
206
|
+
value: filter.value,
|
|
207
|
+
not: shouldNegate,
|
|
208
|
+
display: filter.display || filter.propertyName
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
id: filter.id,
|
|
213
|
+
field: filter.field,
|
|
214
|
+
op: operator,
|
|
215
|
+
value: filter.value,
|
|
216
|
+
not: shouldNegate,
|
|
217
|
+
similarity: filter.similarity,
|
|
218
|
+
where: filter.where,
|
|
219
|
+
display: filter.display || filter.field
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
function useDbAdvanceFilterQuery(query, config) {
|
|
223
|
+
const filterKey = useMemo(
|
|
224
|
+
() => config?.filterKey ?? window.location?.pathname,
|
|
225
|
+
[
|
|
226
|
+
config?.filterKey
|
|
227
|
+
]
|
|
228
|
+
);
|
|
229
|
+
const [filterLayer, setFilterLayer] = useSessionStorageState(filterKey, {
|
|
230
|
+
id: "root",
|
|
231
|
+
op: "AND",
|
|
232
|
+
filters: [],
|
|
233
|
+
pagination: void 0,
|
|
234
|
+
sort: [],
|
|
235
|
+
isReady: isUsable(config?.searchByDefault) ? config.searchByDefault ? false : true : true
|
|
236
|
+
});
|
|
237
|
+
const parser = useMemo(
|
|
238
|
+
() => new PostgrestParser(query),
|
|
239
|
+
[query, config?.key]
|
|
240
|
+
);
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
const searchParam = parser.searchParams.get("order");
|
|
243
|
+
if (searchParam) {
|
|
244
|
+
const orderColumns = searchParam.split(",");
|
|
245
|
+
const orders = [];
|
|
246
|
+
orderColumns.forEach((x) => {
|
|
247
|
+
const values = x.split(".");
|
|
248
|
+
orders.push({
|
|
249
|
+
field: values[0],
|
|
250
|
+
direction: values[1] === "asc" ? "asc" : "desc"
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
setFilterLayer((pre) => {
|
|
254
|
+
if (!pre) {
|
|
255
|
+
return {
|
|
256
|
+
id: "root",
|
|
257
|
+
op: "AND",
|
|
258
|
+
filters: [],
|
|
259
|
+
isReady: true,
|
|
260
|
+
sort: orders
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
...pre,
|
|
265
|
+
id: pre.id || "root",
|
|
266
|
+
op: pre.op || "AND",
|
|
267
|
+
filters: pre.filters || [],
|
|
268
|
+
isReady: pre.isReady ?? true,
|
|
269
|
+
sort: [
|
|
270
|
+
...(pre.sort || []).filter(
|
|
271
|
+
(old) => orders.some((o) => o.field === old.field) === false
|
|
272
|
+
),
|
|
273
|
+
...orders
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}, [JSON.stringify(parser.searchParams), config?.key]);
|
|
279
|
+
const encodedQueryKeyRef = useRef([]);
|
|
280
|
+
const encodedQueryKey = useMemo(() => {
|
|
281
|
+
const newEncoded = encode(query, false);
|
|
282
|
+
const newEncodedString = JSON.stringify(newEncoded);
|
|
283
|
+
const oldEncodedString = JSON.stringify(encodedQueryKeyRef.current);
|
|
284
|
+
if (newEncodedString !== oldEncodedString) {
|
|
285
|
+
encodedQueryKeyRef.current = newEncoded;
|
|
286
|
+
}
|
|
287
|
+
return encodedQueryKeyRef.current;
|
|
288
|
+
}, [query, parser.offset, parser.limit]);
|
|
289
|
+
const filterLayerStringRef = useRef("");
|
|
290
|
+
const currentFilterString = JSON.stringify(filterLayer, (key, value) => key === "id" ? "redacted" : value);
|
|
291
|
+
if (filterLayerStringRef.current !== currentFilterString) {
|
|
292
|
+
filterLayerStringRef.current = currentFilterString;
|
|
293
|
+
}
|
|
294
|
+
const queryKeyRef = useRef([]);
|
|
295
|
+
const newKey = [
|
|
296
|
+
encodedQueryKey[0],
|
|
297
|
+
encodedQueryKey[1],
|
|
298
|
+
encodedQueryKey[2],
|
|
299
|
+
encodedQueryKey[3],
|
|
300
|
+
encodedQueryKey[4],
|
|
301
|
+
encodedQueryKey[5],
|
|
302
|
+
"count=" + (config?.count ?? ""),
|
|
303
|
+
encodedQueryKey[7],
|
|
304
|
+
encodedQueryKey[8],
|
|
305
|
+
filterLayerStringRef.current
|
|
306
|
+
];
|
|
307
|
+
const newKeyString = JSON.stringify(newKey);
|
|
308
|
+
const oldKeyString = JSON.stringify(queryKeyRef.current);
|
|
309
|
+
if (oldKeyString !== newKeyString) {
|
|
310
|
+
queryKeyRef.current = newKey;
|
|
311
|
+
}
|
|
312
|
+
const queryKey = queryKeyRef.current;
|
|
313
|
+
const [previousKey, setPreviousKey] = useState(queryKey);
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
if (filterLayer?.isReady) {
|
|
316
|
+
setPreviousKey(queryKey);
|
|
317
|
+
}
|
|
318
|
+
}, [...queryKey]);
|
|
319
|
+
const loadingKey = filterLayer?.isReady ? queryKey : previousKey ?? queryKey;
|
|
320
|
+
const supabase = useSupabase();
|
|
321
|
+
const isEnabled = config?.enabled == null || config?.enabled === void 0 ? true : config.enabled;
|
|
322
|
+
const [extraData, setExtraData] = useState({});
|
|
323
|
+
const queryResponse = useQuery({
|
|
324
|
+
...omit(
|
|
325
|
+
{
|
|
326
|
+
retry: 0,
|
|
327
|
+
// Changed from 1 to 0 to prevent retries
|
|
328
|
+
...config ?? {},
|
|
329
|
+
// Override any config settings to prevent multiple executions
|
|
330
|
+
refetchOnMount: false,
|
|
331
|
+
refetchOnWindowFocus: false,
|
|
332
|
+
refetchOnReconnect: false,
|
|
333
|
+
structuralSharing: false,
|
|
334
|
+
enabled: filterLayer?.isReady && isEnabled
|
|
335
|
+
},
|
|
336
|
+
["queryKey", "persister", "initialData"]
|
|
337
|
+
),
|
|
338
|
+
queryKey: loadingKey,
|
|
339
|
+
queryFn: async (props) => {
|
|
340
|
+
if (!filterLayer) {
|
|
341
|
+
throw new Error("Filter layer is not initialized");
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const searchParams = Array.from(parser.searchParams.entries());
|
|
345
|
+
const body = {
|
|
346
|
+
...filterLayer,
|
|
347
|
+
filters: [...filterLayer.filters],
|
|
348
|
+
pagination: { ...filterLayer.pagination },
|
|
349
|
+
sort: [...filterLayer.sort || []]
|
|
350
|
+
};
|
|
351
|
+
const currentKey = `${parser.schema}${parser.table}${parser.select}${JSON.stringify(omit(body, "pagination"))}`;
|
|
352
|
+
const requiresEdgeForOrdering = false;
|
|
353
|
+
const hasNaturalLanguageQuery = !!filterLayer.naturalLanguageQuery;
|
|
354
|
+
if (filterLayer.filters.length == 0 && requiresEdgeForOrdering === false && !hasNaturalLanguageQuery) {
|
|
355
|
+
const result2 = await executeSupabaseQuery(
|
|
356
|
+
supabase,
|
|
357
|
+
body,
|
|
358
|
+
parser,
|
|
359
|
+
extraData,
|
|
360
|
+
props.signal,
|
|
361
|
+
config?.count
|
|
362
|
+
);
|
|
363
|
+
setExtraData((pre) => ({
|
|
364
|
+
...omit(result2, "data"),
|
|
365
|
+
count: result2.count ? result2.count : pre.count,
|
|
366
|
+
key: currentKey
|
|
367
|
+
}));
|
|
368
|
+
return result2;
|
|
369
|
+
}
|
|
370
|
+
searchParams.forEach(([k, v]) => {
|
|
371
|
+
if (k.includes("offset")) {
|
|
372
|
+
body.pagination.offset = Number(v);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (k.includes("limit")) {
|
|
376
|
+
body.pagination.limit = Number(v);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (k.includes("order")) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (k === "or") {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (v.includes(".") === false) return;
|
|
386
|
+
const values = v.split(".");
|
|
387
|
+
const column = k;
|
|
388
|
+
let rawCondition = values[0];
|
|
389
|
+
let condition = "";
|
|
390
|
+
let value = values[1];
|
|
391
|
+
const inverted = values[0] === "not";
|
|
392
|
+
if (column == "select") return;
|
|
393
|
+
if (rawCondition === "not") {
|
|
394
|
+
rawCondition = values[1];
|
|
395
|
+
value = values[2];
|
|
396
|
+
}
|
|
397
|
+
switch (rawCondition) {
|
|
398
|
+
case "eq":
|
|
399
|
+
condition = "=";
|
|
400
|
+
break;
|
|
401
|
+
case "in":
|
|
402
|
+
condition = "in";
|
|
403
|
+
value = value.slice(1, value.length - 1).split(",").filter((x) => isNullOrWhitespace(x) === false);
|
|
404
|
+
break;
|
|
405
|
+
case "lt":
|
|
406
|
+
condition = "<";
|
|
407
|
+
break;
|
|
408
|
+
case "gt":
|
|
409
|
+
condition = ">";
|
|
410
|
+
break;
|
|
411
|
+
case "lte":
|
|
412
|
+
condition = "<=";
|
|
413
|
+
break;
|
|
414
|
+
case "gte":
|
|
415
|
+
condition = ">=";
|
|
416
|
+
break;
|
|
417
|
+
case "is":
|
|
418
|
+
condition = "is";
|
|
419
|
+
if (value == "null") {
|
|
420
|
+
value = null;
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
body.filters = [{
|
|
425
|
+
id: `filter_${column}_${Date.now()}`,
|
|
426
|
+
field: column,
|
|
427
|
+
op: condition,
|
|
428
|
+
value,
|
|
429
|
+
not: inverted,
|
|
430
|
+
display: column
|
|
431
|
+
}, { filters: [...body.filters], op: body.op ?? "AND", id: "filterstate" }];
|
|
432
|
+
body.op = "AND";
|
|
433
|
+
const bodyCopy = JSON.parse(JSON.stringify(body));
|
|
434
|
+
bodyCopy.pagination = { page: 0, pageSize: 50 };
|
|
435
|
+
bodyCopy.isReady = true;
|
|
436
|
+
});
|
|
437
|
+
const { data: { session } } = await supabase.auth.getSession();
|
|
438
|
+
if (!session?.access_token) {
|
|
439
|
+
throw new Error("No active session");
|
|
440
|
+
}
|
|
441
|
+
const controller = new AbortController();
|
|
442
|
+
props.signal.addEventListener("abort", () => {
|
|
443
|
+
controller.abort();
|
|
444
|
+
});
|
|
445
|
+
const timeout = setTimeout(
|
|
446
|
+
() => controller.abort(),
|
|
447
|
+
config?.timeout ?? 15e3
|
|
448
|
+
);
|
|
449
|
+
let result = null;
|
|
450
|
+
let response2 = { error: null, data: null };
|
|
451
|
+
try {
|
|
452
|
+
const UI_ONLY_KEYS = /* @__PURE__ */ new Set(["info", "options", "display"]);
|
|
453
|
+
const filteredBody = JSON.parse(JSON.stringify(body, (key, value) => {
|
|
454
|
+
if (UI_ONLY_KEYS.has(key)) {
|
|
455
|
+
return void 0;
|
|
456
|
+
}
|
|
457
|
+
return value;
|
|
458
|
+
}));
|
|
459
|
+
filteredBody.filters = filteredBody.filters.map(normalizeFilter).filter(Boolean);
|
|
460
|
+
const orParam = parser.searchParams.get("or");
|
|
461
|
+
if (orParam) {
|
|
462
|
+
const cleanedOrParam = orParam.replace(/^\(|\)$/g, "");
|
|
463
|
+
const orConditions = cleanedOrParam.split(",");
|
|
464
|
+
const orFilters = orConditions.map((condition, idx) => {
|
|
465
|
+
const match = condition.match(/^(.+?)\.([^.]+)\.(.+)$/);
|
|
466
|
+
if (match) {
|
|
467
|
+
const [_, field, rawOp, value] = match;
|
|
468
|
+
let op = rawOp.trim();
|
|
469
|
+
switch (op) {
|
|
470
|
+
case "eq":
|
|
471
|
+
op = "=";
|
|
472
|
+
break;
|
|
473
|
+
case "neq":
|
|
474
|
+
op = "!=";
|
|
475
|
+
break;
|
|
476
|
+
case "gt":
|
|
477
|
+
op = ">";
|
|
478
|
+
break;
|
|
479
|
+
case "gte":
|
|
480
|
+
op = ">=";
|
|
481
|
+
break;
|
|
482
|
+
case "lt":
|
|
483
|
+
op = "<";
|
|
484
|
+
break;
|
|
485
|
+
case "lte":
|
|
486
|
+
op = "<=";
|
|
487
|
+
break;
|
|
488
|
+
case "like":
|
|
489
|
+
op = "contains";
|
|
490
|
+
break;
|
|
491
|
+
case "ilike":
|
|
492
|
+
op = "contains";
|
|
493
|
+
break;
|
|
494
|
+
case "in":
|
|
495
|
+
op = "in";
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
id: `or-${idx}`,
|
|
500
|
+
field: field.trim(),
|
|
501
|
+
op,
|
|
502
|
+
value: value.trim()
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
return null;
|
|
506
|
+
}).filter(Boolean);
|
|
507
|
+
if (orFilters.length > 0) {
|
|
508
|
+
filteredBody.filters = [
|
|
509
|
+
...filteredBody.filters,
|
|
510
|
+
{
|
|
511
|
+
id: "base-or-group",
|
|
512
|
+
op: "OR",
|
|
513
|
+
filters: orFilters,
|
|
514
|
+
pagination: void 0,
|
|
515
|
+
sort: void 0,
|
|
516
|
+
isReady: true
|
|
517
|
+
}
|
|
518
|
+
];
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const res = await fetch(
|
|
522
|
+
`${getSupabaseUrl()}/functions/v1/query?forceDenoVersion=2`,
|
|
523
|
+
{
|
|
524
|
+
method: "POST",
|
|
525
|
+
headers: {
|
|
526
|
+
"Content-Type": "application/json",
|
|
527
|
+
"Authorization": `Bearer ${session.access_token}`
|
|
528
|
+
},
|
|
529
|
+
body: JSON.stringify({
|
|
530
|
+
table: parser.table,
|
|
531
|
+
schema: parser.schema,
|
|
532
|
+
select: parser.select,
|
|
533
|
+
filters: {
|
|
534
|
+
id: filteredBody.id || "root",
|
|
535
|
+
op: filteredBody.op || filteredBody.operator || "AND",
|
|
536
|
+
not: filteredBody.not || filteredBody.inverted,
|
|
537
|
+
// Support both 'not' and legacy 'inverted'
|
|
538
|
+
filters: filteredBody.filters || []
|
|
539
|
+
},
|
|
540
|
+
pagination: filteredBody.pagination,
|
|
541
|
+
sort: filteredBody.sort,
|
|
542
|
+
distinctOn: filteredBody.distinctOn,
|
|
543
|
+
naturalLanguageQuery: filteredBody.naturalLanguageQuery,
|
|
544
|
+
count: currentKey === extraData.key ? "" : config?.count ?? "",
|
|
545
|
+
debug: true
|
|
546
|
+
}),
|
|
547
|
+
signal: controller.signal
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
if (!res.ok) {
|
|
551
|
+
const errorData = await res.json();
|
|
552
|
+
const errorMessage = typeof errorData?.error === "string" ? errorData.error : errorData?.error?.message || errorData?.message || "An error occurred while processing your request";
|
|
553
|
+
throw new Error(errorMessage);
|
|
554
|
+
}
|
|
555
|
+
const data = await res.json();
|
|
556
|
+
if (data.clarification) {
|
|
557
|
+
return {
|
|
558
|
+
data: [],
|
|
559
|
+
// Empty data array
|
|
560
|
+
count: 0,
|
|
561
|
+
clarification: data.clarification,
|
|
562
|
+
error: void 0
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
result = data;
|
|
566
|
+
response2 = { error: null, data };
|
|
567
|
+
} catch (err) {
|
|
568
|
+
if (err.name === "AbortError") {
|
|
569
|
+
console.error("Fetch aborted/time-out");
|
|
570
|
+
response2 = { error: new Error("This query timed out"), data: null };
|
|
571
|
+
} else if (err instanceof Error) {
|
|
572
|
+
response2 = { error: err, data: null };
|
|
573
|
+
} else {
|
|
574
|
+
const errorMessage = err?.error || err?.message || String(err);
|
|
575
|
+
response2 = { error: new Error(errorMessage), data: null };
|
|
576
|
+
}
|
|
577
|
+
} finally {
|
|
578
|
+
clearTimeout(timeout);
|
|
579
|
+
}
|
|
580
|
+
if (response2.error) {
|
|
581
|
+
throw response2.error;
|
|
582
|
+
} else if (response2.data?.error) {
|
|
583
|
+
throw new Error(response2.data.error);
|
|
584
|
+
}
|
|
585
|
+
if (result.clarification) {
|
|
586
|
+
return {
|
|
587
|
+
data: [],
|
|
588
|
+
count: 0,
|
|
589
|
+
clarification: result.clarification,
|
|
590
|
+
error: void 0
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
setExtraData((pre) => ({
|
|
594
|
+
...omit(result, "data"),
|
|
595
|
+
count: pre.key === currentKey ? pre.count : result.count,
|
|
596
|
+
key: currentKey
|
|
597
|
+
}));
|
|
598
|
+
return {
|
|
599
|
+
...result,
|
|
600
|
+
statusText: "",
|
|
601
|
+
status: result.data?.length > result.count ? 206 : 200,
|
|
602
|
+
error: response2.data?.error ?? null,
|
|
603
|
+
hasMore: result.data?.length < result.count ? true : false
|
|
604
|
+
};
|
|
605
|
+
} catch (error) {
|
|
606
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
607
|
+
console.log("Fetch aborted");
|
|
608
|
+
} else {
|
|
609
|
+
console.error("Error fetching data:", error);
|
|
610
|
+
}
|
|
611
|
+
if (error instanceof Error && error.message === "Failed to send a request to the Edge Function") {
|
|
612
|
+
throw new Error("Could not contact query server");
|
|
613
|
+
}
|
|
614
|
+
throw error;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
const response = {
|
|
619
|
+
...queryResponse,
|
|
620
|
+
data: queryResponse.data?.data,
|
|
621
|
+
count: extraData.count,
|
|
622
|
+
clarification: queryResponse.data?.clarification
|
|
623
|
+
};
|
|
624
|
+
useEffect(() => {
|
|
625
|
+
if (queryResponse.isFetched && response.count == null) {
|
|
626
|
+
queryResponse.refetch();
|
|
627
|
+
}
|
|
628
|
+
}, [response.count]);
|
|
629
|
+
useEffect(() => {
|
|
630
|
+
if (queryResponse.data?.error == null) return;
|
|
631
|
+
if (queryResponse.data?.error?.message?.includes(" does not exist")) {
|
|
632
|
+
setFilterLayer({
|
|
633
|
+
id: "root",
|
|
634
|
+
op: "AND",
|
|
635
|
+
filters: [],
|
|
636
|
+
pagination: void 0,
|
|
637
|
+
sort: [],
|
|
638
|
+
isReady: isUsable(config?.searchByDefault) ? config.searchByDefault ? false : true : true
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}, [queryResponse.data?.error]);
|
|
642
|
+
return [response, filterLayer, setFilterLayer];
|
|
643
|
+
}
|
|
644
|
+
function isSearchableColumn(columnName) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
async function executeSupabaseQuery(supabase, body, parser, extraData, signal, count) {
|
|
648
|
+
const searchParams = Array.from(parser.searchParams.entries());
|
|
649
|
+
const currentKey = `${parser.schema}${parser.table}${parser.select}${JSON.stringify(omit(body, "pagination"))}`;
|
|
650
|
+
const query = supabase.schema(parser.schema).from(parser.table).select(parser.select, {
|
|
651
|
+
count: currentKey === extraData.key ? void 0 : count || void 0
|
|
652
|
+
});
|
|
653
|
+
if (body.sort && Array.isArray(body.sort)) {
|
|
654
|
+
body.sort.forEach((s) => {
|
|
655
|
+
query.order(s.field, { ascending: s.direction === "asc" });
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const from = searchParams.find((x) => x[0].includes("offset"))?.[1];
|
|
659
|
+
const to = searchParams.find((x) => x[0].includes("limit"))?.[1];
|
|
660
|
+
searchParams.forEach(([k, v]) => {
|
|
661
|
+
if (k.includes("offset") && isUsable(v)) {
|
|
662
|
+
body.pagination.from = Number(v);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (k.includes("limit") && isUsable(v)) {
|
|
666
|
+
body.pagination.to = Number(from) + Number(v) - 1;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (k === "or") {
|
|
670
|
+
query.or(v.slice(1, v.length - 2));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
const values = v.split(".");
|
|
674
|
+
const column = k;
|
|
675
|
+
let rawCondition = values[0];
|
|
676
|
+
let value = values[1];
|
|
677
|
+
if (column == "select") return;
|
|
678
|
+
if (v.includes(".") === false) return;
|
|
679
|
+
if (rawCondition === "ilike" && !isSearchableColumn(column)) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (rawCondition === "not") {
|
|
683
|
+
rawCondition = values[1];
|
|
684
|
+
value = values[2];
|
|
685
|
+
query.not(column, rawCondition, value);
|
|
686
|
+
} else {
|
|
687
|
+
query.filter(column, rawCondition, value);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
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) {
|
|
691
|
+
query.range(body.pagination.from, body.pagination.to);
|
|
692
|
+
}
|
|
693
|
+
const result = await query.abortSignal(signal);
|
|
694
|
+
const dataLength = result.data?.length ?? 0;
|
|
695
|
+
const totalCount = result.count ?? 0;
|
|
696
|
+
return {
|
|
697
|
+
...result,
|
|
698
|
+
statusText: "",
|
|
699
|
+
status: dataLength > totalCount ? 206 : 200,
|
|
700
|
+
error: result.error,
|
|
701
|
+
hasMore: dataLength < totalCount
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
export {
|
|
706
|
+
Constants,
|
|
707
|
+
normalizeFilter,
|
|
708
|
+
useDbAdvanceFilterQuery
|
|
709
|
+
};
|
|
710
|
+
//# sourceMappingURL=chunk-7HG6G25H.js.map
|