@softr/sdk 0.0.4 → 0.0.6
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/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/query-C6022JhD.js +528 -0
- package/dist/tanstack.d.ts +1 -1
- package/dist/tanstack.js +199 -28
- package/dist/types-CtUT4jd7.d.ts +653 -0
- package/package.json +4 -2
- package/dist/types-DCiIbAw_.d.ts +0 -237
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as VisibilityHandle, C as AccessError, D as SoftrUserGroupId, E as SoftrContext, F as isUnauthenticatedError, I as q, M as isAccessError, N as isAlreadySignedInError, O as SoftrUserGroups, P as isForbiddenError, S as AccessCheck, T as RouteVisibility, _ as SoftrSDK, a as CreateOptions, b as WorkflowAPI, c as GetOptions, d as ListResult, f as MetricOptions, g as SoftrRecord, h as SoftrPermissions, i as ChartDataResult, j as defineVisibility, k as User, l as IntegrationAPI, m as SoftrMe, n as AuthAPI, o as DatasourceAPI, p as MetricResult, r as ChartDataOptions, s as DatasourcePermissions, t as AggregationFunction, u as ListOptions, v as SoftrUser, w as AccessReason, x as AccessBehaviour, y as UpdateOptions } from "./types-CtUT4jd7.js";
|
|
2
2
|
import * as _tanstack_react_start0 from "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/auth/session.d.ts
|
|
@@ -34,4 +34,4 @@ declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddleware
|
|
|
34
34
|
user: User | null;
|
|
35
35
|
}>;
|
|
36
36
|
//#endregion
|
|
37
|
-
export { type AccessBehaviour, type AccessCheck, type AccessError, type AccessReason, type AuthAPI, type DatasourceAPI, type DatasourcePermissions, type ListOptions, type ListResult, type RouteVisibility, type SoftrContext, type SoftrMe, type SoftrPermissions, type SoftrRecord, type SoftrSDK, type SoftrUser, type SoftrUserGroupId, type SoftrUserGroups, type User, type VisibilityHandle, type WorkflowAPI, defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, softrAuthMiddleware };
|
|
37
|
+
export { type AccessBehaviour, type AccessCheck, type AccessError, type AccessReason, type AggregationFunction, type AuthAPI, type ChartDataOptions, type ChartDataResult, type CreateOptions, type DatasourceAPI, type DatasourcePermissions, type GetOptions, type IntegrationAPI, type ListOptions, type ListResult, type MetricOptions, type MetricResult, type RouteVisibility, type SoftrContext, type SoftrMe, type SoftrPermissions, type SoftrRecord, type SoftrSDK, type SoftrUser, type SoftrUserGroupId, type SoftrUserGroups, type UpdateOptions, type User, type VisibilityHandle, type WorkflowAPI, defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, q, softrAuthMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as q } from "./query-C6022JhD.js";
|
|
1
2
|
import { redirect } from "@tanstack/react-router";
|
|
2
3
|
import { createMiddleware, createServerFn, getGlobalStartContext } from "@tanstack/react-start";
|
|
3
4
|
|
|
@@ -166,4 +167,4 @@ function softrAuthMiddleware() {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
//#endregion
|
|
169
|
-
export { defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, softrAuthMiddleware };
|
|
170
|
+
export { defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, q, softrAuthMiddleware };
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
//#region src/core/query.ts
|
|
2
|
+
const INTERNAL_KIND = Symbol("KIND");
|
|
3
|
+
/**
|
|
4
|
+
* Query builder for filter queries. This exist to alleviate the (LLM?) mental overhead. API filter schema is a bit
|
|
5
|
+
* verbose and confusing, even when dealing with very basic queries. So to fall into the pit of success, aim here
|
|
6
|
+
* is to simplify filtering as much as possible.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* single filter
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const query = q.text("title").contains("hello");
|
|
12
|
+
*
|
|
13
|
+
* const json = buildFilterCriteria(query);
|
|
14
|
+
* // result
|
|
15
|
+
* {
|
|
16
|
+
* "filterCriteria": {
|
|
17
|
+
* "filterConditionGroup": {
|
|
18
|
+
* "logicalOperator": "AND"
|
|
19
|
+
* "filterGroups": [{
|
|
20
|
+
* "logicalOperator": "AND",
|
|
21
|
+
* "filters": [{
|
|
22
|
+
* "subject": "title",
|
|
23
|
+
* "type": "TEXT",
|
|
24
|
+
* "operator": "CONTAINS",
|
|
25
|
+
* "value": "hello"
|
|
26
|
+
* }],
|
|
27
|
+
* }]
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* combining multiple filters
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const query = q.and(
|
|
38
|
+
* q.text("title").contains("hello"),
|
|
39
|
+
* q.number("views").is(100),
|
|
40
|
+
* q.or(
|
|
41
|
+
* q.text("author").is("John"),
|
|
42
|
+
* q.boolean("isPublished").is(true)
|
|
43
|
+
* )
|
|
44
|
+
* );
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const q = {
|
|
48
|
+
select(mapping) {
|
|
49
|
+
return mapping;
|
|
50
|
+
},
|
|
51
|
+
and(...filters) {
|
|
52
|
+
return {
|
|
53
|
+
logicalOperator: "AND",
|
|
54
|
+
filters,
|
|
55
|
+
[INTERNAL_KIND]: "LOGICAL_GROUP"
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
or(...filters) {
|
|
59
|
+
return {
|
|
60
|
+
logicalOperator: "OR",
|
|
61
|
+
filters,
|
|
62
|
+
[INTERNAL_KIND]: "LOGICAL_GROUP"
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
text(subject) {
|
|
66
|
+
const filter = {
|
|
67
|
+
subject,
|
|
68
|
+
type: "TEXT",
|
|
69
|
+
[INTERNAL_KIND]: "FILTER"
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
is(value) {
|
|
73
|
+
return {
|
|
74
|
+
...filter,
|
|
75
|
+
operator: "IS",
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
isNot(value) {
|
|
80
|
+
return {
|
|
81
|
+
...filter,
|
|
82
|
+
operator: "IS_NOT",
|
|
83
|
+
value
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
contains(value) {
|
|
87
|
+
return {
|
|
88
|
+
...filter,
|
|
89
|
+
operator: "CONTAINS",
|
|
90
|
+
value
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
isOneOf(value) {
|
|
94
|
+
return {
|
|
95
|
+
...filter,
|
|
96
|
+
operator: "IS_ONE_OF",
|
|
97
|
+
value
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
isNoneOf(value) {
|
|
101
|
+
return {
|
|
102
|
+
...filter,
|
|
103
|
+
operator: "IS_NONE_OF",
|
|
104
|
+
value
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
startsWith(value) {
|
|
108
|
+
return {
|
|
109
|
+
...filter,
|
|
110
|
+
operator: "STARTS_WITH",
|
|
111
|
+
value
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
endsWith(value) {
|
|
115
|
+
return {
|
|
116
|
+
...filter,
|
|
117
|
+
operator: "ENDS_WITH",
|
|
118
|
+
value
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
hasAllOf(value) {
|
|
122
|
+
return {
|
|
123
|
+
...filter,
|
|
124
|
+
operator: "HAS_ALL_OF",
|
|
125
|
+
value
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
isEmpty() {
|
|
129
|
+
return {
|
|
130
|
+
...filter,
|
|
131
|
+
operator: "IS_EMPTY"
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
isNotEmpty() {
|
|
135
|
+
return {
|
|
136
|
+
...filter,
|
|
137
|
+
operator: "IS_NOT_EMPTY"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
boolean(subject) {
|
|
143
|
+
const filter = {
|
|
144
|
+
subject,
|
|
145
|
+
type: "BOOLEAN",
|
|
146
|
+
[INTERNAL_KIND]: "FILTER"
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
is(value) {
|
|
150
|
+
return {
|
|
151
|
+
...filter,
|
|
152
|
+
operator: "IS",
|
|
153
|
+
value
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
isNot(value) {
|
|
157
|
+
return {
|
|
158
|
+
...filter,
|
|
159
|
+
operator: "IS_NOT",
|
|
160
|
+
value
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
isEmpty() {
|
|
164
|
+
return {
|
|
165
|
+
...filter,
|
|
166
|
+
operator: "IS_EMPTY"
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
isNotEmpty() {
|
|
170
|
+
return {
|
|
171
|
+
...filter,
|
|
172
|
+
operator: "IS_NOT_EMPTY"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
number(subject) {
|
|
178
|
+
const filter = {
|
|
179
|
+
subject,
|
|
180
|
+
type: "NUMERIC",
|
|
181
|
+
[INTERNAL_KIND]: "FILTER"
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
is(value) {
|
|
185
|
+
return {
|
|
186
|
+
...filter,
|
|
187
|
+
operator: "IS",
|
|
188
|
+
value: value.toString()
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
isNot(value) {
|
|
192
|
+
return {
|
|
193
|
+
...filter,
|
|
194
|
+
operator: "IS_NOT",
|
|
195
|
+
value: value.toString()
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
gt(value) {
|
|
199
|
+
return {
|
|
200
|
+
...filter,
|
|
201
|
+
operator: "GT",
|
|
202
|
+
value: value.toString()
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
gte(value) {
|
|
206
|
+
return {
|
|
207
|
+
...filter,
|
|
208
|
+
operator: "GTE",
|
|
209
|
+
value: value.toString()
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
lt(value) {
|
|
213
|
+
return {
|
|
214
|
+
...filter,
|
|
215
|
+
operator: "LT",
|
|
216
|
+
value: value.toString()
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
lte(value) {
|
|
220
|
+
return {
|
|
221
|
+
...filter,
|
|
222
|
+
operator: "LTE",
|
|
223
|
+
value: value.toString()
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
between(start, end) {
|
|
227
|
+
return {
|
|
228
|
+
...filter,
|
|
229
|
+
operator: "BETWEEN",
|
|
230
|
+
value: [start.toString(), end.toString()]
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
isEmpty() {
|
|
234
|
+
return {
|
|
235
|
+
...filter,
|
|
236
|
+
operator: "IS_EMPTY"
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
isNotEmpty() {
|
|
240
|
+
return {
|
|
241
|
+
...filter,
|
|
242
|
+
operator: "IS_NOT_EMPTY"
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
array(subject) {
|
|
248
|
+
const filter = {
|
|
249
|
+
subject,
|
|
250
|
+
type: "ARRAY",
|
|
251
|
+
[INTERNAL_KIND]: "FILTER"
|
|
252
|
+
};
|
|
253
|
+
return {
|
|
254
|
+
is(value) {
|
|
255
|
+
return {
|
|
256
|
+
...filter,
|
|
257
|
+
operator: "IS",
|
|
258
|
+
value
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
isOneOf(value) {
|
|
262
|
+
return {
|
|
263
|
+
...filter,
|
|
264
|
+
operator: "IS_ONE_OF",
|
|
265
|
+
value
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
isNoneOf(value) {
|
|
269
|
+
return {
|
|
270
|
+
...filter,
|
|
271
|
+
operator: "IS_NONE_OF",
|
|
272
|
+
value
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
hasAllOf(value) {
|
|
276
|
+
return {
|
|
277
|
+
...filter,
|
|
278
|
+
operator: "HAS_ALL_OF",
|
|
279
|
+
value
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
isEmpty() {
|
|
283
|
+
return {
|
|
284
|
+
...filter,
|
|
285
|
+
operator: "IS_EMPTY"
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
isNotEmpty() {
|
|
289
|
+
return {
|
|
290
|
+
...filter,
|
|
291
|
+
operator: "IS_NOT_EMPTY"
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
date(subject) {
|
|
297
|
+
const filter = {
|
|
298
|
+
subject,
|
|
299
|
+
type: "DATE",
|
|
300
|
+
[INTERNAL_KIND]: "FILTER"
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
is(value) {
|
|
304
|
+
return {
|
|
305
|
+
...filter,
|
|
306
|
+
operator: "IS",
|
|
307
|
+
value
|
|
308
|
+
};
|
|
309
|
+
},
|
|
310
|
+
isNot(value) {
|
|
311
|
+
return {
|
|
312
|
+
...filter,
|
|
313
|
+
operator: "IS_NOT",
|
|
314
|
+
value
|
|
315
|
+
};
|
|
316
|
+
},
|
|
317
|
+
gt(value) {
|
|
318
|
+
return {
|
|
319
|
+
...filter,
|
|
320
|
+
operator: "GT",
|
|
321
|
+
value
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
gte(value) {
|
|
325
|
+
return {
|
|
326
|
+
...filter,
|
|
327
|
+
operator: "GTE",
|
|
328
|
+
value
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
lt(value) {
|
|
332
|
+
return {
|
|
333
|
+
...filter,
|
|
334
|
+
operator: "LT",
|
|
335
|
+
value
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
lte(value) {
|
|
339
|
+
return {
|
|
340
|
+
...filter,
|
|
341
|
+
operator: "LTE",
|
|
342
|
+
value
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
between(start, end) {
|
|
346
|
+
return {
|
|
347
|
+
...filter,
|
|
348
|
+
operator: "BETWEEN",
|
|
349
|
+
value: [start, end]
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
isNotBetween(start, end) {
|
|
353
|
+
return {
|
|
354
|
+
...filter,
|
|
355
|
+
operator: "IS_NOT_BETWEEN",
|
|
356
|
+
value: [start, end]
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
isEmpty() {
|
|
360
|
+
return {
|
|
361
|
+
...filter,
|
|
362
|
+
operator: "IS_EMPTY"
|
|
363
|
+
};
|
|
364
|
+
},
|
|
365
|
+
isNotEmpty() {
|
|
366
|
+
return {
|
|
367
|
+
...filter,
|
|
368
|
+
operator: "IS_NOT_EMPTY"
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
},
|
|
373
|
+
asc(subject) {
|
|
374
|
+
return {
|
|
375
|
+
sortingField: subject,
|
|
376
|
+
sortType: "ASC",
|
|
377
|
+
[INTERNAL_KIND]: "ORDER_BY"
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
desc(subject) {
|
|
381
|
+
return {
|
|
382
|
+
sortingField: subject,
|
|
383
|
+
sortType: "DESC",
|
|
384
|
+
[INTERNAL_KIND]: "ORDER_BY"
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Converts filter utility conditions to a format our backend supports
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```tsx
|
|
393
|
+
* const query = q.text("title").contains("hello");
|
|
394
|
+
*
|
|
395
|
+
* const json = buildFilterCriteria(query);
|
|
396
|
+
* // result
|
|
397
|
+
* {
|
|
398
|
+
* "filterCriteria": {
|
|
399
|
+
* "filterConditionGroup": {
|
|
400
|
+
* "logicalOperator": "AND"
|
|
401
|
+
* "filterGroups": [{
|
|
402
|
+
* "logicalOperator": "AND",
|
|
403
|
+
* "filters": [{
|
|
404
|
+
* "subject": "title",
|
|
405
|
+
* "type": "TEXT",
|
|
406
|
+
* "operator": "CONTAINS",
|
|
407
|
+
* "value": "hello"
|
|
408
|
+
* }],
|
|
409
|
+
* }]
|
|
410
|
+
* }
|
|
411
|
+
* }
|
|
412
|
+
* }
|
|
413
|
+
*
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
function buildFilterCriteria(input) {
|
|
417
|
+
if (!(INTERNAL_KIND in input)) throw new Error("Filters cannot be constructed manually. Use the 'q' helper.");
|
|
418
|
+
if (isFilter(input)) return { filterConditionGroup: {
|
|
419
|
+
logicalOperator: "AND",
|
|
420
|
+
filterGroups: [{
|
|
421
|
+
logicalOperator: "AND",
|
|
422
|
+
filters: [stripInternalKind(input)]
|
|
423
|
+
}]
|
|
424
|
+
} };
|
|
425
|
+
if (isFilterGroup(input)) {
|
|
426
|
+
if (input.filters.length === 0) return { filterConditionGroup: {
|
|
427
|
+
logicalOperator: input.logicalOperator,
|
|
428
|
+
filterGroups: []
|
|
429
|
+
} };
|
|
430
|
+
return { filterConditionGroup: {
|
|
431
|
+
logicalOperator: input.logicalOperator,
|
|
432
|
+
filterGroups: input.filters.map((inner) => {
|
|
433
|
+
if (isFilter(inner)) return {
|
|
434
|
+
logicalOperator: "AND",
|
|
435
|
+
filters: [stripInternalKind(inner)]
|
|
436
|
+
};
|
|
437
|
+
if (!inner.filters.every(isFilter)) throw new Error("Cannot nest filter groups more than three levels deep.");
|
|
438
|
+
return {
|
|
439
|
+
logicalOperator: inner.logicalOperator,
|
|
440
|
+
filters: inner.filters.map(stripInternalKind)
|
|
441
|
+
};
|
|
442
|
+
})
|
|
443
|
+
} };
|
|
444
|
+
}
|
|
445
|
+
throw new Error("Unknown filter kind: " + input[INTERNAL_KIND]);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Converts order-by utility conditions to a format our backend supports
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* single orderBy
|
|
452
|
+
* ```tsx
|
|
453
|
+
* const orderBy = buildOrderBy(q.asc("title"));
|
|
454
|
+
* // result: [{ sortingField: "title", sortType: "ASC" }]
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* multiple orderBys
|
|
459
|
+
* ```tsx
|
|
460
|
+
* const orderBy = buildOrderBy([q.desc("createdAt"), q.asc("title")]);
|
|
461
|
+
* // result: [
|
|
462
|
+
* // { sortingField: "createdAt", sortType: "DESC" },
|
|
463
|
+
* // { sortingField: "title", sortType: "ASC" }
|
|
464
|
+
* // ]
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
function buildOrderBy(input) {
|
|
468
|
+
const orderBys = Array.isArray(input) ? input : [input];
|
|
469
|
+
if (!orderBys.every((ob) => ob[INTERNAL_KIND] === "ORDER_BY")) throw new Error("orderBy conditions cannot be constructed manually. Use the 'q' helper.");
|
|
470
|
+
return orderBys.map((orderBy) => ({
|
|
471
|
+
sortingField: orderBy.sortingField,
|
|
472
|
+
sortType: orderBy.sortType
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
function dealiasOrderBy(orderbys, aliases) {
|
|
476
|
+
return orderbys.map((orderBy) => {
|
|
477
|
+
const subject = aliases[orderBy.sortingField];
|
|
478
|
+
if (!subject) throw new Error(`Could not find an alias for subject "${orderBy.sortingField}"`);
|
|
479
|
+
return {
|
|
480
|
+
...orderBy,
|
|
481
|
+
sortingField: subject
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Replaces filter subjects with their aliased values.
|
|
487
|
+
*
|
|
488
|
+
* Throws an error if any filter subject does not have a corresponding alias in the provided mapping.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```tsx
|
|
492
|
+
* const criteria = buildFilterCriteria(q.text("name").contains("John"));
|
|
493
|
+
* const aliases = { name: "abcxy123" };
|
|
494
|
+
* const dealiased = dealiasFilterCriteria(criteria, aliases);
|
|
495
|
+
* // Result: filter subject is now "abcxyz123" instead of "name"
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
function dealiasFilterCriteria(criteria, aliases) {
|
|
499
|
+
if (!criteria.filterConditionGroup) return criteria;
|
|
500
|
+
return { filterConditionGroup: {
|
|
501
|
+
...criteria.filterConditionGroup,
|
|
502
|
+
filterGroups: criteria.filterConditionGroup.filterGroups.map((group) => ({
|
|
503
|
+
...group,
|
|
504
|
+
filters: group.filters.map(dealiasFilter)
|
|
505
|
+
}))
|
|
506
|
+
} };
|
|
507
|
+
function dealiasFilter(filter) {
|
|
508
|
+
const subject = aliases[filter.subject];
|
|
509
|
+
if (!subject) throw new Error(`Could not find an alias for subject "${subject}"`);
|
|
510
|
+
return {
|
|
511
|
+
...filter,
|
|
512
|
+
subject
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function stripInternalKind(item) {
|
|
517
|
+
const { [INTERNAL_KIND]: _,...rest } = item;
|
|
518
|
+
return rest;
|
|
519
|
+
}
|
|
520
|
+
function isFilterGroup(item) {
|
|
521
|
+
return item[INTERNAL_KIND] === "LOGICAL_GROUP";
|
|
522
|
+
}
|
|
523
|
+
function isFilter(item) {
|
|
524
|
+
return item[INTERNAL_KIND] === "FILTER";
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
//#endregion
|
|
528
|
+
export { q as a, dealiasOrderBy as i, buildOrderBy as n, dealiasFilterCriteria as r, buildFilterCriteria as t };
|
package/dist/tanstack.d.ts
CHANGED