@samarium.sdk/new 0.22.1 → 0.23.0
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 +749 -369
- 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.0",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 = {};
|
|
@@ -937,6 +937,7 @@ export const SLW_OP_RESULT_DATA_OVERRIDE = Symbol(
|
|
|
937
937
|
export const SLW_RECREATE_VALUE_CALLBACK = Symbol(
|
|
938
938
|
"SLW_RECREATE_VALUE_CALLBACK",
|
|
939
939
|
);
|
|
940
|
+
export const SLW_SETTER_DATA_OVERRIDE = Symbol("SLW_SETTER_DATA_OVERRIDE");
|
|
940
941
|
|
|
941
942
|
export const SLW_CLONE = Symbol("SLW_CLONE");
|
|
942
943
|
|
|
@@ -957,6 +958,7 @@ export class SelectionWrapperImpl<
|
|
|
957
958
|
overrides: {
|
|
958
959
|
SLW_OP_PATH?: string;
|
|
959
960
|
OP_RESULT_DATA?: any;
|
|
961
|
+
SLW_SETTER_DATA_OVERRIDE?: any;
|
|
960
962
|
} = {},
|
|
961
963
|
) {
|
|
962
964
|
const slw = new SelectionWrapper(
|
|
@@ -975,6 +977,9 @@ export class SelectionWrapperImpl<
|
|
|
975
977
|
slw[SLW_IS_FRAGMENT] = this[SLW_IS_FRAGMENT];
|
|
976
978
|
slw[SLW_PARENT_SLW] = this[SLW_PARENT_SLW];
|
|
977
979
|
slw[SLW_OP_PATH] = overrides.SLW_OP_PATH ?? this[SLW_OP_PATH];
|
|
980
|
+
slw[SLW_SETTER_DATA_OVERRIDE] =
|
|
981
|
+
overrides.SLW_SETTER_DATA_OVERRIDE ??
|
|
982
|
+
this[SLW_SETTER_DATA_OVERRIDE];
|
|
978
983
|
|
|
979
984
|
if (overrides.OP_RESULT_DATA) {
|
|
980
985
|
slw[SLW_OP_RESULT_DATA_OVERRIDE] = overrides.OP_RESULT_DATA;
|
|
@@ -1009,6 +1014,7 @@ export class SelectionWrapperImpl<
|
|
|
1009
1014
|
[SLW_RECREATE_VALUE_CALLBACK]?: () => valueT;
|
|
1010
1015
|
|
|
1011
1016
|
[SLW_OP_RESULT_DATA_OVERRIDE]?: any;
|
|
1017
|
+
[SLW_SETTER_DATA_OVERRIDE]?: any;
|
|
1012
1018
|
|
|
1013
1019
|
constructor(
|
|
1014
1020
|
fieldName?: fieldName,
|
|
@@ -1182,375 +1188,458 @@ export class SelectionWrapper<
|
|
|
1182
1188
|
argsMeta,
|
|
1183
1189
|
reCreateValueCallback,
|
|
1184
1190
|
),
|
|
1185
|
-
{
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
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],
|
|
1230
|
+
);
|
|
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,
|
|
1211
1274
|
},
|
|
1212
|
-
|
|
1275
|
+
receiver,
|
|
1276
|
+
);
|
|
1277
|
+
},
|
|
1278
|
+
get: (target, prop) => {
|
|
1279
|
+
if (
|
|
1280
|
+
target[SLW_SETTER_DATA_OVERRIDE] &&
|
|
1281
|
+
target[SLW_SETTER_DATA_OVERRIDE][prop]
|
|
1213
1282
|
) {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
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
|
+
),
|
|
1226
1313
|
),
|
|
1227
|
-
|
|
1228
|
-
};
|
|
1314
|
+
};
|
|
1229
1315
|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
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,
|
|
1237
1331
|
newThisCollector,
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
that[SLW_ARGS_META],
|
|
1254
|
-
);
|
|
1255
|
-
Object.keys(r!).forEach(
|
|
1256
|
-
(key) =>
|
|
1257
|
-
(newThat as valueT)[key as keyof valueT],
|
|
1258
|
-
);
|
|
1259
|
-
|
|
1260
|
-
newThat[SLW_IS_ROOT_TYPE] = that[SLW_IS_ROOT_TYPE];
|
|
1261
|
-
newThat[SLW_IS_ON_TYPE_FRAGMENT] =
|
|
1262
|
-
that[SLW_IS_ON_TYPE_FRAGMENT];
|
|
1263
|
-
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
|
+
);
|
|
1264
1347
|
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
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;
|
|
1274
1364
|
|
|
1275
|
-
|
|
1365
|
+
newThat[SLW_OP_PATH] = that[SLW_OP_PATH];
|
|
1276
1366
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1367
|
+
newRootOpCollectorRef.ref.registerSelection(
|
|
1368
|
+
newThat[SLW_FIELD_NAME]!,
|
|
1369
|
+
newThat,
|
|
1370
|
+
);
|
|
1281
1371
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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
|
+
},
|
|
1300
1391
|
},
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
|
|
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
|
+
},
|
|
1319
1410
|
},
|
|
1320
|
-
|
|
1321
|
-
|
|
1411
|
+
);
|
|
1412
|
+
}
|
|
1413
|
+
target[SLW_LAZY_FLAG] = true;
|
|
1414
|
+
lazy[SLW_LAZY_FLAG] = true;
|
|
1415
|
+
return lazy;
|
|
1322
1416
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
}
|
|
1365
|
-
if (prop === "then") {
|
|
1366
|
-
return this;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
let slw_value = target[SLW_VALUE] as
|
|
1370
|
-
| Record<string, any>
|
|
1371
|
-
| undefined;
|
|
1372
|
-
|
|
1373
|
-
if (target[ROOT_OP_COLLECTOR]?.ref.isExecuted) {
|
|
1374
|
-
const getResultDataForTarget = (
|
|
1375
|
-
t: SelectionWrapperImpl<
|
|
1376
|
-
fieldName,
|
|
1377
|
-
typeNamePure,
|
|
1378
|
-
typeArrDepth,
|
|
1379
|
-
valueT,
|
|
1380
|
-
argsT
|
|
1381
|
-
>,
|
|
1382
|
-
overrideOpPath?: string,
|
|
1383
|
-
): valueT | undefined => {
|
|
1384
|
-
const data = t[
|
|
1385
|
-
ROOT_OP_COLLECTOR
|
|
1386
|
-
]!.ref.getOperationResultPath<valueT>(
|
|
1387
|
-
(
|
|
1388
|
-
(overrideOpPath ?? t[SLW_OP_PATH])?.split(
|
|
1389
|
-
".",
|
|
1390
|
-
) ?? []
|
|
1391
|
-
).map((p) => (!isNaN(+p) ? +p : p)),
|
|
1392
|
-
t[SLW_FIELD_TYPENAME],
|
|
1393
|
-
t[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1394
|
-
);
|
|
1395
|
-
return data;
|
|
1396
|
-
};
|
|
1397
|
-
|
|
1398
|
-
if (prop === Symbol.asyncIterator) {
|
|
1399
|
-
const asyncGenRootPath =
|
|
1400
|
-
target[SLW_OP_PATH]?.split(".")?.[0];
|
|
1401
|
-
const asyncGen = getResultDataForTarget(
|
|
1402
|
-
target,
|
|
1403
|
-
asyncGenRootPath,
|
|
1404
|
-
) as AsyncGenerator<valueT, any, any>;
|
|
1405
|
-
|
|
1406
|
-
return function () {
|
|
1407
|
-
return {
|
|
1408
|
-
next() {
|
|
1409
|
-
return asyncGen.next().then((val) => {
|
|
1410
|
-
return {
|
|
1411
|
-
done: val.done,
|
|
1412
|
-
value: target[SLW_CLONE]({
|
|
1413
|
-
SLW_OP_PATH:
|
|
1414
|
-
asyncGenRootPath,
|
|
1415
|
-
OP_RESULT_DATA: val.value,
|
|
1416
|
-
}),
|
|
1417
|
-
};
|
|
1418
|
-
});
|
|
1419
|
-
},
|
|
1420
|
-
};
|
|
1421
|
-
};
|
|
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;
|
|
1422
1458
|
}
|
|
1423
1459
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
if (!isNaN(+String(prop))) {
|
|
1428
|
-
const elm = target[SLW_CLONE]({
|
|
1429
|
-
SLW_OP_PATH:
|
|
1430
|
-
target[SLW_OP_PATH] +
|
|
1431
|
-
"." +
|
|
1432
|
-
String(prop),
|
|
1433
|
-
OP_RESULT_DATA:
|
|
1434
|
-
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1435
|
-
});
|
|
1436
|
-
return elm;
|
|
1437
|
-
}
|
|
1460
|
+
let slw_value = target[SLW_VALUE] as
|
|
1461
|
+
| Record<string, any>
|
|
1462
|
+
| undefined;
|
|
1438
1463
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
+
}
|
|
1442
1495
|
|
|
1443
|
-
|
|
1496
|
+
if (!Object.hasOwn(slw_value ?? {}, String(prop))) {
|
|
1497
|
+
const _data = getResultDataForTarget(target);
|
|
1498
|
+
const path = target[SLW_OP_PATH] ?? "";
|
|
1444
1499
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
(
|
|
1448
|
-
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]({
|
|
1449
1504
|
SLW_OP_PATH:
|
|
1450
|
-
|
|
1451
|
-
"." +
|
|
1452
|
-
String(i),
|
|
1505
|
+
path + "." + String(prop),
|
|
1453
1506
|
OP_RESULT_DATA:
|
|
1454
1507
|
target[
|
|
1455
1508
|
SLW_OP_RESULT_DATA_OVERRIDE
|
|
1456
1509
|
],
|
|
1457
|
-
})
|
|
1458
|
-
|
|
1510
|
+
});
|
|
1511
|
+
return elm;
|
|
1512
|
+
}
|
|
1459
1513
|
|
|
1460
|
-
|
|
1461
|
-
|
|
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);
|
|
1462
1559
|
if (Object.hasOwn(proto, prop)) {
|
|
1463
|
-
const v = (
|
|
1560
|
+
const v = (data as any)[prop];
|
|
1464
1561
|
if (typeof v === "function")
|
|
1465
|
-
return v.bind(
|
|
1562
|
+
return v.bind(data);
|
|
1466
1563
|
return v;
|
|
1467
1564
|
}
|
|
1468
1565
|
|
|
1469
|
-
return (
|
|
1566
|
+
return (data as any)[prop];
|
|
1470
1567
|
}
|
|
1471
1568
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
if (
|
|
1478
|
-
|
|
1479
|
-
|
|
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
|
+
}
|
|
1480
1578
|
}
|
|
1481
1579
|
|
|
1482
|
-
|
|
1483
|
-
|
|
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
|
+
}
|
|
1484
1595
|
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
if (
|
|
1491
|
-
|
|
1492
|
-
|
|
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;
|
|
1493
1605
|
}
|
|
1494
|
-
}
|
|
1495
1606
|
|
|
1496
|
-
|
|
1497
|
-
slwOpPathIsIndexAccessOrInArray ||
|
|
1498
|
-
(target[SLW_OP_RESULT_DATA_OVERRIDE] &&
|
|
1499
|
-
!slw[SLW_OP_RESULT_DATA_OVERRIDE])
|
|
1500
|
-
) {
|
|
1501
|
-
// index access detected, cloning
|
|
1502
|
-
slw = slw[SLW_CLONE]({
|
|
1503
|
-
SLW_OP_PATH:
|
|
1504
|
-
target[SLW_OP_PATH] + "." + String(prop),
|
|
1505
|
-
OP_RESULT_DATA:
|
|
1506
|
-
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1507
|
-
});
|
|
1607
|
+
return getResultDataForTarget(target);
|
|
1508
1608
|
}
|
|
1509
1609
|
|
|
1510
1610
|
if (
|
|
1511
|
-
|
|
1512
|
-
|
|
1611
|
+
Object.hasOwn(slw_value ?? {}, String(prop)) &&
|
|
1612
|
+
slw_value?.[String(prop)] instanceof
|
|
1613
|
+
SelectionWrapperImpl
|
|
1513
1614
|
) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
if (
|
|
1525
|
-
Object.hasOwn(slw_value ?? {}, String(prop)) &&
|
|
1526
|
-
slw_value?.[String(prop)] instanceof
|
|
1527
|
-
SelectionWrapperImpl
|
|
1528
|
-
) {
|
|
1529
|
-
if (target[SLW_COLLECTOR]) {
|
|
1530
|
-
target[SLW_COLLECTOR].registerSelection(
|
|
1531
|
-
String(prop),
|
|
1532
|
-
slw_value[String(prop)],
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
|
|
1536
|
-
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
|
+
}
|
|
1537
1625
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
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
|
+
}
|
|
1548
1637
|
}
|
|
1549
|
-
}
|
|
1550
1638
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1639
|
+
return slw_value?.[String(prop)] ?? undefined;
|
|
1640
|
+
},
|
|
1641
|
+
};
|
|
1642
|
+
})(),
|
|
1554
1643
|
);
|
|
1555
1644
|
}
|
|
1556
1645
|
}
|
|
@@ -1581,9 +1670,12 @@ export class SelectionWrapper<
|
|
|
1581
1670
|
type CleanupNever<A> = Omit<A, keyof A> & {
|
|
1582
1671
|
[K in keyof A as A[K] extends never ? never : K]: A[K];
|
|
1583
1672
|
};
|
|
1584
|
-
type Prettify<T> =
|
|
1585
|
-
|
|
1586
|
-
|
|
1673
|
+
type Prettify<T> = (
|
|
1674
|
+
T extends Array<infer U>
|
|
1675
|
+
? U[] : {
|
|
1676
|
+
[K in keyof T]: T[K];
|
|
1677
|
+
}
|
|
1678
|
+
) & {};
|
|
1587
1679
|
|
|
1588
1680
|
type SLWsFromSelection<
|
|
1589
1681
|
S,
|
|
@@ -1706,12 +1798,291 @@ export class SelectionWrapper<
|
|
|
1706
1798
|
>
|
|
1707
1799
|
>;
|
|
1708
1800
|
`;static HelperFunctions=`
|
|
1709
|
-
const selectScalars =
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
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 OmitNever<T> =
|
|
1923
|
+
isScalar<T> extends true
|
|
1924
|
+
? T
|
|
1925
|
+
: T extends object
|
|
1926
|
+
? {
|
|
1927
|
+
[K in keyof T as T[K] extends never
|
|
1928
|
+
? never
|
|
1929
|
+
: T[K] extends never[]
|
|
1930
|
+
? never
|
|
1931
|
+
: K]: isScalar<T[K]> extends true
|
|
1932
|
+
? T[K]
|
|
1933
|
+
: T[K] extends object
|
|
1934
|
+
? OmitNever<T[K]>
|
|
1935
|
+
: T[K];
|
|
1936
|
+
}
|
|
1937
|
+
: T;
|
|
1938
|
+
|
|
1939
|
+
const selectCyclicFieldsOptsStr = "select cyclic levels: ";
|
|
1940
|
+
type selectCyclicFieldsOptsStrType = typeof selectCyclicFieldsOptsStr;
|
|
1941
|
+
type cyclicOpts<
|
|
1942
|
+
S,
|
|
1943
|
+
CP = CyclicPaths<S>,
|
|
1944
|
+
kOpts = "exclude" | \`\${selectCyclicFieldsOptsStrType}\${1 | 2 | 3 | 4 | 5}\`,
|
|
1945
|
+
> = CP extends never
|
|
1946
|
+
? never
|
|
1947
|
+
: {
|
|
1948
|
+
[k in CP & string]: kOpts;
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
type Next = [1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
|
|
1952
|
+
type StringToNumber<S extends string> = S extends \`\${infer N extends number}\`
|
|
1953
|
+
? N
|
|
1954
|
+
: never;
|
|
1955
|
+
|
|
1956
|
+
type getNumberNestedLevels<str extends string> =
|
|
1957
|
+
str extends \`\${selectCyclicFieldsOptsStrType}\${infer n}\`
|
|
1958
|
+
? StringToNumber<n>
|
|
1959
|
+
: never;
|
|
1960
|
+
|
|
1961
|
+
type selectAllOpts<S> = OmitNever<{
|
|
1962
|
+
exclude?: Paths<S>[];
|
|
1963
|
+
cyclic: cyclicOpts<S>;
|
|
1964
|
+
}>;
|
|
1965
|
+
type RepeatString<
|
|
1966
|
+
S extends string,
|
|
1967
|
+
N extends number,
|
|
1968
|
+
Splitter extends string = "",
|
|
1969
|
+
Acc extends string = "",
|
|
1970
|
+
Count extends number = N,
|
|
1971
|
+
> = Count extends 0
|
|
1972
|
+
? Acc
|
|
1973
|
+
: RepeatString<
|
|
1974
|
+
S,
|
|
1975
|
+
N,
|
|
1976
|
+
Splitter,
|
|
1977
|
+
\`\${Acc}\${Acc extends "" ? "" : Splitter}\${S}\`,
|
|
1978
|
+
Prev[Count]
|
|
1979
|
+
>;
|
|
1980
|
+
|
|
1981
|
+
type GetSuffix<
|
|
1982
|
+
Str extends string,
|
|
1983
|
+
Prefix extends string,
|
|
1984
|
+
> = Str extends \`\${Prefix}\${infer Suffix}\` ? Suffix : never;
|
|
1985
|
+
|
|
1986
|
+
type selectAllFunc<T, TNP extends string> = <
|
|
1987
|
+
const P = Paths<T>,
|
|
1988
|
+
const CP_WITH_TNP = cyclicOpts<T, \`\${TNP}.\${CyclicPaths<T>}\`>
|
|
1989
|
+
>(opts: {
|
|
1990
|
+
exclude?: \`\${TNP}.\${P & string}\`[];
|
|
1991
|
+
cyclic: CP_WITH_TNP;
|
|
1992
|
+
}) => OmitNever<
|
|
1993
|
+
MergeUnion<
|
|
1994
|
+
OmitMultiplePaths<
|
|
1995
|
+
T,
|
|
1996
|
+
| (P & string)
|
|
1997
|
+
| (CP_WITH_TNP extends never
|
|
1998
|
+
? never
|
|
1999
|
+
: Exclude<
|
|
2000
|
+
{
|
|
2001
|
+
[k in keyof CP_WITH_TNP]: "exclude" extends CP_WITH_TNP[k]
|
|
2002
|
+
? GetSuffix<k & string, \`\${TNP}.\`>
|
|
2003
|
+
: RepeatString<
|
|
2004
|
+
GetSuffix<k & string, \`\${TNP}.\`>,
|
|
2005
|
+
Next[getNumberNestedLevels<
|
|
2006
|
+
CP_WITH_TNP[k] & string
|
|
2007
|
+
>],
|
|
2008
|
+
"."
|
|
2009
|
+
>;
|
|
2010
|
+
}[keyof CP_WITH_TNP],
|
|
2011
|
+
undefined
|
|
2012
|
+
>)
|
|
2013
|
+
>
|
|
2014
|
+
>
|
|
2015
|
+
>;
|
|
2016
|
+
|
|
2017
|
+
const selectAll = <
|
|
2018
|
+
S,
|
|
2019
|
+
TNP extends string,
|
|
2020
|
+
SUB extends ReturnType<SLFN<{}, unknown, string, string, number>>,
|
|
2021
|
+
V extends
|
|
2022
|
+
| (SelectionWrapperImpl<any, any, any> | SUB)
|
|
2023
|
+
| ((args: any) => SelectionWrapperImpl<any, any, any> | SUB),
|
|
2024
|
+
>(
|
|
2025
|
+
selection: Record<string, V>,
|
|
2026
|
+
typeNamePure: TNP,
|
|
2027
|
+
opts: selectAllOpts<S>,
|
|
2028
|
+
collector?: { parents: string[]; path?: string },
|
|
2029
|
+
) => {
|
|
2030
|
+
// let's not make the type too complicated, it's basically a
|
|
2031
|
+
// nested map of string to either SLW or again
|
|
2032
|
+
// a map of string to SLW
|
|
2033
|
+
const s: Record<string, any> = {};
|
|
2034
|
+
const entries = Object.entries(selection);
|
|
2035
|
+
for (const [k, v] of entries) {
|
|
2036
|
+
const tk = collector?.path
|
|
2037
|
+
? \`\${collector.path}.\${k}\`
|
|
2038
|
+
: \`\${typeNamePure}.\${k}\`;
|
|
2039
|
+
let excludePaths = opts?.exclude ?? ([] as string[]);
|
|
2040
|
+
if ("cyclic" in opts) {
|
|
2041
|
+
const exclude = Object.entries(
|
|
2042
|
+
opts.cyclic as Record<string, string>,
|
|
2043
|
+
)
|
|
2044
|
+
.filter(([k, v]) => v === "exclude")
|
|
2045
|
+
.map((e) => e[0]);
|
|
2046
|
+
const cyclicLevels = Object.entries(
|
|
2047
|
+
opts.cyclic as Record<string, string>,
|
|
2048
|
+
)
|
|
2049
|
+
.filter(([k, v]) => v !== "exclude")
|
|
2050
|
+
.map((e) => {
|
|
2051
|
+
const levels = parseInt(
|
|
2052
|
+
e[1]
|
|
2053
|
+
.match(new RegExp(\`\${selectCyclicFieldsOptsStr}(.*)\`))!
|
|
2054
|
+
.at(1)![0],
|
|
2055
|
+
) + 1;
|
|
2056
|
+
const pathFragment = e[0].split(".").slice(1).join(".");
|
|
2057
|
+
return \`\${e[0].split(".")[0]}.\${Array.from({ length: levels }).fill(pathFragment).join(".")}\`;
|
|
2058
|
+
});
|
|
2059
|
+
excludePaths.push(...exclude, ...cyclicLevels);
|
|
2060
|
+
}
|
|
2061
|
+
if (excludePaths.includes(tk as any)) continue;
|
|
2062
|
+
|
|
2063
|
+
if (typeof v === "function") {
|
|
2064
|
+
if (v.name === "bound _SLFN") {
|
|
2065
|
+
// if (collector?.parents?.includes(tk)) continue;
|
|
2066
|
+
const col = {
|
|
2067
|
+
parents: [...(collector?.parents ?? []), tk],
|
|
2068
|
+
path: tk,
|
|
2069
|
+
};
|
|
2070
|
+
s[k] = v(
|
|
2071
|
+
(sub_s: { $all: (_opts?: {}, collector?: {}) => any }) => {
|
|
2072
|
+
return sub_s.$all(opts, col);
|
|
2073
|
+
},
|
|
2074
|
+
);
|
|
2075
|
+
} else if (!k.startsWith("$")) {
|
|
2076
|
+
console.warn(
|
|
2077
|
+
\`Cannot use $all on fields with args: \${k}: \${v.toString()}\`,
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
} else {
|
|
2081
|
+
s[k] = v;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
return s;
|
|
2085
|
+
};
|
|
1715
2086
|
|
|
1716
2087
|
const makeSLFN = <
|
|
1717
2088
|
T extends object,
|
|
@@ -1784,7 +2155,7 @@ export class SelectionWrapper<
|
|
|
1784
2155
|
};
|
|
1785
2156
|
`;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}`} */`:""}
|
|
1786
2157
|
${z}: ${I};`}).join(" ")} }`;this.collector.addArgumentType(X,`export type ${X} = ${Y};`)}return{argsTypeName:X,hasAtLeastOneNonNullArg:q}},Z=D.description?`/* ${D.description} */
|
|
1787
|
-
`:"";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:
|
|
2158
|
+
`:"";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=`
|
|
1788
2159
|
export type ${D} = ${P};
|
|
1789
2160
|
`}else F=`
|
|
1790
2161
|
export type ${D} = {
|
|
@@ -1817,16 +2188,16 @@ export class SelectionWrapper<
|
|
|
1817
2188
|
${this.typeMeta.isList??0},
|
|
1818
2189
|
{},
|
|
1819
2190
|
this
|
|
1820
|
-
)`;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((
|
|
2191
|
+
)`;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=`
|
|
1821
2192
|
$on: {
|
|
1822
|
-
${this.typeMeta.possibleTypes.map((
|
|
2193
|
+
${this.typeMeta.possibleTypes.map((H)=>`${H.name}: ${this.originalTypeNameToTypescriptFriendlyName(H.name)}Selection.bind({
|
|
1823
2194
|
collector: this,
|
|
1824
2195
|
fieldName: "",
|
|
1825
|
-
onTypeFragment: "${
|
|
2196
|
+
onTypeFragment: "${H.name}",
|
|
1826
2197
|
}),`).join(`
|
|
1827
2198
|
`)}
|
|
1828
2199
|
}
|
|
1829
|
-
`;else
|
|
2200
|
+
`;else q=`
|
|
1830
2201
|
$fragment: <F extends (this: any, ...args: any[]) => any>(f: F) =>
|
|
1831
2202
|
f.bind({
|
|
1832
2203
|
collector: this,
|
|
@@ -1840,37 +2211,45 @@ export class SelectionWrapper<
|
|
|
1840
2211
|
) as SLWsFromSelection<
|
|
1841
2212
|
ReturnType<typeof make${D}Input>
|
|
1842
2213
|
>,
|
|
1843
|
-
`:""}
|
|
2214
|
+
`:""}
|
|
2215
|
+
$all: (opts?: any, collector = undefined) =>
|
|
2216
|
+
selectAll(
|
|
2217
|
+
make${D}Input.bind(this)() as any,
|
|
2218
|
+
"${Z}",
|
|
2219
|
+
opts as any,
|
|
2220
|
+
collector
|
|
2221
|
+
) as any
|
|
2222
|
+
`;let X=new Map,J=`
|
|
1844
2223
|
export function make${D}Input(this: any) ${this.typeMeta.isUnion?"":`: ReturnTypeFrom${D}`} {
|
|
1845
2224
|
return {
|
|
1846
|
-
${this.typeMeta.fields.map((
|
|
2225
|
+
${this.typeMeta.fields.map((H)=>[H,this.makeSelectionFunctionInputObjectValueForField(H,this.typeMeta.isInput?[]:[this.typeName])]).map(([H,W])=>{let U=`
|
|
1847
2226
|
$lazy: (
|
|
1848
|
-
${
|
|
1849
|
-
) => Promise<"T">`;return
|
|
1850
|
-
args: ${this.typeName}${
|
|
1851
|
-
) =>`:""}`,`${
|
|
2227
|
+
${H.hasArgs?`args: ${this.typeName}${H.name.slice(0,1).toUpperCase()}${H.name.slice(1)}Args`:""}
|
|
2228
|
+
) => Promise<"T">`;return X.set(H.name,[`${H.hasArgs?`(
|
|
2229
|
+
args: ${this.typeName}${H.name.slice(0,1).toUpperCase()}${H.name.slice(1)}Args
|
|
2230
|
+
) =>`:""}`,`${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<
|
|
1852
2231
|
SLFN<
|
|
1853
2232
|
{},
|
|
1854
|
-
ReturnType<typeof make${super.originalTypeNameToTypescriptFriendlyName(
|
|
1855
|
-
"${super.originalTypeNameToTypescriptFriendlyName(
|
|
1856
|
-
"${super.originalTypeNameToTypescriptTypeNameWithoutModifiers(
|
|
1857
|
-
${
|
|
2233
|
+
ReturnType<typeof make${super.originalTypeNameToTypescriptFriendlyName(H.type.name)}SelectionInput>,
|
|
2234
|
+
"${super.originalTypeNameToTypescriptFriendlyName(H.type.name)}Selection",
|
|
2235
|
+
"${super.originalTypeNameToTypescriptTypeNameWithoutModifiers(H.type.name)}",
|
|
2236
|
+
${H.type.isList??0}
|
|
1858
2237
|
${P?`,
|
|
1859
2238
|
{
|
|
1860
|
-
${
|
|
2239
|
+
${U} ${this.authConfig?`& {
|
|
1861
2240
|
auth: (auth: FnOrPromisOrPrimitive) => Promise<"T">;
|
|
1862
2241
|
}`:""};
|
|
1863
|
-
${this.authConfig?`auth: (auth: FnOrPromisOrPrimitive) => Promise<"T"> & {${
|
|
2242
|
+
${this.authConfig?`auth: (auth: FnOrPromisOrPrimitive) => Promise<"T"> & {${U}}`:""}
|
|
1864
2243
|
},
|
|
1865
2244
|
"$lazy" ${this.authConfig?'| "auth"':""},
|
|
1866
2245
|
AS_PROMISE
|
|
1867
2246
|
${B?", 1":""}
|
|
1868
2247
|
`:""}
|
|
1869
2248
|
>
|
|
1870
|
-
>`}`]),`${
|
|
2249
|
+
>`}`]),`${W},`}).join(`
|
|
1871
2250
|
`)}
|
|
1872
2251
|
|
|
1873
|
-
${
|
|
2252
|
+
${q}
|
|
1874
2253
|
} as const;
|
|
1875
2254
|
};
|
|
1876
2255
|
export const ${D} = makeSLFN(
|
|
@@ -1879,13 +2258,13 @@ export class SelectionWrapper<
|
|
|
1879
2258
|
"${this.originalFullTypeName.replaceAll("[","").replaceAll("]","").replaceAll("!","")}",
|
|
1880
2259
|
${this.typeMeta.isList??0}
|
|
1881
2260
|
);
|
|
1882
|
-
`,
|
|
2261
|
+
`,Y=this.typeMeta.isUnion?"":`
|
|
1883
2262
|
type ReturnTypeFrom${D}RetTypes<AS_PROMISE = 0> = {
|
|
1884
|
-
${Array.from(
|
|
2263
|
+
${Array.from(X).map(([H,[W,U]])=>`${H}: ${U}`).join(`
|
|
1885
2264
|
`)}
|
|
1886
2265
|
}
|
|
1887
2266
|
type ReturnTypeFrom${D} = {
|
|
1888
|
-
${Array.from(
|
|
2267
|
+
${Array.from(X).map(([H,[W,U]])=>`${H}: ${W} ReturnTypeFrom${D}RetTypes["${H}"]`).join(`
|
|
1889
2268
|
`)}
|
|
1890
2269
|
} & {
|
|
1891
2270
|
$fragment: <F extends (this: any, ...args: any[]) => any>(
|
|
@@ -1896,8 +2275,9 @@ export class SelectionWrapper<
|
|
|
1896
2275
|
${F?`
|
|
1897
2276
|
$scalars: () => SLWsFromSelection<ReturnType<typeof ${`make${D}Input`}>>;
|
|
1898
2277
|
`:""}
|
|
1899
|
-
|
|
1900
|
-
|
|
2278
|
+
$all: selectAllFunc<AllNonFuncFieldsFromType<${Z}>, "${Z}">;
|
|
2279
|
+
};`;return this.collector.addSelectionFunction(this.typeMeta,`${Y}
|
|
2280
|
+
${J}
|
|
1901
2281
|
`),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`
|
|
1902
2282
|
${X?.length?`export const $directives = {
|
|
1903
2283
|
${X.join(`,
|
|
@@ -2070,7 +2450,7 @@ export class SelectionWrapper<
|
|
|
2070
2450
|
typeof operation extends "${q[1]}"
|
|
2071
2451
|
? keyof ReturnTypeFrom${q[1]}Selection
|
|
2072
2452
|
: keyof ReturnTypeFrom${q[2]}Selection,`:`keyof ReturnTypeFrom${q[1]}Selection,`}`}
|
|
2073
|
-
"$fragment" | "$scalars"
|
|
2453
|
+
"$fragment" | "$scalars" | "$all"
|
|
2074
2454
|
>,
|
|
2075
2455
|
) => {
|
|
2076
2456
|
const root = new OperationSelectionCollector(
|
|
@@ -2083,7 +2463,7 @@ export class SelectionWrapper<
|
|
|
2083
2463
|
let fieldFn: ${q.map((Y)=>`
|
|
2084
2464
|
ReturnTypeFrom${Y}Selection[Exclude<
|
|
2085
2465
|
keyof ReturnTypeFrom${Y}Selection,
|
|
2086
|
-
"$fragment" | "$scalars"
|
|
2466
|
+
"$fragment" | "$scalars" | "$all"
|
|
2087
2467
|
>]`).join(" | ")};
|
|
2088
2468
|
|
|
2089
2469
|
${q.length>1?`if (operation === "${q[0]}") {`:""}
|
|
@@ -2091,7 +2471,7 @@ export class SelectionWrapper<
|
|
|
2091
2471
|
make${q[0]}SelectionInput.bind(rootRef)()[
|
|
2092
2472
|
field as Exclude<
|
|
2093
2473
|
keyof ReturnTypeFrom${q[0]}Selection,
|
|
2094
|
-
"$fragment" | "$scalars"
|
|
2474
|
+
"$fragment" | "$scalars" | "$all"
|
|
2095
2475
|
>
|
|
2096
2476
|
];
|
|
2097
2477
|
${q.length>1?`} else ${q.length>2?`if (operation === "${q[1]}")`:""}`:""}${q.length>1?`{
|
|
@@ -2099,7 +2479,7 @@ export class SelectionWrapper<
|
|
|
2099
2479
|
make${q[1]}SelectionInput.bind(rootRef)()[
|
|
2100
2480
|
field as Exclude<
|
|
2101
2481
|
keyof ReturnTypeFrom${q[1]}Selection,
|
|
2102
|
-
"$fragment" | "$scalars"
|
|
2482
|
+
"$fragment" | "$scalars" | "$all"
|
|
2103
2483
|
>
|
|
2104
2484
|
];
|
|
2105
2485
|
}`:""}
|
|
@@ -2108,7 +2488,7 @@ export class SelectionWrapper<
|
|
|
2108
2488
|
make${q[2]}SelectionInput.bind(rootRef)()[
|
|
2109
2489
|
field as Exclude<
|
|
2110
2490
|
keyof ReturnTypeFrom${q[2]}Selection,
|
|
2111
|
-
"$fragment" | "$scalars"
|
|
2491
|
+
"$fragment" | "$scalars" | "$all"
|
|
2112
2492
|
>
|
|
2113
2493
|
];
|
|
2114
2494
|
}`:""}
|
|
@@ -2302,7 +2682,7 @@ export class SelectionWrapper<
|
|
|
2302
2682
|
target,
|
|
2303
2683
|
op: Exclude<
|
|
2304
2684
|
keyof ReturnTypeFrom${Y}Selection,
|
|
2305
|
-
"$fragment" | "$scalars"
|
|
2685
|
+
"$fragment" | "$scalars" | "$all"
|
|
2306
2686
|
>,
|
|
2307
2687
|
) {
|
|
2308
2688
|
return _makeOperationShortcut("${Y}", op);
|
|
@@ -2320,7 +2700,7 @@ export class SelectionWrapper<
|
|
|
2320
2700
|
${q.map((Y)=>({op:Y,wrapForAsyncIter:(H)=>Y===Z?`AsyncIterable<${H}>`:H})).map(({op:Y,wrapForAsyncIter:H})=>`${Y?.toLowerCase()}: {
|
|
2321
2701
|
[field in Exclude<
|
|
2322
2702
|
keyof ReturnType<typeof make${Y}SelectionInput>,
|
|
2323
|
-
"$fragment" | "$scalars"
|
|
2703
|
+
"$fragment" | "$scalars" | "$all"
|
|
2324
2704
|
>]: ReturnType<
|
|
2325
2705
|
typeof make${Y}SelectionInput
|
|
2326
2706
|
>[field] extends SelectionWrapperImpl<
|
|
@@ -3975,7 +4355,7 @@ export class SelectionWrapper<
|
|
|
3975
4355
|
export default __client__ as typeof __client__ & {
|
|
3976
4356
|
init: typeof __init__;
|
|
3977
4357
|
};
|
|
3978
|
-
`}}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,"
|
|
4358
|
+
`}}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(`
|
|
3979
4359
|
`)}}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(`
|
|
3980
4360
|
`)}}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(`
|
|
3981
4361
|
_____ _
|