All files / src/commands/contract types.ts

65.51% Statements 19/29
87.5% Branches 7/8
50% Functions 4/8
64.28% Lines 18/28

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 1325631x   1x   16x               16x                           16x             16x     1x                                   1x                                   1x   16x           16x             16x     1x   16x           16x             16x     1x                       2x                      
import * as ts from 'typescript'
 
export function generateRowType(): ts.TypeAliasDeclaration {
    // Create the type parameter 'T'
    const typeParameter = ts.factory.createTypeParameterDeclaration(
        undefined,
        ts.factory.createIdentifier('T'),
        undefined,
        undefined
    )
 
    // Create the conditional type 'T extends keyof TableTypes ? TableTypes[T] : any'
    const conditionalType = ts.factory.createConditionalTypeNode(
        ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('T')),
        ts.factory.createTypeOperatorNode(
            ts.SyntaxKind.KeyOfKeyword,
            ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('TableTypes'))
        ),
        ts.factory.createIndexedAccessTypeNode(
            ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('TableTypes')),
            ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('T'))
        ),
        ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)
    )
 
    // Create the type alias declaration 'type RowType<T> = ...'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'RowType',
        [typeParameter],
        conditionalType
    )
 
    return typeAliasDeclaration
}
 
export function generateTablesTypeAlias(): ts.TypeAliasDeclaration {
    // Create the 'keyof TableTypes' type
    const keyofTableTypes = ts.factory.createTypeOperatorNode(
        ts.SyntaxKind.KeyOfKeyword,
        ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('TableTypes'))
    )
 
    // Create the type alias declaration 'type Tables = ...'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'Tables',
        undefined,
        keyofTableTypes
    )
 
    return typeAliasDeclaration
}
 
export function generateActionsTypeAlias(): ts.TypeAliasDeclaration {
    // Create the 'keyof ActionNameParams' type
    const keyofActionNameParams = ts.factory.createTypeOperatorNode(
        ts.SyntaxKind.KeyOfKeyword,
        ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('ActionNameParams'))
    )
 
    // Create the type alias declaration 'type Actions = ...'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'Actions',
        undefined,
        keyofActionNameParams
    )
 
    return typeAliasDeclaration
}
 
export function generateActionNamesTypeAlias(): ts.TypeAliasDeclaration {
    // Create the 'keyof ActionNameParams' type
    const keyofActionNameParams = ts.factory.createTypeOperatorNode(
        ts.SyntaxKind.KeyOfKeyword,
        ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('ActionNameParams'))
    )
 
    // Create the type alias declaration 'type ActionNames = keyof ActionNameParams'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'ActionNames',
        undefined,
        keyofActionNameParams
    )
 
    return typeAliasDeclaration
}
 
export function generateTableNamesTypeAlias(): ts.TypeAliasDeclaration {
    // Create the 'keyof TableTypes' type
    const keyofTableTypes = ts.factory.createTypeOperatorNode(
        ts.SyntaxKind.KeyOfKeyword,
        ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('TableTypes'))
    )
 
    // Create the type alias declaration 'type TableNames = keyof TableTypes'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'TableNames',
        undefined,
        keyofTableTypes
    )
 
    return typeAliasDeclaration
}
 
export function generateTableNameTypeAlias(): ts.TypeAliasDeclaration {
    // Create the type alias declaration 'type TableName = string'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'TableName',
        undefined,
        ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
    )
 
    return typeAliasDeclaration
}
 
export function generateSerializerTypeAlias(): ts.TypeAliasDeclaration {
    // Create the type alias declaration 'type Serializer = any'
    const typeAliasDeclaration = ts.factory.createTypeAliasDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
        'Serializer',
        undefined,
        ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)
    )
 
    return typeAliasDeclaration
}