@autofleet/sheilta 1.3.7-beta.0 → 1.3.8-beta.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.
- package/lib/formatter/index.js +12 -1
- package/lib/operators/index.d.ts +17 -0
- package/lib/operators/index.js +18 -1
- package/package.json +19 -2
package/lib/formatter/index.js
CHANGED
|
@@ -6,10 +6,20 @@ 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 CUSTOM_FIELDS_QUERY_PREFIX = 'customFields.';
|
|
12
13
|
const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
|
|
14
|
+
const parseCustomFieldScopeQueryValue = (value) => {
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return Object.entries(value).map(([operator, conditionValue]) => ({
|
|
19
|
+
operator: operators_1.OPERATORS_TO_SQL[operator],
|
|
20
|
+
value: conditionValue,
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
13
23
|
const getAttributeFromOrder = (order, options = {}) => {
|
|
14
24
|
const { literalAttributes = [], DBFormatter = undefined } = options;
|
|
15
25
|
const [formattedOrder, attributes] = order.reduce((acc, o) => {
|
|
@@ -62,7 +72,8 @@ const formatQuery = (query, associationModels) => {
|
|
|
62
72
|
formattedScopeMap.set(CUSTOM_FIELDS_FILTER_SCOPE, {});
|
|
63
73
|
}
|
|
64
74
|
const scopeKey = queryItemKey.split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
65
|
-
formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] =
|
|
75
|
+
formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] =
|
|
76
|
+
parseCustomFieldScopeQueryValue(queryItemValue);
|
|
66
77
|
return;
|
|
67
78
|
}
|
|
68
79
|
const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
|
package/lib/operators/index.d.ts
CHANGED
|
@@ -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) => {};
|
package/lib/operators/index.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "1.3.8-beta.0",
|
|
4
4
|
"description": "manage cache",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -10,7 +10,24 @@
|
|
|
10
10
|
"coverage": "jest --coverage --forceExit --runInBand",
|
|
11
11
|
"test": "jest --forceExit --runInBand",
|
|
12
12
|
"test-auto": "jest --watch --runInBand",
|
|
13
|
-
"linter": "./node_modules/.bin/eslint src/**/*.ts"
|
|
13
|
+
"linter": "./node_modules/.bin/eslint src/**/*.ts",
|
|
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
|
+
}
|
|
14
31
|
},
|
|
15
32
|
"jest": {
|
|
16
33
|
"setupTestFrameworkScriptFile": "jest-extended",
|