Skip to content

Commit

Permalink
tests(@nestjs) add dynamic modules & express instance integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 20, 2018
1 parent 6835dd9 commit 52acfe4
Show file tree
Hide file tree
Showing 237 changed files with 2,567 additions and 1,301 deletions.
46 changes: 23 additions & 23 deletions bundle/common/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
export declare const metadata: {
MODULES: string;
IMPORTS: string;
COMPONENTS: string;
PROVIDERS: string;
CONTROLLERS: string;
EXPORTS: string;
MODULES: string;
IMPORTS: string;
COMPONENTS: string;
PROVIDERS: string;
CONTROLLERS: string;
EXPORTS: string;
};
export declare const SHARED_MODULE_METADATA = '__sharedModule__';
export declare const GLOBAL_MODULE_METADATA = '__globalModule__';
export declare const PATH_METADATA = 'path';
export declare const PARAMTYPES_METADATA = 'design:paramtypes';
export declare const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
export declare const METHOD_METADATA = 'method';
export declare const ROUTE_ARGS_METADATA = '__routeArguments__';
export declare const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
export declare const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
export declare const FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
export declare const PIPES_METADATA = '__pipes__';
export declare const GUARDS_METADATA = '__guards__';
export declare const RENDER_METADATA = '__renderTemplate__';
export declare const INTERCEPTORS_METADATA = '__interceptors__';
export declare const HTTP_CODE_METADATA = '__httpCode__';
export declare const GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
export declare const MODULE_PATH = '__module_path__';
export declare const SHARED_MODULE_METADATA = "__sharedModule__";
export declare const GLOBAL_MODULE_METADATA = "__globalModule__";
export declare const PATH_METADATA = "path";
export declare const PARAMTYPES_METADATA = "design:paramtypes";
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
export declare const METHOD_METADATA = "method";
export declare const ROUTE_ARGS_METADATA = "__routeArguments__";
export declare const CUSTOM_ROUTE_AGRS_METADATA = "__customRouteArgs__";
export declare const EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
export declare const FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
export declare const PIPES_METADATA = "__pipes__";
export declare const GUARDS_METADATA = "__guards__";
export declare const RENDER_METADATA = "__renderTemplate__";
export declare const INTERCEPTORS_METADATA = "__interceptors__";
export declare const HTTP_CODE_METADATA = "__httpCode__";
export declare const GATEWAY_MIDDLEWARES = "__gatewayMiddlewares";
export declare const MODULE_PATH = "__module_path__";
5 changes: 5 additions & 0 deletions bundle/common/decorators/core/component.decorator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
*/
export declare function Injectable(): ClassDecorator;
/**
* @deprecated
* Defines the Component. The component can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
export declare function Component(): ClassDecorator;
/**
* @deprecated
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
*/
export declare function Pipe(): ClassDecorator;
/**
* @deprecated
* Defines the Guard. The Guard should implement the `CanActivate` interface.
*/
export declare function Guard(): ClassDecorator;
/**
* @deprecated
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
*/
export declare function Middleware(): ClassDecorator;
/**
* @deprecated
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
*/
export declare function Interceptor(): ClassDecorator;
Expand Down
8 changes: 7 additions & 1 deletion bundle/common/decorators/core/component.decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function Injectable() {
}
exports.Injectable = Injectable;
/**
* @deprecated
* Defines the Component. The component can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
Expand All @@ -19,13 +20,16 @@ function Component() {
}
exports.Component = Component;
/**
* @deprecated
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
*/
function Pipe() {
deprecate('The @Pipe() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
return (target) => { };
}
exports.Pipe = Pipe;
/**
* @deprecated
* Defines the Guard. The Guard should implement the `CanActivate` interface.
*/
function Guard() {
Expand All @@ -34,6 +38,7 @@ function Guard() {
}
exports.Guard = Guard;
/**
* @deprecated
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
*/
function Middleware() {
Expand All @@ -42,6 +47,7 @@ function Middleware() {
}
exports.Middleware = Middleware;
/**
* @deprecated
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
*/
function Interceptor() {
Expand All @@ -54,7 +60,7 @@ function mixin(mixinClass) {
Object.defineProperty(mixinClass, 'name', {
value: JSON.stringify(this.offset),
});
Component()(mixinClass);
Injectable()(mixinClass);
return mixinClass;
}
exports.mixin = mixin;
2 changes: 1 addition & 1 deletion bundle/common/decorators/core/dependencies.decorator.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import 'reflect-metadata';
export declare function flatten(arr: any): any;
export declare function flatten(arr: any[]): any;
export declare const Dependencies: (...dependencies: any[]) => ClassDecorator;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { ExceptionFilter } from '../../index';
* When the `@UseFilters()` is used on the handle level:
* - Exception Filter will be set up only to specified method
*
* @param {ExceptionFilter[]} ...filters (instances)
* @param {ExceptionFilter[]} ...filters
*/
export declare const UseFilters: (...filters: ExceptionFilter[]) => (target: object, key?: any, descriptor?: any) => any;
export declare const UseFilters: (...filters: (Function | ExceptionFilter<any>)[]) => (target: any, key?: any, descriptor?: any) => any;
12 changes: 9 additions & 3 deletions bundle/common/decorators/core/exception-filters.decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const shared_utils_1 = require("../../utils/shared.utils");
const validate_each_util_1 = require("../../utils/validate-each.util");
const defineFiltersMetadata = (...filters) => {
return (target, key, descriptor) => {
const isFilterValid = filter => filter && (shared_utils_1.isFunction(filter) || shared_utils_1.isFunction(filter.catch));
if (descriptor) {
Reflect.defineMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, descriptor.value);
validate_each_util_1.validateEach(target.constructor, filters, isFilterValid, '@UseFilters', 'filter');
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, target);
validate_each_util_1.validateEach(target, filters, isFilterValid, '@UseFilters', 'filter');
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, target);
return target;
};
};
Expand All @@ -20,6 +26,6 @@ const defineFiltersMetadata = (...filters) => {
* When the `@UseFilters()` is used on the handle level:
* - Exception Filter will be set up only to specified method
*
* @param {ExceptionFilter[]} ...filters (instances)
* @param {ExceptionFilter[]} ...filters
*/
exports.UseFilters = (...filters) => defineFiltersMetadata(...filters);
5 changes: 3 additions & 2 deletions bundle/common/decorators/core/use-guards.decorator.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CanActivate } from '../../interfaces';
/**
* Binds guards to the particular context.
* When the `@UseGuards()` is used on the controller level:
Expand All @@ -6,6 +7,6 @@
* When the `@UseGuards()` is used on the handler level:
* - Guard will be registered only to specified method
*
* @param {} ...guards (types)
* @param {} ...guards
*/
export declare function UseGuards(...guards: any[]): (target: object, key?: any, descriptor?: any) => any;
export declare function UseGuards(...guards: (CanActivate | Function)[]): (target: any, key?: any, descriptor?: any) => any;
12 changes: 9 additions & 3 deletions bundle/common/decorators/core/use-guards.decorator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const validate_each_util_1 = require("../../utils/validate-each.util");
const shared_utils_1 = require("../../utils/shared.utils");
/**
* Binds guards to the particular context.
* When the `@UseGuards()` is used on the controller level:
Expand All @@ -9,15 +12,18 @@ const constants_1 = require("../../constants");
* When the `@UseGuards()` is used on the handler level:
* - Guard will be registered only to specified method
*
* @param {} ...guards (types)
* @param {} ...guards
*/
function UseGuards(...guards) {
return (target, key, descriptor) => {
const isValidGuard = guard => guard && (shared_utils_1.isFunction(guard) || shared_utils_1.isFunction(guard.canActivate));
if (descriptor) {
Reflect.defineMetadata(constants_1.GUARDS_METADATA, guards, descriptor.value);
validate_each_util_1.validateEach(target.constructor, guards, isValidGuard, '@UseGuards', 'guard');
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(constants_1.GUARDS_METADATA, guards, target);
validate_each_util_1.validateEach(target, guards, isValidGuard, '@UseGuards', 'guard');
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, target);
return target;
};
}
Expand Down
5 changes: 3 additions & 2 deletions bundle/common/decorators/core/use-interceptors.decorator.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NestInterceptor } from '../../interfaces';
/**
* Binds interceptors to the particular context.
* When the `@UseInterceptors()` is used on the controller level:
Expand All @@ -6,6 +7,6 @@
* When the `@UseInterceptors()` is used on the handle level:
* - Interceptor will be registered only to specified method
*
* @param {} ...interceptors (types)
* @param {} ...interceptors
*/
export declare function UseInterceptors(...interceptors: any[]): (target: object, key?: any, descriptor?: any) => any;
export declare function UseInterceptors(...interceptors: (NestInterceptor | Function)[]): (target: any, key?: any, descriptor?: any) => any;
13 changes: 10 additions & 3 deletions bundle/common/decorators/core/use-interceptors.decorator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const shared_utils_1 = require("../../utils/shared.utils");
const validate_each_util_1 = require("../../utils/validate-each.util");
/**
* Binds interceptors to the particular context.
* When the `@UseInterceptors()` is used on the controller level:
Expand All @@ -9,15 +12,19 @@ const constants_1 = require("../../constants");
* When the `@UseInterceptors()` is used on the handle level:
* - Interceptor will be registered only to specified method
*
* @param {} ...interceptors (types)
* @param {} ...interceptors
*/
function UseInterceptors(...interceptors) {
return (target, key, descriptor) => {
const isValidInterceptor = interceptor => interceptor &&
(shared_utils_1.isFunction(interceptor) || shared_utils_1.isFunction(interceptor.intercept));
if (descriptor) {
Reflect.defineMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, descriptor.value);
validate_each_util_1.validateEach(target.constructor, interceptors, isValidInterceptor, '@UseInterceptors', 'interceptor');
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, target);
validate_each_util_1.validateEach(target, interceptors, isValidInterceptor, '@UseInterceptors', 'interceptor');
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, target);
return target;
};
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/common/decorators/core/use-pipes.decorator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { PipeTransform } from '../../interfaces/index';
* When the `@UsePipes()` is used on the handle level:
* - Pipe will be registered only to specified method
*
* @param {PipeTransform[]} ...pipes (instances)
* @param {PipeTransform[]} ...pipes
*/
export declare function UsePipes(...pipes: PipeTransform<any>[]): (target: object, key?: any, descriptor?: any) => any;
export declare function UsePipes(...pipes: (PipeTransform | Function)[]): (target: any, key?: any, descriptor?: any) => any;
11 changes: 8 additions & 3 deletions bundle/common/decorators/core/use-pipes.decorator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const validate_each_util_1 = require("../../utils/validate-each.util");
const shared_utils_1 = require("../../utils/shared.utils");
/**
* Binds pipes to the particular context.
* When the `@UsePipes()` is used on the controller level:
Expand All @@ -9,15 +12,17 @@ const constants_1 = require("../../constants");
* When the `@UsePipes()` is used on the handle level:
* - Pipe will be registered only to specified method
*
* @param {PipeTransform[]} ...pipes (instances)
* @param {PipeTransform[]} ...pipes
*/
function UsePipes(...pipes) {
return (target, key, descriptor) => {
const isPipeValid = pipe => pipe && (shared_utils_1.isFunction(pipe) || shared_utils_1.isFunction(pipe.transform));
if (descriptor) {
Reflect.defineMetadata(constants_1.PIPES_METADATA, pipes, descriptor.value);
extend_metadata_util_1.extendArrayMetadata(constants_1.PIPES_METADATA, pipes, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(constants_1.PIPES_METADATA, pipes, target);
validate_each_util_1.validateEach(target, pipes, isPipeValid, '@UsePipes', 'pipe');
extend_metadata_util_1.extendArrayMetadata(constants_1.PIPES_METADATA, pipes, target);
return target;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PipeTransform } from '../../index';
*/
export declare function createParamDecorator(factory: CustomParamFactory): (data?: any, ...pipes: PipeTransform<any>[]) => ParameterDecorator;
/**
* Creates route params custom decorator
* Creates HTTP route param decorator
* @deprecated
* @param factory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createParamDecorator(factory) {
}
exports.createParamDecorator = createParamDecorator;
/**
* Creates route params custom decorator
* Creates HTTP route param decorator
* @deprecated
* @param factory
*/
Expand Down
13 changes: 7 additions & 6 deletions bundle/common/decorators/http/route-params.decorator.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'reflect-metadata';
import { PipeTransform } from '../../index';
import { Type } from '../../interfaces';
export declare type ParamData = object | string | number;
export interface RouteParamsMetadata {
[prop: number]: {
Expand All @@ -15,13 +16,13 @@ export declare const UploadedFile: () => ParameterDecorator;
export declare const UploadedFiles: () => ParameterDecorator;
export declare const Headers: (property?: string) => ParameterDecorator;
export declare function Query(): any;
export declare function Query(...pipes: PipeTransform<any>[]): any;
export declare function Query(property: string, ...pipes: PipeTransform<any>[]): any;
export declare function Query(...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Query(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Body(): any;
export declare function Body(...pipes: PipeTransform<any>[]): any;
export declare function Body(property: string, ...pipes: PipeTransform<any>[]): any;
export declare function Body(...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Body(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Param(): any;
export declare function Param(...pipes: PipeTransform<any>[]): any;
export declare function Param(property: string, ...pipes: PipeTransform<any>[]): any;
export declare function Param(...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare function Param(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): any;
export declare const Req: () => ParameterDecorator;
export declare const Res: () => ParameterDecorator;
3 changes: 3 additions & 0 deletions bundle/common/enums/transport.enum.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export declare enum Transport {
TCP = 0,
REDIS = 1,
NATS = 2,
MQTT = 3,
GRPC = 4,
}
3 changes: 3 additions & 0 deletions bundle/common/enums/transport.enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ var Transport;
(function (Transport) {
Transport[Transport["TCP"] = 0] = "TCP";
Transport[Transport["REDIS"] = 1] = "REDIS";
Transport[Transport["NATS"] = 2] = "NATS";
Transport[Transport["MQTT"] = 3] = "MQTT";
Transport[Transport["GRPC"] = 4] = "GRPC";
})(Transport = exports.Transport || (exports.Transport = {}));
2 changes: 1 addition & 1 deletion bundle/common/http/http.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let HttpModule = class HttpModule {
};
HttpModule = __decorate([
module_decorator_1.Module({
components: [http_service_1.HttpService],
providers: [http_service_1.HttpService],
exports: [http_service_1.HttpService],
})
], HttpModule);
Expand Down

0 comments on commit 52acfe4

Please sign in to comment.