module import { createOptModelLogger } from '../../../logger/logger' ; import { PropertyMetadata } from '../../metadata/property-metadata.model' ; import { initOrUpdateProperty } from '../property/init-or-update-property.function' ; import { KEY_PROPERTY } from '../property/key-property.const' ; const logger = createOptModelLogger ( '@PartitionKey' ) ; export function PartitionKey ( ) { return ( target , propertyKey ) => { if ( typeof propertyKey === 'string' ) { const properties = Reflect . getMetadata ( KEY_PROPERTY , target . constructor ) || [ ] ; if ( properties && properties . length ) { const existingPartitionKeys = properties . filter ( ( property ) => property . key && property . key . type === 'HASH' ) ; if ( existingPartitionKeys . length ) { if ( properties . find ( ( property ) => property . name === propertyKey ) ) { logger . warn ( `this is the second execution to define the partitionKey for property ${ propertyKey }` , target . constructor ) ; } else { throw new Error ( 'only one partition key is allowed per model, if you want to define key for indexes use one of these decorators: ' + '@GSIPartitionKey,  @GSISortKey or @LSISortKey' ) ; } } } initOrUpdateProperty ( { key : { type : 'HASH' } } , target , propertyKey ) ; } } ; }