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

@smithy/util-waiter

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/util-waiter - npm Package Compare versions

Comparing version 2.0.16 to 2.1.0

28

dist-cjs/createWaiter.js

@@ -1,27 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWaiter = void 0;
const poller_1 = require("./poller");
const utils_1 = require("./utils");
const waiter_1 = require("./waiter");
const abortTimeout = async (abortSignal) => {
return new Promise((resolve) => {
abortSignal.onabort = () => resolve({ state: waiter_1.WaiterState.ABORTED });
});
};
const createWaiter = async (options, input, acceptorChecks) => {
const params = {
...waiter_1.waiterServiceDefaults,
...options,
};
(0, utils_1.validateWaiterOptions)(params);
const exitConditions = [(0, poller_1.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);
};
exports.createWaiter = createWaiter;
module.exports = require("./index.js");

158

dist-cjs/index.js

@@ -1,5 +0,153 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./createWaiter"), exports);
tslib_1.__exportStar(require("./waiter"), exports);
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
WaiterState: () => WaiterState,
checkExceptions: () => checkExceptions,
createWaiter: () => createWaiter,
waiterServiceDefaults: () => waiterServiceDefaults
});
module.exports = __toCommonJS(src_exports);
// src/utils/sleep.ts
var sleep = /* @__PURE__ */ __name((seconds) => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
}, "sleep");
// src/waiter.ts
var waiterServiceDefaults = {
minDelay: 2,
maxDelay: 120
};
var WaiterState = /* @__PURE__ */ ((WaiterState2) => {
WaiterState2["ABORTED"] = "ABORTED";
WaiterState2["FAILURE"] = "FAILURE";
WaiterState2["SUCCESS"] = "SUCCESS";
WaiterState2["RETRY"] = "RETRY";
WaiterState2["TIMEOUT"] = "TIMEOUT";
return WaiterState2;
})(WaiterState || {});
var checkExceptions = /* @__PURE__ */ __name((result) => {
if (result.state === "ABORTED" /* ABORTED */) {
const abortError = new Error(
`${JSON.stringify({
...result,
reason: "Request was aborted"
})}`
);
abortError.name = "AbortError";
throw abortError;
} else if (result.state === "TIMEOUT" /* TIMEOUT */) {
const timeoutError = new Error(
`${JSON.stringify({
...result,
reason: "Waiter has timed out"
})}`
);
timeoutError.name = "TimeoutError";
throw timeoutError;
} else if (result.state !== "SUCCESS" /* SUCCESS */) {
throw new Error(`${JSON.stringify({ result })}`);
}
return result;
}, "checkExceptions");
// src/poller.ts
var exponentialBackoffWithJitter = /* @__PURE__ */ __name((minDelay, maxDelay, attemptCeiling, attempt) => {
if (attempt > attemptCeiling)
return maxDelay;
const delay = minDelay * 2 ** (attempt - 1);
return randomInRange(minDelay, delay);
}, "exponentialBackoffWithJitter");
var randomInRange = /* @__PURE__ */ __name((min, max) => min + Math.random() * (max - min), "randomInRange");
var runPolling = /* @__PURE__ */ __name(async ({ minDelay, maxDelay, maxWaitTime, abortController, client, abortSignal }, input, acceptorChecks) => {
var _a;
const { state, reason } = await acceptorChecks(client, input);
if (state !== "RETRY" /* RETRY */) {
return { state, reason };
}
let currentAttempt = 1;
const waitUntil = Date.now() + maxWaitTime * 1e3;
const attemptCeiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
while (true) {
if (((_a = abortController == null ? void 0 : abortController.signal) == null ? void 0 : _a.aborted) || (abortSignal == null ? void 0 : abortSignal.aborted)) {
return { state: "ABORTED" /* ABORTED */ };
}
const delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt);
if (Date.now() + delay * 1e3 > waitUntil) {
return { state: "TIMEOUT" /* TIMEOUT */ };
}
await sleep(delay);
const { state: state2, reason: reason2 } = await acceptorChecks(client, input);
if (state2 !== "RETRY" /* RETRY */) {
return { state: state2, reason: reason2 };
}
currentAttempt += 1;
}
}, "runPolling");
// src/utils/validate.ts
var validateWaiterOptions = /* @__PURE__ */ __name((options) => {
if (options.maxWaitTime < 1) {
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`);
} else if (options.maxDelay < 1) {
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`
);
} else if (options.maxDelay < options.minDelay) {
throw new Error(
`WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`
);
}
}, "validateWaiterOptions");
// src/createWaiter.ts
var abortTimeout = /* @__PURE__ */ __name(async (abortSignal) => {
return new Promise((resolve) => {
abortSignal.onabort = () => resolve({ state: "ABORTED" /* ABORTED */ });
});
}, "abortTimeout");
var createWaiter = /* @__PURE__ */ __name(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);
}, "createWaiter");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
WaiterState,
checkExceptions,
createWaiter,
waiterServiceDefaults
});

