@urql/core
Advanced tools
Comparing version 1.10.4 to 1.10.5
# @urql/core | ||
## 1.10.5 | ||
### Patch Changes | ||
- Refactor a couple of core helpers for minor bundlesize savings, by [@kitten](https://github.com/kitten) (See [#658](https://github.com/FormidableLabs/urql/pull/658)) | ||
- Add support for variables that contain non-plain objects without any enumerable keys, e.g. `File` or `Blob`. In this case `stringifyVariables` will now use a stable (but random) key, which means that mutations containing `File`s — or other objects like this — will now be distinct, as they should be, by [@kitten](https://github.com/kitten) (See [#650](https://github.com/FormidableLabs/urql/pull/650)) | ||
## 1.10.4 | ||
@@ -4,0 +11,0 @@ |
import { DocumentNode } from 'graphql'; | ||
export declare const collectTypesFromResponse: (response: object) => string[]; | ||
export declare const formatDocument: (astNode: DocumentNode) => any; | ||
export declare const formatDocument: (node: DocumentNode) => any; |
@@ -55,15 +55,9 @@ "use strict"; | ||
return a; | ||
}, seen = new Set, stringify = function(a) { | ||
if (void 0 === a) { | ||
return ""; | ||
}, seen = new Set, cache = new WeakMap, stringify = function(a) { | ||
if (null === a || seen.has(a)) { | ||
return "null"; | ||
} | ||
if ("number" == typeof a) { | ||
return isFinite(a) ? "" + a : "null"; | ||
} | ||
if ("object" != typeof a) { | ||
return JSON.stringify(a); | ||
return JSON.stringify(a) || ""; | ||
} | ||
if (null === a) { | ||
return "null"; | ||
} | ||
if (a.toJSON) { | ||
@@ -73,4 +67,3 @@ return a.toJSON(); | ||
if (Array.isArray(a)) { | ||
var b = "["; | ||
for (var c = 0, d = a.length; c < d; c++) { | ||
for (var b = "[", c = 0, d = a.length; c < d; c++) { | ||
0 < c && (b += ","); | ||
@@ -82,15 +75,15 @@ var f = stringify(a[c]); | ||
} | ||
if (seen.has(a)) { | ||
throw new TypeError("Converting circular structure to JSON"); | ||
if (!(b = Object.keys(a).sort()).length && a.constructor && a.constructor !== Object) { | ||
return b = cache.get(a) || Math.random().toString(36).slice(2), cache.set(a, b), | ||
'{"__key":"' + b + '"}'; | ||
} | ||
c = Object.keys(a).sort(); | ||
seen.add(a); | ||
b = "{"; | ||
c = "{"; | ||
d = 0; | ||
for (f = c.length; d < f; d++) { | ||
var g = c[d], e = stringify(a[g]); | ||
0 !== e.length && (1 < b.length && (b += ","), b += stringify(g) + ":" + e); | ||
for (f = b.length; d < f; d++) { | ||
var g = b[d], e = stringify(a[g]); | ||
e && (1 < c.length && (c += ","), c += stringify(g) + ":" + e); | ||
} | ||
seen.delete(a); | ||
return b + "}"; | ||
return c + "}"; | ||
}, stringifyVariables = function(a) { | ||
@@ -131,3 +124,3 @@ seen.clear(); | ||
}) : void 0, | ||
extensions: "object" == typeof b.extensions && null !== b.extensions ? b.extensions : void 0 | ||
extensions: "object" == typeof b.extensions && b.extensions || void 0 | ||
}; | ||
@@ -152,6 +145,4 @@ }, makeErrorResult = function(a, b, c) { | ||
for (var d in a) { | ||
if (Object.prototype.hasOwnProperty.call(a, d)) { | ||
var f = a[d]; | ||
"__typename" === d && "string" == typeof f ? b.push(f) : "object" == typeof f && null !== f && collectTypes(f, b); | ||
} | ||
var f = a[d]; | ||
"__typename" === d && "string" == typeof f ? b.push(f) : collectTypes(f, b); | ||
} | ||
@@ -171,17 +162,20 @@ } | ||
function _ref3(a) { | ||
return "Field" === a.kind && "__typename" === a.name.value; | ||
return a.kind === graphql.Kind.FIELD && "__typename" === a.name.value; | ||
} | ||
var formatNode = function(a) { | ||
return void 0 === a.selectionSet ? !1 : a.selectionSet.selections.some(_ref3) ? a : _extends({}, a, { | ||
selectionSet: _extends({}, a.selectionSet, { | ||
selections: a.selectionSet.selections.concat([ { | ||
kind: graphql.Kind.FIELD, | ||
name: { | ||
kind: graphql.Kind.NAME, | ||
value: "__typename" | ||
} | ||
} ]) | ||
}) | ||
}); | ||
if (!a.selectionSet) { | ||
return !1; | ||
} | ||
if (!function(a) { | ||
return a.selections.some(_ref3); | ||
}(a.selectionSet)) { | ||
return a.selectionSet.selections.push({ | ||
kind: graphql.Kind.FIELD, | ||
name: { | ||
kind: graphql.Kind.NAME, | ||
value: "__typename" | ||
} | ||
}), a; | ||
} | ||
}, formatDocument = function(a) { | ||
@@ -248,3 +242,3 @@ return graphql.visit(a, { | ||
function b(a) { | ||
var b = k.get(a.key); | ||
var b = h.get(a.key); | ||
b = _extends({}, b, { | ||
@@ -267,7 +261,7 @@ operation: addMetadata(a, { | ||
} | ||
var g = a.forward, e = a.client, k = new Map; | ||
var g = a.forward, e = a.client, h = new Map; | ||
a = Object.create(null); | ||
var h = _ref$1, l = afterMutation(k, a, e), m = afterQuery(k, a), n = function(a) { | ||
var k = _ref$1, l = afterMutation(h, a, e), m = afterQuery(h, a), n = function(a) { | ||
var c = a.context.requestPolicy; | ||
return "query" === a.operationName && "network-only" !== c && ("cache-only" === c || k.has(a.key)); | ||
return "query" === a.operationName && "network-only" !== c && ("cache-only" === c || h.has(a.key)); | ||
}; | ||
@@ -277,3 +271,3 @@ return function(a) { | ||
a = wonka.map(b)(wonka.filter(c)(e)); | ||
e = wonka.tap(d)(g(wonka.filter(_ref5)(wonka.map(_ref6)(wonka.merge([ wonka.map(h)(wonka.filter(f)(e)), wonka.filter(_ref8)(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 ]); | ||
@@ -349,20 +343,21 @@ }; | ||
function _ref$2(a) { | ||
return "query" === (a = a.operationName) || "mutation" === a; | ||
return "query" === a.operationName || "mutation" === a.operationName; | ||
} | ||
function _ref2$2(a) { | ||
return "query" !== a.operationName && "mutation" !== a.operationName; | ||
} | ||
var fetchExchange = function(a) { | ||
function b(a) { | ||
return !d(a); | ||
} | ||
var c = a.forward, d = _ref$2; | ||
var b = a.forward; | ||
return function(a) { | ||
var f = wonka.share(a); | ||
var c = wonka.share(a); | ||
a = wonka.mergeMap((function(a) { | ||
var b = a.key, c = wonka.filter((function(a) { | ||
var b = a.key, d = wonka.filter((function(a) { | ||
return "teardown" === a.operationName && a.key === b; | ||
}))(f); | ||
return wonka.takeUntil(c)(createFetchSource(a, "query" === a.operationName && !!a.context.preferGetMethod)); | ||
}))(wonka.filter(d)(f)); | ||
var e = c(wonka.filter(b)(f)); | ||
return wonka.merge([ a, e ]); | ||
}))(c); | ||
return wonka.takeUntil(d)(createFetchSource(a, "query" === a.operationName && !!a.context.preferGetMethod)); | ||
}))(wonka.filter(_ref$2)(c)); | ||
var f = b(wonka.filter(_ref2$2)(c)); | ||
return wonka.merge([ a, f ]); | ||
}; | ||
@@ -383,10 +378,10 @@ }; | ||
var e = function(a) { | ||
return void 0 !== (a = a.definitions.find(_ref3$2)) && a.name ? a.name.value : null; | ||
}(a.query), k = { | ||
return (a = a.definitions.find(_ref3$2)) ? a.name.value : null; | ||
}(a.query), h = { | ||
query: graphql.print(a.query), | ||
variables: a.variables | ||
}; | ||
null !== e && (k.operationName = e); | ||
var h = _extends({}, c, { | ||
body: b ? void 0 : JSON.stringify(k), | ||
null !== e && (h.operationName = e); | ||
var k = _extends({}, c, { | ||
body: b ? void 0 : JSON.stringify(h), | ||
method: b ? "GET" : "POST", | ||
@@ -398,6 +393,6 @@ headers: _extends({}, { | ||
}); | ||
b && (a.context.url = convertToGet(a.context.url, k)); | ||
b && (a.context.url = convertToGet(a.context.url, h)); | ||
var l = !1; | ||
Promise.resolve().then((function() { | ||
return l ? void 0 : executeFetch(a, h); | ||
return l ? void 0 : executeFetch(a, k); | ||
})).then((function(a) { | ||
@@ -437,3 +432,3 @@ l || (l = !0, a && d(a), f()); | ||
function _ref2$2(a) { | ||
function _ref2$3(a) { | ||
"teardown" !== (a = a.operationName) && "production" !== process.env.NODE_ENV && console.warn('No exchange has handled operations of type "' + a + "\". Check whether you've added an exchange responsible for these operations."); | ||
@@ -443,3 +438,3 @@ } | ||
var fallbackExchangeIO = function(a) { | ||
return wonka.filter(_ref$3)(wonka.tap(_ref2$2)(a)); | ||
return wonka.filter(_ref$3)(wonka.tap(_ref2$3)(a)); | ||
}, composeExchanges = function(a) { | ||
@@ -537,3 +532,3 @@ return 1 === a.length ? a[0] : function(b) { | ||
function _ref2$3(a) { | ||
function _ref2$4(a) { | ||
a.data = maskTypename(a.data); | ||
@@ -547,3 +542,3 @@ return a; | ||
}))(this.results$); | ||
this.maskTypename && (g = wonka.map(_ref2$3)(g)); | ||
this.maskTypename && (g = wonka.map(_ref2$4)(g)); | ||
if ("mutation" === f) { | ||
@@ -637,3 +632,3 @@ return wonka.take(1)(wonka.onStart((function b() { | ||
function b(a) { | ||
return !k(a); | ||
return !h(a); | ||
} | ||
@@ -655,3 +650,3 @@ function c(a) { | ||
function d(a) { | ||
return k(a); | ||
return h(a); | ||
} | ||
@@ -676,9 +671,9 @@ function f(a) { | ||
} | ||
var e = {}, k = function(a) { | ||
var e = {}, h = function(a) { | ||
return !shouldSkip(a) && void 0 !== e[a.key]; | ||
}, h = function(e) { | ||
var k = e.client, h = e.forward; | ||
}, k = function(e) { | ||
var h = e.client, k = e.forward; | ||
return function(e) { | ||
var p = a && "boolean" == typeof a.isClient ? !!a.isClient : !k.suspense, m = wonka.share(e); | ||
e = h(wonka.filter(b)(m)); | ||
var p = a && "boolean" == typeof a.isClient ? !!a.isClient : !h.suspense, m = wonka.share(e); | ||
e = k(wonka.filter(b)(m)); | ||
m = wonka.map(c)(wonka.filter(d)(m)); | ||
@@ -689,10 +684,10 @@ p ? m = wonka.tap(g)(m) : e = wonka.tap(f)(e); | ||
}; | ||
h.restoreData = function(a) { | ||
k.restoreData = function(a) { | ||
return _extends(e, a); | ||
}; | ||
h.extractData = function() { | ||
k.extractData = function() { | ||
return _extends({}, e); | ||
}; | ||
a && a.initialState && h.restoreData(a.initialState); | ||
return h; | ||
a && a.initialState && k.restoreData(a.initialState); | ||
return k; | ||
}; | ||
@@ -711,3 +706,3 @@ | ||
} | ||
var e = a.client, f = a.forward, h = function(a) { | ||
var e = a.client, f = a.forward, k = function(a) { | ||
var b = c({ | ||
@@ -721,15 +716,15 @@ key: a.key.toString(36), | ||
function d(b) { | ||
return k(makeResult(a, b)); | ||
return h(makeResult(a, b)); | ||
} | ||
function f(b) { | ||
return k(makeErrorResult(a, b)); | ||
return h(makeErrorResult(a, b)); | ||
} | ||
function g() { | ||
h || (h = !0, "subscription" === a.operationName && e.reexecuteOperation(_extends({}, a, { | ||
m || (m = !0, "subscription" === a.operationName && e.reexecuteOperation(_extends({}, a, { | ||
operationName: "teardown" | ||
})), m()); | ||
})), k()); | ||
} | ||
var l, k = c.next, m = c.complete, h = !1; | ||
var l, h = c.next, k = c.complete, m = !1; | ||
Promise.resolve().then((function() { | ||
h || (l = b.subscribe({ | ||
m || (l = b.subscribe({ | ||
next: d, | ||
@@ -741,3 +736,3 @@ error: f, | ||
return function() { | ||
h = !0; | ||
m = !0; | ||
l && l.unsubscribe(); | ||
@@ -753,3 +748,3 @@ }; | ||
}))(b); | ||
return wonka.takeUntil(d)(h(a)); | ||
return wonka.takeUntil(d)(k(a)); | ||
}))(wonka.filter(l)(b)); | ||
@@ -756,0 +751,0 @@ var c = f(wonka.filter(d)(b)); |
@@ -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=function(e){if(void 0===e)return"";if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);if(null===e)return"null";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=c(e[r]);t+=0<o.length?o:"null"}return t+"]"}if(u.has(e))throw new TypeError("Converting circular structure to JSON");for(r=Object.keys(e).sort(),u.add(e),t="{",n=0,o=r.length;n<o;n++){var i=r[n],a=c(e[i]);0!==a.length&&(1<t.length&&(t+=","),t+=c(i)+":"+a)}return u.delete(e),t+"}"},s=function(e){return u.clear(),c(e)},f=function(e){return function(e){return a(5381,e)>>>0}(e.replace(/[\s,]+/g," ").trim())},p=Object.create(null),l=function(e,r){if("string"==typeof e){var n=f(e);e=void 0!==p[n]?p[n]:t.parse(e)}else void 0!==e.__key?n=e.__key:(n=f(t.print(e)),e=void 0!==p[n]?p[n]:e);return p[n]=e,e.__key=n,{key:r?a(n,s(r))>>>0:n,query:e,variables:r||{}}},h=function(e,t){return r({},e,{context:r({},e.context,{meta:r({},e.context.meta,t)})})},y=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&&null!==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}},d=function(e,t){if(void 0===t&&(t=[]),Array.isArray(e))e.forEach((function(e){d(e,t)}));else if("object"==typeof e&&null!==e)for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var n=e[r];"__typename"===r&&"string"==typeof n?t.push(n):"object"==typeof n&&null!==n&&d(n,t)}return t};function m(e,t,r){return r.indexOf(e)===t}var x=function(e){return d(e).filter(m)};function g(e){return"Field"===e.kind&&"__typename"===e.name.value}var k=function(e){return void 0!==e.selectionSet&&(e.selectionSet.selections.some(g)?e:r({},e,{selectionSet:r({},e.selectionSet,{selections:e.selectionSet.selections.concat([{kind:t.Kind.FIELD,name:{kind:t.Kind.NAME,value:"__typename"}}])})}))},O=function(e){return t.visit(e,{Field:k,InlineFragment:k})},b=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(b):n&&"object"==typeof n&&"__typename"in n?b(n):n,t}),{}):e};function E(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 q(e){return e.path||e.extensions?{message:e.message,path:e.path,extensions:e.extensions}:e.message}var N=function(e){return"mutation"!==(e=e.operationName)&&"query"!==e};function S(e){return r({},e,{query:O(e.query)})}function _(e){return"query"!==e.operationName||"cache-only"!==e.context.requestPolicy}function j(e){return h(e,{cacheOutcome:"miss"})}function P(e){return N(e)}var Q=function(t){function n(e){var t=s.get(e.key);return t=r({},t,{operation:h(e,{cacheOutcome:t?"hit":"miss"})}),"cache-and-network"===e.context.requestPolicy&&(t.stale=!0,A(c,e)),t}function o(e){return!N(e)&&y(e)}function i(e){e.operation&&"mutation"===e.operation.operationName?p(e):e.operation&&"query"===e.operation.operationName&&l(e)}function a(e){return!N(e)&&!y(e)}var u=t.forward,c=t.client,s=new Map;t=Object.create(null);var f=S,p=R(s,t,c),l=C(s,t),y=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(_)(e.map(j)(e.merge([e.map(f)(e.filter(a)(r)),e.filter(P)(r)]))))),e.merge([t,r])}},A=function(e,t){return e.reexecuteOperation(r({},t,{context:r({},t.context,{requestPolicy:"network-only"})}))},R=function(e,t,r){function n(t){if(e.has(t)){var n=e.get(t).operation;e.delete(t),A(r,n)}}return function(e){function r(e){o.add(e)}var o=new Set,i=e.operation.context.additionalTypenames;x(e.data).concat(i||[]).forEach((function(e){(e=t[e]||(t[e]=new Set)).forEach(r),e.clear()})),o.forEach(n)}},C=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}),x(r.data).concat(i||[]).forEach((function(e){(t[e]||(t[e]=new Set)).add(n.key)})))}},L=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 M(e){return"query"===(e=e.operationName)||"mutation"===e}var T=function(t){function r(e){return!o(e)}var n=t.forward,o=M;return function(t){var i=e.share(t);t=e.mergeMap((function(t){var r=t.key,n=e.filter((function(e){return"teardown"===e.operationName&&e.key===r}))(i);return e.takeUntil(n)(G(t,"query"===t.operationName&&!!t.context.preferGetMethod))}))(e.filter(o)(i));var a=n(e.filter(r)(i));return e.merge([t,a])}};function I(e){return e.kind===t.Kind.OPERATION_DEFINITION&&e.name}var G=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 void 0!==(e=e.definitions.find(I))&&e.name?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=F(n.context.url,s));var p=!1;return Promise.resolve().then((function(){return p?void 0:D(n,f)})).then((function(e){p||(p=!0,e&&i(e),a())})),function(){p=!0,void 0!==u&&u.abort()}}))},D=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 y(e,t,r)})).catch((function(t){if("AbortError"!==t.name)return v(e,t,r)}))},F=function(e,t){var r=["query="+encodeURIComponent(t.query)];return t.variables&&r.push("variables="+encodeURIComponent(JSON.stringify(t.variables))),e+"?"+r.join("&")};function J(){return!1}function $(e){}var U=function(t){return e.filter(J)(e.tap($)(t))},K=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)}},V=[L,Q,T],W=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=K(void 0!==t.exchanges?t.exchanges:V),this.results$=e.share(this.exchange({client:this,forward:U})(this.operations$)),e.publish(this.results$)};function z(e){return e.data=b(e.data),e}W.prototype.onOperationStart=function(e){var t=e.key;this.activeOperations[t]=(this.activeOperations[t]||0)+1,this.dispatchOperation(e)},W.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"}))},W.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(z)(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},W.prototype.query=function(e,t,n){return n&&"boolean"==typeof n.suspense||(n=r({},n,{suspense:!1})),E(this.executeQuery(l(e,t),n))},W.prototype.readQuery=function(t,r,n){var o=null;return e.subscribe((function(e){o=e}))(this.executeQuery(l(t,r),n)).unsubscribe(),o},W.prototype.mutation=function(e,t,r){return E(this.executeMutation(l(e,t),r))},exports.Client=W,exports.CombinedError=i,exports.cacheExchange=Q,exports.composeExchanges=K,exports.createClient=function(e){return new W(e)},exports.createRequest=l,exports.debugExchange=function(e){var t=e.forward;return function(e){return t(e)}},exports.dedupExchange=L,exports.defaultExchanges=V,exports.fallbackExchangeIO=U,exports.fetchExchange=T,exports.formatDocument=O,exports.makeErrorResult=v,exports.makeResult=y,exports.maskTypename=b,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(q),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=s,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(y(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 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])}}}; | ||
//# sourceMappingURL=urql-core.min.js.map |
{ | ||
"name": "@urql/core", | ||
"version": "1.10.4", | ||
"version": "1.10.5", | ||
"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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
296163
1740