@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,328 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestApplication = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const logger_service_1 = require("@nestjs/common/services/logger.service");
|
|
6
|
+
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
7
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
|
+
const iterare_1 = require("iterare");
|
|
9
|
+
const os_1 = require("os");
|
|
10
|
+
const application_config_1 = require("./application-config");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const optional_require_1 = require("./helpers/optional-require");
|
|
13
|
+
const injector_1 = require("./injector/injector");
|
|
14
|
+
const container_1 = require("./middleware/container");
|
|
15
|
+
const middleware_module_1 = require("./middleware/middleware-module");
|
|
16
|
+
const utils_1 = require("./middleware/utils");
|
|
17
|
+
const nest_application_context_1 = require("./nest-application-context");
|
|
18
|
+
const routes_resolver_1 = require("./router/routes-resolver");
|
|
19
|
+
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
|
|
20
|
+
const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
|
|
21
|
+
/**
|
|
22
|
+
* @publicApi
|
|
23
|
+
*/
|
|
24
|
+
class NestApplication extends nest_application_context_1.NestApplicationContext {
|
|
25
|
+
constructor(container, httpAdapter, config, graphInspector, appOptions = {}) {
|
|
26
|
+
super(container, appOptions);
|
|
27
|
+
this.httpAdapter = httpAdapter;
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.graphInspector = graphInspector;
|
|
30
|
+
this.logger = new logger_service_1.Logger(NestApplication.name, {
|
|
31
|
+
timestamp: true,
|
|
32
|
+
});
|
|
33
|
+
this.middlewareContainer = new container_1.MiddlewareContainer(this.container);
|
|
34
|
+
this.microservicesModule = MicroservicesModule && new MicroservicesModule();
|
|
35
|
+
this.socketModule = SocketModule && new SocketModule();
|
|
36
|
+
this.microservices = [];
|
|
37
|
+
this.isListening = false;
|
|
38
|
+
this.selectContextModule();
|
|
39
|
+
this.registerHttpServer();
|
|
40
|
+
this.injector = new injector_1.Injector({
|
|
41
|
+
preview: this.appOptions.preview,
|
|
42
|
+
instanceDecorator: appOptions.instrument?.instanceDecorator,
|
|
43
|
+
});
|
|
44
|
+
this.middlewareModule = new middleware_module_1.MiddlewareModule();
|
|
45
|
+
this.routesResolver = new routes_resolver_1.RoutesResolver(this.container, this.config, this.injector, this.graphInspector);
|
|
46
|
+
}
|
|
47
|
+
async dispose() {
|
|
48
|
+
this.socketModule && (await this.socketModule.close());
|
|
49
|
+
this.microservicesModule && (await this.microservicesModule.close());
|
|
50
|
+
this.httpAdapter && (await this.httpAdapter.close());
|
|
51
|
+
await Promise.all((0, iterare_1.iterate)(this.microservices).map(async (microservice) => {
|
|
52
|
+
microservice.setIsTerminated(true);
|
|
53
|
+
await microservice.close();
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
getHttpAdapter() {
|
|
57
|
+
return this.httpAdapter;
|
|
58
|
+
}
|
|
59
|
+
registerHttpServer() {
|
|
60
|
+
this.httpServer = this.createServer();
|
|
61
|
+
}
|
|
62
|
+
getUnderlyingHttpServer() {
|
|
63
|
+
return this.httpAdapter.getHttpServer();
|
|
64
|
+
}
|
|
65
|
+
applyOptions() {
|
|
66
|
+
if (!this.appOptions || !this.appOptions.cors) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const passCustomOptions = (0, shared_utils_1.isObject)(this.appOptions.cors) || (0, shared_utils_1.isFunction)(this.appOptions.cors);
|
|
70
|
+
if (!passCustomOptions) {
|
|
71
|
+
return this.enableCors();
|
|
72
|
+
}
|
|
73
|
+
return this.enableCors(this.appOptions.cors);
|
|
74
|
+
}
|
|
75
|
+
createServer() {
|
|
76
|
+
this.httpAdapter.initHttpServer(this.appOptions);
|
|
77
|
+
return this.httpAdapter.getHttpServer();
|
|
78
|
+
}
|
|
79
|
+
async registerModules() {
|
|
80
|
+
this.registerWsModule();
|
|
81
|
+
if (this.microservicesModule) {
|
|
82
|
+
this.microservicesModule.register(this.container, this.graphInspector, this.config, this.appOptions);
|
|
83
|
+
this.microservicesModule.setupClients(this.container);
|
|
84
|
+
}
|
|
85
|
+
await this.middlewareModule.register(this.middlewareContainer, this.container, this.config, this.injector, this.httpAdapter, this.graphInspector, this.appOptions);
|
|
86
|
+
}
|
|
87
|
+
registerWsModule() {
|
|
88
|
+
if (!this.socketModule) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.socketModule.register(this.container, this.config, this.graphInspector, this.appOptions, this.httpServer);
|
|
92
|
+
}
|
|
93
|
+
async init() {
|
|
94
|
+
if (this.isInitialized) {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
this.applyOptions();
|
|
98
|
+
await this.httpAdapter?.init?.();
|
|
99
|
+
const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
|
|
100
|
+
useBodyParser && this.registerParserMiddleware();
|
|
101
|
+
await this.registerModules();
|
|
102
|
+
await this.registerRouter();
|
|
103
|
+
await this.callInitHook();
|
|
104
|
+
await this.registerRouterHooks();
|
|
105
|
+
await this.callBootstrapHook();
|
|
106
|
+
this.isInitialized = true;
|
|
107
|
+
this.logger.log(constants_1.MESSAGES.APPLICATION_READY);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
registerParserMiddleware() {
|
|
111
|
+
const prefix = this.config.getGlobalPrefix();
|
|
112
|
+
const rawBody = !!this.appOptions?.rawBody;
|
|
113
|
+
this.httpAdapter.registerParserMiddleware(prefix, rawBody);
|
|
114
|
+
}
|
|
115
|
+
async registerRouter() {
|
|
116
|
+
await this.registerMiddleware(this.httpAdapter);
|
|
117
|
+
const prefix = this.config.getGlobalPrefix();
|
|
118
|
+
const basePath = (0, shared_utils_1.addLeadingSlash)(prefix);
|
|
119
|
+
this.routesResolver.resolve(this.httpAdapter, basePath);
|
|
120
|
+
}
|
|
121
|
+
async registerRouterHooks() {
|
|
122
|
+
this.routesResolver.registerNotFoundHandler();
|
|
123
|
+
this.routesResolver.registerExceptionHandler();
|
|
124
|
+
}
|
|
125
|
+
connectMicroservice(microserviceOptions, hybridAppOptions = {}) {
|
|
126
|
+
const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
|
|
127
|
+
const { inheritAppConfig } = hybridAppOptions;
|
|
128
|
+
const applicationConfig = inheritAppConfig
|
|
129
|
+
? this.config
|
|
130
|
+
: new application_config_1.ApplicationConfig();
|
|
131
|
+
const instance = new NestMicroservice(this.container, microserviceOptions, this.graphInspector, applicationConfig);
|
|
132
|
+
if (!hybridAppOptions.deferInitialization) {
|
|
133
|
+
instance.registerListeners();
|
|
134
|
+
instance.setIsInitialized(true);
|
|
135
|
+
instance.setIsInitHookCalled(true);
|
|
136
|
+
}
|
|
137
|
+
this.microservices.push(instance);
|
|
138
|
+
return instance;
|
|
139
|
+
}
|
|
140
|
+
getMicroservices() {
|
|
141
|
+
return this.microservices;
|
|
142
|
+
}
|
|
143
|
+
getHttpServer() {
|
|
144
|
+
return this.httpServer;
|
|
145
|
+
}
|
|
146
|
+
async startAllMicroservices() {
|
|
147
|
+
this.assertNotInPreviewMode('startAllMicroservices');
|
|
148
|
+
await Promise.all(this.microservices.map(msvc => msvc.listen()));
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
use(...args) {
|
|
152
|
+
this.httpAdapter.use(...args);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
useBodyParser(...args) {
|
|
156
|
+
if (!('useBodyParser' in this.httpAdapter)) {
|
|
157
|
+
this.logger.warn('Your HTTP Adapter does not support `.useBodyParser`.');
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
const [parserType, ...otherArgs] = args;
|
|
161
|
+
const rawBody = !!this.appOptions.rawBody;
|
|
162
|
+
this.httpAdapter.useBodyParser?.(...[parserType, rawBody, ...otherArgs]);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
enableCors(options) {
|
|
166
|
+
this.httpAdapter.enableCors(options);
|
|
167
|
+
}
|
|
168
|
+
enableVersioning(options = { type: common_1.VersioningType.URI }) {
|
|
169
|
+
this.config.enableVersioning(options);
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
async listen(port, ...args) {
|
|
173
|
+
this.assertNotInPreviewMode('listen');
|
|
174
|
+
if (!this.isInitialized) {
|
|
175
|
+
await this.init();
|
|
176
|
+
}
|
|
177
|
+
const httpAdapterHost = this.container.getHttpAdapterHostRef();
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
const errorHandler = (e) => {
|
|
180
|
+
this.logger.error(e?.toString?.());
|
|
181
|
+
reject(e);
|
|
182
|
+
};
|
|
183
|
+
this.httpServer.once('error', errorHandler);
|
|
184
|
+
const isCallbackInOriginalArgs = (0, shared_utils_1.isFunction)(args[args.length - 1]);
|
|
185
|
+
const listenFnArgs = isCallbackInOriginalArgs
|
|
186
|
+
? args.slice(0, args.length - 1)
|
|
187
|
+
: args;
|
|
188
|
+
this.httpAdapter.listen(port, ...listenFnArgs, (...originalCallbackArgs) => {
|
|
189
|
+
if (this.appOptions?.autoFlushLogs ?? true) {
|
|
190
|
+
this.flushLogs();
|
|
191
|
+
}
|
|
192
|
+
if (originalCallbackArgs[0] instanceof Error) {
|
|
193
|
+
return reject(originalCallbackArgs[0]);
|
|
194
|
+
}
|
|
195
|
+
const address = this.httpServer.address();
|
|
196
|
+
if (address) {
|
|
197
|
+
this.httpServer.removeListener('error', errorHandler);
|
|
198
|
+
this.isListening = true;
|
|
199
|
+
httpAdapterHost.listening = true;
|
|
200
|
+
resolve(this.httpServer);
|
|
201
|
+
}
|
|
202
|
+
if (isCallbackInOriginalArgs) {
|
|
203
|
+
args[args.length - 1](...originalCallbackArgs);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async getUrl() {
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
if (!this.isListening) {
|
|
211
|
+
this.logger.error(constants_1.MESSAGES.CALL_LISTEN_FIRST);
|
|
212
|
+
reject(constants_1.MESSAGES.CALL_LISTEN_FIRST);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const address = this.httpServer.address();
|
|
216
|
+
resolve(this.formatAddress(address));
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
formatAddress(address) {
|
|
220
|
+
if ((0, shared_utils_1.isString)(address)) {
|
|
221
|
+
if ((0, os_1.platform)() === 'win32') {
|
|
222
|
+
return address;
|
|
223
|
+
}
|
|
224
|
+
const basePath = encodeURIComponent(address);
|
|
225
|
+
return `${this.getProtocol()}+unix://${basePath}`;
|
|
226
|
+
}
|
|
227
|
+
let host = this.host();
|
|
228
|
+
if (address && address.family === 'IPv6') {
|
|
229
|
+
if (host === '::') {
|
|
230
|
+
host = '[::1]';
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
host = `[${host}]`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (host === '0.0.0.0') {
|
|
237
|
+
host = '127.0.0.1';
|
|
238
|
+
}
|
|
239
|
+
return `${this.getProtocol()}://${host}:${address.port}`;
|
|
240
|
+
}
|
|
241
|
+
setGlobalPrefix(prefix, options) {
|
|
242
|
+
this.config.setGlobalPrefix(prefix);
|
|
243
|
+
if (options) {
|
|
244
|
+
const exclude = options?.exclude
|
|
245
|
+
? (0, utils_1.mapToExcludeRoute)(options.exclude)
|
|
246
|
+
: [];
|
|
247
|
+
this.config.setGlobalPrefixOptions({
|
|
248
|
+
...options,
|
|
249
|
+
exclude,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
useWebSocketAdapter(adapter) {
|
|
255
|
+
this.config.setIoAdapter(adapter);
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
useGlobalFilters(...filters) {
|
|
259
|
+
filters = this.applyInstanceDecoratorIfRegistered(...filters);
|
|
260
|
+
this.config.useGlobalFilters(...filters);
|
|
261
|
+
filters.forEach(item => this.graphInspector.insertOrphanedEnhancer({
|
|
262
|
+
subtype: 'filter',
|
|
263
|
+
ref: item,
|
|
264
|
+
}));
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
useGlobalPipes(...pipes) {
|
|
268
|
+
pipes = this.applyInstanceDecoratorIfRegistered(...pipes);
|
|
269
|
+
this.config.useGlobalPipes(...pipes);
|
|
270
|
+
pipes.forEach(item => this.graphInspector.insertOrphanedEnhancer({
|
|
271
|
+
subtype: 'pipe',
|
|
272
|
+
ref: item,
|
|
273
|
+
}));
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
useGlobalInterceptors(...interceptors) {
|
|
277
|
+
interceptors = this.applyInstanceDecoratorIfRegistered(...interceptors);
|
|
278
|
+
this.config.useGlobalInterceptors(...interceptors);
|
|
279
|
+
interceptors.forEach(item => this.graphInspector.insertOrphanedEnhancer({
|
|
280
|
+
subtype: 'interceptor',
|
|
281
|
+
ref: item,
|
|
282
|
+
}));
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
useGlobalGuards(...guards) {
|
|
286
|
+
guards = this.applyInstanceDecoratorIfRegistered(...guards);
|
|
287
|
+
this.config.useGlobalGuards(...guards);
|
|
288
|
+
guards.forEach(item => this.graphInspector.insertOrphanedEnhancer({
|
|
289
|
+
subtype: 'guard',
|
|
290
|
+
ref: item,
|
|
291
|
+
}));
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
useStaticAssets(pathOrOptions, options) {
|
|
295
|
+
this.httpAdapter.useStaticAssets &&
|
|
296
|
+
this.httpAdapter.useStaticAssets(pathOrOptions, options);
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
setBaseViewsDir(path) {
|
|
300
|
+
this.httpAdapter.setBaseViewsDir && this.httpAdapter.setBaseViewsDir(path);
|
|
301
|
+
return this;
|
|
302
|
+
}
|
|
303
|
+
setViewEngine(engineOrOptions) {
|
|
304
|
+
this.httpAdapter.setViewEngine &&
|
|
305
|
+
this.httpAdapter.setViewEngine(engineOrOptions);
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
host() {
|
|
309
|
+
const address = this.httpServer.address();
|
|
310
|
+
if ((0, shared_utils_1.isString)(address)) {
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
return address && address.address;
|
|
314
|
+
}
|
|
315
|
+
getProtocol() {
|
|
316
|
+
return this.appOptions && this.appOptions.httpsOptions ? 'https' : 'http';
|
|
317
|
+
}
|
|
318
|
+
async registerMiddleware(instance) {
|
|
319
|
+
await this.middlewareModule.registerMiddleware(this.middlewareContainer, instance);
|
|
320
|
+
}
|
|
321
|
+
applyInstanceDecoratorIfRegistered(...instances) {
|
|
322
|
+
if (this.appOptions.instrument?.instanceDecorator) {
|
|
323
|
+
return instances.map(instance => this.appOptions.instrument.instanceDecorator(instance));
|
|
324
|
+
}
|
|
325
|
+
return instances;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.NestApplication = NestApplication;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, INestMicroservice, Type } from '@nestjs/common';
|
|
2
|
+
import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
|
|
3
|
+
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
|
|
4
|
+
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
|
|
5
|
+
import { AbstractHttpAdapter } from './adapters/http-adapter';
|
|
6
|
+
type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
|
|
7
|
+
/**
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
10
|
+
export declare class NestFactoryStatic {
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private abortOnError;
|
|
13
|
+
private autoFlushLogs;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of NestApplication.
|
|
16
|
+
*
|
|
17
|
+
* @param module Entry (root) application module class
|
|
18
|
+
* @param options List of options to initialize NestApplication
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that, when resolved,
|
|
21
|
+
* contains a reference to the NestApplication instance.
|
|
22
|
+
*/
|
|
23
|
+
create<T extends INestApplication = INestApplication>(module: IEntryNestModule, options?: NestApplicationOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of NestApplication with the specified `httpAdapter`.
|
|
26
|
+
*
|
|
27
|
+
* @param module Entry (root) application module class
|
|
28
|
+
* @param httpAdapter Adapter to proxy the request/response cycle to
|
|
29
|
+
* the underlying HTTP server
|
|
30
|
+
* @param options List of options to initialize NestApplication
|
|
31
|
+
*
|
|
32
|
+
* @returns A promise that, when resolved,
|
|
33
|
+
* contains a reference to the NestApplication instance.
|
|
34
|
+
*/
|
|
35
|
+
create<T extends INestApplication = INestApplication>(module: IEntryNestModule, httpAdapter: AbstractHttpAdapter, options?: NestApplicationOptions): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates an instance of NestMicroservice.
|
|
38
|
+
*
|
|
39
|
+
* @param moduleCls Entry (root) application module class
|
|
40
|
+
* @param options Optional microservice configuration
|
|
41
|
+
*
|
|
42
|
+
* @returns A promise that, when resolved,
|
|
43
|
+
* contains a reference to the NestMicroservice instance.
|
|
44
|
+
*/
|
|
45
|
+
createMicroservice<T extends object>(moduleCls: IEntryNestModule, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates an instance of NestApplicationContext.
|
|
48
|
+
*
|
|
49
|
+
* @param moduleCls Entry (root) application module class
|
|
50
|
+
* @param options Optional Nest application configuration
|
|
51
|
+
*
|
|
52
|
+
* @returns A promise that, when resolved,
|
|
53
|
+
* contains a reference to the NestApplicationContext instance.
|
|
54
|
+
*/
|
|
55
|
+
createApplicationContext(moduleCls: IEntryNestModule, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
|
|
56
|
+
private createNestInstance;
|
|
57
|
+
private initialize;
|
|
58
|
+
private handleInitializationError;
|
|
59
|
+
private createProxy;
|
|
60
|
+
private createExceptionProxy;
|
|
61
|
+
private createExceptionZone;
|
|
62
|
+
private registerLoggerConfiguration;
|
|
63
|
+
private createHttpAdapter;
|
|
64
|
+
private isHttpServer;
|
|
65
|
+
private setAbortOnError;
|
|
66
|
+
private createAdapterProxy;
|
|
67
|
+
private createGraphInspector;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Use NestFactory to create an application instance.
|
|
71
|
+
*
|
|
72
|
+
* ### Specifying an entry module
|
|
73
|
+
*
|
|
74
|
+
* Pass the required *root module* for the application via the module parameter.
|
|
75
|
+
* By convention, it is usually called `ApplicationModule`. Starting with this
|
|
76
|
+
* module, Nest assembles the dependency graph and begins the process of
|
|
77
|
+
* Dependency Injection and instantiates the classes needed to launch your
|
|
78
|
+
* application.
|
|
79
|
+
*
|
|
80
|
+
* @publicApi
|
|
81
|
+
*/
|
|
82
|
+
export declare const NestFactory: NestFactoryStatic;
|
|
83
|
+
export {};
|
package/nest-factory.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestFactory = exports.NestFactoryStatic = void 0;
|
|
4
|
+
const console_logger_service_1 = require("@nestjs/common/services/console-logger.service");
|
|
5
|
+
const logger_service_1 = require("@nestjs/common/services/logger.service");
|
|
6
|
+
const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
7
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
|
+
const application_config_1 = require("./application-config");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const exceptions_zone_1 = require("./errors/exceptions-zone");
|
|
11
|
+
const load_adapter_1 = require("./helpers/load-adapter");
|
|
12
|
+
const rethrow_1 = require("./helpers/rethrow");
|
|
13
|
+
const container_1 = require("./injector/container");
|
|
14
|
+
const injector_1 = require("./injector/injector");
|
|
15
|
+
const instance_loader_1 = require("./injector/instance-loader");
|
|
16
|
+
const graph_inspector_1 = require("./inspector/graph-inspector");
|
|
17
|
+
const noop_graph_inspector_1 = require("./inspector/noop-graph-inspector");
|
|
18
|
+
const uuid_factory_1 = require("./inspector/uuid-factory");
|
|
19
|
+
const metadata_scanner_1 = require("./metadata-scanner");
|
|
20
|
+
const nest_application_1 = require("./nest-application");
|
|
21
|
+
const nest_application_context_1 = require("./nest-application-context");
|
|
22
|
+
const scanner_1 = require("./scanner");
|
|
23
|
+
/**
|
|
24
|
+
* @publicApi
|
|
25
|
+
*/
|
|
26
|
+
class NestFactoryStatic {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.logger = new logger_service_1.Logger('NestFactory', {
|
|
29
|
+
timestamp: true,
|
|
30
|
+
});
|
|
31
|
+
this.abortOnError = true;
|
|
32
|
+
this.autoFlushLogs = false;
|
|
33
|
+
}
|
|
34
|
+
async create(moduleCls, serverOrOptions, options) {
|
|
35
|
+
const [httpServer, appOptions] = this.isHttpServer(serverOrOptions)
|
|
36
|
+
? [serverOrOptions, options]
|
|
37
|
+
: [this.createHttpAdapter(), serverOrOptions];
|
|
38
|
+
const applicationConfig = new application_config_1.ApplicationConfig();
|
|
39
|
+
const container = new container_1.NestContainer(applicationConfig, appOptions);
|
|
40
|
+
const graphInspector = this.createGraphInspector(appOptions, container);
|
|
41
|
+
this.setAbortOnError(serverOrOptions, options);
|
|
42
|
+
this.registerLoggerConfiguration(appOptions);
|
|
43
|
+
await this.initialize(moduleCls, container, graphInspector, applicationConfig, appOptions, httpServer);
|
|
44
|
+
const instance = new nest_application_1.NestApplication(container, httpServer, applicationConfig, graphInspector, appOptions);
|
|
45
|
+
const target = this.createNestInstance(instance);
|
|
46
|
+
return this.createAdapterProxy(target, httpServer);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates an instance of NestMicroservice.
|
|
50
|
+
*
|
|
51
|
+
* @param moduleCls Entry (root) application module class
|
|
52
|
+
* @param options Optional microservice configuration
|
|
53
|
+
*
|
|
54
|
+
* @returns A promise that, when resolved,
|
|
55
|
+
* contains a reference to the NestMicroservice instance.
|
|
56
|
+
*/
|
|
57
|
+
async createMicroservice(moduleCls, options) {
|
|
58
|
+
const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
|
|
59
|
+
const applicationConfig = new application_config_1.ApplicationConfig();
|
|
60
|
+
const container = new container_1.NestContainer(applicationConfig, options);
|
|
61
|
+
const graphInspector = this.createGraphInspector(options, container);
|
|
62
|
+
this.setAbortOnError(options);
|
|
63
|
+
this.registerLoggerConfiguration(options);
|
|
64
|
+
await this.initialize(moduleCls, container, graphInspector, applicationConfig, options);
|
|
65
|
+
return this.createNestInstance(new NestMicroservice(container, options, graphInspector, applicationConfig));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates an instance of NestApplicationContext.
|
|
69
|
+
*
|
|
70
|
+
* @param moduleCls Entry (root) application module class
|
|
71
|
+
* @param options Optional Nest application configuration
|
|
72
|
+
*
|
|
73
|
+
* @returns A promise that, when resolved,
|
|
74
|
+
* contains a reference to the NestApplicationContext instance.
|
|
75
|
+
*/
|
|
76
|
+
async createApplicationContext(moduleCls, options) {
|
|
77
|
+
const applicationConfig = new application_config_1.ApplicationConfig();
|
|
78
|
+
const container = new container_1.NestContainer(applicationConfig, options);
|
|
79
|
+
const graphInspector = this.createGraphInspector(options, container);
|
|
80
|
+
this.setAbortOnError(options);
|
|
81
|
+
this.registerLoggerConfiguration(options);
|
|
82
|
+
await this.initialize(moduleCls, container, graphInspector, applicationConfig, options);
|
|
83
|
+
const modules = container.getModules().values();
|
|
84
|
+
const root = modules.next().value;
|
|
85
|
+
const context = this.createNestInstance(new nest_application_context_1.NestApplicationContext(container, options, root));
|
|
86
|
+
if (this.autoFlushLogs) {
|
|
87
|
+
context.flushLogsOnOverride();
|
|
88
|
+
}
|
|
89
|
+
return context.init();
|
|
90
|
+
}
|
|
91
|
+
createNestInstance(instance) {
|
|
92
|
+
return this.createProxy(instance);
|
|
93
|
+
}
|
|
94
|
+
async initialize(module, container, graphInspector, config = new application_config_1.ApplicationConfig(), options = {}, httpServer = null) {
|
|
95
|
+
uuid_factory_1.UuidFactory.mode = options.snapshot
|
|
96
|
+
? uuid_factory_1.UuidFactoryMode.Deterministic
|
|
97
|
+
: uuid_factory_1.UuidFactoryMode.Random;
|
|
98
|
+
const injector = new injector_1.Injector({
|
|
99
|
+
preview: options.preview,
|
|
100
|
+
instanceDecorator: options.instrument?.instanceDecorator,
|
|
101
|
+
});
|
|
102
|
+
const instanceLoader = new instance_loader_1.InstanceLoader(container, injector, graphInspector);
|
|
103
|
+
const metadataScanner = new metadata_scanner_1.MetadataScanner();
|
|
104
|
+
const dependenciesScanner = new scanner_1.DependenciesScanner(container, metadataScanner, graphInspector, config);
|
|
105
|
+
container.setHttpAdapter(httpServer);
|
|
106
|
+
const teardown = this.abortOnError === false ? rethrow_1.rethrow : undefined;
|
|
107
|
+
await httpServer?.init?.();
|
|
108
|
+
try {
|
|
109
|
+
this.logger.log(constants_1.MESSAGES.APPLICATION_START);
|
|
110
|
+
await exceptions_zone_1.ExceptionsZone.asyncRun(async () => {
|
|
111
|
+
await dependenciesScanner.scan(module);
|
|
112
|
+
await instanceLoader.createInstancesOfDependencies();
|
|
113
|
+
dependenciesScanner.applyApplicationProviders();
|
|
114
|
+
}, teardown, this.autoFlushLogs);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
this.handleInitializationError(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
handleInitializationError(err) {
|
|
121
|
+
if (this.abortOnError) {
|
|
122
|
+
process.abort();
|
|
123
|
+
}
|
|
124
|
+
(0, rethrow_1.rethrow)(err);
|
|
125
|
+
}
|
|
126
|
+
createProxy(target) {
|
|
127
|
+
const proxy = this.createExceptionProxy();
|
|
128
|
+
return new Proxy(target, {
|
|
129
|
+
get: proxy,
|
|
130
|
+
set: proxy,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
createExceptionProxy() {
|
|
134
|
+
return (receiver, prop) => {
|
|
135
|
+
if (!(prop in receiver)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if ((0, shared_utils_1.isFunction)(receiver[prop])) {
|
|
139
|
+
return this.createExceptionZone(receiver, prop);
|
|
140
|
+
}
|
|
141
|
+
return receiver[prop];
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
createExceptionZone(receiver, prop) {
|
|
145
|
+
const teardown = this.abortOnError === false ? rethrow_1.rethrow : undefined;
|
|
146
|
+
return (...args) => {
|
|
147
|
+
let result;
|
|
148
|
+
exceptions_zone_1.ExceptionsZone.run(() => {
|
|
149
|
+
result = receiver[prop](...args);
|
|
150
|
+
}, teardown, this.autoFlushLogs);
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
registerLoggerConfiguration(options) {
|
|
155
|
+
if (!options) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const { logger, bufferLogs, autoFlushLogs, forceConsole } = options;
|
|
159
|
+
if (logger !== true && !(0, shared_utils_1.isNil)(logger)) {
|
|
160
|
+
logger_service_1.Logger.overrideLogger(logger);
|
|
161
|
+
}
|
|
162
|
+
else if (forceConsole) {
|
|
163
|
+
// If no custom logger is provided but forceConsole is true,
|
|
164
|
+
// create a ConsoleLogger with forceConsole option
|
|
165
|
+
const consoleLogger = new console_logger_service_1.ConsoleLogger({ forceConsole: true });
|
|
166
|
+
logger_service_1.Logger.overrideLogger(consoleLogger);
|
|
167
|
+
}
|
|
168
|
+
if (bufferLogs) {
|
|
169
|
+
logger_service_1.Logger.attachBuffer();
|
|
170
|
+
}
|
|
171
|
+
this.autoFlushLogs = autoFlushLogs ?? true;
|
|
172
|
+
}
|
|
173
|
+
createHttpAdapter(httpServer) {
|
|
174
|
+
const { ExpressAdapter } = (0, load_adapter_1.loadAdapter)('@nestjs/platform-express', 'HTTP', () => require('@nestjs/platform-express'));
|
|
175
|
+
return new ExpressAdapter(httpServer);
|
|
176
|
+
}
|
|
177
|
+
isHttpServer(serverOrOptions) {
|
|
178
|
+
return !!(serverOrOptions && serverOrOptions.patch);
|
|
179
|
+
}
|
|
180
|
+
setAbortOnError(serverOrOptions, options) {
|
|
181
|
+
this.abortOnError = this.isHttpServer(serverOrOptions)
|
|
182
|
+
? !(options && options.abortOnError === false)
|
|
183
|
+
: !(serverOrOptions && serverOrOptions.abortOnError === false);
|
|
184
|
+
}
|
|
185
|
+
createAdapterProxy(app, adapter) {
|
|
186
|
+
const proxy = new Proxy(app, {
|
|
187
|
+
get: (receiver, prop) => {
|
|
188
|
+
const mapToProxy = (result) => {
|
|
189
|
+
return result instanceof Promise
|
|
190
|
+
? result.then(mapToProxy)
|
|
191
|
+
: result instanceof nest_application_1.NestApplication
|
|
192
|
+
? proxy
|
|
193
|
+
: result;
|
|
194
|
+
};
|
|
195
|
+
if (!(prop in receiver) && prop in adapter) {
|
|
196
|
+
return (...args) => {
|
|
197
|
+
const result = this.createExceptionZone(adapter, prop)(...args);
|
|
198
|
+
return mapToProxy(result);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if ((0, shared_utils_1.isFunction)(receiver[prop])) {
|
|
202
|
+
return (...args) => {
|
|
203
|
+
const result = receiver[prop](...args);
|
|
204
|
+
return mapToProxy(result);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return receiver[prop];
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
return proxy;
|
|
211
|
+
}
|
|
212
|
+
createGraphInspector(appOptions, container) {
|
|
213
|
+
return appOptions?.snapshot
|
|
214
|
+
? new graph_inspector_1.GraphInspector(container)
|
|
215
|
+
: noop_graph_inspector_1.NoopGraphInspector;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.NestFactoryStatic = NestFactoryStatic;
|
|
219
|
+
/**
|
|
220
|
+
* Use NestFactory to create an application instance.
|
|
221
|
+
*
|
|
222
|
+
* ### Specifying an entry module
|
|
223
|
+
*
|
|
224
|
+
* Pass the required *root module* for the application via the module parameter.
|
|
225
|
+
* By convention, it is usually called `ApplicationModule`. Starting with this
|
|
226
|
+
* module, Nest assembles the dependency graph and begins the process of
|
|
227
|
+
* Dependency Injection and instantiates the classes needed to launch your
|
|
228
|
+
* application.
|
|
229
|
+
*
|
|
230
|
+
* @publicApi
|
|
231
|
+
*/
|
|
232
|
+
exports.NestFactory = new NestFactoryStatic();
|