@adonisjs/http-server 6.8.2-10 → 6.8.2-12

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.
@@ -1,3 +1,4 @@
1
+ import Macroable from '@poppinss/macroable';
1
2
  import type { Level } from '@adonisjs/logger/types';
2
3
  import type { HttpContext } from './http_context/main.js';
3
4
  import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
@@ -13,7 +14,7 @@ import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/ser
13
14
  * - Transforming errors to JSON or HTML using content negotiation
14
15
  * - Reporting errors
15
16
  */
16
- export declare class ExceptionHandler {
17
+ export declare class ExceptionHandler extends Macroable {
17
18
  #private;
18
19
  /**
19
20
  * Whether or not to render debug info. When set to true, the errors
@@ -53,54 +54,54 @@ export declare class ExceptionHandler {
53
54
  * Error reporting context
54
55
  */
55
56
  protected context(ctx: HttpContext): any;
57
+ /**
58
+ * Returns the log level for an error based upon the error
59
+ * status code.
60
+ */
61
+ protected getErrorLogLevel(error: HttpError): Level;
62
+ /**
63
+ * A boolean to control if errors should be rendered with
64
+ * all the available debugging info.
65
+ */
66
+ protected isDebuggingEnabled(_: HttpContext): boolean;
67
+ /**
68
+ * Returns a boolean by checking if an error should be reported.
69
+ */
70
+ protected shouldReport(error: HttpError): boolean;
56
71
  /**
57
72
  * Renders an error to JSON response
58
73
  */
59
- protected renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
74
+ renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
60
75
  /**
61
76
  * Renders an error to JSON API response
62
77
  */
63
- protected renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
78
+ renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
64
79
  /**
65
80
  * Renders an error to HTML response
66
81
  */
67
- protected renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
82
+ renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
68
83
  /**
69
84
  * Renders the validation error message to a JSON
70
85
  * response
71
86
  */
72
- protected renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
87
+ renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
73
88
  /**
74
89
  * Renders the validation error message as per JSON API
75
90
  * spec
76
91
  */
77
- protected renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
92
+ renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
78
93
  /**
79
94
  * Renders the validation error as an HTML string
80
95
  */
81
- protected renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
96
+ renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
82
97
  /**
83
98
  * Renders the error to response
84
99
  */
85
- protected renderError(error: HttpError, ctx: HttpContext): Promise<void>;
100
+ renderError(error: HttpError, ctx: HttpContext): Promise<void>;
86
101
  /**
87
102
  * Renders the validation error to response
88
103
  */
89
- protected renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
90
- /**
91
- * Returns the log level for an error based upon the error
92
- * status code.
93
- */
94
- protected getErrorLogLevel(error: HttpError): Level;
95
- /**
96
- * A boolean to control if errors should be rendered with
97
- * all the available debugging info.
98
- */
99
- protected isDebuggingEnabled(_: HttpContext): boolean;
100
- /**
101
- * Returns a boolean by checking if an error should be reported.
102
- */
103
- protected shouldReport(error: HttpError): boolean;
104
+ renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
104
105
  /**
105
106
  * Reports an error during an HTTP request
106
107
  */
@@ -7,6 +7,7 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import is from '@sindresorhus/is';
10
+ import Macroable from '@poppinss/macroable';
10
11
  import { parseRange } from './helpers.js';
11
12
  import * as errors from './exceptions.js';
12
13
  /**
@@ -21,7 +22,7 @@ import * as errors from './exceptions.js';
21
22
  * - Transforming errors to JSON or HTML using content negotiation
22
23
  * - Reporting errors
23
24
  */
24
- export class ExceptionHandler {
25
+ export class ExceptionHandler extends Macroable {
25
26
  /**
26
27
  * Computed from the status pages property
27
28
  */
@@ -99,6 +100,44 @@ export class ExceptionHandler {
99
100
  }
100
101
  : {};
101
102
  }
103
+ /**
104
+ * Returns the log level for an error based upon the error
105
+ * status code.
106
+ */
107
+ getErrorLogLevel(error) {
108
+ if (error.status >= 500) {
109
+ return 'error';
110
+ }
111
+ if (error.status >= 400) {
112
+ return 'warn';
113
+ }
114
+ return 'info';
115
+ }
116
+ /**
117
+ * A boolean to control if errors should be rendered with
118
+ * all the available debugging info.
119
+ */
120
+ isDebuggingEnabled(_) {
121
+ return this.debug;
122
+ }
123
+ /**
124
+ * Returns a boolean by checking if an error should be reported.
125
+ */
126
+ shouldReport(error) {
127
+ if (this.reportErrors === false) {
128
+ return false;
129
+ }
130
+ if (this.ignoreStatuses.includes(error.status)) {
131
+ return false;
132
+ }
133
+ if (error.code && this.ignoreCodes.includes(error.code)) {
134
+ return false;
135
+ }
136
+ if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
137
+ return false;
138
+ }
139
+ return true;
140
+ }
102
141
  /**
103
142
  * Renders an error to JSON response
104
143
  */
@@ -211,44 +250,6 @@ export class ExceptionHandler {
211
250
  return this.renderValidationErrorAsHTML(error, ctx);
212
251
  }
213
252
  }
214
- /**
215
- * Returns the log level for an error based upon the error
216
- * status code.
217
- */
218
- getErrorLogLevel(error) {
219
- if (error.status >= 500) {
220
- return 'error';
221
- }
222
- if (error.status >= 400) {
223
- return 'warn';
224
- }
225
- return 'info';
226
- }
227
- /**
228
- * A boolean to control if errors should be rendered with
229
- * all the available debugging info.
230
- */
231
- isDebuggingEnabled(_) {
232
- return this.debug;
233
- }
234
- /**
235
- * Returns a boolean by checking if an error should be reported.
236
- */
237
- shouldReport(error) {
238
- if (this.reportErrors === false) {
239
- return false;
240
- }
241
- if (this.ignoreStatuses.includes(error.status)) {
242
- return false;
243
- }
244
- if (error.code && this.ignoreCodes.includes(error.code)) {
245
- return false;
246
- }
247
- if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
248
- return false;
249
- }
250
- return true;
251
- }
252
253
  /**
253
254
  * Reports an error during an HTTP request
254
255
  */
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
3
4
  import Macroable from '@poppinss/macroable';
