@napp/dti-server 3.0.3 → 3.0.8

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.
Files changed (3) hide show
  1. package/adapter.d.ts +1 -0
  2. package/adapter.js +39 -25
  3. package/package.json +2 -2
package/adapter.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare class ServerInstance<RES, PQ, PB> {
27
27
  get path(): string;
28
28
  get queryMode(): string;
29
29
  get bodyMode(): string;
30
+ check(q: PQ, b: PB): void;
30
31
  before(funcs: Array<IMiddleware>): this;
31
32
  handle(action: IAction<RES, PQ, PB>): this;
32
33
  }
package/adapter.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4
- to[j] = from[i];
5
- return to;
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
6
10
  };
7
11
  Object.defineProperty(exports, "__esModule", { value: true });
8
12
  exports.ServerAdapter = exports.ServerInstance = void 0;
@@ -46,6 +50,10 @@ var ServerInstance = /** @class */ (function () {
46
50
  enumerable: false,
47
51
  configurable: true
48
52
  });
53
+ ServerInstance.prototype.check = function (q, b) {
54
+ this.meta.checkQ(q);
55
+ this.meta.checkB(b);
56
+ };
49
57
  ServerInstance.prototype.before = function (funcs) {
50
58
  this.beforeFuncs = funcs;
51
59
  return this;
@@ -93,22 +101,28 @@ var ServerAdapter = /** @class */ (function () {
93
101
  return req.query;
94
102
  };
95
103
  ServerAdapter.prototype.callAction = function (it, req, res, next) {
96
- if (it.actionFunc) {
97
- var q = this.qParam(it, req);
98
- var b = req.body;
99
- return it.actionFunc({ q: q, b: b }, { req: req, res: res })
100
- .then(function (rsu) {
101
- if (rsu instanceof response_1.DtiResponse) {
102
- if (rsu.handle) {
103
- return rsu.handle(res);
104
+ try {
105
+ if (it.actionFunc) {
106
+ var q = this.qParam(it, req);
107
+ var b = req.body;
108
+ it.check(q || {}, b || {});
109
+ return it.actionFunc({ q: q, b: b }, { req: req, res: res })
110
+ .then(function (rsu) {
111
+ if (rsu instanceof response_1.DtiResponse) {
112
+ if (rsu.handle) {
113
+ return rsu.handle(res);
114
+ }
115
+ return res.end();
104
116
  }
105
- return res.end();
106
- }
107
- return res.json(rsu);
108
- })
109
- .catch(function (err) { return next(err); });
117
+ return res.json(rsu);
118
+ })
119
+ .catch(function (err) { return next(err); });
120
+ }
121
+ throw new Error('not found action handle');
122
+ }
123
+ catch (error) {
124
+ return next(error);
110
125
  }
111
- return next(new Error('not found action handle'));
112
126
  };
113
127
  ServerAdapter.prototype.getBodyParser = function (it) {
114
128
  if (this.bodyParser) {
@@ -125,23 +139,23 @@ var ServerAdapter = /** @class */ (function () {
125
139
  var _loop_1 = function (it) {
126
140
  var befores = it.beforeFuncs || [];
127
141
  if (it.method === 'get') {
128
- _route.get(it.path, __spreadArray(__spreadArray([], befores), [function (req, res, next) {
142
+ _route.get(it.path, __spreadArray(__spreadArray([], befores, true), [function (req, res, next) {
129
143
  _this.callAction(it, req, res, next);
130
- }]));
144
+ }], false));
131
145
  }
132
146
  else if (it.method === 'post') {
133
147
  var bodyparser = this_1.getBodyParser(it);
134
148
  if (bodyparser.length === 0) {
135
- this_1.logger('warn', "not found body parser. name=\"" + it.name + "\"; bodyMode=\"" + it.bodyMode + "\"");
149
+ this_1.logger('warn', "not found body parser. name=\"".concat(it.name, "\"; bodyMode=\"").concat(it.bodyMode, "\""));
136
150
  }
137
- _route.post(it.path, __spreadArray(__spreadArray(__spreadArray([], bodyparser), befores), [function (req, res, next) {
151
+ _route.post(it.path, __spreadArray(__spreadArray(__spreadArray([], bodyparser, true), befores, true), [function (req, res, next) {
138
152
  _this.callAction(it, req, res, next);
139
- }]));
153
+ }], false));
140
154
  }
141
155
  else {
142
- this_1.logger('warn', "not supored method. \"" + it.method + "\"");
156
+ this_1.logger('warn', "not supored method. \"".concat(it.method, "\""));
143
157
  }
144
- this_1.logger('info', "[" + it.method + "] " + it.path);
158
+ this_1.logger('info', "[".concat(it.method, "] ").concat(it.path));
145
159
  };
146
160
  var this_1 = this;
147
161
  for (var _i = 0, _a = this.actions; _i < _a.length; _i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napp/dti-server",
3
- "version": "3.0.3",
3
+ "version": "3.0.8",
4
4
  "description": "data transaction interface server library",
5
5
  "types": "index.d.ts",
6
6
  "main": "index.js",
@@ -12,6 +12,6 @@
12
12
  "author": "Farcek <farcek@gmail.com>",
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
- "@napp/dti-core": "3.0.3"
15
+ "@napp/dti-core": "3.0.8"
16
16
  }
17
17
  }