@@ -1,38 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runPolling = void 0;
const sleep_1 = require("./utils/sleep");
const waiter_1 = require("./waiter");
const exponentialBackoffWithJitter = (minDelay, maxDelay, attemptCeiling, attempt) => {
if (attempt > attemptCeiling)
return maxDelay;
const delay = minDelay * 2 ** (attempt - 1);
return randomInRange(minDelay, delay);
};
const randomInRange = (min, max) => min + Math.random() * (max - min);
const runPolling = async ({ minDelay, maxDelay, maxWaitTime, abortController, client, abortSignal }, input, acceptorChecks) => {
var _a;
const { state, reason } = await acceptorChecks(client, input);
if (state !== waiter_1.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 (((_a = abortController === null || abortController === void 0 ? void 0 : abortController.signal) === null || _a === void 0 ? void 0 : _a.aborted) || (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
return { state: waiter_1.WaiterState.ABORTED };
}
const delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt);
if (Date.now() + delay * 1000 > waitUntil) {
return { state: waiter_1.WaiterState.TIMEOUT };
}
await (0, sleep_1.sleep)(delay);
const { state, reason } = await acceptorChecks(client, input);
if (state !== waiter_1.WaiterState.RETRY) {
return { state, reason };
}
currentAttempt += 1;
}
};
exports.runPolling = runPolling;
module.exports = require("./index.js");

@@ -1,5 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./sleep"), exports);
tslib_1.__exportStar(require("./validate"), exports);
module.exports = require("../index.js");

@@ -1,7 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sleep = void 0;
const sleep = (seconds) => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
};
exports.sleep = sleep;
module.exports = require("../index.js");

@@ -1,21 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateWaiterOptions = void 0;
const validateWaiterOptions = (options) => {
if (options.maxWaitTime < 1) {
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`);
}
else if (options.maxDelay < 1) {
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`);
}
else if (options.maxDelay < options.minDelay) {
throw new Error(`WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`);
}
};
exports.validateWaiterOptions = validateWaiterOptions;
module.exports = require("../index.js");

@@ -1,38 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkExceptions = exports.WaiterState = exports.waiterServiceDefaults = void 0;
exports.waiterServiceDefaults = {
minDelay: 2,
maxDelay: 120,
};
var WaiterState;
(function (WaiterState) {
WaiterState["ABORTED"] = "ABORTED";
WaiterState["FAILURE"] = "FAILURE";
WaiterState["SUCCESS"] = "SUCCESS";
WaiterState["RETRY"] = "RETRY";
WaiterState["TIMEOUT"] = "TIMEOUT";
})(WaiterState = exports.WaiterState || (exports.WaiterState = {}));
const checkExceptions = (result) => {
if (result.state === WaiterState.ABORTED) {
const abortError = new Error(`${JSON.stringify({
...result,
reason: "Request was aborted",
})}`);
abortError.name = "AbortError";
throw abortError;
}
else if (result.state === WaiterState.TIMEOUT) {
const timeoutError = new Error(`${JSON.stringify({
...result,
reason: "Waiter has timed out",
})}`);
timeoutError.name = "TimeoutError";
throw timeoutError;
}
else if (result.state !== WaiterState.SUCCESS) {
throw new Error(`${JSON.stringify({ result })}`);
}
return result;
};
exports.checkExceptions = checkExceptions;
module.exports = require("./index.js");
{
"name": "@smithy/util-waiter",
"version": "2.0.16",
"version": "2.1.0",
"description": "Shared utilities for client waiters for the AWS SDK",
"dependencies": {
"@smithy/abort-controller": "^2.0.16",
"@smithy/types": "^2.8.0",
"@smithy/abort-controller": "^2.1.0",
"@smithy/types": "^2.9.0",
"tslib": "^2.5.0"

@@ -12,3 +12,3 @@ },

"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
"build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
"build:cjs": "node ../../scripts/inline util-waiter",
"build:es": "yarn g:tsc -p tsconfig.es.json",

@@ -15,0 +15,0 @@ "build:types": "yarn g:tsc -p tsconfig.types.json",

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