@samarium.sdk/new 0.22.2 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/samarium +744 -392
- package/package.json +1 -1
package/bin/samarium
CHANGED
|
@@ -354,7 +354,7 @@ ${F.comment}`:F.comment}this.doc.range[2]=F.offset;break}default:this.errors.pus
|
|
|
354
354
|
`)+1;while(F!==0)this.onNewLine(this.offset+F),F=this.source.indexOf(`
|
|
355
355
|
`,F)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(D){let F=D.items[D.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,F.value){let P="end"in F.value?F.value.end:void 0;if((Array.isArray(P)?P[P.length-1]:void 0)?.type==="comment")P?.push(this.sourceToken);else D.items.push({start:[this.sourceToken]})}else if(F.sep)F.sep.push(this.sourceToken);else F.start.push(this.sourceToken);return;case"space":case"comment":if(F.value)D.items.push({start:[this.sourceToken]});else if(F.sep)F.sep.push(this.sourceToken);else{if(this.atIndentedComment(F.start,D.indent)){let B=D.items[D.items.length-2]?.value?.end;if(Array.isArray(B)){Array.prototype.push.apply(B,F.start),B.push(this.sourceToken),D.items.pop();return}}F.start.push(this.sourceToken)}return}if(this.indent>=D.indent){let P=!this.onKeyLine&&this.indent===D.indent,B=P&&(F.sep||F.explicitKey)&&this.type!=="seq-item-ind",Z=[];if(B&&F.sep&&!F.value){let q=[];for(let X=0;X<F.sep.length;++X){let J=F.sep[X];switch(J.type){case"newline":q.push(X);break;case"space":break;case"comment":if(J.indent>D.indent)q.length=0;break;default:q.length=0}}if(q.length>=2)Z=F.sep.splice(q[1])}switch(this.type){case"anchor":case"tag":if(B||F.value)Z.push(this.sourceToken),D.items.push({start:Z}),this.onKeyLine=!0;else if(F.sep)F.sep.push(this.sourceToken);else F.start.push(this.sourceToken);return;case"explicit-key-ind":if(!F.sep&&!F.explicitKey)F.start.push(this.sourceToken),F.explicitKey=!0;else if(B||F.value)Z.push(this.sourceToken),D.items.push({start:Z,explicitKey:!0});else this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]});this.onKeyLine=!0;return;case"map-value-ind":if(F.explicitKey)if(!F.sep)if(D8(F.start,"newline"))Object.assign(F,{key:null,sep:[this.sourceToken]});else{let q=l8(F.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:q,key:null,sep:[this.sourceToken]}]})}else if(F.value)D.items.push({start:[],key:null,sep:[this.sourceToken]});else if(D8(F.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:Z,key:null,sep:[this.sourceToken]}]});else if(lQ(F.key)&&!D8(F.sep,"newline")){let q=l8(F.start),X=F.key,J=F.sep;J.push(this.sourceToken),delete F.key,delete F.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:q,key:X,sep:J}]})}else if(Z.length>0)F.sep=F.sep.concat(Z,this.sourceToken);else F.sep.push(this.sourceToken);else if(!F.sep)Object.assign(F,{key:null,sep:[this.sourceToken]});else if(F.value||B)D.items.push({start:Z,key:null,sep:[this.sourceToken]});else if(D8(F.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]});else F.sep.push(this.sourceToken);this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let q=this.flowScalar(this.type);if(B||F.value)D.items.push({start:Z,key:q,sep:[]}),this.onKeyLine=!0;else if(F.sep)this.stack.push(q);else Object.assign(F,{key:q,sep:[]}),this.onKeyLine=!0;return}default:{let q=this.startBlockValue(D);if(q){if(P&&q.type!=="block-seq")D.items.push({start:Z});this.stack.push(q);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(D){let F=D.items[D.items.length-1];switch(this.type){case"newline":if(F.value){let P="end"in F.value?F.value.end:void 0;if((Array.isArray(P)?P[P.length-1]:void 0)?.type==="comment")P?.push(this.sourceToken);else D.items.push({start:[this.sourceToken]})}else F.start.push(this.sourceToken);return;case"space":case"comment":if(F.value)D.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(F.start,D.indent)){let B=D.items[D.items.length-2]?.value?.end;if(Array.isArray(B)){Array.prototype.push.apply(B,F.start),B.push(this.sourceToken),D.items.pop();return}}F.start.push(this.sourceToken)}return;case"anchor":case"tag":if(F.value||this.indent<=D.indent)break;F.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==D.indent)break;if(F.value||D8(F.start,"seq-item-ind"))D.items.push({start:[this.sourceToken]});else F.start.push(this.sourceToken);return}if(this.indent>D.indent){let P=this.startBlockValue(D);if(P){this.stack.push(P);return}}yield*this.pop(),yield*this.step()}*flowCollection(D){let F=D.items[D.items.length-1];if(this.type==="flow-error-end"){let P;do yield*this.pop(),P=this.peek(1);while(P&&P.type==="flow-collection")}else if(D.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":if(!F||F.sep)D.items.push({start:[this.sourceToken]});else F.start.push(this.sourceToken);return;case"map-value-ind":if(!F||F.value)D.items.push({start:[],key:null,sep:[this.sourceToken]});else if(F.sep)F.sep.push(this.sourceToken);else Object.assign(F,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":if(!F||F.value)D.items.push({start:[this.sourceToken]});else if(F.sep)F.sep.push(this.sourceToken);else F.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let B=this.flowScalar(this.type);if(!F||F.value)D.items.push({start:[],key:B,sep:[]});else if(F.sep)this.stack.push(B);else Object.assign(F,{key:B,sep:[]});return}case"flow-map-end":case"flow-seq-end":D.end.push(this.sourceToken);return}let P=this.startBlockValue(D);if(P)this.stack.push(P);else yield*this.pop(),yield*this.step()}else{let P=this.peek(2);if(P.type==="block-map"&&(this.type==="map-value-ind"&&P.indent===D.indent||this.type==="newline"&&!P.items[P.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&P.type!=="flow-collection"){let B=p5(P),Z=l8(B);mQ(D);let q=D.end.splice(1,D.end.length);q.push(this.sourceToken);let X={type:"block-map",offset:D.offset,indent:D.indent,items:[{start:Z,key:D,sep:q}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=X}else yield*this.lineEnd(D)}}flowScalar(D){if(this.onNewLine){let F=this.source.indexOf(`
|
|
356
356
|
`)+1;while(F!==0)this.onNewLine(this.offset+F),F=this.source.indexOf(`
|
|
357
|
-
`,F)+1}return{type:D,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(D){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let F=p5(D),P=l8(F);return P.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:P,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let F=p5(D),P=l8(F);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:P,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(D,F){if(this.type!=="comment")return!1;if(this.indent<=F)return!1;return D.every((P)=>P.type==="newline"||P.type==="space")}*documentEnd(D){if(this.type!=="doc-mode"){if(D.end)D.end.push(this.sourceToken);else D.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}*lineEnd(D){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;case"space":case"comment":default:if(D.end)D.end.push(this.sourceToken);else D.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}}ng.Parser=cQ});var sQ=Q((Zy)=>{var dQ=CP(),og=H6(),G6=U6(),tg=_F(),eg=i(),Dy=_P(),pQ=kP();function rQ(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Dy.LineCounter||null,prettyErrors:F}}function Fy(D,F={}){let{lineCounter:P,prettyErrors:B}=rQ(F),Z=new pQ.Parser(P?.addNewLine),q=new dQ.Composer(F),X=Array.from(q.compose(Z.parse(D)));if(B&&P)for(let J of X)J.errors.forEach(G6.prettifyError(D,P)),J.warnings.forEach(G6.prettifyError(D,P));if(X.length>0)return X;return Object.assign([],{empty:!0},q.streamInfo())}function aQ(D,F={}){let{lineCounter:P,prettyErrors:B}=rQ(F),Z=new pQ.Parser(P?.addNewLine),q=new dQ.Composer(F),X=null;for(let J of q.compose(Z.parse(D),!0,D.length))if(!X)X=J;else if(X.options.logLevel!=="silent"){X.errors.push(new G6.YAMLParseError(J.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(B&&P)X.errors.forEach(G6.prettifyError(D,P)),X.warnings.forEach(G6.prettifyError(D,P));return X}function Py(D,F,P){let B=void 0;if(typeof F==="function")B=F;else if(P===void 0&&F&&typeof F==="object")P=F;let Z=aQ(D,P);if(!Z)return null;if(Z.warnings.forEach((q)=>tg.warn(Z.options.logLevel,q)),Z.errors.length>0)if(Z.options.logLevel!=="silent")throw Z.errors[0];else Z.errors=[];return Z.toJS(Object.assign({reviver:B},P))}function By(D,F,P){let B=null;if(typeof F==="function"||Array.isArray(F))B=F;else if(P===void 0&&F)P=F;if(typeof P==="string")P=P.length;if(typeof P==="number"){let Z=Math.round(P);P=Z<1?void 0:Z>8?{indent:8}:{indent:Z}}if(D===void 0){let{keepUndefined:Z}=P??F??{};if(!Z)return}if(eg.isDocument(D)&&!B)return D.toString(P);return new og.Document(D,B,P).toString(P)}Zy.parse=Py;Zy.parseAllDocuments=Fy;Zy.parseDocument=aQ;Zy.stringify=By});var iQ=Q((Ey)=>{var Hy=CP(),Uy=H6(),Wy=JP(),xP=U6(),Oy=n1(),K2=i(),zy=R2(),Qy=ED(),Gy=$2(),Ry=M2(),Iy=c5(),$y=uP(),My=_P(),Ky=kP(),r5=sQ(),nQ=a1();Ey.Composer=Hy.Composer;Ey.Document=Uy.Document;Ey.Schema=Wy.Schema;Ey.YAMLError=xP.YAMLError;Ey.YAMLParseError=xP.YAMLParseError;Ey.YAMLWarning=xP.YAMLWarning;Ey.Alias=Oy.Alias;Ey.isAlias=K2.isAlias;Ey.isCollection=K2.isCollection;Ey.isDocument=K2.isDocument;Ey.isMap=K2.isMap;Ey.isNode=K2.isNode;Ey.isPair=K2.isPair;Ey.isScalar=K2.isScalar;Ey.isSeq=K2.isSeq;Ey.Pair=zy.Pair;Ey.Scalar=Qy.Scalar;Ey.YAMLMap=Gy.YAMLMap;Ey.YAMLSeq=Ry.YAMLSeq;Ey.CST=Iy;Ey.Lexer=$y.Lexer;Ey.LineCounter=My.LineCounter;Ey.Parser=Ky.Parser;Ey.parse=r5.parse;Ey.parseAllDocuments=r5.parseAllDocuments;Ey.parseDocument=r5.parseDocument;Ey.stringify=r5.stringify;Ey.visit=nQ.visit;Ey.visitAsync=nQ.visitAsync});var $6={name:"@samarium.sdk/new",version:"0.
|
|
357
|
+
`,F)+1}return{type:D,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(D){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let F=p5(D),P=l8(F);return P.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:P,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let F=p5(D),P=l8(F);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:P,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(D,F){if(this.type!=="comment")return!1;if(this.indent<=F)return!1;return D.every((P)=>P.type==="newline"||P.type==="space")}*documentEnd(D){if(this.type!=="doc-mode"){if(D.end)D.end.push(this.sourceToken);else D.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}*lineEnd(D){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;case"space":case"comment":default:if(D.end)D.end.push(this.sourceToken);else D.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}}ng.Parser=cQ});var sQ=Q((Zy)=>{var dQ=CP(),og=H6(),G6=U6(),tg=_F(),eg=i(),Dy=_P(),pQ=kP();function rQ(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Dy.LineCounter||null,prettyErrors:F}}function Fy(D,F={}){let{lineCounter:P,prettyErrors:B}=rQ(F),Z=new pQ.Parser(P?.addNewLine),q=new dQ.Composer(F),X=Array.from(q.compose(Z.parse(D)));if(B&&P)for(let J of X)J.errors.forEach(G6.prettifyError(D,P)),J.warnings.forEach(G6.prettifyError(D,P));if(X.length>0)return X;return Object.assign([],{empty:!0},q.streamInfo())}function aQ(D,F={}){let{lineCounter:P,prettyErrors:B}=rQ(F),Z=new pQ.Parser(P?.addNewLine),q=new dQ.Composer(F),X=null;for(let J of q.compose(Z.parse(D),!0,D.length))if(!X)X=J;else if(X.options.logLevel!=="silent"){X.errors.push(new G6.YAMLParseError(J.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(B&&P)X.errors.forEach(G6.prettifyError(D,P)),X.warnings.forEach(G6.prettifyError(D,P));return X}function Py(D,F,P){let B=void 0;if(typeof F==="function")B=F;else if(P===void 0&&F&&typeof F==="object")P=F;let Z=aQ(D,P);if(!Z)return null;if(Z.warnings.forEach((q)=>tg.warn(Z.options.logLevel,q)),Z.errors.length>0)if(Z.options.logLevel!=="silent")throw Z.errors[0];else Z.errors=[];return Z.toJS(Object.assign({reviver:B},P))}function By(D,F,P){let B=null;if(typeof F==="function"||Array.isArray(F))B=F;else if(P===void 0&&F)P=F;if(typeof P==="string")P=P.length;if(typeof P==="number"){let Z=Math.round(P);P=Z<1?void 0:Z>8?{indent:8}:{indent:Z}}if(D===void 0){let{keepUndefined:Z}=P??F??{};if(!Z)return}if(eg.isDocument(D)&&!B)return D.toString(P);return new og.Document(D,B,P).toString(P)}Zy.parse=Py;Zy.parseAllDocuments=Fy;Zy.parseDocument=aQ;Zy.stringify=By});var iQ=Q((Ey)=>{var Hy=CP(),Uy=H6(),Wy=JP(),xP=U6(),Oy=n1(),K2=i(),zy=R2(),Qy=ED(),Gy=$2(),Ry=M2(),Iy=c5(),$y=uP(),My=_P(),Ky=kP(),r5=sQ(),nQ=a1();Ey.Composer=Hy.Composer;Ey.Document=Uy.Document;Ey.Schema=Wy.Schema;Ey.YAMLError=xP.YAMLError;Ey.YAMLParseError=xP.YAMLParseError;Ey.YAMLWarning=xP.YAMLWarning;Ey.Alias=Oy.Alias;Ey.isAlias=K2.isAlias;Ey.isCollection=K2.isCollection;Ey.isDocument=K2.isDocument;Ey.isMap=K2.isMap;Ey.isNode=K2.isNode;Ey.isPair=K2.isPair;Ey.isScalar=K2.isScalar;Ey.isSeq=K2.isSeq;Ey.Pair=zy.Pair;Ey.Scalar=Qy.Scalar;Ey.YAMLMap=Gy.YAMLMap;Ey.YAMLSeq=Ry.YAMLSeq;Ey.CST=Iy;Ey.Lexer=$y.Lexer;Ey.LineCounter=My.LineCounter;Ey.Parser=Ky.Parser;Ey.parse=r5.parse;Ey.parseAllDocuments=r5.parseAllDocuments;Ey.parseDocument=r5.parseDocument;Ey.stringify=r5.stringify;Ey.visit=nQ.visit;Ey.visitAsync=nQ.visitAsync});var $6={name:"@samarium.sdk/new",version:"0.23.1",main:"bin/samarium",type:"module",repository:{type:"git",url:"https://github.com/liontariai/samarium",directory:"packages/new"},keywords:["graphql","typescript","compiler","api","sdk","openapi","oas3","oas3.1","swagger","graphql-sdk","graphql-codegen"],homepage:"https://liontari.ai",bin:{samarium:"bin/samarium"},publishConfig:{access:"public"},files:["bin/**/*","README.md","package.json"],scripts:{prettier:"prettier --write .",bundle:"bun bundle.js",prepublishOnly:"bun run bundle",test:"bun test"},prettier:{tabWidth:4},devDependencies:{"bun-types":"^1.1.29","@samarium.sdk/make":"workspace:*"},peerDependencies:{typescript:"^5.0.0"},dependencies:{"@inquirer/prompts":"^5.0.5",commander:"^11.1.0","detect-indent":"^7.0.1",prettier:"^3.2.5",yaml:"^2.6.0"}};var XB=UD(qB(),1),{program:Hm,createCommand:Um,createArgument:Wm,createOption:Om,CommanderError:zm,InvalidArgumentError:Qm,InvalidOptionArgumentError:Gm,Command:JB,Argument:Rm,Option:Im,Help:$m}=XB.default;var RU=UD(u0(),1);var A3=UD(u0(),1);class Z2 extends Error{response;request;constructor(D,F){let P=`${Z2.extractMessage(D)}: ${JSON.stringify({response:D,request:F})}`;super(P);if(Object.setPrototypeOf(this,Z2.prototype),this.response=D,this.request=F,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,Z2)}static extractMessage(D){return D.errors?.[0]?.message??`GraphQL Error (Code: ${String(D.status)})`}}var C7=(D)=>D.toUpperCase(),R3=(D)=>{return typeof D==="function"?D():D},L7=(D,F)=>D.map((P,B)=>[P,F[B]]),v2=(D)=>{let F={};if(D instanceof Headers)F=oS(D);else if(Array.isArray(D))D.forEach(([P,B])=>{if(P&&B!==void 0)F[P]=B});else if(D)F=D;return F},oS=(D)=>{let F={};return D.forEach((P,B)=>{F[B]=P}),F},BU=(D)=>{try{let F=D();if(tS(F))return F.catch((P)=>{return PU(P)});return F}catch(F){return PU(F)}},PU=(D)=>{if(D instanceof Error)return D;return new Error(String(D))},tS=(D)=>{return typeof D==="object"&&D!==null&&"then"in D&&typeof D.then==="function"&&"catch"in D&&typeof D.catch==="function"&&"finally"in D&&typeof D.finally==="function"},I3=(D)=>{throw new Error(`Unhandled case: ${String(D)}`)},N1=(D)=>{return typeof D==="object"&&D!==null&&!Array.isArray(D)};var ZU=(D,F)=>{return D.documents?D:{documents:D,requestHeaders:F,signal:void 0}};var qU=(D,F,P)=>{return D.query?D:{query:D,variables:F,requestHeaders:P,signal:void 0}};var YU=UD(u0(),1);var w7="Accept",$3="Content-Type",u1="application/json",M3="application/graphql-response+json";var V7=(D)=>D.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),HU=(D)=>{let F=D.toLowerCase();return F.includes(M3)||F.includes(u1)},j7=(D)=>{try{if(Array.isArray(D))return{_tag:"Batch",executionResults:D.map(XU)};else if(N1(D))return{_tag:"Single",executionResult:XU(D)};else throw new Error(`Invalid execution result: result is not object or array.
|
|
358
358
|
Got:
|
|
359
359
|
${String(D)}`)}catch(F){return F}},XU=(D)=>{if(typeof D!=="object"||D===null)throw new Error("Invalid execution result: result is not object");let F=void 0,P=void 0,B=void 0;if("errors"in D){if(!N1(D.errors)&&!Array.isArray(D.errors))throw new Error("Invalid execution result: errors is not plain object OR array");F=D.errors}if("data"in D){if(!N1(D.data)&&D.data!==null)throw new Error("Invalid execution result: data is not plain object");P=D.data}if("extensions"in D){if(!N1(D.extensions))throw new Error("Invalid execution result: extensions is not plain object");B=D.extensions}return{data:P,errors:F,extensions:B}},UU=(D)=>D._tag==="Batch"?D.executionResults.some(JU):JU(D.executionResult),JU=(D)=>Array.isArray(D.errors)?D.errors.length>0:Boolean(D.errors),b7=(D)=>{return typeof D==="object"&&D!==null&&"kind"in D&&D.kind===YU.Kind.OPERATION_DEFINITION};var WU=UD(u0(),1),OU=UD(u0(),1),zU=UD(u0(),1),eS=(D)=>{let F=void 0,P=D.definitions.filter(b7);if(P.length===1)F=P[0].name?.value;return F},DT=(D)=>{let F=!1,P=D.definitions.filter(b7);if(P.length===1)F=P[0].operation===WU.OperationTypeNode.MUTATION;return F},_1=(D,F)=>{let P=typeof D==="string"?D:zU.print(D),B=!1,Z=void 0;if(F)return{expression:P,isMutation:B,operationName:Z};let q=BU(()=>typeof D==="string"?OU.parse(D):D);if(q instanceof Error)return{expression:P,isMutation:B,operationName:Z};return Z=eS(q),B=DT(q),{expression:P,operationName:Z,isMutation:B}};var K3=JSON;var E3=async(D)=>{let F={...D,method:D.request._tag==="Single"?D.request.document.isMutation?"POST":C7(D.method??"post"):D.request.hasMutations?"POST":C7(D.method??"post"),fetchOptions:{...D.fetchOptions,errorPolicy:D.fetchOptions.errorPolicy??"none"}},B=await PT(F.method)(F);if(!B.ok)return new Z2({status:B.status,headers:B.headers},{query:D.request._tag==="Single"?D.request.document.expression:D.request.query,variables:D.request.variables});let Z=await FT(B,D.fetchOptions.jsonSerializer??K3);if(Z instanceof Error)throw Z;let q={status:B.status,headers:B.headers};if(UU(Z)&&F.fetchOptions.errorPolicy==="none"){let X=Z._tag==="Batch"?{...Z.executionResults,...q}:{...Z.executionResult,...q};return new Z2(X,{query:D.request._tag==="Single"?D.request.document.expression:D.request.query,variables:D.request.variables})}switch(Z._tag){case"Single":return{...q,...QU(F)(Z.executionResult)};case"Batch":return{...q,data:Z.executionResults.map(QU(F))};default:I3(Z)}},QU=(D)=>(F)=>{return{extensions:F.extensions,data:F.data,errors:D.fetchOptions.errorPolicy==="all"?F.errors:void 0}},FT=async(D,F)=>{let P=D.headers.get($3),B=await D.text();if(P&&HU(P))return j7(F.parse(B));else return j7(B)},PT=(D)=>async(F)=>{let P=new Headers(F.headers),B=null,Z=void 0;if(!P.has(w7))P.set(w7,[M3,u1].join(", "));if(D==="POST"){if(Z=(F.fetchOptions.jsonSerializer??K3).stringify(BT(F)),typeof Z==="string"&&!P.has($3))P.set($3,u1)}else B=ZT(F);let q={method:D,headers:P,body:Z,...F.fetchOptions},X=new URL(F.url),J=q;if(F.middleware){let H=await Promise.resolve(F.middleware({...q,url:F.url,operationName:F.request._tag==="Single"?F.request.document.operationName:void 0,variables:F.request.variables})),{url:W,...U}=H;X=new URL(W),J=U}if(B)B.forEach((H,W)=>{X.searchParams.append(W,H)});return await(F.fetch??fetch)(X,J)},BT=(D)=>{switch(D.request._tag){case"Single":return{query:D.request.document.expression,variables:D.request.variables,operationName:D.request.document.operationName};case"Batch":return L7(D.request.query,D.request.variables??[]).map(([F,P])=>({query:F,variables:P}));default:throw I3(D.request)}},ZT=(D)=>{let F=D.fetchOptions.jsonSerializer??K3,P=new URLSearchParams;switch(D.request._tag){case"Single":{if(P.append("query",V7(D.request.document.expression)),D.request.variables)P.append("variables",F.stringify(D.request.variables));if(D.request.document.operationName)P.append("operationName",D.request.document.operationName);return P}case"Batch":{let B=D.request.variables?.map((X)=>F.stringify(X))??[],Z=D.request.query.map(V7),q=L7(Z,B).map(([X,J])=>({query:X,variables:J}));return P.append("query",F.stringify(q)),P}default:throw I3(D.request)}};class g2{url;requestConfig;constructor(D,F={}){this.url=D,this.requestConfig=F}rawRequest=async(...D)=>{let[F,P,B]=D,Z=qU(F,P,B),{headers:q,fetch:X=globalThis.fetch,method:J="POST",requestMiddleware:Y,responseMiddleware:H,excludeOperationName:W,...U}=this.requestConfig,{url:O}=this;if(Z.signal!==void 0)U.signal=Z.signal;let z=_1(Z.query,W),I=await E3({url:O,request:{_tag:"Single",document:z,variables:Z.variables},headers:{...v2(R3(q)),...v2(Z.requestHeaders)},fetch:X,method:J,fetchOptions:U,middleware:Y});if(H)await H(I,{operationName:z.operationName,variables:P,url:this.url});if(I instanceof Error)throw I;return I};async request(D,...F){let[P,B]=F,Z=GU(D,P,B),{headers:q,fetch:X=globalThis.fetch,method:J="POST",requestMiddleware:Y,responseMiddleware:H,excludeOperationName:W,...U}=this.requestConfig,{url:O}=this;if(Z.signal!==void 0)U.signal=Z.signal;let z=_1(Z.document,W),I=await E3({url:O,request:{_tag:"Single",document:z,variables:Z.variables},headers:{...v2(R3(q)),...v2(Z.requestHeaders)},fetch:X,method:J,fetchOptions:U,middleware:Y});if(H)await H(I,{operationName:z.operationName,variables:Z.variables,url:this.url});if(I instanceof Error)throw I;return I.data}async batchRequests(D,F){let P=ZU(D,F),{headers:B,excludeOperationName:Z,...q}=this.requestConfig;if(P.signal!==void 0)q.signal=P.signal;let X=P.documents.map(({document:U})=>_1(U,Z)),J=X.map(({expression:U})=>U),Y=X.some(({isMutation:U})=>U),H=P.documents.map(({variables:U})=>U),W=await E3({url:this.url,request:{_tag:"Batch",operationName:void 0,query:J,hasMutations:Y,variables:H},headers:{...v2(R3(B)),...v2(P.requestHeaders)},fetch:this.requestConfig.fetch??globalThis.fetch,method:this.requestConfig.method||"POST",fetchOptions:q,middleware:this.requestConfig.requestMiddleware});if(this.requestConfig.responseMiddleware)await this.requestConfig.responseMiddleware(W,{operationName:void 0,variables:H,url:this.url});if(W instanceof Error)throw W;return W.data}setHeaders(D){return this.requestConfig.headers=D,this}setHeader(D,F){let{headers:P}=this.requestConfig;if(P)P[D]=F;else this.requestConfig.headers={[D]:F};return this}setEndpoint(D){return this.url=D,this}}var GU=(D,F,P)=>{return D.document?D:{document:D,variables:F,requestHeaders:P,signal:void 0}};async function y2(D,F){try{let B=await new g2(D).request(A3.getIntrospectionQuery(),void 0,new Headers(F?.map((q)=>q.split("="))));return A3.buildClientSchema(B)}catch(P){throw P}}import qT from"fs";var S7=async(D,F)=>{let P=await y2(D.url,D.headers),B=RU.printSchema(P);qT.writeFileSync(F,B)};var C3=UD(u0(),1),L3=UD(u0(),1),MD=UD(u0(),1),XT=Object.defineProperty,$U=(D,F)=>{for(var P in F)XT(D,P,{get:F[P],enumerable:!0,configurable:!0,set:(B)=>F[P]=()=>B})};class MU{collector;options;authConfig;static FieldValueWrapperType;static EnumTypesMapped;static HelperTypes;static HelperFunctions;typeMeta;typeName;originalFullTypeName;constructor(D,F,P,B){this.collector=F,this.options=P,this.authConfig=B,this.typeMeta=F.getType(D),this.originalFullTypeName=D,this.typeName=this.originalTypeNameToTypescriptFriendlyName(D)}originalTypeNameToTypescriptFriendlyName(D){return D.replaceAll("[","").replaceAll("]","Array").replaceAll("!","NotNull")}originalTypeNameToTypescriptTypeNameWithoutModifiers(D,F=""){return`${D.replaceAll("[","").replaceAll("]","").replaceAll("!","")}${F}`}originalTypeNameToTypescriptTypeName(D,F=""){return`${this.originalTypeNameToTypescriptTypeNameWithoutModifiers(D,F)}${Array.from({length:D.split("[").length-1}).fill("[]").join("")}`}static makeRootOperationFunction(D){throw new Error("Method not implemented.")}}var JT=`const Proxy = globalThis.Proxy;
|
|
360
360
|
Proxy.prototype = {};
|
|
@@ -1188,401 +1188,458 @@ export class SelectionWrapper<
|
|
|
1188
1188
|
argsMeta,
|
|
1189
1189
|
reCreateValueCallback,
|
|
1190
1190
|
),
|
|
1191
|
-
{
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1191
|
+
(() => {
|
|
1192
|
+
const cache: {
|
|
1193
|
+
data: Map<string, valueT>;
|
|
1194
|
+
proxiedArray: Map<
|
|
1195
|
+
string,
|
|
1196
|
+
SelectionWrapper<
|
|
1197
|
+
fieldName,
|
|
1198
|
+
typeNamePure,
|
|
1199
|
+
typeArrDepth,
|
|
1200
|
+
valueT,
|
|
1201
|
+
argsT
|
|
1202
|
+
>[]
|
|
1203
|
+
>;
|
|
1204
|
+
} = {
|
|
1205
|
+
data: new Map(),
|
|
1206
|
+
proxiedArray: new Map(),
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
const getResultDataForTarget = (
|
|
1210
|
+
t: SelectionWrapperImpl<
|
|
1211
|
+
fieldName,
|
|
1212
|
+
typeNamePure,
|
|
1213
|
+
typeArrDepth,
|
|
1214
|
+
valueT,
|
|
1215
|
+
argsT
|
|
1216
|
+
>,
|
|
1217
|
+
overrideOpPath?: string,
|
|
1218
|
+
): valueT | undefined => {
|
|
1219
|
+
const path = overrideOpPath ?? t[SLW_OP_PATH] ?? "";
|
|
1220
|
+
if (cache.data.has(path)) return cache.data.get(path);
|
|
1221
|
+
|
|
1222
|
+
const data = t[
|
|
1223
|
+
ROOT_OP_COLLECTOR
|
|
1224
|
+
]!.ref.getOperationResultPath<valueT>(
|
|
1225
|
+
(path?.split(".") ?? []).map((p) =>
|
|
1226
|
+
!isNaN(+p) ? +p : p,
|
|
1227
|
+
),
|
|
1228
|
+
t[SLW_FIELD_TYPENAME],
|
|
1229
|
+
t[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1221
1230
|
);
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1231
|
+
|
|
1232
|
+
cache.data.set(path, data);
|
|
1233
|
+
return data;
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
return {
|
|
1237
|
+
// implement ProxyHandler methods
|
|
1238
|
+
ownKeys() {
|
|
1239
|
+
return Reflect.ownKeys(value ?? {});
|
|
1240
|
+
},
|
|
1241
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1242
|
+
return Reflect.getOwnPropertyDescriptor(
|
|
1243
|
+
value ?? {},
|
|
1244
|
+
prop,
|
|
1245
|
+
);
|
|
1246
|
+
},
|
|
1247
|
+
has(target, prop) {
|
|
1248
|
+
if (prop === Symbol.for("nodejs.util.inspect.custom"))
|
|
1249
|
+
return true;
|
|
1250
|
+
if (
|
|
1251
|
+
prop === Symbol.iterator &&
|
|
1252
|
+
typeArrDepth &&
|
|
1253
|
+
Array.isArray(getResultDataForTarget(target))
|
|
1254
|
+
)
|
|
1255
|
+
return true;
|
|
1256
|
+
|
|
1257
|
+
return Reflect.has(value ?? {}, prop);
|
|
1258
|
+
},
|
|
1259
|
+
set(target, p, newValue, receiver) {
|
|
1260
|
+
const pstr = String(p);
|
|
1261
|
+
if (
|
|
1262
|
+
typeof p === "symbol" &&
|
|
1263
|
+
(pstr.startsWith("Symbol(SLW_") ||
|
|
1264
|
+
pstr == "Symbol(ROOT_OP_COLLECTOR)")
|
|
1265
|
+
) {
|
|
1266
|
+
return Reflect.set(target, p, newValue, receiver);
|
|
1267
|
+
}
|
|
1268
|
+
return Reflect.set(
|
|
1269
|
+
target,
|
|
1270
|
+
SLW_SETTER_DATA_OVERRIDE,
|
|
1271
|
+
{
|
|
1272
|
+
...(target[SLW_SETTER_DATA_OVERRIDE] ?? {}),
|
|
1273
|
+
[p]: newValue,
|
|
1242
1274
|
},
|
|
1243
|
-
|
|
1275
|
+
receiver,
|
|
1276
|
+
);
|
|
1277
|
+
},
|
|
1278
|
+
get: (target, prop) => {
|
|
1279
|
+
if (
|
|
1280
|
+
target[SLW_SETTER_DATA_OVERRIDE] &&
|
|
1281
|
+
target[SLW_SETTER_DATA_OVERRIDE][prop]
|
|
1244
1282
|
) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1283
|
+
return target[SLW_SETTER_DATA_OVERRIDE][prop];
|
|
1284
|
+
}
|
|
1285
|
+
if (prop === "$lazy") {
|
|
1286
|
+
const that = this;
|
|
1287
|
+
function lazy(
|
|
1288
|
+
this: {
|
|
1289
|
+
parentSlw: SelectionWrapperImpl<
|
|
1290
|
+
fieldName,
|
|
1291
|
+
typeNamePure,
|
|
1292
|
+
typeArrDepth,
|
|
1293
|
+
valueT,
|
|
1294
|
+
argsT
|
|
1295
|
+
>;
|
|
1296
|
+
key: string;
|
|
1297
|
+
},
|
|
1298
|
+
args?: argsT,
|
|
1299
|
+
) {
|
|
1300
|
+
const { parentSlw, key } = this;
|
|
1301
|
+
const newRootOpCollectorRef = {
|
|
1302
|
+
ref: new OperationSelectionCollector(
|
|
1303
|
+
undefined,
|
|
1304
|
+
undefined,
|
|
1305
|
+
new RootOperation(
|
|
1306
|
+
that[
|
|
1307
|
+
ROOT_OP_COLLECTOR
|
|
1308
|
+
]!.ref.op!.authArg,
|
|
1309
|
+
that[
|
|
1310
|
+
ROOT_OP_COLLECTOR
|
|
1311
|
+
]!.ref.op!.headers,
|
|
1312
|
+
),
|
|
1257
1313
|
),
|
|
1258
|
-
|
|
1259
|
-
};
|
|
1314
|
+
};
|
|
1260
1315
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1316
|
+
const newThisCollector =
|
|
1317
|
+
new OperationSelectionCollector(
|
|
1318
|
+
undefined,
|
|
1319
|
+
newRootOpCollectorRef,
|
|
1320
|
+
);
|
|
1321
|
+
const r =
|
|
1322
|
+
that[SLW_RECREATE_VALUE_CALLBACK]?.bind(
|
|
1323
|
+
newThisCollector,
|
|
1324
|
+
)?.() ?? {};
|
|
1325
|
+
|
|
1326
|
+
const newThat = new SelectionWrapper(
|
|
1327
|
+
that[SLW_FIELD_NAME],
|
|
1328
|
+
that[SLW_FIELD_TYPENAME],
|
|
1329
|
+
that[SLW_FIELD_ARR_DEPTH],
|
|
1330
|
+
r,
|
|
1268
1331
|
newThisCollector,
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
that[SLW_ARGS_META],
|
|
1285
|
-
);
|
|
1286
|
-
Object.keys(r!).forEach(
|
|
1287
|
-
(key) =>
|
|
1288
|
-
(newThat as valueT)[key as keyof valueT],
|
|
1289
|
-
);
|
|
1290
|
-
|
|
1291
|
-
newThat[SLW_IS_ROOT_TYPE] = that[SLW_IS_ROOT_TYPE];
|
|
1292
|
-
newThat[SLW_IS_ON_TYPE_FRAGMENT] =
|
|
1293
|
-
that[SLW_IS_ON_TYPE_FRAGMENT];
|
|
1294
|
-
newThat[SLW_IS_FRAGMENT] = that[SLW_IS_FRAGMENT];
|
|
1332
|
+
// only set parent collector, if 'that' had one,
|
|
1333
|
+
// the absence indicates, that 'that' is a scalar field
|
|
1334
|
+
// without a subselection!
|
|
1335
|
+
that[SLW_PARENT_COLLECTOR]
|
|
1336
|
+
? newRootOpCollectorRef
|
|
1337
|
+
: undefined,
|
|
1338
|
+
that[SLW_ARGS],
|
|
1339
|
+
that[SLW_ARGS_META],
|
|
1340
|
+
);
|
|
1341
|
+
Object.keys(r!).forEach(
|
|
1342
|
+
(key) =>
|
|
1343
|
+
(newThat as valueT)[
|
|
1344
|
+
key as keyof valueT
|
|
1345
|
+
],
|
|
1346
|
+
);
|
|
1295
1347
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1348
|
+
newThat[SLW_IS_ROOT_TYPE] =
|
|
1349
|
+
that[SLW_IS_ROOT_TYPE];
|
|
1350
|
+
newThat[SLW_IS_ON_TYPE_FRAGMENT] =
|
|
1351
|
+
that[SLW_IS_ON_TYPE_FRAGMENT];
|
|
1352
|
+
newThat[SLW_IS_FRAGMENT] =
|
|
1353
|
+
that[SLW_IS_FRAGMENT];
|
|
1354
|
+
|
|
1355
|
+
newThat[SLW_PARENT_SLW] = parentSlw;
|
|
1356
|
+
parentSlw[SLW_COLLECTOR]?.registerSelection(
|
|
1357
|
+
key,
|
|
1358
|
+
newThat,
|
|
1359
|
+
);
|
|
1360
|
+
newThat[SLW_ARGS] = {
|
|
1361
|
+
...(that[SLW_ARGS] ?? {}),
|
|
1362
|
+
...args,
|
|
1363
|
+
} as argsT;
|
|
1305
1364
|
|
|
1306
|
-
|
|
1365
|
+
newThat[SLW_OP_PATH] = that[SLW_OP_PATH];
|
|
1307
1366
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1367
|
+
newRootOpCollectorRef.ref.registerSelection(
|
|
1368
|
+
newThat[SLW_FIELD_NAME]!,
|
|
1369
|
+
newThat,
|
|
1370
|
+
);
|
|
1312
1371
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1372
|
+
const resultProxy = new Proxy(
|
|
1373
|
+
{},
|
|
1374
|
+
{
|
|
1375
|
+
get(_t, _prop) {
|
|
1376
|
+
const result = new Promise(
|
|
1377
|
+
(resolve, reject) => {
|
|
1378
|
+
newRootOpCollectorRef.ref
|
|
1379
|
+
.execute()
|
|
1380
|
+
.catch(reject)
|
|
1381
|
+
.then(() => {
|
|
1382
|
+
resolve(newThat);
|
|
1383
|
+
});
|
|
1384
|
+
},
|
|
1385
|
+
);
|
|
1386
|
+
if (String(_prop) === "then") {
|
|
1387
|
+
return result.then.bind(result);
|
|
1388
|
+
}
|
|
1389
|
+
return result;
|
|
1390
|
+
},
|
|
1331
1391
|
},
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1392
|
+
) as any;
|
|
1393
|
+
|
|
1394
|
+
return new Proxy(
|
|
1395
|
+
{},
|
|
1396
|
+
{
|
|
1397
|
+
get(_t, _prop) {
|
|
1398
|
+
if (String(_prop) === "auth") {
|
|
1399
|
+
return (
|
|
1400
|
+
auth: FnOrPromisOrPrimitive,
|
|
1401
|
+
) => {
|
|
1402
|
+
newRootOpCollectorRef.ref.op!.setAuth(
|
|
1403
|
+
auth,
|
|
1404
|
+
);
|
|
1405
|
+
return resultProxy;
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
return resultProxy[_prop];
|
|
1409
|
+
},
|
|
1350
1410
|
},
|
|
1351
|
-
|
|
1352
|
-
|
|
1411
|
+
);
|
|
1412
|
+
}
|
|
1413
|
+
target[SLW_LAZY_FLAG] = true;
|
|
1414
|
+
lazy[SLW_LAZY_FLAG] = true;
|
|
1415
|
+
return lazy;
|
|
1353
1416
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
return value;
|
|
1396
|
-
}
|
|
1397
|
-
if (prop === "then") {
|
|
1398
|
-
return this;
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
let slw_value = target[SLW_VALUE] as
|
|
1402
|
-
| Record<string, any>
|
|
1403
|
-
| undefined;
|
|
1404
|
-
|
|
1405
|
-
if (target[ROOT_OP_COLLECTOR]?.ref.isExecuted) {
|
|
1406
|
-
const getResultDataForTarget = (
|
|
1407
|
-
t: SelectionWrapperImpl<
|
|
1408
|
-
fieldName,
|
|
1409
|
-
typeNamePure,
|
|
1410
|
-
typeArrDepth,
|
|
1411
|
-
valueT,
|
|
1412
|
-
argsT
|
|
1413
|
-
>,
|
|
1414
|
-
overrideOpPath?: string,
|
|
1415
|
-
): valueT | undefined => {
|
|
1416
|
-
const data = t[
|
|
1417
|
-
ROOT_OP_COLLECTOR
|
|
1418
|
-
]!.ref.getOperationResultPath<valueT>(
|
|
1419
|
-
(
|
|
1420
|
-
(overrideOpPath ?? t[SLW_OP_PATH])?.split(
|
|
1421
|
-
".",
|
|
1422
|
-
) ?? []
|
|
1423
|
-
).map((p) => (!isNaN(+p) ? +p : p)),
|
|
1424
|
-
t[SLW_FIELD_TYPENAME],
|
|
1425
|
-
t[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1426
|
-
);
|
|
1427
|
-
return data;
|
|
1428
|
-
};
|
|
1429
|
-
|
|
1430
|
-
if (prop === Symbol.asyncIterator) {
|
|
1431
|
-
const asyncGenRootPath =
|
|
1432
|
-
target[SLW_OP_PATH]?.split(".")?.[0];
|
|
1433
|
-
const asyncGen = getResultDataForTarget(
|
|
1434
|
-
target,
|
|
1435
|
-
asyncGenRootPath,
|
|
1436
|
-
) as AsyncGenerator<valueT, any, any>;
|
|
1437
|
-
|
|
1438
|
-
return function () {
|
|
1439
|
-
return {
|
|
1440
|
-
next() {
|
|
1441
|
-
return asyncGen.next().then((val) => {
|
|
1442
|
-
return {
|
|
1443
|
-
done: val.done,
|
|
1444
|
-
value: target[SLW_CLONE]({
|
|
1445
|
-
SLW_OP_PATH:
|
|
1446
|
-
asyncGenRootPath,
|
|
1447
|
-
OP_RESULT_DATA: val.value,
|
|
1448
|
-
}),
|
|
1449
|
-
};
|
|
1450
|
-
});
|
|
1451
|
-
},
|
|
1452
|
-
};
|
|
1453
|
-
};
|
|
1417
|
+
if (
|
|
1418
|
+
prop === SLW_UID ||
|
|
1419
|
+
prop === SLW_FIELD_NAME ||
|
|
1420
|
+
prop === SLW_FIELD_TYPENAME ||
|
|
1421
|
+
prop === SLW_FIELD_ARR_DEPTH ||
|
|
1422
|
+
prop === SLW_IS_ROOT_TYPE ||
|
|
1423
|
+
prop === SLW_IS_ON_TYPE_FRAGMENT ||
|
|
1424
|
+
prop === SLW_IS_FRAGMENT ||
|
|
1425
|
+
prop === SLW_VALUE ||
|
|
1426
|
+
prop === SLW_ARGS ||
|
|
1427
|
+
prop === SLW_ARGS_META ||
|
|
1428
|
+
prop === SLW_DIRECTIVE ||
|
|
1429
|
+
prop === SLW_DIRECTIVE_ARGS ||
|
|
1430
|
+
prop === SLW_DIRECTIVE_ARGS_META ||
|
|
1431
|
+
prop === SLW_PARENT_SLW ||
|
|
1432
|
+
prop === SLW_LAZY_FLAG ||
|
|
1433
|
+
prop === ROOT_OP_COLLECTOR ||
|
|
1434
|
+
prop === SLW_PARENT_COLLECTOR ||
|
|
1435
|
+
prop === SLW_COLLECTOR ||
|
|
1436
|
+
prop === SLW_OP_PATH ||
|
|
1437
|
+
prop === SLW_REGISTER_PATH ||
|
|
1438
|
+
prop === SLW_RENDER_WITH_ARGS ||
|
|
1439
|
+
prop === SLW_RECREATE_VALUE_CALLBACK ||
|
|
1440
|
+
prop === SLW_OP_RESULT_DATA_OVERRIDE ||
|
|
1441
|
+
prop === SLW_CLONE ||
|
|
1442
|
+
prop === SLW_SETTER_DATA_OVERRIDE
|
|
1443
|
+
) {
|
|
1444
|
+
return target[
|
|
1445
|
+
prop as keyof SelectionWrapperImpl<
|
|
1446
|
+
fieldName,
|
|
1447
|
+
typeNamePure,
|
|
1448
|
+
typeArrDepth,
|
|
1449
|
+
valueT
|
|
1450
|
+
>
|
|
1451
|
+
];
|
|
1452
|
+
}
|
|
1453
|
+
if (prop === SLW_VALUE) {
|
|
1454
|
+
return value;
|
|
1455
|
+
}
|
|
1456
|
+
if (prop === "then") {
|
|
1457
|
+
return this;
|
|
1454
1458
|
}
|
|
1455
1459
|
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
if (!isNaN(+String(prop))) {
|
|
1460
|
-
const elm = target[SLW_CLONE]({
|
|
1461
|
-
SLW_OP_PATH:
|
|
1462
|
-
target[SLW_OP_PATH] +
|
|
1463
|
-
"." +
|
|
1464
|
-
String(prop),
|
|
1465
|
-
OP_RESULT_DATA:
|
|
1466
|
-
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1467
|
-
});
|
|
1468
|
-
return elm;
|
|
1469
|
-
}
|
|
1460
|
+
let slw_value = target[SLW_VALUE] as
|
|
1461
|
+
| Record<string, any>
|
|
1462
|
+
| undefined;
|
|
1470
1463
|
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1464
|
+
if (target[ROOT_OP_COLLECTOR]?.ref.isExecuted) {
|
|
1465
|
+
if (prop === Symbol.asyncIterator) {
|
|
1466
|
+
const asyncGenRootPath =
|
|
1467
|
+
target[SLW_OP_PATH]?.split(".")?.[0];
|
|
1468
|
+
const asyncGen = getResultDataForTarget(
|
|
1469
|
+
target,
|
|
1470
|
+
asyncGenRootPath,
|
|
1471
|
+
) as AsyncGenerator<valueT, any, any>;
|
|
1472
|
+
|
|
1473
|
+
return function () {
|
|
1474
|
+
return {
|
|
1475
|
+
next() {
|
|
1476
|
+
return asyncGen
|
|
1477
|
+
.next()
|
|
1478
|
+
.then((val) => {
|
|
1479
|
+
return {
|
|
1480
|
+
done: val.done,
|
|
1481
|
+
value: target[
|
|
1482
|
+
SLW_CLONE
|
|
1483
|
+
]({
|
|
1484
|
+
SLW_OP_PATH:
|
|
1485
|
+
asyncGenRootPath,
|
|
1486
|
+
OP_RESULT_DATA:
|
|
1487
|
+
val.value,
|
|
1488
|
+
}),
|
|
1489
|
+
};
|
|
1490
|
+
});
|
|
1491
|
+
},
|
|
1492
|
+
};
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1474
1495
|
|
|
1475
|
-
|
|
1496
|
+
if (!Object.hasOwn(slw_value ?? {}, String(prop))) {
|
|
1497
|
+
const _data = getResultDataForTarget(target);
|
|
1498
|
+
const path = target[SLW_OP_PATH] ?? "";
|
|
1476
1499
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
(
|
|
1480
|
-
target[SLW_CLONE]({
|
|
1500
|
+
// check if the selected field is an array
|
|
1501
|
+
if (typeArrDepth && Array.isArray(_data)) {
|
|
1502
|
+
if (!isNaN(+String(prop))) {
|
|
1503
|
+
const elm = target[SLW_CLONE]({
|
|
1481
1504
|
SLW_OP_PATH:
|
|
1482
|
-
|
|
1483
|
-
"." +
|
|
1484
|
-
String(i),
|
|
1505
|
+
path + "." + String(prop),
|
|
1485
1506
|
OP_RESULT_DATA:
|
|
1486
1507
|
target[
|
|
1487
1508
|
SLW_OP_RESULT_DATA_OVERRIDE
|
|
1488
1509
|
],
|
|
1489
|
-
})
|
|
1490
|
-
|
|
1510
|
+
});
|
|
1511
|
+
return elm;
|
|
1512
|
+
}
|
|
1491
1513
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1514
|
+
const data = _data as valueT[] | undefined;
|
|
1515
|
+
|
|
1516
|
+
if (data === undefined) return undefined;
|
|
1517
|
+
|
|
1518
|
+
const proxiedData =
|
|
1519
|
+
cache.proxiedArray.get(
|
|
1520
|
+
target[SLW_OP_PATH] ?? "",
|
|
1521
|
+
) ??
|
|
1522
|
+
Array.from(
|
|
1523
|
+
{ length: data.length },
|
|
1524
|
+
(_, i) =>
|
|
1525
|
+
target[SLW_CLONE]({
|
|
1526
|
+
SLW_OP_PATH:
|
|
1527
|
+
target[SLW_OP_PATH] +
|
|
1528
|
+
"." +
|
|
1529
|
+
String(i),
|
|
1530
|
+
OP_RESULT_DATA:
|
|
1531
|
+
target[
|
|
1532
|
+
SLW_OP_RESULT_DATA_OVERRIDE
|
|
1533
|
+
],
|
|
1534
|
+
}),
|
|
1535
|
+
);
|
|
1536
|
+
|
|
1537
|
+
if (!cache.proxiedArray.has(path)) {
|
|
1538
|
+
cache.proxiedArray.set(
|
|
1539
|
+
path,
|
|
1540
|
+
proxiedData,
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
const proto =
|
|
1545
|
+
Object.getPrototypeOf(proxiedData);
|
|
1546
|
+
if (Object.hasOwn(proto, prop)) {
|
|
1547
|
+
const v = (proxiedData as any)[prop];
|
|
1548
|
+
if (typeof v === "function")
|
|
1549
|
+
return v.bind(proxiedData);
|
|
1550
|
+
return v;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
return (proxiedData as any)[prop];
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
const data = _data as valueT | undefined;
|
|
1557
|
+
if (data === undefined) return undefined;
|
|
1558
|
+
const proto = Object.getPrototypeOf(data);
|
|
1494
1559
|
if (Object.hasOwn(proto, prop)) {
|
|
1495
|
-
const v = (
|
|
1560
|
+
const v = (data as any)[prop];
|
|
1496
1561
|
if (typeof v === "function")
|
|
1497
|
-
return v.bind(
|
|
1562
|
+
return v.bind(data);
|
|
1498
1563
|
return v;
|
|
1499
1564
|
}
|
|
1500
1565
|
|
|
1501
|
-
return (
|
|
1566
|
+
return (data as any)[prop];
|
|
1502
1567
|
}
|
|
1503
1568
|
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
if (
|
|
1510
|
-
|
|
1511
|
-
|
|
1569
|
+
let slw = slw_value?.[String(prop)];
|
|
1570
|
+
let slwOpPathIsIndexAccessOrInArray = false;
|
|
1571
|
+
let targetOpPathArr =
|
|
1572
|
+
target[SLW_OP_PATH]?.split(".") ?? [];
|
|
1573
|
+
while (targetOpPathArr.length) {
|
|
1574
|
+
if (!isNaN(+targetOpPathArr.pop()!)) {
|
|
1575
|
+
slwOpPathIsIndexAccessOrInArray = true;
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1512
1578
|
}
|
|
1513
1579
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1580
|
+
if (
|
|
1581
|
+
slwOpPathIsIndexAccessOrInArray ||
|
|
1582
|
+
(target[SLW_OP_RESULT_DATA_OVERRIDE] &&
|
|
1583
|
+
!slw[SLW_OP_RESULT_DATA_OVERRIDE])
|
|
1584
|
+
) {
|
|
1585
|
+
// index access detected, cloning
|
|
1586
|
+
slw = slw[SLW_CLONE]({
|
|
1587
|
+
SLW_OP_PATH:
|
|
1588
|
+
target[SLW_OP_PATH] +
|
|
1589
|
+
"." +
|
|
1590
|
+
String(prop),
|
|
1591
|
+
OP_RESULT_DATA:
|
|
1592
|
+
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1516
1595
|
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
if (
|
|
1523
|
-
|
|
1524
|
-
|
|
1596
|
+
if (
|
|
1597
|
+
slw instanceof SelectionWrapperImpl &&
|
|
1598
|
+
slw[SLW_PARENT_COLLECTOR]
|
|
1599
|
+
) {
|
|
1600
|
+
return slw;
|
|
1601
|
+
} else if (slw instanceof SelectionWrapperImpl) {
|
|
1602
|
+
return getResultDataForTarget(slw);
|
|
1603
|
+
} else if (slw[SLW_LAZY_FLAG]) {
|
|
1604
|
+
return slw;
|
|
1525
1605
|
}
|
|
1526
|
-
}
|
|
1527
1606
|
|
|
1528
|
-
|
|
1529
|
-
slwOpPathIsIndexAccessOrInArray ||
|
|
1530
|
-
(target[SLW_OP_RESULT_DATA_OVERRIDE] &&
|
|
1531
|
-
!slw[SLW_OP_RESULT_DATA_OVERRIDE])
|
|
1532
|
-
) {
|
|
1533
|
-
// index access detected, cloning
|
|
1534
|
-
slw = slw[SLW_CLONE]({
|
|
1535
|
-
SLW_OP_PATH:
|
|
1536
|
-
target[SLW_OP_PATH] + "." + String(prop),
|
|
1537
|
-
OP_RESULT_DATA:
|
|
1538
|
-
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1539
|
-
});
|
|
1607
|
+
return getResultDataForTarget(target);
|
|
1540
1608
|
}
|
|
1541
1609
|
|
|
1542
1610
|
if (
|
|
1543
|
-
|
|
1544
|
-
|
|
1611
|
+
Object.hasOwn(slw_value ?? {}, String(prop)) &&
|
|
1612
|
+
slw_value?.[String(prop)] instanceof
|
|
1613
|
+
SelectionWrapperImpl
|
|
1545
1614
|
) {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
if (
|
|
1557
|
-
Object.hasOwn(slw_value ?? {}, String(prop)) &&
|
|
1558
|
-
slw_value?.[String(prop)] instanceof
|
|
1559
|
-
SelectionWrapperImpl
|
|
1560
|
-
) {
|
|
1561
|
-
if (target[SLW_COLLECTOR]) {
|
|
1562
|
-
target[SLW_COLLECTOR].registerSelection(
|
|
1563
|
-
String(prop),
|
|
1564
|
-
slw_value[String(prop)],
|
|
1565
|
-
);
|
|
1566
|
-
}
|
|
1567
|
-
if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
|
|
1568
|
-
slw_value[String(prop)][SLW_PARENT_SLW] = target;
|
|
1615
|
+
if (target[SLW_COLLECTOR]) {
|
|
1616
|
+
target[SLW_COLLECTOR].registerSelection(
|
|
1617
|
+
String(prop),
|
|
1618
|
+
slw_value[String(prop)],
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
|
|
1622
|
+
slw_value[String(prop)][SLW_PARENT_SLW] =
|
|
1623
|
+
target;
|
|
1624
|
+
}
|
|
1569
1625
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1626
|
+
if (slw_value?.[String(prop)]?.[SLW_LAZY_FLAG]) {
|
|
1627
|
+
if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
|
|
1628
|
+
const lazyFn = slw_value[String(prop)];
|
|
1629
|
+
slw_value[String(prop)] = lazyFn.bind({
|
|
1630
|
+
parentSlw: target,
|
|
1631
|
+
key: String(prop),
|
|
1632
|
+
});
|
|
1633
|
+
slw_value[String(prop)][SLW_PARENT_SLW] =
|
|
1634
|
+
target;
|
|
1635
|
+
slw_value[String(prop)][SLW_LAZY_FLAG] = true;
|
|
1636
|
+
}
|
|
1580
1637
|
}
|
|
1581
|
-
}
|
|
1582
1638
|
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1639
|
+
return slw_value?.[String(prop)] ?? undefined;
|
|
1640
|
+
},
|
|
1641
|
+
};
|
|
1642
|
+
})(),
|
|
1586
1643
|
);
|
|
1587
1644
|
}
|
|
1588
1645
|
}
|
|
@@ -1741,12 +1798,298 @@ export class SelectionWrapper<
|
|
|
1741
1798
|
>
|
|
1742
1799
|
>;
|
|
1743
1800
|
`;static HelperFunctions=`
|
|
1744
|
-
const selectScalars =
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1801
|
+
const selectScalars = (selection: Record<string, any>) =>
|
|
1802
|
+
Object.fromEntries(
|
|
1803
|
+
Object.entries(selection).filter(
|
|
1804
|
+
([k, v]) => v instanceof SelectionWrapperImpl,
|
|
1805
|
+
),
|
|
1806
|
+
);
|
|
1807
|
+
|
|
1808
|
+
type AllNonFuncFieldsFromType<
|
|
1809
|
+
TRaw,
|
|
1810
|
+
T = TRaw extends Array<infer A> ? A : TRaw,
|
|
1811
|
+
> = Pick<
|
|
1812
|
+
T,
|
|
1813
|
+
{ [k in keyof T]: T[k] extends (args: any) => any ? never : k }[keyof T]
|
|
1814
|
+
>;
|
|
1815
|
+
|
|
1816
|
+
type SetNestedFieldNever<
|
|
1817
|
+
T,
|
|
1818
|
+
Path extends string,
|
|
1819
|
+
> = Path extends \`\${infer Key}.\${infer Rest}\`
|
|
1820
|
+
? Key extends keyof T
|
|
1821
|
+
? {
|
|
1822
|
+
[K in keyof T]: K extends Key
|
|
1823
|
+
? SetNestedFieldNever<T[K], Rest>
|
|
1824
|
+
: T[K];
|
|
1825
|
+
}
|
|
1826
|
+
: T
|
|
1827
|
+
: { [K in keyof T]: K extends Path ? never : T[K] };
|
|
1828
|
+
|
|
1829
|
+
type primitives =
|
|
1830
|
+
| string
|
|
1831
|
+
| number
|
|
1832
|
+
| boolean
|
|
1833
|
+
| Record<string | number | symbol, unknown>;
|
|
1834
|
+
type isScalar<T> =
|
|
1835
|
+
T extends Exclude<
|
|
1836
|
+
ScalarTypeMapDefault[keyof ScalarTypeMapDefault],
|
|
1837
|
+
primitives
|
|
1838
|
+
>
|
|
1839
|
+
? true
|
|
1840
|
+
: T extends Exclude<
|
|
1841
|
+
ScalarTypeMapWithCustom[keyof ScalarTypeMapWithCustom],
|
|
1842
|
+
primitives
|
|
1843
|
+
>
|
|
1844
|
+
? true
|
|
1845
|
+
: false;
|
|
1846
|
+
|
|
1847
|
+
// Utility type to get all possible dot-notation paths
|
|
1848
|
+
type Paths<T, Visited = never, Depth extends Prev[number] = 9> =
|
|
1849
|
+
isScalar<T> extends true
|
|
1850
|
+
? never
|
|
1851
|
+
: Depth extends never
|
|
1852
|
+
? never
|
|
1853
|
+
: T extends object
|
|
1854
|
+
? T extends Visited
|
|
1855
|
+
? never // Stop recursion if type is cyclic
|
|
1856
|
+
: {
|
|
1857
|
+
[K in keyof T]: T[K] extends Array<infer U>
|
|
1858
|
+
? K extends string | number
|
|
1859
|
+
?
|
|
1860
|
+
| \`\${K}\`
|
|
1861
|
+
| \`\${K}.\${Paths<U, Visited | T, Prev[Depth]>}\`
|
|
1862
|
+
: never
|
|
1863
|
+
: K extends string | number
|
|
1864
|
+
? T[K] extends object
|
|
1865
|
+
?
|
|
1866
|
+
| \`\${K}\`
|
|
1867
|
+
| \`\${K}.\${Paths<T[K], Visited | T, Prev[Depth]>}\`
|
|
1868
|
+
: \`\${K}\`
|
|
1869
|
+
: never;
|
|
1870
|
+
}[keyof T]
|
|
1871
|
+
: never;
|
|
1872
|
+
|
|
1873
|
+
// Utility type to get only cyclic paths
|
|
1874
|
+
type CyclicPaths<
|
|
1875
|
+
T,
|
|
1876
|
+
Visited = never,
|
|
1877
|
+
Depth extends Prev[number] = 9,
|
|
1878
|
+
Prefix extends string = "",
|
|
1879
|
+
> =
|
|
1880
|
+
isScalar<T> extends true
|
|
1881
|
+
? never
|
|
1882
|
+
: Depth extends never
|
|
1883
|
+
? never
|
|
1884
|
+
: T extends object
|
|
1885
|
+
? {
|
|
1886
|
+
[K in keyof T]: T[K] extends Array<infer U>
|
|
1887
|
+
? K extends string | number
|
|
1888
|
+
? U extends Visited
|
|
1889
|
+
? \`\${Prefix}\${K}\` // Cyclic path found for array element
|
|
1890
|
+
: CyclicPaths<
|
|
1891
|
+
U,
|
|
1892
|
+
Visited | T,
|
|
1893
|
+
Prev[Depth],
|
|
1894
|
+
\`\${Prefix}\${K}.\`
|
|
1895
|
+
>
|
|
1896
|
+
: never
|
|
1897
|
+
: K extends string | number
|
|
1898
|
+
? T[K] extends Visited
|
|
1899
|
+
? \`\${Prefix}\${K}\` // Cyclic path found
|
|
1900
|
+
: T[K] extends object
|
|
1901
|
+
? CyclicPaths<
|
|
1902
|
+
T[K],
|
|
1903
|
+
Visited | T,
|
|
1904
|
+
Prev[Depth],
|
|
1905
|
+
\`\${Prefix}\${K}.\`
|
|
1906
|
+
>
|
|
1907
|
+
: never
|
|
1908
|
+
: never;
|
|
1909
|
+
}[keyof T]
|
|
1910
|
+
: never;
|
|
1911
|
+
|
|
1912
|
+
// Utility type to exclude multiple paths
|
|
1913
|
+
type OmitMultiplePaths<T, Paths extends string> = Paths extends any
|
|
1914
|
+
? SetNestedFieldNever<T, Paths>
|
|
1915
|
+
: T;
|
|
1916
|
+
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
|
|
1917
|
+
x: infer I,
|
|
1918
|
+
) => void
|
|
1919
|
+
? I
|
|
1920
|
+
: never;
|
|
1921
|
+
type MergeUnion<T> = UnionToIntersection<T>;
|
|
1922
|
+
type TurnToArray<T, yes extends boolean> = yes extends true ? T[] : T;
|
|
1923
|
+
type OmitNever<
|
|
1924
|
+
TRaw,
|
|
1925
|
+
TisArray extends boolean = TRaw extends Array<any> ? true : false,
|
|
1926
|
+
T = TRaw extends Array<infer A> ? A : TRaw
|
|
1927
|
+
> = isScalar<T> extends true
|
|
1928
|
+
? TurnToArray<T, TisArray>
|
|
1929
|
+
: T extends object
|
|
1930
|
+
? TurnToArray<
|
|
1931
|
+
{
|
|
1932
|
+
[K in keyof T as T[K] extends never ? never : T[K] extends never[] ? never : K]: isScalar<T[K]> extends true
|
|
1933
|
+
? T[K]
|
|
1934
|
+
: T[K] extends object
|
|
1935
|
+
? OmitNever<T[K]>
|
|
1936
|
+
: T[K];
|
|
1937
|
+
},
|
|
1938
|
+
TisArray
|
|
1939
|
+
>
|
|
1940
|
+
: TurnToArray<T, TisArray>;
|
|
1941
|
+
|
|
1942
|
+
const selectCyclicFieldsOptsStr = "select cyclic levels: ";
|
|
1943
|
+
type selectCyclicFieldsOptsStrType = typeof selectCyclicFieldsOptsStr;
|
|
1944
|
+
type cyclicOpts<
|
|
1945
|
+
S,
|
|
1946
|
+
CP = CyclicPaths<S>,
|
|
1947
|
+
kOpts = "exclude" | \`\${selectCyclicFieldsOptsStrType}\${1 | 2 | 3 | 4 | 5}\`,
|
|
1948
|
+
> = CP extends never
|
|
1949
|
+
? never
|
|
1950
|
+
: {
|
|
1951
|
+
[k in CP & string]: kOpts;
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1954
|
+
type Next = [1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
|
|
1955
|
+
type StringToNumber<S extends string> = S extends \`\${infer N extends number}\`
|
|
1956
|
+
? N
|
|
1957
|
+
: never;
|
|
1958
|
+
|
|
1959
|
+
type getNumberNestedLevels<str extends string> =
|
|
1960
|
+
str extends \`\${selectCyclicFieldsOptsStrType}\${infer n}\`
|
|
1961
|
+
? StringToNumber<n>
|
|
1962
|
+
: never;
|
|
1963
|
+
|
|
1964
|
+
type selectAllOpts<S> =
|
|
1965
|
+
| {
|
|
1966
|
+
exclude?: Paths<S>[];
|
|
1967
|
+
}
|
|
1968
|
+
| {
|
|
1969
|
+
exclude?: Paths<S>[];
|
|
1970
|
+
cyclic: cyclicOpts<S>;
|
|
1971
|
+
};
|
|
1972
|
+
type RepeatString<
|
|
1973
|
+
S extends string,
|
|
1974
|
+
N extends number,
|
|
1975
|
+
Splitter extends string = "",
|
|
1976
|
+
Acc extends string = "",
|
|
1977
|
+
Count extends number = N,
|
|
1978
|
+
> = Count extends 0
|
|
1979
|
+
? Acc
|
|
1980
|
+
: RepeatString<
|
|
1981
|
+
S,
|
|
1982
|
+
N,
|
|
1983
|
+
Splitter,
|
|
1984
|
+
\`\${Acc}\${Acc extends "" ? "" : Splitter}\${S}\`,
|
|
1985
|
+
Prev[Count]
|
|
1986
|
+
>;
|
|
1987
|
+
|
|
1988
|
+
type GetSuffix<
|
|
1989
|
+
Str extends string,
|
|
1990
|
+
Prefix extends string,
|
|
1991
|
+
> = Str extends \`\${Prefix}\${infer Suffix}\` ? Suffix : never;
|
|
1992
|
+
|
|
1993
|
+
type selectAllFunc<T, TNP extends string> = <const P = Paths<T>, const CP_WITH_TNP = cyclicOpts<T, \`\${TNP}.\${CyclicPaths<T>}\`>>(
|
|
1994
|
+
opts: CyclicPaths<T> extends never
|
|
1995
|
+
? {
|
|
1996
|
+
exclude?: \`\${TNP}.\${P & string}\`[];
|
|
1997
|
+
}
|
|
1998
|
+
: {
|
|
1999
|
+
exclude?: \`\${TNP}.\${P & string}\`[];
|
|
2000
|
+
cyclic: CP_WITH_TNP;
|
|
2001
|
+
}
|
|
2002
|
+
) => OmitNever<
|
|
2003
|
+
MergeUnion<
|
|
2004
|
+
OmitMultiplePaths<
|
|
2005
|
+
T,
|
|
2006
|
+
| (Exclude<Paths<T>, P> extends never ? "" : P & string)
|
|
2007
|
+
| (
|
|
2008
|
+
CP_WITH_TNP extends never
|
|
2009
|
+
? ""
|
|
2010
|
+
: {
|
|
2011
|
+
[k in keyof CP_WITH_TNP]: "exclude" extends CP_WITH_TNP[k]
|
|
2012
|
+
? GetSuffix<k & string, \`\${TNP}.\`>
|
|
2013
|
+
: RepeatString<
|
|
2014
|
+
GetSuffix<k & string, \`\${TNP}.\`>,
|
|
2015
|
+
Next[getNumberNestedLevels<CP_WITH_TNP[k] & string>],
|
|
2016
|
+
"."
|
|
2017
|
+
>;
|
|
2018
|
+
}[keyof CP_WITH_TNP]
|
|
2019
|
+
)
|
|
2020
|
+
>
|
|
2021
|
+
>
|
|
2022
|
+
>;
|
|
2023
|
+
|
|
2024
|
+
const selectAll = <
|
|
2025
|
+
S,
|
|
2026
|
+
TNP extends string,
|
|
2027
|
+
SUB extends ReturnType<SLFN<{}, unknown, string, string, number>>,
|
|
2028
|
+
V extends
|
|
2029
|
+
| (SelectionWrapperImpl<any, any, any> | SUB)
|
|
2030
|
+
| ((args: any) => SelectionWrapperImpl<any, any, any> | SUB),
|
|
2031
|
+
>(
|
|
2032
|
+
selection: Record<string, V>,
|
|
2033
|
+
typeNamePure: TNP,
|
|
2034
|
+
opts: selectAllOpts<S>,
|
|
2035
|
+
collector?: { parents: string[]; path?: string },
|
|
2036
|
+
) => {
|
|
2037
|
+
// let's not make the type too complicated, it's basically a
|
|
2038
|
+
// nested map of string to either SLW or again
|
|
2039
|
+
// a map of string to SLW
|
|
2040
|
+
const s: Record<string, any> = {};
|
|
2041
|
+
const entries = Object.entries(selection);
|
|
2042
|
+
for (const [k, v] of entries) {
|
|
2043
|
+
const tk = collector?.path
|
|
2044
|
+
? \`\${collector.path}.\${k}\`
|
|
2045
|
+
: \`\${typeNamePure}.\${k}\`;
|
|
2046
|
+
let excludePaths = opts?.exclude ?? ([] as string[]);
|
|
2047
|
+
if ("cyclic" in opts) {
|
|
2048
|
+
const exclude = Object.entries(
|
|
2049
|
+
opts.cyclic as Record<string, string>,
|
|
2050
|
+
)
|
|
2051
|
+
.filter(([k, v]) => v === "exclude")
|
|
2052
|
+
.map((e) => e[0]);
|
|
2053
|
+
const cyclicLevels = Object.entries(
|
|
2054
|
+
opts.cyclic as Record<string, string>,
|
|
2055
|
+
)
|
|
2056
|
+
.filter(([k, v]) => v !== "exclude")
|
|
2057
|
+
.map((e) => {
|
|
2058
|
+
const levels = parseInt(
|
|
2059
|
+
e[1]
|
|
2060
|
+
.match(new RegExp(\`\${selectCyclicFieldsOptsStr}(.*)\`))!
|
|
2061
|
+
.at(1)![0],
|
|
2062
|
+
) + 1;
|
|
2063
|
+
const pathFragment = e[0].split(".").slice(1).join(".");
|
|
2064
|
+
return \`\${e[0].split(".")[0]}.\${Array.from({ length: levels }).fill(pathFragment).join(".")}\`;
|
|
2065
|
+
});
|
|
2066
|
+
excludePaths.push(...exclude, ...cyclicLevels);
|
|
2067
|
+
}
|
|
2068
|
+
if (excludePaths.includes(tk as any)) continue;
|
|
2069
|
+
|
|
2070
|
+
if (typeof v === "function") {
|
|
2071
|
+
if (v.name === "bound _SLFN") {
|
|
2072
|
+
// if (collector?.parents?.includes(tk)) continue;
|
|
2073
|
+
const col = {
|
|
2074
|
+
parents: [...(collector?.parents ?? []), tk],
|
|
2075
|
+
path: tk,
|
|
2076
|
+
};
|
|
2077
|
+
s[k] = v(
|
|
2078
|
+
(sub_s: { $all: (_opts?: {}, collector?: {}) => any }) => {
|
|
2079
|
+
return sub_s.$all(opts, col);
|
|
2080
|
+
},
|
|
2081
|
+
);
|
|
2082
|
+
} else if (!k.startsWith("$")) {
|
|
2083
|
+
console.warn(
|
|
2084
|
+
\`Cannot use $all on fields with args: \${k}: \${v.toString()}\`,
|
|
2085
|
+
);
|
|
2086
|
+
}
|
|
2087
|
+
} else {
|
|
2088
|
+
s[k] = v;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
return s;
|
|
2092
|
+
};
|
|
1750
2093
|
|
|
1751
2094
|
const makeSLFN = <
|
|
1752
2095
|
T extends object,
|
|
@@ -1819,7 +2162,7 @@ export class SelectionWrapper<
|
|
|
1819
2162
|
};
|
|
1820
2163
|
`;return this.collector.addEnumType(this.typeMeta,F),D}makeSelectionTypeInputValueForFieldWrapperType(D,F){let P="";if(F.isEnum)P=F.ofType.name.replaceAll("!","").replaceAll("[","").replaceAll("]","");else P=this.ScalarTypeMap().get(F.name.replaceAll("!","").replaceAll("[","").replaceAll("]",""))??(F.scalarTSType?`ScalarTypeMapWithCustom["${F.name.replaceAll("!","").replaceAll("[","").replaceAll("]","")}"]`:"any");if(F.isList)return`${Array.from({length:F.isList}).map((B)=>"Array<").join("")}${P}${Array.from({length:F.isList}).map((B)=>">").join("")}`;return P}makeSelectionTypeInputValueForField(D,F=[],P=!1){let B=()=>{let q=D.args.some((J)=>J.type.isNonNull),X=`${F.join()}${D.name.slice(0,1).toUpperCase()}${D.name.slice(1)}Args`;if(!this.collector.hasArgumentType(X)){let Y=`{ ${D.args.map((H)=>{let W=H.type.isScalar,U=H.type.isEnum,O=H.type.isInput,z=`${H.name}${H.type.isNonNull?"":"?"}`,I="any";if(W)I=H.type.scalarTSType?`ScalarTypeMapWithCustom["${H.type.name.replaceAll("!","").replaceAll("[","").replaceAll("]","")}"]`:this.ScalarTypeMap().get(H.type.name.replaceAll("!","").replaceAll("[","").replaceAll("]",""))??"any";else if(O||U)I=this.originalTypeNameToTypescriptTypeName(H.type.name);return`${H.description?`/** ${H.description??`${z}`} */`:""}
|
|
1821
2164
|
${z}: ${I};`}).join(" ")} }`;this.collector.addArgumentType(X,`export type ${X} = ${Y};`)}return{argsTypeName:X,hasAtLeastOneNonNullArg:q}},Z=D.description?`/* ${D.description} */
|
|
1822
|
-
`:"";if(D.type.isScalar||D.type.isEnum){let q=this.makeSelectionTypeInputValueForFieldWrapperType(D.name,D.type);if(this.collector.addSelectionType(D.type,q),D.hasArgs){let{argsTypeName:X,hasAtLeastOneNonNullArg:J}=B();return`${Z}${D.name}: (args${J?"":"?"}: ${X}) => ${q};`}return`${Z}${D.name}${D.type.isNonNull?"":"?"}: ${q};`}else if(D.type.ofType){let q=new m2(D.type.ofType.name,this.collector,this.options).makeSelectionFunction();if(D.hasArgs){let{argsTypeName:
|
|
2165
|
+
`:"";if(D.type.isScalar||D.type.isEnum){let q=this.makeSelectionTypeInputValueForFieldWrapperType(D.name,D.type);if(this.collector.addSelectionType(D.type,q),D.hasArgs){let{argsTypeName:X,hasAtLeastOneNonNullArg:J}=B();return`${Z}${D.name}: (args${J?"":"?"}: ${X}) => ${q};`}return`${Z}${D.name}${D.type.isNonNull?"":"?"}: ${q};`}else if(D.type.ofType){let q=new m2(D.type.ofType.name,this.collector,this.options);q.makeSelectionFunction();let X=q.originalTypeNameToTypescriptTypeName(q.originalFullTypeName);if(D.hasArgs){let{argsTypeName:J,hasAtLeastOneNonNullArg:Y}=B();return`${Z}${D.name}: (args${Y?"":"?"}: ${J} ) => ${X};`}if(P)return`${Z}${D.name}${D.type.isNonNull?"":"?"}: ${this.originalTypeNameToTypescriptTypeName(D.type.ofType.name)};`;return`${Z}${D.name}: ${X};`}else throw console.error(D.type),new Error(`Unknown type for field ${D.name}: ${D.type.name}`)}makeSelectionType(){if(this.typeMeta.isDirective)return"";if(this.typeMeta.isScalar||this.typeMeta.isEnum)return this.makeSelectionTypeInputValueForFieldWrapperType(this.typeName,this.typeMeta);let D=this.typeMeta.isInput?this.originalTypeNameToTypescriptTypeNameWithoutModifiers(this.originalFullTypeName):this.typeName;if(this.collector.hasSelectionType(this.typeMeta))return D;let F="";if(this.typeMeta.isUnion){let P=this.typeMeta.possibleTypes.map((B)=>this.originalTypeNameToTypescriptFriendlyName(B.name)).join(" | ");F=`
|
|
1823
2166
|
export type ${D} = ${P};
|
|
1824
2167
|
`}else F=`
|
|
1825
2168
|
export type ${D} = {
|
|
@@ -1852,16 +2195,16 @@ export class SelectionWrapper<
|
|
|
1852
2195
|
${this.typeMeta.isList??0},
|
|
1853
2196
|
{},
|
|
1854
2197
|
this
|
|
1855
|
-
)`;let D=`${this.typeName}Selection`;if(this.collector.hasSelectionFunction(this.typeMeta))return D;else this.collector.addSelectionFunction(this.typeMeta,D);let F=this.typeMeta.fields.some((
|
|
2198
|
+
)`;let D=`${this.typeName}Selection`;if(this.collector.hasSelectionFunction(this.typeMeta))return D;else this.collector.addSelectionFunction(this.typeMeta,D);let F=this.typeMeta.fields.some((H)=>H.type.isScalar||H.type.isEnum),P=this.typeMeta.name===this.collector.QueryTypeName||this.typeMeta.name===this.collector.MutationTypeName||this.typeMeta.name===this.collector.SubscriptionTypeName,B=this.typeMeta.name===this.collector.SubscriptionTypeName,Z=this.originalTypeNameToTypescriptTypeName(this.originalFullTypeName),q="";if(this.typeMeta.isUnion)q=`
|
|
1856
2199
|
$on: {
|
|
1857
|
-
${this.typeMeta.possibleTypes.map((
|
|
2200
|
+
${this.typeMeta.possibleTypes.map((H)=>`${H.name}: ${this.originalTypeNameToTypescriptFriendlyName(H.name)}Selection.bind({
|
|
1858
2201
|
collector: this,
|
|
1859
2202
|
fieldName: "",
|
|
1860
|
-
onTypeFragment: "${
|
|
2203
|
+
onTypeFragment: "${H.name}",
|
|
1861
2204
|
}),`).join(`
|
|
1862
2205
|
`)}
|
|
1863
2206
|
}
|
|
1864
|
-
`;else
|
|
2207
|
+
`;else q=`
|
|
1865
2208
|
$fragment: <F extends (this: any, ...args: any[]) => any>(f: F) =>
|
|
1866
2209
|
f.bind({
|
|
1867
2210
|
collector: this,
|
|
@@ -1875,37 +2218,45 @@ export class SelectionWrapper<
|
|
|
1875
2218
|
) as SLWsFromSelection<
|
|
1876
2219
|
ReturnType<typeof make${D}Input>
|
|
1877
2220
|
>,
|
|
1878
|
-
`:""}
|
|
2221
|
+
`:""}
|
|
2222
|
+
$all: (opts?: any, collector = undefined) =>
|
|
2223
|
+
selectAll(
|
|
2224
|
+
make${D}Input.bind(this)() as any,
|
|
2225
|
+
"${Z}",
|
|
2226
|
+
opts as any,
|
|
2227
|
+
collector
|
|
2228
|
+
) as any
|
|
2229
|
+
`;let X=new Map,J=`
|
|
1879
2230
|
export function make${D}Input(this: any) ${this.typeMeta.isUnion?"":`: ReturnTypeFrom${D}`} {
|
|
1880
2231
|
return {
|
|
1881
|
-
${this.typeMeta.fields.map((
|
|
2232
|
+
${this.typeMeta.fields.map((H)=>[H,this.makeSelectionFunctionInputObjectValueForField(H,this.typeMeta.isInput?[]:[this.typeName])]).map(([H,W])=>{let U=`
|
|
1882
2233
|
$lazy: (
|
|
1883
|
-
${
|
|
1884
|
-
) => Promise<"T">`;return
|
|
1885
|
-
args: ${this.typeName}${
|
|
1886
|
-
) =>`:""}`,`${
|
|
2234
|
+
${H.hasArgs?`args: ${this.typeName}${H.name.slice(0,1).toUpperCase()}${H.name.slice(1)}Args`:""}
|
|
2235
|
+
) => Promise<"T">`;return X.set(H.name,[`${H.hasArgs?`(
|
|
2236
|
+
args: ${this.typeName}${H.name.slice(0,1).toUpperCase()}${H.name.slice(1)}Args
|
|
2237
|
+
) =>`:""}`,`${H.type.isScalar||H.type.isEnum?`SelectionWrapperImpl<"${H.name}", "${H.type.name.replaceAll("[","").replaceAll("]","").replaceAll("!","")}${H.type.isNonNull?"!":""}", ${H.type.isList}, {}, ${H.hasArgs?`${this.typeName}${H.name.slice(0,1).toUpperCase()}${H.name.slice(1)}Args`:"undefined"}>`:`ReturnType<
|
|
1887
2238
|
SLFN<
|
|
1888
2239
|
{},
|
|
1889
|
-
ReturnType<typeof make${super.originalTypeNameToTypescriptFriendlyName(
|
|
1890
|
-
"${super.originalTypeNameToTypescriptFriendlyName(
|
|
1891
|
-
"${super.originalTypeNameToTypescriptTypeNameWithoutModifiers(
|
|
1892
|
-
${
|
|
2240
|
+
ReturnType<typeof make${super.originalTypeNameToTypescriptFriendlyName(H.type.name)}SelectionInput>,
|
|
2241
|
+
"${super.originalTypeNameToTypescriptFriendlyName(H.type.name)}Selection",
|
|
2242
|
+
"${super.originalTypeNameToTypescriptTypeNameWithoutModifiers(H.type.name)}",
|
|
2243
|
+
${H.type.isList??0}
|
|
1893
2244
|
${P?`,
|
|
1894
2245
|
{
|
|
1895
|
-
${
|
|
2246
|
+
${U} ${this.authConfig?`& {
|
|
1896
2247
|
auth: (auth: FnOrPromisOrPrimitive) => Promise<"T">;
|
|
1897
2248
|
}`:""};
|
|
1898
|
-
${this.authConfig?`auth: (auth: FnOrPromisOrPrimitive) => Promise<"T"> & {${
|
|
2249
|
+
${this.authConfig?`auth: (auth: FnOrPromisOrPrimitive) => Promise<"T"> & {${U}}`:""}
|
|
1899
2250
|
},
|
|
1900
2251
|
"$lazy" ${this.authConfig?'| "auth"':""},
|
|
1901
2252
|
AS_PROMISE
|
|
1902
2253
|
${B?", 1":""}
|
|
1903
2254
|
`:""}
|
|
1904
2255
|
>
|
|
1905
|
-
>`}`]),`${
|
|
2256
|
+
>`}`]),`${W},`}).join(`
|
|
1906
2257
|
`)}
|
|
1907
2258
|
|
|
1908
|
-
${
|
|
2259
|
+
${q}
|
|
1909
2260
|
} as const;
|
|
1910
2261
|
};
|
|
1911
2262
|
export const ${D} = makeSLFN(
|
|
@@ -1914,13 +2265,13 @@ export class SelectionWrapper<
|
|
|
1914
2265
|
"${this.originalFullTypeName.replaceAll("[","").replaceAll("]","").replaceAll("!","")}",
|
|
1915
2266
|
${this.typeMeta.isList??0}
|
|
1916
2267
|
);
|
|
1917
|
-
`,
|
|
2268
|
+
`,Y=this.typeMeta.isUnion?"":`
|
|
1918
2269
|
type ReturnTypeFrom${D}RetTypes<AS_PROMISE = 0> = {
|
|
1919
|
-
${Array.from(
|
|
2270
|
+
${Array.from(X).map(([H,[W,U]])=>`${H}: ${U}`).join(`
|
|
1920
2271
|
`)}
|
|
1921
2272
|
}
|
|
1922
2273
|
type ReturnTypeFrom${D} = {
|
|
1923
|
-
${Array.from(
|
|
2274
|
+
${Array.from(X).map(([H,[W,U]])=>`${H}: ${W} ReturnTypeFrom${D}RetTypes["${H}"]`).join(`
|
|
1924
2275
|
`)}
|
|
1925
2276
|
} & {
|
|
1926
2277
|
$fragment: <F extends (this: any, ...args: any[]) => any>(
|
|
@@ -1931,8 +2282,9 @@ export class SelectionWrapper<
|
|
|
1931
2282
|
${F?`
|
|
1932
2283
|
$scalars: () => SLWsFromSelection<ReturnType<typeof ${`make${D}Input`}>>;
|
|
1933
2284
|
`:""}
|
|
1934
|
-
|
|
1935
|
-
|
|
2285
|
+
$all: selectAllFunc<AllNonFuncFieldsFromType<${Z}>, "${Z}">;
|
|
2286
|
+
};`;return this.collector.addSelectionFunction(this.typeMeta,`${Y}
|
|
2287
|
+
${J}
|
|
1936
2288
|
`),D}static makeRootOperationFunction(D,F){let{QueryTypeName:P,MutationTypeName:B,SubscriptionTypeName:Z}=D,q=[P,B,Z].filter(Boolean),X=[...D.types.values()].filter((Y)=>Y.isDirective?.locations.some((H)=>[C3.DirectiveLocation.FIELD,C3.DirectiveLocation.FRAGMENT_SPREAD,C3.DirectiveLocation.INLINE_FRAGMENT].includes(H))).map((Y)=>{return`"${Y.isDirective.name}": ${new m2(Y.name,D,{}).makeDirective()}`});return`
|
|
1937
2289
|
${X?.length?`export const $directives = {
|
|
1938
2290
|
${X.join(`,
|
|
@@ -2105,7 +2457,7 @@ export class SelectionWrapper<
|
|
|
2105
2457
|
typeof operation extends "${q[1]}"
|
|
2106
2458
|
? keyof ReturnTypeFrom${q[1]}Selection
|
|
2107
2459
|
: keyof ReturnTypeFrom${q[2]}Selection,`:`keyof ReturnTypeFrom${q[1]}Selection,`}`}
|
|
2108
|
-
"$fragment" | "$scalars"
|
|
2460
|
+
"$fragment" | "$scalars" | "$all"
|
|
2109
2461
|
>,
|
|
2110
2462
|
) => {
|
|
2111
2463
|
const root = new OperationSelectionCollector(
|
|
@@ -2118,7 +2470,7 @@ export class SelectionWrapper<
|
|
|
2118
2470
|
let fieldFn: ${q.map((Y)=>`
|
|
2119
2471
|
ReturnTypeFrom${Y}Selection[Exclude<
|
|
2120
2472
|
keyof ReturnTypeFrom${Y}Selection,
|
|
2121
|
-
"$fragment" | "$scalars"
|
|
2473
|
+
"$fragment" | "$scalars" | "$all"
|
|
2122
2474
|
>]`).join(" | ")};
|
|
2123
2475
|
|
|
2124
2476
|
${q.length>1?`if (operation === "${q[0]}") {`:""}
|
|
@@ -2126,7 +2478,7 @@ export class SelectionWrapper<
|
|
|
2126
2478
|
make${q[0]}SelectionInput.bind(rootRef)()[
|
|
2127
2479
|
field as Exclude<
|
|
2128
2480
|
keyof ReturnTypeFrom${q[0]}Selection,
|
|
2129
|
-
"$fragment" | "$scalars"
|
|
2481
|
+
"$fragment" | "$scalars" | "$all"
|
|
2130
2482
|
>
|
|
2131
2483
|
];
|
|
2132
2484
|
${q.length>1?`} else ${q.length>2?`if (operation === "${q[1]}")`:""}`:""}${q.length>1?`{
|
|
@@ -2134,7 +2486,7 @@ export class SelectionWrapper<
|
|
|
2134
2486
|
make${q[1]}SelectionInput.bind(rootRef)()[
|
|
2135
2487
|
field as Exclude<
|
|
2136
2488
|
keyof ReturnTypeFrom${q[1]}Selection,
|
|
2137
|
-
"$fragment" | "$scalars"
|
|
2489
|
+
"$fragment" | "$scalars" | "$all"
|
|
2138
2490
|
>
|
|
2139
2491
|
];
|
|
2140
2492
|
}`:""}
|
|
@@ -2143,7 +2495,7 @@ export class SelectionWrapper<
|
|
|
2143
2495
|
make${q[2]}SelectionInput.bind(rootRef)()[
|
|
2144
2496
|
field as Exclude<
|
|
2145
2497
|
keyof ReturnTypeFrom${q[2]}Selection,
|
|
2146
|
-
"$fragment" | "$scalars"
|
|
2498
|
+
"$fragment" | "$scalars" | "$all"
|
|
2147
2499
|
>
|
|
2148
2500
|
];
|
|
2149
2501
|
}`:""}
|
|
@@ -2337,7 +2689,7 @@ export class SelectionWrapper<
|
|
|
2337
2689
|
target,
|
|
2338
2690
|
op: Exclude<
|
|
2339
2691
|
keyof ReturnTypeFrom${Y}Selection,
|
|
2340
|
-
"$fragment" | "$scalars"
|
|
2692
|
+
"$fragment" | "$scalars" | "$all"
|
|
2341
2693
|
>,
|
|
2342
2694
|
) {
|
|
2343
2695
|
return _makeOperationShortcut("${Y}", op);
|
|
@@ -2352,10 +2704,10 @@ export class SelectionWrapper<
|
|
|
2352
2704
|
export default __client__ as typeof __client__ & {
|
|
2353
2705
|
init: typeof __init__;
|
|
2354
2706
|
} & {
|
|
2355
|
-
${q.map((Y)=>({op:Y,wrapForAsyncIter:(H)=>Y===Z?`AsyncIterable<${H}
|
|
2707
|
+
${q.map((Y)=>({op:Y,wrapForAsyncIter:(H)=>Y===Z?`AsyncIterable<${H}>`:`Promise<${H}>`})).map(({op:Y,wrapForAsyncIter:H})=>`${Y?.toLowerCase()}: {
|
|
2356
2708
|
[field in Exclude<
|
|
2357
2709
|
keyof ReturnType<typeof make${Y}SelectionInput>,
|
|
2358
|
-
"$fragment" | "$scalars"
|
|
2710
|
+
"$fragment" | "$scalars" | "$all"
|
|
2359
2711
|
>]: ReturnType<
|
|
2360
2712
|
typeof make${Y}SelectionInput
|
|
2361
2713
|
>[field] extends SelectionWrapperImpl<
|
|
@@ -4010,7 +4362,7 @@ export class SelectionWrapper<
|
|
|
4010
4362
|
export default __client__ as typeof __client__ & {
|
|
4011
4363
|
init: typeof __init__;
|
|
4012
4364
|
};
|
|
4013
|
-
`}}var k1={};$U(k1,{Generator:()=>EU});var HT=(D,F,P,B)=>{let q=F?.includes("@typedef")?F?.match(/@typedef\s*{(.*)}/)?.[1]:void 0,X={name:D,description:F,isScalar:!0,scalarTSType:q??P,isEnum:!1,isObject:!1,isUnion:!1,isList:0,isNonNull:!1,fields:[],possibleTypes:[],inputFields:[],isInput:!1,enumValues:[],isInterface:!1,isQuery:!1,isMutation:!1,isSubscription:!1};X.ofType=X,B.addType(X),B.addCustomScalar(X);let J={...X,name:`${X.name}!`,isNonNull:!0};return J.ofType=J,B.addType(J),B.addCustomScalar(J),X},UT=(D,F,P)=>{let B={types:[],directives:[],query:[],mutation:[],subscription:[]};for(let Y in D.getTypeMap()){if(!F.includeSchemaDefinition){if(["__Schema","__Type","__TypeKind","__Field","__InputValue","__EnumValue","__Directive"].includes(Y))continue}let H=D.getTypeMap()[Y];if(H instanceof MD.GraphQLScalarType){if(["String","Int","Float","Boolean","ID","Date","DateTime","DateTimeISO","Time","JSON"].includes(Y))continue;B.types.push(HT(Y,H.description??void 0,"
|
|
4365
|
+
`}}var k1={};$U(k1,{Generator:()=>EU});var HT=(D,F,P,B)=>{let q=F?.includes("@typedef")?F?.match(/@typedef\s*{(.*)}/)?.[1]:void 0,X={name:D,description:F,isScalar:!0,scalarTSType:q??P,isEnum:!1,isObject:!1,isUnion:!1,isList:0,isNonNull:!1,fields:[],possibleTypes:[],inputFields:[],isInput:!1,enumValues:[],isInterface:!1,isQuery:!1,isMutation:!1,isSubscription:!1};X.ofType=X,B.addType(X),B.addCustomScalar(X);let J={...X,name:`${X.name}!`,isNonNull:!0};return J.ofType=J,B.addType(J),B.addCustomScalar(J),X},UT=(D,F,P)=>{let B={types:[],directives:[],query:[],mutation:[],subscription:[]};for(let Y in D.getTypeMap()){if(!F.includeSchemaDefinition){if(["__Schema","__Type","__TypeKind","__Field","__InputValue","__EnumValue","__Directive"].includes(Y))continue}let H=D.getTypeMap()[Y];if(H instanceof MD.GraphQLScalarType){if(["String","Int","Float","Boolean","ID","Date","DateTime","DateTimeISO","Time","JSON"].includes(Y))continue;B.types.push(HT(Y,H.description??void 0,"Record<string | number | symbol, unknown>",P))}}let Z=P.customScalars.size>0,q=D.getQueryType();if(q)for(let Y of Object.values(q.getFields()))B.query.push(T7(D,Y,"query",F,P));let X=D.getMutationType();if(X)for(let Y of Object.values(X.getFields()))B.mutation.push(T7(D,Y,"mutation",F,P));let J=D.getSubscriptionType();if(J)for(let Y of Object.values(J.getFields()))B.subscription.push(T7(D,Y,"subscription",F,P));for(let Y in D.getTypeMap()){if(!F.includeSchemaDefinition){if(["__Schema","__Type","__TypeKind","__Field","__InputValue","__EnumValue","__Directive"].includes(Y))continue}let H=D.getTypeMap()[Y];if(MD.isObjectType(H)||Z&&MD.isInputObjectType(H)||MD.isInterfaceType(H))B.types.push(x1(D,H,F,P))}for(let Y of D.getDirectives())B.directives.push(WT(D,Y,F,P));return B},T7=(D,F,P,B,Z)=>{let q={name:F.name,description:F.description??void 0,operation:P,args:[],type:x1(D,F.type,B,Z)};for(let X in F.args){let J=F.args[X];q.args.push(w3(D,J,B,Z))}return q},w3=(D,F,P,B)=>{return{name:F.name,hasArgs:!1,args:[],description:F.description??void 0,type:x1(D,F.type,P,B)}},x1=(D,F,P,B)=>{let Z=MD.getNamedType(F),q={name:F.toString(),description:Z.description??void 0,isList:F.toString().split("[").length-1,isNonNull:F.toString().endsWith("!"),isScalar:Z instanceof MD.GraphQLScalarType,isEnum:Z instanceof MD.GraphQLEnumType,isInput:Z instanceof MD.GraphQLInputObjectType,isInterface:Z instanceof MD.GraphQLInterfaceType,isObject:Z instanceof MD.GraphQLObjectType,isUnion:Z instanceof MD.GraphQLUnionType,isQuery:!1,isMutation:!1,isSubscription:!1,fields:[],possibleTypes:[],enumValues:[],inputFields:[]};if(B.hasType(q.name))return B.getType(q.name);else B.addType(q);if(q.ofType=q,q.isEnum)for(let X of Z.getValues())q.enumValues.push({name:X.name,description:X.description??void 0});if(q.isInput){let X=Z.getFields();for(let J in X)q.inputFields.push(w3(D,X[J],P,B))}if(q.isInterface){let X=Z.getFields();for(let J in X)q.fields.push(IU(D,X[J],P,B))}if(q.isObject){let X=Z.getFields();for(let J in X)q.fields.push(IU(D,X[J],P,B))}if(q.isUnion)for(let X of Z.getTypes())q.possibleTypes.push(x1(D,X,P,B));if(Z instanceof MD.GraphQLObjectType){if(Z.name==="Query")q.isQuery=!0;else if(Z.name==="Mutation")q.isMutation=!0;else if(Z.name==="Subscription")q.isSubscription=!0}return B.addType(q),q},IU=(D,F,P,B)=>{let Z={name:F.name,description:F.description??void 0,hasArgs:Object.keys(F.args).length>0,args:[],type:x1(D,F.type,P,B)};for(let q in F.args){let X=F.args[q];Z.args.push(w3(D,X,P,B))}return Z},WT=(D,F,P,B)=>{let Z={name:F.name,description:F.description??void 0,locations:F.locations,args:[]};for(let q in F.args){let X=F.args[q];Z.args.push(w3(D,X,P,B))}return B.addType({name:`Directive_${F.name}`,description:F.description??void 0,isList:0,isNonNull:!1,isScalar:!1,isEnum:!1,isInput:!1,isInterface:!1,isObject:!1,isUnion:!1,isQuery:!1,isMutation:!1,isSubscription:!1,fields:[],possibleTypes:[],enumValues:[],inputFields:[],isDirective:Z}),Z};class KU{QueryTypeName;MutationTypeName;SubscriptionTypeName;OperationTypeNames;constructor(D,F,P){this.QueryTypeName=D,this.MutationTypeName=F,this.SubscriptionTypeName=P,this.OperationTypeNames=[D,F,P].filter((B)=>B)}_types=new Map;get types(){return this._types}addType(D){this._types.set(D.name,D)}hasType(D){return this._types.has(D)}getType(D){return this._types.get(D)}_customScalars=new Map;get customScalars(){return this._customScalars}addCustomScalar(D){this._customScalars.set(D.name,D)}hasCustomScalar(D){return this._customScalars.has(D)}getCustomScalar(D){return this._customScalars.get(D)}removeCustomScalar(D){this._customScalars.delete(D)}_enumsTypes=new Map;get enumsTypes(){return this._enumsTypes}addEnumType(D,F){this._enumsTypes.set(D,F)}hasEnumType(D){if(!D)return!1;return this._enumsTypes.has(D)}getEnumType(D){return this._enumsTypes.get(D)}_argumentTypes=new Map;get argumentTypes(){return this._argumentTypes}addArgumentType(D,F){this._argumentTypes.set(D,F)}hasArgumentType(D){return this._argumentTypes.has(D)}getArgumentType(D){return this._argumentTypes.get(D)}_argumentMeta=new Map;get argumentMeta(){return this._argumentMeta}addArgumentMeta(D,F){this._argumentMeta.set(D,F)}hasArgumentMeta(D){return this._argumentMeta.has(D)}getArgumentMeta(D){return this._argumentMeta.get(D)}_directivesFunctions=new Map;get directivesFunctions(){return this._directivesFunctions}addDirectiveFunction(D,F){this._directivesFunctions.set(D,F)}hasDirectiveFunction(D){return this._directivesFunctions.has(D)}getDirectiveFunction(D){return this._directivesFunctions.get(D)}_selectionTypes=new Map;get selectionTypes(){return this._selectionTypes}addSelectionType(D,F){this._selectionTypes.set(D,F)}hasSelectionType(D){if(!D)return!1;return this._selectionTypes.has(D)}getSelectionType(D){return this._selectionTypes.get(D)}_selectionFunctions=new Map;get selectionFunctions(){return this._selectionFunctions}addSelectionFunction(D,F){this._selectionFunctions.set(D,F)}hasSelectionFunction(D){if(!D)return!1;return this._selectionFunctions.has(D)}getSelectionFunction(D){return this._selectionFunctions.get(D)}}class EU{Codegen;constructor(D){this.Codegen=D}async generate({schema:D,options:F,authConfig:P}){let B=D.getQueryType()?.name,Z=D.getMutationType()?.name,q=D.getSubscriptionType()?.name,X=new KU(B,Z,q);UT(D,F,X);for(let[Y,H]of X.types.entries()){if(!H.isEnum)continue;new this.Codegen(Y,X,F,P).makeEnumType()}for(let[Y,H]of X.types.entries()){if(!H.isInput)continue;new this.Codegen(Y,X,F,P).makeSelectionType()}for(let[Y,H]of X.types.entries()){if(!H.isDirective?.locations.some((W)=>[L3.DirectiveLocation.FIELD,L3.DirectiveLocation.FRAGMENT_SPREAD,L3.DirectiveLocation.INLINE_FRAGMENT].includes(W)))continue;new this.Codegen(Y,X,F,P).makeDirective()}for(let[Y,H]of X.types.entries()){if(H.isScalar||H.isInput||H.isEnum||H.isDirective)continue;new this.Codegen(Y,X,F,P).makeSelectionType(),new this.Codegen(Y,X,F,P).makeSelectionFunction()}return[this.Codegen.FieldValueWrapperType,this.Codegen.HelperTypes(Array.from(X.customScalars.values())),this.Codegen.HelperFunctions,...[...X.enumsTypes.entries()].map(([Y,H])=>H).filter((Y,H,W)=>W.indexOf(Y)===H),...[...X.argumentTypes.entries()].map(([Y,H])=>H).filter((Y,H,W)=>W.indexOf(Y)===H),...[...X.argumentMeta.entries()].map(([Y,H])=>H).filter((Y,H,W)=>W.indexOf(Y)===H),...[...X.selectionTypes.entries()].filter(([Y])=>Y.isInput||Y.isObject).map(([Y,H])=>H).filter((Y,H,W)=>W.indexOf(Y)===H),this.Codegen.EnumTypesMapped(X),...[...X.selectionFunctions.entries()].filter(([Y])=>!Y.isScalar&&!Y.isEnum&&!Y.isInput).map(([Y,H])=>H),...[...X.directivesFunctions.entries()].map(([Y,H])=>H),this.Codegen.makeRootOperationFunction(X,P)].join(`
|
|
4014
4366
|
`)}}var f1={};$U(f1,{Generator:()=>CU});var SD=(D,F="$")=>{let P="";for(let B of D.filter(Boolean))P+=B.charAt(0).toUpperCase()+B.slice(1)+F;return P.slice(0,P.length-F.length).replaceAll("/","_").replaceAll("-","_").replaceAll(".","_")},OT=(D,F,P)=>{let B={types:[],operations:[],customScalars:[]};for(let[Z,q]of Object.entries(D?.components?.schemas??{}))B.types.push(lD(D,Z,q,"schemas",{isNonNull:!1},P));for(let[Z,q]of Object.entries(D?.paths??{})){if("$ref"in q)continue;for(let[X,J]of Object.entries(q)){if(!J)continue;if("$ref"in J){console.warn(`TODO: Handle $ref in methodValue for ${Z}`);continue}let Y=GT(D,Z,X,J,F,P);if(!Y)continue;B.operations.push(Y)}}return B},N7=(D,F,P,B)=>{let Z={name:D,description:F,isScalar:!0,scalarTSType:P,isEnum:!1,isObject:!1,isUnion:!1,isList:0,isNonNull:!1,fields:[],possibleTypes:[],inputFields:[],isInput:!1,enumValues:[]};return Z.ofType=Z,B.addType(Z),B.addCustomScalar(Z),Z},u7=(D,F)=>{let P=F?.isInput??D.isInput,B=F?.isNonNull??D.isNonNull;return`${D.name.slice(0,P&&B?-1:void 0)}${P?`${B?"Input!":"Input"}`:""}`.replaceAll("-","_")},_7=(D,F)=>{if(D.isInput||D.isScalar)return D;let P=u7(D,{isInput:!0}),B={...D,name:P,isInput:!0,isObject:!1,inputFields:D.fields.map((Z)=>({...Z,location:"$",type:_7(Z.type,F)})),fields:[],possibleTypes:D.possibleTypes.map((Z)=>_7(Z,F))};return B.ofType=B,F.addType(B),B},lD=(D,F,P,B,Z,q)=>{if("ofType"in P)return P;if("$ref"in P){let H=P.$ref.split("/");H.shift();let W=H.shift(),U=H.shift(),O=H.shift(),z=D[W]?.[U]?.[O];if(z)return lD(D,SD([Z.operationResponseType?"":F,O]),z,U,{isNonNull:Z.isNonNull},q);throw new Error(`Reference ${P.$ref} not found`)}if("schema"in P)return lD(D,F,P.schema,"schemas",{isNonNull:Z.isNonNull,operationResponseType:Z.operationResponseType},q);let X=P;if("properties"in X&&!("type"in X))X.type="object";let J={name:Z.operationResponseType?F:Z.isNonNull?`${F}!`:F,description:X.description,isObject:"type"in X&&(X.type==="object"||JSON.stringify(X.type)===JSON.stringify(["object","null"])),fields:[],isUnion:!!X.oneOf||!!X.anyOf||!!X.allOf,possibleTypes:[],isList:0,isNonNull:Z.isNonNull,isScalar:!1,scalarTSType:void 0,isEnum:{schemas:!!X.enum,parameters:!1,responses:!1,requestBodies:!1,headers:!1}[B],enumValues:[],isInput:B==="parameters"||B==="headers"||B==="requestBodies",inputFields:[],ofType:void 0};J.isScalar=!J.isObject&&!J.isUnion&&!J.isEnum&&!J.isInput;let Y=u7(J);if(q.hasType(Y))return q.getType(Y);else J.name=Y,q.addType(J);if(J.ofType=J,J.isEnum){let H=X;for(let W of[...H.enum??[]])J.enumValues.push({name:String(W),description:X.description,type:lD(D,F,X,B,{isNonNull:Z.isNonNull},q)})}if(J.isInput){let H=X;if("content"in H){let W=H;for(let[U,O]of Object.entries(W.content??{})){q.removeType(Y);let z=_7(lD(D,F,O,B,{isNonNull:W.required??!1},q),q);if(z.fields.length===1&&!!z.fields[0].type.scalarTSType)return q.removeType(Y),J=z.fields[0].type,q.addType(J),J;else return q.removeType(Y),J=z,q.addType(J),J}}if("schema"in H&&"in"in H){let W=H;if(W.schema)J.inputFields.push(M8(D,W.name,W.schema,B,W.in,{isNonNull:W.required??!1},q));else J.inputFields.push(M8(D,W.name,lD(D,SD([F,"Input",W.name]),W.content["application/json"],B,{isNonNull:W.required??!1},q),B,W.in,{isNonNull:W.required??!1},q))}if("schema"in H&&!("in"in H)){let W=H;if(W.schema)J.inputFields.push(M8(D,SD([F,"Header"]),W.schema,B,"header",{isNonNull:W.required??!1},q));else J.inputFields.push(M8(D,SD([F,"Header"]),lD(D,SD([F,"Input","Header"]),W.content["application/json"],B,{isNonNull:W.required??!1},q),B,"header",{isNonNull:W.required??!1},q))}}if(J.isObject){let H=X,W=H.properties;for(let[z,I]of Object.entries(W??{})){let R="$ref"in I;q.removeType(SD([F,z]));let $=lD(D,SD([F,z]),I,B,{isNonNull:H.required?.includes(z)??!1},q),E=zT(D,z,$,{isNonNull:H.required?.includes(z)??!1},q);J.fields.push(E)}let U,O=H.additionalProperties;if(O===!0||JSON.stringify(O)===JSON.stringify({}))U=N7(SD([F,"AdditionalProperties"]),"Additional properties","Record<string, any>",q),J.fields.push({name:SD([F,"Any"]),description:"Additional properties",type:U});else if(typeof O==="object")if("type"in O&&O.type==="string")U=N7(SD([F,"AdditionalProperties"]),"Additional properties","Record<string, string>",q),J.fields.push({name:SD([F,"AdditionalProperties"]),description:"Additional properties",type:U});else{let z="$ref"in O,I=lD(D,z?"":SD([F,"AdditionalProperties"]),O,B,{isNonNull:!1},q),R=I.name.replaceAll("!","").replaceAll("[","").replaceAll("]","");R={Int:"number",Float:"number",String:"string",Boolean:"boolean"}[R]??R;let $=R+(I.isList?Array.from({length:I.isList}).map((E)=>"[]").join(""):"");if(I.isScalar&&I.scalarTSType)U=I,J.fields.push({name:SD([F,R]),description:"Additional properties",type:U});else U=N7(SD([F,R]),"Additional properties",`Record<string, ${$}>`,q),J.fields.push({name:SD([F,R]),description:"Additional properties",type:U})}if(U&&J.fields.length===1)return q.removeType(Y),q.addType(U),U}if(J.isUnion){let H=0;for(let W of[...X.oneOf??[],...X.anyOf??[],...X.allOf??[]]){H++,q.removeType(Y);let U="$ref"in W;J.possibleTypes.push(lD(D,U?"":`${F}Subtype${H}`,W,B,{isNonNull:Z.isNonNull},q))}if(J.possibleTypes.length===1){let W=J.possibleTypes[0];J={...W,isList:J.isList,ofType:W,name:J.name}}}if(J.isScalar){let H=X;if(H.type==="array"){let W="$ref"in X.items;if(!W||X.items.$ref!==`#/components/${B}/${Y}`)q.removeType(Y);J.isList++;let U=lD(D,W?"":F,X.items,"schemas",{isNonNull:Z.isNonNull},q),O=J.isList+=U?.isList??0;J={...U,isList:O,name:`[${U.name}]`},J.ofType=J}else if(typeof H.type==="string"){q.removeType(Y),J.name=SD([H.type]);let W={double:"Float",float:"Float",integer:"Int",long:"Int",int32:"Int",int64:"Int",number:"Float",byte:"Int"};if(H.format&&H.format.toLowerCase()in W)J.name=W[H.format.toLowerCase()]}else if(Array.isArray(H))q.removeType(Y),J.name=SD(H);if(Z.isNonNull&&!J.name.endsWith("!"))q.removeType(Y),J.name=`${J.name}!`;J.name=u7(J)}return q.addType(J),J},M8=(D,F,P,B,Z,q,X)=>{return{name:F,description:P.description,location:Z,type:lD(D,F,P,B,q,X)}},zT=(D,F,P,B,Z)=>{return{name:F,description:P.description,type:lD(D,F,P,"schemas",B,Z)}},QT={get:"Get",post:"Create",put:"Update",delete:"Delete",patch:"Patch",options:"Options",head:"Head",trace:"Trace"},GT=(D,F,P,B,Z,q)=>{if(!B.responses){console.warn("Operation has no responses!");return}let X=Object.entries(B.responses).filter(([U,O])=>U.toString().startsWith("2")).sort(([U,O],[z,I])=>+U-+z),J=X.length>0?X[0][1]:B.responses.default,Y=Object.entries(B.responses).filter(([U,O])=>U.toString().startsWith("4")||U.toString().startsWith("5"));if(!J){console.warn("Operation has no success response!",B);return}let H=B.operationId?.replaceAll(".","_").replaceAll("/","_").replaceAll("-","_")??SD([QT[P],...F.split("/").flatMap((U)=>[U.includes("{")?"By":"",U.replace(/{([^}]+)}/g,"$1")].filter((O)=>O.length>0))],""),W={name:H,description:B.description,path:F,method:P,args:[],type:lD(D,H,"content"in J?J.content["application/json"]??Object.entries(J.content).find(([U,O])=>O)?.[1]:J,"responses",{isNonNull:!1,operationResponseType:!0},q)};for(let U of B.parameters??[]){let O="$ref"in U?U.$ref.split("/").pop():U.name,z="in"in U?U.in:U.$ref.split("/").at(-2),I={parameters:"query",requestBodies:"body",headers:"header",cookie:"cookie",path:"path",query:"query",header:"header"}[z];W.args.push(M8(D,O,U,"parameters",I,{isNonNull:"$ref"in U?!1:U.required??!1},q))}if(B.requestBody){let U=B.requestBody,O=M8(D,`${H}RequestBody`,U,"requestBodies","body",{isNonNull:U.required??!1},q);O.name="$",W.args.push(O)}return W};class AU{constructor(){}_types=new Map;get types(){return this._types}addType(D){this._types.set(D.name,D)}hasType(D){return this._types.has(D)}getType(D){return this._types.get(D)}removeType(D){this._types.delete(D)}_customScalars=new Map;get customScalars(){return this._customScalars}addCustomScalar(D){this._customScalars.set(D.name,D)}hasCustomScalar(D){return this._customScalars.has(D)}getCustomScalar(D){return this._customScalars.get(D)}removeCustomScalar(D){this._customScalars.delete(D)}_enumsTypes=new Map;get enumsTypes(){return this._enumsTypes}addEnumType(D,F){this._enumsTypes.set(D,F)}hasEnumType(D){if(!D)return!1;return this._enumsTypes.has(D)}hasEnumTypeName(D){for(let[F,P]of this._enumsTypes.entries())if(F.name===D)return!0;return!1}getEnumType(D){return this._enumsTypes.get(D)}getEnumTypeByName(D){for(let[F,P]of this._enumsTypes.entries())if(F.name===D)return P;return""}_argumentTypes=new Map;get argumentTypes(){return this._argumentTypes}addArgumentType(D,F){this._argumentTypes.set(D,F)}hasArgumentType(D){return this._argumentTypes.has(D)}getArgumentType(D){return this._argumentTypes.get(D)}_argumentMeta=new Map;get argumentMeta(){return this._argumentMeta}addArgumentMeta(D,F){this._argumentMeta.set(D,F)}hasArgumentMeta(D){return this._argumentMeta.has(D)}getArgumentMeta(D){return this._argumentMeta.get(D)}_selectionTypes=new Map;get selectionTypes(){return this._selectionTypes}addSelectionType(D,F){this._selectionTypes.set(D,F)}hasSelectionType(D){if(!D)return!1;return this._selectionTypes.has(D)}getSelectionType(D){return this._selectionTypes.get(D)}_selectionFunctions=new Map;get selectionFunctions(){return this._selectionFunctions}addSelectionFunction(D,F){this._selectionFunctions.set(D,F)}hasSelectionFunction(D){if(!D)return!1;return this._selectionFunctions.has(D)}getSelectionFunction(D){return this._selectionFunctions.get(D)}}class CU{Codegen;constructor(D){this.Codegen=D}async generate({schema:D,options:F,authConfig:P}){let B=new AU,Z=OT(D,F,B);for(let[J,Y]of B.types.entries()){if(!Y.isEnum)continue;new this.Codegen(J,B,F).makeEnumType()}for(let[J,Y]of B.types.entries()){if(!Y.isInput)continue;new this.Codegen(J,B,F).makeSelectionType()}for(let[J,Y]of B.types.entries()){if(Y.isScalar||Y.isInput||Y.isEnum)continue;new this.Codegen(J,B,F).makeSelectionType(),new this.Codegen(J,B,F).makeSelectionFunction()}let q=this.Codegen.makeRootOperationFunction(Z.operations,B,F,P);return[this.Codegen.FieldValueWrapperType,this.Codegen.HelperTypes(Array.from(B.customScalars.values())),this.Codegen.HelperFunctions,...[...B.enumsTypes.entries()].map(([J,Y])=>Y).filter((J,Y,H)=>H.indexOf(J)===Y),...[...B.argumentTypes.entries()].map(([J,Y])=>Y).filter((J,Y,H)=>H.indexOf(J)===Y),...[...B.argumentMeta.entries()].map(([J,Y])=>Y).filter((J,Y,H)=>H.indexOf(J)===Y),...[...B.selectionTypes.entries()].filter(([J])=>!J.isScalar&&!J.isEnum&&!(J.isScalar&&J.isUnion)).map(([J,Y])=>Y).filter((J,Y,H)=>H.indexOf(J)===Y),this.Codegen.EnumTypesMapped(B),this.Codegen.UnionTypesMapped(B),...[...B.selectionFunctions.entries()].filter(([J])=>!J.isScalar&&!J.isEnum&&!J.isInput&&!(J.isScalar&&J.isUnion)).map(([J,Y])=>Y).filter((J)=>!J.startsWith("new SelectionWrapper")).filter((J,Y,H)=>H.indexOf(J)===Y),q].join(`
|
|
4015
4367
|
`)}}var X2={GraphQL:{default:m2},OpenAPI:{default:q2}};import gO from"fs";import r1 from"fs";import AF from"path";var K8=(D)=>{process.stdout.write("\x1Bc"),process.stdout.write(`
|
|
4016
4368
|
_____ _
|