1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | 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;
|
4 | const util_middleware_1 = require("@aws-sdk/util-middleware");
|
5 | const util_retry_1 = require("@aws-sdk/util-retry");
|
6 | exports.ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS";
|
7 | exports.CONFIG_MAX_ATTEMPTS = "max_attempts";
|
8 | exports.NODE_MAX_ATTEMPT_CONFIG_OPTIONS = {
|
9 | environmentVariableSelector: (env) => {
|
10 | const value = env[exports.ENV_MAX_ATTEMPTS];
|
11 | if (!value)
|
12 | return undefined;
|
13 | const maxAttempt = parseInt(value);
|
14 | if (Number.isNaN(maxAttempt)) {
|
15 | throw new Error(`Environment variable ${exports.ENV_MAX_ATTEMPTS} mast be a number, got "${value}"`);
|
16 | }
|
17 | return maxAttempt;
|
18 | },
|
19 | configFileSelector: (profile) => {
|
20 | const value = profile[exports.CONFIG_MAX_ATTEMPTS];
|
21 | if (!value)
|
22 | return undefined;
|
23 | const maxAttempt = parseInt(value);
|
24 | if (Number.isNaN(maxAttempt)) {
|
25 | throw new Error(`Shared config file entry ${exports.CONFIG_MAX_ATTEMPTS} mast be a number, got "${value}"`);
|
26 | }
|
27 | return maxAttempt;
|
28 | },
|
29 | default: util_retry_1.DEFAULT_MAX_ATTEMPTS,
|
30 | };
|
31 | const resolveRetryConfig = (input) => {
|
32 | var _a;
|
33 | const { retryStrategy } = input;
|
34 | const maxAttempts = (0, util_middleware_1.normalizeProvider)((_a = input.maxAttempts) !== null && _a !== void 0 ? _a : util_retry_1.DEFAULT_MAX_ATTEMPTS);
|
35 | return {
|
36 | ...input,
|
37 | maxAttempts,
|
38 | retryStrategy: async () => {
|
39 | if (retryStrategy) {
|
40 | return retryStrategy;
|
41 | }
|
42 | const retryMode = await (0, util_middleware_1.normalizeProvider)(input.retryMode)();
|
43 | if (retryMode === util_retry_1.RETRY_MODES.ADAPTIVE) {
|
44 | return new util_retry_1.AdaptiveRetryStrategy(maxAttempts);
|
45 | }
|
46 | return new util_retry_1.StandardRetryStrategy(maxAttempts);
|
47 | },
|
48 | };
|
49 | };
|
50 | exports.resolveRetryConfig = resolveRetryConfig;
|
51 | exports.ENV_RETRY_MODE = "AWS_RETRY_MODE";
|
52 | exports.CONFIG_RETRY_MODE = "retry_mode";
|
53 | exports.NODE_RETRY_MODE_CONFIG_OPTIONS = {
|
54 | environmentVariableSelector: (env) => env[exports.ENV_RETRY_MODE],
|
55 | configFileSelector: (profile) => profile[exports.CONFIG_RETRY_MODE],
|
56 | default: util_retry_1.DEFAULT_RETRY_MODE,
|
57 | };
|