Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-sdk/util-waiter

Package Overview
Dependencies
Maintainers
5
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/util-waiter - npm Package Compare versions

Comparing version 3.183.0 to 3.186.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
**Note:** Version bump only for package @aws-sdk/util-waiter
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)

@@ -8,0 +16,0 @@

41

dist-es/createWaiter.js

@@ -0,23 +1,26 @@

import { __assign, __awaiter, __generator } from "tslib";
import { runPolling } from "./poller";
import { validateWaiterOptions } from "./utils";
import { waiterServiceDefaults, WaiterState } from "./waiter";
const abortTimeout = async (abortSignal) => {
return new Promise((resolve) => {
abortSignal.onabort = () => resolve({ state: WaiterState.ABORTED });
var abortTimeout = function (abortSignal) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (resolve) {
abortSignal.onabort = function () { return resolve({ state: WaiterState.ABORTED }); };
})];
});
};
export const createWaiter = async (options, input, acceptorChecks) => {
const params = {
...waiterServiceDefaults,
...options,
};
validateWaiterOptions(params);
const exitConditions = [runPolling(params, input, acceptorChecks)];
if (options.abortController) {
exitConditions.push(abortTimeout(options.abortController.signal));
}
if (options.abortSignal) {
exitConditions.push(abortTimeout(options.abortSignal));
}
return Promise.race(exitConditions);
};
}); };
export var createWaiter = function (options, input, acceptorChecks) { return __awaiter(void 0, void 0, void 0, function () {
var params, exitConditions;
return __generator(this, function (_a) {
params = __assign(__assign({}, waiterServiceDefaults), options);
validateWaiterOptions(params);
exitConditions = [runPolling(params, input, acceptorChecks)];
if (options.abortController) {
exitConditions.push(abortTimeout(options.abortController.signal));
}
if (options.abortSignal) {
exitConditions.push(abortTimeout(options.abortSignal));
}
return [2, Promise.race(exitConditions)];
});
}); };

@@ -0,33 +1,52 @@

import { __awaiter, __generator } from "tslib";
import { sleep } from "./utils/sleep";
import { WaiterState } from "./waiter";
const exponentialBackoffWithJitter = (minDelay, maxDelay, attemptCeiling, attempt) => {
var exponentialBackoffWithJitter = function (minDelay, maxDelay, attemptCeiling, attempt) {
if (attempt > attemptCeiling)
return maxDelay;
const delay = minDelay * 2 ** (attempt - 1);
var delay = minDelay * Math.pow(2, (attempt - 1));
return randomInRange(minDelay, delay);
};
const randomInRange = (min, max) => min + Math.random() * (max - min);
export const runPolling = async ({ minDelay, maxDelay, maxWaitTime, abortController, client, abortSignal }, input, acceptorChecks) => {
const { state, reason } = await acceptorChecks(client, input);
if (state !== WaiterState.RETRY) {
return { state, reason };
}
let currentAttempt = 1;
const waitUntil = Date.now() + maxWaitTime * 1000;
const attemptCeiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
while (true) {
if (abortController?.signal?.aborted || abortSignal?.aborted) {
return { state: WaiterState.ABORTED };
}
const delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt);
if (Date.now() + delay * 1000 > waitUntil) {
return { state: WaiterState.TIMEOUT };
}
await sleep(delay);
const { state, reason } = await acceptorChecks(client, input);
if (state !== WaiterState.RETRY) {
return { state, reason };
}
currentAttempt += 1;
}
var randomInRange = function (min, max) { return min + Math.random() * (max - min); };
export var runPolling = function (_a, input, acceptorChecks) {
var minDelay = _a.minDelay, maxDelay = _a.maxDelay, maxWaitTime = _a.maxWaitTime, abortController = _a.abortController, client = _a.client, abortSignal = _a.abortSignal;
return __awaiter(void 0, void 0, void 0, function () {
var _b, state, reason, currentAttempt, waitUntil, attemptCeiling, delay, _c, state_1, reason_1;
var _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0: return [4, acceptorChecks(client, input)];
case 1:
_b = _e.sent(), state = _b.state, reason = _b.reason;
if (state !== WaiterState.RETRY) {
return [2, { state: state, reason: reason }];
}
currentAttempt = 1;
waitUntil = Date.now() + maxWaitTime * 1000;
attemptCeiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
_e.label = 2;
case 2:
if (!true) return [3, 5];
if (((_d = abortController === null || abortController === void 0 ? void 0 : abortController.signal) === null || _d === void 0 ? void 0 : _d.aborted) || (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
return [2, { state: WaiterState.ABORTED }];
}
delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt);
if (Date.now() + delay * 1000 > waitUntil) {
return [2, { state: WaiterState.TIMEOUT }];
}
return [4, sleep(delay)];
case 3:
_e.sent();
return [4, acceptorChecks(client, input)];
case 4:
_c = _e.sent(), state_1 = _c.state, reason_1 = _c.reason;
if (state_1 !== WaiterState.RETRY) {
return [2, { state: state_1, reason: reason_1 }];
}
currentAttempt += 1;
return [3, 2];
case 5: return [2];
}
});
});
};

