@react-querybuilder/core 8.14.4 → 8.16.0
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/README.md +114 -53
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +288 -22
- package/dist/cjs/react-querybuilder_core.cjs.development.js +796 -77
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +288 -22
- 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-CeJSNn37.mjs → convertQuery-BeJJH9BI.mjs} +2 -2
- package/dist/convertQuery-BeJJH9BI.mjs.map +1 -0
- package/dist/{convertQuery-J8LpTG-7.js → convertQuery-Lx2HQa0m.js} +2 -2
- package/dist/convertQuery-Lx2HQa0m.js.map +1 -0
- package/dist/formatQuery.d.mts +89 -2
- package/dist/formatQuery.d.ts +89 -2
- package/dist/formatQuery.js +775 -66
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +768 -67
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-BwQqExpO.d.mts → import-BHlzBLM_.d.mts} +2 -2
- package/dist/{import-CrJf23Nf.d.ts → import-C6imciDf.d.ts} +2 -2
- package/dist/{index-CYT4Saz-.d.mts → index-Cjapnb-H.d.ts} +161 -10
- package/dist/{index-DBlQeLax.d.ts → index-D-Iej37L.d.mts} +161 -10
- package/dist/{objectUtils-ButT0Mng.js → objectUtils-Bzug_QfX.js} +2 -2
- package/dist/objectUtils-Bzug_QfX.js.map +1 -0
- package/dist/{objectUtils-C0WB-8ex.mjs → objectUtils-D96eEEzL.mjs} +2 -2
- package/dist/objectUtils-D96eEEzL.mjs.map +1 -0
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +35 -35
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +35 -35
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseCypher.d.mts +49 -0
- package/dist/parseCypher.d.ts +49 -0
- package/dist/parseCypher.js +578 -0
- package/dist/parseCypher.js.map +1 -0
- package/dist/parseCypher.mjs +575 -0
- package/dist/parseCypher.mjs.map +1 -0
- package/dist/parseGremlin.d.mts +35 -0
- package/dist/parseGremlin.d.ts +35 -0
- package/dist/parseGremlin.js +192 -0
- package/dist/parseGremlin.js.map +1 -0
- package/dist/parseGremlin.mjs +191 -0
- package/dist/parseGremlin.mjs.map +1 -0
- package/dist/parseJSONata.d.mts +2 -2
- package/dist/parseJSONata.d.ts +2 -2
- package/dist/parseJSONata.js +11 -11
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +11 -11
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +2 -2
- package/dist/parseJsonLogic.d.ts +2 -2
- package/dist/parseJsonLogic.js +6 -6
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +6 -6
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +2 -2
- package/dist/parseMongoDB.d.ts +2 -2
- package/dist/parseMongoDB.js +6 -6
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +6 -6
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSPARQL.d.mts +34 -0
- package/dist/parseSPARQL.d.ts +34 -0
- package/dist/parseSPARQL.js +253 -0
- package/dist/parseSPARQL.js.map +1 -0
- package/dist/parseSPARQL.mjs +251 -0
- package/dist/parseSPARQL.mjs.map +1 -0
- package/dist/parseSQL.d.mts +2 -2
- package/dist/parseSQL.d.ts +2 -2
- package/dist/parseSQL.js +16 -16
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +16 -16
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +2 -2
- package/dist/parseSpEL.d.ts +2 -2
- package/dist/parseSpEL.js +10 -10
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +10 -10
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-DO3qXriW.js → prepareQueryObjects-BoG5Rt8z.js} +6 -6
- package/dist/prepareQueryObjects-BoG5Rt8z.js.map +1 -0
- package/dist/{prepareQueryObjects-BfMlS4ql.mjs → prepareQueryObjects-uA10ZpZX.mjs} +6 -6
- package/dist/prepareQueryObjects-uA10ZpZX.mjs.map +1 -0
- package/dist/query-builder.css +1 -1
- package/dist/query-builder.css.map +1 -1
- package/dist/react-querybuilder_core.d.mts +288 -22
- package/dist/react-querybuilder_core.legacy-esm.d.ts +288 -22
- package/dist/react-querybuilder_core.legacy-esm.js +833 -108
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +788 -78
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +288 -22
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/styles/_main.scss +4 -0
- package/dist/transformQuery.d.mts +1 -1
- package/dist/transformQuery.d.ts +1 -1
- package/dist/transformQuery.js +1 -1
- package/dist/transformQuery.mjs +1 -1
- package/dist/{utils-BlMGIhvx.mjs → utils-ChLG90DP.mjs} +3 -3
- package/dist/utils-ChLG90DP.mjs.map +1 -0
- package/dist/{utils-CZRhzje-.js → utils-Qwkq2Q0F.js} +3 -3
- package/dist/utils-Qwkq2Q0F.js.map +1 -0
- package/formatQuery/package.json +1 -1
- package/package.json +53 -14
- package/parseCEL/package.json +1 -1
- package/parseCypher/package.json +4 -0
- package/parseGremlin/package.json +4 -0
- package/parseJSONata/package.json +1 -1
- package/parseJsonLogic/package.json +1 -1
- package/parseMongoDB/package.json +1 -1
- package/parseSPARQL/package.json +4 -0
- package/parseSQL/package.json +1 -1
- package/parseSpEL/package.json +1 -1
- package/transformQuery/package.json +1 -1
- package/dist/convertQuery-CeJSNn37.mjs.map +0 -1
- package/dist/convertQuery-J8LpTG-7.js.map +0 -1
- package/dist/objectUtils-ButT0Mng.js.map +0 -1
- package/dist/objectUtils-C0WB-8ex.mjs.map +0 -1
- package/dist/prepareQueryObjects-BfMlS4ql.mjs.map +0 -1
- package/dist/prepareQueryObjects-DO3qXriW.js.map +0 -1
- package/dist/utils-BlMGIhvx.mjs.map +0 -1
- package/dist/utils-CZRhzje-.js.map +0 -1
|
@@ -412,6 +412,8 @@ const standardClassnames = {
|
|
|
412
412
|
dndCopy: "dndCopy",
|
|
413
413
|
dndGroup: "dndGroup",
|
|
414
414
|
dndDropNotAllowed: "dndDropNotAllowed",
|
|
415
|
+
dndPreviewPosition: "dndPreviewPosition",
|
|
416
|
+
dndHidden: "dndHidden",
|
|
415
417
|
dragHandle: "queryBuilder-dragHandle",
|
|
416
418
|
disabled: "queryBuilder-disabled",
|
|
417
419
|
muted: "queryBuilder-muted",
|
|
@@ -468,6 +470,8 @@ const defaultControlClassnames = {
|
|
|
468
470
|
dndGroup: "",
|
|
469
471
|
dndCopy: "",
|
|
470
472
|
dndDropNotAllowed: "",
|
|
473
|
+
dndPreviewPosition: "",
|
|
474
|
+
dndHidden: "",
|
|
471
475
|
disabled: "",
|
|
472
476
|
valueListItem: "",
|
|
473
477
|
branches: "",
|
|
@@ -612,7 +616,7 @@ const toArray = (a, { retainEmptyStrings } = {}) => Array.isArray(a) ? a.map((v)
|
|
|
612
616
|
const nullFreeArray = (arr) => arr.every((el) => el === false || (el ?? false) !== false);
|
|
613
617
|
//#endregion
|
|
614
618
|
//#region src/utils/clsx.ts
|
|
615
|
-
|
|
619
|
+
/* v8 ignore start -- @preserve */
|
|
616
620
|
function toVal(mix) {
|
|
617
621
|
let k;
|
|
618
622
|
let y;
|
|
@@ -632,12 +636,13 @@ function toVal(mix) {
|
|
|
632
636
|
}
|
|
633
637
|
return str;
|
|
634
638
|
}
|
|
639
|
+
/* v8 ignore stop -- @preserve */
|
|
635
640
|
/**
|
|
636
641
|
* Vendored/adapted version of the `clsx` package.
|
|
637
642
|
*
|
|
638
643
|
* **NOTE:** Prefer the official package from npm outside the context of React Query Builder.
|
|
639
644
|
*/
|
|
640
|
-
//
|
|
645
|
+
// v8 ignore next
|
|
641
646
|
function clsx(...args) {
|
|
642
647
|
let i = 0;
|
|
643
648
|
let tmp;
|
|
@@ -655,7 +660,7 @@ function clsx(...args) {
|
|
|
655
660
|
/**
|
|
656
661
|
* Converts a value to lowercase if it's a string, otherwise returns the value as is.
|
|
657
662
|
*/
|
|
658
|
-
//
|
|
663
|
+
// v8 ignore next
|
|
659
664
|
const lc = (v) => typeof v === "string" ? v.toLowerCase() : v;
|
|
660
665
|
/**
|
|
661
666
|
* Regex matching numeric strings. Passes for positive/negative integers, decimals,
|
|
@@ -783,8 +788,9 @@ const defaultValidator = (query) => {
|
|
|
783
788
|
* Replace this with your custom rule validator.
|
|
784
789
|
*/
|
|
785
790
|
const validateRule = (rule) => {
|
|
786
|
-
|
|
791
|
+
/* v8 ignore start -- @preserve */
|
|
787
792
|
if (rule.id) result[rule.id];
|
|
793
|
+
/* v8 ignore stop -- @preserve */
|
|
788
794
|
};
|
|
789
795
|
const validateGroup = (rg) => {
|
|
790
796
|
const reasons = [];
|
|
@@ -795,7 +801,7 @@ const defaultValidator = (query) => {
|
|
|
795
801
|
if (invalidICs) reasons.push(groupInvalidReasons.invalidIndependentCombinators);
|
|
796
802
|
}
|
|
797
803
|
if (isRuleGroupType(rg) && !defaultCombinators.map((c) => c.name).includes(rg.combinator) && rg.rules.length > 1) reasons.push(groupInvalidReasons.invalidCombinator);
|
|
798
|
-
/*
|
|
804
|
+
/* v8 ignore else -- @preserve */
|
|
799
805
|
if (rg.id) result[rg.id] = reasons.length > 0 ? {
|
|
800
806
|
valid: false,
|
|
801
807
|
reasons
|
|
@@ -956,7 +962,7 @@ function getFirstOption(arr) {
|
|
|
956
962
|
if (!Array.isArray(arr) || arr.length === 0) return null;
|
|
957
963
|
else if (isFlexibleOptionGroupArray(arr, { allowEmpty: true })) {
|
|
958
964
|
for (const og of arr) if (og.options.length > 0) return og.options[0].value ?? og.options[0].name;
|
|
959
|
-
//
|
|
965
|
+
// v8 ignore next
|
|
960
966
|
return null;
|
|
961
967
|
}
|
|
962
968
|
return arr[0].value ?? arr[0].name;
|
|
@@ -1003,7 +1009,7 @@ const uniqOptList = (originalArray) => {
|
|
|
1003
1009
|
return uniqByIdentifier(originalArray.map((o) => toFullOption(o)));
|
|
1004
1010
|
};
|
|
1005
1011
|
const prepareOptionList = (props) => {
|
|
1006
|
-
//
|
|
1012
|
+
// v8 ignore next
|
|
1007
1013
|
const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName = "~", placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
|
|
1008
1014
|
const defaultOption = {
|
|
1009
1015
|
id: placeholderName,
|
|
@@ -1151,7 +1157,7 @@ const isRuleOrGroupValid = (rg, validationResult, validator) => {
|
|
|
1151
1157
|
if (typeof validator === "function" && !isRuleGroup(rg)) {
|
|
1152
1158
|
const vr = validator(rg);
|
|
1153
1159
|
if (typeof vr === "boolean") return vr;
|
|
1154
|
-
//
|
|
1160
|
+
// v8 ignore else
|
|
1155
1161
|
if (isValidationResult(vr)) return vr.valid;
|
|
1156
1162
|
}
|
|
1157
1163
|
return true;
|
|
@@ -1270,7 +1276,7 @@ const numerifyValues = (rg, options) => ({
|
|
|
1270
1276
|
};
|
|
1271
1277
|
const valAsArray = toArray(r.value, { retainEmptyStrings: true }).map((v) => parseNumber(v, { parseNumbers }));
|
|
1272
1278
|
if (valAsArray.every((v) => typeof v === "number")) {
|
|
1273
|
-
//
|
|
1279
|
+
// v8 ignore else
|
|
1274
1280
|
if (valAsArray.length > 1) return {
|
|
1275
1281
|
...r,
|
|
1276
1282
|
value: valAsArray
|
|
@@ -1475,7 +1481,7 @@ const defaultRuleGroupProcessorCEL = (ruleGroup, options) => {
|
|
|
1475
1481
|
//#endregion
|
|
1476
1482
|
//#region src/utils/formatQuery/defaultRuleProcessorCEL.ts
|
|
1477
1483
|
const shouldNegate$2 = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
1478
|
-
const escapeDoubleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`);
|
|
1484
|
+
const escapeDoubleQuotes$1 = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`);
|
|
1479
1485
|
/**
|
|
1480
1486
|
* Default rule processor used by {@link formatQuery} for "cel" format.
|
|
1481
1487
|
*
|
|
@@ -1517,19 +1523,19 @@ const defaultRuleProcessorCEL = (rule, opts = {}) => {
|
|
|
1517
1523
|
case "==":
|
|
1518
1524
|
case "!=":
|
|
1519
1525
|
case ">":
|
|
1520
|
-
case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`}`;
|
|
1526
|
+
case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? trimIfString(value) : `"${escapeDoubleQuotes$1(value, escapeQuotes)}"`}`;
|
|
1521
1527
|
case "contains":
|
|
1522
|
-
case "doesnotcontain": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.contains(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
|
|
1528
|
+
case "doesnotcontain": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.contains(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes$1(value, escapeQuotes)}"`})`;
|
|
1523
1529
|
case "beginswith":
|
|
1524
|
-
case "doesnotbeginwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.startsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
|
|
1530
|
+
case "doesnotbeginwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.startsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes$1(value, escapeQuotes)}"`})`;
|
|
1525
1531
|
case "endswith":
|
|
1526
|
-
case "doesnotendwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.endsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
|
|
1532
|
+
case "doesnotendwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.endsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes$1(value, escapeQuotes)}"`})`;
|
|
1527
1533
|
case "null": return `${field} == null`;
|
|
1528
1534
|
case "notnull": return `${field} != null`;
|
|
1529
1535
|
case "in":
|
|
1530
1536
|
case "notin": {
|
|
1531
1537
|
const [prefix, suffix] = shouldNegate$2(operatorTL) ? ["!(", ")"] : ["", ""];
|
|
1532
|
-
return `${prefix}${field} in [${toArray(value).map((val) => valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `"${escapeDoubleQuotes(val, escapeQuotes)}"`).join(", ")}]${suffix}`;
|
|
1538
|
+
return `${prefix}${field} in [${toArray(value).map((val) => valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `"${escapeDoubleQuotes$1(val, escapeQuotes)}"`).join(", ")}]${suffix}`;
|
|
1533
1539
|
}
|
|
1534
1540
|
case "between":
|
|
1535
1541
|
case "notbetween": {
|
|
@@ -1539,8 +1545,8 @@ const defaultRuleProcessorCEL = (rule, opts = {}) => {
|
|
|
1539
1545
|
const shouldParseNumbers = !(parseNumbers === false);
|
|
1540
1546
|
const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? parseNumber(first, { parseNumbers: shouldParseNumbers }) : NaN;
|
|
1541
1547
|
const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? parseNumber(second, { parseNumbers: shouldParseNumbers }) : NaN;
|
|
1542
|
-
let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `"${escapeDoubleQuotes(first, escapeQuotes)}"` : firstNum;
|
|
1543
|
-
let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `"${escapeDoubleQuotes(second, escapeQuotes)}"` : secondNum;
|
|
1548
|
+
let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `"${escapeDoubleQuotes$1(first, escapeQuotes)}"` : firstNum;
|
|
1549
|
+
let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `"${escapeDoubleQuotes$1(second, escapeQuotes)}"` : secondNum;
|
|
1544
1550
|
if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
|
|
1545
1551
|
const tempNum = secondNum;
|
|
1546
1552
|
secondValue = firstNum;
|
|
@@ -1796,7 +1802,7 @@ const defaultRuleGroupProcessorSpEL = (ruleGroup, options) => {
|
|
|
1796
1802
|
//#region src/utils/formatQuery/defaultRuleProcessorSpEL.ts
|
|
1797
1803
|
const shouldNegate$1 = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
1798
1804
|
const wrapInNegation = (clause, negate) => negate ? `!(${clause})` : clause;
|
|
1799
|
-
const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
|
|
1805
|
+
const escapeSingleQuotes$2 = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
|
|
1800
1806
|
/**
|
|
1801
1807
|
* Default rule processor used by {@link formatQuery} for "spel" format.
|
|
1802
1808
|
*
|
|
@@ -1837,20 +1843,20 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
|
|
|
1837
1843
|
case "==":
|
|
1838
1844
|
case "!=":
|
|
1839
1845
|
case ">":
|
|
1840
|
-
case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? trimIfString(value) : `'${escapeSingleQuotes(value, escapeQuotes)}'`}`;
|
|
1846
|
+
case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? trimIfString(value) : `'${escapeSingleQuotes$2(value, escapeQuotes)}'`}`;
|
|
1841
1847
|
case "contains":
|
|
1842
|
-
case "doesnotcontain": return wrapInNegation(`${field} matches ${valueIsField || useBareValue ? trimIfString(value) : `'${escapeSingleQuotes(value, escapeQuotes)}'`}`, shouldNegate$1(operatorTL));
|
|
1848
|
+
case "doesnotcontain": return wrapInNegation(`${field} matches ${valueIsField || useBareValue ? trimIfString(value) : `'${escapeSingleQuotes$2(value, escapeQuotes)}'`}`, shouldNegate$1(operatorTL));
|
|
1843
1849
|
case "beginswith":
|
|
1844
|
-
case "doesnotbeginwith": return wrapInNegation(`${field} matches ${valueIsField ? `'^'.concat(${trimIfString(value)})` : `'${typeof value === "string" && !value.startsWith("^") || useBareValue ? "^" : ""}${escapeSingleQuotes(value, escapeQuotes)}'`}`, shouldNegate$1(operatorTL));
|
|
1850
|
+
case "doesnotbeginwith": return wrapInNegation(`${field} matches ${valueIsField ? `'^'.concat(${trimIfString(value)})` : `'${typeof value === "string" && !value.startsWith("^") || useBareValue ? "^" : ""}${escapeSingleQuotes$2(value, escapeQuotes)}'`}`, shouldNegate$1(operatorTL));
|
|
1845
1851
|
case "endswith":
|
|
1846
|
-
case "doesnotendwith": return wrapInNegation(`${field} matches ${valueIsField ? `${trimIfString(value)}.concat('$')` : `'${escapeSingleQuotes(value, escapeQuotes)}${typeof value === "string" && !value.endsWith("$") || useBareValue ? "$" : ""}'`}`, shouldNegate$1(operatorTL));
|
|
1852
|
+
case "doesnotendwith": return wrapInNegation(`${field} matches ${valueIsField ? `${trimIfString(value)}.concat('$')` : `'${escapeSingleQuotes$2(value, escapeQuotes)}${typeof value === "string" && !value.endsWith("$") || useBareValue ? "$" : ""}'`}`, shouldNegate$1(operatorTL));
|
|
1847
1853
|
case "null": return `${field} == null`;
|
|
1848
1854
|
case "notnull": return `${field} != null`;
|
|
1849
1855
|
case "in":
|
|
1850
1856
|
case "notin": {
|
|
1851
1857
|
const negate = shouldNegate$1(operatorTL) ? "!" : "";
|
|
1852
1858
|
const valueAsArray = toArray(value);
|
|
1853
|
-
return valueAsArray.length > 0 ? `${negate}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
|
|
1859
|
+
return valueAsArray.length > 0 ? `${negate}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes$2(val, escapeQuotes)}'`}`).join(" or ")})` : "";
|
|
1854
1860
|
}
|
|
1855
1861
|
case "between":
|
|
1856
1862
|
case "notbetween": {
|
|
@@ -1860,8 +1866,8 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
|
|
|
1860
1866
|
const shouldParseNumbers = !(parseNumbers === false);
|
|
1861
1867
|
const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? parseNumber(first, { parseNumbers: shouldParseNumbers }) : NaN;
|
|
1862
1868
|
const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? parseNumber(second, { parseNumbers: shouldParseNumbers }) : NaN;
|
|
1863
|
-
let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `'${escapeSingleQuotes(first, escapeQuotes)}'` : firstNum;
|
|
1864
|
-
let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `'${escapeSingleQuotes(second, escapeQuotes)}'` : secondNum;
|
|
1869
|
+
let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `'${escapeSingleQuotes$2(first, escapeQuotes)}'` : firstNum;
|
|
1870
|
+
let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `'${escapeSingleQuotes$2(second, escapeQuotes)}'` : secondNum;
|
|
1865
1871
|
if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
|
|
1866
1872
|
const tempNum = secondNum;
|
|
1867
1873
|
secondValue = firstNum;
|
|
@@ -1929,6 +1935,70 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
|
|
|
1929
1935
|
return valueIsField ? wrapFieldName(value) : shouldRenderAsNumber(value, parseNumbers) ? `${trimIfString(value)}` : `${wrapAndEscape(value)}`;
|
|
1930
1936
|
};
|
|
1931
1937
|
//#endregion
|
|
1938
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorCypher.ts
|
|
1939
|
+
/**
|
|
1940
|
+
* Maps a {@link DefaultCombinatorName} to a Cypher combinator keyword.
|
|
1941
|
+
*
|
|
1942
|
+
* @group Export
|
|
1943
|
+
*/
|
|
1944
|
+
const cypherCombinatorMap = {
|
|
1945
|
+
and: "AND",
|
|
1946
|
+
or: "OR"
|
|
1947
|
+
};
|
|
1948
|
+
/**
|
|
1949
|
+
* Rule group processor used by {@link formatQuery} for "cypher" and "gql" formats.
|
|
1950
|
+
*
|
|
1951
|
+
* @group Export
|
|
1952
|
+
*/
|
|
1953
|
+
const defaultRuleGroupProcessorCypher = (ruleGroup, options) => {
|
|
1954
|
+
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
1955
|
+
const processRuleGroup = (rg, outermost) => {
|
|
1956
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
|
|
1957
|
+
const processedRules = [];
|
|
1958
|
+
let precedingCombinator = "";
|
|
1959
|
+
let firstRule = true;
|
|
1960
|
+
for (const rule of rg.rules) {
|
|
1961
|
+
if (typeof rule === "string") {
|
|
1962
|
+
precedingCombinator = cypherCombinatorMap[rule];
|
|
1963
|
+
continue;
|
|
1964
|
+
}
|
|
1965
|
+
if (isRuleGroup(rule)) {
|
|
1966
|
+
const processedGroup = processRuleGroup(rule);
|
|
1967
|
+
if (processedGroup) {
|
|
1968
|
+
if (!firstRule && precedingCombinator) {
|
|
1969
|
+
processedRules.push(precedingCombinator);
|
|
1970
|
+
precedingCombinator = "";
|
|
1971
|
+
}
|
|
1972
|
+
firstRule = false;
|
|
1973
|
+
processedRules.push(processedGroup);
|
|
1974
|
+
}
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
1978
|
+
if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) continue;
|
|
1979
|
+
const fieldData = getOption(fields, rule.field);
|
|
1980
|
+
const processedRule = ruleProcessor(rule, {
|
|
1981
|
+
...options,
|
|
1982
|
+
parseNumbers: getParseNumberBoolean(fieldData?.inputType),
|
|
1983
|
+
escapeQuotes: (rule.valueSource ?? "value") === "value",
|
|
1984
|
+
fieldData
|
|
1985
|
+
});
|
|
1986
|
+
if (processedRule) {
|
|
1987
|
+
if (!firstRule && precedingCombinator) {
|
|
1988
|
+
processedRules.push(precedingCombinator);
|
|
1989
|
+
precedingCombinator = "";
|
|
1990
|
+
}
|
|
1991
|
+
firstRule = false;
|
|
1992
|
+
processedRules.push(processedRule);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
const expression = processedRules.join(isRuleGroupType(rg) ? ` ${cypherCombinatorMap[rg.combinator]} ` : " ");
|
|
1996
|
+
const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "NOT " : ""}(`, ")"] : ["", ""];
|
|
1997
|
+
return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
|
|
1998
|
+
};
|
|
1999
|
+
return processRuleGroup(ruleGroup, true);
|
|
2000
|
+
};
|
|
2001
|
+
//#endregion
|
|
1932
2002
|
//#region src/utils/formatQuery/defaultRuleProcessorDrizzle.ts
|
|
1933
2003
|
/**
|
|
1934
2004
|
* Default rule processor used by {@link formatQuery} for the "drizzle" format.
|
|
@@ -1936,22 +2006,22 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
|
|
|
1936
2006
|
* @group Export
|
|
1937
2007
|
*/
|
|
1938
2008
|
const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
1939
|
-
const opts = _options ?? ( /*
|
|
1940
|
-
//
|
|
2009
|
+
const opts = _options ?? ( /* v8 ignore start -- @preserve */ {});
|
|
2010
|
+
// v8 ignore next
|
|
1941
2011
|
const { parseNumbers, preserveValueOrder, context = {} } = opts;
|
|
1942
2012
|
const { columns, drizzleOperators, useRawFields } = context;
|
|
1943
|
-
if (!columns || !drizzleOperators) return;
|
|
2013
|
+
if (!columns || !drizzleOperators) return void 0;
|
|
1944
2014
|
const { between, eq, gt, gte, inArray, isNotNull, isNull, like, lt, lte, ne, notBetween, notInArray, notLike, sql } = drizzleOperators;
|
|
1945
2015
|
const { field, operator, value, valueSource } = rule;
|
|
1946
2016
|
const column = useRawFields && /[a-z][a-z0-9]*/i.test(field) ? sql.raw(field) : columns[field];
|
|
1947
2017
|
const operatorLC = lc(operator);
|
|
1948
2018
|
const valueIsField = valueSource === "field";
|
|
1949
2019
|
const asFieldOrValue = (v) => valueIsField ? columns[v] : v;
|
|
1950
|
-
if (!column) return;
|
|
2020
|
+
if (!column) return void 0;
|
|
1951
2021
|
const matchEval = processMatchMode(rule);
|
|
1952
2022
|
if (matchEval === false) return;
|
|
1953
2023
|
else if (matchEval) {
|
|
1954
|
-
if (opts.preset !== "postgresql") return;
|
|
2024
|
+
if (opts.preset !== "postgresql") return void 0;
|
|
1955
2025
|
const { mode, threshold } = matchEval;
|
|
1956
2026
|
const arrayElementAlias = "elem_alias";
|
|
1957
2027
|
const nestedArrayFilter = defaultRuleGroupProcessorDrizzle(transformQuery(rule.value, { ruleProcessor: (r) => ({
|
|
@@ -2040,7 +2110,7 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
2040
2110
|
*/
|
|
2041
2111
|
const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns, drizzleOperators) => {
|
|
2042
2112
|
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap } = options;
|
|
2043
|
-
if (!columns || !drizzleOperators) return;
|
|
2113
|
+
if (!columns || !drizzleOperators) return void 0;
|
|
2044
2114
|
const { and, not, or } = drizzleOperators;
|
|
2045
2115
|
const ruleProcessor = defaultRuleProcessorDrizzle;
|
|
2046
2116
|
const processRuleGroup = (rg, _outermost) => {
|
|
@@ -2096,6 +2166,67 @@ const defaultRuleGroupProcessorElasticSearch = (ruleGroup, options) => {
|
|
|
2096
2166
|
return processedRuleGroup === false ? {} : processedRuleGroup;
|
|
2097
2167
|
};
|
|
2098
2168
|
//#endregion
|
|
2169
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorGremlin.ts
|
|
2170
|
+
/**
|
|
2171
|
+
* Rule group processor used by {@link formatQuery} for "gremlin" format.
|
|
2172
|
+
*
|
|
2173
|
+
* At the top level, filter rules produce chained `.has()` steps (implicit AND).
|
|
2174
|
+
* Nested groups use `.and()` / `.or()` / `.not()` compound traversals with
|
|
2175
|
+
* `__` anonymous traversal prefixes.
|
|
2176
|
+
*
|
|
2177
|
+
* @group Export
|
|
2178
|
+
*/
|
|
2179
|
+
const defaultRuleGroupProcessorGremlin = (ruleGroup, options) => {
|
|
2180
|
+
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
2181
|
+
const validateAndProcess = (rule) => {
|
|
2182
|
+
// v8 ignore next -- @preserve
|
|
2183
|
+
if (typeof rule === "string" || isRuleGroup(rule)) return void 0;
|
|
2184
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
2185
|
+
if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return;
|
|
2186
|
+
const fieldData = getOption(fields, rule.field);
|
|
2187
|
+
return ruleProcessor(rule, {
|
|
2188
|
+
...options,
|
|
2189
|
+
parseNumbers: getParseNumberBoolean(fieldData?.inputType),
|
|
2190
|
+
escapeQuotes: (rule.valueSource ?? "value") === "value",
|
|
2191
|
+
fieldData
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
/** Recursively processes a nested group into `.and()`/`.or()`/`.not()` form. */
|
|
2195
|
+
const processNested = (rg) => {
|
|
2196
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return "";
|
|
2197
|
+
const predicates = [];
|
|
2198
|
+
for (const rule of rg.rules) {
|
|
2199
|
+
if (typeof rule === "string") continue;
|
|
2200
|
+
if (isRuleGroup(rule)) {
|
|
2201
|
+
const nested = processNested(rule);
|
|
2202
|
+
if (nested) predicates.push(nested);
|
|
2203
|
+
continue;
|
|
2204
|
+
}
|
|
2205
|
+
const processed = validateAndProcess(rule);
|
|
2206
|
+
if (processed) predicates.push(processed);
|
|
2207
|
+
}
|
|
2208
|
+
if (predicates.length === 0) return "";
|
|
2209
|
+
const combinator = rg.combinator ?? "and";
|
|
2210
|
+
const prefix = rg.not ? "not" : combinator;
|
|
2211
|
+
if (predicates.length === 1 && !rg.not) return predicates[0];
|
|
2212
|
+
return `.${prefix}(${predicates.map((p) => p.startsWith(".") ? `__${p}` : p).join(", ")})`;
|
|
2213
|
+
};
|
|
2214
|
+
if (!isRuleOrGroupValid(ruleGroup, validationMap[ruleGroup.id ?? ""])) return fallbackExpression;
|
|
2215
|
+
const steps = [];
|
|
2216
|
+
for (const rule of ruleGroup.rules) {
|
|
2217
|
+
if (typeof rule === "string") continue;
|
|
2218
|
+
if (isRuleGroup(rule)) {
|
|
2219
|
+
const compound = processNested(rule);
|
|
2220
|
+
if (compound) steps.push(compound);
|
|
2221
|
+
continue;
|
|
2222
|
+
}
|
|
2223
|
+
const processed = validateAndProcess(rule);
|
|
2224
|
+
if (processed) steps.push(processed);
|
|
2225
|
+
}
|
|
2226
|
+
if (steps.length === 0) return fallbackExpression;
|
|
2227
|
+
return steps.join("");
|
|
2228
|
+
};
|
|
2229
|
+
//#endregion
|
|
2099
2230
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorJSONata.ts
|
|
2100
2231
|
/**
|
|
2101
2232
|
* Rule group processor used by {@link formatQuery} for "jsonata" format.
|
|
@@ -2259,7 +2390,7 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
|
|
|
2259
2390
|
const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
2260
2391
|
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, translations, validateRule, validationMap } = options;
|
|
2261
2392
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2262
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2393
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2263
2394
|
const rg2 = isRuleGroupTypeIC(rg) && rg.rules.some((r) => typeof r === "string" && lc(r) === "xor") ? convertFromIC(rg) : rg;
|
|
2264
2395
|
const processedRules = [];
|
|
2265
2396
|
let precedingCombinator = "";
|
|
@@ -2271,7 +2402,7 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
|
2271
2402
|
}
|
|
2272
2403
|
if (isRuleGroup(rule)) {
|
|
2273
2404
|
const processedGroup = processRuleGroup(rule, rg2.rules.length === 1 && !(rg2.not || /^xor$/i.test(rg2.combinator ?? "")));
|
|
2274
|
-
//
|
|
2405
|
+
// v8 ignore else
|
|
2275
2406
|
if (processedGroup) {
|
|
2276
2407
|
if (!firstRule && precedingCombinator) {
|
|
2277
2408
|
processedRules.push(precedingCombinator);
|
|
@@ -2347,7 +2478,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2347
2478
|
if (!isPojo(processedRule)) return "";
|
|
2348
2479
|
const { sql, params: customParams } = processedRule;
|
|
2349
2480
|
if (typeof sql !== "string" || !sql) return "";
|
|
2350
|
-
//
|
|
2481
|
+
// v8 ignore else
|
|
2351
2482
|
if (format === "parameterized" && Array.isArray(customParams)) params.push(...customParams);
|
|
2352
2483
|
else if (format === "parameterized_named" && isPojo(customParams)) {
|
|
2353
2484
|
Object.assign(paramsNamed, customParams);
|
|
@@ -2356,7 +2487,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2356
2487
|
return sql;
|
|
2357
2488
|
};
|
|
2358
2489
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2359
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2490
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2360
2491
|
const processedRules = [];
|
|
2361
2492
|
let precedingCombinator = "";
|
|
2362
2493
|
let firstRule = true;
|
|
@@ -2367,7 +2498,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2367
2498
|
}
|
|
2368
2499
|
if (isRuleGroup(rule)) {
|
|
2369
2500
|
const processedGroup = processRuleGroup(rule, rg.rules.length === 1);
|
|
2370
|
-
//
|
|
2501
|
+
// v8 ignore else
|
|
2371
2502
|
if (processedGroup) {
|
|
2372
2503
|
if (!firstRule && precedingCombinator) {
|
|
2373
2504
|
processedRules.push(precedingCombinator);
|
|
@@ -2450,10 +2581,10 @@ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
|
|
|
2450
2581
|
* @group Export
|
|
2451
2582
|
*/
|
|
2452
2583
|
const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
2453
|
-
//
|
|
2584
|
+
// v8 ignore next
|
|
2454
2585
|
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap, context = {} } = options;
|
|
2455
2586
|
const { sequelizeOperators: Op } = context;
|
|
2456
|
-
if (!Op) return;
|
|
2587
|
+
if (!Op) return void 0;
|
|
2457
2588
|
const processRuleGroup = (rg, _outermost) => {
|
|
2458
2589
|
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return;
|
|
2459
2590
|
const combinator = rg.combinator.toUpperCase();
|
|
@@ -2476,13 +2607,70 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
|
2476
2607
|
fieldData
|
|
2477
2608
|
});
|
|
2478
2609
|
}).filter(Boolean);
|
|
2479
|
-
if (expressions.length === 0) return;
|
|
2610
|
+
if (expressions.length === 0) return void 0;
|
|
2480
2611
|
const result = expressions.length === 1 && !hasChildRules ? expressions[0] : { [lc(combinator) === "or" ? Op.or : Op.and]: expressions };
|
|
2481
2612
|
return rg.not ? { [Op.not]: result } : result;
|
|
2482
2613
|
};
|
|
2483
2614
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2484
2615
|
};
|
|
2485
2616
|
//#endregion
|
|
2617
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorSPARQL.ts
|
|
2618
|
+
/**
|
|
2619
|
+
* Rule group processor used by {@link formatQuery} for "sparql" format.
|
|
2620
|
+
*
|
|
2621
|
+
* SPARQL uses the same combinators as CEL (`&&` / `||`) and `!()` for negation.
|
|
2622
|
+
*
|
|
2623
|
+
* @group Export
|
|
2624
|
+
*/
|
|
2625
|
+
const defaultRuleGroupProcessorSPARQL = (ruleGroup, options) => {
|
|
2626
|
+
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
2627
|
+
const processRuleGroup = (rg, outermost) => {
|
|
2628
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
|
|
2629
|
+
const processedRules = [];
|
|
2630
|
+
let precedingCombinator = "";
|
|
2631
|
+
let firstRule = true;
|
|
2632
|
+
for (const rule of rg.rules) {
|
|
2633
|
+
if (typeof rule === "string") {
|
|
2634
|
+
precedingCombinator = celCombinatorMap[rule];
|
|
2635
|
+
continue;
|
|
2636
|
+
}
|
|
2637
|
+
if (isRuleGroup(rule)) {
|
|
2638
|
+
const processedGroup = processRuleGroup(rule);
|
|
2639
|
+
if (processedGroup) {
|
|
2640
|
+
if (!firstRule && precedingCombinator) {
|
|
2641
|
+
processedRules.push(precedingCombinator);
|
|
2642
|
+
precedingCombinator = "";
|
|
2643
|
+
}
|
|
2644
|
+
firstRule = false;
|
|
2645
|
+
processedRules.push(processedGroup);
|
|
2646
|
+
}
|
|
2647
|
+
continue;
|
|
2648
|
+
}
|
|
2649
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
2650
|
+
if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) continue;
|
|
2651
|
+
const fieldData = getOption(fields, rule.field);
|
|
2652
|
+
const processedRule = ruleProcessor(rule, {
|
|
2653
|
+
...options,
|
|
2654
|
+
parseNumbers: getParseNumberBoolean(fieldData?.inputType),
|
|
2655
|
+
escapeQuotes: (rule.valueSource ?? "value") === "value",
|
|
2656
|
+
fieldData
|
|
2657
|
+
});
|
|
2658
|
+
if (processedRule) {
|
|
2659
|
+
if (!firstRule && precedingCombinator) {
|
|
2660
|
+
processedRules.push(precedingCombinator);
|
|
2661
|
+
precedingCombinator = "";
|
|
2662
|
+
}
|
|
2663
|
+
firstRule = false;
|
|
2664
|
+
processedRules.push(processedRule);
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
const expression = processedRules.join(isRuleGroupType(rg) ? ` ${celCombinatorMap[rg.combinator]} ` : " ");
|
|
2668
|
+
const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "!" : ""}(`, ")"] : ["", ""];
|
|
2669
|
+
return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
|
|
2670
|
+
};
|
|
2671
|
+
return processRuleGroup(ruleGroup, true);
|
|
2672
|
+
};
|
|
2673
|
+
//#endregion
|
|
2486
2674
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorSQL.ts
|
|
2487
2675
|
/**
|
|
2488
2676
|
* Default rule processor used by {@link formatQuery} for "sql" format.
|
|
@@ -2492,7 +2680,7 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
|
2492
2680
|
const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
2493
2681
|
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
2494
2682
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2495
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2683
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2496
2684
|
const processedRules = [];
|
|
2497
2685
|
let precedingCombinator = "";
|
|
2498
2686
|
let firstRule = true;
|
|
@@ -2503,7 +2691,7 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
2503
2691
|
}
|
|
2504
2692
|
if (isRuleGroup(rule)) {
|
|
2505
2693
|
const processedGroup = processRuleGroup(rule, rg.rules.length === 1);
|
|
2506
|
-
//
|
|
2694
|
+
// v8 ignore else
|
|
2507
2695
|
if (processedGroup) {
|
|
2508
2696
|
if (!firstRule && precedingCombinator) {
|
|
2509
2697
|
processedRules.push(precedingCombinator);
|
|
@@ -2539,6 +2727,378 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
2539
2727
|
return processRuleGroup(ruleGroup, true);
|
|
2540
2728
|
};
|
|
2541
2729
|
//#endregion
|
|
2730
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorDiagnostics.ts
|
|
2731
|
+
const numericInputTypes = new Set([
|
|
2732
|
+
"number",
|
|
2733
|
+
"range",
|
|
2734
|
+
"bigint"
|
|
2735
|
+
]);
|
|
2736
|
+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
2737
|
+
const timeRegex = /^\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/;
|
|
2738
|
+
const monthRegex = /^\d{4}-\d{2}$/;
|
|
2739
|
+
const weekRegex = /^\d{4}-W\d{2}$/;
|
|
2740
|
+
const colorRegex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
2741
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2742
|
+
const isValidDateComponents = (y, m, d) => {
|
|
2743
|
+
const date = new Date(Date.UTC(y, m - 1, d));
|
|
2744
|
+
return date.getUTCFullYear() === y && date.getUTCMonth() === m - 1 && date.getUTCDate() === d;
|
|
2745
|
+
};
|
|
2746
|
+
const isValidTimeComponents = (s) => {
|
|
2747
|
+
const parts = s.split(":");
|
|
2748
|
+
const h = Number(parts[0]);
|
|
2749
|
+
const m = Number(parts[1]);
|
|
2750
|
+
const sec = parts[2] ? Number.parseFloat(parts[2]) : 0;
|
|
2751
|
+
return h >= 0 && h <= 23 && m >= 0 && m <= 59 && sec >= 0 && sec < 60;
|
|
2752
|
+
};
|
|
2753
|
+
/**
|
|
2754
|
+
* Checks whether a value is compatible with the given {@link FullField.inputType}.
|
|
2755
|
+
* Returns a diagnostic code string if there is a mismatch, or `undefined` if OK.
|
|
2756
|
+
*/
|
|
2757
|
+
const checkValueTypeMismatch = (value, inputType) => {
|
|
2758
|
+
if (value === null || value === void 0 || value === "") return void 0;
|
|
2759
|
+
if (numericInputTypes.has(inputType)) {
|
|
2760
|
+
const v = typeof value === "string" ? value.trim() : value;
|
|
2761
|
+
if (typeof v === "number" || typeof v === "bigint") return void 0;
|
|
2762
|
+
if (typeof v === "string" && numericRegex.test(v)) return void 0;
|
|
2763
|
+
return "VALUE_TYPE_MISMATCH";
|
|
2764
|
+
}
|
|
2765
|
+
if (inputType === "date") {
|
|
2766
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2767
|
+
const v = value.trim();
|
|
2768
|
+
if (!dateRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2769
|
+
const [y, m, d] = v.split("-").map(Number);
|
|
2770
|
+
return isValidDateComponents(y, m, d) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2771
|
+
}
|
|
2772
|
+
if (inputType === "datetime-local") {
|
|
2773
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2774
|
+
const base = value.trim().replace(/(Z|[+-]\d{2}:?\d{2}|[+-]\d{2})$/, "");
|
|
2775
|
+
const tIndex = base.indexOf("T");
|
|
2776
|
+
if (tIndex === -1) return "VALUE_TYPE_MISMATCH";
|
|
2777
|
+
const datePart = base.slice(0, tIndex);
|
|
2778
|
+
const timePart = base.slice(tIndex + 1);
|
|
2779
|
+
if (!dateRegex.test(datePart) || !timeRegex.test(timePart)) return "VALUE_TYPE_MISMATCH";
|
|
2780
|
+
const [y, m, d] = datePart.split("-").map(Number);
|
|
2781
|
+
if (!isValidDateComponents(y, m, d)) return "VALUE_TYPE_MISMATCH";
|
|
2782
|
+
return isValidTimeComponents(timePart) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2783
|
+
}
|
|
2784
|
+
if (inputType === "time") {
|
|
2785
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2786
|
+
const v = value.trim();
|
|
2787
|
+
if (!timeRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2788
|
+
return isValidTimeComponents(v) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2789
|
+
}
|
|
2790
|
+
if (inputType === "month") {
|
|
2791
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2792
|
+
const v = value.trim();
|
|
2793
|
+
if (!monthRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2794
|
+
const m = Number(v.slice(5));
|
|
2795
|
+
return m >= 1 && m <= 12 ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2796
|
+
}
|
|
2797
|
+
if (inputType === "week") {
|
|
2798
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2799
|
+
const v = value.trim();
|
|
2800
|
+
if (!weekRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2801
|
+
const w = Number(v.slice(6));
|
|
2802
|
+
return w >= 1 && w <= 53 ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2803
|
+
}
|
|
2804
|
+
if (inputType === "color") {
|
|
2805
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2806
|
+
return colorRegex.test(value.trim()) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2807
|
+
}
|
|
2808
|
+
if (inputType === "url") {
|
|
2809
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2810
|
+
try {
|
|
2811
|
+
new URL(value.trim());
|
|
2812
|
+
return;
|
|
2813
|
+
} catch {
|
|
2814
|
+
return "VALUE_TYPE_MISMATCH";
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
if (inputType === "email") {
|
|
2818
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2819
|
+
return emailRegex.test(value.trim()) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2820
|
+
}
|
|
2821
|
+
};
|
|
2822
|
+
/**
|
|
2823
|
+
* Rule group processor used by {@link formatQuery} for "diagnostics" format.
|
|
2824
|
+
*
|
|
2825
|
+
* Produces a {@link DiagnosticsResult} containing an annotated copy of the query
|
|
2826
|
+
* tree (`query`) with `valid`, `reasons`, `path`, and `level` properties on every
|
|
2827
|
+
* rule and group; a flat `diagnostics` array; aggregate `stats`; and a per-field
|
|
2828
|
+
* `fieldSummary`.
|
|
2829
|
+
*
|
|
2830
|
+
* @group Export
|
|
2831
|
+
*/
|
|
2832
|
+
const defaultRuleGroupProcessorDiagnostics = (ruleGroup, options) => {
|
|
2833
|
+
const { fields: fieldsOption, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap } = options;
|
|
2834
|
+
const diagnostics = [];
|
|
2835
|
+
const stats = {
|
|
2836
|
+
totalRules: 0,
|
|
2837
|
+
totalGroups: 0,
|
|
2838
|
+
validRules: 0,
|
|
2839
|
+
invalidRules: 0,
|
|
2840
|
+
validGroups: 0,
|
|
2841
|
+
invalidGroups: 0
|
|
2842
|
+
};
|
|
2843
|
+
const fieldSummary = {};
|
|
2844
|
+
const uniqueFields = toFlatOptionArray(fieldsOption);
|
|
2845
|
+
const fieldsByName = /* @__PURE__ */ new Map();
|
|
2846
|
+
for (const f of uniqueFields) fieldsByName.set(f.name, f);
|
|
2847
|
+
const hasFieldsConfig = fieldsByName.size > 0;
|
|
2848
|
+
const processRuleGroup = (rg, path) => {
|
|
2849
|
+
stats.totalGroups++;
|
|
2850
|
+
const level = path.length;
|
|
2851
|
+
const groupValidationEntry = validationMap[rg.id ?? ""];
|
|
2852
|
+
const groupSelfValid = isRuleOrGroupValid(rg, groupValidationEntry);
|
|
2853
|
+
const groupReasons = getReasons(groupValidationEntry);
|
|
2854
|
+
if (rg.muted) diagnostics.push({
|
|
2855
|
+
id: rg.id ?? "",
|
|
2856
|
+
path,
|
|
2857
|
+
code: "MUTED",
|
|
2858
|
+
message: "Group is muted",
|
|
2859
|
+
source: "muted"
|
|
2860
|
+
});
|
|
2861
|
+
else if (!groupSelfValid && groupValidationEntry !== void 0) diagnostics.push({
|
|
2862
|
+
id: rg.id ?? "",
|
|
2863
|
+
path,
|
|
2864
|
+
code: "CUSTOM_VALIDATOR",
|
|
2865
|
+
message: groupReasons ? `Invalid: ${groupReasons.join(", ")}` : "Group failed validation",
|
|
2866
|
+
source: "query-validator"
|
|
2867
|
+
});
|
|
2868
|
+
let allChildrenValid = true;
|
|
2869
|
+
let ruleIndex = 0;
|
|
2870
|
+
const annotatedRules = [];
|
|
2871
|
+
for (const rule of rg.rules) {
|
|
2872
|
+
if (typeof rule === "string") {
|
|
2873
|
+
annotatedRules.push(rule);
|
|
2874
|
+
ruleIndex++;
|
|
2875
|
+
continue;
|
|
2876
|
+
}
|
|
2877
|
+
const childPath = [...path, ruleIndex];
|
|
2878
|
+
if (isRuleGroup(rule)) {
|
|
2879
|
+
const annotatedGroup = processRuleGroup(rule, childPath);
|
|
2880
|
+
if (!annotatedGroup.valid) allChildrenValid = false;
|
|
2881
|
+
annotatedRules.push(annotatedGroup);
|
|
2882
|
+
ruleIndex++;
|
|
2883
|
+
continue;
|
|
2884
|
+
}
|
|
2885
|
+
stats.totalRules++;
|
|
2886
|
+
const childLevel = childPath.length;
|
|
2887
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
2888
|
+
const ruleValid = isRuleOrGroupValid(rule, validationResult, fieldValidator) && rule.field !== placeholderFieldName && rule.operator !== placeholderOperatorName && !(placeholderValueName !== void 0 && rule.value === placeholderValueName);
|
|
2889
|
+
collectRuleDiagnostics(rule, childPath, validationResult, fieldValidator, ruleValid, diagnostics, placeholderFieldName, placeholderOperatorName, placeholderValueName, hasFieldsConfig, fieldsByName);
|
|
2890
|
+
if (!ruleValid) {
|
|
2891
|
+
allChildrenValid = false;
|
|
2892
|
+
stats.invalidRules++;
|
|
2893
|
+
} else stats.validRules++;
|
|
2894
|
+
const fieldName = rule.field;
|
|
2895
|
+
if (!fieldSummary[fieldName]) fieldSummary[fieldName] = {
|
|
2896
|
+
ruleCount: 0,
|
|
2897
|
+
invalidCount: 0
|
|
2898
|
+
};
|
|
2899
|
+
fieldSummary[fieldName].ruleCount++;
|
|
2900
|
+
if (!ruleValid) fieldSummary[fieldName].invalidCount++;
|
|
2901
|
+
const ruleReasons = getReasons(validationResult) ?? getFieldValidatorReasons(rule, fieldValidator);
|
|
2902
|
+
const annotatedRule = {
|
|
2903
|
+
...rule,
|
|
2904
|
+
valid: ruleValid,
|
|
2905
|
+
...ruleReasons ? { reasons: ruleReasons } : null,
|
|
2906
|
+
path: childPath,
|
|
2907
|
+
level: childLevel
|
|
2908
|
+
};
|
|
2909
|
+
annotatedRules.push(annotatedRule);
|
|
2910
|
+
ruleIndex++;
|
|
2911
|
+
}
|
|
2912
|
+
const groupValid = groupSelfValid && allChildrenValid;
|
|
2913
|
+
if (groupValid) stats.validGroups++;
|
|
2914
|
+
else stats.invalidGroups++;
|
|
2915
|
+
if (isRuleGroupType(rg)) return {
|
|
2916
|
+
...rg,
|
|
2917
|
+
valid: groupValid,
|
|
2918
|
+
...groupReasons ? { reasons: groupReasons } : null,
|
|
2919
|
+
path,
|
|
2920
|
+
level,
|
|
2921
|
+
rules: annotatedRules
|
|
2922
|
+
};
|
|
2923
|
+
return {
|
|
2924
|
+
...rg,
|
|
2925
|
+
valid: groupValid,
|
|
2926
|
+
...groupReasons ? { reasons: groupReasons } : null,
|
|
2927
|
+
path,
|
|
2928
|
+
level,
|
|
2929
|
+
rules: annotatedRules
|
|
2930
|
+
};
|
|
2931
|
+
};
|
|
2932
|
+
const query = processRuleGroup(ruleGroup, []);
|
|
2933
|
+
if (hasFieldsConfig) {
|
|
2934
|
+
const referencedFields = new Set(Object.keys(fieldSummary));
|
|
2935
|
+
for (const [fieldName] of fieldsByName) if (!referencedFields.has(fieldName)) diagnostics.push({
|
|
2936
|
+
id: "",
|
|
2937
|
+
path: [],
|
|
2938
|
+
code: "UNREFERENCED_FIELD",
|
|
2939
|
+
message: `Field "${fieldName}" is defined in the fields config but not used in the query`,
|
|
2940
|
+
source: "field-check"
|
|
2941
|
+
});
|
|
2942
|
+
}
|
|
2943
|
+
return {
|
|
2944
|
+
query,
|
|
2945
|
+
diagnostics,
|
|
2946
|
+
stats,
|
|
2947
|
+
fieldSummary
|
|
2948
|
+
};
|
|
2949
|
+
};
|
|
2950
|
+
/**
|
|
2951
|
+
* Collects diagnostic entries for a single rule.
|
|
2952
|
+
*/
|
|
2953
|
+
const collectRuleDiagnostics = (rule, path, validationResult, fieldValidator, ruleValid, diagnostics, placeholderFieldName, placeholderOperatorName, placeholderValueName, hasFieldsConfig, fieldsByName) => {
|
|
2954
|
+
const id = rule.id ?? "";
|
|
2955
|
+
if (rule.muted) diagnostics.push({
|
|
2956
|
+
id,
|
|
2957
|
+
path,
|
|
2958
|
+
code: "MUTED",
|
|
2959
|
+
message: "Rule is muted",
|
|
2960
|
+
source: "muted"
|
|
2961
|
+
});
|
|
2962
|
+
if (rule.field === placeholderFieldName) diagnostics.push({
|
|
2963
|
+
id,
|
|
2964
|
+
path,
|
|
2965
|
+
code: "PLACEHOLDER_FIELD",
|
|
2966
|
+
message: "Rule has a placeholder field",
|
|
2967
|
+
source: "placeholder"
|
|
2968
|
+
});
|
|
2969
|
+
if (rule.operator === placeholderOperatorName) diagnostics.push({
|
|
2970
|
+
id,
|
|
2971
|
+
path,
|
|
2972
|
+
code: "PLACEHOLDER_OPERATOR",
|
|
2973
|
+
message: "Rule has a placeholder operator",
|
|
2974
|
+
source: "placeholder"
|
|
2975
|
+
});
|
|
2976
|
+
if (placeholderValueName !== void 0 && rule.value === placeholderValueName) diagnostics.push({
|
|
2977
|
+
id,
|
|
2978
|
+
path,
|
|
2979
|
+
code: "PLACEHOLDER_VALUE",
|
|
2980
|
+
message: "Rule has a placeholder value",
|
|
2981
|
+
source: "placeholder"
|
|
2982
|
+
});
|
|
2983
|
+
if (!rule.muted && rule.field !== placeholderFieldName && rule.operator !== placeholderOperatorName && !(placeholderValueName !== void 0 && rule.value === placeholderValueName)) {
|
|
2984
|
+
if (typeof validationResult === "boolean" && !validationResult) diagnostics.push({
|
|
2985
|
+
id,
|
|
2986
|
+
path,
|
|
2987
|
+
code: "CUSTOM_VALIDATOR",
|
|
2988
|
+
message: "Rule failed validation",
|
|
2989
|
+
source: "query-validator"
|
|
2990
|
+
});
|
|
2991
|
+
else if (typeof validationResult !== "boolean" && isValidationResult(validationResult) && !validationResult.valid) {
|
|
2992
|
+
const reasons = validationResult.reasons;
|
|
2993
|
+
diagnostics.push({
|
|
2994
|
+
id,
|
|
2995
|
+
path,
|
|
2996
|
+
code: "CUSTOM_VALIDATOR",
|
|
2997
|
+
message: reasons ? `Invalid: ${reasons.join(", ")}` : "Rule failed validation",
|
|
2998
|
+
source: "query-validator"
|
|
2999
|
+
});
|
|
3000
|
+
} else if (!ruleValid && typeof fieldValidator === "function") {
|
|
3001
|
+
const vr = fieldValidator(rule);
|
|
3002
|
+
const reasons = typeof vr !== "boolean" && isValidationResult(vr) && !vr.valid ? vr.reasons : void 0;
|
|
3003
|
+
diagnostics.push({
|
|
3004
|
+
id,
|
|
3005
|
+
path,
|
|
3006
|
+
code: "CUSTOM_VALIDATOR",
|
|
3007
|
+
message: reasons ? `Invalid: ${reasons.join(", ")}` : "Rule failed field validation",
|
|
3008
|
+
source: "field-validator"
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
if (hasFieldsConfig && !fieldsByName.has(rule.field) && rule.field !== placeholderFieldName) diagnostics.push({
|
|
3013
|
+
id,
|
|
3014
|
+
path,
|
|
3015
|
+
code: "UNDEFINED_FIELD",
|
|
3016
|
+
message: `Field "${rule.field}" is not defined in the fields config`,
|
|
3017
|
+
source: "field-check"
|
|
3018
|
+
});
|
|
3019
|
+
if (hasFieldsConfig) {
|
|
3020
|
+
const fieldDef = fieldsByName.get(rule.field);
|
|
3021
|
+
if (fieldDef?.inputType) {
|
|
3022
|
+
const mismatchCode = checkValueTypeMismatch(rule.value, fieldDef.inputType);
|
|
3023
|
+
if (mismatchCode) diagnostics.push({
|
|
3024
|
+
id,
|
|
3025
|
+
path,
|
|
3026
|
+
code: mismatchCode,
|
|
3027
|
+
message: `Value "${rule.value}" is not compatible with input type "${fieldDef.inputType}"`,
|
|
3028
|
+
source: "type-check"
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
};
|
|
3033
|
+
/**
|
|
3034
|
+
* Extracts `reasons` from a validation result, if present.
|
|
3035
|
+
*/
|
|
3036
|
+
const getReasons = (validationResult) => {
|
|
3037
|
+
if (typeof validationResult !== "boolean" && isValidationResult(validationResult) && !validationResult.valid && validationResult.reasons) return validationResult.reasons;
|
|
3038
|
+
};
|
|
3039
|
+
/**
|
|
3040
|
+
* Runs a field-level validator and extracts `reasons` if present.
|
|
3041
|
+
*/
|
|
3042
|
+
const getFieldValidatorReasons = (rule, fieldValidator) => {
|
|
3043
|
+
if (typeof fieldValidator === "function") {
|
|
3044
|
+
const vr = fieldValidator(rule);
|
|
3045
|
+
if (typeof vr !== "boolean" && isValidationResult(vr) && !vr.valid && vr.reasons) return vr.reasons;
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
//#endregion
|
|
3049
|
+
//#region src/utils/formatQuery/defaultRuleProcessorCypher.ts
|
|
3050
|
+
const escapeSingleQuotes$1 = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll("'", "\\'");
|
|
3051
|
+
/**
|
|
3052
|
+
* Default rule processor used by {@link formatQuery} for "cypher" and "gql" formats.
|
|
3053
|
+
*
|
|
3054
|
+
* @group Export
|
|
3055
|
+
*/
|
|
3056
|
+
const defaultRuleProcessorCypher = (rule, opts = {}) => {
|
|
3057
|
+
const { escapeQuotes, parseNumbers } = opts;
|
|
3058
|
+
const { field, operator, value, valueSource } = rule;
|
|
3059
|
+
const valueIsField = valueSource === "field";
|
|
3060
|
+
const operatorTL = operator.toLowerCase();
|
|
3061
|
+
const fmtVal = (v) => {
|
|
3062
|
+
if (v === null || v === void 0) return "null";
|
|
3063
|
+
if (typeof v === "boolean" || typeof v === "bigint") return String(v);
|
|
3064
|
+
if (valueIsField) return trimIfString(v);
|
|
3065
|
+
if (typeof v === "number" || shouldRenderAsNumber(v, parseNumbers)) return trimIfString(v);
|
|
3066
|
+
return `'${escapeSingleQuotes$1(v, escapeQuotes)}'`;
|
|
3067
|
+
};
|
|
3068
|
+
switch (operatorTL) {
|
|
3069
|
+
case "=": return `${field} = ${fmtVal(value)}`;
|
|
3070
|
+
case "!=":
|
|
3071
|
+
case "<>": return `${field} <> ${fmtVal(value)}`;
|
|
3072
|
+
case "<":
|
|
3073
|
+
case ">":
|
|
3074
|
+
case "<=":
|
|
3075
|
+
case ">=": return `${field} ${operatorTL} ${fmtVal(value)}`;
|
|
3076
|
+
case "contains": return `${field} CONTAINS ${fmtVal(value)}`;
|
|
3077
|
+
case "doesnotcontain": return `NOT ${field} CONTAINS ${fmtVal(value)}`;
|
|
3078
|
+
case "beginswith": return `${field} STARTS WITH ${fmtVal(value)}`;
|
|
3079
|
+
case "doesnotbeginwith": return `NOT ${field} STARTS WITH ${fmtVal(value)}`;
|
|
3080
|
+
case "endswith": return `${field} ENDS WITH ${fmtVal(value)}`;
|
|
3081
|
+
case "doesnotendwith": return `NOT ${field} ENDS WITH ${fmtVal(value)}`;
|
|
3082
|
+
case "null": return `${field} IS NULL`;
|
|
3083
|
+
case "notnull": return `${field} IS NOT NULL`;
|
|
3084
|
+
case "in":
|
|
3085
|
+
case "notin": {
|
|
3086
|
+
const values = toArray(value).map(fmtVal);
|
|
3087
|
+
if (!values.length) return "";
|
|
3088
|
+
return `${operatorTL === "notin" ? "NOT " : ""}${field} IN [${values.join(", ")}]`;
|
|
3089
|
+
}
|
|
3090
|
+
case "between":
|
|
3091
|
+
case "notbetween": {
|
|
3092
|
+
const arr = toArray(value);
|
|
3093
|
+
if (arr.length < 2) return "";
|
|
3094
|
+
const [low, high] = [fmtVal(arr[0]), fmtVal(arr[1])];
|
|
3095
|
+
const expr = `${low} <= ${field} AND ${field} <= ${high}`;
|
|
3096
|
+
return operatorTL === "notbetween" ? `NOT (${expr})` : expr;
|
|
3097
|
+
}
|
|
3098
|
+
default: return `${field} ${operator} ${fmtVal(value)}`;
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
//#endregion
|
|
2542
3102
|
//#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
|
|
2543
3103
|
const rangeOperatorMap = {
|
|
2544
3104
|
"<": "lt",
|
|
@@ -2690,6 +3250,68 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
|
|
|
2690
3250
|
return false;
|
|
2691
3251
|
};
|
|
2692
3252
|
//#endregion
|
|
3253
|
+
//#region src/utils/formatQuery/defaultRuleProcessorGremlin.ts
|
|
3254
|
+
const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll("'", "\\'");
|
|
3255
|
+
/**
|
|
3256
|
+
* Default rule processor used by {@link formatQuery} for "gremlin" format.
|
|
3257
|
+
*
|
|
3258
|
+
* Each rule becomes a `.has()` step (or `.hasNot()`/`.has()` for null checks).
|
|
3259
|
+
*
|
|
3260
|
+
* @group Export
|
|
3261
|
+
*/
|
|
3262
|
+
const defaultRuleProcessorGremlin = (rule, opts = {}) => {
|
|
3263
|
+
const { escapeQuotes, parseNumbers } = opts;
|
|
3264
|
+
const { field, operator, value, valueSource } = rule;
|
|
3265
|
+
const valueIsField = valueSource === "field";
|
|
3266
|
+
const operatorTL = operator.toLowerCase();
|
|
3267
|
+
const prop = field.includes(".") ? field.split(".").pop() : field;
|
|
3268
|
+
const fmtVal = (v) => {
|
|
3269
|
+
if (v === null || v === void 0) return "null";
|
|
3270
|
+
if (typeof v === "boolean" || typeof v === "bigint") return String(v);
|
|
3271
|
+
if (valueIsField) return trimIfString(v);
|
|
3272
|
+
if (typeof v === "number" || shouldRenderAsNumber(v, parseNumbers)) return trimIfString(v);
|
|
3273
|
+
return `'${escapeSingleQuotes(v, escapeQuotes)}'`;
|
|
3274
|
+
};
|
|
3275
|
+
switch (operatorTL) {
|
|
3276
|
+
case "=": return `.has('${prop}', ${fmtVal(value)})`;
|
|
3277
|
+
case "!=":
|
|
3278
|
+
case "<>": return `.has('${prop}', neq(${fmtVal(value)}))`;
|
|
3279
|
+
case "<": return `.has('${prop}', lt(${fmtVal(value)}))`;
|
|
3280
|
+
case ">": return `.has('${prop}', gt(${fmtVal(value)}))`;
|
|
3281
|
+
case "<=": return `.has('${prop}', lte(${fmtVal(value)}))`;
|
|
3282
|
+
case ">=": return `.has('${prop}', gte(${fmtVal(value)}))`;
|
|
3283
|
+
case "contains": return `.has('${prop}', containing(${fmtVal(value)}))`;
|
|
3284
|
+
case "doesnotcontain": return `.has('${prop}', notContaining(${fmtVal(value)}))`;
|
|
3285
|
+
case "beginswith": return `.has('${prop}', startingWith(${fmtVal(value)}))`;
|
|
3286
|
+
case "doesnotbeginwith": return `.has('${prop}', notStartingWith(${fmtVal(value)}))`;
|
|
3287
|
+
case "endswith": return `.has('${prop}', endingWith(${fmtVal(value)}))`;
|
|
3288
|
+
case "doesnotendwith": return `.has('${prop}', notEndingWith(${fmtVal(value)}))`;
|
|
3289
|
+
case "null": return `.hasNot('${prop}')`;
|
|
3290
|
+
case "notnull": return `.has('${prop}')`;
|
|
3291
|
+
case "in": {
|
|
3292
|
+
const items = toArray(value).map(fmtVal);
|
|
3293
|
+
if (!items.length) return "";
|
|
3294
|
+
return `.has('${prop}', within(${items.join(", ")}))`;
|
|
3295
|
+
}
|
|
3296
|
+
case "notin": {
|
|
3297
|
+
const items = toArray(value).map(fmtVal);
|
|
3298
|
+
if (!items.length) return "";
|
|
3299
|
+
return `.has('${prop}', without(${items.join(", ")}))`;
|
|
3300
|
+
}
|
|
3301
|
+
case "between": {
|
|
3302
|
+
const arr = toArray(value);
|
|
3303
|
+
if (arr.length < 2) return "";
|
|
3304
|
+
return `.has('${prop}', between(${fmtVal(arr[0])}, ${fmtVal(arr[1])}))`;
|
|
3305
|
+
}
|
|
3306
|
+
case "notbetween": {
|
|
3307
|
+
const arr = toArray(value);
|
|
3308
|
+
if (arr.length < 2) return "";
|
|
3309
|
+
return `.has('${prop}', outside(${fmtVal(arr[0])}, ${fmtVal(arr[1])}))`;
|
|
3310
|
+
}
|
|
3311
|
+
default: return `.has('${prop}', ${fmtVal(value)})`;
|
|
3312
|
+
}
|
|
3313
|
+
};
|
|
3314
|
+
//#endregion
|
|
2693
3315
|
//#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
|
|
2694
3316
|
const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
|
|
2695
3317
|
const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
|
|
@@ -2917,12 +3539,12 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
|
|
|
2917
3539
|
return negateIf(`(&(${field}>=${ldapEscape(firstValue)})(${field}<=${ldapEscape(secondValue)}))`, operatorLC === "notbetween");
|
|
2918
3540
|
}
|
|
2919
3541
|
}
|
|
2920
|
-
//
|
|
3542
|
+
// v8 ignore next
|
|
2921
3543
|
return "";
|
|
2922
3544
|
};
|
|
2923
3545
|
//#endregion
|
|
2924
3546
|
//#region src/utils/formatQuery/defaultValueProcessorNL.ts
|
|
2925
|
-
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
|
|
3547
|
+
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : /* v8 ignore next -- @preserve */ v;
|
|
2926
3548
|
/**
|
|
2927
3549
|
* Default value processor used by {@link formatQuery} for "natural_language" format.
|
|
2928
3550
|
*
|
|
@@ -2940,7 +3562,7 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
2940
3562
|
quoteFieldNamesWith,
|
|
2941
3563
|
fieldIdentifierSeparator
|
|
2942
3564
|
});
|
|
2943
|
-
const t = translations ?? ( /*
|
|
3565
|
+
const t = translations ?? ( /* v8 ignore start -- @preserve */ {});
|
|
2944
3566
|
const orTL = t.or ?? "or";
|
|
2945
3567
|
const trueTL = t.true ?? "true";
|
|
2946
3568
|
const falseTL = t.false ?? "false";
|
|
@@ -2996,7 +3618,7 @@ const defaultExportOperatorMap = {
|
|
|
2996
3618
|
between: ["is between", "is between the values in"],
|
|
2997
3619
|
notbetween: ["is not between", "is not between the values in"]
|
|
2998
3620
|
};
|
|
2999
|
-
/*
|
|
3621
|
+
/* v8 ignore next -- @preserve */
|
|
3000
3622
|
const defaultGetOperators = () => [];
|
|
3001
3623
|
/**
|
|
3002
3624
|
* Default operator processor used by {@link formatQuery} for "natural_language" format.
|
|
@@ -3005,7 +3627,7 @@ const defaultGetOperators = () => [];
|
|
|
3005
3627
|
*/
|
|
3006
3628
|
const defaultOperatorProcessorNL = (rule, opts = {}) => {
|
|
3007
3629
|
const { field, operator, valueSource = "value" } = rule;
|
|
3008
|
-
//
|
|
3630
|
+
// v8 ignore next
|
|
3009
3631
|
const { getOperators = defaultGetOperators, operatorMap: operatorMapParam = defaultExportOperatorMap } = opts;
|
|
3010
3632
|
const mergedOperatorMap = new Map(Object.entries(defaultExportOperatorMap));
|
|
3011
3633
|
for (const [key, value] of Object.entries(operatorMapParam)) mergedOperatorMap.set(lc(key), value);
|
|
@@ -3034,8 +3656,8 @@ const defaultOperatorProcessorNL = (rule, opts = {}) => {
|
|
|
3034
3656
|
*/
|
|
3035
3657
|
const defaultRuleProcessorNL = (rule, opts) => {
|
|
3036
3658
|
const { field, operator } = rule;
|
|
3037
|
-
//
|
|
3038
|
-
const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorNL, valueProcessor = defaultValueProcessorNL, concatOperator = "||", wordOrder = "SVO" } = opts ?? ( /*
|
|
3659
|
+
// v8 ignore next
|
|
3660
|
+
const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorNL, valueProcessor = defaultValueProcessorNL, concatOperator = "||", wordOrder = "SVO" } = opts ?? ( /* v8 ignore start -- @preserve */ {});
|
|
3039
3661
|
const processedField = getQuotedFieldName(fieldData?.label ?? field, {
|
|
3040
3662
|
quoteFieldNamesWith,
|
|
3041
3663
|
fieldIdentifierSeparator
|
|
@@ -3141,7 +3763,7 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
|
|
|
3141
3763
|
* @group Export
|
|
3142
3764
|
*/
|
|
3143
3765
|
const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
3144
|
-
//
|
|
3766
|
+
// v8 ignore next
|
|
3145
3767
|
const { fieldData, format, getNextNamedParam, parseNumbers, paramPrefix, paramsKeepPrefix, numberedParams, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator, concatOperator, operatorProcessor = defaultOperatorProcessorSQL, valueProcessor = defaultValueProcessorByRule } = opts ?? {};
|
|
3146
3768
|
const { processedParams = [] } = meta ?? {};
|
|
3147
3769
|
const parameterized = format === "parameterized";
|
|
@@ -3160,6 +3782,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3160
3782
|
});
|
|
3161
3783
|
const ruleField = wrapFieldName(rule.field);
|
|
3162
3784
|
const matchEval = processMatchMode(rule);
|
|
3785
|
+
/* v8 ignore start -- @preserve */
|
|
3163
3786
|
if (matchEval === false) return;
|
|
3164
3787
|
else if (matchEval) {
|
|
3165
3788
|
if (opts?.preset !== "postgresql") return finalize("");
|
|
@@ -3172,7 +3795,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3172
3795
|
...opts,
|
|
3173
3796
|
fields: []
|
|
3174
3797
|
});
|
|
3175
|
-
// istanbul ignore else
|
|
3176
3798
|
if (Array.isArray(nestedParams)) params.push(...nestedParams);
|
|
3177
3799
|
else Object.assign(paramsNamed, nestedParams);
|
|
3178
3800
|
switch (mode) {
|
|
@@ -3187,6 +3809,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3187
3809
|
}
|
|
3188
3810
|
}
|
|
3189
3811
|
}
|
|
3812
|
+
/* v8 ignore stop -- @preserve */
|
|
3190
3813
|
const value = valueProcessor(rule, {
|
|
3191
3814
|
parseNumbers,
|
|
3192
3815
|
quoteFieldNamesWith,
|
|
@@ -3227,7 +3850,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3227
3850
|
}
|
|
3228
3851
|
let paramValue = rule.value;
|
|
3229
3852
|
if (typeof rule.value === "string") if (shouldRenderAsNumber(rule.value, parseNumbers)) paramValue = parseNumber(rule.value, { parseNumbers });
|
|
3230
|
-
else paramValue = /^'.*'$/g.test(value) ? value.replaceAll(/(^'|'$)/g, "") : value;
|
|
3853
|
+
else paramValue = /^'.*'$/g.test(value) ? value.replaceAll(/(^'|'$)/g, "") : /* v8 ignore next -- @preserve */ value;
|
|
3231
3854
|
let paramName = "";
|
|
3232
3855
|
if (parameterized) params.push(paramValue);
|
|
3233
3856
|
else {
|
|
@@ -3246,9 +3869,9 @@ const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(va
|
|
|
3246
3869
|
*/
|
|
3247
3870
|
const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
3248
3871
|
const { field, operator, value, valueSource } = rule;
|
|
3249
|
-
//
|
|
3872
|
+
// v8 ignore next
|
|
3250
3873
|
const { parseNumbers, preserveValueOrder } = options;
|
|
3251
|
-
if (valueSource === "field" || processMatchMode(rule)) return;
|
|
3874
|
+
if (valueSource === "field" || processMatchMode(rule)) return void 0;
|
|
3252
3875
|
const operatorLC = lc(operator);
|
|
3253
3876
|
switch (operatorLC) {
|
|
3254
3877
|
case "=": return { [field]: processNumber(value, value, parseNumbers) };
|
|
@@ -3306,13 +3929,16 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
|
3306
3929
|
*/
|
|
3307
3930
|
const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder, context = {} } = {}) => {
|
|
3308
3931
|
const { sequelizeOperators: Op, sequelizeCol: col, sequelizeFn: fn } = context;
|
|
3309
|
-
if (processMatchMode(rule)) return;
|
|
3932
|
+
if (processMatchMode(rule)) return void 0;
|
|
3310
3933
|
const { field, operator, value, valueSource } = rule;
|
|
3311
3934
|
const valueIsField = valueSource === "field";
|
|
3312
3935
|
const operatorLC = lc(operator);
|
|
3313
3936
|
if (!Op || valueIsField && (!col || !fn && [
|
|
3937
|
+
"contains",
|
|
3314
3938
|
"doesnotcontain",
|
|
3939
|
+
"beginswith",
|
|
3315
3940
|
"doesnotbeginwith",
|
|
3941
|
+
"endswith",
|
|
3316
3942
|
"doesnotendwith"
|
|
3317
3943
|
].includes(operatorLC))) return;
|
|
3318
3944
|
switch (operatorLC) {
|
|
@@ -3332,9 +3958,9 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
|
|
|
3332
3958
|
}[operatorLC];
|
|
3333
3959
|
return { [field]: valueIsField && operatorLC === "=" ? { [Op.col]: value } : { [sequelizeOperator]: valueIsField ? col(value) : shouldRenderAsNumber(value, parseNumbers) ? parseNumber(value, { parseNumbers: "strict" }) : value } };
|
|
3334
3960
|
}
|
|
3335
|
-
case "contains": return { [field]: { [Op.substring]: valueIsField ? col(value) : `${value}` } };
|
|
3336
|
-
case "beginswith": return { [field]: { [Op.startsWith]: valueIsField ? col(value) : `${value}` } };
|
|
3337
|
-
case "endswith": return { [field]: { [Op.endsWith]: valueIsField ? col(value) : `${value}` } };
|
|
3961
|
+
case "contains": return { [field]: { [valueIsField ? Op.like : Op.substring]: valueIsField ? fn("CONCAT", "%", col(value), "%") : `${value}` } };
|
|
3962
|
+
case "beginswith": return { [field]: { [valueIsField ? Op.like : Op.startsWith]: valueIsField ? fn("CONCAT", col(value), "%") : `${value}` } };
|
|
3963
|
+
case "endswith": return { [field]: { [valueIsField ? Op.like : Op.endsWith]: valueIsField ? fn("CONCAT", "%", col(value)) : `${value}` } };
|
|
3338
3964
|
case "doesnotcontain": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", "%", col(value), "%") : `%${value}%` } };
|
|
3339
3965
|
case "doesnotbeginwith": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", col(value), "%") : `${value}%` } };
|
|
3340
3966
|
case "doesnotendwith": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", "%", col(value)) : `%${value}` } };
|
|
@@ -3364,6 +3990,68 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
|
|
|
3364
3990
|
}
|
|
3365
3991
|
};
|
|
3366
3992
|
//#endregion
|
|
3993
|
+
//#region src/utils/formatQuery/defaultRuleProcessorSPARQL.ts
|
|
3994
|
+
const escapeDoubleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`);
|
|
3995
|
+
/**
|
|
3996
|
+
* Default rule processor used by {@link formatQuery} for "sparql" format.
|
|
3997
|
+
*
|
|
3998
|
+
* @group Export
|
|
3999
|
+
*/
|
|
4000
|
+
const defaultRuleProcessorSPARQL = (rule, opts = {}) => {
|
|
4001
|
+
const { escapeQuotes, parseNumbers } = opts;
|
|
4002
|
+
const { field, operator, value, valueSource } = rule;
|
|
4003
|
+
const valueIsField = valueSource === "field";
|
|
4004
|
+
const operatorTL = operator.toLowerCase();
|
|
4005
|
+
const fmtVal = (v) => {
|
|
4006
|
+
if (v === null || v === void 0) return "\"\"";
|
|
4007
|
+
if (typeof v === "boolean") return `"${v}"^^xsd:boolean`;
|
|
4008
|
+
if (typeof v === "bigint") return String(v);
|
|
4009
|
+
if (valueIsField) return trimIfString(v);
|
|
4010
|
+
if (typeof v === "number" || shouldRenderAsNumber(v, parseNumbers)) return trimIfString(v);
|
|
4011
|
+
const s = typeof v === "string" ? v : JSON.stringify(v) ?? "";
|
|
4012
|
+
if (s.startsWith("?") || s.startsWith("<") || s.includes(":")) return s;
|
|
4013
|
+
return `"${escapeDoubleQuotes(s, escapeQuotes)}"`;
|
|
4014
|
+
};
|
|
4015
|
+
switch (operatorTL) {
|
|
4016
|
+
case "=":
|
|
4017
|
+
case "!=":
|
|
4018
|
+
case "<":
|
|
4019
|
+
case ">":
|
|
4020
|
+
case "<=":
|
|
4021
|
+
case ">=": return `${field} ${operatorTL} ${fmtVal(value)}`;
|
|
4022
|
+
case "<>": return `${field} != ${fmtVal(value)}`;
|
|
4023
|
+
case "contains": return `CONTAINS(${field}, ${fmtVal(value)})`;
|
|
4024
|
+
case "doesnotcontain": return `!CONTAINS(${field}, ${fmtVal(value)})`;
|
|
4025
|
+
case "beginswith": return `STRSTARTS(${field}, ${fmtVal(value)})`;
|
|
4026
|
+
case "doesnotbeginwith": return `!STRSTARTS(${field}, ${fmtVal(value)})`;
|
|
4027
|
+
case "endswith": return `STRENDS(${field}, ${fmtVal(value)})`;
|
|
4028
|
+
case "doesnotendwith": return `!STRENDS(${field}, ${fmtVal(value)})`;
|
|
4029
|
+
case "null": return `!BOUND(${field})`;
|
|
4030
|
+
case "notnull": return `BOUND(${field})`;
|
|
4031
|
+
case "in": {
|
|
4032
|
+
const items = toArray(value).map(fmtVal);
|
|
4033
|
+
if (!items.length) return "";
|
|
4034
|
+
return items.map((item) => `${field} = ${item}`).join(" || ");
|
|
4035
|
+
}
|
|
4036
|
+
case "notin": {
|
|
4037
|
+
const items = toArray(value).map(fmtVal);
|
|
4038
|
+
if (!items.length) return "";
|
|
4039
|
+
return items.map((item) => `${field} != ${item}`).join(" && ");
|
|
4040
|
+
}
|
|
4041
|
+
case "between": {
|
|
4042
|
+
const arr = toArray(value);
|
|
4043
|
+
if (arr.length < 2) return "";
|
|
4044
|
+
return `${field} >= ${fmtVal(arr[0])} && ${field} <= ${fmtVal(arr[1])}`;
|
|
4045
|
+
}
|
|
4046
|
+
case "notbetween": {
|
|
4047
|
+
const arr = toArray(value);
|
|
4048
|
+
if (arr.length < 2) return "";
|
|
4049
|
+
return `(${field} < ${fmtVal(arr[0])} || ${field} > ${fmtVal(arr[1])})`;
|
|
4050
|
+
}
|
|
4051
|
+
default: return `${field} ${operator} ${fmtVal(value)}`;
|
|
4052
|
+
}
|
|
4053
|
+
};
|
|
4054
|
+
//#endregion
|
|
3367
4055
|
//#region src/utils/formatQuery/formatQuery.ts
|
|
3368
4056
|
/**
|
|
3369
4057
|
* A collection of option presets for {@link formatQuery}, specifically for SQL-based formats.
|
|
@@ -3410,9 +4098,14 @@ const defaultRuleProcessors = {
|
|
|
3410
4098
|
prisma: defaultRuleProcessorPrisma,
|
|
3411
4099
|
sequelize: defaultRuleProcessorSequelize,
|
|
3412
4100
|
spel: defaultRuleProcessorSpEL,
|
|
3413
|
-
sql: defaultRuleProcessorSQL
|
|
4101
|
+
sql: defaultRuleProcessorSQL,
|
|
4102
|
+
cypher: defaultRuleProcessorCypher,
|
|
4103
|
+
gql: defaultRuleProcessorCypher,
|
|
4104
|
+
sparql: defaultRuleProcessorSPARQL,
|
|
4105
|
+
gremlin: defaultRuleProcessorGremlin,
|
|
4106
|
+
diagnostics: defaultRuleProcessorSQL
|
|
3414
4107
|
};
|
|
3415
|
-
/*
|
|
4108
|
+
/* v8 ignore next -- @preserve */
|
|
3416
4109
|
const defaultOperatorProcessor = (r) => r.operator;
|
|
3417
4110
|
const defaultOperatorProcessors = {
|
|
3418
4111
|
cel: defaultOperatorProcessor,
|
|
@@ -3431,13 +4124,20 @@ const defaultOperatorProcessors = {
|
|
|
3431
4124
|
prisma: defaultOperatorProcessor,
|
|
3432
4125
|
sequelize: defaultOperatorProcessor,
|
|
3433
4126
|
spel: defaultOperatorProcessor,
|
|
3434
|
-
sql: defaultOperatorProcessorSQL
|
|
4127
|
+
sql: defaultOperatorProcessorSQL,
|
|
4128
|
+
cypher: defaultOperatorProcessor,
|
|
4129
|
+
gql: defaultOperatorProcessor,
|
|
4130
|
+
sparql: defaultOperatorProcessor,
|
|
4131
|
+
gremlin: defaultOperatorProcessor,
|
|
4132
|
+
diagnostics: defaultOperatorProcessor
|
|
3435
4133
|
};
|
|
3436
4134
|
const defaultFallbackExpressions = {
|
|
3437
4135
|
cel: "1 == 1",
|
|
3438
4136
|
ldap: "",
|
|
3439
4137
|
mongodb: "\"$and\":[{\"$expr\":true}]",
|
|
3440
4138
|
natural_language: "1 is 1",
|
|
4139
|
+
sparql: "1 = 1",
|
|
4140
|
+
gremlin: "",
|
|
3441
4141
|
spel: "1 == 1",
|
|
3442
4142
|
sql: "(1 = 1)"
|
|
3443
4143
|
};
|
|
@@ -3505,24 +4205,26 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3505
4205
|
const getOperators = (f, m) => toFullOptionList(getOperators_option(f, m) ?? []);
|
|
3506
4206
|
const fallbackExpression = fallbackExpression_option ?? defaultFallbackExpressions[format] ?? defaultFallbackExpressions.sql;
|
|
3507
4207
|
let validationMap = {};
|
|
3508
|
-
//
|
|
4208
|
+
// v8 ignore else
|
|
3509
4209
|
if (typeof validator === "function") {
|
|
3510
4210
|
const validationResult = validator(ruleGroup);
|
|
3511
4211
|
if (typeof validationResult === "boolean") {
|
|
3512
|
-
//
|
|
3513
|
-
if (!validationResult)
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
4212
|
+
// v8 ignore else
|
|
4213
|
+
if (!validationResult) {
|
|
4214
|
+
if (format !== "diagnostics") return format === "parameterized" ? {
|
|
4215
|
+
sql: fallbackExpression,
|
|
4216
|
+
params: []
|
|
4217
|
+
} : format === "parameterized_named" ? {
|
|
4218
|
+
sql: fallbackExpression,
|
|
4219
|
+
params: {}
|
|
4220
|
+
} : format === "mongodb" ? `{${fallbackExpression}}` : format === "mongodb_query" ? mongoDbFallback : format === "prisma" ? prismaFallback : format === "jsonlogic" ? false : format === "elasticsearch" ? {} : format === "drizzle" || format === "sequelize" ? void 0 : fallbackExpression;
|
|
4221
|
+
}
|
|
3520
4222
|
} else validationMap = validationResult;
|
|
3521
4223
|
}
|
|
3522
4224
|
const validatorMap = {};
|
|
3523
4225
|
const uniqueFields = toFlatOptionArray(fields);
|
|
3524
4226
|
for (const f of uniqueFields)
|
|
3525
|
-
//
|
|
4227
|
+
// v8 ignore else
|
|
3526
4228
|
if (typeof f.validator === "function") validatorMap[f.value ?? f.name] = f.validator;
|
|
3527
4229
|
const validateRule = (rule) => {
|
|
3528
4230
|
let validationResult;
|
|
@@ -3532,7 +4234,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3532
4234
|
const fieldArr = uniqueFields.filter((f) => f.name === rule.field);
|
|
3533
4235
|
if (fieldArr.length > 0) {
|
|
3534
4236
|
const field = fieldArr[0];
|
|
3535
|
-
//
|
|
4237
|
+
// v8 ignore else
|
|
3536
4238
|
if (typeof field.validator === "function") fieldValidator = field.validator;
|
|
3537
4239
|
}
|
|
3538
4240
|
}
|
|
@@ -3576,6 +4278,11 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3576
4278
|
case "prisma": return defaultRuleGroupProcessorPrisma(ruleGroup, finalOptions);
|
|
3577
4279
|
case "drizzle": return defaultRuleGroupProcessorDrizzle(ruleGroup, finalOptions);
|
|
3578
4280
|
case "sequelize": return defaultRuleGroupProcessorSequelize(ruleGroup, finalOptions);
|
|
4281
|
+
case "cypher":
|
|
4282
|
+
case "gql": return defaultRuleGroupProcessorCypher(ruleGroup, finalOptions);
|
|
4283
|
+
case "sparql": return defaultRuleGroupProcessorSPARQL(ruleGroup, finalOptions);
|
|
4284
|
+
case "gremlin": return defaultRuleGroupProcessorGremlin(ruleGroup, finalOptions);
|
|
4285
|
+
case "diagnostics": return defaultRuleGroupProcessorDiagnostics(ruleGroup, finalOptions);
|
|
3579
4286
|
default: return "";
|
|
3580
4287
|
}
|
|
3581
4288
|
}
|
|
@@ -3726,6 +4433,7 @@ const generateAccessibleDescription = (params) => pathsAreEqual([], params.path)
|
|
|
3726
4433
|
//#endregion
|
|
3727
4434
|
//#region src/utils/generateID.ts
|
|
3728
4435
|
const cryptoModule = globalThis.crypto;
|
|
4436
|
+
const uuidV4regex = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
|
|
3729
4437
|
/**
|
|
3730
4438
|
* Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`
|
|
3731
4439
|
* when available, otherwise uses an alternate method based on `getRandomValues`.
|
|
@@ -3735,11 +4443,11 @@ const cryptoModule = globalThis.crypto;
|
|
|
3735
4443
|
* ```
|
|
3736
4444
|
* @returns Valid v4 UUID
|
|
3737
4445
|
*/
|
|
3738
|
-
//
|
|
4446
|
+
// v8 ignore next
|
|
3739
4447
|
let generateID = () => "00-0-4-2-000".replaceAll(/[^-]/g, (s) => ((Math.random() + Math.trunc(s)) * 65536 >> Number.parseInt(s)).toString(16).padStart(4, "0"));
|
|
3740
|
-
//
|
|
4448
|
+
// v8 ignore else
|
|
3741
4449
|
if (cryptoModule) {
|
|
3742
|
-
//
|
|
4450
|
+
// v8 ignore else
|
|
3743
4451
|
if (typeof cryptoModule.randomUUID === "function") generateID = () => cryptoModule.randomUUID();
|
|
3744
4452
|
else if (typeof cryptoModule.getRandomValues === "function") {
|
|
3745
4453
|
const position19vals = "89ab";
|
|
@@ -3772,7 +4480,7 @@ const dummyFD$1 = {
|
|
|
3772
4480
|
* `FullOption<MatchMode>[]` of all match modes by default.
|
|
3773
4481
|
*/
|
|
3774
4482
|
const getMatchModesUtil = (fieldData, getMatchModes) => {
|
|
3775
|
-
const fd = fieldData ? toFullOption(fieldData) : dummyFD$1;
|
|
4483
|
+
const fd = fieldData ? toFullOption(fieldData) : /* v8 ignore next -- @preserve */ dummyFD$1;
|
|
3776
4484
|
let matchModes = fd.matchModes ?? false;
|
|
3777
4485
|
if (!matchModes && getMatchModes) matchModes = getMatchModes(fd.value, { fieldData: fd });
|
|
3778
4486
|
if (matchModes === true) return defaultMatchModes;
|
|
@@ -3834,7 +4542,7 @@ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
|
|
|
3834
4542
|
const mergeAnyTranslations = (base, ...otherTranslations) => {
|
|
3835
4543
|
const result = { ...base };
|
|
3836
4544
|
for (const translations of otherTranslations)
|
|
3837
|
-
//
|
|
4545
|
+
// v8 ignore else
|
|
3838
4546
|
if (translations) for (const key of objectKeys(translations)) {
|
|
3839
4547
|
if (isUnsafeKey(key)) continue;
|
|
3840
4548
|
if (result[key]) result[key] = {
|
|
@@ -3895,6 +4603,8 @@ const mergeClassnames = (...args) => ({
|
|
|
3895
4603
|
dndCopy: joinClassnamesByName("dndCopy", args),
|
|
3896
4604
|
dndGroup: joinClassnamesByName("dndGroup", args),
|
|
3897
4605
|
dndDropNotAllowed: joinClassnamesByName("dndDropNotAllowed", args),
|
|
4606
|
+
dndPreviewPosition: joinClassnamesByName("dndPreviewPosition", args),
|
|
4607
|
+
dndHidden: joinClassnamesByName("dndHidden", args),
|
|
3898
4608
|
disabled: joinClassnamesByName("disabled", args),
|
|
3899
4609
|
valueListItem: joinClassnamesByName("valueListItem", args),
|
|
3900
4610
|
matchMode: joinClassnamesByName("matchMode", args),
|
|
@@ -3990,7 +4700,7 @@ const regenerateIDs = (subject, { idGenerator = generateID } = {}) => {
|
|
|
3990
4700
|
...subject,
|
|
3991
4701
|
id: idGenerator()
|
|
3992
4702
|
};
|
|
3993
|
-
//
|
|
4703
|
+
// v8 ignore else
|
|
3994
4704
|
if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
|
|
3995
4705
|
return newGroup;
|
|
3996
4706
|
};
|
|
@@ -4284,6 +4994,6 @@ const groupInPlace = (query, sourcePathOrID, targetPathOrID, options = {}) => {
|
|
|
4284
4994
|
return query;
|
|
4285
4995
|
};
|
|
4286
4996
|
//#endregion
|
|
4287
|
-
export { LogType, TestID, add, addInPlace, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInPlace, groupInvalidReasons, insert, insertInPlace, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isUnsafeKey, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, moveInPlace, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, removeInPlace, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update, updateInPlace };
|
|
4997
|
+
export { LogType, TestID, add, addInPlace, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, cypherCombinatorMap, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInPlace, groupInvalidReasons, insert, insertInPlace, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isUnsafeKey, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, moveInPlace, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, removeInPlace, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update, updateInPlace, uuidV4regex };
|
|
4288
4998
|
|
|
4289
4999
|
//# sourceMappingURL=react-querybuilder_core.mjs.map
|