@react-querybuilder/core 8.14.0 → 8.14.2
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 +183 -127
- package/dist/cjs/react-querybuilder_core.cjs.development.js +311 -252
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +183 -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-CeJSNn37.mjs} +30 -22
- package/dist/convertQuery-CeJSNn37.mjs.map +1 -0
- package/dist/convertQuery-J8LpTG-7.js +94 -0
- package/dist/convertQuery-J8LpTG-7.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 +75 -107
- 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/objectUtils-ButT0Mng.js +105 -0
- package/dist/objectUtils-ButT0Mng.js.map +1 -0
- package/dist/{isRuleGroup-DztIOOKa.mjs → objectUtils-C0WB-8ex.mjs} +16 -5
- package/dist/objectUtils-C0WB-8ex.mjs.map +1 -0
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +14 -16
- 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 +40 -5614
- 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 +47 -48
- 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 +26 -27
- 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 +13 -15
- 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 +13 -2702
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +7 -9
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BBayjIn2.mjs → prepareQueryObjects-BfMlS4ql.mjs} +34 -18
- package/dist/prepareQueryObjects-BfMlS4ql.mjs.map +1 -0
- package/dist/{prepareQueryObjects-BxWvIPI4.js → prepareQueryObjects-DO3qXriW.js} +50 -35
- package/dist/prepareQueryObjects-DO3qXriW.js.map +1 -0
- package/dist/react-querybuilder_core.d.mts +183 -127
- package/dist/react-querybuilder_core.legacy-esm.d.ts +183 -127
- package/dist/react-querybuilder_core.legacy-esm.js +307 -280
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +299 -248
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +183 -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 +45 -2
- package/dist/transformQuery.js.map +1 -0
- package/dist/transformQuery.mjs +44 -2
- package/dist/transformQuery.mjs.map +1 -0
- package/dist/{utils-nQU7WCM9.mjs → utils-BlMGIhvx.mjs} +32 -92
- package/dist/utils-BlMGIhvx.mjs.map +1 -0
- package/dist/{utils-CR1ToTMW.js → utils-CZRhzje-.js} +187 -265
- package/dist/utils-CZRhzje-.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 +0 -82
- 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
|
|
2
|
-
import { produce } from "immer";
|
|
3
|
-
|
|
1
|
+
import { a as isRuleGroupTypeIC, i as isRuleGroupType, r as isRuleGroup, s as lc } from "./objectUtils-C0WB-8ex.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-CeJSNn37.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertQuery-CeJSNn37.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_objectUtils = require("./objectUtils-ButT0Mng.js");
|
|
2
|
+
//#region src/utils/convertQuery.ts
|
|
3
|
+
const combinatorLevels = [
|
|
4
|
+
"or",
|
|
5
|
+
"xor",
|
|
6
|
+
"and"
|
|
7
|
+
];
|
|
8
|
+
const isSameString = (a, b) => require_objectUtils.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_objectUtils.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_objectUtils.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_objectUtils.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_objectUtils.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_objectUtils.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-J8LpTG-7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertQuery-J8LpTG-7.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
|
*
|