@dillonkearns/elm-graphql
Version:
<img src="https://cdn.jsdelivr.net/gh/martimatix/logo-graphqelm/logo.svg" alt="dillonearns/elm-graphql logo" width="40%" align="right">
3 lines (2 loc) • 9.52 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var _newArrowCheck=_interopDefault(require("babel-runtime/helpers/newArrowCheck")),utilsComposite=require("@jumpn/utils-composite");require("phoenix");var utilsArray=require("@jumpn/utils-array"),_extends=_interopDefault(require("babel-runtime/helpers/extends")),utilsGraphql=require("@jumpn/utils-graphql"),_toConsumableArray=_interopDefault(require("babel-runtime/helpers/toConsumableArray")),_objectWithoutProperties=_interopDefault(require("babel-runtime/helpers/objectWithoutProperties")),Observable=_interopDefault(require("zen-observable")),_this$2=void 0,find=function(e,n,i){return _newArrowCheck(this,_this$2),e.find(utilsComposite.hasIn([n],i))}.bind(void 0),_this$1=void 0,createEventHandler=function(e,n){return _newArrowCheck(this,_this$1),function(i){return _newArrowCheck(this,_this$1),function(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];_newArrowCheck(this,_this$1);var s=find(e.notifiers,"request",n);s&&i.apply(void 0,[e,s].concat(t))}.bind(this)}.bind(this)}.bind(void 0),createPushHandler=function(e,n,i){return _newArrowCheck(this,_this$1),utilsComposite.map(createEventHandler(n,i),e)}.bind(void 0),_this$3=void 0,handlePush=function(e,n){return _newArrowCheck(this,_this$3),e.receive("ok",n.onSucceed).receive("error",n.onError).receive("timeout",n.onTimeout)}.bind(void 0),_this$4=void 0,getNotifier=function(e,n){return _newArrowCheck(this,_this$4),function(i){return _newArrowCheck(this,_this$4),i[e]&&i[e](n)}.bind(this)}.bind(void 0),getHandlerName=function(e){return _newArrowCheck(this,_this$4),"on"+String(e)}.bind(void 0),notify=function(e,n,i){return _newArrowCheck(this,_this$4),e.observers.forEach(getNotifier(getHandlerName(n),i))}.bind(void 0),_this$6=void 0,findIndex=function(e,n,i){return _newArrowCheck(this,_this$6),e.findIndex(utilsComposite.hasIn([n],i))}.bind(void 0),_this$5=void 0,remove$1=function(e){return _newArrowCheck(this,_this$5),function(n){return _newArrowCheck(this,_this$5),utilsArray.remove(findIndex(n,"request",e.request),1,n)}.bind(this)}.bind(void 0),_this$7=void 0,updateNotifiers=function(e,n){return _newArrowCheck(this,_this$7),e.notifiers=n(e.notifiers),e}.bind(void 0),_this=void 0,removeNotifiers=function(e,n){_newArrowCheck(this,_this),updateNotifiers(e,remove$1(n)),notify(n,"Cancel",n)}.bind(void 0),onError=function(e,n,i){_newArrowCheck(this,_this),unsubscribe(e,n),notify(n,"Error","unsubscribe: "+String(i))}.bind(void 0),onTimeout=function(e,n){return _newArrowCheck(this,_this),notify(n,"Error","unsubscribe: timeout")}.bind(void 0),notifierPushHandler={onError:onError,onTimeout:onTimeout,onSucceed:removeNotifiers},unsubscribe=function(e,n){return _newArrowCheck(this,_this),handlePush(e.channel.push("unsubscribe",{subscriptionId:n.subscriptionId}),createPushHandler(notifierPushHandler,e,n.request))}.bind(void 0),cancel=function(e,n){return _newArrowCheck(this,_this),"subscription"===n.operationType?unsubscribe(e,n):removeNotifiers(e,n),e}.bind(void 0),_this$10=void 0,notifyall=function(e,n,i){return _newArrowCheck(this,_this$10),e.forEach(function(e){return _newArrowCheck(this,_this$10),notify(e,n,i)}.bind(this))}.bind(void 0),_this$12=void 0,refresh=function(e){return _newArrowCheck(this,_this$12),function(n){return _newArrowCheck(this,_this$12),utilsArray.replace(findIndex(n,"request",e.request),[e],n)}.bind(this)}.bind(void 0),_this$11=void 0,notifyStart=function(e){return _newArrowCheck(this,_this$11),notify(e,"Start",e)}.bind(void 0),onSubscriptionSucceed=function(e,n,i){var r=i.subscriptionId;_newArrowCheck(this,_this$11);var t=_extends({},n,{subscriptionId:r});updateNotifiers(e,refresh(t)),notifyStart(t)}.bind(void 0),abortRequest=function(e,n,i){_newArrowCheck(this,_this$11),updateNotifiers(e,remove$1(n)),notify(n,"Abort",i)}.bind(void 0),onError$1=function(e,n,i){return _newArrowCheck(this,_this$11),abortRequest(e,n,new Error(i))}.bind(void 0),onSubscriptionResponse=function(e,n,i){_newArrowCheck(this,_this$11),i.errors?onError$1(e,n,utilsGraphql.errorsToString(i.errors)):onSubscriptionSucceed(e,n,i)}.bind(void 0),onQueryOrMutationResponse=function(e,n,i){_newArrowCheck(this,_this$11),updateNotifiers(e,remove$1(n)),notify(n,"Result",i)}.bind(void 0),onTimeout$1=function(e,n){return _newArrowCheck(this,_this$11),notify(n,"Error",new Error("request: timeout"))}.bind(void 0),queryOrMutationHandler={onError:onError$1,onTimeout:onTimeout$1,onSucceed:onQueryOrMutationResponse},subcriptionHandler={onError:onError$1,onTimeout:onTimeout$1,onSucceed:onSubscriptionResponse},send=function(e,n,i){return _newArrowCheck(this,_this$11),handlePush(e.channel.push("doc",utilsGraphql.requestToCompat(n)),createPushHandler(i,e,n))}.bind(void 0),pushRequest=function(e,n){_newArrowCheck(this,_this$11),"subscription"===n.operationType?send(e,n.request,subcriptionHandler):(notifyStart(n),send(e,n.request,queryOrMutationHandler))}.bind(void 0),_this$9=void 0,createChannelJoinHandler=function(e){return _newArrowCheck(this,_this$9),{onError:function(n){return _newArrowCheck(this,_this$9),notifyall(e.notifiers,"Error",new Error("channel join: "+String(n)))}.bind(this),onSucceed:function(){return _newArrowCheck(this,_this$9),e.notifiers.forEach(function(n){return _newArrowCheck(this,_this$9),pushRequest(e,n)}.bind(this))}.bind(this),onTimeout:function(){return _newArrowCheck(this,_this$9),notifyall(e.notifiers,"Error",new Error("channel join: timeout"))}.bind(this)}}.bind(void 0),joinChannel=function(e){return _newArrowCheck(this,_this$9),handlePush(e.channel.join(),createChannelJoinHandler(e)),e.channelJoinCreated=!0,e}.bind(void 0),_this$8=void 0,createConnectionCloseError=function(){return _newArrowCheck(this,_this$8),new Error("connection: close")}.bind(void 0),mutationOnConnectionClose=function(e,n){_newArrowCheck(this,_this$8),updateNotifiers(e,remove$1(n)),notify(n,"Abort",createConnectionCloseError())}.bind(void 0),notifierOnConnectionClose=function(e){return _newArrowCheck(this,_this$8),function(n){_newArrowCheck(this,_this$8),"mutation"===n.operationType?mutationOnConnectionClose(e,n):notify(n,"Error",createConnectionCloseError())}.bind(this)}.bind(void 0),onConnectionClose=function(e){return _newArrowCheck(this,_this$8),function(){return _newArrowCheck(this,_this$8),e.notifiers.forEach(notifierOnConnectionClose(e))}.bind(this)}.bind(void 0),onSubscriptionData=function(e,n){var i=n.payload;_newArrowCheck(this,_this$8);var r=find(e.notifiers,"subscriptionId",i.subscriptionId);r&¬ify(r,"Result",i.result)}.bind(void 0),onMessage=function(e){return _newArrowCheck(this,_this$8),function(n){_newArrowCheck(this,_this$8),"subscription:data"===n.event&&onSubscriptionData(e,n)}.bind(this)}.bind(void 0),shouldJoinChannel=function(e){return _newArrowCheck(this,_this$8),!e.channelJoinCreated&&e.notifiers.length>0}.bind(void 0),onConnectionOpen=function(e){return _newArrowCheck(this,_this$8),function(){_newArrowCheck(this,_this$8),shouldJoinChannel(e)&&joinChannel(e)}.bind(this)}.bind(void 0),absintheChannelName="__absinthe__:control",create=function(e){_newArrowCheck(this,_this$8);var n={phoenixSocket:e,channel:e.channel(absintheChannelName),channelJoinCreated:!1,notifiers:[]};return e.onOpen(onConnectionOpen(n)),e.onMessage(onMessage(n)),e.onClose(onConnectionClose(n)),n}.bind(void 0),_this$14=void 0,observe$2=function(e,n){_newArrowCheck(this,_this$14);var i=e.observers,r=_objectWithoutProperties(e,["observers"]);return _extends({},r,{observers:[].concat(_toConsumableArray(i),[n])})}.bind(void 0),_this$13=void 0,observe=function(e,n,i){return _newArrowCheck(this,_this$13),updateNotifiers(e,refresh(observe$2(n,i)))}.bind(void 0),_this$16=void 0,create$2=function(e){return _newArrowCheck(this,_this$16),{request:e,observers:[],operationType:utilsGraphql.getOperationType(e.operation),subscriptionId:void 0}}.bind(void 0),_this$15=void 0,connectOrJoinChannel=function(e){_newArrowCheck(this,_this$15),e.phoenixSocket.isConnected()?joinChannel(e):e.phoenixSocket.connect()}.bind(void 0),sendNew=function(e,n){_newArrowCheck(this,_this$15);var i=create$2(n);return updateNotifiers(e,utilsArray.append([i])),e.channelJoinCreated?pushRequest(e,i):connectOrJoinChannel(e),i}.bind(void 0),send$1=function(e,n){return _newArrowCheck(this,_this$15),find(e.notifiers,"request",n)||sendNew(e,n)}.bind(void 0),_this$17=void 0,onResult=function(e,n){return _newArrowCheck(this,_this$17),function(i){_newArrowCheck(this,_this$17),n.next(i),"subscription"!==e.operationType&&n.complete()}.bind(this)}.bind(void 0),toObservable=function(e,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i.onError,t=i.onStart,o=i.unsubscribe;return _newArrowCheck(this,_this$17),new Observable(function(i){return _newArrowCheck(this,_this$17),observe(e,n,{onError:r,onStart:t,onAbort:i.error,onResult:onResult(n,i)}),o}.bind(this))}.bind(void 0),_this$19=void 0,unobserve$2=function(e,n){_newArrowCheck(this,_this$19);var i=e.observers,r=_objectWithoutProperties(e,["observers"]);return _extends({},r,{observers:utilsArray.remove(i.indexOf(n),1,i)})}.bind(void 0),_this$18=void 0,unobserve=function(e,n,i){return _newArrowCheck(this,_this$18),updateNotifiers(e,refresh(unobserve$2(n,i))),e}.bind(void 0);exports.cancel=cancel,exports.create=create,exports.observe=observe,exports.send=send$1,exports.toObservable=toObservable,exports.unobserve=unobserve;
//# sourceMappingURL=index.js.map