sanity-diff-patch
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -162,3 +162,3 @@ 'use strict'; | ||
var idPattern = /^[a-z0-9][a-z0-9_.-]+$/i; | ||
var keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]+$/; | ||
var keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||
var keyStartPattern = /^[a-z_]/i; | ||
@@ -165,0 +165,0 @@ function validateDocument(item, path) { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("diff-match-patch");function e(){return(e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function o(t,e,r){return(o=i()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return r&&n(o,r.prototype),o}).apply(null,arguments)}function a(t){var e="function"==typeof Map?new Map:void 0;return(a=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return o(t,arguments,r(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)})(t)}function u(t){return t.reduce((function(t,e,r){if(Array.isArray(e))return t+"["+e.join(":")+"]";if("object"==typeof(n=e)&&"string"==typeof n._key)return t+'[_key=="'+e._key+'"]';var n;if("number"==typeof e)return t+"["+e+"]";if(/^\d+$/.test(e))return t+'["'+e+'"]';if("string"==typeof e)return t+(0===r?"":".")+e;throw new Error('Unsupported path segment "'+e+'"')}),"")}var c=function(t){var e,r;function n(e,r,n){var i,o=u(r);return(i=t.call(this,e+" (at '"+o+"')")||this).path=r,i.serializedPath=o,i.value=n,i}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(a(Error)),f=/^[a-z0-9][a-z0-9_.-]+$/i,s=/^[a-zA-Z_][a-zA-Z0-9_]+$/,p=/^[a-z_]/i;function h(t,e,r){if(!p.test(t))throw new c("Keys must start with a letter (a-z)",r.concat(t),e);if(!s.test(t))throw new c("Keys can only contain letters, numbers and underscores",r.concat(t),e);if("_key"===t||"_ref"===t||"_type"===t){if("string"!=typeof e)throw new c("Keys must be strings",r.concat(t),e);if(!f.test(e))throw new c("Invalid key - use less exotic characters",r.concat(t),e)}return t}var l=["_id","_type","_createdAt","_updatedAt","_rev"],y=new t.diff_match_patch,d={hideWarnings:!1,diffMatchPatch:{enabled:!0,lengthThresholdAbsolute:30,lengthThresholdRelative:1.2}};function v(t,e,r,n,i){if(void 0===r&&(r=d),void 0===n&&(n=[]),void 0===i&&(i=[]),t===e)return i;var o=Array.isArray(t)?"array":typeof t,a=Array.isArray(e)?"array":typeof e,u="undefined"===o,f="undefined"===a;if(u&&!f)return i.push({op:"set",path:n,value:e}),i;if(!u&&f)return i.push({op:"unset",path:n}),i;var s=u?a:o;return"object"===s||"array"===s?o!==a?(i.push({op:"set",path:n,value:e}),i):"array"===s?function(t,e,r,n,i){if(e.length>t.length&&i.push({op:"insert",after:n.concat([-1]),items:e.slice(t.length).map((function(t,e){return w(t,n,e,r)}))}),e.length<t.length){var o=t.length-e.length==1,a=t.slice(e.length);!function(t){return Boolean(t.ifRevisionID||t.ifRevisionId)}(r)&&b(a)?i.push.apply(i,a.map((function(t){return{op:"unset",path:n.concat({_key:t._key})}}))):i.push({op:"unset",path:n.concat([o?e.length:[e.length,""]])})}for(var u=0;u<e.length;u++)if(Array.isArray(e[u]))throw new c("Multi-dimensional arrays not supported",n.concat(u),e[u]);var f=Math.min(t.length,e.length),s=t.slice(0,f),p=e.slice(0,f);return b(s)&&b(p)?function(t,e,r,n,i){var o=m(t),a=m(e);if(!function(t,e){return t.length===e.length&&t.every((function(t,r){return e[r]===t}))}(o.keys,a.keys))return g(t,e,r,n,i);for(var u=0;u<a.keys.length;u++){var c=a.keys[u];v(o.index[c],w(a.index[c],n,u,r),r,n.concat({_key:c}),i)}return i}(s,p,r,n,i):g(s,p,r,n,i)}(t,e,r,n,i):function(t,e,r,n,i){for(var o=0===n.length,a=Object.keys(t).filter(o?_:k).map((function(e){return h(e,t[e],n)})),u=a.length,c=Object.keys(e).filter(o?_:k).map((function(t){return h(t,e[t],n)})),f=c.length,s=0;s<u;s++){var p=a[s];p in e||i.push({op:"unset",path:n.concat(p)})}for(var l=0;l<f;l++){var y=c[l];v(t[y],e[y],r,n.concat([y]),i)}return i}(t,e,r,n,i):function(t,e,r,n,i){var o=function(t,e,r,n){var i=r.diffMatchPatch,o=i.lengthThresholdRelative,a=n[n.length-1];if(!(!i.enabled||"string"!=typeof t||"string"!=typeof e||"string"==typeof a&&"_"===a[0]||e.length<i.lengthThresholdAbsolute)){var u="";try{var c=y.diff_main(t,e);y.diff_cleanupEfficiency(c),u=y.patch_toText(y.patch_make(c))}catch(t){return}return u.length>e.length*o?void 0:{op:"diffMatchPatch",path:n,value:u}}}(t,e,r,n);return i.push(o||{op:"set",path:n,value:e}),i}(t,e,r,n,i)}function g(t,e,r,n,i){for(var o=0;o<t.length;o++)v(t[o],w(e[o],n,o,r),r,n.concat(o),i);return i}function _(t){return-1===l.indexOf(t)}function b(t){for(var e,r=[],n=0;n<t.length;n++){var i="object"==typeof(e=t[n])&&null!==e&&e._key;if(!i||-1!==r.indexOf(i))return!1;r.push(i)}return!0}function m(t){return t.reduce((function(t,e){return t.keys.push(e._key),t.index[e._key]=e,t}),{keys:[],index:{}})}function w(t,e,r,n){if(void 0!==t)return t;if(!n.hideWarnings){var i=u(e.concat(r));console.warn("undefined value in array converted to null (at '"+i+"')")}return null}function k(t){return!0}exports.DiffError=c,exports.diffItem=v,exports.diffPatch=function(t,r,n){var i=n?function(t){return e({},d,t,{diffMatchPatch:e({},d.diffMatchPatch,t.diffMatchPatch||{})})}(n):d,o=i.id||t._id===r._id&&t._id,a=i.ifRevisionID||i.ifRevisionId,c="boolean"==typeof a?t._rev:a,f=i.basePath||[];if(!o)throw new Error("_id on itemA and itemB not present or differs, specify document id the mutations should be applied to");if(!0===a&&!c)throw new Error("`ifRevisionID` is set to `true`, but no `_rev` was passed in item A. Either explicitly set `ifRevisionID` to a revision, or pass `_rev` as part of item A.");if(0===f.length&&t._type!==r._type)throw new Error("_type is immutable and cannot be changed ("+t._type+" => "+r._type+")");return function(t,r){if(0===t.length)return[];var n=r.id,i=r.ifRevisionID,o=t.filter((function(t){return"set"===t.op})),a=t.filter((function(t){return"unset"===t.op})),c=t.filter((function(t){return"insert"===t.op})),f=t.filter((function(t){return"diffMatchPatch"===t.op})),s=o.length>0&&o.reduce((function(t,e){var r=u(e.path);return t.set[r]=e.value,t}),{id:n,set:{}}),p=a.length>0&&a.reduce((function(t,e){var r=u(e.path);return t.unset.push(r),t}),{id:n,unset:[]}),h=c.reduce((function(t,e){var r=u(e.after);return t.concat({id:n,insert:{after:r,items:e.items}})}),[]);return[s,p,f.length>0&&f.reduce((function(t,e){var r=u(e.path);return t.diffMatchPatch[r]=e.value,t}),{id:n,diffMatchPatch:{}})].concat(h).filter((function(t){return!1!==t})).map((function(t,r){return{patch:i&&0===r?e({},t,{ifRevisionID:i}):t}}))}(v(t,r,i,f,[]),{id:o,ifRevisionID:a?c:void 0})},exports.pathToString=u,exports.validateDocument=function t(e,r){if(void 0===r&&(r=[]),Array.isArray(e))return e.every((function(e,n){if(Array.isArray(e))throw new c("Multi-dimensional arrays not supported",r.concat(n));return t(e,r.concat(n))}));if("object"==typeof e&&null!==e){var n=e;return Object.keys(n).every((function(e){return h(e,n[e],r)&&t(n[e],r.concat(e))}))}return!0}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("diff-match-patch");function e(){return(e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function o(t,e,r){return(o=i()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return r&&n(o,r.prototype),o}).apply(null,arguments)}function a(t){var e="function"==typeof Map?new Map:void 0;return(a=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return o(t,arguments,r(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)})(t)}function u(t){return t.reduce((function(t,e,r){if(Array.isArray(e))return t+"["+e.join(":")+"]";if("object"==typeof(n=e)&&"string"==typeof n._key)return t+'[_key=="'+e._key+'"]';var n;if("number"==typeof e)return t+"["+e+"]";if(/^\d+$/.test(e))return t+'["'+e+'"]';if("string"==typeof e)return t+(0===r?"":".")+e;throw new Error('Unsupported path segment "'+e+'"')}),"")}var c=function(t){var e,r;function n(e,r,n){var i,o=u(r);return(i=t.call(this,e+" (at '"+o+"')")||this).path=r,i.serializedPath=o,i.value=n,i}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(a(Error)),f=/^[a-z0-9][a-z0-9_.-]+$/i,s=/^[a-zA-Z_][a-zA-Z0-9_]*$/,p=/^[a-z_]/i;function h(t,e,r){if(!p.test(t))throw new c("Keys must start with a letter (a-z)",r.concat(t),e);if(!s.test(t))throw new c("Keys can only contain letters, numbers and underscores",r.concat(t),e);if("_key"===t||"_ref"===t||"_type"===t){if("string"!=typeof e)throw new c("Keys must be strings",r.concat(t),e);if(!f.test(e))throw new c("Invalid key - use less exotic characters",r.concat(t),e)}return t}var l=["_id","_type","_createdAt","_updatedAt","_rev"],y=new t.diff_match_patch,d={hideWarnings:!1,diffMatchPatch:{enabled:!0,lengthThresholdAbsolute:30,lengthThresholdRelative:1.2}};function v(t,e,r,n,i){if(void 0===r&&(r=d),void 0===n&&(n=[]),void 0===i&&(i=[]),t===e)return i;var o=Array.isArray(t)?"array":typeof t,a=Array.isArray(e)?"array":typeof e,u="undefined"===o,f="undefined"===a;if(u&&!f)return i.push({op:"set",path:n,value:e}),i;if(!u&&f)return i.push({op:"unset",path:n}),i;var s=u?a:o;return"object"===s||"array"===s?o!==a?(i.push({op:"set",path:n,value:e}),i):"array"===s?function(t,e,r,n,i){if(e.length>t.length&&i.push({op:"insert",after:n.concat([-1]),items:e.slice(t.length).map((function(t,e){return w(t,n,e,r)}))}),e.length<t.length){var o=t.length-e.length==1,a=t.slice(e.length);!function(t){return Boolean(t.ifRevisionID||t.ifRevisionId)}(r)&&b(a)?i.push.apply(i,a.map((function(t){return{op:"unset",path:n.concat({_key:t._key})}}))):i.push({op:"unset",path:n.concat([o?e.length:[e.length,""]])})}for(var u=0;u<e.length;u++)if(Array.isArray(e[u]))throw new c("Multi-dimensional arrays not supported",n.concat(u),e[u]);var f=Math.min(t.length,e.length),s=t.slice(0,f),p=e.slice(0,f);return b(s)&&b(p)?function(t,e,r,n,i){var o=m(t),a=m(e);if(!function(t,e){return t.length===e.length&&t.every((function(t,r){return e[r]===t}))}(o.keys,a.keys))return g(t,e,r,n,i);for(var u=0;u<a.keys.length;u++){var c=a.keys[u];v(o.index[c],w(a.index[c],n,u,r),r,n.concat({_key:c}),i)}return i}(s,p,r,n,i):g(s,p,r,n,i)}(t,e,r,n,i):function(t,e,r,n,i){for(var o=0===n.length,a=Object.keys(t).filter(o?_:k).map((function(e){return h(e,t[e],n)})),u=a.length,c=Object.keys(e).filter(o?_:k).map((function(t){return h(t,e[t],n)})),f=c.length,s=0;s<u;s++){var p=a[s];p in e||i.push({op:"unset",path:n.concat(p)})}for(var l=0;l<f;l++){var y=c[l];v(t[y],e[y],r,n.concat([y]),i)}return i}(t,e,r,n,i):function(t,e,r,n,i){var o=function(t,e,r,n){var i=r.diffMatchPatch,o=i.lengthThresholdRelative,a=n[n.length-1];if(!(!i.enabled||"string"!=typeof t||"string"!=typeof e||"string"==typeof a&&"_"===a[0]||e.length<i.lengthThresholdAbsolute)){var u="";try{var c=y.diff_main(t,e);y.diff_cleanupEfficiency(c),u=y.patch_toText(y.patch_make(c))}catch(t){return}return u.length>e.length*o?void 0:{op:"diffMatchPatch",path:n,value:u}}}(t,e,r,n);return i.push(o||{op:"set",path:n,value:e}),i}(t,e,r,n,i)}function g(t,e,r,n,i){for(var o=0;o<t.length;o++)v(t[o],w(e[o],n,o,r),r,n.concat(o),i);return i}function _(t){return-1===l.indexOf(t)}function b(t){for(var e,r=[],n=0;n<t.length;n++){var i="object"==typeof(e=t[n])&&null!==e&&e._key;if(!i||-1!==r.indexOf(i))return!1;r.push(i)}return!0}function m(t){return t.reduce((function(t,e){return t.keys.push(e._key),t.index[e._key]=e,t}),{keys:[],index:{}})}function w(t,e,r,n){if(void 0!==t)return t;if(!n.hideWarnings){var i=u(e.concat(r));console.warn("undefined value in array converted to null (at '"+i+"')")}return null}function k(t){return!0}exports.DiffError=c,exports.diffItem=v,exports.diffPatch=function(t,r,n){var i=n?function(t){return e({},d,t,{diffMatchPatch:e({},d.diffMatchPatch,t.diffMatchPatch||{})})}(n):d,o=i.id||t._id===r._id&&t._id,a=i.ifRevisionID||i.ifRevisionId,c="boolean"==typeof a?t._rev:a,f=i.basePath||[];if(!o)throw new Error("_id on itemA and itemB not present or differs, specify document id the mutations should be applied to");if(!0===a&&!c)throw new Error("`ifRevisionID` is set to `true`, but no `_rev` was passed in item A. Either explicitly set `ifRevisionID` to a revision, or pass `_rev` as part of item A.");if(0===f.length&&t._type!==r._type)throw new Error("_type is immutable and cannot be changed ("+t._type+" => "+r._type+")");return function(t,r){if(0===t.length)return[];var n=r.id,i=r.ifRevisionID,o=t.filter((function(t){return"set"===t.op})),a=t.filter((function(t){return"unset"===t.op})),c=t.filter((function(t){return"insert"===t.op})),f=t.filter((function(t){return"diffMatchPatch"===t.op})),s=o.length>0&&o.reduce((function(t,e){var r=u(e.path);return t.set[r]=e.value,t}),{id:n,set:{}}),p=a.length>0&&a.reduce((function(t,e){var r=u(e.path);return t.unset.push(r),t}),{id:n,unset:[]}),h=c.reduce((function(t,e){var r=u(e.after);return t.concat({id:n,insert:{after:r,items:e.items}})}),[]);return[s,p,f.length>0&&f.reduce((function(t,e){var r=u(e.path);return t.diffMatchPatch[r]=e.value,t}),{id:n,diffMatchPatch:{}})].concat(h).filter((function(t){return!1!==t})).map((function(t,r){return{patch:i&&0===r?e({},t,{ifRevisionID:i}):t}}))}(v(t,r,i,f,[]),{id:o,ifRevisionID:a?c:void 0})},exports.pathToString=u,exports.validateDocument=function t(e,r){if(void 0===r&&(r=[]),Array.isArray(e))return e.every((function(e,n){if(Array.isArray(e))throw new c("Multi-dimensional arrays not supported",r.concat(n));return t(e,r.concat(n))}));if("object"==typeof e&&null!==e){var n=e;return Object.keys(n).every((function(e){return h(e,n[e],r)&&t(n[e],r.concat(e))}))}return!0}; | ||
//# sourceMappingURL=sanity-diff-patch.cjs.production.min.js.map |
@@ -158,3 +158,3 @@ import { diff_match_patch } from 'diff-match-patch'; | ||
var idPattern = /^[a-z0-9][a-z0-9_.-]+$/i; | ||
var keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]+$/; | ||
var keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||
var keyStartPattern = /^[a-z_]/i; | ||
@@ -161,0 +161,0 @@ function validateDocument(item, path) { |
{ | ||
"name": "sanity-diff-patch", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Generates a set of Sanity patches needed to change an item (usually a document) from one shape to another", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# sanity-diff-patch | ||
[![npm version](http://img.shields.io/npm/v/sanity-diff-patch.svg?style=flat-square)](https://www.npmjs.com/package/sanity-diff-patch)[![npm bundle size](https://img.shields.io/bundlephobia/minzip/sanity-diff-patch.svg?style=flat-square)](https://bundlephobia.com/result?p=sanity-diff-patch)[![Build Status](http://img.shields.io/travis/rexxars/sanity-diff-patch/master.svg?style=flat-square)](https://travis-ci.com/rexxars/sanity-diff-patch) | ||
[![npm version](http://img.shields.io/npm/v/sanity-diff-patch.svg?style=flat-square)](https://www.npmjs.com/package/sanity-diff-patch)[![npm bundle size](https://img.shields.io/bundlephobia/minzip/sanity-diff-patch.svg?style=flat-square)](https://bundlephobia.com/result?p=sanity-diff-patch)[![Build Status](http://img.shields.io/travis/rexxars/sanity-diff-patch/main.svg?style=flat-square)](https://travis-ci.com/rexxars/sanity-diff-patch) | ||
@@ -5,0 +5,0 @@ Generates a set of [Sanity](https://www.sanity.io/) patches needed to change an item (usually a document) from one shape to another. |
@@ -5,3 +5,3 @@ import {DiffError} from './diffError' | ||
const idPattern = /^[a-z0-9][a-z0-9_.-]+$/i | ||
const keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]+$/ | ||
const keyPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/ | ||
const keyStartPattern = /^[a-z_]/i | ||
@@ -8,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
160901