UNPKG

@nestjs/common

Version:

Decorators, pipes, exceptions and utilities for NestJS applications: @Controller(), @Injectable(), @Body(), ValidationPipe, HttpException and more.

21 lines (20 loc) • 1.06 kB
export function extendArrayMetadata(key, metadata, target) { const previousValue = Reflect.getMetadata(key, target) || []; const value = [...previousValue, ...metadata]; Reflect.defineMetadata(key, value, target); } /** * Reads the args a param decorator at `index` adds to. An overriding method * starts from its parent's args, so the entry inherited at `index` is left out * and the override's decorator replaces it. * * @internal */ export function getParamArgsMetadata(metadataKey, target, key, index) { const args = Reflect.getMetadata(metadataKey, target.constructor, key) || {}; const inherited = Reflect.getMetadata(metadataKey, Object.getPrototypeOf(target.constructor), key) || {}; // `assignMetadata` and `assignCustomParameterMetadata` spread shallowly, so // an entry the override inherited keeps the parent's reference. If they ever // clone entries, this check stops filtering. return Object.fromEntries(Object.entries(args).filter(([argKey, arg]) => arg.index !== index || arg !== inherited[argKey])); }