@fern-api/go-dynamic-snippets 0.0.13 → 0.0.14
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 +7 -7
- package/cjs/EndpointSnippetGenerator.cjs +6 -6
- package/cjs/context/DynamicSnippetsGeneratorContext.cjs +7 -7
- package/cjs/context/DynamicTypeInstantiationMapper.cjs +7 -7
- package/cjs/context/DynamicTypeMapper.cjs +7 -7
- package/cjs/context/FilePropertyMapper.cjs +4 -4
- package/cjs/index.cjs +8 -8
- package/esm/DynamicSnippetsGenerator.js +1 -1
- package/esm/EndpointSnippetGenerator.js +1 -1
- package/esm/{chunk-IMHG3M62.js → chunk-5HP3T45N.js} +1 -1
- package/esm/chunk-D3UUM672.js +1 -0
- package/esm/{chunk-2GO4GGHE.js → chunk-I3VUX77R.js} +1 -1
- package/esm/{chunk-WXCSO57K.js → chunk-J745U74Q.js} +1 -1
- package/esm/chunk-SS6XZXHU.js +1 -0
- package/esm/{chunk-W5QUFHNP.js → chunk-TUE3DOHS.js} +7 -7
- package/esm/chunk-X7QP3WH3.js +1 -0
- package/esm/{chunk-IHGUMUOY.js → chunk-YAGEU3HO.js} +1 -1
- package/esm/context/DynamicSnippetsGeneratorContext.js +1 -1
- package/esm/context/DynamicTypeInstantiationMapper.js +1 -1
- package/esm/context/DynamicTypeMapper.js +1 -1
- package/esm/context/FilePropertyMapper.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/esm/chunk-25QU7TNW.js +0 -1
- package/esm/chunk-45WV72IW.js +0 -1
- package/esm/chunk-P4OQRDWB.js +0 -1
package/package.json
CHANGED
package/esm/chunk-25QU7TNW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as s,e as c}from"./chunk-WXCSO57K.js";import{j as f,k as F,m as P,n as u,q as n}from"./chunk-W5QUFHNP.js";F();P();var v="example",x="fern",B="do",R="client",A=class{constructor({context:e,formatter:t}){f(this,"context");f(this,"formatter");this.context=e,this.formatter=t}async generateSnippet({endpoint:e,request:t}){var o;return await this.buildCodeBlock({endpoint:e,snippet:t}).toString({packageName:v,importPath:x,rootImportPath:this.context.rootImportPath,customConfig:(o=this.context.customConfig)!=null?o:{},formatter:this.formatter})}generateSnippetSync({endpoint:e,request:t}){var o;return this.buildCodeBlock({endpoint:e,snippet:t}).toStringSync({packageName:v,importPath:x,rootImportPath:this.context.rootImportPath,customConfig:(o=this.context.customConfig)!=null?o:{},formatter:this.formatter})}buildCodeBlock({endpoint:e,snippet:t}){return n.func({name:B,parameters:[],return_:[],body:n.codeblock(r=>{r.writeNode(this.constructClient({endpoint:e,snippet:t})),r.writeLine(),r.writeNode(this.callMethod({endpoint:e,snippet:t}))})})}constructClient({endpoint:e,snippet:t}){return n.codeblock(r=>{r.write(`${R} := `),r.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:e,snippet:t})))})}callMethod({endpoint:e,snippet:t}){return n.invokeMethod({on:n.codeblock(R),method:this.getMethod({endpoint:e}),arguments_:[this.context.getContextTodoFunctionInvocation(),...this.getMethodArgs({endpoint:e,snippet:t})]})}getConstructorArgs({endpoint:e,snippet:t}){let r=[],o=this.getConstructorBaseUrlArg({baseUrl:t.baseURL,environment:t.environment});return o!=null&&r.push(o),e.auth!=null&&(t.auth!=null?r.push(this.getConstructorAuthArg({auth:e.auth,values:t.auth})):this.context.errors.add({severity:s.Warning,message:`Auth with ${e.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(c.Headers),this.context.ir.headers!=null&&t.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:t.headers})),this.context.errors.unscope(),r}getConstructorAuthArg({auth:e,values:t}){switch(e.type){case"basic":return t.type!=="basic"?(this.context.errors.add({severity:s.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),n.TypeInstantiation.nop()):this.getConstructorBasicAuthArg({auth:e,values:t});case"bearer":return t.type!=="bearer"?(this.context.errors.add({severity:s.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),n.TypeInstantiation.nop()):this.getConstructorBearerAuthArg({auth:e,values:t});case"header":return t.type!=="header"?(this.context.errors.add({severity:s.Critical,message:this.context.newAuthMismatchError({auth:e,values:t}).message}),n.TypeInstantiation.nop()):this.getConstructorHeaderAuthArg({auth:e,values:t});default:u(e)}}getConstructorBasicAuthArg({auth:e,values:t}){return n.codeblock(r=>{r.writeNode(n.invokeFunc({func:n.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[n.TypeInstantiation.string(t.username),n.TypeInstantiation.string(t.password)]}))})}getConstructorBaseUrlArg({baseUrl:e,environment:t}){let r=this.getBaseUrlArg({baseUrl:e,environment:t});if(r!=null)return n.codeblock(o=>{o.writeNode(n.invokeFunc({func:n.typeReference({name:"WithBaseURL",importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}getBaseUrlArg({baseUrl:e,environment:t}){if(e!=null&&t!=null){this.context.errors.add({severity:s.Critical,message:"Cannot specify both baseUrl and environment options"});return}if(e!=null)return n.TypeInstantiation.string(e);if(t!=null){if(this.context.isSingleEnvironmentID(t)){let r=this.context.getEnvironmentTypeReferenceFromID(t);if(r==null){this.context.errors.add({severity:s.Warning,message:`Environment ${JSON.stringify(t)} was not found`});return}return n.TypeInstantiation.reference(r)}this.context.isMultiEnvironmentValues(t)&&this.context.errors.add({severity:s.Warning,message:"The Go SDK doesn't support a multi-environment client option yet; use the baseUrl option instead"})}}getConstructorBearerAuthArg({auth:e,values:t}){return n.codeblock(r=>{r.writeNode(n.invokeFunc({func:n.typeReference({name:`With${e.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[n.TypeInstantiation.string(t.token)]}))})}getConstructorHeaderAuthArg({auth:e,values:t}){return n.codeblock(r=>{r.writeNode(n.invokeFunc({func:n.typeReference({name:`With${e.header.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[this.context.dynamicTypeInstantiationMapper.convert({typeReference:e.header.typeReference,value:t.value})]}))})}getConstructorHeaderArgs({headers:e,values:t}){let r=[];for(let o of e){let i=this.getConstructorHeaderArg({header:o,value:t.value});i!=null&&r.push(i)}return r}getConstructorHeaderArg({header:e,value:t}){let r=this.context.dynamicTypeInstantiationMapper.convert({typeReference:e.typeReference,value:t});if(!n.TypeInstantiation.isNop(r))return n.codeblock(o=>{o.writeNode(n.invokeFunc({func:n.typeReference({name:`With${e.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[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:u(e.request)}}getMethodArgsForBodyRequest({request:e,snippet:t}){let r=[];if(this.context.errors.scope(c.PathParameters),e.pathParameters!=null){let o=this.getPathParameters({namedParameters:e.pathParameters,snippet:t});r.push(...o.map(i=>i.value))}return this.context.errors.unscope(),this.context.errors.scope(c.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.dynamicTypeInstantiationMapper.convert({typeReference:e.value,value:t});default:u(e)}}getBytesBodyRequestArg({value:e}){return typeof e!="string"?(this.context.errors.add({severity:s.Critical,message:`Expected bytes value to be a string, got ${typeof e}`}),n.TypeInstantiation.nop()):n.TypeInstantiation.bytes(e)}getMethodArgsForInlinedRequest({request:e,snippet:t}){var l,y,p,h;let r=[],{inlinePathParameters:o,inlineFileProperties:i}={inlinePathParameters:(y=(l=this.context.customConfig)==null?void 0:l.inlinePathParameters)!=null?y:!1,inlineFileProperties:(h=(p=this.context.customConfig)==null?void 0:p.inlineFileProperties)!=null?h:!1};this.context.errors.scope(c.PathParameters);let a=[];e.pathParameters!=null&&a.push(...this.getPathParameters({namedParameters:e.pathParameters,snippet:t})),this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let g=this.getFilePropertyInfo({request:e,snippet:t});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:o})||r.push(...a.map(d=>d.value)),i||r.push(...g.fileFields.map(d=>d.value)),this.context.needsRequestParameter({request:e,inlinePathParameters:o,inlineFileProperties:i})&&r.push(this.getInlinedRequestArg({request:e,snippet:t,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:e,inlinePathParameters:o})?a:[],filePropertyInfo:g})),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:o}){var p,h,d,I;this.context.errors.scope(c.QueryParameters);let a=this.context.associateQueryParametersByWireValue({parameters:(p=e.queryParameters)!=null?p:[],values:(h=t.queryParameters)!=null?h:{}}).map(m=>({name:m.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.Headers);let l=this.context.associateByWireValue({parameters:(d=e.headers)!=null?d:[],values:(I=t.headers)!=null?I:{}}).map(m=>({name:m.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(m)}));this.context.errors.unscope(),this.context.errors.scope(c.RequestBody);let y=e.body!=null?this.getInlinedRequestBodyStructFields({body:e.body,value:t.requestBody,filePropertyInfo:o}):[];return this.context.errors.unscope(),n.TypeInstantiation.structPointer({typeReference:n.typeReference({name:this.context.getMethodName(e.declaration.name),importPath:this.context.getImportPath(e.declaration.fernFilepath)}),fields:[...r,...a,...l,...y]})}getInlinedRequestBodyStructFields({body:e,value:t,filePropertyInfo:r}){switch(e.type){case"properties":return this.getInlinedRequestBodyPropertyStructFields({parameters:e.value,value:t});case"referenced":return[this.getReferencedRequestBodyPropertyStructField({body:e,value:t})];case"fileUpload":return this.getFileUploadRequestBodyStructFields({filePropertyInfo:r});default:u(e)}}getFileUploadRequestBodyStructFields({filePropertyInfo:e}){var t;return(t=this.context.customConfig)!=null&&t.inlineFileProperties?[...e.fileFields,...e.bodyPropertyFields]:e.bodyPropertyFields}getReferencedRequestBodyPropertyStructField({body:e,value:t}){return{name:this.context.getTypeName(e.bodyKey),value:this.getReferencedRequestBodyPropertyTypeInstantiation({body:e.bodyType,value:t})}}getReferencedRequestBodyPropertyTypeInstantiation({body:e,value:t}){switch(e.type){case"bytes":return this.getBytesBodyRequestArg({value:t});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:e.value,value:t});default:u(e)}}getInlinedRequestBodyPropertyStructFields({parameters:e,value:t}){var i;let r=[],o=this.context.associateByWireValue({parameters:e,values:(i=this.context.getRecord(t))!=null?i:{}});for(let a of o)r.push({name:this.context.getTypeName(a.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(a)});return r}getPathParameters({namedParameters:e,snippet:t}){var i;let r=[],o=this.context.associateByWireValue({parameters:e,values:(i=t.pathParameters)!=null?i:{}});for(let a of o)r.push({name:this.context.getTypeName(a.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(a)});return r}getMethod({endpoint:e}){return e.declaration.fernFilepath.allParts.length>0?`${e.declaration.fernFilepath.allParts.map(t=>this.context.getMethodName(t)).join(".")}.${this.context.getMethodName(e.declaration.name)}`:this.context.getMethodName(e.declaration.name)}getRootClientFuncInvocation(e){return n.invokeFunc({func:n.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:e})}};export{A as a};
|
package/esm/chunk-45WV72IW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as c}from"./chunk-WXCSO57K.js";import{j as u,k as l,m as d,n as o,q as i}from"./chunk-W5QUFHNP.js";l();d();var y=class{constructor({context:e}){u(this,"context");this.context=e}convert(e){if(e.value==null)return i.TypeInstantiation.nop();switch(e.typeReference.type){case"list":return this.convertList({list:e.typeReference.value,value:e.value});case"literal":return i.TypeInstantiation.nop();case"map":return this.convertMap({map:e.typeReference,value:e.value});case"named":{let n=this.context.resolveNamedType({typeId:e.typeReference.value});return n==null?i.TypeInstantiation.nop():this.convertNamed({named:n,value:e.value,as:e.as})}case"optional":return i.TypeInstantiation.optional(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"set":return this.convertList({list:e.typeReference.value,value:e.value});case"unknown":return this.convertUnknown({value:e.value});default:o(e.typeReference)}}convertList({list:e,value:n}){return Array.isArray(n)?i.TypeInstantiation.slice({valueType:this.context.dynamicTypeMapper.convert({typeReference:e}),values:n.map((r,t)=>{this.context.errors.scope({index:t});try{return this.convert({typeReference:e,value:r})}finally{this.context.errors.unscope()}})}):(this.context.errors.add({severity:c.Critical,message:`Expected array but got: ${typeof n}`}),i.TypeInstantiation.nop())}convertMap({map:e,value:n}){return typeof n!="object"||n==null?(this.context.errors.add({severity:c.Critical,message:`Expected object but got: ${n==null?"null":typeof n}`}),i.TypeInstantiation.nop()):i.TypeInstantiation.map({keyType:this.context.dynamicTypeMapper.convert({typeReference:e.key}),valueType:this.context.dynamicTypeMapper.convert({typeReference:e.value}),entries:Object.entries(n).map(([r,t])=>{this.context.errors.scope(r);try{return{key:this.convert({typeReference:e.key,value:r,as:"key"}),value:this.convert({typeReference:e.value,value:t})}}finally{this.context.errors.unscope()}})})}convertNamed({named:e,value:n,as:r}){switch(e.type){case"alias":return this.convert({typeReference:e.typeReference,value:n,as:r});case"discriminatedUnion":return this.convertDiscriminatedUnion({discriminatedUnion:e,value:n});case"enum":return this.convertEnum({enum_:e,value:n});case"object":return this.convertObject({object_:e,value:n});case"undiscriminatedUnion":return this.convertUndicriminatedUnion({undicriminatedUnion:e,value:n});default:o(e)}}convertDiscriminatedUnion({discriminatedUnion:e,value:n}){let r=this.context.getGoTypeReferenceFromDeclaration({declaration:e.declaration}),t=this.context.resolveDiscriminatedUnionTypeInstance({discriminatedUnion:e,value:n});if(t==null)return i.TypeInstantiation.nop();let a=t.singleDiscriminatedUnionType,s=this.getBaseFields({discriminatedUnionTypeInstance:t,singleDiscriminatedUnionType:a});switch(a.type){case"samePropertiesAsObject":{let p=this.context.resolveNamedType({typeId:a.typeId});return p==null?i.TypeInstantiation.nop():i.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(a.discriminantValue.name),value:this.convertNamed({named:p,value:t.value})},...s]})}case"singleProperty":{let p=this.context.getRecord(t.value);if(p==null)return i.TypeInstantiation.nop();try{return this.context.errors.scope(a.discriminantValue.wireValue),i.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(a.discriminantValue.name),value:this.convert({typeReference:a.typeReference,value:p[a.discriminantValue.wireValue]})},...s]})}finally{this.context.errors.unscope()}}case"noProperties":return i.TypeInstantiation.structPointer({typeReference:r,fields:[{name:this.context.getTypeName(t.discriminantValue.name),value:i.TypeInstantiation.string(a.discriminantValue.wireValue)},...s]});default:o(a)}}getBaseFields({discriminatedUnionTypeInstance:e,singleDiscriminatedUnionType:n}){var t,a;return this.context.associateByWireValue({parameters:(t=n.properties)!=null?t:[],values:(a=this.context.getRecord(e.value))!=null?a:{},ignoreMissingParameters:!0}).map(s=>{this.context.errors.scope(s.name.wireValue);try{return{name:this.context.getTypeName(s.name.name),value:this.convert(s)}}finally{this.context.errors.unscope()}})}convertObject({object_:e,value:n}){var t;let r=this.context.associateByWireValue({parameters:e.properties,values:(t=this.context.getRecord(n))!=null?t:{}});return i.TypeInstantiation.structPointer({typeReference:i.typeReference({name:this.context.getTypeName(e.declaration.name),importPath:this.context.getImportPath(e.declaration.fernFilepath)}),fields:r.map(a=>{this.context.errors.scope(a.name.wireValue);try{return{name:this.context.getTypeName(a.name.name),value:this.convert(a)}}finally{this.context.errors.unscope()}})})}convertEnum({enum_:e,value:n}){let r=this.getEnumValueName({enum_:e,value:n});return r==null?i.TypeInstantiation.nop():i.TypeInstantiation.enum(i.typeReference({name:r,importPath:this.context.getImportPath(e.declaration.fernFilepath)}))}getEnumValueName({enum_:e,value:n}){if(typeof n!="string"){this.context.errors.add({severity:c.Critical,message:`Expected enum value string, got: ${typeof n}`});return}let r=e.values.find(t=>t.wireValue===n);if(r==null){this.context.errors.add({severity:c.Critical,message:`An enum value named "${n}" does not exist in this context`});return}return`${this.context.getTypeName(e.declaration.name)}${this.context.getTypeName(r.name)}`}convertUndicriminatedUnion({undicriminatedUnion:e,value:n}){let r=this.findMatchingUndiscriminatedUnionType({undicriminatedUnion:e,value:n});if(r==null)return i.TypeInstantiation.nop();let t=this.getUndiscriminatedUnionFieldName({typeReference:r.valueTypeReference});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.structPointer({typeReference:this.context.getGoTypeReferenceFromDeclaration({declaration:e.declaration}),fields:[{name:t,value:r.typeInstantiation}]})}findMatchingUndiscriminatedUnionType({undicriminatedUnion:e,value:n}){for(let r of e.types)try{let t=this.convert({typeReference:r,value:n});return{valueTypeReference:r,typeInstantiation:t}}catch(t){continue}this.context.errors.add({severity:c.Critical,message:`None of the types in the undicriminated union matched the given "${typeof n}" value`})}getUndiscriminatedUnionFieldName({typeReference:e}){switch(e.type){case"list":return this.getUndiscriminatedUnionFieldNameForList({list:e});case"literal":return this.getUndiscriminatedUnionFieldNameForLiteral({literal:e.value});case"map":return this.getUndiscriminatedUnionFieldNameForMap({map:e});case"named":{let n=this.context.resolveNamedType({typeId:e.value});return n==null?void 0:this.context.getTypeName(n.declaration.name)}case"optional":return this.getUndiscriminatedUnionFieldNameForOptional({optional:e});case"primitive":return this.getUndiscriminatedUnionFieldNameForPrimitive({primitive:e.value});case"set":return this.getUndiscriminatedUnionFieldNameForSet({set:e});case"unknown":return"Unknown"}}getUndiscriminatedUnionFieldNameForList({list:e}){let n=this.getUndiscriminatedUnionFieldName({typeReference:e});if(n!=null)return`${n}List`}getUndiscriminatedUnionFieldNameForMap({map:e}){let n=this.getUndiscriminatedUnionFieldName({typeReference:e.key});if(n==null)return;let r=this.getUndiscriminatedUnionFieldName({typeReference:e.value});if(r!=null)return`${n}${r}Map`}getUndiscriminatedUnionFieldNameForOptional({optional:e}){let n=this.getUndiscriminatedUnionFieldName({typeReference:e});if(n!=null)return`${n}Optional`}getUndiscriminatedUnionFieldNameForSet({set:e}){let n=this.getUndiscriminatedUnionFieldName({typeReference:e});if(n!=null)return`${n}Set`}getUndiscriminatedUnionFieldNameForLiteral({literal:e}){switch(e.type){case"boolean":return`${e.value}BoolLiteral`;case"string":return`${e.value}StringLiteral`;default:o(e)}}getUndiscriminatedUnionFieldNameForPrimitive({primitive:e}){switch(e){case"INTEGER":case"UINT":return"Integer";case"LONG":case"UINT_64":return"Long";case"FLOAT":case"DOUBLE":return"Double";case"BOOLEAN":return"Boolean";case"BIG_INTEGER":case"STRING":return"String";case"UUID":return"Uuid";case"DATE":return"Date";case"DATE_TIME":return"DateTime";case"BASE_64":return"Base64";default:o(e)}}convertUnknown({value:e}){return i.TypeInstantiation.any(e)}convertPrimitive({primitive:e,value:n,as:r}){switch(e){case"INTEGER":case"UINT":{let t=this.getValueAsNumber({value:n,as:r});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.int(t)}case"LONG":case"UINT_64":{let t=this.getValueAsNumber({value:n,as:r});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.int64(t)}case"FLOAT":case"DOUBLE":{let t=this.getValueAsNumber({value:n,as:r});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.float64(t)}case"BOOLEAN":{let t=this.getValueAsBoolean({value:n,as:r});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.bool(t)}case"STRING":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.string(t)}case"DATE":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.date(t)}case"DATE_TIME":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.dateTime(t)}case"UUID":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.uuid(t)}case"BASE_64":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.bytes(t)}case"BIG_INTEGER":{let t=this.context.getValueAsString({value:n});return t==null?i.TypeInstantiation.nop():i.TypeInstantiation.string(t)}default:o(e)}}getValueAsNumber({value:e,as:n}){let r=n==="key"&&typeof e=="string"?Number(e):e;return this.context.getValueAsNumber({value:r})}getValueAsBoolean({value:e,as:n}){let r=n==="key"?typeof e=="string"?e==="true":e==="false"?!1:e:e;return this.context.getValueAsBoolean({value:r})}};export{y as a};
|
package/esm/chunk-P4OQRDWB.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as c,k as i,m as p,n,q as e}from"./chunk-W5QUFHNP.js";i();p();var a=class{constructor({context:t}){c(this,"context");this.context=t}convert(t){switch(t.typeReference.type){case"list":return e.Type.slice(this.convert({typeReference:t.typeReference}));case"literal":return this.convertLiteral({literal:t.typeReference.value});case"map":return e.Type.map(this.convert({typeReference:t.typeReference.key}),this.convert({typeReference:t.typeReference.value}));case"named":{let r=this.context.resolveNamedType({typeId:t.typeReference.value});return r==null?this.convertUnknown():this.convertNamed({named:r})}case"optional":return e.Type.optional(this.convert({typeReference:t.typeReference.value}));case"primitive":return this.convertPrimitive({primitive:t.typeReference.value});case"set":return e.Type.slice(this.convert({typeReference:t.typeReference}));case"unknown":return this.convertUnknown();default:n(t.typeReference)}}convertLiteral({literal:t}){switch(t.type){case"boolean":return e.Type.bool();case"string":return e.Type.string()}}convertNamed({named:t}){let r=e.Type.reference(e.typeReference({name:this.context.getTypeName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}));switch(t.type){case"alias":case"enum":return r;case"discriminatedUnion":case"object":case"undiscriminatedUnion":return e.Type.pointer(r);default:n(t)}}convertUnknown(){return e.Type.any()}convertPrimitive({primitive:t}){switch(t){case"INTEGER":return e.Type.int();case"UINT":return e.Type.int();case"LONG":return e.Type.int64();case"UINT_64":return e.Type.int64();case"FLOAT":return e.Type.float64();case"DOUBLE":return e.Type.float64();case"BOOLEAN":return e.Type.bool();case"STRING":return e.Type.string();case"DATE":return e.Type.date();case"DATE_TIME":return e.Type.dateTime();case"UUID":return e.Type.uuid();case"BASE_64":return e.Type.bytes();case"BIG_INTEGER":return e.Type.string();default:n(t)}}};export{a};
|