<commit_before>import oneline from 'oneline'
import {isPlainObject} from 'lodash'
import {randomKey, toString as pathToString} from '@sanity/util/paths'
import {Template} from './Template'
import {TemplateParameter} from './TemplateParameters'
import {getDefaultSchema} from './parts/Schema'

export {validateInitialValue, validateTemplates}

const ALLOWED_REF_PROPS = ['_key', '_ref', '_weak', '_type']
const REQUIRED_TEMPLATE_PROPS: (keyof Template)[] = ['id', 'title', 'schemaType', 'value']

function validateTemplates(templates: Template[]) {
  const idMap = new Map()

  templates.forEach((template, i) => {
    const id = templateId(template, i)
    const missing = REQUIRED_TEMPLATE_PROPS.filter(prop => !template[prop])
    if (missing.length > 0) {
      throw new Error(`Template ${id} is missing required properties: ${missing.join(', ')}`)
    }

    if (typeof template.value !== 'function' && !isPlainObject(template.value)) {<commit_msg>[initial-value-templates] Add validation for plural values mismatch<commit_after>import oneline from 'oneline'
import {isPlainObject} from 'lodash'
import {randomKey, toString as pathToString} from '@sanity/util/paths'
import {Template} from './Template'
import {TemplateParameter} from './TemplateParameters'
import {getDefaultSchema} from './parts/Schema'

export {validateInitialValue, validateTemplates}

const ALLOWED_REF_PROPS = ['_key', '_ref', '_weak', '_type']
const REQUIRED_TEMPLATE_PROPS: (keyof Template)[] = ['id', 'title', 'schemaType', 'value']

function validateTemplates(templates: Template[]) {
  const idMap = new Map()

  templates.forEach((template, i) => {
    const id = templateId(template, i)

    if (typeof (template as {[key: string]: any}).values !== 'undefined' && !template.value) {
      throw new Error(`Template ${id} is missing "value" property, but contained "values". Typo?`)
    }

    const missing = REQUIRED_TEMPLATE_PROPS.filter(prop => !template[prop])
    if (missing.length > 0) {
      throw new Error(`Template ${id} is missing required properties: ${missing.join(', ')}`)
    }

    if (typeof template.value !== 'function' && !isPlainObject(template.value)) {
{'fraction_non_alphanumeric': 0.14801110083256244, 'fraction_numerical': 0.0009250693802035153, 'mean_word_length': 5.380530973451328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6436615', 'n_tokens_mistral': 651, 'n_tokens_neox': 638, 'n_words': 183}