@fern-api/go-dynamic-snippets 0.0.7 → 0.0.8

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.
Files changed (63) hide show
  1. package/cjs/DiscriminatedUnionTypeInstance.cjs +1 -0
  2. package/cjs/DiscriminatedUnionTypeInstance.d.cts +12 -0
  3. package/cjs/DynamicSnippetsGenerator.cjs +19 -0
  4. package/cjs/DynamicSnippetsGenerator.d.cts +20 -0
  5. package/cjs/DynamicSnippetsGeneratorContext-DuDerGxa.d.cts +143 -0
  6. package/cjs/EndpointSnippetGenerator.cjs +19 -0
  7. package/cjs/EndpointSnippetGenerator.d.cts +52 -0
  8. package/cjs/Result.cjs +1 -0
  9. package/cjs/Result.d.cts +23 -0
  10. package/cjs/Scope.cjs +1 -0
  11. package/cjs/Scope.d.cts +9 -0
  12. package/cjs/TypeInstance.cjs +1 -0
  13. package/cjs/TypeInstance.d.cts +15 -0
  14. package/cjs/context/DynamicSnippetsGeneratorContext.cjs +19 -0
  15. package/cjs/context/DynamicSnippetsGeneratorContext.d.cts +7 -0
  16. package/cjs/context/DynamicTypeInstantiationMapper.cjs +19 -0
  17. package/cjs/context/DynamicTypeInstantiationMapper.d.cts +7 -0
  18. package/cjs/context/DynamicTypeMapper.cjs +19 -0
  19. package/cjs/context/DynamicTypeMapper.d.cts +7 -0
  20. package/cjs/context/ErrorReporter.cjs +1 -0
  21. package/cjs/context/ErrorReporter.d.cts +39 -0
  22. package/cjs/context/FilePropertyMapper.cjs +19 -0
  23. package/cjs/context/FilePropertyMapper.d.cts +7 -0
  24. package/cjs/index.cjs +22 -0
  25. package/{index.d.ts → cjs/index.d.cts} +1 -1
  26. package/esm/DiscriminatedUnionTypeInstance.d.ts +12 -0
  27. package/esm/DiscriminatedUnionTypeInstance.js +0 -0
  28. package/esm/DynamicSnippetsGenerator.d.ts +20 -0
  29. package/esm/DynamicSnippetsGenerator.js +1 -0
  30. package/esm/DynamicSnippetsGeneratorContext-DKWsHJSo.d.ts +143 -0
  31. package/esm/EndpointSnippetGenerator.d.ts +52 -0
  32. package/esm/EndpointSnippetGenerator.js +1 -0
  33. package/esm/Result.d.ts +23 -0
  34. package/esm/Result.js +1 -0
  35. package/esm/Scope.d.ts +9 -0
  36. package/esm/Scope.js +1 -0
  37. package/esm/TypeInstance.d.ts +15 -0
  38. package/esm/TypeInstance.js +0 -0
  39. package/esm/chunk-4PKXKUYU.js +1 -0
  40. package/esm/chunk-5XUC5IOB.js +1 -0
  41. package/esm/chunk-6JCPJA27.js +1 -0
  42. package/esm/chunk-BC35GX6S.js +1 -0
  43. package/esm/chunk-COBOWL3P.js +1 -0
  44. package/esm/chunk-IQODEXPX.js +1 -0
  45. package/esm/chunk-KJOW5AZT.js +1 -0
  46. package/esm/chunk-UVYC4FWB.js +1 -0
  47. package/esm/chunk-VAYOWHUI.js +19 -0
  48. package/esm/chunk-ZQRLKIRW.js +1 -0
  49. package/esm/chunk-ZYGZ4VN4.js +1 -0
  50. package/esm/context/DynamicSnippetsGeneratorContext.d.ts +7 -0
  51. package/esm/context/DynamicSnippetsGeneratorContext.js +1 -0
  52. package/esm/context/DynamicTypeInstantiationMapper.d.ts +7 -0
  53. package/esm/context/DynamicTypeInstantiationMapper.js +1 -0
  54. package/esm/context/DynamicTypeMapper.d.ts +7 -0
  55. package/esm/context/DynamicTypeMapper.js +1 -0
  56. package/esm/context/ErrorReporter.d.ts +39 -0
  57. package/esm/context/ErrorReporter.js +1 -0
  58. package/esm/context/FilePropertyMapper.d.ts +7 -0
  59. package/esm/context/FilePropertyMapper.js +1 -0
  60. package/esm/index.d.ts +8 -0
  61. package/esm/index.js +4 -0
  62. package/package.json +18 -6
  63. package/index.cjs +0 -22
