Skip to content

Commit

Permalink
fix(util-waiter): remove type guard for client
Browse files Browse the repository at this point in the history
Remove the type guard to unblock #1803.
TODO: add type guard that doesn't block the compile
  • Loading branch information
AllanZhengYP committed Dec 23, 2020
1 parent 7115f31 commit dbd01e1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
1 change: 0 additions & 1 deletion packages/util-waiter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"tslib": "^1.8.0"
},
"devDependencies": {
"@aws-sdk/smithy-client": "3.0.0",
"@aws-sdk/types": "3.0.0",
"@types/jest": "^26.0.4",
"jest": "^26.1.0",
Expand Down
11 changes: 3 additions & 8 deletions packages/util-waiter/src/createWaiter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { AbortSignal } from "@aws-sdk/types";

import { runPolling } from "./poller";
import { sleep, validateWaiterOptions } from "./utils";
import { SmithyClient, WaiterOptions, WaiterResult, waiterServiceDefaults, WaiterState } from "./waiter";

const waiterTimeout = async (seconds: number): Promise<WaiterResult> => {
await sleep(seconds);
return { state: WaiterState.TIMEOUT };
};
import { validateWaiterOptions } from "./utils";
import { WaiterOptions, WaiterResult, waiterServiceDefaults, WaiterState } from "./waiter";

const abortTimeout = async (abortSignal: AbortSignal): Promise<WaiterResult> => {
return new Promise((resolve) => {
Expand All @@ -24,7 +19,7 @@ const abortTimeout = async (abortSignal: AbortSignal): Promise<WaiterResult> =>
*
* @internal
*/
export const createWaiter = async <Client extends SmithyClient, Input>(
export const createWaiter = async <Client, Input>(
options: WaiterOptions<Client>,
input: Input,
acceptorChecks: (client: Client, input: Input) => Promise<WaiterResult>
Expand Down
10 changes: 5 additions & 5 deletions packages/util-waiter/src/poller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sleep } from "./utils/sleep";
import { ResolvedWaiterOptions, SmithyClient, WaiterResult, WaiterState } from "./waiter";
import { ResolvedWaiterOptions, WaiterResult, WaiterState } from "./waiter";

/**
* Reference: https://awslabs.github.io/smithy/1.0/spec/waiters.html#waiter-retries
Expand All @@ -19,10 +19,10 @@ const randomInRange = (min: number, max: number) => min + Math.random() * (max -
* @param input client input
* @param stateChecker function that checks the acceptor states on each poll.
*/
export const runPolling = async <T extends SmithyClient, S>(
{ minDelay, maxDelay, maxWaitTime, abortController, client }: ResolvedWaiterOptions<T>,
input: S,
acceptorChecks: (client: T, input: S) => Promise<WaiterResult>
export const runPolling = async <Client, Input>(
{ minDelay, maxDelay, maxWaitTime, abortController, client }: ResolvedWaiterOptions<Client>,
input: Input,
acceptorChecks: (client: Client, input: Input) => Promise<WaiterResult>
): Promise<WaiterResult> => {
let currentAttempt = 1;
const waitUntil = Date.now() + maxWaitTime * 1000;
Expand Down
4 changes: 2 additions & 2 deletions packages/util-waiter/src/utils/validate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ResolvedWaiterOptions, SmithyClient } from "../waiter";
import { ResolvedWaiterOptions } from "../waiter";

/**
* Validates that waiter options are passed correctly
* @param options a waiter configuration object
*/
export const validateWaiterOptions = (options: ResolvedWaiterOptions<SmithyClient>): void => {
export const validateWaiterOptions = <Client>(options: ResolvedWaiterOptions<Client>): void => {
if (options.maxWaitTime < 1) {
throw `WaiterOptions.maxWaitTime must be greater than 0`;
} else if (options.maxWaitTime <= options.minDelay) {
Expand Down
13 changes: 4 additions & 9 deletions packages/util-waiter/src/waiter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Client, SmithyConfiguration } from "@aws-sdk/smithy-client";
import { AbortController, HttpHandlerOptions, MetadataBearer } from "@aws-sdk/types";
import { AbortController } from "@aws-sdk/types";

/**
* @internal
*/
export type SmithyClient = Client<HttpHandlerOptions, any, MetadataBearer, SmithyConfiguration<HttpHandlerOptions>>;
export interface WaiterConfiguration<Client extends SmithyClient> {
export interface WaiterConfiguration<Client> {
/**
* Required service client
*/
Expand All @@ -22,7 +17,7 @@ export interface WaiterConfiguration<Client extends SmithyClient> {
abortController?: AbortController;
}

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

export enum WaiterState {
Expand Down

0 comments on commit dbd01e1

Please sign in to comment.