{"version":3,"sources":["jsdelivr-header.js","/npm/@churchill/elastic@1.0.0/elastic.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,UAAY,QAAQ,yBACpB,OAAE,QAAW,QAAQ,0BAErB,UAAY,QAAQ,YAM1B,MAAM,gBAAgB,UAUpB,WAAA,CAAY,GACV,MAAM,IAAK,EAAM,OAAQ,EAAK,QAAU,YACxC,MAAM,OAAE,EAAM,MAAE,EAAK,KAAE,GAAS,EAEhC,GAAK,EAOH,KAAK,OAAS,MAPH,CACX,IAAK,EACH,MAAM,IAAI,MAAM,+DAGlB,KAAK,OAAS,IAAI,OAAO,CAAE,QAC7B,CAIA,IAAK,EACH,MAAM,IAAI,MAAM,iEAGlB,KAAK,MAAQ,CACf,CAQA,SAAM,CAAI,EAAM,EAAQ,GACtB,MAAM,EAAM,KAAK,OAAO,EAAM,EAAQ,GACtC,UACQ,KAAK,OAAO,MAAM,CACtB,MAAO,KAAK,MACZ,KAAM,GAEV,CAAE,MAAO,GACP,KAAK,KAAK,QAAS,EACrB,CACF,EAYF,QAAQ,OAAS,GACR,IAAI,QAAQ,GAGrB,OAAO,QAAU","file":"/npm/@churchill/elastic@1.0.0/elastic.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@churchill/elastic@1.0.0/elastic.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const Transport = require(\"@churchill/transport\");\nconst { Client } = require(\"@elastic/elasticsearch\");\n\nconst toElastic = require(\"./format\");\n\n/**\n * @typedef {import(\"@churchill/core\")} Logger\n */\n\nclass Elastic extends Transport {\n  /**\n   * Logging to Elasticsearch index\n   * @param {Object} opts Options\n   * @param {Function} [opts.format=toElastic] Formatting function\n   * @param {String} [opts.maxLevel] Max logging level\n   * @param {Client} [opts.client] Elastic client\n   * @param {String} [opts.node] Elastic node URL\n   * @param {String} opts.index Index\n   */\n  constructor(opts) {\n    super({ ...opts, format: opts.format || toElastic });\n    const { client, index, node } = opts;\n\n    if (!client) {\n      if (!node) {\n        throw new Error(\"You must provide node, did you forget to pass options.node?\");\n      }\n\n      this.client = new Client({ node });\n    } else {\n      this.client = client;\n    }\n\n    if (!index) {\n      throw new Error(\"You must provide index, did you forget to pass options.index?\");\n    }\n\n    this.index = index;\n  }\n\n  /**\n   * Log a Message\n   * @param {Object} info Message\n   * @param {*} output (Optional) Output of the global formatting function\n   * @param {Logger} logger Logger\n   */\n  async log(info, output, logger) {\n    const out = this.format(info, output, logger);\n    try {\n      await this.client.index({\n        index: this.index,\n        body: out\n      });\n    } catch (err) {\n      this.emit(\"error\", err);\n    }\n  }\n}\n\n/**\n * Create a Elasticsearch transport\n * @param {Object} opts Options\n * @param {Function} [opts.format] Formatting function\n * @param {String} [opts.maxLevel] Max logging level\n * @param {Client} [opts.client] Elastic client\n * @param {String} [opts.node] Elastic node URL\n * @param {String} opts.index Index\n */\nElastic.create = opts => {\n  return new Elastic(opts);\n};\n\nmodule.exports = Elastic;\n"]}