Source

frontend/controllers/cloud_sync/cloud_sync_provider_registry.js

/* This file is part of Ezra Bible App.

   Copyright (C) 2019 - 2026 Ezra Bible App Development Team <contact@ezrabibleapp.net>

   Ezra Bible App is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   (at your option) any later version.

   Ezra Bible App is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Ezra Bible App. See the file LICENSE.
   If not, see <http://www.gnu.org/licenses/>. */

/**
 * Registers cloud-sync provider adapters and looks them up by provider ID.
 * It also delegates configured-state and display-name queries to the adapters.
 */
class CloudSyncProviderRegistry {
  constructor() {
    this.adapters = new Map();
  }

  register(provider, adapter) {
    this.adapters.set(provider, adapter);
  }

  get(provider) {
    return this.adapters.get(provider) || null;
  }

  getProviderIds() {
    return Array.from(this.adapters.keys());
  }

  async isConfigured(provider) {
    const adapter = this.get(provider);
    return adapter && typeof adapter.isConfigured === 'function'
      ? adapter.isConfigured()
      : false;
  }

  getDisplayName(provider) {
    const adapter = this.get(provider);
    return adapter && typeof adapter.getDisplayName === 'function'
      ? adapter.getDisplayName()
      : '';
  }
}

module.exports = CloudSyncProviderRegistry;