UNPKG

altair-static

Version:

Static package for altair graphql client

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