{"version":3,"file":"display.mjs","names":[],"sources":["../../src/util/display.ts"],"sourcesContent":["/** Names of the console methods wrapped by {@link Display}. */\nexport const ConsoleApiName = {\n  log: 'log',\n  debug: 'debug',\n  info: 'info',\n  warn: 'warn',\n  error: 'error',\n} as const\n\n/** Union of the console method names (`'log' | 'debug' | 'info' | 'warn' | 'error'`). */\nexport type ConsoleApiName = (typeof ConsoleApiName)[keyof typeof ConsoleApiName]\n\n/** Console methods pre-bound to the original (unpatched) console implementation. */\nexport interface Display {\n  debug: typeof console.debug\n  log: typeof console.log\n  info: typeof console.info\n  warn: typeof console.warn\n  error: typeof console.error\n}\n\n/**\n * When building JS bundles, some users might use a plugin[1] or configuration[2] to remove\n * \"console.*\" references. This causes some issue as we expect `console.*` to be defined.\n * As a workaround, let's use a variable alias, so those expressions won't be taken into account by\n * simple static analysis.\n *\n * [1]: https://babeljs.io/docs/babel-plugin-transform-remove-console/\n * [2]: https://github.com/terser/terser#compress-options (look for drop_console)\n */\nexport const globalConsole = console\n\n/**\n * Keep references on console methods to avoid triggering patched behaviors\n *\n * NB: in some setup, console could already be patched by another SDK.\n * In this case, some display messages can be sent by the other SDK\n * but we should be safe from infinite loop nonetheless.\n */\nexport const originalConsoleMethods: Display = {\n  log: globalConsole.log,\n  debug: globalConsole.debug,\n  info: globalConsole.info,\n  warn: globalConsole.warn,\n  error: globalConsole.error,\n}\n\n/**\n * Creates a {@link Display} bound to the original (unpatched) console methods, prefixing every\n * message with the given prefix.\n *\n * Capturing the original console methods up front avoids triggering behaviors added by another SDK\n * (or the host application) that may have patched `console.*` afterwards.\n *\n * @param prefix - String prepended to every logged message (e.g. to attribute output to an SDK).\n * @returns A {@link Display} whose methods forward to the original console methods.\n */\nexport function createDisplay(prefix: string): Display {\n  return {\n    debug: originalConsoleMethods.debug.bind(globalConsole, prefix),\n    log: originalConsoleMethods.log.bind(globalConsole, prefix),\n    info: originalConsoleMethods.info.bind(globalConsole, prefix),\n    warn: originalConsoleMethods.warn.bind(globalConsole, prefix),\n    error: originalConsoleMethods.error.bind(globalConsole, prefix),\n  }\n}\n"],"mappings":";;AACA,MAAa,iBAAiB;CAC5B,KAAK;CACL,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;AACT;;;;;;;;;;AAuBA,MAAa,gBAAgB;;;;;;;;AAS7B,MAAa,yBAAkC;CAC7C,KAAK,cAAc;CACnB,OAAO,cAAc;CACrB,MAAM,cAAc;CACpB,MAAM,cAAc;CACpB,OAAO,cAAc;AACvB;;;;;;;;;;;AAYA,SAAgB,cAAc,QAAyB;CACrD,OAAO;EACL,OAAO,uBAAuB,MAAM,KAAK,eAAe,MAAM;EAC9D,KAAK,uBAAuB,IAAI,KAAK,eAAe,MAAM;EAC1D,MAAM,uBAAuB,KAAK,KAAK,eAAe,MAAM;EAC5D,MAAM,uBAAuB,KAAK,KAAK,eAAe,MAAM;EAC5D,OAAO,uBAAuB,MAAM,KAAK,eAAe,MAAM;CAChE;AACF"}