@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
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Injector = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
6
|
+
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
|
7
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
|
+
const iterare_1 = require("iterare");
|
|
9
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
10
|
+
const exceptions_1 = require("../errors/exceptions");
|
|
11
|
+
const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
|
|
12
|
+
const undefined_dependency_exception_1 = require("../errors/exceptions/undefined-dependency.exception");
|
|
13
|
+
const unknown_dependencies_exception_1 = require("../errors/exceptions/unknown-dependencies.exception");
|
|
14
|
+
const barrier_1 = require("../helpers/barrier");
|
|
15
|
+
const constants_2 = require("./constants");
|
|
16
|
+
const inquirer_1 = require("./inquirer");
|
|
17
|
+
const instance_wrapper_1 = require("./instance-wrapper");
|
|
18
|
+
const settlement_signal_1 = require("./settlement-signal");
|
|
19
|
+
class Injector {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.logger = new common_1.Logger('InjectorLogger');
|
|
23
|
+
this.instanceDecorator = (target) => target;
|
|
24
|
+
if (options?.instanceDecorator) {
|
|
25
|
+
this.instanceDecorator = options.instanceDecorator;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
loadPrototype({ token }, collection, contextId = constants_2.STATIC_CONTEXT) {
|
|
29
|
+
if (!collection) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const target = collection.get(token);
|
|
33
|
+
const instance = target.createPrototype(contextId);
|
|
34
|
+
if (instance) {
|
|
35
|
+
const wrapper = new instance_wrapper_1.InstanceWrapper({
|
|
36
|
+
...target,
|
|
37
|
+
instance,
|
|
38
|
+
});
|
|
39
|
+
collection.set(token, wrapper);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async loadInstance(wrapper, collection, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
43
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
44
|
+
const instanceHost = wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId);
|
|
45
|
+
if (instanceHost.isPending) {
|
|
46
|
+
const settlementSignal = wrapper.settlementSignal;
|
|
47
|
+
if (inquirer && settlementSignal?.isCycle(inquirer.id)) {
|
|
48
|
+
throw new exceptions_1.CircularDependencyException(`"${wrapper.name}"`);
|
|
49
|
+
}
|
|
50
|
+
return instanceHost.donePromise.then((err) => {
|
|
51
|
+
if (err) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const settlementSignal = this.applySettlementSignal(instanceHost, wrapper);
|
|
57
|
+
const token = wrapper.token || wrapper.name;
|
|
58
|
+
const { inject } = wrapper;
|
|
59
|
+
const targetWrapper = collection.get(token);
|
|
60
|
+
if ((0, shared_utils_1.isUndefined)(targetWrapper)) {
|
|
61
|
+
throw new runtime_exception_1.RuntimeException();
|
|
62
|
+
}
|
|
63
|
+
if (instanceHost.isResolved) {
|
|
64
|
+
return settlementSignal.complete();
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const t0 = this.getNowTimestamp();
|
|
68
|
+
const callback = async (instances) => {
|
|
69
|
+
const properties = await this.resolveProperties(wrapper, moduleRef, inject, contextId, wrapper, inquirer);
|
|
70
|
+
const instance = await this.instantiateClass(instances, wrapper, targetWrapper, contextId, inquirer);
|
|
71
|
+
this.applyProperties(instance, properties);
|
|
72
|
+
wrapper.initTime = this.getNowTimestamp() - t0;
|
|
73
|
+
settlementSignal.complete();
|
|
74
|
+
};
|
|
75
|
+
await this.resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId, wrapper, inquirer);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
wrapper.removeInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId);
|
|
79
|
+
settlementSignal.error(err);
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async loadMiddleware(wrapper, collection, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
84
|
+
const { metatype, token } = wrapper;
|
|
85
|
+
const targetWrapper = collection.get(token);
|
|
86
|
+
if (!(0, shared_utils_1.isUndefined)(targetWrapper.instance)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
targetWrapper.instance = Object.create(metatype.prototype);
|
|
90
|
+
await this.loadInstance(wrapper, collection, moduleRef, contextId, inquirer || wrapper);
|
|
91
|
+
}
|
|
92
|
+
async loadController(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT) {
|
|
93
|
+
const controllers = moduleRef.controllers;
|
|
94
|
+
await this.loadInstance(wrapper, controllers, moduleRef, contextId, wrapper);
|
|
95
|
+
await this.loadEnhancersPerContext(wrapper, contextId, wrapper);
|
|
96
|
+
}
|
|
97
|
+
async loadInjectable(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
98
|
+
const injectables = moduleRef.injectables;
|
|
99
|
+
await this.loadInstance(wrapper, injectables, moduleRef, contextId, inquirer);
|
|
100
|
+
}
|
|
101
|
+
async loadProvider(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
102
|
+
const providers = moduleRef.providers;
|
|
103
|
+
await this.loadInstance(wrapper, providers, moduleRef, contextId, inquirer);
|
|
104
|
+
await this.loadEnhancersPerContext(wrapper, contextId, wrapper);
|
|
105
|
+
}
|
|
106
|
+
applySettlementSignal(instancePerContext, host) {
|
|
107
|
+
const settlementSignal = new settlement_signal_1.SettlementSignal();
|
|
108
|
+
instancePerContext.donePromise = settlementSignal.asPromise();
|
|
109
|
+
instancePerContext.isPending = true;
|
|
110
|
+
host.settlementSignal = settlementSignal;
|
|
111
|
+
return settlementSignal;
|
|
112
|
+
}
|
|
113
|
+
async resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
|
|
114
|
+
const metadata = wrapper.getCtorMetadata();
|
|
115
|
+
if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
|
|
116
|
+
const deps = await this.loadCtorMetadata(metadata, contextId, inquirer, parentInquirer);
|
|
117
|
+
return callback(deps);
|
|
118
|
+
}
|
|
119
|
+
const isFactoryProvider = !(0, shared_utils_1.isNil)(inject);
|
|
120
|
+
const [dependencies, optionalDependenciesIds] = isFactoryProvider
|
|
121
|
+
? this.getFactoryProviderDependencies(wrapper)
|
|
122
|
+
: this.getClassDependencies(wrapper);
|
|
123
|
+
const paramBarrier = new barrier_1.Barrier(dependencies.length);
|
|
124
|
+
let isResolved = true;
|
|
125
|
+
const resolveParam = async (param, index) => {
|
|
126
|
+
try {
|
|
127
|
+
if (this.isInquirer(param, parentInquirer)) {
|
|
128
|
+
/*
|
|
129
|
+
* Signal the barrier to make sure other dependencies do not get stuck waiting forever.
|
|
130
|
+
*/
|
|
131
|
+
paramBarrier.signal();
|
|
132
|
+
return parentInquirer && parentInquirer.instance;
|
|
133
|
+
}
|
|
134
|
+
if (inquirer?.isTransient && parentInquirer) {
|
|
135
|
+
// When `inquirer` is transient too, inherit the parent inquirer
|
|
136
|
+
// This is required to ensure that transient providers are only resolved
|
|
137
|
+
// when requested
|
|
138
|
+
inquirer.attachRootInquirer(parentInquirer);
|
|
139
|
+
}
|
|
140
|
+
const paramWrapper = await this.resolveSingleParam(wrapper, param, { index, dependencies }, moduleRef, contextId, inquirer, index);
|
|
141
|
+
/*
|
|
142
|
+
* Ensure that all instance wrappers are resolved at this point before we continue.
|
|
143
|
+
* Otherwise the staticity of `wrapper`'s dependency tree may be evaluated incorrectly
|
|
144
|
+
* and result in undefined / null injection.
|
|
145
|
+
*/
|
|
146
|
+
await paramBarrier.signalAndWait();
|
|
147
|
+
const effectiveInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
|
|
148
|
+
const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectiveInquirer);
|
|
149
|
+
const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectiveInquirer));
|
|
150
|
+
if (!instanceHost.isResolved && !paramWrapperWithInstance.forwardRef) {
|
|
151
|
+
isResolved = false;
|
|
152
|
+
}
|
|
153
|
+
return instanceHost?.instance;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
/*
|
|
157
|
+
* Signal the barrier to make sure other dependencies do not get stuck waiting forever. We
|
|
158
|
+
* do not care if this occurs after `Barrier.signalAndWait()` is called in the `try` block
|
|
159
|
+
* because the barrier will always have been resolved by then.
|
|
160
|
+
*/
|
|
161
|
+
paramBarrier.signal();
|
|
162
|
+
const isOptional = optionalDependenciesIds.includes(index);
|
|
163
|
+
if (!isOptional) {
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const instances = await Promise.all(dependencies.map(resolveParam));
|
|
170
|
+
isResolved && (await callback(instances));
|
|
171
|
+
}
|
|
172
|
+
getClassDependencies(wrapper) {
|
|
173
|
+
const ctorRef = wrapper.metatype;
|
|
174
|
+
return [
|
|
175
|
+
this.reflectConstructorParams(ctorRef),
|
|
176
|
+
this.reflectOptionalParams(ctorRef),
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
getFactoryProviderDependencies(wrapper) {
|
|
180
|
+
const optionalDependenciesIds = [];
|
|
181
|
+
/**
|
|
182
|
+
* Same as the internal utility function `isOptionalFactoryDependency` from `@nestjs/common`.
|
|
183
|
+
* We are duplicating it here because that one is not supposed to be exported.
|
|
184
|
+
*/
|
|
185
|
+
function isOptionalFactoryDependency(value) {
|
|
186
|
+
return (!(0, shared_utils_1.isUndefined)(value.token) &&
|
|
187
|
+
!(0, shared_utils_1.isUndefined)(value.optional) &&
|
|
188
|
+
!value.prototype);
|
|
189
|
+
}
|
|
190
|
+
const mapFactoryProviderInjectArray = (item, index) => {
|
|
191
|
+
if (typeof item !== 'object') {
|
|
192
|
+
return item;
|
|
193
|
+
}
|
|
194
|
+
if (isOptionalFactoryDependency(item)) {
|
|
195
|
+
if (item.optional) {
|
|
196
|
+
optionalDependenciesIds.push(index);
|
|
197
|
+
}
|
|
198
|
+
return item?.token;
|
|
199
|
+
}
|
|
200
|
+
return item;
|
|
201
|
+
};
|
|
202
|
+
return [
|
|
203
|
+
wrapper.inject?.map?.(mapFactoryProviderInjectArray),
|
|
204
|
+
optionalDependenciesIds,
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
reflectConstructorParams(type) {
|
|
208
|
+
const paramtypes = [
|
|
209
|
+
...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) || []),
|
|
210
|
+
];
|
|
211
|
+
const selfParams = this.reflectSelfParams(type);
|
|
212
|
+
selfParams.forEach(({ index, param }) => (paramtypes[index] = param));
|
|
213
|
+
return paramtypes;
|
|
214
|
+
}
|
|
215
|
+
reflectOptionalParams(type) {
|
|
216
|
+
return Reflect.getMetadata(constants_1.OPTIONAL_DEPS_METADATA, type) || [];
|
|
217
|
+
}
|
|
218
|
+
reflectSelfParams(type) {
|
|
219
|
+
return Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, type) || [];
|
|
220
|
+
}
|
|
221
|
+
async resolveSingleParam(wrapper, param, dependencyContext, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
222
|
+
if ((0, shared_utils_1.isUndefined)(param)) {
|
|
223
|
+
this.logger.log('Nest encountered an undefined dependency. This may be due to a circular import or a missing dependency declaration.');
|
|
224
|
+
throw new undefined_dependency_exception_1.UndefinedDependencyException(wrapper.name, dependencyContext, moduleRef);
|
|
225
|
+
}
|
|
226
|
+
const token = this.resolveParamToken(wrapper, param);
|
|
227
|
+
return this.resolveComponentWrapper(moduleRef, token, dependencyContext, wrapper, contextId, inquirer, keyOrIndex);
|
|
228
|
+
}
|
|
229
|
+
resolveParamToken(wrapper, param) {
|
|
230
|
+
if (typeof param === 'object' && 'forwardRef' in param) {
|
|
231
|
+
wrapper.forwardRef = true;
|
|
232
|
+
return param.forwardRef();
|
|
233
|
+
}
|
|
234
|
+
return param;
|
|
235
|
+
}
|
|
236
|
+
async resolveComponentWrapper(moduleRef, token, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
237
|
+
this.printResolvingDependenciesLog(token, inquirer);
|
|
238
|
+
this.printLookingForProviderLog(token, moduleRef);
|
|
239
|
+
const providers = moduleRef.providers;
|
|
240
|
+
return this.lookupComponent(providers, moduleRef, { ...dependencyContext, name: token }, wrapper, contextId, inquirer, keyOrIndex);
|
|
241
|
+
}
|
|
242
|
+
async resolveComponentHost(moduleRef, instanceWrapper, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
243
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
244
|
+
const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
|
|
245
|
+
if (!instanceHost.isResolved && !instanceWrapper.forwardRef) {
|
|
246
|
+
inquirer?.settlementSignal?.insertRef(instanceWrapper.id);
|
|
247
|
+
await this.loadProvider(instanceWrapper, instanceWrapper.host ?? moduleRef, contextId, inquirer);
|
|
248
|
+
}
|
|
249
|
+
else if (!instanceHost.isResolved &&
|
|
250
|
+
instanceWrapper.forwardRef &&
|
|
251
|
+
(contextId !== constants_2.STATIC_CONTEXT || !!inquirerId)) {
|
|
252
|
+
/**
|
|
253
|
+
* When circular dependency has been detected between
|
|
254
|
+
* either request/transient providers, we have to asynchronously
|
|
255
|
+
* resolve instance host for a specific contextId or inquirer, to ensure
|
|
256
|
+
* that eventual lazily created instance will be merged with the prototype
|
|
257
|
+
* instantiated beforehand.
|
|
258
|
+
*/
|
|
259
|
+
instanceHost.donePromise &&
|
|
260
|
+
void instanceHost.donePromise
|
|
261
|
+
.then(() => this.loadProvider(instanceWrapper, moduleRef, contextId, inquirer))
|
|
262
|
+
.catch(err => {
|
|
263
|
+
instanceWrapper.settlementSignal?.error(err);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (instanceWrapper.async) {
|
|
267
|
+
const host = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
|
|
268
|
+
host.instance = await host.instance;
|
|
269
|
+
instanceWrapper.setInstanceByContextId(contextId, host, inquirerId);
|
|
270
|
+
}
|
|
271
|
+
return instanceWrapper;
|
|
272
|
+
}
|
|
273
|
+
async lookupComponent(providers, moduleRef, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
274
|
+
const token = wrapper.token || wrapper.name;
|
|
275
|
+
const { name } = dependencyContext;
|
|
276
|
+
if (wrapper && token === name) {
|
|
277
|
+
throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
|
|
278
|
+
}
|
|
279
|
+
if (name && providers.has(name)) {
|
|
280
|
+
const instanceWrapper = providers.get(name);
|
|
281
|
+
this.printFoundInModuleLog(name, moduleRef);
|
|
282
|
+
this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapper);
|
|
283
|
+
return instanceWrapper;
|
|
284
|
+
}
|
|
285
|
+
return this.lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId, inquirer, keyOrIndex);
|
|
286
|
+
}
|
|
287
|
+
async lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
288
|
+
const instanceWrapper = await this.lookupComponentInImports(moduleRef, dependencyContext.name, wrapper, new Set(), contextId, inquirer, keyOrIndex);
|
|
289
|
+
if ((0, shared_utils_1.isNil)(instanceWrapper)) {
|
|
290
|
+
throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
|
|
291
|
+
}
|
|
292
|
+
return instanceWrapper;
|
|
293
|
+
}
|
|
294
|
+
async lookupComponentInImports(moduleRef, name, wrapper, moduleRegistry = new Set(), contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex, isTraversing) {
|
|
295
|
+
let instanceWrapperRef = null;
|
|
296
|
+
const imports = moduleRef.imports || new Set();
|
|
297
|
+
const identity = (item) => item;
|
|
298
|
+
let children = [...imports.values()].filter(identity);
|
|
299
|
+
if (isTraversing) {
|
|
300
|
+
const contextModuleExports = moduleRef.exports;
|
|
301
|
+
children = children.filter(child => contextModuleExports.has(child.metatype));
|
|
302
|
+
}
|
|
303
|
+
for (const relatedModule of children) {
|
|
304
|
+
if (moduleRegistry.has(relatedModule.id)) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
this.printLookingForProviderLog(name, relatedModule);
|
|
308
|
+
moduleRegistry.add(relatedModule.id);
|
|
309
|
+
const { providers, exports } = relatedModule;
|
|
310
|
+
if (!exports.has(name) || !providers.has(name)) {
|
|
311
|
+
const instanceRef = await this.lookupComponentInImports(relatedModule, name, wrapper, moduleRegistry, contextId, inquirer, keyOrIndex, true);
|
|
312
|
+
if (instanceRef) {
|
|
313
|
+
this.addDependencyMetadata(keyOrIndex, wrapper, instanceRef);
|
|
314
|
+
return instanceRef;
|
|
315
|
+
}
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
this.printFoundInModuleLog(name, relatedModule);
|
|
319
|
+
instanceWrapperRef = providers.get(name);
|
|
320
|
+
this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapperRef);
|
|
321
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
322
|
+
const instanceHost = instanceWrapperRef.getInstanceByContextId(this.getContextId(contextId, instanceWrapperRef), inquirerId);
|
|
323
|
+
if (!instanceHost.isResolved && !instanceWrapperRef.forwardRef) {
|
|
324
|
+
/*
|
|
325
|
+
* Provider will be loaded shortly in resolveComponentHost() once we pass the current
|
|
326
|
+
* Barrier. We cannot load it here because doing so could incorrectly evaluate the
|
|
327
|
+
* staticity of the dependency tree and lead to undefined / null injection.
|
|
328
|
+
*/
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return instanceWrapperRef;
|
|
333
|
+
}
|
|
334
|
+
async resolveProperties(wrapper, moduleRef, inject, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
|
|
335
|
+
if (!(0, shared_utils_1.isNil)(inject)) {
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
const metadata = wrapper.getPropertiesMetadata();
|
|
339
|
+
if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
|
|
340
|
+
return this.loadPropertiesMetadata(metadata, contextId, inquirer);
|
|
341
|
+
}
|
|
342
|
+
const properties = this.reflectProperties(wrapper.metatype);
|
|
343
|
+
const propertyBarrier = new barrier_1.Barrier(properties.length);
|
|
344
|
+
const instances = await Promise.all(properties.map(async (item) => {
|
|
345
|
+
try {
|
|
346
|
+
const dependencyContext = {
|
|
347
|
+
key: item.key,
|
|
348
|
+
name: item.name,
|
|
349
|
+
};
|
|
350
|
+
if (this.isInquirer(item.name, parentInquirer)) {
|
|
351
|
+
/*
|
|
352
|
+
* Signal the barrier to make sure other dependencies do not get stuck waiting forever.
|
|
353
|
+
*/
|
|
354
|
+
propertyBarrier.signal();
|
|
355
|
+
return parentInquirer && parentInquirer.instance;
|
|
356
|
+
}
|
|
357
|
+
const paramWrapper = await this.resolveSingleParam(wrapper, item.name, dependencyContext, moduleRef, contextId, inquirer, item.key);
|
|
358
|
+
/*
|
|
359
|
+
* Ensure that all instance wrappers are resolved at this point before we continue.
|
|
360
|
+
* Otherwise the staticity of `wrapper`'s dependency tree may be evaluated incorrectly
|
|
361
|
+
* and result in undefined / null injection.
|
|
362
|
+
*/
|
|
363
|
+
await propertyBarrier.signalAndWait();
|
|
364
|
+
const effectivePropertyInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
|
|
365
|
+
const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectivePropertyInquirer);
|
|
366
|
+
if (!paramWrapperWithInstance) {
|
|
367
|
+
return undefined;
|
|
368
|
+
}
|
|
369
|
+
const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectivePropertyInquirer));
|
|
370
|
+
return instanceHost.instance;
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
/*
|
|
374
|
+
* Signal the barrier to make sure other dependencies do not get stuck waiting forever. We
|
|
375
|
+
* do not care if this occurs after `Barrier.signalAndWait()` is called in the `try` block
|
|
376
|
+
* because the barrier will always have been resolved by then.
|
|
377
|
+
*/
|
|
378
|
+
propertyBarrier.signal();
|
|
379
|
+
if (!item.isOptional) {
|
|
380
|
+
throw err;
|
|
381
|
+
}
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
}));
|
|
385
|
+
return properties.map((item, index) => ({
|
|
386
|
+
...item,
|
|
387
|
+
instance: instances[index],
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
390
|
+
reflectProperties(type) {
|
|
391
|
+
const properties = Reflect.getMetadata(constants_1.PROPERTY_DEPS_METADATA, type) || [];
|
|
392
|
+
const optionalKeys = Reflect.getMetadata(constants_1.OPTIONAL_PROPERTY_DEPS_METADATA, type) || [];
|
|
393
|
+
return properties.map((item) => ({
|
|
394
|
+
...item,
|
|
395
|
+
name: item.type,
|
|
396
|
+
isOptional: optionalKeys.includes(item.key),
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
applyProperties(instance, properties) {
|
|
400
|
+
if (!(0, shared_utils_1.isObject)(instance)) {
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
(0, iterare_1.iterate)(properties)
|
|
404
|
+
.filter(item => !(0, shared_utils_1.isNil)(item.instance))
|
|
405
|
+
.forEach(item => (instance[item.key] = item.instance));
|
|
406
|
+
}
|
|
407
|
+
async instantiateClass(instances, wrapper, targetMetatype, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
408
|
+
const { metatype, inject } = wrapper;
|
|
409
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
410
|
+
const instanceHost = targetMetatype.getInstanceByContextId(this.getContextId(contextId, targetMetatype), inquirerId);
|
|
411
|
+
const isInContext = wrapper.isStatic(contextId, inquirer) ||
|
|
412
|
+
wrapper.isInRequestScope(contextId, inquirer) ||
|
|
413
|
+
wrapper.isLazyTransient(contextId, inquirer) ||
|
|
414
|
+
wrapper.isExplicitlyRequested(contextId, inquirer);
|
|
415
|
+
if (this.options?.preview && !wrapper.host?.initOnPreview) {
|
|
416
|
+
instanceHost.isResolved = true;
|
|
417
|
+
return instanceHost.instance;
|
|
418
|
+
}
|
|
419
|
+
if ((0, shared_utils_1.isNil)(inject) && isInContext) {
|
|
420
|
+
instanceHost.instance = wrapper.forwardRef
|
|
421
|
+
? Object.assign(instanceHost.instance, new metatype(...instances))
|
|
422
|
+
: new metatype(...instances);
|
|
423
|
+
instanceHost.instance = this.instanceDecorator(instanceHost.instance);
|
|
424
|
+
instanceHost.isConstructorCalled = true;
|
|
425
|
+
}
|
|
426
|
+
else if (isInContext) {
|
|
427
|
+
const factoryReturnValue = targetMetatype.metatype(...instances);
|
|
428
|
+
instanceHost.instance = await factoryReturnValue;
|
|
429
|
+
instanceHost.instance = this.instanceDecorator(instanceHost.instance);
|
|
430
|
+
instanceHost.isConstructorCalled = true;
|
|
431
|
+
}
|
|
432
|
+
instanceHost.isResolved = true;
|
|
433
|
+
return instanceHost.instance;
|
|
434
|
+
}
|
|
435
|
+
async loadPerContext(instance, moduleRef, collection, ctx, wrapper) {
|
|
436
|
+
if (!wrapper) {
|
|
437
|
+
const injectionToken = instance.constructor;
|
|
438
|
+
wrapper = collection.get(injectionToken);
|
|
439
|
+
}
|
|
440
|
+
await this.loadInstance(wrapper, collection, moduleRef, ctx, wrapper);
|
|
441
|
+
await this.loadEnhancersPerContext(wrapper, ctx, wrapper);
|
|
442
|
+
const host = wrapper.getInstanceByContextId(this.getContextId(ctx, wrapper), wrapper.id);
|
|
443
|
+
return host && host.instance;
|
|
444
|
+
}
|
|
445
|
+
async loadEnhancersPerContext(wrapper, ctx, inquirer) {
|
|
446
|
+
const enhancers = wrapper.getEnhancersMetadata() || [];
|
|
447
|
+
const loadEnhancer = (item) => {
|
|
448
|
+
const hostModule = item.host;
|
|
449
|
+
return this.loadInstance(item, hostModule.injectables, hostModule, ctx, inquirer);
|
|
450
|
+
};
|
|
451
|
+
await Promise.all(enhancers.map(loadEnhancer));
|
|
452
|
+
}
|
|
453
|
+
async loadCtorMetadata(metadata, contextId, inquirer, parentInquirer) {
|
|
454
|
+
const hosts = await Promise.all(metadata.map(async (item) => this.resolveScopedComponentHost(item, contextId, inquirer, parentInquirer)));
|
|
455
|
+
return hosts.map((item, index) => {
|
|
456
|
+
const dependency = metadata[index];
|
|
457
|
+
const effectiveInquirer = this.getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId);
|
|
458
|
+
return item?.getInstanceByContextId(this.getContextId(contextId, item), this.getInquirerId(effectiveInquirer)).instance;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
async loadPropertiesMetadata(metadata, contextId, inquirer) {
|
|
462
|
+
const dependenciesHosts = await Promise.all(metadata.map(async ({ wrapper: item, key }) => ({
|
|
463
|
+
key,
|
|
464
|
+
host: await this.resolveComponentHost(item.host, item, contextId, inquirer),
|
|
465
|
+
})));
|
|
466
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
467
|
+
return dependenciesHosts.map(({ key, host }) => ({
|
|
468
|
+
key,
|
|
469
|
+
name: key,
|
|
470
|
+
instance: host.getInstanceByContextId(this.getContextId(contextId, host), inquirerId).instance,
|
|
471
|
+
}));
|
|
472
|
+
}
|
|
473
|
+
getInquirerId(inquirer) {
|
|
474
|
+
return inquirer ? inquirer.id : undefined;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* For nested TRANSIENT dependencies (TRANSIENT -> TRANSIENT) in non-static contexts,
|
|
478
|
+
* returns parentInquirer to ensure each parent TRANSIENT gets its own instance.
|
|
479
|
+
* This is necessary because in REQUEST/DURABLE scopes, the same TRANSIENT wrapper
|
|
480
|
+
* can be used by multiple parents, causing nested TRANSIENTs to be shared incorrectly.
|
|
481
|
+
* For non-TRANSIENT -> TRANSIENT, returns inquirer (current wrapper being created).
|
|
482
|
+
*/
|
|
483
|
+
getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId) {
|
|
484
|
+
return dependency?.isTransient &&
|
|
485
|
+
inquirer?.isTransient &&
|
|
486
|
+
parentInquirer &&
|
|
487
|
+
contextId !== constants_2.STATIC_CONTEXT
|
|
488
|
+
? parentInquirer
|
|
489
|
+
: inquirer;
|
|
490
|
+
}
|
|
491
|
+
resolveScopedComponentHost(item, contextId, inquirer, parentInquirer) {
|
|
492
|
+
return this.isInquirerRequest(item, parentInquirer)
|
|
493
|
+
? parentInquirer
|
|
494
|
+
: this.resolveComponentHost(item.host, item, contextId, this.getEffectiveInquirer(item, inquirer, parentInquirer, contextId));
|
|
495
|
+
}
|
|
496
|
+
isInquirerRequest(item, parentInquirer) {
|
|
497
|
+
return item.isTransient && item.name === inquirer_1.INQUIRER && parentInquirer;
|
|
498
|
+
}
|
|
499
|
+
isInquirer(param, parentInquirer) {
|
|
500
|
+
return param === inquirer_1.INQUIRER && parentInquirer;
|
|
501
|
+
}
|
|
502
|
+
addDependencyMetadata(keyOrIndex, hostWrapper, instanceWrapper) {
|
|
503
|
+
if ((0, shared_utils_1.isSymbol)(keyOrIndex) || (0, shared_utils_1.isString)(keyOrIndex)) {
|
|
504
|
+
hostWrapper.addPropertiesMetadata(keyOrIndex, instanceWrapper);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
hostWrapper.addCtorMetadata(keyOrIndex, instanceWrapper);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
getTokenName(token) {
|
|
511
|
+
return (0, shared_utils_1.isFunction)(token) ? token.name : token.toString();
|
|
512
|
+
}
|
|
513
|
+
printResolvingDependenciesLog(token, inquirer) {
|
|
514
|
+
if (!this.isDebugMode()) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const tokenName = this.getTokenName(token);
|
|
518
|
+
const dependentName = (inquirer?.name && inquirer.name.toString?.()) ?? 'unknown';
|
|
519
|
+
const isAlias = dependentName === tokenName;
|
|
520
|
+
const messageToPrint = `Resolving dependency ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in the ')}${cli_colors_util_1.clc.yellow(dependentName)}${cli_colors_util_1.clc.green(` provider ${isAlias ? '(alias)' : ''}`)}`;
|
|
521
|
+
this.logger.log(messageToPrint);
|
|
522
|
+
}
|
|
523
|
+
printLookingForProviderLog(token, moduleRef) {
|
|
524
|
+
if (!this.isDebugMode()) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const tokenName = this.getTokenName(token);
|
|
528
|
+
const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
|
|
529
|
+
this.logger.log(`Looking for ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
|
|
530
|
+
}
|
|
531
|
+
printFoundInModuleLog(token, moduleRef) {
|
|
532
|
+
if (!this.isDebugMode()) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const tokenName = this.getTokenName(token);
|
|
536
|
+
const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
|
|
537
|
+
this.logger.log(`Found ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
|
|
538
|
+
}
|
|
539
|
+
isDebugMode() {
|
|
540
|
+
return !!process.env.NEST_DEBUG;
|
|
541
|
+
}
|
|
542
|
+
getContextId(contextId, instanceWrapper) {
|
|
543
|
+
return contextId.getParent
|
|
544
|
+
? contextId.getParent({
|
|
545
|
+
token: instanceWrapper.token,
|
|
546
|
+
isTreeDurable: instanceWrapper.isDependencyTreeDurable(),
|
|
547
|
+
})
|
|
548
|
+
: contextId;
|
|
549
|
+
}
|
|
550
|
+
getNowTimestamp() {
|
|
551
|
+
return perf_hooks_1.performance.now();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
exports.Injector = Injector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './inquirer-constants';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const INQUIRER = "INQUIRER";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inquirerProvider = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const inquirer_constants_1 = require("./inquirer-constants");
|
|
6
|
+
const noop = () => { };
|
|
7
|
+
exports.inquirerProvider = {
|
|
8
|
+
provide: inquirer_constants_1.INQUIRER,
|
|
9
|
+
scope: common_1.Scope.TRANSIENT,
|
|
10
|
+
useFactory: noop,
|
|
11
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InjectionToken } from '@nestjs/common';
|
|
2
|
+
import { NestContainer } from './container';
|
|
3
|
+
import { InstanceWrapper } from './instance-wrapper';
|
|
4
|
+
export interface InstanceLink<T = any> {
|
|
5
|
+
token: InjectionToken;
|
|
6
|
+
wrapperRef: InstanceWrapper<T>;
|
|
7
|
+
collection: Map<any, InstanceWrapper>;
|
|
8
|
+
moduleId: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class InstanceLinksHost {
|
|
11
|
+
private readonly container;
|
|
12
|
+
private readonly instanceLinks;
|
|
13
|
+
constructor(container: NestContainer);
|
|
14
|
+
get<T = any>(token: InjectionToken): InstanceLink<T>;
|
|
15
|
+
get<T = any>(token: InjectionToken, options?: {
|
|
16
|
+
moduleId?: string;
|
|
17
|
+
each?: boolean;
|
|
18
|
+
}): InstanceLink<T> | Array<InstanceLink<T>>;
|
|
19
|
+
private initialize;
|
|
20
|
+
private addLink;
|
|
21
|
+
private getInstanceNameByToken;
|
|
22
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstanceLinksHost = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
+
const unknown_element_exception_1 = require("../errors/exceptions/unknown-element.exception");
|
|
6
|
+
class InstanceLinksHost {
|
|
7
|
+
constructor(container) {
|
|
8
|
+
this.container = container;
|
|
9
|
+
this.instanceLinks = new Map();
|
|
10
|
+
this.initialize();
|
|
11
|
+
}
|
|
12
|
+
get(token, options = {}) {
|
|
13
|
+
const instanceLinksForGivenToken = this.instanceLinks.get(token);
|
|
14
|
+
if (!instanceLinksForGivenToken) {
|
|
15
|
+
throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
|
|
16
|
+
}
|
|
17
|
+
if (options.each) {
|
|
18
|
+
return instanceLinksForGivenToken;
|
|
19
|
+
}
|
|
20
|
+
const instanceLink = options.moduleId
|
|
21
|
+
? instanceLinksForGivenToken.find(item => item.moduleId === options.moduleId)
|
|
22
|
+
: instanceLinksForGivenToken[instanceLinksForGivenToken.length - 1];
|
|
23
|
+
if (!instanceLink) {
|
|
24
|
+
throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
|
|
25
|
+
}
|
|
26
|
+
return instanceLink;
|
|
27
|
+
}
|
|
28
|
+
initialize() {
|
|
29
|
+
const modules = this.container.getModules();
|
|
30
|
+
modules.forEach(moduleRef => {
|
|
31
|
+
const { providers, injectables, controllers } = moduleRef;
|
|
32
|
+
providers.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'providers'));
|
|
33
|
+
injectables.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'injectables'));
|
|
34
|
+
controllers.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'controllers'));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
addLink(wrapper, token, moduleRef, collectionName) {
|
|
38
|
+
const instanceLink = {
|
|
39
|
+
moduleId: moduleRef.id,
|
|
40
|
+
wrapperRef: wrapper,
|
|
41
|
+
collection: moduleRef[collectionName],
|
|
42
|
+
token,
|
|
43
|
+
};
|
|
44
|
+
const existingLinks = this.instanceLinks.get(token);
|
|
45
|
+
if (!existingLinks) {
|
|
46
|
+
this.instanceLinks.set(token, [instanceLink]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
existingLinks.push(instanceLink);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getInstanceNameByToken(token) {
|
|
53
|
+
return (0, shared_utils_1.isFunction)(token) ? token?.name : token;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.InstanceLinksHost = InstanceLinksHost;
|