@fern-api/php-dynamic-snippets 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DynamicSnippetsGenerator.cjs +9 -9
- package/cjs/DynamicSnippetsGenerator.cjs.map +1 -1
- package/cjs/DynamicSnippetsGenerator.d.cts +2 -1
- package/cjs/EndpointSnippetGenerator.cjs +1 -1
- package/cjs/EndpointSnippetGenerator.cjs.map +1 -1
- package/cjs/EndpointSnippetGenerator.d.cts +10 -3
- package/cjs/index.cjs +9 -9
- package/cjs/index.cjs.map +1 -1
- package/cjs/index.d.cts +1 -1
- package/esm/DynamicSnippetsGenerator.d.ts +2 -1
- package/esm/DynamicSnippetsGenerator.js +1 -1
- package/esm/EndpointSnippetGenerator.d.ts +10 -3
- package/esm/EndpointSnippetGenerator.js +1 -1
- package/esm/chunk-BSK7BOUP.js +2 -0
- package/esm/chunk-BSK7BOUP.js.map +1 -0
- package/esm/{chunk-XX3MRTVI.js → chunk-E5GKCY37.js} +2 -2
- package/esm/chunk-RC5VUNGI.js +2 -0
- package/esm/chunk-RC5VUNGI.js.map +1 -0
- package/esm/{chunk-EECVWAVT.js → chunk-WWRNGEPJ.js} +2 -2
- package/esm/chunk-Y6J7I7AK.js +4 -0
- package/esm/chunk-Y6J7I7AK.js.map +1 -0
- package/esm/context/DynamicSnippetsGeneratorContext.js +1 -1
- package/esm/context/DynamicTypeLiteralMapper.js +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/esm/chunk-3LG5WCZI.js +0 -2
- package/esm/chunk-3LG5WCZI.js.map +0 -1
- package/esm/chunk-6HHK4TUF.js +0 -4
- package/esm/chunk-6HHK4TUF.js.map +0 -1
- package/esm/chunk-SGTIIPPK.js +0 -2
- package/esm/chunk-SGTIIPPK.js.map +0 -1
- /package/esm/{chunk-XX3MRTVI.js.map → chunk-E5GKCY37.js.map} +0 -0
- /package/esm/{chunk-EECVWAVT.js.map → chunk-WWRNGEPJ.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractDynamicSnippetsGenerator, FernGeneratorExec } from '@fern-api/browser-compatible-base-generator';
|
|
1
|
+
import { AbstractDynamicSnippetsGenerator, FernGeneratorExec, AbstractAstNode } from '@fern-api/browser-compatible-base-generator';
|
|
2
2
|
import { FernIr } from '@fern-api/dynamic-ir-sdk';
|
|
3
3
|
import { D as DynamicSnippetsGeneratorContext } from './DynamicSnippetsGeneratorContext-CwkDTYOI.cjs';
|
|
4
4
|
import { EndpointSnippetGenerator } from './EndpointSnippetGenerator.cjs';
|
|
@@ -11,6 +11,7 @@ declare class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<
|
|
|
11
11
|
});
|
|
12
12
|
generate(request: FernIr.dynamic.EndpointSnippetRequest): Promise<FernIr.dynamic.EndpointSnippetResponse>;
|
|
13
13
|
generateSync(request: FernIr.dynamic.EndpointSnippetRequest): FernIr.dynamic.EndpointSnippetResponse;
|
|
14
|
+
generateSnippetAst(request: FernIr.dynamic.EndpointSnippetRequest): Promise<AbstractAstNode>;
|
|
14
15
|
protected createSnippetGenerator(context: DynamicSnippetsGeneratorContext): EndpointSnippetGenerator;
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -24,7 +24,7 @@ ${this.buffer}`:n+`
|
|
|
24
24
|
`):void 0;i!=null&&i.length>1&&(i.forEach(o=>{e.writeLine(` * ${o}`)}),e.writeLine(" *")),e.write(` * @${n.tagType} `),n.type.write(e,{comment:!0}),n.name!=null&&e.write(` ${n.name}`),i!=null&&i.length===1&&e.write(` ${i[0]}`),e.newLine()}};a();s();function ce(r){return Hf(r,[pe.Public,pe.PublicReadonly,pe.Protected,pe.Private])}function Hf(r,t){return t.reduce((e,n)=>[...e,...r.filter(i=>i.access===n)],[])}var X=class extends g{constructor({name:e,namespace:n,abstract:i,docs:o,parentClassReference:f,traits:p}){super();m(this,"name");m(this,"namespace");m(this,"abstract");m(this,"docs");m(this,"parentClassReference");m(this,"traits");m(this,"fields",[]);m(this,"methods",[]);m(this,"constructor_");this.name=e,this.namespace=n,this.abstract=i!=null?i:!1,this.docs=o,this.parentClassReference=f,this.traits=p!=null?p:[]}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 I({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((n,i)=>{i>0&&e.write(","),e.writeNode(n)}),e.writeTextStatement(""),e.newLine()),this.writeFields({writer:e,fields:ce(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:ce(this.methods)}),e.dedent(),e.writeLine("}")}writeComment(e){if(this.docs==null)return;new L({docs:this.docs}).write(e)}writeConstructor({writer:e,constructor:n}){var i;this.writeConstructorComment({writer:e,constructor:n}),n.access!=null&&e.write(`${n.access} `),e.write("function __construct("),e.indent(),n.parameters.forEach((o,f)=>{f===0&&e.newLine(),o.write(e),e.writeLine(",")}),e.dedent(),e.writeLine(")"),e.writeLine("{"),e.indent(),(i=n.body)==null||i.write(e),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeConstructorComment({writer:e,constructor:n}){if(n.parameters.length===0)return;let i=new L;for(let o of n.parameters)i.addTag(o.getCommentTag());i.write(e)}writeFields({writer:e,fields:n}){n.filter(i=>!i.inherited).forEach((i,o)=>{o>0&&e.newLine(),i.write(e),e.writeNewLineIfLastLineNot()})}writeMethods({writer:e,methods:n}){n.forEach((i,o)=>{o>0&&e.newLine(),i.write(e),e.writeNewLineIfLastLineNot()})}};a();s();a();s();function ke({writer:r,arguments_:t,multiline:e}){if(t.length===0){r.write("()");return}if(e){zf({writer:r,arguments_:t});return}Vf({writer:r,arguments_:t})}function zf({writer:r,arguments_:t}){r.writeLine("("),r.indent();for(let e of t)Qn({writer:r,argument:e,writeCompact:!1}),r.writeLine(",");r.dedent(),r.write(")")}function Vf({writer:r,arguments_:t}){r.write("("),t.forEach((e,n)=>{n>0&&r.write(", "),Qn({writer:r,argument:e,writeCompact:!0})}),r.write(")")}function Qn({writer:r,argument:t,writeCompact:e}){Dt(t)?(t.docs&&(e?r.write(`/* ${t.docs} */ `):r.writeLine(`/* ${t.docs} */`)),r.write(`${t.name}: `),r.writeNodeOrString(t.assignment)):t.write(r)}var q=class extends g{constructor({classReference:e,arguments_:n,multiline:i}){super();m(this,"classReference");m(this,"arguments_");m(this,"multiline");this.classReference=e,this.arguments_=n,this.multiline=i!=null?i:!1}write(e){e.write("new "),e.writeNode(this.classReference),ke({writer:e,arguments_:this.arguments_,multiline:this.multiline})}};a();s();var S=class extends g{constructor(e){super();m(this,"arg");this.arg=e}write(e){return new B(this.arg).write(e)}};a();s();a();s();var Z=class extends g{constructor({name:e,type:n,docs:i,initializer:o,access:f,readonly_:p}){super();m(this,"name");m(this,"type");m(this,"docs");m(this,"initializer");m(this,"access");m(this,"readonly_");this.name=le(e),this.type=n,this.docs=i,this.initializer=o,this.access=f,this.readonly_=p!=null?p:!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")}};a();s();a();s();a();s();a();s();var ee=class extends g{constructor({method:e,arguments_:n,static_:i,multiline:o,on:f}){super();m(this,"method");m(this,"arguments_");m(this,"multiline");m(this,"static_");m(this,"on");this.method=e,this.arguments_=n,this.static_=i!=null?i:!1,this.multiline=o!=null?o:!1,this.on=f}write(e){this.on!=null&&(this.on.write(e),e.write(this.getMethodAccessor())),e.write(this.method),ke({writer:e,arguments_:this.arguments_,multiline:this.multiline})}getMethodAccessor(){return this.static_?"::":"->"}};var F=class r extends g{constructor(e){super();m(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(Jf({writer:e,value:this.internalType.value}));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(Kf({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:_(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:n}){e.writeLine("<<<EOT"),e.writeNoIndent(n),e.newLine(),e.writeNoIndent("EOT")}writeClass({writer:e,class_:n}){e.writeNode(new q({classReference:n.reference,arguments_:[r.map({entries:n.fields.map(i=>({key:r.string(i.name),value:i.value}))})]}))}writeList({writer:e,list:n}){let i=Xf({values:n.values});if(i.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let o of i)o.write(e),e.writeLine(",");e.dedent(),e.write("]")}writeMap({writer:e,map:n}){let i=Qf({entries:n.entries});if(i.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let o of i)o.key.write(e),e.write(" => "),o.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:n}){return new this({type:"class",reference:e,fields:n})}static file(e){return new this({type:"file",value:e})}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:n}){switch(typeof n){case"boolean":e.write(n.toString());return;case"string":e.write(n.includes('"')?`\`${n}\``:`"${n}"`);return;case"number":e.write(n.toString());return;case"object":if(n==null){e.write("null");return}if(Array.isArray(n)){this.writeUnknownArray({writer:e,value:n});return}this.writeUnknownMap({writer:e,value:n});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof n}`)}}writeUnknownArray({writer:e,value:n}){if(n.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let i of n)e.writeNode(r.unknown(i)),e.writeLine(",");e.dedent(),e.write("]")}writeUnknownMap({writer:e,value:n}){let i=Object.entries(n);if(i.length===0){e.write("[]");return}e.writeLine("["),e.indent();for(let[o,f]of i)e.write(`'${o}' => `),e.writeNode(r.unknown(f)),e.writeLine(",");e.dedent(),e.write("]")}};function Kf({writer:r,value:t}){return new q({classReference:new I({name:"DateTime",namespace:""}),arguments_:[new S(`'${t}'`)]})}function Jf({writer:r,value:t}){return new ee({on:new I({name:"File",namespace:`${r.rootNamespace}\\Utils`}),method:"createFromString",arguments_:[new S(`"${t}"`)]})}function Qf({entries:r}){return r.filter(t=>!F.isNop(t.key)&&!F.isNop(t.value))}function Xf({values:r}){return r.filter(t=>!F.isNop(t))}var k=class r extends g{constructor(e){super();m(this,"internalType");this.internalType=e}write(e,{comment:n}={}){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(Xn),e.write("DateTime");break;case"dateTime":e.addReference(Xn),e.write("DateTime");break;case"mixed":e.write("mixed");break;case"object":e.write("object");break;case"array":if(!n){e.write("array");break}e.write("array<"),this.internalType.value.write(e,{comment:n}),e.write(">");break;case"map":{if(!n){e.write("array");break}e.write("array<"),this.internalType.keyType.write(e,{comment:n}),e.write(", "),this.internalType.valueType.write(e,{comment:n}),e.write(">");break}case"null":{e.write("null");break}case"typeDict":{if(!n){e.write("array");break}if(this.internalType.multiline){e.writeLine("array{");let i=this.internalType.entries.filter(p=>!p.valueType.isOptional()),o=this.internalType.entries.filter(p=>p.valueType.isOptional()),f=[...i,...o];for(let p of f)e.write(" * "),this.writeTypeDictEntry({writer:e,entry:p,comment:n}),e.writeLine(",");e.write(" * }");break}e.write("array{"),this.internalType.entries.forEach((i,o)=>{o>0&&e.write(", "),this.writeTypeDictEntry({writer:e,entry:i,comment:n})}),e.write("}");break}case"union":{this.writeUnion({writer:e,unionTypes:this.internalType.types,comment:n});break}case"optional":{let i=this.internalType.value.internalType,o=i.type==="mixed",f=i.type==="union";!f&&!o&&e.write("?"),this.internalType.value.write(e,{comment:n}),f&&!this.unionHasOptional(i.types)&&(e.write("|"),e.writeNode(r.null()));break}case"reference":if(n){e.writeNode(this.internalType.value);let i=this.internalType.value.generics;i&&i.length>0&&(e.write("<"),i.forEach((o,f)=>{f>0&&e.write(", "),o.write(e,{comment:n})}),e.write(">"))}else e.writeNode(this.internalType.value);break;case"enumString":n?(e.write("value-of<"),e.writeNode(this.internalType.value),e.write(">")):e.write("string");break;case"literal":if(n)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:_(this.internalType.value.internalType)}break;default:_(this.internalType)}}toOptionalIfNotAlready(){return this.internalType.type==="optional"?this:r.optional(this)}underlyingTypeIfOptional(){if(this.internalType.type==="optional")return this.internalType.value}underlyingType(){var e;return(e=this.underlyingTypeIfOptional())!=null?e:this}isOptional(){return this.internalType.type==="optional"}getClassReference(){switch(this.internalType.type){case"date":case"dateTime":return new I({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:_(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,n){return new this({type:"map",keyType:e,valueType:n})}static typeDict(e,{multiline:n}={}){return new this({type:"typeDict",entries:e,multiline:n})}static union(e){let n=this.flattenUnionTypes(e),i=gt(n,yt);return new this({type:"union",types:i})}static flattenUnionTypes(e){let n=[];for(let i of e)i.internalType.type==="union"?n.push(...this.flattenUnionTypes(i.internalType.types)):n.push(i);return n}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:F.string(e)})}static literalBoolean(e){return new this({type:"literal",value:F.boolean(e)})}static isAlreadyOptional(e){return e.internalType.type==="optional"}writeUnion({writer:e,unionTypes:n,comment:i}){let o=this.getUniqueTypes({types:n,comment:i,writer:e}),f=this.unwrapOptionalTypes(o),p=f.filter(c=>c.underlyingType().internalType.type==="mixed").length>0;if(p&&!i){e.write("mixed");return}if(f.length>0&&i){e.writeLine("("),f.forEach((c,d)=>{d>0?e.write(" * |"):e.write(" * "),p&&(c=c.underlyingType()),c.write(e,{comment:i}),e.writeLine(),d++}),e.write(" * )");return}f.forEach((c,d)=>{d>0&&e.write("|"),p&&(c=c.underlyingType()),c.write(e,{comment:i}),d++})}writeTypeDictEntry({writer:e,entry:n,comment:i}){e.write(n.key),n.optional&&e.write("?"),e.write(": "),n.valueType.write(e,{comment:i})}getUniqueTypes({writer:e,types:n,comment:i}){let o=gt(n,yt),f=new Set;return o.filter(p=>{let c=p.toString({namespace:e.namespace,rootNamespace:e.rootNamespace,customConfig:e.customConfig,comment:i});return f.has(c)?!1:(f.add(c),!0)})}unwrapOptionalTypes(e){let n=!1,i=e.map(o=>o.internalType.type==="optional"?(n=!0,o.internalType.value):o);return n&&i.push(r.null()),i}unionHasOptional(e){return e.filter(n=>n.internalType.type==="optional").length>0}toString({namespace:e,rootNamespace:n,customConfig:i,comment:o}){let f=new j({namespace:e,rootNamespace:n,customConfig:i});return this.write(f,{comment:o!=null?o:!1}),f.toString()}},Xn=new I({namespace:"",name:"DateTime"});a();s();function Zn(r){return r.startsWith("$")?r.slice(1):r}var ei="values",Ae=class extends g{constructor({name:e,namespace:n,abstract:i,docs:o,parentClassReference:f,traits:p,constructorAccess:c}){super();m(this,"name");m(this,"namespace");m(this,"constructorAccess");m(this,"class_");this.name=e,this.namespace=n,this.constructorAccess=c!=null?c:"public",this.class_=new X({name:e,namespace:n,abstract:i,docs:o,parentClassReference:f,traits:p})}addField(e){this.class_.addField(e)}addMethod(e){this.class_.addMethod(e)}addTrait(e){this.class_.addTrait(e)}write(e){let n=ce(this.class_.fields).map(i=>Me(Oe({},i),{name:Zn(i.name)}));n.length>0&&this.class_.addConstructor({access:this.constructorAccess,parameters:this.getConstructorParameters({orderedFields:n}),body:w.codeblock(i=>{for(let o of n)i.write(`$this->${o.name} = $${ei}['${o.name}']`),o.type.isOptional()&&i.write(" ?? null"),i.write(";")})}),this.class_.write(e)}allFieldsAreOptional(){return this.class_.fields.every(e=>e.type.isOptional())}getConstructorParameters({orderedFields:e}){return[new Z({name:ei,type:k.typeDict(e.map(n=>({key:n.name,valueType:n.type,optional:n.type.isOptional()})),{multiline:!0}),initializer:this.allFieldsAreOptional()?new S("[]"):void 0})]}};a();s();a();s();var te=class extends g{constructor({name:e,access:n,parameters:i,throws:o,return_:f,body:p,docs:c,classReference:d,static_:h}){super();m(this,"name");m(this,"access");m(this,"parameters");m(this,"throws");m(this,"return_");m(this,"body");m(this,"docs");m(this,"classReference");m(this,"static_");this.name=e,this.access=n,this.parameters=i,this.throws=o!=null?o:[],this.return_=f,this.body=p,this.docs=c,this.classReference=d,this.static_=h!=null?h:!1}write(e){var f;this.writeComment(e),e.write(`${this.access}${this.static_?" static":""} function ${this.name}(`);let n=this.parameters.filter(p=>!p.type.isOptional()),i=this.parameters.filter(p=>p.type.isOptional());[...n,...i].forEach((p,c)=>{c>0&&e.write(", "),p.write(e)}),e.write("): "),this.return_!=null?e.writeNodeOrString(this.return_):e.write("void"),e.writeLine(" {"),e.indent(),(f=this.body)==null||f.write(e),e.dedent(),e.writeLine("}")}writeComment(e){let n=new L({docs:this.docs});for(let i of this.parameters)n.addTag({tagType:"param",type:i.type,name:i.name,docs:i.docs});this.return_!=null&&this.return_!==zn&&this.return_!==Vn&&n.addTag({tagType:"return",type:this.return_});for(let i of this.throws)n.addTag({tagType:"throws",type:k.reference(i)});e.writeNode(n)}};var be=class extends g{constructor({name:e,namespace:n,backing:i,docs:o,serializable:f}){super();m(this,"name");m(this,"namespace");m(this,"backing");m(this,"docs");m(this,"members",[]);m(this,"serializable");this.name=e,this.namespace=n,this.backing=i,this.docs=o,this.serializable=f!=null?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 I({name:"JsonSerializable",namespace:""})),e.writeLine(" implements JsonSerializable")),e.writeLine(" {"),e.indent();for(let n of this.members){if(e.write(`case ${n.name}`),n.value!=null)if(typeof n.value=="string"){let i=$t(n.value);e.write(` = "${i}"`)}else e.write(` = ${n.value}`);e.writeTextStatement("")}this.serializable&&(e.newLine(),e.writeNode(new te({name:"jsonSerialize",return_:k.string(),access:"public",parameters:[],body:new S("return $this->value;")}))),e.writeNewLineIfLastLineNot(),e.dedent(),e.writeLine("}")}writeComment(e){if(this.docs==null)return;new L({docs:this.docs}).write(e)}};a();s();var Ee=class extends g{constructor({name:e,type:n,access:i,readonly_:o,initializer:f,docs:p,inlineDocs:c,attributes:d,inherited:h}){super();m(this,"name");m(this,"type");m(this,"access");m(this,"readonly_");m(this,"initializer");m(this,"docs");m(this,"inlineDocs");m(this,"attributes");m(this,"inherited");this.name=le(e),this.type=n,this.access=i,this.readonly_=o!=null?o:!1,this.initializer=f,this.docs=p,this.inlineDocs=c,this.attributes=d!=null?d:[],this.inherited=h!=null?h:!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 n=new L;n.addTag({tagType:"var",type:this.type,name:this.name,docs:this.docs}),n.write(e)}writeAttributesIfPresent(e){this.attributes.length>0&&(e.write("#["),this.attributes.forEach((n,i)=>{i>0&&e.write(", "),n.write(e)}),e.writeLine("]"))}};a();s();var Ie=class extends g{constructor({entries:e,multiline:n}){super();m(this,"entries");m(this,"multiline");this.entries=e!=null?e:[],this.multiline=n!=null?n:!1}write(e){if(this.multiline){this.writeMultiline(e);return}this.writeCompact(e)}writeMultiline(e){e.writeLine("["),e.indent();for(let{key:n,value:i}of this.entries)n.write(e),e.write(" => "),i.write(e),e.writeLine(",");e.dedent(),e.write("]")}writeCompact(e){e.write("[");for(let[n,{key:i,value:o}]of this.entries.entries())n>0&&e.write(", "),i.write(e),e.write(" => "),o.write(e);e.write("]")}};a();s();var Ce=class extends g{constructor({name:e,namespace:n,docs:i,traits:o}){super();m(this,"name");m(this,"namespace");m(this,"docs");m(this,"traits");m(this,"fields",[]);m(this,"methods",[]);this.name=e,this.namespace=n,this.docs=i,this.traits=o!=null?o:[]}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((n,i)=>{i>0&&e.write(","),e.writeNode(n)}),e.writeTextStatement(""),e.newLine()),this.writeFields({writer:e,fields:ce(this.fields)}),this.fields.length>0&&this.methods.length>0&&e.newLine(),this.writeMethods({writer:e,methods:ce(this.methods)}),e.dedent(),e.writeLine("}")}writeComment(e){let n=new L({docs:this.docs});for(let i of this.fields)n.addTag({tagType:"property",type:i.type,name:i.name});n.write(e)}writeFields({writer:e,fields:n}){n.forEach((i,o)=>{o>0&&e.newLine(),i.write(e),e.writeNewLineIfLastLineNot()})}writeMethods({writer:e,methods:n}){n.forEach((i,o)=>{o>0&&e.newLine(),i.write(e),e.writeNewLineIfLastLineNot()})}};a();s();var Tt=class extends g{constructor(e){super();m(this,"arrays");this.arrays=e}write(e){e.write("array_merge"),ke({writer:e,arguments_:this.arrays.map(n=>Se(i=>{if(typeof n=="string"||n instanceof g){i.writeNodeOrString(n);return}i.writeNodeOrString(n.ref),n.fallback&&(i.write(" ?? "),i.writeNodeOrString(n.fallback))}))})}};function Zf(r){return new ve(r)}function eu(r){return new Te(r)}function tu(r){return new X(r)}function ru(r){return new Ce(r)}function nu(r){return new I(r)}function Se(r){return new S(r)}function iu(r){return new Ae(r)}function ou(r){return new be(r)}function au(r){return new Ee(r)}function ti(r){return new q(r)}function su(r){return new ee(r)}function fu(r){return Se(t=>{t.write("throw "),t.writeNode(ti(r))})}function uu(r){return new Ie(r)}function pu(r){return new te(r)}function lu(r){return new Z(r)}function cu(r){return new We(r)}function mu(r,t){return Se(e=>{e.writeNodeOrString(r),e.write(" = "),e.writeNodeOrString(t)})}function du(r){return Se(le(r))}function hu(r){return Se(`"${r}"`)}function xu(...r){return new Tt(r)}function $t(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\$/g,"\\$")}function yu(){return new S(r=>{r.write("$this")})}var ri="$client",At="Example",ni=`<?php
|
|
26
26
|
|
|
27
|
-
`,jt=class{constructor({context:t}){m(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){var i;let n=this.buildCodeBlock({endpoint:t,snippet:e});return ni+await n.toStringAsync({namespace:At,rootNamespace:At,customConfig:(i=this.context.customConfig)!=null?i:{}})}generateSnippetSync({endpoint:t,request:e}){var i;let n=this.buildCodeBlock({endpoint:t,snippet:e});return ni+n.toString({namespace:At,rootNamespace:At,customConfig:(i=this.context.customConfig)!=null?i:{}})}buildCodeBlock({endpoint:t,snippet:e}){return w.codeblock(n=>{n.writeNodeStatement(this.constructClient({endpoint:t,snippet:e})),n.writeNodeStatement(this.callMethod({endpoint:t,snippet:e}))})}constructClient({endpoint:t,snippet:e}){return w.codeblock(n=>{n.write(`${ri} = `),n.writeNode(this.getRootClientClassInstantiation(this.getConstructorArgs({endpoint:t,snippet:e})))})}callMethod({endpoint:t,snippet:e}){return w.invokeMethod({on:w.codeblock(ri),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}),multiline:!0})}getConstructorArgs({endpoint:t,snippet:e}){var c;let n=[];t.auth!=null&&(e.auth!=null?n.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth})):this.context.errors.add({severity:ue.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`}));let i=((c=this.context.ir.environments)==null?void 0:c.environments.type)==="multipleBaseUrls",o=this.getConstructorEnvironmentArg({environment:e.environment,hasMultiUrlEnvironments:i}),f=[];if(!i){let d=this.getConstructorBaseUrlArgs({baseUrl:e.baseURL,environment:e.environment});d.length>0&&f.push(...d)}this.context.errors.scope($.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 p=[...n];return o!=null&&p.push(o),f.length>0&&p.push({name:"options",assignment:w.TypeLiteral.map({entries:f.map(d=>({key:w.TypeLiteral.string(d.name),value:d.value}))})}),p}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 this.addWarning("The PHP SDK Generator does not support Inferred auth scheme yet"),[];default:_(t)}}addError(t){this.context.errors.add({severity:ue.Critical,message:t})}addWarning(t){this.context.errors.add({severity:ue.Warning,message:t})}getConstructorBasicAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),assignment:w.TypeLiteral.string(e.username)},{name:this.context.getPropertyName(t.password),assignment:w.TypeLiteral.string(e.password)}]}getConstructorEnvironmentArg({environment:t,hasMultiUrlEnvironments:e}){if(!e)return;let n=this.context.getEnvironmentsClassReference();if(t!=null){if(this.context.isSingleEnvironmentID(t)){let o=this.context.resolveEnvironmentName(t);if(o==null){this.addWarning(`Environment "${t}" was not found`);return}let f=this.context.getClassName(o);return{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(p=>{p.writeNode(n),p.write("::"),p.write(f),p.write("()")}))}}if(this.context.isMultiEnvironmentValues(t)){let o=this.resolveMultiEnvironmentName(t);if(o==null){this.addWarning("Invalid multi url environment");return}return o.type==="named"?{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(f=>{f.writeNode(n),f.write("::"),f.write(o.name),f.write("()")}))}:{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(f=>{f.writeNode(n),f.write("::custom(");let p=Object.entries(o.urls);p.forEach(([c,d],h)=>{f.write(`${c}: '${d}'`),h<p.length-1&&f.write(", ")}),f.write(")")}))}}}let i=this.getDefaultEnvironmentName();if(i!=null)return{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(o=>{o.writeNode(n),o.write("::"),o.write(i),o.write("()")}))}}getDefaultEnvironmentName(){var i;if(((i=this.context.ir.environments)==null?void 0:i.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 o of e){let f=this.context.getClassName(o.name);if(f==="Production")return f}let n=e[0];if(n!=null)return this.context.getClassName(n.name)}resolveMultiEnvironmentName(t){let e=Object.keys(t);if(e.length===0)return;let n=e[0];if(n==null)return;let i=t[n];if(i==null)return;if(this.context.isSingleEnvironmentID(i)){let p=this.context.resolveEnvironmentName(i);if(p==null)return;if(e.every(d=>{let h=t[d];return h!=null&&this.context.isSingleEnvironmentID(h)&&h===i}))return{type:"named",name:this.context.getClassName(p)}}let o={},f=!1;for(let p of e){let c=t[p];if(c!=null&&!this.context.isSingleEnvironmentID(c)){f=!0;let d=this.getBaseUrlPropertyName(p);o[d]=c}}if(f&&Object.keys(o).length>0)return{type:"custom",urls:o}}getBaseUrlPropertyName(t){var i;if(((i=this.context.ir.environments)==null?void 0:i.environments.type)!=="multipleBaseUrls")return t;let e=this.context.ir.environments.environments;if(e.type!=="multipleBaseUrls")return t;let n=e.baseUrls.find(o=>o.id===t);return n==null?t:n.name.camelCase.safeName}getConstructorBaseUrlArgs({baseUrl:t,environment:e}){let n=this.getBaseUrlArg({baseUrl:t,environment:e});return w.TypeLiteral.isNop(n)?[]:[{name:"baseUrl",value:n}]}getBaseUrlArg({baseUrl:t,environment:e}){var n;if(t!=null&&e!=null)return this.context.errors.add({severity:ue.Critical,message:"Cannot specify both baseUrl and environment options"}),w.TypeLiteral.nop();if(t!=null)return w.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:ue.Warning,message:`Environment ${JSON.stringify(e)} was not found`}),w.TypeLiteral.nop()):w.TypeLiteral.reference(w.codeblock(o=>{o.writeNode(i),o.write("->value")}))}if(((n=this.context.ir.environments)==null?void 0:n.environments.type)==="multipleBaseUrls")return w.TypeLiteral.nop()}return w.TypeLiteral.nop()}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),assignment:w.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:w.TypeLiteral.string(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),assignment:w.TypeLiteral.string(e.clientSecret)}]}getConstructorHeaderArgs({headers:t,values:e}){let n=[];for(let i of t){let o=this.getConstructorHeaderArg({header:i,value:e.value});o!=null&&n.push({name:this.context.getPropertyName(i.name.name),value:o})}return n}getConstructorHeaderArg({header:t,value:e}){let n=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!w.TypeLiteral.isNop(n))return n}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:_(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){var o,f;let n=[];this.context.errors.scope($.PathParameters);let i=[...(o=this.context.ir.pathParameters)!=null?o:[],...(f=t.pathParameters)!=null?f:[]];return i.length>0&&n.push(...this.getPathParameters({namedParameters:i,snippet:e}).map(p=>p.value)),this.context.errors.unscope(),this.context.errors.scope($.RequestBody),t.body!=null&&n.push(this.getBodyRequestArg({body:t.body,value:e.requestBody})),this.context.errors.unscope(),n}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:_(t)}}getBytesBodyRequestArg({value:t}){return this.context.errors.add({severity:ue.Critical,message:"The PHP SDK doesn't support bytes requests yet"}),w.TypeLiteral.nop()}getMethodArgsForInlinedRequest({request:t,snippet:e}){var c,d,h,x;let n=[],i=(d=(c=this.context.customConfig)==null?void 0:c.inlinePathParameters)!=null?d:!1;this.context.errors.scope($.PathParameters);let o=[],f=[...(h=this.context.ir.pathParameters)!=null?h:[],...(x=t.pathParameters)!=null?x:[]];f.length>0&&o.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope($.RequestBody);let p=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})||n.push(...o.map(y=>y.value)),this.context.needsRequestParameter({request:t,inlinePathParameters:i,inlineFileProperties:!0})&&n.push(this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})?o:[],filePropertyInfo:p})),n}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:n,filePropertyInfo:i}){var h,x,y,v;this.context.errors.scope($.QueryParameters);let f=this.context.associateQueryParametersByWireValue({parameters:(h=t.queryParameters)!=null?h:[],values:(x=e.queryParameters)!=null?x:{}}).map(T=>({name:this.context.getPropertyName(T.name.name),value:this.context.dynamicTypeLiteralMapper.convert(T)}));this.context.errors.unscope(),this.context.errors.scope($.Headers);let c=this.context.associateByWireValue({parameters:(y=t.headers)!=null?y:[],values:(v=e.headers)!=null?v:{}}).map(T=>({name:this.context.getPropertyName(T.name.name),value:this.context.dynamicTypeLiteralMapper.convert(T)}));this.context.errors.unscope(),this.context.errors.scope($.RequestBody);let d=t.body!=null?this.getInlinedRequestBodyConstructorFields({body:t.body,value:e.requestBody,filePropertyInfo:i}):[];return this.context.errors.unscope(),w.TypeLiteral.class_({reference:w.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getRequestNamespace(t.declaration.fernFilepath)}),fields:[...n,...f,...c,...d]})}getInlinedRequestBodyConstructorFields({body:t,value:e,filePropertyInfo:n}){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:n});default:_(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:_(t)}}getInlinedRequestBodyPropertyConstructorFields({parameters:t,value:e}){var o;let n=[],i=this.context.associateByWireValue({parameters:t,values:(o=this.context.getRecord(e))!=null?o:{}});for(let f of i)n.push({name:this.context.getPropertyName(f.name.name),value:this.context.dynamicTypeLiteralMapper.convert(f)});return n}getPathParameters({namedParameters:t,snippet:e}){var o;let n=[],i=this.context.associateByWireValue({parameters:t,values:(o=e.pathParameters)!=null?o:{}});for(let f of i)n.push({name:this.context.getPropertyName(f.name.name),value:this.context.dynamicTypeLiteralMapper.convert(f)});return n}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 w.instantiateClass({classReference:w.classReference({name:this.context.getRootClientClassName(),namespace:this.context.rootNamespace}),arguments_:t,multiline:!0})}};0&&(module.exports={EndpointSnippetGenerator});
|
|
27
|
+
`,jt=class{constructor({context:t}){m(this,"context");this.context=t}async generateSnippet({endpoint:t,request:e}){var i;let n=this.buildCodeBlock({endpoint:t,snippet:e});return ni+await n.toStringAsync({namespace:At,rootNamespace:At,customConfig:(i=this.context.customConfig)!=null?i:{}})}generateSnippetSync({endpoint:t,request:e}){var i;let n=this.buildCodeBlock({endpoint:t,snippet:e});return ni+n.toString({namespace:At,rootNamespace:At,customConfig:(i=this.context.customConfig)!=null?i:{}})}async generateSnippetAst({endpoint:t,request:e}){return this.buildCodeBlock({endpoint:t,snippet:e})}buildCodeBlock({endpoint:t,snippet:e}){return w.codeblock(n=>{n.writeNodeStatement(this.constructClient({endpoint:t,snippet:e})),n.writeNodeStatement(this.callMethod({endpoint:t,snippet:e}))})}constructClient({endpoint:t,snippet:e}){return w.codeblock(n=>{n.write(`${ri} = `),n.writeNode(this.getRootClientClassInstantiation(this.getConstructorArgs({endpoint:t,snippet:e})))})}callMethod({endpoint:t,snippet:e}){return w.invokeMethod({on:w.codeblock(ri),method:this.getMethod({endpoint:t}),arguments_:this.getMethodArgs({endpoint:t,snippet:e}),multiline:!0})}getConstructorArgs({endpoint:t,snippet:e}){var c;let n=[];t.auth!=null&&(e.auth!=null?n.push(...this.getConstructorAuthArgs({auth:t.auth,values:e.auth})):this.context.errors.add({severity:ue.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`}));let i=((c=this.context.ir.environments)==null?void 0:c.environments.type)==="multipleBaseUrls",o=this.getConstructorEnvironmentArg({environment:e.environment,hasMultiUrlEnvironments:i}),f=[];if(!i){let d=this.getConstructorBaseUrlArgs({baseUrl:e.baseURL,environment:e.environment});d.length>0&&f.push(...d)}this.context.errors.scope($.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 p=[...n];return o!=null&&p.push(o),f.length>0&&p.push({name:"options",assignment:w.TypeLiteral.map({entries:f.map(d=>({key:w.TypeLiteral.string(d.name),value:d.value}))})}),p}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 this.addWarning("The PHP SDK Generator does not support Inferred auth scheme yet"),[];default:_(t)}}addError(t){this.context.errors.add({severity:ue.Critical,message:t})}addWarning(t){this.context.errors.add({severity:ue.Warning,message:t})}getConstructorBasicAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.username),assignment:w.TypeLiteral.string(e.username)},{name:this.context.getPropertyName(t.password),assignment:w.TypeLiteral.string(e.password)}]}getConstructorEnvironmentArg({environment:t,hasMultiUrlEnvironments:e}){if(!e)return;let n=this.context.getEnvironmentsClassReference();if(t!=null){if(this.context.isSingleEnvironmentID(t)){let o=this.context.resolveEnvironmentName(t);if(o==null){this.addWarning(`Environment "${t}" was not found`);return}let f=this.context.getClassName(o);return{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(p=>{p.writeNode(n),p.write("::"),p.write(f),p.write("()")}))}}if(this.context.isMultiEnvironmentValues(t)){let o=this.resolveMultiEnvironmentName(t);if(o==null){this.addWarning("Invalid multi url environment");return}return o.type==="named"?{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(f=>{f.writeNode(n),f.write("::"),f.write(o.name),f.write("()")}))}:{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(f=>{f.writeNode(n),f.write("::custom(");let p=Object.entries(o.urls);p.forEach(([c,d],h)=>{f.write(`${c}: '${d}'`),h<p.length-1&&f.write(", ")}),f.write(")")}))}}}let i=this.getDefaultEnvironmentName();if(i!=null)return{name:"environment",assignment:w.TypeLiteral.reference(w.codeblock(o=>{o.writeNode(n),o.write("::"),o.write(i),o.write("()")}))}}getDefaultEnvironmentName(){var i;if(((i=this.context.ir.environments)==null?void 0:i.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 o of e){let f=this.context.getClassName(o.name);if(f==="Production")return f}let n=e[0];if(n!=null)return this.context.getClassName(n.name)}resolveMultiEnvironmentName(t){let e=Object.keys(t);if(e.length===0)return;let n=e[0];if(n==null)return;let i=t[n];if(i==null)return;if(this.context.isSingleEnvironmentID(i)){let p=this.context.resolveEnvironmentName(i);if(p==null)return;if(e.every(d=>{let h=t[d];return h!=null&&this.context.isSingleEnvironmentID(h)&&h===i}))return{type:"named",name:this.context.getClassName(p)}}let o={},f=!1;for(let p of e){let c=t[p];if(c!=null&&!this.context.isSingleEnvironmentID(c)){f=!0;let d=this.getBaseUrlPropertyName(p);o[d]=c}}if(f&&Object.keys(o).length>0)return{type:"custom",urls:o}}getBaseUrlPropertyName(t){var i;if(((i=this.context.ir.environments)==null?void 0:i.environments.type)!=="multipleBaseUrls")return t;let e=this.context.ir.environments.environments;if(e.type!=="multipleBaseUrls")return t;let n=e.baseUrls.find(o=>o.id===t);return n==null?t:n.name.camelCase.safeName}getConstructorBaseUrlArgs({baseUrl:t,environment:e}){let n=this.getBaseUrlArg({baseUrl:t,environment:e});return w.TypeLiteral.isNop(n)?[]:[{name:"baseUrl",value:n}]}getBaseUrlArg({baseUrl:t,environment:e}){var n;if(t!=null&&e!=null)return this.context.errors.add({severity:ue.Critical,message:"Cannot specify both baseUrl and environment options"}),w.TypeLiteral.nop();if(t!=null)return w.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:ue.Warning,message:`Environment ${JSON.stringify(e)} was not found`}),w.TypeLiteral.nop()):w.TypeLiteral.reference(w.codeblock(o=>{o.writeNode(i),o.write("->value")}))}if(((n=this.context.ir.environments)==null?void 0:n.environments.type)==="multipleBaseUrls")return w.TypeLiteral.nop()}return w.TypeLiteral.nop()}getConstructorBearerAuthArgs({auth:t,values:e}){return[{name:this.context.getPropertyName(t.token),assignment:w.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:w.TypeLiteral.string(e.clientId)},{name:this.context.getPropertyName(t.clientSecret),assignment:w.TypeLiteral.string(e.clientSecret)}]}getConstructorHeaderArgs({headers:t,values:e}){let n=[];for(let i of t){let o=this.getConstructorHeaderArg({header:i,value:e.value});o!=null&&n.push({name:this.context.getPropertyName(i.name.name),value:o})}return n}getConstructorHeaderArg({header:t,value:e}){let n=this.context.dynamicTypeLiteralMapper.convert({typeReference:t.typeReference,value:e});if(!w.TypeLiteral.isNop(n))return n}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:_(t.request)}}getMethodArgsForBodyRequest({request:t,snippet:e}){var o,f;let n=[];this.context.errors.scope($.PathParameters);let i=[...(o=this.context.ir.pathParameters)!=null?o:[],...(f=t.pathParameters)!=null?f:[]];return i.length>0&&n.push(...this.getPathParameters({namedParameters:i,snippet:e}).map(p=>p.value)),this.context.errors.unscope(),this.context.errors.scope($.RequestBody),t.body!=null&&n.push(this.getBodyRequestArg({body:t.body,value:e.requestBody})),this.context.errors.unscope(),n}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:_(t)}}getBytesBodyRequestArg({value:t}){return this.context.errors.add({severity:ue.Critical,message:"The PHP SDK doesn't support bytes requests yet"}),w.TypeLiteral.nop()}getMethodArgsForInlinedRequest({request:t,snippet:e}){var c,d,h,x;let n=[],i=(d=(c=this.context.customConfig)==null?void 0:c.inlinePathParameters)!=null?d:!1;this.context.errors.scope($.PathParameters);let o=[],f=[...(h=this.context.ir.pathParameters)!=null?h:[],...(x=t.pathParameters)!=null?x:[]];f.length>0&&o.push(...this.getPathParameters({namedParameters:f,snippet:e})),this.context.errors.unscope(),this.context.errors.scope($.RequestBody);let p=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})||n.push(...o.map(y=>y.value)),this.context.needsRequestParameter({request:t,inlinePathParameters:i,inlineFileProperties:!0})&&n.push(this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t,inlinePathParameters:i})?o:[],filePropertyInfo:p})),n}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:n,filePropertyInfo:i}){var h,x,y,v;this.context.errors.scope($.QueryParameters);let f=this.context.associateQueryParametersByWireValue({parameters:(h=t.queryParameters)!=null?h:[],values:(x=e.queryParameters)!=null?x:{}}).map(T=>({name:this.context.getPropertyName(T.name.name),value:this.context.dynamicTypeLiteralMapper.convert(T)}));this.context.errors.unscope(),this.context.errors.scope($.Headers);let c=this.context.associateByWireValue({parameters:(y=t.headers)!=null?y:[],values:(v=e.headers)!=null?v:{}}).map(T=>({name:this.context.getPropertyName(T.name.name),value:this.context.dynamicTypeLiteralMapper.convert(T)}));this.context.errors.unscope(),this.context.errors.scope($.RequestBody);let d=t.body!=null?this.getInlinedRequestBodyConstructorFields({body:t.body,value:e.requestBody,filePropertyInfo:i}):[];return this.context.errors.unscope(),w.TypeLiteral.class_({reference:w.classReference({name:this.context.getClassName(t.declaration.name),namespace:this.context.getRequestNamespace(t.declaration.fernFilepath)}),fields:[...n,...f,...c,...d]})}getInlinedRequestBodyConstructorFields({body:t,value:e,filePropertyInfo:n}){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:n});default:_(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:_(t)}}getInlinedRequestBodyPropertyConstructorFields({parameters:t,value:e}){var o;let n=[],i=this.context.associateByWireValue({parameters:t,values:(o=this.context.getRecord(e))!=null?o:{}});for(let f of i)n.push({name:this.context.getPropertyName(f.name.name),value:this.context.dynamicTypeLiteralMapper.convert(f)});return n}getPathParameters({namedParameters:t,snippet:e}){var o;let n=[],i=this.context.associateByWireValue({parameters:t,values:(o=e.pathParameters)!=null?o:{}});for(let f of i)n.push({name:this.context.getPropertyName(f.name.name),value:this.context.dynamicTypeLiteralMapper.convert(f)});return n}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 w.instantiateClass({classReference:w.classReference({name:this.context.getRootClientClassName(),namespace:this.context.rootNamespace}),arguments_:t,multiline:!0})}};0&&(module.exports={EndpointSnippetGenerator});
|
|
28
28
|
/*! Bundled license information:
|
|
29
29
|
|
|
30
30
|
@esbuild-plugins/node-globals-polyfill/Buffer.js:
|