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