@nestjs/core 11.1.15 → 12.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/http-adapter.d.ts +5 -3
- package/adapters/http-adapter.js +8 -5
- package/adapters/index.d.ts +1 -1
- package/adapters/index.js +1 -4
- package/application-config.d.ts +7 -4
- package/application-config.js +20 -15
- package/constants.d.ts +1 -1
- package/constants.js +10 -13
- package/discovery/discoverable-meta-host-collection.d.ts +3 -3
- package/discovery/discoverable-meta-host-collection.js +15 -19
- package/discovery/discovery-module.js +9 -12
- package/discovery/discovery-service.d.ts +4 -4
- package/discovery/discovery-service.js +17 -19
- package/discovery/index.d.ts +2 -2
- package/discovery/index.js +2 -5
- package/errors/exception-handler.js +3 -7
- package/errors/exceptions/circular-dependency.exception.d.ts +1 -1
- package/errors/exceptions/circular-dependency.exception.js +2 -6
- package/errors/exceptions/index.d.ts +8 -8
- package/errors/exceptions/index.js +8 -11
- package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class-module.exception.js +4 -8
- package/errors/exceptions/invalid-class-scope.exception.d.ts +2 -2
- package/errors/exceptions/invalid-class-scope.exception.js +6 -10
- package/errors/exceptions/invalid-class.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class.exception.js +4 -8
- package/errors/exceptions/invalid-exception-filter.exception.d.ts +1 -1
- package/errors/exceptions/invalid-exception-filter.exception.js +4 -8
- package/errors/exceptions/invalid-middleware-configuration.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware-configuration.exception.js +4 -8
- package/errors/exceptions/invalid-middleware.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware.exception.js +4 -8
- package/errors/exceptions/invalid-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-module.exception.js +4 -8
- package/errors/exceptions/runtime.exception.js +1 -5
- package/errors/exceptions/undefined-dependency.exception.d.ts +3 -3
- package/errors/exceptions/undefined-dependency.exception.js +4 -8
- package/errors/exceptions/undefined-forwardref.exception.d.ts +2 -2
- package/errors/exceptions/undefined-forwardref.exception.js +4 -8
- package/errors/exceptions/undefined-module.exception.d.ts +1 -1
- package/errors/exceptions/undefined-module.exception.js +4 -8
- package/errors/exceptions/unknown-dependencies.exception.d.ts +3 -3
- package/errors/exceptions/unknown-dependencies.exception.js +8 -8
- package/errors/exceptions/unknown-element.exception.d.ts +1 -1
- package/errors/exceptions/unknown-element.exception.js +2 -6
- package/errors/exceptions/unknown-export.exception.d.ts +1 -1
- package/errors/exceptions/unknown-export.exception.js +4 -8
- package/errors/exceptions/unknown-module.exception.d.ts +1 -1
- package/errors/exceptions/unknown-module.exception.js +2 -6
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +1 -1
- package/errors/exceptions/unknown-request-mapping.exception.js +4 -8
- package/errors/exceptions-zone.js +6 -10
- package/errors/messages.d.ts +2 -2
- package/errors/messages.js +19 -32
- package/exceptions/base-exception-filter-context.d.ts +6 -7
- package/exceptions/base-exception-filter-context.js +13 -16
- package/exceptions/base-exception-filter.d.ts +4 -4
- package/exceptions/base-exception-filter.js +33 -23
- package/exceptions/exceptions-handler.d.ts +4 -4
- package/exceptions/exceptions-handler.js +8 -16
- package/exceptions/external-exception-filter-context.d.ts +8 -8
- package/exceptions/external-exception-filter-context.js +14 -18
- package/exceptions/external-exception-filter.d.ts +1 -1
- package/exceptions/external-exception-filter.js +4 -8
- package/exceptions/external-exceptions-handler.d.ts +3 -3
- package/exceptions/external-exceptions-handler.js +8 -16
- package/exceptions/index.d.ts +1 -1
- package/exceptions/index.js +1 -4
- package/guards/constants.js +1 -4
- package/guards/guards-consumer.d.ts +4 -3
- package/guards/guards-consumer.js +8 -12
- package/guards/guards-context-creator.d.ts +11 -10
- package/guards/guards-context-creator.js +18 -20
- package/guards/index.d.ts +3 -3
- package/guards/index.js +3 -6
- package/helpers/barrier.js +5 -5
- package/helpers/context-creator.d.ts +2 -2
- package/helpers/context-creator.js +3 -7
- package/helpers/context-id-factory.d.ts +1 -1
- package/helpers/context-id-factory.js +10 -14
- package/helpers/context-utils.d.ts +6 -3
- package/helpers/context-utils.js +7 -12
- package/helpers/execution-context-host.d.ts +3 -3
- package/helpers/execution-context-host.js +5 -6
- package/helpers/external-context-creator.d.ts +15 -18
- package/helpers/external-context-creator.js +54 -43
- package/helpers/external-proxy.d.ts +2 -2
- package/helpers/external-proxy.js +3 -7
- package/helpers/get-class-scope.d.ts +2 -2
- package/helpers/get-class-scope.js +3 -6
- package/helpers/handler-metadata-storage.d.ts +4 -4
- package/helpers/handler-metadata-storage.js +7 -15
- package/helpers/http-adapter-host.d.ts +1 -1
- package/helpers/http-adapter-host.js +6 -11
- package/helpers/index.d.ts +3 -3
- package/helpers/index.js +3 -6
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +2 -2
- package/helpers/interfaces/external-handler-metadata.interface.js +1 -2
- package/helpers/interfaces/index.d.ts +2 -2
- package/helpers/interfaces/index.js +2 -5
- package/helpers/interfaces/params-metadata.interface.d.ts +1 -1
- package/helpers/interfaces/params-metadata.interface.js +1 -2
- package/helpers/is-durable.d.ts +1 -1
- package/helpers/is-durable.js +3 -6
- package/helpers/load-adapter.d.ts +1 -1
- package/helpers/load-adapter.js +4 -7
- package/helpers/messages.d.ts +1 -1
- package/helpers/messages.js +10 -20
- package/helpers/optional-require.d.ts +1 -1
- package/helpers/optional-require.js +2 -5
- package/helpers/rethrow.js +1 -5
- package/helpers/router-method-factory.d.ts +2 -2
- package/helpers/router-method-factory.js +20 -24
- package/hooks/before-app-shutdown.hook.d.ts +3 -3
- package/hooks/before-app-shutdown.hook.js +15 -22
- package/hooks/index.d.ts +5 -5
- package/hooks/index.js +5 -8
- package/hooks/on-app-bootstrap.hook.d.ts +3 -3
- package/hooks/on-app-bootstrap.hook.js +15 -22
- package/hooks/on-app-shutdown.hook.d.ts +3 -3
- package/hooks/on-app-shutdown.hook.js +15 -22
- package/hooks/on-module-destroy.hook.d.ts +3 -3
- package/hooks/on-module-destroy.hook.js +15 -22
- package/hooks/on-module-init.hook.d.ts +3 -3
- package/hooks/on-module-init.hook.js +15 -22
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.d.ts +3 -0
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.js +27 -0
- package/hooks/utils/get-sorted-hierarchy-levels.d.ts +1 -0
- package/hooks/utils/get-sorted-hierarchy-levels.js +7 -0
- package/index.d.ts +16 -16
- package/index.js +17 -26
- package/injector/abstract-instance-resolver.d.ts +6 -6
- package/injector/abstract-instance-resolver.js +7 -11
- package/injector/compiler.d.ts +2 -2
- package/injector/compiler.js +2 -5
- package/injector/constants.d.ts +1 -1
- package/injector/constants.js +2 -5
- package/injector/container.d.ts +13 -14
- package/injector/container.js +40 -40
- package/injector/helpers/provider-classifier.d.ts +1 -1
- package/injector/helpers/provider-classifier.js +5 -10
- package/injector/helpers/silent-logger.js +9 -16
- package/injector/index.d.ts +6 -6
- package/injector/index.js +5 -8
- package/injector/injector.d.ts +7 -6
- package/injector/injector.js +78 -78
- package/injector/inquirer/index.d.ts +1 -1
- package/injector/inquirer/index.js +1 -4
- package/injector/inquirer/inquirer-constants.js +1 -4
- package/injector/inquirer/inquirer-providers.d.ts +1 -1
- package/injector/inquirer/inquirer-providers.js +5 -8
- package/injector/instance-links-host.d.ts +3 -3
- package/injector/instance-links-host.js +8 -11
- package/injector/instance-loader.d.ts +5 -5
- package/injector/instance-loader.js +11 -11
- package/injector/instance-wrapper.d.ts +8 -5
- package/injector/instance-wrapper.js +93 -74
- package/injector/internal-core-module/index.d.ts +1 -1
- package/injector/internal-core-module/index.js +1 -4
- package/injector/internal-core-module/internal-core-module-factory.d.ts +6 -6
- package/injector/internal-core-module/internal-core-module-factory.js +23 -27
- package/injector/internal-core-module/internal-core-module.d.ts +2 -2
- package/injector/internal-core-module/internal-core-module.js +17 -20
- package/injector/internal-providers-storage.d.ts +2 -2
- package/injector/internal-providers-storage.js +4 -9
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +1 -2
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +8 -8
- package/injector/lazy-module-loader/lazy-module-loader.js +10 -9
- package/injector/module-ref.d.ts +7 -7
- package/injector/module-ref.js +19 -20
- package/injector/module.d.ts +5 -5
- package/injector/module.js +93 -79
- package/injector/modules-container.d.ts +1 -1
- package/injector/modules-container.js +5 -12
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +2 -4
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +6 -9
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +2 -3
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +17 -22
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +1 -3
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +1 -2
- package/injector/settlement-signal.js +5 -7
- package/injector/topology-tree/topology-tree.d.ts +1 -1
- package/injector/topology-tree/topology-tree.js +6 -9
- package/injector/topology-tree/tree-node.js +4 -6
- package/inspector/deterministic-uuid-registry.js +2 -6
- package/inspector/graph-inspector.d.ts +7 -7
- package/inspector/graph-inspector.js +10 -12
- package/inspector/index.d.ts +4 -4
- package/inspector/index.js +4 -7
- package/inspector/initialize-on-preview.allowlist.d.ts +1 -1
- package/inspector/initialize-on-preview.allowlist.js +2 -6
- package/inspector/interfaces/edge.interface.d.ts +1 -1
- package/inspector/interfaces/edge.interface.js +1 -2
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +3 -3
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +1 -2
- package/inspector/interfaces/entrypoint.interface.d.ts +2 -2
- package/inspector/interfaces/entrypoint.interface.js +1 -2
- package/inspector/interfaces/extras.interface.d.ts +1 -1
- package/inspector/interfaces/extras.interface.js +1 -2
- package/inspector/interfaces/node.interface.d.ts +2 -2
- package/inspector/interfaces/node.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +6 -6
- package/inspector/interfaces/serialized-graph-json.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +1 -1
- package/inspector/interfaces/serialized-graph-metadata.interface.js +1 -2
- package/inspector/noop-graph-inspector.d.ts +1 -1
- package/inspector/noop-graph-inspector.js +2 -5
- package/inspector/partial-graph.host.d.ts +2 -2
- package/inspector/partial-graph.host.js +2 -5
- package/inspector/serialized-graph.d.ts +7 -7
- package/inspector/serialized-graph.js +35 -40
- package/inspector/uuid-factory.js +8 -12
- package/interceptors/index.d.ts +2 -2
- package/interceptors/index.js +2 -5
- package/interceptors/interceptors-consumer.d.ts +4 -3
- package/interceptors/interceptors-consumer.js +13 -17
- package/interceptors/interceptors-context-creator.d.ts +10 -9
- package/interceptors/interceptors-context-creator.js +18 -20
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/module-definition.interface.d.ts +2 -2
- package/interfaces/module-definition.interface.js +1 -2
- package/interfaces/module-override.interface.d.ts +1 -1
- package/interfaces/module-override.interface.js +1 -2
- package/internal.d.ts +38 -0
- package/internal.js +46 -0
- package/metadata-scanner.d.ts +1 -1
- package/metadata-scanner.js +8 -14
- package/middleware/builder.d.ts +4 -4
- package/middleware/builder.js +78 -76
- package/middleware/container.d.ts +4 -4
- package/middleware/container.js +10 -13
- package/middleware/index.d.ts +1 -1
- package/middleware/index.js +1 -4
- package/middleware/middleware-module.d.ts +8 -9
- package/middleware/middleware-module.js +47 -44
- package/middleware/resolver.d.ts +3 -3
- package/middleware/resolver.js +3 -5
- package/middleware/route-info-path-extractor.d.ts +2 -2
- package/middleware/route-info-path-extractor.js +26 -25
- package/middleware/routes-mapper.d.ts +4 -3
- package/middleware/routes-mapper.js +22 -24
- package/middleware/utils.d.ts +3 -2
- package/middleware/utils.js +34 -45
- package/nest-application-context.d.ts +10 -9
- package/nest-application-context.js +50 -47
- package/nest-application.d.ts +18 -10
- package/nest-application.js +87 -55
- package/nest-factory.d.ts +4 -5
- package/nest-factory.js +61 -68
- package/package.json +32 -3
- package/pipes/index.d.ts +3 -3
- package/pipes/index.js +3 -6
- package/pipes/params-token-factory.d.ts +2 -2
- package/pipes/params-token-factory.js +5 -9
- package/pipes/pipes-consumer.d.ts +3 -7
- package/pipes/pipes-consumer.js +17 -18
- package/pipes/pipes-context-creator.d.ts +10 -9
- package/pipes/pipes-context-creator.js +18 -20
- package/repl/assign-to-object.util.js +1 -4
- package/repl/constants.js +1 -4
- package/repl/index.d.ts +1 -1
- package/repl/index.js +1 -4
- package/repl/native-functions/debug-repl-fn.d.ts +2 -2
- package/repl/native-functions/debug-repl-fn.js +14 -21
- package/repl/native-functions/get-repl-fn.d.ts +2 -2
- package/repl/native-functions/get-repl-fn.js +8 -15
- package/repl/native-functions/help-repl-fn.d.ts +2 -2
- package/repl/native-functions/help-repl-fn.js +13 -20
- package/repl/native-functions/index.d.ts +6 -6
- package/repl/native-functions/index.js +6 -9
- package/repl/native-functions/methods-repl-fn.d.ts +2 -2
- package/repl/native-functions/methods-repl-fn.js +12 -19
- package/repl/native-functions/resolve-repl-fn.d.ts +2 -2
- package/repl/native-functions/resolve-repl-fn.js +7 -14
- package/repl/native-functions/select-relp-fn.d.ts +2 -2
- package/repl/native-functions/select-relp-fn.js +7 -14
- package/repl/repl-context.d.ts +3 -3
- package/repl/repl-context.js +21 -23
- package/repl/repl-function.d.ts +3 -3
- package/repl/repl-function.js +5 -7
- package/repl/repl-logger.js +10 -14
- package/repl/repl-native-commands.js +1 -4
- package/repl/repl.d.ts +1 -1
- package/repl/repl.interfaces.d.ts +2 -2
- package/repl/repl.interfaces.js +1 -2
- package/repl/repl.js +17 -20
- package/router/index.d.ts +3 -3
- package/router/index.js +3 -8
- package/router/interfaces/exceptions-filter.interface.d.ts +3 -3
- package/router/interfaces/exceptions-filter.interface.js +1 -2
- package/router/interfaces/exclude-route-metadata.interface.d.ts +1 -1
- package/router/interfaces/exclude-route-metadata.interface.js +1 -2
- package/router/interfaces/index.d.ts +1 -1
- package/router/interfaces/index.js +1 -4
- package/router/interfaces/resolver.interface.js +1 -2
- package/router/interfaces/route-params-factory.interface.d.ts +1 -1
- package/router/interfaces/route-params-factory.interface.js +1 -2
- package/router/interfaces/route-path-metadata.interface.d.ts +2 -2
- package/router/interfaces/route-path-metadata.interface.js +1 -2
- package/router/interfaces/routes.interface.d.ts +1 -1
- package/router/interfaces/routes.interface.js +1 -2
- package/router/legacy-route-converter.js +3 -7
- package/router/paths-explorer.d.ts +4 -5
- package/router/paths-explorer.js +11 -15
- package/router/request/index.d.ts +1 -1
- package/router/request/index.js +1 -5
- package/router/request/request-constants.js +2 -5
- package/router/request/request-providers.d.ts +1 -1
- package/router/request/request-providers.js +5 -8
- package/router/route-params-factory.d.ts +2 -2
- package/router/route-params-factory.js +15 -19
- package/router/route-path-factory.d.ts +4 -4
- package/router/route-path-factory.js +19 -22
- package/router/router-exception-filters.d.ts +9 -9
- package/router/router-exception-filters.js +15 -18
- package/router/router-execution-context.d.ts +17 -20
- package/router/router-execution-context.js +57 -49
- package/router/router-explorer.d.ts +14 -16
- package/router/router-explorer.js +55 -54
- package/router/router-module.d.ts +4 -4
- package/router/router-module.js +21 -23
- package/router/router-proxy.d.ts +1 -1
- package/router/router-proxy.js +4 -8
- package/router/router-response-controller.d.ts +2 -2
- package/router/router-response-controller.js +20 -23
- package/router/routes-resolver.d.ts +8 -9
- package/router/routes-resolver.js +36 -51
- package/router/sse-stream.d.ts +1 -1
- package/router/sse-stream.js +5 -9
- package/router/utils/exclude-route.util.d.ts +1 -1
- package/router/utils/exclude-route.util.js +7 -12
- package/router/utils/flatten-route-paths.util.d.ts +2 -2
- package/router/utils/flatten-route-paths.util.js +4 -7
- package/router/utils/index.d.ts +2 -2
- package/router/utils/index.js +2 -5
- package/scanner.d.ts +11 -11
- package/scanner.js +64 -65
- package/services/index.d.ts +1 -1
- package/services/index.js +1 -4
- package/services/reflector.service.d.ts +1 -1
- package/services/reflector.service.js +9 -13
- package/tsconfig.build.json +1 -9
package/scanner.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { iterate } from 'iterare';
|
|
2
|
+
import { ApplicationConfig } from './application-config.js';
|
|
3
|
+
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE, ENHANCER_TOKEN_TO_SUBTYPE_MAP, } from './constants.js';
|
|
4
|
+
import { CircularDependencyException } from './errors/exceptions/circular-dependency.exception.js';
|
|
5
|
+
import { InvalidClassModuleException } from './errors/exceptions/invalid-class-module.exception.js';
|
|
6
|
+
import { InvalidModuleException } from './errors/exceptions/invalid-module.exception.js';
|
|
7
|
+
import { UndefinedModuleException } from './errors/exceptions/undefined-module.exception.js';
|
|
8
|
+
import { getClassScope } from './helpers/get-class-scope.js';
|
|
9
|
+
import { InternalCoreModuleFactory } from './injector/internal-core-module/internal-core-module-factory.js';
|
|
10
|
+
import { TopologyTree } from './injector/topology-tree/topology-tree.js';
|
|
11
|
+
import { UuidFactory } from './inspector/uuid-factory.js';
|
|
12
|
+
import { CATCH_WATERMARK, CONTROLLER_WATERMARK, ENHANCER_KEY_TO_SUBTYPE_MAP, EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INJECTABLE_WATERMARK, INTERCEPTORS_METADATA, MODULE_METADATA, PIPES_METADATA, ROUTE_ARGS_METADATA, isFunction, isNil, isUndefined, } from '@nestjs/common/internal';
|
|
13
|
+
import { Scope, } from '@nestjs/common';
|
|
14
|
+
export class DependenciesScanner {
|
|
15
|
+
container;
|
|
16
|
+
metadataScanner;
|
|
17
|
+
graphInspector;
|
|
18
|
+
applicationConfig;
|
|
19
|
+
applicationProvidersApplyMap = [];
|
|
20
|
+
constructor(container, metadataScanner, graphInspector, applicationConfig = new ApplicationConfig()) {
|
|
20
21
|
this.container = container;
|
|
21
22
|
this.metadataScanner = metadataScanner;
|
|
22
23
|
this.graphInspector = graphInspector;
|
|
23
24
|
this.applicationConfig = applicationConfig;
|
|
24
|
-
this.applicationProvidersApplyMap = [];
|
|
25
25
|
}
|
|
26
26
|
async scan(module, options) {
|
|
27
27
|
await this.registerCoreModule(options?.overrides);
|
|
@@ -52,19 +52,19 @@ class DependenciesScanner {
|
|
|
52
52
|
moduleDefinition = moduleDefinition.forwardRef();
|
|
53
53
|
}
|
|
54
54
|
const modules = !this.isDynamicModule(moduleDefinition)
|
|
55
|
-
? this.reflectMetadata(
|
|
55
|
+
? this.reflectMetadata(MODULE_METADATA.IMPORTS, moduleDefinition)
|
|
56
56
|
: [
|
|
57
|
-
...this.reflectMetadata(
|
|
57
|
+
...this.reflectMetadata(MODULE_METADATA.IMPORTS, moduleDefinition.module),
|
|
58
58
|
...(moduleDefinition.imports || []),
|
|
59
59
|
];
|
|
60
60
|
let registeredModuleRefs = [];
|
|
61
61
|
for (const [index, innerModule] of modules.entries()) {
|
|
62
62
|
// In case of a circular dependency (ES module system), JavaScript will resolve the type to `undefined`.
|
|
63
63
|
if (innerModule === undefined) {
|
|
64
|
-
throw new
|
|
64
|
+
throw new UndefinedModuleException(moduleDefinition, index, scope);
|
|
65
65
|
}
|
|
66
66
|
if (!innerModule) {
|
|
67
|
-
throw new
|
|
67
|
+
throw new InvalidModuleException(moduleDefinition, index, scope);
|
|
68
68
|
}
|
|
69
69
|
if (ctxRegistry.includes(innerModule)) {
|
|
70
70
|
continue;
|
|
@@ -93,7 +93,7 @@ class DependenciesScanner {
|
|
|
93
93
|
if (this.isInjectable(moduleToAdd) ||
|
|
94
94
|
this.isController(moduleToAdd) ||
|
|
95
95
|
this.isExceptionFilter(moduleToAdd)) {
|
|
96
|
-
throw new
|
|
96
|
+
throw new InvalidClassModuleException(moduleDefinition, scope);
|
|
97
97
|
}
|
|
98
98
|
return this.container.addModule(moduleToAdd, scope);
|
|
99
99
|
}
|
|
@@ -107,8 +107,8 @@ class DependenciesScanner {
|
|
|
107
107
|
}
|
|
108
108
|
async reflectImports(module, token, context) {
|
|
109
109
|
const modules = [
|
|
110
|
-
...this.reflectMetadata(
|
|
111
|
-
...this.container.getDynamicMetadataByToken(token,
|
|
110
|
+
...this.reflectMetadata(MODULE_METADATA.IMPORTS, module),
|
|
111
|
+
...this.container.getDynamicMetadataByToken(token, MODULE_METADATA.IMPORTS),
|
|
112
112
|
];
|
|
113
113
|
for (const related of modules) {
|
|
114
114
|
await this.insertImport(related, token, context);
|
|
@@ -116,8 +116,8 @@ class DependenciesScanner {
|
|
|
116
116
|
}
|
|
117
117
|
reflectProviders(module, token) {
|
|
118
118
|
const providers = [
|
|
119
|
-
...this.reflectMetadata(
|
|
120
|
-
...this.container.getDynamicMetadataByToken(token,
|
|
119
|
+
...this.reflectMetadata(MODULE_METADATA.PROVIDERS, module),
|
|
120
|
+
...this.container.getDynamicMetadataByToken(token, MODULE_METADATA.PROVIDERS),
|
|
121
121
|
];
|
|
122
122
|
providers.forEach(provider => {
|
|
123
123
|
this.insertProvider(provider, token);
|
|
@@ -126,8 +126,8 @@ class DependenciesScanner {
|
|
|
126
126
|
}
|
|
127
127
|
reflectControllers(module, token) {
|
|
128
128
|
const controllers = [
|
|
129
|
-
...this.reflectMetadata(
|
|
130
|
-
...this.container.getDynamicMetadataByToken(token,
|
|
129
|
+
...this.reflectMetadata(MODULE_METADATA.CONTROLLERS, module),
|
|
130
|
+
...this.container.getDynamicMetadataByToken(token, MODULE_METADATA.CONTROLLERS),
|
|
131
131
|
];
|
|
132
132
|
controllers.forEach(item => {
|
|
133
133
|
this.insertController(item, token);
|
|
@@ -138,16 +138,16 @@ class DependenciesScanner {
|
|
|
138
138
|
if (!cls || !cls.prototype) {
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
this.reflectInjectables(cls, token,
|
|
142
|
-
this.reflectInjectables(cls, token,
|
|
143
|
-
this.reflectInjectables(cls, token,
|
|
144
|
-
this.reflectInjectables(cls, token,
|
|
145
|
-
this.reflectParamInjectables(cls, token,
|
|
141
|
+
this.reflectInjectables(cls, token, GUARDS_METADATA);
|
|
142
|
+
this.reflectInjectables(cls, token, INTERCEPTORS_METADATA);
|
|
143
|
+
this.reflectInjectables(cls, token, EXCEPTION_FILTERS_METADATA);
|
|
144
|
+
this.reflectInjectables(cls, token, PIPES_METADATA);
|
|
145
|
+
this.reflectParamInjectables(cls, token, ROUTE_ARGS_METADATA);
|
|
146
146
|
}
|
|
147
147
|
reflectExports(module, token) {
|
|
148
148
|
const exports = [
|
|
149
|
-
...this.reflectMetadata(
|
|
150
|
-
...this.container.getDynamicMetadataByToken(token,
|
|
149
|
+
...this.reflectMetadata(MODULE_METADATA.EXPORTS, module),
|
|
150
|
+
...this.container.getDynamicMetadataByToken(token, MODULE_METADATA.EXPORTS),
|
|
151
151
|
];
|
|
152
152
|
exports.forEach(exportedProvider => this.insertExportedProviderOrModule(exportedProvider, token));
|
|
153
153
|
}
|
|
@@ -162,9 +162,9 @@ class DependenciesScanner {
|
|
|
162
162
|
}
|
|
163
163
|
return acc;
|
|
164
164
|
}, []);
|
|
165
|
-
controllerInjectables.forEach(injectable => this.insertInjectable(injectable, token, component,
|
|
165
|
+
controllerInjectables.forEach(injectable => this.insertInjectable(injectable, token, component, ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey]));
|
|
166
166
|
methodInjectables.forEach(methodInjectable => {
|
|
167
|
-
methodInjectable.metadata.forEach(injectable => this.insertInjectable(injectable, token, component,
|
|
167
|
+
methodInjectable.metadata.forEach(injectable => this.insertInjectable(injectable, token, component, ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey], methodInjectable.methodKey));
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
reflectParamInjectables(component, token, metadataKey) {
|
|
@@ -208,7 +208,7 @@ class DependenciesScanner {
|
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
210
|
// Convert modules to an acyclic connected graph
|
|
211
|
-
const tree = new
|
|
211
|
+
const tree = new TopologyTree(rootModule);
|
|
212
212
|
tree.walk((moduleRef, depth) => {
|
|
213
213
|
if (moduleRef.isGlobal) {
|
|
214
214
|
return;
|
|
@@ -217,8 +217,8 @@ class DependenciesScanner {
|
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
219
|
async insertImport(related, token, context) {
|
|
220
|
-
if (
|
|
221
|
-
throw new
|
|
220
|
+
if (isUndefined(related)) {
|
|
221
|
+
throw new CircularDependencyException(context);
|
|
222
222
|
}
|
|
223
223
|
if (this.isForwardReference(related)) {
|
|
224
224
|
return this.container.addImport(related.forwardRef(), token);
|
|
@@ -226,7 +226,7 @@ class DependenciesScanner {
|
|
|
226
226
|
await this.container.addImport(related, token);
|
|
227
227
|
}
|
|
228
228
|
isCustomProvider(provider) {
|
|
229
|
-
return provider && !
|
|
229
|
+
return provider && !isNil(provider.provide);
|
|
230
230
|
}
|
|
231
231
|
insertProvider(provider, token) {
|
|
232
232
|
const isCustomProvider = this.isCustomProvider(provider);
|
|
@@ -239,11 +239,11 @@ class DependenciesScanner {
|
|
|
239
239
|
if (!providersKeys.includes(type)) {
|
|
240
240
|
return this.container.addProvider(provider, token);
|
|
241
241
|
}
|
|
242
|
-
const uuid =
|
|
242
|
+
const uuid = UuidFactory.get(type.toString());
|
|
243
243
|
const providerToken = `${type} (UUID: ${uuid})`;
|
|
244
244
|
let scope = provider.scope;
|
|
245
|
-
if (
|
|
246
|
-
scope =
|
|
245
|
+
if (isNil(scope) && provider.useClass) {
|
|
246
|
+
scope = getClassScope(provider.useClass);
|
|
247
247
|
}
|
|
248
248
|
this.applicationProvidersApplyMap.push({
|
|
249
249
|
type,
|
|
@@ -256,7 +256,7 @@ class DependenciesScanner {
|
|
|
256
256
|
provide: providerToken,
|
|
257
257
|
scope,
|
|
258
258
|
};
|
|
259
|
-
const enhancerSubtype =
|
|
259
|
+
const enhancerSubtype = ENHANCER_TOKEN_TO_SUBTYPE_MAP[type];
|
|
260
260
|
const factoryOrClassProvider = newProvider;
|
|
261
261
|
if (this.isRequestOrTransient(factoryOrClassProvider.scope)) {
|
|
262
262
|
return this.container.addInjectable(newProvider, token, enhancerSubtype);
|
|
@@ -264,7 +264,7 @@ class DependenciesScanner {
|
|
|
264
264
|
this.container.addProvider(newProvider, token, enhancerSubtype);
|
|
265
265
|
}
|
|
266
266
|
insertInjectable(injectable, token, host, subtype, methodKey) {
|
|
267
|
-
if (
|
|
267
|
+
if (isFunction(injectable)) {
|
|
268
268
|
const instanceWrapper = this.container.addInjectable(injectable, token, subtype, host);
|
|
269
269
|
this.graphInspector.insertEnhancerMetadataCache({
|
|
270
270
|
moduleToken: token,
|
|
@@ -320,7 +320,7 @@ class DependenciesScanner {
|
|
|
320
320
|
return Reflect.getMetadata(metadataKey, metatype) || [];
|
|
321
321
|
}
|
|
322
322
|
async registerCoreModule(overrides) {
|
|
323
|
-
const moduleDefinition =
|
|
323
|
+
const moduleDefinition = InternalCoreModuleFactory.create(this.container, this, this.container.getModuleCompiler(), this.container.getHttpAdapterHostRef(), this.graphInspector, overrides);
|
|
324
324
|
const [instance] = await this.scanForModules({
|
|
325
325
|
moduleDefinition,
|
|
326
326
|
overrides,
|
|
@@ -332,14 +332,14 @@ class DependenciesScanner {
|
|
|
332
332
|
* to all controllers metadata storage
|
|
333
333
|
*/
|
|
334
334
|
addScopedEnhancersMetadata() {
|
|
335
|
-
|
|
335
|
+
iterate(this.applicationProvidersApplyMap)
|
|
336
336
|
.filter(wrapper => this.isRequestOrTransient(wrapper.scope))
|
|
337
337
|
.forEach(({ moduleKey, providerKey }) => {
|
|
338
338
|
const modulesContainer = this.container.getModules();
|
|
339
339
|
const { injectables } = modulesContainer.get(moduleKey);
|
|
340
340
|
const instanceWrapper = injectables.get(providerKey);
|
|
341
341
|
const iterableIterator = modulesContainer.values();
|
|
342
|
-
|
|
342
|
+
iterate(iterableIterator)
|
|
343
343
|
.map(moduleRef => Array.from(moduleRef.controllers.values()).concat(moduleRef.entryProviders))
|
|
344
344
|
.flatten()
|
|
345
345
|
.forEach(controllerOrEntryProvider => controllerOrEntryProvider.addEnhancerMetadata(instanceWrapper));
|
|
@@ -368,18 +368,18 @@ class DependenciesScanner {
|
|
|
368
368
|
}
|
|
369
369
|
getApplyProvidersMap() {
|
|
370
370
|
return {
|
|
371
|
-
[
|
|
372
|
-
[
|
|
373
|
-
[
|
|
374
|
-
[
|
|
371
|
+
[APP_INTERCEPTOR]: (interceptor) => this.applicationConfig.addGlobalInterceptor(interceptor),
|
|
372
|
+
[APP_PIPE]: (pipe) => this.applicationConfig.addGlobalPipe(pipe),
|
|
373
|
+
[APP_GUARD]: (guard) => this.applicationConfig.addGlobalGuard(guard),
|
|
374
|
+
[APP_FILTER]: (filter) => this.applicationConfig.addGlobalFilter(filter),
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
377
|
getApplyRequestProvidersMap() {
|
|
378
378
|
return {
|
|
379
|
-
[
|
|
380
|
-
[
|
|
381
|
-
[
|
|
382
|
-
[
|
|
379
|
+
[APP_INTERCEPTOR]: (interceptor) => this.applicationConfig.addGlobalRequestInterceptor(interceptor),
|
|
380
|
+
[APP_PIPE]: (pipe) => this.applicationConfig.addGlobalRequestPipe(pipe),
|
|
381
|
+
[APP_GUARD]: (guard) => this.applicationConfig.addGlobalRequestGuard(guard),
|
|
382
|
+
[APP_FILTER]: (filter) => this.applicationConfig.addGlobalRequestFilter(filter),
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
385
|
isDynamicModule(module) {
|
|
@@ -390,27 +390,26 @@ class DependenciesScanner {
|
|
|
390
390
|
* @returns `true` if `metatype` is annotated with the `@Injectable()` decorator.
|
|
391
391
|
*/
|
|
392
392
|
isInjectable(metatype) {
|
|
393
|
-
return !!Reflect.getMetadata(
|
|
393
|
+
return !!Reflect.getMetadata(INJECTABLE_WATERMARK, metatype);
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
396
|
* @param metatype
|
|
397
397
|
* @returns `true` if `metatype` is annotated with the `@Controller()` decorator.
|
|
398
398
|
*/
|
|
399
399
|
isController(metatype) {
|
|
400
|
-
return !!Reflect.getMetadata(
|
|
400
|
+
return !!Reflect.getMetadata(CONTROLLER_WATERMARK, metatype);
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* @param metatype
|
|
404
404
|
* @returns `true` if `metatype` is annotated with the `@Catch()` decorator.
|
|
405
405
|
*/
|
|
406
406
|
isExceptionFilter(metatype) {
|
|
407
|
-
return !!Reflect.getMetadata(
|
|
407
|
+
return !!Reflect.getMetadata(CATCH_WATERMARK, metatype);
|
|
408
408
|
}
|
|
409
409
|
isForwardReference(module) {
|
|
410
410
|
return module && !!module.forwardRef;
|
|
411
411
|
}
|
|
412
412
|
isRequestOrTransient(scope) {
|
|
413
|
-
return scope ===
|
|
413
|
+
return scope === Scope.REQUEST || scope === Scope.TRANSIENT;
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
exports.DependenciesScanner = DependenciesScanner;
|
package/services/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './reflector.service';
|
|
1
|
+
export * from './reflector.service.js';
|
package/services/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
-
const uid_1 = require("uid");
|
|
1
|
+
import { SetMetadata } from '@nestjs/common';
|
|
2
|
+
import { uid } from 'uid';
|
|
3
|
+
import { isEmptyArray, isObject } from '@nestjs/common/internal';
|
|
7
4
|
/**
|
|
8
5
|
* Helper class providing Nest reflection capabilities.
|
|
9
6
|
*
|
|
@@ -11,14 +8,14 @@ const uid_1 = require("uid");
|
|
|
11
8
|
*
|
|
12
9
|
* @publicApi
|
|
13
10
|
*/
|
|
14
|
-
class Reflector {
|
|
11
|
+
export class Reflector {
|
|
15
12
|
static createDecorator(options = {}) {
|
|
16
|
-
const metadataKey = options.key ??
|
|
13
|
+
const metadataKey = options.key ?? uid(21);
|
|
17
14
|
const decoratorFn = (metadataValue) => (target, key, descriptor) => {
|
|
18
15
|
const value = options.transform
|
|
19
16
|
? options.transform(metadataValue)
|
|
20
17
|
: metadataValue;
|
|
21
|
-
|
|
18
|
+
SetMetadata(metadataKey, value ?? {})(target, key, descriptor);
|
|
22
19
|
};
|
|
23
20
|
decoratorFn.KEY = metadataKey;
|
|
24
21
|
return decoratorFn;
|
|
@@ -57,12 +54,12 @@ class Reflector {
|
|
|
57
54
|
*/
|
|
58
55
|
getAllAndMerge(metadataKeyOrDecorator, targets) {
|
|
59
56
|
const metadataCollection = this.getAll(metadataKeyOrDecorator, targets).filter(item => item !== undefined);
|
|
60
|
-
if ((
|
|
57
|
+
if (isEmptyArray(metadataCollection)) {
|
|
61
58
|
return metadataCollection;
|
|
62
59
|
}
|
|
63
60
|
if (metadataCollection.length === 1) {
|
|
64
61
|
const value = metadataCollection[0];
|
|
65
|
-
if (
|
|
62
|
+
if (isObject(value)) {
|
|
66
63
|
return value;
|
|
67
64
|
}
|
|
68
65
|
return metadataCollection;
|
|
@@ -71,7 +68,7 @@ class Reflector {
|
|
|
71
68
|
if (Array.isArray(a)) {
|
|
72
69
|
return a.concat(b);
|
|
73
70
|
}
|
|
74
|
-
if (
|
|
71
|
+
if (isObject(a) && isObject(b)) {
|
|
75
72
|
return {
|
|
76
73
|
...a,
|
|
77
74
|
...b,
|
|
@@ -97,4 +94,3 @@ class Reflector {
|
|
|
97
94
|
return undefined;
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
|
-
exports.Reflector = Reflector;
|
package/tsconfig.build.json
CHANGED
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
"extends": "../tsconfig.build.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"outDir": ".",
|
|
5
|
-
"rootDir": "."
|
|
6
|
-
"paths": {
|
|
7
|
-
"@nestjs/common": ["../common"],
|
|
8
|
-
"@nestjs/common/*": ["../common/*"],
|
|
9
|
-
"@nestjs/microservices": ["../microservices"],
|
|
10
|
-
"@nestjs/microservices/*": ["../microservices/*"],
|
|
11
|
-
"@nestjs/websockets": ["../websockets"],
|
|
12
|
-
"@nestjs/websockets/*": ["../websockets/*"]
|
|
13
|
-
}
|
|
5
|
+
"rootDir": "."
|
|
14
6
|
},
|
|
15
7
|
"exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"],
|
|
16
8
|
"references": [
|