apollo-link-retry
Advanced tools
Comparing version 2.2.8 to 2.2.9
(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)); | ||
}(this, (function (exports,apolloLink) { 'use strict'; | ||
(global = global || self, 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) { | ||
// 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; | ||
} | ||
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; | ||
}; | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
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; | ||
}; | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
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 extendStatics(d, b); | ||
}; | ||
function __extends(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 = function (d, b) { | ||
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 extendStatics(d, b); | ||
}; | ||
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) { | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
@@ -60,4 +43,5 @@ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
}); | ||
}; | ||
var __generator = (undefined && undefined.__generator) || function (thisArg, body) { | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
@@ -88,7 +72,32 @@ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
} | ||
}; | ||
/** | ||
* Tracking and management of operations that may be (or currently are) retried. | ||
*/ | ||
var RetryableOperation = /** @class */ (function () { | ||
} | ||
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)); | ||
if (jitter) { | ||
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; | ||
}; | ||
} | ||
var RetryableOperation = (function () { | ||
function RetryableOperation(operation, nextLink, delayFor, retryIf) { | ||
@@ -130,3 +139,3 @@ var _this = this; | ||
this.retryCount += 1; | ||
return [4 /*yield*/, this.retryIf(this.retryCount, this.operation, error)]; | ||
return [4, this.retryIf(this.retryCount, this.operation, error)]; | ||
case 1: | ||
@@ -136,3 +145,3 @@ shouldRetry = _b.sent(); | ||
this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error)); | ||
return [2 /*return*/]; | ||
return [2]; | ||
} | ||
@@ -146,3 +155,3 @@ this.error = error; | ||
} | ||
return [2 /*return*/]; | ||
return [2]; | ||
} | ||
@@ -152,8 +161,2 @@ }); | ||
} | ||
/** | ||
* 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) { | ||
@@ -164,3 +167,2 @@ 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++) { | ||
@@ -177,8 +179,2 @@ 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) { | ||
@@ -189,6 +185,3 @@ 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; })) { | ||
@@ -198,13 +191,7 @@ this.cancel(); | ||
}; | ||
/** | ||
* Start the initial request. | ||
*/ | ||
RetryableOperation.prototype.start = function () { | ||
if (this.currentSubscription) | ||
return; // Already started. | ||
return; | ||
this.try(); | ||
}; | ||
/** | ||
* Stop retrying for the operation, and cancel any in-progress requests. | ||
*/ | ||
RetryableOperation.prototype.cancel = function () { | ||
@@ -238,3 +225,3 @@ if (this.currentSubscription) { | ||
}()); | ||
var RetryLink = /** @class */ (function (_super) { | ||
var RetryLink = (function (_super) { | ||
__extends(RetryLink, _super); | ||
@@ -267,3 +254,3 @@ function RetryLink(_a) { | ||
}))); | ||
})); | ||
//# 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 { | ||
@@ -10,31 +6,7 @@ (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; | ||
//# sourceMappingURL=delayFunction.d.ts.map |
@@ -1,12 +0,10 @@ | ||
export function buildDelayFunction(_a) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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) { | ||
// 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; | ||
@@ -17,4 +15,2 @@ } | ||
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; | ||
@@ -25,2 +21,3 @@ } | ||
} | ||
exports.buildDelayFunction = buildDelayFunction; | ||
//# sourceMappingURL=delayFunction.js.map |
export * from './retryLink'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,7 @@ | ||
export * from './retryLink'; | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./retryLink")); | ||
//# sourceMappingURL=index.js.map |
import { Operation } from 'apollo-link'; | ||
/** | ||
* Advanced mode: a function that determines both whether a particular | ||
* response should be retried. | ||
*/ | ||
export interface RetryFunction { | ||
@@ -10,21 +6,6 @@ (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; | ||
//# sourceMappingURL=retryFunction.d.ts.map |
@@ -1,2 +0,4 @@ | ||
export function buildRetryFunction(_a) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function buildRetryFunction(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.max, max = _c === void 0 ? 5 : _c, retryIf = _b.retryIf; | ||
@@ -9,2 +11,3 @@ return function retryFunction(count, operation, error) { | ||
} | ||
exports.buildRetryFunction = buildRetryFunction; | ||
//# sourceMappingURL=retryFunction.js.map |
@@ -6,9 +6,3 @@ 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; | ||
@@ -23,1 +17,2 @@ } | ||
} | ||
//# sourceMappingURL=retryLink.d.ts.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -49,9 +50,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { ApolloLink, Observable, } from 'apollo-link'; | ||
import { buildDelayFunction, } from './delayFunction'; | ||
import { buildRetryFunction, } from './retryFunction'; | ||
/** | ||
* Tracking and management of operations that may be (or currently are) retried. | ||
*/ | ||
var RetryableOperation = /** @class */ (function () { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var apollo_link_1 = require("apollo-link"); | ||
var delayFunction_1 = require("./delayFunction"); | ||
var retryFunction_1 = require("./retryFunction"); | ||
var RetryableOperation = (function () { | ||
function RetryableOperation(operation, nextLink, delayFor, retryIf) { | ||
@@ -93,3 +92,3 @@ var _this = this; | ||
this.retryCount += 1; | ||
return [4 /*yield*/, this.retryIf(this.retryCount, this.operation, error)]; | ||
return [4, this.retryIf(this.retryCount, this.operation, error)]; | ||
case 1: | ||
@@ -99,3 +98,3 @@ shouldRetry = _b.sent(); | ||
this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error)); | ||
return [2 /*return*/]; | ||
return [2]; | ||
} | ||
@@ -109,3 +108,3 @@ this.error = error; | ||
} | ||
return [2 /*return*/]; | ||
return [2]; | ||
} | ||
@@ -115,8 +114,2 @@ }); | ||
} | ||
/** | ||
* 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) { | ||
@@ -127,3 +120,2 @@ 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++) { | ||
@@ -140,8 +132,2 @@ 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) { | ||
@@ -152,6 +138,3 @@ 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; })) { | ||
@@ -161,13 +144,7 @@ this.cancel(); | ||
}; | ||
/** | ||
* Start the initial request. | ||
*/ | ||
RetryableOperation.prototype.start = function () { | ||
if (this.currentSubscription) | ||
return; // Already started. | ||
return; | ||
this.try(); | ||
}; | ||
/** | ||
* Stop retrying for the operation, and cancel any in-progress requests. | ||
*/ | ||
RetryableOperation.prototype.cancel = function () { | ||
@@ -201,3 +178,3 @@ if (this.currentSubscription) { | ||
}()); | ||
var RetryLink = /** @class */ (function (_super) { | ||
var RetryLink = (function (_super) { | ||
__extends(RetryLink, _super); | ||
@@ -208,5 +185,5 @@ function RetryLink(_a) { | ||
_this.delayFor = | ||
typeof delay === 'function' ? delay : buildDelayFunction(delay); | ||
typeof delay === 'function' ? delay : delayFunction_1.buildDelayFunction(delay); | ||
_this.retryIf = | ||
typeof attempts === 'function' ? attempts : buildRetryFunction(attempts); | ||
typeof attempts === 'function' ? attempts : retryFunction_1.buildRetryFunction(attempts); | ||
return _this; | ||
@@ -217,3 +194,3 @@ } | ||
retryable.start(); | ||
return new Observable(function (observer) { | ||
return new apollo_link_1.Observable(function (observer) { | ||
retryable.subscribe(observer); | ||
@@ -226,4 +203,4 @@ return function () { | ||
return RetryLink; | ||
}(ApolloLink)); | ||
export { RetryLink }; | ||
}(apollo_link_1.ApolloLink)); | ||
exports.RetryLink = RetryLink; | ||
//# sourceMappingURL=retryLink.js.map |
{ | ||
"name": "apollo-link-retry", | ||
"version": "2.2.8", | ||
"version": "2.2.9", | ||
"description": "Retry Apollo Link for GraphQL Network Stack", | ||
@@ -13,5 +13,4 @@ "author": "Evans Hauser <evanshauser@gmail.com>", | ||
"license": "MIT", | ||
"main": "./lib/bundle.umd.js", | ||
"module": "./lib/index.js", | ||
"jsnext:main": "./lib/index.js", | ||
"main": "./lib/index.js", | ||
"module": "./lib/bundle.esm.js", | ||
"typings": "./lib/index.d.ts", | ||
@@ -28,3 +27,3 @@ "repository": { | ||
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser", | ||
"build": "tsc -p .", | ||
"build": "tsc -p ./tsconfig.cjs.json", | ||
"bundle": "rollup -c", | ||
@@ -34,6 +33,7 @@ "clean": "rimraf lib/* && rimraf coverage/*", | ||
"filesize": "npm run build && npm run build:browser", | ||
"lint": "tslint --type-check -p tsconfig.json -c ../../tslint.json src/*.ts", | ||
"lint": "tslint -c \"../../tslint.json\" -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", | ||
"prebuild": "npm run clean", | ||
"prepare": "npm run lint && npm run build", | ||
"prepublishOnly": "npm run clean && npm run build", | ||
@@ -45,15 +45,15 @@ "test": "jest", | ||
"@types/zen-observable": "0.8.0", | ||
"apollo-link": "^1.2.6" | ||
"apollo-link": "^1.2.7" | ||
}, | ||
"devDependencies": { | ||
"@types/graphql": "14.0.3", | ||
"@types/graphql": "14.0.5", | ||
"@types/jest": "22.2.3", | ||
"browserify": "16.2.3", | ||
"graphql": "14.0.2", | ||
"graphql-tag": "2.10.0", | ||
"graphql": "14.1.1", | ||
"graphql-tag": "2.10.1", | ||
"jest": "22.4.4", | ||
"rimraf": "2.6.1", | ||
"rollup": "0.67.4", | ||
"rimraf": "2.6.3", | ||
"rollup": "0.68.2", | ||
"ts-jest": "22.4.6", | ||
"tslint": "5.11.0", | ||
"tslint": "5.12.1", | ||
"typescript": "3.0.3", | ||
@@ -74,5 +74,4 @@ "uglify-js": "3.4.9", | ||
], | ||
"mapCoverage": true, | ||
"testURL": "http://localhost" | ||
} | ||
} |
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
118886
41
726
1
Updatedapollo-link@^1.2.7