@samarium.sdk/new 0.30.0 → 0.30.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.
- package/bin/samarium +27 -17
- 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()}}}Wg.Parser=wz});var uz=Q((Eg)=>{var jz=DP(),zg=q1(),O1=J1(),Qg=UF(),Gg=t(),Rg=UP(),bz=WP();function Sz(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Rg.LineCounter||null,prettyErrors:F}}function Ig(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 $g(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)=>Qg.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 Mg(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(Gg.isDocument(D)&&!B)return D.toString(P);return new zg.Document(D,B,P).toString(P)}Eg.parse=$g;Eg.parseAllDocuments=Ig;Eg.parseDocument=Tz;Eg.stringify=Mg});var _z=Q((hg)=>{var Vg=DP(),wg=q1(),jg=gF(),OP=J1(),bg=p6(),I0=t(),Sg=O0(),Tg=CD(),ug=Q0(),Ng=G0(),_g=b5(),kg=HP(),xg=UP(),fg=WP(),u5=uz(),Nz=c6();hg.Composer=Vg.Composer;hg.Document=wg.Document;hg.Schema=jg.Schema;hg.YAMLError=OP.YAMLError;hg.YAMLParseError=OP.YAMLParseError;hg.YAMLWarning=OP.YAMLWarning;hg.Alias=bg.Alias;hg.isAlias=I0.isAlias;hg.isCollection=I0.isCollection;hg.isDocument=I0.isDocument;hg.isMap=I0.isMap;hg.isNode=I0.isNode;hg.isPair=I0.isPair;hg.isScalar=I0.isScalar;hg.isSeq=I0.isSeq;hg.Pair=Sg.Pair;hg.Scalar=Tg.Scalar;hg.YAMLMap=ug.YAMLMap;hg.YAMLSeq=Ng.YAMLSeq;hg.CST=_g;hg.Lexer=kg.Lexer;hg.LineCounter=xg.LineCounter;hg.Parser=fg.Parser;hg.parse=u5.parse;hg.parseAllDocuments=u5.parseAllDocuments;hg.parseDocument=u5.parseDocument;hg.stringify=u5.stringify;hg.visit=Nz.visit;hg.visitAsync=Nz.visitAsync});var G1={name:"@samarium.sdk/new",version:"0.30.
|
|
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()}}}Wg.Parser=wz});var uz=Q((Eg)=>{var jz=DP(),zg=q1(),O1=J1(),Qg=UF(),Gg=t(),Rg=UP(),bz=WP();function Sz(D){let F=D.prettyErrors!==!1;return{lineCounter:D.lineCounter||F&&new Rg.LineCounter||null,prettyErrors:F}}function Ig(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 $g(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)=>Qg.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 Mg(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(Gg.isDocument(D)&&!B)return D.toString(P);return new zg.Document(D,B,P).toString(P)}Eg.parse=$g;Eg.parseAllDocuments=Ig;Eg.parseDocument=Tz;Eg.stringify=Mg});var _z=Q((hg)=>{var Vg=DP(),wg=q1(),jg=gF(),OP=J1(),bg=p6(),I0=t(),Sg=O0(),Tg=CD(),ug=Q0(),Ng=G0(),_g=b5(),kg=HP(),xg=UP(),fg=WP(),u5=uz(),Nz=c6();hg.Composer=Vg.Composer;hg.Document=wg.Document;hg.Schema=jg.Schema;hg.YAMLError=OP.YAMLError;hg.YAMLParseError=OP.YAMLParseError;hg.YAMLWarning=OP.YAMLWarning;hg.Alias=bg.Alias;hg.isAlias=I0.isAlias;hg.isCollection=I0.isCollection;hg.isDocument=I0.isDocument;hg.isMap=I0.isMap;hg.isNode=I0.isNode;hg.isPair=I0.isPair;hg.isScalar=I0.isScalar;hg.isSeq=I0.isSeq;hg.Pair=Sg.Pair;hg.Scalar=Tg.Scalar;hg.YAMLMap=ug.YAMLMap;hg.YAMLSeq=Ng.YAMLSeq;hg.CST=_g;hg.Lexer=kg.Lexer;hg.LineCounter=xg.LineCounter;hg.Parser=fg.Parser;hg.parse=u5.parse;hg.parseAllDocuments=u5.parseAllDocuments;hg.parseDocument=u5.parseDocument;hg.stringify=u5.stringify;hg.visit=Nz.visit;hg.visitAsync=Nz.visitAsync});var G1={name:"@samarium.sdk/new",version:"0.30.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:Vv,createCommand:wv,createArgument:jv,createOption:bv,CommanderError:Sv,InvalidArgumentError:Tv,InvalidOptionArgumentError:uv,Command:gP,Argument:Nv,Option:_v,Help:kv}=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=fb(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},fb=(D)=>{let F={};return D.forEach((P,B)=>{F[B]=P}),F},NH=(D)=>{try{let F=D();if(hb(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))},hb=(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),gb=(D)=>{let F=void 0,P=D.definitions.filter(R7);if(P.length===1)F=P[0].name?.value;return F},vb=(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=gb(X),B=vb(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 mb(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 yb(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}},yb=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)},mb=(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(lb(F)),typeof Z==="string"&&!P.has(R3))P.set(R3,T6)}else B=cb(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)},lb=(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)}},cb=(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 db from"fs";var I7=async(D,F)=>{let P=await h0(D.url,D.headers),B=dH.printSchema(P);db.writeFileSync(F,B)};var K3=RD(l2(),1),A3=RD(l2(),1),KD=RD(l2(),1),pb=Object.defineProperty,rb=(D)=>D;function ab(D,F){this[D]=rb.bind(null,F)}var rH=(D,F)=>{for(var P in F)pb(D,P,{get:F[P],enumerable:!0,configurable:!0,set:ab.bind(F,P)})};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 sb=`const Proxy = globalThis.Proxy;
|
|
350
350
|
Proxy.prototype = {};
|
|
@@ -618,15 +618,15 @@ export class RootOperation {
|
|
|
618
618
|
fragments: Map<string, string>;
|
|
619
619
|
},
|
|
620
620
|
headers: Record<string, string> = {},
|
|
621
|
-
): Promise<AsyncGenerator<any, void, unknown
|
|
621
|
+
): Promise<{ generator: AsyncGenerator<any, void, unknown>; abortController: AbortController | undefined;[SLW_IS_ASYNC_ITERABLE]: true }> {
|
|
622
622
|
const that = this;
|
|
623
|
+
const abortState = { controller: undefined as AbortController | undefined };
|
|
623
624
|
const generator = (async function* () {
|
|
624
625
|
|
|
625
|
-
let abortController: AbortController | undefined = undefined;
|
|
626
626
|
let reader: import("stream/web").ReadableStreamDefaultReader<any> | undefined = undefined;
|
|
627
627
|
|
|
628
628
|
try {
|
|
629
|
-
|
|
629
|
+
abortState.controller = new AbortController();
|
|
630
630
|
|
|
631
631
|
const [url, options] = (await (
|
|
632
632
|
RootOperation[OPTIONS].sseFetchTransform ?? ((url: string, options?: RequestInit) => [url, options])
|
|
@@ -641,10 +641,11 @@ export class RootOperation {
|
|
|
641
641
|
query: \`\${[...query.fragments.values()].join("\\n")}\\n \${query.query}\`.trim(),
|
|
642
642
|
variables: query.variables,
|
|
643
643
|
}),
|
|
644
|
-
signal:
|
|
644
|
+
signal: abortState.controller.signal,
|
|
645
645
|
})) as [string | URL | Request, RequestInit];
|
|
646
646
|
const response = await (RootOperation[OPTIONS].fetcher ?? globalThis.fetch)(url, {
|
|
647
647
|
...options,
|
|
648
|
+
signal: abortState.controller.signal,
|
|
648
649
|
headers: {
|
|
649
650
|
...options?.headers,
|
|
650
651
|
"Content-Type": "application/json",
|
|
@@ -698,20 +699,26 @@ export class RootOperation {
|
|
|
698
699
|
|
|
699
700
|
return;
|
|
700
701
|
} catch (error) {
|
|
701
|
-
|
|
702
|
+
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
|
703
|
+
console.error(error);
|
|
704
|
+
}
|
|
702
705
|
}
|
|
703
706
|
finally {
|
|
707
|
+
abortState.controller?.abort();
|
|
704
708
|
if (reader) {
|
|
705
|
-
reader.cancel();
|
|
706
|
-
}
|
|
707
|
-
if (abortController) {
|
|
708
|
-
abortController.abort();
|
|
709
|
+
await reader.cancel().catch(() => { });
|
|
709
710
|
}
|
|
710
711
|
}
|
|
711
712
|
return;
|
|
712
713
|
})();
|
|
713
714
|
|
|
714
|
-
return
|
|
715
|
+
return {
|
|
716
|
+
generator,
|
|
717
|
+
get abortController() {
|
|
718
|
+
return abortState.controller;
|
|
719
|
+
},
|
|
720
|
+
[SLW_IS_ASYNC_ITERABLE]: true,
|
|
721
|
+
};
|
|
715
722
|
}
|
|
716
723
|
|
|
717
724
|
private async executeOperation(
|
|
@@ -996,6 +1003,8 @@ export const SLW_NEEDS_CLONE = Symbol("SLW_NEEDS_CLONE");
|
|
|
996
1003
|
|
|
997
1004
|
export const SLW_CLONE = Symbol("SLW_CLONE");
|
|
998
1005
|
|
|
1006
|
+
export const SLW_IS_ASYNC_ITERABLE = Symbol("SLW_IS_ASYNC_ITERABLE");
|
|
1007
|
+
|
|
999
1008
|
export class SelectionWrapperImpl<
|
|
1000
1009
|
fieldName extends string,
|
|
1001
1010
|
typeNamePure extends string,
|
|
@@ -1403,7 +1412,7 @@ export class SelectionWrapper<
|
|
|
1403
1412
|
const fieldName = newThat[SLW_FIELD_NAME]!;
|
|
1404
1413
|
const d = _data[fieldName];
|
|
1405
1414
|
|
|
1406
|
-
if (
|
|
1415
|
+
if (SLW_IS_ASYNC_ITERABLE in d) {
|
|
1407
1416
|
constPromiseValue = newThat;
|
|
1408
1417
|
lazyFnCallCache.set(cacheKey, { promise: constPromise, status: "fulfilled", reason: undefined, value: newThat });
|
|
1409
1418
|
return resolve(newThat);
|
|
@@ -1522,13 +1531,14 @@ export class SelectionWrapper<
|
|
|
1522
1531
|
target,
|
|
1523
1532
|
asyncGenRootPath,
|
|
1524
1533
|
true,
|
|
1525
|
-
) as AsyncGenerator<valueT, any, any>;
|
|
1534
|
+
) as { generator: AsyncGenerator<valueT, any, any>; abortController: AbortController | undefined };
|
|
1526
1535
|
const isScalar = target[SLW_PARENT_COLLECTOR] === undefined;
|
|
1527
1536
|
|
|
1528
1537
|
return function () {
|
|
1529
1538
|
return {
|
|
1530
1539
|
return() {
|
|
1531
|
-
|
|
1540
|
+
asyncGen.abortController?.abort();
|
|
1541
|
+
return asyncGen.generator.return(undefined).then((val) => {
|
|
1532
1542
|
return {
|
|
1533
1543
|
done: val.done,
|
|
1534
1544
|
value: val.value,
|
|
@@ -1537,7 +1547,7 @@ export class SelectionWrapper<
|
|
|
1537
1547
|
},
|
|
1538
1548
|
|
|
1539
1549
|
next() {
|
|
1540
|
-
return asyncGen.next().then((val) => {
|
|
1550
|
+
return asyncGen.generator.next().then((val) => {
|
|
1541
1551
|
const clonedSlw = target[SLW_CLONE]({
|
|
1542
1552
|
SLW_OP_PATH: asyncGenRootPath,
|
|
1543
1553
|
OP_RESULT_DATA: isScalar
|
|
@@ -2810,7 +2820,7 @@ export class SelectionWrapper<
|
|
|
2810
2820
|
|
|
2811
2821
|
const d = _data[field];
|
|
2812
2822
|
|
|
2813
|
-
if (
|
|
2823
|
+
if (SLW_IS_ASYNC_ITERABLE in d) {
|
|
2814
2824
|
constPromiseValue = fieldSlw as any;
|
|
2815
2825
|
return resolve(fieldSlw as any);
|
|
2816
2826
|
}
|
|
@@ -2940,7 +2950,7 @@ export class SelectionWrapper<
|
|
|
2940
2950
|
|
|
2941
2951
|
const d = _data[field];
|
|
2942
2952
|
|
|
2943
|
-
if (
|
|
2953
|
+
if (SLW_IS_ASYNC_ITERABLE in d) {
|
|
2944
2954
|
constPromiseValue = fieldSlw as any;
|
|
2945
2955
|
return resolve(fieldSlw as any);
|
|
2946
2956
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samarium.sdk/new",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.2",
|
|
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.30.
|
|
47
|
+
"@samarium.sdk/make": "0.30.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"typescript": "^5.0.0"
|