@fern-api/php-dynamic-snippets 0.0.14 → 1.25.0
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/EndpointSnippetGenerator.cjs +7 -7
- package/cjs/EndpointSnippetGenerator.cjs.map +1 -1
- package/cjs/context/DynamicSnippetsGeneratorContext.cjs +6 -6
- package/cjs/context/DynamicSnippetsGeneratorContext.cjs.map +1 -1
- package/cjs/context/DynamicTypeLiteralMapper.cjs +6 -6
- package/cjs/context/DynamicTypeLiteralMapper.cjs.map +1 -1
- package/cjs/context/FilePropertyMapper.cjs +7 -7
- package/cjs/context/FilePropertyMapper.cjs.map +1 -1
- package/cjs/index.cjs +9 -9
- package/cjs/index.cjs.map +1 -1
- package/esm/DynamicSnippetsGenerator.js +1 -1
- package/esm/EndpointSnippetGenerator.js +1 -1
- package/esm/{chunk-PYHFKEW4.js → chunk-34WVNBJS.js} +7 -7
- package/esm/chunk-34WVNBJS.js.map +1 -0
- package/esm/{chunk-RC5VUNGI.js → chunk-BN32SYGE.js} +2 -2
- package/esm/{chunk-3QAUV5WT.js → chunk-F7LTKJMT.js} +2 -2
- package/esm/{chunk-E5GKCY37.js → chunk-MZ7AWQF7.js} +2 -2
- package/esm/{chunk-VYTKQRKI.js → chunk-P7HYTUQU.js} +2 -2
- package/esm/{chunk-WWRNGEPJ.js → chunk-Q7QB5SA5.js} +2 -2
- package/esm/{chunk-EIFVUIK7.js → chunk-U6JJRNQH.js} +2 -2
- package/esm/context/DynamicSnippetsGeneratorContext.js +1 -1
- package/esm/context/DynamicTypeLiteralMapper.js +1 -1
- package/esm/context/FilePropertyMapper.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +1 -1
- package/esm/chunk-PYHFKEW4.js.map +0 -1
- /package/esm/{chunk-RC5VUNGI.js.map → chunk-BN32SYGE.js.map} +0 -0
- /package/esm/{chunk-3QAUV5WT.js.map → chunk-F7LTKJMT.js.map} +0 -0
- /package/esm/{chunk-E5GKCY37.js.map → chunk-MZ7AWQF7.js.map} +0 -0
- /package/esm/{chunk-VYTKQRKI.js.map → chunk-P7HYTUQU.js.map} +0 -0
- /package/esm/{chunk-WWRNGEPJ.js.map → chunk-Q7QB5SA5.js.map} +0 -0
- /package/esm/{chunk-EIFVUIK7.js.map → chunk-U6JJRNQH.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as T,b as P,c as S,d as A,e as p,f as l,g as u,h,k as R}from"./chunk-PYHFKEW4.js";l();u();l();u();var y=class{constructor(){p(this,"reporter");p(this,"snippet");p(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:e,snippet:r}){this.shouldUpdate({snippet:r,reporter:e.errors})&&(this.reporter=e.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:e}){var r;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(r=this.err)!=null?r:new Error(`Failed to generate snippet for endpoint "${e.method} ${e.path}"`)}shouldUpdate({snippet:e,reporter:r}){var t,n;return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:e.length>((n=(t=this.snippet)==null?void 0:t.length)!=null?n:0)}};var E=class{constructor(e){p(this,"context");this.context=e}async generate(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let a=await d.generateSnippet({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:a,errors:void 0};n.update({context:s,snippet:a})}catch(a){n.err==null&&(n.err=a)}}return n.getResponseOrThrow({endpoint:e.endpoint})}async generateSnippetAst(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{return await d.generateSnippetAst({endpoint:i,request:e,options:r})}catch(a){n=a}}throw n!=null?n:new Error(`Failed to generate snippet AST for endpoint: ${e.endpoint.method} ${e.endpoint.path}`)}generateSync(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let a=d.generateSnippetSync({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:a,errors:void 0};n.update({context:s,snippet:a})}catch(a){n.err==null&&(n.err=a)}}return n.getResponseOrThrow({endpoint:e.endpoint})}};l();u();var o={Critical:"CRITICAL",Warning:"WARNING"},g=class m{constructor(){p(this,"errors");p(this,"path");this.errors=[],this.path=[]}add(e){this.errors.push(P(T({},e),{path:[...this.path]}))}scope(e){this.path.push(e)}unscope(){this.path.pop()}getBySeverity(e){return this.errors.filter(r=>r.severity===e)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let e=new m;return e.errors=[...this.errors],e.path=[...this.path],e}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(e=>({severity:e.severity,path:e.path!=null?this.pathToStringArray(e.path):void 0,message:e.message}))}pathToStringArray(e){let r=[];for(let t of e){if(typeof t=="string"){r.push(t);continue}r[r.length-1]+=`[${t.index}]`}return r}};l();u();l();u();l();u();var v=class{constructor(){p(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH|HEAD)\s(\/\S*)$/)}validate(e){return this.REFERENCE_REGEX.test(e)?{type:"valid"}:{type:"invalid"}}tryParse(e){if(this.validate(e).type==="invalid")return;let t=e.match(this.REFERENCE_REGEX);if(!(t==null||t[1]==null||t[2]==null))return{method:t[1],path:t[2]}}};var w=class{constructor({ir:e,config:r,options:t={}}){p(this,"config");p(this,"options");p(this,"errors");p(this,"_ir");p(this,"httpEndpointReferenceParser");this._ir=e,this.config=r,this.options=t,this.errors=new g,this.httpEndpointReferenceParser=new v}associateQueryParametersByWireValue({parameters:e,values:r}){let t=[];for(let[n,i]of Object.entries(r)){this.errors.scope(n);try{let s=e.find(a=>a.name.wireValue===n);if(s==null)throw this.newParameterNotRecognizedError(n);let d=this.isListTypeReference(s.typeReference)&&!Array.isArray(i)?[i]:i;t.push({name:s.name,typeReference:s.typeReference,value:d})}finally{this.errors.unscope()}}return t}associateByWireValueOrDefault({parameters:e,values:r}){let t=[];for(let n of e){this.errors.scope(n.name.wireValue);try{let i=r[n.name.wireValue];if(i==null)if(n.typeReference.type==="primitive"&&n.typeReference.value==="STRING")i=`<${n.name.wireValue}>`;else{this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(n.name.wireValue).message});continue}t.push({name:n.name,typeReference:n.typeReference,value:i})}finally{this.errors.unscope()}}return t}associateByWireValue({parameters:e,values:r,ignoreMissingParameters:t}){let n=[];for(let[i,s]of Object.entries(r)){this.errors.scope(i);try{let d=e.find(a=>a.name.wireValue===i);if(d==null){if(t)continue;this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(i).message});continue}n.push({name:d.name,typeReference:d.typeReference,value:s})}finally{this.errors.unscope()}}return n}getExampleObjectProperties({parameters:e,snippetObject:r}){let t=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{},n=[];for(let i of e){let s=t[i.name.wireValue];s==null?i.typeReference.type==="nullable"&&n.push({name:i.name,typeReference:i.typeReference,value:null}):n.push({name:i.name,typeReference:i.typeReference,value:s})}return n}getSingleFileValue({property:e,record:r}){let t=r[e.wireValue];if(t!=null){if(typeof t!="string"){this.errors.add({severity:o.Critical,message:`Expected file value to be a string, got ${typeof t}`});return}return t}}getFileArrayValues({property:e,record:r}){let t=r[e.wireValue];if(t==null)return;if(!Array.isArray(t)){this.errors.add({severity:o.Critical,message:`Expected file array value to be an array of strings, got ${typeof t}`});return}let n=[];for(let i of t){if(typeof i!="string"){this.errors.add({severity:o.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}n.push(i)}return n}getRecord(e){if(typeof e!="object"||Array.isArray(e)){this.errors.add({severity:o.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(e)?"array":typeof e}`});return}return e==null?{}:e}resolveNamedType({typeId:e}){let r=this._ir.types[e];if(r==null){this.errors.add({severity:o.Critical,message:`Type identified by "${e}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:r}){let t=this.getRecord(r);if(t==null)return;let n=e.discriminant.wireValue,i=t[n];if(i==null){this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(n).message});return}if(typeof i!="string"){this.errors.add({severity:o.Critical,message:`Expected discriminant value to be a string but got: ${typeof i}`});return}let s=e.types[i];if(s==null){this.errors.add({severity:o.Critical,message:`No type found for discriminant value "${i}"`});return}let x=t,{[n]:d}=x,a=A(x,[S(n)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:a}}resolveEndpointOrThrow(e){let r=this.httpEndpointReferenceParser.tryParse(e);if(r==null)throw new Error(`Failed to parse endpoint reference "${e}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocation(e){let r=[];for(let t of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:t,parsedEndpoint:e})&&r.push(t);return r}resolveEndpointLocationOrThrow(e){let r=this.resolveEndpointLocation(e);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${e.method} ${e.path}"`);return r}needsRequestParameter({request:e,inlinePathParameters:r,inlineFileProperties:t}){var n;return this.includePathParametersInWrappedRequest({request:e,inlinePathParameters:r})||e.queryParameters!=null&&e.queryParameters.length>0||e.headers!=null&&e.headers.length>0?!0:e.body!=null?this.includeRequestBodyInWrappedRequest({body:e.body,inlineFileProperties:t}):!((n=e.metadata)!=null&&n.onlyPathParameters)}includePathParametersInWrappedRequest({request:e,inlinePathParameters:r}){var t,n;return r&&((n=(t=e.metadata)==null?void 0:t.includePathParameters)!=null?n:!1)}isFileUploadRequestBody(e){switch(e.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:h(e)}}resolveEnvironmentName(e){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}case"multipleBaseUrls":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}default:h(r)}}isSingleEnvironmentID(e){return typeof e=="string"}isMultiEnvironmentValues(e){return typeof e=="object"}validateMultiEnvironmentUrlValues(e){if(this._ir.environments==null)return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let t=r.environments[0];if(t==null)return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let n=new Set(R(t.urls));for(let i of R(e))n.has(i)&&n.delete(i);return n.size>0?(this.errors.add({severity:o.Critical,message:`The provided environments are invalid; got: [${Object.keys(e).join(", ")}], expected: [${R(t.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:e}){if(typeof e!="number"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"number",value:e}).message});return}return e}getValueAsBoolean({value:e}){if(typeof e!="boolean"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"boolean",value:e}).message});return}return e}getValueAsString({value:e}){if(typeof e!="string"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"string",value:e}).message});return}return e}isOptional(e){switch(e.type){case"nullable":return this.isOptional(e.value);case"optional":return!0;case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(e){switch(e.type){case"nullable":return!0;case"optional":return this.isNullable(e.value);case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:e,values:r}){return new Error(`Expected auth type ${e.type}, got ${r.type}`)}newParameterNotRecognizedError(e){return new Error(`"${e}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:e,value:r}){return new Error(`Expected ${e}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:e,inlineFileProperties:r}){switch(e.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r});default:h(e)}}includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:e})||r&&this.fileUploadHasFileProperties({fileUpload:e})}fileUploadHasBodyProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:h(r)}})}fileUploadHasFileProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:h(r)}})}isListTypeReference(e){return e.type==="optional"?this.isListTypeReference(e.value):e.type==="list"||e.type==="set"}parsedEndpointMatches({endpoint:e,parsedEndpoint:r}){return e.location.method===r.method&&e.location.path===r.path}};l();u();var b={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};l();u();export{E as a,o as b,w as c,b as d};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as T,b as P,c as S,d as A,e as p,f as l,g as u,h,k as R}from"./chunk-34WVNBJS.js";l();u();l();u();var y=class{constructor(){p(this,"reporter");p(this,"snippet");p(this,"err");this.snippet=void 0,this.reporter=void 0,this.err=void 0}update({context:e,snippet:r}){this.shouldUpdate({snippet:r,reporter:e.errors})&&(this.reporter=e.errors.clone(),this.snippet=r)}getResponseOrThrow({endpoint:e}){var r;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(r=this.err)!=null?r:new Error(`Failed to generate snippet for endpoint "${e.method} ${e.path}"`)}shouldUpdate({snippet:e,reporter:r}){var t,n;return this.reporter==null||this.reporter.size()>0&&r.size()===0?!0:e.length>((n=(t=this.snippet)==null?void 0:t.length)!=null?n:0)}};var E=class{constructor(e){p(this,"context");this.context=e}async generate(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let a=await d.generateSnippet({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:a,errors:void 0};n.update({context:s,snippet:a})}catch(a){n.err==null&&(n.err=a)}}return n.getResponseOrThrow({endpoint:e.endpoint})}async generateSnippetAst(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{return await d.generateSnippetAst({endpoint:i,request:e,options:r})}catch(a){n=a}}throw n!=null?n:new Error(`Failed to generate snippet AST for endpoint: ${e.endpoint.method} ${e.endpoint.path}`)}generateSync(e,r={}){let t=this.context.resolveEndpointLocationOrThrow(e.endpoint);if(t.length===0)throw new Error(`No endpoints found that match "${e.endpoint.method} ${e.endpoint.path}"`);let n=new y;for(let i of t){let s=this.context.clone(),d=this.createSnippetGenerator(s);try{let a=d.generateSnippetSync({endpoint:i,request:e,options:r});if(s.errors.empty())return{snippet:a,errors:void 0};n.update({context:s,snippet:a})}catch(a){n.err==null&&(n.err=a)}}return n.getResponseOrThrow({endpoint:e.endpoint})}};l();u();var o={Critical:"CRITICAL",Warning:"WARNING"},g=class m{constructor(){p(this,"errors");p(this,"path");this.errors=[],this.path=[]}add(e){this.errors.push(P(T({},e),{path:[...this.path]}))}scope(e){this.path.push(e)}unscope(){this.path.pop()}getBySeverity(e){return this.errors.filter(r=>r.severity===e)}empty(){return this.errors.length===0}size(){return this.errors.length}clone(){let e=new m;return e.errors=[...this.errors],e.path=[...this.path],e}reset(){this.errors=[],this.path=[]}toDynamicSnippetErrors(){return this.errors.map(e=>({severity:e.severity,path:e.path!=null?this.pathToStringArray(e.path):void 0,message:e.message}))}pathToStringArray(e){let r=[];for(let t of e){if(typeof t=="string"){r.push(t);continue}r[r.length-1]+=`[${t.index}]`}return r}};l();u();l();u();l();u();var v=class{constructor(){p(this,"REFERENCE_REGEX",/^(GET|POST|PUT|DELETE|PATCH|HEAD)\s(\/\S*)$/)}validate(e){return this.REFERENCE_REGEX.test(e)?{type:"valid"}:{type:"invalid"}}tryParse(e){if(this.validate(e).type==="invalid")return;let t=e.match(this.REFERENCE_REGEX);if(!(t==null||t[1]==null||t[2]==null))return{method:t[1],path:t[2]}}};var w=class{constructor({ir:e,config:r,options:t={}}){p(this,"config");p(this,"options");p(this,"errors");p(this,"_ir");p(this,"httpEndpointReferenceParser");this._ir=e,this.config=r,this.options=t,this.errors=new g,this.httpEndpointReferenceParser=new v}associateQueryParametersByWireValue({parameters:e,values:r}){let t=[];for(let[n,i]of Object.entries(r)){this.errors.scope(n);try{let s=e.find(a=>a.name.wireValue===n);if(s==null)throw this.newParameterNotRecognizedError(n);let d=this.isListTypeReference(s.typeReference)&&!Array.isArray(i)?[i]:i;t.push({name:s.name,typeReference:s.typeReference,value:d})}finally{this.errors.unscope()}}return t}associateByWireValueOrDefault({parameters:e,values:r}){let t=[];for(let n of e){this.errors.scope(n.name.wireValue);try{let i=r[n.name.wireValue];if(i==null)if(n.typeReference.type==="primitive"&&n.typeReference.value==="STRING")i=`<${n.name.wireValue}>`;else{this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(n.name.wireValue).message});continue}t.push({name:n.name,typeReference:n.typeReference,value:i})}finally{this.errors.unscope()}}return t}associateByWireValue({parameters:e,values:r,ignoreMissingParameters:t}){let n=[];for(let[i,s]of Object.entries(r)){this.errors.scope(i);try{let d=e.find(a=>a.name.wireValue===i);if(d==null){if(t)continue;this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(i).message});continue}n.push({name:d.name,typeReference:d.typeReference,value:s})}finally{this.errors.unscope()}}return n}getExampleObjectProperties({parameters:e,snippetObject:r}){let t=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{},n=[];for(let i of e){let s=t[i.name.wireValue];s==null?i.typeReference.type==="nullable"&&n.push({name:i.name,typeReference:i.typeReference,value:null}):n.push({name:i.name,typeReference:i.typeReference,value:s})}return n}getSingleFileValue({property:e,record:r}){let t=r[e.wireValue];if(t!=null){if(typeof t!="string"){this.errors.add({severity:o.Critical,message:`Expected file value to be a string, got ${typeof t}`});return}return t}}getFileArrayValues({property:e,record:r}){let t=r[e.wireValue];if(t==null)return;if(!Array.isArray(t)){this.errors.add({severity:o.Critical,message:`Expected file array value to be an array of strings, got ${typeof t}`});return}let n=[];for(let i of t){if(typeof i!="string"){this.errors.add({severity:o.Critical,message:`Expected file array value to be an array of strings, got ${typeof i}`});return}n.push(i)}return n}getRecord(e){if(typeof e!="object"||Array.isArray(e)){this.errors.add({severity:o.Critical,message:`Expected object with key, value pairs but got: ${Array.isArray(e)?"array":typeof e}`});return}return e==null?{}:e}resolveNamedType({typeId:e}){let r=this._ir.types[e];if(r==null){this.errors.add({severity:o.Critical,message:`Type identified by "${e}" could not be found`});return}return r}resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:r}){let t=this.getRecord(r);if(t==null)return;let n=e.discriminant.wireValue,i=t[n];if(i==null){this.errors.add({severity:o.Critical,message:this.newParameterNotRecognizedError(n).message});return}if(typeof i!="string"){this.errors.add({severity:o.Critical,message:`Expected discriminant value to be a string but got: ${typeof i}`});return}let s=e.types[i];if(s==null){this.errors.add({severity:o.Critical,message:`No type found for discriminant value "${i}"`});return}let x=t,{[n]:d}=x,a=A(x,[S(n)]);return{singleDiscriminatedUnionType:s,discriminantValue:s.discriminantValue,value:a}}resolveEndpointOrThrow(e){let r=this.httpEndpointReferenceParser.tryParse(e);if(r==null)throw new Error(`Failed to parse endpoint reference "${e}"`);return this.resolveEndpointLocationOrThrow(r)}resolveEndpointLocation(e){let r=[];for(let t of Object.values(this._ir.endpoints))this.parsedEndpointMatches({endpoint:t,parsedEndpoint:e})&&r.push(t);return r}resolveEndpointLocationOrThrow(e){let r=this.resolveEndpointLocation(e);if(r.length===0)throw new Error(`Failed to find endpoint identified by "${e.method} ${e.path}"`);return r}needsRequestParameter({request:e,inlinePathParameters:r,inlineFileProperties:t}){var n;return this.includePathParametersInWrappedRequest({request:e,inlinePathParameters:r})||e.queryParameters!=null&&e.queryParameters.length>0||e.headers!=null&&e.headers.length>0?!0:e.body!=null?this.includeRequestBodyInWrappedRequest({body:e.body,inlineFileProperties:t}):!((n=e.metadata)!=null&&n.onlyPathParameters)}includePathParametersInWrappedRequest({request:e,inlinePathParameters:r}){var t,n;return r&&((n=(t=e.metadata)==null?void 0:t.includePathParameters)!=null?n:!1)}isFileUploadRequestBody(e){switch(e.type){case"fileUpload":return!0;case"properties":case"referenced":return!1;default:h(e)}}resolveEnvironmentName(e){if(this._ir.environments==null)return;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}case"multipleBaseUrls":{let t=r.environments.find(n=>n.id===e);return t==null?void 0:t.name}default:h(r)}}isSingleEnvironmentID(e){return typeof e=="string"}isMultiEnvironmentValues(e){return typeof e=="object"}validateMultiEnvironmentUrlValues(e){if(this._ir.environments==null)return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;let r=this._ir.environments.environments;switch(r.type){case"singleBaseUrl":return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported for single base URL environments; use the baseUrl option instead"}),!1;case"multipleBaseUrls":{let t=r.environments[0];if(t==null)return this.errors.add({severity:o.Critical,message:"Multiple environments are not supported; use the baseUrl option instead"}),!1;let n=new Set(R(t.urls));for(let i of R(e))n.has(i)&&n.delete(i);return n.size>0?(this.errors.add({severity:o.Critical,message:`The provided environments are invalid; got: [${Object.keys(e).join(", ")}], expected: [${R(t.urls).join(", ")}]`}),!1):!0}}}getValueAsNumber({value:e}){if(typeof e!="number"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"number",value:e}).message});return}return e}getValueAsBoolean({value:e}){if(typeof e!="boolean"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"boolean",value:e}).message});return}return e}getValueAsString({value:e}){if(typeof e!="string"){this.errors.add({severity:o.Critical,message:this.newTypeMismatchError({expected:"string",value:e}).message});return}return e}isOptional(e){switch(e.type){case"nullable":return this.isOptional(e.value);case"optional":return!0;case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}isNullable(e){switch(e.type){case"nullable":return!0;case"optional":return this.isNullable(e.value);case"named":{let r=this.resolveNamedType({typeId:e.value});return r==null?!1:r.type==="alias"?this.isNullable(r.typeReference):!1}}return!1}newAuthMismatchError({auth:e,values:r}){return new Error(`Expected auth type ${e.type}, got ${r.type}`)}newParameterNotRecognizedError(e){return new Error(`"${e}" is not a recognized parameter for this endpoint`)}newTypeMismatchError({expected:e,value:r}){return new Error(`Expected ${e}, got ${typeof r}`)}includeRequestBodyInWrappedRequest({body:e,inlineFileProperties:r}){switch(e.type){case"properties":case"referenced":return!0;case"fileUpload":return this.includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r});default:h(e)}}includeFileUploadBodyInWrappedRequest({fileUpload:e,inlineFileProperties:r}){return this.fileUploadHasBodyProperties({fileUpload:e})||r&&this.fileUploadHasFileProperties({fileUpload:e})}fileUploadHasBodyProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!1;case"bodyProperty":return!0;default:h(r)}})}fileUploadHasFileProperties({fileUpload:e}){return e.properties.some(r=>{switch(r.type){case"file":case"fileArray":return!0;case"bodyProperty":return!1;default:h(r)}})}isListTypeReference(e){return e.type==="optional"?this.isListTypeReference(e.value):e.type==="list"||e.type==="set"}parsedEndpointMatches({endpoint:e,parsedEndpoint:r}){return e.location.method===r.method&&e.location.path===r.path}};l();u();var b={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};l();u();export{E as a,o as b,w as c,b as d};
|
|
2
|
+
//# sourceMappingURL=chunk-BN32SYGE.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e as l,f as a,g as y,h as s,l as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{e as l,f as a,g as y,h as s,l as i}from"./chunk-34WVNBJS.js";a();y();var c=class{constructor({context:r}){l(this,"context");this.context=r}getFilePropertyInfo({body:r,value:o}){var p;let e={fileFields:[],bodyPropertyFields:[]},n=(p=this.context.getRecord(o))!=null?p:{};for(let t of r.properties)switch(t.type){case"file":e.fileFields.push({name:this.context.getPropertyName(t.name),value:this.getSingleFileProperty({property:t,record:n})});break;case"fileArray":e.fileFields.push({name:this.context.getPropertyName(t.name),value:this.getArrayFileProperty({property:t,record:n})});break;case"bodyProperty":e.bodyPropertyFields.push({name:this.context.getPropertyName(t.name.name),value:this.getBodyProperty({property:t,record:n})});break;default:s(t)}return e}getSingleFileProperty({property:r,record:o}){let e=this.context.getSingleFileValue({property:r,record:o});return e==null?i.TypeLiteral.nop():i.TypeLiteral.file(e)}getArrayFileProperty({property:r,record:o}){let e=this.context.getFileArrayValues({property:r,record:o});return e==null?i.TypeLiteral.nop():i.TypeLiteral.list({values:e.map(n=>i.TypeLiteral.file(n))})}getBodyProperty({property:r,record:o}){let e=o[r.name.wireValue];return e==null?i.TypeLiteral.nop():this.context.dynamicTypeLiteralMapper.convert({typeReference:r.typeReference,value:e})}};export{c as a};
|
|
2
|
+
//# sourceMappingURL=chunk-F7LTKJMT.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as g}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as g}from"./chunk-Q7QB5SA5.js";import{c as l}from"./chunk-BN32SYGE.js";import{a as f}from"./chunk-F7LTKJMT.js";import{e as r,f as m,g as p,i as o,j as c,l as s,m as u}from"./chunk-34WVNBJS.js";m();p();var h=["use","clone","list"],d="Requests",y="Types",C=class i extends l{constructor({ir:e,config:t}){var n;super({ir:e,config:t});r(this,"ir");r(this,"customConfig");r(this,"dynamicTypeLiteralMapper");r(this,"filePropertyMapper");r(this,"rootNamespace");this.ir=e,this.customConfig=t.customConfig!=null?t.customConfig:void 0,this.dynamicTypeLiteralMapper=new g({context:this}),this.filePropertyMapper=new f({context:this}),this.rootNamespace=F({organization:t.organization,namespaceOverride:(n=this.customConfig)==null?void 0:n.namespace})}clone(){return new i({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 t=e.camelCase.unsafeName;return h.includes(t)?t:e.camelCase.safeName}getClassName(e){return u(e.pascalCase.safeName)}getRootClientClassName(){var e,t,n;return((e=this.customConfig)==null?void 0:e.clientName)!=null?this.customConfig.clientName:((t=this.customConfig)==null?void 0:t["client-class-name"])!=null?(n=this.customConfig)==null?void 0:n["client-class-name"]:this.getComputedClientName()}getEnvironmentsClassReference(){return s.classReference({name:"Environments",namespace:this.rootNamespace})}getRequestNamespace(e){return this.getNamespace(e,d)}getTypesNamespace(e){return this.getNamespace(e,y)}getNamespace(e,t){let n=e.allParts.map(N=>N.pascalCase.safeName);return n=t!=null?[...n,t]:n,[this.rootNamespace,...n].join("\\")}getEnvironmentClassAccessFromID(e){let t=this.resolveEnvironmentName(e);if(t!=null)return s.codeblock(n=>{n.writeNode(this.getEnvironmentClassReference(t)),n.write("::"),n.write(this.getClassName(t))})}getEnvironmentClassReference(e){return s.classReference({name:"Environments",namespace:this.rootNamespace})}prependUnderscoreIfNeeded(e){return/^[a-zA-Z_]/.test(e)?e:`_${e}`}getComputedClientName(){return`${this.getOrganizationPascalCase()}Client`}getOrganizationPascalCase(){return`${o(c(this.config.organization))}`}};function F({organization:i,namespaceOverride:a}){return a!=null?a:`${o(c(i))}`}export{C as a};
|
|
2
|
+
//# sourceMappingURL=chunk-MZ7AWQF7.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as l,d as p}from"./chunk-
|
|
1
|
+
import{b as l,d as p}from"./chunk-BN32SYGE.js";import{e as F,f as I,g as x,h as m,l as i}from"./chunk-34WVNBJS.js";I();x();var A="$client",f="Example",C=`<?php
|
|
2
2
|
|
|
3
3
|
`,P=class{constructor({context:e}){F(this,"context");this.context=e}async generateSnippet({endpoint:e,request:t}){var n;let r=this.buildCodeBlock({endpoint:e,snippet:t});return C+await r.toStringAsync({namespace:f,rootNamespace:f,customConfig:(n=this.context.customConfig)!=null?n:{}})}generateSnippetSync({endpoint:e,request:t}){var n;let r=this.buildCodeBlock({endpoint:e,snippet:t});return C+r.toString({namespace:f,rootNamespace:f,customConfig:(n=this.context.customConfig)!=null?n:{}})}async generateSnippetAst({endpoint:e,request:t,options:r}){return r!=null&&r.skipClientInstantiation?this.buildCodeBlockWithoutClient({endpoint:e,snippet:t}):this.buildCodeBlock({endpoint:e,snippet:t})}buildCodeBlock({endpoint:e,snippet:t}){return i.codeblock(r=>{r.writeNodeStatement(this.constructClient({endpoint:e,snippet:t})),r.writeNodeStatement(this.callMethod({endpoint:e,snippet:t}))})}buildCodeBlockWithoutClient({endpoint:e,snippet:t}){return i.codeblock(r=>{r.writeNodeStatement(this.callMethodOnExistingClient({endpoint:e,snippet:t}))})}constructClient({endpoint:e,snippet:t}){return i.codeblock(r=>{r.write(`${A} = `),r.writeNode(this.getRootClientClassInstantiation(this.getConstructorArgs({endpoint:e,snippet:t})))})}callMethod({endpoint:e,snippet:t}){return i.invokeMethod({on:i.codeblock(A),method:this.getMethod({endpoint:e}),arguments_:this.getMethodArgs({endpoint:e,snippet:t}),multiline:!0})}callMethodOnExistingClient({endpoint:e,snippet:t}){let r=this.getMethodArgs({endpoint:e,snippet:t}),n=this.getRequestOptions({endpoint:e,snippet:t});return i.TypeLiteral.isNop(n)||r.push(n),i.invokeMethod({on:i.codeblock("$this->client"),method:this.getMethod({endpoint:e}),arguments_:r,multiline:!0})}getRequestOptions({endpoint:e,snippet:t}){var o;let r=(o=t.headers)!=null?o:{},n=Object.entries(r);if(n.length===0)return i.TypeLiteral.nop();let s=new Set;if(this.context.ir.headers!=null)for(let c of this.context.ir.headers)s.add(c.name.wireValue.toLowerCase());if(e.request.type==="inlined"&&e.request.headers!=null)for(let c of e.request.headers)s.add(c.name.wireValue.toLowerCase());let a=n.filter(([c])=>!s.has(c.toLowerCase()));return a.length===0?i.TypeLiteral.nop():i.TypeLiteral.map({entries:[{key:i.TypeLiteral.string("headers"),value:i.TypeLiteral.map({entries:a.map(([c,u])=>({key:i.TypeLiteral.string(c),value:i.TypeLiteral.string(String(u))}))})}]})}getConstructorArgs({endpoint:e,snippet:t}){var c;let r=[];if(e.auth!=null)if(t.auth!=null)r.push(...this.getConstructorAuthArgs({auth:e.auth,values:t.auth}));else if(e.auth.type==="inferred"){let u={type:"inferred"};r.push(...this.getConstructorInferredAuthArgs({auth:e.auth,values:u}))}else this.context.errors.add({severity:l.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`});let n=((c=this.context.ir.environments)==null?void 0:c.environments.type)==="multipleBaseUrls",s=this.getConstructorEnvironmentArg({environment:t.environment,hasMultiUrlEnvironments:n}),a=[];if(!n){let u=this.getConstructorBaseUrlArgs({baseUrl:t.baseURL,environment:t.environment});u.length>0&&a.push(...u)}this.context.errors.scope(p.Headers),this.context.ir.headers!=null&&t.headers!=null&&a.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope();let o=[...r];return s!=null&&o.push(s),a.length>0&&o.push({name:"options",assignment:i.TypeLiteral.map({entries:a.map(u=>({key:i.TypeLiteral.string(u.name),value:u.value}))})}),o}getConstructorAuthArgs({auth:e,values:t}){if(t.type!==e.type)return this.addError(this.context.newAuthMismatchError({auth:e,values:t}).message),[];switch(e.type){case"basic":return t.type==="basic"?this.getConstructorBasicAuthArgs({auth:e,values:t}):[];case"bearer":return t.type==="bearer"?this.getConstructorBearerAuthArgs({auth:e,values:t}):[];case"header":return t.type==="header"?this.getConstructorHeaderAuthArgs({auth:e,values:t}):[];case"oauth":return t.type==="oauth"?this.getConstructorOAuthArgs({auth:e,values:t}):[];case"inferred":return t.type==="inferred"?this.getConstructorInferredAuthArgs({auth:e,values:t}):[];default:m(e)}}addError(e){this.context.errors.add({severity:l.Critical,message:e})}addWarning(e){this.context.errors.add({severity:l.Warning,message:e})}getConstructorBasicAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.username),assignment:i.TypeLiteral.string(t.username)},{name:this.context.getPropertyName(e.password),assignment:i.TypeLiteral.string(t.password)}]}getConstructorEnvironmentArg({environment:e,hasMultiUrlEnvironments:t}){if(!t)return;let r=this.context.getEnvironmentsClassReference();if(e!=null){if(this.context.isSingleEnvironmentID(e)){let s=this.context.resolveEnvironmentName(e);if(s==null){this.addWarning(`Environment "${e}" was not found`);return}let a=this.context.getClassName(s);return{name:"environment",assignment:i.TypeLiteral.reference(i.codeblock(o=>{o.writeNode(r),o.write("::"),o.write(a),o.write("()")}))}}if(this.context.isMultiEnvironmentValues(e)){let s=this.resolveMultiEnvironmentName(e);if(s==null){this.addWarning("Invalid multi url environment");return}return s.type==="named"?{name:"environment",assignment:i.TypeLiteral.reference(i.codeblock(a=>{a.writeNode(r),a.write("::"),a.write(s.name),a.write("()")}))}:{name:"environment",assignment:i.TypeLiteral.reference(i.codeblock(a=>{a.writeNode(r),a.write("::custom(");let o=Object.entries(s.urls);o.forEach(([c,u],d)=>{a.write(`${c}: '${u}'`),d<o.length-1&&a.write(", ")}),a.write(")")}))}}}let n=this.getDefaultEnvironmentName();if(n!=null)return{name:"environment",assignment:i.TypeLiteral.reference(i.codeblock(s=>{s.writeNode(r),s.write("::"),s.write(n),s.write("()")}))}}getDefaultEnvironmentName(){var n;if(((n=this.context.ir.environments)==null?void 0:n.environments.type)!=="multipleBaseUrls")return;let e=this.context.ir.environments.environments;if(e.type!=="multipleBaseUrls")return;let t=e.environments;if(t.length===0)return;for(let s of t){let a=this.context.getClassName(s.name);if(a==="Production")return a}let r=t[0];if(r!=null)return this.context.getClassName(r.name)}resolveMultiEnvironmentName(e){let t=Object.keys(e);if(t.length===0||!this.context.validateMultiEnvironmentUrlValues(e))return;let r=t[0];if(r==null)return;let n=e[r];if(n==null)return;let s=this.context.resolveEnvironmentName(n);if(s!=null&&t.every(c=>{let u=e[c];return u==null?!1:this.context.resolveEnvironmentName(u)!=null&&u===n}))return{type:"named",name:this.context.getClassName(s)};let a={};for(let o of t){let c=e[o];if(c==null)continue;let u=this.getBaseUrlPropertyName(o);a[u]=c}if(Object.keys(a).length>0)return{type:"custom",urls:a}}getBaseUrlPropertyName(e){var n;if(((n=this.context.ir.environments)==null?void 0:n.environments.type)!=="multipleBaseUrls")return e;let t=this.context.ir.environments.environments;if(t.type!=="multipleBaseUrls")return e;let r=t.baseUrls.find(s=>s.id===e);return r==null?e:r.name.camelCase.safeName}getConstructorBaseUrlArgs({baseUrl:e,environment:t}){let r=this.getBaseUrlArg({baseUrl:e,environment:t});return i.TypeLiteral.isNop(r)?[]:[{name:"baseUrl",value:r}]}getBaseUrlArg({baseUrl:e,environment:t}){var r;if(e!=null&&t!=null)return this.context.errors.add({severity:l.Critical,message:"Cannot specify both baseUrl and environment options"}),i.TypeLiteral.nop();if(e!=null)return i.TypeLiteral.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let n=this.context.getEnvironmentClassAccessFromID(t);return n==null?(this.context.errors.add({severity:l.Warning,message:`Environment ${JSON.stringify(t)} was not found`}),i.TypeLiteral.nop()):i.TypeLiteral.reference(i.codeblock(s=>{s.writeNode(n),s.write("->value")}))}if(((r=this.context.ir.environments)==null?void 0:r.environments.type)==="multipleBaseUrls")return i.TypeLiteral.nop()}return i.TypeLiteral.nop()}getConstructorBearerAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.token),assignment:i.TypeLiteral.string(t.token)}]}getConstructorHeaderAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.header.name.name),assignment:this.context.dynamicTypeLiteralMapper.convert({typeReference:e.header.typeReference,value:t.value})}]}getConstructorOAuthArgs({auth:e,values:t}){return[{name:this.context.getPropertyName(e.clientId),assignment:i.TypeLiteral.string(t.clientId)},{name:this.context.getPropertyName(e.clientSecret),assignment:i.TypeLiteral.string(t.clientSecret)}]}getConstructorInferredAuthArgs({auth:e,values:t}){return[]}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let n of e){let s=this.getConstructorHeaderArg({header:n,value:t.value});s!=null&&r.push({name:this.context.getPropertyName(n.name.name),value:s})}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeLiteralMapper.convert({typeReference:e.typeReference,value:t});if(!i.TypeLiteral.isNop(r))return r}getMethodArgs({endpoint:e,snippet:t}){switch(e.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:e.request,snippet:t});case"body":return this.getMethodArgsForBodyRequest({request:e.request,snippet:t});default:m(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){var s,a;let r=[];this.context.errors.scope(p.PathParameters);let n=[...(s=this.context.ir.pathParameters)!=null?s:[],...(a=e.pathParameters)!=null?a:[]];return n.length>0&&r.push(...this.getPathParameters({namedParameters:n,snippet:t}).map(o=>o.value)),this.context.errors.unscope(),this.context.errors.scope(p.RequestBody),e.body!=null&&r.push(this.getBodyRequestArg({body:e.body,value:t.requestBody})),this.context.errors.unscope(),r}getBodyRequestArg({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:m(e)}}getBytesBodyRequestArg({value:e}){return this.context.errors.add({severity:l.Critical,message:"The PHP SDK doesn't support bytes requests yet"}),i.TypeLiteral.nop()}getMethodArgsForInlinedRequest({request:e,snippet:t}){var c,u,d,h;let r=[],n=(u=(c=this.context.customConfig)==null?void 0:c.inlinePathParameters)!=null?u:!1;this.context.errors.scope(p.PathParameters);let s=[],a=[...(d=this.context.ir.pathParameters)!=null?d:[],...(h=e.pathParameters)!=null?h:[]];a.length>0&&s.push(...this.getPathParameters({namedParameters:a,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(p.RequestBody);let o=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:n})||r.push(...s.map(g=>g.value)),this.context.needsRequestParameter({request:e,inlinePathParameters:n,inlineFileProperties:!0})&&r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:n})?s:[],filePropertyInfo:o})),r}getFilePropertyInfo({request:e,snippet:t}){return e.body==null||!this.context.isFileUploadRequestBody(e.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:e.body,value:t.requestBody})}getInlinedRequestArg({request:e,snippet:t,pathParameterFields:r,filePropertyInfo:n}){var d,h,g,v;this.context.errors.scope(p.QueryParameters);let a=this.context.associateQueryParametersByWireValue({parameters:(d=e.queryParameters)!=null?d:[],values:(h=t.queryParameters)!=null?h:{}}).map(y=>({name:this.context.getPropertyName(y.name.name),value:this.context.dynamicTypeLiteralMapper.convert(y)}));this.context.errors.unscope(),this.context.errors.scope(p.Headers);let c=this.context.associateByWireValue({parameters:(g=e.headers)!=null?g:[],values:(v=t.headers)!=null?v:{}}).map(y=>({name:this.context.getPropertyName(y.name.name),value:this.context.dynamicTypeLiteralMapper.convert(y)}));this.context.errors.unscope(),this.context.errors.scope(p.RequestBody);let u=e.body!=null?this.getInlinedRequestBodyConstructorFields({body:e.body,value:t.requestBody,filePropertyInfo:n}):[];return this.context.errors.unscope(),i.TypeLiteral.class_({reference:i.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getRequestNamespace(e.declaration.fernFilepath)}),fields:[...r,...a,...c,...u]})}getInlinedRequestBodyConstructorFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyConstructorFields({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyConstructorField({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyConstructorFields({filePropertyInfo:r});default:m(e)}}getFileUploadRequestBodyConstructorFields({filePropertyInfo:e}){return[...e.fileFields,...e.bodyPropertyFields]}getReferencedRequestBodyPropertyConstructorField({body:e,value:t}){return{name:this.context.getPropertyName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeLiteral({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeLiteral({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeLiteralMapper.convert({typeReference:e.value,value:t});default:m(e)}}getInlinedRequestBodyPropertyConstructorFields({parameters:e,value:t}){var s;let r=[],n=this.context.associateByWireValue({parameters:e,values:(s=this.context.getRecord(t))!=null?s:{}});for(let a of n)r.push({name:this.context.getPropertyName(a.name.name),value:this.context.dynamicTypeLiteralMapper.convert(a)});return r}getPathParameters({namedParameters:e,snippet:t}){var s;let r=[],n=this.context.associateByWireValue({parameters:e,values:(s=t.pathParameters)!=null?s:{}});for(let a of n)r.push({name:this.context.getPropertyName(a.name.name),value:this.context.dynamicTypeLiteralMapper.convert(a)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getPropertyName(t)).join("->")}->${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getRootClientClassInstantiation(e){return i.instantiateClass({classReference:i.classReference({name:this.context.getRootClientClassName(),namespace:this.context.rootNamespace}),arguments_:e,multiline:!0})}};export{P as a};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-P7HYTUQU.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as s}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{b as s}from"./chunk-BN32SYGE.js";import{e as p,f as l,g as u,h as c,l as i}from"./chunk-34WVNBJS.js";l();u();var y=class{constructor({context:e}){p(this,"context");this.context=e}convert(e){if(e.value===null)return this.context.isNullable(e.typeReference)?i.TypeLiteral.null():(this.context.errors.add({severity:s.Critical,message:"Expected non-null value, but got null"}),i.TypeLiteral.nop());if(e.value===void 0)return i.TypeLiteral.nop();switch(e.typeReference.type){case"list":case"set":return this.convertList({list:e.typeReference.value,value:e.value});case"literal":return this.convertLiteral({literalType:e.typeReference.value,value:e.value});case"map":return this.convertMap({map:e.typeReference,value:e.value});case"named":{let t=this.context.resolveNamedType({typeId:e.typeReference.value});return t==null?i.TypeLiteral.nop():this.convertNamed({named:t,value:e.value,as:e.as})}case"optional":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as});case"nullable":return this.convert({typeReference:e.typeReference.value,value:e.value,as:e.as});case"primitive":return this.convertPrimitive({primitive:e.typeReference.value,value:e.value,as:e.as});case"unknown":return this.convertUnknown({value:e.value});default:c(e.typeReference)}}convertLiteral({literalType:e,value:t}){switch(e.type){case"boolean":{let n=this.context.getValueAsBoolean({value:t});return n==null?i.TypeLiteral.nop():i.TypeLiteral.boolean(n)}case"string":{let n=this.context.getValueAsString({value:t});return n==null?i.TypeLiteral.nop():i.TypeLiteral.string(n)}default:c(e)}}convertList({list:e,value:t}){return Array.isArray(t)?i.TypeLiteral.list({values:t.map((n,r)=>{this.context.errors.scope({index:r});try{return this.convert({typeReference:e,value:n})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:s.Critical,message:`Expected array but got: ${typeof t}`}),i.TypeLiteral.nop())}convertMap({map:e,value:t}){return typeof t!="object"||t==null?(this.context.errors.add({severity:s.Critical,message:`Expected object but got: ${t==null?"null":typeof t}`}),i.TypeLiteral.nop()):i.TypeLiteral.map({entries:Object.entries(t).map(([n,r])=>{this.context.errors.scope(n);try{return{key:this.convert({typeReference:e.key,value:n,as:"key"}),value:this.convert({typeReference:e.value,value:r})}}finally{this.context.errors.unscope()}})})}convertNamed({named:e,value:t,as:n}){switch(e.type){case"alias":return this.convert({typeReference:e.typeReference,value:t,as:n});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:e,value:t});case"enum":return this.convertEnum({enum_:e,value:t});case"object":return this.convertObject({object_:e,value:t});case"undiscriminatedUnion":return this.convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t});default:c(e)}}convertDiscriminatedUnion({discriminatedUnion:e,value:t}){let n=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:t});if(n==null)return i.TypeLiteral.nop();let r=n.singleDiscriminatedUnionType,a=this.convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:n,unionVariant:r});return a==null?i.TypeLiteral.nop():i.TypeLiteral.reference(i.codeblock(o=>{o.writeNode(i.invokeMethod({on:i.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getTypesNamespace(e.declaration.fernFilepath)}),method:this.context.getMethodName(r.discriminantValue.name),arguments_:this.convertDiscriminatedUnionVariantArgs({discriminatedUnionTypeInstance:n,unionVariant:r,unionProperties:a}),static_:!0}))}))}convertDiscriminatedUnionProperties({discriminatedUnionTypeInstance:e,unionVariant:t}){switch(t.type){case"samePropertiesAsObject":{let n=this.context.resolveNamedType({typeId:t.typeId});if(n==null)return;let r=this.convertNamed({named:n,value:e.value});if(!r.isClass()){this.context.errors.add({severity:s.Critical,message:"Internal error; expected union value to be an object"});return}return r.asClassOrThrow().fields}case"singleProperty":try{this.context.errors.scope(t.discriminantValue.wireValue);let n=this.context.getRecord(e.value);return n==null?[{name:this.context.getPropertyName(t.discriminantValue.name),value:this.convert({typeReference:t.typeReference,value:e.value})}]:[{name:this.context.getPropertyName(t.discriminantValue.name),value:this.convert({typeReference:t.typeReference,value:n[t.discriminantValue.wireValue]})}]}finally{this.context.errors.unscope()}case"noProperties":return[];default:c(t)}}convertDiscriminatedUnionVariantArgs({discriminatedUnionTypeInstance:e,unionVariant:t,unionProperties:n}){let r=this.getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t});if(t.type==="singleProperty"&&this.context.getRecord(e.value)==null&&n.length===1)return[...r,this.convert({typeReference:t.typeReference,value:e.value})];if(t.type==="samePropertiesAsObject"){let a=this.context.resolveNamedType({typeId:t.typeId});return a==null?[]:[...r,i.TypeLiteral.class_({reference:i.classReference({name:this.context.getClassName(a.declaration.name),namespace:this.context.getTypesNamespace(a.declaration.fernFilepath)}),fields:n})]}return r}getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:t}){var r,a;return this.context.associateByWireValue({parameters:(r=t.properties)!=null?r:[],values:(a=this.context.getRecord(e.value))!=null?a:{},ignoreMissingParameters:!0}).map(o=>{this.context.errors.scope(o.name.wireValue);try{return this.convert(o)}finally{this.context.errors.unscope()}})}convertObject({object_:e,value:t}){var r;let n=this.context.associateByWireValue({parameters:e.properties,values:(r=this.context.getRecord(t))!=null?r:{}});return i.TypeLiteral.class_({reference:i.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getTypesNamespace(e.declaration.fernFilepath)}),fields:n.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_:e,value:t}){let n=this.getEnumValueName({enum_:e,value:t});return n==null?i.TypeLiteral.nop():i.TypeLiteral.reference(i.codeblock(r=>{r.writeNode(i.classReference({name:this.context.getClassName(e.declaration.name),namespace:this.context.getTypesNamespace(e.declaration.fernFilepath)})),r.write("::"),r.write(n),r.write("->value")}))}getEnumValueName({enum_:e,value:t}){if(typeof t!="string"){this.context.errors.add({severity:s.Critical,message:`Expected enum value string, got: ${typeof t}`});return}let n=e.values.find(r=>r.wireValue===t);if(n==null){this.context.errors.add({severity:s.Critical,message:`An enum value named "${t}" does not exist in this context`});return}return this.context.getClassName(n.name)}convertUndiscriminatedUnion({undiscriminatedUnion:e,value:t}){let n=this.findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t});return n==null?i.TypeLiteral.nop():n}findMatchingUndiscriminatedUnionType({undiscriminatedUnion:e,value:t}){for(let n of e.types)try{return this.convert({typeReference:n,value:t})}catch(r){continue}this.context.errors.add({severity:s.Critical,message:`None of the types in the undiscriminated union matched the given "${typeof t}" value`})}convertUnknown({value:e}){return i.TypeLiteral.unknown(e)}convertPrimitive({primitive:e,value:t,as:n}){switch(e){case"INTEGER":case"LONG":case"UINT":case"UINT_64":{let r=this.getValueAsNumber({value:t,as:n});return r==null?i.TypeLiteral.nop():i.TypeLiteral.number(r)}case"FLOAT":case"DOUBLE":{let r=this.getValueAsNumber({value:t});return r==null?i.TypeLiteral.nop():i.TypeLiteral.float(r)}case"BOOLEAN":{let r=this.getValueAsBoolean({value:t,as:n});return r==null?i.TypeLiteral.nop():i.TypeLiteral.boolean(r)}case"DATE":case"DATE_TIME":{let r=this.context.getValueAsString({value:t});return r==null?i.TypeLiteral.nop():i.TypeLiteral.datetime(r)}case"BASE_64":case"UUID":case"BIG_INTEGER":case"STRING":{let r=this.context.getValueAsString({value:t});return r==null?i.TypeLiteral.nop():i.TypeLiteral.string(r)}default:c(e)}}getValueAsNumber({value:e,as:t}){let n=t==="key"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:n})}getValueAsBoolean({value:e,as:t}){let n=t==="key"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:n})}};export{y as a};
|
|
2
|
+
//# sourceMappingURL=chunk-Q7QB5SA5.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as o}from"./chunk-P7HYTUQU.js";import{a as i}from"./chunk-MZ7AWQF7.js";import{a as p}from"./chunk-BN32SYGE.js";import{f as t,g as r}from"./chunk-34WVNBJS.js";t();r();var a=class extends p{constructor({ir:e,config:n}){super(new i({ir:e,config:n}))}async generate(e){return super.generate(e)}generateSync(e){return super.generateSync(e)}async generateSnippetAst(e,n){return await super.generateSnippetAst(e,n)}createSnippetGenerator(e){return new o({context:e})}};export{a};
|
|
2
|
+
//# sourceMappingURL=chunk-U6JJRNQH.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-MZ7AWQF7.js";import"../chunk-Q7QB5SA5.js";import"../chunk-BN32SYGE.js";import"../chunk-F7LTKJMT.js";import"../chunk-34WVNBJS.js";export{a as DynamicSnippetsGeneratorContext};
|
|
2
2
|
//# sourceMappingURL=DynamicSnippetsGeneratorContext.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-Q7QB5SA5.js";import"../chunk-BN32SYGE.js";import"../chunk-34WVNBJS.js";export{a as DynamicTypeLiteralMapper};
|
|
2
2
|
//# sourceMappingURL=DynamicTypeLiteralMapper.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-F7LTKJMT.js";import"../chunk-34WVNBJS.js";export{a as FilePropertyMapper};
|
|
2
2
|
//# sourceMappingURL=FilePropertyMapper.js.map
|
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-U6JJRNQH.js";import{a as n}from"./chunk-P7HYTUQU.js";import"./chunk-MZ7AWQF7.js";import"./chunk-Q7QB5SA5.js";import"./chunk-BN32SYGE.js";import"./chunk-F7LTKJMT.js";import{f as e,g as r}from"./chunk-34WVNBJS.js";e();r();export{o as DynamicSnippetsGenerator,n as EndpointSnippetGenerator};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|