react-querybuilder
Advanced tools
Comparing version 7.1.0 to 7.2.0
@@ -1,2 +0,2 @@ | ||
import { R as RuleProcessor, V as ValueProcessorByRule, F as FormatQueryOptions, P as ParameterizedSQL, a as ParameterizedNamedSQL, b as RQBJsonLogic, E as ExportFormat, c as ValueProcessorLegacy } from './importExport-C0h8KkL7.js'; | ||
import { R as RuleProcessor, V as ValueProcessorByRule, F as FormatQueryOptions, P as ParameterizedSQL, a as ParameterizedNamedSQL, b as RQBJsonLogic, E as ExportFormat, c as ValueProcessorLegacy } from './importExport-DT0uMCJu.js'; | ||
import { R as RuleGroupTypeAny } from './basic-CtWU1IF_.js'; | ||
@@ -32,2 +32,7 @@ import 'json-logic-js'; | ||
/** | ||
* Default rule processor used by {@link formatQuery} for "jsonata" format. | ||
*/ | ||
declare const defaultRuleProcessorJSONata: RuleProcessor; | ||
/** | ||
* Default rule processor used by {@link formatQuery} for "jsonlogic" format. | ||
@@ -80,2 +85,10 @@ */ | ||
/** | ||
* Generates a JSONata query string from an RQB query object. | ||
* | ||
* NOTE: The `parseNumbers` option is recommended for this format. | ||
*/ | ||
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: 'jsonata' | (Omit<FormatQueryOptions, 'format'> & { | ||
format: 'jsonata'; | ||
})): string; | ||
/** | ||
* Generates a formatted (indented two spaces) JSON string from a query object. | ||
@@ -87,3 +100,3 @@ */ | ||
*/ | ||
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: Exclude<ExportFormat, 'parameterized' | 'parameterized_named' | 'jsonlogic' | 'elasticsearch'>): string; | ||
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: Exclude<ExportFormat, 'parameterized' | 'parameterized_named' | 'jsonlogic' | 'elasticsearch' | 'jsonata'>): string; | ||
/** | ||
@@ -93,3 +106,3 @@ * Generates a query string in the requested format. | ||
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: Omit<FormatQueryOptions, 'format'> & { | ||
format: Exclude<ExportFormat, 'parameterized' | 'parameterized_named' | 'jsonlogic' | 'elasticsearch'>; | ||
format: Exclude<ExportFormat, 'parameterized' | 'parameterized_named' | 'jsonlogic' | 'elasticsearch' | 'jsonata'>; | ||
}): string; | ||
@@ -144,2 +157,2 @@ | ||
export { defaultCELValueProcessor, defaultMongoDBValueProcessor, defaultRuleProcessorCEL, defaultRuleProcessorElasticSearch, defaultRuleProcessorJsonLogic, defaultRuleProcessorMongoDB, defaultRuleProcessorParameterized, defaultRuleProcessorSQL, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorSpELByRule, formatQuery, jsonLogicAdditionalOperators }; | ||
export { defaultCELValueProcessor, defaultMongoDBValueProcessor, defaultRuleProcessorCEL, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorMongoDB, defaultRuleProcessorParameterized, defaultRuleProcessorSQL, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorSpELByRule, formatQuery, jsonLogicAdditionalOperators }; |
@@ -27,2 +27,3 @@ "use strict"; | ||
defaultRuleProcessorElasticSearch: () => defaultRuleProcessorElasticSearch, | ||
defaultRuleProcessorJSONata: () => defaultRuleProcessorJSONata, | ||
defaultRuleProcessorJsonLogic: () => defaultRuleProcessorJsonLogic, | ||
@@ -166,2 +167,3 @@ defaultRuleProcessorMongoDB: () => defaultRuleProcessorMongoDB, | ||
var quoteFieldNamesWithArray = (quoteFieldNamesWith = ["", ""]) => Array.isArray(quoteFieldNamesWith) ? quoteFieldNamesWith : typeof quoteFieldNamesWith === "string" ? [quoteFieldNamesWith, quoteFieldNamesWith] : quoteFieldNamesWith ?? ["", ""]; | ||
var nullOrUndefinedOrEmpty = (v) => v === null || typeof v === "undefined" || v === ""; | ||
@@ -185,14 +187,14 @@ // src/utils/formatQuery/defaultRuleProcessorCEL.ts | ||
case "doesNotContain": { | ||
const negate = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate}${field}.contains(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
const negate2 = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate2}${field}.contains(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
} | ||
case "beginsWith": | ||
case "doesNotBeginWith": { | ||
const negate = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate}${field}.startsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
const negate2 = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate2}${field}.startsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
} | ||
case "endsWith": | ||
case "doesNotEndWith": { | ||
const negate = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate}${field}.endsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
const negate2 = shouldNegate(operatorTL) ? "!" : ""; | ||
return `${negate2}${field}.endsWith(${valueIsField ? trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`; | ||
} | ||
@@ -205,8 +207,8 @@ case "null": | ||
case "notIn": { | ||
const negate = shouldNegate(operatorTL); | ||
const negate2 = shouldNegate(operatorTL); | ||
const valueAsArray = toArray(value); | ||
if (valueAsArray.length > 0) { | ||
return `${negate ? "!(" : ""}${field} in [${valueAsArray.map( | ||
return `${negate2 ? "!(" : ""}${field} in [${valueAsArray.map( | ||
(val) => valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `"${escapeDoubleQuotes(val, escapeQuotes)}"` | ||
).join(", ")}]${negate ? ")" : ""}`; | ||
).join(", ")}]${negate2 ? ")" : ""}`; | ||
} else { | ||
@@ -219,3 +221,3 @@ return ""; | ||
const valueAsArray = toArray(value); | ||
if (valueAsArray.length >= 2 && !!valueAsArray[0] && !!valueAsArray[1]) { | ||
if (valueAsArray.length >= 2 && !nullOrUndefinedOrEmpty(valueAsArray[0]) && !nullOrUndefinedOrEmpty(valueAsArray[1])) { | ||
const [first, second] = valueAsArray; | ||
@@ -313,3 +315,3 @@ const firstNum = shouldRenderAsNumber(first, true) ? parseNumber(first, { parseNumbers: true }) : NaN; | ||
var shouldNegate2 = (op) => /^(does)?not/i.test(op); | ||
var wrapInNegation = (clause, negate) => negate ? `!(${clause})` : `${clause}`; | ||
var wrapInNegation = (clause, negate2) => negate2 ? `!(${clause})` : `${clause}`; | ||
var escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? v : v.replaceAll(`'`, `\\'`); | ||
@@ -350,6 +352,6 @@ var defaultRuleProcessorSpEL = ({ field, operator, value, valueSource }, { escapeQuotes, parseNumbers } = {}) => { | ||
case "notIn": { | ||
const negate = shouldNegate2(operatorTL) ? "!" : ""; | ||
const negate2 = shouldNegate2(operatorTL) ? "!" : ""; | ||
const valueAsArray = toArray(value); | ||
if (valueAsArray.length > 0) { | ||
return `${negate}(${valueAsArray.map( | ||
return `${negate2}(${valueAsArray.map( | ||
(val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}` | ||
@@ -364,3 +366,3 @@ ).join(" or ")})`; | ||
const valueAsArray = toArray(value); | ||
if (valueAsArray.length >= 2 && !!valueAsArray[0] && !!valueAsArray[1]) { | ||
if (valueAsArray.length >= 2 && !nullOrUndefinedOrEmpty(valueAsArray[0]) && !nullOrUndefinedOrEmpty(valueAsArray[1])) { | ||
const [first, second] = valueAsArray; | ||
@@ -587,2 +589,75 @@ const firstNum = shouldRenderAsNumber(first, true) ? parseNumber(first, { parseNumbers: true }) : NaN; | ||
// src/utils/formatQuery/defaultRuleProcessorJSONata.ts | ||
var shouldNegate3 = (op) => /^(does)?not/i.test(op); | ||
var quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? v : v.replaceAll(`"`, `\\"`)}"`; | ||
var negate = (clause, negate2) => negate2 ? `$not(${clause})` : `${clause}`; | ||
var escapeStringRegex = (s) => `${s}`.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d"); | ||
var defaultRuleProcessorJSONata = ({ field, operator, value, valueSource }, { escapeQuotes, parseNumbers = true } = {}) => { | ||
const valueIsField = valueSource === "field"; | ||
const useBareValue = typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || shouldRenderAsNumber(value, parseNumbers); | ||
switch (operator) { | ||
case "<": | ||
case "<=": | ||
case "=": | ||
case "!=": | ||
case ">": | ||
case ">=": | ||
return `${field} ${operator} ${valueIsField || useBareValue ? trimIfString(value) : quote(value, escapeQuotes)}`; | ||
case "contains": | ||
case "doesNotContain": | ||
return negate( | ||
`$contains(${field}, ${valueIsField ? trimIfString(value) : quote(value, escapeQuotes)})`, | ||
shouldNegate3(operator) | ||
); | ||
case "beginsWith": | ||
case "doesNotBeginWith": | ||
return negate( | ||
valueIsField ? `$substring(${field}, 0, $length(${trimIfString(value)})) = ${trimIfString(value)}` : `$contains(${field}, /^${escapeStringRegex(value)}/)`, | ||
shouldNegate3(operator) | ||
); | ||
case "endsWith": | ||
case "doesNotEndWith": | ||
return negate( | ||
valueIsField ? `$substring(${field}, $length(${field}) - $length(${trimIfString(value)})) = ${trimIfString(value)}` : `$contains(${field}, /${escapeStringRegex(value)}$/)`, | ||
shouldNegate3(operator) | ||
); | ||
case "null": | ||
return `${field} = null`; | ||
case "notNull": | ||
return `${field} != null`; | ||
case "in": | ||
case "notIn": { | ||
const valueAsArray = toArray(value); | ||
return negate( | ||
`${field} in [${valueAsArray.map( | ||
(val) => valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : quote(val, escapeQuotes) | ||
).join(", ")}]`, | ||
shouldNegate3(operator) | ||
); | ||
} | ||
case "between": | ||
case "notBetween": { | ||
const valueAsArray = toArray(value); | ||
if (valueAsArray.length >= 2 && !nullOrUndefinedOrEmpty(valueAsArray[0]) && !nullOrUndefinedOrEmpty(valueAsArray[1])) { | ||
const [first, second] = valueAsArray; | ||
const firstNum = shouldRenderAsNumber(first, true) ? parseNumber(first, { parseNumbers: true }) : NaN; | ||
const secondNum = shouldRenderAsNumber(second, true) ? parseNumber(second, { parseNumbers: true }) : NaN; | ||
let firstValue = isNaN(firstNum) ? valueIsField ? `${first}` : first : firstNum; | ||
let secondValue = isNaN(secondNum) ? valueIsField ? `${second}` : second : secondNum; | ||
if (firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) { | ||
const tempNum = secondNum; | ||
secondValue = firstNum; | ||
firstValue = tempNum; | ||
} | ||
const renderAsNumbers = shouldRenderAsNumber(first, parseNumbers) && shouldRenderAsNumber(second, parseNumbers); | ||
const expression = `${field} >= ${valueIsField ? first : renderAsNumbers ? firstValue : quote(firstValue, escapeQuotes)} and ${field} <= ${valueIsField ? second : renderAsNumbers ? secondValue : quote(secondValue, escapeQuotes)}`; | ||
return operator === "between" ? `(${expression})` : negate(expression, true); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
} | ||
return ""; | ||
}; | ||
// src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts | ||
@@ -959,2 +1034,4 @@ var convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notNull$/i, "!=").replace(/^null$/i, "=="); | ||
ruleProcessorInternal = defaultRuleProcessorElasticSearch; | ||
} else if (format === "jsonata") { | ||
ruleProcessorInternal = defaultRuleProcessorJSONata; | ||
} | ||
@@ -967,3 +1044,3 @@ } else { | ||
} | ||
valueProcessorInternal = typeof valueProcessor === "function" ? (r, opts) => isValueProcessorLegacy(valueProcessor) ? valueProcessor(r.field, r.operator, r.value, r.valueSource) : valueProcessor(r, opts) : format === "mongodb" ? ruleProcessorInternal ?? defaultRuleProcessorMongoDB : format === "cel" ? ruleProcessorInternal ?? defaultRuleProcessorCEL : format === "spel" ? ruleProcessorInternal ?? defaultRuleProcessorSpEL : format === "jsonlogic" ? ruleProcessorInternal ?? defaultRuleProcessorJsonLogic : format == "elasticsearch" ? ruleProcessorInternal ?? defaultRuleProcessorElasticSearch : defaultValueProcessorByRule; | ||
valueProcessorInternal = typeof valueProcessor === "function" ? (r, opts) => isValueProcessorLegacy(valueProcessor) ? valueProcessor(r.field, r.operator, r.value, r.valueSource) : valueProcessor(r, opts) : format === "mongodb" ? ruleProcessorInternal ?? defaultRuleProcessorMongoDB : format === "cel" ? ruleProcessorInternal ?? defaultRuleProcessorCEL : format === "spel" ? ruleProcessorInternal ?? defaultRuleProcessorSpEL : format === "jsonlogic" ? ruleProcessorInternal ?? defaultRuleProcessorJsonLogic : format === "elasticsearch" ? ruleProcessorInternal ?? defaultRuleProcessorElasticSearch : format === "jsonata" ? ruleProcessorInternal ?? defaultRuleProcessorJSONata : defaultValueProcessorByRule; | ||
quoteFieldNamesWith = quoteFieldNamesWithArray(options.quoteFieldNamesWith); | ||
@@ -1264,2 +1341,32 @@ validator = options.validator ?? (() => true); | ||
} | ||
if (format === "jsonata") { | ||
const processRuleGroup = (rg, outermost) => { | ||
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? /* istanbul ignore next */ | ||
""])) { | ||
return outermost ? fallbackExpression : ""; | ||
} | ||
const expression = rg.rules.map((rule) => { | ||
if (typeof rule === "string") { | ||
return rule; | ||
} | ||
if (isRuleGroup(rule)) { | ||
return processRuleGroup(rule); | ||
} | ||
const [validationResult, fieldValidator] = validateRule(rule); | ||
if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName) { | ||
return ""; | ||
} | ||
const fieldData = getOption(fields, rule.field); | ||
return (ruleProcessorInternal ?? valueProcessorInternal)(rule, { | ||
parseNumbers, | ||
escapeQuotes: (rule.valueSource ?? "value") === "value", | ||
fieldData, | ||
format | ||
}); | ||
}).filter(Boolean).join(isRuleGroupType(rg) ? ` ${rg.combinator} ` : " "); | ||
const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "$not" : ""}(`, ")"] : ["", ""]; | ||
return expression ? `${prefix}${expression}${suffix}` : fallbackExpression; | ||
}; | ||
return processRuleGroup(ruleGroup, true); | ||
} | ||
if (format === "jsonlogic") { | ||
@@ -1358,2 +1465,3 @@ const query = isRuleGroupType(ruleGroup) ? ruleGroup : convertFromIC(ruleGroup); | ||
defaultRuleProcessorElasticSearch, | ||
defaultRuleProcessorJSONata, | ||
defaultRuleProcessorJsonLogic, | ||
@@ -1360,0 +1468,0 @@ defaultRuleProcessorMongoDB, |
import { D as DefaultRuleGroupType, a as DefaultRuleGroupTypeIC } from './basic-CtWU1IF_.js'; | ||
import { d as ParseCELOptions } from './importExport-C0h8KkL7.js'; | ||
import { d as ParseCELOptions } from './importExport-DT0uMCJu.js'; | ||
import 'type-fest'; | ||
@@ -4,0 +4,0 @@ import 'json-logic-js'; |
import { D as DefaultRuleGroupType, a as DefaultRuleGroupTypeIC } from './basic-CtWU1IF_.js'; | ||
import { b as RQBJsonLogic, e as ParseJsonLogicOptions } from './importExport-C0h8KkL7.js'; | ||
import { b as RQBJsonLogic, e as ParseJsonLogicOptions } from './importExport-DT0uMCJu.js'; | ||
import 'type-fest'; | ||
@@ -4,0 +4,0 @@ import 'json-logic-js'; |
import { D as DefaultRuleGroupType, a as DefaultRuleGroupTypeIC } from './basic-CtWU1IF_.js'; | ||
import { f as ParseMongoDbOptions } from './importExport-C0h8KkL7.js'; | ||
import { f as ParseMongoDbOptions } from './importExport-DT0uMCJu.js'; | ||
import 'type-fest'; | ||
@@ -4,0 +4,0 @@ import 'json-logic-js'; |
import { D as DefaultRuleGroupType, a as DefaultRuleGroupTypeIC } from './basic-CtWU1IF_.js'; | ||
import { g as ParseSpELOptions } from './importExport-C0h8KkL7.js'; | ||
import { g as ParseSpELOptions } from './importExport-DT0uMCJu.js'; | ||
import 'type-fest'; | ||
@@ -4,0 +4,0 @@ import 'json-logic-js'; |
import { D as DefaultRuleGroupType, a as DefaultRuleGroupTypeIC } from './basic-CtWU1IF_.js'; | ||
import { h as ParseSQLOptions } from './importExport-C0h8KkL7.js'; | ||
import { h as ParseSQLOptions } from './importExport-DT0uMCJu.js'; | ||
import 'type-fest'; | ||
@@ -4,0 +4,0 @@ import 'json-logic-js'; |
{ | ||
"name": "react-querybuilder", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"description": "The React <QueryBuilder /> component for constructing queries", | ||
@@ -104,2 +104,3 @@ "main": "./dist/cjs/index.js", | ||
"json-logic-js": "^2.0.2", | ||
"jsonata": "^2.0.4", | ||
"query-string": "^9.0.0", | ||
@@ -139,3 +140,3 @@ "react": "^18.2.0", | ||
}, | ||
"gitHead": "853546b1d9c2f81aa35d868956fb9091b8cff11d" | ||
"gitHead": "221085b07f16926e9436968f26c31fd50276201c" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4580716
32454
29