@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,4 @@
1
- import { a as lc, n as isRuleGroupType, r as isRuleGroupTypeIC, t as isRuleGroup } from "./isRuleGroup-DztIOOKa.mjs";
2
- import { produce } from "immer";
3
-
1
+ import { a as lc, n as isRuleGroupType, r as isRuleGroupTypeIC, t as isRuleGroup } from "./isRuleGroup-LzP0HCKh.mjs";
4
2
  //#region src/utils/convertQuery.ts
5
3
  const combinatorLevels = [
6
4
  "or",
@@ -11,20 +9,27 @@ const isSameString = (a, b) => lc(a) === b;
11
9
  const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel = 0) => {
12
10
  const baseCombinator = combinatorLevels[baseCombinatorLevel];
13
11
  if (!rg.rules.includes(baseCombinator)) return baseCombinatorLevel < combinatorLevels.length - 2 ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1) : rg;
14
- return produce(rg, (draft) => {
15
- let cursor = 0;
16
- while (cursor < draft.rules.length - 2) {
17
- if (isSameString(draft.rules[cursor + 1], baseCombinator)) {
18
- cursor += 2;
19
- continue;
20
- }
21
- const nextBaseCombinatorIndex = draft.rules.findIndex((r, i) => i > cursor && typeof r === "string" && lc(r) === baseCombinator);
22
- if (nextBaseCombinatorIndex === -1) {
23
- draft.rules.splice(cursor, draft.rules.length, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor) }, baseCombinatorLevel + 1));
24
- break;
25
- } else draft.rules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
12
+ const newRules = [...rg.rules];
13
+ let cursor = 0;
14
+ while (cursor < newRules.length - 2) {
15
+ if (isSameString(newRules[cursor + 1], baseCombinator)) {
16
+ cursor += 2;
17
+ continue;
18
+ }
19
+ let nextBaseCombinatorIndex = -1;
20
+ for (let i = cursor + 2; i < newRules.length; i++) if (typeof newRules[i] === "string" && lc(newRules[i]) === baseCombinator) {
21
+ nextBaseCombinatorIndex = i;
22
+ break;
26
23
  }
27
- });
24
+ if (nextBaseCombinatorIndex === -1) {
25
+ newRules.splice(cursor, newRules.length, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor) }, baseCombinatorLevel + 1));
26
+ break;
27
+ } else newRules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
28
+ }
29
+ return {
30
+ ...rg,
31
+ rules: newRules
32
+ };
28
33
  };
