@smithy/middleware-retry 3.0.34 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.js +18 -17
- package/package.json +9 -9
package/dist-cjs/index.js
CHANGED
|
@@ -54,9 +54,9 @@ var import_uuid = require("uuid");
|
|
|
54
54
|
var import_util_retry = require("@smithy/util-retry");
|
|
55
55
|
var getDefaultRetryQuota = /* @__PURE__ */ __name((initialRetryTokens, options) => {
|
|
56
56
|
const MAX_CAPACITY = initialRetryTokens;
|
|
57
|
-
const noRetryIncrement =
|
|
58
|
-
const retryCost =
|
|
59
|
-
const timeoutRetryCost =
|
|
57
|
+
const noRetryIncrement = options?.noRetryIncrement ?? import_util_retry.NO_RETRY_INCREMENT;
|
|
58
|
+
const retryCost = options?.retryCost ?? import_util_retry.RETRY_COST;
|
|
59
|
+
const timeoutRetryCost = options?.timeoutRetryCost ?? import_util_retry.TIMEOUT_RETRY_COST;
|
|
60
60
|
let availableCapacity = initialRetryTokens;
|
|
61
61
|
const getCapacityAmount = /* @__PURE__ */ __name((error) => error.name === "TimeoutError" ? timeoutRetryCost : retryCost, "getCapacityAmount");
|
|
62
62
|
const hasRetryTokens = /* @__PURE__ */ __name((error) => getCapacityAmount(error) <= availableCapacity, "hasRetryTokens");
|
|
@@ -104,13 +104,16 @@ var asSdkError = /* @__PURE__ */ __name((error) => {
|
|
|
104
104
|
}, "asSdkError");
|
|
105
105
|
|
|
106
106
|
// src/StandardRetryStrategy.ts
|
|
107
|
-
var
|
|
107
|
+
var StandardRetryStrategy = class {
|
|
108
108
|
constructor(maxAttemptsProvider, options) {
|
|
109
109
|
this.maxAttemptsProvider = maxAttemptsProvider;
|
|
110
110
|
this.mode = import_util_retry.RETRY_MODES.STANDARD;
|
|
111
|
-
this.retryDecider =
|
|
112
|
-
this.delayDecider =
|
|
113
|
-
this.retryQuota =
|
|
111
|
+
this.retryDecider = options?.retryDecider ?? defaultRetryDecider;
|
|
112
|
+
this.delayDecider = options?.delayDecider ?? defaultDelayDecider;
|
|
113
|
+
this.retryQuota = options?.retryQuota ?? getDefaultRetryQuota(import_util_retry.INITIAL_RETRY_TOKENS);
|
|
114
|
+
}
|
|
115
|
+
static {
|
|
116
|
+
__name(this, "StandardRetryStrategy");
|
|
114
117
|
}
|
|
115
118
|
shouldRetry(error, attempts, maxAttempts) {
|
|
116
119
|
return attempts < maxAttempts && this.retryDecider(error) && this.retryQuota.hasRetryTokens(error);
|
|
@@ -138,11 +141,11 @@ var _StandardRetryStrategy = class _StandardRetryStrategy {
|
|
|
138
141
|
if (import_protocol_http.HttpRequest.isInstance(request)) {
|
|
139
142
|
request.headers[import_util_retry.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`;
|
|
140
143
|
}
|
|
141
|
-
if (options
|
|
144
|
+
if (options?.beforeRequest) {
|
|
142
145
|
await options.beforeRequest();
|
|
143
146
|
}
|
|
144
147
|
const { response, output } = await next(args);
|
|
145
|
-
if (options
|
|
148
|
+
if (options?.afterRequest) {
|
|
146
149
|
options.afterRequest(response);
|
|
147
150
|
}
|
|
148
151
|
this.retryQuota.releaseRetryTokens(retryTokenAmount);
|
|
@@ -174,8 +177,6 @@ var _StandardRetryStrategy = class _StandardRetryStrategy {
|
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
179
|
};
|
|
177
|
-
__name(_StandardRetryStrategy, "StandardRetryStrategy");
|
|
178
|
-
var StandardRetryStrategy = _StandardRetryStrategy;
|
|
179
180
|
var getDelayFromRetryAfterHeader = /* @__PURE__ */ __name((response) => {
|
|
180
181
|
if (!import_protocol_http.HttpResponse.isInstance(response))
|
|
181
182
|
return;
|
|
@@ -191,7 +192,10 @@ var getDelayFromRetryAfterHeader = /* @__PURE__ */ __name((response) => {
|
|
|
191
192
|
}, "getDelayFromRetryAfterHeader");
|
|
192
193
|
|
|
193
194
|
// src/AdaptiveRetryStrategy.ts
|
|
194
|
-
var
|
|
195
|
+
var AdaptiveRetryStrategy = class extends StandardRetryStrategy {
|
|
196
|
+
static {
|
|
197
|
+
__name(this, "AdaptiveRetryStrategy");
|
|
198
|
+
}
|
|
195
199
|
constructor(maxAttemptsProvider, options) {
|
|
196
200
|
const { rateLimiter, ...superOptions } = options ?? {};
|
|
197
201
|
super(maxAttemptsProvider, superOptions);
|
|
@@ -209,8 +213,6 @@ var _AdaptiveRetryStrategy = class _AdaptiveRetryStrategy extends StandardRetryS
|
|
|
209
213
|
});
|
|
210
214
|
}
|
|
211
215
|
};
|
|
212
|
-
__name(_AdaptiveRetryStrategy, "AdaptiveRetryStrategy");
|
|
213
|
-
var AdaptiveRetryStrategy = _AdaptiveRetryStrategy;
|
|
214
216
|
|
|
215
217
|
// src/configurations.ts
|
|
216
218
|
var import_util_middleware = require("@smithy/util-middleware");
|
|
@@ -298,7 +300,6 @@ var import_smithy_client = require("@smithy/smithy-client");
|
|
|
298
300
|
|
|
299
301
|
var import_isStreamingPayload = require("./isStreamingPayload/isStreamingPayload");
|
|
300
302
|
var retryMiddleware = /* @__PURE__ */ __name((options) => (next, context) => async (args) => {
|
|
301
|
-
var _a;
|
|
302
303
|
let retryStrategy = await options.retryStrategy();
|
|
303
304
|
const maxAttempts = await options.maxAttempts();
|
|
304
305
|
if (isRetryStrategyV2(retryStrategy)) {
|
|
@@ -326,7 +327,7 @@ var retryMiddleware = /* @__PURE__ */ __name((options) => (next, context) => asy
|
|
|
326
327
|
const retryErrorInfo = getRetryErrorInfo(e);
|
|
327
328
|
lastError = asSdkError(e);
|
|
328
329
|
if (isRequest && (0, import_isStreamingPayload.isStreamingPayload)(request)) {
|
|
329
|
-
(
|
|
330
|
+
(context.logger instanceof import_smithy_client.NoOpLogger ? console : context.logger)?.warn(
|
|
330
331
|
"An error was encountered in a non-retryable streaming request."
|
|
331
332
|
);
|
|
332
333
|
throw lastError;
|
|
@@ -349,7 +350,7 @@ var retryMiddleware = /* @__PURE__ */ __name((options) => (next, context) => asy
|
|
|
349
350
|
}
|
|
350
351
|
} else {
|
|
351
352
|
retryStrategy = retryStrategy;
|
|
352
|
-
if (retryStrategy
|
|
353
|
+
if (retryStrategy?.mode)
|
|
353
354
|
context.userAgent = [...context.userAgent || [], ["cfg/retry-mode", retryStrategy.mode]];
|
|
354
355
|
return retryStrategy.retry(next, args);
|
|
355
356
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/middleware-retry",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "node ../../scripts/inline middleware-retry",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@smithy/node-config-provider": "^
|
|
37
|
-
"@smithy/protocol-http": "^
|
|
38
|
-
"@smithy/service-error-classification": "^
|
|
39
|
-
"@smithy/smithy-client": "^
|
|
40
|
-
"@smithy/types": "^
|
|
41
|
-
"@smithy/util-middleware": "^
|
|
42
|
-
"@smithy/util-retry": "^
|
|
36
|
+
"@smithy/node-config-provider": "^4.0.1",
|
|
37
|
+
"@smithy/protocol-http": "^5.0.1",
|
|
38
|
+
"@smithy/service-error-classification": "^4.0.1",
|
|
39
|
+
"@smithy/smithy-client": "^4.1.0",
|
|
40
|
+
"@smithy/types": "^4.1.0",
|
|
41
|
+
"@smithy/util-middleware": "^4.0.1",
|
|
42
|
+
"@smithy/util-retry": "^4.0.1",
|
|
43
43
|
"tslib": "^2.6.2",
|
|
44
44
|
"uuid": "^9.0.1"
|
|
45
45
|
},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typedoc": "0.23.23"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
55
|
+
"node": ">=18.0.0"
|
|
56
56
|
},
|
|
57
57
|
"typesVersions": {
|
|
58
58
|
"<4.0": {
|