@fern-api/csharp-dynamic-snippets 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DynamicSnippetsGenerator.cjs +4 -4
- package/cjs/EndpointSnippetGenerator.cjs +4 -4
- package/cjs/context/DynamicSnippetsGeneratorContext.cjs +4 -4
- package/cjs/context/DynamicTypeLiteralMapper.cjs +3 -3
- package/cjs/context/DynamicTypeMapper.cjs +3 -3
- package/cjs/context/FilePropertyMapper.cjs +4 -4
- package/cjs/index.cjs +4 -4
- package/esm/DynamicSnippetsGenerator.js +1 -1
- package/esm/EndpointSnippetGenerator.js +1 -1
- package/esm/{chunk-4PKDRTSC.js → chunk-ARC6F6E6.js} +1 -1
- package/esm/{chunk-C4662L36.js → chunk-CIENX2JS.js} +1 -1
- package/esm/{chunk-3DCR7ZLP.js → chunk-DVOWBIEL.js} +1 -1
- package/esm/{chunk-SN6S6BH4.js → chunk-IIP7VDG4.js} +1 -1
- package/esm/{chunk-YSZHI4KM.js → chunk-ME2YBVEY.js} +1 -1
- package/esm/chunk-PJC2VZIA.js +26 -0
- package/esm/{chunk-JE2VCLEP.js → chunk-QKK5PTVJ.js} +1 -1
- package/esm/{chunk-WKJ2SB4L.js → chunk-YL3JFOME.js} +1 -1
- package/esm/context/DynamicSnippetsGeneratorContext.js +1 -1
- package/esm/context/DynamicTypeLiteralMapper.js +1 -1
- package/esm/context/DynamicTypeMapper.js +1 -1
- package/esm/context/FilePropertyMapper.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/esm/chunk-WNZYF5RX.js +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-ME2YBVEY.js";import"./chunk-DVOWBIEL.js";import"./chunk-YL3JFOME.js";import"./chunk-CIENX2JS.js";import"./chunk-IIP7VDG4.js";import"./chunk-QKK5PTVJ.js";import"./chunk-ARC6F6E6.js";import"./chunk-PJC2VZIA.js";import"./chunk-2AZXIWKY.js";export{a as DynamicSnippetsGenerator};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-DVOWBIEL.js";import"./chunk-IIP7VDG4.js";import"./chunk-PJC2VZIA.js";import"./chunk-2AZXIWKY.js";export{a as EndpointSnippetGenerator};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as y,e as n}from"./chunk-
|
|
1
|
+
import{a as y,e as n}from"./chunk-PJC2VZIA.js";import{j as l,k as p,m as s}from"./chunk-2AZXIWKY.js";p();s();var c=class{constructor({context:r}){l(this,"context");this.context=r}getFilePropertyInfo({body:r,value:o}){var a;let e={fileFields:[],bodyPropertyFields:[]},i=(a=this.context.getRecord(o))!=null?a:{};for(let t of r.properties)switch(t.type){case"file":e.fileFields.push({name:this.context.getPropertyName(t.name),value:this.getSingleFileProperty({property:t,record:i})});break;case"fileArray":e.fileFields.push({name:this.context.getPropertyName(t.name),value:this.getArrayFileProperty({property:t,record:i})});break;case"bodyProperty":e.bodyPropertyFields.push({name:this.context.getPropertyName(t.name.name),value:this.getBodyProperty({property:t,record:i})});break;default:y(t)}return e}getSingleFileProperty({property:r,record:o}){let e=this.context.getSingleFileValue({property:r,record:o});return e==null?n.TypeLiteral.nop():this.context.getFileParameterForString(e)}getArrayFileProperty({property:r,record:o}){let e=this.context.getFileArrayValues({property:r,record:o});return e==null?n.TypeLiteral.nop():n.TypeLiteral.list({valueType:n.Type.reference(this.context.getFileParameterClassReference()),values:e.map(i=>this.context.getFileParameterForString(i))})}getBodyProperty({property:r,record:o}){let e=o[r.name.wireValue];return e==null?n.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:r.typeReference,value:e})}};export{c as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as c}from"./chunk-
|
|
1
|
+
import{b as c}from"./chunk-IIP7VDG4.js";import{a as p,e as r}from"./chunk-PJC2VZIA.js";import{j as l,k as u,m as y}from"./chunk-2AZXIWKY.js";u();y();var m=class{constructor({context:e}){l(this,"context");this.context=e}convert(e){if(e.value===null)return this.context.isNullable(e.typeReference)?r.TypeLiteral.null():(this.context.errors.add({severity:c.Critical,message:"Expected non-null value, but got null"}),r.TypeLiteral.nop());if(e.value===void 0)return r.TypeLiteral.nop();switch(e.typeReference.type){case"list":return this.convertList({list:e.typeReference.value,value:e.value});case"literal":return r.TypeLiteral.nop();case"map":return this.convertMap({map:e.typeReference,value:e.value});case"named":{let n=this.context.resolveNamedType({typeId:e.typeReference.value});return n==null?r.TypeLiteral.nop():this.convertNamed({named:n,value:e.value,as:e.as})}case"nullable":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as});case"optional":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as});case"primitive":return this.convertPrimitive({primitive:e.typeReference.value,value:e.value,as:e.as});case"set":return this.convertSet({set:e.typeReference.value,value:e.value});case"unknown":return this.convertUnknown({value:e.value});default:p(e.typeReference)}}convertList({list:e,value:n}){return Array.isArray(n)?r.TypeLiteral.list({valueType:this.context.dynamicTypeMapper.convert({typeReference:e,unboxOptionals:!0}),values:n.map((i,t)=>{this.context.errors.scope({index:t});try{return this.convert({typeReference:e,value:i})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:c.Critical,message:`Expected array but got: ${typeof n}`}),r.TypeLiteral.nop())}convertSet({set:e,value:n}){return Array.isArray(n)?r.TypeLiteral.set({valueType:this.context.dynamicTypeMapper.convert({typeReference:e,unboxOptionals:!0}),values:n.map((i,t)=>{this.context.errors.scope({index:t});try{return this.convert({typeReference:e,value:i})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:c.Critical,message:`Expected array but got: ${typeof n}`}),r.TypeLiteral.nop())}convertMap({map:e,value:n}){return typeof n!="object"||n==null?(this.context.errors.add({severity:c.Critical,message:`Expected object but got: ${n==null?"null":typeof n}`}),r.TypeLiteral.nop()):r.TypeLiteral.dictionary({keyType:this.context.dynamicTypeMapper.convert({typeReference:e.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:e.value}),entries:Object.entries(n).map(([i,t])=>{this.context.errors.scope(i);try{return{key:this.convert({typeReference:e.key,value:i,as:"key"}),value:this.convert({typeReference:e.value,value:t})}}finally{this.context.errors.unscope()}})})}convertNamed({named:e,value:n,as:i}){switch(e.type){case"alias":return this.convert({typeReference:e.typeReference,value:n,as:i});case"discriminatedUnion":return this.context.shouldUseDiscriminatedUnions()?this.convertDiscriminatedUnion({discriminatedUnion:e,value:n}):this.convertUnknown({value:n});case"enum":return this.convertEnum({enum_:e,value:n});case"object":return this.convertObject({object_:e,value:n});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:e,value:n});default:p(e)}}convertDiscriminatedUnion({discriminatedUnion:e,value:n}){let i=r.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getNamespace(e.declaration.fernFilepath)}),t=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:n});if(t==null)return r.TypeLiteral.nop();let a=t.singleDiscriminatedUnionType,s=this.getBaseProperties({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:a});switch(a.type){case"samePropertiesAsObject":{let o=this.context.resolveNamedType({typeId:a.typeId});return o==null?r.TypeLiteral.nop():this.instantiateUnionWithBaseProperties({classReference:i,baseProperties:s,arguments_:[this.convertNamed({named:o,value:t.value})]})}case"singleProperty":{let o=this.context.getRecord(t.value);if(o==null)return r.TypeLiteral.nop();try{return this.context.errors.scope(a.discriminantValue.wireValue),this.instantiateUnionWithBaseProperties({classReference:i,baseProperties:s,arguments_:[this.convert({typeReference:a.typeReference,value:o[a.discriminantValue.wireValue]})]})}finally{this.context.errors.unscope()}}case"noProperties":return this.instantiateUnionWithBaseProperties({classReference:i,baseProperties:s,arguments_:[]});default:p(a)}}getBaseProperties({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:n}){var t,a;return this.context.associateByWireValue({parameters:(t=n.properties)!=null?t:[],values:(a=this.context.getRecord(e.value))!=null?a:{},ignoreMissingParameters:!0}).map(s=>{this.context.errors.scope(s.name.wireValue);try{return{name:this.context.getPropertyName(s.name.name),assignment:this.convert(s)}}finally{this.context.errors.unscope()}})}instantiateUnionWithBaseProperties({classReference:e,arguments_:n,baseProperties:i}){let t=r.instantiateClass({classReference:e,arguments_:n,multiline:!0});return i.length===0?r.TypeLiteral.reference(t):r.TypeLiteral.reference(r.codeblock(a=>{a.writeNode(t),a.writeLine(" {"),a.indent();for(let s of i)a.write(s.name),a.write(" = "),a.writeNodeOrString(s.assignment),a.writeLine(",");a.dedent(),a.write("}")}))}convertEnum({enum_:e,value:n}){let i=this.getEnumValueName({enum_:e,value:n});return i==null?r.TypeLiteral.nop():r.TypeLiteral.reference(r.classReference({name:i,namespace:this.context.getNamespace(e.declaration.fernFilepath)}))}getEnumValueName({enum_:e,value:n}){if(typeof n!="string"){this.context.errors.add({severity:c.Critical,message:`Expected enum value string, got: ${typeof n}`});return}let i=e.values.find(t=>t.wireValue===n);if(i==null){this.context.errors.add({severity:c.Critical,message:`An enum value named "${n}" does not exist in this context`});return}return`${this.context.getClassName(e.declaration.name)}.${this.context.getClassName(i.name)}`}convertObject({object_:e,value:n}){var t;let i=this.context.associateByWireValue({parameters:e.properties,values:(t=this.context.getRecord(n))!=null?t:{}});return r.TypeLiteral.class_({reference:r.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getNamespace(e.declaration.fernFilepath)}),fields:i.map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getClassName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})})}convertUndiscriminatedUnion({undiscriminatedUnion:e,value:n}){let i=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:n});return i==null?r.TypeLiteral.nop():i.typeLiteral}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:n}){for(let i of e.types)try{let t=this.convert({typeReference:i,value:n});return{valueTypeReference:i,typeLiteral:t}}catch(t){continue}this.context.errors.add({severity:c.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof n}" value`})}convertUnknown({value:e}){return r.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:n,as:i}){switch(e){case"INTEGER":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.integer(t)}case"LONG":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.long(t)}case"UINT":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.uint(t)}case"UINT_64":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.ulong(t)}case"FLOAT":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.float(t)}case"DOUBLE":{let t=this.getValueAsNumber({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.double(t)}case"BOOLEAN":{let t=this.getValueAsBoolean({value:n,as:i});return t==null?r.TypeLiteral.nop():r.TypeLiteral.boolean(t)}case"STRING":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.string(t)}case"DATE":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.date(t)}case"DATE_TIME":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.datetime(t)}case"UUID":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.string(t)}case"BASE_64":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.string(t)}case"BIG_INTEGER":{let t=this.context.getValueAsString({value:n});return t==null?r.TypeLiteral.nop():r.TypeLiteral.string(t)}default:p(e)}}getValueAsNumber({value:e,as:n}){let i=n==="key"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:i})}getValueAsBoolean({value:e,as:n}){let i=n==="key"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:i})}};export{m as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as o,d as f,e as c}from"./chunk-SN6S6BH4.js";import{a as u,c as R,d as I,e as a}from"./chunk-WNZYF5RX.js";import{j as x,k as A,m as C}from"./chunk-2AZXIWKY.js";A();C();var F="Usage",B="Example",T="Do",P="client",q={type:"primitive",value:"STRING"},N=class{constructor({context:e}){x(this,"context");this.context=e}async generateSnippet({endpoint:e,request:t,options:r}){var n;return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({namespace:F,rootNamespace:this.context.getRootNamespace(),customConfig:(n=this.context.customConfig)!=null?n:{},allNamespaceSegments:new Set,allTypeClassReferences:new Map})}generateSnippetSync({endpoint:e,request:t,options:r}){var n;return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({namespace:F,rootNamespace:this.context.getRootNamespace(),customConfig:(n=this.context.customConfig)!=null?n:{},allNamespaceSegments:new Set,allTypeClassReferences:new Map})}buildCodeBlock({endpoint:e,snippet:t,options:r}){let s=a.codeblock(i=>{i.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),i.newLine(),i.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))}),n=this.getStyle(r);switch(n){case f.Concise:return s;case f.Full:return this.buildFullCodeBlock({body:s,options:r});default:u(n)}}buildFullCodeBlock({body:e,options:t}){var n;let r=this.getConfig(t),s=a.class_({name:(n=r.fullStyleClassName)!=null?n:B,namespace:F,access:a.Access.Public});return s.addMethod(a.method({name:T,access:a.Access.Public,isAsync:!0,parameters:[],body:e})),s}constructClient({endpoint:e,snippet:t}){return a.codeblock(r=>{r.write(`var ${P} = `),r.writeNode(this.getRootClientConstructorInvocation(this.getConstructorArgs({endpoint:e,snippet:t})))})}callMethod({endpoint:e,snippet:t}){return a.invokeMethod({on:a.codeblock(P),method:this.getMethod({endpoint:e}),arguments_:this.getMethodArgs({endpoint:e,snippet:t}),async:!0,configureAwait:!0,multiline:!0})}getConstructorArgs({endpoint:e,snippet:t}){let r=[];e.auth!=null&&(t.auth!=null?r.push(...this.getConstructorAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:o.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`}));let s=[],n=this.getConstructorBaseUrlArgs({baseUrl:t.baseURL,environment:t.environment});n.length>0&&s.push(...n),this.context.errors.scope(c.Headers);let i=[];return this.context.ir.headers!=null&&t.headers!=null&&i.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope(),s.length===0?[...r,...i]:[...r,...i,{name:"clientOptions",assignment:a.instantiateClass({classReference:this.context.getClientOptionsClassReference(),arguments_:s.map(p=>({name:p.name,assignment:p.assignment})),multiline:!0})}]}getConstructorBaseUrlArgs({baseUrl:e,environment:t}){let r=this.getBaseUrlArg({baseUrl:e,environment:t});return a.TypeLiteral.isNop(r)?[]:[{name:this.getBaseUrlOptionName(),assignment:r}]}getBaseUrlArg({baseUrl:e,environment:t}){var r;if(e!=null&&t!=null)return this.context.errors.add({severity:o.Critical,message:"Cannot specify both baseUrl and environment options"}),a.TypeLiteral.nop();if(e!=null)return((r=this.context.ir.environments)==null?void 0:r.environments.type)==="multipleBaseUrls"?(this.context.errors.add({severity:o.Critical,message:"The C# SDK doesn't support a baseUrl when multiple URL environments are configured"}),a.TypeLiteral.nop()):a.TypeLiteral.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let s=this.context.getEnvironmentTypeReferenceFromID(t);return s==null?(this.context.errors.add({severity:o.Warning,message:`Environment ${JSON.stringify(t)} was not found`}),a.TypeLiteral.nop()):a.TypeLiteral.reference(s)}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?a.TypeLiteral.reference(a.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.entries(t).map(([s,n])=>({name:R(I(s)),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:q,value:n})})),multiline:!0})):a.TypeLiteral.nop()}return a.TypeLiteral.nop()}getConstructorAuthArgs({auth:e,values:t}){switch(e.type){case"basic":return t.type!=="basic"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorBasicAuthArg({auth:e,values:t});case"bearer":return t.type!=="bearer"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorBearerAuthArgs({auth:e,values:t});case"header":return t.type!=="header"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorHeaderAuthArgs({auth:e,values:t});case"oauth":return t.type!=="oauth"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorOAuthArgs({auth:e,values:t});default:u(e)}}getConstructorBasicAuthArg({auth:e,values:t}){return[{name:this.context.getParameterName(e.username),assignment:a.TypeLiteral.string(t.username)},{name:this.context.getParameterName(e.password),assignment:a.TypeLiteral.string(t.password)}]}getConstructorBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.token),assignment:a.TypeLiteral.string(t.token)}]}getConstructorHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.header.name.name),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getConstructorOAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.clientId),assignment:a.TypeLiteral.string(t.clientId)},{name:this.context.getParameterName(e.clientSecret),assignment:a.TypeLiteral.string(t.clientSecret)}]}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let s of e){let n=this.getConstructorHeaderArg({header:s,value:t.value});n!=null&&r.push({name:this.context.getParameterName(s.name.name),assignment:n})}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!a.TypeLiteral.isNop(r))return r}getMethodArgs({endpoint:e,snippet:t}){switch(e.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:e.request,snippet:t});case"body":return this.getMethodArgsForBodyRequest({request:e.request,snippet:t});default:u(e.request)}}getMethodArgsForInlinedRequest({request:e,snippet:t}){var h,y,d,l;let r=[],s=(y=(h=this.context.customConfig)==null?void 0:h["inline-path-parameters"])!=null?y:!1;this.context.errors.scope(c.PathParameters);let n=[],i=[...(d=this.context.ir.pathParameters)!=null?d:[],...(l=e.pathParameters)!=null?l:[]];i.length>0&&n.push(...this.getPathParameters({namedParameters:i,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let p=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:s})||r.push(...n.map(g=>g.value)),r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:s})?n:[],filePropertyInfo:p})),r}getFilePropertyInfo({request:e,snippet:t}){return e.body==null||!this.context.isFileUploadRequestBody(e.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:e.body,value:t.requestBody})}getInlinedRequestArg({request:e,snippet:t,pathParameterFields:r,filePropertyInfo:s}){var d,l,g,v;this.context.errors.scope(c.QueryParameters);let i=this.context.associateQueryParametersByWireValue({parameters:(d=e.queryParameters)!=null?d:[],values:(l=t.queryParameters)!=null?l:{}}).map(m=>({name:this.context.getPropertyName(m.name.name),value:this.context.dynamicTypeLiteralMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.Headers);let h=this.context.associateByWireValue({parameters:(g=e.headers)!=null?g:[],values:(v=t.headers)!=null?v:{}}).map(m=>({name:this.context.getPropertyName(m.name.name),value:this.context.dynamicTypeLiteralMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let y=e.body!=null?this.getInlinedRequestBodyConstructorFields({body:e.body,value:t.requestBody,filePropertyInfo:s}):[];return this.context.errors.unscope(),a.TypeLiteral.class_({reference:a.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getNamespace(e.declaration.fernFilepath)}),fields:[...r,...i,...h,...y]})}getInlinedRequestBodyConstructorFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyConstructorFields({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyConstructorField({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyConstructorFields({filePropertyInfo:r});default:u(e)}}getInlinedRequestBodyPropertyConstructorFields({parameters:e,value:t}){var n;let r=[],s=this.context.associateByWireValue({parameters:e,values:(n=this.context.getRecord(t))!=null?n:{}});for(let i of s)r.push({name:this.context.getPropertyName(i.name.name),value:this.context.dynamicTypeLiteralMapper.convert(i)});return r}getFileUploadRequestBodyConstructorFields({filePropertyInfo:e}){return[...e.fileFields,...e.bodyPropertyFields]}getReferencedRequestBodyPropertyConstructorField({body:e,value:t}){return{name:this.context.getPropertyName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeLiteral({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:u(e)}}getMethodArgsForBodyRequest({request:e,snippet:t}){var n,i;let r=[];this.context.errors.scope(c.PathParameters);let s=[...(n=this.context.ir.pathParameters)!=null?n:[],...(i=e.pathParameters)!=null?i:[]];return s.length>0&&r.push(...this.getPathParameters({namedParameters:s,snippet:t}).map(p=>p.value)),this.context.errors.unscope(),this.context.errors.scope(c.RequestBody),e.body!=null&&r.push(this.getBodyRequestArg({body:e.body,value:t.requestBody})),this.context.errors.unscope(),r}getBodyRequestArg({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:u(e)}}getBytesBodyRequestArg({value:e}){let t=this.context.getValueAsString({value:e});return t==null?(this.context.errors.add({severity:o.Critical,message:"The bytes request body must be provided in string format"}),a.TypeLiteral.nop()):a.TypeLiteral.reference(this.context.getMemoryStreamForString(t))}getRootClientConstructorInvocation(e){return a.instantiateClass({classReference:this.context.getRootClientClassReference(),arguments_:e,forceUseConstructor:!0,multiline:!0})}getPathParameters({namedParameters:e,snippet:t}){var n;let r=[],s=this.context.associateByWireValue({parameters:e,values:(n=t.pathParameters)!=null?n:{}});for(let i of s)r.push({name:this.context.getPropertyName(i.name.name),value:this.context.dynamicTypeLiteralMapper.convert(i)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getClassName(t)).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getBaseUrlOptionName(){var e;return((e=this.context.ir.environments)==null?void 0:e.environments.type)==="multipleBaseUrls"?"Environment":"BaseUrl"}getStyle(e){var t,r;return(r=(t=e.style)!=null?t:this.context.options.style)!=null?r:f.Full}getConfig(e){var t,r;return(r=(t=e.config)!=null?t:this.context.options.config)!=null?r:{}}};export{N as a};
|
|
1
|
+
import{b as o,d as f,e as c}from"./chunk-IIP7VDG4.js";import{a as u,c as R,d as I,e as a}from"./chunk-PJC2VZIA.js";import{j as x,k as A,m as C}from"./chunk-2AZXIWKY.js";A();C();var F="Usage",B="Example",T="Do",P="client",q={type:"primitive",value:"STRING"},N=class{constructor({context:e}){x(this,"context");this.context=e}async generateSnippet({endpoint:e,request:t,options:r}){var n;return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({namespace:F,rootNamespace:this.context.getRootNamespace(),customConfig:(n=this.context.customConfig)!=null?n:{},allNamespaceSegments:new Set,allTypeClassReferences:new Map})}generateSnippetSync({endpoint:e,request:t,options:r}){var n;return this.buildCodeBlock({endpoint:e,snippet:t,options:r}).toString({namespace:F,rootNamespace:this.context.getRootNamespace(),customConfig:(n=this.context.customConfig)!=null?n:{},allNamespaceSegments:new Set,allTypeClassReferences:new Map})}buildCodeBlock({endpoint:e,snippet:t,options:r}){let s=a.codeblock(i=>{i.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),i.newLine(),i.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))}),n=this.getStyle(r);switch(n){case f.Concise:return s;case f.Full:return this.buildFullCodeBlock({body:s,options:r});default:u(n)}}buildFullCodeBlock({body:e,options:t}){var n;let r=this.getConfig(t),s=a.class_({name:(n=r.fullStyleClassName)!=null?n:B,namespace:F,access:a.Access.Public});return s.addMethod(a.method({name:T,access:a.Access.Public,isAsync:!0,parameters:[],body:e})),s}constructClient({endpoint:e,snippet:t}){return a.codeblock(r=>{r.write(`var ${P} = `),r.writeNode(this.getRootClientConstructorInvocation(this.getConstructorArgs({endpoint:e,snippet:t})))})}callMethod({endpoint:e,snippet:t}){return a.invokeMethod({on:a.codeblock(P),method:this.getMethod({endpoint:e}),arguments_:this.getMethodArgs({endpoint:e,snippet:t}),async:!0,configureAwait:!0,multiline:!0})}getConstructorArgs({endpoint:e,snippet:t}){let r=[];e.auth!=null&&(t.auth!=null?r.push(...this.getConstructorAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:o.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`}));let s=[],n=this.getConstructorBaseUrlArgs({baseUrl:t.baseURL,environment:t.environment});n.length>0&&s.push(...n),this.context.errors.scope(c.Headers);let i=[];return this.context.ir.headers!=null&&t.headers!=null&&i.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope(),s.length===0?[...r,...i]:[...r,...i,{name:"clientOptions",assignment:a.instantiateClass({classReference:this.context.getClientOptionsClassReference(),arguments_:s.map(p=>({name:p.name,assignment:p.assignment})),multiline:!0})}]}getConstructorBaseUrlArgs({baseUrl:e,environment:t}){let r=this.getBaseUrlArg({baseUrl:e,environment:t});return a.TypeLiteral.isNop(r)?[]:[{name:this.getBaseUrlOptionName(),assignment:r}]}getBaseUrlArg({baseUrl:e,environment:t}){var r;if(e!=null&&t!=null)return this.context.errors.add({severity:o.Critical,message:"Cannot specify both baseUrl and environment options"}),a.TypeLiteral.nop();if(e!=null)return((r=this.context.ir.environments)==null?void 0:r.environments.type)==="multipleBaseUrls"?(this.context.errors.add({severity:o.Critical,message:"The C# SDK doesn't support a baseUrl when multiple URL environments are configured"}),a.TypeLiteral.nop()):a.TypeLiteral.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let s=this.context.getEnvironmentTypeReferenceFromID(t);return s==null?(this.context.errors.add({severity:o.Warning,message:`Environment ${JSON.stringify(t)} was not found`}),a.TypeLiteral.nop()):a.TypeLiteral.reference(s)}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?a.TypeLiteral.reference(a.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.entries(t).map(([s,n])=>({name:R(I(s)),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:q,value:n})})),multiline:!0})):a.TypeLiteral.nop()}return a.TypeLiteral.nop()}getConstructorAuthArgs({auth:e,values:t}){switch(e.type){case"basic":return t.type!=="basic"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorBasicAuthArg({auth:e,values:t});case"bearer":return t.type!=="bearer"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorBearerAuthArgs({auth:e,values:t});case"header":return t.type!=="header"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorHeaderAuthArgs({auth:e,values:t});case"oauth":return t.type!=="oauth"?(this.context.errors.add({severity:o.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),[]):this.getConstructorOAuthArgs({auth:e,values:t});default:u(e)}}getConstructorBasicAuthArg({auth:e,values:t}){return[{name:this.context.getParameterName(e.username),assignment:a.TypeLiteral.string(t.username)},{name:this.context.getParameterName(e.password),assignment:a.TypeLiteral.string(t.password)}]}getConstructorBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.token),assignment:a.TypeLiteral.string(t.token)}]}getConstructorHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.header.name.name),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getConstructorOAuthArgs({auth:e,values:t}){return[{name:this.context.getParameterName(e.clientId),assignment:a.TypeLiteral.string(t.clientId)},{name:this.context.getParameterName(e.clientSecret),assignment:a.TypeLiteral.string(t.clientSecret)}]}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let s of e){let n=this.getConstructorHeaderArg({header:s,value:t.value});n!=null&&r.push({name:this.context.getParameterName(s.name.name),assignment:n})}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!a.TypeLiteral.isNop(r))return r}getMethodArgs({endpoint:e,snippet:t}){switch(e.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:e.request,snippet:t});case"body":return this.getMethodArgsForBodyRequest({request:e.request,snippet:t});default:u(e.request)}}getMethodArgsForInlinedRequest({request:e,snippet:t}){var h,y,d,l;let r=[],s=(y=(h=this.context.customConfig)==null?void 0:h["inline-path-parameters"])!=null?y:!1;this.context.errors.scope(c.PathParameters);let n=[],i=[...(d=this.context.ir.pathParameters)!=null?d:[],...(l=e.pathParameters)!=null?l:[]];i.length>0&&n.push(...this.getPathParameters({namedParameters:i,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let p=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:s})||r.push(...n.map(g=>g.value)),r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:s})?n:[],filePropertyInfo:p})),r}getFilePropertyInfo({request:e,snippet:t}){return e.body==null||!this.context.isFileUploadRequestBody(e.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:e.body,value:t.requestBody})}getInlinedRequestArg({request:e,snippet:t,pathParameterFields:r,filePropertyInfo:s}){var d,l,g,v;this.context.errors.scope(c.QueryParameters);let i=this.context.associateQueryParametersByWireValue({parameters:(d=e.queryParameters)!=null?d:[],values:(l=t.queryParameters)!=null?l:{}}).map(m=>({name:this.context.getPropertyName(m.name.name),value:this.context.dynamicTypeLiteralMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.Headers);let h=this.context.associateByWireValue({parameters:(g=e.headers)!=null?g:[],values:(v=t.headers)!=null?v:{}}).map(m=>({name:this.context.getPropertyName(m.name.name),value:this.context.dynamicTypeLiteralMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let y=e.body!=null?this.getInlinedRequestBodyConstructorFields({body:e.body,value:t.requestBody,filePropertyInfo:s}):[];return this.context.errors.unscope(),a.TypeLiteral.class_({reference:a.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getNamespace(e.declaration.fernFilepath)}),fields:[...r,...i,...h,...y]})}getInlinedRequestBodyConstructorFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyConstructorFields({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyConstructorField({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyConstructorFields({filePropertyInfo:r});default:u(e)}}getInlinedRequestBodyPropertyConstructorFields({parameters:e,value:t}){var n;let r=[],s=this.context.associateByWireValue({parameters:e,values:(n=this.context.getRecord(t))!=null?n:{}});for(let i of s)r.push({name:this.context.getPropertyName(i.name.name),value:this.context.dynamicTypeLiteralMapper.convert(i)});return r}getFileUploadRequestBodyConstructorFields({filePropertyInfo:e}){return[...e.fileFields,...e.bodyPropertyFields]}getReferencedRequestBodyPropertyConstructorField({body:e,value:t}){return{name:this.context.getPropertyName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeLiteral({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:u(e)}}getMethodArgsForBodyRequest({request:e,snippet:t}){var n,i;let r=[];this.context.errors.scope(c.PathParameters);let s=[...(n=this.context.ir.pathParameters)!=null?n:[],...(i=e.pathParameters)!=null?i:[]];return s.length>0&&r.push(...this.getPathParameters({namedParameters:s,snippet:t}).map(p=>p.value)),this.context.errors.unscope(),this.context.errors.scope(c.RequestBody),e.body!=null&&r.push(this.getBodyRequestArg({body:e.body,value:t.requestBody})),this.context.errors.unscope(),r}getBodyRequestArg({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:u(e)}}getBytesBodyRequestArg({value:e}){let t=this.context.getValueAsString({value:e});return t==null?(this.context.errors.add({severity:o.Critical,message:"The bytes request body must be provided in string format"}),a.TypeLiteral.nop()):a.TypeLiteral.reference(this.context.getMemoryStreamForString(t))}getRootClientConstructorInvocation(e){return a.instantiateClass({classReference:this.context.getRootClientClassReference(),arguments_:e,forceUseConstructor:!0,multiline:!0})}getPathParameters({namedParameters:e,snippet:t}){var n;let r=[],s=this.context.associateByWireValue({parameters:e,values:(n=t.pathParameters)!=null?n:{}});for(let i of s)r.push({name:this.context.getPropertyName(i.name.name),value:this.context.dynamicTypeLiteralMapper.convert(i)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getClassName(t)).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getBaseUrlOptionName(){var e;return((e=this.context.ir.environments)==null?void 0:e.environments.type)==="multipleBaseUrls"?"Environment":"BaseUrl"}getStyle(e){var t,r;return(r=(t=e.style)!=null?t:this.context.options.style)!=null?r:f.Full}getConfig(e){var t,r;return(r=(t=e.config)!=null?t:this.context.options.config)!=null?r:{}}};export{N as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as m,b as E}from"./chunk-WNZYF5RX.js";import{a as T,b as S,c as b,d as A,j as l,k as o,m as a}from"./chunk-2AZXIWKY.js";o();a();o();a();var y=class{constructor(){l(this,"reporter");l(this,"snippet");l(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:e,snippet:r}){this.shouldUpdate({snippet:r,reporter:e.errors})&&(this.reporter=e.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:e}){var r;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(r=this.err)!=null?r:new Error(`Failed to generate snippet for endpoint "${e.method} ${e.path}"`)}shouldUpdate({snippet:e,reporter:r}){var t,n;return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:e.length>((n=(t=this.snippet)==null?void 0:t.length)!=null?n:0)}};var R=class{constructor(e){l(this,"context");this.context=e}async generate(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let u=await d.generateSnippet({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:u,errors:void 0};n.update({context:s,snippet:u})}catch(u){n.err==null&&(n.err=u)}}return n.getResponseOrThrow({endpoint:e.endpoint})}generateSync(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let u=d.generateSnippetSync({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:u,errors:void 0};n.update({context:s,snippet:u})}catch(u){n.err==null&&(n.err=u)}}return n.getResponseOrThrow({endpoint:e.endpoint})}};o();a();var p={Critical:"CRITICAL",Warning:"WARNING"},g=class c{constructor(){l(this,"errors");l(this,"path");this.errors=[],this.path=[]}add(e){this.errors.push(S(T({},e),{path:[...this.path]}))}scope(e){this.path.push(e)}unscope(){this.path.pop()}getBySeverity(e){return this.errors.filter(r=>r.severity===e)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let e=new c;return e.errors=[...this.errors],e.path=[...this.path],e}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(e=>({severity:e.severity,path:e.path!=null?this.pathToStringArray(e.path):void 0,message:e.message}))}pathToStringArray(e){let r=[];for(let t of e){if(typeof t=="string"){r.push(t);continue}r[r.length-1]+=`[${t.index}]`}return r}};o();a();o();a();o();a();var v=class{constructor(){l(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH)\s(\/[a-zA-Z0-9\/{}_-]*)$/)}validate(e){return this.REFERENCE_REGEX.test(e)?{type:"valid"}:{type:"invalid"}}tryParse(e){if(this.validate(e).type==="invalid")return;let t=e.match(this.REFERENCE_REGEX);if(!(t==null||t[1]==null||t[2]==null))return{method:t[1],path:t[2]}}};var w=class{constructor({ir:e,config:r,options:t={}}){l(this,"config");l(this,"options");l(this,"errors");l(this,"_ir");l(this,"httpEndpointReferenceParser");this._ir=e,this.config=r,this.options=t,this.errors=new g,this.httpEndpointReferenceParser=new v}associateQueryParametersByWireValue({parameters:e,values:r}){let t=[];for(let[n,i]of Object.entries(r)){this.errors.scope(n);try{let s=e.find(u=>u.name.wireValue===n);if(s==null)throw this.newParameterNotRecognizedError(n);let d=this.isListTypeReference(s.typeReference)&&!Array.isArray(i)?[i]:i;t.push({name:s.name,typeReference:s.typeReference,value:d})}finally{this.errors.unscope()}}return t}associateByWireValue({parameters:e,values:r,ignoreMissingParameters:t}){let n=[];for(let[i,s]of Object.entries(r)){this.errors.scope(i);try{let d=e.find(u=>u.name.wireValue===i);if(d==null){if(t)continue;this.errors.add({severity:p.Critical,message:this.newParameterNotRecognizedError(i).message});continue}n.push({name:d.name,typeReference:d.typeReference,value:s})}finally{this.errors.unscope()}}return n}getSingleFileValue({property:e,record:r}){let t=r[e.wireValue];if(t!=null){if(typeof t!="string"){this.errors.add({severity:p.Critical,message:`Expected file value to be a string, got ${typeof t}`});return}return t}}getFileArrayValues({property:e,record:r}){let t=r[e.wireValue];if(t==null)return;if(!Array.isArray(t)){this.errors.add({severity:p.Critical,message:`Expected file array value to be an array of strings, got ${typeof t}`});return}let n=[];for(let i of t){if(typeof i!="string"){this.errors.add({severity:p.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}n.push(i)}return n}getRecord(e){if(typeof e!="object"||Array.isArray(e)){this.errors.add({severity:p.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(e)?"array":typeof e}`});return}return e==null?{}:e}resolveNamedType({typeId:e}){let r=this._ir.types[e];if(r==null){this.errors.add({severity:p.Critical,message:`Type identified by "${e}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:r}){let t=this.getRecord(r);if(t==null)return;let n=e.discriminant.wireValue,i=t[n];if(i==null){this.errors.add({severity:p.Critical,message:this.newParameterNotRecognizedError(n).message});return}if(typeof i!="string"){this.errors.add({severity:p.Critical,message:`Expected discriminant value to be a string but got: ${typeof i}`});return}let s=e.types[i];if(s==null){this.errors.add({severity:p.Critical,message:`No type found for discriminant value "${i}"`});return}let P=t,{[n]:d}=P,u=A(P,[b(n)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:u}}resolveEndpointOrThrow(e){let r=this.httpEndpointReferenceParser.tryParse(e);if(r==null)throw new Error(`Failed to parse endpoint reference "${e}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocationOrThrow(e){let r=[];for(let t of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:t,parsedEndpoint:e})&&r.push(t);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${e.method} ${e.path}"`);return r}needsRequestParameter({request:e,inlinePathParameters:r,inlineFileProperties:t}){var n;return this.includePathParametersInWrappedRequest({request:e,inlinePathParameters:r})||e.queryParameters!=null&&e.queryParameters.length>0||e.headers!=null&&e.headers.length>0?!0:e.body!=null?this.includeRequestBodyInWrappedRequest({body:e.body,inlineFileProperties:t}):!((n=e.metadata)!=null&&n.onlyPathParameters)}includePathParametersInWrappedRequest({request:e,inlinePathParameters:r}){var t,n;return r&&((n=(t=e.metadata)==null?void 0:t.includePathParameters)!=null?n:!1)}isFileUploadRequestBody(e){switch(e.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:m(e)}}resolveEnvironmentName(e){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}case"multipleBaseUrls":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}default:m(r)}}isSingleEnvironmentID(e){return typeof e=="string"}isMultiEnvironmentValues(e){return typeof e=="object"}validateMultiEnvironmentUrlValues(e){if(this._ir.environments==null)return this.errors.add({severity:p.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:p.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let t=r.environments[0];if(t==null)return this.errors.add({severity:p.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let n=new Set(E(t.urls));for(let i of E(e))n.has(i)&&n.delete(i);return n.size>0?(this.errors.add({severity:p.Critical,message:`The provided environments are invalid; got: [${Object.keys(e).join(", ")}], expected: [${E(t.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:e}){if(typeof e!="number"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"number",value:e}).message});return}return e}getValueAsBoolean({value:e}){if(typeof e!="boolean"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"boolean",value:e}).message});return}return e}getValueAsString({value:e}){if(typeof e!="string"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"string",value:e}).message});return}return e}isOptional(e){switch(e.type){case"nullable":return this.isOptional(e.value);case"optional":return!0;case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(e){switch(e.type){case"nullable":return!0;case"optional":return this.isNullable(e.value);case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:e,values:r}){return new Error(`Expected auth type ${e.type}, got ${r.type}`)}newParameterNotRecognizedError(e){return new Error(`"${e}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:e,value:r}){return new Error(`Expected ${e}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:e,inlineFileProperties:r}){switch(e.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r});default:m(e)}}includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:e})||r&&this.fileUploadHasFileProperties({fileUpload:e})}fileUploadHasBodyProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:m(r)}})}fileUploadHasFileProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:m(r)}})}isListTypeReference(e){return e.type==="optional"?this.isListTypeReference(e.value):e.type==="list"||e.type==="set"}parsedEndpointMatches({endpoint:e,parsedEndpoint:r}){return e.location.method===r.method&&e.location.path===r.path}};o();a();var x;(function(c){c.Concise="concise",c.Full="full"})(x||(x={}));o();a();var C={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};o();a();export{R as a,p as b,w as c,x as d,C as e};
|
|
1
|
+
import{a as m,b as E}from"./chunk-PJC2VZIA.js";import{a as T,b as S,c as b,d as A,j as l,k as o,m as a}from"./chunk-2AZXIWKY.js";o();a();o();a();var y=class{constructor(){l(this,"reporter");l(this,"snippet");l(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:e,snippet:r}){this.shouldUpdate({snippet:r,reporter:e.errors})&&(this.reporter=e.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:e}){var r;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(r=this.err)!=null?r:new Error(`Failed to generate snippet for endpoint "${e.method} ${e.path}"`)}shouldUpdate({snippet:e,reporter:r}){var t,n;return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:e.length>((n=(t=this.snippet)==null?void 0:t.length)!=null?n:0)}};var R=class{constructor(e){l(this,"context");this.context=e}async generate(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let u=await d.generateSnippet({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:u,errors:void 0};n.update({context:s,snippet:u})}catch(u){n.err==null&&(n.err=u)}}return n.getResponseOrThrow({endpoint:e.endpoint})}generateSync(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let u=d.generateSnippetSync({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:u,errors:void 0};n.update({context:s,snippet:u})}catch(u){n.err==null&&(n.err=u)}}return n.getResponseOrThrow({endpoint:e.endpoint})}};o();a();var p={Critical:"CRITICAL",Warning:"WARNING"},g=class c{constructor(){l(this,"errors");l(this,"path");this.errors=[],this.path=[]}add(e){this.errors.push(S(T({},e),{path:[...this.path]}))}scope(e){this.path.push(e)}unscope(){this.path.pop()}getBySeverity(e){return this.errors.filter(r=>r.severity===e)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let e=new c;return e.errors=[...this.errors],e.path=[...this.path],e}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(e=>({severity:e.severity,path:e.path!=null?this.pathToStringArray(e.path):void 0,message:e.message}))}pathToStringArray(e){let r=[];for(let t of e){if(typeof t=="string"){r.push(t);continue}r[r.length-1]+=`[${t.index}]`}return r}};o();a();o();a();o();a();var v=class{constructor(){l(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH)\s(\/[a-zA-Z0-9\/{}_-]*)$/)}validate(e){return this.REFERENCE_REGEX.test(e)?{type:"valid"}:{type:"invalid"}}tryParse(e){if(this.validate(e).type==="invalid")return;let t=e.match(this.REFERENCE_REGEX);if(!(t==null||t[1]==null||t[2]==null))return{method:t[1],path:t[2]}}};var w=class{constructor({ir:e,config:r,options:t={}}){l(this,"config");l(this,"options");l(this,"errors");l(this,"_ir");l(this,"httpEndpointReferenceParser");this._ir=e,this.config=r,this.options=t,this.errors=new g,this.httpEndpointReferenceParser=new v}associateQueryParametersByWireValue({parameters:e,values:r}){let t=[];for(let[n,i]of Object.entries(r)){this.errors.scope(n);try{let s=e.find(u=>u.name.wireValue===n);if(s==null)throw this.newParameterNotRecognizedError(n);let d=this.isListTypeReference(s.typeReference)&&!Array.isArray(i)?[i]:i;t.push({name:s.name,typeReference:s.typeReference,value:d})}finally{this.errors.unscope()}}return t}associateByWireValue({parameters:e,values:r,ignoreMissingParameters:t}){let n=[];for(let[i,s]of Object.entries(r)){this.errors.scope(i);try{let d=e.find(u=>u.name.wireValue===i);if(d==null){if(t)continue;this.errors.add({severity:p.Critical,message:this.newParameterNotRecognizedError(i).message});continue}n.push({name:d.name,typeReference:d.typeReference,value:s})}finally{this.errors.unscope()}}return n}getSingleFileValue({property:e,record:r}){let t=r[e.wireValue];if(t!=null){if(typeof t!="string"){this.errors.add({severity:p.Critical,message:`Expected file value to be a string, got ${typeof t}`});return}return t}}getFileArrayValues({property:e,record:r}){let t=r[e.wireValue];if(t==null)return;if(!Array.isArray(t)){this.errors.add({severity:p.Critical,message:`Expected file array value to be an array of strings, got ${typeof t}`});return}let n=[];for(let i of t){if(typeof i!="string"){this.errors.add({severity:p.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}n.push(i)}return n}getRecord(e){if(typeof e!="object"||Array.isArray(e)){this.errors.add({severity:p.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(e)?"array":typeof e}`});return}return e==null?{}:e}resolveNamedType({typeId:e}){let r=this._ir.types[e];if(r==null){this.errors.add({severity:p.Critical,message:`Type identified by "${e}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:r}){let t=this.getRecord(r);if(t==null)return;let n=e.discriminant.wireValue,i=t[n];if(i==null){this.errors.add({severity:p.Critical,message:this.newParameterNotRecognizedError(n).message});return}if(typeof i!="string"){this.errors.add({severity:p.Critical,message:`Expected discriminant value to be a string but got: ${typeof i}`});return}let s=e.types[i];if(s==null){this.errors.add({severity:p.Critical,message:`No type found for discriminant value "${i}"`});return}let P=t,{[n]:d}=P,u=A(P,[b(n)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:u}}resolveEndpointOrThrow(e){let r=this.httpEndpointReferenceParser.tryParse(e);if(r==null)throw new Error(`Failed to parse endpoint reference "${e}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocationOrThrow(e){let r=[];for(let t of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:t,parsedEndpoint:e})&&r.push(t);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${e.method} ${e.path}"`);return r}needsRequestParameter({request:e,inlinePathParameters:r,inlineFileProperties:t}){var n;return this.includePathParametersInWrappedRequest({request:e,inlinePathParameters:r})||e.queryParameters!=null&&e.queryParameters.length>0||e.headers!=null&&e.headers.length>0?!0:e.body!=null?this.includeRequestBodyInWrappedRequest({body:e.body,inlineFileProperties:t}):!((n=e.metadata)!=null&&n.onlyPathParameters)}includePathParametersInWrappedRequest({request:e,inlinePathParameters:r}){var t,n;return r&&((n=(t=e.metadata)==null?void 0:t.includePathParameters)!=null?n:!1)}isFileUploadRequestBody(e){switch(e.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:m(e)}}resolveEnvironmentName(e){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}case"multipleBaseUrls":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}default:m(r)}}isSingleEnvironmentID(e){return typeof e=="string"}isMultiEnvironmentValues(e){return typeof e=="object"}validateMultiEnvironmentUrlValues(e){if(this._ir.environments==null)return this.errors.add({severity:p.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:p.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let t=r.environments[0];if(t==null)return this.errors.add({severity:p.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let n=new Set(E(t.urls));for(let i of E(e))n.has(i)&&n.delete(i);return n.size>0?(this.errors.add({severity:p.Critical,message:`The provided environments are invalid; got: [${Object.keys(e).join(", ")}], expected: [${E(t.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:e}){if(typeof e!="number"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"number",value:e}).message});return}return e}getValueAsBoolean({value:e}){if(typeof e!="boolean"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"boolean",value:e}).message});return}return e}getValueAsString({value:e}){if(typeof e!="string"){this.errors.add({severity:p.Critical,message:this.newTypeMismatchError({expected:"string",value:e}).message});return}return e}isOptional(e){switch(e.type){case"nullable":return this.isOptional(e.value);case"optional":return!0;case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(e){switch(e.type){case"nullable":return!0;case"optional":return this.isNullable(e.value);case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:e,values:r}){return new Error(`Expected auth type ${e.type}, got ${r.type}`)}newParameterNotRecognizedError(e){return new Error(`"${e}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:e,value:r}){return new Error(`Expected ${e}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:e,inlineFileProperties:r}){switch(e.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r});default:m(e)}}includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:e})||r&&this.fileUploadHasFileProperties({fileUpload:e})}fileUploadHasBodyProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:m(r)}})}fileUploadHasFileProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:m(r)}})}isListTypeReference(e){return e.type==="optional"?this.isListTypeReference(e.value):e.type==="list"||e.type==="set"}parsedEndpointMatches({endpoint:e,parsedEndpoint:r}){return e.location.method===r.method&&e.location.path===r.path}};o();a();var x;(function(c){c.Concise="concise",c.Full="full"})(x||(x={}));o();a();var C={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};o();a();export{R as a,p as b,w as c,x as d,C as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-DVOWBIEL.js";import{a as i}from"./chunk-YL3JFOME.js";import{a as p}from"./chunk-IIP7VDG4.js";import{k as t,m as r}from"./chunk-2AZXIWKY.js";t();r();var a=class extends p{constructor({ir:e,config:n,options:s={}}){super(new i({ir:e,config:n,options:s}))}async generate(e,n={}){return super.generate(e,n)}generateSync(e,n={}){return super.generateSync(e,n)}createSnippetGenerator(e){return new o({context:e})}};export{a};
|