@react-querybuilder/core 8.13.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.
Files changed (100) hide show
  1. package/dist/{basic-Cw014pDc.d.mts → basic-BXJVfD0P.d.ts} +77 -59
  2. package/dist/{basic-_KlsCAyT.d.ts → basic-CNIjb6rI.d.mts} +77 -59
  3. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +201 -150
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js +323 -252
  5. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  6. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +201 -150
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  8. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  9. package/dist/{convertQuery-DAj92cbM.mjs → convertQuery-B5Qm_6ut.mjs} +30 -22
  10. package/dist/convertQuery-B5Qm_6ut.mjs.map +1 -0
  11. package/dist/convertQuery-DfZehtnd.js +94 -0
  12. package/dist/convertQuery-DfZehtnd.js.map +1 -0
  13. package/dist/{export-CffjLxEe.d.mts → export-6x7MilFR.d.mts} +2 -3
  14. package/dist/{export-DRA8O1Wz.d.ts → export-CpJOQuZv.d.ts} +2 -3
  15. package/dist/formatQuery.d.mts +4 -3
  16. package/dist/formatQuery.d.ts +4 -3
  17. package/dist/formatQuery.js +42 -51
  18. package/dist/formatQuery.js.map +1 -1
  19. package/dist/formatQuery.mjs +41 -50
  20. package/dist/formatQuery.mjs.map +1 -1
  21. package/dist/{import-CWYJkN_w.d.ts → import-B5Iq8XmL.d.ts} +2 -3
  22. package/dist/{import-DjHGaGhJ.d.mts → import-Bltb2mT4.d.mts} +2 -3
  23. package/dist/{isRuleGroup-Cjk1Q2mj.js → isRuleGroup-BCwaLzDj.js} +38 -40
  24. package/dist/isRuleGroup-BCwaLzDj.js.map +1 -0
  25. package/dist/{isRuleGroup-DztIOOKa.mjs → isRuleGroup-LzP0HCKh.mjs} +2 -4
  26. package/dist/isRuleGroup-LzP0HCKh.mjs.map +1 -0
  27. package/dist/parseCEL.d.mts +2 -2
  28. package/dist/parseCEL.d.ts +2 -2
  29. package/dist/parseCEL.js +14 -16
  30. package/dist/parseCEL.js.map +1 -1
  31. package/dist/parseCEL.mjs +7 -10
  32. package/dist/parseCEL.mjs.map +1 -1
  33. package/dist/parseJSONata.d.mts +2 -3
  34. package/dist/parseJSONata.d.ts +2 -3
  35. package/dist/parseJSONata.js +37 -5611
  36. package/dist/parseJSONata.js.map +1 -1
  37. package/dist/parseJSONata.mjs +11 -14
  38. package/dist/parseJSONata.mjs.map +1 -1
  39. package/dist/parseJsonLogic.d.mts +3 -4
  40. package/dist/parseJsonLogic.d.ts +3 -4
  41. package/dist/parseJsonLogic.js +20 -21
  42. package/dist/parseJsonLogic.js.map +1 -1
  43. package/dist/parseJsonLogic.mjs +19 -21
  44. package/dist/parseJsonLogic.mjs.map +1 -1
  45. package/dist/parseMongoDB.d.mts +2 -3
  46. package/dist/parseMongoDB.d.ts +2 -3
  47. package/dist/parseMongoDB.js +7 -8
  48. package/dist/parseMongoDB.js.map +1 -1
  49. package/dist/parseMongoDB.mjs +6 -8
  50. package/dist/parseMongoDB.mjs.map +1 -1
  51. package/dist/parseSQL.d.mts +2 -3
  52. package/dist/parseSQL.d.ts +2 -3
  53. package/dist/parseSQL.js +14 -16
  54. package/dist/parseSQL.js.map +1 -1
  55. package/dist/parseSQL.mjs +7 -10
  56. package/dist/parseSQL.mjs.map +1 -1
  57. package/dist/parseSpEL.d.mts +2 -3
  58. package/dist/parseSpEL.d.ts +2 -3
  59. package/dist/parseSpEL.js +11 -2700
  60. package/dist/parseSpEL.js.map +1 -1
  61. package/dist/parseSpEL.mjs +7 -9
  62. package/dist/parseSpEL.mjs.map +1 -1
  63. package/dist/{prepareQueryObjects-CkN0bTKm.js → prepareQueryObjects-Dc8rqsYM.js} +50 -38
  64. package/dist/prepareQueryObjects-Dc8rqsYM.js.map +1 -0
  65. package/dist/{prepareQueryObjects-6Bxx4Bs1.mjs → prepareQueryObjects-tMukQHT9.mjs} +35 -22
  66. package/dist/prepareQueryObjects-tMukQHT9.mjs.map +1 -0
  67. package/dist/react-querybuilder_core.d.mts +201 -150
  68. package/dist/react-querybuilder_core.legacy-esm.d.ts +201 -150
  69. package/dist/react-querybuilder_core.legacy-esm.js +317 -280
  70. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  71. package/dist/react-querybuilder_core.mjs +312 -248
  72. package/dist/react-querybuilder_core.mjs.map +1 -1
  73. package/dist/react-querybuilder_core.production.d.mts +201 -150
  74. package/dist/react-querybuilder_core.production.mjs +1 -1
  75. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  76. package/dist/transformQuery.d.mts +1 -2
  77. package/dist/transformQuery.d.ts +1 -2
  78. package/dist/transformQuery.js +44 -3
  79. package/dist/transformQuery.js.map +1 -0
  80. package/dist/transformQuery.mjs +43 -3
  81. package/dist/transformQuery.mjs.map +1 -0
  82. package/dist/{utils-nQU7WCM9.mjs → utils-DQoYnxpa.mjs} +32 -84
  83. package/dist/utils-DQoYnxpa.mjs.map +1 -0
  84. package/dist/{utils-CR1ToTMW.js → utils-EsYRkPtf.js} +182 -246
  85. package/dist/utils-EsYRkPtf.js.map +1 -0
  86. package/package.json +29 -21
  87. package/dist/chunk-U64pC571.js +0 -41
  88. package/dist/convertQuery-DAj92cbM.mjs.map +0 -1
  89. package/dist/convertQuery-DRldbzhZ.js +0 -87
  90. package/dist/convertQuery-DRldbzhZ.js.map +0 -1
  91. package/dist/isRuleGroup-Cjk1Q2mj.js.map +0 -1
  92. package/dist/isRuleGroup-DztIOOKa.mjs.map +0 -1
  93. package/dist/prepareQueryObjects-6Bxx4Bs1.mjs.map +0 -1
  94. package/dist/prepareQueryObjects-CkN0bTKm.js.map +0 -1
  95. package/dist/transformQuery-ClBRfnFg.js +0 -54
  96. package/dist/transformQuery-ClBRfnFg.js.map +0 -1
  97. package/dist/transformQuery-DUpbpqjX.mjs +0 -48
  98. package/dist/transformQuery-DUpbpqjX.mjs.map +0 -1
  99. package/dist/utils-CR1ToTMW.js.map +0 -1
  100. 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 = defaultPlaceholderName;
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 = defaultPlaceholderName;
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 = defaultPlaceholderName;
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: defaultPlaceholderFieldName,
74
+ placeholderName: "~",
76
75
  placeholderLabel: defaultPlaceholderFieldLabel,
