@autofleet/sheilta 1.3.2-8 → 1.3.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 +1 -11
- package/lib/formatter/index.js +2 -3
- package/lib/formatter/index.test.js +0 -1
- package/lib/index.d.ts +1 -2
- package/lib/middleware/index.d.ts +7 -1
- package/lib/validations/index.d.ts +1 -1
- package/lib/validations/index.js +1 -1
- package/package.json +1 -2
- package/lib/interface.d.ts +0 -7
- package/lib/interface.js +0 -2
package/lib/formatter/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attribute } from '../
|
|
1
|
+
import type { Attribute } from '../middleware';
|
|
2
2
|
declare type OrderItem = string | [string, string];
|
|
3
3
|
declare type SequelizeOrder = string | OrderItem[];
|
|
4
4
|
export declare type FormatPayloadOptions = {
|
|
@@ -26,15 +26,5 @@ declare const formatPayload: ({ order, page, perPage, include, query, attributes
|
|
|
26
26
|
scopes: (string | {
|
|
27
27
|
method: any[];
|
|
28
28
|
})[];
|
|
29
|
-
} | {
|
|
30
|
-
attributes?: undefined;
|
|
31
|
-
query: {};
|
|
32
|
-
order: SequelizeOrder[];
|
|
33
|
-
page: any;
|
|
34
|
-
perPage: any;
|
|
35
|
-
include: any;
|
|
36
|
-
scopes: (string | {
|
|
37
|
-
method: any[];
|
|
38
|
-
})[];
|
|
39
29
|
};
|
|
40
30
|
export default formatPayload;
|
package/lib/formatter/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const getAttributeFromOrder = (order, options = {}) => {
|
|
|
17
17
|
const found = literalAttributes === null || literalAttributes === void 0 ? void 0 : literalAttributes.find(obj => obj.attribute === item);
|
|
18
18
|
if (found) {
|
|
19
19
|
acc[1].push(found.literal);
|
|
20
|
-
acc[0].push([DBFormatter ? DBFormatter(
|
|
20
|
+
acc[0].push([DBFormatter ? DBFormatter(`"${found.attribute}" ${orderStyle}`) : `${found.attribute} ${orderStyle}`]);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
acc[0].push(o);
|
|
@@ -108,7 +108,6 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
108
108
|
],
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, selectedAttributes);
|
|
111
|
+
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: result.formattedScopes }, (formattedAttribute && { attributes: formattedAttribute }));
|
|
113
112
|
};
|
|
114
113
|
exports.default = formatPayload;
|
|
@@ -201,7 +201,6 @@ describe('formatting test', () => {
|
|
|
201
201
|
literalAttributes: [literalAttribute],
|
|
202
202
|
});
|
|
203
203
|
expect(JSON.stringify(order)).toBe(JSON.stringify([[`${literalAttribute.attribute} ASC`], ['id']]));
|
|
204
|
-
console.log({ attributes });
|
|
205
204
|
expect(JSON.stringify(attributes))
|
|
206
205
|
.toBe(JSON.stringify({ include: [literalAttribute.literal] }));
|
|
207
206
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { formatOperators } from './operators';
|
|
2
|
-
import { queryFormatMiddleware, queryValidationMiddleware } from './middleware';
|
|
3
|
-
import { MiddlewareValidationOption } from './interface';
|
|
2
|
+
import { queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption } from './middleware';
|
|
4
3
|
export { formatOperators, queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, };
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { FormatPayloadOptions } from '../formatter';
|
|
2
|
-
|
|
2
|
+
export declare type Attribute = {
|
|
3
|
+
attribute: string;
|
|
4
|
+
literal: any;
|
|
5
|
+
};
|
|
6
|
+
export declare type MiddlewareValidationOption = {
|
|
7
|
+
literalAttributes?: Attribute[];
|
|
8
|
+
};
|
|
3
9
|
export declare const newQueryValidationMiddleware: (inner?: string) => (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
|
|
4
10
|
export declare const newQueryFormatMiddleware: (inner?: string) => (model: any, options?: FormatPayloadOptions) => (req: any, res: any, next: any) => Promise<void>;
|
|
5
11
|
export declare const queryValidationMiddleware: (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
|
package/lib/validations/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const validateSingleOrder = (currentOrder, rawAttributes, associationModels, opt
|
|
|
26
26
|
[formattedOrderString] = formattedOrderString.split(utils_1.ASSOCIATION_PREFIX);
|
|
27
27
|
}
|
|
28
28
|
if (!(rawAttributes.includes(formattedOrderString) || isOrderAssociation || isLiteralAttribute)) {
|
|
29
|
-
utils_1.throwBadRequestError(`${currentOrder} is invalid isLiteralAttribute: ${isLiteralAttribute}`);
|
|
29
|
+
utils_1.throwBadRequestError(`${currentOrder} is invalid. isLiteralAttribute: ${isLiteralAttribute}`);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
const validateSingleAttribute = (currentAttribute, rawAttributes) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sheilta",
|
|
3
|
-
"version": "1.3.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "manage cache",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@autofleet/common-types": "^1.7.29",
|
|
31
31
|
"@autofleet/errors": "^1.0.10",
|
|
32
|
-
"@autofleet/sheilta": "^1.3.2-6",
|
|
33
32
|
"joi": "^17.9.2",
|
|
34
33
|
"lodash": "^4.17.21"
|
|
35
34
|
},
|
package/lib/interface.d.ts
DELETED
package/lib/interface.js
DELETED