{"version":3,"file":"defineContextMethod.mjs","names":[],"sources":["../../../src/domain/context/defineContextMethod.ts"],"sourcesContent":["import type { RawTelemetryUsage, RawTelemetryUsageFeature } from '../telemetry'\nimport { addTelemetryUsage } from '../telemetry'\nimport { monitor } from '../../tools/monitor'\nimport type { BufferedObservable } from '../../tools/observable'\nimport type { ContextManager } from './contextManager'\nimport type { ContextManagerMethod, CustomerContextKey } from './contextConstants'\n\nexport function defineContextMethod<MethodName extends ContextManagerMethod, Key extends CustomerContextKey>(\n  getStrategy: () => Record<Key, ContextManager>,\n  contextName: Key,\n  methodName: MethodName,\n  usage?: RawTelemetryUsageFeature\n): ContextManager[MethodName] {\n  return monitor((...args: any[]) => {\n    if (usage) {\n      addTelemetryUsage({ feature: usage } as RawTelemetryUsage)\n    }\n    return (getStrategy()[contextName][methodName] as (...args: unknown[]) => unknown)(...args)\n  }) as ContextManager[MethodName]\n}\n\nexport function bufferContextCalls<Key extends string, StartResult extends Record<Key, ContextManager>>(\n  preStartContextManager: ContextManager,\n  name: Key,\n  bufferApiCalls: BufferedObservable<(startResult: StartResult) => void>\n) {\n  preStartContextManager.changeObservable.subscribe(() => {\n    const context = preStartContextManager.getContext()\n    bufferApiCalls.notify((startResult) => startResult[name].setContext(context))\n  })\n}\n"],"mappings":";;;AAOA,SAAgB,oBACd,aACA,aACA,YACA,OAC4B;CAC5B,OAAO,SAAS,GAAG,SAAgB;EACjC,IAAI,OACF,kBAAkB,EAAE,SAAS,MAAM,CAAsB;EAE3D,OAAQ,YAAY,CAAC,CAAC,YAAY,CAAC,WAAW,CAAqC,GAAG,IAAI;CAC5F,CAAC;AACH;AAEA,SAAgB,mBACd,wBACA,MACA,gBACA;CACA,uBAAuB,iBAAiB,gBAAgB;EACtD,MAAM,UAAU,uBAAuB,WAAW;EAClD,eAAe,QAAQ,gBAAgB,YAAY,KAAK,CAAC,WAAW,OAAO,CAAC;CAC9E,CAAC;AACH"}