@adonisjs/http-server 8.0.0-next.0 → 8.0.0-next.10

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 (74) hide show
  1. package/build/chunk-2QM3D5BN.js +87 -0
  2. package/build/chunk-5PWHBE2E.js +128 -0
  3. package/build/chunk-QDK57QGB.js +1176 -0
  4. package/build/{chunk-VYBTM3NC.js → chunk-YBLFT4O6.js} +1161 -1719
  5. package/build/factories/http_context.d.ts +5 -4
  6. package/build/factories/http_server.d.ts +7 -0
  7. package/build/factories/main.d.ts +6 -6
  8. package/build/factories/main.js +33 -5
  9. package/build/factories/qs_parser_factory.d.ts +5 -4
  10. package/build/factories/request.d.ts +3 -2
  11. package/build/factories/response.d.ts +4 -3
  12. package/build/factories/router.d.ts +2 -1
  13. package/build/factories/server_factory.d.ts +3 -2
  14. package/build/factories/url_builder_factory.d.ts +3 -2
  15. package/build/index.d.ts +19 -16
  16. package/build/index.js +97 -42
  17. package/build/src/client/helpers.d.ts +37 -0
  18. package/build/src/client/types.d.ts +88 -66
  19. package/build/src/client/url_builder.d.ts +12 -10
  20. package/build/src/client/url_builder.js +12 -0
  21. package/build/src/cookies/client.d.ts +61 -3
  22. package/build/src/cookies/drivers/encrypted.d.ts +13 -0
  23. package/build/src/cookies/drivers/plain.d.ts +9 -0
  24. package/build/src/cookies/drivers/signed.d.ts +13 -0
  25. package/build/src/cookies/parser.d.ts +18 -0
  26. package/build/src/cookies/serializer.d.ts +22 -3
  27. package/build/src/debug.d.ts +13 -0
  28. package/build/src/define_config.d.ts +21 -5
  29. package/build/src/define_middleware.d.ts +20 -4
  30. package/build/src/errors.d.ts +67 -10
  31. package/build/src/exception_handler.d.ts +95 -41
  32. package/build/src/helpers.d.ts +60 -4
  33. package/build/src/helpers.js +9 -1
  34. package/build/src/http_context/local_storage.d.ts +18 -1
  35. package/build/src/http_context/main.d.ts +71 -13
  36. package/build/src/qs.d.ts +31 -3
  37. package/build/src/redirect.d.ts +87 -16
  38. package/build/src/request.d.ts +121 -15
  39. package/build/src/response.d.ts +421 -208
  40. package/build/src/response_status.d.ts +14 -0
  41. package/build/src/router/brisk.d.ts +18 -7
  42. package/build/src/router/executor.d.ts +7 -3
  43. package/build/src/router/factories/use_return_value.d.ts +6 -1
  44. package/build/src/router/group.d.ts +23 -6
  45. package/build/src/router/legacy/url_builder.d.ts +15 -15
  46. package/build/src/router/main.d.ts +133 -20
  47. package/build/src/router/matchers.d.ts +3 -0
  48. package/build/src/router/resource.d.ts +37 -5
  49. package/build/src/router/route.d.ts +30 -6
  50. package/build/src/router/signed_url_builder.d.ts +7 -10
  51. package/build/src/router/store.d.ts +10 -2
  52. package/build/src/server/factories/middleware_handler.d.ts +12 -3
  53. package/build/src/server/factories/route_finder.d.ts +16 -6
  54. package/build/src/server/factories/write_response.d.ts +10 -3
  55. package/build/src/server/main.d.ts +83 -29
  56. package/build/src/tracing_channels.d.ts +4 -4
  57. package/build/src/types/main.d.ts +1 -1
  58. package/build/src/types/middleware.d.ts +35 -10
  59. package/build/src/types/qs.d.ts +5 -0
  60. package/build/src/types/request.d.ts +1 -1
  61. package/build/src/types/response.d.ts +14 -6
  62. package/build/src/types/route.d.ts +53 -51
  63. package/build/src/types/server.d.ts +30 -15
  64. package/build/src/types/tracing_channels.d.ts +24 -6
  65. package/build/src/types/url_builder.d.ts +22 -0
  66. package/build/src/utils.d.ts +76 -11
  67. package/package.json +29 -30
  68. package/build/chunk-ASX56VAK.js +0 -76
  69. package/build/client.cjs +0 -232
  70. package/build/client.d.cts +0 -258
  71. package/build/client.d.ts +0 -258
  72. package/build/client.js +0 -229
  73. package/build/src/client/main.d.ts +0 -3
  74. package/build/src/client/router.d.ts +0 -68
