{"version":3,"file":"redis-migrator.mjs","sources":["../../../src/redis-migrator.ts"],"sourcesContent":["import {\n  AbstractMigrationEngine,\n  SessionStorageMigratorOptions,\n  MigrationOperation,\n} from '@shopify/shopify-app-session-storage';\n\nimport {RedisConnection} from './redis-connection';\n\nexport class RedisSessionStorageMigrator extends AbstractMigrationEngine<\n  RedisConnection,\n  SessionStorageMigratorOptions\n> {\n  constructor(\n    dbConnection: RedisConnection,\n    opts: Partial<SessionStorageMigratorOptions> = {},\n    migrations: MigrationOperation[],\n  ) {\n    // The name has already been decided whith the last migration\n    opts.migrationDBIdentifier = 'migrations';\n    super(dbConnection, opts, migrations);\n  }\n\n  async initMigrationPersistence(): Promise<void> {\n    // nothing to do here\n    return Promise.resolve();\n  }\n\n  async hasMigrationBeenApplied(migrationName: string): Promise<boolean> {\n    const migrations = await this.getMigrationRecords();\n    const found = migrations.get(migrationName) ?? false;\n\n    return Promise.resolve(found);\n  }\n\n  async saveAppliedMigration(migrationName: string): Promise<void> {\n    const migrations = await this.getMigrationRecords();\n    migrations.set(migrationName, true);\n\n    this.connection.set(\n      this.options.migrationDBIdentifier,\n      JSON.stringify(Object.fromEntries(migrations)),\n    );\n\n    return Promise.resolve();\n  }\n\n  private async getMigrationRecords(): Promise<Map<string, boolean>> {\n    const migrationsRecord = await this.connection.get(\n      this.options.migrationDBIdentifier,\n    );\n    let migrations: Map<string, boolean> = new Map();\n    if (migrationsRecord) {\n      migrations = new Map(Object.entries(JSON.parse(migrationsRecord)));\n    }\n\n    return Promise.resolve(migrations);\n  }\n}\n"],"names":[],"mappings":";;AAQM,MAAO,2BAA4B,SAAQ,uBAGhD,CAAA;AACC,IAAA,WAAA,CACE,YAA6B,EAC7B,IAAA,GAA+C,EAAE,EACjD,UAAgC,EAAA;;AAGhC,QAAA,IAAI,CAAC,qBAAqB,GAAG,YAAY;AACzC,QAAA,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,UAAU,CAAC;IACvC;AAEA,IAAA,MAAM,wBAA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