!function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=8)}([function(e,t,r){e.exports=r(6)(1465)},function(e,t,r){r.r(t);var n=__kbnBundles__.get("plugin/kibanaUtils/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(n))},function(e,t){e.exports=__kbnSharedDeps__.RxjsOperators},function(e,t){e.exports=__kbnSharedDeps__.Rxjs},function(e,t){e.exports=__kbnSharedDeps__.KbnI18n},function(e,t){e.exports=__kbnSharedDeps__.Fflate},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,r){e.exports=r(6)(2944)},function(e,t,r){r(9),__kbnBundles__.define("plugin/bfetch/public",r,10)},function(e,t,r){r.p=window.__kbnPublicPath__.bfetch},function(e,t,r){"use strict";r.r(t),r.d(t,"split",(function(){return a})),r.d(t,"DISABLE_BFETCH",(function(){return l})),r.d(t,"BfetchRequestError",(function(){return bfetch_error_BfetchRequestError})),r.d(t,"plugin",(function(){return d}));var n=r(0),s=r.n(n),o=r(1),i=r(3),c=r(2);const a=(e="\n")=>t=>{const r=new i.Subject;let n="";return t.subscribe((t=>{const s=(n+t).split(e);s.slice(0,-1).forEach(r.next.bind(r)),n=s.length?s[s.length-1]:""}),r.error.bind(r),(()=>{r.next(n),r.complete()})),r.pipe(Object(c.filter)(Boolean))},u=(e,t,r)=>{const n=e.includes("?")?"&":"?";return`${e}${n}${t}=${r}`};class item_buffer_ItemBuffer{constructor(e){s()(this,"list",[]),this.params=e}get length(){return this.list.length}write(e){this.list.push(e);const{flushOnMaxItems:t}=this.params;t&&this.list.length>=t&&this.flush()}clear(){this.list=[]}flush(){this.flushAsync().catch((()=>{}))}async flushAsync(){let e;[e,this.list]=[this.list,[]],await this.params.onFlush(e)}}class timed_item_buffer_TimedItemBuffer extends item_buffer_ItemBuffer{constructor(e){super(e),s()(this,"timer",void 0),s()(this,"onTimeout",(()=>{this.flush()})),this.params=e}write(e){super.write(e),this.params.maxItemAge&&1===this.length&&(this.timer=setTimeout(this.onTimeout,this.params.maxItemAge))}clear(){clearTimeout(this.timer),super.clear()}flush(){clearTimeout(this.timer),super.flush()}async flushAsync(){clearTimeout(this.timer),await super.flushAsync()}}const l="bfetch:disable";var f=r(4);class bfetch_error_BfetchRequestError extends Error{constructor(e){super(0===e?f.i18n.translate("bfetch.networkError",{defaultMessage:"Check your network connection and try again."}):f.i18n.translate("bfetch.networkErrorWithStatus",{defaultMessage:"Check your network connection and try again. Code {code}",values:{code:e}})),s()(this,"code",void 0),this.name="BfetchRequestError",this.code=e}}const h=(e,t)=>{const r=new i.Subject;let n=0,s=!1;const o=()=>0===e.status||e.status>=400,c=()=>{if(s)return;if(o())return;const{responseText:t}=e;n>=t.length||(r.next(t.substr(n)),n=t.length)};e.onprogress=c;const a=()=>{4!==e.readyState&&(s=!0,e.abort(),r.complete(),t&&t.removeEventListener("abort",a))};return t&&t.addEventListener("abort",a),e.onreadystatechange=()=>{s||(c(),4===e.readyState&&(t&&t.removeEventListener("abort",a),o()?r.error(new bfetch_error_BfetchRequestError(e.status)):r.complete()))},r};function m({url:e,headers:t={},method:r="POST",body:n="",signal:s,getIsCompressionDisabled:o=(()=>!1)}){const i=new window.XMLHttpRequest,l=o();l||(e=u(e,"compress","true")),i.open(r,e),i.withCredentials=!0,Object.entries(t).forEach((([e,t])=>i.setRequestHeader(e,t)));const f=h(i,s);i.send(n);const m=f.pipe(a("\n"),Object(c.map)((e=>l?e:function(e){const t=Object(b.toByteArray)(e),r=Object(p.unzlibSync)(t);return Object(p.strFromU8)(r)}(e))),Object(c.share)());return{xhr:i,stream:m}}var p=r(5),b=r(7);class plugin_BfetchPublicPlugin{constructor(e){s()(this,"contract",void 0),s()(this,"fetchStreaming",((e,t,r,n)=>s=>{return m({...s,url:`${r}/${o=s.url,"/"===o[0]?o.substr(1):o}`,headers:{"Content-Type":"application/json","kbn-version":t,"x-elastic-internal-origin":"Kibana","elastic-api-version":e,...s.headers||{}},getIsCompressionDisabled:n});var o})),s()(this,"batchedFunction",((e,t)=>r=>(e=>{const{url:t,fetchStreaming:r=m,flushOnMaxItems:n=25,maxItemAge:s=10,getIsCompressionDisabled:i=(()=>!1)}=e,[c]=(e=>{const{onCall:t,onBatch:r,maxItemAge:n=10,flushOnMaxItems:s=25}=e,o=new timed_item_buffer_TimedItemBuffer({onFlush:r,maxItemAge:n,flushOnMaxItems:s});return[(...e)=>{const[r,n]=t(...e);return o.write(n),r},o]})({onCall:(e,t)=>{const r=Object(o.defer)(),n={payload:e,future:r,signal:t};return[r.promise,n]},onBatch:async e=>{try{if(0===(e=e.filter((e=>{var t,r;return null!==(t=e.signal)&&void 0!==t&&t.aborted&&e.future.reject(new o.AbortError),!(null!==(r=e.signal)&&void 0!==r&&r.aborted)}))).length)return;const n=e.map((e=>new Promise((t=>{const{promise:r,cleanup:n}=e.signal?Object(o.abortSignalToPromise)(e.signal):{promise:void 0,cleanup:()=>{}},s=()=>{t(),n()};r&&r.catch((()=>{e.future.reject(new o.AbortError),s()})),e.future.promise.then(s,s)})))),s=new AbortController;let c=!1;Promise.all(n).then((()=>{c=!0,s.abort()}));const a=e.map((e=>e.payload)),{stream:u}=r({url:t,body:JSON.stringify({batch:a}),method:"POST",signal:s.signal,getIsCompressionDisabled:i}),l=t=>{const r=(n=t)?n instanceof bfetch_error_BfetchRequestError?n:n instanceof Error?{message:n.message}:"object"==typeof n?{...n,message:n.message||"Unknown error."}:{message:String(n)}:{message:"Unknown error."};var n;r.code="STREAM";for(const{future:t}of e)t.reject(r)};u.subscribe({next:t=>{try{const r=JSON.parse(t);r.error?e[r.id].future.reject(r.error):void 0!==r.result&&e[r.id].future.resolve(r.result)}catch(e){l(e)}},error:l,complete:()=>{if(!c){const t={message:"Connection terminated prematurely.",code:"CONNECTION"};for(const{future:r}of e)r.reject(t)}}}),await u.toPromise()}catch(t){for(const r of e)r.future.reject(t)}},flushOnMaxItems:n,maxItemAge:s});return c})({...r,getIsCompressionDisabled:t,fetchStreaming:r.fetchStreaming||e}))),this.initializerContext=e}setup(e,t){const{version:r}=this.initializerContext.env.packageInfo,n=e.http.basePath.get(),s=Object(o.createStartServicesGetter)(e.getStartServices),i=()=>s().core.uiSettings.get("bfetch:disableCompression"),c=this.fetchStreaming("1",r,n,i),a=this.batchedFunction(c,i);return this.contract={fetchStreaming:c,batchedFunction:a},this.contract}start(e,t){return this.contract}stop(){}}function d(e){return new plugin_BfetchPublicPlugin(e)}}]);