export type Method = string | MethodMap ; export type MethodMap = { [ key ] : Method ; } ; export type AliasMap = { [ key ] : string ; } ; export function renderIndentation ( indentation ) { return Array ( indentation ) . fill ( "  " ) . join ( "" ) ; } export type MethodFormatter = ( base : string , method : string , map : MethodMap , aliases ? : AliasMap ) => string ; export const CRDApiCallFormatter = ( base , method , map , aliases ) => `crdApiCallMethod<defs["${ map [ method ] }"]>("${ map [ method ] }", "${ aliases ! [ map [ method ] as string ] }")` ; export const CRDApiTypeFormatter = ( base , method , map , aliases ) => `CRDApiCallMethod<defs["${ map [ method ] }"]>` ; export const DefinitionsApiCallFormatter = ( base , method , map , aliases ) => `apiCallMethod<defs["${ map [ method ] }"]>("${ map [ method ] }")` ; export const DefinitionsApiTypeFormatter = ( base , method , map , aliases ) => `ApiCallMethod<defs["${ map [ method ] }"]>` ; export function renderMethodMap ( base , formatter , map , aliases ? , indents = 0 ) { const indentation = renderIndentation ( indents + 1 ) ; let text = `${ renderIndentation ( indents ) }"${ base }": {\n` ; const methods = Object . keys ( map ) ; for ( let method of methods ) { if ( typeof map [ method ] == "string" ) { text += `${ indentation }"${ method }": ${ formatter ( base , method , map , aliases ) },\n` ; } else { text += `${ renderMethodMap ( method , formatter , map [ method ] as MethodMap , aliases , indents + 1 ) }\n` ; } } text += `${ renderIndentation ( indents ) }},` ; return text ; }