@fern-api/swift-dynamic-snippets 0.35.14 → 0.35.16
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 +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,7 @@ ${this.internalExpression.value}
|
|
|
22
22
|
`).forEach((m,l)=>{l===0?(e.write("/// - Throws: "),e.write(m)):(e.write("/// "),e.write(m)),e.newLine()})}writeMultilineText(e,r){let s=r.split(`
|
|
23
23
|
`);for(let m of s)e.write("/// "),e.write(m),e.newLine()}static sanitizeText(e){return e=e.replace(/\r\n/g,`
|
|
24
24
|
`).replace(/\r/g,`
|
|
25
|
-
`),e=e.replace(/\x00/g,""),e}};u();c();p();var ze=class extends B{constructor({accessLevel:e,indirect:r,name:s,conformances:m,cases:l,initializers:b,methods:v,nestedTypes:T,docs:I}){super();d(this,"name");d(this,"accessLevel");d(this,"indirect");d(this,"conformances");d(this,"cases");d(this,"initializers");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.name=s,this.indirect=r??!1,this.accessLevel=e,this.conformances=m??[],this.cases=l,this.initializers=b??[],this.methods=v??[],this.nestedTypes=T??[],this.docs=I}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.indirect&&e.write("indirect "),e.write(`enum ${k(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),e.write(" {"),e.newLine(),e.indent(),this.cases.forEach(r=>{r.docs!=null&&r.docs.write(e),e.write("case "),e.write(k(r.unsafeName)),r.associatedValue!=null&&(e.write("("),r.associatedValue.forEach((s,m)=>{m>0&&e.write(", "),s.write(e)}),e.write(")")),e.newLine()}),this.initializers.length>0&&(e.newLine(),this.initializers.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),this.methods.length>0&&(e.newLine(),this.methods.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),this.nestedTypes.length>0&&(e.newLine(),this.nestedTypes.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),e.dedent(),e.write("}")}};u();c();p();var Ge=class extends B{constructor({accessLevel:e,name:r,conformances:s,cases:m,docs:l}){super();d(this,"name");d(this,"accessLevel");d(this,"conformances");d(this,"cases");d(this,"docs");this.name=r,this.accessLevel=e,this.conformances=s??[],this.cases=m,this.docs=l}write(e){if(this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),e.write(`enum ${k(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),this.cases.length===0){e.write(" {}");return}e.write(" {"),e.newLine(),e.indent(),this.cases.forEach(r=>{r.docs!=null&&r.docs.write(e),e.write("case "),e.write(k(r.unsafeName)),r.rawValue!==r.unsafeName&&(e.write(" = "),e.write(`"${Dt(r.rawValue)}"`)),e.newLine()}),e.dedent(),e.write("}")}};u();c();p();var He=class extends B{constructor({name:e,conformances:r,initializers:s,computedProperties:m,methods:l,nestedTypes:b,docs:v}){super();d(this,"name");d(this,"conformances");d(this,"initializers");d(this,"computedProperties");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.name=e,this.conformances=r??[],this.initializers=s??[],this.computedProperties=m??[],this.methods=l??[],this.nestedTypes=b??[],this.docs=v}write(e){this.docs!=null&&this.docs.write(e),e.write(`extension ${$t(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),e.write(" {"),this.initializers.length>0&&(e.newLine(),e.indent(),this.initializers.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.computedProperties.length>0&&(e.newLine(),e.indent(),this.computedProperties.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.methods.length>0&&(e.newLine(),e.indent(),this.methods.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.nestedTypes.length>0&&(e.newLine(),e.indent(),this.nestedTypes.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),e.write("}")}};u();c();p();var Ke=class extends B{constructor({label:e,value:r}){super();d(this,"label");d(this,"value");this.label=e,this.value=r}write(e){this.label!=null&&(e.write(this.label),e.write(": ")),this.value.write(e)}};u();c();p();var Ye=class extends B{constructor({argumentLabel:e,unsafeName:r,escaping:s,type:m,defaultValue:l,docsContent:b}){super();d(this,"argumentLabel");d(this,"unsafeName");d(this,"escaping");d(this,"type");d(this,"defaultValue");d(this,"docsContent");this.argumentLabel=e,this.unsafeName=r,this.escaping=s,this.type=m,this.defaultValue=l,this.docsContent=b}write(e){this.argumentLabel==null?e.write("_ "):this.argumentLabel!==this.unsafeName&&(e.write(this.argumentLabel),e.write(" ")),e.write(this.unsafeName),e.write(": "),this.escaping&&e.write("@escaping "),this.type.write(e),this.defaultValue!=null&&(e.write(" = "),this.defaultValue.write(e))}};u();c();p();var Je=class extends B{constructor({accessLevel:e,convenience:r,failable:s,throws:m,parameters:l,body:b,multiline:v,docs:T}){super();d(this,"accessLevel");d(this,"convenience");d(this,"failable");d(this,"throws");d(this,"parameters");d(this,"body");d(this,"multiline");d(this,"docs");this.accessLevel=e,this.convenience=r,this.failable=s,this.throws=m,this.parameters=l??[],this.body=b??z.empty(),this.multiline=v,this.docs=T}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.convenience&&e.write("convenience "),e.write("init"),this.failable&&e.write("?"),e.write("("),this.multiline&&(e.newLine(),e.indent()),this.parameters.forEach((r,s)=>{s>0&&(e.write(","),this.multiline?e.newLine():e.write(" ")),r.write(e)}),this.multiline&&(e.newLine(),e.dedent()),e.write(") "),this.throws&&e.write("throws "),this.body.write(e)}};u();c();p();var qt=class i extends B{constructor({count:e=1}={}){super();d(this,"count");this.count=e}write(e){for(let r=0;r<this.count;r++)e.newLine()}static single(){return new i({count:1})}static double(){return new i({count:2})}static multiple(e){return new i({count:e})}};u();c();p();var Ze=class extends B{constructor({attributes:e,unsafeName:r,accessLevel:s,static_:m,parameters:l,async:b,throws:v,returnType:T,body:I,docs:C}){super();d(this,"attributes");d(this,"unsafeName");d(this,"accessLevel");d(this,"static_");d(this,"parameters");d(this,"async");d(this,"throws");d(this,"returnType");d(this,"body");d(this,"docs");this.attributes=e??[],this.unsafeName=r,this.accessLevel=s,this.static_=m,this.parameters=l??[],this.async=b,this.throws=v,this.returnType=T,this.body=I??z.empty(),this.docs=C}write(e){this.docs!=null&&this.docs.write(e),this.attributes.forEach(r=>{r.arguments?.length?pe.functionCall({unsafeName:`@${r.name}`,arguments_:r.arguments}).write(e):(e.write("@"),e.write(r.name)),e.write(" ")}),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.static_&&e.write("static "),e.write("func "),e.write(k(this.unsafeName)),e.write("("),this.parameters.forEach((r,s)=>{s>0&&e.write(", "),r.write(e)}),e.write(")"),this.async&&e.write(" async"),this.throws&&e.write(" throws"),e.write(" -> "),this.returnType.write(e),e.write(" "),this.body.write(e)}};u();c();p();var Wt=class extends B{constructor(e){super();d(this,"internalPattern");this.internalPattern=e}write(e){this.internalPattern.type==="enum-case-value-binding"?(e.write("."),e.write(this.internalPattern.caseName),e.write("("),e.write(this.internalPattern.declarationType),e.write(" "),e.write(this.internalPattern.referenceName),e.write(")")):A(this.internalPattern.type)}static enumCaseValueBinding(e){return new this({type:"enum-case-value-binding",...e})}};u();c();p();var Xe=class extends B{constructor({unsafeName:e,accessLevel:r,static_:s,declarationType:m,type:l,indirect:b,defaultValue:v,docs:T}){super();d(this,"unsafeName");d(this,"accessLevel");d(this,"static_");d(this,"declarationType");d(this,"type");d(this,"indirect");d(this,"defaultValue");d(this,"docs");this.unsafeName=e,this.accessLevel=r,this.static_=s,this.declarationType=m,this.type=l,this.indirect=b,this.defaultValue=v,this.docs=T}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.static_&&e.write("static "),e.write(this.declarationType),e.write(" "),e.write(k(this.unsafeName)),e.write(": "),this.type.write(e),this.defaultValue!=null&&(e.write(" = "),this.defaultValue.write(e))}};u();c();p();var ms={CaseIterable:"CaseIterable",Codable:"Codable",CodingKey:"CodingKey",Decodable:"Decodable",Encodable:"Encodable",Equatable:"Equatable",Error:"Error",Hashable:"Hashable",Sendable:"Sendable",MultipartFormDataConvertible:"MultipartFormDataConvertible"};u();c();p();var Qe=class extends B{constructor({attributes:e,accessLevel:r,name:s,conformances:m,properties:l,initializers:b,methods:v,nestedTypes:T,docs:I}){super();d(this,"attributes");d(this,"name");d(this,"accessLevel");d(this,"conformances");d(this,"properties");d(this,"initializers");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.attributes=e??[],this.name=s,this.accessLevel=r,this.conformances=m??[],this.properties=l??[],this.initializers=b??[],this.methods=v??[],this.nestedTypes=T??[],this.docs=I}write(e){this.docs!=null&&this.docs.write(e),this.attributes.forEach(v=>{v.arguments?.length?pe.functionCall({unsafeName:`@${v.name}`,arguments_:v.arguments}).write(e):(e.write("@"),e.write(v.name)),e.write(" ")}),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),e.write(`struct ${k(this.name)}`),this.conformances.forEach((v,T)=>{T===0?e.write(": "):T>0&&e.write(", "),e.write(v)}),e.write(" {"),e.newLine(),e.indent();let r=this.properties.length>0,s=this.initializers.length>0,m=this.methods.length>0,l=this.nestedTypes.length>0;this.properties.forEach(v=>{v.write(e),e.newLine()});let b=r;s&&(b&&e.newLine(),this.initializers.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()}),b=!0),m&&(b&&e.newLine(),this.methods.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()}),b=!0),l&&(b&&e.newLine(),this.nestedTypes.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()})),e.dedent(),e.write("}")}};u();c();p();u();c();p();var Np={Http:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"HTTP",symbols:[{name:"HTTP",shape:{type:"enum-container"}}]},MultipartFormData:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormData",symbols:[{name:"MultipartFormData",shape:{type:"class"}}]},MultipartFormDataConvertible:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormDataConvertible",symbols:[{name:"MultipartFormDataConvertible",shape:{type:"protocol"}}]},MultipartFormField:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormField",symbols:[{name:"MultipartFormField",shape:{type:"enum-with-associated-values"}}]},QueryParameter:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"QueryParameter",symbols:[{name:"QueryParameter",shape:{type:"enum-with-associated-values"}}]},DecoderPlusAdditionalProperties:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Decoder+AdditionalProperties",symbols:[]},EncodableValue:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"EncodableValue",symbols:[{name:"EncodableValue",shape:{type:"struct"}}]},EncoderPlusAdditionalProperties:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Encoder+AdditionalProperties",symbols:[]},JSONEncoderPlusEncodableValue:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"JSONEncoder+EncodableValue",symbols:[]},KeyedDecodingContainerPlusNullable:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"KeyedDecodingContainer+Nullable",symbols:[]},KeyedEncodingContainerPlusNullable:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"KeyedEncodingContainer+Nullable",symbols:[]},Serde:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Serde",symbols:[{name:"Serde",shape:{type:"class"}}]},StringKey:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"StringKey",symbols:[{name:"StringKey",shape:{type:"struct"}}]},DataPlusString:{relativePathToDir:"Core",filenameWithoutExtension:"Data+String",symbols:[]},StringPlusUrlEncoding:{relativePathToDir:"Core",filenameWithoutExtension:"String+URLEncoding",symbols:[]},CalendarDate:{relativePathToDir:"Public",filenameWithoutExtension:"CalendarDate",symbols:[{name:"CalendarDate",shape:{type:"struct"}}]},FormFile:{relativePathToDir:"Public",filenameWithoutExtension:"FormFile",symbols:[{name:"FormFile",shape:{type:"struct"}}]},HTTPError:{relativePathToDir:"Public",filenameWithoutExtension:"HTTPError",symbols:[{name:"HTTPError",shape:{type:"struct"}}]},Indirect:{relativePathToDir:"Public",filenameWithoutExtension:"Indirect",symbols:[{name:"Indirect",shape:{type:"class"}}]},JsonValue:{relativePathToDir:"Public",filenameWithoutExtension:"JSONValue",symbols:[{name:"JSONValue",shape:{type:"enum-with-associated-values"}}]},Networking:{relativePathToDir:"Public",filenameWithoutExtension:"Networking",symbols:[{name:"Networking",shape:{type:"enum-container"}}]},Nullable:{relativePathToDir:"Public",filenameWithoutExtension:"Nullable",symbols:[{name:"Nullable",shape:{type:"enum-with-associated-values"}}]},RequestOptions:{relativePathToDir:"Public",filenameWithoutExtension:"RequestOptions",symbols:[{name:"RequestOptions",shape:{type:"struct"}}]}};u();c();p();var R=class R{constructor(t,e,r){d(this,"id");d(this,"name");d(this,"shape");this.id=t,this.name=e,this.shape=r}static isSwiftSymbol(t){return R.SWIFT_SYMBOL_ID===t||t.startsWith(`${R.SWIFT_SYMBOL_ID}.`)}static isSwiftSymbolName(t){return t in R.swiftTypeSymbolsByName}static isFoundationSymbol(t){return R.FOUNDATION_SYMBOL_ID===t||t.startsWith(`${R.FOUNDATION_SYMBOL_ID}.`)}static isFoundationSymbolName(t){return t in R.foundationTypeSymbolsByName}static isCustomSymbol(t){return!R.isSwiftSymbol(t)&&!R.isFoundationSymbol(t)}static create(t,e,r){return new R(t,e,r)}static swiftType(t){return R.create(`${R.SWIFT_SYMBOL_ID}.${t}`,t,{type:"system"})}static foundationType(t){return R.create(`${R.FOUNDATION_SYMBOL_ID}.${t}`,t,{type:"system"})}get isSwiftSymbol(){return R.isSwiftSymbol(this.id)}get isFoundationSymbol(){return R.isFoundationSymbol(this.id)}get isCustomSymbol(){return R.isCustomSymbol(this.id)}};d(R,"SWIFT_SYMBOL_NAME","Swift"),d(R,"SWIFT_SYMBOL_ID",R.SWIFT_SYMBOL_NAME),d(R,"swiftTypeSymbolsByName",{String:R.swiftType("String"),Bool:R.swiftType("Bool"),Int:R.swiftType("Int"),Int64:R.swiftType("Int64"),UInt:R.swiftType("UInt"),UInt64:R.swiftType("UInt64"),Float:R.swiftType("Float"),Double:R.swiftType("Double"),Void:R.swiftType("Void"),Encoder:R.swiftType("Encoder"),Decoder:R.swiftType("Decoder"),Any:R.swiftType("Any")}),d(R,"swiftTypeSymbols",Object.values(R.swiftTypeSymbolsByName)),d(R,"FOUNDATION_SYMBOL_NAME","Foundation"),d(R,"FOUNDATION_SYMBOL_ID",R.FOUNDATION_SYMBOL_NAME),d(R,"foundationTypeSymbolsByName",{Data:R.foundationType("Data"),Date:R.foundationType("Date"),UUID:R.foundationType("UUID")}),d(R,"foundationTypeSymbols",Object.values(R.foundationTypeSymbolsByName));var q=R;u();c();p();u();c();p();u();c();p();u();c();p();var Vt=class{constructor(t,e){d(this,"id");d(this,"name");d(this,"childrenByName");this.id=t,this.name=e,this.childrenByName=new Map}get children(){return Array.from(this.childrenByName.values())}addChild(t){if(this.childrenByName.has(t.name))throw new Error(`A child with the name '${t.name}' already exists in module '${this.name}'.`);this.childrenByName.set(t.name,t)}getChildByName(t){return this.childrenByName.get(t)}},jt=class extends Vt{constructor(e,r){super(e,r);d(this,"kind","module");d(this,"imports");d(this,"parent",null);this.imports=[]}addImport(e){this.imports.push(e)}get qualifiedPath(){return[this.name]}get qualifiedName(){return this.name}},zt=class extends Vt{constructor(e,r,s){super(r,e);d(this,"kind","type");d(this,"shape");d(this,"parent");this.parent=null,this.shape=s}getNearestModuleAncestorOrThrow(){let e=this.parent;for(;e!==null&&e.kind!=="module";)e=e.parent;return Q(e,`No module ancestor found for type symbol '${this.id}'`),e}get qualifiedPath(){return[...this.parent?.qualifiedPath??[],this.name]}get qualifiedName(){return this.qualifiedPath.join(".")}};var yt=class{constructor(){d(this,"symbolsById",new Map)}createModuleSymbol({symbolId:t,symbolName:e}){this.validateSymbolNotExists(t);let r=new jt(t,e);return this.symbolsById.set(t,r),r}createTypeSymbol({symbolId:t,symbolName:e,shape:r}){this.validateSymbolNotExists(t);let s=new zt(e,t,r);return this.symbolsById.set(t,s),s}addImportRelation({clientSymbolId:t,importedSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e);if(r.kind!=="module"||s.kind!=="module")throw new Error(`Client module '${r.id}' and imported module '${s.id}' must both be module symbols.`);r.addImport(s)}nestSymbol({parentSymbolId:t,childSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e);r.addChild(s),s.parent=r}reference({fromSymbolId:t,targetSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e),m=s.qualifiedPath;for(let l=1;l<=m.length;l++){let b=m.slice(m.length-l);if(this.resolvePath(r,b)?.id===s.id)return b.join(".")}return s.qualifiedName}resolveReference({fromSymbolId:t,reference:e}){let r=this.getSymbolByIdOrThrow(t),s=e.split(".").filter(m=>m.length>0);return this.resolvePath(r,s)}resolvePath(t,e){let[r,...s]=e;if(r===void 0)return null;let m=this.resolveFirstSegment(t,r);if(m===null)return null;let l=m;for(let b=0;b<s.length;b++){let v=s[b];if(ne(v),l=l.getChildByName(v)??null,l===null)return null}return l}resolveFirstSegment(t,e){let r=t;for(;r!==null;){let l=r.getChildByName(e);if(l)return l;r=r.parent}let s=t.kind==="module"?t:t.getNearestModuleAncestorOrThrow();if(s.name===e)return s;for(let l of s.imports)if(l.name===e)return l;let m=null;for(let l of s.imports){let b=l.getChildByName(e);if(b){if(m!=null&&m.id!==b.id)return null;m=b}}return m}getSymbolByIdOrThrow(t){let e=this.symbolsById.get(t);return ne(e,`A symbol with the ID '${t}' was not found in the registry.`),e}getSymbolById(t){return this.symbolsById.get(t)??null}validateSymbolNotExists(t){if(this.symbolsById.has(t))throw new Error(`A symbol with the ID '${t}' already exists in the registry.`)}};var Tr=class i{constructor(t,e,r){d(this,"graph");d(this,"swiftSymbol");d(this,"foundationSymbol");d(this,"registeredSourceModule");d(this,"registeredTestModule");this.graph=t,this.swiftSymbol=e,this.foundationSymbol=r,this.registeredSourceModule=null,this.registeredTestModule=null}static create(){let{graph:t,swiftSymbol:e,foundationSymbol:r}=i.createGraph();return new i(t,e,r)}static createGraph(){let t=new yt,e=()=>{let l=t.createModuleSymbol({symbolId:q.SWIFT_SYMBOL_ID,symbolName:q.SWIFT_SYMBOL_NAME});return q.swiftTypeSymbols.forEach(b=>{let v=t.createTypeSymbol({symbolId:b.id,symbolName:b.name,shape:{type:"system"}});t.nestSymbol({parentSymbolId:l.id,childSymbolId:v.id})}),l},r=()=>{let l=t.createModuleSymbol({symbolId:q.FOUNDATION_SYMBOL_ID,symbolName:q.FOUNDATION_SYMBOL_NAME});return q.foundationTypeSymbols.forEach(b=>{let v=t.createTypeSymbol({symbolId:b.id,symbolName:b.name,shape:{type:"system"}});t.nestSymbol({parentSymbolId:l.id,childSymbolId:v.id})}),l},s=e(),m=r();return{graph:t,swiftSymbol:s,foundationSymbol:m}}getRegisteredSourceModuleSymbolOrThrow(){return Q(this.registeredSourceModule,"Module symbol not found."),q.create(this.registeredSourceModule.id,this.registeredSourceModule.name,{type:"other"})}getRegisteredTestModuleSymbolOrThrow(){return Q(this.registeredTestModule,"Module symbol not found."),q.create(this.registeredTestModule.id,this.registeredTestModule.name,{type:"other"})}getSymbolByIdOrThrow(t){let e=this.graph.getSymbolById(t);return Q(e,`Symbol with ID '${t}' not found in registry.`),q.create(e.id,e.name,e.kind==="type"?e.shape:{type:"other"})}registerSourceModule(t){let e=t,r=this.graph.createModuleSymbol({symbolId:e,symbolName:t});return r.addImport(this.swiftSymbol),r.addImport(this.foundationSymbol),this.registeredSourceModule=r,q.create(r.id,r.name,{type:"other"})}registerTestModule(t){let e=t,r=this.graph.createModuleSymbol({symbolId:e,symbolName:t});return r.addImport(this.swiftSymbol),r.addImport(this.foundationSymbol),Q(this.registeredSourceModule,"Cannot register a test module before registering a source module."),r.addImport(this.registeredSourceModule),this.registeredTestModule=r,q.create(r.id,r.name,{type:"other"})}registerSourceModuleType(t,e){Q(this.registeredSourceModule,"Cannot register a type before registering a module.");let r=this.inferSymbolIdForSourceModuleType(t),s=this.graph.createTypeSymbol({symbolId:r,symbolName:t,shape:e});return this.graph.nestSymbol({parentSymbolId:this.registeredSourceModule.id,childSymbolId:s.id}),q.create(s.id,s.name,e)}registerTestModuleType(t,e){Q(this.registeredTestModule,"Cannot register a type before registering a module.");let r=this.inferSymbolIdForTestModuleType(t),s=this.graph.createTypeSymbol({symbolId:r,symbolName:t,shape:e});return this.graph.nestSymbol({parentSymbolId:this.registeredTestModule.id,childSymbolId:s.id}),q.create(s.id,s.name,e)}registerNestedType({parentSymbol:t,symbolName:e,shape:r}){let s=typeof t=="string"?t:t.id,m=this.inferSymbolIdForNestedType(s,e),l=this.graph.createTypeSymbol({symbolId:m,symbolName:e,shape:r});return this.graph.nestSymbol({parentSymbolId:s,childSymbolId:l.id}),q.create(l.id,l.name,r)}reference({fromSymbol:t,toSymbol:e}){let r=typeof t=="string"?t:t.id,s=typeof e=="string"?e:e.id;return this.graph.reference({fromSymbolId:r,targetSymbolId:s})}resolveReference({fromSymbol:t,reference:e}){let r=typeof t=="string"?t:t.id,s=this.graph.resolveReference({fromSymbolId:r,reference:e});return s?q.create(s.id,s.name,s.kind==="type"?s.shape:{type:"other"}):null}inferSymbolIdForSourceModuleType(t){return Q(this.registeredSourceModule,"Cannot get symbol id for a type before registering a module."),`${this.registeredSourceModule.id}.${t}`}inferSymbolIdForTestModuleType(t){return Q(this.registeredTestModule,"Cannot get symbol id for a type before registering a module."),`${this.registeredTestModule.id}.${t}`}inferSymbolIdForNestedType(t,e){return`${t}.${e}`}};u();c();p();var Rp={ClientError:{relativePath:"",filenameWithoutExtension:i=>(ar(i.errorEnumName),i.errorEnumName)},HTTPClient:{relativePath:"Core/Networking",filenameWithoutExtension:()=>"HTTPClient"},ClientConfig:{relativePath:"Public",filenameWithoutExtension:()=>"ClientConfig"}};var Gt=class i extends B{constructor(e){super();d(this,"variant");this.variant=e}nonOptional(){return i.nonOptional(this)}nonNullable(){return i.nonNullable(this)}getReferenceIfSymbolType(){return this.variant.type==="symbol"?this.variant.symbol:null}write(e){let{variant:r}=this;switch(r.type){case"symbol":e.write(q.isSwiftSymbolName(r.symbol)||q.isFoundationSymbolName(r.symbol)?r.symbol:$t(r.symbol));break;case"generic":{r.reference.write(e),r.arguments.length>0&&(e.write("<"),r.arguments.forEach((s,m)=>{s.write(e),m<r.arguments.length-1&&e.write(", ")}),e.write(">"));break}case"tuple":e.write("("),r.elements.forEach((s,m)=>{m>0&&e.write(", "),s.write(e)}),e.write(")");break;case"array":e.write("["),r.elementType.write(e),e.write("]");break;case"dictionary":e.write("["),r.keyType.write(e),e.write(": "),r.valueType.write(e),e.write("]");break;case"optional":r.valueType.write(e),e.write("?");break;case"nullable":e.write("Nullable<"),r.valueType.write(e),e.write(">");break;case"member-access":r.target.write(e),e.write("."),e.write(r.memberName);break;default:A(r)}}equals(e){switch(this.variant.type){case"symbol":return e.variant.type==="symbol"&&this.variant.symbol===e.variant.symbol;case"generic":return e.variant.type==="generic"&&this.variant.reference.equals(e.variant.reference)&&this.variant.arguments.every((r,s)=>e.variant.type==="generic"&&e.variant.arguments[s]&&r.equals(e.variant.arguments[s]));case"tuple":return e.variant.type==="tuple"&&this.variant.elements.every((r,s)=>e.variant.type==="tuple"&&e.variant.elements[s]&&r.equals(e.variant.elements[s]));case"array":return e.variant.type==="array"&&this.variant.elementType.equals(e.variant.elementType);case"dictionary":return e.variant.type==="dictionary"&&this.variant.keyType.equals(e.variant.keyType)&&this.variant.valueType.equals(e.variant.valueType);case"optional":return e.variant.type=="optional"&&this.variant.valueType.equals(e.variant.valueType);case"nullable":return e.variant.type==="nullable"&&this.variant.valueType.equals(e.variant.valueType);case"member-access":return e.variant.type==="member-access"&&this.variant.target.equals(e.variant.target)&&this.variant.memberName===e.variant.memberName;default:A(this.variant)}}static symbol(e){return new this({type:"symbol",symbol:e})}static generic(e,r){return new this({type:"generic",reference:e,arguments:r})}static tuple(e){return new this({type:"tuple",elements:e})}static array(e){return new this({type:"array",elementType:e})}static dictionary(e,r){return new this({type:"dictionary",keyType:e,valueType:r})}static optional(e){return e.variant.type==="optional"?e:new this({type:"optional",valueType:e})}static nullable(e){return e.variant.type==="nullable"?e:new this({type:"nullable",valueType:e})}static memberAccess(e,r){return new this({type:"member-access",target:e,memberName:r})}static nonOptional(e){return e.variant.type==="optional"?i.nonOptional(e.variant.valueType):e}static nonNullable(e){return e.variant.type==="nullable"?i.nonNullable(e.variant.valueType):e}static unqualifiedToSwiftType(e){return i.symbol(e)}static unqualifiedToFoundationType(e){return i.symbol(e)}};function Ap(i){return new $e(i)}function Cp(i){return new z(i)}function Bp(i){return new qe(i)}function Lp(i){return new Ve(i)}function Fp(i){return new je(i)}function Mp(i){return new ze(i)}function Op(i){return new Ge(i)}function Pp(i){return new He(i)}function kp(i){return new Ke(i)}function Up(i){return new Ye(i)}function _p(i){return new Je(i)}function Dp(i){return new Ze(i)}function $p(i){return new Xe(i)}function qp(i){return new Qe(i)}u();c();p();function fs(i){return H(te(i))}u();c();p();var Ht=class{constructor({context:t}){d(this,"context");this.context=t}convert(t){let{fromSymbol:e,typeReference:r,value:s,as:m}=t;switch(r.type){case"list":return this.convertList({fromSymbol:e,list:r.value,value:s});case"literal":{if(r.value.type==="string")return S.Expression.enumCaseShorthand(Ae.generateEnumCaseLabel(r.value.value));if(r.value.type==="boolean")return S.Expression.boolLiteral(r.value.value);A(r.value);break}case"map":return this.convertMap({fromSymbol:e,map:r,value:s});case"named":{let l=this.context.resolveNamedType({typeId:r.value});return l==null?S.Expression.nop():this.convertNamed({fromSymbol:e,typeId:r.value,named:l,value:s,as:m})}case"nullable":return this.context.customConfig?.nullableAsOptional?this.convert({fromSymbol:e,typeReference:r.value,value:s,as:m}):this.convertNullable({fromSymbol:e,nullable:r,value:s,as:m});case"optional":return this.convert({fromSymbol:e,typeReference:r.value,value:s,as:m});case"primitive":return this.convertPrimitive({primitive:r.value,value:s,as:m});case"set":return S.Expression.nop();case"unknown":return this.convertUnknown(s);default:A(r)}}convertList({fromSymbol:t,list:e,value:r}){return Array.isArray(r)?S.Expression.arrayLiteral({elements:r.map((s,m)=>{this.context.errors.scope({index:m});try{return this.convert({fromSymbol:t,typeReference:e,value:s})}finally{this.context.errors.unscope()}}),multiline:!0}):(this.context.errors.add({severity:M.Critical,message:`Expected array but got: ${typeof r}`}),S.Expression.nop())}convertMap({fromSymbol:t,map:e,value:r}){return typeof r!="object"||r==null?(this.context.errors.add({severity:M.Critical,message:`Expected object but got: ${r==null?"null":typeof r}`}),S.Expression.nop()):S.Expression.dictionaryLiteral({entries:Object.entries(r).map(([s,m])=>{this.context.errors.scope(s);try{return[this.convert({fromSymbol:t,typeReference:e.key,value:s,as:"mapKey"}),this.convert({fromSymbol:t,typeReference:e.value,value:m,as:"mapValue"})]}finally{this.context.errors.unscope()}}),multiline:!0})}convertNamed({fromSymbol:t,typeId:e,named:r,value:s,as:m}){switch(r.type){case"alias":return this.convert({fromSymbol:t,typeReference:r.typeReference,value:s,as:m});case"discriminatedUnion":{let l=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e);return this.convertDiscriminatedUnion({fromSymbol:t,unionSymbol:l,discriminatedUnion:r,value:s})}case"enum":return this.convertEnum({enum_:r,value:s});case"object":return this.convertObject({fromSymbol:t,typeId:e,object_:r,value:s});case"undiscriminatedUnion":{let l=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e);return this.convertUndiscriminatedUnion({fromSymbol:t,unionSymbol:l,undiscriminatedUnion:r,value:s})}default:A(r)}}convertNullable({fromSymbol:t,nullable:e,value:r,as:s}){return r==null?S.Expression.enumCaseShorthand("null"):S.Expression.contextualMethodCall({methodName:"value",arguments_:[S.functionArgument({value:this.convert({fromSymbol:t,typeReference:e.value,value:r,as:s})})]})}convertDiscriminatedUnion({fromSymbol:t,discriminatedUnion:e,unionSymbol:r,value:s}){let m=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:s});if(m==null)return S.Expression.nop();let l=m.singleDiscriminatedUnionType,b=Ft.sanitizeToCamelCase(l.discriminantValue.name.camelCase.unsafeName);switch(l.type){case"samePropertiesAsObject":{let v=this.context.resolveNamedType({typeId:l.typeId});if(v==null)return S.Expression.nop();let T=this.convertNamed({fromSymbol:t,typeId:l.typeId,named:v,value:m.value});return S.Expression.methodCall({target:S.Expression.reference(r.name),methodName:b,arguments_:[S.functionArgument({value:T})],multiline:!0})}case"singleProperty":try{this.context.errors.scope(l.discriminantValue.wireValue);let v=this.context.getRecord(m.value);if(v==null)return S.Expression.nop();let T=new Set((l.properties??[]).map(_=>_.name.wireValue)),I=Object.keys(v).find(_=>!T.has(_))??"value",C=this.convert({fromSymbol:t,typeReference:l.typeReference,value:v[I]});return S.Expression.methodCall({target:S.Expression.reference(r.name),methodName:b,arguments_:[S.functionArgument({value:C})],multiline:!0})}finally{this.context.errors.unscope()}case"noProperties":return S.Expression.memberAccess({target:S.Expression.reference(r.name),memberName:b});default:A(l)}}convertEnum({enum_:t,value:e}){let r=this.getEnumValue({enum_:t,value:e});return r==null?S.Expression.nop():S.Expression.enumCaseShorthand(r.name.camelCase.unsafeName)}getEnumValue({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:M.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let r=t.values.find(s=>s.wireValue===e);if(r==null){this.context.errors.add({severity:M.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return r}convertObject({fromSymbol:t,typeId:e,object_:r,value:s}){let m=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e),l=this.context.getExampleObjectProperties({parameters:r.properties,snippetObject:s}),b=new Map(l.map(T=>[T.name.wireValue,T])),v=r.properties.map(T=>{let I=b.get(T.name.wireValue);return I??(T.typeReference.type==="literal"?{name:T.name,typeReference:T.typeReference,value:void 0}:null)}).filter(T=>T!=null);return S.Expression.structInitialization({unsafeName:m.name,arguments_:v.map(T=>{let I=this.convert({fromSymbol:t,typeReference:T.typeReference,value:T.value});return I.isNop()?null:S.functionArgument({label:De(T.name.name.camelCase.unsafeName),value:I})}).filter(T=>T!=null),multiline:!0})}convertUndiscriminatedUnion({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s}){let m=this.findMatchingUndiscriminatedUnionType({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s});return m??S.Expression.nop()}findMatchingUndiscriminatedUnionType({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s}){let m=this.context.nameRegistry.getAllUndiscriminatedUnionVariantsOrThrow(e);for(let l of r.types){let b=this.context.errors.size();try{let v=this.convert({fromSymbol:t,typeReference:l,value:s}),T=this.context.getSwiftTypeReferenceFromScope(l,t),I=m.find(C=>C.swiftType.equals(T));if(I==null){this.context.errors.truncate(b);continue}return S.Expression.methodCall({target:S.Expression.reference(e.name),methodName:I.caseName,arguments_:[S.functionArgument({value:v})],multiline:!0})}catch{this.context.errors.truncate(b);continue}}this.context.errors.add({severity:M.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof s}" value`})}convertUnknown(t){switch(typeof t){case"boolean":return S.Expression.contextualMethodCall({methodName:"bool",arguments_:[S.functionArgument({value:S.Expression.boolLiteral(t)})]});case"string":return S.Expression.contextualMethodCall({methodName:"string",arguments_:[S.functionArgument({value:S.Expression.escapedStringLiteral(t)})]});case"number":return S.Expression.contextualMethodCall({methodName:"number",arguments_:[S.functionArgument({value:S.Expression.numberLiteral(t)})]});case"object":return t===null?S.Expression.enumCaseShorthand("null"):Array.isArray(t)?S.Expression.contextualMethodCall({methodName:"array",arguments_:[S.functionArgument({value:S.Expression.arrayLiteral({elements:t.map(e=>this.convertUnknown(e)),multiline:!0})})]}):S.Expression.contextualMethodCall({methodName:"object",arguments_:[S.functionArgument({value:S.Expression.dictionaryLiteral({entries:Object.entries(t).map(([e,r])=>[S.Expression.escapedStringLiteral(e),this.convertUnknown(r)]),multiline:!0})})]});default:throw new Error(`Internal error; unsupported unknown type: ${typeof t}`)}}convertPrimitive({primitive:t,value:e,as:r}){switch(t){case"INTEGER":case"UINT":case"LONG":case"UINT_64":case"FLOAT":case"DOUBLE":{let s=this.getValueAsNumber({value:e,as:r});return s==null?S.Expression.nop():S.Expression.numberLiteral(s)}case"BOOLEAN":{let s=this.getValueAsBoolean({value:e,as:r});return s==null?S.Expression.nop():S.Expression.boolLiteral(s)}case"STRING":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.escapedStringLiteral(s)}case"DATE":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.calendarDateLiteral(s)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let s=this.context.getValueAsString({value:e});if(s==null)return S.Expression.nop();let m=new Date(s).getTime(),l=Math.round(m/1e3),v=new Date(l*1e3).toISOString().replace(/\.\d{3}Z$/,"Z");return S.Expression.dateLiteral(v)}case"UUID":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.uuidLiteral(s)}case"BASE_64":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.escapedStringLiteral(s)}case"BIG_INTEGER":return this.context.getValueAsString({value:e})==null?S.Expression.nop():S.Expression.nop();default:A(t)}}getValueAsNumber({value:t,as:e}){let r=e==="mapKey"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:t,as:e}){let r=(()=>{switch(e){case"mapKey":return t==="true"?!0:t==="false"?!1:t;case"mapValue":case void 0:return t;default:A(e)}})();return this.context.getValueAsBoolean({value:r})}};u();c();p();var Kt=class{constructor({context:t}){d(this,"context");this.context=t}getFilePropertyInfo({fromSymbol:t,body:e,value:r}){let s={fileFields:[],bodyPropertyFields:[],orderedFields:[]},m=this.context.getRecord(r)??{};for(let l of e.properties)switch(l.type){case"file":{let b=S.functionArgument({label:De(l.name.camelCase.unsafeName),value:this.getSingleFileProperty({property:l,record:m})});s.fileFields.push(b),s.orderedFields.push(b);break}case"fileArray":{let b=S.functionArgument({label:De(l.name.camelCase.unsafeName),value:this.getArrayFileProperty({property:l,record:m})});s.fileFields.push(b),s.orderedFields.push(b);break}case"bodyProperty":{let b=S.functionArgument({label:De(l.name.name.camelCase.unsafeName),value:this.getBodyProperty({fromSymbol:t,property:l,record:m})});s.bodyPropertyFields.push(b),s.orderedFields.push(b);break}default:A(l)}return s}getSingleFileProperty({property:t,record:e}){let r=this.context.getSingleFileValue({property:t,record:e});return S.Expression.contextualMethodCall({methodName:"init",arguments_:[S.functionArgument({label:"data",value:S.Expression.dataLiteral(r??"")})]})}getArrayFileProperty({property:t,record:e}){let r=this.context.getFileArrayValues({property:t,record:e});return S.Expression.arrayLiteral({elements:(r??[]).map(s=>S.Expression.contextualMethodCall({methodName:"init",arguments_:[S.functionArgument({label:"data",value:S.Expression.dataLiteral(s)})]})),multiline:!0})}getBodyProperty({fromSymbol:t,property:e,record:r}){let s=r[e.name.wireValue];return s==null?S.Expression.nop():this.context.dynamicTypeLiteralMapper.convert({fromSymbol:t,typeReference:e.typeReference,value:s})}};u();c();p();function ds({parentSymbol:i,registry:t,namedType:e,context:r}){ie(e,"type")._visit({object:s=>{Ir({parentSymbol:i,registry:t,properties:s.properties})},discriminatedUnion:s=>{Object.values(s.types).forEach(m=>{ie(m,"type")._visit({noProperties:K,samePropertiesAsObject:K,singleProperty:l=>{se({parentSymbol:i,registry:t,typeReference:l.typeReference})},_other:K})})},undiscriminatedUnion:s=>{s.types.forEach(m=>{se({parentSymbol:i,registry:t,typeReference:m})})},alias:K,enum:K,_other:K})}function Ir({parentSymbol:i,registry:t,properties:e}){e.forEach(r=>{se({parentSymbol:i,registry:t,typeReference:r.typeReference})})}function se({parentSymbol:i,registry:t,typeReference:e}){ie(e,"type")._visit({list:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},literal:r=>{ie(r.value,"type")._visit({string:s=>{t.registerNestedLiteralEnumSymbol({parentSymbol:i,literalValue:s.value})},boolean:K,_other:K})},map:r=>{se({parentSymbol:i,registry:t,typeReference:r.key}),se({parentSymbol:i,registry:t,typeReference:r.value})},named:K,nullable:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},optional:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},primitive:K,set:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},unknown:K,_other:K})}u();c();p();function hs({parentSymbol:i,registry:t,namedType:e,context:r}){if(e.type==="undiscriminatedUnion"){let s=e.types.map(m=>{let l=r.getSwiftTypeReferenceFromScope(m,i);return{swiftType:l,caseName:Ot.inferCaseNameForTypeReference(i,l,t),docsContent:void 0}});t.registerUndiscriminatedUnionVariants({parentSymbol:i,variants:s})}}var Yt=class i extends ft{constructor({ir:e,config:r,options:s,sharedNameRegistry:m}){super({ir:e,config:r,options:s});d(this,"ir");d(this,"customConfig");d(this,"dynamicTypeLiteralMapper");d(this,"filePropertyMapper");d(this,"nameRegistry");this.ir=e,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeLiteralMapper=new Ht({context:this}),this.filePropertyMapper=new Kt({context:this}),m!=null?this.nameRegistry=m:(this.nameRegistry=_t.create(),this.registerSourceSymbols(this.nameRegistry,e))}registerSourceSymbols(e,r){let s=fs(this.config.workspaceName),m=e.registerSourceModuleSymbol({configModuleName:this.customConfig?.moduleName,apiNamePascalCase:s,asIsSymbols:Object.values(S.SourceAsIsFileSpecs).flatMap(b=>b.symbols)});return e.registerRootClientSymbol({configClientClassName:this.customConfig?.clientClassName,registeredSourceModuleName:m.name}),lr(S.SourceTemplateFileSpecs).forEach(([b])=>{switch(b){case"ClientError":e.registerErrorEnumSymbol(m.name);break;case"HTTPClient":e.registerSourceStaticSymbol(b,{type:"class"});break;case"ClientConfig":e.registerSourceStaticSymbol(b,{type:"class"});break;default:A(b)}}),e.registerEnvironmentSymbol({configEnvironmentEnumName:this.customConfig?.environmentEnumName,registeredSourceModuleName:m.name}),Object.entries(r.types).map(([b,v])=>{let T=ie(v,"type")._visit({alias:()=>({type:"struct"}),enum:()=>({type:"enum-with-raw-values"}),object:()=>({type:"struct"}),discriminatedUnion:()=>({type:"enum-with-associated-values"}),undiscriminatedUnion:()=>({type:"enum-with-associated-values"}),_other:()=>({type:"other"})}),I=e.registerSchemaTypeSymbol(b,v.declaration.name.pascalCase.unsafeName,T);return{namedType:v,registeredSymbol:I}}).forEach(({namedType:b,registeredSymbol:v})=>{ds({parentSymbol:v,registry:e,namedType:b,context:this}),hs({parentSymbol:v,registry:e,namedType:b,context:this})}),e.registerRequestsContainerSymbol(),Object.entries(r.endpoints).forEach(([b,v])=>{if(v.request.type==="inlined"){if(v.request.body?.type==="properties"){let T=e.registerRequestTypeSymbol({endpointId:b,requestNamePascalCase:v.request.declaration.name.pascalCase.unsafeName});Ir({parentSymbol:T,registry:e,properties:v.request.body.value})}v.request.body?.type==="fileUpload"&&e.registerRequestTypeSymbol({endpointId:b,requestNamePascalCase:v.request.declaration.name.pascalCase.unsafeName}),v.request.queryParameters?.forEach(T=>{se({parentSymbol:m,registry:e,typeReference:T.typeReference})})}}),e}getNamedTypeOrThrow(e){let r=this.ir.types[e];return ne(r,`Type declaration with the id '${e}' not found`),r}getPropertiesOfDiscriminatedUnionVariant(e){let r=this.getNamedTypeOrThrow(e);return ie(r,"type")._visit({alias:()=>[],enum:()=>[],object:s=>s.properties,discriminatedUnion:()=>[],undiscriminatedUnion:()=>[],_other:()=>[]})}getSwiftTypeReferenceFromScope(e,r){let s=this.createReferencer(r);return ie(e,"type")._visit({list:m=>S.TypeReference.array(this.getSwiftTypeReferenceFromScope(m.value,r)),literal:m=>ie(m.value,"type")._visit({boolean:()=>s.referenceSwiftType("Bool"),string:l=>{let b=this.nameRegistry.getNestedLiteralEnumSymbol(r,l.value);return b==null?s.referenceAsIsType("JSONValue"):s.referenceType(b)},_other:()=>s.referenceAsIsType("JSONValue")}),map:m=>S.TypeReference.dictionary(this.getSwiftTypeReferenceFromScope(m.key,r),this.getSwiftTypeReferenceFromScope(m.value,r)),named:m=>{let l=this.nameRegistry.getSchemaTypeSymbolOrThrow(m.value),b=this.nameRegistry.reference({fromSymbol:r,toSymbol:l});return S.TypeReference.symbol(b)},nullable:m=>this.customConfig?.nullableAsOptional?S.TypeReference.optional(this.getSwiftTypeReferenceFromScope(m.value,r)):S.TypeReference.nullable(this.getSwiftTypeReferenceFromScope(m.value,r)),optional:m=>S.TypeReference.optional(this.getSwiftTypeReferenceFromScope(m.value,r)),primitive:m=>ie(m,"value")._visit({STRING:()=>s.referenceSwiftType("String"),BOOLEAN:()=>s.referenceSwiftType("Bool"),INTEGER:()=>s.referenceSwiftType("Int"),UINT:()=>s.referenceSwiftType("UInt"),UINT_64:()=>s.referenceSwiftType("UInt64"),LONG:()=>s.referenceSwiftType("Int64"),FLOAT:()=>s.referenceSwiftType("Float"),DOUBLE:()=>s.referenceSwiftType("Double"),BIG_INTEGER:()=>s.referenceSwiftType("String"),DATE:()=>s.referenceAsIsType("CalendarDate"),DATE_TIME:()=>s.referenceFoundationType("Date"),DATE_TIME_RFC_2822:()=>s.referenceFoundationType("Date"),BASE_64:()=>s.referenceSwiftType("String"),UUID:()=>s.referenceFoundationType("UUID"),_other:()=>s.referenceAsIsType("JSONValue")}),set:()=>s.referenceAsIsType("JSONValue"),unknown:()=>s.referenceAsIsType("JSONValue"),_other:()=>s.referenceAsIsType("JSONValue")})}createReferencer(e){return new Mt(this.nameRegistry,e)}clone(){return new i({ir:this.ir,config:this.config,options:this.options,sharedNameRegistry:this.nameRegistry})}};u();c();p();var ys="client",et=class{constructor({context:t}){d(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e,options:r}){return this.buildCodeBlock({endpoint:t,snippetRequest:e,options:r})}generateSnippetSync({endpoint:t,request:e,options:r}){return this.buildCodeBlock({endpoint:t,snippetRequest:e,options:r})}async generateSnippetAst({endpoint:t,request:e,options:r}){throw new Error("Unsupported")}buildCodeBlock({endpoint:t,snippetRequest:e,options:r}){return[this.generateImportFoundationStatement(),this.generateImportModuleStatement(),S.LineBreak.single(),this.generateMainFunctionDeclarationWithEndpointSnippet({endpoint:t,snippet:e}),S.LineBreak.single(),this.generateMainFunctionInvocationStatement()].map(m=>m.toString()).join("")}generateImportFoundationStatement(){return S.Statement.import("Foundation")}generateImportModuleStatement(){let t=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return S.Statement.import(t.name)}generateMainFunctionDeclarationWithEndpointSnippet({endpoint:t,snippet:e}){return S.Statement.functionDeclaration({unsafeName:"main",accessLevel:"private",async:!0,throws:!0,body:S.CodeBlock.withStatements([this.generateRootClientInitializationStatement({auth:t.auth,snippet:e}),S.LineBreak.single(),this.generateEndpointMethodCallStatement({endpoint:t,snippet:e})])})}generateRootClientInitializationStatement({auth:t,snippet:e,additionalArgs:r=[]}){let s=[],m=this.getRootClientBaseURLArg({snippet:e});m!=null&&s.push(m);let l=t?this.getRootClientAuthArgs({auth:t,snippet:e}):[];s.push(...l),this.context.ir.headers!=null&&e.headers!=null&&s.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:e.headers})),s.push(...r);let b=s.filter(T=>!T.value.isNop()),v=this.context.nameRegistry.getRootClientSymbolOrThrow();return S.Statement.constantDeclaration({unsafeName:ys,value:S.Expression.classInitialization({unsafeName:v.name,arguments_:b,multiline:b.length>1?!0:void 0})})}getRootClientHeaderArgs({headers:t,values:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),s=[];for(let m of t){let l=e[m.name.wireValue],b=this.getRootClientHeaderArg({moduleSymbol:r,header:m,value:l});b!=null&&s.push(b)}return s}getRootClientHeaderArg({moduleSymbol:t,header:e,value:r}){if(e.typeReference.type==="literal")return;let s=this.context.dynamicTypeLiteralMapper.convert({fromSymbol:t,typeReference:e.typeReference,value:r});if(!s.isNop())return S.functionArgument({label:e.name.name.camelCase.unsafeName,value:s})}getRootClientBaseURLArg({snippet:t}){return t.baseURL!=null&&t.environment!=null?(this.context.errors.add({severity:M.Critical,message:"Cannot specify both baseUrl and environment options"}),null):t.baseURL!=null?this.context.ir.environments?.environments.type==="multipleBaseUrls"?null:S.functionArgument({label:"baseURL",value:S.Expression.escapedStringLiteral(t.baseURL)}):null}getRootClientAuthArgs({auth:t,snippet:e}){let r=[],s=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),m=e.auth;if(m==null)return r;switch(t.type){case"basic":if(m.type!=="basic"){this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message});break}r.push(S.functionArgument({label:t.username.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.username)}),S.functionArgument({label:t.password.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.password)}));break;case"bearer":if(m.type!=="bearer")return this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;r.push(S.functionArgument({label:t.token.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.token)}));break;case"header":if(m.type!=="header")return this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;r.push(S.functionArgument({label:t.header.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:s,typeReference:t.header.typeReference,value:m.value})}));break;case"oauth":return m.type!=="oauth"&&this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;case"inferred":return m.type!=="inferred"&&this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;default:A(t)}return r}generateEndpointMethodCallStatement({endpoint:t,snippet:e}){return S.Statement.discardAssignment(this.generateEndpointMethodCallExpression({endpoint:t,snippet:e}))}generateEndpointMethodCallExpression({endpoint:t,snippet:e,additionalArguments:r=[]}){let m=[...this.getEndpointMethodArguments({endpoint:t,snippet:e}).filter(l=>!l.value.isNop()),...r];return S.Expression.try(S.Expression.await(S.Expression.methodCall({target:S.Expression.rawValue(ys),methodName:this.getEndpointMethodName({endpoint:t}),arguments_:m,multiline:m.length>1?!0:void 0})))}generateMainFunctionInvocationStatement(){return S.Statement.expressionStatement(S.Expression.try(S.Expression.await(S.Expression.functionCall({unsafeName:"main"}))))}getEndpointMethodName({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${`${t.declaration.fernFilepath.allParts.map(r=>r.camelCase.unsafeName).join(".")}`}.${t.declaration.name.camelCase.unsafeName}`:t.declaration.name.camelCase.unsafeName}getEndpointMethodArguments({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getEndpointMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getEndpointMethodArgsForBodyRequest({request:t.request,snippet:e});default:A(t.request)}}getEndpointMethodArgsForInlinedRequest({request:t,snippet:e}){let r=[];this.context.errors.scope(he.PathParameters);let s=[...this.context.ir.pathParameters??[],...t.pathParameters??[]],m=[];s.length>0&&m.push(...this.getEndpointMethodPathParameters({namedParameters:s,snippet:e})),this.context.errors.unscope(),r.push(...m),this.context.errors.scope(he.Headers);let l=[];t.headers!=null&&l.push(...this.getEndpointMethodHeaderParameters({namedParameters:t.headers,snippet:e})),this.context.errors.unscope(),r.push(...l),this.context.errors.scope(he.QueryParameters);let b=[];t.queryParameters!=null&&b.push(...this.getEndpointMethodQueryParameters({namedParameters:t.queryParameters,snippet:e})),this.context.errors.unscope(),r.push(...b),this.context.errors.scope(he.RequestBody);let v=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),t.body!=null&&(t.body.type==="referenced"?r.push(S.functionArgument({label:"request",value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.body.bodyType,value:e.requestBody})})):r.push(S.functionArgument({label:"request",value:this.getInlinedRequestArg({request:t,snippet:e,filePropertyInfo:v})}))),r}getEndpointMethodPathParameters({namedParameters:t,snippet:e}){return this.context.getExampleObjectProperties({parameters:t,snippetObject:e.pathParameters??{}}).map(r=>S.functionArgument({label:r.name.name.camelCase.unsafeName,value:this.renderPathParameterValueAsSwiftString({value:r.value})}))}renderPathParameterValueAsSwiftString({value:t}){return typeof t=="string"?S.Expression.escapedStringLiteral(t):typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?S.Expression.escapedStringLiteral(String(t)):t==null?S.Expression.nop():S.Expression.escapedStringLiteral(JSON.stringify(t))}getEndpointMethodQueryParameters({namedParameters:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return this.context.getExampleObjectProperties({parameters:t,snippetObject:e.queryParameters??{}}).map(s=>S.functionArgument({label:s.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:s.typeReference,value:s.value})}))}getEndpointMethodHeaderParameters({namedParameters:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),s=this.context.createReferencer(r);return this.context.getExampleObjectProperties({parameters:t,snippetObject:e.headers??{}}).filter(m=>{let l=this.resolveAliasTypeReference(m.typeReference),b=this.context.getSwiftTypeReferenceFromScope(l,r);return s.resolvesToTheSwiftType(b.nonOptional(),"String")}).map(m=>S.functionArgument({label:m.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:m.typeReference,value:m.value})}))}resolveAliasTypeReference(t){if(t.type==="named"){let e=this.context.ir.types[t.value];if(e!=null&&e.type==="alias")return this.resolveAliasTypeReference(e.typeReference)}return t}getFilePropertyInfo({request:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[],orderedFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({fromSymbol:r,body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,filePropertyInfo:r}){this.context.errors.scope(he.RequestBody);let s=t.body!=null?this.getInlinedRequestBodyObjectFields({body:t.body,value:e.requestBody,filePropertyInfo:r}):[];this.context.errors.unscope();let m=s.filter(l=>!l.value.isNop());return S.Expression.contextualMethodCall({methodName:"init",arguments_:m,multiline:m.length>1?!0:void 0})}getInlinedRequestBodyObjectFields({body:t,value:e,filePropertyInfo:r}){switch(t.type){case"fileUpload":return r.orderedFields;case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyObjectField({body:t,value:e})];default:A(t)}}getInlinedRequestBodyPropertyObjectFields({parameters:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return this.context.getExampleObjectProperties({parameters:t,snippetObject:e}).map(s=>S.functionArgument({label:s.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:s.typeReference,value:s.value})}))}getReferencedRequestBodyPropertyObjectField({body:t,value:e}){return S.functionArgument({label:t.bodyKey.camelCase.unsafeName,value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.bodyType,value:e})})}getReferencedRequestBodyPropertyTypeLiteral({body:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:t.value,value:e});default:A(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:M.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),S.Expression.dataLiteral("data")):S.Expression.dataLiteral(t)}getEndpointMethodArgsForBodyRequest({request:t,snippet:e}){let r=[];this.context.errors.scope(he.PathParameters);let s=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];if(s.length>0&&r.push(...this.getEndpointMethodPathParameters({namedParameters:s,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(he.RequestBody),t.body!=null){let m=this.getEndpointMethodBodyRequestArg({body:t.body,value:e.requestBody});m.value.isNop()||r.push(m)}return this.context.errors.unscope(),r}getEndpointMethodBodyRequestArg({body:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();switch(t.type){case"bytes":return S.functionArgument({label:"request",value:this.getBytesBodyRequestArg({value:e})});case"typeReference":return t.value.type==="optional"&&e==null?S.functionArgument({label:"request",value:S.Expression.nop()}):S.functionArgument({label:"request",value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:t.value,value:e})});default:A(t)}}};var Jt=class extends pt{constructor({ir:t,config:e,options:r={}}){super(new Yt({ir:t,config:e,options:r}))}async generate(t,e={}){return super.generate(t,e)}generateSync(t,e={}){return super.generateSync(t,e)}async generateSnippetAst(t){return super.generateSnippetAst(t)}createSnippetGenerator(t){return new et({context:t})}};0&&(module.exports={DynamicSnippetsGenerator,EndpointSnippetGenerator});
|
|
25
|
+
`),e=e.replace(/\x00/g,""),e}};u();c();p();var ze=class extends B{constructor({accessLevel:e,indirect:r,name:s,conformances:m,cases:l,initializers:b,methods:v,nestedTypes:T,docs:I}){super();d(this,"name");d(this,"accessLevel");d(this,"indirect");d(this,"conformances");d(this,"cases");d(this,"initializers");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.name=s,this.indirect=r??!1,this.accessLevel=e,this.conformances=m??[],this.cases=l,this.initializers=b??[],this.methods=v??[],this.nestedTypes=T??[],this.docs=I}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.indirect&&e.write("indirect "),e.write(`enum ${k(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),e.write(" {"),e.newLine(),e.indent(),this.cases.forEach(r=>{r.docs!=null&&r.docs.write(e),e.write("case "),e.write(k(r.unsafeName)),r.associatedValue!=null&&(e.write("("),r.associatedValue.forEach((s,m)=>{m>0&&e.write(", "),s.write(e)}),e.write(")")),e.newLine()}),this.initializers.length>0&&(e.newLine(),this.initializers.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),this.methods.length>0&&(e.newLine(),this.methods.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),this.nestedTypes.length>0&&(e.newLine(),this.nestedTypes.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()})),e.dedent(),e.write("}")}};u();c();p();var Ge=class extends B{constructor({accessLevel:e,name:r,conformances:s,cases:m,docs:l}){super();d(this,"name");d(this,"accessLevel");d(this,"conformances");d(this,"cases");d(this,"docs");this.name=r,this.accessLevel=e,this.conformances=s??[],this.cases=m,this.docs=l}write(e){if(this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),e.write(`enum ${k(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),this.cases.length===0){e.write(" {}");return}e.write(" {"),e.newLine(),e.indent(),this.cases.forEach(r=>{r.docs!=null&&r.docs.write(e),e.write("case "),e.write(k(r.unsafeName)),r.rawValue!==r.unsafeName&&(e.write(" = "),e.write(`"${Dt(r.rawValue)}"`)),e.newLine()}),e.dedent(),e.write("}")}};u();c();p();var He=class extends B{constructor({name:e,conformances:r,initializers:s,computedProperties:m,methods:l,nestedTypes:b,docs:v}){super();d(this,"name");d(this,"conformances");d(this,"initializers");d(this,"computedProperties");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.name=e,this.conformances=r??[],this.initializers=s??[],this.computedProperties=m??[],this.methods=l??[],this.nestedTypes=b??[],this.docs=v}write(e){this.docs!=null&&this.docs.write(e),e.write(`extension ${$t(this.name)}`),this.conformances.forEach((r,s)=>{s===0?e.write(": "):s>0&&e.write(", "),e.write(r)}),e.write(" {"),this.initializers.length>0&&(e.newLine(),e.indent(),this.initializers.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.computedProperties.length>0&&(e.newLine(),e.indent(),this.computedProperties.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.methods.length>0&&(e.newLine(),e.indent(),this.methods.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),this.nestedTypes.length>0&&(e.newLine(),e.indent(),this.nestedTypes.forEach((r,s)=>{s>0&&e.newLine(),r.write(e),e.newLine()}),e.dedent()),e.write("}")}};u();c();p();var Ke=class extends B{constructor({label:e,value:r}){super();d(this,"label");d(this,"value");this.label=e,this.value=r}write(e){this.label!=null&&(e.write(this.label),e.write(": ")),this.value.write(e)}};u();c();p();var Ye=class extends B{constructor({argumentLabel:e,unsafeName:r,escaping:s,type:m,defaultValue:l,docsContent:b}){super();d(this,"argumentLabel");d(this,"unsafeName");d(this,"escaping");d(this,"type");d(this,"defaultValue");d(this,"docsContent");this.argumentLabel=e,this.unsafeName=r,this.escaping=s,this.type=m,this.defaultValue=l,this.docsContent=b}write(e){this.argumentLabel==null?e.write("_ "):this.argumentLabel!==this.unsafeName&&(e.write(this.argumentLabel),e.write(" ")),e.write(this.unsafeName),e.write(": "),this.escaping&&e.write("@escaping "),this.type.write(e),this.defaultValue!=null&&(e.write(" = "),this.defaultValue.write(e))}};u();c();p();var Je=class extends B{constructor({accessLevel:e,convenience:r,failable:s,throws:m,parameters:l,body:b,multiline:v,docs:T}){super();d(this,"accessLevel");d(this,"convenience");d(this,"failable");d(this,"throws");d(this,"parameters");d(this,"body");d(this,"multiline");d(this,"docs");this.accessLevel=e,this.convenience=r,this.failable=s,this.throws=m,this.parameters=l??[],this.body=b??z.empty(),this.multiline=v,this.docs=T}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.convenience&&e.write("convenience "),e.write("init"),this.failable&&e.write("?"),e.write("("),this.multiline&&(e.newLine(),e.indent()),this.parameters.forEach((r,s)=>{s>0&&(e.write(","),this.multiline?e.newLine():e.write(" ")),r.write(e)}),this.multiline&&(e.newLine(),e.dedent()),e.write(") "),this.throws&&e.write("throws "),this.body.write(e)}};u();c();p();var qt=class i extends B{constructor({count:e=1}={}){super();d(this,"count");this.count=e}write(e){for(let r=0;r<this.count;r++)e.newLine()}static single(){return new i({count:1})}static double(){return new i({count:2})}static multiple(e){return new i({count:e})}};u();c();p();var Ze=class extends B{constructor({attributes:e,unsafeName:r,accessLevel:s,static_:m,parameters:l,async:b,throws:v,returnType:T,body:I,docs:C}){super();d(this,"attributes");d(this,"unsafeName");d(this,"accessLevel");d(this,"static_");d(this,"parameters");d(this,"async");d(this,"throws");d(this,"returnType");d(this,"body");d(this,"docs");this.attributes=e??[],this.unsafeName=r,this.accessLevel=s,this.static_=m,this.parameters=l??[],this.async=b,this.throws=v,this.returnType=T,this.body=I??z.empty(),this.docs=C}write(e){this.docs!=null&&this.docs.write(e),this.attributes.forEach(r=>{r.arguments?.length?pe.functionCall({unsafeName:`@${r.name}`,arguments_:r.arguments}).write(e):(e.write("@"),e.write(r.name)),e.write(" ")}),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.static_&&e.write("static "),e.write("func "),e.write(k(this.unsafeName)),e.write("("),this.parameters.forEach((r,s)=>{s>0&&e.write(", "),r.write(e)}),e.write(")"),this.async&&e.write(" async"),this.throws&&e.write(" throws"),e.write(" -> "),this.returnType.write(e),e.write(" "),this.body.write(e)}};u();c();p();var Wt=class extends B{constructor(e){super();d(this,"internalPattern");this.internalPattern=e}write(e){this.internalPattern.type==="enum-case-value-binding"?(e.write("."),e.write(this.internalPattern.caseName),e.write("("),e.write(this.internalPattern.declarationType),e.write(" "),e.write(this.internalPattern.referenceName),e.write(")")):A(this.internalPattern.type)}static enumCaseValueBinding(e){return new this({type:"enum-case-value-binding",...e})}};u();c();p();var Xe=class extends B{constructor({unsafeName:e,accessLevel:r,static_:s,declarationType:m,type:l,indirect:b,defaultValue:v,docs:T}){super();d(this,"unsafeName");d(this,"accessLevel");d(this,"static_");d(this,"declarationType");d(this,"type");d(this,"indirect");d(this,"defaultValue");d(this,"docs");this.unsafeName=e,this.accessLevel=r,this.static_=s,this.declarationType=m,this.type=l,this.indirect=b,this.defaultValue=v,this.docs=T}write(e){this.docs!=null&&this.docs.write(e),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),this.static_&&e.write("static "),e.write(this.declarationType),e.write(" "),e.write(k(this.unsafeName)),e.write(": "),this.type.write(e),this.defaultValue!=null&&(e.write(" = "),this.defaultValue.write(e))}};u();c();p();var ms={CaseIterable:"CaseIterable",Codable:"Codable",CodingKey:"CodingKey",Decodable:"Decodable",Encodable:"Encodable",Equatable:"Equatable",Error:"Error",Hashable:"Hashable",Sendable:"Sendable",MultipartFormDataConvertible:"MultipartFormDataConvertible"};u();c();p();var Qe=class extends B{constructor({attributes:e,accessLevel:r,name:s,conformances:m,properties:l,initializers:b,methods:v,nestedTypes:T,docs:I}){super();d(this,"attributes");d(this,"name");d(this,"accessLevel");d(this,"conformances");d(this,"properties");d(this,"initializers");d(this,"methods");d(this,"nestedTypes");d(this,"docs");this.attributes=e??[],this.name=s,this.accessLevel=r,this.conformances=m??[],this.properties=l??[],this.initializers=b??[],this.methods=v??[],this.nestedTypes=T??[],this.docs=I}write(e){this.docs!=null&&this.docs.write(e),this.attributes.forEach(v=>{v.arguments?.length?pe.functionCall({unsafeName:`@${v.name}`,arguments_:v.arguments}).write(e):(e.write("@"),e.write(v.name)),e.write(" ")}),this.accessLevel!=null&&(e.write(this.accessLevel),e.write(" ")),e.write(`struct ${k(this.name)}`),this.conformances.forEach((v,T)=>{T===0?e.write(": "):T>0&&e.write(", "),e.write(v)}),e.write(" {"),e.newLine(),e.indent();let r=this.properties.length>0,s=this.initializers.length>0,m=this.methods.length>0,l=this.nestedTypes.length>0;this.properties.forEach(v=>{v.write(e),e.newLine()});let b=r;s&&(b&&e.newLine(),this.initializers.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()}),b=!0),m&&(b&&e.newLine(),this.methods.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()}),b=!0),l&&(b&&e.newLine(),this.nestedTypes.forEach((v,T)=>{T>0&&e.newLine(),v.write(e),e.newLine()})),e.dedent(),e.write("}")}};u();c();p();u();c();p();var Np={Http:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"HTTP",symbols:[{name:"HTTP",shape:{type:"enum-container"}}]},MultipartFormData:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormData",symbols:[{name:"MultipartFormData",shape:{type:"class"}}]},MultipartFormDataConvertible:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormDataConvertible",symbols:[{name:"MultipartFormDataConvertible",shape:{type:"protocol"}}]},MultipartFormField:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"MultipartFormField",symbols:[{name:"MultipartFormField",shape:{type:"enum-with-associated-values"}}]},QueryParameter:{relativePathToDir:"Core/Networking",filenameWithoutExtension:"QueryParameter",symbols:[{name:"QueryParameter",shape:{type:"enum-with-associated-values"}}]},DecoderPlusAdditionalProperties:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Decoder+AdditionalProperties",symbols:[]},EncodableValue:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"EncodableValue",symbols:[{name:"EncodableValue",shape:{type:"struct"}}]},EncoderPlusAdditionalProperties:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Encoder+AdditionalProperties",symbols:[]},JSONEncoderPlusEncodableValue:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"JSONEncoder+EncodableValue",symbols:[]},KeyedDecodingContainerPlusNullable:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"KeyedDecodingContainer+Nullable",symbols:[]},KeyedEncodingContainerPlusNullable:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"KeyedEncodingContainer+Nullable",symbols:[]},Serde:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"Serde",symbols:[{name:"Serde",shape:{type:"class"}}]},StringKey:{relativePathToDir:"Core/Serde",filenameWithoutExtension:"StringKey",symbols:[{name:"StringKey",shape:{type:"struct"}}]},DataPlusString:{relativePathToDir:"Core",filenameWithoutExtension:"Data+String",symbols:[]},StringPlusUrlEncoding:{relativePathToDir:"Core",filenameWithoutExtension:"String+URLEncoding",symbols:[]},CalendarDate:{relativePathToDir:"Public",filenameWithoutExtension:"CalendarDate",symbols:[{name:"CalendarDate",shape:{type:"struct"}}]},FormFile:{relativePathToDir:"Public",filenameWithoutExtension:"FormFile",symbols:[{name:"FormFile",shape:{type:"struct"}}]},HTTPError:{relativePathToDir:"Public",filenameWithoutExtension:"HTTPError",symbols:[{name:"HTTPError",shape:{type:"struct"}}]},Indirect:{relativePathToDir:"Public",filenameWithoutExtension:"Indirect",symbols:[{name:"Indirect",shape:{type:"class"}}]},JsonValue:{relativePathToDir:"Public",filenameWithoutExtension:"JSONValue",symbols:[{name:"JSONValue",shape:{type:"enum-with-associated-values"}}]},Networking:{relativePathToDir:"Public",filenameWithoutExtension:"Networking",symbols:[{name:"Networking",shape:{type:"enum-container"}}]},Nullable:{relativePathToDir:"Public",filenameWithoutExtension:"Nullable",symbols:[{name:"Nullable",shape:{type:"enum-with-associated-values"}}]},RequestOptions:{relativePathToDir:"Public",filenameWithoutExtension:"RequestOptions",symbols:[{name:"RequestOptions",shape:{type:"struct"}}]}};u();c();p();var R=class R{constructor(t,e,r){d(this,"id");d(this,"name");d(this,"shape");this.id=t,this.name=e,this.shape=r}static isSwiftSymbol(t){return R.SWIFT_SYMBOL_ID===t||t.startsWith(`${R.SWIFT_SYMBOL_ID}.`)}static isSwiftSymbolName(t){return t in R.swiftTypeSymbolsByName}static isFoundationSymbol(t){return R.FOUNDATION_SYMBOL_ID===t||t.startsWith(`${R.FOUNDATION_SYMBOL_ID}.`)}static isFoundationSymbolName(t){return t in R.foundationTypeSymbolsByName}static isCustomSymbol(t){return!R.isSwiftSymbol(t)&&!R.isFoundationSymbol(t)}static create(t,e,r){return new R(t,e,r)}static swiftType(t){return R.create(`${R.SWIFT_SYMBOL_ID}.${t}`,t,{type:"system"})}static foundationType(t){return R.create(`${R.FOUNDATION_SYMBOL_ID}.${t}`,t,{type:"system"})}get isSwiftSymbol(){return R.isSwiftSymbol(this.id)}get isFoundationSymbol(){return R.isFoundationSymbol(this.id)}get isCustomSymbol(){return R.isCustomSymbol(this.id)}};d(R,"SWIFT_SYMBOL_NAME","Swift"),d(R,"SWIFT_SYMBOL_ID",R.SWIFT_SYMBOL_NAME),d(R,"swiftTypeSymbolsByName",{String:R.swiftType("String"),Bool:R.swiftType("Bool"),Int:R.swiftType("Int"),Int64:R.swiftType("Int64"),UInt:R.swiftType("UInt"),UInt64:R.swiftType("UInt64"),Float:R.swiftType("Float"),Double:R.swiftType("Double"),Void:R.swiftType("Void"),Encoder:R.swiftType("Encoder"),Decoder:R.swiftType("Decoder"),Any:R.swiftType("Any")}),d(R,"swiftTypeSymbols",Object.values(R.swiftTypeSymbolsByName)),d(R,"FOUNDATION_SYMBOL_NAME","Foundation"),d(R,"FOUNDATION_SYMBOL_ID",R.FOUNDATION_SYMBOL_NAME),d(R,"foundationTypeSymbolsByName",{Data:R.foundationType("Data"),Date:R.foundationType("Date"),UUID:R.foundationType("UUID")}),d(R,"foundationTypeSymbols",Object.values(R.foundationTypeSymbolsByName));var q=R;u();c();p();u();c();p();u();c();p();u();c();p();var Vt=class{constructor(t,e){d(this,"id");d(this,"name");d(this,"childrenByName");this.id=t,this.name=e,this.childrenByName=new Map}get children(){return Array.from(this.childrenByName.values())}addChild(t){if(this.childrenByName.has(t.name))throw new Error(`A child with the name '${t.name}' already exists in module '${this.name}'.`);this.childrenByName.set(t.name,t)}getChildByName(t){return this.childrenByName.get(t)}},jt=class extends Vt{constructor(e,r){super(e,r);d(this,"kind","module");d(this,"imports");d(this,"parent",null);this.imports=[]}addImport(e){this.imports.push(e)}get qualifiedPath(){return[this.name]}get qualifiedName(){return this.name}},zt=class extends Vt{constructor(e,r,s){super(r,e);d(this,"kind","type");d(this,"shape");d(this,"parent");this.parent=null,this.shape=s}getNearestModuleAncestorOrThrow(){let e=this.parent;for(;e!==null&&e.kind!=="module";)e=e.parent;return Q(e,`No module ancestor found for type symbol '${this.id}'`),e}get qualifiedPath(){return[...this.parent?.qualifiedPath??[],this.name]}get qualifiedName(){return this.qualifiedPath.join(".")}};var yt=class{constructor(){d(this,"symbolsById",new Map)}createModuleSymbol({symbolId:t,symbolName:e}){this.validateSymbolNotExists(t);let r=new jt(t,e);return this.symbolsById.set(t,r),r}createTypeSymbol({symbolId:t,symbolName:e,shape:r}){this.validateSymbolNotExists(t);let s=new zt(e,t,r);return this.symbolsById.set(t,s),s}addImportRelation({clientSymbolId:t,importedSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e);if(r.kind!=="module"||s.kind!=="module")throw new Error(`Client module '${r.id}' and imported module '${s.id}' must both be module symbols.`);r.addImport(s)}nestSymbol({parentSymbolId:t,childSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e);r.addChild(s),s.parent=r}reference({fromSymbolId:t,targetSymbolId:e}){let r=this.getSymbolByIdOrThrow(t),s=this.getSymbolByIdOrThrow(e),m=s.qualifiedPath;for(let l=1;l<=m.length;l++){let b=m.slice(m.length-l);if(this.resolvePath(r,b)?.id===s.id)return b.join(".")}return s.qualifiedName}resolveReference({fromSymbolId:t,reference:e}){let r=this.getSymbolByIdOrThrow(t),s=e.split(".").filter(m=>m.length>0);return this.resolvePath(r,s)}resolvePath(t,e){let[r,...s]=e;if(r===void 0)return null;let m=this.resolveFirstSegment(t,r);if(m===null)return null;let l=m;for(let b=0;b<s.length;b++){let v=s[b];if(ne(v),l=l.getChildByName(v)??null,l===null)return null}return l}resolveFirstSegment(t,e){let r=t;for(;r!==null;){let l=r.getChildByName(e);if(l)return l;r=r.parent}let s=t.kind==="module"?t:t.getNearestModuleAncestorOrThrow();if(s.name===e)return s;for(let l of s.imports)if(l.name===e)return l;let m=null;for(let l of s.imports){let b=l.getChildByName(e);if(b){if(m!=null&&m.id!==b.id)return null;m=b}}return m}getSymbolByIdOrThrow(t){let e=this.symbolsById.get(t);return ne(e,`A symbol with the ID '${t}' was not found in the registry.`),e}getSymbolById(t){return this.symbolsById.get(t)??null}validateSymbolNotExists(t){if(this.symbolsById.has(t))throw new Error(`A symbol with the ID '${t}' already exists in the registry.`)}};var Tr=class i{constructor(t,e,r){d(this,"graph");d(this,"swiftSymbol");d(this,"foundationSymbol");d(this,"registeredSourceModule");d(this,"registeredTestModule");this.graph=t,this.swiftSymbol=e,this.foundationSymbol=r,this.registeredSourceModule=null,this.registeredTestModule=null}static create(){let{graph:t,swiftSymbol:e,foundationSymbol:r}=i.createGraph();return new i(t,e,r)}static createGraph(){let t=new yt,e=()=>{let l=t.createModuleSymbol({symbolId:q.SWIFT_SYMBOL_ID,symbolName:q.SWIFT_SYMBOL_NAME});return q.swiftTypeSymbols.forEach(b=>{let v=t.createTypeSymbol({symbolId:b.id,symbolName:b.name,shape:{type:"system"}});t.nestSymbol({parentSymbolId:l.id,childSymbolId:v.id})}),l},r=()=>{let l=t.createModuleSymbol({symbolId:q.FOUNDATION_SYMBOL_ID,symbolName:q.FOUNDATION_SYMBOL_NAME});return q.foundationTypeSymbols.forEach(b=>{let v=t.createTypeSymbol({symbolId:b.id,symbolName:b.name,shape:{type:"system"}});t.nestSymbol({parentSymbolId:l.id,childSymbolId:v.id})}),l},s=e(),m=r();return{graph:t,swiftSymbol:s,foundationSymbol:m}}getRegisteredSourceModuleSymbolOrThrow(){return Q(this.registeredSourceModule,"Module symbol not found."),q.create(this.registeredSourceModule.id,this.registeredSourceModule.name,{type:"other"})}getRegisteredTestModuleSymbolOrThrow(){return Q(this.registeredTestModule,"Module symbol not found."),q.create(this.registeredTestModule.id,this.registeredTestModule.name,{type:"other"})}getSymbolByIdOrThrow(t){let e=this.graph.getSymbolById(t);return Q(e,`Symbol with ID '${t}' not found in registry.`),q.create(e.id,e.name,e.kind==="type"?e.shape:{type:"other"})}registerSourceModule(t){let e=t,r=this.graph.createModuleSymbol({symbolId:e,symbolName:t});return r.addImport(this.swiftSymbol),r.addImport(this.foundationSymbol),this.registeredSourceModule=r,q.create(r.id,r.name,{type:"other"})}registerTestModule(t){let e=t,r=this.graph.createModuleSymbol({symbolId:e,symbolName:t});return r.addImport(this.swiftSymbol),r.addImport(this.foundationSymbol),Q(this.registeredSourceModule,"Cannot register a test module before registering a source module."),r.addImport(this.registeredSourceModule),this.registeredTestModule=r,q.create(r.id,r.name,{type:"other"})}registerSourceModuleType(t,e){Q(this.registeredSourceModule,"Cannot register a type before registering a module.");let r=this.inferSymbolIdForSourceModuleType(t),s=this.graph.createTypeSymbol({symbolId:r,symbolName:t,shape:e});return this.graph.nestSymbol({parentSymbolId:this.registeredSourceModule.id,childSymbolId:s.id}),q.create(s.id,s.name,e)}registerTestModuleType(t,e){Q(this.registeredTestModule,"Cannot register a type before registering a module.");let r=this.inferSymbolIdForTestModuleType(t),s=this.graph.createTypeSymbol({symbolId:r,symbolName:t,shape:e});return this.graph.nestSymbol({parentSymbolId:this.registeredTestModule.id,childSymbolId:s.id}),q.create(s.id,s.name,e)}registerNestedType({parentSymbol:t,symbolName:e,shape:r}){let s=typeof t=="string"?t:t.id,m=this.inferSymbolIdForNestedType(s,e),l=this.graph.createTypeSymbol({symbolId:m,symbolName:e,shape:r});return this.graph.nestSymbol({parentSymbolId:s,childSymbolId:l.id}),q.create(l.id,l.name,r)}reference({fromSymbol:t,toSymbol:e}){let r=typeof t=="string"?t:t.id,s=typeof e=="string"?e:e.id;return this.graph.reference({fromSymbolId:r,targetSymbolId:s})}resolveReference({fromSymbol:t,reference:e}){let r=typeof t=="string"?t:t.id,s=this.graph.resolveReference({fromSymbolId:r,reference:e});return s?q.create(s.id,s.name,s.kind==="type"?s.shape:{type:"other"}):null}inferSymbolIdForSourceModuleType(t){return Q(this.registeredSourceModule,"Cannot get symbol id for a type before registering a module."),`${this.registeredSourceModule.id}.${t}`}inferSymbolIdForTestModuleType(t){return Q(this.registeredTestModule,"Cannot get symbol id for a type before registering a module."),`${this.registeredTestModule.id}.${t}`}inferSymbolIdForNestedType(t,e){return`${t}.${e}`}};u();c();p();var Rp={ClientError:{relativePath:"",filenameWithoutExtension:i=>(ar(i.errorEnumName),i.errorEnumName)},HTTPClient:{relativePath:"Core/Networking",filenameWithoutExtension:()=>"HTTPClient"},ClientConfig:{relativePath:"Public",filenameWithoutExtension:()=>"ClientConfig"}};var Gt=class i extends B{constructor(e){super();d(this,"variant");this.variant=e}nonOptional(){return i.nonOptional(this)}nonNullable(){return i.nonNullable(this)}getReferenceIfSymbolType(){return this.variant.type==="symbol"?this.variant.symbol:null}write(e){let{variant:r}=this;switch(r.type){case"symbol":e.write(q.isSwiftSymbolName(r.symbol)||q.isFoundationSymbolName(r.symbol)?r.symbol:$t(r.symbol));break;case"generic":{r.reference.write(e),r.arguments.length>0&&(e.write("<"),r.arguments.forEach((s,m)=>{s.write(e),m<r.arguments.length-1&&e.write(", ")}),e.write(">"));break}case"tuple":e.write("("),r.elements.forEach((s,m)=>{m>0&&e.write(", "),s.write(e)}),e.write(")");break;case"array":e.write("["),r.elementType.write(e),e.write("]");break;case"dictionary":e.write("["),r.keyType.write(e),e.write(": "),r.valueType.write(e),e.write("]");break;case"optional":r.valueType.write(e),e.write("?");break;case"nullable":e.write("Nullable<"),r.valueType.write(e),e.write(">");break;case"member-access":r.target.write(e),e.write("."),e.write(r.memberName);break;default:A(r)}}equals(e){switch(this.variant.type){case"symbol":return e.variant.type==="symbol"&&this.variant.symbol===e.variant.symbol;case"generic":return e.variant.type==="generic"&&this.variant.reference.equals(e.variant.reference)&&this.variant.arguments.every((r,s)=>e.variant.type==="generic"&&e.variant.arguments[s]&&r.equals(e.variant.arguments[s]));case"tuple":return e.variant.type==="tuple"&&this.variant.elements.every((r,s)=>e.variant.type==="tuple"&&e.variant.elements[s]&&r.equals(e.variant.elements[s]));case"array":return e.variant.type==="array"&&this.variant.elementType.equals(e.variant.elementType);case"dictionary":return e.variant.type==="dictionary"&&this.variant.keyType.equals(e.variant.keyType)&&this.variant.valueType.equals(e.variant.valueType);case"optional":return e.variant.type=="optional"&&this.variant.valueType.equals(e.variant.valueType);case"nullable":return e.variant.type==="nullable"&&this.variant.valueType.equals(e.variant.valueType);case"member-access":return e.variant.type==="member-access"&&this.variant.target.equals(e.variant.target)&&this.variant.memberName===e.variant.memberName;default:A(this.variant)}}static symbol(e){return new this({type:"symbol",symbol:e})}static generic(e,r){return new this({type:"generic",reference:e,arguments:r})}static tuple(e){return new this({type:"tuple",elements:e})}static array(e){return new this({type:"array",elementType:e})}static dictionary(e,r){return new this({type:"dictionary",keyType:e,valueType:r})}static optional(e){return e.variant.type==="optional"?e:new this({type:"optional",valueType:e})}static nullable(e){return e.variant.type==="nullable"?e:new this({type:"nullable",valueType:e})}static memberAccess(e,r){return new this({type:"member-access",target:e,memberName:r})}static nonOptional(e){return e.variant.type==="optional"?i.nonOptional(e.variant.valueType):e}static nonNullable(e){return e.variant.type==="nullable"?i.nonNullable(e.variant.valueType):e}static unqualifiedToSwiftType(e){return i.symbol(e)}static unqualifiedToFoundationType(e){return i.symbol(e)}};function Ap(i){return new $e(i)}function Cp(i){return new z(i)}function Bp(i){return new qe(i)}function Lp(i){return new Ve(i)}function Fp(i){return new je(i)}function Mp(i){return new ze(i)}function Op(i){return new Ge(i)}function Pp(i){return new He(i)}function kp(i){return new Ke(i)}function Up(i){return new Ye(i)}function _p(i){return new Je(i)}function Dp(i){return new Ze(i)}function $p(i){return new Xe(i)}function qp(i){return new Qe(i)}u();c();p();function fs(i){return H(te(i))}u();c();p();var Ht=class{constructor({context:t}){d(this,"context");this.context=t}convert(t){let{fromSymbol:e,typeReference:r,value:s,as:m}=t;switch(r.type){case"list":return this.convertList({fromSymbol:e,list:r.value,value:s});case"literal":{if(r.value.type==="string")return S.Expression.enumCaseShorthand(Ae.generateEnumCaseLabel(r.value.value));if(r.value.type==="boolean")return S.Expression.boolLiteral(r.value.value);A(r.value);break}case"map":return this.convertMap({fromSymbol:e,map:r,value:s});case"named":{let l=this.context.resolveNamedType({typeId:r.value});return l==null?S.Expression.nop():this.convertNamed({fromSymbol:e,typeId:r.value,named:l,value:s,as:m})}case"nullable":return this.context.customConfig?.nullableAsOptional?this.convert({fromSymbol:e,typeReference:r.value,value:s,as:m}):this.convertNullable({fromSymbol:e,nullable:r,value:s,as:m});case"optional":return this.convert({fromSymbol:e,typeReference:r.value,value:s,as:m});case"primitive":return this.convertPrimitive({primitive:r.value,value:s,as:m});case"set":return S.Expression.nop();case"unknown":return this.convertUnknown(s);default:A(r)}}convertList({fromSymbol:t,list:e,value:r}){return Array.isArray(r)?S.Expression.arrayLiteral({elements:r.map((s,m)=>{this.context.errors.scope({index:m});try{return this.convert({fromSymbol:t,typeReference:e,value:s})}finally{this.context.errors.unscope()}}),multiline:!0}):(this.context.errors.add({severity:M.Critical,message:`Expected array but got: ${typeof r}`}),S.Expression.nop())}convertMap({fromSymbol:t,map:e,value:r}){return typeof r!="object"||r==null?(this.context.errors.add({severity:M.Critical,message:`Expected object but got: ${r==null?"null":typeof r}`}),S.Expression.nop()):S.Expression.dictionaryLiteral({entries:Object.entries(r).map(([s,m])=>{this.context.errors.scope(s);try{return[this.convert({fromSymbol:t,typeReference:e.key,value:s,as:"mapKey"}),this.convert({fromSymbol:t,typeReference:e.value,value:m,as:"mapValue"})]}finally{this.context.errors.unscope()}}),multiline:!0})}convertNamed({fromSymbol:t,typeId:e,named:r,value:s,as:m}){switch(r.type){case"alias":return this.convert({fromSymbol:t,typeReference:r.typeReference,value:s,as:m});case"discriminatedUnion":{let l=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e);return this.convertDiscriminatedUnion({fromSymbol:t,unionSymbol:l,discriminatedUnion:r,value:s})}case"enum":return this.convertEnum({enum_:r,value:s});case"object":return this.convertObject({fromSymbol:t,typeId:e,object_:r,value:s});case"undiscriminatedUnion":{let l=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e);return this.convertUndiscriminatedUnion({fromSymbol:t,unionSymbol:l,undiscriminatedUnion:r,value:s})}default:A(r)}}convertNullable({fromSymbol:t,nullable:e,value:r,as:s}){return r==null?S.Expression.enumCaseShorthand("null"):S.Expression.contextualMethodCall({methodName:"value",arguments_:[S.functionArgument({value:this.convert({fromSymbol:t,typeReference:e.value,value:r,as:s})})]})}convertDiscriminatedUnion({fromSymbol:t,discriminatedUnion:e,unionSymbol:r,value:s}){let m=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:s});if(m==null)return S.Expression.nop();let l=m.singleDiscriminatedUnionType,b=Ft.sanitizeToCamelCase(l.discriminantValue.name.camelCase.unsafeName);switch(l.type){case"samePropertiesAsObject":{let v=this.context.resolveNamedType({typeId:l.typeId});if(v==null)return S.Expression.nop();let T=this.convertNamed({fromSymbol:t,typeId:l.typeId,named:v,value:m.value});return S.Expression.methodCall({target:S.Expression.reference(r.name),methodName:b,arguments_:[S.functionArgument({value:T})],multiline:!0})}case"singleProperty":try{this.context.errors.scope(l.discriminantValue.wireValue);let v=this.context.getRecord(m.value);if(v==null)return S.Expression.nop();let T=new Set((l.properties??[]).map(_=>_.name.wireValue)),I=Object.keys(v).find(_=>!T.has(_))??"value",C=this.convert({fromSymbol:t,typeReference:l.typeReference,value:v[I]});return S.Expression.methodCall({target:S.Expression.reference(r.name),methodName:b,arguments_:[S.functionArgument({value:C})],multiline:!0})}finally{this.context.errors.unscope()}case"noProperties":return S.Expression.memberAccess({target:S.Expression.reference(r.name),memberName:b});default:A(l)}}convertEnum({enum_:t,value:e}){let r=this.getEnumValue({enum_:t,value:e});return r==null?S.Expression.nop():S.Expression.enumCaseShorthand(r.name.camelCase.unsafeName)}getEnumValue({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:M.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let r=t.values.find(s=>s.wireValue===e);if(r==null){this.context.errors.add({severity:M.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return r}convertObject({fromSymbol:t,typeId:e,object_:r,value:s}){let m=this.context.nameRegistry.getSchemaTypeSymbolOrThrow(e),l=this.context.getExampleObjectProperties({parameters:r.properties,snippetObject:s}),b=new Map(l.map(T=>[T.name.wireValue,T])),v=r.properties.map(T=>{let I=b.get(T.name.wireValue);return I??(T.typeReference.type==="literal"?{name:T.name,typeReference:T.typeReference,value:void 0}:null)}).filter(T=>T!=null);return S.Expression.structInitialization({unsafeName:m.name,arguments_:v.map(T=>{let I=this.convert({fromSymbol:t,typeReference:T.typeReference,value:T.value});return I.isNop()?null:S.functionArgument({label:De(T.name.name.camelCase.unsafeName),value:I})}).filter(T=>T!=null),multiline:!0})}convertUndiscriminatedUnion({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s}){let m=this.findMatchingUndiscriminatedUnionType({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s});return m??S.Expression.nop()}findMatchingUndiscriminatedUnionType({fromSymbol:t,unionSymbol:e,undiscriminatedUnion:r,value:s}){let m=this.context.nameRegistry.getAllUndiscriminatedUnionVariantsOrThrow(e);for(let l of r.types){let b=this.context.errors.size();try{let v=this.convert({fromSymbol:t,typeReference:l,value:s}),T=this.context.getSwiftTypeReferenceFromScope(l,t),I=m.find(C=>C.swiftType.equals(T));if(I==null){this.context.errors.truncate(b);continue}return S.Expression.methodCall({target:S.Expression.reference(e.name),methodName:I.caseName,arguments_:[S.functionArgument({value:v})],multiline:!0})}catch{this.context.errors.truncate(b);continue}}this.context.errors.add({severity:M.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof s}" value`})}convertUnknown(t){switch(typeof t){case"boolean":return S.Expression.contextualMethodCall({methodName:"bool",arguments_:[S.functionArgument({value:S.Expression.boolLiteral(t)})]});case"string":return S.Expression.contextualMethodCall({methodName:"string",arguments_:[S.functionArgument({value:S.Expression.escapedStringLiteral(t)})]});case"number":return S.Expression.contextualMethodCall({methodName:"number",arguments_:[S.functionArgument({value:S.Expression.numberLiteral(t)})]});case"object":return t===null?S.Expression.enumCaseShorthand("null"):Array.isArray(t)?S.Expression.contextualMethodCall({methodName:"array",arguments_:[S.functionArgument({value:S.Expression.arrayLiteral({elements:t.map(e=>this.convertUnknown(e)),multiline:!0})})]}):S.Expression.contextualMethodCall({methodName:"object",arguments_:[S.functionArgument({value:S.Expression.dictionaryLiteral({entries:Object.entries(t).map(([e,r])=>[S.Expression.escapedStringLiteral(e),this.convertUnknown(r)]),multiline:!0})})]});default:throw new Error(`Internal error; unsupported unknown type: ${typeof t}`)}}convertPrimitive({primitive:t,value:e,as:r}){switch(t){case"INTEGER":case"UINT":case"LONG":case"UINT_64":case"FLOAT":case"DOUBLE":{let s=this.getValueAsNumber({value:e,as:r});return s==null?S.Expression.nop():S.Expression.numberLiteral(s)}case"BOOLEAN":{let s=this.getValueAsBoolean({value:e,as:r});return s==null?S.Expression.nop():S.Expression.boolLiteral(s)}case"STRING":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.escapedStringLiteral(s)}case"DATE":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.calendarDateLiteral(s)}case"DATE_TIME":case"DATE_TIME_RFC_2822":{let s=this.context.getValueAsString({value:e});if(s==null)return S.Expression.nop();let m=new Date(s).getTime(),l=Math.round(m/1e3),v=new Date(l*1e3).toISOString().replace(/\.\d{3}Z$/,"Z");return S.Expression.dateLiteral(v)}case"UUID":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.uuidLiteral(s)}case"BASE_64":{let s=this.context.getValueAsString({value:e});return s==null?S.Expression.nop():S.Expression.escapedStringLiteral(s)}case"BIG_INTEGER":return this.context.getValueAsString({value:e})==null?S.Expression.nop():S.Expression.nop();default:A(t)}}getValueAsNumber({value:t,as:e}){let r=e==="mapKey"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:t,as:e}){let r=(()=>{switch(e){case"mapKey":return t==="true"?!0:t==="false"?!1:t;case"mapValue":case void 0:return t;default:A(e)}})();return this.context.getValueAsBoolean({value:r})}};u();c();p();var Kt=class{constructor({context:t}){d(this,"context");this.context=t}getFilePropertyInfo({fromSymbol:t,body:e,value:r}){let s={fileFields:[],bodyPropertyFields:[],orderedFields:[]},m=this.context.getRecord(r)??{};for(let l of e.properties)switch(l.type){case"file":{let b=S.functionArgument({label:De(l.name.camelCase.unsafeName),value:this.getSingleFileProperty({property:l,record:m})});s.fileFields.push(b),s.orderedFields.push(b);break}case"fileArray":{let b=S.functionArgument({label:De(l.name.camelCase.unsafeName),value:this.getArrayFileProperty({property:l,record:m})});s.fileFields.push(b),s.orderedFields.push(b);break}case"bodyProperty":{let b=S.functionArgument({label:De(l.name.name.camelCase.unsafeName),value:this.getBodyProperty({fromSymbol:t,property:l,record:m})});s.bodyPropertyFields.push(b),s.orderedFields.push(b);break}default:A(l)}return s}getSingleFileProperty({property:t,record:e}){let r=this.context.getSingleFileValue({property:t,record:e});return S.Expression.contextualMethodCall({methodName:"init",arguments_:[S.functionArgument({label:"data",value:S.Expression.dataLiteral(r??"")})]})}getArrayFileProperty({property:t,record:e}){let r=this.context.getFileArrayValues({property:t,record:e});return S.Expression.arrayLiteral({elements:(r??[]).map(s=>S.Expression.contextualMethodCall({methodName:"init",arguments_:[S.functionArgument({label:"data",value:S.Expression.dataLiteral(s)})]})),multiline:!0})}getBodyProperty({fromSymbol:t,property:e,record:r}){let s=r[e.name.wireValue];return s==null?S.Expression.nop():this.context.dynamicTypeLiteralMapper.convert({fromSymbol:t,typeReference:e.typeReference,value:s})}};u();c();p();function ds({parentSymbol:i,registry:t,namedType:e,context:r}){ie(e,"type")._visit({object:s=>{Ir({parentSymbol:i,registry:t,properties:s.properties})},discriminatedUnion:s=>{Object.values(s.types).forEach(m=>{ie(m,"type")._visit({noProperties:K,samePropertiesAsObject:K,singleProperty:l=>{se({parentSymbol:i,registry:t,typeReference:l.typeReference})},_other:K})})},undiscriminatedUnion:s=>{s.types.forEach(m=>{se({parentSymbol:i,registry:t,typeReference:m})})},alias:K,enum:K,_other:K})}function Ir({parentSymbol:i,registry:t,properties:e}){e.forEach(r=>{se({parentSymbol:i,registry:t,typeReference:r.typeReference})})}function se({parentSymbol:i,registry:t,typeReference:e}){ie(e,"type")._visit({list:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},literal:r=>{ie(r.value,"type")._visit({string:s=>{t.registerNestedLiteralEnumSymbol({parentSymbol:i,literalValue:s.value})},boolean:K,_other:K})},map:r=>{se({parentSymbol:i,registry:t,typeReference:r.key}),se({parentSymbol:i,registry:t,typeReference:r.value})},named:K,nullable:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},optional:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},primitive:K,set:r=>{se({parentSymbol:i,registry:t,typeReference:r.value})},unknown:K,_other:K})}u();c();p();function hs({parentSymbol:i,registry:t,namedType:e,context:r}){if(e.type==="undiscriminatedUnion"){let s=e.types.map(m=>{let l=r.getSwiftTypeReferenceFromScope(m,i);return{swiftType:l,caseName:Ot.inferCaseNameForTypeReference(i,l,t),docsContent:void 0}});t.registerUndiscriminatedUnionVariants({parentSymbol:i,variants:s})}}var Yt=class i extends ft{constructor({ir:e,config:r,options:s,sharedNameRegistry:m}){super({ir:e,config:r,options:s});d(this,"ir");d(this,"customConfig");d(this,"dynamicTypeLiteralMapper");d(this,"filePropertyMapper");d(this,"nameRegistry");this.ir=e,this.customConfig=r.customConfig!=null?r.customConfig:void 0,this.dynamicTypeLiteralMapper=new Ht({context:this}),this.filePropertyMapper=new Kt({context:this}),m!=null?this.nameRegistry=m:(this.nameRegistry=_t.create(),this.registerSourceSymbols(this.nameRegistry,e))}registerSourceSymbols(e,r){let s=fs(this.config.workspaceName),m=e.registerSourceModuleSymbol({configModuleName:this.customConfig?.moduleName,apiNamePascalCase:s,asIsSymbols:Object.values(S.SourceAsIsFileSpecs).flatMap(b=>b.symbols)});return e.registerRootClientSymbol({configClientClassName:this.customConfig?.clientClassName,registeredSourceModuleName:m.name}),lr(S.SourceTemplateFileSpecs).forEach(([b])=>{switch(b){case"ClientError":e.registerErrorEnumSymbol(m.name);break;case"HTTPClient":e.registerSourceStaticSymbol(b,{type:"class"});break;case"ClientConfig":e.registerSourceStaticSymbol(b,{type:"class"});break;default:A(b)}}),e.registerEnvironmentSymbol({configEnvironmentEnumName:this.customConfig?.environmentEnumName,registeredSourceModuleName:m.name}),Object.entries(r.types).map(([b,v])=>{let T=ie(v,"type")._visit({alias:()=>({type:"struct"}),enum:()=>({type:"enum-with-raw-values"}),object:()=>({type:"struct"}),discriminatedUnion:()=>({type:"enum-with-associated-values"}),undiscriminatedUnion:()=>({type:"enum-with-associated-values"}),_other:()=>({type:"other"})}),I=e.registerSchemaTypeSymbol(b,v.declaration.name.pascalCase.unsafeName,T);return{namedType:v,registeredSymbol:I}}).forEach(({namedType:b,registeredSymbol:v})=>{ds({parentSymbol:v,registry:e,namedType:b,context:this}),hs({parentSymbol:v,registry:e,namedType:b,context:this})}),e.registerRequestsContainerSymbol(),Object.entries(r.endpoints).forEach(([b,v])=>{if(v.request.type==="inlined"){if(v.request.body?.type==="properties"){let T=e.registerRequestTypeSymbol({endpointId:b,requestNamePascalCase:v.request.declaration.name.pascalCase.unsafeName});Ir({parentSymbol:T,registry:e,properties:v.request.body.value})}v.request.body?.type==="fileUpload"&&e.registerRequestTypeSymbol({endpointId:b,requestNamePascalCase:v.request.declaration.name.pascalCase.unsafeName}),v.request.queryParameters?.forEach(T=>{se({parentSymbol:m,registry:e,typeReference:T.typeReference})})}}),e}getNamedTypeOrThrow(e){let r=this.ir.types[e];return ne(r,`Type declaration with the id '${e}' not found`),r}getPropertiesOfDiscriminatedUnionVariant(e){let r=this.getNamedTypeOrThrow(e);return ie(r,"type")._visit({alias:()=>[],enum:()=>[],object:s=>s.properties,discriminatedUnion:()=>[],undiscriminatedUnion:()=>[],_other:()=>[]})}getSwiftTypeReferenceFromScope(e,r){let s=this.createReferencer(r);return ie(e,"type")._visit({list:m=>S.TypeReference.array(this.getSwiftTypeReferenceFromScope(m.value,r)),literal:m=>ie(m.value,"type")._visit({boolean:()=>s.referenceSwiftType("Bool"),string:l=>{let b=this.nameRegistry.getNestedLiteralEnumSymbol(r,l.value);return b==null?s.referenceAsIsType("JSONValue"):s.referenceType(b)},_other:()=>s.referenceAsIsType("JSONValue")}),map:m=>S.TypeReference.dictionary(this.getSwiftTypeReferenceFromScope(m.key,r),this.getSwiftTypeReferenceFromScope(m.value,r)),named:m=>{let l=this.nameRegistry.getSchemaTypeSymbolOrThrow(m.value),b=this.nameRegistry.reference({fromSymbol:r,toSymbol:l});return S.TypeReference.symbol(b)},nullable:m=>this.customConfig?.nullableAsOptional?S.TypeReference.optional(this.getSwiftTypeReferenceFromScope(m.value,r)):S.TypeReference.nullable(this.getSwiftTypeReferenceFromScope(m.value,r)),optional:m=>S.TypeReference.optional(this.getSwiftTypeReferenceFromScope(m.value,r)),primitive:m=>ie(m,"value")._visit({STRING:()=>s.referenceSwiftType("String"),BOOLEAN:()=>s.referenceSwiftType("Bool"),INTEGER:()=>s.referenceSwiftType("Int"),UINT:()=>s.referenceSwiftType("UInt"),UINT_64:()=>s.referenceSwiftType("UInt64"),LONG:()=>s.referenceSwiftType("Int64"),FLOAT:()=>s.referenceSwiftType("Float"),DOUBLE:()=>s.referenceSwiftType("Double"),BIG_INTEGER:()=>s.referenceSwiftType("String"),DATE:()=>s.referenceAsIsType("CalendarDate"),DATE_TIME:()=>s.referenceFoundationType("Date"),DATE_TIME_RFC_2822:()=>s.referenceFoundationType("Date"),BASE_64:()=>s.referenceSwiftType("String"),UUID:()=>s.referenceFoundationType("UUID"),_other:()=>s.referenceAsIsType("JSONValue")}),set:()=>s.referenceAsIsType("JSONValue"),unknown:()=>s.referenceAsIsType("JSONValue"),_other:()=>s.referenceAsIsType("JSONValue")})}createReferencer(e){return new Mt(this.nameRegistry,e)}clone(){return new i({ir:this.ir,config:this.config,options:this.options,sharedNameRegistry:this.nameRegistry})}};u();c();p();var ys="client",et=class{constructor({context:t}){d(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e,options:r}){return this.buildCodeBlock({endpoint:t,snippetRequest:e,options:r})}generateSnippetSync({endpoint:t,request:e,options:r}){return this.buildCodeBlock({endpoint:t,snippetRequest:e,options:r})}async generateSnippetAst({endpoint:t,request:e,options:r}){throw new Error("Unsupported")}buildCodeBlock({endpoint:t,snippetRequest:e,options:r}){return[this.generateImportFoundationStatement(),this.generateImportModuleStatement(),S.LineBreak.single(),this.generateMainFunctionDeclarationWithEndpointSnippet({endpoint:t,snippet:e}),S.LineBreak.single(),this.generateMainFunctionInvocationStatement()].map(m=>m.toString()).join("")}generateImportFoundationStatement(){return S.Statement.import("Foundation")}generateImportModuleStatement(){let t=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return S.Statement.import(t.name)}generateMainFunctionDeclarationWithEndpointSnippet({endpoint:t,snippet:e}){return S.Statement.functionDeclaration({unsafeName:"main",accessLevel:"private",async:!0,throws:!0,body:S.CodeBlock.withStatements([this.generateRootClientInitializationStatement({auth:t.auth,snippet:e}),S.LineBreak.single(),this.generateEndpointMethodCallStatement({endpoint:t,snippet:e})])})}generateRootClientInitializationStatement({auth:t,snippet:e,additionalArgs:r=[]}){let s=[],m=this.getRootClientBaseURLArg({snippet:e});m!=null&&s.push(m);let l=t?this.getRootClientAuthArgs({auth:t,snippet:e}):[];s.push(...l),this.context.ir.headers!=null&&e.headers!=null&&s.push(...this.getRootClientHeaderArgs({headers:this.context.ir.headers,values:e.headers})),s.push(...r);let b=s.filter(T=>!T.value.isNop()),v=this.context.nameRegistry.getRootClientSymbolOrThrow();return S.Statement.constantDeclaration({unsafeName:ys,value:S.Expression.classInitialization({unsafeName:v.name,arguments_:b,multiline:b.length>1?!0:void 0})})}getRootClientHeaderArgs({headers:t,values:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),s=[];for(let m of t){let l=e[m.name.wireValue],b=this.getRootClientHeaderArg({moduleSymbol:r,header:m,value:l});b!=null&&s.push(b)}return s}getRootClientHeaderArg({moduleSymbol:t,header:e,value:r}){if(e.typeReference.type==="literal")return;let s=this.context.dynamicTypeLiteralMapper.convert({fromSymbol:t,typeReference:e.typeReference,value:r});if(!s.isNop())return S.functionArgument({label:e.name.name.camelCase.unsafeName,value:s})}getRootClientBaseURLArg({snippet:t}){return t.baseURL!=null&&t.environment!=null?(this.context.errors.add({severity:M.Critical,message:"Cannot specify both baseUrl and environment options"}),null):t.baseURL!=null?this.context.ir.environments?.environments.type==="multipleBaseUrls"?null:S.functionArgument({label:"baseURL",value:S.Expression.escapedStringLiteral(t.baseURL)}):null}getRootClientAuthArgs({auth:t,snippet:e}){let r=[],s=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),m=e.auth;if(m==null)return r;switch(t.type){case"basic":if(m.type!=="basic"){this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message});break}r.push(S.functionArgument({label:t.username.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.username)}),S.functionArgument({label:t.password.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.password)}));break;case"bearer":if(m.type!=="bearer")return this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;r.push(S.functionArgument({label:t.token.camelCase.unsafeName,value:S.Expression.escapedStringLiteral(m.token)}));break;case"header":if(m.type!=="header")return this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;r.push(S.functionArgument({label:t.header.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:s,typeReference:t.header.typeReference,value:m.value})}));break;case"oauth":return m.type!=="oauth"&&this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;case"inferred":return m.type!=="inferred"&&this.context.errors.add({severity:M.Critical,message:this.context.newAuthMismatchError({auth:t,values:m}).message}),r;default:A(t)}return r}generateEndpointMethodCallStatement({endpoint:t,snippet:e}){return S.Statement.discardAssignment(this.generateEndpointMethodCallExpression({endpoint:t,snippet:e}))}generateEndpointMethodCallExpression({endpoint:t,snippet:e,additionalArguments:r=[]}){let m=[...this.getEndpointMethodArguments({endpoint:t,snippet:e}).filter(l=>!l.value.isNop()),...r];return S.Expression.try(S.Expression.await(S.Expression.methodCall({target:S.Expression.rawValue(ys),methodName:this.getEndpointMethodName({endpoint:t}),arguments_:m,multiline:m.length>1?!0:void 0})))}generateMainFunctionInvocationStatement(){return S.Statement.expressionStatement(S.Expression.try(S.Expression.await(S.Expression.functionCall({unsafeName:"main"}))))}getEndpointMethodName({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${`${t.declaration.fernFilepath.allParts.map(r=>r.camelCase.unsafeName).join(".")}`}.${t.declaration.name.camelCase.unsafeName}`:t.declaration.name.camelCase.unsafeName}getEndpointMethodArguments({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getEndpointMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getEndpointMethodArgsForBodyRequest({request:t.request,snippet:e});default:A(t.request)}}getEndpointMethodArgsForInlinedRequest({request:t,snippet:e}){let r=[];this.context.errors.scope(he.PathParameters);let s=[...this.context.ir.pathParameters??[],...t.pathParameters??[]],m=[];s.length>0&&m.push(...this.getEndpointMethodPathParameters({namedParameters:s,snippet:e})),this.context.errors.unscope(),r.push(...m),this.context.errors.scope(he.Headers);let l=[];t.headers!=null&&l.push(...this.getEndpointMethodHeaderParameters({namedParameters:t.headers,snippet:e})),this.context.errors.unscope(),r.push(...l),this.context.errors.scope(he.QueryParameters);let b=[];t.queryParameters!=null&&b.push(...this.getEndpointMethodQueryParameters({namedParameters:t.queryParameters,snippet:e})),this.context.errors.unscope(),r.push(...b),this.context.errors.scope(he.RequestBody);let v=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),t.body!=null&&(t.body.type==="referenced"?r.push(S.functionArgument({label:"request",value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.body.bodyType,value:e.requestBody})})):r.push(S.functionArgument({label:"request",value:this.getInlinedRequestArg({request:t,snippet:e,filePropertyInfo:v})}))),r}getEndpointMethodPathParameters({namedParameters:t,snippet:e}){return this.context.associateByWireValueOrDefault({parameters:t,values:e.pathParameters??{}}).map(r=>S.functionArgument({label:r.name.name.camelCase.unsafeName,value:this.renderPathParameterValueAsSwiftString({value:r.value})}))}renderPathParameterValueAsSwiftString({value:t}){return typeof t=="string"?S.Expression.escapedStringLiteral(t):typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?S.Expression.escapedStringLiteral(String(t)):t==null?S.Expression.nop():S.Expression.escapedStringLiteral(JSON.stringify(t))}getEndpointMethodQueryParameters({namedParameters:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return this.context.getExampleObjectProperties({parameters:t,snippetObject:e.queryParameters??{}}).map(s=>S.functionArgument({label:s.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:s.typeReference,value:s.value})}))}getEndpointMethodHeaderParameters({namedParameters:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow(),s=this.context.createReferencer(r);return this.context.getExampleObjectProperties({parameters:t,snippetObject:e.headers??{}}).filter(m=>{let l=this.resolveAliasTypeReference(m.typeReference),b=this.context.getSwiftTypeReferenceFromScope(l,r);return s.resolvesToTheSwiftType(b.nonOptional(),"String")}).map(m=>S.functionArgument({label:m.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:m.typeReference,value:m.value})}))}resolveAliasTypeReference(t){if(t.type==="named"){let e=this.context.ir.types[t.value];if(e!=null&&e.type==="alias")return this.resolveAliasTypeReference(e.typeReference)}return t}getFilePropertyInfo({request:t,snippet:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[],orderedFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({fromSymbol:r,body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,filePropertyInfo:r}){this.context.errors.scope(he.RequestBody);let s=t.body!=null?this.getInlinedRequestBodyObjectFields({body:t.body,value:e.requestBody,filePropertyInfo:r}):[];this.context.errors.unscope();let m=s.filter(l=>!l.value.isNop());return S.Expression.contextualMethodCall({methodName:"init",arguments_:m,multiline:m.length>1?!0:void 0})}getInlinedRequestBodyObjectFields({body:t,value:e,filePropertyInfo:r}){switch(t.type){case"fileUpload":return r.orderedFields;case"properties":return this.getInlinedRequestBodyPropertyObjectFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyObjectField({body:t,value:e})];default:A(t)}}getInlinedRequestBodyPropertyObjectFields({parameters:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();return this.context.getExampleObjectProperties({parameters:t,snippetObject:e}).map(s=>S.functionArgument({label:s.name.name.camelCase.unsafeName,value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:s.typeReference,value:s.value})}))}getReferencedRequestBodyPropertyObjectField({body:t,value:e}){return S.functionArgument({label:t.bodyKey.camelCase.unsafeName,value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.bodyType,value:e})})}getReferencedRequestBodyPropertyTypeLiteral({body:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:t.value,value:e});default:A(t)}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:M.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),S.Expression.dataLiteral("data")):S.Expression.dataLiteral(t)}getEndpointMethodArgsForBodyRequest({request:t,snippet:e}){let r=[];this.context.errors.scope(he.PathParameters);let s=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];if(s.length>0&&r.push(...this.getEndpointMethodPathParameters({namedParameters:s,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(he.RequestBody),t.body!=null){let m=this.getEndpointMethodBodyRequestArg({body:t.body,value:e.requestBody});m.value.isNop()||r.push(m)}return this.context.errors.unscope(),r}getEndpointMethodBodyRequestArg({body:t,value:e}){let r=this.context.nameRegistry.getRegisteredSourceModuleSymbolOrThrow();switch(t.type){case"bytes":return S.functionArgument({label:"request",value:this.getBytesBodyRequestArg({value:e})});case"typeReference":return t.value.type==="optional"&&e==null?S.functionArgument({label:"request",value:S.Expression.nop()}):S.functionArgument({label:"request",value:this.context.dynamicTypeLiteralMapper.convert({fromSymbol:r,typeReference:t.value,value:e})});default:A(t)}}};var Jt=class extends pt{constructor({ir:t,config:e,options:r={}}){super(new Yt({ir:t,config:e,options:r}))}async generate(t,e={}){return super.generate(t,e)}generateSync(t,e={}){return super.generateSync(t,e)}async generateSnippetAst(t){return super.generateSnippetAst(t)}createSnippetGenerator(t){return new et({context:t})}};0&&(module.exports={DynamicSnippetsGenerator,EndpointSnippetGenerator});
|
|
26
26
|
/*! Bundled license information:
|
|
27
27
|
|
|
28
28
|
@jspm/core/nodelibs/browser/chunk-DtuTasat.js:
|