@nestjs/core 11.1.15 → 12.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/http-adapter.d.ts +5 -3
- package/adapters/http-adapter.js +8 -5
- package/adapters/index.d.ts +1 -1
- package/adapters/index.js +1 -4
- package/application-config.d.ts +7 -4
- package/application-config.js +20 -15
- package/constants.d.ts +1 -1
- package/constants.js +10 -13
- package/discovery/discoverable-meta-host-collection.d.ts +3 -3
- package/discovery/discoverable-meta-host-collection.js +15 -19
- package/discovery/discovery-module.js +9 -12
- package/discovery/discovery-service.d.ts +4 -4
- package/discovery/discovery-service.js +17 -19
- package/discovery/index.d.ts +2 -2
- package/discovery/index.js +2 -5
- package/errors/exception-handler.js +3 -7
- package/errors/exceptions/circular-dependency.exception.d.ts +1 -1
- package/errors/exceptions/circular-dependency.exception.js +2 -6
- package/errors/exceptions/index.d.ts +8 -8
- package/errors/exceptions/index.js +8 -11
- package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class-module.exception.js +4 -8
- package/errors/exceptions/invalid-class-scope.exception.d.ts +2 -2
- package/errors/exceptions/invalid-class-scope.exception.js +6 -10
- package/errors/exceptions/invalid-class.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class.exception.js +4 -8
- package/errors/exceptions/invalid-exception-filter.exception.d.ts +1 -1
- package/errors/exceptions/invalid-exception-filter.exception.js +4 -8
- package/errors/exceptions/invalid-middleware-configuration.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware-configuration.exception.js +4 -8
- package/errors/exceptions/invalid-middleware.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware.exception.js +4 -8
- package/errors/exceptions/invalid-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-module.exception.js +4 -8
- package/errors/exceptions/runtime.exception.js +1 -5
- package/errors/exceptions/undefined-dependency.exception.d.ts +3 -3
- package/errors/exceptions/undefined-dependency.exception.js +4 -8
- package/errors/exceptions/undefined-forwardref.exception.d.ts +2 -2
- package/errors/exceptions/undefined-forwardref.exception.js +4 -8
- package/errors/exceptions/undefined-module.exception.d.ts +1 -1
- package/errors/exceptions/undefined-module.exception.js +4 -8
- package/errors/exceptions/unknown-dependencies.exception.d.ts +3 -3
- package/errors/exceptions/unknown-dependencies.exception.js +8 -8
- package/errors/exceptions/unknown-element.exception.d.ts +1 -1
- package/errors/exceptions/unknown-element.exception.js +2 -6
- package/errors/exceptions/unknown-export.exception.d.ts +1 -1
- package/errors/exceptions/unknown-export.exception.js +4 -8
- package/errors/exceptions/unknown-module.exception.d.ts +1 -1
- package/errors/exceptions/unknown-module.exception.js +2 -6
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +1 -1
- package/errors/exceptions/unknown-request-mapping.exception.js +4 -8
- package/errors/exceptions-zone.js +6 -10
- package/errors/messages.d.ts +2 -2
- package/errors/messages.js +19 -32
- package/exceptions/base-exception-filter-context.d.ts +6 -7
- package/exceptions/base-exception-filter-context.js +13 -16
- package/exceptions/base-exception-filter.d.ts +4 -4
- package/exceptions/base-exception-filter.js +33 -23
- package/exceptions/exceptions-handler.d.ts +4 -4
- package/exceptions/exceptions-handler.js +8 -16
- package/exceptions/external-exception-filter-context.d.ts +8 -8
- package/exceptions/external-exception-filter-context.js +14 -18
- package/exceptions/external-exception-filter.d.ts +1 -1
- package/exceptions/external-exception-filter.js +4 -8
- package/exceptions/external-exceptions-handler.d.ts +3 -3
- package/exceptions/external-exceptions-handler.js +8 -16
- package/exceptions/index.d.ts +1 -1
- package/exceptions/index.js +1 -4
- package/guards/constants.js +1 -4
- package/guards/guards-consumer.d.ts +4 -3
- package/guards/guards-consumer.js +8 -12
- package/guards/guards-context-creator.d.ts +11 -10
- package/guards/guards-context-creator.js +18 -20
- package/guards/index.d.ts +3 -3
- package/guards/index.js +3 -6
- package/helpers/barrier.js +5 -5
- package/helpers/context-creator.d.ts +2 -2
- package/helpers/context-creator.js +3 -7
- package/helpers/context-id-factory.d.ts +1 -1
- package/helpers/context-id-factory.js +10 -14
- package/helpers/context-utils.d.ts +6 -3
- package/helpers/context-utils.js +7 -12
- package/helpers/execution-context-host.d.ts +3 -3
- package/helpers/execution-context-host.js +5 -6
- package/helpers/external-context-creator.d.ts +15 -18
- package/helpers/external-context-creator.js +54 -43
- package/helpers/external-proxy.d.ts +2 -2
- package/helpers/external-proxy.js +3 -7
- package/helpers/get-class-scope.d.ts +2 -2
- package/helpers/get-class-scope.js +3 -6
- package/helpers/handler-metadata-storage.d.ts +4 -4
- package/helpers/handler-metadata-storage.js +7 -15
- package/helpers/http-adapter-host.d.ts +1 -1
- package/helpers/http-adapter-host.js +6 -11
- package/helpers/index.d.ts +3 -3
- package/helpers/index.js +3 -6
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +2 -2
- package/helpers/interfaces/external-handler-metadata.interface.js +1 -2
- package/helpers/interfaces/index.d.ts +2 -2
- package/helpers/interfaces/index.js +2 -5
- package/helpers/interfaces/params-metadata.interface.d.ts +1 -1
- package/helpers/interfaces/params-metadata.interface.js +1 -2
- package/helpers/is-durable.d.ts +1 -1
- package/helpers/is-durable.js +3 -6
- package/helpers/load-adapter.d.ts +1 -1
- package/helpers/load-adapter.js +4 -7
- package/helpers/messages.d.ts +1 -1
- package/helpers/messages.js +10 -20
- package/helpers/optional-require.d.ts +1 -1
- package/helpers/optional-require.js +2 -5
- package/helpers/rethrow.js +1 -5
- package/helpers/router-method-factory.d.ts +2 -2
- package/helpers/router-method-factory.js +20 -24
- package/hooks/before-app-shutdown.hook.d.ts +3 -3
- package/hooks/before-app-shutdown.hook.js +15 -22
- package/hooks/index.d.ts +5 -5
- package/hooks/index.js +5 -8
- package/hooks/on-app-bootstrap.hook.d.ts +3 -3
- package/hooks/on-app-bootstrap.hook.js +15 -22
- package/hooks/on-app-shutdown.hook.d.ts +3 -3
- package/hooks/on-app-shutdown.hook.js +15 -22
- package/hooks/on-module-destroy.hook.d.ts +3 -3
- package/hooks/on-module-destroy.hook.js +15 -22
- package/hooks/on-module-init.hook.d.ts +3 -3
- package/hooks/on-module-init.hook.js +15 -22
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.d.ts +3 -0
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.js +27 -0
- package/hooks/utils/get-sorted-hierarchy-levels.d.ts +1 -0
- package/hooks/utils/get-sorted-hierarchy-levels.js +7 -0
- package/index.d.ts +16 -16
- package/index.js +17 -26
- package/injector/abstract-instance-resolver.d.ts +6 -6
- package/injector/abstract-instance-resolver.js +7 -11
- package/injector/compiler.d.ts +2 -2
- package/injector/compiler.js +2 -5
- package/injector/constants.d.ts +1 -1
- package/injector/constants.js +2 -5
- package/injector/container.d.ts +13 -14
- package/injector/container.js +40 -40
- package/injector/helpers/provider-classifier.d.ts +1 -1
- package/injector/helpers/provider-classifier.js +5 -10
- package/injector/helpers/silent-logger.js +9 -16
- package/injector/index.d.ts +6 -6
- package/injector/index.js +5 -8
- package/injector/injector.d.ts +7 -6
- package/injector/injector.js +78 -78
- package/injector/inquirer/index.d.ts +1 -1
- package/injector/inquirer/index.js +1 -4
- package/injector/inquirer/inquirer-constants.js +1 -4
- package/injector/inquirer/inquirer-providers.d.ts +1 -1
- package/injector/inquirer/inquirer-providers.js +5 -8
- package/injector/instance-links-host.d.ts +3 -3
- package/injector/instance-links-host.js +8 -11
- package/injector/instance-loader.d.ts +5 -5
- package/injector/instance-loader.js +11 -11
- package/injector/instance-wrapper.d.ts +8 -5
- package/injector/instance-wrapper.js +93 -74
- package/injector/internal-core-module/index.d.ts +1 -1
- package/injector/internal-core-module/index.js +1 -4
- package/injector/internal-core-module/internal-core-module-factory.d.ts +6 -6
- package/injector/internal-core-module/internal-core-module-factory.js +23 -27
- package/injector/internal-core-module/internal-core-module.d.ts +2 -2
- package/injector/internal-core-module/internal-core-module.js +17 -20
- package/injector/internal-providers-storage.d.ts +2 -2
- package/injector/internal-providers-storage.js +4 -9
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +1 -2
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +8 -8
- package/injector/lazy-module-loader/lazy-module-loader.js +10 -9
- package/injector/module-ref.d.ts +7 -7
- package/injector/module-ref.js +19 -20
- package/injector/module.d.ts +5 -5
- package/injector/module.js +93 -79
- package/injector/modules-container.d.ts +1 -1
- package/injector/modules-container.js +5 -12
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +2 -4
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +6 -9
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +2 -3
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +17 -22
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +1 -3
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +1 -2
- package/injector/settlement-signal.js +5 -7
- package/injector/topology-tree/topology-tree.d.ts +1 -1
- package/injector/topology-tree/topology-tree.js +6 -9
- package/injector/topology-tree/tree-node.js +4 -6
- package/inspector/deterministic-uuid-registry.js +2 -6
- package/inspector/graph-inspector.d.ts +7 -7
- package/inspector/graph-inspector.js +10 -12
- package/inspector/index.d.ts +4 -4
- package/inspector/index.js +4 -7
- package/inspector/initialize-on-preview.allowlist.d.ts +1 -1
- package/inspector/initialize-on-preview.allowlist.js +2 -6
- package/inspector/interfaces/edge.interface.d.ts +1 -1
- package/inspector/interfaces/edge.interface.js +1 -2
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +3 -3
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +1 -2
- package/inspector/interfaces/entrypoint.interface.d.ts +2 -2
- package/inspector/interfaces/entrypoint.interface.js +1 -2
- package/inspector/interfaces/extras.interface.d.ts +1 -1
- package/inspector/interfaces/extras.interface.js +1 -2
- package/inspector/interfaces/node.interface.d.ts +2 -2
- package/inspector/interfaces/node.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +6 -6
- package/inspector/interfaces/serialized-graph-json.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +1 -1
- package/inspector/interfaces/serialized-graph-metadata.interface.js +1 -2
- package/inspector/noop-graph-inspector.d.ts +1 -1
- package/inspector/noop-graph-inspector.js +2 -5
- package/inspector/partial-graph.host.d.ts +2 -2
- package/inspector/partial-graph.host.js +2 -5
- package/inspector/serialized-graph.d.ts +7 -7
- package/inspector/serialized-graph.js +35 -40
- package/inspector/uuid-factory.js +8 -12
- package/interceptors/index.d.ts +2 -2
- package/interceptors/index.js +2 -5
- package/interceptors/interceptors-consumer.d.ts +4 -3
- package/interceptors/interceptors-consumer.js +13 -17
- package/interceptors/interceptors-context-creator.d.ts +10 -9
- package/interceptors/interceptors-context-creator.js +18 -20
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/module-definition.interface.d.ts +2 -2
- package/interfaces/module-definition.interface.js +1 -2
- package/interfaces/module-override.interface.d.ts +1 -1
- package/interfaces/module-override.interface.js +1 -2
- package/internal.d.ts +38 -0
- package/internal.js +46 -0
- package/metadata-scanner.d.ts +1 -1
- package/metadata-scanner.js +8 -14
- package/middleware/builder.d.ts +4 -4
- package/middleware/builder.js +78 -76
- package/middleware/container.d.ts +4 -4
- package/middleware/container.js +10 -13
- package/middleware/index.d.ts +1 -1
- package/middleware/index.js +1 -4
- package/middleware/middleware-module.d.ts +8 -9
- package/middleware/middleware-module.js +47 -44
- package/middleware/resolver.d.ts +3 -3
- package/middleware/resolver.js +3 -5
- package/middleware/route-info-path-extractor.d.ts +2 -2
- package/middleware/route-info-path-extractor.js +26 -25
- package/middleware/routes-mapper.d.ts +4 -3
- package/middleware/routes-mapper.js +22 -24
- package/middleware/utils.d.ts +3 -2
- package/middleware/utils.js +34 -45
- package/nest-application-context.d.ts +10 -9
- package/nest-application-context.js +50 -47
- package/nest-application.d.ts +18 -10
- package/nest-application.js +87 -55
- package/nest-factory.d.ts +4 -5
- package/nest-factory.js +61 -68
- package/package.json +32 -3
- package/pipes/index.d.ts +3 -3
- package/pipes/index.js +3 -6
- package/pipes/params-token-factory.d.ts +2 -2
- package/pipes/params-token-factory.js +5 -9
- package/pipes/pipes-consumer.d.ts +3 -7
- package/pipes/pipes-consumer.js +17 -18
- package/pipes/pipes-context-creator.d.ts +10 -9
- package/pipes/pipes-context-creator.js +18 -20
- package/repl/assign-to-object.util.js +1 -4
- package/repl/constants.js +1 -4
- package/repl/index.d.ts +1 -1
- package/repl/index.js +1 -4
- package/repl/native-functions/debug-repl-fn.d.ts +2 -2
- package/repl/native-functions/debug-repl-fn.js +14 -21
- package/repl/native-functions/get-repl-fn.d.ts +2 -2
- package/repl/native-functions/get-repl-fn.js +8 -15
- package/repl/native-functions/help-repl-fn.d.ts +2 -2
- package/repl/native-functions/help-repl-fn.js +13 -20
- package/repl/native-functions/index.d.ts +6 -6
- package/repl/native-functions/index.js +6 -9
- package/repl/native-functions/methods-repl-fn.d.ts +2 -2
- package/repl/native-functions/methods-repl-fn.js +12 -19
- package/repl/native-functions/resolve-repl-fn.d.ts +2 -2
- package/repl/native-functions/resolve-repl-fn.js +7 -14
- package/repl/native-functions/select-relp-fn.d.ts +2 -2
- package/repl/native-functions/select-relp-fn.js +7 -14
- package/repl/repl-context.d.ts +3 -3
- package/repl/repl-context.js +21 -23
- package/repl/repl-function.d.ts +3 -3
- package/repl/repl-function.js +5 -7
- package/repl/repl-logger.js +10 -14
- package/repl/repl-native-commands.js +1 -4
- package/repl/repl.d.ts +1 -1
- package/repl/repl.interfaces.d.ts +2 -2
- package/repl/repl.interfaces.js +1 -2
- package/repl/repl.js +17 -20
- package/router/index.d.ts +3 -3
- package/router/index.js +3 -8
- package/router/interfaces/exceptions-filter.interface.d.ts +3 -3
- package/router/interfaces/exceptions-filter.interface.js +1 -2
- package/router/interfaces/exclude-route-metadata.interface.d.ts +1 -1
- package/router/interfaces/exclude-route-metadata.interface.js +1 -2
- package/router/interfaces/index.d.ts +1 -1
- package/router/interfaces/index.js +1 -4
- package/router/interfaces/resolver.interface.js +1 -2
- package/router/interfaces/route-params-factory.interface.d.ts +1 -1
- package/router/interfaces/route-params-factory.interface.js +1 -2
- package/router/interfaces/route-path-metadata.interface.d.ts +2 -2
- package/router/interfaces/route-path-metadata.interface.js +1 -2
- package/router/interfaces/routes.interface.d.ts +1 -1
- package/router/interfaces/routes.interface.js +1 -2
- package/router/legacy-route-converter.js +3 -7
- package/router/paths-explorer.d.ts +4 -5
- package/router/paths-explorer.js +11 -15
- package/router/request/index.d.ts +1 -1
- package/router/request/index.js +1 -5
- package/router/request/request-constants.js +2 -5
- package/router/request/request-providers.d.ts +1 -1
- package/router/request/request-providers.js +5 -8
- package/router/route-params-factory.d.ts +2 -2
- package/router/route-params-factory.js +15 -19
- package/router/route-path-factory.d.ts +4 -4
- package/router/route-path-factory.js +19 -22
- package/router/router-exception-filters.d.ts +9 -9
- package/router/router-exception-filters.js +15 -18
- package/router/router-execution-context.d.ts +17 -20
- package/router/router-execution-context.js +57 -49
- package/router/router-explorer.d.ts +14 -16
- package/router/router-explorer.js +55 -54
- package/router/router-module.d.ts +4 -4
- package/router/router-module.js +21 -23
- package/router/router-proxy.d.ts +1 -1
- package/router/router-proxy.js +4 -8
- package/router/router-response-controller.d.ts +2 -2
- package/router/router-response-controller.js +20 -23
- package/router/routes-resolver.d.ts +8 -9
- package/router/routes-resolver.js +36 -51
- package/router/sse-stream.d.ts +1 -1
- package/router/sse-stream.js +5 -9
- package/router/utils/exclude-route.util.d.ts +1 -1
- package/router/utils/exclude-route.util.js +7 -12
- package/router/utils/flatten-route-paths.util.d.ts +2 -2
- package/router/utils/flatten-route-paths.util.js +4 -7
- package/router/utils/index.d.ts +2 -2
- package/router/utils/index.js +2 -5
- package/scanner.d.ts +11 -11
- package/scanner.js +64 -65
- package/services/index.d.ts +1 -1
- package/services/index.js +1 -4
- package/services/reflector.service.d.ts +1 -1
- package/services/reflector.service.js +9 -13
- package/tsconfig.build.json +1 -9
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const abstract_instance_resolver_1 = require("./injector/abstract-instance-resolver");
|
|
12
|
-
const injector_1 = require("./injector/injector");
|
|
13
|
-
const instance_links_host_1 = require("./injector/instance-links-host");
|
|
1
|
+
import { Logger, ShutdownSignal, } from '@nestjs/common';
|
|
2
|
+
import { iterate } from 'iterare';
|
|
3
|
+
import { MESSAGES } from './constants.js';
|
|
4
|
+
import { UnknownModuleException } from './errors/exceptions/index.js';
|
|
5
|
+
import { createContextId } from './helpers/context-id-factory.js';
|
|
6
|
+
import { callAppShutdownHook, callBeforeAppShutdownHook, callModuleBootstrapHook, callModuleDestroyHook, callModuleInitHook, } from './hooks/index.js';
|
|
7
|
+
import { AbstractInstanceResolver } from './injector/abstract-instance-resolver.js';
|
|
8
|
+
import { Injector } from './injector/injector.js';
|
|
9
|
+
import { InstanceLinksHost } from './injector/instance-links-host.js';
|
|
10
|
+
import { isEmptyArray, } from '@nestjs/common/internal';
|
|
14
11
|
/**
|
|
15
12
|
* @publicApi
|
|
16
13
|
*/
|
|
17
|
-
class NestApplicationContext extends
|
|
14
|
+
export class NestApplicationContext extends AbstractInstanceResolver {
|
|
15
|
+
container;
|
|
16
|
+
appOptions;
|
|
17
|
+
contextModule;
|
|
18
|
+
scope;
|
|
19
|
+
isInitialized = false;
|
|
20
|
+
injector;
|
|
21
|
+
logger = new Logger(NestApplicationContext.name, {
|
|
22
|
+
timestamp: true,
|
|
23
|
+
});
|
|
24
|
+
shouldFlushLogsOnOverride = false;
|
|
25
|
+
activeShutdownSignals = new Array();
|
|
26
|
+
moduleCompiler;
|
|
27
|
+
shutdownCleanupRef;
|
|
28
|
+
_instanceLinksHost;
|
|
29
|
+
_moduleRefsForHooksByDistance;
|
|
30
|
+
initializationPromise;
|
|
18
31
|
get instanceLinksHost() {
|
|
19
32
|
if (!this._instanceLinksHost) {
|
|
20
|
-
this._instanceLinksHost = new
|
|
33
|
+
this._instanceLinksHost = new InstanceLinksHost(this.container);
|
|
21
34
|
}
|
|
22
35
|
return this._instanceLinksHost;
|
|
23
36
|
}
|
|
@@ -27,13 +40,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
27
40
|
this.appOptions = appOptions;
|
|
28
41
|
this.contextModule = contextModule;
|
|
29
42
|
this.scope = scope;
|
|
30
|
-
this.
|
|
31
|
-
this.logger = new common_1.Logger(NestApplicationContext.name, {
|
|
32
|
-
timestamp: true,
|
|
33
|
-
});
|
|
34
|
-
this.shouldFlushLogsOnOverride = false;
|
|
35
|
-
this.activeShutdownSignals = new Array();
|
|
36
|
-
this.injector = new injector_1.Injector();
|
|
43
|
+
this.injector = new Injector();
|
|
37
44
|
this.moduleCompiler = container.getModuleCompiler();
|
|
38
45
|
if (this.appOptions.preview) {
|
|
39
46
|
this.printInPreviewModeWarning();
|
|
@@ -58,7 +65,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
58
65
|
: moduleTokenFactory.createForStatic(type, moduleType);
|
|
59
66
|
const selectedModule = modulesContainer.get(token);
|
|
60
67
|
if (!selectedModule) {
|
|
61
|
-
throw new
|
|
68
|
+
throw new UnknownModuleException(type.name);
|
|
62
69
|
}
|
|
63
70
|
const options = typeof selectOptions?.abortOnError !== 'undefined'
|
|
64
71
|
? {
|
|
@@ -84,7 +91,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
84
91
|
* Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
85
92
|
* @returns {Promise<TResult | Array<TResult>>}
|
|
86
93
|
*/
|
|
87
|
-
resolve(typeOrToken, contextId =
|
|
94
|
+
resolve(typeOrToken, contextId = createContextId(), options = { strict: false }) {
|
|
88
95
|
return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
|
|
89
96
|
}
|
|
90
97
|
/**
|
|
@@ -104,17 +111,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
104
111
|
if (this.isInitialized) {
|
|
105
112
|
return this;
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
this.initializationPromise = new Promise(async (resolve, reject) => {
|
|
109
|
-
try {
|
|
110
|
-
await this.callInitHook();
|
|
111
|
-
await this.callBootstrapHook();
|
|
112
|
-
resolve();
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
reject(err);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
114
|
+
this.initializationPromise = this.callInitHook().then(() => this.callBootstrapHook());
|
|
118
115
|
await this.initializationPromise;
|
|
119
116
|
this.isInitialized = true;
|
|
120
117
|
return this;
|
|
@@ -125,6 +122,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
125
122
|
*/
|
|
126
123
|
async close(signal) {
|
|
127
124
|
await this.initializationPromise;
|
|
125
|
+
await this.prepareClose();
|
|
128
126
|
await this.callDestroyHook();
|
|
129
127
|
await this.callBeforeShutdownHook(signal);
|
|
130
128
|
await this.dispose();
|
|
@@ -137,7 +135,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
137
135
|
* @returns {void}
|
|
138
136
|
*/
|
|
139
137
|
useLogger(logger) {
|
|
140
|
-
|
|
138
|
+
Logger.overrideLogger(logger);
|
|
141
139
|
if (this.shouldFlushLogsOnOverride) {
|
|
142
140
|
this.flushLogs();
|
|
143
141
|
}
|
|
@@ -147,7 +145,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
147
145
|
* @returns {void}
|
|
148
146
|
*/
|
|
149
147
|
flushLogs() {
|
|
150
|
-
|
|
148
|
+
Logger.flush();
|
|
151
149
|
}
|
|
152
150
|
/**
|
|
153
151
|
* Define that it must flush logs right after defining a custom logger.
|
|
@@ -166,15 +164,15 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
166
164
|
* @returns {this} The Nest application context instance
|
|
167
165
|
*/
|
|
168
166
|
enableShutdownHooks(signals = [], options = {}) {
|
|
169
|
-
if ((
|
|
170
|
-
signals = Object.
|
|
167
|
+
if (isEmptyArray(signals)) {
|
|
168
|
+
signals = Object.values(ShutdownSignal);
|
|
171
169
|
}
|
|
172
170
|
else {
|
|
173
171
|
// given signals array should be unique because
|
|
174
172
|
// process shouldn't listen to the same signal more than once.
|
|
175
173
|
signals = Array.from(new Set(signals));
|
|
176
174
|
}
|
|
177
|
-
signals =
|
|
175
|
+
signals = iterate(signals)
|
|
178
176
|
.map((signal) => signal.toString().toUpperCase().trim())
|
|
179
177
|
// filter out the signals which is already listening to
|
|
180
178
|
.filter(signal => !this.activeShutdownSignals.includes(signal))
|
|
@@ -182,6 +180,11 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
182
180
|
this.listenToShutdownSignals(signals, options);
|
|
183
181
|
return this;
|
|
184
182
|
}
|
|
183
|
+
async prepareClose() {
|
|
184
|
+
// Nest application context has no server
|
|
185
|
+
// to signal, therefore just call a noop
|
|
186
|
+
return Promise.resolve();
|
|
187
|
+
}
|
|
185
188
|
async dispose() {
|
|
186
189
|
// Nest application context has no server
|
|
187
190
|
// to dispose, therefore just call a noop
|
|
@@ -205,6 +208,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
205
208
|
}
|
|
206
209
|
receivedSignal = true;
|
|
207
210
|
await this.initializationPromise;
|
|
211
|
+
await this.prepareClose();
|
|
208
212
|
await this.callDestroyHook();
|
|
209
213
|
await this.callBeforeShutdownHook(signal);
|
|
210
214
|
await this.dispose();
|
|
@@ -221,7 +225,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
catch (err) {
|
|
224
|
-
|
|
228
|
+
Logger.error(MESSAGES.ERROR_DURING_SHUTDOWN, err?.stack, NestApplicationContext.name);
|
|
225
229
|
process.exit(1);
|
|
226
230
|
}
|
|
227
231
|
};
|
|
@@ -249,7 +253,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
249
253
|
async callInitHook() {
|
|
250
254
|
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
251
255
|
for (const module of modulesSortedByDistance) {
|
|
252
|
-
await
|
|
256
|
+
await callModuleInitHook(module);
|
|
253
257
|
}
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
@@ -261,7 +265,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
261
265
|
...this.getModulesToTriggerHooksOn(),
|
|
262
266
|
].reverse();
|
|
263
267
|
for (const module of modulesSortedByDistance) {
|
|
264
|
-
await
|
|
268
|
+
await callModuleDestroyHook(module);
|
|
265
269
|
}
|
|
266
270
|
}
|
|
267
271
|
/**
|
|
@@ -271,7 +275,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
271
275
|
async callBootstrapHook() {
|
|
272
276
|
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
273
277
|
for (const module of modulesSortedByDistance) {
|
|
274
|
-
await
|
|
278
|
+
await callModuleBootstrapHook(module);
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
281
|
/**
|
|
@@ -283,7 +287,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
283
287
|
...this.getModulesToTriggerHooksOn(),
|
|
284
288
|
].reverse();
|
|
285
289
|
for (const module of modulesSortedByDistance) {
|
|
286
|
-
await
|
|
290
|
+
await callAppShutdownHook(module, signal);
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
293
|
/**
|
|
@@ -295,7 +299,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
295
299
|
...this.getModulesToTriggerHooksOn(),
|
|
296
300
|
].reverse();
|
|
297
301
|
for (const module of modulesSortedByDistance) {
|
|
298
|
-
await
|
|
302
|
+
await callBeforeAppShutdownHook(module, signal);
|
|
299
303
|
}
|
|
300
304
|
}
|
|
301
305
|
assertNotInPreviewMode(methodName) {
|
|
@@ -324,4 +328,3 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
324
328
|
this.logger.warn('------------------------------------------------');
|
|
325
329
|
}
|
|
326
330
|
}
|
|
327
|
-
exports.NestApplicationContext = NestApplicationContext;
|
package/nest-application.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CanActivate, ExceptionFilter, HttpServer, INestApplication, INestMicroservice, NestHybridApplicationOptions, NestInterceptor, PipeTransform, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { type CanActivate, type ExceptionFilter, type HttpServer, type INestApplication, type INestMicroservice, type NestHybridApplicationOptions, type NestInterceptor, type PipeTransform, type VersioningOptions, type WebSocketAdapter } from '@nestjs/common';
|
|
2
|
+
import { AbstractHttpAdapter } from './adapters/index.js';
|
|
3
|
+
import { ApplicationConfig } from './application-config.js';
|
|
4
|
+
import { NestContainer } from './injector/container.js';
|
|
5
|
+
import { GraphInspector } from './inspector/graph-inspector.js';
|
|
6
|
+
import { NestApplicationContext } from './nest-application-context.js';
|
|
7
|
+
import { type NestApplicationOptions, Logger } from '@nestjs/common';
|
|
8
|
+
import { type GlobalPrefixOptions } from '@nestjs/common/internal';
|
|
9
9
|
/**
|
|
10
10
|
* @publicApi
|
|
11
11
|
*/
|
|
@@ -16,13 +16,14 @@ export declare class NestApplication extends NestApplicationContext<NestApplicat
|
|
|
16
16
|
protected readonly logger: Logger;
|
|
17
17
|
private readonly middlewareModule;
|
|
18
18
|
private readonly middlewareContainer;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
19
|
+
private microservicesModule;
|
|
20
|
+
private socketModule;
|
|
21
21
|
private readonly routesResolver;
|
|
22
22
|
private readonly microservices;
|
|
23
23
|
private httpServer;
|
|
24
24
|
private isListening;
|
|
25
25
|
constructor(container: NestContainer, httpAdapter: HttpServer, config: ApplicationConfig, graphInspector: GraphInspector, appOptions?: NestApplicationOptions);
|
|
26
|
+
protected prepareClose(): Promise<void>;
|
|
26
27
|
protected dispose(): Promise<void>;
|
|
27
28
|
getHttpAdapter(): AbstractHttpAdapter;
|
|
28
29
|
registerHttpServer(): void;
|
|
@@ -57,8 +58,15 @@ export declare class NestApplication extends NestApplicationContext<NestApplicat
|
|
|
57
58
|
useStaticAssets(path: string, options?: any): this;
|
|
58
59
|
setBaseViewsDir(path: string | string[]): this;
|
|
59
60
|
setViewEngine(engineOrOptions: any): this;
|
|
61
|
+
/**
|
|
62
|
+
* Pre-load optional packages so that createNestApplication,
|
|
63
|
+
* createNestMicroservice and createHttpAdapter can stay synchronous.
|
|
64
|
+
*/
|
|
65
|
+
preloadLazyPackages(): Promise<void>;
|
|
60
66
|
private host;
|
|
61
67
|
private getProtocol;
|
|
62
68
|
private registerMiddleware;
|
|
63
69
|
private applyInstanceDecoratorIfRegistered;
|
|
70
|
+
private loadSocketModule;
|
|
71
|
+
private loadMicroservicesModule;
|
|
64
72
|
}
|
package/nest-application.js
CHANGED
|
@@ -1,54 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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'));
|
|
1
|
+
import { VersioningType, } from '@nestjs/common';
|
|
2
|
+
import { iterate } from 'iterare';
|
|
3
|
+
import { platform } from 'os';
|
|
4
|
+
import { ApplicationConfig } from './application-config.js';
|
|
5
|
+
import { MESSAGES } from './constants.js';
|
|
6
|
+
import { optionalRequire } from './helpers/optional-require.js';
|
|
7
|
+
import { Injector } from './injector/injector.js';
|
|
8
|
+
import { MiddlewareContainer } from './middleware/container.js';
|
|
9
|
+
import { MiddlewareModule } from './middleware/middleware-module.js';
|
|
10
|
+
import { mapToExcludeRoute } from './middleware/utils.js';
|
|
11
|
+
import { NestApplicationContext } from './nest-application-context.js';
|
|
12
|
+
import { RoutesResolver } from './router/routes-resolver.js';
|
|
13
|
+
import { Logger } from '@nestjs/common';
|
|
14
|
+
import { loadPackage, loadPackageCached, addLeadingSlash, isFunction, isObject, isString, } from '@nestjs/common/internal';
|
|
21
15
|
/**
|
|
22
16
|
* @publicApi
|
|
23
17
|
*/
|
|
24
|
-
class NestApplication extends
|
|
18
|
+
export class NestApplication extends NestApplicationContext {
|
|
19
|
+
httpAdapter;
|
|
20
|
+
config;
|
|
21
|
+
graphInspector;
|
|
22
|
+
logger = new Logger(NestApplication.name, {
|
|
23
|
+
timestamp: true,
|
|
24
|
+
});
|
|
25
|
+
middlewareModule;
|
|
26
|
+
middlewareContainer = new MiddlewareContainer(this.container);
|
|
27
|
+
microservicesModule = null;
|
|
28
|
+
socketModule = null;
|
|
29
|
+
routesResolver;
|
|
30
|
+
microservices = [];
|
|
31
|
+
httpServer;
|
|
32
|
+
isListening = false;
|
|
25
33
|
constructor(container, httpAdapter, config, graphInspector, appOptions = {}) {
|
|
26
34
|
super(container, appOptions);
|
|
27
35
|
this.httpAdapter = httpAdapter;
|
|
28
36
|
this.config = config;
|
|
29
37
|
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
38
|
this.selectContextModule();
|
|
39
39
|
this.registerHttpServer();
|
|
40
|
-
this.injector = new
|
|
40
|
+
this.injector = new Injector({
|
|
41
41
|
preview: this.appOptions.preview,
|
|
42
42
|
instanceDecorator: appOptions.instrument?.instanceDecorator,
|
|
43
43
|
});
|
|
44
|
-
this.middlewareModule = new
|
|
45
|
-
this.routesResolver = new
|
|
44
|
+
this.middlewareModule = new MiddlewareModule();
|
|
45
|
+
this.routesResolver = new RoutesResolver(this.container, this.config, this.injector, this.graphInspector);
|
|
46
|
+
}
|
|
47
|
+
async prepareClose() {
|
|
48
|
+
this.httpAdapter && (await this.httpAdapter.beforeClose?.());
|
|
46
49
|
}
|
|
47
50
|
async dispose() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
await Promise.all(
|
|
51
|
+
await this.socketModule?.close();
|
|
52
|
+
await this.microservicesModule?.close();
|
|
53
|
+
await this.httpAdapter?.close();
|
|
54
|
+
await Promise.all(iterate(this.microservices).map(async (microservice) => {
|
|
52
55
|
microservice.setIsTerminated(true);
|
|
53
56
|
await microservice.close();
|
|
54
57
|
}));
|
|
@@ -66,7 +69,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
66
69
|
if (!this.appOptions || !this.appOptions.cors) {
|
|
67
70
|
return undefined;
|
|
68
71
|
}
|
|
69
|
-
const passCustomOptions =
|
|
72
|
+
const passCustomOptions = isObject(this.appOptions.cors) || isFunction(this.appOptions.cors);
|
|
70
73
|
if (!passCustomOptions) {
|
|
71
74
|
return this.enableCors();
|
|
72
75
|
}
|
|
@@ -94,6 +97,11 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
94
97
|
if (this.isInitialized) {
|
|
95
98
|
return this;
|
|
96
99
|
}
|
|
100
|
+
// Lazy-load optional modules (ESM-compatible)
|
|
101
|
+
await Promise.all([
|
|
102
|
+
this.loadSocketModule(),
|
|
103
|
+
this.loadMicroservicesModule(),
|
|
104
|
+
]);
|
|
97
105
|
this.applyOptions();
|
|
98
106
|
await this.httpAdapter?.init?.();
|
|
99
107
|
const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
|
|
@@ -104,7 +112,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
104
112
|
await this.registerRouterHooks();
|
|
105
113
|
await this.callBootstrapHook();
|
|
106
114
|
this.isInitialized = true;
|
|
107
|
-
this.logger.log(
|
|
115
|
+
this.logger.log(MESSAGES.APPLICATION_READY);
|
|
108
116
|
return this;
|
|
109
117
|
}
|
|
110
118
|
registerParserMiddleware() {
|
|
@@ -115,7 +123,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
115
123
|
async registerRouter() {
|
|
116
124
|
await this.registerMiddleware(this.httpAdapter);
|
|
117
125
|
const prefix = this.config.getGlobalPrefix();
|
|
118
|
-
const basePath =
|
|
126
|
+
const basePath = addLeadingSlash(prefix);
|
|
119
127
|
this.routesResolver.resolve(this.httpAdapter, basePath);
|
|
120
128
|
}
|
|
121
129
|
async registerRouterHooks() {
|
|
@@ -123,11 +131,11 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
123
131
|
this.routesResolver.registerExceptionHandler();
|
|
124
132
|
}
|
|
125
133
|
connectMicroservice(microserviceOptions, hybridAppOptions = {}) {
|
|
126
|
-
const { NestMicroservice } = (
|
|
134
|
+
const { NestMicroservice } = loadPackageCached('@nestjs/microservices');
|
|
127
135
|
const { inheritAppConfig } = hybridAppOptions;
|
|
128
136
|
const applicationConfig = inheritAppConfig
|
|
129
137
|
? this.config
|
|
130
|
-
: new
|
|
138
|
+
: new ApplicationConfig();
|
|
131
139
|
const instance = new NestMicroservice(this.container, microserviceOptions, this.graphInspector, applicationConfig);
|
|
132
140
|
if (!hybridAppOptions.deferInitialization) {
|
|
133
141
|
instance.registerListeners();
|
|
@@ -165,7 +173,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
165
173
|
enableCors(options) {
|
|
166
174
|
this.httpAdapter.enableCors(options);
|
|
167
175
|
}
|
|
168
|
-
enableVersioning(options = { type:
|
|
176
|
+
enableVersioning(options = { type: VersioningType.URI }) {
|
|
169
177
|
this.config.enableVersioning(options);
|
|
170
178
|
return this;
|
|
171
179
|
}
|
|
@@ -181,7 +189,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
181
189
|
reject(e);
|
|
182
190
|
};
|
|
183
191
|
this.httpServer.once('error', errorHandler);
|
|
184
|
-
const isCallbackInOriginalArgs =
|
|
192
|
+
const isCallbackInOriginalArgs = isFunction(args[args.length - 1]);
|
|
185
193
|
const listenFnArgs = isCallbackInOriginalArgs
|
|
186
194
|
? args.slice(0, args.length - 1)
|
|
187
195
|
: args;
|
|
@@ -208,8 +216,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
208
216
|
async getUrl() {
|
|
209
217
|
return new Promise((resolve, reject) => {
|
|
210
218
|
if (!this.isListening) {
|
|
211
|
-
this.logger.error(
|
|
212
|
-
reject(
|
|
219
|
+
this.logger.error(MESSAGES.CALL_LISTEN_FIRST);
|
|
220
|
+
reject(MESSAGES.CALL_LISTEN_FIRST);
|
|
213
221
|
return;
|
|
214
222
|
}
|
|
215
223
|
const address = this.httpServer.address();
|
|
@@ -217,8 +225,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
217
225
|
});
|
|
218
226
|
}
|
|
219
227
|
formatAddress(address) {
|
|
220
|
-
if (
|
|
221
|
-
if (
|
|
228
|
+
if (isString(address)) {
|
|
229
|
+
if (platform() === 'win32') {
|
|
222
230
|
return address;
|
|
223
231
|
}
|
|
224
232
|
const basePath = encodeURIComponent(address);
|
|
@@ -242,7 +250,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
242
250
|
this.config.setGlobalPrefix(prefix);
|
|
243
251
|
if (options) {
|
|
244
252
|
const exclude = options?.exclude
|
|
245
|
-
?
|
|
253
|
+
? mapToExcludeRoute(options.exclude)
|
|
246
254
|
: [];
|
|
247
255
|
this.config.setGlobalPrefixOptions({
|
|
248
256
|
...options,
|
|
@@ -292,22 +300,29 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
292
300
|
return this;
|
|
293
301
|
}
|
|
294
302
|
useStaticAssets(pathOrOptions, options) {
|
|
295
|
-
this.httpAdapter.useStaticAssets
|
|
296
|
-
this.httpAdapter.useStaticAssets(pathOrOptions, options);
|
|
303
|
+
this.httpAdapter.useStaticAssets?.(pathOrOptions, options);
|
|
297
304
|
return this;
|
|
298
305
|
}
|
|
299
306
|
setBaseViewsDir(path) {
|
|
300
|
-
this.httpAdapter.setBaseViewsDir
|
|
307
|
+
this.httpAdapter.setBaseViewsDir?.(path);
|
|
301
308
|
return this;
|
|
302
309
|
}
|
|
303
310
|
setViewEngine(engineOrOptions) {
|
|
304
|
-
this.httpAdapter.setViewEngine
|
|
305
|
-
this.httpAdapter.setViewEngine(engineOrOptions);
|
|
311
|
+
this.httpAdapter.setViewEngine?.(engineOrOptions);
|
|
306
312
|
return this;
|
|
307
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Pre-load optional packages so that createNestApplication,
|
|
316
|
+
* createNestMicroservice and createHttpAdapter can stay synchronous.
|
|
317
|
+
*/
|
|
318
|
+
async preloadLazyPackages() {
|
|
319
|
+
// Best-effort: silently swallow if packages are not installed
|
|
320
|
+
await loadPackage('@nestjs/platform-express', 'TestingModule', () => import('@nestjs/platform-express')).catch(() => { });
|
|
321
|
+
await loadPackage('@nestjs/microservices', 'TestingModule', () => import('@nestjs/microservices')).catch(() => { });
|
|
322
|
+
}
|
|
308
323
|
host() {
|
|
309
324
|
const address = this.httpServer.address();
|
|
310
|
-
if (
|
|
325
|
+
if (isString(address)) {
|
|
311
326
|
return undefined;
|
|
312
327
|
}
|
|
313
328
|
return address && address.address;
|
|
@@ -324,5 +339,22 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
324
339
|
}
|
|
325
340
|
return instances;
|
|
326
341
|
}
|
|
342
|
+
async loadSocketModule() {
|
|
343
|
+
if (!this.socketModule) {
|
|
344
|
+
const socketModule = await optionalRequire('@nestjs/websockets/socket-module', () => import('@nestjs/websockets/socket-module.js'));
|
|
345
|
+
if (socketModule?.SocketModule) {
|
|
346
|
+
this.socketModule = new socketModule.SocketModule();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
async loadMicroservicesModule() {
|
|
351
|
+
if (!this.microservicesModule) {
|
|
352
|
+
const msModule = await optionalRequire('@nestjs/microservices/microservices-module', () => import('@nestjs/microservices/microservices-module.js'));
|
|
353
|
+
if (msModule?.MicroservicesModule) {
|
|
354
|
+
this.microservicesModule = new msModule.MicroservicesModule();
|
|
355
|
+
// Pre-cache the main barrel so connectMicroservice() can stay synchronous
|
|
356
|
+
await loadPackage('@nestjs/microservices', 'NestFactory', () => import('@nestjs/microservices'));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
327
360
|
}
|
|
328
|
-
exports.NestApplication = NestApplication;
|
package/nest-factory.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, INestMicroservice, Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import { NestApplicationContextOptions } from '@nestjs/common/
|
|
4
|
-
import { NestApplicationOptions } from '@nestjs/common
|
|
5
|
-
import { AbstractHttpAdapter } from './adapters/http-adapter';
|
|
1
|
+
import type { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, INestMicroservice, Type } from '@nestjs/common';
|
|
2
|
+
import { AbstractHttpAdapter } from './adapters/http-adapter.js';
|
|
3
|
+
import { type NestMicroserviceOptions, type NestApplicationContextOptions } from '@nestjs/common/internal';
|
|
4
|
+
import { type NestApplicationOptions } from '@nestjs/common';
|
|
6
5
|
type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
|
|
7
6
|
/**
|
|
8
7
|
* @publicApi
|