UNPKG

@nestjs/core

Version:

The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.

24 lines (23 loc) • 921 B
import { getClassRef } from './class-ref-registry.js'; export const HANDLER_METADATA_SYMBOL = Symbol.for('handler_metadata:cache'); export class HandlerMetadataStorage { // Keyed by class: same-named classes must not share an entry, and neither // must classes that a mixin helper gave the same `constructor`. [HANDLER_METADATA_SYMBOL] = new WeakMap(); set(controller, methodName, metadata) { const ctor = getClassRef(controller); if (!ctor) { return; } let handlers = this[HANDLER_METADATA_SYMBOL].get(ctor); if (!handlers) { handlers = new Map(); this[HANDLER_METADATA_SYMBOL].set(ctor, handlers); } handlers.set(methodName, metadata); } get(controller, methodName) { const handlers = this[HANDLER_METADATA_SYMBOL].get(getClassRef(controller)); return handlers?.get(methodName); } }