@fern-api/go-dynamic-snippets 1.23.0 → 1.23.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/dist/index.js CHANGED
@@ -23,7 +23,8 @@ ${this.buffer}`:t+this.buffer}stringifyImports(){let t=Object.entries(this.impor
23
23
  ${t}
24
24
  )`:""}};var l={};Xt(l,{Alias:()=>xe,AstNode:()=>P,CodeBlock:()=>ie,Enum:()=>Ee,Field:()=>Ne,File:()=>be,Func:()=>Ae,FuncInvocation:()=>ee,IoReaderTypeReference:()=>Ut,Method:()=>le,MethodInvocation:()=>pe,MultiNode:()=>Xe,Parameter:()=>Re,Pointer:()=>Fe,Selector:()=>ke,Struct:()=>Pe,TimeTypeReference:()=>pt,Type:()=>Ze,TypeDeclaration:()=>Be,TypeInstantiation:()=>K,TypeReference:()=>J,UuidTypeReference:()=>lt,Writer:()=>Ie,alias:()=>Bo,codeblock:()=>So,enum_:()=>Co,field:()=>Uo,file:()=>Lo,func:()=>_o,identifier:()=>Mo,invokeFunc:()=>$o,invokeMethod:()=>Do,method:()=>Oo,parameter:()=>Vo,pointer:()=>Wo,selector:()=>qo,struct:()=>Go,switch_:()=>jo,typeDeclaration:()=>Ho,typeReference:()=>zo});y();w();g();y();w();g();y();w();g();y();w();g();y();w();g();var P=class extends ve{async toStringAsync({packageName:t,rootImportPath:e,importPath:i,customConfig:a,formatter:p}){let s=new Je({packageName:t,rootImportPath:e,importPath:i,customConfig:a,formatter:p});return this.write(s),s.toStringAsync()}toString({packageName:t,rootImportPath:e,importPath:i,customConfig:a,formatter:p}){let s=new Je({packageName:t,rootImportPath:e,importPath:i,customConfig:a,formatter:p});return this.write(s),s.toString()}};var j=class extends P{constructor({docs:e}={}){super();m(this,"docs");this.docs=e}write(e){this.docs!=null&&this.docs.split(`
25
25
  `).forEach(i=>{e.writeLine(`// ${i}`)})}};var xe=class extends P{constructor({name:e,type:i,docs:a}){super();m(this,"name");m(this,"type");m(this,"docs");this.name=e,this.type=i,this.docs=a}write(e){e.writeNode(new j({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" = "),e.writeNode(this.type)}};y();w();g();var ie=class extends P{constructor(e){super();m(this,"arg");this.arg=e}write(e){return new Z(this.arg).write(e)}};y();w();g();y();w();g();var ue=class extends P{constructor(e){super();m(this,"name");this.name=e}write(e){e.write(this.name)}};y();w();g();y();w();g();y();w();g();function _e({writer:u,arguments_:t,multiline:e=!0}){let i=t.map(a=>a instanceof K&&K.isNop(a)?K.nil():a);if(i.length===0){u.write("()");return}if(e){Io({writer:u,arguments_:i});return}To({writer:u,arguments_:i})}function Io({writer:u,arguments_:t}){u.writeLine("("),u.indent();for(let e of t)e.write(u),u.writeLine(",");u.dedent(),u.write(")")}function To({writer:u,arguments_:t}){u.write("("),t.forEach((e,i)=>{i>0&&u.write(", "),e.write(u)}),u.write(")")}var ee=class extends P{constructor({func:e,arguments_:i,multiline:a=!0}){super();m(this,"func");m(this,"arguments_");m(this,"multiline");this.func=e,this.arguments_=i,this.multiline=a}write(e){e.writeNode(this.func),_e({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};y();w();g();y();w();g();function kr({writer:u,generics:t}){t.length!==0&&(u.write("["),t.forEach((e,i)=>{i>0&&u.write(", "),e!=null&&u.writeNode(e)}),u.write("]"))}var J=class extends P{constructor({name:e,importPath:i,generics:a}){super();m(this,"name");m(this,"importPath");m(this,"generics");this.name=e,this.importPath=i,this.generics=a}write(e){if(this.importPath==null||e.importPath===this.importPath){e.write(this.name);return}let i=e.addImport(this.importPath);e.write(`${i}.${this.name}`),this.generics!=null&&kr({writer:e,generics:this.generics})}};y();w();g();var pe=class extends P{constructor({method:e,arguments_:i,on:a,multiline:p}){super();m(this,"on");m(this,"method");m(this,"arguments_");m(this,"multiline");this.on=a,this.method=e,this.arguments_=i,this.multiline=p}write(e){this.on.write(e),e.write("."),e.write(this.method),_e({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};var xo=new Set(["bool","date","dateTime","float64","int","int64","string","uuid"]),Pr=new Set(["any","bytes","map","slice"]),K=class u extends P{constructor(e){super();m(this,"internalType");this.internalType=e}write(e){switch(this.internalType.type){case"any":this.writeAny({writer:e,value:this.internalType.value});break;case"bool":e.write(this.internalType.value.toString());break;case"bytes":e.write(`[]byte("${this.internalType.value}")`);break;case"date":case"dateTime":e.writeNode(bo({writer:e,type:this.internalType}));break;case"enum":e.writeNode(this.internalType.typeReference);break;case"float64":e.write(this.internalType.value.toString());break;case"int":case"int64":e.write(this.internalType.value.toString());break;case"map":this.writeMap({writer:e,map:this.internalType});break;case"nil":e.write("nil");break;case"nop":break;case"optional":this.writeOptional({writer:e,type:this.internalType.value});break;case"reference":e.writeNode(this.internalType.value);break;case"slice":this.writeSlice({writer:e,slice:this.internalType});break;case"string":e.write(this.internalType.value.includes('"')||this.internalType.value.includes(`
26
- `)?`\`${this.internalType.value}\``:`"${this.internalType.value}"`);break;case"struct":this.writeStruct({writer:e,struct:this.internalType});break;case"uuid":e.writeNode(Ao({value:this.internalType.value}));break;default:U(this.internalType)}}static any(e){return new this({type:"any",value:e})}static bool(e){return new this({type:"bool",value:e})}static bytes(e){return new this({type:"bytes",value:e})}static date(e){return new this({type:"date",value:e})}static dateTime(e){return new this({type:"dateTime",value:e})}static enum(e){return new this({type:"enum",typeReference:e})}static float64(e){return new this({type:"float64",value:e})}static int(e){return new this({type:"int",value:e})}static int64(e){return new this({type:"int64",value:e})}static map({keyType:e,valueType:i,entries:a}){return new this({type:"map",keyType:e,valueType:i,entries:a})}static nil(){return new this({type:"nil"})}static nop(){return new this({type:"nop"})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static reference(e){return new this({type:"reference",value:e})}static slice({valueType:e,values:i}){return new this({type:"slice",valueType:e,values:i})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:i}){return new this({type:"struct",typeReference:e,fields:i})}static structPointer({typeReference:e,fields:i,generics:a}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:i,generics:a})})}static uuid(e){return new this({type:"uuid",value:e})}static isNop(e){return e.internalType.type==="optional"?this.isNop(e.internalType.value):e.internalType.type==="nop"}writeAny({writer:e,value:i}){switch(typeof i){case"boolean":e.write(i.toString());return;case"string":e.write(i.includes('"')?`\`${i}\``:`"${i}"`);return;case"number":e.write(i.toString());return;case"object":if(i==null){e.write("nil");return}if(Array.isArray(i)){this.writeAnyArray({writer:e,value:i});return}this.writeAnyObject({writer:e,value:i});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof i}`)}}writeAnyArray({writer:e,value:i}){if(e.write("[]any"),i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let a of i)e.writeNode(u.any(a)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:i}){e.write("map[string]any");let a=Object.entries(i);if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[p,s]of a)e.write(`"${p}": `),e.writeNode(u.any(s)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:i}){e.write("map["),e.writeNode(i.keyType),e.write("]"),e.writeNode(i.valueType);let a=Ro({entries:i.entries});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)p.key.write(e),e.write(": "),p.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeOptional({writer:e,type:i}){if(xo.has(i.internalType.type)){e.writeNode(Eo({writer:e,type:i}));return}if(Pr.has(i.internalType.type)){i.write(e);return}if(i.internalType.type==="enum"){e.writeNode(new pe({on:i.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),i.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||Pr.has(e.internalType.type)}writeSlice({writer:e,slice:i}){e.write("[]"),e.writeNode(i.valueType);let a=ko({values:i.values});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)p.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeStruct({writer:e,struct:i}){e.writeNode(i.typeReference),i.generics!=null&&(e.write("["),i.generics.forEach((p,s)=>{s>0&&e.write(", "),e.writeNode(p)}),e.write("]"));let a=Fo({fields:i.fields});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)e.write(`${p.name}: `),p.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function Eo({writer:u,type:t}){return new ee({func:new J({name:No({type:t}),importPath:u.rootImportPath}),arguments_:[t]})}function No({type:u}){switch(u.internalType.type){case"bool":return"Bool";case"date":case"dateTime":return"Time";case"float64":return"Float64";case"int":return"Int";case"int64":return"Int64";case"string":return"String";case"uuid":return"UUID";default:return""}}function bo({writer:u,type:t}){let e=t.type==="date"?"MustParseDate":"MustParseDateTime";return new ee({func:new J({name:e,importPath:u.rootImportPath}),arguments_:[new ie(`"${t.value}"`)]})}function Ao({value:u}){return new ee({func:new J({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new ie(`"${u}"`)]})}function Ro({entries:u}){return u.filter(t=>!K.isNop(t.key)&&!K.isNop(t.value))}function Fo({fields:u}){return u.filter(t=>!K.isNop(t.value))}function ko({values:u}){return u.filter(t=>!K.isNop(t))}var Ee=class u extends P{constructor({name:e,docs:i}){super();m(this,"name");m(this,"docs");m(this,"members",[]);m(this,"methods",[]);m(this,"constructor_");this.name=e,this.docs=i}addConstructor(e){this.constructor_=e}addMember(e){this.members.push(e)}addMethod(e){this.methods.push(e)}write(e){this.writeType({writer:e}),this.writeMembers({writer:e}),this.writeConstructor({writer:e}),this.writeMethods({writer:e})}writeType({writer:e}){e.writeNode(new j({docs:this.docs})),e.writeLine(`type ${this.name} string`)}writeMembers({writer:e}){if(this.members.length!==0){e.newLine(),e.writeLine("const ("),e.indent();for(let i of this.members)e.writeNode(new j({docs:i.docs})),e.writeNode(u.getMemberIdentifier({name:this.name,member:i})),e.write(" = "),e.writeNode(K.string(i.value)),e.newLine();e.dedent(),e.write(")")}}writeConstructor({writer:e}){this.constructor_!=null&&(e.newLine(),e.writeNode(this.constructor_))}writeMethods({writer:e}){e.newLine();for(let i of this.methods)e.newLine(),e.writeNode(i),e.newLine()}static getMemberIdentifier({name:e,member:i}){return new ue(`${e}${i.name}`)}};y();w();g();var Ne=class extends P{constructor({name:e,type:i,docs:a,tags:p}){super();m(this,"name");m(this,"type");m(this,"docs");m(this,"tags",[]);this.name=e,this.type=i,this.docs=a,this.tags=p??[]}addTags(...e){this.tags.push(...e)}write(e){e.writeNode(new j({docs:this.docs})),e.write(`${this.name} `),this.type.write(e),this.writeTags({writer:e})}writeTags({writer:e}){this.tags.length!==0&&(e.write(" `"),this.tags.forEach((i,a)=>{a>0&&e.write(" "),e.write(`${i.name}:"${i.value}"`)}),e.write("`"))}};y();w();g();var be=class extends P{constructor({nodes:e}={nodes:[]}){super();m(this,"nodes");this.nodes=e??[]}add(...e){this.nodes.push(...e)}write(e){for(let i of this.nodes)i.write(e)}};y();w();g();y();w();g();var le=class extends P{constructor({name:e,parameters:i,return_:a,body:p,docs:s,typeReference:f,multiline:I,receiver:x,pointerReceiver:E}){super();m(this,"parameters");m(this,"return_");m(this,"name");m(this,"body");m(this,"docs");m(this,"typeReference");m(this,"multiline");m(this,"receiver");m(this,"pointerReceiver");this.name=e,this.parameters=i,this.return_=a,this.body=p,this.docs=s,this.typeReference=f,this.multiline=I,this.receiver=x,this.pointerReceiver=E}write(e){e.writeNode(new j({docs:this.docs})),e.write("func"),this.typeReference!=null&&this.writeReceiver({writer:e,typeReference:this.typeReference,receiver:this.receiver}),this.name!=null&&e.write(` ${this.name}`),_e({writer:e,arguments_:this.parameters,multiline:this.multiline}),this.return_!=null&&(e.write(" "),this.return_.length>1&&e.write("("),this.return_.forEach((i,a)=>{a>0&&e.write(", "),e.writeNode(i)}),this.return_.length>1&&e.write(")")),e.writeLine("{"),e.indent(),this.body?.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.write("}")}writeReceiver({writer:e,typeReference:i,receiver:a}){e.write(` (${this.getReceiverName({typeReference:i,receiver:a})} `),this.pointerReceiver&&e.write("*"),i.write(e),e.write(")")}getReceiverName({typeReference:e,receiver:i}){return i??e.name.charAt(0).toLowerCase()}};var Ae=class extends P{constructor({name:e,parameters:i,return_:a,body:p,docs:s,multiline:f}){super();m(this,"func");this.func=new le({name:e,parameters:i,return_:a,body:p,docs:s,multiline:f})}get parameters(){return this.func.parameters}get return_(){return this.func.return_}get name(){return this.func.name}get body(){return this.func.body}get docs(){return this.func.docs}write(e){e.writeNode(this.func)}};y();w();g();var Xe=class extends P{constructor({nodes:e}){super();m(this,"nodes");this.nodes=e}write(e){for(let i of this.nodes)e.newLine(),i.write(e),e.newLine()}};y();w();g();var Re=class extends P{constructor({name:e,type:i,docs:a}){super();m(this,"name");m(this,"type");m(this,"docs");this.name=e,this.type=i,this.docs=a}write(e){e.writeNode(new j({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};y();w();g();var Fe=class extends P{constructor({node:e}){super();m(this,"node");this.node=e}write(e){e.write("*"),this.node.write(e)}};y();w();g();var ke=class extends P{constructor({on:e,selector:i}){super();m(this,"on");m(this,"selector");this.on=e,this.selector=i}write(e){e.writeNode(this.on),e.write("."),e.writeNode(this.selector)}};y();w();g();var Pe=class extends P{constructor({name:e,embeds:i,fields:a,docs:p}){super();m(this,"name");m(this,"embeds",[]);m(this,"fields",[]);m(this,"docs");m(this,"methods",[]);m(this,"constructor_");this.name=e,this.docs=p,this.embeds=i??[],this.fields=a??[]}addConstructor(e){this.constructor_=e}addField(...e){this.fields.push(...e)}addMethod(...e){this.methods.push(...e)}write(e){this.writeType({writer:e}),this.constructor_!=null&&(e.newLine(),e.newLine(),this.writeConstructor({writer:e,constructor:this.constructor_})),this.writeMethods({writer:e})}writeType({writer:e}){if(e.writeNode(new j({docs:this.docs})),this.name!=null?e.write(`type ${this.name} struct {`):e.write("struct{"),this.embeds.length===0&&this.fields.length===0){e.writeLine("}");return}e.newLine(),e.indent();for(let p of this.embeds)e.writeNode(p),e.newLine();let i=this.fields.filter(p=>this.isExported(p));for(let p of i)e.writeNode(p),e.newLine();let a=this.fields.filter(p=>!this.isExported(p));i.length>0&&a.length>0&&e.newLine();for(let p of a)e.writeNode(p),e.newLine();e.dedent(),e.write("}")}writeConstructor({writer:e,constructor:i}){i.name!=null?e.write(`func ${i.name}(`):e.write(`func New${this.name}(`),i.parameters.forEach((a,p)=>{p>0&&e.write(", "),e.writeNode(a)}),e.write(`) *${this.name} {`),e.newLine(),e.indent(),e.writeNode(i.body),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeMethods({writer:e}){if(this.methods.length!==0){e.writeNewLineIfLastLineNot();for(let i of this.methods)e.newLine(),e.writeNode(i),e.newLine()}}isExported(e){let i=e.name.charAt(0);return i===i.toUpperCase()}};y();w();g();var Qe=class extends P{constructor({on:e,cases:i,default:a}){super();m(this,"on");m(this,"cases");m(this,"default");this.on=e,this.cases=i,this.default=a}write(e){let i=this.cases;this.default!=null&&i.push({on:new ue("default"),body:this.default}),e.write("switch "),e.writeNode(this.on),e.writeLine("{"),e.indent();for(let a of i)e.write("case "),e.writeNode(a.on),e.writeLine(":"),e.indent(),e.writeNode(a.body),e.dedent(),e.writeNewLineIfLastLineNot();e.dedent(),e.write("}")}};y();w();g();var Po=new Set(["any","bytes","map","slice"]),Ze=class u extends P{constructor(e){super();m(this,"internalType");this.internalType=e}write(e,{comment:i}={}){switch(this.internalType.type){case"any":e.write("any");break;case"bool":e.write("bool");break;case"bytes":e.write("[]byte");break;case"date":case"dateTime":e.writeNode(pt);break;case"error":e.write("error");break;case"float64":e.write("float64");break;case"int":e.write("int");break;case"int64":e.write("int64");break;case"map":{e.write("map["),this.internalType.keyType.write(e),e.write("]"),this.internalType.valueType.write(e);break}case"optional":{e.write("*"),this.internalType.value.write(e);break}case"reference":e.writeNode(this.internalType.value);break;case"slice":e.write("[]"),this.internalType.value.write(e);break;case"string":e.write("string");break;case"uuid":e.writeNode(lt);break;case"variadic":e.write("..."),this.internalType.value.write(e);break;default:U(this.internalType)}}isOptional(){return this.internalType.type==="optional"}isIterable(){return this.internalType.type==="slice"||this.internalType.type==="variadic"}iterableElement(){if(this.internalType.type==="slice"||this.internalType.type==="variadic")return this.internalType.value}underlying(){return this.internalType.type==="optional"?this.internalType.value:this}static any(){return new this({type:"any"})}static bool(){return new this({type:"bool"})}static bytes(){return new this({type:"bytes"})}static date(){return new this({type:"date"})}static dateTime(){return new this({type:"dateTime"})}static dereference(e){return e.internalType.type==="optional"?e.internalType.value:e}static error(){return new this({type:"error"})}static float64(){return new this({type:"float64"})}static int(){return new this({type:"int"})}static int64(){return new this({type:"int64"})}static map(e,i){return new this({type:"map",keyType:e,valueType:i})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return u.optional(e)}static reference(e){return new this({type:"reference",value:e})}static slice(e){return new this({type:"slice",value:e})}static string(){return new this({type:"string"})}static uuid(){return new this({type:"uuid"})}static variadic(e){return this.isAlreadyVariadic(e)?e:new this({type:"variadic",value:e})}static isAlreadyOptional(e){return e.internalType.type==="optional"||Po.has(e.internalType.type)}static isAlreadyVariadic(e){return e.internalType.type==="variadic"}},pt=new J({importPath:"time",name:"Time"}),lt=new J({importPath:"github.com/google/uuid",name:"UUID"}),Ut=new J({importPath:"io",name:"Reader"});y();w();g();var Be=class extends P{constructor({name:e,type:i,docs:a}){super();m(this,"name");m(this,"type");m(this,"docs");this.name=e,this.type=i,this.docs=a}write(e){e.writeNode(new j({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" "),e.writeNode(this.type)}};function Bo(u){return new xe(u)}function So(u){return new ie(u)}function Co(u){return new Ee(u)}function Uo(u){return new Ne(u)}function Lo(u={}){return new be(u)}function _o(u){return new Ae(u)}function Mo(u){return new ue(u)}function $o(u){return new ee(u)}function Do(u){return new pe(u)}function Oo(u){return new le(u)}function Vo(u){return new Re(u)}function Wo(u){return new Fe(u)}function qo(u){return new ke(u)}function Go(u={}){return new Pe(u)}function jo(u){return new Qe(u)}function Ho(u){return new Be(u)}function zo(u){return new J(u)}y();w();g();var Yo=new Set(["string"]);function Lt(u){if(u==="")return"Underscore";let t=u;for(;t.startsWith("_");)t=t.slice(1);if(t==="")return"Underscore";if(t.length>0&&/^\d/.test(t))return"Field"+t;let e=t,i=t[0];return t.length>0&&i!=null&&i!==i.toUpperCase()&&(e=i.toUpperCase()+t.slice(1)),Yo.has(e.toLowerCase())?"Field"+e:e}y();w();g();Fr();var Ko="sdk";function _t({config:u,customConfig:t}){let e=Xo({config:u}),i=Jo({config:u,customConfig:t});return e!=null?Zo({importPath:i,majorVersion:e}):i}function Jo({config:u,customConfig:t,isModulePath:e=!1}){let i=t?.importPath??t?.module?.path??(u.output.mode.type==="github"?es(u.output.mode.repoUrl,"https://"):Ko);return e?i:q.join(i,t?.packagePath??"")}function Xo({config:u}){let t=Qo({config:u});if(!(t==null||t==="v0"||t==="v1"))return`${t}`}function Qo({config:u}){let t=ts(u);if(t==null)return;let e=t.split(".");if(e[0]==null)return;let i=e[0];return i.startsWith("v")?i:`v${i}`}function Zo({importPath:u,majorVersion:t}){return Ke(u)===t?u:`${u}/${t}`}function es(u,t){return u.startsWith(t)?u.slice(t.length):u}function ts(u){let t=u?.output?.mode;if(t!=null)return t.type==="github"||t.type==="publish"?t.version:void 0}y();w();g();var dt=class{constructor({context:t}){m(this,"context");this.context=t}convert(t){if(t.value===null&&!this.context.isNullable(t.typeReference)&&this.context.errors.add({severity:L.Critical,message:"Expected non-null value, but got null"}),t.value==null)return l.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return l.TypeInstantiation.nop();case"map":return this.convertMap({map:t.typeReference,value:t.value});case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?l.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"nullable":{let e=t.typeReference.value;if(e.type==="named"){let i=this.context.resolveNamedType({typeId:e.value});if(i?.type==="alias"&&["list","set","map"].includes(i.typeReference.type)){let a=this.convert({typeReference:i.typeReference,value:t.value,as:t.as}),p=this.context.getTypeName(i.declaration.name),s=this.context.getImportPath(i.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:a,aliasName:p,aliasImportPath:s})}if(i?.type==="alias"&&i.typeReference.type==="literal")return this.convertLiteralToOptionalPrimitive(i.typeReference.value)}return l.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"optional":{let e=t.typeReference.value;if(e.type==="named"){let i=this.context.resolveNamedType({typeId:e.value});if(i?.type==="alias"&&["list","set","map"].includes(i.typeReference.type)){let a=this.convert({typeReference:i.typeReference,value:t.value,as:t.as}),p=this.context.getTypeName(i.declaration.name),s=this.context.getImportPath(i.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:a,aliasName:p,aliasImportPath:s})}if(i?.type==="alias"&&i.typeReference.type==="literal")return this.convertLiteralToOptionalPrimitive(i.typeReference.value)}return l.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"primitive":return this.convertPrimitive({primitive:t.typeReference.value,value:t.value,as:t.as});case"set":return this.convertList({list:t.typeReference.value,value:t.value});case"unknown":return this.convertUnknown({value:t.value});default:U(t.typeReference)}}convertToPointerIfPossible(t){let e=this.convert(t);switch(t.typeReference.type){case"named":return this.context.resolveNamedType({typeId:t.typeReference.value})?.type==="enum"?l.TypeInstantiation.reference(l.invokeMethod({on:e,method:"Ptr",arguments_:[]})):e;default:return e}}convertList({list:t,value:e}){return Array.isArray(e)?l.TypeInstantiation.slice({valueType:this.context.dynamicTypeMapper.convert({typeReference:t}),values:e.map((i,a)=>{this.context.errors.scope({index:a});try{return this.convert({typeReference:t,value:i})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:L.Critical,message:`Expected array but got: ${typeof e}`}),l.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:L.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),l.TypeInstantiation.nop()):l.TypeInstantiation.map({keyType:this.context.dynamicTypeMapper.convert({typeReference:t.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:t.value}),entries:Object.entries(e).map(([i,a])=>{this.context.errors.scope(i);try{return{key:this.convert({typeReference:t.key,value:i,as:"key"}),value:this.convert({typeReference:t.value,value:a})}}finally{this.context.errors.unscope()}})})}convertNamed({named:t,value:e,as:i}){switch(t.type){case"alias":return this.convertAlias({aliasType:t,value:e,as:i});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:t,value:e});case"enum":return this.convertEnum({enum_:t,value:e});case"object":return this.convertObject({object_:t,value:e});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e});default:U(t)}}convertAlias({aliasType:t,value:e,as:i}){switch(t.typeReference.type){case"literal":return l.TypeInstantiation.reference(l.invokeFunc({func:l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),arguments_:[this.convertLiteralValue(t.typeReference.value)]}));default:return this.convert({typeReference:t.typeReference,value:e,as:i})}}reconstructAliasCollectionLiteral({collectionLiteral:t,aliasName:e,aliasImportPath:i}){let a=t.internalType;return a.type==="slice"?l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(l.typeReference({name:e,importPath:i}));let s=a.values;if(s.length===0){p.write("{}");return}p.writeLine("{"),p.indent();for(let f of s)p.writeNode(f),p.writeLine(",");p.dedent(),p.write("}")})):a.type==="map"?l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(l.typeReference({name:e,importPath:i}));let s=a.entries;if(s.length===0){p.write("{}");return}p.writeLine("{"),p.indent();for(let f of s)p.writeNode(f.key),p.write(": "),p.writeNode(f.value),p.writeLine(",");p.dedent(),p.write("}")})):l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(t)}))}convertLiteralValue(t){switch(t.type){case"boolean":return l.TypeInstantiation.bool(t.value);case"string":return l.TypeInstantiation.string(t.value);default:U(t)}}convertLiteralToOptionalPrimitive(t){switch(t.type){case"boolean":return l.TypeInstantiation.optional(l.TypeInstantiation.bool(t.value));case"string":return l.TypeInstantiation.optional(l.TypeInstantiation.string(t.value));default:U(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let i=this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),a=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(a==null)return l.TypeInstantiation.nop();let p=a.singleDiscriminatedUnionType,s=this.getBaseFields({discriminatedUnionTypeInstance:a,singleDiscriminatedUnionType:p});switch(p.type){case"samePropertiesAsObject":{let f=this.context.resolveNamedType({typeId:p.typeId});return f==null?l.TypeInstantiation.nop():l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(p.discriminantValue.name),value:this.convertNamed({named:f,value:a.value})},...s]})}case"singleProperty":{let f=this.context.getRecord(a.value);if(f==null)return l.TypeInstantiation.nop();try{return this.context.errors.scope(p.discriminantValue.wireValue),l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(p.discriminantValue.name),value:this.convert({typeReference:p.typeReference,value:f[p.discriminantValue.wireValue]})},...s]})}finally{this.context.errors.unscope()}}case"noProperties":return l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(a.discriminantValue.name),value:l.TypeInstantiation.string(p.discriminantValue.wireValue)},...s]});default:U(p)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){return this.context.associateByWireValue({parameters:e.properties??[],values:this.context.getRecord(t.value)??{},ignoreMissingParameters:!0}).map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getFieldName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})}convertObject({object_:t,value:e}){let i=this.context.associateByWireValue({parameters:t.properties,values:this.context.getRecord(e)??{}});return l.TypeInstantiation.structPointer({typeReference:l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),fields:i.map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getFieldName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:t,value:e}){let i=this.getEnumValueName({enum_:t,value:e});return i==null?l.TypeInstantiation.nop():l.TypeInstantiation.enum(l.typeReference({name:i,importPath:this.context.getImportPath(t.declaration.fernFilepath)}))}getEnumValueName({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:L.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let i=t.values.find(a=>a.wireValue===e);if(i==null){this.context.errors.add({severity:L.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return`${this.context.getTypeName(t.declaration.name)}${this.context.getTypeName(i.name)}`}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let i=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});if(i==null)return l.TypeInstantiation.nop();let a=this.getUndiscriminatedUnionFieldName({typeReference:i.valueTypeReference});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.structPointer({typeReference:this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),fields:[{name:a,value:i.typeInstantiation}]})}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let i of t.types)try{let a=this.convert({typeReference:i,value:e});return{valueTypeReference:i,typeInstantiation:a}}catch{continue}this.context.errors.add({severity:L.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof e}" value`})}getUndiscriminatedUnionFieldName({typeReference:t}){switch(t.type){case"list":return this.getUndiscriminatedUnionFieldNameForList({list:t});case"literal":return this.getUndiscriminatedUnionFieldNameForLiteral({literal:t.value});case"map":return this.getUndiscriminatedUnionFieldNameForMap({map:t});case"named":{let e=this.context.resolveNamedType({typeId:t.value});return e==null?void 0:this.context.getTypeName(e.declaration.name)}case"optional":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:t});case"nullable":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:t});case"primitive":return this.getUndiscriminatedUnionFieldNameForPrimitive({primitive:t.value});case"set":return this.getUndiscriminatedUnionFieldNameForSet({set:t});case"unknown":return"Unknown";default:U(t)}}getUndiscriminatedUnionFieldNameForList({list:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}List`}getUndiscriminatedUnionFieldNameForMap({map:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t.key});if(e==null)return;let i=this.getUndiscriminatedUnionFieldName({typeReference:t.value});if(i!=null)return`${e}${i}Map`}getUndiscriminatedUnionFieldNameForOptional({typeReference:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}Optional`}getUndiscriminatedUnionFieldNameForSet({set:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}Set`}getUndiscriminatedUnionFieldNameForLiteral({literal:t}){switch(t.type){case"boolean":return t.value?"TrueLiteral":"FalseLiteral";case"string":return`${t.value}StringLiteral`;default:U(t)}}getUndiscriminatedUnionFieldNameForPrimitive({primitive:t}){switch(t){case"INTEGER":case"UINT":return"Integer";case"LONG":case"UINT_64":return"Long";case"FLOAT":case"DOUBLE":return"Double";case"BOOLEAN":return"Boolean";case"BIG_INTEGER":case"STRING":return"String";case"UUID":return"Uuid";case"DATE":return"Date";case"DATE_TIME":return"DateTime";case"BASE_64":return"Base64";default:U(t)}}convertUnknown({value:t}){return l.TypeInstantiation.any(t)}convertPrimitive({primitive:t,value:e,as:i}){switch(t){case"INTEGER":case"UINT":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.int(a)}case"LONG":case"UINT_64":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.int64(a)}case"FLOAT":case"DOUBLE":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.float64(a)}case"BOOLEAN":{let a=this.getValueAsBoolean({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.bool(a)}case"STRING":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.string(a)}case"DATE":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.date(a)}case"DATE_TIME":{let a=this.context.getValueAsString({value:e});if(a==null)return l.TypeInstantiation.nop();let p=this.normalizeDateTimeString(a);return l.TypeInstantiation.dateTime(p)}case"UUID":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.uuid(a)}case"BASE_64":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.bytes(a)}case"BIG_INTEGER":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.string(a)}default:U(t)}}getValueAsNumber({value:t,as:e}){let i=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:i})}getValueAsBoolean({value:t,as:e}){let i=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:i})}normalizeDateTimeString(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?`${t}T00:00:00Z`:/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(t)?`${t}Z`:t}};y();w();g();var ft=class{constructor({context:t}){m(this,"context");this.context=t}convert(t){switch(t.typeReference.type){case"list":return l.Type.slice(this.convert({typeReference:t.typeReference.value}));case"literal":return this.convertLiteral({literal:t.typeReference.value});case"map":return l.Type.map(this.convert({typeReference:t.typeReference.key}),this.convert({typeReference:t.typeReference.value}));case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?this.convertUnknown():this.convertNamed({named:e})}case"optional":return l.Type.optional(this.convert({typeReference:t.typeReference.value}));case"nullable":return l.Type.optional(this.convert({typeReference:t.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:t.typeReference.value});case"set":return l.Type.slice(this.convert({typeReference:t.typeReference}));case"unknown":return this.convertUnknown();default:U(t.typeReference)}}convertLiteral({literal:t}){switch(t.type){case"boolean":return l.Type.bool();case"string":return l.Type.string()}}convertNamed({named:t}){let e=l.Type.reference(l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}));switch(t.type){case"alias":case"enum":return e;case"discriminatedUnion":case"object":case"undiscriminatedUnion":return l.Type.pointer(e);default:U(t)}}convertUnknown(){return l.Type.any()}convertPrimitive({primitive:t}){switch(t){case"INTEGER":return l.Type.int();case"UINT":return l.Type.int();case"LONG":return l.Type.int64();case"UINT_64":return l.Type.int64();case"FLOAT":return l.Type.float64();case"DOUBLE":return l.Type.float64();case"BOOLEAN":return l.Type.bool();case"STRING":return l.Type.string();case"DATE":return l.Type.date();case"DATE_TIME":return l.Type.dateTime();case"UUID":return l.Type.uuid();case"BASE_64":return l.Type.bytes();case"BIG_INTEGER":return l.Type.string();default:U(t)}}};y();w();g();var ht=class{constructor({context:t}){m(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){let i={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(e)??{};for(let p of t.properties)switch(p.type){case"file":i.fileFields.push({name:this.context.getFieldName(p.name),value:this.getSingleFileProperty({property:p,record:a})});break;case"fileArray":i.fileFields.push({name:this.context.getFieldName(p.name),value:this.getArrayFileProperty({property:p,record:a})});break;case"bodyProperty":i.bodyPropertyFields.push({name:this.context.getFieldName(p.name.name),value:this.getBodyProperty({property:p,record:a})});break;default:U(p)}return i}getSingleFileProperty({property:t,record:e}){let i=this.context.getSingleFileValue({property:t,record:e})||"";return l.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(i))}getArrayFileProperty({property:t,record:e}){let i=this.context.getFileArrayValues({property:t,record:e});return i==null?l.TypeInstantiation.nop():l.TypeInstantiation.slice({valueType:l.Type.reference(this.context.getIoReaderTypeReference()),values:i.map(a=>l.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(a)))})}getBodyProperty({property:t,record:e}){let i=e[t.name.wireValue];return i==null?l.TypeInstantiation.nop():this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:i})}};var mt=class u extends Ye{constructor({ir:e,config:i}){super({ir:e,config:i});m(this,"ir");m(this,"customConfig");m(this,"dynamicTypeMapper");m(this,"dynamicTypeInstantiationMapper");m(this,"filePropertyMapper");m(this,"rootImportPath");this.ir=e,this.customConfig=i.customConfig!=null?i.customConfig:void 0,this.dynamicTypeMapper=new ft({context:this}),this.dynamicTypeInstantiationMapper=new dt({context:this}),this.filePropertyMapper=new ht({context:this}),this.rootImportPath=_t({config:i,customConfig:this.customConfig})}clone(){return new u({ir:this.ir,config:this.config})}isOptional(e){switch(e.type){case"optional":case"map":return!0;case"nullable":case"list":case"set":return this.isOptional(e.value);case"named":case"literal":case"primitive":case"unknown":return!1;default:U(e)}}getMethodName(e){return e.pascalCase.unsafeName}getTestMethodName(e){return e.declaration.fernFilepath.allParts.map(i=>i.pascalCase.unsafeName).join("")+e.declaration.name.pascalCase.unsafeName}getTypeName(e){return e.pascalCase.unsafeName}getFieldName(e){return Lt(e.pascalCase.unsafeName)}getImportPath(e){let i=e.packagePath.map(a=>a.pascalCase.unsafeName.toLowerCase());return[this.rootImportPath,...i].join("/")}getImportPathForRequest(e){return this.customConfig?.exportAllRequestsAtRoot?this.rootImportPath:this.getImportPath(e)}getContextTypeReference(){return l.typeReference({name:"Context",importPath:"context"})}getContextTodoFunctionInvocation(){return l.invokeFunc({func:l.typeReference({name:"TODO",importPath:"context"}),arguments_:[]})}getIoReaderTypeReference(){return l.typeReference({name:"Reader",importPath:"io"})}getTestingTypeReference(){return l.typeReference({name:"T",importPath:"testing"})}getNewStringsReaderFunctionInvocation(e){return l.invokeFunc({func:l.typeReference({name:"NewReader",importPath:"strings"}),arguments_:[l.TypeInstantiation.string(e)]})}getClientConstructorName(){return this.customConfig?.clientConstructorName!=null?this.customConfig.clientConstructorName:this.customConfig?.exportedClientName!=null?`New${this.customConfig.exportedClientName}`:`New${this.getClientName()}`}getClientName(){return this.customConfig?.clientName!=null?this.customConfig.clientName:"Client"}getClientImportPath(){return`${this.rootImportPath}/client`}getOptionImportPath(){return`${this.rootImportPath}/option`}getGoTypeReferenceFromDeclaration({declaration:e}){return l.typeReference({name:e.name.pascalCase.unsafeName,importPath:this.getImportPath(e.fernFilepath)})}getEnvironmentTypeReferenceFromID(e){let i=this.resolveEnvironmentName(e);if(i!=null)return this.getEnvironmentTypeReference(i)}getEnvironmentTypeReference(e){return l.typeReference({name:`Environments.${this.getTypeName(e)}`,importPath:this.rootImportPath})}static chainMethods(e,...i){if(i.length===0)throw new Error("Must have methods to chain");let a=e;for(let p of i)a=l.invokeMethod({on:a,method:p.method,arguments_:p.arguments_,multiline:p.multiline});return a}};y();w();g();var Br="example",Mt="fern",ns="do",et="client",Me=l.TypeInstantiation,rs="WireMockBaseURL",is="WireMockClient",yt=class{constructor({context:t,formatter:e}){m(this,"context");m(this,"formatter");this.context=t,this.formatter=e}async generateSnippet({endpoint:t,request:e,options:i}){return i?.config?.outputWiremockTests??!1?this.generateWiremockTest({endpoint:t,snippet:e}):await this.buildCodeBlock({endpoint:t,snippet:e}).toStringAsync({packageName:Br,importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}generateSnippetSync({endpoint:t,request:e,options:i}){return i?.config?.outputWiremockTests??!1?this.generateWiremockTest({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e}).toString({packageName:Br,importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}async generateSnippetAst({endpoint:t,request:e,options:i}){throw new Error("Unsupported")}generateWiremockTest({endpoint:t,snippet:e}){return this.buildWiremockTestCodeBlock({endpoint:t,snippet:e}).toString({packageName:"wiremock",importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}buildCodeBlock({endpoint:t,snippet:e}){return l.codeblock(i=>{i.writeNode(l.func({name:ns,parameters:[],return_:[],body:l.codeblock(a=>{a.writeNode(this.constructClient({endpoint:t,snippet:e})),a.writeLine(),a.writeNode(this.callMethod({endpoint:t,snippet:e}))})})),i.writeNewLineIfLastLineNot()})}buildWiremockTestCodeBlock({endpoint:t,snippet:e}){return l.codeblock(i=>{i.writeNode(l.func({name:"Test"+this.context.getTestMethodName(t)+"WithWireMock",parameters:[l.parameter({name:"t",type:l.Type.pointer(l.Type.reference(this.context.getTestingTypeReference()))})],return_:[],body:l.codeblock(a=>{for(let p of this.buildWiremockTestSetup({endpoint:t}))a.writeNode(p),a.writeLine();a.writeLine(),a.writeNode(this.constructWiremockTestClient({endpoint:t,snippet:e})),a.writeLine(),a.writeNode(this.callClientMethodAndAssert({endpoint:t,snippet:e,includeTestIdHeader:!0}))})})),i.writeNewLineIfLastLineNot()})}constructClient({endpoint:t,snippet:e}){return l.codeblock(i=>{i.write(`${et} := `),i.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:t,snippet:e})))})}constructWiremockTestClient({endpoint:t,snippet:e}){return l.codeblock(i=>{i.write(`${et} := `),i.writeNode(this.getRootClientFuncInvocation(this.getWiremockTestConstructorArgs()))})}writeMethodInvocation({writer:t,endpoint:e,snippet:i,includeTestIdHeader:a}){let{otherArgs:p,requestArg:s}=this.getMethodArgs({endpoint:e,snippet:i}),f=a?[l.codeblock(I=>{I.writeNode(l.invokeFunc({func:l.typeReference({name:"WithHTTPHeader",importPath:this.context.getOptionImportPath()}),arguments_:[l.codeblock('http.Header{"X-Test-Id": []string{"TEST-ID-PLACEHOLDER"}}')]}))})]:[];if(s!=null)if(s instanceof l.TypeInstantiation&&l.TypeInstantiation.isNop(s))t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,l.codeblock("nil")]}));else{t.write("request := "),t.writeNode(s),t.writeLine();let I=l.codeblock("request");t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,I,...f]}))}else t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,...f]}))}callMethod({endpoint:t,snippet:e}){return l.codeblock(i=>{this.writeMethodInvocation({writer:i,endpoint:t,snippet:e})})}getConstructorArgs({endpoint:t,snippet:e}){let i=[],a=this.getConstructorBaseUrlArg({baseUrl:e.baseURL,environment:e.environment});return a!=null&&i.push(a),t.auth!=null&&(e.auth!=null?i.push(this.getConstructorAuthArg({auth:t.auth,values:e.auth})):this.context.errors.add({severity:L.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(re.Headers),this.context.ir.headers!=null&&e.headers!=null&&i.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),i}getWiremockTestConstructorArgs(){return[l.codeblock(t=>{t.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[l.codeblock(rs)]}))})]}getConstructorAuthArg({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),Me.nop();switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArg({auth:t,values:e}):Me.nop();case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArg({auth:t,values:e}):Me.nop();case"header":return e.type==="header"?this.getConstructorHeaderAuthArg({auth:t,values:e}):Me.nop();case"oauth":return e.type==="oauth"?this.getConstructorOAuthAuthArg({values:e}):Me.nop();case"inferred":return this.addWarning("The Go SDK Generator does not support Inferred auth scheme yet"),Me.nop();default:U(t)}}addError(t){this.context.errors.add({severity:L.Critical,message:t})}addWarning(t){this.context.errors.add({severity:L.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(e.username),l.TypeInstantiation.string(e.password)]}))})}getConstructorBaseUrlArg({baseUrl:t,environment:e}){let i=this.getBaseUrlArg({baseUrl:t,environment:e});if(i!=null)return l.codeblock(a=>{a.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[i]}))})}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:L.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return l.TypeInstantiation.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let i=this.context.getEnvironmentTypeReferenceFromID(e);if(i==null){this.context.errors.add({severity:L.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return l.TypeInstantiation.reference(i)}this.context.isMultiEnvironmentValues(e)&&this.context.errors.add({severity:L.Warning,message:"The Go SDK doesn't support a multi-environment client option yet; use the baseUrl option instead"})}}getConstructorBearerAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(e.token)]}))})}getConstructorHeaderAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.header.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.header.typeReference,value:e.value})]}))})}getConstructorOAuthAuthArg({values:t}){return l.codeblock(e=>{e.writeNode(l.invokeFunc({func:l.typeReference({name:"WithClientCredentials",importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(t.clientId),l.TypeInstantiation.string(t.clientSecret)]}))})}getConstructorHeaderArgs({headers:t,values:e}){let i=[];for(let a of t){let p=this.getConstructorHeaderArg({header:a,value:e.value});p!=null&&i.push(p)}return i}getConstructorHeaderArg({header:t,value:e}){let i=this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:e});if(!l.TypeInstantiation.isNop(i))return l.codeblock(a=>{a.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[i]}))})}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:U(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let i=[];this.context.errors.scope(re.PathParameters);let a=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];a.length>0&&i.push(...this.getPathParameters({namedParameters:a,snippet:e}).map(s=>s.value)),this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let p=t.body!=null?this.getBodyRequestArg({body:t.body,value:e.requestBody}):void 0;return this.context.errors.unscope(),{otherArgs:i,requestArg:p}}getBodyRequestArg({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e});default:U(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:L.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),l.TypeInstantiation.nop()):l.TypeInstantiation.bytes(t)}getMethodArgsForInlinedRequest({request:t,snippet:e}){let i=[],{inlinePathParameters:a,inlineFileProperties:p}={inlinePathParameters:this.context.customConfig?.inlinePathParameters??!0,inlineFileProperties:this.context.customConfig?.inlineFileProperties??!0};this.context.errors.scope(re.PathParameters);let s=[],f=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];f.length>0&&s.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let I=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})||i.push(...s.map(E=>E.value)),p||i.push(...I.fileFields.map(E=>E.value));let x=this.context.needsRequestParameter({request:t,inlinePathParameters:a,inlineFileProperties:p})?this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})?s:[],filePropertyInfo:I}):void 0;return{otherArgs:i,requestArg:x}}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:i,filePropertyInfo:a}){this.context.errors.scope(re.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(E=>({name:E.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(E)}));this.context.errors.unscope(),this.context.errors.scope(re.Headers);let I=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(E=>({name:E.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(E)}));this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let x=t.body!=null?this.getInlinedRequestBodyStructFields({body:t.body,value:e.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),l.TypeInstantiation.structPointer({typeReference:l.typeReference({name:this.context.getMethodName(t.declaration.name),importPath:this.context.getImportPathForRequest(t.declaration.fernFilepath)}),fields:[...i,...s,...I,...x]})}getInlinedRequestBodyStructFields({body:t,value:e,filePropertyInfo:i}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyStructFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyStructField({body:t,value:e})];case"fileUpload":return this.getFileUploadRequestBodyStructFields({filePropertyInfo:i});default:U(t)}}getFileUploadRequestBodyStructFields({filePropertyInfo:t}){return this.context.customConfig?.inlineFileProperties?[...t.fileFields,...t.bodyPropertyFields]:t.bodyPropertyFields}getReferencedRequestBodyPropertyStructField({body:t,value:e}){return{name:this.context.getTypeName(t.bodyKey),value:this.getReferencedRequestBodyPropertyTypeInstantiation({body:t.bodyType,value:e})}}getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e});default:U(t)}}getInlinedRequestBodyPropertyStructFields({parameters:t,value:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}});for(let p of a)i.push({name:this.context.getTypeName(p.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(p)});return i}getPathParameters({namedParameters:t,snippet:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:e.pathParameters??{}});for(let p of a)i.push({name:this.context.getTypeName(p.name.name),value:this.context.dynamicTypeInstantiationMapper.convertToPointerIfPossible(p)});return i}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getMethodName(e)).join(".")}.${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getRootClientFuncInvocation(t){return l.invokeFunc({func:l.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:t})}buildWiremockTestSetup({endpoint:t,errorCase:e}){let i="stub";return[]}callClientMethodAndAssert({endpoint:t,snippet:e,includeTestIdHeader:i}){return l.codeblock(a=>{this.writeMethodInvocation({writer:a,endpoint:t,snippet:e,includeTestIdHeader:!0}),a.writeLine(),a.writeLine(),a.write("ok, countErr := "),a.writeNode(l.invokeMethod({on:l.codeblock(is),method:"Verify",arguments_:[l.invokeMethod({on:l.codeblock("stub"),method:"Request",arguments_:[],multiline:!1}),l.codeblock("1")],multiline:!1})),a.writeLine(),a.writeNode(l.invokeFunc({func:l.typeReference({name:"NoError",importPath:"github.com/stretchr/testify/require"}),arguments_:[l.codeblock("t"),l.codeblock("countErr"),l.TypeInstantiation.string("Failed to verify WireMock request was matched")],multiline:!1})),a.writeLine(),a.writeNode(l.invokeFunc({func:l.typeReference({name:"True",importPath:"github.com/stretchr/testify/require"}),arguments_:[l.codeblock("t"),l.codeblock("ok"),l.TypeInstantiation.string("WireMock request was not matched")],multiline:!1})),a.writeLine()})}};var $t=class extends je{constructor({ir:e,config:i,formatter:a}){super(new mt({ir:e,config:i}));m(this,"formatter");this.formatter=a}async generate(e,i){return super.generate(e,i)}generateSync(e,i){return super.generateSync(e,i)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new yt({context:e,formatter:this.formatter})}};export{$t as DynamicSnippetsGenerator};
26
+ `)?`\`${this.internalType.value}\``:`"${this.internalType.value}"`);break;case"struct":this.writeStruct({writer:e,struct:this.internalType});break;case"uuid":e.writeNode(Ao({value:this.internalType.value}));break;default:U(this.internalType)}}static any(e){return new this({type:"any",value:e})}static bool(e){return new this({type:"bool",value:e})}static bytes(e){return new this({type:"bytes",value:e})}static date(e){return new this({type:"date",value:e})}static dateTime(e){return new this({type:"dateTime",value:e})}static enum(e){return new this({type:"enum",typeReference:e})}static float64(e){return new this({type:"float64",value:e})}static int(e){return new this({type:"int",value:e})}static int64(e){return new this({type:"int64",value:e})}static map({keyType:e,valueType:i,entries:a}){return new this({type:"map",keyType:e,valueType:i,entries:a})}static nil(){return new this({type:"nil"})}static nop(){return new this({type:"nop"})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static reference(e){return new this({type:"reference",value:e})}static slice({valueType:e,values:i}){return new this({type:"slice",valueType:e,values:i})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:i}){return new this({type:"struct",typeReference:e,fields:i})}static structPointer({typeReference:e,fields:i,generics:a}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:i,generics:a})})}static uuid(e){return new this({type:"uuid",value:e})}static isNop(e){return e.internalType.type==="optional"?this.isNop(e.internalType.value):e.internalType.type==="nop"}writeAny({writer:e,value:i}){switch(typeof i){case"boolean":e.write(i.toString());return;case"string":e.write(i.includes('"')||i.includes(`
27
+ `)?`\`${i}\``:`"${i}"`);return;case"number":e.write(i.toString());return;case"object":if(i==null){e.write("nil");return}if(Array.isArray(i)){this.writeAnyArray({writer:e,value:i});return}this.writeAnyObject({writer:e,value:i});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof i}`)}}writeAnyArray({writer:e,value:i}){if(e.write("[]any"),i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let a of i)e.writeNode(u.any(a)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:i}){e.write("map[string]any");let a=Object.entries(i);if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[p,s]of a)e.write(`"${p}": `),e.writeNode(u.any(s)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:i}){e.write("map["),e.writeNode(i.keyType),e.write("]"),e.writeNode(i.valueType);let a=Ro({entries:i.entries});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)p.key.write(e),e.write(": "),p.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeOptional({writer:e,type:i}){if(xo.has(i.internalType.type)){e.writeNode(Eo({writer:e,type:i}));return}if(Pr.has(i.internalType.type)){i.write(e);return}if(i.internalType.type==="enum"){e.writeNode(new pe({on:i.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),i.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||Pr.has(e.internalType.type)}writeSlice({writer:e,slice:i}){e.write("[]"),e.writeNode(i.valueType);let a=ko({values:i.values});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)p.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeStruct({writer:e,struct:i}){e.writeNode(i.typeReference),i.generics!=null&&(e.write("["),i.generics.forEach((p,s)=>{s>0&&e.write(", "),e.writeNode(p)}),e.write("]"));let a=Fo({fields:i.fields});if(a.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let p of a)e.write(`${p.name}: `),p.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function Eo({writer:u,type:t}){return new ee({func:new J({name:No({type:t}),importPath:u.rootImportPath}),arguments_:[t]})}function No({type:u}){switch(u.internalType.type){case"bool":return"Bool";case"date":case"dateTime":return"Time";case"float64":return"Float64";case"int":return"Int";case"int64":return"Int64";case"string":return"String";case"uuid":return"UUID";default:return""}}function bo({writer:u,type:t}){let e=t.type==="date"?"MustParseDate":"MustParseDateTime";return new ee({func:new J({name:e,importPath:u.rootImportPath}),arguments_:[new ie(`"${t.value}"`)]})}function Ao({value:u}){return new ee({func:new J({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new ie(`"${u}"`)]})}function Ro({entries:u}){return u.filter(t=>!K.isNop(t.key)&&!K.isNop(t.value))}function Fo({fields:u}){return u.filter(t=>!K.isNop(t.value))}function ko({values:u}){return u.filter(t=>!K.isNop(t))}var Ee=class u extends P{constructor({name:e,docs:i}){super();m(this,"name");m(this,"docs");m(this,"members",[]);m(this,"methods",[]);m(this,"constructor_");this.name=e,this.docs=i}addConstructor(e){this.constructor_=e}addMember(e){this.members.push(e)}addMethod(e){this.methods.push(e)}write(e){this.writeType({writer:e}),this.writeMembers({writer:e}),this.writeConstructor({writer:e}),this.writeMethods({writer:e})}writeType({writer:e}){e.writeNode(new j({docs:this.docs})),e.writeLine(`type ${this.name} string`)}writeMembers({writer:e}){if(this.members.length!==0){e.newLine(),e.writeLine("const ("),e.indent();for(let i of this.members)e.writeNode(new j({docs:i.docs})),e.writeNode(u.getMemberIdentifier({name:this.name,member:i})),e.write(" = "),e.writeNode(K.string(i.value)),e.newLine();e.dedent(),e.write(")")}}writeConstructor({writer:e}){this.constructor_!=null&&(e.newLine(),e.writeNode(this.constructor_))}writeMethods({writer:e}){e.newLine();for(let i of this.methods)e.newLine(),e.writeNode(i),e.newLine()}static getMemberIdentifier({name:e,member:i}){return new ue(`${e}${i.name}`)}};y();w();g();var Ne=class extends P{constructor({name:e,type:i,docs:a,tags:p}){super();m(this,"name");m(this,"type");m(this,"docs");m(this,"tags",[]);this.name=e,this.type=i,this.docs=a,this.tags=p??[]}addTags(...e){this.tags.push(...e)}write(e){e.writeNode(new j({docs:this.docs})),e.write(`${this.name} `),this.type.write(e),this.writeTags({writer:e})}writeTags({writer:e}){this.tags.length!==0&&(e.write(" `"),this.tags.forEach((i,a)=>{a>0&&e.write(" "),e.write(`${i.name}:"${i.value}"`)}),e.write("`"))}};y();w();g();var be=class extends P{constructor({nodes:e}={nodes:[]}){super();m(this,"nodes");this.nodes=e??[]}add(...e){this.nodes.push(...e)}write(e){for(let i of this.nodes)i.write(e)}};y();w();g();y();w();g();var le=class extends P{constructor({name:e,parameters:i,return_:a,body:p,docs:s,typeReference:f,multiline:I,receiver:x,pointerReceiver:E}){super();m(this,"parameters");m(this,"return_");m(this,"name");m(this,"body");m(this,"docs");m(this,"typeReference");m(this,"multiline");m(this,"receiver");m(this,"pointerReceiver");this.name=e,this.parameters=i,this.return_=a,this.body=p,this.docs=s,this.typeReference=f,this.multiline=I,this.receiver=x,this.pointerReceiver=E}write(e){e.writeNode(new j({docs:this.docs})),e.write("func"),this.typeReference!=null&&this.writeReceiver({writer:e,typeReference:this.typeReference,receiver:this.receiver}),this.name!=null&&e.write(` ${this.name}`),_e({writer:e,arguments_:this.parameters,multiline:this.multiline}),this.return_!=null&&(e.write(" "),this.return_.length>1&&e.write("("),this.return_.forEach((i,a)=>{a>0&&e.write(", "),e.writeNode(i)}),this.return_.length>1&&e.write(")")),e.writeLine("{"),e.indent(),this.body?.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.write("}")}writeReceiver({writer:e,typeReference:i,receiver:a}){e.write(` (${this.getReceiverName({typeReference:i,receiver:a})} `),this.pointerReceiver&&e.write("*"),i.write(e),e.write(")")}getReceiverName({typeReference:e,receiver:i}){return i??e.name.charAt(0).toLowerCase()}};var Ae=class extends P{constructor({name:e,parameters:i,return_:a,body:p,docs:s,multiline:f}){super();m(this,"func");this.func=new le({name:e,parameters:i,return_:a,body:p,docs:s,multiline:f})}get parameters(){return this.func.parameters}get return_(){return this.func.return_}get name(){return this.func.name}get body(){return this.func.body}get docs(){return this.func.docs}write(e){e.writeNode(this.func)}};y();w();g();var Xe=class extends P{constructor({nodes:e}){super();m(this,"nodes");this.nodes=e}write(e){for(let i of this.nodes)e.newLine(),i.write(e),e.newLine()}};y();w();g();var Re=class extends P{constructor({name:e,type:i,docs:a}){super();m(this,"name");m(this,"type");m(this,"docs");this.name=e,this.type=i,this.docs=a}write(e){e.writeNode(new j({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};y();w();g();var Fe=class extends P{constructor({node:e}){super();m(this,"node");this.node=e}write(e){e.write("*"),this.node.write(e)}};y();w();g();var ke=class extends P{constructor({on:e,selector:i}){super();m(this,"on");m(this,"selector");this.on=e,this.selector=i}write(e){e.writeNode(this.on),e.write("."),e.writeNode(this.selector)}};y();w();g();var Pe=class extends P{constructor({name:e,embeds:i,fields:a,docs:p}){super();m(this,"name");m(this,"embeds",[]);m(this,"fields",[]);m(this,"docs");m(this,"methods",[]);m(this,"constructor_");this.name=e,this.docs=p,this.embeds=i??[],this.fields=a??[]}addConstructor(e){this.constructor_=e}addField(...e){this.fields.push(...e)}addMethod(...e){this.methods.push(...e)}write(e){this.writeType({writer:e}),this.constructor_!=null&&(e.newLine(),e.newLine(),this.writeConstructor({writer:e,constructor:this.constructor_})),this.writeMethods({writer:e})}writeType({writer:e}){if(e.writeNode(new j({docs:this.docs})),this.name!=null?e.write(`type ${this.name} struct {`):e.write("struct{"),this.embeds.length===0&&this.fields.length===0){e.writeLine("}");return}e.newLine(),e.indent();for(let p of this.embeds)e.writeNode(p),e.newLine();let i=this.fields.filter(p=>this.isExported(p));for(let p of i)e.writeNode(p),e.newLine();let a=this.fields.filter(p=>!this.isExported(p));i.length>0&&a.length>0&&e.newLine();for(let p of a)e.writeNode(p),e.newLine();e.dedent(),e.write("}")}writeConstructor({writer:e,constructor:i}){i.name!=null?e.write(`func ${i.name}(`):e.write(`func New${this.name}(`),i.parameters.forEach((a,p)=>{p>0&&e.write(", "),e.writeNode(a)}),e.write(`) *${this.name} {`),e.newLine(),e.indent(),e.writeNode(i.body),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeMethods({writer:e}){if(this.methods.length!==0){e.writeNewLineIfLastLineNot();for(let i of this.methods)e.newLine(),e.writeNode(i),e.newLine()}}isExported(e){let i=e.name.charAt(0);return i===i.toUpperCase()}};y();w();g();var Qe=class extends P{constructor({on:e,cases:i,default:a}){super();m(this,"on");m(this,"cases");m(this,"default");this.on=e,this.cases=i,this.default=a}write(e){let i=this.cases;this.default!=null&&i.push({on:new ue("default"),body:this.default}),e.write("switch "),e.writeNode(this.on),e.writeLine("{"),e.indent();for(let a of i)e.write("case "),e.writeNode(a.on),e.writeLine(":"),e.indent(),e.writeNode(a.body),e.dedent(),e.writeNewLineIfLastLineNot();e.dedent(),e.write("}")}};y();w();g();var Po=new Set(["any","bytes","map","slice"]),Ze=class u extends P{constructor(e){super();m(this,"internalType");this.internalType=e}write(e,{comment:i}={}){switch(this.internalType.type){case"any":e.write("any");break;case"bool":e.write("bool");break;case"bytes":e.write("[]byte");break;case"date":case"dateTime":e.writeNode(pt);break;case"error":e.write("error");break;case"float64":e.write("float64");break;case"int":e.write("int");break;case"int64":e.write("int64");break;case"map":{e.write("map["),this.internalType.keyType.write(e),e.write("]"),this.internalType.valueType.write(e);break}case"optional":{e.write("*"),this.internalType.value.write(e);break}case"reference":e.writeNode(this.internalType.value);break;case"slice":e.write("[]"),this.internalType.value.write(e);break;case"string":e.write("string");break;case"uuid":e.writeNode(lt);break;case"variadic":e.write("..."),this.internalType.value.write(e);break;default:U(this.internalType)}}isOptional(){return this.internalType.type==="optional"}isIterable(){return this.internalType.type==="slice"||this.internalType.type==="variadic"}iterableElement(){if(this.internalType.type==="slice"||this.internalType.type==="variadic")return this.internalType.value}underlying(){return this.internalType.type==="optional"?this.internalType.value:this}static any(){return new this({type:"any"})}static bool(){return new this({type:"bool"})}static bytes(){return new this({type:"bytes"})}static date(){return new this({type:"date"})}static dateTime(){return new this({type:"dateTime"})}static dereference(e){return e.internalType.type==="optional"?e.internalType.value:e}static error(){return new this({type:"error"})}static float64(){return new this({type:"float64"})}static int(){return new this({type:"int"})}static int64(){return new this({type:"int64"})}static map(e,i){return new this({type:"map",keyType:e,valueType:i})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return u.optional(e)}static reference(e){return new this({type:"reference",value:e})}static slice(e){return new this({type:"slice",value:e})}static string(){return new this({type:"string"})}static uuid(){return new this({type:"uuid"})}static variadic(e){return this.isAlreadyVariadic(e)?e:new this({type:"variadic",value:e})}static isAlreadyOptional(e){return e.internalType.type==="optional"||Po.has(e.internalType.type)}static isAlreadyVariadic(e){return e.internalType.type==="variadic"}},pt=new J({importPath:"time",name:"Time"}),lt=new J({importPath:"github.com/google/uuid",name:"UUID"}),Ut=new J({importPath:"io",name:"Reader"});y();w();g();var Be=class extends P{constructor({name:e,type:i,docs:a}){super();m(this,"name");m(this,"type");m(this,"docs");this.name=e,this.type=i,this.docs=a}write(e){e.writeNode(new j({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" "),e.writeNode(this.type)}};function Bo(u){return new xe(u)}function So(u){return new ie(u)}function Co(u){return new Ee(u)}function Uo(u){return new Ne(u)}function Lo(u={}){return new be(u)}function _o(u){return new Ae(u)}function Mo(u){return new ue(u)}function $o(u){return new ee(u)}function Do(u){return new pe(u)}function Oo(u){return new le(u)}function Vo(u){return new Re(u)}function Wo(u){return new Fe(u)}function qo(u){return new ke(u)}function Go(u={}){return new Pe(u)}function jo(u){return new Qe(u)}function Ho(u){return new Be(u)}function zo(u){return new J(u)}y();w();g();var Yo=new Set(["string"]);function Lt(u){if(u==="")return"Underscore";let t=u;for(;t.startsWith("_");)t=t.slice(1);if(t==="")return"Underscore";if(t.length>0&&/^\d/.test(t))return"Field"+t;let e=t,i=t[0];return t.length>0&&i!=null&&i!==i.toUpperCase()&&(e=i.toUpperCase()+t.slice(1)),Yo.has(e.toLowerCase())?"Field"+e:e}y();w();g();Fr();var Ko="sdk";function _t({config:u,customConfig:t}){let e=Xo({config:u}),i=Jo({config:u,customConfig:t});return e!=null?Zo({importPath:i,majorVersion:e}):i}function Jo({config:u,customConfig:t,isModulePath:e=!1}){let i=t?.importPath??t?.module?.path??(u.output.mode.type==="github"?es(u.output.mode.repoUrl,"https://"):Ko);return e?i:q.join(i,t?.packagePath??"")}function Xo({config:u}){let t=Qo({config:u});if(!(t==null||t==="v0"||t==="v1"))return`${t}`}function Qo({config:u}){let t=ts(u);if(t==null)return;let e=t.split(".");if(e[0]==null)return;let i=e[0];return i.startsWith("v")?i:`v${i}`}function Zo({importPath:u,majorVersion:t}){return Ke(u)===t?u:`${u}/${t}`}function es(u,t){return u.startsWith(t)?u.slice(t.length):u}function ts(u){let t=u?.output?.mode;if(t!=null)return t.type==="github"||t.type==="publish"?t.version:void 0}y();w();g();var dt=class{constructor({context:t}){m(this,"context");this.context=t}convert(t){if(t.value===null&&!this.context.isNullable(t.typeReference)&&this.context.errors.add({severity:L.Critical,message:"Expected non-null value, but got null"}),t.value==null)return l.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return l.TypeInstantiation.nop();case"map":return this.convertMap({map:t.typeReference,value:t.value});case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?l.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"nullable":{let e=t.typeReference.value;if(e.type==="named"){let i=this.context.resolveNamedType({typeId:e.value});if(i?.type==="alias"&&["list","set","map"].includes(i.typeReference.type)){let a=this.convert({typeReference:i.typeReference,value:t.value,as:t.as}),p=this.context.getTypeName(i.declaration.name),s=this.context.getImportPath(i.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:a,aliasName:p,aliasImportPath:s})}if(i?.type==="alias"&&i.typeReference.type==="literal")return this.convertLiteralToOptionalPrimitive(i.typeReference.value)}return l.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"optional":{let e=t.typeReference.value;if(e.type==="named"){let i=this.context.resolveNamedType({typeId:e.value});if(i?.type==="alias"&&["list","set","map"].includes(i.typeReference.type)){let a=this.convert({typeReference:i.typeReference,value:t.value,as:t.as}),p=this.context.getTypeName(i.declaration.name),s=this.context.getImportPath(i.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:a,aliasName:p,aliasImportPath:s})}if(i?.type==="alias"&&i.typeReference.type==="literal")return this.convertLiteralToOptionalPrimitive(i.typeReference.value)}return l.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"primitive":return this.convertPrimitive({primitive:t.typeReference.value,value:t.value,as:t.as});case"set":return this.convertList({list:t.typeReference.value,value:t.value});case"unknown":return this.convertUnknown({value:t.value});default:U(t.typeReference)}}convertToPointerIfPossible(t){let e=this.convert(t);switch(t.typeReference.type){case"named":return this.context.resolveNamedType({typeId:t.typeReference.value})?.type==="enum"?l.TypeInstantiation.reference(l.invokeMethod({on:e,method:"Ptr",arguments_:[]})):e;default:return e}}convertList({list:t,value:e}){return Array.isArray(e)?l.TypeInstantiation.slice({valueType:this.context.dynamicTypeMapper.convert({typeReference:t}),values:e.map((i,a)=>{this.context.errors.scope({index:a});try{return this.convert({typeReference:t,value:i})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:L.Critical,message:`Expected array but got: ${typeof e}`}),l.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:L.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),l.TypeInstantiation.nop()):l.TypeInstantiation.map({keyType:this.context.dynamicTypeMapper.convert({typeReference:t.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:t.value}),entries:Object.entries(e).map(([i,a])=>{this.context.errors.scope(i);try{return{key:this.convert({typeReference:t.key,value:i,as:"key"}),value:this.convert({typeReference:t.value,value:a})}}finally{this.context.errors.unscope()}})})}convertNamed({named:t,value:e,as:i}){switch(t.type){case"alias":return this.convertAlias({aliasType:t,value:e,as:i});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:t,value:e});case"enum":return this.convertEnum({enum_:t,value:e});case"object":return this.convertObject({object_:t,value:e});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e});default:U(t)}}convertAlias({aliasType:t,value:e,as:i}){switch(t.typeReference.type){case"literal":return l.TypeInstantiation.reference(l.invokeFunc({func:l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),arguments_:[this.convertLiteralValue(t.typeReference.value)]}));default:return this.convert({typeReference:t.typeReference,value:e,as:i})}}reconstructAliasCollectionLiteral({collectionLiteral:t,aliasName:e,aliasImportPath:i}){let a=t.internalType;return a.type==="slice"?l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(l.typeReference({name:e,importPath:i}));let s=a.values;if(s.length===0){p.write("{}");return}p.writeLine("{"),p.indent();for(let f of s)p.writeNode(f),p.writeLine(",");p.dedent(),p.write("}")})):a.type==="map"?l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(l.typeReference({name:e,importPath:i}));let s=a.entries;if(s.length===0){p.write("{}");return}p.writeLine("{"),p.indent();for(let f of s)p.writeNode(f.key),p.write(": "),p.writeNode(f.value),p.writeLine(",");p.dedent(),p.write("}")})):l.TypeInstantiation.reference(l.codeblock(p=>{p.write("&"),p.writeNode(t)}))}convertLiteralValue(t){switch(t.type){case"boolean":return l.TypeInstantiation.bool(t.value);case"string":return l.TypeInstantiation.string(t.value);default:U(t)}}convertLiteralToOptionalPrimitive(t){switch(t.type){case"boolean":return l.TypeInstantiation.optional(l.TypeInstantiation.bool(t.value));case"string":return l.TypeInstantiation.optional(l.TypeInstantiation.string(t.value));default:U(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let i=this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),a=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(a==null)return l.TypeInstantiation.nop();let p=a.singleDiscriminatedUnionType,s=this.getBaseFields({discriminatedUnionTypeInstance:a,singleDiscriminatedUnionType:p});switch(p.type){case"samePropertiesAsObject":{let f=this.context.resolveNamedType({typeId:p.typeId});return f==null?l.TypeInstantiation.nop():l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(p.discriminantValue.name),value:this.convertNamed({named:f,value:a.value})},...s]})}case"singleProperty":{let f=this.context.getRecord(a.value);if(f==null)return l.TypeInstantiation.nop();try{return this.context.errors.scope(p.discriminantValue.wireValue),l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(p.discriminantValue.name),value:this.convert({typeReference:p.typeReference,value:f[p.discriminantValue.wireValue]})},...s]})}finally{this.context.errors.unscope()}}case"noProperties":return l.TypeInstantiation.structPointer({typeReference:i,fields:[{name:this.context.getFieldName(a.discriminantValue.name),value:l.TypeInstantiation.string(p.discriminantValue.wireValue)},...s]});default:U(p)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){return this.context.associateByWireValue({parameters:e.properties??[],values:this.context.getRecord(t.value)??{},ignoreMissingParameters:!0}).map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getFieldName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})}convertObject({object_:t,value:e}){let i=this.context.associateByWireValue({parameters:t.properties,values:this.context.getRecord(e)??{}});return l.TypeInstantiation.structPointer({typeReference:l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),fields:i.map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getFieldName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:t,value:e}){let i=this.getEnumValueName({enum_:t,value:e});return i==null?l.TypeInstantiation.nop():l.TypeInstantiation.enum(l.typeReference({name:i,importPath:this.context.getImportPath(t.declaration.fernFilepath)}))}getEnumValueName({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:L.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let i=t.values.find(a=>a.wireValue===e);if(i==null){this.context.errors.add({severity:L.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return`${this.context.getTypeName(t.declaration.name)}${this.context.getTypeName(i.name)}`}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let i=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});if(i==null)return l.TypeInstantiation.nop();let a=this.getUndiscriminatedUnionFieldName({typeReference:i.valueTypeReference});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.structPointer({typeReference:this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),fields:[{name:a,value:i.typeInstantiation}]})}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let i of t.types)try{let a=this.convert({typeReference:i,value:e});if(l.TypeInstantiation.isNop(a))continue;return{valueTypeReference:i,typeInstantiation:a}}catch{continue}this.context.errors.add({severity:L.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof e}" value`})}getUndiscriminatedUnionFieldName({typeReference:t}){switch(t.type){case"list":return this.getUndiscriminatedUnionFieldNameForList({list:t});case"literal":return this.getUndiscriminatedUnionFieldNameForLiteral({literal:t.value});case"map":return this.getUndiscriminatedUnionFieldNameForMap({map:t});case"named":{let e=this.context.resolveNamedType({typeId:t.value});return e==null?void 0:this.context.getTypeName(e.declaration.name)}case"optional":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:t});case"nullable":return this.getUndiscriminatedUnionFieldNameForOptional({typeReference:t});case"primitive":return this.getUndiscriminatedUnionFieldNameForPrimitive({primitive:t.value});case"set":return this.getUndiscriminatedUnionFieldNameForSet({set:t});case"unknown":return"Unknown";default:U(t)}}getUndiscriminatedUnionFieldNameForList({list:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}List`}getUndiscriminatedUnionFieldNameForMap({map:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t.key});if(e==null)return;let i=this.getUndiscriminatedUnionFieldName({typeReference:t.value});if(i!=null)return`${e}${i}Map`}getUndiscriminatedUnionFieldNameForOptional({typeReference:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}Optional`}getUndiscriminatedUnionFieldNameForSet({set:t}){let e=this.getUndiscriminatedUnionFieldName({typeReference:t});if(e!=null)return`${e}Set`}getUndiscriminatedUnionFieldNameForLiteral({literal:t}){switch(t.type){case"boolean":return t.value?"TrueLiteral":"FalseLiteral";case"string":return`${t.value}StringLiteral`;default:U(t)}}getUndiscriminatedUnionFieldNameForPrimitive({primitive:t}){switch(t){case"INTEGER":case"UINT":return"Integer";case"LONG":case"UINT_64":return"Long";case"FLOAT":case"DOUBLE":return"Double";case"BOOLEAN":return"Boolean";case"BIG_INTEGER":case"STRING":return"String";case"UUID":return"Uuid";case"DATE":return"Date";case"DATE_TIME":return"DateTime";case"BASE_64":return"Base64";default:U(t)}}convertUnknown({value:t}){return l.TypeInstantiation.any(t)}convertPrimitive({primitive:t,value:e,as:i}){switch(t){case"INTEGER":case"UINT":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.int(a)}case"LONG":case"UINT_64":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.int64(a)}case"FLOAT":case"DOUBLE":{let a=this.getValueAsNumber({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.float64(a)}case"BOOLEAN":{let a=this.getValueAsBoolean({value:e,as:i});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.bool(a)}case"STRING":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.string(a)}case"DATE":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.date(a)}case"DATE_TIME":{let a=this.context.getValueAsString({value:e});if(a==null)return l.TypeInstantiation.nop();let p=this.normalizeDateTimeString(a);return l.TypeInstantiation.dateTime(p)}case"UUID":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.uuid(a)}case"BASE_64":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.bytes(a)}case"BIG_INTEGER":{let a=this.context.getValueAsString({value:e});return a==null?l.TypeInstantiation.nop():l.TypeInstantiation.string(a)}default:U(t)}}getValueAsNumber({value:t,as:e}){let i=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:i})}getValueAsBoolean({value:t,as:e}){let i=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:i})}normalizeDateTimeString(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?`${t}T00:00:00Z`:/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(t)?`${t}Z`:t}};y();w();g();var ft=class{constructor({context:t}){m(this,"context");this.context=t}convert(t){switch(t.typeReference.type){case"list":return l.Type.slice(this.convert({typeReference:t.typeReference.value}));case"literal":return this.convertLiteral({literal:t.typeReference.value});case"map":return l.Type.map(this.convert({typeReference:t.typeReference.key}),this.convert({typeReference:t.typeReference.value}));case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?this.convertUnknown():this.convertNamed({named:e})}case"optional":return l.Type.optional(this.convert({typeReference:t.typeReference.value}));case"nullable":return l.Type.optional(this.convert({typeReference:t.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:t.typeReference.value});case"set":return l.Type.slice(this.convert({typeReference:t.typeReference}));case"unknown":return this.convertUnknown();default:U(t.typeReference)}}convertLiteral({literal:t}){switch(t.type){case"boolean":return l.Type.bool();case"string":return l.Type.string()}}convertNamed({named:t}){let e=l.Type.reference(l.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}));switch(t.type){case"alias":case"enum":return e;case"discriminatedUnion":case"object":case"undiscriminatedUnion":return l.Type.pointer(e);default:U(t)}}convertUnknown(){return l.Type.any()}convertPrimitive({primitive:t}){switch(t){case"INTEGER":return l.Type.int();case"UINT":return l.Type.int();case"LONG":return l.Type.int64();case"UINT_64":return l.Type.int64();case"FLOAT":return l.Type.float64();case"DOUBLE":return l.Type.float64();case"BOOLEAN":return l.Type.bool();case"STRING":return l.Type.string();case"DATE":return l.Type.date();case"DATE_TIME":return l.Type.dateTime();case"UUID":return l.Type.uuid();case"BASE_64":return l.Type.bytes();case"BIG_INTEGER":return l.Type.string();default:U(t)}}};y();w();g();var ht=class{constructor({context:t}){m(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){let i={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(e)??{};for(let p of t.properties)switch(p.type){case"file":i.fileFields.push({name:this.context.getFieldName(p.name),value:this.getSingleFileProperty({property:p,record:a})});break;case"fileArray":i.fileFields.push({name:this.context.getFieldName(p.name),value:this.getArrayFileProperty({property:p,record:a})});break;case"bodyProperty":i.bodyPropertyFields.push({name:this.context.getFieldName(p.name.name),value:this.getBodyProperty({property:p,record:a})});break;default:U(p)}return i}getSingleFileProperty({property:t,record:e}){let i=this.context.getSingleFileValue({property:t,record:e})||"";return l.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(i))}getArrayFileProperty({property:t,record:e}){let i=this.context.getFileArrayValues({property:t,record:e});return i==null?l.TypeInstantiation.nop():l.TypeInstantiation.slice({valueType:l.Type.reference(this.context.getIoReaderTypeReference()),values:i.map(a=>l.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(a)))})}getBodyProperty({property:t,record:e}){let i=e[t.name.wireValue];return i==null?l.TypeInstantiation.nop():this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:i})}};var mt=class u extends Ye{constructor({ir:e,config:i}){super({ir:e,config:i});m(this,"ir");m(this,"customConfig");m(this,"dynamicTypeMapper");m(this,"dynamicTypeInstantiationMapper");m(this,"filePropertyMapper");m(this,"rootImportPath");this.ir=e,this.customConfig=i.customConfig!=null?i.customConfig:void 0,this.dynamicTypeMapper=new ft({context:this}),this.dynamicTypeInstantiationMapper=new dt({context:this}),this.filePropertyMapper=new ht({context:this}),this.rootImportPath=_t({config:i,customConfig:this.customConfig})}clone(){return new u({ir:this.ir,config:this.config})}isOptional(e){switch(e.type){case"optional":case"map":return!0;case"nullable":case"list":case"set":return this.isOptional(e.value);case"named":case"literal":case"primitive":case"unknown":return!1;default:U(e)}}getMethodName(e){return e.pascalCase.unsafeName}getTestMethodName(e){return e.declaration.fernFilepath.allParts.map(i=>i.pascalCase.unsafeName).join("")+e.declaration.name.pascalCase.unsafeName}getTypeName(e){return e.pascalCase.unsafeName}getFieldName(e){return Lt(e.pascalCase.unsafeName)}getImportPath(e){let i=e.packagePath.map(a=>a.pascalCase.unsafeName.toLowerCase());return[this.rootImportPath,...i].join("/")}getImportPathForRequest(e){return this.customConfig?.exportAllRequestsAtRoot?this.rootImportPath:this.getImportPath(e)}getContextTypeReference(){return l.typeReference({name:"Context",importPath:"context"})}getContextTodoFunctionInvocation(){return l.invokeFunc({func:l.typeReference({name:"TODO",importPath:"context"}),arguments_:[]})}getIoReaderTypeReference(){return l.typeReference({name:"Reader",importPath:"io"})}getTestingTypeReference(){return l.typeReference({name:"T",importPath:"testing"})}getNewStringsReaderFunctionInvocation(e){return l.invokeFunc({func:l.typeReference({name:"NewReader",importPath:"strings"}),arguments_:[l.TypeInstantiation.string(e)]})}getClientConstructorName(){return this.customConfig?.clientConstructorName!=null?this.customConfig.clientConstructorName:this.customConfig?.exportedClientName!=null?`New${this.customConfig.exportedClientName}`:`New${this.getClientName()}`}getClientName(){return this.customConfig?.clientName!=null?this.customConfig.clientName:"Client"}getClientImportPath(){return`${this.rootImportPath}/client`}getOptionImportPath(){return`${this.rootImportPath}/option`}getGoTypeReferenceFromDeclaration({declaration:e}){return l.typeReference({name:e.name.pascalCase.unsafeName,importPath:this.getImportPath(e.fernFilepath)})}getEnvironmentTypeReferenceFromID(e){let i=this.resolveEnvironmentName(e);if(i!=null)return this.getEnvironmentTypeReference(i)}getEnvironmentTypeReference(e){return l.typeReference({name:`Environments.${this.getTypeName(e)}`,importPath:this.rootImportPath})}static chainMethods(e,...i){if(i.length===0)throw new Error("Must have methods to chain");let a=e;for(let p of i)a=l.invokeMethod({on:a,method:p.method,arguments_:p.arguments_,multiline:p.multiline});return a}};y();w();g();var Br="example",Mt="fern",ns="do",et="client",Me=l.TypeInstantiation,rs="WireMockBaseURL",is="WireMockClient",yt=class{constructor({context:t,formatter:e}){m(this,"context");m(this,"formatter");this.context=t,this.formatter=e}async generateSnippet({endpoint:t,request:e,options:i}){return i?.config?.outputWiremockTests??!1?this.generateWiremockTest({endpoint:t,snippet:e}):await this.buildCodeBlock({endpoint:t,snippet:e}).toStringAsync({packageName:Br,importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}generateSnippetSync({endpoint:t,request:e,options:i}){return i?.config?.outputWiremockTests??!1?this.generateWiremockTest({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e}).toString({packageName:Br,importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}async generateSnippetAst({endpoint:t,request:e,options:i}){throw new Error("Unsupported")}generateWiremockTest({endpoint:t,snippet:e}){return this.buildWiremockTestCodeBlock({endpoint:t,snippet:e}).toString({packageName:"wiremock",importPath:Mt,rootImportPath:this.context.rootImportPath,customConfig:this.context.customConfig??{},formatter:this.formatter})}buildCodeBlock({endpoint:t,snippet:e}){return l.codeblock(i=>{i.writeNode(l.func({name:ns,parameters:[],return_:[],body:l.codeblock(a=>{a.writeNode(this.constructClient({endpoint:t,snippet:e})),a.writeLine(),a.writeNode(this.callMethod({endpoint:t,snippet:e}))})})),i.writeNewLineIfLastLineNot()})}buildWiremockTestCodeBlock({endpoint:t,snippet:e}){return l.codeblock(i=>{i.writeNode(l.func({name:"Test"+this.context.getTestMethodName(t)+"WithWireMock",parameters:[l.parameter({name:"t",type:l.Type.pointer(l.Type.reference(this.context.getTestingTypeReference()))})],return_:[],body:l.codeblock(a=>{for(let p of this.buildWiremockTestSetup({endpoint:t}))a.writeNode(p),a.writeLine();a.writeLine(),a.writeNode(this.constructWiremockTestClient({endpoint:t,snippet:e})),a.writeLine(),a.writeNode(this.callClientMethodAndAssert({endpoint:t,snippet:e,includeTestIdHeader:!0}))})})),i.writeNewLineIfLastLineNot()})}constructClient({endpoint:t,snippet:e}){return l.codeblock(i=>{i.write(`${et} := `),i.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:t,snippet:e})))})}constructWiremockTestClient({endpoint:t,snippet:e}){return l.codeblock(i=>{i.write(`${et} := `),i.writeNode(this.getRootClientFuncInvocation(this.getWiremockTestConstructorArgs()))})}writeMethodInvocation({writer:t,endpoint:e,snippet:i,includeTestIdHeader:a}){let{otherArgs:p,requestArg:s}=this.getMethodArgs({endpoint:e,snippet:i}),f=a?[l.codeblock(I=>{I.writeNode(l.invokeFunc({func:l.typeReference({name:"WithHTTPHeader",importPath:this.context.getOptionImportPath()}),arguments_:[l.codeblock('http.Header{"X-Test-Id": []string{"TEST-ID-PLACEHOLDER"}}')]}))})]:[];if(s!=null)if(s instanceof l.TypeInstantiation&&l.TypeInstantiation.isNop(s))t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,l.codeblock("nil")]}));else{t.write("request := "),t.writeNode(s),t.writeLine();let I=l.codeblock("request");t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,I,...f]}))}else t.writeNode(l.invokeMethod({on:l.codeblock(et),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...p,...f]}))}callMethod({endpoint:t,snippet:e}){return l.codeblock(i=>{this.writeMethodInvocation({writer:i,endpoint:t,snippet:e})})}getConstructorArgs({endpoint:t,snippet:e}){let i=[],a=this.getConstructorBaseUrlArg({baseUrl:e.baseURL,environment:e.environment});return a!=null&&i.push(a),t.auth!=null&&(e.auth!=null?i.push(this.getConstructorAuthArg({auth:t.auth,values:e.auth})):this.context.errors.add({severity:L.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(re.Headers),this.context.ir.headers!=null&&e.headers!=null&&i.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),i}getWiremockTestConstructorArgs(){return[l.codeblock(t=>{t.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[l.codeblock(rs)]}))})]}getConstructorAuthArg({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),Me.nop();switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArg({auth:t,values:e}):Me.nop();case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArg({auth:t,values:e}):Me.nop();case"header":return e.type==="header"?this.getConstructorHeaderAuthArg({auth:t,values:e}):Me.nop();case"oauth":return e.type==="oauth"?this.getConstructorOAuthAuthArg({values:e}):Me.nop();case"inferred":return this.addWarning("The Go SDK Generator does not support Inferred auth scheme yet"),Me.nop();default:U(t)}}addError(t){this.context.errors.add({severity:L.Critical,message:t})}addWarning(t){this.context.errors.add({severity:L.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(e.username),l.TypeInstantiation.string(e.password)]}))})}getConstructorBaseUrlArg({baseUrl:t,environment:e}){let i=this.getBaseUrlArg({baseUrl:t,environment:e});if(i!=null)return l.codeblock(a=>{a.writeNode(l.invokeFunc({func:l.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[i]}))})}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:L.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return l.TypeInstantiation.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let i=this.context.getEnvironmentTypeReferenceFromID(e);if(i==null){this.context.errors.add({severity:L.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return l.TypeInstantiation.reference(i)}this.context.isMultiEnvironmentValues(e)&&this.context.errors.add({severity:L.Warning,message:"The Go SDK doesn't support a multi-environment client option yet; use the baseUrl option instead"})}}getConstructorBearerAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(e.token)]}))})}getConstructorHeaderAuthArg({auth:t,values:e}){return l.codeblock(i=>{i.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.header.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.header.typeReference,value:e.value})]}))})}getConstructorOAuthAuthArg({values:t}){return l.codeblock(e=>{e.writeNode(l.invokeFunc({func:l.typeReference({name:"WithClientCredentials",importPath:this.context.getOptionImportPath()}),arguments_:[l.TypeInstantiation.string(t.clientId),l.TypeInstantiation.string(t.clientSecret)]}))})}getConstructorHeaderArgs({headers:t,values:e}){let i=[];for(let a of t){let p=this.getConstructorHeaderArg({header:a,value:e.value});p!=null&&i.push(p)}return i}getConstructorHeaderArg({header:t,value:e}){let i=this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:e});if(!l.TypeInstantiation.isNop(i))return l.codeblock(a=>{a.writeNode(l.invokeFunc({func:l.typeReference({name:`With${t.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[i]}))})}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:U(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let i=[];this.context.errors.scope(re.PathParameters);let a=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];a.length>0&&i.push(...this.getPathParameters({namedParameters:a,snippet:e}).map(s=>s.value)),this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let p=t.body!=null?this.getBodyRequestArg({body:t.body,value:e.requestBody}):void 0;return this.context.errors.unscope(),{otherArgs:i,requestArg:p}}getBodyRequestArg({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e});default:U(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:L.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),l.TypeInstantiation.nop()):l.TypeInstantiation.bytes(t)}getMethodArgsForInlinedRequest({request:t,snippet:e}){let i=[],{inlinePathParameters:a,inlineFileProperties:p}={inlinePathParameters:this.context.customConfig?.inlinePathParameters??!0,inlineFileProperties:this.context.customConfig?.inlineFileProperties??!0};this.context.errors.scope(re.PathParameters);let s=[],f=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];f.length>0&&s.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let I=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})||i.push(...s.map(E=>E.value)),p||i.push(...I.fileFields.map(E=>E.value));let x=this.context.needsRequestParameter({request:t,inlinePathParameters:a,inlineFileProperties:p})?this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})?s:[],filePropertyInfo:I}):void 0;return{otherArgs:i,requestArg:x}}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:i,filePropertyInfo:a}){this.context.errors.scope(re.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(E=>({name:E.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(E)}));this.context.errors.unscope(),this.context.errors.scope(re.Headers);let I=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(E=>({name:E.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(E)}));this.context.errors.unscope(),this.context.errors.scope(re.RequestBody);let x=t.body!=null?this.getInlinedRequestBodyStructFields({body:t.body,value:e.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),l.TypeInstantiation.structPointer({typeReference:l.typeReference({name:this.context.getMethodName(t.declaration.name),importPath:this.context.getImportPathForRequest(t.declaration.fernFilepath)}),fields:[...i,...s,...I,...x]})}getInlinedRequestBodyStructFields({body:t,value:e,filePropertyInfo:i}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyStructFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyStructField({body:t,value:e})];case"fileUpload":return this.getFileUploadRequestBodyStructFields({filePropertyInfo:i});default:U(t)}}getFileUploadRequestBodyStructFields({filePropertyInfo:t}){return this.context.customConfig?.inlineFileProperties??!0?[...t.fileFields,...t.bodyPropertyFields]:t.bodyPropertyFields}getReferencedRequestBodyPropertyStructField({body:t,value:e}){return{name:this.context.getTypeName(t.bodyKey),value:this.getReferencedRequestBodyPropertyTypeInstantiation({body:t.bodyType,value:e})}}getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e});default:U(t)}}getInlinedRequestBodyPropertyStructFields({parameters:t,value:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}});for(let p of a)i.push({name:this.context.getTypeName(p.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(p)});return i}getPathParameters({namedParameters:t,snippet:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:e.pathParameters??{}});for(let p of a)i.push({name:this.context.getTypeName(p.name.name),value:this.context.dynamicTypeInstantiationMapper.convertToPointerIfPossible(p)});return i}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getMethodName(e)).join(".")}.${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getRootClientFuncInvocation(t){return l.invokeFunc({func:l.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:t})}buildWiremockTestSetup({endpoint:t,errorCase:e}){let i="stub";return[]}callClientMethodAndAssert({endpoint:t,snippet:e,includeTestIdHeader:i}){return l.codeblock(a=>{this.writeMethodInvocation({writer:a,endpoint:t,snippet:e,includeTestIdHeader:!0}),a.writeLine(),a.writeLine(),a.write("ok, countErr := "),a.writeNode(l.invokeMethod({on:l.codeblock(is),method:"Verify",arguments_:[l.invokeMethod({on:l.codeblock("stub"),method:"Request",arguments_:[],multiline:!1}),l.codeblock("1")],multiline:!1})),a.writeLine(),a.writeNode(l.invokeFunc({func:l.typeReference({name:"NoError",importPath:"github.com/stretchr/testify/require"}),arguments_:[l.codeblock("t"),l.codeblock("countErr"),l.TypeInstantiation.string("Failed to verify WireMock request was matched")],multiline:!1})),a.writeLine(),a.writeNode(l.invokeFunc({func:l.typeReference({name:"True",importPath:"github.com/stretchr/testify/require"}),arguments_:[l.codeblock("t"),l.codeblock("ok"),l.TypeInstantiation.string("WireMock request was not matched")],multiline:!1})),a.writeLine()})}};var $t=class extends je{constructor({ir:e,config:i,formatter:a}){super(new mt({ir:e,config:i}));m(this,"formatter");this.formatter=a}async generate(e,i){return super.generate(e,i)}generateSync(e,i){return super.generateSync(e,i)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new yt({context:e,formatter:this.formatter})}};export{$t as DynamicSnippetsGenerator};
27
28
  /*! Bundled license information:
28
29
 
29
30
  @jspm/core/nodelibs/browser/chunk-DtuTasat.js: