@fgv/ts-json 5.0.0-2 → 5.0.0-21
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/.vscode/launch.json +16 -0
- package/.vscode/settings.json +32 -0
- package/config/api-extractor.json +343 -0
- package/config/rig.json +16 -0
- package/dist/ts-json.d.ts +719 -28
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +25 -0
- package/lib/packlets/diff/detailedDiff.d.ts +375 -0
- package/lib/packlets/diff/detailedDiff.js +342 -0
- package/lib/packlets/diff/index.d.ts +3 -0
- package/lib/packlets/diff/index.js +40 -0
- package/lib/packlets/diff/threeWayDiff.d.ts +263 -0
- package/lib/packlets/diff/threeWayDiff.js +261 -0
- package/lib/packlets/diff/utils.d.ts +6 -0
- package/lib/packlets/diff/utils.js +62 -0
- package/lib/packlets/editor/common.d.ts +6 -0
- package/lib/packlets/editor/jsonEditor.d.ts +57 -28
- package/lib/packlets/editor/jsonEditor.js +101 -32
- package/lib/test/legacy/jsonConverter.conditional.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/conditional.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/multivalue.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/references.test.d.ts +2 -0
- package/lib/test/legacy/jsonEditor/rules/templates.test.d.ts +2 -0
- package/lib/test/unit/contextHelpers.test.d.ts +2 -0
- package/lib/test/unit/converters.test.d.ts +2 -0
- package/lib/test/unit/diff/jsonDiff.test.d.ts +2 -0
- package/lib/test/unit/jsonConverter.test.d.ts +2 -0
- package/lib/test/unit/jsonEditor/jsonEditor.test.d.ts +2 -0
- package/lib/test/unit/jsonEditor/templateContext.test.d.ts +2 -0
- package/lib/test/unit/jsonReferenceMap.test.d.ts +2 -0
- package/package.json +11 -11
- package/src/index.ts +29 -0
- package/src/packlets/context/compositeJsonMap.ts +120 -0
- package/src/packlets/context/contextHelpers.ts +221 -0
- package/src/packlets/context/index.ts +33 -0
- package/src/packlets/context/jsonContext.ts +133 -0
- package/src/packlets/converters/converters.ts +117 -0
- package/src/packlets/converters/index.ts +26 -0
- package/src/packlets/converters/jsonConverter.ts +476 -0
- package/src/packlets/diff/detailedDiff.ts +585 -0
- package/src/packlets/diff/index.ts +24 -0
- package/src/packlets/diff/threeWayDiff.ts +420 -0
- package/src/packlets/diff/utils.ts +66 -0
- package/src/packlets/editor/common.ts +125 -0
- package/src/packlets/editor/index.ts +36 -0
- package/src/packlets/editor/jsonEditor.ts +523 -0
- package/src/packlets/editor/jsonEditorRule.ts +117 -0
- package/src/packlets/editor/jsonEditorState.ts +225 -0
- package/src/packlets/editor/jsonReferenceMap.ts +516 -0
- package/src/packlets/editor/rules/conditional.ts +222 -0
- package/src/packlets/editor/rules/index.ts +25 -0
- package/src/packlets/editor/rules/multivalue.ts +206 -0
- package/src/packlets/editor/rules/references.ts +177 -0
- package/src/packlets/editor/rules/templates.ts +159 -0
- package/CHANGELOG.md +0 -115
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/context/compositeJsonMap.d.ts.map +0 -1
- package/lib/packlets/context/compositeJsonMap.js.map +0 -1
- package/lib/packlets/context/contextHelpers.d.ts.map +0 -1
- package/lib/packlets/context/contextHelpers.js.map +0 -1
- package/lib/packlets/context/index.d.ts.map +0 -1
- package/lib/packlets/context/index.js.map +0 -1
- package/lib/packlets/context/jsonContext.d.ts.map +0 -1
- package/lib/packlets/context/jsonContext.js.map +0 -1
- package/lib/packlets/converters/converters.d.ts.map +0 -1
- package/lib/packlets/converters/converters.js.map +0 -1
- package/lib/packlets/converters/index.d.ts.map +0 -1
- package/lib/packlets/converters/index.js.map +0 -1
- package/lib/packlets/converters/jsonConverter.d.ts.map +0 -1
- package/lib/packlets/converters/jsonConverter.js.map +0 -1
- package/lib/packlets/editor/common.d.ts.map +0 -1
- package/lib/packlets/editor/common.js.map +0 -1
- package/lib/packlets/editor/index.d.ts.map +0 -1
- package/lib/packlets/editor/index.js.map +0 -1
- package/lib/packlets/editor/jsonEditor.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditor.js.map +0 -1
- package/lib/packlets/editor/jsonEditorRule.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditorRule.js.map +0 -1
- package/lib/packlets/editor/jsonEditorState.d.ts.map +0 -1
- package/lib/packlets/editor/jsonEditorState.js.map +0 -1
- package/lib/packlets/editor/jsonReferenceMap.d.ts.map +0 -1
- package/lib/packlets/editor/jsonReferenceMap.js.map +0 -1
- package/lib/packlets/editor/rules/conditional.d.ts.map +0 -1
- package/lib/packlets/editor/rules/conditional.js.map +0 -1
- package/lib/packlets/editor/rules/index.d.ts.map +0 -1
- package/lib/packlets/editor/rules/index.js.map +0 -1
- package/lib/packlets/editor/rules/multivalue.d.ts.map +0 -1
- package/lib/packlets/editor/rules/multivalue.js.map +0 -1
- package/lib/packlets/editor/rules/references.d.ts.map +0 -1
- package/lib/packlets/editor/rules/references.js.map +0 -1
- package/lib/packlets/editor/rules/templates.d.ts.map +0 -1
- package/lib/packlets/editor/rules/templates.js.map +0 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.jsonThreeWayDiff = jsonThreeWayDiff;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
27
|
+
const utils_1 = require("./utils");
|
|
28
|
+
/**
|
|
29
|
+
* Internal function to build three-way diff for objects.
|
|
30
|
+
*/
|
|
31
|
+
function buildThreeWayDiffForObjects(obj1, obj2, metadata) {
|
|
32
|
+
if (!(0, ts_json_base_1.isJsonObject)(obj1) || !(0, ts_json_base_1.isJsonObject)(obj2)) {
|
|
33
|
+
// Handle non-object cases
|
|
34
|
+
if ((0, utils_1.deepEquals)(obj1, obj2)) {
|
|
35
|
+
metadata.unchanged++;
|
|
36
|
+
return {
|
|
37
|
+
onlyInA: null,
|
|
38
|
+
unchanged: obj1,
|
|
39
|
+
onlyInB: null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
metadata.modified++;
|
|
44
|
+
return {
|
|
45
|
+
onlyInA: obj1,
|
|
46
|
+
unchanged: null,
|
|
47
|
+
onlyInB: obj2
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const keys1 = new Set(Object.keys(obj1));
|
|
52
|
+
const keys2 = new Set(Object.keys(obj2));
|
|
53
|
+
const allKeys = new Set([...keys1, ...keys2]);
|
|
54
|
+
const onlyInA = {};
|
|
55
|
+
const unchanged = {};
|
|
56
|
+
const onlyInB = {};
|
|
57
|
+
let hasOnlyInA = false;
|
|
58
|
+
let hasUnchanged = false;
|
|
59
|
+
let hasOnlyInB = false;
|
|
60
|
+
for (const key of allKeys) {
|
|
61
|
+
if (!keys1.has(key)) {
|
|
62
|
+
// Property only exists in obj2
|
|
63
|
+
metadata.added++;
|
|
64
|
+
onlyInB[key] = obj2[key];
|
|
65
|
+
hasOnlyInB = true;
|
|
66
|
+
}
|
|
67
|
+
else if (!keys2.has(key)) {
|
|
68
|
+
// Property only exists in obj1
|
|
69
|
+
metadata.removed++;
|
|
70
|
+
onlyInA[key] = obj1[key];
|
|
71
|
+
hasOnlyInA = true;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Property exists in both
|
|
75
|
+
const val1 = obj1[key];
|
|
76
|
+
const val2 = obj2[key];
|
|
77
|
+
if ((0, utils_1.deepEquals)(val1, val2)) {
|
|
78
|
+
// Values are identical
|
|
79
|
+
if ((0, ts_json_base_1.isJsonObject)(val1) && (0, ts_json_base_1.isJsonObject)(val2)) {
|
|
80
|
+
// For objects, we need to recurse to get proper metadata counts
|
|
81
|
+
const childDiff = buildThreeWayDiffForObjects(val1, val2, metadata);
|
|
82
|
+
if (childDiff.unchanged !== null) {
|
|
83
|
+
unchanged[key] = childDiff.unchanged;
|
|
84
|
+
hasUnchanged = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
metadata.unchanged++;
|
|
89
|
+
unchanged[key] = val1;
|
|
90
|
+
hasUnchanged = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Values are different
|
|
95
|
+
if ((0, ts_json_base_1.isJsonObject)(val1) && (0, ts_json_base_1.isJsonObject)(val2)) {
|
|
96
|
+
// For nested objects, recurse
|
|
97
|
+
const childDiff = buildThreeWayDiffForObjects(val1, val2, metadata);
|
|
98
|
+
if (childDiff.onlyInA !== null) {
|
|
99
|
+
onlyInA[key] = childDiff.onlyInA;
|
|
100
|
+
hasOnlyInA = true;
|
|
101
|
+
}
|
|
102
|
+
if (childDiff.unchanged !== null) {
|
|
103
|
+
unchanged[key] = childDiff.unchanged;
|
|
104
|
+
hasUnchanged = true;
|
|
105
|
+
}
|
|
106
|
+
if (childDiff.onlyInB !== null) {
|
|
107
|
+
onlyInB[key] = childDiff.onlyInB;
|
|
108
|
+
hasOnlyInB = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// For primitives or arrays, treat as complete replacement
|
|
113
|
+
metadata.modified++;
|
|
114
|
+
onlyInA[key] = val1;
|
|
115
|
+
onlyInB[key] = val2;
|
|
116
|
+
hasOnlyInA = true;
|
|
117
|
+
hasOnlyInB = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
onlyInA: hasOnlyInA ? onlyInA : null,
|
|
124
|
+
unchanged: hasUnchanged ? unchanged : null,
|
|
125
|
+
onlyInB: hasOnlyInB ? onlyInB : null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Performs a three-way diff comparison between two JSON values, returning separate
|
|
130
|
+
* objects containing the differences and similarities.
|
|
131
|
+
*
|
|
132
|
+
* This function provides an alternative to {@link Diff.jsonDiff} that focuses on actionable
|
|
133
|
+
* results rather than detailed change analysis. Instead of a list of individual changes,
|
|
134
|
+
* it returns three objects that can be directly used for merging, UI display, or
|
|
135
|
+
* programmatic manipulation.
|
|
136
|
+
*
|
|
137
|
+
* **Key Features:**
|
|
138
|
+
* - **Actionable Results**: Returns objects ready for immediate use in merging operations
|
|
139
|
+
* - **Simplified Array Handling**: Arrays are treated as atomic values for cleaner results
|
|
140
|
+
* - **Structural Preservation**: Maintains original JSON structure rather than flattened paths
|
|
141
|
+
* - **UI-Optimized**: Perfect for side-by-side diff displays and change visualization
|
|
142
|
+
* - **Merge-Friendly**: Designed specifically for three-way merge scenarios
|
|
143
|
+
*
|
|
144
|
+
* **Array Handling:**
|
|
145
|
+
* Unlike {@link Diff.jsonDiff}, this function treats arrays as complete units. If arrays differ,
|
|
146
|
+
* the entire array appears in the appropriate result object rather than computing
|
|
147
|
+
* element-by-element deltas. This approach is simpler and more predictable for most
|
|
148
|
+
* use cases involving data updates and synchronization.
|
|
149
|
+
*
|
|
150
|
+
* **Use Cases:**
|
|
151
|
+
* - Applying configuration updates while preserving unchanged settings
|
|
152
|
+
* - Creating side-by-side diff displays in user interfaces
|
|
153
|
+
* - Building three-way merge tools for data synchronization
|
|
154
|
+
* - Implementing undo/redo functionality with granular control
|
|
155
|
+
* - Generating patch objects for API updates
|
|
156
|
+
*
|
|
157
|
+
* @param obj1 - The first JSON value to compare (often the "before" or "source" state)
|
|
158
|
+
* @param obj2 - The second JSON value to compare (often the "after" or "target" state)
|
|
159
|
+
* @returns A Result containing the three-way diff with separate objects and metadata
|
|
160
|
+
*
|
|
161
|
+
* @example Basic usage for applying changes
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const original = { name: "John", age: 30, city: "NYC", active: true };
|
|
164
|
+
* const updated = { name: "Jane", age: 30, country: "USA", active: true };
|
|
165
|
+
*
|
|
166
|
+
* const result = jsonThreeWayDiff(original, updated);
|
|
167
|
+
* if (result.success) {
|
|
168
|
+
* const { onlyInA, unchanged, onlyInB } = result.value;
|
|
169
|
+
*
|
|
170
|
+
* // Apply changes: merge unchanged + onlyInB
|
|
171
|
+
* const applied = { ...unchanged, ...onlyInB };
|
|
172
|
+
* console.log(applied); // { age: 30, active: true, name: "Jane", country: "USA" }
|
|
173
|
+
*
|
|
174
|
+
* // Revert changes: merge unchanged + onlyInA
|
|
175
|
+
* const reverted = { ...unchanged, ...onlyInA };
|
|
176
|
+
* console.log(reverted); // { age: 30, active: true, name: "John", city: "NYC" }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example UI-friendly diff display
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const result = jsonThreeWayDiff(userBefore, userAfter);
|
|
183
|
+
* if (result.success) {
|
|
184
|
+
* const { onlyInA, unchanged, onlyInB, metadata } = result.value;
|
|
185
|
+
*
|
|
186
|
+
* // Display summary
|
|
187
|
+
* console.log(`Changes: ${metadata.added} added, ${metadata.removed} removed, ${metadata.modified} modified`);
|
|
188
|
+
*
|
|
189
|
+
* // Show removed/old values in red
|
|
190
|
+
* if (onlyInA) displayInColor(onlyInA, 'red');
|
|
191
|
+
*
|
|
192
|
+
* // Show unchanged values in gray
|
|
193
|
+
* if (unchanged) displayInColor(unchanged, 'gray');
|
|
194
|
+
*
|
|
195
|
+
* // Show added/new values in green
|
|
196
|
+
* if (onlyInB) displayInColor(onlyInB, 'green');
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @example Nested objects and array handling
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const config1 = {
|
|
203
|
+
* database: { host: "localhost", port: 5432 },
|
|
204
|
+
* features: ["auth", "logging"],
|
|
205
|
+
* version: "1.0"
|
|
206
|
+
* };
|
|
207
|
+
* const config2 = {
|
|
208
|
+
* database: { host: "production.db", port: 5432 },
|
|
209
|
+
* features: ["auth", "logging", "metrics"], // Array treated as complete unit
|
|
210
|
+
* version: "1.1"
|
|
211
|
+
* };
|
|
212
|
+
*
|
|
213
|
+
* const result = jsonThreeWayDiff(config1, config2);
|
|
214
|
+
* if (result.success) {
|
|
215
|
+
* // result.value.onlyInA = { database: { host: "localhost" }, features: ["auth", "logging"], version: "1.0" }
|
|
216
|
+
* // result.value.unchanged = { database: { port: 5432 } }
|
|
217
|
+
* // result.value.onlyInB = { database: { host: "production.db" }, features: ["auth", "logging", "metrics"], version: "1.1" }
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @example Conditional updates based on changes
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const result = jsonThreeWayDiff(currentState, newState);
|
|
224
|
+
* if (result.success && !result.value.identical) {
|
|
225
|
+
* const { metadata } = result.value;
|
|
226
|
+
*
|
|
227
|
+
* if (metadata.modified > 0) {
|
|
228
|
+
* console.log("Critical settings changed - requires restart");
|
|
229
|
+
* } else if (metadata.added > 0) {
|
|
230
|
+
* console.log("New features enabled");
|
|
231
|
+
* } else if (metadata.removed > 0) {
|
|
232
|
+
* console.log("Features disabled");
|
|
233
|
+
* }
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* @see {@link IThreeWayDiff} for the structure of returned results
|
|
238
|
+
* @see {@link IThreeWayDiffMetadata} for metadata details
|
|
239
|
+
* @see {@link Diff.jsonDiff} for detailed change-by-change analysis
|
|
240
|
+
* @see {@link jsonEquals} for simple equality checking
|
|
241
|
+
*
|
|
242
|
+
* @public
|
|
243
|
+
*/
|
|
244
|
+
function jsonThreeWayDiff(obj1, obj2) {
|
|
245
|
+
const metadata = {
|
|
246
|
+
removed: 0,
|
|
247
|
+
added: 0,
|
|
248
|
+
modified: 0,
|
|
249
|
+
unchanged: 0
|
|
250
|
+
};
|
|
251
|
+
const diff = buildThreeWayDiffForObjects(obj1, obj2, metadata);
|
|
252
|
+
const result = {
|
|
253
|
+
onlyInA: diff.onlyInA,
|
|
254
|
+
unchanged: diff.unchanged,
|
|
255
|
+
onlyInB: diff.onlyInB,
|
|
256
|
+
metadata,
|
|
257
|
+
identical: metadata.removed === 0 && metadata.added === 0 && metadata.modified === 0
|
|
258
|
+
};
|
|
259
|
+
return (0, ts_utils_1.succeed)(result);
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=threeWayDiff.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.deepEquals = deepEquals;
|
|
25
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
26
|
+
/**
|
|
27
|
+
* Deep comparison function for JSON values that handles all JSON types.
|
|
28
|
+
*/
|
|
29
|
+
function deepEquals(a, b) {
|
|
30
|
+
if (a === b) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if ((0, ts_json_base_1.isJsonPrimitive)(a) || (0, ts_json_base_1.isJsonPrimitive)(b)) {
|
|
34
|
+
return a === b;
|
|
35
|
+
}
|
|
36
|
+
if ((0, ts_json_base_1.isJsonArray)(a) && (0, ts_json_base_1.isJsonArray)(b)) {
|
|
37
|
+
if (a.length !== b.length) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
for (let i = 0; i < a.length; i++) {
|
|
41
|
+
if (!deepEquals(a[i], b[i])) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if ((0, ts_json_base_1.isJsonObject)(a) && (0, ts_json_base_1.isJsonObject)(b)) {
|
|
48
|
+
const keysA = Object.keys(a);
|
|
49
|
+
const keysB = Object.keys(b);
|
|
50
|
+
if (keysA.length !== keysB.length) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
for (const key of keysA) {
|
|
54
|
+
if (!(key in b) || !deepEquals(a[key], b[key])) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -32,6 +32,12 @@ export interface IJsonEditorMergeOptions {
|
|
|
32
32
|
* - `'replace'`: Existing array is completely replaced with the new array
|
|
33
33
|
*/
|
|
34
34
|
arrayMergeBehavior: ArrayMergeBehavior;
|
|
35
|
+
/**
|
|
36
|
+
* Controls whether null values should be treated as property deletion during merge operations.
|
|
37
|
+
* - `false` (default): Null values are merged normally, setting the property to null
|
|
38
|
+
* - `true`: Null values delete the property from the target object during merge
|
|
39
|
+
*/
|
|
40
|
+
nullAsDelete?: boolean;
|
|
35
41
|
}
|
|
36
42
|
/**
|
|
37
43
|
* Validation options for a {@link JsonEditor | JsonEditor}.
|
|
@@ -58,6 +58,11 @@ export declare class JsonEditor implements IJsonCloneEditor {
|
|
|
58
58
|
*/
|
|
59
59
|
static getDefaultRules(options?: IJsonEditorOptions): Result<IJsonEditorRule[]>;
|
|
60
60
|
/**
|
|
61
|
+
* Creates a complete IJsonEditorOptions object from partial options, filling in
|
|
62
|
+
* default values for any missing properties. This ensures all editor instances
|
|
63
|
+
* have consistent, complete configuration including validation rules and merge behavior.
|
|
64
|
+
* @param options - Optional partial editor options to merge with defaults
|
|
65
|
+
* @returns Success with complete editor options, or Failure if validation fails
|
|
61
66
|
* @internal
|
|
62
67
|
*/
|
|
63
68
|
protected static _getDefaultOptions(options?: Partial<IJsonEditorOptions>): Result<IJsonEditorOptions>;
|
|
@@ -100,54 +105,78 @@ export declare class JsonEditor implements IJsonCloneEditor {
|
|
|
100
105
|
*/
|
|
101
106
|
clone(src: JsonValue, context?: IJsonContext): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
102
107
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* @param
|
|
107
|
-
* @
|
|
108
|
+
* Merges properties from a source object into a target object, applying editor rules and
|
|
109
|
+
* null-as-delete logic. This is the core merge implementation that handles property-by-property
|
|
110
|
+
* merging with rule processing and deferred property handling.
|
|
111
|
+
* @param target - The target object to merge properties into
|
|
112
|
+
* @param src - The source object containing properties to merge
|
|
113
|
+
* @param state - The editor state containing options and context
|
|
114
|
+
* @returns Success with the modified target object, or Failure with error details
|
|
108
115
|
* @internal
|
|
109
116
|
*/
|
|
110
117
|
protected _mergeObjectInPlace(target: JsonObject, src: JsonObject, state: JsonEditorState): Result<JsonObject>;
|
|
111
118
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
119
|
+
* Creates a deep clone of a JSON array by recursively cloning each element.
|
|
120
|
+
* Each array element is cloned using the main clone method, preserving the
|
|
121
|
+
* editor's rules and validation settings.
|
|
122
|
+
* @param src - The source JSON array to clone
|
|
123
|
+
* @param context - Optional JSON context for cloning operations
|
|
124
|
+
* @returns Success with the cloned array, or Failure with error details
|
|
116
125
|
* @internal
|
|
117
126
|
*/
|
|
118
127
|
protected _cloneArray(src: JsonArray, context?: IJsonContext): DetailedResult<JsonArray, JsonEditFailureReason>;
|
|
119
128
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param
|
|
125
|
-
* @
|
|
129
|
+
* Merges a single cloned property value into a target object. This method handles
|
|
130
|
+
* the core merge logic including null-as-delete behavior, array merging, and
|
|
131
|
+
* recursive object merging. The null-as-delete check occurs before primitive
|
|
132
|
+
* handling to ensure null values can signal property deletion.
|
|
133
|
+
* @param target - The target object to merge the property into
|
|
134
|
+
* @param key - The property key being merged
|
|
135
|
+
* @param newValue - The cloned value to merge (from source object)
|
|
136
|
+
* @param state - The editor state containing merge options and context
|
|
137
|
+
* @returns Success with the merged value, or Failure with error details
|
|
126
138
|
* @internal
|
|
127
139
|
*/
|
|
128
140
|
protected _mergeClonedProperty(target: JsonObject, key: string, newValue: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
129
141
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
134
|
-
* @
|
|
142
|
+
* Applies editor rules to a single property during merge operations. This method
|
|
143
|
+
* iterates through all configured editor rules to process the property, handling
|
|
144
|
+
* templates, conditionals, multi-value properties, and references.
|
|
145
|
+
* @param key - The property key to edit
|
|
146
|
+
* @param value - The property value to edit
|
|
147
|
+
* @param state - The editor state containing rules and context
|
|
148
|
+
* @returns Success with transformed property object, or Failure if rules cannot process
|
|
135
149
|
* @internal
|
|
136
150
|
*/
|
|
137
151
|
protected _editProperty(key: string, value: JsonValue, state: JsonEditorState): DetailedResult<JsonObject, JsonPropertyEditFailureReason>;
|
|
138
152
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @
|
|
153
|
+
* Applies editor rules to a single JSON value during clone operations. This method
|
|
154
|
+
* iterates through all configured editor rules to process the value, handling
|
|
155
|
+
* templates, conditionals, multi-value expressions, and references.
|
|
156
|
+
* @param value - The JSON value to edit and transform
|
|
157
|
+
* @param state - The editor state containing rules and context
|
|
158
|
+
* @returns Success with transformed value, or Failure if rules cannot process
|
|
143
159
|
* @internal
|
|
144
160
|
*/
|
|
145
161
|
protected _editValue(value: JsonValue, state: JsonEditorState): DetailedResult<JsonValue, JsonEditFailureReason>;
|
|
146
162
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @param
|
|
150
|
-
* @
|
|
163
|
+
* Clone an object without applying null-as-delete behavior.
|
|
164
|
+
* This preserves null values during cloning so they can be used for deletion signaling during merge.
|
|
165
|
+
* @param target - The target object to clone into
|
|
166
|
+
* @param src - The source object to clone
|
|
167
|
+
* @param state - The editor state
|
|
168
|
+
* @returns The cloned object
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
protected _cloneObjectWithoutNullAsDelete(target: JsonObject, src: JsonObject, state: JsonEditorState): DetailedResult<JsonObject, JsonEditFailureReason>;
|
|
172
|
+
/**
|
|
173
|
+
* Finalizes the merge operation by processing any deferred properties and merging
|
|
174
|
+
* them into the target object. Deferred properties are those that require special
|
|
175
|
+
* processing after the initial merge phase, such as references that depend on
|
|
176
|
+
* other properties being resolved first.
|
|
177
|
+
* @param target - The target object that has been merged
|
|
178
|
+
* @param state - The editor state containing deferred properties and rules
|
|
179
|
+
* @returns Success with the finalized target object, or Failure with error details
|
|
151
180
|
* @internal
|
|
152
181
|
*/
|
|
153
182
|
protected _finalizeAndMerge(target: JsonObject, state: JsonEditorState): DetailedResult<JsonObject, JsonEditFailureReason>;
|