remove node_modules and .gitignore them
This commit is contained in:
-24
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AdaptiveRetryStrategy = void 0;
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const StandardRetryStrategy_1 = require("./StandardRetryStrategy");
|
||||
class AdaptiveRetryStrategy extends StandardRetryStrategy_1.StandardRetryStrategy {
|
||||
constructor(maxAttemptsProvider, options) {
|
||||
const { rateLimiter, ...superOptions } = options !== null && options !== void 0 ? options : {};
|
||||
super(maxAttemptsProvider, superOptions);
|
||||
this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new util_retry_1.DefaultRateLimiter();
|
||||
this.mode = util_retry_1.RETRY_MODES.ADAPTIVE;
|
||||
}
|
||||
async retry(next, args) {
|
||||
return super.retry(next, args, {
|
||||
beforeRequest: async () => {
|
||||
return this.rateLimiter.getSendToken();
|
||||
},
|
||||
afterRequest: (response) => {
|
||||
this.rateLimiter.updateClientSendingRate(response);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.AdaptiveRetryStrategy = AdaptiveRetryStrategy;
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StandardRetryStrategy = void 0;
|
||||
const protocol_http_1 = require("@smithy/protocol-http");
|
||||
const service_error_classification_1 = require("@smithy/service-error-classification");
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const uuid_1 = require("uuid");
|
||||
const defaultRetryQuota_1 = require("./defaultRetryQuota");
|
||||
const delayDecider_1 = require("./delayDecider");
|
||||
const retryDecider_1 = require("./retryDecider");
|
||||
const util_1 = require("./util");
|
||||
class StandardRetryStrategy {
|
||||
constructor(maxAttemptsProvider, options) {
|
||||
var _a, _b, _c;
|
||||
this.maxAttemptsProvider = maxAttemptsProvider;
|
||||
this.mode = util_retry_1.RETRY_MODES.STANDARD;
|
||||
this.retryDecider = (_a = options === null || options === void 0 ? void 0 : options.retryDecider) !== null && _a !== void 0 ? _a : retryDecider_1.defaultRetryDecider;
|
||||
this.delayDecider = (_b = options === null || options === void 0 ? void 0 : options.delayDecider) !== null && _b !== void 0 ? _b : delayDecider_1.defaultDelayDecider;
|
||||
this.retryQuota = (_c = options === null || options === void 0 ? void 0 : options.retryQuota) !== null && _c !== void 0 ? _c : (0, defaultRetryQuota_1.getDefaultRetryQuota)(util_retry_1.INITIAL_RETRY_TOKENS);
|
||||
}
|
||||
shouldRetry(error, attempts, maxAttempts) {
|
||||
return attempts < maxAttempts && this.retryDecider(error) && this.retryQuota.hasRetryTokens(error);
|
||||
}
|
||||
async getMaxAttempts() {
|
||||
let maxAttempts;
|
||||
try {
|
||||
maxAttempts = await this.maxAttemptsProvider();
|
||||
}
|
||||
catch (error) {
|
||||
maxAttempts = util_retry_1.DEFAULT_MAX_ATTEMPTS;
|
||||
}
|
||||
return maxAttempts;
|
||||
}
|
||||
async retry(next, args, options) {
|
||||
let retryTokenAmount;
|
||||
let attempts = 0;
|
||||
let totalDelay = 0;
|
||||
const maxAttempts = await this.getMaxAttempts();
|
||||
const { request } = args;
|
||||
if (protocol_http_1.HttpRequest.isInstance(request)) {
|
||||
request.headers[util_retry_1.INVOCATION_ID_HEADER] = (0, uuid_1.v4)();
|
||||
}
|
||||
while (true) {
|
||||
try {
|
||||
if (protocol_http_1.HttpRequest.isInstance(request)) {
|
||||
request.headers[util_retry_1.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`;
|
||||
}
|
||||
if (options === null || options === void 0 ? void 0 : options.beforeRequest) {
|
||||
await options.beforeRequest();
|
||||
}
|
||||
const { response, output } = await next(args);
|
||||
if (options === null || options === void 0 ? void 0 : options.afterRequest) {
|
||||
options.afterRequest(response);
|
||||
}
|
||||
this.retryQuota.releaseRetryTokens(retryTokenAmount);
|
||||
output.$metadata.attempts = attempts + 1;
|
||||
output.$metadata.totalRetryDelay = totalDelay;
|
||||
return { response, output };
|
||||
}
|
||||
catch (e) {
|
||||
const err = (0, util_1.asSdkError)(e);
|
||||
attempts++;
|
||||
if (this.shouldRetry(err, attempts, maxAttempts)) {
|
||||
retryTokenAmount = this.retryQuota.retrieveRetryTokens(err);
|
||||
const delayFromDecider = this.delayDecider((0, service_error_classification_1.isThrottlingError)(err) ? util_retry_1.THROTTLING_RETRY_DELAY_BASE : util_retry_1.DEFAULT_RETRY_DELAY_BASE, attempts);
|
||||
const delayFromResponse = getDelayFromRetryAfterHeader(err.$response);
|
||||
const delay = Math.max(delayFromResponse || 0, delayFromDecider);
|
||||
totalDelay += delay;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
continue;
|
||||
}
|
||||
if (!err.$metadata) {
|
||||
err.$metadata = {};
|
||||
}
|
||||
err.$metadata.attempts = attempts;
|
||||
err.$metadata.totalRetryDelay = totalDelay;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.StandardRetryStrategy = StandardRetryStrategy;
|
||||
const getDelayFromRetryAfterHeader = (response) => {
|
||||
if (!protocol_http_1.HttpResponse.isInstance(response))
|
||||
return;
|
||||
const retryAfterHeaderName = Object.keys(response.headers).find((key) => key.toLowerCase() === "retry-after");
|
||||
if (!retryAfterHeaderName)
|
||||
return;
|
||||
const retryAfter = response.headers[retryAfterHeaderName];
|
||||
const retryAfterSeconds = Number(retryAfter);
|
||||
if (!Number.isNaN(retryAfterSeconds))
|
||||
return retryAfterSeconds * 1000;
|
||||
const retryAfterDate = new Date(retryAfter);
|
||||
return retryAfterDate.getTime() - Date.now();
|
||||
};
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NODE_RETRY_MODE_CONFIG_OPTIONS = exports.CONFIG_RETRY_MODE = exports.ENV_RETRY_MODE = exports.resolveRetryConfig = exports.NODE_MAX_ATTEMPT_CONFIG_OPTIONS = exports.CONFIG_MAX_ATTEMPTS = exports.ENV_MAX_ATTEMPTS = void 0;
|
||||
const util_middleware_1 = require("@smithy/util-middleware");
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
exports.ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS";
|
||||
exports.CONFIG_MAX_ATTEMPTS = "max_attempts";
|
||||
exports.NODE_MAX_ATTEMPT_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector: (env) => {
|
||||
const value = env[exports.ENV_MAX_ATTEMPTS];
|
||||
if (!value)
|
||||
return undefined;
|
||||
const maxAttempt = parseInt(value);
|
||||
if (Number.isNaN(maxAttempt)) {
|
||||
throw new Error(`Environment variable ${exports.ENV_MAX_ATTEMPTS} mast be a number, got "${value}"`);
|
||||
}
|
||||
return maxAttempt;
|
||||
},
|
||||
configFileSelector: (profile) => {
|
||||
const value = profile[exports.CONFIG_MAX_ATTEMPTS];
|
||||
if (!value)
|
||||
return undefined;
|
||||
const maxAttempt = parseInt(value);
|
||||
if (Number.isNaN(maxAttempt)) {
|
||||
throw new Error(`Shared config file entry ${exports.CONFIG_MAX_ATTEMPTS} mast be a number, got "${value}"`);
|
||||
}
|
||||
return maxAttempt;
|
||||
},
|
||||
default: util_retry_1.DEFAULT_MAX_ATTEMPTS,
|
||||
};
|
||||
const resolveRetryConfig = (input) => {
|
||||
var _a;
|
||||
const { retryStrategy } = input;
|
||||
const maxAttempts = (0, util_middleware_1.normalizeProvider)((_a = input.maxAttempts) !== null && _a !== void 0 ? _a : util_retry_1.DEFAULT_MAX_ATTEMPTS);
|
||||
return {
|
||||
...input,
|
||||
maxAttempts,
|
||||
retryStrategy: async () => {
|
||||
if (retryStrategy) {
|
||||
return retryStrategy;
|
||||
}
|
||||
const retryMode = await (0, util_middleware_1.normalizeProvider)(input.retryMode)();
|
||||
if (retryMode === util_retry_1.RETRY_MODES.ADAPTIVE) {
|
||||
return new util_retry_1.AdaptiveRetryStrategy(maxAttempts);
|
||||
}
|
||||
return new util_retry_1.StandardRetryStrategy(maxAttempts);
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.resolveRetryConfig = resolveRetryConfig;
|
||||
exports.ENV_RETRY_MODE = "AWS_RETRY_MODE";
|
||||
exports.CONFIG_RETRY_MODE = "retry_mode";
|
||||
exports.NODE_RETRY_MODE_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector: (env) => env[exports.ENV_RETRY_MODE],
|
||||
configFileSelector: (profile) => profile[exports.CONFIG_RETRY_MODE],
|
||||
default: util_retry_1.DEFAULT_RETRY_MODE,
|
||||
};
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDefaultRetryQuota = void 0;
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const getDefaultRetryQuota = (initialRetryTokens, options) => {
|
||||
var _a, _b, _c;
|
||||
const MAX_CAPACITY = initialRetryTokens;
|
||||
const noRetryIncrement = (_a = options === null || options === void 0 ? void 0 : options.noRetryIncrement) !== null && _a !== void 0 ? _a : util_retry_1.NO_RETRY_INCREMENT;
|
||||
const retryCost = (_b = options === null || options === void 0 ? void 0 : options.retryCost) !== null && _b !== void 0 ? _b : util_retry_1.RETRY_COST;
|
||||
const timeoutRetryCost = (_c = options === null || options === void 0 ? void 0 : options.timeoutRetryCost) !== null && _c !== void 0 ? _c : util_retry_1.TIMEOUT_RETRY_COST;
|
||||
let availableCapacity = initialRetryTokens;
|
||||
const getCapacityAmount = (error) => (error.name === "TimeoutError" ? timeoutRetryCost : retryCost);
|
||||
const hasRetryTokens = (error) => getCapacityAmount(error) <= availableCapacity;
|
||||
const retrieveRetryTokens = (error) => {
|
||||
if (!hasRetryTokens(error)) {
|
||||
throw new Error("No retry token available");
|
||||
}
|
||||
const capacityAmount = getCapacityAmount(error);
|
||||
availableCapacity -= capacityAmount;
|
||||
return capacityAmount;
|
||||
};
|
||||
const releaseRetryTokens = (capacityReleaseAmount) => {
|
||||
availableCapacity += capacityReleaseAmount !== null && capacityReleaseAmount !== void 0 ? capacityReleaseAmount : noRetryIncrement;
|
||||
availableCapacity = Math.min(availableCapacity, MAX_CAPACITY);
|
||||
};
|
||||
return Object.freeze({
|
||||
hasRetryTokens,
|
||||
retrieveRetryTokens,
|
||||
releaseRetryTokens,
|
||||
});
|
||||
};
|
||||
exports.getDefaultRetryQuota = getDefaultRetryQuota;
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultDelayDecider = void 0;
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const defaultDelayDecider = (delayBase, attempts) => Math.floor(Math.min(util_retry_1.MAXIMUM_RETRY_DELAY, Math.random() * 2 ** attempts * delayBase));
|
||||
exports.defaultDelayDecider = defaultDelayDecider;
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./AdaptiveRetryStrategy"), exports);
|
||||
tslib_1.__exportStar(require("./StandardRetryStrategy"), exports);
|
||||
tslib_1.__exportStar(require("./configurations"), exports);
|
||||
tslib_1.__exportStar(require("./delayDecider"), exports);
|
||||
tslib_1.__exportStar(require("./omitRetryHeadersMiddleware"), exports);
|
||||
tslib_1.__exportStar(require("./retryDecider"), exports);
|
||||
tslib_1.__exportStar(require("./retryMiddleware"), exports);
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getOmitRetryHeadersPlugin = exports.omitRetryHeadersMiddlewareOptions = exports.omitRetryHeadersMiddleware = void 0;
|
||||
const protocol_http_1 = require("@smithy/protocol-http");
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const omitRetryHeadersMiddleware = () => (next) => async (args) => {
|
||||
const { request } = args;
|
||||
if (protocol_http_1.HttpRequest.isInstance(request)) {
|
||||
delete request.headers[util_retry_1.INVOCATION_ID_HEADER];
|
||||
delete request.headers[util_retry_1.REQUEST_HEADER];
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
exports.omitRetryHeadersMiddleware = omitRetryHeadersMiddleware;
|
||||
exports.omitRetryHeadersMiddlewareOptions = {
|
||||
name: "omitRetryHeadersMiddleware",
|
||||
tags: ["RETRY", "HEADERS", "OMIT_RETRY_HEADERS"],
|
||||
relation: "before",
|
||||
toMiddleware: "awsAuthMiddleware",
|
||||
override: true,
|
||||
};
|
||||
const getOmitRetryHeadersPlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo((0, exports.omitRetryHeadersMiddleware)(), exports.omitRetryHeadersMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
exports.getOmitRetryHeadersPlugin = getOmitRetryHeadersPlugin;
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultRetryDecider = void 0;
|
||||
const service_error_classification_1 = require("@smithy/service-error-classification");
|
||||
const defaultRetryDecider = (error) => {
|
||||
if (!error) {
|
||||
return false;
|
||||
}
|
||||
return (0, service_error_classification_1.isRetryableByTrait)(error) || (0, service_error_classification_1.isClockSkewError)(error) || (0, service_error_classification_1.isThrottlingError)(error) || (0, service_error_classification_1.isTransientError)(error);
|
||||
};
|
||||
exports.defaultRetryDecider = defaultRetryDecider;
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRetryAfterHint = exports.getRetryPlugin = exports.retryMiddlewareOptions = exports.retryMiddleware = void 0;
|
||||
const protocol_http_1 = require("@smithy/protocol-http");
|
||||
const service_error_classification_1 = require("@smithy/service-error-classification");
|
||||
const util_retry_1 = require("@smithy/util-retry");
|
||||
const uuid_1 = require("uuid");
|
||||
const util_1 = require("./util");
|
||||
const retryMiddleware = (options) => (next, context) => async (args) => {
|
||||
let retryStrategy = await options.retryStrategy();
|
||||
const maxAttempts = await options.maxAttempts();
|
||||
if (isRetryStrategyV2(retryStrategy)) {
|
||||
retryStrategy = retryStrategy;
|
||||
let retryToken = await retryStrategy.acquireInitialRetryToken(context["partition_id"]);
|
||||
let lastError = new Error();
|
||||
let attempts = 0;
|
||||
let totalRetryDelay = 0;
|
||||
const { request } = args;
|
||||
if (protocol_http_1.HttpRequest.isInstance(request)) {
|
||||
request.headers[util_retry_1.INVOCATION_ID_HEADER] = (0, uuid_1.v4)();
|
||||
}
|
||||
while (true) {
|
||||
try {
|
||||
if (protocol_http_1.HttpRequest.isInstance(request)) {
|
||||
request.headers[util_retry_1.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`;
|
||||
}
|
||||
const { response, output } = await next(args);
|
||||
retryStrategy.recordSuccess(retryToken);
|
||||
output.$metadata.attempts = attempts + 1;
|
||||
output.$metadata.totalRetryDelay = totalRetryDelay;
|
||||
return { response, output };
|
||||
}
|
||||
catch (e) {
|
||||
const retryErrorInfo = getRetryErrorInfo(e);
|
||||
lastError = (0, util_1.asSdkError)(e);
|
||||
try {
|
||||
retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
|
||||
}
|
||||
catch (refreshError) {
|
||||
if (!lastError.$metadata) {
|
||||
lastError.$metadata = {};
|
||||
}
|
||||
lastError.$metadata.attempts = attempts + 1;
|
||||
lastError.$metadata.totalRetryDelay = totalRetryDelay;
|
||||
throw lastError;
|
||||
}
|
||||
attempts = retryToken.getRetryCount();
|
||||
const delay = retryToken.getRetryDelay();
|
||||
totalRetryDelay += delay;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
retryStrategy = retryStrategy;
|
||||
if (retryStrategy === null || retryStrategy === void 0 ? void 0 : retryStrategy.mode)
|
||||
context.userAgent = [...(context.userAgent || []), ["cfg/retry-mode", retryStrategy.mode]];
|
||||
return retryStrategy.retry(next, args);
|
||||
}
|
||||
};
|
||||
exports.retryMiddleware = retryMiddleware;
|
||||
const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" &&
|
||||
typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" &&
|
||||
typeof retryStrategy.recordSuccess !== "undefined";
|
||||
const getRetryErrorInfo = (error) => {
|
||||
const errorInfo = {
|
||||
errorType: getRetryErrorType(error),
|
||||
};
|
||||
const retryAfterHint = (0, exports.getRetryAfterHint)(error.$response);
|
||||
if (retryAfterHint) {
|
||||
errorInfo.retryAfterHint = retryAfterHint;
|
||||
}
|
||||
return errorInfo;
|
||||
};
|
||||
const getRetryErrorType = (error) => {
|
||||
if ((0, service_error_classification_1.isThrottlingError)(error))
|
||||
return "THROTTLING";
|
||||
if ((0, service_error_classification_1.isTransientError)(error))
|
||||
return "TRANSIENT";
|
||||
if ((0, service_error_classification_1.isServerError)(error))
|
||||
return "SERVER_ERROR";
|
||||
return "CLIENT_ERROR";
|
||||
};
|
||||
exports.retryMiddlewareOptions = {
|
||||
name: "retryMiddleware",
|
||||
tags: ["RETRY"],
|
||||
step: "finalizeRequest",
|
||||
priority: "high",
|
||||
override: true,
|
||||
};
|
||||
const getRetryPlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add((0, exports.retryMiddleware)(options), exports.retryMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
exports.getRetryPlugin = getRetryPlugin;
|
||||
const getRetryAfterHint = (response) => {
|
||||
if (!protocol_http_1.HttpResponse.isInstance(response))
|
||||
return;
|
||||
const retryAfterHeaderName = Object.keys(response.headers).find((key) => key.toLowerCase() === "retry-after");
|
||||
if (!retryAfterHeaderName)
|
||||
return;
|
||||
const retryAfter = response.headers[retryAfterHeaderName];
|
||||
const retryAfterSeconds = Number(retryAfter);
|
||||
if (!Number.isNaN(retryAfterSeconds))
|
||||
return new Date(retryAfterSeconds * 1000);
|
||||
const retryAfterDate = new Date(retryAfter);
|
||||
return retryAfterDate;
|
||||
};
|
||||
exports.getRetryAfterHint = getRetryAfterHint;
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.asSdkError = void 0;
|
||||
const asSdkError = (error) => {
|
||||
if (error instanceof Error)
|
||||
return error;
|
||||
if (error instanceof Object)
|
||||
return Object.assign(new Error(), error);
|
||||
if (typeof error === "string")
|
||||
return new Error(error);
|
||||
return new Error(`AWS SDK error wrapper for ${error}`);
|
||||
};
|
||||
exports.asSdkError = asSdkError;
|
||||
Reference in New Issue
Block a user