Skip to content

Commit 52acfe4

Browse files
tests(@nestjs) add dynamic modules & express instance integration tests
1 parent 6835dd9 commit 52acfe4

237 files changed

Lines changed: 2567 additions & 1301 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundle/common/constants.d.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
export declare const metadata: {
2-
MODULES: string;
3-
IMPORTS: string;
4-
COMPONENTS: string;
5-
PROVIDERS: string;
6-
CONTROLLERS: string;
7-
EXPORTS: string;
2+
MODULES: string;
3+
IMPORTS: string;
4+
COMPONENTS: string;
5+
PROVIDERS: string;
6+
CONTROLLERS: string;
7+
EXPORTS: string;
88
};
9-
export declare const SHARED_MODULE_METADATA = '__sharedModule__';
10-
export declare const GLOBAL_MODULE_METADATA = '__globalModule__';
11-
export declare const PATH_METADATA = 'path';
12-
export declare const PARAMTYPES_METADATA = 'design:paramtypes';
13-
export declare const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
14-
export declare const METHOD_METADATA = 'method';
15-
export declare const ROUTE_ARGS_METADATA = '__routeArguments__';
16-
export declare const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
17-
export declare const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
18-
export declare const FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
19-
export declare const PIPES_METADATA = '__pipes__';
20-
export declare const GUARDS_METADATA = '__guards__';
21-
export declare const RENDER_METADATA = '__renderTemplate__';
22-
export declare const INTERCEPTORS_METADATA = '__interceptors__';
23-
export declare const HTTP_CODE_METADATA = '__httpCode__';
24-
export declare const GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
25-
export declare const MODULE_PATH = '__module_path__';
9+
export declare const SHARED_MODULE_METADATA = "__sharedModule__";
10+
export declare const GLOBAL_MODULE_METADATA = "__globalModule__";
11+
export declare const PATH_METADATA = "path";
12+
export declare const PARAMTYPES_METADATA = "design:paramtypes";
13+
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
14+
export declare const METHOD_METADATA = "method";
15+
export declare const ROUTE_ARGS_METADATA = "__routeArguments__";
16+
export declare const CUSTOM_ROUTE_AGRS_METADATA = "__customRouteArgs__";
17+
export declare const EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
18+
export declare const FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
19+
export declare const PIPES_METADATA = "__pipes__";
20+
export declare const GUARDS_METADATA = "__guards__";
21+
export declare const RENDER_METADATA = "__renderTemplate__";
22+
export declare const INTERCEPTORS_METADATA = "__interceptors__";
23+
export declare const HTTP_CODE_METADATA = "__httpCode__";
24+
export declare const GATEWAY_MIDDLEWARES = "__gatewayMiddlewares";
25+
export declare const MODULE_PATH = "__module_path__";

bundle/common/decorators/core/component.decorator.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
*/
55
export declare function Injectable(): ClassDecorator;
66
/**
7+
* @deprecated
78
* Defines the Component. The component can inject dependencies through constructor.
89
* Those dependencies have to belong to the same module.
910
*/
1011
export declare function Component(): ClassDecorator;
1112
/**
13+
* @deprecated
1214
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
1315
*/
1416
export declare function Pipe(): ClassDecorator;
1517
/**
18+
* @deprecated
1619
* Defines the Guard. The Guard should implement the `CanActivate` interface.
1720
*/
1821
export declare function Guard(): ClassDecorator;
1922
/**
23+
* @deprecated
2024
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
2125
*/
2226
export declare function Middleware(): ClassDecorator;
2327
/**
28+
* @deprecated
2429
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
2530
*/
2631
export declare function Interceptor(): ClassDecorator;

