Détail du package

mendoza

sanity-io894.5kMIT3.0.8

Mendoza, differ for structured documents

mendoza, diff

readme

mendoza-js

npm stat npm version gzip size size

Mendoza decoder in TypeScript.

Installation

npm install mendoza

or

pnpm install mendoza

or

yarn add mendoza

Usage

Basic example:

import {applyPatch} from "mendoza"

let left = {…};
let patch = […];
let right = applyPatch(left, patch);

Incremental patcher:

import {incremental} from "mendoza"

const {Value, rebaseValue, wrap, unwrap, getType, applyPatch} = incremental

// Create an empty initial version:
const ROOT = wrap(null, null);

// Input of patches:
let patches = […];

// `origin` can be whatever you want to identify where a change comes from:
let origin = 0;

// Reference to the latest version:
let value = ROOT;

// Rebasing is for maintaing history across deleted versions:
let rebaseTarget;

for (let patch of patches) {
  // Apply the patch:
  let newValue = applyPatch(value, patch, origin);

  // Rebase if needed:
  if (rebaseTarget) {
    newValue = rebaseValue(rebaseTarget, newValue);
  }

  // If the document was deleted, store the previous version so we can rebase:
  if (getType(newValue) === "null") {
    rebaseTarget = value;
  } else {
    rebaseTarget = null;
  }

  value = newValue;
  origin++;
}

// Return the final full object:
console.log(unwrap(value));

License

MIT © Sanity.io

Release new version

Run the "CI & Release" workflow. Make sure to select the main branch and check "Release new version".

Semantic release will only release on configured branches, so it is safe to run release on any branch.

changelog

📓 Changelog

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.8 (2024-12-04)

Bug Fixes

  • stricter typescript output (8d27d5b)

3.0.7 (2024-04-11)

Bug Fixes

  • install snippets in README (19d0c17)

3.0.6 (2024-03-18)

Bug Fixes

  • deps: update dependency @sanity/pkg-utils to ^5.0.4 (#55) (6479553)

3.0.5 (2024-02-26)

Bug Fixes

  • deps: update dependency @sanity/pkg-utils to ^4.3.0 (#32) (b10eb77)

3.0.4 (2024-01-25)

Bug Fixes

  • deps: update dependency typescript to ^5.3.3 (#25) (ab0d3db)

3.0.3 (2023-08-04)

Bug Fixes

  • don't use TS private class fields (7ca1455)
  • Next.js build issue with the SimpleModel instance (393f721)

3.0.2 (2023-08-04)

Bug Fixes

  • don't use TS private class fields (65bba5a)

3.0.1 (2023-08-04)

Bug Fixes

  • solve issue affecting Next.js and swcMinify in production (7b4c271)

3.0.0 (2023-08-04)

⚠ BREAKING CHANGES

  • export modern ESM and CJS syntax
  • bump minimum required node to v14.18

Features

  • export modern ESM and CJS syntax (53c36bf)

Bug Fixes

  • bump minimum required node to v14.18 (f351fc1)

2.1.2 (2023-08-04)

Bug Fixes

  • setup release automation and provenance (14d24c7)