@fern-api/csharp-dynamic-snippets 2.19.6 → 2.19.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -22,7 +22,7 @@ ${y}`);this.isAtStartOfLine()&&(c=y+c),n&&(c+=`
22
22
  `)}writeSemicolonIfLastCharacterIsNot(){this.lastCharacterIsSemicolon||this.writeInternal(";")}writeNewLineIfLastLineNot(){this.lastCharacterIsNewline||this.writeInternal(`
23
23
  `)}indent(){this.indentLevel++}dedent(){this.indentLevel--}delimit({nodes:t,delimiter:r,writeFunction:n}){if(t.length>0){let i=t[0];i!=null&&n(i);for(let y=1;y<t.length;y++){this.write(r);let c=t[y];c!=null&&n(c)}}}toString(){return this.buffer}writeInternal(t){if(t.length===0)return;let r=!this.lastCharacterIsNewline;this.hasWrittenAnything=!0,this.lastCharacterIsNewline=t.endsWith(`
24
24
  `),this.lastCharacterIsSemicolon=t.endsWith(";");let n=t.split(`
25
- `),i=Et&&!this.shouldSkipTracking(n)&&this.lastCharacterIsNewline;r&&(this.lastLine=`${this.lastLine}${n.shift()||""}`),this.lastCharacterIsNewline&&n.pop(),this.lineBuffer.push(...n),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,r=""){return t.map(n=>`${r?`(${r}) `:""} ${n.fn} - ${n.path} : ${n.position}`)}filterStack(t){return t.filter(r=>!r.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(Ls({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,to){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(r=>` // ${r}`))}boxTrackingComment(t){this.lineBuffer.push("/*",...t.map(r=>` ${r}`),"*/")}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*this.getTabSize())}getTabSize(){return ZT}};s();o();a();function Oa(e){return e?.name!=null&&e?.assignment!=null}function io(e){return e.length>0&&e[0]!=null&&Oa(e[0])}s();o();a();var Gs=class extends An{constructor({condition:r,true_:n,false_:i}){super();g(this,"condition");g(this,"true_");g(this,"false_");this.condition=r,this.true_=n,this.false_=i}write(r){r.writeNode(this.condition),r.write(" ? "),r.writeNode(this.true_),r.write(" : "),r.writeNode(this.false_)}};s();o();a();s();o();a();s();o();a();var Hs=class{constructor(){g(this,"reporter");g(this,"snippet");g(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:t,snippet:r}){this.shouldUpdate({snippet:r,reporter:t.errors})&&(this.reporter=t.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:t}){if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw this.err??new Error(`Failed to generate snippet for endpoint "${t.method} ${t.path}"`)}shouldUpdate({snippet:t,reporter:r}){return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:t.length>(this.snippet?.length??0)}};var zs=class{constructor(t){g(this,"context");this.context=t}async generate(t,r={}){let n=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new Hs;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{let O=await b.generateSnippet({endpoint:y,request:t,options:r});if(c.errors.empty())return{snippet:O,errors:void 0};i.update({context:c,snippet:O})}catch(O){i.err==null&&(i.err=O)}}return i.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,r={}){let n=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{return await b.generateSnippetAst({endpoint:y,request:t,options:r})}catch(O){i=O}}throw i??new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,r={}){let n=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new Hs;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{let O=b.generateSnippetSync({endpoint:y,request:t,options:r});if(c.errors.empty())return{snippet:O,errors:void 0};i.update({context:c,snippet:O})}catch(O){i.err==null&&(i.err=O)}}return i.getResponseOrThrow({endpoint:t.endpoint})}};s();o();a();s();o();a();s();o();a();var Ks=class{constructor(){g(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 n=t.match(this.REFERENCE_REGEX);if(!(n==null||n[1]==null||n[2]==null))return{method:n[1],path:n[2]}}};s();o();a();var Te={Critical:"CRITICAL",Warning:"WARNING"},Js=class e{constructor(){g(this,"errors");g(this,"path");this.errors=[],this.path=[]}add(t){this.errors.push({...t,path:[...this.path]})}scope(t){this.path.push(t)}unscope(){this.path.pop()}getBySeverity(t){return this.errors.filter(r=>r.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new e;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 r=[];for(let n of t){if(typeof n=="string"){r.push(n);continue}r[r.length-1]+=`[${n.index}]`}return r}};var Qs=class{constructor({ir:t,config:r,options:n={}}){g(this,"config");g(this,"options");g(this,"errors");g(this,"_ir");g(this,"httpEndpointReferenceParser");this._ir=t,this.config=r,this.options=n,this.errors=new Js,this.httpEndpointReferenceParser=new Ks}associateQueryParametersByWireValue({parameters:t,values:r}){let n=[];for(let[i,y]of Object.entries(r))if(y!==void 0){this.errors.scope(i);try{let c=t.find(O=>O.name.wireValue===i);if(c==null)throw this.newParameterNotRecognizedError(i);let b=this.isListTypeReference(c.typeReference)&&!Array.isArray(y)?[y]:y;n.push({name:c.name,typeReference:c.typeReference,value:b})}finally{this.errors.unscope()}}return n}associateByWireValueOrDefault({parameters:t,values:r}){let n=[];for(let i of t){this.errors.scope(i.name.wireValue);try{let y=r[i.name.wireValue];if(y==null)if(i.typeReference.type==="primitive"&&i.typeReference.value==="STRING")y=`<${i.name.wireValue}>`;else{this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(i.name.wireValue).message});continue}n.push({name:i.name,typeReference:i.typeReference,value:y})}finally{this.errors.unscope()}}return n}associateByWireValue({parameters:t,values:r,ignoreMissingParameters:n}){let i=[];for(let[y,c]of Object.entries(r))if(c!==void 0){this.errors.scope(y);try{let b=t.find(O=>O.name.wireValue===y);if(b==null){if(n)continue;this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(y).message});continue}i.push({name:b.name,typeReference:b.typeReference,value:c})}finally{this.errors.unscope()}}return i}getExampleObjectProperties({parameters:t,snippetObject:r}){let n=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{},i=[];for(let y of t){let c=n[y.name.wireValue];c==null?y.typeReference.type==="nullable"&&i.push({name:y.name,typeReference:y.typeReference,value:null}):i.push({name:y.name,typeReference:y.typeReference,value:c})}return i}getSingleFileValue({property:t,record:r}){let n=r[t.wireValue];if(n!=null){if(typeof n!="string"){this.errors.add({severity:Te.Critical,message:`Expected file value to be a string, got ${typeof n}`});return}return n}}getFileArrayValues({property:t,record:r}){let n=r[t.wireValue];if(n==null)return;if(!Array.isArray(n)){this.errors.add({severity:Te.Critical,message:`Expected file array value to be an array of strings, got ${typeof n}`});return}let i=[];for(let y of n){if(typeof y!="string"){this.errors.add({severity:Te.Critical,message:`Expected file array value to be an array of strings, got ${typeof y}`});return}i.push(y)}return i}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:Te.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t??{}}resolveNamedType({typeId:t}){let r=this._ir.types[t];if(r==null){this.errors.add({severity:Te.Critical,message:`Type identified by "${t}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:r}){let n=this.getRecord(r);if(n==null)return;let i=t.discriminant.wireValue,y=n[i];if(y==null){this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(i).message});return}if(typeof y!="string"){this.errors.add({severity:Te.Critical,message:`Expected discriminant value to be a string but got: ${typeof y}`});return}let c=t.types[y];if(c==null){this.errors.add({severity:Te.Critical,message:`No type found for discriminant value "${y}"`});return}let{[i]:b,...O}=n;return{singleDiscriminatedUnionType:c,discriminantValue:c.discriminantValue,value:O}}resolveEndpointOrThrow(t){let r=this.httpEndpointReferenceParser.tryParse(t);if(r==null)throw new Error(`Failed to parse endpoint reference "${t}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocation(t){let r=[];for(let n of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:n,parsedEndpoint:t})&&r.push(n);return r}resolveEndpointLocationOrThrow(t){let r=this.resolveEndpointLocation(t);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${t.method} ${t.path}"`);return r}resolveEndpointById(t){return this._ir.endpoints[t]}resolveEndpointByIdOrThrow(t){let r=this.resolveEndpointById(t);if(r==null)throw new Error(`Failed to find endpoint with ID "${t}"`);return r}needsRequestParameter({request:t,inlinePathParameters:r,inlineFileProperties:n}){return this.includePathParametersInWrappedRequest({request:t,inlinePathParameters:r})||t.queryParameters!=null&&t.queryParameters.length>0||t.headers!=null&&t.headers.length>0?!0:t.body!=null?this.includeRequestBodyInWrappedRequest({body:t.body,inlineFileProperties:n}):!t.metadata?.onlyPathParameters}includePathParametersInWrappedRequest({request:t,inlinePathParameters:r}){return r&&(t.metadata?.includePathParameters??!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:$e(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let n=r.environments.find(i=>i.id===t);return n?.name}case"multipleBaseUrls":{let n=r.environments.find(i=>i.id===t);return n?.name}default:$e(r)}}isSingleEnvironmentID(t){return typeof t=="string"}isMultiEnvironmentValues(t){return typeof t=="object"}validateMultiEnvironmentUrlValues(t){if(this._ir.environments==null)return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let n=r.environments[0];if(n==null)return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let i=new Set(Fs(n.urls));for(let y of Fs(t))i.has(y)&&i.delete(y);return i.size>0?(this.errors.add({severity:Te.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${Fs(n.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:Te.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:Te.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:Te.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 r=this.resolveNamedType({typeId:t.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(t){switch(t.type){case"nullable":return!0;case"optional":return this.isNullable(t.value);case"named":{let r=this.resolveNamedType({typeId:t.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:t,values:r}){return new Error(`Expected auth type ${t.type}, got ${r.type}`)}newParameterNotRecognizedError(t){return new Error(`"${t}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:t,value:r}){return new Error(`Expected ${t}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:t,inlineFileProperties:r}){switch(t.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:r});default:$e(t)}}includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:t})||r&&this.fileUploadHasFileProperties({fileUpload:t})}fileUploadHasBodyProperties({fileUpload:t}){return t.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:$e(r)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:$e(r)}})}isListTypeReference(t){return t.type==="optional"?this.isListTypeReference(t.value):t.type==="list"||t.type==="set"}parsedEndpointMatches({endpoint:t,parsedEndpoint:r}){return t.location.method===r.method&&t.location.path===r.path}};s();o();a();var ei;(function(e){e.Concise="concise",e.Full="full"})(ei||(ei={}));s();o();a();var Yt={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};s();o();a();s();o();a();var Rs={};da(Rs,{Access:()=>Ze,And:()=>ys,Annotation:()=>Rn,AnnotationGroup:()=>ms,AnonymousFunction:()=>gs,AstNode:()=>de,Block:()=>Hn,Class:()=>On,ClassInstantiation:()=>as,ClassReference:()=>gt,CodeBlock:()=>Gn,Dictionary:()=>os,Enum:()=>xs,EnumInstantiation:()=>us,Field:()=>Ss,InstantiatedPrimitive:()=>ft,Interface:()=>Ts,List:()=>cs,Literal:()=>me,MemberNode:()=>Cn,Method:()=>Xn,MethodInvocation:()=>fs,MethodType:()=>Jt,Node:()=>xt,OptionalWrapper:()=>ss,Or:()=>bs,Parameter:()=>Kt,ReadOnlyMemory:()=>ls,Set:()=>ps,String_:()=>ds,Switch:()=>_s,Ternary:()=>Os,TestClass:()=>Ms,Writer:()=>Ht,XmlDocBlock:()=>zn,XmlDocWriter:()=>hs,convertReadOnlyPrimitiveTypes:()=>qE});s();o();a();s();o();a();s();o();a();var xB=require("assert");s();o();a();s();o();a();s();o();a();var Ht=class extends Ws{constructor({namespace:r,allNamespaceSegments:n,allTypeClassReferences:i,generation:y,skipImports:c=!1}){super();g(this,"references",{});g(this,"namespace");g(this,"namespaceAliases",{});g(this,"allNamespaceSegments");g(this,"allTypeClassReferences");g(this,"generation");g(this,"skipImports");g(this,"inQuoteBlock",!1);this.namespace=r,this.allNamespaceSegments=n,this.allTypeClassReferences=i,this.generation=y,this.skipImports=c}addReference(r){if(r.namespace==null)return;let n=this.references[r.namespace];n!=null?n.push(r):this.references[r.namespace]=[r]}addNamespace(r){this.references[r]==null&&(this.references[r]=[])}addNamespaceAlias(r,n){let i=new Set(Object.values(this.namespaceAliases));for(;i.has(r);)r=`_${r}`;return this.namespaceAliases[r]=n,r}getReferencedNamespaces(){return Object.keys(this.references)}getAllTypeClassReferences(){return this.allTypeClassReferences}getAllNamespaceSegments(){return this.allNamespaceSegments}toString(r=!1){if(!r){let n=this.stringifyImports();if(n.length>0)return`${n}
25
+ `),i=Et&&!this.shouldSkipTracking(n)&&this.lastCharacterIsNewline;r&&(this.lastLine=`${this.lastLine}${n.shift()||""}`),this.lastCharacterIsNewline&&n.pop(),this.lineBuffer.push(...n),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,r=""){return t.map(n=>`${r?`(${r}) `:""} ${n.fn} - ${n.path} : ${n.position}`)}filterStack(t){return t.filter(r=>!r.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(Ls({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,to){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(r=>` // ${r}`))}boxTrackingComment(t){this.lineBuffer.push("/*",...t.map(r=>` ${r}`),"*/")}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*this.getTabSize())}getTabSize(){return ZT}};s();o();a();function Oa(e){return e?.name!=null&&e?.assignment!=null}function io(e){return e.length>0&&e[0]!=null&&Oa(e[0])}s();o();a();var Gs=class extends An{constructor({condition:r,true_:n,false_:i}){super();g(this,"condition");g(this,"true_");g(this,"false_");this.condition=r,this.true_=n,this.false_=i}write(r){r.writeNode(this.condition),r.write(" ? "),r.writeNode(this.true_),r.write(" : "),r.writeNode(this.false_)}};s();o();a();s();o();a();s();o();a();var Hs=class{constructor(){g(this,"reporter");g(this,"snippet");g(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:t,snippet:r}){this.shouldUpdate({snippet:r,reporter:t.errors})&&(this.reporter=t.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:t}){if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw this.err??new Error(`Failed to generate snippet for endpoint "${t.method} ${t.path}"`)}shouldUpdate({snippet:t,reporter:r}){return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:t.length>(this.snippet?.length??0)}};var zs=class{constructor(t){g(this,"context");this.context=t}async generate(t,r={}){let n=this.resolveEndpoints({request:t,options:r});if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new Hs;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{let O=await b.generateSnippet({endpoint:y,request:t,options:r});if(c.errors.empty())return{snippet:O,errors:void 0};i.update({context:c,snippet:O})}catch(O){i.err==null&&(i.err=O)}}return i.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,r={}){let n=this.resolveEndpoints({request:t,options:r});if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{return await b.generateSnippetAst({endpoint:y,request:t,options:r})}catch(O){i=O}}throw i??new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,r={}){let n=this.resolveEndpoints({request:t,options:r});if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let i=new Hs;for(let y of n){let c=this.context.clone(),b=this.createSnippetGenerator(c);try{let O=b.generateSnippetSync({endpoint:y,request:t,options:r});if(c.errors.empty())return{snippet:O,errors:void 0};i.update({context:c,snippet:O})}catch(O){i.err==null&&(i.err=O)}}return i.getResponseOrThrow({endpoint:t.endpoint})}resolveEndpoints({request:t,options:r}){if(r.endpointId!=null){let n=this.context.resolveEndpointById(r.endpointId);if(n==null)throw new Error(`No endpoint found with ID "${r.endpointId}"`);return[n]}return this.context.resolveEndpointLocationOrThrow(t.endpoint)}};s();o();a();s();o();a();s();o();a();var Ks=class{constructor(){g(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 n=t.match(this.REFERENCE_REGEX);if(!(n==null||n[1]==null||n[2]==null))return{method:n[1],path:n[2]}}};s();o();a();var Te={Critical:"CRITICAL",Warning:"WARNING"},Js=class e{constructor(){g(this,"errors");g(this,"path");this.errors=[],this.path=[]}add(t){this.errors.push({...t,path:[...this.path]})}scope(t){this.path.push(t)}unscope(){this.path.pop()}getBySeverity(t){return this.errors.filter(r=>r.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new e;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 r=[];for(let n of t){if(typeof n=="string"){r.push(n);continue}r[r.length-1]+=`[${n.index}]`}return r}};var Qs=class{constructor({ir:t,config:r,options:n={}}){g(this,"config");g(this,"options");g(this,"errors");g(this,"_ir");g(this,"httpEndpointReferenceParser");this._ir=t,this.config=r,this.options=n,this.errors=new Js,this.httpEndpointReferenceParser=new Ks}associateQueryParametersByWireValue({parameters:t,values:r}){let n=[];for(let[i,y]of Object.entries(r))if(y!==void 0){this.errors.scope(i);try{let c=t.find(O=>O.name.wireValue===i);if(c==null)throw this.newParameterNotRecognizedError(i);let b=this.isListTypeReference(c.typeReference)&&!Array.isArray(y)?[y]:y;n.push({name:c.name,typeReference:c.typeReference,value:b})}finally{this.errors.unscope()}}return n}associateByWireValueOrDefault({parameters:t,values:r}){let n=[];for(let i of t){this.errors.scope(i.name.wireValue);try{let y=r[i.name.wireValue];if(y==null)if(i.typeReference.type==="primitive"&&i.typeReference.value==="STRING")y=`<${i.name.wireValue}>`;else{this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(i.name.wireValue).message});continue}n.push({name:i.name,typeReference:i.typeReference,value:y})}finally{this.errors.unscope()}}return n}associateByWireValue({parameters:t,values:r,ignoreMissingParameters:n}){let i=[];for(let[y,c]of Object.entries(r))if(c!==void 0){this.errors.scope(y);try{let b=t.find(O=>O.name.wireValue===y);if(b==null){if(n)continue;this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(y).message});continue}i.push({name:b.name,typeReference:b.typeReference,value:c})}finally{this.errors.unscope()}}return i}getExampleObjectProperties({parameters:t,snippetObject:r}){let n=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{},i=[];for(let y of t){let c=n[y.name.wireValue];c==null?y.typeReference.type==="nullable"&&i.push({name:y.name,typeReference:y.typeReference,value:null}):i.push({name:y.name,typeReference:y.typeReference,value:c})}return i}getSingleFileValue({property:t,record:r}){let n=r[t.wireValue];if(n!=null){if(typeof n!="string"){this.errors.add({severity:Te.Critical,message:`Expected file value to be a string, got ${typeof n}`});return}return n}}getFileArrayValues({property:t,record:r}){let n=r[t.wireValue];if(n==null)return;if(!Array.isArray(n)){this.errors.add({severity:Te.Critical,message:`Expected file array value to be an array of strings, got ${typeof n}`});return}let i=[];for(let y of n){if(typeof y!="string"){this.errors.add({severity:Te.Critical,message:`Expected file array value to be an array of strings, got ${typeof y}`});return}i.push(y)}return i}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:Te.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t??{}}resolveNamedType({typeId:t}){let r=this._ir.types[t];if(r==null){this.errors.add({severity:Te.Critical,message:`Type identified by "${t}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:r}){let n=this.getRecord(r);if(n==null)return;let i=t.discriminant.wireValue,y=n[i];if(y==null){this.errors.add({severity:Te.Critical,message:this.newParameterNotRecognizedError(i).message});return}if(typeof y!="string"){this.errors.add({severity:Te.Critical,message:`Expected discriminant value to be a string but got: ${typeof y}`});return}let c=t.types[y];if(c==null){this.errors.add({severity:Te.Critical,message:`No type found for discriminant value "${y}"`});return}let{[i]:b,...O}=n;return{singleDiscriminatedUnionType:c,discriminantValue:c.discriminantValue,value:O}}resolveEndpointOrThrow(t){let r=this.httpEndpointReferenceParser.tryParse(t);if(r==null)throw new Error(`Failed to parse endpoint reference "${t}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocation(t){let r=[];for(let n of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:n,parsedEndpoint:t})&&r.push(n);return r}resolveEndpointLocationOrThrow(t){let r=this.resolveEndpointLocation(t);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${t.method} ${t.path}"`);return r}resolveEndpointById(t){return this._ir.endpoints[t]}resolveEndpointByIdOrThrow(t){let r=this.resolveEndpointById(t);if(r==null)throw new Error(`Failed to find endpoint with ID "${t}"`);return r}needsRequestParameter({request:t,inlinePathParameters:r,inlineFileProperties:n}){return this.includePathParametersInWrappedRequest({request:t,inlinePathParameters:r})||t.queryParameters!=null&&t.queryParameters.length>0||t.headers!=null&&t.headers.length>0?!0:t.body!=null?this.includeRequestBodyInWrappedRequest({body:t.body,inlineFileProperties:n}):!t.metadata?.onlyPathParameters}includePathParametersInWrappedRequest({request:t,inlinePathParameters:r}){return r&&(t.metadata?.includePathParameters??!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:$e(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let n=r.environments.find(i=>i.id===t);return n?.name}case"multipleBaseUrls":{let n=r.environments.find(i=>i.id===t);return n?.name}default:$e(r)}}isSingleEnvironmentID(t){return typeof t=="string"}isMultiEnvironmentValues(t){return typeof t=="object"}validateMultiEnvironmentUrlValues(t){if(this._ir.environments==null)return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let n=r.environments[0];if(n==null)return this.errors.add({severity:Te.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let i=new Set(Fs(n.urls));for(let y of Fs(t))i.has(y)&&i.delete(y);return i.size>0?(this.errors.add({severity:Te.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${Fs(n.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:Te.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:Te.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:Te.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 r=this.resolveNamedType({typeId:t.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(t){switch(t.type){case"nullable":return!0;case"optional":return this.isNullable(t.value);case"named":{let r=this.resolveNamedType({typeId:t.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:t,values:r}){return new Error(`Expected auth type ${t.type}, got ${r.type}`)}newParameterNotRecognizedError(t){return new Error(`"${t}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:t,value:r}){return new Error(`Expected ${t}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:t,inlineFileProperties:r}){switch(t.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:r});default:$e(t)}}includeFileUploadBodyInWrappedRequest({fileUpload:t,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:t})||r&&this.fileUploadHasFileProperties({fileUpload:t})}fileUploadHasBodyProperties({fileUpload:t}){return t.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:$e(r)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:$e(r)}})}isListTypeReference(t){return t.type==="optional"?this.isListTypeReference(t.value):t.type==="list"||t.type==="set"}parsedEndpointMatches({endpoint:t,parsedEndpoint:r}){return t.location.method===r.method&&t.location.path===r.path}};s();o();a();var ei;(function(e){e.Concise="concise",e.Full="full"})(ei||(ei={}));s();o();a();var Yt={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};s();o();a();s();o();a();var Rs={};da(Rs,{Access:()=>Ze,And:()=>ys,Annotation:()=>Rn,AnnotationGroup:()=>ms,AnonymousFunction:()=>gs,AstNode:()=>de,Block:()=>Hn,Class:()=>On,ClassInstantiation:()=>as,ClassReference:()=>gt,CodeBlock:()=>Gn,Dictionary:()=>os,Enum:()=>xs,EnumInstantiation:()=>us,Field:()=>Ss,InstantiatedPrimitive:()=>ft,Interface:()=>Ts,List:()=>cs,Literal:()=>me,MemberNode:()=>Cn,Method:()=>Xn,MethodInvocation:()=>fs,MethodType:()=>Jt,Node:()=>xt,OptionalWrapper:()=>ss,Or:()=>bs,Parameter:()=>Kt,ReadOnlyMemory:()=>ls,Set:()=>ps,String_:()=>ds,Switch:()=>_s,Ternary:()=>Os,TestClass:()=>Ms,Writer:()=>Ht,XmlDocBlock:()=>zn,XmlDocWriter:()=>hs,convertReadOnlyPrimitiveTypes:()=>qE});s();o();a();s();o();a();s();o();a();var xB=require("assert");s();o();a();s();o();a();s();o();a();var Ht=class extends Ws{constructor({namespace:r,allNamespaceSegments:n,allTypeClassReferences:i,generation:y,skipImports:c=!1}){super();g(this,"references",{});g(this,"namespace");g(this,"namespaceAliases",{});g(this,"allNamespaceSegments");g(this,"allTypeClassReferences");g(this,"generation");g(this,"skipImports");g(this,"inQuoteBlock",!1);this.namespace=r,this.allNamespaceSegments=n,this.allTypeClassReferences=i,this.generation=y,this.skipImports=c}addReference(r){if(r.namespace==null)return;let n=this.references[r.namespace];n!=null?n.push(r):this.references[r.namespace]=[r]}addNamespace(r){this.references[r]==null&&(this.references[r]=[])}addNamespaceAlias(r,n){let i=new Set(Object.values(this.namespaceAliases));for(;i.has(r);)r=`_${r}`;return this.namespaceAliases[r]=n,r}getReferencedNamespaces(){return Object.keys(this.references)}getAllTypeClassReferences(){return this.allTypeClassReferences}getAllNamespaceSegments(){return this.allNamespaceSegments}toString(r=!1){if(!r){let n=this.stringifyImports();if(n.length>0)return`${n}
26
26
  ${this.buffer}`}return this.buffer}importsToString(){let r=this.stringifyImports();return r.length>0?r:void 0}isReadOnlyMemoryType(r){return this.generation.settings.readOnlyMemoryTypes.includes(r)}shouldSkipTracking(r){return r.forEach(n=>this.inQuoteBlock=n.includes('"""')?!this.inQuoteBlock:this.inQuoteBlock),this.inQuoteBlock}stringifyImports(){let r=Object.entries(this.references).filter(([n])=>n&&!this.isCurrentNamespace(n)&&!this.generation.registry.isNamespaceImplicit(n)).map(([,n])=>`using ${n.some(i=>i?.global)?"global::":""}${n[0].resolveNamespace()};`).join(`
27
27
  `);r.length>0&&(r=`${r}
28
28
  `);for(let[n,i]of Object.entries(this.namespaceAliases))r=`${r}using ${n} = ${i};