@autofleet/sheilta 1.3.4-beta.2 → 1.3.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.
@@ -5,7 +5,6 @@ export declare type FormatPayloadOptions = {
5
5
  includeRawPayload?: boolean;
6
6
  literalAttributes?: LiteralAttribute[];
7
7
  DBFormatter?: any;
8
- skipSearchTermFormat?: boolean;
9
8
  };
10
9
  declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
11
10
  order?: any[];
@@ -43,7 +43,13 @@ const formatOrder = ({ order, associationModels = [], }) => order.map((o) => {
43
43
  const formatPage = page => page || utils_1.PAGE_DEFAULT;
44
44
  const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
45
45
  const formatInclude = (include, associationsMap = {}) => {
46
- let formattedInclude = include.map(i => (Object.assign(Object.assign({}, i), { association: associationsMap[i.association || i.model], required: i.required !== false })));
46
+ let formattedInclude = include.map((i) => {
47
+ var _a;
48
+ const includedAssociation = associationsMap[i.association || i.model];
49
+ return Object.assign(Object.assign(Object.assign({}, i), { association: includedAssociation, required: i.required !== false }), (i.include && {
50
+ include: formatInclude(i.include, (_a = includedAssociation === null || includedAssociation === void 0 ? void 0 : includedAssociation.target) === null || _a === void 0 ? void 0 : _a.associations),
51
+ }));
52
+ });
47
53
  formattedInclude = formattedInclude.map(i => lodash_1.default.omit(i, ['model']));
48
54
  return formattedInclude;
49
55
  };
@@ -59,9 +65,9 @@ const formatQuery = (query, associationModels) => {
59
65
  formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] = queryItemValue;
60
66
  return;
61
67
  }
62
- const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
63
- ? utils_1.wrapAttributeWithOperator(queryItemKey)
64
- : queryItemKey;
68
+ const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels) ?
69
+ utils_1.wrapAttributeWithOperator(queryItemKey) :
70
+ queryItemKey;
65
71
  formattedQuery[key] = queryItemValue;
66
72
  });
67
73
  const formattedScopes = Array.from(formattedScopeMap.entries()).map(([scopeName, scopeValue]) => {
@@ -98,7 +104,7 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
98
104
  const formattedPerPage = formatPerPage(perPage);
99
105
  const result = formatQuery(query, associationModels);
100
106
  let { formattedQuery } = result;
101
- if (searchTerm && !(options === null || options === void 0 ? void 0 : options.skipSearchTermFormat)) {
107
+ if (searchTerm) {
102
108
  const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
103
109
  const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
104
110
  formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.3.4-beta.2",
3
+ "version": "1.3.4",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",