{"version":3,"file":"bufferedData.mjs","names":[],"sources":["../../src/domain/bufferedData.ts"],"sourcesContent":["import { ConsoleApiName } from '@openobserve/js-core/util'\nimport type { Observable, Subscription } from '../tools/observable'\nimport { BufferedObservable } from '../tools/observable'\nimport { mockable } from '../tools/mockable'\nimport type { FetchContext } from '../browser/fetchObservable'\nimport { initFetchObservable } from '../browser/fetchObservable'\nimport type { XhrContext } from '../browser/xhrObservable'\nimport { initXhrObservable } from '../browser/xhrObservable'\nimport { addTelemetryDebug } from './telemetry'\nimport type { RawError } from './error/error.types'\nimport { trackRuntimeError } from './error/trackRuntimeError'\nimport type { ConsoleLog } from './console/consoleObservable'\nimport { initConsoleObservable } from './console/consoleObservable'\n\nconst BUFFER_LIMIT = 500\n\nexport const enum BufferedDataType {\n  RUNTIME_ERROR,\n  FETCH,\n  XHR,\n  CONSOLE,\n}\n\nexport type BufferedData =\n  | { type: BufferedDataType.RUNTIME_ERROR; data: RawError }\n  | { type: BufferedDataType.FETCH; data: FetchContext }\n  | { type: BufferedDataType.XHR; data: XhrContext }\n  | { type: BufferedDataType.CONSOLE; data: ConsoleLog }\n\nexport function startBufferingData() {\n  const observable = new BufferedObservable<BufferedData>(BUFFER_LIMIT, (count) => {\n    // monitor-until: 2026-10-14\n    addTelemetryDebug('Early data collection dropped data on unbuffer', {\n      count,\n    })\n  })\n  const subscriptions: Subscription[] = []\n\n  function subscribe<T extends BufferedDataType>(\n    type: T,\n    source: Observable<Extract<BufferedData, { type: T }>['data']>\n  ) {\n    subscriptions.push(\n      source.subscribe((data) => {\n        observable.notify({ type, data } as BufferedData)\n      })\n    )\n  }\n\n  subscribe(BufferedDataType.RUNTIME_ERROR, mockable(trackRuntimeError)())\n  subscribe(BufferedDataType.FETCH, initFetchObservable())\n  subscribe(BufferedDataType.XHR, initXhrObservable())\n  subscribe(BufferedDataType.CONSOLE, initConsoleObservable(Object.values(ConsoleApiName)))\n\n  return {\n    observable,\n    stop: () => subscriptions.forEach((subscription) => subscription.unsubscribe()),\n  }\n}\n"],"mappings":";;;;;;;;;AAcA,MAAM,eAAe;AAErB,IAAkB,mBAAX,yBAAA,kBAAA;CACL,iBAAA,iBAAA,mBAAA,KAAA;CACA,iBAAA,iBAAA,WAAA,KAAA;CACA,iBAAA,iBAAA,SAAA,KAAA;CACA,iBAAA,iBAAA,aAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAQA,SAAgB,qBAAqB;CACnC,MAAM,aAAa,IAAI,mBAAiC,eAAe,UAAU;EAE/E,kBAAkB,kDAAkD,EAClE,MACF,CAAC;CACH,CAAC;CACD,MAAM,gBAAgC,CAAC;CAEvC,SAAS,UACP,MACA,QACA;EACA,cAAc,KACZ,OAAO,WAAW,SAAS;GACzB,WAAW,OAAO;IAAE;IAAM;GAAK,CAAiB;EAClD,CAAC,CACH;CACF;CAEA,UAAA,GAA0C,SAAS,iBAAiB,CAAC,CAAC,CAAC;CACvE,UAAA,GAAkC,oBAAoB,CAAC;CACvD,UAAA,GAAgC,kBAAkB,CAAC;CACnD,UAAA,GAAoC,sBAAsB,OAAO,OAAO,cAAc,CAAC,CAAC;CAExF,OAAO;EACL;EACA,YAAY,cAAc,SAAS,iBAAiB,aAAa,YAAY,CAAC;CAChF;AACF"}