import { AsyncLocalStorage } from "node:async_hooks"; export type ScopeKey = string | symbol; export type ScopedStateMaps = Map>; export interface ScopedStateStoreOwner { scopedStateMaps: ScopedStateMaps; } export const currentAppStorage = new AsyncLocalStorage(); export const requestStorage = new AsyncLocalStorage(); export const GLOBAL_SCOPE: unique symbol = Symbol("raven:global"); export function getOrCreateScopeMap(parent: ScopedStateMaps, key: ScopeKey): Map { let map = parent.get(key); if (!map) { map = new Map(); parent.set(key, map); } return map; }