bundle/common/decorators/core/component.decorator.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function Injectable() {
1010
}
1111
exports.Injectable = Injectable;
1212
/**
13+
* @deprecated
1314
* Defines the Component. The component can inject dependencies through constructor.
1415
* Those dependencies have to belong to the same module.
1516
*/
@@ -19,13 +20,16 @@ function Component() {
1920
}
2021
exports.Component = Component;
2122
/**
23+
* @deprecated
2224
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
2325
*/
2426
function Pipe() {
27+
deprecate('The @Pipe() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
2528
return (target) => { };
2629
}
2730
exports.Pipe = Pipe;
2831
/**
32+
* @deprecated
2933
* Defines the Guard. The Guard should implement the `CanActivate` interface.
3034
*/
3135
function Guard() {
@@ -34,6 +38,7 @@ function Guard() {
3438
}
3539
exports.Guard = Guard;
3640
/**
41+
* @deprecated
3742
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
3843
*/
3944
function Middleware() {
@@ -42,6 +47,7 @@ function Middleware() {
4247
}
4348
exports.Middleware = Middleware;
4449
/**
50+
* @deprecated
4551
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
4652
*/
4753
function Interceptor() {
@@ -54,7 +60,7 @@ function mixin(mixinClass) {
5460
Object.defineProperty(mixinClass, 'name', {
5561
value: JSON.stringify(this.offset),
5662
});
57-
Component()(mixinClass);
63+
Injectable()(mixinClass);
5864
return mixinClass;
5965
}
6066
exports.mixin = mixin;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import 'reflect-metadata';
2-
export declare function flatten(arr: any): any;
2+
export declare function flatten(arr: any[]): any;
33
export declare const Dependencies: (...dependencies: any[]) => ClassDecorator;

bundle/common/decorators/core/exception-filters.decorator.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import { ExceptionFilter } from '../../index';
88
* When the `@UseFilters()` is used on the handle level:
99
* - Exception Filter will be set up only to specified method
1010
*
11-
* @param {ExceptionFilter[]} ...filters (instances)
11+
* @param {ExceptionFilter[]} ...filters
1212
*/
13-
export declare const UseFilters: (...filters: ExceptionFilter[]) => (target: object, key?: any, descriptor?: any) => any;
13+
export declare const UseFilters: (...filters: (Function | ExceptionFilter<any>)[]) => (target: any, key?: any, descriptor?: any) => any;

bundle/common/decorators/core/exception-filters.decorator.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
require("reflect-metadata");
44
const constants_1 = require("../../constants");
5+
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
6+
const shared_utils_1 = require("../../utils/shared.utils");
7+
const validate_each_util_1 = require("../../utils/validate-each.util");
58
const defineFiltersMetadata = (...filters) => {
69
return (target, key, descriptor) => {
10+
const isFilterValid = filter => filter && (shared_utils_1.isFunction(filter) || shared_utils_1.isFunction(filter.catch));
711
if (descriptor) {
8-
Reflect.defineMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, descriptor.value);
12+
validate_each_util_1.validateEach(target.constructor, filters, isFilterValid, '@UseFilters', 'filter');
13+
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, descriptor.value);
914
return descriptor;
1015
}
11-
Reflect.defineMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, target);
16+
validate_each_util_1.validateEach(target, filters, isFilterValid, '@UseFilters', 'filter');
17+
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, target);
1218
return target;
1319
};
1420
};
@@ -20,6 +26,6 @@ const defineFiltersMetadata = (...filters) => {
2026
* When the `@UseFilters()` is used on the handle level:
2127
* - Exception Filter will be set up only to specified method
2228
*
23-
* @param {ExceptionFilter[]} ...filters (instances)
29+
* @param {ExceptionFilter[]} ...filters
2430
*/
2531
exports.UseFilters = (...filters) => defineFiltersMetadata(...filters);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CanActivate } from '../../interfaces';
12
/**
23
* Binds guards to the particular context.
34
* When the `@UseGuards()` is used on the controller level:
@@ -6,6 +7,6 @@
67
* When the `@UseGuards()` is used on the handler level:
78
* - Guard will be registered only to specified method
89
*
9-
* @param {} ...guards (types)
10+
* @param {} ...guards
1011
*/
11-
export declare function UseGuards(...guards: any[]): (target: object, key?: any, descriptor?: any) => any;
12+
export declare function UseGuards(...guards: (CanActivate | Function)[]): (target: any, key?: any, descriptor?: any) => any;

