UNPKG

10.4 kBJavaScriptView Raw
1!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@urql/core"),require("jotai"),require("wonka")):"function"==typeof define&&define.amd?define(["exports","@urql/core","jotai","wonka"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).jotaiUrql={},t.core,t.jotai,t.wonka)}(this,(function(t,r,e,n){"use strict";var o=function(){try{return process.env.JOTAI_URQL_DEFAULT_URL}catch(t){return}}()||"/graphql",i=e.atom(r.createClient({url:o}));function u(){
2/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3u=function(){return t};var t={},r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function l(t,r,e,n){var o=r&&r.prototype instanceof h?r:h,i=Object.create(o.prototype),u=new P(n||[]);return i._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return _()}for(e.method=o,e.arg=i;;){var u=e.delegate;if(u){var a=x(u,e);if(a){if(a===s)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=f(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,u),i}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var s={};function h(){}function p(){}function v(){}var y={};c(y,o,(function(){return this}));var d=Object.getPrototypeOf,m=d&&d(d(j([])));m&&m!==r&&e.call(m,o)&&(y=m);var g=v.prototype=h.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function b(t,r){function n(o,i,u,a){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==typeof s&&e.call(s,"__await")?r.resolve(s.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):r.resolve(s).then((function(t){l.value=t,u(l)}),(function(t){return n("throw",t,u,a)}))}a(c.arg)}var o;this._invoke=function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}}function x(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,x(t,r),"throw"===r.method))return s;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=f(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,s;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,s):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,s)}function L(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function j(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:_}}function _(){return{value:void 0,done:!0}}return p.prototype=v,c(g,"constructor",v),c(v,"constructor",p),p.displayName=c(v,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(b.prototype),c(b.prototype,i,(function(){return this})),t.AsyncIterator=b,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var u=new b(l(r,e,n,o),i);return t.isGeneratorFunction(e)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},w(g),c(g,a,"Generator"),c(g,o,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=j,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return u.type="throw",u.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=r,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(u)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),s},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),s}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:j(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),s}},t}function a(t,r,e,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void e(t)}a.done?r(c):Promise.resolve(c).then(n,o)}function c(){return c=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},c.apply(this,arguments)}t.atomWithMutation=function(t,r){void 0===r&&(r=function(t){return t(i)});var n,o,c=e.atom(new Promise((function(){}))),l=e.atom((function(t){return t(c)}),(n=u().mark((function e(n,o,i){var a,l;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o(c,new Promise((function(){}))),a=r(n),l=t(n),e.abrupt("return",a.mutation(l,i.variables,i.context).toPromise().then((function(t){if(null==i.callback||i.callback(t),t.error)throw t.error;o(c,t)})));case 4:case"end":return e.stop()}}),e)})),o=function(){var t=this,r=arguments;return new Promise((function(e,o){var i=n.apply(t,r);function u(t){a(i,e,o,u,c,"next",t)}function c(t){a(i,e,o,u,c,"throw",t)}u(void 0)}))},function(t,r,e){return o.apply(this,arguments)}));return l},t.atomWithQuery=function(t,r){void 0===r&&(r=function(t){return t(i)});var o=e.atom((function(o){var i=t(o);if(i.pause)return null;var u,a=r(o),l=null,f=function(){return new Promise((function(t){l=t}))},s=e.atom(f()),h=null,p=function(t){if(!l&&!h)throw new Error("setting result without mount");l&&(l(t),l=null),h&&h(t)},v=null,y=function(t){v&&(clearTimeout(u),v.unsubscribe()),v=n.pipe(a.query(i.query,i.variables,c({},i.requestPolicy&&{requestPolicy:i.requestPolicy},i.context,t)),n.subscribe(p)),h||(u=setTimeout((function(){v&&(v.unsubscribe(),v=null)}),1e3))};return y(),s.onMount=function(t){return h=t,v?clearTimeout(u):y(),function(){h=null,v&&(v.unsubscribe(),v=null)}},{resultAtom:s,makePending:f,startQuery:y}}));return e.atom((function(t){var r=t(o);if(!r)return null;var e=t(r.resultAtom);if(!function(t){return"data"in t&&!t.error}(e))throw e.error;return e}),(function(t,r,e){if("reexecute"===e.type&&(console.warn("DEPRECATED [atomWithQuery] use refetch instead of reexecute"),e.type="refetch"),"refetch"===e.type){var n=t(o);if(!n)throw new Error("query is paused");var i=n.resultAtom,u=n.makePending,a=n.startQuery;return r(i,u()),void a(e.opts)}}))},t.atomWithSubscription=function(t,r){void 0===r&&(r=function(t){return t(i)});var o=e.atom((function(o){var i=t(o);if(i.pause)return null;var u,a=r(o),c=null,l=function(){return new Promise((function(t){c=t}))},f=e.atom(l()),s=null,h=function(t){c&&(c(t),c=null),s&&s(t)},p=null,v=function(){p&&(clearTimeout(u),p.unsubscribe()),p=n.pipe(a.subscription(i.query,i.variables,i.context),n.subscribe(h)),s||(u=setTimeout((function(){p&&(p.unsubscribe(),p=null)}),1e3))};return v(),f.onMount=function(t){return s=t,p?clearTimeout(u):v(),function(){s=null,p&&(p.unsubscribe(),p=null)}},{resultAtom:f,makePending:l,startSub:v}}));return e.atom((function(t){var r=t(o);if(!r)return null;var e=t(r.resultAtom);if(!function(t){return"data"in t&&!t.error}(e))throw e.error;return e}),(function(t,r,e){if("refetch"===e.type){var n=t(o);if(!n)throw new Error("query is paused");var i=n.resultAtom,u=n.makePending,a=n.startSub;return r(i,u()),void a()}}))},t.clientAtom=i,Object.defineProperty(t,"__esModule",{value:!0})}));