<commit_before>/**
 * Define outbound to load entity refs
 * @function refOutbound
 * @param {ClayResource} refResource - Resource of entities
 * @returns {function} Outbound function
 */
'use strict'

const {isEntity} = require('clay-entity')
const {parse: parseRef, refTo} = require('clay-resource-ref')
const {LogPrefixes} = require('clay-constants')
const clayResourceName = require('clay-resource-name')
const {RESOURCE_PREFIX} = LogPrefixes

/** @lends refOutbound */
function refOutbound (refResource) {
  const refResourceName = String(clayResourceName(refResource))

  async function outboundAttribute (resourceName, name, attribute, actionContext) {
    const {skipResolvingRefFor = []} = actionContext
    const skip = skipResolvingRefFor.includes(refResourceName)
    if (skip) {
      return attribute
    }

    if (Array.isArray(attribute)) {
      return Promise.all(
        attribute.map((attribute) => outboundAttribute(resourceName, name, attribute, actionContext))
      )
    }
    if (isEntity(attribute)) {
      if (!attribute.$$as) {
        console.warn(`${RESOURCE_PREFIX} You cannot use "${attribute}" as ref of "${name}" since it is not annotated`)
        return attribute
      }
      const hit = String(attribute.$$as) === refResourceName
      if (hit) {
        attribute = {$ref: refTo(refResource, attribute.id)}
      }
    }
    const isNullRef = attribute && attribute.hasOwnProperty('$ref') && attribute.$ref === null
    if (isNullRef) {
      return null
    }
    const $ref = parseRef(attribute && attribute.$ref)
    if (!$ref) {
      return attribute
    }
    const hit = String($ref.resource) === refResourceName
    if (hit) {
      return refResource.one($ref.id, {
        skipResolvingRefFor: [...skipResolvingRefFor, resourceName].filter(Boolean)
      })
    }

    return attribute
  }

  /**
   * @function refOutbound
   * @param {Entity[]} - Entities
   * @param {Object} [actionContext={}]
   * @returns {Promise.<Entity[]>}
   */
  return async function outbound (resource, entities, actionContext = {}) {
    const resourceName = String(clayResourceName(resource))
    for (const entity of entities) {
      for (const name of Object.keys(entity)) {
        const attribute = entity[name]
        entity[name] = await outboundAttribute(resourceName, name, attribute, actionContext)
      }
    }
    return entities
  }<commit_msg>Add cache ignore<commit_after>/**
 * Define outbound to load entity refs
 * @function refOutbound
 * @param {ClayResource} refResource - Resource of entities
 * @returns {function} Outbound function
 */
'use strict'

const {isEntity} = require('clay-entity')
const {parse: parseRef, refTo} = require('clay-resource-ref')
const {LogPrefixes} = require('clay-constants')
const clayResourceName = require('clay-resource-name')
const {RESOURCE_PREFIX} = LogPrefixes

/** @lends refOutbound */
function refOutbound (refResource) {
  const refResourceName = String(clayResourceName(refResource))

  async function outboundAttribute (resourceName, name, attribute, actionContext) {
    const {skipResolvingRefFor = [], ignoreCached = false} = actionContext
    const skip = skipResolvingRefFor.includes(refResourceName)
    if (skip) {
      return attribute
    }

    if (Array.isArray(attribute)) {
      return Promise.all(
        attribute.map((attribute) => outboundAttribute(resourceName, name, attribute, actionContext))
      )
    }
    if (isEntity(attribute)) {
      if (!attribute.$$as) {
        console.warn(`${RESOURCE_PREFIX} You cannot use "${attribute}" as ref of "${name}" since it is not annotated`)
        return attribute
      }
      const hit = String(attribute.$$as) === refResourceName
      if (hit) {
        attribute = {$ref: refTo(refResource, attribute.id)}
      }
    }
    const isNullRef = attribute && attribute.hasOwnProperty('$ref') && attribute.$ref === null
    if (isNullRef) {
      return null
    }
    const $ref = parseRef(attribute && attribute.$ref)
    if (!$ref) {
      return attribute
    }
    const hit = String($ref.resource) === refResourceName
    if (hit) {
      return refResource.one($ref.id, {
        ignoreCached,
        skipResolvingRefFor: [...skipResolvingRefFor, resourceName].filter(Boolean)
      })
    }

    return attribute
  }

  /**
   * @function refOutbound
   * @param {Entity[]} - Entities
   * @param {Object} [actionContext={}]
   * @returns {Promise.<Entity[]>}
   */
  return async function outbound (resource, entities, actionContext = {}) {
    const resourceName = String(clayResourceName(resource))
    for (const entity of entities) {
      for (const name of Object.keys(entity)) {
        const attribute = entity[name]
        entity[name] = await outboundAttribute(resourceName, name, attribute, actionContext)
      }
    }
    return entities
  }
{'fraction_non_alphanumeric': 0.12549100682241057, 'fraction_numerical': 0.0, 'mean_word_length': 3.394187102633969, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4866037', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1374, 'n_words': 355}