axe-api 1.0.0-rc7 → 1.0.0-rc9

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.
@@ -236,7 +236,7 @@ export interface AxeRequestResponsePair {
236
236
  axeResponse: AxeResponse;
237
237
  }
238
238
  export interface MiddlewareResolution {
239
- middlewares: MiddlewareFunction[];
239
+ middlewares: (MiddlewareFunction | HandlerFunction)[];
240
240
  handler: HandlerFunction;
241
241
  }
242
242
  export {};
@@ -9,8 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const Helpers_1 = require("../../Handlers/Helpers");
12
13
  exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  var _a, _b;
15
+ if (context.query && context.queryParser && context.conditions) {
16
+ // Users should be able to select some fields to show.
17
+ context.queryParser.applyFields(context.query, context.conditions.fields);
18
+ // Binding parent id if there is.
19
+ (0, Helpers_1.addForeignKeyQuery)(context.req, context.query, context.relation, context.parentModel);
20
+ // Users should be able to filter records
21
+ context.queryParser.applyWheres(context.query, context.conditions.q);
22
+ // User should be able to select sorting fields and types
23
+ context.queryParser.applySorting(context.query, context.conditions.sort);
24
+ }
14
25
  context.result = yield context.query.paginate({
15
26
  perPage: ((_a = context.conditions) === null || _a === void 0 ? void 0 : _a.per_page) || 10,
16
27
  currentPage: ((_b = context.conditions) === null || _b === void 0 ? void 0 : _b.page) || 1,
@@ -19,12 +19,4 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  context.query = context.database.from(context.model.instance.table);
20
20
  // If there is a deletedAtColumn, it means that this table support soft-delete
21
21
  (0, Helpers_1.addSoftDeleteQuery)(context.model, context.conditions, context.query);
22
- // Users should be able to select some fields to show.
23
- context.queryParser.applyFields(context.query, context.conditions.fields);
24
- // Binding parent id if there is.
25
- (0, Helpers_1.addForeignKeyQuery)(context.req, context.query, context.relation, context.parentModel);
26
- // Users should be able to filter records
27
- context.queryParser.applyWheres(context.query, context.conditions.q);
28
- // User should be able to select sorting fields and types
29
- context.queryParser.applySorting(context.query, context.conditions.sort);
30
22
  });
@@ -13,7 +13,7 @@ interface Pair {
13
13
  declare class URLService {
14
14
  private static urls;
15
15
  static add(method: string, pattern: string, data: IRouteData, middlewares: StepTypes[]): Promise<void>;
16
- static addHandler(method: string, pattern: string, customHandler: HandlerFunction, middlewares: MiddlewareFunction[]): Promise<void>;
16
+ static addHandler(method: string, pattern: string, customHandler: HandlerFunction, middlewares: (MiddlewareFunction | HandlerFunction)[]): Promise<void>;
17
17
  static match(request: AxeRequest): {
18
18
  params: any;
19
19
  method: string;
@@ -73,8 +73,15 @@ class URLService {
73
73
  isAsync: false,
74
74
  name: `middleware:test`,
75
75
  callback: (pack) => __awaiter(this, void 0, void 0, function* () {
76
- const caller = (0, util_1.promisify)((pack, next) => middleware(pack.req.original, pack.res.original, next));
77
- yield caller(pack);
76
+ if ((0, ConverterService_1.isMiddlewareFunction)(middleware)) {
77
+ // It should be wrapped
78
+ const caller = (0, util_1.promisify)((pack, next) => middleware(pack.req.original, pack.res.original, next));
79
+ yield caller(pack);
80
+ }
81
+ else {
82
+ // We call it directly.
83
+ yield middleware(pack.req, pack.res);
84
+ }
78
85
  }),
79
86
  };
80
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.0.0-rc7",
3
+ "version": "1.0.0-rc9",
4
4
  "description": "AXE API is a simple tool to create Rest APIs quickly.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",