import {Event} from '../../../event/Event' import {Migration} from '../Migration' import {Inject, Injectable} from '../../../di' import {Migrations} from '../../services/Migrations' import {ErrorWithContext} from '../../../util' /** * Generic base-class for migration-related events. */ @Injectable() export abstract class MigrationEvent extends Event { @Inject() protected readonly migrations!: Migrations /** The migration relevant to this event. */ private internalMigration: Migration /** * Get the relevant migration. */ public get migration(): Migration { return this.internalMigration } constructor( migration: Migration, ) { super() this.internalMigration = migration } dehydrate(): {identifier: string} { return { identifier: this.migration.identifier, } } rehydrate(state: {identifier: string}): void { const migration = this.migrations.get(state.identifier) if ( !migration ) { throw new ErrorWithContext(`Unable to find migration with identifier: ${state.identifier}`, { identifier: state.identifier, }) } this.internalMigration = migration } }