import { Type } from '@nestjs/common' ; import { identity } from 'lodash' ; import { METADATA_FACTORY_NAME } from '../plugin/plugin-constants' ; export function clonePluginMetadataFactory ( target , parent , transformFn = identity ) { let targetMetadata = { } ; do { if ( ! parent . constructor ) { return ; } if ( ! parent . constructor [ METADATA_FACTORY_NAME ] ) { continue ; } const parentMetadata = parent . constructor [ METADATA_FACTORY_NAME ] ( ) ; targetMetadata = { ... parentMetadata , ... targetMetadata } ; } while ( ( parent = Reflect . getPrototypeOf ( parent ) as Type < any > ) && parent !== Object . prototype && parent ) ; targetMetadata = transformFn ( targetMetadata ) ; if ( target [ METADATA_FACTORY_NAME ] ) { const originalFactory = target [ METADATA_FACTORY_NAME ] ; target [ METADATA_FACTORY_NAME ] = ( ) => { const originalMetadata = originalFactory ( ) ; return { ... originalMetadata , ... targetMetadata } ; } ; } else { target [ METADATA_FACTORY_NAME ] = ( ) => targetMetadata ; } }