@loopback/rest 1.24.0 → 1.26.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/CHANGELOG.md +38 -0
- package/dist/body-parsers/body-parser.helpers.js +5 -2
- package/dist/body-parsers/body-parser.helpers.js.map +1 -1
- package/dist/body-parsers/body-parser.js +8 -4
- package/dist/body-parsers/body-parser.js.map +1 -1
- package/dist/coercion/coerce-parameter.js +9 -4
- package/dist/coercion/coerce-parameter.js.map +1 -1
- package/dist/coercion/utils.js +5 -2
- package/dist/coercion/utils.js.map +1 -1
- package/dist/coercion/validator.js +4 -2
- package/dist/coercion/validator.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +1 -1
- package/dist/parser.js +7 -3
- package/dist/parser.js.map +1 -1
- package/dist/providers/log-error.provider.js +2 -1
- package/dist/providers/log-error.provider.js.map +1 -1
- package/dist/request-context.js +17 -11
- package/dist/request-context.js.map +1 -1
- package/dist/rest-http-error.d.ts +1 -1
- package/dist/rest-http-error.js +11 -8
- package/dist/rest-http-error.js.map +1 -1
- package/dist/rest.component.js +2 -1
- package/dist/rest.component.js.map +1 -1
- package/dist/rest.server.d.ts +2 -2
- package/dist/rest.server.js +20 -15
- package/dist/rest.server.js.map +1 -1
- package/dist/router/base-route.d.ts +8 -1
- package/dist/router/base-route.js +13 -0
- package/dist/router/base-route.js.map +1 -1
- package/dist/router/controller-route.js +10 -6
- package/dist/router/controller-route.js.map +1 -1
- package/dist/router/external-express-routes.d.ts +1 -1
- package/dist/router/external-express-routes.js +11 -8
- package/dist/router/external-express-routes.js.map +1 -1
- package/dist/router/handler-route.js +1 -1
- package/dist/router/handler-route.js.map +1 -1
- package/dist/router/router-base.js +2 -1
- package/dist/router/router-base.js.map +1 -1
- package/dist/router/routing-table.js +12 -8
- package/dist/router/routing-table.js.map +1 -1
- package/dist/router/trie-router.js +2 -1
- package/dist/router/trie-router.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/validation/request-body.validator.js +19 -14
- package/dist/validation/request-body.validator.js.map +1 -1
- package/dist/writer.js +2 -1
- package/dist/writer.js.map +1 -1
- package/package.json +17 -17
- package/src/body-parsers/body-parser.helpers.ts +1 -1
- package/src/body-parsers/body-parser.ts +3 -3
- package/src/coercion/coerce-parameter.ts +3 -3
- package/src/coercion/utils.ts +1 -1
- package/src/coercion/validator.ts +2 -2
- package/src/index.ts +11 -14
- package/src/keys.ts +1 -1
- package/src/parser.ts +2 -2
- package/src/providers/log-error.provider.ts +1 -1
- package/src/request-context.ts +10 -10
- package/src/rest-http-error.ts +4 -5
- package/src/rest.component.ts +1 -1
- package/src/rest.server.ts +11 -11
- package/src/router/base-route.ts +13 -1
- package/src/router/controller-route.ts +7 -5
- package/src/router/external-express-routes.ts +3 -4
- package/src/router/handler-route.ts +8 -2
- package/src/router/router-base.ts +1 -1
- package/src/router/routing-table.ts +5 -5
- package/src/router/trie-router.ts +1 -1
- package/src/types.ts +1 -1
- package/src/validation/request-body.validator.ts +7 -7
- package/src/writer.ts +1 -1
|
@@ -7,7 +7,7 @@ import {Context, invokeMethodWithInterceptors} from '@loopback/context';
|
|
|
7
7
|
import {OperationObject} from '@loopback/openapi-v3';
|
|
8
8
|
import {RestBindings} from '../keys';
|
|
9
9
|
import {OperationArgs, OperationRetval} from '../types';
|
|
10
|
-
import {BaseRoute} from './base-route';
|
|
10
|
+
import {BaseRoute, RouteSource} from './base-route';
|
|
11
11
|
|
|
12
12
|
export class Route extends BaseRoute {
|
|
13
13
|
constructor(
|
|
@@ -33,6 +33,12 @@ export class Route extends BaseRoute {
|
|
|
33
33
|
): Promise<OperationRetval> {
|
|
34
34
|
// Use `invokeMethodWithInterceptors` to invoke the handler function so
|
|
35
35
|
// that global interceptors are applied
|
|
36
|
-
return invokeMethodWithInterceptors(
|
|
36
|
+
return invokeMethodWithInterceptors(
|
|
37
|
+
requestContext,
|
|
38
|
+
this,
|
|
39
|
+
'_handler',
|
|
40
|
+
args,
|
|
41
|
+
{source: new RouteSource(this)},
|
|
42
|
+
);
|
|
37
43
|
}
|
|
38
44
|
}
|
|
@@ -109,7 +109,7 @@ export abstract class BaseRouter implements RestRouter {
|
|
|
109
109
|
*/
|
|
110
110
|
function normalizeVerb(verb: string) {
|
|
111
111
|
// Use lower case, default to `get`
|
|
112
|
-
return
|
|
112
|
+
return verb?.toLowerCase() || 'get';
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
ParameterObject,
|
|
10
10
|
PathObject,
|
|
11
11
|
} from '@loopback/openapi-v3';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
12
|
+
import assert from 'assert';
|
|
13
|
+
import debugFactory from 'debug';
|
|
14
|
+
import HttpErrors from 'http-errors';
|
|
15
15
|
import {inspect} from 'util';
|
|
16
16
|
import {Request} from '../types';
|
|
17
17
|
import {
|
|
@@ -57,7 +57,7 @@ export class RoutingTable {
|
|
|
57
57
|
|
|
58
58
|
debug('Registering Controller with API %s', inspect(spec, {depth: null}));
|
|
59
59
|
|
|
60
|
-
const basePath = spec.basePath
|
|
60
|
+
const basePath = spec.basePath ?? '/';
|
|
61
61
|
for (const p in spec.paths) {
|
|
62
62
|
for (const verb in spec.paths[p]) {
|
|
63
63
|
const opSpec: OperationObject = spec.paths[p][verb];
|
|
@@ -154,6 +154,6 @@ export class RoutingTable {
|
|
|
154
154
|
|
|
155
155
|
function describeOperationParameters(opSpec: OperationObject) {
|
|
156
156
|
return ((opSpec.parameters as ParameterObject[]) || [])
|
|
157
|
-
.map(p =>
|
|
157
|
+
.map(p => p?.name || '')
|
|
158
158
|
.join(', ');
|
|
159
159
|
}
|
|
@@ -42,7 +42,7 @@ export class TrieRouter extends BaseRouter {
|
|
|
42
42
|
const route = found.node.value!;
|
|
43
43
|
if (route) {
|
|
44
44
|
debug('Route found: %s', inspect(route, {depth: 5}));
|
|
45
|
-
return createResolvedRoute(route, found.params
|
|
45
|
+
return createResolvedRoute(route, found.params ?? {});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
return undefined;
|
package/src/types.ts
CHANGED
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
SchemaObject,
|
|
11
11
|
SchemasObject,
|
|
12
12
|
} from '@loopback/openapi-v3';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
13
|
+
import AJV from 'ajv';
|
|
14
|
+
import debugModule from 'debug';
|
|
15
|
+
import _ from 'lodash';
|
|
16
|
+
import util from 'util';
|
|
17
17
|
import {HttpErrors, RequestBody, RestHttpErrors} from '..';
|
|
18
18
|
import {RequestBodyValidationOptions, SchemaValidatorCache} from '../types';
|
|
19
19
|
|
|
@@ -38,7 +38,7 @@ export function validateRequestBody(
|
|
|
38
38
|
globalSchemas: SchemasObject = {},
|
|
39
39
|
options: RequestBodyValidationOptions = {},
|
|
40
40
|
) {
|
|
41
|
-
const required = requestBodySpec
|
|
41
|
+
const required = requestBodySpec?.required;
|
|
42
42
|
|
|
43
43
|
if (required && body.value == null) {
|
|
44
44
|
const err = Object.assign(
|
|
@@ -125,7 +125,7 @@ function validateValueAgainstSchema(
|
|
|
125
125
|
) {
|
|
126
126
|
let validate: AJV.ValidateFunction | undefined;
|
|
127
127
|
|
|
128
|
-
const cache = options.compiledSchemaCache
|
|
128
|
+
const cache = options.compiledSchemaCache ?? DEFAULT_COMPILED_SCHEMA_CACHE;
|
|
129
129
|
const key = getKeyForOptions(options);
|
|
130
130
|
|
|
131
131
|
let validatorMap: Map<string, AJV.ValidateFunction> | undefined;
|
|
@@ -136,7 +136,7 @@ function validateValueAgainstSchema(
|
|
|
136
136
|
|
|
137
137
|
if (!validate) {
|
|
138
138
|
validate = createValidator(schema, globalSchemas, options);
|
|
139
|
-
validatorMap = validatorMap
|
|
139
|
+
validatorMap = validatorMap ?? new Map();
|
|
140
140
|
validatorMap.set(key, validate);
|
|
141
141
|
cache.set(schema, validatorMap);
|
|
142
142
|
}
|
package/src/writer.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function writeResultToResponse(
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const isStream =
|
|
34
|
-
result instanceof Readable || typeof
|
|
34
|
+
result instanceof Readable || typeof result?.pipe === 'function';
|
|
35
35
|
|
|
36
36
|
if (isStream) {
|
|
37
37
|
response.setHeader('Content-Type', 'application/octet-stream');
|