import { EventEmitter2 } from "eventemitter2" ; import startsWith from "coral-common/utils/startsWith" ; import { Decorator } from "./types" ; const withEventEmitter = ( eventEmitter , enableDeprecatedEvents = false ) : Decorator => ( pym ) => { pym . onMessage ( "event" , ( raw ) => { const { eventName , value } = JSON . parse ( raw ) ; if ( ! enableDeprecatedEvents ) { if ( startsWith ( eventName as string , "mutation." ) ) { return ; } if ( startsWith ( eventName as string , "fetch." ) ) { return ; } if ( startsWith ( eventName as string , "subscription." ) ) { return ; } } eventEmitter . emit ( eventName , value ) ; } ) ; pym . onMessage ( "ready" , ( ) => { eventEmitter . emit ( "ready" ) ; } ) ; } ; export default withEventEmitter ;