How to use the @sanity/validation.validateDocument function in @sanity/validation

To help you get started, we’ve selected a few @sanity/validation 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 / desk-tool / src / pane / DocumentPane.tsx View on Github external
validateDocument = async () => {
    const {draft, published} = this.props
    const doc = draft || published
    if (!doc || !doc._type) {
      return []
    }

    const type = schema.get(doc._type)
    if (!type) {
      // eslint-disable-next-line no-console
      console.warn('Schema for document type "%s" not found, skipping validation')
      return []
    }

    const markers = await validateDocument(doc, schema)
    this.setStateIfMounted({markers, validationPending: false})
    return markers
  }
github sanity-io / sanity / packages / @sanity / desk-tool / src / pane / DocumentPane.js View on Github external
validateDocument = async () => {
      const {draft, published} = this.getDocumentSnapshots()
      const doc = draft || published
      if (!doc || !doc._type) {
        return []
      }

      const type = schema.get(doc._type)
      if (!type) {
        // eslint-disable-next-line no-console
        console.warn('Schema for document type "%s" not found, skipping validation')
        return []
      }

      const markers = await validateDocument(doc, schema)
      this.setStateIfMounted({markers, validationPending: false})
      return markers
    }
github sanity-io / sanity / packages / @sanity / desk-tool / src / pane / EditorWrapper.js View on Github external
validateDocument = async () => {
    const {draft, published} = this.state
    const doc = (draft && draft.snapshot) || (published && published.snapshot)
    if (!doc || !doc._type) {
      return []
    }

    const type = schema.get(doc._type)
    if (!type) {
      // eslint-disable-next-line no-console
      console.warn('Schema for document type "%s" not found, skipping validation')
      return []
    }

    const markers = await validateDocument(doc, schema)
    this.setStateIfMounted({markers, validationPending: false})
    return markers
  }
github sanity-io / sanity / packages / @sanity / desk-tool / src / pane / EditorPane.js View on Github external
validateDocument = async () => {
      const {draft, published} = this.state
      const doc = (draft && draft.snapshot) || (published && published.snapshot)
      if (!doc || !doc._type) {
        return []
      }

      const type = schema.get(doc._type)
      if (!type) {
        // eslint-disable-next-line no-console
        console.warn('Schema for document type "%s" not found, skipping validation')
        return []
      }

      const markers = await validateDocument(doc, schema)
      this.setStateIfMounted({markers, validationPending: false})
      return markers
    }
github sanity-io / sanity / packages / @sanity / base / src / datastores / document / document-pair / editState.ts View on Github external
function getValidationMarkers(draft, published): Observable {
  const doc = draft || published
  if (!doc || !doc._type) {
    return of([])
  }
  return from(validateDocument(doc, schema) as Promise)
}

@sanity/validation

Validation and warning infrastructure for Sanity projects

MIT
Latest version published 1 year ago

Package Health Score

81 / 100
Full package analysis