express-ext 0.2.2 → 0.2.4

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/index.js CHANGED
@@ -1,43 +1,52 @@
1
- "use strict";
1
+ 'use strict';
2
2
  function __export(m) {
3
3
  for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
4
  }
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var GenericController_1 = require("./GenericController");
5
+ Object.defineProperty(exports, '__esModule', { value: true });
6
+ var GenericController_1 = require('./GenericController');
7
7
  exports.GenericHandler = GenericController_1.GenericController;
8
- var GenericSearchController_1 = require("./GenericSearchController");
8
+ var GenericSearchController_1 = require('./GenericSearchController');
9
9
  exports.GenericSearchHandler = GenericSearchController_1.GenericSearchController;
10
- var HealthController_1 = require("./HealthController");
10
+ var HealthController_1 = require('./HealthController');
11
11
  exports.HealthHandler = HealthController_1.HealthController;
12
- var http_1 = require("./http");
13
- var LoadController_1 = require("./LoadController");
12
+ var http_1 = require('./http');
13
+ var LoadController_1 = require('./LoadController');
14
14
  exports.LoadHandler = LoadController_1.LoadController;
15
15
  exports.ViewHandler = LoadController_1.LoadController;
16
- var LoadSearchController_1 = require("./LoadSearchController");
16
+ var LoadSearchController_1 = require('./LoadSearchController');
17
17
  exports.LoadSearchHandler = LoadSearchController_1.LoadSearchController;
18
- var LogController_1 = require("./LogController");
18
+ var LogController_1 = require('./LogController');
19
19
  exports.LogHandler = LogController_1.LogController;
20
- var LowCodeController_1 = require("./LowCodeController");
20
+ var LowCodeController_1 = require('./LowCodeController');
21
21
  exports.Handler = LowCodeController_1.Controller;
22
- var SearchController_1 = require("./SearchController");
22
+ var SearchController_1 = require('./SearchController');
23
23
  exports.SearchHandler = SearchController_1.SearchController;
24
- __export(require("./health"));
25
- __export(require("./client"));
26
- __export(require("./HealthController"));
27
- __export(require("./LogController"));
28
- __export(require("./log"));
29
- __export(require("./http"));
30
- __export(require("./view"));
31
- __export(require("./LoadController"));
32
- __export(require("./search_func"));
33
- __export(require("./search"));
34
- __export(require("./SearchController"));
35
- __export(require("./LoadSearchController"));
36
- __export(require("./resources"));
37
- __export(require("./edit"));
38
- __export(require("./GenericController"));
39
- __export(require("./GenericSearchController"));
40
- __export(require("./LowCodeController"));
24
+ __export(require('./client'));
25
+ __export(require('./edit'));
26
+ __export(require('./GenericController'));
27
+ __export(require('./GenericSearchController'));
28
+ __export(require('./health'));
29
+ __export(require('./HealthController'));
30
+ __export(require('./http'));
31
+ __export(require('./LoadController'));
32
+ __export(require('./LoadSearchController'));
33
+ __export(require('./log'));
34
+ __export(require('./LogController'));
35
+ __export(require('./LowCodeController'));
36
+ __export(require('./resources'));
37
+ __export(require('./search'));
38
+ __export(require('./search_func'));
39
+ __export(require('./SearchController'));
40
+ __export(require('./view'));
41
+ function hasQuery(req) {
42
+ return req.url.indexOf('?') >= 0;
43
+ }
44
+ exports.hasQuery = hasQuery;
45
+ function getQuery(url) {
46
+ var i = url.indexOf('?');
47
+ return i < 0 ? '' : url.substring(i + 1);
48
+ }
49
+ exports.getQuery = getQuery;
41
50
  function allow(access) {
42
51
  var ao = access.origin;
43
52
  if (typeof ao === 'string') {
@@ -48,8 +57,7 @@ function allow(access) {
48
57
  res.setHeader('Access-Control-Allow-Headers', access.headers);
49
58
  next();
50
59
  };
51
- }
52
- else if (Array.isArray(ao) && ao.length > 0) {
60
+ } else if (Array.isArray(ao) && ao.length > 0) {
53
61
  return function (req, res, next) {
54
62
  var origin = req.headers.origin;
55
63
  if (origin) {
@@ -76,7 +84,7 @@ var SavedController = (function () {
76
84
  this.log = log;
77
85
  this.service = service;
78
86
  this.item = item;
79
- this.id = (id && id.length > 0 ? id : 'id');
87
+ this.id = id && id.length > 0 ? id : 'id';
80
88
  this.save = this.save.bind(this);
81
89
  this.remove = this.remove.bind(this);
82
90
  this.load = this.load.bind(this);
@@ -93,10 +101,14 @@ var SavedController = (function () {
93
101
  res.status(400).end("'" + this.item + "' cannot be empty");
94
102
  return;
95
103
  }
96
- this.service.save(id, itemId).then(function (data) {
97
- res.status(200).json(data).end();
98
- })
99
- .catch(function (err) { return http_1.handleError(err, res, _this.log); });
104
+ this.service
105
+ .save(id, itemId)
106
+ .then(function (data) {
107
+ res.status(200).json(data).end();
108
+ })
109
+ .catch(function (err) {
110
+ return http_1.handleError(err, res, _this.log);
111
+ });
100
112
  };
101
113
  SavedController.prototype.remove = function (req, res) {
102
114
  var _this = this;
@@ -110,10 +122,14 @@ var SavedController = (function () {
110
122
  res.status(400).end("'" + this.item + "' cannot be empty");
111
123
  return;
112
124
  }
113
- this.service.remove(id, itemId).then(function (data) {
114
- res.status(200).json(data).end();
115
- })
116
- .catch(function (err) { return http_1.handleError(err, res, _this.log); });
125
+ this.service
126
+ .remove(id, itemId)
127
+ .then(function (data) {
128
+ res.status(200).json(data).end();
129
+ })
130
+ .catch(function (err) {
131
+ return http_1.handleError(err, res, _this.log);
132
+ });
117
133
  };
118
134
  SavedController.prototype.load = function (req, res) {
119
135
  var _this = this;
@@ -122,20 +138,24 @@ var SavedController = (function () {
122
138
  res.status(400).end("'" + this.id + "' cannot be empty");
123
139
  return;
124
140
  }
125
- this.service.load(id).then(function (data) {
126
- res.status(200).json(data).end();
127
- })
128
- .catch(function (err) { return http_1.handleError(err, res, _this.log); });
141
+ this.service
142
+ .load(id)
143
+ .then(function (data) {
144
+ res.status(200).json(data).end();
145
+ })
146
+ .catch(function (err) {
147
+ return http_1.handleError(err, res, _this.log);
148
+ });
129
149
  };
130
150
  return SavedController;
131
- }());
151
+ })();
132
152
  exports.SavedController = SavedController;
133
153
  var FollowController = (function () {
134
154
  function FollowController(log, service, target, id) {
135
155
  this.log = log;
136
156
  this.service = service;
137
157
  this.target = target;
138
- this.id = (id && id.length > 0 ? id : 'id');
158
+ this.id = id && id.length > 0 ? id : 'id';
139
159
  this.follow = this.follow.bind(this);
140
160
  this.unfollow = this.unfollow.bind(this);
141
161
  this.checkFollow = this.checkFollow.bind(this);
@@ -152,9 +172,14 @@ var FollowController = (function () {
152
172
  res.status(400).end("'" + this.target + "' cannot be empty");
153
173
  return;
154
174
  }
155
- this.service.follow(id, target).then(function (count) {
156
- return res.status(200).json(count).end();
157
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
175
+ this.service
176
+ .follow(id, target)
177
+ .then(function (count) {
178
+ return res.status(200).json(count).end();
179
+ })
180
+ .catch(function (err) {
181
+ return http_1.handleError(err, res, _this.log);
182
+ });
158
183
  };
159
184
  FollowController.prototype.unfollow = function (req, res) {
160
185
  var _this = this;
@@ -168,9 +193,14 @@ var FollowController = (function () {
168
193
  res.status(400).end("'" + this.target + "' cannot be empty");
169
194
  return;
170
195
  }
171
- this.service.unfollow(id, target).then(function (count) {
172
- return res.status(200).json(count).end();
173
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
196
+ this.service
197
+ .unfollow(id, target)
198
+ .then(function (count) {
199
+ return res.status(200).json(count).end();
200
+ })
201
+ .catch(function (err) {
202
+ return http_1.handleError(err, res, _this.log);
203
+ });
174
204
  };
175
205
  FollowController.prototype.checkFollow = function (req, res) {
176
206
  var _this = this;
@@ -184,12 +214,17 @@ var FollowController = (function () {
184
214
  res.status(400).end("'" + this.target + "' cannot be empty");
185
215
  return;
186
216
  }
187
- this.service.checkFollow(id, target).then(function (count) {
188
- return res.status(200).json(count).end();
189
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
217
+ this.service
218
+ .checkFollow(id, target)
219
+ .then(function (count) {
220
+ return res.status(200).json(count).end();
221
+ })
222
+ .catch(function (err) {
223
+ return http_1.handleError(err, res, _this.log);
224
+ });
190
225
  };
191
226
  return FollowController;
192
- }());
227
+ })();
193
228
  exports.FollowController = FollowController;
194
229
  var UserReactionController = (function () {
195
230
  function UserReactionController(log, service, author, id, reaction) {
@@ -197,7 +232,7 @@ var UserReactionController = (function () {
197
232
  this.service = service;
198
233
  this.author = author;
199
234
  this.reaction = reaction;
200
- this.id = (id && id.length > 0 ? id : 'id');
235
+ this.id = id && id.length > 0 ? id : 'id';
201
236
  this.react = this.react.bind(this);
202
237
  this.unreact = this.unreact.bind(this);
203
238
  this.checkReaction = this.checkReaction.bind(this);
@@ -219,9 +254,14 @@ var UserReactionController = (function () {
219
254
  res.status(400).end("'" + this.reaction + "' cannot be empty");
220
255
  return;
221
256
  }
222
- this.service.react(id, author, reaction).then(function (count) {
223
- return res.status(200).json(count).end();
224
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
257
+ this.service
258
+ .react(id, author, reaction)
259
+ .then(function (count) {
260
+ return res.status(200).json(count).end();
261
+ })
262
+ .catch(function (err) {
263
+ return http_1.handleError(err, res, _this.log);
264
+ });
225
265
  };
226
266
  UserReactionController.prototype.unreact = function (req, res) {
227
267
  var _this = this;
@@ -240,9 +280,14 @@ var UserReactionController = (function () {
240
280
  res.status(400).end("'" + this.reaction + "' cannot be empty");
241
281
  return;
242
282
  }
243
- this.service.unreact(id, author, reaction).then(function (count) {
244
- return res.status(200).json(count).end();
245
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
283
+ this.service
284
+ .unreact(id, author, reaction)
285
+ .then(function (count) {
286
+ return res.status(200).json(count).end();
287
+ })
288
+ .catch(function (err) {
289
+ return http_1.handleError(err, res, _this.log);
290
+ });
246
291
  };
247
292
  UserReactionController.prototype.checkReaction = function (req, res) {
248
293
  var _this = this;
@@ -256,12 +301,17 @@ var UserReactionController = (function () {
256
301
  res.status(400).end("'" + this.author + "' cannot be empty");
257
302
  return;
258
303
  }
259
- this.service.checkReaction(id, author).then(function (count) {
260
- return res.status(200).json(count).end();
261
- }).catch(function (err) { return http_1.handleError(err, res, _this.log); });
304
+ this.service
305
+ .checkReaction(id, author)
306
+ .then(function (count) {
307
+ return res.status(200).json(count).end();
308
+ })
309
+ .catch(function (err) {
310
+ return http_1.handleError(err, res, _this.log);
311
+ });
262
312
  };
263
313
  return UserReactionController;
264
- }());
314
+ })();
265
315
  exports.UserReactionController = UserReactionController;
266
316
  exports.ReactController = UserReactionController;
267
317
  exports.ReactionController = UserReactionController;