{"version":3,"file":"sync-local-storage.mjs","names":[],"sources":["../../../../src/internal/context/sync-local-storage.mts"],"sourcesContent":["import type { IAsyncLocalStorage } from './async-local-storage.types.mjs'\n\n/**\n * A synchronous-only polyfill for AsyncLocalStorage.\n *\n * This provides the same API as Node's AsyncLocalStorage but only works\n * for synchronous code paths. It uses a simple stack-based approach.\n *\n * Limitations:\n * - Context does NOT propagate across async boundaries (setTimeout, promises, etc.)\n * - Only suitable for environments where DI resolution is synchronous\n *\n * This is acceptable for browser environments where:\n * 1. Constructors are typically synchronous\n * 2. Circular dependency detection mainly needs sync tracking\n */\nexport class SyncLocalStorage<T> implements IAsyncLocalStorage<T> {\n  private stack: T[] = []\n\n  /**\n   * Runs a function within the given store context.\n   * The context is only available synchronously within the function.\n   */\n  run<R>(store: T, fn: () => R): R {\n    this.stack.push(store)\n    try {\n      return fn()\n    } finally {\n      this.stack.pop()\n    }\n  }\n\n  /**\n   * Gets the current store value, or undefined if not in a context.\n   */\n  getStore(): T | undefined {\n    return this.stack.length > 0 ? this.stack[this.stack.length - 1] : undefined\n  }\n\n  /**\n   * Exits the current context and runs the function without any store.\n   * This matches AsyncLocalStorage.exit() behavior.\n   */\n  exit<R>(fn: () => R): R {\n    const savedStack = this.stack\n    this.stack = []\n    try {\n      return fn()\n    } finally {\n      this.stack = savedStack\n    }\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAa,mBAAb,MAAkE;CAChE,AAAQ,QAAa,EAAE;;;;;CAMvB,IAAO,OAAU,IAAgB;AAC/B,OAAK,MAAM,KAAK,MAAM;AACtB,MAAI;AACF,UAAO,IAAI;YACH;AACR,QAAK,MAAM,KAAK;;;;;;CAOpB,WAA0B;AACxB,SAAO,KAAK,MAAM,SAAS,IAAI,KAAK,MAAM,KAAK,MAAM,SAAS,KAAK;;;;;;CAOrE,KAAQ,IAAgB;EACtB,MAAM,aAAa,KAAK;AACxB,OAAK,QAAQ,EAAE;AACf,MAAI;AACF,UAAO,IAAI;YACH;AACR,QAAK,QAAQ"}