@autofleet/sheilta 1.3.2 → 1.3.4-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.d.ts +3 -2
- package/lib/formatter/index.js +4 -4
- package/lib/index.d.ts +2 -2
- package/lib/middleware/index.d.ts +6 -3
- package/lib/utils.js +2 -2
- package/package.json +2 -2
package/lib/formatter/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiteralAttribute } from '../middleware';
|
|
2
2
|
declare type OrderItem = string | [string, string];
|
|
3
3
|
declare type SequelizeOrder = string | OrderItem[];
|
|
4
4
|
export declare type FormatPayloadOptions = {
|
|
5
5
|
includeRawPayload?: boolean;
|
|
6
|
-
literalAttributes?:
|
|
6
|
+
literalAttributes?: LiteralAttribute[];
|
|
7
7
|
DBFormatter?: any;
|
|
8
|
+
skipSearchTermQuery?: boolean;
|
|
8
9
|
};
|
|
9
10
|
declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
|
|
10
11
|
order?: any[];
|
package/lib/formatter/index.js
CHANGED
|
@@ -59,9 +59,9 @@ const formatQuery = (query, associationModels) => {
|
|
|
59
59
|
formattedScopeMap.get(CUSTOM_FIELDS_FILTER_SCOPE)[scopeKey] = queryItemValue;
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
|
|
63
|
-
utils_1.wrapAttributeWithOperator(queryItemKey)
|
|
64
|
-
queryItemKey;
|
|
62
|
+
const key = utils_1.isAttributeByAssociation(queryItemKey, associationModels)
|
|
63
|
+
? utils_1.wrapAttributeWithOperator(queryItemKey)
|
|
64
|
+
: queryItemKey;
|
|
65
65
|
formattedQuery[key] = queryItemValue;
|
|
66
66
|
});
|
|
67
67
|
const formattedScopes = Array.from(formattedScopeMap.entries()).map(([scopeName, scopeValue]) => {
|
|
@@ -98,7 +98,7 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
98
98
|
const formattedPerPage = formatPerPage(perPage);
|
|
99
99
|
const result = formatQuery(query, associationModels);
|
|
100
100
|
let { formattedQuery } = result;
|
|
101
|
-
if (searchTerm) {
|
|
101
|
+
if (searchTerm && !(options === null || options === void 0 ? void 0 : options.skipSearchTermQuery)) {
|
|
102
102
|
const attributesToSend = (attributes === null || attributes === void 0 ? void 0 : attributes.length) ? attributes : Object.keys(model.rawAttributes);
|
|
103
103
|
const queryWithSearchTerm = formatSearchTerm(searchTerm, attributesToSend, model.rawAttributes);
|
|
104
104
|
formattedQuery = lodash_1.default.isEmpty(formattedQuery) ? queryWithSearchTerm : {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { formatOperators } from './operators';
|
|
2
|
-
import { queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption } from './middleware';
|
|
3
|
-
export { formatOperators, queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, };
|
|
2
|
+
import { queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, LiteralAttribute } from './middleware';
|
|
3
|
+
export { formatOperators, queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, LiteralAttribute, };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { FormatPayloadOptions } from '../formatter';
|
|
2
|
-
|
|
2
|
+
declare type literal = any;
|
|
3
|
+
declare type LiteralQuery = (literal | string)[] | literal;
|
|
4
|
+
export declare type LiteralAttribute = {
|
|
3
5
|
attribute: string;
|
|
4
|
-
literal:
|
|
6
|
+
literal: LiteralQuery;
|
|
5
7
|
};
|
|
6
8
|
export declare type MiddlewareValidationOption = {
|
|
7
|
-
literalAttributes?:
|
|
9
|
+
literalAttributes?: LiteralAttribute[];
|
|
8
10
|
};
|
|
9
11
|
export declare const newQueryValidationMiddleware: (inner?: string) => (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
|
|
10
12
|
export declare const newQueryFormatMiddleware: (inner?: string) => (model: any, options?: FormatPayloadOptions) => (req: any, res: any, next: any) => Promise<void>;
|
|
11
13
|
export declare const queryValidationMiddleware: (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
|
|
12
14
|
export declare const queryFormatMiddleware: (model: any, options?: FormatPayloadOptions) => (req: any, res: any, next: any) => Promise<void>;
|
|
15
|
+
export {};
|
package/lib/utils.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.PAGE_DEFAULT = 1;
|
|
|
10
10
|
exports.PER_PAGE_MAX_LIMIT = 100;
|
|
11
11
|
exports.PER_PAGE_MIN_LIMIT = 1;
|
|
12
12
|
exports.PAGE_MIN = 1;
|
|
13
|
-
exports.wrapAttributeWithOperator = attribute => `${operators_1.OPERATOR_PREFIX}${attribute}${operators_1.OPERATOR_PREFIX}`;
|
|
13
|
+
exports.wrapAttributeWithOperator = (attribute) => `${operators_1.OPERATOR_PREFIX}${attribute}${operators_1.OPERATOR_PREFIX}`;
|
|
14
14
|
exports.isAttributeByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
|
|
15
15
|
&& associatedModels.includes(attributeName.split(exports.ASSOCIATION_PREFIX)[0]);
|
|
16
16
|
exports.extractAttributeNameFromOrder = (order, associationModels) => {
|
|
@@ -26,6 +26,6 @@ exports.extractAttributeNameFromOrder = (order, associationModels) => {
|
|
|
26
26
|
};
|
|
27
27
|
exports.isOrderDesc = (order) => order.includes(exports.ORDER_PREFIX);
|
|
28
28
|
exports.throwBadRequestError = (message) => {
|
|
29
|
-
throw new errors_1.BadRequest([{ message }], null);
|
|
29
|
+
throw new errors_1.BadRequest([{ message, name: 'badRequestError' }], null);
|
|
30
30
|
};
|
|
31
31
|
exports.extractAssociatedAttributeNameFromOrder = (order) => order.split(exports.ASSOCIATION_PREFIX)[1];
|
package/package.json
CHANGED