<commit_before>const _ = require('lodash');

function Source (opts) {
  if (!opts) {
    opts = {};
  }
  if (!opts.model) {
    throw new Error('No bookshelf model specified.');
  }
  this.model = opts.model;
}

Source.prototype.filters = function () {
  return this.model.filters||{};
};

Source.prototype.relations = function () {
  return this.model.relations||{};
};

Source.prototype.filter = function (params) {
  if (!params) {
    params = {};
  }
  var filters = this.filters();
  // open query builder for this model
  return this.model.collection().query(function (qb) {
    // iterate over all params we explicitly support in the request
    // filtering the query
    qb = Object.keys(params).reduce(function (result, key) {
      var value = params[key];
      // see if there is a finder on the model for this param
      var filter = filters[key];
      // process the query with the filter, or, if none is found, pass it along
      return filter ? filter.call(filters, qb, value, params) : qb;
    }, qb);
  });
};

Source.prototype.fetch = function (query, relations, cb) {
  query.fetch({
    withRelated: relations||[]
  }).exec(cb);
};


// The following two methods are absolutely atrocious.
// They format Bookshelf queries to be json-api compliant.
// Something absolutely must be upstreamed into bookshelf to
// support this, or an entirely different approach must be taken.
// I miss ruby.
function unnest (node) {
  var output = [];
  var resource = node.attributes;
  // if the node has attributes, we've hit a single model
  if (resource) {
    // unnest all of it's relations
    var relations = node.relations;
    var links = {};
    if (!_.isEmpty(relations)) {
      resource.links = links;
    }
    Object.keys(relations).forEach(function (relationName) {
      // link the relation ids to the base model
      var relation = relations[relationName];
      // if the relation has attributes, it's a hasOne
      if (relation.attributes) {
        links[relationName] = relation.get('id');
      } else {<commit_msg>punctuation<commit_after>const _ = require('lodash');

function Source (opts) {
  if (!opts) {
    opts = {};
  }
  if (!opts.model) {
    throw new Error('No bookshelf model specified.');
  }
  this.model = opts.model;
}

Source.prototype.filters = function () {
  return this.model.filters||{};
};

Source.prototype.relations = function () {
  return this.model.relations||{};
};

Source.prototype.filter = function (params) {
  if (!params) {
    params = {};
  }
  var filters = this.filters();
  // open query builder for this model
  return this.model.collection().query(function (qb) {
    // iterate over all params we explicitly support in the request
    // filtering the query
    qb = Object.keys(params).reduce(function (result, key) {
      var value = params[key];
      // see if there is a finder on the model for this param
      var filter = filters[key];
      // process the query with the filter, or, if none is found, pass it along
      return filter ? filter.call(filters, qb, value, params) : qb;
    }, qb);
  });
};

Source.prototype.fetch = function (query, relations, cb) {
  query.fetch({
    withRelated: relations||[]
  }).exec(cb);
};


// The following two methods are absolutely atrocious.
// They format Bookshelf queries to be json-api compliant.
// Something absolutely must be upstreamed into bookshelf to
// support this, or an entirely different approach must be taken.
// I miss ruby.
function unnest (node) {
  var output = [];
  var resource = node.attributes;
  // if the node has attributes, we've hit a single model
  if (resource) {
    // unnest all of its relations
    var relations = node.relations;
    var links = {};
    if (!_.isEmpty(relations)) {
      resource.links = links;
    }
    Object.keys(relations).forEach(function (relationName) {
      // link the relation ids to the base model
      var relation = relations[relationName];
      // if the relation has attributes, it's a hasOne
      if (relation.attributes) {
        links[relationName] = relation.get('id');
      } else {
{'fraction_non_alphanumeric': 0.12503046551303923, 'fraction_numerical': 0.0, 'mean_word_length': 2.972894482090997, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4655220', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1157, 'n_words': 412}