@adonisjs/http-server 5.10.1 → 5.12.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/build/adonis-typings/request.d.ts +1 -1
- package/build/adonis-typings/response.d.ts +3 -1
- package/build/adonis-typings/route.d.ts +12 -0
- package/build/src/Cookie/Parser/index.d.ts +1 -1
- package/build/src/Cookie/Parser/index.js +2 -2
- package/build/src/Cookie/Serializer/index.d.ts +3 -1
- package/build/src/Cookie/Serializer/index.js +1 -1
- package/build/src/Request/index.d.ts +1 -1
- package/build/src/Request/index.js +2 -2
- package/build/src/Response/index.d.ts +3 -1
- package/build/src/Router/Resource.d.ts +11 -0
- package/build/src/Router/Resource.js +30 -1
- package/build/src/Router/Route.d.ts +9 -1
- package/build/src/Router/Route.js +15 -2
- package/build/src/Server/PreCompiler/index.js +4 -2
- package/package.json +24 -24
|
@@ -520,7 +520,7 @@ declare module '@ioc:Adonis/Core/Request' {
|
|
|
520
520
|
* Returns value for a given key from unsigned cookies. Optional
|
|
521
521
|
* defaultValue is returned when actual value is undefined.
|
|
522
522
|
*/
|
|
523
|
-
plainCookie(key: string, defaultValue?: any): any;
|
|
523
|
+
plainCookie(key: string, defaultValue?: any, encoded?: boolean): any;
|
|
524
524
|
/**
|
|
525
525
|
* Returns a boolean telling if a signed url as a valid signature
|
|
526
526
|
* or not.
|
|
@@ -310,7 +310,9 @@ declare module '@ioc:Adonis/Core/Response' {
|
|
|
310
310
|
* Set unsigned cookie as the response header. The inline options overrides
|
|
311
311
|
* all options from the config (means they are not merged)
|
|
312
312
|
*/
|
|
313
|
-
plainCookie(key: string, value: any, options?: Partial<CookieOptions
|
|
313
|
+
plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
|
|
314
|
+
encoded: boolean;
|
|
315
|
+
}>): this;
|
|
314
316
|
/**
|
|
315
317
|
* Set unsigned cookie as the response header. The inline options overrides
|
|
316
318
|
* all options from the config (means they are not merged)
|
|
@@ -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
|
*/
|
|
@@ -41,7 +41,7 @@ export declare class CookieParser {
|
|
|
41
41
|
* you are assuming that the cookie was just encoded at the first
|
|
42
42
|
* place and not signed or encrypted.
|
|
43
43
|
*/
|
|
44
|
-
decode(key: string): any | null;
|
|
44
|
+
decode(key: string, encoded?: boolean): any | null;
|
|
45
45
|
/**
|
|
46
46
|
* Attempts to unsign a cookie by the name. When calling this method,
|
|
47
47
|
* you are assuming that the cookie was signed at the first place.
|
|
@@ -64,7 +64,7 @@ class CookieParser {
|
|
|
64
64
|
* you are assuming that the cookie was just encoded at the first
|
|
65
65
|
* place and not signed or encrypted.
|
|
66
66
|
*/
|
|
67
|
-
decode(key) {
|
|
67
|
+
decode(key, encoded = true) {
|
|
68
68
|
/*
|
|
69
69
|
* Ignore when initial value is not defined or null
|
|
70
70
|
*/
|
|
@@ -88,7 +88,7 @@ class CookieParser {
|
|
|
88
88
|
* Attempt to unpack and cache it for future. The value is only
|
|
89
89
|
* when value it is not null.
|
|
90
90
|
*/
|
|
91
|
-
const parsed = this.client.decode(key, value);
|
|
91
|
+
const parsed = encoded ? this.client.decode(key, value) : value;
|
|
92
92
|
if (parsed !== null) {
|
|
93
93
|
cacheObject[key] = parsed;
|
|
94
94
|
}
|
|
@@ -31,7 +31,9 @@ export declare class CookieSerializer {
|
|
|
31
31
|
* serializer.encode('name', 'virk')
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
encode(key: string, value: any, options?: Partial<CookieOptions
|
|
34
|
+
encode(key: string, value: any, options?: Partial<CookieOptions & {
|
|
35
|
+
encode: boolean;
|
|
36
|
+
}>): string | null;
|
|
35
37
|
/**
|
|
36
38
|
* Signs the value and returns it back as a url safe string. The signed value
|
|
37
39
|
* has a verification hash attached to it to detect data tampering.
|
|
@@ -57,7 +57,7 @@ class CookieSerializer {
|
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
encode(key, value, options) {
|
|
60
|
-
const packedValue = this.client.encode(key, value);
|
|
60
|
+
const packedValue = !(options?.encode ?? true) ? value : this.client.encode(key, value);
|
|
61
61
|
if (packedValue === null) {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
@@ -593,7 +593,7 @@ export declare class Request extends Macroable implements RequestContract {
|
|
|
593
593
|
* Returns value for a given key from unsigned cookies. Optional
|
|
594
594
|
* defaultValue is returned when actual value is undefined.
|
|
595
595
|
*/
|
|
596
|
-
plainCookie(key: string, defaultValue?: string): any;
|
|
596
|
+
plainCookie(key: string, defaultValue?: string, encoded?: boolean): any;
|
|
597
597
|
/**
|
|
598
598
|
* Returns a boolean telling if a signed url as a valid signature
|
|
599
599
|
* or not.
|
|
@@ -811,9 +811,9 @@ class Request extends macroable_1.Macroable {
|
|
|
811
811
|
* Returns value for a given key from unsigned cookies. Optional
|
|
812
812
|
* defaultValue is returned when actual value is undefined.
|
|
813
813
|
*/
|
|
814
|
-
plainCookie(key, defaultValue) {
|
|
814
|
+
plainCookie(key, defaultValue, encoded) {
|
|
815
815
|
this.initiateCookieParser();
|
|
816
|
-
return this.cookieParser.decode(key) || defaultValue;
|
|
816
|
+
return this.cookieParser.decode(key, encoded) || defaultValue;
|
|
817
817
|
}
|
|
818
818
|
/**
|
|
819
819
|
* Returns a boolean telling if a signed url as a valid signature
|
|
@@ -350,7 +350,9 @@ export declare class Response extends Macroable implements ResponseContract {
|
|
|
350
350
|
* Set unsigned cookie as the response header. The inline options overrides
|
|
351
351
|
* all options from the config (means they are not merged)
|
|
352
352
|
*/
|
|
353
|
-
plainCookie(key: string, value: any, options?: Partial<CookieOptions
|
|
353
|
+
plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
|
|
354
|
+
encode: boolean;
|
|
355
|
+
}>): this;
|
|
354
356
|
/**
|
|
355
357
|
* Set unsigned cookie as the response header. The inline options overrides
|
|
356
358
|
* all options from the config (means they are not merged)
|
|
@@ -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,
|
|
@@ -110,8 +110,10 @@ class PreCompiler {
|
|
|
110
110
|
error.help = exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.help.join('\n');
|
|
111
111
|
throw error;
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
return {
|
|
114
|
+
...resolvedMiddleware,
|
|
115
|
+
args,
|
|
116
|
+
};
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
119
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.12.0",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/providers/HttpServerProvider.js",
|
|
6
6
|
"files": [
|
|
@@ -39,41 +39,41 @@
|
|
|
39
39
|
"@adonisjs/application": "^5.2.5",
|
|
40
40
|
"@adonisjs/encryption": "^4.0.8",
|
|
41
41
|
"@adonisjs/mrm-preset": "^5.0.3",
|
|
42
|
-
"@adonisjs/require-ts": "^2.0.
|
|
43
|
-
"@japa/assert": "^1.3.
|
|
44
|
-
"@japa/run-failed-tests": "^1.0
|
|
45
|
-
"@japa/runner": "^2.
|
|
46
|
-
"@japa/spec-reporter": "^1.
|
|
42
|
+
"@adonisjs/require-ts": "^2.0.13",
|
|
43
|
+
"@japa/assert": "^1.3.6",
|
|
44
|
+
"@japa/run-failed-tests": "^1.1.0",
|
|
45
|
+
"@japa/runner": "^2.2.2",
|
|
46
|
+
"@japa/spec-reporter": "^1.3.2",
|
|
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": "^
|
|
50
|
+
"@types/node": "^18.11.0",
|
|
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.
|
|
56
|
-
"commitizen": "^4.2.
|
|
55
|
+
"autocannon": "^7.10.0",
|
|
56
|
+
"commitizen": "^4.2.5",
|
|
57
57
|
"cross-env": "^7.0.3",
|
|
58
58
|
"cz-conventional-changelog": "^3.3.0",
|
|
59
|
-
"del-cli": "^
|
|
60
|
-
"eslint": "^8.
|
|
59
|
+
"del-cli": "^5.0.0",
|
|
60
|
+
"eslint": "^8.25.0",
|
|
61
61
|
"eslint-config-prettier": "^8.5.0",
|
|
62
|
-
"eslint-plugin-adonis": "^2.1.
|
|
63
|
-
"eslint-plugin-prettier": "^4.
|
|
64
|
-
"fastify": "^
|
|
62
|
+
"eslint-plugin-adonis": "^2.1.1",
|
|
63
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
64
|
+
"fastify": "^4.9.0",
|
|
65
65
|
"github-label-sync": "^2.2.0",
|
|
66
66
|
"http-status-codes": "^2.2.0",
|
|
67
67
|
"husky": "^8.0.1",
|
|
68
|
-
"middie": "^
|
|
69
|
-
"mrm": "^4.
|
|
70
|
-
"np": "^7.6.
|
|
68
|
+
"middie": "^7.1.0",
|
|
69
|
+
"mrm": "^4.1.7",
|
|
70
|
+
"np": "^7.6.2",
|
|
71
71
|
"pem": "^1.14.6",
|
|
72
|
-
"prettier": "^2.
|
|
72
|
+
"prettier": "^2.7.1",
|
|
73
73
|
"reflect-metadata": "^0.1.13",
|
|
74
|
-
"supertest": "^6.
|
|
75
|
-
"ts-node": "^10.
|
|
76
|
-
"typescript": "^4.
|
|
74
|
+
"supertest": "^6.3.0",
|
|
75
|
+
"ts-node": "^10.9.1",
|
|
76
|
+
"typescript": "^4.8.4"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@adonisjs/application": "^5.0.0",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"@poppinss/matchit": "^3.1.2",
|
|
101
|
-
"@poppinss/utils": "^
|
|
101
|
+
"@poppinss/utils": "^5.0.0",
|
|
102
102
|
"accepts": "^1.3.8",
|
|
103
103
|
"co-compose": "^7.0.2",
|
|
104
104
|
"content-disposition": "^0.5.4",
|
|
@@ -108,13 +108,13 @@
|
|
|
108
108
|
"etag": "^1.8.1",
|
|
109
109
|
"fresh": "^0.5.2",
|
|
110
110
|
"haye": "^3.0.0",
|
|
111
|
-
"macroable": "^7.0.
|
|
111
|
+
"macroable": "^7.0.2",
|
|
112
112
|
"mime-types": "^2.1.35",
|
|
113
113
|
"ms": "^2.1.3",
|
|
114
114
|
"on-finished": "^2.4.1",
|
|
115
115
|
"pluralize": "^8.0.0",
|
|
116
116
|
"proxy-addr": "^2.0.7",
|
|
117
|
-
"qs": "^6.
|
|
117
|
+
"qs": "^6.11.0",
|
|
118
118
|
"tmp-cache": "^1.1.0",
|
|
119
119
|
"type-is": "^1.6.18",
|
|
120
120
|
"vary": "^1.1.2"
|