<commit_before>var path = require('path');

var middleware = module.exports = {
  exec: function (request, response, next) {
    var ids;

    // 404 if document(s) not found or 0 documents removed
    if (!request.baucis.documents) return response.send(404);

    if (!Array.isArray(request.baucis.documents)
      || request.baucis.documents.length === 1) {
      request.baucis.location = path.join(request.app.get('basePath'), request.baucis.documents.id);
    }
    else {
      ids = request.baucis.documents.map(function (doc) { return doc.id });
      request.baucis.location = request.app.get('basePath') + '?conditions={ _id: { $in: [' + ids.join() + '] } }';
    }

    response.json(request.baucis.documents);
  },
  count: function (request, response, next) {
    // 404 if no matching documents
    if (request.baucis.count === 0) return response.send(404);
    response.json(request.baucis.count);
  },
  stream: function (request, response, next) {
    var firstWasProcessed = false;

    request.baucis.stream.resume();

    response.set('Content-Type', 'application/json');
    response.write('[');

    request.baucis.stream.on('error', next);
    request.baucis.stream.on('data', function (doc) {
      if (firstWasProcessed) response.write(',');
      response.write(JSON.stringify(doc.toJSON()));
      firstWasProcessed = true;<commit_msg>Don't set location when documents is a number<commit_after>var path = require('path');

var middleware = module.exports = {
  exec: function (request, response, next) {
    var ids;

    // 404 if document(s) not found or 0 documents removed
    if (!request.baucis.documents) return response.send(404);

    // If it's a document count (e.g. the result of a DELETE), send it back and short-circuit
    if (typeof request.baucis.documents === 'number') {
      return response.json(request.baucis.documents);
    }

    // Otherwise, set the location and send JSON document(s)
    if (!Array.isArray(request.baucis.documents)
      || request.baucis.documents.length === 1) {
      request.baucis.location = path.join(request.app.get('basePath'), request.baucis.documents.id);
    }
    else {
      ids = request.baucis.documents.map(function (doc) { return doc.id });
      request.baucis.location = request.app.get('basePath') + '?conditions={ _id: { $in: [' + ids.join() + '] } }';
    }

    response.json(request.baucis.documents);
  },
  count: function (request, response, next) {
    // 404 if no matching documents
    if (request.baucis.count === 0) return response.send(404);
    response.json(request.baucis.count);
  },
  stream: function (request, response, next) {
    var firstWasProcessed = false;

    request.baucis.stream.resume();

    response.set('Content-Type', 'application/json');
    response.write('[');

    request.baucis.stream.on('error', next);
    request.baucis.stream.on('data', function (doc) {
      if (firstWasProcessed) response.write(',');
      response.write(JSON.stringify(doc.toJSON()));
      firstWasProcessed = true;
{'fraction_non_alphanumeric': 0.15587846763540292, 'fraction_numerical': 0.009907529722589167, 'mean_word_length': 3.441348973607038, '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': '4581530', 'n_tokens_mistral': 999, 'n_tokens_neox': 945, 'n_words': 206}