@react-querybuilder/core 8.20.1 → 8.21.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.
Files changed (108) hide show
  1. package/README.md +4 -0
  2. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +2261 -2113
  3. package/dist/cjs/react-querybuilder_core.cjs.development.js +323 -26
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  5. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +2261 -2113
  6. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  8. package/dist/{convertQuery-BJKNgecE.js → convertQuery-Cw76XFIn.js} +8 -8
  9. package/dist/{convertQuery-BJKNgecE.js.map → convertQuery-Cw76XFIn.js.map} +1 -1
  10. package/dist/{convertQuery-J1CaoDxe.mjs → convertQuery-D_4J7E-Z.mjs} +2 -2
  11. package/dist/{convertQuery-J1CaoDxe.mjs.map → convertQuery-D_4J7E-Z.mjs.map} +1 -1
  12. package/dist/formatQuery.d.mts +499 -459
  13. package/dist/formatQuery.d.ts +499 -459
  14. package/dist/formatQuery.js +173 -91
  15. package/dist/formatQuery.js.map +1 -1
  16. package/dist/formatQuery.mjs +100 -23
  17. package/dist/formatQuery.mjs.map +1 -1
  18. package/dist/import-BVdxeIBO.d.mts +26 -0
  19. package/dist/import-Ddc3d_8q.d.ts +26 -0
  20. package/dist/{index-DlVg-QXo.d.mts → index-BSwFvkeI.d.mts} +679 -648
  21. package/dist/{index-DlVg-QXo.d.ts → index-BSwFvkeI.d.ts} +679 -648
  22. package/dist/{objectUtils-DBJI82bl.js → isRuleGroup-0JNiQgLg.js} +1 -26
  23. package/dist/isRuleGroup-0JNiQgLg.js.map +1 -0
  24. package/dist/{objectUtils-ZvPkF6u6.mjs → isRuleGroup-CqLThsbu.mjs} +2 -15
  25. package/dist/isRuleGroup-CqLThsbu.mjs.map +1 -0
  26. package/dist/objectUtils-Cr02aGxb.js +27 -0
  27. package/dist/objectUtils-Cr02aGxb.js.map +1 -0
  28. package/dist/objectUtils-DBlmJgBf.mjs +16 -0
  29. package/dist/objectUtils-DBlmJgBf.mjs.map +1 -0
  30. package/dist/parseCEL.d.mts +64 -30
  31. package/dist/parseCEL.d.ts +64 -30
  32. package/dist/parseCEL.js +91 -12
  33. package/dist/parseCEL.js.map +1 -1
  34. package/dist/parseCEL.mjs +85 -8
  35. package/dist/parseCEL.mjs.map +1 -1
  36. package/dist/parseCypher.d.mts +24 -25
  37. package/dist/parseCypher.d.ts +24 -25
  38. package/dist/parseGremlin.d.mts +18 -19
  39. package/dist/parseGremlin.d.ts +18 -19
  40. package/dist/parseJSONata.d.mts +207 -20
  41. package/dist/parseJSONata.d.ts +207 -20
  42. package/dist/parseJSONata.js +92 -7
  43. package/dist/parseJSONata.js.map +1 -1
  44. package/dist/parseJSONata.mjs +80 -4
  45. package/dist/parseJSONata.mjs.map +1 -1
  46. package/dist/parseJsonLogic.d.mts +51 -18
  47. package/dist/parseJsonLogic.d.ts +51 -18
  48. package/dist/parseJsonLogic.js +95 -34
  49. package/dist/parseJsonLogic.js.map +1 -1
  50. package/dist/parseJsonLogic.mjs +65 -6
  51. package/dist/parseJsonLogic.mjs.map +1 -1
  52. package/dist/parseMongoDB.d.mts +89 -58
  53. package/dist/parseMongoDB.d.ts +89 -58
  54. package/dist/parseMongoDB.js +140 -15
  55. package/dist/parseMongoDB.js.map +1 -1
  56. package/dist/parseMongoDB.mjs +128 -5
  57. package/dist/parseMongoDB.mjs.map +1 -1
  58. package/dist/parseSPARQL.d.mts +17 -18
  59. package/dist/parseSPARQL.d.ts +17 -18
  60. package/dist/parseSPARQL.js.map +1 -1
  61. package/dist/parseSPARQL.mjs.map +1 -1
  62. package/dist/parseSQL.d.mts +266 -18
  63. package/dist/parseSQL.d.ts +266 -18
  64. package/dist/parseSQL.js +163 -10
  65. package/dist/parseSQL.js.map +1 -1
  66. package/dist/parseSQL.mjs +149 -7
  67. package/dist/parseSQL.mjs.map +1 -1
  68. package/dist/parseSpEL.d.mts +193 -19
  69. package/dist/parseSpEL.d.ts +193 -19
  70. package/dist/parseSpEL.js +166 -7
  71. package/dist/parseSpEL.js.map +1 -1
  72. package/dist/parseSpEL.mjs +142 -6
  73. package/dist/parseSpEL.mjs.map +1 -1
  74. package/dist/{prepareQueryObjects-DaAXX792.js → prepareQueryObjects-C2-kTZvR.js} +6 -6
  75. package/dist/prepareQueryObjects-C2-kTZvR.js.map +1 -0
  76. package/dist/{prepareQueryObjects-Cd_tt4oy.mjs → prepareQueryObjects-Q18lHCKl.mjs} +4 -4
  77. package/dist/prepareQueryObjects-Q18lHCKl.mjs.map +1 -0
  78. package/dist/query-builder-layout.css.map +1 -1
  79. package/dist/query-builder.css.map +1 -1
  80. package/dist/react-querybuilder_core.d.mts +2261 -2113
  81. package/dist/react-querybuilder_core.legacy-esm.d.ts +2261 -2113
  82. package/dist/react-querybuilder_core.legacy-esm.js +339 -44
  83. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  84. package/dist/react-querybuilder_core.mjs +313 -27
  85. package/dist/react-querybuilder_core.mjs.map +1 -1
  86. package/dist/react-querybuilder_core.production.d.mts +2261 -2113
  87. package/dist/react-querybuilder_core.production.mjs +1 -1
  88. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  89. package/dist/styles/_layout.scss +4 -10
  90. package/dist/transformQuery.d.mts +91 -92
  91. package/dist/transformQuery.d.ts +91 -92
  92. package/dist/transformQuery.js +4 -3
  93. package/dist/transformQuery.js.map +1 -1
  94. package/dist/transformQuery.mjs +2 -1
  95. package/dist/transformQuery.mjs.map +1 -1
  96. package/dist/{utils-BpaOtylk.js → utils-DEwV7F6B.js} +108 -12
  97. package/dist/utils-DEwV7F6B.js.map +1 -0
  98. package/dist/{utils-CJRGiPb-.mjs → utils-Dt0D_DMV.mjs} +69 -3
  99. package/dist/utils-Dt0D_DMV.mjs.map +1 -0
  100. package/package.json +15 -14
  101. package/dist/import-Qs1-kgv5.d.ts +0 -27
  102. package/dist/import-ShTj5IdB.d.mts +0 -27
  103. package/dist/objectUtils-DBJI82bl.js.map +0 -1
  104. package/dist/objectUtils-ZvPkF6u6.mjs.map +0 -1
  105. package/dist/prepareQueryObjects-Cd_tt4oy.mjs.map +0 -1
  106. package/dist/prepareQueryObjects-DaAXX792.js.map +0 -1
  107. package/dist/utils-BpaOtylk.js.map +0 -1
  108. package/dist/utils-CJRGiPb-.mjs.map +0 -1
