sqlparser-devexpress 2.3.17 → 2.3.19

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.3.17",
3
+ "version": "2.3.19",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "test": "vitest"
7
+ "test": "vitest run"
8
8
  },
9
9
  "exports": {
10
10
  "import": "./src/index.js",
@@ -139,9 +139,9 @@ function DevExpressConverter() {
139
139
  }
140
140
 
141
141
  const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
142
- const leftDefault = ast.left?.args[1]?.value;
142
+ const leftDefault = ast.left?.args && ast.left?.args[1]?.value;
143
143
  const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
144
- const rightDefault = ast.right?.args[1]?.value;
144
+ const rightDefault = ast.right?.args && ast.right?.args[1]?.value;
145
145
  let operatorToken = ast.operator.toLowerCase();
146
146
  let includeExtradata = false;
147
147
 
@@ -140,6 +140,16 @@ export function parse(input, variables = []) {
140
140
  // Recursively parse the right-hand expression with adjusted precedence
141
141
  const right = parseExpression(OPERATOR_PRECEDENCE[operator]);
142
142
  left = { type: "logical", operator, left, right };
143
+ } else if (currentToken?.type == "identifier") {
144
+ const right = parseValue(operator);
145
+ let newOperator = inverseOperator(operator);
146
+
147
+ left = {
148
+ type: "comparison",
149
+ right: left,
150
+ operator: newOperator,
151
+ left: { type: "field", value: right }
152
+ };
143
153
  }
144
154
  }
145
155
 
@@ -218,12 +228,28 @@ export function parse(input, variables = []) {
218
228
  throw new Error(`Invalid comparison: ${field} ${operator} ${value}`);
219
229
  }
220
230
 
231
+ // Swap the field and value if the field is a placeholder and the value is an identifier
232
+ if (valueType == "identifier" && fieldType == "placeholder") {
233
+ let newOperator = inverseOperator(operator);
234
+ return { type: "comparison", value: field, operator: newOperator, field: value, originalOperator };
235
+ }
236
+
221
237
  return { type: "comparison", field, operator, value, originalOperator };
222
238
  }
223
239
 
224
240
  return { type: "field", value: field };
225
241
  }
226
242
 
243
+ function inverseOperator(operator) {
244
+ switch (operator.toUpperCase()) {
245
+ case ">": return "<";
246
+ case "<": return ">";
247
+ case ">=": return "<=";
248
+ case "<=": return ">=";
249
+ default: return operator; // Return the operator as is if no inverse is defined
250
+ }
251
+ }
252
+
227
253
  // Parses values including numbers, strings, placeholders, and IN lists
228
254
  function parseValue(operatorToken) {
229
255
  if (!currentToken) throw new Error("Unexpected end of input");
@@ -268,6 +268,26 @@ describe("Parser SQL to dx Filter Builder", () => {
268
268
  {
269
269
  input: "ID IN ({SaleOrderStatusStmtGlobalRpt.RegionID})",
270
270
  expected: []
271
+ },
272
+ {
273
+ input: "10 < ID AND ApplicableUoms IN ({WorkOrderLine.ApplicableUoms})",
274
+ expected: [
275
+ ["ID", ">", 10],
276
+ "and",
277
+ [
278
+ ["ApplicableUoms", "=", "UOM1"],
279
+ "or",
280
+ ["ApplicableUoms", "=", "UOM2"],
281
+ "or",
282
+ ["ApplicableUoms", "=", "UOM3"]
283
+ ]
284
+ ],
285
+ },
286
+ {
287
+ input: "{ServiceOrderDocument.SourceID} = ID",
288
+ expected: [
289
+ "ID", "=", 2
290
+ ]
271
291
  }
272
292
  ];
273
293