@adonisjs/http-server 5.8.0 → 5.9.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.
|
@@ -116,20 +116,11 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
116
116
|
domain?: string;
|
|
117
117
|
matchers: RouteMatchersNode;
|
|
118
118
|
};
|
|
119
|
-
/**
|
|
120
|
-
* Shape of the identifier node of the URL builder
|
|
121
|
-
*/
|
|
122
|
-
export type LookupStoreIdentifier = {
|
|
123
|
-
handler: RouteHandler;
|
|
124
|
-
methods: string[];
|
|
125
|
-
pattern: string;
|
|
126
|
-
name?: string;
|
|
127
|
-
};
|
|
128
119
|
/**
|
|
129
120
|
* Shape of the routes tree maintained by the UrlBuilder
|
|
130
121
|
*/
|
|
131
122
|
export type LookupStoreTree = {
|
|
132
|
-
[domain: string]:
|
|
123
|
+
[domain: string]: RouteJSON[];
|
|
133
124
|
};
|
|
134
125
|
/**
|
|
135
126
|
* Shape of the matched route for a pattern, method and domain. We set
|
|
@@ -490,6 +481,21 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
490
481
|
* directly
|
|
491
482
|
*/
|
|
492
483
|
export interface LookupStoreContract {
|
|
484
|
+
/**
|
|
485
|
+
* Find a route by indentifier. Optionally one can find routes inside
|
|
486
|
+
* a given domain
|
|
487
|
+
*/
|
|
488
|
+
find(routeIdentifier: string, domainPattern?: string): RouteJSON | null;
|
|
489
|
+
/**
|
|
490
|
+
* Find a route by indentifier or fail. Optionally one can find routes inside
|
|
491
|
+
* a given domain
|
|
492
|
+
*/
|
|
493
|
+
findOrFail(routeIdentifier: string, domainPattern?: string): RouteJSON;
|
|
494
|
+
/**
|
|
495
|
+
* Find if a route for given identifier exists. Optionally one can find routes inside
|
|
496
|
+
* a given domain
|
|
497
|
+
*/
|
|
498
|
+
has(routeIdentifier: string, domainPattern?: string): boolean;
|
|
493
499
|
/**
|
|
494
500
|
* Get the builder instance for the main domain
|
|
495
501
|
*/
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { RouteJSON, LookupStoreTree, UrlBuilderContract,
|
|
1
|
+
import { RouteJSON, LookupStoreTree, UrlBuilderContract, LookupStoreContract } from '@ioc:Adonis/Core/Route';
|
|
2
2
|
import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
|
|
3
|
+
/**
|
|
4
|
+
* A class to encapsulate finding routes
|
|
5
|
+
*/
|
|
6
|
+
declare class Routes {
|
|
7
|
+
private routes;
|
|
8
|
+
constructor(routes: RouteJSON[]);
|
|
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
|
+
}
|
|
3
22
|
/**
|
|
4
23
|
* Url builder is responsible for building the URLs
|
|
5
24
|
*/
|
|
@@ -23,16 +42,11 @@ export declare class UrlBuilder implements UrlBuilderContract {
|
|
|
23
42
|
* A baseUrl to prefix to the endpoint
|
|
24
43
|
*/
|
|
25
44
|
private baseUrl;
|
|
26
|
-
constructor(encryption: EncryptionContract, routes:
|
|
45
|
+
constructor(encryption: EncryptionContract, routes: Routes);
|
|
27
46
|
/**
|
|
28
47
|
* Processes the pattern against the params
|
|
29
48
|
*/
|
|
30
49
|
private processPattern;
|
|
31
|
-
/**
|
|
32
|
-
* Finds the route inside the list of registered routes and
|
|
33
|
-
* raises exception when unable to
|
|
34
|
-
*/
|
|
35
|
-
private findRouteOrFail;
|
|
36
50
|
/**
|
|
37
51
|
* Suffix the query string to the URL
|
|
38
52
|
*/
|
|
@@ -70,7 +84,7 @@ export declare class UrlBuilder implements UrlBuilderContract {
|
|
|
70
84
|
* The look up store to make URLs for a given route by looking
|
|
71
85
|
* it by its name, route handler or the pattern directly.
|
|
72
86
|
*/
|
|
73
|
-
export declare class LookupStore {
|
|
87
|
+
export declare class LookupStore implements LookupStoreContract {
|
|
74
88
|
private encryption;
|
|
75
89
|
/**
|
|
76
90
|
* Shape of the registered routes. Optimized for lookups
|
|
@@ -89,4 +103,20 @@ export declare class LookupStore {
|
|
|
89
103
|
* Returns the route builder a given domain.
|
|
90
104
|
*/
|
|
91
105
|
builderForDomain(domainPattern: string): UrlBuilder;
|
|
106
|
+
/**
|
|
107
|
+
* Find a route by indentifier. Optionally one can find routes inside
|
|
108
|
+
* a given domain
|
|
109
|
+
*/
|
|
110
|
+
find(routeIdentifier: string, domainPattern?: string): RouteJSON | null;
|
|
111
|
+
/**
|
|
112
|
+
* Find a route by indentifier or fail. Optionally one can find routes inside
|
|
113
|
+
* a given domain
|
|
114
|
+
*/
|
|
115
|
+
findOrFail(routeIdentifier: string, domainPattern?: string): RouteJSON;
|
|
116
|
+
/**
|
|
117
|
+
* Find if a route for given identifier exists. Optionally one can find routes inside
|
|
118
|
+
* a given domain
|
|
119
|
+
*/
|
|
120
|
+
has(routeIdentifier: string, domainPattern?: string): boolean;
|
|
92
121
|
}
|
|
122
|
+
export {};
|
|
@@ -15,6 +15,38 @@ exports.LookupStore = exports.UrlBuilder = void 0;
|
|
|
15
15
|
const qs_1 = __importDefault(require("qs"));
|
|
16
16
|
const encodeurl_1 = __importDefault(require("encodeurl"));
|
|
17
17
|
const RouterException_1 = require("../Exceptions/RouterException");
|
|
18
|
+
/**
|
|
19
|
+
* A class to encapsulate finding routes
|
|
20
|
+
*/
|
|
21
|
+
class Routes {
|
|
22
|
+
constructor(routes) {
|
|
23
|
+
this.routes = routes;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Find a route by indentifier
|
|
27
|
+
*/
|
|
28
|
+
find(routeIdentifier) {
|
|
29
|
+
return (this.routes.find(({ name, pattern, handler }) => {
|
|
30
|
+
return (name === routeIdentifier || pattern === routeIdentifier || handler === routeIdentifier);
|
|
31
|
+
}) || null);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Find a route by indentifier or fail
|
|
35
|
+
*/
|
|
36
|
+
findOrFail(routeIdentifier) {
|
|
37
|
+
const route = this.find(routeIdentifier);
|
|
38
|
+
if (!route) {
|
|
39
|
+
throw RouterException_1.RouterException.cannotLookupRoute(routeIdentifier);
|
|
40
|
+
}
|
|
41
|
+
return route;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Find if a route exists
|
|
45
|
+
*/
|
|
46
|
+
has(routeIdentifier) {
|
|
47
|
+
return !!this.find(routeIdentifier);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
18
50
|
/**
|
|
19
51
|
* Url builder is responsible for building the URLs
|
|
20
52
|
*/
|
|
@@ -80,19 +112,6 @@ class UrlBuilder {
|
|
|
80
112
|
}
|
|
81
113
|
return url.join('/');
|
|
82
114
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Finds the route inside the list of registered routes and
|
|
85
|
-
* raises exception when unable to
|
|
86
|
-
*/
|
|
87
|
-
findRouteOrFail(identifier) {
|
|
88
|
-
const route = this.routes.find(({ name, pattern, handler }) => {
|
|
89
|
-
return name === identifier || pattern === identifier || handler === identifier;
|
|
90
|
-
});
|
|
91
|
-
if (!route) {
|
|
92
|
-
throw RouterException_1.RouterException.cannotLookupRoute(identifier);
|
|
93
|
-
}
|
|
94
|
-
return route;
|
|
95
|
-
}
|
|
96
115
|
/**
|
|
97
116
|
* Suffix the query string to the URL
|
|
98
117
|
*/
|
|
@@ -144,7 +163,7 @@ class UrlBuilder {
|
|
|
144
163
|
make(identifier) {
|
|
145
164
|
let url;
|
|
146
165
|
if (this.lookupRoute) {
|
|
147
|
-
const route = this.
|
|
166
|
+
const route = this.routes.findOrFail(identifier);
|
|
148
167
|
url = this.processPattern(route.pattern);
|
|
149
168
|
}
|
|
150
169
|
else {
|
|
@@ -158,7 +177,7 @@ class UrlBuilder {
|
|
|
158
177
|
makeSigned(identifier, options) {
|
|
159
178
|
let url;
|
|
160
179
|
if (this.lookupRoute) {
|
|
161
|
-
const route = this.
|
|
180
|
+
const route = this.routes.findOrFail(identifier);
|
|
162
181
|
url = this.processPattern(route.pattern);
|
|
163
182
|
}
|
|
164
183
|
else {
|
|
@@ -199,12 +218,7 @@ class LookupStore {
|
|
|
199
218
|
register(route) {
|
|
200
219
|
const domain = route.domain || 'root';
|
|
201
220
|
this.tree[domain] = this.tree[domain] || [];
|
|
202
|
-
this.tree[domain].push(
|
|
203
|
-
methods: route.methods,
|
|
204
|
-
name: route.name,
|
|
205
|
-
handler: route.handler,
|
|
206
|
-
pattern: route.pattern,
|
|
207
|
-
});
|
|
221
|
+
this.tree[domain].push(route);
|
|
208
222
|
}
|
|
209
223
|
/**
|
|
210
224
|
* Returns the route builder for the root domain
|
|
@@ -220,7 +234,31 @@ class LookupStore {
|
|
|
220
234
|
if (!domainRoutes && domainPattern !== 'root') {
|
|
221
235
|
throw RouterException_1.RouterException.cannotLookupDomain(domainPattern);
|
|
222
236
|
}
|
|
223
|
-
return new UrlBuilder(this.encryption, domainRoutes || []);
|
|
237
|
+
return new UrlBuilder(this.encryption, new Routes(domainRoutes || []));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Find a route by indentifier. Optionally one can find routes inside
|
|
241
|
+
* a given domain
|
|
242
|
+
*/
|
|
243
|
+
find(routeIdentifier, domainPattern) {
|
|
244
|
+
const routes = this.tree[domainPattern || 'root'] || [];
|
|
245
|
+
return new Routes(routes || []).find(routeIdentifier);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Find a route by indentifier or fail. Optionally one can find routes inside
|
|
249
|
+
* a given domain
|
|
250
|
+
*/
|
|
251
|
+
findOrFail(routeIdentifier, domainPattern) {
|
|
252
|
+
const routes = this.tree[domainPattern || 'root'] || [];
|
|
253
|
+
return new Routes(routes || []).findOrFail(routeIdentifier);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Find if a route for given identifier exists. Optionally one can find routes inside
|
|
257
|
+
* a given domain
|
|
258
|
+
*/
|
|
259
|
+
has(routeIdentifier, domainPattern) {
|
|
260
|
+
const routes = this.tree[domainPattern || 'root'] || [];
|
|
261
|
+
return new Routes(routes || []).has(routeIdentifier);
|
|
224
262
|
}
|
|
225
263
|
}
|
|
226
264
|
exports.LookupStore = LookupStore;
|
|
@@ -14,6 +14,7 @@ import { RouteGroup } from './Group';
|
|
|
14
14
|
import { BriskRoute } from './BriskRoute';
|
|
15
15
|
import { RouteResource } from './Resource';
|
|
16
16
|
import { RouteMatchers } from './Matchers';
|
|
17
|
+
import { LookupStore } from './LookupStore';
|
|
17
18
|
/**
|
|
18
19
|
* Router class exposes unified API to create new routes, group them or
|
|
19
20
|
* create route resources.
|
|
@@ -27,8 +28,7 @@ import { RouteMatchers } from './Matchers';
|
|
|
27
28
|
* })
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
export declare class Router implements RouterContract {
|
|
31
|
-
private encryption;
|
|
31
|
+
export declare class Router extends LookupStore implements RouterContract {
|
|
32
32
|
private routeProcessor?;
|
|
33
33
|
/**
|
|
34
34
|
* Collection of routes, including route resource and route
|
|
@@ -52,10 +52,6 @@ export declare class Router implements RouterContract {
|
|
|
52
52
|
* Global matchers to test route params against regular expressions.
|
|
53
53
|
*/
|
|
54
54
|
private paramMatchers;
|
|
55
|
-
/**
|
|
56
|
-
* The lookup store instance
|
|
57
|
-
*/
|
|
58
|
-
private lookupStore;
|
|
59
55
|
/**
|
|
60
56
|
* Store with tokenized routes
|
|
61
57
|
*/
|
|
@@ -133,14 +129,6 @@ export declare class Router implements RouterContract {
|
|
|
133
129
|
* Find route for a given URL, method and optionally domain
|
|
134
130
|
*/
|
|
135
131
|
match(url: string, method: string, domain?: string): null | MatchedRoute;
|
|
136
|
-
/**
|
|
137
|
-
* Access to the URL builder
|
|
138
|
-
*/
|
|
139
|
-
builder(): import("./LookupStore").UrlBuilder;
|
|
140
|
-
/**
|
|
141
|
-
* Access to the URL builder for a specific domain
|
|
142
|
-
*/
|
|
143
|
-
builderForDomain(domainPattern: string): import("./LookupStore").UrlBuilder;
|
|
144
132
|
/**
|
|
145
133
|
* Makes url to a registered route by looking it up with the route pattern,
|
|
146
134
|
* name or the controller.method
|
|
@@ -33,9 +33,9 @@ const LookupStore_1 = require("./LookupStore");
|
|
|
33
33
|
* })
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
class Router {
|
|
36
|
+
class Router extends LookupStore_1.LookupStore {
|
|
37
37
|
constructor(encryption, routeProcessor) {
|
|
38
|
-
|
|
38
|
+
super(encryption);
|
|
39
39
|
this.routeProcessor = routeProcessor;
|
|
40
40
|
/**
|
|
41
41
|
* Collection of routes, including route resource and route
|
|
@@ -59,10 +59,6 @@ class Router {
|
|
|
59
59
|
* Global matchers to test route params against regular expressions.
|
|
60
60
|
*/
|
|
61
61
|
this.paramMatchers = {};
|
|
62
|
-
/**
|
|
63
|
-
* The lookup store instance
|
|
64
|
-
*/
|
|
65
|
-
this.lookupStore = new LookupStore_1.LookupStore(this.encryption);
|
|
66
62
|
/**
|
|
67
63
|
* Store with tokenized routes
|
|
68
64
|
*/
|
|
@@ -224,7 +220,7 @@ class Router {
|
|
|
224
220
|
* Returns a flat list of routes JSON
|
|
225
221
|
*/
|
|
226
222
|
toJSON() {
|
|
227
|
-
const lookupStoreRoutes = this.
|
|
223
|
+
const lookupStoreRoutes = this.tree;
|
|
228
224
|
const domains = Object.keys(lookupStoreRoutes);
|
|
229
225
|
return domains.reduce((result, domain) => {
|
|
230
226
|
result[domain] = lookupStoreRoutes[domain].map((route) => {
|
|
@@ -264,7 +260,7 @@ class Router {
|
|
|
264
260
|
/**
|
|
265
261
|
* Register the route with the lookup store
|
|
266
262
|
*/
|
|
267
|
-
this.
|
|
263
|
+
this.register(route);
|
|
268
264
|
this.store.add(route);
|
|
269
265
|
});
|
|
270
266
|
this.routes = [];
|
|
@@ -303,18 +299,6 @@ class Router {
|
|
|
303
299
|
}
|
|
304
300
|
return response;
|
|
305
301
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Access to the URL builder
|
|
308
|
-
*/
|
|
309
|
-
builder() {
|
|
310
|
-
return this.lookupStore.builder();
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Access to the URL builder for a specific domain
|
|
314
|
-
*/
|
|
315
|
-
builderForDomain(domainPattern) {
|
|
316
|
-
return this.lookupStore.builderForDomain(domainPattern);
|
|
317
|
-
}
|
|
318
302
|
/**
|
|
319
303
|
* Makes url to a registered route by looking it up with the route pattern,
|
|
320
304
|
* name or the controller.method
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/providers/HttpServerProvider.js",
|
|
6
6
|
"files": [
|
|
@@ -36,44 +36,44 @@
|
|
|
36
36
|
"author": "virk,adonisjs",
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@adonisjs/application": "^5.2.
|
|
39
|
+
"@adonisjs/application": "^5.2.4",
|
|
40
40
|
"@adonisjs/encryption": "^4.0.8",
|
|
41
41
|
"@adonisjs/mrm-preset": "^5.0.3",
|
|
42
42
|
"@adonisjs/require-ts": "^2.0.11",
|
|
43
|
-
"@japa/assert": "^1.3.
|
|
43
|
+
"@japa/assert": "^1.3.4",
|
|
44
44
|
"@japa/run-failed-tests": "^1.0.7",
|
|
45
|
-
"@japa/runner": "^2.0.
|
|
45
|
+
"@japa/runner": "^2.0.7",
|
|
46
46
|
"@japa/spec-reporter": "^1.1.12",
|
|
47
47
|
"@poppinss/dev-utils": "^2.0.3",
|
|
48
|
-
"@types/cookie": "^0.
|
|
48
|
+
"@types/cookie": "^0.5.1",
|
|
49
49
|
"@types/ms": "^0.7.31",
|
|
50
|
-
"@types/node": "^17.0.
|
|
50
|
+
"@types/node": "^17.0.31",
|
|
51
51
|
"@types/pluralize": "0.0.29",
|
|
52
52
|
"@types/proxy-addr": "^2.0.0",
|
|
53
53
|
"@types/qs": "^6.9.7",
|
|
54
54
|
"@types/supertest": "^2.0.12",
|
|
55
|
-
"autocannon": "^7.
|
|
55
|
+
"autocannon": "^7.9.0",
|
|
56
56
|
"commitizen": "^4.2.4",
|
|
57
57
|
"cross-env": "^7.0.3",
|
|
58
58
|
"cz-conventional-changelog": "^3.3.0",
|
|
59
59
|
"del-cli": "^4.0.1",
|
|
60
|
-
"eslint": "^8.
|
|
60
|
+
"eslint": "^8.15.0",
|
|
61
61
|
"eslint-config-prettier": "^8.5.0",
|
|
62
62
|
"eslint-plugin-adonis": "^2.1.0",
|
|
63
63
|
"eslint-plugin-prettier": "^4.0.0",
|
|
64
|
-
"fastify": "^3.
|
|
64
|
+
"fastify": "^3.29.0",
|
|
65
65
|
"github-label-sync": "^2.2.0",
|
|
66
66
|
"http-status-codes": "^2.2.0",
|
|
67
|
-
"husky": "^
|
|
67
|
+
"husky": "^8.0.0",
|
|
68
68
|
"middie": "^6.0.0",
|
|
69
69
|
"mrm": "^4.0.0",
|
|
70
70
|
"np": "^7.6.1",
|
|
71
71
|
"pem": "^1.14.6",
|
|
72
72
|
"prettier": "^2.6.2",
|
|
73
73
|
"reflect-metadata": "^0.1.13",
|
|
74
|
-
"supertest": "^6.2.
|
|
74
|
+
"supertest": "^6.2.3",
|
|
75
75
|
"ts-node": "^10.7.0",
|
|
76
|
-
"typescript": "^4.6.
|
|
76
|
+
"typescript": "^4.6.4"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@adonisjs/application": "^5.0.0",
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"@poppinss/matchit": "^3.1.2",
|
|
101
|
-
"@poppinss/utils": "^4.0.
|
|
101
|
+
"@poppinss/utils": "^4.0.4",
|
|
102
102
|
"accepts": "^1.3.8",
|
|
103
103
|
"co-compose": "^7.0.2",
|
|
104
104
|
"content-disposition": "^0.5.4",
|
|
105
|
-
"cookie": "^0.
|
|
105
|
+
"cookie": "^0.5.0",
|
|
106
106
|
"destroy": "^1.2.0",
|
|
107
107
|
"encodeurl": "^1.0.2",
|
|
108
108
|
"etag": "^1.8.1",
|