{"version":3,"file":"resolution-context.mjs","names":["createAsyncLocalStorage","resolutionContext","getResolutionContext","withResolutionContext","waiterHolder","getHolder","fn","run","getCurrentResolutionContext","getStore","withoutResolutionContext","undefined"],"sources":["../../../../src/internal/context/resolution-context.mts"],"sourcesContent":["import type { InstanceHolder } from '../holder/instance-holder.mjs'\nimport type { IAsyncLocalStorage } from './async-local-storage.types.mjs'\n\nimport { createAsyncLocalStorage } from './async-local-storage.mjs'\n\n/**\n * Data stored in the resolution context during service instantiation.\n */\nexport interface ResolutionContextData {\n  /** The holder that is currently being instantiated */\n  waiterHolder: InstanceHolder\n  /** Function to get a holder by name (for cycle detection) */\n  getHolder: (name: string) => InstanceHolder | undefined\n}\n\n/**\n * AsyncLocalStorage for tracking the current resolution context.\n *\n * This allows tracking which service is being instantiated even across\n * async boundaries (like when inject() is called inside a constructor).\n * Essential for circular dependency detection.\n *\n * The actual implementation varies by environment:\n * - Production: No-op (returns undefined, run() just calls fn directly)\n * - Development: Real AsyncLocalStorage with full async tracking\n * - Browser: SyncLocalStorage for synchronous-only tracking\n */\nlet resolutionContext: IAsyncLocalStorage<ResolutionContextData> | null = null\n\nfunction getResolutionContext(): IAsyncLocalStorage<ResolutionContextData> {\n  if (!resolutionContext) {\n    resolutionContext = createAsyncLocalStorage<ResolutionContextData>()\n  }\n  return resolutionContext\n}\n\n/**\n * Runs a function within a resolution context.\n *\n * The context tracks which holder is currently being instantiated,\n * allowing circular dependency detection to work correctly.\n *\n * @param waiterHolder The holder being instantiated\n * @param getHolder Function to retrieve holders by name\n * @param fn The function to run within the context\n */\nexport function withResolutionContext<T>(\n  waiterHolder: InstanceHolder,\n  getHolder: (name: string) => InstanceHolder | undefined,\n  fn: () => T,\n): T {\n  return getResolutionContext().run({ waiterHolder, getHolder }, fn)\n}\n\n/**\n * Gets the current resolution context, if any.\n *\n * Returns undefined if we're not inside a resolution context\n * (e.g., when resolving a top-level service that has no parent).\n */\nexport function getCurrentResolutionContext():\n  | ResolutionContextData\n  | undefined {\n  return getResolutionContext().getStore()\n}\n\n/**\n * Runs a function outside any resolution context.\n *\n * This is useful for async injections that should not participate\n * in circular dependency detection since they don't block.\n *\n * @param fn The function to run without resolution context\n */\nexport function withoutResolutionContext<T>(fn: () => T): T {\n  // Run with undefined context to clear any current context\n  return getResolutionContext().run(\n    undefined as unknown as ResolutionContextData,\n    fn,\n  )\n}\n\n"],"mappings":";;;;;;;;;;;;;;GA2BA,IAAIC,oBAAsE;AAE1E,SAASC,uBAAAA;AACP,KAAI,CAACD,kBACHA,qBAAoBD,yBAAAA;AAEtB,QAAOC;;;;;;;;;;;GAaT,SAAgBE,sBACdC,cACAC,WACAC,IAAW;AAEX,QAAOJ,sBAAAA,CAAuBK,IAAI;EAAEH;EAAcC;EAAU,EAAGC,GAAAA;;;;;;;GASjE,SAAgBE,8BAAAA;AAGd,QAAON,sBAAAA,CAAuBO,UAAQ;;;;;;;;;GAWxC,SAAgBC,yBAA4BJ,IAAW;AAErD,QAAOJ,sBAAAA,CAAuBK,IAC5BI,QACAL,GAAAA"}