@samarium.sdk/new 0.23.1 → 0.24.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 +126 -47
- package/package.json +3 -3
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.24.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"},peerDependencies:{typescript:"^5.0.0"},dependencies:{"@samarium.sdk/make":"workspace:*","@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 = {};
|
|
@@ -693,6 +693,15 @@ export class OperationSelectionCollector {
|
|
|
693
693
|
|
|
694
694
|
private executed = false;
|
|
695
695
|
private operationResult: any | undefined = undefined;
|
|
696
|
+
|
|
697
|
+
public cache: {
|
|
698
|
+
data: Map<string, any>;
|
|
699
|
+
proxiedArray: Map<string, any[]>;
|
|
700
|
+
} = {
|
|
701
|
+
data: new Map(),
|
|
702
|
+
proxiedArray: new Map(),
|
|
703
|
+
};
|
|
704
|
+
|
|
696
705
|
public async execute(headers?: Record<string, string>) {
|
|
697
706
|
if (!this.op) {
|
|
698
707
|
throw new Error(
|
|
@@ -938,6 +947,7 @@ export const SLW_RECREATE_VALUE_CALLBACK = Symbol(
|
|
|
938
947
|
"SLW_RECREATE_VALUE_CALLBACK",
|
|
939
948
|
);
|
|
940
949
|
export const SLW_SETTER_DATA_OVERRIDE = Symbol("SLW_SETTER_DATA_OVERRIDE");
|
|
950
|
+
export const SLW_NEEDS_CLONE = Symbol("SLW_NEEDS_CLONE");
|
|
941
951
|
|
|
942
952
|
export const SLW_CLONE = Symbol("SLW_CLONE");
|
|
943
953
|
|
|
@@ -959,6 +969,7 @@ export class SelectionWrapperImpl<
|
|
|
959
969
|
SLW_OP_PATH?: string;
|
|
960
970
|
OP_RESULT_DATA?: any;
|
|
961
971
|
SLW_SETTER_DATA_OVERRIDE?: any;
|
|
972
|
+
SLW_NEEDS_CLONE?: boolean;
|
|
962
973
|
} = {},
|
|
963
974
|
) {
|
|
964
975
|
const slw = new SelectionWrapper(
|
|
@@ -981,6 +992,12 @@ export class SelectionWrapperImpl<
|
|
|
981
992
|
overrides.SLW_SETTER_DATA_OVERRIDE ??
|
|
982
993
|
this[SLW_SETTER_DATA_OVERRIDE];
|
|
983
994
|
|
|
995
|
+
slw[SLW_NEEDS_CLONE] = overrides.SLW_NEEDS_CLONE
|
|
996
|
+
? true
|
|
997
|
+
: this[SLW_NEEDS_CLONE]
|
|
998
|
+
? false
|
|
999
|
+
: true;
|
|
1000
|
+
|
|
984
1001
|
if (overrides.OP_RESULT_DATA) {
|
|
985
1002
|
slw[SLW_OP_RESULT_DATA_OVERRIDE] = overrides.OP_RESULT_DATA;
|
|
986
1003
|
}
|
|
@@ -1010,11 +1027,11 @@ export class SelectionWrapperImpl<
|
|
|
1010
1027
|
|
|
1011
1028
|
[SLW_PARENT_SLW]?: SelectionWrapperImpl<string, string, number, any, any>;
|
|
1012
1029
|
[SLW_LAZY_FLAG]?: boolean;
|
|
1013
|
-
|
|
1014
1030
|
[SLW_RECREATE_VALUE_CALLBACK]?: () => valueT;
|
|
1015
1031
|
|
|
1016
1032
|
[SLW_OP_RESULT_DATA_OVERRIDE]?: any;
|
|
1017
1033
|
[SLW_SETTER_DATA_OVERRIDE]?: any;
|
|
1034
|
+
[SLW_NEEDS_CLONE]?: boolean;
|
|
1018
1035
|
|
|
1019
1036
|
constructor(
|
|
1020
1037
|
fieldName?: fieldName,
|
|
@@ -1189,22 +1206,15 @@ export class SelectionWrapper<
|
|
|
1189
1206
|
reCreateValueCallback,
|
|
1190
1207
|
),
|
|
1191
1208
|
(() => {
|
|
1192
|
-
const
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
argsT
|
|
1202
|
-
>[]
|
|
1203
|
-
>;
|
|
1204
|
-
} = {
|
|
1205
|
-
data: new Map(),
|
|
1206
|
-
proxiedArray: new Map(),
|
|
1207
|
-
};
|
|
1209
|
+
const getCache = (
|
|
1210
|
+
t: SelectionWrapperImpl<
|
|
1211
|
+
fieldName,
|
|
1212
|
+
typeNamePure,
|
|
1213
|
+
typeArrDepth,
|
|
1214
|
+
valueT,
|
|
1215
|
+
argsT
|
|
1216
|
+
>,
|
|
1217
|
+
) => t[ROOT_OP_COLLECTOR]!.ref.cache;
|
|
1208
1218
|
|
|
1209
1219
|
const getResultDataForTarget = (
|
|
1210
1220
|
t: SelectionWrapperImpl<
|
|
@@ -1216,8 +1226,11 @@ export class SelectionWrapper<
|
|
|
1216
1226
|
>,
|
|
1217
1227
|
overrideOpPath?: string,
|
|
1218
1228
|
): valueT | undefined => {
|
|
1229
|
+
const cache = getCache(t);
|
|
1230
|
+
|
|
1219
1231
|
const path = overrideOpPath ?? t[SLW_OP_PATH] ?? "";
|
|
1220
|
-
if (cache.data.has(path)
|
|
1232
|
+
if (cache.data.has(path) && !t[SLW_NEEDS_CLONE])
|
|
1233
|
+
return cache.data.get(path);
|
|
1221
1234
|
|
|
1222
1235
|
const data = t[
|
|
1223
1236
|
ROOT_OP_COLLECTOR
|
|
@@ -1247,12 +1260,12 @@ export class SelectionWrapper<
|
|
|
1247
1260
|
has(target, prop) {
|
|
1248
1261
|
if (prop === Symbol.for("nodejs.util.inspect.custom"))
|
|
1249
1262
|
return true;
|
|
1250
|
-
if (
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1263
|
+
if (prop === Symbol.iterator && typeArrDepth) {
|
|
1264
|
+
const dataArr = getResultDataForTarget(target);
|
|
1265
|
+
if (Array.isArray(dataArr)) return true;
|
|
1266
|
+
if (dataArr === undefined || dataArr === null)
|
|
1267
|
+
return false;
|
|
1268
|
+
}
|
|
1256
1269
|
|
|
1257
1270
|
return Reflect.has(value ?? {}, prop);
|
|
1258
1271
|
},
|
|
@@ -1485,6 +1498,10 @@ export class SelectionWrapper<
|
|
|
1485
1498
|
asyncGenRootPath,
|
|
1486
1499
|
OP_RESULT_DATA:
|
|
1487
1500
|
val.value,
|
|
1501
|
+
|
|
1502
|
+
// this is only for subscriptions
|
|
1503
|
+
SLW_NEEDS_CLONE:
|
|
1504
|
+
true,
|
|
1488
1505
|
}),
|
|
1489
1506
|
};
|
|
1490
1507
|
});
|
|
@@ -1495,7 +1512,7 @@ export class SelectionWrapper<
|
|
|
1495
1512
|
|
|
1496
1513
|
if (!Object.hasOwn(slw_value ?? {}, String(prop))) {
|
|
1497
1514
|
const _data = getResultDataForTarget(target);
|
|
1498
|
-
const path = target[SLW_OP_PATH]
|
|
1515
|
+
const path = target[SLW_OP_PATH]!;
|
|
1499
1516
|
|
|
1500
1517
|
// check if the selected field is an array
|
|
1501
1518
|
if (typeArrDepth && Array.isArray(_data)) {
|
|
@@ -1514,10 +1531,11 @@ export class SelectionWrapper<
|
|
|
1514
1531
|
const data = _data as valueT[] | undefined;
|
|
1515
1532
|
|
|
1516
1533
|
if (data === undefined) return undefined;
|
|
1534
|
+
const cache = getCache(target);
|
|
1517
1535
|
|
|
1518
1536
|
const proxiedData =
|
|
1519
1537
|
cache.proxiedArray.get(
|
|
1520
|
-
target[SLW_OP_PATH]
|
|
1538
|
+
target[SLW_OP_PATH]!,
|
|
1521
1539
|
) ??
|
|
1522
1540
|
Array.from(
|
|
1523
1541
|
{ length: data.length },
|
|
@@ -1550,11 +1568,16 @@ export class SelectionWrapper<
|
|
|
1550
1568
|
return v;
|
|
1551
1569
|
}
|
|
1552
1570
|
|
|
1571
|
+
if (data === undefined) return undefined;
|
|
1572
|
+
if (data === null) return null;
|
|
1573
|
+
|
|
1553
1574
|
return (proxiedData as any)[prop];
|
|
1554
1575
|
}
|
|
1555
1576
|
|
|
1556
1577
|
const data = _data as valueT | undefined;
|
|
1557
1578
|
if (data === undefined) return undefined;
|
|
1579
|
+
if (data === null) return null;
|
|
1580
|
+
|
|
1558
1581
|
const proto = Object.getPrototypeOf(data);
|
|
1559
1582
|
if (Object.hasOwn(proto, prop)) {
|
|
1560
1583
|
const v = (data as any)[prop];
|
|
@@ -1582,15 +1605,54 @@ export class SelectionWrapper<
|
|
|
1582
1605
|
(target[SLW_OP_RESULT_DATA_OVERRIDE] &&
|
|
1583
1606
|
!slw[SLW_OP_RESULT_DATA_OVERRIDE])
|
|
1584
1607
|
) {
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1608
|
+
if (target[SLW_NEEDS_CLONE]) {
|
|
1609
|
+
// if the slw is flagged it needs to be cloned
|
|
1610
|
+
// this is only for subscriptions, because
|
|
1611
|
+
// the original slw will continue to exist
|
|
1612
|
+
// and also have the same op path
|
|
1613
|
+
// we need a new object that doesn't reference
|
|
1614
|
+
// the other objects
|
|
1615
|
+
slw = slw[SLW_CLONE]({
|
|
1616
|
+
SLW_OP_PATH:
|
|
1617
|
+
target[SLW_OP_PATH] +
|
|
1618
|
+
"." +
|
|
1619
|
+
String(prop),
|
|
1620
|
+
OP_RESULT_DATA:
|
|
1621
|
+
target[SLW_OP_RESULT_DATA_OVERRIDE],
|
|
1622
|
+
});
|
|
1623
|
+
} else {
|
|
1624
|
+
// index access detected, setting the op path
|
|
1625
|
+
// with the index (coming from the slw's parent (target))
|
|
1626
|
+
// it's in the parent because the parent was cloned before
|
|
1627
|
+
slw[SLW_OP_PATH] =
|
|
1588
1628
|
target[SLW_OP_PATH] +
|
|
1589
1629
|
"." +
|
|
1590
|
-
String(prop)
|
|
1591
|
-
|
|
1592
|
-
target[SLW_OP_RESULT_DATA_OVERRIDE]
|
|
1593
|
-
}
|
|
1630
|
+
String(prop);
|
|
1631
|
+
slw[SLW_OP_RESULT_DATA_OVERRIDE] =
|
|
1632
|
+
target[SLW_OP_RESULT_DATA_OVERRIDE];
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
if (
|
|
1637
|
+
slw instanceof SelectionWrapperImpl &&
|
|
1638
|
+
slw[SLW_FIELD_ARR_DEPTH]
|
|
1639
|
+
) {
|
|
1640
|
+
const dataArr = getResultDataForTarget(slw) as
|
|
1641
|
+
| unknown[]
|
|
1642
|
+
| undefined
|
|
1643
|
+
| null;
|
|
1644
|
+
if (dataArr === undefined) return undefined;
|
|
1645
|
+
if (dataArr === null) return null;
|
|
1646
|
+
if (!dataArr?.length) {
|
|
1647
|
+
return [];
|
|
1648
|
+
}
|
|
1649
|
+
} else if (slw instanceof SelectionWrapperImpl) {
|
|
1650
|
+
const data = getResultDataForTarget(slw) as
|
|
1651
|
+
| unknown
|
|
1652
|
+
| undefined
|
|
1653
|
+
| null;
|
|
1654
|
+
if (data === undefined) return undefined;
|
|
1655
|
+
if (data === null) return null;
|
|
1594
1656
|
}
|
|
1595
1657
|
|
|
1596
1658
|
if (
|
|
@@ -2075,9 +2137,25 @@ export class SelectionWrapper<
|
|
|
2075
2137
|
path: tk,
|
|
2076
2138
|
};
|
|
2077
2139
|
s[k] = v(
|
|
2078
|
-
(sub_s: {
|
|
2079
|
-
|
|
2080
|
-
|
|
2140
|
+
(sub_s: {
|
|
2141
|
+
$on?: { [k: string]: (utype_sub: (utype_sub_s: { $all: (_opts?: {}, collector?: {}) => any }) => any) => any };
|
|
2142
|
+
$all?: (_opts?: {}, collector?: {}) => any;
|
|
2143
|
+
}) => {
|
|
2144
|
+
if (sub_s.$all) {
|
|
2145
|
+
return sub_s.$all(opts, col);
|
|
2146
|
+
}
|
|
2147
|
+
if (sub_s.$on) {
|
|
2148
|
+
return Object.values(sub_s.$on).reduce(
|
|
2149
|
+
(sel, tselfn) => ({
|
|
2150
|
+
...sel,
|
|
2151
|
+
...tselfn(utype_sub_s => {
|
|
2152
|
+
return utype_sub_s.$all(opts, col);
|
|
2153
|
+
}),
|
|
2154
|
+
}),
|
|
2155
|
+
{}
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2081
2159
|
);
|
|
2082
2160
|
} else if (!k.startsWith("$")) {
|
|
2083
2161
|
console.warn(
|
|
@@ -2153,16 +2231,17 @@ export class SelectionWrapper<
|
|
|
2153
2231
|
return _SLFN as ReturnType<SLFN<T, F, N, TNP, TAD>>;
|
|
2154
2232
|
};
|
|
2155
2233
|
`;constructor(D,F,P,B){super(D,F,P,B);this.collector=F,this.options=P,this.authConfig=B}makeEnumType(){let D=this.originalTypeNameToTypescriptTypeNameWithoutModifiers(this.originalFullTypeName);if(this.collector.hasEnumType(this.typeMeta))return D;if(this.typeMeta.enumValues.length===0)console.warn(`Schema contains empty enum: ${this.typeMeta.name}.
|
|
2156
|
-
This is not allowed in GraphQL, but it happens. Please check your schema. Code is still generated and will work, but the type is being set to undefined.`);let F
|
|
2157
|
-
|
|
2234
|
+
This is not allowed in GraphQL, but it happens. Please check your schema. Code is still generated and will work, but the type is being set to undefined.`);let F=this.typeMeta.description?.split(`
|
|
2235
|
+
`).filter((B)=>B.startsWith("@property")).reduce((B,Z)=>{let q=Z.match(/@property \{"(.*?)"\} (.*?)$/),X=q?.[1],J=q?.[2];if(X&&J)B[X]=J;return B},{})??{},P=`
|
|
2236
|
+
export type ${D} = ${this.typeMeta.enumValues.length===0?"undefined":this.typeMeta.enumValues.map((B)=>`"${B.name}"`).join(" | ")};
|
|
2158
2237
|
export enum ${D}Enum {
|
|
2159
|
-
${this.typeMeta.enumValues.map((
|
|
2160
|
-
`:""}${
|
|
2238
|
+
${this.typeMeta.enumValues.map((B)=>{let Z=F[B.name];return`${B.description?`/** ${B.description} */
|
|
2239
|
+
`:""}${Z??B.name} = "${B.name}",`}).join(`
|
|
2161
2240
|
`)}
|
|
2162
2241
|
};
|
|
2163
|
-
`;return this.collector.addEnumType(this.typeMeta,
|
|
2242
|
+
`;return this.collector.addEnumType(this.typeMeta,P),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}`} */`:""}
|
|
2164
2243
|
${z}: ${I};`}).join(" ")} }`;this.collector.addArgumentType(X,`export type ${X} = ${Y};`)}return{argsTypeName:X,hasAtLeastOneNonNullArg:q}},Z=D.description?`/* ${D.description} */
|
|
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.
|
|
2244
|
+
`:"";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.originalTypeNameToTypescriptTypeNameWithoutModifiers(this.originalFullTypeName);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=`
|
|
2166
2245
|
export type ${D} = ${P};
|
|
2167
2246
|
`}else F=`
|
|
2168
2247
|
export type ${D} = {
|
|
@@ -2504,7 +2583,7 @@ export class SelectionWrapper<
|
|
|
2504
2583
|
const makeSubSelectionFn =
|
|
2505
2584
|
(
|
|
2506
2585
|
opFnArgs?: Exclude<
|
|
2507
|
-
Parameters<typeof fieldFn
|
|
2586
|
+
Parameters<Extract<typeof fieldFn, (args: any) => any>>[0],
|
|
2508
2587
|
(args: any) => any
|
|
2509
2588
|
>,
|
|
2510
2589
|
) =>
|
|
@@ -2518,7 +2597,7 @@ export class SelectionWrapper<
|
|
|
2518
2597
|
) => (s: typeof opFnSelectionCb) => unknown
|
|
2519
2598
|
)(opFnArgs);
|
|
2520
2599
|
|
|
2521
|
-
const fieldSlw = fieldSLFN(
|
|
2600
|
+
const fieldSlw = (fieldSLFN as Extract<typeof fieldSLFN, (args: any) => any>)(
|
|
2522
2601
|
opFnSelectionCb as any,
|
|
2523
2602
|
) as unknown as SelectionWrapperImpl<
|
|
2524
2603
|
typeof field,
|
|
@@ -2602,7 +2681,7 @@ export class SelectionWrapper<
|
|
|
2602
2681
|
}
|
|
2603
2682
|
return (
|
|
2604
2683
|
opFnArgs: Exclude<
|
|
2605
|
-
Parameters<typeof fieldFn
|
|
2684
|
+
Parameters<Extract<typeof fieldFn, (args: any) => any>>[0],
|
|
2606
2685
|
(args: any) => any
|
|
2607
2686
|
>,
|
|
2608
2687
|
) => {
|
|
@@ -4362,7 +4441,7 @@ export class SelectionWrapper<
|
|
|
4362
4441
|
export default __client__ as typeof __client__ & {
|
|
4363
4442
|
init: typeof __init__;
|
|
4364
4443
|
};
|
|
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(`
|
|
4444
|
+
`}}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||Y.isUnion).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(`
|
|
4366
4445
|
`)}}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(`
|
|
4367
4446
|
`)}}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(`
|
|
4368
4447
|
_____ _
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samarium.sdk/new",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"main": "bin/samarium",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"tabWidth": 4
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"bun-types": "^1.1.29"
|
|
47
|
-
"@samarium.sdk/make": "0.21.2"
|
|
46
|
+
"bun-types": "^1.1.29"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
49
|
"typescript": "^5.0.0"
|
|
51
50
|
},
|
|
52
51
|
"dependencies": {
|
|
52
|
+
"@samarium.sdk/make": "0.21.2",
|
|
53
53
|
"@inquirer/prompts": "^5.0.5",
|
|
54
54
|
"commander": "^11.1.0",
|
|
55
55
|
"detect-indent": "^7.0.1",
|