@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.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { E as joinWith, T as parseNumber } from "./utils-CJRGiPb-.mjs";
2
- import { r as isRuleGroup, s as lc } from "./objectUtils-ZvPkF6u6.mjs";
3
- import { n as fieldIsValidUtil, r as getFieldsArray, t as prepareRuleGroup } from "./prepareQueryObjects-Cd_tt4oy.mjs";
1
+ import { A as parseNumber, j as joinWith } from "./utils-Dt0D_DMV.mjs";
2
+ import { a as lc, t as isRuleGroup } from "./isRuleGroup-CqLThsbu.mjs";
3
+ import { n as fieldIsValidUtil, r as getFieldsArray, t as prepareRuleGroup } from "./prepareQueryObjects-Q18lHCKl.mjs";
4
4
  import { JisonParser } from "@ts-jison/parser";
5
5
  import { JisonLexer } from "@ts-jison/lexer";
6
6
  //#region src/utils/parseSQL/sqlParser.ts
@@ -5887,6 +5887,15 @@ const isSQLLiteralValue = (v) => v?.type === "String" || v?.type === "Number" ||
5887
5887
  const isSQLSignedNumber = (v) => v?.type === "Prefix" && (v.prefix === "+" || v.prefix === "-") && v.value.type === "Number";
5888
5888
  const isSQLLiteralOrSignedNumberValue = (v) => isSQLLiteralValue(v) || isSQLSignedNumber(v);
5889
5889
  const isSQLIdentifier = (v) => v?.type === "Identifier";
