<commit_before>import {Container} from 'aurelia-dependency-injection';
import {inject} from 'aurelia-framework';
import {Rest} from 'spoonx/aurelia-api';

@inject(Rest, Container)
export class Repository {
  constructor (restClient, container) {
    this.api       = restClient;
    this.container = container;
  }

  setEntity (entity) {
    this.entity = entity;

    return this;
  }

  find (criteria, raw) {
    let findQuery = this.api.find(this.entity.resource, criteria);

    if (raw) {
      return findQuery;
    }

    return findQuery.then(x => this.populateEntities(x));
  }

  count (criteria) {
    return this.api.find(this.entity.resource + '/count', criteria);
  }

  create (data) {
    return this.getPopulatedEntity(data);
  }

  populateEntities (data) {
    if (!data) {
      return null;
    }

    if (!Array.isArray(data)){
      return this.getPopulatedEntity(data);
    }

    let collection = [];

    data.forEach(entity => {
      collection.push(this.getPopulatedEntity(entity));
    });

    return collection;
  }

  getPopulatedEntity (data) {
    return this.getNewEntity().setData(data);
  }

  getNewEntity () {
    return this.container.get(this.entity);
  }
}<commit_msg>Implement entityReference and add docblocks<commit_after>import {inject} from 'aurelia-framework';
import {Rest} from 'spoonx/aurelia-api';

@inject(Rest)
export class Repository {
  /**
   * Construct.
   *
   * @param {Rest} restClient
   *
   * @constructor
   */
  constructor (restClient) {
    this.api = restClient;
  }

  /**
   * Set an entity instance.
   * Used to harvest information such as the resource name.
   *
   * @param {Entity} entity
   * @return {Repository}
   */
  setEntity (entity) {
    this.entity = entity;

    return this;
  }

  /**
   * Set the entity reference.
   * Used to create new instances of the entity using aurelia DI.
   *
   * @param {Entity} entityReference
   * @return {Repository}
   */
  setEntityReference (entityReference) {
    this.entityReference = entityReference;

    return this;
  }

  /**
   * Perform a find query.
   *
   * @param {null|{}|Number} criteria Criteria to add to the query.
   * @param {boolean}        raw      Set to true to get a POJO in stead of populated entities.
   * @return {*}
   */
  find (criteria, raw) {
    let findQuery = this.api.find(this.entity.resource, criteria);

    if (raw) {
      return findQuery;
    }

    return findQuery.then(x => this.populateEntities(x));
  }

  /**
   * Perform a count.
   *
   * @param {null|{}} criteria
   * @return {*}
   */
  count (criteria) {
    return this.api.find(this.entity.resource + '/count', criteria);
  }

  /**
   * Create a new, populated entity based on supplied `data`.
   *
   * @param {{}} data
   * @return {*}
   */
  create (data) {
    return this.getPopulatedEntity(data);
  }

  /**
   * Populate entities based on supplied data.
   *
   * @param {{}} data
   * @return {*}
   */
  populateEntities (data) {
    if (!data) {
      return null;
    }

    if (!Array.isArray(data)) {
      return this.getPopulatedEntity(data);
    }

    let collection = [];

    data.forEach(source => {
      collection.push(this.getPopulatedEntity(source));
    });

    return collection;
  }

  /**
   * @param {{}} data
   * @return {Entity}
   */
  getPopulatedEntity (data) {
    return this.getNewEntity().setData(data);
  }

  /**
   * Get a new instance for entityReference.
   *
   * @return {Entity}
   */
  getNewEntity () {
    return this.entityManager.getEntity(this.entityReference);
  }
}
{'fraction_non_alphanumeric': 0.13692480359147025, 'fraction_numerical': 0.0, 'mean_word_length': 2.6526639344262297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6371733', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1136, 'n_words': 268}