@nestjs/core 9.4.3 → 10.0.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 (69) hide show
  1. package/adapters/http-adapter.d.ts +2 -0
  2. package/adapters/http-adapter.js +3 -0
  3. package/discovery/discovery-module.js +2 -3
  4. package/discovery/discovery-service.js +2 -3
  5. package/errors/exception-handler.js +1 -1
  6. package/errors/exceptions-zone.js +1 -1
  7. package/errors/messages.js +7 -8
  8. package/exceptions/base-exception-filter.js +2 -2
  9. package/exceptions/exceptions-handler.d.ts +1 -1
  10. package/exceptions/exceptions-handler.js +3 -6
  11. package/exceptions/external-exception-filter.js +1 -1
  12. package/exceptions/external-exceptions-handler.d.ts +1 -1
  13. package/exceptions/external-exceptions-handler.js +3 -6
  14. package/helpers/context-id-factory.js +1 -2
  15. package/helpers/context-utils.js +4 -1
  16. package/helpers/execution-context-host.js +1 -0
  17. package/injector/abstract-instance-resolver.js +1 -1
  18. package/injector/compiler.js +2 -3
  19. package/injector/container.d.ts +6 -1
  20. package/injector/container.js +23 -3
  21. package/injector/helpers/provider-classifier.js +2 -2
  22. package/injector/helpers/transient-instances.d.ts +3 -3
  23. package/injector/injector.d.ts +7 -7
  24. package/injector/injector.js +24 -20
  25. package/injector/instance-links-host.d.ts +4 -4
  26. package/injector/instance-links-host.js +1 -1
  27. package/injector/instance-wrapper.d.ts +4 -4
  28. package/injector/instance-wrapper.js +17 -10
  29. package/injector/internal-core-module/internal-core-module-factory.d.ts +2 -1
  30. package/injector/internal-core-module/internal-core-module-factory.js +2 -6
  31. package/injector/internal-core-module/internal-core-module.js +2 -3
  32. package/injector/lazy-module-loader/lazy-module-loader.d.ts +3 -1
  33. package/injector/lazy-module-loader/lazy-module-loader.js +7 -3
  34. package/injector/module.d.ts +12 -29
  35. package/injector/module.js +14 -32
  36. package/inspector/deterministic-uuid-registry.js +1 -1
  37. package/inspector/graph-inspector.js +18 -14
  38. package/inspector/initialize-on-preview.allowlist.js +1 -1
  39. package/inspector/partial-graph.host.js +2 -4
  40. package/inspector/serialized-graph.js +15 -8
  41. package/inspector/uuid-factory.js +2 -2
  42. package/interceptors/interceptors-consumer.js +4 -5
  43. package/middleware/builder.js +26 -3
  44. package/middleware/container.d.ts +2 -2
  45. package/middleware/container.js +1 -2
  46. package/middleware/middleware-module.js +4 -4
  47. package/middleware/route-info-path-extractor.js +1 -2
  48. package/middleware/routes-mapper.d.ts +5 -2
  49. package/middleware/routes-mapper.js +45 -26
  50. package/middleware/utils.js +2 -3
  51. package/nest-application-context.js +3 -5
  52. package/nest-application.js +9 -10
  53. package/nest-factory.js +3 -3
  54. package/package.json +6 -6
  55. package/repl/native-functions/help-repl-fn.js +1 -1
  56. package/repl/native-functions/methods-repl-fn.js +1 -1
  57. package/repl/repl-context.js +6 -5
  58. package/repl/repl-logger.js +1 -1
  59. package/repl/repl-native-commands.js +1 -1
  60. package/router/route-path-factory.d.ts +4 -2
  61. package/router/route-path-factory.js +20 -4
  62. package/router/router-execution-context.js +1 -2
  63. package/router/router-explorer.js +12 -2
  64. package/router/router-module.js +8 -6
  65. package/router/routes-resolver.js +3 -3
  66. package/router/sse-stream.js +9 -4
  67. package/scanner.d.ts +17 -3
  68. package/scanner.js +49 -10
  69. package/services/reflector.service.js +4 -1
@@ -25,6 +25,8 @@ export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any,
25
25
  patch(path: any, handler: RequestHandler): any;
26
26
  all(handler: RequestHandler): any;
27
27
  all(path: any, handler: RequestHandler): any;
28
+ search(port: string | number, callback?: () => void): any;
29
+ search(port: string | number, hostname: string, callback?: () => void): any;
28
30
  options(handler: RequestHandler): any;
29
31
  options(path: any, handler: RequestHandler): any;
30
32
  listen(port: string | number, callback?: () => void): any;
@@ -34,6 +34,9 @@ class AbstractHttpAdapter {
34
34
  all(...args) {
35
35
  return this.instance.all(...args);
36
36
  }
37
+ search(port, hostname, callback) {
38
+ return this.instance.search(port, hostname, callback);
39
+ }
37
40
  options(...args) {
38
41
  return this.instance.options(...args);
39
42
  }
@@ -8,12 +8,11 @@ const discovery_service_1 = require("./discovery-service");
8
8
  /**
9
9
  * @publicApi
10
10
  */
11
- let DiscoveryModule = class DiscoveryModule {
11
+ let DiscoveryModule = exports.DiscoveryModule = class DiscoveryModule {
12
12
  };
13
- DiscoveryModule = tslib_1.__decorate([
13
+ exports.DiscoveryModule = DiscoveryModule = tslib_1.__decorate([
14
14
  (0, common_1.Module)({
15
15
  providers: [metadata_scanner_1.MetadataScanner, discovery_service_1.DiscoveryService],
16
16
  exports: [metadata_scanner_1.MetadataScanner, discovery_service_1.DiscoveryService],
17
17
  })
18
18
  ], DiscoveryModule);
19
- exports.DiscoveryModule = DiscoveryModule;
@@ -7,7 +7,7 @@ const modules_container_1 = require("../injector/modules-container");
7
7
  /**
8
8
  * @publicApi
9
9
  */
10
- let DiscoveryService = class DiscoveryService {
10
+ let DiscoveryService = exports.DiscoveryService = class DiscoveryService {
11
11
  constructor(modulesContainer) {
12
12
  this.modulesContainer = modulesContainer;
13
13
  }
@@ -32,8 +32,7 @@ let DiscoveryService = class DiscoveryService {
32
32
  return moduleRefs.filter(({ metatype }) => include.some(item => item === metatype));
33
33
  }
34
34
  };
35
- DiscoveryService = tslib_1.__decorate([
35
+ exports.DiscoveryService = DiscoveryService = tslib_1.__decorate([
36
36
  (0, common_1.Injectable)(),
37
37
  tslib_1.__metadata("design:paramtypes", [modules_container_1.ModulesContainer])
38
38
  ], DiscoveryService);
39
- exports.DiscoveryService = DiscoveryService;
@@ -12,5 +12,5 @@ class ExceptionHandler {
12
12
  ExceptionHandler.logger.error(exception.what(), exception.stack);
13
13
  }
14
14
  }
15
- ExceptionHandler.logger = new logger_service_1.Logger(ExceptionHandler.name);
16
15
  exports.ExceptionHandler = ExceptionHandler;
16
+ ExceptionHandler.logger = new logger_service_1.Logger(ExceptionHandler.name);
@@ -30,5 +30,5 @@ class ExceptionsZone {
30
30
  }
31
31
  }
32
32
  }
33
- ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();
34
33
  exports.ExceptionsZone = ExceptionsZone;
34
+ ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();
@@ -7,14 +7,13 @@ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
7
7
  * @param instance The instance which should get the name from
8
8
  */
9
9
  const getInstanceName = (instance) => {
10
- var _a, _b;
11
- if (instance === null || instance === void 0 ? void 0 : instance.forwardRef) {
12
- return (_a = instance.forwardRef()) === null || _a === void 0 ? void 0 : _a.name;
10
+ if (instance?.forwardRef) {
11
+ return instance.forwardRef()?.name;
13
12
  }
14
- if (instance === null || instance === void 0 ? void 0 : instance.module) {
15
- return (_b = instance.module) === null || _b === void 0 ? void 0 : _b.name;
13
+ if (instance?.module) {
14
+ return instance.module?.name;
16
15
  }
17
- return instance === null || instance === void 0 ? void 0 : instance.name;
16
+ return instance?.name;
18
17
  };
19
18
  /**
20
19
  * Returns the name of the dependency
@@ -85,7 +84,7 @@ Scope [${stringifyScope(scope)}]
85
84
  `;
86
85
  exports.UNDEFINED_FORWARDREF_MESSAGE = UNDEFINED_FORWARDREF_MESSAGE;
87
86
  const INVALID_MODULE_MESSAGE = (parentModule, index, scope) => {
88
- const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
87
+ const parentModuleName = parentModule?.name || 'module';
89
88
  return `Nest cannot create the ${parentModuleName} instance.
90
89
  Received an unexpected value at index [${index}] of the ${parentModuleName} "imports" array.
91
90
 
@@ -102,7 +101,7 @@ Scope [${stringifyScope(scope)}]
102
101
  };
103
102
  exports.USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = USING_INVALID_CLASS_AS_A_MODULE_MESSAGE;
104
103
  const UNDEFINED_MODULE_MESSAGE = (parentModule, index, scope) => {
105
- const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
104
+ const parentModuleName = parentModule?.name || 'module';
106
105
  return `Nest cannot create the ${parentModuleName} instance.
107
106
  The module at index [${index}] of the ${parentModuleName} "imports" array is undefined.
108
107
 
@@ -61,13 +61,13 @@ class BaseExceptionFilter {
61
61
  * @param err error object
62
62
  */
63
63
  isHttpError(err) {
64
- return (err === null || err === void 0 ? void 0 : err.statusCode) && (err === null || err === void 0 ? void 0 : err.message);
64
+ return err?.statusCode && err?.message;
65
65
  }
66
66
  }
67
+ exports.BaseExceptionFilter = BaseExceptionFilter;
67
68
  BaseExceptionFilter.logger = new common_1.Logger('ExceptionsHandler');
68
69
  tslib_1.__decorate([
69
70
  (0, common_1.Optional)(),
70
71
  (0, common_1.Inject)(),
71
72
  tslib_1.__metadata("design:type", http_adapter_host_1.HttpAdapterHost)
72
73
  ], BaseExceptionFilter.prototype, "httpAdapterHost", void 0);
73
- exports.BaseExceptionFilter = BaseExceptionFilter;
@@ -1,6 +1,6 @@
1
1
  import { HttpException } from '@nestjs/common';
2
- import { ExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions/exception-filter-metadata.interface';
3
2
  import { ArgumentsHost } from '@nestjs/common/interfaces/features/arguments-host.interface';
3
+ import { ExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions/exception-filter-metadata.interface';
4
4
  import { BaseExceptionFilter } from './base-exception-filter';
5
5
  export declare class ExceptionsHandler extends BaseExceptionFilter {
6
6
  private filters;
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExceptionsHandler = void 0;
4
4
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
- const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
5
+ const select_exception_filter_metadata_util_1 = require("@nestjs/common/utils/select-exception-filter-metadata.util");
6
6
  const base_exception_filter_1 = require("./base-exception-filter");
7
+ const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
7
8
  class ExceptionsHandler extends base_exception_filter_1.BaseExceptionFilter {
8
9
  constructor() {
9
10
  super(...arguments);
@@ -25,11 +26,7 @@ class ExceptionsHandler extends base_exception_filter_1.BaseExceptionFilter {
25
26
  if ((0, shared_utils_1.isEmpty)(this.filters)) {
26
27
  return false;
27
28
  }
28
- const isInstanceOf = (metatype) => exception instanceof metatype;
29
- const filter = this.filters.find(({ exceptionMetatypes }) => {
30
- const typeExists = !exceptionMetatypes.length || exceptionMetatypes.some(isInstanceOf);
31
- return typeExists;
32
- });
29
+ const filter = (0, select_exception_filter_metadata_util_1.selectExceptionFilterMetadata)(this.filters, exception);
33
30
  filter && filter.func(exception, ctx);
34
31
  return !!filter;
35
32
  }
@@ -10,5 +10,5 @@ class ExternalExceptionFilter {
10
10
  throw exception;
11
11
  }
12
12
  }
13
- ExternalExceptionFilter.logger = new common_1.Logger('ExceptionsHandler');
14
13
  exports.ExternalExceptionFilter = ExternalExceptionFilter;
14
+ ExternalExceptionFilter.logger = new common_1.Logger('ExceptionsHandler');
@@ -1,5 +1,5 @@
1
- import { ExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions';
2
1
  import { ArgumentsHost } from '@nestjs/common/interfaces/features/arguments-host.interface';
2
+ import { ExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions';
3
3
  import { ExternalExceptionFilter } from './external-exception-filter';
4
4
  export declare class ExternalExceptionsHandler extends ExternalExceptionFilter {
5
5
  private filters;
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExternalExceptionsHandler = void 0;
4
4
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
- const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
5
+ const select_exception_filter_metadata_util_1 = require("@nestjs/common/utils/select-exception-filter-metadata.util");
6
6
  const external_exception_filter_1 = require("./external-exception-filter");
7
+ const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
7
8
  class ExternalExceptionsHandler extends external_exception_filter_1.ExternalExceptionFilter {
8
9
  constructor() {
9
10
  super(...arguments);
@@ -26,11 +27,7 @@ class ExternalExceptionsHandler extends external_exception_filter_1.ExternalExce
26
27
  if ((0, shared_utils_1.isEmpty)(this.filters)) {
27
28
  return null;
28
29
  }
29
- const isInstanceOf = (metatype) => exception instanceof metatype;
30
- const filter = this.filters.find(({ exceptionMetatypes }) => {
31
- const typeExists = !exceptionMetatypes.length || exceptionMetatypes.some(isInstanceOf);
32
- return typeExists;
33
- });
30
+ const filter = (0, select_exception_filter_metadata_util_1.selectExceptionFilterMetadata)(this.filters, exception);
34
31
  return filter ? filter.func(exception, host) : null;
35
32
  }
36
33
  }
@@ -27,7 +27,6 @@ class ContextIdFactory {
27
27
  * @param request request object
28
28
  */
29
29
  static getByRequest(request, propsToInspect = ['raw']) {
30
- var _a;
31
30
  if (!request) {
32
31
  return ContextIdFactory.create();
33
32
  }
@@ -35,7 +34,7 @@ class ContextIdFactory {
35
34
  return request[request_constants_1.REQUEST_CONTEXT_ID];
36
35
  }
37
36
  for (const key of propsToInspect) {
38
- if ((_a = request[key]) === null || _a === void 0 ? void 0 : _a[request_constants_1.REQUEST_CONTEXT_ID]) {
37
+ if (request[key]?.[request_constants_1.REQUEST_CONTEXT_ID]) {
39
38
  return request[key][request_constants_1.REQUEST_CONTEXT_ID];
40
39
  }
41
40
  }
@@ -33,7 +33,10 @@ class ContextUtils {
33
33
  if (!paramtypes) {
34
34
  return paramsProperties;
35
35
  }
36
- return paramsProperties.map(param => (Object.assign(Object.assign({}, param), { metatype: paramtypes[param.index] })));
36
+ return paramsProperties.map(param => ({
37
+ ...param,
38
+ metatype: paramtypes[param.index],
39
+ }));
37
40
  }
38
41
  getCustomFactory(factory, data, contextFactory) {
39
42
  return (0, shared_utils_1.isFunction)(factory)
@@ -43,6 +43,7 @@ class ExecutionContextHost {
43
43
  return Object.assign(this, {
44
44
  getClient: () => this.getArgByIndex(0),
45
45
  getData: () => this.getArgByIndex(1),
46
+ getPattern: () => this.getArgByIndex(this.getArgs().length - 1),
46
47
  });
47
48
  }
48
49
  }
@@ -19,7 +19,7 @@ class AbstractInstanceResolver {
19
19
  return pluckInstance(instanceLinkOrArray);
20
20
  }
21
21
  async resolvePerContext(typeOrToken, contextModule, contextId, options) {
22
- const instanceLinkOrArray = (options === null || options === void 0 ? void 0 : options.strict)
22
+ const instanceLinkOrArray = options?.strict
23
23
  ? this.instanceLinksHost.get(typeOrToken, {
24
24
  moduleId: contextModule.id,
25
25
  each: options.each,
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModuleCompiler = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const module_token_factory_1 = require("./module-token-factory");
6
5
  class ModuleCompiler {
7
6
  constructor(moduleTokenFactory = new module_token_factory_1.ModuleTokenFactory()) {
@@ -15,12 +14,12 @@ class ModuleCompiler {
15
14
  extractMetadata(metatype) {
16
15
  if (!this.isDynamicModule(metatype)) {
17
16
  return {
18
- type: (metatype === null || metatype === void 0 ? void 0 : metatype.forwardRef)
17
+ type: metatype?.forwardRef
19
18
  ? metatype.forwardRef()
20
19
  : metatype,
21
20
  };
22
21
  }
23
- const { module: type } = metatype, dynamicMetadata = tslib_1.__rest(metatype, ["module"]);
22
+ const { module: type, ...dynamicMetadata } = metatype;
24
23
  return { type, dynamicMetadata };
25
24
  }
26
25
  isDynamicModule(module) {
@@ -8,6 +8,8 @@ import { ContextId } from './instance-wrapper';
8
8
  import { Module } from './module';
9
9
  import { ModuleTokenFactory } from './module-token-factory';
10
10
  import { ModulesContainer } from './modules-container';
11
+ type ModuleMetatype = Type<any> | DynamicModule | Promise<DynamicModule>;
12
+ type ModuleScope = Type<any>[];
11
13
  export declare class NestContainer {
12
14
  private readonly _applicationConfig;
13
15
  private readonly globalModules;
@@ -24,7 +26,9 @@ export declare class NestContainer {
24
26
  setHttpAdapter(httpAdapter: any): void;
25
27
  getHttpAdapterRef(): import("..").AbstractHttpAdapter<any, any, any>;
26
28
  getHttpAdapterHostRef(): import("..").HttpAdapterHost<import("..").AbstractHttpAdapter<any, any, any>>;
27
- addModule(metatype: Type<any> | DynamicModule | Promise<DynamicModule>, scope: Type<any>[]): Promise<Module | undefined>;
29
+ addModule(metatype: ModuleMetatype, scope: ModuleScope): Promise<Module | undefined>;
30
+ replaceModule(metatypeToReplace: ModuleMetatype, newMetatype: ModuleMetatype, scope: ModuleScope): Promise<Module | undefined>;
31
+ private setModule;
28
32
  addDynamicMetadata(token: string, dynamicModuleMetadata: Partial<DynamicModule>, scope: Type<any>[]): Promise<void>;
29
33
  addDynamicModules(modules: any[], scope: Type<any>[]): Promise<void>;
30
34
  isGlobalModule(metatype: Type<any>, dynamicMetadata?: Partial<DynamicModule>): boolean;
@@ -52,3 +56,4 @@ export declare class NestContainer {
52
56
  registerRequestProvider<T = any>(request: T, contextId: ContextId): void;
53
57
  private shouldInitOnPreview;
54
58
  }
59
+ export {};
@@ -53,6 +53,27 @@ class NestContainer {
53
53
  if (this.modules.has(token)) {
54
54
  return this.modules.get(token);
55
55
  }
56
+ return this.setModule({
57
+ token,
58
+ type,
59
+ dynamicMetadata,
60
+ }, scope);
61
+ }
62
+ async replaceModule(metatypeToReplace, newMetatype, scope) {
63
+ // In DependenciesScanner#scanForModules we already check for undefined or invalid modules
64
+ // We still need to catch the edge-case of `forwardRef(() => undefined)`
65
+ if (!metatypeToReplace || !newMetatype) {
66
+ throw new exceptions_1.UndefinedForwardRefException(scope);
67
+ }
68
+ const { token } = await this.moduleCompiler.compile(metatypeToReplace);
69
+ const { type, dynamicMetadata } = await this.moduleCompiler.compile(newMetatype);
70
+ return this.setModule({
71
+ token,
72
+ type,
73
+ dynamicMetadata,
74
+ }, scope);
75
+ }
76
+ async setModule({ token, dynamicMetadata, type }, scope) {
56
77
  const moduleRef = new module_1.Module(type, this);
57
78
  moduleRef.token = token;
58
79
  moduleRef.initOnPreview = this.shouldInitOnPreview(type);
@@ -112,7 +133,7 @@ class NestContainer {
112
133
  addProvider(provider, token, enhancerSubtype) {
113
134
  const moduleRef = this.modules.get(token);
114
135
  if (!provider) {
115
- throw new exceptions_1.CircularDependencyException(moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype.name);
136
+ throw new exceptions_1.CircularDependencyException(moduleRef?.metatype.name);
116
137
  }
117
138
  if (!moduleRef) {
118
139
  throw new exceptions_1.UnknownModuleException();
@@ -159,9 +180,8 @@ class NestContainer {
159
180
  target.addRelatedModule(globalModule);
160
181
  }
161
182
  getDynamicMetadataByToken(token, metadataKey) {
162
- var _a;
163
183
  const metadata = this.dynamicModulesMetadata.get(token);
164
- return metadataKey ? (_a = metadata === null || metadata === void 0 ? void 0 : metadata[metadataKey]) !== null && _a !== void 0 ? _a : [] : metadata;
184
+ return metadataKey ? metadata?.[metadataKey] ?? [] : metadata;
165
185
  }
166
186
  registerCoreModuleRef(moduleRef) {
167
187
  this.internalCoreModule = moduleRef;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isFactoryProvider = exports.isValueProvider = exports.isClassProvider = void 0;
4
4
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
5
  function isClassProvider(provider) {
6
- return Boolean(provider === null || provider === void 0 ? void 0 : provider.useClass);
6
+ return Boolean(provider?.useClass);
7
7
  }
8
8
  exports.isClassProvider = isClassProvider;
9
9
  function isValueProvider(provider) {
10
- const providerValue = provider === null || provider === void 0 ? void 0 : provider.useValue;
10
+ const providerValue = provider?.useValue;
11
11
  return !(0, shared_utils_1.isUndefined)(providerValue);
12
12
  }
13
13
  exports.isValueProvider = isValueProvider;
@@ -1,12 +1,12 @@
1
+ import { InjectionToken } from '@nestjs/common';
1
2
  import { InstanceWrapper } from '../instance-wrapper';
2
- import { InstanceToken } from '../module';
3
3
  /**
4
4
  * Returns the instances which are transient
5
5
  * @param instances The instances which should be checked whether they are transient
6
6
  */
7
- export declare function getTransientInstances(instances: [InstanceToken, InstanceWrapper][]): InstanceWrapper[];
7
+ export declare function getTransientInstances(instances: [InjectionToken, InstanceWrapper][]): InstanceWrapper[];
8
8
  /**
9
9
  * Returns the instances which are not transient
10
10
  * @param instances The instances which should be checked whether they are transient
11
11
  */
12
- export declare function getNonTransientInstances(instances: [InstanceToken, InstanceWrapper][]): InstanceWrapper[];
12
+ export declare function getNonTransientInstances(instances: [InjectionToken, InstanceWrapper][]): InstanceWrapper[];
@@ -1,7 +1,7 @@
1
1
  import { InjectionToken } from '@nestjs/common';
2
2
  import { Controller, Injectable, Type } from '@nestjs/common/interfaces';
3
3
  import { ContextId, InstancePerContext, InstanceWrapper, PropertyMetadata } from './instance-wrapper';
4
- import { InstanceToken, Module } from './module';
4
+ import { Module } from './module';
5
5
  /**
6
6
  * The type of an injectable dependency
7
7
  */
@@ -44,9 +44,9 @@ export declare class Injector {
44
44
  constructor(options?: {
45
45
  preview: boolean;
46
46
  });
47
- loadPrototype<T>({ token }: InstanceWrapper<T>, collection: Map<InstanceToken, InstanceWrapper<T>>, contextId?: ContextId): void;
48
- loadInstance<T>(wrapper: InstanceWrapper<T>, collection: Map<InstanceToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
49
- loadMiddleware(wrapper: InstanceWrapper, collection: Map<InstanceToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
47
+ loadPrototype<T>({ token }: InstanceWrapper<T>, collection: Map<InjectionToken, InstanceWrapper<T>>, contextId?: ContextId): void;
48
+ loadInstance<T>(wrapper: InstanceWrapper<T>, collection: Map<InjectionToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
49
+ loadMiddleware(wrapper: InstanceWrapper, collection: Map<InjectionToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
50
50
  loadController(wrapper: InstanceWrapper<Controller>, moduleRef: Module, contextId?: ContextId): Promise<void>;
51
51
  loadInjectable<T = any>(wrapper: InstanceWrapper<T>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
52
52
  loadProvider(wrapper: InstanceWrapper<Injectable>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
@@ -59,16 +59,16 @@ export declare class Injector {
59
59
  reflectSelfParams<T>(type: Type<T>): any[];
60
60
  resolveSingleParam<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol | any, dependencyContext: InjectorDependencyContext, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper<any>>;
61
61
  resolveParamToken<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol | any): any;
62
- resolveComponentInstance<T>(moduleRef: Module, token: InstanceToken, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper>;
62
+ resolveComponentInstance<T>(moduleRef: Module, token: InjectionToken, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper>;
63
63
  resolveComponentHost<T>(moduleRef: Module, instanceWrapper: InstanceWrapper<T | Promise<T>>, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<InstanceWrapper>;
64
64
  lookupComponent<T = any>(providers: Map<Function | string | symbol, InstanceWrapper>, moduleRef: Module, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper<T>>;
65
65
  lookupComponentInParentModules<T = any>(dependencyContext: InjectorDependencyContext, moduleRef: Module, wrapper: InstanceWrapper<T>, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<any>;
66
- lookupComponentInImports(moduleRef: Module, name: InstanceToken, wrapper: InstanceWrapper, moduleRegistry?: any[], contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number, isTraversing?: boolean): Promise<any>;
66
+ lookupComponentInImports(moduleRef: Module, name: InjectionToken, wrapper: InstanceWrapper, moduleRegistry?: any[], contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number, isTraversing?: boolean): Promise<any>;
67
67
  resolveProperties<T>(wrapper: InstanceWrapper<T>, moduleRef: Module, inject?: InjectorDependency[], contextId?: ContextId, inquirer?: InstanceWrapper, parentInquirer?: InstanceWrapper): Promise<PropertyDependency[]>;
68
68
  reflectProperties<T>(type: Type<T>): PropertyDependency[];
69
69
  applyProperties<T = any>(instance: T, properties: PropertyDependency[]): void;
70
70
  instantiateClass<T = any>(instances: any[], wrapper: InstanceWrapper, targetMetatype: InstanceWrapper, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<T>;
71
- loadPerContext<T = any>(instance: T, moduleRef: Module, collection: Map<InstanceToken, InstanceWrapper>, ctx: ContextId, wrapper?: InstanceWrapper): Promise<T>;
71
+ loadPerContext<T = any>(instance: T, moduleRef: Module, collection: Map<InjectionToken, InstanceWrapper>, ctx: ContextId, wrapper?: InstanceWrapper): Promise<T>;
72
72
  loadEnhancersPerContext(wrapper: InstanceWrapper, ctx: ContextId, inquirer?: InstanceWrapper): Promise<void>;
73
73
  loadCtorMetadata(metadata: InstanceWrapper<any>[], contextId: ContextId, inquirer?: InstanceWrapper, parentInquirer?: InstanceWrapper): Promise<any[]>;
74
74
  loadPropertiesMetadata(metadata: PropertyMetadata[], contextId: ContextId, inquirer?: InstanceWrapper): Promise<PropertyDependency[]>;
@@ -25,7 +25,10 @@ class Injector {
25
25
  const target = collection.get(token);
26
26
  const instance = target.createPrototype(contextId);
27
27
  if (instance) {
28
- const wrapper = new instance_wrapper_1.InstanceWrapper(Object.assign(Object.assign({}, target), { instance }));
28
+ const wrapper = new instance_wrapper_1.InstanceWrapper({
29
+ ...target,
30
+ instance,
31
+ });
29
32
  collection.set(token, wrapper);
30
33
  }
31
34
  }
@@ -113,7 +116,7 @@ class Injector {
113
116
  if (this.isInquirer(param, parentInquirer)) {
114
117
  return parentInquirer && parentInquirer.instance;
115
118
  }
116
- if ((inquirer === null || inquirer === void 0 ? void 0 : inquirer.isTransient) && parentInquirer) {
119
+ if (inquirer?.isTransient && parentInquirer) {
117
120
  inquirer = parentInquirer;
118
121
  inquirerId = this.getInquirerId(parentInquirer);
119
122
  }
@@ -122,7 +125,7 @@ class Injector {
122
125
  if (!instanceHost.isResolved && !paramWrapper.forwardRef) {
123
126
  isResolved = false;
124
127
  }
125
- return instanceHost === null || instanceHost === void 0 ? void 0 : instanceHost.instance;
128
+ return instanceHost?.instance;
126
129
  }
127
130
  catch (err) {
128
131
  const isOptional = optionalDependenciesIds.includes(index);
@@ -143,7 +146,6 @@ class Injector {
143
146
  ];
144
147
  }
145
148
  getFactoryProviderDependencies(wrapper) {
146
- var _a, _b;
147
149
  const optionalDependenciesIds = [];
148
150
  const isOptionalFactoryDep = (item) => !(0, shared_utils_1.isUndefined)(item.token) &&
149
151
  !(0, shared_utils_1.isUndefined)(item.optional);
@@ -155,12 +157,12 @@ class Injector {
155
157
  if (item.optional) {
156
158
  optionalDependenciesIds.push(index);
157
159
  }
158
- return item === null || item === void 0 ? void 0 : item.token;
160
+ return item?.token;
159
161
  }
160
162
  return item;
161
163
  };
162
164
  return [
163
- (_b = (_a = wrapper.inject) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, mapFactoryProviderInjectArray),
165
+ wrapper.inject?.map?.(mapFactoryProviderInjectArray),
164
166
  optionalDependenciesIds,
165
167
  ];
166
168
  }
@@ -197,15 +199,14 @@ class Injector {
197
199
  this.printResolvingDependenciesLog(token, inquirer);
198
200
  this.printLookingForProviderLog(token, moduleRef);
199
201
  const providers = moduleRef.providers;
200
- const instanceWrapper = await this.lookupComponent(providers, moduleRef, Object.assign(Object.assign({}, dependencyContext), { name: token }), wrapper, contextId, inquirer, keyOrIndex);
202
+ const instanceWrapper = await this.lookupComponent(providers, moduleRef, { ...dependencyContext, name: token }, wrapper, contextId, inquirer, keyOrIndex);
201
203
  return this.resolveComponentHost(moduleRef, instanceWrapper, contextId, inquirer);
202
204
  }
203
205
  async resolveComponentHost(moduleRef, instanceWrapper, contextId = constants_2.STATIC_CONTEXT, inquirer) {
204
- var _a;
205
206
  const inquirerId = this.getInquirerId(inquirer);
206
207
  const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
207
208
  if (!instanceHost.isResolved && !instanceWrapper.forwardRef) {
208
- await this.loadProvider(instanceWrapper, (_a = instanceWrapper.host) !== null && _a !== void 0 ? _a : moduleRef, contextId, inquirer);
209
+ await this.loadProvider(instanceWrapper, instanceWrapper.host ?? moduleRef, contextId, inquirer);
209
210
  }
210
211
  else if (!instanceHost.isResolved &&
211
212
  instanceWrapper.forwardRef &&
@@ -317,12 +318,19 @@ class Injector {
317
318
  return undefined;
318
319
  }
319
320
  }));
320
- return properties.map((item, index) => (Object.assign(Object.assign({}, item), { instance: instances[index] })));
321
+ return properties.map((item, index) => ({
322
+ ...item,
323
+ instance: instances[index],
324
+ }));
321
325
  }
322
326
  reflectProperties(type) {
323
327
  const properties = Reflect.getMetadata(constants_1.PROPERTY_DEPS_METADATA, type) || [];
324
328
  const optionalKeys = Reflect.getMetadata(constants_1.OPTIONAL_PROPERTY_DEPS_METADATA, type) || [];
325
- return properties.map((item) => (Object.assign(Object.assign({}, item), { name: item.type, isOptional: optionalKeys.includes(item.key) })));
329
+ return properties.map((item) => ({
330
+ ...item,
331
+ name: item.type,
332
+ isOptional: optionalKeys.includes(item.key),
333
+ }));
326
334
  }
327
335
  applyProperties(instance, properties) {
328
336
  if (!(0, shared_utils_1.isObject)(instance)) {
@@ -333,7 +341,6 @@ class Injector {
333
341
  .forEach(item => (instance[item.key] = item.instance));
334
342
  }
335
343
  async instantiateClass(instances, wrapper, targetMetatype, contextId = constants_2.STATIC_CONTEXT, inquirer) {
336
- var _a, _b;
337
344
  const { metatype, inject } = wrapper;
338
345
  const inquirerId = this.getInquirerId(inquirer);
339
346
  const instanceHost = targetMetatype.getInstanceByContextId(this.getContextId(contextId, targetMetatype), inquirerId);
@@ -341,7 +348,7 @@ class Injector {
341
348
  wrapper.isInRequestScope(contextId, inquirer) ||
342
349
  wrapper.isLazyTransient(contextId, inquirer) ||
343
350
  wrapper.isExplicitlyRequested(contextId, inquirer);
344
- if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.preview) && !((_b = wrapper.host) === null || _b === void 0 ? void 0 : _b.initOnPreview)) {
351
+ if (this.options?.preview && !wrapper.host?.initOnPreview) {
345
352
  instanceHost.isResolved = true;
346
353
  return instanceHost.instance;
347
354
  }
@@ -378,7 +385,7 @@ class Injector {
378
385
  async loadCtorMetadata(metadata, contextId, inquirer, parentInquirer) {
379
386
  const hosts = await Promise.all(metadata.map(async (item) => this.resolveScopedComponentHost(item, contextId, inquirer, parentInquirer)));
380
387
  const inquirerId = this.getInquirerId(inquirer);
381
- return hosts.map(item => item === null || item === void 0 ? void 0 : item.getInstanceByContextId(this.getContextId(contextId, item), inquirerId).instance);
388
+ return hosts.map(item => item?.getInstanceByContextId(this.getContextId(contextId, item), inquirerId).instance);
382
389
  }
383
390
  async loadPropertiesMetadata(metadata, contextId, inquirer) {
384
391
  const dependenciesHosts = await Promise.all(metadata.map(async ({ wrapper: item, key }) => ({
@@ -418,32 +425,29 @@ class Injector {
418
425
  return (0, shared_utils_1.isFunction)(token) ? token.name : token.toString();
419
426
  }
420
427
  printResolvingDependenciesLog(token, inquirer) {
421
- var _a, _b, _c;
422
428
  if (!this.isDebugMode()) {
423
429
  return;
424
430
  }
425
431
  const tokenName = this.getTokenName(token);
426
- const dependentName = (_c = ((inquirer === null || inquirer === void 0 ? void 0 : inquirer.name) && ((_b = (_a = inquirer.name).toString) === null || _b === void 0 ? void 0 : _b.call(_a)))) !== null && _c !== void 0 ? _c : 'unknown';
432
+ const dependentName = (inquirer?.name && inquirer.name.toString?.()) ?? 'unknown';
427
433
  const isAlias = dependentName === tokenName;
428
434
  const messageToPrint = `Resolving dependency ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in the ')}${cli_colors_util_1.clc.yellow(dependentName)}${cli_colors_util_1.clc.green(` provider ${isAlias ? '(alias)' : ''}`)}`;
429
435
  this.logger.log(messageToPrint);
430
436
  }
431
437
  printLookingForProviderLog(token, moduleRef) {
432
- var _a, _b;
433
438
  if (!this.isDebugMode()) {
434
439
  return;
435
440
  }
436
441
  const tokenName = this.getTokenName(token);
437
- const moduleRefName = (_b = (_a = moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown';
442
+ const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
438
443
  this.logger.log(`Looking for ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
439
444
  }
440
445
  printFoundInModuleLog(token, moduleRef) {
441
- var _a, _b;
442
446
  if (!this.isDebugMode()) {
443
447
  return;
444
448
  }
445
449
  const tokenName = this.getTokenName(token);
446
- const moduleRefName = (_b = (_a = moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown';
450
+ const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
447
451
  this.logger.log(`Found ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
448
452
  }
449
453
  isDebugMode() {
@@ -1,8 +1,8 @@
1
+ import { InjectionToken } from '@nestjs/common';
1
2
  import { NestContainer } from './container';
2
3
  import { InstanceWrapper } from './instance-wrapper';
3
- import { InstanceToken } from './module';
4
4
  export interface InstanceLink<T = any> {
5
- token: InstanceToken;
5
+ token: InjectionToken;
6
6
  wrapperRef: InstanceWrapper<T>;
7
7
  collection: Map<any, InstanceWrapper>;
8
8
  moduleId: string;
@@ -11,8 +11,8 @@ export declare class InstanceLinksHost {
11
11
  private readonly container;
12
12
  private readonly instanceLinks;
13
13
  constructor(container: NestContainer);
14
- get<T = any>(token: InstanceToken): InstanceLink<T>;
15
- get<T = any>(token: InstanceToken, options?: {
14
+ get<T = any>(token: InjectionToken): InstanceLink<T>;
15
+ get<T = any>(token: InjectionToken, options?: {
16
16
  moduleId?: string;
17
17
  each?: boolean;
18
18
  }): InstanceLink<T> | Array<InstanceLink<T>>;
@@ -50,7 +50,7 @@ class InstanceLinksHost {
50
50
  }
51
51
  }
52
52
  getInstanceNameByToken(token) {
53
- return (0, shared_utils_1.isFunction)(token) ? token === null || token === void 0 ? void 0 : token.name : token;
53
+ return (0, shared_utils_1.isFunction)(token) ? token?.name : token;
54
54
  }
55
55
  }
56
56
  exports.InstanceLinksHost = InstanceLinksHost;