@nestjs/core 8.2.3 → 8.3.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/LICENSE +1 -1
- package/Readme.md +8 -2
- package/adapters/index.js +1 -1
- package/application-config.js +4 -0
- 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-module.exception.d.ts +4 -0
- package/errors/exceptions/invalid-class-module.exception.js +11 -0
- 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.d.ts +2 -1
- package/errors/messages.js +22 -9
- 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 +8 -4
- package/helpers/external-context-creator.js +3 -3
- package/helpers/index.js +2 -2
- package/helpers/interfaces/index.js +2 -2
- package/helpers/messages.js +10 -8
- 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 +13 -13
- 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 +5 -4
- 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/container.d.ts +0 -1
- package/middleware/container.js +2 -6
- package/middleware/index.js +1 -1
- package/middleware/middleware-module.js +6 -6
- package/middleware/routes-mapper.js +6 -6
- package/middleware/utils.js +6 -6
- package/nest-application-context.d.ts +5 -0
- package/nest-application-context.js +18 -8
- package/nest-application.js +13 -14
- package/nest-factory.js +9 -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 +21 -16
- package/router/router-exception-filters.js +2 -2
- package/router/router-execution-context.js +7 -6
- package/router/router-explorer.js +12 -12
- package/router/router-module.js +6 -6
- package/router/router-response-controller.d.ts +5 -2
- package/router/router-response-controller.js +19 -10
- package/router/routes-resolver.js +6 -3
- package/router/sse-stream.d.ts +8 -2
- package/router/sse-stream.js +7 -10
- package/router/utils/exclude-route.util.js +1 -1
- package/router/utils/flatten-route-paths.util.js +2 -2
- package/router/utils/index.js +2 -2
- package/scanner.d.ts +18 -2
- package/scanner.js +43 -14
- package/services/index.js +1 -1
- package/services/reflector.service.js +2 -2
|
@@ -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 = !shared_utils_1.isEmpty(responseHeaders);
|
|
70
|
+
const hasCustomHeaders = !(0, 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 (!shared_utils_1.isEmpty(pipes)) {
|
|
119
|
+
if (!(0, 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
|
-
shared_utils_1.isString(type));
|
|
130
|
+
(0, shared_utils_1.isString)(type));
|
|
131
131
|
}
|
|
132
132
|
createGuardsFn(guards, instance, callback, contextType) {
|
|
133
133
|
const canActivateFn = async (args) => {
|
|
@@ -158,15 +158,16 @@ class RouterExecutionContext {
|
|
|
158
158
|
return await this.responseController.render(result, res, renderTemplate);
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
if (redirectResponse &&
|
|
161
|
+
if (redirectResponse && (0, shared_utils_1.isString)(redirectResponse.url)) {
|
|
162
162
|
return async (result, res) => {
|
|
163
163
|
await this.responseController.redirect(result, res, redirectResponse);
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
const isSseHandler = !!this.reflectSse(callback);
|
|
167
167
|
if (isSseHandler) {
|
|
168
|
-
return
|
|
169
|
-
|
|
168
|
+
return (result, res, req) => {
|
|
169
|
+
var _a;
|
|
170
|
+
this.responseController.sse(result, res.raw || res, req.raw || req, { additionalHeaders: (_a = res.getHeaders) === null || _a === void 0 ? void 0 : _a.call(res) });
|
|
170
171
|
};
|
|
171
172
|
}
|
|
172
173
|
return async (result, res) => {
|
|
@@ -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 (shared_utils_1.isUndefined(path)) {
|
|
56
|
+
if ((0, 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 => shared_utils_1.addLeadingSlash(p));
|
|
60
|
+
return path.map(p => (0, shared_utils_1.addLeadingSlash)(p));
|
|
61
61
|
}
|
|
62
|
-
return [shared_utils_1.addLeadingSlash(path)];
|
|
62
|
+
return [(0, shared_utils_1.addLeadingSlash)(path)];
|
|
63
63
|
}
|
|
64
64
|
scanForPaths(instance, prototype) {
|
|
65
|
-
const instancePrototype = shared_utils_1.isUndefined(prototype)
|
|
65
|
+
const instancePrototype = (0, 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 (shared_utils_1.isUndefined(routePath)) {
|
|
74
|
+
if ((0, 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 = shared_utils_1.isString(routePath)
|
|
80
|
-
? [shared_utils_1.addLeadingSlash(routePath)]
|
|
81
|
-
: routePath.map((p) => shared_utils_1.addLeadingSlash(p));
|
|
79
|
+
const path = (0, shared_utils_1.isString)(routePath)
|
|
80
|
+
? [(0, shared_utils_1.addLeadingSlash)(routePath)]
|
|
81
|
+
: routePath.map((p) => (0, 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(messages_1.VERSIONED_ROUTE_MAPPED_MESSAGE(path, requestMethod, version));
|
|
124
|
+
this.logger.log((0, messages_1.VERSIONED_ROUTE_MAPPED_MESSAGE)(path, requestMethod, version));
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
|
-
this.logger.log(messages_1.ROUTE_MAPPED_MESSAGE(path, requestMethod));
|
|
127
|
+
this.logger.log((0, 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 (shared_utils_1.isString(version)) {
|
|
196
|
+
else if ((0, 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 (shared_utils_1.isString(version)) {
|
|
213
|
+
else if ((0, 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 = utils_1.flattenRoutePaths(this.routes);
|
|
46
|
+
const flattenedRoutes = (0, utils_1.flattenRoutePaths)(this.routes);
|
|
47
47
|
flattenedRoutes.forEach(route => {
|
|
48
|
-
const modulePath = shared_utils_1.normalizePath(route.path);
|
|
48
|
+
const modulePath = (0, 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 = 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])
|
|
72
|
+
RouterModule = RouterModule_1 = (0, tslib_1.__decorate)([
|
|
73
|
+
(0, common_1.Module)({}),
|
|
74
|
+
(0, tslib_1.__param)(1, (0, common_1.Inject)(exports.ROUTES)),
|
|
75
|
+
(0, tslib_1.__metadata)("design:paramtypes", [modules_container_1.ModulesContainer, Array])
|
|
76
76
|
], RouterModule);
|
|
77
77
|
exports.RouterModule = RouterModule;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { HttpServer, RequestMethod } from '@nestjs/common';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
|
-
import {
|
|
5
|
+
import { AdditionalHeaders, WritableHeaderStream } from './sse-stream';
|
|
6
6
|
export interface CustomHeader {
|
|
7
7
|
name: string;
|
|
8
8
|
value: string;
|
|
@@ -13,6 +13,7 @@ export interface RedirectResponse {
|
|
|
13
13
|
}
|
|
14
14
|
export declare class RouterResponseController {
|
|
15
15
|
private readonly applicationRef;
|
|
16
|
+
private readonly logger;
|
|
16
17
|
constructor(applicationRef: HttpServer);
|
|
17
18
|
apply<TInput = any, TResponse = any>(result: TInput, response: TResponse, httpStatusCode?: number): Promise<any>;
|
|
18
19
|
redirect<TInput = any, TResponse = any>(resultOrDeferred: TInput, response: TResponse, redirectResponse: RedirectResponse): Promise<void>;
|
|
@@ -21,6 +22,8 @@ export declare class RouterResponseController {
|
|
|
21
22
|
getStatusByMethod(requestMethod: RequestMethod): number;
|
|
22
23
|
setHeaders<TResponse = unknown>(response: TResponse, headers: CustomHeader[]): void;
|
|
23
24
|
setStatus<TResponse = unknown>(response: TResponse, statusCode: number): void;
|
|
24
|
-
sse<TInput extends Observable<unknown> = any, TResponse extends
|
|
25
|
+
sse<TInput extends Observable<unknown> = any, TResponse extends WritableHeaderStream = any, TRequest extends IncomingMessage = any>(result: TInput, response: TResponse, request: TRequest, options?: {
|
|
26
|
+
additionalHeaders: AdditionalHeaders;
|
|
27
|
+
}): void;
|
|
25
28
|
private assertObservable;
|
|
26
29
|
}
|
|
@@ -9,6 +9,7 @@ const sse_stream_1 = require("./sse-stream");
|
|
|
9
9
|
class RouterResponseController {
|
|
10
10
|
constructor(applicationRef) {
|
|
11
11
|
this.applicationRef = applicationRef;
|
|
12
|
+
this.logger = new common_1.Logger(RouterResponseController.name);
|
|
12
13
|
}
|
|
13
14
|
async apply(result, response, httpStatusCode) {
|
|
14
15
|
return this.applicationRef.reply(response, result, httpStatusCode);
|
|
@@ -28,8 +29,8 @@ class RouterResponseController {
|
|
|
28
29
|
return this.applicationRef.render(response, template, result);
|
|
29
30
|
}
|
|
30
31
|
async transformToResult(resultOrDeferred) {
|
|
31
|
-
if (resultOrDeferred && shared_utils_1.isFunction(resultOrDeferred.subscribe)) {
|
|
32
|
-
return rxjs_1.lastValueFrom(resultOrDeferred);
|
|
32
|
+
if (resultOrDeferred && (0, shared_utils_1.isFunction)(resultOrDeferred.subscribe)) {
|
|
33
|
+
return (0, rxjs_1.lastValueFrom)(resultOrDeferred);
|
|
33
34
|
}
|
|
34
35
|
return resultOrDeferred;
|
|
35
36
|
}
|
|
@@ -47,21 +48,29 @@ class RouterResponseController {
|
|
|
47
48
|
setStatus(response, statusCode) {
|
|
48
49
|
this.applicationRef.status(response, statusCode);
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
sse(result, response, request, options) {
|
|
51
52
|
// It's possible that we sent headers already so don't use a stream
|
|
52
53
|
if (response.writableEnded) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
this.assertObservable(result);
|
|
56
57
|
const stream = new sse_stream_1.SseStream(request);
|
|
57
|
-
stream.pipe(response);
|
|
58
|
+
stream.pipe(response, options);
|
|
58
59
|
const subscription = result
|
|
59
|
-
.pipe(operators_1.
|
|
60
|
-
if (
|
|
61
|
-
|
|
60
|
+
.pipe((0, operators_1.map)((message) => {
|
|
61
|
+
if ((0, shared_utils_1.isObject)(message)) {
|
|
62
|
+
return message;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
})))
|
|
64
|
+
return { data: message };
|
|
65
|
+
}), (0, operators_1.debounce)(message => new Promise(resolve => stream.writeMessage(message, () => resolve()))), (0, operators_1.catchError)(err => {
|
|
66
|
+
const data = err instanceof Error ? err.message : err;
|
|
67
|
+
stream.writeMessage({ type: 'error', data }, writeError => {
|
|
68
|
+
if (writeError) {
|
|
69
|
+
this.logger.error(writeError);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return rxjs_1.EMPTY;
|
|
73
|
+
}))
|
|
65
74
|
.subscribe({
|
|
66
75
|
complete: () => {
|
|
67
76
|
response.end();
|
|
@@ -72,7 +81,7 @@ class RouterResponseController {
|
|
|
72
81
|
});
|
|
73
82
|
}
|
|
74
83
|
assertObservable(result) {
|
|
75
|
-
if (!shared_utils_1.isFunction(result.subscribe)) {
|
|
84
|
+
if (!(0, shared_utils_1.isFunction)(result.subscribe)) {
|
|
76
85
|
throw new ReferenceError('You must return an Observable stream to use Server-Sent Events (SSE).');
|
|
77
86
|
}
|
|
78
87
|
}
|
|
@@ -47,13 +47,13 @@ class RoutesResolver {
|
|
|
47
47
|
});
|
|
48
48
|
if (!controllerVersion) {
|
|
49
49
|
pathsToLog.forEach(path => {
|
|
50
|
-
const logMessage = messages_1.CONTROLLER_MAPPING_MESSAGE(controllerName, path);
|
|
50
|
+
const logMessage = (0, 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 = messages_1.VERSIONED_CONTROLLER_MAPPING_MESSAGE(controllerName, path, controllerVersion);
|
|
56
|
+
const logMessage = (0, messages_1.VERSIONED_CONTROLLER_MAPPING_MESSAGE)(controllerName, path, controllerVersion);
|
|
57
57
|
this.logger.log(logMessage);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -93,7 +93,10 @@ class RoutesResolver {
|
|
|
93
93
|
}
|
|
94
94
|
mapExternalException(err) {
|
|
95
95
|
switch (true) {
|
|
96
|
-
|
|
96
|
+
// SyntaxError is thrown by Express body-parser when given invalid JSON (#422, #430)
|
|
97
|
+
// URIError is thrown by Express when given a path parameter with an invalid percentage
|
|
98
|
+
// encoding, e.g. '%FF' (#8915)
|
|
99
|
+
case err instanceof SyntaxError || err instanceof URIError:
|
|
97
100
|
return new common_1.BadRequestException(err.message);
|
|
98
101
|
default:
|
|
99
102
|
return err;
|
package/router/sse-stream.d.ts
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
import { MessageEvent } from '@nestjs/common/interfaces';
|
|
3
3
|
import { IncomingMessage, OutgoingHttpHeaders } from 'http';
|
|
4
4
|
import { Transform } from 'stream';
|
|
5
|
+
export declare type AdditionalHeaders = Record<string, string[] | string | number | undefined>;
|
|
6
|
+
interface ReadHeaders {
|
|
7
|
+
getHeaders?(): AdditionalHeaders;
|
|
8
|
+
}
|
|
5
9
|
interface WriteHeaders {
|
|
6
10
|
writableEnded?: boolean;
|
|
7
11
|
writeHead?(statusCode: number, reasonPhrase?: string, headers?: OutgoingHttpHeaders): void;
|
|
8
12
|
writeHead?(statusCode: number, headers?: OutgoingHttpHeaders): void;
|
|
9
13
|
flushHeaders?(): void;
|
|
10
14
|
}
|
|
11
|
-
export declare type
|
|
15
|
+
export declare type WritableHeaderStream = NodeJS.WritableStream & WriteHeaders;
|
|
16
|
+
export declare type HeaderStream = WritableHeaderStream & ReadHeaders;
|
|
12
17
|
/**
|
|
13
18
|
* Adapted from https://raw.githubusercontent.com/EventSource/node-ssestream
|
|
14
19
|
* Transforms "messages" to W3C event stream content.
|
|
@@ -25,7 +30,8 @@ export declare type HeaderStream = NodeJS.WritableStream & WriteHeaders;
|
|
|
25
30
|
export declare class SseStream extends Transform {
|
|
26
31
|
private lastEventId;
|
|
27
32
|
constructor(req?: IncomingMessage);
|
|
28
|
-
pipe<T extends
|
|
33
|
+
pipe<T extends WritableHeaderStream>(destination: T, options?: {
|
|
34
|
+
additionalHeaders?: AdditionalHeaders;
|
|
29
35
|
end?: boolean;
|
|
30
36
|
}): T;
|
|
31
37
|
_transform(message: MessageEvent, encoding: string, callback: (error?: Error | null, data?: any) => void): void;
|
package/router/sse-stream.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SseStream = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
4
5
|
const stream_1 = require("stream");
|
|
5
6
|
function toDataString(data) {
|
|
6
|
-
if (
|
|
7
|
+
if ((0, shared_utils_1.isObject)(data)) {
|
|
7
8
|
return toDataString(JSON.stringify(data));
|
|
8
9
|
}
|
|
9
10
|
return data
|
|
@@ -36,20 +37,16 @@ class SseStream extends stream_1.Transform {
|
|
|
36
37
|
}
|
|
37
38
|
pipe(destination, options) {
|
|
38
39
|
if (destination.writeHead) {
|
|
39
|
-
destination.writeHead(200, {
|
|
40
|
+
destination.writeHead(200, Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.additionalHeaders), {
|
|
40
41
|
// See https://github.com/dunglas/mercure/blob/master/hub/subscribe.go#L124-L130
|
|
41
|
-
'Content-Type': 'text/event-stream',
|
|
42
|
-
Connection: 'keep-alive',
|
|
42
|
+
'Content-Type': 'text/event-stream', Connection: 'keep-alive',
|
|
43
43
|
// Disable cache, even for old browsers and proxies
|
|
44
|
-
'Cache-Control': 'private, no-cache, no-store, must-revalidate, max-age=0, no-transform',
|
|
45
|
-
Pragma: 'no-cache',
|
|
46
|
-
Expire: '0',
|
|
44
|
+
'Cache-Control': 'private, no-cache, no-store, must-revalidate, max-age=0, no-transform', Pragma: 'no-cache', Expire: '0',
|
|
47
45
|
// NGINX support https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering
|
|
48
|
-
'X-Accel-Buffering': 'no'
|
|
49
|
-
});
|
|
46
|
+
'X-Accel-Buffering': 'no' }));
|
|
50
47
|
destination.flushHeaders();
|
|
51
48
|
}
|
|
52
|
-
destination.write('
|
|
49
|
+
destination.write('\n');
|
|
53
50
|
return super.pipe(destination, options);
|
|
54
51
|
}
|
|
55
52
|
_transform(message, encoding, callback) {
|
|
@@ -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 (exports.isRequestMethodAll(route.requestMethod) ||
|
|
11
|
+
if ((0, exports.isRequestMethodAll)(route.requestMethod) ||
|
|
12
12
|
route.requestMethod === requestMethod) {
|
|
13
13
|
return route.pathRegex.exec(path);
|
|
14
14
|
}
|
|
@@ -11,8 +11,8 @@ function flattenRoutePaths(routes) {
|
|
|
11
11
|
if (item.children) {
|
|
12
12
|
const childrenRef = item.children;
|
|
13
13
|
childrenRef.forEach(child => {
|
|
14
|
-
if (
|
|
15
|
-
child.path = shared_utils_1.normalizePath(shared_utils_1.normalizePath(item.path) + shared_utils_1.normalizePath(child.path));
|
|
14
|
+
if (!(0, shared_utils_1.isString)(child) && child.path) {
|
|
15
|
+
child.path = (0, shared_utils_1.normalizePath)((0, shared_utils_1.normalizePath)(item.path) + (0, 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
|
-
tslib_1.__exportStar(require("./exclude-route.util"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./flatten-route-paths.util"), exports);
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./exclude-route.util"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./flatten-route-paths.util"), exports);
|
package/scanner.d.ts
CHANGED
|
@@ -11,11 +11,12 @@ export declare class DependenciesScanner {
|
|
|
11
11
|
private readonly container;
|
|
12
12
|
private readonly metadataScanner;
|
|
13
13
|
private readonly applicationConfig;
|
|
14
|
+
private readonly logger;
|
|
14
15
|
private readonly applicationProvidersApplyMap;
|
|
15
16
|
constructor(container: NestContainer, metadataScanner: MetadataScanner, applicationConfig?: ApplicationConfig);
|
|
16
17
|
scan(module: Type<any>): Promise<void>;
|
|
17
18
|
scanForModules(moduleDefinition: ForwardReference | Type<unknown> | DynamicModule | Promise<DynamicModule>, scope?: Type<unknown>[], ctxRegistry?: (ForwardReference | DynamicModule | Type<unknown>)[]): Promise<Module[]>;
|
|
18
|
-
insertModule(
|
|
19
|
+
insertModule(moduleDefinition: any, scope: Type<unknown>[]): Promise<Module | undefined>;
|
|
19
20
|
scanModulesForDependencies(modules?: Map<string, Module>): Promise<void>;
|
|
20
21
|
reflectImports(module: Type<unknown>, token: string, context: string): Promise<void>;
|
|
21
22
|
reflectProviders(module: Type<any>, token: string): void;
|
|
@@ -47,7 +48,22 @@ export declare class DependenciesScanner {
|
|
|
47
48
|
[type: string]: Function;
|
|
48
49
|
};
|
|
49
50
|
isDynamicModule(module: Type<any> | DynamicModule): module is DynamicModule;
|
|
50
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @param metatype
|
|
53
|
+
* @returns `true` if `metatype` is annotated with the `@Injectable()` decorator.
|
|
54
|
+
*/
|
|
55
|
+
private isInjectable;
|
|
56
|
+
/**
|
|
57
|
+
* @param metatype
|
|
58
|
+
* @returns `true` if `metatype` is annotated with the `@Controller()` decorator.
|
|
59
|
+
*/
|
|
60
|
+
private isController;
|
|
61
|
+
/**
|
|
62
|
+
* @param metatype
|
|
63
|
+
* @returns `true` if `metatype` is annotated with the `@Catch()` decorator.
|
|
64
|
+
*/
|
|
65
|
+
private isExceptionFilter;
|
|
66
|
+
private isForwardReference;
|
|
51
67
|
private flatten;
|
|
52
68
|
private isRequestOrTransient;
|
|
53
69
|
}
|
package/scanner.js
CHANGED
|
@@ -11,6 +11,7 @@ const application_config_1 = require("./application-config");
|
|
|
11
11
|
const constants_2 = require("./constants");
|
|
12
12
|
const circular_dependency_exception_1 = require("./errors/exceptions/circular-dependency.exception");
|
|
13
13
|
const invalid_module_exception_1 = require("./errors/exceptions/invalid-module.exception");
|
|
14
|
+
const invalid_class_module_exception_1 = require("./errors/exceptions/invalid-class-module.exception");
|
|
14
15
|
const undefined_module_exception_1 = require("./errors/exceptions/undefined-module.exception");
|
|
15
16
|
const get_class_scope_1 = require("./helpers/get-class-scope");
|
|
16
17
|
const internal_core_module_factory_1 = require("./injector/internal-core-module-factory");
|
|
@@ -19,6 +20,7 @@ class DependenciesScanner {
|
|
|
19
20
|
this.container = container;
|
|
20
21
|
this.metadataScanner = metadataScanner;
|
|
21
22
|
this.applicationConfig = applicationConfig;
|
|
23
|
+
this.logger = new common_1.Logger(DependenciesScanner.name);
|
|
22
24
|
this.applicationProvidersApplyMap = [];
|
|
23
25
|
}
|
|
24
26
|
async scan(module) {
|
|
@@ -65,11 +67,17 @@ class DependenciesScanner {
|
|
|
65
67
|
}
|
|
66
68
|
return [moduleInstance].concat(registeredModuleRefs);
|
|
67
69
|
}
|
|
68
|
-
async insertModule(
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
async insertModule(moduleDefinition, scope) {
|
|
71
|
+
const moduleToAdd = this.isForwardReference(moduleDefinition)
|
|
72
|
+
? moduleDefinition.forwardRef()
|
|
73
|
+
: moduleDefinition;
|
|
74
|
+
if (this.isInjectable(moduleToAdd) ||
|
|
75
|
+
this.isController(moduleToAdd) ||
|
|
76
|
+
this.isExceptionFilter(moduleToAdd)) {
|
|
77
|
+
// TODO(v9): Throw the exception instead of printing a warning
|
|
78
|
+
this.logger.warn(new invalid_class_module_exception_1.InvalidClassModuleException(moduleDefinition, scope).message);
|
|
71
79
|
}
|
|
72
|
-
return this.container.addModule(
|
|
80
|
+
return this.container.addModule(moduleToAdd, scope);
|
|
73
81
|
}
|
|
74
82
|
async scanModulesForDependencies(modules = this.container.getModules()) {
|
|
75
83
|
for (const [token, { metatype }] of modules) {
|
|
@@ -138,8 +146,8 @@ class DependenciesScanner {
|
|
|
138
146
|
}
|
|
139
147
|
reflectParamInjectables(component, token, metadataKey) {
|
|
140
148
|
const paramsMetadata = this.metadataScanner.scanFromPrototype(null, component.prototype, method => Reflect.getMetadata(metadataKey, component, method));
|
|
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));
|
|
149
|
+
const paramsInjectables = this.flatten(paramsMetadata).map((param) => (0, common_1.flatten)(Object.keys(param).map(k => param[k].pipes)).filter(shared_utils_1.isFunction));
|
|
150
|
+
(0, common_1.flatten)(paramsInjectables).forEach((injectable) => this.insertInjectable(injectable, token, component));
|
|
143
151
|
}
|
|
144
152
|
reflectKeyMetadata(component, key, method) {
|
|
145
153
|
let prototype = component.prototype;
|
|
@@ -176,16 +184,16 @@ class DependenciesScanner {
|
|
|
176
184
|
calculateDistance(rootModule);
|
|
177
185
|
}
|
|
178
186
|
async insertImport(related, token, context) {
|
|
179
|
-
if (shared_utils_1.isUndefined(related)) {
|
|
187
|
+
if ((0, shared_utils_1.isUndefined)(related)) {
|
|
180
188
|
throw new circular_dependency_exception_1.CircularDependencyException(context);
|
|
181
189
|
}
|
|
182
|
-
if (related
|
|
190
|
+
if (this.isForwardReference(related)) {
|
|
183
191
|
return this.container.addImport(related.forwardRef(), token);
|
|
184
192
|
}
|
|
185
193
|
await this.container.addImport(related, token);
|
|
186
194
|
}
|
|
187
195
|
isCustomProvider(provider) {
|
|
188
|
-
return provider && !shared_utils_1.isNil(provider.provide);
|
|
196
|
+
return provider && !(0, shared_utils_1.isNil)(provider.provide);
|
|
189
197
|
}
|
|
190
198
|
insertProvider(provider, token) {
|
|
191
199
|
const isCustomProvider = this.isCustomProvider(provider);
|
|
@@ -198,10 +206,10 @@ class DependenciesScanner {
|
|
|
198
206
|
if (!providersKeys.includes(type)) {
|
|
199
207
|
return this.container.addProvider(provider, token);
|
|
200
208
|
}
|
|
201
|
-
const providerToken = `${type} (UUID: ${random_string_generator_util_1.randomStringGenerator()})`;
|
|
209
|
+
const providerToken = `${type} (UUID: ${(0, random_string_generator_util_1.randomStringGenerator)()})`;
|
|
202
210
|
let scope = provider.scope;
|
|
203
|
-
if (shared_utils_1.isNil(scope) && provider.useClass) {
|
|
204
|
-
scope = get_class_scope_1.getClassScope(provider.useClass);
|
|
211
|
+
if ((0, shared_utils_1.isNil)(scope) && provider.useClass) {
|
|
212
|
+
scope = (0, get_class_scope_1.getClassScope)(provider.useClass);
|
|
205
213
|
}
|
|
206
214
|
this.applicationProvidersApplyMap.push({
|
|
207
215
|
type,
|
|
@@ -238,13 +246,13 @@ class DependenciesScanner {
|
|
|
238
246
|
* to all controllers metadata storage
|
|
239
247
|
*/
|
|
240
248
|
addScopedEnhancersMetadata() {
|
|
241
|
-
iterare_1.iterate(this.applicationProvidersApplyMap)
|
|
249
|
+
(0, iterare_1.iterate)(this.applicationProvidersApplyMap)
|
|
242
250
|
.filter(wrapper => this.isRequestOrTransient(wrapper.scope))
|
|
243
251
|
.forEach(({ moduleKey, providerKey }) => {
|
|
244
252
|
const modulesContainer = this.container.getModules();
|
|
245
253
|
const { injectables } = modulesContainer.get(moduleKey);
|
|
246
254
|
const instanceWrapper = injectables.get(providerKey);
|
|
247
|
-
iterare_1.iterate(modulesContainer.values())
|
|
255
|
+
(0, iterare_1.iterate)(modulesContainer.values())
|
|
248
256
|
.map(module => module.controllers.values())
|
|
249
257
|
.flatten()
|
|
250
258
|
.forEach(controller => controller.addEnhancerMetadata(instanceWrapper));
|
|
@@ -288,6 +296,27 @@ class DependenciesScanner {
|
|
|
288
296
|
isDynamicModule(module) {
|
|
289
297
|
return module && !!module.module;
|
|
290
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* @param metatype
|
|
301
|
+
* @returns `true` if `metatype` is annotated with the `@Injectable()` decorator.
|
|
302
|
+
*/
|
|
303
|
+
isInjectable(metatype) {
|
|
304
|
+
return !!Reflect.getMetadata(constants_1.INJECTABLE_WATERMARK, metatype);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* @param metatype
|
|
308
|
+
* @returns `true` if `metatype` is annotated with the `@Controller()` decorator.
|
|
309
|
+
*/
|
|
310
|
+
isController(metatype) {
|
|
311
|
+
return !!Reflect.getMetadata(constants_1.CONTROLLER_WATERMARK, metatype);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* @param metatype
|
|
315
|
+
* @returns `true` if `metatype` is annotated with the `@Catch()` decorator.
|
|
316
|
+
*/
|
|
317
|
+
isExceptionFilter(metatype) {
|
|
318
|
+
return !!Reflect.getMetadata(constants_1.CATCH_WATERMARK, metatype);
|
|
319
|
+
}
|
|
291
320
|
isForwardReference(module) {
|
|
292
321
|
return module && !!module.forwardRef;
|
|
293
322
|
}
|
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 (shared_utils_1.isEmpty(metadataCollection)) {
|
|
45
|
+
if ((0, 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 (shared_utils_1.isObject(a) && shared_utils_1.isObject(b)) {
|
|
52
|
+
if ((0, shared_utils_1.isObject)(a) && (0, shared_utils_1.isObject)(b)) {
|
|
53
53
|
return Object.assign(Object.assign({}, a), b);
|
|
54
54
|
}
|
|
55
55
|
return [a, b];
|