@adonisjs/http-server 7.6.1 → 8.0.0-next.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 (63) hide show
  1. package/build/chunk-ASX56VAK.js +76 -0
  2. package/build/{chunk-7AGINHO3.js → chunk-VYBTM3NC.js} +1025 -607
  3. package/build/client.cjs +232 -0
  4. package/build/client.d.cts +258 -0
  5. package/build/client.d.ts +258 -0
  6. package/build/client.js +229 -0
  7. package/build/factories/http_server.d.ts +1 -1
  8. package/build/factories/main.d.ts +3 -3
  9. package/build/factories/main.js +89 -89
  10. package/build/factories/request.d.ts +1 -1
  11. package/build/factories/response.d.ts +2 -2
  12. package/build/factories/url_builder_factory.d.ts +25 -0
  13. package/build/index.d.ts +3 -2
  14. package/build/index.js +25 -23
  15. package/build/src/client/main.d.ts +3 -0
  16. package/build/src/client/router.d.ts +68 -0
  17. package/build/src/client/types.d.ts +181 -0
  18. package/build/src/client/url_builder.d.ts +13 -0
  19. package/build/src/cookies/client.d.ts +2 -2
  20. package/build/src/cookies/parser.d.ts +2 -2
  21. package/build/src/cookies/serializer.d.ts +7 -1
  22. package/build/src/define_middleware.d.ts +3 -2
  23. package/build/src/{exceptions.d.ts → errors.d.ts} +13 -1
  24. package/build/src/exception_handler.d.ts +2 -2
  25. package/build/src/helpers.d.ts +51 -15
  26. package/build/src/helpers.js +18 -0
  27. package/build/src/http_context/main.d.ts +3 -3
  28. package/build/src/qs.d.ts +3 -3
  29. package/build/src/redirect.d.ts +3 -2
  30. package/build/src/request.d.ts +10 -9
  31. package/build/src/response.d.ts +1 -1
  32. package/build/src/router/brisk.d.ts +4 -3
  33. package/build/src/router/executor.d.ts +2 -2
  34. package/build/src/router/factories/use_return_value.d.ts +6 -1
  35. package/build/src/router/group.d.ts +4 -4
  36. package/build/src/router/{lookup_store → legacy}/url_builder.d.ts +20 -4
  37. package/build/src/router/main.d.ts +52 -12
  38. package/build/src/router/resource.d.ts +4 -3
  39. package/build/src/router/route.d.ts +3 -2
  40. package/build/src/router/signed_url_builder.d.ts +14 -0
  41. package/build/src/router/store.d.ts +3 -2
  42. package/build/src/server/factories/middleware_handler.d.ts +3 -3
  43. package/build/src/server/factories/{final_handler.d.ts → route_finder.d.ts} +2 -2
  44. package/build/src/server/main.d.ts +7 -3
  45. package/build/src/tracing_channels.d.ts +23 -0
  46. package/build/src/types/main.d.ts +7 -7
  47. package/build/src/types/main.js +0 -1
  48. package/build/src/types/middleware.d.ts +34 -1
  49. package/build/src/types/request.d.ts +4 -0
  50. package/build/src/types/response.d.ts +1 -1
  51. package/build/src/types/route.d.ts +50 -51
  52. package/build/src/types/server.d.ts +1 -1
  53. package/build/src/types/tracing_channels.d.ts +6 -0
  54. package/build/src/utils.d.ts +28 -0
  55. package/package.json +60 -48
  56. package/build/chunk-7AGINHO3.js.map +0 -1
  57. package/build/factories/main.js.map +0 -1
  58. package/build/index.js.map +0 -1
  59. package/build/src/router/lookup_store/main.d.ts +0 -48
  60. package/build/src/router/lookup_store/route_finder.d.ts +0 -25
  61. package/build/src/router/parser.d.ts +0 -5
  62. package/build/src/types/base.d.ts +0 -19
  63. package/build/src/types/main.js.map +0 -1
