@fern-api/php-dynamic-snippets 1.25.3 → 1.25.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +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.js
CHANGED
|
@@ -24,7 +24,7 @@ ${this.buffer}`:i+`
|
|
|
24
24
|
`):void 0;a!=null&&a.length>1&&(a.forEach(d=>{e.writeLine(` * ${d}`)}),e.writeLine(" *")),e.write(` * @${i.tagType} `),i.type.write(e,{comment:!0}),i.name!=null&&e.write(` ${i.name}`),a!=null&&a.length===1&&e.write(` ${a[0]}`),e.newLine()}};s();p();u();function Be(r){return oc(r,[Se.Public,Se.PublicReadonly,Se.Protected,Se.Private])}function oc(r,t){return t.reduce((e,i)=>[...e,...r.filter(a=>a.access===i)],[])}var ge=class extends S{constructor({name:e,namespace:i,abstract:a,docs:d,parentClassReference:f,traits:v}){super();x(this,"name");x(this,"namespace");x(this,"abstract");x(this,"docs");x(this,"parentClassReference");x(this,"traits");x(this,"fields",[]);x(this,"methods",[]);x(this,"constructor_");this.name=e,this.namespace=i,this.abstract=a??!1,this.docs=d,this.parentClassReference=f,this.traits=v??[]}addConstructor(e){this.constructor_=e}addField(e){this.fields.push(e)}addMethod(e){this.methods.push(e)}addMethods(e){this.methods.push(...e)}addTrait(e){this.traits.push(e)}write(e){e.addReference(new K({name:this.name,namespace:this.namespace})),this.abstract&&e.write("abstract "),this.writeComment(e),e.write(`class ${this.name} `),this.parentClassReference!=null&&(e.write("extends "),this.parentClassReference.write(e)),e.newLine(),e.writeLine("{"),e.indent(),this.traits.length>0&&(e.write("use "),this.traits.forEach((i,a)=>{a>0&&e.write(","),e.writeNode(i)}),e.writeTextStatement(""),e.newLine()),this.writeFields({writer:e,fields:Be(this.fields)}),(this.constructor!=null||this.methods.length>0)&&e.newLine(),this.constructor_!=null&&(this.writeConstructor({writer:e,constructor:this.constructor_}),this.methods.length>0&&e.newLine()),this.writeMethods({writer:e,methods:Be(this.methods)}),e.dedent(),e.writeLine("}")}writeComment(e){if(this.docs==null)return;new X({docs:this.docs}).write(e)}writeConstructor({writer:e,constructor:i}){this.writeConstructorComment({writer:e,constructor:i}),i.access!=null&&e.write(`${i.access} `),e.write("function __construct("),e.indent(),i.parameters.forEach((a,d)=>{d===0&&e.newLine(),a.write(e),e.writeLine(",")}),e.dedent(),e.writeLine(")"),e.writeLine("{"),e.indent(),i.body?.write(e),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeConstructorComment({writer:e,constructor:i}){if(i.parameters.length===0)return;let a=new X;for(let d of i.parameters)a.addTag(d.getCommentTag());a.write(e)}writeFields({writer:e,fields:i}){i.filter(a=>!a.inherited).forEach((a,d)=>{d>0&&e.newLine(),a.write(e),e.writeNewLineIfLastLineNot()})}writeMethods({writer:e,methods:i}){i.forEach((a,d)=>{d>0&&e.newLine(),a.write(e),e.writeNewLineIfLastLineNot()})}};s();p();u();s();p();u();function tt({writer:r,arguments_:t,multiline:e}){if(t.length===0){r.write("()");return}if(e){ac({writer:r,arguments_:t});return}sc({writer:r,arguments_:t})}function ac({writer:r,arguments_:t}){r.writeLine("("),r.indent();for(let e of t)Sa({writer:r,argument:e,writeCompact:!1}),r.writeLine(",");r.dedent(),r.write(")")}function sc({writer:r,arguments_:t}){r.write("("),t.forEach((e,i)=>{i>0&&r.write(", "),Sa({writer:r,argument:e,writeCompact:!0})}),r.write(")")}function Sa({writer:r,argument:t,writeCompact:e}){hr(t)?(t.docs&&(e?r.write(`/* ${t.docs} */ `):r.writeLine(`/* ${t.docs} */`)),r.write(`${t.name}: `),r.writeNodeOrString(t.assignment)):t.write(r)}var le=class extends S{constructor({classReference:e,arguments_:i,multiline:a}){super();x(this,"classReference");x(this,"arguments_");x(this,"multiline");this.classReference=e,this.arguments_=i,this.multiline=a??!1}write(e){e.write("new "),e.writeNode(this.classReference),tt({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};s();p();u();var J=class extends S{constructor(e){super();x(this,"arg");this.arg=e}write(e){return new ne(this.arg).write(e)}};s();p();u();s();p();u();var xe=class extends S{constructor({name:e,type:i,docs:a,initializer:d,access:f,readonly_:v}){super();x(this,"name");x(this,"type");x(this,"docs");x(this,"initializer");x(this,"access");x(this,"readonly_");this.name=Le(e),this.type=i,this.docs=a,this.initializer=d,this.access=f,this.readonly_=v??!1}getCommentTag(){return{tagType:"param",type:this.type,name:this.name,docs:this.docs}}write(e){this.access!=null&&e.write(`${this.access} `),this.readonly_&&e.write("readonly "),this.type.write(e),e.write(` ${this.name}`),this.initializer!=null?(e.write(" = "),this.initializer.write(e)):this.type.isOptional()&&e.write(" = null")}};s();p();u();s();p();u();s();p();u();s();p();u();var we=class extends S{constructor({method:e,arguments_:i,static_:a,multiline:d,on:f}){super();x(this,"method");x(this,"arguments_");x(this,"multiline");x(this,"static_");x(this,"on");this.method=e,this.arguments_=i,this.static_=a??!1,this.multiline=d??!1,this.on=f}write(e){this.on!=null&&(this.on.write(e),e.write(this.getMethodAccessor())),e.write(this.method),tt({writer:e,arguments_:this.arguments_,multiline:this.multiline})}getMethodAccessor(){return this.static_?"::":"->"}};var ie=class r extends S{constructor(e){super();x(this,"internalType");this.internalType=e}write(e){switch(this.internalType.type){case"list":{this.writeList({writer:e,list:this.internalType});break}case"boolean":{e.write(this.internalType.value.toString());break}case"class":{this.writeClass({writer:e,class_:this.internalType});break}case"file":{e.writeNode(pc({writer:e,value:this.internalType.value,namespace:this.internalType.namespace}));break}case"float":{e.write(this.internalType.value.toString());break}case"number":{e.write(this.internalType.value.toString());break}case"map":{this.writeMap({writer:e,map:this.internalType});break}case"reference":{e.writeNode(this.internalType.value);break}case"datetime":{e.writeNode(uc({writer:e,value:this.internalType.value}));break}case"string":{if(this.internalType.value.includes(`
|
|
25
25
|
`)){this.writeStringWithHeredoc({writer:e,value:this.internalType.value});break}if(this.internalType.value.includes("'")){e.write(`"${this.internalType.value.replaceAll('"','\\"')}"`);break}e.write(`'${this.internalType.value}'`);break}case"unknown":{this.writeUnknown({writer:e,value:this.internalType.value});break}case"null":{e.write("null");break}case"nop":break;default:O(this.internalType)}}isClass(){return this.internalType.type==="class"}asClassOrThrow(){if(this.isClass())return this.internalType;throw new Error("Internal error; ts.TypeLiteral is not a class")}writeStringWithHeredoc({writer:e,value:i}){e.writeLine("<<<EOT"),e.writeNoIndent(i),e.newLine(),e.writeNoIndent("EOT")}writeClass({writer:e,class_:i}){e.writeNode(new le({classReference:i.reference,arguments_:[r.map({entries:i.fields.map(a=>({key:r.string(a.name),value:a.value}))})]}))}writeList({writer:e,list:i}){let a=fc({values:i.values});if(a.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let d of a)d.write(e),e.writeLine(",");e.dedent(),e.write("]")}writeMap({writer:e,map:i}){let a=lc({entries:i.entries});if(a.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let d of a)d.key.write(e),e.write(" => "),d.value.write(e),e.writeLine(",");e.dedent(),e.write("]")}static list({values:e}){return new this({type:"list",values:e})}static boolean(e){return new this({type:"boolean",value:e})}static class_({reference:e,fields:i}){return new this({type:"class",reference:e,fields:i})}static file(e,i){return new this({type:"file",value:e,namespace:i})}static float(e){return new this({type:"float",value:e})}static datetime(e){return new this({type:"datetime",value:e})}static number(e){return new this({type:"number",value:e})}static map({entries:e}){return new this({type:"map",entries:e})}static reference(e){return new this({type:"reference",value:e})}static string(e){return new this({type:"string",value:e})}static unknown(e){return new this({type:"unknown",value:e})}static null(){return new this({type:"null"})}static nop(){return new this({type:"nop"})}static isNop(e){return e.internalType.type==="nop"}writeUnknown({writer:e,value:i}){switch(typeof i){case"boolean":e.write(i.toString());return;case"string":e.write(i.includes('"')?`\`${i}\``:`"${i}"`);return;case"number":e.write(i.toString());return;case"object":if(i==null){e.write("null");return}if(Array.isArray(i)){this.writeUnknownArray({writer:e,value:i});return}this.writeUnknownMap({writer:e,value:i});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof i}`)}}writeUnknownArray({writer:e,value:i}){if(i.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let a of i)e.writeNode(r.unknown(a)),e.writeLine(",");e.dedent(),e.write("]")}writeUnknownMap({writer:e,value:i}){let a=Object.entries(i);if(a.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let[d,f]of a)e.write(`'${d}' => `),e.writeNode(r.unknown(f)),e.writeLine(",");e.dedent(),e.write("]")}};function uc({writer:r,value:t}){return new le({classReference:new K({name:"DateTime",namespace:""}),arguments_:[new J(`'${t}'`)]})}function pc({writer:r,value:t,namespace:e}){return new we({on:new K({name:"File",namespace:e!=null?`${e}\\Utils`:`${r.rootNamespace}\\Utils`}),method:"createFromString",arguments_:[new J(`"${t}"`),new J(`"${t}"`)],static_:!0})}function lc({entries:r}){return r.filter(t=>!ie.isNop(t.key)&&!ie.isNop(t.value))}function fc({values:r}){return r.filter(t=>!ie.isNop(t))}var oe=class r extends S{constructor(e){super();x(this,"internalType");this.internalType=e}write(e,{comment:i}={}){switch(this.internalType.type){case"int":e.write("int");break;case"string":e.write("string");break;case"bool":e.write("bool");break;case"float":e.write("float");break;case"date":e.addReference(La),e.write("DateTime");break;case"dateTime":e.addReference(La),e.write("DateTime");break;case"mixed":e.write("mixed");break;case"object":e.write("object");break;case"array":if(!i){e.write("array");break}e.write("array<"),this.internalType.value.write(e,{comment:i}),e.write(">");break;case"map":{if(!i){e.write("array");break}e.write("array<"),this.internalType.keyType.write(e,{comment:i}),e.write(", "),this.internalType.valueType.write(e,{comment:i}),e.write(">");break}case"null":{e.write("null");break}case"typeDict":{if(!i){e.write("array");break}if(this.internalType.multiline){e.writeLine("array{");let a=this.internalType.entries.filter(v=>!v.valueType.isOptional()),d=this.internalType.entries.filter(v=>v.valueType.isOptional()),f=[...a,...d];for(let v of f)e.write(" * "),this.writeTypeDictEntry({writer:e,entry:v,comment:i}),e.writeLine(",");e.write(" * }");break}e.write("array{"),this.internalType.entries.forEach((a,d)=>{d>0&&e.write(", "),this.writeTypeDictEntry({writer:e,entry:a,comment:i})}),e.write("}");break}case"union":{this.writeUnion({writer:e,unionTypes:this.internalType.types,comment:i});break}case"optional":{let a=this.internalType.value.internalType,d=a.type==="mixed",f=a.type==="union";!f&&!d&&e.write("?"),this.internalType.value.write(e,{comment:i}),f&&!this.unionHasOptional(a.types)&&(e.write("|"),e.writeNode(r.null()));break}case"reference":if(i){e.writeNode(this.internalType.value);let a=this.internalType.value.generics;a&&a.length>0&&(e.write("<"),a.forEach((d,f)=>{f>0&&e.write(", "),d.write(e,{comment:i})}),e.write(">"))}else e.writeNode(this.internalType.value);break;case"enumString":i?(e.write("value-of<"),e.writeNode(this.internalType.value),e.write(">")):e.write("string");break;case"literal":if(i)e.writeNode(this.internalType.value);else switch(this.internalType.value.internalType.type){case"string":e.write("string");break;case"boolean":e.write("bool");break;default:O(this.internalType.value.internalType)}break;default:O(this.internalType)}}toOptionalIfNotAlready(){return this.internalType.type==="optional"?this:r.optional(this)}underlyingTypeIfOptional(){if(this.internalType.type==="optional")return this.internalType.value}underlyingType(){return this.underlyingTypeIfOptional()??this}isOptional(){return this.internalType.type==="optional"}getClassReference(){switch(this.internalType.type){case"date":case"dateTime":return new K({name:"DateTime",namespace:""});case"enumString":case"reference":return this.internalType.value;case"int":case"string":case"bool":case"float":case"object":case"map":case"array":case"null":case"mixed":case"optional":case"typeDict":case"union":case"literal":throw new Error("Cannot get class reference for "+this.internalType.type);default:O(this.internalType)}}static int(){return new this({type:"int"})}static string(){return new this({type:"string"})}static bool(){return new this({type:"bool"})}static float(){return new this({type:"float"})}static date(){return new this({type:"date"})}static dateTime(){return new this({type:"dateTime"})}static mixed(){return new this({type:"mixed"})}static object(){return new this({type:"object"})}static array(e){return new this({type:"array",value:e})}static map(e,i){return new this({type:"map",keyType:e,valueType:i})}static typeDict(e,{multiline:i}={}){return new this({type:"typeDict",entries:e,multiline:i})}static union(e){let i=this.flattenUnionTypes(e),a=qt(i,jt);return new this({type:"union",types:a})}static flattenUnionTypes(e){let i=[];for(let a of e)a.internalType.type==="union"?i.push(...this.flattenUnionTypes(a.internalType.types)):i.push(a);return i}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static null(){return new this({type:"null"})}static reference(e){return new this({type:"reference",value:e})}static enumString(e){return new this({type:"enumString",value:e})}static literalString(e){return new this({type:"literal",value:ie.string(e)})}static literalBoolean(e){return new this({type:"literal",value:ie.boolean(e)})}static isAlreadyOptional(e){return e.internalType.type==="optional"}writeUnion({writer:e,unionTypes:i,comment:a}){let d=this.getUniqueTypes({types:i,comment:a,writer:e}),f=this.unwrapOptionalTypes(d),v=f.filter(T=>T.underlyingType().internalType.type==="mixed").length>0;if(v&&!a){e.write("mixed");return}if(f.length>0&&a){e.writeLine("("),f.forEach((T,E)=>{E>0?e.write(" * |"):e.write(" * "),v&&(T=T.underlyingType()),T.write(e,{comment:a}),e.writeLine(),E++}),e.write(" * )");return}f.forEach((T,E)=>{E>0&&e.write("|"),v&&(T=T.underlyingType()),T.write(e,{comment:a}),E++})}writeTypeDictEntry({writer:e,entry:i,comment:a}){e.write(i.key),i.optional&&e.write("?"),e.write(": "),i.valueType.write(e,{comment:a})}getUniqueTypes({writer:e,types:i,comment:a}){let d=qt(i,jt),f=new Set;return d.filter(v=>{let T=v.toString({namespace:e.namespace,rootNamespace:e.rootNamespace,customConfig:e.customConfig,comment:a});return f.has(T)?!1:(f.add(T),!0)})}unwrapOptionalTypes(e){let i=!1,a=e.map(d=>d.internalType.type==="optional"?(i=!0,d.internalType.value):d);return i&&a.push(r.null()),a}unionHasOptional(e){return e.filter(i=>i.internalType.type==="optional").length>0}toString({namespace:e,rootNamespace:i,customConfig:a,comment:d}){let f=new pe({namespace:e,rootNamespace:i,customConfig:a});return this.write(f,{comment:d??!1}),f.toString()}},La=new K({namespace:"",name:"DateTime"});s();p();u();function Ba(r){return r.startsWith("$")?r.slice(1):r}var yr="values",Me=class extends S{constructor({name:e,namespace:i,abstract:a,docs:d,parentClassReference:f,traits:v,constructorAccess:T}){super();x(this,"name");x(this,"namespace");x(this,"constructorAccess");x(this,"class_");this.name=e,this.namespace=i,this.constructorAccess=T??"public",this.class_=new ge({name:e,namespace:i,abstract:a,docs:d,parentClassReference:f,traits:v})}addField(e){this.class_.addField(e)}addMethod(e){this.class_.addMethod(e)}addTrait(e){this.class_.addTrait(e)}write(e){let i=Be(this.class_.fields).map(a=>({...a,name:Ba(a.name)}));this.class_.addConstructor({access:this.constructorAccess,parameters:this.getConstructorParameters({orderedFields:i}),body:A.codeblock(a=>{if(i.length>0)for(let d of i)a.write(`$this->${d.name} = $${yr}['${d.name}']`),d.type.isOptional()&&a.write(" ?? null"),a.write(";");else a.writeLine(`unset($${yr});`)})}),this.class_.write(e)}allFieldsAreOptional(){return this.class_.fields.every(e=>e.type.isOptional())}getConstructorParameters({orderedFields:e}){return[new xe({name:yr,type:oe.typeDict(e.map(i=>({key:i.name,valueType:i.type,optional:i.type.isOptional()})),{multiline:!0}),initializer:this.allFieldsAreOptional()?new J("[]"):void 0})]}};s();p();u();s();p();u();var ve=class extends S{constructor({name:e,access:i,parameters:a,throws:d,return_:f,body:v,docs:T,classReference:E,static_:I}){super();x(this,"name");x(this,"access");x(this,"parameters");x(this,"throws");x(this,"return_");x(this,"body");x(this,"docs");x(this,"classReference");x(this,"static_");this.name=e,this.access=i,this.parameters=a,this.throws=d??[],this.return_=f,this.body=v,this.docs=T,this.classReference=E,this.static_=I??!1}write(e){this.writeComment(e),e.write(`${this.access}${this.static_?" static":""} function ${this.name}(`);let i=this.parameters.filter(f=>!f.type.isOptional()),a=this.parameters.filter(f=>f.type.isOptional());[...i,...a].forEach((f,v)=>{v>0&&e.write(", "),f.write(e)}),e.write("): "),this.return_!=null?e.writeNodeOrString(this.return_):e.write("void"),e.writeLine(" {"),e.indent(),this.body?.write(e),e.dedent(),e.writeLine("}")}writeComment(e){let i=new X({docs:this.docs});for(let a of this.parameters)i.addTag({tagType:"param",type:a.type,name:a.name,docs:a.docs});this.return_!=null&&this.return_!==Ea&&this.return_!==Ia&&i.addTag({tagType:"return",type:this.return_});for(let a of this.throws)i.addTag({tagType:"throws",type:oe.reference(a)});e.writeNode(i)}};var $e=class extends S{constructor({name:e,namespace:i,backing:a,docs:d,serializable:f}){super();x(this,"name");x(this,"namespace");x(this,"backing");x(this,"docs");x(this,"members",[]);x(this,"serializable");this.name=e,this.namespace=i,this.backing=a,this.docs=d,this.serializable=f??!1}addMember(e){this.members.push(e)}write(e){this.writeComment(e),e.write("enum "),e.writeLine(`${this.name}`),this.backing!=null&&e.write(` : ${this.backing}`),this.serializable&&(e.addReference(new K({name:"JsonSerializable",namespace:""})),e.writeLine(" implements JsonSerializable")),e.writeLine(" {"),e.indent();for(let i of this.members){if(e.write(`case ${i.name}`),i.value!=null)if(typeof i.value=="string"){let a=gr(i.value);e.write(` = "${a}"`)}else e.write(` = ${i.value}`);e.writeTextStatement("")}this.serializable&&(e.newLine(),e.writeNode(new ve({name:"jsonSerialize",return_:oe.string(),access:"public",parameters:[],body:new J("return $this->value;")}))),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeComment(e){if(this.docs==null)return;new X({docs:this.docs}).write(e)}};s();p();u();var De=class extends S{constructor({name:e,type:i,access:a,readonly_:d,initializer:f,docs:v,inlineDocs:T,attributes:E,inherited:I}){super();x(this,"name");x(this,"type");x(this,"access");x(this,"readonly_");x(this,"initializer");x(this,"docs");x(this,"inlineDocs");x(this,"attributes");x(this,"inherited");this.name=Le(e),this.type=i,this.access=a,this.readonly_=d??!1,this.initializer=f,this.docs=v,this.inlineDocs=T,this.attributes=E??[],this.inherited=I??!1}write(e){this.writeComment(e),this.writeAttributesIfPresent(e),e.write(`${this.access} `),this.readonly_&&e.write("readonly "),this.type.write(e),e.write(` ${this.name}`),this.initializer!=null&&(e.write(" = "),this.initializer.write(e)),e.write(";"),this.inlineDocs!=null&&e.write(` // ${this.inlineDocs}`),e.newLine()}writeComment(e){let i=new X;i.addTag({tagType:"var",type:this.type,name:this.name,docs:this.docs}),i.write(e)}writeAttributesIfPresent(e){this.attributes.length>0&&(e.write("#["),this.attributes.forEach((i,a)=>{a>0&&e.write(", "),i.write(e)}),e.writeLine("]"))}};s();p();u();var je=class extends S{constructor({entries:e,multiline:i}){super();x(this,"entries");x(this,"multiline");this.entries=e??[],this.multiline=i??!1}write(e){if(this.multiline){this.writeMultiline(e);return}this.writeCompact(e)}writeMultiline(e){e.writeLine("["),e.indent();for(let{key:i,value:a}of this.entries)i.write(e),e.write(" => "),a.write(e),e.writeLine(",");e.dedent(),e.write("]")}writeCompact(e){e.write("[");for(let[i,{key:a,value:d}]of this.entries.entries())i>0&&e.write(", "),a.write(e),e.write(" => "),d.write(e);e.write("]")}};s();p();u();var qe=class extends S{constructor({name:e,namespace:i,docs:a,traits:d}){super();x(this,"name");x(this,"namespace");x(this,"docs");x(this,"traits");x(this,"fields",[]);x(this,"methods",[]);this.name=e,this.namespace=i,this.docs=a,this.traits=d??[]}addField(e){this.fields.push(e)}addMethod(e){this.methods.push(e)}write(e){this.writeComment(e),e.write(`trait ${this.name} `),e.newLine(),e.writeLine("{"),e.indent(),this.traits.length>0&&(e.write("use "),this.traits.forEach((i,a)=>{a>0&&e.write(","),e.writeNode(i)}),e.writeTextStatement(""),e.newLine()),this.writeFields({writer:e,fields:Be(this.fields)}),this.fields.length>0&&this.methods.length>0&&e.newLine(),this.writeMethods({writer:e,methods:Be(this.methods)}),e.dedent(),e.writeLine("}")}writeComment(e){let i=new X({docs:this.docs});for(let a of this.fields)i.addTag({tagType:"property",type:a.type,name:a.name});i.write(e)}writeFields({writer:e,fields:i}){i.forEach((a,d)=>{d>0&&e.newLine(),a.write(e),e.writeNewLineIfLastLineNot()})}writeMethods({writer:e,methods:i}){i.forEach((a,d)=>{d>0&&e.newLine(),a.write(e),e.writeNewLineIfLastLineNot()})}};s();p();u();var Gt=class extends S{constructor(e){super();x(this,"arrays");this.arrays=e}write(e){e.write("array_merge"),tt({writer:e,arguments_:this.arrays.map(i=>Ve(a=>{if(typeof i=="string"||i instanceof S){a.writeNodeOrString(i);return}a.writeNodeOrString(i.ref),i.fallback&&(a.write(" ?? "),a.writeNodeOrString(i.fallback))}))})}};function cc(r){return new Ue(r)}function dc(r){return new Oe(r)}function mc(r){return new ge(r)}function hc(r){return new qe(r)}function yc(r){return new K(r)}function Ve(r){return new J(r)}function gc(r){return new Me(r)}function xc(r){return new $e(r)}function wc(r){return new De(r)}function Pa(r){return new le(r)}function vc(r){return new we(r)}function bc(r){return Ve(t=>{t.write("throw "),t.writeNode(Pa(r))})}function Tc(r){return new je(r)}function Ac(r){return new ve(r)}function Ec(r){return new xe(r)}function Ic(r){return new lt(r)}function Cc(r,t){return Ve(e=>{e.writeNodeOrString(r),e.write(" = "),e.writeNodeOrString(t)})}function Nc(r){return Ve(Le(r))}function Rc(r){return Ve(`"${r}"`)}function Sc(...r){return new Gt(r)}function gr(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\$/g,"\\$")}function Lc(){return new J(r=>{r.write("$this")})}s();p();u();function xr(r){return Ca.has(r.toLowerCase())?`${r}_`:r}s();p();u();var zt=class{constructor({context:t}){x(this,"context");this.context=t}convert(t){if(t.value===null)return this.context.isNullable(t.typeReference)?A.TypeLiteral.null():(this.context.errors.add({severity:_.Critical,message:"Expected non-null value, but got null"}),A.TypeLiteral.nop());if(t.value===void 0)return A.TypeLiteral.nop();switch(t.typeReference.type){case"list":case"set":return this.convertList({list:t.typeReference.value,value:t.value});case"literal":return this.convertLiteral({literalType:t.typeReference.value,value:t.value});case"map":return this.convertMap({map:t.typeReference,value:t.value});case"named":{let e=this.context.resolveNamedType({typeId:t.typeReference.value});return e==null?A.TypeLiteral.nop():this.convertNamed({named:e,value:t.value,as:t.as})}case"optional":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"nullable":return this.convert({typeReference:t.typeReference.value,value:t.value,as:t.as});case"primitive":return this.convertPrimitive({primitive:t.typeReference.value,value:t.value,as:t.as});case"unknown":return this.convertUnknown({value:t.value});default:O(t.typeReference)}}convertLiteral({literalType:t,value:e}){switch(t.type){case"boolean":{let i=this.context.getValueAsBoolean({value:e});return i==null?A.TypeLiteral.nop():A.TypeLiteral.boolean(i)}case"string":{let i=this.context.getValueAsString({value:e});return i==null?A.TypeLiteral.nop():A.TypeLiteral.string(i)}default:O(t)}}convertList({list:t,value:e}){return Array.isArray(e)?A.TypeLiteral.list({values:e.map((i,a)=>{this.context.errors.scope({index:a});try{return this.convert({typeReference:t,value:i})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:_.Critical,message:`Expected array but got: ${typeof e}`}),A.TypeLiteral.nop())}convertMap({map:t,value:e}){return typeof e!="object"||e==null?(this.context.errors.add({severity:_.Critical,message:`Expected object but got: ${e==null?"null":typeof e}`}),A.TypeLiteral.nop()):A.TypeLiteral.map({entries:Object.entries(e).map(([i,a])=>{this.context.errors.scope(i);try{return{key:this.convert({typeReference:t.key,value:i,as:"key"}),value:this.convert({typeReference:t.value,value:a})}}finally{this.context.errors.unscope()}})})}convertNamed({named:t,value:e,as:i}){switch(t.type){case"alias":return this.convert({typeReference:t.typeReference,value:e,as:i});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:t,value:e});case"enum":return this.convertEnum({enum_:t,value:e});case"object":return this.convertObject({object_:t,value:e});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e});default:O(t)}}convertDiscriminatedUnion({discriminatedUnion:t,value:e}){let i=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:t,value:e});if(i==null)return A.TypeLiteral.nop();let a=i.singleDiscriminatedUnionType,d=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:i,unionVariant:a});return d==null?A.TypeLiteral.nop():A.TypeLiteral.reference(A.codeblock(f=>{f.writeNode(A.invokeMethod({on:A.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getTypesNamespace(t.declaration.fernFilepath)}),method:this.context.getMethodName(a.discriminantValue.name),arguments_:this.convertDiscriminatedUnionVariantArgs({discriminatedUnionTypeInstance:i,unionVariant:a,unionProperties:d}),static_:!0}))}))}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:t,unionVariant:e}){switch(e.type){case"samePropertiesAsObject":{let i=this.context.resolveNamedType({typeId:e.typeId});if(i==null)return;let a=this.convertNamed({named:i,value:t.value});if(!a.isClass()){this.context.errors.add({severity:_.Critical,message:"Internal error; expected union value to be an object"});return}return a.asClassOrThrow().fields}case"singleProperty":try{this.context.errors.scope(e.discriminantValue.wireValue);let i=this.context.getRecord(t.value);return i==null?[{name:this.context.getPropertyName(e.discriminantValue.name),value:this.convert({typeReference:e.typeReference,value:t.value})}]:[{name:this.context.getPropertyName(e.discriminantValue.name),value:this.convert({typeReference:e.typeReference,value:i[e.discriminantValue.wireValue]})}]}finally{this.context.errors.unscope()}case"noProperties":return[];default:O(e)}}convertDiscriminatedUnionVariantArgs({discriminatedUnionTypeInstance:t,unionVariant:e,unionProperties:i}){let a=this.getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e});if(e.type==="singleProperty"&&this.context.getRecord(t.value)==null&&i.length===1)return[...a,this.convert({typeReference:e.typeReference,value:t.value})];if(e.type==="samePropertiesAsObject"){let d=this.context.resolveNamedType({typeId:e.typeId});return d==null?[]:[...a,A.TypeLiteral.class_({reference:A.classReference({name:this.context.getClassName(d.declaration.name),namespace:this.context.getTypesNamespace(d.declaration.fernFilepath)}),fields:i})]}return a}getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:e}){return this.context.associateByWireValue({parameters:e.properties??[],values:this.context.getRecord(t.value)??{},ignoreMissingParameters:!0}).map(a=>{this.context.errors.scope(a.name.wireValue);try{return this.convert(a)}finally{this.context.errors.unscope()}})}convertObject({object_:t,value:e}){let i=this.context.associateByWireValue({parameters:t.properties,values:this.context.getRecord(e)??{}});return A.TypeLiteral.class_({reference:A.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getTypesNamespace(t.declaration.fernFilepath)}),fields:i.map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getPropertyName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:t,value:e}){let i=this.getEnumValueName({enum_:t,value:e});return i==null?A.TypeLiteral.nop():A.TypeLiteral.reference(A.codeblock(a=>{a.writeNode(A.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getTypesNamespace(t.declaration.fernFilepath)})),a.write("::"),a.write(i),a.write("->value")}))}getEnumValueName({enum_:t,value:e}){if(typeof e!="string"){this.context.errors.add({severity:_.Critical,message:`Expected enum value string, got: ${typeof e}`});return}let i=t.values.find(a=>a.wireValue===e);if(i==null){this.context.errors.add({severity:_.Critical,message:`An enum value named "${e}" does not exist in this context`});return}return this.context.getClassName(i.name)}convertUndiscriminatedUnion({undiscriminatedUnion:t,value:e}){let i=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e});return i??A.TypeLiteral.nop()}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:t,value:e}){for(let i of t.types)try{return this.convert({typeReference:i,value:e})}catch{continue}this.context.errors.add({severity:_.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof e}" value`})}convertUnknown({value:t}){return A.TypeLiteral.unknown(t)}convertPrimitive({primitive:t,value:e,as:i}){switch(t){case"INTEGER":case"LONG":case"UINT":case"UINT_64":{let a=this.getValueAsNumber({value:e,as:i});return a==null?A.TypeLiteral.nop():A.TypeLiteral.number(a)}case"FLOAT":case"DOUBLE":{let a=this.getValueAsNumber({value:e});return a==null?A.TypeLiteral.nop():A.TypeLiteral.float(a)}case"BOOLEAN":{let a=this.getValueAsBoolean({value:e,as:i});return a==null?A.TypeLiteral.nop():A.TypeLiteral.boolean(a)}case"DATE":case"DATE_TIME":{let a=this.context.getValueAsString({value:e});return a==null?A.TypeLiteral.nop():A.TypeLiteral.datetime(a)}case"BASE_64":case"UUID":case"BIG_INTEGER":case"STRING":{let a=this.context.getValueAsString({value:e});return a==null?A.TypeLiteral.nop():A.TypeLiteral.string(a)}default:O(t)}}getValueAsNumber({value:t,as:e}){let i=e==="key"&&typeof t=="string"?Number(t):t;return this.context.getValueAsNumber({value:i})}getValueAsBoolean({value:t,as:e}){let i=e==="key"?typeof t=="string"?t==="true":t==="false"?!1:t:t;return this.context.getValueAsBoolean({value:i})}};s();p();u();var Ht=class{constructor({context:t}){x(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){let i={fileFields:[],bodyPropertyFields:[]},a=this.context.getRecord(e)??{};for(let d of t.properties)switch(d.type){case"file":i.fileFields.push({name:this.context.getPropertyName(d.name),value:this.getSingleFileProperty({property:d,record:a})});break;case"fileArray":i.fileFields.push({name:this.context.getPropertyName(d.name),value:this.getArrayFileProperty({property:d,record:a})});break;case"bodyProperty":i.bodyPropertyFields.push({name:this.context.getPropertyName(d.name.name),value:this.getBodyProperty({property:d,record:a})});break;default:O(d)}return i}getSingleFileProperty({property:t,record:e}){let i=this.context.getSingleFileValue({property:t,record:e});return i==null&&(i=`example_${t.wireValue??"file"}`),A.TypeLiteral.file(i,this.context.rootNamespace)}getArrayFileProperty({property:t,record:e}){let i=this.context.getFileArrayValues({property:t,record:e});if(i==null){let a=`example_${t.wireValue??"files"}`;return A.TypeLiteral.list({values:[A.TypeLiteral.file(a,this.context.rootNamespace)]})}return A.TypeLiteral.list({values:i.map(a=>A.TypeLiteral.file(a,this.context.rootNamespace))})}getBodyProperty({property:t,record:e}){let i=e[t.name.wireValue];return i==null?A.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:i})}};var Bc=["use","clone","list"],Pc="Requests",_c="Types",Kt=class r extends ht{constructor({ir:e,config:i}){super({ir:e,config:i});x(this,"ir");x(this,"customConfig");x(this,"dynamicTypeLiteralMapper");x(this,"filePropertyMapper");x(this,"rootNamespace");this.ir=e,this.customConfig=i.customConfig!=null?i.customConfig:void 0,this.dynamicTypeLiteralMapper=new zt({context:this}),this.filePropertyMapper=new Ht({context:this}),this.rootNamespace=Fc({organization:i.organization,namespaceOverride:this.customConfig?.namespace})}clone(){return new r({ir:this.ir,config:this.config})}getParameterName(e){return this.prependUnderscoreIfNeeded(e.camelCase.unsafeName)}getPropertyName(e){return this.prependUnderscoreIfNeeded(e.camelCase.unsafeName)}getMethodName(e){let i=e.camelCase.unsafeName;return Bc.includes(i)?i:e.camelCase.safeName}getClassName(e){return xr(e.pascalCase.safeName)}getRootClientClassName(){return this.customConfig?.clientName!=null?this.customConfig.clientName:this.customConfig?.["client-class-name"]!=null?this.customConfig?.["client-class-name"]:this.getComputedClientName()}getEnvironmentsClassReference(){return A.classReference({name:"Environments",namespace:this.rootNamespace})}getRequestNamespace(e){return this.getNamespace(e,Pc)}getTypesNamespace(e){return this.getNamespace(e,_c)}getNamespace(e,i){let a=e.allParts.map(d=>d.pascalCase.safeName);return a=i!=null?[...a,i]:a,[this.rootNamespace,...a].join("\\")}getEnvironmentClassAccessFromID(e){let i=this.resolveEnvironmentName(e);if(i!=null)return A.codeblock(a=>{a.writeNode(this.getEnvironmentClassReference(i)),a.write("::"),a.write(this.getClassName(i))})}getEnvironmentClassReference(e){return A.classReference({name:"Environments",namespace:this.rootNamespace})}prependUnderscoreIfNeeded(e){return/^[a-zA-Z_]/.test(e)?e:`_${e}`}getComputedClientName(){return`${this.getOrganizationPascalCase()}Client`}getOrganizationPascalCase(){return`${Ze(Pt(this.config.organization))}`}};function Fc({organization:r,namespaceOverride:t}){return t??`${Ze(Pt(r))}`}s();p();u();var _a="$client",Yt="Example",Fa=`<?php
|
|
26
26
|
|
|
27
|
-
`,yt=class{constructor({context:t}){x(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){let i=this.buildCodeBlock({endpoint:t,snippet:e});return Fa+await i.toStringAsync({namespace:Yt,rootNamespace:Yt,customConfig:this.context.customConfig??{}})}generateSnippetSync({endpoint:t,request:e}){let i=this.buildCodeBlock({endpoint:t,snippet:e});return Fa+i.toString({namespace:Yt,rootNamespace:Yt,customConfig:this.context.customConfig??{}})}async generateSnippetAst({endpoint:t,request:e,options:i}){return i?.skipClientInstantiation?this.buildCodeBlockWithoutClient({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e})}buildCodeBlock({endpoint:t,snippet:e}){return A.codeblock(i=>{i.writeNodeStatement(this.constructClient({endpoint:t,snippet:e})),i.writeNodeStatement(this.callMethod({endpoint:t,snippet:e}))})}buildCodeBlockWithoutClient({endpoint:t,snippet:e}){return A.codeblock(i=>{i.writeNodeStatement(this.callMethodOnExistingClient({endpoint:t,snippet:e}))})}constructClient({endpoint:t,snippet:e}){return A.codeblock(i=>{i.write(`${_a} = `),i.writeNode(this.getRootClientClassInstantiation(this.getConstructorArgs({endpoint:t,snippet:e})))})}callMethod({endpoint:t,snippet:e}){return A.invokeMethod({on:A.codeblock(_a),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}),multiline:!0})}callMethodOnExistingClient({endpoint:t,snippet:e}){let i=this.getMethodArgs({endpoint:t,snippet:e}),a=this.getRequestOptions({endpoint:t,snippet:e});return A.TypeLiteral.isNop(a)||i.push(a),A.invokeMethod({on:A.codeblock("$this->client"),method:this.getMethod({endpoint:t}),arguments_:i,multiline:!0})}getRequestOptions({endpoint:t,snippet:e}){let i=e.headers??{},a=Object.entries(i);if(a.length===0)return A.TypeLiteral.nop();let d=new Set;if(this.context.ir.headers!=null)for(let v of this.context.ir.headers)d.add(v.name.wireValue.toLowerCase());if(t.request.type==="inlined"&&t.request.headers!=null)for(let v of t.request.headers)d.add(v.name.wireValue.toLowerCase());let f=a.filter(([v])=>!d.has(v.toLowerCase()));return f.length===0?A.TypeLiteral.nop():A.TypeLiteral.map({entries:[{key:A.TypeLiteral.string("headers"),value:A.TypeLiteral.map({entries:f.map(([v,T])=>({key:A.TypeLiteral.string(v),value:A.TypeLiteral.string(String(T))}))})}]})}getConstructorArgs({endpoint:t,snippet:e}){let i=[];if(t.auth!=null)if(e.auth!=null)i.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth}));else if(t.auth.type==="inferred"){let T={type:"inferred"};i.push(...this.getConstructorInferredAuthArgs({auth:t.auth,values:T}))}else this.context.errors.add({severity:_.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`});let a=this.context.ir.environments?.environments.type==="multipleBaseUrls",d=this.getConstructorEnvironmentArg({environment:e.environment,hasMultiUrlEnvironments:a}),f=[];if(!a){let T=this.getConstructorBaseUrlArgs({baseUrl:e.baseURL,environment:e.environment});T.length>0&&f.push(...T)}this.context.errors.scope(ue.Headers),this.context.ir.headers!=null&&e.headers!=null&&f.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope();let v=[...i];return d!=null&&v.push(d),f.length>0&&v.push({name:"options",assignment:A.TypeLiteral.map({entries:f.map(T=>({key:A.TypeLiteral.string(T.name),value:T.value}))})}),v}getConstructorAuthArgs({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),[];switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArgs({auth:t,values:e}):[];case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArgs({auth:t,values:e}):[];case"header":return e.type==="header"?this.getConstructorHeaderAuthArgs({auth:t,values:e}):[];case"oauth":return e.type==="oauth"?this.getConstructorOAuthArgs({auth:t,values:e}):[];case"inferred":return e.type==="inferred"?this.getConstructorInferredAuthArgs({auth:t,values:e}):[];default:O(t)}}addError(t){this.context.errors.add({severity:_.Critical,message:t})}addWarning(t){this.context.errors.add({severity:_.Warning,message:t})}getConstructorBasicAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),assignment:A.TypeLiteral.string(e.username)},{name:this.context.getPropertyName(t.password),assignment:A.TypeLiteral.string(e.password)}]}getConstructorEnvironmentArg({environment:t,hasMultiUrlEnvironments:e}){if(!e)return;let i=this.context.getEnvironmentsClassReference();if(t!=null){if(this.context.isSingleEnvironmentID(t)){let d=this.context.resolveEnvironmentName(t);if(d==null){this.addWarning(`Environment "${t}" was not found`);return}let f=this.context.getClassName(d);return{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(v=>{v.writeNode(i),v.write("::"),v.write(f),v.write("()")}))}}if(this.context.isMultiEnvironmentValues(t)){let d=this.resolveMultiEnvironmentName(t);if(d==null){this.addWarning("Invalid multi url environment");return}return d.type==="named"?{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(f=>{f.writeNode(i),f.write("::"),f.write(d.name),f.write("()")}))}:{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(f=>{f.writeNode(i),f.write("::custom(");let v=Object.entries(d.urls);v.forEach(([T,E],I)=>{f.write(`${T}: '${E}'`),I<v.length-1&&f.write(", ")}),f.write(")")}))}}}let a=this.getDefaultEnvironmentName();if(a!=null)return{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(d=>{d.writeNode(i),d.write("::"),d.write(a),d.write("()")}))}}getDefaultEnvironmentName(){if(this.context.ir.environments?.environments.type!=="multipleBaseUrls")return;let t=this.context.ir.environments.environments;if(t.type!=="multipleBaseUrls")return;let e=t.environments;if(e.length===0)return;for(let a of e){let d=this.context.getClassName(a.name);if(d==="Production")return d}let i=e[0];if(i!=null)return this.context.getClassName(i.name)}resolveMultiEnvironmentName(t){let e=Object.keys(t);if(e.length===0||!this.context.validateMultiEnvironmentUrlValues(t))return;let i=e[0];if(i==null)return;let a=t[i];if(a==null)return;let d=this.context.resolveEnvironmentName(a);if(d!=null&&e.every(T=>{let E=t[T];return E==null?!1:this.context.resolveEnvironmentName(E)!=null&&E===a}))return{type:"named",name:this.context.getClassName(d)};let f={};for(let v of e){let T=t[v];if(T==null)continue;let E=this.getBaseUrlPropertyName(v);f[E]=T}if(Object.keys(f).length>0)return{type:"custom",urls:f}}getBaseUrlPropertyName(t){if(this.context.ir.environments?.environments.type!=="multipleBaseUrls")return t;let e=this.context.ir.environments.environments;if(e.type!=="multipleBaseUrls")return t;let i=e.baseUrls.find(a=>a.id===t);return i==null?t:i.name.camelCase.safeName}getConstructorBaseUrlArgs({baseUrl:t,environment:e}){let i=this.getBaseUrlArg({baseUrl:t,environment:e});return A.TypeLiteral.isNop(i)?[]:[{name:"baseUrl",value:i}]}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null)return this.context.errors.add({severity:_.Critical,message:"Cannot specify both baseUrl and environment options"}),A.TypeLiteral.nop();if(t!=null)return A.TypeLiteral.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let i=this.context.getEnvironmentClassAccessFromID(e);return i==null?(this.context.errors.add({severity:_.Warning,message:`Environment ${JSON.stringify(e)} was not found`}),A.TypeLiteral.nop()):A.TypeLiteral.reference(A.codeblock(a=>{a.writeNode(i),a.write("->value")}))}if(this.context.ir.environments?.environments.type==="multipleBaseUrls")return A.TypeLiteral.nop()}return A.TypeLiteral.nop()}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),assignment:A.TypeLiteral.string(e.token)}]}getConstructorHeaderAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.header.name.name),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:t.header.typeReference,value:e.value})}]}getConstructorOAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.clientId),assignment:A.TypeLiteral.string(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),assignment:A.TypeLiteral.string(e.clientSecret)}]}getConstructorInferredAuthArgs({auth:t,values:e}){return[]}getConstructorHeaderArgs({headers:t,values:e}){let i=[];for(let a of t){let d=this.getConstructorHeaderArg({header:a,value:e.value});d!=null&&i.push({name:this.context.getPropertyName(a.name.name),value:d})}return i}getConstructorHeaderArg({header:t,value:e}){let i=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!A.TypeLiteral.isNop(i))return i}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:O(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let i=[];this.context.errors.scope(ue.PathParameters);let a=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];return a.length>0&&i.push(...this.getPathParameters({namedParameters:a,snippet:e}).map(d=>d.value)),this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody),t.body!=null&&i.push(this.getBodyRequestArg({body:t.body,value:e.requestBody})),this.context.errors.unscope(),i}getBodyRequestArg({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:t.value,value:e});default:O(t)}}getBytesBodyRequestArg({value:t}){return this.context.errors.add({severity:_.Critical,message:"The PHP SDK doesn't support bytes requests yet"}),A.TypeLiteral.nop()}getMethodArgsForInlinedRequest({request:t,snippet:e}){let i=[],a=this.context.customConfig?.inlinePathParameters??!1;this.context.errors.scope(ue.PathParameters);let d=[],f=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];f.length>0&&d.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody);let v=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})||i.push(...d.map(T=>T.value)),this.context.needsRequestParameter({request:t,inlinePathParameters:a,inlineFileProperties:!0})&&i.push(this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})?d:[],filePropertyInfo:v})),i}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:i,filePropertyInfo:a}){this.context.errors.scope(ue.QueryParameters);let f=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(I=>({name:this.context.getPropertyName(I.name.name),value:this.context.dynamicTypeLiteralMapper.convert(I)}));this.context.errors.unscope(),this.context.errors.scope(ue.Headers);let T=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(I=>({name:this.context.getPropertyName(I.name.name),value:this.context.dynamicTypeLiteralMapper.convert(I)}));this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody);let E=t.body!=null?this.getInlinedRequestBodyConstructorFields({body:t.body,value:e.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),A.TypeLiteral.class_({reference:A.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getRequestNamespace(t.declaration.fernFilepath)}),fields:[...i,...f,...T,...E]})}getInlinedRequestBodyConstructorFields({body:t,value:e,filePropertyInfo:i}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyConstructorFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyConstructorField({body:t,value:e})];case"fileUpload":return this.getFileUploadRequestBodyConstructorFields({filePropertyInfo:i});default:O(t)}}getFileUploadRequestBodyConstructorFields({filePropertyInfo:t}){return[...t.fileFields,...t.bodyPropertyFields]}getReferencedRequestBodyPropertyConstructorField({body:t,value:e}){return{name:this.context.getPropertyName(t.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.bodyType,value:e})}}getReferencedRequestBodyPropertyTypeLiteral({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:t.value,value:e});default:O(t)}}getInlinedRequestBodyPropertyConstructorFields({parameters:t,value:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}});for(let d of a)i.push({name:this.context.getPropertyName(d.name.name),value:this.context.dynamicTypeLiteralMapper.convert(d)});return i}getPathParameters({namedParameters:t,snippet:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:e.pathParameters??{}});for(let d of a)i.push({name:this.context.getPropertyName(d.name.name),value:this.context.dynamicTypeLiteralMapper.convert(d)});return i}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getPropertyName(e)).join("->")}->${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getRootClientClassInstantiation(t){return A.instantiateClass({classReference:A.classReference({name:this.context.getRootClientClassName(),namespace:this.context.rootNamespace}),arguments_:t,multiline:!0})}};var wr=class extends ct{constructor({ir:t,config:e}){super(new Kt({ir:t,config:e}))}async generate(t){return super.generate(t)}generateSync(t){return super.generateSync(t)}async generateSnippetAst(t,e){return await super.generateSnippetAst(t,e)}createSnippetGenerator(t){return new yt({context:t})}};export{wr as DynamicSnippetsGenerator,yt as EndpointSnippetGenerator};
|
|
27
|
+
`,yt=class{constructor({context:t}){x(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){let i=this.buildCodeBlock({endpoint:t,snippet:e});return Fa+await i.toStringAsync({namespace:Yt,rootNamespace:Yt,customConfig:this.context.customConfig??{}})}generateSnippetSync({endpoint:t,request:e}){let i=this.buildCodeBlock({endpoint:t,snippet:e});return Fa+i.toString({namespace:Yt,rootNamespace:Yt,customConfig:this.context.customConfig??{}})}async generateSnippetAst({endpoint:t,request:e,options:i}){return i?.skipClientInstantiation?this.buildCodeBlockWithoutClient({endpoint:t,snippet:e}):this.buildCodeBlock({endpoint:t,snippet:e})}buildCodeBlock({endpoint:t,snippet:e}){return A.codeblock(i=>{i.writeNodeStatement(this.constructClient({endpoint:t,snippet:e})),i.writeNodeStatement(this.callMethod({endpoint:t,snippet:e}))})}buildCodeBlockWithoutClient({endpoint:t,snippet:e}){return A.codeblock(i=>{i.writeNodeStatement(this.callMethodOnExistingClient({endpoint:t,snippet:e}))})}constructClient({endpoint:t,snippet:e}){return A.codeblock(i=>{i.write(`${_a} = `),i.writeNode(this.getRootClientClassInstantiation(this.getConstructorArgs({endpoint:t,snippet:e})))})}callMethod({endpoint:t,snippet:e}){return A.invokeMethod({on:A.codeblock(_a),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}),multiline:!0})}callMethodOnExistingClient({endpoint:t,snippet:e}){let i=this.getMethodArgs({endpoint:t,snippet:e}),a=this.getRequestOptions({endpoint:t,snippet:e});return A.TypeLiteral.isNop(a)||i.push(a),A.invokeMethod({on:A.codeblock("$this->client"),method:this.getMethod({endpoint:t}),arguments_:i,multiline:!0})}getRequestOptions({endpoint:t,snippet:e}){let i=e.headers??{},a=Object.entries(i);if(a.length===0)return A.TypeLiteral.nop();let d=new Set;if(this.context.ir.headers!=null)for(let v of this.context.ir.headers)d.add(v.name.wireValue.toLowerCase());if(t.request.type==="inlined"&&t.request.headers!=null)for(let v of t.request.headers)d.add(v.name.wireValue.toLowerCase());let f=a.filter(([v])=>!d.has(v.toLowerCase()));return f.length===0?A.TypeLiteral.nop():A.TypeLiteral.map({entries:[{key:A.TypeLiteral.string("headers"),value:A.TypeLiteral.map({entries:f.map(([v,T])=>({key:A.TypeLiteral.string(v),value:A.TypeLiteral.string(String(T))}))})}]})}getConstructorArgs({endpoint:t,snippet:e}){let i=[];if(t.auth!=null)if(e.auth!=null)i.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth}));else if(t.auth.type==="inferred"){let T={values:void 0};i.push(...this.getConstructorInferredAuthArgs({auth:t.auth,values:T}))}else this.context.errors.add({severity:_.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`});let a=this.context.ir.environments?.environments.type==="multipleBaseUrls",d=this.getConstructorEnvironmentArg({environment:e.environment,hasMultiUrlEnvironments:a}),f=[];if(!a){let T=this.getConstructorBaseUrlArgs({baseUrl:e.baseURL,environment:e.environment});T.length>0&&f.push(...T)}this.context.errors.scope(ue.Headers),this.context.ir.headers!=null&&e.headers!=null&&f.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope();let v=[...i];return d!=null&&v.push(d),f.length>0&&v.push({name:"options",assignment:A.TypeLiteral.map({entries:f.map(T=>({key:A.TypeLiteral.string(T.name),value:T.value}))})}),v}getConstructorAuthArgs({auth:t,values:e}){if(e.type!==t.type)return this.addError(this.context.newAuthMismatchError({auth:t,values:e}).message),[];switch(t.type){case"basic":return e.type==="basic"?this.getConstructorBasicAuthArgs({auth:t,values:e}):[];case"bearer":return e.type==="bearer"?this.getConstructorBearerAuthArgs({auth:t,values:e}):[];case"header":return e.type==="header"?this.getConstructorHeaderAuthArgs({auth:t,values:e}):[];case"oauth":return e.type==="oauth"?this.getConstructorOAuthArgs({auth:t,values:e}):[];case"inferred":return e.type==="inferred"?this.getConstructorInferredAuthArgs({auth:t,values:e}):[];default:O(t)}}addError(t){this.context.errors.add({severity:_.Critical,message:t})}addWarning(t){this.context.errors.add({severity:_.Warning,message:t})}getConstructorBasicAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),assignment:A.TypeLiteral.string(e.username)},{name:this.context.getPropertyName(t.password),assignment:A.TypeLiteral.string(e.password)}]}getConstructorEnvironmentArg({environment:t,hasMultiUrlEnvironments:e}){if(!e)return;let i=this.context.getEnvironmentsClassReference();if(t!=null){if(this.context.isSingleEnvironmentID(t)){let d=this.context.resolveEnvironmentName(t);if(d==null){this.addWarning(`Environment "${t}" was not found`);return}let f=this.context.getClassName(d);return{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(v=>{v.writeNode(i),v.write("::"),v.write(f),v.write("()")}))}}if(this.context.isMultiEnvironmentValues(t)){let d=this.resolveMultiEnvironmentName(t);if(d==null){this.addWarning("Invalid multi url environment");return}return d.type==="named"?{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(f=>{f.writeNode(i),f.write("::"),f.write(d.name),f.write("()")}))}:{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(f=>{f.writeNode(i),f.write("::custom(");let v=Object.entries(d.urls);v.forEach(([T,E],I)=>{f.write(`${T}: '${E}'`),I<v.length-1&&f.write(", ")}),f.write(")")}))}}}let a=this.getDefaultEnvironmentName();if(a!=null)return{name:"environment",assignment:A.TypeLiteral.reference(A.codeblock(d=>{d.writeNode(i),d.write("::"),d.write(a),d.write("()")}))}}getDefaultEnvironmentName(){if(this.context.ir.environments?.environments.type!=="multipleBaseUrls")return;let t=this.context.ir.environments.environments;if(t.type!=="multipleBaseUrls")return;let e=t.environments;if(e.length===0)return;for(let a of e){let d=this.context.getClassName(a.name);if(d==="Production")return d}let i=e[0];if(i!=null)return this.context.getClassName(i.name)}resolveMultiEnvironmentName(t){let e=Object.keys(t);if(e.length===0||!this.context.validateMultiEnvironmentUrlValues(t))return;let i=e[0];if(i==null)return;let a=t[i];if(a==null)return;let d=this.context.resolveEnvironmentName(a);if(d!=null&&e.every(T=>{let E=t[T];return E==null?!1:this.context.resolveEnvironmentName(E)!=null&&E===a}))return{type:"named",name:this.context.getClassName(d)};let f={};for(let v of e){let T=t[v];if(T==null)continue;let E=this.getBaseUrlPropertyName(v);f[E]=T}if(Object.keys(f).length>0)return{type:"custom",urls:f}}getBaseUrlPropertyName(t){if(this.context.ir.environments?.environments.type!=="multipleBaseUrls")return t;let e=this.context.ir.environments.environments;if(e.type!=="multipleBaseUrls")return t;let i=e.baseUrls.find(a=>a.id===t);return i==null?t:i.name.camelCase.safeName}getConstructorBaseUrlArgs({baseUrl:t,environment:e}){let i=this.getBaseUrlArg({baseUrl:t,environment:e});return A.TypeLiteral.isNop(i)?[]:[{name:"baseUrl",value:i}]}getBaseUrlArg({baseUrl:t,environment:e}){if(t!=null&&e!=null)return this.context.errors.add({severity:_.Critical,message:"Cannot specify both baseUrl and environment options"}),A.TypeLiteral.nop();if(t!=null)return A.TypeLiteral.string(t);if(e!=null){if(this.context.isSingleEnvironmentID(e)){let i=this.context.getEnvironmentClassAccessFromID(e);return i==null?(this.context.errors.add({severity:_.Warning,message:`Environment ${JSON.stringify(e)} was not found`}),A.TypeLiteral.nop()):A.TypeLiteral.reference(A.codeblock(a=>{a.writeNode(i),a.write("->value")}))}if(this.context.ir.environments?.environments.type==="multipleBaseUrls")return A.TypeLiteral.nop()}return A.TypeLiteral.nop()}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),assignment:A.TypeLiteral.string(e.token)}]}getConstructorHeaderAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.header.name.name),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:t.header.typeReference,value:e.value})}]}getConstructorOAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.clientId),assignment:A.TypeLiteral.string(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),assignment:A.TypeLiteral.string(e.clientSecret)}]}getConstructorInferredAuthArgs({auth:t,values:e}){return[]}getConstructorHeaderArgs({headers:t,values:e}){let i=[];for(let a of t){let d=this.getConstructorHeaderArg({header:a,value:e.value});d!=null&&i.push({name:this.context.getPropertyName(a.name.name),value:d})}return i}getConstructorHeaderArg({header:t,value:e}){let i=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!A.TypeLiteral.isNop(i))return i}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e});default:O(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){let i=[];this.context.errors.scope(ue.PathParameters);let a=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];return a.length>0&&i.push(...this.getPathParameters({namedParameters:a,snippet:e}).map(d=>d.value)),this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody),t.body!=null&&i.push(this.getBodyRequestArg({body:t.body,value:e.requestBody})),this.context.errors.unscope(),i}getBodyRequestArg({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:t.value,value:e});default:O(t)}}getBytesBodyRequestArg({value:t}){return this.context.errors.add({severity:_.Critical,message:"The PHP SDK doesn't support bytes requests yet"}),A.TypeLiteral.nop()}getMethodArgsForInlinedRequest({request:t,snippet:e}){let i=[],a=this.context.customConfig?.inlinePathParameters??!1;this.context.errors.scope(ue.PathParameters);let d=[],f=[...this.context.ir.pathParameters??[],...t.pathParameters??[]];f.length>0&&d.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody);let v=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})||i.push(...d.map(T=>T.value)),this.context.needsRequestParameter({request:t,inlinePathParameters:a,inlineFileProperties:!0})&&i.push(this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:a})?d:[],filePropertyInfo:v})),i}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:i,filePropertyInfo:a}){this.context.errors.scope(ue.QueryParameters);let f=this.context.associateQueryParametersByWireValue({parameters:t.queryParameters??[],values:e.queryParameters??{}}).map(I=>({name:this.context.getPropertyName(I.name.name),value:this.context.dynamicTypeLiteralMapper.convert(I)}));this.context.errors.unscope(),this.context.errors.scope(ue.Headers);let T=this.context.associateByWireValue({parameters:t.headers??[],values:e.headers??{}}).map(I=>({name:this.context.getPropertyName(I.name.name),value:this.context.dynamicTypeLiteralMapper.convert(I)}));this.context.errors.unscope(),this.context.errors.scope(ue.RequestBody);let E=t.body!=null?this.getInlinedRequestBodyConstructorFields({body:t.body,value:e.requestBody,filePropertyInfo:a}):[];return this.context.errors.unscope(),A.TypeLiteral.class_({reference:A.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getRequestNamespace(t.declaration.fernFilepath)}),fields:[...i,...f,...T,...E]})}getInlinedRequestBodyConstructorFields({body:t,value:e,filePropertyInfo:i}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyConstructorFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyConstructorField({body:t,value:e})];case"fileUpload":return this.getFileUploadRequestBodyConstructorFields({filePropertyInfo:i});default:O(t)}}getFileUploadRequestBodyConstructorFields({filePropertyInfo:t}){return[...t.fileFields,...t.bodyPropertyFields]}getReferencedRequestBodyPropertyConstructorField({body:t,value:e}){return{name:this.context.getPropertyName(t.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:t.bodyType,value:e})}}getReferencedRequestBodyPropertyTypeLiteral({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:t.value,value:e});default:O(t)}}getInlinedRequestBodyPropertyConstructorFields({parameters:t,value:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:this.context.getRecord(e)??{}});for(let d of a)i.push({name:this.context.getPropertyName(d.name.name),value:this.context.dynamicTypeLiteralMapper.convert(d)});return i}getPathParameters({namedParameters:t,snippet:e}){let i=[],a=this.context.associateByWireValue({parameters:t,values:e.pathParameters??{}});for(let d of a)i.push({name:this.context.getPropertyName(d.name.name),value:this.context.dynamicTypeLiteralMapper.convert(d)});return i}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getPropertyName(e)).join("->")}->${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getRootClientClassInstantiation(t){return A.instantiateClass({classReference:A.classReference({name:this.context.getRootClientClassName(),namespace:this.context.rootNamespace}),arguments_:t,multiline:!0})}};var wr=class extends ct{constructor({ir:t,config:e}){super(new Kt({ir:t,config:e}))}async generate(t){return super.generate(t)}generateSync(t){return super.generateSync(t)}async generateSnippetAst(t,e){return await super.generateSnippetAst(t,e)}createSnippetGenerator(t){return new yt({context:t})}};export{wr as DynamicSnippetsGenerator,yt as EndpointSnippetGenerator};
|
|
28
28
|
/*! Bundled license information:
|
|
29
29
|
|
|
30
30
|
@jspm/core/nodelibs/browser/chunk-DtuTasat.js:
|