@fern-api/go-dynamic-snippets 0.0.17 → 0.0.18

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.
@@ -12,7 +12,7 @@ ${o}`);this.isAtStartOfLine()&&(s=o+s),r&&(s+=`
12
12
  `)}writeSemicolonIfLastCharacterIsNot(){this.lastCharacterIsSemicolon||this.writeInternal(";")}writeNewLineIfLastLineNot(){this.lastCharacterIsNewline||this.writeInternal(`
13
13
  `)}indent(){this.indentLevel++}dedent(){this.indentLevel--}delimit({nodes:t,delimiter:e,writeFunction:r}){if(t.length>0){let i=t[0];i!=null&&r(i);for(let o=1;o<t.length;o++){this.write(e);let s=t[o];s!=null&&r(s)}}}toString(){return this.buffer}writeInternal(t){if(t.length===0)return;let e=!this.lastCharacterIsNewline;this.hasWrittenAnything=!0,this.lastCharacterIsNewline=t.endsWith(`
14
14
  `),this.lastCharacterIsSemicolon=t.endsWith(";");let r=t.split(`
15
- `),i=B&&!this.shouldSkipTracking(r)&&this.lastCharacterIsNewline;e&&(this.lastLine=`${this.lastLine}${r.shift()||""}`),this.lastCharacterIsNewline&&r.pop(),this.lineBuffer.push(...r),i&&this.appendTrackingComment()}set lastLine(t){this.lineBuffer.length>0?this.lineBuffer[this.lineBuffer.length-1]=t:this.lineBuffer.push(t)}get lastLine(){return this.lineBuffer[this.lineBuffer.length-1]||""}shouldSkipTracking(t){return!1}formatStack(t,e=""){return t.map(r=>`${e?`(${e}) `:""} ${r.fn} - ${r.path} : ${r.position}`)}filterStack(t){return t.filter(e=>!e.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(De({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,Ze){case"single":return this.singleLineTrackingComment(t);case"multiline":return this.multiLineTrackingComment(t);case"box":return this.boxTrackingComment(t)}}singleLineTrackingComment(t){this.lastLine=`${this.lastLine} // ${t.join(" ")}`}multiLineTrackingComment(t){this.lineBuffer.push(...t.map(e=>` // ${e}`))}boxTrackingComment(t){this.lineBuffer.push("/*",...t.map(e=>` ${e}`),"*/")}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*this.getTabSize())}getTabSize(){return sn}};l();f();l();f();l();f();var ye=class{constructor(){u(this,"reporter");u(this,"snippet");u(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:t,snippet:e}){this.shouldUpdate({snippet:e,reporter:t.errors})&&(this.reporter=t.errors.clone(),this.snippet=e)}getResponseOrThrow({endpoint:t}){var e;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(e=this.err)!=null?e:new Error(`Failed to generate snippet for endpoint "${t.method} ${t.path}"`)}shouldUpdate({snippet:t,reporter:e}){var r,i;return this.reporter==null||this.reporter.size()>0&&e.size()===0?!0:t.length>((i=(r=this.snippet)==null?void 0:r.length)!=null?i:0)}};var ge=class{constructor(t){u(this,"context");this.context=t}async generate(t,e={}){let r=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(r.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new ye;for(let o of r){let s=this.context.clone(),p=this.createSnippetGenerator(s);try{let h=await p.generateSnippet({endpoint:o,request:t,options:e});if(s.errors.empty())return{snippet:h,errors:void 0};i.update({context:s,snippet:h})}catch(h){i.err==null&&(i.err=h)}}return i.getResponseOrThrow({endpoint:t.endpoint})}generateSync(t,e={}){let r=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(r.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new ye;for(let o of r){let s=this.context.clone(),p=this.createSnippetGenerator(s);try{let h=p.generateSnippetSync({endpoint:o,request:t,options:e});if(s.errors.empty())return{snippet:h,errors:void 0};i.update({context:s,snippet:h})}catch(h){i.err==null&&(i.err=h)}}return i.getResponseOrThrow({endpoint:t.endpoint})}};l();f();l();f();l();f();var we=class{constructor(){u(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH|HEAD)\s(\/\S*)$/)}validate(t){return this.REFERENCE_REGEX.test(t)?{type:"valid"}:{type:"invalid"}}tryParse(t){if(this.validate(t).type==="invalid")return;let r=t.match(this.REFERENCE_REGEX);if(!(r==null||r[1]==null||r[2]==null))return{method:r[1],path:r[2]}}};l();f();var v={Critical:"CRITICAL",Warning:"WARNING"},xe=class n{constructor(){u(this,"errors");u(this,"path");this.errors=[],this.path=[]}add(t){this.errors.push(pt(ut({},t),{path:[...this.path]}))}scope(t){this.path.push(t)}unscope(){this.path.pop()}getBySeverity(t){return this.errors.filter(e=>e.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new n;return t.errors=[...this.errors],t.path=[...this.path],t}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(t=>({severity:t.severity,path:t.path!=null?this.pathToStringArray(t.path):void 0,message:t.message}))}pathToStringArray(t){let e=[];for(let r of t){if(typeof r=="string"){e.push(r);continue}e[e.length-1]+=`[${r.index}]`}return e}};var ve=class{constructor({ir:t,config:e,options:r={}}){u(this,"config");u(this,"options");u(this,"errors");u(this,"_ir");u(this,"httpEndpointReferenceParser");this._ir=t,this.config=e,this.options=r,this.errors=new xe,this.httpEndpointReferenceParser=new we}associateQueryParametersByWireValue({parameters:t,values:e}){let r=[];for(let[i,o]of Object.entries(e)){this.errors.scope(i);try{let s=t.find(h=>h.name.wireValue===i);if(s==null)throw this.newParameterNotRecognizedError(i);let p=this.isListTypeReference(s.typeReference)&&!Array.isArray(o)?[o]:o;r.push({name:s.name,typeReference:s.typeReference,value:p})}finally{this.errors.unscope()}}return r}associateByWireValueOrDefault({parameters:t,values:e}){let r=[];for(let i of t){this.errors.scope(i.name.wireValue);try{let o=e[i.name.wireValue];if(o==null)if(i.typeReference.type==="primitive"&&i.typeReference.value==="STRING")o=`<${i.name.wireValue}>`;else{this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(i.name.wireValue).message});continue}r.push({name:i.name,typeReference:i.typeReference,value:o})}finally{this.errors.unscope()}}return r}associateByWireValue({parameters:t,values:e,ignoreMissingParameters:r}){let i=[];for(let[o,s]of Object.entries(e)){this.errors.scope(o);try{let p=t.find(h=>h.name.wireValue===o);if(p==null){if(r)continue;this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(o).message});continue}i.push({name:p.name,typeReference:p.typeReference,value:s})}finally{this.errors.unscope()}}return i}getExampleObjectProperties({parameters:t,snippetObject:e}){let r=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{},i=[];for(let o of t){let s=r[o.name.wireValue];s==null?o.typeReference.type==="nullable"&&i.push({name:o.name,typeReference:o.typeReference,value:null}):i.push({name:o.name,typeReference:o.typeReference,value:s})}return i}getSingleFileValue({property:t,record:e}){let r=e[t.wireValue];if(r!=null){if(typeof r!="string"){this.errors.add({severity:v.Critical,message:`Expected file value to be a string, got ${typeof r}`});return}return r}}getFileArrayValues({property:t,record:e}){let r=e[t.wireValue];if(r==null)return;if(!Array.isArray(r)){this.errors.add({severity:v.Critical,message:`Expected file array value to be an array of strings, got ${typeof r}`});return}let i=[];for(let o of r){if(typeof o!="string"){this.errors.add({severity:v.Critical,message:`Expected file array value to be an array of strings, got ${typeof o}`});return}i.push(o)}return i}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:v.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t==null?{}:t}resolveNamedType({typeId:t}){let e=this._ir.types[t];if(e==null){this.errors.add({severity:v.Critical,message:`Type identified by "${t}" could not be found`});return}return e}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e}){let r=this.getRecord(e);if(r==null)return;let i=t.discriminant.wireValue,o=r[i];if(o==null){this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(i).message});return}if(typeof o!="string"){this.errors.add({severity:v.Critical,message:`Expected discriminant value to be a string but got: ${typeof o}`});return}let s=t.types[o];if(s==null){this.errors.add({severity:v.Critical,message:`No type found for discriminant value "${o}"`});return}let m=r,{[i]:p}=m,h=ft(m,[lt(i)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:h}}resolveEndpointOrThrow(t){let e=this.httpEndpointReferenceParser.tryParse(t);if(e==null)throw new Error(`Failed to parse endpoint reference "${t}"`);return this.resolveEndpointLocationOrThrow(e)}resolveEndpointLocation(t){let e=[];for(let r of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:r,parsedEndpoint:t})&&e.push(r);return e}resolveEndpointLocationOrThrow(t){let e=this.resolveEndpointLocation(t);if(e.length===0)throw new Error(`Failed to find endpoint identified by "${t.method} ${t.path}"`);return e}needsRequestParameter({request:t,inlinePathParameters:e,inlineFileProperties:r}){var i;return this.includePathParametersInWrappedRequest({request:t,inlinePathParameters:e})||t.queryParameters!=null&&t.queryParameters.length>0||t.headers!=null&&t.headers.length>0?!0:t.body!=null?this.includeRequestBodyInWrappedRequest({body:t.body,inlineFileProperties:r}):!((i=t.metadata)!=null&&i.onlyPathParameters)}includePathParametersInWrappedRequest({request:t,inlinePathParameters:e}){var r,i;return e&&((i=(r=t.metadata)==null?void 0:r.includePathParameters)!=null?i:!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:x(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":{let r=e.environments.find(i=>i.id===t);return r==null?void 0:r.name}case"multipleBaseUrls":{let r=e.environments.find(i=>i.id===t);return r==null?void 0:r.name}default:x(e)}}isSingleEnvironmentID(t){return typeof t=="string"}isMultiEnvironmentValues(t){return typeof t=="object"}validateMultiEnvironmentUrlValues(t){if(this._ir.environments==null)return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let r=e.environments[0];if(r==null)return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let i=new Set(fe(r.urls));for(let o of fe(t))i.has(o)&&i.delete(o);return i.size>0?(this.errors.add({severity:v.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${fe(r.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"string",value:t}).message});return}return t}isOptional(t){switch(t.type){case"nullable":return this.isOptional(t.value);case"optional":return!0;case"named":{let e=this.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.isNullable(e.typeReference):!1}}return!1}isNullable(t){switch(t.type){case"nullable":return!0;case"optional":return this.isNullable(t.value);case"named":{let e=this.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.isNullable(e.typeReference):!1}}return!1}newAuthMismatchError({auth:t,values:e}){return new Error(`Expected auth type ${t.type}, got ${e.type}`)}newParameterNotRecognizedError(t){return new Error(`"${t}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:t,value:e}){return new Error(`Expected ${t}, got ${typeof e}`)}includeRequestBodyInWrappedRequest({body:t,inlineFileProperties:e}){switch(t.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:e});default:x(t)}}includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:e}){return this.fileUploadHasBodyProperties({fileUpload:t})||e&&this.fileUploadHasFileProperties({fileUpload:t})}fileUploadHasBodyProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:x(e)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:x(e)}})}isListTypeReference(t){return t.type==="optional"?this.isListTypeReference(t.value):t.type==="list"||t.type==="set"}parsedEndpointMatches({endpoint:t,parsedEndpoint:e}){return t.location.method===e.method&&t.location.path===e.path}};l();f();var L={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};l();f();l();f();function Te(n,t){var r,i;let e=(r=n.split("/").pop())!=null?r:n;return t!=null&&t.stripExtension&&(i=e.split(".")[0])!=null?i:e}l();f();l();f();l();f();l();f();var an=/[^0-9a-zA-Z_]/g,cn=["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],J=class extends me{constructor({packageName:e,rootImportPath:r,importPath:i,customConfig:o,formatter:s}){super();u(this,"packageName");u(this,"rootImportPath");u(this,"importPath");u(this,"customConfig");u(this,"formatter");u(this,"imports",{});this.packageName=e,this.rootImportPath=r,this.importPath=i,this.customConfig=o,this.formatter=s!=null?s:new de}addImport(e){let r=this.imports[e];if(r!=null)return r;if(e===this.rootImportPath&&this.customConfig.packageName!=null)return this.imports[e]=this.customConfig.packageName,this.customConfig.packageName;let i=new Set(Object.values(this.imports)),o=e.split("/");for(let p=1;p<=o.length;p++){let h=o.slice(-p),m=this.getValidAlias(h.join(""));if(!i.has(m))return this.imports[e]=m,m}let s=this.getValidAlias(Te(e));for(;i.has(s);)s="_"+s;return this.imports[e]=s,s}isValidAlias(e){return!cn.includes(e)}getValidAlias(e){let r=e.split("-");if(r[0]==null)return e;let i=r.map(o=>o.replace(an,"")).join("");return this.isValidAlias(i)?i:"_"+i}};var Ie=class extends J{constructor({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o}){super({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o})}async toStringAsync(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.format(t)}catch(e){throw new Error(`Failed to format Go file: ${e}
15
+ `),i=B&&!this.shouldSkipTracking(r)&&this.lastCharacterIsNewline;e&&(this.lastLine=`${this.lastLine}${r.shift()||""}`),this.lastCharacterIsNewline&&r.pop(),this.lineBuffer.push(...r),i&&this.appendTrackingComment()}set lastLine(t){this.lineBuffer.length>0?this.lineBuffer[this.lineBuffer.length-1]=t:this.lineBuffer.push(t)}get lastLine(){return this.lineBuffer[this.lineBuffer.length-1]||""}shouldSkipTracking(t){return!1}formatStack(t,e=""){return t.map(r=>`${e?`(${e}) `:""} ${r.fn} - ${r.path} : ${r.position}`)}filterStack(t){return t.filter(e=>!e.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(De({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,Ze){case"single":return this.singleLineTrackingComment(t);case"multiline":return this.multiLineTrackingComment(t);case"box":return this.boxTrackingComment(t)}}singleLineTrackingComment(t){this.lastLine=`${this.lastLine} // ${t.join(" ")}`}multiLineTrackingComment(t){this.lineBuffer.push(...t.map(e=>` // ${e}`))}boxTrackingComment(t){this.lineBuffer.push("/*",...t.map(e=>` ${e}`),"*/")}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*this.getTabSize())}getTabSize(){return sn}};l();f();l();f();l();f();var ye=class{constructor(){u(this,"reporter");u(this,"snippet");u(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:t,snippet:e}){this.shouldUpdate({snippet:e,reporter:t.errors})&&(this.reporter=t.errors.clone(),this.snippet=e)}getResponseOrThrow({endpoint:t}){var e;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(e=this.err)!=null?e:new Error(`Failed to generate snippet for endpoint "${t.method} ${t.path}"`)}shouldUpdate({snippet:t,reporter:e}){var r,i;return this.reporter==null||this.reporter.size()>0&&e.size()===0?!0:t.length>((i=(r=this.snippet)==null?void 0:r.length)!=null?i:0)}};var ge=class{constructor(t){u(this,"context");this.context=t}async generate(t,e={}){let r=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(r.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new ye;for(let o of r){let s=this.context.clone(),p=this.createSnippetGenerator(s);try{let h=await p.generateSnippet({endpoint:o,request:t,options:e});if(s.errors.empty())return{snippet:h,errors:void 0};i.update({context:s,snippet:h})}catch(h){i.err==null&&(i.err=h)}}return i.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,e={}){let r=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(r.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i;for(let o of r){let s=this.context.clone(),p=this.createSnippetGenerator(s);try{return await p.generateSnippetAst({endpoint:o,request:t,options:e})}catch(h){i=h}}throw i!=null?i:new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,e={}){let r=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(r.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new ye;for(let o of r){let s=this.context.clone(),p=this.createSnippetGenerator(s);try{let h=p.generateSnippetSync({endpoint:o,request:t,options:e});if(s.errors.empty())return{snippet:h,errors:void 0};i.update({context:s,snippet:h})}catch(h){i.err==null&&(i.err=h)}}return i.getResponseOrThrow({endpoint:t.endpoint})}};l();f();l();f();l();f();var we=class{constructor(){u(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH|HEAD)\s(\/\S*)$/)}validate(t){return this.REFERENCE_REGEX.test(t)?{type:"valid"}:{type:"invalid"}}tryParse(t){if(this.validate(t).type==="invalid")return;let r=t.match(this.REFERENCE_REGEX);if(!(r==null||r[1]==null||r[2]==null))return{method:r[1],path:r[2]}}};l();f();var v={Critical:"CRITICAL",Warning:"WARNING"},xe=class n{constructor(){u(this,"errors");u(this,"path");this.errors=[],this.path=[]}add(t){this.errors.push(pt(ut({},t),{path:[...this.path]}))}scope(t){this.path.push(t)}unscope(){this.path.pop()}getBySeverity(t){return this.errors.filter(e=>e.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new n;return t.errors=[...this.errors],t.path=[...this.path],t}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(t=>({severity:t.severity,path:t.path!=null?this.pathToStringArray(t.path):void 0,message:t.message}))}pathToStringArray(t){let e=[];for(let r of t){if(typeof r=="string"){e.push(r);continue}e[e.length-1]+=`[${r.index}]`}return e}};var ve=class{constructor({ir:t,config:e,options:r={}}){u(this,"config");u(this,"options");u(this,"errors");u(this,"_ir");u(this,"httpEndpointReferenceParser");this._ir=t,this.config=e,this.options=r,this.errors=new xe,this.httpEndpointReferenceParser=new we}associateQueryParametersByWireValue({parameters:t,values:e}){let r=[];for(let[i,o]of Object.entries(e)){this.errors.scope(i);try{let s=t.find(h=>h.name.wireValue===i);if(s==null)throw this.newParameterNotRecognizedError(i);let p=this.isListTypeReference(s.typeReference)&&!Array.isArray(o)?[o]:o;r.push({name:s.name,typeReference:s.typeReference,value:p})}finally{this.errors.unscope()}}return r}associateByWireValueOrDefault({parameters:t,values:e}){let r=[];for(let i of t){this.errors.scope(i.name.wireValue);try{let o=e[i.name.wireValue];if(o==null)if(i.typeReference.type==="primitive"&&i.typeReference.value==="STRING")o=`<${i.name.wireValue}>`;else{this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(i.name.wireValue).message});continue}r.push({name:i.name,typeReference:i.typeReference,value:o})}finally{this.errors.unscope()}}return r}associateByWireValue({parameters:t,values:e,ignoreMissingParameters:r}){let i=[];for(let[o,s]of Object.entries(e)){this.errors.scope(o);try{let p=t.find(h=>h.name.wireValue===o);if(p==null){if(r)continue;this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(o).message});continue}i.push({name:p.name,typeReference:p.typeReference,value:s})}finally{this.errors.unscope()}}return i}getExampleObjectProperties({parameters:t,snippetObject:e}){let r=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{},i=[];for(let o of t){let s=r[o.name.wireValue];s==null?o.typeReference.type==="nullable"&&i.push({name:o.name,typeReference:o.typeReference,value:null}):i.push({name:o.name,typeReference:o.typeReference,value:s})}return i}getSingleFileValue({property:t,record:e}){let r=e[t.wireValue];if(r!=null){if(typeof r!="string"){this.errors.add({severity:v.Critical,message:`Expected file value to be a string, got ${typeof r}`});return}return r}}getFileArrayValues({property:t,record:e}){let r=e[t.wireValue];if(r==null)return;if(!Array.isArray(r)){this.errors.add({severity:v.Critical,message:`Expected file array value to be an array of strings, got ${typeof r}`});return}let i=[];for(let o of r){if(typeof o!="string"){this.errors.add({severity:v.Critical,message:`Expected file array value to be an array of strings, got ${typeof o}`});return}i.push(o)}return i}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:v.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t==null?{}:t}resolveNamedType({typeId:t}){let e=this._ir.types[t];if(e==null){this.errors.add({severity:v.Critical,message:`Type identified by "${t}" could not be found`});return}return e}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e}){let r=this.getRecord(e);if(r==null)return;let i=t.discriminant.wireValue,o=r[i];if(o==null){this.errors.add({severity:v.Critical,message:this.newParameterNotRecognizedError(i).message});return}if(typeof o!="string"){this.errors.add({severity:v.Critical,message:`Expected discriminant value to be a string but got: ${typeof o}`});return}let s=t.types[o];if(s==null){this.errors.add({severity:v.Critical,message:`No type found for discriminant value "${o}"`});return}let m=r,{[i]:p}=m,h=ft(m,[lt(i)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:h}}resolveEndpointOrThrow(t){let e=this.httpEndpointReferenceParser.tryParse(t);if(e==null)throw new Error(`Failed to parse endpoint reference "${t}"`);return this.resolveEndpointLocationOrThrow(e)}resolveEndpointLocation(t){let e=[];for(let r of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:r,parsedEndpoint:t})&&e.push(r);return e}resolveEndpointLocationOrThrow(t){let e=this.resolveEndpointLocation(t);if(e.length===0)throw new Error(`Failed to find endpoint identified by "${t.method} ${t.path}"`);return e}needsRequestParameter({request:t,inlinePathParameters:e,inlineFileProperties:r}){var i;return this.includePathParametersInWrappedRequest({request:t,inlinePathParameters:e})||t.queryParameters!=null&&t.queryParameters.length>0||t.headers!=null&&t.headers.length>0?!0:t.body!=null?this.includeRequestBodyInWrappedRequest({body:t.body,inlineFileProperties:r}):!((i=t.metadata)!=null&&i.onlyPathParameters)}includePathParametersInWrappedRequest({request:t,inlinePathParameters:e}){var r,i;return e&&((i=(r=t.metadata)==null?void 0:r.includePathParameters)!=null?i:!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:x(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":{let r=e.environments.find(i=>i.id===t);return r==null?void 0:r.name}case"multipleBaseUrls":{let r=e.environments.find(i=>i.id===t);return r==null?void 0:r.name}default:x(e)}}isSingleEnvironmentID(t){return typeof t=="string"}isMultiEnvironmentValues(t){return typeof t=="object"}validateMultiEnvironmentUrlValues(t){if(this._ir.environments==null)return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let r=e.environments[0];if(r==null)return this.errors.add({severity:v.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let i=new Set(fe(r.urls));for(let o of fe(t))i.has(o)&&i.delete(o);return i.size>0?(this.errors.add({severity:v.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${fe(r.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:v.Critical,message:this.newTypeMismatchError({expected:"string",value:t}).message});return}return t}isOptional(t){switch(t.type){case"nullable":return this.isOptional(t.value);case"optional":return!0;case"named":{let e=this.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.isNullable(e.typeReference):!1}}return!1}isNullable(t){switch(t.type){case"nullable":return!0;case"optional":return this.isNullable(t.value);case"named":{let e=this.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.isNullable(e.typeReference):!1}}return!1}newAuthMismatchError({auth:t,values:e}){return new Error(`Expected auth type ${t.type}, got ${e.type}`)}newParameterNotRecognizedError(t){return new Error(`"${t}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:t,value:e}){return new Error(`Expected ${t}, got ${typeof e}`)}includeRequestBodyInWrappedRequest({body:t,inlineFileProperties:e}){switch(t.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:e});default:x(t)}}includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:e}){return this.fileUploadHasBodyProperties({fileUpload:t})||e&&this.fileUploadHasFileProperties({fileUpload:t})}fileUploadHasBodyProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:x(e)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:x(e)}})}isListTypeReference(t){return t.type==="optional"?this.isListTypeReference(t.value):t.type==="list"||t.type==="set"}parsedEndpointMatches({endpoint:t,parsedEndpoint:e}){return t.location.method===e.method&&t.location.path===e.path}};l();f();var L={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};l();f();l();f();function Te(n,t){var r,i;let e=(r=n.split("/").pop())!=null?r:n;return t!=null&&t.stripExtension&&(i=e.split(".")[0])!=null?i:e}l();f();l();f();l();f();l();f();var an=/[^0-9a-zA-Z_]/g,cn=["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],J=class extends me{constructor({packageName:e,rootImportPath:r,importPath:i,customConfig:o,formatter:s}){super();u(this,"packageName");u(this,"rootImportPath");u(this,"importPath");u(this,"customConfig");u(this,"formatter");u(this,"imports",{});this.packageName=e,this.rootImportPath=r,this.importPath=i,this.customConfig=o,this.formatter=s!=null?s:new de}addImport(e){let r=this.imports[e];if(r!=null)return r;if(e===this.rootImportPath&&this.customConfig.packageName!=null)return this.imports[e]=this.customConfig.packageName,this.customConfig.packageName;let i=new Set(Object.values(this.imports)),o=e.split("/");for(let p=1;p<=o.length;p++){let h=o.slice(-p),m=this.getValidAlias(h.join(""));if(!i.has(m))return this.imports[e]=m,m}let s=this.getValidAlias(Te(e));for(;i.has(s);)s="_"+s;return this.imports[e]=s,s}isValidAlias(e){return!cn.includes(e)}getValidAlias(e){let r=e.split("-");if(r[0]==null)return e;let i=r.map(o=>o.replace(an,"")).join("");return this.isValidAlias(i)?i:"_"+i}};var Ie=class extends J{constructor({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o}){super({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o})}async toStringAsync(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.format(t)}catch(e){throw new Error(`Failed to format Go file: ${e}
16
16
  ${t}`)}return t}toString(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.formatSync(t)}catch(e){throw new Error(`Failed to format Go file: ${e}
