@nestjs/core
Advanced tools
Comparing version 4.1.7 to 4.1.8
import { PipeTransform, WebSocketAdapter, ExceptionFilter, NestInterceptor, CanActivate } from '@nestjs/common'; | ||
import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface'; | ||
export declare class ApplicationConfig implements ConfigurationProvider { | ||
private ioAdapter; | ||
private globalPipes; | ||
@@ -8,4 +9,4 @@ private globalFilters; | ||
private globalGuards; | ||
private ioAdapter; | ||
private globalPrefix; | ||
constructor(ioAdapter?: WebSocketAdapter | null); | ||
setGlobalPrefix(prefix: string): void; | ||
@@ -12,0 +13,0 @@ getGlobalPrefix(): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const optional = require("optional"); | ||
const { IoAdapter } = optional('@nestjs/websockets/adapters/io-adapter') || {}; | ||
class ApplicationConfig { | ||
constructor() { | ||
constructor(ioAdapter = null) { | ||
this.ioAdapter = ioAdapter; | ||
this.globalPipes = []; | ||
@@ -11,3 +10,2 @@ this.globalFilters = []; | ||
this.globalGuards = []; | ||
this.ioAdapter = IoAdapter ? new IoAdapter() : null; | ||
this.globalPrefix = ''; | ||
@@ -14,0 +12,0 @@ } |
export declare const ModuleInitMessage: (module: string) => string; | ||
export declare const RouteMappedMessage: (path: string, method: any) => string; | ||
export declare const ControllerMappingMessage: (name: string) => string; | ||
export declare const ControllerMappingMessage: (name: string, path: string) => string; |
@@ -6,2 +6,2 @@ "use strict"; | ||
exports.RouteMappedMessage = (path, method) => `Mapped {${path}, ${request_method_enum_1.RequestMethod[method]}} route`; | ||
exports.ControllerMappingMessage = (name) => `${name}:`; | ||
exports.ControllerMappingMessage = (name, path) => `${name} {${path}}:`; |
@@ -12,3 +12,3 @@ import 'reflect-metadata'; | ||
loadInstanceOfInjectable(wrapper: InstanceWrapper<Controller>, module: Module): Promise<void>; | ||
loadPrototypeOfInstance<T>({metatype, name}: InstanceWrapper<T>, collection: Map<string, InstanceWrapper<T>>): void; | ||
loadPrototypeOfInstance<T>({metatype, name}: InstanceWrapper<T>, collection: Map<string, InstanceWrapper<T>>): any; | ||
loadInstanceOfComponent(wrapper: InstanceWrapper<Injectable>, module: Module, context?: Module[]): Promise<void>; | ||
@@ -15,0 +15,0 @@ applyDoneSubject<T>(wrapper: InstanceWrapper<T>): () => void; |
@@ -46,6 +46,6 @@ "use strict"; | ||
if (!collection) | ||
return; | ||
return null; | ||
const target = collection.get(name); | ||
if (target.isResolved || !shared_utils_1.isNil(target.inject)) | ||
return; | ||
return null; | ||
collection.set(name, Object.assign({}, collection.get(name), { instance: Object.create(metatype.prototype) })); | ||
@@ -77,3 +77,3 @@ } | ||
if (currentMetatype.isResolved) | ||
return; | ||
return null; | ||
yield this.resolveConstructorParams(wrapper, module, inject, context, (instances) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -80,0 +80,0 @@ if (shared_utils_1.isNil(inject)) { |
@@ -8,8 +8,8 @@ import { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, WebSocketAdapter } from '@nestjs/common'; | ||
private readonly express; | ||
private readonly config; | ||
private readonly logger; | ||
private readonly httpServer; | ||
private readonly routesResolver; | ||
private readonly config; | ||
private readonly microservices; | ||
private isInitialized; | ||
private server; | ||
constructor(container: NestContainer, express: any); | ||
@@ -16,0 +16,0 @@ setupModules(): Promise<void>; |
@@ -11,2 +11,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const http = require("http"); | ||
const optional = require("optional"); | ||
@@ -25,2 +26,3 @@ const iterare_1 = require("iterare"); | ||
const { NestMicroservice } = optional('@nestjs/microservices/nest-microservice') || {}; | ||
const { IoAdapter } = optional('@nestjs/websockets/adapters/io-adapter'); | ||
class NestApplication { | ||
@@ -30,8 +32,10 @@ constructor(container, express) { | ||
this.express = express; | ||
this.config = new application_config_1.ApplicationConfig(); | ||
this.logger = new logger_service_1.Logger(NestApplication.name, true); | ||
this.httpServer = null; | ||
this.routesResolver = null; | ||
this.microservices = []; | ||
this.isInitialized = false; | ||
this.server = null; | ||
this.httpServer = http.createServer(express); | ||
const ioAdapter = IoAdapter ? new IoAdapter(this.httpServer) : null; | ||
this.config = new application_config_1.ApplicationConfig(ioAdapter); | ||
this.routesResolver = new routes_resolver_1.RoutesResolver(container, express_adapter_1.ExpressAdapter, this.config); | ||
@@ -92,4 +96,4 @@ } | ||
(!this.isInitialized) && (yield this.init()); | ||
this.server = this.express.listen(port, ...args); | ||
return this.server; | ||
this.httpServer.listen(port, ...args); | ||
return this.httpServer; | ||
}); | ||
@@ -104,3 +108,3 @@ } | ||
SocketModule && SocketModule.close(); | ||
this.server && this.server.close(); | ||
this.httpServer && this.httpServer.close(); | ||
this.microservices.forEach((microservice) => { | ||
@@ -107,0 +111,0 @@ microservice.setIsTerminated(true); |
{ | ||
"name": "@nestjs/core", | ||
"version": "4.1.7", | ||
"version": "4.1.8", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@core)", | ||
@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec", |
@@ -5,2 +5,3 @@ import { Controller } from '@nestjs/common/interfaces/index'; | ||
explore(instance: Controller, metatype: Metatype<Controller>, module: string): any; | ||
fetchRouterPath(metatype: Metatype<Controller>): string; | ||
} |
@@ -30,6 +30,6 @@ import 'reflect-metadata'; | ||
constructor(paramsFactory: IRouteParamsFactory, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer); | ||
create(instance: Controller, callback: (...args) => any, module: string, requestMethod: RequestMethod): (req: any, res: any, next: any) => Promise<any>; | ||
create(instance: Controller, callback: (...args) => any, methodName: string, module: string, requestMethod: RequestMethod): (req: any, res: any, next: any) => Promise<any>; | ||
mapParamType(key: string): RouteParamtypes; | ||
reflectCallbackMetadata(instance: Controller, callback: (...args) => any): RouteParamsMetadata; | ||
reflectCallbackParamtypes(instance: Controller, callback: (...args) => any): any[]; | ||
reflectCallbackMetadata(instance: Controller, methodName: string): RouteParamsMetadata; | ||
reflectCallbackParamtypes(instance: Controller, methodName: string): any[]; | ||
reflectHttpStatusCode(callback: (...args) => any): number; | ||
@@ -36,0 +36,0 @@ getArgumentsLength(keys: string[], metadata: RouteParamsMetadata): number; |
@@ -29,8 +29,8 @@ "use strict"; | ||
} | ||
create(instance, callback, module, requestMethod) { | ||
const metadata = this.reflectCallbackMetadata(instance, callback) || {}; | ||
create(instance, callback, methodName, module, requestMethod) { | ||
const metadata = this.reflectCallbackMetadata(instance, methodName) || {}; | ||
const keys = Object.keys(metadata); | ||
const argsLength = this.getArgumentsLength(keys, metadata); | ||
const pipes = this.pipesContextCreator.create(instance, callback); | ||
const paramtypes = this.reflectCallbackParamtypes(instance, callback); | ||
const paramtypes = this.reflectCallbackParamtypes(instance, methodName); | ||
const guards = this.guardsContextCreator.create(instance, callback, module); | ||
@@ -64,7 +64,7 @@ const interceptors = this.interceptorsContextCreator.create(instance, callback, module); | ||
} | ||
reflectCallbackMetadata(instance, callback) { | ||
return Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, instance, callback.name); | ||
reflectCallbackMetadata(instance, methodName) { | ||
return Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, instance, methodName); | ||
} | ||
reflectCallbackParamtypes(instance, callback) { | ||
return Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, callback.name); | ||
reflectCallbackParamtypes(instance, methodName) { | ||
return Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, methodName); | ||
} | ||
@@ -71,0 +71,0 @@ reflectHttpStatusCode(callback) { |
@@ -22,6 +22,5 @@ import 'reflect-metadata'; | ||
constructor(metadataScanner?: MetadataScanner, routerProxy?: RouterProxy, expressAdapter?: ExpressAdapter, exceptionsFilter?: ExceptionsFilter, config?: ApplicationConfig, container?: NestContainer); | ||
explore(instance: Controller, metatype: Metatype<Controller>, module: string): { | ||
path: string; | ||
router: any; | ||
}; | ||
explore(instance: Controller, metatype: Metatype<Controller>, module: string): any; | ||
fetchRouterPath(metatype: Metatype<Controller>): string; | ||
validateRoutePath(path: string): string; | ||
scanForPaths(instance: Controller, prototype?: any): RoutePathProperties[]; | ||
@@ -31,5 +30,3 @@ exploreMethodMetadata(instance: Controller, instancePrototype: any, methodName: string): RoutePathProperties; | ||
private applyCallbackToRouter(router, pathProperties, instance, module); | ||
private createCallbackProxy(instance, callback, module, requestMethod); | ||
private fetchRouterPath(metatype); | ||
private validateRoutePath(path); | ||
private createCallbackProxy(instance, callback, methodName, module, requestMethod); | ||
} | ||
@@ -40,2 +37,3 @@ export interface RoutePathProperties { | ||
targetCallback: RouterProxyCallback; | ||
methodName: string; | ||
} |
@@ -31,7 +31,16 @@ "use strict"; | ||
const router = this.expressAdapter.createRouter(); | ||
const path = this.fetchRouterPath(metatype); | ||
const routerPaths = this.scanForPaths(instance); | ||
this.applyPathsToRouterProxy(router, routerPaths, instance, module); | ||
return { path, router }; | ||
return router; | ||
} | ||
fetchRouterPath(metatype) { | ||
const path = Reflect.getMetadata(constants_1.PATH_METADATA, metatype); | ||
return this.validateRoutePath(path); | ||
} | ||
validateRoutePath(path) { | ||
if (shared_utils_1.isUndefined(path)) { | ||
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException(); | ||
} | ||
return shared_utils_1.validatePath(path); | ||
} | ||
scanForPaths(instance, prototype) { | ||
@@ -49,5 +58,6 @@ const instancePrototype = shared_utils_1.isUndefined(prototype) ? Object.getPrototypeOf(instance) : prototype; | ||
return { | ||
path: this.validateRoutePath(routePath), | ||
requestMethod, | ||
targetCallback, | ||
requestMethod, | ||
path: this.validateRoutePath(routePath), | ||
methodName, | ||
}; | ||
@@ -63,23 +73,13 @@ } | ||
applyCallbackToRouter(router, pathProperties, instance, module) { | ||
const { path, requestMethod, targetCallback } = pathProperties; | ||
const { path, requestMethod, targetCallback, methodName } = pathProperties; | ||
const routerMethod = this.routerMethodFactory.get(router, requestMethod).bind(router); | ||
const proxy = this.createCallbackProxy(instance, targetCallback, module, requestMethod); | ||
const proxy = this.createCallbackProxy(instance, targetCallback, methodName, module, requestMethod); | ||
routerMethod(path, proxy); | ||
} | ||
createCallbackProxy(instance, callback, module, requestMethod) { | ||
const executionContext = this.executionContextCreator.create(instance, callback, module, requestMethod); | ||
createCallbackProxy(instance, callback, methodName, module, requestMethod) { | ||
const executionContext = this.executionContextCreator.create(instance, callback, methodName, module, requestMethod); | ||
const exceptionFilter = this.exceptionsFilter.create(instance, callback); | ||
return this.routerProxy.createProxy(executionContext, exceptionFilter); | ||
} | ||
fetchRouterPath(metatype) { | ||
const path = Reflect.getMetadata(constants_1.PATH_METADATA, metatype); | ||
return this.validateRoutePath(path); | ||
} | ||
validateRoutePath(path) { | ||
if (shared_utils_1.isUndefined(path)) { | ||
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException(); | ||
} | ||
return shared_utils_1.validatePath(path); | ||
} | ||
} | ||
exports.ExpressRouterExplorer = ExpressRouterExplorer; |
@@ -25,4 +25,6 @@ "use strict"; | ||
routes.forEach(({ instance, metatype }) => { | ||
this.logger.log(messages_1.ControllerMappingMessage(metatype.name)); | ||
const { path, router } = this.routerBuilder.explore(instance, metatype, moduleName); | ||
const path = this.routerBuilder.fetchRouterPath(metatype); | ||
const controllerName = metatype.name; | ||
this.logger.log(messages_1.ControllerMappingMessage(controllerName, path)); | ||
const router = this.routerBuilder.explore(instance, metatype, moduleName); | ||
express.use(path, router); | ||
@@ -29,0 +31,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
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
155471
3141
1