@adonisjs/http-server 6.8.2-8 → 7.0.0-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 (107) hide show
  1. package/build/chunk-XX72ATFY.js +4388 -0
  2. package/build/factories/main.d.ts +149 -6
  3. package/build/factories/main.js +331 -14
  4. package/build/index.d.ts +272 -14
  5. package/build/index.js +308 -22
  6. package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
  7. package/build/main-e5b46c83.d.ts +2210 -0
  8. package/build/src/types/main.d.ts +14 -7
  9. package/build/src/types/main.js +0 -15
  10. package/package.json +65 -55
  11. package/build/factories/http_context.d.ts +0 -25
  12. package/build/factories/http_context.js +0 -51
  13. package/build/factories/http_server.d.ts +0 -8
  14. package/build/factories/http_server.js +0 -26
  15. package/build/factories/qs_parser_factory.d.ts +0 -20
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.d.ts +0 -29
  18. package/build/factories/request.js +0 -73
  19. package/build/factories/response.d.ts +0 -29
  20. package/build/factories/response.js +0 -77
  21. package/build/factories/router.d.ts +0 -23
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.d.ts +0 -29
  24. package/build/factories/server_factory.js +0 -65
  25. package/build/src/cookies/client.d.ts +0 -37
  26. package/build/src/cookies/client.js +0 -84
  27. package/build/src/cookies/drivers/encrypted.d.ts +0 -16
  28. package/build/src/cookies/drivers/encrypted.js +0 -36
  29. package/build/src/cookies/drivers/plain.d.ts +0 -15
  30. package/build/src/cookies/drivers/plain.js +0 -33
  31. package/build/src/cookies/drivers/signed.d.ts +0 -16
  32. package/build/src/cookies/drivers/signed.js +0 -36
  33. package/build/src/cookies/parser.d.ts +0 -37
  34. package/build/src/cookies/parser.js +0 -167
  35. package/build/src/cookies/serializer.d.ts +0 -33
  36. package/build/src/cookies/serializer.js +0 -79
  37. package/build/src/debug.d.ts +0 -3
  38. package/build/src/debug.js +0 -10
  39. package/build/src/define_config.d.ts +0 -5
  40. package/build/src/define_config.js +0 -51
  41. package/build/src/define_middleware.d.ts +0 -11
  42. package/build/src/define_middleware.js +0 -35
  43. package/build/src/exception_handler.d.ts +0 -90
  44. package/build/src/exception_handler.js +0 -239
  45. package/build/src/exceptions.d.ts +0 -84
  46. package/build/src/exceptions.js +0 -38
  47. package/build/src/helpers.d.ts +0 -23
  48. package/build/src/helpers.js +0 -84
  49. package/build/src/http_context/local_storage.d.ts +0 -12
  50. package/build/src/http_context/local_storage.js +0 -39
  51. package/build/src/http_context/main.d.ts +0 -58
  52. package/build/src/http_context/main.js +0 -105
  53. package/build/src/qs.d.ts +0 -11
  54. package/build/src/qs.js +0 -25
  55. package/build/src/redirect.d.ts +0 -42
  56. package/build/src/redirect.js +0 -140
  57. package/build/src/request.d.ts +0 -565
  58. package/build/src/request.js +0 -865
  59. package/build/src/response.d.ts +0 -540
  60. package/build/src/response.js +0 -1208
  61. package/build/src/router/brisk.d.ts +0 -42
  62. package/build/src/router/brisk.js +0 -85
  63. package/build/src/router/executor.d.ts +0 -8
  64. package/build/src/router/executor.js +0 -29
  65. package/build/src/router/factories/use_return_value.d.ts +0 -6
  66. package/build/src/router/factories/use_return_value.js +0 -22
  67. package/build/src/router/group.d.ts +0 -65
  68. package/build/src/router/group.js +0 -207
  69. package/build/src/router/lookup_store/main.d.ts +0 -49
  70. package/build/src/router/lookup_store/main.js +0 -86
  71. package/build/src/router/lookup_store/route_finder.d.ts +0 -21
  72. package/build/src/router/lookup_store/route_finder.js +0 -49
  73. package/build/src/router/lookup_store/url_builder.d.ts +0 -52
  74. package/build/src/router/lookup_store/url_builder.js +0 -209
  75. package/build/src/router/main.d.ts +0 -128
  76. package/build/src/router/main.js +0 -316
  77. package/build/src/router/matchers.d.ts +0 -27
  78. package/build/src/router/matchers.js +0 -36
  79. package/build/src/router/parser.d.ts +0 -5
  80. package/build/src/router/parser.js +0 -17
  81. package/build/src/router/resource.d.ts +0 -54
  82. package/build/src/router/resource.js +0 -216
  83. package/build/src/router/route.d.ts +0 -92
  84. package/build/src/router/route.js +0 -293
  85. package/build/src/router/store.d.ts +0 -66
  86. package/build/src/router/store.js +0 -195
  87. package/build/src/server/factories/final_handler.d.ts +0 -9
  88. package/build/src/server/factories/final_handler.js +0 -30
  89. package/build/src/server/factories/middleware_handler.d.ts +0 -8
  90. package/build/src/server/factories/middleware_handler.js +0 -16
  91. package/build/src/server/factories/write_response.d.ts +0 -6
  92. package/build/src/server/factories/write_response.js +0 -24
  93. package/build/src/server/main.js +0 -283
  94. package/build/src/types/base.d.ts +0 -19
  95. package/build/src/types/base.js +0 -9
  96. package/build/src/types/middleware.d.ts +0 -35
  97. package/build/src/types/middleware.js +0 -9
  98. package/build/src/types/qs.d.ts +0 -68
  99. package/build/src/types/qs.js +0 -9
  100. package/build/src/types/request.d.ts +0 -39
  101. package/build/src/types/request.js +0 -9
  102. package/build/src/types/response.d.ts +0 -45
  103. package/build/src/types/response.js +0 -9
  104. package/build/src/types/route.d.ts +0 -165
  105. package/build/src/types/route.js +0 -9
  106. package/build/src/types/server.d.ts +0 -72
  107. package/build/src/types/server.js +0 -9
