@taruvi/refine-providers 1.3.3 → 1.3.4-beta.1
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/README.md +23 -8
- package/dist/index.cjs +342 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -8
- package/dist/index.d.ts +77 -8
- package/dist/index.js +332 -97
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -108,6 +108,13 @@ mutate({ resource: "posts", id: 1 });
|
|
|
108
108
|
|
|
109
109
|
### Filtering
|
|
110
110
|
|
|
111
|
+
List `getList` filters use an explicit **`TaruviListFilters`** shape:
|
|
112
|
+
|
|
113
|
+
- **`FlatFilterLeaf[]`** (array of `{ field, operator, value }`) → top-level **`field__op`** query params via `Database.filters(field, op, value)` (including FK traversal like `department_id.name`).
|
|
114
|
+
- **`LogicalCrudFilter`** (object `{ operator: "and" | "or", value: [...] }`) → JSON **`filters`** tree via `Database.filters(tree)`.
|
|
115
|
+
|
|
116
|
+
Legacy Refine **`CrudFilter[]`** is still accepted: all field leaves → flat array; a single root `and`/`or` object → logical object; mixed lists fall back to the JSON tree. Bracket keys from `convertRefineFilters` remain for helpers / Storage flatten mode.
|
|
117
|
+
|
|
111
118
|
Full support for Refine filter operators:
|
|
112
119
|
|
|
113
120
|
```tsx
|
|
@@ -116,25 +123,33 @@ const { data } = useList({
|
|
|
116
123
|
filters: [
|
|
117
124
|
{ field: "status", operator: "eq", value: "published" },
|
|
118
125
|
{ field: "views", operator: "gte", value: 100 },
|
|
119
|
-
{ field: "title", operator: "
|
|
126
|
+
{ field: "title", operator: "containss", value: "refine" },
|
|
120
127
|
{ field: "category", operator: "in", value: ["tech", "news"] },
|
|
121
128
|
],
|
|
122
129
|
});
|
|
123
130
|
```
|
|
124
131
|
|
|
125
|
-
**
|
|
132
|
+
**Refine → backend operator mapping (important):**
|
|
133
|
+
|
|
134
|
+
Wire suffixes match the platform (`contains` = case-insensitive, `containss` = case-sensitive). Refine aliases map to the same tokens, e.g. `icontains` → `contains`. See `REFINE_OPERATOR_MAP` in [`src/utils.ts`](src/utils.ts).
|
|
135
|
+
|
|
136
|
+
**More operators:**
|
|
126
137
|
|
|
127
138
|
| Operator | Description | Example |
|
|
128
139
|
|----------|-------------|---------|
|
|
129
140
|
| `eq` | Equal | `status = "active"` |
|
|
130
141
|
| `ne` | Not equal | `status != "deleted"` |
|
|
131
142
|
| `lt`, `gt`, `lte`, `gte` | Comparison | `age >= 18` |
|
|
132
|
-
| `contains`, `ncontains` |
|
|
133
|
-
| `containss`, `ncontainss` |
|
|
134
|
-
| `startswith`, `endswith` |
|
|
135
|
-
| `
|
|
136
|
-
| `
|
|
137
|
-
| `
|
|
143
|
+
| `contains`, `ncontains` | Case-insensitive contains / not | FK traversal, search UX |
|
|
144
|
+
| `containss`, `ncontainss` | Case-sensitive contains / not | |
|
|
145
|
+
| `startswith`, `endswith` | Case-insensitive prefix/suffix | |
|
|
146
|
+
| `startswiths`, `endswiths` | Case-sensitive prefix/suffix | |
|
|
147
|
+
| `in`, `nin`, `ina`, `nina` | Array membership | |
|
|
148
|
+
| `null`, `nnull` | Null checks | |
|
|
149
|
+
| `between`, `nbetween` | Range | |
|
|
150
|
+
| `acontains`, … `aelement`, `naelement` | PostgreSQL array ops | |
|
|
151
|
+
| `rcontains`, … `rstrictright` | PostgreSQL range ops | |
|
|
152
|
+
| `like`, `ilike`, `search` | Pattern / FTS | |
|
|
138
153
|
|
|
139
154
|
### Sorting & Pagination
|
|
140
155
|
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
|
|
|
11
11
|
|
|
12
12
|
// package.json
|
|
13
13
|
var package_default = {
|
|
14
|
-
version: "1.3.
|
|
14
|
+
version: "1.3.4-beta.1"};
|
|
15
15
|
|
|
16
16
|
// src/utils.ts
|
|
17
17
|
var REFINE_OPERATOR_MAP = {
|
|
@@ -24,65 +24,306 @@ var REFINE_OPERATOR_MAP = {
|
|
|
24
24
|
gt: "gt",
|
|
25
25
|
lte: "lte",
|
|
26
26
|
gte: "gte",
|
|
27
|
-
// String
|
|
27
|
+
// String matching — Taruvi wire suffix matches platform filter_translator.
|
|
28
28
|
contains: "contains",
|
|
29
29
|
ncontains: "ncontains",
|
|
30
|
+
containss: "containss",
|
|
31
|
+
ncontainss: "ncontainss",
|
|
30
32
|
startswith: "startswith",
|
|
31
33
|
nstartswith: "nstartswith",
|
|
32
34
|
endswith: "endswith",
|
|
33
35
|
nendswith: "nendswith",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
startswiths: "startswiths",
|
|
37
|
+
nstartswiths: "nstartswiths",
|
|
38
|
+
endswiths: "endswiths",
|
|
39
|
+
nendswiths: "nendswiths",
|
|
40
|
+
// Refine aliases → platform insensitive tokens
|
|
41
|
+
icontains: "contains",
|
|
42
|
+
nicontains: "ncontains",
|
|
43
|
+
istartswith: "startswith",
|
|
44
|
+
nistartswith: "nstartswith",
|
|
45
|
+
iendswith: "endswith",
|
|
46
|
+
niendswith: "nendswith",
|
|
47
|
+
// Array / membership
|
|
42
48
|
in: "in",
|
|
43
49
|
nin: "nin",
|
|
50
|
+
ina: "ina",
|
|
51
|
+
nina: "nina",
|
|
44
52
|
// Null checks
|
|
45
53
|
null: "null",
|
|
46
54
|
nnull: "nnull",
|
|
47
55
|
// Range
|
|
48
56
|
between: "between",
|
|
49
|
-
nbetween: "nbetween"
|
|
57
|
+
nbetween: "nbetween",
|
|
58
|
+
// PostgreSQL array ops (pass-through suffix names)
|
|
59
|
+
acontains: "acontains",
|
|
60
|
+
nacontains: "nacontains",
|
|
61
|
+
acontainedby: "acontainedby",
|
|
62
|
+
nacontainedby: "nacontainedby",
|
|
63
|
+
aoverlap: "aoverlap",
|
|
64
|
+
naoverlap: "naoverlap",
|
|
65
|
+
aelement: "aelement",
|
|
66
|
+
naelement: "naelement",
|
|
67
|
+
// PostgreSQL range column ops
|
|
68
|
+
rcontains: "rcontains",
|
|
69
|
+
rcontainedby: "rcontainedby",
|
|
70
|
+
roverlaps: "roverlaps",
|
|
71
|
+
radjacent: "radjacent",
|
|
72
|
+
rstrictleft: "rstrictleft",
|
|
73
|
+
rstrictright: "rstrictright",
|
|
74
|
+
// Raw pattern / field search
|
|
75
|
+
like: "like",
|
|
76
|
+
ilike: "ilike",
|
|
77
|
+
search: "search"
|
|
50
78
|
};
|
|
51
|
-
|
|
79
|
+
var COMMA_VALUE_OPERATORS = /* @__PURE__ */ new Set([
|
|
80
|
+
"in",
|
|
81
|
+
"nin",
|
|
82
|
+
"ina",
|
|
83
|
+
"nina",
|
|
84
|
+
"between",
|
|
85
|
+
"nbetween",
|
|
86
|
+
"acontains",
|
|
87
|
+
"nacontains",
|
|
88
|
+
"acontainedby",
|
|
89
|
+
"nacontainedby",
|
|
90
|
+
"aoverlap",
|
|
91
|
+
"naoverlap",
|
|
92
|
+
"aelement",
|
|
93
|
+
"naelement",
|
|
94
|
+
"rcontains",
|
|
95
|
+
"rcontainedby",
|
|
96
|
+
"roverlaps",
|
|
97
|
+
"radjacent",
|
|
98
|
+
"rstrictleft",
|
|
99
|
+
"rstrictright"
|
|
100
|
+
]);
|
|
101
|
+
function isLogicalFilter(filter) {
|
|
102
|
+
return typeof filter === "object" && filter !== null && "operator" in filter && (filter.operator === "and" || filter.operator === "or") && "value" in filter && Array.isArray(filter.value);
|
|
103
|
+
}
|
|
104
|
+
function isFieldFilter(filter) {
|
|
105
|
+
return typeof filter === "object" && filter !== null && "field" in filter && "operator" in filter && typeof filter.field === "string" && typeof filter.operator === "string";
|
|
106
|
+
}
|
|
107
|
+
function isFlatFilterList(filters) {
|
|
108
|
+
if (!Array.isArray(filters)) return false;
|
|
109
|
+
return filters.every((f) => {
|
|
110
|
+
if (!isFieldFilter(f)) return false;
|
|
111
|
+
const leaf = f;
|
|
112
|
+
if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function isLogicalCrudFilter(filters) {
|
|
122
|
+
return typeof filters === "object" && filters !== null && !Array.isArray(filters) && isLogicalFilter(filters);
|
|
123
|
+
}
|
|
124
|
+
function normalizeTaruviListFilters(filters) {
|
|
125
|
+
if (filters === void 0 || filters === null) return void 0;
|
|
126
|
+
if (isLogicalCrudFilter(filters)) return filters;
|
|
127
|
+
if (isFlatFilterList(filters)) return filters;
|
|
128
|
+
if (!Array.isArray(filters) || filters.length === 0) return void 0;
|
|
129
|
+
if (filters.length === 1 && isLogicalFilter(filters[0])) {
|
|
130
|
+
return filters[0];
|
|
131
|
+
}
|
|
132
|
+
if (filters.every(isFieldFilter)) {
|
|
133
|
+
return filters;
|
|
134
|
+
}
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
function collectFlatLeaves(filters) {
|
|
138
|
+
if (!filters?.length) return [];
|
|
139
|
+
const leaves = [];
|
|
140
|
+
const walk = (group) => {
|
|
141
|
+
for (const filter of group) {
|
|
142
|
+
if (isLogicalFilter(filter)) {
|
|
143
|
+
if (filter.operator === "or") return false;
|
|
144
|
+
if (!walk(filter.value)) return false;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!isFieldFilter(filter)) return false;
|
|
148
|
+
const leaf = filter;
|
|
149
|
+
if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
|
|
153
|
+
console.warn(`Unknown Refine operator: ${leaf.operator}`);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
leaves.push({
|
|
157
|
+
field: leaf.field,
|
|
158
|
+
operator: leaf.operator,
|
|
159
|
+
value: leaf.value
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
};
|
|
164
|
+
if (!walk(filters)) return null;
|
|
165
|
+
return leaves;
|
|
166
|
+
}
|
|
167
|
+
function refineOperatorToBackendKey(operator) {
|
|
168
|
+
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
169
|
+
if (suffix === void 0) return operator;
|
|
170
|
+
return suffix === "" ? "eq" : suffix;
|
|
171
|
+
}
|
|
172
|
+
function formatRefineLeafValue(operator, value) {
|
|
173
|
+
if (COMMA_VALUE_OPERATORS.has(operator)) {
|
|
174
|
+
return Array.isArray(value) ? value.join(",") : String(value);
|
|
175
|
+
}
|
|
176
|
+
if (operator === "null" || operator === "nnull") {
|
|
177
|
+
return "true";
|
|
178
|
+
}
|
|
179
|
+
return String(value);
|
|
180
|
+
}
|
|
181
|
+
function encodeLeafFlat(field, operator, value, params) {
|
|
182
|
+
if (value === void 0 || value === null && operator !== "null") {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
186
|
+
if (suffix === void 0) {
|
|
187
|
+
console.warn(`Unknown Refine operator: ${operator}`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
191
|
+
params[paramKey] = formatRefineLeafValue(operator, value);
|
|
192
|
+
}
|
|
193
|
+
function encodeCrudFilterBracket(filter, path, out) {
|
|
194
|
+
if (isLogicalFilter(filter)) {
|
|
195
|
+
const op = filter.operator;
|
|
196
|
+
out[`${path}[operator]`] = op;
|
|
197
|
+
const children = filter.value;
|
|
198
|
+
children.forEach((child, i) => {
|
|
199
|
+
encodeCrudFilterBracket(child, `${path}[value][${i}]`, out);
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!isFieldFilter(filter)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const leaf = filter;
|
|
207
|
+
const { field, operator, value } = leaf;
|
|
208
|
+
if (value === void 0 || value === null && operator !== "null") {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
212
|
+
if (suffix === void 0) {
|
|
213
|
+
console.warn(`Unknown Refine operator: ${operator}`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
out[`${path}[field]`] = field;
|
|
217
|
+
out[`${path}[operator]`] = refineOperatorToBackendKey(operator);
|
|
218
|
+
out[`${path}[value]`] = formatRefineLeafValue(operator, value);
|
|
219
|
+
}
|
|
220
|
+
function isLogicalBackendNode(n) {
|
|
221
|
+
return !("field" in n) && (n.operator === "and" || n.operator === "or");
|
|
222
|
+
}
|
|
223
|
+
function jsonLeafValue(operator, value) {
|
|
224
|
+
if (operator === "null" || operator === "nnull") return true;
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
function crudFilterToBackendNodeOrNull(filter) {
|
|
228
|
+
if (isLogicalFilter(filter)) {
|
|
229
|
+
const children = filter.value.map(crudFilterToBackendNodeOrNull).filter((n) => n !== null);
|
|
230
|
+
if (children.length === 0) return null;
|
|
231
|
+
return { operator: filter.operator, value: children };
|
|
232
|
+
}
|
|
233
|
+
if (isFieldFilter(filter)) {
|
|
234
|
+
const leaf = filter;
|
|
235
|
+
if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
|
|
239
|
+
console.warn(`Unknown Refine operator: ${leaf.operator}`);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
const backendOp = refineOperatorToBackendKey(leaf.operator);
|
|
243
|
+
return {
|
|
244
|
+
field: leaf.field,
|
|
245
|
+
operator: backendOp,
|
|
246
|
+
value: jsonLeafValue(leaf.operator, leaf.value)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function convertRefineFiltersToBackendTree(filters) {
|
|
252
|
+
if (!filters?.length) return null;
|
|
253
|
+
const nodes = filters.map(crudFilterToBackendNodeOrNull).filter((n) => n !== null);
|
|
254
|
+
if (nodes.length === 0) return null;
|
|
255
|
+
if (nodes.length === 1 && isLogicalBackendNode(nodes[0])) {
|
|
256
|
+
return [nodes[0]];
|
|
257
|
+
}
|
|
258
|
+
return [{ operator: "and", value: nodes }];
|
|
259
|
+
}
|
|
260
|
+
function convertLogicalFilterToBackendTree(filter) {
|
|
261
|
+
const node = crudFilterToBackendNodeOrNull(filter);
|
|
262
|
+
if (!node || !isLogicalBackendNode(node)) return null;
|
|
263
|
+
return [node];
|
|
264
|
+
}
|
|
265
|
+
function encodeFlatFilterListToParams(leaves) {
|
|
266
|
+
const params = {};
|
|
267
|
+
for (const leaf of leaves) {
|
|
268
|
+
encodeLeafFlat(leaf.field, leaf.operator, leaf.value, params);
|
|
269
|
+
}
|
|
270
|
+
return params;
|
|
271
|
+
}
|
|
272
|
+
function convertRefineFiltersFlattened(filters) {
|
|
52
273
|
if (!filters || filters.length === 0) return {};
|
|
53
274
|
const params = {};
|
|
54
275
|
for (const filter of filters) {
|
|
55
|
-
if (
|
|
276
|
+
if (isLogicalFilter(filter)) {
|
|
56
277
|
if (filter.value && Array.isArray(filter.value)) {
|
|
57
|
-
const nested =
|
|
278
|
+
const nested = convertRefineFiltersFlattened(
|
|
279
|
+
filter.value
|
|
280
|
+
);
|
|
58
281
|
Object.assign(params, nested);
|
|
59
282
|
}
|
|
60
283
|
continue;
|
|
61
284
|
}
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
68
|
-
if (suffix === void 0) {
|
|
69
|
-
console.warn(`Unknown Refine operator: ${operator}`);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
73
|
-
if (operator === "in" || operator === "nin") {
|
|
74
|
-
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
75
|
-
} else if (operator === "between" || operator === "nbetween") {
|
|
76
|
-
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
77
|
-
} else if (operator === "null" || operator === "nnull") {
|
|
78
|
-
params[paramKey] = "true";
|
|
79
|
-
} else {
|
|
80
|
-
params[paramKey] = String(value);
|
|
81
|
-
}
|
|
285
|
+
if (isFieldFilter(filter)) {
|
|
286
|
+
const leaf = filter;
|
|
287
|
+
encodeLeafFlat(leaf.field, leaf.operator, leaf.value, params);
|
|
82
288
|
}
|
|
83
289
|
}
|
|
84
290
|
return params;
|
|
85
291
|
}
|
|
292
|
+
function convertRefineFilters(filters, options) {
|
|
293
|
+
if (!filters || filters.length === 0) return {};
|
|
294
|
+
if (options?.logicalEncoding === "flatten") {
|
|
295
|
+
return convertRefineFiltersFlattened(filters);
|
|
296
|
+
}
|
|
297
|
+
const hasLogical = filters.some(isLogicalFilter);
|
|
298
|
+
if (!hasLogical) {
|
|
299
|
+
const params = {};
|
|
300
|
+
for (const filter of filters) {
|
|
301
|
+
if (isFieldFilter(filter)) {
|
|
302
|
+
const leaf = filter;
|
|
303
|
+
encodeLeafFlat(leaf.field, leaf.operator, leaf.value, params);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return params;
|
|
307
|
+
}
|
|
308
|
+
if (filters.length === 1 && isLogicalFilter(filters[0])) {
|
|
309
|
+
const out2 = {};
|
|
310
|
+
encodeCrudFilterBracket(filters[0], "filters[0]", out2);
|
|
311
|
+
return out2;
|
|
312
|
+
}
|
|
313
|
+
const out = {};
|
|
314
|
+
out["filters[0][operator]"] = "and";
|
|
315
|
+
filters.forEach((f, i) => {
|
|
316
|
+
encodeCrudFilterBracket(f, `filters[0][value][${i}]`, out);
|
|
317
|
+
});
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
function applyRefineQueryParamsToDatabase(query, params) {
|
|
321
|
+
let result = query;
|
|
322
|
+
for (const [key, val] of Object.entries(params)) {
|
|
323
|
+
result = result.filters(key, "eq", val);
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
86
327
|
function convertRefineSorters(sorters) {
|
|
87
328
|
if (!sorters || sorters.length === 0) return void 0;
|
|
88
329
|
return sorters.map((sort) => sort.order === "desc" ? `-${sort.field}` : sort.field).join(",");
|
|
@@ -138,16 +379,7 @@ function formatHaving(having) {
|
|
|
138
379
|
continue;
|
|
139
380
|
}
|
|
140
381
|
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
141
|
-
|
|
142
|
-
if (operator === "in" || operator === "nin") {
|
|
143
|
-
paramValue = Array.isArray(value) ? value.join(",") : String(value);
|
|
144
|
-
} else if (operator === "between" || operator === "nbetween") {
|
|
145
|
-
paramValue = Array.isArray(value) ? value.join(",") : String(value);
|
|
146
|
-
} else if (operator === "null" || operator === "nnull") {
|
|
147
|
-
paramValue = "true";
|
|
148
|
-
} else {
|
|
149
|
-
paramValue = String(value);
|
|
150
|
-
}
|
|
382
|
+
const paramValue = formatRefineLeafValue(operator, value);
|
|
151
383
|
params.push(`${paramKey}=${paramValue}`);
|
|
152
384
|
}
|
|
153
385
|
}
|
|
@@ -179,45 +411,42 @@ function applyAggregations(query, meta) {
|
|
|
179
411
|
}
|
|
180
412
|
return result;
|
|
181
413
|
}
|
|
182
|
-
function
|
|
183
|
-
if (!filters || filters.length === 0) return query;
|
|
414
|
+
function applyFlatFilterList(query, leaves) {
|
|
184
415
|
let result = query;
|
|
185
|
-
for (const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const { field, operator, value } = filter;
|
|
194
|
-
if (value === void 0 || value === null && operator !== "null") continue;
|
|
195
|
-
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
196
|
-
if (suffix === void 0) {
|
|
197
|
-
console.warn(`Unknown Refine operator: ${operator}`);
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
201
|
-
let paramValue;
|
|
202
|
-
if (operator === "in" || operator === "nin" || operator === "between" || operator === "nbetween") {
|
|
203
|
-
paramValue = Array.isArray(value) ? value.join(",") : String(value);
|
|
204
|
-
} else if (operator === "null" || operator === "nnull") {
|
|
205
|
-
paramValue = "true";
|
|
206
|
-
} else {
|
|
207
|
-
paramValue = String(value);
|
|
208
|
-
}
|
|
209
|
-
result = result.filter(paramKey, "eq", paramValue);
|
|
210
|
-
}
|
|
416
|
+
for (const { field, operator, value } of leaves) {
|
|
417
|
+
const backendOp = refineOperatorToBackendKey(operator);
|
|
418
|
+
const formatted = formatRefineLeafValue(operator, value);
|
|
419
|
+
result = result.filters(
|
|
420
|
+
field,
|
|
421
|
+
backendOp,
|
|
422
|
+
formatted
|
|
423
|
+
);
|
|
211
424
|
}
|
|
212
425
|
return result;
|
|
213
426
|
}
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
427
|
+
function applyFilters(query, filters) {
|
|
428
|
+
const normalized = normalizeTaruviListFilters(filters);
|
|
429
|
+
if (normalized === void 0) {
|
|
430
|
+
if (Array.isArray(filters) && filters.length > 0) {
|
|
431
|
+
const tree = convertRefineFiltersToBackendTree(filters);
|
|
432
|
+
if (tree) return query.filters(tree);
|
|
433
|
+
}
|
|
434
|
+
return query;
|
|
219
435
|
}
|
|
220
|
-
|
|
436
|
+
if (isFlatFilterList(normalized)) {
|
|
437
|
+
if (normalized.length === 0) return query;
|
|
438
|
+
return applyFlatFilterList(query, normalized);
|
|
439
|
+
}
|
|
440
|
+
if (isLogicalCrudFilter(normalized)) {
|
|
441
|
+
const tree = convertLogicalFilterToBackendTree(normalized);
|
|
442
|
+
if (!tree) return query;
|
|
443
|
+
return query.filters(tree);
|
|
444
|
+
}
|
|
445
|
+
return query;
|
|
446
|
+
}
|
|
447
|
+
function applySorters(query, sorters) {
|
|
448
|
+
const ordering = convertRefineSorters(sorters);
|
|
449
|
+
return ordering ? query.orderBy(ordering) : query;
|
|
221
450
|
}
|
|
222
451
|
function applyPagination(query, pagination) {
|
|
223
452
|
if (!pagination || pagination.mode === "off") return query;
|
|
@@ -305,7 +534,7 @@ function dataProvider(client) {
|
|
|
305
534
|
}
|
|
306
535
|
const idColumn = getIdColumn(taruviMeta);
|
|
307
536
|
let query = new sdk.Database(client).from(tableName);
|
|
308
|
-
query = query.
|
|
537
|
+
query = query.filters(idColumn, "in", ids.map(String));
|
|
309
538
|
query = applyPopulate(query, taruviMeta);
|
|
310
539
|
const response = await query.execute();
|
|
311
540
|
return { data: response.data };
|
|
@@ -422,7 +651,7 @@ function storageDataProvider(client) {
|
|
|
422
651
|
const getBucketName = (resource, meta) => meta?.bucketName ?? resource;
|
|
423
652
|
const buildFilters = (params) => {
|
|
424
653
|
const filters = {
|
|
425
|
-
...convertRefineFilters(params.filters),
|
|
654
|
+
...convertRefineFilters(params.filters, { logicalEncoding: "flatten" }),
|
|
426
655
|
...convertRefinePagination(params.pagination)
|
|
427
656
|
};
|
|
428
657
|
const ordering = convertRefineSorters(params.sorters);
|
|
@@ -930,20 +1159,27 @@ function analyticsDataProvider(client) {
|
|
|
930
1159
|
exports._cachedUser = null;
|
|
931
1160
|
function authProvider(client) {
|
|
932
1161
|
const auth = new sdk.Auth(client);
|
|
933
|
-
function redirectToLogin() {
|
|
934
|
-
exports._cachedUser = null;
|
|
935
|
-
auth.login();
|
|
936
|
-
}
|
|
937
1162
|
return {
|
|
938
|
-
login: async () => {
|
|
939
|
-
|
|
1163
|
+
login: async (params = {}) => {
|
|
1164
|
+
const { callbackUrl, redirect = true } = params;
|
|
1165
|
+
if (auth.isUserAuthenticated()) {
|
|
1166
|
+
return {
|
|
1167
|
+
success: true,
|
|
1168
|
+
redirectTo: callbackUrl || "/"
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
if (redirect) {
|
|
1172
|
+
auth.login(callbackUrl);
|
|
940
1173
|
return {
|
|
941
1174
|
success: true
|
|
942
1175
|
};
|
|
943
1176
|
}
|
|
944
|
-
redirectToLogin();
|
|
945
1177
|
return {
|
|
946
|
-
success:
|
|
1178
|
+
success: false,
|
|
1179
|
+
error: {
|
|
1180
|
+
name: "LoginError",
|
|
1181
|
+
message: "Login failed. Please try again."
|
|
1182
|
+
}
|
|
947
1183
|
};
|
|
948
1184
|
},
|
|
949
1185
|
logout: async (params = {}) => {
|
|
@@ -956,20 +1192,19 @@ function authProvider(client) {
|
|
|
956
1192
|
};
|
|
957
1193
|
},
|
|
958
1194
|
check: async () => {
|
|
959
|
-
if (!auth.
|
|
960
|
-
return { authenticated: false };
|
|
961
|
-
}
|
|
962
|
-
const isValid = await auth.isUserAuthenticated();
|
|
963
|
-
if (!isValid) {
|
|
964
|
-
return { authenticated: false };
|
|
1195
|
+
if (!auth.isUserAuthenticated()) {
|
|
1196
|
+
return { authenticated: false, redirectTo: "/login" };
|
|
965
1197
|
}
|
|
966
1198
|
return { authenticated: true };
|
|
967
1199
|
},
|
|
968
1200
|
onError: async (error) => {
|
|
969
1201
|
const status = error?.statusCode || error?.status || error?.response?.status;
|
|
970
1202
|
if (status === 401) {
|
|
971
|
-
|
|
972
|
-
|
|
1203
|
+
return {
|
|
1204
|
+
logout: true,
|
|
1205
|
+
redirectTo: "/login",
|
|
1206
|
+
error
|
|
1207
|
+
};
|
|
973
1208
|
}
|
|
974
1209
|
if (status === 403) {
|
|
975
1210
|
return { error };
|
|
@@ -1112,15 +1347,26 @@ exports.REFINE_OPERATOR_MAP = REFINE_OPERATOR_MAP;
|
|
|
1112
1347
|
exports.accessControlProvider = accessControlProvider;
|
|
1113
1348
|
exports.analyticsDataProvider = analyticsDataProvider;
|
|
1114
1349
|
exports.appDataProvider = appDataProvider;
|
|
1350
|
+
exports.applyRefineQueryParamsToDatabase = applyRefineQueryParamsToDatabase;
|
|
1115
1351
|
exports.authProvider = authProvider;
|
|
1116
1352
|
exports.buildQueryString = buildQueryString;
|
|
1117
1353
|
exports.buildRefineQueryParams = buildRefineQueryParams;
|
|
1354
|
+
exports.collectFlatLeaves = collectFlatLeaves;
|
|
1355
|
+
exports.convertLogicalFilterToBackendTree = convertLogicalFilterToBackendTree;
|
|
1118
1356
|
exports.convertRefineFilters = convertRefineFilters;
|
|
1357
|
+
exports.convertRefineFiltersToBackendTree = convertRefineFiltersToBackendTree;
|
|
1119
1358
|
exports.convertRefinePagination = convertRefinePagination;
|
|
1120
1359
|
exports.convertRefineSorters = convertRefineSorters;
|
|
1121
1360
|
exports.dataProvider = dataProvider;
|
|
1361
|
+
exports.encodeCrudFilterBracket = encodeCrudFilterBracket;
|
|
1362
|
+
exports.encodeFlatFilterListToParams = encodeFlatFilterListToParams;
|
|
1363
|
+
exports.formatRefineLeafValue = formatRefineLeafValue;
|
|
1122
1364
|
exports.functionsDataProvider = functionsDataProvider;
|
|
1123
1365
|
exports.handleError = handleError;
|
|
1366
|
+
exports.isFlatFilterList = isFlatFilterList;
|
|
1367
|
+
exports.isLogicalCrudFilter = isLogicalCrudFilter;
|
|
1368
|
+
exports.normalizeTaruviListFilters = normalizeTaruviListFilters;
|
|
1369
|
+
exports.refineOperatorToBackendKey = refineOperatorToBackendKey;
|
|
1124
1370
|
exports.storageDataProvider = storageDataProvider;
|
|
1125
1371
|
exports.userDataProvider = userDataProvider;
|
|
1126
1372
|
//# sourceMappingURL=index.cjs.map
|