17
17
  ${t}`)}return t}getContent(){let t=`package ${this.packageName}
18
18
 
@@ -23,7 +23,7 @@ ${this.buffer}`:t+this.buffer}stringifyImports(){let t=Object.entries(this.impor
23
23
  ${t}
24
24
  )`:""}};var a={};ht(a,{Alias:()=>X,AstNode:()=>w,CodeBlock:()=>_,Enum:()=>Q,Field:()=>Z,File:()=>ee,Func:()=>te,FuncInvocation:()=>S,IoReaderTypeReference:()=>it,Method:()=>W,MethodInvocation:()=>V,MultiNode:()=>Re,Parameter:()=>re,Pointer:()=>ne,Selector:()=>ie,Struct:()=>oe,TimeTypeReference:()=>Oe,Type:()=>Ae,TypeDeclaration:()=>se,TypeInstantiation:()=>E,TypeReference:()=>F,UuidTypeReference:()=>Ve,Writer:()=>J,alias:()=>Pn,codeblock:()=>kn,enum_:()=>Sn,field:()=>Cn,file:()=>Un,func:()=>Bn,identifier:()=>Ln,invokeFunc:()=>_n,invokeMethod:()=>Mn,method:()=>Dn,parameter:()=>$n,pointer:()=>On,selector:()=>Vn,struct:()=>Wn,switch_:()=>qn,typeDeclaration:()=>Gn,typeReference:()=>Yn});l();f();l();f();l();f();l();f();l();f();var w=class extends K{async toStringAsync({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o}){let s=new Ie({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o});return this.write(s),s.toStringAsync()}toString({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o}){let s=new Ie({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:o});return this.write(s),s.toString()}};var A=class extends w{constructor({docs:e}={}){super();u(this,"docs");this.docs=e}write(e){this.docs!=null&&this.docs.split(`
25
25
  `).forEach(r=>{e.writeLine(`// ${r}`)})}};var X=class extends w{constructor({name:e,type:r,docs:i}){super();u(this,"name");u(this,"type");u(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new A({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" = "),e.writeNode(this.type)}};l();f();var _=class extends w{constructor(e){super();u(this,"arg");this.arg=e}write(e){return new k(this.arg).write(e)}};l();f();l();f();var O=class extends w{constructor(e){super();u(this,"name");this.name=e}write(e){e.write(this.name)}};l();f();l();f();l();f();function ue({writer:n,arguments_:t,multiline:e=!0}){let r=t.map(i=>i instanceof E&&E.isNop(i)?E.nil():i);if(r.length===0){n.write("()");return}if(e){wn({writer:n,arguments_:r});return}xn({writer:n,arguments_:r})}function wn({writer:n,arguments_:t}){n.writeLine("("),n.indent();for(let e of t)e.write(n),n.writeLine(",");n.dedent(),n.write(")")}function xn({writer:n,arguments_:t}){n.write("("),t.forEach((e,r)=>{r>0&&n.write(", "),e.write(n)}),n.write(")")}var S=class extends w{constructor({func:e,arguments_:r,multiline:i=!0}){super();u(this,"func");u(this,"arguments_");u(this,"multiline");this.func=e,this.arguments_=r,this.multiline=i}write(e){e.writeNode(this.func),ue({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};l();f();l();f();function jt({writer:n,generics:t}){t.length!==0&&(n.write("["),t.forEach((e,r)=>{r>0&&n.write(", "),e!=null&&n.writeNode(e)}),n.write("]"))}var F=class extends w{constructor({name:e,importPath:r,generics:i}){super();u(this,"name");u(this,"importPath");u(this,"generics");this.name=e,this.importPath=r,this.generics=i}write(e){if(this.importPath==null||e.importPath===this.importPath){e.write(this.name);return}let r=e.addImport(this.importPath);e.write(`${r}.${this.name}`),this.generics!=null&&jt({writer:e,generics:this.generics})}};l();f();var V=class extends w{constructor({method:e,arguments_:r,on:i,multiline:o}){super();u(this,"on");u(this,"method");u(this,"arguments_");u(this,"multiline");this.on=i,this.method=e,this.arguments_=r,this.multiline=o}write(e){this.on.write(e),e.write("."),e.write(this.method),ue({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};var vn=new Set(["bool","date","dateTime","float64","int","int64","string","uuid"]),Ht=new Set(["any","bytes","map","slice"]),E=class n extends w{constructor(e){super();u(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(Rn({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(Nn({value:this.internalType.value}));break;default:x(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:r,entries:i}){return new this({type:"map",keyType:e,valueType:r,entries:i})}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:r}){return new this({type:"slice",valueType:e,values:r})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:r}){return new this({type:"struct",typeReference:e,fields:r})}static structPointer({typeReference:e,fields:r,generics:i}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:r,generics:i})})}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:r}){switch(typeof r){case"boolean":e.write(r.toString());return;case"string":e.write(r.includes('"')?`\`${r}\``:`"${r}"`);return;case"number":e.write(r.toString());return;case"object":if(r==null){e.write("nil");return}if(Array.isArray(r)){this.writeAnyArray({writer:e,value:r});return}this.writeAnyObject({writer:e,value:r});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof r}`)}}writeAnyArray({writer:e,value:r}){if(e.write("[]any"),r.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let i of r)e.writeNode(n.any(i)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:r}){e.write("map[string]any");let i=Object.entries(r);if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[o,s]of i)e.write(`"${o}": `),e.writeNode(n.any(s)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:r}){e.write("map["),e.writeNode(r.keyType),e.write("]"),e.writeNode(r.valueType);let i=An({entries:r.entries});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)o.key.write(e),e.write(": "),o.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeOptional({writer:e,type:r}){if(vn.has(r.internalType.type)){e.writeNode(Tn({writer:e,type:r}));return}if(Ht.has(r.internalType.type)){r.write(e);return}if(r.internalType.type==="enum"){e.writeNode(new V({on:r.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),r.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||Ht.has(e.internalType.type)}writeSlice({writer:e,slice:r}){e.write("[]"),e.writeNode(r.valueType);let i=Fn({values:r.values});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)o.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeStruct({writer:e,struct:r}){e.writeNode(r.typeReference),r.generics!=null&&(e.write("["),r.generics.forEach((o,s)=>{s>0&&e.write(", "),e.writeNode(o)}),e.write("]"));let i=En({fields:r.fields});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)e.write(`${o.name}: `),o.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function Tn({writer:n,type:t}){return new S({func:new F({name:In({type:t}),importPath:n.rootImportPath}),arguments_:[t]})}function In({type:n}){switch(n.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 Rn({writer:n,type:t}){let e=t.type==="date"?"MustParseDate":"MustParseDateTime";return new S({func:new F({name:e,importPath:n.rootImportPath}),arguments_:[new _(`"${t.value}"`)]})}function Nn({value:n}){return new S({func:new F({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new _(`"${n}"`)]})}function An({entries:n}){return n.filter(t=>!E.isNop(t.key)&&!E.isNop(t.value))}function En({fields:n}){return n.filter(t=>!E.isNop(t.value))}function Fn({values:n}){return n.filter(t=>!E.isNop(t))}var Q=class n extends w{constructor({name:e,docs:r}){super();u(this,"name");u(this,"docs");u(this,"members",[]);u(this,"methods",[]);u(this,"constructor_");this.name=e,this.docs=r}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 A({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 r of this.members)e.writeNode(new A({docs:r.docs})),e.writeNode(n.getMemberIdentifier({name:this.name,member:r})),e.write(" = "),e.writeNode(E.string(r.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 r of this.methods)e.newLine(),e.writeNode(r),e.newLine()}static getMemberIdentifier({name:e,member:r}){return new O(`${e}${r.name}`)}};l();f();var Z=class extends w{constructor({name:e,type:r,docs:i,tags:o}){super();u(this,"name");u(this,"type");u(this,"docs");u(this,"tags",[]);this.name=e,this.type=r,this.docs=i,this.tags=o!=null?o:[]}addTags(...e){this.tags.push(...e)}write(e){e.writeNode(new A({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((r,i)=>{i>0&&e.write(" "),e.write(`${r.name}:"${r.value}"`)}),e.write("`"))}};l();f();var ee=class extends w{constructor({nodes:e}={nodes:[]}){super();u(this,"nodes");this.nodes=e!=null?e:[]}add(...e){this.nodes.push(...e)}write(e){for(let r of this.nodes)r.write(e)}};l();f();l();f();var W=class extends w{constructor({name:e,parameters:r,return_:i,body:o,docs:s,typeReference:p,multiline:h,receiver:m,pointerReceiver:y}){super();u(this,"parameters");u(this,"return_");u(this,"name");u(this,"body");u(this,"docs");u(this,"typeReference");u(this,"multiline");u(this,"receiver");u(this,"pointerReceiver");this.name=e,this.parameters=r,this.return_=i,this.body=o,this.docs=s,this.typeReference=p,this.multiline=h,this.receiver=m,this.pointerReceiver=y}write(e){var r;e.writeNode(new A({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}`),ue({writer:e,arguments_:this.parameters,multiline:this.multiline}),this.return_!=null&&(e.write(" "),this.return_.length>1&&e.write("("),this.return_.forEach((i,o)=>{o>0&&e.write(", "),e.writeNode(i)}),this.return_.length>1&&e.write(")")),e.writeLine("{"),e.indent(),(r=this.body)==null||r.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.write("}")}writeReceiver({writer:e,typeReference:r,receiver:i}){e.write(` (${this.getReceiverName({typeReference:r,receiver:i})} `),this.pointerReceiver&&e.write("*"),r.write(e),e.write(")")}getReceiverName({typeReference:e,receiver:r}){return r!=null?r:e.name.charAt(0).toLowerCase()}};var te=class extends w{constructor({name:e,parameters:r,return_:i,body:o,docs:s,multiline:p}){super();u(this,"func");this.func=new W({name:e,parameters:r,return_:i,body:o,docs:s,multiline:p})}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)}};l();f();var Re=class extends w{constructor({nodes:e}){super();u(this,"nodes");this.nodes=e}write(e){for(let r of this.nodes)e.newLine(),r.write(e),e.newLine()}};l();f();var re=class extends w{constructor({name:e,type:r,docs:i}){super();u(this,"name");u(this,"type");u(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new A({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};l();f();var ne=class extends w{constructor({node:e}){super();u(this,"node");this.node=e}write(e){e.write("*"),this.node.write(e)}};l();f();var ie=class extends w{constructor({on:e,selector:r}){super();u(this,"on");u(this,"selector");this.on=e,this.selector=r}write(e){e.writeNode(this.on),e.write("."),e.writeNode(this.selector)}};l();f();var oe=class extends w{constructor({name:e,embeds:r,fields:i,docs:o}){super();u(this,"name");u(this,"embeds",[]);u(this,"fields",[]);u(this,"docs");u(this,"methods",[]);u(this,"constructor_");this.name=e,this.docs=o,this.embeds=r!=null?r:[],this.fields=i!=null?i:[]}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 A({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 o of this.embeds)e.writeNode(o),e.newLine();let r=this.fields.filter(o=>this.isExported(o));for(let o of r)e.writeNode(o),e.newLine();let i=this.fields.filter(o=>!this.isExported(o));r.length>0&&i.length>0&&e.newLine();for(let o of i)e.writeNode(o),e.newLine();e.dedent(),e.write("}")}writeConstructor({writer:e,constructor:r}){r.name!=null?e.write(`func ${r.name}(`):e.write(`func New${this.name}(`),r.parameters.forEach((i,o)=>{o>0&&e.write(", "),e.writeNode(i)}),e.write(`) *${this.name} {`),e.newLine(),e.indent(),e.writeNode(r.body),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeMethods({writer:e}){if(this.methods.length!==0){e.writeNewLineIfLastLineNot();for(let r of this.methods)e.newLine(),e.writeNode(r),e.newLine()}}isExported(e){let r=e.name.charAt(0);return r===r.toUpperCase()}};l();f();var Ne=class extends w{constructor({on:e,cases:r,default:i}){super();u(this,"on");u(this,"cases");u(this,"default");this.on=e,this.cases=r,this.default=i}write(e){let r=this.cases;this.default!=null&&r.push({on:new O("default"),body:this.default}),e.write("switch "),e.writeNode(this.on),e.writeLine("{"),e.indent();for(let i of r)e.write("case "),e.writeNode(i.on),e.writeLine(":"),e.indent(),e.writeNode(i.body),e.dedent(),e.writeNewLineIfLastLineNot();e.dedent(),e.write("}")}};l();f();var bn=new Set(["any","bytes","map","slice"]),Ae=class n extends w{constructor(e){super();u(this,"internalType");this.internalType=e}write(e,{comment:r}={}){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(Oe);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(Ve);break;case"variadic":e.write("..."),this.internalType.value.write(e);break;default:x(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,r){return new this({type:"map",keyType:e,valueType:r})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return n.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"||bn.has(e.internalType.type)}static isAlreadyVariadic(e){return e.internalType.type==="variadic"}},Oe=new F({importPath:"time",name:"Time"}),Ve=new F({importPath:"github.com/google/uuid",name:"UUID"}),it=new F({importPath:"io",name:"Reader"});l();f();var se=class extends w{constructor({name:e,type:r,docs:i}){super();u(this,"name");u(this,"type");u(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new A({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" "),e.writeNode(this.type)}};function Pn(n){return new X(n)}function kn(n){return new _(n)}function Sn(n){return new Q(n)}function Cn(n){return new Z(n)}function Un(n={}){return new ee(n)}function Bn(n){return new te(n)}function Ln(n){return new O(n)}function _n(n){return new S(n)}function Mn(n){return new V(n)}function Dn(n){return new W(n)}function $n(n){return new re(n)}function On(n){return new ne(n)}function Vn(n){return new ie(n)}function Wn(n={}){return new oe(n)}function qn(n){return new Ne(n)}function Gn(n){return new se(n)}function Yn(n){return new F(n)}l();f();Yt();var jn="sdk";function ot({config:n,customConfig:t}){let e=zn({config:n}),r=Hn({config:n,customConfig:t});return e!=null?Jn({importPath:r,majorVersion:e}):r}function Hn({config:n,customConfig:t,isModulePath:e=!1}){var i,o,s,p;let r=(s=(o=t==null?void 0:t.importPath)!=null?o:(i=t==null?void 0:t.module)==null?void 0:i.path)!=null?s:n.output.mode.type==="github"?Xn(n.output.mode.repoUrl,"https://"):jn;return e?r:Gt.join(r,(p=t==null?void 0:t.packagePath)!=null?p:"")}function zn({config:n}){let t=Kn({config:n});if(!(t==null||t==="v0"||t==="v1"))return`${t}`}function Kn({config:n}){let t=Qn(n);if(t==null)return;let e=t.split(".");if(e[0]==null)return;let r=e[0];return r.startsWith("v")?r:`v${r}`}function Jn({importPath:n,majorVersion:t}){return Te(n)===t?n:`${n}/${t}`}function Xn(n,t){return n.startsWith(t)?n.slice(t.length):n}function Qn(n){var e;let t=(e=n==null?void 0:n.output)==null?void 0:e.mode;if(t!=null)return t.type==="github"||t.type==="publish"?t.version:void 0}l();f();var We=class{constructor({context:t}){u(this,"context");this.context=t}convert(t){if(t.value===null&&!this.context.isNullable(t.typeReference)&&this.context.errors.add({severity:v.Critical,message:"Expected non-null value, but got null"}),t.value==null)return a.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return a.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?a.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"nullable":{let e=t.typeReference.value;if(e.type==="named"){let r=this.context.resolveNamedType({typeId:e.value});if((r==null?void 0:r.type)==="alias"&&["list","set","map"].includes(r.typeReference.type)){let i=this.convert({typeReference:r.typeReference,value:t.value,as:t.as}),o=this.context.getTypeName(r.declaration.name),s=this.context.getImportPath(r.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:i,aliasName:o,aliasImportPath:s})}}return a.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"optional":{let e=t.typeReference.value;if(e.type==="named"){let r=this.context.resolveNamedType({typeId:e.value});if((r==null?void 0:r.type)==="alias"&&["list","set","map"].includes(r.typeReference.type)){let i=this.convert({typeReference:r.typeReference,value:t.value,as:t.as}),o=this.context.getTypeName(r.declaration.name),s=this.context.getImportPath(r.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:i,aliasName:o,aliasImportPath:s})}}return a.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:x(t.typeReference)}}convertToPointerIfPossible(t){let e=this.convert(t);switch(t.typeReference.type){case"named":{let r=this.context.resolveNamedType({typeId:t.typeReference.value});return(r==null?void 0:r.type)==="enum"?a.TypeInstantiation.reference(a.invokeMethod({on:e,method:"Ptr",arguments_:[]})):e}default:return e}}convertList({list:t,value:e}){return Array.isArray(e)?a.TypeInstantiation.slice({valueType:this.context.dynamicTypeMapper.convert({typeReference:t}),values:e.map((r,i)=>{this.context.errors.scope({index:i});try{return this.convert({typeReference:t,value:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:v.Critical,message:`Expected array but got: ${typeof e}`}),a.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:v.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),a.TypeInstantiation.nop()):a.TypeInstantiation.map({keyType:this.context.dynamicTypeMapper.convert({typeReference:t.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:t.value}),entries:Object.entries(e).map(([r,i])=>{this.context.errors.scope(r);try{return{key:this.convert({typeReference:t.key,value:r,as:"key"}),value:this.convert({typeReference:t.value,value:i})}}finally{this.context.errors.unscope()}})})}convertNamed({named:t,value:e,as:r}){switch(t.type){case"alias":return this.convertAlias({aliasType:t,value:e,as:r});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:x(t)}}convertAlias({aliasType:t,value:e,as:r}){switch(t.typeReference.type){case"literal":return a.TypeInstantiation.reference(a.invokeFunc({func:a.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:r})}}reconstructAliasCollectionLiteral({collectionLiteral:t,aliasName:e,aliasImportPath:r}){let i=t.internalType;return i.type==="slice"?a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(a.typeReference({name:e,importPath:r}));let s=i.values;if(s.length===0){o.write("{}");return}o.writeLine("{"),o.indent();for(let p of s)o.writeNode(p),o.writeLine(",");o.dedent(),o.write("}")})):i.type==="map"?a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(a.typeReference({name:e,importPath:r}));let s=i.entries;if(s.length===0){o.write("{}");return}o.writeLine("{"),o.indent();for(let p of s)o.writeNode(p.key),o.write(": "),o.writeNode(p.value),o.writeLine(",");o.dedent(),o.write("}")})):a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(t)}))}convertLiteralValue(t){switch(t.type){case"boolean":return a.TypeInstantiation.bool(t.value);case"string":return a.TypeInstantiation.string(t.value);default:x(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let r=this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),i=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(i==null)return a.TypeInstantiation.nop();let o=i.singleDiscriminatedUnionType,s=this.getBaseFields({discriminatedUnionTypeInstance:i,singleDiscriminatedUnionType:o});switch(o.type){case"samePropertiesAsObject":{let p=this.context.resolveNamedType({typeId:o.typeId});return p==null?a.TypeInstantiation.nop():a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(o.discriminantValue.name),value:this.convertNamed({named:p,value:i.value})},...s]})}case"singleProperty":{let p=this.context.getRecord(i.value);if(p==null)return a.TypeInstantiation.nop();try{return this.context.errors.scope(o.discriminantValue.wireValue),a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(o.discriminantValue.name),value:this.convert({typeReference:o.typeReference,value:p[o.discriminantValue.wireValue]})},...s]})}finally{this.context.errors.unscope()}}case"noProperties":return a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(i.discriminantValue.name),value:a.TypeInstantiation.string(o.discriminantValue.wireValue)},...s]});default:x(o)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){var i,o;return this.context.associateByWireValue({parameters:(i=e.properties)!=null?i:[],values:(o=this.context.getRecord(t.value))!=null?o:{},ignoreMissingParameters:!0}).map(s=>{this.context.errors.scope(s.name.wireValue);try{return{name:this.context.getTypeName(s.name.name),value:this.convert(s)}}finally{this.context.errors.unscope()}})}convertObject({object_:t,value:e}){var i;let r=this.context.associateByWireValue({parameters:t.properties,values:(i=this.context.getRecord(e))!=null?i:{}});return a.TypeInstantiation.structPointer({typeReference:a.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),fields:r.map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getTypeName(o.name.name),value:this.convert(o)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:t,value:e}){let r=this.getEnumValueName({enum_:t,value:e});return r==null?a.TypeInstantiation.nop():a.TypeInstantiation.enum(a.typeReference({name:r,importPath:this.context.getImportPath(t.declaration.fernFilepath)}))}getEnumValueName({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:v.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let r=t.values.find(i=>i.wireValue===e);if(r==null){this.context.errors.add({severity:v.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return`${this.context.getTypeName(t.declaration.name)}${this.context.getTypeName(r.name)}`}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let r=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});if(r==null)return a.TypeInstantiation.nop();let i=this.getUndiscriminatedUnionFieldName({typeReference:r.valueTypeReference});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.structPointer({typeReference:this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),fields:[{name:i,value:r.typeInstantiation}]})}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let r of t.types)try{let i=this.convert({typeReference:r,value:e});return{valueTypeReference:r,typeInstantiation:i}}catch(i){continue}this.context.errors.add({severity:v.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:x(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 r=this.getUndiscriminatedUnionFieldName({typeReference:t.value});if(r!=null)return`${e}${r}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:x(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:x(t)}}convertUnknown({value:t}){return a.TypeInstantiation.any(t)}convertPrimitive({primitive:t,value:e,as:r}){switch(t){case"INTEGER":case"UINT":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.int(i)}case"LONG":case"UINT_64":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.int64(i)}case"FLOAT":case"DOUBLE":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.float64(i)}case"BOOLEAN":{let i=this.getValueAsBoolean({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.bool(i)}case"STRING":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.string(i)}case"DATE":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.date(i)}case"DATE_TIME":{let i=this.context.getValueAsString({value:e});if(i==null)return a.TypeInstantiation.nop();let o=this.normalizeDateTimeString(i);return a.TypeInstantiation.dateTime(o)}case"UUID":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.uuid(i)}case"BASE_64":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.bytes(i)}case"BIG_INTEGER":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.string(i)}default:x(t)}}getValueAsNumber({value:t,as:e}){let r=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:t,as:e}){let r=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:r})}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}};l();f();var qe=class{constructor({context:t}){u(this,"context");this.context=t}convert(t){switch(t.typeReference.type){case"list":return a.Type.slice(this.convert({typeReference:t.typeReference.value}));case"literal":return this.convertLiteral({literal:t.typeReference.value});case"map":return a.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 a.Type.optional(this.convert({typeReference:t.typeReference.value}));case"nullable":return a.Type.optional(this.convert({typeReference:t.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:t.typeReference.value});case"set":return a.Type.slice(this.convert({typeReference:t.typeReference}));case"unknown":return this.convertUnknown();default:x(t.typeReference)}}convertLiteral({literal:t}){switch(t.type){case"boolean":return a.Type.bool();case"string":return a.Type.string()}}convertNamed({named:t}){let e=a.Type.reference(a.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 a.Type.pointer(e);default:x(t)}}convertUnknown(){return a.Type.any()}convertPrimitive({primitive:t}){switch(t){case"INTEGER":return a.Type.int();case"UINT":return a.Type.int();case"LONG":return a.Type.int64();case"UINT_64":return a.Type.int64();case"FLOAT":return a.Type.float64();case"DOUBLE":return a.Type.float64();case"BOOLEAN":return a.Type.bool();case"STRING":return a.Type.string();case"DATE":return a.Type.date();case"DATE_TIME":return a.Type.dateTime();case"UUID":return a.Type.uuid();case"BASE_64":return a.Type.bytes();case"BIG_INTEGER":return a.Type.string();default:x(t)}}};l();f();var Ge=class{constructor({context:t}){u(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){var o;let r={fileFields:[],bodyPropertyFields:[]},i=(o=this.context.getRecord(e))!=null?o:{};for(let s of t.properties)switch(s.type){case"file":r.fileFields.push({name:this.context.getTypeName(s.name),value:this.getSingleFileProperty({property:s,record:i})});break;case"fileArray":r.fileFields.push({name:this.context.getTypeName(s.name),value:this.getArrayFileProperty({property:s,record:i})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getTypeName(s.name.name),value:this.getBodyProperty({property:s,record:i})});break;default:x(s)}return r}getSingleFileProperty({property:t,record:e}){let r=this.context.getSingleFileValue({property:t,record:e})||"";return a.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(r))}getArrayFileProperty({property:t,record:e}){let r=this.context.getFileArrayValues({property:t,record:e});return r==null?a.TypeInstantiation.nop():a.TypeInstantiation.slice({valueType:a.Type.reference(this.context.getIoReaderTypeReference()),values:r.map(i=>a.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(i)))})}getBodyProperty({property:t,record:e}){let r=e[t.name.wireValue];return r==null?a.TypeInstantiation.nop():this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:r})}};var Ye=class n extends ve{constructor({ir:e,config:r}){super({ir:e,config:r});u(this,"ir");u(this,"customConfig");u(this,"dynamicTypeMapper");u(this,"dynamicTypeInstantiationMapper");u(this,"filePropertyMapper");u(this,"rootImportPath");this.ir=e,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeMapper=new qe({context:this}),this.dynamicTypeInstantiationMapper=new We({context:this}),this.filePropertyMapper=new Ge({context:this}),this.rootImportPath=ot({config:r,customConfig:this.customConfig})}clone(){return new n({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:x(e)}}getMethodName(e){return e.pascalCase.unsafeName}getTestMethodName(e){return e.declaration.fernFilepath.allParts.map(r=>r.pascalCase.unsafeName).join("")+e.declaration.name.pascalCase.unsafeName}getTypeName(e){return e.pascalCase.unsafeName}getImportPath(e){let r=e.packagePath.map(i=>i.pascalCase.unsafeName.toLowerCase());return[this.rootImportPath,...r].join("/")}getImportPathForRequest(e){var r;return(r=this.customConfig)!=null&&r.exportAllRequestsAtRoot?this.rootImportPath:this.getImportPath(e)}getContextTypeReference(){return a.typeReference({name:"Context",importPath:"context"})}getContextTodoFunctionInvocation(){return a.invokeFunc({func:a.typeReference({name:"TODO",importPath:"context"}),arguments_:[]})}getIoReaderTypeReference(){return a.typeReference({name:"Reader",importPath:"io"})}getTestingTypeReference(){return a.typeReference({name:"T",importPath:"testing"})}getNewStringsReaderFunctionInvocation(e){return a.invokeFunc({func:a.typeReference({name:"NewReader",importPath:"strings"}),arguments_:[a.TypeInstantiation.string(e)]})}getClientConstructorName(){var e,r;return((e=this.customConfig)==null?void 0:e.clientConstructorName)!=null?this.customConfig.clientConstructorName:((r=this.customConfig)==null?void 0:r.exportedClientName)!=null?`New${this.customConfig.exportedClientName}`:`New${this.getClientName()}`}getClientName(){var e;return((e=this.customConfig)==null?void 0:e.clientName)!=null?this.customConfig.clientName:"Client"}getClientImportPath(){return`${this.rootImportPath}/client`}getOptionImportPath(){return`${this.rootImportPath}/option`}getGoTypeReferenceFromDeclaration({declaration:e}){return a.typeReference({name:e.name.pascalCase.unsafeName,importPath:this.getImportPath(e.fernFilepath)})}getEnvironmentTypeReferenceFromID(e){let r=this.resolveEnvironmentName(e);if(r!=null)return this.getEnvironmentTypeReference(r)}getEnvironmentTypeReference(e){return a.typeReference({name:`Environments.${this.getTypeName(e)}`,importPath:this.rootImportPath})}static chainMethods(e,...r){if(r.length===0)throw new Error("Must have methods to chain");let i=e;for(let o of r)i=a.invokeMethod({on:i,method:o.method,arguments_:o.arguments_,multiline:o.multiline});return i}};l();f();var zt="example",st="fern",Zn="do",Ee="client",pe=a.TypeInstantiation,ei="WireMockBaseURL",ti="WireMockClient",je=class{constructor({context:t,formatter:e}){u(this,"context");u(this,"formatter");this.context=t,this.formatter=e}async generateSnippet({endpoint:t,request:e,options:r}){var s,p,h;return((p=(s=r==null?void 0:r.config)==null?void 0:s.outputWiremockTests)!=null?p:!1)?this.generateWiremockTest({endpoint:t,snippet:e}):await this.buildCodeBlock({endpoint:t,snippet:e}).toStringAsync({packageName:zt,importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(h=this.context.customConfig)!=null?h:{},formatter:this.formatter})}generateSnippetSync({endpoint:t,request:e,options:r}){var s,p,h;return((p=(s=r==null?void 0:r.config)==null?void 0:s.outputWiremockTests)!=null?p:!1)?this.generateWiremockTest({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e}).toString({packageName:zt,importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(h=this.context.customConfig)!=null?h:{},formatter:this.formatter})}generateWiremockTest({endpoint:t,snippet:e}){var i;return this.buildWiremockTestCodeBlock({endpoint:t,snippet:e}).toString({packageName:"wiremock",importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(i=this.context.customConfig)!=null?i:{},formatter:this.formatter})}buildCodeBlock({endpoint:t,snippet:e}){return a.codeblock(r=>{r.writeNode(a.func({name:Zn,parameters:[],return_:[],body:a.codeblock(i=>{i.writeNode(this.constructClient({endpoint:t,snippet:e})),i.writeLine(),i.writeNode(this.callMethod({endpoint:t,snippet:e}))})})),r.writeNewLineIfLastLineNot()})}buildWiremockTestCodeBlock({endpoint:t,snippet:e}){return a.codeblock(r=>{r.writeNode(a.func({name:"Test"+this.context.getTestMethodName(t)+"WithWireMock",parameters:[a.parameter({name:"t",type:a.Type.pointer(a.Type.reference(this.context.getTestingTypeReference()))})],return_:[],body:a.codeblock(i=>{for(let o of this.buildWiremockTestSetup({endpoint:t}))i.writeNode(o),i.writeLine();i.writeLine(),i.writeNode(this.constructWiremockTestClient({endpoint:t,snippet:e})),i.writeLine(),i.writeNode(this.callClientMethodAndAssert({endpoint:t,snippet:e}))})})),r.writeNewLineIfLastLineNot()})}constructClient({endpoint:t,snippet:e}){return a.codeblock(r=>{r.write(`${Ee} := `),r.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:t,snippet:e})))})}constructWiremockTestClient({endpoint:t,snippet:e}){return a.codeblock(r=>{r.write(`${Ee} := `),r.writeNode(this.getRootClientFuncInvocation(this.getWiremockTestConstructorArgs()))})}writeMethodInvocation({writer:t,endpoint:e,snippet:r}){let{otherArgs:i,requestArg:o}=this.getMethodArgs({endpoint:e,snippet:r});if(o!=null)if(o instanceof a.TypeInstantiation&&a.TypeInstantiation.isNop(o))t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i,a.codeblock("nil")]}));else{t.write("request := "),t.writeNode(o),t.writeLine();let s=a.codeblock("request");t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i,s]}))}else t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i]}))}callMethod({endpoint:t,snippet:e}){return a.codeblock(r=>{this.writeMethodInvocation({writer:r,endpoint:t,snippet:e})})}getConstructorArgs({endpoint:t,snippet:e}){let r=[],i=this.getConstructorBaseUrlArg({baseUrl:e.baseURL,environment:e.environment});return i!=null&&r.push(i),t.auth!=null&&(e.auth!=null?r.push(this.getConstructorAuthArg({auth:t.auth,values:e.auth})):this.context.errors.add({severity:v.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(L.Headers),this.context.ir.headers!=null&&e.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),r}getWiremockTestConstructorArgs(){return[a.codeblock(t=>{t.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[a.codeblock(ei)]}))})]}getConstructorAuthArg({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),pe.nop();switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArg({auth:t,values:e}):pe.nop();case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArg({auth:t,values:e}):pe.nop();case"header":return e.type==="header"?this.getConstructorHeaderAuthArg({auth:t,values:e}):pe.nop();case"oauth":return this.addWarning("The Go SDK doesn't support OAuth client credentials yet"),pe.nop();case"inferred":return this.addWarning("The Go SDK Generator does not support Inferred auth scheme yet"),pe.nop();default:x(t)}}addError(t){this.context.errors.add({severity:v.Critical,message:t})}addWarning(t){this.context.errors.add({severity:v.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.username),a.TypeInstantiation.string(e.password)]}))})}getConstructorBaseUrlArg({baseUrl:t,environment:e}){let r=this.getBaseUrlArg({baseUrl:t,environment:e});if(r!=null)return a.codeblock(i=>{i.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:v.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return a.TypeInstantiation.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let r=this.context.getEnvironmentTypeReferenceFromID(e);if(r==null){this.context.errors.add({severity:v.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return a.TypeInstantiation.reference(r)}this.context.isMultiEnvironmentValues(e)&&this.context.errors.add({severity:v.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 a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.token)]}))})}getConstructorHeaderAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.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})]}))})}getConstructorHeaderArgs({headers:t,values:e}){let r=[];for(let i of t){let o=this.getConstructorHeaderArg({header:i,value:e.value});o!=null&&r.push(o)}return r}getConstructorHeaderArg({header:t,value:e}){let r=this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:e});if(!a.TypeInstantiation.isNop(r))return a.codeblock(i=>{i.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}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:x(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){var s,p;let r=[];this.context.errors.scope(L.PathParameters);let i=[...(s=this.context.ir.pathParameters)!=null?s:[],...(p=t.pathParameters)!=null?p:[]];i.length>0&&r.push(...this.getPathParameters({namedParameters:i,snippet:e}).map(h=>h.value)),this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let o=t.body!=null?this.getBodyRequestArg({body:t.body,value:e.requestBody}):void 0;return this.context.errors.unscope(),{otherArgs:r,requestArg:o}}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:x(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:v.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),a.TypeInstantiation.nop()):a.TypeInstantiation.bytes(t)}getMethodArgsForInlinedRequest({request:t,snippet:e}){var y,g,T,I,R,Y;let r=[],{inlinePathParameters:i,inlineFileProperties:o}={inlinePathParameters:(g=(y=this.context.customConfig)==null?void 0:y.inlinePathParameters)!=null?g:!0,inlineFileProperties:(I=(T=this.context.customConfig)==null?void 0:T.inlineFileProperties)!=null?I:!0};this.context.errors.scope(L.PathParameters);let s=[],p=[...(R=this.context.ir.pathParameters)!=null?R:[],...(Y=t.pathParameters)!=null?Y:[]];p.length>0&&s.push(...this.getPathParameters({namedParameters:p,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let h=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})||r.push(...s.map(le=>le.value)),o||r.push(...h.fileFields.map(le=>le.value));let m=this.context.needsRequestParameter({request:t,inlinePathParameters:i,inlineFileProperties:o})?this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})?s:[],filePropertyInfo:h}):void 0;return{otherArgs:r,requestArg:m}}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:r,filePropertyInfo:i}){var y,g,T,I;this.context.errors.scope(L.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:(y=t.queryParameters)!=null?y:[],values:(g=e.queryParameters)!=null?g:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(L.Headers);let h=this.context.associateByWireValue({parameters:(T=t.headers)!=null?T:[],values:(I=e.headers)!=null?I:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let m=t.body!=null?this.getInlinedRequestBodyStructFields({body:t.body,value:e.requestBody,filePropertyInfo:i}):[];return this.context.errors.unscope(),a.TypeInstantiation.structPointer({typeReference:a.typeReference({name:this.context.getMethodName(t.declaration.name),importPath:this.context.getImportPathForRequest(t.declaration.fernFilepath)}),fields:[...r,...s,...h,...m]})}getInlinedRequestBodyStructFields({body:t,value:e,filePropertyInfo:r}){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:r});default:x(t)}}getFileUploadRequestBodyStructFields({filePropertyInfo:t}){var e;return(e=this.context.customConfig)!=null&&e.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:x(t)}}getInlinedRequestBodyPropertyStructFields({parameters:t,value:e}){var o;let r=[],i=this.context.associateByWireValue({parameters:t,values:(o=this.context.getRecord(e))!=null?o:{}});for(let s of i)r.push({name:this.context.getTypeName(s.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(s)});return r}getPathParameters({namedParameters:t,snippet:e}){var o;let r=[],i=this.context.associateByWireValue({parameters:t,values:(o=e.pathParameters)!=null?o:{}});for(let s of i)r.push({name:this.context.getTypeName(s.name.name),value:this.context.dynamicTypeInstantiationMapper.convertToPointerIfPossible(s)});return r}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 a.invokeFunc({func:a.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:t})}buildWiremockTestSetup({endpoint:t,errorCase:e}){let r="stub";return[]}callClientMethodAndAssert({endpoint:t,snippet:e}){return a.codeblock(r=>{this.writeMethodInvocation({writer:r,endpoint:t,snippet:e}),r.writeLine(),r.writeLine(),r.write("ok, countErr := "),r.writeNode(a.invokeMethod({on:a.codeblock(ti),method:"Verify",arguments_:[a.invokeMethod({on:a.codeblock("stub"),method:"Request",arguments_:[],multiline:!1}),a.codeblock("1")],multiline:!1})),r.writeLine(),r.writeNode(a.invokeFunc({func:a.typeReference({name:"NoError",importPath:"github.com/stretchr/testify/require"}),arguments_:[a.codeblock("t"),a.codeblock("countErr"),a.TypeInstantiation.string("Failed to verify WireMock request was matched")],multiline:!1})),r.writeLine(),r.writeNode(a.invokeFunc({func:a.typeReference({name:"True",importPath:"github.com/stretchr/testify/require"}),arguments_:[a.codeblock("t"),a.codeblock("ok"),a.TypeInstantiation.string("WireMock request was not matched")],multiline:!1})),r.writeLine()})}};var at=class extends ge{constructor({ir:e,config:r,formatter:i}){super(new Ye({ir:e,config:r}));u(this,"formatter");this.formatter=i}async generate(e,r){return super.generate(e,r)}generateSync(e,r){return super.generateSync(e,r)}createSnippetGenerator(e){return new je({context:e,formatter:this.formatter})}};0&&(module.exports={DynamicSnippetsGenerator});
26
+ `)?`\`${this.internalType.value}\``:`"${this.internalType.value}"`);break;case"struct":this.writeStruct({writer:e,struct:this.internalType});break;case"uuid":e.writeNode(Nn({value:this.internalType.value}));break;default:x(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:r,entries:i}){return new this({type:"map",keyType:e,valueType:r,entries:i})}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:r}){return new this({type:"slice",valueType:e,values:r})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:r}){return new this({type:"struct",typeReference:e,fields:r})}static structPointer({typeReference:e,fields:r,generics:i}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:r,generics:i})})}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:r}){switch(typeof r){case"boolean":e.write(r.toString());return;case"string":e.write(r.includes('"')?`\`${r}\``:`"${r}"`);return;case"number":e.write(r.toString());return;case"object":if(r==null){e.write("nil");return}if(Array.isArray(r)){this.writeAnyArray({writer:e,value:r});return}this.writeAnyObject({writer:e,value:r});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof r}`)}}writeAnyArray({writer:e,value:r}){if(e.write("[]any"),r.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let i of r)e.writeNode(n.any(i)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:r}){e.write("map[string]any");let i=Object.entries(r);if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[o,s]of i)e.write(`"${o}": `),e.writeNode(n.any(s)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:r}){e.write("map["),e.writeNode(r.keyType),e.write("]"),e.writeNode(r.valueType);let i=An({entries:r.entries});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)o.key.write(e),e.write(": "),o.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeOptional({writer:e,type:r}){if(vn.has(r.internalType.type)){e.writeNode(Tn({writer:e,type:r}));return}if(Ht.has(r.internalType.type)){r.write(e);return}if(r.internalType.type==="enum"){e.writeNode(new V({on:r.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),r.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||Ht.has(e.internalType.type)}writeSlice({writer:e,slice:r}){e.write("[]"),e.writeNode(r.valueType);let i=Fn({values:r.values});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)o.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeStruct({writer:e,struct:r}){e.writeNode(r.typeReference),r.generics!=null&&(e.write("["),r.generics.forEach((o,s)=>{s>0&&e.write(", "),e.writeNode(o)}),e.write("]"));let i=En({fields:r.fields});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)e.write(`${o.name}: `),o.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function Tn({writer:n,type:t}){return new S({func:new F({name:In({type:t}),importPath:n.rootImportPath}),arguments_:[t]})}function In({type:n}){switch(n.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 Rn({writer:n,type:t}){let e=t.type==="date"?"MustParseDate":"MustParseDateTime";return new S({func:new F({name:e,importPath:n.rootImportPath}),arguments_:[new _(`"${t.value}"`)]})}function Nn({value:n}){return new S({func:new F({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new _(`"${n}"`)]})}function An({entries:n}){return n.filter(t=>!E.isNop(t.key)&&!E.isNop(t.value))}function En({fields:n}){return n.filter(t=>!E.isNop(t.value))}function Fn({values:n}){return n.filter(t=>!E.isNop(t))}var Q=class n extends w{constructor({name:e,docs:r}){super();u(this,"name");u(this,"docs");u(this,"members",[]);u(this,"methods",[]);u(this,"constructor_");this.name=e,this.docs=r}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 A({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 r of this.members)e.writeNode(new A({docs:r.docs})),e.writeNode(n.getMemberIdentifier({name:this.name,member:r})),e.write(" = "),e.writeNode(E.string(r.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 r of this.methods)e.newLine(),e.writeNode(r),e.newLine()}static getMemberIdentifier({name:e,member:r}){return new O(`${e}${r.name}`)}};l();f();var Z=class extends w{constructor({name:e,type:r,docs:i,tags:o}){super();u(this,"name");u(this,"type");u(this,"docs");u(this,"tags",[]);this.name=e,this.type=r,this.docs=i,this.tags=o!=null?o:[]}addTags(...e){this.tags.push(...e)}write(e){e.writeNode(new A({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((r,i)=>{i>0&&e.write(" "),e.write(`${r.name}:"${r.value}"`)}),e.write("`"))}};l();f();var ee=class extends w{constructor({nodes:e}={nodes:[]}){super();u(this,"nodes");this.nodes=e!=null?e:[]}add(...e){this.nodes.push(...e)}write(e){for(let r of this.nodes)r.write(e)}};l();f();l();f();var W=class extends w{constructor({name:e,parameters:r,return_:i,body:o,docs:s,typeReference:p,multiline:h,receiver:m,pointerReceiver:y}){super();u(this,"parameters");u(this,"return_");u(this,"name");u(this,"body");u(this,"docs");u(this,"typeReference");u(this,"multiline");u(this,"receiver");u(this,"pointerReceiver");this.name=e,this.parameters=r,this.return_=i,this.body=o,this.docs=s,this.typeReference=p,this.multiline=h,this.receiver=m,this.pointerReceiver=y}write(e){var r;e.writeNode(new A({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}`),ue({writer:e,arguments_:this.parameters,multiline:this.multiline}),this.return_!=null&&(e.write(" "),this.return_.length>1&&e.write("("),this.return_.forEach((i,o)=>{o>0&&e.write(", "),e.writeNode(i)}),this.return_.length>1&&e.write(")")),e.writeLine("{"),e.indent(),(r=this.body)==null||r.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.write("}")}writeReceiver({writer:e,typeReference:r,receiver:i}){e.write(` (${this.getReceiverName({typeReference:r,receiver:i})} `),this.pointerReceiver&&e.write("*"),r.write(e),e.write(")")}getReceiverName({typeReference:e,receiver:r}){return r!=null?r:e.name.charAt(0).toLowerCase()}};var te=class extends w{constructor({name:e,parameters:r,return_:i,body:o,docs:s,multiline:p}){super();u(this,"func");this.func=new W({name:e,parameters:r,return_:i,body:o,docs:s,multiline:p})}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)}};l();f();var Re=class extends w{constructor({nodes:e}){super();u(this,"nodes");this.nodes=e}write(e){for(let r of this.nodes)e.newLine(),r.write(e),e.newLine()}};l();f();var re=class extends w{constructor({name:e,type:r,docs:i}){super();u(this,"name");u(this,"type");u(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new A({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};l();f();var ne=class extends w{constructor({node:e}){super();u(this,"node");this.node=e}write(e){e.write("*"),this.node.write(e)}};l();f();var ie=class extends w{constructor({on:e,selector:r}){super();u(this,"on");u(this,"selector");this.on=e,this.selector=r}write(e){e.writeNode(this.on),e.write("."),e.writeNode(this.selector)}};l();f();var oe=class extends w{constructor({name:e,embeds:r,fields:i,docs:o}){super();u(this,"name");u(this,"embeds",[]);u(this,"fields",[]);u(this,"docs");u(this,"methods",[]);u(this,"constructor_");this.name=e,this.docs=o,this.embeds=r!=null?r:[],this.fields=i!=null?i:[]}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 A({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 o of this.embeds)e.writeNode(o),e.newLine();let r=this.fields.filter(o=>this.isExported(o));for(let o of r)e.writeNode(o),e.newLine();let i=this.fields.filter(o=>!this.isExported(o));r.length>0&&i.length>0&&e.newLine();for(let o of i)e.writeNode(o),e.newLine();e.dedent(),e.write("}")}writeConstructor({writer:e,constructor:r}){r.name!=null?e.write(`func ${r.name}(`):e.write(`func New${this.name}(`),r.parameters.forEach((i,o)=>{o>0&&e.write(", "),e.writeNode(i)}),e.write(`) *${this.name} {`),e.newLine(),e.indent(),e.writeNode(r.body),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeMethods({writer:e}){if(this.methods.length!==0){e.writeNewLineIfLastLineNot();for(let r of this.methods)e.newLine(),e.writeNode(r),e.newLine()}}isExported(e){let r=e.name.charAt(0);return r===r.toUpperCase()}};l();f();var Ne=class extends w{constructor({on:e,cases:r,default:i}){super();u(this,"on");u(this,"cases");u(this,"default");this.on=e,this.cases=r,this.default=i}write(e){let r=this.cases;this.default!=null&&r.push({on:new O("default"),body:this.default}),e.write("switch "),e.writeNode(this.on),e.writeLine("{"),e.indent();for(let i of r)e.write("case "),e.writeNode(i.on),e.writeLine(":"),e.indent(),e.writeNode(i.body),e.dedent(),e.writeNewLineIfLastLineNot();e.dedent(),e.write("}")}};l();f();var bn=new Set(["any","bytes","map","slice"]),Ae=class n extends w{constructor(e){super();u(this,"internalType");this.internalType=e}write(e,{comment:r}={}){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(Oe);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(Ve);break;case"variadic":e.write("..."),this.internalType.value.write(e);break;default:x(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,r){return new this({type:"map",keyType:e,valueType:r})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return n.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"||bn.has(e.internalType.type)}static isAlreadyVariadic(e){return e.internalType.type==="variadic"}},Oe=new F({importPath:"time",name:"Time"}),Ve=new F({importPath:"github.com/google/uuid",name:"UUID"}),it=new F({importPath:"io",name:"Reader"});l();f();var se=class extends w{constructor({name:e,type:r,docs:i}){super();u(this,"name");u(this,"type");u(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new A({docs:this.docs})),e.write("type "),e.write(this.name),e.write(" "),e.writeNode(this.type)}};function Pn(n){return new X(n)}function kn(n){return new _(n)}function Sn(n){return new Q(n)}function Cn(n){return new Z(n)}function Un(n={}){return new ee(n)}function Bn(n){return new te(n)}function Ln(n){return new O(n)}function _n(n){return new S(n)}function Mn(n){return new V(n)}function Dn(n){return new W(n)}function $n(n){return new re(n)}function On(n){return new ne(n)}function Vn(n){return new ie(n)}function Wn(n={}){return new oe(n)}function qn(n){return new Ne(n)}function Gn(n){return new se(n)}function Yn(n){return new F(n)}l();f();Yt();var jn="sdk";function ot({config:n,customConfig:t}){let e=zn({config:n}),r=Hn({config:n,customConfig:t});return e!=null?Jn({importPath:r,majorVersion:e}):r}function Hn({config:n,customConfig:t,isModulePath:e=!1}){var i,o,s,p;let r=(s=(o=t==null?void 0:t.importPath)!=null?o:(i=t==null?void 0:t.module)==null?void 0:i.path)!=null?s:n.output.mode.type==="github"?Xn(n.output.mode.repoUrl,"https://"):jn;return e?r:Gt.join(r,(p=t==null?void 0:t.packagePath)!=null?p:"")}function zn({config:n}){let t=Kn({config:n});if(!(t==null||t==="v0"||t==="v1"))return`${t}`}function Kn({config:n}){let t=Qn(n);if(t==null)return;let e=t.split(".");if(e[0]==null)return;let r=e[0];return r.startsWith("v")?r:`v${r}`}function Jn({importPath:n,majorVersion:t}){return Te(n)===t?n:`${n}/${t}`}function Xn(n,t){return n.startsWith(t)?n.slice(t.length):n}function Qn(n){var e;let t=(e=n==null?void 0:n.output)==null?void 0:e.mode;if(t!=null)return t.type==="github"||t.type==="publish"?t.version:void 0}l();f();var We=class{constructor({context:t}){u(this,"context");this.context=t}convert(t){if(t.value===null&&!this.context.isNullable(t.typeReference)&&this.context.errors.add({severity:v.Critical,message:"Expected non-null value, but got null"}),t.value==null)return a.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return a.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?a.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"nullable":{let e=t.typeReference.value;if(e.type==="named"){let r=this.context.resolveNamedType({typeId:e.value});if((r==null?void 0:r.type)==="alias"&&["list","set","map"].includes(r.typeReference.type)){let i=this.convert({typeReference:r.typeReference,value:t.value,as:t.as}),o=this.context.getTypeName(r.declaration.name),s=this.context.getImportPath(r.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:i,aliasName:o,aliasImportPath:s})}}return a.TypeInstantiation.optional(this.convert({typeReference:e,value:t.value,as:t.as}))}case"optional":{let e=t.typeReference.value;if(e.type==="named"){let r=this.context.resolveNamedType({typeId:e.value});if((r==null?void 0:r.type)==="alias"&&["list","set","map"].includes(r.typeReference.type)){let i=this.convert({typeReference:r.typeReference,value:t.value,as:t.as}),o=this.context.getTypeName(r.declaration.name),s=this.context.getImportPath(r.declaration.fernFilepath);return this.reconstructAliasCollectionLiteral({collectionLiteral:i,aliasName:o,aliasImportPath:s})}}return a.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:x(t.typeReference)}}convertToPointerIfPossible(t){let e=this.convert(t);switch(t.typeReference.type){case"named":{let r=this.context.resolveNamedType({typeId:t.typeReference.value});return(r==null?void 0:r.type)==="enum"?a.TypeInstantiation.reference(a.invokeMethod({on:e,method:"Ptr",arguments_:[]})):e}default:return e}}convertList({list:t,value:e}){return Array.isArray(e)?a.TypeInstantiation.slice({valueType:this.context.dynamicTypeMapper.convert({typeReference:t}),values:e.map((r,i)=>{this.context.errors.scope({index:i});try{return this.convert({typeReference:t,value:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:v.Critical,message:`Expected array but got: ${typeof e}`}),a.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:v.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),a.TypeInstantiation.nop()):a.TypeInstantiation.map({keyType:this.context.dynamicTypeMapper.convert({typeReference:t.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:t.value}),entries:Object.entries(e).map(([r,i])=>{this.context.errors.scope(r);try{return{key:this.convert({typeReference:t.key,value:r,as:"key"}),value:this.convert({typeReference:t.value,value:i})}}finally{this.context.errors.unscope()}})})}convertNamed({named:t,value:e,as:r}){switch(t.type){case"alias":return this.convertAlias({aliasType:t,value:e,as:r});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:x(t)}}convertAlias({aliasType:t,value:e,as:r}){switch(t.typeReference.type){case"literal":return a.TypeInstantiation.reference(a.invokeFunc({func:a.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:r})}}reconstructAliasCollectionLiteral({collectionLiteral:t,aliasName:e,aliasImportPath:r}){let i=t.internalType;return i.type==="slice"?a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(a.typeReference({name:e,importPath:r}));let s=i.values;if(s.length===0){o.write("{}");return}o.writeLine("{"),o.indent();for(let p of s)o.writeNode(p),o.writeLine(",");o.dedent(),o.write("}")})):i.type==="map"?a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(a.typeReference({name:e,importPath:r}));let s=i.entries;if(s.length===0){o.write("{}");return}o.writeLine("{"),o.indent();for(let p of s)o.writeNode(p.key),o.write(": "),o.writeNode(p.value),o.writeLine(",");o.dedent(),o.write("}")})):a.TypeInstantiation.reference(a.codeblock(o=>{o.write("&"),o.writeNode(t)}))}convertLiteralValue(t){switch(t.type){case"boolean":return a.TypeInstantiation.bool(t.value);case"string":return a.TypeInstantiation.string(t.value);default:x(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let r=this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),i=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(i==null)return a.TypeInstantiation.nop();let o=i.singleDiscriminatedUnionType,s=this.getBaseFields({discriminatedUnionTypeInstance:i,singleDiscriminatedUnionType:o});switch(o.type){case"samePropertiesAsObject":{let p=this.context.resolveNamedType({typeId:o.typeId});return p==null?a.TypeInstantiation.nop():a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(o.discriminantValue.name),value:this.convertNamed({named:p,value:i.value})},...s]})}case"singleProperty":{let p=this.context.getRecord(i.value);if(p==null)return a.TypeInstantiation.nop();try{return this.context.errors.scope(o.discriminantValue.wireValue),a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(o.discriminantValue.name),value:this.convert({typeReference:o.typeReference,value:p[o.discriminantValue.wireValue]})},...s]})}finally{this.context.errors.unscope()}}case"noProperties":return a.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(i.discriminantValue.name),value:a.TypeInstantiation.string(o.discriminantValue.wireValue)},...s]});default:x(o)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){var i,o;return this.context.associateByWireValue({parameters:(i=e.properties)!=null?i:[],values:(o=this.context.getRecord(t.value))!=null?o:{},ignoreMissingParameters:!0}).map(s=>{this.context.errors.scope(s.name.wireValue);try{return{name:this.context.getTypeName(s.name.name),value:this.convert(s)}}finally{this.context.errors.unscope()}})}convertObject({object_:t,value:e}){var i;let r=this.context.associateByWireValue({parameters:t.properties,values:(i=this.context.getRecord(e))!=null?i:{}});return a.TypeInstantiation.structPointer({typeReference:a.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),fields:r.map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getTypeName(o.name.name),value:this.convert(o)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:t,value:e}){let r=this.getEnumValueName({enum_:t,value:e});return r==null?a.TypeInstantiation.nop():a.TypeInstantiation.enum(a.typeReference({name:r,importPath:this.context.getImportPath(t.declaration.fernFilepath)}))}getEnumValueName({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:v.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let r=t.values.find(i=>i.wireValue===e);if(r==null){this.context.errors.add({severity:v.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return`${this.context.getTypeName(t.declaration.name)}${this.context.getTypeName(r.name)}`}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let r=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});if(r==null)return a.TypeInstantiation.nop();let i=this.getUndiscriminatedUnionFieldName({typeReference:r.valueTypeReference});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.structPointer({typeReference:this.context.getGoTypeReferenceFromDeclaration({declaration:t.declaration}),fields:[{name:i,value:r.typeInstantiation}]})}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let r of t.types)try{let i=this.convert({typeReference:r,value:e});return{valueTypeReference:r,typeInstantiation:i}}catch(i){continue}this.context.errors.add({severity:v.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:x(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 r=this.getUndiscriminatedUnionFieldName({typeReference:t.value});if(r!=null)return`${e}${r}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:x(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:x(t)}}convertUnknown({value:t}){return a.TypeInstantiation.any(t)}convertPrimitive({primitive:t,value:e,as:r}){switch(t){case"INTEGER":case"UINT":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.int(i)}case"LONG":case"UINT_64":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.int64(i)}case"FLOAT":case"DOUBLE":{let i=this.getValueAsNumber({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.float64(i)}case"BOOLEAN":{let i=this.getValueAsBoolean({value:e,as:r});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.bool(i)}case"STRING":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.string(i)}case"DATE":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.date(i)}case"DATE_TIME":{let i=this.context.getValueAsString({value:e});if(i==null)return a.TypeInstantiation.nop();let o=this.normalizeDateTimeString(i);return a.TypeInstantiation.dateTime(o)}case"UUID":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.uuid(i)}case"BASE_64":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.bytes(i)}case"BIG_INTEGER":{let i=this.context.getValueAsString({value:e});return i==null?a.TypeInstantiation.nop():a.TypeInstantiation.string(i)}default:x(t)}}getValueAsNumber({value:t,as:e}){let r=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:t,as:e}){let r=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:r})}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}};l();f();var qe=class{constructor({context:t}){u(this,"context");this.context=t}convert(t){switch(t.typeReference.type){case"list":return a.Type.slice(this.convert({typeReference:t.typeReference.value}));case"literal":return this.convertLiteral({literal:t.typeReference.value});case"map":return a.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 a.Type.optional(this.convert({typeReference:t.typeReference.value}));case"nullable":return a.Type.optional(this.convert({typeReference:t.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:t.typeReference.value});case"set":return a.Type.slice(this.convert({typeReference:t.typeReference}));case"unknown":return this.convertUnknown();default:x(t.typeReference)}}convertLiteral({literal:t}){switch(t.type){case"boolean":return a.Type.bool();case"string":return a.Type.string()}}convertNamed({named:t}){let e=a.Type.reference(a.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 a.Type.pointer(e);default:x(t)}}convertUnknown(){return a.Type.any()}convertPrimitive({primitive:t}){switch(t){case"INTEGER":return a.Type.int();case"UINT":return a.Type.int();case"LONG":return a.Type.int64();case"UINT_64":return a.Type.int64();case"FLOAT":return a.Type.float64();case"DOUBLE":return a.Type.float64();case"BOOLEAN":return a.Type.bool();case"STRING":return a.Type.string();case"DATE":return a.Type.date();case"DATE_TIME":return a.Type.dateTime();case"UUID":return a.Type.uuid();case"BASE_64":return a.Type.bytes();case"BIG_INTEGER":return a.Type.string();default:x(t)}}};l();f();var Ge=class{constructor({context:t}){u(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){var o;let r={fileFields:[],bodyPropertyFields:[]},i=(o=this.context.getRecord(e))!=null?o:{};for(let s of t.properties)switch(s.type){case"file":r.fileFields.push({name:this.context.getTypeName(s.name),value:this.getSingleFileProperty({property:s,record:i})});break;case"fileArray":r.fileFields.push({name:this.context.getTypeName(s.name),value:this.getArrayFileProperty({property:s,record:i})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getTypeName(s.name.name),value:this.getBodyProperty({property:s,record:i})});break;default:x(s)}return r}getSingleFileProperty({property:t,record:e}){let r=this.context.getSingleFileValue({property:t,record:e})||"";return a.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(r))}getArrayFileProperty({property:t,record:e}){let r=this.context.getFileArrayValues({property:t,record:e});return r==null?a.TypeInstantiation.nop():a.TypeInstantiation.slice({valueType:a.Type.reference(this.context.getIoReaderTypeReference()),values:r.map(i=>a.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(i)))})}getBodyProperty({property:t,record:e}){let r=e[t.name.wireValue];return r==null?a.TypeInstantiation.nop():this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:r})}};var Ye=class n extends ve{constructor({ir:e,config:r}){super({ir:e,config:r});u(this,"ir");u(this,"customConfig");u(this,"dynamicTypeMapper");u(this,"dynamicTypeInstantiationMapper");u(this,"filePropertyMapper");u(this,"rootImportPath");this.ir=e,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeMapper=new qe({context:this}),this.dynamicTypeInstantiationMapper=new We({context:this}),this.filePropertyMapper=new Ge({context:this}),this.rootImportPath=ot({config:r,customConfig:this.customConfig})}clone(){return new n({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:x(e)}}getMethodName(e){return e.pascalCase.unsafeName}getTestMethodName(e){return e.declaration.fernFilepath.allParts.map(r=>r.pascalCase.unsafeName).join("")+e.declaration.name.pascalCase.unsafeName}getTypeName(e){return e.pascalCase.unsafeName}getImportPath(e){let r=e.packagePath.map(i=>i.pascalCase.unsafeName.toLowerCase());return[this.rootImportPath,...r].join("/")}getImportPathForRequest(e){var r;return(r=this.customConfig)!=null&&r.exportAllRequestsAtRoot?this.rootImportPath:this.getImportPath(e)}getContextTypeReference(){return a.typeReference({name:"Context",importPath:"context"})}getContextTodoFunctionInvocation(){return a.invokeFunc({func:a.typeReference({name:"TODO",importPath:"context"}),arguments_:[]})}getIoReaderTypeReference(){return a.typeReference({name:"Reader",importPath:"io"})}getTestingTypeReference(){return a.typeReference({name:"T",importPath:"testing"})}getNewStringsReaderFunctionInvocation(e){return a.invokeFunc({func:a.typeReference({name:"NewReader",importPath:"strings"}),arguments_:[a.TypeInstantiation.string(e)]})}getClientConstructorName(){var e,r;return((e=this.customConfig)==null?void 0:e.clientConstructorName)!=null?this.customConfig.clientConstructorName:((r=this.customConfig)==null?void 0:r.exportedClientName)!=null?`New${this.customConfig.exportedClientName}`:`New${this.getClientName()}`}getClientName(){var e;return((e=this.customConfig)==null?void 0:e.clientName)!=null?this.customConfig.clientName:"Client"}getClientImportPath(){return`${this.rootImportPath}/client`}getOptionImportPath(){return`${this.rootImportPath}/option`}getGoTypeReferenceFromDeclaration({declaration:e}){return a.typeReference({name:e.name.pascalCase.unsafeName,importPath:this.getImportPath(e.fernFilepath)})}getEnvironmentTypeReferenceFromID(e){let r=this.resolveEnvironmentName(e);if(r!=null)return this.getEnvironmentTypeReference(r)}getEnvironmentTypeReference(e){return a.typeReference({name:`Environments.${this.getTypeName(e)}`,importPath:this.rootImportPath})}static chainMethods(e,...r){if(r.length===0)throw new Error("Must have methods to chain");let i=e;for(let o of r)i=a.invokeMethod({on:i,method:o.method,arguments_:o.arguments_,multiline:o.multiline});return i}};l();f();var zt="example",st="fern",Zn="do",Ee="client",pe=a.TypeInstantiation,ei="WireMockBaseURL",ti="WireMockClient",je=class{constructor({context:t,formatter:e}){u(this,"context");u(this,"formatter");this.context=t,this.formatter=e}async generateSnippet({endpoint:t,request:e,options:r}){var s,p,h;return((p=(s=r==null?void 0:r.config)==null?void 0:s.outputWiremockTests)!=null?p:!1)?this.generateWiremockTest({endpoint:t,snippet:e}):await this.buildCodeBlock({endpoint:t,snippet:e}).toStringAsync({packageName:zt,importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(h=this.context.customConfig)!=null?h:{},formatter:this.formatter})}generateSnippetSync({endpoint:t,request:e,options:r}){var s,p,h;return((p=(s=r==null?void 0:r.config)==null?void 0:s.outputWiremockTests)!=null?p:!1)?this.generateWiremockTest({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e}).toString({packageName:zt,importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(h=this.context.customConfig)!=null?h:{},formatter:this.formatter})}async generateSnippetAst({endpoint:t,request:e,options:r}){throw new Error("Unsupported")}generateWiremockTest({endpoint:t,snippet:e}){var i;return this.buildWiremockTestCodeBlock({endpoint:t,snippet:e}).toString({packageName:"wiremock",importPath:st,rootImportPath:this.context.rootImportPath,customConfig:(i=this.context.customConfig)!=null?i:{},formatter:this.formatter})}buildCodeBlock({endpoint:t,snippet:e}){return a.codeblock(r=>{r.writeNode(a.func({name:Zn,parameters:[],return_:[],body:a.codeblock(i=>{i.writeNode(this.constructClient({endpoint:t,snippet:e})),i.writeLine(),i.writeNode(this.callMethod({endpoint:t,snippet:e}))})})),r.writeNewLineIfLastLineNot()})}buildWiremockTestCodeBlock({endpoint:t,snippet:e}){return a.codeblock(r=>{r.writeNode(a.func({name:"Test"+this.context.getTestMethodName(t)+"WithWireMock",parameters:[a.parameter({name:"t",type:a.Type.pointer(a.Type.reference(this.context.getTestingTypeReference()))})],return_:[],body:a.codeblock(i=>{for(let o of this.buildWiremockTestSetup({endpoint:t}))i.writeNode(o),i.writeLine();i.writeLine(),i.writeNode(this.constructWiremockTestClient({endpoint:t,snippet:e})),i.writeLine(),i.writeNode(this.callClientMethodAndAssert({endpoint:t,snippet:e}))})})),r.writeNewLineIfLastLineNot()})}constructClient({endpoint:t,snippet:e}){return a.codeblock(r=>{r.write(`${Ee} := `),r.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:t,snippet:e})))})}constructWiremockTestClient({endpoint:t,snippet:e}){return a.codeblock(r=>{r.write(`${Ee} := `),r.writeNode(this.getRootClientFuncInvocation(this.getWiremockTestConstructorArgs()))})}writeMethodInvocation({writer:t,endpoint:e,snippet:r}){let{otherArgs:i,requestArg:o}=this.getMethodArgs({endpoint:e,snippet:r});if(o!=null)if(o instanceof a.TypeInstantiation&&a.TypeInstantiation.isNop(o))t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i,a.codeblock("nil")]}));else{t.write("request := "),t.writeNode(o),t.writeLine();let s=a.codeblock("request");t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i,s]}))}else t.writeNode(a.invokeMethod({on:a.codeblock(Ee),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...i]}))}callMethod({endpoint:t,snippet:e}){return a.codeblock(r=>{this.writeMethodInvocation({writer:r,endpoint:t,snippet:e})})}getConstructorArgs({endpoint:t,snippet:e}){let r=[],i=this.getConstructorBaseUrlArg({baseUrl:e.baseURL,environment:e.environment});return i!=null&&r.push(i),t.auth!=null&&(e.auth!=null?r.push(this.getConstructorAuthArg({auth:t.auth,values:e.auth})):this.context.errors.add({severity:v.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(L.Headers),this.context.ir.headers!=null&&e.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),r}getWiremockTestConstructorArgs(){return[a.codeblock(t=>{t.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[a.codeblock(ei)]}))})]}getConstructorAuthArg({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),pe.nop();switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArg({auth:t,values:e}):pe.nop();case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArg({auth:t,values:e}):pe.nop();case"header":return e.type==="header"?this.getConstructorHeaderAuthArg({auth:t,values:e}):pe.nop();case"oauth":return this.addWarning("The Go SDK doesn't support OAuth client credentials yet"),pe.nop();case"inferred":return this.addWarning("The Go SDK Generator does not support Inferred auth scheme yet"),pe.nop();default:x(t)}}addError(t){this.context.errors.add({severity:v.Critical,message:t})}addWarning(t){this.context.errors.add({severity:v.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.username),a.TypeInstantiation.string(e.password)]}))})}getConstructorBaseUrlArg({baseUrl:t,environment:e}){let r=this.getBaseUrlArg({baseUrl:t,environment:e});if(r!=null)return a.codeblock(i=>{i.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:v.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return a.TypeInstantiation.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let r=this.context.getEnvironmentTypeReferenceFromID(e);if(r==null){this.context.errors.add({severity:v.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return a.TypeInstantiation.reference(r)}this.context.isMultiEnvironmentValues(e)&&this.context.errors.add({severity:v.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 a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.token)]}))})}getConstructorHeaderAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.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})]}))})}getConstructorHeaderArgs({headers:t,values:e}){let r=[];for(let i of t){let o=this.getConstructorHeaderArg({header:i,value:e.value});o!=null&&r.push(o)}return r}getConstructorHeaderArg({header:t,value:e}){let r=this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:e});if(!a.TypeInstantiation.isNop(r))return a.codeblock(i=>{i.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}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:x(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){var s,p;let r=[];this.context.errors.scope(L.PathParameters);let i=[...(s=this.context.ir.pathParameters)!=null?s:[],...(p=t.pathParameters)!=null?p:[]];i.length>0&&r.push(...this.getPathParameters({namedParameters:i,snippet:e}).map(h=>h.value)),this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let o=t.body!=null?this.getBodyRequestArg({body:t.body,value:e.requestBody}):void 0;return this.context.errors.unscope(),{otherArgs:r,requestArg:o}}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:x(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:v.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),a.TypeInstantiation.nop()):a.TypeInstantiation.bytes(t)}getMethodArgsForInlinedRequest({request:t,snippet:e}){var y,g,T,I,R,Y;let r=[],{inlinePathParameters:i,inlineFileProperties:o}={inlinePathParameters:(g=(y=this.context.customConfig)==null?void 0:y.inlinePathParameters)!=null?g:!0,inlineFileProperties:(I=(T=this.context.customConfig)==null?void 0:T.inlineFileProperties)!=null?I:!0};this.context.errors.scope(L.PathParameters);let s=[],p=[...(R=this.context.ir.pathParameters)!=null?R:[],...(Y=t.pathParameters)!=null?Y:[]];p.length>0&&s.push(...this.getPathParameters({namedParameters:p,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let h=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})||r.push(...s.map(le=>le.value)),o||r.push(...h.fileFields.map(le=>le.value));let m=this.context.needsRequestParameter({request:t,inlinePathParameters:i,inlineFileProperties:o})?this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})?s:[],filePropertyInfo:h}):void 0;return{otherArgs:r,requestArg:m}}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:r,filePropertyInfo:i}){var y,g,T,I;this.context.errors.scope(L.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:(y=t.queryParameters)!=null?y:[],values:(g=e.queryParameters)!=null?g:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(L.Headers);let h=this.context.associateByWireValue({parameters:(T=t.headers)!=null?T:[],values:(I=e.headers)!=null?I:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(L.RequestBody);let m=t.body!=null?this.getInlinedRequestBodyStructFields({body:t.body,value:e.requestBody,filePropertyInfo:i}):[];return this.context.errors.unscope(),a.TypeInstantiation.structPointer({typeReference:a.typeReference({name:this.context.getMethodName(t.declaration.name),importPath:this.context.getImportPathForRequest(t.declaration.fernFilepath)}),fields:[...r,...s,...h,...m]})}getInlinedRequestBodyStructFields({body:t,value:e,filePropertyInfo:r}){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:r});default:x(t)}}getFileUploadRequestBodyStructFields({filePropertyInfo:t}){var e;return(e=this.context.customConfig)!=null&&e.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:x(t)}}getInlinedRequestBodyPropertyStructFields({parameters:t,value:e}){var o;let r=[],i=this.context.associateByWireValue({parameters:t,values:(o=this.context.getRecord(e))!=null?o:{}});for(let s of i)r.push({name:this.context.getTypeName(s.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(s)});return r}getPathParameters({namedParameters:t,snippet:e}){var o;let r=[],i=this.context.associateByWireValue({parameters:t,values:(o=e.pathParameters)!=null?o:{}});for(let s of i)r.push({name:this.context.getTypeName(s.name.name),value:this.context.dynamicTypeInstantiationMapper.convertToPointerIfPossible(s)});return r}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 a.invokeFunc({func:a.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:t})}buildWiremockTestSetup({endpoint:t,errorCase:e}){let r="stub";return[]}callClientMethodAndAssert({endpoint:t,snippet:e}){return a.codeblock(r=>{this.writeMethodInvocation({writer:r,endpoint:t,snippet:e}),r.writeLine(),r.writeLine(),r.write("ok, countErr := "),r.writeNode(a.invokeMethod({on:a.codeblock(ti),method:"Verify",arguments_:[a.invokeMethod({on:a.codeblock("stub"),method:"Request",arguments_:[],multiline:!1}),a.codeblock("1")],multiline:!1})),r.writeLine(),r.writeNode(a.invokeFunc({func:a.typeReference({name:"NoError",importPath:"github.com/stretchr/testify/require"}),arguments_:[a.codeblock("t"),a.codeblock("countErr"),a.TypeInstantiation.string("Failed to verify WireMock request was matched")],multiline:!1})),r.writeLine(),r.writeNode(a.invokeFunc({func:a.typeReference({name:"True",importPath:"github.com/stretchr/testify/require"}),arguments_:[a.codeblock("t"),a.codeblock("ok"),a.TypeInstantiation.string("WireMock request was not matched")],multiline:!1})),r.writeLine()})}};var at=class extends ge{constructor({ir:e,config:r,formatter:i}){super(new Ye({ir:e,config:r}));u(this,"formatter");this.formatter=i}async generate(e,r){return super.generate(e,r)}generateSync(e,r){return super.generateSync(e,r)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new je({context:e,formatter:this.formatter})}};0&&(module.exports={DynamicSnippetsGenerator});
27
27
  /*! Bundled license information:
28
28
 
29
29
  @esbuild-plugins/node-globals-polyfill/Buffer.js: