@depup/nestjs__core 11.1.17-depup.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/LICENSE +22 -0
- package/PACKAGE.md +1 -0
- package/README.md +25 -0
- package/Readme.md +146 -0
- package/adapters/http-adapter.d.ts +80 -0
- package/adapters/http-adapter.js +90 -0
- package/adapters/index.d.ts +1 -0
- package/adapters/index.js +4 -0
- package/application-config.d.ts +47 -0
- package/application-config.js +107 -0
- package/changes.json +5 -0
- package/constants.d.ts +14 -0
- package/constants.js +21 -0
- package/discovery/discoverable-meta-host-collection.d.ts +46 -0
- package/discovery/discoverable-meta-host-collection.js +98 -0
- package/discovery/discovery-module.d.ts +5 -0
- package/discovery/discovery-module.js +19 -0
- package/discovery/discovery-service.d.ts +76 -0
- package/discovery/discovery-service.js +98 -0
- package/discovery/index.d.ts +2 -0
- package/discovery/index.js +5 -0
- package/errors/exception-handler.d.ts +4 -0
- package/errors/exception-handler.js +11 -0
- package/errors/exceptions/circular-dependency.exception.d.ts +4 -0
- package/errors/exceptions/circular-dependency.exception.js +11 -0
- package/errors/exceptions/index.d.ts +8 -0
- package/errors/exceptions/index.js +11 -0
- package/errors/exceptions/invalid-class-module.exception.d.ts +4 -0
- package/errors/exceptions/invalid-class-module.exception.js +11 -0
- package/errors/exceptions/invalid-class-scope.exception.d.ts +5 -0
- package/errors/exceptions/invalid-class-scope.exception.js +16 -0
- package/errors/exceptions/invalid-class.exception.d.ts +4 -0
- package/errors/exceptions/invalid-class.exception.js +11 -0
- package/errors/exceptions/invalid-exception-filter.exception.d.ts +4 -0
- package/errors/exceptions/invalid-exception-filter.exception.js +11 -0
- package/errors/exceptions/invalid-middleware-configuration.exception.d.ts +4 -0
- package/errors/exceptions/invalid-middleware-configuration.exception.js +11 -0
- package/errors/exceptions/invalid-middleware.exception.d.ts +4 -0
- package/errors/exceptions/invalid-middleware.exception.js +11 -0
- package/errors/exceptions/invalid-module.exception.d.ts +4 -0
- package/errors/exceptions/invalid-module.exception.js +11 -0
- package/errors/exceptions/runtime.exception.d.ts +4 -0
- package/errors/exceptions/runtime.exception.js +12 -0
- package/errors/exceptions/undefined-dependency.exception.d.ts +6 -0
- package/errors/exceptions/undefined-dependency.exception.js +11 -0
- package/errors/exceptions/undefined-forwardref.exception.d.ts +5 -0
- package/errors/exceptions/undefined-forwardref.exception.js +11 -0
- package/errors/exceptions/undefined-module.exception.d.ts +4 -0
- package/errors/exceptions/undefined-module.exception.js +11 -0
- package/errors/exceptions/unknown-dependencies.exception.d.ts +16 -0
- package/errors/exceptions/unknown-dependencies.exception.js +15 -0
- package/errors/exceptions/unknown-element.exception.d.ts +4 -0
- package/errors/exceptions/unknown-element.exception.js +11 -0
- package/errors/exceptions/unknown-export.exception.d.ts +4 -0
- package/errors/exceptions/unknown-export.exception.js +11 -0
- package/errors/exceptions/unknown-module.exception.d.ts +4 -0
- package/errors/exceptions/unknown-module.exception.js +10 -0
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +5 -0
- package/errors/exceptions/unknown-request-mapping.exception.js +11 -0
- package/errors/exceptions-zone.d.ts +5 -0
- package/errors/exceptions-zone.js +34 -0
- package/errors/messages.d.ts +17 -0
- package/errors/messages.js +174 -0
- package/exceptions/base-exception-filter-context.d.ts +14 -0
- package/exceptions/base-exception-filter-context.js +56 -0
- package/exceptions/base-exception-filter.d.ts +20 -0
- package/exceptions/base-exception-filter.js +72 -0
- package/exceptions/exceptions-handler.d.ts +10 -0
- package/exceptions/exceptions-handler.js +34 -0
- package/exceptions/external-exception-filter-context.d.ts +12 -0
- package/exceptions/external-exception-filter-context.js +42 -0
- package/exceptions/external-exception-filter.d.ts +5 -0
- package/exceptions/external-exception-filter.js +15 -0
- package/exceptions/external-exceptions-handler.d.ts +9 -0
- package/exceptions/external-exceptions-handler.js +34 -0
- package/exceptions/index.d.ts +1 -0
- package/exceptions/index.js +4 -0
- package/guards/constants.d.ts +1 -0
- package/guards/constants.js +4 -0
- package/guards/guards-consumer.d.ts +9 -0
- package/guards/guards-consumer.js +39 -0
- package/guards/guards-context-creator.d.ts +17 -0
- package/guards/guards-context-creator.js +70 -0
- package/guards/index.d.ts +3 -0
- package/guards/index.js +6 -0
- package/helpers/barrier.d.ts +30 -0
- package/helpers/barrier.js +46 -0
- package/helpers/context-creator.d.ts +10 -0
- package/helpers/context-creator.js +33 -0
- package/helpers/context-id-factory.d.ts +41 -0
- package/helpers/context-id-factory.js +67 -0
- package/helpers/context-utils.d.ts +23 -0
- package/helpers/context-utils.js +55 -0
- package/helpers/execution-context-host.d.ts +19 -0
- package/helpers/execution-context-host.js +50 -0
- package/helpers/external-context-creator.d.ts +51 -0
- package/helpers/external-context-creator.js +166 -0
- package/helpers/external-proxy.d.ts +5 -0
- package/helpers/external-proxy.js +19 -0
- package/helpers/get-class-scope.d.ts +3 -0
- package/helpers/get-class-scope.js +8 -0
- package/helpers/handler-metadata-storage.d.ts +27 -0
- package/helpers/handler-metadata-storage.js +26 -0
- package/helpers/http-adapter-host.d.ts +51 -0
- package/helpers/http-adapter-host.js +73 -0
- package/helpers/index.d.ts +3 -0
- package/helpers/index.js +6 -0
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +11 -0
- package/helpers/interfaces/external-handler-metadata.interface.js +2 -0
- package/helpers/interfaces/index.d.ts +2 -0
- package/helpers/interfaces/index.js +5 -0
- package/helpers/interfaces/params-metadata.interface.d.ts +6 -0
- package/helpers/interfaces/params-metadata.interface.js +2 -0
- package/helpers/is-durable.d.ts +2 -0
- package/helpers/is-durable.js +8 -0
- package/helpers/load-adapter.d.ts +1 -0
- package/helpers/load-adapter.js +15 -0
- package/helpers/messages.d.ts +7 -0
- package/helpers/messages.js +29 -0
- package/helpers/optional-require.d.ts +1 -0
- package/helpers/optional-require.js +11 -0
- package/helpers/rethrow.d.ts +1 -0
- package/helpers/rethrow.js +7 -0
- package/helpers/router-method-factory.d.ts +23 -0
- package/helpers/router-method-factory.js +33 -0
- package/hooks/before-app-shutdown.hook.d.ts +9 -0
- package/hooks/before-app-shutdown.hook.js +51 -0
- package/hooks/index.d.ts +5 -0
- package/hooks/index.js +8 -0
- package/hooks/on-app-bootstrap.hook.d.ts +8 -0
- package/hooks/on-app-bootstrap.hook.js +53 -0
- package/hooks/on-app-shutdown.hook.d.ts +9 -0
- package/hooks/on-app-shutdown.hook.js +54 -0
- package/hooks/on-module-destroy.hook.d.ts +8 -0
- package/hooks/on-module-destroy.hook.js +53 -0
- package/hooks/on-module-init.hook.d.ts +8 -0
- package/hooks/on-module-init.hook.js +53 -0
- 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 +17 -0
- package/index.js +32 -0
- package/injector/abstract-instance-resolver.d.ts +16 -0
- package/injector/abstract-instance-resolver.js +49 -0
- package/injector/compiler.d.ts +18 -0
- package/injector/compiler.js +35 -0
- package/injector/constants.d.ts +3 -0
- package/injector/constants.js +8 -0
- package/injector/container.d.ts +67 -0
- package/injector/container.js +233 -0
- package/injector/helpers/provider-classifier.d.ts +4 -0
- package/injector/helpers/provider-classifier.js +16 -0
- package/injector/helpers/silent-logger.d.ts +10 -0
- package/injector/helpers/silent-logger.js +18 -0
- package/injector/helpers/transient-instances.d.ts +12 -0
- package/injector/helpers/transient-instances.js +28 -0
- package/injector/index.d.ts +6 -0
- package/injector/index.js +8 -0
- package/injector/injector.d.ts +104 -0
- package/injector/injector.js +554 -0
- package/injector/inquirer/index.d.ts +1 -0
- package/injector/inquirer/index.js +4 -0
- package/injector/inquirer/inquirer-constants.d.ts +1 -0
- package/injector/inquirer/inquirer-constants.js +4 -0
- package/injector/inquirer/inquirer-providers.d.ts +2 -0
- package/injector/inquirer/inquirer-providers.js +11 -0
- package/injector/instance-links-host.d.ts +22 -0
- package/injector/instance-links-host.js +56 -0
- package/injector/instance-loader.d.ts +23 -0
- package/injector/instance-loader.js +88 -0
- package/injector/instance-wrapper.d.ts +99 -0
- package/injector/instance-wrapper.js +350 -0
- package/injector/internal-core-module/index.d.ts +1 -0
- package/injector/internal-core-module/index.js +4 -0
- package/injector/internal-core-module/internal-core-module-factory.d.ts +9 -0
- package/injector/internal-core-module/internal-core-module-factory.js +52 -0
- package/injector/internal-core-module/internal-core-module.d.ts +5 -0
- package/injector/internal-core-module/internal-core-module.js +40 -0
- package/injector/internal-providers-storage.d.ts +9 -0
- package/injector/internal-providers-storage.js +19 -0
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.d.ts +6 -0
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +2 -0
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +20 -0
- package/injector/lazy-module-loader/lazy-module-loader.js +49 -0
- package/injector/module-ref.d.ts +106 -0
- package/injector/module-ref.js +66 -0
- package/injector/module.d.ts +82 -0
- package/injector/module.js +432 -0
- package/injector/modules-container.d.ts +27 -0
- package/injector/modules-container.js +42 -0
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +15 -0
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +41 -0
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +15 -0
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +83 -0
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +18 -0
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +2 -0
- package/injector/settlement-signal.d.ts +37 -0
- package/injector/settlement-signal.js +55 -0
- package/injector/topology-tree/topology-tree.d.ts +8 -0
- package/injector/topology-tree/topology-tree.js +51 -0
- package/injector/topology-tree/tree-node.d.ts +14 -0
- package/injector/topology-tree/tree-node.js +54 -0
- package/inspector/deterministic-uuid-registry.d.ts +6 -0
- package/inspector/deterministic-uuid-registry.js +24 -0
- package/inspector/graph-inspector.d.ts +26 -0
- package/inspector/graph-inspector.js +166 -0
- package/inspector/index.d.ts +4 -0
- package/inspector/index.js +7 -0
- package/inspector/initialize-on-preview.allowlist.d.ts +6 -0
- package/inspector/initialize-on-preview.allowlist.js +13 -0
- package/inspector/interfaces/edge.interface.d.ts +28 -0
- package/inspector/interfaces/edge.interface.js +2 -0
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +12 -0
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +2 -0
- package/inspector/interfaces/entrypoint.interface.d.ts +23 -0
- package/inspector/interfaces/entrypoint.interface.js +2 -0
- package/inspector/interfaces/extras.interface.d.ts +18 -0
- package/inspector/interfaces/extras.interface.js +2 -0
- package/inspector/interfaces/node.interface.d.ts +48 -0
- package/inspector/interfaces/node.interface.js +2 -0
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +14 -0
- package/inspector/interfaces/serialized-graph-json.interface.js +2 -0
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +10 -0
- package/inspector/interfaces/serialized-graph-metadata.interface.js +2 -0
- package/inspector/noop-graph-inspector.d.ts +2 -0
- package/inspector/noop-graph-inspector.js +8 -0
- package/inspector/partial-graph.host.d.ts +7 -0
- package/inspector/partial-graph.host.js +15 -0
- package/inspector/serialized-graph.d.ts +52 -0
- package/inspector/serialized-graph.js +124 -0
- package/inspector/uuid-factory.d.ts +9 -0
- package/inspector/uuid-factory.js +22 -0
- package/interceptors/index.d.ts +2 -0
- package/interceptors/index.js +5 -0
- package/interceptors/interceptors-consumer.d.ts +9 -0
- package/interceptors/interceptors-consumer.js +37 -0
- package/interceptors/interceptors-context-creator.d.ts +16 -0
- package/interceptors/interceptors-context-creator.js +69 -0
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/module-definition.interface.d.ts +3 -0
- package/interfaces/module-definition.interface.js +2 -0
- package/interfaces/module-override.interface.d.ts +5 -0
- package/interfaces/module-override.interface.js +2 -0
- package/internal.d.ts +38 -0
- package/internal.js +46 -0
- package/metadata-scanner.d.ts +17 -0
- package/metadata-scanner.js +83 -0
- package/middleware/builder.d.ts +15 -0
- package/middleware/builder.js +91 -0
- package/middleware/container.d.ts +14 -0
- package/middleware/container.js +49 -0
- package/middleware/index.d.ts +1 -0
- package/middleware/index.js +4 -0
- package/middleware/middleware-module.d.ts +33 -0
- package/middleware/middleware-module.js +208 -0
- package/middleware/resolver.d.ts +10 -0
- package/middleware/resolver.js +18 -0
- package/middleware/route-info-path-extractor.d.ts +15 -0
- package/middleware/route-info-path-extractor.js +81 -0
- package/middleware/routes-mapper.d.ts +19 -0
- package/middleware/routes-mapper.js +117 -0
- package/middleware/utils.d.ts +8 -0
- package/middleware/utils.js +106 -0
- package/nest-application-context.d.ts +173 -0
- package/nest-application-context.js +327 -0
- package/nest-application.d.ts +64 -0
- package/nest-application.js +328 -0
- package/nest-factory.d.ts +83 -0
- package/nest-factory.js +232 -0
- package/package.json +73 -0
- package/pipes/index.d.ts +3 -0
- package/pipes/index.js +6 -0
- package/pipes/params-token-factory.d.ts +5 -0
- package/pipes/params-token-factory.js +19 -0
- package/pipes/pipes-consumer.d.ts +10 -0
- package/pipes/pipes-consumer.js +21 -0
- package/pipes/pipes-context-creator.d.ts +17 -0
- package/pipes/pipes-context-creator.js +72 -0
- package/repl/assign-to-object.util.d.ts +5 -0
- package/repl/assign-to-object.util.js +14 -0
- package/repl/constants.d.ts +1 -0
- package/repl/constants.js +4 -0
- package/repl/index.d.ts +1 -0
- package/repl/index.js +4 -0
- package/repl/native-functions/debug-repl-fn.d.ts +9 -0
- package/repl/native-functions/debug-repl-fn.js +46 -0
- package/repl/native-functions/get-repl-fn.d.ts +7 -0
- package/repl/native-functions/get-repl-fn.js +19 -0
- package/repl/native-functions/help-repl-fn.d.ts +7 -0
- package/repl/native-functions/help-repl-fn.js +29 -0
- package/repl/native-functions/index.d.ts +6 -0
- package/repl/native-functions/index.js +9 -0
- package/repl/native-functions/methods-repl-fn.d.ts +8 -0
- package/repl/native-functions/methods-repl-fn.js +28 -0
- package/repl/native-functions/resolve-repl-fn.d.ts +7 -0
- package/repl/native-functions/resolve-repl-fn.js +18 -0
- package/repl/native-functions/select-relp-fn.d.ts +7 -0
- package/repl/native-functions/select-relp-fn.js +18 -0
- package/repl/repl-context.d.ts +26 -0
- package/repl/repl-context.js +126 -0
- package/repl/repl-function.d.ts +18 -0
- package/repl/repl-function.js +19 -0
- package/repl/repl-logger.d.ts +5 -0
- package/repl/repl-logger.js +22 -0
- package/repl/repl-native-commands.d.ts +2 -0
- package/repl/repl-native-commands.js +46 -0
- package/repl/repl.d.ts +3 -0
- package/repl/repl.interfaces.d.ts +16 -0
- package/repl/repl.interfaces.js +2 -0
- package/repl/repl.js +32 -0
- package/router/index.d.ts +3 -0
- package/router/index.js +8 -0
- package/router/interfaces/exceptions-filter.interface.d.ts +6 -0
- package/router/interfaces/exceptions-filter.interface.js +2 -0
- package/router/interfaces/exclude-route-metadata.interface.d.ts +15 -0
- package/router/interfaces/exclude-route-metadata.interface.js +2 -0
- package/router/interfaces/index.d.ts +1 -0
- package/router/interfaces/index.js +4 -0
- package/router/interfaces/resolver.interface.d.ts +5 -0
- package/router/interfaces/resolver.interface.js +2 -0
- package/router/interfaces/route-params-factory.interface.d.ts +8 -0
- package/router/interfaces/route-params-factory.interface.js +2 -0
- package/router/interfaces/route-path-metadata.interface.d.ts +32 -0
- package/router/interfaces/route-path-metadata.interface.js +2 -0
- package/router/interfaces/routes.interface.d.ts +7 -0
- package/router/interfaces/routes.interface.js +2 -0
- package/router/legacy-route-converter.d.ts +16 -0
- package/router/legacy-route-converter.js +61 -0
- package/router/paths-explorer.d.ts +18 -0
- package/router/paths-explorer.js +45 -0
- package/router/request/index.d.ts +1 -0
- package/router/request/index.js +5 -0
- package/router/request/request-constants.d.ts +2 -0
- package/router/request/request-constants.js +5 -0
- package/router/request/request-providers.d.ts +2 -0
- package/router/request/request-providers.js +11 -0
- package/router/route-params-factory.d.ts +9 -0
- package/router/route-params-factory.js +41 -0
- package/router/route-path-factory.d.ts +14 -0
- package/router/route-path-factory.js +101 -0
- package/router/router-exception-filters.d.ts +14 -0
- package/router/router-exception-filters.js +40 -0
- package/router/router-execution-context.d.ts +54 -0
- package/router/router-execution-context.js +186 -0
- package/router/router-explorer.d.ts +47 -0
- package/router/router-explorer.js +234 -0
- package/router/router-module.d.ts +19 -0
- package/router/router-module.js +80 -0
- package/router/router-proxy.d.ts +6 -0
- package/router/router-proxy.js +31 -0
- package/router/router-response-controller.d.ts +28 -0
- package/router/router-response-controller.js +98 -0
- package/router/routes-resolver.d.ts +27 -0
- package/router/routes-resolver.js +129 -0
- package/router/sse-stream.d.ts +43 -0
- package/router/sse-stream.js +83 -0
- package/router/utils/exclude-route.util.d.ts +4 -0
- package/router/utils/exclude-route.util.js +19 -0
- package/router/utils/flatten-route-paths.util.d.ts +6 -0
- package/router/utils/flatten-route-paths.util.js +25 -0
- package/router/utils/index.d.ts +2 -0
- package/router/utils/index.js +5 -0
- package/scanner.d.ts +89 -0
- package/scanner.js +416 -0
- package/services/index.d.ts +1 -0
- package/services/index.js +4 -0
- package/services/reflector.service.d.ts +111 -0
- package/services/reflector.service.js +100 -0
- package/tsconfig.build.json +21 -0
package/scanner.js
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependenciesScanner = void 0;
|
|
4
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
+
const interfaces_1 = require("@nestjs/common/interfaces");
|
|
6
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
|
+
const iterare_1 = require("iterare");
|
|
8
|
+
const application_config_1 = require("./application-config");
|
|
9
|
+
const constants_2 = require("./constants");
|
|
10
|
+
const circular_dependency_exception_1 = require("./errors/exceptions/circular-dependency.exception");
|
|
11
|
+
const invalid_class_module_exception_1 = require("./errors/exceptions/invalid-class-module.exception");
|
|
12
|
+
const invalid_module_exception_1 = require("./errors/exceptions/invalid-module.exception");
|
|
13
|
+
const undefined_module_exception_1 = require("./errors/exceptions/undefined-module.exception");
|
|
14
|
+
const get_class_scope_1 = require("./helpers/get-class-scope");
|
|
15
|
+
const internal_core_module_factory_1 = require("./injector/internal-core-module/internal-core-module-factory");
|
|
16
|
+
const topology_tree_1 = require("./injector/topology-tree/topology-tree");
|
|
17
|
+
const uuid_factory_1 = require("./inspector/uuid-factory");
|
|
18
|
+
class DependenciesScanner {
|
|
19
|
+
constructor(container, metadataScanner, graphInspector, applicationConfig = new application_config_1.ApplicationConfig()) {
|
|
20
|
+
this.container = container;
|
|
21
|
+
this.metadataScanner = metadataScanner;
|
|
22
|
+
this.graphInspector = graphInspector;
|
|
23
|
+
this.applicationConfig = applicationConfig;
|
|
24
|
+
this.applicationProvidersApplyMap = [];
|
|
25
|
+
}
|
|
26
|
+
async scan(module, options) {
|
|
27
|
+
await this.registerCoreModule(options?.overrides);
|
|
28
|
+
await this.scanForModules({
|
|
29
|
+
moduleDefinition: module,
|
|
30
|
+
overrides: options?.overrides,
|
|
31
|
+
});
|
|
32
|
+
await this.scanModulesForDependencies();
|
|
33
|
+
this.addScopedEnhancersMetadata();
|
|
34
|
+
// Modules distance calculation should be done after all modules are scanned
|
|
35
|
+
// but before global modules are registered (linked to all modules).
|
|
36
|
+
// Global modules have their distance set to MAX anyway.
|
|
37
|
+
this.calculateModulesDistance();
|
|
38
|
+
this.container.bindGlobalScope();
|
|
39
|
+
}
|
|
40
|
+
async scanForModules({ moduleDefinition, lazy, scope = [], ctxRegistry = [], overrides = [], }) {
|
|
41
|
+
const { moduleRef: moduleInstance, inserted: moduleInserted } = (await this.insertOrOverrideModule(moduleDefinition, overrides, scope)) ??
|
|
42
|
+
{};
|
|
43
|
+
moduleDefinition =
|
|
44
|
+
this.getOverrideModuleByModule(moduleDefinition, overrides)?.newModule ??
|
|
45
|
+
moduleDefinition;
|
|
46
|
+
moduleDefinition =
|
|
47
|
+
moduleDefinition instanceof Promise
|
|
48
|
+
? await moduleDefinition
|
|
49
|
+
: moduleDefinition;
|
|
50
|
+
ctxRegistry.push(moduleDefinition);
|
|
51
|
+
if (this.isForwardReference(moduleDefinition)) {
|
|
52
|
+
moduleDefinition = moduleDefinition.forwardRef();
|
|
53
|
+
}
|
|
54
|
+
const modules = !this.isDynamicModule(moduleDefinition)
|
|
55
|
+
? this.reflectMetadata(constants_1.MODULE_METADATA.IMPORTS, moduleDefinition)
|
|
56
|
+
: [
|
|
57
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.IMPORTS, moduleDefinition.module),
|
|
58
|
+
...(moduleDefinition.imports || []),
|
|
59
|
+
];
|
|
60
|
+
let registeredModuleRefs = [];
|
|
61
|
+
for (const [index, innerModule] of modules.entries()) {
|
|
62
|
+
// In case of a circular dependency (ES module system), JavaScript will resolve the type to `undefined`.
|
|
63
|
+
if (innerModule === undefined) {
|
|
64
|
+
throw new undefined_module_exception_1.UndefinedModuleException(moduleDefinition, index, scope);
|
|
65
|
+
}
|
|
66
|
+
if (!innerModule) {
|
|
67
|
+
throw new invalid_module_exception_1.InvalidModuleException(moduleDefinition, index, scope);
|
|
68
|
+
}
|
|
69
|
+
if (ctxRegistry.includes(innerModule)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const moduleRefs = await this.scanForModules({
|
|
73
|
+
moduleDefinition: innerModule,
|
|
74
|
+
scope: [].concat(scope, moduleDefinition),
|
|
75
|
+
ctxRegistry,
|
|
76
|
+
overrides,
|
|
77
|
+
lazy,
|
|
78
|
+
});
|
|
79
|
+
registeredModuleRefs = registeredModuleRefs.concat(moduleRefs);
|
|
80
|
+
}
|
|
81
|
+
if (!moduleInstance) {
|
|
82
|
+
return registeredModuleRefs;
|
|
83
|
+
}
|
|
84
|
+
if (lazy && moduleInserted) {
|
|
85
|
+
this.container.bindGlobalsToImports(moduleInstance);
|
|
86
|
+
}
|
|
87
|
+
return [moduleInstance].concat(registeredModuleRefs);
|
|
88
|
+
}
|
|
89
|
+
async insertModule(moduleDefinition, scope) {
|
|
90
|
+
const moduleToAdd = this.isForwardReference(moduleDefinition)
|
|
91
|
+
? moduleDefinition.forwardRef()
|
|
92
|
+
: moduleDefinition;
|
|
93
|
+
if (this.isInjectable(moduleToAdd) ||
|
|
94
|
+
this.isController(moduleToAdd) ||
|
|
95
|
+
this.isExceptionFilter(moduleToAdd)) {
|
|
96
|
+
throw new invalid_class_module_exception_1.InvalidClassModuleException(moduleDefinition, scope);
|
|
97
|
+
}
|
|
98
|
+
return this.container.addModule(moduleToAdd, scope);
|
|
99
|
+
}
|
|
100
|
+
async scanModulesForDependencies(modules = this.container.getModules()) {
|
|
101
|
+
for (const [token, { metatype }] of modules) {
|
|
102
|
+
await this.reflectImports(metatype, token, metatype.name);
|
|
103
|
+
this.reflectProviders(metatype, token);
|
|
104
|
+
this.reflectControllers(metatype, token);
|
|
105
|
+
this.reflectExports(metatype, token);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async reflectImports(module, token, context) {
|
|
109
|
+
const modules = [
|
|
110
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.IMPORTS, module),
|
|
111
|
+
...this.container.getDynamicMetadataByToken(token, constants_1.MODULE_METADATA.IMPORTS),
|
|
112
|
+
];
|
|
113
|
+
for (const related of modules) {
|
|
114
|
+
await this.insertImport(related, token, context);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
reflectProviders(module, token) {
|
|
118
|
+
const providers = [
|
|
119
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.PROVIDERS, module),
|
|
120
|
+
...this.container.getDynamicMetadataByToken(token, constants_1.MODULE_METADATA.PROVIDERS),
|
|
121
|
+
];
|
|
122
|
+
providers.forEach(provider => {
|
|
123
|
+
this.insertProvider(provider, token);
|
|
124
|
+
this.reflectDynamicMetadata(provider, token);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
reflectControllers(module, token) {
|
|
128
|
+
const controllers = [
|
|
129
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.CONTROLLERS, module),
|
|
130
|
+
...this.container.getDynamicMetadataByToken(token, constants_1.MODULE_METADATA.CONTROLLERS),
|
|
131
|
+
];
|
|
132
|
+
controllers.forEach(item => {
|
|
133
|
+
this.insertController(item, token);
|
|
134
|
+
this.reflectDynamicMetadata(item, token);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
reflectDynamicMetadata(cls, token) {
|
|
138
|
+
if (!cls || !cls.prototype) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.reflectInjectables(cls, token, constants_1.GUARDS_METADATA);
|
|
142
|
+
this.reflectInjectables(cls, token, constants_1.INTERCEPTORS_METADATA);
|
|
143
|
+
this.reflectInjectables(cls, token, constants_1.EXCEPTION_FILTERS_METADATA);
|
|
144
|
+
this.reflectInjectables(cls, token, constants_1.PIPES_METADATA);
|
|
145
|
+
this.reflectParamInjectables(cls, token, constants_1.ROUTE_ARGS_METADATA);
|
|
146
|
+
}
|
|
147
|
+
reflectExports(module, token) {
|
|
148
|
+
const exports = [
|
|
149
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.EXPORTS, module),
|
|
150
|
+
...this.container.getDynamicMetadataByToken(token, constants_1.MODULE_METADATA.EXPORTS),
|
|
151
|
+
];
|
|
152
|
+
exports.forEach(exportedProvider => this.insertExportedProviderOrModule(exportedProvider, token));
|
|
153
|
+
}
|
|
154
|
+
reflectInjectables(component, token, metadataKey) {
|
|
155
|
+
const controllerInjectables = this.reflectMetadata(metadataKey, component);
|
|
156
|
+
const methodInjectables = this.metadataScanner
|
|
157
|
+
.getAllMethodNames(component.prototype)
|
|
158
|
+
.reduce((acc, method) => {
|
|
159
|
+
const methodInjectable = this.reflectKeyMetadata(component, metadataKey, method);
|
|
160
|
+
if (methodInjectable) {
|
|
161
|
+
acc.push(methodInjectable);
|
|
162
|
+
}
|
|
163
|
+
return acc;
|
|
164
|
+
}, []);
|
|
165
|
+
controllerInjectables.forEach(injectable => this.insertInjectable(injectable, token, component, constants_1.ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey]));
|
|
166
|
+
methodInjectables.forEach(methodInjectable => {
|
|
167
|
+
methodInjectable.metadata.forEach(injectable => this.insertInjectable(injectable, token, component, constants_1.ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey], methodInjectable.methodKey));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
reflectParamInjectables(component, token, metadataKey) {
|
|
171
|
+
const paramsMethods = this.metadataScanner.getAllMethodNames(component.prototype);
|
|
172
|
+
paramsMethods.forEach(methodKey => {
|
|
173
|
+
const metadata = Reflect.getMetadata(metadataKey, component, methodKey);
|
|
174
|
+
if (!metadata) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const params = Object.values(metadata);
|
|
178
|
+
params
|
|
179
|
+
.map(item => item.pipes)
|
|
180
|
+
.flat(1)
|
|
181
|
+
.forEach(injectable => this.insertInjectable(injectable, token, component, 'pipe', methodKey));
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
reflectKeyMetadata(component, key, methodKey) {
|
|
185
|
+
let prototype = component.prototype;
|
|
186
|
+
do {
|
|
187
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(prototype, methodKey);
|
|
188
|
+
if (!descriptor) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const metadata = Reflect.getMetadata(key, descriptor.value);
|
|
192
|
+
if (!metadata) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
return { methodKey, metadata };
|
|
196
|
+
} while ((prototype = Reflect.getPrototypeOf(prototype)) &&
|
|
197
|
+
prototype !== Object.prototype &&
|
|
198
|
+
prototype);
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
calculateModulesDistance() {
|
|
202
|
+
const modulesGenerator = this.container.getModules().values();
|
|
203
|
+
// Skip "InternalCoreModule"
|
|
204
|
+
// The second element is the actual root module
|
|
205
|
+
modulesGenerator.next();
|
|
206
|
+
const rootModule = modulesGenerator.next().value;
|
|
207
|
+
if (!rootModule) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// Convert modules to an acyclic connected graph
|
|
211
|
+
const tree = new topology_tree_1.TopologyTree(rootModule);
|
|
212
|
+
tree.walk((moduleRef, depth) => {
|
|
213
|
+
if (moduleRef.isGlobal) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
moduleRef.distance = depth;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async insertImport(related, token, context) {
|
|
220
|
+
if ((0, shared_utils_1.isUndefined)(related)) {
|
|
221
|
+
throw new circular_dependency_exception_1.CircularDependencyException(context);
|
|
222
|
+
}
|
|
223
|
+
if (this.isForwardReference(related)) {
|
|
224
|
+
return this.container.addImport(related.forwardRef(), token);
|
|
225
|
+
}
|
|
226
|
+
await this.container.addImport(related, token);
|
|
227
|
+
}
|
|
228
|
+
isCustomProvider(provider) {
|
|
229
|
+
return provider && !(0, shared_utils_1.isNil)(provider.provide);
|
|
230
|
+
}
|
|
231
|
+
insertProvider(provider, token) {
|
|
232
|
+
const isCustomProvider = this.isCustomProvider(provider);
|
|
233
|
+
if (!isCustomProvider) {
|
|
234
|
+
return this.container.addProvider(provider, token);
|
|
235
|
+
}
|
|
236
|
+
const applyProvidersMap = this.getApplyProvidersMap();
|
|
237
|
+
const providersKeys = Object.keys(applyProvidersMap);
|
|
238
|
+
const type = provider.provide;
|
|
239
|
+
if (!providersKeys.includes(type)) {
|
|
240
|
+
return this.container.addProvider(provider, token);
|
|
241
|
+
}
|
|
242
|
+
const uuid = uuid_factory_1.UuidFactory.get(type.toString());
|
|
243
|
+
const providerToken = `${type} (UUID: ${uuid})`;
|
|
244
|
+
let scope = provider.scope;
|
|
245
|
+
if ((0, shared_utils_1.isNil)(scope) && provider.useClass) {
|
|
246
|
+
scope = (0, get_class_scope_1.getClassScope)(provider.useClass);
|
|
247
|
+
}
|
|
248
|
+
this.applicationProvidersApplyMap.push({
|
|
249
|
+
type,
|
|
250
|
+
moduleKey: token,
|
|
251
|
+
providerKey: providerToken,
|
|
252
|
+
scope,
|
|
253
|
+
});
|
|
254
|
+
const newProvider = {
|
|
255
|
+
...provider,
|
|
256
|
+
provide: providerToken,
|
|
257
|
+
scope,
|
|
258
|
+
};
|
|
259
|
+
const enhancerSubtype = constants_2.ENHANCER_TOKEN_TO_SUBTYPE_MAP[type];
|
|
260
|
+
const factoryOrClassProvider = newProvider;
|
|
261
|
+
if (this.isRequestOrTransient(factoryOrClassProvider.scope)) {
|
|
262
|
+
return this.container.addInjectable(newProvider, token, enhancerSubtype);
|
|
263
|
+
}
|
|
264
|
+
this.container.addProvider(newProvider, token, enhancerSubtype);
|
|
265
|
+
}
|
|
266
|
+
insertInjectable(injectable, token, host, subtype, methodKey) {
|
|
267
|
+
if ((0, shared_utils_1.isFunction)(injectable)) {
|
|
268
|
+
const instanceWrapper = this.container.addInjectable(injectable, token, subtype, host);
|
|
269
|
+
this.graphInspector.insertEnhancerMetadataCache({
|
|
270
|
+
moduleToken: token,
|
|
271
|
+
classRef: host,
|
|
272
|
+
enhancerInstanceWrapper: instanceWrapper,
|
|
273
|
+
targetNodeId: instanceWrapper.id,
|
|
274
|
+
subtype,
|
|
275
|
+
methodKey,
|
|
276
|
+
});
|
|
277
|
+
return instanceWrapper;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
this.graphInspector.insertEnhancerMetadataCache({
|
|
281
|
+
moduleToken: token,
|
|
282
|
+
classRef: host,
|
|
283
|
+
enhancerRef: injectable,
|
|
284
|
+
methodKey,
|
|
285
|
+
subtype,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
insertExportedProviderOrModule(toExport, token) {
|
|
290
|
+
const fulfilledProvider = this.isForwardReference(toExport)
|
|
291
|
+
? toExport.forwardRef()
|
|
292
|
+
: toExport;
|
|
293
|
+
this.container.addExportedProviderOrModule(fulfilledProvider, token);
|
|
294
|
+
}
|
|
295
|
+
insertController(controller, token) {
|
|
296
|
+
this.container.addController(controller, token);
|
|
297
|
+
}
|
|
298
|
+
insertOrOverrideModule(moduleDefinition, overrides, scope) {
|
|
299
|
+
const overrideModule = this.getOverrideModuleByModule(moduleDefinition, overrides);
|
|
300
|
+
if (overrideModule !== undefined) {
|
|
301
|
+
return this.overrideModule(moduleDefinition, overrideModule.newModule, scope);
|
|
302
|
+
}
|
|
303
|
+
return this.insertModule(moduleDefinition, scope);
|
|
304
|
+
}
|
|
305
|
+
getOverrideModuleByModule(module, overrides) {
|
|
306
|
+
if (this.isForwardReference(module)) {
|
|
307
|
+
return overrides.find(moduleToOverride => {
|
|
308
|
+
return (moduleToOverride.moduleToReplace === module.forwardRef() ||
|
|
309
|
+
moduleToOverride.moduleToReplace.forwardRef?.() === module.forwardRef());
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return overrides.find(moduleToOverride => moduleToOverride.moduleToReplace === module);
|
|
313
|
+
}
|
|
314
|
+
async overrideModule(moduleToOverride, newModule, scope) {
|
|
315
|
+
return this.container.replaceModule(this.isForwardReference(moduleToOverride)
|
|
316
|
+
? moduleToOverride.forwardRef()
|
|
317
|
+
: moduleToOverride, this.isForwardReference(newModule) ? newModule.forwardRef() : newModule, scope);
|
|
318
|
+
}
|
|
319
|
+
reflectMetadata(metadataKey, metatype) {
|
|
320
|
+
return Reflect.getMetadata(metadataKey, metatype) || [];
|
|
321
|
+
}
|
|
322
|
+
async registerCoreModule(overrides) {
|
|
323
|
+
const moduleDefinition = internal_core_module_factory_1.InternalCoreModuleFactory.create(this.container, this, this.container.getModuleCompiler(), this.container.getHttpAdapterHostRef(), this.graphInspector, overrides);
|
|
324
|
+
const [instance] = await this.scanForModules({
|
|
325
|
+
moduleDefinition,
|
|
326
|
+
overrides,
|
|
327
|
+
});
|
|
328
|
+
this.container.registerCoreModuleRef(instance);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Add either request or transient globally scoped enhancers
|
|
332
|
+
* to all controllers metadata storage
|
|
333
|
+
*/
|
|
334
|
+
addScopedEnhancersMetadata() {
|
|
335
|
+
(0, iterare_1.iterate)(this.applicationProvidersApplyMap)
|
|
336
|
+
.filter(wrapper => this.isRequestOrTransient(wrapper.scope))
|
|
337
|
+
.forEach(({ moduleKey, providerKey }) => {
|
|
338
|
+
const modulesContainer = this.container.getModules();
|
|
339
|
+
const { injectables } = modulesContainer.get(moduleKey);
|
|
340
|
+
const instanceWrapper = injectables.get(providerKey);
|
|
341
|
+
const iterableIterator = modulesContainer.values();
|
|
342
|
+
(0, iterare_1.iterate)(iterableIterator)
|
|
343
|
+
.map(moduleRef => Array.from(moduleRef.controllers.values()).concat(moduleRef.entryProviders))
|
|
344
|
+
.flatten()
|
|
345
|
+
.forEach(controllerOrEntryProvider => controllerOrEntryProvider.addEnhancerMetadata(instanceWrapper));
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
applyApplicationProviders() {
|
|
349
|
+
const applyProvidersMap = this.getApplyProvidersMap();
|
|
350
|
+
const applyRequestProvidersMap = this.getApplyRequestProvidersMap();
|
|
351
|
+
const getInstanceWrapper = (moduleKey, providerKey, collectionKey) => {
|
|
352
|
+
const modules = this.container.getModules();
|
|
353
|
+
const collection = modules.get(moduleKey)[collectionKey];
|
|
354
|
+
return collection.get(providerKey);
|
|
355
|
+
};
|
|
356
|
+
// Add global enhancers to the application config
|
|
357
|
+
this.applicationProvidersApplyMap.forEach(({ moduleKey, providerKey, type, scope }) => {
|
|
358
|
+
let instanceWrapper;
|
|
359
|
+
if (this.isRequestOrTransient(scope)) {
|
|
360
|
+
instanceWrapper = getInstanceWrapper(moduleKey, providerKey, 'injectables');
|
|
361
|
+
this.graphInspector.insertAttachedEnhancer(instanceWrapper);
|
|
362
|
+
return applyRequestProvidersMap[type](instanceWrapper);
|
|
363
|
+
}
|
|
364
|
+
instanceWrapper = getInstanceWrapper(moduleKey, providerKey, 'providers');
|
|
365
|
+
this.graphInspector.insertAttachedEnhancer(instanceWrapper);
|
|
366
|
+
applyProvidersMap[type](instanceWrapper.instance);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
getApplyProvidersMap() {
|
|
370
|
+
return {
|
|
371
|
+
[constants_2.APP_INTERCEPTOR]: (interceptor) => this.applicationConfig.addGlobalInterceptor(interceptor),
|
|
372
|
+
[constants_2.APP_PIPE]: (pipe) => this.applicationConfig.addGlobalPipe(pipe),
|
|
373
|
+
[constants_2.APP_GUARD]: (guard) => this.applicationConfig.addGlobalGuard(guard),
|
|
374
|
+
[constants_2.APP_FILTER]: (filter) => this.applicationConfig.addGlobalFilter(filter),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
getApplyRequestProvidersMap() {
|
|
378
|
+
return {
|
|
379
|
+
[constants_2.APP_INTERCEPTOR]: (interceptor) => this.applicationConfig.addGlobalRequestInterceptor(interceptor),
|
|
380
|
+
[constants_2.APP_PIPE]: (pipe) => this.applicationConfig.addGlobalRequestPipe(pipe),
|
|
381
|
+
[constants_2.APP_GUARD]: (guard) => this.applicationConfig.addGlobalRequestGuard(guard),
|
|
382
|
+
[constants_2.APP_FILTER]: (filter) => this.applicationConfig.addGlobalRequestFilter(filter),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
isDynamicModule(module) {
|
|
386
|
+
return module && !!module.module;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @param metatype
|
|
390
|
+
* @returns `true` if `metatype` is annotated with the `@Injectable()` decorator.
|
|
391
|
+
*/
|
|
392
|
+
isInjectable(metatype) {
|
|
393
|
+
return !!Reflect.getMetadata(constants_1.INJECTABLE_WATERMARK, metatype);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @param metatype
|
|
397
|
+
* @returns `true` if `metatype` is annotated with the `@Controller()` decorator.
|
|
398
|
+
*/
|
|
399
|
+
isController(metatype) {
|
|
400
|
+
return !!Reflect.getMetadata(constants_1.CONTROLLER_WATERMARK, metatype);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* @param metatype
|
|
404
|
+
* @returns `true` if `metatype` is annotated with the `@Catch()` decorator.
|
|
405
|
+
*/
|
|
406
|
+
isExceptionFilter(metatype) {
|
|
407
|
+
return !!Reflect.getMetadata(constants_1.CATCH_WATERMARK, metatype);
|
|
408
|
+
}
|
|
409
|
+
isForwardReference(module) {
|
|
410
|
+
return module && !!module.forwardRef;
|
|
411
|
+
}
|
|
412
|
+
isRequestOrTransient(scope) {
|
|
413
|
+
return scope === interfaces_1.Scope.REQUEST || scope === interfaces_1.Scope.TRANSIENT;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.DependenciesScanner = DependenciesScanner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './reflector.service';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { CustomDecorator, Type } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* @publicApi
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateDecoratorOptions<TParam = any, TTransformed = TParam> {
|
|
6
|
+
/**
|
|
7
|
+
* The key for the metadata.
|
|
8
|
+
* @default uid(21)
|
|
9
|
+
*/
|
|
10
|
+
key?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The transform function to apply to the metadata value.
|
|
13
|
+
* @default value => value
|
|
14
|
+
*/
|
|
15
|
+
transform?: (value: TParam) => TTransformed;
|
|
16
|
+
}
|
|
17
|
+
type CreateDecoratorWithTransformOptions<TParam, TTransformed = TParam> = CreateDecoratorOptions<TParam, TTransformed> & Required<Pick<CreateDecoratorOptions<TParam, TTransformed>, 'transform'>>;
|
|
18
|
+
/**
|
|
19
|
+
* @publicApi
|
|
20
|
+
*/
|
|
21
|
+
export type ReflectableDecorator<TParam, TTransformed = TParam> = ((opts?: TParam) => CustomDecorator) & {
|
|
22
|
+
KEY: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Helper class providing Nest reflection capabilities.
|
|
26
|
+
*
|
|
27
|
+
* @see [Reflection](https://docs.nestjs.com/guards#putting-it-all-together)
|
|
28
|
+
*
|
|
29
|
+
* @publicApi
|
|
30
|
+
*/
|
|
31
|
+
export declare class Reflector {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a decorator that can be used to decorate classes and methods with metadata.
|
|
34
|
+
* Can be used as a strongly-typed alternative to `@SetMetadata`.
|
|
35
|
+
* @param options Decorator options.
|
|
36
|
+
* @returns A decorator function.
|
|
37
|
+
*/
|
|
38
|
+
static createDecorator<TParam>(options?: CreateDecoratorOptions<TParam>): ReflectableDecorator<TParam>;
|
|
39
|
+
static createDecorator<TParam, TTransformed>(options: CreateDecoratorWithTransformOptions<TParam, TTransformed>): ReflectableDecorator<TParam, TTransformed>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve metadata for a reflectable decorator for a specified target.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* `const roles = this.reflector.get(Roles, context.getHandler());`
|
|
45
|
+
*
|
|
46
|
+
* @param decorator reflectable decorator created through `Reflector.createDecorator`
|
|
47
|
+
* @param target context (decorated object) to retrieve metadata from
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
get<T extends ReflectableDecorator<any>>(decorator: T, target: Type<any> | Function): T extends ReflectableDecorator<any, infer R> ? R : unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve metadata for a specified key for a specified target.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* `const roles = this.reflector.get<string[]>('roles', context.getHandler());`
|
|
56
|
+
*
|
|
57
|
+
* @param metadataKey lookup key for metadata to retrieve
|
|
58
|
+
* @param target context (decorated object) to retrieve metadata from
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
get<TResult = any, TKey = any>(metadataKey: TKey, target: Type<any> | Function): TResult;
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve metadata for a specified decorator for a specified set of targets.
|
|
64
|
+
*
|
|
65
|
+
* @param decorator lookup decorator for metadata to retrieve
|
|
66
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
getAll<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed extends Array<any> ? TTransformed : TTransformed[];
|
|
70
|
+
/**
|
|
71
|
+
* Retrieve metadata for a specified key for a specified set of targets.
|
|
72
|
+
*
|
|
73
|
+
* @param metadataKey lookup key for metadata to retrieve
|
|
74
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
getAll<TResult extends any[] = any[], TKey = any>(metadataKey: TKey, targets: (Type<any> | Function)[]): TResult;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieve metadata for a specified decorator for a specified set of targets and merge results.
|
|
80
|
+
*
|
|
81
|
+
* @param decorator lookup decorator for metadata to retrieve
|
|
82
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
getAllAndMerge<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed extends Array<any> ? TTransformed : TTransformed extends object ? TTransformed : TTransformed[];
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve metadata for a specified key for a specified set of targets and merge results.
|
|
88
|
+
*
|
|
89
|
+
* @param metadataKey lookup key for metadata to retrieve
|
|
90
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
getAllAndMerge<TResult extends any[] | object = any[], TKey = any>(metadataKey: TKey, targets: (Type<any> | Function)[]): TResult;
|
|
94
|
+
/**
|
|
95
|
+
* Retrieve metadata for a specified decorator for a specified set of targets and return a first not undefined value.
|
|
96
|
+
*
|
|
97
|
+
* @param decorator lookup decorator for metadata to retrieve
|
|
98
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
99
|
+
*
|
|
100
|
+
*/
|
|
101
|
+
getAllAndOverride<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieve metadata for a specified key for a specified set of targets and return a first not undefined value.
|
|
104
|
+
*
|
|
105
|
+
* @param metadataKey lookup key for metadata to retrieve
|
|
106
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
getAllAndOverride<TResult = any, TKey = any>(metadataKey: TKey, targets: (Type<any> | Function)[]): TResult;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reflector = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
+
const uid_1 = require("uid");
|
|
7
|
+
/**
|
|
8
|
+
* Helper class providing Nest reflection capabilities.
|
|
9
|
+
*
|
|
10
|
+
* @see [Reflection](https://docs.nestjs.com/guards#putting-it-all-together)
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
class Reflector {
|
|
15
|
+
static createDecorator(options = {}) {
|
|
16
|
+
const metadataKey = options.key ?? (0, uid_1.uid)(21);
|
|
17
|
+
const decoratorFn = (metadataValue) => (target, key, descriptor) => {
|
|
18
|
+
const value = options.transform
|
|
19
|
+
? options.transform(metadataValue)
|
|
20
|
+
: metadataValue;
|
|
21
|
+
(0, common_1.SetMetadata)(metadataKey, value ?? {})(target, key, descriptor);
|
|
22
|
+
};
|
|
23
|
+
decoratorFn.KEY = metadataKey;
|
|
24
|
+
return decoratorFn;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve metadata for a specified key or decorator for a specified target.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* `const roles = this.reflector.get<string[]>('roles', context.getHandler());`
|
|
31
|
+
*
|
|
32
|
+
* @param metadataKey lookup key or decorator for metadata to retrieve
|
|
33
|
+
* @param target context (decorated object) to retrieve metadata from
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
get(metadataKeyOrDecorator, target) {
|
|
37
|
+
const metadataKey = metadataKeyOrDecorator.KEY ??
|
|
38
|
+
metadataKeyOrDecorator;
|
|
39
|
+
return Reflect.getMetadata(metadataKey, target);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve metadata for a specified key or decorator for a specified set of targets.
|
|
43
|
+
*
|
|
44
|
+
* @param metadataKeyOrDecorator lookup key or decorator for metadata to retrieve
|
|
45
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
getAll(metadataKeyOrDecorator, targets) {
|
|
49
|
+
return (targets || []).map(target => this.get(metadataKeyOrDecorator, target));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve metadata for a specified key or decorator for a specified set of targets and merge results.
|
|
53
|
+
*
|
|
54
|
+
* @param metadataKeyOrDecorator lookup key for metadata to retrieve
|
|
55
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
getAllAndMerge(metadataKeyOrDecorator, targets) {
|
|
59
|
+
const metadataCollection = this.getAll(metadataKeyOrDecorator, targets).filter(item => item !== undefined);
|
|
60
|
+
if ((0, shared_utils_1.isEmpty)(metadataCollection)) {
|
|
61
|
+
return metadataCollection;
|
|
62
|
+
}
|
|
63
|
+
if (metadataCollection.length === 1) {
|
|
64
|
+
const value = metadataCollection[0];
|
|
65
|
+
if ((0, shared_utils_1.isObject)(value)) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
return metadataCollection;
|
|
69
|
+
}
|
|
70
|
+
return metadataCollection.reduce((a, b) => {
|
|
71
|
+
if (Array.isArray(a)) {
|
|
72
|
+
return a.concat(b);
|
|
73
|
+
}
|
|
74
|
+
if ((0, shared_utils_1.isObject)(a) && (0, shared_utils_1.isObject)(b)) {
|
|
75
|
+
return {
|
|
76
|
+
...a,
|
|
77
|
+
...b,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return [a, b];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Retrieve metadata for a specified key or decorator for a specified set of targets and return a first not undefined value.
|
|
85
|
+
*
|
|
86
|
+
* @param metadataKeyOrDecorator lookup key or metadata for metadata to retrieve
|
|
87
|
+
* @param targets context (decorated objects) to retrieve metadata from
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
getAllAndOverride(metadataKeyOrDecorator, targets) {
|
|
91
|
+
for (const target of targets) {
|
|
92
|
+
const result = this.get(metadataKeyOrDecorator, target);
|
|
93
|
+
if (result !== undefined) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.Reflector = Reflector;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.build.json",
|
|
3
|
+
"compilerOptions": {
|
|
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
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"],
|
|
16
|
+
"references": [
|
|
17
|
+
{
|
|
18
|
+
"path": "../common/tsconfig.build.json"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|