{"version":3,"file":"current-http.mjs","names":[],"sources":["../../../../../../http/src/current-http.ts"],"sourcesContent":["import type { Http } from \"./Http\";\n\nlet _current: Http | null = null;\n\n/**\n * Set the application-wide default Http instance.\n * Call this once during app bootstrap, before any Resource is used.\n *\n * > ⚠️ **This is module-level global state — safe in a browser, not on a server.**\n * > A server process handles many users concurrently, so calling this per request\n * > (e.g. to attach the current user's token) lets one request overwrite the instance\n * > another is mid-way through using, and requests can end up sending the wrong\n * > credentials. On a server either set a single instance with no per-user state at\n * > bootstrap, or skip this entirely and build a request-scoped `new Http({ auth })`,\n * > passing it explicitly to whatever needs it.\n *\n * @example\n * import { Http, setCurrentHttp } from '@mongez/http';\n *\n * const http = new Http({ baseURL: 'https://api.example.com' });\n * setCurrentHttp(http);\n */\nexport function setCurrentHttp(instance: Http): void {\n  _current = instance;\n}\n\n/**\n * Get the application-wide default Http instance.\n * Throws if `setCurrentHttp` was never called — fail loudly rather than silently.\n */\nexport function getCurrentHttp(): Http {\n  if (!_current) {\n    throw new Error(\n      \"@mongez/http: No default Http instance found. \" +\n        \"Call setCurrentHttp(http) during app bootstrap before using Resource.\",\n    );\n  }\n  return _current;\n}\n"],"mappings":";AAEA,IAAI,WAAwB;;;;;;;;;;;;;;;;;;;AAoB5B,SAAgB,eAAe,UAAsB;CACnD,WAAW;AACb;;;;;AAMA,SAAgB,iBAAuB;CACrC,IAAI,CAAC,UACH,MAAM,IAAI,MACR,qHAEF;CAEF,OAAO;AACT"}