UNPKG

@opra/common

Version:
20 lines (19 loc) 860 B
import { WS_PARAM_METADATA } from '../constants.js'; export function WsParam(type, options) { return (target, propertyKey, parameterIndex) => { if (typeof propertyKey !== 'string') throw new TypeError(`Un-named properties can not be decorated`); if (!type) { const designTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey); type = designTypes[parameterIndex]; if (!type) throw new TypeError(`Missing parameter type`); } let paramMetadata = Reflect.getOwnMetadata(WS_PARAM_METADATA, target, propertyKey); if (!paramMetadata) { paramMetadata = []; Reflect.defineMetadata(WS_PARAM_METADATA, paramMetadata, target, propertyKey); } paramMetadata.push({ ...options, type, parameterIndex }); }; }