@nestjs/core
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -46,5 +46,8 @@ "use strict"; | ||
getGlobalMetadata() { | ||
return []; | ||
if (!this.config) { | ||
return []; | ||
} | ||
return this.config.getGlobalGuards(); | ||
} | ||
} | ||
exports.GuardsContextCreator = GuardsContextCreator; |
@@ -57,3 +57,8 @@ import { InstanceWrapper } from './container'; | ||
replace(toReplace: any, options: any): void; | ||
private getModuleRefMetatype(components); | ||
createModuleRefMetatype(components: any): { | ||
new (): { | ||
readonly components: any; | ||
get<T>(type: OpaqueToken): T; | ||
}; | ||
}; | ||
} |
@@ -52,3 +52,3 @@ "use strict"; | ||
addModuleRef() { | ||
const moduleRef = this.getModuleRefMetatype(this._components); | ||
const moduleRef = this.createModuleRefMetatype(this._components); | ||
this._components.set(module_ref_1.ModuleRef.name, { | ||
@@ -180,3 +180,3 @@ name: module_ref_1.ModuleRef.name, | ||
} | ||
getModuleRefMetatype(components) { | ||
createModuleRefMetatype(components) { | ||
return class { | ||
@@ -183,0 +183,0 @@ constructor() { |
import { Controller } from '@nestjs/common/interfaces'; | ||
import { ExecutionContext, NestInterceptor } from '@nestjs/common'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/toPromise'; | ||
@@ -9,2 +10,3 @@ import 'rxjs/add/observable/defer'; | ||
createContext(instance: Controller, callback: (...args) => any): ExecutionContext; | ||
transformDeffered(next: () => any): Promise<any> | Observable<any>; | ||
} |
@@ -23,7 +23,3 @@ "use strict"; | ||
const context = this.createContext(instance, callback); | ||
const start$ = Observable_1.Observable.defer(() => { | ||
const res = next(); | ||
const isDeffered = res instanceof Promise || res instanceof Observable_1.Observable; | ||
return isDeffered ? res : Promise.resolve(res); | ||
}); | ||
const start$ = Observable_1.Observable.defer(() => this.transformDeffered(next)); | ||
const result$ = yield interceptors.reduce((stream$, interceptor) => __awaiter(this, void 0, void 0, function* () { return yield interceptor.intercept(dataOrRequest, context, yield stream$); }), Promise.resolve(start$)); | ||
@@ -39,3 +35,8 @@ return yield result$.toPromise(); | ||
} | ||
transformDeffered(next) { | ||
const res = next(); | ||
const isDeffered = res instanceof Promise || res instanceof Observable_1.Observable; | ||
return isDeffered ? res : Promise.resolve(res); | ||
} | ||
} | ||
exports.InterceptorsConsumer = InterceptorsConsumer; |
@@ -22,4 +22,5 @@ import { NestContainer } from './injector/container'; | ||
use(requestHandler: any): void; | ||
listen(port: number, callback?: () => void): Promise<any>; | ||
listenAsync(port: number): Promise<any>; | ||
listen(port: number, callback?: () => void): any; | ||
listen(port: number, hostname: string, callback?: () => void): any; | ||
listenAsync(port: number, hostname?: string): Promise<any>; | ||
close(): void; | ||
@@ -26,0 +27,0 @@ setGlobalPrefix(prefix: string): void; |
@@ -73,12 +73,12 @@ "use strict"; | ||
} | ||
listen(port, callback) { | ||
listen(port, ...args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(!this.isInitialized) && (yield this.init()); | ||
this.server = this.express.listen(port, callback); | ||
this.server = this.express.listen(port, ...args); | ||
return this.server; | ||
}); | ||
} | ||
listenAsync(port) { | ||
listenAsync(port, hostname) { | ||
return new Promise((resolve) => { | ||
const server = this.listen(port, () => resolve(server)); | ||
const server = this.listen(port, hostname, () => resolve(server)); | ||
}); | ||
@@ -85,0 +85,0 @@ } |
{ | ||
"name": "@nestjs/core", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@core)", | ||
@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec", |
import 'reflect-metadata'; | ||
import { NestContainer } from './injector/container'; | ||
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface'; | ||
import { Injectable } from '@nestjs/common/interfaces/injectable.interface'; | ||
import { NestModuleMetatype } from '@nestjs/common/interfaces/modules/module-metatype.interface'; | ||
import { Metatype } from '@nestjs/common/interfaces/metatype.interface'; | ||
import { MetadataScanner } from '../core/metadata-scanner'; | ||
@@ -10,20 +13,21 @@ export declare class DependenciesScanner { | ||
scan(module: NestModuleMetatype): void; | ||
private scanForModules(module, scope?); | ||
private storeModule(module, scope); | ||
private scanModulesForDependencies(); | ||
private reflectRelatedModules(module, token); | ||
private reflectComponents(module, token); | ||
private reflectComponentMetadata(component, token); | ||
private reflectControllers(module, token); | ||
private reflectDynamicMetadata(obj, token); | ||
private reflectExports(module, token); | ||
private reflectGatewaysMiddlewares(component, token); | ||
private reflectGuards(component, token); | ||
private reflectInterceptors(component, token); | ||
private storeRelatedModule(related, token); | ||
private storeComponent(component, token); | ||
private storeInjectable(component, token); | ||
private storeExportedComponent(exportedComponent, token); | ||
private storeRoute(route, token); | ||
private reflectMetadata(metatype, metadata); | ||
scanForModules(module: NestModuleMetatype, scope?: NestModuleMetatype[]): void; | ||
storeModule(module: NestModuleMetatype, scope: NestModuleMetatype[]): void; | ||
scanModulesForDependencies(): void; | ||
reflectRelatedModules(module: NestModuleMetatype, token: string): void; | ||
reflectComponents(module: NestModuleMetatype, token: string): void; | ||
reflectComponentMetadata(component: Metatype<Injectable>, token: string): void; | ||
reflectControllers(module: NestModuleMetatype, token: string): void; | ||
reflectDynamicMetadata(obj: Metatype<Injectable>, token: string): void; | ||
reflectExports(module: NestModuleMetatype, token: string): void; | ||
reflectGatewaysMiddlewares(component: Metatype<Injectable>, token: string): void; | ||
reflectGuards(component: Metatype<Injectable>, token: string): void; | ||
reflectInterceptors(component: Metatype<Injectable>, token: string): void; | ||
reflectKeyMetadata(component: Metatype<Injectable>, key: string, method: string): any; | ||
storeRelatedModule(related: NestModuleMetatype, token: string): void; | ||
storeComponent(component: Metatype<Injectable>, token: string): void; | ||
storeInjectable(component: Metatype<Injectable>, token: string): void; | ||
storeExportedComponent(exportedComponent: Metatype<Injectable>, token: string): void; | ||
storeRoute(route: Metatype<Controller>, token: string): void; | ||
reflectMetadata(metatype: any, metadata: string): any; | ||
} |
@@ -73,6 +73,3 @@ "use strict"; | ||
const controllerGuards = this.reflectMetadata(component, constants_1.GUARDS_METADATA); | ||
const methodsGuards = this.metadataScanner.scanFromPrototype(null, component.prototype, (method) => { | ||
const descriptor = Reflect.getOwnPropertyDescriptor(component.prototype, method); | ||
return descriptor ? Reflect.getMetadata(constants_1.GUARDS_METADATA, descriptor.value) : undefined; | ||
}); | ||
const methodsGuards = this.metadataScanner.scanFromPrototype(null, component.prototype, this.reflectKeyMetadata.bind(this, component, constants_1.GUARDS_METADATA)); | ||
const flattenMethodsGuards = methodsGuards.reduce((a, b) => a.concat(b), []); | ||
@@ -83,9 +80,10 @@ [...controllerGuards, ...flattenMethodsGuards].map((guard) => this.storeInjectable(guard, token)); | ||
const controllerInterceptors = this.reflectMetadata(component, constants_1.INTERCEPTORS_METADATA); | ||
const methodsInterceptors = this.metadataScanner.scanFromPrototype(null, component.prototype, (method) => { | ||
const descriptor = Reflect.getOwnPropertyDescriptor(component.prototype, method); | ||
return descriptor ? Reflect.getMetadata(constants_1.INTERCEPTORS_METADATA, descriptor.value) : undefined; | ||
}); | ||
const methodsInterceptors = this.metadataScanner.scanFromPrototype(null, component.prototype, this.reflectKeyMetadata.bind(this, component, constants_1.INTERCEPTORS_METADATA)); | ||
const flattenMethodsInterceptors = methodsInterceptors.reduce((a, b) => a.concat(b), []); | ||
[...controllerInterceptors, ...flattenMethodsInterceptors].map((guard) => this.storeInjectable(guard, token)); | ||
} | ||
reflectKeyMetadata(component, key, method) { | ||
const descriptor = Reflect.getOwnPropertyDescriptor(component.prototype, method); | ||
return descriptor ? Reflect.getMetadata(key, descriptor.value) : undefined; | ||
} | ||
storeRelatedModule(related, token) { | ||
@@ -92,0 +90,0 @@ this.container.addRelatedModule(related, token); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161805
3329