@adonisjs/http-server 7.0.0-0 → 7.0.0-2
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.
- package/build/{chunk-XX72ATFY.js → chunk-Z63E3STR.js} +66 -18
- package/build/chunk-Z63E3STR.js.map +1 -0
- package/build/factories/http_context.d.ts +25 -0
- package/build/factories/http_server.d.ts +8 -0
- package/build/factories/main.d.ts +6 -149
- package/build/factories/main.js +2 -1
- package/build/factories/main.js.map +1 -0
- package/build/factories/qs_parser_factory.d.ts +20 -0
- package/build/factories/request.d.ts +29 -0
- package/build/factories/response.d.ts +29 -0
- package/build/factories/router.d.ts +23 -0
- package/build/factories/server_factory.d.ts +29 -0
- package/build/index.d.ts +14 -272
- package/build/index.js +2 -1
- package/build/index.js.map +1 -0
- package/build/src/cookies/client.d.ts +37 -0
- package/build/src/cookies/drivers/encrypted.d.ts +16 -0
- package/build/src/cookies/drivers/plain.d.ts +15 -0
- package/build/src/cookies/drivers/signed.d.ts +16 -0
- package/build/src/cookies/parser.d.ts +37 -0
- package/build/src/cookies/serializer.d.ts +33 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/define_config.d.ts +9 -0
- package/build/src/define_middleware.d.ts +11 -0
- package/build/src/exception_handler.d.ts +113 -0
- package/build/src/exceptions.d.ts +84 -0
- package/build/src/helpers.d.ts +23 -0
- package/build/src/http_context/local_storage.d.ts +12 -0
- package/build/src/http_context/main.d.ts +58 -0
- package/build/src/qs.d.ts +11 -0
- package/build/src/redirect.d.ts +42 -0
- package/build/src/request.d.ts +565 -0
- package/build/src/response.d.ts +620 -0
- package/build/src/router/brisk.d.ts +42 -0
- package/build/src/router/executor.d.ts +9 -0
- package/build/src/router/factories/use_return_value.d.ts +6 -0
- package/build/src/router/group.d.ts +65 -0
- package/build/src/router/lookup_store/main.d.ts +47 -0
- package/build/src/router/lookup_store/route_finder.d.ts +25 -0
- package/build/src/router/lookup_store/url_builder.d.ts +52 -0
- package/build/src/router/main.d.ts +128 -0
- package/build/src/router/matchers.d.ts +27 -0
- package/build/src/router/parser.d.ts +5 -0
- package/build/src/router/resource.d.ts +66 -0
- package/build/src/router/route.d.ts +92 -0
- package/build/src/router/store.d.ts +66 -0
- package/build/src/server/factories/final_handler.d.ts +10 -0
- package/build/src/server/factories/middleware_handler.d.ts +8 -0
- package/build/src/server/factories/write_response.d.ts +6 -0
- package/build/{main-29eaaee4.d.ts → src/server/main.d.ts} +18 -13
- package/build/src/types/base.d.ts +19 -0
- package/build/src/types/main.d.ts +7 -14
- package/build/src/types/main.js +1 -0
- package/build/src/types/main.js.map +1 -0
- package/build/src/types/middleware.d.ts +35 -0
- package/build/src/types/qs.d.ts +68 -0
- package/build/src/types/request.d.ts +39 -0
- package/build/src/types/response.d.ts +45 -0
- package/build/src/types/route.d.ts +166 -0
- package/build/src/types/server.d.ts +72 -0
- package/package.json +52 -48
- package/build/main-e5b46c83.d.ts +0 -2210
|
@@ -0,0 +1,65 @@
|
|
|
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';
|
|
5
|
+
import { BriskRoute } from './brisk.js';
|
|
6
|
+
import { RouteResource } from './resource.js';
|
|
7
|
+
import { OneOrMore } from '../types/base.js';
|
|
8
|
+
/**
|
|
9
|
+
* Group class exposes the API to take action on a group of routes.
|
|
10
|
+
* The group routes must be pre-defined using the constructor.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RouteGroup extends Macroable {
|
|
13
|
+
#private;
|
|
14
|
+
routes: (Route | RouteGroup | RouteResource | BriskRoute)[];
|
|
15
|
+
constructor(routes: (Route | RouteGroup | RouteResource | BriskRoute)[]);
|
|
16
|
+
/**
|
|
17
|
+
* Define route param matcher
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* Route.group(() => {
|
|
21
|
+
* }).where('id', /^[0-9]+/)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
25
|
+
/**
|
|
26
|
+
* Define prefix all the routes in the group.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* Route.group(() => {
|
|
30
|
+
* }).prefix('v1')
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
prefix(prefix: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Define domain for all the routes.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* Route.group(() => {
|
|
39
|
+
* }).domain(':name.adonisjs.com')
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
domain(domain: string): this;
|
|
43
|
+
/**
|
|
44
|
+
* Prepend name to the routes name.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* Route.group(() => {
|
|
48
|
+
* }).as('version1')
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
as(name: string): this;
|
|
52
|
+
/**
|
|
53
|
+
* Prepend an array of middleware to all routes middleware.
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* Route.group(() => {
|
|
57
|
+
* }).use(middleware.auth())
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
61
|
+
/**
|
|
62
|
+
* @alias use
|
|
63
|
+
*/
|
|
64
|
+
middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
65
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
import type { Qs } from '../../qs.js';
|
|
3
|
+
import { UrlBuilder } from './url_builder.js';
|
|
4
|
+
import type { RouteJSON } from '../../types/route.js';
|
|
5
|
+
/**
|
|
6
|
+
* Lookup store exposes the API to lookup routes and
|
|
7
|
+
* make URLs for registered routes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LookupStore {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(encryption: Encryption, qsParser: Qs);
|
|
12
|
+
/**
|
|
13
|
+
* Register route JSON payload
|
|
14
|
+
*/
|
|
15
|
+
register(route: RouteJSON): void;
|
|
16
|
+
/**
|
|
17
|
+
* Returns an instance of the URL builder for making
|
|
18
|
+
* route URIs
|
|
19
|
+
*/
|
|
20
|
+
builder(): UrlBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* Returns an instance of the URL builder for a specific
|
|
23
|
+
* domain.
|
|
24
|
+
*/
|
|
25
|
+
builderForDomain(domain: string): UrlBuilder;
|
|
26
|
+
/**
|
|
27
|
+
* Finds a route by its identifier. The identifier can be the
|
|
28
|
+
* route name, controller.method name or the route pattern
|
|
29
|
+
* itself.
|
|
30
|
+
*/
|
|
31
|
+
find(routeIdentifier: string, domain?: string): RouteJSON | null;
|
|
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
|
+
* An error is raised when unable to find the route.
|
|
38
|
+
*/
|
|
39
|
+
findOrFail(routeIdentifier: string, domain?: string): RouteJSON;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a route exists. The identifier can be the
|
|
42
|
+
* route name, controller.method name or the route pattern
|
|
43
|
+
* itself.
|
|
44
|
+
*/
|
|
45
|
+
has(routeIdentifier: string, domain?: string): boolean;
|
|
46
|
+
toJSON(): Record<string, RouteJSON[]>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RouteJSON } from '../../types/route.js';
|
|
2
|
+
/**
|
|
3
|
+
* Route finder is used to find a route by its name, route pattern
|
|
4
|
+
* or the controller.method name.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RouteFinder {
|
|
7
|
+
#private;
|
|
8
|
+
register(route: RouteJSON): void;
|
|
9
|
+
/**
|
|
10
|
+
* Find a route by indentifier
|
|
11
|
+
*/
|
|
12
|
+
find(routeIdentifier: string): RouteJSON | null;
|
|
13
|
+
/**
|
|
14
|
+
* Find a route by indentifier or fail
|
|
15
|
+
*/
|
|
16
|
+
findOrFail(routeIdentifier: string): RouteJSON;
|
|
17
|
+
/**
|
|
18
|
+
* Find if a route exists
|
|
19
|
+
*/
|
|
20
|
+
has(routeIdentifier: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Returns an array of registered routes
|
|
23
|
+
*/
|
|
24
|
+
toJSON(): RouteJSON[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
import type { Qs } from '../../qs.js';
|
|
3
|
+
import type { RouteFinder } from './route_finder.js';
|
|
4
|
+
/**
|
|
5
|
+
* URL builder class is used to create URIs for pre-registered
|
|
6
|
+
* routes.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const builder = new UrlBuilder(encryption, routeFinder)
|
|
10
|
+
*
|
|
11
|
+
* builder
|
|
12
|
+
* .qs({ sort: 'id' })
|
|
13
|
+
* .params([category.id])
|
|
14
|
+
* .make('categories.posts.index')
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class UrlBuilder {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(encryption: Encryption, routeFinder: RouteFinder, qsParser: Qs);
|
|
20
|
+
/**
|
|
21
|
+
* Prefix a custom base URL to the final URI
|
|
22
|
+
*/
|
|
23
|
+
prefixUrl(url: string): this;
|
|
24
|
+
/**
|
|
25
|
+
* Disable route lookup. Calling this method considers
|
|
26
|
+
* the "identifier" as the route pattern
|
|
27
|
+
*/
|
|
28
|
+
disableRouteLookup(): this;
|
|
29
|
+
/**
|
|
30
|
+
* Append query string to the final URI
|
|
31
|
+
*/
|
|
32
|
+
qs(queryString?: Record<string, any>): this;
|
|
33
|
+
/**
|
|
34
|
+
* Specify params to apply to the route pattern
|
|
35
|
+
*/
|
|
36
|
+
params(params?: any[] | Record<string, any>): this;
|
|
37
|
+
/**
|
|
38
|
+
* Generate URL for the given route identifier. The identifier can be the
|
|
39
|
+
* route name, controller.method name or the route pattern
|
|
40
|
+
* itself.
|
|
41
|
+
*/
|
|
42
|
+
make(identifier: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Generate a signed URL for the given route identifier. The identifier can be the
|
|
45
|
+
* route name, controller.method name or the route pattern
|
|
46
|
+
* itself.
|
|
47
|
+
*/
|
|
48
|
+
makeSigned(identifier: string, options?: {
|
|
49
|
+
expiresIn?: string | number;
|
|
50
|
+
purpose?: string;
|
|
51
|
+
}): string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
import type { Application } from '@adonisjs/application';
|
|
3
|
+
import type { Qs } from '../qs.js';
|
|
4
|
+
import { Route } from './route.js';
|
|
5
|
+
import { RouteGroup } from './group.js';
|
|
6
|
+
import { BriskRoute } from './brisk.js';
|
|
7
|
+
import { RouteResource } from './resource.js';
|
|
8
|
+
import { LookupStore } from './lookup_store/main.js';
|
|
9
|
+
import { RouteMatchers as Matchers } from './matchers.js';
|
|
10
|
+
import type { Constructor, LazyImport } from '../types/base.js';
|
|
11
|
+
import type { MiddlewareAsClass, ParsedGlobalMiddleware } from '../types/middleware.js';
|
|
12
|
+
import type { RouteFn, MatchedRoute, RouteMatcher, RouteMatchers, MakeUrlOptions, MakeSignedUrlOptions, GetControllerHandlers } from '../types/route.js';
|
|
13
|
+
/**
|
|
14
|
+
* Router class exposes a unified API to register new routes, group them or
|
|
15
|
+
* create route resources.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const router = new Router()
|
|
19
|
+
*
|
|
20
|
+
* router.get('/', async function () {
|
|
21
|
+
* // handle request
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class Router extends LookupStore {
|
|
26
|
+
#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
|
+
/**
|
|
33
|
+
* A flag to know if routes for explicit domains have been registered.
|
|
34
|
+
* The boolean is computed after calling the "commit" method.
|
|
35
|
+
*/
|
|
36
|
+
usingDomains: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Shortcut methods for commonly used route matchers
|
|
39
|
+
*/
|
|
40
|
+
matchers: Matchers;
|
|
41
|
+
constructor(app: Application<any>, encryption: Encryption, qsParser: Qs);
|
|
42
|
+
/**
|
|
43
|
+
* Parses the route pattern
|
|
44
|
+
*/
|
|
45
|
+
parsePattern(pattern: string, matchers?: RouteMatchers): import("../types/route.js").MatchItRouteToken[];
|
|
46
|
+
/**
|
|
47
|
+
* Define an array of middleware to use on all the routes.
|
|
48
|
+
* Calling this method multiple times pushes to the
|
|
49
|
+
* existing list of middleware
|
|
50
|
+
*/
|
|
51
|
+
use(middleware: LazyImport<MiddlewareAsClass>[]): this;
|
|
52
|
+
/**
|
|
53
|
+
* Define a collection of named middleware. The defined collection is
|
|
54
|
+
* not registered anywhere, but instead converted in a new collection
|
|
55
|
+
* of functions you can apply on the routes, or router groups.
|
|
56
|
+
*/
|
|
57
|
+
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) => {
|
|
58
|
+
name: K;
|
|
59
|
+
args: Args[0];
|
|
60
|
+
} & ParsedGlobalMiddleware; };
|
|
61
|
+
/**
|
|
62
|
+
* Add route for a given pattern and methods
|
|
63
|
+
*/
|
|
64
|
+
route<T extends Constructor<any>>(pattern: string, methods: string[], handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Define a route that handles all common HTTP methods
|
|
67
|
+
*/
|
|
68
|
+
any<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Define `GET` route
|
|
71
|
+
*/
|
|
72
|
+
get<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Define `POST` route
|
|
75
|
+
*/
|
|
76
|
+
post<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
77
|
+
/**
|
|
78
|
+
* Define `PUT` route
|
|
79
|
+
*/
|
|
80
|
+
put<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Define `PATCH` route
|
|
83
|
+
*/
|
|
84
|
+
patch<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Define `DELETE` route
|
|
87
|
+
*/
|
|
88
|
+
delete<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a group of routes. A route group can apply transforms
|
|
91
|
+
* to routes in bulk
|
|
92
|
+
*/
|
|
93
|
+
group(callback: () => void): RouteGroup;
|
|
94
|
+
/**
|
|
95
|
+
* Registers a route resource with conventional set of routes
|
|
96
|
+
*/
|
|
97
|
+
resource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource<import("../types/route.js").ResourceActionNames>;
|
|
98
|
+
/**
|
|
99
|
+
* Register a route resource with shallow nested routes.
|
|
100
|
+
*/
|
|
101
|
+
shallowResource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource<import("../types/route.js").ResourceActionNames>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a brisk route instance for a given URL pattern
|
|
104
|
+
*/
|
|
105
|
+
on(pattern: string): BriskRoute;
|
|
106
|
+
/**
|
|
107
|
+
* Define matcher for a given param. The global params are applied
|
|
108
|
+
* on all the routes (unless overridden at the route level).
|
|
109
|
+
*/
|
|
110
|
+
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
111
|
+
/**
|
|
112
|
+
* Commit routes to the store. The router is freezed after the
|
|
113
|
+
* commit method is called.
|
|
114
|
+
*/
|
|
115
|
+
commit(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Find route for a given URL, method and optionally domain
|
|
118
|
+
*/
|
|
119
|
+
match(url: string, method: string, hostname?: string | null): null | MatchedRoute;
|
|
120
|
+
/**
|
|
121
|
+
* Make URL to a pre-registered route
|
|
122
|
+
*/
|
|
123
|
+
makeUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): string;
|
|
124
|
+
/**
|
|
125
|
+
* Makes a signed URL to a pre-registered route.
|
|
126
|
+
*/
|
|
127
|
+
makeSignedUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeSignedUrlOptions): string;
|
|
128
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Macroable from '@poppinss/macroable';
|
|
2
|
+
import type { Application } from '@adonisjs/application';
|
|
3
|
+
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';
|
|
7
|
+
/**
|
|
8
|
+
* Route resource exposes the API to register multiple routes for a resource.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RouteResource<ActionNames extends ResourceActionNames = ResourceActionNames> 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<Name extends ActionNames>(names: Name[]): RouteResource<Name>;
|
|
26
|
+
/**
|
|
27
|
+
* Register all routes, except the one's defined
|
|
28
|
+
*/
|
|
29
|
+
except<Name extends ActionNames>(names: Name[]): RouteResource<Exclude<ActionNames, Name>>;
|
|
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(): RouteResource<Exclude<ActionNames, 'create' | 'edit'>>;
|
|
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: ActionNames | ActionNames[], 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
|
+
* Define one or more middleware on the routes created by
|
|
52
|
+
* the resource.
|
|
53
|
+
*
|
|
54
|
+
* Calling this method multiple times will append middleware
|
|
55
|
+
* to existing list.
|
|
56
|
+
*/
|
|
57
|
+
use(actions: ActionNames | ActionNames[] | '*', middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
58
|
+
/**
|
|
59
|
+
* @alias use
|
|
60
|
+
*/
|
|
61
|
+
middleware(actions: ActionNames | ActionNames[] | '*', middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
62
|
+
/**
|
|
63
|
+
* Prepend name to all the routes
|
|
64
|
+
*/
|
|
65
|
+
as(name: string, normalizeName?: boolean): this;
|
|
66
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { RouteJSON, MatchedRoute, StoreRoutesTree, MatchItRouteToken } from '../types/route.js';
|
|
2
|
+
/**
|
|
3
|
+
* Store class is used to store a list of routes, along side with their tokens
|
|
4
|
+
* to match the URLs.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const store = new Store()
|
|
8
|
+
*
|
|
9
|
+
* store.add({
|
|
10
|
+
* pattern: 'posts/:id',
|
|
11
|
+
* handler: function onRoute () {},
|
|
12
|
+
* middleware: [],
|
|
13
|
+
* matchers: {
|
|
14
|
+
* id: '^[0-9]$+'
|
|
15
|
+
* },
|
|
16
|
+
* meta: {},
|
|
17
|
+
* methods: ['GET']
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* store.match('posts/1', 'GET')
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class RoutesStore {
|
|
24
|
+
#private;
|
|
25
|
+
/**
|
|
26
|
+
* A flag to know if routes for explicit domains
|
|
27
|
+
* have been registered
|
|
28
|
+
*/
|
|
29
|
+
usingDomains: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Tree of registered routes and their matchit tokens
|
|
32
|
+
*/
|
|
33
|
+
tree: StoreRoutesTree;
|
|
34
|
+
/**
|
|
35
|
+
* Add a route to the store
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* store.add({
|
|
39
|
+
* pattern: 'post/:id',
|
|
40
|
+
* methods: ['GET'],
|
|
41
|
+
* matchers: {},
|
|
42
|
+
* meta: {},
|
|
43
|
+
* handler: function handler () {
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
add(route: RouteJSON): this;
|
|
49
|
+
/**
|
|
50
|
+
* Matches the url, method and optionally domain to pull the matching
|
|
51
|
+
* route. `null` is returned when unable to match the URL against
|
|
52
|
+
* registered routes.
|
|
53
|
+
*
|
|
54
|
+
* The domain parameter has to be a registered pattern and not the fully
|
|
55
|
+
* qualified runtime domain. You must call `matchDomain` first to fetch
|
|
56
|
+
* the pattern for qualified domain
|
|
57
|
+
*/
|
|
58
|
+
match(url: string, method: string, domain?: {
|
|
59
|
+
tokens: MatchItRouteToken[];
|
|
60
|
+
hostname: string;
|
|
61
|
+
}): null | MatchedRoute;
|
|
62
|
+
/**
|
|
63
|
+
* Match hostname against registered domains.
|
|
64
|
+
*/
|
|
65
|
+
matchDomain(hostname?: string | null): MatchItRouteToken[];
|
|
66
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContainerResolver } from '@adonisjs/fold';
|
|
2
|
+
import type { Router } from '../../router/main.js';
|
|
3
|
+
import type { HttpContext } from '../../http_context/main.js';
|
|
4
|
+
import type { ServerErrorHandler } from '../../types/server.js';
|
|
5
|
+
/**
|
|
6
|
+
* The final handler is executed after the server middleware stack.
|
|
7
|
+
* It looks for a matching route and executes the route middleware
|
|
8
|
+
* stack.
|
|
9
|
+
*/
|
|
10
|
+
export declare function finalHandler(router: Router, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): () => any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NextFn } from '@poppinss/middleware/types';
|
|
2
|
+
import type { ContainerResolver } from '@adonisjs/fold';
|
|
3
|
+
import type { HttpContext } from '../../http_context/main.js';
|
|
4
|
+
import { ParsedGlobalMiddleware } from '../../types/middleware.js';
|
|
5
|
+
/**
|
|
6
|
+
* The middleware handler invokes the middleware functions.
|
|
7
|
+
*/
|
|
8
|
+
export declare function middlewareHandler(resolver: ContainerResolver<any>, ctx: HttpContext): (fn: ParsedGlobalMiddleware, next: NextFn) => any;
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Logger } from '@adonisjs/logger';
|
|
4
|
+
import type { Emitter } from '@adonisjs/events';
|
|
5
|
+
import type { Encryption } from '@adonisjs/encryption';
|
|
6
|
+
import type { Server as HttpsServer } from 'node:https';
|
|
7
|
+
import type { Application } from '@adonisjs/application';
|
|
6
8
|
import { ContainerResolver } from '@adonisjs/fold';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
9
|
+
import type { ServerResponse, IncomingMessage, Server as HttpServer } from 'node:http';
|
|
10
|
+
import type { LazyImport } from '../types/base.js';
|
|
11
|
+
import type { MiddlewareAsClass } from '../types/middleware.js';
|
|
12
|
+
import type { ServerConfig, ErrorHandlerAsAClass, TestingMiddlewarePipeline } from '../types/server.js';
|
|
13
|
+
import { Request } from '../request.js';
|
|
14
|
+
import { Response } from '../response.js';
|
|
15
|
+
import { Router } from '../router/main.js';
|
|
16
|
+
import { HttpContext } from '../http_context/main.js';
|
|
10
17
|
/**
|
|
11
18
|
* The HTTP server implementation to handle incoming requests and respond using the
|
|
12
19
|
* registered routes.
|
|
13
20
|
*/
|
|
14
|
-
declare class Server {
|
|
21
|
+
export declare class Server {
|
|
15
22
|
#private;
|
|
16
23
|
/**
|
|
17
24
|
* Know if async local storage is enabled or not.
|
|
@@ -43,12 +50,12 @@ declare class Server {
|
|
|
43
50
|
/**
|
|
44
51
|
* Set the HTTP server instance used to listen for requests.
|
|
45
52
|
*/
|
|
46
|
-
setNodeServer(server:
|
|
53
|
+
setNodeServer(server: HttpServer | HttpsServer): void;
|
|
47
54
|
/**
|
|
48
55
|
* Returns reference to the underlying HTTP server
|
|
49
56
|
* in use
|
|
50
57
|
*/
|
|
51
|
-
getNodeServer():
|
|
58
|
+
getNodeServer(): HttpServer<typeof IncomingMessage, typeof ServerResponse> | HttpsServer<typeof IncomingMessage, typeof ServerResponse> | undefined;
|
|
52
59
|
/**
|
|
53
60
|
* Returns reference to the router instance used
|
|
54
61
|
* by the server.
|
|
@@ -71,5 +78,3 @@ declare class Server {
|
|
|
71
78
|
*/
|
|
72
79
|
handle(req: IncomingMessage, res: ServerResponse): Promise<any>;
|
|
73
80
|
}
|
|
74
|
-
|
|
75
|
-
export { Server as S };
|