@autofleet/sheilta 1.3.2-9 → 1.3.3

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.
@@ -1,9 +1,9 @@
1
- import type { Attribute } from '../interface';
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?: Attribute[];
6
+ literalAttributes?: LiteralAttribute[];
7
7
  DBFormatter?: any;
8
8
  };
9
9
  declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
@@ -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;
@@ -108,7 +108,6 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
108
108
  ],
109
109
  };
110
110
  }
111
- const selectedAttributes = formattedAttribute ? { attributes: formattedAttribute } : {};
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';
4
- export { formatOperators, queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, };
2
+ import { queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, LiteralAttribute } from './middleware';
3
+ export { formatOperators, queryFormatMiddleware, queryValidationMiddleware, MiddlewareValidationOption, LiteralAttribute, };
@@ -1,6 +1,15 @@
1
1
  import { FormatPayloadOptions } from '../formatter';
2
- import { MiddlewareValidationOption } from '../interface';
2
+ declare type literal = any;
3
+ declare type LiteralQuery = (literal | string)[] | literal;
4
+ export declare type LiteralAttribute = {
5
+ attribute: string;
6
+ literal: LiteralQuery;
7
+ };
8
+ export declare type MiddlewareValidationOption = {
9
+ literalAttributes?: LiteralAttribute[];
10
+ };
3
11
  export declare const newQueryValidationMiddleware: (inner?: string) => (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
4
12
  export declare const newQueryFormatMiddleware: (inner?: string) => (model: any, options?: FormatPayloadOptions) => (req: any, res: any, next: any) => Promise<void>;
5
13
  export declare const queryValidationMiddleware: (model: any, options?: MiddlewareValidationOption) => (req: any, res: any, next: any) => Promise<void>;
6
14
  export declare const queryFormatMiddleware: (model: any, options?: FormatPayloadOptions) => (req: any, res: any, next: any) => Promise<void>;
15
+ export {};
@@ -1,4 +1,4 @@
1
- import { MiddlewareValidationOption } from '../interface';
1
+ import type { MiddlewareValidationOption } from '../middleware';
2
2
  export declare const validatePayload: ({ query, order, attributes, include, page, perPage, }: {
3
3
  query?: {};
4
4
  order?: any[];
@@ -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-9",
3
+ "version": "1.3.3",
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
  },
@@ -1,7 +0,0 @@
1
- export declare type Attribute = {
2
- attribute: string;
3
- literal: any;
4
- };
5
- export declare type MiddlewareValidationOption = {
6
- literalAttributes?: Attribute[];
7
- };
package/lib/interface.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });