@fgv/ts-json 4.6.0 → 5.0.0-10
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/CHANGELOG.json +15 -0
- package/CHANGELOG.md +9 -1
- package/dist/ts-json.d.ts +739 -28
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -1
- package/lib/packlets/diff/detailedDiff.d.ts +375 -0
- package/lib/packlets/diff/detailedDiff.d.ts.map +1 -0
- package/lib/packlets/diff/detailedDiff.js +342 -0
- package/lib/packlets/diff/detailedDiff.js.map +1 -0
- package/lib/packlets/diff/index.d.ts +3 -0
- package/lib/packlets/diff/index.d.ts.map +1 -0
- package/lib/packlets/diff/index.js +40 -0
- package/lib/packlets/diff/index.js.map +1 -0
- package/lib/packlets/diff/threeWayDiff.d.ts +263 -0
- package/lib/packlets/diff/threeWayDiff.d.ts.map +1 -0
- package/lib/packlets/diff/threeWayDiff.js +261 -0
- package/lib/packlets/diff/threeWayDiff.js.map +1 -0
- package/lib/packlets/diff/utils.d.ts +6 -0
- package/lib/packlets/diff/utils.d.ts.map +1 -0
- package/lib/packlets/diff/utils.js +62 -0
- package/lib/packlets/diff/utils.js.map +1 -0
- package/lib/packlets/editor/common.d.ts +24 -0
- package/lib/packlets/editor/common.d.ts.map +1 -1
- package/lib/packlets/editor/common.js.map +1 -1
- package/lib/packlets/editor/jsonEditor.d.ts +57 -28
- package/lib/packlets/editor/jsonEditor.d.ts.map +1 -1
- package/lib/packlets/editor/jsonEditor.js +119 -31
- package/lib/packlets/editor/jsonEditor.js.map +1 -1
- package/lib/packlets/editor/jsonEditorState.js +1 -1
- package/lib/packlets/editor/jsonEditorState.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,342 @@
|
|
|
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.jsonDiff = jsonDiff;
|
|
25
|
+
exports.jsonEquals = jsonEquals;
|
|
26
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const utils_1 = require("./utils");
|
|
29
|
+
/**
|
|
30
|
+
* Internal recursive diff function that builds the change list.
|
|
31
|
+
*/
|
|
32
|
+
function diffRecursive(obj1, obj2, path, options, changes) {
|
|
33
|
+
const pathPrefix = path ? `${path}${options.pathSeparator}` : '';
|
|
34
|
+
// Handle primitive values
|
|
35
|
+
if ((0, ts_json_base_1.isJsonPrimitive)(obj1) || (0, ts_json_base_1.isJsonPrimitive)(obj2)) {
|
|
36
|
+
if (!(0, utils_1.deepEquals)(obj1, obj2)) {
|
|
37
|
+
changes.push({
|
|
38
|
+
path,
|
|
39
|
+
type: 'modified',
|
|
40
|
+
oldValue: obj1,
|
|
41
|
+
newValue: obj2
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else if (options.includeUnchanged) {
|
|
45
|
+
changes.push({
|
|
46
|
+
path,
|
|
47
|
+
type: 'unchanged',
|
|
48
|
+
oldValue: obj1,
|
|
49
|
+
newValue: obj2
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Handle arrays
|
|
55
|
+
if ((0, ts_json_base_1.isJsonArray)(obj1) && (0, ts_json_base_1.isJsonArray)(obj2)) {
|
|
56
|
+
if (options.arrayOrderMatters) {
|
|
57
|
+
// Ordered array comparison
|
|
58
|
+
const maxLength = Math.max(obj1.length, obj2.length);
|
|
59
|
+
for (let i = 0; i < maxLength; i++) {
|
|
60
|
+
const itemPath = `${pathPrefix}${i}`;
|
|
61
|
+
if (i >= obj1.length) {
|
|
62
|
+
changes.push({
|
|
63
|
+
path: itemPath,
|
|
64
|
+
type: 'added',
|
|
65
|
+
newValue: obj2[i]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else if (i >= obj2.length) {
|
|
69
|
+
changes.push({
|
|
70
|
+
path: itemPath,
|
|
71
|
+
type: 'removed',
|
|
72
|
+
oldValue: obj1[i]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
diffRecursive(obj1[i], obj2[i], itemPath, options, changes);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Unordered array comparison - simplified approach
|
|
82
|
+
// This is a basic implementation; a more sophisticated approach would use
|
|
83
|
+
// algorithms like longest common subsequence for better matching
|
|
84
|
+
const processed = new Set();
|
|
85
|
+
// Find matching elements
|
|
86
|
+
for (let i = 0; i < obj1.length; i++) {
|
|
87
|
+
let found = false;
|
|
88
|
+
for (let j = 0; j < obj2.length; j++) {
|
|
89
|
+
if (!processed.has(j) && (0, utils_1.deepEquals)(obj1[i], obj2[j])) {
|
|
90
|
+
processed.add(j);
|
|
91
|
+
found = true;
|
|
92
|
+
if (options.includeUnchanged) {
|
|
93
|
+
changes.push({
|
|
94
|
+
path: `${pathPrefix}${i}`,
|
|
95
|
+
type: 'unchanged',
|
|
96
|
+
oldValue: obj1[i],
|
|
97
|
+
newValue: obj2[j]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!found) {
|
|
104
|
+
changes.push({
|
|
105
|
+
path: `${pathPrefix}${i}`,
|
|
106
|
+
type: 'removed',
|
|
107
|
+
oldValue: obj1[i]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Find added elements
|
|
112
|
+
for (let j = 0; j < obj2.length; j++) {
|
|
113
|
+
if (!processed.has(j)) {
|
|
114
|
+
changes.push({
|
|
115
|
+
path: `${pathPrefix}${j}`,
|
|
116
|
+
type: 'added',
|
|
117
|
+
newValue: obj2[j]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Handle one array, one non-array
|
|
125
|
+
if ((0, ts_json_base_1.isJsonArray)(obj1) || (0, ts_json_base_1.isJsonArray)(obj2)) {
|
|
126
|
+
changes.push({
|
|
127
|
+
path,
|
|
128
|
+
type: 'modified',
|
|
129
|
+
oldValue: obj1,
|
|
130
|
+
newValue: obj2
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// Handle objects
|
|
135
|
+
if ((0, ts_json_base_1.isJsonObject)(obj1) && (0, ts_json_base_1.isJsonObject)(obj2)) {
|
|
136
|
+
const keys1 = new Set(Object.keys(obj1));
|
|
137
|
+
const keys2 = new Set(Object.keys(obj2));
|
|
138
|
+
const allKeys = new Set([...keys1, ...keys2]);
|
|
139
|
+
for (const key of allKeys) {
|
|
140
|
+
const keyPath = path ? `${path}${options.pathSeparator}${key}` : key;
|
|
141
|
+
if (!keys1.has(key)) {
|
|
142
|
+
changes.push({
|
|
143
|
+
path: keyPath,
|
|
144
|
+
type: 'added',
|
|
145
|
+
newValue: obj2[key]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else if (!keys2.has(key)) {
|
|
149
|
+
changes.push({
|
|
150
|
+
path: keyPath,
|
|
151
|
+
type: 'removed',
|
|
152
|
+
oldValue: obj1[key]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
diffRecursive(obj1[key], obj2[key], keyPath, options, changes);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
/* c8 ignore next 9 - defensive code path that should never be reached with valid JsonValue types */
|
|
162
|
+
// Handle mixed object types
|
|
163
|
+
changes.push({
|
|
164
|
+
path,
|
|
165
|
+
type: 'modified',
|
|
166
|
+
oldValue: obj1,
|
|
167
|
+
newValue: obj2
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Performs a deep diff comparison between two JSON values.
|
|
172
|
+
*
|
|
173
|
+
* This function provides detailed change tracking by analyzing every difference
|
|
174
|
+
* between two JSON structures. It returns a list of specific changes with paths,
|
|
175
|
+
* making it ideal for debugging, logging, change analysis, and understanding
|
|
176
|
+
* exactly what has changed between two data states.
|
|
177
|
+
*
|
|
178
|
+
* **Key Features:**
|
|
179
|
+
* - Deep recursive comparison of nested objects and arrays
|
|
180
|
+
* - Precise path tracking using dot notation (e.g., "user.profile.name")
|
|
181
|
+
* - Support for all JSON value types: objects, arrays, primitives, null
|
|
182
|
+
* - Configurable array comparison (ordered vs unordered)
|
|
183
|
+
* - Optional inclusion of unchanged values for complete comparisons
|
|
184
|
+
*
|
|
185
|
+
* **Use Cases:**
|
|
186
|
+
* - Debugging data changes in applications
|
|
187
|
+
* - Generating change logs or audit trails
|
|
188
|
+
* - Validating API responses against expected data
|
|
189
|
+
* - Creating detailed diff reports for data synchronization
|
|
190
|
+
*
|
|
191
|
+
* @param obj1 - The first JSON value to compare (often the "before" state)
|
|
192
|
+
* @param obj2 - The second JSON value to compare (often the "after" state)
|
|
193
|
+
* @param options - Optional configuration for customizing diff behavior
|
|
194
|
+
* @returns A Result containing the diff result with all detected changes
|
|
195
|
+
*
|
|
196
|
+
* @example Basic usage with objects
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const before = { name: "John", age: 30, city: "NYC" };
|
|
199
|
+
* const after = { name: "Jane", age: 30, country: "USA" };
|
|
200
|
+
*
|
|
201
|
+
* const result = jsonDiff(before, after);
|
|
202
|
+
* if (result.success) {
|
|
203
|
+
* result.value.changes.forEach(change => {
|
|
204
|
+
* console.log(`${change.path}: ${change.type}`);
|
|
205
|
+
* // Output:
|
|
206
|
+
* // name: modified
|
|
207
|
+
* // city: removed
|
|
208
|
+
* // country: added
|
|
209
|
+
* });
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @example With arrays and nested structures
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const user1 = {
|
|
216
|
+
* profile: { name: "John", hobbies: ["reading"] },
|
|
217
|
+
* settings: { theme: "dark" }
|
|
218
|
+
* };
|
|
219
|
+
* const user2 = {
|
|
220
|
+
* profile: { name: "John", hobbies: ["reading", "gaming"] },
|
|
221
|
+
* settings: { theme: "light", notifications: true }
|
|
222
|
+
* };
|
|
223
|
+
*
|
|
224
|
+
* const result = jsonDiff(user1, user2);
|
|
225
|
+
* if (result.success) {
|
|
226
|
+
* console.log(result.value.changes);
|
|
227
|
+
* // [
|
|
228
|
+
* // { path: "profile.hobbies.1", type: "added", newValue: "gaming" },
|
|
229
|
+
* // { path: "settings.theme", type: "modified", oldValue: "dark", newValue: "light" },
|
|
230
|
+
* // { path: "settings.notifications", type: "added", newValue: true }
|
|
231
|
+
* // ]
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @example Using options for custom behavior
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const options: IJsonDiffOptions = {
|
|
238
|
+
* includeUnchanged: true, // Include unchanged properties
|
|
239
|
+
* pathSeparator: '/', // Use '/' instead of '.' in paths
|
|
240
|
+
* arrayOrderMatters: false // Treat arrays as unordered sets
|
|
241
|
+
* };
|
|
242
|
+
*
|
|
243
|
+
* const result = jsonDiff(obj1, obj2, options);
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @see {@link IDiffResult} for the structure of returned results
|
|
247
|
+
* @see {@link IDiffChange} for details about individual changes
|
|
248
|
+
* @see {@link IJsonDiffOptions} for available configuration options
|
|
249
|
+
* @see {@link jsonThreeWayDiff} for an alternative API focused on actionable results
|
|
250
|
+
* @see {@link jsonEquals} for simple equality checking without change details
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
function jsonDiff(obj1, obj2, options = {}) {
|
|
255
|
+
const opts = Object.assign({ includeUnchanged: false, pathSeparator: '.', arrayOrderMatters: true }, options);
|
|
256
|
+
const changes = [];
|
|
257
|
+
diffRecursive(obj1, obj2, '', opts, changes);
|
|
258
|
+
const result = {
|
|
259
|
+
changes,
|
|
260
|
+
identical: changes.length === 0 || changes.every((c) => c.type === 'unchanged')
|
|
261
|
+
};
|
|
262
|
+
return (0, ts_utils_1.succeed)(result);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A simpler helper function that returns true if two JSON values are deeply equal.
|
|
266
|
+
*
|
|
267
|
+
* This function provides a fast boolean check for JSON equality without the overhead
|
|
268
|
+
* of tracking individual changes. It performs the same deep comparison logic as
|
|
269
|
+
* {@link Diff.jsonDiff} but returns only a true/false result, making it ideal for
|
|
270
|
+
* conditional logic and validation scenarios.
|
|
271
|
+
*
|
|
272
|
+
* **Key Features:**
|
|
273
|
+
* - Deep recursive comparison of all nested structures
|
|
274
|
+
* - Handles all JSON types: objects, arrays, primitives, null
|
|
275
|
+
* - Object property order independence
|
|
276
|
+
* - Array order significance (index positions matter)
|
|
277
|
+
* - Performance optimized for equality checking
|
|
278
|
+
*
|
|
279
|
+
* **Use Cases:**
|
|
280
|
+
* - Conditional logic based on data equality
|
|
281
|
+
* - Input validation and testing assertions
|
|
282
|
+
* - Caching and memoization keys
|
|
283
|
+
* - Quick checks before expensive diff operations
|
|
284
|
+
*
|
|
285
|
+
* @param obj1 - The first JSON value to compare
|
|
286
|
+
* @param obj2 - The second JSON value to compare
|
|
287
|
+
* @returns True if the values are deeply equal, false otherwise
|
|
288
|
+
*
|
|
289
|
+
* @example Basic equality checking
|
|
290
|
+
* ```typescript
|
|
291
|
+
* // Objects with same structure and values
|
|
292
|
+
* const user1 = { name: "John", hobbies: ["reading", "gaming"] };
|
|
293
|
+
* const user2 = { name: "John", hobbies: ["reading", "gaming"] };
|
|
294
|
+
* console.log(jsonEquals(user1, user2)); // true
|
|
295
|
+
*
|
|
296
|
+
* // Different property order (still equal)
|
|
297
|
+
* const obj1 = { a: 1, b: 2 };
|
|
298
|
+
* const obj2 = { b: 2, a: 1 };
|
|
299
|
+
* console.log(jsonEquals(obj1, obj2)); // true
|
|
300
|
+
*
|
|
301
|
+
* // Different values
|
|
302
|
+
* const before = { status: "pending" };
|
|
303
|
+
* const after = { status: "completed" };
|
|
304
|
+
* console.log(jsonEquals(before, after)); // false
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* @example With nested structures
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const config1 = {
|
|
310
|
+
* database: { host: "localhost", port: 5432 },
|
|
311
|
+
* features: ["auth", "cache"]
|
|
312
|
+
* };
|
|
313
|
+
* const config2 = {
|
|
314
|
+
* database: { host: "localhost", port: 5432 },
|
|
315
|
+
* features: ["auth", "cache"]
|
|
316
|
+
* };
|
|
317
|
+
*
|
|
318
|
+
* if (jsonEquals(config1, config2)) {
|
|
319
|
+
* console.log("Configurations are identical");
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example Array order sensitivity
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const list1 = [1, 2, 3];
|
|
326
|
+
* const list2 = [3, 2, 1];
|
|
327
|
+
* console.log(jsonEquals(list1, list2)); // false - order matters
|
|
328
|
+
*
|
|
329
|
+
* const list3 = [1, 2, 3];
|
|
330
|
+
* const list4 = [1, 2, 3];
|
|
331
|
+
* console.log(jsonEquals(list3, list4)); // true - same order
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @see {@link Diff.jsonDiff} for detailed change analysis when equality fails
|
|
335
|
+
* @see {@link jsonThreeWayDiff} for actionable difference results
|
|
336
|
+
*
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
function jsonEquals(obj1, obj2) {
|
|
340
|
+
return (0, utils_1.deepEquals)(obj1, obj2);
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=detailedDiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detailedDiff.js","sourceRoot":"","sources":["../../../src/packlets/diff/detailedDiff.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAgdH,4BAqBC;AA6ED,gCAEC;AAljBD,oDAA0F;AAC1F,4CAAgD;AAChD,mCAAqC;AAgOrC;;GAEG;AACH,SAAS,aAAa,CACpB,IAAe,EACf,IAAe,EACf,IAAY,EACZ,OAAmC,EACnC,OAAsB;IAEtB,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjE,0BAA0B;IAC1B,IAA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B,iBAAiB,EAAE,IAAI,IACpB,OAAO,CACX,CAAC;IAEF,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAE7C,MAAM,MAAM,GAAgB;QAC1B,OAAO;QACP,SAAS,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;KAChF,CAAC;IAEF,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,SAAgB,UAAU,CAAC,IAAe,EAAE,IAAe;IACzD,OAAO,IAAA,kBAAU,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonValue, isJsonObject, isJsonArray, isJsonPrimitive } from '@fgv/ts-json-base';\nimport { Result, succeed } from '@fgv/ts-utils';\nimport { deepEquals } from './utils';\n\n/**\n * JSON Diff Utilities for TypeScript\n *\n * This module provides comprehensive tools for comparing JSON values and identifying\n * differences between them. It offers two complementary approaches:\n *\n * ## **Detailed Diff API** (`jsonDiff`)\n * Best for analysis, debugging, and understanding specific changes:\n * - Returns a list of individual changes with exact paths and values\n * - Ideal for logging, change tracking, and detailed analysis\n * - Configurable options for array handling and path notation\n *\n * ## **Three-Way Diff API** (`jsonThreeWayDiff`)\n * Best for applying changes and programmatic manipulation:\n * - Returns three objects representing removed, unchanged, and added data\n * - Perfect for merging, UI displays, and actionable results\n * - Treats arrays as atomic units for simpler handling\n *\n * ## **Simple Equality** (`jsonEquals`)\n * Fast boolean check for JSON equality without change details.\n *\n * **Key Features:**\n * - Deep recursive comparison of nested structures\n * - Support for all JSON types: objects, arrays, primitives, null\n * - TypeScript-first with comprehensive type safety\n * - Result pattern for consistent error handling\n * - Extensive TSDoc documentation with practical examples\n *\n * @example Quick comparison of the two main APIs\n * ```typescript\n * const before = { name: \"John\", age: 30, city: \"NYC\" };\n * const after = { name: \"Jane\", age: 30, country: \"USA\" };\n *\n * // Detailed analysis\n * const detailed = jsonDiff(before, after);\n * // Returns: [\n * // { path: \"name\", type: \"modified\", oldValue: \"John\", newValue: \"Jane\" },\n * // { path: \"city\", type: \"removed\", oldValue: \"NYC\" },\n * // { path: \"country\", type: \"added\", newValue: \"USA\" }\n * // ]\n *\n * // Actionable objects\n * const actionable = jsonThreeWayDiff(before, after);\n * // Returns: {\n * // onlyInA: { name: \"John\", city: \"NYC\" },\n * // unchanged: { age: 30 },\n * // onlyInB: { name: \"Jane\", country: \"USA\" }\n * // }\n *\n * // Apply changes: { ...unchanged, ...onlyInB }\n * // Revert changes: { ...unchanged, ...onlyInA }\n * ```\n */\n\n/**\n * Type of change detected in a JSON diff operation.\n *\n * - `'added'` - Property exists only in the second object\n * - `'removed'` - Property exists only in the first object\n * - `'modified'` - Property exists in both objects but with different values\n * - `'unchanged'` - Property exists in both objects with identical values (only included when `includeUnchanged` is true)\n *\n * @public\n */\nexport type DiffChangeType = 'added' | 'removed' | 'modified' | 'unchanged';\n\n/**\n * Represents a single change in a JSON diff operation.\n *\n * Each change describes a specific difference between two JSON values, including\n * the location of the change and the old/new values involved.\n *\n * @example\n * ```typescript\n * // Example changes from diffing { name: \"John\", age: 30 } vs { name: \"Jane\", city: \"NYC\" }\n * const changes: IDiffChange[] = [\n * { path: \"name\", type: \"modified\", oldValue: \"John\", newValue: \"Jane\" },\n * { path: \"age\", type: \"removed\", oldValue: 30 },\n * { path: \"city\", type: \"added\", newValue: \"NYC\" }\n * ];\n * ```\n *\n * @public\n */\nexport interface IDiffChange {\n /**\n * The path to the changed value using dot notation.\n *\n * For nested objects, uses dots to separate levels (e.g., \"user.profile.name\").\n * For arrays, uses numeric indices (e.g., \"items.0.id\", \"tags.2\").\n * Empty string indicates the root value itself changed.\n *\n * @example \"user.name\", \"items.0.id\", \"settings.theme\", \"\"\n */\n path: string;\n\n /**\n * The type of change that occurred.\n *\n * @see {@link DiffChangeType} for detailed descriptions of each change type.\n */\n type: DiffChangeType;\n\n /**\n * The value in the first object.\n *\n * - Present for `'removed'` and `'modified'` changes\n * - Present for `'unchanged'` changes when `includeUnchanged` is true\n * - Undefined for `'added'` changes\n */\n oldValue?: JsonValue;\n\n /**\n * The value in the second object.\n *\n * - Present for `'added'` and `'modified'` changes\n * - Present for `'unchanged'` changes when `includeUnchanged` is true\n * - Undefined for `'removed'` changes\n */\n newValue?: JsonValue;\n}\n\n/**\n * Result of a JSON diff operation containing all detected changes.\n *\n * This interface provides detailed information about every difference found\n * between two JSON values, making it ideal for analysis, debugging, and\n * understanding exactly what changed.\n *\n * @example\n * ```typescript\n * const result: IDiffResult = {\n * changes: [\n * { path: \"name\", type: \"modified\", oldValue: \"John\", newValue: \"Jane\" },\n * { path: \"hobbies.1\", type: \"added\", newValue: \"gaming\" }\n * ],\n * identical: false\n * };\n * ```\n *\n * @see {@link IDiffChange} for details about individual change objects\n * @see {@link Diff.jsonDiff} for the function that produces this result\n * @public\n */\nexport interface IDiffResult {\n /**\n * Array of all changes detected between the two JSON objects.\n *\n * Changes are ordered by the path where they occur. For nested structures,\n * parent changes appear before child changes.\n */\n changes: IDiffChange[];\n\n /**\n * True if the objects are identical, false otherwise.\n *\n * When true, the `changes` array will be empty (unless `includeUnchanged`\n * option was used, in which case it may contain 'unchanged' entries).\n */\n identical: boolean;\n}\n\n/**\n * Options for customizing JSON diff behavior.\n *\n * These options allow you to control how the diff algorithm processes\n * different types of JSON structures and what information is included\n * in the results.\n *\n * @example\n * ```typescript\n * // Include unchanged values and use custom path separator\n * const options: IJsonDiffOptions = {\n * includeUnchanged: true,\n * pathSeparator: '/',\n * arrayOrderMatters: false\n * };\n *\n * const result = jsonDiff(obj1, obj2, options);\n * ```\n *\n * @public\n */\nexport interface IJsonDiffOptions {\n /**\n * If true, includes unchanged values in the result.\n *\n * When enabled, the diff result will include entries with `type: 'unchanged'`\n * for properties that exist in both objects with identical values. This can\n * be useful for displaying complete side-by-side comparisons.\n *\n * @defaultValue false\n */\n includeUnchanged?: boolean;\n\n /**\n * Custom path separator for nested property paths.\n *\n * Controls the character used to separate levels in nested object paths.\n * For example, with separator `'/'`, a nested property would be reported\n * as `\"user/profile/name\"` instead of `\"user.profile.name\"`.\n *\n * @defaultValue \".\"\n * @example \"/\", \"-\\>\", \"::\"\n */\n pathSeparator?: string;\n\n /**\n * If true, treats arrays as ordered lists where position matters.\n * If false, treats arrays as unordered sets.\n *\n * When `true` (default), array changes are reported by index position:\n * `[1,2,3]` vs `[1,3,2]` shows modifications at indices 1 and 2.\n *\n * When `false`, arrays are compared as sets: `[1,2,3]` vs `[1,3,2]`\n * may be considered equivalent (simplified unordered comparison).\n *\n * @defaultValue true\n */\n arrayOrderMatters?: boolean;\n}\n\n/**\n * Internal recursive diff function that builds the change list.\n */\nfunction diffRecursive(\n obj1: JsonValue,\n obj2: JsonValue,\n path: string,\n options: Required<IJsonDiffOptions>,\n changes: IDiffChange[]\n): void {\n const pathPrefix = path ? `${path}${options.pathSeparator}` : '';\n\n // Handle primitive values\n if (isJsonPrimitive(obj1) || isJsonPrimitive(obj2)) {\n if (!deepEquals(obj1, obj2)) {\n changes.push({\n path,\n type: 'modified',\n oldValue: obj1,\n newValue: obj2\n });\n } else if (options.includeUnchanged) {\n changes.push({\n path,\n type: 'unchanged',\n oldValue: obj1,\n newValue: obj2\n });\n }\n return;\n }\n\n // Handle arrays\n if (isJsonArray(obj1) && isJsonArray(obj2)) {\n if (options.arrayOrderMatters) {\n // Ordered array comparison\n const maxLength = Math.max(obj1.length, obj2.length);\n for (let i = 0; i < maxLength; i++) {\n const itemPath = `${pathPrefix}${i}`;\n\n if (i >= obj1.length) {\n changes.push({\n path: itemPath,\n type: 'added',\n newValue: obj2[i]\n });\n } else if (i >= obj2.length) {\n changes.push({\n path: itemPath,\n type: 'removed',\n oldValue: obj1[i]\n });\n } else {\n diffRecursive(obj1[i], obj2[i], itemPath, options, changes);\n }\n }\n } else {\n // Unordered array comparison - simplified approach\n // This is a basic implementation; a more sophisticated approach would use\n // algorithms like longest common subsequence for better matching\n const processed = new Set<number>();\n\n // Find matching elements\n for (let i = 0; i < obj1.length; i++) {\n let found = false;\n for (let j = 0; j < obj2.length; j++) {\n if (!processed.has(j) && deepEquals(obj1[i], obj2[j])) {\n processed.add(j);\n found = true;\n if (options.includeUnchanged) {\n changes.push({\n path: `${pathPrefix}${i}`,\n type: 'unchanged',\n oldValue: obj1[i],\n newValue: obj2[j]\n });\n }\n break;\n }\n }\n if (!found) {\n changes.push({\n path: `${pathPrefix}${i}`,\n type: 'removed',\n oldValue: obj1[i]\n });\n }\n }\n\n // Find added elements\n for (let j = 0; j < obj2.length; j++) {\n if (!processed.has(j)) {\n changes.push({\n path: `${pathPrefix}${j}`,\n type: 'added',\n newValue: obj2[j]\n });\n }\n }\n }\n return;\n }\n\n // Handle one array, one non-array\n if (isJsonArray(obj1) || isJsonArray(obj2)) {\n changes.push({\n path,\n type: 'modified',\n oldValue: obj1,\n newValue: obj2\n });\n return;\n }\n\n // Handle objects\n if (isJsonObject(obj1) && isJsonObject(obj2)) {\n const keys1 = new Set(Object.keys(obj1));\n const keys2 = new Set(Object.keys(obj2));\n const allKeys = new Set([...keys1, ...keys2]);\n\n for (const key of allKeys) {\n const keyPath = path ? `${path}${options.pathSeparator}${key}` : key;\n\n if (!keys1.has(key)) {\n changes.push({\n path: keyPath,\n type: 'added',\n newValue: obj2[key]\n });\n } else if (!keys2.has(key)) {\n changes.push({\n path: keyPath,\n type: 'removed',\n oldValue: obj1[key]\n });\n } else {\n diffRecursive(obj1[key], obj2[key], keyPath, options, changes);\n }\n }\n return;\n }\n /* c8 ignore next 9 - defensive code path that should never be reached with valid JsonValue types */\n\n // Handle mixed object types\n changes.push({\n path,\n type: 'modified',\n oldValue: obj1,\n newValue: obj2\n });\n}\n\n/**\n * Performs a deep diff comparison between two JSON values.\n *\n * This function provides detailed change tracking by analyzing every difference\n * between two JSON structures. It returns a list of specific changes with paths,\n * making it ideal for debugging, logging, change analysis, and understanding\n * exactly what has changed between two data states.\n *\n * **Key Features:**\n * - Deep recursive comparison of nested objects and arrays\n * - Precise path tracking using dot notation (e.g., \"user.profile.name\")\n * - Support for all JSON value types: objects, arrays, primitives, null\n * - Configurable array comparison (ordered vs unordered)\n * - Optional inclusion of unchanged values for complete comparisons\n *\n * **Use Cases:**\n * - Debugging data changes in applications\n * - Generating change logs or audit trails\n * - Validating API responses against expected data\n * - Creating detailed diff reports for data synchronization\n *\n * @param obj1 - The first JSON value to compare (often the \"before\" state)\n * @param obj2 - The second JSON value to compare (often the \"after\" state)\n * @param options - Optional configuration for customizing diff behavior\n * @returns A Result containing the diff result with all detected changes\n *\n * @example Basic usage with objects\n * ```typescript\n * const before = { name: \"John\", age: 30, city: \"NYC\" };\n * const after = { name: \"Jane\", age: 30, country: \"USA\" };\n *\n * const result = jsonDiff(before, after);\n * if (result.success) {\n * result.value.changes.forEach(change => {\n * console.log(`${change.path}: ${change.type}`);\n * // Output:\n * // name: modified\n * // city: removed\n * // country: added\n * });\n * }\n * ```\n *\n * @example With arrays and nested structures\n * ```typescript\n * const user1 = {\n * profile: { name: \"John\", hobbies: [\"reading\"] },\n * settings: { theme: \"dark\" }\n * };\n * const user2 = {\n * profile: { name: \"John\", hobbies: [\"reading\", \"gaming\"] },\n * settings: { theme: \"light\", notifications: true }\n * };\n *\n * const result = jsonDiff(user1, user2);\n * if (result.success) {\n * console.log(result.value.changes);\n * // [\n * // { path: \"profile.hobbies.1\", type: \"added\", newValue: \"gaming\" },\n * // { path: \"settings.theme\", type: \"modified\", oldValue: \"dark\", newValue: \"light\" },\n * // { path: \"settings.notifications\", type: \"added\", newValue: true }\n * // ]\n * }\n * ```\n *\n * @example Using options for custom behavior\n * ```typescript\n * const options: IJsonDiffOptions = {\n * includeUnchanged: true, // Include unchanged properties\n * pathSeparator: '/', // Use '/' instead of '.' in paths\n * arrayOrderMatters: false // Treat arrays as unordered sets\n * };\n *\n * const result = jsonDiff(obj1, obj2, options);\n * ```\n *\n * @see {@link IDiffResult} for the structure of returned results\n * @see {@link IDiffChange} for details about individual changes\n * @see {@link IJsonDiffOptions} for available configuration options\n * @see {@link jsonThreeWayDiff} for an alternative API focused on actionable results\n * @see {@link jsonEquals} for simple equality checking without change details\n *\n * @public\n */\nexport function jsonDiff(\n obj1: JsonValue,\n obj2: JsonValue,\n options: IJsonDiffOptions = {}\n): Result<IDiffResult> {\n const opts: Required<IJsonDiffOptions> = {\n includeUnchanged: false,\n pathSeparator: '.',\n arrayOrderMatters: true,\n ...options\n };\n\n const changes: IDiffChange[] = [];\n diffRecursive(obj1, obj2, '', opts, changes);\n\n const result: IDiffResult = {\n changes,\n identical: changes.length === 0 || changes.every((c) => c.type === 'unchanged')\n };\n\n return succeed(result);\n}\n\n/**\n * A simpler helper function that returns true if two JSON values are deeply equal.\n *\n * This function provides a fast boolean check for JSON equality without the overhead\n * of tracking individual changes. It performs the same deep comparison logic as\n * {@link Diff.jsonDiff} but returns only a true/false result, making it ideal for\n * conditional logic and validation scenarios.\n *\n * **Key Features:**\n * - Deep recursive comparison of all nested structures\n * - Handles all JSON types: objects, arrays, primitives, null\n * - Object property order independence\n * - Array order significance (index positions matter)\n * - Performance optimized for equality checking\n *\n * **Use Cases:**\n * - Conditional logic based on data equality\n * - Input validation and testing assertions\n * - Caching and memoization keys\n * - Quick checks before expensive diff operations\n *\n * @param obj1 - The first JSON value to compare\n * @param obj2 - The second JSON value to compare\n * @returns True if the values are deeply equal, false otherwise\n *\n * @example Basic equality checking\n * ```typescript\n * // Objects with same structure and values\n * const user1 = { name: \"John\", hobbies: [\"reading\", \"gaming\"] };\n * const user2 = { name: \"John\", hobbies: [\"reading\", \"gaming\"] };\n * console.log(jsonEquals(user1, user2)); // true\n *\n * // Different property order (still equal)\n * const obj1 = { a: 1, b: 2 };\n * const obj2 = { b: 2, a: 1 };\n * console.log(jsonEquals(obj1, obj2)); // true\n *\n * // Different values\n * const before = { status: \"pending\" };\n * const after = { status: \"completed\" };\n * console.log(jsonEquals(before, after)); // false\n * ```\n *\n * @example With nested structures\n * ```typescript\n * const config1 = {\n * database: { host: \"localhost\", port: 5432 },\n * features: [\"auth\", \"cache\"]\n * };\n * const config2 = {\n * database: { host: \"localhost\", port: 5432 },\n * features: [\"auth\", \"cache\"]\n * };\n *\n * if (jsonEquals(config1, config2)) {\n * console.log(\"Configurations are identical\");\n * }\n * ```\n *\n * @example Array order sensitivity\n * ```typescript\n * const list1 = [1, 2, 3];\n * const list2 = [3, 2, 1];\n * console.log(jsonEquals(list1, list2)); // false - order matters\n *\n * const list3 = [1, 2, 3];\n * const list4 = [1, 2, 3];\n * console.log(jsonEquals(list3, list4)); // true - same order\n * ```\n *\n * @see {@link Diff.jsonDiff} for detailed change analysis when equality fails\n * @see {@link jsonThreeWayDiff} for actionable difference results\n *\n * @public\n */\nexport function jsonEquals(obj1: JsonValue, obj2: JsonValue): boolean {\n return deepEquals(obj1, obj2);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/diff/index.ts"],"names":[],"mappings":"AAsBA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
__exportStar(require("./detailedDiff"), exports);
|
|
39
|
+
__exportStar(require("./threeWayDiff"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/diff/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,iDAA+B;AAC/B,iDAA+B","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './detailedDiff';\nexport * from './threeWayDiff';\n"]}
|