Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setTypeOnReferences(doc) {
extractWithPath('..[_ref]', doc)
.map(match => match.path.slice(0, -1))
.map(path => ({path, ref: get(doc, path)}))
.filter(item => typeof item.ref._type === 'undefined')
.forEach(item => {
item.ref._type = 'reference'
})
return doc
}
function findAssetRefs(doc) {
return extractWithPath(`..[${assetKey}]`, doc).map(match => match.path)
}
function rewriteNodeReferences(doc: SanityDocument, options: ProcessingOptions) {
const {createNodeId} = options
const refs = extractWithPath('..[_ref]', doc)
if (refs.length === 0) {
return doc
}
const newDoc = cloneDeep(doc)
refs.forEach(match => {
set(newDoc, match.path, safeId(match.value, createNodeId))
})
return newDoc
}
function findStrongRefs(doc) {
return extractWithPath('..[_ref]', doc)
.map(match => match.path.slice(0, -1))
.map(path => ({path, ref: get(doc, path)}))
.filter(item => item.ref._weak !== true)
}
function findStrongRefs(doc) {
return extractWithPath('..[_ref]', doc)
.map(match => match.path.slice(0, -1))
.map(path => ({path, ref: get(doc, path)}))
.filter(item => item.ref._weak !== true)
}