package/dist/parseSQL.js CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils = require("./utils-BpaOtylk.js");
3
- const require_objectUtils = require("./objectUtils-DBJI82bl.js");
4
- const require_prepareQueryObjects = require("./prepareQueryObjects-DaAXX792.js");
2
+ const require_utils = require("./utils-DEwV7F6B.js");
3
+ const require_isRuleGroup = require("./isRuleGroup-0JNiQgLg.js");
4
+ const require_prepareQueryObjects = require("./prepareQueryObjects-C2-kTZvR.js");
5
5
  let _ts_jison_parser = require("@ts-jison/parser");
6
6
  let _ts_jison_lexer = require("@ts-jison/lexer");
7
7
  //#region src/utils/parseSQL/sqlParser.ts
@@ -5888,6 +5888,15 @@ const isSQLLiteralValue = (v) => v?.type === "String" || v?.type === "Number" ||
5888
5888
  const isSQLSignedNumber = (v) => v?.type === "Prefix" && (v.prefix === "+" || v.prefix === "-") && v.value.type === "Number";
5889
5889
  const isSQLLiteralOrSignedNumberValue = (v) => isSQLLiteralValue(v) || isSQLSignedNumber(v);
5890
5890
  const isSQLIdentifier = (v) => v?.type === "Identifier";
