How to use the @sanity/util/paths.randomKey function in @sanity/util

To help you get started, we’ve selected a few @sanity/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / initial-value-templates / src / validate.ts View on Github external
if (Array.isArray(item)) {
        throw new Error(
          `multidimensional arrays are not supported (at path "${pathToString(path)}")`
        )
      }

      return validateValue(item, path.concat(i), true)
    })
  }

  if (!isPlainObject(value)) {
    return value
  }

  // Apply missing keys is the parent is an array
  const initial: {[key: string]: any} = parentIsArray && !value._key ? {_key: randomKey()} : {}

  // Ensure non-root objects have _type
  if (path.length > 0 && !value._type) {
    if (value._ref) {
      // In the case of references, we know what the type should be, so apply it
      initial._type = 'reference'
    } else {
      throw new Error(`missing "_type" property at path "${pathToString(path)}"`)
    }
  }

  if (value._ref) {
    validateReference(value, path)
  }

  // Validate deeply