<commit_before>const { get } = require('lodash')

const { transformApiResponseToCollection } = require('../transformers')
const { buildSearchAggregation } = require('./builders')

/**
 * @param {object} [options] {object}
 * @param {string} [options.searchTerm] - search term used for highlighting words in collection macro
 * @param {object} [options.query] - URL query object used in pagination
 * @param {...function} [itemTransformers] - an array of transformer functions to apply for each item in the list
 * @returns {object, undefined}
 */
function transformApiResponseToSearchCollection (options = {}, ...itemTransformers) {
  /**
   * @param {object} response - API response object
   * @returns {function}
   */
  return function transformResponseToCollection (response) {
    if (!response) { return }

    const collection = transformApiResponseToCollection(options, ...itemTransformers)(response)

    return Object.assign({}, collection, {
      highlightTerm: get(options, 'searchTerm'),
      aggregations: buildSearchAggregation(response.aggregations),
    })
  }
}

module.exports = {
  transformApiResponseToSearchCollection,
}<commit_msg>send through user permissions to be used in collection transformer and passed through to search aggregation builder<commit_after>const { get } = require('lodash')

const { transformApiResponseToCollection } = require('../transformers')
const { buildSearchAggregation } = require('./builders')

/**
 * @param {object} [options] {object}
 * @param {string} [options.searchTerm] - search term used for highlighting words in collection macro
 * @param {object} [options.query] - URL query object used in pagination
 * @param {...function} [itemTransformers] - an array of transformer functions to apply for each item in the list
 * @returns {object, undefined}
 */
function transformApiResponseToSearchCollection (options = {}, ...itemTransformers) {
  /**
   * @param {object} response - API response object
   * @returns {function}
   */
  return function transformResponseToCollection (response) {
    if (!response) { return }

    const collection = transformApiResponseToCollection(options, ...itemTransformers)(response)

    return Object.assign({}, collection, {
      highlightTerm: get(options, 'searchTerm'),
      aggregations: buildSearchAggregation({
        aggregations: response.aggregations,
        userPermissions: get(options, 'userPermissions'),
      }),
    })
  }
}

module.exports = {
  transformApiResponseToSearchCollection,
}
{'fraction_non_alphanumeric': 0.11757672379434038, 'fraction_numerical': 0.0, 'mean_word_length': 4.49234135667396, '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': '6321692', 'n_tokens_mistral': 646, 'n_tokens_neox': 632, 'n_words': 193}