UNPKG

altair-static

Version:

Static package for altair graphql client

6 lines (5 loc) 11.5 kB
"use strict"; !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="309ec40a-f454-5bdc-b397-4d82adf4199b")}catch(e){}}(); (self.webpackChunkaltair=self.webpackChunkaltair||[]).push([[784],{61784:(ge,te,R)=>{R.r(te),R.d(te,{SSERequestHandler:()=>ye});var A=R(35121),oe=R(38821),X=R(24140),Z=R(83770);function q(e){var n,t,c,l=2;for(typeof Symbol<"u"&&(t=Symbol.asyncIterator,c=Symbol.iterator);l--;){if(t&&null!=(n=e[t]))return n.call(e);if(c&&null!=(n=e[c]))return new W(n.call(e));t="@@asyncIterator",c="@@iterator"}throw new TypeError("Object is not async iterable")}function W(e){function n(t){if(Object(t)!==t)return Promise.reject(new TypeError(t+" is not an object."));var c=t.done;return Promise.resolve(t.value).then(function(l){return{value:l,done:c}})}return(W=function(c){this.s=c,this.n=c.next}).prototype={s:null,n:null,next:function(){return n(this.n.apply(this.s,arguments))},return:function(c){var l=this.s.return;return void 0===l?Promise.resolve({value:c,done:!0}):n(l.apply(this.s,arguments))},throw:function(c){var l=this.s.return;return void 0===l?Promise.reject(c):n(l.apply(this.s,arguments))}},new W(e)}function le(e){if("next"!==e&&"complete"!==e)throw new Error(`Invalid stream event "${e}"`);return e}function ae(e,n){if(n)try{n=JSON.parse(n)}catch{throw new Error("Invalid stream data")}if("next"===e&&!n)throw new Error('Stream data must be an object for "next" events');return n||null}var z=function(e){return e[e.NewLine=10]="NewLine",e[e.CchunkiageReturn=13]="CchunkiageReturn",e[e.Space=32]="Space",e[e.Colon=58]="Colon",e}(z||{});class T extends Error{constructor(n){let t,c;!function de(e){return function ce(e){return"object"==typeof e&&null!==e}(e)&&"boolean"==typeof e.ok&&"number"==typeof e.status&&"string"==typeof e.statusText}(n)?t=n instanceof Error?n.message:String(n):(c=n,t="Server responded with "+n.status+": "+n.statusText),super(t),this.name=this.constructor.name,this.response=c}}function re(e){return _.apply(this,arguments)}function _(){return(_=(0,A.A)(function*(e){const{signal:n,url:t,credentials:c,headers:l,body:L,referrer:x,referrerPolicy:Q,fetchFn:j,onMessage:E}=e,d={},u={};let o;try{o=yield j(t,{signal:n,method:L?"POST":"GET",credentials:c,referrer:x,referrerPolicy:Q,headers:{...l,accept:"text/event-stream"},body:L})}catch(h){throw new T(h)}if(!o.ok)throw new T(o);if(!o.body)throw new Error("Missing response body");let k,f=null;return(0,A.A)(function*(){var h;try{const M=function se(){let e,n,t,c=!1,l={event:"",data:""},L=[];const x=new TextDecoder;return function(j){if(void 0===e)e=j,n=0,t=-1;else{const u=new Uint8Array(e.length+j.length);u.set(e),u.set(j,e.length),e=u}const E=e.length;let d=0;for(;n<E;){c&&(e[n]===z.NewLine&&(d=++n),c=!1);let u=-1;for(;n<E&&-1===u;++n)switch(e[n]){case z.Colon:-1===t&&(t=n-d);break;case z.CchunkiageReturn:c=!0;case z.NewLine:u=n}if(-1===u)break;if(d===u){if(l.event||l.data){if(!l.event)throw new Error("Missing message event");const o=le(l.event),f=ae(o,l.data);L.push({event:o,data:f}),l={event:"",data:""}}}else if(t>0){const o=e.subarray(d,u),f=x.decode(o.subarray(0,t)),h=x.decode(o.subarray(t+(o[t+1]===z.Space?2:1)));switch(f){case"event":l.event=h;break;case"data":l.data=l.data?l.data+"\n"+h:h}}d=n,t=-1}if(d===E){e=void 0;const u=[...L];return L=[],u}0!==d&&(e=e.subarray(d),n-=d)}}();var S,w=!1,y=!1;try{for(var I,p=q(function fe(e){return"function"==typeof Object(e)[Symbol.asyncIterator]?e[Symbol.asyncIterator]():(0,Z.A)(function*(){const n=e.getReader();let t;do{t=yield(0,X.A)(n.read()),void 0!==t.value&&(yield t.value)}while(!t.done)})()}(o.body));w=!(I=yield p.next()).done;w=!1){const C=I.value;{if("string"==typeof C)throw f=new Error(`Unexpected string chunk "${C}"`);let H;try{H=M(C)}catch(r){throw f=r}if(!H)continue;for(const r of H){try{E?.(r)}catch(i){throw f=i}const s=r.data&&"id"in r.data?r.data.id:"";switch(s in u||(u[s]=[]),r.event){case"next":u[s].push(s?r.data.payload:r.data);break;case"complete":u[s].push("complete");break;default:throw f=new Error(`Unexpected message event "${r.event}"`)}null===(h=d[s])||void 0===h||h.proceed()}}}}catch(C){y=!0,S=C}finally{try{w&&null!=p.return&&(yield p.return())}finally{if(y)throw S}}if(Object.keys(d).length)throw new Error("Connection closed while having active streams")}catch(M){f=!f&&Object.keys(d).length?new T(M):M,k?.(f)}finally{Object.values(d).forEach(({proceed:M})=>M())}})(),{url:t,headers:l,waitForThrow:()=>new Promise((h,w)=>{if(f)return w(f);k=w}),getResults:h=>(0,Z.A)(function*(){var w;const{signal:y,operationId:S=""}=h??{};try{for(;;){for(;null!==(w=u[S])&&void 0!==w&&w.length;){const p=u[S].shift();if("complete"===p)return;yield p}if(f)throw f;if(y?.aborted)throw new Error("Getting results aborted by the client");yield(0,X.A)(new Promise(p=>{const I=()=>{y?.removeEventListener("abort",I),delete d[S],p()};y?.addEventListener("abort",I),d[S]={proceed:I}}))}}finally{delete u[S]}})()}})).apply(this,arguments)}var he=R(19746);class ye{handle(n){return new oe.c(t=>{if(this.client=function ue(e){const{singleConnection:n=!1,lazy:t=!0,lazyCloseTimeout:c=0,onNonLazyError:l=console.error,generateID:L=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{const i=16*Math.random()|0;return("x"==s?i:3&i|8).toString(16)})},retryAttempts:x=5,retry:Q=function(){var r=(0,A.A)(function*(i){let a=1e3;for(let D=0;D<i;D++)a*=2;yield new Promise(D=>setTimeout(D,a+Math.floor(2700*Math.random()+300)))});return function s(i){return r.apply(this,arguments)}}(),credentials:j="same-origin",referrer:E,referrerPolicy:d,onMessage:u,on:o}=e,f=e.fetchFn||fetch,k=e.abortControllerImpl||AbortController,h=(()=>{let r=!1;const s=[];return{get disposed(){return r},onDispose:i=>r?(setTimeout(()=>i(),0),()=>{}):(s.push(i),()=>{s.splice(s.indexOf(i),1)}),dispose(){if(!r){r=!0;for(const i of[...s])i()}}}})();let w,y,S=0,p=null,I=0;function M(){return C.apply(this,arguments)}function C(){return(C=(0,A.A)(function*(){try{if(h.disposed)throw new Error("Client has been disposed");return yield y??(y=(0,A.A)(function*(){var r,s,i;if(p){if(yield Q(I),w.signal.aborted)throw new Error("Connection aborted by the client");I++}null===(r=o?.connecting)||void 0===r||r.call(o,!!p),w=new k;const a=h.onDispose(()=>w.abort());w.signal.addEventListener("abort",()=>{a(),y=void 0});const D="function"==typeof e.url?yield e.url():e.url;if(w.signal.aborted)throw new Error("Connection aborted by the client");const v="function"==typeof e.headers?yield e.headers():null!==(s=e.headers)&&void 0!==s?s:{};if(w.signal.aborted)throw new Error("Connection aborted by the client");let g;try{g=yield f(D,{signal:w.signal,method:"PUT",credentials:j,referrer:E,referrerPolicy:d,headers:v})}catch(P){throw new T(P)}if(201!==g.status)throw new T(g);const b=yield g.text();v["x-graphql-event-stream-token"]=b;const N=yield re({signal:w.signal,headers:v,credentials:j,referrer:E,referrerPolicy:d,url:D,fetchFn:f,onMessage:P=>{var O;null===(O=o?.message)||void 0===O||O.call(o,P),u?.(P)}});return null===(i=o?.connected)||void 0===i||i.call(o,!!p),N.waitForThrow().catch(()=>y=void 0),N})())}catch(r){throw y=void 0,r}})).apply(this,arguments)}function H(r,s,i){if(!n){const v=new k,g=h.onDispose(()=>{g(),v.abort()});return(0,A.A)(function*(){var b,N,P,O,Y;let m=null,J=0;for(;;)try{if(m){if(yield Q(J),v.signal.aborted)throw new Error("Connection aborted by the client");J++}null===(b=o?.connecting)||void 0===b||b.call(o,!!m),null===(N=i?.connecting)||void 0===N||N.call(i,!!m);const U="function"==typeof e.url?yield e.url():e.url;if(v.signal.aborted)throw new Error("Connection aborted by the client");const ve="function"==typeof e.headers?yield e.headers():null!==(P=e.headers)&&void 0!==P?P:{};if(v.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:we}=yield re({signal:v.signal,headers:{...ve,"content-type":"application/json; charset=utf-8"},credentials:j,referrer:E,referrerPolicy:d,url:U,body:JSON.stringify(r),fetchFn:f,onMessage:$=>{var ee,ne;null===(ee=o?.message)||void 0===ee||ee.call(o,$),null===(ne=i?.message)||void 0===ne||ne.call(i,$),u?.($)}});null===(O=o?.connected)||void 0===O||O.call(o,!!m),null===(Y=i?.connected)||void 0===Y||Y.call(i,!!m);var F,V=!1,B=!1;try{for(var K,G=q(we());V=!(K=yield G.next()).done;V=!1)m=null,J=0,s.next(K.value)}catch($){B=!0,F=$}finally{try{V&&null!=G.return&&(yield G.return())}finally{if(B)throw F}}return v.abort()}catch(U){if(v.signal.aborted)return;if(!(U instanceof T)||!x||J>=x)throw U;m=U}})().then(()=>s.complete()).catch(b=>s.error(b)),()=>v.abort()}S++;const a=new k,D=h.onDispose(()=>{D(),a.abort()});return(0,A.A)(function*(){const v=L();r={...r,extensions:{...r.extensions,operationId:v}};let g=null;for(;;){g=null;try{const{url:m,headers:J,getResults:V}=yield M();let B;try{B=yield f(m,{signal:a.signal,method:"POST",credentials:j,referrer:E,referrerPolicy:d,headers:{...J,"content-type":"application/json; charset=utf-8"},body:JSON.stringify(r)})}catch(F){throw new T(F)}if(202!==B.status)throw new T(B);g=function(){var F=(0,A.A)(function*(){let G;try{const K=new k,U=h.onDispose(()=>{U(),K.abort()});G=yield f(m+"?operationId="+v,{signal:K.signal,method:"DELETE",credentials:j,referrer:E,referrerPolicy:d,headers:J})}catch(K){throw new T(K)}if(200!==G.status)throw new T(G)});return function(){return F.apply(this,arguments)}}();var P,b=!1,N=!1;try{for(var Y,O=q(V({signal:a.signal,operationId:v}));b=!(Y=yield O.next()).done;b=!1)p=null,I=0,s.next(Y.value)}catch(F){N=!0,P=F}finally{try{b&&null!=O.return&&(yield O.return())}finally{if(N)throw P}}return g=null,a.abort()}catch(m){if(a.signal.aborted)return yield g?.();if(!(m instanceof T)||(t&&(y=void 0),!x||I>=x))throw a.abort(),m;p=m}finally{a.signal.aborted&&0==--S&&(isFinite(c)&&c>0?setTimeout(()=>{S||w.abort()},c):w.abort())}}})().then(()=>s.complete()).catch(v=>s.error(v)),()=>a.abort()}return n&&!t&&(0,A.A)(function*(){for(S++;;)try{const{waitForThrow:r}=yield M();yield r()}catch(r){if(h.disposed)return;if(!(r instanceof T)||(y=void 0,!x||I>=x))return l?.(r);p=r}})(),{subscribe:H,iterate(r,s){const i=[],a={done:!1,error:null,resolve:()=>{}},D=H(r,{next(g){i.push(g),a.resolve()},error(g){a.done=!0,a.error=g,a.resolve()},complete(){a.done=!0,a.resolve()}},s),v=(g=(0,Z.A)(function*(){for(;;){for(i.length||(yield(0,X.A)(new Promise(N=>a.resolve=N)));i.length;)yield i.shift();if(a.error)throw a.error;if(a.done)return}}),function b(){return g.apply(this,arguments)})();var g;return v.throw=function(){var g=(0,A.A)(function*(b){return a.done||(a.done=!0,a.error=b,a.resolve()),{done:!0,value:void 0}});return function(b){return g.apply(this,arguments)}}(),v.return=(0,A.A)(function*(){return D(),{done:!0,value:void 0}}),v},dispose(){h.dispose()}}}({url:n.url,credentials:n.withCredentials?"include":"same-origin",headers:n.headers?.reduce((l,{key:L,value:x})=>(l[L]=x,l),{})}),!this.client)throw new Error("Could not create SSE client!");const c=Date.now();return this.cleanup=this.client.subscribe({query:n.query,variables:n.variables,operationName:n.selectedOperation??void 0,extensions:n.extensions},(0,he.G)(t,n.url,c)),()=>{this.destroy()}})}destroy(){var n=this;return(0,A.A)(function*(){try{n.cleanup?.(),n.cleanup=void 0,yield n.client?.dispose(),n.client=void 0}catch(t){console.error(t)}})()}}}}]); //# sourceMappingURL=784.js.map //# debugId=309ec40a-f454-5bdc-b397-4d82adf4199b