<commit_before>exports.couch = (function() {
  
  function keyToAddress(key) {
    var i = 0;
    while(i < key.length && key[i] =='u') {
     i++;
    }
    if((i < key.length) && (key[i] == '_')) {
      key = 'u'+key;
    }
    return localStorage.getItem('_shadowBackendAddress') + key;
  }
  function doCall(method, key, obj, err, cb, timeout) {
    var ajaxObj = {
      url: keyToAddress(key),
      method: method,
      error: err,
      success: cb,
      timeout: timeout
    }
    ajaxObj.headers= {Authorization: 'Bearer '+localStorage.getItem('_shadowBackendToken')};
    ajaxObj.fields={withCredentials: 'true'};
    if(method!='GET') {
      ajaxObj.data=JSON.stringify(obj);
    }
    exports.ajax(ajaxObj);
  }
  function init(address, bearerToken) {
    localStorage.setItem('_shadowBackendAddress', address);
    localStorage.setItem('_shadowBackendToken', bearerToken);
  }
  function get(key, err, cb, timeout) {
    console.log('couch.get("'+key+'", err, cb, '+timeout+');');
    doCall('GET', key, null, err, cb, timeout);
  }
  function set(key, value, err, cb, timeout) {
    console.log('couch.set("'+key+'", "'+value+'", err, cb, '+timeout+');');
    doCall('PUT', key, value, err, cb, timeout);
  }
  function remove(key, err, cb, timeout) {
    console.log('couch.remove("'+key+'", err, cb, '+timeout+');');
    doCall('DELETE', key, null, err, cb, timeout);
  }
  return {<commit_msg>trying to add JSON-objectification and revision handling<commit_after>exports.couch = (function() {
  
  function keyToAddress(key) {
    var i = 0;
    while(i < key.length && key[i] =='u') {
     i++;
    }
    if((i < key.length) && (key[i] == '_')) {
      key = 'u'+key;
    }
    return localStorage.getItem('_shadowBackendAddress') + key;
  }
  function doCall(method, key, obj, err, cb, timeout) {
    var ajaxObj = {
      url: keyToAddress(key),
      method: method,
      error: err,
      success: cb,
      timeout: timeout
    }
    ajaxObj.headers= {Authorization: 'Bearer '+localStorage.getItem('_shadowBackendToken')};
    ajaxObj.fields={withCredentials: 'true'};
    if(method!='GET') {
      ajaxObj.data=JSON.stringify(obj);
    }
    exports.ajax(ajaxObj);
  }
  function init(address, bearerToken) {
    localStorage.setItem('_shadowBackendAddress', address);
    localStorage.setItem('_shadowBackendToken', bearerToken);
  }
  function get(key, err, cb, timeout) {
    console.log('couch.get("'+key+'", err, cb, '+timeout+');');
    doCall('GET', key, null, err, function(str) {
      var obj = JSON.parse(str);
      localStorage.setItem('_shadowCouchRev_'+key, obj.revision);
      cb(obj.value);
    }, timeout);
  }
  function set(key, value, err, cb, timeout) {
    console.log('couch.set("'+key+'", "'+value+'", err, cb, '+timeout+');');
    var revision = localStorage.getItem('_shadowCouchRev_'+key);
    var obj = {
      value: value
    };
    if(revision) {
      obj.revision = revision;
    }
    doCall('PUT', key, JSON.stringify(obj), err, cb, timeout);
  }
  function remove(key, err, cb, timeout) {
    console.log('couch.remove("'+key+'", err, cb, '+timeout+');');
    doCall('DELETE', key, null, err, cb, timeout);
  }
  return {
{'fraction_non_alphanumeric': 0.18563813107557228, 'fraction_numerical': 0.0006271558482282847, 'mean_word_length': 3.424410540915395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '992257', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1109, 'n_words': 228}