import { Wetland } from './Wetland' ; import { SchemaBuilder } from './SchemaBuilder' ; export class SchemaManager { type { Wetland } private wetland : Wetland ; type { SchemaBuilder } private schemaBuilder : SchemaBuilder ; param { Wetland } wetland constructor ( wetland ) { this . wetland = wetland ; this . schemaBuilder = new SchemaBuilder ( wetland . getManager ( ) ) ; } param { { } } previous param { boolean } revert returns { string } public getSQL ( previous = { } , revert = false ) { return this . prepare ( previous , revert ) . getSQL ( ) ; } param { { } } previous param { boolean } revert returns { string } public getCode ( previous = { } , revert = false ) { return this . prepare ( previous , revert ) . getCode ( ) ; } returns { Promise < any > } public create ( ) { return this . apply ( { } ) ; } param { { } } previous param { boolean } revert returns { Promise < any > } public apply ( previous = { } , revert = false ) { return this . prepare ( previous , revert ) . apply ( ) ; } param { { } } previous param { boolean } revert returns { SchemaBuilder } private prepare ( previous , revert = false ) { const snapshot = this . wetland . getSnapshotManager ( ) ; const serializable = snapshot . getSerializable ( ) ; let instructions ; if ( revert ) { instructions = snapshot . diff ( serializable , previous ) ; } else { instructions = snapshot . diff ( previous , serializable ) ; } return this . schemaBuilder . process ( instructions ) ; } }