| 2 | import {TableProps} from './table'; |
| 3 | |
| 4 | export class TableParser { |
| 5 | table: TableProps; |
| 6 | |
| 7 | constructor(tableInfo: TableProps) { |
| 8 | this.table = tableInfo; |
| 9 | } |
| 10 | |
| 11 | get title() { |
| 12 | return this.table.name; |
| 13 | } |
| 14 | |
| 15 | get fieldNames() { |
| 16 | return this.table.fields.map((f) => f.name); |
| 17 | } |
| 18 | |
| 19 | formatStringField(field: IBaseFieldMeta) { |
| 20 | return `${ field.name }: string;`; |
| 21 | } |
| 22 | |
| 23 | formatSelectField(field: IBaseFieldMeta) { |
| 24 | const property = field.property as any; |
| 25 | if (!property || !property?.options) { |
| 26 | { |
| 27 | return ''; |
| 28 | } |
| 29 | } |
| 30 | const options = property.options as any; |
| 31 | if (!options) { |
| 32 | return ''; |
| 33 | } |
| 34 | const optionsStr = options.map((o: any) => `"${ o.name }"`).join(' | '); |
| 35 | return `${ field.name }: ${ optionsStr };`; |
| 36 | } |
| 37 | |
| 38 | formatMultiSelectField(field: IBaseFieldMeta) { |
| 39 | const property = field.property as any; |
| 40 | if (!property || !property?.options) { |
| 41 | { |
| 42 | return ''; |
| 43 | } |
| 44 | } |
| 45 | const options = property.options as any; |
| 46 | if (!options) { |
| 47 | return ''; |
| 48 | } |
| 49 | const optionsStr = options.map((o: any) => `"${ o.name }"`).join(' | '); |
| 50 | return `${ field.name }: (${ optionsStr })[];`; |
| 51 | } |
| 52 | |
| 53 | formatNumberField(iBaseFieldMeta: IBaseFieldMeta) { |
| 54 | return `${ iBaseFieldMeta.name }: number;`; |
| 55 | } |
| 56 | |
| 57 | formatPhoneField(iBaseFieldMeta: IBaseFieldMeta) { |
| 58 | return `${ iBaseFieldMeta.name }: string;`; |
| 59 | } |
| 60 | |
| 61 | formatUrlField(iBaseFieldMeta: IBaseFieldMeta) { |
nothing calls this directly
no outgoing calls
no test coverage detected