@dabble/patches 0.5.19 → 0.5.20
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.
|
@@ -3,7 +3,7 @@ import { deepEqual } from "../utils/deepEqual.js";
|
|
|
3
3
|
import { getOpData } from "../utils/getOpData.js";
|
|
4
4
|
import {
|
|
5
5
|
isArrayPath,
|
|
6
|
-
|
|
6
|
+
isEmptyContainer,
|
|
7
7
|
log,
|
|
8
8
|
updateArrayIndexes,
|
|
9
9
|
updateRemovedOps,
|
|
@@ -47,8 +47,8 @@ const add = {
|
|
|
47
47
|
log("Transforming", otherOps, 'against "add"', thisOp);
|
|
48
48
|
if (isArrayPath(thisOp.path, state)) {
|
|
49
49
|
return updateArrayIndexes(state, thisOp.path, otherOps, 1);
|
|
50
|
-
} else if (
|
|
51
|
-
return updateSoftWrites(thisOp.path, otherOps);
|
|
50
|
+
} else if (isEmptyContainer(thisOp.value)) {
|
|
51
|
+
return updateSoftWrites(thisOp.path, otherOps, thisOp.value);
|
|
52
52
|
} else {
|
|
53
53
|
return updateRemovedOps(state, thisOp.path, otherOps);
|
|
54
54
|
}
|
|
@@ -7,7 +7,7 @@ export { isAdd, mapAndFilterOps, transformRemove, updateRemovedOps } from './ops
|
|
|
7
7
|
export { getArrayIndex, getArrayPrefixAndIndex, getIndexAndEnd, getPrefix, getPrefixAndProp, getProp, getPropAfter, isArrayPath } from './paths.js';
|
|
8
8
|
export { EMPTY, EMPTY_ARRAY, getValue, pluck, pluckWithShallowCopy } from './pluck.js';
|
|
9
9
|
export { shallowCopy } from './shallowCopy.js';
|
|
10
|
-
export {
|
|
10
|
+
export { isEmptyContainer, updateSoftWrites } from './softWrites.js';
|
|
11
11
|
export { toArrayIndex } from './toArrayIndex.js';
|
|
12
12
|
export { toKeys } from './toKeys.js';
|
|
13
13
|
export { updateArrayIndexes } from './updateArrayIndexes.js';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { JSONPatchOp } from '../types.js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function isEmptyContainer(value: any): boolean;
|
|
4
4
|
/**
|
|
5
|
-
* If other objects were added to this same path, assume they are maps/hashes/lookups
|
|
6
|
-
* subsequent ops to merge onto the first
|
|
5
|
+
* If other empty objects or arrays were added to this same path, assume they are maps/hashes/lookups/collections
|
|
6
|
+
* and don't overwrite, allow subsequent ops to merge onto the first container created. `soft` will also do this
|
|
7
|
+
* for any value that already exists.
|
|
7
8
|
*/
|
|
8
|
-
declare function updateSoftWrites(overPath: string, ops: JSONPatchOp[]): JSONPatchOp[];
|
|
9
|
+
declare function updateSoftWrites(overPath: string, ops: JSONPatchOp[], originalValue: any): JSONPatchOp[];
|
|
9
10
|
|
|
10
|
-
export {
|
|
11
|
+
export { isEmptyContainer, updateSoftWrites };
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import "../../chunk-IZ2YBCUP.js";
|
|
2
2
|
import { log } from "./log.js";
|
|
3
3
|
import { mapAndFilterOps } from "./ops.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
4
|
+
function isEmptyContainer(value) {
|
|
5
|
+
if (!value || typeof value !== "object") return false;
|
|
6
|
+
return Array.isArray(value) ? value.length === 0 : Object.keys(value).length === 0;
|
|
6
7
|
}
|
|
7
|
-
function updateSoftWrites(overPath, ops) {
|
|
8
|
+
function updateSoftWrites(overPath, ops, originalValue) {
|
|
9
|
+
const originalIsArray = Array.isArray(originalValue);
|
|
8
10
|
return mapAndFilterOps(ops, (op) => {
|
|
9
|
-
if (op.op === "add" && op.path === overPath &&
|
|
10
|
-
log("Removing empty
|
|
11
|
+
if (op.op === "add" && op.path === overPath && isEmptyContainer(op.value) && Array.isArray(op.value) === originalIsArray) {
|
|
12
|
+
log("Removing empty container", op);
|
|
11
13
|
return null;
|
|
12
14
|
}
|
|
13
15
|
return op;
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
export {
|
|
17
|
-
|
|
19
|
+
isEmptyContainer,
|
|
18
20
|
updateSoftWrites
|
|
19
21
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabble/patches",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.20",
|
|
4
4
|
"description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
|
|
5
5
|
"author": "Jacob Wright <jacwright@gmail.com>",
|
|
6
6
|
"bugs": {
|