@smithy/middleware-retry 1.0.3 → 1.0.4
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-types/ts3.4/AdaptiveRetryStrategy.d.ts +20 -0
- package/dist-types/ts3.4/StandardRetryStrategy.d.ts +30 -0
- package/dist-types/ts3.4/configurations.d.ts +37 -0
- package/dist-types/ts3.4/defaultRetryQuota.d.ts +18 -0
- package/dist-types/ts3.4/delayDecider.d.ts +4 -0
- package/dist-types/ts3.4/index.d.ts +7 -0
- package/dist-types/ts3.4/omitRetryHeadersMiddleware.d.ts +4 -0
- package/dist-types/ts3.4/retryDecider.d.ts +2 -0
- package/dist-types/ts3.4/retryMiddleware.d.ts +6 -0
- package/dist-types/ts3.4/types.d.ts +53 -0
- package/dist-types/ts3.4/util.d.ts +2 -0
- package/package.json +8 -8
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FinalizeHandler, FinalizeHandlerArguments, MetadataBearer, Provider } from "@smithy/types";
|
|
2
|
+
import { RateLimiter } from "@smithy/util-retry";
|
|
3
|
+
import { StandardRetryStrategy, StandardRetryStrategyOptions } from "./StandardRetryStrategy";
|
|
4
|
+
/**
|
|
5
|
+
* Strategy options to be passed to AdaptiveRetryStrategy
|
|
6
|
+
*/
|
|
7
|
+
export interface AdaptiveRetryStrategyOptions extends StandardRetryStrategyOptions {
|
|
8
|
+
rateLimiter?: RateLimiter;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use AdaptiveRetryStrategy from @smithy/util-retry
|
|
12
|
+
*/
|
|
13
|
+
export declare class AdaptiveRetryStrategy extends StandardRetryStrategy {
|
|
14
|
+
private rateLimiter;
|
|
15
|
+
constructor(maxAttemptsProvider: Provider<number>, options?: AdaptiveRetryStrategyOptions);
|
|
16
|
+
retry<Input extends object, Ouput extends MetadataBearer>(next: FinalizeHandler<Input, Ouput>, args: FinalizeHandlerArguments<Input>): Promise<{
|
|
17
|
+
response: unknown;
|
|
18
|
+
output: Ouput;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FinalizeHandler, FinalizeHandlerArguments, MetadataBearer, Provider, RetryStrategy } from "@smithy/types";
|
|
2
|
+
import { DelayDecider, RetryDecider, RetryQuota } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Strategy options to be passed to StandardRetryStrategy
|
|
5
|
+
*/
|
|
6
|
+
export interface StandardRetryStrategyOptions {
|
|
7
|
+
retryDecider?: RetryDecider;
|
|
8
|
+
delayDecider?: DelayDecider;
|
|
9
|
+
retryQuota?: RetryQuota;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use StandardRetryStrategy from @smithy/util-retry
|
|
13
|
+
*/
|
|
14
|
+
export declare class StandardRetryStrategy implements RetryStrategy {
|
|
15
|
+
private readonly maxAttemptsProvider;
|
|
16
|
+
private retryDecider;
|
|
17
|
+
private delayDecider;
|
|
18
|
+
private retryQuota;
|
|
19
|
+
mode: string;
|
|
20
|
+
constructor(maxAttemptsProvider: Provider<number>, options?: StandardRetryStrategyOptions);
|
|
21
|
+
private shouldRetry;
|
|
22
|
+
private getMaxAttempts;
|
|
23
|
+
retry<Input extends object, Ouput extends MetadataBearer>(next: FinalizeHandler<Input, Ouput>, args: FinalizeHandlerArguments<Input>, options?: {
|
|
24
|
+
beforeRequest: Function;
|
|
25
|
+
afterRequest: Function;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
response: unknown;
|
|
28
|
+
output: Ouput;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
|
|
2
|
+
import { Provider, RetryStrategy, RetryStrategyV2 } from "@smithy/types";
|
|
3
|
+
export declare const ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS";
|
|
4
|
+
export declare const CONFIG_MAX_ATTEMPTS = "max_attempts";
|
|
5
|
+
export declare const NODE_MAX_ATTEMPT_CONFIG_OPTIONS: LoadedConfigSelectors<number>;
|
|
6
|
+
export interface RetryInputConfig {
|
|
7
|
+
/**
|
|
8
|
+
* The maximum number of times requests that encounter retryable failures should be attempted.
|
|
9
|
+
*/
|
|
10
|
+
maxAttempts?: number | Provider<number>;
|
|
11
|
+
/**
|
|
12
|
+
* The strategy to retry the request. Using built-in exponential backoff strategy by default.
|
|
13
|
+
*/
|
|
14
|
+
retryStrategy?: RetryStrategy | RetryStrategyV2;
|
|
15
|
+
}
|
|
16
|
+
interface PreviouslyResolved {
|
|
17
|
+
/**
|
|
18
|
+
* Specifies provider for retry algorithm to use.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
retryMode: string | Provider<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface RetryResolvedConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Resolved value for input config {@link RetryInputConfig.maxAttempts}
|
|
26
|
+
*/
|
|
27
|
+
maxAttempts: Provider<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Resolved value for input config {@link RetryInputConfig.retryStrategy}
|
|
30
|
+
*/
|
|
31
|
+
retryStrategy: Provider<RetryStrategyV2 | RetryStrategy>;
|
|
32
|
+
}
|
|
33
|
+
export declare const resolveRetryConfig: <T>(input: T & PreviouslyResolved & RetryInputConfig) => T & RetryResolvedConfig;
|
|
34
|
+
export declare const ENV_RETRY_MODE = "AWS_RETRY_MODE";
|
|
35
|
+
export declare const CONFIG_RETRY_MODE = "retry_mode";
|
|
36
|
+
export declare const NODE_RETRY_MODE_CONFIG_OPTIONS: LoadedConfigSelectors<string>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RetryQuota } from "./types";
|
|
2
|
+
export interface DefaultRetryQuotaOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The total amount of retry token to be incremented from retry token balance
|
|
5
|
+
* if an SDK operation invocation succeeds without requiring a retry request.
|
|
6
|
+
*/
|
|
7
|
+
noRetryIncrement?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The total amount of retry tokens to be decremented from retry token balance.
|
|
10
|
+
*/
|
|
11
|
+
retryCost?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The total amount of retry tokens to be decremented from retry token balance
|
|
14
|
+
* when a throttling error is encountered.
|
|
15
|
+
*/
|
|
16
|
+
timeoutRetryCost?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const getDefaultRetryQuota: (initialRetryTokens: number, options?: DefaultRetryQuotaOptions) => RetryQuota;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./AdaptiveRetryStrategy";
|
|
2
|
+
export * from "./StandardRetryStrategy";
|
|
3
|
+
export * from "./configurations";
|
|
4
|
+
export * from "./delayDecider";
|
|
5
|
+
export * from "./omitRetryHeadersMiddleware";
|
|
6
|
+
export * from "./retryDecider";
|
|
7
|
+
export * from "./retryMiddleware";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FinalizeHandler, MetadataBearer, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
|
|
2
|
+
export declare const omitRetryHeadersMiddleware: () => <Output extends MetadataBearer = MetadataBearer>(next: FinalizeHandler<any, Output>) => FinalizeHandler<any, Output>;
|
|
3
|
+
export declare const omitRetryHeadersMiddlewareOptions: RelativeMiddlewareOptions;
|
|
4
|
+
export declare const getOmitRetryHeadersPlugin: (options: unknown) => Pluggable<any, any>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbsoluteLocation, FinalizeHandler, FinalizeRequestHandlerOptions, HandlerExecutionContext, MetadataBearer, Pluggable } from "@smithy/types";
|
|
2
|
+
import { RetryResolvedConfig } from "./configurations";
|
|
3
|
+
export declare const retryMiddleware: (options: RetryResolvedConfig) => <Output extends MetadataBearer = MetadataBearer>(next: FinalizeHandler<any, Output>, context: HandlerExecutionContext) => FinalizeHandler<any, Output>;
|
|
4
|
+
export declare const retryMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLocation;
|
|
5
|
+
export declare const getRetryPlugin: (options: RetryResolvedConfig) => Pluggable<any, any>;
|
|
6
|
+
export declare const getRetryAfterHint: (response: unknown) => Date | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SdkError } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* Determines whether an error is retryable based on the number of retries
|
|
4
|
+
* already attempted, the HTTP status code, and the error received (if any).
|
|
5
|
+
*
|
|
6
|
+
* @param error - The error encountered.
|
|
7
|
+
*/
|
|
8
|
+
export interface RetryDecider {
|
|
9
|
+
(error: SdkError): boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Determines the number of milliseconds to wait before retrying an action.
|
|
13
|
+
*
|
|
14
|
+
* @param delayBase - The base delay (in milliseconds).
|
|
15
|
+
* @param attempts - The number of times the action has already been tried.
|
|
16
|
+
*/
|
|
17
|
+
export interface DelayDecider {
|
|
18
|
+
(delayBase: number, attempts: number): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface that specifies the retry quota behavior.
|
|
22
|
+
*/
|
|
23
|
+
export interface RetryQuota {
|
|
24
|
+
/**
|
|
25
|
+
* returns true if retry tokens are available from the retry quota bucket.
|
|
26
|
+
*/
|
|
27
|
+
hasRetryTokens: (error: SdkError) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* returns token amount from the retry quota bucket.
|
|
30
|
+
* throws error is retry tokens are not available.
|
|
31
|
+
*/
|
|
32
|
+
retrieveRetryTokens: (error: SdkError) => number;
|
|
33
|
+
/**
|
|
34
|
+
* releases tokens back to the retry quota.
|
|
35
|
+
*/
|
|
36
|
+
releaseRetryTokens: (releaseCapacityAmount?: number) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface RateLimiter {
|
|
39
|
+
/**
|
|
40
|
+
* If there is sufficient capacity (tokens) available, it immediately returns.
|
|
41
|
+
* If there is not sufficient capacity, it will either sleep a certain amount
|
|
42
|
+
* of time until the rate limiter can retrieve a token from its token bucket
|
|
43
|
+
* or raise an exception indicating there is insufficient capacity.
|
|
44
|
+
*/
|
|
45
|
+
getSendToken: () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Updates the client sending rate based on response.
|
|
48
|
+
* If the response was successful, the capacity and fill rate are increased.
|
|
49
|
+
* If the response was a throttling response, the capacity and fill rate are
|
|
50
|
+
* decreased. Transient errors do not affect the rate limiter.
|
|
51
|
+
*/
|
|
52
|
+
updateClientSendingRate: (response: any) => void;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/middleware-retry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
5
|
+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
8
|
"build:types": "tsc -p tsconfig.types.json",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@smithy/protocol-http": "^1.1.
|
|
27
|
-
"@smithy/service-error-classification": "^1.0.
|
|
28
|
-
"@smithy/types": "^1.1.
|
|
29
|
-
"@smithy/util-middleware": "^1.0.
|
|
30
|
-
"@smithy/util-retry": "^1.0.
|
|
26
|
+
"@smithy/protocol-http": "^1.1.1",
|
|
27
|
+
"@smithy/service-error-classification": "^1.0.3",
|
|
28
|
+
"@smithy/types": "^1.1.1",
|
|
29
|
+
"@smithy/util-middleware": "^1.0.2",
|
|
30
|
+
"@smithy/util-retry": "^1.0.4",
|
|
31
31
|
"tslib": "^2.5.0",
|
|
32
32
|
"uuid": "^8.3.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@smithy/node-config-provider": "^1.0.
|
|
35
|
+
"@smithy/node-config-provider": "^1.0.2",
|
|
36
36
|
"@tsconfig/recommended": "1.0.1",
|
|
37
37
|
"@types/uuid": "^8.3.0",
|
|
38
38
|
"concurrently": "7.0.0",
|