@fern-api/ruby-dynamic-snippets 1.0.0-rc76 → 1.0.0-rc77
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@ ${f}`);this.isAtStartOfLine()&&(u=f+u),i&&(u+=`
|
|
|
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:i}){if(t.length>0){let s=t[0];s!=null&&i(s);for(let f=1;f<t.length;f++){this.write(e);let u=t[f];u!=null&&i(u)}}}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 i=t.split(`
|
|
15
|
-
`),s=Z&&!this.shouldSkipTracking(i)&&this.lastCharacterIsNewline;e&&(this.lastLine=`${this.lastLine}${i.shift()||""}`),this.lastCharacterIsNewline&&i.pop(),this.lineBuffer.push(...i),s&&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(i=>`${e?`(${e}) `:""} ${i.fn} - ${i.path} : ${i.position}`)}filterStack(t){return t.filter(e=>!e.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(Qe({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,wt){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 oo}};c();m();d();c();m();d();c();m();d();var Fe=class{constructor(){y(this,"reporter");y(this,"snippet");y(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}){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:e}){return this.reporter==null||this.reporter.size()>0&&e.size()===0?!0:t.length>(this.snippet?.length??0)}};var Pe=class{constructor(t){y(this,"context");this.context=t}async generate(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s=new Fe;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{let w=await T.generateSnippet({endpoint:f,request:t,options:e});if(u.errors.empty())return{snippet:w,errors:void 0};s.update({context:u,snippet:w})}catch(w){s.err==null&&(s.err=w)}}return s.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{return await T.generateSnippetAst({endpoint:f,request:t,options:e})}catch(w){s=w}}throw s??new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s=new Fe;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{let w=T.generateSnippetSync({endpoint:f,request:t,options:e});if(u.errors.empty())return{snippet:w,errors:void 0};s.update({context:u,snippet:w})}catch(w){s.err==null&&(s.err=w)}}return s.getResponseOrThrow({endpoint:t.endpoint})}};c();m();d();c();m();d();c();m();d();var Ue=class{constructor(){y(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 i=t.match(this.REFERENCE_REGEX);if(!(i==null||i[1]==null||i[2]==null))return{method:i[1],path:i[2]}}};c();m();d();var N={Critical:"CRITICAL",Warning:"WARNING"},Me=class l{constructor(){y(this,"errors");y(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(e=>e.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new l;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 i of t){if(typeof i=="string"){e.push(i);continue}e[e.length-1]+=`[${i.index}]`}return e}};var $e=class{constructor({ir:t,config:e,options:i={}}){y(this,"config");y(this,"options");y(this,"errors");y(this,"_ir");y(this,"httpEndpointReferenceParser");this._ir=t,this.config=e,this.options=i,this.errors=new Me,this.httpEndpointReferenceParser=new Ue}associateQueryParametersByWireValue({parameters:t,values:e}){let i=[];for(let[s,f]of Object.entries(e)){this.errors.scope(s);try{let u=t.find(w=>w.name.wireValue===s);if(u==null)throw this.newParameterNotRecognizedError(s);let T=this.isListTypeReference(u.typeReference)&&!Array.isArray(f)?[f]:f;i.push({name:u.name,typeReference:u.typeReference,value:T})}finally{this.errors.unscope()}}return i}associateByWireValueOrDefault({parameters:t,values:e}){let i=[];for(let s of t){this.errors.scope(s.name.wireValue);try{let f=e[s.name.wireValue];if(f==null)if(s.typeReference.type==="primitive"&&s.typeReference.value==="STRING")f=`<${s.name.wireValue}>`;else{this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(s.name.wireValue).message});continue}i.push({name:s.name,typeReference:s.typeReference,value:f})}finally{this.errors.unscope()}}return i}associateByWireValue({parameters:t,values:e,ignoreMissingParameters:i}){let s=[];for(let[f,u]of Object.entries(e)){this.errors.scope(f);try{let T=t.find(w=>w.name.wireValue===f);if(T==null){if(i)continue;this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(f).message});continue}s.push({name:T.name,typeReference:T.typeReference,value:u})}finally{this.errors.unscope()}}return s}getExampleObjectProperties({parameters:t,snippetObject:e}){let i=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{},s=[];for(let f of t){let u=i[f.name.wireValue];u==null?f.typeReference.type==="nullable"&&s.push({name:f.name,typeReference:f.typeReference,value:null}):s.push({name:f.name,typeReference:f.typeReference,value:u})}return s}getSingleFileValue({property:t,record:e}){let i=e[t.wireValue];if(i!=null){if(typeof i!="string"){this.errors.add({severity:N.Critical,message:`Expected file value to be a string, got ${typeof i}`});return}return i}}getFileArrayValues({property:t,record:e}){let i=e[t.wireValue];if(i==null)return;if(!Array.isArray(i)){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}let s=[];for(let f of i){if(typeof f!="string"){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof f}`});return}s.push(f)}return s}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:N.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t??{}}resolveNamedType({typeId:t}){let e=this._ir.types[t];if(e==null){this.errors.add({severity:N.Critical,message:`Type identified by "${t}" could not be found`});return}return e}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e}){let i=this.getRecord(e);if(i==null)return;let s=t.discriminant.wireValue,f=i[s];if(f==null){this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(s).message});return}if(typeof f!="string"){this.errors.add({severity:N.Critical,message:`Expected discriminant value to be a string but got: ${typeof f}`});return}let u=t.types[f];if(u==null){this.errors.add({severity:N.Critical,message:`No type found for discriminant value "${f}"`});return}let{[s]:T,...w}=i;return{singleDiscriminatedUnionType:u,discriminantValue:u.discriminantValue,value:w}}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 i of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:i,parsedEndpoint:t})&&e.push(i);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: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:i}):!t.metadata?.onlyPathParameters}includePathParametersInWrappedRequest({request:t,inlinePathParameters:e}){return e&&(t.metadata?.includePathParameters??!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:L(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":{let i=e.environments.find(s=>s.id===t);return i?.name}case"multipleBaseUrls":{let i=e.environments.find(s=>s.id===t);return i?.name}default:L(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:N.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:N.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let i=e.environments[0];if(i==null)return this.errors.add({severity:N.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let s=new Set(Se(i.urls));for(let f of Se(t))s.has(f)&&s.delete(f);return s.size>0?(this.errors.add({severity:N.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${Se(i.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:N.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:L(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:L(e)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:L(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}};c();m();d();c();m();d();c();m();d();c();m();d();var so=2,Y=class extends Ce{constructor({customConfig:e,formatter:i}){super();y(this,"customConfig");y(this,"formatter");y(this,"requires",new Set);y(this,"_indentLevel",0);this.customConfig=e,this.formatter=i??new Le}addRequire(e){this.requires.add(e)}get currentIndentLevel(){return this._indentLevel}indent(){this._indentLevel++,super.indent()}dedent(){this._indentLevel--,super.dedent()}getTabSize(){return so}};var Ie=class extends Y{constructor({customConfig:t,formatter:e}){super({customConfig:t,formatter:e})}async toStringAsync(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.format(t)}catch(e){throw new Error(`Failed to format Ruby file: ${e}
|
|
15
|
+
`),s=Z&&!this.shouldSkipTracking(i)&&this.lastCharacterIsNewline;e&&(this.lastLine=`${this.lastLine}${i.shift()||""}`),this.lastCharacterIsNewline&&i.pop(),this.lineBuffer.push(...i),s&&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(i=>`${e?`(${e}) `:""} ${i.fn} - ${i.path} : ${i.position}`)}filterStack(t){return t.filter(e=>!e.fn.startsWith(`${this.constructor.name}.`))}appendTrackingComment(){let t=[...this.formatStack(this.filterStack(Qe({maxFrames:15,skip:3}))),...this.formatStack(this.filterStack(this.nodeStackFrames),"node")];switch(this.nodeStackFrames.length=0,wt){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 oo}};c();m();d();c();m();d();c();m();d();var Fe=class{constructor(){y(this,"reporter");y(this,"snippet");y(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}){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:e}){return this.reporter==null||this.reporter.size()>0&&e.size()===0?!0:t.length>(this.snippet?.length??0)}};var Pe=class{constructor(t){y(this,"context");this.context=t}async generate(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s=new Fe;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{let w=await T.generateSnippet({endpoint:f,request:t,options:e});if(u.errors.empty())return{snippet:w,errors:void 0};s.update({context:u,snippet:w})}catch(w){s.err==null&&(s.err=w)}}return s.getResponseOrThrow({endpoint:t.endpoint})}async generateSnippetAst(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{return await T.generateSnippetAst({endpoint:f,request:t,options:e})}catch(w){s=w}}throw s??new Error(`Failed to generate snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}generateSync(t,e={}){let i=this.context.resolveEndpointLocationOrThrow(t.endpoint);if(i.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let s=new Fe;for(let f of i){let u=this.context.clone(),T=this.createSnippetGenerator(u);try{let w=T.generateSnippetSync({endpoint:f,request:t,options:e});if(u.errors.empty())return{snippet:w,errors:void 0};s.update({context:u,snippet:w})}catch(w){s.err==null&&(s.err=w)}}return s.getResponseOrThrow({endpoint:t.endpoint})}};c();m();d();c();m();d();c();m();d();var Ue=class{constructor(){y(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 i=t.match(this.REFERENCE_REGEX);if(!(i==null||i[1]==null||i[2]==null))return{method:i[1],path:i[2]}}};c();m();d();var N={Critical:"CRITICAL",Warning:"WARNING"},Me=class l{constructor(){y(this,"errors");y(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(e=>e.severity===t)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let t=new l;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 i of t){if(typeof i=="string"){e.push(i);continue}e[e.length-1]+=`[${i.index}]`}return e}};var $e=class{constructor({ir:t,config:e,options:i={}}){y(this,"config");y(this,"options");y(this,"errors");y(this,"_ir");y(this,"httpEndpointReferenceParser");this._ir=t,this.config=e,this.options=i,this.errors=new Me,this.httpEndpointReferenceParser=new Ue}associateQueryParametersByWireValue({parameters:t,values:e}){let i=[];for(let[s,f]of Object.entries(e))if(f!==void 0){this.errors.scope(s);try{let u=t.find(w=>w.name.wireValue===s);if(u==null)throw this.newParameterNotRecognizedError(s);let T=this.isListTypeReference(u.typeReference)&&!Array.isArray(f)?[f]:f;i.push({name:u.name,typeReference:u.typeReference,value:T})}finally{this.errors.unscope()}}return i}associateByWireValueOrDefault({parameters:t,values:e}){let i=[];for(let s of t){this.errors.scope(s.name.wireValue);try{let f=e[s.name.wireValue];if(f==null)if(s.typeReference.type==="primitive"&&s.typeReference.value==="STRING")f=`<${s.name.wireValue}>`;else{this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(s.name.wireValue).message});continue}i.push({name:s.name,typeReference:s.typeReference,value:f})}finally{this.errors.unscope()}}return i}associateByWireValue({parameters:t,values:e,ignoreMissingParameters:i}){let s=[];for(let[f,u]of Object.entries(e))if(u!==void 0){this.errors.scope(f);try{let T=t.find(w=>w.name.wireValue===f);if(T==null){if(i)continue;this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(f).message});continue}s.push({name:T.name,typeReference:T.typeReference,value:u})}finally{this.errors.unscope()}}return s}getExampleObjectProperties({parameters:t,snippetObject:e}){let i=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{},s=[];for(let f of t){let u=i[f.name.wireValue];u==null?f.typeReference.type==="nullable"&&s.push({name:f.name,typeReference:f.typeReference,value:null}):s.push({name:f.name,typeReference:f.typeReference,value:u})}return s}getSingleFileValue({property:t,record:e}){let i=e[t.wireValue];if(i!=null){if(typeof i!="string"){this.errors.add({severity:N.Critical,message:`Expected file value to be a string, got ${typeof i}`});return}return i}}getFileArrayValues({property:t,record:e}){let i=e[t.wireValue];if(i==null)return;if(!Array.isArray(i)){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}let s=[];for(let f of i){if(typeof f!="string"){this.errors.add({severity:N.Critical,message:`Expected file array value to be an array of strings, got ${typeof f}`});return}s.push(f)}return s}getRecord(t){if(typeof t!="object"||Array.isArray(t)){this.errors.add({severity:N.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(t)?"array":typeof t}`});return}return t??{}}resolveNamedType({typeId:t}){let e=this._ir.types[t];if(e==null){this.errors.add({severity:N.Critical,message:`Type identified by "${t}" could not be found`});return}return e}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e}){let i=this.getRecord(e);if(i==null)return;let s=t.discriminant.wireValue,f=i[s];if(f==null){this.errors.add({severity:N.Critical,message:this.newParameterNotRecognizedError(s).message});return}if(typeof f!="string"){this.errors.add({severity:N.Critical,message:`Expected discriminant value to be a string but got: ${typeof f}`});return}let u=t.types[f];if(u==null){this.errors.add({severity:N.Critical,message:`No type found for discriminant value "${f}"`});return}let{[s]:T,...w}=i;return{singleDiscriminatedUnionType:u,discriminantValue:u.discriminantValue,value:w}}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 i of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:i,parsedEndpoint:t})&&e.push(i);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}resolveEndpointById(t){return this._ir.endpoints[t]}resolveEndpointByIdOrThrow(t){let e=this.resolveEndpointById(t);if(e==null)throw new Error(`Failed to find endpoint with ID "${t}"`);return e}needsRequestParameter({request:t,inlinePathParameters:e,inlineFileProperties: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:i}):!t.metadata?.onlyPathParameters}includePathParametersInWrappedRequest({request:t,inlinePathParameters:e}){return e&&(t.metadata?.includePathParameters??!1)}isFileUploadRequestBody(t){switch(t.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:L(t)}}resolveEnvironmentName(t){if(this._ir.environments==null)return;let e=this._ir.environments.environments;switch(e.type){case"singleBaseUrl":{let i=e.environments.find(s=>s.id===t);return i?.name}case"multipleBaseUrls":{let i=e.environments.find(s=>s.id===t);return i?.name}default:L(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:N.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:N.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let i=e.environments[0];if(i==null)return this.errors.add({severity:N.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let s=new Set(Se(i.urls));for(let f of Se(t))s.has(f)&&s.delete(f);return s.size>0?(this.errors.add({severity:N.Critical,message:`The provided environments are invalid; got: [${Object.keys(t).join(", ")}], expected: [${Se(i.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:t}){if(typeof t!="number"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"number",value:t}).message});return}return t}getValueAsBoolean({value:t}){if(typeof t!="boolean"){this.errors.add({severity:N.Critical,message:this.newTypeMismatchError({expected:"boolean",value:t}).message});return}return t}getValueAsString({value:t}){if(typeof t!="string"){this.errors.add({severity:N.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:L(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:L(e)}})}fileUploadHasFileProperties({fileUpload:t}){return t.properties.some(e=>{switch(e.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:L(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}};c();m();d();c();m();d();c();m();d();c();m();d();var so=2,Y=class extends Ce{constructor({customConfig:e,formatter:i}){super();y(this,"customConfig");y(this,"formatter");y(this,"requires",new Set);y(this,"_indentLevel",0);this.customConfig=e,this.formatter=i??new Le}addRequire(e){this.requires.add(e)}get currentIndentLevel(){return this._indentLevel}indent(){this._indentLevel++,super.indent()}dedent(){this._indentLevel--,super.dedent()}getTabSize(){return so}};var Ie=class extends Y{constructor({customConfig:t,formatter:e}){super({customConfig:t,formatter:e})}async toStringAsync(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.format(t)}catch(e){throw new Error(`Failed to format Ruby 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 Ruby file: ${e}
|
|
17
17
|
${t}`)}return t}getContent(){let t=this.stringifyRequires();return t.length>0?`${t}
|
|
18
18
|
|