Skip to content

Commit ca1f0d6

Browse files
authored
fix(util-waiter): fix compiling error with waiter (#1812)
* fix(util-waiter): fix compiling error with waiter * fix(util-waiter): remove type guard for client Remove the type guard to unblock #1803. TODO: add type guard that doesn't block the compile
1 parent e539302 commit ca1f0d6

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

Diff for: packages/util-waiter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "Shared utilities for client waiters for the AWS SDK",
55
"dependencies": {
66
"@aws-sdk/abort-controller": "3.0.0",
7-
"@aws-sdk/types": "3.0.0",
87
"tslib": "^1.8.0"
98
},
109
"devDependencies": {
10+
"@aws-sdk/types": "3.0.0",
1111
"@types/jest": "^26.0.4",
1212
"jest": "^26.1.0",
1313
"typescript": "~4.1.2"

Diff for: packages/util-waiter/src/createWaiter.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { AbortSignal } from "@aws-sdk/types";
22

33
import { runPolling } from "./poller";
4-
import { sleep, validateWaiterOptions } from "./utils";
5-
import { SmithyClient, WaiterOptions, WaiterResult, waiterServiceDefaults, WaiterState } from "./waiter";
6-
7-
const waiterTimeout = async (seconds: number): Promise<WaiterResult> => {
8-
await sleep(seconds);
9-
return { state: WaiterState.TIMEOUT };
10-
};
4+
import { validateWaiterOptions } from "./utils";
5+
import { WaiterOptions, WaiterResult, waiterServiceDefaults, WaiterState } from "./waiter";
116

127
const abortTimeout = async (abortSignal: AbortSignal): Promise<WaiterResult> => {
138
return new Promise((resolve) => {
@@ -24,7 +19,7 @@ const abortTimeout = async (abortSignal: AbortSignal): Promise<WaiterResult> =>
2419
*
2520
* @internal
2621
*/
27-
export const createWaiter = async <Client extends SmithyClient, Input>(
22+
export const createWaiter = async <Client, Input>(
2823
options: WaiterOptions<Client>,
2924
input: Input,
3025
acceptorChecks: (client: Client, input: Input) => Promise<WaiterResult>

Diff for: packages/util-waiter/src/poller.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sleep } from "./utils/sleep";
2-
import { ResolvedWaiterOptions, SmithyClient, WaiterResult, WaiterState } from "./waiter";
2+
import { ResolvedWaiterOptions, WaiterResult, WaiterState } from "./waiter";
33

44
/**
55
* Reference: https://awslabs.github.io/smithy/1.0/spec/waiters.html#waiter-retries
@@ -19,10 +19,10 @@ const randomInRange = (min: number, max: number) => min + Math.random() * (max -
1919
* @param input client input
2020
* @param stateChecker function that checks the acceptor states on each poll.
2121
*/
22-
export const runPolling = async <T extends SmithyClient, S>(
23-
{ minDelay, maxDelay, maxWaitTime, abortController, client }: ResolvedWaiterOptions<T>,
24-
input: S,
25-
acceptorChecks: (client: T, input: S) => Promise<WaiterResult>
22+
export const runPolling = async <Client, Input>(
23+
{ minDelay, maxDelay, maxWaitTime, abortController, client }: ResolvedWaiterOptions<Client>,
24+
input: Input,
25+
acceptorChecks: (client: Client, input: Input) => Promise<WaiterResult>
2626
): Promise<WaiterResult> => {
2727
let currentAttempt = 1;
2828
const waitUntil = Date.now() + maxWaitTime * 1000;

Diff for: packages/util-waiter/src/utils/validate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ResolvedWaiterOptions, SmithyClient } from "../waiter";
1+
import { ResolvedWaiterOptions } from "../waiter";
22

33
/**
44
* Validates that waiter options are passed correctly
55
* @param options a waiter configuration object
66
*/
7-
export const validateWaiterOptions = (options: ResolvedWaiterOptions<SmithyClient>): void => {
7+
export const validateWaiterOptions = <Client>(options: ResolvedWaiterOptions<Client>): void => {
88
if (options.maxWaitTime < 1) {
99
throw `WaiterOptions.maxWaitTime must be greater than 0`;
1010
} else if (options.maxWaitTime <= options.minDelay) {

Diff for: packages/util-waiter/src/waiter.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { AbortController, Client } from "@aws-sdk/types";
1+
import { AbortController } from "@aws-sdk/types";
22

3-
/**
4-
* @internal
5-
*/
6-
export type SmithyClient = Client<any, any, any>;
7-
export interface WaiterConfiguration<Client extends SmithyClient> {
3+
export interface WaiterConfiguration<Client> {
84
/**
95
* Required service client
106
*/
@@ -21,7 +17,7 @@ export interface WaiterConfiguration<Client extends SmithyClient> {
2117
abortController?: AbortController;
2218
}
2319

24-
export interface WaiterOptions<Client extends SmithyClient> extends WaiterConfiguration<Client> {
20+
export interface WaiterOptions<Client> extends WaiterConfiguration<Client> {
2521
/**
2622
* The minimum amount of time to delay between retries in seconds. This value defaults
2723
* to 2 if not specified. If specified, this value MUST be greater than or equal to 1
@@ -48,7 +44,7 @@ export const waiterServiceDefaults = {
4844
/**
4945
* @private
5046
*/
51-
export type ResolvedWaiterOptions<Client extends SmithyClient> = WaiterOptions<Client> &
47+
export type ResolvedWaiterOptions<Client> = WaiterOptions<Client> &
5248
Required<Pick<WaiterOptions<Client>, "minDelay" | "maxDelay">>;
5349

5450
export enum WaiterState {

0 commit comments

Comments
 (0)