@fern-api/typescript-dynamic-snippets 3.87.2 → 3.87.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -21,7 +21,7 @@ ${e}`)}return e}getContent(){let e=this.stringifyImports();return e.length>0?e+`
21
21
  `)?this.writeStringWithBackticks({writer:t,value:this.internalType.value}):t.write(`"${this.internalType.value.replaceAll('"','\\"')}"`);break}case"tuple":{this.writeIterable({writer:t,iterable:this.internalType});break}case"unknown":{this.writeUnknown({writer:t,value:this.internalType.value});break}case"null":{t.write("null");break}case"nop":break;default:q(this.internalType)}}isObject(){return this.internalType.type==="object"}asObjectOrThrow(){if(this.isObject())return this.internalType;throw new Error("Internal error; ts.TypeLiteral is not an object")}isSet(){return this.internalType.type==="set"}asSetOrThrow(){if(this.isSet())return this.internalType;throw new Error("Internal error; ts.TypeLiteral is not a set")}isSetOfObjects(){return this.isSet()&&this.asSetOrThrow().values.every(t=>t.isObject())}writeStringWithBackticks({writer:t,value:r}){t.write("`");let a=r.split(`
22
22
  `),o=a[0]+`
23
23
  `,u=a.slice(1).join(`
24
- `);t.write(o.replaceAll("`","\\`")),t.writeNoIndent(u.replaceAll("`","\\`")),t.write("`")}writeIterable({writer:t,iterable:r}){let a=Ec({values:r.values});if(a.length===0){t.write("[]");return}t.writeLine("["),t.indent();for(let o of a)o.write(t),t.writeLine(",");t.dedent(),t.write("]")}writeRecord({writer:t,record:r}){let a=Ic({entries:r.entries});if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let o of a)this.writeObjectKey({writer:t,key:o.key}),t.write(": "),o.value.write(t),t.writeLine(",");t.dedent(),t.write("}")}writeObjectKey({writer:t,key:r}){let a=r.internalType;if(a.type==="string"&&Fa(a.value)){t.write(a.value);return}r.write(t)}writeObject({writer:t,object:r}){let a=kc({fields:r.fields});if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let o of a)t.write(`${o.name}: `),o.value.write(t),t.writeLine(",");t.dedent(),t.write("}")}static array({values:t}){return new this({type:"array",values:t})}static bigint(t){return new this({type:"bigint",value:t})}static blob(t){return new this({type:"blob",value:t})}static boolean(t){return new this({type:"boolean",value:t})}static datetime(t){return new this({type:"datetime",value:t})}static number(t){return new this({type:"number",value:t})}static object({fields:t}){return new this({type:"object",fields:t})}static record({entries:t}){return new this({type:"record",entries:t})}static reference(t){return new this({type:"reference",value:t})}static set({values:t}){return new this({type:"set",values:t})}static string(t){return new this({type:"string",value:t})}static tuple({values:t}){return new this({type:"tuple",values:t})}static unknown(t){return new this({type:"unknown",value:t})}static null(){return new this({type:"null"})}static nop(){return new this({type:"nop"})}static isNop(t){return t.internalType.type==="nop"}writeUnknown({writer:t,value:r}){switch(typeof r){case"boolean":t.write(r.toString());return;case"string":t.write(r.includes('"')?`\`${r}\``:`"${r}"`);return;case"number":t.write(r.toString());return;case"object":if(r==null){t.write("null");return}if(Array.isArray(r)){this.writeUnknownArray({writer:t,value:r});return}this.writeUnknownObject({writer:t,value:r});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof r}`)}}writeUnknownArray({writer:t,value:r}){if(r.length===0){t.write("[]");return}t.writeLine("["),t.indent();for(let a of r)t.writeNode(n.unknown(a)),t.writeLine(",");t.dedent(),t.write("]")}writeUnknownObject({writer:t,value:r}){let a=Object.entries(r);if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let[o,u]of a)Fa(o)?t.write(`${o}: `):(t.writeNode(n.string(o)),t.write(": ")),t.writeNode(n.unknown(u)),t.writeLine(",");t.dedent(),t.write("}")}};function Fa(n){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n)}function kc({fields:n}){return n.filter(e=>!Ae.isNop(e.value))}function Ic({entries:n}){return n.filter(e=>!Ae.isNop(e.key)&&!Ae.isNop(e.value))}function Ec({values:n}){return n.filter(e=>!Ae.isNop(e))}p();f();d();var It=class extends W{constructor(t){super();I(this,"args");this.args=t}write(t){this.args.export&&t.write("export "),this.args.const?t.write("const "):t.write("let "),t.write(`${this.args.name} = `),t.writeNode(this.args.initializer)}};function Rc(n){return new bt(n)}function Sc(n){return new wt(n)}function Nc(n){return new vt(n)}function Cc(n){return new _t(n)}function Fc(n){return new Tt(n)}function Bc(n){return new kt(n)}function Oc(n){return new it(n)}function Lc(n){return new It(n)}p();f();d();p();f();d();function Oa({generatorConfig:n,isPackagePrivate:e}){let t=n.output.mode;switch(t.type){case"downloadFiles":return;case"publish":return{packageName:t.registriesV2.npm.packageName,version:t.version,private:e,publishInfo:{registryUrl:t.registriesV2.npm.registryUrl,token:t.registriesV2.npm.token},license:Ba(n.license),repoUrl:void 0};case"github":if(t.publishInfo!=null&&t.publishInfo.type!=="npm")throw new Error(`Expected to receive npm publish info but received ${t.publishInfo.type} instead`);return{packageName:t.publishInfo!=null?t.publishInfo.packageName:"",version:t.version,private:e,publishInfo:void 0,repoUrl:Pc(t.repoUrl),license:Ba(n.license)};default:throw new Error(`Encountered unknown output mode: ${t}`)}}function Pc(n){if(n!=null)return n.startsWith("https://github.com/")?`git+${n}`:n.startsWith("ssh://github.com/")?`github:${qt(n).replace("ssh://github.com/","")}`:n.startsWith("https://bitbucket.org/")?`bitbucket:${qt(n).replace("https://bitbucket.org/","")}`:n.startsWith("ssh://bitbucket.org/")?`bitbucket:${qt(n).replace("ssh://bitbucket.org/","")}`:n.startsWith("https://gitlab.com/")?`gitlab:${qt(n).replace("https://gitlab.com/","")}`:n.startsWith("ssh://gitlab.com/")?`gitlab:${qt(n).replace("ssh://gitlab.com/","")}`:(n.startsWith("git+")||(n=`git+${n}`),n.endsWith(".git")||(n=`${n}.git`),n)}function qt(n){return n.endsWith(".git")?n.slice(0,-4):n}function Ba(n){return n?._visit({basic:e=>e.id,custom:e=>`See ${e.filename}`,_other:()=>{}})}p();f();d();function Er({organization:n,workspaceName:e,namespaceExport:t,naming:r}){return(typeof r=="string"?r:r?.namespace)??t??`${Ue(St(n))}${Ue(St(e))}`}function Ar({namespaceExport:n,naming:e}){let t=typeof e=="string"?{}:e,r=e!=null?Ue(St(n)):n;return{namespace:n,client:t?.client??`${r}Client`,error:t?.error??`${r}Error`,timeoutError:t?.timeoutError??`${r}TimeoutError`,environment:t?.environment??`${r}Environment`,environmentUrls:t?.environmentUrls??`${r}EnvironmentUrls`,version:t?.version??`${r}Version`}}p();f();d();p();f();d();var zt={};pe(zt,{commons:()=>La,dynamic:()=>Cr,generatorExec:()=>Br});p();f();d();p();f();d();var La={};p();f();d();var Cr={};pe(Cr,{ErrorSeverity:()=>Wa,HttpMethod:()=>Da,ObjectPropertyAccess:()=>qa,PrimitiveTypeV1:()=>za,auth:()=>Pa,commons:()=>ja,declaration:()=>Ma,endpoints:()=>Ua,environment:()=>$a,http:()=>Rr,ir:()=>Va,snippets:()=>Sr,types:()=>Nr,variables:()=>Za});p();f();d();p();f();d();var Pa={};p();f();d();var ja={};p();f();d();var Ma={};p();f();d();var Ua={};p();f();d();var $a={};p();f();d();var Rr={};pe(Rr,{HttpMethod:()=>Da});p();f();d();p();f();d();var Da={Get:"GET",Post:"POST",Put:"PUT",Patch:"PATCH",Delete:"DELETE",Head:"HEAD"};var Va={};p();f();d();var Sr={};pe(Sr,{ErrorSeverity:()=>Wa});p();f();d();p();f();d();var Wa={Critical:"CRITICAL",Warning:"WARNING"};var Nr={};pe(Nr,{ObjectPropertyAccess:()=>qa,PrimitiveTypeV1:()=>za});p();f();d();p();f();d();var qa={ReadOnly:"READ_ONLY",WriteOnly:"WRITE_ONLY"};p();f();d();var za={Integer:"INTEGER",Long:"LONG",Uint:"UINT",Uint64:"UINT_64",Float:"FLOAT",Double:"DOUBLE",Boolean:"BOOLEAN",String:"STRING",Date:"DATE",DateTime:"DATE_TIME",DateTimeRfc2822:"DATE_TIME_RFC_2822",Uuid:"UUID",Base64:"BASE_64",BigInteger:"BIG_INTEGER"};var Za={};p();f();d();var Br={};pe(Br,{LicenseId:()=>Ga,config:()=>Fr});p();f();d();p();f();d();var Fr={};pe(Fr,{LicenseId:()=>Ga});p();f();d();p();f();d();var Ga={Mit:"MIT",Apache2:"Apache-2.0"};var jc="value",or=class{constructor({context:e}){I(this,"context");this.context=e}convert(e){let t=e.convertOpts;if(e.value===null)return this.context.isNullable(e.typeReference)?E.TypeLiteral.null():(this.context.errors.add({severity:$.Critical,message:"Expected non-null value, but got null"}),E.TypeLiteral.nop());if(e.value===void 0)return E.TypeLiteral.nop();switch(e.typeReference.type){case"list":return this.convertList({list:e.typeReference.value,value:e.value,convertOpts:t});case"literal":return this.convertLiteral({literalType:e.typeReference.value,value:e.value,convertOpts:t});case"map":return this.convertMap({map:e.typeReference,value:e.value,convertOpts:t});case"named":{let r=this.context.resolveNamedType({typeId:e.typeReference.value});return r==null?E.TypeLiteral.nop():this.convertNamed({named:r,value:e.value,as:e.as,convertOpts:t})}case"optional":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"nullable":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"primitive":return this.convertPrimitive({primitive:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"set":return this.convertSet({set:e.typeReference.value,value:e.value,convertOpts:t});case"unknown":return this.convertUnknown({value:e.value,convertOpts:t});default:q(e.typeReference)}}convertLiteral({literalType:e,value:t}){switch(e.type){case"boolean":{let r=this.context.getValueAsBoolean({value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.boolean(r)}case"string":{let r=this.context.getValueAsString({value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.string(r)}default:q(e)}}convertList({list:e,value:t,convertOpts:r}){return Array.isArray(t)?E.TypeLiteral.array({values:t.map((a,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:e,value:a,convertOpts:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:$.Critical,message:`Expected array but got: ${typeof t}`}),E.TypeLiteral.nop())}convertSet({set:e,value:t,convertOpts:r}){return Array.isArray(t)?E.TypeLiteral.set({values:t.map((a,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:e,value:a,convertOpts:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:$.Critical,message:`Expected array but got: ${typeof t}`}),E.TypeLiteral.nop())}convertMap({map:e,value:t,convertOpts:r}){return typeof t!="object"||t==null?(this.context.errors.add({severity:$.Critical,message:`Expected object but got: ${t==null?"null":typeof t}`}),E.TypeLiteral.nop()):E.TypeLiteral.record({entries:Object.entries(t).map(([a,o])=>{this.context.errors.scope(a);try{return{key:this.convert({typeReference:e.key,value:a,as:"key",convertOpts:r}),value:this.convert({typeReference:e.value,value:o,convertOpts:r})}}finally{this.context.errors.unscope()}})})}convertNamed({named:e,value:t,as:r,convertOpts:a}){switch(e.type){case"alias":return this.context.customConfig?.useBrandedStringAliases?E.TypeLiteral.reference(E.codeblock(o=>{o.writeNode(E.reference({name:this.context.namespaceExport,importFrom:this.context.getModuleImport(),memberName:this.context.getFullyQualifiedReference({declaration:e.declaration})})),o.write("("),o.writeNode(this.convert({typeReference:e.typeReference,value:t,as:r,convertOpts:a})),o.write(")")})):this.convert({typeReference:e.typeReference,value:t,as:r,convertOpts:a});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:e,value:t,convertOpts:a});case"enum":return this.convertEnum({enum_:e,value:t,convertOpts:a});case"object":return this.convertObject({object_:e,value:t,convertOpts:a});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t,convertOpts:a});default:q(e)}}convertDiscriminatedUnion({discriminatedUnion:e,value:t,convertOpts:r}){let a=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:t});if(a==null)return E.TypeLiteral.nop();let o=a.singleDiscriminatedUnionType,u=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:a,unionVariant:o,convertOpts:r});if(u==null)return E.TypeLiteral.nop();if(this.context.customConfig?.includeUtilsOnUnionMembers)return E.TypeLiteral.reference(E.codeblock(x=>{x.writeNode(E.invokeMethod({on:E.reference({name:this.context.namespaceExport,importFrom:this.context.getModuleImport(),memberName:this.context.getFullyQualifiedReference({declaration:e.declaration})}),method:this.context.getMethodName(o.discriminantValue.name),arguments_:this.convertDiscriminatedUnionUtilsArgs({discriminatedUnionTypeInstance:a,unionVariant:o,unionProperties:u,convertOpts:r})}))}));let m={name:this.context.getPropertyName(e.discriminant.name),value:E.TypeLiteral.string(o.discriminantValue.wireValue)};return E.TypeLiteral.object({fields:[m,...u]})}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:e,unionVariant:t,convertOpts:r}){let a=this.getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t});switch(t.type){case"samePropertiesAsObject":{let o=this.context.resolveNamedType({typeId:t.typeId});if(o==null)return;let u=this.convertNamed({named:o,value:e.value,convertOpts:r});if(!u.isObject()){this.context.errors.add({severity:$.Critical,message:"Internal error; expected union value to be an object"});return}let m=u.asObjectOrThrow();return[...a,...m.fields]}case"singleProperty":try{this.context.errors.scope(t.discriminantValue.wireValue);let o=this.context.getRecord(e.value);return o==null?[...a,{name:jc,value:this.convert({typeReference:t.typeReference,value:e.value,convertOpts:r})}]:[...a,{name:this.context.getPropertyName(t.discriminantValue.name),value:this.convert({typeReference:t.typeReference,value:o[t.discriminantValue.wireValue],convertOpts:r})}]}finally{this.context.errors.unscope()}case"noProperties":return a;default:q(t)}}convertDiscriminatedUnionUtilsArgs({discriminatedUnionTypeInstance:e,unionVariant:t,unionProperties:r,convertOpts:a}){return t.type==="singleProperty"&&this.context.getRecord(e.value)==null&&r.length===1?[this.convert({typeReference:t.typeReference,value:e.value,convertOpts:a})]:r.length>0?[E.TypeLiteral.object({fields:r})]:[]}getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t,convertOpts:r}){return this.context.associateByWireValue({parameters:t.properties??[],values:this.context.getRecord(e.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,convertOpts:r})}}finally{this.context.errors.unscope()}})}convertObject({object_:e,value:t,convertOpts:r}){let a=this.context.associateByWireValue({parameters:this.filterReadWriteProperties(e.properties,r),values:this.context.getRecord(t)??{}});return E.TypeLiteral.object({fields:a.map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getPropertyName(o.name.name),value:this.convert({...o,convertOpts:r})}}finally{this.context.errors.unscope()}})})}filterReadWriteProperties(e,t){return this.context.customConfig?.experimentalGenerateReadWriteOnlyTypes!==!0||typeof t>"u"||(t.isForRequest&&(e=e.filter(r=>r.propertyAccess!==zt.dynamic.ObjectPropertyAccess.ReadOnly)),t.isForResponse&&(e=e.filter(r=>r.propertyAccess!==zt.dynamic.ObjectPropertyAccess.WriteOnly))),e}convertEnum({enum_:e,value:t}){let r=this.getEnumValue({enum_:e,value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.string(r)}getEnumValue({enum_:e,value:t}){if(typeof t!="string"){this.context.errors.add({severity:$.Critical,message:`Expected enum value string, got: ${typeof t}`});return}if(e.values.find(a=>a.wireValue===t)==null){this.context.errors.add({severity:$.Critical,message:`An enum value named "${t}" does not exist in this context`});return}return t}convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t,convertOpts:r}){let a=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t,convertOpts:r});return a??E.TypeLiteral.nop()}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t,convertOpts:r}){for(let a of e.types){let o=this.context.errors.size();try{let u=this.convert({typeReference:a,value:t,convertOpts:r});if(E.TypeLiteral.isNop(u)||this.context.errors.size()>o){this.context.errors.truncate(o);continue}return u}catch{this.context.errors.truncate(o);continue}}this.context.errors.add({severity:$.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof t}" value`})}convertUnknown({value:e,convertOpts:t}){return E.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:t,as:r,convertOpts:a}){switch(e){case"INTEGER":case"UINT":{let o=this.getValueAsNumber({value:t,as:r});return o==null?E.TypeLiteral.nop():E.TypeLiteral.number(o)}case"LONG":case"UINT_64":{let o=this.getValueAsNumber({value:t,as:r});return o==null?E.TypeLiteral.nop():this.context.customConfig?.useBigInt?E.TypeLiteral.bigint(BigInt(o)):E.TypeLiteral.number(o)}case"FLOAT":case"DOUBLE":{let o=this.getValueAsNumber({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.number(o)}case"BOOLEAN":{let o=this.getValueAsBoolean({value:t,as:r});return o==null?E.TypeLiteral.nop():E.TypeLiteral.boolean(o)}case"BASE_64":case"DATE":case"UUID":case"STRING":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.string(o)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.datetime(o)}case"BIG_INTEGER":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():this.context.customConfig?.useBigInt?E.TypeLiteral.bigint(BigInt(o)):E.TypeLiteral.string(o)}default:q(e)}}getValueAsNumber({value:e,as:t}){let r=t==="key"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:e,as:t}){let r=t==="key"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:r})}};p();f();d();var ur=class{constructor({context:e}){I(this,"context");this.context=e}getFilePropertyInfo({body:e,value:t}){let r={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(t)??{};for(let o of e.properties)switch(o.type){case"file":r.fileFields.push({name:this.context.getPropertyName(o.name),value:this.getSingleFileProperty({property:o,record:a})});break;case"fileArray":r.fileFields.push({name:this.context.getPropertyName(o.name),value:this.getArrayFileProperty({property:o,record:a})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getPropertyName(o.name.name),value:this.getBodyProperty({property:o,record:a})});break;default:q(o)}return r}getSingleFileProperty({property:e,record:t}){let r=this.context.getSingleFileValue({property:e,record:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.blob(r)}getArrayFileProperty({property:e,record:t}){let r=this.context.getFileArrayValues({property:e,record:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.array({values:r.map(a=>E.TypeLiteral.blob(a))})}getBodyProperty({property:e,record:t}){let r=t[e.name.wireValue];return r==null?E.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:r})}};var cr=class n extends Mt{constructor({ir:t,config:r}){super({ir:t,config:r});I(this,"ir");I(this,"customConfig");I(this,"dynamicTypeLiteralMapper");I(this,"filePropertyMapper");I(this,"moduleName");I(this,"namespaceExport");I(this,"resolvedClientName");I(this,"resolvedEnvironmentName");this.ir=t,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeLiteralMapper=new or({context:this}),this.filePropertyMapper=new ur({context:this}),this.moduleName=Mc({config:r,customConfig:this.customConfig}),this.namespaceExport=Er({organization:r.organization,workspaceName:r.workspaceName,namespaceExport:this.customConfig?.namespaceExport,naming:this.customConfig?.naming});let a=Ar({namespaceExport:this.namespaceExport,naming:this.customConfig?.naming});this.resolvedClientName=a.client,this.resolvedEnvironmentName=a.environment}clone(){return new n({ir:this.ir,config:this.config})}getModuleImport(){return{type:"named",moduleName:this.moduleName}}getRootClientName(){return this.resolvedClientName}getPropertyName(t){return this.customConfig?.retainOriginalCasing||Wt(this.customConfig)?this.formatOriginalPropertyName(t.originalName):t.camelCase.unsafeName}getMethodName(t){return t.camelCase.unsafeName}getTypeName(t){return t.pascalCase.unsafeName}getEnvironmentTypeReferenceFromID(t){let r=this.resolveEnvironmentName(t);if(r!=null)return this.getEnvironmentsTypeReference(r)}getFullyQualifiedReference({declaration:t}){return t.fernFilepath.allParts.length>0?`${t.fernFilepath.allParts.map(r=>r.camelCase.unsafeName).join(".")}.${this.getTypeName(t.name)}`:`${this.getTypeName(t.name)}`}getEnvironmentsTypeReference(t){return E.reference({name:this.resolvedEnvironmentName,importFrom:this.getModuleImport(),memberName:this.getTypeName(t)})}formatOriginalPropertyName(t){return t.includes("-")?`"${t}"`:t}};function Mc({config:n,customConfig:e}){return Oa({generatorConfig:n,isPackagePrivate:e?.private??!1})?.packageName??n.organization}p();f();d();var Ha="client",Ja="main",Uc={type:"primitive",value:"STRING"},lr=class{constructor({context:e}){I(this,"context");this.context=e}async generateSnippet({endpoint:e,request:t}){return await this.buildCodeBlock({endpoint:e,snippet:t}).toStringAsync({customConfig:this.context.customConfig})}generateSnippetSync({endpoint:e,request:t}){return this.buildCodeBlock({endpoint:e,snippet:t}).toString({customConfig:this.context.customConfig})}async generateSnippetAst({endpoint:e,request:t}){return this.buildCodeBlock({endpoint:e,snippet:t})}buildCodeBlock({endpoint:e,snippet:t}){return E.codeblock(r=>{r.writeNode(E.function_({name:Ja,async:!0,parameters:[],body:E.codeblock(a=>{a.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),a.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))})})),r.writeNodeStatement(E.invokeFunction({function_:E.reference({name:Ja}),arguments_:[]}))})}constructClient({endpoint:e,snippet:t}){return E.variable({name:Ha,const:!0,initializer:E.instantiateClass({class_:E.reference({name:this.context.getRootClientName(),importFrom:this.context.getModuleImport()}),arguments_:[this.getConstructorArgs({endpoint:e,snippet:t})]})})}getConstructorArgs({endpoint:e,snippet:t}){let r=[],a=this.getConstructorEnvironmentArgs({baseUrl:t.baseURL,environment:t.environment});return a.length>0&&r.push(...a),e.auth!=null&&(t.auth!=null?r.push(...this.getConstructorAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:$.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(fe.PathParameters),this.context.ir.pathParameters!=null&&r.push(...this.getPathParameters({namedParameters:this.context.ir.pathParameters,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(fe.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope(),r.length===0?E.TypeLiteral.nop():E.TypeLiteral.object({fields:r})}getConstructorEnvironmentArgs({baseUrl:e,environment:t}){let r=this.getEnvironmentValue({baseUrl:e,environment:t});return r==null?[]:[{name:"environment",value:r}]}getEnvironmentValue({baseUrl:e,environment:t}){if(e!=null&&t!=null){this.context.errors.add({severity:$.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(e!=null)return E.TypeLiteral.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let r=this.context.getEnvironmentTypeReferenceFromID(t);if(r==null){this.context.errors.add({severity:$.Warning,message:`Environment ${JSON.stringify(t)} was not found`});return}return E.TypeLiteral.reference(r)}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?E.TypeLiteral.object({fields:Object.entries(t).map(([r,a])=>({name:r,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Uc,value:a})}))}):void 0}}getConstructorAuthArgs({auth:e,values:t}){switch(e.type){case"basic":return t.type!=="basic"?(this.addAuthMismatchError(e,t),[]):this.getConstructorBasicAuthArg({auth:e,values:t});case"bearer":return t.type!=="bearer"?(this.addAuthMismatchError(e,t),[]):this.getConstructorBearerAuthArgs({auth:e,values:t});case"header":return t.type!=="header"?(this.addAuthMismatchError(e,t),[]):this.getConstructorHeaderAuthArgs({auth:e,values:t});case"oauth":return t.type!=="oauth"?(this.addAuthMismatchError(e,t),[]):this.getConstructorOAuthArgs({auth:e,values:t});case"inferred":return t.type!=="inferred"?(this.addAuthMismatchError(e,t),[]):(this.addWarning("The TypeScript SDK v2 Generator does not support Inferred auth scheme yet"),[]);default:q(e)}}addAuthMismatchError(e,t){this.context.errors.add({severity:$.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message})}addWarning(e){this.context.errors.add({severity:$.Warning,message:e})}getConstructorBasicAuthArg({auth:e,values:t}){return[{name:this.context.getPropertyName(e.username),value:E.TypeLiteral.string(t.username)},{name:this.context.getPropertyName(e.password),value:E.TypeLiteral.string(t.password)}]}getConstructorBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.token),value:E.TypeLiteral.string(t.token)}]}getConstructorHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getConstructorOAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.clientId),value:E.TypeLiteral.string(t.clientId)},{name:this.context.getPropertyName(e.clientSecret),value:E.TypeLiteral.string(t.clientSecret)}]}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let a of e){let o=t[a.name.wireValue],u=this.getConstructorHeaderArg({header:a,value:o});u!=null&&r.push(u)}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!E.TypeLiteral.isNop(r))return{name:this.context.getPropertyName(e.name.name),value:r}}callMethod({endpoint:e,snippet:t}){return E.invokeMethod({on:E.reference({name:Ha}),method:this.getMethod({endpoint:e}),async:!0,arguments_:this.getMethodArgs({endpoint:e,snippet:t})})}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:q(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){let r=[];this.context.errors.scope(fe.PathParameters);let a=[...this.context.ir.pathParameters??[],...e.pathParameters??[]];return a.length>0&&r.push(...this.getPathParameters({namedParameters:a,snippet:t}).map(o=>o.value)),this.context.errors.unscope(),this.context.errors.scope(fe.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,convertOpts:{isForRequest:!0}});default:q(e)}}getBytesBodyRequestArg({value:e}){return typeof e!="string"?(this.context.errors.add({severity:$.Critical,message:`Expected bytes value to be a string, got ${typeof e}`}),E.TypeLiteral.nop()):E.TypeLiteral.blob(e)}getMethodArgsForInlinedRequest({request:e,snippet:t}){let r=[],{inlinePathParameters:a,inlineFileProperties:o}={inlinePathParameters:this.context.customConfig?.inlinePathParameters??!0,inlineFileProperties:this.context.customConfig?.inlineFileProperties??!0};this.context.errors.scope(fe.PathParameters);let u=[];e.pathParameters!=null&&u.push(...this.getPathParameters({namedParameters:e.pathParameters,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(fe.RequestBody);let m=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})||r.push(...u.map(x=>x.value)),o||r.push(...m.fileFields.map(x=>x.value)),this.context.needsRequestParameter({request:e,inlinePathParameters:a,inlineFileProperties:o})&&r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})?u:[],filePropertyInfo:m})),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:a}){this.context.errors.scope(fe.QueryParameters);let u=this.context.associateQueryParametersByWireValue({parameters:e.queryParameters??[],values:t.queryParameters??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...R,convertOpts:{isForRequest:!0}})}));this.context.errors.unscope(),this.context.errors.scope(fe.Headers);let x=this.context.associateByWireValue({parameters:e.headers??[],values:t.headers??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...R,convertOpts:{isForRequest:!0}})}));this.context.errors.unscope(),this.context.errors.scope(fe.RequestBody);let k=e.body!=null?this.getInlinedRequestBodyObjectFields({body:e.body,value:t.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),E.TypeLiteral.object({fields:[...r,...u,...x,...k]})}getInlinedRequestBodyObjectFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyObjectField({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyObjectFields({filePropertyInfo:r});default:q(e)}}getFileUploadRequestBodyObjectFields({filePropertyInfo:e}){return this.context.customConfig?.inlineFileProperties??!0?[...e.fileFields,...e.bodyPropertyFields]:e.bodyPropertyFields}getReferencedRequestBodyPropertyObjectField({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,convertOpts:{isForRequest:!0}});default:q(e)}}getInlinedRequestBodyPropertyObjectFields({parameters:e,value:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:this.context.getRecord(t)??{}});for(let o of a)r.push({name:this.context.getPropertyName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...o,convertOpts:{isForRequest:!0}})});return r}getPathParameters({namedParameters:e,snippet:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:t.pathParameters??{},ignoreMissingParameters:!0});for(let o of a)r.push({name:this.context.getPropertyName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...o,convertOpts:{isForRequest:!0}})});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getMethodName(t)).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}};var pr=class extends Lt{constructor({ir:e,config:t}){super(new cr({ir:e,config:t}))}async generate(e,t={}){return super.generate(e,t)}generateSync(e){return super.generateSync(e)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new lr({context:e})}};0&&(module.exports={DynamicSnippetsGenerator});
24
+ `);t.write(o.replaceAll("`","\\`")),t.writeNoIndent(u.replaceAll("`","\\`")),t.write("`")}writeIterable({writer:t,iterable:r}){let a=Ec({values:r.values});if(a.length===0){t.write("[]");return}t.writeLine("["),t.indent();for(let o of a)o.write(t),t.writeLine(",");t.dedent(),t.write("]")}writeRecord({writer:t,record:r}){let a=Ic({entries:r.entries});if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let o of a)this.writeObjectKey({writer:t,key:o.key}),t.write(": "),o.value.write(t),t.writeLine(",");t.dedent(),t.write("}")}writeObjectKey({writer:t,key:r}){let a=r.internalType;if(a.type==="string"&&Fa(a.value)){t.write(a.value);return}r.write(t)}writeObject({writer:t,object:r}){let a=kc({fields:r.fields});if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let o of a)t.write(`${o.name}: `),o.value.write(t),t.writeLine(",");t.dedent(),t.write("}")}static array({values:t}){return new this({type:"array",values:t})}static bigint(t){return new this({type:"bigint",value:t})}static blob(t){return new this({type:"blob",value:t})}static boolean(t){return new this({type:"boolean",value:t})}static datetime(t){return new this({type:"datetime",value:t})}static number(t){return new this({type:"number",value:t})}static object({fields:t}){return new this({type:"object",fields:t})}static record({entries:t}){return new this({type:"record",entries:t})}static reference(t){return new this({type:"reference",value:t})}static set({values:t}){return new this({type:"set",values:t})}static string(t){return new this({type:"string",value:t})}static tuple({values:t}){return new this({type:"tuple",values:t})}static unknown(t){return new this({type:"unknown",value:t})}static null(){return new this({type:"null"})}static nop(){return new this({type:"nop"})}static isNop(t){return t.internalType.type==="nop"}writeUnknown({writer:t,value:r}){switch(typeof r){case"boolean":t.write(r.toString());return;case"string":t.write(r.includes('"')?`\`${r}\``:`"${r}"`);return;case"number":t.write(r.toString());return;case"object":if(r==null){t.write("null");return}if(Array.isArray(r)){this.writeUnknownArray({writer:t,value:r});return}this.writeUnknownObject({writer:t,value:r});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof r}`)}}writeUnknownArray({writer:t,value:r}){if(r.length===0){t.write("[]");return}t.writeLine("["),t.indent();for(let a of r)t.writeNode(n.unknown(a)),t.writeLine(",");t.dedent(),t.write("]")}writeUnknownObject({writer:t,value:r}){let a=Object.entries(r);if(a.length===0){t.write("{}");return}t.writeLine("{"),t.indent();for(let[o,u]of a)Fa(o)?t.write(`${o}: `):(t.writeNode(n.string(o)),t.write(": ")),t.writeNode(n.unknown(u)),t.writeLine(",");t.dedent(),t.write("}")}};function Fa(n){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n)}function kc({fields:n}){return n.filter(e=>!Ae.isNop(e.value))}function Ic({entries:n}){return n.filter(e=>!Ae.isNop(e.key)&&!Ae.isNop(e.value))}function Ec({values:n}){return n.filter(e=>!Ae.isNop(e))}p();f();d();var It=class extends W{constructor(t){super();I(this,"args");this.args=t}write(t){this.args.export&&t.write("export "),this.args.const?t.write("const "):t.write("let "),t.write(`${this.args.name} = `),t.writeNode(this.args.initializer)}};function Rc(n){return new bt(n)}function Sc(n){return new wt(n)}function Nc(n){return new vt(n)}function Cc(n){return new _t(n)}function Fc(n){return new Tt(n)}function Bc(n){return new kt(n)}function Oc(n){return new it(n)}function Lc(n){return new It(n)}p();f();d();p();f();d();function Oa({generatorConfig:n,isPackagePrivate:e}){let t=n.output.mode;switch(t.type){case"downloadFiles":return;case"publish":return{packageName:t.registriesV2.npm.packageName,version:t.version,private:e,publishInfo:{registryUrl:t.registriesV2.npm.registryUrl,token:t.registriesV2.npm.token},license:Ba(n.license),repoUrl:void 0};case"github":if(t.publishInfo!=null&&t.publishInfo.type!=="npm")throw new Error(`Expected to receive npm publish info but received ${t.publishInfo.type} instead`);return{packageName:t.publishInfo!=null?t.publishInfo.packageName:"",version:t.version,private:e,publishInfo:void 0,repoUrl:Pc(t.repoUrl),license:Ba(n.license)};default:throw new Error(`Encountered unknown output mode: ${t}`)}}function Pc(n){if(n!=null)return n.startsWith("https://github.com/")?`git+${n}`:n.startsWith("ssh://github.com/")?`github:${qt(n).replace("ssh://github.com/","")}`:n.startsWith("https://bitbucket.org/")?`bitbucket:${qt(n).replace("https://bitbucket.org/","")}`:n.startsWith("ssh://bitbucket.org/")?`bitbucket:${qt(n).replace("ssh://bitbucket.org/","")}`:n.startsWith("https://gitlab.com/")?`gitlab:${qt(n).replace("https://gitlab.com/","")}`:n.startsWith("ssh://gitlab.com/")?`gitlab:${qt(n).replace("ssh://gitlab.com/","")}`:(n.startsWith("git+")||(n=`git+${n}`),n.endsWith(".git")||(n=`${n}.git`),n)}function qt(n){return n.endsWith(".git")?n.slice(0,-4):n}function Ba(n){return n?._visit({basic:e=>e.id,custom:e=>`See ${e.filename}`,_other:()=>{}})}p();f();d();function Er({organization:n,workspaceName:e,namespaceExport:t,naming:r}){return(typeof r=="string"?r:r?.namespace)??t??`${Ue(St(n))}${Ue(St(e))}`}function Ar({namespaceExport:n,naming:e}){let t=typeof e=="string"?{}:e,r=e!=null?Ue(St(n)):n;return{namespace:n,client:t?.client??`${r}Client`,error:t?.error??`${r}Error`,timeoutError:t?.timeoutError??`${r}TimeoutError`,environment:t?.environment??`${r}Environment`,environmentUrls:t?.environmentUrls??`${r}EnvironmentUrls`,version:t?.version??`${r}Version`}}p();f();d();p();f();d();var zt={};pe(zt,{commons:()=>La,dynamic:()=>Cr,generatorExec:()=>Br});p();f();d();p();f();d();var La={};p();f();d();var Cr={};pe(Cr,{ErrorSeverity:()=>Wa,HttpMethod:()=>Da,ObjectPropertyAccess:()=>qa,PrimitiveTypeV1:()=>za,auth:()=>Pa,commons:()=>ja,declaration:()=>Ma,endpoints:()=>Ua,environment:()=>$a,http:()=>Rr,ir:()=>Va,snippets:()=>Sr,types:()=>Nr,variables:()=>Za});p();f();d();p();f();d();var Pa={};p();f();d();var ja={};p();f();d();var Ma={};p();f();d();var Ua={};p();f();d();var $a={};p();f();d();var Rr={};pe(Rr,{HttpMethod:()=>Da});p();f();d();p();f();d();var Da={Get:"GET",Post:"POST",Put:"PUT",Patch:"PATCH",Delete:"DELETE",Head:"HEAD"};var Va={};p();f();d();var Sr={};pe(Sr,{ErrorSeverity:()=>Wa});p();f();d();p();f();d();var Wa={Critical:"CRITICAL",Warning:"WARNING"};var Nr={};pe(Nr,{ObjectPropertyAccess:()=>qa,PrimitiveTypeV1:()=>za});p();f();d();p();f();d();var qa={ReadOnly:"READ_ONLY",WriteOnly:"WRITE_ONLY"};p();f();d();var za={Integer:"INTEGER",Long:"LONG",Uint:"UINT",Uint64:"UINT_64",Float:"FLOAT",Double:"DOUBLE",Boolean:"BOOLEAN",String:"STRING",Date:"DATE",DateTime:"DATE_TIME",DateTimeRfc2822:"DATE_TIME_RFC_2822",Uuid:"UUID",Base64:"BASE_64",BigInteger:"BIG_INTEGER"};var Za={};p();f();d();var Br={};pe(Br,{LicenseId:()=>Ga,config:()=>Fr});p();f();d();p();f();d();var Fr={};pe(Fr,{LicenseId:()=>Ga});p();f();d();p();f();d();var Ga={Mit:"MIT",Apache2:"Apache-2.0"};var jc="value",or=class{constructor({context:e}){I(this,"context");this.context=e}convert(e){let t=e.convertOpts;if(e.value===null)return this.context.isNullable(e.typeReference)?E.TypeLiteral.null():(this.context.errors.add({severity:$.Critical,message:"Expected non-null value, but got null"}),E.TypeLiteral.nop());if(e.value===void 0)return E.TypeLiteral.nop();switch(e.typeReference.type){case"list":return this.convertList({list:e.typeReference.value,value:e.value,convertOpts:t});case"literal":return this.convertLiteral({literalType:e.typeReference.value,value:e.value,convertOpts:t});case"map":return this.convertMap({map:e.typeReference,value:e.value,convertOpts:t});case"named":{let r=this.context.resolveNamedType({typeId:e.typeReference.value});return r==null?E.TypeLiteral.nop():this.convertNamed({named:r,value:e.value,as:e.as,convertOpts:t})}case"optional":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"nullable":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"primitive":return this.convertPrimitive({primitive:e.typeReference.value,value:e.value,as:e.as,convertOpts:t});case"set":return this.convertSet({set:e.typeReference.value,value:e.value,convertOpts:t});case"unknown":return this.convertUnknown({value:e.value,convertOpts:t});default:q(e.typeReference)}}convertLiteral({literalType:e,value:t}){switch(e.type){case"boolean":{let r=this.context.getValueAsBoolean({value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.boolean(r)}case"string":{let r=this.context.getValueAsString({value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.string(r)}default:q(e)}}convertList({list:e,value:t,convertOpts:r}){return Array.isArray(t)?E.TypeLiteral.array({values:t.map((a,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:e,value:a,convertOpts:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:$.Critical,message:`Expected array but got: ${typeof t}`}),E.TypeLiteral.nop())}convertSet({set:e,value:t,convertOpts:r}){return Array.isArray(t)?E.TypeLiteral.set({values:t.map((a,o)=>{this.context.errors.scope({index:o});try{return this.convert({typeReference:e,value:a,convertOpts:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:$.Critical,message:`Expected array but got: ${typeof t}`}),E.TypeLiteral.nop())}convertMap({map:e,value:t,convertOpts:r}){return typeof t!="object"||t==null?(this.context.errors.add({severity:$.Critical,message:`Expected object but got: ${t==null?"null":typeof t}`}),E.TypeLiteral.nop()):E.TypeLiteral.record({entries:Object.entries(t).map(([a,o])=>{this.context.errors.scope(a);try{return{key:this.convert({typeReference:e.key,value:a,as:"key",convertOpts:r}),value:this.convert({typeReference:e.value,value:o,convertOpts:r})}}finally{this.context.errors.unscope()}})})}convertNamed({named:e,value:t,as:r,convertOpts:a}){switch(e.type){case"alias":return this.context.customConfig?.useBrandedStringAliases?E.TypeLiteral.reference(E.codeblock(o=>{o.writeNode(E.reference({name:this.context.namespaceExport,importFrom:this.context.getModuleImport(),memberName:this.context.getFullyQualifiedReference({declaration:e.declaration})})),o.write("("),o.writeNode(this.convert({typeReference:e.typeReference,value:t,as:r,convertOpts:a})),o.write(")")})):this.convert({typeReference:e.typeReference,value:t,as:r,convertOpts:a});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:e,value:t,convertOpts:a});case"enum":return this.convertEnum({enum_:e,value:t,convertOpts:a});case"object":return this.convertObject({object_:e,value:t,convertOpts:a});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t,convertOpts:a});default:q(e)}}convertDiscriminatedUnion({discriminatedUnion:e,value:t,convertOpts:r}){let a=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:t});if(a==null)return E.TypeLiteral.nop();let o=a.singleDiscriminatedUnionType,u=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:a,unionVariant:o,convertOpts:r});if(u==null)return E.TypeLiteral.nop();if(this.context.customConfig?.includeUtilsOnUnionMembers)return E.TypeLiteral.reference(E.codeblock(x=>{x.writeNode(E.invokeMethod({on:E.reference({name:this.context.namespaceExport,importFrom:this.context.getModuleImport(),memberName:this.context.getFullyQualifiedReference({declaration:e.declaration})}),method:this.context.getMethodName(o.discriminantValue.name),arguments_:this.convertDiscriminatedUnionUtilsArgs({discriminatedUnionTypeInstance:a,unionVariant:o,unionProperties:u,convertOpts:r})}))}));let m={name:this.context.getPropertyName(e.discriminant.name),value:E.TypeLiteral.string(o.discriminantValue.wireValue)};return E.TypeLiteral.object({fields:[m,...u]})}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:e,unionVariant:t,convertOpts:r}){let a=this.getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t});switch(t.type){case"samePropertiesAsObject":{let o=this.context.resolveNamedType({typeId:t.typeId});if(o==null)return;let u=this.convertNamed({named:o,value:e.value,convertOpts:r});if(!u.isObject()){this.context.errors.add({severity:$.Critical,message:"Internal error; expected union value to be an object"});return}let m=u.asObjectOrThrow();return[...a,...m.fields]}case"singleProperty":try{this.context.errors.scope(t.discriminantValue.wireValue);let o=this.context.getRecord(e.value);return o==null?[...a,{name:jc,value:this.convert({typeReference:t.typeReference,value:e.value,convertOpts:r})}]:[...a,{name:this.context.getPropertyName(t.discriminantValue.name),value:this.convert({typeReference:t.typeReference,value:o[t.discriminantValue.wireValue],convertOpts:r})}]}finally{this.context.errors.unscope()}case"noProperties":return a;default:q(t)}}convertDiscriminatedUnionUtilsArgs({discriminatedUnionTypeInstance:e,unionVariant:t,unionProperties:r,convertOpts:a}){return t.type==="singleProperty"&&this.context.getRecord(e.value)==null&&r.length===1?[this.convert({typeReference:t.typeReference,value:e.value,convertOpts:a})]:r.length>0?[E.TypeLiteral.object({fields:r})]:[]}getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t,convertOpts:r}){return this.context.associateByWireValue({parameters:t.properties??[],values:this.context.getRecord(e.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,convertOpts:r})}}finally{this.context.errors.unscope()}})}convertObject({object_:e,value:t,convertOpts:r}){let a=this.context.associateByWireValue({parameters:this.filterReadWriteProperties(e.properties,r),values:this.context.getRecord(t)??{}});return E.TypeLiteral.object({fields:a.map(o=>{this.context.errors.scope(o.name.wireValue);try{return{name:this.context.getPropertyName(o.name.name),value:this.convert({...o,convertOpts:r})}}finally{this.context.errors.unscope()}})})}filterReadWriteProperties(e,t){return this.context.customConfig?.experimentalGenerateReadWriteOnlyTypes!==!0||typeof t>"u"||(t.isForRequest&&(e=e.filter(r=>r.propertyAccess!==zt.dynamic.ObjectPropertyAccess.ReadOnly)),t.isForResponse&&(e=e.filter(r=>r.propertyAccess!==zt.dynamic.ObjectPropertyAccess.WriteOnly))),e}convertEnum({enum_:e,value:t}){let r=this.getEnumValue({enum_:e,value:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.string(r)}getEnumValue({enum_:e,value:t}){if(typeof t!="string"){this.context.errors.add({severity:$.Critical,message:`Expected enum value string, got: ${typeof t}`});return}if(e.values.find(a=>a.wireValue===t)==null){this.context.errors.add({severity:$.Critical,message:`An enum value named "${t}" does not exist in this context`});return}return t}convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t,convertOpts:r}){let a=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t,convertOpts:r});return a??E.TypeLiteral.nop()}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t,convertOpts:r}){for(let a of e.types){let o=this.context.errors.size();try{let u=this.convert({typeReference:a,value:t,convertOpts:r});if(E.TypeLiteral.isNop(u)||this.context.errors.size()>o){this.context.errors.truncate(o);continue}return u}catch{this.context.errors.truncate(o);continue}}this.context.errors.add({severity:$.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof t}" value`})}convertUnknown({value:e,convertOpts:t}){return E.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:t,as:r,convertOpts:a}){switch(e){case"INTEGER":case"UINT":{let o=this.getValueAsNumber({value:t,as:r});return o==null?E.TypeLiteral.nop():E.TypeLiteral.number(o)}case"LONG":case"UINT_64":{let o=this.getValueAsNumber({value:t,as:r});return o==null?E.TypeLiteral.nop():this.context.customConfig?.useBigInt?E.TypeLiteral.bigint(BigInt(o)):E.TypeLiteral.number(o)}case"FLOAT":case"DOUBLE":{let o=this.getValueAsNumber({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.number(o)}case"BOOLEAN":{let o=this.getValueAsBoolean({value:t,as:r});return o==null?E.TypeLiteral.nop():E.TypeLiteral.boolean(o)}case"BASE_64":case"DATE":case"UUID":case"STRING":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.string(o)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():E.TypeLiteral.datetime(o)}case"BIG_INTEGER":{let o=this.context.getValueAsString({value:t});return o==null?E.TypeLiteral.nop():this.context.customConfig?.useBigInt?E.TypeLiteral.bigint(BigInt(o)):E.TypeLiteral.string(o)}default:q(e)}}getValueAsNumber({value:e,as:t}){let r=t==="key"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:e,as:t}){let r=t==="key"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:r})}};p();f();d();var ur=class{constructor({context:e}){I(this,"context");this.context=e}getFilePropertyInfo({body:e,value:t}){let r={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(t)??{};for(let o of e.properties)switch(o.type){case"file":r.fileFields.push({name:this.context.getPropertyName(o.name),value:this.getSingleFileProperty({property:o,record:a})});break;case"fileArray":r.fileFields.push({name:this.context.getPropertyName(o.name),value:this.getArrayFileProperty({property:o,record:a})});break;case"bodyProperty":r.bodyPropertyFields.push({name:this.context.getPropertyName(o.name.name),value:this.getBodyProperty({property:o,record:a})});break;default:q(o)}return r}getSingleFileProperty({property:e,record:t}){let r=this.context.getSingleFileValue({property:e,record:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.blob(r)}getArrayFileProperty({property:e,record:t}){let r=this.context.getFileArrayValues({property:e,record:t});return r==null?E.TypeLiteral.nop():E.TypeLiteral.array({values:r.map(a=>E.TypeLiteral.blob(a))})}getBodyProperty({property:e,record:t}){let r=t[e.name.wireValue];return r==null?E.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:r})}};var cr=class n extends Mt{constructor({ir:t,config:r}){super({ir:t,config:r});I(this,"ir");I(this,"customConfig");I(this,"dynamicTypeLiteralMapper");I(this,"filePropertyMapper");I(this,"moduleName");I(this,"namespaceExport");I(this,"resolvedClientName");I(this,"resolvedEnvironmentName");this.ir=t,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeLiteralMapper=new or({context:this}),this.filePropertyMapper=new ur({context:this}),this.moduleName=Mc({config:r,customConfig:this.customConfig}),this.namespaceExport=Er({organization:r.organization,workspaceName:r.workspaceName,namespaceExport:this.customConfig?.namespaceExport,naming:this.customConfig?.naming});let a=Ar({namespaceExport:this.namespaceExport,naming:this.customConfig?.naming});this.resolvedClientName=a.client,this.resolvedEnvironmentName=a.environment}clone(){return new n({ir:this.ir,config:this.config})}getModuleImport(){return{type:"named",moduleName:this.moduleName}}getRootClientName(){return this.resolvedClientName}getPropertyName(t){return this.customConfig?.retainOriginalCasing||Wt(this.customConfig)?this.formatOriginalPropertyName(t.originalName):t.camelCase.unsafeName}getMethodName(t){return t.camelCase.unsafeName}getTypeName(t){return t.pascalCase.unsafeName}getEnvironmentTypeReferenceFromID(t){let r=this.resolveEnvironmentName(t);if(r!=null)return this.getEnvironmentsTypeReference(r)}getFullyQualifiedReference({declaration:t}){return t.fernFilepath.allParts.length>0?`${t.fernFilepath.allParts.map(r=>r.camelCase.unsafeName).join(".")}.${this.getTypeName(t.name)}`:`${this.getTypeName(t.name)}`}getEnvironmentsTypeReference(t){return E.reference({name:this.resolvedEnvironmentName,importFrom:this.getModuleImport(),memberName:this.getTypeName(t)})}formatOriginalPropertyName(t){return t.includes("-")?`"${t}"`:t}};function Mc({config:n,customConfig:e}){return Oa({generatorConfig:n,isPackagePrivate:e?.private??!1})?.packageName??n.organization}p();f();d();var Ha="client",Ja="main",Uc={type:"primitive",value:"STRING"},lr=class{constructor({context:e}){I(this,"context");this.context=e}async generateSnippet({endpoint:e,request:t}){return await this.buildCodeBlock({endpoint:e,snippet:t}).toStringAsync({customConfig:this.context.customConfig})}generateSnippetSync({endpoint:e,request:t}){return this.buildCodeBlock({endpoint:e,snippet:t}).toString({customConfig:this.context.customConfig})}async generateSnippetAst({endpoint:e,request:t}){return this.buildCodeBlock({endpoint:e,snippet:t})}buildCodeBlock({endpoint:e,snippet:t}){return E.codeblock(r=>{r.writeNode(E.function_({name:Ja,async:!0,parameters:[],body:E.codeblock(a=>{a.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),a.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))})})),r.writeNodeStatement(E.invokeFunction({function_:E.reference({name:Ja}),arguments_:[]}))})}constructClient({endpoint:e,snippet:t}){return E.variable({name:Ha,const:!0,initializer:E.instantiateClass({class_:E.reference({name:this.context.getRootClientName(),importFrom:this.context.getModuleImport()}),arguments_:[this.getConstructorArgs({endpoint:e,snippet:t})]})})}getConstructorArgs({endpoint:e,snippet:t}){let r=[],a=this.getConstructorEnvironmentArgs({baseUrl:t.baseURL,environment:t.environment});return a.length>0&&r.push(...a),e.auth!=null&&(t.auth!=null?r.push(...this.getConstructorAuthArgs({auth:e.auth,values:t.auth})):this.context.errors.add({severity:$.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(fe.PathParameters),this.context.ir.pathParameters!=null&&r.push(...this.getPathParameters({namedParameters:this.context.ir.pathParameters,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(fe.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope(),r.length===0?E.TypeLiteral.nop():E.TypeLiteral.object({fields:r})}getConstructorEnvironmentArgs({baseUrl:e,environment:t}){let r=this.getEnvironmentValue({baseUrl:e,environment:t});return r==null?[]:[{name:"environment",value:r}]}getEnvironmentValue({baseUrl:e,environment:t}){if(e!=null&&t!=null){this.context.errors.add({severity:$.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(e!=null)return E.TypeLiteral.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let r=this.context.getEnvironmentTypeReferenceFromID(t);if(r==null){this.context.errors.add({severity:$.Warning,message:`Environment ${JSON.stringify(t)} was not found`});return}return E.TypeLiteral.reference(r)}if(this.context.isMultiEnvironmentValues(t))return this.context.validateMultiEnvironmentUrlValues(t)?E.TypeLiteral.object({fields:Object.entries(t).map(([r,a])=>({name:r,value:this.context.dynamicTypeLiteralMapper.convert({typeReference:Uc,value:a})}))}):void 0}}getConstructorAuthArgs({auth:e,values:t}){switch(e.type){case"basic":return t.type!=="basic"?(this.addAuthMismatchError(e,t),[]):this.getConstructorBasicAuthArg({auth:e,values:t});case"bearer":return t.type!=="bearer"?(this.addAuthMismatchError(e,t),[]):this.getConstructorBearerAuthArgs({auth:e,values:t});case"header":return t.type!=="header"?(this.addAuthMismatchError(e,t),[]):this.getConstructorHeaderAuthArgs({auth:e,values:t});case"oauth":return t.type!=="oauth"?(this.addAuthMismatchError(e,t),[]):this.getConstructorOAuthArgs({auth:e,values:t});case"inferred":return t.type!=="inferred"?(this.addAuthMismatchError(e,t),[]):(this.addWarning("The TypeScript SDK v2 Generator does not support Inferred auth scheme yet"),[]);default:q(e)}}addAuthMismatchError(e,t){this.context.errors.add({severity:$.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message})}addWarning(e){this.context.errors.add({severity:$.Warning,message:e})}getConstructorBasicAuthArg({auth:e,values:t}){return[{name:this.context.getPropertyName(e.username),value:E.TypeLiteral.string(t.username)},{name:this.context.getPropertyName(e.password),value:E.TypeLiteral.string(t.password)}]}getConstructorBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.token),value:E.TypeLiteral.string(t.token)}]}getConstructorHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.header.name.name),value:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getConstructorOAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.clientId),value:E.TypeLiteral.string(t.clientId)},{name:this.context.getPropertyName(e.clientSecret),value:E.TypeLiteral.string(t.clientSecret)}]}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let a of e){let o=t[a.name.wireValue],u=this.getConstructorHeaderArg({header:a,value:o});u!=null&&r.push(u)}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!E.TypeLiteral.isNop(r))return{name:this.context.getPropertyName(e.name.name),value:r}}callMethod({endpoint:e,snippet:t}){return E.invokeMethod({on:E.reference({name:Ha}),method:this.getMethod({endpoint:e}),async:!0,arguments_:this.getMethodArgs({endpoint:e,snippet:t})})}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:q(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){let r=[];this.context.errors.scope(fe.PathParameters);let a=[...this.context.ir.pathParameters??[],...e.pathParameters??[]];if(a.length>0&&r.push(...this.getPathParameters({namedParameters:a,snippet:t}).map(o=>o.value)),this.context.errors.unscope(),this.context.errors.scope(fe.RequestBody),e.body!=null){let o=this.getBodyRequestArg({body:e.body,value:t.requestBody});E.TypeLiteral.isNop(o)||r.push(o)}return 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,convertOpts:{isForRequest:!0}});default:q(e)}}getBytesBodyRequestArg({value:e}){return typeof e!="string"?(this.context.errors.add({severity:$.Critical,message:`Expected bytes value to be a string, got ${typeof e}`}),E.TypeLiteral.nop()):E.TypeLiteral.blob(e)}getMethodArgsForInlinedRequest({request:e,snippet:t}){let r=[],{inlinePathParameters:a,inlineFileProperties:o}={inlinePathParameters:this.context.customConfig?.inlinePathParameters??!0,inlineFileProperties:this.context.customConfig?.inlineFileProperties??!0};this.context.errors.scope(fe.PathParameters);let u=[];e.pathParameters!=null&&u.push(...this.getPathParameters({namedParameters:e.pathParameters,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(fe.RequestBody);let m=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})||r.push(...u.map(x=>x.value)),o||r.push(...m.fileFields.map(x=>x.value)),this.context.needsRequestParameter({request:e,inlinePathParameters:a,inlineFileProperties:o})&&r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:a})?u:[],filePropertyInfo:m})),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:a}){this.context.errors.scope(fe.QueryParameters);let u=this.context.associateQueryParametersByWireValue({parameters:e.queryParameters??[],values:t.queryParameters??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...R,convertOpts:{isForRequest:!0}})}));this.context.errors.unscope(),this.context.errors.scope(fe.Headers);let x=this.context.associateByWireValue({parameters:e.headers??[],values:t.headers??{}}).map(R=>({name:this.context.getPropertyName(R.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...R,convertOpts:{isForRequest:!0}})}));this.context.errors.unscope(),this.context.errors.scope(fe.RequestBody);let k=e.body!=null?this.getInlinedRequestBodyObjectFields({body:e.body,value:t.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),E.TypeLiteral.object({fields:[...r,...u,...x,...k]})}getInlinedRequestBodyObjectFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:e.value,value:t});case"referenced":{let a=this.getReferencedRequestBodyPropertyObjectField({body:e,value:t});return E.TypeLiteral.isNop(a.value)?[]:[a]}case"fileUpload":return this.getFileUploadRequestBodyObjectFields({filePropertyInfo:r});default:q(e)}}getFileUploadRequestBodyObjectFields({filePropertyInfo:e}){return this.context.customConfig?.inlineFileProperties??!0?[...e.fileFields,...e.bodyPropertyFields]:e.bodyPropertyFields}getReferencedRequestBodyPropertyObjectField({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,convertOpts:{isForRequest:!0}});default:q(e)}}getInlinedRequestBodyPropertyObjectFields({parameters:e,value:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:this.context.getRecord(t)??{}});for(let o of a)r.push({name:this.context.getPropertyName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...o,convertOpts:{isForRequest:!0}})});return r}getPathParameters({namedParameters:e,snippet:t}){let r=[],a=this.context.associateByWireValue({parameters:e,values:t.pathParameters??{},ignoreMissingParameters:!0});for(let o of a)r.push({name:this.context.getPropertyName(o.name.name),value:this.context.dynamicTypeLiteralMapper.convert({...o,convertOpts:{isForRequest:!0}})});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getMethodName(t)).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}};var pr=class extends Lt{constructor({ir:e,config:t}){super(new cr({ir:e,config:t}))}async generate(e,t={}){return super.generate(e,t)}generateSync(e){return super.generateSync(e)}async generateSnippetAst(e){return super.generateSnippetAst(e)}createSnippetGenerator(e){return new lr({context:e})}};0&&(module.exports={DynamicSnippetsGenerator});
25
25
  /*! Bundled license information:
26
26
 
27
27
  @jspm/core/nodelibs/browser/chunk-DtuTasat.js: