@autofleet/sheilta 1.3.8-beta.1 → 1.3.9

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.
@@ -6,11 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
7
  const common_types_1 = require("@autofleet/common-types");
8
8
  const utils_1 = require("../utils");
9
+ const operators_1 = require("../operators");
9
10
  const DEFAULT_ORDER = 'id';
10
11
  const DESCENDING_KEY = 'DESC';
11
12
  const ASCENDING_KEY = 'ASC';
12
13
  const CUSTOM_FIELDS_QUERY_PREFIX = 'customFields.';
13
14
  const { CUSTOM_FIELDS_FILTER_SCOPE, CUSTOM_FIELDS_SORT_SCOPE } = common_types_1.customFields;
15
+ const parseCustomFieldScopeQueryValue = (value) => {
16
+ if (typeof value === 'string') {
17
+ return value;
18
+ }
19
+ return Object.entries(value).map(([operator, conditionValue]) => ({
20
+ operator: operators_1.OPERATORS_TO_SQL[operator],
21
+ value: conditionValue,
22
+ }));
23
+ };
14
24
  const getAttributeFromOrder = (order, options = {}) => {
15
25
  const { literalAttributes = [], DBFormatter = undefined } = options;
16
26
  const [formattedOrder, attributes] = order.reduce((acc, o) => {
@@ -31,8 +41,7 @@ const formatOrder = ({ order, associationModels = [], }) => {
31
41
  const formattedOrders = [];
32
42
  const orderScopesMap = new Map();
33
43
  order.forEach((o) => {
34
- if (o.startsWith(CUSTOM_FIELDS_QUERY_PREFIX) ||
35
- o.substring(1).startsWith(CUSTOM_FIELDS_QUERY_PREFIX)) {
44
+ if ([o, o.substring(1)].some(t => t.startsWith(CUSTOM_FIELDS_QUERY_PREFIX))) {
36
45
  if (!orderScopesMap.has(CUSTOM_FIELDS_SORT_SCOPE)) {
37
46
  orderScopesMap.set(CUSTOM_FIELDS_SORT_SCOPE, {});
38
47
  }
@@ -87,7 +96,8 @@ const formatQuery = (query, associationModels) => {
87
96
  formattedScopeMap.set(CUSTOM_FIELDS_FILTER_SCOPE, {});
88
97
  }
89
98
  const scopeKey = queryItemKey.split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
90
- formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] = queryItemValue;
99
+ formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] =
100
+ parseCustomFieldScopeQueryValue(queryItemValue);
91
101
  return;
92
102
  }
93
103
  const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
@@ -1,3 +1,20 @@
1
1
  export declare const OPERATORS: string[];
2
2
  export declare const OPERATOR_PREFIX = "$";
3
+ export declare const OPERATORS_TO_SQL: {
4
+ $eq: string;
5
+ $ne: string;
6
+ $gte: string;
7
+ $gt: string;
8
+ $lte: string;
9
+ $lt: string;
10
+ $not: string;
11
+ $in: string;
12
+ $notIn: string;
13
+ $is: string;
14
+ $like: string;
15
+ $iLike: string;
16
+ $notLike: string;
17
+ $and: string;
18
+ $or: string;
19
+ };
3
20
  export declare const formatOperators: (Sequelize: any) => {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatOperators = exports.OPERATOR_PREFIX = exports.OPERATORS = void 0;
3
+ exports.formatOperators = exports.OPERATORS_TO_SQL = exports.OPERATOR_PREFIX = exports.OPERATORS = void 0;
4
4
  exports.OPERATORS = [
5
5
  'eq',
6
6
  'ne',
@@ -22,6 +22,23 @@ exports.OPERATORS = [
22
22
  'contains',
23
23
  ];
24
24
  exports.OPERATOR_PREFIX = '$';
25
+ exports.OPERATORS_TO_SQL = {
26
+ $eq: '=',
27
+ $ne: '!=',
28
+ $gte: '>=',
29
+ $gt: '>',
30
+ $lte: '<=',
31
+ $lt: '<',
32
+ $not: 'NOT',
33
+ $in: 'IN',
34
+ $notIn: 'NOT IN',
35
+ $is: 'IS',
36
+ $like: 'LIKE',
37
+ $iLike: 'ILIKE',
38
+ $notLike: 'NOT LIKE',
39
+ $and: 'AND',
40
+ $or: 'OR',
41
+ };
25
42
  exports.formatOperators = (Sequelize) => {
26
43
  const { Op } = Sequelize;
27
44
  return exports.OPERATORS.reduce((map, o) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.3.8-beta.1",
3
+ "version": "1.3.9",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,7 +11,23 @@
11
11
  "test": "jest --forceExit --runInBand",
12
12
  "test-auto": "jest --watch --runInBand",
13
13
  "linter": "./node_modules/.bin/eslint src/**/*.ts",
14
- "build-to-local-repo": "npm run build && cp -r lib/* ../task-ms/node_modules/$npm_package_name/lib"
14
+ "build-to-local-repo": "npm run build && cp -r lib/* ../$REPO/node_modules/$npm_package_name/lib",
15
+ "watch": "npm-watch build-to-local-repo"
16
+ },
17
+ "watch": {
18
+ "build-to-local-repo": {
19
+ "extensions": [
20
+ "js",
21
+ "jsx",
22
+ "ts",
23
+ "tsx",
24
+ "css"
25
+ ],
26
+ "patterns": [
27
+ "src"
28
+ ],
29
+ "quiet": false
30
+ }
15
31
  },
16
32
  "jest": {
17
33
  "setupTestFrameworkScriptFile": "jest-extended",