@adonisjs/http-server 7.0.0-0 → 7.0.0-2

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 (62) hide show
  1. package/build/{chunk-XX72ATFY.js → chunk-Z63E3STR.js} +66 -18
  2. package/build/chunk-Z63E3STR.js.map +1 -0
  3. package/build/factories/http_context.d.ts +25 -0
  4. package/build/factories/http_server.d.ts +8 -0
  5. package/build/factories/main.d.ts +6 -149
  6. package/build/factories/main.js +2 -1
  7. package/build/factories/main.js.map +1 -0
  8. package/build/factories/qs_parser_factory.d.ts +20 -0
  9. package/build/factories/request.d.ts +29 -0
  10. package/build/factories/response.d.ts +29 -0
  11. package/build/factories/router.d.ts +23 -0
  12. package/build/factories/server_factory.d.ts +29 -0
  13. package/build/index.d.ts +14 -272
  14. package/build/index.js +2 -1
  15. package/build/index.js.map +1 -0
  16. package/build/src/cookies/client.d.ts +37 -0
  17. package/build/src/cookies/drivers/encrypted.d.ts +16 -0
  18. package/build/src/cookies/drivers/plain.d.ts +15 -0
  19. package/build/src/cookies/drivers/signed.d.ts +16 -0
  20. package/build/src/cookies/parser.d.ts +37 -0
  21. package/build/src/cookies/serializer.d.ts +33 -0
  22. package/build/src/debug.d.ts +3 -0
  23. package/build/src/define_config.d.ts +9 -0
  24. package/build/src/define_middleware.d.ts +11 -0
  25. package/build/src/exception_handler.d.ts +113 -0
  26. package/build/src/exceptions.d.ts +84 -0
  27. package/build/src/helpers.d.ts +23 -0
  28. package/build/src/http_context/local_storage.d.ts +12 -0
  29. package/build/src/http_context/main.d.ts +58 -0
  30. package/build/src/qs.d.ts +11 -0
  31. package/build/src/redirect.d.ts +42 -0
  32. package/build/src/request.d.ts +565 -0
  33. package/build/src/response.d.ts +620 -0
  34. package/build/src/router/brisk.d.ts +42 -0
  35. package/build/src/router/executor.d.ts +9 -0
  36. package/build/src/router/factories/use_return_value.d.ts +6 -0
  37. package/build/src/router/group.d.ts +65 -0
  38. package/build/src/router/lookup_store/main.d.ts +47 -0
  39. package/build/src/router/lookup_store/route_finder.d.ts +25 -0
  40. package/build/src/router/lookup_store/url_builder.d.ts +52 -0
  41. package/build/src/router/main.d.ts +128 -0
  42. package/build/src/router/matchers.d.ts +27 -0
  43. package/build/src/router/parser.d.ts +5 -0
  44. package/build/src/router/resource.d.ts +66 -0
  45. package/build/src/router/route.d.ts +92 -0
  46. package/build/src/router/store.d.ts +66 -0
  47. package/build/src/server/factories/final_handler.d.ts +10 -0
  48. package/build/src/server/factories/middleware_handler.d.ts +8 -0
  49. package/build/src/server/factories/write_response.d.ts +6 -0
  50. package/build/{main-29eaaee4.d.ts → src/server/main.d.ts} +18 -13
  51. package/build/src/types/base.d.ts +19 -0
  52. package/build/src/types/main.d.ts +7 -14
  53. package/build/src/types/main.js +1 -0
  54. package/build/src/types/main.js.map +1 -0
  55. package/build/src/types/middleware.d.ts +35 -0
  56. package/build/src/types/qs.d.ts +68 -0
  57. package/build/src/types/request.d.ts +39 -0
  58. package/build/src/types/response.d.ts +45 -0
  59. package/build/src/types/route.d.ts +166 -0
  60. package/build/src/types/server.d.ts +72 -0
  61. package/package.json +52 -48
  62. package/build/main-e5b46c83.d.ts +0 -2210
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exception_handler.ts"],"sourcesContent":["/*\n * @adonisjs/http-server\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport is from '@sindresorhus/is'\nimport Macroable from '@poppinss/macroable'\nimport type { Level } from '@adonisjs/logger/types'\n\nimport { parseRange } from './helpers.js'\nimport * as errors from './exceptions.js'\nimport type { HttpContext } from './http_context/main.js'\nimport type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js'\n\n/**\n * The base HTTP exception handler one can inherit from to handle\n * HTTP exceptions.\n *\n * The HTTP exception handler has support for\n *\n * - Ability to render exceptions by calling the render method on the exception.\n * - Rendering status pages\n * - Pretty printing errors during development\n * - Transforming errors to JSON or HTML using content negotiation\n * - Reporting errors\n */\nexport class ExceptionHandler extends Macroable {\n /**\n * Computed from the status pages property\n */\n #expandedStatusPages?: Record<number, StatusPageRenderer>\n\n /**\n * Whether or not to render debug info. When set to true, the errors\n * will have the complete error stack.\n */\n protected debug: boolean = process.env.NODE_ENV !== 'production'\n\n /**\n * Whether or not to render status pages. When set to true, the unhandled\n * errors with matching status codes will be rendered using a status\n * page.\n */\n protected renderStatusPages: boolean = process.env.NODE_ENV === 'production'\n\n /**\n * A collection of error status code range and the view to render.\n */\n protected statusPages: Record<StatusPageRange, StatusPageRenderer> = {}\n\n /**\n * Enable/disable errors reporting\n */\n protected reportErrors: boolean = true\n\n /**\n * An array of exception classes to ignore when\n * reporting an error\n */\n protected ignoreExceptions: any[] = [\n errors.E_HTTP_EXCEPTION,\n errors.E_ROUTE_NOT_FOUND,\n errors.E_CANNOT_LOOKUP_ROUTE,\n errors.E_HTTP_REQUEST_ABORTED,\n ]\n\n /**\n * An array of HTTP status codes to ignore when reporting\n * an error\n */\n protected ignoreStatuses: number[] = [400, 422, 401]\n\n /**\n * An array of error codes to ignore when reporting\n * an error\n */\n protected ignoreCodes: string[] = []\n\n /**\n * Expands status pages\n */\n #expandStatusPages() {\n if (!this.#expandedStatusPages) {\n this.#expandedStatusPages = Object.keys(this.statusPages).reduce(\n (result, range) => {\n const renderer = this.statusPages[range as StatusPageRange]\n result = Object.assign(result, parseRange(range, renderer))\n return result\n },\n {} as Record<number, StatusPageRenderer>\n )\n }\n\n return this.#expandedStatusPages\n }\n\n /**\n * Forcefully tweaking the type of the error object to\n * have known properties.\n */\n #toHttpError(error: unknown): HttpError {\n const httpError: any = is.object(error) ? error : new Error(String(error))\n httpError.message = httpError.message || 'Internal server error'\n httpError.status = httpError.status || 500\n return httpError\n }\n\n /**\n * Error reporting context\n */\n protected context(ctx: HttpContext): any {\n const requestId = ctx.request.id()\n return requestId\n ? {\n 'x-request-id': requestId,\n }\n : {}\n }\n\n /**\n * Returns the log level for an error based upon the error\n * status code.\n */\n protected getErrorLogLevel(error: HttpError): Level {\n if (error.status >= 500) {\n return 'error'\n }\n\n if (error.status >= 400) {\n return 'warn'\n }\n\n return 'info'\n }\n\n /**\n * A boolean to control if errors should be rendered with\n * all the available debugging info.\n */\n protected isDebuggingEnabled(_: HttpContext): boolean {\n return this.debug\n }\n\n /**\n * Returns a boolean by checking if an error should be reported.\n */\n protected shouldReport(error: HttpError): boolean {\n if (this.reportErrors === false) {\n return false\n }\n\n if (this.ignoreStatuses.includes(error.status)) {\n return false\n }\n\n if (error.code && this.ignoreCodes.includes(error.code)) {\n return false\n }\n\n if (this.ignoreExceptions.find((exception) => error instanceof exception)) {\n return false\n }\n\n return true\n }\n\n /**\n * Renders an error to JSON response\n */\n async renderErrorAsJSON(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const json = await new Youch(error, ctx.request.request).toJSON()\n ctx.response.status(error.status).send(json.error)\n return\n }\n\n ctx.response.status(error.status).send({ message: error.message })\n }\n\n /**\n * Renders an error to JSON API response\n */\n async renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const json = await new Youch(error, ctx.request.request).toJSON()\n ctx.response.status(error.status).send(json.error)\n return\n }\n\n ctx.response.status(error.status).send({\n errors: [\n {\n title: error.message,\n code: error.code,\n status: error.status,\n },\n ],\n })\n }\n\n /**\n * Renders an error to HTML response\n */\n async renderErrorAsHTML(error: HttpError, ctx: HttpContext) {\n if (this.isDebuggingEnabled(ctx)) {\n const { default: Youch } = await import('youch')\n const html = await new Youch(error, ctx.request.request).toHTML({\n cspNonce: 'nonce' in ctx.response ? ctx.response.nonce : undefined,\n })\n ctx.response.status(error.status).send(html)\n return\n }\n\n ctx.response.status(error.status).send(`<p> ${error.message} </p>`)\n }\n\n /**\n * Renders the validation error message to a JSON\n * response\n */\n async renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext) {\n ctx.response.status(error.status).send({\n errors: error.messages,\n })\n }\n\n /**\n * Renders the validation error message as per JSON API\n * spec\n */\n async renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext) {\n ctx.response.status(error.status).send({\n errors: error.messages.map((message: any) => {\n return {\n title: message.message,\n code: message.rule,\n source: {\n pointer: message.field,\n },\n meta: message.meta,\n }\n }),\n })\n }\n\n /**\n * Renders the validation error as an HTML string\n */\n async renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext) {\n ctx.response\n .status(error.status)\n .type('html')\n .send(\n error.messages\n .map((message: any) => {\n return `${message.field} - ${message.message}`\n })\n .join('<br />')\n )\n }\n\n /**\n * Renders the error to response\n */\n renderError(error: HttpError, ctx: HttpContext) {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'application/vnd.api+json':\n return this.renderErrorAsJSONAPI(error, ctx)\n case 'json':\n return this.renderErrorAsJSON(error, ctx)\n case 'html':\n default:\n return this.renderErrorAsHTML(error, ctx)\n }\n }\n\n /**\n * Renders the validation error to response\n */\n renderValidationError(error: HttpError, ctx: HttpContext) {\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'application/vnd.api+json':\n return this.renderValidationErrorAsJSONAPI(error, ctx)\n case 'json':\n return this.renderValidationErrorAsJSON(error, ctx)\n case 'html':\n default:\n return this.renderValidationErrorAsHTML(error, ctx)\n }\n }\n\n /**\n * Reports an error during an HTTP request\n */\n async report(error: unknown, ctx: HttpContext) {\n const httpError = this.#toHttpError(error)\n if (!this.shouldReport(httpError)) {\n return\n }\n\n if (typeof httpError.report === 'function') {\n httpError.report(httpError, ctx)\n return\n }\n\n /**\n * Log the error using the logger\n */\n const level = this.getErrorLogLevel(httpError)\n ctx.logger.log(\n level,\n {\n ...(level === 'error' || level === 'fatal' ? { err: httpError } : {}),\n ...this.context(ctx),\n },\n httpError.message\n )\n }\n\n /**\n * Handles the error during the HTTP request.\n */\n async handle(error: unknown, ctx: HttpContext) {\n const httpError = this.#toHttpError(error)\n\n /**\n * Self handle exception\n */\n if (typeof httpError.handle === 'function') {\n return httpError.handle(httpError, ctx)\n }\n\n /**\n * Handle validation error using the validation error\n * renderers\n */\n if (httpError.code === 'E_VALIDATION_ERROR' && 'messages' in httpError) {\n return this.renderValidationError(httpError, ctx)\n }\n\n /**\n * Render status page\n */\n const statusPages = this.#expandStatusPages()\n if (this.renderStatusPages && statusPages[httpError.status]) {\n return statusPages[httpError.status](httpError, ctx)\n }\n\n /**\n * Use the format renderers.\n */\n return this.renderError(httpError, ctx)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASA,OAAO,QAAQ;AACf,OAAO,eAAe;AAoBf,IAAM,mBAAN,cAA+B,UAAU;AAAA;AAAA;AAAA;AAAA,EAI9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,QAAiB,QAAQ,IAAI,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO1C,oBAA6B,QAAQ,IAAI,aAAa;AAAA;AAAA;AAAA;AAAA,EAKtD,cAA2D,CAAC;AAAA;AAAA;AAAA;AAAA,EAK5D,eAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,mBAA0B;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,iBAA2B,CAAC,KAAK,KAAK,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzC,cAAwB,CAAC;AAAA;AAAA;AAAA;AAAA,EAKnC,qBAAqB;AACnB,QAAI,CAAC,KAAK,sBAAsB;AAC9B,WAAK,uBAAuB,OAAO,KAAK,KAAK,WAAW,EAAE;AAAA,QACxD,CAAC,QAAQ,UAAU;AACjB,gBAAM,WAAW,KAAK,YAAY,KAAwB;AAC1D,mBAAS,OAAO,OAAO,QAAQ,WAAW,OAAO,QAAQ,CAAC;AAC1D,iBAAO;AAAA,QACT;A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+ * as a client.
5
+ */
6
+ export declare class CookieClient {
7
+ #private;
8
+ constructor(encryption: Encryption);
9
+ /**
10
+ * Encrypt a key value pair to be sent in the cookie header
11
+ */
12
+ encrypt(key: string, value: any): string | null;
13
+ /**
14
+ * Sign a key value pair to be sent in the cookie header
15
+ */
16
+ sign(key: string, value: any): string | null;
17
+ /**
18
+ * Encode a key value pair to be sent in the cookie header
19
+ */
20
+ encode(_: string, value: any): string | null;
21
+ /**
22
+ * Unsign a signed cookie value
23
+ */
24
+ unsign(key: string, value: string): any;
25
+ /**
26
+ * Decrypt an encrypted cookie value
27
+ */
28
+ decrypt(key: string, value: string): any;
29
+ /**
30
+ * Decode an encoded cookie value
31
+ */
32
+ decode(_: string, value: string): any;
33
+ /**
34
+ * Parse response cookie
35
+ */
36
+ parse(key: string, value: any): any;
37
+ }
@@ -0,0 +1,16 @@
1
+ import type { Encryption } from '@adonisjs/encryption';
2
+ /**
3
+ * Encrypt a value to be set as cookie
4
+ */
5
+ export declare function pack(key: string, value: any, encryption: Encryption): null | string;
6
+ /**
7
+ * Returns a boolean, if the unpack method from this module can attempt
8
+ * to unpack encrypted value.
9
+ */
10
+ export declare function canUnpack(encryptedValue: string): boolean;
11
+ /**
12
+ * Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
13
+ * Only call this method, when `canUnpack` returns true, otherwise runtime
14
+ * exceptions can be raised.
15
+ */
16
+ export declare function unpack(key: string, encryptedValue: string, encryption: Encryption): null | any;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Encodes a value into a base64 url encoded string to
3
+ * be set as cookie
4
+ */
5
+ export declare function pack(value: any): null | string;
6
+ /**
7
+ * Returns true when this `unpack` method of this module can attempt
8
+ * to unpack the encode value.
9
+ */
10
+ export declare function canUnpack(encodedValue: string): boolean;
11
+ /**
12
+ * Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
13
+ * before calling this method
14
+ */
15
+ export declare function unpack(encodedValue: string): null | any;
@@ -0,0 +1,16 @@
1
+ import type { Encryption } from '@adonisjs/encryption';
2
+ /**
3
+ * Signs a value to be shared as a cookie. The signed output has a
4
+ * hash to verify tampering with the original value
5
+ */
6
+ export declare function pack(key: string, value: any, encryption: Encryption): null | string;
7
+ /**
8
+ * Returns a boolean, if the unpack method from this module can attempt
9
+ * to unpack the signed value.
10
+ */
11
+ export declare function canUnpack(signedValue: string): boolean;
12
+ /**
13
+ * Attempts to unpack the signed value. Make sure to call `canUnpack` before
14
+ * calling this method.
15
+ */
16
+ export declare function unpack(key: string, signedValue: string, encryption: Encryption): null | any;
@@ -0,0 +1,37 @@
1
+ import type { Encryption } from '@adonisjs/encryption';
2
+ /**
3
+ * Cookie parser parses the HTTP `cookie` header and collects all cookies
4
+ * inside an object of `key-value` pair, but doesn't attempt to decrypt
5
+ * or unsign or decode the individual values.
6
+ *
7
+ * The cookie values are lazily decrypted, or unsigned to avoid unncessary
8
+ * processing, which infact can be used as a means to burden the server
9
+ * by sending too many cookies which even doesn't belongs to the
10
+ * server.
11
+ */
12
+ export declare class CookieParser {
13
+ #private;
14
+ constructor(cookieHeader: string, encryption: Encryption);
15
+ /**
16
+ * Attempts to decode a cookie by the name. When calling this method,
17
+ * you are assuming that the cookie was just encoded in the first
18
+ * place and not signed or encrypted.
19
+ */
20
+ decode(key: string, encoded?: boolean): any | null;
21
+ /**
22
+ * Attempts to unsign a cookie by the name. When calling this method,
23
+ * you are assuming that the cookie was signed in the first place.
24
+ */
25
+ unsign(key: string): null | any;
26
+ /**
27
+ * Attempts to decrypt a cookie by the name. When calling this method,
28
+ * you are assuming that the cookie was encrypted in the first place.
29
+ */
30
+ decrypt(key: string): null | any;
31
+ /**
32
+ * Returns an object of cookies key-value pair. Do note, the
33
+ * cookies are not decoded, unsigned or decrypted inside this
34
+ * list.
35
+ */
36
+ list(): Record<string, any>;
37
+ }
@@ -0,0 +1,33 @@
1
+ import type { Encryption } from '@adonisjs/encryption';
2
+ import type { CookieOptions } from '../types/response.js';
3
+ /**
4
+ * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
5
+ * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
6
+ * and then set them individually using the `set-cookie` header.
7
+ */
8
+ export declare class CookieSerializer {
9
+ #private;
10
+ constructor(encryption: Encryption);
11
+ /**
12
+ * Encodes value as a plain cookie. By default, the plain value will be converted
13
+ * to a string using "JSON.stringify" method and then encoded as a base64 string.
14
+ *
15
+ * You can disable encoding of the cookie by setting `options.encoded = false`.
16
+ *
17
+ * ```ts
18
+ * serializer.encode('name', 'virk')
19
+ * ```
20
+ */
21
+ encode(key: string, value: any, options?: Partial<CookieOptions & {
22
+ encode: boolean;
23
+ }>): string | null;
24
+ /**
25
+ * Sign a key-value pair to a signed cookie. The signed value has a
26
+ * verification hash attached to it to detect data tampering.
27
+ */
28
+ sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
29
+ /**
30
+ * Encrypts a key-value pair to an encrypted cookie.
31
+ */
32
+ encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
33
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ declare const _default: import("util").DebugLogger;
3
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import type { ServerConfig } from './types/server.js';
2
+ type UserDefinedServerConfig = Partial<Omit<ServerConfig, 'trustProxy'> & {
3
+ trustProxy: ((address: string, distance: number) => boolean) | boolean | string;
4
+ }>;
5
+ /**
6
+ * Define configuration for the HTTP server
7
+ */
8
+ export declare function defineConfig(config: UserDefinedServerConfig): ServerConfig;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { LazyImport, UnWrapLazyImport } from './types/base.js';
2
+ import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } from './types/middleware.js';
3
+ /**
4
+ * Define an collection of named middleware. The collection gets converted
5
+ * into a collection of factory functions. Calling the function returns
6
+ * a reference to the executable middleware.
7
+ */
8
+ export declare function defineNamedMiddleware<NamedMiddleware extends Record<string | number | symbol, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
9
+ name: K;
10
+ args: Args[0];
11
+ } & ParsedGlobalMiddleware; };
@@ -0,0 +1,113 @@
1
+ import Macroable from '@poppinss/macroable';
2
+ import type { Level } from '@adonisjs/logger/types';
3
+ import type { HttpContext } from './http_context/main.js';
4
+ import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
5
+ /**
6
+ * The base HTTP exception handler one can inherit from to handle
7
+ * HTTP exceptions.
8
+ *
9
+ * The HTTP exception handler has support for
10
+ *
11
+ * - Ability to render exceptions by calling the render method on the exception.
12
+ * - Rendering status pages
13
+ * - Pretty printing errors during development
14
+ * - Transforming errors to JSON or HTML using content negotiation
15
+ * - Reporting errors
16
+ */
17
+ export declare class ExceptionHandler extends Macroable {
18
+ #private;
19
+ /**
20
+ * Whether or not to render debug info. When set to true, the errors
21
+ * will have the complete error stack.
22
+ */
23
+ protected debug: boolean;
24
+ /**
25
+ * Whether or not to render status pages. When set to true, the unhandled
26
+ * errors with matching status codes will be rendered using a status
27
+ * page.
28
+ */
29
+ protected renderStatusPages: boolean;
30
+ /**
31
+ * A collection of error status code range and the view to render.
32
+ */
33
+ protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
34
+ /**
35
+ * Enable/disable errors reporting
36
+ */
37
+ protected reportErrors: boolean;
38
+ /**
39
+ * An array of exception classes to ignore when
40
+ * reporting an error
41
+ */
42
+ protected ignoreExceptions: any[];
43
+ /**
44
+ * An array of HTTP status codes to ignore when reporting
45
+ * an error
46
+ */
47
+ protected ignoreStatuses: number[];
48
+ /**
49
+ * An array of error codes to ignore when reporting
50
+ * an error
51
+ */
52
+ protected ignoreCodes: string[];
53
+ /**
54
+ * Error reporting context
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;
71
+ /**
72
+ * Renders an error to JSON response
73
+ */
74
+ renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
75
+ /**
76
+ * Renders an error to JSON API response
77
+ */
78
+ renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
79
+ /**
80
+ * Renders an error to HTML response
81
+ */
82
+ renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
83
+ /**
84
+ * Renders the validation error message to a JSON
85
+ * response
86
+ */
87
+ renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
88
+ /**
89
+ * Renders the validation error message as per JSON API
90
+ * spec
91
+ */
92
+ renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
93
+ /**
94
+ * Renders the validation error as an HTML string
95
+ */
96
+ renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
97
+ /**
98
+ * Renders the error to response
99
+ */
100
+ renderError(error: HttpError, ctx: HttpContext): Promise<void>;
101
+ /**
102
+ * Renders the validation error to response
103
+ */
104
+ renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
105
+ /**
106
+ * Reports an error during an HTTP request
107
+ */
108
+ report(error: unknown, ctx: HttpContext): Promise<void>;
109
+ /**
110
+ * Handles the error during the HTTP request.
111
+ */
112
+ handle(error: unknown, ctx: HttpContext): Promise<any>;
113
+ }
@@ -0,0 +1,84 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { Exception } from '@poppinss/utils';
3
+ import type { HttpContext } from './http_context/main.js';
4
+ export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions | undefined) => Exception;
5
+ export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions | undefined) => Exception;
6
+ export declare const E_HTTP_EXCEPTION: {
7
+ new (message?: string | undefined, options?: (ErrorOptions & {
8
+ code?: string | undefined;
9
+ status?: number | undefined;
10
+ }) | undefined): {
11
+ body: any;
12
+ name: string;
13
+ help?: string | undefined;
14
+ code?: string | undefined;
15
+ status: number;
16
+ toString(): string;
17
+ readonly [Symbol.toStringTag]: string;
18
+ message: string;
19
+ stack?: string | undefined;
20
+ cause?: unknown;
21
+ };
22
+ code: string;
23
+ /**
24
+ * This method returns an instance of the exception class
25
+ */
26
+ invoke(body: any, status: number, code?: string): {
27
+ body: any;
28
+ name: string;
29
+ help?: string | undefined;
30
+ code?: string | undefined;
31
+ status: number;
32
+ toString(): string;
33
+ readonly [Symbol.toStringTag]: string;
34
+ message: string;
35
+ stack?: string | undefined;
36
+ cause?: unknown;
37
+ };
38
+ help?: string | undefined;
39
+ status?: number | undefined;
40
+ message?: string | undefined;
41
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
42
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
43
+ stackTraceLimit: number;
44
+ };
45
+ export declare const E_HTTP_REQUEST_ABORTED: {
46
+ new (message?: string | undefined, options?: (ErrorOptions & {
47
+ code?: string | undefined;
48
+ status?: number | undefined;
49
+ }) | undefined): {
50
+ handle(error: any, ctx: HttpContext): void;
51
+ body: any;
52
+ name: string;
53
+ help?: string | undefined;
54
+ code?: string | undefined;
55
+ status: number;
56
+ toString(): string;
57
+ readonly [Symbol.toStringTag]: string;
58
+ message: string;
59
+ stack?: string | undefined;
60
+ cause?: unknown;
61
+ };
62
+ code: string;
63
+ /**
64
+ * This method returns an instance of the exception class
65
+ */
66
+ invoke(body: any, status: number, code?: string): {
67
+ body: any;
68
+ name: string;
69
+ help?: string | undefined;
70
+ code?: string | undefined;
71
+ status: number;
72
+ toString(): string;
73
+ readonly [Symbol.toStringTag]: string;
74
+ message: string;
75
+ stack?: string | undefined;
76
+ cause?: unknown;
77
+ };
78
+ help?: string | undefined;
79
+ status?: number | undefined;
80
+ message?: string | undefined;
81
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
82
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
83
+ stackTraceLimit: number;
84
+ };
@@ -0,0 +1,23 @@
1
+ import { Route } from './router/route.js';
2
+ import { BriskRoute } from './router/brisk.js';
3
+ import { RouteGroup } from './router/group.js';
4
+ import type { RouteJSON } from './types/route.js';
5
+ import { RouteResource } from './router/resource.js';
6
+ /**
7
+ * Makes input string consistent by having only the starting
8
+ * slash
9
+ */
10
+ export declare function dropSlash(input: string): string;
11
+ /**
12
+ * Returns a flat list of routes from the route groups and resources
13
+ */
14
+ export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
15
+ /**
16
+ * Helper to know if the remote address should
17
+ * be trusted.
18
+ */
19
+ export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
20
+ /**
21
+ * Parses a range expression to an object filled with the range
22
+ */
23
+ export declare function parseRange<T>(range: string, value: T): Record<number, T>;
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import type { HttpContext } from './main.js';
4
+ /**
5
+ * Async local storage for HTTP context
6
+ */
7
+ export declare const asyncLocalStorage: {
8
+ isEnabled: boolean;
9
+ storage: null | AsyncLocalStorage<HttpContext>;
10
+ create(): AsyncLocalStorage<HttpContext>;
11
+ destroy(): void;
12
+ };
@@ -0,0 +1,58 @@
1
+ import Macroable from '@poppinss/macroable';
2
+ import type { Logger } from '@adonisjs/logger';
3
+ import { ContainerResolver } from '@adonisjs/fold';
4
+ import type { Request } from '../request.js';
5
+ import type { Response } from '../response.js';
6
+ import type { StoreRouteNode } from '../types/route.js';
7
+ /**
8
+ * Http context encapsulates properties for a given HTTP request. The
9
+ * context class can be extended using macros and getters.
10
+ */
11
+ export declare class HttpContext extends Macroable {
12
+ request: Request;
13
+ response: Response;
14
+ logger: Logger;
15
+ containerResolver: ContainerResolver<any>;
16
+ /**
17
+ * Find if async localstorage is enabled for HTTP requests
18
+ * or not
19
+ */
20
+ static get usingAsyncLocalStorage(): boolean;
21
+ /**
22
+ * Get access to the HTTP context. Available only when
23
+ * "usingAsyncLocalStorage" is true
24
+ */
25
+ static get(): HttpContext | null;
26
+ /**
27
+ * Get the HttpContext instance or raise an exception if not
28
+ * available
29
+ */
30
+ static getOrFail(): HttpContext;
31
+ /**
32
+ * Run a method that doesn't have access to HTTP context from
33
+ * the async local storage.
34
+ */
35
+ static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
36
+ /**
37
+ * Reference to the current route. Not available inside
38
+ * server middleware
39
+ */
40
+ route?: StoreRouteNode;
41
+ /**
42
+ * A unique key for the current route
43
+ */
44
+ routeKey?: string;
45
+ /**
46
+ * Route params
47
+ */
48
+ params: Record<string, any>;
49
+ /**
50
+ * Route subdomains
51
+ */
52
+ subdomains: Record<string, any>;
53
+ constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
54
+ /**
55
+ * A helper to see top level properties on the context object
56
+ */
57
+ inspect(): string;
58
+ }
@@ -0,0 +1,11 @@
1
+ import { QSParserConfig } from './types/qs.js';
2
+ /**
3
+ * Query string parser used to parse and stringify query
4
+ * strings.
5
+ */
6
+ export declare class Qs {
7
+ #private;
8
+ constructor(config: QSParserConfig);
9
+ parse(value: string): import("qs").ParsedQs;
10
+ stringify(value: any): string;
11
+ }
@@ -0,0 +1,42 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { IncomingMessage } from 'node:http';
3
+ import type { Qs } from './qs.js';
4
+ import type { Response } from './response.js';
5
+ import type { Router } from './router/main.js';
6
+ import type { MakeUrlOptions } from './types/route.js';
7
+ /**
8
+ * Exposes the API to construct redirect routes
9
+ */
10
+ export declare class Redirect {
11
+ #private;
12
+ constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
13
+ /**
14
+ * Set a custom status code.
15
+ */
16
+ status(statusCode: number): this;
17
+ /**
18
+ * Clearing query string values added using the
19
+ * "withQs" method
20
+ */
21
+ clearQs(): this;
22
+ /**
23
+ * Define query string for the redirect. Not passing
24
+ * any value will forward the current request query
25
+ * string.
26
+ */
27
+ withQs(): this;
28
+ withQs(values: Record<string, any>): this;
29
+ withQs(name: string, value: any): this;
30
+ /**
31
+ * Redirect to the previous path.
32
+ */
33
+ back(): void;
34
+ /**
35
+ * Redirect the request using a route identifier.
36
+ */
37
+ toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
38
+ /**
39
+ * Redirect the request using a path.
40
+ */
41
+ toPath(url: string): void;
42
+ }