Skip to content

Commit dbd01e1

Browse files
committed
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 7115f31 commit dbd01e1

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

packages/util-waiter/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"tslib": "^1.8.0"
88
},
99
"devDependencies": {
10-
"@aws-sdk/smithy-client": "3.0.0",
1110
"@aws-sdk/types": "3.0.0",
1211
"@types/jest": "^26.0.4",
1312
"jest": "^26.1.0",

packages/util-waiter/src/createWaiter.ts

Lines changed: 3 additions & 8 deletions
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>

packages/util-waiter/src/poller.ts

Lines changed: 5 additions & 5 deletions
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;

packages/util-waiter/src/utils/validate.ts

Lines changed: 2 additions & 2 deletions
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) {

packages/util-waiter/src/waiter.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { Client, SmithyConfiguration } from "@aws-sdk/smithy-client";
2-
import { AbortController, HttpHandlerOptions, MetadataBearer } from "@aws-sdk/types";
1+
import { AbortController } from "@aws-sdk/types";
32

4-
/**
5-
* @internal
6-
*/
7-
export type SmithyClient = Client<HttpHandlerOptions, any, MetadataBearer, SmithyConfiguration<HttpHandlerOptions>>;
8-
export interface WaiterConfiguration<Client extends SmithyClient> {
3+
export interface WaiterConfiguration<Client> {
94
/**
105
* Required service client
116
*/
@@ -22,7 +17,7 @@ export interface WaiterConfiguration<Client extends SmithyClient> {
2217
abortController?: AbortController;
2318
}
2419

25-
export interface WaiterOptions<Client extends SmithyClient> extends WaiterConfiguration<Client> {
20+
export interface WaiterOptions<Client> extends WaiterConfiguration<Client> {
2621
/**
2722
* The minimum amount of time to delay between retries in seconds. This value defaults
2823
* to 2 if not specified. If specified, this value MUST be greater than or equal to 1
@@ -49,7 +44,7 @@ export const waiterServiceDefaults = {
4944
/**
5045
* @private
5146
*/
52-
export type ResolvedWaiterOptions<Client extends SmithyClient> = WaiterOptions<Client> &
47+
export type ResolvedWaiterOptions<Client> = WaiterOptions<Client> &
5348
Required<Pick<WaiterOptions<Client>, "minDelay" | "maxDelay">>;
5449

5550
export enum WaiterState {

0 commit comments

Comments
 (0)