@@ -12,14 +12,20 @@ export declare class CookieSerializer {
12
12
  * Encodes value as a plain cookie. By default, the plain value will be converted
13
13
  * to a string using "JSON.stringify" method and then encoded as a base64 string.
14
14
  *
15
- * You can disable encoding of the cookie by setting `options.encoded = false`.
15
+ * You can disable cookie stringifaction by setting `options.stringify = false`.
16
16
  *
17
17
  * ```ts
18
18
  * serializer.encode('name', 'virk')
19
+ * serializer.encode('name', 'virk', { stringify: false })
19
20
  * ```
20
21
  */
21
22
  encode(key: string, value: any, options?: Partial<CookieOptions & {
23
+ /**
24
+ * @depreacted
25
+ * Instead use stringify option
26
+ */
22
27
  encode: boolean;
28
+ stringify: boolean;
23
29
  }>): string | null;
24
30
  /**
25
31
  * Sign a key-value pair to a signed cookie. The signed value has a
@@ -1,12 +1,13 @@
1
- import type { LazyImport, UnWrapLazyImport } from './types/base.js';
1
+ import type { LazyImport, UnWrapLazyImport } from '@poppinss/utils/types';
2
2
  import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } from './types/middleware.js';
3
3
  /**
4
4
  * Define an collection of named middleware. The collection gets converted
5
5
  * into a collection of factory functions. Calling the function returns
6
6
  * a reference to the executable middleware.
7
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) => {
8
+ export declare function defineNamedMiddleware<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
9
9
  name: K;
10
+ reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
10
11
  args: Args[0];
11
12
  handle: ParsedGlobalMiddleware["handle"];
12
13
  }; };
@@ -1,7 +1,16 @@
1
- import { Exception } from '@poppinss/utils';
1
+ import { Exception } from '@poppinss/utils/exception';
2
2
  import type { HttpContext } from './http_context/main.js';
3
+ /**
4
+ * Thrown when unable to find a matching route for the given request
5
+ */
3
6
  export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions) => Exception;
7
+ /**
8
+ * Thrown when unable to lookup a route by its identifier.
9
+ */
4
10
  export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions) => Exception;
