import * as i from './interfaces' ; import { isString } from '../strings' ; import { isNumber } from '../numbers' ; export function defineEntityProperties ( entity ) { Object . defineProperty ( entity , i . __IS_DATAENTITY_KEY , { value : true , configurable : false , enumerable : false , writable : false , } ) ; Object . defineProperty ( entity , i . __ENTITY_METADATA_KEY , { value : { } , configurable : false , enumerable : false , writable : false , } ) ; } export function createMetadata < M > ( metadata ) { return { ... createCoreMetadata ( ) , ... metadata } as i . _DataEntityMetadata < M > ; } export function makeMetadata < M extends i . _DataEntityMetadataType > ( metadata ? ) { if ( ! metadata ) return createCoreMetadata ( ) ; return createMetadata ( metadata ) ; } export function createCoreMetadata < M extends i . _DataEntityMetadataType > ( ) { return { _createTime : Date . now ( ) } as i . _DataEntityMetadata < M > ; } export function jsonToBuffer ( input ) { return Buffer . from ( JSON . stringify ( input ) ) ; } export function isValidKey ( key ) { if ( key == null ) return false ; if ( isString ( key ) && key !== '' ) return true ; if ( isNumber ( key ) ) return true ; return false ; } export function isDataEntity ( input ) { return Boolean ( input != null && ( input as any ) [ i . __IS_DATAENTITY_KEY ] === true ) ; }