@samarium.sdk/new 0.25.0 → 0.25.2

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.
Files changed (2) hide show
  1. package/bin/samarium +252 -658
  2. package/package.json +2 -2
package/bin/samarium CHANGED
@@ -344,7 +344,7 @@ ${F.comment}`:F.comment}this.doc.range[2]=F.offset;break}default:this.errors.pus
344
344
  `)+1;while(F!==0)this.onNewLine(this.offset+F),F=this.source.indexOf(`
345
345
  `,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 X=[];for(let q=0;q<F.sep.length;++q){let J=F.sep[q];switch(J.type){case"newline":X.push(q);break;case"space":break;case"comment":if(J.indent>D.indent)X.length=0;break;default:X.length=0}}if(X.length>=2)Z=F.sep.splice(X[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(R0(F.start,"newline"))Object.assign(F,{key:null,sep:[this.sourceToken]});else{let X=y8(F.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:X,key:null,sep:[this.sourceToken]}]})}else if(F.value)D.items.push({start:[],key:null,sep:[this.sourceToken]});else if(R0(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(Vz(F.key)&&!R0(F.sep,"newline")){let X=y8(F.start),q=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:X,key:q,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(R0(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 X=this.flowScalar(this.type);if(B||F.value)D.items.push({start:Z,key:X,sep:[]}),this.onKeyLine=!0;else if(F.sep)this.stack.push(X);else Object.assign(F,{key:X,sep:[]}),this.onKeyLine=!0;return}default:{let X=this.startBlockValue(D);if(X){if(X.type==="block-seq"){if(!F.explicitKey&&F.sep&&!R0(F.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else if(P)D.items.push({start:Z});this.stack.push(X);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||R0(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=T5(P),Z=y8(B);Lz(D);let X=D.end.splice(1,D.end.length);X.push(this.sourceToken);let q={type:"block-map",offset:D.offset,indent:D.indent,items:[{start:Z,key:D,sep:X}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=q}else yield*this.lineEnd(D)}}flowScalar(D){if(this.onNewLine){let F=this.source.indexOf(`
346
346
  `)+1;while(F!==0)this.onNewLine(this.offset+F),F=this.source.indexOf(`
347
- `,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=T5(D),P=y8(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=T5(D),P=y8(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()}}}qg.Parser=wz});var uz=Q((Gg)=>{var jz=DP(),Yg=q1(),O1=J1(),Hg=UF(),Ug=t(),Wg=UP(),bz=WP();function Sz(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Wg.LineCounter||null,prettyErrors:F}}function Og(D,F={}){let{lineCounter:P,prettyErrors:B}=Sz(F),Z=new bz.Parser(P?.addNewLine),X=new jz.Composer(F),q=Array.from(X.compose(Z.parse(D)));if(B&&P)for(let J of q)J.errors.forEach(O1.prettifyError(D,P)),J.warnings.forEach(O1.prettifyError(D,P));if(q.length>0)return q;return Object.assign([],{empty:!0},X.streamInfo())}function Tz(D,F={}){let{lineCounter:P,prettyErrors:B}=Sz(F),Z=new bz.Parser(P?.addNewLine),X=new jz.Composer(F),q=null;for(let J of X.compose(Z.parse(D),!0,D.length))if(!q)q=J;else if(q.options.logLevel!=="silent"){q.errors.push(new O1.YAMLParseError(J.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(B&&P)q.errors.forEach(O1.prettifyError(D,P)),q.warnings.forEach(O1.prettifyError(D,P));return q}function zg(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=Tz(D,P);if(!Z)return null;if(Z.warnings.forEach((X)=>Hg.warn(Z.options.logLevel,X)),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 Qg(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(Ug.isDocument(D)&&!B)return D.toString(P);return new Yg.Document(D,B,P).toString(P)}Gg.parse=zg;Gg.parseAllDocuments=Og;Gg.parseDocument=Tz;Gg.stringify=Qg});var _z=Q((Ng)=>{var Eg=DP(),Kg=q1(),Ag=gF(),OP=J1(),Cg=p6(),I0=t(),Lg=O0(),Vg=CD(),wg=Q0(),jg=G0(),bg=b5(),Sg=HP(),Tg=UP(),ug=WP(),u5=uz(),Nz=c6();Ng.Composer=Eg.Composer;Ng.Document=Kg.Document;Ng.Schema=Ag.Schema;Ng.YAMLError=OP.YAMLError;Ng.YAMLParseError=OP.YAMLParseError;Ng.YAMLWarning=OP.YAMLWarning;Ng.Alias=Cg.Alias;Ng.isAlias=I0.isAlias;Ng.isCollection=I0.isCollection;Ng.isDocument=I0.isDocument;Ng.isMap=I0.isMap;Ng.isNode=I0.isNode;Ng.isPair=I0.isPair;Ng.isScalar=I0.isScalar;Ng.isSeq=I0.isSeq;Ng.Pair=Lg.Pair;Ng.Scalar=Vg.Scalar;Ng.YAMLMap=wg.YAMLMap;Ng.YAMLSeq=jg.YAMLSeq;Ng.CST=bg;Ng.Lexer=Sg.Lexer;Ng.LineCounter=Tg.LineCounter;Ng.Parser=ug.Parser;Ng.parse=u5.parse;Ng.parseAllDocuments=u5.parseAllDocuments;Ng.parseDocument=u5.parseDocument;Ng.stringify=u5.stringify;Ng.visit=Nz.visit;Ng.visitAsync=Nz.visitAsync});var G1={name:"@samarium.sdk/new",version:"0.25.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.ts",prepublishOnly:"bun run bundle",test:"bun test"},prettier:{tabWidth:4},devDependencies:{"bun-types":"^1.2.19","@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 hP=RD(fP(),1),{program:Ev,createCommand:Kv,createArgument:Av,createOption:Cv,CommanderError:Lv,InvalidArgumentError:Vv,InvalidOptionArgumentError:wv,Command:gP,Argument:jv,Option:bv,Help:Sv}=hP.default;var dH=RD(l2(),1);var E3=RD(l2(),1);class P0 extends Error{response;request;constructor(D,F){let P=`${P0.extractMessage(D)}: ${JSON.stringify({response:D,request:F})}`;super(P);if(Object.setPrototypeOf(this,P0.prototype),this.response=D,this.request=F,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,P0)}static extractMessage(D){return D.errors?.[0]?.message??`GraphQL Error (Code: ${String(D.status)})`}}var W7=(D)=>D.toUpperCase(),Q3=(D)=>{return typeof D==="function"?D():D},O7=(D,F)=>D.map((P,B)=>[P,F[B]]),x0=(D)=>{let F={};if(D instanceof Headers)F=_b(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},_b=(D)=>{let F={};return D.forEach((P,B)=>{F[B]=P}),F},NH=(D)=>{try{let F=D();if(kb(F))return F.catch((P)=>{return uH(P)});return F}catch(F){return uH(F)}},uH=(D)=>{if(D instanceof Error)return D;return Error(String(D))},kb=(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"},G3=(D)=>{throw Error(`Unhandled case: ${String(D)}`)},S6=(D)=>{return typeof D==="object"&&D!==null&&!Array.isArray(D)};var _H=(D,F)=>{return D.documents?D:{documents:D,requestHeaders:F,signal:void 0}};var kH=(D,F,P)=>{return D.query?D:{query:D,variables:F,requestHeaders:P,signal:void 0}};var hH=RD(l2(),1);var z7="Accept",R3="Content-Type",T6="application/json",I3="application/graphql-response+json";var Q7=(D)=>D.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),gH=(D)=>{let F=D.toLowerCase();return F.includes(I3)||F.includes(T6)},G7=(D)=>{try{if(Array.isArray(D))return{_tag:"Batch",executionResults:D.map(xH)};else if(S6(D))return{_tag:"Single",executionResult:xH(D)};else throw Error(`Invalid execution result: result is not object or array.
347
+ `,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=T5(D),P=y8(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=T5(D),P=y8(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()}}}qg.Parser=wz});var uz=Q((Gg)=>{var jz=DP(),Yg=q1(),O1=J1(),Hg=UF(),Ug=t(),Wg=UP(),bz=WP();function Sz(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Wg.LineCounter||null,prettyErrors:F}}function Og(D,F={}){let{lineCounter:P,prettyErrors:B}=Sz(F),Z=new bz.Parser(P?.addNewLine),X=new jz.Composer(F),q=Array.from(X.compose(Z.parse(D)));if(B&&P)for(let J of q)J.errors.forEach(O1.prettifyError(D,P)),J.warnings.forEach(O1.prettifyError(D,P));if(q.length>0)return q;return Object.assign([],{empty:!0},X.streamInfo())}function Tz(D,F={}){let{lineCounter:P,prettyErrors:B}=Sz(F),Z=new bz.Parser(P?.addNewLine),X=new jz.Composer(F),q=null;for(let J of X.compose(Z.parse(D),!0,D.length))if(!q)q=J;else if(q.options.logLevel!=="silent"){q.errors.push(new O1.YAMLParseError(J.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(B&&P)q.errors.forEach(O1.prettifyError(D,P)),q.warnings.forEach(O1.prettifyError(D,P));return q}function zg(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=Tz(D,P);if(!Z)return null;if(Z.warnings.forEach((X)=>Hg.warn(Z.options.logLevel,X)),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 Qg(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(Ug.isDocument(D)&&!B)return D.toString(P);return new Yg.Document(D,B,P).toString(P)}Gg.parse=zg;Gg.parseAllDocuments=Og;Gg.parseDocument=Tz;Gg.stringify=Qg});var _z=Q((Ng)=>{var Eg=DP(),Kg=q1(),Ag=gF(),OP=J1(),Cg=p6(),I0=t(),Lg=O0(),Vg=CD(),wg=Q0(),jg=G0(),bg=b5(),Sg=HP(),Tg=UP(),ug=WP(),u5=uz(),Nz=c6();Ng.Composer=Eg.Composer;Ng.Document=Kg.Document;Ng.Schema=Ag.Schema;Ng.YAMLError=OP.YAMLError;Ng.YAMLParseError=OP.YAMLParseError;Ng.YAMLWarning=OP.YAMLWarning;Ng.Alias=Cg.Alias;Ng.isAlias=I0.isAlias;Ng.isCollection=I0.isCollection;Ng.isDocument=I0.isDocument;Ng.isMap=I0.isMap;Ng.isNode=I0.isNode;Ng.isPair=I0.isPair;Ng.isScalar=I0.isScalar;Ng.isSeq=I0.isSeq;Ng.Pair=Lg.Pair;Ng.Scalar=Vg.Scalar;Ng.YAMLMap=wg.YAMLMap;Ng.YAMLSeq=jg.YAMLSeq;Ng.CST=bg;Ng.Lexer=Sg.Lexer;Ng.LineCounter=Tg.LineCounter;Ng.Parser=ug.Parser;Ng.parse=u5.parse;Ng.parseAllDocuments=u5.parseAllDocuments;Ng.parseDocument=u5.parseDocument;Ng.stringify=u5.stringify;Ng.visit=Nz.visit;Ng.visitAsync=Nz.visitAsync});var G1={name:"@samarium.sdk/new",version:"0.25.2",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.ts",prepublishOnly:"bun run bundle",test:"bun test"},prettier:{tabWidth:4},devDependencies:{"bun-types":"^1.2.19","@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 hP=RD(fP(),1),{program:Ev,createCommand:Kv,createArgument:Av,createOption:Cv,CommanderError:Lv,InvalidArgumentError:Vv,InvalidOptionArgumentError:wv,Command:gP,Argument:jv,Option:bv,Help:Sv}=hP.default;var dH=RD(l2(),1);var E3=RD(l2(),1);class P0 extends Error{response;request;constructor(D,F){let P=`${P0.extractMessage(D)}: ${JSON.stringify({response:D,request:F})}`;super(P);if(Object.setPrototypeOf(this,P0.prototype),this.response=D,this.request=F,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,P0)}static extractMessage(D){return D.errors?.[0]?.message??`GraphQL Error (Code: ${String(D.status)})`}}var W7=(D)=>D.toUpperCase(),Q3=(D)=>{return typeof D==="function"?D():D},O7=(D,F)=>D.map((P,B)=>[P,F[B]]),x0=(D)=>{let F={};if(D instanceof Headers)F=_b(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},_b=(D)=>{let F={};return D.forEach((P,B)=>{F[B]=P}),F},NH=(D)=>{try{let F=D();if(kb(F))return F.catch((P)=>{return uH(P)});return F}catch(F){return uH(F)}},uH=(D)=>{if(D instanceof Error)return D;return Error(String(D))},kb=(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"},G3=(D)=>{throw Error(`Unhandled case: ${String(D)}`)},S6=(D)=>{return typeof D==="object"&&D!==null&&!Array.isArray(D)};var _H=(D,F)=>{return D.documents?D:{documents:D,requestHeaders:F,signal:void 0}};var kH=(D,F,P)=>{return D.query?D:{query:D,variables:F,requestHeaders:P,signal:void 0}};var hH=RD(l2(),1);var z7="Accept",R3="Content-Type",T6="application/json",I3="application/graphql-response+json";var Q7=(D)=>D.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),gH=(D)=>{let F=D.toLowerCase();return F.includes(I3)||F.includes(T6)},G7=(D)=>{try{if(Array.isArray(D))return{_tag:"Batch",executionResults:D.map(xH)};else if(S6(D))return{_tag:"Single",executionResult:xH(D)};else throw Error(`Invalid execution result: result is not object or array.
348
348
  Got:
349
349
  ${String(D)}`)}catch(F){return F}},xH=(D)=>{if(typeof D!=="object"||D===null)throw Error("Invalid execution result: result is not object");let F=void 0,P=void 0,B=void 0;if("errors"in D){if(!S6(D.errors)&&!Array.isArray(D.errors))throw Error("Invalid execution result: errors is not plain object OR array");F=D.errors}if("data"in D){if(!S6(D.data)&&D.data!==null)throw Error("Invalid execution result: data is not plain object");P=D.data}if("extensions"in D){if(!S6(D.extensions))throw Error("Invalid execution result: extensions is not plain object");B=D.extensions}return{data:P,errors:F,extensions:B}},vH=(D)=>D._tag==="Batch"?D.executionResults.some(fH):fH(D.executionResult),fH=(D)=>Array.isArray(D.errors)?D.errors.length>0:Boolean(D.errors),R7=(D)=>{return typeof D==="object"&&D!==null&&"kind"in D&&D.kind===hH.Kind.OPERATION_DEFINITION};var yH=RD(l2(),1),mH=RD(l2(),1),xb=(D)=>{let F=void 0,P=D.definitions.filter(R7);if(P.length===1)F=P[0].name?.value;return F},fb=(D)=>{let F=!1,P=D.definitions.filter(R7);if(P.length===1)F=P[0].operation==="mutation";return F},u6=(D,F)=>{let P=typeof D==="string"?D:mH.print(D),B=!1,Z=void 0;if(F)return{expression:P,isMutation:B,operationName:Z};let X=NH(()=>typeof D==="string"?yH.parse(D):D);if(X instanceof Error)return{expression:P,isMutation:B,operationName:Z};return Z=xb(X),B=fb(X),{expression:P,operationName:Z,isMutation:B}};var $3=JSON;var M3=async(D)=>{let F={...D,method:D.request._tag==="Single"?D.request.document.isMutation?"POST":W7(D.method??"post"):D.request.hasMutations?"POST":W7(D.method??"post"),fetchOptions:{...D.fetchOptions,errorPolicy:D.fetchOptions.errorPolicy??"none"}},B=await gb(F.method)(F);if(!B.ok)return new P0({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 hb(B,D.fetchOptions.jsonSerializer??$3);if(Z instanceof Error)throw Z;let X={status:B.status,headers:B.headers};if(vH(Z)&&F.fetchOptions.errorPolicy==="none"){let q=Z._tag==="Batch"?{...Z.executionResults,...X}:{...Z.executionResult,...X};return new P0(q,{query:D.request._tag==="Single"?D.request.document.expression:D.request.query,variables:D.request.variables})}switch(Z._tag){case"Single":return{...X,...lH(F)(Z.executionResult)};case"Batch":return{...X,data:Z.executionResults.map(lH(F))};default:G3(Z)}},lH=(D)=>(F)=>{return{extensions:F.extensions,data:F.data,errors:D.fetchOptions.errorPolicy==="all"?F.errors:void 0}},hb=async(D,F)=>{let P=D.headers.get(R3),B=await D.text();if(P&&gH(P))return G7(F.parse(B));else return G7(B)},gb=(D)=>async(F)=>{let P=new Headers(F.headers),B=null,Z=void 0;if(!P.has(z7))P.set(z7,[I3,T6].join(", "));if(D==="POST"){if(Z=(F.fetchOptions.jsonSerializer??$3).stringify(vb(F)),typeof Z==="string"&&!P.has(R3))P.set(R3,T6)}else B=yb(F);let X={method:D,headers:P,body:Z,...F.fetchOptions},q=new URL(F.url),J=X;if(F.middleware){let H=await Promise.resolve(F.middleware({...X,url:F.url,operationName:F.request._tag==="Single"?F.request.document.operationName:void 0,variables:F.request.variables})),{url:U,...W}=H;q=new URL(U),J=W}if(B)B.forEach((H,U)=>{q.searchParams.append(U,H)});return await(F.fetch??fetch)(q,J)},vb=(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 O7(D.request.query,D.request.variables??[]).map(([F,P])=>({query:F,variables:P}));default:throw G3(D.request)}},yb=(D)=>{let F=D.fetchOptions.jsonSerializer??$3,P=new URLSearchParams;switch(D.request._tag){case"Single":{if(P.append("query",Q7(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((q)=>F.stringify(q))??[],Z=D.request.query.map(Q7),X=O7(Z,B).map(([q,J])=>({query:q,variables:J}));return P.append("query",F.stringify(X)),P}default:throw G3(D.request)}};class f0{url;requestConfig;constructor(D,F={}){this.url=D,this.requestConfig=F}rawRequest=async(...D)=>{let[F,P,B]=D,Z=kH(F,P,B),{headers:X,fetch:q=globalThis.fetch,method:J="POST",requestMiddleware:Y,responseMiddleware:H,excludeOperationName:U,...W}=this.requestConfig,{url:O}=this;if(Z.signal!==void 0)W.signal=Z.signal;let z=u6(Z.query,U),I=await M3({url:O,request:{_tag:"Single",document:z,variables:Z.variables},headers:{...x0(Q3(X)),...x0(Z.requestHeaders)},fetch:q,method:J,fetchOptions:W,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=cH(D,P,B),{headers:X,fetch:q=globalThis.fetch,method:J="POST",requestMiddleware:Y,responseMiddleware:H,excludeOperationName:U,...W}=this.requestConfig,{url:O}=this;if(Z.signal!==void 0)W.signal=Z.signal;let z=u6(Z.document,U),I=await M3({url:O,request:{_tag:"Single",document:z,variables:Z.variables},headers:{...x0(Q3(X)),...x0(Z.requestHeaders)},fetch:q,method:J,fetchOptions:W,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=_H(D,F),{headers:B,excludeOperationName:Z,...X}=this.requestConfig;if(P.signal!==void 0)X.signal=P.signal;let q=P.documents.map(({document:W})=>u6(W,Z)),J=q.map(({expression:W})=>W),Y=q.some(({isMutation:W})=>W),H=P.documents.map(({variables:W})=>W),U=await M3({url:this.url,request:{_tag:"Batch",operationName:void 0,query:J,hasMutations:Y,variables:H},headers:{...x0(Q3(B)),...x0(P.requestHeaders)},fetch:this.requestConfig.fetch??globalThis.fetch,method:this.requestConfig.method||"POST",fetchOptions:X,middleware:this.requestConfig.requestMiddleware});if(this.requestConfig.responseMiddleware)await this.requestConfig.responseMiddleware(U,{operationName:void 0,variables:H,url:this.url});if(U instanceof Error)throw U;return U.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 cH=(D,F,P)=>{return D.document?D:{document:D,variables:F,requestHeaders:P,signal:void 0}};async function h0(D,F){try{let B=await new f0(D).request(E3.getIntrospectionQuery(),void 0,new Headers(F?.map((X)=>X.split("="))));return E3.buildClientSchema(B)}catch(P){throw P}}import mb from"fs";var I7=async(D,F)=>{let P=await h0(D.url,D.headers),B=dH.printSchema(P);mb.writeFileSync(F,B)};var K3=RD(l2(),1),A3=RD(l2(),1),KD=RD(l2(),1),lb=Object.defineProperty,rH=(D,F)=>{for(var P in F)lb(D,P,{get:F[P],enumerable:!0,configurable:!0,set:(B)=>F[P]=()=>B})};class aH{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 Error("Method not implemented.")}}var cb=`const Proxy = globalThis.Proxy;
350
350
  Proxy.prototype = {};
@@ -355,12 +355,7 @@ function proxify(data: any, slw: any): any & ArrayLike<any> {
355
355
  get(target: any[], prop: PropertyKey, receiver: any): any {
356
356
  return Reflect.get(slw, prop, receiver);
357
357
  },
358
- set(
359
- target: any[],
360
- prop: PropertyKey,
361
- value: any,
362
- receiver: any,
363
- ): boolean {
358
+ set(target: any[], prop: PropertyKey, value: any, receiver: any): boolean {
364
359
  return Reflect.set(slw, prop, value, receiver);
365
360
  },
366
361
  has(target: any[], prop: PropertyKey): boolean {
@@ -370,13 +365,10 @@ function proxify(data: any, slw: any): any & ArrayLike<any> {
370
365
  return Reflect.deleteProperty(slw, prop);
371
366
  },
372
367
  ownKeys(target: any[]): ArrayLike<string | symbol> {
373
- return Reflect.ownKeys(slw);
368
+ return Reflect.ownKeys(target);
374
369
  },
375
- getOwnPropertyDescriptor(
376
- target: any[],
377
- prop: PropertyKey,
378
- ): PropertyDescriptor | undefined {
379
- return Reflect.getOwnPropertyDescriptor(slw, prop);
370
+ getOwnPropertyDescriptor(target: any[], prop: PropertyKey): PropertyDescriptor | undefined {
371
+ return Reflect.getOwnPropertyDescriptor(target, prop);
380
372
  },
381
373
  getPrototypeOf(target: any[]): object | null {
382
374
  // Return Array.prototype for better array-like behavior (e.g., instanceof Array)
@@ -398,9 +390,7 @@ export const _ = Symbol("_") as any;
398
390
  export const OPTIONS = Symbol("OPTIONS");
399
391
  export class RootOperation {
400
392
  public static authHeaderName = "[AUTH_HEADER_NAME]";
401
- private resolveFnOrPromisOrPrimitiveHeaders = (
402
- arg?: FnOrPromisOrPrimitive,
403
- ) => {
393
+ private resolveFnOrPromisOrPrimitiveHeaders = (arg?: FnOrPromisOrPrimitive) => {
404
394
  if (!arg) return undefined;
405
395
  let headers: Record<string, string> | undefined = undefined;
406
396
  if (typeof arg === "string") {
@@ -409,8 +399,7 @@ export class RootOperation {
409
399
  const tokenOrPromise = arg();
410
400
  if (tokenOrPromise instanceof Promise) {
411
401
  return tokenOrPromise.then((t) => {
412
- if (typeof t === "string")
413
- headers = { [RootOperation.authHeaderName]: t };
402
+ if (typeof t === "string") headers = { [RootOperation.authHeaderName]: t };
414
403
  else headers = t;
415
404
 
416
405
  return headers;
@@ -450,9 +439,7 @@ export class RootOperation {
450
439
  sseFetchTransform: undefined as unknown as (
451
440
  input: string | URL | globalThis.Request,
452
441
  init?: RequestInit,
453
- ) => Promise<
454
- [string | URL | globalThis.Request, RequestInit | undefined]
455
- >,
442
+ ) => Promise<[string | URL | globalThis.Request, RequestInit | undefined]>,
456
443
 
457
444
  _auth_fn: undefined as
458
445
  | (() => string | { [key: string]: string } | undefined)
@@ -468,10 +455,7 @@ export class RootOperation {
468
455
  };
469
456
 
470
457
  private utilSet = (obj: Record<string, any>, path: string[], value: any) =>
471
- path.reduce(
472
- (o, p, i, a) => (o[p] = a.length - 1 === i ? value : o[p] || {}),
473
- obj,
474
- );
458
+ path.reduce((o, p, i, a) => (o[p] = a.length - 1 === i ? value : o[p] || {}), obj);
475
459
 
476
460
  private rootCollector: OperationSelectionCollector | undefined = undefined;
477
461
  public registerRootCollector(collector: OperationSelectionCollector) {
@@ -482,16 +466,12 @@ export class RootOperation {
482
466
  throw new Error("RootOperation has no registered collector");
483
467
  }
484
468
 
485
- const authHeaders =
486
- await this.rootCollector.op!.resolveFnOrPromisOrPrimitiveHeaders(
487
- this.rootCollector.op!.authArg ??
488
- RootOperation[OPTIONS]._auth_fn,
489
- );
490
- const headersHeaders =
491
- await this.rootCollector.op!.resolveFnOrPromisOrPrimitiveHeaders(
492
- this.rootCollector.op!.headers ??
493
- RootOperation[OPTIONS].headers,
494
- );
469
+ const authHeaders = await this.rootCollector.op!.resolveFnOrPromisOrPrimitiveHeaders(
470
+ this.rootCollector.op!.authArg ?? RootOperation[OPTIONS]._auth_fn,
471
+ );
472
+ const headersHeaders = await this.rootCollector.op!.resolveFnOrPromisOrPrimitiveHeaders(
473
+ this.rootCollector.op!.headers ?? RootOperation[OPTIONS].headers,
474
+ );
495
475
 
496
476
  headers = {
497
477
  ...authHeaders,
@@ -499,19 +479,14 @@ export class RootOperation {
499
479
  ...headers,
500
480
  };
501
481
 
502
- type selection = ReturnType<
503
- typeof OperationSelectionCollector.prototype.renderSelections
504
- >;
482
+ type selection = ReturnType<typeof OperationSelectionCollector.prototype.renderSelections>;
505
483
  const operations: {
506
484
  [key: string]: {
507
485
  selection: selection;
508
486
  rootSlw: SelectionWrapperImpl<string, string, number, any>;
509
487
  };
510
488
  } = {};
511
- for (const [
512
- opName,
513
- opSelection,
514
- ] of this.rootCollector?.selections.entries()) {
489
+ for (const [opName, opSelection] of this.rootCollector?.selections.entries()) {
515
490
  if (opSelection[SLW_LAZY_FLAG]) continue;
516
491
 
517
492
  let rootSlw = opSelection;
@@ -537,14 +512,9 @@ export class RootOperation {
537
512
  (acc, [opName, { selection, rootSlw }]) => ({
538
513
  ...acc,
539
514
  [opName]: {
540
- opType: rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase() as
541
- | "subscription"
542
- | "query"
543
- | "mutation",
515
+ opType: rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase() as "subscription" | "query" | "mutation",
544
516
  query: \`\${rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase()} \${opName} \${
545
- selection.variableDefinitions.length
546
- ? \`(\${selection.variableDefinitions.join(", ")}) \`
547
- : ""
517
+ selection.variableDefinitions.length ? \`(\${selection.variableDefinitions.join(", ")}) \` : ""
548
518
  }\${selection.selection}\`,
549
519
  variables: selection.variables,
550
520
  fragments: selection.usedFragments,
@@ -590,8 +560,7 @@ export class RootOperation {
590
560
  const that = this;
591
561
  const generator = (async function* () {
592
562
  const [url, options] = (await (
593
- RootOperation[OPTIONS].sseFetchTransform ??
594
- ((url: string, options?: RequestInit) => [url, options])
563
+ RootOperation[OPTIONS].sseFetchTransform ?? ((url: string, options?: RequestInit) => [url, options])
595
564
  )("http://localhost:4000/graphql", {
596
565
  method: "POST",
597
566
  headers: {
@@ -630,8 +599,7 @@ export class RootOperation {
630
599
  const eventName = event.match(/^event: (.*)$/m)?.[1];
631
600
  const rawdata = event.match(/^data: (.*)$/m)?.[1];
632
601
 
633
- if ((eventName === null && rawdata === "") || !rawdata)
634
- continue;
602
+ if ((eventName === null && rawdata === "") || !rawdata) continue;
635
603
  if (eventName === "complete" || done) break;
636
604
 
637
605
  const parsed = JSON.parse(rawdata) as {
@@ -673,20 +641,17 @@ export class RootOperation {
673
641
  },
674
642
  headers: Record<string, string> = {},
675
643
  ) {
676
- const res = await (RootOperation[OPTIONS].fetcher ?? globalThis.fetch)(
677
- "[ENDPOINT]",
678
- {
679
- method: "POST",
680
- headers: {
681
- "Content-Type": "application/json",
682
- ...headers,
683
- },
684
- body: JSON.stringify({
685
- query: \`\${[...query.fragments.values()].join("\\n")}\\n \${query.query}\`.trim(),
686
- variables: query.variables,
687
- }),
644
+ const res = await (RootOperation[OPTIONS].fetcher ?? globalThis.fetch)("[ENDPOINT]", {
645
+ method: "POST",
646
+ headers: {
647
+ "Content-Type": "application/json",
648
+ ...headers,
688
649
  },
689
- );
650
+ body: JSON.stringify({
651
+ query: \`\${[...query.fragments.values()].join("\\n")}\\n \${query.query}\`.trim(),
652
+ variables: query.variables,
653
+ }),
654
+ });
690
655
  const result = (await res.json()) as { data: any; errors: any[] };
691
656
 
692
657
  const { data, errors } = result ?? {};
@@ -713,9 +678,7 @@ export type OperationSelectionCollectorRef = {
713
678
  export class OperationSelectionCollector {
714
679
  constructor(
715
680
  public readonly name?: string,
716
- public readonly parent?:
717
- | OperationSelectionCollector
718
- | OperationSelectionCollectorRef,
681
+ public readonly parent?: OperationSelectionCollector | OperationSelectionCollectorRef,
719
682
  public readonly op?: RootOperation,
720
683
  ) {
721
684
  if (op) op.registerRootCollector(this);
@@ -734,9 +697,7 @@ export class OperationSelectionCollector {
734
697
 
735
698
  public async execute(headers?: Record<string, string>) {
736
699
  if (!this.op) {
737
- throw new Error(
738
- "OperationSelectionCollector is not registered to a root operation",
739
- );
700
+ throw new Error("OperationSelectionCollector is not registered to a root operation");
740
701
  }
741
702
  this.operationResult = await this.op.execute(headers);
742
703
  this.executed = true;
@@ -746,14 +707,8 @@ export class OperationSelectionCollector {
746
707
  return this.executed;
747
708
  }
748
709
 
749
- public readonly selections = new Map<
750
- string,
751
- SelectionWrapperImpl<string, string, number, any>
752
- >();
753
- public registerSelection(
754
- id: string,
755
- selection: SelectionWrapperImpl<string, string, number, any, any>,
756
- ) {
710
+ public readonly selections = new Map<string, SelectionWrapperImpl<string, string, number, any>>();
711
+ public registerSelection(id: string, selection: SelectionWrapperImpl<string, string, number, any, any>) {
757
712
  this.selections.set(id, selection);
758
713
  }
759
714
 
@@ -761,12 +716,7 @@ export class OperationSelectionCollector {
761
716
  path: string[] = [],
762
717
  opVars: Record<string, any> = {},
763
718
  usedFragments: Map<string, string> = new Map(),
764
- renderOnlyTheseSelections: SelectionWrapperImpl<
765
- string,
766
- string,
767
- number,
768
- any
769
- >[] = [],
719
+ renderOnlyTheseSelections: SelectionWrapperImpl<string, string, number, any>[] = [],
770
720
  ) {
771
721
  const result: Record<string, string | undefined> = {};
772
722
  const varDefs: string[] = [];
@@ -775,9 +725,7 @@ export class OperationSelectionCollector {
775
725
  for (const [key, value] of [...this.selections.entries()].filter(
776
726
  ([k, v]) =>
777
727
  renderOnlyTheseSelections.length === 0 ||
778
- renderOnlyTheseSelections.find(
779
- (r) => r[SLW_UID] === v[SLW_UID],
780
- ),
728
+ renderOnlyTheseSelections.find((r) => r[SLW_UID] === v[SLW_UID]),
781
729
  )) {
782
730
  const subPath = [...path, key];
783
731
  const {
@@ -793,10 +741,7 @@ export class OperationSelectionCollector {
793
741
  varDefs.push(...fieldVarDefs);
794
742
 
795
743
  if (directiveRendered) {
796
- const {
797
- variableDefinitions: directiveVarDefs,
798
- variables: directiveVars,
799
- } = directiveRendered;
744
+ const { variableDefinitions: directiveVarDefs, variables: directiveVars } = directiveRendered;
800
745
 
801
746
  varDefs.push(...directiveVarDefs);
802
747
  Object.assign(variables, directiveVars);
@@ -807,38 +752,29 @@ export class OperationSelectionCollector {
807
752
 
808
753
  if (value[SLW_PARENT_COLLECTOR] === undefined) {
809
754
  if (directiveRendered) {
810
- result[key] =
811
- \`\${fieldSelection} \${directiveRendered.rendered}\`;
755
+ result[key] = \`\${fieldSelection} \${directiveRendered.rendered}\`;
812
756
  } else {
813
757
  result[key] = fieldSelection;
814
758
  }
815
- } else if (
816
- value[SLW_COLLECTOR] instanceof OperationSelectionCollector
817
- ) {
759
+ } else if (value[SLW_COLLECTOR] instanceof OperationSelectionCollector) {
818
760
  const {
819
761
  selection: subSelection,
820
762
  variableDefinitions: subVarDefs,
821
763
  variables: subVars,
822
- } = value[SLW_COLLECTOR].renderSelections(
823
- subPath,
824
- opVars,
825
- usedFragments,
826
- );
764
+ } = value[SLW_COLLECTOR].renderSelections(subPath, opVars, usedFragments);
827
765
 
828
766
  if (value[SLW_IS_ON_TYPE_FRAGMENT]) {
829
767
  if (directiveRendered) {
830
768
  result[key] =
831
769
  \`... on \${value[SLW_IS_ON_TYPE_FRAGMENT]} \${directiveRendered.rendered} \${subSelection}\`;
832
770
  } else {
833
- result[key] =
834
- \`... on \${value[SLW_IS_ON_TYPE_FRAGMENT]} \${subSelection}\`;
771
+ result[key] = \`... on \${value[SLW_IS_ON_TYPE_FRAGMENT]} \${subSelection}\`;
835
772
  }
836
773
  } else if (value[SLW_IS_FRAGMENT]) {
837
774
  const fragmentName = \`\${key}_\${subVarDefs.map((v) => v.split(":")[0].slice(1)).join("_")}\`;
838
775
 
839
776
  if (directiveRendered) {
840
- result[key] =
841
- \`...\${fragmentName} \${directiveRendered.rendered}\`;
777
+ result[key] = \`...\${fragmentName} \${directiveRendered.rendered}\`;
842
778
  } else {
843
779
  result[key] = \`...\${fragmentName}\`;
844
780
  }
@@ -847,14 +783,11 @@ export class OperationSelectionCollector {
847
783
  if (!usedFragments.has(fragmentName)) {
848
784
  usedFragments.set(fragmentName, fragment);
849
785
  } else if (usedFragments.get(fragmentName) !== fragment) {
850
- console.warn(
851
- \`Fragment \${fragmentName} is already defined with a different selection\`,
852
- );
786
+ console.warn(\`Fragment \${fragmentName} is already defined with a different selection\`);
853
787
  }
854
788
  } else {
855
789
  if (directiveRendered) {
856
- result[key] =
857
- \`\${fieldSelection} \${directiveRendered.rendered} \${subSelection}\`;
790
+ result[key] = \`\${fieldSelection} \${directiveRendered.rendered} \${subSelection}\`;
858
791
  } else {
859
792
  result[key] = \`\${fieldSelection} \${subSelection}\`;
860
793
  }
@@ -866,11 +799,8 @@ export class OperationSelectionCollector {
866
799
  }
867
800
  }
868
801
  let rendered = "{ ";
869
- for (const [key, value] of Object.entries(result).filter(
870
- ([k, v]) => v !== undefined,
871
- ) as [string, string][]) {
872
- const keyIsFieldName =
873
- value.startsWith(\`\${key} {\`) || value.startsWith(\`\${key} (\`);
802
+ for (const [key, value] of Object.entries(result).filter(([k, v]) => v !== undefined) as [string, string][]) {
803
+ const keyIsFieldName = value.startsWith(\`\${key} {\`) || value.startsWith(\`\${key} (\`);
874
804
  const isSubSelection = value.startsWith("{");
875
805
  const isOnType = value.startsWith("... on");
876
806
  const isFragment = value.startsWith("...");
@@ -891,17 +821,10 @@ export class OperationSelectionCollector {
891
821
  };
892
822
  }
893
823
 
894
- private utilGet = (obj: Record<string, any>, path: (string | number)[]) =>
895
- path.reduce((o, p) => o?.[p], obj);
896
- public getOperationResultPath<T>(
897
- path: (string | number)[] = [],
898
- _type?: string,
899
- opResultDataOverride?: any,
900
- ): T {
824
+ private utilGet = (obj: Record<string, any>, path: (string | number)[]) => path.reduce((o, p) => o?.[p], obj);
825
+ public getOperationResultPath<T>(path: (string | number)[] = [], _type?: string, opResultDataOverride?: any): T {
901
826
  if (!this.op) {
902
- throw new Error(
903
- "OperationSelectionCollector is not registered to a root operation",
904
- );
827
+ throw new Error("OperationSelectionCollector is not registered to a root operation");
905
828
  }
906
829
 
907
830
  let result = opResultDataOverride ?? this.operationResult;
@@ -920,25 +843,18 @@ export class OperationSelectionCollector {
920
843
  depth++;
921
844
  }
922
845
 
923
- const deepParse = (
924
- res: any | any[],
925
- depth: number,
926
- parse: (v: string) => any,
927
- ) => {
846
+ const deepParse = (res: any | any[], depth: number, parse: (v: string) => any) => {
928
847
  if (depth === 0) {
929
848
  return parse(res);
930
849
  }
931
- return res.map((rarr: any) =>
932
- deepParse(rarr, depth - 1, parse),
933
- );
850
+ return res.map((rarr: any) => deepParse(rarr, depth - 1, parse));
934
851
  };
935
852
 
936
853
  return deepParse(
937
854
  finalResult,
938
855
  depth,
939
- RootOperation[OPTIONS].scalars[
940
- type as keyof (typeof RootOperation)[typeof OPTIONS]["scalars"]
941
- ] ?? ((value: string) => JSON.parse(value)),
856
+ RootOperation[OPTIONS].scalars[type as keyof (typeof RootOperation)[typeof OPTIONS]["scalars"]] ??
857
+ ((value: string) => JSON.parse(value)),
942
858
  ) as T;
943
859
  }
944
860
 
@@ -970,13 +886,9 @@ export const SLW_OP_PATH = Symbol("SLW_OP_PATH");
970
886
  export const SLW_REGISTER_PATH = Symbol("SLW_REGISTER_PATH");
971
887
  export const SLW_RENDER_WITH_ARGS = Symbol("SLW_RENDER_WITH_ARGS");
972
888
 
973
- export const SLW_OP_RESULT_DATA_OVERRIDE = Symbol(
974
- "SLW_OP_RESULT_DATA_OVERRIDE",
975
- );
889
+ export const SLW_OP_RESULT_DATA_OVERRIDE = Symbol("SLW_OP_RESULT_DATA_OVERRIDE");
976
890
 
977
- export const SLW_RECREATE_VALUE_CALLBACK = Symbol(
978
- "SLW_RECREATE_VALUE_CALLBACK",
979
- );
891
+ export const SLW_RECREATE_VALUE_CALLBACK = Symbol("SLW_RECREATE_VALUE_CALLBACK");
980
892
  export const SLW_SETTER_DATA_OVERRIDE = Symbol("SLW_SETTER_DATA_OVERRIDE");
981
893
  export const SLW_NEEDS_CLONE = Symbol("SLW_NEEDS_CLONE");
982
894
 
@@ -990,10 +902,7 @@ export class SelectionWrapperImpl<
990
902
  argsT extends Record<string, any> | undefined = undefined,
991
903
  > {
992
904
  private generateUniqueId(): string {
993
- return (
994
- performance.now().toString(36) +
995
- Math.random().toString(36).substring(2)
996
- );
905
+ return performance.now().toString(36) + Math.random().toString(36).substring(2);
997
906
  }
998
907
  [SLW_CLONE](
999
908
  overrides: {
@@ -1019,15 +928,9 @@ export class SelectionWrapperImpl<
1019
928
  slw[SLW_IS_FRAGMENT] = this[SLW_IS_FRAGMENT];
1020
929
  slw[SLW_PARENT_SLW] = this[SLW_PARENT_SLW];
1021
930
  slw[SLW_OP_PATH] = overrides.SLW_OP_PATH ?? this[SLW_OP_PATH];
1022
- slw[SLW_SETTER_DATA_OVERRIDE] =
1023
- overrides.SLW_SETTER_DATA_OVERRIDE ??
1024
- this[SLW_SETTER_DATA_OVERRIDE];
931
+ slw[SLW_SETTER_DATA_OVERRIDE] = overrides.SLW_SETTER_DATA_OVERRIDE ?? this[SLW_SETTER_DATA_OVERRIDE];
1025
932
 
1026
- slw[SLW_NEEDS_CLONE] = overrides.SLW_NEEDS_CLONE
1027
- ? true
1028
- : this[SLW_NEEDS_CLONE]
1029
- ? false
1030
- : true;
933
+ slw[SLW_NEEDS_CLONE] = overrides.SLW_NEEDS_CLONE ? true : this[SLW_NEEDS_CLONE] ? false : true;
1031
934
 
1032
935
  if (overrides.OP_RESULT_DATA) {
1033
936
  slw[SLW_OP_RESULT_DATA_OVERRIDE] = overrides.OP_RESULT_DATA;
@@ -1093,9 +996,7 @@ export class SelectionWrapperImpl<
1093
996
  this[SLW_COLLECTOR] = collector;
1094
997
 
1095
998
  let rootCollector = collector;
1096
- while (
1097
- rootCollector?.parent instanceof OperationSelectionCollector
1098
- ) {
999
+ while (rootCollector?.parent instanceof OperationSelectionCollector) {
1099
1000
  rootCollector = rootCollector.parent;
1100
1001
  }
1101
1002
  if (rootCollector.parent && "ref" in rootCollector.parent) {
@@ -1113,20 +1014,14 @@ export class SelectionWrapperImpl<
1113
1014
  if (!this[SLW_OP_PATH]) this[SLW_OP_PATH] = path.join(".");
1114
1015
  }
1115
1016
  [SLW_RENDER_WITH_ARGS](opVars: Record<string, any> = {}) {
1116
- const renderArgsString = (
1117
- args: Record<string, any>,
1118
- argsMeta: Record<string, string>,
1119
- ) => {
1017
+ const renderArgsString = (args: Record<string, any>, argsMeta: Record<string, string>) => {
1120
1018
  const argToVarMap: Record<string, string> = {};
1121
1019
  let argsString = "(";
1122
1020
  const argsStringParts: string[] = [];
1123
1021
  for (const key of Object.keys(args)) {
1124
1022
  let varName = key;
1125
1023
  if (opVars[key] !== undefined) {
1126
- varName = \`\${key}_\${
1127
- Object.keys(opVars).filter((k) => k.startsWith(key))
1128
- .length
1129
- }\`;
1024
+ varName = \`\${key}_\${Object.keys(opVars).filter((k) => k.startsWith(key)).length}\`;
1130
1025
  argToVarMap[varName] = varName;
1131
1026
  args[varName] = args[key];
1132
1027
  argsMeta[varName] = argsMeta[key];
@@ -1150,19 +1045,14 @@ export class SelectionWrapperImpl<
1150
1045
  const args = this[SLW_DIRECTIVE_ARGS];
1151
1046
  const argsMeta = this[SLW_DIRECTIVE_ARGS_META]!;
1152
1047
 
1153
- const { argsString, argToVarMap } = renderArgsString(
1154
- args,
1155
- argsMeta,
1156
- );
1048
+ const { argsString, argToVarMap } = renderArgsString(args, argsMeta);
1157
1049
 
1158
1050
  directiveRender.rendered = \`@\${directive}\${Object.keys(args).length ? argsString : ""}\`;
1159
1051
  directiveRender.variables = args;
1160
- directiveRender.variableDefinitions = Object.keys(args).map(
1161
- (key) => {
1162
- const varName = argToVarMap[key] ?? key;
1163
- return \`$\${varName}: \${argsMeta[key]}\`;
1164
- },
1165
- );
1052
+ directiveRender.variableDefinitions = Object.keys(args).map((key) => {
1053
+ const varName = argToVarMap[key] ?? key;
1054
+ return \`$\${varName}: \${argsMeta[key]}\`;
1055
+ });
1166
1056
  } else {
1167
1057
  directiveRender.rendered = \`@\${directive}\`;
1168
1058
  }
@@ -1172,10 +1062,7 @@ export class SelectionWrapperImpl<
1172
1062
  const args = this[SLW_ARGS];
1173
1063
  const argsMeta = this[SLW_ARGS_META]!;
1174
1064
 
1175
- const { argsString, argToVarMap } = renderArgsString(
1176
- args,
1177
- argsMeta,
1178
- );
1065
+ const { argsString, argToVarMap } = renderArgsString(args, argsMeta);
1179
1066
  return {
1180
1067
  selection: \`\${this[SLW_FIELD_NAME]}\${Object.keys(args).length ? argsString : ""}\`,
1181
1068
  variables: args,
@@ -1184,9 +1071,7 @@ export class SelectionWrapperImpl<
1184
1071
  return \`$\${varName}: \${argsMeta[key]}\`;
1185
1072
  }),
1186
1073
 
1187
- directive: directiveRender.rendered
1188
- ? directiveRender
1189
- : undefined,
1074
+ directive: directiveRender.rendered ? directiveRender : undefined,
1190
1075
  };
1191
1076
  }
1192
1077
  return {
@@ -1204,9 +1089,7 @@ export class SelectionWrapper<
1204
1089
  typeArrDepth extends number,
1205
1090
  valueT extends any = any,
1206
1091
  argsT extends Record<string, any> | undefined = undefined,
1207
- > extends Proxy<
1208
- SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>
1209
- > {
1092
+ > extends Proxy<SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>> {
1210
1093
  constructor(
1211
1094
  fieldName?: fieldName,
1212
1095
  typeNamePure?: typeNamePure,
@@ -1219,13 +1102,7 @@ export class SelectionWrapper<
1219
1102
  reCreateValueCallback?: () => valueT,
1220
1103
  ) {
1221
1104
  super(
1222
- new SelectionWrapperImpl<
1223
- fieldName,
1224
- typeNamePure,
1225
- typeArrDepth,
1226
- valueT,
1227
- argsT
1228
- >(
1105
+ new SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>(
1229
1106
  fieldName,
1230
1107
  typeNamePure,
1231
1108
  typeArrDepth,
@@ -1237,65 +1114,53 @@ export class SelectionWrapper<
1237
1114
  reCreateValueCallback,
1238
1115
  ),
1239
1116
  (() => {
1240
- const getCache = (
1241
- t: SelectionWrapperImpl<
1242
- fieldName,
1243
- typeNamePure,
1244
- typeArrDepth,
1245
- valueT,
1246
- argsT
1247
- >,
1248
- ) => t[ROOT_OP_COLLECTOR]!.ref.cache;
1117
+ const getCache = (t: SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>) =>
1118
+ t[SLW_OP_RESULT_DATA_OVERRIDE]
1119
+ ? { data: new Map(), proxiedArray: new Map() }
1120
+ : t[ROOT_OP_COLLECTOR]!.ref.cache;
1249
1121
 
1250
1122
  const getResultDataForTarget = (
1251
- t: SelectionWrapperImpl<
1252
- fieldName,
1253
- typeNamePure,
1254
- typeArrDepth,
1255
- valueT,
1256
- argsT
1257
- >,
1123
+ t: SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>,
1258
1124
  overrideOpPath?: string,
1259
1125
  ): valueT | undefined => {
1260
1126
  const cache = getCache(t);
1261
1127
 
1262
- const path = overrideOpPath ?? t[SLW_OP_PATH] ?? "";
1263
- if (cache.data.has(path) && !t[SLW_NEEDS_CLONE])
1264
- return cache.data.get(path);
1128
+ const path = overrideOpPath ?? t[SLW_OP_PATH] ?? undefined;
1129
+ if (path && cache.data.has(path) && !t[SLW_NEEDS_CLONE]) return cache.data.get(path);
1265
1130
 
1266
- const data = t[
1267
- ROOT_OP_COLLECTOR
1268
- ]!.ref.getOperationResultPath<valueT>(
1269
- (path?.split(".") ?? []).map((p) =>
1270
- !isNaN(+p) ? +p : p,
1271
- ),
1131
+ const data = t[ROOT_OP_COLLECTOR]!.ref.getOperationResultPath<valueT>(
1132
+ (path?.split(".") ?? []).map((p) => (!isNaN(+p) ? +p : p)),
1272
1133
  t[SLW_FIELD_TYPENAME],
1273
1134
  t[SLW_OP_RESULT_DATA_OVERRIDE],
1274
1135
  );
1275
1136
 
1276
- cache.data.set(path, data);
1137
+ if (path) cache.data.set(path, data);
1277
1138
  return data;
1278
1139
  };
1279
1140
 
1280
1141
  return {
1281
1142
  // implement ProxyHandler methods
1282
- ownKeys() {
1143
+ ownKeys(target) {
1144
+ if (target[SLW_FIELD_ARR_DEPTH]) {
1145
+ return Reflect.ownKeys(new Array(target[SLW_FIELD_ARR_DEPTH]));
1146
+ }
1283
1147
  return Reflect.ownKeys(value ?? {});
1284
1148
  },
1285
1149
  getOwnPropertyDescriptor(target, prop) {
1286
- return Reflect.getOwnPropertyDescriptor(
1287
- value ?? {},
1288
- prop,
1289
- );
1150
+ if (target[SLW_FIELD_ARR_DEPTH]) {
1151
+ return Reflect.getOwnPropertyDescriptor(new Array(target[SLW_FIELD_ARR_DEPTH]), prop);
1152
+ }
1153
+ return Reflect.getOwnPropertyDescriptor(value ?? {}, prop);
1290
1154
  },
1291
1155
  has(target, prop) {
1292
- if (prop === Symbol.for("nodejs.util.inspect.custom"))
1293
- return true;
1156
+ if (prop === Symbol.for("nodejs.util.inspect.custom")) return true;
1294
1157
  if (prop === Symbol.iterator && typeArrDepth) {
1295
1158
  const dataArr = getResultDataForTarget(target);
1296
1159
  if (Array.isArray(dataArr)) return true;
1297
- if (dataArr === undefined || dataArr === null)
1298
- return false;
1160
+ if (dataArr === undefined || dataArr === null) return false;
1161
+ }
1162
+ if (target[SLW_FIELD_ARR_DEPTH]) {
1163
+ return Reflect.has(new Array(target[SLW_FIELD_ARR_DEPTH]), prop);
1299
1164
  }
1300
1165
 
1301
1166
  return Reflect.has(value ?? {}, prop);
@@ -1304,8 +1169,7 @@ export class SelectionWrapper<
1304
1169
  const pstr = String(p);
1305
1170
  if (
1306
1171
  typeof p === "symbol" &&
1307
- (pstr.startsWith("Symbol(SLW_") ||
1308
- pstr == "Symbol(ROOT_OP_COLLECTOR)")
1172
+ (pstr.startsWith("Symbol(SLW_") || pstr == "Symbol(ROOT_OP_COLLECTOR)")
1309
1173
  ) {
1310
1174
  return Reflect.set(target, p, newValue, receiver);
1311
1175
  }
@@ -1320,10 +1184,7 @@ export class SelectionWrapper<
1320
1184
  );
1321
1185
  },
1322
1186
  get: (target, prop) => {
1323
- if (
1324
- target[SLW_SETTER_DATA_OVERRIDE] &&
1325
- target[SLW_SETTER_DATA_OVERRIDE][prop]
1326
- ) {
1187
+ if (target[SLW_SETTER_DATA_OVERRIDE] && target[SLW_SETTER_DATA_OVERRIDE][prop]) {
1327
1188
  return target[SLW_SETTER_DATA_OVERRIDE][prop];
1328
1189
  }
1329
1190
  if (prop === "$lazy") {
@@ -1347,25 +1208,17 @@ export class SelectionWrapper<
1347
1208
  undefined,
1348
1209
  undefined,
1349
1210
  new RootOperation(
1350
- that[
1351
- ROOT_OP_COLLECTOR
1352
- ]!.ref.op!.authArg,
1353
- that[
1354
- ROOT_OP_COLLECTOR
1355
- ]!.ref.op!.headers,
1211
+ that[ROOT_OP_COLLECTOR]!.ref.op!.authArg,
1212
+ that[ROOT_OP_COLLECTOR]!.ref.op!.headers,
1356
1213
  ),
1357
1214
  ),
1358
1215
  };
1359
1216
 
1360
- const newThisCollector =
1361
- new OperationSelectionCollector(
1362
- undefined,
1363
- newRootOpCollectorRef,
1364
- );
1365
- const r =
1366
- that[SLW_RECREATE_VALUE_CALLBACK]?.bind(
1367
- newThisCollector,
1368
- )?.() ?? {};
1217
+ const newThisCollector = new OperationSelectionCollector(
1218
+ undefined,
1219
+ newRootOpCollectorRef,
1220
+ );
1221
+ const r = that[SLW_RECREATE_VALUE_CALLBACK]?.bind(newThisCollector)?.() ?? {};
1369
1222
 
1370
1223
  const newThat = new SelectionWrapper(
1371
1224
  that[SLW_FIELD_NAME],
@@ -1376,33 +1229,20 @@ export class SelectionWrapper<
1376
1229
  // only set parent collector, if 'that' had one,
1377
1230
  // the absence indicates, that 'that' is a scalar field
1378
1231
  // without a subselection!
1379
- that[SLW_PARENT_COLLECTOR]
1380
- ? newRootOpCollectorRef
1381
- : undefined,
1232
+ that[SLW_PARENT_COLLECTOR] ? newRootOpCollectorRef : undefined,
1382
1233
  that[SLW_ARGS],
1383
1234
  that[SLW_ARGS_META],
1384
1235
  );
1385
1236
  newThat[SLW_UID] = that[SLW_UID];
1386
1237
 
1387
- Object.keys(r!).forEach(
1388
- (key) =>
1389
- (newThat as valueT)[
1390
- key as keyof valueT
1391
- ],
1392
- );
1238
+ Object.keys(r!).forEach((key) => (newThat as valueT)[key as keyof valueT]);
1393
1239
 
1394
- newThat[SLW_IS_ROOT_TYPE] =
1395
- that[SLW_IS_ROOT_TYPE];
1396
- newThat[SLW_IS_ON_TYPE_FRAGMENT] =
1397
- that[SLW_IS_ON_TYPE_FRAGMENT];
1398
- newThat[SLW_IS_FRAGMENT] =
1399
- that[SLW_IS_FRAGMENT];
1240
+ newThat[SLW_IS_ROOT_TYPE] = that[SLW_IS_ROOT_TYPE];
1241
+ newThat[SLW_IS_ON_TYPE_FRAGMENT] = that[SLW_IS_ON_TYPE_FRAGMENT];
1242
+ newThat[SLW_IS_FRAGMENT] = that[SLW_IS_FRAGMENT];
1400
1243
 
1401
1244
  newThat[SLW_PARENT_SLW] = parentSlw;
1402
- parentSlw[SLW_COLLECTOR]?.registerSelection(
1403
- key,
1404
- newThat,
1405
- );
1245
+ parentSlw[SLW_COLLECTOR]?.registerSelection(key, newThat);
1406
1246
  newThat[SLW_ARGS] = {
1407
1247
  ...(that[SLW_ARGS] ?? {}),
1408
1248
  ...args,
@@ -1410,41 +1250,30 @@ export class SelectionWrapper<
1410
1250
 
1411
1251
  newThat[SLW_OP_PATH] = that[SLW_OP_PATH];
1412
1252
 
1413
- newRootOpCollectorRef.ref.registerSelection(
1414
- newThat[SLW_FIELD_NAME]!,
1415
- newThat,
1416
- );
1253
+ newRootOpCollectorRef.ref.registerSelection(newThat[SLW_FIELD_NAME]!, newThat);
1417
1254
 
1418
1255
  const resultProxy = new Proxy(
1419
1256
  {},
1420
1257
  {
1421
1258
  get(_t, _prop) {
1422
- const result = new Promise(
1423
- (resolve, reject) => {
1424
- newRootOpCollectorRef.ref
1425
- .execute()
1426
- .catch(reject)
1427
- .then((_data) => {
1428
- const data =
1429
- _data[
1430
- newThat[
1431
- SLW_FIELD_NAME
1432
- ]
1433
- ][
1434
- newThat[
1435
- SLW_FIELD_NAME
1436
- ]
1437
- ];
1438
-
1439
- resolve(
1440
- proxify(
1441
- data,
1442
- newThat as any,
1443
- ),
1444
- );
1445
- });
1446
- },
1447
- );
1259
+ const result = new Promise((resolve, reject) => {
1260
+ newRootOpCollectorRef.ref
1261
+ .execute()
1262
+ .catch(reject)
1263
+ .then((_data) => {
1264
+ const fieldName = newThat[SLW_FIELD_NAME]!;
1265
+ const d = _data[fieldName];
1266
+
1267
+ if (Symbol.asyncIterator in d) {
1268
+ return resolve(newThat);
1269
+ }
1270
+ if (typeof d === "object" && d && fieldName in d) {
1271
+ return resolve(proxify(d[fieldName], newThat as any));
1272
+ }
1273
+
1274
+ return resolve(proxify(d, newThat as any));
1275
+ });
1276
+ });
1448
1277
  if (String(_prop) === "then") {
1449
1278
  return result.then.bind(result);
1450
1279
  }
@@ -1458,12 +1287,8 @@ export class SelectionWrapper<
1458
1287
  {
1459
1288
  get(_t, _prop) {
1460
1289
  if (String(_prop) === "auth") {
1461
- return (
1462
- auth: FnOrPromisOrPrimitive,
1463
- ) => {
1464
- newRootOpCollectorRef.ref.op!.setAuth(
1465
- auth,
1466
- );
1290
+ return (auth: FnOrPromisOrPrimitive) => {
1291
+ newRootOpCollectorRef.ref.op!.setAuth(auth);
1467
1292
  return resultProxy;
1468
1293
  };
1469
1294
  }
@@ -1505,12 +1330,7 @@ export class SelectionWrapper<
1505
1330
  prop === SLW_NEEDS_CLONE
1506
1331
  ) {
1507
1332
  return target[
1508
- prop as keyof SelectionWrapperImpl<
1509
- fieldName,
1510
- typeNamePure,
1511
- typeArrDepth,
1512
- valueT
1513
- >
1333
+ prop as keyof SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT>
1514
1334
  ];
1515
1335
  }
1516
1336
  if (prop === SLW_VALUE) {
@@ -1520,41 +1340,35 @@ export class SelectionWrapper<
1520
1340
  return this;
1521
1341
  }
1522
1342
 
1523
- let slw_value = target[SLW_VALUE] as
1524
- | Record<string, any>
1525
- | undefined;
1343
+ let slw_value = target[SLW_VALUE] as Record<string, any> | undefined;
1526
1344
 
1527
1345
  if (target[ROOT_OP_COLLECTOR]?.ref.isExecuted) {
1528
1346
  if (prop === Symbol.asyncIterator) {
1529
- const asyncGenRootPath =
1530
- target[SLW_OP_PATH]?.split(".")?.[0];
1531
- const asyncGen = getResultDataForTarget(
1532
- target,
1533
- asyncGenRootPath,
1534
- ) as AsyncGenerator<valueT, any, any>;
1347
+ const asyncGenRootPath = target[SLW_OP_PATH]?.split(".")?.[0];
1348
+ const asyncGen = getResultDataForTarget(target, asyncGenRootPath) as AsyncGenerator<
1349
+ valueT,
1350
+ any,
1351
+ any
1352
+ >;
1535
1353
 
1536
1354
  return function () {
1537
1355
  return {
1538
1356
  next() {
1539
- return asyncGen
1540
- .next()
1541
- .then((val) => {
1542
- return {
1543
- done: val.done,
1544
- value: proxify(
1545
- val.value,
1546
- target[SLW_CLONE]({
1547
- SLW_OP_PATH:
1548
- asyncGenRootPath,
1549
- OP_RESULT_DATA:
1550
- val.value,
1551
-
1552
- // this is only for subscriptions
1553
- SLW_NEEDS_CLONE: true,
1554
- }),
1555
- ),
1556
- };
1557
- });
1357
+ return asyncGen.next().then((val) => {
1358
+ return {
1359
+ done: val.done,
1360
+ value: proxify(
1361
+ val.value,
1362
+ target[SLW_CLONE]({
1363
+ SLW_OP_PATH: asyncGenRootPath,
1364
+ OP_RESULT_DATA: val.value,
1365
+
1366
+ // this is only for subscriptions
1367
+ SLW_NEEDS_CLONE: true,
1368
+ }),
1369
+ ),
1370
+ };
1371
+ });
1558
1372
  },
1559
1373
  };
1560
1374
  };
@@ -1568,17 +1382,10 @@ export class SelectionWrapper<
1568
1382
  if (typeArrDepth && Array.isArray(_data)) {
1569
1383
  if (!isNaN(+String(prop))) {
1570
1384
  const elm = target[SLW_CLONE]({
1571
- SLW_OP_PATH:
1572
- path + "." + String(prop),
1573
- OP_RESULT_DATA:
1574
- target[
1575
- SLW_OP_RESULT_DATA_OVERRIDE
1576
- ],
1385
+ SLW_OP_PATH: path + "." + String(prop),
1386
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1577
1387
  });
1578
- return proxify(
1579
- _data[Number(prop)],
1580
- elm,
1581
- );
1388
+ return proxify(_data[Number(prop)], elm);
1582
1389
  }
1583
1390
 
1584
1391
  const data = _data as valueT[] | undefined;
@@ -1587,42 +1394,30 @@ export class SelectionWrapper<
1587
1394
  const cache = getCache(target);
1588
1395
 
1589
1396
  const proxiedData =
1590
- cache.proxiedArray.get(
1591
- target[SLW_OP_PATH]!,
1592
- ) ??
1593
- Array.from(
1594
- { length: data.length },
1595
- (_, i) =>
1596
- proxify(
1597
- data[i],
1598
- target[SLW_CLONE]({
1599
- SLW_OP_PATH:
1600
- target[
1601
- SLW_OP_PATH
1602
- ] +
1603
- "." +
1604
- String(i),
1605
- OP_RESULT_DATA:
1606
- target[
1607
- SLW_OP_RESULT_DATA_OVERRIDE
1608
- ],
1609
- }),
1610
- ),
1397
+ cache.proxiedArray.get(target[SLW_OP_PATH]!) ??
1398
+ Array.from({ length: data.length }, (_, i) =>
1399
+ typeof data[i] === "object"
1400
+ ? proxify(
1401
+ data[i],
1402
+ target[SLW_CLONE]({
1403
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1404
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1405
+ }),
1406
+ )
1407
+ : target[SLW_CLONE]({
1408
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1409
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1410
+ }),
1611
1411
  );
1612
1412
 
1613
1413
  if (!cache.proxiedArray.has(path)) {
1614
- cache.proxiedArray.set(
1615
- path,
1616
- proxiedData,
1617
- );
1414
+ cache.proxiedArray.set(path, proxiedData);
1618
1415
  }
1619
1416
 
1620
- const proto =
1621
- Object.getPrototypeOf(proxiedData);
1417
+ const proto = Object.getPrototypeOf(proxiedData);
1622
1418
  if (Object.hasOwn(proto, prop)) {
1623
1419
  const v = (proxiedData as any)[prop];
1624
- if (typeof v === "function")
1625
- return v.bind(proxiedData);
1420
+ if (typeof v === "function") return v.bind(proxiedData);
1626
1421
  return v;
1627
1422
  }
1628
1423
 
@@ -1639,8 +1434,7 @@ export class SelectionWrapper<
1639
1434
  const proto = Object.getPrototypeOf(data);
1640
1435
  if (Object.hasOwn(proto, prop)) {
1641
1436
  const v = (data as any)[prop];
1642
- if (typeof v === "function")
1643
- return v.bind(data);
1437
+ if (typeof v === "function") return v.bind(data);
1644
1438
  return v;
1645
1439
  }
1646
1440
 
@@ -1649,8 +1443,7 @@ export class SelectionWrapper<
1649
1443
 
1650
1444
  let slw = slw_value?.[String(prop)];
1651
1445
  let slwOpPathIsIndexAccessOrInArray = false;
1652
- let targetOpPathArr =
1653
- target[SLW_OP_PATH]?.split(".") ?? [];
1446
+ let targetOpPathArr = target[SLW_OP_PATH]?.split(".") ?? [];
1654
1447
  while (targetOpPathArr.length) {
1655
1448
  if (!isNaN(+targetOpPathArr.pop()!)) {
1656
1449
  slwOpPathIsIndexAccessOrInArray = true;
@@ -1660,8 +1453,7 @@ export class SelectionWrapper<
1660
1453
 
1661
1454
  if (
1662
1455
  slwOpPathIsIndexAccessOrInArray ||
1663
- (target[SLW_OP_RESULT_DATA_OVERRIDE] &&
1664
- !slw[SLW_OP_RESULT_DATA_OVERRIDE])
1456
+ (target[SLW_OP_RESULT_DATA_OVERRIDE] && !slw[SLW_OP_RESULT_DATA_OVERRIDE])
1665
1457
  ) {
1666
1458
  if (target[SLW_NEEDS_CLONE]) {
1667
1459
  // if the slw is flagged it needs to be cloned
@@ -1671,34 +1463,20 @@ export class SelectionWrapper<
1671
1463
  // we need a new object that doesn't reference
1672
1464
  // the other objects
1673
1465
  slw = slw[SLW_CLONE]({
1674
- SLW_OP_PATH:
1675
- target[SLW_OP_PATH] +
1676
- "." +
1677
- String(prop),
1678
- OP_RESULT_DATA:
1679
- target[SLW_OP_RESULT_DATA_OVERRIDE],
1466
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(prop),
1467
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1680
1468
  });
1681
1469
  } else {
1682
1470
  // index access detected, setting the op path
1683
1471
  // with the index (coming from the slw's parent (target))
1684
1472
  // it's in the parent because the parent was cloned before
1685
- slw[SLW_OP_PATH] =
1686
- target[SLW_OP_PATH] +
1687
- "." +
1688
- String(prop);
1689
- slw[SLW_OP_RESULT_DATA_OVERRIDE] =
1690
- target[SLW_OP_RESULT_DATA_OVERRIDE];
1473
+ slw[SLW_OP_PATH] = target[SLW_OP_PATH] + "." + String(prop);
1474
+ slw[SLW_OP_RESULT_DATA_OVERRIDE] = target[SLW_OP_RESULT_DATA_OVERRIDE];
1691
1475
  }
1692
1476
  }
1693
1477
 
1694
- if (
1695
- slw instanceof SelectionWrapperImpl &&
1696
- slw[SLW_FIELD_ARR_DEPTH]
1697
- ) {
1698
- const dataArr = getResultDataForTarget(slw) as
1699
- | unknown[]
1700
- | undefined
1701
- | null;
1478
+ if (slw instanceof SelectionWrapperImpl && slw[SLW_FIELD_ARR_DEPTH]) {
1479
+ const dataArr = getResultDataForTarget(slw) as unknown[] | undefined | null;
1702
1480
  if (dataArr === undefined) return undefined;
1703
1481
  if (dataArr === null) return null;
1704
1482
  if (!dataArr?.length) {
@@ -1709,10 +1487,7 @@ export class SelectionWrapper<
1709
1487
  return proxify(dataArr, slw);
1710
1488
  }
1711
1489
  } else if (slw instanceof SelectionWrapperImpl) {
1712
- const data = getResultDataForTarget(slw) as
1713
- | unknown
1714
- | undefined
1715
- | null;
1490
+ const data = getResultDataForTarget(slw) as unknown | undefined | null;
1716
1491
  if (data === undefined) return undefined;
1717
1492
  if (data === null) return null;
1718
1493
 
@@ -1732,18 +1507,13 @@ export class SelectionWrapper<
1732
1507
 
1733
1508
  if (
1734
1509
  Object.hasOwn(slw_value ?? {}, String(prop)) &&
1735
- slw_value?.[String(prop)] instanceof
1736
- SelectionWrapperImpl
1510
+ slw_value?.[String(prop)] instanceof SelectionWrapperImpl
1737
1511
  ) {
1738
1512
  if (target[SLW_COLLECTOR]) {
1739
- target[SLW_COLLECTOR].registerSelection(
1740
- String(prop),
1741
- slw_value[String(prop)],
1742
- );
1513
+ target[SLW_COLLECTOR].registerSelection(String(prop), slw_value[String(prop)]);
1743
1514
  }
1744
1515
  if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
1745
- slw_value[String(prop)][SLW_PARENT_SLW] =
1746
- target;
1516
+ slw_value[String(prop)][SLW_PARENT_SLW] = target;
1747
1517
  }
1748
1518
  }
1749
1519
  if (slw_value?.[String(prop)]?.[SLW_LAZY_FLAG]) {
@@ -1753,8 +1523,7 @@ export class SelectionWrapper<
1753
1523
  parentSlw: target,
1754
1524
  key: String(prop),
1755
1525
  });
1756
- slw_value[String(prop)][SLW_PARENT_SLW] =
1757
- target;
1526
+ slw_value[String(prop)][SLW_PARENT_SLW] = target;
1758
1527
  slw_value[String(prop)][SLW_LAZY_FLAG] = true;
1759
1528
  }
1760
1529
  }
@@ -2930,10 +2699,7 @@ export class RootOperation {
2930
2699
  };
2931
2700
 
2932
2701
  private utilSet = (obj: Record<string, any>, path: string[], value: any) =>
2933
- path.reduce(
2934
- (o, p, i, a) => (o[p] = a.length - 1 === i ? value : o[p] || {}),
2935
- obj,
2936
- );
2702
+ path.reduce((o, p, i, a) => (o[p] = a.length - 1 === i ? value : o[p] || {}), obj);
2937
2703
 
2938
2704
  private rootCollector: OperationSelectionCollector | undefined = undefined;
2939
2705
  public registerRootCollector(collector: OperationSelectionCollector) {
@@ -2944,26 +2710,18 @@ export class RootOperation {
2944
2710
  throw new Error("RootOperation has no registered collector");
2945
2711
  }
2946
2712
 
2947
- type selection = ReturnType<
2948
- typeof OperationSelectionCollector.prototype.renderSelections
2949
- >;
2713
+ type selection = ReturnType<typeof OperationSelectionCollector.prototype.renderSelections>;
2950
2714
  const operations: {
2951
2715
  [key: string]: {
2952
2716
  selection: selection;
2953
2717
  rootSlw: SelectionWrapperImpl<string, string, number, any>;
2954
2718
  };
2955
2719
  } = {};
2956
- for (const [
2957
- opName,
2958
- opSelection,
2959
- ] of this.rootCollector?.selections.entries()) {
2720
+ for (const [opName, opSelection] of this.rootCollector?.selections.entries()) {
2960
2721
  if (opSelection[SLW_LAZY_FLAG]) continue;
2961
2722
 
2962
2723
  const rootSlw = opSelection;
2963
- const selection = rootSlw[SLW_PARENT_COLLECTOR]!.renderSelections(
2964
- [],
2965
- [rootSlw],
2966
- );
2724
+ const selection = rootSlw[SLW_PARENT_COLLECTOR]!.renderSelections([], [rootSlw]);
2967
2725
 
2968
2726
  operations[opName] = {
2969
2727
  selection,
@@ -2973,15 +2731,13 @@ export class RootOperation {
2973
2731
 
2974
2732
  const ops = Object.entries(operations).reduce(
2975
2733
  (acc, [opName, { selection, rootSlw }]) => {
2976
- const bodyVarDefCount = Object.entries(
2977
- selection.variableDefinitions,
2978
- ).filter(([_, v]) => v.location === "body").length;
2734
+ const bodyVarDefCount = Object.entries(selection.variableDefinitions).filter(
2735
+ ([_, v]) => v.location === "body",
2736
+ ).length;
2979
2737
  const body =
2980
2738
  bodyVarDefCount === 0
2981
2739
  ? undefined
2982
- : bodyVarDefCount === 1 &&
2983
- Object.keys(selection.variableDefinitions)
2984
- .length === 1
2740
+ : bodyVarDefCount === 1 && Object.keys(selection.variableDefinitions).length === 1
2985
2741
  ? selection.variables
2986
2742
  : bodyVarDefCount === 1 &&
2987
2743
  "$body" in selection.variableDefinitions &&
@@ -2990,10 +2746,7 @@ export class RootOperation {
2990
2746
  : Object.fromEntries(
2991
2747
  Object.entries(selection.variableDefinitions)
2992
2748
  .filter(([_, v]) => v.location === "body")
2993
- .map(([k, _]) => [
2994
- k,
2995
- selection.variables[k],
2996
- ]),
2749
+ .map(([k, _]) => [k, selection.variables[k]]),
2997
2750
  );
2998
2751
 
2999
2752
  return {
@@ -3010,18 +2763,12 @@ export class RootOperation {
3010
2763
  path: Object.fromEntries(
3011
2764
  Object.entries(selection.variableDefinitions)
3012
2765
  .filter(([_, v]) => v.location === "path")
3013
- .map(([k, v]) => [
3014
- k,
3015
- selection.variables[k],
3016
- ]),
2766
+ .map(([k, v]) => [k, selection.variables[k]]),
3017
2767
  ),
3018
2768
  query: Object.fromEntries(
3019
2769
  Object.entries(selection.variableDefinitions)
3020
2770
  .filter(([_, v]) => v.location === "query")
3021
- .map(([k, v]) => [
3022
- k,
3023
- selection.variables[k],
3024
- ]),
2771
+ .map(([k, v]) => [k, selection.variables[k]]),
3025
2772
  ),
3026
2773
  },
3027
2774
  body,
@@ -3037,15 +2784,7 @@ export class RootOperation {
3037
2784
  string,
3038
2785
  {
3039
2786
  path: string;
3040
- method:
3041
- | "get"
3042
- | "post"
3043
- | "put"
3044
- | "delete"
3045
- | "patch"
3046
- | "head"
3047
- | "options"
3048
- | "trace";
2787
+ method: "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "trace";
3049
2788
  header: Record<string, any>;
3050
2789
  params: {
3051
2790
  path: Record<string, any>;
@@ -3061,11 +2800,7 @@ export class RootOperation {
3061
2800
  const results = Object.fromEntries(
3062
2801
  await Promise.all([
3063
2802
  ...Object.entries(ops).map(
3064
- async ([opName, op]) =>
3065
- [
3066
- opName,
3067
- await this.executeOperation(op, headers),
3068
- ] as const,
2803
+ async ([opName, op]) => [opName, await this.executeOperation(op, headers)] as const,
3069
2804
  ),
3070
2805
  ]),
3071
2806
  );
@@ -3076,15 +2811,7 @@ export class RootOperation {
3076
2811
  private async executeOperation(
3077
2812
  request: {
3078
2813
  path: string;
3079
- method:
3080
- | "get"
3081
- | "post"
3082
- | "put"
3083
- | "delete"
3084
- | "patch"
3085
- | "head"
3086
- | "options"
3087
- | "trace";
2814
+ method: "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "trace";
3088
2815
  header: Record<string, any>;
3089
2816
  params: {
3090
2817
  path: Record<string, any>;
@@ -3100,9 +2827,7 @@ export class RootOperation {
3100
2827
  });
3101
2828
  const finalQuery = new URLSearchParams(request.params.query).toString();
3102
2829
  // remove the '{?arg1, arg2, ...}' part from the finalPath and add the finalQuery to the end
3103
- finalPath = \`\${finalPath.replace(/\\{.*?\\}$/, "")}\${
3104
- finalQuery ? \`?\${finalQuery}\` : ""
3105
- }\`;
2830
+ finalPath = \`\${finalPath.replace(/\\{.*?\\}$/, "")}\${finalQuery ? \`?\${finalQuery}\` : ""}\`;
3106
2831
  const cookies = new URLSearchParams(request.cookie).toString();
3107
2832
 
3108
2833
  const res = await fetch(\`[ENDPOINT]\${finalPath}\`, {
@@ -3132,9 +2857,7 @@ export type OperationSelectionCollectorRef = {
3132
2857
  export class OperationSelectionCollector {
3133
2858
  constructor(
3134
2859
  public readonly name?: string,
3135
- public readonly parent?:
3136
- | OperationSelectionCollector
3137
- | OperationSelectionCollectorRef,
2860
+ public readonly parent?: OperationSelectionCollector | OperationSelectionCollectorRef,
3138
2861
  public readonly op?: RootOperation,
3139
2862
  ) {
3140
2863
  if (op) op.registerRootCollector(this);
@@ -3142,13 +2865,9 @@ export class OperationSelectionCollector {
3142
2865
 
3143
2866
  private executed = false;
3144
2867
  private operationResult: any | undefined = undefined;
3145
- public async execute(
3146
- headers: Record<string, string> = RootOperation[OPTIONS].headers,
3147
- ) {
2868
+ public async execute(headers: Record<string, string> = RootOperation[OPTIONS].headers) {
3148
2869
  if (!this.op) {
3149
- throw new Error(
3150
- "OperationSelectionCollector is not registered to a root operation",
3151
- );
2870
+ throw new Error("OperationSelectionCollector is not registered to a root operation");
3152
2871
  }
3153
2872
  this.operationResult = await this.op.execute(headers);
3154
2873
  this.executed = true;
@@ -3157,25 +2876,14 @@ export class OperationSelectionCollector {
3157
2876
  return this.executed;
3158
2877
  }
3159
2878
 
3160
- public readonly selections = new Map<
3161
- string,
3162
- SelectionWrapperImpl<string, string, number, any>
3163
- >();
3164
- public registerSelection(
3165
- id: string,
3166
- selection: SelectionWrapperImpl<string, string, number, any, any>,
3167
- ) {
2879
+ public readonly selections = new Map<string, SelectionWrapperImpl<string, string, number, any>>();
2880
+ public registerSelection(id: string, selection: SelectionWrapperImpl<string, string, number, any, any>) {
3168
2881
  this.selections.set(id, selection);
3169
2882
  }
3170
2883
 
3171
2884
  public renderSelections(
3172
2885
  path: string[] = [],
3173
- renderOnlyTheseSelections: SelectionWrapperImpl<
3174
- string,
3175
- string,
3176
- number,
3177
- any
3178
- >[] = [],
2886
+ renderOnlyTheseSelections: SelectionWrapperImpl<string, string, number, any>[] = [],
3179
2887
  ) {
3180
2888
  const varDefs: Record<
3181
2889
  string,
@@ -3189,13 +2897,10 @@ export class OperationSelectionCollector {
3189
2897
  for (const [key, value] of [...this.selections.entries()].filter(
3190
2898
  ([k, v]) =>
3191
2899
  renderOnlyTheseSelections.length === 0 ||
3192
- renderOnlyTheseSelections.find(
3193
- (r) => r[SLW_UID] === v[SLW_UID],
3194
- ),
2900
+ renderOnlyTheseSelections.find((r) => r[SLW_UID] === v[SLW_UID]),
3195
2901
  )) {
3196
2902
  const subPath = [...path, key];
3197
- const { variableDefinitions: fieldVarDefs, variables: fieldVars } =
3198
- value[SLW_RENDER_WITH_ARGS]();
2903
+ const { variableDefinitions: fieldVarDefs, variables: fieldVars } = value[SLW_RENDER_WITH_ARGS]();
3199
2904
 
3200
2905
  Object.assign(variables, fieldVars);
3201
2906
  Object.assign(varDefs, fieldVarDefs);
@@ -3204,9 +2909,7 @@ export class OperationSelectionCollector {
3204
2909
 
3205
2910
  if (value[SLW_PARENT_COLLECTOR] === undefined) {
3206
2911
  // do nothing
3207
- } else if (
3208
- value[SLW_COLLECTOR] instanceof OperationSelectionCollector
3209
- ) {
2912
+ } else if (value[SLW_COLLECTOR] instanceof OperationSelectionCollector) {
3210
2913
  const { variableDefinitions: subVarDefs, variables: subVars } =
3211
2914
  value[SLW_COLLECTOR].renderSelections(subPath);
3212
2915
 
@@ -3221,16 +2924,10 @@ export class OperationSelectionCollector {
3221
2924
  };
3222
2925
  }
3223
2926
 
3224
- private utilGet = (obj: Record<string, any>, path: (string | number)[]) =>
3225
- path.reduce((o, p) => o?.[p], obj);
3226
- public getOperationResultPath<T>(
3227
- path: (string | number)[] = [],
3228
- type?: string,
3229
- ): T {
2927
+ private utilGet = (obj: Record<string, any>, path: (string | number)[]) => path.reduce((o, p) => o?.[p], obj);
2928
+ public getOperationResultPath<T>(path: (string | number)[] = [], type?: string): T {
3230
2929
  if (!this.op) {
3231
- throw new Error(
3232
- "OperationSelectionCollector is not registered to a root operation",
3233
- );
2930
+ throw new Error("OperationSelectionCollector is not registered to a root operation");
3234
2931
  }
3235
2932
 
3236
2933
  let result = this.operationResult;
@@ -3248,25 +2945,17 @@ export class OperationSelectionCollector {
3248
2945
  depth++;
3249
2946
  }
3250
2947
 
3251
- const deepParse = (
3252
- res: any | any[],
3253
- depth: number,
3254
- parse: (v: string) => any,
3255
- ) => {
2948
+ const deepParse = (res: any | any[], depth: number, parse: (v: string) => any) => {
3256
2949
  if (depth === 0) {
3257
2950
  return parse(res);
3258
2951
  }
3259
- return res.map((rarr: any) =>
3260
- deepParse(rarr, depth - 1, parse),
3261
- );
2952
+ return res.map((rarr: any) => deepParse(rarr, depth - 1, parse));
3262
2953
  };
3263
2954
 
3264
2955
  return deepParse(
3265
2956
  finalResult,
3266
2957
  depth,
3267
- RootOperation[OPTIONS].scalars[
3268
- type as keyof (typeof RootOperation)[typeof OPTIONS]["scalars"]
3269
- ],
2958
+ RootOperation[OPTIONS].scalars[type as keyof (typeof RootOperation)[typeof OPTIONS]["scalars"]],
3270
2959
  ) as T;
3271
2960
  }
3272
2961
 
@@ -3295,9 +2984,7 @@ export const SLW_OP_PATH = Symbol("SLW_OP_PATH");
3295
2984
  export const SLW_REGISTER_PATH = Symbol("SLW_REGISTER_PATH");
3296
2985
  export const SLW_RENDER_WITH_ARGS = Symbol("SLW_RENDER_WITH_ARGS");
3297
2986
 
3298
- export const SLW_RECREATE_VALUE_CALLBACK = Symbol(
3299
- "SLW_RECREATE_VALUE_CALLBACK",
3300
- );
2987
+ export const SLW_RECREATE_VALUE_CALLBACK = Symbol("SLW_RECREATE_VALUE_CALLBACK");
3301
2988
 
3302
2989
  export const SLW_CLONE = Symbol("SLW_CLONE");
3303
2990
 
@@ -3312,10 +2999,7 @@ export class SelectionWrapperImpl<
3312
2999
  argsT extends Record<string, any> | any | undefined = undefined,
3313
3000
  > {
3314
3001
  private generateUniqueId(): string {
3315
- return (
3316
- performance.now().toString(36) +
3317
- Math.random().toString(36).substring(2)
3318
- );
3002
+ return performance.now().toString(36) + Math.random().toString(36).substring(2);
3319
3003
  }
3320
3004
  [SLW_CLONE](
3321
3005
  overrides: {
@@ -3352,15 +3036,7 @@ export class SelectionWrapperImpl<
3352
3036
 
3353
3037
  [ROOT_OP_META]?: {
3354
3038
  path: string;
3355
- method:
3356
- | "get"
3357
- | "post"
3358
- | "put"
3359
- | "delete"
3360
- | "patch"
3361
- | "head"
3362
- | "options"
3363
- | "trace";
3039
+ method: "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "trace";
3364
3040
  };
3365
3041
 
3366
3042
  [SLW_ARGS]?: argsT;
@@ -3415,9 +3091,7 @@ export class SelectionWrapperImpl<
3415
3091
  this[SLW_COLLECTOR] = collector;
3416
3092
 
3417
3093
  let rootCollector = collector;
3418
- while (
3419
- rootCollector?.parent instanceof OperationSelectionCollector
3420
- ) {
3094
+ while (rootCollector?.parent instanceof OperationSelectionCollector) {
3421
3095
  rootCollector = rootCollector.parent;
3422
3096
  }
3423
3097
  if (rootCollector.parent && "ref" in rootCollector.parent) {
@@ -3452,7 +3126,7 @@ export class SelectionWrapperImpl<
3452
3126
  return {
3453
3127
  variables: args ?? {},
3454
3128
  variableDefinitions: argsMeta?.["$body"]
3455
- ? argsMeta ?? {}
3129
+ ? (argsMeta ?? {})
3456
3130
  : args
3457
3131
  ? Object.keys(args).reduce(
3458
3132
  (acc, key) => {
@@ -3463,12 +3137,7 @@ export class SelectionWrapperImpl<
3463
3137
  string,
3464
3138
  {
3465
3139
  type: string;
3466
- location:
3467
- | "path"
3468
- | "query"
3469
- | "header"
3470
- | "cookie"
3471
- | "body";
3140
+ location: "path" | "query" | "header" | "cookie" | "body";
3472
3141
  }
3473
3142
  >,
3474
3143
  )
@@ -3493,9 +3162,7 @@ export class SelectionWrapper<
3493
3162
  typeArrDepth extends number,
3494
3163
  valueT extends any = any,
3495
3164
  argsT extends Record<string, any> | any | undefined = undefined,
3496
- > extends Proxy<
3497
- SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>
3498
- > {
3165
+ > extends Proxy<SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>> {
3499
3166
  constructor(
3500
3167
  fieldName?: fieldName,
3501
3168
  typeNamePure?: typeNamePure,
@@ -3515,13 +3182,7 @@ export class SelectionWrapper<
3515
3182
  isScalarOp?: boolean,
3516
3183
  ) {
3517
3184
  super(
3518
- new SelectionWrapperImpl<
3519
- fieldName,
3520
- typeNamePure,
3521
- typeArrDepth,
3522
- valueT,
3523
- argsT
3524
- >(
3185
+ new SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>(
3525
3186
  fieldName,
3526
3187
  typeNamePure,
3527
3188
  typeArrDepth,
@@ -3542,8 +3203,7 @@ export class SelectionWrapper<
3542
3203
  return Reflect.getOwnPropertyDescriptor(value ?? {}, prop);
3543
3204
  },
3544
3205
  has(target, prop) {
3545
- if (prop === Symbol.for("nodejs.util.inspect.custom"))
3546
- return true;
3206
+ if (prop === Symbol.for("nodejs.util.inspect.custom")) return true;
3547
3207
  return Reflect.has(value ?? {}, prop);
3548
3208
  },
3549
3209
  get: (target, prop) => {
@@ -3551,35 +3211,18 @@ export class SelectionWrapper<
3551
3211
  const that = this;
3552
3212
  function lazy(
3553
3213
  this: {
3554
- parentSlw: SelectionWrapperImpl<
3555
- fieldName,
3556
- typeNamePure,
3557
- typeArrDepth,
3558
- valueT,
3559
- argsT
3560
- >;
3214
+ parentSlw: SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>;
3561
3215
  key: string;
3562
3216
  },
3563
3217
  args?: argsT,
3564
3218
  ) {
3565
3219
  const { parentSlw, key } = this;
3566
3220
  const newRootOpCollectorRef = {
3567
- ref: new OperationSelectionCollector(
3568
- undefined,
3569
- undefined,
3570
- new RootOperation(),
3571
- ),
3221
+ ref: new OperationSelectionCollector(undefined, undefined, new RootOperation()),
3572
3222
  };
3573
3223
 
3574
- const newThisCollector =
3575
- new OperationSelectionCollector(
3576
- undefined,
3577
- newRootOpCollectorRef,
3578
- );
3579
- const r =
3580
- that[SLW_RECREATE_VALUE_CALLBACK]?.bind(
3581
- newThisCollector,
3582
- )();
3224
+ const newThisCollector = new OperationSelectionCollector(undefined, newRootOpCollectorRef);
3225
+ const r = that[SLW_RECREATE_VALUE_CALLBACK]?.bind(newThisCollector)();
3583
3226
 
3584
3227
  const newThat = new SelectionWrapper(
3585
3228
  that[SLW_FIELD_NAME],
@@ -3593,18 +3236,12 @@ export class SelectionWrapper<
3593
3236
  that[SLW_RECREATE_VALUE_CALLBACK],
3594
3237
  that[SLW_IS_SCALAR_OP],
3595
3238
  );
3596
- Object.keys(r!).forEach(
3597
- (key) =>
3598
- (newThat as valueT)[key as keyof valueT],
3599
- );
3239
+ Object.keys(r!).forEach((key) => (newThat as valueT)[key as keyof valueT]);
3600
3240
 
3601
3241
  newThat[ROOT_OP_META] = that[ROOT_OP_META];
3602
3242
 
3603
3243
  newThat[SLW_PARENT_SLW] = parentSlw;
3604
- parentSlw[SLW_COLLECTOR]?.registerSelection(
3605
- key,
3606
- newThat,
3607
- );
3244
+ parentSlw[SLW_COLLECTOR]?.registerSelection(key, newThat);
3608
3245
  newThat[SLW_ARGS] = {
3609
3246
  ...(that[SLW_ARGS] ?? {}),
3610
3247
  ...(args as any), // need to fix this
@@ -3612,10 +3249,7 @@ export class SelectionWrapper<
3612
3249
 
3613
3250
  newThat[SLW_OP_PATH] = that[SLW_OP_PATH];
3614
3251
 
3615
- newRootOpCollectorRef.ref.registerSelection(
3616
- newThat[SLW_FIELD_NAME]!,
3617
- newThat,
3618
- );
3252
+ newRootOpCollectorRef.ref.registerSelection(newThat[SLW_FIELD_NAME]!, newThat);
3619
3253
 
3620
3254
  return new Promise((resolve, reject) => {
3621
3255
  newRootOpCollectorRef.ref
@@ -3655,12 +3289,7 @@ export class SelectionWrapper<
3655
3289
  prop === SLW_IS_SCALAR_OP
3656
3290
  ) {
3657
3291
  return target[
3658
- prop as keyof SelectionWrapperImpl<
3659
- fieldName,
3660
- typeNamePure,
3661
- typeArrDepth,
3662
- valueT
3663
- >
3292
+ prop as keyof SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT>
3664
3293
  ];
3665
3294
  }
3666
3295
  if (prop === SLW_VALUE) {
@@ -3670,26 +3299,14 @@ export class SelectionWrapper<
3670
3299
  return this;
3671
3300
  }
3672
3301
 
3673
- let slw_value = target[SLW_VALUE] as
3674
- | Record<string, any>
3675
- | undefined;
3302
+ let slw_value = target[SLW_VALUE] as Record<string, any> | undefined;
3676
3303
 
3677
3304
  if (target[ROOT_OP_COLLECTOR]?.ref.isExecuted) {
3678
3305
  const getResultDataForTarget = (
3679
- t: SelectionWrapperImpl<
3680
- fieldName,
3681
- typeNamePure,
3682
- typeArrDepth,
3683
- valueT,
3684
- argsT
3685
- >,
3306
+ t: SelectionWrapperImpl<fieldName, typeNamePure, typeArrDepth, valueT, argsT>,
3686
3307
  ): valueT | undefined => {
3687
- const data = t[
3688
- ROOT_OP_COLLECTOR
3689
- ]!.ref.getOperationResultPath<valueT>(
3690
- (t[SLW_OP_PATH]?.split(".") ?? []).map((p) =>
3691
- !isNaN(+p) ? +p : p,
3692
- ),
3308
+ const data = t[ROOT_OP_COLLECTOR]!.ref.getOperationResultPath<valueT>(
3309
+ (t[SLW_OP_PATH]?.split(".") ?? []).map((p) => (!isNaN(+p) ? +p : p)),
3693
3310
  t[SLW_FIELD_TYPENAME],
3694
3311
  );
3695
3312
  return data;
@@ -3700,37 +3317,25 @@ export class SelectionWrapper<
3700
3317
  if (typeArrDepth) {
3701
3318
  if (!isNaN(+String(prop))) {
3702
3319
  const elm = target[SLW_CLONE]({
3703
- SLW_OP_PATH:
3704
- target[SLW_OP_PATH] +
3705
- "." +
3706
- String(prop),
3320
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(prop),
3707
3321
  });
3708
3322
  return elm;
3709
3323
  }
3710
3324
 
3711
- const data = getResultDataForTarget(target) as
3712
- | valueT[]
3713
- | undefined;
3325
+ const data = getResultDataForTarget(target) as valueT[] | undefined;
3714
3326
 
3715
3327
  if (data === undefined) return undefined;
3716
3328
 
3717
- const proxiedData = Array.from(
3718
- { length: data.length },
3719
- (_, i) =>
3720
- target[SLW_CLONE]({
3721
- SLW_OP_PATH:
3722
- target[SLW_OP_PATH] +
3723
- "." +
3724
- String(i),
3725
- }),
3329
+ const proxiedData = Array.from({ length: data.length }, (_, i) =>
3330
+ target[SLW_CLONE]({
3331
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
3332
+ }),
3726
3333
  );
3727
3334
 
3728
- const proto =
3729
- Object.getPrototypeOf(proxiedData);
3335
+ const proto = Object.getPrototypeOf(proxiedData);
3730
3336
  if (Object.hasOwn(proto, prop)) {
3731
3337
  const v = (proxiedData as any)[prop];
3732
- if (typeof v === "function")
3733
- return v.bind(proxiedData);
3338
+ if (typeof v === "function") return v.bind(proxiedData);
3734
3339
  return v;
3735
3340
  }
3736
3341
 
@@ -3742,8 +3347,7 @@ export class SelectionWrapper<
3742
3347
  const proto = Object.getPrototypeOf(data);
3743
3348
  if (Object.hasOwn(proto, prop)) {
3744
3349
  const v = (data as any)[prop];
3745
- if (typeof v === "function")
3746
- return v.bind(data);
3350
+ if (typeof v === "function") return v.bind(data);
3747
3351
  return v;
3748
3352
  }
3749
3353
 
@@ -3751,21 +3355,15 @@ export class SelectionWrapper<
3751
3355
  }
3752
3356
 
3753
3357
  let slw = slw_value?.[String(prop)];
3754
- const slwOpPathIsIndexAccess = !isNaN(
3755
- +target[SLW_OP_PATH]?.split(".").pop()!,
3756
- );
3358
+ const slwOpPathIsIndexAccess = !isNaN(+target[SLW_OP_PATH]?.split(".").pop()!);
3757
3359
  if (slwOpPathIsIndexAccess) {
3758
3360
  // index access detected, cloning
3759
3361
  slw = slw[SLW_CLONE]({
3760
- SLW_OP_PATH:
3761
- target[SLW_OP_PATH] + "." + String(prop),
3362
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(prop),
3762
3363
  });
3763
3364
  }
3764
3365
 
3765
- if (
3766
- slw instanceof SelectionWrapperImpl &&
3767
- slw[SLW_PARENT_COLLECTOR]
3768
- ) {
3366
+ if (slw instanceof SelectionWrapperImpl && slw[SLW_PARENT_COLLECTOR]) {
3769
3367
  return slw;
3770
3368
  } else if (slw instanceof SelectionWrapperImpl) {
3771
3369
  return getResultDataForTarget(slw);
@@ -3778,14 +3376,10 @@ export class SelectionWrapper<
3778
3376
 
3779
3377
  if (
3780
3378
  Object.hasOwn(slw_value ?? {}, String(prop)) &&
3781
- slw_value?.[String(prop)] instanceof
3782
- SelectionWrapperImpl
3379
+ slw_value?.[String(prop)] instanceof SelectionWrapperImpl
3783
3380
  ) {
3784
3381
  if (target[SLW_COLLECTOR]) {
3785
- target[SLW_COLLECTOR].registerSelection(
3786
- String(prop),
3787
- slw_value[String(prop)],
3788
- );
3382
+ target[SLW_COLLECTOR].registerSelection(String(prop), slw_value[String(prop)]);
3789
3383
  }
3790
3384
  if (!slw_value[String(prop)][SLW_PARENT_SLW]) {
3791
3385
  slw_value[String(prop)][SLW_PARENT_SLW] = target;