import { newRawValue } from "./history" ; import { getDateString } from "../../tools/date" ; import { getAllEntries as getAllFormatAEntries , getAllGroups as getAllFormatAGroups } from "../formatA/tools" ; import { FormatAEntry , FormatAGroup , FormatAVault , FormatBEntry , FormatBGroup , FormatBKeyValueObject , FormatBVault , PropertyKeyValueObject } from "../../types" ; export function convertFormatAEntry ( entry ) { return { id : entry . id , a : flatKeyValueObjectToValuesObject ( entry . attributes || { } ) , p : flatKeyValueObjectToValuesObject ( entry . properties || { } ) , g : entry . parentID } ; } export function convertFormatAGroup ( group ) { return { id : group . id , a : flatKeyValueObjectToValuesObject ( group . attributes || { } ) , t : group . title , g : group . parentID } ; } export function convertFormatAVault ( vault ) { return { id : vault . id , a : flatKeyValueObjectToValuesObject ( vault . attributes || { } ) , g : getAllFormatAGroups ( vault ) . map ( group => convertFormatAGroup ( group ) ) , e : getAllFormatAEntries ( vault ) . map ( entry => convertFormatAEntry ( entry ) ) , c : getDateString ( ) } ; } function flatKeyValueObjectToValuesObject ( obj ) { return Object . keys ( obj ) . reduce ( ( output , key ) => Object . assign ( output , { [ key ] : newRawValue ( obj [ key ] ) } ) , { } ) ; } export function isFormatBEntry ( entry ) { return ( < FormatBEntry > entry ) . g !== undefined ; } export function isFormatBGroup ( group ) { return ( < FormatBGroup > group ) . g !== undefined ; } param valuesObj export function valuesObjectToKeyValueObject ( valuesObj ) { return Object . keys ( valuesObj ) . reduce ( ( output , key ) => { if ( valuesObj [ key ] . deleted ) return output ; return Object . assign ( output , { [ key ] : valuesObj [ key ] . value } ) ; } , { } ) ; }