77
76
  placeholderGroupLabel: defaultPlaceholderFieldGroupLabel
78
77
  },
79
78
  operators: {
80
79
  title: "Operator",
81
- placeholderName: defaultPlaceholderOperatorName,
80
+ placeholderName: "~",
82
81
  placeholderLabel: defaultPlaceholderOperatorLabel,
83
82
  placeholderGroupLabel: defaultPlaceholderOperatorGroupLabel
84
83
  },
85
84
  values: {
86
85
  title: "Values",
87
- placeholderName: defaultPlaceholderValueName,
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 = defaultJoinChar) => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
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 = defaultJoinChar) => strArr.map((str) => `${str ?? ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(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 = (v, { retainEmptyStrings } = {}) => Array.isArray(v) ? v.map((v$1) => trimIfString(v$1)) : typeof v === "string" ? splitBy(v, defaultJoinChar).filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof v === "number" ? [v] : [];
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
- return produce(rg, (draft) => {
709
- let cursor = 0;
710
- while (cursor < draft.rules.length - 2) {
711
- if (isSameString(draft.rules[cursor + 1], baseCombinator)) {
712
- cursor += 2;
713
- continue;
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 rulesAsMixedList = processedRG.rules.map((r) => typeof r === "string" || !isRuleGroup(r) ? r : convertFromIC(r));
735
- const combinator = rulesAsMixedList.length < 2 ? "and" : rulesAsMixedList[1];
736
- const rules = rulesAsMixedList.filter((r) => typeof r !== "string");
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 (const [idx, r] of rg.rules.entries()) {
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
- return produce((draft) => {
834
- const idObj = {};
835
- let needsUpdating = !!baseProperties;
836
- if (typeof draft === "string") return {
837
- ...baseProperties,
838
- name: draft,
839
- value: draft,
840
- label: labelMap?.[draft] ?? draft
841
- };
842
- if (isOptionWithName(draft) && !isOptionWithValue(draft)) {
843
- idObj.value = draft.name;
844
- needsUpdating = true;
845
- } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {
846
- idObj.name = draft.value;
847
- needsUpdating = true;
848
- }
849
- if (needsUpdating) return Object.assign({}, baseProperties, draft, idObj);
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
- return produce((draft) => {
861
- if (isFlexibleOptionGroupArray(draft)) for (const optGroup of draft) for (const [idx, opt] of optGroup.options.entries()) optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);
862
- else for (const [idx, opt] of draft.entries()) draft[idx] = toFullOption(opt, baseProperties, labelMap);
863
- })(optList);
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 = defaultPlaceholderName, placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
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
- * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),
1095
- * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a
1096
- * new query object if there were any referential changes.
1097
- *
1098
- * @module transformQuery
1099
- */
1100
- const remapProperties = (obj, propertyMap, deleteRemappedProperties) => produce(obj, (draft) => {
1101
- for (const [k, v] of Object.entries(propertyMap)) if (v === false) delete draft[k];
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
- * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
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
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
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$1) => negate$1 ? `!(${clause})` : clause;
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$1 = shouldNegate$1(operatorTL) ? "!" : "";
1843
+ const negate = shouldNegate$1(operatorTL) ? "!" : "";
1855
1844
  const valueAsArray = toArray(value);
1856
- return valueAsArray.length > 0 ? `${negate$1}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
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
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
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 = {
@@ -2585,7 +2561,30 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
2585
2561
  const { field, operator, value, valueSource } = rule;
2586
2562
  const { parseNumbers, preserveValueOrder } = options;
2587
2563
  const operatorLC = lc(operator);
2588
- if (processMatchMode(rule)) return false;
2564
+ const matchEval = processMatchMode(rule);
2565
+ if (matchEval === false) return false;
2566
+ else if (matchEval) {
2567
+ const { mode } = matchEval;
2568
+ const subQuery = defaultRuleGroupProcessorElasticSearch(transformQuery(rule.value, { ruleProcessor: (r) => ({
2569
+ ...r,
2570
+ field: r.field ? `${field}.${r.field}` : field
2571
+ }) }), options);
2572
+ if (Object.keys(subQuery).length === 0) return false;
2573
+ switch (mode) {
2574
+ case "some": return { nested: {
2575
+ path: field,
2576
+ query: subQuery
2577
+ } };
2578
+ case "none": return { bool: { must_not: { nested: {
2579
+ path: field,
2580
+ query: subQuery
2581
+ } } } };
2582
+ case "all":
2583
+ case "atleast":
2584
+ case "atmost":
2585
+ case "exactly": return false;
2586
+ }
2587
+ }
2589
2588
  if (valueSource === "field") {
2590
2589
  if (toArray(value).some((v) => typeof v !== "string")) return false;
2591
2590
  const fieldForScript = escapeSQ(field);
@@ -2682,12 +2681,11 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
2682
2681
  }
2683
2682
  return false;
2684
2683
  };
2685
-
2686
2684
  //#endregion
2687
2685
  //#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
2688
2686
  const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
2689
2687
  const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
2690
- const negate = (clause, negate$1) => negate$1 ? `$not(${clause})` : clause;
2688
+ const negate = (clause, neg) => neg ? `$not(${clause})` : clause;
2691
2689
  const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
2692
2690
  /**
2693
2691
  * Default rule processor used by {@link formatQuery} for "jsonata" format.
@@ -2769,7 +2767,6 @@ const defaultRuleProcessorJSONata = (rule, options = {}) => {
2769
2767
  }
2770
2768
  return "";
2771
2769
  };
2772
-
2773
2770
  //#endregion
2774
2771
  //#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
2775
2772
  const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
@@ -2864,10 +2861,9 @@ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
2864
2861
  }
2865
2862
  return false;
2866
2863
  };
2867
-
2868
2864
  //#endregion
2869
2865
  //#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
2870
- const negateIf = (clause, negate$1) => negate$1 ? `(!${clause})` : `${clause}`;
2866
+ const negateIf = (clause, negate) => negate ? `(!${clause})` : `${clause}`;
2871
2867
  const ldapEscape = (s) => `${trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
2872
2868
  /**
2873
2869
  * Default rule processor used by {@link formatQuery} for "ldap" format.
@@ -2916,7 +2912,6 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
2916
2912
  // istanbul ignore next
2917
2913
  return "";
2918
2914
  };
2919
-
2920
2915
  //#endregion
2921
2916
  //#region src/utils/formatQuery/defaultValueProcessorNL.ts
2922
2917
  const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
@@ -2966,7 +2961,6 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
2966
2961
  if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
2967
2962
  return valueIsField ? wrapFieldName(getOption(fields ?? [], rule.value)?.label ?? rule.value) : shouldRenderAsNumber(rule.value, parseNumbers) ? `${trimIfString(rule.value)}` : `${wrapAndEscape(rule.value)}`;
2968
2963
  };
2969
-
2970
2964
  //#endregion
2971
2965
  //#region src/utils/formatQuery/defaultRuleProcessorNL.ts
2972
2966
  /**
@@ -3076,7 +3070,6 @@ const defaultRuleProcessorNL = (rule, opts) => {
3076
3070
  };
3077
3071
  return normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
3078
3072
  };
3079
-
3080
3073
  //#endregion
3081
3074
  //#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
3082
3075
  /**
@@ -3131,7 +3124,6 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
3131
3124
  if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
3132
3125
  return `${ruleField} ${operator} ${value}`.trim();
3133
3126
  };
3134
-
3135
3127
  //#endregion
3136
3128
  //#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
3137
3129
  /**
@@ -3236,7 +3228,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
3236
3228
  }
3237
3229
  return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
3238
3230
  };
3239
-
3240
3231
  //#endregion
3241
3232
  //#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
3242
3233
  const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
@@ -3298,7 +3289,6 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
3298
3289
  }
3299
3290
  return "";
3300
3291
  };
3301
-
3302
3292
  //#endregion
3303
3293
  //#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
3304
3294
  /**
@@ -3365,7 +3355,6 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
3365
3355
  }
3366
3356
  }
3367
3357
  };
3368
-
3369
3358
  //#endregion
3370
3359
  //#region src/utils/formatQuery/formatQuery.ts
3371
3360
  /**
@@ -3454,8 +3443,8 @@ const defaultFormatQueryOptions = {
3454
3443
  paramsKeepPrefix: false,
3455
3444
  numberedParams: false,
3456
3445
  preserveValueOrder: false,
3457
- placeholderFieldName: defaultPlaceholderFieldName,
3458
- placeholderOperatorName: defaultPlaceholderOperatorName,
3446
+ placeholderFieldName: "~",
3447
+ placeholderOperatorName: "~",
3459
3448
  quoteValuesWith: "'",
3460
3449
  concatOperator: "||",
3461
3450
  preset: "ansi",
@@ -3560,7 +3549,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
3560
3549
  switch (format) {
3561
3550
  case "json":
3562
3551
  case "json_without_ids": {
3563
- const rg = parseNumbers ? produce(ruleGroup, (g) => numerifyValues(g, finalOptions)) : ruleGroup;
3552
+ const rg = parseNumbers ? numerifyValues(ruleGroup, finalOptions) : ruleGroup;
3564
3553
  if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : bigIntJsonStringifyReplacer(key, value));
3565
3554
  return JSON.stringify(rg, bigIntJsonStringifyReplacer, 2);
3566
3555
  }
@@ -3582,7 +3571,6 @@ function formatQuery(ruleGroup, optionParam = {}) {
3582
3571
  default: return "";
3583
3572
  }
3584
3573
  }
3585
-
3586
3574
  //#endregion
3587
3575
  //#region src/utils/formatQuery/index.ts
3588
3576
  const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
@@ -3633,7 +3621,6 @@ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
3633
3621
  * @group Export
3634
3622
  */
3635
3623
  const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
3636
-
3637
3624
  //#endregion
3638
3625
  //#region src/utils/pathUtils.ts
3639
3626
  /**
@@ -3692,7 +3679,7 @@ const pathsAreEqual = (path1, path2) => path1.length === path2.length && path1.e
3692
3679
  * Determines if the first path is an ancestor of the second path. The first path must
3693
3680
  * be shorter and exactly match the second path up through the length of the first path.
3694
3681
  */
3695
- const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length && (/* @__PURE__ */ new RegExp(`^${maybeAncestor.join("-")}`)).test(path.join("-"));
3682
+ const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length && new RegExp(`^${maybeAncestor.join("-")}`).test(path.join("-"));
3696
3683
  /**
3697
3684
  * Finds the deepest/longest path that two paths have in common.
3698
3685
  */
@@ -3725,11 +3712,9 @@ const pathIsDisabled = (path, query) => {
3725
3712
  }
3726
3713
  return disabled;
3727
3714
  };
