Merge branch 'middleware-order' of https://github.com/underfin/nest into underfin-middleware-order

This commit is contained in:
Kamil Myśliwiec
2019-08-26 14:23:40 +02:00
4 changed files with 112 additions and 2 deletions

View File

@@ -43,6 +43,7 @@ export class Module {
InstanceWrapper<Controller>
>();
private readonly _exports = new Set<string | symbol>();
private _distance: number = 0;
constructor(
private readonly _metatype: Type<any>,
@@ -114,6 +115,17 @@ export class Module {
return this._metatype;
}
get distance(): number {
return this._distance;
}
set distance(distance: number){
this._distance = distance;
Array.from(this._imports)
.filter((module) => !module.imports.has(this))
.forEach((module) => module.distance = distance + 1);
}
public addCoreProviders(container: NestContainer) {
this.addModuleAsProvider();
this.addModuleRef();
@@ -398,8 +410,9 @@ export class Module {
);
}
public addRelatedModule(module: any) {
public addRelatedModule(module: Module) {
this._imports.add(module);
module.distance = this._distance + 1 > module._distance ? this._distance + 1 : module._distance;
}
public replace(toReplace: string | symbol | Type<any>, options: any) {