chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:32:57 +08:00
commit cd420f9332
4811 changed files with 884702 additions and 0 deletions
@@ -0,0 +1,33 @@
import { AsyncLocalStorage } from "node:async_hooks";
export type HttpLocalStorage = {
requestId: string;
path: string;
host: string;
method: string;
abortController: AbortController;
};
const httpLocalStorage = new AsyncLocalStorage<HttpLocalStorage>();
export type RunWithHttpContextFunction = <T>(context: HttpLocalStorage, fn: () => T) => T;
export function runWithHttpContext<T>(context: HttpLocalStorage, fn: () => T): T {
return httpLocalStorage.run(context, fn);
}
export function getHttpContext(): HttpLocalStorage | undefined {
return httpLocalStorage.getStore();
}
// Fallback signal that is never aborted, safe for tests and non-Express contexts.
const neverAbortedSignal = new AbortController().signal;
/**
* Returns an AbortSignal wired to the Express response's "close" event.
* This bypasses the broken request.signal chain in @remix-run/express
* (caused by Node.js undici GC bug nodejs/node#55428).
*/
export function getRequestAbortSignal(): AbortSignal {
return httpLocalStorage.getStore()?.abortController.signal ?? neverAbortedSignal;
}