3728
-
3729
3715
  //#endregion
3730
3716
  //#region src/utils/generateAccessibleDescription.ts
3731
3717
  const generateAccessibleDescription = (params) => pathsAreEqual([], params.path) ? `Query builder` : `Rule group at path ${params.path.join("-")}`;
3732
-
3733
3718
  //#endregion
3734
3719
  //#region src/utils/generateID.ts
3735
3720
  const cryptoModule = globalThis.crypto;
@@ -3764,7 +3749,6 @@ if (cryptoModule) {
3764
3749
  };
3765
3750
  }
3766
3751
  }
3767
-
3768
3752
  //#endregion
3769
3753
  //#region src/utils/getMatchModesUtil.ts
3770
3754
  const dummyFD$1 = {
@@ -3792,7 +3776,6 @@ const getMatchModesUtil = (fieldData, getMatchModes) => {
3792
3776
  label: mm
3793
3777
  }) ?? [];
3794
3778
  };
3795
-
3796
3779
  //#endregion
3797
3780
  //#region src/utils/getValidationClassNames.ts
3798
3781
  /**
@@ -3803,7 +3786,6 @@ const getValidationClassNames = (validationResult) => {
3803
3786
  const valid = typeof validationResult === "boolean" ? validationResult : typeof validationResult === "object" && validationResult !== null ? validationResult.valid : null;
3804
3787
  return typeof valid === "boolean" ? valid ? standardClassnames.valid : standardClassnames.invalid : "";
3805
3788
  };
3806
-
3807
3789
  //#endregion
3808
3790
  //#region src/utils/getValueSourcesUtil.ts
3809
3791
  const defaultValueSourcesArray = [{
@@ -3836,18 +3818,22 @@ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
3836
3818
  label: vs
3837
3819
  });
3838
3820
  };
3839
-
3840
3821
  //#endregion
3841
3822
  //#region src/utils/mergeAnyTranslations.ts
3842
3823
  /**
3843
3824
  * Merges any number of partial translations into a single definition.
3844
3825
  */