bundle/common/decorators/core/use-guards.decorator.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const constants_1 = require("../../constants");
4+
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
5+
const validate_each_util_1 = require("../../utils/validate-each.util");
6+
const shared_utils_1 = require("../../utils/shared.utils");
47
/**
58
* Binds guards to the particular context.
69
* When the `@UseGuards()` is used on the controller level:
@@ -9,15 +12,18 @@ const constants_1 = require("../../constants");
912
* When the `@UseGuards()` is used on the handler level:
1013
* - Guard will be registered only to specified method
1114
*
12-
* @param {} ...guards (types)
15+
* @param {} ...guards
1316
*/
1417
function UseGuards(...guards) {
1518
return (target, key, descriptor) => {
19+
const isValidGuard = guard => guard && (shared_utils_1.isFunction(guard) || shared_utils_1.isFunction(guard.canActivate));
1620
if (descriptor) {
17-
Reflect.defineMetadata(constants_1.GUARDS_METADATA, guards, descriptor.value);
21+
validate_each_util_1.validateEach(target.constructor, guards, isValidGuard, '@UseGuards', 'guard');
22+
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, descriptor.value);
1823
return descriptor;
1924
}
20-
Reflect.defineMetadata(constants_1.GUARDS_METADATA, guards, target);
25+
validate_each_util_1.validateEach(target, guards, isValidGuard, '@UseGuards', 'guard');
26+
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, target);
2127
return target;
2228
};
2329
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NestInterceptor } from '../../interfaces';
12
/**
23
* Binds interceptors to the particular context.
34
* When the `@UseInterceptors()` is used on the controller level:
@@ -6,6 +7,6 @@
67
* When the `@UseInterceptors()` is used on the handle level:
78
* - Interceptor will be registered only to specified method
89
*
9-
* @param {} ...interceptors (types)
10+
* @param {} ...interceptors
1011
*/
11-
export declare function UseInterceptors(...interceptors: any[]): (target: object, key?: any, descriptor?: any) => any;
12+
export declare function UseInterceptors(...interceptors: (NestInterceptor | Function)[]): (target: any, key?: any, descriptor?: any) => any;

bundle/common/decorators/core/use-interceptors.decorator.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const constants_1 = require("../../constants");
4+
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
5+
const shared_utils_1 = require("../../utils/shared.utils");
6+
const validate_each_util_1 = require("../../utils/validate-each.util");
47
/**
58
* Binds interceptors to the particular context.
69
* When the `@UseInterceptors()` is used on the controller level:
@@ -9,15 +12,19 @@ const constants_1 = require("../../constants");
912
* When the `@UseInterceptors()` is used on the handle level:
1013
* - Interceptor will be registered only to specified method
1114
*
12-
* @param {} ...interceptors (types)
15+
* @param {} ...interceptors
1316
*/
1417
function UseInterceptors(...interceptors) {
1518
return (target, key, descriptor) => {
19+
const isValidInterceptor = interceptor => interceptor &&
20+
(shared_utils_1.isFunction(interceptor) || shared_utils_1.isFunction(interceptor.intercept));
1621
if (descriptor) {
17-
Reflect.defineMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, descriptor.value);
22+
validate_each_util_1.validateEach(target.constructor, interceptors, isValidInterceptor, '@UseInterceptors', 'interceptor');
23+
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, descriptor.value);
1824
return descriptor;
1925
}
20-
Reflect.defineMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, target);
26+
validate_each_util_1.validateEach(target, interceptors, isValidInterceptor, '@UseInterceptors', 'interceptor');
27+
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, target);
2128
return target;
2229
};
2330
}

0 commit comments

Comments
 (0)