@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,27 +0,0 @@
1
- import Macroable from '@poppinss/macroable';
2
- /**
3
- * Shortcut methods for commonly used route matchers
4
- */
5
- export declare class RouteMatchers extends Macroable {
6
- /**
7
- * Enforce value to be a number and also casts it to number data
8
- * type
9
- */
10
- number(): {
11
- match: RegExp;
12
- cast: (value: string) => number;
13
- };
14
- /**
15
- * Enforce value to be formatted as uuid
16
- */
17
- uuid(): {
18
- match: RegExp;
19
- cast: (value: string) => string;
20
- };
21
- /**
22
- * Enforce value to be formatted as slug
23
- */
24
- slug(): {
25
- match: RegExp;
26
- };
27
- }
@@ -1,36 +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 Macroable from '@poppinss/macroable';
10
- /**
11
- * Shortcut methods for commonly used route matchers
12
- */
13
- export class RouteMatchers extends Macroable {
14
- /**
15
- * Enforce value to be a number and also casts it to number data
16
- * type
17
- */
18
- number() {
19
- return { match: /^[0-9]+$/, cast: (value) => Number(value) };
20
- }
21
- /**
22
- * Enforce value to be formatted as uuid
23
- */
24
- uuid() {
25
- return {
26
- 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}$/,
27
- cast: (value) => value.toLowerCase(),
28
- };
29
- }
30
- /**
31
- * Enforce value to be formatted as slug
32
- */
33
- slug() {
34
- return { match: /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/ };
35
- }
36
- }
@@ -1,5 +0,0 @@
1
- import { MatchItRouteToken, RouteMatchers } from '../types/route.js';
2
- /**
3
- * Parses the route pattern
4
- */
5
- export declare function parseRoutePattern(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
@@ -1,17 +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
- // @ts-expect-error
10
- import matchit from '@poppinss/matchit';
11
- /**
12
- * Parses the route pattern
13
- */
14
- export function parseRoutePattern(pattern, matchers) {
15
- const tokens = matchit.parse(pattern, matchers);
16
- return tokens;
17
- }
@@ -1,54 +0,0 @@
1
- import Macroable from '@poppinss/macroable';
2
- import type { Application } from '@adonisjs/application';
3
- import { Route } from './route.js';
4
- import type { Constructor, LazyImport } from '../types/base.js';
5
- import type { ParsedGlobalMiddleware } from '../types/middleware.js';
6
- import type { ResourceActionNames, RouteMatcher, RouteMatchers } from '../types/route.js';
7
- /**
8
- * Route resource exposes the API to register multiple routes for a resource.
9
- */
10
- export declare class RouteResource extends Macroable {
11
- #private;
12
- /**
13
- * A collection of routes instances that belongs to this resource
14
- */
15
- routes: Route[];
16
- constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
17
- resource: string;
18
- controller: string | LazyImport<Constructor<any>> | Constructor<any>;
19
- globalMatchers: RouteMatchers;
20
- shallow: boolean;
21
- });
22
- /**
23
- * Register only given routes and remove others
24
- */
25
- only(names: ResourceActionNames[]): this;
26
- /**
27
- * Register all routes, except the one's defined
28
- */
29
- except(names: ResourceActionNames[]): this;
30
- /**
31
- * Register api only routes. The `create` and `edit` routes, which
32
- * are meant to show forms will not be registered
33
- */
34
- apiOnly(): this;
35
- /**
36
- * Define matcher for params inside the resource
37
- */
38
- where(key: string, matcher: RouteMatcher | string | RegExp): this;
39
- /**
40
- * Tap into multiple routes to configure them by their name
41
- */
42
- tap(callback: (route: Route) => void): this;
43
- tap(actions: ResourceActionNames | ResourceActionNames[], callback: (route: Route) => void): this;
44
- /**
45
- * Set the param name for a given resource
46
- */
47
- params(resources: {
48
- [resource: string]: string;
49
- }): this;
50
- /**
51
- * Prepend name to all the routes
52
- */
53
- as(name: string, normalizeName?: boolean): this;
54
- }
@@ -1,216 +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 string from '@poppinss/utils/string';
10
- import Macroable from '@poppinss/macroable';
11
- import { RuntimeException } from '@poppinss/utils';
12
- import { Route } from './route.js';
13
- /**
14
- * Route resource exposes the API to register multiple routes for a resource.
15
- */
16
- export class RouteResource extends Macroable {
17
- /**
18
- * Resource identifier. Nested resources are separated
19
- * with a dot notation
20
- */
21
- #resource;
22
- /**
23
- * The controller to handle resource routing requests
24
- */
25
- #controller;
26
- /**
27
- * Is it a shallow resource? Shallow resources URLs do not have parent
28
- * resource name and id once they can be identified with the id.
29
- */
30
- #shallow = false;
31
- /**
32
- * Matchers inherited from the router
33
- */
34
- #globalMatchers;
35
- /**
36
- * Reference to the AdonisJS application
37
- */
38
- #app;
39
- /**
40
- * Middleware registered on the router
41
- */
42
- #routerMiddleware;
43
- /**
44
- * Parameter names for the resources. Defaults to `id` for
45
- * a singular resource and `resource_id` for nested
46
- * resources.
47
- */
48
- #params = {};
49
- /**
50
- * Base name for the routes. We suffix action names
51
- * on top of the base name
52
- */
53
- #routesBaseName;
54
- /**
55
- * A collection of routes instances that belongs to this resource
56
- */
57
- routes = [];
58
- constructor(app, routerMiddleware, options) {
59
- super();
60
- this.#validateResourceName(options.resource);
61
- this.#app = app;
62
- this.#shallow = options.shallow;
63
- this.#routerMiddleware = routerMiddleware;
64
- this.#controller = options.controller;
65
- this.#globalMatchers = options.globalMatchers;
66
- this.#resource = this.#normalizeResourceName(options.resource);
67
- this.#routesBaseName = this.#getRoutesBaseName();
68
- this.#buildRoutes();
69
- }
70
- /**
71
- * Normalizes the resource name to dropping leading and trailing
72
- * slashes.
73
- */
74
- #normalizeResourceName(resource) {
75
- return resource.replace(/^\//, '').replace(/\/$/, '');
76
- }
77
- /**
78
- * Ensure resource name is not an empty string
79
- */
80
- #validateResourceName(resource) {
81
- if (!resource || resource === '/') {
82
- throw new RuntimeException(`Invalid resource name "${resource}"`);
83
- }
84
- }
85
- /**
86
- * Converting segments of a resource to snake case to
87
- * make the route name.
88
- */
89
- #getRoutesBaseName() {
90
- return this.#resource
91
- .split('.')
92
- .map((token) => string.snakeCase(token))
93
- .join('.');
94
- }
95
- /**
96
- * Create a new route for the given pattern, methods and controller action
97
- */
98
- #createRoute(pattern, methods, action) {
99
- const route = new Route(this.#app, this.#routerMiddleware, {
100
- pattern,
101
- methods,
102
- handler: typeof this.#controller === 'string'
103
- ? `${this.#controller}.${action}`
104
- : [this.#controller, action],
105
- globalMatchers: this.#globalMatchers,
106
- });
107
- route.as(`${this.#routesBaseName}.${action}`);
108
- this.routes.push(route);
109
- }
110
- /**
111
- * Returns the `resource_id` name for a given resource. The
112
- * resource name is converted to singular form and
113
- * transformed to snake case.
114
- *
115
- * photos becomes photo_id
116
- * users becomes user_id
117
- */
118
- #getResourceId(resource) {
119
- return `${string.snakeCase(string.singular(resource))}_id`;
120
- }
121
- /**
122
- * Build routes for the given resource
123
- */
124
- #buildRoutes() {
125
- const resources = this.#resource.split('.');
126
- const mainResource = resources.pop();
127
- this.#params[mainResource] = ':id';
128
- const baseURI = `${resources
129
- .map((resource) => {
130
- const paramName = `:${this.#getResourceId(resource)}`;
131
- this.#params[resource] = paramName;
132
- return `${resource}/${paramName}`;
133
- })
134
- .join('/')}/${mainResource}`;
135
- this.#createRoute(baseURI, ['GET', 'HEAD'], 'index');
136
- this.#createRoute(`${baseURI}/create`, ['GET', 'HEAD'], 'create');
137
- this.#createRoute(baseURI, ['POST'], 'store');
138
- this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ['GET', 'HEAD'], 'show');
139
- this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id/edit`, ['GET', 'HEAD'], 'edit');
140
- this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ['PUT', 'PATCH'], 'update');
141
- this.#createRoute(`${this.#shallow ? mainResource : baseURI}/:id`, ['DELETE'], 'destroy');
142
- }
143
- /**
144
- * Filter the routes based on their partial names
145
- */
146
- #filter(names, inverse) {
147
- const actions = Array.isArray(names) ? names : [names];
148
- return this.routes.filter((route) => {
149
- const match = actions.find((name) => route.getName().endsWith(name));
150
- return inverse ? !match : match;
151
- });
152
- }
153
- /**
154
- * Register only given routes and remove others
155
- */
156
- only(names) {
157
- this.#filter(names, true).forEach((route) => route.markAsDeleted());
158
- return this;
159
- }
160
- /**
161
- * Register all routes, except the one's defined
162
- */
163
- except(names) {
164
- this.#filter(names, false).forEach((route) => route.markAsDeleted());
165
- return this;
166
- }
167
- /**
168
- * Register api only routes. The `create` and `edit` routes, which
169
- * are meant to show forms will not be registered
170
- */
171
- apiOnly() {
172
- return this.except(['create', 'edit']);
173
- }
174
- /**
175
- * Define matcher for params inside the resource
176
- */
177
- where(key, matcher) {
178
- this.routes.forEach((route) => {
179
- route.where(key, matcher);
180
- });
181
- return this;
182
- }
183
- tap(actions, callback) {
184
- if (typeof actions === 'function') {
185
- this.routes.forEach((route) => actions(route));
186
- return this;
187
- }
188
- this.#filter(actions, false).forEach((route) => callback(route));
189
- return this;
190
- }
191
- /**
192
- * Set the param name for a given resource
193
- */
194
- params(resources) {
195
- Object.keys(resources).forEach((resource) => {
196
- const param = resources[resource];
197
- const existingParam = this.#params[resource];
198
- this.#params[resource] = `:${param}`;
199
- this.routes.forEach((route) => {
200
- route.setPattern(route.getPattern().replace(`${resource}/${existingParam}`, `${resource}/:${param}`));
201
- });
202
- });
203
- return this;
204
- }
205
- /**
206
- * Prepend name to all the routes
207
- */
208
- as(name, normalizeName = true) {
209
- name = normalizeName ? string.snakeCase(name) : name;
210
- this.routes.forEach((route) => {
211
- route.as(route.getName().replace(this.#routesBaseName, name), false);
212
- });
213
- this.#routesBaseName = name;
214
- return this;
215
- }
216
- }
@@ -1,92 +0,0 @@
1
- import Macroable from '@poppinss/macroable';
2
- import type { Application } from '@adonisjs/application';
3
- import type { Constructor, LazyImport, OneOrMore } from '../types/base.js';
4
- import type { MiddlewareFn, ParsedNamedMiddleware, ParsedGlobalMiddleware } from '../types/middleware.js';
5
- import type { GetControllerHandlers, RouteFn, RouteJSON, RouteMatcher, RouteMatchers, StoreRouteMiddleware } from '../types/route.js';
6
- /**
7
- * The route class exposes the APIs for constructing a route using the
8
- * fluent API.
9
- */
10
- export declare class Route<Controller extends Constructor<any> = any> extends Macroable {
11
- #private;
12
- constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
13
- pattern: string;
14
- methods: string[];
15
- handler: RouteFn | string | [LazyImport<Controller> | Controller, GetControllerHandlers<Controller>?];
16
- globalMatchers: RouteMatchers;
17
- });
18
- /**
19
- * Define matcher for a given param. If a matcher exists, then we do not
20
- * override that, since the routes inside a group will set matchers
21
- * before the group, so they should have priority over the group
22
- * matchers.
23
- *
24
- * ```ts
25
- * Route.group(() => {
26
- * Route.get('/:id', 'handler').where('id', /^[0-9]$/)
27
- * }).where('id', /[^a-z$]/)
28
- * ```
29
- *
30
- * The `/^[0-9]$/` will win over the matcher defined by the group
31
- */
32
- where(param: string, matcher: RouteMatcher | string | RegExp): this;
33
- /**
34
- * Define prefix for the route. Calling this method multiple times
35
- * applies multiple prefixes in the reverse order.
36
- */
37
- prefix(prefix: string): this;
38
- /**
39
- * Define a custom domain for the route. We do not overwrite the domain
40
- * unless `overwrite` flag is set to true.
41
- */
42
- domain(domain: string, overwrite?: boolean): this;
43
- /**
44
- * Define one or more middleware to be executed before the route
45
- * handler.
46
- *
47
- * Named middleware can be referenced using the name registered with
48
- * the router middleware store.
49
- */
50
- use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
51
- /**
52
- * @alias use
53
- */
54
- middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
55
- /**
56
- * Give a unique name to the route. Assinging a new unique removes the
57
- * existing name of the route.
58
- *
59
- * Setting prepends to true prefixes the name to the existing name.
60
- */
61
- as(name: string, prepend?: boolean): this;
62
- /**
63
- * Check if the route was marked to be deleted
64
- */
65
- isDeleted(): boolean;
66
- /**
67
- * Mark route as deleted. Deleted routes are not registered
68
- * with the route store
69
- */
70
- markAsDeleted(): void;
71
- /**
72
- * Get the route name
73
- */
74
- getName(): string | undefined;
75
- /**
76
- * Get the route pattern
77
- */
78
- getPattern(): string;
79
- /**
80
- * Set the route pattern
81
- */
82
- setPattern(pattern: string): this;
83
- /**
84
- * Returns the stack of middleware registered on the route.
85
- * The value is shared by reference.
86
- */
87
- getMiddleware(): StoreRouteMiddleware[][];
88
- /**
89
- * Returns JSON representation of the route
90
- */
91
- toJSON(): RouteJSON;
92
- }