@autofleet/sheilta 1.4.0-beta.2.1 → 1.4.0-beta.4
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.d.ts +6 -1
- package/lib/formatter/index.js +27 -25
- package/package.json +2 -2
package/lib/formatter/index.d.ts
CHANGED
|
@@ -16,10 +16,15 @@ export declare type ConditionValue = ConditionWithOperator | ConditionWithOperat
|
|
|
16
16
|
* Generates replacements for the given conditions.
|
|
17
17
|
*
|
|
18
18
|
* @param conditions - The conditions to generate replacements for.
|
|
19
|
-
* @param name - The model type name used to join custom_field_definitions.
|
|
20
19
|
* @returns The replacements object.
|
|
21
20
|
*/
|
|
22
21
|
export declare const generateFilterReplacements: (conditions: Record<string, ConditionValue>) => Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Generates replacements for the given order array.
|
|
24
|
+
*
|
|
25
|
+
* @param order - The order array to generate replacements for.
|
|
26
|
+
* @returns The replacements object.
|
|
27
|
+
*/
|
|
23
28
|
export declare const generateOrderReplacements: (order: string[]) => Record<string, string>;
|
|
24
29
|
declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
|
|
25
30
|
order?: any[];
|
package/lib/formatter/index.js
CHANGED
|
@@ -42,52 +42,60 @@ const getAttributeFromOrder = (order, options = {}) => {
|
|
|
42
42
|
* Generates replacements for the given conditions.
|
|
43
43
|
*
|
|
44
44
|
* @param conditions - The conditions to generate replacements for.
|
|
45
|
-
* @param name - The model type name used to join custom_field_definitions.
|
|
46
45
|
* @returns The replacements object.
|
|
47
46
|
*/
|
|
48
47
|
exports.generateFilterReplacements = (conditions) => {
|
|
49
48
|
const replacements = {};
|
|
50
|
-
console.log('sheilta - conditions:', conditions);
|
|
51
49
|
Object.entries(conditions).forEach(([key, condition]) => {
|
|
52
|
-
const
|
|
53
|
-
|
|
50
|
+
const replacementKey = utils_1.generateRandomString();
|
|
51
|
+
// eslint-disable-next-line prefer-destructuring
|
|
52
|
+
replacements[replacementKey] = key.split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
54
53
|
if (Array.isArray(condition)) {
|
|
55
54
|
condition.forEach((value) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
replacements[`${valRandom}`] = `${value}`;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const valRep = utils_1.generateRandomString();
|
|
62
|
-
replacements[valRep] = `${value.value}`;
|
|
63
|
-
}
|
|
55
|
+
const valueKey = utils_1.generateRandomString();
|
|
56
|
+
replacements[valueKey] = typeof value === 'string' ? value : value.value;
|
|
64
57
|
});
|
|
65
58
|
}
|
|
66
|
-
else if (typeof condition === 'string') {
|
|
67
|
-
const
|
|
68
|
-
replacements[
|
|
59
|
+
else if (typeof condition === 'string' || typeof condition === 'number') {
|
|
60
|
+
const conditionKey = utils_1.generateRandomString();
|
|
61
|
+
replacements[conditionKey] = condition;
|
|
69
62
|
}
|
|
70
63
|
else if (condition === null || condition === void 0 ? void 0 : condition.operator) {
|
|
71
|
-
const
|
|
72
|
-
replacements[
|
|
64
|
+
const operatorKey = utils_1.generateRandomString();
|
|
65
|
+
replacements[operatorKey] = condition.value;
|
|
73
66
|
}
|
|
74
67
|
});
|
|
75
68
|
return replacements;
|
|
76
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Generates replacements for the given order array.
|
|
72
|
+
*
|
|
73
|
+
* @param order - The order array to generate replacements for.
|
|
74
|
+
* @returns The replacements object.
|
|
75
|
+
*/
|
|
77
76
|
exports.generateOrderReplacements = (order) => {
|
|
78
77
|
const replacementMap = {};
|
|
79
78
|
order.forEach((o) => {
|
|
80
79
|
if (o.startsWith(CUSTOM_FIELDS_QUERY_PREFIX)) {
|
|
81
80
|
const rand = utils_1.generateRandomString();
|
|
82
|
-
|
|
81
|
+
// eslint-disable-next-line prefer-destructuring
|
|
82
|
+
replacementMap[rand] = o.split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
83
83
|
}
|
|
84
84
|
else if (o.substring(1).startsWith(CUSTOM_FIELDS_QUERY_PREFIX)) {
|
|
85
85
|
const rand = utils_1.generateRandomString();
|
|
86
|
-
|
|
86
|
+
// eslint-disable-next-line prefer-destructuring
|
|
87
|
+
replacementMap[rand] = o.substring(1).split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
return replacementMap;
|
|
90
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Creates a combined replacement map from order and query.
|
|
94
|
+
*
|
|
95
|
+
* @param order - The order array.
|
|
96
|
+
* @param query - The query object.
|
|
97
|
+
* @returns The combined replacements object.
|
|
98
|
+
*/
|
|
91
99
|
const createReplacementMap = (order, query) => (Object.assign(Object.assign({}, exports.generateOrderReplacements(order)), exports.generateFilterReplacements(query)));
|
|
92
100
|
const formatOrder = ({ order, associationModels = [], replacementsMap = {}, }) => {
|
|
93
101
|
const formattedOrders = [];
|
|
@@ -215,12 +223,6 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
215
223
|
],
|
|
216
224
|
};
|
|
217
225
|
}
|
|
218
|
-
console.log('🐶');
|
|
219
|
-
console.log('scopes:', [...orderScopes, ...queryScopes]);
|
|
220
|
-
[...orderScopes, ...queryScopes].map((scope) => {
|
|
221
|
-
console.log('scope:', scope.method[0]);
|
|
222
|
-
console.log('scope:', scope.method[1]);
|
|
223
|
-
});
|
|
224
226
|
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: [...queryScopes, ...orderScopes] }, (formattedAttribute && { attributes: formattedAttribute }));
|
|
225
227
|
};
|
|
226
228
|
exports.default = formatPayload;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sheilta",
|
|
3
|
-
"version": "1.4.0-beta.
|
|
3
|
+
"version": "1.4.0-beta.4",
|
|
4
4
|
"description": "manage cache",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
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/*
|
|
14
|
+
"build-to-local-repo": "npm run build && cp -r lib/* ../task-ms/node_modules/@autofleet/sheilta/lib",
|
|
15
15
|
"watch": "npm-watch build-to-local-repo"
|
|
16
16
|
},
|
|
17
17
|
"watch": {
|