@react-querybuilder/core 8.14.0 → 8.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{basic-Dxm6jWFu.d.ts → basic-BXJVfD0P.d.ts} +68 -50
- package/dist/{basic-GFsWfi0Z.d.mts → basic-CNIjb6rI.d.mts} +68 -50
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +178 -127
- package/dist/cjs/react-querybuilder_core.cjs.development.js +299 -251
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +178 -127
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-DAj92cbM.mjs → convertQuery-B5Qm_6ut.mjs} +30 -22
- package/dist/convertQuery-B5Qm_6ut.mjs.map +1 -0
- package/dist/convertQuery-DfZehtnd.js +94 -0
- package/dist/convertQuery-DfZehtnd.js.map +1 -0
- package/dist/{export-_wipiqJZ.d.mts → export-6x7MilFR.d.mts} +2 -3
- package/dist/{export-6VbkhCrf.d.ts → export-CpJOQuZv.d.ts} +2 -3
- package/dist/formatQuery.d.mts +4 -3
- package/dist/formatQuery.d.ts +4 -3
- package/dist/formatQuery.js +18 -50
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +17 -49
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-D8M7awTx.d.ts → import-B5Iq8XmL.d.ts} +2 -3
- package/dist/{import-DRmutNSr.d.mts → import-Bltb2mT4.d.mts} +2 -3
- package/dist/{isRuleGroup-Cjk1Q2mj.js → isRuleGroup-BCwaLzDj.js} +38 -40
- package/dist/isRuleGroup-BCwaLzDj.js.map +1 -0
- package/dist/{isRuleGroup-DztIOOKa.mjs → isRuleGroup-LzP0HCKh.mjs} +2 -4
- package/dist/isRuleGroup-LzP0HCKh.mjs.map +1 -0
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +9 -11
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +7 -10
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +2 -3
- package/dist/parseJSONata.d.ts +2 -3
- package/dist/parseJSONata.js +37 -5611
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +11 -13
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +3 -4
- package/dist/parseJsonLogic.d.ts +3 -4
- package/dist/parseJsonLogic.js +20 -21
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +19 -21
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +2 -3
- package/dist/parseMongoDB.d.ts +2 -3
- package/dist/parseMongoDB.js +7 -8
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +6 -8
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSQL.d.mts +2 -3
- package/dist/parseSQL.d.ts +2 -3
- package/dist/parseSQL.js +9 -11
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +7 -10
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +2 -3
- package/dist/parseSpEL.d.ts +2 -3
- package/dist/parseSpEL.js +11 -2700
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +7 -9
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BxWvIPI4.js → prepareQueryObjects-Dc8rqsYM.js} +49 -34
- package/dist/prepareQueryObjects-Dc8rqsYM.js.map +1 -0
- package/dist/{prepareQueryObjects-BBayjIn2.mjs → prepareQueryObjects-tMukQHT9.mjs} +34 -18
- package/dist/prepareQueryObjects-tMukQHT9.mjs.map +1 -0
- package/dist/react-querybuilder_core.d.mts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.d.ts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.js +296 -279
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +288 -247
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +178 -127
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/transformQuery.d.mts +1 -2
- package/dist/transformQuery.d.ts +1 -2
- package/dist/transformQuery.js +44 -2
- package/dist/transformQuery.js.map +1 -0
- package/dist/transformQuery.mjs +43 -2
- package/dist/transformQuery.mjs.map +1 -0
- package/dist/{utils-nQU7WCM9.mjs → utils-DQoYnxpa.mjs} +32 -84
- package/dist/utils-DQoYnxpa.mjs.map +1 -0
- package/dist/{utils-CR1ToTMW.js → utils-EsYRkPtf.js} +182 -246
- package/dist/utils-EsYRkPtf.js.map +1 -0
- package/package.json +25 -17
- package/dist/chunk-U64pC571.js +0 -41
- package/dist/convertQuery-DAj92cbM.mjs.map +0 -1
- package/dist/convertQuery-DRldbzhZ.js +0 -87
- package/dist/convertQuery-DRldbzhZ.js.map +0 -1
- package/dist/isRuleGroup-Cjk1Q2mj.js.map +0 -1
- package/dist/isRuleGroup-DztIOOKa.mjs.map +0 -1
- package/dist/prepareQueryObjects-BBayjIn2.mjs.map +0 -1
- package/dist/prepareQueryObjects-BxWvIPI4.js.map +0 -1
- package/dist/transformQuery-ClBRfnFg.js +0 -54
- package/dist/transformQuery-ClBRfnFg.js.map +0 -1
- package/dist/transformQuery-DUpbpqjX.mjs +0 -48
- package/dist/transformQuery-DUpbpqjX.mjs.map +0 -1
- package/dist/utils-CR1ToTMW.js.map +0 -1
- package/dist/utils-nQU7WCM9.mjs.map +0 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { a as lc, n as isRuleGroupType, r as isRuleGroupTypeIC, t as isRuleGroup } from "./isRuleGroup-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
41
|
-
|
|
42
|
-
const
|
|
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 (
|
|
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
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
451
|
+
//# sourceMappingURL=export-CpJOQuZv.d.ts.map
|
package/dist/formatQuery.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-
|
|
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-
|
|
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
|
-
*
|
|
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
|
*
|
package/dist/formatQuery.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SetRequired, f as RuleGroupTypeAny, v as RuleType } from "./basic-
|
|
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-
|
|
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
|
-
*
|
|
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
|
*
|
package/dist/formatQuery.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const require_utils = require(
|
|
3
|
-
const require_isRuleGroup = require(
|
|
4
|
-
const require_transformQuery = require(
|
|
5
|
-
const require_convertQuery = require(
|
|
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
|
-
|
|
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
|
|
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
|
|
457
|
+
const negate = shouldNegate$1(operatorTL) ? "!" : "";
|
|
466
458
|
const valueAsArray = require_utils.toArray(value);
|
|
467
|
-
return valueAsArray.length > 0 ? `${negate
|
|
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
|
-
|
|
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 = {
|
|
@@ -1316,12 +1295,11 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
|
|
|
1316
1295
|
}
|
|
1317
1296
|
return false;
|
|
1318
1297
|
};
|
|
1319
|
-
|
|
1320
1298
|
//#endregion
|
|
1321
1299
|
//#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
|
|
1322
1300
|
const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
1323
1301
|
const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
|
|
1324
|
-
const negate = (clause,
|
|
1302
|
+
const negate = (clause, neg) => neg ? `$not(${clause})` : clause;
|
|
1325
1303
|
const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
|
|
1326
1304
|
/**
|
|
1327
1305
|
* Default rule processor used by {@link formatQuery} for "jsonata" format.
|
|
@@ -1403,7 +1381,6 @@ const defaultRuleProcessorJSONata = (rule, options = {}) => {
|
|
|
1403
1381
|
}
|
|
1404
1382
|
return "";
|
|
1405
1383
|
};
|
|
1406
|
-
|
|
1407
1384
|
//#endregion
|
|
1408
1385
|
//#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
|
|
1409
1386
|
const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
|
|
@@ -1498,10 +1475,9 @@ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
|
|
|
1498
1475
|
}
|
|
1499
1476
|
return false;
|
|
1500
1477
|
};
|
|
1501
|
-
|
|
1502
1478
|
//#endregion
|
|
1503
1479
|
//#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
|
|
1504
|
-
const negateIf = (clause, negate
|
|
1480
|
+
const negateIf = (clause, negate) => negate ? `(!${clause})` : `${clause}`;
|
|
1505
1481
|
const ldapEscape = (s) => `${require_utils.trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
|
|
1506
1482
|
/**
|
|
1507
1483
|
* Default rule processor used by {@link formatQuery} for "ldap" format.
|
|
@@ -1550,7 +1526,6 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
|
|
|
1550
1526
|
// istanbul ignore next
|
|
1551
1527
|
return "";
|
|
1552
1528
|
};
|
|
1553
|
-
|
|
1554
1529
|
//#endregion
|
|
1555
1530
|
//#region src/utils/formatQuery/defaultValueProcessorNL.ts
|
|
1556
1531
|
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
|
|
@@ -1600,7 +1575,6 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
1600
1575
|
if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
|
|
1601
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)}`;
|
|
1602
1577
|
};
|
|
1603
|
-
|
|
1604
1578
|
//#endregion
|
|
1605
1579
|
//#region src/utils/formatQuery/defaultRuleProcessorNL.ts
|
|
1606
1580
|
/**
|
|
@@ -1710,7 +1684,6 @@ const defaultRuleProcessorNL = (rule, opts) => {
|
|
|
1710
1684
|
};
|
|
1711
1685
|
return require_utils.normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
|
|
1712
1686
|
};
|
|
1713
|
-
|
|
1714
1687
|
//#endregion
|
|
1715
1688
|
//#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
|
|
1716
1689
|
/**
|
|
@@ -1765,7 +1738,6 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
|
|
|
1765
1738
|
if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
|
|
1766
1739
|
return `${ruleField} ${operator} ${value}`.trim();
|
|
1767
1740
|
};
|
|
1768
|
-
|
|
1769
1741
|
//#endregion
|
|
1770
1742
|
//#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
|
|
1771
1743
|
/**
|
|
@@ -1870,7 +1842,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
1870
1842
|
}
|
|
1871
1843
|
return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
|
|
1872
1844
|
};
|
|
1873
|
-
|
|
1874
1845
|
//#endregion
|
|
1875
1846
|
//#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
|
|
1876
1847
|
const processNumber = (value, fallback, parseNumbers) => require_utils.shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(require_utils.parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
|
|
@@ -1932,7 +1903,6 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
|
1932
1903
|
}
|
|
1933
1904
|
return "";
|
|
1934
1905
|
};
|
|
1935
|
-
|
|
1936
1906
|
//#endregion
|
|
1937
1907
|
//#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
|
|
1938
1908
|
/**
|
|
@@ -1999,7 +1969,6 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
|
|
|
1999
1969
|
}
|
|
2000
1970
|
}
|
|
2001
1971
|
};
|
|
2002
|
-
|
|
2003
1972
|
//#endregion
|
|
2004
1973
|
//#region src/utils/formatQuery/formatQuery.ts
|
|
2005
1974
|
/**
|
|
@@ -2088,8 +2057,8 @@ const defaultFormatQueryOptions = {
|
|
|
2088
2057
|
paramsKeepPrefix: false,
|
|
2089
2058
|
numberedParams: false,
|
|
2090
2059
|
preserveValueOrder: false,
|
|
2091
|
-
placeholderFieldName:
|
|
2092
|
-
placeholderOperatorName:
|
|
2060
|
+
placeholderFieldName: "~",
|
|
2061
|
+
placeholderOperatorName: "~",
|
|
2093
2062
|
quoteValuesWith: "'",
|
|
2094
2063
|
concatOperator: "||",
|
|
2095
2064
|
preset: "ansi",
|
|
@@ -2194,7 +2163,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
2194
2163
|
switch (format) {
|
|
2195
2164
|
case "json":
|
|
2196
2165
|
case "json_without_ids": {
|
|
2197
|
-
const rg = parseNumbers ?
|
|
2166
|
+
const rg = parseNumbers ? require_utils.numerifyValues(ruleGroup, finalOptions) : ruleGroup;
|
|
2198
2167
|
if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : require_utils.bigIntJsonStringifyReplacer(key, value));
|
|
2199
2168
|
return JSON.stringify(rg, require_utils.bigIntJsonStringifyReplacer, 2);
|
|
2200
2169
|
}
|
|
@@ -2216,7 +2185,6 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
2216
2185
|
default: return "";
|
|
2217
2186
|
}
|
|
2218
2187
|
}
|
|
2219
|
-
|
|
2220
2188
|
//#endregion
|
|
2221
2189
|
//#region src/utils/formatQuery/index.ts
|
|
2222
2190
|
const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
|
|
@@ -2267,7 +2235,6 @@ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
|
|
|
2267
2235
|
* @group Export
|
|
2268
2236
|
*/
|
|
2269
2237
|
const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
|
|
2270
|
-
|
|
2271
2238
|
//#endregion
|
|
2272
2239
|
exports.bigIntJsonParseReviver = require_utils.bigIntJsonParseReviver;
|
|
2273
2240
|
exports.bigIntJsonStringifyReplacer = require_utils.bigIntJsonStringifyReplacer;
|
|
@@ -2331,4 +2298,5 @@ exports.prismaOperators = require_utils.prismaOperators;
|
|
|
2331
2298
|
exports.processMatchMode = require_utils.processMatchMode;
|
|
2332
2299
|
exports.shouldRenderAsNumber = require_utils.shouldRenderAsNumber;
|
|
2333
2300
|
exports.sqlDialectPresets = sqlDialectPresets;
|
|
2301
|
+
|
|
2334
2302
|
//# sourceMappingURL=formatQuery.js.map
|