3845
- const mergeAnyTranslations = (base, ...otherTranslations) => produce(base, (draft) => {
3826
+ const mergeAnyTranslations = (base, ...otherTranslations) => {
3827
+ const result = { ...base };
3846
3828
  for (const translations of otherTranslations)
3847
3829
  // istanbul ignore else
3848
- if (translations) for (const t of objectKeys(translations)) if (draft[t]) Object.assign(draft[t], translations[t]);
3849
- else Object.assign(draft, { [t]: translations[t] });
3850
- });
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
+ };
3851
3837
  const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
3852
3838
  const finalKeys = objectEntries(keyPropContextMap).map(([key, [pT, cT]]) => [key, pT ?? cT ?? defaults?.[el]?.[key]]).filter((k) => !!k[1]);
3853
3839
  if (finalKeys.length > 0 || defaults) {
@@ -3856,7 +3842,6 @@ const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
3856
3842
  return { [el]: finalObject };
3857
3843
  }
3858
3844
  };
3859
-
3860
3845
  //#endregion
3861
3846
  //#region src/utils/mergeClassnames.ts
3862
3847
  const joinClassnamesByName = (name, args) => clsx(args.map((c) => clsx(c?.[name])));
@@ -3906,7 +3891,6 @@ const mergeClassnames = (...args) => ({
3906
3891
  hasSubQuery: joinClassnamesByName("hasSubQuery", args),
3907
3892
  loading: joinClassnamesByName("loading", args)
3908
3893
  });