@@ -1,84 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import Cache from 'tmp-cache';
10
- import { InvalidArgumentsException } from '@poppinss/utils';
11
- import { BriskRoute } from './router/brisk.js';
12
- import { RouteGroup } from './router/group.js';
13
- import { RouteResource } from './router/resource.js';
14
- const proxyCache = new Cache({ max: 200 });
15
- /**
16
- * Makes input string consistent by having only the starting
17
- * slash
18
- */
19
- export function dropSlash(input) {
20
- if (input === '/') {
21
- return '/';
22
- }
23
- return `/${input.replace(/^\//, '').replace(/\/$/, '')}`;
24
- }
25
- /**
26
- * Returns a flat list of routes from the route groups and resources
27
- */
28
- export function toRoutesJSON(routes) {
29
- return routes.reduce((list, route) => {
30
- if (route instanceof RouteGroup) {
31
- list = list.concat(toRoutesJSON(route.routes));
32
- return list;
33
- }
34
- if (route instanceof RouteResource) {
35
- list = list.concat(toRoutesJSON(route.routes));
36
- return list;
37
- }
38
- if (route instanceof BriskRoute) {
39
- if (route.route && !route.route.isDeleted()) {
40
- list.push(route.route.toJSON());
41
- }
42
- return list;
43
- }
44
- if (!route.isDeleted()) {
45
- list.push(route.toJSON());
46
- }
47
- return list;
48
- }, []);
49
- }
50
- /**
51
- * Helper to know if the remote address should
52
- * be trusted.
53
- */
54
- export function trustProxy(remoteAddress, proxyFn) {
55
- if (proxyCache.has(remoteAddress)) {
56
- return proxyCache.get(remoteAddress);
57
- }
58
- const result = proxyFn(remoteAddress, 0);
59
- proxyCache.set(remoteAddress, result);
60
- return result;
61
- }
62
- /**
63
- * Parses a range expression to an object filled with the range
64
- */
65
- export function parseRange(range, value) {
66
- const parts = range.split('..');
67
- const min = Number(parts[0]);
68
- const max = Number(parts[1]);
69
- if (Number.isNaN(min) || Number.isNaN(max)) {
70
- return {};
71
- }
72
- if (min === max) {
73
- return {
74
- [min]: value,
75
- };
76
- }
77
- if (max < min) {
78
- throw new InvalidArgumentsException(`Invalid range "${range}"`);
79
- }
80
- return [...Array(max - min + 1).keys()].reduce((result, step) => {
81
- result[min + step] = value;
82
- return result;
83
- }, {});
84
- }
@@ -1,12 +0,0 @@
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
- };
@@ -1,39 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { AsyncLocalStorage } from 'node:async_hooks';
10
- /**
11
- * Async local storage for HTTP context
12
- */
13
- export const asyncLocalStorage = {
14
- /**
15
- * Check if the async local storage for the HTTP
16
- * context is enabled or not
17
- */
18
- isEnabled: false,
19
- /**
20
- * HTTP context storage instance for the current scope
21
- */
22
- storage: null,
23
- /**
24
- * Create the storage instance. This method must be called only
25
- * once.
26
- */
27
- create() {
28
- this.isEnabled = true;
29
- this.storage = new AsyncLocalStorage();
30
- return this.storage;
31
- },
32
- /**
33
- * Destroy the create storage instance
34
- */
35
- destroy() {
36
- this.isEnabled = false;
37
- this.storage = null;
38
- },
39
- };
@@ -1,58 +0,0 @@
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
- }
@@ -1,105 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { inspect } from 'node:util';
10
- import Macroable from '@poppinss/macroable';
11
- import { RuntimeException } from '@poppinss/utils';
12
- import { asyncLocalStorage } from './local_storage.js';
13
- /**
14
- * Http context encapsulates properties for a given HTTP request. The
15
- * context class can be extended using macros and getters.
16
- */
17
- export class HttpContext extends Macroable {
18
- request;
19
- response;
20
- logger;
21
- containerResolver;
22
- /**
23
- * Find if async localstorage is enabled for HTTP requests
24
- * or not
25
- */
26
- static get usingAsyncLocalStorage() {
27
- return asyncLocalStorage.isEnabled;
28
- }
29
- /**
30
- * Get access to the HTTP context. Available only when
31
- * "usingAsyncLocalStorage" is true
32
- */
33
- static get() {
34
- if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
35
- return null;
36
- }
37
- return asyncLocalStorage.storage.getStore() || null;
38
- }
39
- /**
40
- * Get the HttpContext instance or raise an exception if not
41
- * available
42
- */
43
- static getOrFail() {
44
- /**
45
- * Localstorage is not enabled
46
- */
47
- if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
48
- throw new RuntimeException('HTTP context is not available. Enable "useAsyncLocalStorage" inside "config/app.ts" file');
49
- }
50
- const store = this.get();
51
- if (!store) {
52
- throw new RuntimeException('Http context is not available outside of an HTTP request');
53
- }
54
- return store;
55
- }
56
- /**
57
- * Run a method that doesn't have access to HTTP context from
58
- * the async local storage.
59
- */
60
- static runOutsideContext(callback, ...args) {
61
- if (!asyncLocalStorage.storage) {
62
- return callback(...args);
63
- }
64
- return asyncLocalStorage.storage.exit(callback, ...args);
65
- }
66
- /**
67
- * Reference to the current route. Not available inside
68
- * server middleware
69
- */
70
- route;
71
- /**
72
- * A unique key for the current route
73
- */
74
- routeKey;
75
- /**
76
- * Route params
77
- */
78
- params = {};
79
- /**
80
- * Route subdomains
81
- */
82
- subdomains = {};
83
- constructor(request, response, logger, containerResolver) {
84
- super();
85
- this.request = request;
86
- this.response = response;
87
- this.logger = logger;
88
- this.containerResolver = containerResolver;
89
- /*
90
- * Creating the circular reference. We do this, since request and response
91
- * are meant to be extended and at times people would want to access
92
- * other ctx properties like `logger`, `profiler` inside those
93
- * extended methods.
94
- */
95
- this.request.ctx = this;
96
- this.response.ctx = this;
97
- }
98
- /**
99
- * A helper to see top level properties on the context object
100
- */
101
- /* c8 ignore next 3 */
102
- inspect() {
103
- return inspect(this, false, 1, true);
104
- }
105
- }
package/build/src/qs.d.ts DELETED
@@ -1,11 +0,0 @@
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
- }
package/build/src/qs.js DELETED
@@ -1,25 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { parse, stringify } from 'qs';
10
- /**
11
- * Query string parser used to parse and stringify query
12
- * strings.
13
- */
14
- export class Qs {
15
- #config;
16
- constructor(config) {
17
- this.#config = config;
18
- }
19
- parse(value) {
20
- return parse(value, this.#config.parse);
21
- }
22
- stringify(value) {
23
- return stringify(value, this.#config.stringify);
24
- }
25
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,140 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { parse } from 'node:url';
10
- import encodeUrl from 'encodeurl';
11
- import debug from './debug.js';
12
- /**
13
- * Exposes the API to construct redirect routes
14
- */
15
- export class Redirect {
16
- /**
17
- * A boolean to forward the existing query string
18
- */
19
- #forwardQueryString = false;
20
- /**
21
- * The status code for the redirect
22
- */
23
- #statusCode = 302;
24
- /**
25
- * A custom query string to forward
26
- */
27
- #queryString = {};
28
- #request;
29
- #response;
30
- #router;
31
- #qs;
32
- constructor(request, response, router, qs) {
33
- this.#request = request;
34
- this.#response = response;
35
- this.#router = router;
36
- this.#qs = qs;
37
- }
38
- /**
39
- * Sends response by setting require headers
40
- */
41
- #sendResponse(url, query) {
42
- const stringified = this.#qs.stringify(query);
43
- url = stringified ? `${url}?${stringified}` : url;
44
- debug('redirecting to url "%s"', url);
45
- this.#response.location(encodeUrl(url));
46
- this.#response.safeStatus(this.#statusCode);
47
- this.#response.type('text/plain; charset=utf-8');
48
- this.#response.send(`Redirecting to ${url}`);
49
- }
50
- /**
51
- * Returns the referrer url
52
- */
53
- #getReferrerUrl() {
54
- let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
55
- return Array.isArray(url) ? url[0] : url;
56
- }
57
- /**
58
- * Set a custom status code.
59
- */
60
- status(statusCode) {
61
- this.#statusCode = statusCode;
62
- return this;
63
- }
64
- /**
65
- * Clearing query string values added using the
66
- * "withQs" method
67
- */
68
- clearQs() {
69
- this.#forwardQueryString = false;
70
- this.#queryString = {};
71
- return this;
72
- }
73
- withQs(name, value) {
74
- if (typeof name === 'undefined') {
75
- this.#forwardQueryString = true;
76
- return this;
77
- }
78
- if (typeof name === 'string') {
79
- this.#queryString[name] = value;
80
- return this;
81
- }
82
- Object.assign(this.#queryString, name);
83
- return this;
84
- }
85
- /**
86
- * Redirect to the previous path.
87
- */
88
- back() {
89
- let query = {};
90
- const referrerUrl = this.#getReferrerUrl();
91
- const url = parse(referrerUrl);
92
- debug('referrer url "%s"', referrerUrl);
93
- debug('referrer base url "%s"', url.pathname);
94
- /**
95
- * Parse query string from the referrer url
96
- */
97
- if (this.#forwardQueryString) {
98
- query = this.#qs.parse(url.query || '');
99
- }
100
- /**
101
- * Append custom query string
102
- */
103
- Object.assign(query, this.#queryString);
104
- /**
105
- * Redirect
106
- */
107
- this.#sendResponse(url.pathname || '', query);
108
- }
109
- /**
110
- * Redirect the request using a route identifier.
111
- */
112
- toRoute(routeIdentifier, params, options) {
113
- if (options && options.qs) {
114
- this.withQs(options.qs);
115
- options.qs = undefined;
116
- }
117
- const url = this.#router.makeUrl(routeIdentifier, params, options);
118
- return this.toPath(url);
119
- }
120
- /**
121
- * Redirect the request using a path.
122
- */
123
- toPath(url) {
124
- let query = {};
125
- /**
126
- * Extract query string from the current URL
127
- */
128
- if (this.#forwardQueryString) {
129
- query = this.#qs.parse(parse(this.#request.url).query || '');
130
- }
131
- /**
132
- * Assign custom query string
133
- */
134
- Object.assign(query, this.#queryString);
135
- /**
136
- * Redirect
137
- */
138
- this.#sendResponse(url, query);
139
- }
140
- }