UNPKG

altair-static

Version:

Static package for altair graphql client

7 lines (4 loc) 6.29 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]="234234e3-c6bd-58b9-8ed9-c09889974842")}catch(e){}}(); import{G as g,I as A,J as R,Ja as j,L as V,N as x,Q as G,R as w,S as B,W as y,ha as k,ia as S,k as O,m as D,s as _,t as L,u as h,x as I}from"./chunk-K6UUAPPR.js";import{a as n,r as E,v as b}from"./chunk-ZYOLZTH5.js";import{a as m,b as T,j as v}from"./chunk-B7YGBANW.js";j();j();var Q=e=>e.trim().replace(/[^A-Za-z0-9]/g,"_").replace(/_+/g,"_").substr(0,20)+(Math.random()*1e3).toFixed(0),F=e=>g(e).toString(),C=e=>`${e}Fields`,K=e=>({kind:n.FRAGMENT_SPREAD,name:{kind:n.NAME,value:e}}),Y=(e,r)=>Object.entries(e).map(([i,t])=>{let c=r.getType(i),l=c&&c.getFields();return{kind:n.FRAGMENT_DEFINITION,name:{kind:n.NAME,value:C(i)},typeCondition:{kind:n.NAMED_TYPE,name:{kind:n.NAME,value:i}},selectionSet:{kind:n.SELECTION_SET,selections:t.map(p=>{let a=l&&l[p];return{kind:n.FIELD,name:{kind:n.NAME,value:p},type:a?a.type.inspect():""}})}}}),ne=(e,r,i)=>{let t=new k(i);return E(e,S(t,{Field:{enter(l){t.enter(l);let p=t.getType();if(p){let a=F(p),o=r[a];if(o&&l.selectionSet&&o.every(s=>!!l.selectionSet.selections.find(u=>"name"in u&&u.name.value===s)))return T(m({},l),{selectionSet:T(m({},l.selectionSet),{selections:[...l.selectionSet.selections.filter(s=>"name"in s&&!o.includes(s.name.value)),K(C(a))]})})}},leave(l){t.leave(l)}}}))},ie=(e,r)=>{let i=new k(r),t={name:"root",count:0,fields:[],children:{}},c={root:t};function l(o){let s=g(o),u=s.toString();return c[u]||={name:u,count:0,type:s,fields:[],children:{}}}let p={enter(o){i.enter(o);let s=i.getType();if(o.type=s,s&&!I(g(s))){let u=l(s);if(u.count++,o.selectionSet&&o.selectionSet.selections){let N=o.selectionSet.selections.filter(d=>!d.selectionSet||!d.selectionSet.selections).filter(d=>d.kind===n.FIELD).filter(d=>d.name&&d.name.value).map(d=>d.name&&d.name.value).filter(Boolean);u.fields.push(N)}let f=i.getParentType();if(f){let N=l(f);N.children[u.name]=u}else t.children[u.name]=u}return o},leave(o){i.leave(o)}};return E(e,S(i,{OperationDefinition:p,Field:p})),{map:c,tree:t}},re=e=>{let r={};return Object.values(e.map).forEach(i=>{i.count>=2&&i.fields.length&&i.fields[0]?.forEach(t=>{i.fields.slice(1).every(c=>c.includes(t))&&(r[i.name]||=[]).push(t)})}),r},ae=(e,r,i)=>E(e,{Document(t){return T(m({},t),{definitions:t.definitions.concat(Y(r,i))})}}),z=(e,r)=>O(e,r),Z=(e,r)=>z(e.value,r),oe=(e,r,i)=>{let t={},c=[],l=new k(r);return{document:E(e,{enter(a){switch(l.enter(a),a.kind){case n.ARGUMENT:{let o=l.getFieldDef();if(a.value.kind!==n.VARIABLE&&o&&o.args){let s=o.args.find(u=>u.name===a.name.value);if(s){let u=s.name;t[u]&&(u=Q(s.name));let f={name:u,value:Z(a,i),type:s.type.inspect()};return t[u]=f,c.push(f),T(m({},a),{value:{kind:n.VARIABLE,name:{kind:n.NAME,value:u}}})}}}break}},leave(a){switch(l.leave(a),a.kind){case n.OPERATION_DEFINITION:{let o=T(m({},a),{variableDefinitions:(a.variableDefinitions||[]).concat(c.map(u=>({kind:n.VARIABLE_DEFINITION,variable:{kind:n.VARIABLE,name:{kind:n.NAME,value:u.name}},type:{kind:n.NAMED_TYPE,name:{kind:n.NAME,value:u.type}}})))}),s=a.name||{kind:n.NAME,value:Q("refactored")};return o.name=s,c=[],o}}}}),variables:Object.entries(t).reduce((a,[o,s])=>(a[o]=s.value,a),{})}},se=e=>e.replace(/[[\]!]/g,"");var P=(e,r=2)=>v(null,null,function*(){let i=yield import("./chunk-GZBCODHK.js"),t=yield import("./chunk-UM73JACQ.js");return i.format(e,{parser:"graphql",plugins:[t],tabWidth:r})});var Te=(l,p,a,...o)=>v(null,[l,p,a,...o],function*(e,r,i,{maxDepth:t=2,tabSize:c=2}={}){let s=e.getType(i);if(!(s instanceof A))return{generated:"",metas:[]};let u=s.getFields()[r];if(!u)return{generated:"",metas:[]};let f=$(e,s),{node:N,metas:d}=U(u,{maxDepth:t,currentDepth:0}),M={kind:n.SELECTION_SET,selections:[N]},W={kind:n.DOCUMENT,definitions:[f?H(f,M):X(s,M)]};return{generated:yield P(b(W),c),metas:d}}),$=(e,r)=>new Map([[e.getQueryType(),"query"],[e.getMutationType(),"mutation"],[e.getSubscriptionType(),"subscription"]]).get(r),H=(e,r)=>({kind:n.OPERATION_DEFINITION,operation:e,name:void 0,variableDefinitions:[],directives:[],selectionSet:r}),X=(e,r)=>({kind:n.FRAGMENT_DEFINITION,name:{kind:n.NAME,value:"____"},variableDefinitions:[],directives:[],typeCondition:{kind:n.NAMED_TYPE,name:{kind:n.NAME,value:e.name}},selectionSet:r}),ee=(e,{maxDepth:r=1,currentDepth:i=0}={})=>{let t=[],c={kind:n.SELECTION_SET,selections:[]};if(!e)return{selectionSet:c,metas:t};let l=g(e);if(!(l instanceof A||l instanceof R))return{selectionSet:c,metas:t};if(I(e))return{selectionSet:c,metas:t};if(i>=r)return{selectionSet:c,metas:t};let p=l&&l.getFields();return c.selections=Object.entries(p).map(([,a])=>{let{node:o,metas:s}=U(a,{maxDepth:r,currentDepth:i});return t=[...t,...s],o}),{selectionSet:c,metas:t}},U=(e,{maxDepth:r=1,currentDepth:i=0}={})=>{let t=e.args.map(a=>({kind:n.ARGUMENT,name:{kind:n.NAME,value:a.name},value:q(a.type,a.defaultValue)})),{selectionSet:c,metas:l}=ee(e.type,{maxDepth:r,currentDepth:i+1});return{node:{kind:n.FIELD,alias:void 0,name:{kind:n.NAME,value:e.name},arguments:t,directives:[],selectionSet:c},metas:[{hasArgs:!!t.length},...l]}},q=(e,r,{currentDepth:i=0,maxDepth:t=2}={})=>J(e,r,{currentDepth:i,maxDepth:t})??{kind:n.STRING,value:"_____"},J=(e,r,{currentDepth:i=0,maxDepth:t=2}={})=>{let c=y(r,e);if(c)return c;if(h(e)&&(e=e.ofType),L(e))return{kind:n.LIST,values:[q(e.ofType,void 0,{currentDepth:i+1,maxDepth:t})]};if(D(e)||_(e)){if(i>=t)return;let p=[];for(let a of Object.values(e.getFields()))if(x(a)){let o=J(a.type,void 0,{currentDepth:i+1,maxDepth:t});o&&p.push({kind:n.OBJECT_FIELD,name:{kind:n.NAME,value:a.name},value:o})}return{kind:n.OBJECT,fields:p}}if(e instanceof V){let p=e.getValues()[0];return p?y(p.name,e):void 0}switch(F(e)){case"String":return y("string",w);case"Boolean":return y(!0,B);case"Int":return y(1,G)}};var Ne=e=>[e.getQueryType(),e.getMutationType(),e.getSubscriptionType()].filter(Boolean);export{Q as a,ne as b,ie as c,re as d,ae as e,oe as f,se as g,P as h,Te as i,ee as j,Ne as k}; //# sourceMappingURL=chunk-RU5GXIYR.js.map //# debugId=234234e3-c6bd-58b9-8ed9-c09889974842