3909
-
3910
3894
  //#endregion
3911
3895
  //#region src/utils/preferProp.ts
3912
3896
  const preferPropDefaultTrue = (prop, context) => prop === false ? false : prop ? true : !(context === false);
@@ -3929,29 +3913,49 @@ const preferFlagProps = (props = {}, contextVals = {}, finalize) => objectEntrie
3929
3913
  acc[key] = preferProp(def, props[key], contextVals[key], !finalize);
3930
3914
  return acc;
3931
3915
  }, {});
3932
-
3933
3916
  //#endregion
3934
3917
  //#region src/utils/prepareQueryObjects.ts
3935
3918
  /**
3936
3919
  * Ensures that a rule is valid by adding an `id` property if it does not already exist.
3937
3920
  */
3938
- const prepareRule = (rule, { idGenerator = generateID } = {}) => produce(rule, (draft) => {
3939
- if (!draft.id) draft.id = idGenerator();
3940
- if (processMatchMode(draft)) draft.value = prepareRuleGroup(draft.value, { idGenerator });
3941
- });
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
+ };
3942
3931
  /**
3943
3932
  * Ensures that a rule group is valid by recursively adding an `id` property to the group itself
3944
3933
  * and all its rules and subgroups where one does not already exist.
3945
3934
  */
