@urql/core
Advanced tools
Comparing version 1.10.5 to 1.10.6
# @urql/core | ||
## 1.10.6 | ||
### Patch Changes | ||
- ⚠️ Fix critical bug in operation queueing that can lead to unexpected teardowns and swallowed operations. This would happen when a teardown operation kicks off the queue, by [@kitten](https://github.com/kitten) (See [#662](https://github.com/FormidableLabs/urql/pull/662)) | ||
## 1.10.5 | ||
@@ -4,0 +10,0 @@ |
@@ -37,6 +37,7 @@ import { Source } from 'wonka'; | ||
maskTypename: boolean; | ||
dispatchOperation: (operation: Operation) => void; | ||
dispatchOperation: (operation?: Operation) => void; | ||
operations$: Source<Operation>; | ||
results$: Source<OperationResult>; | ||
activeOperations: ActiveOperations; | ||
queue: Operation[]; | ||
constructor(opts: ClientOptions); | ||
@@ -43,0 +44,0 @@ private createOperationContext; |
@@ -27,3 +27,3 @@ "use strict"; | ||
function b(b) { | ||
var c = b.networkError, f = b.response; | ||
var c = b.networkError, e = b.response; | ||
var g = function(a, b) { | ||
@@ -44,3 +44,3 @@ var d = ""; | ||
this.networkError = c; | ||
this.response = f; | ||
this.response = e; | ||
} | ||
@@ -70,4 +70,4 @@ a && (b.__proto__ = a); | ||
0 < c && (b += ","); | ||
var f = stringify(a[c]); | ||
b += 0 < f.length ? f : "null"; | ||
var e = stringify(a[c]); | ||
b += 0 < e.length ? e : "null"; | ||
} | ||
@@ -83,5 +83,5 @@ return b + "]"; | ||
d = 0; | ||
for (f = b.length; d < f; d++) { | ||
var g = b[d], e = stringify(a[g]); | ||
e && (1 < c.length && (c += ","), c += stringify(g) + ":" + e); | ||
for (e = b.length; d < e; d++) { | ||
var g = b[d], f = stringify(a[g]); | ||
f && (1 < c.length && (c += ","), c += stringify(g) + ":" + f); | ||
} | ||
@@ -145,4 +145,4 @@ seen.delete(a); | ||
for (var d in a) { | ||
var f = a[d]; | ||
"__typename" === d && "string" == typeof f ? b.push(f) : collectTypes(f, b); | ||
var e = a[d]; | ||
"__typename" === d && "string" == typeof e ? b.push(e) : collectTypes(e, b); | ||
} | ||
@@ -247,3 +247,3 @@ } | ||
}); | ||
"cache-and-network" === a.context.requestPolicy && (b.stale = !0, reexecuteOperation(e, a)); | ||
"cache-and-network" === a.context.requestPolicy && (b.stale = !0, reexecuteOperation(f, a)); | ||
return b; | ||
@@ -257,8 +257,8 @@ } | ||
} | ||
function f(a) { | ||
function e(a) { | ||
return !shouldSkip$1(a) && !n(a); | ||
} | ||
var g = a.forward, e = a.client, h = new Map; | ||
var g = a.forward, f = a.client, h = new Map; | ||
a = Object.create(null); | ||
var k = _ref$1, l = afterMutation(h, a, e), m = afterQuery(h, a), n = function(a) { | ||
var k = _ref$1, l = afterMutation(h, a, f), m = afterQuery(h, a), n = function(a) { | ||
var c = a.context.requestPolicy; | ||
@@ -268,6 +268,6 @@ return "query" === a.operationName && "network-only" !== c && ("cache-only" === c || h.has(a.key)); | ||
return function(a) { | ||
var e = wonka.share(a); | ||
a = wonka.map(b)(wonka.filter(c)(e)); | ||
e = wonka.tap(d)(g(wonka.filter(_ref5)(wonka.map(_ref6)(wonka.merge([ wonka.map(k)(wonka.filter(f)(e)), wonka.filter(_ref8)(e) ]))))); | ||
return wonka.merge([ a, e ]); | ||
var f = wonka.share(a); | ||
a = wonka.map(b)(wonka.filter(c)(f)); | ||
f = wonka.tap(d)(g(wonka.filter(_ref5)(wonka.map(_ref6)(wonka.merge([ wonka.map(k)(wonka.filter(e)(f)), wonka.filter(_ref8)(f) ]))))); | ||
return wonka.merge([ a, f ]); | ||
}; | ||
@@ -283,5 +283,5 @@ }, reexecuteOperation = function(a, b) { | ||
if (a.has(b)) { | ||
var d = a.get(b).operation; | ||
var g = a.get(b).operation; | ||
a.delete(b); | ||
reexecuteOperation(c, d); | ||
reexecuteOperation(c, g); | ||
} | ||
@@ -293,4 +293,4 @@ } | ||
} | ||
var e = new Set, f = a.operation.context.additionalTypenames; | ||
collectTypesFromResponse(a.data).concat(f || []).forEach((function(a) { | ||
var e = new Set, h = a.operation.context.additionalTypenames; | ||
collectTypesFromResponse(a.data).concat(h || []).forEach((function(a) { | ||
(a = b[a] || (b[a] = new Set)).forEach(c); | ||
@@ -303,6 +303,6 @@ a.clear(); | ||
return function(c) { | ||
var d = c.operation, f = c.data, g = d.context.additionalTypenames; | ||
null != f && (a.set(d.key, { | ||
var d = c.operation, e = c.data, g = d.context.additionalTypenames; | ||
null != e && (a.set(d.key, { | ||
operation: d, | ||
data: f, | ||
data: e, | ||
error: c.error | ||
@@ -335,3 +335,3 @@ }), collectTypesFromResponse(c.data).concat(g || []).forEach((function(a) { | ||
return !a; | ||
}, f = function(a) { | ||
}, e = function(a) { | ||
c.delete(a.operation.key); | ||
@@ -341,3 +341,3 @@ }; | ||
a = wonka.filter(d)(a); | ||
return wonka.tap(f)(b(a)); | ||
return wonka.tap(e)(b(a)); | ||
}; | ||
@@ -364,4 +364,4 @@ }; | ||
}))(wonka.filter(_ref$2)(c)); | ||
var f = b(wonka.filter(_ref2$2)(c)); | ||
return wonka.merge([ a, f ]); | ||
var e = b(wonka.filter(_ref2$2)(c)); | ||
return wonka.merge([ a, e ]); | ||
}; | ||
@@ -379,5 +379,5 @@ }; | ||
return wonka.make((function(c) { | ||
var d = c.next, f = c.complete, g = "undefined" != typeof AbortController ? new AbortController : void 0; | ||
var d = c.next, e = c.complete, g = "undefined" != typeof AbortController ? new AbortController : void 0; | ||
c = "function" == typeof (c = a.context).fetchOptions ? c.fetchOptions() : c.fetchOptions || {}; | ||
var e = function(a) { | ||
var f = function(a) { | ||
return (a = a.definitions.find(_ref3$2)) ? a.name.value : null; | ||
@@ -388,3 +388,3 @@ }(a.query), h = { | ||
}; | ||
null !== e && (h.operationName = e); | ||
null !== f && (h.operationName = f); | ||
var k = _extends({}, c, { | ||
@@ -403,3 +403,3 @@ body: b ? void 0 : JSON.stringify(h), | ||
})).then((function(a) { | ||
l || (l = !0, a && d(a), f()); | ||
l || (l = !0, a && d(a), e()); | ||
})); | ||
@@ -455,2 +455,3 @@ return function() { | ||
this.activeOperations = Object.create(null); | ||
this.queue = []; | ||
this.createOperationContext = function(a) { | ||
@@ -476,3 +477,3 @@ return _extends({}, { | ||
this.reexecuteOperation = function(a) { | ||
0 < (b.activeOperations[a.key] || 0) && b.dispatchOperation(a); | ||
0 < (b.activeOperations[a.key] || 0) && (b.queue.push(a), b.dispatchOperation()); | ||
}; | ||
@@ -506,10 +507,10 @@ this.executeQuery = function(a, c) { | ||
this.operations$ = c.source; | ||
var f = [], g = !1; | ||
var e = !1; | ||
this.dispatchOperation = function(a) { | ||
f.push(a); | ||
if (!g) { | ||
for (g = !0; void 0 !== (a = f.shift()); ) { | ||
a && d(a); | ||
if (!e) { | ||
for (e = !0; a = b.queue.shift(); ) { | ||
d(a); | ||
} | ||
g = !1; | ||
e = !1; | ||
} | ||
@@ -544,7 +545,7 @@ }; | ||
Client.prototype.executeRequestOperation = function(a) { | ||
var c = this, d = a.key, f = a.operationName, g = wonka.filter((function(a) { | ||
var c = this, d = a.key, e = a.operationName, g = wonka.filter((function(a) { | ||
return a.operation.key === d; | ||
}))(this.results$); | ||
this.maskTypename && (g = wonka.map(_ref2$4)(g)); | ||
if ("mutation" === f) { | ||
if ("mutation" === e) { | ||
return wonka.take(1)(wonka.onStart((function b() { | ||
@@ -554,3 +555,3 @@ return c.dispatchOperation(a); | ||
} | ||
var e = wonka.filter((function(a) { | ||
var f = wonka.filter((function(a) { | ||
return "teardown" === a.operationName && a.key === d; | ||
@@ -562,13 +563,13 @@ }))(this.operations$); | ||
c.onOperationStart(a); | ||
}))(wonka.takeUntil(e)(g))); | ||
return !1 !== a.context.suspense && this.suspense && "query" === f ? function(a) { | ||
}))(wonka.takeUntil(f)(g))); | ||
return !1 !== a.context.suspense && this.suspense && "query" === e ? function(a) { | ||
return function(b) { | ||
var c = wonka.share(a), d = !1, f = !1; | ||
var c = wonka.share(a), d = !1, e = !1; | ||
wonka.onPush((function() { | ||
return d = !0; | ||
}))(wonka.takeWhile((function() { | ||
return !f; | ||
return !e; | ||
}))(c))(b); | ||
if (!d) { | ||
throw f = !0, b(0), wonka.toPromise(wonka.take(1)(c)); | ||
throw e = !0, b(0), wonka.toPromise(wonka.take(1)(c)); | ||
} | ||
@@ -653,3 +654,3 @@ }; | ||
}; | ||
}(a, e[a.key]); | ||
}(a, f[a.key]); | ||
} | ||
@@ -659,3 +660,3 @@ function d(a) { | ||
} | ||
function f(a) { | ||
function e(a) { | ||
var b = a.operation; | ||
@@ -673,24 +674,24 @@ shouldSkip(b) || (a = function(a) { | ||
return a; | ||
}(a), e[b.key] = a); | ||
}(a), f[b.key] = a); | ||
} | ||
function g(a) { | ||
delete e[a.operation.key]; | ||
delete f[a.operation.key]; | ||
} | ||
var e = {}, h = function(a) { | ||
return !shouldSkip(a) && void 0 !== e[a.key]; | ||
}, k = function(e) { | ||
var h = e.client, k = e.forward; | ||
return function(e) { | ||
var p = a && "boolean" == typeof a.isClient ? !!a.isClient : !h.suspense, m = wonka.share(e); | ||
e = k(wonka.filter(b)(m)); | ||
var f = {}, h = function(a) { | ||
return !shouldSkip(a) && void 0 !== f[a.key]; | ||
}, k = function(f) { | ||
var h = f.client, k = f.forward; | ||
return function(f) { | ||
var p = a && "boolean" == typeof a.isClient ? !!a.isClient : !h.suspense, m = wonka.share(f); | ||
f = k(wonka.filter(b)(m)); | ||
m = wonka.map(c)(wonka.filter(d)(m)); | ||
p ? m = wonka.tap(g)(m) : e = wonka.tap(f)(e); | ||
return wonka.merge([ e, m ]); | ||
p ? m = wonka.tap(g)(m) : f = wonka.tap(e)(f); | ||
return wonka.merge([ f, m ]); | ||
}; | ||
}; | ||
k.restoreData = function(a) { | ||
return _extends(e, a); | ||
return _extends(f, a); | ||
}; | ||
k.extractData = function() { | ||
return _extends({}, e); | ||
return _extends({}, f); | ||
}; | ||
@@ -709,6 +710,6 @@ a && a.initialState && k.restoreData(a.initialState); | ||
return function(a) { | ||
function d(a) { | ||
function g(a) { | ||
return !l(a); | ||
} | ||
var e = a.client, f = a.forward, k = function(a) { | ||
var d = a.client, e = a.forward, k = function(a) { | ||
var b = c({ | ||
@@ -721,10 +722,10 @@ key: a.key.toString(36), | ||
return wonka.make((function(c) { | ||
function d(b) { | ||
function g(b) { | ||
return h(makeResult(a, b)); | ||
} | ||
function f(b) { | ||
function e(b) { | ||
return h(makeErrorResult(a, b)); | ||
} | ||
function g() { | ||
m || (m = !0, "subscription" === a.operationName && e.reexecuteOperation(_extends({}, a, { | ||
function f() { | ||
m || (m = !0, "subscription" === a.operationName && d.reexecuteOperation(_extends({}, a, { | ||
operationName: "teardown" | ||
@@ -736,5 +737,5 @@ })), k()); | ||
m || (l = b.subscribe({ | ||
next: d, | ||
error: f, | ||
complete: g | ||
next: g, | ||
error: e, | ||
complete: f | ||
})); | ||
@@ -751,8 +752,8 @@ })); | ||
a = wonka.mergeMap((function(a) { | ||
var c = a.key, d = wonka.filter((function(a) { | ||
var c = a.key, g = wonka.filter((function(a) { | ||
return "teardown" === a.operationName && a.key === c; | ||
}))(b); | ||
return wonka.takeUntil(d)(k(a)); | ||
return wonka.takeUntil(g)(k(a)); | ||
}))(wonka.filter(l)(b)); | ||
var c = f(wonka.filter(d)(b)); | ||
var c = e(wonka.filter(g)(b)); | ||
return wonka.merge([ a, c ]); | ||
@@ -759,0 +760,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("wonka"),t=require("graphql");function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r,n=arguments[t];for(r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(e){return"string"==typeof e?new t.GraphQLError(e):"object"==typeof e&&e.message?new t.GraphQLError(e.message,e.nodes,e.source,e.positions,e.path,e,e.extensions||{}):e};function o(){return this.message}var i=function(e){function t(t){var r=t.networkError,o=t.response,i=function(e,t){var r="";return void 0!==e?r="[Network] "+e.message:(void 0!==t&&t.forEach((function(e){r+="[GraphQL] "+e.message+"\n"})),r.trim())}(r,t=(t.graphQLErrors||[]).map(n));e.call(this,i),this.name="CombinedError",this.message=i,this.graphQLErrors=t,this.networkError=r,this.response=o}return e&&(t.__proto__=e),(t.prototype=Object.create(e&&e.prototype)).constructor=t,t.prototype.toString=o,t}(Error),a=function(e,t){e|=0;for(var r=0,n=0|t.length;r<n;r++)e=(e<<5)+e+t.charCodeAt(r);return e},u=new Set,c=new WeakMap,s=function(e){if(null===e||u.has(e))return"null";if("object"!=typeof e)return JSON.stringify(e)||"";if(e.toJSON)return e.toJSON();if(Array.isArray(e)){for(var t="[",r=0,n=e.length;r<n;r++){0<r&&(t+=",");var o=s(e[r]);t+=0<o.length?o:"null"}return t+"]"}if(!(t=Object.keys(e).sort()).length&&e.constructor&&e.constructor!==Object)return t=c.get(e)||Math.random().toString(36).slice(2),c.set(e,t),'{"__key":"'+t+'"}';for(u.add(e),r="{",n=0,o=t.length;n<o;n++){var i=t[n],a=s(e[i]);a&&(1<r.length&&(r+=","),r+=s(i)+":"+a)}return u.delete(e),r+"}"},f=function(e){return u.clear(),s(e)},p=function(e){return function(e){return a(5381,e)>>>0}(e.replace(/[\s,]+/g," ").trim())},l=Object.create(null),h=function(e,r){if("string"==typeof e){var n=p(e);e=void 0!==l[n]?l[n]:t.parse(e)}else void 0!==e.__key?n=e.__key:(n=p(t.print(e)),e=void 0!==l[n]?l[n]:e);return l[n]=e,e.__key=n,{key:r?a(n,f(r))>>>0:n,query:e,variables:r||{}}},y=function(e,t){return r({},e,{context:r({},e.context,{meta:r({},e.context.meta,t)})})},d=function(e,t,r){return{operation:e,data:t.data,error:Array.isArray(t.errors)?new i({graphQLErrors:t.errors,response:r}):void 0,extensions:"object"==typeof t.extensions&&t.extensions||void 0}},v=function(e,t,r){return{operation:e,data:void 0,error:new i({networkError:t,response:r}),extensions:void 0}},m=function(e,t){if(void 0===t&&(t=[]),Array.isArray(e))e.forEach((function(e){m(e,t)}));else if("object"==typeof e&&null!==e)for(var r in e){var n=e[r];"__typename"===r&&"string"==typeof n?t.push(n):m(n,t)}return t};function x(e,t,r){return r.indexOf(e)===t}var g=function(e){return m(e).filter(x)};function k(e){return e.kind===t.Kind.FIELD&&"__typename"===e.name.value}var O=function(e){return!!e.selectionSet&&(function(e){return e.selections.some(k)}(e.selectionSet)?void 0:(e.selectionSet.selections.push({kind:t.Kind.FIELD,name:{kind:t.Kind.NAME,value:"__typename"}}),e))},b=function(e){return t.visit(e,{Field:O,InlineFragment:O})},E=function(e){return e&&"object"==typeof e?Object.keys(e).reduce((function(t,r){var n=e[r];return"__typename"===r?Object.defineProperty(t,"__typename",{enumerable:!1,value:n}):t[r]=Array.isArray(n)?n.map(E):n&&"object"==typeof n&&"__typename"in n?E(n):n,t}),{}):e};function w(t){return t.toPromise=function(){return e.toPromise(e.take(1)(t))},t}var q=function(e){return"subscription"!==(e=e.operationName)&&"query"!==e};function N(e){return e.path||e.extensions?{message:e.message,path:e.path,extensions:e.extensions}:e.message}var S=function(e){return"mutation"!==(e=e.operationName)&&"query"!==e};function _(e){return r({},e,{query:b(e.query)})}function j(e){return"query"!==e.operationName||"cache-only"!==e.context.requestPolicy}function P(e){return y(e,{cacheOutcome:"miss"})}function Q(e){return S(e)}var A=function(t){function n(e){var t=s.get(e.key);return t=r({},t,{operation:y(e,{cacheOutcome:t?"hit":"miss"})}),"cache-and-network"===e.context.requestPolicy&&(t.stale=!0,R(c,e)),t}function o(e){return!S(e)&&h(e)}function i(e){e.operation&&"mutation"===e.operation.operationName?p(e):e.operation&&"query"===e.operation.operationName&&l(e)}function a(e){return!S(e)&&!h(e)}var u=t.forward,c=t.client,s=new Map;t=Object.create(null);var f=_,p=L(s,t,c),l=M(s,t),h=function(e){var t=e.context.requestPolicy;return"query"===e.operationName&&"network-only"!==t&&("cache-only"===t||s.has(e.key))};return function(t){var r=e.share(t);return t=e.map(n)(e.filter(o)(r)),r=e.tap(i)(u(e.filter(j)(e.map(P)(e.merge([e.map(f)(e.filter(a)(r)),e.filter(Q)(r)]))))),e.merge([t,r])}},R=function(e,t){return e.reexecuteOperation(r({},t,{context:r({},t.context,{requestPolicy:"network-only"})}))},L=function(e,t,r){function n(t){if(e.has(t)){var n=e.get(t).operation;e.delete(t),R(r,n)}}return function(e){function r(e){o.add(e)}var o=new Set,i=e.operation.context.additionalTypenames;g(e.data).concat(i||[]).forEach((function(e){(e=t[e]||(t[e]=new Set)).forEach(r),e.clear()})),o.forEach(n)}},M=function(e,t){return function(r){var n=r.operation,o=r.data,i=n.context.additionalTypenames;null!=o&&(e.set(n.key,{operation:n,data:o,error:r.error}),g(r.data).concat(i||[]).forEach((function(e){(t[e]||(t[e]=new Set)).add(n.key)})))}},C=function(t){var r=t.forward,n=new Set,o=function(e){var t=e.key;return"teardown"===(e=e.operationName)?(n.delete(t),!0):"query"!==e&&"subscription"!==e||(e=n.has(t),n.add(t),!e)},i=function(e){n.delete(e.operation.key)};return function(t){return t=e.filter(o)(t),e.tap(i)(r(t))}};function I(e){return"query"===e.operationName||"mutation"===e.operationName}function T(e){return"query"!==e.operationName&&"mutation"!==e.operationName}var G=function(t){var r=t.forward;return function(t){var n=e.share(t);t=e.mergeMap((function(t){var r=t.key,o=e.filter((function(e){return"teardown"===e.operationName&&e.key===r}))(n);return e.takeUntil(o)($(t,"query"===t.operationName&&!!t.context.preferGetMethod))}))(e.filter(I)(n));var o=r(e.filter(T)(n));return e.merge([t,o])}};function D(e){return e.kind===t.Kind.OPERATION_DEFINITION&&e.name}var $=function(n,o){return e.make((function(e){var i=e.next,a=e.complete,u="undefined"!=typeof AbortController?new AbortController:void 0;e="function"==typeof(e=n.context).fetchOptions?e.fetchOptions():e.fetchOptions||{};var c=function(e){return(e=e.definitions.find(D))?e.name.value:null}(n.query),s={query:t.print(n.query),variables:n.variables};null!==c&&(s.operationName=c);var f=r({},e,{body:o?void 0:JSON.stringify(s),method:o?"GET":"POST",headers:r({},{"content-type":"application/json"},e.headers),signal:void 0!==u?u.signal:void 0});o&&(n.context.url=J(n.context.url,s));var p=!1;return Promise.resolve().then((function(){return p?void 0:F(n,f)})).then((function(e){p||(p=!0,e&&i(e),a())})),function(){p=!0,void 0!==u&&u.abort()}}))},F=function(e,t){var r,n=e.context;return(n.fetch||fetch)(n.url,t).then((function(e){var n=e.status;if(r=e,200>n||n>=("manual"===t.redirect?400:300))throw Error(e.statusText);return e.json()})).then((function(t){return d(e,t,r)})).catch((function(t){if("AbortError"!==t.name)return v(e,t,r)}))},J=function(e,t){var r=["query="+encodeURIComponent(t.query)];return t.variables&&r.push("variables="+encodeURIComponent(JSON.stringify(t.variables))),e+"?"+r.join("&")};function U(){return!1}function K(e){}var V=function(t){return e.filter(U)(e.tap(K)(t))},W=function(e){return 1===e.length?e[0]:function(t){return e.reduceRight((function(e,r){return r({client:t.client,forward:e})}),t.forward)}},z=[C,A,G],B=function(t){var n=this;this.activeOperations=Object.create(null),this.createOperationContext=function(e){return r({},{url:n.url,fetchOptions:n.fetchOptions,fetch:n.fetch,preferGetMethod:n.preferGetMethod},e,{requestPolicy:(e||{}).requestPolicy||n.requestPolicy})},this.createRequestOperation=function(e,t,r){return{key:t.key,query:t.query,variables:t.variables,operationName:e,context:n.createOperationContext(r)}},this.reexecuteOperation=function(e){0<(n.activeOperations[e.key]||0)&&n.dispatchOperation(e)},this.executeQuery=function(t,r){t=n.createRequestOperation("query",t,r);var o=n.executeRequestOperation(t);return(t=t.context.pollInterval)?e.switchMap((function(){return o}))(e.merge([e.fromValue(0),e.interval(t)])):o},this.executeSubscription=function(e,t){return e=n.createRequestOperation("subscription",e,t),n.executeRequestOperation(e)},this.executeMutation=function(e,t){return e=n.createRequestOperation("mutation",e,t),n.executeRequestOperation(e)},this.url=t.url,this.fetchOptions=t.fetchOptions,this.fetch=t.fetch,this.suspense=!!t.suspense,this.requestPolicy=t.requestPolicy||"cache-first",this.preferGetMethod=!!t.preferGetMethod,this.maskTypename=!!t.maskTypename;var o=e.makeSubject(),i=o.next;this.operations$=o.source;var a=[],u=!1;this.dispatchOperation=function(e){if(a.push(e),!u){for(u=!0;void 0!==(e=a.shift());)i(e);u=!1}},this.exchange=W(void 0!==t.exchanges?t.exchanges:z),this.results$=e.share(this.exchange({client:this,forward:V})(this.operations$)),e.publish(this.results$)};function H(e){return e.data=E(e.data),e}B.prototype.onOperationStart=function(e){var t=e.key;this.activeOperations[t]=(this.activeOperations[t]||0)+1,this.dispatchOperation(e)},B.prototype.onOperationEnd=function(e){var t=e.key,n=this.activeOperations[t]||0;0>=(this.activeOperations[t]=0>=n?0:n-1)&&this.dispatchOperation(r({},e,{operationName:"teardown"}))},B.prototype.executeRequestOperation=function(t){var r=this,n=t.key,o=t.operationName,i=e.filter((function(e){return e.operation.key===n}))(this.results$);if(this.maskTypename&&(i=e.map(H)(i)),"mutation"===o)return e.take(1)(e.onStart((function(){return r.dispatchOperation(t)}))(i));var a=e.filter((function(e){return"teardown"===e.operationName&&e.key===n}))(this.operations$);return i=e.onEnd((function(){r.onOperationEnd(t)}))(e.onStart((function(){r.onOperationStart(t)}))(e.takeUntil(a)(i))),!1!==t.context.suspense&&this.suspense&&"query"===o?function(t){return function(r){var n=e.share(t),o=!1,i=!1;if(e.onPush((function(){return o=!0}))(e.takeWhile((function(){return!i}))(n))(r),!o)throw i=!0,r(0),e.toPromise(e.take(1)(n))}}(i):i},B.prototype.query=function(e,t,n){return n&&"boolean"==typeof n.suspense||(n=r({},n,{suspense:!1})),w(this.executeQuery(h(e,t),n))},B.prototype.readQuery=function(t,r,n){var o=null;return e.subscribe((function(e){o=e}))(this.executeQuery(h(t,r),n)).unsubscribe(),o},B.prototype.mutation=function(e,t,r){return w(this.executeMutation(h(e,t),r))},exports.Client=B,exports.CombinedError=i,exports.cacheExchange=A,exports.composeExchanges=W,exports.createClient=function(e){return new B(e)},exports.createRequest=h,exports.debugExchange=function(e){var t=e.forward;return function(e){return t(e)}},exports.dedupExchange=C,exports.defaultExchanges=z,exports.fallbackExchangeIO=V,exports.fetchExchange=G,exports.formatDocument=b,exports.makeErrorResult=v,exports.makeResult=d,exports.maskTypename=E,exports.ssrExchange=function(t){function n(e){return!f(e)}function o(e){return function(e,t){var r=t.error;return{operation:e,data:t.data,extensions:void 0,error:r?new i({networkError:r.networkError?Error(r.networkError):void 0,graphQLErrors:r.graphQLErrors&&r.graphQLErrors.length?r.graphQLErrors:void 0}):void 0}}(e,s[e.key])}function a(e){return f(e)}function u(e){var t=e.operation;q(t)||(e=function(e){var t=e.error;return e={data:e.data,error:void 0},t&&(e.error={graphQLErrors:t.graphQLErrors.map(N),networkError:t.networkError?""+t.networkError:void 0}),e}(e),s[t.key]=e)}function c(e){delete s[e.operation.key]}var s={},f=function(e){return!q(e)&&void 0!==s[e.key]},p=function(r){var i=r.client,s=r.forward;return function(r){var f=t&&"boolean"==typeof t.isClient?!!t.isClient:!i.suspense,p=e.share(r);return r=s(e.filter(n)(p)),p=e.map(o)(e.filter(a)(p)),f?p=e.tap(c)(p):r=e.tap(u)(r),e.merge([r,p])}};return p.restoreData=function(e){return r(s,e)},p.extractData=function(){return r({},s)},t&&t.initialState&&p.restoreData(t.initialState),p},exports.stringifyVariables=f,exports.subscriptionExchange=function(n){function o(e){return"subscription"===(e=e.operationName)||!!a&&("query"===e||"mutation"===e)}var i=n.forwardSubscription,a=n.enableAllOperations;return function(n){function a(e){return!f(e)}var u=n.client,c=n.forward,s=function(n){var o=i({key:n.key.toString(36),query:t.print(n.query),variables:n.variables,context:r({},n.context)});return e.make((function(e){function t(e){return s(d(n,e))}function i(e){return s(v(n,e))}function a(){p||(p=!0,"subscription"===n.operationName&&u.reexecuteOperation(r({},n,{operationName:"teardown"})),f())}var c,s=e.next,f=e.complete,p=!1;return Promise.resolve().then((function(){p||(c=o.subscribe({next:t,error:i,complete:a}))})),function(){p=!0,c&&c.unsubscribe()}}))},f=o;return function(t){var r=e.share(t);t=e.mergeMap((function(t){var n=t.key,o=e.filter((function(e){return"teardown"===e.operationName&&e.key===n}))(r);return e.takeUntil(o)(s(t))}))(e.filter(f)(r));var n=c(e.filter(a)(r));return e.merge([t,n])}}}; | ||
"use strict";var e=require("wonka"),t=require("graphql");function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r,n=arguments[t];for(r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(e){return"string"==typeof e?new t.GraphQLError(e):"object"==typeof e&&e.message?new t.GraphQLError(e.message,e.nodes,e.source,e.positions,e.path,e,e.extensions||{}):e};function o(){return this.message}var i=function(e){function t(t){var r=t.networkError,o=t.response,i=function(e,t){var r="";return void 0!==e?r="[Network] "+e.message:(void 0!==t&&t.forEach((function(e){r+="[GraphQL] "+e.message+"\n"})),r.trim())}(r,t=(t.graphQLErrors||[]).map(n));e.call(this,i),this.name="CombinedError",this.message=i,this.graphQLErrors=t,this.networkError=r,this.response=o}return e&&(t.__proto__=e),(t.prototype=Object.create(e&&e.prototype)).constructor=t,t.prototype.toString=o,t}(Error),a=function(e,t){e|=0;for(var r=0,n=0|t.length;r<n;r++)e=(e<<5)+e+t.charCodeAt(r);return e},u=new Set,c=new WeakMap,s=function(e){if(null===e||u.has(e))return"null";if("object"!=typeof e)return JSON.stringify(e)||"";if(e.toJSON)return e.toJSON();if(Array.isArray(e)){for(var t="[",r=0,n=e.length;r<n;r++){0<r&&(t+=",");var o=s(e[r]);t+=0<o.length?o:"null"}return t+"]"}if(!(t=Object.keys(e).sort()).length&&e.constructor&&e.constructor!==Object)return t=c.get(e)||Math.random().toString(36).slice(2),c.set(e,t),'{"__key":"'+t+'"}';for(u.add(e),r="{",n=0,o=t.length;n<o;n++){var i=t[n],a=s(e[i]);a&&(1<r.length&&(r+=","),r+=s(i)+":"+a)}return u.delete(e),r+"}"},f=function(e){return u.clear(),s(e)},p=function(e){return function(e){return a(5381,e)>>>0}(e.replace(/[\s,]+/g," ").trim())},l=Object.create(null),h=function(e,r){if("string"==typeof e){var n=p(e);e=void 0!==l[n]?l[n]:t.parse(e)}else void 0!==e.__key?n=e.__key:(n=p(t.print(e)),e=void 0!==l[n]?l[n]:e);return l[n]=e,e.__key=n,{key:r?a(n,f(r))>>>0:n,query:e,variables:r||{}}},y=function(e,t){return r({},e,{context:r({},e.context,{meta:r({},e.context.meta,t)})})},d=function(e,t,r){return{operation:e,data:t.data,error:Array.isArray(t.errors)?new i({graphQLErrors:t.errors,response:r}):void 0,extensions:"object"==typeof t.extensions&&t.extensions||void 0}},v=function(e,t,r){return{operation:e,data:void 0,error:new i({networkError:t,response:r}),extensions:void 0}},m=function(e,t){if(void 0===t&&(t=[]),Array.isArray(e))e.forEach((function(e){m(e,t)}));else if("object"==typeof e&&null!==e)for(var r in e){var n=e[r];"__typename"===r&&"string"==typeof n?t.push(n):m(n,t)}return t};function x(e,t,r){return r.indexOf(e)===t}var g=function(e){return m(e).filter(x)};function k(e){return e.kind===t.Kind.FIELD&&"__typename"===e.name.value}var O=function(e){return!!e.selectionSet&&(function(e){return e.selections.some(k)}(e.selectionSet)?void 0:(e.selectionSet.selections.push({kind:t.Kind.FIELD,name:{kind:t.Kind.NAME,value:"__typename"}}),e))},b=function(e){return t.visit(e,{Field:O,InlineFragment:O})},E=function(e){return e&&"object"==typeof e?Object.keys(e).reduce((function(t,r){var n=e[r];return"__typename"===r?Object.defineProperty(t,"__typename",{enumerable:!1,value:n}):t[r]=Array.isArray(n)?n.map(E):n&&"object"==typeof n&&"__typename"in n?E(n):n,t}),{}):e};function q(t){return t.toPromise=function(){return e.toPromise(e.take(1)(t))},t}var w=function(e){return"subscription"!==(e=e.operationName)&&"query"!==e};function N(e){return e.path||e.extensions?{message:e.message,path:e.path,extensions:e.extensions}:e.message}var S=function(e){return"mutation"!==(e=e.operationName)&&"query"!==e};function _(e){return r({},e,{query:b(e.query)})}function j(e){return"query"!==e.operationName||"cache-only"!==e.context.requestPolicy}function P(e){return y(e,{cacheOutcome:"miss"})}function Q(e){return S(e)}var A=function(t){function n(e){var t=s.get(e.key);return t=r({},t,{operation:y(e,{cacheOutcome:t?"hit":"miss"})}),"cache-and-network"===e.context.requestPolicy&&(t.stale=!0,R(c,e)),t}function o(e){return!S(e)&&h(e)}function i(e){e.operation&&"mutation"===e.operation.operationName?p(e):e.operation&&"query"===e.operation.operationName&&l(e)}function a(e){return!S(e)&&!h(e)}var u=t.forward,c=t.client,s=new Map;t=Object.create(null);var f=_,p=L(s,t,c),l=M(s,t),h=function(e){var t=e.context.requestPolicy;return"query"===e.operationName&&"network-only"!==t&&("cache-only"===t||s.has(e.key))};return function(t){var r=e.share(t);return t=e.map(n)(e.filter(o)(r)),r=e.tap(i)(u(e.filter(j)(e.map(P)(e.merge([e.map(f)(e.filter(a)(r)),e.filter(Q)(r)]))))),e.merge([t,r])}},R=function(e,t){return e.reexecuteOperation(r({},t,{context:r({},t.context,{requestPolicy:"network-only"})}))},L=function(e,t,r){function n(t){if(e.has(t)){var n=e.get(t).operation;e.delete(t),R(r,n)}}return function(e){function r(e){o.add(e)}var o=new Set,i=e.operation.context.additionalTypenames;g(e.data).concat(i||[]).forEach((function(e){(e=t[e]||(t[e]=new Set)).forEach(r),e.clear()})),o.forEach(n)}},M=function(e,t){return function(r){var n=r.operation,o=r.data,i=n.context.additionalTypenames;null!=o&&(e.set(n.key,{operation:n,data:o,error:r.error}),g(r.data).concat(i||[]).forEach((function(e){(t[e]||(t[e]=new Set)).add(n.key)})))}},C=function(t){var r=t.forward,n=new Set,o=function(e){var t=e.key;return"teardown"===(e=e.operationName)?(n.delete(t),!0):"query"!==e&&"subscription"!==e||(e=n.has(t),n.add(t),!e)},i=function(e){n.delete(e.operation.key)};return function(t){return t=e.filter(o)(t),e.tap(i)(r(t))}};function I(e){return"query"===e.operationName||"mutation"===e.operationName}function T(e){return"query"!==e.operationName&&"mutation"!==e.operationName}var G=function(t){var r=t.forward;return function(t){var n=e.share(t);t=e.mergeMap((function(t){var r=t.key,o=e.filter((function(e){return"teardown"===e.operationName&&e.key===r}))(n);return e.takeUntil(o)($(t,"query"===t.operationName&&!!t.context.preferGetMethod))}))(e.filter(I)(n));var o=r(e.filter(T)(n));return e.merge([t,o])}};function D(e){return e.kind===t.Kind.OPERATION_DEFINITION&&e.name}var $=function(n,o){return e.make((function(e){var i=e.next,a=e.complete,u="undefined"!=typeof AbortController?new AbortController:void 0;e="function"==typeof(e=n.context).fetchOptions?e.fetchOptions():e.fetchOptions||{};var c=function(e){return(e=e.definitions.find(D))?e.name.value:null}(n.query),s={query:t.print(n.query),variables:n.variables};null!==c&&(s.operationName=c);var f=r({},e,{body:o?void 0:JSON.stringify(s),method:o?"GET":"POST",headers:r({},{"content-type":"application/json"},e.headers),signal:void 0!==u?u.signal:void 0});o&&(n.context.url=J(n.context.url,s));var p=!1;return Promise.resolve().then((function(){return p?void 0:F(n,f)})).then((function(e){p||(p=!0,e&&i(e),a())})),function(){p=!0,void 0!==u&&u.abort()}}))},F=function(e,t){var r,n=e.context;return(n.fetch||fetch)(n.url,t).then((function(e){var n=e.status;if(r=e,200>n||n>=("manual"===t.redirect?400:300))throw Error(e.statusText);return e.json()})).then((function(t){return d(e,t,r)})).catch((function(t){if("AbortError"!==t.name)return v(e,t,r)}))},J=function(e,t){var r=["query="+encodeURIComponent(t.query)];return t.variables&&r.push("variables="+encodeURIComponent(JSON.stringify(t.variables))),e+"?"+r.join("&")};function U(){return!1}function K(e){}var V=function(t){return e.filter(U)(e.tap(K)(t))},W=function(e){return 1===e.length?e[0]:function(t){return e.reduceRight((function(e,r){return r({client:t.client,forward:e})}),t.forward)}},z=[C,A,G],B=function(t){var n=this;this.activeOperations=Object.create(null),this.queue=[],this.createOperationContext=function(e){return r({},{url:n.url,fetchOptions:n.fetchOptions,fetch:n.fetch,preferGetMethod:n.preferGetMethod},e,{requestPolicy:(e||{}).requestPolicy||n.requestPolicy})},this.createRequestOperation=function(e,t,r){return{key:t.key,query:t.query,variables:t.variables,operationName:e,context:n.createOperationContext(r)}},this.reexecuteOperation=function(e){0<(n.activeOperations[e.key]||0)&&(n.queue.push(e),n.dispatchOperation())},this.executeQuery=function(t,r){t=n.createRequestOperation("query",t,r);var o=n.executeRequestOperation(t);return(t=t.context.pollInterval)?e.switchMap((function(){return o}))(e.merge([e.fromValue(0),e.interval(t)])):o},this.executeSubscription=function(e,t){return e=n.createRequestOperation("subscription",e,t),n.executeRequestOperation(e)},this.executeMutation=function(e,t){return e=n.createRequestOperation("mutation",e,t),n.executeRequestOperation(e)},this.url=t.url,this.fetchOptions=t.fetchOptions,this.fetch=t.fetch,this.suspense=!!t.suspense,this.requestPolicy=t.requestPolicy||"cache-first",this.preferGetMethod=!!t.preferGetMethod,this.maskTypename=!!t.maskTypename;var o=e.makeSubject(),i=o.next;this.operations$=o.source;var a=!1;this.dispatchOperation=function(e){if(e&&i(e),!a){for(a=!0;e=n.queue.shift();)i(e);a=!1}},this.exchange=W(void 0!==t.exchanges?t.exchanges:z),this.results$=e.share(this.exchange({client:this,forward:V})(this.operations$)),e.publish(this.results$)};function H(e){return e.data=E(e.data),e}B.prototype.onOperationStart=function(e){var t=e.key;this.activeOperations[t]=(this.activeOperations[t]||0)+1,this.dispatchOperation(e)},B.prototype.onOperationEnd=function(e){var t=e.key,n=this.activeOperations[t]||0;0>=(this.activeOperations[t]=0>=n?0:n-1)&&this.dispatchOperation(r({},e,{operationName:"teardown"}))},B.prototype.executeRequestOperation=function(t){var r=this,n=t.key,o=t.operationName,i=e.filter((function(e){return e.operation.key===n}))(this.results$);if(this.maskTypename&&(i=e.map(H)(i)),"mutation"===o)return e.take(1)(e.onStart((function(){return r.dispatchOperation(t)}))(i));var a=e.filter((function(e){return"teardown"===e.operationName&&e.key===n}))(this.operations$);return i=e.onEnd((function(){r.onOperationEnd(t)}))(e.onStart((function(){r.onOperationStart(t)}))(e.takeUntil(a)(i))),!1!==t.context.suspense&&this.suspense&&"query"===o?function(t){return function(r){var n=e.share(t),o=!1,i=!1;if(e.onPush((function(){return o=!0}))(e.takeWhile((function(){return!i}))(n))(r),!o)throw i=!0,r(0),e.toPromise(e.take(1)(n))}}(i):i},B.prototype.query=function(e,t,n){return n&&"boolean"==typeof n.suspense||(n=r({},n,{suspense:!1})),q(this.executeQuery(h(e,t),n))},B.prototype.readQuery=function(t,r,n){var o=null;return e.subscribe((function(e){o=e}))(this.executeQuery(h(t,r),n)).unsubscribe(),o},B.prototype.mutation=function(e,t,r){return q(this.executeMutation(h(e,t),r))},exports.Client=B,exports.CombinedError=i,exports.cacheExchange=A,exports.composeExchanges=W,exports.createClient=function(e){return new B(e)},exports.createRequest=h,exports.debugExchange=function(e){var t=e.forward;return function(e){return t(e)}},exports.dedupExchange=C,exports.defaultExchanges=z,exports.fallbackExchangeIO=V,exports.fetchExchange=G,exports.formatDocument=b,exports.makeErrorResult=v,exports.makeResult=d,exports.maskTypename=E,exports.ssrExchange=function(t){function n(e){return!f(e)}function o(e){return function(e,t){var r=t.error;return{operation:e,data:t.data,extensions:void 0,error:r?new i({networkError:r.networkError?Error(r.networkError):void 0,graphQLErrors:r.graphQLErrors&&r.graphQLErrors.length?r.graphQLErrors:void 0}):void 0}}(e,s[e.key])}function a(e){return f(e)}function u(e){var t=e.operation;w(t)||(e=function(e){var t=e.error;return e={data:e.data,error:void 0},t&&(e.error={graphQLErrors:t.graphQLErrors.map(N),networkError:t.networkError?""+t.networkError:void 0}),e}(e),s[t.key]=e)}function c(e){delete s[e.operation.key]}var s={},f=function(e){return!w(e)&&void 0!==s[e.key]},p=function(r){var i=r.client,s=r.forward;return function(r){var f=t&&"boolean"==typeof t.isClient?!!t.isClient:!i.suspense,p=e.share(r);return r=s(e.filter(n)(p)),p=e.map(o)(e.filter(a)(p)),f?p=e.tap(c)(p):r=e.tap(u)(r),e.merge([r,p])}};return p.restoreData=function(e){return r(s,e)},p.extractData=function(){return r({},s)},t&&t.initialState&&p.restoreData(t.initialState),p},exports.stringifyVariables=f,exports.subscriptionExchange=function(n){function o(e){return"subscription"===(e=e.operationName)||!!a&&("query"===e||"mutation"===e)}var i=n.forwardSubscription,a=n.enableAllOperations;return function(n){function a(e){return!f(e)}var u=n.client,c=n.forward,s=function(n){var o=i({key:n.key.toString(36),query:t.print(n.query),variables:n.variables,context:r({},n.context)});return e.make((function(e){function t(e){return s(d(n,e))}function i(e){return s(v(n,e))}function a(){p||(p=!0,"subscription"===n.operationName&&u.reexecuteOperation(r({},n,{operationName:"teardown"})),f())}var c,s=e.next,f=e.complete,p=!1;return Promise.resolve().then((function(){p||(c=o.subscribe({next:t,error:i,complete:a}))})),function(){p=!0,c&&c.unsubscribe()}}))},f=o;return function(t){var r=e.share(t);t=e.mergeMap((function(t){var n=t.key,o=e.filter((function(e){return"teardown"===e.operationName&&e.key===n}))(r);return e.takeUntil(o)(s(t))}))(e.filter(f)(r));var n=c(e.filter(a)(r));return e.merge([t,n])}}}; | ||
//# sourceMappingURL=urql-core.min.js.map |
{ | ||
"name": "@urql/core", | ||
"version": "1.10.5", | ||
"version": "1.10.6", | ||
"description": "The shared core for the highly customizable and versatile GraphQL client", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1743
295597