29
34
  /**
30
35
  * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.
@@ -37,9 +42,11 @@ const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel =
37
42
  const convertFromIC = (rg) => {
38
43
  if (isRuleGroupType(rg)) return rg;
39
44
  const processedRG = generateRuleGroupICWithConsistentCombinators(rg);
40
- const rulesAsMixedList = processedRG.rules.map((r) => typeof r === "string" || !isRuleGroup(r) ? r : convertFromIC(r));
41
- const combinator = rulesAsMixedList.length < 2 ? "and" : rulesAsMixedList[1];
42
- const rules = rulesAsMixedList.filter((r) => typeof r !== "string");
45
+ const rules = [];
46
+ let combinator = "and";
47
+ for (const [idx, r] of processedRG.rules.entries()) if (typeof r === "string") {
48
+ if (idx === 1) combinator = r;
49
+ } else rules.push(isRuleGroup(r) ? convertFromIC(r) : r);
43
50
  return {
44
51
  ...processedRG,
45
52
  combinator,
@@ -59,7 +66,8 @@ const convertToIC = (rg) => {
59
66
  const { combinator, ...queryWithoutCombinator } = rg;
60
67
  const rules = [];
61
68
  const { length } = rg.rules;
62
- for (const [idx, r] of rg.rules.entries()) {
69
+ for (let idx = 0; idx < length; idx++) {
70
+ const r = rg.rules[idx];
63
71
  if (isRuleGroup(r)) rules.push(convertToIC(r));
64
72
  else rules.push(r);
65
73
  if (combinator && idx < length - 1) rules.push(combinator);
@@ -69,7 +77,7 @@ const convertToIC = (rg) => {
69
77
  rules
70
78
  };
71
79
  };
72
-
73
80
  //#endregion
74
81
  export { convertToIC as n, convertFromIC as t };
75
- //# sourceMappingURL=convertQuery-DAj92cbM.mjs.map
82
+
83
+ //# sourceMappingURL=convertQuery-B5Qm_6ut.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertQuery-B5Qm_6ut.mjs","names":[],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupType = RuleGroupType>(\n rg: RuleGroupTypeAny\n): RG => {\n if (isRuleGroupType(rg)) {\n return rg as RG;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as RG;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RGIC extends RuleGroupTypeIC = RuleGroupTypeIC>(\n rg: RuleGroupTypeAny\n): RGIC => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as RGIC;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as RGIC;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAWA,MAAM,mBAAmB;CAAC;CAAM;CAAO;CAAM;AAE7C,MAAM,gBAAgB,GAAY,MAAc,GAAG,EAAE,KAAK;AAE1D,MAAM,gDACJ,IACA,sBAA8B,MACV;CACpB,MAAM,iBAAiB,iBAAiB;AAGxC,KAAI,CAAC,GAAG,MAAM,SAAS,eAAsB,CAG3C,QAAO,sBAAsB,iBAAiB,SAAS,IACnD,6CAA6C,IAAI,sBAAsB,EAAE,GACzE;CAGN,MAAM,WAAW,CAAC,GAAG,GAAG,MAAM;CAC9B,IAAI,SAAS;AAGb,QAAO,SAAS,SAAS,SAAS,GAAG;AACnC,MAAI,aAAa,SAAS,SAAS,IAAI,eAAe,EAAE;AACtD,aAAU;AACV;;EAGF,IAAI,0BAA0B;AAC9B,OAAK,IAAI,IAAI,SAAS,GAAG,IAAI,SAAS,QAAQ,IAC5C,KAAI,OAAO,SAAS,OAAO,YAAY,GAAG,SAAS,GAAG,KAAK,gBAAgB;AACzE,6BAA0B;AAC1B;;AAIJ,MAAI,4BAA4B,IAAI;AAElC,YAAS,OACP,QACA,SAAS,QACT,6CAEE,EAAE,OAAO,SAAS,MAAM,OAAO,EAAS,EACxC,sBAAsB,EACvB,CACF;AACD;QAGA,UAAS,OACP,QACA,0BAA0B,QAC1B,6CAEE,EAAE,OAAO,SAAS,MAAM,QAAQ,wBAAwB,EAAS,EACjE,sBAAsB,EACvB,CACF;;AAIL,QAAO;EAAE,GAAG;EAAI,OAAO;EAAU;;;;;;;;;;AAWnC,MAAa,iBACX,OACO;AACP,KAAI,gBAAgB,GAAG,CACrB,QAAO;CAET,MAAM,cAAc,6CAA6C,GAAG;CACpE,MAAM,QAAwB,EAAE;CAChC,IAAI,aAAa;AACjB,MAAK,MAAM,CAAC,KAAK,MAAM,YAAY,MAAM,SAAS,CAChD,KAAI,OAAO,MAAM;MACX,QAAQ,EAAG,cAAa;OAE5B,OAAM,KAAK,YAAY,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;AAGrD,QAAO;EAAE,GAAG;EAAa;EAAY;EAAO;;;;;;;;;;AAW9C,MAAa,eACX,OACS;AACT,KAAI,kBAAkB,GAAG,CACvB,QAAO;CAET,MAAM,EAAE,YAAY,GAAG,2BAA2B;CAClD,MAAM,QAAiD,EAAE;CACzD,MAAM,EAAE,WAAW,GAAG;AACtB,MAAK,IAAI,MAAM,GAAG,MAAM,QAAQ,OAAO;EACrC,MAAM,IAAI,GAAG,MAAM;AACnB,MAAI,YAAY,EAAE,CAChB,OAAM,KAAK,YAAY,EAAE,CAAC;MAE1B,OAAM,KAAK,EAAE;AAEf,MAAI,cAAc,MAAM,SAAS,EAC/B,OAAM,KAAK,WAAW;;AAG1B,QAAO;EAAE,GAAG;EAAwB;EAAO"}
@@ -0,0 +1,94 @@
1
+ const require_isRuleGroup = require("./isRuleGroup-BCwaLzDj.js");
2
+ //#region src/utils/convertQuery.ts
3
+ const combinatorLevels = [
4
+ "or",
5
+ "xor",
6
+ "and"
7
+ ];
8
+ const isSameString = (a, b) => require_isRuleGroup.lc(a) === b;
9
+ const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel = 0) => {
10
+ const baseCombinator = combinatorLevels[baseCombinatorLevel];
11
+ if (!rg.rules.includes(baseCombinator)) return baseCombinatorLevel < combinatorLevels.length - 2 ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1) : rg;
12
+ const newRules = [...rg.rules];
13
+ let cursor = 0;
14
+ while (cursor < newRules.length - 2) {
15
+ if (isSameString(newRules[cursor + 1], baseCombinator)) {
16
+ cursor += 2;
17
+ continue;
18
+ }
19
+ let nextBaseCombinatorIndex = -1;
20
+ for (let i = cursor + 2; i < newRules.length; i++) if (typeof newRules[i] === "string" && require_isRuleGroup.lc(newRules[i]) === baseCombinator) {
21
+ nextBaseCombinatorIndex = i;
22
+ break;
23
+ }
24
+ if (nextBaseCombinatorIndex === -1) {
25
+ newRules.splice(cursor, newRules.length, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor) }, baseCombinatorLevel + 1));
26
+ break;
27
+ } else newRules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
28
+ }
29
+ return {
30
+ ...rg,
31
+ rules: newRules
32
+ };
33
+ };
34
+ /**
35
+ * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.
36
+ *
37
+ * This function is idempotent: {@link RuleGroupType} queries will be
38
+ * returned as-is.
39
+ *
40
+ * @group Query Tools
41
+ */
42
+ const convertFromIC = (rg) => {
43
+ if (require_isRuleGroup.isRuleGroupType(rg)) return rg;
44
+ const processedRG = generateRuleGroupICWithConsistentCombinators(rg);
45
+ const rules = [];
46
+ let combinator = "and";
47
+ for (const [idx, r] of processedRG.rules.entries()) if (typeof r === "string") {
48
+ if (idx === 1) combinator = r;
49
+ } else rules.push(require_isRuleGroup.isRuleGroup(r) ? convertFromIC(r) : r);
50
+ return {
51
+ ...processedRG,
52
+ combinator,
53
+ rules
54
+ };
55
+ };
56
+ /**
57
+ * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.
58
+ *
59
+ * This function is idempotent: {@link RuleGroupTypeIC} queries will be
60
+ * returned as-is.
61
+ *
62
+ * @group Query Tools
63
+ */
64
+ const convertToIC = (rg) => {
65
+ if (require_isRuleGroup.isRuleGroupTypeIC(rg)) return rg;
66
+ const { combinator, ...queryWithoutCombinator } = rg;
67
+ const rules = [];
68
+ const { length } = rg.rules;
69
+ for (let idx = 0; idx < length; idx++) {
70
+ const r = rg.rules[idx];
71
+ if (require_isRuleGroup.isRuleGroup(r)) rules.push(convertToIC(r));
72
+ else rules.push(r);
73
+ if (combinator && idx < length - 1) rules.push(combinator);
74
+ }
75
+ return {
76
+ ...queryWithoutCombinator,
77
+ rules
78
+ };
79
+ };
80
+ //#endregion
81
+ Object.defineProperty(exports, "convertFromIC", {
82
+ enumerable: true,
83
+ get: function() {
84
+ return convertFromIC;
85
+ }
86
+ });
87
+ Object.defineProperty(exports, "convertToIC", {
88
+ enumerable: true,
89
+ get: function() {
90
+ return convertToIC;
91
+ }
92
+ });
93
+
94
+ //# sourceMappingURL=convertQuery-DfZehtnd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertQuery-DfZehtnd.js","names":["lc","isRuleGroupType","isRuleGroup","isRuleGroupTypeIC"],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupType = RuleGroupType>(\n rg: RuleGroupTypeAny\n): RG => {\n if (isRuleGroupType(rg)) {\n return rg as RG;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as RG;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RGIC extends RuleGroupTypeIC = RuleGroupTypeIC>(\n rg: RuleGroupTypeAny\n): RGIC => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as RGIC;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as RGIC;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAWA,MAAM,mBAAmB;CAAC;CAAM;CAAO;CAAM;AAE7C,MAAM,gBAAgB,GAAY,MAAcA,oBAAAA,GAAG,EAAE,KAAK;AAE1D,MAAM,gDACJ,IACA,sBAA8B,MACV;CACpB,MAAM,iBAAiB,iBAAiB;AAGxC,KAAI,CAAC,GAAG,MAAM,SAAS,eAAsB,CAG3C,QAAO,sBAAsB,iBAAiB,SAAS,IACnD,6CAA6C,IAAI,sBAAsB,EAAE,GACzE;CAGN,MAAM,WAAW,CAAC,GAAG,GAAG,MAAM;CAC9B,IAAI,SAAS;AAGb,QAAO,SAAS,SAAS,SAAS,GAAG;AACnC,MAAI,aAAa,SAAS,SAAS,IAAI,eAAe,EAAE;AACtD,aAAU;AACV;;EAGF,IAAI,0BAA0B;AAC9B,OAAK,IAAI,IAAI,SAAS,GAAG,IAAI,SAAS,QAAQ,IAC5C,KAAI,OAAO,SAAS,OAAO,YAAYA,oBAAAA,GAAG,SAAS,GAAG,KAAK,gBAAgB;AACzE,6BAA0B;AAC1B;;AAIJ,MAAI,4BAA4B,IAAI;AAElC,YAAS,OACP,QACA,SAAS,QACT,6CAEE,EAAE,OAAO,SAAS,MAAM,OAAO,EAAS,EACxC,sBAAsB,EACvB,CACF;AACD;QAGA,UAAS,OACP,QACA,0BAA0B,QAC1B,6CAEE,EAAE,OAAO,SAAS,MAAM,QAAQ,wBAAwB,EAAS,EACjE,sBAAsB,EACvB,CACF;;AAIL,QAAO;EAAE,GAAG;EAAI,OAAO;EAAU;;;;;;;;;;AAWnC,MAAa,iBACX,OACO;AACP,KAAIC,oBAAAA,gBAAgB,GAAG,CACrB,QAAO;CAET,MAAM,cAAc,6CAA6C,GAAG;CACpE,MAAM,QAAwB,EAAE;CAChC,IAAI,aAAa;AACjB,MAAK,MAAM,CAAC,KAAK,MAAM,YAAY,MAAM,SAAS,CAChD,KAAI,OAAO,MAAM;MACX,QAAQ,EAAG,cAAa;OAE5B,OAAM,KAAKC,oBAAAA,YAAY,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;AAGrD,QAAO;EAAE,GAAG;EAAa;EAAY;EAAO;;;;;;;;;;AAW9C,MAAa,eACX,OACS;AACT,KAAIC,oBAAAA,kBAAkB,GAAG,CACvB,QAAO;CAET,MAAM,EAAE,YAAY,GAAG,2BAA2B;CAClD,MAAM,QAAiD,EAAE;CACzD,MAAM,EAAE,WAAW,GAAG;AACtB,MAAK,IAAI,MAAM,GAAG,MAAM,QAAQ,OAAO;EACrC,MAAM,IAAI,GAAG,MAAM;AACnB,MAAID,oBAAAA,YAAY,EAAE,CAChB,OAAM,KAAK,YAAY,EAAE,CAAC;MAE1B,OAAM,KAAK,EAAE;AAEf,MAAI,cAAc,MAAM,SAAS,EAC/B,OAAM,KAAK,WAAW;;AAG1B,QAAO;EAAE,GAAG;EAAwB;EAAO"}
@@ -1,8 +1,7 @@
1
- import { C as Except, a as ValueSource, b as FullOptionList, c as RuleValidator, f as RuleGroupTypeAny, h as DefaultOperatorName, i as ParseNumbersPropConfig, l as ValidationMap, n as FullOperator, r as InputType, s as QueryValidator, t as FullField, u as ValidationResult, v as RuleType, y as FlexibleOptionList } from "./basic-Cw014pDc.mjs";
1
+ import { C as Except, a as ValueSource, b as FullOptionList, c as RuleValidator, f as RuleGroupTypeAny, h as DefaultOperatorName, i as ParseNumbersPropConfig, l as ValidationMap, n as FullOperator, r as InputType, s as QueryValidator, t as FullField, u as ValidationResult, v as RuleType, y as FlexibleOptionList } from "./basic-CNIjb6rI.mjs";
2
2
  import { RulesLogic } from "json-logic-js";
