nodester 0.1.4 → 0.2.0

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 (63) hide show
  1. package/Readme.md +16 -55
  2. package/lib/application/index.js +174 -63
  3. package/lib/body/extract.js +89 -0
  4. package/lib/constants/Bounds.js +15 -0
  5. package/lib/constants/Clauses.js +13 -0
  6. package/lib/constants/ResponseFormats.js +2 -2
  7. package/lib/controllers/methods/index.js +7 -0
  8. package/lib/controllers/mixins/index.js +36 -36
  9. package/lib/database/connection.js +6 -0
  10. package/lib/database/migration.js +14 -4
  11. package/lib/facades/methods/index.js +16 -16
  12. package/lib/facades/mixins/index.js +67 -13
  13. package/lib/factories/responses/rest.js +25 -13
  14. package/lib/http/codes/descriptions.js +82 -0
  15. package/lib/http/codes/index.js +70 -145
  16. package/lib/http/codes/symbols.js +82 -0
  17. package/lib/http/{request.js → request/index.js} +53 -75
  18. package/lib/http/request/utils.js +27 -0
  19. package/lib/http/response/headers.js +138 -0
  20. package/lib/http/response/index.js +248 -0
  21. package/lib/http/response/utils.js +38 -0
  22. package/lib/middlewares/SearchParams/index.js +25 -0
  23. package/lib/middlewares/cookies/index.js +44 -0
  24. package/lib/middlewares/etag/index.js +32 -15
  25. package/lib/middlewares/formidable/index.js +30 -25
  26. package/lib/middlewares/ql/sequelize/index.js +13 -4
  27. package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +4 -3
  28. package/lib/middlewares/render/index.js +62 -0
  29. package/lib/models/associate.js +25 -1
  30. package/lib/models/define.js +26 -19
  31. package/lib/models/mixins.js +8 -1
  32. package/lib/{queries → query}/traverse.js +118 -77
  33. package/lib/router/handlers.util.js +1 -0
  34. package/lib/router/index.js +194 -99
  35. package/lib/router/markers.js +7 -0
  36. package/lib/router/route.js +5 -0
  37. package/lib/router/routes.util.js +16 -14
  38. package/lib/router/utils.js +7 -0
  39. package/lib/stacks/MarkersStack.js +41 -3
  40. package/lib/stacks/MiddlewaresStack.js +200 -0
  41. package/lib/structures/Enum.js +46 -0
  42. package/lib/structures/Filter.js +156 -0
  43. package/lib/structures/Params.js +55 -0
  44. package/lib/tools/sql.tool.js +7 -0
  45. package/lib/utils/objects.util.js +31 -24
  46. package/lib/utils/sanitizations.util.js +10 -4
  47. package/lib/validators/arguments.js +68 -0
  48. package/lib/validators/dates.js +7 -0
  49. package/lib/validators/numbers.js +7 -0
  50. package/package.json +20 -10
  51. package/lib/database/utils.js +0 -19
  52. package/lib/enums/Enum.js +0 -16
  53. package/lib/http/response.js +0 -1074
  54. package/lib/http/utils.js +0 -254
  55. package/lib/params/Params.js +0 -37
  56. package/lib/policies/Role.js +0 -77
  57. package/lib/policies/RoleExtracting.js +0 -97
  58. package/lib/preprocessors/BodyPreprocessor.js +0 -61
  59. package/lib/queries/Colander.js +0 -107
  60. package/lib/queries/NodesterQueryParams.js +0 -145
  61. package/lib/services/includes.service.js +0 -79
  62. package/lib/services/jwt.service.js +0 -147
  63. package/lib/stacks/MiddlewareStack.js +0 -159
@@ -1,157 +1,82 @@
1
- const symbolsByTag = {
2
- // Informational:
3
- CONTINUE: Symbol('100: Continue'),
4
- SWITCHING_PROTOCOLS: Symbol('101: Switching Protocols'),
5
- PROCESSING: Symbol('102: Processing'),
6
- EARLY_HINTS: Symbol('103: Early Hints'),
1
+ /*!
2
+ * /nodester
3
+ * MIT Licensed
4
+ */
5
+ 'use strict';
7
6
 
8
- // Success:
9
- OK: Symbol('200: OK'),
10
- CREATED: Symbol('201: Created'),
11
- ACCEPTED: Symbol('202: Accepted'),
12
- NON_AUTHORITATIVE_INFORMATION: Symbol('203: Non-Authoritative Information'),
13
- NO_CONTENT: Symbol('204: No Content'),
14
- RESET_CONTENT: Symbol('205: Reset Content'),
15
- PARTIAL_CONTENT: Symbol('206: Partial Content'),
16
- MULTI_STATUS: Symbol('207: Multi-Status'),
17
- ALREADY_REPORTED: Symbol('208: Already Reported'),
18
- IM_USED: Symbol('226: IM Used'),
7
+ const Enum = require('nodester/enum');
19
8
 
20
- // Redirections:
21
- MULTIPLE_CHOICES: Symbol('300: Multiple Choices'),
22
- MOVED_PERMANENTLY: Symbol('301: Moved Permanently'),
23
- FOUND: Symbol('302: Found'),
24
- SEE_OTHER: Symbol('303: See Other'),
25
- NOT_MODIFIED: Symbol('304: Not Modified'),
26
- USE_PROXY: Symbol('305: Use Proxy'),
27
- TEMPORARY_REDIRECT: Symbol('307: Temporary Redirect'),
28
- PERMANENT_REDIRECT: Symbol('308: Permanent Redirect'),
29
-
30
- // Client Errors:
31
- BAD_REQUEST: Symbol('400: Bad Request'),
32
- UNAUTHORIZED: Symbol('401: Unauthorized'),
33
- PAYMENT_REQUIRED: Symbol('402: Payment Required'),
34
- FORBIDDEN: Symbol('403: Forbidden'),
35
- NOT_FOUND: Symbol('404: Not Found'),
36
- METHOD_NOT_ALLOWED: Symbol('405: Method Not Allowed'),
37
- NOT_ACCEPTABLE: Symbol('406: Not Acceptable'),
38
- PROXY_AUTHENTICATION_REQUIRED: Symbol('407: Proxy Authentication Required'),
39
- REQUEST_TIMEOUT: Symbol('408: Request Timeout'),
40
- CONFLICT: Symbol('409: Conflict'),
41
- GONE: Symbol('410: Gone'),
42
- LENGTH_REQUIRED: Symbol('411: Length Required'),
43
- PRECONDITION_FAILED: Symbol('412: Precondition Failed'),
44
- PAYLOAD_TOO_LARGE: Symbol('413: Payload Too Large'),
45
- URI_TOO_LONG: Symbol('414: URI Too Long'),
46
- UNSUPPORTED_MEDIA_TYPE: Symbol('415: Unsupported Media Type'),
47
- RANGE_NOT_SATISFIABLE: Symbol('416: Range Not Satisfiable'),
48
- EXPECTATION_FAILED: Symbol('417: Expectation Failed'),
49
- IM_A_TEAPOT: Symbol("418: I'm a teapot"),
50
- MISDIRECTED_REQUEST: Symbol('421: Misdirected Request'),
51
- UNPROCESSABLE_ENTITY: Symbol('422: Unprocessable Entity'),
52
- LOCKED: Symbol('423: Locked'),
53
- FAILED_DEPENDENCY: Symbol('424: Failed Dependency'),
54
- TOO_EARLY: Symbol('425: Too Early'),
55
- UPGRADE_REQUIRED: Symbol('426: Upgrade Required'),
56
- PRECONDITION_REQUIRED: Symbol('428: Precondition Required'),
57
- TOO_MANY_REQUESTS: Symbol('429: Too Many Requests'),
58
- REQUEST_HEADER_FIELDS_TOO_LARGE: Symbol('431: Request Header Fields Too Large'),
59
- UNAVAILABLE_FOR_LEGAL_REASONS: Symbol('451: Unavailable For Legal Reasons'),
60
9
 
61
- // Server Errors:
62
- INTERNAL_SERVER_ERROR: Symbol('500: Internal Server Error'),
63
- NOT_IMPLEMENTED: Symbol('501: Not Implemented'),
64
- BAD_GATEWAY: Symbol('502: Bad Gateway'),
65
- SERVICE_UNAVAILABLE: Symbol('503: Service Unavailable'),
66
- GATEWAY_TIMEOUT: Symbol('504: Gateway Timeout'),
67
- HTTP_VERSION_NOT_SUPPORTED: Symbol('505: HTTP Version Not Supported'),
68
- VARIANT_ALSO_NEGOTIATES: Symbol('506: Variant Also Negotiates'),
69
- INSUFFICIENT_STORAGE: Symbol('507: Insufficient Storage'),
70
- LOOP_DETECTED: Symbol('508: Loop Detected'),
71
- NOT_EXTENDED: Symbol('510: Not Extended'),
72
- NETWORK_AUTHENTICATION_REQUIRED: Symbol('511: Network Authentication Required')
73
- }
74
-
75
- const descriptionsByCode = {
10
+ module.exports = new Enum({
76
11
  // Informational:
77
- 100: 'Continue',
78
- 101: 'Switching Protocols',
79
- 102: 'Processing',
80
- 103: 'Early Hints',
12
+ CONTINUE: 100,
13
+ SWITCHING_PROTOCOLS: 101,
14
+ PROCESSING: 102,
15
+ EARLY_HINTS: 103,
81
16
 
82
17
  // Success:
83
- 200: 'OK',
84
- 201: 'Created',
85
- 202: 'Accepted',
86
- 203: 'Non-Authoritative Information',
87
- 204: 'No Content',
88
- 205: 'Reset Content',
89
- 206: 'Partial Content',
90
- 207: 'Multi-Status',
91
- 208: 'Already Reported',
92
- 226: 'IM Used',
18
+ OK: 200,
19
+ CREATED: 201,
20
+ ACCEPTED: 202,
21
+ NON_AUTHORITATIVE_INFORMATION: 203,
22
+ NO_CONTENT: 204,
23
+ RESET_CONTENT: 205,
24
+ PARTIAL_CONTENT: 206,
25
+ MULTI_STATUS: 207,
26
+ ALREADY_REPORTED: 208,
27
+ IM_USED: 226,
93
28
 
94
29
  // Redirections:
95
- 300: 'Multiple Choices',
96
- 301: 'Moved Permanently',
97
- 302: 'Found',
98
- 303: 'See Other',
99
- 304: 'Not Modified',
100
- 305: 'Use Proxy',
101
- 307: 'Temporary Redirect',
102
- 308: 'Permanent Redirect',
30
+ MULTIPLE_CHOICES: 300,
31
+ MOVED_PERMANENTLY: 301,
32
+ FOUND: 302,
33
+ SEE_OTHER: 303,
34
+ NOT_MODIFIED: 304,
35
+ USE_PROXY: 305,
36
+ TEMPORARY_REDIRECT: 307,
37
+ PERMANENT_REDIRECT: 308,
103
38
 
104
39
  // Client Errors:
105
- 400: 'Bad Request',
106
- 401: 'Unauthorized',
107
- 402: 'Payment Required',
108
- 403: 'Forbidden',
109
- 404: 'Not Found',
110
- 405: 'Method Not Allowed',
111
- 406: 'Not Acceptable',
112
- 407: 'Proxy Authentication Required',
113
- 408: 'Request Timeout',
114
- 409: 'Conflict',
115
- 410: 'Gone',
116
- 411: 'Length Required',
117
- 412: 'Precondition Failed',
118
- 413: 'Payload Too Large',
119
- 414: 'URI Too Long',
120
- 415: 'Unsupported Media Type',
121
- 416: 'Range Not Satisfiable',
122
- 417: 'Expectation Failed',
123
- 418: 'I\'m a teapot',
124
- 421: 'Misdirected Request',
125
- 422: 'Unprocessable Entity',
126
- 423: 'Locked',
127
- 424: 'Failed Dependency',
128
- 425: 'Too Early',
129
- 426: 'Upgrade Required',
130
- 428: 'Precondition Required',
131
- 429: 'Too Many Requests',
132
- 431: 'Request Header Fields Too Large',
133
- 451: 'Unavailable For Legal Reasons',
40
+ BAD_REQUEST: 400,
41
+ UNAUTHORIZED: 401,
42
+ PAYMENT_REQUIRED: 402,
43
+ FORBIDDEN: 403,
44
+ NOT_FOUND: 404,
45
+ METHOD_NOT_ALLOWED: 405,
46
+ NOT_ACCEPTABLE: 406,
47
+ PROXY_AUTHENTICATION_REQUIRED: 407,
48
+ REQUEST_TIMEOUT: 408,
49
+ CONFLICT: 409,
50
+ GONE: 410,
51
+ LENGTH_REQUIRED: 411,
52
+ PRECONDITION_FAILED: 412,
53
+ PAYLOAD_TOO_LARGE: 413,
54
+ URI_TOO_LONG: 414,
55
+ UNSUPPORTED_MEDIA_TYPE: 415,
56
+ RANGE_NOT_SATISFIABLE: 416,
57
+ EXPECTATION_FAILED: 417,
58
+ IM_A_TEAPOT: 418,
59
+ MISDIRECTED_REQUEST: 421,
60
+ UNPROCESSABLE_ENTITY: 422,
61
+ LOCKED: 423,
62
+ FAILED_DEPENDENCY: 424,
63
+ TOO_EARLY: 425,
64
+ UPGRADE_REQUIRED: 426,
65
+ PRECONDITION_REQUIRED: 428,
66
+ TOO_MANY_REQUESTS: 429,
67
+ REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
68
+ UNAVAILABLE_FOR_LEGAL_REASONS: 451,
134
69
 
135
70
  // Server Errors:
136
- 500: 'Internal Server Error',
137
- 501: 'Not Implemented',
138
- 502: 'Bad Gateway',
139
- 503: 'Service Unavailable',
140
- 504: 'Gateway Timeout',
141
- 505: 'HTTP Version Not Supported',
142
- 506: 'Variant Also Negotiates',
143
- 507: 'Insufficient Storage',
144
- 508: 'Loop Detected',
145
- 510: 'Not Extended',
146
- 511: 'Network Authentication Required'
147
- };
148
-
149
- module.exports = {
150
- descriptions: {
151
- byCode: descriptionsByCode
152
- },
153
-
154
- symbols: {
155
- byTag: symbolsByTag
156
- }
157
- }
71
+ INTERNAL_SERVER_ERROR: 500,
72
+ NOT_IMPLEMENTED: 501,
73
+ BAD_GATEWAY: 502,
74
+ SERVICE_UNAVAILABLE: 503,
75
+ GATEWAY_TIMEOUT: 504,
76
+ HTTP_VERSION_NOT_SUPPORTED: 505,
77
+ VARIANT_ALSO_NEGOTIATES: 506,
78
+ INSUFFICIENT_STORAGE: 507,
79
+ LOOP_DETECTED: 508,
80
+ NOT_EXTENDED: 510,
81
+ NETWORK_AUTHENTICATION_REQUIRED: 511,
82
+ });
@@ -0,0 +1,82 @@
1
+ /*!
2
+ * /nodester
3
+ * MIT Licensed
4
+ */
5
+ 'use strict';
6
+
7
+ const Enum = require('nodester/enum');
8
+
9
+
10
+ module.exports = new Enum({
11
+ // Informational:
12
+ CONTINUE: Symbol('100: Continue'),
13
+ SWITCHING_PROTOCOLS: Symbol('101: Switching Protocols'),
14
+ PROCESSING: Symbol('102: Processing'),
15
+ EARLY_HINTS: Symbol('103: Early Hints'),
16
+
17
+ // Success:
18
+ OK: Symbol('200: OK'),
19
+ CREATED: Symbol('201: Created'),
20
+ ACCEPTED: Symbol('202: Accepted'),
21
+ NON_AUTHORITATIVE_INFORMATION: Symbol('203: Non-Authoritative Information'),
22
+ NO_CONTENT: Symbol('204: No Content'),
23
+ RESET_CONTENT: Symbol('205: Reset Content'),
24
+ PARTIAL_CONTENT: Symbol('206: Partial Content'),
25
+ MULTI_STATUS: Symbol('207: Multi-Status'),
26
+ ALREADY_REPORTED: Symbol('208: Already Reported'),
27
+ IM_USED: Symbol('226: IM Used'),
28
+
29
+ // Redirections:
30
+ MULTIPLE_CHOICES: Symbol('300: Multiple Choices'),
31
+ MOVED_PERMANENTLY: Symbol('301: Moved Permanently'),
32
+ FOUND: Symbol('302: Found'),
33
+ SEE_OTHER: Symbol('303: See Other'),
34
+ NOT_MODIFIED: Symbol('304: Not Modified'),
35
+ USE_PROXY: Symbol('305: Use Proxy'),
36
+ TEMPORARY_REDIRECT: Symbol('307: Temporary Redirect'),
37
+ PERMANENT_REDIRECT: Symbol('308: Permanent Redirect'),
38
+
39
+ // Client Errors:
40
+ BAD_REQUEST: Symbol('400: Bad Request'),
41
+ UNAUTHORIZED: Symbol('401: Unauthorized'),
42
+ PAYMENT_REQUIRED: Symbol('402: Payment Required'),
43
+ FORBIDDEN: Symbol('403: Forbidden'),
44
+ NOT_FOUND: Symbol('404: Not Found'),
45
+ METHOD_NOT_ALLOWED: Symbol('405: Method Not Allowed'),
46
+ NOT_ACCEPTABLE: Symbol('406: Not Acceptable'),
47
+ PROXY_AUTHENTICATION_REQUIRED: Symbol('407: Proxy Authentication Required'),
48
+ REQUEST_TIMEOUT: Symbol('408: Request Timeout'),
49
+ CONFLICT: Symbol('409: Conflict'),
50
+ GONE: Symbol('410: Gone'),
51
+ LENGTH_REQUIRED: Symbol('411: Length Required'),
52
+ PRECONDITION_FAILED: Symbol('412: Precondition Failed'),
53
+ PAYLOAD_TOO_LARGE: Symbol('413: Payload Too Large'),
54
+ URI_TOO_LONG: Symbol('414: URI Too Long'),
55
+ UNSUPPORTED_MEDIA_TYPE: Symbol('415: Unsupported Media Type'),
56
+ RANGE_NOT_SATISFIABLE: Symbol('416: Range Not Satisfiable'),
57
+ EXPECTATION_FAILED: Symbol('417: Expectation Failed'),
58
+ IM_A_TEAPOT: Symbol("418: I'm a teapot"),
59
+ MISDIRECTED_REQUEST: Symbol('421: Misdirected Request'),
60
+ UNPROCESSABLE_ENTITY: Symbol('422: Unprocessable Entity'),
61
+ LOCKED: Symbol('423: Locked'),
62
+ FAILED_DEPENDENCY: Symbol('424: Failed Dependency'),
63
+ TOO_EARLY: Symbol('425: Too Early'),
64
+ UPGRADE_REQUIRED: Symbol('426: Upgrade Required'),
65
+ PRECONDITION_REQUIRED: Symbol('428: Precondition Required'),
66
+ TOO_MANY_REQUESTS: Symbol('429: Too Many Requests'),
67
+ REQUEST_HEADER_FIELDS_TOO_LARGE: Symbol('431: Request Header Fields Too Large'),
68
+ UNAVAILABLE_FOR_LEGAL_REASONS: Symbol('451: Unavailable For Legal Reasons'),
69
+
70
+ // Server Errors:
71
+ INTERNAL_SERVER_ERROR: Symbol('500: Internal Server Error'),
72
+ NOT_IMPLEMENTED: Symbol('501: Not Implemented'),
73
+ BAD_GATEWAY: Symbol('502: Bad Gateway'),
74
+ SERVICE_UNAVAILABLE: Symbol('503: Service Unavailable'),
75
+ GATEWAY_TIMEOUT: Symbol('504: Gateway Timeout'),
76
+ HTTP_VERSION_NOT_SUPPORTED: Symbol('505: HTTP Version Not Supported'),
77
+ VARIANT_ALSO_NEGOTIATES: Symbol('506: Variant Also Negotiates'),
78
+ INSUFFICIENT_STORAGE: Symbol('507: Insufficient Storage'),
79
+ LOOP_DETECTED: Symbol('508: Loop Detected'),
80
+ NOT_EXTENDED: Symbol('510: Not Extended'),
81
+ NETWORK_AUTHENTICATION_REQUIRED: Symbol('511: Network Authentication Required')
82
+ });
@@ -2,17 +2,21 @@
2
2
  * /nodester
3
3
  * MIT Licensed
4
4
  */
5
+
5
6
  'use strict';
6
7
 
8
+ const { IncomingMessage } = require('http');
9
+
7
10
  const accepts = require('accepts');
8
11
  const isIP = require('net').isIP;
9
12
  const typeis = require('type-is');
10
- const { IncomingMessage } = require('http');
11
13
  const fresh = require('fresh');
12
14
  const parseRange = require('range-parser');
13
15
  const parse = require('parseurl');
14
16
  const proxyaddr = require('proxy-addr');
15
17
 
18
+ const { defineGetter } = require('./utils');
19
+
16
20
 
17
21
  const req = IncomingMessage.prototype;
18
22
 
@@ -38,8 +42,10 @@ module.exports = req;
38
42
  * Aliased as `req.header()`.
39
43
  *
40
44
  * @param {String} name
45
+ *
41
46
  * @return {String}
42
- * @public
47
+ *
48
+ * @api public
43
49
  */
44
50
  req.get =
45
51
  req.header = function header(name) {
@@ -106,7 +112,8 @@ req.header = function header(name) {
106
112
  *
107
113
  * @param {String|Array} type(s)
108
114
  * @return {String|Array|Boolean}
109
- * @public
115
+ *
116
+ * @api public
110
117
  */
111
118
  req.accepts = function() {
112
119
  const accept = accepts(this);
@@ -119,7 +126,8 @@ req.accepts = function() {
119
126
  *
120
127
  * @param {String} ...encoding
121
128
  * @return {String|Array}
122
- * @public
129
+ *
130
+ * @api public
123
131
  */
124
132
  req.acceptsEncodings = function() {
125
133
  const accept = accepts(this);
@@ -133,7 +141,8 @@ req.acceptsEncodings = function() {
133
141
  *
134
142
  * @param {String} ...charset
135
143
  * @return {String|Array}
136
- * @public
144
+ *
145
+ * @api public
137
146
  */
138
147
  req.acceptsCharsets = function() {
139
148
  const accept = accepts(this);
@@ -147,7 +156,8 @@ req.acceptsCharsets = function() {
147
156
  *
148
157
  * @param {String} ...lang
149
158
  * @return {String|Array}
150
- * @public
159
+ *
160
+ * @api public
151
161
  */
152
162
  req.acceptsLanguages = function() {
153
163
  const accept = accepts(this);
@@ -176,8 +186,10 @@ req.acceptsLanguages = function() {
176
186
  * @param {number} size
177
187
  * @param {object} [options]
178
188
  * @param {boolean} [options.combine=false]
189
+ *
179
190
  * @return {number|array}
180
- * @public
191
+ *
192
+ * @api public
181
193
  */
182
194
  req.range = function range(size, options) {
183
195
  const range = this.get('Range');
@@ -211,7 +223,8 @@ req.range = function range(size, options) {
211
223
  *
212
224
  * @param {String|Array} types...
213
225
  * @return {String|false|null}
214
- * @public
226
+ *
227
+ * @api public
215
228
  */
216
229
  req.is = function is(types) {
217
230
  let arr = types;
@@ -239,7 +252,8 @@ req.is = function is(types) {
239
252
  * supplies https for you this may be enabled.
240
253
  *
241
254
  * @return {String}
242
- * @public
255
+ *
256
+ * @api public
243
257
  */
244
258
 
245
259
  defineGetter(req, 'protocol', function protocol() {
@@ -254,12 +268,13 @@ defineGetter(req, 'protocol', function protocol() {
254
268
 
255
269
  // Note: X-Forwarded-Proto is normally only ever a
256
270
  // single value, but this is to be safe.
257
- const header = this.get('X-Forwarded-Proto') || proto
258
- const index = header.indexOf(',')
271
+ const header = this.get('X-Forwarded-Proto') || proto;
272
+ const index = header.indexOf(',');
259
273
 
260
- return index !== -1
261
- ? header.substring(0, index).trim()
262
- : header.trim()
274
+ return index !== -1 ?
275
+ header.substring(0, index).trim()
276
+ :
277
+ header.trim();
263
278
  });
264
279
 
265
280
 
@@ -269,7 +284,8 @@ defineGetter(req, 'protocol', function protocol() {
269
284
  * req.protocol === 'https'
270
285
  *
271
286
  * @return {Boolean}
272
- * @public
287
+ *
288
+ * @api public
273
289
  */
274
290
  defineGetter(req, 'secure', function secure() {
275
291
  return this.protocol === 'https';
@@ -283,7 +299,8 @@ defineGetter(req, 'secure', function secure() {
283
299
  * "trust proxy" is set.
284
300
  *
285
301
  * @return {String}
286
- * @public
302
+ *
303
+ * @api public
287
304
  */
288
305
  defineGetter(req, 'ip', function ip() {
289
306
  const trust = this.app.get('trust proxy fn');
@@ -299,8 +316,9 @@ defineGetter(req, 'ip', function ip() {
299
316
  * where "proxy2" is the furthest down-stream and "proxy1" and
300
317
  * "proxy2" were trusted.
301
318
  *
302
- * @return {Array}
303
- * @public
319
+ * @return {Array} addresses
320
+ *
321
+ * @api public
304
322
  */
305
323
  defineGetter(req, 'ips', function ips() {
306
324
  const trust = this.app.get('trust proxy fn');
@@ -308,37 +326,9 @@ defineGetter(req, 'ips', function ips() {
308
326
 
309
327
  // reverse the order (to farthest -> closest)
310
328
  // and remove socket address
311
- addrs.reverse().pop()
329
+ addresses.reverse().pop()
312
330
 
313
- return addrs
314
- });
315
-
316
-
317
- /**
318
- * Return subdomains as an array.
319
- *
320
- * Subdomains are the dot-separated parts of the host before the main domain of
321
- * the app. By default, the domain of the app is assumed to be the last two
322
- * parts of the host. This can be changed by setting "subdomain offset".
323
- *
324
- * For example, if the domain is "tobi.ferrets.example.com":
325
- * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
326
- * If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
327
- *
328
- * @return {Array}
329
- * @public
330
- */
331
- defineGetter(req, 'subdomains', function subdomains() {
332
- const hostname = this.hostname;
333
-
334
- if (!hostname) return [];
335
-
336
- const offset = this.app.get('subdomain offset');
337
- const subdomains = !isIP(hostname)
338
- ? hostname.split('.').reverse()
339
- : [hostname];
340
-
341
- return subdomains.slice(offset);
331
+ return addresses;
342
332
  });
343
333
 
344
334
 
@@ -346,7 +336,8 @@ defineGetter(req, 'subdomains', function subdomains() {
346
336
  * Short-hand for `url.parse(req.url).pathname`.
347
337
  *
348
338
  * @return {String}
349
- * @public
339
+ *
340
+ * @api public
350
341
  */
351
342
  defineGetter(req, 'path', function path() {
352
343
  return parse(this).pathname;
@@ -359,7 +350,8 @@ defineGetter(req, 'path', function path() {
359
350
  * or "Host" as a fallback.
360
351
  *
361
352
  * @return {String}
362
- * @public
353
+ *
354
+ * @api public
363
355
  */
364
356
  defineGetter(req, 'hostname', function hostname() {
365
357
  const host = this.get('X-Forwarded-Host') ?? this.get('Host');
@@ -373,23 +365,24 @@ defineGetter(req, 'hostname', function hostname() {
373
365
  * still match.
374
366
  *
375
367
  * @return {Boolean}
376
- * @public
368
+ *
369
+ * @api public
377
370
  */
378
371
  defineGetter(req, 'fresh', function() {
379
372
  const method = this.method;
380
- const res = this.res
381
- const status = res.statusCode
373
+ const res = this.res;
374
+ const status = res.statusCode;
382
375
 
383
376
  // GET or HEAD for weak freshness validation only
384
- if ('GET' !== method && 'HEAD' !== method)
377
+ if (method !== 'GET' && method !== 'HEAD')
385
378
  return false;
386
379
 
387
380
  // 2xx or 304 as per rfc2616 14.26
388
381
  if ((status >= 200 && status < 300) || 304 === status) {
389
382
  return fresh(this.headers, {
390
- 'etag': res.get('ETag'),
383
+ 'etag': res.get('etag'),
391
384
  'last-modified': res.get('Last-Modified')
392
- })
385
+ });
393
386
  }
394
387
 
395
388
  return false;
@@ -402,7 +395,8 @@ defineGetter(req, 'fresh', function() {
402
395
  * resource has changed.
403
396
  *
404
397
  * @return {Boolean}
405
- * @public
398
+ *
399
+ * @api public
406
400
  */
407
401
  defineGetter(req, 'stale', function stale() {
408
402
  return !this.fresh;
@@ -413,26 +407,10 @@ defineGetter(req, 'stale', function stale() {
413
407
  * Check if the request was an _XMLHttpRequest_.
414
408
  *
415
409
  * @return {Boolean}
416
- * @public
410
+ *
411
+ * @api public
417
412
  */
418
413
  defineGetter(req, 'xhr', function xhr() {
419
414
  const val = this.get('X-Requested-With') || '';
420
415
  return val.toLowerCase() === 'xmlhttprequest';
421
416
  });
422
-
423
-
424
- /**
425
- * Helper function for creating a getter on an object.
426
- *
427
- * @param {Object} obj
428
- * @param {String} name
429
- * @param {Function} getter
430
- * @private
431
- */
432
- function defineGetter(obj, name, getter) {
433
- Object.defineProperty(obj, name, {
434
- configurable: true,
435
- enumerable: true,
436
- get: getter
437
- });
438
- }
@@ -0,0 +1,27 @@
1
+ /*!
2
+ * /nodester
3
+ * MIT Licensed
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ module.exports = {
9
+ defineGetter: _defineGetter
10
+ }
11
+
12
+ /**
13
+ * Helper function for creating a getter on an object.
14
+ *
15
+ * @param {Object} obj
16
+ * @param {String} name
17
+ * @param {Function} getter
18
+ *
19
+ * @api private
20
+ */
21
+ function _defineGetter(obj, name, getter) {
22
+ Object.defineProperty(obj, name, {
23
+ configurable: true,
24
+ enumerable: true,
25
+ get: getter
26
+ });
27
+ }