UNPKG

@shopify/shopify-app-session-storage-redis

Version:
38 lines (34 loc) 1.5 kB
'use strict'; var shopifyAppSessionStorage = require('@shopify/shopify-app-session-storage'); class RedisSessionStorageMigrator extends shopifyAppSessionStorage.AbstractMigrationEngine { constructor(dbConnection, opts = {}, migrations) { // The name has already been decided whith the last migration opts.migrationDBIdentifier = 'migrations'; super(dbConnection, opts, migrations); } async initMigrationPersistence() { // nothing to do here return Promise.resolve(); } async hasMigrationBeenApplied(migrationName) { const migrations = await this.getMigrationRecords(); const found = migrations.get(migrationName) ?? false; return Promise.resolve(found); } async saveAppliedMigration(migrationName) { const migrations = await this.getMigrationRecords(); migrations.set(migrationName, true); this.connection.set(this.options.migrationDBIdentifier, JSON.stringify(Object.fromEntries(migrations))); return Promise.resolve(); } async getMigrationRecords() { const migrationsRecord = await this.connection.get(this.options.migrationDBIdentifier); let migrations = new Map(); if (migrationsRecord) { migrations = new Map(Object.entries(JSON.parse(migrationsRecord))); } return Promise.resolve(migrations); } } exports.RedisSessionStorageMigrator = RedisSessionStorageMigrator; //# sourceMappingURL=redis-migrator.js.map