Merge branch 'jbpionnier-refactor_module_path'

This commit is contained in:
Kamil Myśliwiec
2018-10-02 22:41:11 +02:00
50 changed files with 75 additions and 86 deletions

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncClassApplicationModule } from './../src/async-options-class.module';
import { AsyncClassApplicationModule } from '../src/async-options-class.module';
describe('GraphQL (async class)', () => {
let app: INestApplication;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncExistingApplicationModule } from './../src/async-options-existing.module';
import { AsyncExistingApplicationModule } from '../src/async-options-existing.module';
describe('GraphQL (async existing)', () => {
let app: INestApplication;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncApplicationModule } from './../src/async-options.module';
import { AsyncApplicationModule } from '../src/async-options.module';
describe('GraphQL (async configuration)', () => {
let app: INestApplication;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('GraphQL', () => {
let app: INestApplication;

View File

@@ -1,7 +1,6 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication, HttpStatus } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ErrorsController } from '../src/errors/errors.controller';
describe('Error messages', () => {

View File

@@ -2,7 +2,7 @@ import * as express from 'express';
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('Hello world (express instance)', () => {
let server;

View File

@@ -3,7 +3,7 @@ import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-
import { FastifyAdapter } from '@nestjs/core/adapters/fastify-adapter';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('Hello world (fastify adapter)', () => {
let app: INestApplication & INestFastifyApplication;

View File

@@ -1,7 +1,7 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication, Injectable, UnauthorizedException } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
import { APP_GUARD } from '@nestjs/core';
@Injectable()

View File

@@ -1,7 +1,7 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('Hello world (default adapter)', () => {
let server;

View File

@@ -1,7 +1,7 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication, Injectable } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';

View File

@@ -1,7 +1,7 @@
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('Hello world (default adapter)', () => {
let server;

View File

@@ -21,7 +21,7 @@ describe('GRPC transport', () => {
transport: Transport.GRPC,
options: {
package: 'math',
protoPath: join(__dirname, './../src/grpc/math.proto'),
protoPath: join(__dirname, '../src/grpc/math.proto'),
},
});
await app.startAllMicroservicesAsync();

View File

@@ -3,7 +3,7 @@ import { Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
import * as express from 'express';
import * as request from 'supertest';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('RPC transport', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('Mongoose', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { AsyncOptionsClassModule } from './../src/async-class-options.module';
import { AsyncOptionsClassModule } from '../src/async-class-options.module';
describe('TypeOrm (async configuration)', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { AsyncOptionsExistingModule } from './../src/async-existing-options.module';
import { AsyncOptionsExistingModule } from '../src/async-existing-options.module';
describe('TypeOrm (async configuration)', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { AsyncOptionsFactoryModule } from './../src/async-options.module';
import { AsyncOptionsFactoryModule } from '../src/async-options.module';
describe('TypeOrm (async configuration)', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { AsyncApplicationModule } from './../src/app-async.module';
import { AsyncApplicationModule } from '../src/app-async.module';
describe('TypeOrm (async configuration)', () => {
let server;

View File

@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from './../src/app.module';
import { ApplicationModule } from '../src/app.module';
describe('TypeOrm', () => {
let server;

View File

@@ -55,8 +55,7 @@ export class CacheModule {
}
return {
provide: CACHE_MODULE_OPTIONS,
useFactory: async (optionsFactory: CacheOptionsFactory) =>
await optionsFactory.createCacheOptions(),
useFactory: async (optionsFactory: CacheOptionsFactory) => optionsFactory.createCacheOptions(),
inject: [options.useExisting || options.useClass],
};
}

View File

@@ -52,8 +52,7 @@ export class MulterModule {
}
return {
provide: MULTER_MODULE_OPTIONS,
useFactory: async (optionsFactory: MulterOptionsFactory) =>
await optionsFactory.createMulterOptions(),
useFactory: async (optionsFactory: MulterOptionsFactory) => optionsFactory.createMulterOptions(),
inject: [options.useExisting || options.useClass],
};
}

View File

@@ -1,4 +1,4 @@
import axios, { AxiosRequestConfig } from 'axios';
import Axios, { AxiosRequestConfig } from 'axios';
import { Module } from '../decorators/modules/module.decorator';
import { DynamicModule } from '../interfaces';
import { randomStringGenerator } from '../utils/random-string-generator.util';
@@ -10,7 +10,7 @@ import { HttpService } from './http.service';
HttpService,
{
provide: AXIOS_INSTANCE_TOKEN,
useValue: axios,
useValue: Axios,
},
],
exports: [HttpService],
@@ -22,7 +22,7 @@ export class HttpModule {
providers: [
{
provide: AXIOS_INSTANCE_TOKEN,
useValue: axios.create(config),
useValue: Axios.create(config),
},
{
provide: HTTP_MODULE_ID,

View File

@@ -1,4 +1,4 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import Axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { defer, Observable } from 'rxjs';
import { Inject } from '../decorators';
import { AXIOS_INSTANCE_TOKEN } from './http.constants';
@@ -6,7 +6,7 @@ import { AXIOS_INSTANCE_TOKEN } from './http.constants';
export class HttpService {
constructor(
@Inject(AXIOS_INSTANCE_TOKEN)
private readonly instance: AxiosInstance = axios,
private readonly instance: AxiosInstance = Axios,
) {}
request<T = any>(config: AxiosRequestConfig): Observable<AxiosResponse<T>> {

View File

@@ -6,7 +6,7 @@ export declare class Error {
}
export class RuntimeException extends Error {
constructor(private msg = ``) {
constructor(private readonly msg = ``) {
super(msg);
}

View File

@@ -114,7 +114,7 @@ export class ExternalContextCreator {
callback,
handler(initialArgs, ...args),
);
return await this.transformToResult(result);
return this.transformToResult(result);
};
}
@@ -205,7 +205,7 @@ export class ExternalContextCreator {
{ metatype, type, data },
transforms: Transform<any>[],
): Promise<any> {
return await this.pipesConsumer.apply(
return this.pipesConsumer.apply(
value,
{ metatype, type, data },
transforms,
@@ -214,7 +214,7 @@ export class ExternalContextCreator {
public async transformToResult(resultOrDeffered) {
if (resultOrDeffered && isFunction(resultOrDeffered.subscribe)) {
return await resultOrDeffered.toPromise();
return resultOrDeffered.toPromise();
}
return resultOrDeffered;
}

View File

@@ -122,7 +122,7 @@ export class Injector {
module: Module,
) {
if (wrapper.isPending) {
return await wrapper.done$;
return wrapper.done$;
}
const done = this.applyDoneHook(wrapper);
const { metatype, name, inject } = wrapper;
@@ -220,7 +220,7 @@ export class Injector {
throw new UndefinedDependencyException(wrapper.name, dependencyContext);
}
const token = this.resolveParamToken(wrapper, param);
return await this.resolveComponentInstance<T>(
return this.resolveComponentInstance<T>(
module,
isFunction(token) ? (token as Type<any>).name : token,
dependencyContext,
@@ -275,7 +275,7 @@ export class Injector {
module,
wrapper,
);
return components.has(name) ? components.get(name) : await scanInExports();
return components.has(name) ? components.get(name) : scanInExports();
}
public async lookupComponentInExports<T = any>(

View File

@@ -52,8 +52,7 @@ export class InstanceLoader {
private async createInstancesOfComponents(module: Module) {
await Promise.all(
[...module.components.values()].map(
async wrapper =>
await this.injector.loadInstanceOfComponent(wrapper, module),
async wrapper => this.injector.loadInstanceOfComponent(wrapper, module),
),
);
}
@@ -67,8 +66,7 @@ export class InstanceLoader {
private async createInstancesOfRoutes(module: Module) {
await Promise.all(
[...module.routes.values()].map(
async wrapper =>
await this.injector.loadInstanceOfRoute(wrapper, module),
async wrapper => this.injector.loadInstanceOfRoute(wrapper, module),
),
);
}
@@ -85,8 +83,7 @@ export class InstanceLoader {
private async createInstancesOfInjectables(module: Module) {
await Promise.all(
[...module.injectables.values()].map(
async wrapper =>
await this.injector.loadInstanceOfInjectable(wrapper, module),
async wrapper => this.injector.loadInstanceOfInjectable(wrapper, module),
),
);
}

View File

@@ -42,11 +42,11 @@ export type ComponentMetatype =
export class Module {
private readonly _id: string;
private _relatedModules = new Set<Module>();
private _components = new Map<any, InstanceWrapper<Injectable>>();
private _injectables = new Map<any, InstanceWrapper<Injectable>>();
private _routes = new Map<string, InstanceWrapper<Controller>>();
private _exports = new Set<string>();
private readonly _relatedModules = new Set<Module>();
private readonly _components = new Map<any, InstanceWrapper<Injectable>>();
private readonly _injectables = new Map<any, InstanceWrapper<Injectable>>();
private readonly _routes = new Map<string, InstanceWrapper<Controller>>();
private readonly _exports = new Set<string>();
constructor(
private readonly _metatype: Type<any>,

View File

@@ -14,7 +14,7 @@ export class InterceptorsConsumer {
next: () => Promise<any>,
): Promise<any> {
if (isEmpty(interceptors)) {
return await await next();
return next();
}
const context = this.createContext(args, instance, callback);
const start$ = defer(() => this.transformDeffered(next));
@@ -27,11 +27,10 @@ export class InterceptorsConsumer {
};
*/
const result$ = await interceptors.reduce(
async (stream$, interceptor) =>
await interceptor.intercept(context, await stream$),
async (stream$, interceptor) => interceptor.intercept(context, await stream$),
Promise.resolve(start$),
);
return await result$.toPromise();
return result$.toPromise();
}
public createContext(

View File

@@ -37,7 +37,7 @@ export class MiddlewareBuilder implements MiddlewareConsumer {
return [].concat(middleware).map(bindArgs);
}
private static ConfigProxy = class implements MiddlewareConfigProxy {
private static readonly ConfigProxy = class implements MiddlewareConfigProxy {
private contextParameters = null;
private excludedRoutes: RouteInfo[] = [];
private readonly includedRoutes: any[];

View File

@@ -11,8 +11,7 @@ export class MiddlewareResolver {
const middleware = this.middlewareContainer.getMiddleware(moduleName);
await Promise.all(
[...middleware.values()].map(
async wrapper =>
await this.resolveMiddlewareInstance(wrapper, middleware, module),
async wrapper => this.resolveMiddlewareInstance(wrapper, middleware, module),
),
);
}

View File

@@ -5,7 +5,7 @@ export const filterMiddleware = middleware => {
return []
.concat(middleware)
.filter(isFunction)
.map(ware => mapToClass(ware));
.map(mapToClass);
};
export const mapToClass = middleware => {

View File

@@ -91,7 +91,7 @@ export class NestApplicationContext extends ModuleRef
.map(([key, { instance }]) => instance)
.filter(instance => !isNil(instance))
.filter(this.hasOnModuleInitHook)
.map(async instance => await (instance as OnModuleInit).onModuleInit()),
.map(async instance => (instance as OnModuleInit).onModuleInit()),
);
if (moduleClassInstance && this.hasOnModuleInitHook(moduleClassInstance)) {
await (moduleClassInstance as OnModuleInit).onModuleInit();
@@ -121,10 +121,7 @@ export class NestApplicationContext extends ModuleRef
.map(([key, { instance }]) => instance)
.filter(instance => !isNil(instance))
.filter(this.hasOnModuleDestroyHook)
.map(
async instance =>
await (instance as OnModuleDestroy).onModuleDestroy(),
),
.map(async instance => (instance as OnModuleDestroy).onModuleDestroy()),
);
if (
moduleClassInstance &&
@@ -155,9 +152,8 @@ export class NestApplicationContext extends ModuleRef
.map(([key, { instance }]) => instance)
.filter(instance => !isNil(instance))
.filter(this.hasOnAppBotstrapHook)
.map(
async instance =>
await (instance as OnApplicationBootstrap).onApplicationBootstrap(),
.map(async instance =>
(instance as OnApplicationBootstrap).onApplicationBootstrap(),
),
);
if (moduleClassInstance && this.hasOnAppBotstrapHook(moduleClassInstance)) {

View File

@@ -117,7 +117,7 @@ export class NestFactoryStatic {
const context = this.createNestInstance<NestApplicationContext>(
new NestApplicationContext(container, [], root),
);
return await context.init();
return context.init();
}
private createNestInstance<T>(instance: T): T {

View File

@@ -10,7 +10,7 @@ export class PipesConsumer {
transforms: Transform<any>[],
) {
const token = this.paramsTokenFactory.exchangeEnumForString(type);
return await this.applyPipes(
return this.applyPipes(
value,
{ metatype, type: token, data },
transforms,
@@ -22,7 +22,7 @@ export class PipesConsumer {
{ metatype, type, data }: { metatype; type?; data? },
transforms: Transform<any>[],
) {
return await transforms.reduce(async (defferedValue, fn) => {
return transforms.reduce(async (defferedValue, fn) => {
const val = await defferedValue;
const result = fn(val, { metatype, type, data });
return result;

View File

@@ -186,7 +186,7 @@ export class RouterExecutionContext {
type === RouteParamtypes.PARAM ||
isString(type)
) {
return await this.pipesConsumer.apply(
return this.pipesConsumer.apply(
value,
{ metatype, type, data },
transforms,

View File

@@ -21,7 +21,7 @@ export class RouterResponseController {
public async transformToResult(resultOrDeffered) {
if (resultOrDeffered && isFunction(resultOrDeffered.subscribe)) {
return await resultOrDeffered.toPromise();
return resultOrDeffered.toPromise();
}
return resultOrDeffered;
}

View File

@@ -79,7 +79,7 @@ export class DependenciesScanner {
public async storeModule(module: any, scope: Type<any>[]) {
if (module && module.forwardRef) {
return await this.container.addModule(module.forwardRef(), scope);
return this.container.addModule(module.forwardRef(), scope);
}
await this.container.addModule(module, scope);
}
@@ -256,7 +256,7 @@ export class DependenciesScanner {
throw new CircularDependencyException(context);
}
if (related && related.forwardRef) {
return await this.container.addRelatedModule(related.forwardRef(), token);
return this.container.addRelatedModule(related.forwardRef(), token);
}
await this.container.addRelatedModule(related, token);
}

View File

@@ -74,16 +74,16 @@ describe('InterceptorsConsumer', () => {
const val = 3;
const next = async () => val;
expect(
await await consumer.transformDeffered(next).toPromise(),
await consumer.transformDeffered(next).toPromise(),
).to.be.eql(val);
});
});
describe('when next() result is Promise', () => {
it('should return Observable', async () => {
const val = 3;
const next = () => Promise.resolve(val);
const next = async () => val;
expect(
await await consumer.transformDeffered(next).toPromise(),
await consumer.transformDeffered(next).toPromise(),
).to.be.eql(val);
});
});

View File

@@ -30,7 +30,7 @@ export abstract class ClientProxy {
if (isNil(pattern) || isNil(data)) {
return _throw(new InvalidMessageException());
}
return defer(async () => await this.connect()).pipe(
return defer(async () => this.connect()).pipe(
mergeMap(
() =>
new Observable((observer: Observer<TResult>) => {

View File

@@ -26,7 +26,7 @@ export class ClientRedis extends ClientProxy {
protected pubClient: RedisClient;
protected subClient: RedisClient;
protected connection: Promise<any>;
private isExplicitlyTerminated = false;
protected isExplicitlyTerminated = false;
constructor(protected readonly options: ClientOptions['options']) {
super();
@@ -48,6 +48,7 @@ export class ClientRedis extends ClientProxy {
this.pubClient && this.pubClient.quit();
this.subClient && this.subClient.quit();
this.pubClient = this.subClient = null;
this.isExplicitlyTerminated = true;
}
public connect(): Promise<any> {

View File

@@ -56,7 +56,7 @@ export class RpcContextCreator {
return this.rpcProxy.create(async (...args) => {
fnCanActivate && (await fnCanActivate(args));
return await this.interceptorsConsumer.intercept(
return this.interceptorsConsumer.intercept(
interceptors,
args,
instance,

View File

@@ -120,7 +120,7 @@ export class NestMicroservice extends NestApplicationContext
}
public async listenAsync(): Promise<any> {
return await new Promise(resolve => this.listen(resolve));
return new Promise(resolve => this.listen(resolve));
}
public async close(): Promise<any> {

View File

@@ -58,8 +58,7 @@ export class ServerMqtt extends Server implements CustomTransportStrategy {
}
public getMessageHandler(pub: MqttClient): any {
return async (channel, buffer) =>
await this.handleMessage(channel, buffer, pub);
return async (channel, buffer) => this.handleMessage(channel, buffer, pub);
}
public async handleMessage(

View File

@@ -64,8 +64,7 @@ export class ServerNats extends Server implements CustomTransportStrategy {
}
public getMessageHandler(channel: string, client: Client) {
return async (buffer, replyTo: string) =>
await this.handleMessage(channel, buffer, client, replyTo);
return async (buffer, replyTo: string) => this.handleMessage(channel, buffer, client, replyTo);
}
public async handleMessage(

View File

@@ -72,8 +72,7 @@ export class ServerRedis extends Server implements CustomTransportStrategy {
}
public getMessageHandler(pub: RedisClient) {
return async (channel, buffer) =>
await this.handleMessage(channel, buffer, pub);
return async (channel, buffer) => this.handleMessage(channel, buffer, pub);
}
public async handleMessage(channel, buffer: string | any, pub: RedisClient) {

View File

@@ -42,7 +42,7 @@ export class ServerTCP extends Server implements CustomTransportStrategy {
const readSocket = this.getSocketInstance(socket);
readSocket.on(
MESSAGE_EVENT,
async msg => await this.handleMessage(readSocket, msg),
async msg => this.handleMessage(readSocket, msg),
);
}

View File

@@ -55,7 +55,7 @@ export class WsContextCreator {
return this.wsProxy.create(async (...args) => {
fnCanActivate && (await fnCanActivate(args));
return await this.interceptorsConsumer.intercept(
return this.interceptorsConsumer.intercept(
interceptors,
args,
instance,

View File

@@ -73,7 +73,7 @@ export class SocketModule {
const servers = this.socketsContainer.getAllServers();
await Promise.all(
iterate(servers.values()).map(
async ({ server }) => server && (await adapter.close(server)),
async ({ server }) => server && adapter.close(server),
),
);
this.socketsContainer.clear();

View File

@@ -50,7 +50,10 @@
],
"one-variable-per-declaration": [
false
]
],
"no-return-await": true,
"match-default-export-name": true,
"prefer-readonly": true
},
"rulesDirectory": []
}