@nestjs/core 8.1.0 → 8.2.1
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/CHANGELOG.md +12 -0
- package/adapters/index.js +1 -1
- package/discovery/discovery-module.js +2 -2
- package/discovery/discovery-service.js +5 -5
- package/discovery/index.js +2 -2
- package/errors/exceptions/invalid-class-scope.exception.js +2 -2
- package/errors/exceptions/invalid-class.exception.js +1 -1
- package/errors/exceptions/invalid-middleware.exception.js +1 -1
- package/errors/exceptions/invalid-module.exception.js +1 -1
- package/errors/exceptions/undefined-dependency.exception.js +1 -1
- package/errors/exceptions/undefined-forwardref.exception.js +1 -1
- package/errors/exceptions/undefined-module.exception.js +1 -1
- package/errors/exceptions/unknown-dependencies.exception.js +1 -1
- package/errors/exceptions/unknown-export.exception.js +1 -1
- package/errors/messages.js +3 -3
- package/exceptions/base-exception-filter-context.js +3 -3
- package/exceptions/base-exception-filter.js +6 -6
- package/exceptions/exceptions-handler.js +1 -1
- package/exceptions/external-exception-filter-context.js +2 -2
- package/exceptions/external-exceptions-handler.js +1 -1
- package/exceptions/index.js +1 -1
- package/guards/guards-consumer.js +2 -2
- package/guards/guards-context-creator.js +4 -4
- package/helpers/context-utils.js +1 -1
- package/helpers/external-context-creator.js +3 -3
- package/helpers/index.js +2 -2
- package/helpers/interfaces/index.js +2 -2
- package/hooks/before-app-shutdown.hook.js +5 -5
- package/hooks/index.js +5 -5
- package/hooks/on-app-bootstrap.hook.js +5 -5
- package/hooks/on-app-shutdown.hook.js +5 -5
- package/hooks/on-module-destroy.hook.js +5 -5
- package/hooks/on-module-init.hook.js +5 -5
- package/index.js +12 -12
- package/injector/compiler.js +1 -1
- package/injector/helpers/transient-instances.js +2 -2
- package/injector/index.js +5 -5
- package/injector/injector.js +18 -18
- package/injector/inquirer/index.js +1 -1
- package/injector/instance-links-host.js +1 -1
- package/injector/instance-loader.js +1 -1
- package/injector/instance-wrapper.js +7 -7
- package/injector/internal-core-module.js +3 -3
- package/injector/module-ref.js +1 -1
- package/injector/module-token-factory.js +2 -2
- package/injector/module.js +18 -18
- package/injector/modules-container.js +1 -1
- package/interceptors/interceptors-consumer.js +4 -4
- package/interceptors/interceptors-context-creator.js +4 -4
- package/metadata-scanner.js +4 -4
- package/middleware/builder.js +3 -3
- package/middleware/index.js +1 -1
- package/middleware/middleware-module.js +6 -6
- package/middleware/routes-mapper.js +6 -6
- package/middleware/utils.js +5 -5
- package/nest-application-context.js +8 -8
- package/nest-application.js +14 -11
- package/nest-factory.js +6 -6
- package/package.json +2 -2
- package/pipes/pipes-context-creator.js +4 -4
- package/router/index.js +2 -2
- package/router/interfaces/index.js +1 -1
- package/router/route-path-factory.js +8 -8
- package/router/router-exception-filters.js +2 -2
- package/router/router-execution-context.js +3 -3
- package/router/router-explorer.js +12 -12
- package/router/router-module.js +6 -6
- package/router/router-response-controller.js +5 -5
- package/router/routes-resolver.js +2 -2
- package/router/utils/exclude-route.util.js +1 -1
- package/router/utils/flatten-route-paths.util.js +1 -1
- package/router/utils/index.js +2 -2
- package/scanner.js +9 -9
- package/services/index.js +1 -1
- package/services/reflector.service.js +2 -2
|
@@ -55,7 +55,7 @@ class NestApplicationContext {
|
|
|
55
55
|
? this.find(typeOrToken)
|
|
56
56
|
: this.find(typeOrToken, this.contextModule);
|
|
57
57
|
}
|
|
58
|
-
resolve(typeOrToken, contextId =
|
|
58
|
+
resolve(typeOrToken, contextId = context_id_factory_1.createContextId(), options = { strict: false }) {
|
|
59
59
|
return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
|
|
60
60
|
}
|
|
61
61
|
registerRequestByContextId(request, contextId) {
|
|
@@ -99,7 +99,7 @@ class NestApplicationContext {
|
|
|
99
99
|
* @returns {this} The Nest application context instance
|
|
100
100
|
*/
|
|
101
101
|
enableShutdownHooks(signals = []) {
|
|
102
|
-
if (
|
|
102
|
+
if (shared_utils_1.isEmpty(signals)) {
|
|
103
103
|
signals = Object.keys(common_1.ShutdownSignal).map((key) => common_1.ShutdownSignal[key]);
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
@@ -107,7 +107,7 @@ class NestApplicationContext {
|
|
|
107
107
|
// process shouldn't listen to the same signal more than once.
|
|
108
108
|
signals = Array.from(new Set(signals));
|
|
109
109
|
}
|
|
110
|
-
signals =
|
|
110
|
+
signals = iterare_1.iterate(signals)
|
|
111
111
|
.map((signal) => signal.toString().toUpperCase().trim())
|
|
112
112
|
// filter out the signals which is already listening to
|
|
113
113
|
.filter(signal => !this.activeShutdownSignals.includes(signal))
|
|
@@ -166,7 +166,7 @@ class NestApplicationContext {
|
|
|
166
166
|
async callInitHook() {
|
|
167
167
|
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
168
168
|
for (const module of modulesSortedByDistance) {
|
|
169
|
-
await
|
|
169
|
+
await hooks_1.callModuleInitHook(module);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
@@ -176,7 +176,7 @@ class NestApplicationContext {
|
|
|
176
176
|
async callDestroyHook() {
|
|
177
177
|
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
178
178
|
for (const module of modulesSortedByDistance) {
|
|
179
|
-
await
|
|
179
|
+
await hooks_1.callModuleDestroyHook(module);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
@@ -186,7 +186,7 @@ class NestApplicationContext {
|
|
|
186
186
|
async callBootstrapHook() {
|
|
187
187
|
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
188
188
|
for (const module of modulesSortedByDistance) {
|
|
189
|
-
await
|
|
189
|
+
await hooks_1.callModuleBootstrapHook(module);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
@@ -196,7 +196,7 @@ class NestApplicationContext {
|
|
|
196
196
|
async callShutdownHook(signal) {
|
|
197
197
|
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
198
198
|
for (const module of modulesSortedByDistance) {
|
|
199
|
-
await
|
|
199
|
+
await hooks_1.callAppShutdownHook(module, signal);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
@@ -206,7 +206,7 @@ class NestApplicationContext {
|
|
|
206
206
|
async callBeforeShutdownHook(signal) {
|
|
207
207
|
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
208
208
|
for (const module of modulesSortedByDistance) {
|
|
209
|
-
await
|
|
209
|
+
await hooks_1.callBeforeAppShutdownHook(module, signal);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
find(typeOrToken, contextModule) {
|
package/nest-application.js
CHANGED
|
@@ -15,8 +15,8 @@ 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
17
|
const routes_resolver_1 = require("./router/routes-resolver");
|
|
18
|
-
const { SocketModule } =
|
|
19
|
-
const { MicroservicesModule } =
|
|
18
|
+
const { SocketModule } = optional_require_1.optionalRequire('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
|
|
19
|
+
const { MicroservicesModule } = optional_require_1.optionalRequire('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
|
|
20
20
|
/**
|
|
21
21
|
* @publicApi
|
|
22
22
|
*/
|
|
@@ -43,7 +43,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
43
43
|
this.socketModule && (await this.socketModule.close());
|
|
44
44
|
this.microservicesModule && (await this.microservicesModule.close());
|
|
45
45
|
this.httpAdapter && (await this.httpAdapter.close());
|
|
46
|
-
await Promise.all(
|
|
46
|
+
await Promise.all(iterare_1.iterate(this.microservices).map(async (microservice) => {
|
|
47
47
|
microservice.setIsTerminated(true);
|
|
48
48
|
await microservice.close();
|
|
49
49
|
}));
|
|
@@ -61,7 +61,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
61
61
|
if (!this.appOptions || !this.appOptions.cors) {
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
|
-
const passCustomOptions =
|
|
64
|
+
const passCustomOptions = shared_utils_1.isObject(this.appOptions.cors) ||
|
|
65
65
|
typeof this.appOptions.cors === 'function';
|
|
66
66
|
if (!passCustomOptions) {
|
|
67
67
|
return this.enableCors();
|
|
@@ -107,7 +107,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
107
107
|
async registerRouter() {
|
|
108
108
|
await this.registerMiddleware(this.httpAdapter);
|
|
109
109
|
const prefix = this.config.getGlobalPrefix();
|
|
110
|
-
const basePath =
|
|
110
|
+
const basePath = shared_utils_1.addLeadingSlash(prefix);
|
|
111
111
|
this.routesResolver.resolve(this.httpAdapter, basePath);
|
|
112
112
|
}
|
|
113
113
|
async registerRouterHooks() {
|
|
@@ -115,7 +115,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
115
115
|
this.routesResolver.registerExceptionHandler();
|
|
116
116
|
}
|
|
117
117
|
connectMicroservice(microserviceOptions, hybridAppOptions = {}) {
|
|
118
|
-
const { NestMicroservice } =
|
|
118
|
+
const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
|
|
119
119
|
const { inheritAppConfig } = hybridAppOptions;
|
|
120
120
|
const applicationConfig = inheritAppConfig
|
|
121
121
|
? this.config
|
|
@@ -161,7 +161,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
161
161
|
reject(e);
|
|
162
162
|
};
|
|
163
163
|
this.httpServer.once('error', errorHandler);
|
|
164
|
-
const isCallbackInOriginalArgs =
|
|
164
|
+
const isCallbackInOriginalArgs = shared_utils_1.isFunction(args[args.length - 1]);
|
|
165
165
|
const listenFnArgs = isCallbackInOriginalArgs
|
|
166
166
|
? args.slice(0, args.length - 1)
|
|
167
167
|
: args;
|
|
@@ -170,6 +170,9 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
170
170
|
if ((_b = (_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.autoFlushLogs) !== null && _b !== void 0 ? _b : true) {
|
|
171
171
|
this.flushLogs();
|
|
172
172
|
}
|
|
173
|
+
if (originalCallbackArgs[0] instanceof Error) {
|
|
174
|
+
return reject(originalCallbackArgs[0]);
|
|
175
|
+
}
|
|
173
176
|
const address = this.httpServer.address();
|
|
174
177
|
if (address) {
|
|
175
178
|
this.httpServer.removeListener('error', errorHandler);
|
|
@@ -198,7 +201,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
198
201
|
}
|
|
199
202
|
formatAddress(address) {
|
|
200
203
|
if (typeof address === 'string') {
|
|
201
|
-
if (
|
|
204
|
+
if (os_1.platform() === 'win32') {
|
|
202
205
|
return address;
|
|
203
206
|
}
|
|
204
207
|
const basePath = encodeURIComponent(address);
|
|
@@ -222,15 +225,15 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
222
225
|
this.config.setGlobalPrefix(prefix);
|
|
223
226
|
if (options) {
|
|
224
227
|
const exclude = options === null || options === void 0 ? void 0 : options.exclude.map((route) => {
|
|
225
|
-
if (
|
|
228
|
+
if (shared_utils_1.isString(route)) {
|
|
226
229
|
return {
|
|
227
230
|
requestMethod: common_1.RequestMethod.ALL,
|
|
228
|
-
pathRegex: pathToRegexp(
|
|
231
|
+
pathRegex: pathToRegexp(shared_utils_1.addLeadingSlash(route)),
|
|
229
232
|
};
|
|
230
233
|
}
|
|
231
234
|
return {
|
|
232
235
|
requestMethod: route.method,
|
|
233
|
-
pathRegex: pathToRegexp(
|
|
236
|
+
pathRegex: pathToRegexp(shared_utils_1.addLeadingSlash(route.path)),
|
|
234
237
|
};
|
|
235
238
|
});
|
|
236
239
|
this.config.setGlobalPrefixOptions(Object.assign(Object.assign({}, options), { exclude }));
|
package/nest-factory.js
CHANGED
|
@@ -49,7 +49,7 @@ class NestFactoryStatic {
|
|
|
49
49
|
* contains a reference to the NestMicroservice instance.
|
|
50
50
|
*/
|
|
51
51
|
async createMicroservice(module, options) {
|
|
52
|
-
const { NestMicroservice } =
|
|
52
|
+
const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
|
|
53
53
|
const applicationConfig = new application_config_1.ApplicationConfig();
|
|
54
54
|
const container = new container_1.NestContainer(applicationConfig);
|
|
55
55
|
this.setAbortOnError(options);
|
|
@@ -102,7 +102,7 @@ class NestFactoryStatic {
|
|
|
102
102
|
if (this.abortOnError) {
|
|
103
103
|
process.abort();
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
rethrow_1.rethrow(err);
|
|
106
106
|
}
|
|
107
107
|
createProxy(target) {
|
|
108
108
|
const proxy = this.createExceptionProxy();
|
|
@@ -116,7 +116,7 @@ class NestFactoryStatic {
|
|
|
116
116
|
if (!(prop in receiver)) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
119
|
+
if (shared_utils_1.isFunction(receiver[prop])) {
|
|
120
120
|
return this.createExceptionZone(receiver, prop);
|
|
121
121
|
}
|
|
122
122
|
return receiver[prop];
|
|
@@ -137,7 +137,7 @@ class NestFactoryStatic {
|
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
const { logger, bufferLogs, autoFlushLogs } = options;
|
|
140
|
-
if (logger !== true && !
|
|
140
|
+
if (logger !== true && !shared_utils_1.isNil(logger)) {
|
|
141
141
|
logger_service_1.Logger.overrideLogger(logger);
|
|
142
142
|
}
|
|
143
143
|
if (bufferLogs) {
|
|
@@ -146,7 +146,7 @@ class NestFactoryStatic {
|
|
|
146
146
|
this.autoFlushLogs = autoFlushLogs !== null && autoFlushLogs !== void 0 ? autoFlushLogs : true;
|
|
147
147
|
}
|
|
148
148
|
createHttpAdapter(httpServer) {
|
|
149
|
-
const { ExpressAdapter } =
|
|
149
|
+
const { ExpressAdapter } = load_adapter_1.loadAdapter('@nestjs/platform-express', 'HTTP', () => require('@nestjs/platform-express'));
|
|
150
150
|
return new ExpressAdapter(httpServer);
|
|
151
151
|
}
|
|
152
152
|
isHttpServer(serverOrOptions) {
|
|
@@ -173,7 +173,7 @@ class NestFactoryStatic {
|
|
|
173
173
|
return mapToProxy(result);
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
|
-
if (
|
|
176
|
+
if (shared_utils_1.isFunction(receiver[prop])) {
|
|
177
177
|
return (...args) => {
|
|
178
178
|
const result = receiver[prop](...args);
|
|
179
179
|
return mapToProxy(result);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "8.1
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"uuid": "8.3.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "8.1
|
|
39
|
+
"@nestjs/common": "8.2.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^8.0.0",
|
|
@@ -17,13 +17,13 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
|
|
|
17
17
|
return this.createContext(instance, callback, constants_1.PIPES_METADATA, contextId, inquirerId);
|
|
18
18
|
}
|
|
19
19
|
createConcreteContext(metadata, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
|
20
|
-
if (
|
|
20
|
+
if (shared_utils_1.isEmpty(metadata)) {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return iterare_1.iterate(metadata)
|
|
24
24
|
.filter((pipe) => pipe && (pipe.name || pipe.transform))
|
|
25
25
|
.map(pipe => this.getPipeInstance(pipe, contextId, inquirerId))
|
|
26
|
-
.filter(pipe => pipe && pipe.transform &&
|
|
26
|
+
.filter(pipe => pipe && pipe.transform && shared_utils_1.isFunction(pipe.transform))
|
|
27
27
|
.toArray();
|
|
28
28
|
}
|
|
29
29
|
getPipeInstance(pipe, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
|
@@ -58,7 +58,7 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
|
|
|
58
58
|
return globalPipes;
|
|
59
59
|
}
|
|
60
60
|
const scopedPipeWrappers = this.config.getGlobalRequestPipes();
|
|
61
|
-
const scopedPipes =
|
|
61
|
+
const scopedPipes = iterare_1.iterate(scopedPipeWrappers)
|
|
62
62
|
.map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
|
|
63
63
|
.filter(host => !!host)
|
|
64
64
|
.map(host => host.instance)
|
package/router/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RouterModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
tslib_1.__exportStar(require("./interfaces"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./request"), exports);
|
|
7
7
|
var router_module_1 = require("./router-module");
|
|
8
8
|
Object.defineProperty(exports, "RouterModule", { enumerable: true, get: function () { return router_module_1.RouterModule; } });
|
|
@@ -17,7 +17,7 @@ class RoutePathFactory {
|
|
|
17
17
|
// Version Neutral - Do not include version in URL
|
|
18
18
|
if (version !== common_1.VERSION_NEUTRAL) {
|
|
19
19
|
if (Array.isArray(version)) {
|
|
20
|
-
paths =
|
|
20
|
+
paths = common_1.flatten(paths.map(path => version.map(v => path + `/${versionPrefix}${v}`)));
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
paths = paths.map(path => path + `/${versionPrefix}${version}`);
|
|
@@ -32,12 +32,12 @@ class RoutePathFactory {
|
|
|
32
32
|
if (this.isExcludedFromGlobalPrefix(path, requestMethod)) {
|
|
33
33
|
return path;
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return shared_utils_1.stripEndSlash(metadata.globalPrefix || '') + path;
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
return paths
|
|
39
|
-
.map(path =>
|
|
40
|
-
.map(path => (path !== '/' ?
|
|
39
|
+
.map(path => shared_utils_1.addLeadingSlash(path || '/'))
|
|
40
|
+
.map(path => (path !== '/' ? shared_utils_1.stripEndSlash(path) : path));
|
|
41
41
|
}
|
|
42
42
|
getVersion(metadata) {
|
|
43
43
|
// The version will be either the path version or the controller version,
|
|
@@ -60,21 +60,21 @@ class RoutePathFactory {
|
|
|
60
60
|
if (!fragmentToAppend) {
|
|
61
61
|
return paths;
|
|
62
62
|
}
|
|
63
|
-
const concatPaths = (a, b) =>
|
|
63
|
+
const concatPaths = (a, b) => shared_utils_1.stripEndSlash(a) + shared_utils_1.addLeadingSlash(b);
|
|
64
64
|
if (Array.isArray(fragmentToAppend)) {
|
|
65
65
|
const paths2dArray = paths.map(path => fragmentToAppend.map(fragment => concatPaths(path, fragment)));
|
|
66
|
-
return
|
|
66
|
+
return common_1.flatten(paths2dArray);
|
|
67
67
|
}
|
|
68
68
|
return paths.map(path => concatPaths(path, fragmentToAppend));
|
|
69
69
|
}
|
|
70
70
|
isExcludedFromGlobalPrefix(path, requestMethod) {
|
|
71
|
-
if (
|
|
71
|
+
if (shared_utils_1.isUndefined(requestMethod)) {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
74
|
const options = this.applicationConfig.getGlobalPrefixOptions();
|
|
75
75
|
const excludedRoutes = options.exclude;
|
|
76
76
|
return (Array.isArray(excludedRoutes) &&
|
|
77
|
-
|
|
77
|
+
utils_1.isRouteExcluded(excludedRoutes, path, requestMethod));
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
exports.RoutePathFactory = RoutePathFactory;
|
|
@@ -17,7 +17,7 @@ class RouterExceptionFilters extends base_exception_filter_context_1.BaseExcepti
|
|
|
17
17
|
this.moduleContext = moduleKey;
|
|
18
18
|
const exceptionHandler = new exceptions_handler_1.ExceptionsHandler(this.applicationRef);
|
|
19
19
|
const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
|
|
20
|
-
if (
|
|
20
|
+
if (shared_utils_1.isEmpty(filters)) {
|
|
21
21
|
return exceptionHandler;
|
|
22
22
|
}
|
|
23
23
|
exceptionHandler.setCustomFilters(filters.reverse());
|
|
@@ -29,7 +29,7 @@ class RouterExceptionFilters extends base_exception_filter_context_1.BaseExcepti
|
|
|
29
29
|
return globalFilters;
|
|
30
30
|
}
|
|
31
31
|
const scopedFilterWrappers = this.config.getGlobalRequestFilters();
|
|
32
|
-
const scopedFilters =
|
|
32
|
+
const scopedFilters = iterare_1.iterate(scopedFilterWrappers)
|
|
33
33
|
.map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
|
|
34
34
|
.filter(host => !!host)
|
|
35
35
|
.map(host => host.instance)
|
|
@@ -67,7 +67,7 @@ class RouterExecutionContext {
|
|
|
67
67
|
? httpCode
|
|
68
68
|
: this.responseController.getStatusByMethod(requestMethod);
|
|
69
69
|
const responseHeaders = this.reflectResponseHeaders(callback);
|
|
70
|
-
const hasCustomHeaders = !
|
|
70
|
+
const hasCustomHeaders = !shared_utils_1.isEmpty(responseHeaders);
|
|
71
71
|
const handlerMetadata = {
|
|
72
72
|
argsLength,
|
|
73
73
|
fnHandleResponse,
|
|
@@ -116,7 +116,7 @@ class RouterExecutionContext {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
async getParamValue(value, { metatype, type, data, }, pipes) {
|
|
119
|
-
if (!
|
|
119
|
+
if (!shared_utils_1.isEmpty(pipes)) {
|
|
120
120
|
return this.pipesConsumer.apply(value, { metatype, type, data }, pipes);
|
|
121
121
|
}
|
|
122
122
|
return value;
|
|
@@ -127,7 +127,7 @@ class RouterExecutionContext {
|
|
|
127
127
|
type === route_paramtypes_enum_1.RouteParamtypes.PARAM ||
|
|
128
128
|
type === route_paramtypes_enum_1.RouteParamtypes.FILE ||
|
|
129
129
|
type === route_paramtypes_enum_1.RouteParamtypes.FILES ||
|
|
130
|
-
|
|
130
|
+
shared_utils_1.isString(type));
|
|
131
131
|
}
|
|
132
132
|
createGuardsFn(guards, instance, callback, contextType) {
|
|
133
133
|
const canActivateFn = async (args) => {
|
|
@@ -53,16 +53,16 @@ class RouterExplorer {
|
|
|
53
53
|
}
|
|
54
54
|
extractRouterPath(metatype) {
|
|
55
55
|
const path = Reflect.getMetadata(constants_1.PATH_METADATA, metatype);
|
|
56
|
-
if (
|
|
56
|
+
if (shared_utils_1.isUndefined(path)) {
|
|
57
57
|
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException();
|
|
58
58
|
}
|
|
59
59
|
if (Array.isArray(path)) {
|
|
60
|
-
return path.map(p =>
|
|
60
|
+
return path.map(p => shared_utils_1.addLeadingSlash(p));
|
|
61
61
|
}
|
|
62
|
-
return [
|
|
62
|
+
return [shared_utils_1.addLeadingSlash(path)];
|
|
63
63
|
}
|
|
64
64
|
scanForPaths(instance, prototype) {
|
|
65
|
-
const instancePrototype =
|
|
65
|
+
const instancePrototype = shared_utils_1.isUndefined(prototype)
|
|
66
66
|
? Object.getPrototypeOf(instance)
|
|
67
67
|
: prototype;
|
|
68
68
|
return this.metadataScanner.scanFromPrototype(instance, instancePrototype, method => this.exploreMethodMetadata(instance, instancePrototype, method));
|
|
@@ -71,14 +71,14 @@ class RouterExplorer {
|
|
|
71
71
|
const instanceCallback = instance[methodName];
|
|
72
72
|
const prototypeCallback = prototype[methodName];
|
|
73
73
|
const routePath = Reflect.getMetadata(constants_1.PATH_METADATA, prototypeCallback);
|
|
74
|
-
if (
|
|
74
|
+
if (shared_utils_1.isUndefined(routePath)) {
|
|
75
75
|
return null;
|
|
76
76
|
}
|
|
77
77
|
const requestMethod = Reflect.getMetadata(constants_1.METHOD_METADATA, prototypeCallback);
|
|
78
78
|
const version = Reflect.getMetadata(constants_1.VERSION_METADATA, prototypeCallback);
|
|
79
|
-
const path =
|
|
80
|
-
? [
|
|
81
|
-
: routePath.map((p) =>
|
|
79
|
+
const path = shared_utils_1.isString(routePath)
|
|
80
|
+
? [shared_utils_1.addLeadingSlash(routePath)]
|
|
81
|
+
: routePath.map((p) => shared_utils_1.addLeadingSlash(p));
|
|
82
82
|
return {
|
|
83
83
|
path,
|
|
84
84
|
requestMethod,
|
|
@@ -121,10 +121,10 @@ class RouterExplorer {
|
|
|
121
121
|
pathsToLog.forEach(path => {
|
|
122
122
|
if (isVersioned) {
|
|
123
123
|
const version = this.routePathFactory.getVersion(routePathMetadata);
|
|
124
|
-
this.logger.log(
|
|
124
|
+
this.logger.log(messages_1.VERSIONED_ROUTE_MAPPED_MESSAGE(path, requestMethod, version));
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
|
-
this.logger.log(
|
|
127
|
+
this.logger.log(messages_1.ROUTE_MAPPED_MESSAGE(path, requestMethod));
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -193,7 +193,7 @@ class RouterExplorer {
|
|
|
193
193
|
return handler(req, res, next);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
else if (
|
|
196
|
+
else if (shared_utils_1.isString(version)) {
|
|
197
197
|
if (version === headerVersion) {
|
|
198
198
|
return handler(req, res, next);
|
|
199
199
|
}
|
|
@@ -210,7 +210,7 @@ class RouterExplorer {
|
|
|
210
210
|
return handler(req, res, next);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
else if (
|
|
213
|
+
else if (shared_utils_1.isString(version)) {
|
|
214
214
|
if (version === customHeaderVersionParameter) {
|
|
215
215
|
return handler(req, res, next);
|
|
216
216
|
}
|
package/router/router-module.js
CHANGED
|
@@ -43,9 +43,9 @@ let RouterModule = RouterModule_1 = class RouterModule {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
initialize() {
|
|
46
|
-
const flattenedRoutes =
|
|
46
|
+
const flattenedRoutes = utils_1.flattenRoutePaths(this.routes);
|
|
47
47
|
flattenedRoutes.forEach(route => {
|
|
48
|
-
const modulePath =
|
|
48
|
+
const modulePath = shared_utils_1.normalizePath(route.path);
|
|
49
49
|
this.registerModulePathMetadata(route.module, modulePath);
|
|
50
50
|
this.updateTargetModulesCache(route.module);
|
|
51
51
|
});
|
|
@@ -69,9 +69,9 @@ let RouterModule = RouterModule_1 = class RouterModule {
|
|
|
69
69
|
moduleClassSet.add(moduleRef);
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
RouterModule = RouterModule_1 =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
RouterModule = RouterModule_1 = tslib_1.__decorate([
|
|
73
|
+
common_1.Module({}),
|
|
74
|
+
tslib_1.__param(1, common_1.Inject(exports.ROUTES)),
|
|
75
|
+
tslib_1.__metadata("design:paramtypes", [modules_container_1.ModulesContainer, Array])
|
|
76
76
|
], RouterModule);
|
|
77
77
|
exports.RouterModule = RouterModule;
|
|
@@ -28,8 +28,8 @@ class RouterResponseController {
|
|
|
28
28
|
return this.applicationRef.render(response, template, result);
|
|
29
29
|
}
|
|
30
30
|
async transformToResult(resultOrDeferred) {
|
|
31
|
-
if (resultOrDeferred &&
|
|
32
|
-
return
|
|
31
|
+
if (resultOrDeferred && shared_utils_1.isFunction(resultOrDeferred.subscribe)) {
|
|
32
|
+
return rxjs_1.lastValueFrom(resultOrDeferred);
|
|
33
33
|
}
|
|
34
34
|
return resultOrDeferred;
|
|
35
35
|
}
|
|
@@ -56,8 +56,8 @@ class RouterResponseController {
|
|
|
56
56
|
const stream = new sse_stream_1.SseStream(request);
|
|
57
57
|
stream.pipe(response);
|
|
58
58
|
const subscription = result
|
|
59
|
-
.pipe(
|
|
60
|
-
if (!
|
|
59
|
+
.pipe(operators_1.debounce((message) => new Promise(resolve => {
|
|
60
|
+
if (!shared_utils_1.isObject(message)) {
|
|
61
61
|
message = { data: message };
|
|
62
62
|
}
|
|
63
63
|
stream.writeMessage(message, resolve);
|
|
@@ -72,7 +72,7 @@ class RouterResponseController {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
assertObservable(result) {
|
|
75
|
-
if (!
|
|
75
|
+
if (!shared_utils_1.isFunction(result.subscribe)) {
|
|
76
76
|
throw new ReferenceError('You must return an Observable stream to use Server-Sent Events (SSE).');
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -47,13 +47,13 @@ class RoutesResolver {
|
|
|
47
47
|
});
|
|
48
48
|
if (!controllerVersion) {
|
|
49
49
|
pathsToLog.forEach(path => {
|
|
50
|
-
const logMessage =
|
|
50
|
+
const logMessage = messages_1.CONTROLLER_MAPPING_MESSAGE(controllerName, path);
|
|
51
51
|
this.logger.log(logMessage);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
pathsToLog.forEach(path => {
|
|
56
|
-
const logMessage =
|
|
56
|
+
const logMessage = messages_1.VERSIONED_CONTROLLER_MAPPING_MESSAGE(controllerName, path, controllerVersion);
|
|
57
57
|
this.logger.log(logMessage);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -8,7 +8,7 @@ const isRequestMethodAll = (method) => {
|
|
|
8
8
|
exports.isRequestMethodAll = isRequestMethodAll;
|
|
9
9
|
function isRouteExcluded(excludedRoutes, path, requestMethod) {
|
|
10
10
|
return excludedRoutes.some(route => {
|
|
11
|
-
if (
|
|
11
|
+
if (exports.isRequestMethodAll(route.requestMethod) ||
|
|
12
12
|
route.requestMethod === requestMethod) {
|
|
13
13
|
return route.pathRegex.exec(path);
|
|
14
14
|
}
|
|
@@ -12,7 +12,7 @@ function flattenRoutePaths(routes) {
|
|
|
12
12
|
const childrenRef = item.children;
|
|
13
13
|
childrenRef.forEach(child => {
|
|
14
14
|
if (typeof child !== 'string' && child.path) {
|
|
15
|
-
child.path =
|
|
15
|
+
child.path = shared_utils_1.normalizePath(shared_utils_1.normalizePath(item.path) + shared_utils_1.normalizePath(child.path));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
result.push({ path: item.path, module: child });
|
package/router/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./exclude-route.util"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./flatten-route-paths.util"), exports);
|
package/scanner.js
CHANGED
|
@@ -138,8 +138,8 @@ class DependenciesScanner {
|
|
|
138
138
|
}
|
|
139
139
|
reflectParamInjectables(component, token, metadataKey) {
|
|
140
140
|
const paramsMetadata = this.metadataScanner.scanFromPrototype(null, component.prototype, method => Reflect.getMetadata(metadataKey, component, method));
|
|
141
|
-
const paramsInjectables = this.flatten(paramsMetadata).map((param) =>
|
|
142
|
-
|
|
141
|
+
const paramsInjectables = this.flatten(paramsMetadata).map((param) => common_1.flatten(Object.keys(param).map(k => param[k].pipes)).filter(shared_utils_1.isFunction));
|
|
142
|
+
common_1.flatten(paramsInjectables).forEach((injectable) => this.insertInjectable(injectable, token, component));
|
|
143
143
|
}
|
|
144
144
|
reflectKeyMetadata(component, key, method) {
|
|
145
145
|
let prototype = component.prototype;
|
|
@@ -176,7 +176,7 @@ class DependenciesScanner {
|
|
|
176
176
|
calculateDistance(rootModule);
|
|
177
177
|
}
|
|
178
178
|
async insertImport(related, token, context) {
|
|
179
|
-
if (
|
|
179
|
+
if (shared_utils_1.isUndefined(related)) {
|
|
180
180
|
throw new circular_dependency_exception_1.CircularDependencyException(context);
|
|
181
181
|
}
|
|
182
182
|
if (related && related.forwardRef) {
|
|
@@ -185,7 +185,7 @@ class DependenciesScanner {
|
|
|
185
185
|
await this.container.addImport(related, token);
|
|
186
186
|
}
|
|
187
187
|
isCustomProvider(provider) {
|
|
188
|
-
return provider && !
|
|
188
|
+
return provider && !shared_utils_1.isNil(provider.provide);
|
|
189
189
|
}
|
|
190
190
|
insertProvider(provider, token) {
|
|
191
191
|
const isCustomProvider = this.isCustomProvider(provider);
|
|
@@ -198,10 +198,10 @@ class DependenciesScanner {
|
|
|
198
198
|
if (!providersKeys.includes(type)) {
|
|
199
199
|
return this.container.addProvider(provider, token);
|
|
200
200
|
}
|
|
201
|
-
const providerToken = `${type} (UUID: ${
|
|
201
|
+
const providerToken = `${type} (UUID: ${random_string_generator_util_1.randomStringGenerator()})`;
|
|
202
202
|
let scope = provider.scope;
|
|
203
|
-
if (
|
|
204
|
-
scope =
|
|
203
|
+
if (shared_utils_1.isNil(scope) && provider.useClass) {
|
|
204
|
+
scope = get_class_scope_1.getClassScope(provider.useClass);
|
|
205
205
|
}
|
|
206
206
|
this.applicationProvidersApplyMap.push({
|
|
207
207
|
type,
|
|
@@ -238,13 +238,13 @@ class DependenciesScanner {
|
|
|
238
238
|
* to all controllers metadata storage
|
|
239
239
|
*/
|
|
240
240
|
addScopedEnhancersMetadata() {
|
|
241
|
-
|
|
241
|
+
iterare_1.iterate(this.applicationProvidersApplyMap)
|
|
242
242
|
.filter(wrapper => this.isRequestOrTransient(wrapper.scope))
|
|
243
243
|
.forEach(({ moduleKey, providerKey }) => {
|
|
244
244
|
const modulesContainer = this.container.getModules();
|
|
245
245
|
const { injectables } = modulesContainer.get(moduleKey);
|
|
246
246
|
const instanceWrapper = injectables.get(providerKey);
|
|
247
|
-
|
|
247
|
+
iterare_1.iterate(modulesContainer.values())
|
|
248
248
|
.map(module => module.controllers.values())
|
|
249
249
|
.flatten()
|
|
250
250
|
.forEach(controller => controller.addEnhancerMetadata(instanceWrapper));
|
package/services/index.js
CHANGED
|
@@ -42,14 +42,14 @@ class Reflector {
|
|
|
42
42
|
*/
|
|
43
43
|
getAllAndMerge(metadataKey, targets) {
|
|
44
44
|
const metadataCollection = this.getAll(metadataKey, targets).filter(item => item !== undefined);
|
|
45
|
-
if (
|
|
45
|
+
if (shared_utils_1.isEmpty(metadataCollection)) {
|
|
46
46
|
return metadataCollection;
|
|
47
47
|
}
|
|
48
48
|
return metadataCollection.reduce((a, b) => {
|
|
49
49
|
if (Array.isArray(a)) {
|
|
50
50
|
return a.concat(b);
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
52
|
+
if (shared_utils_1.isObject(a) && shared_utils_1.isObject(b)) {
|
|
53
53
|
return Object.assign(Object.assign({}, a), b);
|
|
54
54
|
}
|
|
55
55
|
return [a, b];
|