@adonisjs/http-server 8.0.0-next.8 → 8.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 (49) hide show
  1. package/build/define_config-D-kQXU0e.js +2438 -0
  2. package/build/factories/http_context.d.ts +10 -4
  3. package/build/factories/main.d.ts +2 -2
  4. package/build/factories/main.js +170 -345
  5. package/build/factories/request.d.ts +4 -4
  6. package/build/factories/response.d.ts +4 -4
  7. package/build/factories/router.d.ts +1 -1
  8. package/build/factories/server_factory.d.ts +1 -1
  9. package/build/factories/url_builder_factory.d.ts +3 -3
  10. package/build/helpers-C_2HouOe.js +52 -0
  11. package/build/index.d.ts +3 -2
  12. package/build/index.js +155 -370
  13. package/build/src/client/helpers.d.ts +37 -0
  14. package/build/src/client/types.d.ts +194 -0
  15. package/build/src/client/url_builder.d.ts +15 -0
  16. package/build/src/client/url_builder.js +115 -0
  17. package/build/src/cookies/client.d.ts +28 -5
  18. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  19. package/build/src/cookies/drivers/signed.d.ts +1 -1
  20. package/build/src/cookies/parser.d.ts +1 -1
  21. package/build/src/cookies/serializer.d.ts +2 -2
  22. package/build/src/debug.d.ts +14 -1
  23. package/build/src/define_config.d.ts +19 -1
  24. package/build/src/define_middleware.d.ts +19 -3
  25. package/build/src/errors.d.ts +60 -5
  26. package/build/src/exception_handler.d.ts +28 -8
  27. package/build/src/helpers.d.ts +23 -16
  28. package/build/src/helpers.js +76 -22
  29. package/build/src/http_context/main.d.ts +67 -17
  30. package/build/src/qs.d.ts +17 -3
  31. package/build/src/redirect.d.ts +22 -3
  32. package/build/src/request.d.ts +12 -5
  33. package/build/src/response.d.ts +5 -5
  34. package/build/src/response_status.d.ts +14 -0
  35. package/build/src/router/main.d.ts +6 -2
  36. package/build/src/router/route.d.ts +130 -32
  37. package/build/src/router/signed_url_builder.d.ts +1 -1
  38. package/build/src/server/main.d.ts +6 -6
  39. package/build/src/types/main.js +1 -0
  40. package/build/src/types/response.d.ts +6 -1
  41. package/build/src/types/route.d.ts +3 -27
  42. package/build/src/types/url_builder.d.ts +2 -140
  43. package/build/src/utils.d.ts +71 -6
  44. package/build/types-AUwURgIL.js +1 -0
  45. package/build/utils-BjSHKI3s.js +618 -0
  46. package/package.json +56 -47
  47. package/build/chunk-NQNHMINZ.js +0 -135
  48. package/build/chunk-W6WKITGF.js +0 -5486
  49. package/build/src/router/url_builder.d.ts +0 -9
@@ -1,8 +1,11 @@
1
- import { type Encryption } from '@adonisjs/encryption';
1
+ import { type Encryption } from '@boringnode/encryption';
2
+ import { type Qs } from './qs.ts';
3
+ import { createURL } from './client/helpers.ts';
2
4
  import { type CookieOptions } from './types/response.ts';
3
- import { type SignedURLOptions, type URLOptions } from './types/url_builder.ts';
5
+ import { type SignedURLOptions } from './types/url_builder.ts';
4
6
  import type { RouteMatchers, RouteJSON, MatchItRouteToken } from './types/route.ts';
5
7
  import { type MiddlewareFn, type RouteHandlerInfo, type MiddlewareHandlerInfo, type ParsedGlobalMiddleware, type ParsedNamedMiddleware } from './types/middleware.ts';
8
+ export { createURL };
6
9
  /**
7
10
  * This function is similar to the intrinsic function encodeURI. However, it will not encode:
8
11
  * - The \, ^, or | characters
@@ -42,20 +45,6 @@ export { default as mime } from 'mime-types';
42
45
  * @returns {MatchItRouteToken[]} Array of parsed route tokens
43
46
  */
