@fern-api/python-dynamic-snippets 5.3.4 → 5.3.6
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 +11 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,7 @@ ${l}`);this.isAtStartOfLine()&&(s=l+s),n&&(s+=`
|
|
|
17
17
|
`);if(s.length<=1){e.write(this.escapeString(s[0]??"")),e.write('"""');return}o&&e.writeNoIndent(`\\
|
|
18
18
|
`),s.forEach((w,v)=>{e.writeNoIndent(this.escapeString(w)),v===s.length-1?l&&e.writeNoIndent(`\\
|
|
19
19
|
`):e.writeNoIndent(`
|
|
20
|
-
`)}),e.writeNoIndent('"""')}escapeString(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/'/g,"\\'").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r")}writeUnknown({writer:e,value:n}){switch(typeof n){case"boolean":e.write(n?"True":"False");return;case"string":e.write(`"${this.escapeString(n)}"`);return;case"number":e.write(n.toString());return;case"object":if(n==null){e.write("None");return}if(Array.isArray(n)){this.writeUnknownArray({writer:e,value:n});return}this.writeUnknownObject({writer:e,value:n});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof n}`)}}writeUnknownArray({writer:e,value:n}){if(n.length===0){e.write("[]");return}e.write("["),n.forEach((o,l)=>{l>0&&e.write(", "),e.writeNode(p.unknown(o))}),e.write("]")}writeUnknownObject({writer:e,value:n}){let o=Object.entries(n);if(o.length===0){e.write("{}");return}e.write("{"),o.forEach(([l,s],w)=>{w>0&&e.write(", "),e.write(`"${l}": `),e.writeNode(p.unknown(s))}),e.write("}")}};function Sa({entries:p}){return p.filter(t=>!de.isNop(t.key)&&!de.isNop(t.value))}function Ba({entries:p}){return p.filter(t=>!de.isNop(t.value))}function Rt({values:p}){return p.filter(t=>!de.isNop(t))}function Pa(p){return new be(p)}function Ca(p){return new it(p)}function Fa(p){return new Le(p)}function ka(p){return new ue(p)}function La(p){return new Re(p)}function Ua(p){return new Ne(p)}function Ma(p){return new ee(p)}function Oa(p){return new fe(p)}function _a(p){return new pe(p)}function Va(p){return new ie(p)}function Da(p){return new Ae(p)}function $a(p){return new Se(p)}function ja(p){return new Be(p)}function Wa(p){return new ce(p)}function qa(p){return new Ee(p)}function Ga(p){return new Fe(p)}function za(p){return new le(p)}function Ha(p){return new Ce(p)}function Qa(p){return new ke(p)}f();m();d();var Ya="value",at=class{constructor({context:t}){g(this,"context");this.context=t}convert(t){if(t.value===null)return this.context.isNullable(t.typeReference)?y.TypeInstantiation.none():(this.context.errors.add({severity:C.Critical,message:"Expected non-null value, but got null"}),y.TypeInstantiation.nop());if(t.value===void 0)return y.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return this.convertLiteral({literalType:t.typeReference.value,value:t.value});case"map":return this.convertMap({map:t.typeReference,value:t.value});case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?y.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"optional":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"nullable":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"primitive":return this.convertPrimitive({primitive:t.typeReference.value,value:t.value,as:t.as});case"set":return this.convertSet({set:t.typeReference.value,value:t.value});case"unknown":return y.TypeInstantiation.unknown(t.value);default:B(t.typeReference)}}convertLiteral({literalType:t,value:e}){switch(t.type){case"boolean":{let n=this.context.getValueAsBoolean({value:e});return n==null?y.TypeInstantiation.nop():y.TypeInstantiation.bool(n)}case"string":{let n=this.context.getValueAsString({value:e});return n==null?y.TypeInstantiation.nop():y.TypeInstantiation.str(n)}default:B(t)}}convertList({list:t,value:e}){return Array.isArray(e)?y.TypeInstantiation.list(e.map((n,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:t,value:n})}finally{this.context.errors.unscope()}}),{multiline:!0}):(this.context.errors.add({severity:C.Critical,message:`Expected array but got: ${typeof e}`}),y.TypeInstantiation.nop())}convertSet({set:t,value:e}){return Array.isArray(e)?y.TypeInstantiation.list(e.map((n,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:t,value:n})}finally{this.context.errors.unscope()}}),{multiline:!0}):(this.context.errors.add({severity:C.Critical,message:`Expected array but got: ${typeof e}`}),y.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:C.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),y.TypeInstantiation.nop()):y.TypeInstantiation.dict(Object.entries(e).map(([n,o])=>{this.context.errors.scope(n);try{return{key:this.convert({typeReference:t.key,value:n,as:"key"}),value:this.convert({typeReference:t.value,value:o})}}finally{this.context.errors.unscope()}}),{multiline:!0})}convertNamed({named:t,value:e,as:n}){switch(t.type){case"alias":return this.convert({typeReference:t.typeReference,value:e,as:n});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:t,value:e});case"enum":return this.convertEnum({enum_:t,value:e});case"object":return this.convertObject({object_:t,value:e});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e});default:B(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let n=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(n==null)return y.TypeInstantiation.nop();let o=n.singleDiscriminatedUnionType,l=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:n,unionVariant:o});if(l==null)return y.TypeInstantiation.nop();let s=this.context.getDiscriminatedUnionVariantClassReference({unionDeclaration:t.declaration,discriminantValue:o.discriminantValue});return y.TypeInstantiation.reference(y.instantiateClass({classReference:s,arguments_:l.map(w=>y.methodArgument({name:w.name,value:w.value})),multiline:!0}))}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:t,unionVariant:e}){let n=this.getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e});switch(e.type){case"samePropertiesAsObject":{let o=this.context.resolveNamedType({typeId:e.typeId});if(o==null)return;if(o.type!=="object"){this.context.errors.add({severity:C.Critical,message:"Internal error; expected union value to be an object"});return}let l=this.convertObjectEntries({object_:o,value:t.value});return[...n,...l]}case"singleProperty":try{this.context.errors.scope(e.discriminantValue.wireValue);let o=this.context.getRecord(t.value);return o==null?[...n,{name:Ya,value:this.convert({typeReference:e.typeReference,value:t.value})}]:[...n,{name:this.context.getPropertyName(e.discriminantValue.name),value:this.convert({typeReference:e.typeReference,value:o[e.discriminantValue.wireValue]})}]}finally{this.context.errors.unscope()}case"noProperties":return n;default:B(e)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){return this.context.associateByWireValue({parameters:e.properties??[],values:this.context.getRecord(t.value)??{},ignoreMissingParameters:!0}).map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getPropertyName(o.name.name),value:this.convert(o)}}finally{this.context.errors.unscope()}})}convertObjectEntries({object_:t,value:e}){let n=this.context.getRecord(e)??{},o=this.context.associateByWireValue({parameters:t.properties,values:n}),l=new Set(Object.keys(n)),s=o.map(w=>{this.context.errors.scope(w.name.wireValue);try{return{name:this.context.getPropertyName(w.name.name),value:this.convert(w)}}finally{this.context.errors.unscope()}});for(let w of t.properties){if(l.has(w.name.wireValue)||this.context.isOptional(w.typeReference)||this.context.isNullable(w.typeReference))continue;let v=this.synthesizeDefaultValue(w.typeReference);y.TypeInstantiation.isNop(v)||s.push({name:this.context.getPropertyName(w.name.name),value:v})}return s}convertObject({object_:t,value:e}){let n=this.convertObjectEntries({object_:t,value:e}),o=this.context.getTypeClassReference(t.declaration);return y.TypeInstantiation.reference(y.instantiateClass({classReference:o,arguments_:n.map(l=>y.methodArgument({name:l.name,value:l.value})),multiline:!0}))}convertEnum({enum_:t,value:e}){let n=this.getEnumValue({enum_:t,value:e});if(n==null)return y.TypeInstantiation.nop();let o=this.context.customConfig.pydantic_config?.enum_type;if(o==="python_enums"||o==="forward_compatible_python_enums"){let l=this.context.getTypeClassReference(t.declaration),s=n.name.screamingSnakeCase.safeName;return y.TypeInstantiation.reference(y.accessAttribute({lhs:l,rhs:y.codeBlock(s)}))}return y.TypeInstantiation.str(n.wireValue)}getEnumValue({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:C.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let n=t.values.find(o=>o.wireValue===e);if(n==null){this.context.errors.add({severity:C.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return n}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let n=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});return n??y.TypeInstantiation.nop()}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let n of t.types){let o=this.context.errors.size();try{let l=this.convert({typeReference:n,value:e});if(y.TypeInstantiation.isNop(l)||this.context.errors.size()>o){this.context.errors.truncate(o);continue}return l}catch{this.context.errors.truncate(o);continue}}this.context.errors.add({severity:C.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof e}" value`})}synthesizeDefaultValue(t,e=new Set){switch(t.type){case"optional":case"nullable":return y.TypeInstantiation.nop();case"primitive":return this.synthesizeDefaultPrimitive(t.value);case"literal":return this.synthesizeDefaultLiteral(t.value);case"list":return y.TypeInstantiation.list([]);case"set":return y.TypeInstantiation.list([]);case"map":return y.TypeInstantiation.dict([]);case"named":{if(e.has(t.value))return y.TypeInstantiation.nop();let n=this.context.resolveNamedType({typeId:t.value});return n==null?y.TypeInstantiation.nop():this.synthesizeDefaultNamed({named:n,typeId:t.value,seen:e})}case"unknown":return y.TypeInstantiation.nop();default:B(t)}}synthesizeDefaultPrimitive(t){switch(t){case"STRING":case"BASE_64":case"BIG_INTEGER":return y.TypeInstantiation.str("string");case"INTEGER":case"LONG":case"UINT":case"UINT_64":return y.TypeInstantiation.int(1);case"FLOAT":case"DOUBLE":return y.TypeInstantiation.float(1.1);case"BOOLEAN":return y.TypeInstantiation.bool(!0);case"DATE":return y.TypeInstantiation.date("2024-01-15");case"DATE_TIME":case"DATE_TIME_RFC_2822":return y.TypeInstantiation.datetime("2024-01-15T09:30:00Z");case"UUID":return y.TypeInstantiation.uuid("d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32");default:B(t)}}synthesizeDefaultLiteral(t){switch(t.type){case"boolean":return y.TypeInstantiation.bool(t.value);case"string":return y.TypeInstantiation.str(t.value);default:B(t)}}synthesizeDefaultNamed({named:t,typeId:e,seen:n}){let o=new Set(n);switch(o.add(e),t.type){case"alias":return this.synthesizeDefaultValue(t.typeReference,o);case"enum":{let l=t.values[0];if(l==null)return y.TypeInstantiation.nop();let s=this.context.customConfig.pydantic_config?.enum_type;if(s==="python_enums"||s==="forward_compatible_python_enums"){let w=this.context.getTypeClassReference(t.declaration),v=l.name.screamingSnakeCase.safeName;return y.TypeInstantiation.reference(y.accessAttribute({lhs:w,rhs:y.codeBlock(v)}))}return y.TypeInstantiation.str(l.wireValue)}case"object":{let l=[];for(let w of t.properties){if(this.context.isOptional(w.typeReference)||this.context.isNullable(w.typeReference))continue;let v=this.synthesizeDefaultValue(w.typeReference,o);y.TypeInstantiation.isNop(v)||l.push({name:this.context.getPropertyName(w.name.name),value:v})}let s=this.context.getTypeClassReference(t.declaration);return y.TypeInstantiation.reference(y.instantiateClass({classReference:s,arguments_:l.map(w=>y.methodArgument({name:w.name,value:w.value})),multiline:!0}))}case"discriminatedUnion":case"undiscriminatedUnion":return y.TypeInstantiation.nop();default:B(t)}}convertPrimitive({primitive:t,value:e,as:n}){switch(t){case"INTEGER":case"LONG":case"UINT":case"UINT_64":{let o=this.getValueAsNumber({value:e,as:n});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.int(o)}case"FLOAT":case"DOUBLE":{let o=this.getValueAsNumber({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.float(o)}case"BOOLEAN":{let o=this.getValueAsBoolean({value:e,as:n});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.bool(o)}case"BASE_64":case"BIG_INTEGER":case"STRING":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.str(o)}case"UUID":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.uuid(o)}case"DATE":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.date(o)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.datetime(o)}default:B(t)}}getValueAsNumber({value:t,as:e}){let n=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:n})}getValueAsBoolean({value:t,as:e}){let n=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:n})}};f();m();d();var st=class{constructor({context:t}){g(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){let n={fileFields:[],bodyPropertyFields:[]},o=this.context.getRecord(e)??{};for(let l of t.properties)switch(l.type){case"file":{let s=this.getSingleFileProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.fileFields.push({name:this.context.getPropertyName(l.name),value:s});break}case"fileArray":{let s=this.getArrayFileProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.fileFields.push({name:this.context.getPropertyName(l.name),value:s});break}case"bodyProperty":{let s=this.getBodyProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.bodyPropertyFields.push({name:this.context.getPropertyName(l.name.name),value:s});break}default:B(l)}return n}getSingleFileProperty({property:t,record:e}){let n=this.context.getSingleFileValue({property:t,record:e});return n==null&&(n=`example_${t.wireValue??"file"}`),this.context.getFileFromString(n)}getArrayFileProperty({property:t,record:e}){let n=this.context.getFileArrayValues({property:t,record:e});if(n==null){let o=`example_${t.wireValue??"files"}`;return y.TypeInstantiation.list([this.context.getFileFromString(o)])}return y.TypeInstantiation.list(n.map(o=>this.context.getFileFromString(o)))}getBodyProperty({property:t,record:e}){let n=e[t.name.wireValue];return n==null?y.TypeInstantiation.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:n})}};var Za=["list","set"],ut=class p extends ze{constructor({ir:e,config:n}){super({ir:e,config:n});g(this,"ir");g(this,"customConfig");g(this,"dynamicTypeLiteralMapper");g(this,"filePropertyMapper");this.ir=e,this.customConfig=n.customConfig??{},this.dynamicTypeLiteralMapper=new at({context:this}),this.filePropertyMapper=new st({context:this})}clone(){return new p({ir:this.ir,config:this.config})}getClassName(e){let n=e.pascalCase.safeName,o=this.getRootClientClassName();return n===o?`${o}Model`:n}getTypedDictClassName(e){return`${this.getClassName(e)}Params`}getPropertyName(e){let n=e.snakeCase.safeName;return n.startsWith("_")?"f_"+n.substring(n.lastIndexOf("_")+1):n}getMethodName(e){return Za.includes(e.snakeCase.unsafeName)?e.snakeCase.unsafeName:e.snakeCase.safeName}getRootClientClassReference(){return y.reference({name:this.getRootClientClassName(),modulePath:this.getRootModulePath()})}getTypeClassReference(e){let n=this.getClassName(e.name),o=[...this.getRootModulePath(),...e.fernFilepath.allParts.map(l=>l.snakeCase.safeName)];return y.reference({name:n,modulePath:o})}getDiscriminatedUnionVariantClassReference({unionDeclaration:e,discriminantValue:n}){let o=this.getClassName(e.name),l=n.name.pascalCase.safeName,s=[...this.getRootModulePath(),...e.fernFilepath.allParts.map(w=>w.snakeCase.safeName)];return y.reference({name:`${o}_${l}`,modulePath:s})}useTypedDictRequests(){return this.customConfig.use_typeddict_requests===!0}getRootClientClassName(){return this.customConfig.client?.exported_class_name!=null?this.customConfig.client.exported_class_name:this.customConfig.client_class_name!=null?this.customConfig.client_class_name:this.customConfig.client?.class_name!=null?this.customConfig.client.class_name:this.pascalCase(this.config.organization)+this.pascalCase(this.config.workspaceName)}getEnvironmentClassName(){return`${this.getRootClientClassName()}Environment`}getEnvironmentTypeReferenceFromID(e){let n=this.resolveEnvironmentName(e);if(n!=null)return y.accessAttribute({lhs:this.getEnvironmentClassReference(),rhs:y.codeBlock(this.getEnvironmentEnumName(n))})}getEnvironmentClassReference(){return y.reference({name:this.getEnvironmentClassName(),modulePath:this.getEnvironmentModulePath()})}getEnvironmentEnumName(e){return e.screamingSnakeCase.safeName}isPrimitive(e){switch(e.type){case"primitive":return!0;case"optional":case"nullable":return this.isPrimitive(e.value);case"named":{let n=this.resolveNamedType({typeId:e.value});if(n==null)return!1;switch(n.type){case"alias":return this.isPrimitive(n.typeReference);case"discriminatedUnion":case"undiscriminatedUnion":case"object":case"enum":return!1;default:B(n)}break}case"list":case"set":case"map":case"literal":case"unknown":return!1;default:B(e)}}getFileFromString(e){return y.TypeInstantiation.str(e)}getRootModulePath(){if(this.customConfig.package_name!=null)return[this.customConfig.package_name];let e=this.cleanOrganizationName();return this.customConfig.use_api_name_in_package?[e,this.getApiName()]:[e]}getCoreModulePath(){return this.getRootModulePath().concat("core")}getEnvironmentModulePath(){return this.getRootModulePath().concat("environment")}shouldInlinePathParameters(){return!0}cleanOrganizationName(){return this.config.organization.replace(/[^a-zA-Z0-9]/g,"_")}getApiName(){return vt(this.config.workspaceName)}pascalCase(e){let n=It(e);return n.charAt(0).toUpperCase()+n.slice(1)}};f();m();d();var Ja={type:"primitive",value:"STRING"},Ka=["example"],li="client",Ue="request",pt=class{constructor({context:t}){g(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e}).toString()}generateSnippetSync({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e}).toString()}async generateSnippetAst({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e})}generateMethodCallSnippetAst({endpoint:t,request:e}){return this.callMethod({endpoint:t,snippet:e})}buildPythonFile({endpoint:t,snippet:e}){return y.file({path:Ka,statements:[this.constructClient({endpoint:t,snippet:e}),this.callMethod({endpoint:t,snippet:e})]})}constructClient({endpoint:t,snippet:e}){return y.assign({lhs:y.reference({name:li}),rhs:y.instantiateClass({classReference:this.context.getRootClientClassReference(),arguments_:this.getConstructorArgs({endpoint:t,snippet:e}).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})})}getConstructorArgs({endpoint:t,snippet:e}){let n=[],o=this.getConstructorEnvironmentArgs({baseUrl:e.baseURL,environment:e.environment});return o.length>0&&n.push(...o),t.auth!=null&&(e.auth!=null?n.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth})):this.context.errors.add({severity:C.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(Y.PathParameters),this.context.ir.pathParameters!=null&&n.push(...this.getPathParameters({namedParameters:this.context.ir.pathParameters,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(Y.Headers),this.context.ir.headers!=null&&e.headers!=null&&n.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),n}getConstructorEnvironmentArgs({baseUrl:t,environment:e}){let n=this.getEnvironmentValue({baseUrl:t,environment:e});return n==null?[]:e!=null&&this.context.isMultiEnvironmentValues(e)?[{name:"environment",value:n}]:[{name:this.getEnvironmentOptionName({environment:e}),value:n}]}getEnvironmentValue({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:C.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return y.TypeInstantiation.str(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let n=this.context.getEnvironmentTypeReferenceFromID(e);if(n==null){this.context.errors.add({severity:C.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return y.TypeInstantiation.reference(n)}if(this.context.isMultiEnvironmentValues(e))return this.context.validateMultiEnvironmentUrlValues(e)?y.TypeInstantiation.reference(y.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.entries(e).map(([n,o])=>({name:n,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Ja,value:o})})).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})):void 0}}getConstructorAuthArgs({auth:t,values:e}){switch(t.type){case"basic":return e.type!=="basic"?(this.addAuthMismatchError(t,e),[]):this.getConstructorBasicAuthArg({auth:t,values:e});case"bearer":return e.type!=="bearer"?(this.addAuthMismatchError(t,e),[]):this.getConstructorBearerAuthArgs({auth:t,values:e});case"header":return e.type!=="header"?(this.addAuthMismatchError(t,e),[]):this.getConstructorHeaderAuthArgs({auth:t,values:e});case"oauth":return e.type!=="oauth"?(this.addAuthMismatchError(t,e),[]):this.getConstructorOAuthArgs({auth:t,values:e});case"inferred":return e.type!=="inferred"?(this.addAuthMismatchError(t,e),[]):this.getConstructorInferredAuthArgs({auth:t,values:e});default:B(t)}}addAuthMismatchError(t,e){this.context.errors.add({severity:C.Critical,message:this.context.newAuthMismatchError({auth:t,values:e}).message})}addWarning(t){this.context.errors.add({severity:C.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),value:y.TypeInstantiation.str(e.username)},{name:this.context.getPropertyName(t.password),value:y.TypeInstantiation.str(e.password)}]}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),value:y.TypeInstantiation.str(e.token)}]}getConstructorHeaderAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t.header.typeReference,value:e.value})}]}getConstructorOAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.clientId),value:y.TypeInstantiation.str(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),value:y.TypeInstantiation.str(e.clientSecret)}]}getConstructorInferredAuthArgs({auth:t,values:e}){let n=t.parameters??[];if(n.length===0)return this.addWarning("Inferred auth scheme is missing parameters; cannot generate constructor arguments."),[];let o=e.values;if(o==null)return this.addWarning("Inferred auth values were not provided; cannot generate constructor arguments."),[];let l=[];for(let s of n){let w=s.name.wireValue;if(!Object.hasOwn(o,w)){this.addWarning(`Missing inferred auth value for ${w}`);continue}let v=o[w],A=this.context.dynamicTypeLiteralMapper.convert({typeReference:s.typeReference,value:v});y.TypeInstantiation.isNop(A)||l.push({name:this.context.getPropertyName(s.name.name),value:A})}return l}getConstructorHeaderArgs({headers:t,values:e}){let n=[];for(let o of t){let l=e[o.name.wireValue],s=this.getConstructorHeaderArg({header:o,value:l});s!=null&&n.push(s)}return n}getConstructorHeaderArg({header:t,value:e}){let n=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!y.TypeInstantiation.isNop(n))return{name:this.context.getPropertyName(t.name.name),value:n}}callMethod({endpoint:t,snippet:e}){return y.invokeMethod({on:y.reference({name:li}),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}).filter(n=>!y.TypeInstantiation.isNop(n.value)).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:B(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let n=[];this.context.errors.scope(Y.PathParameters);let o=[...this.context.ir.pathParameters??[],...t.pathParameters??[]],l=new Set;if(t.body!=null){let s=this.getBodyRequestArgs({body:t.body,value:e.requestBody});if(l=new Set(s.map(w=>w.name)),t.body.type==="typeReference"){let w=t.body.value;if(w.type==="named"){let v=this.context.resolveNamedType({typeId:w.value});if(v!=null&&v.type==="object")for(let A of v.properties)this.resolvesToLiteralType(A.typeReference)||l.add(this.context.getPropertyName(A.name.name))}}}if(o.length>0){let w=this.getPathParameters({namedParameters:o,snippet:e}).map(v=>l.has(v.name)?{...v,name:v.name+"_"}:v);n.push(...w)}return this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody),t.body!=null&&n.push(...this.getBodyRequestArgs({body:t.body,value:e.requestBody})),this.context.errors.unscope(),n}getBodyRequestArgs({body:t,value:e}){switch(t.type){case"bytes":return[{name:Ue,value:this.getBytesBodyRequestTypeInstantiation({value:e})}];case"typeReference":return this.getBodyRequestArgsForTypeReference({typeReference:t.value,value:e});default:B(t)}}getBodyRequestArgsForTypeReference({typeReference:t,value:e}){switch(t.type){case"named":{let n=this.context.resolveNamedType({typeId:t.value});return n==null?[]:this.getBodyRequestArgsForNamedTypeReference({typeReference:t,named:n,value:e})}case"nullable":case"optional":{let n=t.value;return n.type==="named"&&this.context.resolveNamedType({typeId:n.value})?.type==="object"?[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:n,value:e})}]:this.getBodyRequestArgsForTypeReference({typeReference:t.value,value:e})}case"list":case"map":case"set":case"literal":case"primitive":case"unknown":return[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:e})}];default:B(t)}}getBodyRequestArgsForNamedTypeReference({typeReference:t,named:e,value:n}){switch(e.type){case"alias":return this.getBodyRequestArgsForTypeReference({typeReference:e.typeReference,value:n});case"enum":case"discriminatedUnion":case"undiscriminatedUnion":return[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:n})}];case"object":return this.context.customConfig.inline_request_params===!1?[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:n})}]:this.context.associateByWireValue({parameters:e.properties,values:this.context.getRecord(n)??{}}).filter(s=>!this.resolvesToLiteralType(s.typeReference)).map(s=>({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)}));default:B(e)}}resolvesToLiteralType(t){switch(t.type){case"literal":return!0;case"optional":case"nullable":return this.resolvesToLiteralType(t.value);case"named":{let e=this.context.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.resolvesToLiteralType(e.typeReference):!1}case"list":case"map":case"set":case"primitive":case"unknown":return!1;default:B(t)}}getBodyRequestArgsForBytes({body:t,value:e}){let n=this.getBytesBodyRequestTypeInstantiation({value:e});return y.TypeInstantiation.isNop(n)?[]:[{name:Ue,value:n}]}getBytesBodyRequestTypeInstantiation({value:t}){return typeof t!="string"?(this.context.errors.add({severity:C.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),y.TypeInstantiation.nop()):y.TypeInstantiation.bytes(t)}getBodyPropertyNamesForInlinedRequest(t){if(t.body==null)return new Set;switch(t.body.type){case"referenced":{let e=t.body.bodyType;if(e.type!=="typeReference")return new Set;let n=e.value;if(n.type!=="named")return new Set;let o=this.context.resolveNamedType({typeId:n.value});if(o==null||o.type!=="object")return new Set;let l=new Set;for(let s of o.properties)this.resolvesToLiteralType(s.typeReference)||l.add(this.context.getPropertyName(s.name.name));return l}case"properties":return new Set(t.body.value.filter(e=>!this.resolvesToLiteralType(e.typeReference)).map(e=>this.context.getPropertyName(e.name.name)));case"fileUpload":return new Set(t.body.properties.filter(e=>e.type==="bodyProperty").map(e=>this.context.getPropertyName(e.name.name)));default:B(t.body)}}getMethodArgsForInlinedRequest({request:t,snippet:e}){let n=[],o=this.context.shouldInlinePathParameters();this.context.errors.scope(Y.PathParameters);let l=[];t.pathParameters!=null&&l.push(...this.getPathParameters({namedParameters:t.pathParameters,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody);let s=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope();let w=this.getBodyPropertyNamesForInlinedRequest(t),v=l.map(A=>w.has(A.name)?{...A,name:`${A.name}_`}:A);return this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:o})||n.push(...v),this.context.needsRequestParameter({request:t,inlinePathParameters:o,inlineFileProperties:!0})&&n.push(...this.getInlinedRequestArgs({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:o})?v:[],filePropertyInfo:s})),n}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArgs({request:t,snippet:e,pathParameterFields:n,filePropertyInfo:o}){this.context.errors.scope(Y.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(Y.Headers);let v=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody);let A=t.body!=null?this.getInlinedRequestBodyObjectFields({body:t.body,value:e.requestBody,filePropertyInfo:o}):[];return this.context.errors.unscope(),[...n,...s,...v,...A]}getInlinedRequestBodyObjectFields({body:t,value:e,filePropertyInfo:n}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:t.value,value:e});case"referenced":return this.getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e});case"fileUpload":return this.getFileUploadRequestBodyObjectFields({filePropertyInfo:n});default:B(t)}}getFileUploadRequestBodyObjectFields({filePropertyInfo:t}){return[...t.fileFields,...t.bodyPropertyFields]}getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e}){let n=t.bodyType;switch(n.type){case"bytes":return this.getBodyRequestArgsForBytes({body:t,value:e});case"typeReference":return this.getBodyRequestArgsForTypeReference({typeReference:n.value,value:e});default:B(n)}}getInlinedRequestBodyPropertyObjectFields({parameters:t,value:e}){let n=[],l=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}}).filter(s=>!this.resolvesToLiteralType(s.typeReference));for(let s of l)n.push({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)});return n}getPathParameters({namedParameters:t,snippet:e}){let n=[],o=t.filter(s=>!this.resolvesToLiteralType(s.typeReference)),l=this.context.associateByWireValue({parameters:o,values:e.pathParameters??{},ignoreMissingParameters:!0});for(let s of l)n.push({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)});return n}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getMethodName(e)).join(".")}.${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getEnvironmentOptionName({environment:t}){return t!=null?"environment":"base_url"}};var lt=class extends We{constructor({ir:t,config:e}){super(new ut({ir:t,config:e}))}async generate(t,e={}){return super.generate(t,e)}generateSync(t,e={}){return super.generateSync(t,e)}async generateSnippetAst(t,e={}){return super.generateSnippetAst(t,e)}generateMethodCallSnippetAst({request:t,options:e={}}){let n=this.resolveEndpointsForMethodCall({request:t,options:e});if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let o;for(let l of n){let s=this.context.clone(),w=this.createSnippetGenerator(s);try{return w.generateMethodCallSnippetAst({endpoint:l,request:t})}catch(v){o=v}}throw o??new Error(`Failed to generate method call snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}resolveEndpointsForMethodCall({request:t,options:e}){if(e.endpointId!=null){let n=this.context.resolveEndpointById(e.endpointId);if(n==null)throw new Error(`No endpoint found with ID "${e.endpointId}"`);return[n]}return this.context.resolveEndpointLocationOrThrow(t.endpoint)}createSnippetGenerator(t){return new pt({context:t})}};0&&(module.exports={DynamicSnippetsGenerator});
|
|
20
|
+
`)}),e.writeNoIndent('"""')}escapeString(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/'/g,"\\'").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r")}writeUnknown({writer:e,value:n}){switch(typeof n){case"boolean":e.write(n?"True":"False");return;case"string":e.write(`"${this.escapeString(n)}"`);return;case"number":e.write(n.toString());return;case"object":if(n==null){e.write("None");return}if(Array.isArray(n)){this.writeUnknownArray({writer:e,value:n});return}this.writeUnknownObject({writer:e,value:n});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof n}`)}}writeUnknownArray({writer:e,value:n}){if(n.length===0){e.write("[]");return}e.write("["),n.forEach((o,l)=>{l>0&&e.write(", "),e.writeNode(p.unknown(o))}),e.write("]")}writeUnknownObject({writer:e,value:n}){let o=Object.entries(n);if(o.length===0){e.write("{}");return}e.write("{"),o.forEach(([l,s],w)=>{w>0&&e.write(", "),e.write(`"${l}": `),e.writeNode(p.unknown(s))}),e.write("}")}};function Sa({entries:p}){return p.filter(t=>!de.isNop(t.key)&&!de.isNop(t.value))}function Ba({entries:p}){return p.filter(t=>!de.isNop(t.value))}function Rt({values:p}){return p.filter(t=>!de.isNop(t))}function Pa(p){return new be(p)}function Ca(p){return new it(p)}function Fa(p){return new Le(p)}function ka(p){return new ue(p)}function La(p){return new Re(p)}function Ua(p){return new Ne(p)}function Ma(p){return new ee(p)}function Oa(p){return new fe(p)}function _a(p){return new pe(p)}function Va(p){return new ie(p)}function Da(p){return new Ae(p)}function $a(p){return new Se(p)}function ja(p){return new Be(p)}function Wa(p){return new ce(p)}function qa(p){return new Ee(p)}function Ga(p){return new Fe(p)}function za(p){return new le(p)}function Ha(p){return new Ce(p)}function Qa(p){return new ke(p)}f();m();d();var Ya="value",at=class{constructor({context:t}){g(this,"context");this.context=t}convert(t){if(t.value===null)return this.context.isNullable(t.typeReference)?y.TypeInstantiation.none():(this.context.errors.add({severity:C.Critical,message:"Expected non-null value, but got null"}),y.TypeInstantiation.nop());if(t.value===void 0)return y.TypeInstantiation.nop();switch(t.typeReference.type){case"list":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return this.convertLiteral({literalType:t.typeReference.value,value:t.value});case"map":return this.convertMap({map:t.typeReference,value:t.value});case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?y.TypeInstantiation.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"optional":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"nullable":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"primitive":return this.convertPrimitive({primitive:t.typeReference.value,value:t.value,as:t.as});case"set":return this.convertSet({set:t.typeReference.value,value:t.value});case"unknown":return y.TypeInstantiation.unknown(t.value);default:B(t.typeReference)}}convertLiteral({literalType:t,value:e}){switch(t.type){case"boolean":{let n=this.context.getValueAsBoolean({value:e});return n==null?y.TypeInstantiation.nop():y.TypeInstantiation.bool(n)}case"string":{let n=this.context.getValueAsString({value:e});return n==null?y.TypeInstantiation.nop():y.TypeInstantiation.str(n)}default:B(t)}}convertList({list:t,value:e}){return Array.isArray(e)?y.TypeInstantiation.list(e.map((n,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:t,value:n})}finally{this.context.errors.unscope()}}),{multiline:!0}):(this.context.errors.add({severity:C.Critical,message:`Expected array but got: ${typeof e}`}),y.TypeInstantiation.nop())}convertSet({set:t,value:e}){return Array.isArray(e)?y.TypeInstantiation.list(e.map((n,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:t,value:n})}finally{this.context.errors.unscope()}}),{multiline:!0}):(this.context.errors.add({severity:C.Critical,message:`Expected array but got: ${typeof e}`}),y.TypeInstantiation.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:C.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),y.TypeInstantiation.nop()):y.TypeInstantiation.dict(Object.entries(e).map(([n,o])=>{this.context.errors.scope(n);try{return{key:this.convert({typeReference:t.key,value:n,as:"key"}),value:this.convert({typeReference:t.value,value:o})}}finally{this.context.errors.unscope()}}),{multiline:!0})}convertNamed({named:t,value:e,as:n}){switch(t.type){case"alias":return this.convert({typeReference:t.typeReference,value:e,as:n});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:t,value:e});case"enum":return this.convertEnum({enum_:t,value:e});case"object":return this.convertObject({object_:t,value:e});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e});default:B(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let n=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(n==null)return y.TypeInstantiation.nop();let o=n.singleDiscriminatedUnionType,l=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:n,unionVariant:o});if(l==null)return y.TypeInstantiation.nop();let s=this.context.getDiscriminatedUnionVariantClassReference({unionDeclaration:t.declaration,discriminantValue:o.discriminantValue});return y.TypeInstantiation.reference(y.instantiateClass({classReference:s,arguments_:l.map(w=>y.methodArgument({name:w.name,value:w.value})),multiline:!0}))}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:t,unionVariant:e}){let n=this.getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e});switch(e.type){case"samePropertiesAsObject":{let o=this.context.resolveNamedType({typeId:e.typeId});if(o==null)return;if(o.type!=="object"){this.context.errors.add({severity:C.Critical,message:"Internal error; expected union value to be an object"});return}let l=this.convertObjectEntries({object_:o,value:t.value});return[...n,...l]}case"singleProperty":try{this.context.errors.scope(e.discriminantValue.wireValue);let o=this.context.getRecord(t.value);return o==null?[...n,{name:Ya,value:this.convert({typeReference:e.typeReference,value:t.value})}]:[...n,{name:this.context.getPropertyName(e.discriminantValue.name),value:this.convert({typeReference:e.typeReference,value:o[e.discriminantValue.wireValue]})}]}finally{this.context.errors.unscope()}case"noProperties":return n;default:B(e)}}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){return this.context.associateByWireValue({parameters:e.properties??[],values:this.context.getRecord(t.value)??{},ignoreMissingParameters:!0}).map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getPropertyName(o.name.name),value:this.convert(o)}}finally{this.context.errors.unscope()}})}convertObjectEntries({object_:t,value:e}){let n=this.context.getRecord(e)??{},o=this.context.associateByWireValue({parameters:t.properties,values:n}),l=new Set(Object.keys(n)),s=o.map(w=>{this.context.errors.scope(w.name.wireValue);try{return{name:this.context.getPropertyName(w.name.name),value:this.convert(w)}}finally{this.context.errors.unscope()}});for(let w of t.properties){if(l.has(w.name.wireValue)||this.context.isOptional(w.typeReference)||this.context.isNullable(w.typeReference))continue;let v=this.synthesizeDefaultValue(w.typeReference);y.TypeInstantiation.isNop(v)||s.push({name:this.context.getPropertyName(w.name.name),value:v})}return s.filter(w=>!y.TypeInstantiation.isNop(w.value))}convertObject({object_:t,value:e}){let n=this.convertObjectEntries({object_:t,value:e}),o=this.context.getTypeClassReference(t.declaration);return y.TypeInstantiation.reference(y.instantiateClass({classReference:o,arguments_:n.map(l=>y.methodArgument({name:l.name,value:l.value})),multiline:!0}))}convertEnum({enum_:t,value:e}){let n=this.getEnumValue({enum_:t,value:e});if(n==null)return y.TypeInstantiation.nop();let o=this.context.customConfig.pydantic_config?.enum_type;if(o==="python_enums"||o==="forward_compatible_python_enums"){let l=this.context.getTypeClassReference(t.declaration),s=n.name.screamingSnakeCase.safeName;return y.TypeInstantiation.reference(y.accessAttribute({lhs:l,rhs:y.codeBlock(s)}))}return y.TypeInstantiation.str(n.wireValue)}getEnumValue({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:C.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let n=t.values.find(o=>o.wireValue===e);if(n==null){this.context.errors.add({severity:C.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return n}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let n=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});return n??y.TypeInstantiation.nop()}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let n of t.types){let o=this.context.errors.size();try{let l=this.convert({typeReference:n,value:e});if(y.TypeInstantiation.isNop(l)||this.context.errors.size()>o){this.context.errors.truncate(o);continue}return l}catch{this.context.errors.truncate(o);continue}}this.context.errors.add({severity:C.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof e}" value`})}synthesizeDefaultValue(t,e=new Set){switch(t.type){case"optional":case"nullable":return y.TypeInstantiation.nop();case"primitive":return this.synthesizeDefaultPrimitive(t.value);case"literal":return this.synthesizeDefaultLiteral(t.value);case"list":return y.TypeInstantiation.list([]);case"set":return y.TypeInstantiation.list([]);case"map":return y.TypeInstantiation.dict([]);case"named":{if(e.has(t.value))return y.TypeInstantiation.nop();let n=this.context.resolveNamedType({typeId:t.value});return n==null?y.TypeInstantiation.nop():this.synthesizeDefaultNamed({named:n,typeId:t.value,seen:e})}case"unknown":return y.TypeInstantiation.nop();default:B(t)}}synthesizeDefaultPrimitive(t){switch(t){case"STRING":case"BASE_64":case"BIG_INTEGER":return y.TypeInstantiation.str("string");case"INTEGER":case"LONG":case"UINT":case"UINT_64":return y.TypeInstantiation.int(1);case"FLOAT":case"DOUBLE":return y.TypeInstantiation.float(1.1);case"BOOLEAN":return y.TypeInstantiation.bool(!0);case"DATE":return y.TypeInstantiation.date("2024-01-15");case"DATE_TIME":case"DATE_TIME_RFC_2822":return y.TypeInstantiation.datetime("2024-01-15T09:30:00Z");case"UUID":return y.TypeInstantiation.uuid("d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32");default:B(t)}}synthesizeDefaultLiteral(t){switch(t.type){case"boolean":return y.TypeInstantiation.bool(t.value);case"string":return y.TypeInstantiation.str(t.value);default:B(t)}}synthesizeDefaultNamed({named:t,typeId:e,seen:n}){let o=new Set(n);switch(o.add(e),t.type){case"alias":return this.synthesizeDefaultValue(t.typeReference,o);case"enum":{let l=t.values[0];if(l==null)return y.TypeInstantiation.nop();let s=this.context.customConfig.pydantic_config?.enum_type;if(s==="python_enums"||s==="forward_compatible_python_enums"){let w=this.context.getTypeClassReference(t.declaration),v=l.name.screamingSnakeCase.safeName;return y.TypeInstantiation.reference(y.accessAttribute({lhs:w,rhs:y.codeBlock(v)}))}return y.TypeInstantiation.str(l.wireValue)}case"object":{let l=[];for(let w of t.properties){if(this.context.isOptional(w.typeReference)||this.context.isNullable(w.typeReference))continue;let v=this.synthesizeDefaultValue(w.typeReference,o);y.TypeInstantiation.isNop(v)||l.push({name:this.context.getPropertyName(w.name.name),value:v})}let s=this.context.getTypeClassReference(t.declaration);return y.TypeInstantiation.reference(y.instantiateClass({classReference:s,arguments_:l.map(w=>y.methodArgument({name:w.name,value:w.value})),multiline:!0}))}case"discriminatedUnion":case"undiscriminatedUnion":return y.TypeInstantiation.nop();default:B(t)}}convertPrimitive({primitive:t,value:e,as:n}){switch(t){case"INTEGER":case"LONG":case"UINT":case"UINT_64":{let o=this.getValueAsNumber({value:e,as:n});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.int(o)}case"FLOAT":case"DOUBLE":{let o=this.getValueAsNumber({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.float(o)}case"BOOLEAN":{let o=this.getValueAsBoolean({value:e,as:n});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.bool(o)}case"BASE_64":case"BIG_INTEGER":case"STRING":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.str(o)}case"UUID":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.uuid(o)}case"DATE":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.date(o)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let o=this.context.getValueAsString({value:e});return o==null?y.TypeInstantiation.nop():y.TypeInstantiation.datetime(o)}default:B(t)}}getValueAsNumber({value:t,as:e}){let n=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:n})}getValueAsBoolean({value:t,as:e}){let n=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:n})}};f();m();d();var st=class{constructor({context:t}){g(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){let n={fileFields:[],bodyPropertyFields:[]},o=this.context.getRecord(e)??{};for(let l of t.properties)switch(l.type){case"file":{let s=this.getSingleFileProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.fileFields.push({name:this.context.getPropertyName(l.name),value:s});break}case"fileArray":{let s=this.getArrayFileProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.fileFields.push({name:this.context.getPropertyName(l.name),value:s});break}case"bodyProperty":{let s=this.getBodyProperty({property:l,record:o});if(y.TypeInstantiation.isNop(s))break;n.bodyPropertyFields.push({name:this.context.getPropertyName(l.name.name),value:s});break}default:B(l)}return n}getSingleFileProperty({property:t,record:e}){let n=this.context.getSingleFileValue({property:t,record:e});return n==null&&(n=`example_${t.wireValue??"file"}`),this.context.getFileFromString(n)}getArrayFileProperty({property:t,record:e}){let n=this.context.getFileArrayValues({property:t,record:e});if(n==null){let o=`example_${t.wireValue??"files"}`;return y.TypeInstantiation.list([this.context.getFileFromString(o)])}return y.TypeInstantiation.list(n.map(o=>this.context.getFileFromString(o)))}getBodyProperty({property:t,record:e}){let n=e[t.name.wireValue];return n==null?y.TypeInstantiation.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:n})}};var Za=["list","set"],ut=class p extends ze{constructor({ir:e,config:n}){super({ir:e,config:n});g(this,"ir");g(this,"customConfig");g(this,"dynamicTypeLiteralMapper");g(this,"filePropertyMapper");this.ir=e,this.customConfig=n.customConfig??{},this.dynamicTypeLiteralMapper=new at({context:this}),this.filePropertyMapper=new st({context:this})}clone(){return new p({ir:this.ir,config:this.config})}getClassName(e){let n=e.pascalCase.safeName,o=this.getRootClientClassName();return n===o?`${o}Model`:n}getTypedDictClassName(e){return`${this.getClassName(e)}Params`}getPropertyName(e){let n=e.snakeCase.safeName;return n.startsWith("_")?"f_"+n.substring(n.lastIndexOf("_")+1):n}getMethodName(e){return Za.includes(e.snakeCase.unsafeName)?e.snakeCase.unsafeName:e.snakeCase.safeName}getRootClientClassReference(){return y.reference({name:this.getRootClientClassName(),modulePath:this.getRootModulePath()})}getTypeClassReference(e){let n=this.getClassName(e.name),o=[...this.getRootModulePath(),...e.fernFilepath.allParts.map(l=>l.snakeCase.safeName)];return y.reference({name:n,modulePath:o})}getDiscriminatedUnionVariantClassReference({unionDeclaration:e,discriminantValue:n}){let o=this.getClassName(e.name),l=n.name.pascalCase.safeName,s=[...this.getRootModulePath(),...e.fernFilepath.allParts.map(w=>w.snakeCase.safeName)];return y.reference({name:`${o}_${l}`,modulePath:s})}useTypedDictRequests(){return this.customConfig.use_typeddict_requests===!0}getRootClientClassName(){return this.customConfig.client?.exported_class_name!=null?this.customConfig.client.exported_class_name:this.customConfig.client_class_name!=null?this.customConfig.client_class_name:this.customConfig.client?.class_name!=null?this.customConfig.client.class_name:this.pascalCase(this.config.organization)+this.pascalCase(this.config.workspaceName)}getEnvironmentClassName(){return`${this.getRootClientClassName()}Environment`}getEnvironmentTypeReferenceFromID(e){let n=this.resolveEnvironmentName(e);if(n!=null)return y.accessAttribute({lhs:this.getEnvironmentClassReference(),rhs:y.codeBlock(this.getEnvironmentEnumName(n))})}getEnvironmentClassReference(){return y.reference({name:this.getEnvironmentClassName(),modulePath:this.getEnvironmentModulePath()})}getEnvironmentEnumName(e){return e.screamingSnakeCase.safeName}isPrimitive(e){switch(e.type){case"primitive":return!0;case"optional":case"nullable":return this.isPrimitive(e.value);case"named":{let n=this.resolveNamedType({typeId:e.value});if(n==null)return!1;switch(n.type){case"alias":return this.isPrimitive(n.typeReference);case"discriminatedUnion":case"undiscriminatedUnion":case"object":case"enum":return!1;default:B(n)}break}case"list":case"set":case"map":case"literal":case"unknown":return!1;default:B(e)}}getFileFromString(e){return y.TypeInstantiation.str(e)}getRootModulePath(){if(this.customConfig.package_name!=null)return[this.customConfig.package_name];let e=this.cleanOrganizationName();if(this.customConfig.use_api_name_in_package)return[e,this.getApiName()];if(this.customConfig.package_path!=null){let n=this.customConfig.package_path.replace(/\//g,".").split(".");return[e,...n]}return[e]}getCoreModulePath(){return this.getRootModulePath().concat("core")}getEnvironmentModulePath(){return this.getRootModulePath().concat("environment")}shouldInlinePathParameters(){return!0}cleanOrganizationName(){return this.config.organization.replace(/[^a-zA-Z0-9]/g,"_")}getApiName(){return vt(this.config.workspaceName)}pascalCase(e){let n=It(e);return n.charAt(0).toUpperCase()+n.slice(1)}};f();m();d();var Ja={type:"primitive",value:"STRING"},Ka=["example"],li="client",Ue="request",pt=class{constructor({context:t}){g(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e}).toString()}generateSnippetSync({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e}).toString()}async generateSnippetAst({endpoint:t,request:e}){return this.buildPythonFile({endpoint:t,snippet:e})}generateMethodCallSnippetAst({endpoint:t,request:e}){return this.callMethod({endpoint:t,snippet:e})}buildPythonFile({endpoint:t,snippet:e}){return y.file({path:Ka,statements:[this.constructClient({endpoint:t,snippet:e}),this.callMethod({endpoint:t,snippet:e})]})}constructClient({endpoint:t,snippet:e}){return y.assign({lhs:y.reference({name:li}),rhs:y.instantiateClass({classReference:this.context.getRootClientClassReference(),arguments_:this.getConstructorArgs({endpoint:t,snippet:e}).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})})}getConstructorArgs({endpoint:t,snippet:e}){let n=[],o=this.getConstructorEnvironmentArgs({baseUrl:e.baseURL,environment:e.environment});return o.length>0&&n.push(...o),t.auth!=null&&(e.auth!=null?n.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth})):this.context.errors.add({severity:C.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(Y.PathParameters),this.context.ir.pathParameters!=null&&n.push(...this.getPathParameters({namedParameters:this.context.ir.pathParameters,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(Y.Headers),this.context.ir.headers!=null&&e.headers!=null&&n.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),n}getConstructorEnvironmentArgs({baseUrl:t,environment:e}){let n=this.getEnvironmentValue({baseUrl:t,environment:e});return n==null?[]:e!=null&&this.context.isMultiEnvironmentValues(e)?[{name:"environment",value:n}]:[{name:this.getEnvironmentOptionName({environment:e}),value:n}]}getEnvironmentValue({baseUrl:t,environment:e}){if(t!=null&&e!=null){this.context.errors.add({severity:C.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(t!=null)return y.TypeInstantiation.str(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let n=this.context.getEnvironmentTypeReferenceFromID(e);if(n==null){this.context.errors.add({severity:C.Warning,message:`Environment ${JSON.stringify(e)} was not found`});return}return y.TypeInstantiation.reference(n)}if(this.context.isMultiEnvironmentValues(e))return this.context.validateMultiEnvironmentUrlValues(e)?y.TypeInstantiation.reference(y.instantiateClass({classReference:this.context.getEnvironmentClassReference(),arguments_:Object.entries(e).map(([n,o])=>({name:n,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Ja,value:o})})).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})):void 0}}getConstructorAuthArgs({auth:t,values:e}){switch(t.type){case"basic":return e.type!=="basic"?(this.addAuthMismatchError(t,e),[]):this.getConstructorBasicAuthArg({auth:t,values:e});case"bearer":return e.type!=="bearer"?(this.addAuthMismatchError(t,e),[]):this.getConstructorBearerAuthArgs({auth:t,values:e});case"header":return e.type!=="header"?(this.addAuthMismatchError(t,e),[]):this.getConstructorHeaderAuthArgs({auth:t,values:e});case"oauth":return e.type!=="oauth"?(this.addAuthMismatchError(t,e),[]):this.getConstructorOAuthArgs({auth:t,values:e});case"inferred":return e.type!=="inferred"?(this.addAuthMismatchError(t,e),[]):this.getConstructorInferredAuthArgs({auth:t,values:e});default:B(t)}}addAuthMismatchError(t,e){this.context.errors.add({severity:C.Critical,message:this.context.newAuthMismatchError({auth:t,values:e}).message})}addWarning(t){this.context.errors.add({severity:C.Warning,message:t})}getConstructorBasicAuthArg({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),value:y.TypeInstantiation.str(e.username)},{name:this.context.getPropertyName(t.password),value:y.TypeInstantiation.str(e.password)}]}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),value:y.TypeInstantiation.str(e.token)}]}getConstructorHeaderAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t.header.typeReference,value:e.value})}]}getConstructorOAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.clientId),value:y.TypeInstantiation.str(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),value:y.TypeInstantiation.str(e.clientSecret)}]}getConstructorInferredAuthArgs({auth:t,values:e}){let n=t.parameters??[];if(n.length===0)return this.addWarning("Inferred auth scheme is missing parameters; cannot generate constructor arguments."),[];let o=e.values;if(o==null)return this.addWarning("Inferred auth values were not provided; cannot generate constructor arguments."),[];let l=[];for(let s of n){let w=s.name.wireValue;if(!Object.hasOwn(o,w)){this.addWarning(`Missing inferred auth value for ${w}`);continue}let v=o[w],A=this.context.dynamicTypeLiteralMapper.convert({typeReference:s.typeReference,value:v});y.TypeInstantiation.isNop(A)||l.push({name:this.context.getPropertyName(s.name.name),value:A})}return l}getConstructorHeaderArgs({headers:t,values:e}){let n=[];for(let o of t){let l=e[o.name.wireValue],s=this.getConstructorHeaderArg({header:o,value:l});s!=null&&n.push(s)}return n}getConstructorHeaderArg({header:t,value:e}){let n=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!y.TypeInstantiation.isNop(n))return{name:this.context.getPropertyName(t.name.name),value:n}}callMethod({endpoint:t,snippet:e}){return y.invokeMethod({on:y.reference({name:li}),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}).filter(n=>!y.TypeInstantiation.isNop(n.value)).map(n=>y.methodArgument({name:n.name,value:n.value})),multiline:!0})}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:B(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let n=[];this.context.errors.scope(Y.PathParameters);let o=[...this.context.ir.pathParameters??[],...t.pathParameters??[]],l=new Set;if(t.body!=null){let s=this.getBodyRequestArgs({body:t.body,value:e.requestBody});if(l=new Set(s.map(w=>w.name)),t.body.type==="typeReference"){let w=t.body.value;if(w.type==="named"){let v=this.context.resolveNamedType({typeId:w.value});if(v!=null&&v.type==="object")for(let A of v.properties)this.resolvesToLiteralType(A.typeReference)||l.add(this.context.getPropertyName(A.name.name))}}}if(o.length>0){let w=this.getPathParameters({namedParameters:o,snippet:e}).map(v=>l.has(v.name)?{...v,name:v.name+"_"}:v);n.push(...w)}return this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody),t.body!=null&&n.push(...this.getBodyRequestArgs({body:t.body,value:e.requestBody})),this.context.errors.unscope(),n}getBodyRequestArgs({body:t,value:e}){switch(t.type){case"bytes":return[{name:Ue,value:this.getBytesBodyRequestTypeInstantiation({value:e})}];case"typeReference":return this.getBodyRequestArgsForTypeReference({typeReference:t.value,value:e});default:B(t)}}getBodyRequestArgsForTypeReference({typeReference:t,value:e}){switch(t.type){case"named":{let n=this.context.resolveNamedType({typeId:t.value});return n==null?[]:this.getBodyRequestArgsForNamedTypeReference({typeReference:t,named:n,value:e})}case"nullable":case"optional":{let n=t.value;return n.type==="named"&&this.context.resolveNamedType({typeId:n.value})?.type==="object"?[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:n,value:e})}]:this.getBodyRequestArgsForTypeReference({typeReference:t.value,value:e})}case"list":case"map":case"set":case"literal":case"primitive":case"unknown":return[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:e})}];default:B(t)}}getBodyRequestArgsForNamedTypeReference({typeReference:t,named:e,value:n}){switch(e.type){case"alias":return this.getBodyRequestArgsForTypeReference({typeReference:e.typeReference,value:n});case"enum":case"discriminatedUnion":case"undiscriminatedUnion":return[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:n})}];case"object":return this.context.customConfig.inline_request_params===!1?[{name:Ue,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:t,value:n})}]:this.context.associateByWireValue({parameters:e.properties,values:this.context.getRecord(n)??{}}).filter(s=>!this.resolvesToLiteralType(s.typeReference)).map(s=>({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)}));default:B(e)}}resolvesToLiteralType(t){switch(t.type){case"literal":return!0;case"optional":case"nullable":return this.resolvesToLiteralType(t.value);case"named":{let e=this.context.resolveNamedType({typeId:t.value});return e==null?!1:e.type==="alias"?this.resolvesToLiteralType(e.typeReference):!1}case"list":case"map":case"set":case"primitive":case"unknown":return!1;default:B(t)}}getBodyRequestArgsForBytes({body:t,value:e}){let n=this.getBytesBodyRequestTypeInstantiation({value:e});return y.TypeInstantiation.isNop(n)?[]:[{name:Ue,value:n}]}getBytesBodyRequestTypeInstantiation({value:t}){return typeof t!="string"?(this.context.errors.add({severity:C.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),y.TypeInstantiation.nop()):y.TypeInstantiation.bytes(t)}getBodyPropertyNamesForInlinedRequest(t){if(t.body==null)return new Set;switch(t.body.type){case"referenced":{let e=t.body.bodyType;if(e.type!=="typeReference")return new Set;let n=e.value;if(n.type!=="named")return new Set;let o=this.context.resolveNamedType({typeId:n.value});if(o==null||o.type!=="object")return new Set;let l=new Set;for(let s of o.properties)this.resolvesToLiteralType(s.typeReference)||l.add(this.context.getPropertyName(s.name.name));return l}case"properties":return new Set(t.body.value.filter(e=>!this.resolvesToLiteralType(e.typeReference)).map(e=>this.context.getPropertyName(e.name.name)));case"fileUpload":return new Set(t.body.properties.filter(e=>e.type==="bodyProperty").map(e=>this.context.getPropertyName(e.name.name)));default:B(t.body)}}getMethodArgsForInlinedRequest({request:t,snippet:e}){let n=[],o=this.context.shouldInlinePathParameters();this.context.errors.scope(Y.PathParameters);let l=[];t.pathParameters!=null&&l.push(...this.getPathParameters({namedParameters:t.pathParameters,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody);let s=this.getFilePropertyInfo({request:t,snippet:e});this.context.errors.unscope();let w=this.getBodyPropertyNamesForInlinedRequest(t),v=l.map(A=>w.has(A.name)?{...A,name:`${A.name}_`}:A);return this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:o})||n.push(...v),this.context.needsRequestParameter({request:t,inlinePathParameters:o,inlineFileProperties:!0})&&n.push(...this.getInlinedRequestArgs({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:o})?v:[],filePropertyInfo:s})),n}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArgs({request:t,snippet:e,pathParameterFields:n,filePropertyInfo:o}){this.context.errors.scope(Y.QueryParameters);let s=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(Y.Headers);let v=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(Y.RequestBody);let A=t.body!=null?this.getInlinedRequestBodyObjectFields({body:t.body,value:e.requestBody,filePropertyInfo:o}):[];return this.context.errors.unscope(),[...n,...s,...v,...A]}getInlinedRequestBodyObjectFields({body:t,value:e,filePropertyInfo:n}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:t.value,value:e});case"referenced":return this.getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e});case"fileUpload":return this.getFileUploadRequestBodyObjectFields({filePropertyInfo:n});default:B(t)}}getFileUploadRequestBodyObjectFields({filePropertyInfo:t}){return[...t.fileFields,...t.bodyPropertyFields]}getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e}){let n=t.bodyType;switch(n.type){case"bytes":return this.getBodyRequestArgsForBytes({body:t,value:e});case"typeReference":return this.getBodyRequestArgsForTypeReference({typeReference:n.value,value:e});default:B(n)}}getInlinedRequestBodyPropertyObjectFields({parameters:t,value:e}){let n=[],l=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}}).filter(s=>!this.resolvesToLiteralType(s.typeReference));for(let s of l)n.push({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)});return n}getPathParameters({namedParameters:t,snippet:e}){let n=[],o=t.filter(s=>!this.resolvesToLiteralType(s.typeReference)),l=this.context.associateByWireValue({parameters:o,values:e.pathParameters??{},ignoreMissingParameters:!0});for(let s of l)n.push({name:this.context.getPropertyName(s.name.name),value:this.context.dynamicTypeLiteralMapper.convert(s)});return n}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getMethodName(e)).join(".")}.${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getEnvironmentOptionName({environment:t}){return t!=null?"environment":"base_url"}};var lt=class extends We{constructor({ir:t,config:e}){super(new ut({ir:t,config:e}))}async generate(t,e={}){return super.generate(t,e)}generateSync(t,e={}){return super.generateSync(t,e)}async generateSnippetAst(t,e={}){return super.generateSnippetAst(t,e)}generateMethodCallSnippetAst({request:t,options:e={}}){let n=this.resolveEndpointsForMethodCall({request:t,options:e});if(n.length===0)throw new Error(`No endpoints found that match "${t.endpoint.method} ${t.endpoint.path}"`);let o;for(let l of n){let s=this.context.clone(),w=this.createSnippetGenerator(s);try{return w.generateMethodCallSnippetAst({endpoint:l,request:t})}catch(v){o=v}}throw o??new Error(`Failed to generate method call snippet AST for endpoint: ${t.endpoint.method} ${t.endpoint.path}`)}resolveEndpointsForMethodCall({request:t,options:e}){if(e.endpointId!=null){let n=this.context.resolveEndpointById(e.endpointId);if(n==null)throw new Error(`No endpoint found with ID "${e.endpointId}"`);return[n]}return this.context.resolveEndpointLocationOrThrow(t.endpoint)}createSnippetGenerator(t){return new pt({context:t})}};0&&(module.exports={DynamicSnippetsGenerator});
|
|
21
21
|
/*! Bundled license information:
|
|
22
22
|
|
|
23
23
|
@jspm/core/nodelibs/browser/chunk-DtuTasat.js:
|