import { AsyncLocalStorage } from "node:async_hooks"; export function createContext(name: string) { const storage = new AsyncLocalStorage(); return { use() { const result = storage.getStore(); if (!result) { throw new Error("Context not provided: " + name); } return result; }, with(value: T, fn: () => R) { return storage.run(value, fn); }, }; }