@react-querybuilder/core 8.14.0 → 8.14.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/dist/{basic-Dxm6jWFu.d.ts → basic-BXJVfD0P.d.ts} +68 -50
- package/dist/{basic-GFsWfi0Z.d.mts → basic-CNIjb6rI.d.mts} +68 -50
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +178 -127
- package/dist/cjs/react-querybuilder_core.cjs.development.js +299 -251
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +178 -127
- 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-DAj92cbM.mjs → convertQuery-B5Qm_6ut.mjs} +30 -22
- package/dist/convertQuery-B5Qm_6ut.mjs.map +1 -0
- package/dist/convertQuery-DfZehtnd.js +94 -0
- package/dist/convertQuery-DfZehtnd.js.map +1 -0
- package/dist/{export-_wipiqJZ.d.mts → export-6x7MilFR.d.mts} +2 -3
- package/dist/{export-6VbkhCrf.d.ts → export-CpJOQuZv.d.ts} +2 -3
- package/dist/formatQuery.d.mts +4 -3
- package/dist/formatQuery.d.ts +4 -3
- package/dist/formatQuery.js +18 -50
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +17 -49
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-D8M7awTx.d.ts → import-B5Iq8XmL.d.ts} +2 -3
- package/dist/{import-DRmutNSr.d.mts → import-Bltb2mT4.d.mts} +2 -3
- package/dist/{isRuleGroup-Cjk1Q2mj.js → isRuleGroup-BCwaLzDj.js} +38 -40
- package/dist/isRuleGroup-BCwaLzDj.js.map +1 -0
- package/dist/{isRuleGroup-DztIOOKa.mjs → isRuleGroup-LzP0HCKh.mjs} +2 -4
- package/dist/isRuleGroup-LzP0HCKh.mjs.map +1 -0
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +9 -11
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +7 -10
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +2 -3
- package/dist/parseJSONata.d.ts +2 -3
- package/dist/parseJSONata.js +37 -5611
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +11 -13
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +3 -4
- package/dist/parseJsonLogic.d.ts +3 -4
- package/dist/parseJsonLogic.js +20 -21
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +19 -21
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +2 -3
- package/dist/parseMongoDB.d.ts +2 -3
- package/dist/parseMongoDB.js +7 -8
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +6 -8
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSQL.d.mts +2 -3
- package/dist/parseSQL.d.ts +2 -3
- package/dist/parseSQL.js +9 -11
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +7 -10
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +2 -3
- package/dist/parseSpEL.d.ts +2 -3
- package/dist/parseSpEL.js +11 -2700
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +7 -9
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BxWvIPI4.js → prepareQueryObjects-Dc8rqsYM.js} +49 -34
- package/dist/prepareQueryObjects-Dc8rqsYM.js.map +1 -0
- package/dist/{prepareQueryObjects-BBayjIn2.mjs → prepareQueryObjects-tMukQHT9.mjs} +34 -18
- package/dist/prepareQueryObjects-tMukQHT9.mjs.map +1 -0
- package/dist/react-querybuilder_core.d.mts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.d.ts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.js +296 -279
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +288 -247
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +178 -127
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/transformQuery.d.mts +1 -2
- package/dist/transformQuery.d.ts +1 -2
- package/dist/transformQuery.js +44 -2
- package/dist/transformQuery.js.map +1 -0
- package/dist/transformQuery.mjs +43 -2
- package/dist/transformQuery.mjs.map +1 -0
- package/dist/{utils-nQU7WCM9.mjs → utils-DQoYnxpa.mjs} +32 -84
- package/dist/utils-DQoYnxpa.mjs.map +1 -0
- package/dist/{utils-CR1ToTMW.js → utils-EsYRkPtf.js} +182 -246
- package/dist/utils-EsYRkPtf.js.map +1 -0
- package/package.json +25 -17
- package/dist/chunk-U64pC571.js +0 -41
- package/dist/convertQuery-DAj92cbM.mjs.map +0 -1
- package/dist/convertQuery-DRldbzhZ.js +0 -87
- package/dist/convertQuery-DRldbzhZ.js.map +0 -1
- package/dist/isRuleGroup-Cjk1Q2mj.js.map +0 -1
- package/dist/isRuleGroup-DztIOOKa.mjs.map +0 -1
- package/dist/prepareQueryObjects-BBayjIn2.mjs.map +0 -1
- package/dist/prepareQueryObjects-BxWvIPI4.js.map +0 -1
- package/dist/transformQuery-ClBRfnFg.js +0 -54
- package/dist/transformQuery-ClBRfnFg.js.map +0 -1
- package/dist/transformQuery-DUpbpqjX.mjs +0 -48
- package/dist/transformQuery-DUpbpqjX.mjs.map +0 -1
- package/dist/utils-CR1ToTMW.js.map +0 -1
- package/dist/utils-nQU7WCM9.mjs.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { produce } from "immer";
|
|
2
1
|
import { numericQuantity, numericRegex as numericRegex$1 } from "numeric-quantity";
|
|
3
|
-
|
|
2
|
+
import { current, isDraft, produce } from "immer";
|
|
4
3
|
//#region src/defaults.ts
|
|
5
4
|
/**
|
|
6
5
|
* @group Defaults
|
|
@@ -15,7 +14,7 @@ const defaultPlaceholderLabel = "------";
|
|
|
15
14
|
*
|
|
16
15
|
* @group Defaults
|
|
17
16
|
*/
|
|
18
|
-
const defaultPlaceholderFieldName =
|
|
17
|
+
const defaultPlaceholderFieldName = "~";
|
|
19
18
|
/**
|
|
20
19
|
* Default `label` for placeholder option in the `fields` array.
|
|
21
20
|
*
|
|
@@ -33,7 +32,7 @@ const defaultPlaceholderFieldGroupLabel = defaultPlaceholderLabel;
|
|
|
33
32
|
*
|
|
34
33
|
* @group Defaults
|
|
35
34
|
*/
|
|
36
|
-
const defaultPlaceholderOperatorName =
|
|
35
|
+
const defaultPlaceholderOperatorName = "~";
|
|
37
36
|
/**
|
|
38
37
|
* Default `label` for placeholder option in the `operators` array.
|
|
39
38
|
*
|
|
@@ -51,7 +50,7 @@ const defaultPlaceholderOperatorGroupLabel = defaultPlaceholderLabel;
|
|
|
51
50
|
*
|
|
52
51
|
* @group Defaults
|
|
53
52
|
*/
|
|
54
|
-
const defaultPlaceholderValueName =
|
|
53
|
+
const defaultPlaceholderValueName = "~";
|
|
55
54
|
/**
|
|
56
55
|
* Default `label` for placeholder option in the `values` array.
|
|
57
56
|
*
|
|
@@ -72,19 +71,19 @@ const defaultPlaceholderValueGroupLabel = defaultPlaceholderLabel;
|
|
|
72
71
|
const defaultTranslations = {
|
|
73
72
|
fields: {
|
|
74
73
|
title: "Field",
|
|
75
|
-
placeholderName:
|
|
74
|
+
placeholderName: "~",
|
|
76
75
|
placeholderLabel: defaultPlaceholderFieldLabel,
|
|
77
76
|
placeholderGroupLabel: defaultPlaceholderFieldGroupLabel
|
|
78
77
|
},
|
|
79
78
|
operators: {
|
|
80
79
|
title: "Operator",
|
|
81
|
-
placeholderName:
|
|
80
|
+
placeholderName: "~",
|
|
82
81
|
placeholderLabel: defaultPlaceholderOperatorLabel,
|
|
83
82
|
placeholderGroupLabel: defaultPlaceholderOperatorGroupLabel
|
|
84
83
|
},
|
|
85
84
|
values: {
|
|
86
85
|
title: "Values",
|
|
87
|
-
placeholderName:
|
|
86
|
+
placeholderName: "~",
|
|
88
87
|
placeholderLabel: defaultPlaceholderValueLabel,
|
|
89
88
|
placeholderGroupLabel: defaultPlaceholderValueGroupLabel
|
|
90
89
|
},
|
|
@@ -562,7 +561,6 @@ const queryBuilderFlagDefaults = {
|
|
|
562
561
|
showShiftActions: false,
|
|
563
562
|
suppressStandardClassnames: false
|
|
564
563
|
};
|
|
565
|
-
|
|
566
564
|
//#endregion
|
|
567
565
|
//#region src/utils/arrayUtils.ts
|
|
568
566
|
/**
|
|
@@ -577,7 +575,7 @@ const queryBuilderFlagDefaults = {
|
|
|
577
575
|
* // would return
|
|
578
576
|
* ['this,,that', '', 'the other', '', '', ',']
|
|
579
577
|
*/
|
|
580
|
-
const splitBy = (str, splitChar =
|
|
578
|
+
const splitBy = (str, splitChar = ",") => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
|
|
581
579
|
if (idx === 0) return curr;
|
|
582
580
|
return [
|
|
583
581
|
...prev.slice(0, -1),
|
|
@@ -598,7 +596,7 @@ const splitBy = (str, splitChar = defaultJoinChar) => typeof str === "string" ?
|
|
|
598
596
|
* // would return
|
|
599
597
|
* 'this\\,\\,that, , the other, , , \\,'
|
|
600
598
|
*/
|
|
601
|
-
const joinWith = (strArr, joinChar =
|
|
599
|
+
const joinWith = (strArr, joinChar = ",") => strArr.map((str) => `${str ?? ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(joinChar);
|
|
602
600
|
/**
|
|
603
601
|
* Trims the value if it is a string. Otherwise returns the value as is.
|
|
604
602
|
*/
|
|
@@ -607,12 +605,11 @@ const trimIfString = (val) => typeof val === "string" ? val.trim() : val;
|
|
|
607
605
|
* Splits a string by comma then trims each element. Arrays are returned as is except
|
|
608
606
|
* any string elements are trimmed.
|
|
609
607
|
*/
|
|
610
|
-
const toArray = (
|
|
608
|
+
const toArray = (a, { retainEmptyStrings } = {}) => Array.isArray(a) ? a.map((v) => trimIfString(v)) : typeof a === "string" ? splitBy(a, ",").filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof a === "number" ? [a] : [];
|
|
611
609
|
/**
|
|
612
610
|
* Determines if an array is free of `null`/`undefined`.
|
|
613
611
|
*/
|
|
614
612
|
const nullFreeArray = (arr) => arr.every((el) => el === false || (el ?? false) !== false);
|
|
615
|
-
|
|
616
613
|
//#endregion
|
|
617
614
|
//#region src/utils/clsx.ts
|
|
618
615
|
// istanbul ignore next
|
|
@@ -653,7 +650,6 @@ function clsx(...args) {
|
|
|
653
650
|
}
|
|
654
651
|
return str;
|
|
655
652
|
}
|
|
656
|
-
|
|
657
653
|
//#endregion
|
|
658
654
|
//#region src/utils/misc.ts
|
|
659
655
|
/**
|
|
@@ -674,7 +670,6 @@ const isPojo = (obj) => obj === null || typeof obj !== "object" ? false : Object
|
|
|
674
670
|
* Simple helper to determine whether a value is null, undefined, or an empty string.
|
|
675
671
|
*/
|
|
676
672
|
const nullOrUndefinedOrEmpty = (value) => value === null || value === void 0 || value === "";
|
|
677
|
-
|
|
678
673
|
//#endregion
|
|
679
674
|
//#region src/utils/isRuleGroup.ts
|
|
680
675
|
/**
|
|
@@ -693,7 +688,6 @@ const isRuleGroupType = (rg) => isRuleGroup(rg) && typeof rg.combinator === "str
|
|
|
693
688
|
* Determines if an object is a {@link RuleGroupTypeIC}.
|
|
694
689
|
*/
|
|
695
690
|
const isRuleGroupTypeIC = (rg) => isRuleGroup(rg) && rg.combinator === void 0;
|
|
696
|
-
|
|
697
691
|
//#endregion
|
|
698
692
|
//#region src/utils/convertQuery.ts
|
|
699
693
|
const combinatorLevels = [
|
|
@@ -705,20 +699,27 @@ const isSameString = (a, b) => lc(a) === b;
|
|
|
705
699
|
const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel = 0) => {
|
|
706
700
|
const baseCombinator = combinatorLevels[baseCombinatorLevel];
|
|
707
701
|
if (!rg.rules.includes(baseCombinator)) return baseCombinatorLevel < combinatorLevels.length - 2 ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1) : rg;
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
const nextBaseCombinatorIndex = draft.rules.findIndex((r, i) => i > cursor && typeof r === "string" && lc(r) === baseCombinator);
|
|
716
|
-
if (nextBaseCombinatorIndex === -1) {
|
|
717
|
-
draft.rules.splice(cursor, draft.rules.length, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor) }, baseCombinatorLevel + 1));
|
|
718
|
-
break;
|
|
719
|
-
} else draft.rules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
|
|
702
|
+
const newRules = [...rg.rules];
|
|
703
|
+
let cursor = 0;
|
|
704
|
+
while (cursor < newRules.length - 2) {
|
|
705
|
+
if (isSameString(newRules[cursor + 1], baseCombinator)) {
|
|
706
|
+
cursor += 2;
|
|
707
|
+
continue;
|
|
720
708
|
}
|
|
721
|
-
|
|
709
|
+
let nextBaseCombinatorIndex = -1;
|
|
710
|
+
for (let i = cursor + 2; i < newRules.length; i++) if (typeof newRules[i] === "string" && lc(newRules[i]) === baseCombinator) {
|
|
711
|
+
nextBaseCombinatorIndex = i;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
if (nextBaseCombinatorIndex === -1) {
|
|
715
|
+
newRules.splice(cursor, newRules.length, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor) }, baseCombinatorLevel + 1));
|
|
716
|
+
break;
|
|
717
|
+
} else newRules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
...rg,
|
|
721
|
+
rules: newRules
|
|
722
|
+
};
|
|
722
723
|
};
|
|
723
724
|
/**
|
|
724
725
|
* Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.
|
|
@@ -731,9 +732,11 @@ const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel =
|
|
|
731
732
|
const convertFromIC = (rg) => {
|
|
732
733
|
if (isRuleGroupType(rg)) return rg;
|
|
733
734
|
const processedRG = generateRuleGroupICWithConsistentCombinators(rg);
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
const
|
|
735
|
+
const rules = [];
|
|
736
|
+
let combinator = "and";
|
|
737
|
+
for (const [idx, r] of processedRG.rules.entries()) if (typeof r === "string") {
|
|
738
|
+
if (idx === 1) combinator = r;
|
|
739
|
+
} else rules.push(isRuleGroup(r) ? convertFromIC(r) : r);
|
|
737
740
|
return {
|
|
738
741
|
...processedRG,
|
|
739
742
|
combinator,
|
|
@@ -753,7 +756,8 @@ const convertToIC = (rg) => {
|
|
|
753
756
|
const { combinator, ...queryWithoutCombinator } = rg;
|
|
754
757
|
const rules = [];
|
|
755
758
|
const { length } = rg.rules;
|
|
756
|
-
for (
|
|
759
|
+
for (let idx = 0; idx < length; idx++) {
|
|
760
|
+
const r = rg.rules[idx];
|
|
757
761
|
if (isRuleGroup(r)) rules.push(convertToIC(r));
|
|
758
762
|
else rules.push(r);
|
|
759
763
|
if (combinator && idx < length - 1) rules.push(combinator);
|
|
@@ -766,7 +770,6 @@ const convertToIC = (rg) => {
|
|
|
766
770
|
function convertQuery(query) {
|
|
767
771
|
return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);
|
|
768
772
|
}
|
|
769
|
-
|
|
770
773
|
//#endregion
|
|
771
774
|
//#region src/utils/defaultValidator.ts
|
|
772
775
|
/**
|
|
@@ -803,7 +806,6 @@ const defaultValidator = (query) => {
|
|
|
803
806
|
validateGroup(query);
|
|
804
807
|
return result;
|
|
805
808
|
};
|
|
806
|
-
|
|
807
809
|
//#endregion
|
|
808
810
|
//#region src/utils/objectUtils.ts
|
|
809
811
|
/**
|
|
@@ -818,7 +820,6 @@ const objectKeys = Object.keys;
|
|
|
818
820
|
* [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-entries.ts)
|
|
819
821
|
*/
|
|
820
822
|
const objectEntries = Object.entries;
|
|
821
|
-
|
|
822
823
|
//#endregion
|
|
823
824
|
//#region src/utils/optGroupUtils.ts
|
|
824
825
|
const isOptionWithName = (opt) => isPojo(opt) && "name" in opt && typeof opt.name === "string";
|
|
@@ -830,24 +831,23 @@ const isOptionWithValue = (opt) => isPojo(opt) && "value" in opt && typeof opt.v
|
|
|
830
831
|
* @group Option Lists
|
|
831
832
|
*/
|
|
832
833
|
function toFullOption(opt, baseProperties, labelMap) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
})(opt);
|
|
834
|
+
if (typeof opt === "string") return {
|
|
835
|
+
...baseProperties,
|
|
836
|
+
name: opt,
|
|
837
|
+
value: opt,
|
|
838
|
+
label: labelMap?.[opt] ?? opt
|
|
839
|
+
};
|
|
840
|
+
const idObj = {};
|
|
841
|
+
let needsUpdating = !!baseProperties;
|
|
842
|
+
if (isOptionWithName(opt) && !isOptionWithValue(opt)) {
|
|
843
|
+
idObj.value = opt.name;
|
|
844
|
+
needsUpdating = true;
|
|
845
|
+
} else if (!isOptionWithName(opt) && isOptionWithValue(opt)) {
|
|
846
|
+
idObj.name = opt.value;
|
|
847
|
+
needsUpdating = true;
|
|
848
|
+
}
|
|
849
|
+
if (needsUpdating) return Object.assign({}, baseProperties, opt, idObj);
|
|
850
|
+
return opt;
|
|
851
851
|
}
|
|
852
852
|
/**
|
|
853
853
|
* Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.
|
|
@@ -857,10 +857,12 @@ function toFullOption(opt, baseProperties, labelMap) {
|
|
|
857
857
|
*/
|
|
858
858
|
function toFullOptionList(optList, baseProperties, labelMap) {
|
|
859
859
|
if (!Array.isArray(optList)) return [];
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
860
|
+
const list = optList;
|
|
861
|
+
if (isFlexibleOptionGroupArray(list)) return list.map((optGroup) => ({
|
|
862
|
+
...optGroup,
|
|
863
|
+
options: optGroup.options.map((opt) => toFullOption(opt, baseProperties, labelMap))
|
|
864
|
+
}));
|
|
865
|
+
return list.map((opt) => toFullOption(opt, baseProperties, labelMap));
|
|
864
866
|
}
|
|
865
867
|
/**
|
|
866
868
|
* Converts a {@link FlexibleOptionList} into a {@link FullOptionList}.
|
|
@@ -997,7 +999,7 @@ const uniqOptList = (originalArray) => {
|
|
|
997
999
|
};
|
|
998
1000
|
const prepareOptionList = (props) => {
|
|
999
1001
|
// istanbul ignore next
|
|
1000
|
-
const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName =
|
|
1002
|
+
const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName = "~", placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
|
|
1001
1003
|
const defaultOption = {
|
|
1002
1004
|
id: placeholderName,
|
|
1003
1005
|
name: placeholderName,
|
|
@@ -1031,7 +1033,6 @@ const prepareOptionList = (props) => {
|
|
|
1031
1033
|
optionsMap
|
|
1032
1034
|
};
|
|
1033
1035
|
};
|
|
1034
|
-
|
|
1035
1036
|
//#endregion
|
|
1036
1037
|
//#region src/utils/filterFieldsByComparator.ts
|
|
1037
1038
|
const filterByComparator = (field, operator, fieldToCompare) => {
|
|
@@ -1067,7 +1068,6 @@ const filterFieldsByComparator = (field, fields, operator) => {
|
|
|
1067
1068
|
})).filter((og) => og.options.length > 0);
|
|
1068
1069
|
return fields.filter((f) => filterByComparator(field, operator, f));
|
|
1069
1070
|
};
|
|
1070
|
-
|
|
1071
1071
|
//#endregion
|
|
1072
1072
|
//#region src/utils/parseNumber.ts
|
|
1073
1073
|
/**
|
|
@@ -1087,23 +1087,20 @@ const parseNumber = (val, { parseNumbers, bigIntOnOverflow } = {}) => {
|
|
|
1087
1087
|
});
|
|
1088
1088
|
return typeof valAsNum === "bigint" || !Number.isNaN(valAsNum) ? valAsNum : val;
|
|
1089
1089
|
};
|
|
1090
|
-
|
|
1091
1090
|
//#endregion
|
|
1092
1091
|
//#region src/utils/transformQuery.ts
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
else if (!!v && k !== v && k in draft) {
|
|
1103
|
-
draft[v] = draft[k];
|
|
1104
|
-
if (deleteRemappedProperties) delete draft[k];
|
|
1092
|
+
const remapProperties = (obj, propertyMap, deleteRemappedProperties) => {
|
|
1093
|
+
const result = {};
|
|
1094
|
+
for (const key in obj) {
|
|
1095
|
+
const mappedKey = propertyMap[key];
|
|
1096
|
+
if (mappedKey === false) continue;
|
|
1097
|
+
if (mappedKey && key !== mappedKey) {
|
|
1098
|
+
result[mappedKey] = obj[key];
|
|
1099
|
+
if (!deleteRemappedProperties) result[key] = obj[key];
|
|
1100
|
+
} else result[key] = obj[key];
|
|
1105
1101
|
}
|
|
1106
|
-
|
|
1102
|
+
return result;
|
|
1103
|
+
};
|
|
1107
1104
|
function transformQuery(query, options = {}) {
|
|
1108
1105
|
const { ruleProcessor = (r) => r, ruleGroupProcessor = (rg) => rg, propertyMap = {}, combinatorMap = {}, operatorMap = {}, omitPath = false, deleteRemappedProperties = true } = options;
|
|
1109
1106
|
const processGroup = (rg) => ({
|
|
@@ -1130,7 +1127,6 @@ function transformQuery(query, options = {}) {
|
|
|
1130
1127
|
...omitPath ? null : { path: [] }
|
|
1131
1128
|
});
|
|
1132
1129
|
}
|
|
1133
|
-
|
|
1134
1130
|
//#endregion
|
|
1135
1131
|
//#region src/utils/isRuleOrGroupValid.ts
|
|
1136
1132
|
/**
|
|
@@ -1154,7 +1150,6 @@ const isRuleOrGroupValid = (rg, validationResult, validator) => {
|
|
|
1154
1150
|
}
|
|
1155
1151
|
return true;
|
|
1156
1152
|
};
|
|
1157
|
-
|
|
1158
1153
|
//#endregion
|
|
1159
1154
|
//#region src/utils/getParseNumberMethod.ts
|
|
1160
1155
|
const getParseNumberMethod = ({ parseNumbers, inputType }) => {
|
|
@@ -1165,7 +1160,6 @@ const getParseNumberMethod = ({ parseNumbers, inputType }) => {
|
|
|
1165
1160
|
}
|
|
1166
1161
|
return parseNumbers ? "strict" : false;
|
|
1167
1162
|
};
|
|
1168
|
-
|
|
1169
1163
|
//#endregion
|
|
1170
1164
|
//#region src/utils/formatQuery/utils.ts
|
|
1171
1165
|
/**
|
|
@@ -1247,7 +1241,8 @@ const jsonLogicAdditionalOperators = {
|
|
|
1247
1241
|
endsWith: (a, b) => typeof a === "string" && a.endsWith(b)
|
|
1248
1242
|
};
|
|
1249
1243
|
/**
|
|
1250
|
-
*
|
|
1244
|
+
* Returns a new query object with all `string`-type `value` properties converted
|
|
1245
|
+
* to `number` where appropriate.
|
|
1251
1246
|
*
|
|
1252
1247
|
* Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
|
|
1253
1248
|
*
|
|
@@ -1416,7 +1411,6 @@ const bigIntJsonStringifyReplacer = (_key, value) => typeof value === "bigint" ?
|
|
|
1416
1411
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
|
|
1417
1412
|
*/
|
|
1418
1413
|
const bigIntJsonParseReviver = (_key, value) => isPojo(value) && Object.keys(value).length === 1 && typeof value.$bigint === "string" ? BigInt(value.$bigint) : value;
|
|
1419
|
-
|
|
1420
1414
|
//#endregion
|
|
1421
1415
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorCEL.ts
|
|
1422
1416
|
/**
|
|
@@ -1472,7 +1466,6 @@ const defaultRuleGroupProcessorCEL = (ruleGroup, options) => {
|
|
|
1472
1466
|
};
|
|
1473
1467
|
return processRuleGroup(ruleGroup, true);
|
|
1474
1468
|
};
|
|
1475
|
-
|
|
1476
1469
|
//#endregion
|
|
1477
1470
|
//#region src/utils/formatQuery/defaultRuleProcessorCEL.ts
|
|
1478
1471
|
const shouldNegate$2 = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
@@ -1553,7 +1546,6 @@ const defaultRuleProcessorCEL = (rule, opts = {}) => {
|
|
|
1553
1546
|
}
|
|
1554
1547
|
return "";
|
|
1555
1548
|
};
|
|
1556
|
-
|
|
1557
1549
|
//#endregion
|
|
1558
1550
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDBQuery.ts
|
|
1559
1551
|
/**
|
|
@@ -1591,11 +1583,11 @@ const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
|
|
|
1591
1583
|
fieldData
|
|
1592
1584
|
}, meta);
|
|
1593
1585
|
}).filter(Boolean);
|
|
1594
|
-
|
|
1586
|
+
const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
|
|
1587
|
+
return rg.not ? { $not: result } : result;
|
|
1595
1588
|
};
|
|
1596
1589
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
1597
1590
|
};
|
|
1598
|
-
|
|
1599
1591
|
//#endregion
|
|
1600
1592
|
//#region src/utils/formatQuery/defaultRuleProcessorMongoDBQuery.ts
|
|
1601
1593
|
const processNumber$1 = (value, fallback, parseNumbers = false) => shouldRenderAsNumber(value, parseNumbers || typeof value === "bigint") ? Number(parseNumber(value, { parseNumbers: "strict" })) : fallback;
|
|
@@ -1724,7 +1716,6 @@ const defaultRuleProcessorMongoDBQuery = (rule, options = {}) => {
|
|
|
1724
1716
|
}
|
|
1725
1717
|
return "";
|
|
1726
1718
|
};
|
|
1727
|
-
|
|
1728
1719
|
//#endregion
|
|
1729
1720
|
//#region src/utils/formatQuery/defaultRuleProcessorMongoDB.ts
|
|
1730
1721
|
/**
|
|
@@ -1738,7 +1729,6 @@ const defaultRuleProcessorMongoDB = (rule, options) => {
|
|
|
1738
1729
|
const queryObj = defaultRuleProcessorMongoDBQuery(rule, options);
|
|
1739
1730
|
return queryObj ? JSON.stringify(queryObj) : "";
|
|
1740
1731
|
};
|
|
1741
|
-
|
|
1742
1732
|
//#endregion
|
|
1743
1733
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorSpEL.ts
|
|
1744
1734
|
/**
|
|
@@ -1794,11 +1784,10 @@ const defaultRuleGroupProcessorSpEL = (ruleGroup, options) => {
|
|
|
1794
1784
|
};
|
|
1795
1785
|
return processRuleGroup(ruleGroup, true);
|
|
1796
1786
|
};
|
|
1797
|
-
|
|
1798
1787
|
//#endregion
|
|
1799
1788
|
//#region src/utils/formatQuery/defaultRuleProcessorSpEL.ts
|
|
1800
1789
|
const shouldNegate$1 = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
1801
|
-
const wrapInNegation = (clause, negate
|
|
1790
|
+
const wrapInNegation = (clause, negate) => negate ? `!(${clause})` : clause;
|
|
1802
1791
|
const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
|
|
1803
1792
|
/**
|
|
1804
1793
|
* Default rule processor used by {@link formatQuery} for "spel" format.
|
|
@@ -1851,9 +1840,9 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
|
|
|
1851
1840
|
case "notnull": return `${field} != null`;
|
|
1852
1841
|
case "in":
|
|
1853
1842
|
case "notin": {
|
|
1854
|
-
const negate
|
|
1843
|
+
const negate = shouldNegate$1(operatorTL) ? "!" : "";
|
|
1855
1844
|
const valueAsArray = toArray(value);
|
|
1856
|
-
return valueAsArray.length > 0 ? `${negate
|
|
1845
|
+
return valueAsArray.length > 0 ? `${negate}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
|
|
1857
1846
|
}
|
|
1858
1847
|
case "between":
|
|
1859
1848
|
case "notbetween": {
|
|
@@ -1876,7 +1865,6 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
|
|
|
1876
1865
|
}
|
|
1877
1866
|
return "";
|
|
1878
1867
|
};
|
|
1879
|
-
|
|
1880
1868
|
//#endregion
|
|
1881
1869
|
//#region src/utils/formatQuery/defaultValueProcessorByRule.ts
|
|
1882
1870
|
const escapeStringValueQuotes$1 = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
|
|
@@ -1932,7 +1920,6 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
|
|
|
1932
1920
|
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
1933
1921
|
return valueIsField ? wrapFieldName(value) : shouldRenderAsNumber(value, parseNumbers) ? `${trimIfString(value)}` : `${wrapAndEscape(value)}`;
|
|
1934
1922
|
};
|
|
1935
|
-
|
|
1936
1923
|
//#endregion
|
|
1937
1924
|
//#region src/utils/formatQuery/defaultRuleProcessorDrizzle.ts
|
|
1938
1925
|
/**
|
|
@@ -2029,7 +2016,6 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
2029
2016
|
default: return;
|
|
2030
2017
|
}
|
|
2031
2018
|
};
|
|
2032
|
-
|
|
2033
2019
|
//#endregion
|
|
2034
2020
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorDrizzle.ts
|
|
2035
2021
|
/**
|
|
@@ -2073,7 +2059,6 @@ const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns
|
|
|
2073
2059
|
};
|
|
2074
2060
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2075
2061
|
};
|
|
2076
|
-
|
|
2077
2062
|
//#endregion
|
|
2078
2063
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorElasticSearch.ts
|
|
2079
2064
|
/**
|
|
@@ -2102,7 +2087,6 @@ const defaultRuleGroupProcessorElasticSearch = (ruleGroup, options) => {
|
|
|
2102
2087
|
const processedRuleGroup = processRuleGroup(convertFromIC(ruleGroup));
|
|
2103
2088
|
return processedRuleGroup === false ? {} : processedRuleGroup;
|
|
2104
2089
|
};
|
|
2105
|
-
|
|
2106
2090
|
//#endregion
|
|
2107
2091
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorJSONata.ts
|
|
2108
2092
|
/**
|
|
@@ -2158,7 +2142,6 @@ const defaultRuleGroupProcessorJSONata = (ruleGroup, options) => {
|
|
|
2158
2142
|
};
|
|
2159
2143
|
return processRuleGroup(ruleGroup, true);
|
|
2160
2144
|
};
|
|
2161
|
-
|
|
2162
2145
|
//#endregion
|
|
2163
2146
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorJsonLogic.ts
|
|
2164
2147
|
/**
|
|
@@ -2188,7 +2171,6 @@ const defaultRuleGroupProcessorJsonLogic = (ruleGroup, options) => {
|
|
|
2188
2171
|
};
|
|
2189
2172
|
return processRuleGroup(query, true);
|
|
2190
2173
|
};
|
|
2191
|
-
|
|
2192
2174
|
//#endregion
|
|
2193
2175
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorLDAP.ts
|
|
2194
2176
|
/**
|
|
@@ -2219,7 +2201,6 @@ const defaultRuleGroupProcessorLDAP = (ruleGroup, options) => {
|
|
|
2219
2201
|
};
|
|
2220
2202
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2221
2203
|
};
|
|
2222
|
-
|
|
2223
2204
|
//#endregion
|
|
2224
2205
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDB.ts
|
|
2225
2206
|
const isBracketed = (str) => str.startsWith("{") && str.endsWith("}");
|
|
@@ -2254,12 +2235,12 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
|
|
|
2254
2235
|
fieldData
|
|
2255
2236
|
}, meta);
|
|
2256
2237
|
}).filter(Boolean);
|
|
2257
|
-
|
|
2238
|
+
const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
|
|
2239
|
+
return rg.not ? `"$not":${isBracketed(result) ? result : `{${result}}`}` : result;
|
|
2258
2240
|
};
|
|
2259
2241
|
const processedQuery = processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2260
2242
|
return isBracketed(processedQuery) ? processedQuery : `{${processedQuery}}`;
|
|
2261
2243
|
};
|
|
2262
|
-
|
|
2263
2244
|
//#endregion
|
|
2264
2245
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorNL.ts
|
|
2265
2246
|
/**
|
|
@@ -2323,7 +2304,6 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
|
2323
2304
|
};
|
|
2324
2305
|
return processRuleGroup(ruleGroup, true);
|
|
2325
2306
|
};
|
|
2326
|
-
|
|
2327
2307
|
//#endregion
|
|
2328
2308
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorParameterized.ts
|
|
2329
2309
|
/**
|
|
@@ -2412,7 +2392,6 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2412
2392
|
params: paramsNamed
|
|
2413
2393
|
};
|
|
2414
2394
|
};
|
|
2415
|
-
|
|
2416
2395
|
//#endregion
|
|
2417
2396
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorPrisma.ts
|
|
2418
2397
|
/**
|
|
@@ -2455,7 +2434,6 @@ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
|
|
|
2455
2434
|
const result = processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2456
2435
|
return ruleGroup.not ? { NOT: result } : result;
|
|
2457
2436
|
};
|
|
2458
|
-
|
|
2459
2437
|
//#endregion
|
|
2460
2438
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorSequelize.ts
|
|
2461
2439
|
/**
|
|
@@ -2496,7 +2474,6 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
|
2496
2474
|
};
|
|
2497
2475
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2498
2476
|
};
|
|
2499
|
-
|
|
2500
2477
|
//#endregion
|
|
2501
2478
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorSQL.ts
|
|
2502
2479
|
/**
|
|
@@ -2553,7 +2530,6 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
2553
2530
|
};
|
|
2554
2531
|
return processRuleGroup(ruleGroup, true);
|
|
2555
2532
|
};
|
|
2556
|
-
|
|
2557
2533
|
//#endregion
|
|
2558
2534
|
//#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
|
|
2559
2535
|
const rangeOperatorMap = {
|
|
@@ -2705,12 +2681,11 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
|
|
|
2705
2681
|
}
|
|
2706
2682
|
return false;
|
|
2707
2683
|
};
|
|
2708
|
-
|
|
2709
2684
|
//#endregion
|
|
2710
2685
|
//#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
|
|
2711
2686
|
const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
2712
2687
|
const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
|
|
2713
|
-
const negate = (clause,
|
|
2688
|
+
const negate = (clause, neg) => neg ? `$not(${clause})` : clause;
|
|
2714
2689
|
const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
|
|
2715
2690
|
/**
|
|
2716
2691
|
* Default rule processor used by {@link formatQuery} for "jsonata" format.
|
|
@@ -2792,7 +2767,6 @@ const defaultRuleProcessorJSONata = (rule, options = {}) => {
|
|
|
2792
2767
|
}
|
|
2793
2768
|
return "";
|
|
2794
2769
|
};
|
|
2795
|
-
|
|
2796
2770
|
//#endregion
|
|
2797
2771
|
//#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
|
|
2798
2772
|
const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
|
|
@@ -2887,10 +2861,9 @@ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
|
|
|
2887
2861
|
}
|
|
2888
2862
|
return false;
|
|
2889
2863
|
};
|
|
2890
|
-
|
|
2891
2864
|
//#endregion
|
|
2892
2865
|
//#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
|
|
2893
|
-
const negateIf = (clause, negate
|
|
2866
|
+
const negateIf = (clause, negate) => negate ? `(!${clause})` : `${clause}`;
|
|
2894
2867
|
const ldapEscape = (s) => `${trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
|
|
2895
2868
|
/**
|
|
2896
2869
|
* Default rule processor used by {@link formatQuery} for "ldap" format.
|
|
@@ -2939,7 +2912,6 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
|
|
|
2939
2912
|
// istanbul ignore next
|
|
2940
2913
|
return "";
|
|
2941
2914
|
};
|
|
2942
|
-
|
|
2943
2915
|
//#endregion
|
|
2944
2916
|
//#region src/utils/formatQuery/defaultValueProcessorNL.ts
|
|
2945
2917
|
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
|
|
@@ -2989,7 +2961,6 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
2989
2961
|
if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
|
|
2990
2962
|
return valueIsField ? wrapFieldName(getOption(fields ?? [], rule.value)?.label ?? rule.value) : shouldRenderAsNumber(rule.value, parseNumbers) ? `${trimIfString(rule.value)}` : `${wrapAndEscape(rule.value)}`;
|
|
2991
2963
|
};
|
|
2992
|
-
|
|
2993
2964
|
//#endregion
|
|
2994
2965
|
//#region src/utils/formatQuery/defaultRuleProcessorNL.ts
|
|
2995
2966
|
/**
|
|
@@ -3099,7 +3070,6 @@ const defaultRuleProcessorNL = (rule, opts) => {
|
|
|
3099
3070
|
};
|
|
3100
3071
|
return normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
|
|
3101
3072
|
};
|
|
3102
|
-
|
|
3103
3073
|
//#endregion
|
|
3104
3074
|
//#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
|
|
3105
3075
|
/**
|
|
@@ -3154,7 +3124,6 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
|
|
|
3154
3124
|
if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
|
|
3155
3125
|
return `${ruleField} ${operator} ${value}`.trim();
|
|
3156
3126
|
};
|
|
3157
|
-
|
|
3158
3127
|
//#endregion
|
|
3159
3128
|
//#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
|
|
3160
3129
|
/**
|
|
@@ -3259,7 +3228,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3259
3228
|
}
|
|
3260
3229
|
return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
|
|
3261
3230
|
};
|
|
3262
|
-
|
|
3263
3231
|
//#endregion
|
|
3264
3232
|
//#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
|
|
3265
3233
|
const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
|
|
@@ -3321,7 +3289,6 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
|
3321
3289
|
}
|
|
3322
3290
|
return "";
|
|
3323
3291
|
};
|
|
3324
|
-
|
|
3325
3292
|
//#endregion
|
|
3326
3293
|
//#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
|
|
3327
3294
|
/**
|
|
@@ -3388,7 +3355,6 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
|
|
|
3388
3355
|
}
|
|
3389
3356
|
}
|
|
3390
3357
|
};
|
|
3391
|
-
|
|
3392
3358
|
//#endregion
|
|
3393
3359
|
//#region src/utils/formatQuery/formatQuery.ts
|
|
3394
3360
|
/**
|
|
@@ -3477,8 +3443,8 @@ const defaultFormatQueryOptions = {
|
|
|
3477
3443
|
paramsKeepPrefix: false,
|
|
3478
3444
|
numberedParams: false,
|
|
3479
3445
|
preserveValueOrder: false,
|
|
3480
|
-
placeholderFieldName:
|
|
3481
|
-
placeholderOperatorName:
|
|
3446
|
+
placeholderFieldName: "~",
|
|
3447
|
+
placeholderOperatorName: "~",
|
|
3482
3448
|
quoteValuesWith: "'",
|
|
3483
3449
|
concatOperator: "||",
|
|
3484
3450
|
preset: "ansi",
|
|
@@ -3583,7 +3549,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3583
3549
|
switch (format) {
|
|
3584
3550
|
case "json":
|
|
3585
3551
|
case "json_without_ids": {
|
|
3586
|
-
const rg = parseNumbers ?
|
|
3552
|
+
const rg = parseNumbers ? numerifyValues(ruleGroup, finalOptions) : ruleGroup;
|
|
3587
3553
|
if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : bigIntJsonStringifyReplacer(key, value));
|
|
3588
3554
|
return JSON.stringify(rg, bigIntJsonStringifyReplacer, 2);
|
|
3589
3555
|
}
|
|
@@ -3605,7 +3571,6 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3605
3571
|
default: return "";
|
|
3606
3572
|
}
|
|
3607
3573
|
}
|
|
3608
|
-
|
|
3609
3574
|
//#endregion
|
|
3610
3575
|
//#region src/utils/formatQuery/index.ts
|
|
3611
3576
|
const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
|
|
@@ -3656,7 +3621,6 @@ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
|
|
|
3656
3621
|
* @group Export
|
|
3657
3622
|
*/
|
|
3658
3623
|
const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
|
|
3659
|
-
|
|
3660
3624
|
//#endregion
|
|
3661
3625
|
//#region src/utils/pathUtils.ts
|
|
3662
3626
|
/**
|
|
@@ -3715,7 +3679,7 @@ const pathsAreEqual = (path1, path2) => path1.length === path2.length && path1.e
|
|
|
3715
3679
|
* Determines if the first path is an ancestor of the second path. The first path must
|
|
3716
3680
|
* be shorter and exactly match the second path up through the length of the first path.
|
|
3717
3681
|
*/
|
|
3718
|
-
const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length &&
|
|
3682
|
+
const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length && new RegExp(`^${maybeAncestor.join("-")}`).test(path.join("-"));
|
|
3719
3683
|
/**
|
|
3720
3684
|
* Finds the deepest/longest path that two paths have in common.
|
|
3721
3685
|
*/
|
|
@@ -3748,11 +3712,9 @@ const pathIsDisabled = (path, query) => {
|
|
|
3748
3712
|
}
|
|
3749
3713
|
return disabled;
|
|
3750
3714
|
};
|
|
3751
|
-
|
|
3752
3715
|
//#endregion
|
|
3753
3716
|
//#region src/utils/generateAccessibleDescription.ts
|
|
3754
3717
|
const generateAccessibleDescription = (params) => pathsAreEqual([], params.path) ? `Query builder` : `Rule group at path ${params.path.join("-")}`;
|
|
3755
|
-
|
|
3756
3718
|
//#endregion
|
|
3757
3719
|
//#region src/utils/generateID.ts
|
|
3758
3720
|
const cryptoModule = globalThis.crypto;
|
|
@@ -3787,7 +3749,6 @@ if (cryptoModule) {
|
|
|
3787
3749
|
};
|
|
3788
3750
|
}
|
|
3789
3751
|
}
|
|
3790
|
-
|
|
3791
3752
|
//#endregion
|
|
3792
3753
|
//#region src/utils/getMatchModesUtil.ts
|
|
3793
3754
|
const dummyFD$1 = {
|
|
@@ -3815,7 +3776,6 @@ const getMatchModesUtil = (fieldData, getMatchModes) => {
|
|
|
3815
3776
|
label: mm
|
|
3816
3777
|
}) ?? [];
|
|
3817
3778
|
};
|
|
3818
|
-
|
|
3819
3779
|
//#endregion
|
|
3820
3780
|
//#region src/utils/getValidationClassNames.ts
|
|
3821
3781
|
/**
|
|
@@ -3826,7 +3786,6 @@ const getValidationClassNames = (validationResult) => {
|
|
|
3826
3786
|
const valid = typeof validationResult === "boolean" ? validationResult : typeof validationResult === "object" && validationResult !== null ? validationResult.valid : null;
|
|
3827
3787
|
return typeof valid === "boolean" ? valid ? standardClassnames.valid : standardClassnames.invalid : "";
|
|
3828
3788
|
};
|
|
3829
|
-
|
|
3830
3789
|
//#endregion
|
|
3831
3790
|
//#region src/utils/getValueSourcesUtil.ts
|
|
3832
3791
|
const defaultValueSourcesArray = [{
|
|
@@ -3859,18 +3818,22 @@ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
|
|
|
3859
3818
|
label: vs
|
|
3860
3819
|
});
|
|
3861
3820
|
};
|
|
3862
|
-
|
|
3863
3821
|
//#endregion
|
|
3864
3822
|
//#region src/utils/mergeAnyTranslations.ts
|
|
3865
3823
|
/**
|
|
3866
3824
|
* Merges any number of partial translations into a single definition.
|
|
3867
3825
|
*/
|
|
3868
|
-
const mergeAnyTranslations = (base, ...otherTranslations) =>
|
|
3826
|
+
const mergeAnyTranslations = (base, ...otherTranslations) => {
|
|
3827
|
+
const result = { ...base };
|
|
3869
3828
|
for (const translations of otherTranslations)
|
|
3870
3829
|
// istanbul ignore else
|
|
3871
|
-
if (translations) for (const
|
|
3872
|
-
|
|
3873
|
-
|
|
3830
|
+
if (translations) for (const key of objectKeys(translations)) if (result[key]) result[key] = {
|
|
3831
|
+
...result[key],
|
|
3832
|
+
...translations[key]
|
|
3833
|
+
};
|
|
3834
|
+
else result[key] = { ...translations[key] };
|
|
3835
|
+
return result;
|
|
3836
|
+
};
|
|
3874
3837
|
const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
|
|
3875
3838
|
const finalKeys = objectEntries(keyPropContextMap).map(([key, [pT, cT]]) => [key, pT ?? cT ?? defaults?.[el]?.[key]]).filter((k) => !!k[1]);
|
|
3876
3839
|
if (finalKeys.length > 0 || defaults) {
|
|
@@ -3879,7 +3842,6 @@ const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
|
|
|
3879
3842
|
return { [el]: finalObject };
|
|
3880
3843
|
}
|
|
3881
3844
|
};
|
|
3882
|
-
|
|
3883
3845
|
//#endregion
|
|
3884
3846
|
//#region src/utils/mergeClassnames.ts
|
|
3885
3847
|
const joinClassnamesByName = (name, args) => clsx(args.map((c) => clsx(c?.[name])));
|
|
@@ -3929,7 +3891,6 @@ const mergeClassnames = (...args) => ({
|
|
|
3929
3891
|
hasSubQuery: joinClassnamesByName("hasSubQuery", args),
|
|
3930
3892
|
loading: joinClassnamesByName("loading", args)
|
|
3931
3893
|
});
|
|
3932
|
-
|
|
3933
3894
|
//#endregion
|
|
3934
3895
|
//#region src/utils/preferProp.ts
|
|
3935
3896
|
const preferPropDefaultTrue = (prop, context) => prop === false ? false : prop ? true : !(context === false);
|
|
@@ -3952,29 +3913,49 @@ const preferFlagProps = (props = {}, contextVals = {}, finalize) => objectEntrie
|
|
|
3952
3913
|
acc[key] = preferProp(def, props[key], contextVals[key], !finalize);
|
|
3953
3914
|
return acc;
|
|
3954
3915
|
}, {});
|
|
3955
|
-
|
|
3956
3916
|
//#endregion
|
|
3957
3917
|
//#region src/utils/prepareQueryObjects.ts
|
|
3958
3918
|
/**
|
|
3959
3919
|
* Ensures that a rule is valid by adding an `id` property if it does not already exist.
|
|
3960
3920
|
*/
|
|
3961
|
-
const prepareRule = (rule, { idGenerator = generateID } = {}) =>
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3921
|
+
const prepareRule = (rule, { idGenerator = generateID } = {}) => {
|
|
3922
|
+
const needsId = !rule.id;
|
|
3923
|
+
const hasMatchMode = processMatchMode(rule);
|
|
3924
|
+
if (!needsId && !hasMatchMode) return rule;
|
|
3925
|
+
return {
|
|
3926
|
+
...rule,
|
|
3927
|
+
...needsId && { id: idGenerator() },
|
|
3928
|
+
...hasMatchMode && { value: prepareRuleGroup(rule.value, { idGenerator }) }
|
|
3929
|
+
};
|
|
3930
|
+
};
|
|
3965
3931
|
/**
|
|
3966
3932
|
* Ensures that a rule group is valid by recursively adding an `id` property to the group itself
|
|
3967
3933
|
* and all its rules and subgroups where one does not already exist.
|
|
3968
3934
|
*/
|
|
3969
|
-
const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) =>
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3935
|
+
const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => {
|
|
3936
|
+
const needsId = !queryObject.id;
|
|
3937
|
+
let rulesChanged = false;
|
|
3938
|
+
const newRules = [];
|
|
3939
|
+
for (let i = 0; i < queryObject.rules.length; i++) {
|
|
3940
|
+
const r = queryObject.rules[i];
|
|
3941
|
+
if (typeof r === "string") newRules.push(r);
|
|
3942
|
+
else {
|
|
3943
|
+
const prepared = isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator });
|
|
3944
|
+
newRules.push(prepared);
|
|
3945
|
+
if (prepared !== r) rulesChanged = true;
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
if (!needsId && !rulesChanged) return queryObject;
|
|
3949
|
+
return {
|
|
3950
|
+
...queryObject,
|
|
3951
|
+
...needsId && { id: idGenerator() },
|
|
3952
|
+
rules: newRules
|
|
3953
|
+
};
|
|
3954
|
+
};
|
|
3973
3955
|
/**
|
|
3974
3956
|
* Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
|
|
3975
3957
|
*/
|
|
3976
3958
|
const prepareRuleOrGroup = (rg, { idGenerator = generateID } = {}) => isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });
|
|
3977
|
-
|
|
3978
3959
|
//#endregion
|
|
3979
3960
|
//#region src/utils/regenerateIDs.ts
|
|
3980
3961
|
/**
|
|
@@ -4001,44 +3982,65 @@ const regenerateIDs = (subject, { idGenerator = generateID } = {}) => {
|
|
|
4001
3982
|
if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
|
|
4002
3983
|
return newGroup;
|
|
4003
3984
|
};
|
|
4004
|
-
|
|
4005
3985
|
//#endregion
|
|
4006
3986
|
//#region src/utils/queryTools.ts
|
|
4007
3987
|
/**
|
|
4008
|
-
* Adds a rule or group to a query.
|
|
4009
|
-
*
|
|
3988
|
+
* Adds a rule or group to a query without mutating the original query.
|
|
3989
|
+
*
|
|
3990
|
+
* @returns A new query with the rule or group added.
|
|
3991
|
+
*
|
|
3992
|
+
* @group Query Tools
|
|
3993
|
+
*/
|
|
3994
|
+
const add = (query, ruleOrGroup, parentPathOrID, options = {}) => produce(query, (q) => addInPlace(q, ruleOrGroup, parentPathOrID, options));
|
|
3995
|
+
/**
|
|
3996
|
+
* Adds a rule or group to a query in place.
|
|
3997
|
+
*
|
|
3998
|
+
* @returns The query (mutated in place) with the rule or group added.
|
|
4010
3999
|
*
|
|
4011
4000
|
* @group Query Tools
|
|
4012
4001
|
*/
|
|
4013
|
-
const
|
|
4014
|
-
const
|
|
4015
|
-
|
|
4002
|
+
const addInPlace = (query, ruleOrGroup, parentPathOrID, options = {}) => {
|
|
4003
|
+
const { combinators = defaultCombinators, combinatorPreceding, idGenerator = generateID } = options;
|
|
4004
|
+
const parent = Array.isArray(parentPathOrID) ? findPath(parentPathOrID, query) : findID(parentPathOrID, query);
|
|
4005
|
+
if (!parent || !isRuleGroup(parent)) return query;
|
|
4016
4006
|
if (isRuleGroupTypeIC(parent) && parent.rules.length > 0) {
|
|
4017
4007
|
const prevCombinator = parent.rules.at(-2);
|
|
4018
4008
|
parent.rules.push(combinatorPreceding ?? (typeof prevCombinator === "string" ? prevCombinator : getFirstOption(combinators)));
|
|
4019
4009
|
}
|
|
4020
4010
|
parent.rules.push(prepareRuleOrGroup(ruleOrGroup, { idGenerator }));
|
|
4021
|
-
|
|
4011
|
+
return query;
|
|
4012
|
+
};
|
|
4022
4013
|
/**
|
|
4023
|
-
* Updates a property of a rule or group within a query.
|
|
4024
|
-
*
|
|
4014
|
+
* Updates a property of a rule or group within a query without mutating the original query.
|
|
4015
|
+
*
|
|
4016
|
+
* @returns A new query with the rule or group property updated.
|
|
4025
4017
|
*
|
|
4026
4018
|
* @group Query Tools
|
|
4027
4019
|
*/
|
|
4028
|
-
const update = (query, prop, value, pathOrID,
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4020
|
+
const update = (query, prop, value, pathOrID, options = {}) => produce(query, (q) => updateInPlace(q, prop, value, pathOrID, options));
|
|
4021
|
+
/**
|
|
4022
|
+
* Updates a property of a rule or group within a query in place.
|
|
4023
|
+
*
|
|
4024
|
+
* @returns The query (mutated in place) with the rule or group property updated.
|
|
4025
|
+
*
|
|
4026
|
+
* @group Query Tools
|
|
4027
|
+
*/
|
|
4028
|
+
const updateInPlace = (query, prop, value, pathOrID, options = {}) => {
|
|
4029
|
+
const { resetOnFieldChange: _resetOnFieldChange = true, resetOnOperatorChange = false, getRuleDefaultOperator = () => "=", getValueSources = () => ["value"], getRuleDefaultValue = () => "", getMatchModes = () => [] } = options;
|
|
4030
|
+
let resetOnFieldChange = _resetOnFieldChange;
|
|
4031
|
+
const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
|
|
4032
|
+
if (!path) return query;
|
|
4033
|
+
if (prop === "combinator" && !isRuleGroupType(query)) {
|
|
4034
|
+
const parentRules = findPath(getParentPath(path), query).rules;
|
|
4033
4035
|
if (path.at(-1) % 2 === 1) parentRules[path.at(-1)] = value;
|
|
4034
|
-
return;
|
|
4036
|
+
return query;
|
|
4035
4037
|
}
|
|
4036
|
-
const ruleOrGroup = findPath(path,
|
|
4037
|
-
if (!ruleOrGroup) return;
|
|
4038
|
+
const ruleOrGroup = findPath(path, query);
|
|
4039
|
+
if (!ruleOrGroup) return query;
|
|
4038
4040
|
const isGroup = isRuleGroup(ruleOrGroup);
|
|
4039
|
-
if (ruleOrGroup[prop] === value) return;
|
|
4041
|
+
if (ruleOrGroup[prop] === value) return query;
|
|
4040
4042
|
if (prop !== "valueSource") ruleOrGroup[prop] = value;
|
|
4041
|
-
if (isGroup) return;
|
|
4043
|
+
if (isGroup) return query;
|
|
4042
4044
|
let resetValueSource = false;
|
|
4043
4045
|
let resetValue = false;
|
|
4044
4046
|
if (prop === "field") {
|
|
@@ -4073,25 +4075,33 @@ const update = (query, prop, value, pathOrID, { resetOnFieldChange = true, reset
|
|
|
4073
4075
|
ruleOrGroup.valueSource = resetValueSource ? defaultValueSource : value;
|
|
4074
4076
|
}
|
|
4075
4077
|
if (resetValue) ruleOrGroup.value = getRuleDefaultValue(ruleOrGroup);
|
|
4076
|
-
|
|
4078
|
+
return query;
|
|
4079
|
+
};
|
|
4080
|
+
/**
|
|
4081
|
+
* Removes a rule or group from a query without mutating the original query.
|
|
4082
|
+
*
|
|
4083
|
+
* @returns A new query with the rule or group removed.
|
|
4084
|
+
*
|
|
4085
|
+
* @group Query Tools
|
|
4086
|
+
*/
|
|
4087
|
+
const remove = (query, pathOrID) => produce(query, (q) => removeInPlace(q, pathOrID));
|
|
4077
4088
|
/**
|
|
4078
|
-
* Removes a rule or group from a query.
|
|
4079
|
-
*
|
|
4089
|
+
* Removes a rule or group from a query in place.
|
|
4090
|
+
*
|
|
4091
|
+
* @returns The query (mutated in place) with the rule or group removed.
|
|
4080
4092
|
*
|
|
4081
4093
|
* @group Query Tools
|
|
4082
4094
|
*/
|
|
4083
|
-
const
|
|
4095
|
+
const removeInPlace = (query, pathOrID) => {
|
|
4084
4096
|
const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
|
|
4085
|
-
if (!path) return query;
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
const
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
} else parent.rules.splice(index, 1);
|
|
4094
|
-
});
|
|
4097
|
+
if (!path || path.length === 0 || !isRuleGroupType(query) && !findPath(path, query)) return query;
|
|
4098
|
+
const index = path.at(-1);
|
|
4099
|
+
const parent = findPath(getParentPath(path), query);
|
|
4100
|
+
if (parent && isRuleGroup(parent)) if (!isRuleGroupType(parent) && parent.rules.length > 1) {
|
|
4101
|
+
const idxStartDelete = index === 0 ? 0 : index - 1;
|
|
4102
|
+
parent.rules.splice(idxStartDelete, 2);
|
|
4103
|
+
} else parent.rules.splice(index, 1);
|
|
4104
|
+
return query;
|
|
4095
4105
|
};
|
|
4096
4106
|
const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
|
|
4097
4107
|
if (Array.isArray(newPathOrShiftDirection)) return newPathOrShiftDirection;
|
|
@@ -4118,59 +4128,79 @@ const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
|
|
|
4118
4128
|
return currentPath;
|
|
4119
4129
|
};
|
|
4120
4130
|
/**
|
|
4121
|
-
* Moves a rule or group from one path to another
|
|
4122
|
-
* `{ clone: true }` to copy instead of move.
|
|
4123
|
-
*
|
|
4131
|
+
* Moves a rule or group from one path to another without mutating the original query.
|
|
4132
|
+
* In the options parameter, pass `{ clone: true }` to copy instead of move.
|
|
4133
|
+
*
|
|
4134
|
+
* @returns A new query with the rule or group moved or cloned.
|
|
4124
4135
|
*
|
|
4125
4136
|
* @group Query Tools
|
|
4126
4137
|
*/
|
|
4127
|
-
const move = (query, oldPathOrID, newPath,
|
|
4138
|
+
const move = (query, oldPathOrID, newPath, options = {}) => produce(query, (q) => moveInPlace(q, oldPathOrID, newPath, options));
|
|
4139
|
+
/**
|
|
4140
|
+
* Moves a rule or group from one path to another in place.
|
|
4141
|
+
* In the options parameter, pass `{ clone: true }` to copy instead of move.
|
|
4142
|
+
*
|
|
4143
|
+
* @returns The query (mutated in place) with the rule or group moved or cloned.
|
|
4144
|
+
*
|
|
4145
|
+
* @group Query Tools
|
|
4146
|
+
*/
|
|
4147
|
+
const moveInPlace = (query, oldPathOrID, newPath, options = {}) => {
|
|
4148
|
+
const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
|
|
4128
4149
|
const oldPath = Array.isArray(oldPathOrID) ? oldPathOrID : getPathOfID(oldPathOrID, query);
|
|
4129
4150
|
if (!oldPath) return query;
|
|
4130
4151
|
const nextPath = getNextPath(query, oldPath, newPath);
|
|
4131
4152
|
if (oldPath.length === 0 || pathsAreEqual(oldPath, nextPath) || !findPath(getParentPath(nextPath), query)) return query;
|
|
4132
4153
|
const ruleOrGroupOriginal = findPath(oldPath, query);
|
|
4133
4154
|
if (!ruleOrGroupOriginal) return query;
|
|
4134
|
-
const ruleOrGroup = clone ? regenerateIDs(ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
});
|
|
4155
|
+
const ruleOrGroup = clone ? regenerateIDs(isDraft(ruleOrGroupOriginal) ? current(ruleOrGroupOriginal) : ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
|
|
4156
|
+
const independentCombinators = isRuleGroupTypeIC(query);
|
|
4157
|
+
const parentOfRuleToRemove = findPath(getParentPath(oldPath), query);
|
|
4158
|
+
const ruleToRemoveIndex = oldPath.at(-1);
|
|
4159
|
+
const oldPrevCombinator = independentCombinators && ruleToRemoveIndex > 0 ? parentOfRuleToRemove.rules[ruleToRemoveIndex - 1] : null;
|
|
4160
|
+
const oldNextCombinator = independentCombinators && ruleToRemoveIndex < parentOfRuleToRemove.rules.length - 1 ? parentOfRuleToRemove.rules[ruleToRemoveIndex + 1] : null;
|
|
4161
|
+
if (!clone) {
|
|
4162
|
+
const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
|
|
4163
|
+
const deleteLength = independentCombinators ? 2 : 1;
|
|
4164
|
+
parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
|
|
4165
|
+
}
|
|
4166
|
+
const newNewPath = [...nextPath];
|
|
4167
|
+
const commonAncestorPath = getCommonAncestorPath(oldPath, nextPath);
|
|
4168
|
+
if (!clone && oldPath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > oldPath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
|
|
4169
|
+
const parentToInsertInto = findPath(getParentPath(newNewPath), query);
|
|
4170
|
+
const newIndex = newNewPath.at(-1);
|
|
4171
|
+
/**
|
|
4172
|
+
* This function 1) glosses over the need for type assertions to splice directly
|
|
4173
|
+
* into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
|
|
4174
|
+
*/
|
|
4175
|
+
const insertRuleOrGroup = (...args) => parentToInsertInto.rules.splice(newIndex, 0, ...args);
|
|
4176
|
+
if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(ruleOrGroup);
|
|
4177
|
+
else if (newIndex === 0) if (ruleToRemoveIndex === 0 && oldNextCombinator) insertRuleOrGroup(ruleOrGroup, oldNextCombinator);
|
|
4178
|
+
else insertRuleOrGroup(ruleOrGroup, parentToInsertInto.rules[1] ?? oldPrevCombinator ?? getFirstOption(combinators));
|
|
4179
|
+
else if (oldPrevCombinator) insertRuleOrGroup(oldPrevCombinator, ruleOrGroup);
|
|
4180
|
+
else insertRuleOrGroup(parentToInsertInto.rules[newIndex - 2] ?? oldNextCombinator ?? getFirstOption(combinators), ruleOrGroup);
|
|
4181
|
+
return query;
|
|
4162
4182
|
};
|
|
4163
4183
|
/**
|
|
4164
|
-
* Inserts a rule or group into a query.
|
|
4165
|
-
*
|
|
4184
|
+
* Inserts a rule or group into a query without mutating the original query.
|
|
4185
|
+
*
|
|
4186
|
+
* @returns A new query with the rule or group inserted.
|
|
4187
|
+
*
|
|
4188
|
+
* @group Query Tools
|
|
4189
|
+
*/
|
|
4190
|
+
const insert = (query, ruleOrGroup, path, options = {}) => produce(query, (q) => insertInPlace(q, ruleOrGroup, path, options));
|
|
4191
|
+
/**
|
|
4192
|
+
* Inserts a rule or group into a query in place.
|
|
4193
|
+
*
|
|
4194
|
+
* @returns The query (mutated in place) with the rule or group inserted.
|
|
4166
4195
|
*
|
|
4167
4196
|
* @group Query Tools
|
|
4168
4197
|
*/
|
|
4169
|
-
const
|
|
4170
|
-
const
|
|
4171
|
-
|
|
4198
|
+
const insertInPlace = (query, ruleOrGroup, path, options = {}) => {
|
|
4199
|
+
const { combinators = defaultCombinators, combinatorPreceding, combinatorSucceeding, idGenerator = generateID, replace = false } = options;
|
|
4200
|
+
const parentToInsertInto = findPath(getParentPath(path), query);
|
|
4201
|
+
if (!parentToInsertInto || !isRuleGroup(parentToInsertInto)) return query;
|
|
4172
4202
|
const rorg = regenerateIDs(ruleOrGroup, { idGenerator });
|
|
4173
|
-
const independentCombinators = isRuleGroupTypeIC(
|
|
4203
|
+
const independentCombinators = isRuleGroupTypeIC(query);
|
|
4174
4204
|
const newIndex = path.at(-1);
|
|
4175
4205
|
/**
|
|
4176
4206
|
* This function 1) glosses over the need for type assertions to splice directly
|
|
@@ -4186,17 +4216,29 @@ const insert = (query, ruleOrGroup, path, { combinators = defaultCombinators, co
|
|
|
4186
4216
|
if (combinatorPreceding) insertRuleOrGroup(normalizedNewIndex, combinatorPreceding, rorg);
|
|
4187
4217
|
else insertRuleOrGroup(normalizedNewIndex, parentToInsertInto.rules[normalizedNewIndex - 2] ?? combinatorSucceeding ?? getFirstOption(combinators), rorg);
|
|
4188
4218
|
}
|
|
4189
|
-
|
|
4219
|
+
return query;
|
|
4220
|
+
};
|
|
4190
4221
|
/**
|
|
4191
4222
|
* Creates a new group at a target path with its `rules` array containing the current
|
|
4192
|
-
* objects at the target path and the source path
|
|
4193
|
-
* `{ clone: true }` to copy the source rule/group instead of move.
|
|
4223
|
+
* objects at the target path and the source path without mutating the original query.
|
|
4224
|
+
* In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
|
|
4194
4225
|
*
|
|
4195
|
-
* @returns
|
|
4226
|
+
* @returns A new query with the rules or groups grouped.
|
|
4196
4227
|
*
|
|
4197
4228
|
* @group Query Tools
|
|
4198
4229
|
*/
|
|
4199
|
-
const group = (query, sourcePathOrID, targetPathOrID,
|
|
4230
|
+
const group = (query, sourcePathOrID, targetPathOrID, options = {}) => produce(query, (q) => groupInPlace(q, sourcePathOrID, targetPathOrID, options));
|
|
4231
|
+
/**
|
|
4232
|
+
* Creates a new group at a target path with its `rules` array containing the current
|
|
4233
|
+
* objects at the target path and the source path in place.
|
|
4234
|
+
* In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
|
|
4235
|
+
*
|
|
4236
|
+
* @returns The query (mutated in place) with the rules or groups grouped.
|
|
4237
|
+
*
|
|
4238
|
+
* @group Query Tools
|
|
4239
|
+
*/
|
|
4240
|
+
const groupInPlace = (query, sourcePathOrID, targetPathOrID, options = {}) => {
|
|
4241
|
+
const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
|
|
4200
4242
|
const sourcePath = Array.isArray(sourcePathOrID) ? sourcePathOrID : getPathOfID(sourcePathOrID, query);
|
|
4201
4243
|
const targetPath = Array.isArray(targetPathOrID) ? targetPathOrID : getPathOfID(targetPathOrID, query);
|
|
4202
4244
|
if (!sourcePath || !targetPath) return query;
|
|
@@ -4205,32 +4247,31 @@ const group = (query, sourcePathOrID, targetPathOrID, { clone = false, combinato
|
|
|
4205
4247
|
const sourceRuleOrGroupOriginal = findPath(sourcePath, query);
|
|
4206
4248
|
const targetRuleOrGroup = findPath(targetPath, query);
|
|
4207
4249
|
if (!sourceRuleOrGroupOriginal || !targetRuleOrGroup) return query;
|
|
4208
|
-
const sourceRuleOrGroup = clone ? regenerateIDs(sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
});
|
|
4250
|
+
const sourceRuleOrGroup = clone ? regenerateIDs(isDraft(sourceRuleOrGroupOriginal) ? current(sourceRuleOrGroupOriginal) : sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
|
|
4251
|
+
const independentCombinators = isRuleGroupTypeIC(query);
|
|
4252
|
+
const parentOfRuleToRemove = findPath(getParentPath(sourcePath), query);
|
|
4253
|
+
const ruleToRemoveIndex = sourcePath.at(-1);
|
|
4254
|
+
if (!clone) {
|
|
4255
|
+
const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
|
|
4256
|
+
const deleteLength = independentCombinators ? 2 : 1;
|
|
4257
|
+
parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
|
|
4258
|
+
}
|
|
4259
|
+
const newNewPath = [...nextPath];
|
|
4260
|
+
const commonAncestorPath = getCommonAncestorPath(sourcePath, nextPath);
|
|
4261
|
+
if (!clone && sourcePath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > sourcePath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
|
|
4262
|
+
const parentOfTargetPath = findPath(getParentPath(newNewPath), query);
|
|
4263
|
+
const targetPathIndex = newNewPath.at(-1);
|
|
4264
|
+
parentOfTargetPath.rules.splice(targetPathIndex, 1, prepareRuleOrGroup(independentCombinators ? { rules: [
|
|
4265
|
+
targetRuleOrGroup,
|
|
4266
|
+
getFirstOption(combinators),
|
|
4267
|
+
sourceRuleOrGroup
|
|
4268
|
+
] } : {
|
|
4269
|
+
combinator: getFirstOption(combinators),
|
|
4270
|
+
rules: [targetRuleOrGroup, sourceRuleOrGroup]
|
|
4271
|
+
}, { idGenerator }));
|
|
4272
|
+
return query;
|
|
4232
4273
|
};
|
|
4233
|
-
|
|
4234
4274
|
//#endregion
|
|
4235
|
-
export { LogType, TestID, add, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInvalidReasons, insert, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update };
|
|
4275
|
+
export { LogType, TestID, add, addInPlace, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInPlace, groupInvalidReasons, insert, insertInPlace, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, moveInPlace, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, removeInPlace, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update, updateInPlace };
|
|
4276
|
+
|
|
4236
4277
|
//# sourceMappingURL=react-querybuilder_core.mjs.map
|