package/build/client.cjs DELETED
@@ -1,232 +0,0 @@
1
- 'use strict';
2
-
3
- // src/client/router.ts
4
- var RouterClient = class {
5
- /**
6
- * List of route references kept for lookup.
7
- */
8
- routes;
9
- /**
10
- * The lookup strategies to follow when generating URL builder
11
- * types and client
12
- */
13
- lookupStrategies = ["name", "pattern"];
14
- constructor(routes) {
15
- this.routes = routes ?? {};
16
- }
17
- /**
18
- * Register route JSON payload
19
- */
20
- register(route) {
21
- this.routes[route.domain] = this.routes[route.domain] || [];
22
- this.routes[route.domain].push(route);
23
- }
24
- /**
25
- * Define the lookup strategies to follow when generating URL builder
26
- * types and client.
27
- */
28
- updateLookupStrategies(strategies) {
29
- this.lookupStrategies = strategies;
30
- return this;
31
- }
32
- /**
33
- * Finds a route by its identifier. The identifier can be the
34
- * route name, controller.method name or the route pattern
35
- * itself.
36
- *
37
- * When "followLookupStrategy" is enabled, the lookup will be performed
38
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
39
- * method. The default lookupStrategy is "name" and "pattern".
40
- */
41
- find(routeIdentifier, domain, method, followLookupStrategy) {
42
- if (!domain) {
43
- let route = null;
44
- for (const routeDomain of Object.keys(this.routes)) {
45
- route = this.find(routeIdentifier, routeDomain, method, followLookupStrategy);
46
- if (route) {
47
- break;
48
- }
49
- }
50
- return route;
51
- }
52
- const routes = this.routes[domain];
53
- if (!routes) {
54
- return null;
55
- }
56
- const lookupByName = !followLookupStrategy || this.lookupStrategies.includes("name");
57
- const lookupByPattern = !followLookupStrategy || this.lookupStrategies.includes("pattern");
58
- const lookupByController = !followLookupStrategy || this.lookupStrategies.includes("controller");
59
- return routes.find((route) => {
60
- if (method && !route.methods.includes(method)) {
61
- return false;
62
- }
63
- if (route.name === routeIdentifier && lookupByName || route.pattern === routeIdentifier && lookupByPattern) {
64
- return true;
65
- }
66
- if (typeof route.handler === "function" || !lookupByController) {
67
- return false;
68
- }
69
- return route.handler.reference === routeIdentifier;
70
- }) || null;
71
- }
72
- /**
73
- * Finds a route by its identifier. The identifier can be the
74
- * route name, controller.method name or the route pattern
75
- * itself.
76
- *
77
- * An error is raised when unable to find the route.
78
- *
79
- * When "followLookupStrategy" is enabled, the lookup will be performed
80
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
81
- * method. The default lookupStrategy is "name" and "pattern".
82
- */
83
- findOrFail(routeIdentifier, domain, method, followLookupStrategy) {
84
- const route = this.find(routeIdentifier, domain, method, followLookupStrategy);
85
- if (!route) {
86
- throw new Error(`Cannot lookup route "${routeIdentifier}"`);
87
- }
88
- return route;
89
- }
90
- /**
91
- * Check if a route exists. The identifier can be the
92
- * route name, controller.method name or the route pattern
93
- * itself.
94
- *
95
- * When "followLookupStrategy" is enabled, the lookup will be performed
96
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
97
- * method. The default lookupStrategy is "name" and "pattern".
98
- */
99
- has(routeIdentifier, domain, method, followLookupStrategy) {
100
- return !!this.find(routeIdentifier, domain, method, followLookupStrategy);
101
- }
102
- /**
103
- * Returns a list of routes grouped by their domain names
104
- */
105
- toJSON() {
106
- return this.routes;
107
- }
108
- };
109
-
110
- // src/client/url_builder.ts
111
- function createURL(identifier, tokens, searchParamsStringifier, params, options) {
112
- const uriSegments = [];
113
- const paramsArray = Array.isArray(params) ? params : null;
114
- const paramsObject = !Array.isArray(params) ? params ?? {} : {};
115
- let paramsIndex = 0;
116
- for (const token of tokens) {
117
- if (token.type === 0) {
118
- uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
119
- continue;
120
- }
121
- if (token.type === 2) {
122
- const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
123
- if (!Array.isArray(values) || !values.length) {
124
- throw new Error(
125
- `Cannot make URL for "${identifier}". Invalid value provided for the wildcard param`
126
- );
127
- }
128
- uriSegments.push(`${values.join("/")}${token.end}`);
129
- break;
130
- }
131
- const paramName = token.val;
132
- const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
133
- const isDefined = value !== void 0 && value !== null;
134
- if (token.type === 1 && !isDefined) {
135
- throw new Error(
136
- `Cannot make URL for "${identifier}". Missing value for the "${paramName}" param`
137
- );
138
- }
139
- if (isDefined) {
140
- uriSegments.push(`${value}${token.end}`);
141
- }
142
- paramsIndex++;
143
- }
144
- let URI = `/${uriSegments.join("/")}`;
145
- if (options?.prefixUrl) {
146
- URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
147
- }
148
- if (options?.qs) {
149
- const queryString = searchParamsStringifier(options?.qs);
150
- URI = queryString ? `${URI}?${queryString}` : URI;
151
- }
152
- return URI;
153
- }
154
- function createUrlBuilder(router, searchParamsStringifier) {
155
- let domainsList;
156
- function createUrlForRoute(identifier, params, options, method) {
157
- if (!domainsList) {
158
- domainsList = Object.keys(router.toJSON()).filter((domain2) => domain2 !== "root");
159
- }
160
- const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
161
- const routeIdentifier = domain ? identifier.replace(new RegExp(`^${domain}@`), "") : identifier;
162
- const route = router.findOrFail(routeIdentifier, domain, method, true);
163
- return createURL(
164
- route.name ?? route.pattern,
165
- route.tokens,
166
- searchParamsStringifier,
167
- params,
168
- options
169
- );
170
- }
171
- const urlFor = function route(...[identifier, params, options]) {
172
- return createUrlForRoute(identifier, params, options);
173
- };
174
- urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
175
- return {
176
- url: createUrlForRoute(identifier, params, options, "GET"),
177
- method: "get",
178
- toString() {
179
- return this.url;
180
- }
181
- };
182
- };
183
- urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
184
- return {
185
- url: createUrlForRoute(identifier, params, options, "POST"),
186
- method: "post",
187
- toString() {
188
- return this.url;
189
- }
190
- };
191
- };
192
- urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
193
- return {
194
- url: createUrlForRoute(identifier, params, options, "PUT"),
195
- method: "put",
196
- toString() {
197
- return this.url;
198
- }
199
- };
200
- };
201
- urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
202
- return {
203
- url: createUrlForRoute(identifier, params, options, "PATCH"),
204
- method: "patch",
205
- toString() {
206
- return this.url;
207
- }
208
- };
209
- };
210
- urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
211
- return {
212
- url: createUrlForRoute(identifier, params, options, "DELETE"),
213
- method: "delete",
214
- toString() {
215
- return this.url;
216
- }
217
- };
218
- };
219
- urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
220
- return {
221
- url: createUrlForRoute(identifier, params, options, method),
222
- method,
223
- toString() {
224
- return this.url;
225
- }
226
- };
227
- };
228
- return urlFor;
229
- }
230
-
231
- exports.RouterClient = RouterClient;
232
- exports.createUrlBuilder = createUrlBuilder;
@@ -1,258 +0,0 @@
1
- import { Prettify } from '@poppinss/utils/types';
2
-
3
- /**
4
- * Types shared with the client. These should never import other types
5
- */
6
-
7
- /**
8
- * Options accepted by "url" and "route" helper methods
9
- */
10
- type URLOptions = {
11
- qs?: Record<string, any>;
12
- prefixUrl?: string;
13
- };
14
- /**
15
- * Options accepted by "signedUrl" and "signedRoute" helper methods
16
- */
17
- type SignedURLOptions = URLOptions & {
18
- expiresIn?: string | number;
19
- purpose?: string;
20
- };
21
- /**
22
- * Returns params for a route identifier
23
- */
24
- type RouteBuilderArguments<Routes, Method extends keyof Routes, Identifier extends keyof Routes[Method], Options extends any = URLOptions> = Routes extends LookupList ? Prettify<undefined extends Routes[Method][Identifier]['params'] ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Routes[Method][Identifier]['params']] ? [
25
- identifier: Identifier,
26
- params?: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
27
- options?: Options
28
- ] : [
29
- identifier: Identifier,
30
- params: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
31
- options?: Options
32
- ]> : never;
33
- /**
34
- * Shape of a route param matcher
35
- */
36
- type RouteMatcher = {
37
- match?: RegExp;
38
- cast?: (value: string) => any;
39
- };
40
- /**
41
- * Route token stored by matchit library
42
- */
43
- type MatchItRouteToken = RouteMatcher & {
44
- old: string;
45
- type: 0 | 1 | 2 | 3;
46
- val: string;
47
- end: string;
48
- };
49
- /**
50
- * Representation of route shared with the client
51
- */
52
- type ClientRouteJSON = {
53
- /**
54
- * A unique name for the route
55
- */
56
- name?: string;
57
- /**
58
- * Route URI pattern
59
- */
60
- pattern: string;
61
- /**
62
- * HTTP methods, the route responds to.
63
- */
64
- methods: string[];
65
- /**
66
- * Route domain
67
- */
68
- domain: string;
69
- /**
70
- * Reference to the route handler
71
- */
72
- handler: {
73
- reference?: any;
74
- } | Function;
75
- /**
76
- * Tokens to be used to construct the route URL
77
- */
78
- tokens: MatchItRouteToken[];
79
- };
80
- /**
81
- * LookupList type is used by the URLBuilder to provide
82
- * type-safety when creating URLs.
83
- *
84
- * There is no runtime property that matches this type. Its
85
- * purely for type-inference.
86
- */
87
- type LookupList = {
88
- [method: string]: {
89
- [identifier: string]: {
90
- paramsTuple?: [...any[]];
91
- params?: {
92
- [name: string]: any;
93
- };
94
- };
95
- };
96
- };
97
- /**
98
- * The urlFor helper is used to make URLs for pre-existing known routes. You can
99
- * make a URL using the route name, route pattern, or the route controller
100
- * reference (depends upon enabled lookupStrategies)
101
- *
102
- * ```ts
103
- * urlFor('users.show', [1]) // /users/1
104
- *
105
- * // Lookup inside a specific domain
106
- * urlFor('blog.adonisjs.com@posts.show', [1]) // /posts/1
107
- * ```
108
- */
109
- type UrlFor<Routes extends LookupList, Options extends any = URLOptions> = (<Identifier extends keyof Routes['ALL'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'ALL', Identifier, Options>) => string) & {
110
- /**
111
- * Make URL for a GET route. An error will be raised if the route doesn't
112
- * exist.
113
- *
114
- * ```ts
115
- * urlFor.get('users.show', [1]) // { method: 'get', url: '/users/1' }
116
- * urlFor.get('users.store', [1]) // Error: Route not found GET@users/store
117
- * ```
118
- */
119
- get<RouteIdentifier extends keyof Routes['GET'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'GET', RouteIdentifier, Options>): {
120
- method: 'get';
121
- url: string;
122
- };
123
- /**
124
- * Make URL for a POST route. An error will be raised if the route doesn't
125
- * exist.
126
- *
127
- * ```ts
128
- * urlFor.post('users.store') // { method: 'post', url: '/users' }
129
- * urlFor.post('users.show', [1]) // Error: Route not found POST@users.show
130
- * ```
131
- */
132
- post<RouteIdentifier extends keyof Routes['POST'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'POST', RouteIdentifier, Options>): {
133
- method: 'post';
134
- url: string;
135
- };
136
- /**
137
- * Make URL for a PUT route. An error will be raised if the route doesn't
138
- * exist.
139
- *
140
- * ```ts
141
- * urlFor.put('users.update', [1]) // { method: 'put', url: '/users/1' }
142
- * urlFor.put('users.show', [1]) // Error: Route not found PUT@users.show
143
- * ```
144
- */
145
- put<RouteIdentifier extends keyof Routes['PUT'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PUT', RouteIdentifier, Options>): {
146
- method: 'put';
147
- url: string;
148
- };
149
- /**
150
- * Make URL for a PATCH route. An error will be raised if the route doesn't
151
- * exist.
152
- *
153
- * ```ts
154
- * urlFor.put('users.update', [1]) // { method: 'patch', url: '/users/1' }
155
- * urlFor.put('users.show', [1]) // Error: Route not found PATCH@users.show
156
- * ```
157
- */
158
- patch<RouteIdentifier extends keyof Routes['PATCH'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PATCH', RouteIdentifier, Options>): {
159
- method: 'patch';
160
- url: string;
161
- };
162
- /**
163
- * Make URL for a DELETE route. An error will be raised if the route doesn't
164
- * exist.
165
- *
166
- * ```ts
167
- * urlFor.delete('users.destroy', [1]) // { method: 'delete', url: '/users/1' }
168
- * urlFor.delete('users.show', [1]) // Error: Route not found DELETE@users.show
169
- * ```
170
- */
171
- delete<RouteIdentifier extends keyof Routes['DELETE'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'DELETE', RouteIdentifier, Options>): {
172
- method: 'delete';
173
- url: string;
174
- };
175
- /**
176
- * Make URL for a custom route method. An error will be raised if the route doesn't
177
- * exist for the same method.
178
- */
179
- method<Method extends keyof Routes & string, RouteIdentifier extends keyof Routes[Method] & string>(method: Method, ...[identifier, params, options]: RouteBuilderArguments<Routes, Method, RouteIdentifier, Options>): {
180
- method: Method;
181
- url: string;
182
- };
183
- };
184
-
185
- /**
186
- * The router client contains the shared logic for finding routes
187
- * used by the server and the client.
188
- */
189
- declare class RouterClient<T extends ClientRouteJSON> {
190
- /**
191
- * List of route references kept for lookup.
192
- */
193
- protected routes: {
194
- [domain: string]: T[];
195
- };
196
- /**
197
- * The lookup strategies to follow when generating URL builder
198
- * types and client
199
- */
200
- lookupStrategies: ('name' | 'pattern' | 'controller')[];
201
- constructor(routes?: {
202
- [domain: string]: T[];
203
- });
204
- /**
205
- * Register route JSON payload
206
- */
207
- protected register(route: T): void;
208
- /**
209
- * Define the lookup strategies to follow when generating URL builder
210
- * types and client.
211
- */
212
- updateLookupStrategies(strategies: ('name' | 'pattern' | 'controller')[]): this;
213
- /**
214
- * Finds a route by its identifier. The identifier can be the
215
- * route name, controller.method name or the route pattern
216
- * itself.
217
- *
218
- * When "followLookupStrategy" is enabled, the lookup will be performed
219
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
220
- * method. The default lookupStrategy is "name" and "pattern".
221
- */
222
- find(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T | null;
223
- /**
224
- * Finds a route by its identifier. The identifier can be the
225
- * route name, controller.method name or the route pattern
226
- * itself.
227
- *
228
- * An error is raised when unable to find the route.
229
- *
230
- * When "followLookupStrategy" is enabled, the lookup will be performed
231
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
232
- * method. The default lookupStrategy is "name" and "pattern".
233
- */
234
- findOrFail(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T;
235
- /**
236
- * Check if a route exists. The identifier can be the
237
- * route name, controller.method name or the route pattern
238
- * itself.
239
- *
240
- * When "followLookupStrategy" is enabled, the lookup will be performed
241
- * on the basis of the lookup strategy enabled via the "lookupStrategies"
242
- * method. The default lookupStrategy is "name" and "pattern".
243
- */
244
- has(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): boolean;
245
- /**
246
- * Returns a list of routes grouped by their domain names
247
- */
248
- toJSON(): {
249
- [domain: string]: T[];
250
- };
251
- }
252
-
253
- /**
254
- * Creates the URLBuilder helper
255
- */
256
- declare function createUrlBuilder<Routes extends LookupList>(router: RouterClient<ClientRouteJSON>, searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes>;
257
-
258
- export { type ClientRouteJSON, type LookupList, type MatchItRouteToken, type RouteBuilderArguments, type RouteMatcher, RouterClient, type SignedURLOptions, type URLOptions, type UrlFor, createUrlBuilder };