5890
+ const isSQLBitExpression = (v) => v?.type === "BitExpression";
5891
+ const isSQLFunctionCall = (v) => v?.type === "FunctionCall";
5892
+ const isSQLPlaceHolder = (v) => v?.type === "PlaceHolder";
5893
+ /** An operand that is neither a bare identifier nor a (signed) literal nor a placeholder. */
5894
+ const isSQLExpressionOperand = (v) => {
5895
+ if (isSQLBitExpression(v) || isSQLFunctionCall(v)) return true;
5896
+ if (v?.type === "SimpleExprParentheses") return isSQLExpressionOperand(v.value?.value?.[0]);
5897
+ return false;
5898
+ };
5890
5899
  const getParamString = (param) => {
5891
5900
  switch (typeof param) {
5892
5901
  case "number": return `${param}`;
@@ -6025,8 +6034,62 @@ const generateMixedAndXorOrList = (expr) => {
6025
6034
  };
6026
6035
  //#endregion
6027
6036
  //#region src/utils/parseSQL/parseSQL.ts
6037
+ /**
6038
+ * Rewrites named (`:name`, or any configured prefix) and positional (`?`) parameter
6039
+ * placeholders into the grammar's native `${name}` form so they surface as `PlaceHolder`
6040
+ * nodes. Positional placeholders are named by 1-based ordinal. Skips string/quoted-identifier
6041
+ * literals so placeholder-like text inside them is preserved.
6042
+ */
6043
+ // v8 ignore next -- @preserve
6044
+ const normalizeParameterPlaceholders = (str, prefixes, positional) => {
6045
+ let out = "";
6046
+ let quote = "";
6047
+ let ordinal = 0;
6048
+ for (let i = 0; i < str.length;) {
6049
+ const c = str[i];
6050
+ if (quote) {
6051
+ out += c;
6052
+ if (c === quote) {
6053
+ if (str[i + 1] === quote) {
6054
+ out += str[i + 1];
6055
+ i += 2;
6056
+ continue;
6057
+ }
6058
+ quote = "";
6059
+ }
6060
+ i++;
6061
+ continue;
6062
+ }
6063
+ if (c === `'` || c === `"` || c === "`") {
6064
+ quote = c;
6065
+ out += c;
6066
+ i++;
6067
+ continue;
6068
+ }
6069
+ if (positional && c === "?") {
6070
+ ordinal++;
6071
+ out += `\${${ordinal}}`;
6072
+ i++;
6073
+ continue;
6074
+ }
6075
+ let matched = false;
6076
+ for (const p of prefixes) if (p.length > 0 && str.startsWith(p, i)) {
6077
+ const m = /^([A-Za-z_$][\w$]*)/.exec(str.slice(i + p.length));
6078
+ if (m) {
6079
+ out += `\${${m[1]}}`;
6080
+ i += p.length + m[1].length;
6081
+ matched = true;
6082
+ break;
6083
+ }
6084
+ }
6085
+ if (matched) continue;
6086
+ out += c;
6087
+ i++;
6088
+ }
6089
+ return out;
6090
+ };
6028
6091
  function parseSQL(sql, options = {}) {
6029
- const { params, paramPrefix, independentCombinators, fields, getValueSources, bigIntOnOverflow } = options;
6092
+ const { params, paramPrefix, independentCombinators, fields, getValueSources, bigIntOnOverflow, getExpression, parseParameters } = options;
6030
6093
  let sqlString = /^\s*select\b/i.test(sql) ? sql : /^\s*where\b/i.test(sql) ? `SELECT * FROM t ${sql}` : `SELECT * FROM t WHERE ${sql}`;
6031
6094
  let ic = false;
6032
6095
  const fieldsFlat = getFieldsArray(fields);
@@ -6044,6 +6107,13 @@ function parseSQL(sql, options = {}) {
6044
6107
  const prefix = paramPrefix ?? ":";
6045
6108
  for (const p of keys) sqlString = sqlString.replaceAll(new RegExp(`\\${prefix}${p}\\b`, "ig"), getParamString(params[p]));
6046
6109
  }
6110
+ if (parseParameters) {
6111
+ const cfg = parseParameters === true ? {} : parseParameters;
6112
+ const pre = cfg.prefix ?? ":";
6113
+ const prefixes = Array.isArray(pre) ? pre : [pre];
6114
+ const positional = cfg.positional ?? true;
6115
+ sqlString = normalizeParameterPlaceholders(sqlString, prefixes, positional);
6116
+ }
6047
6117
  const fieldIsValid = (fieldName, operator, subordinateFieldName) => fieldIsValidUtil({
6048
6118
  fieldName,
6049
6119
  fieldsFlat,
@@ -6051,10 +6121,15 @@ function parseSQL(sql, options = {}) {
6051
6121
  subordinateFieldName,
6052
6122
  getValueSources
6053
6123
  });
6124
+ const exprCtx = {
6125
+ bigIntOnOverflow,
6126
+ fieldExists: (fieldName) => fieldsFlat.length === 0 || fieldsFlat.some((f) => f.name === fieldName)
6127
+ };
6054
6128
  const processSQLExpression = (expr) => {
6055
6129
  switch (expr.type) {
6056
6130
  case "NotExpression": {
6057
- const rule = processSQLExpression(expr.value.type === "SimpleExprParentheses" ? expr.value.value.value[0] : expr.value);
6131
+ const val = expr.value.type === "SimpleExprParentheses" ? expr.value.value.value[0] : expr.value;
6132
+ const rule = processSQLExpression(val);
6058
6133
  if (rule) {
6059
6134
  if (isRuleGroup(rule)) return {
6060
6135
  ...rule,
@@ -6123,7 +6198,6 @@ function parseSQL(sql, options = {}) {
6123
6198
  }
6124
6199
  break;
6125
6200
  case "ComparisonBooleanPrimary":
6126
- /* v8 ignore else -- @preserve */
6127
6201
  if (isSQLIdentifier(expr.left) && !isSQLIdentifier(expr.right) || !isSQLIdentifier(expr.left) && isSQLIdentifier(expr.right)) {
6128
6202
  const identifier = isSQLIdentifier(expr.left) ? expr.left.value : expr.right.value;
6129
6203
  const valueObj = [expr.left, expr.right].find((t) => !isSQLIdentifier(t));
@@ -6135,6 +6209,26 @@ function parseSQL(sql, options = {}) {
6135
6209
  operator,
6136
6210
  value: evalSQLLiteralValue(valueObj, { bigIntOnOverflow })
6137
6211
  };
6212
+ } else if (parseParameters && isSQLPlaceHolder(valueObj)) {
6213
+ const f = getFieldName(identifier);
6214
+ const operator = normalizeOperator(expr.operator, isSQLIdentifier(expr.right));
6215
+ if (fieldIsValid(f, operator)) return {
6216
+ field: f,
6217
+ operator,
6218
+ value: valueObj.param,
6219
+ valueSource: "parameter"
6220
+ };
6221
+ } else if (getExpression && isSQLExpressionOperand(valueObj)) {
6222
+ const node = getExpression(valueObj, exprCtx);
6223
+ if (!node) return null;
6224
+ const f = getFieldName(identifier);
6225
+ const operator = normalizeOperator(expr.operator, isSQLIdentifier(expr.right));
6226
+ if (fieldIsValid(f, operator)) return {
6227
+ field: f,
6228
+ operator,
6229
+ value: node,
6230
+ valueSource: "expression"
6231
+ };
6138
6232
  }
6139
6233
  } else if (isSQLIdentifier(expr.left) && isSQLIdentifier(expr.right)) {
6140
6234
  const f = getFieldName(expr.left);
@@ -6146,6 +6240,30 @@ function parseSQL(sql, options = {}) {
6146
6240
  value: sf,
6147
6241
  valueSource: "field"
6148
6242
  };
6243
+ } else if (getExpression && isSQLExpressionOperand(expr.left) && isSQLExpressionOperand(expr.right)) {
6244
+ const lhs = getExpression(expr.left, exprCtx);
6245
+ const rhs = getExpression(expr.right, exprCtx);
6246
+ if (!lhs || !rhs) return null;
6247
+ return {
6248
+ field: "",
6249
+ operator: normalizeOperator(expr.operator),
6250
+ lhs,
6251
+ value: rhs,
6252
+ valueSource: "expression"
6253
+ };
6254
+ } else if (getExpression && (isSQLExpressionOperand(expr.left) || isSQLExpressionOperand(expr.right))) {
6255
+ const exprOnLeft = isSQLExpressionOperand(expr.left);
6256
+ const exprSide = exprOnLeft ? expr.left : expr.right;
6257
+ const otherSide = exprOnLeft ? expr.right : expr.left;
6258
+ const lhs = getExpression(exprSide, exprCtx);
6259
+ if (!lhs) return null;
6260
+ if (isSQLLiteralOrSignedNumberValue(otherSide)) return {
6261
+ field: "",
6262
+ operator: normalizeOperator(expr.operator, !exprOnLeft),
6263
+ lhs,
6264
+ value: evalSQLLiteralValue(otherSide, { bigIntOnOverflow })
6265
+ };
6266
+ return null;
6149
6267
  }
6150
6268
  break;
6151
6269
  case "InExpressionListPredicate":
@@ -6194,6 +6312,30 @@ function parseSQL(sql, options = {}) {
6194
6312
  value: options?.listsAsArrays ? valueArray : joinWith(valueArray, ", "),
6195
6313
  valueSource: "field"
6196
6314
  };
6315
+ } else if (parseParameters && isSQLIdentifier(expr.left) && isSQLPlaceHolder(expr.right.left) && isSQLPlaceHolder(expr.right.right)) {
6316
+ const f = getFieldName(expr.left);
6317
+ const operator = expr.hasNot ? "notBetween" : "between";
6318
+ if (fieldIsValid(f, operator)) {
6319
+ const valueArray = [expr.right.left.param, expr.right.right.param];
6320
+ return {
6321
+ field: f,
6322
+ operator,
6323
+ value: options?.listsAsArrays ? valueArray : joinWith(valueArray, ", "),
6324
+ valueSource: "parameter"
6325
+ };
6326
+ }
6327
+ } else if (getExpression && isSQLIdentifier(expr.left) && (isSQLExpressionOperand(expr.right.left) || isSQLExpressionOperand(expr.right.right))) {
6328
+ const rhs = getExpression(expr.right.left, exprCtx);
6329
+ const rhs2 = getExpression(expr.right.right, exprCtx);
6330
+ if (!rhs || !rhs2) return null;
6331
+ const f = getFieldName(expr.left);
6332
+ const operator = expr.hasNot ? "notBetween" : "between";
6333
+ if (fieldIsValid(f, operator)) return {
6334
+ field: f,
6335
+ operator,
6336
+ value: [rhs, rhs2],
6337
+ valueSource: "expression"
6338
+ };
6197
6339
  }
6198
6340
  break;
6199
6341
  case "LikePredicate":
@@ -6270,6 +6412,6 @@ function parseSQL(sql, options = {}) {
6270
6412
  });
6271
6413
  }
6272
6414
  //#endregion
6273
- export { parseSQL };
6415
+ export { evalSQLLiteralValue, getFieldName, isSQLBitExpression, isSQLExpressionOperand, isSQLFunctionCall, isSQLIdentifier, isSQLLiteralOrSignedNumberValue, isSQLLiteralValue, isSQLPlaceHolder, isSQLSignedNumber, normalizeOperator, parseSQL };
6274
6416
 
6275
6417
  //# sourceMappingURL=parseSQL.mjs.map