express-ext 0.1.13 → 0.1.17

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.
@@ -41,7 +41,7 @@ var GenericSearchController = (function (_super) {
41
41
  }
42
42
  GenericSearchController.prototype.search = function (req, res) {
43
43
  var _this = this;
44
- var s = search_1.fromRequest(req, this.fields, this.excluding);
44
+ var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
45
45
  var l = search_1.getParameters(s, this.config);
46
46
  var s2 = search_1.format(s, this.dates, this.numbers);
47
47
  this.find(s2, l.limit, l.skipOrRefId, l.fields)
@@ -7,12 +7,12 @@ var HealthController = (function () {
7
7
  this.check = this.check.bind(this);
8
8
  }
9
9
  HealthController.prototype.check = function (req, res) {
10
- health_1.check(this.checkers).then(function (heath) {
11
- if (heath.status === 'UP') {
12
- return res.status(200).json(heath).end();
10
+ health_1.health(this.checkers).then(function (r) {
11
+ if (r.status === 'UP') {
12
+ return res.status(200).json(r).end();
13
13
  }
14
14
  else {
15
- return res.status(500).json(heath).end();
15
+ return res.status(500).json(r).end();
16
16
  }
17
17
  });
18
18
  };
@@ -45,7 +45,7 @@ var LoadController = (function () {
45
45
  var id = view_1.buildAndCheckId(req, res, this.keys);
46
46
  if (id) {
47
47
  this.view(id)
48
- .then(function (obj) { return http_1.respondModel(obj, res); })
48
+ .then(function (obj) { return http_1.respondModel(http_1.minimize(obj), res); })
49
49
  .catch(function (err) { return http_1.handleError(err, res, _this.log); });
50
50
  }
51
51
  };
@@ -48,7 +48,7 @@ var LoadSearchController = (function (_super) {
48
48
  }
49
49
  LoadSearchController.prototype.search = function (req, res) {
50
50
  var _this = this;
51
- var s = search_1.fromRequest(req, this.fields, this.excluding);
51
+ var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
52
52
  var l = search_1.getParameters(s, this.config);
53
53
  var s2 = search_1.format(s, this.dates, this.numbers);
54
54
  this.find(s2, l.limit, l.skipOrRefId, l.fields)
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.map = {
4
+ TRACE: -2,
5
+ DEBUG: -1,
6
+ INFO: 0,
7
+ WARN: 1,
8
+ ERROR: 2,
9
+ PANIC: 3,
10
+ FATAL: 4
11
+ };
3
12
  var LogController = (function () {
4
- function LogController(logger, mp) {
13
+ function LogController(logger, updateL, mp) {
5
14
  this.logger = logger;
6
- this.map = mp;
15
+ this.map = (mp ? mp : exports.map);
16
+ this.update = updateL ? updateL : updateLog;
7
17
  this.config = this.config.bind(this);
8
18
  }
9
19
  LogController.prototype.config = function (req, res) {
@@ -11,41 +21,70 @@ var LogController = (function () {
11
21
  if (!obj || obj === '') {
12
22
  return res.status(400).end('The request body cannot be empty');
13
23
  }
14
- if (!this.logger || !this.map) {
24
+ if (!this.logger) {
15
25
  return res.status(503).end('Logger is not available');
16
26
  }
17
- if (!this.map) {
18
- return res.status(503).end('Map is not available');
19
- }
20
- var changed = false;
21
- if (obj.level && typeof obj.level === 'string' && obj.level.length > 0) {
22
- var lv = this.map[obj.level.toUpperCase()];
23
- if (lv !== undefined) {
24
- this.logger.level = lv;
25
- changed = true;
26
- }
27
- }
28
- if (obj.map) {
29
- if (obj.map.level && typeof obj.map.level === 'string' && obj.map.level.length > 0) {
30
- this.logger.map.level = obj.map.level;
31
- changed = true;
32
- }
33
- if (obj.map.time && typeof obj.map.time === 'string' && obj.map.time.length > 0) {
34
- this.logger.map.time = obj.map.time;
35
- changed = true;
36
- }
37
- if (obj.map.msg && typeof obj.map.msg === 'string' && obj.map.msg.length > 0) {
38
- this.logger.map.msg = obj.map.msg;
39
- changed = true;
27
+ if (typeof obj.level === 'string' && obj.level.length > 0) {
28
+ if (!this.map) {
29
+ return res.status(503).end('Map is not available');
40
30
  }
41
31
  }
32
+ var changed = this.update(this.logger, obj, this.map);
42
33
  if (changed) {
43
- return res.status(200).end('true');
34
+ return res.status(200).json(true).end();
44
35
  }
45
36
  else {
46
- return res.status(204).end('false');
37
+ return res.status(204).json(false).end();
47
38
  }
48
39
  };
49
40
  return LogController;
50
41
  }());
51
42
  exports.LogController = LogController;
43
+ function updateLog(logger, obj, mp) {
44
+ var changed = false;
45
+ if (typeof obj.level === 'string' && obj.level.length > 0) {
46
+ var lv = mp[obj.level.toUpperCase()];
47
+ if (lv !== undefined) {
48
+ logger.level = lv;
49
+ changed = true;
50
+ }
51
+ }
52
+ if (obj.map) {
53
+ if (typeof obj.map.level === 'string' && obj.map.level.length > 0) {
54
+ logger.map.level = obj.map.level;
55
+ changed = true;
56
+ }
57
+ if (typeof obj.map.time === 'string' && obj.map.time.length > 0) {
58
+ logger.map.time = obj.map.time;
59
+ changed = true;
60
+ }
61
+ if (typeof obj.map.msg === 'string' && obj.map.msg.length > 0) {
62
+ logger.map.msg = obj.map.msg;
63
+ changed = true;
64
+ }
65
+ }
66
+ if (obj.constants !== undefined && typeof obj.constants === 'object') {
67
+ var ks = Object.keys(obj.constants);
68
+ if (ks.length > 0) {
69
+ logger.constants = obj.constants;
70
+ }
71
+ else {
72
+ logger.constants = undefined;
73
+ }
74
+ changed = true;
75
+ }
76
+ if (obj.name) {
77
+ if (typeof obj.name.trace === 'string'
78
+ && typeof obj.name.debug === 'string'
79
+ && typeof obj.name.info === 'string'
80
+ && typeof obj.name.warn === 'string'
81
+ && typeof obj.name.error === 'string'
82
+ && typeof obj.name.panic === 'string'
83
+ && typeof obj.name.fatal === 'string') {
84
+ logger.name = obj.name;
85
+ changed = true;
86
+ }
87
+ }
88
+ return changed;
89
+ }
90
+ exports.updateLog = updateLog;
@@ -41,7 +41,7 @@ var LowCodeController = (function (_super) {
41
41
  }
42
42
  LowCodeController.prototype.search = function (req, res) {
43
43
  var _this = this;
44
- var s = search_1.fromRequest(req, this.fields, this.excluding);
44
+ var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
45
45
  var l = search_1.getParameters(s, this.config);
46
46
  var s2 = search_1.format(s, this.dates, this.numbers);
47
47
  this.lowCodeService.search(s2, l.limit, l.skipOrRefId, l.fields)
@@ -28,7 +28,7 @@ var SearchController = (function () {
28
28
  }
29
29
  SearchController.prototype.search = function (req, res) {
30
30
  var _this = this;
31
- var s = search_1.fromRequest(req, this.fields, this.excluding);
31
+ var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
32
32
  var l = search_1.getParameters(s, this.config);
33
33
  var s2 = search_1.format(s, this.dates, this.numbers);
34
34
  this.find(s2, l.limit, l.skipOrRefId, l.fields)
package/lib/health.js CHANGED
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- function check(checkers) {
39
+ function health(checkers) {
40
40
  return __awaiter(this, void 0, void 0, function () {
41
41
  var p, total, count, _i, checkers_1, checker, sub, r, err_1;
42
42
  return __generator(this, function (_a) {
@@ -90,4 +90,4 @@ function check(checkers) {
90
90
  });
91
91
  });
92
92
  }
93
- exports.check = check;
93
+ exports.health = health;
package/lib/http.js CHANGED
@@ -262,3 +262,41 @@ function getDate(req, name, d) {
262
262
  return date;
263
263
  }
264
264
  exports.getDate = getDate;
265
+ var o = 'object';
266
+ function minimize(obj) {
267
+ if (!obj || typeof obj !== o) {
268
+ return obj;
269
+ }
270
+ var keys = Object.keys(obj);
271
+ for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
272
+ var key = keys_2[_i];
273
+ var v = obj[key];
274
+ if (v == null) {
275
+ delete obj[key];
276
+ }
277
+ else if (Array.isArray(v) && v.length > 0) {
278
+ var v1 = v[0];
279
+ if (typeof v1 === o && !(v1 instanceof Date)) {
280
+ for (var _a = 0, v_1 = v; _a < v_1.length; _a++) {
281
+ var item = v_1[_a];
282
+ minimize(item);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ return obj;
288
+ }
289
+ exports.minimize = minimize;
290
+ function minimizeArray(arrs) {
291
+ if (!arrs) {
292
+ return arrs;
293
+ }
294
+ if (arrs.length > 0) {
295
+ for (var _i = 0, arrs_1 = arrs; _i < arrs_1.length; _i++) {
296
+ var obj = arrs_1[_i];
297
+ minimize(obj);
298
+ }
299
+ }
300
+ return arrs;
301
+ }
302
+ exports.minimizeArray = minimizeArray;
package/lib/index.js CHANGED
@@ -1 +1,3 @@
1
- "use strict";function __export(r){for(var e in r)exports.hasOwnProperty(e)||(exports[e]=r[e])}Object.defineProperty(exports,"__esModule",{value:!0});var GenericController_1=require("./GenericController");exports.GenericHandler=GenericController_1.GenericController;var GenericSearchController_1=require("./GenericSearchController");exports.GenericSearchHandler=GenericSearchController_1.GenericSearchController;var HealthController_1=require("./HealthController");exports.HealthHandler=HealthController_1.HealthController;var LoadController_1=require("./LoadController");exports.LoadHandler=LoadController_1.LoadController,exports.ViewHandler=LoadController_1.LoadController,exports.ViewController=LoadController_1.LoadController;var LoadSearchController_1=require("./LoadSearchController");exports.LoadSearchHandler=LoadSearchController_1.LoadSearchController;var LogController_1=require("./LogController");exports.LogHandler=LogController_1.LogController;var LowCodeController_1=require("./LowCodeController");exports.LowCodeHandler=LowCodeController_1.LowCodeController,exports.Handler=LowCodeController_1.LowCodeController,exports.Controller=LowCodeController_1.LowCodeController;var SearchController_1=require("./SearchController");exports.SearchHandler=SearchController_1.SearchController,__export(require("./health")),__export(require("./HealthController")),__export(require("./LogController")),__export(require("./log")),__export(require("./http")),__export(require("./view")),__export(require("./LoadController")),__export(require("./search_func")),__export(require("./search")),__export(require("./SearchController")),__export(require("./LoadSearchController")),__export(require("./resources")),__export(require("./edit")),__export(require("./GenericController")),__export(require("./GenericSearchController")),__export(require("./LowCodeController"));
1
+ "use strict";function __export(m){for(var p in m)if(!exports.hasOwnProperty(p))exports[p]=m[p]}
2
+ Object.defineProperty(exports,"__esModule",{value:!0});var GenericController_1=require("./GenericController");exports.GenericHandler=GenericController_1.GenericController;var GenericSearchController_1=require("./GenericSearchController");exports.GenericSearchHandler=GenericSearchController_1.GenericSearchController;var HealthController_1=require("./HealthController");exports.HealthHandler=HealthController_1.HealthController;var LoadController_1=require("./LoadController");exports.LoadHandler=LoadController_1.LoadController;exports.ViewHandler=LoadController_1.LoadController;exports.ViewController=LoadController_1.LoadController;var LoadSearchController_1=require("./LoadSearchController");exports.LoadSearchHandler=LoadSearchController_1.LoadSearchController;var LogController_1=require("./LogController");exports.LogHandler=LogController_1.LogController;var LowCodeController_1=require("./LowCodeController");exports.LowCodeHandler=LowCodeController_1.LowCodeController;exports.Handler=LowCodeController_1.LowCodeController;exports.Controller=LowCodeController_1.LowCodeController;var SearchController_1=require("./SearchController");exports.SearchHandler=SearchController_1.SearchController;__export(require("./health"));__export(require("./HealthController"));__export(require("./LogController"));__export(require("./log"));__export(require("./http"));__export(require("./view"));__export(require("./LoadController"));__export(require("./search_func"));__export(require("./search"));__export(require("./SearchController"));__export(require("./LoadSearchController"));__export(require("./resources"));__export(require("./edit"));__export(require("./GenericController"));__export(require("./GenericSearchController"));__export(require("./LowCodeController"));function allow(access){return function(req,res,next){res.header('Access-Control-Allow-Origin',access.origin);res.header('Access-Control-Allow-Credentials',access.credentials);res.header('Access-Control-Allow-Methods',access.methods);res.setHeader('Access-Control-Allow-Headers',access.headers);next()}}
3
+ exports.allow=allow
package/lib/log.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var stream_1 = require("stream");
4
+ var resources_1 = require("./resources");
4
5
  function createConfig(c) {
5
6
  if (!c) {
6
7
  return { skips: [], duration: 'duration', request: '', response: '', status: '', size: '' };
@@ -37,28 +38,29 @@ function removeUrlParams(url) {
37
38
  return startParams !== -1 ? url.substring(0, startParams) : url;
38
39
  }
39
40
  exports.removeUrlParams = removeUrlParams;
40
- var Logger = (function () {
41
- function Logger(write, conf, build) {
41
+ var o = 'OPTIONS';
42
+ var MiddlewareLogger = (function () {
43
+ function MiddlewareLogger(write, conf, build) {
42
44
  this.write = write;
43
45
  this.build = build;
44
46
  this.log = this.log.bind(this);
45
- this.c = createConfig(conf);
47
+ this.conf = createConfig(conf);
46
48
  }
47
- Logger.prototype.log = function (req, res, next) {
49
+ MiddlewareLogger.prototype.log = function (req, res, next) {
48
50
  var _this = this;
49
- if (this.c.log && !skip(this.c.skips, req.originalUrl)) {
51
+ var m = req.method;
52
+ if (m !== o && this.conf.log && !skip(this.conf.skips, req.originalUrl)) {
50
53
  var start_1 = process.hrtime();
51
- var m = req.method;
52
- var x = this.c.request;
54
+ var x_1 = this.conf.request;
53
55
  var r_1 = false;
54
56
  if (m !== 'GET' && m !== 'DELETE') {
55
57
  r_1 = true;
56
58
  }
57
59
  var msg_1 = m + " " + req.originalUrl;
58
- if (this.c.separate && r_1) {
59
- if (this.c.request.length > 0) {
60
+ if (this.conf.separate && r_1) {
61
+ if (this.conf.request.length > 0) {
60
62
  var op = {};
61
- op[x] = JSON.stringify(req.body);
63
+ op[x_1] = JSON.stringify(req.body);
62
64
  if (this.build) {
63
65
  var op2 = this.build(req, op);
64
66
  this.write(msg_1, op2);
@@ -73,28 +75,28 @@ var Logger = (function () {
73
75
  res.on('finish', function () {
74
76
  var duration = getDurationInMilliseconds(start_1);
75
77
  var op = {};
76
- op[_this.c.duration] = duration;
77
- if (r_1 && !_this.c.separate && _this.c.request.length > 0) {
78
- op[_this.c.request] = JSON.stringify(req.body);
78
+ if (r_1 && !_this.conf.separate && _this.conf.request.length > 0) {
79
+ op[x_1] = JSON.stringify(req.body);
79
80
  }
80
- if (_this.c.response.length > 0) {
81
- var rsBody = Buffer.concat(chunks_1).toString();
82
- op[_this.c.response] = rsBody;
81
+ if (_this.conf.response.length > 0) {
82
+ var rsBody = Buffer.concat(chunks_1).toString(resources_1.resources.encoding);
83
+ op[_this.conf.response] = rsBody;
83
84
  }
84
- if (_this.c.status.length > 0) {
85
- op[_this.c.status] = res.statusCode;
85
+ if (_this.conf.status.length > 0) {
86
+ op[_this.conf.status] = res.statusCode;
86
87
  }
87
- if (_this.c.size.length > 0) {
88
+ if (_this.conf.size.length > 0) {
88
89
  if ('_contentLength' in res) {
89
- op[_this.c.size] = res['_contentLength'];
90
+ op[_this.conf.size] = res['_contentLength'];
90
91
  }
91
92
  else if (res.hasHeader('content-length')) {
92
93
  var l = res.getHeader('content-length');
93
94
  if (typeof l === 'number' || typeof l === 'string') {
94
- op[_this.c.size] = l;
95
+ op[_this.conf.size] = l;
95
96
  }
96
97
  }
97
98
  }
99
+ op[_this.conf.duration] = duration;
98
100
  if (_this.build) {
99
101
  var op2 = _this.build(req, op);
100
102
  _this.write(msg_1, op2);
@@ -109,9 +111,9 @@ var Logger = (function () {
109
111
  next();
110
112
  }
111
113
  };
112
- return Logger;
114
+ return MiddlewareLogger;
113
115
  }());
114
- exports.Logger = Logger;
116
+ exports.MiddlewareLogger = MiddlewareLogger;
115
117
  var mapResponseBody = function (res, chunks) {
116
118
  var defaultWrite = res.write.bind(res);
117
119
  var defaultEnd = res.end.bind(res);
@@ -141,3 +143,105 @@ var getDurationInMilliseconds = function (start) {
141
143
  var diff = process.hrtime(start);
142
144
  return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
143
145
  };
146
+ var MiddlewareController = (function () {
147
+ function MiddlewareController(logger) {
148
+ this.logger = logger;
149
+ this.config = this.config.bind(this);
150
+ }
151
+ MiddlewareController.prototype.config = function (req, res) {
152
+ var obj = req.body;
153
+ if (!obj || obj === '') {
154
+ return res.status(400).end('The request body cannot be empty');
155
+ }
156
+ if (!this.logger) {
157
+ return res.status(503).end('Logger is not available');
158
+ }
159
+ var changed = false;
160
+ if (obj.log !== undefined) {
161
+ this.logger.conf.log = obj.log;
162
+ changed = true;
163
+ }
164
+ if (obj.separate !== undefined) {
165
+ this.logger.conf.separate = obj.separate;
166
+ changed = true;
167
+ }
168
+ if (Array.isArray(obj.skips)) {
169
+ if (isValidSkips(obj.skips)) {
170
+ this.logger.conf.skips = obj.skips;
171
+ changed = true;
172
+ }
173
+ }
174
+ if (typeof obj.duration === 'string' && obj.duration.length > 0) {
175
+ this.logger.conf.duration = obj.duration;
176
+ changed = true;
177
+ }
178
+ if (typeof obj.request === 'string') {
179
+ this.logger.conf.request = obj.request;
180
+ changed = true;
181
+ }
182
+ if (typeof obj.response === 'string') {
183
+ this.logger.conf.response = obj.response;
184
+ changed = true;
185
+ }
186
+ if (typeof obj.status === 'string') {
187
+ this.logger.conf.status = obj.status;
188
+ changed = true;
189
+ }
190
+ if (typeof obj.size === 'string') {
191
+ this.logger.conf.size = obj.size;
192
+ changed = true;
193
+ }
194
+ if (changed) {
195
+ return res.status(200).json(true).end();
196
+ }
197
+ else {
198
+ return res.status(204).json(false).end();
199
+ }
200
+ };
201
+ return MiddlewareController;
202
+ }());
203
+ exports.MiddlewareController = MiddlewareController;
204
+ function isValidSkips(s) {
205
+ for (var _i = 0, s_1 = s; _i < s_1.length; _i++) {
206
+ var x = s_1[_i];
207
+ if (!(typeof x === 'string')) {
208
+ return false;
209
+ }
210
+ }
211
+ return true;
212
+ }
213
+ exports.isValidSkips = isValidSkips;
214
+ function mask(s, start, end, replace) {
215
+ if (start < 0) {
216
+ start = 0;
217
+ }
218
+ if (end < 0) {
219
+ end = 0;
220
+ }
221
+ var t = start + end;
222
+ if (t >= s.length) {
223
+ return replace.repeat(s.length);
224
+ }
225
+ return s.substr(0, start) + replace.repeat(s.length - t) + s.substr(s.length - end);
226
+ }
227
+ exports.mask = mask;
228
+ function margin(s, start, end, replace) {
229
+ if (start >= end) {
230
+ return '';
231
+ }
232
+ if (start < 0) {
233
+ start = 0;
234
+ }
235
+ if (end < 0) {
236
+ end = 0;
237
+ }
238
+ if (start >= s.length) {
239
+ return replace.repeat(s.length);
240
+ }
241
+ if (end >= s.length) {
242
+ return replace.repeat(start) + s.substr(start);
243
+ }
244
+ return replace.repeat(start) + s.substr(start, end - start) + replace.repeat(s.length - end);
245
+ }
246
+ exports.margin = margin;
247
+ exports.maskMargin = margin;
package/lib/resources.js CHANGED
@@ -1,2 +1,55 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var resources=(function(){function resources(){}
2
- return resources}());exports.resources=resources
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var fs = require("fs");
4
+ var resources = (function () {
5
+ function resources() {
6
+ }
7
+ resources.encoding = 'utf-8';
8
+ return resources;
9
+ }());
10
+ exports.resources = resources;
11
+ var TypeChecker = (function () {
12
+ function TypeChecker(attributes, allowUndefined) {
13
+ this.attributes = attributes;
14
+ this.allowUndefined = allowUndefined;
15
+ this.check = this.check.bind(this);
16
+ }
17
+ TypeChecker.prototype.check = function (req, res, next) {
18
+ var obj = req.body;
19
+ if (!obj || obj === '') {
20
+ return res.status(400).end('The request body cannot be empty');
21
+ }
22
+ else {
23
+ var errors = resources.check(obj, this.attributes, this.allowUndefined);
24
+ if (errors.length > 0) {
25
+ res.status(400).json(errors).end();
26
+ }
27
+ else {
28
+ next();
29
+ }
30
+ }
31
+ };
32
+ return TypeChecker;
33
+ }());
34
+ exports.TypeChecker = TypeChecker;
35
+ function check(attributes, allowUndefined) {
36
+ var x = new TypeChecker(attributes, allowUndefined);
37
+ return x.check;
38
+ }
39
+ exports.check = check;
40
+ function loadTemplates(ok, buildTemplates, correct, files) {
41
+ if (!ok) {
42
+ return undefined;
43
+ }
44
+ if (!files) {
45
+ files = ['./src/query.xml'];
46
+ }
47
+ var mappers = [];
48
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
49
+ var file = files_1[_i];
50
+ var mapper = fs.readFileSync(file, 'utf8');
51
+ mappers.push(mapper);
52
+ }
53
+ return buildTemplates(mappers, correct);
54
+ }
55
+ exports.loadTemplates = loadTemplates;
package/lib/search.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var http_1 = require("./http");
3
4
  function jsonResult(res, result, quick, fields, config) {
4
5
  if (quick && fields && fields.length > 0) {
5
6
  res.status(200).json(toCsv(fields, result)).end();
@@ -15,7 +16,7 @@ function buildResult(r, conf) {
15
16
  }
16
17
  var x = {};
17
18
  var li = (conf.list ? conf.list : 'list');
18
- x[li] = r.list;
19
+ x[li] = http_1.minimizeArray(r.list);
19
20
  var to = (conf.total ? conf.total : 'total');
20
21
  x[to] = r.total;
21
22
  if (r.nextPageToken && r.nextPageToken.length > 0) {
@@ -83,27 +84,40 @@ function initializeConfig(conf) {
83
84
  return c;
84
85
  }
85
86
  exports.initializeConfig = initializeConfig;
86
- function fromRequest(req, fields, excluding) {
87
- var s = (req.method === 'GET' ? fromUrl(req, fields, excluding) : req.body);
87
+ function fromRequest(req, arr) {
88
+ var s = (req.method === 'GET' ? fromUrl(req, arr) : req.body);
88
89
  return s;
89
90
  }
90
91
  exports.fromRequest = fromRequest;
91
- function fromUrl(req, fields, excluding) {
92
- if (!fields || fields.length === 0) {
93
- fields = 'fields';
92
+ function buildArray(arr, s0, s1, s2) {
93
+ var r = [];
94
+ if (arr && arr.length > 0) {
95
+ for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
96
+ var a = arr_1[_i];
97
+ r.push(a);
98
+ }
99
+ }
100
+ if (s0 && s0.length > 0) {
101
+ r.push(s0);
102
+ }
103
+ if (s1 && s1.length > 0) {
104
+ r.push(s1);
94
105
  }
106
+ if (s2 && s2.length > 0) {
107
+ r.push(s2);
108
+ }
109
+ return r;
110
+ }
111
+ exports.buildArray = buildArray;
112
+ function fromUrl(req, arr) {
95
113
  var s = {};
96
114
  var obj = req.query;
97
115
  var keys = Object.keys(obj);
98
116
  for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
99
117
  var key = keys_1[_i];
100
- if (key === fields) {
101
- var x = obj[key].split(',');
102
- s[key] = x;
103
- }
104
- else if (key === excluding) {
118
+ if (inArray(key, arr)) {
105
119
  var x = obj[key].split(',');
106
- s[key] = x;
120
+ setValue(s, key, x);
107
121
  }
108
122
  else {
109
123
  setValue(s, key, obj[key]);
@@ -112,6 +126,19 @@ function fromUrl(req, fields, excluding) {
112
126
  return s;
113
127
  }
114
128
  exports.fromUrl = fromUrl;
129
+ function inArray(s, arr) {
130
+ if (!arr || arr.length === 0) {
131
+ return false;
132
+ }
133
+ for (var _i = 0, arr_2 = arr; _i < arr_2.length; _i++) {
134
+ var a = arr_2[_i];
135
+ if (s === a) {
136
+ return true;
137
+ }
138
+ }
139
+ return false;
140
+ }
141
+ exports.inArray = inArray;
115
142
  function setValue(obj, path, value) {
116
143
  var paths = path.split('.');
117
144
  if (paths.length === 1) {
@@ -315,8 +342,8 @@ function deletePageInfo(obj, arr) {
315
342
  delete obj['nextPageToken'];
316
343
  }
317
344
  else {
318
- for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
319
- var o = arr_1[_i];
345
+ for (var _i = 0, arr_3 = arr; _i < arr_3.length; _i++) {
346
+ var o = arr_3[_i];
320
347
  if (o && o.length > 0) {
321
348
  delete obj[o];
322
349
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.1.13",
3
+ "version": "0.1.17",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -3,7 +3,7 @@ import {ResultInfo, StatusConfig} from './edit';
3
3
  import {GenericController, GenericService} from './GenericController';
4
4
  import {handleError, Log} from './http';
5
5
  import {ErrorMessage} from './metadata';
6
- import {Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult} from './search';
6
+ import {buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult} from './search';
7
7
  import {getMetadataFunc} from './search_func';
8
8
 
9
9
  export interface Config extends StatusConfig, SearchConfig {
@@ -15,6 +15,7 @@ export class GenericSearchController<T, ID, S extends Filter> extends GenericCon
15
15
  numbers?: string[];
16
16
  fields?: string;
17
17
  excluding?: string;
18
+ array?: string[];
18
19
  constructor(log: Log, public find: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, service: GenericService<T, ID, number|ResultInfo<T>>, config?: Config, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, dates?: string[], numbers?: string[]) {
19
20
  super(log, service, config, validate);
20
21
  this.search = this.search.bind(this);
@@ -34,7 +35,7 @@ export class GenericSearchController<T, ID, S extends Filter> extends GenericCon
34
35
  }
35
36
  }
36
37
  search(req: Request, res: Response) {
37
- const s = fromRequest<S>(req, this.fields, this.excluding);
38
+ const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
38
39
  const l = getParameters(s, this.config);
39
40
  const s2 = format(s, this.dates, this.numbers);
40
41
  this.find(s2, l.limit, l.skipOrRefId, l.fields)
@@ -1,16 +1,16 @@
1
1
  import {Request, Response} from 'express';
2
- import {check, HealthChecker} from './health';
2
+ import {health, HealthChecker} from './health';
3
3
 
4
4
  export class HealthController {
5
5
  constructor(protected checkers: HealthChecker[]) {
6
6
  this.check = this.check.bind(this);
7
7
  }
8
8
  check(req: Request, res: Response) {
9
- check(this.checkers).then(heath => {
10
- if (heath.status === 'UP') {
11
- return res.status(200).json(heath).end();
9
+ health(this.checkers).then(r => {
10
+ if (r.status === 'UP') {
11
+ return res.status(200).json(r).end();
12
12
  } else {
13
- return res.status(500).json(heath).end();
13
+ return res.status(500).json(r).end();
14
14
  }
15
15
  });
16
16
  }