@nestjs/core 10.4.10 → 11.0.0-next.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 (79) hide show
  1. package/adapters/http-adapter.d.ts +14 -0
  2. package/adapters/http-adapter.js +21 -1
  3. package/errors/exception-handler.d.ts +1 -2
  4. package/errors/exception-handler.js +1 -6
  5. package/errors/exceptions/undefined-dependency.exception.d.ts +2 -2
  6. package/errors/exceptions/undefined-dependency.exception.js +2 -2
  7. package/errors/exceptions/unknown-dependencies.exception.d.ts +2 -2
  8. package/errors/exceptions-zone.d.ts +2 -2
  9. package/errors/messages.d.ts +2 -2
  10. package/errors/messages.js +3 -3
  11. package/exceptions/base-exception-filter-context.js +1 -1
  12. package/exceptions/base-exception-filter.d.ts +2 -2
  13. package/exceptions/base-exception-filter.js +2 -3
  14. package/exceptions/exceptions-handler.d.ts +2 -2
  15. package/exceptions/exceptions-handler.js +2 -2
  16. package/exceptions/external-exception-filter-context.d.ts +1 -1
  17. package/exceptions/external-exception-filter-context.js +1 -1
  18. package/exceptions/external-exception-filter.js +3 -2
  19. package/exceptions/external-exceptions-handler.d.ts +2 -2
  20. package/exceptions/external-exceptions-handler.js +2 -2
  21. package/guards/guards-context-creator.d.ts +1 -1
  22. package/guards/guards-context-creator.js +2 -2
  23. package/helpers/execution-context-host.d.ts +1 -1
  24. package/helpers/external-context-creator.d.ts +1 -1
  25. package/helpers/external-context-creator.js +8 -8
  26. package/helpers/router-method-factory.js +7 -0
  27. package/injector/abstract-instance-resolver.js +2 -2
  28. package/injector/compiler.d.ts +9 -8
  29. package/injector/compiler.js +20 -14
  30. package/injector/container.d.ts +8 -7
  31. package/injector/container.js +13 -5
  32. package/injector/helpers/silent-logger.js +0 -1
  33. package/injector/injector.d.ts +5 -5
  34. package/injector/injector.js +7 -7
  35. package/injector/inquirer/inquirer-providers.js +0 -1
  36. package/injector/instance-wrapper.d.ts +4 -4
  37. package/injector/instance-wrapper.js +4 -4
  38. package/injector/lazy-module-loader/lazy-module-loader.d.ts +1 -1
  39. package/injector/module-ref.js +1 -0
  40. package/injector/module.d.ts +2 -2
  41. package/injector/module.js +7 -3
  42. package/inspector/noop-graph-inspector.js +0 -1
  43. package/inspector/serialized-graph.d.ts +2 -2
  44. package/interceptors/interceptors-context-creator.d.ts +1 -1
  45. package/interceptors/interceptors-context-creator.js +2 -2
  46. package/metadata-scanner.d.ts +1 -1
  47. package/middleware/builder.d.ts +1 -1
  48. package/middleware/builder.js +2 -3
  49. package/middleware/middleware-module.js +1 -1
  50. package/middleware/route-info-path-extractor.js +6 -2
  51. package/middleware/utils.js +22 -11
  52. package/nest-application-context.d.ts +3 -3
  53. package/nest-application-context.js +16 -6
  54. package/nest-application.js +2 -2
  55. package/nest-factory.d.ts +7 -5
  56. package/nest-factory.js +1 -1
  57. package/package.json +3 -3
  58. package/pipes/pipes-context-creator.d.ts +1 -1
  59. package/pipes/pipes-context-creator.js +2 -2
  60. package/repl/assign-to-object.util.d.ts +1 -1
  61. package/router/interfaces/route-params-factory.interface.d.ts +1 -1
  62. package/router/legacy-route-converter.d.ts +13 -0
  63. package/router/legacy-route-converter.js +48 -0
  64. package/router/request/request-providers.js +0 -1
  65. package/router/route-params-factory.d.ts +2 -2
  66. package/router/route-params-factory.js +1 -0
  67. package/router/route-path-factory.d.ts +1 -1
  68. package/router/router-exception-filters.d.ts +1 -1
  69. package/router/router-exception-filters.js +1 -1
  70. package/router/router-execution-context.d.ts +2 -2
  71. package/router/router-execution-context.js +1 -1
  72. package/router/router-explorer.js +24 -5
  73. package/router/router-proxy.d.ts +3 -3
  74. package/router/sse-stream.js +1 -1
  75. package/router/utils/flatten-route-paths.util.d.ts +5 -1
  76. package/scanner.d.ts +2 -2
  77. package/scanner.js +6 -6
  78. package/services/reflector.service.d.ts +3 -3
  79. package/services/reflector.service.js +7 -0
@@ -1,5 +1,5 @@
1
1
  import { InjectionToken } from '@nestjs/common';
2
- import { Controller, Injectable, Type } from '@nestjs/common/interfaces';
2
+ import { Controller, ForwardReference, Injectable, Type } from '@nestjs/common/interfaces';
3
3
  import { ContextId, InstancePerContext, InstanceWrapper, PropertyMetadata } from './instance-wrapper';
4
4
  import { Module } from './module';
5
5
  import { SettlementSignal } from './settlement-signal';
@@ -44,7 +44,7 @@ export declare class Injector {
44
44
  private logger;
45
45
  constructor(options?: {
46
46
  preview: boolean;
47
- });
47
+ } | undefined);
48
48
  loadPrototype<T>({ token }: InstanceWrapper<T>, collection: Map<InjectionToken, InstanceWrapper<T>>, contextId?: ContextId): void;
49
49
  loadInstance<T>(wrapper: InstanceWrapper<T>, collection: Map<InjectionToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
50
50
  loadMiddleware(wrapper: InstanceWrapper, collection: Map<InjectionToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
@@ -52,14 +52,14 @@ export declare class Injector {
52
52
  loadInjectable<T = any>(wrapper: InstanceWrapper<T>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
53
53
  loadProvider(wrapper: InstanceWrapper<Injectable>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
54
54
  applySettlementSignal<T>(instancePerContext: InstancePerContext<T>, host: InstanceWrapper<T>): SettlementSignal;
55
- resolveConstructorParams<T>(wrapper: InstanceWrapper<T>, moduleRef: Module, inject: InjectorDependency[], callback: (args: unknown[]) => void | Promise<void>, contextId?: ContextId, inquirer?: InstanceWrapper, parentInquirer?: InstanceWrapper): Promise<void>;
55
+ resolveConstructorParams<T>(wrapper: InstanceWrapper<T>, moduleRef: Module, inject: InjectorDependency[] | undefined, callback: (args: unknown[]) => void | Promise<void>, contextId?: ContextId, inquirer?: InstanceWrapper, parentInquirer?: InstanceWrapper): Promise<void>;
56
56
  getClassDependencies<T>(wrapper: InstanceWrapper<T>): [InjectorDependency[], number[]];
57
57
  getFactoryProviderDependencies<T>(wrapper: InstanceWrapper<T>): [InjectorDependency[], number[]];
58
58
  reflectConstructorParams<T>(type: Type<T>): any[];
59
59
  reflectOptionalParams<T>(type: Type<T>): any[];
60
60
  reflectSelfParams<T>(type: Type<T>): any[];
61
- 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>>;
62
- resolveParamToken<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol | any): any;
61
+ resolveSingleParam<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol, dependencyContext: InjectorDependencyContext, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper<any>>;
62
+ resolveParamToken<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol | ForwardReference): any;
63
63
  resolveComponentInstance<T>(moduleRef: Module, token: InjectionToken, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>, contextId?: ContextId, inquirer?: InstanceWrapper, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper>;
64
64
  resolveComponentHost<T>(moduleRef: Module, instanceWrapper: InstanceWrapper<T | Promise<T>>, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<InstanceWrapper>;
65
65
  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>>;
@@ -202,11 +202,11 @@ class Injector {
202
202
  return this.resolveComponentInstance(moduleRef, token, dependencyContext, wrapper, contextId, inquirer, keyOrIndex);
203
203
  }
204
204
  resolveParamToken(wrapper, param) {
205
- if (!param.forwardRef) {
206
- return param;
205
+ if (typeof param === 'object' && 'forwardRef' in param) {
206
+ wrapper.forwardRef = true;
207
+ return param.forwardRef();
207
208
  }
208
- wrapper.forwardRef = true;
209
- return param.forwardRef();
209
+ return param;
210
210
  }
211
211
  async resolveComponentInstance(moduleRef, token, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
212
212
  this.printResolvingDependenciesLog(token, inquirer);
@@ -233,7 +233,7 @@ class Injector {
233
233
  * instantiated beforehand.
234
234
  */
235
235
  instanceHost.donePromise &&
236
- instanceHost.donePromise.then(() => this.loadProvider(instanceWrapper, moduleRef, contextId, inquirer));
236
+ void instanceHost.donePromise.then(() => this.loadProvider(instanceWrapper, moduleRef, contextId, inquirer));
237
237
  }
238
238
  if (instanceWrapper.async) {
239
239
  const host = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
@@ -248,7 +248,7 @@ class Injector {
248
248
  if (wrapper && token === name) {
249
249
  throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
250
250
  }
251
- if (providers.has(name)) {
251
+ if (name && providers.has(name)) {
252
252
  const instanceWrapper = providers.get(name);
253
253
  this.printFoundInModuleLog(name, moduleRef);
254
254
  this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapper);
@@ -415,7 +415,7 @@ class Injector {
415
415
  }));
416
416
  }
417
417
  getInquirerId(inquirer) {
418
- return inquirer && inquirer.id;
418
+ return inquirer ? inquirer.id : undefined;
419
419
  }
420
420
  resolveScopedComponentHost(item, contextId, inquirer, parentInquirer) {
421
421
  return this.isInquirerRequest(item, parentInquirer)
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inquirerProvider = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const inquirer_constants_1 = require("./inquirer-constants");
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function
7
6
  const noop = () => { };
8
7
  exports.inquirerProvider = {
9
8
  provide: inquirer_constants_1.INQUIRER,
@@ -38,8 +38,8 @@ export declare class InstanceWrapper<T = any> {
38
38
  readonly isAlias: boolean;
39
39
  readonly subtype?: EnhancerSubtype;
40
40
  scope?: Scope;
41
- metatype: Type<T> | Function;
42
- inject?: FactoryProvider['inject'];
41
+ metatype: Type<T> | Function | null;
42
+ inject?: FactoryProvider['inject'] | null;
43
43
  forwardRef?: boolean;
44
44
  durable?: boolean;
45
45
  initTime?: number;
@@ -76,11 +76,11 @@ export declare class InstanceWrapper<T = any> {
76
76
  cloneStaticInstance(contextId: ContextId): InstancePerContext<T>;
77
77
  cloneTransientInstance(contextId: ContextId, inquirerId: string): InstancePerContext<T>;
78
78
  createPrototype(contextId: ContextId): any;
79
- isInRequestScope(contextId: ContextId, inquirer?: InstanceWrapper | undefined): boolean;
79
+ isInRequestScope(contextId: ContextId, inquirer?: InstanceWrapper): boolean;
80
80
  isLazyTransient(contextId: ContextId, inquirer: InstanceWrapper | undefined): boolean;
81
81
  isExplicitlyRequested(contextId: ContextId, inquirer?: InstanceWrapper): boolean;
82
82
  isStatic(contextId: ContextId, inquirer: InstanceWrapper | undefined): boolean;
83
- getStaticTransientInstances(): InstancePerContext<T>[];
83
+ getStaticTransientInstances(): (InstancePerContext<T> | undefined)[];
84
84
  mergeWith(provider: Provider): void;
85
85
  private isNewable;
86
86
  private initialize;
@@ -36,7 +36,7 @@ class InstanceWrapper {
36
36
  return !this.metatype || this.isFactory;
37
37
  }
38
38
  get isFactory() {
39
- return this.metatype && !(0, shared_utils_1.isNil)(this.inject);
39
+ return !!this.metatype && !(0, shared_utils_1.isNil)(this.inject);
40
40
  }
41
41
  get isTransient() {
42
42
  return this.scope === common_1.Scope.TRANSIENT;
@@ -221,7 +221,7 @@ class InstanceWrapper {
221
221
  (!this.isTransient || (this.isTransient && !!inquirer)));
222
222
  }
223
223
  isLazyTransient(contextId, inquirer) {
224
- const isInquirerRequestScoped = inquirer && !inquirer.isDependencyTreeStatic();
224
+ const isInquirerRequestScoped = !!(inquirer && !inquirer.isDependencyTreeStatic());
225
225
  return (this.isDependencyTreeStatic() &&
226
226
  contextId !== constants_1.STATIC_CONTEXT &&
227
227
  this.isTransient &&
@@ -231,7 +231,7 @@ class InstanceWrapper {
231
231
  const isSelfRequested = inquirer === this;
232
232
  return (this.isDependencyTreeStatic() &&
233
233
  contextId !== constants_1.STATIC_CONTEXT &&
234
- (isSelfRequested || (inquirer && inquirer.scope === common_1.Scope.TRANSIENT)));
234
+ (isSelfRequested || !!(inquirer && inquirer.scope === common_1.Scope.TRANSIENT)));
235
235
  }
236
236
  isStatic(contextId, inquirer) {
237
237
  const isInquirerRequestScoped = inquirer && !inquirer.isDependencyTreeStatic();
@@ -278,7 +278,7 @@ class InstanceWrapper {
278
278
  const { instance, isResolved, ...wrapperPartial } = metadata;
279
279
  Object.assign(this, wrapperPartial);
280
280
  this.setInstanceByContextId(constants_1.STATIC_CONTEXT, {
281
- instance,
281
+ instance: instance,
282
282
  isResolved,
283
283
  });
284
284
  this.scope === common_1.Scope.TRANSIENT && (this.transientMap = new Map());
@@ -12,7 +12,7 @@ export declare class LazyModuleLoader {
12
12
  private readonly moduleCompiler;
13
13
  private readonly modulesContainer;
14
14
  private readonly moduleOverrides?;
15
- constructor(dependenciesScanner: DependenciesScanner, instanceLoader: InstanceLoader, moduleCompiler: ModuleCompiler, modulesContainer: ModulesContainer, moduleOverrides?: ModuleOverride[]);
15
+ constructor(dependenciesScanner: DependenciesScanner, instanceLoader: InstanceLoader, moduleCompiler: ModuleCompiler, modulesContainer: ModulesContainer, moduleOverrides?: ModuleOverride[] | undefined);
16
16
  load(loaderFn: () => Promise<Type<unknown> | DynamicModule> | Type<unknown> | DynamicModule, loadOpts?: LazyModuleLoaderLoadOptions): Promise<ModuleRef>;
17
17
  private registerLoggerConfiguration;
18
18
  private createLazyModulesContainer;
@@ -43,6 +43,7 @@ class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
43
43
  durable: (0, is_durable_1.isDurable)(type),
44
44
  host: moduleRef,
45
45
  });
46
+ /* eslint-disable-next-line no-async-promise-executor */
46
47
  return new Promise(async (resolve, reject) => {
47
48
  try {
48
49
  const callback = async (instances) => {
@@ -56,8 +56,8 @@ export declare class Module {
56
56
  addCustomValue(provider: ValueProvider, collection: Map<Function | string | symbol, InstanceWrapper>, enhancerSubtype?: EnhancerSubtype): void;
57
57
  addCustomFactory(provider: FactoryProvider, collection: Map<Function | string | symbol, InstanceWrapper>, enhancerSubtype?: EnhancerSubtype): void;
58
58
  addCustomUseExisting(provider: ExistingProvider, collection: Map<Function | string | symbol, InstanceWrapper>, enhancerSubtype?: EnhancerSubtype): void;
59
- addExportedProvider(provider: Provider | string | symbol | DynamicModule): Set<InjectionToken>;
60
- addCustomExportedProvider(provider: FactoryProvider | ValueProvider | ClassProvider | ExistingProvider): Set<InjectionToken>;
59
+ addExportedProvider(provider: Provider | string | symbol | DynamicModule): Set<InjectionToken> | undefined;
60
+ addCustomExportedProvider(provider: FactoryProvider | ValueProvider | ClassProvider | ExistingProvider): Set<InjectionToken> | undefined;
61
61
  validateExportedProvider(token: InjectionToken): InjectionToken;
62
62
  addController(controller: Type<Controller>): void;
63
63
  assignControllerUniqueId(controller: Type<Controller>): void;
@@ -81,8 +81,8 @@ class Module {
81
81
  if (!this._providers.has(this._metatype)) {
82
82
  throw new exceptions_1.RuntimeException();
83
83
  }
84
- const module = this._providers.get(this._metatype);
85
- return module.instance;
84
+ const moduleRef = this._providers.get(this._metatype);
85
+ return moduleRef.instance;
86
86
  }
87
87
  get metatype() {
88
88
  return this._metatype;
@@ -418,7 +418,11 @@ class Module {
418
418
  }
419
419
  generateUuid() {
420
420
  const prefix = 'M_';
421
- const key = this.name?.toString() ?? this.token?.toString();
421
+ const key = this.token
422
+ ? this.token.includes(':')
423
+ ? this.token.split(':')[1]
424
+ : this.token
425
+ : this.name;
422
426
  return key ? uuid_factory_1.UuidFactory.get(`${prefix}_${key}`) : (0, random_string_generator_util_1.randomStringGenerator)();
423
427
  }
424
428
  isTransientProvider(provider) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoopGraphInspector = void 0;
4
4
  const graph_inspector_1 = require("./graph-inspector");
5
- // eslint-disable-next-line @typescript-eslint/no-empty-function
6
5
  const noop = () => { };
7
6
  exports.NoopGraphInspector = new Proxy(graph_inspector_1.GraphInspector.prototype, {
8
7
  get: () => noop,
@@ -17,7 +17,7 @@ export declare class SerializedGraph {
17
17
  private static readonly INTERNAL_PROVIDERS;
18
18
  set status(status: SerializedGraphStatus);
19
19
  set metadata(metadata: SerializedGraphMetadata);
20
- insertNode(nodeDefinition: Node): Node;
20
+ insertNode(nodeDefinition: Node): Node | undefined;
21
21
  insertEdge(edgeDefinition: WithOptionalId<Edge>): {
22
22
  id: string;
23
23
  source: string;
@@ -44,7 +44,7 @@ export declare class SerializedGraph {
44
44
  insertEntrypoint<T>(definition: Entrypoint<T>, parentId: string): void;
45
45
  insertOrphanedEnhancer(entry: OrphanedEnhancerDefinition): void;
46
46
  insertAttachedEnhancer(nodeId: string): void;
47
- getNodeById(id: string): Node;
47
+ getNodeById(id: string): Node | undefined;
48
48
  toJSON(): SerializedGraphJson;
49
49
  toString(): string;
50
50
  private generateUuidByEdgeDefinition;
@@ -7,7 +7,7 @@ export declare class InterceptorsContextCreator extends ContextCreator {
7
7
  private readonly container;
8
8
  private readonly config?;
9
9
  private moduleContext;
10
- constructor(container: NestContainer, config?: ApplicationConfig);
10
+ constructor(container: NestContainer, config?: ApplicationConfig | undefined);
11
11
  create(instance: Controller, callback: (...args: unknown[]) => unknown, module: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): NestInterceptor[];
12
12
  createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): R;
13
13
  getInterceptorInstance(metatype: Function | NestInterceptor, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): NestInterceptor | null;
@@ -23,11 +23,11 @@ class InterceptorsContextCreator extends context_creator_1.ContextCreator {
23
23
  return (0, iterare_1.iterate)(metadata)
24
24
  .filter(interceptor => interceptor && (interceptor.name || interceptor.intercept))
25
25
  .map(interceptor => this.getInterceptorInstance(interceptor, contextId, inquirerId))
26
- .filter((interceptor) => interceptor && (0, shared_utils_1.isFunction)(interceptor.intercept))
26
+ .filter((interceptor) => interceptor ? (0, shared_utils_1.isFunction)(interceptor.intercept) : false)
27
27
  .toArray();
28
28
  }
29
29
  getInterceptorInstance(metatype, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
30
- const isObject = metatype.intercept;
30
+ const isObject = !!metatype.intercept;
31
31
  if (isObject) {
32
32
  return metatype;
33
33
  }
@@ -6,7 +6,7 @@ export declare class MetadataScanner {
6
6
  * @see {@link getAllMethodNames}
7
7
  * @see getAllMethodNames
8
8
  */
9
- scanFromPrototype<T extends Injectable, R = any>(instance: T, prototype: object, callback: (name: string) => R): R[];
9
+ scanFromPrototype<T extends Injectable, R = any>(instance: T, prototype: object | null, callback: (name: string) => R): R[];
10
10
  /**
11
11
  * @deprecated
12
12
  * @see {@link getAllMethodNames}
@@ -8,7 +8,7 @@ export declare class MiddlewareBuilder implements MiddlewareConsumer {
8
8
  private readonly routeInfoPathExtractor;
9
9
  private readonly middlewareCollection;
10
10
  constructor(routesMapper: RoutesMapper, httpAdapter: HttpServer, routeInfoPathExtractor: RouteInfoPathExtractor);
11
- apply(...middleware: Array<Type<any> | Function | any>): MiddlewareConfigProxy;
11
+ apply(...middleware: Array<Type<any> | Function | Array<Type<any> | Function>>): MiddlewareConfigProxy;
12
12
  build(): MiddlewareConfiguration[];
13
13
  getHttpAdapter(): HttpServer;
14
14
  private static readonly ConfigProxy;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MiddlewareBuilder = void 0;
4
- const dependencies_decorator_1 = require("@nestjs/common/decorators/core/dependencies.decorator");
5
4
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
5
  const iterare_1 = require("iterare");
7
6
  const utils_1 = require("./utils");
@@ -13,7 +12,7 @@ class MiddlewareBuilder {
13
12
  this.middlewareCollection = new Set();
14
13
  }
15
14
  apply(...middleware) {
16
- return new MiddlewareBuilder.ConfigProxy(this, (0, dependencies_decorator_1.flatten)(middleware), this.routeInfoPathExtractor);
15
+ return new MiddlewareBuilder.ConfigProxy(this, middleware.flat(), this.routeInfoPathExtractor);
17
16
  }
18
17
  build() {
19
18
  return [...this.middlewareCollection];
@@ -67,7 +66,7 @@ MiddlewareBuilder.ConfigProxy = class {
67
66
  .toArray();
68
67
  }
69
68
  removeOverlappedRoutes(routes) {
70
- const regexMatchParams = /(:[^\/]*)/g;
69
+ const regexMatchParams = /(:[^/]*)/g;
71
70
  const wildcard = '([^/]*)';
72
71
  const routesWithRegex = routes
73
72
  .filter(route => route.path.includes(':'))
@@ -162,7 +162,7 @@ class MiddlewareModule {
162
162
  const middlewareFunction = isMethodAll
163
163
  ? proxy
164
164
  : (req, res, next) => {
165
- if (applicationRef.getRequestMethod(req) === requestMethod) {
165
+ if (applicationRef.getRequestMethod?.(req) === requestMethod) {
166
166
  return proxy(req, res, next);
167
167
  }
168
168
  return next();
@@ -30,7 +30,11 @@ class RouteInfoPathExtractor {
30
30
  return Array.isArray(this.excludedGlobalPrefixRoutes)
31
31
  ? [
32
32
  ...entries,
33
- ...this.excludedGlobalPrefixRoutes.map(route => versionPaths + (0, shared_utils_1.addLeadingSlash)(route.path)),
33
+ ...this.excludedGlobalPrefixRoutes
34
+ .map(route => Array.isArray(versionPaths) && versionPaths.length > 0
35
+ ? versionPaths.map(v => v + (0, shared_utils_1.addLeadingSlash)(route.path))
36
+ : (0, shared_utils_1.addLeadingSlash)(route.path))
37
+ .flat(),
34
38
  ]
35
39
  : entries;
36
40
  }
@@ -43,7 +47,7 @@ class RouteInfoPathExtractor {
43
47
  return this.extractNonWildcardPathsFrom(route);
44
48
  }
45
49
  isAWildcard(path) {
46
- return ['*', '/*', '/*/', '(.*)', '/(.*)'].includes(path);
50
+ return ['*', '/*', '/*/', '*path', '/*path', '(.*)', '/(.*)'].includes(path);
47
51
  }
48
52
  extractNonWildcardPathsFrom({ path, method, version, }) {
49
53
  const versionPaths = this.extractVersionPathFrom(version);
@@ -7,23 +7,34 @@ exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
7
7
  const common_1 = require("@nestjs/common");
8
8
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
9
9
  const iterare_1 = require("iterare");
10
- const pathToRegexp = require("path-to-regexp");
10
+ const path_to_regexp_1 = require("path-to-regexp");
11
11
  const uid_1 = require("uid");
12
+ const legacy_route_converter_1 = require("../router/legacy-route-converter");
12
13
  const utils_1 = require("../router/utils");
13
14
  const mapToExcludeRoute = (routes) => {
14
15
  return routes.map(route => {
15
- if ((0, shared_utils_1.isString)(route)) {
16
+ const originalPath = (0, shared_utils_1.isString)(route) ? route : route.path;
17
+ const path = legacy_route_converter_1.LegacyRouteConverter.tryConvert(originalPath);
18
+ try {
19
+ if ((0, shared_utils_1.isString)(route)) {
20
+ return {
21
+ path,
22
+ requestMethod: common_1.RequestMethod.ALL,
23
+ pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, shared_utils_1.addLeadingSlash)(path)).regexp,
24
+ };
25
+ }
16
26
  return {
17
- path: route,
18
- requestMethod: common_1.RequestMethod.ALL,
19
- pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route)),
27
+ path,
28
+ requestMethod: route.method,
29
+ pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, shared_utils_1.addLeadingSlash)(path)).regexp,
20
30
  };
21
31
  }
22
- return {
23
- path: route.path,
24
- requestMethod: route.method,
25
- pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route.path)),
26
- };
32
+ catch (e) {
33
+ if (e instanceof TypeError) {
34
+ legacy_route_converter_1.LegacyRouteConverter.printError(originalPath);
35
+ }
36
+ throw e;
37
+ }
27
38
  });
28
39
  };
29
40
  exports.mapToExcludeRoute = mapToExcludeRoute;
@@ -87,7 +98,7 @@ function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
87
98
  }
88
99
  const reqMethod = httpAdapter.getRequestMethod(req);
89
100
  const originalUrl = httpAdapter.getRequestUrl(req);
90
- const queryParamsIndex = originalUrl && originalUrl.indexOf('?');
101
+ const queryParamsIndex = originalUrl ? originalUrl.indexOf('?') : -1;
91
102
  const pathname = queryParamsIndex >= 0
92
103
  ? originalUrl.slice(0, queryParamsIndex)
93
104
  : originalUrl;
@@ -1,5 +1,5 @@
1
1
  import { INestApplicationContext, Logger, LoggerService, LogLevel, ShutdownSignal } from '@nestjs/common';
2
- import { DynamicModule, Type } from '@nestjs/common/interfaces';
2
+ import { DynamicModule, SelectOptions, Type } from '@nestjs/common/interfaces';
3
3
  import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
4
4
  import { AbstractInstanceResolver } from './injector/abstract-instance-resolver';
5
5
  import { NestContainer } from './injector/container';
@@ -26,13 +26,13 @@ export declare class NestApplicationContext<TOptions extends NestApplicationCont
26
26
  private _moduleRefsForHooksByDistance?;
27
27
  private initializationPromise?;
28
28
  protected get instanceLinksHost(): InstanceLinksHost;
29
- constructor(container: NestContainer, appOptions?: TOptions, contextModule?: Module, scope?: Type<any>[]);
29
+ constructor(container: NestContainer, appOptions?: TOptions, contextModule?: Module | null, scope?: Type<any>[]);
30
30
  selectContextModule(): void;
31
31
  /**
32
32
  * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
33
33
  * @returns {INestApplicationContext}
34
34
  */
35
- select<T>(moduleType: Type<T> | DynamicModule): INestApplicationContext;
35
+ select<T>(moduleType: Type<T> | DynamicModule, selectOptions?: SelectOptions): INestApplicationContext;
36
36
  /**
37
37
  * Retrieves an instance of either injectable or controller, otherwise, throws exception.
38
38
  * @returns {TResult}
@@ -9,7 +9,6 @@ const exceptions_1 = require("./errors/exceptions");
9
9
  const context_id_factory_1 = require("./helpers/context-id-factory");
10
10
  const hooks_1 = require("./hooks");
11
11
  const abstract_instance_resolver_1 = require("./injector/abstract-instance-resolver");
12
- const compiler_1 = require("./injector/compiler");
13
12
  const injector_1 = require("./injector/injector");
14
13
  const instance_links_host_1 = require("./injector/instance-links-host");
15
14
  /**
@@ -34,8 +33,8 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
34
33
  });
35
34
  this.shouldFlushLogsOnOverride = false;
36
35
  this.activeShutdownSignals = new Array();
37
- this.moduleCompiler = new compiler_1.ModuleCompiler();
38
36
  this.injector = new injector_1.Injector();
37
+ this.moduleCompiler = container.getModuleCompiler();
39
38
  if (this.appOptions.preview) {
40
39
  this.printInPreviewModeWarning();
41
40
  }
@@ -48,18 +47,26 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
48
47
  * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
49
48
  * @returns {INestApplicationContext}
50
49
  */
51
- select(moduleType) {
50
+ select(moduleType, selectOptions) {
52
51
  const modulesContainer = this.container.getModules();
53
52
  const contextModuleCtor = this.contextModule.metatype;
54
53
  const scope = this.scope.concat(contextModuleCtor);
55
54
  const moduleTokenFactory = this.container.getModuleTokenFactory();
56
55
  const { type, dynamicMetadata } = this.moduleCompiler.extractMetadata(moduleType);
57
- const token = moduleTokenFactory.create(type, dynamicMetadata);
56
+ const token = dynamicMetadata
57
+ ? moduleTokenFactory.createForDynamic(type, dynamicMetadata, moduleType)
58
+ : moduleTokenFactory.createForStatic(type, moduleType);
58
59
  const selectedModule = modulesContainer.get(token);
59
60
  if (!selectedModule) {
60
61
  throw new exceptions_1.UnknownModuleException(type.name);
61
62
  }
62
- return new NestApplicationContext(this.container, this.appOptions, selectedModule, scope);
63
+ const options = typeof selectOptions?.abortOnError !== 'undefined'
64
+ ? {
65
+ ...this.appOptions,
66
+ ...selectOptions,
67
+ }
68
+ : this.appOptions;
69
+ return new NestApplicationContext(this.container, options, selectedModule, scope);
63
70
  }
64
71
  /**
65
72
  * Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
@@ -97,6 +104,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
97
104
  if (this.isInitialized) {
98
105
  return this;
99
106
  }
107
+ /* eslint-disable-next-line no-async-promise-executor */
100
108
  this.initializationPromise = new Promise(async (resolve, reject) => {
101
109
  try {
102
110
  await this.callInitHook();
@@ -239,7 +247,9 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
239
247
  * modules and its children.
240
248
  */
241
249
  async callDestroyHook() {
242
- const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
250
+ const modulesSortedByDistance = [
251
+ ...this.getModulesToTriggerHooksOn(),
252
+ ].reverse();
243
253
  for (const module of modulesSortedByDistance) {
244
254
  await (0, hooks_1.callModuleDestroyHook)(module);
245
255
  }
@@ -92,7 +92,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
92
92
  return this;
93
93
  }
94
94
  this.applyOptions();
95
- await this.httpAdapter?.init();
95
+ await this.httpAdapter?.init?.();
96
96
  const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
97
97
  useBodyParser && this.registerParserMiddleware();
98
98
  await this.registerModules();
@@ -154,7 +154,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
154
154
  }
155
155
  const [parserType, ...otherArgs] = args;
156
156
  const rawBody = !!this.appOptions.rawBody;
157
- this.httpAdapter.useBodyParser(...[parserType, rawBody, ...otherArgs]);
157
+ this.httpAdapter.useBodyParser?.(...[parserType, rawBody, ...otherArgs]);
158
158
  return this;
159
159
  }
160
160
  enableCors(options) {
package/nest-factory.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { INestApplication, INestApplicationContext, INestMicroservice } from '@nestjs/common';
1
+ import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, INestMicroservice, Type } from '@nestjs/common';
2
2
  import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
3
3
  import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
4
4
  import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
5
5
  import { AbstractHttpAdapter } from './adapters/http-adapter';
6
+ type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
6
7
  /**
7
8
  * @publicApi
8
9
  */
@@ -19,7 +20,7 @@ export declare class NestFactoryStatic {
19
20
  * @returns A promise that, when resolved,
20
21
  * contains a reference to the NestApplication instance.
21
22
  */
22
- create<T extends INestApplication = INestApplication>(module: any, options?: NestApplicationOptions): Promise<T>;
23
+ create<T extends INestApplication = INestApplication>(module: IEntryNestModule, options?: NestApplicationOptions): Promise<T>;
23
24
  /**
24
25
  * Creates an instance of NestApplication with the specified `httpAdapter`.
25
26
  *
@@ -31,7 +32,7 @@ export declare class NestFactoryStatic {
31
32
  * @returns A promise that, when resolved,
32
33
  * contains a reference to the NestApplication instance.
33
34
  */
34
- create<T extends INestApplication = INestApplication>(module: any, httpAdapter: AbstractHttpAdapter, options?: NestApplicationOptions): Promise<T>;
35
+ create<T extends INestApplication = INestApplication>(module: IEntryNestModule, httpAdapter: AbstractHttpAdapter, options?: NestApplicationOptions): Promise<T>;
35
36
  /**
36
37
  * Creates an instance of NestMicroservice.
37
38
  *
@@ -41,7 +42,7 @@ export declare class NestFactoryStatic {
41
42
  * @returns A promise that, when resolved,
42
43
  * contains a reference to the NestMicroservice instance.
43
44
  */
44
- createMicroservice<T extends object>(moduleCls: any, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
45
+ createMicroservice<T extends object>(moduleCls: IEntryNestModule, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
45
46
  /**
46
47
  * Creates an instance of NestApplicationContext.
47
48
  *
@@ -51,7 +52,7 @@ export declare class NestFactoryStatic {
51
52
  * @returns A promise that, when resolved,
52
53
  * contains a reference to the NestApplicationContext instance.
53
54
  */
54
- createApplicationContext(moduleCls: any, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
55
+ createApplicationContext(moduleCls: IEntryNestModule, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
55
56
  private createNestInstance;
56
57
  private initialize;
57
58
  private handleInitializationError;
@@ -79,3 +80,4 @@ export declare class NestFactoryStatic {
79
80
  * @publicApi
80
81
  */
81
82
  export declare const NestFactory: NestFactoryStatic;
83
+ export {};
package/nest-factory.js CHANGED
@@ -100,7 +100,7 @@ class NestFactoryStatic {
100
100
  const dependenciesScanner = new scanner_1.DependenciesScanner(container, metadataScanner, graphInspector, config);
101
101
  container.setHttpAdapter(httpServer);
102
102
  const teardown = this.abortOnError === false ? rethrow_1.rethrow : undefined;
103
- await httpServer?.init();
103
+ await httpServer?.init?.();
104
104
  try {
105
105
  this.logger.log(constants_1.MESSAGES.APPLICATION_START);
106
106
  await exceptions_zone_1.ExceptionsZone.asyncRun(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "10.4.10",
3
+ "version": "11.0.0-next.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -31,12 +31,12 @@
31
31
  "@nuxtjs/opencollective": "0.3.2",
32
32
  "fast-safe-stringify": "2.1.1",
33
33
  "iterare": "1.2.1",
34
- "path-to-regexp": "3.3.0",
34
+ "path-to-regexp": "8.2.0",
35
35
  "tslib": "2.7.0",
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.4.10"
39
+ "@nestjs/common": "^11.0.0-next.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^10.0.0",
@@ -7,7 +7,7 @@ export declare class PipesContextCreator extends ContextCreator {
7
7
  private readonly container;
8
8
  private readonly config?;
9
9
  private moduleContext;
10
- constructor(container: NestContainer, config?: ApplicationConfig);
10
+ constructor(container: NestContainer, config?: ApplicationConfig | undefined);
11
11
  create(instance: Controller, callback: (...args: unknown[]) => unknown, moduleKey: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): PipeTransform[];
12
12
  createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): R;
13
13
  getPipeInstance(pipe: Function | PipeTransform, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): PipeTransform | null;
@@ -23,11 +23,11 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
23
23
  return (0, iterare_1.iterate)(metadata)
24
24
  .filter((pipe) => pipe && (pipe.name || pipe.transform))
25
25
  .map(pipe => this.getPipeInstance(pipe, contextId, inquirerId))
26
- .filter(pipe => pipe && pipe.transform && (0, shared_utils_1.isFunction)(pipe.transform))
26
+ .filter(pipe => !!pipe && pipe.transform && (0, shared_utils_1.isFunction)(pipe.transform))
27
27
  .toArray();
28
28
  }
29
29
  getPipeInstance(pipe, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
30
- const isObject = pipe.transform;
30
+ const isObject = !!pipe.transform;
31
31
  if (isObject) {
32
32
  return pipe;
33
33
  }
@@ -2,4 +2,4 @@
2
2
  * Similar to `Object.assign` but copying properties descriptors from `source`
3
3
  * as well.
4
4
  */
5
- export declare function assignToObject<T, U>(target: T, source: U): T & U;
5
+ export declare function assignToObject<T, U extends object>(target: T, source: U): T & U;
@@ -4,5 +4,5 @@ export interface IRouteParamsFactory {
4
4
  req: TRequest;
5
5
  res: TResponse;
6
6
  next: Function;
7
- }): TResult;
7
+ }): TResult | null;
8
8
  }