3946
- const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => produce(queryObject, (draft) => {
3947
- if (!draft.id) draft.id = idGenerator();
3948
- draft.rules = draft.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator }));
3949
- });
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
+ };
3950
3955
  /**
3951
3956
  * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
3952
3957
  */
3953
3958
  const prepareRuleOrGroup = (rg, { idGenerator = generateID } = {}) => isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });
3954
-
3955
3959
  //#endregion
3956
3960
  //#region src/utils/regenerateIDs.ts
3957
3961
  /**
@@ -3978,44 +3982,65 @@ const regenerateIDs = (subject, { idGenerator = generateID } = {}) => {
3978
3982
  if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
3979
3983
  return newGroup;
3980
3984
  };
3981
-
3982
3985
  //#endregion
3983
3986
  //#region src/utils/queryTools.ts
3984
3987
  /**
3985
- * Adds a rule or group to a query.
3986
- * @returns The new query with the rule or group added.
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.
3987
3999
  *
3988
4000
  * @group Query Tools
3989
4001
  */
3990
- const add = (query, ruleOrGroup, parentPathOrID, { combinators = defaultCombinators, combinatorPreceding, idGenerator = generateID } = {}) => produce(query, (draft) => {
3991
- const parent = Array.isArray(parentPathOrID) ? findPath(parentPathOrID, draft) : findID(parentPathOrID, draft);
3992
- if (!parent || !isRuleGroup(parent)) return;
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;
3993
4006
  if (isRuleGroupTypeIC(parent) && parent.rules.length > 0) {
3994
4007
  const prevCombinator = parent.rules.at(-2);
3995
4008
  parent.rules.push(combinatorPreceding ?? (typeof prevCombinator === "string" ? prevCombinator : getFirstOption(combinators)));
3996
4009
  }
3997
4010
  parent.rules.push(prepareRuleOrGroup(ruleOrGroup, { idGenerator }));
3998
- });
4011
+ return query;
4012
+ };
3999
4013
  /**
4000
- * Updates a property of a rule or group within a query.
4001
- * @returns The new query with the rule or group property updated.
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.
4017
+ *
4018
+ * @group Query Tools
4019
+ */
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.
4002
4025
  *
4003
4026
  * @group Query Tools
4004
4027
  */
4005
- const update = (query, prop, value, pathOrID, { resetOnFieldChange = true, resetOnOperatorChange = false, getRuleDefaultOperator = () => "=", getValueSources = () => ["value"], getRuleDefaultValue = () => "", getMatchModes = () => [] } = {}) => produce(query, (draft) => {
4006
- const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, draft);
4007
- if (!path) return;
4008
- if (prop === "combinator" && !isRuleGroupType(draft)) {
4009
- const parentRules = findPath(getParentPath(path), draft).rules;
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;
4010
4035
  if (path.at(-1) % 2 === 1) parentRules[path.at(-1)] = value;
4011
- return;
4036
+ return query;
4012
4037
  }
4013
- const ruleOrGroup = findPath(path, draft);
4014
- if (!ruleOrGroup) return;
4038
+ const ruleOrGroup = findPath(path, query);
4039
+ if (!ruleOrGroup) return query;
4015
4040
  const isGroup = isRuleGroup(ruleOrGroup);
4016
- if (ruleOrGroup[prop] === value) return;
4041
+ if (ruleOrGroup[prop] === value) return query;
4017
4042
  if (prop !== "valueSource") ruleOrGroup[prop] = value;
4018
- if (isGroup) return;
4043
+ if (isGroup) return query;
4019
4044
  let resetValueSource = false;
4020
4045
  let resetValue = false;
4021
4046
  if (prop === "field") {
@@ -4050,25 +4075,33 @@ const update = (query, prop, value, pathOrID, { resetOnFieldChange = true, reset
4050
4075
  ruleOrGroup.valueSource = resetValueSource ? defaultValueSource : value;
4051
4076
  }
4052
4077
  if (resetValue) ruleOrGroup.value = getRuleDefaultValue(ruleOrGroup);
4053
- });
4078
+ return query;
4079
+ };
4054
4080
  /**
4055
- * Removes a rule or group from a query.
4056
- * @returns The new query with the rule or group removed.
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));
4088
+ /**
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.
4057
4092
  *
4058
4093
  * @group Query Tools
4059
4094
  */
