import { fromByteArray , toByteArray } from 'base64-js' ; import { applyUpdate , Doc , Map as YMap } from 'yjs' ; export function getUpdates ( func , doc = new Doc ( ) ) { const bots = doc . getMap ( 'bots' ) as YMap < YMap < any > > ; let update ; doc . on ( 'update' , ( u ) => { update = u ; } ) ; doc . transact ( ( ) => { func ( doc , bots ) ; } ) ; return [ fromByteArray ( update ) ] ; } export function createDocFromUpdates ( messageUpdates ) { const doc = new Doc ( ) ; for ( let update of messageUpdates ) { applyUpdate ( doc , toByteArray ( update ) ) ; } return doc ; }