44
47
  export declare function parseRoute(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
45
- /**
46
- * Makes URL for a given route pattern using its parsed tokens. The
47
- * tokens could be generated using the "parseRoute" method.
48
- *
49
- * @param pattern - The route pattern
50
- * @param tokens - Array of parsed route tokens
51
- * @param searchParamsStringifier - Function to stringify query parameters
52
- * @param params - Route parameters as array or object
53
- * @param options - URL options
54
- * @returns {string} The generated URL
55
- */
56
- export declare function createURL(pattern: string, tokens: Pick<MatchItRouteToken, 'val' | 'type' | 'end'>[], searchParamsStringifier: (qs: Record<string, any>) => string, params?: any[] | {
57
- [param: string]: any;
58
- }, options?: URLOptions): string;
59
48
  /**
60
49
  * Makes signed URL for a given route pattern using its parsed tokens. The
61
50
  * tokens could be generated using the "parseRoute" method.
@@ -106,3 +95,21 @@ export declare function middlewareInfo(middleware: MiddlewareFn | ParsedGlobalMi
106
95
  * @returns {Promise<RouteHandlerInfo>} Promise resolving to route handler information
107
96
  */
108
97
  export declare function routeInfo(route: RouteJSON): Promise<RouteHandlerInfo>;
98
+ /**
99
+ * Appends query string parameters to a URI. Existing query parameters
100
+ * in the URI are merged with the new ones.
101
+ *
102
+ * @param uri - The base URI to append query string to
103
+ * @param queryString - Object containing query parameters to append
104
+ * @param qsParser - Query string parser instance for stringify/parse operations
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const result = appendQueryString('/users', { page: 1, limit: 10 }, qsParser)
109
+ * // Returns: '/users?page=1&limit=10'
110
+ *
111
+ * const result2 = appendQueryString('/users?sort=name', { page: 1 }, qsParser)
112
+ * // Returns: '/users?sort=name&page=1'
113
+ * ```
114
+ */
115
+ export declare function appendQueryString(uri: string, queryString: Record<string, any>, qsParser: Qs): string;
@@ -1,22 +1,76 @@
1
- import {
2
- createSignedURL,
3
- createURL,
4
- default as default2,
5
- default2 as default3,
6
- matchRoute,
7
- middlewareInfo,
8
- parseRoute,
9
- routeInfo,
10
- serializeCookie
11
- } from "../chunk-NQNHMINZ.js";
12
- export {
13
- createSignedURL,
14
- createURL,
15
- default2 as encodeUrl,
16
- matchRoute,
17
- middlewareInfo,
18
- default3 as mime,
19
- parseRoute,
20
- routeInfo,
21
- serializeCookie
22
- };
1
+ import { n as safeDecodeURI } from "../utils-BjSHKI3s.js";
2
+ import { t as createURL } from "../helpers-C_2HouOe.js";
3
+ import { serialize } from "cookie-es";
4
+ import matchit from "@poppinss/matchit";
5
+ import string from "@poppinss/utils/string";
6
+ import { parseBindingReference } from "@adonisjs/fold";
7
+ import encodeUrl from "encodeurl";
8
+ import mime from "mime-types";
9
+ function parseRoute(pattern, matchers) {
10
+ return matchit.parse(pattern, matchers);
11
+ }
12
+ function createSignedURL(identifier, tokens, searchParamsStringifier, encryption, params, options) {
13
+ const signature = encryption.getMessageVerifier().sign(createURL(identifier, tokens, searchParamsStringifier, params, {
14
+ ...options,
15
+ prefixUrl: void 0
16
+ }), options?.expiresIn, options?.purpose);
17
+ return createURL(identifier, tokens, searchParamsStringifier, params, {
18
+ ...options,
19
+ qs: {
20
+ ...options?.qs,
21
+ signature
22
+ }
23
+ });
24
+ }
25
+ function matchRoute(url, patterns) {
26
+ const tokensBucket = patterns.map((pattern) => parseRoute(pattern));
27
+ const match = matchit.match(url, tokensBucket);
28
+ if (!match.length) return null;
29
+ return matchit.exec(url, match);
30
+ }
31
+ function serializeCookie(key, value, options) {
32
+ let expires;
33
+ let maxAge;
34
+ if (options) {
35
+ expires = typeof options.expires === "function" ? options.expires() : options.expires;
36
+ maxAge = options.maxAge ? string.seconds.parse(options.maxAge) : void 0;
37
+ }
38
+ return serialize(key, value, {
39
+ ...options,
40
+ maxAge,
41
+ expires
42
+ });
43
+ }
44
+ async function middlewareInfo(middleware) {
45
+ if (typeof middleware === "function") return {
46
+ type: "closure",
47
+ name: middleware.name || "closure"
48
+ };
49
+ if ("args" in middleware) return {
50
+ type: "named",
51
+ name: middleware.name,
52
+ args: middleware.args,
53
+ ...await parseBindingReference([middleware.reference])
54
+ };
55
+ return {
56
+ type: "global",
57
+ name: middleware.name,
58
+ ...await parseBindingReference([middleware.reference])
59
+ };
60
+ }
61
+ async function routeInfo(route) {
62
+ return "reference" in route.handler ? {
63
+ type: "controller",
64
+ ...await parseBindingReference(route.handler.reference)
65
+ } : {
66
+ type: "closure",
67
+ name: route.handler.name || "closure",
68
+ args: "listArgs" in route.handler ? String(route.handler.listArgs) : void 0
69
+ };
70
+ }
71
+ function appendQueryString(uri, queryString, qsParser) {
72
+ const { query, pathname } = safeDecodeURI(uri, false);
73
+ const mergedQueryString = qsParser.stringify(Object.assign(qsParser.parse(query), queryString));
74
+ return mergedQueryString ? `${pathname}?${mergedQueryString}` : pathname;
75
+ }
76
+ export { appendQueryString, createSignedURL, createURL, encodeUrl, matchRoute, middlewareInfo, mime, parseRoute, routeInfo, serializeCookie };
@@ -1,36 +1,86 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Logger } from '@adonisjs/logger';
3
3
  import { type ContainerResolver } from '@adonisjs/fold';
