@urql/exchange-retry
Advanced tools
Comparing version 0.2.1 to 0.3.0
# Changelog | ||
## 0.3.0 | ||
### Minor Changes | ||
- Add a new `retryWith` option which allows operations to be updated when a request is being retried, by [@kitten](https://github.com/kitten) (See [#1881](https://github.com/FormidableLabs/urql/pull/1881)) | ||
### Patch Changes | ||
- Updated dependencies (See [#1870](https://github.com/FormidableLabs/urql/pull/1870) and [#1880](https://github.com/FormidableLabs/urql/pull/1880)) | ||
- @urql/core@2.3.1 | ||
## 0.2.1 | ||
@@ -4,0 +15,0 @@ |
@@ -9,3 +9,5 @@ import { Exchange, Operation, CombinedError } from '@urql/core'; | ||
retryIf?: (error: CombinedError, operation: Operation) => boolean; | ||
/** Conditionally update operations as they're retried (retryIf can be replaced with this) */ | ||
retryWith?: (error: CombinedError, operation: Operation) => Operation | null | undefined; | ||
} | ||
export declare const retryExchange: ({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf: retryIfOption, }: RetryExchangeOptions) => Exchange; | ||
export declare const retryExchange: ({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf, retryWith, }: RetryExchangeOptions) => Exchange; |
@@ -20,52 +20,55 @@ var r = require("wonka"); | ||
exports.retryExchange = function retryExchange(t) { | ||
var a = t.initialDelayMs || 1e3; | ||
var n = t.maxDelayMs || 15e3; | ||
var o = t.maxNumberAttempts || 2; | ||
var i = t.randomDelay || !0; | ||
var u = t.retryIf || function(r) { | ||
return r && r.networkError; | ||
}; | ||
var a = t.retryIf; | ||
var n = t.retryWith; | ||
var o = t.initialDelayMs || 1e3; | ||
var i = t.maxDelayMs || 15e3; | ||
var u = t.maxNumberAttempts || 2; | ||
var s = t.randomDelay || !0; | ||
return function(t) { | ||
var s = t.forward; | ||
var c = t.dispatchDebug; | ||
var c = t.forward; | ||
var y = t.dispatchDebug; | ||
return function(t) { | ||
var y = r.share(t); | ||
var v = r.share(t); | ||
var p = r.makeSubject(); | ||
var v = p.source; | ||
var f = p.next; | ||
var d = r.mergeMap((function(t) { | ||
var u = t.key; | ||
var s = t.context; | ||
var p = (s.retryCount || 0) + 1; | ||
var v = s.retryDelay || a; | ||
var f = p.source; | ||
var d = p.next; | ||
var h = r.mergeMap((function(t) { | ||
var a = t.key; | ||
var n = t.context; | ||
var c = (n.retryCount || 0) + 1; | ||
var p = n.retryDelay || o; | ||
var f = Math.random() + 1.5; | ||
if (i && v * f < n) { | ||
v *= f; | ||
if (s && p * f < i) { | ||
p *= f; | ||
} | ||
var d = r.filter((function(r) { | ||
return ("query" === r.kind || "teardown" === r.kind) && r.key === u; | ||
}))(y); | ||
"production" !== process.env.NODE_ENV && c({ | ||
return ("query" === r.kind || "teardown" === r.kind) && r.key === a; | ||
}))(v); | ||
"production" !== process.env.NODE_ENV && y({ | ||
type: "retryAttempt", | ||
message: "The operation has failed and a retry has been triggered (" + p + " / " + o + ")", | ||
message: "The operation has failed and a retry has been triggered (" + c + " / " + u + ")", | ||
operation: t, | ||
data: { | ||
retryCount: p | ||
retryCount: c | ||
}, | ||
source: "retryExchange" | ||
}); | ||
return r.takeUntil(d)(r.delay(v)(r.fromValue(e.makeOperation(t.kind, t, _extends({}, t.context, { | ||
retryDelay: v, | ||
retryCount: p | ||
return r.takeUntil(d)(r.delay(p)(r.fromValue(e.makeOperation(t.kind, t, _extends({}, t.context, { | ||
retryDelay: p, | ||
retryCount: c | ||
}))))); | ||
}))(v); | ||
}))(f); | ||
return r.filter((function(r) { | ||
if (!r.error || !u(r.error, r.operation)) { | ||
if (!(r.error && (a ? a(r.error, r.operation) : n || r.error.networkError))) { | ||
return !0; | ||
} | ||
if (!((r.operation.context.retryCount || 0) >= o - 1)) { | ||
f(r.operation); | ||
if (!((r.operation.context.retryCount || 0) >= u - 1)) { | ||
var e = n ? n(r.error, r.operation) : r.operation; | ||
if (!e) { | ||
return !0; | ||
} | ||
d(e); | ||
return !1; | ||
} | ||
"production" !== process.env.NODE_ENV && c({ | ||
"production" !== process.env.NODE_ENV && y({ | ||
type: "retryExhausted", | ||
@@ -77,3 +80,3 @@ message: "Maximum number of retries has been reached. No further retries will be performed.", | ||
return !0; | ||
}))(r.share(s(r.merge([ y, d ])))); | ||
}))(r.share(c(r.merge([ v, h ])))); | ||
}; | ||
@@ -80,0 +83,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
var r=require("wonka"),e=require("@urql/core");function t(){return(t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}exports.retryExchange=function(n){var a=n.initialDelayMs||1e3,o=n.maxDelayMs||15e3,u=n.maxNumberAttempts||2,i=n.randomDelay||!0,c=n.retryIf||function(r){return r&&r.networkError};return function(n){var y=n.forward;return function(n){var f=r.share(n),l=r.makeSubject(),p=l.source,m=l.next,s=r.mergeMap((function(n){var u=n.key,c=n.context,y=(c.retryCount||0)+1,l=c.retryDelay||a,p=Math.random()+1.5;i&&l*p<o&&(l*=p);var m=r.filter((function(r){return("query"===r.kind||"teardown"===r.kind)&&r.key===u}))(f);return r.takeUntil(m)(r.delay(l)(r.fromValue(e.makeOperation(n.kind,n,t({},n.context,{retryDelay:l,retryCount:y})))))}))(p);return r.filter((function(r){return!(r.error&&c(r.error,r.operation)&&!((r.operation.context.retryCount||0)>=u-1)&&(m(r.operation),1))}))(r.share(y(r.merge([f,s]))))}}}; | ||
var r=require("wonka"),e=require("@urql/core");function t(){return(t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}exports.retryExchange=function(n){var o=n.retryIf,a=n.retryWith,i=n.initialDelayMs||1e3,u=n.maxDelayMs||15e3,y=n.maxNumberAttempts||2,c=n.randomDelay||!0;return function(n){var f=n.forward;return function(n){var l=r.share(n),p=r.makeSubject(),m=p.source,s=p.next,k=r.mergeMap((function(n){var o=n.key,a=n.context,y=(a.retryCount||0)+1,f=a.retryDelay||i,p=Math.random()+1.5;c&&f*p<u&&(f*=p);var m=r.filter((function(r){return("query"===r.kind||"teardown"===r.kind)&&r.key===o}))(l);return r.takeUntil(m)(r.delay(f)(r.fromValue(e.makeOperation(n.kind,n,t({},n.context,{retryDelay:f,retryCount:y})))))}))(m);return r.filter((function(r){if(!r.error||!(o?o(r.error,r.operation):a||r.error.networkError))return!0;if(!((r.operation.context.retryCount||0)>=y-1)){var e=a?a(r.error,r.operation):r.operation;return!e||(s(e),!1)}return!0}))(r.share(f(r.merge([l,k]))))}}}; | ||
//# sourceMappingURL=urql-exchange-retry.min.js.map |
{ | ||
"name": "@urql/exchange-retry", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "An exchange for operation retry support in urql", | ||
@@ -59,3 +59,3 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@urql/core": ">=2.1.0", | ||
"@urql/core": ">=2.3.1", | ||
"wonka": "^4.0.14" | ||
@@ -62,0 +62,0 @@ }, |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39634
186
1
Updated@urql/core@>=2.3.1