@nestjs/core 12.0.0-alpha.4 → 12.0.0-alpha.5

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 (40) hide show
  1. package/Readme.md +1 -0
  2. package/application-config.d.ts +8 -2
  3. package/application-config.js +14 -0
  4. package/errors/exceptions/index.d.ts +1 -0
  5. package/errors/exceptions/index.js +1 -0
  6. package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
  7. package/errors/exceptions/invalid-class-module.exception.js +2 -2
  8. package/errors/exceptions/invalid-module.exception.d.ts +1 -1
  9. package/errors/exceptions/invalid-module.exception.js +2 -2
  10. package/errors/exceptions/route-conflict.exception.d.ts +4 -0
  11. package/errors/exceptions/route-conflict.exception.js +7 -0
  12. package/errors/messages.d.ts +5 -2
  13. package/errors/messages.js +37 -4
  14. package/injector/helpers/transient-instances.d.ts +12 -0
  15. package/injector/helpers/transient-instances.js +28 -0
  16. package/injector/injector.d.ts +4 -3
  17. package/injector/injector.js +28 -3
  18. package/injector/instance-wrapper.d.ts +2 -0
  19. package/injector/instance-wrapper.js +25 -0
  20. package/nest-application.d.ts +1 -0
  21. package/nest-application.js +77 -1
  22. package/package.json +3 -3
  23. package/router/interfaces/index.d.ts +3 -0
  24. package/router/interfaces/index.js +3 -0
  25. package/router/interfaces/resolved-route.interface.d.ts +32 -0
  26. package/router/interfaces/resolved-route.interface.js +1 -0
  27. package/router/interfaces/resolver.interface.d.ts +5 -1
  28. package/router/interfaces/route-conflict.interface.d.ts +14 -0
  29. package/router/interfaces/route-conflict.interface.js +1 -0
  30. package/router/interfaces/route-resolution-options.interface.d.ts +24 -0
  31. package/router/interfaces/route-resolution-options.interface.js +1 -0
  32. package/router/route-conflict-detector.d.ts +71 -0
  33. package/router/route-conflict-detector.js +276 -0
  34. package/router/route-specificity-sorter.d.ts +23 -0
  35. package/router/route-specificity-sorter.js +59 -0
  36. package/router/router-explorer.d.ts +11 -2
  37. package/router/router-explorer.js +61 -19
  38. package/router/routes-resolver.d.ts +7 -4
  39. package/router/routes-resolver.js +9 -7
  40. package/scanner.js +9 -5
@@ -1,12 +1,11 @@
1
- import { NotFoundException, } from '@nestjs/common';
1
+ import { Logger, NotFoundException, } from '@nestjs/common';
2
+ import { HOST_METADATA, MODULE_PATH, VERSION_METADATA, } from '@nestjs/common/internal';
2
3
  import { CONTROLLER_MAPPING_MESSAGE, VERSIONED_CONTROLLER_MAPPING_MESSAGE, } from '../helpers/messages.js';
3
4
  import { MetadataScanner } from '../metadata-scanner.js';
4
5
  import { RoutePathFactory } from './route-path-factory.js';
5
6
  import { RouterExceptionFilters } from './router-exception-filters.js';
6
7
  import { RouterExplorer } from './router-explorer.js';
7
8
  import { RouterProxy } from './router-proxy.js';
8
- import { HOST_METADATA, MODULE_PATH, VERSION_METADATA, } from '@nestjs/common/internal';
9
- import { Logger } from '@nestjs/common';
10
9
  export class RoutesResolver {
11
10
  container;
12
11
  applicationConfig;
@@ -28,14 +27,17 @@ export class RoutesResolver {
28
27
  const metadataScanner = new MetadataScanner();
29
28
  this.routerExplorer = new RouterExplorer(metadataScanner, this.container, this.injector, this.routerProxy, this.routerExceptionsFilter, this.applicationConfig, this.routePathFactory, graphInspector);
30
29
  }
31
- resolve(applicationRef, globalPrefix) {
30
+ resolve(applicationRef, globalPrefix, options = {}) {
32
31
  const modules = this.container.getModules();
33
32
  modules.forEach(({ controllers, metatype }, moduleName) => {
34
33
  const modulePath = this.getModulePathMetadata(metatype);
35
- this.registerRouters(controllers, moduleName, globalPrefix, modulePath, applicationRef);
34
+ this.registerRouters(controllers, moduleName, globalPrefix, modulePath, applicationRef, options);
36
35
  });
37
36
  }
38
- registerRouters(routes, moduleName, globalPrefix, modulePath, applicationRef) {
37
+ registerResolvedRoute(applicationRef, route) {
38
+ this.routerExplorer.registerResolvedRoute(applicationRef, route);
39
+ }
40
+ registerRouters(routes, moduleName, globalPrefix, modulePath, applicationRef, options = {}) {
39
41
  routes.forEach(instanceWrapper => {
40
42
  const { metatype } = instanceWrapper;
41
43
  const host = this.getHostMetadata(metatype);
@@ -68,7 +70,7 @@ export class RoutesResolver {
68
70
  controllerVersion,
69
71
  versioningOptions,
70
72
  };
71
- this.routerExplorer.explore(instanceWrapper, moduleName, applicationRef, host, routePathMetadata);
73
+ this.routerExplorer.explore(instanceWrapper, moduleName, applicationRef, host, routePathMetadata, options);
72
74
  });
73
75
  });
74
76
  }
package/scanner.js CHANGED
@@ -64,7 +64,7 @@ export class DependenciesScanner {
64
64
  throw new UndefinedModuleException(moduleDefinition, index, scope);
65
65
  }
66
66
  if (!innerModule) {
67
- throw new InvalidModuleException(moduleDefinition, index, scope);
67
+ throw new InvalidModuleException(moduleDefinition, index, scope, innerModule);
68
68
  }
69
69
  if (ctxRegistry.includes(innerModule)) {
70
70
  continue;
@@ -90,10 +90,14 @@ export class DependenciesScanner {
90
90
  const moduleToAdd = this.isForwardReference(moduleDefinition)
91
91
  ? moduleDefinition.forwardRef()
92
92
  : moduleDefinition;
93
- if (this.isInjectable(moduleToAdd) ||
94
- this.isController(moduleToAdd) ||
95
- this.isExceptionFilter(moduleToAdd)) {
96
- throw new InvalidClassModuleException(moduleDefinition, scope);
93
+ if (this.isInjectable(moduleToAdd)) {
94
+ throw new InvalidClassModuleException(moduleDefinition, scope, 'provider');
95
+ }
96
+ if (this.isController(moduleToAdd)) {
97
+ throw new InvalidClassModuleException(moduleDefinition, scope, 'controller');
98
+ }
99
+ if (this.isExceptionFilter(moduleToAdd)) {
100
+ throw new InvalidClassModuleException(moduleDefinition, scope, 'filter');
97
101
  }
98
102
  return this.container.addModule(moduleToAdd, scope);
99
103
  }