4060
- const remove = (query, pathOrID) => {
4095
+ const removeInPlace = (query, pathOrID) => {
4061
4096
  const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
4062
- if (!path) return query;
4063
- if (path.length === 0 || !isRuleGroupType(query) && !findPath(path, query)) return query;
4064
- return produce(query, (draft) => {
4065
- const index = path.at(-1);
4066
- const parent = findPath(getParentPath(path), draft);
4067
- if (parent && isRuleGroup(parent)) if (!isRuleGroupType(parent) && parent.rules.length > 1) {
4068
- const idxStartDelete = index === 0 ? 0 : index - 1;
4069
- parent.rules.splice(idxStartDelete, 2);
4070
- } else parent.rules.splice(index, 1);
4071
- });
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;
4072
4105
  };
4073
4106
  const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
4074
4107
  if (Array.isArray(newPathOrShiftDirection)) return newPathOrShiftDirection;
@@ -4095,59 +4128,79 @@ const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
4095
4128
  return currentPath;
4096
4129
  };
4097
4130
  /**
4098
- * Moves a rule or group from one path to another. In the options parameter, pass
4099
- * `{ clone: true }` to copy instead of move.
4100
- * @returns The new query with the rule or group moved or cloned.
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.
4135
+ *
4136
+ * @group Query Tools
4137
+ */
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.
4101
4144
  *
4102
4145
  * @group Query Tools
4103
4146
  */
