@autofleet/sheilta 1.4.0-beta.1 → 1.4.0-beta.2
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 +7 -1
- package/lib/formatter/index.js +31 -38
- package/lib/utils.js +1 -1
- package/package.json +2 -2
package/lib/formatter/index.d.ts
CHANGED
|
@@ -16,10 +16,16 @@ 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
|
+
*/
|
|
28
|
+
export declare const generateOrderReplacements: (order: string[]) => Record<string, string>;
|
|
23
29
|
declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
|
|
24
30
|
order?: any[];
|
|
25
31
|
page?: number;
|
package/lib/formatter/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateFilterReplacements = void 0;
|
|
6
|
+
exports.generateOrderReplacements = exports.generateFilterReplacements = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const common_types_1 = require("@autofleet/common-types");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
@@ -42,56 +42,55 @@ 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
|
-
replacements[
|
|
50
|
+
const replacementKey = utils_1.generateRandomString();
|
|
51
|
+
replacements[replacementKey] = key.split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
54
52
|
if (Array.isArray(condition)) {
|
|
55
53
|
condition.forEach((value) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
replacements[`${valRandom}`] = `${value}`;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const valRep = utils_1.generateRandomString();
|
|
62
|
-
replacements[valRep] = `${value.value}`;
|
|
63
|
-
}
|
|
54
|
+
const valueKey = utils_1.generateRandomString();
|
|
55
|
+
replacements[valueKey] = typeof value === 'string' ? value : value.value;
|
|
64
56
|
});
|
|
65
57
|
}
|
|
66
58
|
else if (typeof condition === 'string') {
|
|
67
|
-
const
|
|
68
|
-
replacements[
|
|
59
|
+
const conditionKey = utils_1.generateRandomString();
|
|
60
|
+
replacements[conditionKey] = condition;
|
|
69
61
|
}
|
|
70
62
|
else if (condition === null || condition === void 0 ? void 0 : condition.operator) {
|
|
71
|
-
const
|
|
72
|
-
replacements[
|
|
63
|
+
const operatorKey = utils_1.generateRandomString();
|
|
64
|
+
replacements[operatorKey] = condition.value;
|
|
73
65
|
}
|
|
74
66
|
});
|
|
75
67
|
return replacements;
|
|
76
68
|
};
|
|
77
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Generates replacements for the given order array.
|
|
71
|
+
*
|
|
72
|
+
* @param order - The order array to generate replacements for.
|
|
73
|
+
* @returns The replacements object.
|
|
74
|
+
*/
|
|
75
|
+
exports.generateOrderReplacements = (order) => {
|
|
78
76
|
const replacementMap = {};
|
|
79
|
-
order.forEach((
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const rand = utils_1.generateRandomString();
|
|
86
|
-
replacementMap[o.substring(1).split(CUSTOM_FIELDS_QUERY_PREFIX)[1]] = rand;
|
|
87
|
-
}
|
|
77
|
+
order.forEach((item) => {
|
|
78
|
+
const itemKey = item.startsWith(CUSTOM_FIELDS_QUERY_PREFIX)
|
|
79
|
+
? item.split(CUSTOM_FIELDS_QUERY_PREFIX)[1]
|
|
80
|
+
: item.substring(1).split(CUSTOM_FIELDS_QUERY_PREFIX)[1];
|
|
81
|
+
const randomValue = utils_1.generateRandomString();
|
|
82
|
+
replacementMap[itemKey] = randomValue;
|
|
88
83
|
});
|
|
89
|
-
|
|
90
|
-
console.log('query:', query);
|
|
91
|
-
const queryReplacements = exports.generateFilterReplacements(query);
|
|
92
|
-
console.log('queryReplacements:', queryReplacements);
|
|
93
|
-
return Object.assign(Object.assign({}, replacementMap), queryReplacements);
|
|
84
|
+
return replacementMap;
|
|
94
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Creates a combined replacement map from order and query.
|
|
88
|
+
*
|
|
89
|
+
* @param order - The order array.
|
|
90
|
+
* @param query - The query object.
|
|
91
|
+
* @returns The combined replacements object.
|
|
92
|
+
*/
|
|
93
|
+
const createReplacementMap = (order, query) => (Object.assign(Object.assign({}, exports.generateOrderReplacements(order)), exports.generateFilterReplacements(query)));
|
|
95
94
|
const formatOrder = ({ order, associationModels = [], replacementsMap = {}, }) => {
|
|
96
95
|
const formattedOrders = [];
|
|
97
96
|
const orderScopesMap = new Map();
|
|
@@ -218,12 +217,6 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
218
217
|
],
|
|
219
218
|
};
|
|
220
219
|
}
|
|
221
|
-
console.log('🐶');
|
|
222
|
-
console.log('scopes:', [...orderScopes, ...queryScopes]);
|
|
223
|
-
[...orderScopes, ...queryScopes].map((scope) => {
|
|
224
|
-
console.log('scope:', scope.method[0]);
|
|
225
|
-
console.log('scope:', scope.method[1]);
|
|
226
|
-
});
|
|
227
220
|
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: [...queryScopes, ...orderScopes] }, (formattedAttribute && { attributes: formattedAttribute }));
|
|
228
221
|
};
|
|
229
222
|
exports.default = formatPayload;
|
package/lib/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRandomString = exports.extractAssociatedAttributeNameFromOrder = exports.throwBadRequestError = exports.isOrderDesc = exports.extractAttributeNameFromOrder = exports.isAttributeByAssociation = exports.wrapAttributeWithOperator = exports.PAGE_MIN = exports.PER_PAGE_MIN_LIMIT = exports.PER_PAGE_MAX_LIMIT = exports.PAGE_DEFAULT = exports.PER_PAGE_DEFAULT = exports.ASSOCIATION_PREFIX = exports.ORDER_PREFIX = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
4
5
|
const errors_1 = require("@autofleet/errors");
|
|
5
6
|
const operators_1 = require("./operators");
|
|
6
|
-
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
exports.ORDER_PREFIX = '-';
|
|
8
8
|
exports.ASSOCIATION_PREFIX = '.';
|
|
9
9
|
exports.PER_PAGE_DEFAULT = 20;
|
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.2",
|
|
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/* ../$REPO/node_modules/$npm_package_name/lib",
|
|
15
15
|
"watch": "npm-watch build-to-local-repo"
|
|
16
16
|
},
|
|
17
17
|
"watch": {
|