JSPM

  • Created
  • Published
  • Downloads 1242003
  • Score
    100M100P100Q204816F
  • License MIT

Experimental toolkit for working with Sanity mutations in JavaScript & TypeScript

Package Exports

  • @sanity/mutate
  • @sanity/mutate/_unstable_apply
  • @sanity/mutate/_unstable_machine
  • @sanity/mutate/_unstable_store
  • @sanity/mutate/package.json
  • @sanity/mutate/path

Readme

@sanity/mutate

@sanity/mutate

[!NOTE] Experimental. Use at your own risk.

A TypeScript toolkit for Sanity mutations:

  • Declarative, composable mutation creators
  • A pure, in-memory apply engine
  • An optimistic local store with rebase semantics

Install

npm install @sanity/mutate

Example

import {
  at,
  create,
  createIfNotExists,
  patch,
  SanityEncoder,
  set,
  setIfMissing,
} from '@sanity/mutate'

const projectId = '<projectId>'
const dataset = '<dataset>'

const mutations = [
  create({_type: 'dog', name: 'Fido'}),
  createIfNotExists({_id: 'document-1', _type: 'someType'}),
  patch('other-document', [
    at('published', set(true)),
    at('address', setIfMissing({_type: 'address'})),
    at('address.city', set('Oslo')),
  ]),
]

await fetch(
  `https://${projectId}.api.sanity.io/v2026-05-12/data/mutate/${dataset}`,
  {
    method: 'POST',
    mode: 'cors',
    credentials: 'include',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(SanityEncoder.encodeAll(mutations)),
  },
)

Documentation

Full reference and guides at https://sanity-io.github.io/mutate (sources in docs/; run the site locally with pnpm docs:dev):

License

MIT