<commit_before>import DS from "ember-data";

function bin2String(uintArray) {
  var encodedString = String.fromCharCode.apply(null, uintArray),
      decodedString = decodeURIComponent((encodedString));
  return decodedString;
}

export default DS.Serializer.extend({
  resource(key, body, type) {
    let resource = {};
    // Take the last section as the ID
    let id = key.substr(key.lastIndexOf("/")+1);
    resource.id = id;

    resource.type = type;
    resource.attributes = {};
    resource.attributes.key = key;
    if(body){
      resource.attributes._body = bin2String(body);
      resource.attributes._bodyHasBeenFetched = true;
    }

    return resource;
  },

  normalizeResponse(store, type, payload, id, requestType) {
    let jsonapiPayload = {};

    if (requestType === "findAll") {
      jsonapiPayload.data = [];
      payload.Contents.forEach((element) => {
        // Do not serialize the folder indicator eg. 'article/'
        if (element.Key !== type.modelName+"/") {
          jsonapiPayload.data.pushObject(this.resource(element.Key, element.Body, type.modelName));
        }
      });
    } else {
      if (payload.Key !== type.modelName+"/") {
        jsonapiPayload.data = this.resource(payload.Key, payload.Body, type.modelName);
      }
    }

    return jsonapiPayload;
  }
});<commit_msg>create a more Ember-ish serializer, that serializes attributes<commit_after>import DS from "ember-data";
const { getOwner } = Ember;

export default DS.JSONSerializer.extend({
  serialize(snapshot) {
    var json = this._super(...arguments);
    return this.jsonToAmazonObject(json, snapshot);
  },
  normalizeResponse(store, primaryModelClass, payload, id, requestType) {
    let newPayload = {};
    switch (requestType) {
      case 'findRecord':
        newPayload = this.amazonObjectToJson(payload);
        break;
      case 'queryRecord':
        1+1;
        break;
      case 'findAll':
        newPayload = this.amazonListToJson(payload);
        break;
      case 'findBelongsTo':
        1+1;
        //TODO: Implement
        break;
      case 'findHasMany':
        1+1;
        //TODO: Implement
        break;
      case 'findMany':
        1+1;
        //TODO: Implement
        break;
      case 'query':
        break;
        //TODO: Implement
        1+1;
      case 'createRecord':
        1+1;
        newPayload = this.amazonObjectToJson(payload);
        //TODO: Implement
        break;
      case 'deleteRecord':
        1+1;
        //TODO: Implement
        break;
      case 'updateRecord':
        1+1;
        newPayload = this.amazonObjectToJson(payload);
        //TODO: Implement
        break;
    }
    var json = this._super(store, primaryModelClass, newPayload, id, requestType);
    return json;
  },
  amazonListToJson(oldPayload) {
    var payload = [];
    oldPayload.Contents.forEach((item) => {
      let key = item.Key;
      if(!(key.substring(key.length - 1, key.length) == '/')) {
        payload.pushObject(this.amazonObjectToJson(item));
      }
    });
    return payload;
  },
  amazonObjectToJson(object) {
    let key = object.Key;
    let id = key.substr(key.lastIndexOf("/")+1);
    object.id = id;
    object.key = key;
    if(object.Body) {
      object._body = object.Body;
    }
    return object;
  },
  jsonToAmazonObject(json, snapshot) {
    json.Body = json._body;
    return json;
  }
});
{'fraction_non_alphanumeric': 0.13039621525724424, 'fraction_numerical': 0.006209343583678297, 'mean_word_length': 2.424089068825911, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1530015', 'n_tokens_mistral': 1031, 'n_tokens_neox': 1028, 'n_words': 219}