<commit_before>var url = require('url');
var rel = require('zetta-rels');

module.exports = function(context) {
  var loader = context.loader;
  var env = context.env;
  var model = context.model;
  var actions = buildActions(model, env);
  var streams = buildStreamLinks(model, loader, env);
  var entity = {
    class: ['device'],
    properties: model.properties(),
    actions: actions,
    links: [{ rel: ['self'], href: env.helpers.url.path(loader.path + '/devices/' + model.id) },
            { title: context.serverName, rel: ['up', rel.server], href: env.helpers.url.path(loader.path) }]
  };

  if (entity.actions) {
    entity.actions.forEach(function(action) {
      if (!action.href) {
        action.href = env.helpers.url.path(loader.path + '/devices/' + model.id);
      }
    });
  }

  entity.links = entity.links.concat(streams);
  return entity;
};

var buildActions = function(model, env) {
  var actions = null;
  var transitions = model.transitionsAvailable();
  Object.keys(transitions).forEach(function(type) {
    var transition = transitions[type];
    var fields = transition.fields ? [].concat(transition.fields) : [];
    fields.push({ name: 'action', type: 'hidden', value: type });

    var action = {
      name: type,
      method: 'POST',
      href: null,
      fields: fields
    };
    if (!actions) {
      actions = [];
    }

    actions.push(action);
  });

  return actions;
};

var buildStreamLinks = function(model, loader, env) {
  var links = [];
  var eventPath = env.helpers.url.path(loader.path + '/events');
  var streams = model._streams;
  streams.logs = {}; // add logs to links
  Object.keys(streams).forEach(function(name) {
    var q = { topic: model.type + '/' + model.id + '/' + name };
    var streamRel = rel.objectStream;
    if (streams[name]._writableState && !streams[name]._writableState.objectMode) {
      streamRel = rel.binaryStream;
    }
    var stream = {
      title: name,
      rel: ['monitor', streamRel],
      href: eventPath.replace('http', 'ws') + url.format({ query: q})
    };
    links.push(stream);
  });

  return links;

};
<commit_msg>Exported build actions on formatter.<commit_after>var url = require('url');
var rel = require('zetta-rels');

module.exports = function(context) {
  var loader = context.loader;
  var env = context.env;
  var model = context.model;
  var actions = buildActions(model, env);
  var streams = buildStreamLinks(model, loader, env);
  var entity = {
    class: ['device'],
    properties: model.properties(),
    actions: actions,
    links: [{ rel: ['self'], href: env.helpers.url.path(loader.path + '/devices/' + model.id) },
            { title: context.serverName, rel: ['up', rel.server], href: env.helpers.url.path(loader.path) }]
  };

  if (entity.actions) {
    entity.actions.forEach(function(action) {
      if (!action.href) {
        action.href = env.helpers.url.path(loader.path + '/devices/' + model.id);
      }
    });
  }

  entity.links = entity.links.concat(streams);
  return entity;
};

var buildActions = module.buildActions = function(model, env) {
  var actions = null;
  var transitions = model.transitionsAvailable();
  Object.keys(transitions).forEach(function(type) {
    var transition = transitions[type];
    var fields = transition.fields ? [].concat(transition.fields) : [];
    fields.push({ name: 'action', type: 'hidden', value: type });

    var action = {
      name: type,
      method: 'POST',
      href: null,
      fields: fields
    };
    if (!actions) {
      actions = [];
    }

    actions.push(action);
  });

  return actions;
};

var buildStreamLinks = function(model, loader, env) {
  var links = [];
  var eventPath = env.helpers.url.path(loader.path + '/events');
  var streams = model._streams;
  streams.logs = {}; // add logs to links
  Object.keys(streams).forEach(function(name) {
    var q = { topic: model.type + '/' + model.id + '/' + name };
    var streamRel = rel.objectStream;
    if (streams[name]._writableState && !streams[name]._writableState.objectMode) {
      streamRel = rel.binaryStream;
    }
    var stream = {
      title: name,
      rel: ['monitor', streamRel],
      href: eventPath.replace('http', 'ws') + url.format({ query: q})
    };
    links.push(stream);
  });

  return links;

};

{'fraction_non_alphanumeric': 0.16383127476112794, 'fraction_numerical': 0.0, 'mean_word_length': 3.06824644549763, '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': '2999912', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1349, 'n_words': 309}