<commit_before>import FileSaver from 'file-saver';
import axios from 'axios';
import Consts from './AppConsts';
import EnvironmentService from './EnvironmentService';

export default class CatalogApi {

  static getCatalogSchemaData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.SCHEMAS);
    return axios.get(url).then(response => response.data);
  }

  static getCatalogEntityTypeData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_TYPE);
    return axios.get(url).then(response => response.data);
  }

  static getCatalogEntitySetData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_SET);
    return axios.get(url).then(response => response.data);
  }

  static getDownloadRequestBody(data, method, datatype, url) {
    const type = (datatype === Consts.JSON) ? 'application/json' : 'text/csv';
    const req = {
      method,
      url,
      headers: {
        'Content-Type': 'application/json'
      }
    };
    if (method === Consts.PUT) {
      req.data = data;
    }
    if (datatype === Consts.CSV) {
      req.headers.Accept = type;
    }
    return req;
  }

  static saveFile(entityData, name, datatype, success) {

    let contentType = 'application/json';
    let data = entityData;

    if (datatype === Consts.JSON) {
      contentType = 'text/csv';
      data = JSON.stringify(entityData);
    }

    const blob = new Blob([data], { contentType });
    FileSaver.saveAs(blob, name.concat(
      (datatype === Consts.JSON) ? '.json' : '.csv'
    ));
    success(datatype);
  }

  static downloadSchema(data, name, datatype, success) {
    this.saveFile(data, name, datatype, success);
  }

  static downloadEntityType(namespace, name, datatype, err, success) {
    const data = JSON.stringify({
      namespace,
      name
    });
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_TYPE_DATA_URL);
    return axios(this.getDownloadRequestBody(data, Consts.PUT, datatype, url)
      ).then((resp) => {<commit_msg>Blob constructor expects "type"<commit_after>import FileSaver from 'file-saver';
import axios from 'axios';
import Consts from './AppConsts';
import EnvironmentService from './EnvironmentService';

export default class CatalogApi {

  static getCatalogSchemaData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.SCHEMAS);
    return axios.get(url).then(response => response.data);
  }

  static getCatalogEntityTypeData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_TYPE);
    return axios.get(url).then(response => response.data);
  }

  static getCatalogEntitySetData() {
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_SET);
    return axios.get(url).then(response => response.data);
  }

  static getDownloadRequestBody(data, method, datatype, url) {
    const type = (datatype === Consts.JSON) ? 'application/json' : 'text/csv';
    const req = {
      method,
      url,
      headers: {
        'Content-Type': 'application/json'
      }
    };
    if (method === Consts.PUT) {
      req.data = data;
    }
    if (datatype === Consts.CSV) {
      req.headers.Accept = type;
    }
    return req;
  }

  static saveFile(entityData, name, datatype, success) {

    let contentType = 'application/json';
    let data = entityData;

    if (datatype === Consts.JSON) {
      contentType = 'text/csv';
      data = JSON.stringify(entityData);
    }

    const blob = new Blob([data], {
      type: contentType
    });

    FileSaver.saveAs(blob, name.concat(
      (datatype === Consts.JSON) ? '.json' : '.csv'
    ));
    success(datatype);
  }

  static downloadSchema(data, name, datatype, success) {
    this.saveFile(data, name, datatype, success);
  }

  static downloadEntityType(namespace, name, datatype, err, success) {
    const data = JSON.stringify({
      namespace,
      name
    });
    const url = EnvironmentService.getDatastoreUrl().concat(Consts.ENTITY_TYPE_DATA_URL);
    return axios(this.getDownloadRequestBody(data, Consts.PUT, datatype, url)
      ).then((resp) => {
{'fraction_non_alphanumeric': 0.13341433778857836, 'fraction_numerical': 0.0, 'mean_word_length': 3.3694267515923566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4704298', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1273, 'n_words': 270}