@adonisjs/http-server 5.5.6 → 5.6.1

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The MIT License
2
2
 
3
- Copyright 2021 Harminder Virk, contributors
3
+ Copyright 2022 Harminder Virk, contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
@@ -534,7 +534,7 @@ declare module '@ioc:Adonis/Core/Request' {
534
534
  * Shape of the request config
535
535
  */
536
536
  export type RequestConfig = {
537
- forceContentNegotiationTo?: string;
537
+ forceContentNegotiationTo?: string | ((ctx: HttpContextContract) => string);
538
538
  subdomainOffset: number;
539
539
  generateRequestId: boolean;
540
540
  allowMethodSpoofing: boolean;
@@ -474,6 +474,7 @@ declare module '@ioc:Adonis/Core/Route' {
474
474
  */
475
475
  uuid(): {
476
476
  match: RegExp;
477
+ cast: (value: string) => string;
477
478
  };
478
479
  /**
479
480
  * Enforce value to be formatted as slug
@@ -87,7 +87,7 @@ class CookieClient {
87
87
  * array of parsed cookies
88
88
  */
89
89
  parse(setCookieHeader) {
90
- const cookies = set_cookie_parser_1.default(setCookieHeader);
90
+ const cookies = (0, set_cookie_parser_1.default)(setCookieHeader);
91
91
  return cookies.map((cookie) => {
92
92
  cookie.encrypted = false;
93
93
  cookie.signed = false;
@@ -42,7 +42,7 @@ class CookieSerializer {
42
42
  */
43
43
  let maxAge = options?.maxAge;
44
44
  if (typeof maxAge === 'string') {
45
- maxAge = ms_1.default(maxAge) / 1000;
45
+ maxAge = (0, ms_1.default)(maxAge) / 1000;
46
46
  }
47
47
  const parsedOptions = Object.assign({}, options, { maxAge, expires });
48
48
  return cookie_1.default.serialize(key, value, parsedOptions);
@@ -24,11 +24,11 @@ class HttpException extends utils_1.Exception {
24
24
  const message = exceptions_json_1.E_HTTP_EXCEPTION.message;
25
25
  code = code || exceptions_json_1.E_HTTP_EXCEPTION.code;
26
26
  if (body !== null && typeof body === 'object') {
27
- const error = new this(body.message || helpers_1.interpolate(message, { status }), status, code);
27
+ const error = new this(body.message || (0, helpers_1.interpolate)(message, { status }), status, code);
28
28
  error.body = body;
29
29
  return error;
30
30
  }
31
- const error = new this(body || helpers_1.interpolate(message, { status }), status, code);
31
+ const error = new this(body || (0, helpers_1.interpolate)(message, { status }), status, code);
32
32
  error.body = error.message;
33
33
  return error;
34
34
  }
@@ -29,7 +29,7 @@ class RouterException extends utils_1.Exception {
29
29
  * Raised when a duplicate route pattern is find for the same HTTP method
30
30
  */
31
31
  static duplicateRoute(method, pattern) {
32
- const error = new this(helpers_1.interpolate(exceptions_json_1.E_DUPLICATE_ROUTE.message, { method, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE.status, exceptions_json_1.E_DUPLICATE_ROUTE.code);
32
+ const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE.message, { method, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE.status, exceptions_json_1.E_DUPLICATE_ROUTE.code);
33
33
  error.help = exceptions_json_1.E_DUPLICATE_ROUTE.help.join('\n');
34
34
  throw error;
35
35
  }
@@ -37,13 +37,13 @@ class RouterException extends utils_1.Exception {
37
37
  * Raised when a route has duplicate params
38
38
  */
39
39
  static duplicateRouteParam(param, pattern) {
40
- return new this(helpers_1.interpolate(exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.message, { param, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.status, exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.code);
40
+ return new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.message, { param, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.status, exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.code);
41
41
  }
42
42
  /**
43
43
  * Raised when route name is not unique
44
44
  */
45
45
  static duplicateRouteName(name) {
46
- const error = new this(helpers_1.interpolate(exceptions_json_1.E_DUPLICATE_ROUTE_NAME.message, { name }), exceptions_json_1.E_DUPLICATE_ROUTE_NAME.status, exceptions_json_1.E_DUPLICATE_ROUTE_NAME.code);
46
+ const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE_NAME.message, { name }), exceptions_json_1.E_DUPLICATE_ROUTE_NAME.status, exceptions_json_1.E_DUPLICATE_ROUTE_NAME.code);
47
47
  error.help = exceptions_json_1.E_DUPLICATE_ROUTE_NAME.help.join('\n');
48
48
  throw error;
49
49
  }
@@ -52,7 +52,7 @@ class RouterException extends utils_1.Exception {
52
52
  * params value is not defined
53
53
  */
54
54
  static cannotMakeRoute(param, pattern) {
55
- const error = new this(helpers_1.interpolate(exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.message, { pattern, param }), exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.status, exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.code);
55
+ const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.message, { pattern, param }), exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.status, exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.code);
56
56
  error.help = exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.help.join('\n');
57
57
  throw error;
58
58
  }
@@ -60,7 +60,7 @@ class RouterException extends utils_1.Exception {
60
60
  * Raised when unable to lookup a route using its identifier
61
61
  */
62
62
  static cannotLookupRoute(identifier) {
63
- const error = new this(helpers_1.interpolate(exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.message, { identifier }), exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.status, exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.code);
63
+ const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.message, { identifier }), exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.status, exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.code);
64
64
  error.help = exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.help.join('\n');
65
65
  throw error;
66
66
  }
@@ -68,7 +68,7 @@ class RouterException extends utils_1.Exception {
68
68
  * Raised when unable to lookup domain
69
69
  */
70
70
  static cannotLookupDomain(domain) {
71
- const error = new this(helpers_1.interpolate(exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.message, { domain }), exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.status, exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.code);
71
+ const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.message, { domain }), exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.status, exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.code);
72
72
  error.help = exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.help.join('\n');
73
73
  throw error;
74
74
  }
@@ -100,7 +100,7 @@ class HttpContext extends macroable_1.Macroable {
100
100
  * A helper to see top level properties on the context object
101
101
  */
102
102
  inspect() {
103
- return util_1.inspect(this, false, 1, true);
103
+ return (0, util_1.inspect)(this, false, 1, true);
104
104
  }
105
105
  /**
106
106
  * Creates a new fake context instance for a given route. The method is
@@ -119,7 +119,7 @@ class HttpContext extends macroable_1.Macroable {
119
119
  * Creating the url from the router pattern and params. Only
120
120
  * when actual URL isn't defined.
121
121
  */
122
- req.url = req.url || helpers_1.processPattern(routePattern, routeParams);
122
+ req.url = req.url || (0, helpers_1.processPattern)(routePattern, routeParams);
123
123
  /*
124
124
  * Creating new request instance
125
125
  */
@@ -43,7 +43,7 @@ class Redirect {
43
43
  sendResponse(url, query) {
44
44
  const stringified = qs_1.default.stringify(query);
45
45
  url = stringified ? `${url}?${stringified}` : url;
46
- this.response.location(encodeurl_1.default(url));
46
+ this.response.location((0, encodeurl_1.default)(url));
47
47
  this.response.safeStatus(this.statusCode);
48
48
  this.response.type('text/plain; charset=utf-8');
49
49
  this.response.send(`Redirecting to ${url}`);
@@ -88,7 +88,7 @@ class Redirect {
88
88
  */
89
89
  back() {
90
90
  let query = {};
91
- const url = url_1.parse(this.getReferrerUrl());
91
+ const url = (0, url_1.parse)(this.getReferrerUrl());
92
92
  /**
93
93
  * Parse query string from the referrer url
94
94
  */
@@ -124,7 +124,7 @@ class Redirect {
124
124
  * Extract query string from the current URL
125
125
  */
126
126
  if (this.forwardQueryString) {
127
- query = qs_1.default.parse(url_1.parse(this.request.url).query || '');
127
+ query = qs_1.default.parse((0, url_1.parse)(this.request.url).query || '');
128
128
  }
129
129
  /**
130
130
  * Assign custom query string
@@ -76,7 +76,7 @@ class Request extends macroable_1.Macroable {
76
76
  * object. This is done to build URL's with query string without
77
77
  * stringifying the object
78
78
  */
79
- this.parsedUrl = url_1.parse(this.request.url, false);
79
+ this.parsedUrl = (0, url_1.parse)(this.request.url, false);
80
80
  this.parseQueryString();
81
81
  }
82
82
  /**
@@ -102,7 +102,7 @@ class Request extends macroable_1.Macroable {
102
102
  * methods are used.
103
103
  */
104
104
  initiateAccepts() {
105
- this.lazyAccepts = this.lazyAccepts || accepts_1.default(this.request);
105
+ this.lazyAccepts = this.lazyAccepts || (0, accepts_1.default)(this.request);
106
106
  }
107
107
  /**
108
108
  * Returns the request id from the `x-request-id` header. The
@@ -111,7 +111,7 @@ class Request extends macroable_1.Macroable {
111
111
  id() {
112
112
  let requestId = this.header('x-request-id');
113
113
  if (!requestId && this.config.generateRequestId) {
114
- requestId = helpers_1.cuid();
114
+ requestId = (0, helpers_1.cuid)();
115
115
  this.request.headers['x-request-id'] = requestId;
116
116
  }
117
117
  return requestId;
@@ -360,7 +360,7 @@ class Request extends macroable_1.Macroable {
360
360
  if (typeof ipFn === 'function') {
361
361
  return ipFn(this);
362
362
  }
363
- return proxy_addr_1.default(this.request, this.config.trustProxy);
363
+ return (0, proxy_addr_1.default)(this.request, this.config.trustProxy);
364
364
  }
365
365
  /**
366
366
  * Returns an array of ip addresses from most to least trusted one.
@@ -407,7 +407,7 @@ class Request extends macroable_1.Macroable {
407
407
  if (this.request.connection['encrypted']) {
408
408
  return 'https';
409
409
  }
410
- if (!helpers_2.trustProxy(this.request.connection.remoteAddress, this.config.trustProxy)) {
410
+ if (!(0, helpers_2.trustProxy)(this.request.connection.remoteAddress, this.config.trustProxy)) {
411
411
  return this.parsedUrl.protocol || 'http';
412
412
  }
413
413
  const forwardedProtocol = this.header('X-Forwarded-Proto');
@@ -444,7 +444,7 @@ class Request extends macroable_1.Macroable {
444
444
  * Use X-Fowarded-Host when we trust the proxy header and it
445
445
  * exists
446
446
  */
447
- if (!helpers_2.trustProxy(this.request.connection.remoteAddress, this.config.trustProxy)) {
447
+ if (!(0, helpers_2.trustProxy)(this.request.connection.remoteAddress, this.config.trustProxy)) {
448
448
  host = this.header('X-Forwarded-Host') || host;
449
449
  }
450
450
  if (!host) {
@@ -495,7 +495,7 @@ class Request extends macroable_1.Macroable {
495
495
  * Return empty array when hostname is missing or it's
496
496
  * an IP address
497
497
  */
498
- if (!hostname || net_1.isIP(hostname)) {
498
+ if (!hostname || (0, net_1.isIP)(hostname)) {
499
499
  return [];
500
500
  }
501
501
  const offset = this.config.subdomainOffset;
@@ -604,7 +604,7 @@ class Request extends macroable_1.Macroable {
604
604
  * ```
605
605
  */
606
606
  is(types) {
607
- return type_is_1.default(this.request, types) || null;
607
+ return (0, type_is_1.default)(this.request, types) || null;
608
608
  }
609
609
  /**
610
610
  * Returns the best type using `Accept` header and
@@ -773,7 +773,7 @@ class Request extends macroable_1.Macroable {
773
773
  }
774
774
  const status = this.response.statusCode;
775
775
  if ((status >= 200 && status < 300) || status === 304) {
776
- return fresh_1.default(this.headers(), this.response.getHeaders());
776
+ return (0, fresh_1.default)(this.headers(), this.response.getHeaders());
777
777
  }
778
778
  return false;
779
779
  }
@@ -154,7 +154,7 @@ class Response extends macroable_1.Macroable {
154
154
  if (dataType === 'object') {
155
155
  return 'object';
156
156
  }
157
- const error = new utils_1.Exception(helpers_1.interpolate(exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.message, { dataType }), exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.status, exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.code);
157
+ const error = new utils_1.Exception((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.message, { dataType }), exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.status, exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.code);
158
158
  error.help = exceptions_json_1.E_CANNOT_SERIALIZE_RESPONSE_BODY.help.join('\n');
159
159
  throw error;
160
160
  }
@@ -207,7 +207,7 @@ class Response extends macroable_1.Macroable {
207
207
  * Transforming date, number, boolean and object to a string
208
208
  */
209
209
  if (dataType === 'object') {
210
- content = utils_1.safeStringify(content);
210
+ content = (0, utils_1.safeStringify)(content);
211
211
  }
212
212
  else if (dataType === 'number' ||
213
213
  dataType === 'boolean' ||
@@ -324,7 +324,7 @@ class Response extends macroable_1.Macroable {
324
324
  return;
325
325
  }
326
326
  finished = true;
327
- destroy_1.default(body);
327
+ (0, destroy_1.default)(body);
328
328
  this.type('text');
329
329
  if (typeof errorCallback === 'function') {
330
330
  this.endResponse(...errorCallback(error));
@@ -341,9 +341,9 @@ class Response extends macroable_1.Macroable {
341
341
  /*
342
342
  * Cleanup stream when finishing response
343
343
  */
344
- on_finished_1.default(this.response, () => {
344
+ (0, on_finished_1.default)(this.response, () => {
345
345
  finished = true;
346
- destroy_1.default(body);
346
+ (0, destroy_1.default)(body);
347
347
  });
348
348
  /*
349
349
  * Pipe stream
@@ -357,7 +357,7 @@ class Response extends macroable_1.Macroable {
357
357
  */
358
358
  async streamFileForDownload(filePath, generateEtag, errorCallback) {
359
359
  try {
360
- const stats = await helpers_2.statFn(filePath);
360
+ const stats = await (0, helpers_2.statFn)(filePath);
361
361
  if (!stats || !stats.isFile()) {
362
362
  throw new utils_1.Exception('response.download only accepts path to a file');
363
363
  }
@@ -365,7 +365,7 @@ class Response extends macroable_1.Macroable {
365
365
  * Set appropriate headers
366
366
  */
367
367
  this.header('Last-Modified', stats.mtime.toUTCString());
368
- this.type(path_1.extname(filePath));
368
+ this.type((0, path_1.extname)(filePath));
369
369
  /*
370
370
  * Set the etag when instructed.
371
371
  */
@@ -402,7 +402,7 @@ class Response extends macroable_1.Macroable {
402
402
  /*
403
403
  * Finally stream the file
404
404
  */
405
- return this.streamBody(fs_1.createReadStream(filePath), errorCallback);
405
+ return this.streamBody((0, fs_1.createReadStream)(filePath), errorCallback);
406
406
  }
407
407
  catch (error) {
408
408
  this.type('text');
@@ -552,7 +552,7 @@ class Response extends macroable_1.Macroable {
552
552
  * Set the Vary HTTP header
553
553
  */
554
554
  vary(field) {
555
- vary_1.default(this.response, field);
555
+ (0, vary_1.default)(this.response, field);
556
556
  return this;
557
557
  }
558
558
  /**
@@ -562,7 +562,7 @@ class Response extends macroable_1.Macroable {
562
562
  * Use this function, when you want to compute etag manually for some other resons.
563
563
  */
564
564
  setEtag(body, weak = false) {
565
- this.header('Etag', etag_1.default(body, { weak }));
565
+ this.header('Etag', (0, etag_1.default)(body, { weak }));
566
566
  return this;
567
567
  }
568
568
  /**
@@ -596,7 +596,7 @@ class Response extends macroable_1.Macroable {
596
596
  }
597
597
  const status = this.response.statusCode;
598
598
  if ((status >= 200 && status < 300) || status === 304) {
599
- return fresh_1.default(this.request.headers, this.headers);
599
+ return (0, fresh_1.default)(this.request.headers, this.headers);
600
600
  }
601
601
  return false;
602
602
  }
@@ -718,7 +718,7 @@ class Response extends macroable_1.Macroable {
718
718
  */
719
719
  attachment(filePath, name, disposition, generateEtag, errorCallback) {
720
720
  name = name || filePath;
721
- this.header('Content-Disposition', content_disposition_1.default(name, { type: disposition }));
721
+ this.header('Content-Disposition', (0, content_disposition_1.default)(name, { type: disposition }));
722
722
  return this.download(filePath, generateEtag, errorCallback);
723
723
  }
724
724
  /**
@@ -94,7 +94,7 @@ class UrlBuilder {
94
94
  suffixQueryString(url) {
95
95
  if (this.queryString) {
96
96
  const encoded = qs_1.default.stringify(this.queryString);
97
- url = encoded ? `${url}?${encodeurl_1.default(encoded)}` : url;
97
+ url = encoded ? `${url}?${(0, encodeurl_1.default)(encoded)}` : url;
98
98
  }
99
99
  return url;
100
100
  }
@@ -20,6 +20,7 @@ export declare class RouteMatchers extends Macroable implements RouteMatchersCon
20
20
  */
21
21
  uuid(): {
22
22
  match: RegExp;
23
+ cast: (value: string) => string;
23
24
  };
24
25
  /**
25
26
  * Enforce value to be formatted as slug
@@ -26,7 +26,10 @@ class RouteMatchers extends macroable_1.Macroable {
26
26
  * Enforce value to be formatted as uuid
27
27
  */
28
28
  uuid() {
29
- return { match: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/ };
29
+ return {
30
+ match: /^[0-9a-zA-F]{8}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{12}$/,
31
+ cast: (value) => value.toLowerCase(),
32
+ };
30
33
  }
31
34
  /**
32
35
  * Enforce value to be formatted as slug
@@ -60,7 +60,7 @@ class RouteResource extends macroable_1.Macroable {
60
60
  const resourceTokens = this.resource.split('.');
61
61
  const mainResource = resourceTokens.pop();
62
62
  const fullUrl = `${resourceTokens
63
- .map((token) => `${token}/:${helpers_1.string.snakeCase(pluralize_1.singular(token))}_id`)
63
+ .map((token) => `${token}/:${helpers_1.string.snakeCase((0, pluralize_1.singular)(token))}_id`)
64
64
  .join('/')}/${mainResource}`;
65
65
  this.makeRoute(fullUrl, ['HEAD', 'GET'], 'index');
66
66
  this.makeRoute(`${fullUrl}/create`, ['HEAD', 'GET'], 'create');
@@ -76,11 +76,11 @@ class Route extends macroable_1.Macroable {
76
76
  * Returns a normalized pattern string by prefixing the `prefix` (if defined).
77
77
  */
78
78
  getPattern() {
79
- const pattern = helpers_2.dropSlash(this.pattern);
79
+ const pattern = (0, helpers_2.dropSlash)(this.pattern);
80
80
  const prefix = this.prefixes
81
81
  .slice()
82
82
  .reverse()
83
- .map((one) => helpers_2.dropSlash(one))
83
+ .map((one) => (0, helpers_2.dropSlash)(one))
84
84
  .join('');
85
85
  return prefix ? `${prefix}${pattern === '/' ? '' : pattern}` : pattern;
86
86
  }
@@ -240,7 +240,7 @@ class Router {
240
240
  */
241
241
  commit() {
242
242
  const names = [];
243
- helpers_2.toRoutesJSON(this.routes).forEach((route) => {
243
+ (0, helpers_2.toRoutesJSON)(this.routes).forEach((route) => {
244
244
  /*
245
245
  * Raise error when route name is already in use. Route names have to be unique
246
246
  * to ensure that only one route is returned during lookup.
@@ -320,7 +320,7 @@ class Router {
320
320
  * name or the controller.method
321
321
  */
322
322
  makeUrl(routeIdentifier, params, options) {
323
- const normalizedOptions = helpers_2.normalizeMakeUrlOptions(params, options);
323
+ const normalizedOptions = (0, helpers_2.normalizeMakeUrlOptions)(params, options);
324
324
  const builder = normalizedOptions.domain
325
325
  ? this.builderForDomain(normalizedOptions.domain)
326
326
  : this.builder();
@@ -334,7 +334,7 @@ class Router {
334
334
  * relying on any sort of backend storage.
335
335
  */
336
336
  makeSignedUrl(routeIdentifier, params, options) {
337
- const normalizedOptions = helpers_2.normalizeMakeSignedUrlOptions(params, options);
337
+ const normalizedOptions = (0, helpers_2.normalizeMakeSignedUrlOptions)(params, options);
338
338
  const builder = normalizedOptions.domain
339
339
  ? this.builderForDomain(normalizedOptions.domain)
340
340
  : this.builder();
@@ -60,7 +60,7 @@ class ExceptionManager {
60
60
  else {
61
61
  value = await this.resolver.call(this.resolvedErrorHandler, undefined, [error, ctx]);
62
62
  }
63
- if (helpers_1.useReturnValue(value, ctx)) {
63
+ if ((0, helpers_1.useReturnValue)(value, ctx)) {
64
64
  ctx.response.send(value);
65
65
  }
66
66
  }
@@ -46,7 +46,7 @@ class PreCompiler {
46
46
  else {
47
47
  returnValue = await this.resolver.call(routeHandler, undefined, [ctx]);
48
48
  }
49
- if (helpers_2.useReturnValue(returnValue, ctx)) {
49
+ if ((0, helpers_2.useReturnValue)(returnValue, ctx)) {
50
50
  ctx.response.send(returnValue);
51
51
  }
52
52
  };
@@ -98,7 +98,7 @@ class PreCompiler {
98
98
  */
99
99
  const resolvedMiddleware = this.middlewareStore.getNamed(name);
100
100
  if (!resolvedMiddleware) {
101
- const error = new utils_1.Exception(helpers_1.interpolate(exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.message, { name }), exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.status, exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.code);
101
+ const error = new utils_1.Exception((0, helpers_1.interpolate)(exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.message, { name }), exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.status, exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.code);
102
102
  error.help = exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.help.join('\n');
103
103
  throw error;
104
104
  }
@@ -46,7 +46,7 @@ class RequestHandler {
46
46
  * Raise error when route is missing
47
47
  */
48
48
  if (!route) {
49
- throw HttpException_1.HttpException.invoke(helpers_1.interpolate(exceptions_json_1.E_ROUTE_NOT_FOUND.message, { method, url }), exceptions_json_1.E_ROUTE_NOT_FOUND.status, exceptions_json_1.E_ROUTE_NOT_FOUND.code);
49
+ throw HttpException_1.HttpException.invoke((0, helpers_1.interpolate)(exceptions_json_1.E_ROUTE_NOT_FOUND.message, { method, url }), exceptions_json_1.E_ROUTE_NOT_FOUND.status, exceptions_json_1.E_ROUTE_NOT_FOUND.code);
50
50
  }
51
51
  /*
52
52
  * Attach `params`, `subdomains` and `route` when route is found. This
@@ -60,9 +60,9 @@ class Server {
60
60
  * Pre process config to convert max age string to seconds.
61
61
  */
62
62
  if (httpConfig.cookie.maxAge && typeof httpConfig.cookie.maxAge === 'string') {
63
- httpConfig.cookie.maxAge = ms_1.default(httpConfig.cookie.maxAge) / 1000;
63
+ httpConfig.cookie.maxAge = (0, ms_1.default)(httpConfig.cookie.maxAge) / 1000;
64
64
  }
65
- LocalStorage_1.useAsyncLocalStorage(httpConfig.useAsyncLocalStorage || false);
65
+ (0, LocalStorage_1.useAsyncLocalStorage)(httpConfig.useAsyncLocalStorage || false);
66
66
  }
67
67
  /**
68
68
  * Handles HTTP request
@@ -153,16 +153,17 @@ class Server {
153
153
  * server
154
154
  */
155
155
  async handle(req, res) {
156
- /*
157
- * Reset accept header when `forceContentNegotiationToJSON = true`
158
- */
159
- if (this.httpConfig.forceContentNegotiationTo) {
160
- req.headers['accept'] = this.httpConfig.forceContentNegotiationTo;
161
- }
162
156
  const request = new Request_1.Request(req, res, this.encryption, this.httpConfig);
163
157
  const response = new Response_1.Response(req, res, this.encryption, this.httpConfig, this.router);
164
158
  const requestAction = this.getProfilerRow(request);
165
159
  const ctx = this.getContext(request, response, requestAction);
160
+ /*
161
+ * Reset accept header when `forceContentNegotiationTo` is defined
162
+ */
163
+ const accept = this.httpConfig.forceContentNegotiationTo;
164
+ if (accept) {
165
+ req.headers['accept'] = typeof accept === 'function' ? accept(ctx) : accept;
166
+ }
166
167
  if (LocalStorage_1.usingAsyncLocalStorage) {
167
168
  return LocalStorage_1.httpContextLocalStorage.run(ctx, () => this.handleRequest(ctx, requestAction, res));
168
169
  }
@@ -182,7 +182,7 @@ exports.normalizeMakeSignedUrlOptions = normalizeMakeSignedUrlOptions;
182
182
  */
183
183
  function statFn(filePath) {
184
184
  return new Promise((resolve, reject) => {
185
- fs_1.stat(filePath, (error, stats) => {
185
+ (0, fs_1.stat)(filePath, (error, stats) => {
186
186
  if (error) {
187
187
  reject(error);
188
188
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "5.5.6",
3
+ "version": "5.6.1",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/providers/HttpServerProvider.js",
6
6
  "files": [
@@ -14,14 +14,14 @@
14
14
  "scripts": {
15
15
  "mrm": "mrm --preset=@adonisjs/mrm-preset",
16
16
  "pretest": "npm run lint",
17
- "test": "node japaFile.js && cross-env ASYNC_HOOKS=1 node japaFile.js",
17
+ "test": "node .bin/test.js",
18
18
  "clean": "del build",
19
19
  "compile": "npm run lint && npm run clean && tsc",
20
20
  "build": "npm run compile",
21
21
  "benchmark": "ENV_SILENT=true node build/benchmarks/index.js",
22
22
  "build:tmp": "npm run compile",
23
23
  "commit": "git-cz",
24
- "release": "np",
24
+ "release": "np --message=\"chore(release): %s\"",
25
25
  "version": "npm run build",
26
26
  "prepublishOnly": "npm run build",
27
27
  "lint": "eslint . --ext=.ts",
@@ -36,38 +36,40 @@
36
36
  "author": "virk,adonisjs",
37
37
  "license": "MIT",
38
38
  "devDependencies": {
39
- "@adonisjs/application": "^5.1.6",
40
- "@adonisjs/encryption": "^4.0.5",
41
- "@adonisjs/mrm-preset": "^4.1.2",
42
- "@adonisjs/require-ts": "^2.0.7",
43
- "@poppinss/dev-utils": "^1.1.5",
39
+ "@adonisjs/application": "^5.1.10",
40
+ "@adonisjs/encryption": "^4.0.7",
41
+ "@adonisjs/mrm-preset": "^5.0.2",
42
+ "@adonisjs/require-ts": "^2.0.10",
43
+ "@poppinss/dev-utils": "^2.0.2",
44
44
  "@types/cookie": "^0.4.1",
45
45
  "@types/ms": "^0.7.31",
46
- "@types/node": "^16.6.2",
46
+ "@types/node": "^17.0.21",
47
47
  "@types/pluralize": "0.0.29",
48
48
  "@types/proxy-addr": "^2.0.0",
49
49
  "@types/qs": "^6.9.7",
50
50
  "@types/supertest": "^2.0.11",
51
- "autocannon": "^7.4.0",
51
+ "autocannon": "^7.7.0",
52
+ "commitizen": "^4.2.4",
52
53
  "cross-env": "^7.0.3",
54
+ "cz-conventional-changelog": "^3.3.0",
53
55
  "del-cli": "^4.0.1",
54
- "eslint": "^7.31.0",
55
- "eslint-config-prettier": "^8.3.0",
56
- "eslint-plugin-adonis": "^1.3.3",
57
- "eslint-plugin-prettier": "^3.4.0",
58
- "fastify": "^3.20.2",
56
+ "eslint": "^8.9.0",
57
+ "eslint-config-prettier": "^8.4.0",
58
+ "eslint-plugin-adonis": "^2.1.0",
59
+ "eslint-plugin-prettier": "^4.0.0",
60
+ "fastify": "^3.27.2",
59
61
  "github-label-sync": "^2.0.2",
60
- "http-status-codes": "^2.1.4",
61
- "husky": "^7.0.1",
62
- "japa": "^3.1.1",
63
- "middie": "^5.3.0",
64
- "mrm": "^3.0.5",
65
- "np": "^7.5.0",
66
- "pem": "^1.14.4",
67
- "prettier": "^2.3.2",
62
+ "http-status-codes": "^2.2.0",
63
+ "husky": "^7.0.4",
64
+ "japa": "^4.0.0",
65
+ "middie": "^6.0.0",
66
+ "mrm": "^3.0.10",
67
+ "np": "^7.6.0",
68
+ "pem": "^1.14.6",
69
+ "prettier": "^2.5.1",
68
70
  "reflect-metadata": "^0.1.13",
69
- "supertest": "^6.1.6",
70
- "typescript": "^4.3.5"
71
+ "supertest": "^6.2.2",
72
+ "typescript": "^4.5.5"
71
73
  },
72
74
  "peerDependencies": {
73
75
  "@adonisjs/application": "^5.0.0",
@@ -92,23 +94,23 @@
92
94
  },
93
95
  "dependencies": {
94
96
  "@poppinss/matchit": "^3.1.2",
95
- "@poppinss/utils": "^3.1.5",
96
- "accepts": "^1.3.7",
97
- "co-compose": "^6.1.4",
98
- "content-disposition": "^0.5.3",
99
- "cookie": "^0.4.1",
100
- "destroy": "^1.0.4",
97
+ "@poppinss/utils": "^4.0.2",
98
+ "accepts": "^1.3.8",
99
+ "co-compose": "^7.0.1",
100
+ "content-disposition": "^0.5.4",
101
+ "cookie": "^0.4.2",
102
+ "destroy": "^1.1.0",
101
103
  "encodeurl": "^1.0.2",
102
104
  "etag": "^1.8.1",
103
105
  "fresh": "^0.5.2",
104
106
  "haye": "^3.0.0",
105
- "macroable": "^5.1.4",
106
- "mime-types": "^2.1.31",
107
+ "macroable": "^6.0.1",
108
+ "mime-types": "^2.1.34",
107
109
  "ms": "^2.1.3",
108
- "on-finished": "^2.3.0",
110
+ "on-finished": "^2.4.1",
109
111
  "pluralize": "^8.0.0",
110
112
  "proxy-addr": "^2.0.7",
111
- "qs": "^6.10.1",
113
+ "qs": "^6.10.3",
112
114
  "set-cookie-parser": "^2.4.8",
113
115
  "tmp-cache": "^1.1.0",
114
116
  "type-is": "^1.6.18",
@@ -132,5 +134,48 @@
132
134
  "publishConfig": {
133
135
  "access": "public",
134
136
  "tag": "latest"
137
+ },
138
+ "mrmConfig": {
139
+ "core": true,
140
+ "license": "MIT",
141
+ "services": [
142
+ "github-actions"
143
+ ],
144
+ "minNodeVersion": "14.15.4",
145
+ "probotApps": [
146
+ "stale",
147
+ "lock"
148
+ ],
149
+ "runGhActionsOnWindows": false
150
+ },
151
+ "eslintConfig": {
152
+ "extends": [
153
+ "plugin:adonis/typescriptPackage",
154
+ "prettier"
155
+ ],
156
+ "plugins": [
157
+ "prettier"
158
+ ],
159
+ "rules": {
160
+ "prettier/prettier": [
161
+ "error",
162
+ {
163
+ "endOfLine": "auto"
164
+ }
165
+ ]
166
+ }
167
+ },
168
+ "eslintIgnore": [
169
+ "build"
170
+ ],
171
+ "prettier": {
172
+ "trailingComma": "es5",
173
+ "semi": false,
174
+ "singleQuote": true,
175
+ "useTabs": false,
176
+ "quoteProps": "consistent",
177
+ "bracketSpacing": true,
178
+ "arrowParens": "always",
179
+ "printWidth": 100
135
180
  }
136
181
  }