@@ -0,0 +1,143 @@
1
+ import { AbstractDynamicSnippetsGeneratorContext, FernGeneratorExec } from '@fern-api/browser-compatible-base-generator';
2
+ import { go, BaseGoCustomConfigSchema } from '@fern-api/go-ast';
3
+ import { dynamic, TypeId, Name, FernFilepath } from '@fern-fern/ir-sdk/api';
4
+ import { TypeInstance } from './TypeInstance.cjs';
5
+ import { DiscriminatedUnionTypeInstance } from './DiscriminatedUnionTypeInstance.cjs';
6
+ import { ErrorReporter } from './context/ErrorReporter.cjs';
7
+
8
+ declare namespace DynamicTypeMapper {
9
+ interface Args {
10
+ typeReference: dynamic.TypeReference;
11
+ }
12
+ }
13
+ declare class DynamicTypeMapper {
14
+ private context;
15
+ constructor({ context }: {
16
+ context: DynamicSnippetsGeneratorContext;
17
+ });
18
+ convert(args: DynamicTypeMapper.Args): go.Type;
19
+ private convertLiteral;
20
+ private convertNamed;
21
+ private convertUnknown;
22
+ private convertPrimitive;
23
+ }
24
+
25
+ declare namespace DynamicTypeInstantiationMapper {
26
+ interface Args {
27
+ typeReference: dynamic.TypeReference;
28
+ value: unknown;
29
+ as?: ConvertedAs;
30
+ }
31
+ type ConvertedAs = "key";
32
+ }
33
+ declare class DynamicTypeInstantiationMapper {
34
+ private context;
35
+ constructor({ context }: {
36
+ context: DynamicSnippetsGeneratorContext;
37
+ });
38
+ convert(args: DynamicTypeInstantiationMapper.Args): go.TypeInstantiation;
39
+ private convertList;
40
+ private convertMap;
41
+ private convertNamed;
42
+ private convertDiscriminatedUnion;
43
+ private getBaseFields;
44
+ private convertObject;
45
+ private convertEnum;
46
+ private getEnumValueName;
47
+ private convertUndicriminatedUnion;
48
+ private findMatchingUndiscriminatedUnionType;
49
+ private getUndiscriminatedUnionFieldName;
50
+ private getUndiscriminatedUnionFieldNameForList;
51
+ private getUndiscriminatedUnionFieldNameForMap;
52
+ private getUndiscriminatedUnionFieldNameForOptional;
53
+ private getUndiscriminatedUnionFieldNameForSet;
54
+ private getUndiscriminatedUnionFieldNameForLiteral;
55
+ private getUndiscriminatedUnionFieldNameForPrimitive;
56
+ private convertUnknown;
57
+ private convertPrimitive;
58
+ private getValueAsNumber;
59
+ private getValueAsBoolean;
60
+ private getValueAsString;
61
+ private newTypeMismatchError;
62
+ }
63
+
64
+ interface FilePropertyInfo {
65
+ fileFields: go.StructField[];
66
+ bodyPropertyFields: go.StructField[];
67
+ }
68
+ declare class FilePropertyMapper {
69
+ private context;
70
+ constructor({ context }: {
71
+ context: DynamicSnippetsGeneratorContext;
72
+ });
73
+ getFilePropertyInfo({ body, value }: {
74
+ body: dynamic.FileUploadRequestBody;
75
+ value: unknown;
76
+ }): FilePropertyInfo;
77
+ private getSingleFileProperty;
78
+ private getArrayFileProperty;
79
+ private getBodyProperty;
80
+ }
81
+
82
+ declare class DynamicSnippetsGeneratorContext extends AbstractDynamicSnippetsGeneratorContext<dynamic.DynamicIntermediateRepresentation> {
83
+ customConfig: BaseGoCustomConfigSchema | undefined;
84
+ errors: ErrorReporter;
85
+ dynamicTypeMapper: DynamicTypeMapper;
86
+ dynamicTypeInstantiationMapper: DynamicTypeInstantiationMapper;
87
+ filePropertyMapper: FilePropertyMapper;
88
+ rootImportPath: string;
89
+ private httpEndpointReferenceParser;
90
+ constructor({ ir, config }: {
91
+ ir: dynamic.DynamicIntermediateRepresentation;
92
+ config: FernGeneratorExec.GeneratorConfig;
93
+ });
94
+ clone(): DynamicSnippetsGeneratorContext;
95
+ associateQueryParametersByWireValue({ parameters, values }: {
96
+ parameters: dynamic.NamedParameter[];
97
+ values: dynamic.Values;
98
+ }): TypeInstance[];
99
+ associateByWireValue({ parameters, values, ignoreMissingParameters }: {
100
+ parameters: dynamic.NamedParameter[];
101
+ values: dynamic.Values;
102
+ ignoreMissingParameters?: boolean;
103
+ }): TypeInstance[];
104
+ isFileUploadRequestBody(body: dynamic.InlinedRequestBody): body is dynamic.InlinedRequestBody.FileUpload;
105
+ needsRequestParameter({ request }: {
106
+ request: dynamic.InlinedRequest;
107
+ }): boolean;
108
+ includePathParametersInWrappedRequest({ request }: {
109
+ request: dynamic.InlinedRequest;
110
+ }): boolean;
111
+ private includeRequestBodyInWrappedRequest;
112
+ private includeFileUploadBodyInWrappedRequest;
113
+ private fileUploadHasBodyProperties;
114
+ private fileUploadHasFileProperties;
115
+ getRecord(value: unknown): Record<string, unknown> | undefined;
116
+ resolveNamedType({ typeId }: {
117
+ typeId: TypeId;
118
+ }): dynamic.NamedType | undefined;
119
+ resolveDiscriminatedUnionTypeInstance({ discriminatedUnion, value }: {
120
+ discriminatedUnion: dynamic.DiscriminatedUnionType;
121
+ value: unknown;
122
+ }): DiscriminatedUnionTypeInstance | undefined;
123
+ getMethodName(name: Name): string;
124
+ getTypeName(name: Name): string;
125
+ getImportPath(fernFilepath: FernFilepath): string;
126
+ getContextTypeReference(): go.TypeReference;
127
+ getContextTodoFunctionInvocation(): go.FuncInvocation;
128
+ getIoReaderTypeReference(): go.TypeReference;
129
+ getNewStringsReaderFunctionInvocation(s: string): go.FuncInvocation;
130
+ getClientConstructorName(): string;
131
+ getClientImportPath(): string;
132
+ getOptionImportPath(): string;
133
+ resolveEndpointOrThrow(rawEndpoint: string): dynamic.Endpoint[];
134
+ resolveEndpointLocationOrThrow(location: dynamic.EndpointLocation): dynamic.Endpoint[];
135
+ getGoTypeReferenceFromDeclaration({ declaration }: {
136
+ declaration: dynamic.Declaration;
137
+ }): go.TypeReference;
138
+ newParameterNotRecognizedError(parameterName: string): Error;
139
+ private isListTypeReference;
140
+ private parsedEndpointMatches;
141
+ }
142
+
143
+ export { DynamicSnippetsGeneratorContext as D, type FilePropertyInfo as F, DynamicTypeMapper as a, DynamicTypeInstantiationMapper as b, FilePropertyMapper as c };
@@ -0,0 +1,19 @@
1
+ "use strict";var L=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var ee=(n,t,e)=>t in n?L(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var H=(n,t)=>{for(var e in t)L(n,e,{get:t[e],enumerable:!0})},te=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Z(t))!X.call(n,i)&&i!==e&&L(n,i,{get:()=>t[i],enumerable:!(r=z(t,i))||r.enumerable});return n};var re=n=>te(L({},"__esModule",{value:!0}),n);var o=(n,t,e)=>ee(n,typeof t!="symbol"?t+"":t,e);var ke={};H(ke,{EndpointSnippetGenerator:()=>_});module.exports=re(ke);function k(n){throw new Error("Unexpected value: "+JSON.stringify(n))}var w=class{};var x=class extends w{constructor(e){super();o(this,"value");this.value=e}write(e){typeof this.value=="string"?e.write(this.value):this.value(e)}};var ne=4,F=class{constructor(){o(this,"buffer","");o(this,"indentLevel",0);o(this,"hasWrittenAnything",!1);o(this,"lastCharacterIsNewline",!1)}write(t){let e=t.length>0&&t.endsWith(`
2
+ `),r=e?t.substring(0,t.length-1):t,i=this.getIndentString(),s=r.replaceAll(`
3
+ `,`
4
+ ${i}`);this.isAtStartOfLine()&&(s=i+s),e&&(s+=`
5
+ `),this.writeInternal(s)}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 x(t).write(this),this.write(";"),this.writeNewLineIfLastLineNot()}controlFlow(t,e){new x(t).write(this),this.write(" ("),this.writeNode(e),this.write(") {"),this.writeNewLineIfLastLineNot(),this.indent()}endControlFlow(){this.dedent(),this.writeLine("}")}openBlock(t,e="{",r,i="}"){let s=t.filter(c=>c!==void 0).join(" ");s?this.write(`${s} ${e!=null?e:""}`):this.write(e!=null?e:"");try{this.indent(),r(),this.dedent()}finally{this.write(i!=null?i:"")}}writeLine(t=""){this.write(t),this.writeNewLineIfLastLineNot()}newLine(){this.writeInternal(`
6
+ `)}writeNewLineIfLastLineNot(){this.lastCharacterIsNewline||this.writeInternal(`
7
+ `)}indent(){this.indentLevel++}dedent(){this.indentLevel--}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*ne)}};var D=class{},E=class extends D{async format(t){return t}formatSync(t){return t}};function M(n){return(n==null?void 0:n.name)!=null}function $(n,t){var r,i;let e=(r=n.split("/").pop())!=null?r:n;return t!=null&&t.stripExtension&&(i=e.split(".")[0])!=null?i:e}var ie=/[^0-9a-zA-Z_]/g,v=class extends F{constructor({packageName:e,rootImportPath:r,importPath:i,customConfig:s,formatter:c}){super();o(this,"packageName");o(this,"rootImportPath");o(this,"importPath");o(this,"customConfig");o(this,"formatter");o(this,"imports",{});this.packageName=e,this.rootImportPath=r,this.importPath=i,this.customConfig=s,this.formatter=c!=null?c:new E}addImport(e){let r=this.imports[e];if(r!=null)return r;let i=this.getValidAlias($(e));for(;i in this.imports;)i="_"+i;return this.imports[e]=i,i}getValidAlias(e){let r=e.split("-");return r[0]==null?e:r[0].replace(ie,"")}};var B=class extends v{constructor({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s}){super({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s})}async toString(){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}toStringSync(){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
+ ${t}`)}return t}getContent(){let t=`package ${this.packageName}
11
+
12
+ `,e=this.stringifyImports();return e.length>0?`${t}${e}
13
+
14
+ ${this.buffer}`:t+this.buffer}stringifyImports(){let t=Object.entries(this.imports).filter(([e,r])=>e!==this.importPath).map(([e,r])=>` ${r} "${e}"`).join(`
15
+ `);return t?`import (
16
+ ${t}
17
+ )`:""}};var p=class extends w{async toString({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s}){let c=new B({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s});return this.write(c),c.toString()}toStringSync({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s}){let c=new B({packageName:t,rootImportPath:e,importPath:r,customConfig:i,formatter:s});return this.write(c),c.toStringSync()}};var l=class extends p{constructor(e){super();o(this,"arg");this.arg=e}write(e){return new x(this.arg).write(e)}};var h=class extends p{constructor({docs:e}={}){super();o(this,"docs");this.docs=e}write(e){this.docs!=null&&this.docs.split(`
18
+ `).forEach(r=>{e.writeLine(`// ${r}`)})}};var N=class extends p{constructor({name:e,docs:r}){super();o(this,"name");o(this,"docs");o(this,"members",[]);this.name=e,this.docs=r}addMember(e){this.members.push(e)}write(e){e.writeNode(new h({docs:this.docs})),e.write(`type ${this.name} string`)}};var A=class extends p{constructor({name:e,type:r,docs:i}){super();o(this,"name");o(this,"type");o(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new h({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};var y=class extends p{constructor({name:e,parameters:r,return_:i,body:s,docs:c,typeReference:T}){super();o(this,"name");o(this,"parameters");o(this,"return_");o(this,"body");o(this,"docs");o(this,"typeReference");this.name=e,this.parameters=r,this.return_=i,this.body=s,this.docs=c,this.typeReference=T}write(e){var r;if(e.writeNode(new h({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,s)=>{s>0&&e.write(", "),e.writeNode(i)}),e.write(")")),e.writeLine(" {"),e.indent(),(r=this.body)==null||r.write(e),e.dedent(),e.writeNewLineIfLastLineNot(),e.writeLine("}")}writeReceiver({writer:e,typeReference:r}){e.write(`(${this.getReceiverName(r.name)} `),r.write(e),e.write(") ")}getReceiverName(e){return e.charAt(0).toLowerCase()}};var P=class extends p{constructor({name:e,parameters:r,return_:i,body:s,docs:c}){super();o(this,"func");this.func=new y({name:e,parameters:r,return_:i,body:s,docs:c})}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)}};var u=class extends p{constructor({name:e,importPath:r}){super();o(this,"name");o(this,"importPath");this.name=e,this.importPath=r}write(e){if(e.importPath===this.importPath){e.write(this.name);return}let r=e.addImport(this.importPath);e.write(`${r}.${this.name}`)}};var f=class extends p{constructor({method:e,arguments_:r,on:i}){super();o(this,"on");o(this,"method");o(this,"arguments_");this.on=i,this.method=e,this.arguments_=r}write(e){this.on.write(e),e.write("."),e.write(this.method),q({writer:e,arguments_:this.arguments_})}};var oe=new Set(["bool","date","dateTime","float64","int","int64","string","uuid"]),U=new Set(["any","bytes","map","slice"]),m=class n extends p{constructor(e){super();o(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(pe({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
+ `)?`\`${this.internalType.value}\``:`"${this.internalType.value}"`);break;case"struct":this.writeStruct({writer:e,struct:this.internalType});break;case"uuid":e.writeNode(ce({value:this.internalType.value}));break;default:k(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:r,entries:i}){return new this({type:"map",keyType:e,valueType:r,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:r}){return new this({type:"slice",valueType:e,values:r})}static string(e){return new this({type:"string",value:e})}static struct({typeReference:e,fields:r}){return new this({type:"struct",typeReference:e,fields:r})}static structPointer({typeReference:e,fields:r}){return new this({type:"optional",value:new this({type:"struct",typeReference:e,fields:r})})}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:r}){switch(typeof r){case"boolean":e.write(r.toString());return;case"string":e.write(r.includes('"')?`\`${r}\``:`"${r}"`);return;case"number":e.write(r.toString());return;case"object":if(r==null){e.write("nil");return}if(Array.isArray(r)){this.writeAnyArray({writer:e,value:r});return}this.writeAnyObject({writer:e,value:r});return;default:throw new Error(`Internal error; unsupported unknown type: ${typeof r}`)}}writeAnyArray({writer:e,value:r}){if(e.write("[]interface{}"),r.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let i of r)e.writeNode(n.any(i)),e.writeLine(",");e.dedent(),e.write("}")}writeAnyObject({writer:e,value:r}){e.write("map[string]interface{}");let i=Object.entries(r);if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let[s,c]of i)e.write(`"${s}": `),e.writeNode(n.any(c)),e.writeLine(",");e.dedent(),e.write("}")}writeMap({writer:e,map:r}){e.write("map["),e.writeNode(r.keyType),e.write("]"),e.writeNode(r.valueType);let i=ue({entries:r.entries});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let s of i)s.key.write(e),e.write(": "),s.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeOptional({writer:e,type:r}){if(oe.has(r.internalType.type)){e.writeNode(se({writer:e,type:r}));return}if(U.has(r.internalType.type)){r.write(e);return}if(r.internalType.type==="enum"){e.writeNode(new f({on:r.internalType.typeReference,method:"Ptr",arguments_:[]}));return}e.write("&"),r.write(e)}static isAlreadyOptional(e){return e.internalType.type==="optional"||U.has(e.internalType.type)}writeSlice({writer:e,slice:r}){e.write("[]"),e.writeNode(r.valueType);let i=me({values:r.values});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let s of i)s.write(e),e.writeLine(",");e.dedent(),e.write("}")}writeStruct({writer:e,struct:r}){e.writeNode(r.typeReference);let i=he({fields:r.fields});if(i.length===0){e.write("{}");return}e.writeLine("{"),e.indent();for(let s of i)e.write(`${s.name}: `),s.value.write(e),e.writeLine(",");e.dedent(),e.write("}")}};function se({writer:n,type:t}){return new d({func:new u({name:ae({type:t}),importPath:n.rootImportPath}),arguments_:[t]})}function ae({type:n}){switch(n.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 pe({writer:n,type:t}){let e=t instanceof Date?"MustParseDate":"MustParseDateTime";return new d({func:new u({name:e,importPath:n.rootImportPath}),arguments_:[new l(`"${t.value}"`)]})}function ce({value:n}){return new d({func:new u({name:"MustParse",importPath:"github.com/google/uuid"}),arguments_:[new l(`"${n}"`)]})}function ue({entries:n}){return n.filter(t=>!m.isNop(t.key)&&!m.isNop(t.value))}function he({fields:n}){return n.filter(t=>!m.isNop(t.value))}function me({values:n}){return n.filter(t=>!m.isNop(t))}function q({writer:n,arguments_:t}){let e=le(t);if(e.length===0){n.write("()");return}n.writeLine("("),n.indent();for(let r of e)de({writer:n,argument:r}),n.writeLine(",");n.dedent(),n.write(")")}function de({writer:n,argument:t}){M(t)?t.assignment.write(n):t.write(n)}function le(n){return n.filter(t=>!(t instanceof m&&m.isNop(t)))}var d=class extends p{constructor({func:e,arguments_:r}){super();o(this,"func");o(this,"arguments_");this.func=e,this.arguments_=r}write(e){e.writeNode(this.func),q({writer:e,arguments_:this.arguments_})}};var S=class extends p{constructor({name:e,type:r,docs:i}){super();o(this,"name");o(this,"type");o(this,"docs");this.name=e,this.type=r,this.docs=i}write(e){e.writeNode(new h({docs:this.docs})),e.write(`${this.name} `),this.type.write(e)}};var b=class extends p{constructor({name:e,importPath:r,docs:i}){super();o(this,"name");o(this,"importPath");o(this,"docs");o(this,"fields",[]);o(this,"methods",[]);this.name=e,this.importPath=r,this.docs=i}addField(e){this.fields.push(e)}addMethod(e){this.methods.push(e)}write(e){if(e.writeNode(new h({docs:this.docs})),e.write(`type ${this.name} struct {`),this.fields.length>0)e.writeLine("}");else{e.newLine(),e.indent();for(let r of this.fields)e.writeNode(r),e.newLine();e.dedent(),e.writeLine("}")}(this.constructor!=null||this.methods.length>0)&&e.newLine();for(let r of this.methods)e.writeNode(r),e.newLine()}};var ye=new Set(["any","bytes","map","slice"]),C=class n extends p{constructor(e){super();o(this,"internalType");this.internalType=e}write(e,{comment:r}={}){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(fe);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(ge);break;default:k(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,r){return new this({type:"map",keyType:e,valueType:r})}static optional(e){return this.isAlreadyOptional(e)?e:new this({type:"optional",value:e})}static pointer(e){return n.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"||ye.has(e.internalType.type)}},fe=new u({importPath:"time",name:"Time"}),ge=new u({importPath:"github.com/google/uuid",name:"UUID"});var a={};H(a,{AstNode:()=>p,CodeBlock:()=>l,Enum:()=>N,Field:()=>A,Func:()=>P,FuncInvocation:()=>d,Method:()=>y,MethodInvocation:()=>f,Parameter:()=>S,Struct:()=>b,Type:()=>C,TypeInstantiation:()=>m,TypeReference:()=>u,Writer:()=>v,codeblock:()=>xe,enum_:()=>we,field:()=>ve,func:()=>Ne,invokeFunc:()=>Ae,invokeMethod:()=>Pe,method:()=>Se,parameter:()=>be,struct:()=>Te,typeReference:()=>Ie});function xe(n){return new l(n)}function we(n){return new N(n)}function ve(n){return new A(n)}function Ne(n){return new P(n)}function Ae(n){return new d(n)}function Pe(n){return new f(n)}function Se(n){return new y(n)}function be(n){return new S(n)}function Te(n){return new b(n)}function Ie(n){return new u(n)}var I={Critical:"CRITICAL",Warning:"WARNING"};var g={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};var j="example",Y="fern",Re="do",J="client",_=class{constructor({context:t,formatter:e}){o(this,"context");o(this,"formatter");this.context=t,this.formatter=e}async generateSnippet({endpoint:t,request:e}){var i;return await this.buildCodeBlock({endpoint:t,snippet:e}).toString({packageName:j,importPath:Y,rootImportPath:this.context.rootImportPath,customConfig:(i=this.context.customConfig)!=null?i:{},formatter:this.formatter})}generateSnippetSync({endpoint:t,request:e}){var i;return this.buildCodeBlock({endpoint:t,snippet:e}).toStringSync({packageName:j,importPath:Y,rootImportPath:this.context.rootImportPath,customConfig:(i=this.context.customConfig)!=null?i:{},formatter:this.formatter})}buildCodeBlock({endpoint:t,snippet:e}){return a.func({name:Re,parameters:[],return_:[],body:a.codeblock(r=>{r.writeNode(this.constructClient({endpoint:t,snippet:e})),r.writeLine(),r.writeNode(this.callMethod({endpoint:t,snippet:e}))})})}constructClient({endpoint:t,snippet:e}){return a.codeblock(r=>{r.write(`${J} := `),r.writeNode(this.getRootClientFuncInvocation(this.getConstructorArgs({endpoint:t,snippet:e})))})}callMethod({endpoint:t,snippet:e}){return a.invokeMethod({on:a.codeblock(J),method:this.getMethod({endpoint:t}),arguments_:[this.context.getContextTodoFunctionInvocation(),...this.getMethodArgs({endpoint:t,snippet:e})]})}getConstructorArgs({endpoint:t,snippet:e}){let r=[];return t.auth!=null&&(e.auth!=null?r.push(this.getConstructorAuthArg({auth:t.auth,values:e.auth})):this.context.errors.add({severity:I.Warning,message:`Auth with ${t.auth.type} configuration is required for this endpoint`})),this.context.errors.scope(g.Headers),this.context.ir.headers!=null&&e.headers!=null&&r.push(...this.getConstructorHeaderArgs({headers:this.context.ir.headers,values:e.headers})),this.context.errors.unscope(),r}getConstructorAuthArg({auth:t,values:e}){switch(t.type){case"basic":return e.type!=="basic"?(this.context.errors.add({severity:I.Critical,message:this.newAuthMismatchError({auth:t,values:e}).message}),a.TypeInstantiation.nop()):this.getConstructorBasicAuthArg({auth:t,values:e});case"bearer":return e.type!=="bearer"?(this.context.errors.add({severity:I.Critical,message:this.newAuthMismatchError({auth:t,values:e}).message}),a.TypeInstantiation.nop()):this.getConstructorBearerAuthArg({auth:t,values:e});case"header":return e.type!=="header"?(this.context.errors.add({severity:I.Critical,message:this.newAuthMismatchError({auth:t,values:e}).message}),a.TypeInstantiation.nop()):this.getConstructorHeaderAuthArg({auth:t,values:e})}}getConstructorBasicAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:"WithBasicAuth",importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.username),a.TypeInstantiation.string(e.password)]}))})}getConstructorBearerAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.token.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[a.TypeInstantiation.string(e.token)]}))})}getConstructorHeaderAuthArg({auth:t,values:e}){return a.codeblock(r=>{r.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.header.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.header.typeReference,value:e.value})]}))})}getConstructorHeaderArgs({headers:t,values:e}){let r=[];for(let i of t){let s=this.getConstructorHeaderArg({header:i,value:e.value});s!=null&&r.push(s)}return r}getConstructorHeaderArg({header:t,value:e}){let r=this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.typeReference,value:e});if(!a.TypeInstantiation.isNop(r))return a.codeblock(i=>{i.writeNode(a.invokeFunc({func:a.typeReference({name:`With${t.name.name.pascalCase.unsafeName}`,importPath:this.context.getOptionImportPath()}),arguments_:[r]}))})}getMethodArgs({endpoint:t,snippet:e}){switch(t.request.type){case"inlined":return this.getMethodArgsForInlinedRequest({request:t.request,snippet:e});case"body":return this.getMethodArgsForBodyRequest({request:t.request,snippet:e})}}getMethodArgsForBodyRequest({request:t,snippet:e}){let r=[];if(this.context.errors.scope(g.PathParameters),t.pathParameters!=null){let i=this.getPathParameters({namedParameters:t.pathParameters,snippet:e});r.push(...i.map(s=>s.value))}return this.context.errors.unscope(),this.context.errors.scope(g.RequestBody),t.body!=null&&r.push(this.getBodyRequestArg({body:t.body,value:e.requestBody})),this.context.errors.unscope(),r}getBodyRequestArg({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e})}}getBytesBodyRequestArg({value:t}){return typeof t!="string"?(this.context.errors.add({severity:I.Critical,message:`Expected bytes value to be a string, got ${typeof t}`}),a.TypeInstantiation.nop()):a.TypeInstantiation.bytes(t)}getMethodArgsForInlinedRequest({request:t,snippet:e}){var c;let r=[];this.context.errors.scope(g.PathParameters);let i=[];t.pathParameters!=null&&i.push(...this.getPathParameters({namedParameters:t.pathParameters,snippet:e})),this.context.errors.unscope(),this.context.errors.scope(g.RequestBody);let s=this.getFilePropertyInfo({request:t,snippet:e});return this.context.errors.unscope(),this.context.includePathParametersInWrappedRequest({request:t})||r.push(...i.map(T=>T.value)),(c=this.context.customConfig)!=null&&c.inlineFileProperties||r.push(...s.fileFields.map(T=>T.value)),this.context.needsRequestParameter({request:t})&&r.push(this.getInlinedRequestArg({request:t,snippet:e,pathParameterFields:this.context.includePathParametersInWrappedRequest({request:t})?i:[],filePropertyInfo:s})),r}getFilePropertyInfo({request:t,snippet:e}){return t.body==null||!this.context.isFileUploadRequestBody(t.body)?{fileFields:[],bodyPropertyFields:[]}:this.context.filePropertyMapper.getFilePropertyInfo({body:t.body,value:e.requestBody})}getInlinedRequestArg({request:t,snippet:e,pathParameterFields:r,filePropertyInfo:i}){var O,W,V,G;this.context.errors.scope(g.QueryParameters);let c=this.context.associateQueryParametersByWireValue({parameters:(O=t.queryParameters)!=null?O:[],values:(W=e.queryParameters)!=null?W:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(g.Headers);let K=this.context.associateByWireValue({parameters:(V=t.headers)!=null?V:[],values:(G=e.headers)!=null?G:{}}).map(R=>({name:R.name.name.pascalCase.unsafeName,value:this.context.dynamicTypeInstantiationMapper.convert(R)}));this.context.errors.unscope(),this.context.errors.scope(g.RequestBody);let Q=t.body!=null?this.getInlinedRequestBodyStructFields({body:t.body,value:e.requestBody,filePropertyInfo:i}):[];return this.context.errors.unscope(),a.TypeInstantiation.structPointer({typeReference:a.typeReference({name:this.context.getMethodName(t.declaration.name),importPath:this.context.getImportPath(t.declaration.fernFilepath)}),fields:[...r,...c,...K,...Q]})}getInlinedRequestBodyStructFields({body:t,value:e,filePropertyInfo:r}){switch(t.type){case"properties":return this.getInlinedRequestBodyPropertyStructFields({parameters:t.value,value:e});case"referenced":return[this.getReferencedRequestBodyPropertyStructField({body:t,value:e})];case"fileUpload":return this.getFileUploadRequestBodyStructFields({filePropertyInfo:r})}}getFileUploadRequestBodyStructFields({filePropertyInfo:t}){var e;return(e=this.context.customConfig)!=null&&e.inlineFileProperties?[...t.fileFields,...t.bodyPropertyFields]:t.bodyPropertyFields}getReferencedRequestBodyPropertyStructField({body:t,value:e}){return{name:this.context.getTypeName(t.bodyKey),value:this.getReferencedRequestBodyPropertyTypeInstantiation({body:t.bodyType,value:e})}}getReferencedRequestBodyPropertyTypeInstantiation({body:t,value:e}){switch(t.type){case"bytes":return this.getBytesBodyRequestArg({value:e});case"typeReference":return this.context.dynamicTypeInstantiationMapper.convert({typeReference:t.value,value:e})}}getInlinedRequestBodyPropertyStructFields({parameters:t,value:e}){var s;let r=[],i=this.context.associateByWireValue({parameters:t,values:(s=this.context.getRecord(e))!=null?s:{}});for(let c of i)r.push({name:this.context.getTypeName(c.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(c)});return r}getPathParameters({namedParameters:t,snippet:e}){var s;let r=[],i=this.context.associateByWireValue({parameters:t,values:(s=e.pathParameters)!=null?s:{}});for(let c of i)r.push({name:this.context.getTypeName(c.name.name),value:this.context.dynamicTypeInstantiationMapper.convert(c)});return r}getMethod({endpoint:t}){return t.declaration.fernFilepath.allParts.length>0?`${t.declaration.fernFilepath.allParts.map(e=>this.context.getMethodName(e)).join(".")}.${this.context.getMethodName(t.declaration.name)}`:this.context.getMethodName(t.declaration.name)}getRootClientFuncInvocation(t){return a.invokeFunc({func:a.typeReference({name:this.context.getClientConstructorName(),importPath:this.context.getClientImportPath()}),arguments_:t})}newAuthMismatchError({auth:t,values:e}){return new Error(`Expected auth type ${t.type}, got ${e.type}`)}};0&&(module.exports={EndpointSnippetGenerator});
@@ -0,0 +1,52 @@
1
+ import { AbstractFormatter } from '@fern-api/browser-compatible-base-generator';
2
+ import { D as DynamicSnippetsGeneratorContext } from './DynamicSnippetsGeneratorContext-DuDerGxa.cjs';
3
+ import { dynamic } from '@fern-fern/ir-sdk/api';
4
+ import '@fern-api/go-ast';
5
+ import './TypeInstance.cjs';
6
+ import './DiscriminatedUnionTypeInstance.cjs';
7
+ import './context/ErrorReporter.cjs';
8
+
9
+ declare class EndpointSnippetGenerator {
10
+ private context;
11
+ private formatter;
12
+ constructor({ context, formatter }: {
13
+ context: DynamicSnippetsGeneratorContext;
14
+ formatter?: AbstractFormatter;
15
+ });
16
+ generateSnippet({ endpoint, request }: {
17
+ endpoint: dynamic.Endpoint;
18
+ request: dynamic.EndpointSnippetRequest;
19
+ }): Promise<string>;
20
+ generateSnippetSync({ endpoint, request }: {
21
+ endpoint: dynamic.Endpoint;
22
+ request: dynamic.EndpointSnippetRequest;
23
+ }): string;
24
+ private buildCodeBlock;
25
+ private constructClient;
26
+ private callMethod;
27
+ private getConstructorArgs;
28
+ private getConstructorAuthArg;
29
+ private getConstructorBasicAuthArg;
30
+ private getConstructorBearerAuthArg;
31
+ private getConstructorHeaderAuthArg;
32
+ private getConstructorHeaderArgs;
33
+ private getConstructorHeaderArg;
34
+ private getMethodArgs;
35
+ private getMethodArgsForBodyRequest;
36
+ private getBodyRequestArg;
37
+ private getBytesBodyRequestArg;
38
+ private getMethodArgsForInlinedRequest;
39
+ private getFilePropertyInfo;
40
+ private getInlinedRequestArg;
41
+ private getInlinedRequestBodyStructFields;
42
+ private getFileUploadRequestBodyStructFields;
43
+ private getReferencedRequestBodyPropertyStructField;
44
+ private getReferencedRequestBodyPropertyTypeInstantiation;
45
+ private getInlinedRequestBodyPropertyStructFields;
46
+ private getPathParameters;
47
+ private getMethod;
48
+ private getRootClientFuncInvocation;
49
+ private newAuthMismatchError;
50
+ }
51
+
52
+ export { EndpointSnippetGenerator };
package/cjs/Result.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var n=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var u=(e,r,t)=>r in e?n(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var a=(e,r)=>{for(var t in r)n(e,t,{get:r[t],enumerable:!0})},l=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of c(r))!h.call(e,i)&&i!==t&&n(e,i,{get:()=>r[i],enumerable:!(s=d(r,i))||s.enumerable});return e};var m=e=>l(n({},"__esModule",{value:!0}),e);var p=(e,r,t)=>u(e,typeof r!="symbol"?r+"":r,t);var f={};a(f,{Result:()=>o});module.exports=m(f);var o=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:r,snippet:t}){(this.reporter==null||this.reporter.size()>r.errors.size())&&(this.reporter=r.errors.clone(),this.snippet=t)}getResponseOrThrow({endpoint:r}){var t;if(this.snippet!=null&&this.reporter!=null)return{snippet:this.snippet,errors:this.reporter.toDynamicSnippetErrors()};throw(t=this.err)!=null?t:new Error(`Failed to generate snippet for endpoint "${r.method} ${r.path}"`)}};0&&(module.exports={Result});
@@ -0,0 +1,23 @@
1
+ import { D as DynamicSnippetsGeneratorContext } from './DynamicSnippetsGeneratorContext-DuDerGxa.cjs';
2
+ import { ErrorReporter } from './context/ErrorReporter.cjs';
3
+ import { dynamic } from '@fern-fern/ir-sdk/api';
4
+ import '@fern-api/browser-compatible-base-generator';
5
+ import '@fern-api/go-ast';
6
+ import './TypeInstance.cjs';
7
+ import './DiscriminatedUnionTypeInstance.cjs';
8
+
9
+ declare class Result {
10
+ reporter: ErrorReporter | undefined;
11
+ snippet: string | undefined;
12
+ err: Error | undefined;
13
+ constructor();
14
+ update({ context, snippet }: {
15
+ context: DynamicSnippetsGeneratorContext;
16
+ snippet: string;
17
+ }): void;
18
+ getResponseOrThrow({ endpoint }: {
19
+ endpoint: dynamic.EndpointLocation;
20
+ }): dynamic.EndpointSnippetResponse;
21
+ }
22
+
23
+ export { Result };
package/cjs/Scope.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var a in e)o(r,a,{get:e[a],enumerable:!0})},d=(r,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of y(e))!c.call(r,t)&&t!==a&&o(r,t,{get:()=>e[t],enumerable:!(s=p(e,t))||s.enumerable});return r};var m=r=>d(o({},"__esModule",{value:!0}),r);var S={};P(S,{Scope:()=>u});module.exports=m(S);var u={PathParameters:"pathParameters",QueryParameters:"queryParameters",Headers:"headers",RequestBody:"requestBody"};0&&(module.exports={Scope});
@@ -0,0 +1,9 @@
1
+ declare const Scope: {
2
+ readonly PathParameters: "pathParameters";
3
+ readonly QueryParameters: "queryParameters";
4
+ readonly Headers: "headers";
5
+ readonly RequestBody: "requestBody";
6
+ };
7
+ declare type Scope = typeof Scope[keyof typeof Scope];
8
+
9
+ export { Scope };
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var y=(n,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of c(e))!t.call(n,a)&&a!==m&&p(n,a,{get:()=>e[a],enumerable:!(i=r(e,a))||i.enumerable});return n};var f=n=>y(p({},"__esModule",{value:!0}),n);var o={};module.exports=f(o);
@@ -0,0 +1,15 @@
1
+ import { NameAndWireValue, dynamic } from '@fern-fern/ir-sdk/api';
2
+
3
+ /**
4
+ * A type instance that can be converted into a language-specific AST node.
5
+ *
6
+ * The 'type' and 'value' are used to convert the AST node itself, and the name
7
+ * is (optionally) used within the dynamic snippet, e.g. for named fields.
8
+ */
9
+ interface TypeInstance {
10
+ name: NameAndWireValue;
11
+ typeReference: dynamic.TypeReference;
12
+ value: unknown;
13
+ }
14
+
15
+ export type { TypeInstance };