author Jeremy Daly <jeremy@jeremydaly.com>
 *  license import validateTypes from './validateTypes' ; import { error , transformAttr } from './utils' ; import { DocumentClient } from 'aws-sdk/clients/dynamodb' ; export default ( DocumentClient ) => ( data , schema , partitionKey , sortKey ) => { partitionKey = schema [ partitionKey ] . map || partitionKey ; sortKey = ( schema [ sortKey ] && schema [ sortKey ] . map ) || sortKey || null ; let validateType = validateTypes ( DocumentClient ) ; let pk = data [ partitionKey ] ; if ( pk === undefined || pk === null || pk === '' ) { error ( `'${ partitionKey }'${ schema [ partitionKey ] . alias ? ` or '${ schema [ partitionKey ] . alias }'` : '' } is required` ) ; } const sk = data [ sortKey ] ; if ( sortKey && ( sk === undefined || sk === null || sk === '' ) ) { error ( `'${ sortKey }'${ schema [ sortKey ] . alias ? ` or '${ schema [ sortKey ] . alias }'` : '' } is required` ) ; } return Object . assign ( { [ partitionKey ] : transformAttr ( schema [ partitionKey ] , validateType ( schema [ partitionKey ] , partitionKey , pk ) , data ) } , sortKey !== null ? { [ sortKey ] : transformAttr ( schema [ sortKey ] , validateType ( schema [ sortKey ] , sortKey , sk ) , data ) } : { } ) ; } ;