Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util-waiter): fix compiling error with waiter #1812

Merged
merged 2 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/util-waiter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "Shared utilities for client waiters for the AWS SDK",
"dependencies": {
"@aws-sdk/abort-controller": "3.0.0",
"@aws-sdk/types": "3.0.0",
"tslib": "^1.8.0"
},
"devDependencies": {
"@aws-sdk/types": "3.0.0",
"@types/jest": "^26.0.4",
"jest": "^26.1.0",
"typescript": "~4.1.2"
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
12 changes: 4 additions & 8 deletions packages/util-waiter/src/waiter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { AbortController, Client } from "@aws-sdk/types";
import { AbortController } from "@aws-sdk/types";

/**
* @internal
*/
export type SmithyClient = Client<any, any, any>;
export interface WaiterConfiguration<Client extends SmithyClient> {
export interface WaiterConfiguration<Client> {
/**
* Required service client
*/
Expand All @@ -21,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 @@ -48,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