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]="a51599c7-37ab-5e2b-9704-fe828e8d99ae")}catch(e){}}(); import{a as ee}from"./chunk-ANLTCLUB.js";import{c as q}from"./chunk-HQ6DUYXL.js";import{a as R,b as J,j as b,k as H,l as Q,m as V}from"./chunk-MZPAXKJS.js";function te(e){return typeof e=="object"&&e!==null}var ne="x-graphql-event-stream-token";function re(e){if(e=e,e!=="next"&&e!=="complete")throw new Error(`Invalid stream event "${e}"`);return e}function oe(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 ie(){let e,t,l,p=!1,c={event:"",data:""},N=[],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;){p&&(e[t]===Y.NewLine&&(d=++t),p=!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:p=!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=re(c.event),u=oe(r,c.data);N.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=[...N];return N=[],s}else d!==0&&(e=e.subarray(d),t-=d)}}function se(e){let{singleConnection:t=!1,lazy:l=!0,lazyCloseTimeout:p=0,onNonLazyError:c=console.error,generateID:N=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,y=0,E=null,I=0;function S(){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(E){if(yield $(I),h.signal.aborted)throw new Error("Connection aborted by the client");I++}(a=r?.connecting)===null||a===void 0||a.call(r,!!E),h=new _;let o=D.onDispose(()=>h.abort());h.signal.addEventListener("abort",()=>{o(),v=void 0});let F=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(F,{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 O=yield w.text();f[ne]=O;let A=yield ae({signal:h.signal,headers:f,credentials:T,referrer:m,referrerPolicy:d,url:F,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,!!E),A.waitForThrow().catch(()=>v=void 0),A}))}catch(a){throw v=void 0,a}})}t&&!l&&b(null,null,function*(){for(y++;;)try{let{waitForThrow:a}=yield S();yield a()}catch(a){if(D.disposed)return;if(!(a instanceof g)||(v=void 0,!x||I>=x))return c?.(a);E=a}});function M(a,i,n){if(!t){let f=new _,w=D.onDispose(()=>{w(),f.abort()});return b(null,null,function*(){var O,A,L,C,k;let j=null,U=0;for(;;)try{if(j){if(yield $(U),f.signal.aborted)throw new Error("Connection aborted by the client");U++}(O=r?.connecting)===null||O===void 0||O.call(r,!!j),(A=n?.connecting)===null||A===void 0||A.call(n,!!j);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 ae({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:G=>{var W,X;(W=r?.message)===null||W===void 0||W.call(r,G),(X=n?.message)===null||X===void 0||X.call(n,G),s?.(G)}});(C=r?.connected)===null||C===void 0||C.call(r,!!j),(k=n?.connected)===null||k===void 0||k.call(n,!!j);try{for(var B=V(de()),P,z,Z;P=!(z=yield B.next()).done;P=!1){let G=z.value;j=null,U=0,i.next(G)}}catch(z){Z=[z]}finally{try{P&&(z=B.return)&&(yield z.call(B))}finally{if(Z)throw Z[0]}}return f.abort()}catch(K){if(f.signal.aborted)return;if(!(K instanceof g)||!x||U>=x)throw K;j=K}}).then(()=>i.complete()).catch(O=>i.error(O)),()=>f.abort()}y++;let o=new _,F=D.onDispose(()=>{F(),o.abort()});return b(null,null,function*(){let f=N();a=J(R({},a),{extensions:J(R({},a.extensions),{operationId:f})});let w=null;for(;;){w=null;try{let{url:k,headers:j,getResults:U}=yield S(),B;try{B=yield u(k,{signal:o.signal,method:"POST",credentials:T,referrer:m,referrerPolicy:d,headers:J(R({},j),{"content-type":"application/json; charset=utf-8"}),body:JSON.stringify(a)})}catch(P){throw new g(P)}if(B.status!==202)throw new g(B);w=()=>b(null,null,function*(){let P;try{let z=new _,Z=D.onDispose(()=>{Z(),z.abort()});P=yield u(k+"?operationId="+f,{signal:z.signal,method:"DELETE",credentials:T,referrer:m,referrerPolicy:d,headers:j})}catch(z){throw new g(z)}if(P.status!==200)throw new g(P)});try{for(var O=V(U({signal:o.signal,operationId:f})),A,L,C;A=!(L=yield O.next()).done;A=!1){let P=L.value;E=null,I=0,i.next(P)}}catch(L){C=[L]}finally{try{A&&(L=O.return)&&(yield L.call(O))}finally{if(C)throw C[0]}}return w=null,o.abort()}catch(k){if(o.signal.aborted)return yield w?.();if(!(k instanceof g)||(l&&(v=void 0),!x||I>=x))throw o.abort(),k;E=k}finally{o.signal.aborted&&--y===0&&(isFinite(p)&&p>0?setTimeout(()=>{y||h.abort()},p):h.abort())}}}).then(()=>i.complete()).catch(f=>i.error(f)),()=>o.abort()}return{subscribe:M,iterate(a,i){let n=[],o={done:!1,error:null,resolve:()=>{}},F=M(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 Q(this,null,function*(){for(;;){for(n.length||(yield new H(new Promise(O=>o.resolve=O)));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 F(),{done:!0,value:void 0}}),f},dispose(){D.dispose()}}}var g=class extends Error{constructor(t){let l,p;ue(t)?(p=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=p}};function ue(e){return te(e)&&typeof e.ok=="boolean"&&typeof e.status=="number"&&typeof e.statusText=="string"}function ae(e){return b(this,null,function*(){let{signal:t,url:l,credentials:p,headers:c,body:N,referrer:x,referrerPolicy:$,fetchFn:T,onMessage:m}=e,d={},s={},r;try{r=yield T(l,{signal:t,method:N?"POST":"GET",credentials:p,referrer:x,referrerPolicy:$,headers:J(R({},c),{accept:"text/event-stream"}),body:N})}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 S=ie();try{for(var v=V(fe(r.body)),y,E,I;y=!(E=yield v.next()).done;y=!1){let M=E.value;if(typeof M=="string")throw u=new Error(`Unexpected string chunk "${M}"`);let a;try{a=S(M)}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(E){I=[E]}finally{try{y&&(E=v.return)&&(yield E.call(v))}finally{if(I)throw I[0]}}if(Object.keys(d).length)throw new Error("Connection closed while having active streams")}catch(S){!u&&Object.keys(d).length?u=new g(S):u=S,_?.(u)}finally{Object.values(d).forEach(({proceed:S})=>S())}}),{url:l,headers:c,waitForThrow:()=>new Promise((h,v)=>{if(u)return v(u);_=v}),getResults(h){return Q(this,null,function*(){var v;let{signal:y,operationId:E=""}=h??{};try{for(;;){for(;!((v=s[E])===null||v===void 0)&&v.length;){let I=s[E].shift();if(I==="complete")return;yield I}if(u)throw u;if(y?.aborted)throw new Error("Getting results aborted by the client");yield new H(new Promise(I=>{let S=()=>{y?.removeEventListener("abort",S),delete d[E],I()};y?.addEventListener("abort",S),d[E]={proceed:S}}))}}finally{delete s[E]}})}}})}function fe(e){return typeof Object(e)[Symbol.asyncIterator]=="function"?(e=e,e[Symbol.asyncIterator]()):(function(){return Q(this,null,function*(){let t=e.getReader(),l;do l=yield new H(t.read()),l.value!==void 0&&(yield l.value);while(!l.done)})})()}var le=class{handle(t){return new q(l=>{if(this.client=se({url:t.url,credentials:t.withCredentials?"include":"same-origin",headers:t.headers?.reduce((c,{key:N,value:x})=>(c[N]=x,c),{})}),!this.client)throw new Error("Could not create SSE client!");let p=Date.now();return this.cleanup=this.client.subscribe({query:t.query,variables:t.variables,operationName:t.selectedOperation??void 0,extensions:t.extensions},ee(l,t.url,p)),()=>{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{le as SSERequestHandler}; //# sourceMappingURL=chunk-COP2XRU7.js.map //# debugId=a51599c7-37ab-5e2b-9704-fe828e8d99ae