@react-querybuilder/core 8.20.2 → 8.21.0
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 +4 -0
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +2261 -2113
- package/dist/cjs/react-querybuilder_core.cjs.development.js +319 -22
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +2261 -2113
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-BJKNgecE.js → convertQuery-Cw76XFIn.js} +8 -8
- package/dist/{convertQuery-BJKNgecE.js.map → convertQuery-Cw76XFIn.js.map} +1 -1
- package/dist/{convertQuery-J1CaoDxe.mjs → convertQuery-D_4J7E-Z.mjs} +2 -2
- package/dist/{convertQuery-J1CaoDxe.mjs.map → convertQuery-D_4J7E-Z.mjs.map} +1 -1
- package/dist/formatQuery.d.mts +499 -459
- package/dist/formatQuery.d.ts +499 -459
- package/dist/formatQuery.js +170 -88
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +97 -20
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/import-BVdxeIBO.d.mts +26 -0
- package/dist/import-Ddc3d_8q.d.ts +26 -0
- package/dist/{index-DlVg-QXo.d.mts → index-BSwFvkeI.d.mts} +679 -648
- package/dist/{index-DlVg-QXo.d.ts → index-BSwFvkeI.d.ts} +679 -648
- package/dist/{objectUtils-DBJI82bl.js → isRuleGroup-0JNiQgLg.js} +1 -26
- package/dist/isRuleGroup-0JNiQgLg.js.map +1 -0
- package/dist/{objectUtils-ZvPkF6u6.mjs → isRuleGroup-CqLThsbu.mjs} +2 -15
- package/dist/isRuleGroup-CqLThsbu.mjs.map +1 -0
- package/dist/objectUtils-Cr02aGxb.js +27 -0
- package/dist/objectUtils-Cr02aGxb.js.map +1 -0
- package/dist/objectUtils-DBlmJgBf.mjs +16 -0
- package/dist/objectUtils-DBlmJgBf.mjs.map +1 -0
- package/dist/parseCEL.d.mts +64 -30
- package/dist/parseCEL.d.ts +64 -30
- package/dist/parseCEL.js +91 -12
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +85 -8
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseCypher.d.mts +24 -25
- package/dist/parseCypher.d.ts +24 -25
- package/dist/parseGremlin.d.mts +18 -19
- package/dist/parseGremlin.d.ts +18 -19
- package/dist/parseJSONata.d.mts +207 -20
- package/dist/parseJSONata.d.ts +207 -20
- package/dist/parseJSONata.js +92 -7
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +80 -4
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +51 -18
- package/dist/parseJsonLogic.d.ts +51 -18
- package/dist/parseJsonLogic.js +95 -34
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +65 -6
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +89 -58
- package/dist/parseMongoDB.d.ts +89 -58
- package/dist/parseMongoDB.js +140 -15
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +128 -5
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSPARQL.d.mts +17 -18
- package/dist/parseSPARQL.d.ts +17 -18
- package/dist/parseSPARQL.js.map +1 -1
- package/dist/parseSPARQL.mjs.map +1 -1
- package/dist/parseSQL.d.mts +266 -18
- package/dist/parseSQL.d.ts +266 -18
- package/dist/parseSQL.js +163 -10
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +149 -7
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +193 -19
- package/dist/parseSpEL.d.ts +193 -19
- package/dist/parseSpEL.js +166 -7
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +142 -6
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-Bni5VgYM.js → prepareQueryObjects-C2-kTZvR.js} +5 -5
- package/dist/prepareQueryObjects-C2-kTZvR.js.map +1 -0
- package/dist/{prepareQueryObjects-BCLU20Cg.mjs → prepareQueryObjects-Q18lHCKl.mjs} +3 -3
- package/dist/prepareQueryObjects-Q18lHCKl.mjs.map +1 -0
- package/dist/query-builder-layout.css.map +1 -1
- package/dist/query-builder.css.map +1 -1
- package/dist/react-querybuilder_core.d.mts +2261 -2113
- package/dist/react-querybuilder_core.legacy-esm.d.ts +2261 -2113
- package/dist/react-querybuilder_core.legacy-esm.js +335 -40
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +309 -23
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +2261 -2113
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/styles/_layout.scss +4 -10
- package/dist/transformQuery.d.mts +91 -92
- package/dist/transformQuery.d.ts +91 -92
- package/dist/transformQuery.js +4 -3
- package/dist/transformQuery.js.map +1 -1
- package/dist/transformQuery.mjs +2 -1
- package/dist/transformQuery.mjs.map +1 -1
- package/dist/{utils-BpaOtylk.js → utils-DEwV7F6B.js} +108 -12
- package/dist/utils-DEwV7F6B.js.map +1 -0
- package/dist/{utils-CJRGiPb-.mjs → utils-Dt0D_DMV.mjs} +69 -3
- package/dist/utils-Dt0D_DMV.mjs.map +1 -0
- package/package.json +14 -14
- package/dist/import-Qs1-kgv5.d.ts +0 -27
- package/dist/import-ShTj5IdB.d.mts +0 -27
- package/dist/objectUtils-DBJI82bl.js.map +0 -1
- package/dist/objectUtils-ZvPkF6u6.mjs.map +0 -1
- package/dist/prepareQueryObjects-BCLU20Cg.mjs.map +0 -1
- package/dist/prepareQueryObjects-Bni5VgYM.js.map +0 -1
- package/dist/utils-BpaOtylk.js.map +0 -1
- package/dist/utils-CJRGiPb-.mjs.map +0 -1
package/dist/styles/_layout.scss
CHANGED
|
@@ -112,14 +112,10 @@
|
|
|
112
112
|
top: calc(-1 * var(--#{$rqb-var-prefix}spacing));
|
|
113
113
|
height: calc(50% + var(--#{$rqb-var-prefix}spacing));
|
|
114
114
|
@if $direction == rtl {
|
|
115
|
-
border-width: 0
|
|
116
|
-
var(--#{$rqb-var-prefix}branch-width)
|
|
117
|
-
var(--#{$rqb-var-prefix}branch-width)
|
|
115
|
+
border-width: 0 var(--#{$rqb-var-prefix}branch-width) var(--#{$rqb-var-prefix}branch-width)
|
|
118
116
|
0;
|
|
119
117
|
} @else {
|
|
120
|
-
border-width: 0
|
|
121
|
-
0
|
|
122
|
-
var(--#{$rqb-var-prefix}branch-width)
|
|
118
|
+
border-width: 0 0 var(--#{$rqb-var-prefix}branch-width)
|
|
123
119
|
var(--#{$rqb-var-prefix}branch-width);
|
|
124
120
|
}
|
|
125
121
|
}
|
|
@@ -145,10 +141,8 @@
|
|
|
145
141
|
&::after {
|
|
146
142
|
#{$margin-side}: calc(
|
|
147
143
|
-1 *
|
|
148
|
-
(
|
|
149
|
-
var(--#{$rqb-var-prefix}
|
|
150
|
-
var(--#{$rqb-var-prefix}border-width)
|
|
151
|
-
)
|
|
144
|
+
(var(--#{$rqb-var-prefix}branch-indent) + var(--#{$rqb-var-prefix}branch-width) +
|
|
145
|
+
var(--#{$rqb-var-prefix}border-width))
|
|
152
146
|
);
|
|
153
147
|
}
|
|
154
148
|
|
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { D as RuleGroupTypeIC, E as RuleGroupTypeAny, M as RuleGroupType, N as RuleType } from "./index-BSwFvkeI.mjs";
|
|
3
2
|
//#region src/utils/transformQuery.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Options object for {@link index!transformQuery transformQuery}.
|
|
6
|
-
*/
|
|
4
|
+
* Options object for {@link index!transformQuery transformQuery}.
|
|
5
|
+
*/
|
|
7
6
|
interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
* When a rule is encountered in the hierarchy, it will be replaced
|
|
9
|
+
* with the result of this function.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `r => r`
|
|
12
|
+
*/
|
|
14
13
|
ruleProcessor?: (rule: RuleType) => any;
|
|
15
14
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
* When a group is encountered in the hierarchy (including the root group, the
|
|
16
|
+
* query itself), it will be replaced with the result of this function.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `rg => rg`
|
|
19
|
+
*/
|
|
21
20
|
ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;
|
|
22
21
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
* For each rule and group in the query, any properties matching a key
|
|
23
|
+
* in this object will be renamed to the corresponding value. To retain both
|
|
24
|
+
* the new _and_ the original properties, set `deleteRemappedProperties`
|
|
25
|
+
* to `false`.
|
|
26
|
+
*
|
|
27
|
+
* If a key has a value of `false`, the corresponding property will be removed
|
|
28
|
+
* without being copied to a new property name. (Warning: `{ rules: false }`
|
|
29
|
+
* will prevent recursion and only return the processed root group.)
|
|
30
|
+
*
|
|
31
|
+
* @defaultValue `{}`
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```
|
|
35
|
+
* transformQuery(
|
|
36
|
+
* { combinator: 'and', not: true, rules: [] },
|
|
37
|
+
* { propertyMap: { combinator: 'AndOr', not: false } }
|
|
38
|
+
* )
|
|
39
|
+
* // Returns: { AndOr: 'and', rules: [] }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
43
42
|
propertyMap?: Record<string, string | false>;
|
|
44
43
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
* Any combinator values (including independent combinators) will be translated
|
|
45
|
+
* from the key in this object to the value.
|
|
46
|
+
*
|
|
47
|
+
* @defaultValue `{}`
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```
|
|
51
|
+
* transformQuery(
|
|
52
|
+
* { combinator: 'and', rules: [] },
|
|
53
|
+
* { combinatorMap: { and: '&&', or: '||' } }
|
|
54
|
+
* )
|
|
55
|
+
* // Returns: { combinator: '&&', rules: [] }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
59
58
|
combinatorMap?: Record<string, string>;
|
|
60
59
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
* Any operator values will be translated from the key in this object to the value.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue `{}`
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```
|
|
66
|
+
* transformQuery(
|
|
67
|
+
* { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },
|
|
68
|
+
* { operatorMap: { '=': 'is' } }
|
|
69
|
+
* )
|
|
70
|
+
* // Returns:
|
|
71
|
+
* // {
|
|
72
|
+
* // combinator: 'and',
|
|
73
|
+
* // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
78
77
|
operatorMap?: Record<string, string>;
|
|
79
78
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
* Prevents the `path` property (see {@link index!Path Path}) from being added to each
|
|
80
|
+
* rule and group in the hierarchy.
|
|
81
|
+
*
|
|
82
|
+
* @defaultValue `false`
|
|
83
|
+
*/
|
|
85
84
|
omitPath?: boolean;
|
|
86
85
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
* Original properties remapped according to the `propertyMap` option will be removed.
|
|
87
|
+
*
|
|
88
|
+
* @defaultValue `true`
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```
|
|
92
|
+
* transformQuery(
|
|
93
|
+
* { combinator: 'and', rules: [] },
|
|
94
|
+
* { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }
|
|
95
|
+
* )
|
|
96
|
+
* // Returns: { combinator: 'and', AndOr: 'and', rules: [] }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
100
99
|
deleteRemappedProperties?: boolean;
|
|
101
100
|
}
|
|
102
101
|
/**
|
|
103
|
-
* Recursively process a query heirarchy using this versatile utility function.
|
|
104
|
-
*
|
|
105
|
-
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
106
|
-
*/
|
|
102
|
+
* Recursively process a query heirarchy using this versatile utility function.
|
|
103
|
+
*
|
|
104
|
+
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
105
|
+
*/
|
|
107
106
|
declare function transformQuery(query: RuleGroupType, options?: TransformQueryOptions): any;
|
|
108
107
|
/**
|
|
109
|
-
* Recursively process a query heirarchy with independent combinators using this
|
|
110
|
-
* versatile utility function.
|
|
111
|
-
*
|
|
112
|
-
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
113
|
-
*/
|
|
108
|
+
* Recursively process a query heirarchy with independent combinators using this
|
|
109
|
+
* versatile utility function.
|
|
110
|
+
*
|
|
111
|
+
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
112
|
+
*/
|
|
114
113
|
declare function transformQuery(query: RuleGroupTypeIC, options?: TransformQueryOptions<RuleGroupTypeIC>): any;
|
|
115
114
|
//#endregion
|
|
116
115
|
export { TransformQueryOptions, transformQuery };
|
package/dist/transformQuery.d.ts
CHANGED
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { D as RuleGroupTypeIC, E as RuleGroupTypeAny, M as RuleGroupType, N as RuleType } from "./index-BSwFvkeI.js";
|
|
3
2
|
//#region src/utils/transformQuery.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Options object for {@link index!transformQuery transformQuery}.
|
|
6
|
-
*/
|
|
4
|
+
* Options object for {@link index!transformQuery transformQuery}.
|
|
5
|
+
*/
|
|
7
6
|
interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
* When a rule is encountered in the hierarchy, it will be replaced
|
|
9
|
+
* with the result of this function.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `r => r`
|
|
12
|
+
*/
|
|
14
13
|
ruleProcessor?: (rule: RuleType) => any;
|
|
15
14
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
* When a group is encountered in the hierarchy (including the root group, the
|
|
16
|
+
* query itself), it will be replaced with the result of this function.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `rg => rg`
|
|
19
|
+
*/
|
|
21
20
|
ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;
|
|
22
21
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
* For each rule and group in the query, any properties matching a key
|
|
23
|
+
* in this object will be renamed to the corresponding value. To retain both
|
|
24
|
+
* the new _and_ the original properties, set `deleteRemappedProperties`
|
|
25
|
+
* to `false`.
|
|
26
|
+
*
|
|
27
|
+
* If a key has a value of `false`, the corresponding property will be removed
|
|
28
|
+
* without being copied to a new property name. (Warning: `{ rules: false }`
|
|
29
|
+
* will prevent recursion and only return the processed root group.)
|
|
30
|
+
*
|
|
31
|
+
* @defaultValue `{}`
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```
|
|
35
|
+
* transformQuery(
|
|
36
|
+
* { combinator: 'and', not: true, rules: [] },
|
|
37
|
+
* { propertyMap: { combinator: 'AndOr', not: false } }
|
|
38
|
+
* )
|
|
39
|
+
* // Returns: { AndOr: 'and', rules: [] }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
43
42
|
propertyMap?: Record<string, string | false>;
|
|
44
43
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
* Any combinator values (including independent combinators) will be translated
|
|
45
|
+
* from the key in this object to the value.
|
|
46
|
+
*
|
|
47
|
+
* @defaultValue `{}`
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```
|
|
51
|
+
* transformQuery(
|
|
52
|
+
* { combinator: 'and', rules: [] },
|
|
53
|
+
* { combinatorMap: { and: '&&', or: '||' } }
|
|
54
|
+
* )
|
|
55
|
+
* // Returns: { combinator: '&&', rules: [] }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
59
58
|
combinatorMap?: Record<string, string>;
|
|
60
59
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
* Any operator values will be translated from the key in this object to the value.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue `{}`
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```
|
|
66
|
+
* transformQuery(
|
|
67
|
+
* { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },
|
|
68
|
+
* { operatorMap: { '=': 'is' } }
|
|
69
|
+
* )
|
|
70
|
+
* // Returns:
|
|
71
|
+
* // {
|
|
72
|
+
* // combinator: 'and',
|
|
73
|
+
* // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
78
77
|
operatorMap?: Record<string, string>;
|
|
79
78
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
* Prevents the `path` property (see {@link index!Path Path}) from being added to each
|
|
80
|
+
* rule and group in the hierarchy.
|
|
81
|
+
*
|
|
82
|
+
* @defaultValue `false`
|
|
83
|
+
*/
|
|
85
84
|
omitPath?: boolean;
|
|
86
85
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
* Original properties remapped according to the `propertyMap` option will be removed.
|
|
87
|
+
*
|
|
88
|
+
* @defaultValue `true`
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```
|
|
92
|
+
* transformQuery(
|
|
93
|
+
* { combinator: 'and', rules: [] },
|
|
94
|
+
* { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }
|
|
95
|
+
* )
|
|
96
|
+
* // Returns: { combinator: 'and', AndOr: 'and', rules: [] }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
100
99
|
deleteRemappedProperties?: boolean;
|
|
101
100
|
}
|
|
102
101
|
/**
|
|
103
|
-
* Recursively process a query heirarchy using this versatile utility function.
|
|
104
|
-
*
|
|
105
|
-
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
106
|
-
*/
|
|
102
|
+
* Recursively process a query heirarchy using this versatile utility function.
|
|
103
|
+
*
|
|
104
|
+
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
105
|
+
*/
|
|
107
106
|
declare function transformQuery(query: RuleGroupType, options?: TransformQueryOptions): any;
|
|
108
107
|
/**
|
|
109
|
-
* Recursively process a query heirarchy with independent combinators using this
|
|
110
|
-
* versatile utility function.
|
|
111
|
-
*
|
|
112
|
-
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
113
|
-
*/
|
|
108
|
+
* Recursively process a query heirarchy with independent combinators using this
|
|
109
|
+
* versatile utility function.
|
|
110
|
+
*
|
|
111
|
+
* [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)
|
|
112
|
+
*/
|
|
114
113
|
declare function transformQuery(query: RuleGroupTypeIC, options?: TransformQueryOptions<RuleGroupTypeIC>): any;
|
|
115
114
|
//#endregion
|
|
116
115
|
export { TransformQueryOptions, transformQuery };
|
package/dist/transformQuery.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_isRuleGroup = require("./isRuleGroup-0JNiQgLg.js");
|
|
3
|
+
const require_objectUtils = require("./objectUtils-Cr02aGxb.js");
|
|
3
4
|
//#region src/utils/transformQuery.ts
|
|
4
5
|
const remapProperties = (obj, propertyMap, deleteRemappedProperties) => {
|
|
5
6
|
const result = {};
|
|
@@ -19,12 +20,12 @@ function transformQuery(query, options = {}) {
|
|
|
19
20
|
const processGroup = (rg) => ({
|
|
20
21
|
...ruleGroupProcessor(remapProperties({
|
|
21
22
|
...rg,
|
|
22
|
-
...
|
|
23
|
+
...require_isRuleGroup.isRuleGroupType(rg) ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator } : {}
|
|
23
24
|
}, propertyMap, deleteRemappedProperties)),
|
|
24
25
|
...propertyMap["rules"] === false ? null : { [propertyMap["rules"] ?? "rules"]: rg.rules.map((r, idx) => {
|
|
25
26
|
const pathObject = omitPath ? null : { path: [...rg.path, idx] };
|
|
26
27
|
if (typeof r === "string") return combinatorMap[r] ?? r;
|
|
27
|
-
else if (
|
|
28
|
+
else if (require_isRuleGroup.isRuleGroup(r)) return processGroup({
|
|
28
29
|
...r,
|
|
29
30
|
...pathObject
|
|
30
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformQuery.js","names":["isUnsafeKey","isRuleGroupType","isRuleGroup"],"sources":["../src/utils/transformQuery.ts"],"sourcesContent":["/**\n * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),\n * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a\n * new query object if there were any referential changes.\n *\n * @module transformQuery\n */\n\nimport type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isRuleGroup, isRuleGroupType } from './isRuleGroup';\nimport { isUnsafeKey } from './objectUtils';\n\nconst remapProperties = (\n obj: Record<string, unknown>,\n propertyMap: Record<string, string | false>,\n deleteRemappedProperties: boolean\n): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n\n for (const key in obj) {\n if (isUnsafeKey(key)) continue;\n const mappedKey = propertyMap[key];\n if (mappedKey === false) {\n continue;\n }\n if (mappedKey && key !== mappedKey) {\n if (!isUnsafeKey(mappedKey)) {\n result[mappedKey] = obj[key];\n }\n if (!deleteRemappedProperties) {\n result[key] = obj[key];\n }\n } else {\n result[key] = obj[key];\n }\n }\n\n return result;\n};\n\n/**\n * Options object for {@link index!transformQuery transformQuery}.\n */\nexport interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {\n /**\n * When a rule is encountered in the hierarchy, it will be replaced\n * with the result of this function.\n *\n * @defaultValue `r => r`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleProcessor?: (rule: RuleType) => any;\n /**\n * When a group is encountered in the hierarchy (including the root group, the\n * query itself), it will be replaced with the result of this function.\n *\n * @defaultValue `rg => rg`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;\n /**\n * For each rule and group in the query, any properties matching a key\n * in this object will be renamed to the corresponding value. To retain both\n * the new _and_ the original properties, set `deleteRemappedProperties`\n * to `false`.\n *\n * If a key has a value of `false`, the corresponding property will be removed\n * without being copied to a new property name. (Warning: `{ rules: false }`\n * will prevent recursion and only return the processed root group.)\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', not: true, rules: [] },\n * { propertyMap: { combinator: 'AndOr', not: false } }\n * )\n * // Returns: { AndOr: 'and', rules: [] }\n * ```\n */\n propertyMap?: Record<string, string | false>;\n /**\n * Any combinator values (including independent combinators) will be translated\n * from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { combinatorMap: { and: '&&', or: '||' } }\n * )\n * // Returns: { combinator: '&&', rules: [] }\n * ```\n */\n combinatorMap?: Record<string, string>;\n /**\n * Any operator values will be translated from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },\n * { operatorMap: { '=': 'is' } }\n * )\n * // Returns:\n * // {\n * // combinator: 'and',\n * // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]\n * // }\n * ```\n */\n operatorMap?: Record<string, string>;\n /**\n * Prevents the `path` property (see {@link index!Path Path}) from being added to each\n * rule and group in the hierarchy.\n *\n * @defaultValue `false`\n */\n omitPath?: boolean;\n /**\n * Original properties remapped according to the `propertyMap` option will be removed.\n *\n * @defaultValue `true`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }\n * )\n * // Returns: { combinator: 'and', AndOr: 'and', rules: [] }\n * ```\n */\n deleteRemappedProperties?: boolean;\n}\n\n/**\n * Recursively process a query heirarchy using this versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupType,\n options?: TransformQueryOptions\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\n/**\n * Recursively process a query heirarchy with independent combinators using this\n * versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupTypeIC,\n options?: TransformQueryOptions<RuleGroupTypeIC>\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\nexport function transformQuery<RG extends RuleGroupTypeAny>(\n query: RG,\n options: TransformQueryOptions<RG> = {}\n) {\n const {\n ruleProcessor = r => r,\n ruleGroupProcessor = rg => rg,\n propertyMap = {},\n combinatorMap = {},\n operatorMap = {},\n omitPath = false,\n deleteRemappedProperties = true,\n } = options;\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const processGroup = (rg: RuleGroupTypeAny): any => ({\n ...ruleGroupProcessor(\n remapProperties(\n {\n ...rg,\n ...(isRuleGroupType(rg)\n ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator }\n : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as RG\n ),\n ...(propertyMap['rules'] === false\n ? null\n : {\n // oxlint-disable-next-line typescript/no-explicit-any\n [propertyMap['rules'] ?? 'rules']: rg.rules.map((r: any, idx) => {\n const pathObject = omitPath ? null : { path: [...rg.path!, idx] };\n if (typeof r === 'string') {\n // independent combinators\n return combinatorMap[r] ?? r;\n } else if (isRuleGroup(r)) {\n // sub-groups\n return processGroup({ ...r, ...pathObject });\n }\n // rules\n return ruleProcessor(\n remapProperties(\n {\n ...r,\n ...pathObject,\n ...('operator' in r ? { operator: operatorMap[r.operator] ?? r.operator } : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as unknown as RuleType\n );\n }),\n }),\n });\n\n return processGroup({ ...query, ...(omitPath ? null : { path: [] }) });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformQuery.js","names":["isUnsafeKey","isRuleGroupType","isRuleGroup"],"sources":["../src/utils/transformQuery.ts"],"sourcesContent":["/**\n * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),\n * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a\n * new query object if there were any referential changes.\n *\n * @module transformQuery\n */\n\nimport type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isRuleGroup, isRuleGroupType } from './isRuleGroup';\nimport { isUnsafeKey } from './objectUtils';\n\nconst remapProperties = (\n obj: Record<string, unknown>,\n propertyMap: Record<string, string | false>,\n deleteRemappedProperties: boolean\n): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n\n for (const key in obj) {\n if (isUnsafeKey(key)) continue;\n const mappedKey = propertyMap[key];\n if (mappedKey === false) {\n continue;\n }\n if (mappedKey && key !== mappedKey) {\n if (!isUnsafeKey(mappedKey)) {\n result[mappedKey] = obj[key];\n }\n if (!deleteRemappedProperties) {\n result[key] = obj[key];\n }\n } else {\n result[key] = obj[key];\n }\n }\n\n return result;\n};\n\n/**\n * Options object for {@link index!transformQuery transformQuery}.\n */\nexport interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {\n /**\n * When a rule is encountered in the hierarchy, it will be replaced\n * with the result of this function.\n *\n * @defaultValue `r => r`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleProcessor?: (rule: RuleType) => any;\n /**\n * When a group is encountered in the hierarchy (including the root group, the\n * query itself), it will be replaced with the result of this function.\n *\n * @defaultValue `rg => rg`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;\n /**\n * For each rule and group in the query, any properties matching a key\n * in this object will be renamed to the corresponding value. To retain both\n * the new _and_ the original properties, set `deleteRemappedProperties`\n * to `false`.\n *\n * If a key has a value of `false`, the corresponding property will be removed\n * without being copied to a new property name. (Warning: `{ rules: false }`\n * will prevent recursion and only return the processed root group.)\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', not: true, rules: [] },\n * { propertyMap: { combinator: 'AndOr', not: false } }\n * )\n * // Returns: { AndOr: 'and', rules: [] }\n * ```\n */\n propertyMap?: Record<string, string | false>;\n /**\n * Any combinator values (including independent combinators) will be translated\n * from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { combinatorMap: { and: '&&', or: '||' } }\n * )\n * // Returns: { combinator: '&&', rules: [] }\n * ```\n */\n combinatorMap?: Record<string, string>;\n /**\n * Any operator values will be translated from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },\n * { operatorMap: { '=': 'is' } }\n * )\n * // Returns:\n * // {\n * // combinator: 'and',\n * // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]\n * // }\n * ```\n */\n operatorMap?: Record<string, string>;\n /**\n * Prevents the `path` property (see {@link index!Path Path}) from being added to each\n * rule and group in the hierarchy.\n *\n * @defaultValue `false`\n */\n omitPath?: boolean;\n /**\n * Original properties remapped according to the `propertyMap` option will be removed.\n *\n * @defaultValue `true`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }\n * )\n * // Returns: { combinator: 'and', AndOr: 'and', rules: [] }\n * ```\n */\n deleteRemappedProperties?: boolean;\n}\n\n/**\n * Recursively process a query heirarchy using this versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupType,\n options?: TransformQueryOptions\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\n/**\n * Recursively process a query heirarchy with independent combinators using this\n * versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupTypeIC,\n options?: TransformQueryOptions<RuleGroupTypeIC>\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\nexport function transformQuery<RG extends RuleGroupTypeAny>(\n query: RG,\n options: TransformQueryOptions<RG> = {}\n) {\n const {\n ruleProcessor = r => r,\n ruleGroupProcessor = rg => rg,\n propertyMap = {},\n combinatorMap = {},\n operatorMap = {},\n omitPath = false,\n deleteRemappedProperties = true,\n } = options;\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const processGroup = (rg: RuleGroupTypeAny): any => ({\n ...ruleGroupProcessor(\n remapProperties(\n {\n ...rg,\n ...(isRuleGroupType(rg)\n ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator }\n : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as RG\n ),\n ...(propertyMap['rules'] === false\n ? null\n : {\n // oxlint-disable-next-line typescript/no-explicit-any\n [propertyMap['rules'] ?? 'rules']: rg.rules.map((r: any, idx) => {\n const pathObject = omitPath ? null : { path: [...rg.path!, idx] };\n if (typeof r === 'string') {\n // independent combinators\n return combinatorMap[r] ?? r;\n } else if (isRuleGroup(r)) {\n // sub-groups\n return processGroup({ ...r, ...pathObject });\n }\n // rules\n return ruleProcessor(\n remapProperties(\n {\n ...r,\n ...pathObject,\n ...('operator' in r ? { operator: operatorMap[r.operator] ?? r.operator } : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as unknown as RuleType\n );\n }),\n }),\n });\n\n return processGroup({ ...query, ...(omitPath ? null : { path: [] }) });\n}\n"],"mappings":";;;;AAYA,MAAM,mBACJ,KACA,aACA,6BAC4B;CAC5B,MAAM,SAAkC,CAAC;CAEzC,KAAK,MAAM,OAAO,KAAK;EACrB,IAAIA,oBAAAA,YAAY,GAAG,GAAG;EACtB,MAAM,YAAY,YAAY;EAC9B,IAAI,cAAc,OAChB;EAEF,IAAI,aAAa,QAAQ,WAAW;GAClC,IAAI,CAACA,oBAAAA,YAAY,SAAS,GACxB,OAAO,aAAa,IAAI;GAE1B,IAAI,CAAC,0BACH,OAAO,OAAO,IAAI;EAEtB,OACE,OAAO,OAAO,IAAI;CAEtB;CAEA,OAAO;AACT;AA4HA,SAAgB,eACd,OACA,UAAqC,CAAC,GACtC;CACA,MAAM,EACJ,iBAAgB,MAAK,GACrB,sBAAqB,OAAM,IAC3B,cAAc,CAAC,GACf,gBAAgB,CAAC,GACjB,cAAc,CAAC,GACf,WAAW,OACX,2BAA2B,SACzB;CAGJ,MAAM,gBAAgB,QAA+B;EACnD,GAAG,mBACD,gBACE;GACE,GAAG;GACH,GAAIC,oBAAAA,gBAAgB,EAAE,IAClB,EAAE,YAAY,cAAc,GAAG,eAAe,GAAG,WAAW,IAC5D,CAAC;EACP,GACA,aACA,wBACF,CACF;EACA,GAAI,YAAY,aAAa,QACzB,OACA,GAEG,YAAY,YAAY,UAAU,GAAG,MAAM,KAAK,GAAQ,QAAQ;GAC/D,MAAM,aAAa,WAAW,OAAO,EAAE,MAAM,CAAC,GAAG,GAAG,MAAO,GAAG,EAAE;GAChE,IAAI,OAAO,MAAM,UAEf,OAAO,cAAc,MAAM;QACtB,IAAIC,oBAAAA,YAAY,CAAC,GAEtB,OAAO,aAAa;IAAE,GAAG;IAAG,GAAG;GAAW,CAAC;GAG7C,OAAO,cACL,gBACE;IACE,GAAG;IACH,GAAG;IACH,GAAI,cAAc,IAAI,EAAE,UAAU,YAAY,EAAE,aAAa,EAAE,SAAS,IAAI,CAAC;GAC/E,GACA,aACA,wBACF,CACF;EACF,CAAC,EACH;CACN;CAEA,OAAO,aAAa;EAAE,GAAG;EAAO,GAAI,WAAW,OAAO,EAAE,MAAM,CAAC,EAAE;CAAG,CAAC;AACvE"}
|
package/dist/transformQuery.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as isRuleGroupType, t as isRuleGroup } from "./isRuleGroup-CqLThsbu.mjs";
|
|
2
|
+
import { t as isUnsafeKey } from "./objectUtils-DBlmJgBf.mjs";
|
|
2
3
|
//#region src/utils/transformQuery.ts
|
|
3
4
|
const remapProperties = (obj, propertyMap, deleteRemappedProperties) => {
|
|
4
5
|
const result = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformQuery.mjs","names":[],"sources":["../src/utils/transformQuery.ts"],"sourcesContent":["/**\n * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),\n * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a\n * new query object if there were any referential changes.\n *\n * @module transformQuery\n */\n\nimport type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isRuleGroup, isRuleGroupType } from './isRuleGroup';\nimport { isUnsafeKey } from './objectUtils';\n\nconst remapProperties = (\n obj: Record<string, unknown>,\n propertyMap: Record<string, string | false>,\n deleteRemappedProperties: boolean\n): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n\n for (const key in obj) {\n if (isUnsafeKey(key)) continue;\n const mappedKey = propertyMap[key];\n if (mappedKey === false) {\n continue;\n }\n if (mappedKey && key !== mappedKey) {\n if (!isUnsafeKey(mappedKey)) {\n result[mappedKey] = obj[key];\n }\n if (!deleteRemappedProperties) {\n result[key] = obj[key];\n }\n } else {\n result[key] = obj[key];\n }\n }\n\n return result;\n};\n\n/**\n * Options object for {@link index!transformQuery transformQuery}.\n */\nexport interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {\n /**\n * When a rule is encountered in the hierarchy, it will be replaced\n * with the result of this function.\n *\n * @defaultValue `r => r`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleProcessor?: (rule: RuleType) => any;\n /**\n * When a group is encountered in the hierarchy (including the root group, the\n * query itself), it will be replaced with the result of this function.\n *\n * @defaultValue `rg => rg`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;\n /**\n * For each rule and group in the query, any properties matching a key\n * in this object will be renamed to the corresponding value. To retain both\n * the new _and_ the original properties, set `deleteRemappedProperties`\n * to `false`.\n *\n * If a key has a value of `false`, the corresponding property will be removed\n * without being copied to a new property name. (Warning: `{ rules: false }`\n * will prevent recursion and only return the processed root group.)\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', not: true, rules: [] },\n * { propertyMap: { combinator: 'AndOr', not: false } }\n * )\n * // Returns: { AndOr: 'and', rules: [] }\n * ```\n */\n propertyMap?: Record<string, string | false>;\n /**\n * Any combinator values (including independent combinators) will be translated\n * from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { combinatorMap: { and: '&&', or: '||' } }\n * )\n * // Returns: { combinator: '&&', rules: [] }\n * ```\n */\n combinatorMap?: Record<string, string>;\n /**\n * Any operator values will be translated from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },\n * { operatorMap: { '=': 'is' } }\n * )\n * // Returns:\n * // {\n * // combinator: 'and',\n * // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]\n * // }\n * ```\n */\n operatorMap?: Record<string, string>;\n /**\n * Prevents the `path` property (see {@link index!Path Path}) from being added to each\n * rule and group in the hierarchy.\n *\n * @defaultValue `false`\n */\n omitPath?: boolean;\n /**\n * Original properties remapped according to the `propertyMap` option will be removed.\n *\n * @defaultValue `true`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }\n * )\n * // Returns: { combinator: 'and', AndOr: 'and', rules: [] }\n * ```\n */\n deleteRemappedProperties?: boolean;\n}\n\n/**\n * Recursively process a query heirarchy using this versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupType,\n options?: TransformQueryOptions\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\n/**\n * Recursively process a query heirarchy with independent combinators using this\n * versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupTypeIC,\n options?: TransformQueryOptions<RuleGroupTypeIC>\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\nexport function transformQuery<RG extends RuleGroupTypeAny>(\n query: RG,\n options: TransformQueryOptions<RG> = {}\n) {\n const {\n ruleProcessor = r => r,\n ruleGroupProcessor = rg => rg,\n propertyMap = {},\n combinatorMap = {},\n operatorMap = {},\n omitPath = false,\n deleteRemappedProperties = true,\n } = options;\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const processGroup = (rg: RuleGroupTypeAny): any => ({\n ...ruleGroupProcessor(\n remapProperties(\n {\n ...rg,\n ...(isRuleGroupType(rg)\n ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator }\n : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as RG\n ),\n ...(propertyMap['rules'] === false\n ? null\n : {\n // oxlint-disable-next-line typescript/no-explicit-any\n [propertyMap['rules'] ?? 'rules']: rg.rules.map((r: any, idx) => {\n const pathObject = omitPath ? null : { path: [...rg.path!, idx] };\n if (typeof r === 'string') {\n // independent combinators\n return combinatorMap[r] ?? r;\n } else if (isRuleGroup(r)) {\n // sub-groups\n return processGroup({ ...r, ...pathObject });\n }\n // rules\n return ruleProcessor(\n remapProperties(\n {\n ...r,\n ...pathObject,\n ...('operator' in r ? { operator: operatorMap[r.operator] ?? r.operator } : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as unknown as RuleType\n );\n }),\n }),\n });\n\n return processGroup({ ...query, ...(omitPath ? null : { path: [] }) });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformQuery.mjs","names":[],"sources":["../src/utils/transformQuery.ts"],"sourcesContent":["/**\n * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),\n * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a\n * new query object if there were any referential changes.\n *\n * @module transformQuery\n */\n\nimport type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isRuleGroup, isRuleGroupType } from './isRuleGroup';\nimport { isUnsafeKey } from './objectUtils';\n\nconst remapProperties = (\n obj: Record<string, unknown>,\n propertyMap: Record<string, string | false>,\n deleteRemappedProperties: boolean\n): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n\n for (const key in obj) {\n if (isUnsafeKey(key)) continue;\n const mappedKey = propertyMap[key];\n if (mappedKey === false) {\n continue;\n }\n if (mappedKey && key !== mappedKey) {\n if (!isUnsafeKey(mappedKey)) {\n result[mappedKey] = obj[key];\n }\n if (!deleteRemappedProperties) {\n result[key] = obj[key];\n }\n } else {\n result[key] = obj[key];\n }\n }\n\n return result;\n};\n\n/**\n * Options object for {@link index!transformQuery transformQuery}.\n */\nexport interface TransformQueryOptions<RG extends RuleGroupTypeAny = RuleGroupType> {\n /**\n * When a rule is encountered in the hierarchy, it will be replaced\n * with the result of this function.\n *\n * @defaultValue `r => r`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleProcessor?: (rule: RuleType) => any;\n /**\n * When a group is encountered in the hierarchy (including the root group, the\n * query itself), it will be replaced with the result of this function.\n *\n * @defaultValue `rg => rg`\n */\n // oxlint-disable-next-line typescript/no-explicit-any\n ruleGroupProcessor?: (ruleGroup: RG) => Record<string, any>;\n /**\n * For each rule and group in the query, any properties matching a key\n * in this object will be renamed to the corresponding value. To retain both\n * the new _and_ the original properties, set `deleteRemappedProperties`\n * to `false`.\n *\n * If a key has a value of `false`, the corresponding property will be removed\n * without being copied to a new property name. (Warning: `{ rules: false }`\n * will prevent recursion and only return the processed root group.)\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', not: true, rules: [] },\n * { propertyMap: { combinator: 'AndOr', not: false } }\n * )\n * // Returns: { AndOr: 'and', rules: [] }\n * ```\n */\n propertyMap?: Record<string, string | false>;\n /**\n * Any combinator values (including independent combinators) will be translated\n * from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { combinatorMap: { and: '&&', or: '||' } }\n * )\n * // Returns: { combinator: '&&', rules: [] }\n * ```\n */\n combinatorMap?: Record<string, string>;\n /**\n * Any operator values will be translated from the key in this object to the value.\n *\n * @defaultValue `{}`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [{ field: 'name', operator: '=', value: 'Steve Vai' }] },\n * { operatorMap: { '=': 'is' } }\n * )\n * // Returns:\n * // {\n * // combinator: 'and',\n * // rules: [{ field: 'name', operator: 'is', value: 'Steve Vai' }]\n * // }\n * ```\n */\n operatorMap?: Record<string, string>;\n /**\n * Prevents the `path` property (see {@link index!Path Path}) from being added to each\n * rule and group in the hierarchy.\n *\n * @defaultValue `false`\n */\n omitPath?: boolean;\n /**\n * Original properties remapped according to the `propertyMap` option will be removed.\n *\n * @defaultValue `true`\n *\n * @example\n * ```\n * transformQuery(\n * { combinator: 'and', rules: [] },\n * { propertyMap: { combinator: 'AndOr' }, deleteRemappedProperties: false }\n * )\n * // Returns: { combinator: 'and', AndOr: 'and', rules: [] }\n * ```\n */\n deleteRemappedProperties?: boolean;\n}\n\n/**\n * Recursively process a query heirarchy using this versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupType,\n options?: TransformQueryOptions\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\n/**\n * Recursively process a query heirarchy with independent combinators using this\n * versatile utility function.\n *\n * [Documentation](https://react-querybuilder.js.org/docs/utils/misc#transformquery)\n */\nexport function transformQuery(\n query: RuleGroupTypeIC,\n options?: TransformQueryOptions<RuleGroupTypeIC>\n // oxlint-disable-next-line typescript/no-explicit-any\n): any;\nexport function transformQuery<RG extends RuleGroupTypeAny>(\n query: RG,\n options: TransformQueryOptions<RG> = {}\n) {\n const {\n ruleProcessor = r => r,\n ruleGroupProcessor = rg => rg,\n propertyMap = {},\n combinatorMap = {},\n operatorMap = {},\n omitPath = false,\n deleteRemappedProperties = true,\n } = options;\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const processGroup = (rg: RuleGroupTypeAny): any => ({\n ...ruleGroupProcessor(\n remapProperties(\n {\n ...rg,\n ...(isRuleGroupType(rg)\n ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator }\n : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as RG\n ),\n ...(propertyMap['rules'] === false\n ? null\n : {\n // oxlint-disable-next-line typescript/no-explicit-any\n [propertyMap['rules'] ?? 'rules']: rg.rules.map((r: any, idx) => {\n const pathObject = omitPath ? null : { path: [...rg.path!, idx] };\n if (typeof r === 'string') {\n // independent combinators\n return combinatorMap[r] ?? r;\n } else if (isRuleGroup(r)) {\n // sub-groups\n return processGroup({ ...r, ...pathObject });\n }\n // rules\n return ruleProcessor(\n remapProperties(\n {\n ...r,\n ...pathObject,\n ...('operator' in r ? { operator: operatorMap[r.operator] ?? r.operator } : {}),\n },\n propertyMap,\n deleteRemappedProperties\n ) as unknown as RuleType\n );\n }),\n }),\n });\n\n return processGroup({ ...query, ...(omitPath ? null : { path: [] }) });\n}\n"],"mappings":";;;AAYA,MAAM,mBACJ,KACA,aACA,6BAC4B;CAC5B,MAAM,SAAkC,CAAC;CAEzC,KAAK,MAAM,OAAO,KAAK;EACrB,IAAI,YAAY,GAAG,GAAG;EACtB,MAAM,YAAY,YAAY;EAC9B,IAAI,cAAc,OAChB;EAEF,IAAI,aAAa,QAAQ,WAAW;GAClC,IAAI,CAAC,YAAY,SAAS,GACxB,OAAO,aAAa,IAAI;GAE1B,IAAI,CAAC,0BACH,OAAO,OAAO,IAAI;EAEtB,OACE,OAAO,OAAO,IAAI;CAEtB;CAEA,OAAO;AACT;AA4HA,SAAgB,eACd,OACA,UAAqC,CAAC,GACtC;CACA,MAAM,EACJ,iBAAgB,MAAK,GACrB,sBAAqB,OAAM,IAC3B,cAAc,CAAC,GACf,gBAAgB,CAAC,GACjB,cAAc,CAAC,GACf,WAAW,OACX,2BAA2B,SACzB;CAGJ,MAAM,gBAAgB,QAA+B;EACnD,GAAG,mBACD,gBACE;GACE,GAAG;GACH,GAAI,gBAAgB,EAAE,IAClB,EAAE,YAAY,cAAc,GAAG,eAAe,GAAG,WAAW,IAC5D,CAAC;EACP,GACA,aACA,wBACF,CACF;EACA,GAAI,YAAY,aAAa,QACzB,OACA,GAEG,YAAY,YAAY,UAAU,GAAG,MAAM,KAAK,GAAQ,QAAQ;GAC/D,MAAM,aAAa,WAAW,OAAO,EAAE,MAAM,CAAC,GAAG,GAAG,MAAO,GAAG,EAAE;GAChE,IAAI,OAAO,MAAM,UAEf,OAAO,cAAc,MAAM;QACtB,IAAI,YAAY,CAAC,GAEtB,OAAO,aAAa;IAAE,GAAG;IAAG,GAAG;GAAW,CAAC;GAG7C,OAAO,cACL,gBACE;IACE,GAAG;IACH,GAAG;IACH,GAAI,cAAc,IAAI,EAAE,UAAU,YAAY,EAAE,aAAa,EAAE,SAAS,IAAI,CAAC;GAC/E,GACA,aACA,wBACF,CACF;EACF,CAAC,EACH;CACN;CAEA,OAAO,aAAa;EAAE,GAAG;EAAO,GAAI,WAAW,OAAO,EAAE,MAAM,CAAC,EAAE;CAAG,CAAC;AACvE"}
|