@react-querybuilder/core 8.14.3 → 8.15.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/dist/cjs/react-querybuilder_core.cjs.development.d.ts +201 -8
- package/dist/cjs/react-querybuilder_core.cjs.development.js +400 -62
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +201 -8
- 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 +24 -3
- package/dist/formatQuery.d.ts +24 -3
- package/dist/formatQuery.js +379 -51
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +379 -52
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-Bltb2mT4.d.mts → import-0wp72lLT.d.mts} +2 -2
- package/dist/{import-B5Iq8XmL.d.ts → import-yRVJh7E1.d.ts} +2 -2
- package/dist/{basic-BXJVfD0P.d.ts → index-D5TXNIzF.d.ts} +595 -3
- package/dist/{basic-CNIjb6rI.d.mts → index-Lht_Wq3V.d.mts} +595 -3
- 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/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 -3
- package/dist/parseJsonLogic.d.ts +2 -3
- 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/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 +201 -8
- package/dist/react-querybuilder_core.legacy-esm.d.ts +201 -8
- package/dist/react-querybuilder_core.legacy-esm.js +441 -93
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +399 -63
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +201 -8
- 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/package.json +12 -16
- package/dist/convertQuery-CeJSNn37.mjs.map +0 -1
- package/dist/convertQuery-J8LpTG-7.js.map +0 -1
- package/dist/export-6x7MilFR.d.mts +0 -451
- package/dist/export-CpJOQuZv.d.ts +0 -451
- 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
|
@@ -413,6 +413,8 @@ const standardClassnames = {
|
|
|
413
413
|
dndCopy: "dndCopy",
|
|
414
414
|
dndGroup: "dndGroup",
|
|
415
415
|
dndDropNotAllowed: "dndDropNotAllowed",
|
|
416
|
+
dndPreviewPosition: "dndPreviewPosition",
|
|
417
|
+
dndHidden: "dndHidden",
|
|
416
418
|
dragHandle: "queryBuilder-dragHandle",
|
|
417
419
|
disabled: "queryBuilder-disabled",
|
|
418
420
|
muted: "queryBuilder-muted",
|
|
@@ -469,6 +471,8 @@ const defaultControlClassnames = {
|
|
|
469
471
|
dndGroup: "",
|
|
470
472
|
dndCopy: "",
|
|
471
473
|
dndDropNotAllowed: "",
|
|
474
|
+
dndPreviewPosition: "",
|
|
475
|
+
dndHidden: "",
|
|
472
476
|
disabled: "",
|
|
473
477
|
valueListItem: "",
|
|
474
478
|
branches: "",
|
|
@@ -613,7 +617,7 @@ const toArray = (a, { retainEmptyStrings } = {}) => Array.isArray(a) ? a.map((v)
|
|
|
613
617
|
const nullFreeArray = (arr) => arr.every((el) => el === false || (el ?? false) !== false);
|
|
614
618
|
//#endregion
|
|
615
619
|
//#region src/utils/clsx.ts
|
|
616
|
-
|
|
620
|
+
/* v8 ignore start -- @preserve */
|
|
617
621
|
function toVal(mix) {
|
|
618
622
|
let k;
|
|
619
623
|
let y;
|
|
@@ -633,12 +637,13 @@ function toVal(mix) {
|
|
|
633
637
|
}
|
|
634
638
|
return str;
|
|
635
639
|
}
|
|
640
|
+
/* v8 ignore stop -- @preserve */
|
|
636
641
|
/**
|
|
637
642
|
* Vendored/adapted version of the `clsx` package.
|
|
638
643
|
*
|
|
639
644
|
* **NOTE:** Prefer the official package from npm outside the context of React Query Builder.
|
|
640
645
|
*/
|
|
641
|
-
//
|
|
646
|
+
// v8 ignore next
|
|
642
647
|
function clsx(...args) {
|
|
643
648
|
let i = 0;
|
|
644
649
|
let tmp;
|
|
@@ -656,7 +661,7 @@ function clsx(...args) {
|
|
|
656
661
|
/**
|
|
657
662
|
* Converts a value to lowercase if it's a string, otherwise returns the value as is.
|
|
658
663
|
*/
|
|
659
|
-
//
|
|
664
|
+
// v8 ignore next
|
|
660
665
|
const lc = (v) => typeof v === "string" ? v.toLowerCase() : v;
|
|
661
666
|
/**
|
|
662
667
|
* Regex matching numeric strings. Passes for positive/negative integers, decimals,
|
|
@@ -784,8 +789,9 @@ const defaultValidator = (query) => {
|
|
|
784
789
|
* Replace this with your custom rule validator.
|
|
785
790
|
*/
|
|
786
791
|
const validateRule = (rule) => {
|
|
787
|
-
|
|
792
|
+
/* v8 ignore start -- @preserve */
|
|
788
793
|
if (rule.id) result[rule.id];
|
|
794
|
+
/* v8 ignore stop -- @preserve */
|
|
789
795
|
};
|
|
790
796
|
const validateGroup = (rg) => {
|
|
791
797
|
const reasons = [];
|
|
@@ -796,7 +802,7 @@ const defaultValidator = (query) => {
|
|
|
796
802
|
if (invalidICs) reasons.push(groupInvalidReasons.invalidIndependentCombinators);
|
|
797
803
|
}
|
|
798
804
|
if (isRuleGroupType(rg) && !defaultCombinators.map((c) => c.name).includes(rg.combinator) && rg.rules.length > 1) reasons.push(groupInvalidReasons.invalidCombinator);
|
|
799
|
-
/*
|
|
805
|
+
/* v8 ignore else -- @preserve */
|
|
800
806
|
if (rg.id) result[rg.id] = reasons.length > 0 ? {
|
|
801
807
|
valid: false,
|
|
802
808
|
reasons
|
|
@@ -957,7 +963,7 @@ function getFirstOption(arr) {
|
|
|
957
963
|
if (!Array.isArray(arr) || arr.length === 0) return null;
|
|
958
964
|
else if (isFlexibleOptionGroupArray(arr, { allowEmpty: true })) {
|
|
959
965
|
for (const og of arr) if (og.options.length > 0) return og.options[0].value ?? og.options[0].name;
|
|
960
|
-
//
|
|
966
|
+
// v8 ignore next
|
|
961
967
|
return null;
|
|
962
968
|
}
|
|
963
969
|
return arr[0].value ?? arr[0].name;
|
|
@@ -1004,7 +1010,7 @@ const uniqOptList = (originalArray) => {
|
|
|
1004
1010
|
return uniqByIdentifier(originalArray.map((o) => toFullOption(o)));
|
|
1005
1011
|
};
|
|
1006
1012
|
const prepareOptionList = (props) => {
|
|
1007
|
-
//
|
|
1013
|
+
// v8 ignore next
|
|
1008
1014
|
const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName = "~", placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
|
|
1009
1015
|
const defaultOption = {
|
|
1010
1016
|
id: placeholderName,
|
|
@@ -1152,7 +1158,7 @@ const isRuleOrGroupValid = (rg, validationResult, validator) => {
|
|
|
1152
1158
|
if (typeof validator === "function" && !isRuleGroup(rg)) {
|
|
1153
1159
|
const vr = validator(rg);
|
|
1154
1160
|
if (typeof vr === "boolean") return vr;
|
|
1155
|
-
//
|
|
1161
|
+
// v8 ignore else
|
|
1156
1162
|
if (isValidationResult(vr)) return vr.valid;
|
|
1157
1163
|
}
|
|
1158
1164
|
return true;
|
|
@@ -1271,7 +1277,7 @@ const numerifyValues = (rg, options) => ({
|
|
|
1271
1277
|
};
|
|
1272
1278
|
const valAsArray = toArray(r.value, { retainEmptyStrings: true }).map((v) => parseNumber(v, { parseNumbers }));
|
|
1273
1279
|
if (valAsArray.every((v) => typeof v === "number")) {
|
|
1274
|
-
//
|
|
1280
|
+
// v8 ignore else
|
|
1275
1281
|
if (valAsArray.length > 1) return {
|
|
1276
1282
|
...r,
|
|
1277
1283
|
value: valAsArray
|
|
@@ -1567,7 +1573,8 @@ const mongoDbFallback = { $and: [{ $expr: true }] };
|
|
|
1567
1573
|
* @group Export
|
|
1568
1574
|
*/
|
|
1569
1575
|
const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
|
|
1570
|
-
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
1576
|
+
const { context, fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
1577
|
+
const { inExpressionContext } = context ?? {};
|
|
1571
1578
|
const processRuleGroup = (rg, outermost) => {
|
|
1572
1579
|
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? mongoDbFallback : false;
|
|
1573
1580
|
const combinator = `$${lc(rg.combinator)}`;
|
|
@@ -1591,7 +1598,7 @@ const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
|
|
|
1591
1598
|
}, meta);
|
|
1592
1599
|
}).filter(Boolean);
|
|
1593
1600
|
const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
|
|
1594
|
-
return rg.not ? { $not: result } : result;
|
|
1601
|
+
return rg.not ? inExpressionContext ? { $not: result } : { $nor: [result] } : result;
|
|
1595
1602
|
};
|
|
1596
1603
|
return processRuleGroup(convertFromIC(ruleGroup), true);
|
|
1597
1604
|
};
|
|
@@ -1632,7 +1639,8 @@ const defaultRuleProcessorMongoDBQuery = (rule, options = {}) => {
|
|
|
1632
1639
|
ruleProcessor: defaultRuleProcessorMongoDBQuery,
|
|
1633
1640
|
context: {
|
|
1634
1641
|
...options.context,
|
|
1635
|
-
avoidFieldsAsKeys: true
|
|
1642
|
+
avoidFieldsAsKeys: true,
|
|
1643
|
+
inExpressionContext: true
|
|
1636
1644
|
}
|
|
1637
1645
|
});
|
|
1638
1646
|
const filteredCount = { $size: { $ifNull: [{ $filter: {
|
|
@@ -1935,22 +1943,22 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
|
|
|
1935
1943
|
* @group Export
|
|
1936
1944
|
*/
|
|
1937
1945
|
const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
1938
|
-
const opts = _options ?? ( /*
|
|
1939
|
-
//
|
|
1946
|
+
const opts = _options ?? ( /* v8 ignore start -- @preserve */ {});
|
|
1947
|
+
// v8 ignore next
|
|
1940
1948
|
const { parseNumbers, preserveValueOrder, context = {} } = opts;
|
|
1941
1949
|
const { columns, drizzleOperators, useRawFields } = context;
|
|
1942
|
-
if (!columns || !drizzleOperators) return;
|
|
1950
|
+
if (!columns || !drizzleOperators) return void 0;
|
|
1943
1951
|
const { between, eq, gt, gte, inArray, isNotNull, isNull, like, lt, lte, ne, notBetween, notInArray, notLike, sql } = drizzleOperators;
|
|
1944
1952
|
const { field, operator, value, valueSource } = rule;
|
|
1945
1953
|
const column = useRawFields && /[a-z][a-z0-9]*/i.test(field) ? sql.raw(field) : columns[field];
|
|
1946
1954
|
const operatorLC = lc(operator);
|
|
1947
1955
|
const valueIsField = valueSource === "field";
|
|
1948
1956
|
const asFieldOrValue = (v) => valueIsField ? columns[v] : v;
|
|
1949
|
-
if (!column) return;
|
|
1957
|
+
if (!column) return void 0;
|
|
1950
1958
|
const matchEval = processMatchMode(rule);
|
|
1951
1959
|
if (matchEval === false) return;
|
|
1952
1960
|
else if (matchEval) {
|
|
1953
|
-
if (opts.preset !== "postgresql") return;
|
|
1961
|
+
if (opts.preset !== "postgresql") return void 0;
|
|
1954
1962
|
const { mode, threshold } = matchEval;
|
|
1955
1963
|
const arrayElementAlias = "elem_alias";
|
|
1956
1964
|
const nestedArrayFilter = defaultRuleGroupProcessorDrizzle(transformQuery(rule.value, { ruleProcessor: (r) => ({
|
|
@@ -2039,7 +2047,7 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
2039
2047
|
*/
|
|
2040
2048
|
const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns, drizzleOperators) => {
|
|
2041
2049
|
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap } = options;
|
|
2042
|
-
if (!columns || !drizzleOperators) return;
|
|
2050
|
+
if (!columns || !drizzleOperators) return void 0;
|
|
2043
2051
|
const { and, not, or } = drizzleOperators;
|
|
2044
2052
|
const ruleProcessor = defaultRuleProcessorDrizzle;
|
|
2045
2053
|
const processRuleGroup = (rg, _outermost) => {
|
|
@@ -2243,7 +2251,7 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
|
|
|
2243
2251
|
}, meta);
|
|
2244
2252
|
}).filter(Boolean);
|
|
2245
2253
|
const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
|
|
2246
|
-
return rg.not ? `"$
|
|
2254
|
+
return rg.not ? `"$nor":[${isBracketed(result) ? result : `{${result}}`}]` : result;
|
|
2247
2255
|
};
|
|
2248
2256
|
const processedQuery = processRuleGroup(convertFromIC(ruleGroup), true);
|
|
2249
2257
|
return isBracketed(processedQuery) ? processedQuery : `{${processedQuery}}`;
|
|
@@ -2258,7 +2266,7 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
|
|
|
2258
2266
|
const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
2259
2267
|
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, translations, validateRule, validationMap } = options;
|
|
2260
2268
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2261
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2269
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2262
2270
|
const rg2 = isRuleGroupTypeIC(rg) && rg.rules.some((r) => typeof r === "string" && lc(r) === "xor") ? convertFromIC(rg) : rg;
|
|
2263
2271
|
const processedRules = [];
|
|
2264
2272
|
let precedingCombinator = "";
|
|
@@ -2270,7 +2278,7 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
|
2270
2278
|
}
|
|
2271
2279
|
if (isRuleGroup(rule)) {
|
|
2272
2280
|
const processedGroup = processRuleGroup(rule, rg2.rules.length === 1 && !(rg2.not || /^xor$/i.test(rg2.combinator ?? "")));
|
|
2273
|
-
//
|
|
2281
|
+
// v8 ignore else
|
|
2274
2282
|
if (processedGroup) {
|
|
2275
2283
|
if (!firstRule && precedingCombinator) {
|
|
2276
2284
|
processedRules.push(precedingCombinator);
|
|
@@ -2346,7 +2354,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2346
2354
|
if (!isPojo(processedRule)) return "";
|
|
2347
2355
|
const { sql, params: customParams } = processedRule;
|
|
2348
2356
|
if (typeof sql !== "string" || !sql) return "";
|
|
2349
|
-
//
|
|
2357
|
+
// v8 ignore else
|
|
2350
2358
|
if (format === "parameterized" && Array.isArray(customParams)) params.push(...customParams);
|
|
2351
2359
|
else if (format === "parameterized_named" && isPojo(customParams)) {
|
|
2352
2360
|
Object.assign(paramsNamed, customParams);
|
|
@@ -2355,7 +2363,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2355
2363
|
return sql;
|
|
2356
2364
|
};
|
|
2357
2365
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2358
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2366
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2359
2367
|
const processedRules = [];
|
|
2360
2368
|
let precedingCombinator = "";
|
|
2361
2369
|
let firstRule = true;
|
|
@@ -2366,7 +2374,7 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
|
|
|
2366
2374
|
}
|
|
2367
2375
|
if (isRuleGroup(rule)) {
|
|
2368
2376
|
const processedGroup = processRuleGroup(rule, rg.rules.length === 1);
|
|
2369
|
-
//
|
|
2377
|
+
// v8 ignore else
|
|
2370
2378
|
if (processedGroup) {
|
|
2371
2379
|
if (!firstRule && precedingCombinator) {
|
|
2372
2380
|
processedRules.push(precedingCombinator);
|
|
@@ -2449,10 +2457,10 @@ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
|
|
|
2449
2457
|
* @group Export
|
|
2450
2458
|
*/
|
|
2451
2459
|
const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
2452
|
-
//
|
|
2460
|
+
// v8 ignore next
|
|
2453
2461
|
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap, context = {} } = options;
|
|
2454
2462
|
const { sequelizeOperators: Op } = context;
|
|
2455
|
-
if (!Op) return;
|
|
2463
|
+
if (!Op) return void 0;
|
|
2456
2464
|
const processRuleGroup = (rg, _outermost) => {
|
|
2457
2465
|
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return;
|
|
2458
2466
|
const combinator = rg.combinator.toUpperCase();
|
|
@@ -2475,7 +2483,7 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
|
2475
2483
|
fieldData
|
|
2476
2484
|
});
|
|
2477
2485
|
}).filter(Boolean);
|
|
2478
|
-
if (expressions.length === 0) return;
|
|
2486
|
+
if (expressions.length === 0) return void 0;
|
|
2479
2487
|
const result = expressions.length === 1 && !hasChildRules ? expressions[0] : { [lc(combinator) === "or" ? Op.or : Op.and]: expressions };
|
|
2480
2488
|
return rg.not ? { [Op.not]: result } : result;
|
|
2481
2489
|
};
|
|
@@ -2491,7 +2499,7 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
|
|
|
2491
2499
|
const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
2492
2500
|
const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
|
|
2493
2501
|
const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
|
|
2494
|
-
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
|
|
2502
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : /* v8 ignore next -- @preserve */ "";
|
|
2495
2503
|
const processedRules = [];
|
|
2496
2504
|
let precedingCombinator = "";
|
|
2497
2505
|
let firstRule = true;
|
|
@@ -2502,7 +2510,7 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
2502
2510
|
}
|
|
2503
2511
|
if (isRuleGroup(rule)) {
|
|
2504
2512
|
const processedGroup = processRuleGroup(rule, rg.rules.length === 1);
|
|
2505
|
-
//
|
|
2513
|
+
// v8 ignore else
|
|
2506
2514
|
if (processedGroup) {
|
|
2507
2515
|
if (!firstRule && precedingCombinator) {
|
|
2508
2516
|
processedRules.push(precedingCombinator);
|
|
@@ -2538,6 +2546,325 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
2538
2546
|
return processRuleGroup(ruleGroup, true);
|
|
2539
2547
|
};
|
|
2540
2548
|
//#endregion
|
|
2549
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorDiagnostics.ts
|
|
2550
|
+
const numericInputTypes = new Set([
|
|
2551
|
+
"number",
|
|
2552
|
+
"range",
|
|
2553
|
+
"bigint"
|
|
2554
|
+
]);
|
|
2555
|
+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
2556
|
+
const timeRegex = /^\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/;
|
|
2557
|
+
const monthRegex = /^\d{4}-\d{2}$/;
|
|
2558
|
+
const weekRegex = /^\d{4}-W\d{2}$/;
|
|
2559
|
+
const colorRegex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
2560
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2561
|
+
const isValidDateComponents = (y, m, d) => {
|
|
2562
|
+
const date = new Date(Date.UTC(y, m - 1, d));
|
|
2563
|
+
return date.getUTCFullYear() === y && date.getUTCMonth() === m - 1 && date.getUTCDate() === d;
|
|
2564
|
+
};
|
|
2565
|
+
const isValidTimeComponents = (s) => {
|
|
2566
|
+
const parts = s.split(":");
|
|
2567
|
+
const h = Number(parts[0]);
|
|
2568
|
+
const m = Number(parts[1]);
|
|
2569
|
+
const sec = parts[2] ? Number.parseFloat(parts[2]) : 0;
|
|
2570
|
+
return h >= 0 && h <= 23 && m >= 0 && m <= 59 && sec >= 0 && sec < 60;
|
|
2571
|
+
};
|
|
2572
|
+
/**
|
|
2573
|
+
* Checks whether a value is compatible with the given {@link FullField.inputType}.
|
|
2574
|
+
* Returns a diagnostic code string if there is a mismatch, or `undefined` if OK.
|
|
2575
|
+
*/
|
|
2576
|
+
const checkValueTypeMismatch = (value, inputType) => {
|
|
2577
|
+
if (value === null || value === void 0 || value === "") return void 0;
|
|
2578
|
+
if (numericInputTypes.has(inputType)) {
|
|
2579
|
+
const v = typeof value === "string" ? value.trim() : value;
|
|
2580
|
+
if (typeof v === "number" || typeof v === "bigint") return void 0;
|
|
2581
|
+
if (typeof v === "string" && numericRegex.test(v)) return void 0;
|
|
2582
|
+
return "VALUE_TYPE_MISMATCH";
|
|
2583
|
+
}
|
|
2584
|
+
if (inputType === "date") {
|
|
2585
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2586
|
+
const v = value.trim();
|
|
2587
|
+
if (!dateRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2588
|
+
const [y, m, d] = v.split("-").map(Number);
|
|
2589
|
+
return isValidDateComponents(y, m, d) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2590
|
+
}
|
|
2591
|
+
if (inputType === "datetime-local") {
|
|
2592
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2593
|
+
const base = value.trim().replace(/(Z|[+-]\d{2}:?\d{2}|[+-]\d{2})$/, "");
|
|
2594
|
+
const tIndex = base.indexOf("T");
|
|
2595
|
+
if (tIndex === -1) return "VALUE_TYPE_MISMATCH";
|
|
2596
|
+
const datePart = base.slice(0, tIndex);
|
|
2597
|
+
const timePart = base.slice(tIndex + 1);
|
|
2598
|
+
if (!dateRegex.test(datePart) || !timeRegex.test(timePart)) return "VALUE_TYPE_MISMATCH";
|
|
2599
|
+
const [y, m, d] = datePart.split("-").map(Number);
|
|
2600
|
+
if (!isValidDateComponents(y, m, d)) return "VALUE_TYPE_MISMATCH";
|
|
2601
|
+
return isValidTimeComponents(timePart) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2602
|
+
}
|
|
2603
|
+
if (inputType === "time") {
|
|
2604
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2605
|
+
const v = value.trim();
|
|
2606
|
+
if (!timeRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2607
|
+
return isValidTimeComponents(v) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2608
|
+
}
|
|
2609
|
+
if (inputType === "month") {
|
|
2610
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2611
|
+
const v = value.trim();
|
|
2612
|
+
if (!monthRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2613
|
+
const m = Number(v.slice(5));
|
|
2614
|
+
return m >= 1 && m <= 12 ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2615
|
+
}
|
|
2616
|
+
if (inputType === "week") {
|
|
2617
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2618
|
+
const v = value.trim();
|
|
2619
|
+
if (!weekRegex.test(v)) return "VALUE_TYPE_MISMATCH";
|
|
2620
|
+
const w = Number(v.slice(6));
|
|
2621
|
+
return w >= 1 && w <= 53 ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2622
|
+
}
|
|
2623
|
+
if (inputType === "color") {
|
|
2624
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2625
|
+
return colorRegex.test(value.trim()) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2626
|
+
}
|
|
2627
|
+
if (inputType === "url") {
|
|
2628
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2629
|
+
try {
|
|
2630
|
+
new URL(value.trim());
|
|
2631
|
+
return;
|
|
2632
|
+
} catch {
|
|
2633
|
+
return "VALUE_TYPE_MISMATCH";
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
if (inputType === "email") {
|
|
2637
|
+
if (typeof value !== "string") return "VALUE_TYPE_MISMATCH";
|
|
2638
|
+
return emailRegex.test(value.trim()) ? void 0 : "VALUE_TYPE_MISMATCH";
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
/**
|
|
2642
|
+
* Rule group processor used by {@link formatQuery} for "diagnostics" format.
|
|
2643
|
+
*
|
|
2644
|
+
* Produces a {@link DiagnosticsResult} containing an annotated copy of the query
|
|
2645
|
+
* tree (`query`) with `valid`, `reasons`, `path`, and `level` properties on every
|
|
2646
|
+
* rule and group; a flat `diagnostics` array; aggregate `stats`; and a per-field
|
|
2647
|
+
* `fieldSummary`.
|
|
2648
|
+
*
|
|
2649
|
+
* @group Export
|
|
2650
|
+
*/
|
|
2651
|
+
const defaultRuleGroupProcessorDiagnostics = (ruleGroup, options) => {
|
|
2652
|
+
const { fields: fieldsOption, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap } = options;
|
|
2653
|
+
const diagnostics = [];
|
|
2654
|
+
const stats = {
|
|
2655
|
+
totalRules: 0,
|
|
2656
|
+
totalGroups: 0,
|
|
2657
|
+
validRules: 0,
|
|
2658
|
+
invalidRules: 0,
|
|
2659
|
+
validGroups: 0,
|
|
2660
|
+
invalidGroups: 0
|
|
2661
|
+
};
|
|
2662
|
+
const fieldSummary = {};
|
|
2663
|
+
const uniqueFields = toFlatOptionArray(fieldsOption);
|
|
2664
|
+
const fieldsByName = /* @__PURE__ */ new Map();
|
|
2665
|
+
for (const f of uniqueFields) fieldsByName.set(f.name, f);
|
|
2666
|
+
const hasFieldsConfig = fieldsByName.size > 0;
|
|
2667
|
+
const processRuleGroup = (rg, path) => {
|
|
2668
|
+
stats.totalGroups++;
|
|
2669
|
+
const level = path.length;
|
|
2670
|
+
const groupValidationEntry = validationMap[rg.id ?? ""];
|
|
2671
|
+
const groupSelfValid = isRuleOrGroupValid(rg, groupValidationEntry);
|
|
2672
|
+
const groupReasons = getReasons(groupValidationEntry);
|
|
2673
|
+
if (rg.muted) diagnostics.push({
|
|
2674
|
+
id: rg.id ?? "",
|
|
2675
|
+
path,
|
|
2676
|
+
code: "MUTED",
|
|
2677
|
+
message: "Group is muted",
|
|
2678
|
+
source: "muted"
|
|
2679
|
+
});
|
|
2680
|
+
else if (!groupSelfValid && groupValidationEntry !== void 0) diagnostics.push({
|
|
2681
|
+
id: rg.id ?? "",
|
|
2682
|
+
path,
|
|
2683
|
+
code: "CUSTOM_VALIDATOR",
|
|
2684
|
+
message: groupReasons ? `Invalid: ${groupReasons.join(", ")}` : "Group failed validation",
|
|
2685
|
+
source: "query-validator"
|
|
2686
|
+
});
|
|
2687
|
+
let allChildrenValid = true;
|
|
2688
|
+
let ruleIndex = 0;
|
|
2689
|
+
const annotatedRules = [];
|
|
2690
|
+
for (const rule of rg.rules) {
|
|
2691
|
+
if (typeof rule === "string") {
|
|
2692
|
+
annotatedRules.push(rule);
|
|
2693
|
+
ruleIndex++;
|
|
2694
|
+
continue;
|
|
2695
|
+
}
|
|
2696
|
+
const childPath = [...path, ruleIndex];
|
|
2697
|
+
if (isRuleGroup(rule)) {
|
|
2698
|
+
const annotatedGroup = processRuleGroup(rule, childPath);
|
|
2699
|
+
if (!annotatedGroup.valid) allChildrenValid = false;
|
|
2700
|
+
annotatedRules.push(annotatedGroup);
|
|
2701
|
+
ruleIndex++;
|
|
2702
|
+
continue;
|
|
2703
|
+
}
|
|
2704
|
+
stats.totalRules++;
|
|
2705
|
+
const childLevel = childPath.length;
|
|
2706
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
2707
|
+
const ruleValid = isRuleOrGroupValid(rule, validationResult, fieldValidator) && rule.field !== placeholderFieldName && rule.operator !== placeholderOperatorName && !(placeholderValueName !== void 0 && rule.value === placeholderValueName);
|
|
2708
|
+
collectRuleDiagnostics(rule, childPath, validationResult, fieldValidator, ruleValid, diagnostics, placeholderFieldName, placeholderOperatorName, placeholderValueName, hasFieldsConfig, fieldsByName);
|
|
2709
|
+
if (!ruleValid) {
|
|
2710
|
+
allChildrenValid = false;
|
|
2711
|
+
stats.invalidRules++;
|
|
2712
|
+
} else stats.validRules++;
|
|
2713
|
+
const fieldName = rule.field;
|
|
2714
|
+
if (!fieldSummary[fieldName]) fieldSummary[fieldName] = {
|
|
2715
|
+
ruleCount: 0,
|
|
2716
|
+
invalidCount: 0
|
|
2717
|
+
};
|
|
2718
|
+
fieldSummary[fieldName].ruleCount++;
|
|
2719
|
+
if (!ruleValid) fieldSummary[fieldName].invalidCount++;
|
|
2720
|
+
const ruleReasons = getReasons(validationResult) ?? getFieldValidatorReasons(rule, fieldValidator);
|
|
2721
|
+
const annotatedRule = {
|
|
2722
|
+
...rule,
|
|
2723
|
+
valid: ruleValid,
|
|
2724
|
+
...ruleReasons ? { reasons: ruleReasons } : null,
|
|
2725
|
+
path: childPath,
|
|
2726
|
+
level: childLevel
|
|
2727
|
+
};
|
|
2728
|
+
annotatedRules.push(annotatedRule);
|
|
2729
|
+
ruleIndex++;
|
|
2730
|
+
}
|
|
2731
|
+
const groupValid = groupSelfValid && allChildrenValid;
|
|
2732
|
+
if (groupValid) stats.validGroups++;
|
|
2733
|
+
else stats.invalidGroups++;
|
|
2734
|
+
if (isRuleGroupType(rg)) return {
|
|
2735
|
+
...rg,
|
|
2736
|
+
valid: groupValid,
|
|
2737
|
+
...groupReasons ? { reasons: groupReasons } : null,
|
|
2738
|
+
path,
|
|
2739
|
+
level,
|
|
2740
|
+
rules: annotatedRules
|
|
2741
|
+
};
|
|
2742
|
+
return {
|
|
2743
|
+
...rg,
|
|
2744
|
+
valid: groupValid,
|
|
2745
|
+
...groupReasons ? { reasons: groupReasons } : null,
|
|
2746
|
+
path,
|
|
2747
|
+
level,
|
|
2748
|
+
rules: annotatedRules
|
|
2749
|
+
};
|
|
2750
|
+
};
|
|
2751
|
+
const query = processRuleGroup(ruleGroup, []);
|
|
2752
|
+
if (hasFieldsConfig) {
|
|
2753
|
+
const referencedFields = new Set(Object.keys(fieldSummary));
|
|
2754
|
+
for (const [fieldName] of fieldsByName) if (!referencedFields.has(fieldName)) diagnostics.push({
|
|
2755
|
+
id: "",
|
|
2756
|
+
path: [],
|
|
2757
|
+
code: "UNREFERENCED_FIELD",
|
|
2758
|
+
message: `Field "${fieldName}" is defined in the fields config but not used in the query`,
|
|
2759
|
+
source: "field-check"
|
|
2760
|
+
});
|
|
2761
|
+
}
|
|
2762
|
+
return {
|
|
2763
|
+
query,
|
|
2764
|
+
diagnostics,
|
|
2765
|
+
stats,
|
|
2766
|
+
fieldSummary
|
|
2767
|
+
};
|
|
2768
|
+
};
|
|
2769
|
+
/**
|
|
2770
|
+
* Collects diagnostic entries for a single rule.
|
|
2771
|
+
*/
|
|
2772
|
+
const collectRuleDiagnostics = (rule, path, validationResult, fieldValidator, ruleValid, diagnostics, placeholderFieldName, placeholderOperatorName, placeholderValueName, hasFieldsConfig, fieldsByName) => {
|
|
2773
|
+
const id = rule.id ?? "";
|
|
2774
|
+
if (rule.muted) diagnostics.push({
|
|
2775
|
+
id,
|
|
2776
|
+
path,
|
|
2777
|
+
code: "MUTED",
|
|
2778
|
+
message: "Rule is muted",
|
|
2779
|
+
source: "muted"
|
|
2780
|
+
});
|
|
2781
|
+
if (rule.field === placeholderFieldName) diagnostics.push({
|
|
2782
|
+
id,
|
|
2783
|
+
path,
|
|
2784
|
+
code: "PLACEHOLDER_FIELD",
|
|
2785
|
+
message: "Rule has a placeholder field",
|
|
2786
|
+
source: "placeholder"
|
|
2787
|
+
});
|
|
2788
|
+
if (rule.operator === placeholderOperatorName) diagnostics.push({
|
|
2789
|
+
id,
|
|
2790
|
+
path,
|
|
2791
|
+
code: "PLACEHOLDER_OPERATOR",
|
|
2792
|
+
message: "Rule has a placeholder operator",
|
|
2793
|
+
source: "placeholder"
|
|
2794
|
+
});
|
|
2795
|
+
if (placeholderValueName !== void 0 && rule.value === placeholderValueName) diagnostics.push({
|
|
2796
|
+
id,
|
|
2797
|
+
path,
|
|
2798
|
+
code: "PLACEHOLDER_VALUE",
|
|
2799
|
+
message: "Rule has a placeholder value",
|
|
2800
|
+
source: "placeholder"
|
|
2801
|
+
});
|
|
2802
|
+
if (!rule.muted && rule.field !== placeholderFieldName && rule.operator !== placeholderOperatorName && !(placeholderValueName !== void 0 && rule.value === placeholderValueName)) {
|
|
2803
|
+
if (typeof validationResult === "boolean" && !validationResult) diagnostics.push({
|
|
2804
|
+
id,
|
|
2805
|
+
path,
|
|
2806
|
+
code: "CUSTOM_VALIDATOR",
|
|
2807
|
+
message: "Rule failed validation",
|
|
2808
|
+
source: "query-validator"
|
|
2809
|
+
});
|
|
2810
|
+
else if (typeof validationResult !== "boolean" && isValidationResult(validationResult) && !validationResult.valid) {
|
|
2811
|
+
const reasons = validationResult.reasons;
|
|
2812
|
+
diagnostics.push({
|
|
2813
|
+
id,
|
|
2814
|
+
path,
|
|
2815
|
+
code: "CUSTOM_VALIDATOR",
|
|
2816
|
+
message: reasons ? `Invalid: ${reasons.join(", ")}` : "Rule failed validation",
|
|
2817
|
+
source: "query-validator"
|
|
2818
|
+
});
|
|
2819
|
+
} else if (!ruleValid && typeof fieldValidator === "function") {
|
|
2820
|
+
const vr = fieldValidator(rule);
|
|
2821
|
+
const reasons = typeof vr !== "boolean" && isValidationResult(vr) && !vr.valid ? vr.reasons : void 0;
|
|
2822
|
+
diagnostics.push({
|
|
2823
|
+
id,
|
|
2824
|
+
path,
|
|
2825
|
+
code: "CUSTOM_VALIDATOR",
|
|
2826
|
+
message: reasons ? `Invalid: ${reasons.join(", ")}` : "Rule failed field validation",
|
|
2827
|
+
source: "field-validator"
|
|
2828
|
+
});
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
if (hasFieldsConfig && !fieldsByName.has(rule.field) && rule.field !== placeholderFieldName) diagnostics.push({
|
|
2832
|
+
id,
|
|
2833
|
+
path,
|
|
2834
|
+
code: "UNDEFINED_FIELD",
|
|
2835
|
+
message: `Field "${rule.field}" is not defined in the fields config`,
|
|
2836
|
+
source: "field-check"
|
|
2837
|
+
});
|
|
2838
|
+
if (hasFieldsConfig) {
|
|
2839
|
+
const fieldDef = fieldsByName.get(rule.field);
|
|
2840
|
+
if (fieldDef?.inputType) {
|
|
2841
|
+
const mismatchCode = checkValueTypeMismatch(rule.value, fieldDef.inputType);
|
|
2842
|
+
if (mismatchCode) diagnostics.push({
|
|
2843
|
+
id,
|
|
2844
|
+
path,
|
|
2845
|
+
code: mismatchCode,
|
|
2846
|
+
message: `Value "${rule.value}" is not compatible with input type "${fieldDef.inputType}"`,
|
|
2847
|
+
source: "type-check"
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
/**
|
|
2853
|
+
* Extracts `reasons` from a validation result, if present.
|
|
2854
|
+
*/
|
|
2855
|
+
const getReasons = (validationResult) => {
|
|
2856
|
+
if (typeof validationResult !== "boolean" && isValidationResult(validationResult) && !validationResult.valid && validationResult.reasons) return validationResult.reasons;
|
|
2857
|
+
};
|
|
2858
|
+
/**
|
|
2859
|
+
* Runs a field-level validator and extracts `reasons` if present.
|
|
2860
|
+
*/
|
|
2861
|
+
const getFieldValidatorReasons = (rule, fieldValidator) => {
|
|
2862
|
+
if (typeof fieldValidator === "function") {
|
|
2863
|
+
const vr = fieldValidator(rule);
|
|
2864
|
+
if (typeof vr !== "boolean" && isValidationResult(vr) && !vr.valid && vr.reasons) return vr.reasons;
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
//#endregion
|
|
2541
2868
|
//#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
|
|
2542
2869
|
const rangeOperatorMap = {
|
|
2543
2870
|
"<": "lt",
|
|
@@ -2916,12 +3243,12 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
|
|
|
2916
3243
|
return negateIf(`(&(${field}>=${ldapEscape(firstValue)})(${field}<=${ldapEscape(secondValue)}))`, operatorLC === "notbetween");
|
|
2917
3244
|
}
|
|
2918
3245
|
}
|
|
2919
|
-
//
|
|
3246
|
+
// v8 ignore next
|
|
2920
3247
|
return "";
|
|
2921
3248
|
};
|
|
2922
3249
|
//#endregion
|
|
2923
3250
|
//#region src/utils/formatQuery/defaultValueProcessorNL.ts
|
|
2924
|
-
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
|
|
3251
|
+
const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : /* v8 ignore next -- @preserve */ v;
|
|
2925
3252
|
/**
|
|
2926
3253
|
* Default value processor used by {@link formatQuery} for "natural_language" format.
|
|
2927
3254
|
*
|
|
@@ -2939,7 +3266,7 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
2939
3266
|
quoteFieldNamesWith,
|
|
2940
3267
|
fieldIdentifierSeparator
|
|
2941
3268
|
});
|
|
2942
|
-
const t = translations ?? ( /*
|
|
3269
|
+
const t = translations ?? ( /* v8 ignore start -- @preserve */ {});
|
|
2943
3270
|
const orTL = t.or ?? "or";
|
|
2944
3271
|
const trueTL = t.true ?? "true";
|
|
2945
3272
|
const falseTL = t.false ?? "false";
|
|
@@ -2995,7 +3322,7 @@ const defaultExportOperatorMap = {
|
|
|
2995
3322
|
between: ["is between", "is between the values in"],
|
|
2996
3323
|
notbetween: ["is not between", "is not between the values in"]
|
|
2997
3324
|
};
|
|
2998
|
-
/*
|
|
3325
|
+
/* v8 ignore next -- @preserve */
|
|
2999
3326
|
const defaultGetOperators = () => [];
|
|
3000
3327
|
/**
|
|
3001
3328
|
* Default operator processor used by {@link formatQuery} for "natural_language" format.
|
|
@@ -3004,7 +3331,7 @@ const defaultGetOperators = () => [];
|
|
|
3004
3331
|
*/
|
|
3005
3332
|
const defaultOperatorProcessorNL = (rule, opts = {}) => {
|
|
3006
3333
|
const { field, operator, valueSource = "value" } = rule;
|
|
3007
|
-
//
|
|
3334
|
+
// v8 ignore next
|
|
3008
3335
|
const { getOperators = defaultGetOperators, operatorMap: operatorMapParam = defaultExportOperatorMap } = opts;
|
|
3009
3336
|
const mergedOperatorMap = new Map(Object.entries(defaultExportOperatorMap));
|
|
3010
3337
|
for (const [key, value] of Object.entries(operatorMapParam)) mergedOperatorMap.set(lc(key), value);
|
|
@@ -3033,8 +3360,8 @@ const defaultOperatorProcessorNL = (rule, opts = {}) => {
|
|
|
3033
3360
|
*/
|
|
3034
3361
|
const defaultRuleProcessorNL = (rule, opts) => {
|
|
3035
3362
|
const { field, operator } = rule;
|
|
3036
|
-
//
|
|
3037
|
-
const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorNL, valueProcessor = defaultValueProcessorNL, concatOperator = "||", wordOrder = "SVO" } = opts ?? ( /*
|
|
3363
|
+
// v8 ignore next
|
|
3364
|
+
const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorNL, valueProcessor = defaultValueProcessorNL, concatOperator = "||", wordOrder = "SVO" } = opts ?? ( /* v8 ignore start -- @preserve */ {});
|
|
3038
3365
|
const processedField = getQuotedFieldName(fieldData?.label ?? field, {
|
|
3039
3366
|
quoteFieldNamesWith,
|
|
3040
3367
|
fieldIdentifierSeparator
|
|
@@ -3140,7 +3467,7 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
|
|
|
3140
3467
|
* @group Export
|
|
3141
3468
|
*/
|
|
3142
3469
|
const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
3143
|
-
//
|
|
3470
|
+
// v8 ignore next
|
|
3144
3471
|
const { fieldData, format, getNextNamedParam, parseNumbers, paramPrefix, paramsKeepPrefix, numberedParams, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator, concatOperator, operatorProcessor = defaultOperatorProcessorSQL, valueProcessor = defaultValueProcessorByRule } = opts ?? {};
|
|
3145
3472
|
const { processedParams = [] } = meta ?? {};
|
|
3146
3473
|
const parameterized = format === "parameterized";
|
|
@@ -3159,6 +3486,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3159
3486
|
});
|
|
3160
3487
|
const ruleField = wrapFieldName(rule.field);
|
|
3161
3488
|
const matchEval = processMatchMode(rule);
|
|
3489
|
+
/* v8 ignore start -- @preserve */
|
|
3162
3490
|
if (matchEval === false) return;
|
|
3163
3491
|
else if (matchEval) {
|
|
3164
3492
|
if (opts?.preset !== "postgresql") return finalize("");
|
|
@@ -3171,7 +3499,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3171
3499
|
...opts,
|
|
3172
3500
|
fields: []
|
|
3173
3501
|
});
|
|
3174
|
-
// istanbul ignore else
|
|
3175
3502
|
if (Array.isArray(nestedParams)) params.push(...nestedParams);
|
|
3176
3503
|
else Object.assign(paramsNamed, nestedParams);
|
|
3177
3504
|
switch (mode) {
|
|
@@ -3186,6 +3513,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3186
3513
|
}
|
|
3187
3514
|
}
|
|
3188
3515
|
}
|
|
3516
|
+
/* v8 ignore stop -- @preserve */
|
|
3189
3517
|
const value = valueProcessor(rule, {
|
|
3190
3518
|
parseNumbers,
|
|
3191
3519
|
quoteFieldNamesWith,
|
|
@@ -3226,7 +3554,7 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
|
|
|
3226
3554
|
}
|
|
3227
3555
|
let paramValue = rule.value;
|
|
3228
3556
|
if (typeof rule.value === "string") if (shouldRenderAsNumber(rule.value, parseNumbers)) paramValue = parseNumber(rule.value, { parseNumbers });
|
|
3229
|
-
else paramValue = /^'.*'$/g.test(value) ? value.replaceAll(/(^'|'$)/g, "") : value;
|
|
3557
|
+
else paramValue = /^'.*'$/g.test(value) ? value.replaceAll(/(^'|'$)/g, "") : /* v8 ignore next -- @preserve */ value;
|
|
3230
3558
|
let paramName = "";
|
|
3231
3559
|
if (parameterized) params.push(paramValue);
|
|
3232
3560
|
else {
|
|
@@ -3245,9 +3573,9 @@ const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(va
|
|
|
3245
3573
|
*/
|
|
3246
3574
|
const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
3247
3575
|
const { field, operator, value, valueSource } = rule;
|
|
3248
|
-
//
|
|
3576
|
+
// v8 ignore next
|
|
3249
3577
|
const { parseNumbers, preserveValueOrder } = options;
|
|
3250
|
-
if (valueSource === "field" || processMatchMode(rule)) return;
|
|
3578
|
+
if (valueSource === "field" || processMatchMode(rule)) return void 0;
|
|
3251
3579
|
const operatorLC = lc(operator);
|
|
3252
3580
|
switch (operatorLC) {
|
|
3253
3581
|
case "=": return { [field]: processNumber(value, value, parseNumbers) };
|
|
@@ -3305,7 +3633,7 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
|
|
|
3305
3633
|
*/
|
|
3306
3634
|
const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder, context = {} } = {}) => {
|
|
3307
3635
|
const { sequelizeOperators: Op, sequelizeCol: col, sequelizeFn: fn } = context;
|
|
3308
|
-
if (processMatchMode(rule)) return;
|
|
3636
|
+
if (processMatchMode(rule)) return void 0;
|
|
3309
3637
|
const { field, operator, value, valueSource } = rule;
|
|
3310
3638
|
const valueIsField = valueSource === "field";
|
|
3311
3639
|
const operatorLC = lc(operator);
|
|
@@ -3409,9 +3737,10 @@ const defaultRuleProcessors = {
|
|
|
3409
3737
|
prisma: defaultRuleProcessorPrisma,
|
|
3410
3738
|
sequelize: defaultRuleProcessorSequelize,
|
|
3411
3739
|
spel: defaultRuleProcessorSpEL,
|
|
3412
|
-
sql: defaultRuleProcessorSQL
|
|
3740
|
+
sql: defaultRuleProcessorSQL,
|
|
3741
|
+
diagnostics: defaultRuleProcessorSQL
|
|
3413
3742
|
};
|
|
3414
|
-
/*
|
|
3743
|
+
/* v8 ignore next -- @preserve */
|
|
3415
3744
|
const defaultOperatorProcessor = (r) => r.operator;
|
|
3416
3745
|
const defaultOperatorProcessors = {
|
|
3417
3746
|
cel: defaultOperatorProcessor,
|
|
@@ -3430,7 +3759,8 @@ const defaultOperatorProcessors = {
|
|
|
3430
3759
|
prisma: defaultOperatorProcessor,
|
|
3431
3760
|
sequelize: defaultOperatorProcessor,
|
|
3432
3761
|
spel: defaultOperatorProcessor,
|
|
3433
|
-
sql: defaultOperatorProcessorSQL
|
|
3762
|
+
sql: defaultOperatorProcessorSQL,
|
|
3763
|
+
diagnostics: defaultOperatorProcessor
|
|
3434
3764
|
};
|
|
3435
3765
|
const defaultFallbackExpressions = {
|
|
3436
3766
|
cel: "1 == 1",
|
|
@@ -3504,24 +3834,26 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3504
3834
|
const getOperators = (f, m) => toFullOptionList(getOperators_option(f, m) ?? []);
|
|
3505
3835
|
const fallbackExpression = fallbackExpression_option ?? defaultFallbackExpressions[format] ?? defaultFallbackExpressions.sql;
|
|
3506
3836
|
let validationMap = {};
|
|
3507
|
-
//
|
|
3837
|
+
// v8 ignore else
|
|
3508
3838
|
if (typeof validator === "function") {
|
|
3509
3839
|
const validationResult = validator(ruleGroup);
|
|
3510
3840
|
if (typeof validationResult === "boolean") {
|
|
3511
|
-
//
|
|
3512
|
-
if (!validationResult)
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3841
|
+
// v8 ignore else
|
|
3842
|
+
if (!validationResult) {
|
|
3843
|
+
if (format !== "diagnostics") return format === "parameterized" ? {
|
|
3844
|
+
sql: fallbackExpression,
|
|
3845
|
+
params: []
|
|
3846
|
+
} : format === "parameterized_named" ? {
|
|
3847
|
+
sql: fallbackExpression,
|
|
3848
|
+
params: {}
|
|
3849
|
+
} : format === "mongodb" ? `{${fallbackExpression}}` : format === "mongodb_query" ? mongoDbFallback : format === "prisma" ? prismaFallback : format === "jsonlogic" ? false : format === "elasticsearch" ? {} : format === "drizzle" || format === "sequelize" ? void 0 : fallbackExpression;
|
|
3850
|
+
}
|
|
3519
3851
|
} else validationMap = validationResult;
|
|
3520
3852
|
}
|
|
3521
3853
|
const validatorMap = {};
|
|
3522
3854
|
const uniqueFields = toFlatOptionArray(fields);
|
|
3523
3855
|
for (const f of uniqueFields)
|
|
3524
|
-
//
|
|
3856
|
+
// v8 ignore else
|
|
3525
3857
|
if (typeof f.validator === "function") validatorMap[f.value ?? f.name] = f.validator;
|
|
3526
3858
|
const validateRule = (rule) => {
|
|
3527
3859
|
let validationResult;
|
|
@@ -3531,7 +3863,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3531
3863
|
const fieldArr = uniqueFields.filter((f) => f.name === rule.field);
|
|
3532
3864
|
if (fieldArr.length > 0) {
|
|
3533
3865
|
const field = fieldArr[0];
|
|
3534
|
-
//
|
|
3866
|
+
// v8 ignore else
|
|
3535
3867
|
if (typeof field.validator === "function") fieldValidator = field.validator;
|
|
3536
3868
|
}
|
|
3537
3869
|
}
|
|
@@ -3575,6 +3907,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
3575
3907
|
case "prisma": return defaultRuleGroupProcessorPrisma(ruleGroup, finalOptions);
|
|
3576
3908
|
case "drizzle": return defaultRuleGroupProcessorDrizzle(ruleGroup, finalOptions);
|
|
3577
3909
|
case "sequelize": return defaultRuleGroupProcessorSequelize(ruleGroup, finalOptions);
|
|
3910
|
+
case "diagnostics": return defaultRuleGroupProcessorDiagnostics(ruleGroup, finalOptions);
|
|
3578
3911
|
default: return "";
|
|
3579
3912
|
}
|
|
3580
3913
|
}
|
|
@@ -3725,6 +4058,7 @@ const generateAccessibleDescription = (params) => pathsAreEqual([], params.path)
|
|
|
3725
4058
|
//#endregion
|
|
3726
4059
|
//#region src/utils/generateID.ts
|
|
3727
4060
|
const cryptoModule = globalThis.crypto;
|
|
4061
|
+
const uuidV4regex = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
|
|
3728
4062
|
/**
|
|
3729
4063
|
* Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`
|
|
3730
4064
|
* when available, otherwise uses an alternate method based on `getRandomValues`.
|
|
@@ -3734,11 +4068,11 @@ const cryptoModule = globalThis.crypto;
|
|
|
3734
4068
|
* ```
|
|
3735
4069
|
* @returns Valid v4 UUID
|
|
3736
4070
|
*/
|
|
3737
|
-
//
|
|
4071
|
+
// v8 ignore next
|
|
3738
4072
|
let generateID = () => "00-0-4-2-000".replaceAll(/[^-]/g, (s) => ((Math.random() + Math.trunc(s)) * 65536 >> Number.parseInt(s)).toString(16).padStart(4, "0"));
|
|
3739
|
-
//
|
|
4073
|
+
// v8 ignore else
|
|
3740
4074
|
if (cryptoModule) {
|
|
3741
|
-
//
|
|
4075
|
+
// v8 ignore else
|
|
3742
4076
|
if (typeof cryptoModule.randomUUID === "function") generateID = () => cryptoModule.randomUUID();
|
|
3743
4077
|
else if (typeof cryptoModule.getRandomValues === "function") {
|
|
3744
4078
|
const position19vals = "89ab";
|
|
@@ -3771,7 +4105,7 @@ const dummyFD$1 = {
|
|
|
3771
4105
|
* `FullOption<MatchMode>[]` of all match modes by default.
|
|
3772
4106
|
*/
|
|
3773
4107
|
const getMatchModesUtil = (fieldData, getMatchModes) => {
|
|
3774
|
-
const fd = fieldData ? toFullOption(fieldData) : dummyFD$1;
|
|
4108
|
+
const fd = fieldData ? toFullOption(fieldData) : /* v8 ignore next -- @preserve */ dummyFD$1;
|
|
3775
4109
|
let matchModes = fd.matchModes ?? false;
|
|
3776
4110
|
if (!matchModes && getMatchModes) matchModes = getMatchModes(fd.value, { fieldData: fd });
|
|
3777
4111
|
if (matchModes === true) return defaultMatchModes;
|
|
@@ -3833,7 +4167,7 @@ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
|
|
|
3833
4167
|
const mergeAnyTranslations = (base, ...otherTranslations) => {
|
|
3834
4168
|
const result = { ...base };
|
|
3835
4169
|
for (const translations of otherTranslations)
|
|
3836
|
-
//
|
|
4170
|
+
// v8 ignore else
|
|
3837
4171
|
if (translations) for (const key of objectKeys(translations)) {
|
|
3838
4172
|
if (isUnsafeKey(key)) continue;
|
|
3839
4173
|
if (result[key]) result[key] = {
|
|
@@ -3894,6 +4228,8 @@ const mergeClassnames = (...args) => ({
|
|
|
3894
4228
|
dndCopy: joinClassnamesByName("dndCopy", args),
|
|
3895
4229
|
dndGroup: joinClassnamesByName("dndGroup", args),
|
|
3896
4230
|
dndDropNotAllowed: joinClassnamesByName("dndDropNotAllowed", args),
|
|
4231
|
+
dndPreviewPosition: joinClassnamesByName("dndPreviewPosition", args),
|
|
4232
|
+
dndHidden: joinClassnamesByName("dndHidden", args),
|
|
3897
4233
|
disabled: joinClassnamesByName("disabled", args),
|
|
3898
4234
|
valueListItem: joinClassnamesByName("valueListItem", args),
|
|
3899
4235
|
matchMode: joinClassnamesByName("matchMode", args),
|
|
@@ -3989,7 +4325,7 @@ const regenerateIDs = (subject, { idGenerator = generateID } = {}) => {
|
|
|
3989
4325
|
...subject,
|
|
3990
4326
|
id: idGenerator()
|
|
3991
4327
|
};
|
|
3992
|
-
//
|
|
4328
|
+
// v8 ignore else
|
|
3993
4329
|
if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
|
|
3994
4330
|
return newGroup;
|
|
3995
4331
|
};
|
|
@@ -4321,6 +4657,7 @@ exports.defaultPlaceholderValueGroupLabel = defaultPlaceholderValueGroupLabel;
|
|
|
4321
4657
|
exports.defaultPlaceholderValueLabel = defaultPlaceholderValueLabel;
|
|
4322
4658
|
exports.defaultPlaceholderValueName = defaultPlaceholderValueName;
|
|
4323
4659
|
exports.defaultRuleGroupProcessorCEL = defaultRuleGroupProcessorCEL;
|
|
4660
|
+
exports.defaultRuleGroupProcessorDiagnostics = defaultRuleGroupProcessorDiagnostics;
|
|
4324
4661
|
exports.defaultRuleGroupProcessorDrizzle = defaultRuleGroupProcessorDrizzle;
|
|
4325
4662
|
exports.defaultRuleGroupProcessorElasticSearch = defaultRuleGroupProcessorElasticSearch;
|
|
4326
4663
|
exports.defaultRuleGroupProcessorJSONata = defaultRuleGroupProcessorJSONata;
|
|
@@ -4456,5 +4793,6 @@ exports.uniqOptGroups = uniqOptGroups;
|
|
|
4456
4793
|
exports.uniqOptList = uniqOptList;
|
|
4457
4794
|
exports.update = update;
|
|
4458
4795
|
exports.updateInPlace = updateInPlace;
|
|
4796
|
+
exports.uuidV4regex = uuidV4regex;
|
|
4459
4797
|
|
|
4460
4798
|
//# sourceMappingURL=react-querybuilder_core.cjs.development.js.map
|