unconventional 0.0.12 → 1.0.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.
@@ -52,13 +52,19 @@ function getWhere(model, filterString) {
52
52
  filter = filter.substring(unconventional_pg_queries_1.AndOr.Or.length + 1);
53
53
  andOr = unconventional_pg_queries_1.AndOr.Or;
54
54
  }
55
- let field = filter.substring(0, filter.indexOf(' '));
56
- let value = filter.substring(filter.lastIndexOf(' ') + 1);
57
- let operator = filter.substring(filter.indexOf(' ') + 1, filter.lastIndexOf(' '));
55
+ const singleQuoteIndex = filter.indexOf("'");
56
+ const matchingOperators = singleQuoteIndex === -1 ?
57
+ db_types_1.ValidSqlOperators.filter(op => filter.includes(` ${op}`)) :
58
+ db_types_1.ValidSqlOperators.filter(op => filter.includes(` ${op}`) && filter.indexOf(` ${op}`) < singleQuoteIndex);
59
+ if (!matchingOperators.length)
60
+ throw api_error_1.APIError.errInvalidQueryParameter(`No valid operator in filter: '${filter}'`);
61
+ // Handle when multiple operators are present in the filter (e.g. LIKE and NOT LIKE)
62
+ let operator = matchingOperators.sort((a, b) => b.length - a.length)[0];
63
+ let field = filter.substring(0, filter.indexOf(operator)).trim();
64
+ let value = filter.substring(filter.indexOf(operator) + operator.length).trim();
58
65
  let jsonPath = [];
59
66
  // Handle IS NULL and IS NOT NULL, which don't have values
60
67
  if (operator.startsWith('IS')) {
61
- operator = `${operator} ${value}`;
62
68
  value = null;
63
69
  }
64
70
  // Handle JSON path
@@ -68,8 +74,6 @@ function getWhere(model, filterString) {
68
74
  }
69
75
  if (!propSummary[field])
70
76
  throw api_error_1.APIError.errInvalidQueryParameter(`Invalid filter: '${field}'`);
71
- if (!db_types_1.ValidSqlOperators.includes(operator))
72
- throw api_error_1.APIError.errInvalidQueryParameter(`Invalid operator in filter: '${operator}'`);
73
77
  if (!value && !db_types_1.NullSqlOperators.includes(operator))
74
78
  throw api_error_1.APIError.errInvalidQueryParameter(`Invalid value in filter: '${value}'`);
75
79
  wheres.push({ field, jsonPath, operator: operator, value, andOr });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unconventional",
3
- "version": "0.0.12",
3
+ "version": "1.0.0",
4
4
  "description": "A complete server built on Cloudflare Pages Functions",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -41,14 +41,14 @@
41
41
  "docs:serve": "vitepress serve docs"
42
42
  },
43
43
  "peerDependencies": {
44
- "hono": "^3.11.5",
44
+ "hono": "^4",
45
45
  "unconventional-pg-queries": "^0.0.6"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@cloudflare/workers-types": "^4.20231121.0",
49
49
  "@typescript-eslint/eslint-plugin": "^5.62.0",
50
50
  "@typescript-eslint/parser": "^5.62.0",
51
- "hono": "^3.11.5",
51
+ "hono": "^4",
52
52
  "typescript": "^5.3.3",
53
53
  "unconventional-pg-queries": "^0.0.6"
54
54
  }