@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
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
${i}`);this.isAtStartOfLine()&&(o=i+o),e&&(o+=`
|
|
5
5
|
`),this.writeInternal(o)}writeNoIndent(t){let e=this.indentLevel;this.indentLevel=0,this.write(t),this.indentLevel=e}writeNode(t){t.write(this)}writeNodeStatement(t){t.write(this),this.write(";"),this.writeNewLineIfLastLineNot()}writeTextStatement(t){new C(t).write(this),this.write(";"),this.writeNewLineIfLastLineNot()}controlFlow(t,e){new C(t).write(this),this.write(" ("),this.writeNode(e),this.write(") {"),this.writeNewLineIfLastLineNot(),this.indent()}endControlFlow(){this.dedent(),this.writeLine("}")}openBlock(t,e="{",n,i="}"){let o=t.filter(s=>s!==void 0).join(" ");o?this.write(`${o} ${e!=null?e:""}`):this.write(e!=null?e:"");try{this.indent(),n(),this.dedent()}finally{this.write(i!=null?i:"")}}writeLine(t=""){this.write(t),this.writeNewLineIfLastLineNot()}newLine(){this.writeInternal(`
|
|
6
6
|
`)}writeNewLineIfLastLineNot(){this.lastCharacterIsNewline||this.writeInternal(`
|
|
7
|
-
`)}indent(){this.indentLevel++}dedent(){this.indentLevel--}delimit({nodes:t,delimiter:e,writeFunction:n}){if(t.length>0){let i=t[0];i!=null&&n(i);for(let o=1;o<t.length;o++){this.write(e);let s=t[o];s!=null&&n(s)}}}writeInternal(t){return t.length>0&&(this.hasWrittenAnything=!0,this.lastCharacterIsNewline=t.endsWith(`
|
|
8
|
-
`)),this.buffer+=t}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*er)}};u();f();var ce=class{},j=class extends ce{async format(t){return t}formatSync(t){return t}};u();f();function ye(r){return(r==null?void 0:r.name)!=null}u();f();u();f();function xe(r,t){var n,i;let e=(n=r.split("/").pop())!=null?n:r;return t!=null&&t.stripExtension&&(i=e.split(".")[0])!=null?i:e}u();f();u();f();u();f();u();f();u();f();var tr=/[^0-9a-zA-Z_]/g,V=class extends K{constructor({packageName:e,rootImportPath:n,importPath:i,customConfig:o,formatter:s}){super();c(this,"packageName");c(this,"rootImportPath");c(this,"importPath");c(this,"customConfig");c(this,"formatter");c(this,"imports",{});this.packageName=e,this.rootImportPath=n,this.importPath=i,this.customConfig=o,this.formatter=s!=null?s:new j}addImport(e){let n=this.imports[e];if(n!=null)return n;let i=this.getValidAlias(xe(e));for(;i in this.imports;)i="_"+i;return this.imports[e]=i,i}getValidAlias(e){let n=e.split("-");return n[0]==null?e:n[0].replace(tr,"")}};var ee=class extends V{constructor({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o}){super({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o})}async
|
|
9
|
-
${t}`)}return t}
|
|
7
|
+
`)}indent(){this.indentLevel++}dedent(){this.indentLevel--}delimit({nodes:t,delimiter:e,writeFunction:n}){if(t.length>0){let i=t[0];i!=null&&n(i);for(let o=1;o<t.length;o++){this.write(e);let s=t[o];s!=null&&n(s)}}}toString(){return this.buffer}writeInternal(t){return t.length>0&&(this.hasWrittenAnything=!0,this.lastCharacterIsNewline=t.endsWith(`
|
|
8
|
+
`)),this.buffer+=t}isAtStartOfLine(){return this.lastCharacterIsNewline||!this.hasWrittenAnything}getIndentString(){return" ".repeat(this.indentLevel*er)}};u();f();var ce=class{},j=class extends ce{async format(t){return t}formatSync(t){return t}};u();f();function ye(r){return(r==null?void 0:r.name)!=null}u();f();u();f();function xe(r,t){var n,i;let e=(n=r.split("/").pop())!=null?n:r;return t!=null&&t.stripExtension&&(i=e.split(".")[0])!=null?i:e}u();f();u();f();u();f();u();f();u();f();var tr=/[^0-9a-zA-Z_]/g,V=class extends K{constructor({packageName:e,rootImportPath:n,importPath:i,customConfig:o,formatter:s}){super();c(this,"packageName");c(this,"rootImportPath");c(this,"importPath");c(this,"customConfig");c(this,"formatter");c(this,"imports",{});this.packageName=e,this.rootImportPath=n,this.importPath=i,this.customConfig=o,this.formatter=s!=null?s:new j}addImport(e){let n=this.imports[e];if(n!=null)return n;let i=this.getValidAlias(xe(e));for(;i in this.imports;)i="_"+i;return this.imports[e]=i,i}getValidAlias(e){let n=e.split("-");return n[0]==null?e:n[0].replace(tr,"")}};var ee=class extends V{constructor({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o}){super({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o})}async toStringAsync(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.format(t)}catch(e){throw new Error(`Failed to format Go file: ${e}
|
|
9
|
+
${t}`)}return t}toString(){let t=this.getContent();if(this.formatter!=null)try{return this.formatter.formatSync(t)}catch(e){throw new Error(`Failed to format Go file: ${e}
|
|
10
10
|
${t}`)}return t}getContent(){let t=`package ${this.packageName}
|
|
11
11
|
|
|
12
12
|
`,e=this.stringifyImports();return e.length>0?`${t}${e}
|
|
@@ -14,7 +14,7 @@ ${t}`)}return t}getContent(){let t=`package ${this.packageName}
|
|
|
14
14
|
${this.buffer}`:t+this.buffer}stringifyImports(){let t=Object.entries(this.imports).filter(([e,n])=>e!==this.importPath).map(([e,n])=>` ${n} "${e}"`).join(`
|
|
15
15
|
`);return t?`import (
|
|
16
16
|
${t}
|
|
17
|
-
)`:""}};var y=class extends W{async
|
|
17
|
+
)`:""}};var y=class extends W{async toStringAsync({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o}){let s=new ee({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o});return this.write(s),s.toStringAsync()}toString({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o}){let s=new ee({packageName:t,rootImportPath:e,importPath:n,customConfig:i,formatter:o});return this.write(s),s.toString()}};var T=class extends y{constructor({name:e,importPath:n}){super();c(this,"name");c(this,"importPath");this.name=e,this.importPath=n}write(e){if(e.importPath===this.importPath){e.write(this.name);return}let n=e.addImport(this.importPath);e.write(`${n}.${this.name}`)}};var rr=new Set(["any","bytes","map","slice"]),te=class r extends y{constructor(e){super();c(this,"internalType");this.internalType=e}write(e,{comment:n}={}){switch(this.internalType.type){case"any":e.write("interface{}");break;case"bool":e.write("bool");break;case"bytes":e.write("[]byte");break;case"date":case"dateTime":e.writeNode(nr);break;case"float64":e.write("float64");break;case"int":e.write("int");break;case"int64":e.write("int64");break;case"map":{e.write("map["),this.internalType.keyType.write(e),e.write("]"),this.internalType.valueType.write(e);break}case"optional":{e.write("*"),this.internalType.value.write(e);break}case"reference":e.writeNode(this.internalType.value);break;case"slice":e.write("[]"),this.internalType.value.write(e);break;case"string":e.write("string");break;case"uuid":e.writeNode(ir);break;default:O(this.internalType)}}isOptional(){return this.internalType.type==="optional"}static any(){return new this({type:"any"})}static bool(){return new this({type:"bool"})}static bytes(){return new this({type:"bytes"})}static date(){return new this({type:"date"})}static dateTime(){return new this({type:"dateTime"})}static float64(){return new this({type:"float64"})}static int(){return new this({type:"int"})}static int64(){return new this({type:"int64"})}static map(e,n){return new this({type:"map",keyType:e,valueType:n})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return r.optional(e)}static reference(e){return new this({type:"reference",value:e})}static slice(e){return new this({type:"slice",value:e})}static string(){return new this({type:"string"})}static uuid(){return new this({type:"uuid"})}static isAlreadyOptional(e){return e.internalType.type==="optional"||rr.has(e.internalType.type)}},nr=new T({importPath:"time",name:"Time"}),ir=new T({importPath:"github.com/google/uuid",name:"UUID"});u();f();u();f();var k=class extends y{constructor(e){super();c(this,"arg");this.arg=e}write(e){return new C(this.arg).write(e)}};u();f();u();f();var v=class extends y{constructor({docs:e}={}){super();c(this,"docs");this.docs=e}write(e){this.docs!=null&&this.docs.split(`
|
|
18
18
|
`).forEach(n=>{e.writeLine(`// ${n}`)})}};var G=class extends y{constructor({name:e,docs:n}){super();c(this,"name");c(this,"docs");c(this,"members",[]);this.name=e,this.docs=n}addMember(e){this.members.push(e)}write(e){e.writeNode(new v({docs:this.docs})),e.write(`type ${this.name} string`)}};u();f();var H=class extends y{constructor({name:e,type:n,docs:i}){super();c(this,"name");c(this,"type");c(this,"docs");this.name=e,this.type=n,this.docs=i}write(e){e.writeNode(new v({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};u();f();u();f();var U=class extends y{constructor({name:e,parameters:n,return_:i,body:o,docs:s,typeReference:p}){super();c(this,"name");c(this,"parameters");c(this,"return_");c(this,"body");c(this,"docs");c(this,"typeReference");this.name=e,this.parameters=n,this.return_=i,this.body=o,this.docs=s,this.typeReference=p}write(e){var n;if(e.writeNode(new v({docs:this.docs})),e.write("func "),this.typeReference!=null&&this.writeReceiver({writer:e,typeReference:this.typeReference}),e.write(`${this.name}`),this.parameters.length===0)e.write("() ");else{e.writeLine("(");for(let i of this.parameters)e.writeNode(i),e.writeLine(",");e.write(")")}this.return_!=null&&(e.write("("),this.return_.forEach((i,o)=>{o>0&&e.write(", "),e.writeNode(i)}),e.write(")")),e.writeLine(" {"),e.indent(),(n=this.body)==null||n.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.writeLine("}")}writeReceiver({writer:e,typeReference:n}){e.write(`(${this.getReceiverName(n.name)} `),n.write(e),e.write(") ")}getReceiverName(e){return e.charAt(0).toLowerCase()}};var J=class extends y{constructor({name:e,parameters:n,return_:i,body:o,docs:s}){super();c(this,"func");this.func=new U({name:e,parameters:n,return_:i,body:o,docs:s})}get name(){return this.func.name}get parameters(){return this.func.parameters}get return_(){return this.func.return_}get body(){return this.func.body}get docs(){return this.func.docs}write(e){e.writeNode(this.func)}};u();f();u();f();u();f();u();f();var L=class extends y{constructor({method:e,arguments_:n,on:i}){super();c(this,"on");c(this,"method");c(this,"arguments_");this.on=i,this.method=e,this.arguments_=n}write(e){this.on.write(e),e.write("."),e.write(this.method),pe({writer:e,arguments_:this.arguments_})}};var or=new Set(["bool","date","dateTime","float64","int","int64","string","uuid"]),Ge=new Set(["any","bytes","map","slice"]),I=class r extends y{constructor(e){super();c(this,"internalType");this.internalType=e}write(e){switch(this.internalType.type){case"any":this.writeAny({writer:e,value:this.internalType.value});break;case"bool":e.write(this.internalType.value.toString());break;case"bytes":e.write(`[]byte("${this.internalType.value}")`);break;case"date":case"dateTime":e.writeNode(ur({writer:e,type:this.internalType}));break;case"enum":e.writeNode(this.internalType.typeReference);break;case"float64":e.write(this.internalType.value.toString());break;case"int":case"int64":e.write(this.internalType.value.toString());break;case"map":this.writeMap({writer:e,map:this.internalType});break;case"nil":e.write("nil");break;case"nop":break;case"optional":this.writeOptional({writer:e,type:this.internalType.value});break;case"reference":e.writeNode(this.internalType.value);break;case"slice":this.writeSlice({writer:e,slice:this.internalType});break;case"string":e.write(this.internalType.value.includes('"')||this.internalType.value.includes(`
|
|
19
19
|
`)?`\`${this.internalType.value}\``:`"${this.internalType.value}"`);break;case"struct":this.writeStruct({writer:e,struct:this.internalType});break;case"uuid":e.writeNode(fr({value:this.internalType.value}));break;default:O(this.internalType)}}static any(e){return new this({type:"any",value:e})}static bool(e){return new this({type:"bool",value:e})}static bytes(e){return new this({type:"bytes",value:e})}static date(e){return new this({type:"date",value:e})}static dateTime(e){return new this({type:"dateTime",value:e})}static enum(e){return new this({type:"enum",typeReference:e})}static float64(e){return new this({type:"float64",value:e})}static int(e){return new this({type:"int",value:e})}static int64(e){return new this({type:"int64",value:e})}static map({keyType:e,valueType:n,entries:i}){return new this({type:"map",keyType:e,valueType:n,entries:i})}static nil(){return new this({type:"nil"})}static nop(){return new this({type:"nop"})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static reference(e){return new this({type:"reference",value:e})}static slice({valueType:e,values:n}){return new this({type:"slice",valueType:e,values:n})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:n}){return new this({type:"struct",typeReference:e,fields:n})}static structPointer({typeReference:e,fields:n}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:n})})}static uuid(e){return new this({type:"uuid",value:e})}static isNop(e){return e.internalType.type==="optional"?this.isNop(e.internalType.value):e.internalType.type==="nop"}writeAny({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("nil");return}if(Array.isArray(n)){this.writeAnyArray({writer:e,value:n});return}this.writeAnyObject({writer:e,value:n});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof n}`)}}writeAnyArray({writer:e,value:n}){if(e.write("[]interface{}"),n.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let i of n)e.writeNode(r.any(i)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:n}){e.write("map[string]interface{}");let i=Object.entries(n);if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[o,s]of i)e.write(`"${o}": `),e.writeNode(r.any(s)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:n}){e.write("map["),e.writeNode(n.keyType),e.write("]"),e.writeNode(n.valueType);let i=cr({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("}")}writeOptional({writer:e,type:n}){if(or.has(n.internalType.type)){e.writeNode(sr({writer:e,type:n}));return}if(Ge.has(n.internalType.type)){n.write(e);return}if(n.internalType.type==="enum"){e.writeNode(new L({on:n.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),n.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||Ge.has(e.internalType.type)}writeSlice({writer:e,slice:n}){e.write("[]"),e.writeNode(n.valueType);let i=hr({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("}")}writeStruct({writer:e,struct:n}){e.writeNode(n.typeReference);let i=pr({fields:n.fields});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let o of i)e.write(`${o.name}: `),o.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function sr({writer:r,type:t}){return new R({func:new T({name:ar({type:t}),importPath:r.rootImportPath}),arguments_:[t]})}function ar({type:r}){switch(r.internalType.type){case"bool":return"Bool";case"date":case"dateTime":return"Time";case"float64":return"Float64";case"int":return"Int";case"int64":return"Int64";case"string":return"String";case"uuid":return"UUID";default:return""}}function ur({writer:r,type:t}){let e=t instanceof Date?"MustParseDate":"MustParseDateTime";return new R({func:new T({name:e,importPath:r.rootImportPath}),arguments_:[new k(`"${t.value}"`)]})}function fr({value:r}){return new R({func:new T({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new k(`"${r}"`)]})}function cr({entries:r}){return r.filter(t=>!I.isNop(t.key)&&!I.isNop(t.value))}function pr({fields:r}){return r.filter(t=>!I.isNop(t.value))}function hr({values:r}){return r.filter(t=>!I.isNop(t))}function pe({writer:r,arguments_:t}){let e=mr(t);if(e.length===0){r.write("()");return}r.writeLine("("),r.indent();for(let n of e)lr({writer:r,argument:n}),r.writeLine(",");r.dedent(),r.write(")")}function lr({writer:r,argument:t}){ye(t)?t.assignment.write(r):t.write(r)}function mr(r){return r.filter(t=>!(t instanceof I&&I.isNop(t)))}var R=class extends y{constructor({func:e,arguments_:n}){super();c(this,"func");c(this,"arguments_");this.func=e,this.arguments_=n}write(e){e.writeNode(this.func),pe({writer:e,arguments_:this.arguments_})}};u();f();var q=class extends y{constructor({name:e,type:n,docs:i}){super();c(this,"name");c(this,"type");c(this,"docs");this.name=e,this.type=n,this.docs=i}write(e){e.writeNode(new v({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};u();f();var z=class extends y{constructor({name:e,importPath:n,docs:i}){super();c(this,"name");c(this,"importPath");c(this,"docs");c(this,"fields",[]);c(this,"methods",[]);this.name=e,this.importPath=n,this.docs=i}addField(e){this.fields.push(e)}addMethod(e){this.methods.push(e)}write(e){if(e.writeNode(new v({docs:this.docs})),e.write(`type ${this.name} struct {`),this.fields.length>0)e.writeLine("}");else{e.newLine(),e.indent();for(let n of this.fields)e.writeNode(n),e.newLine();e.dedent(),e.writeLine("}")}(this.constructor!=null||this.methods.length>0)&&e.newLine();for(let n of this.methods)e.writeNode(n),e.newLine()}};var _={};Te(_,{AstNode:()=>y,CodeBlock:()=>k,Enum:()=>G,Field:()=>H,Func:()=>J,FuncInvocation:()=>R,Method:()=>U,MethodInvocation:()=>L,Parameter:()=>q,Struct:()=>z,Type:()=>te,TypeInstantiation:()=>I,TypeReference:()=>T,Writer:()=>V,codeblock:()=>wr,enum_:()=>dr,field:()=>yr,func:()=>xr,invokeFunc:()=>gr,invokeMethod:()=>Tr,method:()=>Ar,parameter:()=>Er,struct:()=>vr,typeReference:()=>Ir});u();f();function wr(r){return new k(r)}function dr(r){return new G(r)}function yr(r){return new H(r)}function xr(r){return new J(r)}function gr(r){return new R(r)}function Tr(r){return new L(r)}function Ar(r){return new U(r)}function Er(r){return new q(r)}function vr(r){return new z(r)}function Ir(r){return new T(r)}var ge=class{constructor({context:t}){c(this,"context");this.context=t}getFilePropertyInfo({body:t,value:e}){var o;let n={fileFields:[],bodyPropertyFields:[]},i=(o=this.context.getRecord(e))!=null?o:{};for(let s of t.properties)switch(s.type){case"file":n.fileFields.push({name:this.context.getTypeName(s.name),value:this.getSingleFileProperty({property:s,record:i})});break;case"fileArray":n.fileFields.push({name:this.context.getTypeName(s.name),value:this.getArrayFileProperty({property:s,record:i})});break;case"bodyProperty":n.bodyPropertyFields.push({name:this.context.getTypeName(s.name.name),value:this.getBodyProperty({property:s,record:i})});break;default:O(s)}return n}getSingleFileProperty({property:t,record:e}){let n=this.context.getSingleFileValue({property:t,record:e});return n==null?_.TypeInstantiation.nop():_.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(n))}getArrayFileProperty({property:t,record:e}){let n=this.context.getFileArrayValues({property:t,record:e});return n==null?_.TypeInstantiation.nop():_.TypeInstantiation.slice({valueType:_.Type.reference(this.context.getIoReaderTypeReference()),values:n.map(i=>_.TypeInstantiation.reference(this.context.getNewStringsReaderFunctionInvocation(i)))})}getBodyProperty({property:t,record:e}){let n=e[t.name.wireValue];return n==null?_.TypeInstantiation.nop():this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:n})}};0&&(module.exports={FilePropertyMapper});
|
|
20
20
|
/*! Bundled license information:
|