3
3
 
4
4
  //#region src/types/export.d.ts
5
-
6
5
  /**
7
6
  * Available export formats for {@link formatQuery}.
8
7
  *
@@ -449,4 +448,4 @@ type NLTranslationKey = "and" | "or" | "true" | "false" | `groupPrefix${ZeroOrMo
449
448
  type NLTranslations = Partial<Record<NLTranslationKey, string>>;
450
449
  //#endregion
451
450
  export { ValueProcessorOptions as _, FormatQueryOptions as a, NLTranslations as c, RQBJsonLogic as d, RuleGroupProcessor as f, ValueProcessorLegacy as g, ValueProcessorByRule as h, ExportOperatorMap as i, ParameterizedNamedSQL as l, SQLPreset as m, ExportFormat as n, GroupVariantCondition as o, RuleProcessor as p, ExportObjectFormats as r, NLTranslationKey as s, ConstituentWordOrder as t, ParameterizedSQL as u };
452
- //# sourceMappingURL=export-CffjLxEe.d.mts.map
451
+ //# sourceMappingURL=export-6x7MilFR.d.mts.map
@@ -1,8 +1,7 @@
1
- import { C as Except, a as ValueSource, b as FullOptionList, c as RuleValidator, f as RuleGroupTypeAny, h as DefaultOperatorName, i as ParseNumbersPropConfig, l as ValidationMap, n as FullOperator, r as InputType, s as QueryValidator, t as FullField, u as ValidationResult, v as RuleType, y as FlexibleOptionList } from "./basic-_KlsCAyT.js";
1
+ import { C as Except, a as ValueSource, b as FullOptionList, c as RuleValidator, f as RuleGroupTypeAny, h as DefaultOperatorName, i as ParseNumbersPropConfig, l as ValidationMap, n as FullOperator, r as InputType, s as QueryValidator, t as FullField, u as ValidationResult, v as RuleType, y as FlexibleOptionList } from "./basic-BXJVfD0P.js";
2
2
  import { RulesLogic } from "json-logic-js";
3
3
 
4
4
  //#region src/types/export.d.ts
5
-
6
5
  /**
7
6
  * Available export formats for {@link formatQuery}.
8
7
  *
@@ -449,4 +448,4 @@ type NLTranslationKey = "and" | "or" | "true" | "false" | `groupPrefix${ZeroOrMo
449
448
  type NLTranslations = Partial<Record<NLTranslationKey, string>>;
450
449
  //#endregion
451
450
  export { ValueProcessorOptions as _, FormatQueryOptions as a, NLTranslations as c, RQBJsonLogic as d, RuleGroupProcessor as f, ValueProcessorLegacy as g, ValueProcessorByRule as h, ExportOperatorMap as i, ParameterizedNamedSQL as l, SQLPreset as m, ExportFormat as n, GroupVariantCondition as o, RuleProcessor as p, ExportObjectFormats as r, NLTranslationKey as s, ConstituentWordOrder as t, ParameterizedSQL as u };
452
- //# sourceMappingURL=export-DRA8O1Wz.d.ts.map
451
+ //# sourceMappingURL=export-CpJOQuZv.d.ts.map
@@ -1,5 +1,5 @@
1
- import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-Cw014pDc.mjs";
2
- import { _ as ValueProcessorOptions, a as FormatQueryOptions, c as NLTranslations, d as RQBJsonLogic, f as RuleGroupProcessor, g as ValueProcessorLegacy, h as ValueProcessorByRule, i as ExportOperatorMap, l as ParameterizedNamedSQL, m as SQLPreset, n as ExportFormat, o as GroupVariantCondition, p as RuleProcessor, r as ExportObjectFormats, s as NLTranslationKey, t as ConstituentWordOrder, u as ParameterizedSQL } from "./export-CffjLxEe.mjs";
1
+ import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-CNIjb6rI.mjs";
2
+ import { _ as ValueProcessorOptions, a as FormatQueryOptions, c as NLTranslations, d as RQBJsonLogic, f as RuleGroupProcessor, g as ValueProcessorLegacy, h as ValueProcessorByRule, i as ExportOperatorMap, l as ParameterizedNamedSQL, m as SQLPreset, n as ExportFormat, o as GroupVariantCondition, p as RuleProcessor, r as ExportObjectFormats, s as NLTranslationKey, t as ConstituentWordOrder, u as ParameterizedSQL } from "./export-6x7MilFR.mjs";
3
3
  import { Column, Operators, SQL, Table } from "drizzle-orm";
4
4
  import { WhereOptions } from "sequelize";
5
5
 
@@ -506,7 +506,8 @@ declare const celCombinatorMap: {
506
506
  */
507
507
  declare const jsonLogicAdditionalOperators: Record<"startsWith" | "endsWith", (a: string, b: string) => boolean>;
508
508
  /**
509
- * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
509
+ * Returns a new query object with all `string`-type `value` properties converted
510
+ * to `number` where appropriate.
510
511
  *
511
512
  * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
512
513
  *
@@ -1,5 +1,5 @@
1
- import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-_KlsCAyT.js";
2
- import { _ as ValueProcessorOptions, a as FormatQueryOptions, c as NLTranslations, d as RQBJsonLogic, f as RuleGroupProcessor, g as ValueProcessorLegacy, h as ValueProcessorByRule, i as ExportOperatorMap, l as ParameterizedNamedSQL, m as SQLPreset, n as ExportFormat, o as GroupVariantCondition, p as RuleProcessor, r as ExportObjectFormats, s as NLTranslationKey, t as ConstituentWordOrder, u as ParameterizedSQL } from "./export-DRA8O1Wz.js";
1
+ import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-BXJVfD0P.js";
2
+ import { _ as ValueProcessorOptions, a as FormatQueryOptions, c as NLTranslations, d as RQBJsonLogic, f as RuleGroupProcessor, g as ValueProcessorLegacy, h as ValueProcessorByRule, i as ExportOperatorMap, l as ParameterizedNamedSQL, m as SQLPreset, n as ExportFormat, o as GroupVariantCondition, p as RuleProcessor, r as ExportObjectFormats, s as NLTranslationKey, t as ConstituentWordOrder, u as ParameterizedSQL } from "./export-CpJOQuZv.js";
3
3
  import { Column, Operators, SQL, Table } from "drizzle-orm";
4
4
  import { WhereOptions } from "sequelize";
5
5
 
@@ -506,7 +506,8 @@ declare const celCombinatorMap: {
506
506
  */
