All files / src/generate/generateSDK generateSDKconfigShared.ts

40% Statements 16/40
100% Branches 0/0
0% Functions 0/3
40% Lines 16/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x               1x 1x 1x 1x 1x                                  
 
import { GenerateSdkConfig, ServiceDocObject } from '../../types/core.types'
import { camelCase } from 'topkat-utils'
import { GenericDef } from 'good-cop'
import { generateJsDoc } from './generateJsDocForSdk'
 
export const env = process.env.NODE_ENV as Env
 
export const generateSdkConfigDefault: Partial<GenerateSdkConfig> = {
    isEs6Import: false,
    processAddrInSdk(addrRaw) {
        // TODO make more generic ?? actually dao should not come there
        const addrBits = addrRaw
            .replace(/\./g, '-') // replace '.' by '-'
            .replace(/([a-z])([A-Z])/g, '$1-$2') // uncamelcaseify
            .toLowerCase()
            .split('-')
        return camelCase(addrBits)
    },
    shallExposeRoute: () => true
}
 
 
export function getTsTypeAsStringAndRouteClean(
    queryName: string,
    originalApiAddr: string,
    objectTs: Record<string, string>,
    ts: string[],
    outputValidator: GenericDef,
    doc?: ServiceDocObject
) {
    const routeClean = originalApiAddr.replace(/\./g, '/') // replace a.b => a/b
    if (doc) objectTs[queryName + '__COMMENT__'] = generateJsDoc(doc, outputValidator)

    const tsTypesAsString = ts.map(str => str.replace(/ +ctx: Ctx,\n/, '')) // TODO remove this once using the right type for dao-types => https://stackoverflow.com/questions/76853143/typescript-getting-returntype-of-a-function-called-with-certains-parameter-types

    objectTs[queryName] = tsTypesAsString.join(`\n    ${queryName}`)

    return { routeClean, tsTypesAsString }
}