apollo-link-retry
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -5,2 +5,5 @@ # Change log | ||
### 2.2.3 | ||
- Update apollo-link [#559](https://github.com/apollographql/apollo-link/pull/559) | ||
### 2.2.2 | ||
@@ -7,0 +10,0 @@ - Fix a bug where `observer` is null during onComplete, onNext, onError [#528](https://github.com/apollographql/apollo-link/pull/528) |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) : | ||
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.retry = {}),global.apolloLink.core)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) : | ||
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.retry = {}),global.apolloLink.core)); | ||
}(this, (function (exports,apolloLink) { 'use strict'; | ||
function buildDelayFunction(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.initial, initial = _c === void 0 ? 300 : _c, _d = _b.max, max = _d === void 0 ? Infinity : _d, _e = _b.jitter, jitter = _e === void 0 ? true : _e; | ||
var baseDelay; | ||
if (jitter) { | ||
baseDelay = initial; | ||
} | ||
else { | ||
baseDelay = initial / 2; | ||
} | ||
return function delayFunction(count) { | ||
var delay = Math.min(max, baseDelay * Math.pow(2, count)); | ||
function buildDelayFunction(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.initial, initial = _c === void 0 ? 300 : _c, _d = _b.max, max = _d === void 0 ? Infinity : _d, _e = _b.jitter, jitter = _e === void 0 ? true : _e; | ||
var baseDelay; | ||
if (jitter) { | ||
delay = Math.random() * delay; | ||
// If we're jittering, baseDelay is half of the maximum delay for that | ||
// attempt (and is, on average, the delay we will encounter). | ||
baseDelay = initial; | ||
} | ||
return delay; | ||
}; | ||
} | ||
else { | ||
// If we're not jittering, adjust baseDelay so that the first attempt | ||
// lines up with initialDelay, for everyone's sanity. | ||
baseDelay = initial / 2; | ||
} | ||
return function delayFunction(count) { | ||
var delay = Math.min(max, baseDelay * Math.pow(2, count)); | ||
if (jitter) { | ||
// We opt for a full jitter approach for a mostly uniform distribution, | ||
// but bound it within initialDelay and delay for everyone's sanity. | ||
delay = Math.random() * delay; | ||
} | ||
return delay; | ||
}; | ||
} | ||
function buildRetryFunction(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.max, max = _c === void 0 ? 5 : _c, retryIf = _b.retryIf; | ||
return function retryFunction(count, operation, error) { | ||
if (count >= max) | ||
return false; | ||
return retryIf ? retryIf(error, operation) : !!error; | ||
}; | ||
} | ||
function buildRetryFunction(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.max, max = _c === void 0 ? 5 : _c, retryIf = _b.retryIf; | ||
return function retryFunction(count, operation, error) { | ||
if (count >= max) | ||
return false; | ||
return retryIf ? retryIf(error, operation) : !!error; | ||
}; | ||
} | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
})(); | ||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (undefined && undefined.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
var __generator = (undefined && undefined.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
/** | ||
* Tracking and management of operations that may be (or currently are) retried. | ||
*/ | ||
var RetryableOperation = /** @class */ (function () { | ||
function RetryableOperation(operation, nextLink, delayFor, retryIf) { | ||
var _this = this; | ||
this.operation = operation; | ||
this.nextLink = nextLink; | ||
this.delayFor = delayFor; | ||
this.retryIf = retryIf; | ||
this.retryCount = 0; | ||
this.values = []; | ||
this.complete = false; | ||
this.canceled = false; | ||
this.observers = []; | ||
this.currentSubscription = null; | ||
this.onNext = function (value) { | ||
_this.values.push(value); | ||
for (var _i = 0, _a = _this.observers; _i < _a.length; _i++) { | ||
var observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
observer.next(value); | ||
} | ||
}; | ||
this.onComplete = function () { | ||
_this.complete = true; | ||
for (var _i = 0, _a = _this.observers; _i < _a.length; _i++) { | ||
var observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
observer.complete(); | ||
} | ||
}; | ||
this.onError = function (error) { return __awaiter(_this, void 0, void 0, function () { | ||
var shouldRetry, _i, _a, observer; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
this.retryCount += 1; | ||
return [4 /*yield*/, this.retryIf(this.retryCount, this.operation, error)]; | ||
case 1: | ||
shouldRetry = _b.sent(); | ||
if (shouldRetry) { | ||
this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error)); | ||
return [2 /*return*/]; | ||
} | ||
this.error = error; | ||
for (_i = 0, _a = this.observers; _i < _a.length; _i++) { | ||
observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
observer.error(error); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
/** | ||
* Register a new observer for this operation. | ||
* | ||
* If the operation has previously emitted other events, they will be | ||
* immediately triggered for the observer. | ||
*/ | ||
RetryableOperation.prototype.subscribe = function (observer) { | ||
if (this.canceled) { | ||
throw new Error("Subscribing to a retryable link that was canceled is not supported"); | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var RetryableOperation = (function () { | ||
function RetryableOperation(operation, nextLink, delayFor, retryIf) { | ||
var _this = this; | ||
this.operation = operation; | ||
this.nextLink = nextLink; | ||
this.delayFor = delayFor; | ||
this.retryIf = retryIf; | ||
this.retryCount = 0; | ||
this.values = []; | ||
this.complete = false; | ||
this.canceled = false; | ||
this.observers = []; | ||
this.currentSubscription = null; | ||
this.onNext = function (value) { | ||
_this.values.push(value); | ||
for (var _i = 0, _a = _this.observers; _i < _a.length; _i++) { | ||
var observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
this.observers.push(observer); | ||
// If we've already begun, catch this observer up. | ||
for (var _i = 0, _a = this.values; _i < _a.length; _i++) { | ||
var value = _a[_i]; | ||
observer.next(value); | ||
} | ||
}; | ||
this.onComplete = function () { | ||
_this.complete = true; | ||
for (var _i = 0, _a = _this.observers; _i < _a.length; _i++) { | ||
var observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
if (this.complete) { | ||
observer.complete(); | ||
} | ||
else if (this.error) { | ||
observer.error(this.error); | ||
} | ||
}; | ||
this.onError = function (error) { return __awaiter(_this, void 0, void 0, function () { | ||
var shouldRetry, _i, _a, observer; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
this.retryCount += 1; | ||
return [4, this.retryIf(this.retryCount, this.operation, error)]; | ||
case 1: | ||
shouldRetry = _b.sent(); | ||
if (shouldRetry) { | ||
this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error)); | ||
return [2]; | ||
} | ||
this.error = error; | ||
for (_i = 0, _a = this.observers; _i < _a.length; _i++) { | ||
observer = _a[_i]; | ||
if (!observer) | ||
continue; | ||
observer.error(error); | ||
} | ||
return [2]; | ||
} | ||
/** | ||
* Remove a previously registered observer from this operation. | ||
* | ||
* If no observers remain, the operation will stop retrying, and unsubscribe | ||
* from its downstream link. | ||
*/ | ||
RetryableOperation.prototype.unsubscribe = function (observer) { | ||
var index = this.observers.indexOf(observer); | ||
if (index < 0) { | ||
throw new Error("RetryLink BUG! Attempting to unsubscribe unknown observer!"); | ||
} | ||
// Note that we are careful not to change the order of length of the array, | ||
// as we are often mid-iteration when calling this method. | ||
this.observers[index] = null; | ||
// If this is the last observer, we're done. | ||
if (this.observers.every(function (o) { return o === null; })) { | ||
this.cancel(); | ||
} | ||
}; | ||
/** | ||
* Start the initial request. | ||
*/ | ||
RetryableOperation.prototype.start = function () { | ||
if (this.currentSubscription) | ||
return; // Already started. | ||
this.try(); | ||
}; | ||
/** | ||
* Stop retrying for the operation, and cancel any in-progress requests. | ||
*/ | ||
RetryableOperation.prototype.cancel = function () { | ||
if (this.currentSubscription) { | ||
this.currentSubscription.unsubscribe(); | ||
} | ||
clearTimeout(this.timerId); | ||
this.timerId = null; | ||
this.currentSubscription = null; | ||
this.canceled = true; | ||
}; | ||
RetryableOperation.prototype.try = function () { | ||
this.currentSubscription = this.nextLink(this.operation).subscribe({ | ||
next: this.onNext, | ||
error: this.onError, | ||
complete: this.onComplete, | ||
}); | ||
}); }; | ||
} | ||
RetryableOperation.prototype.subscribe = function (observer) { | ||
if (this.canceled) { | ||
throw new Error("Subscribing to a retryable link that was canceled is not supported"); | ||
}; | ||
RetryableOperation.prototype.scheduleRetry = function (delay) { | ||
var _this = this; | ||
if (this.timerId) { | ||
throw new Error("RetryLink BUG! Encountered overlapping retries"); | ||
} | ||
this.timerId = setTimeout(function () { | ||
_this.timerId = null; | ||
_this.try(); | ||
}, delay); | ||
}; | ||
return RetryableOperation; | ||
}()); | ||
var RetryLink = /** @class */ (function (_super) { | ||
__extends(RetryLink, _super); | ||
function RetryLink(_a) { | ||
var _b = _a === void 0 ? {} : _a, delay = _b.delay, attempts = _b.attempts; | ||
var _this = _super.call(this) || this; | ||
_this.delayFor = | ||
typeof delay === 'function' ? delay : buildDelayFunction(delay); | ||
_this.retryIf = | ||
typeof attempts === 'function' ? attempts : buildRetryFunction(attempts); | ||
return _this; | ||
} | ||
this.observers.push(observer); | ||
for (var _i = 0, _a = this.values; _i < _a.length; _i++) { | ||
var value = _a[_i]; | ||
observer.next(value); | ||
} | ||
if (this.complete) { | ||
observer.complete(); | ||
} | ||
else if (this.error) { | ||
observer.error(this.error); | ||
} | ||
}; | ||
RetryableOperation.prototype.unsubscribe = function (observer) { | ||
var index = this.observers.indexOf(observer); | ||
if (index < 0) { | ||
throw new Error("RetryLink BUG! Attempting to unsubscribe unknown observer!"); | ||
} | ||
this.observers[index] = null; | ||
if (this.observers.every(function (o) { return o === null; })) { | ||
this.cancel(); | ||
} | ||
}; | ||
RetryableOperation.prototype.start = function () { | ||
if (this.currentSubscription) | ||
return; | ||
this.try(); | ||
}; | ||
RetryableOperation.prototype.cancel = function () { | ||
if (this.currentSubscription) { | ||
this.currentSubscription.unsubscribe(); | ||
} | ||
clearTimeout(this.timerId); | ||
this.timerId = null; | ||
this.currentSubscription = null; | ||
this.canceled = true; | ||
}; | ||
RetryableOperation.prototype.try = function () { | ||
this.currentSubscription = this.nextLink(this.operation).subscribe({ | ||
next: this.onNext, | ||
error: this.onError, | ||
complete: this.onComplete, | ||
}); | ||
}; | ||
RetryableOperation.prototype.scheduleRetry = function (delay) { | ||
var _this = this; | ||
if (this.timerId) { | ||
throw new Error("RetryLink BUG! Encountered overlapping retries"); | ||
} | ||
this.timerId = setTimeout(function () { | ||
_this.timerId = null; | ||
_this.try(); | ||
}, delay); | ||
}; | ||
return RetryableOperation; | ||
}()); | ||
var RetryLink = (function (_super) { | ||
__extends(RetryLink, _super); | ||
function RetryLink(_a) { | ||
var _b = _a === void 0 ? {} : _a, delay = _b.delay, attempts = _b.attempts; | ||
var _this = _super.call(this) || this; | ||
_this.delayFor = | ||
typeof delay === 'function' ? delay : buildDelayFunction(delay); | ||
_this.retryIf = | ||
typeof attempts === 'function' ? attempts : buildRetryFunction(attempts); | ||
return _this; | ||
} | ||
RetryLink.prototype.request = function (operation, nextLink) { | ||
var retryable = new RetryableOperation(operation, nextLink, this.delayFor, this.retryIf); | ||
retryable.start(); | ||
return new apolloLink.Observable(function (observer) { | ||
retryable.subscribe(observer); | ||
return function () { | ||
retryable.unsubscribe(observer); | ||
}; | ||
}); | ||
}; | ||
return RetryLink; | ||
}(apolloLink.ApolloLink)); | ||
RetryLink.prototype.request = function (operation, nextLink) { | ||
var retryable = new RetryableOperation(operation, nextLink, this.delayFor, this.retryIf); | ||
retryable.start(); | ||
return new apolloLink.Observable(function (observer) { | ||
retryable.subscribe(observer); | ||
return function () { | ||
retryable.unsubscribe(observer); | ||
}; | ||
}); | ||
}; | ||
return RetryLink; | ||
}(apolloLink.ApolloLink)); | ||
exports.RetryLink = RetryLink; | ||
exports.RetryLink = RetryLink; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=bundle.umd.js.map |
import { Operation } from 'apollo-link'; | ||
/** | ||
* Advanced mode: a function that implements the strategy for calculating delays | ||
* for particular responses. | ||
*/ | ||
export interface DelayFunction { | ||
@@ -6,6 +10,31 @@ (count: number, operation: Operation, error: any): number; | ||
export interface DelayFunctionOptions { | ||
/** | ||
* The number of milliseconds to wait before attempting the first retry. | ||
* | ||
* Delays will increase exponentially for each attempt. E.g. if this is | ||
* set to 100, subsequent retries will be delayed by 200, 400, 800, etc, | ||
* until they reach maxDelay. | ||
* | ||
* Note that if jittering is enabled, this is the _average_ delay. | ||
* | ||
* Defaults to 300. | ||
*/ | ||
initial?: number; | ||
/** | ||
* The maximum number of milliseconds that the link should wait for any | ||
* retry. | ||
* | ||
* Defaults to Infinity. | ||
*/ | ||
max?: number; | ||
/** | ||
* Whether delays between attempts should be randomized. | ||
* | ||
* This helps avoid thundering herd type situations by better distributing | ||
* load during major outages. | ||
* | ||
* Defaults to true. | ||
*/ | ||
jitter?: boolean; | ||
} | ||
export declare function buildDelayFunction({initial, max, jitter}?: DelayFunctionOptions): DelayFunction; |
@@ -5,5 +5,9 @@ export function buildDelayFunction(_a) { | ||
if (jitter) { | ||
// If we're jittering, baseDelay is half of the maximum delay for that | ||
// attempt (and is, on average, the delay we will encounter). | ||
baseDelay = initial; | ||
} | ||
else { | ||
// If we're not jittering, adjust baseDelay so that the first attempt | ||
// lines up with initialDelay, for everyone's sanity. | ||
baseDelay = initial / 2; | ||
@@ -14,2 +18,4 @@ } | ||
if (jitter) { | ||
// We opt for a full jitter approach for a mostly uniform distribution, | ||
// but bound it within initialDelay and delay for everyone's sanity. | ||
delay = Math.random() * delay; | ||
@@ -16,0 +22,0 @@ } |
import { Operation } from 'apollo-link'; | ||
/** | ||
* Advanced mode: a function that determines both whether a particular | ||
* response should be retried. | ||
*/ | ||
export interface RetryFunction { | ||
@@ -6,5 +10,21 @@ (count: number, operation: Operation, error: any): boolean | Promise<boolean>; | ||
export interface RetryFunctionOptions { | ||
/** | ||
* The max number of times to try a single operation before giving up. | ||
* | ||
* Note that this INCLUDES the initial request as part of the count. | ||
* E.g. maxTries of 1 indicates no retrying should occur. | ||
* | ||
* Defaults to 5. Pass Infinity for infinite retries. | ||
*/ | ||
max?: number; | ||
/** | ||
* Predicate function that determines whether a particular error should | ||
* trigger a retry. | ||
* | ||
* For example, you may want to not retry 4xx class HTTP errors. | ||
* | ||
* By default, all errors are retried. | ||
*/ | ||
retryIf?: (error: any, operation: Operation) => boolean | Promise<boolean>; | ||
} | ||
export declare function buildRetryFunction({max, retryIf}?: RetryFunctionOptions): RetryFunction; |
@@ -6,3 +6,9 @@ import { ApolloLink, Observable, Operation, NextLink, FetchResult } from 'apollo-link'; | ||
interface Options { | ||
/** | ||
* Configuration for the delay strategy to use, or a custom delay strategy. | ||
*/ | ||
delay?: DelayFunctionOptions | DelayFunction; | ||
/** | ||
* Configuration for the retry strategy to use, or a custom retry strategy. | ||
*/ | ||
attempts?: RetryFunctionOptions | RetryFunction; | ||
@@ -9,0 +15,0 @@ } |
@@ -49,3 +49,6 @@ var __extends = (this && this.__extends) || (function () { | ||
import { buildRetryFunction, } from './retryFunction'; | ||
var RetryableOperation = (function () { | ||
/** | ||
* Tracking and management of operations that may be (or currently are) retried. | ||
*/ | ||
var RetryableOperation = /** @class */ (function () { | ||
function RetryableOperation(operation, nextLink, delayFor, retryIf) { | ||
@@ -87,3 +90,3 @@ var _this = this; | ||
this.retryCount += 1; | ||
return [4, this.retryIf(this.retryCount, this.operation, error)]; | ||
return [4 /*yield*/, this.retryIf(this.retryCount, this.operation, error)]; | ||
case 1: | ||
@@ -93,3 +96,3 @@ shouldRetry = _b.sent(); | ||
this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error)); | ||
return [2]; | ||
return [2 /*return*/]; | ||
} | ||
@@ -103,3 +106,3 @@ this.error = error; | ||
} | ||
return [2]; | ||
return [2 /*return*/]; | ||
} | ||
@@ -109,2 +112,8 @@ }); | ||
} | ||
/** | ||
* Register a new observer for this operation. | ||
* | ||
* If the operation has previously emitted other events, they will be | ||
* immediately triggered for the observer. | ||
*/ | ||
RetryableOperation.prototype.subscribe = function (observer) { | ||
@@ -115,2 +124,3 @@ if (this.canceled) { | ||
this.observers.push(observer); | ||
// If we've already begun, catch this observer up. | ||
for (var _i = 0, _a = this.values; _i < _a.length; _i++) { | ||
@@ -127,2 +137,8 @@ var value = _a[_i]; | ||
}; | ||
/** | ||
* Remove a previously registered observer from this operation. | ||
* | ||
* If no observers remain, the operation will stop retrying, and unsubscribe | ||
* from its downstream link. | ||
*/ | ||
RetryableOperation.prototype.unsubscribe = function (observer) { | ||
@@ -133,3 +149,6 @@ var index = this.observers.indexOf(observer); | ||
} | ||
// Note that we are careful not to change the order of length of the array, | ||
// as we are often mid-iteration when calling this method. | ||
this.observers[index] = null; | ||
// If this is the last observer, we're done. | ||
if (this.observers.every(function (o) { return o === null; })) { | ||
@@ -139,7 +158,13 @@ this.cancel(); | ||
}; | ||
/** | ||
* Start the initial request. | ||
*/ | ||
RetryableOperation.prototype.start = function () { | ||
if (this.currentSubscription) | ||
return; | ||
return; // Already started. | ||
this.try(); | ||
}; | ||
/** | ||
* Stop retrying for the operation, and cancel any in-progress requests. | ||
*/ | ||
RetryableOperation.prototype.cancel = function () { | ||
@@ -173,3 +198,3 @@ if (this.currentSubscription) { | ||
}()); | ||
var RetryLink = (function (_super) { | ||
var RetryLink = /** @class */ (function (_super) { | ||
__extends(RetryLink, _super); | ||
@@ -176,0 +201,0 @@ function RetryLink(_a) { |
{ | ||
"name": "apollo-link-retry", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Retry Apollo Link for GraphQL Network Stack", | ||
@@ -26,4 +26,3 @@ "author": "Evans Hauser <evanshauser@gmail.com>", | ||
"scripts": { | ||
"build:browser": | ||
"browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser", | ||
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser", | ||
"build": "tsc -p .", | ||
@@ -34,6 +33,4 @@ "bundle": "rollup -c", | ||
"filesize": "npm run build && npm run build:browser", | ||
"lint": | ||
"tslint --type-check -p tsconfig.json -c ../../tslint.json src/*.ts", | ||
"minify:browser": | ||
"uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js", | ||
"lint": "tslint --type-check -p tsconfig.json -c ../../tslint.json src/*.ts", | ||
"minify:browser": "uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js", | ||
"postbuild": "npm run bundle", | ||
@@ -47,17 +44,17 @@ "prebuild": "npm run clean", | ||
"@types/zen-observable": "0.5.3", | ||
"apollo-link": "^1.2.1" | ||
"apollo-link": "^1.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/graphql": "0.12.4", | ||
"@types/jest": "21.1.10", | ||
"browserify": "16.1.0", | ||
"graphql": "0.13.1", | ||
"graphql-tag": "2.7.3", | ||
"jest": "21.2.1", | ||
"@types/graphql": "0.12.6", | ||
"@types/jest": "22.2.2", | ||
"browserify": "16.1.1", | ||
"graphql": "0.13.2", | ||
"graphql-tag": "2.8.0", | ||
"jest": "22.4.3", | ||
"rimraf": "2.6.1", | ||
"rollup": "0.56.2", | ||
"rollup": "0.57.1", | ||
"ts-jest": "21.2.4", | ||
"tslint": "5.9.1", | ||
"typescript": "2.7.2", | ||
"uglify-js": "3.3.11", | ||
"uglify-js": "3.3.16", | ||
"wait-for-observables": "1.0.3" | ||
@@ -67,8 +64,13 @@ }, | ||
"transform": { | ||
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
".(ts|tsx)": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", | ||
"moduleFileExtensions": ["ts", "tsx", "js", "json"], | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"json" | ||
], | ||
"mapCoverage": true | ||
} | ||
} |
@@ -173,3 +173,2 @@ import gql from 'graphql-tag'; | ||
it('supports custom attempt functions that return either Promises or booleans', async () => { | ||
@@ -197,1 +196,2 @@ const attemptStub = jest.fn(); | ||
}); | ||
}); |
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
87740
37
1353
0
Updatedapollo-link@^1.2.2