@nestjs/core 9.1.6 → 9.2.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/Readme.md +3 -1
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +2 -1
- package/errors/exceptions/unknown-request-mapping.exception.js +2 -2
- package/errors/messages.d.ts +1 -1
- package/errors/messages.js +8 -2
- package/helpers/handler-metadata-storage.d.ts +1 -1
- package/injector/abstract-instance-resolver.d.ts +16 -0
- package/injector/abstract-instance-resolver.js +48 -0
- package/injector/container.js +1 -1
- package/injector/{silent-logger.d.ts → helpers/silent-logger.d.ts} +0 -0
- package/injector/{silent-logger.js → helpers/silent-logger.js} +0 -0
- package/injector/index.d.ts +1 -1
- package/injector/index.js +1 -1
- package/injector/injector.d.ts +1 -3
- package/injector/instance-links-host.d.ts +5 -1
- package/injector/instance-links-host.js +9 -6
- package/injector/instance-loader.js +1 -1
- package/injector/internal-core-module/index.d.ts +1 -0
- package/injector/internal-core-module/index.js +4 -0
- package/injector/{internal-core-module-factory.d.ts → internal-core-module/internal-core-module-factory.d.ts} +4 -4
- package/injector/{internal-core-module-factory.js → internal-core-module/internal-core-module-factory.js} +5 -5
- package/injector/{internal-core-module.d.ts → internal-core-module/internal-core-module.d.ts} +0 -0
- package/injector/{internal-core-module.js → internal-core-module/internal-core-module.js} +3 -3
- package/injector/{lazy-module-loader-options.interface.d.ts → lazy-module-loader/lazy-module-loader-options.interface.d.ts} +0 -0
- package/injector/{lazy-module-loader-options.interface.js → lazy-module-loader/lazy-module-loader-options.interface.js} +0 -0
- package/injector/{lazy-module-loader.d.ts → lazy-module-loader/lazy-module-loader.d.ts} +5 -5
- package/injector/{lazy-module-loader.js → lazy-module-loader/lazy-module-loader.js} +2 -2
- package/injector/module-ref.d.ts +70 -11
- package/injector/module-ref.js +3 -27
- package/injector/module.d.ts +1 -2
- package/injector/module.js +5 -2
- package/middleware/builder.d.ts +1 -2
- package/middleware/middleware-module.d.ts +3 -0
- package/middleware/middleware-module.js +13 -6
- package/middleware/routes-mapper.d.ts +3 -0
- package/middleware/routes-mapper.js +32 -17
- package/nest-application-context.d.ts +77 -12
- package/nest-application-context.js +38 -29
- package/nest-application.js +2 -1
- package/package.json +3 -3
- package/repl/repl-context.js +1 -1
- package/repl/repl.d.ts +2 -2
- package/router/router-execution-context.js +1 -0
- package/router/router-explorer.js +1 -1
- package/scanner.js +1 -1
package/Readme.md
CHANGED
|
@@ -90,7 +90,9 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
90
90
|
<a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
|
|
91
91
|
<td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png#1" width="140" valign="middle" /></td>
|
|
92
92
|
<td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td></tr><tr>
|
|
93
|
-
<td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td
|
|
93
|
+
<td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td>
|
|
94
|
+
<td><a href="https://ipinfo.ai/" target="_blank"><img src="https://nestjs.com/img/ipinfo-logo.png" width="130" valign="middle" /></td></tr>
|
|
95
|
+
</table>
|
|
94
96
|
|
|
95
97
|
#### Sponsors
|
|
96
98
|
|
|
@@ -4,8 +4,8 @@ exports.UnknownRequestMappingException = void 0;
|
|
|
4
4
|
const runtime_exception_1 = require("./runtime.exception");
|
|
5
5
|
const messages_1 = require("../messages");
|
|
6
6
|
class UnknownRequestMappingException extends runtime_exception_1.RuntimeException {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(messages_1.UNKNOWN_REQUEST_MAPPING);
|
|
7
|
+
constructor(metatype) {
|
|
8
|
+
super((0, messages_1.UNKNOWN_REQUEST_MAPPING)(metatype));
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.UnknownRequestMappingException = UnknownRequestMappingException;
|
package/errors/messages.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export declare const UNDEFINED_MODULE_MESSAGE: (parentModule: any, index: number
|
|
|
10
10
|
export declare const UNKNOWN_EXPORT_MESSAGE: (token: string | symbol, module: string) => string;
|
|
11
11
|
export declare const INVALID_CLASS_MESSAGE: (text: TemplateStringsArray, value: any) => string;
|
|
12
12
|
export declare const INVALID_CLASS_SCOPE_MESSAGE: (text: TemplateStringsArray, name: string | undefined) => string;
|
|
13
|
+
export declare const UNKNOWN_REQUEST_MAPPING: (metatype: Type) => string;
|
|
13
14
|
export declare const INVALID_MIDDLEWARE_CONFIGURATION = "An invalid middleware configuration has been passed inside the module 'configure()' method.";
|
|
14
|
-
export declare const UNKNOWN_REQUEST_MAPPING = "An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.";
|
|
15
15
|
export declare const UNHANDLED_RUNTIME_EXCEPTION = "Unhandled Runtime Exception.";
|
|
16
16
|
export declare const INVALID_EXCEPTION_FILTER = "Invalid exception filters (@UseFilters()).";
|
|
17
17
|
export declare const MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = "Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)";
|
package/errors/messages.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = exports.INVALID_EXCEPTION_FILTER = exports.UNHANDLED_RUNTIME_EXCEPTION = exports.
|
|
3
|
+
exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = exports.INVALID_EXCEPTION_FILTER = exports.UNHANDLED_RUNTIME_EXCEPTION = exports.INVALID_MIDDLEWARE_CONFIGURATION = exports.UNKNOWN_REQUEST_MAPPING = exports.INVALID_CLASS_SCOPE_MESSAGE = exports.INVALID_CLASS_MESSAGE = exports.UNKNOWN_EXPORT_MESSAGE = exports.UNDEFINED_MODULE_MESSAGE = exports.USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = exports.INVALID_MODULE_MESSAGE = exports.UNDEFINED_FORWARDREF_MESSAGE = exports.INVALID_MIDDLEWARE_MESSAGE = exports.UNKNOWN_DEPENDENCIES_MESSAGE = void 0;
|
|
4
4
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
5
|
/**
|
|
6
6
|
* Returns the name of an instance or `undefined`
|
|
@@ -114,8 +114,14 @@ const INVALID_CLASS_MESSAGE = (text, value) => `ModuleRef cannot instantiate cla
|
|
|
114
114
|
exports.INVALID_CLASS_MESSAGE = INVALID_CLASS_MESSAGE;
|
|
115
115
|
const INVALID_CLASS_SCOPE_MESSAGE = (text, name) => `${name || 'This class'} is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.`;
|
|
116
116
|
exports.INVALID_CLASS_SCOPE_MESSAGE = INVALID_CLASS_SCOPE_MESSAGE;
|
|
117
|
+
const UNKNOWN_REQUEST_MAPPING = (metatype) => {
|
|
118
|
+
const className = metatype.name;
|
|
119
|
+
return className
|
|
120
|
+
? `An invalid controller has been detected. "${className}" does not have the @Controller() decorator but it is being listed in the "controllers" array of some module.`
|
|
121
|
+
: `An invalid controller has been detected. Perhaps, one of your controllers is missing the @Controller() decorator.`;
|
|
122
|
+
};
|
|
123
|
+
exports.UNKNOWN_REQUEST_MAPPING = UNKNOWN_REQUEST_MAPPING;
|
|
117
124
|
exports.INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
|
|
118
|
-
exports.UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`;
|
|
119
125
|
exports.UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
|
|
120
126
|
exports.INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
|
|
121
127
|
exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Abstract, Type } from '@nestjs/common';
|
|
2
|
+
import { GetOrResolveOptions } from '@nestjs/common/interfaces';
|
|
3
|
+
import { Injector } from './injector';
|
|
4
|
+
import { InstanceLinksHost } from './instance-links-host';
|
|
5
|
+
import { ContextId } from './instance-wrapper';
|
|
6
|
+
import { Module } from './module';
|
|
7
|
+
export declare abstract class AbstractInstanceResolver {
|
|
8
|
+
protected abstract instanceLinksHost: InstanceLinksHost;
|
|
9
|
+
protected abstract injector: Injector;
|
|
10
|
+
protected abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: GetOrResolveOptions): TResult | Array<TResult>;
|
|
11
|
+
protected find<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, options: {
|
|
12
|
+
moduleId?: string;
|
|
13
|
+
each?: boolean;
|
|
14
|
+
}): TResult | Array<TResult>;
|
|
15
|
+
protected resolvePerContext<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule: Module, contextId: ContextId, options?: GetOrResolveOptions): Promise<TResult | Array<TResult>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractInstanceResolver = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const exceptions_1 = require("../errors/exceptions");
|
|
6
|
+
class AbstractInstanceResolver {
|
|
7
|
+
find(typeOrToken, options) {
|
|
8
|
+
const instanceLinkOrArray = this.instanceLinksHost.get(typeOrToken, options);
|
|
9
|
+
const pluckInstance = ({ wrapperRef }) => {
|
|
10
|
+
if (wrapperRef.scope === common_1.Scope.REQUEST ||
|
|
11
|
+
wrapperRef.scope === common_1.Scope.TRANSIENT) {
|
|
12
|
+
throw new exceptions_1.InvalidClassScopeException(typeOrToken);
|
|
13
|
+
}
|
|
14
|
+
return wrapperRef.instance;
|
|
15
|
+
};
|
|
16
|
+
if (Array.isArray(instanceLinkOrArray)) {
|
|
17
|
+
return instanceLinkOrArray.map(pluckInstance);
|
|
18
|
+
}
|
|
19
|
+
return pluckInstance(instanceLinkOrArray);
|
|
20
|
+
}
|
|
21
|
+
async resolvePerContext(typeOrToken, contextModule, contextId, options) {
|
|
22
|
+
const instanceLinkOrArray = (options === null || options === void 0 ? void 0 : options.strict)
|
|
23
|
+
? this.instanceLinksHost.get(typeOrToken, {
|
|
24
|
+
moduleId: contextModule.id,
|
|
25
|
+
each: options.each,
|
|
26
|
+
})
|
|
27
|
+
: this.instanceLinksHost.get(typeOrToken, {
|
|
28
|
+
each: options.each,
|
|
29
|
+
});
|
|
30
|
+
const pluckInstance = async (instanceLink) => {
|
|
31
|
+
const { wrapperRef, collection } = instanceLink;
|
|
32
|
+
if (wrapperRef.isDependencyTreeStatic() && !wrapperRef.isTransient) {
|
|
33
|
+
return this.get(typeOrToken, { strict: options.strict });
|
|
34
|
+
}
|
|
35
|
+
const ctorHost = wrapperRef.instance || { constructor: typeOrToken };
|
|
36
|
+
const instance = await this.injector.loadPerContext(ctorHost, wrapperRef.host, collection, contextId, wrapperRef);
|
|
37
|
+
if (!instance) {
|
|
38
|
+
throw new exceptions_1.UnknownElementException();
|
|
39
|
+
}
|
|
40
|
+
return instance;
|
|
41
|
+
};
|
|
42
|
+
if (Array.isArray(instanceLinkOrArray)) {
|
|
43
|
+
return Promise.all(instanceLinkOrArray.map(instanceLink => pluckInstance(instanceLink)));
|
|
44
|
+
}
|
|
45
|
+
return pluckInstance(instanceLinkOrArray);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AbstractInstanceResolver = AbstractInstanceResolver;
|
package/injector/container.js
CHANGED
|
@@ -5,7 +5,7 @@ const constants_1 = require("@nestjs/common/constants");
|
|
|
5
5
|
const exceptions_1 = require("../errors/exceptions");
|
|
6
6
|
const request_constants_1 = require("../router/request/request-constants");
|
|
7
7
|
const compiler_1 = require("./compiler");
|
|
8
|
-
const internal_core_module_1 = require("./internal-core-module");
|
|
8
|
+
const internal_core_module_1 = require("./internal-core-module/internal-core-module");
|
|
9
9
|
const internal_providers_storage_1 = require("./internal-providers-storage");
|
|
10
10
|
const module_1 = require("./module");
|
|
11
11
|
const module_token_factory_1 = require("./module-token-factory");
|
|
File without changes
|
|
File without changes
|
package/injector/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './container';
|
|
2
2
|
export * from './inquirer';
|
|
3
3
|
export { ContextId, HostComponentInfo } from './instance-wrapper';
|
|
4
|
-
export * from './lazy-module-loader';
|
|
4
|
+
export * from './lazy-module-loader/lazy-module-loader';
|
|
5
5
|
export * from './module-ref';
|
|
6
6
|
export * from './modules-container';
|
package/injector/index.js
CHANGED
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./container"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./inquirer"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./lazy-module-loader"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lazy-module-loader/lazy-module-loader"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./module-ref"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./modules-container"), exports);
|
package/injector/injector.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { InjectionToken } from '@nestjs/common';
|
|
2
|
-
import { Controller } from '@nestjs/common/interfaces
|
|
3
|
-
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
|
|
4
|
-
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
2
|
+
import { Controller, Injectable, Type } from '@nestjs/common/interfaces';
|
|
5
3
|
import { ContextId, InstancePerContext, InstanceWrapper, PropertyMetadata } from './instance-wrapper';
|
|
6
4
|
import { InstanceToken, Module } from './module';
|
|
7
5
|
/**
|
|
@@ -11,7 +11,11 @@ export declare class InstanceLinksHost {
|
|
|
11
11
|
private readonly container;
|
|
12
12
|
private readonly instanceLinks;
|
|
13
13
|
constructor(container: NestContainer);
|
|
14
|
-
get<T = any>(token: InstanceToken
|
|
14
|
+
get<T = any>(token: InstanceToken): InstanceLink<T>;
|
|
15
|
+
get<T = any>(token: InstanceToken, options?: {
|
|
16
|
+
moduleId?: string;
|
|
17
|
+
each?: boolean;
|
|
18
|
+
}): InstanceLink<T> | Array<InstanceLink<T>>;
|
|
15
19
|
private initialize;
|
|
16
20
|
private addLink;
|
|
17
21
|
private getInstanceNameByToken;
|
|
@@ -9,14 +9,17 @@ class InstanceLinksHost {
|
|
|
9
9
|
this.instanceLinks = new Map();
|
|
10
10
|
this.initialize();
|
|
11
11
|
}
|
|
12
|
-
get(token,
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
12
|
+
get(token, options = {}) {
|
|
13
|
+
const instanceLinksForGivenToken = this.instanceLinks.get(token);
|
|
14
|
+
if (!instanceLinksForGivenToken) {
|
|
15
15
|
throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (options.each) {
|
|
18
|
+
return instanceLinksForGivenToken;
|
|
19
|
+
}
|
|
20
|
+
const instanceLink = options.moduleId
|
|
21
|
+
? instanceLinksForGivenToken.find(item => item.moduleId === options.moduleId)
|
|
22
|
+
: instanceLinksForGivenToken[instanceLinksForGivenToken.length - 1];
|
|
20
23
|
if (!instanceLink) {
|
|
21
24
|
throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
|
|
22
25
|
}
|
|
@@ -4,7 +4,7 @@ exports.InstanceLoader = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const messages_1 = require("../helpers/messages");
|
|
6
6
|
const injector_1 = require("./injector");
|
|
7
|
-
const internal_core_module_1 = require("./internal-core-module");
|
|
7
|
+
const internal_core_module_1 = require("./internal-core-module/internal-core-module");
|
|
8
8
|
class InstanceLoader {
|
|
9
9
|
constructor(container, logger = new common_1.Logger(InstanceLoader.name, {
|
|
10
10
|
timestamp: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './internal-core-module';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HttpAdapterHost } from '
|
|
2
|
-
import { DependenciesScanner } from '
|
|
3
|
-
import { ModuleCompiler } from '
|
|
4
|
-
import { NestContainer } from '
|
|
1
|
+
import { HttpAdapterHost } from '../../helpers/http-adapter-host';
|
|
2
|
+
import { DependenciesScanner } from '../../scanner';
|
|
3
|
+
import { ModuleCompiler } from '../compiler';
|
|
4
|
+
import { NestContainer } from '../container';
|
|
5
5
|
export declare class InternalCoreModuleFactory {
|
|
6
6
|
static create(container: NestContainer, scanner: DependenciesScanner, moduleCompiler: ModuleCompiler, httpAdapterHost: HttpAdapterHost): import("@nestjs/common").DynamicModule;
|
|
7
7
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InternalCoreModuleFactory = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const external_context_creator_1 = require("
|
|
6
|
-
const http_adapter_host_1 = require("
|
|
7
|
-
const instance_loader_1 = require("
|
|
5
|
+
const external_context_creator_1 = require("../../helpers/external-context-creator");
|
|
6
|
+
const http_adapter_host_1 = require("../../helpers/http-adapter-host");
|
|
7
|
+
const instance_loader_1 = require("../instance-loader");
|
|
8
|
+
const lazy_module_loader_1 = require("../lazy-module-loader/lazy-module-loader");
|
|
9
|
+
const modules_container_1 = require("../modules-container");
|
|
8
10
|
const internal_core_module_1 = require("./internal-core-module");
|
|
9
|
-
const lazy_module_loader_1 = require("./lazy-module-loader");
|
|
10
|
-
const modules_container_1 = require("./modules-container");
|
|
11
11
|
class InternalCoreModuleFactory {
|
|
12
12
|
static create(container, scanner, moduleCompiler, httpAdapterHost) {
|
|
13
13
|
return internal_core_module_1.InternalCoreModule.register([
|
package/injector/{internal-core-module.d.ts → internal-core-module/internal-core-module.d.ts}
RENAMED
|
File without changes
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.InternalCoreModule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
|
-
const request_providers_1 = require("
|
|
8
|
-
const services_1 = require("
|
|
9
|
-
const inquirer_providers_1 = require("
|
|
7
|
+
const request_providers_1 = require("../../router/request/request-providers");
|
|
8
|
+
const services_1 = require("../../services");
|
|
9
|
+
const inquirer_providers_1 = require("../inquirer/inquirer-providers");
|
|
10
10
|
const ReflectorAliasProvider = {
|
|
11
11
|
provide: services_1.Reflector.name,
|
|
12
12
|
useExisting: services_1.Reflector,
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
-
import { DependenciesScanner } from '
|
|
3
|
-
import { ModuleCompiler } from '
|
|
4
|
-
import { InstanceLoader } from '
|
|
2
|
+
import { DependenciesScanner } from '../../scanner';
|
|
3
|
+
import { ModuleCompiler } from '../compiler';
|
|
4
|
+
import { InstanceLoader } from '../instance-loader';
|
|
5
|
+
import { ModuleRef } from '../module-ref';
|
|
6
|
+
import { ModulesContainer } from '../modules-container';
|
|
5
7
|
import { LazyModuleLoaderLoadOptions } from './lazy-module-loader-options.interface';
|
|
6
|
-
import { ModuleRef } from './module-ref';
|
|
7
|
-
import { ModulesContainer } from './modules-container';
|
|
8
8
|
export declare class LazyModuleLoader {
|
|
9
9
|
private readonly dependenciesScanner;
|
|
10
10
|
private readonly instanceLoader;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LazyModuleLoader = void 0;
|
|
4
|
-
const silent_logger_1 = require("
|
|
5
|
-
const module_ref_1 = require("
|
|
4
|
+
const silent_logger_1 = require("../helpers/silent-logger");
|
|
5
|
+
const module_ref_1 = require("../module-ref");
|
|
6
6
|
class LazyModuleLoader {
|
|
7
7
|
constructor(dependenciesScanner, instanceLoader, moduleCompiler, modulesContainer) {
|
|
8
8
|
this.dependenciesScanner = dependenciesScanner;
|
package/injector/module-ref.d.ts
CHANGED
|
@@ -1,25 +1,84 @@
|
|
|
1
1
|
import { IntrospectionResult, Type } from '@nestjs/common';
|
|
2
|
+
import { GetOrResolveOptions } from '@nestjs/common/interfaces';
|
|
3
|
+
import { AbstractInstanceResolver } from './abstract-instance-resolver';
|
|
2
4
|
import { NestContainer } from './container';
|
|
5
|
+
import { Injector } from './injector';
|
|
6
|
+
import { InstanceLinksHost } from './instance-links-host';
|
|
3
7
|
import { ContextId } from './instance-wrapper';
|
|
4
8
|
import { Module } from './module';
|
|
5
|
-
export declare abstract class ModuleRef {
|
|
9
|
+
export declare abstract class ModuleRef extends AbstractInstanceResolver {
|
|
6
10
|
protected readonly container: NestContainer;
|
|
7
|
-
|
|
11
|
+
protected readonly injector: Injector;
|
|
8
12
|
private _instanceLinksHost;
|
|
9
|
-
|
|
13
|
+
protected get instanceLinksHost(): InstanceLinksHost;
|
|
10
14
|
constructor(container: NestContainer);
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
17
|
+
* @returns {TResult}
|
|
18
|
+
*/
|
|
19
|
+
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
22
|
+
* @returns {TResult}
|
|
23
|
+
*/
|
|
24
|
+
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
25
|
+
strict?: boolean;
|
|
26
|
+
each?: undefined | false;
|
|
13
27
|
}): TResult;
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
|
|
30
|
+
* @returns {Array<TResult>}
|
|
31
|
+
*/
|
|
32
|
+
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
33
|
+
strict?: boolean;
|
|
34
|
+
each: true;
|
|
35
|
+
}): Array<TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
38
|
+
* @returns {TResult | Array<TResult>}
|
|
39
|
+
*/
|
|
40
|
+
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: GetOrResolveOptions): TResult | Array<TResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
43
|
+
* @returns {Array<TResult>}
|
|
44
|
+
*/
|
|
45
|
+
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
48
|
+
* @returns {Array<TResult>}
|
|
49
|
+
*/
|
|
50
|
+
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
51
|
+
id: number;
|
|
16
52
|
}): Promise<TResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
55
|
+
* @returns {Array<TResult>}
|
|
56
|
+
*/
|
|
57
|
+
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
58
|
+
id: number;
|
|
59
|
+
}, options?: {
|
|
60
|
+
strict?: boolean;
|
|
61
|
+
each?: undefined | false;
|
|
62
|
+
}): Promise<TResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
|
|
65
|
+
* @returns {Array<TResult>}
|
|
66
|
+
*/
|
|
67
|
+
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
68
|
+
id: number;
|
|
69
|
+
}, options?: {
|
|
70
|
+
strict?: boolean;
|
|
71
|
+
each: true;
|
|
72
|
+
}): Promise<Array<TResult>>;
|
|
73
|
+
/**
|
|
74
|
+
* Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
75
|
+
* @returns {Promise<TResult | Array<TResult>>}
|
|
76
|
+
*/
|
|
77
|
+
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
78
|
+
id: number;
|
|
79
|
+
}, options?: GetOrResolveOptions): Promise<TResult | Array<TResult>>;
|
|
17
80
|
abstract create<T = any>(type: Type<T>): Promise<T>;
|
|
18
81
|
introspect<T = any>(token: Type<T> | string | symbol): IntrospectionResult;
|
|
19
82
|
registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
|
|
20
|
-
protected find<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | string | symbol, contextModule?: Module): TResult;
|
|
21
|
-
protected resolvePerContext<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | string | symbol, contextModule: Module, contextId: ContextId, options?: {
|
|
22
|
-
strict: boolean;
|
|
23
|
-
}): Promise<TResult>;
|
|
24
83
|
protected instantiateClass<T = any>(type: Type<T>, moduleRef: Module): Promise<T>;
|
|
25
84
|
}
|
package/injector/module-ref.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModuleRef = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const exceptions_1 = require("../errors/exceptions");
|
|
6
5
|
const get_class_scope_1 = require("../helpers/get-class-scope");
|
|
7
6
|
const is_durable_1 = require("../helpers/is-durable");
|
|
7
|
+
const abstract_instance_resolver_1 = require("./abstract-instance-resolver");
|
|
8
8
|
const injector_1 = require("./injector");
|
|
9
9
|
const instance_links_host_1 = require("./instance-links-host");
|
|
10
10
|
const instance_wrapper_1 = require("./instance-wrapper");
|
|
11
|
-
class ModuleRef {
|
|
11
|
+
class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
12
12
|
constructor(container) {
|
|
13
|
+
super();
|
|
13
14
|
this.container = container;
|
|
14
15
|
this.injector = new injector_1.Injector();
|
|
15
16
|
}
|
|
@@ -33,31 +34,6 @@ class ModuleRef {
|
|
|
33
34
|
registerRequestByContextId(request, contextId) {
|
|
34
35
|
this.container.registerRequestProvider(request, contextId);
|
|
35
36
|
}
|
|
36
|
-
find(typeOrToken, contextModule) {
|
|
37
|
-
const moduleId = contextModule && contextModule.id;
|
|
38
|
-
const { wrapperRef } = this.instanceLinksHost.get(typeOrToken, moduleId);
|
|
39
|
-
if (wrapperRef.scope === common_1.Scope.REQUEST ||
|
|
40
|
-
wrapperRef.scope === common_1.Scope.TRANSIENT) {
|
|
41
|
-
throw new exceptions_1.InvalidClassScopeException(typeOrToken);
|
|
42
|
-
}
|
|
43
|
-
return wrapperRef.instance;
|
|
44
|
-
}
|
|
45
|
-
async resolvePerContext(typeOrToken, contextModule, contextId, options) {
|
|
46
|
-
const isStrictModeEnabled = options && options.strict;
|
|
47
|
-
const instanceLink = isStrictModeEnabled
|
|
48
|
-
? this.instanceLinksHost.get(typeOrToken, contextModule.id)
|
|
49
|
-
: this.instanceLinksHost.get(typeOrToken);
|
|
50
|
-
const { wrapperRef, collection } = instanceLink;
|
|
51
|
-
if (wrapperRef.isDependencyTreeStatic() && !wrapperRef.isTransient) {
|
|
52
|
-
return this.get(typeOrToken, options);
|
|
53
|
-
}
|
|
54
|
-
const ctorHost = wrapperRef.instance || { constructor: typeOrToken };
|
|
55
|
-
const instance = await this.injector.loadPerContext(ctorHost, wrapperRef.host, collection, contextId, wrapperRef);
|
|
56
|
-
if (!instance) {
|
|
57
|
-
throw new exceptions_1.UnknownElementException();
|
|
58
|
-
}
|
|
59
|
-
return instance;
|
|
60
|
-
}
|
|
61
37
|
async instantiateClass(type, moduleRef) {
|
|
62
38
|
const wrapper = new instance_wrapper_1.InstanceWrapper({
|
|
63
39
|
name: type && type.name,
|
package/injector/module.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ClassProvider, Controller, DynamicModule, ExistingProvider, FactoryProvider, Injectable, InjectionToken, NestModule, Provider, ValueProvider } from '@nestjs/common/interfaces';
|
|
2
|
-
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
1
|
+
import { ClassProvider, Controller, DynamicModule, ExistingProvider, FactoryProvider, Injectable, InjectionToken, NestModule, Provider, Type, ValueProvider } from '@nestjs/common/interfaces';
|
|
3
2
|
import { NestContainer } from './container';
|
|
4
3
|
import { InstanceWrapper } from './instance-wrapper';
|
|
5
4
|
import { ModuleRef } from './module-ref';
|
package/injector/module.js
CHANGED
|
@@ -345,8 +345,11 @@ class Module {
|
|
|
345
345
|
}
|
|
346
346
|
get(typeOrToken, options = { strict: true }) {
|
|
347
347
|
return !(options && options.strict)
|
|
348
|
-
? this.find(typeOrToken)
|
|
349
|
-
: this.find(typeOrToken,
|
|
348
|
+
? this.find(typeOrToken, options)
|
|
349
|
+
: this.find(typeOrToken, {
|
|
350
|
+
moduleId: self.id,
|
|
351
|
+
each: options.each,
|
|
352
|
+
});
|
|
350
353
|
}
|
|
351
354
|
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = { strict: true }) {
|
|
352
355
|
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
package/middleware/builder.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HttpServer, MiddlewareConsumer, Type } from '@nestjs/common/interfaces';
|
|
2
|
-
import { MiddlewareConfigProxy } from '@nestjs/common/interfaces/middleware';
|
|
3
|
-
import { MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware/middleware-configuration.interface';
|
|
2
|
+
import { MiddlewareConfigProxy, MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware';
|
|
4
3
|
import { RoutesMapper } from './routes-mapper';
|
|
5
4
|
export declare class MiddlewareBuilder implements MiddlewareConsumer {
|
|
6
5
|
private readonly routesMapper;
|
|
@@ -4,8 +4,10 @@ import { ApplicationConfig } from '../application-config';
|
|
|
4
4
|
import { NestContainer } from '../injector/container';
|
|
5
5
|
import { Injector } from '../injector/injector';
|
|
6
6
|
import { Module } from '../injector/module';
|
|
7
|
+
import { RoutePathFactory } from '../router/route-path-factory';
|
|
7
8
|
import { MiddlewareContainer } from './container';
|
|
8
9
|
export declare class MiddlewareModule {
|
|
10
|
+
private readonly routePathFactory;
|
|
9
11
|
private readonly routerProxy;
|
|
10
12
|
private readonly exceptionFiltersCache;
|
|
11
13
|
private injector;
|
|
@@ -15,6 +17,7 @@ export declare class MiddlewareModule {
|
|
|
15
17
|
private config;
|
|
16
18
|
private container;
|
|
17
19
|
private httpAdapter;
|
|
20
|
+
constructor(routePathFactory: RoutePathFactory);
|
|
18
21
|
register(middlewareContainer: MiddlewareContainer, container: NestContainer, config: ApplicationConfig, injector: Injector, httpAdapter: HttpServer): Promise<void>;
|
|
19
22
|
resolveMiddleware(middlewareContainer: MiddlewareContainer, modules: Map<string, Module>): Promise<void>;
|
|
20
23
|
loadConfiguration(middlewareContainer: MiddlewareContainer, moduleRef: Module, moduleKey: string): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MiddlewareModule = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
4
5
|
const request_method_enum_1 = require("@nestjs/common/enums/request-method.enum");
|
|
5
6
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
7
|
const invalid_middleware_exception_1 = require("../errors/exceptions/invalid-middleware.exception");
|
|
@@ -16,7 +17,8 @@ const builder_1 = require("./builder");
|
|
|
16
17
|
const resolver_1 = require("./resolver");
|
|
17
18
|
const routes_mapper_1 = require("./routes-mapper");
|
|
18
19
|
class MiddlewareModule {
|
|
19
|
-
constructor() {
|
|
20
|
+
constructor(routePathFactory) {
|
|
21
|
+
this.routePathFactory = routePathFactory;
|
|
20
22
|
this.routerProxy = new router_proxy_1.RouterProxy();
|
|
21
23
|
this.exceptionFiltersCache = new WeakMap();
|
|
22
24
|
}
|
|
@@ -86,10 +88,10 @@ class MiddlewareModule {
|
|
|
86
88
|
if (instanceWrapper.isTransient) {
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
|
-
await this.bindHandler(instanceWrapper, applicationRef, routeInfo
|
|
91
|
+
await this.bindHandler(instanceWrapper, applicationRef, routeInfo, moduleRef, collection);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
async bindHandler(wrapper, applicationRef,
|
|
94
|
+
async bindHandler(wrapper, applicationRef, routeInfo, moduleRef, collection) {
|
|
93
95
|
const { instance, metatype } = wrapper;
|
|
94
96
|
if ((0, shared_utils_1.isUndefined)(instance === null || instance === void 0 ? void 0 : instance.use)) {
|
|
95
97
|
throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
|
|
@@ -97,9 +99,9 @@ class MiddlewareModule {
|
|
|
97
99
|
const isStatic = wrapper.isDependencyTreeStatic();
|
|
98
100
|
if (isStatic) {
|
|
99
101
|
const proxy = await this.createProxy(instance);
|
|
100
|
-
return this.registerHandler(applicationRef,
|
|
102
|
+
return this.registerHandler(applicationRef, routeInfo, proxy);
|
|
101
103
|
}
|
|
102
|
-
await this.registerHandler(applicationRef,
|
|
104
|
+
await this.registerHandler(applicationRef, routeInfo, async (req, res, next) => {
|
|
103
105
|
try {
|
|
104
106
|
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(req);
|
|
105
107
|
if (!req[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
@@ -131,7 +133,7 @@ class MiddlewareModule {
|
|
|
131
133
|
const middleware = instance.use.bind(instance);
|
|
132
134
|
return this.routerProxy.createProxy(middleware, exceptionsHandler);
|
|
133
135
|
}
|
|
134
|
-
async registerHandler(applicationRef, method,
|
|
136
|
+
async registerHandler(applicationRef, { path, method, version }, proxy) {
|
|
135
137
|
const prefix = this.config.getGlobalPrefix();
|
|
136
138
|
const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
|
|
137
139
|
if ((Array.isArray(excludedRoutes) &&
|
|
@@ -148,6 +150,11 @@ class MiddlewareModule {
|
|
|
148
150
|
}
|
|
149
151
|
path = basePath + path;
|
|
150
152
|
}
|
|
153
|
+
const applicationVersioningConfig = this.config.getVersioning();
|
|
154
|
+
if (version && applicationVersioningConfig.type === common_1.VersioningType.URI) {
|
|
155
|
+
const versionPrefix = this.routePathFactory.getVersionPrefix(applicationVersioningConfig);
|
|
156
|
+
path = `/${versionPrefix}${version.toString()}${path}`;
|
|
157
|
+
}
|
|
151
158
|
const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
|
|
152
159
|
const requestMethod = request_method_enum_1.RequestMethod[method];
|
|
153
160
|
const router = await applicationRef.createMiddlewareFactory(method);
|
|
@@ -5,6 +5,9 @@ export declare class RoutesMapper {
|
|
|
5
5
|
private readonly routerExplorer;
|
|
6
6
|
constructor(container: NestContainer);
|
|
7
7
|
mapRouteToRouteInfo(route: Type<any> | RouteInfo | string): RouteInfo[];
|
|
8
|
+
private getRouteInfoFromPath;
|
|
9
|
+
private getRouteInfoFromObject;
|
|
10
|
+
private getRouteInfoFromController;
|
|
8
11
|
private isRouteInfo;
|
|
9
12
|
private normalizeGlobalPath;
|
|
10
13
|
private getRoutePath;
|
|
@@ -13,39 +13,54 @@ class RoutesMapper {
|
|
|
13
13
|
}
|
|
14
14
|
mapRouteToRouteInfo(route) {
|
|
15
15
|
if ((0, shared_utils_1.isString)(route)) {
|
|
16
|
-
|
|
17
|
-
return [
|
|
18
|
-
{
|
|
19
|
-
path: (0, shared_utils_1.addLeadingSlash)(route),
|
|
20
|
-
method: defaultRequestMethod,
|
|
21
|
-
},
|
|
22
|
-
];
|
|
16
|
+
return this.getRouteInfoFromPath(route);
|
|
23
17
|
}
|
|
24
18
|
const routePathOrPaths = this.getRoutePath(route);
|
|
25
19
|
if (this.isRouteInfo(routePathOrPaths, route)) {
|
|
26
|
-
return
|
|
27
|
-
{
|
|
28
|
-
path: (0, shared_utils_1.addLeadingSlash)(route.path),
|
|
29
|
-
method: route.method,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
20
|
+
return this.getRouteInfoFromObject(route);
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
return this.getRouteInfoFromController(route, routePathOrPaths);
|
|
23
|
+
}
|
|
24
|
+
getRouteInfoFromPath(routePath) {
|
|
25
|
+
const defaultRequestMethod = -1;
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
path: (0, shared_utils_1.addLeadingSlash)(routePath),
|
|
29
|
+
method: defaultRequestMethod,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
getRouteInfoFromObject(routeInfoObject) {
|
|
34
|
+
const routeInfo = {
|
|
35
|
+
path: (0, shared_utils_1.addLeadingSlash)(routeInfoObject.path),
|
|
36
|
+
method: routeInfoObject.method,
|
|
37
|
+
};
|
|
38
|
+
if (routeInfoObject.version) {
|
|
39
|
+
routeInfo.version = routeInfoObject.version;
|
|
40
|
+
}
|
|
41
|
+
return [routeInfo];
|
|
42
|
+
}
|
|
43
|
+
getRouteInfoFromController(controller, routePath) {
|
|
44
|
+
const controllerPaths = this.routerExplorer.scanForPaths(Object.create(controller), controller.prototype);
|
|
45
|
+
const moduleRef = this.getHostModuleOfController(controller);
|
|
35
46
|
const modulePath = this.getModulePath(moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype);
|
|
36
47
|
const concatPaths = (acc, currentValue) => acc.concat(currentValue);
|
|
37
48
|
return []
|
|
38
|
-
.concat(
|
|
49
|
+
.concat(routePath)
|
|
39
50
|
.map(routePath => controllerPaths
|
|
40
51
|
.map(item => {
|
|
41
52
|
var _a;
|
|
42
53
|
return (_a = item.path) === null || _a === void 0 ? void 0 : _a.map(p => {
|
|
43
54
|
let path = modulePath !== null && modulePath !== void 0 ? modulePath : '';
|
|
44
55
|
path += this.normalizeGlobalPath(routePath) + (0, shared_utils_1.addLeadingSlash)(p);
|
|
45
|
-
|
|
56
|
+
const routeInfo = {
|
|
46
57
|
path,
|
|
47
58
|
method: item.requestMethod,
|
|
48
59
|
};
|
|
60
|
+
if (item.version) {
|
|
61
|
+
routeInfo.version = item.version;
|
|
62
|
+
}
|
|
63
|
+
return routeInfo;
|
|
49
64
|
});
|
|
50
65
|
})
|
|
51
66
|
.reduce(concatPaths, []))
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { INestApplicationContext, LoggerService, LogLevel, ShutdownSignal } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { DynamicModule, Type } from '@nestjs/common/interfaces';
|
|
3
|
+
import { AbstractInstanceResolver } from './injector/abstract-instance-resolver';
|
|
4
4
|
import { NestContainer } from './injector/container';
|
|
5
5
|
import { Injector } from './injector/injector';
|
|
6
|
+
import { InstanceLinksHost } from './injector/instance-links-host';
|
|
6
7
|
import { ContextId } from './injector/instance-wrapper';
|
|
7
8
|
import { Module } from './injector/module';
|
|
8
9
|
/**
|
|
9
10
|
* @publicApi
|
|
10
11
|
*/
|
|
11
|
-
export declare class NestApplicationContext implements INestApplicationContext {
|
|
12
|
+
export declare class NestApplicationContext extends AbstractInstanceResolver implements INestApplicationContext {
|
|
12
13
|
protected readonly container: NestContainer;
|
|
13
14
|
private readonly scope;
|
|
14
15
|
private contextModule;
|
|
@@ -20,16 +21,71 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
20
21
|
private shutdownCleanupRef?;
|
|
21
22
|
private _instanceLinksHost;
|
|
22
23
|
private _moduleRefsByDistance?;
|
|
23
|
-
|
|
24
|
+
protected get instanceLinksHost(): InstanceLinksHost;
|
|
24
25
|
constructor(container: NestContainer, scope?: Type<any>[], contextModule?: Module);
|
|
25
26
|
selectContextModule(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
|
|
29
|
+
* @returns {INestApplicationContext}
|
|
30
|
+
*/
|
|
26
31
|
select<T>(moduleType: Type<T> | DynamicModule): INestApplicationContext;
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
34
|
+
* @returns {TResult}
|
|
35
|
+
*/
|
|
36
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
39
|
+
* @returns {TResult}
|
|
40
|
+
*/
|
|
41
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
42
|
+
strict?: boolean;
|
|
43
|
+
each?: undefined | false;
|
|
29
44
|
}): TResult;
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
|
|
47
|
+
* @returns {Array<TResult>}
|
|
48
|
+
*/
|
|
49
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
50
|
+
strict?: boolean;
|
|
51
|
+
each: true;
|
|
52
|
+
}): Array<TResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
55
|
+
* @returns {Array<TResult>}
|
|
56
|
+
*/
|
|
57
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
60
|
+
* @returns {Array<TResult>}
|
|
61
|
+
*/
|
|
62
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
63
|
+
id: number;
|
|
64
|
+
}): Promise<TResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
67
|
+
* @returns {Array<TResult>}
|
|
68
|
+
*/
|
|
69
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
70
|
+
id: number;
|
|
71
|
+
}, options?: {
|
|
72
|
+
strict?: boolean;
|
|
73
|
+
each?: undefined | false;
|
|
32
74
|
}): Promise<TResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
|
|
77
|
+
* @returns {Array<TResult>}
|
|
78
|
+
*/
|
|
79
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
80
|
+
id: number;
|
|
81
|
+
}, options?: {
|
|
82
|
+
strict?: boolean;
|
|
83
|
+
each: true;
|
|
84
|
+
}): Promise<Array<TResult>>;
|
|
85
|
+
/**
|
|
86
|
+
* Registers the request/context object for a given context ID (DI container sub-tree).
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
33
89
|
registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
|
|
34
90
|
/**
|
|
35
91
|
* Initializes the Nest application.
|
|
@@ -38,8 +94,21 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
38
94
|
* @returns {Promise<this>} The NestApplicationContext instance as Promise
|
|
39
95
|
*/
|
|
40
96
|
init(): Promise<this>;
|
|
97
|
+
/**
|
|
98
|
+
* Terminates the application
|
|
99
|
+
* @returns {Promise<void>}
|
|
100
|
+
*/
|
|
41
101
|
close(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Sets custom logger service.
|
|
104
|
+
* Flushes buffered logs if auto flush is on.
|
|
105
|
+
* @returns {void}
|
|
106
|
+
*/
|
|
42
107
|
useLogger(logger: LoggerService | LogLevel[] | false): void;
|
|
108
|
+
/**
|
|
109
|
+
* Prints buffered logs and detaches buffer.
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
43
112
|
flushLogs(): void;
|
|
44
113
|
/**
|
|
45
114
|
* Define that it must flush logs right after defining a custom logger.
|
|
@@ -92,9 +161,5 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
92
161
|
* modules and children.
|
|
93
162
|
*/
|
|
94
163
|
protected callBeforeShutdownHook(signal?: string): Promise<void>;
|
|
95
|
-
protected find<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule?: Module): TResult;
|
|
96
|
-
protected resolvePerContext<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule: Module, contextId: ContextId, options?: {
|
|
97
|
-
strict: boolean;
|
|
98
|
-
}): Promise<TResult>;
|
|
99
164
|
private getModulesSortedByDistance;
|
|
100
165
|
}
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NestApplicationContext = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const interfaces_1 = require("@nestjs/common/interfaces");
|
|
6
5
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
6
|
const iterare_1 = require("iterare");
|
|
8
7
|
const constants_1 = require("./constants");
|
|
9
8
|
const exceptions_1 = require("./errors/exceptions");
|
|
10
9
|
const context_id_factory_1 = require("./helpers/context-id-factory");
|
|
11
10
|
const hooks_1 = require("./hooks");
|
|
11
|
+
const abstract_instance_resolver_1 = require("./injector/abstract-instance-resolver");
|
|
12
12
|
const compiler_1 = require("./injector/compiler");
|
|
13
13
|
const injector_1 = require("./injector/injector");
|
|
14
14
|
const instance_links_host_1 = require("./injector/instance-links-host");
|
|
15
15
|
/**
|
|
16
16
|
* @publicApi
|
|
17
17
|
*/
|
|
18
|
-
class NestApplicationContext {
|
|
18
|
+
class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
19
19
|
constructor(container, scope = new Array(), contextModule = null) {
|
|
20
|
+
super();
|
|
20
21
|
this.container = container;
|
|
21
22
|
this.scope = scope;
|
|
22
23
|
this.contextModule = contextModule;
|
|
@@ -36,6 +37,10 @@ class NestApplicationContext {
|
|
|
36
37
|
const modules = this.container.getModules().values();
|
|
37
38
|
this.contextModule = modules.next().value;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
|
|
42
|
+
* @returns {INestApplicationContext}
|
|
43
|
+
*/
|
|
39
44
|
select(moduleType) {
|
|
40
45
|
const modulesContainer = this.container.getModules();
|
|
41
46
|
const contextModuleCtor = this.contextModule.metatype;
|
|
@@ -49,14 +54,30 @@ class NestApplicationContext {
|
|
|
49
54
|
}
|
|
50
55
|
return new NestApplicationContext(this.container, scope, selectedModule);
|
|
51
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
59
|
+
* @returns {TResult | Array<TResult>}
|
|
60
|
+
*/
|
|
52
61
|
get(typeOrToken, options = { strict: false }) {
|
|
62
|
+
var _a;
|
|
53
63
|
return !(options && options.strict)
|
|
54
|
-
? this.find(typeOrToken)
|
|
55
|
-
: this.find(typeOrToken,
|
|
64
|
+
? this.find(typeOrToken, options)
|
|
65
|
+
: this.find(typeOrToken, {
|
|
66
|
+
moduleId: (_a = this.contextModule) === null || _a === void 0 ? void 0 : _a.id,
|
|
67
|
+
each: options.each,
|
|
68
|
+
});
|
|
56
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
72
|
+
* @returns {Promise<TResult | Array<TResult>>}
|
|
73
|
+
*/
|
|
57
74
|
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = { strict: false }) {
|
|
58
75
|
return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
|
|
59
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers the request/context object for a given context ID (DI container sub-tree).
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
60
81
|
registerRequestByContextId(request, contextId) {
|
|
61
82
|
this.container.registerRequestProvider(request, contextId);
|
|
62
83
|
}
|
|
@@ -75,6 +96,10 @@ class NestApplicationContext {
|
|
|
75
96
|
this.isInitialized = true;
|
|
76
97
|
return this;
|
|
77
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Terminates the application
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
78
103
|
async close() {
|
|
79
104
|
await this.callDestroyHook();
|
|
80
105
|
await this.callBeforeShutdownHook();
|
|
@@ -82,12 +107,21 @@ class NestApplicationContext {
|
|
|
82
107
|
await this.callShutdownHook();
|
|
83
108
|
this.unsubscribeFromProcessSignals();
|
|
84
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Sets custom logger service.
|
|
112
|
+
* Flushes buffered logs if auto flush is on.
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
85
115
|
useLogger(logger) {
|
|
86
116
|
common_1.Logger.overrideLogger(logger);
|
|
87
117
|
if (this.shouldFlushLogsOnOverride) {
|
|
88
118
|
this.flushLogs();
|
|
89
119
|
}
|
|
90
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Prints buffered logs and detaches buffer.
|
|
123
|
+
* @returns {void}
|
|
124
|
+
*/
|
|
91
125
|
flushLogs() {
|
|
92
126
|
common_1.Logger.flush();
|
|
93
127
|
}
|
|
@@ -216,31 +250,6 @@ class NestApplicationContext {
|
|
|
216
250
|
await (0, hooks_1.callBeforeAppShutdownHook)(module, signal);
|
|
217
251
|
}
|
|
218
252
|
}
|
|
219
|
-
find(typeOrToken, contextModule) {
|
|
220
|
-
const moduleId = contextModule && contextModule.id;
|
|
221
|
-
const { wrapperRef } = this.instanceLinksHost.get(typeOrToken, moduleId);
|
|
222
|
-
if (wrapperRef.scope === interfaces_1.Scope.REQUEST ||
|
|
223
|
-
wrapperRef.scope === interfaces_1.Scope.TRANSIENT) {
|
|
224
|
-
throw new exceptions_1.InvalidClassScopeException(typeOrToken);
|
|
225
|
-
}
|
|
226
|
-
return wrapperRef.instance;
|
|
227
|
-
}
|
|
228
|
-
async resolvePerContext(typeOrToken, contextModule, contextId, options) {
|
|
229
|
-
const isStrictModeEnabled = options && options.strict;
|
|
230
|
-
const instanceLink = isStrictModeEnabled
|
|
231
|
-
? this.instanceLinksHost.get(typeOrToken, contextModule.id)
|
|
232
|
-
: this.instanceLinksHost.get(typeOrToken);
|
|
233
|
-
const { wrapperRef, collection } = instanceLink;
|
|
234
|
-
if (wrapperRef.isDependencyTreeStatic() && !wrapperRef.isTransient) {
|
|
235
|
-
return this.get(typeOrToken, options);
|
|
236
|
-
}
|
|
237
|
-
const ctorHost = wrapperRef.instance || { constructor: typeOrToken };
|
|
238
|
-
const instance = await this.injector.loadPerContext(ctorHost, wrapperRef.host, collection, contextId, wrapperRef);
|
|
239
|
-
if (!instance) {
|
|
240
|
-
throw new exceptions_1.UnknownElementException();
|
|
241
|
-
}
|
|
242
|
-
return instance;
|
|
243
|
-
}
|
|
244
253
|
getModulesSortedByDistance() {
|
|
245
254
|
if (this._moduleRefsByDistance) {
|
|
246
255
|
return this._moduleRefsByDistance;
|
package/nest-application.js
CHANGED
|
@@ -14,6 +14,7 @@ const optional_require_1 = require("./helpers/optional-require");
|
|
|
14
14
|
const container_1 = require("./middleware/container");
|
|
15
15
|
const middleware_module_1 = require("./middleware/middleware-module");
|
|
16
16
|
const nest_application_context_1 = require("./nest-application-context");
|
|
17
|
+
const route_path_factory_1 = require("./router/route-path-factory");
|
|
17
18
|
const routes_resolver_1 = require("./router/routes-resolver");
|
|
18
19
|
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
|
|
19
20
|
const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
|
|
@@ -29,7 +30,6 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
29
30
|
this.logger = new logger_service_1.Logger(NestApplication.name, {
|
|
30
31
|
timestamp: true,
|
|
31
32
|
});
|
|
32
|
-
this.middlewareModule = new middleware_module_1.MiddlewareModule();
|
|
33
33
|
this.middlewareContainer = new container_1.MiddlewareContainer(this.container);
|
|
34
34
|
this.microservicesModule = MicroservicesModule && new MicroservicesModule();
|
|
35
35
|
this.socketModule = SocketModule && new SocketModule();
|
|
@@ -37,6 +37,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
37
37
|
this.isListening = false;
|
|
38
38
|
this.selectContextModule();
|
|
39
39
|
this.registerHttpServer();
|
|
40
|
+
this.middlewareModule = new middleware_module_1.MiddlewareModule(new route_path_factory_1.RoutePathFactory(config));
|
|
40
41
|
this.routesResolver = new routes_resolver_1.RoutesResolver(this.container, this.config, this.injector);
|
|
41
42
|
}
|
|
42
43
|
async dispose() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"iterare": "1.2.1",
|
|
33
33
|
"object-hash": "3.0.0",
|
|
34
34
|
"path-to-regexp": "3.2.0",
|
|
35
|
-
"tslib": "2.4.
|
|
35
|
+
"tslib": "2.4.1",
|
|
36
36
|
"uuid": "9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "9.
|
|
39
|
+
"@nestjs/common": "9.2.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^9.0.0",
|
package/repl/repl-context.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.ReplContext = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const application_config_1 = require("../application-config");
|
|
6
6
|
const injector_1 = require("../injector");
|
|
7
|
-
const internal_core_module_1 = require("../injector/internal-core-module");
|
|
7
|
+
const internal_core_module_1 = require("../injector/internal-core-module/internal-core-module");
|
|
8
8
|
const native_functions_1 = require("./native-functions");
|
|
9
9
|
class ReplContext {
|
|
10
10
|
constructor(app, nativeFunctionsClassRefs) {
|
package/repl/repl.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Type } from '@nestjs/common';
|
|
3
|
-
export declare function repl(module: Type): Promise<import("repl").REPLServer>;
|
|
2
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
3
|
+
export declare function repl(module: Type | DynamicModule): Promise<import("repl").REPLServer>;
|
|
@@ -174,6 +174,7 @@ class RouterExecutionContext {
|
|
|
174
174
|
result = await this.responseController.transformToResult(result);
|
|
175
175
|
!isResponseHandled &&
|
|
176
176
|
(await this.responseController.apply(result, res, httpStatusCode));
|
|
177
|
+
return res;
|
|
177
178
|
};
|
|
178
179
|
}
|
|
179
180
|
isResponseHandled(instance, methodName, paramsMetadata) {
|
|
@@ -53,7 +53,7 @@ class RouterExplorer {
|
|
|
53
53
|
extractRouterPath(metatype) {
|
|
54
54
|
const path = Reflect.getMetadata(constants_1.PATH_METADATA, metatype);
|
|
55
55
|
if ((0, shared_utils_1.isUndefined)(path)) {
|
|
56
|
-
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException();
|
|
56
|
+
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException(metatype);
|
|
57
57
|
}
|
|
58
58
|
if (Array.isArray(path)) {
|
|
59
59
|
return path.map(p => (0, shared_utils_1.addLeadingSlash)(p));
|
package/scanner.js
CHANGED
|
@@ -14,7 +14,7 @@ const invalid_class_module_exception_1 = require("./errors/exceptions/invalid-cl
|
|
|
14
14
|
const invalid_module_exception_1 = require("./errors/exceptions/invalid-module.exception");
|
|
15
15
|
const undefined_module_exception_1 = require("./errors/exceptions/undefined-module.exception");
|
|
16
16
|
const get_class_scope_1 = require("./helpers/get-class-scope");
|
|
17
|
-
const internal_core_module_factory_1 = require("./injector/internal-core-module-factory");
|
|
17
|
+
const internal_core_module_factory_1 = require("./injector/internal-core-module/internal-core-module-factory");
|
|
18
18
|
class DependenciesScanner {
|
|
19
19
|
constructor(container, metadataScanner, applicationConfig = new application_config_1.ApplicationConfig()) {
|
|
20
20
|
this.container = container;
|