5891
+ const isSQLBitExpression = (v) => v?.type === "BitExpression";
5892
+ const isSQLFunctionCall = (v) => v?.type === "FunctionCall";
5893
+ const isSQLPlaceHolder = (v) => v?.type === "PlaceHolder";
5894
+ /** An operand that is neither a bare identifier nor a (signed) literal nor a placeholder. */
5895
+ const isSQLExpressionOperand = (v) => {
5896
+ if (isSQLBitExpression(v) || isSQLFunctionCall(v)) return true;
5897
+ if (v?.type === "SimpleExprParentheses") return isSQLExpressionOperand(v.value?.value?.[0]);
5898
+ return false;
5899
+ };
5891
5900
  const getParamString = (param) => {
5892
5901
  switch (typeof param) {
5893
5902
  case "number": return `${param}`;
@@ -5902,7 +5911,7 @@ const getFieldName = (f) => {
5902
5911
  else if (fieldName.startsWith("[") && fieldName.endsWith("]")) return fieldName.replaceAll(/(^\[|]$)/g, "").replaceAll("]]", "]");
5903
5912
  return fieldName;
5904
5913
  };
5905
- const normalizeCombinator = (c) => require_objectUtils.lc(c.replace("&&", "and").replace("||", "or"));
5914
+ const normalizeCombinator = (c) => require_isRuleGroup.lc(c.replace("&&", "and").replace("||", "or"));
5906
5915
  const normalizeOperator = (op, flip) => {
5907
5916
  if (flip) {
5908
5917
  if (op === "<") return ">";
@@ -5918,7 +5927,7 @@ const evalSQLLiteralValue = (valueObj, { bigIntOnOverflow } = {}) => {
5918
5927
  const valueString = valueObj.value;
5919
5928
  if (valueString.startsWith(`'`) && valueString.endsWith(`'`) || valueString.startsWith(`"`) && valueString.endsWith(`"`)) return valueString.slice(1, -1).replaceAll(/''/gm, "'");
5920
5929
  return valueString;
5921
- } else if (valueObj.type === "Boolean") return require_objectUtils.lc(valueObj.value) === "true";
5930
+ } else if (valueObj.type === "Boolean") return require_isRuleGroup.lc(valueObj.value) === "true";
5922
5931
  else if (isSQLSignedNumber(valueObj)) return require_utils.parseNumber(`${valueObj.prefix}${valueObj.value.value}`, {
5923
5932
  parseNumbers: true,
5924
5933
  bigIntOnOverflow
@@ -6026,8 +6035,62 @@ const generateMixedAndXorOrList = (expr) => {
6026
6035
  };
6027
6036
  //#endregion
6028
6037
  //#region src/utils/parseSQL/parseSQL.ts
6038
+ /**
6039
+ * Rewrites named (`:name`, or any configured prefix) and positional (`?`) parameter
6040
+ * placeholders into the grammar's native `${name}` form so they surface as `PlaceHolder`
6041
+ * nodes. Positional placeholders are named by 1-based ordinal. Skips string/quoted-identifier
6042
+ * literals so placeholder-like text inside them is preserved.
6043
+ */
6044
+ // v8 ignore next -- @preserve
6045
+ const normalizeParameterPlaceholders = (str, prefixes, positional) => {
6046
+ let out = "";
6047
+ let quote = "";
6048
+ let ordinal = 0;
6049
+ for (let i = 0; i < str.length;) {
6050
+ const c = str[i];
6051
+ if (quote) {
6052
+ out += c;
6053
+ if (c === quote) {
6054
+ if (str[i + 1] === quote) {
6055
+ out += str[i + 1];
6056
+ i += 2;
6057
+ continue;
6058
+ }
6059
+ quote = "";
6060
+ }
6061
+ i++;
6062
+ continue;
6063
+ }
6064
+ if (c === `'` || c === `"` || c === "`") {
6065
+ quote = c;
6066
+ out += c;
6067
+ i++;
6068
+ continue;
6069
+ }
6070
+ if (positional && c === "?") {
6071
+ ordinal++;
6072
+ out += `\${${ordinal}}`;
6073
+ i++;
6074
+ continue;
6075
+ }
6076
+ let matched = false;
6077
+ for (const p of prefixes) if (p.length > 0 && str.startsWith(p, i)) {
6078
+ const m = /^([A-Za-z_$][\w$]*)/.exec(str.slice(i + p.length));
6079
+ if (m) {
6080
+ out += `\${${m[1]}}`;
6081
+ i += p.length + m[1].length;
6082
+ matched = true;
6083
+ break;
6084
+ }
6085
+ }
6086
+ if (matched) continue;
6087
+ out += c;
6088
+ i++;
6089
+ }
6090
+ return out;
6091
+ };
6029
6092
  function parseSQL(sql, options = {}) {
6030
- const { params, paramPrefix, independentCombinators, fields, getValueSources, bigIntOnOverflow } = options;
6093
+ const { params, paramPrefix, independentCombinators, fields, getValueSources, bigIntOnOverflow, getExpression, parseParameters } = options;
6031
6094
  let sqlString = /^\s*select\b/i.test(sql) ? sql : /^\s*where\b/i.test(sql) ? `SELECT * FROM t ${sql}` : `SELECT * FROM t WHERE ${sql}`;
6032
6095
  let ic = false;
6033
6096
  const fieldsFlat = require_prepareQueryObjects.getFieldsArray(fields);
@@ -6045,6 +6108,13 @@ function parseSQL(sql, options = {}) {
6045
6108
  const prefix = paramPrefix ?? ":";
6046
6109
  for (const p of keys) sqlString = sqlString.replaceAll(new RegExp(`\\${prefix}${p}\\b`, "ig"), getParamString(params[p]));
6047
6110
  }
6111
+ if (parseParameters) {
6112
+ const cfg = parseParameters === true ? {} : parseParameters;
6113
+ const pre = cfg.prefix ?? ":";
6114
+ const prefixes = Array.isArray(pre) ? pre : [pre];
6115
+ const positional = cfg.positional ?? true;
6116
+ sqlString = normalizeParameterPlaceholders(sqlString, prefixes, positional);
6117
+ }
6048
6118
  const fieldIsValid = (fieldName, operator, subordinateFieldName) => require_prepareQueryObjects.fieldIsValidUtil({
6049
6119
  fieldName,
6050
6120
  fieldsFlat,
@@ -6052,12 +6122,17 @@ function parseSQL(sql, options = {}) {
6052
6122
  subordinateFieldName,
6053
6123
  getValueSources
6054
6124
  });
6125
+ const exprCtx = {
6126
+ bigIntOnOverflow,
6127
+ fieldExists: (fieldName) => fieldsFlat.length === 0 || fieldsFlat.some((f) => f.name === fieldName)
6128
+ };
6055
6129
  const processSQLExpression = (expr) => {
6056
6130
  switch (expr.type) {
6057
6131
  case "NotExpression": {
6058
- const rule = processSQLExpression(expr.value.type === "SimpleExprParentheses" ? expr.value.value.value[0] : expr.value);
6132
+ const val = expr.value.type === "SimpleExprParentheses" ? expr.value.value.value[0] : expr.value;
6133
+ const rule = processSQLExpression(val);
6059
6134
  if (rule) {
6060
- if (require_objectUtils.isRuleGroup(rule)) return {
6135
+ if (require_isRuleGroup.isRuleGroup(rule)) return {
6061
6136
  ...rule,
6062
6137
  not: true
6063
6138
  };
@@ -6124,7 +6199,6 @@ function parseSQL(sql, options = {}) {
6124
6199
  }
6125
6200
  break;
6126
6201
  case "ComparisonBooleanPrimary":
6127
- /* v8 ignore else -- @preserve */
6128
6202
  if (isSQLIdentifier(expr.left) && !isSQLIdentifier(expr.right) || !isSQLIdentifier(expr.left) && isSQLIdentifier(expr.right)) {
6129
6203
  const identifier = isSQLIdentifier(expr.left) ? expr.left.value : expr.right.value;
6130
6204
  const valueObj = [expr.left, expr.right].find((t) => !isSQLIdentifier(t));
@@ -6136,6 +6210,26 @@ function parseSQL(sql, options = {}) {
6136
6210
  operator,
6137
6211
  value: evalSQLLiteralValue(valueObj, { bigIntOnOverflow })
6138
6212
  };
6213
+ } else if (parseParameters && isSQLPlaceHolder(valueObj)) {
6214
+ const f = getFieldName(identifier);
6215
+ const operator = normalizeOperator(expr.operator, isSQLIdentifier(expr.right));
6216
+ if (fieldIsValid(f, operator)) return {
6217
+ field: f,
6218
+ operator,
6219
+ value: valueObj.param,
6220
+ valueSource: "parameter"
6221
+ };
6222
+ } else if (getExpression && isSQLExpressionOperand(valueObj)) {
6223
+ const node = getExpression(valueObj, exprCtx);
6224
+ if (!node) return null;
6225
+ const f = getFieldName(identifier);
6226
+ const operator = normalizeOperator(expr.operator, isSQLIdentifier(expr.right));
6227
+ if (fieldIsValid(f, operator)) return {
6228
+ field: f,
6229
+ operator,
6230
+ value: node,
6231
+ valueSource: "expression"
6232
+ };
6139
6233
  }
6140
6234
  } else if (isSQLIdentifier(expr.left) && isSQLIdentifier(expr.right)) {
6141
6235
  const f = getFieldName(expr.left);
@@ -6147,6 +6241,30 @@ function parseSQL(sql, options = {}) {
6147
6241
  value: sf,
6148
6242
  valueSource: "field"
6149
6243
  };
6244
+ } else if (getExpression && isSQLExpressionOperand(expr.left) && isSQLExpressionOperand(expr.right)) {
6245
+ const lhs = getExpression(expr.left, exprCtx);
6246
+ const rhs = getExpression(expr.right, exprCtx);
6247
+ if (!lhs || !rhs) return null;
6248
+ return {
6249
+ field: "",
6250
+ operator: normalizeOperator(expr.operator),
6251
+ lhs,
6252
+ value: rhs,
6253
+ valueSource: "expression"
6254
+ };
6255
+ } else if (getExpression && (isSQLExpressionOperand(expr.left) || isSQLExpressionOperand(expr.right))) {
6256
+ const exprOnLeft = isSQLExpressionOperand(expr.left);
6257
+ const exprSide = exprOnLeft ? expr.left : expr.right;
6258
+ const otherSide = exprOnLeft ? expr.right : expr.left;
6259
+ const lhs = getExpression(exprSide, exprCtx);
6260
+ if (!lhs) return null;
6261
+ if (isSQLLiteralOrSignedNumberValue(otherSide)) return {
6262
+ field: "",
6263
+ operator: normalizeOperator(expr.operator, !exprOnLeft),
6264
+ lhs,
6265
+ value: evalSQLLiteralValue(otherSide, { bigIntOnOverflow })
6266
+ };
6267
+ return null;
6150
6268
  }
6151
6269
  break;
6152
6270
  case "InExpressionListPredicate":
@@ -6195,6 +6313,30 @@ function parseSQL(sql, options = {}) {
6195
6313
  value: options?.listsAsArrays ? valueArray : require_utils.joinWith(valueArray, ", "),
6196
6314
  valueSource: "field"
6197
6315
  };
6316
+ } else if (parseParameters && isSQLIdentifier(expr.left) && isSQLPlaceHolder(expr.right.left) && isSQLPlaceHolder(expr.right.right)) {
6317
+ const f = getFieldName(expr.left);
6318
+ const operator = expr.hasNot ? "notBetween" : "between";
6319
+ if (fieldIsValid(f, operator)) {
6320
+ const valueArray = [expr.right.left.param, expr.right.right.param];
6321
+ return {
6322
+ field: f,
6323
+ operator,
6324
+ value: options?.listsAsArrays ? valueArray : require_utils.joinWith(valueArray, ", "),
6325
+ valueSource: "parameter"
6326
+ };
6327
+ }
6328
+ } else if (getExpression && isSQLIdentifier(expr.left) && (isSQLExpressionOperand(expr.right.left) || isSQLExpressionOperand(expr.right.right))) {
6329
+ const rhs = getExpression(expr.right.left, exprCtx);
6330
+ const rhs2 = getExpression(expr.right.right, exprCtx);
6331
+ if (!rhs || !rhs2) return null;
6332
+ const f = getFieldName(expr.left);
6333
+ const operator = expr.hasNot ? "notBetween" : "between";
6334
+ if (fieldIsValid(f, operator)) return {
6335
+ field: f,
6336
+ operator,
6337
+ value: [rhs, rhs2],
6338
+ valueSource: "expression"
6339
+ };
6198
6340
  }
6199
6341
  break;
6200
6342
  case "LikePredicate":
@@ -6258,7 +6400,7 @@ function parseSQL(sql, options = {}) {
6258
6400
  if (where) {
6259
6401
  const result = processSQLExpression(where);
6260
6402
  if (result) {
6261
- if (require_objectUtils.isRuleGroup(result)) return prepare(result);
6403
+ if (require_isRuleGroup.isRuleGroup(result)) return prepare(result);
6262
6404
  return prepare({
6263
6405
  rules: [result],
6264
6406
  ...ic ? {} : { combinator: "and" }
@@ -6271,6 +6413,17 @@ function parseSQL(sql, options = {}) {
6271
6413
  });
6272
6414
  }
6273
6415
  //#endregion
6416
+ exports.evalSQLLiteralValue = evalSQLLiteralValue;
6417
+ exports.getFieldName = getFieldName;
6418
+ exports.isSQLBitExpression = isSQLBitExpression;
6419
+ exports.isSQLExpressionOperand = isSQLExpressionOperand;
6420
+ exports.isSQLFunctionCall = isSQLFunctionCall;
6421
+ exports.isSQLIdentifier = isSQLIdentifier;
6422
+ exports.isSQLLiteralOrSignedNumberValue = isSQLLiteralOrSignedNumberValue;
6423
+ exports.isSQLLiteralValue = isSQLLiteralValue;
6424
+ exports.isSQLPlaceHolder = isSQLPlaceHolder;
6425
+ exports.isSQLSignedNumber = isSQLSignedNumber;
6426
+ exports.normalizeOperator = normalizeOperator;
6274
6427
  exports.parseSQL = parseSQL;
6275
6428
 
6276
6429
  //# sourceMappingURL=parseSQL.js.map