@adonisjs/http-server 5.12.0 → 6.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -38
- package/build/index.d.ts +16 -0
- package/build/index.js +16 -0
- package/build/src/cookies/client.d.ts +12 -0
- package/build/src/cookies/client.js +42 -0
- package/build/src/cookies/drivers/encrypted.d.ts +4 -0
- package/build/src/cookies/drivers/encrypted.js +16 -0
- package/build/src/cookies/drivers/plain.d.ts +3 -0
- package/build/src/cookies/drivers/plain.js +13 -0
- package/build/src/cookies/drivers/signed.d.ts +4 -0
- package/build/src/cookies/drivers/signed.js +16 -0
- package/build/src/cookies/parser.d.ts +9 -0
- package/build/src/cookies/parser.js +69 -0
- package/build/src/cookies/serializer.d.ts +11 -0
- package/build/src/cookies/serializer.js +39 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +2 -0
- package/build/src/define_config.d.ts +2 -0
- package/build/src/define_config.js +40 -0
- package/build/src/define_middleware.d.ts +4 -0
- package/build/src/define_middleware.js +6 -0
- package/build/src/exceptions/abort_exception.d.ts +5 -0
- package/build/src/exceptions/abort_exception.js +6 -0
- package/build/src/exceptions/cannot_lookup_route.d.ts +5 -0
- package/build/src/exceptions/cannot_lookup_route.js +5 -0
- package/build/src/exceptions/http_exception.d.ts +6 -0
- package/build/src/exceptions/http_exception.js +20 -0
- package/build/src/exceptions/route_not_found.d.ts +5 -0
- package/build/src/exceptions/route_not_found.js +5 -0
- package/build/src/helpers.d.ts +6 -67
- package/build/src/helpers.js +13 -168
- package/build/src/http_context/local_storage.d.ts +9 -0
- package/build/src/http_context/local_storage.js +14 -0
- package/build/src/http_context/main.d.ts +20 -0
- package/build/src/http_context/main.js +49 -0
- package/build/src/middleware/store.d.ts +11 -0
- package/build/src/middleware/store.js +33 -0
- package/build/src/qs.d.ts +7 -0
- package/build/src/qs.js +13 -0
- package/build/src/redirect.d.ts +18 -0
- package/build/src/redirect.js +80 -0
- package/build/src/request.d.ts +81 -0
- package/build/src/request.js +315 -0
- package/build/src/response.d.ts +108 -0
- package/build/src/response.js +587 -0
- package/build/src/router/brisk.d.ts +18 -0
- package/build/src/router/brisk.js +35 -0
- package/build/src/router/executor.d.ts +4 -0
- package/build/src/router/executor.js +16 -0
- package/build/src/router/group.d.ts +19 -0
- package/build/src/router/group.js +117 -0
- package/build/src/router/lookup_store/main.d.ts +17 -0
- package/build/src/router/lookup_store/main.js +37 -0
- package/build/src/router/lookup_store/route_finder.d.ts +8 -0
- package/build/src/router/lookup_store/route_finder.js +28 -0
- package/build/src/router/lookup_store/url_builder.d.ts +16 -0
- package/build/src/router/lookup_store/url_builder.js +111 -0
- package/build/src/router/main.d.ts +36 -0
- package/build/src/router/main.js +161 -0
- package/build/src/router/matchers.d.ts +14 -0
- package/build/src/router/matchers.js +15 -0
- package/build/src/router/resource.d.ts +27 -0
- package/build/src/router/resource.js +124 -0
- package/build/src/router/route.d.ts +28 -0
- package/build/src/router/route.js +135 -0
- package/build/src/router/store.d.ts +12 -0
- package/build/src/router/store.js +87 -0
- package/build/src/server/factories/final_handler.d.ts +4 -0
- package/build/src/server/factories/final_handler.js +17 -0
- package/build/src/server/factories/middleware_handler.d.ts +5 -0
- package/build/src/server/factories/middleware_handler.js +5 -0
- package/build/src/server/factories/use_return_value.d.ts +2 -0
- package/build/src/server/factories/use_return_value.js +9 -0
- package/build/src/server/factories/write_response.d.ts +2 -0
- package/build/src/server/factories/write_response.js +12 -0
- package/build/src/server/main.d.ts +23 -0
- package/build/src/server/main.js +124 -0
- package/build/src/types/base.d.ts +5 -0
- package/build/src/types/base.js +1 -0
- package/build/src/types/middleware.d.ts +14 -0
- package/build/src/types/middleware.js +1 -0
- package/build/src/types/qs.d.ts +15 -0
- package/build/src/types/qs.js +1 -0
- package/build/src/types/request.d.ts +7 -0
- package/build/src/types/request.js +1 -0
- package/build/src/types/response.d.ts +18 -0
- package/build/src/types/response.js +1 -0
- package/build/src/types/route.d.ts +74 -0
- package/build/src/types/route.js +1 -0
- package/build/src/types/server.d.ts +13 -0
- package/build/src/types/server.js +1 -0
- package/package.json +88 -86
- package/build/adonis-typings/container.d.ts +0 -24
- package/build/adonis-typings/container.js +0 -8
- package/build/adonis-typings/context.d.ts +0 -73
- package/build/adonis-typings/context.js +0 -8
- package/build/adonis-typings/cookie-client.d.ts +0 -34
- package/build/adonis-typings/cookie-client.js +0 -8
- package/build/adonis-typings/http-server.d.ts +0 -98
- package/build/adonis-typings/http-server.js +0 -8
- package/build/adonis-typings/index.d.ts +0 -16
- package/build/adonis-typings/index.js +0 -16
- package/build/adonis-typings/middleware.d.ts +0 -95
- package/build/adonis-typings/middleware.js +0 -8
- package/build/adonis-typings/request.d.ts +0 -556
- package/build/adonis-typings/request.js +0 -8
- package/build/adonis-typings/response.d.ts +0 -440
- package/build/adonis-typings/response.js +0 -8
- package/build/adonis-typings/route.d.ts +0 -559
- package/build/adonis-typings/route.js +0 -8
- package/build/exceptions.json +0 -110
- package/build/providers/HttpServerProvider.d.ts +0 -46
- package/build/providers/HttpServerProvider.js +0 -100
- package/build/src/Cookie/Client/index.d.ts +0 -39
- package/build/src/Cookie/Client/index.js +0 -108
- package/build/src/Cookie/Drivers/Encrypted.d.ts +0 -24
- package/build/src/Cookie/Drivers/Encrypted.js +0 -42
- package/build/src/Cookie/Drivers/Plain.d.ts +0 -23
- package/build/src/Cookie/Drivers/Plain.js +0 -40
- package/build/src/Cookie/Drivers/Signed.d.ts +0 -24
- package/build/src/Cookie/Drivers/Signed.js +0 -42
- package/build/src/Cookie/Parser/index.d.ts +0 -61
- package/build/src/Cookie/Parser/index.js +0 -174
- package/build/src/Cookie/Serializer/index.d.ts +0 -46
- package/build/src/Cookie/Serializer/index.js +0 -88
- package/build/src/Exceptions/HttpException.d.ts +0 -20
- package/build/src/Exceptions/HttpException.js +0 -36
- package/build/src/Exceptions/RouterException.d.ts +0 -36
- package/build/src/Exceptions/RouterException.js +0 -76
- package/build/src/HttpContext/LocalStorage/index.d.ts +0 -24
- package/build/src/HttpContext/LocalStorage/index.js +0 -28
- package/build/src/HttpContext/index.d.ts +0 -90
- package/build/src/HttpContext/index.js +0 -181
- package/build/src/MiddlewareStore/index.d.ts +0 -92
- package/build/src/MiddlewareStore/index.js +0 -133
- package/build/src/Redirect/index.d.ts +0 -71
- package/build/src/Redirect/index.js +0 -139
- package/build/src/Request/index.d.ts +0 -619
- package/build/src/Request/index.js +0 -862
- package/build/src/Response/index.d.ts +0 -414
- package/build/src/Response/index.js +0 -1010
- package/build/src/Router/BriskRoute.d.ts +0 -53
- package/build/src/Router/BriskRoute.js +0 -74
- package/build/src/Router/Group.d.ts +0 -101
- package/build/src/Router/Group.js +0 -165
- package/build/src/Router/LookupStore.d.ts +0 -122
- package/build/src/Router/LookupStore.js +0 -264
- package/build/src/Router/Matchers.d.ts +0 -31
- package/build/src/Router/Matchers.js +0 -43
- package/build/src/Router/Resource.d.ts +0 -95
- package/build/src/Router/Resource.js +0 -182
- package/build/src/Router/Route.d.ts +0 -138
- package/build/src/Router/Route.js +0 -204
- package/build/src/Router/Store.d.ts +0 -93
- package/build/src/Router/Store.js +0 -211
- package/build/src/Router/index.d.ts +0 -142
- package/build/src/Router/index.js +0 -333
- package/build/src/Server/ExceptionManager/index.d.ts +0 -49
- package/build/src/Server/ExceptionManager/index.js +0 -96
- package/build/src/Server/Hooks/index.d.ts +0 -43
- package/build/src/Server/Hooks/index.js +0 -77
- package/build/src/Server/PreCompiler/index.d.ts +0 -60
- package/build/src/Server/PreCompiler/index.js +0 -143
- package/build/src/Server/RequestHandler/index.d.ts +0 -39
- package/build/src/Server/RequestHandler/index.js +0 -87
- package/build/src/Server/index.d.ts +0 -90
- package/build/src/Server/index.js +0 -175
- package/build/standalone.d.ts +0 -14
- package/build/standalone.js +0 -23
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference path="../../adonis-typings/index.d.ts" />
|
|
10
|
-
import { Macroable } from 'macroable';
|
|
11
|
-
import { RouteJSON, RouteContract, RouteHandler, RouteMatchersNode, RouteParamMatcher, RouteMiddlewareHandler } from '@ioc:Adonis/Core/Route';
|
|
12
|
-
/**
|
|
13
|
-
* Route class is used to construct consistent [[RouteDefinition]] using
|
|
14
|
-
* fluent API. An instance of route is usually obtained using the
|
|
15
|
-
* [[Router]] class helper methods.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const route = new Route('posts/:id', ['GET'], async function () {
|
|
20
|
-
* })
|
|
21
|
-
*
|
|
22
|
-
* route
|
|
23
|
-
* .where('id', /^[0-9]+$/)
|
|
24
|
-
* .middleware(async function () {
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare class Route extends Macroable implements RouteContract {
|
|
29
|
-
private pattern;
|
|
30
|
-
private methods;
|
|
31
|
-
private handler;
|
|
32
|
-
private globalMatchers;
|
|
33
|
-
protected static macros: {};
|
|
34
|
-
protected static getters: {};
|
|
35
|
-
/**
|
|
36
|
-
* By default the route is part of `root` domain. Root
|
|
37
|
-
* domain is used when no domain is defined
|
|
38
|
-
*/
|
|
39
|
-
private routeDomain;
|
|
40
|
-
/**
|
|
41
|
-
* An object of matchers to be forwarded to the
|
|
42
|
-
* store. The matchers list is populated by
|
|
43
|
-
* calling `where` method
|
|
44
|
-
*/
|
|
45
|
-
private matchers;
|
|
46
|
-
/**
|
|
47
|
-
* Custom prefixes. Usually added to a group of routes. We keep an array of them
|
|
48
|
-
* since nested groups will want all of them ot concat.
|
|
49
|
-
*/
|
|
50
|
-
private prefixes;
|
|
51
|
-
/**
|
|
52
|
-
* An array of middleware. Added using `middleware` function
|
|
53
|
-
*/
|
|
54
|
-
private routeMiddleware;
|
|
55
|
-
/**
|
|
56
|
-
* Storing the namespace explicitly set using `route.namespace` method
|
|
57
|
-
*/
|
|
58
|
-
private routeNamespace;
|
|
59
|
-
/**
|
|
60
|
-
* A boolean to prevent route from getting registered within
|
|
61
|
-
* the [[Store]].
|
|
62
|
-
*
|
|
63
|
-
* This flag must be set before [[Router.commit]] method
|
|
64
|
-
*/
|
|
65
|
-
deleted: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* A unique name to lookup the route
|
|
68
|
-
*/
|
|
69
|
-
name: string;
|
|
70
|
-
constructor(pattern: string, methods: string[], handler: RouteHandler, globalMatchers: RouteMatchersNode);
|
|
71
|
-
/**
|
|
72
|
-
* Returns an object of param matchers by merging global and local
|
|
73
|
-
* matchers. The local copy is given preference over the global
|
|
74
|
-
* one's
|
|
75
|
-
*/
|
|
76
|
-
private getMatchers;
|
|
77
|
-
/**
|
|
78
|
-
* Returns a normalized pattern string by prefixing the `prefix` (if defined).
|
|
79
|
-
*/
|
|
80
|
-
private computePattern;
|
|
81
|
-
/**
|
|
82
|
-
* Define Regex matcher for a given param. If a matcher exists, then we do not
|
|
83
|
-
* override that, since the routes inside a group will set matchers before
|
|
84
|
-
* the group, so they should have priority over the route matchers.
|
|
85
|
-
*
|
|
86
|
-
* ```
|
|
87
|
-
* Route.group(() => {
|
|
88
|
-
* Route.get('/:id', 'handler').where('id', /^[0-9]$/)
|
|
89
|
-
* }).where('id', /[^a-z$]/)
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* The `/^[0-9]$/` should win over the matcher defined by the group
|
|
93
|
-
*/
|
|
94
|
-
where(param: string, matcher: RouteParamMatcher): this;
|
|
95
|
-
/**
|
|
96
|
-
* Define prefix for the route. Prefixes will be concated
|
|
97
|
-
* This method is mainly exposed for the [[RouteGroup]]
|
|
98
|
-
*/
|
|
99
|
-
prefix(prefix: string): this;
|
|
100
|
-
/**
|
|
101
|
-
* Define a custom domain for the route. Again we do not overwrite the domain
|
|
102
|
-
* unless `overwrite` flag is set to true.
|
|
103
|
-
*
|
|
104
|
-
* This is again done to make route.domain win over route.group.domain
|
|
105
|
-
*/
|
|
106
|
-
domain(domain: string, overwrite?: boolean): this;
|
|
107
|
-
/**
|
|
108
|
-
* Define an array of middleware to be executed on the route. If `prepend`
|
|
109
|
-
* is true, then middleware will be added to start of the existing
|
|
110
|
-
* middleware. The option is exposed for [[RouteGroup]]
|
|
111
|
-
*/
|
|
112
|
-
middleware(middleware: RouteMiddlewareHandler | RouteMiddlewareHandler[], prepend?: boolean): this;
|
|
113
|
-
/**
|
|
114
|
-
* Give memorizable name to the route. This is helpful, when you
|
|
115
|
-
* want to lookup route defination by it's name.
|
|
116
|
-
*
|
|
117
|
-
* If `prepend` is true, then it will keep on prepending to the existing
|
|
118
|
-
* name. This option is exposed for [[RouteGroup]]
|
|
119
|
-
*/
|
|
120
|
-
as(name: string, prepend?: boolean): this;
|
|
121
|
-
/**
|
|
122
|
-
* Define controller namespace for a given route
|
|
123
|
-
*/
|
|
124
|
-
namespace(namespace: string, overwrite?: boolean): this;
|
|
125
|
-
/**
|
|
126
|
-
* Get the route pattern
|
|
127
|
-
*/
|
|
128
|
-
getPattern(): string;
|
|
129
|
-
/**
|
|
130
|
-
* Set the route pattern
|
|
131
|
-
*/
|
|
132
|
-
setPattern(pattern: string): this;
|
|
133
|
-
/**
|
|
134
|
-
* Returns [[RouteDefinition]] that can be passed to the [[Store]] for
|
|
135
|
-
* registering the route
|
|
136
|
-
*/
|
|
137
|
-
toJSON(): RouteJSON;
|
|
138
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Route = void 0;
|
|
12
|
-
/// <reference path="../../adonis-typings/index.ts" />
|
|
13
|
-
const macroable_1 = require("macroable");
|
|
14
|
-
const helpers_1 = require("@poppinss/utils/build/helpers");
|
|
15
|
-
const helpers_2 = require("../helpers");
|
|
16
|
-
/**
|
|
17
|
-
* Route class is used to construct consistent [[RouteDefinition]] using
|
|
18
|
-
* fluent API. An instance of route is usually obtained using the
|
|
19
|
-
* [[Router]] class helper methods.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const route = new Route('posts/:id', ['GET'], async function () {
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* route
|
|
27
|
-
* .where('id', /^[0-9]+$/)
|
|
28
|
-
* .middleware(async function () {
|
|
29
|
-
* })
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
class Route extends macroable_1.Macroable {
|
|
33
|
-
constructor(pattern, methods, handler, globalMatchers) {
|
|
34
|
-
super();
|
|
35
|
-
this.pattern = pattern;
|
|
36
|
-
this.methods = methods;
|
|
37
|
-
this.handler = handler;
|
|
38
|
-
this.globalMatchers = globalMatchers;
|
|
39
|
-
/**
|
|
40
|
-
* By default the route is part of `root` domain. Root
|
|
41
|
-
* domain is used when no domain is defined
|
|
42
|
-
*/
|
|
43
|
-
this.routeDomain = 'root';
|
|
44
|
-
/**
|
|
45
|
-
* An object of matchers to be forwarded to the
|
|
46
|
-
* store. The matchers list is populated by
|
|
47
|
-
* calling `where` method
|
|
48
|
-
*/
|
|
49
|
-
this.matchers = {};
|
|
50
|
-
/**
|
|
51
|
-
* Custom prefixes. Usually added to a group of routes. We keep an array of them
|
|
52
|
-
* since nested groups will want all of them ot concat.
|
|
53
|
-
*/
|
|
54
|
-
this.prefixes = [];
|
|
55
|
-
/**
|
|
56
|
-
* An array of middleware. Added using `middleware` function
|
|
57
|
-
*/
|
|
58
|
-
this.routeMiddleware = [];
|
|
59
|
-
/**
|
|
60
|
-
* A boolean to prevent route from getting registered within
|
|
61
|
-
* the [[Store]].
|
|
62
|
-
*
|
|
63
|
-
* This flag must be set before [[Router.commit]] method
|
|
64
|
-
*/
|
|
65
|
-
this.deleted = false;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Returns an object of param matchers by merging global and local
|
|
69
|
-
* matchers. The local copy is given preference over the global
|
|
70
|
-
* one's
|
|
71
|
-
*/
|
|
72
|
-
getMatchers() {
|
|
73
|
-
return Object.assign({}, this.globalMatchers, this.matchers);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Returns a normalized pattern string by prefixing the `prefix` (if defined).
|
|
77
|
-
*/
|
|
78
|
-
computePattern() {
|
|
79
|
-
const pattern = (0, helpers_2.dropSlash)(this.pattern);
|
|
80
|
-
const prefix = this.prefixes
|
|
81
|
-
.slice()
|
|
82
|
-
.reverse()
|
|
83
|
-
.map((one) => (0, helpers_2.dropSlash)(one))
|
|
84
|
-
.join('');
|
|
85
|
-
return prefix ? `${prefix}${pattern === '/' ? '' : pattern}` : pattern;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Define Regex matcher for a given param. If a matcher exists, then we do not
|
|
89
|
-
* override that, since the routes inside a group will set matchers before
|
|
90
|
-
* the group, so they should have priority over the route matchers.
|
|
91
|
-
*
|
|
92
|
-
* ```
|
|
93
|
-
* Route.group(() => {
|
|
94
|
-
* Route.get('/:id', 'handler').where('id', /^[0-9]$/)
|
|
95
|
-
* }).where('id', /[^a-z$]/)
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* The `/^[0-9]$/` should win over the matcher defined by the group
|
|
99
|
-
*/
|
|
100
|
-
where(param, matcher) {
|
|
101
|
-
if (this.matchers[param]) {
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
if (typeof matcher === 'string') {
|
|
105
|
-
this.matchers[param] = { match: new RegExp(matcher) };
|
|
106
|
-
}
|
|
107
|
-
else if (helpers_1.types.isRegexp(matcher)) {
|
|
108
|
-
this.matchers[param] = { match: matcher };
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.matchers[param] = matcher;
|
|
112
|
-
}
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Define prefix for the route. Prefixes will be concated
|
|
117
|
-
* This method is mainly exposed for the [[RouteGroup]]
|
|
118
|
-
*/
|
|
119
|
-
prefix(prefix) {
|
|
120
|
-
this.prefixes.push(prefix);
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Define a custom domain for the route. Again we do not overwrite the domain
|
|
125
|
-
* unless `overwrite` flag is set to true.
|
|
126
|
-
*
|
|
127
|
-
* This is again done to make route.domain win over route.group.domain
|
|
128
|
-
*/
|
|
129
|
-
domain(domain, overwrite = false) {
|
|
130
|
-
if (this.routeDomain === 'root' || overwrite) {
|
|
131
|
-
this.routeDomain = domain;
|
|
132
|
-
}
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Define an array of middleware to be executed on the route. If `prepend`
|
|
137
|
-
* is true, then middleware will be added to start of the existing
|
|
138
|
-
* middleware. The option is exposed for [[RouteGroup]]
|
|
139
|
-
*/
|
|
140
|
-
middleware(middleware, prepend = false) {
|
|
141
|
-
middleware = Array.isArray(middleware) ? middleware : [middleware];
|
|
142
|
-
if (prepend) {
|
|
143
|
-
this.routeMiddleware.unshift(middleware);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
this.routeMiddleware.push(middleware);
|
|
147
|
-
}
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Give memorizable name to the route. This is helpful, when you
|
|
152
|
-
* want to lookup route defination by it's name.
|
|
153
|
-
*
|
|
154
|
-
* If `prepend` is true, then it will keep on prepending to the existing
|
|
155
|
-
* name. This option is exposed for [[RouteGroup]]
|
|
156
|
-
*/
|
|
157
|
-
as(name, prepend = false) {
|
|
158
|
-
this.name = prepend ? `${name}.${this.name}` : name;
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Define controller namespace for a given route
|
|
163
|
-
*/
|
|
164
|
-
namespace(namespace, overwrite = false) {
|
|
165
|
-
if (!this.routeNamespace || overwrite) {
|
|
166
|
-
this.routeNamespace = namespace;
|
|
167
|
-
}
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Get the route pattern
|
|
172
|
-
*/
|
|
173
|
-
getPattern() {
|
|
174
|
-
return this.pattern;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Set the route pattern
|
|
178
|
-
*/
|
|
179
|
-
setPattern(pattern) {
|
|
180
|
-
this.pattern = pattern;
|
|
181
|
-
return this;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Returns [[RouteDefinition]] that can be passed to the [[Store]] for
|
|
185
|
-
* registering the route
|
|
186
|
-
*/
|
|
187
|
-
toJSON() {
|
|
188
|
-
return {
|
|
189
|
-
domain: this.routeDomain,
|
|
190
|
-
pattern: this.computePattern(),
|
|
191
|
-
matchers: this.getMatchers(),
|
|
192
|
-
meta: {
|
|
193
|
-
namespace: this.routeNamespace,
|
|
194
|
-
},
|
|
195
|
-
name: this.name,
|
|
196
|
-
handler: this.handler,
|
|
197
|
-
methods: this.methods,
|
|
198
|
-
middleware: this.routeMiddleware.flat(),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.Route = Route;
|
|
203
|
-
Route.macros = {};
|
|
204
|
-
Route.getters = {};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference path="../../adonis-typings/index.d.ts" />
|
|
10
|
-
import { RouteJSON, RoutesTree, MatchedRoute, RouteStoreMatch } from '@ioc:Adonis/Core/Route';
|
|
11
|
-
/**
|
|
12
|
-
* Store class is used to store a list of routes, along side with their tokens
|
|
13
|
-
* to match the URL's. The used data structures to store information is tailored
|
|
14
|
-
* for quick lookups.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const store = new Store()
|
|
19
|
-
*
|
|
20
|
-
* store.add({
|
|
21
|
-
* pattern: 'posts/:id',
|
|
22
|
-
* handler: function onRoute () {},
|
|
23
|
-
* middleware: [],
|
|
24
|
-
* matchers: {
|
|
25
|
-
* id: '^[0-9]$+'
|
|
26
|
-
* },
|
|
27
|
-
* meta: {},
|
|
28
|
-
* methods: ['GET']
|
|
29
|
-
* })
|
|
30
|
-
*
|
|
31
|
-
* store.match('posts/1', 'GET')
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare class Store {
|
|
35
|
-
tree: RoutesTree;
|
|
36
|
-
/**
|
|
37
|
-
* The [[matchDomainReal]] and [[matchDomainNoop]] functions are two
|
|
38
|
-
* implementation of matching a domain. We use noop implementation
|
|
39
|
-
* by default and once an explicit domain is registered, we
|
|
40
|
-
* pivot to [[matchDomainReal]].
|
|
41
|
-
*
|
|
42
|
-
* This all is done for performance, since we have noticed around 8-10%
|
|
43
|
-
* improvement.
|
|
44
|
-
*/
|
|
45
|
-
private matchDomainReal;
|
|
46
|
-
private matchDomainNoop;
|
|
47
|
-
/**
|
|
48
|
-
* The implementation used for matching domain. Will pivot to `matchDomainReal`
|
|
49
|
-
* when one or more domains will be defined
|
|
50
|
-
*/
|
|
51
|
-
matchDomain: any;
|
|
52
|
-
/**
|
|
53
|
-
* Returns the domain node for a given domain. If domain node is missing,
|
|
54
|
-
* it will added to the routes object and tokens are also generated
|
|
55
|
-
*/
|
|
56
|
-
private getDomainNode;
|
|
57
|
-
/**
|
|
58
|
-
* Returns the method node for a given domain and method. If method is
|
|
59
|
-
* missing, it will be added to the domain node
|
|
60
|
-
*/
|
|
61
|
-
private getMethodRoutes;
|
|
62
|
-
/**
|
|
63
|
-
* Adds a route to the store for all the given HTTP methods. Also an array
|
|
64
|
-
* of tokens is generated for the route pattern. The tokens are then
|
|
65
|
-
* matched against the URL to find the appropriate route.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* store.add({
|
|
70
|
-
* pattern: 'post/:id',
|
|
71
|
-
* methods: ['GET'],
|
|
72
|
-
* matchers: {},
|
|
73
|
-
* meta: {},
|
|
74
|
-
* handler: function handler () {
|
|
75
|
-
* }
|
|
76
|
-
* })
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
add(route: RouteJSON): this;
|
|
80
|
-
/**
|
|
81
|
-
* Matches the url, method and optionally domain to pull the matching
|
|
82
|
-
* route. `null` is returned when unable to match the URL against
|
|
83
|
-
* registered routes.
|
|
84
|
-
*
|
|
85
|
-
* The domain parameter has to be a registered pattern and not the fully
|
|
86
|
-
* qualified runtime domain. You must call `matchDomain` first to fetch
|
|
87
|
-
* the pattern for qualified domain
|
|
88
|
-
*/
|
|
89
|
-
match(url: string, method: string, domain?: {
|
|
90
|
-
storeMatch: RouteStoreMatch[];
|
|
91
|
-
value: string;
|
|
92
|
-
}): null | MatchedRoute;
|
|
93
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.Store = void 0;
|
|
15
|
-
/// <reference path="../../adonis-typings/index.ts" />
|
|
16
|
-
const matchit_1 = __importDefault(require("@poppinss/matchit"));
|
|
17
|
-
const utils_1 = require("@poppinss/utils");
|
|
18
|
-
const RouterException_1 = require("../Exceptions/RouterException");
|
|
19
|
-
/**
|
|
20
|
-
* Store class is used to store a list of routes, along side with their tokens
|
|
21
|
-
* to match the URL's. The used data structures to store information is tailored
|
|
22
|
-
* for quick lookups.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const store = new Store()
|
|
27
|
-
*
|
|
28
|
-
* store.add({
|
|
29
|
-
* pattern: 'posts/:id',
|
|
30
|
-
* handler: function onRoute () {},
|
|
31
|
-
* middleware: [],
|
|
32
|
-
* matchers: {
|
|
33
|
-
* id: '^[0-9]$+'
|
|
34
|
-
* },
|
|
35
|
-
* meta: {},
|
|
36
|
-
* methods: ['GET']
|
|
37
|
-
* })
|
|
38
|
-
*
|
|
39
|
-
* store.match('posts/1', 'GET')
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
class Store {
|
|
43
|
-
constructor() {
|
|
44
|
-
this.tree = { tokens: [], domains: {} };
|
|
45
|
-
/**
|
|
46
|
-
* The [[matchDomainReal]] and [[matchDomainNoop]] functions are two
|
|
47
|
-
* implementation of matching a domain. We use noop implementation
|
|
48
|
-
* by default and once an explicit domain is registered, we
|
|
49
|
-
* pivot to [[matchDomainReal]].
|
|
50
|
-
*
|
|
51
|
-
* This all is done for performance, since we have noticed around 8-10%
|
|
52
|
-
* improvement.
|
|
53
|
-
*/
|
|
54
|
-
this.matchDomainReal = function (domain) {
|
|
55
|
-
return matchit_1.default.match(domain || 'root', this.tree.tokens);
|
|
56
|
-
}.bind(this);
|
|
57
|
-
this.matchDomainNoop = function (_) {
|
|
58
|
-
return [];
|
|
59
|
-
}.bind(this);
|
|
60
|
-
/**
|
|
61
|
-
* The implementation used for matching domain. Will pivot to `matchDomainReal`
|
|
62
|
-
* when one or more domains will be defined
|
|
63
|
-
*/
|
|
64
|
-
this.matchDomain = this.matchDomainNoop;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns the domain node for a given domain. If domain node is missing,
|
|
68
|
-
* it will added to the routes object and tokens are also generated
|
|
69
|
-
*/
|
|
70
|
-
getDomainNode(domain) {
|
|
71
|
-
if (!this.tree.domains[domain]) {
|
|
72
|
-
/**
|
|
73
|
-
* The tokens are required to match dynamic domains
|
|
74
|
-
*/
|
|
75
|
-
this.tree.tokens.push(matchit_1.default.parse(domain));
|
|
76
|
-
this.tree.domains[domain] = {};
|
|
77
|
-
}
|
|
78
|
-
return this.tree.domains[domain];
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Returns the method node for a given domain and method. If method is
|
|
82
|
-
* missing, it will be added to the domain node
|
|
83
|
-
*/
|
|
84
|
-
getMethodRoutes(domain, method) {
|
|
85
|
-
const domainNode = this.getDomainNode(domain);
|
|
86
|
-
if (!domainNode[method]) {
|
|
87
|
-
domainNode[method] = { tokens: [], routes: {} };
|
|
88
|
-
}
|
|
89
|
-
return domainNode[method];
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Adds a route to the store for all the given HTTP methods. Also an array
|
|
93
|
-
* of tokens is generated for the route pattern. The tokens are then
|
|
94
|
-
* matched against the URL to find the appropriate route.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* store.add({
|
|
99
|
-
* pattern: 'post/:id',
|
|
100
|
-
* methods: ['GET'],
|
|
101
|
-
* matchers: {},
|
|
102
|
-
* meta: {},
|
|
103
|
-
* handler: function handler () {
|
|
104
|
-
* }
|
|
105
|
-
* })
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
add(route) {
|
|
109
|
-
/*
|
|
110
|
-
* Create a copy of route properties by cherry picking
|
|
111
|
-
* fields. We create the copy outside the forEach
|
|
112
|
-
* loop, so that the same object is shared across
|
|
113
|
-
* all the methods (saving memory).
|
|
114
|
-
*
|
|
115
|
-
* Also sharing a single route note among all the methods is fine,
|
|
116
|
-
* since we create sub-trees for each method to make the lookups
|
|
117
|
-
* fast.
|
|
118
|
-
*/
|
|
119
|
-
const routeJSON = {};
|
|
120
|
-
utils_1.lodash.merge(routeJSON, utils_1.lodash.pick(route, ['pattern', 'handler', 'meta', 'middleware', 'name']));
|
|
121
|
-
/*
|
|
122
|
-
* An explicit domain is defined
|
|
123
|
-
*/
|
|
124
|
-
if (route.domain && route.domain !== 'root' && this.matchDomain !== this.matchDomainReal) {
|
|
125
|
-
this.matchDomain = this.matchDomainReal;
|
|
126
|
-
}
|
|
127
|
-
/*
|
|
128
|
-
* Generate tokens for the given route and push to the list
|
|
129
|
-
* of tokens
|
|
130
|
-
*/
|
|
131
|
-
const tokens = matchit_1.default.parse(route.pattern, route.matchers);
|
|
132
|
-
const collectedParams = new Set();
|
|
133
|
-
/**
|
|
134
|
-
* Avoiding duplicate route params
|
|
135
|
-
*/
|
|
136
|
-
for (let token of tokens) {
|
|
137
|
-
if ([1, 3].includes(token.type)) {
|
|
138
|
-
if (collectedParams.has(token.val)) {
|
|
139
|
-
throw RouterException_1.RouterException.duplicateRouteParam(token.val, route.pattern);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
collectedParams.add(token.val);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
routeJSON.params = new Array(...collectedParams);
|
|
147
|
-
collectedParams.clear();
|
|
148
|
-
route.methods.forEach((method) => {
|
|
149
|
-
const methodRoutes = this.getMethodRoutes(route.domain || 'root', method);
|
|
150
|
-
/*
|
|
151
|
-
* Ensure that route doesn't pre-exists. In that case, we need to throw
|
|
152
|
-
* the exception, since it's a programmer error to create multiple
|
|
153
|
-
* routes with the same pattern on the same method.
|
|
154
|
-
*/
|
|
155
|
-
if (methodRoutes.routes[route.pattern]) {
|
|
156
|
-
throw RouterException_1.RouterException.duplicateRoute(method, route.pattern);
|
|
157
|
-
}
|
|
158
|
-
methodRoutes.tokens.push(tokens);
|
|
159
|
-
/*
|
|
160
|
-
* Store reference to the route, so that we can return it to the user, when
|
|
161
|
-
* they call `match`.
|
|
162
|
-
*/
|
|
163
|
-
methodRoutes.routes[route.pattern] = routeJSON;
|
|
164
|
-
});
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Matches the url, method and optionally domain to pull the matching
|
|
169
|
-
* route. `null` is returned when unable to match the URL against
|
|
170
|
-
* registered routes.
|
|
171
|
-
*
|
|
172
|
-
* The domain parameter has to be a registered pattern and not the fully
|
|
173
|
-
* qualified runtime domain. You must call `matchDomain` first to fetch
|
|
174
|
-
* the pattern for qualified domain
|
|
175
|
-
*/
|
|
176
|
-
match(url, method, domain) {
|
|
177
|
-
const matchingDomain = domain && domain.storeMatch[0] && domain.storeMatch[0].old;
|
|
178
|
-
const domainName = matchingDomain || 'root';
|
|
179
|
-
const matchedDomain = this.tree.domains[domainName];
|
|
180
|
-
if (!matchedDomain) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
/*
|
|
184
|
-
* Next get the method node for the given method inside the domain. If
|
|
185
|
-
* method node is missing, means no routes ever got registered for that
|
|
186
|
-
* method
|
|
187
|
-
*/
|
|
188
|
-
const matchedMethod = this.tree.domains[domainName][method];
|
|
189
|
-
if (!matchedMethod) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
/*
|
|
193
|
-
* Next, match route for the given url inside the tokens list for the
|
|
194
|
-
* matchedMethod
|
|
195
|
-
*/
|
|
196
|
-
const matchedRoute = matchit_1.default.match(url, matchedMethod.tokens);
|
|
197
|
-
if (!matchedRoute.length) {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
const route = matchedMethod.routes[matchedRoute[0].old];
|
|
201
|
-
return {
|
|
202
|
-
route: route,
|
|
203
|
-
routeKey: matchingDomain
|
|
204
|
-
? `${matchingDomain}-${method}-${route.pattern}`
|
|
205
|
-
: `${method}-${route.pattern}`,
|
|
206
|
-
params: matchit_1.default.exec(url, matchedRoute),
|
|
207
|
-
subdomains: domain?.value ? matchit_1.default.exec(domain.value, domain.storeMatch) : {},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.Store = Store;
|