<commit_before>/*

  a database implementation that uses ajax
  to speak to a remote REST API
  
*/

import superagent from 'superagent'

const DEFAULT_URLS = {
  loadTree:(base) => {
    return base + '/tree'
  },
  addItem:(base, id) => {
    return base + '/add/:id'
  }
}

export default function ajaxdb(opts = {}){

  const urls = Object.assign({}, DEFAULT_URLS, opts.urls)

  return {
    saveItem:(item, done) => {
      
    },
    addItem:(parent, item, done) => {
      superagent
        .post(urls.addItem(opts.base, parent))
        .send(JSON.stringify(item))
        .set('Accept', 'application/json')
        .end((err, res) => {
          if(res.status<500){
            done && done(res.body)
          }
          else{
            done && done(null, res.body)
          }
        })
    },
    pasteItems:(mode, parent, items, done) => {
      
    },
    deleteItem:(id, done) => {
      
    },
    loadItem:(id, done) => {
      
    },
    loadChildren:(id, done) => {
      
    },
    loadTree:(done) => {
      superagent
        .get(urls.loadTree(opts.base))
        .set('Accept', 'application/json')
        .end((err, res) => {
          if(res.status>=400){
            done && done(res.body)
          }
          else{
            done && done(null, res.body)
          }
        })
    }
  }
}<commit_msg>add filter results (for digger-folder-ui)<commit_after>/*

  a database implementation that uses ajax
  to speak to a remote REST API
  
*/

import superagent from 'superagent'

const DEFAULT_URLS = {
  loadTree:(base) => {
    return base + '/tree'
  },
  addItem:(base, id) => {
    return base + '/add' + (id ? '/' + id : '')
  }
}

export default function ajaxdb(opts = {}){

  const urls = Object.assign({}, DEFAULT_URLS, opts.urls)
  const mapFns = Object.assign({}, opts.mapFns)

  const filterResults = (type, data) => {
    return mapFns[type] ? mapFns[type](data) : data
  }

  return {
    saveItem:(item, done) => {
      
    },
    addItem:(parent, item, done) => {
      superagent
        .post(urls.addItem(opts.base, parent ? parent.id : null))
        .send(JSON.stringify(item))
        .set('Accept', 'application/json')
        .end((err, res) => {
          if(res.status<500){
            done && done(res.body)
          }
          else{
            done && done(null, filterResults('addItem', res.body))
          }
        })
    },
    pasteItems:(mode, parent, items, done) => {
      
    },
    deleteItem:(id, done) => {
      
    },
    loadItem:(id, done) => {
      
    },
    loadChildren:(id, done) => {
      
    },
    loadTree:(done) => {
      superagent
        .get(urls.loadTree(opts.base))
        .set('Accept', 'application/json')
        .end((err, res) => {
          if(res.status>=400){
            done && done(res.body)
          }
          else{
            done && done(null, filterResults('loadTree', res.body))
          }
        })
    }
  }
}
{'fraction_non_alphanumeric': 0.16485753052917232, 'fraction_numerical': 0.004070556309362279, 'mean_word_length': 1.7979127134724857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '5166474', 'n_tokens_mistral': 997, 'n_tokens_neox': 962, 'n_words': 188}