How to use the @sanity/mutator.extractWithPath function in @sanity/mutator

To help you get started, we’ve selected a few @sanity/mutator 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 / import / src / references.js View on Github external
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
}
github sanity-io / sanity / packages / @sanity / import / src / assetRefs.js View on Github external
function findAssetRefs(doc) {
  return extractWithPath(`..[${assetKey}]`, doc).map(match => match.path)
}
github sanity-io / gatsby-source-sanity / src / util / normalize.ts View on Github external
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
}
github sanity-io / sanity / packages / @sanity / import / src / references.js View on Github external
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)
}
github sanity-io / sanity / packages / @sanity / core / src / actions / dataset / import / getReferenceWeakener.js View on Github external
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)
}

@sanity/mutator

A set of models to make it easier to utilize the powerful real time collaborative features of Sanity

MIT
Latest version published 3 days ago

Package Health Score

98 / 100
Full package analysis