@nestjs/core 9.1.5 → 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/index.d.ts +8 -0
- package/errors/exceptions/index.js +11 -0
- 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/guards/index.d.ts +3 -0
- package/guards/index.js +6 -0
- 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 +8 -10
- 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 -28
- package/injector/module.d.ts +1 -2
- package/injector/module.js +9 -8
- package/interceptors/index.d.ts +2 -0
- package/interceptors/index.js +5 -0
- package/middleware/builder.d.ts +1 -2
- package/middleware/middleware-module.d.ts +4 -1
- 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 +40 -33
- package/nest-application.d.ts +1 -2
- package/nest-application.js +2 -1
- package/package.json +3 -3
- package/pipes/index.d.ts +3 -0
- package/pipes/index.js +6 -0
- package/repl/repl-context.js +1 -1
- package/repl/repl.d.ts +2 -2
- package/router/router-execution-context.d.ts +1 -2
- package/router/router-execution-context.js +7 -6
- package/router/router-explorer.d.ts +1 -1
- package/router/router-explorer.js +3 -3
- package/router/routes-resolver.d.ts +1 -2
- 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
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './circular-dependency.exception';
|
|
2
|
+
export * from './runtime.exception';
|
|
3
|
+
export * from './unknown-element.exception';
|
|
4
|
+
export * from './invalid-class-scope.exception';
|
|
5
|
+
export * from './invalid-class.exception';
|
|
6
|
+
export * from './unknown-export.exception';
|
|
7
|
+
export * from './unknown-module.exception';
|
|
8
|
+
export * from './undefined-forwardref.exception';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./circular-dependency.exception"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./runtime.exception"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./unknown-element.exception"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./invalid-class-scope.exception"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./invalid-class.exception"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./unknown-export.exception"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./unknown-module.exception"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./undefined-forwardref.exception"), exports);
|
|
@@ -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.)`;
|
package/guards/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./constants"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./guards-consumer"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./guards-context-creator"), exports);
|
|
@@ -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
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NestContainer = void 0;
|
|
4
4
|
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
-
const
|
|
6
|
-
const undefined_forwardref_exception_1 = require("../errors/exceptions/undefined-forwardref.exception");
|
|
7
|
-
const unknown_module_exception_1 = require("../errors/exceptions/unknown-module.exception");
|
|
5
|
+
const exceptions_1 = require("../errors/exceptions");
|
|
8
6
|
const request_constants_1 = require("../router/request/request-constants");
|
|
9
7
|
const compiler_1 = require("./compiler");
|
|
10
|
-
const internal_core_module_1 = require("./internal-core-module");
|
|
8
|
+
const internal_core_module_1 = require("./internal-core-module/internal-core-module");
|
|
11
9
|
const internal_providers_storage_1 = require("./internal-providers-storage");
|
|
12
10
|
const module_1 = require("./module");
|
|
13
11
|
const module_token_factory_1 = require("./module-token-factory");
|
|
@@ -43,7 +41,7 @@ class NestContainer {
|
|
|
43
41
|
// In DependenciesScanner#scanForModules we already check for undefined or invalid modules
|
|
44
42
|
// We still need to catch the edge-case of `forwardRef(() => undefined)`
|
|
45
43
|
if (!metatype) {
|
|
46
|
-
throw new
|
|
44
|
+
throw new exceptions_1.UndefinedForwardRefException(scope);
|
|
47
45
|
}
|
|
48
46
|
const { type, dynamicMetadata, token } = await this.moduleCompiler.compile(metatype);
|
|
49
47
|
if (this.modules.has(token)) {
|
|
@@ -105,30 +103,30 @@ class NestContainer {
|
|
|
105
103
|
addProvider(provider, token) {
|
|
106
104
|
const moduleRef = this.modules.get(token);
|
|
107
105
|
if (!provider) {
|
|
108
|
-
throw new
|
|
106
|
+
throw new exceptions_1.CircularDependencyException(moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype.name);
|
|
109
107
|
}
|
|
110
108
|
if (!moduleRef) {
|
|
111
|
-
throw new
|
|
109
|
+
throw new exceptions_1.UnknownModuleException();
|
|
112
110
|
}
|
|
113
111
|
return moduleRef.addProvider(provider);
|
|
114
112
|
}
|
|
115
113
|
addInjectable(injectable, token, host) {
|
|
116
114
|
if (!this.modules.has(token)) {
|
|
117
|
-
throw new
|
|
115
|
+
throw new exceptions_1.UnknownModuleException();
|
|
118
116
|
}
|
|
119
117
|
const moduleRef = this.modules.get(token);
|
|
120
118
|
moduleRef.addInjectable(injectable, host);
|
|
121
119
|
}
|
|
122
120
|
addExportedProvider(provider, token) {
|
|
123
121
|
if (!this.modules.has(token)) {
|
|
124
|
-
throw new
|
|
122
|
+
throw new exceptions_1.UnknownModuleException();
|
|
125
123
|
}
|
|
126
124
|
const moduleRef = this.modules.get(token);
|
|
127
125
|
moduleRef.addExportedProvider(provider);
|
|
128
126
|
}
|
|
129
127
|
addController(controller, token) {
|
|
130
128
|
if (!this.modules.has(token)) {
|
|
131
|
-
throw new
|
|
129
|
+
throw new exceptions_1.UnknownModuleException();
|
|
132
130
|
}
|
|
133
131
|
const moduleRef = this.modules.get(token);
|
|
134
132
|
moduleRef.addController(controller);
|
|
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,15 +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 invalid_class_scope_exception_1 = require("../errors/exceptions/invalid-class-scope.exception");
|
|
6
|
-
const unknown_element_exception_1 = require("../errors/exceptions/unknown-element.exception");
|
|
7
5
|
const get_class_scope_1 = require("../helpers/get-class-scope");
|
|
8
6
|
const is_durable_1 = require("../helpers/is-durable");
|
|
7
|
+
const abstract_instance_resolver_1 = require("./abstract-instance-resolver");
|
|
9
8
|
const injector_1 = require("./injector");
|
|
10
9
|
const instance_links_host_1 = require("./instance-links-host");
|
|
11
10
|
const instance_wrapper_1 = require("./instance-wrapper");
|
|
12
|
-
class ModuleRef {
|
|
11
|
+
class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
13
12
|
constructor(container) {
|
|
13
|
+
super();
|
|
14
14
|
this.container = container;
|
|
15
15
|
this.injector = new injector_1.Injector();
|
|
16
16
|
}
|
|
@@ -34,31 +34,6 @@ class ModuleRef {
|
|
|
34
34
|
registerRequestByContextId(request, contextId) {
|
|
35
35
|
this.container.registerRequestProvider(request, contextId);
|
|
36
36
|
}
|
|
37
|
-
find(typeOrToken, contextModule) {
|
|
38
|
-
const moduleId = contextModule && contextModule.id;
|
|
39
|
-
const { wrapperRef } = this.instanceLinksHost.get(typeOrToken, moduleId);
|
|
40
|
-
if (wrapperRef.scope === common_1.Scope.REQUEST ||
|
|
41
|
-
wrapperRef.scope === common_1.Scope.TRANSIENT) {
|
|
42
|
-
throw new invalid_class_scope_exception_1.InvalidClassScopeException(typeOrToken);
|
|
43
|
-
}
|
|
44
|
-
return wrapperRef.instance;
|
|
45
|
-
}
|
|
46
|
-
async resolvePerContext(typeOrToken, contextModule, contextId, options) {
|
|
47
|
-
const isStrictModeEnabled = options && options.strict;
|
|
48
|
-
const instanceLink = isStrictModeEnabled
|
|
49
|
-
? this.instanceLinksHost.get(typeOrToken, contextModule.id)
|
|
50
|
-
: this.instanceLinksHost.get(typeOrToken);
|
|
51
|
-
const { wrapperRef, collection } = instanceLink;
|
|
52
|
-
if (wrapperRef.isDependencyTreeStatic() && !wrapperRef.isTransient) {
|
|
53
|
-
return this.get(typeOrToken, options);
|
|
54
|
-
}
|
|
55
|
-
const ctorHost = wrapperRef.instance || { constructor: typeOrToken };
|
|
56
|
-
const instance = await this.injector.loadPerContext(ctorHost, wrapperRef.host, collection, contextId, wrapperRef);
|
|
57
|
-
if (!instance) {
|
|
58
|
-
throw new unknown_element_exception_1.UnknownElementException();
|
|
59
|
-
}
|
|
60
|
-
return instance;
|
|
61
|
-
}
|
|
62
37
|
async instantiateClass(type, moduleRef) {
|
|
63
38
|
const wrapper = new instance_wrapper_1.InstanceWrapper({
|
|
64
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
|
@@ -5,9 +5,7 @@ const random_string_generator_util_1 = require("@nestjs/common/utils/random-stri
|
|
|
5
5
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
6
|
const iterare_1 = require("iterare");
|
|
7
7
|
const application_config_1 = require("../application-config");
|
|
8
|
-
const
|
|
9
|
-
const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
|
|
10
|
-
const unknown_export_exception_1 = require("../errors/exceptions/unknown-export.exception");
|
|
8
|
+
const exceptions_1 = require("../errors/exceptions");
|
|
11
9
|
const context_id_factory_1 = require("../helpers/context-id-factory");
|
|
12
10
|
const get_class_scope_1 = require("../helpers/get-class-scope");
|
|
13
11
|
const is_durable_1 = require("../helpers/is-durable");
|
|
@@ -75,7 +73,7 @@ class Module {
|
|
|
75
73
|
}
|
|
76
74
|
get instance() {
|
|
77
75
|
if (!this._providers.has(this._metatype)) {
|
|
78
|
-
throw new
|
|
76
|
+
throw new exceptions_1.RuntimeException();
|
|
79
77
|
}
|
|
80
78
|
const module = this._providers.get(this._metatype);
|
|
81
79
|
return module.instance;
|
|
@@ -288,7 +286,7 @@ class Module {
|
|
|
288
286
|
if (!imports.includes(token)) {
|
|
289
287
|
const { name } = this.metatype;
|
|
290
288
|
const providerName = (0, shared_utils_1.isFunction)(token) ? token.name : token;
|
|
291
|
-
throw new
|
|
289
|
+
throw new exceptions_1.UnknownExportException(providerName, name);
|
|
292
290
|
}
|
|
293
291
|
return token;
|
|
294
292
|
}
|
|
@@ -347,15 +345,18 @@ class Module {
|
|
|
347
345
|
}
|
|
348
346
|
get(typeOrToken, options = { strict: true }) {
|
|
349
347
|
return !(options && options.strict)
|
|
350
|
-
? this.find(typeOrToken)
|
|
351
|
-
: this.find(typeOrToken,
|
|
348
|
+
? this.find(typeOrToken, options)
|
|
349
|
+
: this.find(typeOrToken, {
|
|
350
|
+
moduleId: self.id,
|
|
351
|
+
each: options.each,
|
|
352
|
+
});
|
|
352
353
|
}
|
|
353
354
|
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = { strict: true }) {
|
|
354
355
|
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
|
355
356
|
}
|
|
356
357
|
async create(type) {
|
|
357
358
|
if (!(type && (0, shared_utils_1.isFunction)(type) && type.prototype)) {
|
|
358
|
-
throw new
|
|
359
|
+
throw new exceptions_1.InvalidClassException(type);
|
|
359
360
|
}
|
|
360
361
|
return this.instantiateClass(type, self);
|
|
361
362
|
}
|