UNPKG

react-blips

Version:
3 lines (2 loc) 15.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("graphql")):"function"==typeof define&&define.amd?define(["exports","react","graphql"],t):t(e.blips={},e.React,e.graphql)}(this,function(e,t,n){"use strict";function r(e){return function(){return e}}function o(e,t){if(e===t)return!0;if("object"!==(void 0===e?"undefined":B(e))||null===e||"object"!==(void 0===t?"undefined":B(t))||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=0;n.length>o;o++){var i=n[o];if(!t.hasOwnProperty(i)||e[i]!==t[i])return!1}return!0}function i(e){return null==e}function u(e){return function(t){var n=e;return i(t.name)||("object"===B(t.name)?n=t.name[e]||e:"string"==typeof t.name&&(n="data"===e?t.name:e)),n}}function c(e){return function(t){return Object.entries(t).reduce(function(t,n){var r;return V({},t,(r={},r[n[0]]=e(n[1]),r))},{})}}function a(e){return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.entries(e).reduce(function(e,t){var n,r=t[0];return V({},e,(n={},n[r]=[].concat(e[r]||[],t[1]),n))},t)}}function s(e){return n.visit(e,{leave:function(e,t,n,r,o){return"OperationDefinition"===e.kind&&"subscription"===e.operation?V({},e,{operation:"query",name:V({},e.name,{value:(e.name.value||"").replace("Subscription","Query")})}):e}})}function f(e,t,n){var r=!!e;return"function"==typeof e&&(r=!!e(n)),r?"function"==typeof t?t(n):t:n}function p(e){return"string"==typeof e?""===e:"object"===(void 0===e?"undefined":B(e))&&(e.hasOwnProperty("length")?!e.length:e.hasOwnProperty("size")?!e.size:!Object.keys(e).length)}function l(e,t){for(var n={},r={},o=e.length,i=0;o>i;)r[e[i]]=1,i+=1;for(var u in t)r.hasOwnProperty(u)||(n[u]=t[u]);return n}function v(e){return Object.entries(e).reduce(function(e,t){var n,r=t[0],o=t[1];return p(o)||i(o)?e:V({},e,(n={},n[r]=o,n))},{})}function h(e,t){var n=t.dataKey,r=t.queriesKey,o=t.mutationsKey,u={},c=e.reduce(function(e,t){var c,s=t.errors,p=t.data,l=X(t,["errors","data"]);return s&&(u=a(s)(u)),V({},e,(c={},c[n]=V({},e[n]||{},f(i,{},p)),c[o]=V({},e[o]||{},f(i,{},l[o])),c[r]=V({},e[r]||{},f(i,{},l[r])),c))},arguments.length>2&&void 0!==arguments[2]?arguments[2]:{});return p(u)||(c[n]=l(Object.keys(u),c[n]),c[n].errors=u),v(c)}function d(e){return e&&e.kind!==n.Kind.DOCUMENT?{kind:"Document",definitions:[e]}:e}function y(e,t){return t.directives.some(function(t){return e.includes(t.name.value)})}function m(e,t){return t.directives.filter(function(t){return!e.includes(t.name.value)})}function b(e){return!(e.kind!==n.Kind.OPERATION_DEFINITION)}function g(e){return!(e.kind!==n.Kind.FRAGMENT_DEFINITION)}function O(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).name.value}function j(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).operation}function R(e){var t=[];return n.visit(e,{leave:function(e){var r=e.name;r=void 0===r?{}:r,e.kind===n.Kind.FRAGMENT_SPREAD&&t.push(r.value)}}),t}function q(e){return function(t){return n.concatAST([d(t)].concat(R(t).map(function(t){return d(e[t])})))}}function w(e){var t=$.get(e);if(!t){var n=e.definitions.reduce(function(e,t){var n,r,o=void 0,u=b(t)?y(["fetch"],t)?(o=V({},t,{directives:m(["fetch"],t)}),["fetch",O(t)]):[j(t),O(t)]:g(t)?["fragment",O(t)]:[null,null],c=u[0],a=u[1];return i(c)||i(a)?e:V({},e,(r={},r[c]=V({},e[c]||{},(n={},n[a]=o||t,n)),r))},{}),r=n.fragment,o=X(n,["fragment"]);t=c(c(q(r)))(o),$.set(e,t)}return t}function P(e){return function(t,n){var r,o=(r={},r[e]=V({},t[e]||{},n[e]||{}),r);return f(p(o[e]),{},o)}}function x(e,t){var n=P("query")(e,t),r=P("mutation")(e,t),o=P("subscription")(e,t),i=P("fetch")(e,t);return V({},e,n,r,o,i)}function T(e,r){var i=u("data")(r),a=u("mutations")(r),f=u("queries")(r),p=[],l=p.push.bind(p),v=function(){return p.length=0},d=[],y=d.push.bind(d),m=function(){return d.length=0},b=function(){for(var e=Array.isArray(n=d),t=0,n=e?n:n[Symbol.iterator]();;){var r;if(e){if(t>=n.length)break;r=n[t++]}else{if((t=n.next()).done)break;r=t.value}r.unsubscribe()}},g=[],O=function(e){return r.options&&"function"==typeof r.options?r.options(e):r.options||{}};return function(r){Q("function"==typeof r,"You must pass a component to the function returned by graphql. Instead received "+JSON.stringify(r));var u=function(t){function u(r,o){var v,d=this;z(this,u);var m=Z(this,t.call(this,r,o));return m.state=(v={},v[i]={loading:!0},v),m.cancelResolve=function(){},m.batchUpdateState=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:g;(0!==e.length||arguments[2])&&(m.setState(h(e,{dataKey:i,queriesKey:f,mutationsKey:a},arguments.length>1&&void 0!==arguments[1]?arguments[1]:m.state)),g.length=0)},m.parse=function(e){var t=e.map(n.parse);return{sources:e,documents:t,operations:t.map(w).reduce(x,{})}},m.resolve=function(){for(var e,t=!1,n=m.parsedData.operations,r=n.query,o=void 0===r?{}:r,u=n.mutation,v=void 0===u?{}:u,h=n.subscription,d=n.fetch,y=void 0===d?{}:d,b=Object.values(void 0===h?{}:h),g=Array.isArray(b),O=0,b=g?b:b[Symbol.iterator]();;){var j;if(g){if(O>=b.length)break;j=b[O++]}else{if((O=b.next()).done)break;j=O.value}var R=j;m.subscribe(R)(m.options),l(m.query(s(R))(m.options))}for(var q=Object.values(o),w=Array.isArray(q),P=0,q=w?q:q[Symbol.iterator]();;){var x;if(w){if(P>=q.length)break;x=q[P++]}else{if((P=q.next()).done)break;x=P.value}l(m.query(x)(m.options))}for(var T=Object.values(y),k=Array.isArray(T),S=0,T=k?T:T[Symbol.iterator]();;){var N;if(k){if(S>=T.length)break;N=T[S++]}else{if((S=T.next()).done)break;N=S.value}l(m.fetch(N)(m.options))}l(Promise.resolve((e={},e[f]=V({},c(m.query)(o),c(m.fetch)(y)),e[a]=c(m.mutate)(v),e))),Promise.all(p).then(function(e){var n;!t&&m.batchUpdateState(e,(n={},n[i]={loading:!1},n),!0)}),m.cancelResolve=function(){return t=!0}},m.query=function(e){return function(){return m.client.query(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:m.options)}},m.mutate=function(e){return function(){return m.client.mutate(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:m.options)}},m.fetch=function(e){return function(){return m.client.fetch(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:m.options)}},m.subscribe=function(e){return function(){var t=J(regeneratorRuntime.mark(function t(){var n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:m.options;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.client.subscribe(e,r);case 2:y((n=t.sent).subscribe(function(e){g.push(e),process.nextTick(m.batchUpdateState)}));case 4:case"end":return t.stop()}},t,d)}));return function(){return t.apply(this,arguments)}}()},m.client=o.client,m.options=O(r),m.parsedData=m.parse(e),m}return H(u,t),u.prototype.componentWillMount=function(){this.resolve()},u.prototype.componentWillReceiveProps=function(e){var t=O(e);o(this.options,t)||(this.options=V({},t),b(),m(),v(),this.cancelResolve(),this.resolve())},u.prototype.render=function(){var e=Object.entries(this.state).reduce(function(e,t){var n,r=t[0];return V({},e,(n={},n[r]=V({},e[r]||{},t[1]),n))},this.props);return S.createElement(r,e)},u}(t.Component);return u.displayName="Blips("+(r.displayName||r.name||"Component")+")",u.WrappedComponent=r,u.contextTypes={client:A.object.isRequired},G(u,r,{})}}function k(e,r){var a=u("mutations")(r),s=u("queries")(r),f=function(e){return r.options&&"function"==typeof r.options?r.options(e):r.options||{}};return function(r){Q("function"==typeof r,"You must pass a component to the function returned by blips. Instead received "+JSON.stringify(r));var u=function(t){function u(r,o){z(this,u);var i=Z(this,t.call(this,r,o));return i.parse=function(e){var t=e.map(n.parse);return{sources:e,documents:t,operations:t.map(w).reduce(x,{})}},i.resolve=function(){var e,t=i.parsedData.operations,n=t.query,r=void 0===n?{}:n,o=t.mutation,u=void 0===o?{}:o,f=t.fetch,p=void 0===f?{}:f;i.operations=(e={},e[s]=V({},c(i.query)(r),c(i.fetch)(p)),e[a]=c(i.mutate)(u),e)},i.query=function(e){return function(){return i.client.query(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.options)}},i.mutate=function(e){return function(){return i.client.mutate(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.options)}},i.fetch=function(e){return function(){return i.client.fetch(e,arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.options)}},i.client=o.client,i.options=f(r),i.parsedData=i.parse(e),i}return H(u,t),u.prototype.componentWillMount=function(){this.resolve()},u.prototype.componentWillReceiveProps=function(e){var t=f(e);o(this.options,t)||(this.options=V({},t),this.resolve())},u.prototype.render=function(){var e=Object.entries(this.operations).reduce(function(e,t){var n,r=t[0],o=t[1];return p(o)||i(o)?e:V({},e,(n={},n[r]=V({},e[r]||{},o),n))},this.props);return S.createElement(r,e)},u}(t.Component);return u.displayName="withOperations("+(r.displayName||r.name||"Component")+")",u.WrappedComponent=r,u.contextTypes={client:A.object.isRequired},G(u,r,{})}}var S="default"in t?t.default:t,N=function(){};N.thatReturns=r,N.thatReturnsFalse=r(!1),N.thatReturnsTrue=r(!0),N.thatReturnsNull=r(null),N.thatReturnsThis=function(){return this},N.thatReturnsArgument=function(e){return e};var _=N,C=function(e,t,n,r,o,i,u,c){if(!e){var a;if(void 0===t)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,r,o,i,u,c],f=0;(a=Error(t.replace(/%s/g,function(){return s[f++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}},E="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",I=function(){function e(e,t,n,r,o,i){i!==E&&C(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=_,n.PropTypes=n,n},A=function(e,t){return t={exports:{}},e(t,t.exports),t.exports}(function(e){e.exports=I()}),D={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},K={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},M=Object.defineProperty,U=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,L=Object.getOwnPropertyDescriptor,F=Object.getPrototypeOf,Y=F&&F(Object),G=function e(t,n,r){if("string"!=typeof n){if(Y){var o=F(n);o&&o!==Y&&e(t,o,r)}var i=U(n);W&&(i=i.concat(W(n)));for(var u=0;i.length>u;++u){var c=i[u];if(!(D[c]||K[c]||r&&r[c])){var a=L(n,c);try{M(t,c,a)}catch(e){}}}return t}return t},Q=function(e,t,n,r,o,i,u,c){if(!e){var a;if(void 0===t)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,r,o,i,u,c],f=0;(a=Error(t.replace(/%s/g,function(){return s[f++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}},B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},J=(function(){function e(e){this.value=e}function t(t){function n(o,i){try{var u=t[o](i),c=u.value;c instanceof e?Promise.resolve(c.value).then(function(e){n("next",e)},function(e){n("throw",e)}):r(u.done?"return":"normal",u.value)}catch(e){r("throw",e)}}function r(e,t){switch(e){case"return":o.resolve({value:t,done:!0});break;case"throw":o.reject(t);break;default:o.resolve({value:t,done:!1})}(o=o.next)?n(o.key,o.arg):i=null}var o,i;this._invoke=function(e,t){return new Promise(function(r,u){var c={key:e,arg:t,resolve:r,reject:u,next:null};i?i=i.next=c:(o=i=c,n(e,t))})},"function"!=typeof t.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)}}(),function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,n){function r(o,i){try{var u=t[o](i),c=u.value}catch(e){return void n(e)}if(!u.done)return Promise.resolve(c).then(function(e){r("next",e)},function(e){r("throw",e)});e(c)}return r("next")})}}),z=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},V=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},H=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},X=function(e,t){var n={};for(var r in e)0>t.indexOf(r)&&Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Z=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},$=new Map,ee=function(e){function r(t,o){z(this,r);var i=Z(this,e.call(this,t,o));i.client=t.client;var u=new n.GraphQLDirective({name:"api",description:"Sends this operation to a real GraphQL server for execution",locations:[n.DirectiveLocation.QUERY,n.DirectiveLocation.MUTATION,n.DirectiveLocation.SUBSCRIPTION]});return i.client.schema._directives.push(u),i}return H(r,e),r.prototype.getChildContext=function(){return{client:this.client}},r.prototype.render=function(){return t.Children.only(this.props.children)},r}(t.Component);ee.propTypes={client:A.shape({state:A.object.isRequired,schema:A.object.isRequired,query:A.func.isRequired,mutate:A.func.isRequired,subscribe:A.func.isRequired,fetch:A.func.isRequired}).isRequired,children:A.element.isRequired},ee.childContextTypes={client:A.object.isRequired},e.graphql=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r={};return"object"===B(t[t.length-1])&&(r=t.pop()),T([].concat(t),r)},e.withClient=function(e){Q("function"==typeof e,"You must pass a component to the function returned by graphql. Instead received "+JSON.stringify(e));var n=function(t){function n(e,r){z(this,n);var o=Z(this,t.call(this,e,r));return o.client=e.client||r.client,o}return H(n,t),n.prototype.componentWillReceiveProps=function(e){e.client&&e.client!==this.client&&(this.client=e.client)},n.prototype.render=function(){return S.createElement(e,V({},this.props,{client:this.client}))},n}(t.Component);return n.displayName="withClient("+(e.displayName||e.name||"Component")+")",n.WrappedComponent=e,n.propTypes={client:A.object},n.contextTypes={client:A.object.isRequired},G(n,e,{})},e.withOperations=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r={};return"object"===B(t[t.length-1])&&(r=t.pop()),k([].concat(t),r)},e.Provider=ee,e.compose=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce(function(e,t){return function(){return e(t.apply(void 0,arguments))}})},Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=react-blips.min.js.map