<commit_before>import * as http from "http";

export class CouchDB {
  private host: string;

  public constructor(databaseHost: string) {
    this.host = databaseHost;
  }

  public get(id: string) {
    return new Promise((resolve, reject) => {
      let url = [this.host, id].join("/");
      http.getJSON(url).then(response => {
        if(response.statusCode === 200){
          resolve(response.content.toJSON());    
        }else{
          reject(new Error(reponse));
        }
      }, err => reject(new Error(err)));
    })
  }


  public put(data: Object) {
    let params = {
      url: [this.host, data._id].join("/"),
      method: "PUT",
      headers: { "Content-Type": "application/json" },
      content: JSON.stringify(data)   
    }
    return new Promise((resolve, reject) => {
      http.request(params).then(response => {
        if(response.statusCode === 201){
          resolve(response.content.toJSON());
        }else{
          reject(new Error(response));
        }
      }, err => reject(new Error(err)));
    })
  }


  public remove(data: Object) {
    let params = {
      url: [this.host, data._id].join("/"),
      method: "DELETE",
      headers: { "Content-Type": "application/json" },
      content: JSON.stringify(data)   
    }
    return new Promise((resolve, reject) => {
      http.request(params).then(response => {
        if(response.statusCode === 200){
          resolve(response.content.toJSON());
        }else{
          reject(new Error(response));
        }
      }, err => reject(new Error(err)));
    })
  }
}<commit_msg>add api support for alldocs<commit_after>import * as http from "http";

export class CouchDB {
  private host: string;

  public constructor(databaseHost: string) {
    this.host = databaseHost;
  }

  public get(id: string) {
    return new Promise((resolve, reject) => {
      let url = [this.host, id].join("/");
      http.getJSON(url).then(response => {
        if(response.statusCode === 200){
          resolve(response.content.toJSON());    
        }else{
          reject(new Error(reponse));
        }
      }, err => reject(new Error(err)));
    })
  }


  public put(data: Object) {
    let params = {
      url: [this.host, data._id].join("/"),
      method: "PUT",
      headers: { "Content-Type": "application/json" },
      content: JSON.stringify(data)   
    }
    return new Promise((resolve, reject) => {
      http.request(params).then(response => {
        if(response.statusCode === 201){
          resolve(response.content.toJSON());
        }else{
          reject(new Error(response));
        }
      }, err => reject(new Error(err)));
    })
  }


  public remove(data: Object) {
    let params = {
      url: [this.host, data._id].join("/"),
      method: "DELETE",
      headers: { "Content-Type": "application/json" },
      content: JSON.stringify(data)   
    }
    return new Promise((resolve, reject) => {
      http.request(params).then(response => {
        if(response.statusCode === 200){
          resolve(response.content.toJSON());
        }else{
          reject(new Error(response));
        }
      }, err => reject(new Error(err)));
    })
  }


  private buildRequestParams(data: Object) {
    let keys = Object.keys(data);
    let args: string[] = "";
    keys.forEach(key => {
      let value = [key, encodeURI(data[key])].join("=");
      args.push(value);
    })
    return "?" + args;
  }


  public allDocs(data: Object) {
    let url = [this.url, "_all_docs", this.buildRequestParams(data)].join("/");
      http.getJSON(url).then(response => {
        if(response.statusCode === 200){
          resolve(response.content.toJSON());    
        }else{
          reject(new Error(reponse));
        }
      }, err => reject(new Error(err)));
    })
  }
}
{'fraction_non_alphanumeric': 0.1688243064729194, 'fraction_numerical': 0.005548216644649934, 'mean_word_length': 2.31523642732049, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 24, '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': '3237368', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1135, 'n_words': 229}