@@ -1,3 +0,3 @@

export const sleep = (seconds) => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
export var sleep = function (seconds) {
return new Promise(function (resolve) { return setTimeout(resolve, seconds * 1000); });
};

@@ -1,17 +0,17 @@

export const validateWaiterOptions = (options) => {
export var validateWaiterOptions = function (options) {
if (options.maxWaitTime < 1) {
throw new Error(`WaiterConfiguration.maxWaitTime must be greater than 0`);
throw new Error("WaiterConfiguration.maxWaitTime must be greater than 0");
}
else if (options.minDelay < 1) {
throw new Error(`WaiterConfiguration.minDelay must be greater than 0`);
throw new Error("WaiterConfiguration.minDelay must be greater than 0");
}
else if (options.maxDelay < 1) {
throw new Error(`WaiterConfiguration.maxDelay must be greater than 0`);
throw new Error("WaiterConfiguration.maxDelay must be greater than 0");
}
else if (options.maxWaitTime <= options.minDelay) {
throw new Error(`WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`);
throw new Error("WaiterConfiguration.maxWaitTime [".concat(options.maxWaitTime, "] must be greater than WaiterConfiguration.minDelay [").concat(options.minDelay, "] for this waiter"));
}
else if (options.maxDelay < options.minDelay) {
throw new Error(`WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`);
throw new Error("WaiterConfiguration.maxDelay [".concat(options.maxDelay, "] must be greater than WaiterConfiguration.minDelay [").concat(options.minDelay, "] for this waiter"));
}
};

@@ -1,2 +0,3 @@

export const waiterServiceDefaults = {
import { __assign } from "tslib";
export var waiterServiceDefaults = {
minDelay: 2,

@@ -13,8 +14,5 @@ maxDelay: 120,

})(WaiterState || (WaiterState = {}));
export const checkExceptions = (result) => {
export var checkExceptions = function (result) {
if (result.state === WaiterState.ABORTED) {
const abortError = new Error(`${JSON.stringify({
...result,
reason: "Request was aborted",
})}`);
var abortError = new Error("".concat(JSON.stringify(__assign(__assign({}, result), { reason: "Request was aborted" }))));
abortError.name = "AbortError";

@@ -24,6 +22,3 @@ throw abortError;

else if (result.state === WaiterState.TIMEOUT) {
const timeoutError = new Error(`${JSON.stringify({
...result,
reason: "Waiter has timed out",
})}`);
var timeoutError = new Error("".concat(JSON.stringify(__assign(__assign({}, result), { reason: "Waiter has timed out" }))));
timeoutError.name = "TimeoutError";

@@ -33,5 +28,5 @@ throw timeoutError;

else if (result.state !== WaiterState.SUCCESS) {
throw new Error(`${JSON.stringify({ result })}`);
throw new Error("".concat(JSON.stringify({ result: result })));
}
return result;
};
{
"name": "@aws-sdk/util-waiter",
"version": "3.183.0",
"version": "3.186.0",
"description": "Shared utilities for client waiters for the AWS SDK",
"dependencies": {
"@aws-sdk/abort-controller": "3.183.0",
"@aws-sdk/types": "3.183.0",
"@aws-sdk/abort-controller": "3.186.0",
"@aws-sdk/types": "3.186.0",
"tslib": "^2.3.1"

@@ -9,0 +9,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc