@loopback/rest 9.1.3 → 9.3.1
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/dist/body-parsers/body-parser.helpers.js.map +1 -1
- package/dist/body-parsers/body-parser.js.map +1 -1
- package/dist/body-parsers/body-parser.json.js.map +1 -1
- package/dist/coercion/coerce-parameter.js.map +1 -1
- package/dist/coercion/utils.js.map +1 -1
- package/dist/coercion/validator.js.map +1 -1
- package/dist/http-handler.js.map +1 -1
- package/dist/keys.js.map +1 -1
- package/dist/parse-json.js.map +1 -1
- package/dist/parser.js +3 -2
- package/dist/parser.js.map +1 -1
- package/dist/providers/log-error.provider.js.map +1 -1
- package/dist/providers/parse-params.provider.js.map +1 -1
- package/dist/request-context.js.map +1 -1
- package/dist/rest-http-error.js +2 -1
- package/dist/rest-http-error.js.map +1 -1
- package/dist/rest.component.js.map +1 -1
- package/dist/rest.server.js +4 -3
- package/dist/rest.server.js.map +1 -1
- package/dist/router/controller-route.js +2 -1
- package/dist/router/controller-route.js.map +1 -1
- package/dist/router/redirect-route.js.map +1 -1
- package/dist/router/router-base.js.map +1 -1
- package/dist/router/trie-router.js.map +1 -1
- package/dist/spec-enhancers/consolidate.spec-enhancer.js.map +1 -1
- package/dist/spec-enhancers/info.spec-enhancer.js.map +1 -1
- package/dist/validation/ajv-factory.provider.js.map +1 -1
- package/dist/validation/request-body.validator.js.map +1 -1
- package/dist/writer.js.map +1 -1
- package/package.json +40 -40
- package/src/body-parsers/body-parser.helpers.ts +1 -1
- package/src/coercion/utils.ts +2 -1
- package/src/keys.ts +12 -15
- package/src/parser.ts +4 -2
- package/src/request-context.ts +2 -1
- package/src/rest.server.ts +5 -4
- package/CHANGELOG.md +0 -2172
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/rest",
|
|
3
|
-
"version": "9.1.3",
|
|
4
3
|
"description": "Expose controllers as REST endpoints and route REST API requests to controller methods",
|
|
4
|
+
"version": "9.3.1",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"author": "IBM Corp.",
|
|
9
|
+
"copyright.owner": "IBM Corp.",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/strongloop/loopback-next.git",
|
|
13
|
+
"directory": "packages/rest"
|
|
14
|
+
},
|
|
7
15
|
"engines": {
|
|
8
|
-
"node": "^10.16 || 12 || 14 ||
|
|
16
|
+
"node": "^10.16 || 12 || 14 || 16"
|
|
9
17
|
},
|
|
10
18
|
"scripts": {
|
|
11
19
|
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
|
|
@@ -17,24 +25,27 @@
|
|
|
17
25
|
"unit": "lb-mocha \"dist/__tests__/unit/**/*.js\"",
|
|
18
26
|
"verify": "npm pack && tar xf loopback-rest*.tgz && tree package && npm run clean"
|
|
19
27
|
},
|
|
20
|
-
"author": "IBM Corp.",
|
|
21
|
-
"copyright.owner": "IBM Corp.",
|
|
22
|
-
"license": "MIT",
|
|
23
28
|
"publishConfig": {
|
|
24
29
|
"access": "public"
|
|
25
30
|
},
|
|
31
|
+
"files": [
|
|
32
|
+
"README.md",
|
|
33
|
+
"dist",
|
|
34
|
+
"src",
|
|
35
|
+
"!*/__tests__"
|
|
36
|
+
],
|
|
26
37
|
"peerDependencies": {
|
|
27
|
-
"@loopback/core": "^2.
|
|
38
|
+
"@loopback/core": "^2.16.1"
|
|
28
39
|
},
|
|
29
40
|
"dependencies": {
|
|
30
|
-
"@loopback/express": "^3.1
|
|
31
|
-
"@loopback/http-server": "^2.
|
|
32
|
-
"@loopback/openapi-v3": "^5.1
|
|
33
|
-
"@openapi-contrib/openapi-schema-to-json-schema": "^3.0
|
|
41
|
+
"@loopback/express": "^3.3.1",
|
|
42
|
+
"@loopback/http-server": "^2.5.1",
|
|
43
|
+
"@loopback/openapi-v3": "^5.3.1",
|
|
44
|
+
"@openapi-contrib/openapi-schema-to-json-schema": "^3.1.0",
|
|
34
45
|
"@types/body-parser": "^1.19.0",
|
|
35
|
-
"@types/cors": "^2.8.
|
|
36
|
-
"@types/express": "^4.17.
|
|
37
|
-
"@types/express-serve-static-core": "^4.17.
|
|
46
|
+
"@types/cors": "^2.8.10",
|
|
47
|
+
"@types/express": "^4.17.12",
|
|
48
|
+
"@types/express-serve-static-core": "^4.17.21",
|
|
38
49
|
"@types/http-errors": "^1.8.0",
|
|
39
50
|
"@types/on-finished": "^2.3.1",
|
|
40
51
|
"@types/serve-static": "1.13.9",
|
|
@@ -47,44 +58,33 @@
|
|
|
47
58
|
"debug": "^4.3.1",
|
|
48
59
|
"express": "^4.17.1",
|
|
49
60
|
"http-errors": "^1.8.0",
|
|
50
|
-
"js-yaml": "^
|
|
61
|
+
"js-yaml": "^4.1.0",
|
|
51
62
|
"json-schema-compare": "^0.2.2",
|
|
52
|
-
"lodash": "^4.17.
|
|
63
|
+
"lodash": "^4.17.21",
|
|
53
64
|
"on-finished": "^2.3.0",
|
|
54
65
|
"path-to-regexp": "^6.2.0",
|
|
55
|
-
"qs": "^6.
|
|
66
|
+
"qs": "^6.10.1",
|
|
56
67
|
"strong-error-handler": "^4.0.0",
|
|
57
|
-
"tslib": "^2.
|
|
68
|
+
"tslib": "^2.2.0",
|
|
58
69
|
"type-is": "^1.6.18",
|
|
59
|
-
"validator": "^13.
|
|
70
|
+
"validator": "^13.6.0"
|
|
60
71
|
},
|
|
61
72
|
"devDependencies": {
|
|
62
|
-
"@loopback/build": "^6.
|
|
63
|
-
"@loopback/core": "^2.
|
|
64
|
-
"@loopback/eslint-config": "^10.
|
|
65
|
-
"@loopback/openapi-spec-builder": "^3.
|
|
66
|
-
"@loopback/repository": "^3.
|
|
67
|
-
"@loopback/testlab": "^3.
|
|
73
|
+
"@loopback/build": "^6.4.1",
|
|
74
|
+
"@loopback/core": "^2.16.1",
|
|
75
|
+
"@loopback/eslint-config": "^10.2.1",
|
|
76
|
+
"@loopback/openapi-spec-builder": "^3.2.1",
|
|
77
|
+
"@loopback/repository": "^3.7.0",
|
|
78
|
+
"@loopback/testlab": "^3.4.1",
|
|
68
79
|
"@types/debug": "^4.1.5",
|
|
69
|
-
"@types/js-yaml": "^
|
|
80
|
+
"@types/js-yaml": "^4.0.1",
|
|
70
81
|
"@types/json-schema-compare": "^0.2.0",
|
|
71
|
-
"@types/lodash": "^4.14.
|
|
82
|
+
"@types/lodash": "^4.14.170",
|
|
72
83
|
"@types/multer": "^1.4.5",
|
|
73
|
-
"@types/node": "^10.17.
|
|
84
|
+
"@types/node": "^10.17.60",
|
|
74
85
|
"@types/on-finished": "^2.3.1",
|
|
75
|
-
"@types/qs": "^6.9.
|
|
86
|
+
"@types/qs": "^6.9.6",
|
|
76
87
|
"multer": "^1.4.2"
|
|
77
88
|
},
|
|
78
|
-
"
|
|
79
|
-
"README.md",
|
|
80
|
-
"dist",
|
|
81
|
-
"src",
|
|
82
|
-
"!*/__tests__"
|
|
83
|
-
],
|
|
84
|
-
"repository": {
|
|
85
|
-
"type": "git",
|
|
86
|
-
"url": "https://github.com/strongloop/loopback-next.git",
|
|
87
|
-
"directory": "packages/rest"
|
|
88
|
-
},
|
|
89
|
-
"gitHead": "0fcf97fa1e87457de85f8f1b6b5cbf9f4f0bd640"
|
|
89
|
+
"gitHead": "2a3b684ec76fa299d80b099abbf101358538cb75"
|
|
90
90
|
}
|
|
@@ -56,7 +56,7 @@ export function invokeBodyParserMiddleware(
|
|
|
56
56
|
request: Request,
|
|
57
57
|
): Promise<any> {
|
|
58
58
|
// A hack to fool TypeScript as we don't need `response`
|
|
59
|
-
const response =
|
|
59
|
+
const response = {} as any as Response;
|
|
60
60
|
return new Promise<void>((resolve, reject) => {
|
|
61
61
|
handle(request, response, err => {
|
|
62
62
|
if (err) {
|
package/src/coercion/utils.ts
CHANGED
|
@@ -51,7 +51,8 @@ export function isValidDateTime(data: Date) {
|
|
|
51
51
|
return isNaN(data.getTime()) ? false : true;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const REGEX_RFC3339_DATE =
|
|
54
|
+
const REGEX_RFC3339_DATE =
|
|
55
|
+
/^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/;
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Return true when a date follows the RFC3339 standard
|
package/src/keys.ts
CHANGED
|
@@ -36,9 +36,8 @@ export namespace RestBindings {
|
|
|
36
36
|
/**
|
|
37
37
|
* Binding key for setting and injecting RestComponentConfig
|
|
38
38
|
*/
|
|
39
|
-
export const CONFIG: BindingKey<RestServerConfig> =
|
|
40
|
-
'rest'
|
|
41
|
-
);
|
|
39
|
+
export const CONFIG: BindingKey<RestServerConfig> =
|
|
40
|
+
CoreBindings.APPLICATION_CONFIG.deepProperty('rest');
|
|
42
41
|
/**
|
|
43
42
|
* Binding key for setting and injecting the host name of RestServer
|
|
44
43
|
*/
|
|
@@ -62,9 +61,8 @@ export namespace RestBindings {
|
|
|
62
61
|
/**
|
|
63
62
|
* Binding key for HTTPS options
|
|
64
63
|
*/
|
|
65
|
-
export const HTTPS_OPTIONS =
|
|
66
|
-
'rest.httpsOptions'
|
|
67
|
-
);
|
|
64
|
+
export const HTTPS_OPTIONS =
|
|
65
|
+
BindingKey.create<https.ServerOptions>('rest.httpsOptions');
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* Binding key for the server itself
|
|
@@ -105,9 +103,10 @@ export namespace RestBindings {
|
|
|
105
103
|
/**
|
|
106
104
|
* Binding key for request body parser options
|
|
107
105
|
*/
|
|
108
|
-
export const REQUEST_BODY_PARSER_OPTIONS =
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
export const REQUEST_BODY_PARSER_OPTIONS =
|
|
107
|
+
BindingKey.create<RequestBodyParserOptions>(
|
|
108
|
+
'rest.requestBodyParserOptions',
|
|
109
|
+
);
|
|
111
110
|
|
|
112
111
|
/**
|
|
113
112
|
* Binding key for request body parser
|
|
@@ -165,9 +164,8 @@ export namespace RestBindings {
|
|
|
165
164
|
/**
|
|
166
165
|
* Binding key for setting and injecting an OpenAPI spec
|
|
167
166
|
*/
|
|
168
|
-
export const API_SPEC: BindingKey<OpenApiSpec> =
|
|
169
|
-
'rest.apiSpec'
|
|
170
|
-
);
|
|
167
|
+
export const API_SPEC: BindingKey<OpenApiSpec> =
|
|
168
|
+
BindingKey.create<OpenApiSpec>('rest.apiSpec');
|
|
171
169
|
|
|
172
170
|
/**
|
|
173
171
|
* Binding key for setting and injecting an OpenAPI operation spec
|
|
@@ -256,9 +254,8 @@ export namespace RestBindings {
|
|
|
256
254
|
/**
|
|
257
255
|
* Binding key for setting and injecting the http request
|
|
258
256
|
*/
|
|
259
|
-
export const REQUEST: BindingKey<Request> =
|
|
260
|
-
'rest.http.request'
|
|
261
|
-
);
|
|
257
|
+
export const REQUEST: BindingKey<Request> =
|
|
258
|
+
BindingKey.create<Request>('rest.http.request');
|
|
262
259
|
/**
|
|
263
260
|
* Binding key for setting and injecting the http response
|
|
264
261
|
*/
|
package/src/parser.ts
CHANGED
|
@@ -71,7 +71,7 @@ async function buildOperationArguments(
|
|
|
71
71
|
throw new Error('$ref requestBody is not supported yet.');
|
|
72
72
|
}
|
|
73
73
|
const i = operationSpec.requestBody[REQUEST_BODY_INDEX];
|
|
74
|
-
requestBodyIndex = i ? i : 0;
|
|
74
|
+
requestBodyIndex = i != null ? i : 0;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const paramArgs: OperationArgs = [];
|
|
@@ -96,7 +96,9 @@ async function buildOperationArguments(
|
|
|
96
96
|
options,
|
|
97
97
|
);
|
|
98
98
|
|
|
99
|
-
if (requestBodyIndex
|
|
99
|
+
if (requestBodyIndex >= 0) {
|
|
100
|
+
paramArgs.splice(requestBodyIndex, 0, body.value);
|
|
101
|
+
}
|
|
100
102
|
return paramArgs;
|
|
101
103
|
}
|
|
102
104
|
|
package/src/request-context.ts
CHANGED
|
@@ -19,7 +19,8 @@ import {RestServerResolvedConfig} from './rest.server';
|
|
|
19
19
|
*/
|
|
20
20
|
export class RequestContext
|
|
21
21
|
extends MiddlewareContext
|
|
22
|
-
implements HandlerContext
|
|
22
|
+
implements HandlerContext
|
|
23
|
+
{
|
|
23
24
|
/**
|
|
24
25
|
* Get the protocol used by the client to make the request.
|
|
25
26
|
* Please note this protocol may be different from what we are observing
|
package/src/rest.server.ts
CHANGED
|
@@ -38,7 +38,7 @@ import {PathParams} from 'express-serve-static-core';
|
|
|
38
38
|
import fs from 'fs';
|
|
39
39
|
import {IncomingMessage, ServerResponse} from 'http';
|
|
40
40
|
import {ServerOptions} from 'https';
|
|
41
|
-
import {
|
|
41
|
+
import {dump} from 'js-yaml';
|
|
42
42
|
import {cloneDeep} from 'lodash';
|
|
43
43
|
import {ServeStaticOptions} from 'serve-static';
|
|
44
44
|
import {writeErrorToResponse} from 'strong-error-handler';
|
|
@@ -113,7 +113,8 @@ const SequenceActions = RestBindings.SequenceActions;
|
|
|
113
113
|
*/
|
|
114
114
|
export class RestServer
|
|
115
115
|
extends BaseMiddlewareRegistry
|
|
116
|
-
implements Server, HttpServerLike
|
|
116
|
+
implements Server, HttpServerLike
|
|
117
|
+
{
|
|
117
118
|
/**
|
|
118
119
|
* Handle incoming HTTP(S) request by invoking the corresponding
|
|
119
120
|
* Controller method via the configured Sequence.
|
|
@@ -553,7 +554,7 @@ export class RestServer
|
|
|
553
554
|
response.setHeader('content-type', 'application/json; charset=utf-8');
|
|
554
555
|
response.end(spec, 'utf-8');
|
|
555
556
|
} else {
|
|
556
|
-
const yaml =
|
|
557
|
+
const yaml = dump(specObj, {});
|
|
557
558
|
response.setHeader('content-type', 'text/yaml; charset=utf-8');
|
|
558
559
|
response.end(yaml, 'utf-8');
|
|
559
560
|
}
|
|
@@ -1045,7 +1046,7 @@ export class RestServer
|
|
|
1045
1046
|
}
|
|
1046
1047
|
const fileName = outFile.toLowerCase();
|
|
1047
1048
|
if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
|
|
1048
|
-
const yaml =
|
|
1049
|
+
const yaml = dump(spec);
|
|
1049
1050
|
fs.writeFileSync(outFile, yaml, 'utf-8');
|
|
1050
1051
|
} else {
|
|
1051
1052
|
const json = JSON.stringify(spec, null, 2);
|