-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: turn keyword into a command fragment (#67)
BREAKING CHANGE: replaces the keyword table (renames old table)
- Loading branch information
Showing
4 changed files
with
112 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,51 @@ | ||
import { Command } from 'src/entity/Command'; | ||
import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm'; | ||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
export interface KeywordOptions { | ||
command: Command; | ||
controller: string; | ||
name: string; | ||
import { BaseCommand } from 'src/entity/base/BaseCommand'; | ||
import { CommandOptions } from 'src/entity/Command'; | ||
import { dictToMap } from 'src/utils/Map'; | ||
|
||
export interface KeywordOptions extends CommandOptions { | ||
controllerId: string; | ||
|
||
/** | ||
* The keyword to execute with. | ||
*/ | ||
key: string; | ||
} | ||
|
||
@Entity() | ||
export class Keyword implements KeywordOptions { | ||
@OneToOne((type) => Command, (cmd) => cmd.id, { | ||
cascade: true, | ||
}) | ||
@JoinColumn() | ||
public command: Command; | ||
export const TABLE_KEYWORD = 'keyword'; | ||
|
||
@Entity(TABLE_KEYWORD) | ||
export class Keyword extends BaseCommand implements KeywordOptions { | ||
@Column() | ||
public controller: string; | ||
public controllerId: string; | ||
|
||
@PrimaryGeneratedColumn('uuid') | ||
public id: string; | ||
|
||
@PrimaryColumn() | ||
public name: string; | ||
public key: string; | ||
|
||
constructor(options?: KeywordOptions) { | ||
super(); | ||
|
||
if (options) { | ||
this.command = options.command; | ||
this.controller = options.controller; | ||
this.name = options.name; | ||
this.controllerId = options.controllerId; | ||
this.data = dictToMap(options.data); | ||
this.key = options.key; | ||
this.labels = dictToMap(options.labels); | ||
this.noun = options.noun; | ||
this.verb = options.verb; | ||
} | ||
} | ||
|
||
public toJSON() { | ||
return { | ||
controllerId: this.controllerId, | ||
id: this.id, | ||
key: this.key, | ||
noun: this.noun, | ||
verb: this.verb, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MigrationInterface, QueryRunner, Table } from 'typeorm'; | ||
|
||
import { TABLE_KEYWORD } from 'src/entity/misc/Keyword'; | ||
|
||
const OLD_TABLE = `${TABLE_KEYWORD}_old`; | ||
|
||
export class KeywordCommand0001545509108 implements MigrationInterface { | ||
public async up(query: QueryRunner): Promise<any> { | ||
await query.renameTable(TABLE_KEYWORD, OLD_TABLE); | ||
await query.createTable(new Table({ | ||
columns: [{ | ||
isPrimary: true, | ||
name: 'id', | ||
type: 'varchar', | ||
}, { | ||
name: 'controllerId', | ||
type: 'varchar', | ||
}, { | ||
name: 'data', | ||
type: 'varchar', | ||
}, { | ||
name: 'key', | ||
type: 'varchar', | ||
}, { | ||
name: 'labels', | ||
type: 'varchar', | ||
}, { | ||
name: 'noun', | ||
type: 'varchar', | ||
}, { | ||
name: 'verb', | ||
type: 'varchar', | ||
}], | ||
name: 'keyword', | ||
})); | ||
} | ||
|
||
public async down(query: QueryRunner): Promise<any> { | ||
await query.dropTable(TABLE_KEYWORD); | ||
if (await query.hasTable(OLD_TABLE)) { | ||
await query.renameTable(OLD_TABLE, TABLE_KEYWORD); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters