@nestjs/core 11.1.16 → 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 +20 -36
- package/exceptions/base-exception-filter-context.d.ts +6 -7
- package/exceptions/base-exception-filter-context.js +13 -16
- package/exceptions/base-exception-filter.d.ts +4 -4
- package/exceptions/base-exception-filter.js +33 -23
- package/exceptions/exceptions-handler.d.ts +4 -4
- package/exceptions/exceptions-handler.js +8 -16
- package/exceptions/external-exception-filter-context.d.ts +8 -8
- package/exceptions/external-exception-filter-context.js +14 -18
- package/exceptions/external-exception-filter.d.ts +1 -1
- package/exceptions/external-exception-filter.js +4 -8
- package/exceptions/external-exceptions-handler.d.ts +3 -3
- package/exceptions/external-exceptions-handler.js +8 -16
- package/exceptions/index.d.ts +1 -1
- package/exceptions/index.js +1 -4
- package/guards/constants.js +1 -4
- package/guards/guards-consumer.d.ts +4 -3
- package/guards/guards-consumer.js +8 -12
- package/guards/guards-context-creator.d.ts +11 -10
- package/guards/guards-context-creator.js +18 -20
- package/guards/index.d.ts +3 -3
- package/guards/index.js +3 -6
- package/helpers/barrier.js +5 -5
- package/helpers/context-creator.d.ts +2 -2
- package/helpers/context-creator.js +3 -7
- package/helpers/context-id-factory.d.ts +1 -1
- package/helpers/context-id-factory.js +10 -14
- package/helpers/context-utils.d.ts +6 -3
- package/helpers/context-utils.js +7 -12
- package/helpers/execution-context-host.d.ts +3 -3
- package/helpers/execution-context-host.js +5 -6
- package/helpers/external-context-creator.d.ts +15 -18
- package/helpers/external-context-creator.js +54 -43
- package/helpers/external-proxy.d.ts +2 -2
- package/helpers/external-proxy.js +3 -7
- package/helpers/get-class-scope.d.ts +2 -2
- package/helpers/get-class-scope.js +3 -6
- package/helpers/handler-metadata-storage.d.ts +4 -4
- package/helpers/handler-metadata-storage.js +7 -15
- package/helpers/http-adapter-host.d.ts +1 -1
- package/helpers/http-adapter-host.js +6 -11
- package/helpers/index.d.ts +3 -3
- package/helpers/index.js +3 -6
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +2 -2
- package/helpers/interfaces/external-handler-metadata.interface.js +1 -2
- package/helpers/interfaces/index.d.ts +2 -2
- package/helpers/interfaces/index.js +2 -5
- package/helpers/interfaces/params-metadata.interface.d.ts +1 -1
- package/helpers/interfaces/params-metadata.interface.js +1 -2
- package/helpers/is-durable.d.ts +1 -1
- package/helpers/is-durable.js +3 -6
- package/helpers/load-adapter.d.ts +1 -1
- package/helpers/load-adapter.js +4 -7
- package/helpers/messages.d.ts +1 -1
- package/helpers/messages.js +10 -20
- package/helpers/optional-require.d.ts +1 -1
- package/helpers/optional-require.js +2 -5
- package/helpers/rethrow.js +1 -5
- package/helpers/router-method-factory.d.ts +2 -2
- package/helpers/router-method-factory.js +20 -24
- package/hooks/before-app-shutdown.hook.d.ts +3 -3
- package/hooks/before-app-shutdown.hook.js +15 -22
- package/hooks/index.d.ts +5 -5
- package/hooks/index.js +5 -8
- package/hooks/on-app-bootstrap.hook.d.ts +3 -3
- package/hooks/on-app-bootstrap.hook.js +15 -22
- package/hooks/on-app-shutdown.hook.d.ts +3 -3
- package/hooks/on-app-shutdown.hook.js +15 -22
- package/hooks/on-module-destroy.hook.d.ts +3 -3
- package/hooks/on-module-destroy.hook.js +15 -22
- package/hooks/on-module-init.hook.d.ts +3 -3
- package/hooks/on-module-init.hook.js +15 -22
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.d.ts +3 -0
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.js +27 -0
- package/hooks/utils/get-sorted-hierarchy-levels.d.ts +1 -0
- package/hooks/utils/get-sorted-hierarchy-levels.js +7 -0
- package/index.d.ts +16 -16
- package/index.js +17 -26
- package/injector/abstract-instance-resolver.d.ts +6 -6
- package/injector/abstract-instance-resolver.js +7 -11
- package/injector/compiler.d.ts +2 -2
- package/injector/compiler.js +2 -5
- package/injector/constants.d.ts +1 -1
- package/injector/constants.js +2 -5
- package/injector/container.d.ts +13 -14
- package/injector/container.js +40 -40
- package/injector/helpers/provider-classifier.d.ts +1 -1
- package/injector/helpers/provider-classifier.js +5 -10
- package/injector/helpers/silent-logger.js +9 -16
- package/injector/index.d.ts +6 -6
- package/injector/index.js +5 -8
- package/injector/injector.d.ts +7 -6
- package/injector/injector.js +78 -78
- package/injector/inquirer/index.d.ts +1 -1
- package/injector/inquirer/index.js +1 -4
- package/injector/inquirer/inquirer-constants.js +1 -4
- package/injector/inquirer/inquirer-providers.d.ts +1 -1
- package/injector/inquirer/inquirer-providers.js +5 -8
- package/injector/instance-links-host.d.ts +3 -3
- package/injector/instance-links-host.js +8 -11
- package/injector/instance-loader.d.ts +5 -5
- package/injector/instance-loader.js +11 -11
- package/injector/instance-wrapper.d.ts +8 -5
- package/injector/instance-wrapper.js +93 -74
- package/injector/internal-core-module/index.d.ts +1 -1
- package/injector/internal-core-module/index.js +1 -4
- package/injector/internal-core-module/internal-core-module-factory.d.ts +6 -6
- package/injector/internal-core-module/internal-core-module-factory.js +23 -27
- package/injector/internal-core-module/internal-core-module.d.ts +2 -2
- package/injector/internal-core-module/internal-core-module.js +17 -20
- package/injector/internal-providers-storage.d.ts +2 -2
- package/injector/internal-providers-storage.js +4 -9
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +1 -2
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +8 -8
- package/injector/lazy-module-loader/lazy-module-loader.js +10 -9
- package/injector/module-ref.d.ts +7 -7
- package/injector/module-ref.js +19 -20
- package/injector/module.d.ts +5 -5
- package/injector/module.js +93 -79
- package/injector/modules-container.d.ts +1 -1
- package/injector/modules-container.js +5 -12
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +2 -4
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +6 -9
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +2 -3
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +17 -22
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +1 -3
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +1 -2
- package/injector/settlement-signal.js +5 -7
- package/injector/topology-tree/topology-tree.d.ts +1 -1
- package/injector/topology-tree/topology-tree.js +6 -9
- package/injector/topology-tree/tree-node.js +4 -6
- package/inspector/deterministic-uuid-registry.js +2 -6
- package/inspector/graph-inspector.d.ts +7 -7
- package/inspector/graph-inspector.js +10 -12
- package/inspector/index.d.ts +4 -4
- package/inspector/index.js +4 -7
- package/inspector/initialize-on-preview.allowlist.d.ts +1 -1
- package/inspector/initialize-on-preview.allowlist.js +2 -6
- package/inspector/interfaces/edge.interface.d.ts +1 -1
- package/inspector/interfaces/edge.interface.js +1 -2
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +3 -3
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +1 -2
- package/inspector/interfaces/entrypoint.interface.d.ts +2 -2
- package/inspector/interfaces/entrypoint.interface.js +1 -2
- package/inspector/interfaces/extras.interface.d.ts +1 -1
- package/inspector/interfaces/extras.interface.js +1 -2
- package/inspector/interfaces/node.interface.d.ts +2 -2
- package/inspector/interfaces/node.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +6 -6
- package/inspector/interfaces/serialized-graph-json.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +1 -1
- package/inspector/interfaces/serialized-graph-metadata.interface.js +1 -2
- package/inspector/noop-graph-inspector.d.ts +1 -1
- package/inspector/noop-graph-inspector.js +2 -5
- package/inspector/partial-graph.host.d.ts +2 -2
- package/inspector/partial-graph.host.js +2 -5
- package/inspector/serialized-graph.d.ts +7 -7
- package/inspector/serialized-graph.js +35 -40
- package/inspector/uuid-factory.js +8 -12
- package/interceptors/index.d.ts +2 -2
- package/interceptors/index.js +2 -5
- package/interceptors/interceptors-consumer.d.ts +4 -3
- package/interceptors/interceptors-consumer.js +13 -17
- package/interceptors/interceptors-context-creator.d.ts +10 -9
- package/interceptors/interceptors-context-creator.js +18 -20
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/module-definition.interface.d.ts +2 -2
- package/interfaces/module-definition.interface.js +1 -2
- package/interfaces/module-override.interface.d.ts +1 -1
- package/interfaces/module-override.interface.js +1 -2
- package/internal.d.ts +38 -0
- package/internal.js +46 -0
- package/metadata-scanner.d.ts +1 -1
- package/metadata-scanner.js +8 -14
- package/middleware/builder.d.ts +4 -4
- package/middleware/builder.js +78 -76
- package/middleware/container.d.ts +4 -4
- package/middleware/container.js +10 -13
- package/middleware/index.d.ts +1 -1
- package/middleware/index.js +1 -4
- package/middleware/middleware-module.d.ts +8 -9
- package/middleware/middleware-module.js +47 -44
- package/middleware/resolver.d.ts +3 -3
- package/middleware/resolver.js +3 -5
- package/middleware/route-info-path-extractor.d.ts +2 -2
- package/middleware/route-info-path-extractor.js +26 -25
- package/middleware/routes-mapper.d.ts +4 -3
- package/middleware/routes-mapper.js +22 -24
- package/middleware/utils.d.ts +3 -2
- package/middleware/utils.js +34 -45
- package/nest-application-context.d.ts +10 -9
- package/nest-application-context.js +50 -47
- package/nest-application.d.ts +18 -10
- package/nest-application.js +87 -55
- package/nest-factory.d.ts +4 -5
- package/nest-factory.js +61 -68
- package/package.json +32 -3
- package/pipes/index.d.ts +3 -3
- package/pipes/index.js +3 -6
- package/pipes/params-token-factory.d.ts +2 -2
- package/pipes/params-token-factory.js +5 -9
- package/pipes/pipes-consumer.d.ts +3 -7
- package/pipes/pipes-consumer.js +17 -18
- package/pipes/pipes-context-creator.d.ts +10 -9
- package/pipes/pipes-context-creator.js +18 -20
- package/repl/assign-to-object.util.js +1 -4
- package/repl/constants.js +1 -4
- package/repl/index.d.ts +1 -1
- package/repl/index.js +1 -4
- package/repl/native-functions/debug-repl-fn.d.ts +2 -2
- package/repl/native-functions/debug-repl-fn.js +14 -21
- package/repl/native-functions/get-repl-fn.d.ts +2 -2
- package/repl/native-functions/get-repl-fn.js +8 -15
- package/repl/native-functions/help-repl-fn.d.ts +2 -2
- package/repl/native-functions/help-repl-fn.js +13 -20
- package/repl/native-functions/index.d.ts +6 -6
- package/repl/native-functions/index.js +6 -9
- package/repl/native-functions/methods-repl-fn.d.ts +2 -2
- package/repl/native-functions/methods-repl-fn.js +12 -19
- package/repl/native-functions/resolve-repl-fn.d.ts +2 -2
- package/repl/native-functions/resolve-repl-fn.js +7 -14
- package/repl/native-functions/select-relp-fn.d.ts +2 -2
- package/repl/native-functions/select-relp-fn.js +7 -14
- package/repl/repl-context.d.ts +3 -3
- package/repl/repl-context.js +21 -23
- package/repl/repl-function.d.ts +3 -3
- package/repl/repl-function.js +5 -7
- package/repl/repl-logger.js +10 -14
- package/repl/repl-native-commands.js +1 -4
- package/repl/repl.d.ts +1 -1
- package/repl/repl.interfaces.d.ts +2 -2
- package/repl/repl.interfaces.js +1 -2
- package/repl/repl.js +17 -20
- package/router/index.d.ts +3 -3
- package/router/index.js +3 -8
- package/router/interfaces/exceptions-filter.interface.d.ts +3 -3
- package/router/interfaces/exceptions-filter.interface.js +1 -2
- package/router/interfaces/exclude-route-metadata.interface.d.ts +1 -1
- package/router/interfaces/exclude-route-metadata.interface.js +1 -2
- package/router/interfaces/index.d.ts +1 -1
- package/router/interfaces/index.js +1 -4
- package/router/interfaces/resolver.interface.js +1 -2
- package/router/interfaces/route-params-factory.interface.d.ts +1 -1
- package/router/interfaces/route-params-factory.interface.js +1 -2
- package/router/interfaces/route-path-metadata.interface.d.ts +2 -2
- package/router/interfaces/route-path-metadata.interface.js +1 -2
- package/router/interfaces/routes.interface.d.ts +1 -1
- package/router/interfaces/routes.interface.js +1 -2
- package/router/legacy-route-converter.js +3 -7
- package/router/paths-explorer.d.ts +4 -5
- package/router/paths-explorer.js +11 -15
- package/router/request/index.d.ts +1 -1
- package/router/request/index.js +1 -5
- package/router/request/request-constants.js +2 -5
- package/router/request/request-providers.d.ts +1 -1
- package/router/request/request-providers.js +5 -8
- package/router/route-params-factory.d.ts +2 -2
- package/router/route-params-factory.js +15 -19
- package/router/route-path-factory.d.ts +4 -4
- package/router/route-path-factory.js +19 -22
- package/router/router-exception-filters.d.ts +9 -9
- package/router/router-exception-filters.js +15 -18
- package/router/router-execution-context.d.ts +17 -20
- package/router/router-execution-context.js +57 -49
- package/router/router-explorer.d.ts +14 -16
- package/router/router-explorer.js +55 -54
- package/router/router-module.d.ts +4 -4
- package/router/router-module.js +21 -23
- package/router/router-proxy.d.ts +1 -1
- package/router/router-proxy.js +4 -8
- package/router/router-response-controller.d.ts +2 -2
- package/router/router-response-controller.js +20 -23
- package/router/routes-resolver.d.ts +8 -9
- package/router/routes-resolver.js +36 -51
- package/router/sse-stream.d.ts +1 -1
- package/router/sse-stream.js +5 -9
- package/router/utils/exclude-route.util.d.ts +1 -1
- package/router/utils/exclude-route.util.js +7 -12
- package/router/utils/flatten-route-paths.util.d.ts +2 -2
- package/router/utils/flatten-route-paths.util.js +4 -7
- package/router/utils/index.d.ts +2 -2
- package/router/utils/index.js +2 -5
- package/scanner.d.ts +11 -11
- package/scanner.js +64 -65
- package/services/index.d.ts +1 -1
- package/services/index.js +1 -4
- package/services/reflector.service.d.ts +1 -1
- package/services/reflector.service.js +9 -13
- package/tsconfig.build.json +1 -9
package/injector/module-ref.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Scope } from '@nestjs/common';
|
|
2
|
+
import { getClassScope } from '../helpers/get-class-scope.js';
|
|
3
|
+
import { isDurable } from '../helpers/is-durable.js';
|
|
4
|
+
import { AbstractInstanceResolver } from './abstract-instance-resolver.js';
|
|
5
|
+
import { Injector } from './injector.js';
|
|
6
|
+
import { InstanceLinksHost } from './instance-links-host.js';
|
|
7
|
+
import { InstanceWrapper } from './instance-wrapper.js';
|
|
8
|
+
export class ModuleRef extends AbstractInstanceResolver {
|
|
9
|
+
container;
|
|
10
|
+
injector;
|
|
11
|
+
_instanceLinksHost;
|
|
12
12
|
get instanceLinksHost() {
|
|
13
13
|
if (!this._instanceLinksHost) {
|
|
14
|
-
this._instanceLinksHost = new
|
|
14
|
+
this._instanceLinksHost = new InstanceLinksHost(this.container);
|
|
15
15
|
}
|
|
16
16
|
return this._instanceLinksHost;
|
|
17
17
|
}
|
|
18
18
|
constructor(container) {
|
|
19
19
|
super();
|
|
20
20
|
this.container = container;
|
|
21
|
-
this.injector = new
|
|
21
|
+
this.injector = new Injector({
|
|
22
22
|
preview: container.contextOptions?.preview,
|
|
23
23
|
instanceDecorator: container.contextOptions?.instrument?.instanceDecorator,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
introspect(token) {
|
|
27
27
|
const { wrapperRef } = this.instanceLinksHost.get(token);
|
|
28
|
-
let scope =
|
|
28
|
+
let scope = Scope.DEFAULT;
|
|
29
29
|
if (!wrapperRef.isDependencyTreeStatic()) {
|
|
30
|
-
scope =
|
|
30
|
+
scope = Scope.REQUEST;
|
|
31
31
|
}
|
|
32
32
|
else if (wrapperRef.isTransient) {
|
|
33
|
-
scope =
|
|
33
|
+
scope = Scope.TRANSIENT;
|
|
34
34
|
}
|
|
35
35
|
return { scope };
|
|
36
36
|
}
|
|
@@ -38,12 +38,12 @@ class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
|
38
38
|
this.container.registerRequestProvider(request, contextId);
|
|
39
39
|
}
|
|
40
40
|
async instantiateClass(type, moduleRef, contextId) {
|
|
41
|
-
const wrapper = new
|
|
41
|
+
const wrapper = new InstanceWrapper({
|
|
42
42
|
name: type && type.name,
|
|
43
43
|
metatype: type,
|
|
44
44
|
isResolved: false,
|
|
45
|
-
scope:
|
|
46
|
-
durable:
|
|
45
|
+
scope: getClassScope(type),
|
|
46
|
+
durable: isDurable(type),
|
|
47
47
|
host: moduleRef,
|
|
48
48
|
});
|
|
49
49
|
/* eslint-disable-next-line no-async-promise-executor */
|
|
@@ -63,4 +63,3 @@ class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
exports.ModuleRef = ModuleRef;
|
package/injector/module.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { NestContainer } from './container.js';
|
|
2
|
+
import { InstanceWrapper } from './instance-wrapper.js';
|
|
3
|
+
import { ModuleRef } from './module-ref.js';
|
|
4
|
+
import { type EnhancerSubtype, type Controller, type Injectable } from '@nestjs/common/internal';
|
|
5
|
+
import { type ClassProvider, type DynamicModule, type ExistingProvider, type FactoryProvider, type InjectionToken, type NestModule, type Provider, type Type, type ValueProvider } from '@nestjs/common';
|
|
6
6
|
export declare class Module {
|
|
7
7
|
private readonly _metatype;
|
|
8
8
|
private readonly container;
|
package/injector/module.js
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { iterate } from 'iterare';
|
|
2
|
+
import { ApplicationConfig } from '../application-config.js';
|
|
3
|
+
import { InvalidClassException, RuntimeException, UnknownExportException, } from '../errors/exceptions/index.js';
|
|
4
|
+
import { createContextId } from '../helpers/context-id-factory.js';
|
|
5
|
+
import { getClassScope } from '../helpers/get-class-scope.js';
|
|
6
|
+
import { isDurable } from '../helpers/is-durable.js';
|
|
7
|
+
import { UuidFactory } from '../inspector/uuid-factory.js';
|
|
8
|
+
import { CONTROLLER_ID_KEY } from './constants.js';
|
|
9
|
+
import { InstanceWrapper } from './instance-wrapper.js';
|
|
10
|
+
import { ModuleRef } from './module-ref.js';
|
|
11
|
+
import { ENTRY_PROVIDER_WATERMARK, randomStringGenerator, isFunction, isNil, isObject, isString, isSymbol, isUndefined, } from '@nestjs/common/internal';
|
|
12
|
+
import { Scope, } from '@nestjs/common';
|
|
13
|
+
export class Module {
|
|
14
|
+
_metatype;
|
|
15
|
+
container;
|
|
16
|
+
_id;
|
|
17
|
+
_imports = new Set();
|
|
18
|
+
_providers = new Map();
|
|
19
|
+
_injectables = new Map();
|
|
20
|
+
_middlewares = new Map();
|
|
21
|
+
_controllers = new Map();
|
|
22
|
+
_entryProviderKeys = new Set();
|
|
23
|
+
_exports = new Set();
|
|
24
|
+
_distance = 0;
|
|
25
|
+
_initOnPreview = false;
|
|
26
|
+
_isGlobal = false;
|
|
27
|
+
_token;
|
|
19
28
|
constructor(_metatype, container) {
|
|
20
29
|
this._metatype = _metatype;
|
|
21
30
|
this.container = container;
|
|
22
|
-
this._imports = new Set();
|
|
23
|
-
this._providers = new Map();
|
|
24
|
-
this._injectables = new Map();
|
|
25
|
-
this._middlewares = new Map();
|
|
26
|
-
this._controllers = new Map();
|
|
27
|
-
this._entryProviderKeys = new Set();
|
|
28
|
-
this._exports = new Set();
|
|
29
|
-
this._distance = 0;
|
|
30
|
-
this._initOnPreview = false;
|
|
31
|
-
this._isGlobal = false;
|
|
32
31
|
this.addCoreProviders();
|
|
33
32
|
this._id = this.generateUuid();
|
|
34
33
|
}
|
|
@@ -79,7 +78,7 @@ class Module {
|
|
|
79
78
|
}
|
|
80
79
|
get instance() {
|
|
81
80
|
if (!this._providers.has(this._metatype)) {
|
|
82
|
-
throw new
|
|
81
|
+
throw new RuntimeException();
|
|
83
82
|
}
|
|
84
83
|
const moduleRef = this._providers.get(this._metatype);
|
|
85
84
|
return moduleRef.instance;
|
|
@@ -100,17 +99,17 @@ class Module {
|
|
|
100
99
|
}
|
|
101
100
|
addModuleRef() {
|
|
102
101
|
const moduleRef = this.createModuleReferenceType();
|
|
103
|
-
this._providers.set(
|
|
104
|
-
token:
|
|
105
|
-
name:
|
|
106
|
-
metatype:
|
|
102
|
+
this._providers.set(ModuleRef, new InstanceWrapper({
|
|
103
|
+
token: ModuleRef,
|
|
104
|
+
name: ModuleRef.name,
|
|
105
|
+
metatype: ModuleRef,
|
|
107
106
|
isResolved: true,
|
|
108
107
|
instance: new moduleRef(),
|
|
109
108
|
host: this,
|
|
110
109
|
}));
|
|
111
110
|
}
|
|
112
111
|
addModuleAsProvider() {
|
|
113
|
-
this._providers.set(this._metatype, new
|
|
112
|
+
this._providers.set(this._metatype, new InstanceWrapper({
|
|
114
113
|
token: this._metatype,
|
|
115
114
|
name: this._metatype.name,
|
|
116
115
|
metatype: this._metatype,
|
|
@@ -120,9 +119,9 @@ class Module {
|
|
|
120
119
|
}));
|
|
121
120
|
}
|
|
122
121
|
addApplicationConfig() {
|
|
123
|
-
this._providers.set(
|
|
124
|
-
token:
|
|
125
|
-
name:
|
|
122
|
+
this._providers.set(ApplicationConfig, new InstanceWrapper({
|
|
123
|
+
token: ApplicationConfig,
|
|
124
|
+
name: ApplicationConfig.name,
|
|
126
125
|
isResolved: true,
|
|
127
126
|
instance: this.container.applicationConfig,
|
|
128
127
|
host: this,
|
|
@@ -134,14 +133,14 @@ class Module {
|
|
|
134
133
|
}
|
|
135
134
|
let instanceWrapper = this.injectables.get(injectable);
|
|
136
135
|
if (!instanceWrapper) {
|
|
137
|
-
instanceWrapper = new
|
|
136
|
+
instanceWrapper = new InstanceWrapper({
|
|
138
137
|
token: injectable,
|
|
139
138
|
name: injectable.name,
|
|
140
139
|
metatype: injectable,
|
|
141
140
|
instance: null,
|
|
142
141
|
isResolved: false,
|
|
143
|
-
scope:
|
|
144
|
-
durable:
|
|
142
|
+
scope: getClassScope(injectable),
|
|
143
|
+
durable: isDurable(injectable),
|
|
145
144
|
subtype: enhancerSubtype,
|
|
146
145
|
host: this,
|
|
147
146
|
});
|
|
@@ -166,14 +165,14 @@ class Module {
|
|
|
166
165
|
isAlreadyDeclared) {
|
|
167
166
|
return provider;
|
|
168
167
|
}
|
|
169
|
-
this._providers.set(provider, new
|
|
168
|
+
this._providers.set(provider, new InstanceWrapper({
|
|
170
169
|
token: provider,
|
|
171
170
|
name: provider.name,
|
|
172
171
|
metatype: provider,
|
|
173
172
|
instance: null,
|
|
174
173
|
isResolved: false,
|
|
175
|
-
scope:
|
|
176
|
-
durable:
|
|
174
|
+
scope: getClassScope(provider),
|
|
175
|
+
durable: isDurable(provider),
|
|
177
176
|
host: this,
|
|
178
177
|
}));
|
|
179
178
|
if (this.isEntryProvider(provider)) {
|
|
@@ -182,7 +181,7 @@ class Module {
|
|
|
182
181
|
return provider;
|
|
183
182
|
}
|
|
184
183
|
isCustomProvider(provider) {
|
|
185
|
-
return !
|
|
184
|
+
return !isNil(provider.provide);
|
|
186
185
|
}
|
|
187
186
|
addCustomProvider(provider, collection, enhancerSubtype) {
|
|
188
187
|
if (this.isCustomClass(provider)) {
|
|
@@ -200,17 +199,17 @@ class Module {
|
|
|
200
199
|
return provider.provide;
|
|
201
200
|
}
|
|
202
201
|
isCustomClass(provider) {
|
|
203
|
-
return !
|
|
202
|
+
return !isUndefined(provider.useClass);
|
|
204
203
|
}
|
|
205
204
|
isCustomValue(provider) {
|
|
206
|
-
return (
|
|
205
|
+
return (isObject(provider) &&
|
|
207
206
|
Object.prototype.hasOwnProperty.call(provider, 'useValue'));
|
|
208
207
|
}
|
|
209
208
|
isCustomFactory(provider) {
|
|
210
|
-
return !
|
|
209
|
+
return !isUndefined(provider.useFactory);
|
|
211
210
|
}
|
|
212
211
|
isCustomUseExisting(provider) {
|
|
213
|
-
return !
|
|
212
|
+
return !isUndefined(provider.useExisting);
|
|
214
213
|
}
|
|
215
214
|
isDynamicModule(exported) {
|
|
216
215
|
return exported && exported.module;
|
|
@@ -218,14 +217,14 @@ class Module {
|
|
|
218
217
|
addCustomClass(provider, collection, enhancerSubtype) {
|
|
219
218
|
let { scope, durable } = provider;
|
|
220
219
|
const { useClass } = provider;
|
|
221
|
-
if (
|
|
222
|
-
scope =
|
|
220
|
+
if (isUndefined(scope)) {
|
|
221
|
+
scope = getClassScope(useClass);
|
|
223
222
|
}
|
|
224
|
-
if (
|
|
225
|
-
durable =
|
|
223
|
+
if (isUndefined(durable)) {
|
|
224
|
+
durable = isDurable(useClass);
|
|
226
225
|
}
|
|
227
226
|
const token = provider.provide;
|
|
228
|
-
collection.set(token, new
|
|
227
|
+
collection.set(token, new InstanceWrapper({
|
|
229
228
|
token,
|
|
230
229
|
name: useClass?.name || useClass,
|
|
231
230
|
metatype: useClass,
|
|
@@ -240,7 +239,7 @@ class Module {
|
|
|
240
239
|
addCustomValue(provider, collection, enhancerSubtype) {
|
|
241
240
|
const { useValue: value, provide: providerToken } = provider;
|
|
242
241
|
const instanceDecorator = this.container.contextOptions?.instrument?.instanceDecorator;
|
|
243
|
-
collection.set(providerToken, new
|
|
242
|
+
collection.set(providerToken, new InstanceWrapper({
|
|
244
243
|
token: providerToken,
|
|
245
244
|
name: providerToken?.name || providerToken,
|
|
246
245
|
metatype: null,
|
|
@@ -253,7 +252,7 @@ class Module {
|
|
|
253
252
|
}
|
|
254
253
|
addCustomFactory(provider, collection, enhancerSubtype) {
|
|
255
254
|
const { useFactory: factory, inject, scope, durable, provide: providerToken, } = provider;
|
|
256
|
-
collection.set(providerToken, new
|
|
255
|
+
collection.set(providerToken, new InstanceWrapper({
|
|
257
256
|
token: providerToken,
|
|
258
257
|
name: providerToken?.name || providerToken,
|
|
259
258
|
metatype: factory,
|
|
@@ -268,7 +267,7 @@ class Module {
|
|
|
268
267
|
}
|
|
269
268
|
addCustomUseExisting(provider, collection, enhancerSubtype) {
|
|
270
269
|
const { useExisting, provide: providerToken } = provider;
|
|
271
|
-
collection.set(providerToken, new
|
|
270
|
+
collection.set(providerToken, new InstanceWrapper({
|
|
272
271
|
token: providerToken,
|
|
273
272
|
name: providerToken?.name || providerToken,
|
|
274
273
|
metatype: (instance => instance),
|
|
@@ -285,7 +284,7 @@ class Module {
|
|
|
285
284
|
if (this.isCustomProvider(toExport)) {
|
|
286
285
|
return this.addCustomExportedProvider(toExport);
|
|
287
286
|
}
|
|
288
|
-
else if (
|
|
287
|
+
else if (isString(toExport) || isSymbol(toExport)) {
|
|
289
288
|
return addExportedUnit(toExport);
|
|
290
289
|
}
|
|
291
290
|
else if (this.isDynamicModule(toExport)) {
|
|
@@ -296,7 +295,7 @@ class Module {
|
|
|
296
295
|
}
|
|
297
296
|
addCustomExportedProvider(provider) {
|
|
298
297
|
const provide = provider.provide;
|
|
299
|
-
if (
|
|
298
|
+
if (isString(provide) || isSymbol(provide)) {
|
|
300
299
|
return this._exports.add(this.validateExportedProvider(provide));
|
|
301
300
|
}
|
|
302
301
|
this._exports.add(this.validateExportedProvider(provide));
|
|
@@ -305,37 +304,37 @@ class Module {
|
|
|
305
304
|
if (this._providers.has(token)) {
|
|
306
305
|
return token;
|
|
307
306
|
}
|
|
308
|
-
const imports =
|
|
307
|
+
const imports = iterate(this._imports.values())
|
|
309
308
|
.filter(item => !!item)
|
|
310
309
|
.map(({ metatype }) => metatype)
|
|
311
310
|
.filter(metatype => !!metatype)
|
|
312
311
|
.toArray();
|
|
313
312
|
if (!imports.includes(token)) {
|
|
314
313
|
const { name } = this.metatype;
|
|
315
|
-
const providerName =
|
|
316
|
-
throw new
|
|
314
|
+
const providerName = isFunction(token) ? token.name : token;
|
|
315
|
+
throw new UnknownExportException(providerName, name);
|
|
317
316
|
}
|
|
318
317
|
return token;
|
|
319
318
|
}
|
|
320
319
|
addController(controller) {
|
|
321
|
-
this._controllers.set(controller, new
|
|
320
|
+
this._controllers.set(controller, new InstanceWrapper({
|
|
322
321
|
token: controller,
|
|
323
322
|
name: controller.name,
|
|
324
323
|
metatype: controller,
|
|
325
324
|
instance: null,
|
|
326
325
|
isResolved: false,
|
|
327
|
-
scope:
|
|
328
|
-
durable:
|
|
326
|
+
scope: getClassScope(controller),
|
|
327
|
+
durable: isDurable(controller),
|
|
329
328
|
host: this,
|
|
330
329
|
}));
|
|
331
330
|
this.assignControllerUniqueId(controller);
|
|
332
331
|
}
|
|
333
332
|
assignControllerUniqueId(controller) {
|
|
334
|
-
Object.defineProperty(controller,
|
|
333
|
+
Object.defineProperty(controller, CONTROLLER_ID_KEY, {
|
|
335
334
|
enumerable: false,
|
|
336
335
|
writable: false,
|
|
337
336
|
configurable: true,
|
|
338
|
-
value:
|
|
337
|
+
value: randomStringGenerator(),
|
|
339
338
|
});
|
|
340
339
|
}
|
|
341
340
|
addImport(moduleRef) {
|
|
@@ -364,16 +363,32 @@ class Module {
|
|
|
364
363
|
return this._providers.get(name);
|
|
365
364
|
}
|
|
366
365
|
getProviderById(id) {
|
|
367
|
-
|
|
366
|
+
for (const item of this._providers.values()) {
|
|
367
|
+
if (item.id === id)
|
|
368
|
+
return item;
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
368
371
|
}
|
|
369
372
|
getControllerById(id) {
|
|
370
|
-
|
|
373
|
+
for (const item of this._controllers.values()) {
|
|
374
|
+
if (item.id === id)
|
|
375
|
+
return item;
|
|
376
|
+
}
|
|
377
|
+
return undefined;
|
|
371
378
|
}
|
|
372
379
|
getInjectableById(id) {
|
|
373
|
-
|
|
380
|
+
for (const item of this._injectables.values()) {
|
|
381
|
+
if (item.id === id)
|
|
382
|
+
return item;
|
|
383
|
+
}
|
|
384
|
+
return undefined;
|
|
374
385
|
}
|
|
375
386
|
getMiddlewareById(id) {
|
|
376
|
-
|
|
387
|
+
for (const item of this._middlewares.values()) {
|
|
388
|
+
if (item.id === id)
|
|
389
|
+
return item;
|
|
390
|
+
}
|
|
391
|
+
return undefined;
|
|
377
392
|
}
|
|
378
393
|
getNonAliasProviders() {
|
|
379
394
|
return [...this._providers].filter(([_, wrapper]) => !wrapper.isAlias);
|
|
@@ -381,7 +396,7 @@ class Module {
|
|
|
381
396
|
createModuleReferenceType() {
|
|
382
397
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
383
398
|
const self = this;
|
|
384
|
-
return class extends
|
|
399
|
+
return class extends ModuleRef {
|
|
385
400
|
constructor() {
|
|
386
401
|
super(self.container);
|
|
387
402
|
}
|
|
@@ -395,14 +410,14 @@ class Module {
|
|
|
395
410
|
}
|
|
396
411
|
: options);
|
|
397
412
|
}
|
|
398
|
-
resolve(typeOrToken, contextId =
|
|
413
|
+
resolve(typeOrToken, contextId = createContextId(), options = {}) {
|
|
399
414
|
options.strict ??= true;
|
|
400
415
|
options.each ??= false;
|
|
401
416
|
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
|
402
417
|
}
|
|
403
418
|
async create(type, contextId) {
|
|
404
|
-
if (!(type &&
|
|
405
|
-
throw new
|
|
419
|
+
if (!(type && isFunction(type) && type.prototype)) {
|
|
420
|
+
throw new InvalidClassException(type);
|
|
406
421
|
}
|
|
407
422
|
return this.instantiateClass(type, self, contextId);
|
|
408
423
|
}
|
|
@@ -410,7 +425,7 @@ class Module {
|
|
|
410
425
|
}
|
|
411
426
|
isEntryProvider(metatype) {
|
|
412
427
|
return typeof metatype === 'function'
|
|
413
|
-
? !!Reflect.getMetadata(
|
|
428
|
+
? !!Reflect.getMetadata(ENTRY_PROVIDER_WATERMARK, metatype)
|
|
414
429
|
: false;
|
|
415
430
|
}
|
|
416
431
|
generateUuid() {
|
|
@@ -420,13 +435,12 @@ class Module {
|
|
|
420
435
|
? this.token.split(':')[1]
|
|
421
436
|
: this.token
|
|
422
437
|
: this.name;
|
|
423
|
-
return key ?
|
|
438
|
+
return key ? UuidFactory.get(`${prefix}_${key}`) : randomStringGenerator();
|
|
424
439
|
}
|
|
425
440
|
isTransientProvider(provider) {
|
|
426
|
-
return
|
|
441
|
+
return getClassScope(provider) === Scope.TRANSIENT;
|
|
427
442
|
}
|
|
428
443
|
isRequestScopeProvider(provider) {
|
|
429
|
-
return
|
|
444
|
+
return getClassScope(provider) === Scope.REQUEST;
|
|
430
445
|
}
|
|
431
446
|
}
|
|
432
|
-
exports.Module = Module;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ModulesContainer extends Map {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this._applicationId = (0, uid_1.uid)(21);
|
|
10
|
-
this._rpcTargetRegistry$ = new rxjs_1.ReplaySubject();
|
|
11
|
-
}
|
|
1
|
+
import { ReplaySubject } from 'rxjs';
|
|
2
|
+
import { uid } from 'uid';
|
|
3
|
+
export class ModulesContainer extends Map {
|
|
4
|
+
_applicationId = uid(21);
|
|
5
|
+
_rpcTargetRegistry$ = new ReplaySubject();
|
|
12
6
|
/**
|
|
13
7
|
* Unique identifier of the application instance.
|
|
14
8
|
*/
|
|
@@ -39,4 +33,3 @@ class ModulesContainer extends Map {
|
|
|
39
33
|
this._rpcTargetRegistry$.next(target);
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
|
-
exports.ModulesContainer = ModulesContainer;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ForwardReference } from '@nestjs/common
|
|
3
|
-
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
4
|
-
import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface';
|
|
1
|
+
import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface.js';
|
|
2
|
+
import type { DynamicModule, ForwardReference, Type } from '@nestjs/common';
|
|
5
3
|
export declare class ByReferenceModuleOpaqueKeyFactory implements ModuleOpaqueKeyFactory {
|
|
6
4
|
private readonly keyGenerationStrategy;
|
|
7
5
|
constructor(options?: {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ByReferenceModuleOpaqueKeyFactory = void 0;
|
|
4
|
-
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { randomStringGenerator } from '@nestjs/common/internal';
|
|
6
3
|
const K_MODULE_ID = Symbol('K_MODULE_ID');
|
|
7
|
-
class ByReferenceModuleOpaqueKeyFactory {
|
|
4
|
+
export class ByReferenceModuleOpaqueKeyFactory {
|
|
5
|
+
keyGenerationStrategy;
|
|
8
6
|
constructor(options) {
|
|
9
7
|
this.keyGenerationStrategy = options?.keyGenerationStrategy ?? 'random';
|
|
10
8
|
}
|
|
@@ -32,10 +30,9 @@ class ByReferenceModuleOpaqueKeyFactory {
|
|
|
32
30
|
return moduleId;
|
|
33
31
|
}
|
|
34
32
|
hashString(value) {
|
|
35
|
-
return
|
|
33
|
+
return createHash('sha256').update(value).digest('hex');
|
|
36
34
|
}
|
|
37
35
|
generateRandomString() {
|
|
38
|
-
return
|
|
36
|
+
return randomStringGenerator();
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
exports.ByReferenceModuleOpaqueKeyFactory = ByReferenceModuleOpaqueKeyFactory;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Type } from '@nestjs/common
|
|
3
|
-
import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface';
|
|
1
|
+
import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface.js';
|
|
2
|
+
import { type DynamicModule, type Type } from '@nestjs/common';
|
|
4
3
|
export declare class DeepHashedModuleOpaqueKeyFactory implements ModuleOpaqueKeyFactory {
|
|
5
4
|
private readonly moduleIdsCache;
|
|
6
5
|
private readonly moduleTokenCache;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const crypto_1 = require("crypto");
|
|
8
|
-
const fast_safe_stringify_1 = require("fast-safe-stringify");
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import _stringify from 'fast-safe-stringify';
|
|
3
|
+
import { Logger } from '@nestjs/common';
|
|
4
|
+
import { randomStringGenerator, isFunction, isSymbol, } from '@nestjs/common/internal';
|
|
5
|
+
// CJS interop: fast-safe-stringify sets module.exports.default = module.exports
|
|
6
|
+
const stringify = (_stringify.default ?? _stringify);
|
|
9
7
|
const CLASS_STR = 'class ';
|
|
10
8
|
const CLASS_STR_LEN = CLASS_STR.length;
|
|
11
|
-
class DeepHashedModuleOpaqueKeyFactory {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
}
|
|
9
|
+
export class DeepHashedModuleOpaqueKeyFactory {
|
|
10
|
+
moduleIdsCache = new WeakMap();
|
|
11
|
+
moduleTokenCache = new Map();
|
|
12
|
+
logger = new Logger(DeepHashedModuleOpaqueKeyFactory.name, {
|
|
13
|
+
timestamp: true,
|
|
14
|
+
});
|
|
19
15
|
createForStatic(moduleCls) {
|
|
20
16
|
const moduleId = this.getModuleId(moduleCls);
|
|
21
17
|
const moduleName = this.getModuleName(moduleCls);
|
|
@@ -48,14 +44,14 @@ class DeepHashedModuleOpaqueKeyFactory {
|
|
|
48
44
|
// Uses safeStringify instead of JSON.stringify to support circular dynamic modules
|
|
49
45
|
// The replacer function is also required in order to obtain real class names
|
|
50
46
|
// instead of the unified "Function" key
|
|
51
|
-
return opaqueToken ? (
|
|
47
|
+
return opaqueToken ? stringify(opaqueToken, this.replacer) : '';
|
|
52
48
|
}
|
|
53
49
|
getModuleId(metatype) {
|
|
54
50
|
let moduleId = this.moduleIdsCache.get(metatype);
|
|
55
51
|
if (moduleId) {
|
|
56
52
|
return moduleId;
|
|
57
53
|
}
|
|
58
|
-
moduleId =
|
|
54
|
+
moduleId = randomStringGenerator();
|
|
59
55
|
this.moduleIdsCache.set(metatype, moduleId);
|
|
60
56
|
return moduleId;
|
|
61
57
|
}
|
|
@@ -63,10 +59,10 @@ class DeepHashedModuleOpaqueKeyFactory {
|
|
|
63
59
|
return metatype.name;
|
|
64
60
|
}
|
|
65
61
|
hashString(value) {
|
|
66
|
-
return
|
|
62
|
+
return createHash('sha256').update(value).digest('hex');
|
|
67
63
|
}
|
|
68
64
|
replacer(key, value) {
|
|
69
|
-
if (
|
|
65
|
+
if (isFunction(value)) {
|
|
70
66
|
const funcAsString = value.toString();
|
|
71
67
|
const isClass = funcAsString.slice(0, CLASS_STR_LEN) === CLASS_STR;
|
|
72
68
|
if (isClass) {
|
|
@@ -74,10 +70,9 @@ class DeepHashedModuleOpaqueKeyFactory {
|
|
|
74
70
|
}
|
|
75
71
|
return funcAsString;
|
|
76
72
|
}
|
|
77
|
-
if (
|
|
73
|
+
if (isSymbol(value)) {
|
|
78
74
|
return value.toString();
|
|
79
75
|
}
|
|
80
76
|
return value;
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
|
-
exports.DeepHashedModuleOpaqueKeyFactory = DeepHashedModuleOpaqueKeyFactory;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common
|
|
2
|
-
import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
|
|
3
|
-
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
1
|
+
import type { DynamicModule, ForwardReference, Type } from '@nestjs/common';
|
|
4
2
|
export interface ModuleOpaqueKeyFactory {
|
|
5
3
|
/**
|
|
6
4
|
* Creates a unique opaque key for the given static module.
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|