{"version":3,"file":"abstract-migration-engine.mjs","sources":["../../../src/abstract-migration-engine.ts"],"sourcesContent":["import {\n  MigrationOperation,\n  SessionStorageMigrator,\n  SessionStorageMigratorOptions,\n  defaultSessionStorageMigratorOptions,\n  DBConnection,\n} from './types';\n\nexport abstract class AbstractMigrationEngine<\n  ConnectionType extends DBConnection,\n  MigratorOptionType extends SessionStorageMigratorOptions,\n> implements SessionStorageMigrator {\n  protected options: SessionStorageMigratorOptions;\n  protected connection: ConnectionType;\n  protected ready: Promise<void>;\n  protected migrations: MigrationOperation[];\n\n  constructor(\n    db: ConnectionType,\n    opts: Partial<MigratorOptionType> = {},\n    migrations: MigrationOperation[],\n  ) {\n    this.options = {...defaultSessionStorageMigratorOptions, ...opts};\n    this.connection = db;\n    this.migrations = migrations;\n\n    this.ready = this.initMigrationPersistence();\n  }\n\n  async applyMigrations(databaseReady: Promise<void>): Promise<void> {\n    await databaseReady;\n    await this.ready;\n\n    for (const {migrationName, migrationFunction} of this.getMigrationList()) {\n      const migrationApplied =\n        await this.hasMigrationBeenApplied(migrationName);\n      if (!migrationApplied) {\n        await migrationFunction(this.connection);\n        await this.saveAppliedMigration(migrationName);\n      }\n    }\n    return Promise.resolve();\n  }\n\n  getMigrationList(): MigrationOperation[] {\n    return this.migrations;\n  }\n\n  abstract initMigrationPersistence(): Promise<void>;\n  abstract hasMigrationBeenApplied(migrationName: string): Promise<boolean>;\n  abstract saveAppliedMigration(migrationName: string): Promise<void>;\n}\n"],"names":[],"mappings":";;MAQsB,uBAAuB,CAAA;AAIjC,IAAA,OAAO;AACP,IAAA,UAAU;AACV,IAAA,KAAK;AACL,IAAA,UAAU;AAEpB,IAAA,WAAA,CACE,EAAkB,EAClB,IAAA,GAAoC,EAAE,EACtC,UAAgC,EAAA;QAEhC,IAAI,CAAC,OAAO,GAAG,EAAC,GAAG,oCAAoC,EAAE,GAAG,IAAI,EAAC;AACjE,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;AAE5B,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,wBAAwB,EAAE;IAC9C;IAEA,MAAM,eAAe,CAAC,aAA4B,EAAA;AAChD,QAAA,MAAM,aAAa;QACnB,MAAM,IAAI,CAAC,KAAK;AAEhB,QAAA,KAAK,MAAM,EAAC,aAAa,EAAE,iBAAiB,EAAC,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE;YACxE,MAAM,gBAAgB,GACpB,MAAM,IAAI,CAAC,uBAAuB,CAAC,aAAa,CAAC;YACnD,IAAI,CAAC,gBAAgB,EAAE;AACrB,gBAAA,MAAM,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC;AACxC,gBAAA,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC;YAChD;QACF;AACA,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE;IAC1B;IAEA,gBAAgB,GAAA;QACd,OAAO,IAAI,CAAC,UAAU;IACxB;AAKD;;;;"}