Skip to content

Commit

Permalink
Make meta-interfaces private, add function to generate export aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpf committed Feb 10, 2018
1 parent 301bbc2 commit f79f289
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Created by xiamx on 2016-08-10.
*/

import { generateEnumType, generateTableTypes, generateTableInterface } from './typescript'
import { generateEnumType, generateTableTypes, generateTableInterface, generateExports } from './typescript'
import { getDatabase, Database } from './schema'
import Options, { OptionValues } from './options'
import { processString } from 'typescript-formatter'
Expand Down Expand Up @@ -71,6 +71,8 @@ export async function typescriptOfTable (db: Database|string,
let tableTypes = await db.getTableTypes(table, schema, options)
interfaces += generateTableTypes(table, tableTypes, options)
interfaces += generateTableInterface(table, tableTypes, options)
interfaces += generateExports(table, tableTypes, options)

return interfaces
}

Expand Down
18 changes: 17 additions & 1 deletion src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function generateTableInterface (tableNameRaw: string, tableDefinition: T
})

return `
export interface ${normalizeName(tableName, options)} {
interface ${normalizeName(tableName, options)}Meta {
${members}
}
`
Expand Down Expand Up @@ -79,3 +79,19 @@ export function generateTableTypes (tableNameRaw: string, tableDefinition: Table
}
`
}

export function generateExports (tableNameRaw: string, tableDefinition: TableDefinition, options: Options) {
const tableName = options.transformTypeName(tableNameRaw)

if (options.isVerbose()) {
// If in verbose mode, simply rename <table>Meta to <table>
return `
export type ${tableName} = ${tableName}Meta
`
}

// If not in verbose mode, transform the meta interfaces to simple interfaces
return `
export type ${tableName} = SimpleSchema<${tableName}Meta>
`
}

0 comments on commit f79f289

Please sign in to comment.