<commit_before>import {ReferenceInput} from 'role:@sanity/form-builder'
import client from 'client:@sanity/base/client'
import {unprefixType} from '../utils/unprefixType'

function fetchSingle(id) {
  return client.fetch('*[.$id == %id]', {id}).then(response => unprefixType(response.result[0]))
}

export default ReferenceInput.createBrowser({
  fetch(field) {

    const toFieldTypes = field.to.map(toField => toField.type)

    const params = toFieldTypes.reduce((acc, toFieldType, i) => {
      acc[`toFieldType${i}`] = `beerfiesta.${toFieldType}`
      return acc
    }, {})

    const eqls = Object.keys(params).map(key => (
      `.$type == %${key}`
    )).join(' || ')

    return client.fetch(`*[${eqls}]`, params)
      .then(response => response.result.map(unprefixType))
  },
  materializeReferences(referenceIds) {
    return Promise.all(referenceIds.map(fetchSingle))
  }
})<commit_msg>Make reference input use new Sanity client syntax<commit_after>import client from 'client:@sanity/base/client'
import {ReferenceInput} from 'role:@sanity/form-builder'
import {unprefixType} from '../utils/unprefixType'

function fetchSingle(id) {
  return client.data.getDocument(id).then(doc => unprefixType(doc))
}

export default ReferenceInput.createBrowser({
  fetch(field) {
    const toFieldTypes = field.to.map(toField => toField.type)
    const dataset = client.config().dataset
    const params = toFieldTypes.reduce((acc, toFieldType, i) => {
      acc[`toFieldType${i}`] = `${dataset}.${toFieldType}`
      return acc
    }, {})

    const eqls = Object.keys(params).map(key => (
      `.$type == %${key}`
    )).join(' || ')

    return client.data.fetch(`*[${eqls}]`, params)
      .then(response => response.map(unprefixType))
  },

  materializeReferences(referenceIds) {
    return Promise.all(referenceIds.map(fetchSingle))
  }
})
{'fraction_non_alphanumeric': 0.17045454545454544, 'fraction_numerical': 0.0005411255411255411, 'mean_word_length': 4.267806267806268, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4015885', 'n_tokens_mistral': 598, 'n_tokens_neox': 594, 'n_words': 108}