4
5
  import type { Encryption } from '@adonisjs/encryption';
5
6
  import { ServerResponse, IncomingMessage } from 'node:http';
@@ -44,7 +45,7 @@ export declare class Response extends Macroable {
44
45
  * Returns reference to the stream set using "response.stream"
45
46
  * method
46
47
  */
47
- get outgoingStream(): ResponseStream | undefined;
48
+ get outgoingStream(): import("stream").Readable | undefined;
48
49
  /**
49
50
  * Returns reference to the file path set using "response.stream"
50
51
  * method.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
2
+ import { Readable } from 'node:stream';
3
3
  /**
4
4
  * Cookie options can that can be set on the response
5
5
  */
@@ -42,4 +42,4 @@ export type ResponseConfig = {
42
42
  /**
43
43
  * Stream that can be piped to the "response.stream" method
44
44
  */
45
- export type ResponseStream = NodeJS.ReadStream | NodeJS.ReadWriteStream | NodeJS.ReadableStream;
45
+ export type ResponseStream = Readable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "6.8.2-10",
3
+ "version": "6.8.2-12",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -43,12 +43,12 @@
43
43
  "author": "virk,adonisjs",
44
44
  "license": "MIT",
45
45
  "devDependencies": {
46
- "@adonisjs/application": "^7.1.2-8",
46
+ "@adonisjs/application": "^7.1.2-9",
47
47
  "@adonisjs/encryption": "^5.1.2-2",
48
48
  "@adonisjs/eslint-config": "^1.1.8",
49
- "@adonisjs/events": "^8.4.9-3",
50
- "@adonisjs/fold": "^9.9.3-6",
51
- "@adonisjs/logger": "^5.4.2-3",
49
+ "@adonisjs/events": "^8.4.9-4",
50
+ "@adonisjs/fold": "^9.9.3-7",
51
+ "@adonisjs/logger": "^5.4.2-4",
52
52
  "@adonisjs/prettier-config": "^1.1.8",
53
53
  "@adonisjs/tsconfig": "^1.1.8",
54
54
  "@commitlint/cli": "^17.6.7",
@@ -58,7 +58,7 @@
58
58
  "@japa/assert": "^2.0.0-1",
59
59
  "@japa/expect-type": "^2.0.0-0",
60
60
  "@japa/runner": "^3.0.0-5",
61
- "@swc/core": "^1.3.70",
61
+ "@swc/core": "^1.3.72",
62
62
  "@types/accepts": "^1.3.5",
63
63
  "@types/content-disposition": "^0.5.5",
64
64
  "@types/cookie": "^0.5.1",
@@ -69,7 +69,7 @@
69
69
  "@types/fs-extra": "^11.0.1",
70
70
  "@types/http-status-codes": "^1.2.0",
71
71
  "@types/mime-types": "^2.1.1",
72
- "@types/node": "^20.4.3",
72
+ "@types/node": "^20.4.5",
73
73
  "@types/on-finished": "^2.3.1",
74
74
  "@types/pem": "^1.14.0",
75
75
  "@types/proxy-addr": "^2.0.0",
@@ -77,13 +77,13 @@
77
77
  "@types/supertest": "^2.0.12",
78
78
  "@types/type-is": "^1.6.3",
79
79
  "@types/vary": "^1.1.0",
80
- "@vinejs/vine": "^1.5.2",
80
+ "@vinejs/vine": "^1.6.0",
81
81
  "autocannon": "^7.11.0",
82
- "c8": "^8.0.0",
82
+ "c8": "^8.0.1",
83
83
  "cross-env": "^7.0.3",
84
84
  "del-cli": "^5.0.0",
85
- "eslint": "^8.45.0",
86
- "fastify": "^4.20.0",
85
+ "eslint": "^8.46.0",
86
+ "fastify": "^4.21.0",
87
87
  "fs-extra": "^11.1.1",
88
88
  "get-port": "^7.0.0",
89
89
  "github-label-sync": "^2.3.1",
@@ -103,7 +103,7 @@
103
103
  "@poppinss/matchit": "^3.1.2",
104
104
  "@poppinss/middleware": "^3.1.3",
105
105
  "@poppinss/utils": "^6.5.0-3",
106
- "@sindresorhus/is": "^5.5.2",
106
+ "@sindresorhus/is": "^5.6.0",
107
107
  "accepts": "^1.3.8",
108
108
  "content-disposition": "^0.5.4",
109
109
  "cookie": "^0.5.0",
@@ -121,11 +121,11 @@
121
121
  "youch": "^3.2.3"
122
122
  },
123
123
  "peerDependencies": {
124
- "@adonisjs/application": "^7.1.2-3",
125
- "@adonisjs/encryption": "^5.1.2-1",
126
- "@adonisjs/events": "^8.4.9-2",
127
- "@adonisjs/fold": "^9.9.3-4",
128
- "@adonisjs/logger": "^5.4.2-1"
124
+ "@adonisjs/application": "^7.1.2-9",
125
+ "@adonisjs/encryption": "^5.1.2-2",
126
+ "@adonisjs/events": "^8.4.9-4",
127
+ "@adonisjs/fold": "^9.9.3-7",
128
+ "@adonisjs/logger": "^5.4.2-4"
129
129
  },
130
130
  "repository": {
131
131
  "type": "git",