UNPKG

@micro.ts/core

Version:

Microservice framework with Typescript

41 lines (40 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHandlerMetadata = exports.printMetadata = exports.getGlobalMetadata = void 0; const metadata = { // Filled after the controller decorators are executed controllers: new Map(), // Used to keep all method decorators, reused after every controller decorator executed methods: new Map(), // USed to keep all parameter decorators, reused after every execution of method decorators parameters: new Map(), }; /** * Get the global metadata object */ function getGlobalMetadata() { return metadata; } exports.getGlobalMetadata = getGlobalMetadata; function printMetadata() { console.dir(metadata, { depth: null }); } exports.printMetadata = printMetadata; /** * Return metadata for the method and the controller that contains it * @param ctor Controller constructor passed as a value * @param methodName Name of the method */ function getHandlerMetadata(ctor, methodName) { let ctorMetadata = metadata.controllers.get(ctor); if (!ctorMetadata) { const methodDesc = { name: methodName, params: [] }; const controllerOptions = {}; return { method: methodDesc, controller: controllerOptions }; } const handlers = ctorMetadata.handlers || {}; const methodDescription = handlers[methodName]; const controllerDescription = ctorMetadata.options; return { method: methodDescription, controller: controllerDescription || {} }; } exports.getHandlerMetadata = getHandlerMetadata;