import { IsCompositePrimaryKey , PrimaryKey } from '@typedorm/common' ; import { DynamoEntitySchemaPrimaryKey } from '../classes/metadata/entity-metadata' ; import { getInterpolatedKeys } from './get-interpolated-keys' ; const IsRawPrimaryKey = ( key ) : key is PrimaryKey => { return ! ! ( key as PrimaryKey ) . partitionKey ; } ; export function isUsedForPrimaryKey ( primaryKey , attributeName ) { let primaryKeyInterpolations = [ ] as string [ ] ; if ( IsRawPrimaryKey ( primaryKey ) ) { primaryKeyInterpolations = [ ... primaryKeyInterpolations , ... getInterpolatedKeys ( primaryKey . partitionKey ) , ] ; if ( IsCompositePrimaryKey ( primaryKey ) ) { primaryKeyInterpolations = [ ... primaryKeyInterpolations , ... getInterpolatedKeys ( primaryKey . sortKey ) , ] ; } } else { const interpolationsToFlatten = primaryKey . metadata . _interpolations ?? { } ; primaryKeyInterpolations = [ ... primaryKeyInterpolations , ... Object . keys ( interpolationsToFlatten ) . flatMap ( key => { const currInterpolation = interpolationsToFlatten [ key ] ; return currInterpolation ; } ) , ] ; } return primaryKeyInterpolations . includes ( attributeName ) ; }