@samarium.sdk/new 0.28.2 → 0.29.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.
Files changed (2) hide show
  1. package/bin/samarium +138 -41
  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.28.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.
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.29.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.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 = {};
@@ -457,7 +457,7 @@ export class RootOperation {
457
457
  constructor(
458
458
  public authArg?: FnOrPromisOrPrimitive,
459
459
  public headers?: FnOrPromisOrPrimitive,
460
- ) {}
460
+ ) { }
461
461
  public setAuth(auth: FnOrPromisOrPrimitive) {
462
462
  this.authArg = auth;
463
463
  return this;
@@ -576,9 +576,8 @@ export class RootOperation {
576
576
  ...acc,
577
577
  [opName]: {
578
578
  opType: rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase() as "subscription" | "query" | "mutation",
579
- query: \`\${rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase()} \${opName} \${
580
- selection.variableDefinitions.length ? \`(\${selection.variableDefinitions.join(", ")}) \` : ""
581
- }\${selection.selection}\`,
579
+ query: \`\${rootSlw[SLW_IS_ROOT_TYPE]?.toLowerCase()} \${opName} \${selection.variableDefinitions.length ? \`(\${selection.variableDefinitions.join(", ")}) \` : ""
580
+ }\${selection.selection}\`,
582
581
  variables: selection.variables,
583
582
  fragments: selection.usedFragments,
584
583
  },
@@ -754,9 +753,9 @@ export class OperationSelectionCollector {
754
753
  data: Map<string, any>;
755
754
  proxiedArray: Map<string, any[]>;
756
755
  } = {
757
- data: new Map(),
758
- proxiedArray: new Map(),
759
- };
756
+ data: new Map(),
757
+ proxiedArray: new Map(),
758
+ };
760
759
 
761
760
  public async execute(headers?: Record<string, string>) {
762
761
  if (!this.op) {
@@ -936,7 +935,7 @@ export class OperationSelectionCollector {
936
935
  finalResult,
937
936
  depth,
938
937
  RootOperation[OPTIONS].scalars[type as keyof (typeof RootOperation)[typeof OPTIONS]["scalars"]] ??
939
- ((value: string) => JSON.parse(value)),
938
+ ((value: string) => JSON.parse(value)),
940
939
  ) as T;
941
940
  }
942
941
 
@@ -1289,6 +1288,7 @@ export class SelectionWrapper<
1289
1288
  }
1290
1289
  if (prop === "$lazy") {
1291
1290
  const that = this;
1291
+ const lazyFnCallCache = new Map<string, { promise: Promise<any> | undefined, status: "pending" | "fulfilled" | "rejected", reason: string | undefined, value: any | undefined }>();
1292
1292
  function lazy(
1293
1293
  this: {
1294
1294
  parentSlw: SelectionWrapperImpl<
@@ -1354,16 +1354,29 @@ export class SelectionWrapper<
1354
1354
 
1355
1355
  const isScalar = newThat[SLW_PARENT_COLLECTOR] === undefined;
1356
1356
 
1357
+ const cacheKey = JSON.stringify({ parentSlw: parentSlw[SLW_UID], key, args });
1358
+ let constPromise: Promise<any> | undefined = lazyFnCallCache.get(cacheKey)?.promise;
1359
+ let constPromiseStatus: "pending" | "fulfilled" | "rejected" = lazyFnCallCache.get(cacheKey)?.status ?? "pending";
1360
+ let constPromiseReason: string | undefined = lazyFnCallCache.get(cacheKey)?.reason;
1361
+ let constPromiseValue: any | undefined = lazyFnCallCache.get(cacheKey)?.value;
1357
1362
  const resultProxy = new Proxy(
1358
1363
  {},
1359
1364
  {
1360
1365
  get(_t, _prop) {
1361
- const result = new Promise((resolve, reject) => {
1366
+ const makePromise = () => new Promise((resolve, reject) => {
1362
1367
  newRootOpCollectorRef.ref
1363
1368
  .execute()
1364
- .catch(reject)
1369
+ .catch((reason) => {
1370
+ constPromiseStatus = "rejected";
1371
+ constPromiseReason = reason;
1372
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "rejected", reason, value: undefined });
1373
+ return reject(reason);
1374
+ })
1365
1375
  .then((_data) => {
1376
+ constPromiseStatus = "fulfilled";
1366
1377
  if (_data === undefined || _data === null) {
1378
+ constPromiseValue = _data;
1379
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: _data });
1367
1380
  return resolve(_data);
1368
1381
  }
1369
1382
 
@@ -1371,33 +1384,51 @@ export class SelectionWrapper<
1371
1384
  const d = _data[fieldName];
1372
1385
 
1373
1386
  if (Symbol.asyncIterator in d) {
1387
+ constPromiseValue = newThat;
1388
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: newThat });
1374
1389
  return resolve(newThat);
1375
1390
  }
1376
1391
  if (typeof d === "object" && d && fieldName in d) {
1377
1392
  const retval = d[fieldName];
1378
1393
  if (retval === undefined || retval === null) {
1394
+ constPromiseValue = retval;
1395
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: retval });
1379
1396
  return resolve(retval);
1380
1397
  }
1381
1398
  const ret = isScalar
1382
1399
  ? getResultDataForTarget(
1383
- newThat as SelectionWrapper<
1384
- fieldName,
1385
- typeNamePure,
1386
- typeArrDepth,
1387
- valueT,
1388
- argsT
1389
- >,
1390
- )
1400
+ newThat as SelectionWrapper<
1401
+ fieldName,
1402
+ typeNamePure,
1403
+ typeArrDepth,
1404
+ valueT,
1405
+ argsT
1406
+ >,
1407
+ )
1391
1408
  : proxify(retval, newThat);
1409
+ constPromiseValue = ret;
1410
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: ret });
1392
1411
  return resolve(ret);
1393
1412
  }
1394
1413
 
1414
+ constPromiseValue = newThat;
1415
+ lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: newThat });
1395
1416
  return resolve(newThat);
1396
1417
  });
1397
1418
  });
1419
+ const result = constPromiseStatus === "fulfilled" && constPromise ? (constPromise = makePromise()) : constPromise ?? (constPromise = makePromise());
1398
1420
  if (String(_prop) === "then") {
1399
1421
  return result.then.bind(result);
1400
1422
  }
1423
+ if (String(_prop) === "status") {
1424
+ return constPromiseStatus;
1425
+ }
1426
+ if (String(_prop) === "reason") {
1427
+ return constPromiseReason;
1428
+ }
1429
+ if (String(_prop) === "value") {
1430
+ return constPromiseValue;
1431
+ }
1401
1432
  return result;
1402
1433
  },
1403
1434
  },
@@ -1538,16 +1569,16 @@ export class SelectionWrapper<
1538
1569
  Array.from({ length: data.length }, (_, i) =>
1539
1570
  typeof data[i] === "object"
1540
1571
  ? proxify(
1541
- data[i],
1542
- target[SLW_CLONE]({
1543
- SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1544
- OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1545
- }),
1546
- )
1572
+ data[i],
1573
+ target[SLW_CLONE]({
1574
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1575
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1576
+ }),
1577
+ )
1547
1578
  : target[SLW_CLONE]({
1548
- SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1549
- OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1550
- }),
1579
+ SLW_OP_PATH: target[SLW_OP_PATH] + "." + String(i),
1580
+ OP_RESULT_DATA: target[SLW_OP_RESULT_DATA_OVERRIDE],
1581
+ }),
1551
1582
  );
1552
1583
 
1553
1584
  if (!cache.proxiedArray.has(path)) {
@@ -1663,8 +1694,8 @@ export class SelectionWrapper<
1663
1694
  let realSlw = isOnTypeFragment
1664
1695
  ? slw[SLW_IS_ON_TYPE_FRAGMENT]
1665
1696
  : isFragment
1666
- ? slw[SLW_IS_FRAGMENT]
1667
- : slw;
1697
+ ? slw[SLW_IS_FRAGMENT]
1698
+ : slw;
1668
1699
  if (target[SLW_COLLECTOR]) {
1669
1700
  target[SLW_COLLECTOR].registerSelection(String(prop), realSlw);
1670
1701
  if (isOnTypeFragment || isFragment) {
@@ -2491,6 +2522,10 @@ export class SelectionWrapper<
2491
2522
  ? _TR
2492
2523
  : Promise<_TR>;
2493
2524
 
2525
+ let constPromise: Promise<any> | undefined;
2526
+ let constPromiseStatus: "pending" | "fulfilled" | "rejected" = "pending";
2527
+ let constPromiseReason: string | undefined;
2528
+ let constPromiseValue: any | undefined;
2494
2529
  const resultProxy = new Proxy(
2495
2530
  {},
2496
2531
  {
@@ -2499,19 +2534,35 @@ export class SelectionWrapper<
2499
2534
  if (typeof rAtProp === "function") {
2500
2535
  return rAtProp;
2501
2536
  }
2502
- const promise = new Promise((resolve, reject) => {
2537
+ const promise = constPromise ?? (constPromise = new Promise((resolve, reject) => {
2503
2538
  root.execute()
2504
- .catch(reject)
2539
+ .catch((reason) => {
2540
+ constPromiseStatus = "rejected";
2541
+ constPromiseReason = reason;
2542
+ return reject(reason);
2543
+ })
2505
2544
  .then((_data) => {
2545
+ constPromiseStatus = "fulfilled";
2506
2546
  if (_data === undefined || _data === null) {
2547
+ constPromiseValue = _data;
2507
2548
  return resolve(_data);
2508
2549
  }
2509
- resolve(rAtProp);
2510
- });
2511
- });
2550
+ constPromiseValue = rAtProp;
2551
+ return resolve(rAtProp);
2552
+ });
2553
+ }));
2512
2554
  if (String(_prop) === "then") {
2513
2555
  return promise.then.bind(promise);
2514
2556
  }
2557
+ if (String(_prop) === "status") {
2558
+ return constPromiseStatus;
2559
+ }
2560
+ if (String(_prop) === "reason") {
2561
+ return constPromiseReason;
2562
+ }
2563
+ if (String(_prop) === "value") {
2564
+ return constPromiseValue;
2565
+ }
2515
2566
  return promise;
2516
2567
  },
2517
2568
  },
@@ -2700,6 +2751,10 @@ export class SelectionWrapper<
2700
2751
  // access the keys of the proxy object, to register operations
2701
2752
  Object.keys({ [field]: 0 }).forEach(key => (rootSlw as any)[key as any]);
2702
2753
 
2754
+ let constPromise: Promise<any> | undefined;
2755
+ let constPromiseStatus: "pending" | "fulfilled" | "rejected" = "pending";
2756
+ let constPromiseReason: string | undefined;
2757
+ let constPromiseValue: any | undefined;
2703
2758
  const resultProxy = new Proxy(
2704
2759
  {},
2705
2760
  {
@@ -2710,17 +2765,24 @@ export class SelectionWrapper<
2710
2765
  key: field,
2711
2766
  });
2712
2767
  } else {
2713
- const result = new Promise((resolve, reject) => {
2768
+ const result = constPromise ?? (constPromise = new Promise((resolve, reject) => {
2714
2769
  root.execute()
2715
- .catch(reject)
2770
+ .catch((reason) => {
2771
+ constPromiseStatus = "rejected";
2772
+ constPromiseReason = reason;
2773
+ return reject(reason);
2774
+ })
2716
2775
  .then((_data) => {
2776
+ constPromiseStatus = "fulfilled";
2717
2777
  if (_data === undefined || _data === null) {
2778
+ constPromiseValue = _data;
2718
2779
  return resolve(_data);
2719
2780
  }
2720
2781
 
2721
2782
  const d = _data[field];
2722
2783
 
2723
2784
  if (Symbol.asyncIterator in d) {
2785
+ constPromiseValue = fieldSlw as any;
2724
2786
  return resolve(fieldSlw as any);
2725
2787
  }
2726
2788
 
@@ -2728,17 +2790,29 @@ export class SelectionWrapper<
2728
2790
  if (typeof d === "object" && d && field in d) {
2729
2791
  const retval = d[field];
2730
2792
  if (retval === undefined || retval === null) {
2793
+ constPromiseValue = retval;
2731
2794
  return resolve(retval);
2732
2795
  }
2733
2796
  const ret = typeof retval !== "object" ? slw : proxify(retval, slw);
2797
+ constPromiseValue = ret;
2734
2798
  return resolve(ret);
2735
2799
  }
2800
+ constPromiseValue = slw;
2736
2801
  return resolve(slw);
2737
2802
  });
2738
- });
2803
+ }));
2739
2804
  if (String(_prop) === "then") {
2740
2805
  return result.then.bind(result);
2741
2806
  }
2807
+ if (String(_prop) === "status") {
2808
+ return constPromiseStatus;
2809
+ }
2810
+ if (String(_prop) === "reason") {
2811
+ return constPromiseReason;
2812
+ }
2813
+ if (String(_prop) === "value") {
2814
+ return constPromiseValue;
2815
+ }
2742
2816
  return result;
2743
2817
  }
2744
2818
  },
@@ -2807,6 +2881,10 @@ export class SelectionWrapper<
2807
2881
  // access the keys of the proxy object, to register operations
2808
2882
  Object.keys({ [field]: 0 }).forEach(key => (rootSlw as any)[key as any]);
2809
2883
 
2884
+ let constPromise: Promise<any> | undefined;
2885
+ let constPromiseStatus: "pending" | "fulfilled" | "rejected" = "pending";
2886
+ let constPromiseReason: string | undefined;
2887
+ let constPromiseValue: any | undefined;
2810
2888
  const resultProxy = new Proxy(
2811
2889
  {},
2812
2890
  {
@@ -2817,17 +2895,24 @@ export class SelectionWrapper<
2817
2895
  key: field,
2818
2896
  });
2819
2897
  } else {
2820
- const result = new Promise((resolve, reject) => {
2898
+ const result = constPromise ?? (constPromise = new Promise((resolve, reject) => {
2821
2899
  root.execute()
2822
- .catch(reject)
2900
+ .catch((reason) => {
2901
+ constPromiseStatus = "rejected";
2902
+ constPromiseReason = reason;
2903
+ return reject(reason);
2904
+ })
2823
2905
  .then((_data) => {
2906
+ constPromiseStatus = "fulfilled";
2824
2907
  if (_data === undefined || _data === null) {
2908
+ constPromiseValue = _data;
2825
2909
  return resolve(_data);
2826
2910
  }
2827
2911
 
2828
2912
  const d = _data[field];
2829
2913
 
2830
2914
  if (Symbol.asyncIterator in d) {
2915
+ constPromiseValue = fieldSlw as any;
2831
2916
  return resolve(fieldSlw as any);
2832
2917
  }
2833
2918
 
@@ -2835,17 +2920,29 @@ export class SelectionWrapper<
2835
2920
  if (typeof d === "object" && d && field in d) {
2836
2921
  const retval = d[field];
2837
2922
  if (retval === undefined || retval === null) {
2923
+ constPromiseValue = retval;
2838
2924
  return resolve(retval);
2839
2925
  }
2840
2926
  const ret = typeof retval !== "object" ? slw : proxify(retval, slw);
2927
+ constPromiseValue = ret;
2841
2928
  return resolve(ret);
2842
2929
  }
2930
+ constPromiseValue = slw;
2843
2931
  return resolve(slw);
2844
2932
  });
2845
- });
2933
+ }));
2846
2934
  if (String(_prop) === "then") {
2847
2935
  return result.then.bind(result);
2848
2936
  }
2937
+ if (String(_prop) === "status") {
2938
+ return constPromiseStatus;
2939
+ }
2940
+ if (String(_prop) === "reason") {
2941
+ return constPromiseReason;
2942
+ }
2943
+ if (String(_prop) === "value") {
2944
+ return constPromiseValue;
2945
+ }
2849
2946
  return result;
2850
2947
  }
2851
2948
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samarium.sdk/new",
3
- "version": "0.28.2",
3
+ "version": "0.29.1",
4
4
  "main": "bin/samarium",
5
5
  "type": "module",
6
6
  "repository": {
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "bun-types": "^1.2.19",
47
- "@samarium.sdk/make": "0.28.2"
47
+ "@samarium.sdk/make": "0.29.1"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "typescript": "^5.0.0"