@sanity/mutator 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/lib/index.js +31 -28
- package/lib/index.js.map +1 -1
- package/package.json +17 -15
- package/lib/index.d.mts +0 -377
- package/lib/index.mjs +0 -1820
- package/lib/index.mjs.map +0 -1
package/LICENSE
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
2
|
+
import debugIt from "debug";
|
|
3
|
+
import flatten from "lodash/flatten.js";
|
|
4
|
+
import { parsePatch as parsePatch$1, applyPatches, stringifyPatches, makePatches } from "@sanity/diff-match-patch";
|
|
5
|
+
import max from "lodash/max.js";
|
|
6
|
+
import min from "lodash/min.js";
|
|
7
|
+
import { uuid } from "@sanity/uuid";
|
|
8
|
+
import compact from "lodash/compact.js";
|
|
9
|
+
const debug = debugIt("mutator-document");
|
|
9
10
|
class ImmutableAccessor {
|
|
10
11
|
_value;
|
|
11
12
|
path;
|
|
@@ -257,7 +258,7 @@ class Tokenizer {
|
|
|
257
258
|
const number = this.takeWhile((char) => char === "." && !dotSeen && digitSeen ? (dotSeen = !0, char) : (digitSeen = !0, char.match(digitChar) ? char : null));
|
|
258
259
|
return number !== null ? {
|
|
259
260
|
type: "number",
|
|
260
|
-
value: negative ? -number : +number,
|
|
261
|
+
value: negative ? -Number(number) : +number,
|
|
261
262
|
raw: negative ? `-${number}` : number
|
|
262
263
|
} : (this.i = start, null);
|
|
263
264
|
}
|
|
@@ -692,7 +693,7 @@ class Descender {
|
|
|
692
693
|
if (this.head && this.head.isConstraint()) {
|
|
693
694
|
let anyConstraints = !0;
|
|
694
695
|
for (; anyConstraints; )
|
|
695
|
-
result =
|
|
696
|
+
result = flatten(
|
|
696
697
|
result.map((descender) => descender.iterateConstraints(probe))
|
|
697
698
|
), anyConstraints = result.some((descender) => descender.head && descender.head.isConstraint());
|
|
698
699
|
}
|
|
@@ -887,7 +888,7 @@ function accessorsFromTarget(target, accessor) {
|
|
|
887
888
|
result.push(accessor);
|
|
888
889
|
else
|
|
889
890
|
throw new Error(`Unable to derive accessor for target ${target.toString()}`);
|
|
890
|
-
return
|
|
891
|
+
return compact(result);
|
|
891
892
|
}
|
|
892
893
|
function extract(path, value) {
|
|
893
894
|
return extractAccessors(path, value).map((acc) => acc.get());
|
|
@@ -897,7 +898,7 @@ function extractWithPath(path, value) {
|
|
|
897
898
|
}
|
|
898
899
|
function applyPatch(patch, oldValue) {
|
|
899
900
|
if (typeof oldValue != "string") return oldValue;
|
|
900
|
-
const [result] =
|
|
901
|
+
const [result] = applyPatches(patch, oldValue, { allowExceedingIndices: !0 });
|
|
901
902
|
return result;
|
|
902
903
|
}
|
|
903
904
|
class DiffMatchPatch {
|
|
@@ -905,7 +906,7 @@ class DiffMatchPatch {
|
|
|
905
906
|
dmpPatch;
|
|
906
907
|
id;
|
|
907
908
|
constructor(id, path, dmpPatchSrc) {
|
|
908
|
-
this.id = id, this.path = path, this.dmpPatch =
|
|
909
|
+
this.id = id, this.path = path, this.dmpPatch = parsePatch$1(dmpPatchSrc);
|
|
909
910
|
}
|
|
910
911
|
apply(targets, accessor) {
|
|
911
912
|
let result = accessor;
|
|
@@ -977,7 +978,7 @@ function targetsToIndicies(targets, accessor) {
|
|
|
977
978
|
const result = [];
|
|
978
979
|
return targets.forEach((target) => {
|
|
979
980
|
target.isIndexReference() && result.push(...target.toIndicies(accessor));
|
|
980
|
-
}), result.sort();
|
|
981
|
+
}), result.sort((a, b) => a - b);
|
|
981
982
|
}
|
|
982
983
|
class InsertPatch {
|
|
983
984
|
location;
|
|
@@ -1014,7 +1015,7 @@ class InsertPatch {
|
|
|
1014
1015
|
}
|
|
1015
1016
|
}
|
|
1016
1017
|
function minIndex(targets, accessor) {
|
|
1017
|
-
let result =
|
|
1018
|
+
let result = min(targetsToIndicies(targets, accessor)) || 0;
|
|
1018
1019
|
return targets.forEach((target) => {
|
|
1019
1020
|
if (target.isRange()) {
|
|
1020
1021
|
const { start } = target.expandRange();
|
|
@@ -1023,7 +1024,7 @@ function minIndex(targets, accessor) {
|
|
|
1023
1024
|
}), result;
|
|
1024
1025
|
}
|
|
1025
1026
|
function maxIndex(targets, accessor) {
|
|
1026
|
-
let result =
|
|
1027
|
+
let result = max(targetsToIndicies(targets, accessor)) || 0;
|
|
1027
1028
|
return targets.forEach((target) => {
|
|
1028
1029
|
if (target.isRange()) {
|
|
1029
1030
|
const { end } = target.expandRange();
|
|
@@ -1103,15 +1104,15 @@ function parsePatch(patch) {
|
|
|
1103
1104
|
const result = [];
|
|
1104
1105
|
if (Array.isArray(patch))
|
|
1105
1106
|
return patch.reduce((r, p) => r.concat(parsePatch(p)), result);
|
|
1106
|
-
const { set, setIfMissing, unset, diffMatchPatch
|
|
1107
|
+
const { set, setIfMissing, unset, diffMatchPatch, inc, dec, insert } = patch;
|
|
1107
1108
|
if (setIfMissing && Object.keys(setIfMissing).forEach((path) => {
|
|
1108
1109
|
result.push(new SetIfMissingPatch(patch.id, path, setIfMissing[path]));
|
|
1109
1110
|
}), set && Object.keys(set).forEach((path) => {
|
|
1110
1111
|
result.push(new SetPatch(patch.id, path, set[path]));
|
|
1111
1112
|
}), unset && unset.forEach((path) => {
|
|
1112
1113
|
result.push(new UnsetPatch(patch.id, path));
|
|
1113
|
-
}),
|
|
1114
|
-
result.push(new DiffMatchPatch(patch.id, path,
|
|
1114
|
+
}), diffMatchPatch && Object.keys(diffMatchPatch).forEach((path) => {
|
|
1115
|
+
result.push(new DiffMatchPatch(patch.id, path, diffMatchPatch[path]));
|
|
1115
1116
|
}), inc && Object.keys(inc).forEach((path) => {
|
|
1116
1117
|
result.push(new IncPatch(patch.id, path, inc[path]));
|
|
1117
1118
|
}), dec && Object.keys(dec).forEach((path) => {
|
|
@@ -1186,7 +1187,7 @@ function process(matcher, accessor) {
|
|
|
1186
1187
|
function isPatcher(payload) {
|
|
1187
1188
|
return !!(payload && typeof payload == "object" && payload !== null && "apply" in payload && typeof payload.apply == "function");
|
|
1188
1189
|
}
|
|
1189
|
-
const luid = uuid
|
|
1190
|
+
const luid = uuid;
|
|
1190
1191
|
class Mutation {
|
|
1191
1192
|
params;
|
|
1192
1193
|
compiled;
|
|
@@ -1522,7 +1523,7 @@ class Document {
|
|
|
1522
1523
|
}
|
|
1523
1524
|
rebase(incomingMutations) {
|
|
1524
1525
|
const oldEdge = this.EDGE;
|
|
1525
|
-
this.EDGE = Mutation.applyAll(this.HEAD, this.submitted.concat(this.pending)), oldEdge !== null && this.EDGE !== null && (oldEdge._rev = this.EDGE._rev), !
|
|
1526
|
+
this.EDGE = Mutation.applyAll(this.HEAD, this.submitted.concat(this.pending)), oldEdge !== null && this.EDGE !== null && (oldEdge._rev = this.EDGE._rev), !isEqual(this.EDGE, oldEdge) && this.onRebase && this.onRebase(this.EDGE, incomingMutations, this.pending);
|
|
1526
1527
|
}
|
|
1527
1528
|
}
|
|
1528
1529
|
class SquashingBuffer {
|
|
@@ -1617,7 +1618,7 @@ class SquashingBuffer {
|
|
|
1617
1618
|
op = null;
|
|
1618
1619
|
else if (typeof match.value == "string" && typeof nextValue == "string")
|
|
1619
1620
|
try {
|
|
1620
|
-
const patch =
|
|
1621
|
+
const patch = stringifyPatches(makePatches(match.value, nextValue));
|
|
1621
1622
|
op = { patch: { id: this.PRESTAGE._id, diffMatchPatch: { [path]: patch } } };
|
|
1622
1623
|
} catch {
|
|
1623
1624
|
return !1;
|
|
@@ -1796,7 +1797,7 @@ class BufferedDocument {
|
|
|
1796
1797
|
rebase(remoteMutations, localMutations) {
|
|
1797
1798
|
debug("Rebasing document"), this.document.EDGE === null && this.handleDocumentDeleted();
|
|
1798
1799
|
const oldLocal = this.LOCAL;
|
|
1799
|
-
this.LOCAL = this.commits.reduce((doc, commit) => commit.apply(doc), this.document.EDGE), this.LOCAL = this.buffer.rebase(this.LOCAL), oldLocal !== null && this.LOCAL !== null && (oldLocal._rev = this.LOCAL._rev), !
|
|
1800
|
+
this.LOCAL = this.commits.reduce((doc, commit) => commit.apply(doc), this.document.EDGE), this.LOCAL = this.buffer.rebase(this.LOCAL), oldLocal !== null && this.LOCAL !== null && (oldLocal._rev = this.LOCAL._rev), !isEqual(this.LOCAL, oldLocal) && this.onRebase && this.onRebase(
|
|
1800
1801
|
this.LOCAL,
|
|
1801
1802
|
remoteMutations.reduce(mutReducerFn, []),
|
|
1802
1803
|
localMutations.reduce(mutReducerFn, [])
|
|
@@ -1809,9 +1810,11 @@ class BufferedDocument {
|
|
|
1809
1810
|
isConsistent && !hasLocalChanges && this.onConsistencyChanged(!0), isConsistent || this.onConsistencyChanged(!1);
|
|
1810
1811
|
}
|
|
1811
1812
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1813
|
+
export {
|
|
1814
|
+
BufferedDocument,
|
|
1815
|
+
Mutation,
|
|
1816
|
+
arrayToJSONMatchPath,
|
|
1817
|
+
extract,
|
|
1818
|
+
extractWithPath
|
|
1819
|
+
};
|
|
1817
1820
|
//# sourceMappingURL=index.js.map
|