text: 'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.providers=void 0;var _messenger=require('@aragon/messenger'),_messenger2=_interopRequireDefault(_messenger),_defer=require('rxjs/observable/defer'),_empty=require('rxjs/observable/empty'),_fromPromise=require('rxjs/observable/fromPromise'),_merge=require('rxjs/observable/merge');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const AppProxyHandler={get(target,name){return name in target?target[name]:function(...params){return target.rpc.sendAndObserveResponse('intent',[name,...params]).pluck('result')}}};class AppProxy{constructor(provider){this.rpc=new _messenger2.default(provider)}accounts(){return this.rpc.sendAndObserveResponses('accounts').pluck('result')}identify(identifier){this.rpc.send('identify',[identifier])}events(){return(0,_defer.defer)(()=>this.rpc.sendAndObserveResponses('events').pluck('result'))}external(address,jsonInterface){const contract={events:(fromBlock=0)=>(0,_defer.defer)(()=>this.rpc.sendAndObserveResponses('external_events',[address,jsonInterface.filter(item=>'event'===item.type),fromBlock]).pluck('result'))},callMethods=jsonInterface.filter(item=>'function'===item.type&&item.constant);return callMethods.forEach(methodJsonInterface=>{contract[methodJsonInterface.name]=(...params)=>this.rpc.sendAndObserveResponse('external_call',[address,methodJsonInterface,...params]).pluck('result')}),contract}cache(key,value){return this.rpc.send('cache',['set',key,value]),value}state(){return this.rpc.sendAndObserveResponses('cache',['get','state']).pluck('result')}store(reducer,events=[(0,_empty.empty)()]){const initialState=this.state().first(),wrappedReducer=(state,event)=>(0,_fromPromise.fromPromise)(Promise.resolve(reducer(state,event))),store$=initialState.switchMap(initialState=>(0,_merge.merge)(this.events(),...events).mergeScan(wrappedReducer,initialState,1).map(state=>this.cache('state',state))).publishReplay(1);return store$.connect(),store$}call(method,...params){return this.rpc.sendAndObserveResponse('call',[method,...params]).pluck('result')}notify(title,body,context={},date=new Date){return this.rpc.send('notification',[title,body,context,date])}context(){return this.rpc.requests().filter(request=>'context'===request.method).map(request=>request.params[0])}describeScript(script){return this.rpc.sendAndObserveResponse('describe_script',[script]).pluck('result')}}class AragonApp{constructor(provider=new _messenger.providers.MessagePortMessage){return new Proxy(new AppProxy(provider),AppProxyHandler)}}exports.default=AragonApp,exports.providers=_messenger.providers;