4
- import type { Request } from '../request.ts';
5
- import type { Response } from '../response.ts';
4
+ import type { HttpRequest } from '../request.ts';
5
+ import type { HttpResponse } from '../response.ts';
6
6
  import type { RouteJSON } from '../types/route.ts';
7
7
  /**
8
- * Http context encapsulates properties for a given HTTP request. The
9
- * context class can be extended using macros and getters.
8
+ * HTTP context encapsulates all properties and services for a given HTTP request.
9
+ *
10
+ * The HttpContext class serves as the central hub for request-specific data and services.
11
+ * It provides access to the request, response, route information, container resolver,
12
+ * and logger instances. The context can be extended using macros and getters for
13
+ * application-specific functionality.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * export default class UsersController {
18
+ * async show({ request, response, params }: HttpContext) {
19
+ * const user = await User.find(params.id)
20
+ * return response.json(user)
21
+ * }
22
+ * }
23
+ * ```
10
24
  */
11
25
  export declare class HttpContext extends Macroable {
12
- request: Request;
13
- response: Response;
26
+ request: HttpRequest;
27
+ response: HttpResponse;
14
28
  logger: Logger;
15
29
  containerResolver: ContainerResolver<any>;
16
30
  /**
17
- * Find if async localstorage is enabled for HTTP requests
18
- * or not
31
+ * Indicates whether async local storage is enabled for HTTP requests.
32
+ *
33
+ * When enabled, the HTTP context is automatically available within the
34
+ * scope of request processing through static methods like get() and getOrFail().
19
35
  */
20
36
  static get usingAsyncLocalStorage(): boolean;
21
37
  /**
22
- * Get access to the HTTP context. Available only when
23
- * "usingAsyncLocalStorage" is true
38
+ * Get access to the current HTTP context from async local storage.
39
+ *
40
+ * This method is only available when async local storage is enabled.
41
+ * Returns null if called outside of an HTTP request context.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const ctx = HttpContext.get()
46
+ * if (ctx) {
47
+ * console.log(ctx.request.url())
48
+ * }
49
+ * ```
24
50
  */
25
51
  static get(): HttpContext | null;
26
52
  /**
27
- * Get the HttpContext instance or raise an exception if not
28
- * available
53
+ * Get the HttpContext instance or raise an exception if not available.
54
+ *
55
+ * This method is useful when you need guaranteed access to the HTTP context
56
+ * and want to fail fast if it's not available.
57
+ *
58
+ * @throws RuntimeException when async local storage is disabled or context is unavailable
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const ctx = HttpContext.getOrFail()
63
+ * const userId = ctx.request.input('user_id')
64
+ * ```
29
65
  */
30
66
  static getOrFail(): HttpContext;
31
67
  /**
32
- * Run a method that doesn't have access to HTTP context from
33
- * the async local storage.
68
+ * Run a method outside of the HTTP context scope.
69
+ *
70
+ * This method allows you to execute code that should not have access to
71
+ * the current HTTP context from async local storage. Useful for background
72
+ * tasks or operations that should be context-independent.
73
+ *
74
+ * @param callback - Function to execute outside the context
75
+ * @param args - Arguments to pass to the callback
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * HttpContext.runOutsideContext(() => {
80
+ * // This code cannot access HttpContext.get()
81
+ * performBackgroundTask()
82
+ * })
83
+ * ```
34
84
  */
35
85
  static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
36
86
  /**
@@ -53,12 +103,12 @@ export declare class HttpContext extends Macroable {
53
103
  /**
54
104
  * Creates a new HttpContext instance
55
105
  *
56
- * @param {Request} request - The HTTP request instance
57
- * @param {Response} response - The HTTP response instance
106
+ * @param {HttpRequest} request - The HTTP request instance
107
+ * @param {HttpResponse} response - The HTTP response instance
58
108
  * @param {Logger} logger - The logger instance
59
109
  * @param {ContainerResolver<any>} containerResolver - The IoC container resolver
60
110
  */
61
- constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
111
+ constructor(request: HttpRequest, response: HttpResponse, logger: Logger, containerResolver: ContainerResolver<any>);
62
112
  /**
63
113
  * A helper to see top level properties on the context object
64
114
  */
package/build/src/qs.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  import { type QSParserConfig } from './types/qs.ts';
2
2
  /**
3
- * Query string parser used to parse and stringify query
4
- * strings.
3
+ * Query string parser that provides methods to parse and stringify query strings.
4
+ *
5
+ * This class wraps the popular 'qs' package with configurable options for parsing
6
+ * and stringifying query parameters. It allows customization of array handling,
7
+ * depth limits, and encoding behavior.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const qs = new Qs({
12
+ * parse: { depth: 5, arrayLimit: 20 },
13
+ * stringify: { encode: false, skipNulls: true }
14
+ * })
15
+ *
16
+ * const parsed = qs.parse('users[0][name]=john&users[0][age]=25')
17
+ * const stringified = qs.stringify({ users: [{ name: 'john', age: 25 }] })
18
+ * ```
5
19
  */
6
20
  export declare class Qs {
7
21
  #private;
@@ -15,7 +29,7 @@ export declare class Qs {
15
29
  * @param value - Query string to parse (e.g., "foo=bar&baz=qux")
16
30
  * @returns Parsed object representation of the query string
17
31
  */
18
- parse: (value: string) => import("qs").ParsedQs;
32
+ parse: (value: string) => import("@poppinss/qs").ParsedQs;
19
33
  /**
20
34
  * Converts a JavaScript object into a query string using the configured options
21
35
  * @param value - Object to convert to query string
@@ -1,10 +1,29 @@
1
1
  import type { IncomingMessage } from 'node:http';
2
2
  import type { Qs } from './qs.ts';
3
- import type { Response } from './response.ts';
4
3
  import type { Router } from './router/main.ts';
4
+ import type { HttpResponse } from './response.ts';
5
5
  import type { RoutesList, LookupList, URLOptions, GetRoutesForMethod, RouteBuilderArguments } from './types/url_builder.ts';
6
6
  /**
7
- * Exposes the API to construct redirect routes
7
+ * Provides a fluent API for constructing HTTP redirect responses.
8
+ *
9
+ * The Redirect class allows you to build redirects with custom status codes,
10
+ * query string forwarding, and route-based URL generation. It supports both
11
+ * direct URL redirects and route-based redirects using registered route names.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Basic redirect
16
+ * return response.redirect('https://example.com')
17
+ *
18
+ * // Redirect to a route
19
+ * return response.redirect().toRoute('users.show', { id: 1 })
20
+ *
21
+ * // Redirect with status code and query string
22
+ * return response.redirect()
23
+ * .status(301)
24
+ * .withQs({ utm_source: 'newsletter' })
25
+ * .toPath('/dashboard')
26
+ * ```
8
27
  */
9
28
  export declare class Redirect {
10
29
  #private;
@@ -15,7 +34,7 @@ export declare class Redirect {
15
34
  * @param router - AdonisJS router instance
16
35
  * @param qs - Query string parser instance
17
36
  */
18
- constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
37
+ constructor(request: IncomingMessage, response: HttpResponse, router: Router, qs: Qs);
19
38
  /**
20
39
  * Sets a custom HTTP status code for the redirect response
21
40
  * @param statusCode - HTTP status code to use (e.g., 301, 302, 307)
@@ -1,5 +1,5 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import type { Encryption } from '@adonisjs/encryption';
2
+ import type { Encryption } from '@boringnode/encryption';
3
3
  import { type ServerResponse, type IncomingMessage, type IncomingHttpHeaders } from 'node:http';
4
4
  import type { Qs } from './qs.ts';
5
5
  import { type RequestConfig } from './types/request.ts';
@@ -13,7 +13,7 @@ import type { HttpContext } from './http_context/main.ts';
13
13
  * You can access the original [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
14
14
  * using `request.request` property.
15
15
  */
16
- export declare class Request extends Macroable {
16
+ export declare class HttpRequest extends Macroable {
17
17
  #private;
18
18
  /** Native Node.js incoming message instance */
19
19
  request: IncomingMessage;
@@ -48,9 +48,16 @@ export declare class Request extends Macroable {
48
48
  /** Native Node.js server response instance */
49
49
  response: ServerResponse, encryption: Encryption, config: RequestConfig, qsParser: Qs);
50
50
  /**
51
- * Returns the request id from the `x-request-id` header. The
52
- * header is untouched, if it already exists.
53
- * @returns The request ID or undefined if not found/generated
51
+ * Returns the request ID from the `x-request-id` header.
52
+ *
53
+ * If the header doesn't exist and request ID generation is enabled,
54
+ * a new UUID will be generated and added to the request headers.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const requestId = request.id()
59
+ * console.log(requestId) // '550e8400-e29b-41d4-a716-446655440000'
60
+ * ```
54
61
  */
55
62
  id(): string | undefined;
56
63
  /**
@@ -1,5 +1,5 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import type { Encryption } from '@adonisjs/encryption';
2
+ import type { Encryption } from '@boringnode/encryption';
3
3
  import { type ServerResponse, type IncomingMessage } from 'node:http';
4
4
  import type { Qs } from './qs.ts';
5
5
  import { Redirect } from './redirect.ts';
@@ -19,7 +19,7 @@ import type { CastableHeader, CookieOptions, ResponseConfig, ResponseStream } fr
19
19
  * response.download('/path/to/file.pdf')
20
20
  * ```
21
21
  */
22
- export declare class Response extends Macroable {
22
+ export declare class HttpResponse extends Macroable {
23
23
  #private;
24
24
  request: IncomingMessage;
25
25
  response: ServerResponse;
@@ -46,7 +46,7 @@ export declare class Response extends Macroable {
46
46
  /**
47
47
  * The readable stream instance configured for the response
48
48
  */
49
- get outgoingStream(): import("stream").Readable | undefined;
49
+ get outgoingStream(): ResponseStream | undefined;
50
50
  /**
51
51
  * Configuration for file streaming including path and etag generation flag
52
52
  */
@@ -159,14 +159,14 @@ export declare class Response extends Macroable {
159
159
  * @param key - Header name
160
160
  * @returns The header value
161
161
  */
162
- getHeader(key: string): import("http").OutgoingHttpHeader | undefined;
162
+ getHeader(key: string): import("node:http").OutgoingHttpHeader | undefined;
163
163
  /**
164
164
  * Gets all response headers as an object
165
165
  *
166
166
  * @returns Object containing all headers
167
167
  */
168
168
  getHeaders(): {
169
- [x: string]: import("http").OutgoingHttpHeader | undefined;
169
+ [x: string]: import("node:http").OutgoingHttpHeader | undefined;
170
170
  accept?: string | string[] | undefined;
171
171
  "accept-charset"?: string | string[] | undefined;
172
172
  "accept-encoding"?: string | string[] | undefined;
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Standard HTTP response status codes organized as a constant object.
3
+ *
4
+ * This object provides named constants for all standard HTTP status codes,
5
+ * making code more readable and less error-prone when setting response statuses.
6
+ * The naming follows PascalCase convention for consistency with TypeScript conventions.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * response.status(ResponseStatus.NotFound)
11
+ * response.status(ResponseStatus.InternalServerError)
12
+ * response.status(ResponseStatus.Created)
13
+ * ```
14
+ */
1
15
  export declare const ResponseStatus: {
2
16
  readonly Continue: 100;
3
17
  readonly SwitchingProtocols: 101;
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import type { Application } from '@adonisjs/application';
3
3
  import type { Constructor, LazyImport } from '@poppinss/utils/types';
4
4
  import type { Qs } from '../qs.ts';
@@ -249,7 +249,11 @@ export declare class Router {
249
249
  * @param indentation - Indentation level for generated types
250
250
  * @returns Generated TypeScript types as string
251
251
  */
252
- generateTypes(indentation?: number): string;
252
+ generateTypes(indentation?: number): {
253
+ imports: never[];
254
+ types: string[];
255
+ routes: string;
256
+ };
253
257
  /**
254
258
  * Find route for a given URL, method and optionally domain
255
259
  * @param uri - The URI to match