11
+ /**
12
+ * A generic HTTP exception to convert errors to HTTP response
13
+ */
5
14
  export declare const E_HTTP_EXCEPTION: {
6
15
  new (message?: string, options?: ErrorOptions & {
7
16
  code?: string;
@@ -41,6 +50,9 @@ export declare const E_HTTP_EXCEPTION: {
41
50
  prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
42
51
  stackTraceLimit: number;
43
52
  };
53
+ /**
54
+ * Thrown when the "response.abort" method is called
55
+ */
44
56
  export declare const E_HTTP_REQUEST_ABORTED: {
45
57
  new (message?: string, options?: ErrorOptions & {
46
58
  code?: string;
@@ -79,7 +79,7 @@ export declare class ExceptionHandler extends Macroable {
79
79
  /**
80
80
  * Renders an error to HTML response
81
81
  */
82
- renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
82
+ renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<any>;
83
83
  /**
84
84
  * Renders the validation error message to a JSON
85
85
  * response
@@ -97,7 +97,7 @@ export declare class ExceptionHandler extends Macroable {
97
97
  /**
98
98
  * Renders the error to response
99
99
  */
100
- renderError(error: HttpError, ctx: HttpContext): Promise<void>;
100
+ renderError(error: HttpError, ctx: HttpContext): Promise<any>;
101
101
  /**
102
102
  * Renders the validation error to response
103
103
  */
@@ -1,23 +1,59 @@
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';
1
+ import { type CookieOptions } from './types/response.js';
2
+ import type { RouteMatchers, RouteJSON } from './types/route.js';
3
+ import { type RouteHandlerInfo, type MiddlewareFn, type MiddlewareHandlerInfo, type ParsedGlobalMiddleware, type ParsedNamedMiddleware } from './types/middleware.ts';
4
+ import { type MatchItRouteToken } from './client/types.ts';
6
5
  /**
7
- * Makes input string consistent by having only the starting
8
- * slash
6
+ * This function is similar to the intrinsic function encodeURI. However, it will not encode:
7
+ * - The \, ^, or | characters
8
+ * - The % character when it's part of a valid sequence
9
+ * - [ and ] (for IPv6 hostnames)
10
+ * - Replaces raw, unpaired surrogate pairs with the Unicode replacement character
11
+ *
12
+ * Some tests
13
+ * encodeURI('http://localhost/%20snow.html') // http://localhost/%2520snow.html
14
+ * encodeUrl('http://localhost/%20snow.html') // http://localhost/%20snow.html
15
+ *
16
+ * encodeURI('http://[::1]:8080/foo/bar') // http://%5B::1%5D:8080/foo/bar
17
+ * encodeUrl('http://[::1]:8080/foo/bar') // http://[::1]:8080/foo/bar
9
18
  */
10
- export declare function dropSlash(input: string): string;
19
+ export { default as encodeUrl } from 'encodeurl';
11
20
  /**
12
- * Returns a flat list of routes from the route groups and resources
21
+ * Re-exports the "https://www.npmjs.com/package/mime-types" package
13
22
  */
14
- export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
23
+ export { default as mime } from 'mime-types';
15
24
  /**
16
- * Helper to know if the remote address should
17
- * be trusted.
25
+ * Parse a route pattern into an array of tokens. These tokes can be used
26
+ * to match routes, or print them with semantic information.
27
+ *
28
+ * Token types
29
+ *
30
+ * - 0: (static) segment
31
+ * - 1: (parameter) segment
32
+ * - 2: (wildcard) segment
33
+ * - 3: (optional parameter) segment
34
+ *
35
+ * Value (val) refers to the segment value
36
+ *
37
+ * end refers to be the suffix or the segment (if any)
18
38
  */
19
- export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
39
+ export declare function parseRoute(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
20
40
  /**
21
- * Parses a range expression to an object filled with the range
41
+ * Match a given URI with an array of patterns and extract the params
42
+ * from the URL. Null value is returned in case of no match
22
43
  */
23
- export declare function parseRange<T>(range: string, value: T): Record<number, T>;
44
+ export declare function matchRoute(url: string, patterns: string[]): null | Record<string, string>;
45
+ /**
46
+ * Serialize the value of a cookie to a string you can send via
47
+ * set-cookie response header.
48
+ */
49
+ export declare function serializeCookie(key: string, value: string, options?: Partial<CookieOptions>): string;
50
+ /**
51
+ * Returns the info about a middleware handler. In case of lazy imports, the method
52
+ * will return the import path
53
+ */
54
+ export declare function middlewareInfo(middleware: MiddlewareFn | ParsedGlobalMiddleware | ParsedNamedMiddleware): Promise<MiddlewareHandlerInfo>;
55
+ /**
56
+ * Returns the info about a route handler. In case of lazy imports, the method
57
+ * will return the import path.
58
+ */
59
+ export declare function routeInfo(route: RouteJSON): Promise<RouteHandlerInfo>;
@@ -0,0 +1,18 @@
1
+ import {
2
+ default as default2,
3
+ default2 as default3,
4
+ matchRoute,
5
+ middlewareInfo,
6
+ parseRoute,
7
+ routeInfo,
8
+ serializeCookie
9
+ } from "../chunk-ASX56VAK.js";
10
+ export {
11
+ default2 as encodeUrl,
12
+ matchRoute,
13
+ middlewareInfo,
14
+ default3 as mime,
15
+ parseRoute,
16
+ routeInfo,
17
+ serializeCookie
18
+ };
@@ -1,9 +1,9 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Logger } from '@adonisjs/logger';
3
- import { ContainerResolver } from '@adonisjs/fold';
3
+ import { type ContainerResolver } from '@adonisjs/fold';
4
4
  import type { Request } from '../request.js';
5
5
  import type { Response } from '../response.js';
6
- import type { StoreRouteNode } from '../types/route.js';
6
+ import type { RouteJSON } from '../types/route.js';
7
7
  /**
8
8
  * Http context encapsulates properties for a given HTTP request. The
9
9
  * context class can be extended using macros and getters.
@@ -37,7 +37,7 @@ export declare class HttpContext extends Macroable {
37
37
  * Reference to the current route. Not available inside
38
38
  * server middleware
39
39
  */
40
- route?: StoreRouteNode;
40
+ route?: RouteJSON;
41
41
  /**
42
42
  * A unique key for the current route
43
43
  */
package/build/src/qs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { QSParserConfig } from './types/qs.js';
1
+ import { type QSParserConfig } from './types/qs.js';
2
2
  /**
3
3
  * Query string parser used to parse and stringify query
4
4
  * strings.
@@ -6,6 +6,6 @@ import { QSParserConfig } from './types/qs.js';
6
6
  export declare class Qs {
7
7
  #private;
8
8
  constructor(config: QSParserConfig);
9
- parse(value: string): import("qs").ParsedQs;
10
- stringify(value: any): string;
9
+ parse: (value: string) => import("qs").ParsedQs;
10
+ stringify: (value: any) => string;
11
11
  }
@@ -2,7 +2,8 @@ import type { IncomingMessage } from 'node:http';
2
2
  import type { Qs } from './qs.js';
3
3
  import type { Response } from './response.js';
4
4
  import type { Router } from './router/main.js';
5
- import type { MakeUrlOptions } from './types/route.js';
5
+ import type { GetRoutesForMethod, RoutesList } from './types/route.js';
6
+ import type { RouteBuilderArguments, URLOptions } from './client/types.ts';
6
7
  /**
7
8
  * Exposes the API to construct redirect routes
8
9
  */
@@ -33,7 +34,7 @@ export declare class Redirect {
33
34
  /**
34
35
  * Redirect the request using a route identifier.
35
36
  */
36
- toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
37
+ toRoute<Identifier extends keyof GetRoutesForMethod<'GET'> & string>(...args: RouteBuilderArguments<RoutesList, Identifier, 'GET', URLOptions>): void;
37
38
  /**
38
39
  * Redirect the request using a path.
39
40
  */
@@ -1,9 +1,8 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import { UrlWithStringQuery } from 'node:url';
3
2
  import type { Encryption } from '@adonisjs/encryption';
4
- import { ServerResponse, IncomingMessage, IncomingHttpHeaders } from 'node:http';
3
+ import { type ServerResponse, type IncomingMessage, type IncomingHttpHeaders } from 'node:http';
5
4
  import type { Qs } from './qs.js';
6
- import { RequestConfig } from './types/request.js';
5
+ import { type RequestConfig } from './types/request.js';
7
6
  import type { HttpContext } from './http_context/main.js';
8
7
  /**
9
8
  * HTTP Request class exposes the interface to consistently read values
@@ -19,11 +18,13 @@ export declare class Request extends Macroable {
19
18
  request: IncomingMessage;
20
19
  response: ServerResponse;
21
20
  /**
22
- * Parses copy of the URL with query string as a string and not
23
- * object. This is done to build URL's with query string without
24
- * stringifying the object
21
+ * Parsed URL with query string stored as a string.
25
22
  */
26
- parsedUrl: UrlWithStringQuery;
23
+ parsedUrl: {
24
+ pathname: string;
25
+ query: string;
26
+ shouldDecodeParam: boolean;
27
+ };
27
28
  /**
28
29
  * The ctx will be set by the context itself. It creates a circular
29
30
  * reference
@@ -532,7 +533,7 @@ export declare class Request extends Macroable {
532
533
  serialize(): {
533
534
  id: string | undefined;
534
535
  url: string;
535
- query: string | null;
536
+ query: string;
536
537
  body: Record<string, any>;
537
538
  params: Record<string, any>;
538
539
  headers: IncomingHttpHeaders;
@@ -549,7 +550,7 @@ export declare class Request extends Macroable {
549
550
  toJSON(): {
550
551
  id: string | undefined;
551
552
  url: string;
552
- query: string | null;
553
+ query: string;
553
554
  body: Record<string, any>;
554
555
  params: Record<string, any>;
555
556
  headers: IncomingHttpHeaders;
@@ -1,6 +1,6 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Encryption } from '@adonisjs/encryption';
3
- import { ServerResponse, IncomingMessage } from 'node:http';
3
+ import { type ServerResponse, type IncomingMessage } from 'node:http';
4
4
  import type { Qs } from './qs.js';
5
5
  import { Redirect } from './redirect.js';
6
6
  import type { Router } from './router/main.js';
@@ -2,7 +2,8 @@ import Macroable from '@poppinss/macroable';
2
2
  import type { Application } from '@adonisjs/application';
3
3
  import { Route } from './route.js';
4
4
  import type { ParsedGlobalMiddleware } from '../types/middleware.js';
5
- import type { MakeUrlOptions, RouteFn, RouteMatchers } from '../types/route.js';
5
+ import type { RouteBuilderArguments, URLOptions } from '../client/types.ts';
6
+ import type { GetRoutesForMethod, RouteFn, RouteMatchers, RoutesList } from '../types/route.js';
6
7
  /**
7
8
  * Brisk routes exposes the API to configure the route handler by chaining
8
9
  * one of the pre-defined methods.
@@ -30,9 +31,9 @@ export declare class BriskRoute extends Macroable {
30
31
  * Redirects to a given route. Params from the original request will
31
32
  * be used when no custom params are defined.
32
33
  */
33
- redirect(identifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions & {
34
+ redirect<Identifier extends keyof GetRoutesForMethod<'GET'> & string>(...args: RouteBuilderArguments<RoutesList, Identifier, 'GET', URLOptions & {
34
35
  status: number;
35
- }): Route;
36
+ }>): Route;
36
37
  /**
37
38
  * Redirect request to a fixed URL
38
39
  */
@@ -1,9 +1,9 @@
1
1
  import type { ContainerResolver } from '@adonisjs/fold';
2
- import type { StoreRouteNode } from '../types/route.js';
2
+ import type { RouteJSON } from '../types/route.js';
3
3
  import type { HttpContext } from '../http_context/main.js';
4
4
  import type { ServerErrorHandler } from '../types/server.js';
5
5
  /**
6
6
  * Executor to execute the route middleware pipeline the route
7
7
  * handler
8
8
  */
9
- export declare function execute(route: StoreRouteNode, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): Promise<void>;
9
+ export declare function execute(route: RouteJSON, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): Promise<void>;
@@ -1,4 +1,9 @@
1
- import type { HttpContext } from '../../http_context/main.js';
1
+ import { type HttpContext } from '../../http_context/main.js';
2
+ /**
3
+ * Check if the value can be used to write the response body. Returns
4
+ * false when the response body has already been set
5
+ */
6
+ export declare function canWriteResponseBody(value: any, ctx: HttpContext): boolean;
2
7
  /**
3
8
  * A factory function that uses the return value of the request
4
9
  * pipeline as the response
@@ -1,10 +1,10 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import type { RouteMatcher } from '../types/route.js';
3
- import type { MiddlewareFn, ParsedNamedMiddleware } from '../types/middleware.js';
4
- import { Route } from './route.js';
2
+ import type { OneOrMore } from '@poppinss/utils/types';
3
+ import { type Route } from './route.js';
5
4
  import { BriskRoute } from './brisk.js';
6
5
  import { RouteResource } from './resource.js';
7
- import { OneOrMore } from '../types/base.js';
6
+ import type { RouteMatcher } from '../client/types.ts';
7
+ import type { MiddlewareFn, ParsedNamedMiddleware } from '../types/middleware.js';
8
8
  /**
9
9
  * Group class exposes the API to take action on a group of routes.
10
10
  * The group routes must be pre-defined using the constructor.
@@ -1,6 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- import type { Qs } from '../../qs.js';
3
- import type { RouteFinder } from './route_finder.js';
1
+ import { type Router } from '../main.js';
4
2
  /**
5
3
  * URL builder class is used to create URIs for pre-registered
6
4
  * routes.
@@ -13,37 +11,55 @@ import type { RouteFinder } from './route_finder.js';
13
11
  * .params([category.id])
14
12
  * .make('categories.posts.index')
15
13
  * ```
14
+ *
15
+ * @deprecated
16
+ * Instead use "@adonisjs/core/services/url_builder" instead
16
17
  */
17
18
  export declare class UrlBuilder {
18
19
  #private;
19
- constructor(encryption: Encryption, routeFinder: RouteFinder, qsParser: Qs);
20
+ constructor(router: Router, domain?: string);
20
21
  /**
21
22
  * Prefix a custom base URL to the final URI
23
+ * @deprecated
24
+ * Instead use "@adonisjs/core/services/url_builder" instead
22
25
  */
23
26
  prefixUrl(url: string): this;
24
27
  /**
25
28
  * Disable route lookup. Calling this method considers
26
29
  * the "identifier" as the route pattern
30
+ * @deprecated
31
+ * Instead use "@adonisjs/core/services/url_builder" instead
27
32
  */
28
33
  disableRouteLookup(): this;
29
34
  /**
30
35
  * Append query string to the final URI
36
+ * @deprecated
37
+ * Instead use "@adonisjs/core/services/url_builder" instead
31
38
  */
32
39
  qs(queryString?: Record<string, any>): this;
33
40
  /**
34
41
  * Specify params to apply to the route pattern
42
+ * @deprecated
43
+ * Instead use "@adonisjs/core/services/url_builder" instead
35
44
  */
36
45
  params(params?: any[] | Record<string, any>): this;
37
46
  /**
38
47
  * Generate URL for the given route identifier. The identifier can be the
39
48
  * route name, controller.method name or the route pattern
40
49
  * itself.
50
+ *
51
+ * @deprecated
52
+ * Instead use "@adonisjs/core/services/url_builder" instead
41
53
  */
42
54
  make(identifier: string): string;
43
55
  /**
44
56
  * Generate a signed URL for the given route identifier. The identifier can be the
45
57
  * route name, controller.method name or the route pattern
46
58
  * itself.
59
+ *
60
+ * @deprecated
61
+ * Instead use "@adonisjs/core/services/url_builder" instead
62
+ *
47
63
  */
48
64
  makeSigned(identifier: string, options?: {
49
65
  expiresIn?: string | number;
@@ -1,15 +1,17 @@
1
1
  import type { Encryption } from '@adonisjs/encryption';
2
2
  import type { Application } from '@adonisjs/application';
3
+ import type { Constructor, LazyImport } from '@poppinss/utils/types';
3
4
  import type { Qs } from '../qs.js';
4
5
  import { Route } from './route.js';
5
6
  import { RouteGroup } from './group.js';
6
7
  import { BriskRoute } from './brisk.js';
7
8
  import { RouteResource } from './resource.js';
8
- import { LookupStore } from './lookup_store/main.js';
9
+ import { RouterClient } from '../client/router.ts';
10
+ import { UrlBuilder } from './legacy/url_builder.js';
9
11
  import { RouteMatchers as Matchers } from './matchers.js';
10
- import type { Constructor, LazyImport } from '../types/base.js';
11
12
  import type { MiddlewareAsClass, ParsedGlobalMiddleware } from '../types/middleware.js';
12
- import type { RouteFn, MatchedRoute, RouteMatcher, RouteMatchers, MakeUrlOptions, MakeSignedUrlOptions, GetControllerHandlers } from '../types/route.js';
13
+ import type { RouteFn, RouteJSON, RoutesList, MatchedRoute, RouteMatchers, MakeUrlOptions, MakeSignedUrlOptions, GetControllerHandlers } from '../types/route.js';
14
+ import { type UrlFor, type LookupList, type SignedURLOptions, type RouteMatcher, type MatchItRouteToken } from '../client/types.ts';
13
15
  /**
14
16
  * Router class exposes a unified API to register new routes, group them or
15
17
  * create route resources.
@@ -22,13 +24,8 @@ import type { RouteFn, MatchedRoute, RouteMatcher, RouteMatchers, MakeUrlOptions
22
24
  * })
23
25
  * ```
24
26
  */
25
- export declare class Router extends LookupStore {
27
+ export declare class Router extends RouterClient<RouteJSON> {
26
28
  #private;
27
- /**
28
- * Collection of routes, including route resource and route
29
- * group. To get a flat list of routes, call `router.toJSON()`
30
- */
31
- routes: (Route | RouteResource | RouteGroup | BriskRoute)[];
32
29
  /**
33
30
  * A flag to know if routes for explicit domains have been registered.
34
31
  * The boolean is computed after calling the "commit" method.
@@ -44,11 +41,26 @@ export declare class Router extends LookupStore {
44
41
  * have no impact
45
42
  */
46
43
  get commited(): boolean;
44
+ /**
45
+ * Query string parser for making URLs
46
+ */
47
+ qs: Qs;
48
+ /**
49
+ * The URLBuilder offers a type-safe API for creating URL for pre-registered
50
+ * routes or the route patterns.
51
+ *
52
+ * We recommend using the URLBuilder over the "makeUrl" and "makeSignedUrl"
53
+ * methods.
54
+ */
55
+ urlBuilder: {
56
+ urlFor: UrlFor<RoutesList extends LookupList ? RoutesList : never>;
57
+ signedUrlFor: UrlFor<RoutesList extends LookupList ? RoutesList : never, SignedURLOptions>;
58
+ };
47
59
  constructor(app: Application<any>, encryption: Encryption, qsParser: Qs);
48
60
  /**
49
61
  * Parses the route pattern
50
62
  */
51
- parsePattern(pattern: string, matchers?: RouteMatchers): import("../types/route.js").MatchItRouteToken[];
63
+ parsePattern(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
52
64
  /**
53
65
  * Define an array of middleware to use on all the routes.
54
66
  * Calling this method multiple times pushes to the
@@ -60,8 +72,9 @@ export declare class Router extends LookupStore {
60
72
  * not registered anywhere, but instead converted in a new collection
61
73
  * of functions you can apply on the routes, or router groups.
62
74
  */
63
- named<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends import("../types/middleware.js").GetMiddlewareArgs<import("../types/base.js").UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
75
+ named<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends import("../types/middleware.js").GetMiddlewareArgs<import("@poppinss/utils/types").UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
64
76
  name: K;
77
+ reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
65
78
  args: Args[0];
66
79
  handle: ParsedGlobalMiddleware["handle"];
67
80
  }; };
@@ -120,16 +133,43 @@ export declare class Router extends LookupStore {
120
133
  * commit method is called.
121
134
  */
122
135
  commit(): void;
136
+ /**
137
+ * Generates types for the URL builder. These types must
138
+ * be written inside a file for the URL builder to
139
+ * pick them up.
140
+ */
141
+ generateTypes(indentation?: number): string;
142
+ generateClient(): string;
123
143
  /**
124
144
  * Find route for a given URL, method and optionally domain
125
145
  */
126
- match(url: string, method: string, hostname?: string | null): null | MatchedRoute;
146
+ match(uri: string, method: string, shouldDecodeParam: boolean, hostname?: string | null): null | MatchedRoute;
147
+ /**
148
+ * Create URL builder instance.
149
+ * @deprecated
150
+ *
151
+ * Instead use "@adonisjs/core/services/url_builder" instead
152
+ */
153
+ builder(): UrlBuilder;
154
+ /**
155
+ * Create URL builder instance for a given domain.
156
+ * @deprecated
157
+ *
158
+ * Instead use "@adonisjs/core/services/url_builder"
159
+ */
160
+ builderForDomain(domain: string): UrlBuilder;
127
161
  /**
128
162
  * Make URL to a pre-registered route
163
+ *
164
+ * @deprecated
165
+ * Instead use "@adonisjs/core/services/url_builder"
129
166
  */
130
167
  makeUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): string;
131
168
  /**
132
169
  * Makes a signed URL to a pre-registered route.
170
+ *
171
+ * @deprecated
172
+ * Instead use "@adonisjs/core/services/url_builder"
133
173
  */
134
174
  makeSignedUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeSignedUrlOptions): string;
135
175
  }
@@ -1,9 +1,10 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Application } from '@adonisjs/application';
3
+ import type { Constructor, LazyImport, OneOrMore } from '@poppinss/utils/types';
3
4
  import { Route } from './route.js';
4
- import type { Constructor, LazyImport, OneOrMore } from '../types/base.js';
5
- import type { MiddlewareFn, ParsedGlobalMiddleware, ParsedNamedMiddleware } from '../types/middleware.js';
6
- import type { ResourceActionNames, RouteMatcher, RouteMatchers } from '../types/route.js';
5
+ import { type RouteMatcher } from '../client/types.ts';
6
+ import type { ResourceActionNames, RouteMatchers } from '../types/route.js';
7
+ import type { MiddlewareFn, ParsedNamedMiddleware, ParsedGlobalMiddleware } from '../types/middleware.js';
7
8
  /**
8
9
  * Route resource exposes the API to register multiple routes for a resource.
9
10
  */
@@ -1,8 +1,9 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Application } from '@adonisjs/application';
3
- import type { Constructor, LazyImport, OneOrMore } from '../types/base.js';
3
+ import type { Constructor, LazyImport, OneOrMore } from '@poppinss/utils/types';
4
+ import { type RouteMatcher } from '../client/types.ts';
4
5
  import type { MiddlewareFn, ParsedNamedMiddleware, ParsedGlobalMiddleware } from '../types/middleware.js';
5
- import type { GetControllerHandlers, RouteFn, RouteJSON, RouteMatcher, RouteMatchers, StoreRouteMiddleware } from '../types/route.js';
6
+ import type { RouteFn, RouteJSON, RouteMatchers, StoreRouteMiddleware, GetControllerHandlers } from '../types/route.js';
6
7
  /**
7
8
  * The route class exposes the APIs for constructing a route using the
8
9
  * fluent API.
@@ -0,0 +1,14 @@
1
+ import type { Encryption } from '@adonisjs/encryption';
2
+ import { type RouterClient } from '../client/router.ts';
3
+ import { type UrlFor, type LookupList, type ClientRouteJSON, type SignedURLOptions, type MatchItRouteToken } from '../client/types.ts';
4
+ /**
5
+ * Makes signed URL for a given route pattern. The route pattern could be an
6
+ * identifier or an array of tokens.
7
+ */
8
+ export declare function createSignedURL(identifier: string, tokens: MatchItRouteToken[], searchParamsStringifier: (qs: Record<string, any>) => string, encryption: Encryption, params?: any[] | {
9
+ [param: string]: any;
10
+ }, options?: SignedURLOptions): string;
11
+ /**
12
+ * Creates the URLBuilder helper for making signed URLs
13
+ */
14
+ export declare function createSignedUrlBuilder<Routes extends LookupList>(router: RouterClient<ClientRouteJSON>, encryption: Encryption, searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes, SignedURLOptions>;
@@ -1,4 +1,5 @@
1
- import type { RouteJSON, MatchedRoute, StoreRoutesTree, MatchItRouteToken } from '../types/route.js';
1
+ import type { RouteJSON, MatchedRoute, StoreRoutesTree } from '../types/route.js';
2
+ import { type MatchItRouteToken } from '../client/types.ts';
2
3
  /**
3
4
  * Store class is used to store a list of routes, along side with their tokens
4
5
  * to match the URLs.
@@ -55,7 +56,7 @@ export declare class RoutesStore {
55
56
  * qualified runtime domain. You must call `matchDomain` first to fetch
56
57
  * the pattern for qualified domain
57
58
  */
58
- match(url: string, method: string, domain?: {
59
+ match(url: string, method: string, shouldDecodeParam: boolean, domain?: {
59
60
  tokens: MatchItRouteToken[];
60
61
  hostname: string;
61
62
  }): null | MatchedRoute;
@@ -1,8 +1,8 @@
1
- import type { NextFn } from '@poppinss/middleware/types';
2
1
  import type { ContainerResolver } from '@adonisjs/fold';
2
+ import type { NextFn } from '@poppinss/middleware/types';
3
3
  import type { HttpContext } from '../../http_context/main.js';
4
- import { ParsedGlobalMiddleware } from '../../types/middleware.js';
4
+ import { type ParsedGlobalMiddleware } from '../../types/middleware.js';
5
5
  /**
6
6
  * The middleware handler invokes the middleware functions.
7
7
  */
8
- export declare function middlewareHandler(resolver: ContainerResolver<any>, ctx: HttpContext): (fn: ParsedGlobalMiddleware, next: NextFn) => any;
8
+ export declare function middlewareHandler(resolver: ContainerResolver<any>, ctx: HttpContext): (fn: ParsedGlobalMiddleware, next: NextFn) => Promise<any>;
@@ -3,8 +3,8 @@ import type { Router } from '../../router/main.js';
3
3
  import type { HttpContext } from '../../http_context/main.js';
4
4
  import type { ServerErrorHandler } from '../../types/server.js';
5
5
  /**
6
- * The final handler is executed after the server middleware stack.
6
+ * The route finder is executed after the server middleware stack.
7
7
  * It looks for a matching route and executes the route middleware
8
8
  * stack.
9
9
  */
10
- export declare function finalHandler(router: Router, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): () => any;
10
+ export declare function routeFinder(router: Router, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): () => any;