Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
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
}
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
}
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
}
function getValidationMarkers(draft, published): Observable {
const doc = draft || published
if (!doc || !doc._type) {
return of([])
}
return from(validateDocument(doc, schema) as Promise)
}