{"version":3,"file":"context-CAWi28RU.cjs","sources":["../src/private/odata_macro/services/odata_context_service.ts","../src/odata/context.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type { ODataResponseFormat, ODataMetadataLevel } from '../utils/http'\n\nexport interface ResolvedODataContext {\n  serviceBaseUrl: string\n  serveAs: ODataResponseFormat\n  metadataLevel: ODataMetadataLevel\n}\n\nexport interface ResourcefulODataContextResolver {\n  (\n    fallbackResponseFormat?: ODataResponseFormat,\n    fallbackMetadataLevel?: ODataMetadataLevel\n  ): Promise<ResolvedODataContext>\n}\n\nexport interface ResourcefulODataContextStore {\n  resolver: ResourcefulODataContextResolver\n}\n\nexport const ODataContext = new AsyncLocalStorage<ResourcefulODataContextStore>()\n","/**\n * Utility which allows resolution of resourceful odata context.\n * @module @nhtio/lucid-resourceful/odata/context\n */\nimport { E_NOT_IN_ODATA_CONTEXT } from '@nhtio/lucid-resourceful/errors'\nimport { ODataContext } from '@/private/odata_macro/services/odata_context_service'\nimport type { ResolvedODataContext } from '@/private/odata_macro/services/odata_context_service'\n\nexport const useODataContext = async (): Promise<ResolvedODataContext> => {\n  try {\n    const store = ODataContext.getStore()\n    if (!store || !('resolver' in store) || 'function' !== typeof store.resolver) {\n      throw new E_NOT_IN_ODATA_CONTEXT()\n    }\n    return await store.resolver()\n  } catch (err) {\n    throw new E_NOT_IN_ODATA_CONTEXT(err)\n  }\n}\n\nexport type { ResolvedODataContext }\n"],"names":["AsyncLocalStorage","E_NOT_IN_ODATA_CONTEXT"],"mappings":";;;AAoBO,MAAM,eAAe,IAAIA,iBAAAA,kBAAA;ACZzB,MAAM,kBAAkB,YAA2C;AACxE,MAAI;AACF,UAAM,QAAQ,aAAa,SAAA;AAC3B,QAAI,CAAC,SAAS,EAAE,cAAc,UAAU,eAAe,OAAO,MAAM,UAAU;AAC5E,YAAM,IAAIC,OAAAA,uBAAA;AAAA,IACZ;AACA,WAAO,MAAM,MAAM,SAAA;AAAA,EACrB,SAAS,KAAK;AACZ,UAAM,IAAIA,OAAAA,uBAAuB,GAAG;AAAA,EACtC;AACF;;;"}