type DocumentStoreEntry = { connections : Set < any > ; } ; const documents = { } ; export const addUpdate = ( documentId , update , connection ) => { documents [ documentId ] ?. connections ?. forEach ( ( conn ) => { if ( connection !== conn ) { conn . send ( JSON . stringify ( update ) ) ; } } ) ; } ; export const addConnection = ( documentId , connection ) => { if ( documents [ documentId ] ) { documents [ documentId ] . connections . add ( connection ) ; } else { documents [ documentId ] = { connections : new Set < any > ( ) , } ; documents [ documentId ] . connections . add ( connection ) ; } } ; export const removeConnection = ( documentId , connection ) => { if ( documents [ documentId ] ) { documents [ documentId ] . connections . delete ( connection ) ; } } ;