4104
- const move = (query, oldPathOrID, newPath, { clone = false, combinators = defaultCombinators, idGenerator = generateID } = {}) => {
4147
+ const moveInPlace = (query, oldPathOrID, newPath, options = {}) => {
4148
+ const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
4105
4149
  const oldPath = Array.isArray(oldPathOrID) ? oldPathOrID : getPathOfID(oldPathOrID, query);
4106
4150
  if (!oldPath) return query;
4107
4151
  const nextPath = getNextPath(query, oldPath, newPath);
4108
4152
  if (oldPath.length === 0 || pathsAreEqual(oldPath, nextPath) || !findPath(getParentPath(nextPath), query)) return query;
4109
4153
  const ruleOrGroupOriginal = findPath(oldPath, query);
4110
4154
  if (!ruleOrGroupOriginal) return query;
4111
- const ruleOrGroup = clone ? regenerateIDs(ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
4112
- return produce(query, (draft) => {
4113
- const independentCombinators = isRuleGroupTypeIC(draft);
4114
- const parentOfRuleToRemove = findPath(getParentPath(oldPath), draft);
4115
- const ruleToRemoveIndex = oldPath.at(-1);
4116
- const oldPrevCombinator = independentCombinators && ruleToRemoveIndex > 0 ? parentOfRuleToRemove.rules[ruleToRemoveIndex - 1] : null;
4117
- const oldNextCombinator = independentCombinators && ruleToRemoveIndex < parentOfRuleToRemove.rules.length - 1 ? parentOfRuleToRemove.rules[ruleToRemoveIndex + 1] : null;
4118
- if (!clone) {
4119
- const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4120
- const deleteLength = independentCombinators ? 2 : 1;
4121
- parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4122
- }
4123
- const newNewPath = [...nextPath];
4124
- const commonAncestorPath = getCommonAncestorPath(oldPath, nextPath);
4125
- if (!clone && oldPath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > oldPath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4126
- const parentToInsertInto = findPath(getParentPath(newNewPath), draft);
4127
- const newIndex = newNewPath.at(-1);
4128
- /**
4129
- * This function 1) glosses over the need for type assertions to splice directly
4130
- * into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
4131
- */
4132
- const insertRuleOrGroup = (...args) => parentToInsertInto.rules.splice(newIndex, 0, ...args);
4133
- if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(ruleOrGroup);
4134
- else if (newIndex === 0) if (ruleToRemoveIndex === 0 && oldNextCombinator) insertRuleOrGroup(ruleOrGroup, oldNextCombinator);
4135
- else insertRuleOrGroup(ruleOrGroup, parentToInsertInto.rules[1] ?? oldPrevCombinator ?? getFirstOption(combinators));
4136
- else if (oldPrevCombinator) insertRuleOrGroup(oldPrevCombinator, ruleOrGroup);
4137
- else insertRuleOrGroup(parentToInsertInto.rules[newIndex - 2] ?? oldNextCombinator ?? getFirstOption(combinators), ruleOrGroup);
4138
- });
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;
4139
4182
  };
4140
4183
  /**
4141
- * Inserts a rule or group into a query.
4142
- * @returns The new query with the rule or group inserted.
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.
4143
4195
  *
4144
4196
  * @group Query Tools
4145
4197
  */
4146
- const insert = (query, ruleOrGroup, path, { combinators = defaultCombinators, combinatorPreceding, combinatorSucceeding, idGenerator = generateID, replace = false } = {}) => produce(query, (draft) => {
4147
- const parentToInsertInto = findPath(getParentPath(path), draft);
4148
- if (!parentToInsertInto || !isRuleGroup(parentToInsertInto)) return;
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;
4149
4202
  const rorg = regenerateIDs(ruleOrGroup, { idGenerator });
4150
- const independentCombinators = isRuleGroupTypeIC(draft);
4203
+ const independentCombinators = isRuleGroupTypeIC(query);
4151
4204
  const newIndex = path.at(-1);
4152
4205
  /**
4153
4206
  * This function 1) glosses over the need for type assertions to splice directly
@@ -4163,17 +4216,29 @@ const insert = (query, ruleOrGroup, path, { combinators = defaultCombinators, co
4163
4216
  if (combinatorPreceding) insertRuleOrGroup(normalizedNewIndex, combinatorPreceding, rorg);
4164
4217
  else insertRuleOrGroup(normalizedNewIndex, parentToInsertInto.rules[normalizedNewIndex - 2] ?? combinatorSucceeding ?? getFirstOption(combinators), rorg);
4165
4218
  }
4166
- });
4219
+ return query;
4220
+ };
4221
+ /**
4222
+ * Creates a new group at a target path with its `rules` array containing the current
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.
4225
+ *
4226
+ * @returns A new query with the rules or groups grouped.
4227
+ *
4228
+ * @group Query Tools
4229
+ */
4230
+ const group = (query, sourcePathOrID, targetPathOrID, options = {}) => produce(query, (q) => groupInPlace(q, sourcePathOrID, targetPathOrID, options));
4167
4231
  /**
4168
4232
  * Creates a new group at a target path with its `rules` array containing the current
4169
- * objects at the target path and the source path. In the options parameter, pass
4170
- * `{ clone: true }` to copy the source rule/group instead of move.
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.
4171
4235
  *
4172
- * @returns The new query with the rules or groups grouped.
4236
+ * @returns The query (mutated in place) with the rules or groups grouped.
4173
4237
  *
4174
4238
  * @group Query Tools
4175
4239
  */
4176
- const group = (query, sourcePathOrID, targetPathOrID, { clone = false, combinators = defaultCombinators, idGenerator = generateID } = {}) => {
4240
+ const groupInPlace = (query, sourcePathOrID, targetPathOrID, options = {}) => {
4241
+ const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
4177
4242
  const sourcePath = Array.isArray(sourcePathOrID) ? sourcePathOrID : getPathOfID(sourcePathOrID, query);
4178
4243
  const targetPath = Array.isArray(targetPathOrID) ? targetPathOrID : getPathOfID(targetPathOrID, query);
4179
4244
  if (!sourcePath || !targetPath) return query;
@@ -4182,32 +4247,31 @@ const group = (query, sourcePathOrID, targetPathOrID, { clone = false, combinato
4182
4247
  const sourceRuleOrGroupOriginal = findPath(sourcePath, query);
4183
4248
  const targetRuleOrGroup = findPath(targetPath, query);
4184
4249
  if (!sourceRuleOrGroupOriginal || !targetRuleOrGroup) return query;
4185
- const sourceRuleOrGroup = clone ? regenerateIDs(sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
4186
- return produce(query, (draft) => {
4187
- const independentCombinators = isRuleGroupTypeIC(draft);
4188
- const parentOfRuleToRemove = findPath(getParentPath(sourcePath), draft);
4189
- const ruleToRemoveIndex = sourcePath.at(-1);
4190
- if (!clone) {
4191
- const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4192
- const deleteLength = independentCombinators ? 2 : 1;
4193
- parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4194
- }
4195
- const newNewPath = [...nextPath];
4196
- const commonAncestorPath = getCommonAncestorPath(sourcePath, nextPath);
4197
- if (!clone && sourcePath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > sourcePath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4198
- const parentOfTargetPath = findPath(getParentPath(newNewPath), draft);
4199
- const targetPathIndex = newNewPath.at(-1);
4200
- parentOfTargetPath.rules.splice(targetPathIndex, 1, prepareRuleOrGroup(independentCombinators ? { rules: [
4201
- targetRuleOrGroup,
4202
- getFirstOption(combinators),
4203
- sourceRuleOrGroup
4204
- ] } : {
4205
- combinator: getFirstOption(combinators),
4206
- rules: [targetRuleOrGroup, sourceRuleOrGroup]
4207
- }, { idGenerator }));
4208
- });
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;
4209
4273
  };
4210
-
4211
4274
  //#endregion
4212
- 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
+
4213
4277
  //# sourceMappingURL=react-querybuilder_core.mjs.map