author Jeremy Daly <jeremy@jeremydaly.com>
 *  license import { EntityAttributeConfig } from '../classes/Entity' ; export const validTypes = [ 'string' , 'boolean' , 'number' , 'list' , 'map' , 'binary' , 'set' ] ; export const validKeyTypes = [ 'string' , 'number' , 'binary' ] ; export const toBool = ( val ) => typeof val === 'boolean' ? val : [ 'false' , '0' , 'no' ] . includes ( String ( val ) . toLowerCase ( ) ) ? false : Boolean ( val ) ; export const hasValue = ( val ) => val !== undefined && val !== null ; export const isEmpty = ( val ) => val === undefined || ( typeof val === 'object' && Object . keys ( val ) . length === 0 ) ; export const error = ( err ) => { throw new Error ( err ) ; } ; export const typeError = ( field ) => { error ( `Invalid or missing type for '${ field }'. ` + `Valid types are '${ validTypes . slice ( 0 , - 1 ) . join ( `', '` ) }',` + ` and '${ validTypes . slice ( - 1 ) }'.` ) ; } ; export const keyTypeError = ( field ) => { error ( `Invalid or missing type for '${ field }'. ` + `Valid types for partitionKey and sortKey are 'string','number' and 'binary'` ) ; } ; export const conditonError = ( op ) => error ( `You can only supply one sortKey condition per query. Already using '${ op }'` ) ; export const transformAttr = ( mapping , value , data ) => { value = mapping . transform ? mapping . transform ( value , data ) : value ; return mapping . prefix || mapping . suffix ? `${ mapping . prefix || '' }${ value }${ mapping . suffix || '' }` : value ; } ;