unconventional 0.0.11 → 0.0.13

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.
@@ -112,6 +112,7 @@ class BaseService {
112
112
  throw api_error_1.APIError.errNotFound(`No ${this.model.name} found with id ${identifier}`);
113
113
  }
114
114
  else if (config?.cache) {
115
+ await base_cache_1.BaseCache.clearPage(config.cache, this.model);
115
116
  await base_cache_1.BaseCache.clearModel(config.cache, response);
116
117
  await base_cache_1.BaseCache.setModel(config.cache, response, undefined, config.cacheTTL);
117
118
  }
@@ -129,6 +130,7 @@ class BaseService {
129
130
  }
130
131
  else if (config?.cache) {
131
132
  const cache = config.cache;
133
+ await base_cache_1.BaseCache.clearPage(cache, this.model);
132
134
  await Promise.all(response.map(item => base_cache_1.BaseCache.clearModel(cache, item)));
133
135
  await Promise.all(response.map(item => base_cache_1.BaseCache.setModel(cache, item, undefined, config.cacheTTL)));
134
136
  }
@@ -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.11",
3
+ "version": "0.0.13",
4
4
  "description": "A complete server built on Cloudflare Pages Functions",
5
5
  "keywords": [
6
6
  "cloudflare",