<commit_before>var Url = require('url');
var Path = require('path');
var Class = require('es-class');
var extend = require('xtend');
var traverse = require('traverse');
var _ = require('lodash');
var debug = require('debug')('base-service');

var config = require('config');

var stripSlashes = function (name) {
  return name.replace(/^\/|\/$/g, '');
};

module.exports = Class({
  constructor: function _BaseService_constructor (options) {
    
    var httpConfig = options.httpConfig || config.api || {};

    this.protocol = httpConfig.protocol || "http";
    this.hostname = httpConfig.hostname || "localhost";
    this.port = httpConfig.port || 3000;
    this.prefix = stripSlashes(httpConfig.prefix || "");
    this.prefixRe = new RegExp("^" + this.prefix);

    this.context = options.context || this.context || {};
    this.collection = options.collection || this.collection || "";

    this.storage = options.storage;

    // re-assign props so enumerable, otherwise deleting during
    // https://github.com/feathersjs/feathers/blob/master/lib/application.js#L27
    // TODO fix this in es-class
    this.urlId = this.urlId;
    this.get = this.get;
    this.find = this.find;
  },

  urlId: function _BaseService_urlId (id) {
    debug("urlId(", id, ")");

    id = Url.format({
      protocol: this.protocol,
      hostname: this.hostname,
      port: this.port,
      pathname: Path.join(this.prefix, id || ""),
    });

    debug("urlId() ->", id);
    return id;
  },

  find: function _BaseService_find (params, cb) {
    debug("find(", params, ")");

    return this.storage.find(params, function (err, objs) {
      if (err) { return cb(err); }

      var urlId = this.urlId.bind(this);
      var ret = {
        '@graph': objs.map(function (obj) {
          return traverse(obj).map(function () {
            if (this.node['@id']) {
              this.node['@id'] = urlId(this.node['@id']);
            }
          });
        }, this),
        '@context': this.context,
      };

      debug("find() ->", ret);
      return cb(null, ret);

    }.bind(this));
  },

  get: function _BaseService_get (id, params, cb) {
    debug("get(", id, params, ")");

    return this.storage.get(id, params, function (err, graph) {
      if (err) { return cb(err); }

      var ret = {
        '@graph': [],
        '@context': this.context,
      };
      _.each(graph, function (obj, id) {
        var urlId = this.urlId.bind(this);
        entity = traverse(obj).map(function () {
          if (this.node['@id']) {
            this.node['@id'] = urlId(this.node['@id']);
          }
        });
        ret['@graph'].push(obj);
      }, this)

      debug("get() ->", ret);
      return cb(null, ret);

    }.bind(this));
  },

  create: function () {
  },
  update: function () {
  },
  patch: function () {
  },
  remove: function () {
  },
});
<commit_msg>properly set @id's in base service get<commit_after>var Url = require('url');
var Path = require('path');
var Class = require('es-class');
var extend = require('xtend');
var traverse = require('traverse');
var _ = require('lodash');
var debug = require('debug')('base-service');

var config = require('config');

var stripSlashes = function (name) {
  return name.replace(/^\/|\/$/g, '');
};

module.exports = Class({
  constructor: function _BaseService_constructor (options) {
    
    var httpConfig = options.httpConfig || config.api || {};

    this.protocol = httpConfig.protocol || "http";
    this.hostname = httpConfig.hostname || "localhost";
    this.port = httpConfig.port || 3000;
    this.prefix = stripSlashes(httpConfig.prefix || "");
    this.prefixRe = new RegExp("^" + this.prefix);

    this.context = options.context || this.context || {};
    this.collection = options.collection || this.collection || "";

    this.storage = options.storage;

    // re-assign props so enumerable, otherwise deleting during
    // https://github.com/feathersjs/feathers/blob/master/lib/application.js#L27
    // TODO fix this in es-class
    this.urlId = this.urlId;
    this.get = this.get;
    this.find = this.find;
  },

  urlId: function _BaseService_urlId (id) {
    debug("urlId(", id, ")");

    id = Url.format({
      protocol: this.protocol,
      hostname: this.hostname,
      port: this.port,
      pathname: Path.join(this.prefix, id || ""),
    });

    debug("urlId() ->", id);
    return id;
  },

  find: function _BaseService_find (params, cb) {
    debug("find(", params, ")");

    return this.storage.find(params, function (err, objs) {
      if (err) { return cb(err); }

      var urlId = this.urlId.bind(this);
      var ret = {
        '@graph': objs.map(function (obj) {
          return traverse(obj).map(function () {
            if (this.node['@id']) {
              this.node['@id'] = urlId(this.node['@id']);
            }
          });
        }, this),
        '@context': this.context,
      };

      debug("find() ->", ret);
      return cb(null, ret);

    }.bind(this));
  },

  get: function _BaseService_get (id, params, cb) {
    debug("get(", id, params, ")");

    return this.storage.get(id, params, function (err, graph) {
      if (err) { return cb(err); }

      var urlId = this.urlId.bind(this);
      var ret = {
        '@graph': _.map(graph, function (obj) {
          return traverse(obj).map(function () {
            if (this.key === '@id') {
              this.update(urlId(this.node));
            }
          });
        }, this),
        '@context': this.context,
      };

      debug("get() ->", ret);
      return cb(null, ret);

    }.bind(this));
  },

  create: function () {
  },
  update: function () {
  },
  patch: function () {
  },
  remove: function () {
  },
});

{'fraction_non_alphanumeric': 0.18396639243829863, 'fraction_numerical': 0.002100472606336426, 'mean_word_length': 2.5098280098280097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '6068546', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1815, 'n_words': 392}