import { Base64 } from 'js-base64' ; import { NODE_TYPES } from 'common/enums' ; import { UserInputError } from 'common/errors' ; export const toGlobalId = ( { type , id , } ) => Base64 . encodeURI ( `${ type }:${ id }` ) ; export const fromGlobalId = ( globalId ) => { const [ type , id ] = Base64 . decode ( globalId ) . split ( ':' ) ; if ( ! id ) { throw new UserInputError ( 'invalid globalId' ) ; } return { type : type as NODE_TYPES , id } ; } ;