<commit_before>'use strict';

const request = require('request');
const fs      = require('fs');
const path    = require('path');
const co      = require('co');

const services = {
  logs: '/logs'
};

const defaults = {
  baseUrl: 'https://ezmesure.couperin.org/api'
};

exports.config = {};

exports.config.load = function (config) {
  return new Promise((resolve, reject) => {
    if (typeof config === 'object') {
      Object.assign(defaults, config);
      return resolve();
    }

    if (typeof config !== 'string') {
      return reject(new Error('config should be either an object or a string'));
    }

    fs.readFile(path.resolve(config), 'utf-8', (err, content) => {
      if (err) { return reject(err); }

      try {
        Object.assign(defaults, JSON.parse(content));
      } catch (e) {
        return reject(e);
      }

      resolve();
    });
  });
};

exports.indices = {};

exports.indices.list = function (options, callback) {
  return promisedQuery('GET', services.logs, options).then(res => {
    if (!res || !res.indices) { return Promise.reject(new Error('Invalid response')); }

    return Object.keys(res.indices)
      .filter(name => !name.startsWith('.'))
      .sort()
      .map(name => {
        return {
          name,
          docs: res.indices[name].total.docs.count
        };
      });
  });
};

exports.indices.delete = function (indice, options) {
  return promisedQuery('DELETE', `${services.logs}/${indice}`, options).then(res => {
    if (res && res.acknowledged) { return res; }

    return Promise.reject(new Error('Invalid response'));
  });
};

exports.indices.insert = co.wrap(function* (file, indice, options) {<commit_msg>resolve even if acknoledge is false<commit_after>'use strict';

const request = require('request');
const fs      = require('fs');
const path    = require('path');
const co      = require('co');

const services = {
  logs: '/logs'
};

const defaults = {
  baseUrl: 'https://ezmesure.couperin.org/api'
};

exports.config = {};

exports.config.load = function (config) {
  return new Promise((resolve, reject) => {
    if (typeof config === 'object') {
      Object.assign(defaults, config);
      return resolve();
    }

    if (typeof config !== 'string') {
      return reject(new Error('config should be either an object or a string'));
    }

    fs.readFile(path.resolve(config), 'utf-8', (err, content) => {
      if (err) { return reject(err); }

      try {
        Object.assign(defaults, JSON.parse(content));
      } catch (e) {
        return reject(e);
      }

      resolve();
    });
  });
};

exports.indices = {};

exports.indices.list = function (options, callback) {
  return promisedQuery('GET', services.logs, options).then(res => {
    if (!res || !res.indices) { return Promise.reject(new Error('Invalid response')); }

    return Object.keys(res.indices)
      .filter(name => !name.startsWith('.'))
      .sort()
      .map(name => {
        return {
          name,
          docs: res.indices[name].total.docs.count
        };
      });
  });
};

exports.indices.delete = function (indice, options) {
  return promisedQuery('DELETE', `${services.logs}/${indice}`, options).then(res => {
    if (res && res.hasOwnProperty('acknowledged')) { return res; }

    return Promise.reject(new Error('Invalid response'));
  });
};

exports.indices.insert = co.wrap(function* (file, indice, options) {
{'fraction_non_alphanumeric': 0.17598587404355504, 'fraction_numerical': 0.0005885815185403178, 'mean_word_length': 2.9431554524361947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6655481', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1026, 'n_words': 239}