Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@sanity/mutate

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/mutate

Experimental toolkit for working with Sanity mutations in JavaScript & TypeScript

latest
Source
npmnpm
Version
0.18.1
Version published
Weekly downloads
1M
16.23%
Maintainers
2
Weekly downloads
 
Created
Source

@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://mutate.sanity.dev (sources in docs/; run the site locally with pnpm docs:dev):

License

MIT

Keywords

sanity

FAQs

Package last updated on 11 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts