@arcanejs/diff 0.3.1 → 0.4.0
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/dist/chunk-6R7Z62HK.js +81 -0
- package/dist/chunk-HLUKTMHV.js +52 -0
- package/dist/diff.js +5 -104
- package/dist/index.js +7 -155
- package/dist/patch.js +5 -75
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/diff.ts
|
|
2
|
+
var jsonTypeMatches = (a, b) => typeof a === typeof b && Array.isArray(a) === Array.isArray(b) && a === null === (b === null);
|
|
3
|
+
var diffJson = (a, b) => {
|
|
4
|
+
if (a === b) {
|
|
5
|
+
return { type: "match" };
|
|
6
|
+
}
|
|
7
|
+
if (!jsonTypeMatches(a, b)) {
|
|
8
|
+
throw new Error("Types don't match, unable to diff");
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
11
|
+
if (a.length === b.length) {
|
|
12
|
+
const changes = [];
|
|
13
|
+
for (let i = 0; i < a.length; i++) {
|
|
14
|
+
const d = diffJson(a[i], b[i]);
|
|
15
|
+
if (d.type !== "match") {
|
|
16
|
+
changes.push({ i, diff: d });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (changes.length === 0) {
|
|
20
|
+
return { type: "match" };
|
|
21
|
+
}
|
|
22
|
+
return { type: "modified-a", changes };
|
|
23
|
+
} else {
|
|
24
|
+
let start = 0;
|
|
25
|
+
while (start < a.length && start < b.length && diffJson(a[start], b[start]).type === "match") {
|
|
26
|
+
start++;
|
|
27
|
+
}
|
|
28
|
+
let endIndexA = a.length - 1;
|
|
29
|
+
let endIndexB = b.length - 1;
|
|
30
|
+
while (endIndexA >= start && endIndexB >= start && diffJson(a[endIndexA], b[endIndexB]).type === "match") {
|
|
31
|
+
endIndexA--;
|
|
32
|
+
endIndexB--;
|
|
33
|
+
}
|
|
34
|
+
const count = endIndexA - start + 1;
|
|
35
|
+
const items = b.slice(start, endIndexB + 1);
|
|
36
|
+
return { type: "splice", start, count, items };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (a === null || b === null) {
|
|
40
|
+
return { type: "value", before: a, after: b };
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
43
|
+
return { type: "value", before: a, after: b };
|
|
44
|
+
}
|
|
45
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
46
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
47
|
+
const changes = {};
|
|
48
|
+
const additions = {};
|
|
49
|
+
const deletions = {};
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const valueA = a[key];
|
|
52
|
+
const valueB = b[key];
|
|
53
|
+
if (valueA === void 0 && valueB !== void 0) {
|
|
54
|
+
additions[key] = valueB;
|
|
55
|
+
} else if (valueB === void 0 && valueA !== void 0) {
|
|
56
|
+
deletions[key] = valueA;
|
|
57
|
+
} else if (valueA !== void 0 && valueB !== void 0) {
|
|
58
|
+
const d = diffJson(valueA, valueB);
|
|
59
|
+
if (d.type !== "match") {
|
|
60
|
+
changes[key] = d;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const result = {
|
|
65
|
+
type: "modified-o",
|
|
66
|
+
...Object.keys(changes).length === 0 ? {} : { changes },
|
|
67
|
+
...Object.keys(additions).length === 0 ? {} : { additions },
|
|
68
|
+
...Object.keys(deletions).length === 0 ? {} : { deletions }
|
|
69
|
+
};
|
|
70
|
+
if (result.changes || result.additions || result.deletions) {
|
|
71
|
+
return result;
|
|
72
|
+
} else {
|
|
73
|
+
return { type: "match" };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { type: "value", before: a, after: b };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
exports.diffJson = diffJson;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/patch.ts
|
|
2
|
+
var patchJson = (old, diff) => {
|
|
3
|
+
if (diff.type === "match") {
|
|
4
|
+
return old;
|
|
5
|
+
}
|
|
6
|
+
if (diff.type === "value") {
|
|
7
|
+
return diff.after;
|
|
8
|
+
}
|
|
9
|
+
if (diff.type === "splice") {
|
|
10
|
+
if (!Array.isArray(old)) {
|
|
11
|
+
throw new Error("Cannot apply splice diff to non-array value");
|
|
12
|
+
}
|
|
13
|
+
const result = [...old];
|
|
14
|
+
result.splice(diff.start, diff.count, ...diff.items);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
if (diff.type === "modified-a") {
|
|
18
|
+
if (!Array.isArray(old)) {
|
|
19
|
+
throw new Error("Cannot apply changes diff to non-array value");
|
|
20
|
+
}
|
|
21
|
+
const result = [...old];
|
|
22
|
+
for (const { i, diff: d } of diff.changes) {
|
|
23
|
+
result[i] = patchJson(old[i], d);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(old)) {
|
|
28
|
+
throw new Error("Unexpected array type");
|
|
29
|
+
}
|
|
30
|
+
if (diff.type === "modified-o") {
|
|
31
|
+
if (typeof old !== "object" || old === null) {
|
|
32
|
+
throw new Error("Cannot apply modified diff to non-object value");
|
|
33
|
+
}
|
|
34
|
+
const result = { ...old, ...diff.additions };
|
|
35
|
+
for (const key of Object.keys(diff.changes || {})) {
|
|
36
|
+
const changes = _optionalChain([diff, 'access', _ => _.changes, 'optionalAccess', _2 => _2[key]]);
|
|
37
|
+
if (changes) {
|
|
38
|
+
result[key] = patchJson(old[key], changes);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const keu of Object.keys(diff.deletions || {})) {
|
|
42
|
+
delete result[keu];
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const _n = diff;
|
|
47
|
+
throw new Error(`Unknown diff type: ${_n}`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
exports.patchJson = patchJson;
|
package/dist/diff.js
CHANGED
|
@@ -1,105 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(diff_exports);
|
|
26
|
-
var jsonTypeMatches = (a, b) => typeof a === typeof b && Array.isArray(a) === Array.isArray(b) && a === null === (b === null);
|
|
27
|
-
var diffJson = (a, b) => {
|
|
28
|
-
if (a === b) {
|
|
29
|
-
return { type: "match" };
|
|
30
|
-
}
|
|
31
|
-
if (!jsonTypeMatches(a, b)) {
|
|
32
|
-
throw new Error("Types don't match, unable to diff");
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
35
|
-
if (a.length === b.length) {
|
|
36
|
-
const changes = [];
|
|
37
|
-
for (let i = 0; i < a.length; i++) {
|
|
38
|
-
const d = diffJson(a[i], b[i]);
|
|
39
|
-
if (d.type !== "match") {
|
|
40
|
-
changes.push({ i, diff: d });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (changes.length === 0) {
|
|
44
|
-
return { type: "match" };
|
|
45
|
-
}
|
|
46
|
-
return { type: "modified-a", changes };
|
|
47
|
-
} else {
|
|
48
|
-
let start = 0;
|
|
49
|
-
while (start < a.length && start < b.length && diffJson(a[start], b[start]).type === "match") {
|
|
50
|
-
start++;
|
|
51
|
-
}
|
|
52
|
-
let endIndexA = a.length - 1;
|
|
53
|
-
let endIndexB = b.length - 1;
|
|
54
|
-
while (endIndexA >= start && endIndexB >= start && diffJson(a[endIndexA], b[endIndexB]).type === "match") {
|
|
55
|
-
endIndexA--;
|
|
56
|
-
endIndexB--;
|
|
57
|
-
}
|
|
58
|
-
const count = endIndexA - start + 1;
|
|
59
|
-
const items = b.slice(start, endIndexB + 1);
|
|
60
|
-
return { type: "splice", start, count, items };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (a === null || b === null) {
|
|
64
|
-
return { type: "value", before: a, after: b };
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
67
|
-
return { type: "value", before: a, after: b };
|
|
68
|
-
}
|
|
69
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
70
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
71
|
-
const changes = {};
|
|
72
|
-
const additions = {};
|
|
73
|
-
const deletions = {};
|
|
74
|
-
for (const key of keys) {
|
|
75
|
-
const valueA = a[key];
|
|
76
|
-
const valueB = b[key];
|
|
77
|
-
if (valueA === void 0 && valueB !== void 0) {
|
|
78
|
-
additions[key] = valueB;
|
|
79
|
-
} else if (valueB === void 0 && valueA !== void 0) {
|
|
80
|
-
deletions[key] = valueA;
|
|
81
|
-
} else if (valueA !== void 0 && valueB !== void 0) {
|
|
82
|
-
const d = diffJson(valueA, valueB);
|
|
83
|
-
if (d.type !== "match") {
|
|
84
|
-
changes[key] = d;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const result = {
|
|
89
|
-
type: "modified-o",
|
|
90
|
-
...Object.keys(changes).length === 0 ? {} : { changes },
|
|
91
|
-
...Object.keys(additions).length === 0 ? {} : { additions },
|
|
92
|
-
...Object.keys(deletions).length === 0 ? {} : { deletions }
|
|
93
|
-
};
|
|
94
|
-
if (result.changes || result.additions || result.deletions) {
|
|
95
|
-
return result;
|
|
96
|
-
} else {
|
|
97
|
-
return { type: "match" };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return { type: "value", before: a, after: b };
|
|
101
|
-
};
|
|
102
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
-
0 && (module.exports = {
|
|
104
|
-
diffJson
|
|
105
|
-
});
|
|
3
|
+
var _chunk6R7Z62HKjs = require('./chunk-6R7Z62HK.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
exports.diffJson = _chunk6R7Z62HKjs.diffJson;
|
package/dist/index.js
CHANGED
|
@@ -1,158 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
diffJson: () => diffJson,
|
|
24
|
-
patchJson: () => patchJson
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var _chunk6R7Z62HKjs = require('./chunk-6R7Z62HK.js');
|
|
27
4
|
|
|
28
|
-
// src/diff.ts
|
|
29
|
-
var jsonTypeMatches = (a, b) => typeof a === typeof b && Array.isArray(a) === Array.isArray(b) && a === null === (b === null);
|
|
30
|
-
var diffJson = (a, b) => {
|
|
31
|
-
if (a === b) {
|
|
32
|
-
return { type: "match" };
|
|
33
|
-
}
|
|
34
|
-
if (!jsonTypeMatches(a, b)) {
|
|
35
|
-
throw new Error("Types don't match, unable to diff");
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
38
|
-
if (a.length === b.length) {
|
|
39
|
-
const changes = [];
|
|
40
|
-
for (let i = 0; i < a.length; i++) {
|
|
41
|
-
const d = diffJson(a[i], b[i]);
|
|
42
|
-
if (d.type !== "match") {
|
|
43
|
-
changes.push({ i, diff: d });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (changes.length === 0) {
|
|
47
|
-
return { type: "match" };
|
|
48
|
-
}
|
|
49
|
-
return { type: "modified-a", changes };
|
|
50
|
-
} else {
|
|
51
|
-
let start = 0;
|
|
52
|
-
while (start < a.length && start < b.length && diffJson(a[start], b[start]).type === "match") {
|
|
53
|
-
start++;
|
|
54
|
-
}
|
|
55
|
-
let endIndexA = a.length - 1;
|
|
56
|
-
let endIndexB = b.length - 1;
|
|
57
|
-
while (endIndexA >= start && endIndexB >= start && diffJson(a[endIndexA], b[endIndexB]).type === "match") {
|
|
58
|
-
endIndexA--;
|
|
59
|
-
endIndexB--;
|
|
60
|
-
}
|
|
61
|
-
const count = endIndexA - start + 1;
|
|
62
|
-
const items = b.slice(start, endIndexB + 1);
|
|
63
|
-
return { type: "splice", start, count, items };
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (a === null || b === null) {
|
|
67
|
-
return { type: "value", before: a, after: b };
|
|
68
|
-
}
|
|
69
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
70
|
-
return { type: "value", before: a, after: b };
|
|
71
|
-
}
|
|
72
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
73
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
74
|
-
const changes = {};
|
|
75
|
-
const additions = {};
|
|
76
|
-
const deletions = {};
|
|
77
|
-
for (const key of keys) {
|
|
78
|
-
const valueA = a[key];
|
|
79
|
-
const valueB = b[key];
|
|
80
|
-
if (valueA === void 0 && valueB !== void 0) {
|
|
81
|
-
additions[key] = valueB;
|
|
82
|
-
} else if (valueB === void 0 && valueA !== void 0) {
|
|
83
|
-
deletions[key] = valueA;
|
|
84
|
-
} else if (valueA !== void 0 && valueB !== void 0) {
|
|
85
|
-
const d = diffJson(valueA, valueB);
|
|
86
|
-
if (d.type !== "match") {
|
|
87
|
-
changes[key] = d;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const result = {
|
|
92
|
-
type: "modified-o",
|
|
93
|
-
...Object.keys(changes).length === 0 ? {} : { changes },
|
|
94
|
-
...Object.keys(additions).length === 0 ? {} : { additions },
|
|
95
|
-
...Object.keys(deletions).length === 0 ? {} : { deletions }
|
|
96
|
-
};
|
|
97
|
-
if (result.changes || result.additions || result.deletions) {
|
|
98
|
-
return result;
|
|
99
|
-
} else {
|
|
100
|
-
return { type: "match" };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { type: "value", before: a, after: b };
|
|
104
|
-
};
|
|
105
5
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (diff.type === "value") {
|
|
112
|
-
return diff.after;
|
|
113
|
-
}
|
|
114
|
-
if (diff.type === "splice") {
|
|
115
|
-
if (!Array.isArray(old)) {
|
|
116
|
-
throw new Error("Cannot apply splice diff to non-array value");
|
|
117
|
-
}
|
|
118
|
-
const result = [...old];
|
|
119
|
-
result.splice(diff.start, diff.count, ...diff.items);
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
if (diff.type === "modified-a") {
|
|
123
|
-
if (!Array.isArray(old)) {
|
|
124
|
-
throw new Error("Cannot apply changes diff to non-array value");
|
|
125
|
-
}
|
|
126
|
-
const result = [...old];
|
|
127
|
-
for (const { i, diff: d } of diff.changes) {
|
|
128
|
-
result[i] = patchJson(old[i], d);
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
if (Array.isArray(old)) {
|
|
133
|
-
throw new Error("Unexpected array type");
|
|
134
|
-
}
|
|
135
|
-
if (diff.type === "modified-o") {
|
|
136
|
-
if (typeof old !== "object" || old === null) {
|
|
137
|
-
throw new Error("Cannot apply modified diff to non-object value");
|
|
138
|
-
}
|
|
139
|
-
const result = { ...old, ...diff.additions };
|
|
140
|
-
for (const key of Object.keys(diff.changes || {})) {
|
|
141
|
-
const changes = diff.changes?.[key];
|
|
142
|
-
if (changes) {
|
|
143
|
-
result[key] = patchJson(old[key], changes);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
for (const keu of Object.keys(diff.deletions || {})) {
|
|
147
|
-
delete result[keu];
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
const _n = diff;
|
|
152
|
-
throw new Error(`Unknown diff type: ${_n}`);
|
|
153
|
-
};
|
|
154
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
-
0 && (module.exports = {
|
|
156
|
-
diffJson,
|
|
157
|
-
patchJson
|
|
158
|
-
});
|
|
6
|
+
var _chunkHLUKTMHVjs = require('./chunk-HLUKTMHV.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.diffJson = _chunk6R7Z62HKjs.diffJson; exports.patchJson = _chunkHLUKTMHVjs.patchJson;
|
package/dist/patch.js
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(patch_exports);
|
|
26
|
-
var patchJson = (old, diff) => {
|
|
27
|
-
if (diff.type === "match") {
|
|
28
|
-
return old;
|
|
29
|
-
}
|
|
30
|
-
if (diff.type === "value") {
|
|
31
|
-
return diff.after;
|
|
32
|
-
}
|
|
33
|
-
if (diff.type === "splice") {
|
|
34
|
-
if (!Array.isArray(old)) {
|
|
35
|
-
throw new Error("Cannot apply splice diff to non-array value");
|
|
36
|
-
}
|
|
37
|
-
const result = [...old];
|
|
38
|
-
result.splice(diff.start, diff.count, ...diff.items);
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
if (diff.type === "modified-a") {
|
|
42
|
-
if (!Array.isArray(old)) {
|
|
43
|
-
throw new Error("Cannot apply changes diff to non-array value");
|
|
44
|
-
}
|
|
45
|
-
const result = [...old];
|
|
46
|
-
for (const { i, diff: d } of diff.changes) {
|
|
47
|
-
result[i] = patchJson(old[i], d);
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
if (Array.isArray(old)) {
|
|
52
|
-
throw new Error("Unexpected array type");
|
|
53
|
-
}
|
|
54
|
-
if (diff.type === "modified-o") {
|
|
55
|
-
if (typeof old !== "object" || old === null) {
|
|
56
|
-
throw new Error("Cannot apply modified diff to non-object value");
|
|
57
|
-
}
|
|
58
|
-
const result = { ...old, ...diff.additions };
|
|
59
|
-
for (const key of Object.keys(diff.changes || {})) {
|
|
60
|
-
const changes = diff.changes?.[key];
|
|
61
|
-
if (changes) {
|
|
62
|
-
result[key] = patchJson(old[key], changes);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for (const keu of Object.keys(diff.deletions || {})) {
|
|
66
|
-
delete result[keu];
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
const _n = diff;
|
|
71
|
-
throw new Error(`Unknown diff type: ${_n}`);
|
|
72
|
-
};
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
patchJson
|
|
76
|
-
});
|
|
3
|
+
var _chunkHLUKTMHVjs = require('./chunk-HLUKTMHV.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
exports.patchJson = _chunkHLUKTMHVjs.patchJson;
|