New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-hive/gateway-abort-signal-any

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-hive/gateway-abort-signal-any - npm Package Compare versions

Comparing version 0.0.4-alpha-d8dc77bc27e4abf917b03c197fe569c509e54a72 to 1.0.0-alpha-d6fbffa3533e2ab4005a589cc73e1806eaa73756

15

CHANGELOG.md
# @graphql-hive/gateway-abort-signal-any
## 0.0.4-alpha-d8dc77bc27e4abf917b03c197fe569c509e54a72
## 1.0.0-alpha-d6fbffa3533e2ab4005a589cc73e1806eaa73756
### Patch Changes
### Major Changes
- [#407](https://github.com/graphql-hive/gateway/pull/407) [`d8dc77b`](https://github.com/graphql-hive/gateway/commit/d8dc77bc27e4abf917b03c197fe569c509e54a72) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
- [#593](https://github.com/graphql-hive/gateway/pull/593) [`d6fbffa`](https://github.com/graphql-hive/gateway/commit/d6fbffa3533e2ab4005a589cc73e1806eaa73756) Thanks [@enisdenjo](https://github.com/enisdenjo)! - `abortSignalAny` uses `AbortSignal.any` if available and falls back to `AbortController` for ponyfilling
- Added dependency [`@whatwg-node/disposablestack@^0.0.5` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.5) (to `dependencies`)
- [#593](https://github.com/graphql-hive/gateway/pull/593) [`d6fbffa`](https://github.com/graphql-hive/gateway/commit/d6fbffa3533e2ab4005a589cc73e1806eaa73756) Thanks [@enisdenjo](https://github.com/enisdenjo)! - `abortSignalAny` returns the native `AbortSignal`
- [#407](https://github.com/graphql-hive/gateway/pull/407) [`31d44e7`](https://github.com/graphql-hive/gateway/commit/31d44e76d3e17b29527b4604440c39687a0880f5) Thanks [@ardatan](https://github.com/ardatan)! - Introduce disposable timeout signals.
Instead of the custom `AbortSignalFromAny`. There is no need for the complication of adding signals to existing sets, chaining signals enough as well as simpler.
When `AbortSignal.timeout(MS)` is used, the timer is not cleaned up until it finishes.
This leads to memory leaks when the signal is not used anymore.
- [#593](https://github.com/graphql-hive/gateway/pull/593) [`d6fbffa`](https://github.com/graphql-hive/gateway/commit/d6fbffa3533e2ab4005a589cc73e1806eaa73756) Thanks [@enisdenjo](https://github.com/enisdenjo)! - `AbortSignal.any` ponyfill under `abortSignalAny` is now stable
This change introduces a disposable timeout signal that cleans up the timer when the signal is disposed, and in the plugins the signal is disposed whenever the operation is completed.
## 0.0.3

@@ -19,0 +16,0 @@

13

dist/index.d.ts

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

type AbortSignalFromAny = AbortSignal & {
signals: Set<AbortSignal>;
addSignals(signals: Iterable<AbortSignal>): void;
};
declare function isAbortSignalFromAny(signal?: AbortSignal | null): signal is AbortSignalFromAny;
declare function createTimeoutSignalWithDispose(timeout: number): {
signal: AbortSignal;
[Symbol.dispose](): void;
};
declare function abortSignalAny(givenSignals: Iterable<AbortSignal>): AbortSignal | undefined;
declare function abortSignalAny(iterable: Iterable<AbortSignal>): AbortSignal;
export { type AbortSignalFromAny, abortSignalAny, createTimeoutSignalWithDispose, isAbortSignalFromAny };
export { abortSignalAny };

@@ -1,78 +0,23 @@

import { registerAbortSignalListener } from '@graphql-tools/utils';
import { DisposableSymbols } from '@whatwg-node/disposablestack';
function isAbortSignalFromAny(signal) {
return signal != null && "signals" in signal && "addSignals" in signal;
}
function createTimeoutSignalWithDispose(timeout) {
const ctrl = new AbortController();
const id = setTimeout(
() => ctrl.abort(
new DOMException(
"The operation was aborted due to timeout",
"TimeoutError"
)
),
timeout
);
return {
signal: ctrl.signal,
[DisposableSymbols.dispose]() {
clearTimeout(id);
}
};
}
function abortSignalAny(givenSignals) {
const signals = /* @__PURE__ */ new Set();
let singleSignal;
for (const signal of givenSignals) {
if (isAbortSignalFromAny(signal)) {
for (const childSignal of signal.signals) {
singleSignal = childSignal;
signals.add(childSignal);
}
} else {
singleSignal = signal;
signals.add(signal);
}
function abortSignalAny(iterable) {
const signals = Array.from(iterable);
const aborted = signals.find((s) => s.aborted);
if (aborted) {
return aborted;
}
if (signals.size < 2) {
return singleSignal;
if ("any" in AbortSignal) {
return AbortSignal.any(signals);
}
if (signals.size === 0) {
return void 0;
}
const ctrl = new AbortController();
function onAbort(ev) {
const signal = this || ev?.target;
ctrl.abort(signal?.reason);
function abort() {
ctrl.abort(this.reason);
for (const signal of signals) {
signal.removeEventListener("abort", abort);
}
}
for (const signal of signals) {
registerAbortSignalListener(signal, onAbort);
signal.addEventListener("abort", abort);
}
Object.defineProperties(ctrl.signal, {
signals: { value: signals },
addSignals: {
value(newSignals) {
for (const signal of newSignals) {
if (isAbortSignalFromAny(signal)) {
for (const childSignal of signal.signals) {
if (!signals.has(childSignal)) {
signals.add(childSignal);
registerAbortSignalListener(childSignal, onAbort);
}
}
} else {
if (!signals.has(signal)) {
signals.add(signal);
registerAbortSignalListener(signal, onAbort);
}
}
}
}
}
});
return ctrl.signal;
}
export { abortSignalAny, createTimeoutSignalWithDispose, isAbortSignalFromAny };
export { abortSignalAny };
{
"name": "@graphql-hive/gateway-abort-signal-any",
"version": "0.0.4-alpha-d8dc77bc27e4abf917b03c197fe569c509e54a72",
"version": "1.0.0-alpha-d6fbffa3533e2ab4005a589cc73e1806eaa73756",
"type": "module",

@@ -41,3 +41,2 @@ "repository": {

"@graphql-tools/utils": "^10.7.0",
"@whatwg-node/disposablestack": "^0.0.5",
"tslib": "^2.8.1"

@@ -47,3 +46,3 @@ },

"graphql": "^16.9.0",
"pkgroll": "2.6.0"
"pkgroll": "2.6.1"
},

@@ -50,0 +49,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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