@adonisjs/http-server 5.10.1 → 5.11.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.
|
@@ -198,6 +198,14 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
198
198
|
* Define controller namespace for a given route
|
|
199
199
|
*/
|
|
200
200
|
namespace(namespace: string): this;
|
|
201
|
+
/**
|
|
202
|
+
* Get the route pattern
|
|
203
|
+
*/
|
|
204
|
+
getPattern(): string;
|
|
205
|
+
/**
|
|
206
|
+
* Update route pattern
|
|
207
|
+
*/
|
|
208
|
+
setPattern(pattern: string): this;
|
|
201
209
|
/**
|
|
202
210
|
* Returns [[RouteDefinition]] that can be passed to the [[Store]] for
|
|
203
211
|
* registering the route
|
|
@@ -242,6 +250,10 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
242
250
|
* Define namespace for all the routes inside a given resource
|
|
243
251
|
*/
|
|
244
252
|
namespace(namespace: string): this;
|
|
253
|
+
/**
|
|
254
|
+
* Set the param name for a given resource
|
|
255
|
+
*/
|
|
256
|
+
paramFor(resource: string, param: string): this;
|
|
245
257
|
/**
|
|
246
258
|
* Prepend name to the routes names
|
|
247
259
|
*/
|
|
@@ -27,6 +27,13 @@ export declare class RouteResource extends Macroable implements RouteResourceCon
|
|
|
27
27
|
private shallow;
|
|
28
28
|
protected static macros: {};
|
|
29
29
|
protected static getters: {};
|
|
30
|
+
/**
|
|
31
|
+
* The param names used to create the resource URLs.
|
|
32
|
+
*
|
|
33
|
+
* We need these later when someone explicitly wants to remap
|
|
34
|
+
* param name for a given resource using the "paramFor" method.
|
|
35
|
+
*/
|
|
36
|
+
private resourceParamNames;
|
|
30
37
|
/**
|
|
31
38
|
* A copy of routes that belongs to this resource
|
|
32
39
|
*/
|
|
@@ -77,6 +84,10 @@ export declare class RouteResource extends Macroable implements RouteResourceCon
|
|
|
77
84
|
* Define namespace for all the routes inside a given resource
|
|
78
85
|
*/
|
|
79
86
|
namespace(namespace: string): this;
|
|
87
|
+
/**
|
|
88
|
+
* Set the param name for a given resource
|
|
89
|
+
*/
|
|
90
|
+
paramFor(resource: string, param: string): this;
|
|
80
91
|
/**
|
|
81
92
|
* Prepend name to the routes names
|
|
82
93
|
*/
|
|
@@ -31,6 +31,13 @@ class RouteResource extends macroable_1.Macroable {
|
|
|
31
31
|
this.controller = controller;
|
|
32
32
|
this.globalMatchers = globalMatchers;
|
|
33
33
|
this.shallow = shallow;
|
|
34
|
+
/**
|
|
35
|
+
* The param names used to create the resource URLs.
|
|
36
|
+
*
|
|
37
|
+
* We need these later when someone explicitly wants to remap
|
|
38
|
+
* param name for a given resource using the "paramFor" method.
|
|
39
|
+
*/
|
|
40
|
+
this.resourceParamNames = {};
|
|
34
41
|
/**
|
|
35
42
|
* A copy of routes that belongs to this resource
|
|
36
43
|
*/
|
|
@@ -59,8 +66,16 @@ class RouteResource extends macroable_1.Macroable {
|
|
|
59
66
|
this.resource = this.resource.replace(/^\//, '').replace(/\/$/, '');
|
|
60
67
|
const resourceTokens = this.resource.split('.');
|
|
61
68
|
const mainResource = resourceTokens.pop();
|
|
69
|
+
/**
|
|
70
|
+
* The main resource always uses ids
|
|
71
|
+
*/
|
|
72
|
+
this.resourceParamNames[mainResource] = ':id';
|
|
62
73
|
const fullUrl = `${resourceTokens
|
|
63
|
-
.map((token) =>
|
|
74
|
+
.map((token) => {
|
|
75
|
+
const paramName = `:${helpers_1.string.snakeCase((0, pluralize_1.singular)(token))}_id`;
|
|
76
|
+
this.resourceParamNames[token] = paramName;
|
|
77
|
+
return `${token}/${paramName}`;
|
|
78
|
+
})
|
|
64
79
|
.join('/')}/${mainResource}`;
|
|
65
80
|
this.makeRoute(fullUrl, ['GET', 'HEAD'], 'index');
|
|
66
81
|
this.makeRoute(`${fullUrl}/create`, ['GET', 'HEAD'], 'create');
|
|
@@ -136,6 +151,20 @@ class RouteResource extends macroable_1.Macroable {
|
|
|
136
151
|
});
|
|
137
152
|
return this;
|
|
138
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Set the param name for a given resource
|
|
156
|
+
*/
|
|
157
|
+
paramFor(resource, param) {
|
|
158
|
+
const existingParam = this.resourceParamNames[resource];
|
|
159
|
+
this.resourceParamNames[resource] = `:${param}`;
|
|
160
|
+
this.routes.forEach((route) => {
|
|
161
|
+
/**
|
|
162
|
+
* Update the pattern for the route with the new param name
|
|
163
|
+
*/
|
|
164
|
+
route.setPattern(route.getPattern().replace(`${resource}/${existingParam}`, `${resource}/:${param}`));
|
|
165
|
+
});
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
139
168
|
/**
|
|
140
169
|
* Prepend name to the routes names
|
|
141
170
|
*/
|
|
@@ -77,7 +77,7 @@ export declare class Route extends Macroable implements RouteContract {
|
|
|
77
77
|
/**
|
|
78
78
|
* Returns a normalized pattern string by prefixing the `prefix` (if defined).
|
|
79
79
|
*/
|
|
80
|
-
private
|
|
80
|
+
private computePattern;
|
|
81
81
|
/**
|
|
82
82
|
* Define Regex matcher for a given param. If a matcher exists, then we do not
|
|
83
83
|
* override that, since the routes inside a group will set matchers before
|
|
@@ -122,6 +122,14 @@ export declare class Route extends Macroable implements RouteContract {
|
|
|
122
122
|
* Define controller namespace for a given route
|
|
123
123
|
*/
|
|
124
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;
|
|
125
133
|
/**
|
|
126
134
|
* Returns [[RouteDefinition]] that can be passed to the [[Store]] for
|
|
127
135
|
* registering the route
|
|
@@ -75,7 +75,7 @@ class Route extends macroable_1.Macroable {
|
|
|
75
75
|
/**
|
|
76
76
|
* Returns a normalized pattern string by prefixing the `prefix` (if defined).
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
computePattern() {
|
|
79
79
|
const pattern = (0, helpers_2.dropSlash)(this.pattern);
|
|
80
80
|
const prefix = this.prefixes
|
|
81
81
|
.slice()
|
|
@@ -167,6 +167,19 @@ class Route extends macroable_1.Macroable {
|
|
|
167
167
|
}
|
|
168
168
|
return this;
|
|
169
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
|
+
}
|
|
170
183
|
/**
|
|
171
184
|
* Returns [[RouteDefinition]] that can be passed to the [[Store]] for
|
|
172
185
|
* registering the route
|
|
@@ -174,7 +187,7 @@ class Route extends macroable_1.Macroable {
|
|
|
174
187
|
toJSON() {
|
|
175
188
|
return {
|
|
176
189
|
domain: this.routeDomain,
|
|
177
|
-
pattern: this.
|
|
190
|
+
pattern: this.computePattern(),
|
|
178
191
|
matchers: this.getMatchers(),
|
|
179
192
|
meta: {
|
|
180
193
|
namespace: this.routeNamespace,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.0",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/providers/HttpServerProvider.js",
|
|
6
6
|
"files": [
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@adonisjs/require-ts": "^2.0.12",
|
|
43
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.9",
|
|
46
46
|
"@japa/spec-reporter": "^1.1.12",
|
|
47
47
|
"@poppinss/dev-utils": "^2.0.3",
|
|
48
48
|
"@types/cookie": "^0.5.1",
|
|
49
49
|
"@types/ms": "^0.7.31",
|
|
50
|
-
"@types/node": "^17.0.
|
|
50
|
+
"@types/node": "^17.0.42",
|
|
51
51
|
"@types/pluralize": "0.0.29",
|
|
52
52
|
"@types/proxy-addr": "^2.0.0",
|
|
53
53
|
"@types/qs": "^6.9.7",
|
|
@@ -57,23 +57,23 @@
|
|
|
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.17.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": "^
|
|
64
|
+
"fastify": "^4.0.1",
|
|
65
65
|
"github-label-sync": "^2.2.0",
|
|
66
66
|
"http-status-codes": "^2.2.0",
|
|
67
67
|
"husky": "^8.0.1",
|
|
68
|
-
"middie": "^
|
|
68
|
+
"middie": "^7.1.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
74
|
"supertest": "^6.2.3",
|
|
75
|
-
"ts-node": "^10.8.
|
|
76
|
-
"typescript": "^4.7.
|
|
75
|
+
"ts-node": "^10.8.1",
|
|
76
|
+
"typescript": "^4.7.3"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@adonisjs/application": "^5.0.0",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"on-finished": "^2.4.1",
|
|
115
115
|
"pluralize": "^8.0.0",
|
|
116
116
|
"proxy-addr": "^2.0.7",
|
|
117
|
-
"qs": "^6.10.
|
|
117
|
+
"qs": "^6.10.5",
|
|
118
118
|
"tmp-cache": "^1.1.0",
|
|
119
119
|
"type-is": "^1.6.18",
|
|
120
120
|
"vary": "^1.1.2"
|