protected async getConnectedServicesByType()

in packages/app/main/src/commands/connectedServiceCommands.ts [50:100]


  protected async getConnectedServicesByType(
    armToken: string,
    serviceType: ServiceTypes
  ): Promise<{ services: IConnectedService[] }> {
    let it;
    switch (serviceType) {
      case ServiceTypes.Luis:
      // Falls through

      case ServiceTypes.Dispatch:
        it = LuisApi.getServices(armToken);
        break;

      case ServiceTypes.QnA:
        it = QnaApiService.getKnowledgeBases(armToken);
        break;

      case ServiceTypes.BlobStorage:
        it = StorageAccountApiService.getBlobStorageServices(armToken);
        break;

      case ServiceTypes.CosmosDB:
        it = CosmosDbApiService.getCosmosDbServices(armToken);
        break;

      default:
        throw new TypeError(`The ServiceTypes ${serviceType} is not a known service type`);
    }

    let result: { services: IConnectedService[] };
    // eslint-disable-next-line no-constant-condition
    while (true) {
      const next = it.next(result);
      if (next.done) {
        result = next.value;
        break;
      }
      try {
        result = await next.value;
        // Signature for a progress update that needs to
        // be sent to the rendering process
        if (typeof result === 'object' && 'label' in result && 'progress' in result) {
          await this.commandService.remoteCall(UI.UpdateProgressIndicator, result);
        }
      } catch (e) {
        break;
      }
    }
    result.services = result.services.filter(service => service.type === serviceType);
    return result;
  }