507
507
  declare const jsonLogicAdditionalOperators: Record<"startsWith" | "endsWith", (a: string, b: string) => boolean>;
508
508
  /**
509
- * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
509
+ * Returns a new query object with all `string`-type `value` properties converted
510
+ * to `number` where appropriate.
510
511
  *
511
512
  * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
512
513
  *
@@ -1,10 +1,8 @@
1
- const require_chunk = require('./chunk-U64pC571.js');
2
- const require_utils = require('./utils-CR1ToTMW.js');
3
- const require_isRuleGroup = require('./isRuleGroup-Cjk1Q2mj.js');
4
- const require_transformQuery = require('./transformQuery-ClBRfnFg.js');
5
- const require_convertQuery = require('./convertQuery-DRldbzhZ.js');
6
- let immer = require("immer");
7
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils = require("./utils-EsYRkPtf.js");
3
+ const require_isRuleGroup = require("./isRuleGroup-BCwaLzDj.js");
4
+ const require_transformQuery = require("./transformQuery.js");
5
+ const require_convertQuery = require("./convertQuery-DfZehtnd.js");
8
6
  //#region src/utils/isRuleOrGroupValid.ts
9
7
  /**
10
8
  * Determines if an object is useful as a validation result.
@@ -27,7 +25,6 @@ const isRuleOrGroupValid = (rg, validationResult, validator) => {
27
25
  }
28
26
  return true;
29
27
  };
30
-
31
28
  //#endregion
32
29
  //#region src/utils/formatQuery/defaultRuleGroupProcessorCEL.ts
33
30
  /**
@@ -83,7 +80,6 @@ const defaultRuleGroupProcessorCEL = (ruleGroup, options) => {
83
80
  };
84
81
  return processRuleGroup(ruleGroup, true);
85
82
  };
86
-
87
83
  //#endregion
88
84
  //#region src/utils/formatQuery/defaultRuleProcessorCEL.ts
89
85
  const shouldNegate$2 = (op) => op.startsWith("not") || op.startsWith("doesnot");
@@ -164,7 +160,6 @@ const defaultRuleProcessorCEL = (rule, opts = {}) => {
164
160
  }
165
161
  return "";
166
162
  };
167
-
168
163
  //#endregion
169
164
  //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDBQuery.ts
170
165
  /**
@@ -202,11 +197,11 @@ const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
202
197
  fieldData
203
198
  }, meta);
204
199
  }).filter(Boolean);
205
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
200
+ const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
201
+ return rg.not ? { $not: result } : result;
206
202
  };
207
203
  return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
208
204
  };
209
-
210
205
  //#endregion
211
206
  //#region src/utils/formatQuery/defaultRuleProcessorMongoDBQuery.ts
212
207
  const processNumber$1 = (value, fallback, parseNumbers = false) => require_utils.shouldRenderAsNumber(value, parseNumbers || typeof value === "bigint") ? Number(require_utils.parseNumber(value, { parseNumbers: "strict" })) : fallback;
@@ -335,7 +330,6 @@ const defaultRuleProcessorMongoDBQuery = (rule, options = {}) => {
335
330
  }
336
331
  return "";
337
332
  };
338
-
339
333
  //#endregion
340
334
  //#region src/utils/formatQuery/defaultRuleProcessorMongoDB.ts
341
335
  /**
@@ -349,7 +343,6 @@ const defaultRuleProcessorMongoDB = (rule, options) => {
349
343
  const queryObj = defaultRuleProcessorMongoDBQuery(rule, options);
350
344
  return queryObj ? JSON.stringify(queryObj) : "";
351
345
  };
352
-
353
346
  //#endregion
354
347
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSpEL.ts
355
348
  /**
@@ -405,11 +398,10 @@ const defaultRuleGroupProcessorSpEL = (ruleGroup, options) => {
405
398
  };
406
399
  return processRuleGroup(ruleGroup, true);
407
400
  };
408
-
409
401
  //#endregion
410
402
  //#region src/utils/formatQuery/defaultRuleProcessorSpEL.ts
411
403
  const shouldNegate$1 = (op) => op.startsWith("not") || op.startsWith("doesnot");
412
- const wrapInNegation = (clause, negate$1) => negate$1 ? `!(${clause})` : clause;
404
+ const wrapInNegation = (clause, negate) => negate ? `!(${clause})` : clause;
413
405
  const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
414
406
  /**
415
407
  * Default rule processor used by {@link formatQuery} for "spel" format.
@@ -462,9 +454,9 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
462
454
  case "notnull": return `${field} != null`;
463
455
  case "in":
464
456
  case "notin": {
465
- const negate$1 = shouldNegate$1(operatorTL) ? "!" : "";
457
+ const negate = shouldNegate$1(operatorTL) ? "!" : "";
466
458
  const valueAsArray = require_utils.toArray(value);
467
- return valueAsArray.length > 0 ? `${negate$1}(${valueAsArray.map((val) => `${field} == ${valueIsField || require_utils.shouldRenderAsNumber(val, parseNumbers) ? `${require_utils.trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
459
+ return valueAsArray.length > 0 ? `${negate}(${valueAsArray.map((val) => `${field} == ${valueIsField || require_utils.shouldRenderAsNumber(val, parseNumbers) ? `${require_utils.trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
468
460
  }
469
461
  case "between":
470
462
  case "notbetween": {
@@ -487,7 +479,6 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
487
479
  }
488
480
  return "";
489
481
  };
490
-
491
482
  //#endregion
492
483
  //#region src/utils/formatQuery/defaultValueProcessorByRule.ts
493
484
  const escapeStringValueQuotes$1 = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
@@ -543,7 +534,6 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
543
534
  if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
544
535
  return valueIsField ? wrapFieldName(value) : require_utils.shouldRenderAsNumber(value, parseNumbers) ? `${require_utils.trimIfString(value)}` : `${wrapAndEscape(value)}`;
545
536
  };
546
-
547
537
  //#endregion
548
538
  //#region src/utils/formatQuery/defaultRuleProcessorDrizzle.ts
549
539
  /**
@@ -640,7 +630,6 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
640
630
  default: return;
641
631
  }
642
632
  };
643
-
644
633
  //#endregion
645
634
  //#region src/utils/formatQuery/defaultRuleGroupProcessorDrizzle.ts
646
635
  /**
@@ -684,7 +673,6 @@ const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns
684
673
  };
685
674
  return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
686
675
  };
687
-
688
676
  //#endregion
689
677
  //#region src/utils/formatQuery/defaultRuleGroupProcessorElasticSearch.ts
690
678
  /**
@@ -713,7 +701,6 @@ const defaultRuleGroupProcessorElasticSearch = (ruleGroup, options) => {
713
701
  const processedRuleGroup = processRuleGroup(require_convertQuery.convertFromIC(ruleGroup));
714
702
  return processedRuleGroup === false ? {} : processedRuleGroup;
715
703
  };
716
-
717
704
  //#endregion
718
705
  //#region src/utils/formatQuery/defaultRuleGroupProcessorJSONata.ts
719
706
  /**
@@ -769,7 +756,6 @@ const defaultRuleGroupProcessorJSONata = (ruleGroup, options) => {
769
756
  };
770
757
  return processRuleGroup(ruleGroup, true);
771
758
  };
772
-
773
759
  //#endregion
774
760
  //#region src/utils/formatQuery/defaultRuleGroupProcessorJsonLogic.ts
775
761
  /**
@@ -799,7 +785,6 @@ const defaultRuleGroupProcessorJsonLogic = (ruleGroup, options) => {
799
785
  };
800
786
  return processRuleGroup(query, true);
801
787
  };
802
-
803
788
  //#endregion
804
789
  //#region src/utils/formatQuery/defaultRuleGroupProcessorLDAP.ts
805
790
  /**
@@ -830,7 +815,6 @@ const defaultRuleGroupProcessorLDAP = (ruleGroup, options) => {
830
815
  };
831
816
  return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
832
817
  };
833
-
834
818
  //#endregion
835
819
  //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDB.ts
836
820
  const isBracketed = (str) => str.startsWith("{") && str.endsWith("}");
@@ -865,12 +849,12 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
865
849
  fieldData
866
850
  }, meta);
867
851
  }).filter(Boolean);
868
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
852
+ const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
853
+ return rg.not ? `"$not":${isBracketed(result) ? result : `{${result}}`}` : result;
869
854
  };
870
855
  const processedQuery = processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
871
856
  return isBracketed(processedQuery) ? processedQuery : `{${processedQuery}}`;
872
857
  };
873
-
874
858
  //#endregion
875
859
  //#region src/utils/formatQuery/defaultRuleGroupProcessorNL.ts
876
860
  /**
@@ -934,7 +918,6 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
934
918
  };
935
919
  return processRuleGroup(ruleGroup, true);
936
920
  };
937
-
938
921
  //#endregion
939
922
  //#region src/utils/formatQuery/defaultRuleGroupProcessorParameterized.ts
940
923
  /**
@@ -1023,7 +1006,6 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
1023
1006
  params: paramsNamed
1024
1007
  };
1025
1008
  };
1026
-
1027
1009
  //#endregion
1028
1010
  //#region src/utils/formatQuery/defaultRuleGroupProcessorPrisma.ts
1029
1011
  /**
@@ -1066,7 +1048,6 @@ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
1066
1048
  const result = processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
1067
1049
  return ruleGroup.not ? { NOT: result } : result;
1068
1050
  };
1069
-
1070
1051
  //#endregion
1071
1052
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSequelize.ts
1072
1053
  /**
@@ -1107,7 +1088,6 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
1107
1088
  };
1108
1089
  return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
1109
1090
  };
1110
-
1111
1091
  //#endregion
1112
1092
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSQL.ts
1113
1093
  /**
@@ -1164,7 +1144,6 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
1164
1144
  };
1165
1145
  return processRuleGroup(ruleGroup, true);
1166
1146
  };
1167
-
1168
1147
  //#endregion
1169
1148
  //#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
1170
1149
  const rangeOperatorMap = {
@@ -1196,7 +1175,30 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
1196
1175
  const { field, operator, value, valueSource } = rule;
1197
1176
  const { parseNumbers, preserveValueOrder } = options;
1198
1177
  const operatorLC = require_isRuleGroup.lc(operator);
1199
- if (require_utils.processMatchMode(rule)) return false;
1178
+ const matchEval = require_utils.processMatchMode(rule);
1179
+ if (matchEval === false) return false;
1180
+ else if (matchEval) {
1181
+ const { mode } = matchEval;
1182
+ const subQuery = defaultRuleGroupProcessorElasticSearch(require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
1183
+ ...r,
1184
+ field: r.field ? `${field}.${r.field}` : field
1185
+ }) }), options);
1186
+ if (Object.keys(subQuery).length === 0) return false;
1187
+ switch (mode) {
1188
+ case "some": return { nested: {
1189
+ path: field,
1190
+ query: subQuery
1191
+ } };
1192
+ case "none": return { bool: { must_not: { nested: {
1193
+ path: field,
1194
+ query: subQuery
1195
+ } } } };
1196
+ case "all":
1197
+ case "atleast":
1198
+ case "atmost":
1199
+ case "exactly": return false;
1200
+ }
1201
+ }
1200
1202
  if (valueSource === "field") {
1201
1203
  if (require_utils.toArray(value).some((v) => typeof v !== "string")) return false;
1202
1204
  const fieldForScript = escapeSQ(field);
@@ -1293,12 +1295,11 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
1293
1295
  }
1294
1296
  return false;
1295
1297
  };
1296
-
1297
1298
  //#endregion
1298
1299
  //#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
1299
1300
  const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
1300
1301
  const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
1301
- const negate = (clause, negate$1) => negate$1 ? `$not(${clause})` : clause;
1302
+ const negate = (clause, neg) => neg ? `$not(${clause})` : clause;
1302
1303
  const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
1303
1304
  /**
1304
1305
  * Default rule processor used by {@link formatQuery} for "jsonata" format.
@@ -1380,7 +1381,6 @@ const defaultRuleProcessorJSONata = (rule, options = {}) => {
1380
1381
  }
1381
1382
  return "";
1382
1383
  };
1383
-
1384
1384
  //#endregion
1385
1385
  //#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
1386
1386
  const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
@@ -1475,10 +1475,9 @@ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
1475
1475
  }
1476
1476
  return false;
1477
1477
  };
1478
-
1479
1478
  //#endregion
1480
1479
  //#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
1481
- const negateIf = (clause, negate$1) => negate$1 ? `(!${clause})` : `${clause}`;
1480
+ const negateIf = (clause, negate) => negate ? `(!${clause})` : `${clause}`;
1482
1481
  const ldapEscape = (s) => `${require_utils.trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
1483
1482
  /**
1484
1483
  * Default rule processor used by {@link formatQuery} for "ldap" format.
@@ -1527,7 +1526,6 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
1527
1526
  // istanbul ignore next
1528
1527
  return "";
1529
1528
  };
1530
-
1531
1529
  //#endregion
1532
1530
  //#region src/utils/formatQuery/defaultValueProcessorNL.ts
1533
1531
  const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
@@ -1577,7 +1575,6 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
1577
1575
  if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
1578
1576
  return valueIsField ? wrapFieldName(require_utils.getOption(fields ?? [], rule.value)?.label ?? rule.value) : require_utils.shouldRenderAsNumber(rule.value, parseNumbers) ? `${require_utils.trimIfString(rule.value)}` : `${wrapAndEscape(rule.value)}`;
1579
1577
  };
1580
-
1581
1578
  //#endregion
1582
1579
  //#region src/utils/formatQuery/defaultRuleProcessorNL.ts
1583
1580
  /**
@@ -1687,7 +1684,6 @@ const defaultRuleProcessorNL = (rule, opts) => {
1687
1684
  };
1688
1685
  return require_utils.normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
1689
1686
  };
1690
-
1691
1687
  //#endregion
1692
1688
  //#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
1693
1689
  /**
@@ -1742,7 +1738,6 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
1742
1738
  if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
1743
1739
  return `${ruleField} ${operator} ${value}`.trim();
1744
1740
  };
1745
-
1746
1741
  //#endregion
1747
1742
  //#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
1748
1743
  /**
@@ -1847,7 +1842,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
1847
1842
  }
1848
1843
  return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
1849
1844
  };
1850
-
1851
1845
  //#endregion
1852
1846
  //#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
1853
1847
  const processNumber = (value, fallback, parseNumbers) => require_utils.shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(require_utils.parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
@@ -1909,7 +1903,6 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
1909
1903
  }
1910
1904
  return "";
1911
1905
  };
1912
-
1913
1906
  //#endregion
1914
1907
  //#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
1915
1908
  /**
@@ -1976,7 +1969,6 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
1976
1969
  }
1977
1970
  }
1978
1971
  };
1979
-
1980
1972
  //#endregion
1981
1973
  //#region src/utils/formatQuery/formatQuery.ts
1982
1974
  /**
@@ -2065,8 +2057,8 @@ const defaultFormatQueryOptions = {
2065
2057
  paramsKeepPrefix: false,
2066
2058
  numberedParams: false,
2067
2059
  preserveValueOrder: false,
2068
- placeholderFieldName: require_utils.defaultPlaceholderFieldName,
2069
- placeholderOperatorName: require_utils.defaultPlaceholderOperatorName,
2060
+ placeholderFieldName: "~",
2061
+ placeholderOperatorName: "~",
2070
2062
  quoteValuesWith: "'",
2071
2063
  concatOperator: "||",
2072
2064
  preset: "ansi",
@@ -2171,7 +2163,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
2171
2163
  switch (format) {
2172
2164
  case "json":
2173
2165
  case "json_without_ids": {
2174
- const rg = parseNumbers ? (0, immer.produce)(ruleGroup, (g) => require_utils.numerifyValues(g, finalOptions)) : ruleGroup;
2166
+ const rg = parseNumbers ? require_utils.numerifyValues(ruleGroup, finalOptions) : ruleGroup;
2175
2167
  if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : require_utils.bigIntJsonStringifyReplacer(key, value));
2176
2168
  return JSON.stringify(rg, require_utils.bigIntJsonStringifyReplacer, 2);
2177
2169
  }
@@ -2193,7 +2185,6 @@ function formatQuery(ruleGroup, optionParam = {}) {
2193
2185
  default: return "";
2194
2186
  }
2195
2187
  }
2196
-
2197
2188
  //#endregion
2198
2189
  //#region src/utils/formatQuery/index.ts
2199
2190
  const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
@@ -2244,7 +2235,6 @@ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
2244
2235
  * @group Export
2245
2236
  */
2246
2237
  const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
2247
-
2248
2238
  //#endregion
2249
2239
  exports.bigIntJsonParseReviver = require_utils.bigIntJsonParseReviver;
2250
2240
  exports.bigIntJsonStringifyReplacer = require_utils.bigIntJsonStringifyReplacer;
@@ -2308,4 +2298,5 @@ exports.prismaOperators = require_utils.prismaOperators;
2308
2298
  exports.processMatchMode = require_utils.processMatchMode;
2309
2299
  exports.shouldRenderAsNumber = require_utils.shouldRenderAsNumber;
2310
2300
  exports.sqlDialectPresets = sqlDialectPresets;
2301
+
2311
2302
  //# sourceMappingURL=formatQuery.js.map