<commit_before>/*
eslint
no-console: 0,
@typescript-eslint/explicit-function-return-type: 0,
@typescript-eslint/no-explicit-any: 0
*/
import inflection from 'inflection'

export default function makeFindMixin(options) {
  const {
    service,
    params,
    fetchParams,
    queryWhen,
    id,
    local = false,
    qid = 'default',
    item,
    debug
  } = options
  let { name, watch = [] } = options

  if (typeof watch === 'string') {
    watch = [watch]
  } else if (typeof watch === 'boolean' && watch) {
    watch = ['query']
  }

  if (
    !service ||
    (typeof service !== 'string' && typeof service !== 'function')
  ) {
    throw new Error(
      `The 'service' option is required in the FeathersVuex make-find-mixin and must be a string.`
    )
  }
  if (typeof service === 'function' && !name) {
    name = 'service'
  }

  const nameToUse = (name || service).replace('-', '_')
  const singularized = inflection.singularize(nameToUse)
  const prefix = inflection.camelize(singularized, true)
  const capitalized = prefix.charAt(0).toUpperCase() + prefix.slice(1)
  const SERVICE_NAME = `${prefix}ServiceName`
  let ITEM = item || prefix
  if (typeof service === 'function' && name === 'service' && !item) {
    ITEM = 'item'
  }
  const IS_GET_PENDING = `isGet${capitalized}Pending`
  const PARAMS = `${prefix}Params`
  const FETCH_PARAMS = `${prefix}FetchParams`
  const WATCH = `${prefix}Watch`
  const QUERY_WHEN = `${prefix}QueryWhen`
  const GET_ACTION = `get${capitalized}`
  const LOCAL = `${prefix}Local`
  const QID = `${prefix}Qid`
  const ID = `${prefix}Id`
  const data = {
    [IS_GET_PENDING]: false,
    [WATCH]: watch,
    [QID]: qid
  }

  const mixin = {
    data() {
      return data
    },
    computed: {
      [ITEM]() {
        return this[ID]
          ? this.$store.getters[`${this[SERVICE_NAME]}/get`](this[ID])
          : null
      },
      [QUERY_WHEN]() {
        return true
      }
    },
    methods: {
      [GET_ACTION](id, params) {
        const paramsToUse = params || this[FETCH_PARAMS] || this[PARAMS]
        const idToUse = id || this[ID]

        if (!this[LOCAL]) {
          if (this[QUERY_WHEN]) {
            this[IS_GET_PENDING] = true

            if (idToUse != null) {<commit_msg>Add `get<Item>FromStore` to makeFindGetter<commit_after>/*
eslint
no-console: 0,
@typescript-eslint/explicit-function-return-type: 0,
@typescript-eslint/no-explicit-any: 0
*/
import inflection from 'inflection'

export default function makeFindMixin(options) {
  const {
    service,
    params,
    fetchParams,
    queryWhen,
    id,
    local = false,
    qid = 'default',
    item,
    debug
  } = options
  let { name, watch = [] } = options

  if (typeof watch === 'string') {
    watch = [watch]
  } else if (typeof watch === 'boolean' && watch) {
    watch = ['query']
  }

  if (
    !service ||
    (typeof service !== 'string' && typeof service !== 'function')
  ) {
    throw new Error(
      `The 'service' option is required in the FeathersVuex make-find-mixin and must be a string.`
    )
  }
  if (typeof service === 'function' && !name) {
    name = 'service'
  }

  const nameToUse = (name || service).replace('-', '_')
  const singularized = inflection.singularize(nameToUse)
  const prefix = inflection.camelize(singularized, true)
  const capitalized = prefix.charAt(0).toUpperCase() + prefix.slice(1)
  const SERVICE_NAME = `${prefix}ServiceName`
  let ITEM = item || prefix
  if (typeof service === 'function' && name === 'service' && !item) {
    ITEM = 'item'
  }
  const IS_GET_PENDING = `isGet${capitalized}Pending`
  const PARAMS = `${prefix}Params`
  const FETCH_PARAMS = `${prefix}FetchParams`
  const WATCH = `${prefix}Watch`
  const QUERY_WHEN = `${prefix}QueryWhen`
  const GET_ACTION = `get${capitalized}`
  const GET_GETTER = `get${capitalized}FromStore`
  const LOCAL = `${prefix}Local`
  const QID = `${prefix}Qid`
  const ID = `${prefix}Id`
  const data = {
    [IS_GET_PENDING]: false,
    [WATCH]: watch,
    [QID]: qid
  }

  const mixin = {
    data() {
      return data
    },
    computed: {
      [ITEM]() {
        return this[ID]
          ? this.$store.getters[`${this[SERVICE_NAME]}/get`](this[ID])
          : null
      },
      [QUERY_WHEN]() {
        return true
      },
      // Exposes `get<Item>FromStore`
      [GET_GETTER]() {
        return id => {
          const serviceName = this[SERVICE_NAME]
          return this.$store.getters[`${serviceName}/get`](id)
        }
      }
    },
    methods: {
      [GET_ACTION](id, params) {
        const paramsToUse = params || this[FETCH_PARAMS] || this[PARAMS]
        const idToUse = id || this[ID]

        if (!this[LOCAL]) {
          if (this[QUERY_WHEN]) {
            this[IS_GET_PENDING] = true

            if (idToUse != null) {
{'fraction_non_alphanumeric': 0.15193830762817842, 'fraction_numerical': 0.0020842017507294707, 'mean_word_length': 2.74921875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5357238', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1644, 'n_words': 376}