@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.
Files changed (74) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/body-parsers/body-parser.helpers.js +5 -2
  3. package/dist/body-parsers/body-parser.helpers.js.map +1 -1
  4. package/dist/body-parsers/body-parser.js +8 -4
  5. package/dist/body-parsers/body-parser.js.map +1 -1
  6. package/dist/coercion/coerce-parameter.js +9 -4
  7. package/dist/coercion/coerce-parameter.js.map +1 -1
  8. package/dist/coercion/utils.js +5 -2
  9. package/dist/coercion/utils.js.map +1 -1
  10. package/dist/coercion/validator.js +4 -2
  11. package/dist/coercion/validator.js.map +1 -1
  12. package/dist/index.d.ts +10 -10
  13. package/dist/index.js +13 -10
  14. package/dist/index.js.map +1 -1
  15. package/dist/keys.d.ts +1 -1
  16. package/dist/parser.js +7 -3
  17. package/dist/parser.js.map +1 -1
  18. package/dist/providers/log-error.provider.js +2 -1
  19. package/dist/providers/log-error.provider.js.map +1 -1
  20. package/dist/request-context.js +17 -11
  21. package/dist/request-context.js.map +1 -1
  22. package/dist/rest-http-error.d.ts +1 -1
  23. package/dist/rest-http-error.js +11 -8
  24. package/dist/rest-http-error.js.map +1 -1
  25. package/dist/rest.component.js +2 -1
  26. package/dist/rest.component.js.map +1 -1
  27. package/dist/rest.server.d.ts +2 -2
  28. package/dist/rest.server.js +20 -15
  29. package/dist/rest.server.js.map +1 -1
  30. package/dist/router/base-route.d.ts +8 -1
  31. package/dist/router/base-route.js +13 -0
  32. package/dist/router/base-route.js.map +1 -1
  33. package/dist/router/controller-route.js +10 -6
  34. package/dist/router/controller-route.js.map +1 -1
  35. package/dist/router/external-express-routes.d.ts +1 -1
  36. package/dist/router/external-express-routes.js +11 -8
  37. package/dist/router/external-express-routes.js.map +1 -1
  38. package/dist/router/handler-route.js +1 -1
  39. package/dist/router/handler-route.js.map +1 -1
  40. package/dist/router/router-base.js +2 -1
  41. package/dist/router/router-base.js.map +1 -1
  42. package/dist/router/routing-table.js +12 -8
  43. package/dist/router/routing-table.js.map +1 -1
  44. package/dist/router/trie-router.js +2 -1
  45. package/dist/router/trie-router.js.map +1 -1
  46. package/dist/types.d.ts +1 -1
  47. package/dist/validation/request-body.validator.js +19 -14
  48. package/dist/validation/request-body.validator.js.map +1 -1
  49. package/dist/writer.js +2 -1
  50. package/dist/writer.js.map +1 -1
  51. package/package.json +17 -17
  52. package/src/body-parsers/body-parser.helpers.ts +1 -1
  53. package/src/body-parsers/body-parser.ts +3 -3
  54. package/src/coercion/coerce-parameter.ts +3 -3
  55. package/src/coercion/utils.ts +1 -1
  56. package/src/coercion/validator.ts +2 -2
  57. package/src/index.ts +11 -14
  58. package/src/keys.ts +1 -1
  59. package/src/parser.ts +2 -2
  60. package/src/providers/log-error.provider.ts +1 -1
  61. package/src/request-context.ts +10 -10
  62. package/src/rest-http-error.ts +4 -5
  63. package/src/rest.component.ts +1 -1
  64. package/src/rest.server.ts +11 -11
  65. package/src/router/base-route.ts +13 -1
  66. package/src/router/controller-route.ts +7 -5
  67. package/src/router/external-express-routes.ts +3 -4
  68. package/src/router/handler-route.ts +8 -2
  69. package/src/router/router-base.ts +1 -1
  70. package/src/router/routing-table.ts +5 -5
  71. package/src/router/trie-router.ts +1 -1
  72. package/src/types.ts +1 -1
  73. package/src/validation/request-body.validator.ts +7 -7
  74. 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(requestContext, this, '_handler', args);
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 (verb && verb.toLowerCase()) || 'get';
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 * as assert from 'assert';
13
- import * as debugFactory from 'debug';
14
- import * as HttpErrors from 'http-errors';
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 => (p && p.name) || '')
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  import {Binding, BoundValue} from '@loopback/context';
7
7
  import {ReferenceObject, SchemaObject} from '@loopback/openapi-v3';
8
- import * as ajv from 'ajv';
8
+ import ajv from 'ajv';
9
9
  import {
10
10
  Options,
11
11
  OptionsJson,
@@ -10,10 +10,10 @@ import {
10
10
  SchemaObject,
11
11
  SchemasObject,
12
12
  } from '@loopback/openapi-v3';
13
- import * as AJV from 'ajv';
14
- import * as debugModule from 'debug';
15
- import * as _ from 'lodash';
16
- import * as util from 'util';
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 && requestBodySpec.required;
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 || DEFAULT_COMPILED_SCHEMA_CACHE;
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 || new Map();
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 (result && result.pipe) === 'function';
34
+ result instanceof Readable || typeof result?.pipe === 'function';
35
35
 
36
36
  if (isStream) {
37
37
  response.setHeader('Content-Type', 'application/octet-stream');