@sanity/diff 6.9.2-next.9 → 6.9.3-next.1

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/lib/index.js CHANGED
@@ -2,6 +2,134 @@ import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, cleanupSemantic, makeDiff } from
2
2
  function replaceProperty(parent, prop, value) {
3
3
  return delete parent[prop], parent[prop] = value, value;
4
4
  }
5
+ function diffNumber(fromInput, toInput, options) {
6
+ let fromValue = fromInput.value, toValue = toInput.value, type = fromInput.type;
7
+ return fromValue === toValue ? {
8
+ type,
9
+ action: "unchanged",
10
+ fromValue,
11
+ toValue,
12
+ isChanged: !1
13
+ } : {
14
+ type: fromInput.type,
15
+ action: "changed",
16
+ isChanged: !0,
17
+ fromValue,
18
+ toValue,
19
+ annotation: toInput.annotation
20
+ };
21
+ }
22
+ function diffBoolean(fromInput, toInput, options) {
23
+ let fromValue = fromInput.value, toValue = toInput.value, type = fromInput.type;
24
+ return fromValue === toValue ? {
25
+ type,
26
+ action: "unchanged",
27
+ fromValue,
28
+ toValue,
29
+ isChanged: !1
30
+ } : {
31
+ type: fromInput.type,
32
+ action: "changed",
33
+ isChanged: !0,
34
+ fromValue,
35
+ toValue,
36
+ annotation: toInput.annotation
37
+ };
38
+ }
39
+ function diffString(fromInput, toInput, options) {
40
+ let fromValue = fromInput.value, toValue = toInput.value;
41
+ return fromValue === toValue ? {
42
+ type: "string",
43
+ action: "unchanged",
44
+ isChanged: !1,
45
+ fromValue,
46
+ toValue,
47
+ segments: [{
48
+ type: "stringSegment",
49
+ action: "unchanged",
50
+ text: fromValue
51
+ }]
52
+ } : {
53
+ type: "string",
54
+ action: "changed",
55
+ isChanged: !0,
56
+ fromValue,
57
+ toValue,
58
+ annotation: toInput.annotation,
59
+ get segments() {
60
+ let segments = buildSegments(fromInput, toInput);
61
+ return replaceProperty(this, "segments", segments);
62
+ }
63
+ };
64
+ }
65
+ function buildSegments(fromInput, toInput) {
66
+ let segments = [], dmpDiffs = cleanupSemantic(makeDiff(fromInput.value, toInput.value)), fromIdx = 0, toIdx = 0;
67
+ for (let [op, text] of dmpDiffs) switch (op) {
68
+ case DIFF_EQUAL:
69
+ segments.push({
70
+ type: "stringSegment",
71
+ action: "unchanged",
72
+ text
73
+ }), fromIdx += text.length, toIdx += text.length;
74
+ break;
75
+ case DIFF_DELETE:
76
+ for (let segment of fromInput.sliceAnnotation(fromIdx, fromIdx + text.length)) segments.push({
77
+ type: "stringSegment",
78
+ action: "removed",
79
+ text: segment.text,
80
+ annotation: segment.annotation
81
+ });
82
+ fromIdx += text.length;
83
+ break;
84
+ case DIFF_INSERT:
85
+ for (let segment of toInput.sliceAnnotation(toIdx, toIdx + text.length)) segments.push({
86
+ type: "stringSegment",
87
+ action: "added",
88
+ text: segment.text,
89
+ annotation: segment.annotation
90
+ });
91
+ toIdx += text.length;
92
+ break;
93
+ default: throw Error(`Unhandled diff-match-patch operation "${op}"`);
94
+ }
95
+ return segments;
96
+ }
97
+ function removedString(input, toValue, options) {
98
+ return {
99
+ type: "string",
100
+ action: "removed",
101
+ isChanged: !0,
102
+ fromValue: input.value,
103
+ toValue,
104
+ annotation: input.annotation,
105
+ get segments() {
106
+ let segments = input.sliceAnnotation(0, input.value.length).map((segment) => ({
107
+ type: "stringSegment",
108
+ action: "removed",
109
+ ...segment
110
+ }));
111
+ return replaceProperty(this, "segments", segments);
112
+ }
113
+ };
114
+ }
115
+ function addedString(input, fromValue, options) {
116
+ return {
117
+ type: "string",
118
+ action: "added",
119
+ isChanged: !0,
120
+ fromValue,
121
+ toValue: input.value,
122
+ annotation: input.annotation,
123
+ get segments() {
124
+ let segments = input.sliceAnnotation(0, input.value.length).map((segment) => ({
125
+ type: "stringSegment",
126
+ action: "added",
127
+ ...segment
128
+ }));
129
+ return replaceProperty(this, "segments", segments);
130
+ }
131
+ };
132
+ }
5
133
  function getLongestCommonSubsequence(previous, next) {
6
134
  return backtrack(getLengthMatrix(previous, next), previous, next);
7
135
  }
@@ -20,6 +148,113 @@ function backtrack(matrix, previous, next) {
20
148
  for (; prevIndex !== 0 && nextIndex !== 0;) previous[prevIndex - 1] === next[nextIndex - 1] ? (subsequence.sequence.unshift(previous[prevIndex - 1]), subsequence.prevIndices.unshift(prevIndex - 1), subsequence.nextIndices.unshift(nextIndex - 1), --prevIndex, --nextIndex) : matrix[prevIndex][nextIndex - 1] > matrix[prevIndex - 1][nextIndex] ? --nextIndex : --prevIndex;
21
149
  return subsequence;
22
150
  }
151
+ /**
152
+ * Takes a `from` and `to` input and calulates a diff between the two
153
+ *
154
+ * @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an "input"
155
+ * @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an "input"
156
+ * @param options - Options for the diffing process - currently no options are defined
157
+ * @returns A diff object representing the change
158
+ * @public
159
+ */
160
+ function diffInput(fromInput, toInput, options = {}) {
161
+ return fromInput.type === toInput.type ? diffWithType(fromInput.type, fromInput, toInput, options) : fromInput.type === "null" ? addedInput(toInput, null, options) : toInput.type === "null" ? removedInput(fromInput, null, options) : diffTypeChange(fromInput, toInput, options);
162
+ }
163
+ function diffWithType(type, fromInput, toInput, options) {
164
+ switch (type) {
165
+ case "null": return {
166
+ type: "null",
167
+ action: "unchanged",
168
+ isChanged: !1,
169
+ toValue: null,
170
+ fromValue: null
171
+ };
172
+ case "boolean": return diffBoolean(fromInput, toInput, options);
173
+ case "number": return diffNumber(fromInput, toInput, options);
174
+ case "string": return diffString(fromInput, toInput, options);
175
+ case "array": return diffArray(fromInput, toInput, options);
176
+ case "object": return diffObject(fromInput, toInput, options);
177
+ default: throw Error(`Unhandled diff type "${type}"`);
178
+ }
179
+ }
180
+ function removedInput(input, toValue, options) {
181
+ switch (input.type) {
182
+ case "null": return {
183
+ type: "null",
184
+ action: "removed",
185
+ isChanged: !0,
186
+ fromValue: null,
187
+ toValue,
188
+ annotation: input.annotation
189
+ };
190
+ case "boolean": return {
191
+ type: "boolean",
192
+ action: "removed",
193
+ isChanged: !0,
194
+ fromValue: input.value,
195
+ toValue,
196
+ annotation: input.annotation
197
+ };
198
+ case "number": return {
199
+ type: "number",
200
+ action: "removed",
201
+ isChanged: !0,
202
+ fromValue: input.value,
203
+ toValue,
204
+ annotation: input.annotation
205
+ };
206
+ case "string": return removedString(input, toValue, options);
207
+ case "array": return removedArray(input, toValue, options);
208
+ case "object": return removedObject(input, toValue, options);
209
+ default: throw Error("Unhandled diff type");
210
+ }
211
+ }
212
+ function addedInput(input, fromValue, options) {
213
+ switch (input.type) {
214
+ case "null": return {
215
+ type: "null",
216
+ action: "added",
217
+ isChanged: !0,
218
+ fromValue,
219
+ toValue: null,
220
+ annotation: input.annotation
221
+ };
222
+ case "boolean": return {
223
+ type: "boolean",
224
+ action: "added",
225
+ isChanged: !0,
226
+ fromValue,
227
+ toValue: input.value,
228
+ annotation: input.annotation
229
+ };
230
+ case "number": return {
231
+ type: "number",
232
+ action: "added",
233
+ isChanged: !0,
234
+ fromValue,
235
+ toValue: input.value,
236
+ annotation: input.annotation
237
+ };
238
+ case "string": return addedString(input, fromValue, options);
239
+ case "array": return addedArray(input, fromValue, options);
240
+ case "object": return addedObject(input, fromValue, options);
241
+ default: throw Error("Unhandled diff type");
242
+ }
243
+ }
244
+ function diffTypeChange(fromInput, toInput, options) {
245
+ return {
246
+ type: "typeChange",
247
+ action: "changed",
248
+ isChanged: !0,
249
+ fromType: fromInput.type,
250
+ fromValue: fromInput.value,
251
+ fromDiff: removedInput(fromInput, void 0, options),
252
+ toType: toInput.type,
253
+ toValue: toInput.value,
254
+ toDiff: addedInput(toInput, void 0, options),
255
+ annotation: toInput.annotation
256
+ };
257
+ }
23
258
  function diffArray(fromInput, toInput, options) {
24
259
  if (fromInput === toInput) return {
25
260
  type: "array",
@@ -108,7 +343,7 @@ function diffArrayByKey(fromArray, fromKeyIndex, toArray, toKeyIndex, options) {
108
343
  let items = [], isChanged = !1;
109
344
  function diffCommon(key, fromIndex, toIndex, hasMoved) {
110
345
  deletePositionInIndex(fromKeyIndex.index, key, fromIndex), deletePositionInIndex(toKeyIndex.index, key, toIndex);
111
- let diff = diffInput(fromArray.at(fromIndex), toArray.at(toIndex));
346
+ let diff = diffInput(fromArray.at(fromIndex), toArray.at(toIndex), options);
112
347
  items.push({
113
348
  fromIndex,
114
349
  toIndex,
@@ -193,13 +428,10 @@ function indexByKey(arr) {
193
428
  case "null":
194
429
  key = "n";
195
430
  break;
196
- case "object":
197
- {
198
- let keyField = item.get("_key");
199
- if (keyField && keyField.type === "string" && (key = `k${keyField.value}`, index.has(key))) return;
200
- }
201
- break;
202
- default:
431
+ case "object": {
432
+ let keyField = item.get("_key");
433
+ if (keyField && keyField.type === "string" && (key = `k${keyField.value}`, index.has(key))) return;
434
+ }
203
435
  }
204
436
  if (key === null) return;
205
437
  keys.push(key);
@@ -326,242 +558,27 @@ function addedObject(input, fromValue, options) {
326
558
  }
327
559
  };
328
560
  }
329
- function diffNumber(fromInput, toInput, options) {
330
- let fromValue = fromInput.value, toValue = toInput.value, type = fromInput.type;
331
- return fromValue === toValue ? {
332
- type,
333
- action: "unchanged",
334
- fromValue,
335
- toValue,
336
- isChanged: !1
337
- } : {
338
- type: fromInput.type,
339
- action: "changed",
340
- isChanged: !0,
341
- fromValue,
342
- toValue,
343
- annotation: toInput.annotation
344
- };
345
- }
346
- function diffBoolean(fromInput, toInput, options) {
347
- let fromValue = fromInput.value, toValue = toInput.value, type = fromInput.type;
348
- return fromValue === toValue ? {
349
- type,
350
- action: "unchanged",
351
- fromValue,
352
- toValue,
353
- isChanged: !1
354
- } : {
355
- type: fromInput.type,
356
- action: "changed",
357
- isChanged: !0,
358
- fromValue,
359
- toValue,
360
- annotation: toInput.annotation
361
- };
362
- }
363
- function diffString(fromInput, toInput, options) {
364
- let fromValue = fromInput.value, toValue = toInput.value;
365
- return fromValue === toValue ? {
366
- type: "string",
367
- action: "unchanged",
368
- isChanged: !1,
369
- fromValue,
370
- toValue,
371
- segments: [{
372
- type: "stringSegment",
373
- action: "unchanged",
374
- text: fromValue
375
- }]
376
- } : {
377
- type: "string",
378
- action: "changed",
379
- isChanged: !0,
380
- fromValue,
381
- toValue,
382
- annotation: toInput.annotation,
383
- get segments() {
384
- let segments = buildSegments(fromInput, toInput);
385
- return replaceProperty(this, "segments", segments);
386
- }
387
- };
388
- }
389
- function buildSegments(fromInput, toInput) {
390
- let segments = [], dmpDiffs = cleanupSemantic(makeDiff(fromInput.value, toInput.value)), fromIdx = 0, toIdx = 0;
391
- for (let [op, text] of dmpDiffs) switch (op) {
392
- case DIFF_EQUAL:
393
- segments.push({
394
- type: "stringSegment",
395
- action: "unchanged",
396
- text
397
- }), fromIdx += text.length, toIdx += text.length;
398
- break;
399
- case DIFF_DELETE:
400
- for (let segment of fromInput.sliceAnnotation(fromIdx, fromIdx + text.length)) segments.push({
401
- type: "stringSegment",
402
- action: "removed",
403
- text: segment.text,
404
- annotation: segment.annotation
405
- });
406
- fromIdx += text.length;
407
- break;
408
- case DIFF_INSERT:
409
- for (let segment of toInput.sliceAnnotation(toIdx, toIdx + text.length)) segments.push({
410
- type: "stringSegment",
411
- action: "added",
412
- text: segment.text,
413
- annotation: segment.annotation
414
- });
415
- toIdx += text.length;
416
- break;
417
- default: throw Error(`Unhandled diff-match-patch operation "${op}"`);
418
- }
419
- return segments;
420
- }
421
- function removedString(input, toValue, options) {
422
- return {
423
- type: "string",
424
- action: "removed",
425
- isChanged: !0,
426
- fromValue: input.value,
427
- toValue,
428
- annotation: input.annotation,
429
- get segments() {
430
- let segments = input.sliceAnnotation(0, input.value.length).map((segment) => ({
431
- type: "stringSegment",
432
- action: "removed",
433
- ...segment
434
- }));
435
- return replaceProperty(this, "segments", segments);
436
- }
437
- };
438
- }
439
- function addedString(input, fromValue, options) {
440
- return {
441
- type: "string",
442
- action: "added",
443
- isChanged: !0,
444
- fromValue,
445
- toValue: input.value,
446
- annotation: input.annotation,
447
- get segments() {
448
- let segments = input.sliceAnnotation(0, input.value.length).map((segment) => ({
449
- type: "stringSegment",
450
- action: "added",
451
- ...segment
452
- }));
453
- return replaceProperty(this, "segments", segments);
454
- }
455
- };
456
- }
457
- function diffTypeChange(fromInput, toInput, options) {
458
- return {
459
- type: "typeChange",
460
- action: "changed",
461
- isChanged: !0,
462
- fromType: fromInput.type,
463
- fromValue: fromInput.value,
464
- fromDiff: removedInput(fromInput, void 0, options),
465
- toType: toInput.type,
466
- toValue: toInput.value,
467
- toDiff: addedInput(toInput, void 0, options),
468
- annotation: toInput.annotation
469
- };
470
- }
471
- /**
472
- * Takes a `from` and `to` input and calulates a diff between the two
473
- *
474
- * @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an "input"
475
- * @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an "input"
476
- * @param options - Options for the diffing process - currently no options are defined
477
- * @returns A diff object representing the change
478
- * @public
479
- */
480
- function diffInput(fromInput, toInput, options = {}) {
481
- return fromInput.type === toInput.type ? diffWithType(fromInput.type, fromInput, toInput, options) : fromInput.type === "null" ? addedInput(toInput, null, options) : toInput.type === "null" ? removedInput(fromInput, null, options) : diffTypeChange(fromInput, toInput, options);
482
- }
483
- function diffWithType(type, fromInput, toInput, options) {
484
- switch (type) {
485
- case "null": return {
486
- type: "null",
487
- action: "unchanged",
488
- isChanged: !1,
489
- toValue: null,
490
- fromValue: null
491
- };
492
- case "boolean": return diffBoolean(fromInput, toInput, options);
493
- case "number": return diffNumber(fromInput, toInput, options);
494
- case "string": return diffString(fromInput, toInput, options);
495
- case "array": return diffArray(fromInput, toInput, options);
496
- case "object": return diffObject(fromInput, toInput, options);
497
- default: throw Error(`Unhandled diff type "${type}"`);
561
+ var BasicWrapper = class {
562
+ type;
563
+ value;
564
+ annotation;
565
+ constructor(type, value, annotation) {
566
+ this.type = type, this.value = value, this.annotation = annotation;
498
567
  }
499
- }
500
- function removedInput(input, toValue, options) {
501
- switch (input.type) {
502
- case "null": return {
503
- type: "null",
504
- action: "removed",
505
- isChanged: !0,
506
- fromValue: null,
507
- toValue,
508
- annotation: input.annotation
509
- };
510
- case "boolean": return {
511
- type: "boolean",
512
- action: "removed",
513
- isChanged: !0,
514
- fromValue: input.value,
515
- toValue,
516
- annotation: input.annotation
517
- };
518
- case "number": return {
519
- type: "number",
520
- action: "removed",
521
- isChanged: !0,
522
- fromValue: input.value,
523
- toValue,
524
- annotation: input.annotation
525
- };
526
- case "string": return removedString(input, toValue, options);
527
- case "array": return removedArray(input, toValue, options);
528
- case "object": return removedObject(input, toValue, options);
529
- default: throw Error("Unhandled diff type");
568
+ }, StringWrapper = class {
569
+ type = "string";
570
+ value;
571
+ annotation;
572
+ constructor(value, annotation) {
573
+ this.value = value, this.annotation = annotation;
530
574
  }
531
- }
532
- function addedInput(input, fromValue, options) {
533
- switch (input.type) {
534
- case "null": return {
535
- type: "null",
536
- action: "added",
537
- isChanged: !0,
538
- fromValue,
539
- toValue: null,
540
- annotation: input.annotation
541
- };
542
- case "boolean": return {
543
- type: "boolean",
544
- action: "added",
545
- isChanged: !0,
546
- fromValue,
547
- toValue: input.value,
548
- annotation: input.annotation
549
- };
550
- case "number": return {
551
- type: "number",
552
- action: "added",
553
- isChanged: !0,
554
- fromValue,
555
- toValue: input.value,
556
- annotation: input.annotation
557
- };
558
- case "string": return addedString(input, fromValue, options);
559
- case "array": return addedArray(input, fromValue, options);
560
- case "object": return addedObject(input, fromValue, options);
561
- default: throw Error("Unhandled diff type");
575
+ sliceAnnotation(start, end) {
576
+ return [{
577
+ text: this.value.slice(start, end),
578
+ annotation: this.annotation
579
+ }];
562
580
  }
563
- }
564
- var ArrayWrapper = class {
581
+ }, ArrayWrapper = class {
565
582
  type = "array";
566
583
  length;
567
584
  value;
@@ -577,13 +594,6 @@ var ArrayWrapper = class {
577
594
  annotationAt() {
578
595
  return this.annotation;
579
596
  }
580
- }, BasicWrapper = class {
581
- type;
582
- value;
583
- annotation;
584
- constructor(type, value, annotation) {
585
- this.type = type, this.value = value, this.annotation = annotation;
586
- }
587
597
  }, ObjectWrapper = class {
588
598
  type = "object";
589
599
  value;
@@ -604,20 +614,6 @@ var ArrayWrapper = class {
604
614
  function filterUndefinedEntries(value) {
605
615
  return Object.fromEntries(Object.entries(value).filter(([, entryValue]) => entryValue !== void 0));
606
616
  }
607
- var StringWrapper = class {
608
- type = "string";
609
- value;
610
- annotation;
611
- constructor(value, annotation) {
612
- this.value = value, this.annotation = annotation;
613
- }
614
- sliceAnnotation(start, end) {
615
- return [{
616
- text: this.value.slice(start, end),
617
- annotation: this.annotation
618
- }];
619
- }
620
- };
621
617
  /**
622
618
  * Takes an input (any JSON-serializable value) and an annotation, and generates an input
623
619
  * object for it, to be used with {@link diffInput | the diffInput() method} and others.
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/helpers.ts","../src/calculate/lcs.ts","../src/calculate/diffArray.ts","../src/calculate/diffObject.ts","../src/calculate/diffSimple.ts","../src/calculate/diffString.ts","../src/calculate/diffTypeChange.ts","../src/calculate/diffInput.ts","../src/inputWrappers/array.ts","../src/inputWrappers/basic.ts","../src/inputWrappers/object.ts","../src/inputWrappers/string.ts","../src/inputWrappers/index.ts"],"sourcesContent":["export function replaceProperty<P, V extends P[K], K extends keyof P>(\n parent: P,\n prop: K,\n value: V,\n): V {\n delete parent[prop]\n parent[prop] = value\n return value\n}\n","/*\n * Longest common subsequence implementation, for diffing arrays\n * Reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem\n */\n\ntype NumberArray = number[]\ntype LengthMatrix = NumberArray[]\ntype Subsequence<E> = {\n sequence: E[]\n prevIndices: number[]\n nextIndices: number[]\n}\n\nexport function getLongestCommonSubsequence<E>(previous: E[], next: E[]): Subsequence<E> {\n const matrix = getLengthMatrix(previous, next)\n const result = backtrack(matrix, previous, next)\n return result\n}\n\nfunction getLengthMatrix<E>(previous: E[], next: E[]): LengthMatrix {\n const len1 = previous.length\n const len2 = next.length\n let x = 0\n let y = 0\n\n // initialize empty matrix of len1+1 x len2+1\n const matrix: LengthMatrix = new Array(len1 + 1)\n for (x = 0; x < len1 + 1; x++) {\n matrix[x] = [len2 + 1]\n for (y = 0; y < len2 + 1; y++) {\n matrix[x][y] = 0\n }\n }\n\n // save sequence lengths for each coordinate\n for (x = 1; x < len1 + 1; x++) {\n for (y = 1; y < len2 + 1; y++) {\n if (previous[x - 1] === next[y - 1]) {\n matrix[x][y] = matrix[x - 1][y - 1] + 1\n } else {\n matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1])\n }\n }\n }\n\n return matrix\n}\n\nfunction backtrack<E>(matrix: LengthMatrix, previous: E[], next: E[]): Subsequence<E> {\n let prevIndex = previous.length\n let nextIndex = next.length\n const subsequence: Subsequence<E> = {\n sequence: [],\n prevIndices: [],\n nextIndices: [],\n }\n\n while (prevIndex !== 0 && nextIndex !== 0) {\n const areEqual = previous[prevIndex - 1] === next[nextIndex - 1]\n if (areEqual) {\n subsequence.sequence.unshift(previous[prevIndex - 1])\n subsequence.prevIndices.unshift(prevIndex - 1)\n subsequence.nextIndices.unshift(nextIndex - 1)\n --prevIndex\n --nextIndex\n } else {\n const valueAtMatrixAbove = matrix[prevIndex][nextIndex - 1]\n const valueAtMatrixLeft = matrix[prevIndex - 1][nextIndex]\n if (valueAtMatrixAbove > valueAtMatrixLeft) {\n --nextIndex\n } else {\n --prevIndex\n }\n }\n }\n return subsequence\n}\n","import {replaceProperty} from '../helpers'\nimport {type ArrayDiff, type ArrayInput, type DiffOptions, type ItemDiff} from '../types'\nimport {addedInput, diffInput, removedInput} from './diffInput'\nimport {getLongestCommonSubsequence} from './lcs'\n\nexport function diffArray<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ArrayDiff<A> {\n if (fromInput === toInput) {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n return {\n type: 'array',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n get items(): ItemDiff<A>[] {\n const items = diffExactByPosition(fromInput, toInput, options)\n if (!items) throw new Error('invariant broken: equivalent input, but diff detected')\n return replaceProperty(this, 'items', items)\n },\n }\n }\n\n // The key-ed approach should handle most cases (_key'ed objects, primitives):\n const keyedA = indexByKey(fromInput)\n const keyedB = indexByKey(toInput)\n\n if (keyedA && keyedB) {\n return diffArrayByKey(fromInput, keyedA, toInput, keyedB, options)\n }\n\n // Check if they are 100% equivalent:\n const items = diffExactByPosition(fromInput, toInput, options)\n if (items) return buildArrayDiff(fromInput, toInput, items, false)\n\n // Otherwise we create a diff where we model it as removing the from-items and adding the to-items.\n return diffArrayByReinsert(fromInput, toInput, options)\n}\n\nfunction buildArrayDiff<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n items: ItemDiff<A>[],\n isChanged: boolean,\n): ArrayDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n return isChanged\n ? {\n type: 'array',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n items,\n annotation: toInput.annotation,\n }\n : {\n type: 'array',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n items,\n }\n}\n\n/**\n * Diffes the two arrays by position. Returns an `items` array if they are unchanged, or undefined\n * if there are any changes anywhere.\n */\nfunction diffExactByPosition<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ItemDiff<A>[] | undefined {\n if (fromInput.length !== toInput.length) {\n return undefined\n }\n\n const items: ItemDiff<A>[] = []\n\n for (let idx = 0; idx < fromInput.length; idx++) {\n const diff = diffInput(fromInput.at(idx), toInput.at(idx), options)\n if (diff.isChanged) {\n return undefined\n }\n\n items.push({\n fromIndex: idx,\n toIndex: idx,\n hasMoved: false,\n diff,\n annotation: toInput.annotationAt(idx),\n })\n }\n\n return items\n}\n\nfunction diffArrayByReinsert<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ArrayDiff<A> {\n const items: ItemDiff<A>[] = []\n\n for (let idx = 0; idx < toInput.length; idx++) {\n const input = toInput.at(idx)\n\n items.push({\n fromIndex: undefined,\n toIndex: idx,\n hasMoved: false,\n diff: addedInput(input, undefined, options),\n annotation: input.annotation,\n })\n }\n\n for (let idx = 0; idx < fromInput.length; idx++) {\n const input = fromInput.at(idx)\n\n items.push({\n fromIndex: idx,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(input, undefined, options),\n annotation: input.annotation,\n })\n }\n\n return buildArrayDiff(fromInput, toInput, items, true)\n}\n\ntype Key = string | number | boolean\n\n/**\n * Diff an array when all the elements have _key in the same position.\n */\nfunction diffArrayByKey<A>(\n fromArray: ArrayInput<A>,\n fromKeyIndex: KeyIndex,\n toArray: ArrayInput<A>,\n toKeyIndex: KeyIndex,\n options: DiffOptions,\n): ArrayDiff<A> {\n const items: ItemDiff<A>[] = []\n let isChanged = false\n\n function diffCommon(key: Key, fromIndex: number, toIndex: number, hasMoved: boolean) {\n deletePositionInIndex(fromKeyIndex.index, key, fromIndex)\n deletePositionInIndex(toKeyIndex.index, key, toIndex)\n\n const fromInput = fromArray.at(fromIndex)\n const toInput = toArray.at(toIndex)\n\n const diff = diffInput(fromInput, toInput)\n items.push({\n fromIndex,\n toIndex,\n hasMoved,\n diff,\n annotation: toArray.annotationAt(toIndex),\n })\n\n if (diff.isChanged || fromIndex !== toIndex) {\n isChanged = true\n }\n }\n\n const lcs = getLongestCommonSubsequence(fromKeyIndex.keys, toKeyIndex.keys)\n\n for (let fromIndex = 0; fromIndex < fromKeyIndex.keys.length; fromIndex++) {\n const key = fromKeyIndex.keys[fromIndex]\n\n const subsequenceIdx = lcs.prevIndices.indexOf(fromIndex)\n if (subsequenceIdx !== -1) {\n // Part of the common subsequence => hasMoved:false\n diffCommon(key, fromIndex, lcs.nextIndices[subsequenceIdx], false)\n continue\n }\n\n // Not a part of the subsequence. Try to find another item which has the same key\n // and also is not part of the common subsequence.\n const toIndexes = toKeyIndex.index.get(key)\n const toIndex = toIndexes && toIndexes.find((idx) => !lcs.nextIndices.includes(idx))\n if (toIndex !== undefined) {\n diffCommon(key, fromIndex, toIndex, true)\n continue\n }\n\n const input = fromArray.at(fromIndex)\n\n items.push({\n fromIndex,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(input, undefined, options),\n annotation: fromArray.annotationAt(fromIndex),\n })\n\n isChanged = true\n }\n\n // The remaining data in toKeyIndex are the new elements which has been added\n for (const positions of toKeyIndex.index.values()) {\n for (const toIndex of positions) {\n const input = toArray.at(toIndex)\n items.push({\n fromIndex: undefined,\n toIndex,\n hasMoved: false,\n diff: addedInput(input, undefined, options),\n annotation: toArray.annotationAt(toIndex),\n })\n }\n\n isChanged = true\n }\n\n items.sort(compareItemDiff)\n\n return buildArrayDiff(fromArray, toArray, items, isChanged)\n}\n\nfunction compareItemDiff<A>(a: ItemDiff<A>, b: ItemDiff<A>): number {\n if (a.toIndex !== undefined && b.toIndex !== undefined) {\n return a.toIndex - b.toIndex\n }\n\n if (a.fromIndex !== undefined && b.fromIndex !== undefined) {\n return a.fromIndex - b.fromIndex\n }\n\n if (a.fromIndex !== undefined && b.toIndex !== undefined) {\n // A was removed and B was added. Prefer to sort removals last.\n return -1\n }\n\n if (a.toIndex !== undefined && b.fromIndex !== undefined) {\n // A was added and B was removed. Prefer to sort removals last.\n return 1\n }\n\n throw new Error('invalid item diff comparison')\n}\n\nfunction deletePositionInIndex(index: Map<Key, number[]>, key: Key, pos: number) {\n const positions = index.get(key)!\n deleteArrayValue(positions, pos)\n if (positions.length === 0) {\n index.delete(key)\n }\n}\n\nfunction deleteArrayValue<E>(arr: E[], value: E) {\n const idx = arr.indexOf(value)\n if (idx === -1) throw new Error('value not found')\n arr.splice(idx, 1)\n}\n\ntype KeyIndex = {\n keys: Key[]\n index: Map<Key, number[]>\n}\n\n/**\n * Indexes the array by a key. This handles cases where the items are:\n *\n * - Objects with _key\n * - Strings\n * - Numbers\n */\nfunction indexByKey<A>(arr: ArrayInput<A>): KeyIndex | undefined {\n const index = new Map<Key, number[]>()\n const keys: Key[] = []\n const length = arr.length\n\n for (let i = 0; i < length; i++) {\n const item = arr.at(i)\n\n let key: Key | null = null\n\n switch (item.type) {\n case 'string':\n key = `s${item.value}`\n break\n case 'number':\n key = item.value\n break\n case 'boolean':\n key = item.value\n break\n case 'null':\n key = 'n'\n break\n case 'object':\n {\n const keyField = item.get('_key')\n if (keyField && keyField.type === 'string') {\n key = `k${keyField.value}`\n\n // We do not handle duplicate _key\n if (index.has(key)) return undefined\n }\n }\n break\n default:\n }\n\n // No key => abort\n if (key === null) return undefined\n\n keys.push(key)\n let positions = index.get(key)\n if (!positions) {\n positions = []\n index.set(key, positions)\n }\n positions.push(i)\n }\n\n // All is good.\n return {keys, index}\n}\n\nexport function removedArray<A>(\n input: ArrayInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): ArrayDiff<A> & {action: 'removed'} {\n return {\n type: 'array',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get items(): ArrayDiff<A>['items'] {\n const items: ArrayDiff<A>['items'] = []\n for (let i = 0; i < input.length; i++) {\n const item = input.at(i)\n items.push({\n fromIndex: i,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(item, undefined, options),\n annotation: input.annotationAt(i),\n })\n }\n\n return replaceProperty(this, 'items', items)\n },\n }\n}\n\nexport function addedArray<A>(\n input: ArrayInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): ArrayDiff<A> & {action: 'added'} {\n return {\n type: 'array',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get items(): ArrayDiff<A>['items'] {\n const items: ArrayDiff<A>['items'] = []\n for (let i = 0; i < input.length; i++) {\n const item = input.at(i)\n items.push({\n fromIndex: undefined,\n toIndex: i,\n hasMoved: false,\n diff: addedInput(item, undefined, options),\n annotation: input.annotationAt(i),\n })\n }\n\n return replaceProperty(this, 'items', items)\n },\n }\n}\n","import {replaceProperty} from '../helpers'\nimport {type DiffOptions, type ObjectDiff, type ObjectInput} from '../types'\nimport {addedInput, diffInput, removedInput} from './diffInput'\n\nconst ignoredFields = new Set(['_id', '_type', '_createdAt', '_updatedAt', '_rev', '_weak'])\n\nexport function diffObject<A>(\n fromInput: ObjectInput<A>,\n toInput: ObjectInput<A>,\n options: DiffOptions,\n): ObjectDiff<A> {\n const fields: ObjectDiff<A>['fields'] = {}\n let isChanged = false\n\n for (const key of fromInput.keys) {\n if (ignoredFields.has(key)) continue\n\n const fromField = fromInput.get(key)!\n\n const toField = toInput.get(key)\n if (toField) {\n const fieldDiff = diffInput(fromField, toField, options)\n fields[key] = fieldDiff\n if (fieldDiff.isChanged) isChanged = true\n } else {\n fields[key] = removedInput(fromField, undefined, options)\n isChanged = true\n }\n }\n\n for (const key of toInput.keys) {\n if (ignoredFields.has(key)) continue\n\n // Already handled above\n if (fromInput.get(key)) continue\n\n const toField = toInput.get(key)!\n fields[key] = addedInput(toField, undefined, options)\n isChanged = true\n }\n\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n if (!isChanged) {\n return {\n type: 'object',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n fields,\n }\n }\n\n return {\n type: 'object',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n fields,\n annotation: toInput.annotation,\n }\n}\n\nexport function removedObject<A>(\n input: ObjectInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): ObjectDiff<A> & {action: 'removed'} {\n return {\n type: 'object',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get fields(): ObjectDiff<A>['fields'] {\n const fields: ObjectDiff<A>['fields'] = {}\n for (const key of input.keys) {\n const value = input.get(key)!\n fields[key] = removedInput(value, undefined, options)\n }\n return replaceProperty(this, 'fields', fields)\n },\n }\n}\n\nexport function addedObject<A>(\n input: ObjectInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): ObjectDiff<A> & {action: 'added'} {\n return {\n type: 'object',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get fields(): ObjectDiff<A>['fields'] {\n const fields: ObjectDiff<A>['fields'] = {}\n for (const key of input.keys) {\n const value = input.get(key)!\n fields[key] = addedInput(value, undefined, options)\n }\n return replaceProperty(this, 'fields', fields)\n },\n }\n}\n","import {\n type BooleanDiff,\n type BooleanInput,\n type DiffOptions,\n type NumberDiff,\n type NumberInput,\n} from '../types'\n\nexport function diffNumber<A>(\n fromInput: NumberInput<A>,\n toInput: NumberInput<A>,\n options: DiffOptions,\n): NumberDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n const type = fromInput.type\n\n if (fromValue === toValue)\n return {\n type,\n action: 'unchanged',\n fromValue,\n toValue,\n isChanged: false,\n }\n\n return {\n type: fromInput.type,\n action: 'changed',\n isChanged: true,\n fromValue: fromValue,\n toValue: toValue,\n annotation: toInput.annotation,\n }\n}\n\nexport function diffBoolean<A>(\n fromInput: BooleanInput<A>,\n toInput: BooleanInput<A>,\n options: DiffOptions,\n): BooleanDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n const type = fromInput.type\n\n if (fromValue === toValue)\n return {\n type,\n action: 'unchanged',\n fromValue,\n toValue,\n isChanged: false,\n }\n\n return {\n type: fromInput.type,\n action: 'changed',\n isChanged: true,\n fromValue: fromValue,\n toValue: toValue,\n annotation: toInput.annotation,\n }\n}\n","import {\n cleanupSemantic,\n DIFF_DELETE,\n DIFF_EQUAL,\n DIFF_INSERT,\n makeDiff,\n} from '@sanity/diff-match-patch'\n\nimport {replaceProperty} from '../helpers'\nimport {type DiffOptions, type StringDiff, type StringDiffSegment, type StringInput} from '../types'\n\nexport function diffString<A>(\n fromInput: StringInput<A>,\n toInput: StringInput<A>,\n options: DiffOptions,\n): StringDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n if (fromValue === toValue) {\n return {\n type: 'string',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n segments: [{type: 'stringSegment', action: 'unchanged', text: fromValue}],\n }\n }\n\n return {\n type: 'string',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n annotation: toInput.annotation,\n\n // Compute and memoize string segments only when accessed\n get segments(): StringDiffSegment<A>[] {\n const segments = buildSegments(fromInput, toInput)\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n\nfunction buildSegments<A>(\n fromInput: StringInput<A>,\n toInput: StringInput<A>,\n): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = []\n const dmpDiffs = cleanupSemantic(makeDiff(fromInput.value, toInput.value))\n\n let fromIdx = 0\n let toIdx = 0\n\n for (const [op, text] of dmpDiffs) {\n switch (op) {\n case DIFF_EQUAL:\n segments.push({type: 'stringSegment', action: 'unchanged', text})\n fromIdx += text.length\n toIdx += text.length\n break\n case DIFF_DELETE:\n for (const segment of fromInput.sliceAnnotation(fromIdx, fromIdx + text.length)) {\n segments.push({\n type: 'stringSegment',\n action: 'removed',\n text: segment.text,\n annotation: segment.annotation,\n })\n }\n fromIdx += text.length\n break\n case DIFF_INSERT:\n for (const segment of toInput.sliceAnnotation(toIdx, toIdx + text.length)) {\n segments.push({\n type: 'stringSegment',\n action: 'added',\n text: segment.text,\n annotation: segment.annotation,\n })\n }\n toIdx += text.length\n break\n default:\n throw new Error(`Unhandled diff-match-patch operation \"${op}\"`)\n }\n }\n\n return segments\n}\n\nexport function removedString<A>(\n input: StringInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): StringDiff<A> & {action: 'removed'} {\n return {\n type: 'string',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get segments(): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = input\n .sliceAnnotation(0, input.value.length)\n .map((segment) => ({type: 'stringSegment', action: 'removed', ...segment}))\n\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n\nexport function addedString<A>(\n input: StringInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): StringDiff<A> & {action: 'added'} {\n return {\n type: 'string',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get segments(): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = input\n .sliceAnnotation(0, input.value.length)\n .map((segment) => ({type: 'stringSegment', action: 'added', ...segment}))\n\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n","import {type DiffOptions, type Input, type TypeChangeDiff} from '../types'\nimport {addedInput, removedInput} from './diffInput'\n\nexport function diffTypeChange<A>(\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions,\n): TypeChangeDiff<A> {\n return {\n type: 'typeChange',\n action: 'changed',\n isChanged: true,\n\n fromType: fromInput.type,\n fromValue: fromInput.value,\n fromDiff: removedInput(fromInput, undefined, options),\n\n toType: toInput.type,\n toValue: toInput.value,\n toDiff: addedInput(toInput, undefined, options),\n\n annotation: toInput.annotation,\n }\n}\n","import {\n type ArrayInput,\n type BooleanInput,\n type Diff,\n type DiffOptions,\n type Input,\n type NumberInput,\n type ObjectInput,\n type StringInput,\n} from '../types'\nimport {addedArray, diffArray, removedArray} from './diffArray'\nimport {addedObject, diffObject, removedObject} from './diffObject'\nimport {diffBoolean, diffNumber} from './diffSimple'\nimport {addedString, diffString, removedString} from './diffString'\nimport {diffTypeChange} from './diffTypeChange'\n\n/**\n * Takes a `from` and `to` input and calulates a diff between the two\n *\n * @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an \"input\"\n * @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an \"input\"\n * @param options - Options for the diffing process - currently no options are defined\n * @returns A diff object representing the change\n * @public\n */\nexport function diffInput<A>(\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions = {},\n): Diff<A> {\n if (fromInput.type !== toInput.type) {\n if (fromInput.type === 'null') {\n return addedInput(toInput, null, options)\n }\n\n if (toInput.type === 'null') {\n return removedInput(fromInput, null, options)\n }\n\n return diffTypeChange(fromInput, toInput, options)\n }\n\n return diffWithType(fromInput.type, fromInput, toInput, options)\n}\n\nfunction diffWithType<A>(\n type: Input<A>['type'],\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions,\n): Diff<A> {\n switch (type) {\n case 'null':\n return {\n type: 'null',\n action: 'unchanged',\n isChanged: false,\n toValue: null,\n fromValue: null,\n }\n case 'boolean':\n return diffBoolean(fromInput as BooleanInput<A>, toInput as BooleanInput<A>, options)\n case 'number':\n return diffNumber(fromInput as NumberInput<A>, toInput as NumberInput<A>, options)\n case 'string':\n return diffString(fromInput as StringInput<A>, toInput as StringInput<A>, options)\n case 'array':\n return diffArray(fromInput as ArrayInput<A>, toInput as ArrayInput<A>, options)\n case 'object':\n return diffObject(fromInput as ObjectInput<A>, toInput as ObjectInput<A>, options)\n default:\n // oxlint-disable-next-line restrict-template-expressions - this is a fallback in an edge case scenario, so we can't trust that `type` is truly `never`\n throw new Error(`Unhandled diff type \"${type}\"`)\n }\n}\n\nexport function removedInput<A>(\n input: Input<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): Diff<A> & {action: 'removed'} {\n switch (input.type) {\n case 'null':\n return {\n type: 'null',\n action: 'removed',\n isChanged: true,\n fromValue: null,\n toValue,\n annotation: input.annotation,\n }\n case 'boolean':\n return {\n type: 'boolean',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n }\n case 'number':\n return {\n type: 'number',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n }\n case 'string':\n return removedString(input, toValue, options)\n case 'array':\n return removedArray(input, toValue, options)\n case 'object':\n return removedObject(input, toValue, options)\n default:\n throw new Error('Unhandled diff type')\n }\n}\n\nexport function addedInput<A>(\n input: Input<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): Diff<A> & {action: 'added'} {\n switch (input.type) {\n case 'null':\n return {\n type: 'null',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: null,\n annotation: input.annotation,\n }\n case 'boolean':\n return {\n type: 'boolean',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n }\n case 'number':\n return {\n type: 'number',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n }\n case 'string':\n return addedString(input, fromValue, options)\n case 'array':\n return addedArray(input, fromValue, options)\n case 'object':\n return addedObject(input, fromValue, options)\n default:\n throw new Error('Unhandled diff type')\n }\n}\n","import {type ArrayInput, type Input} from '../types'\nimport {wrap} from './index'\n\nexport default class ArrayWrapper<A> implements ArrayInput<A> {\n type = 'array' as const\n length: number\n value: unknown[]\n annotation: A\n\n private elements: Input<A>[] = []\n\n constructor(value: unknown[], annotation: A) {\n this.annotation = annotation\n this.value = value\n this.length = value.length\n }\n\n at(idx: number): Input<A> {\n if (idx >= this.length) throw new Error('out of bounds')\n const input = this.elements[idx]\n if (input) {\n return input\n }\n\n return (this.elements[idx] = wrap(this.value[idx], this.annotation))\n }\n\n annotationAt(): A {\n return this.annotation\n }\n}\n","type SimpleType = 'boolean' | 'number' | 'null'\n\nexport default class BasicWrapper<K extends SimpleType, V, A> {\n type: K\n value: V\n annotation: A\n\n constructor(type: K, value: V, annotation: A) {\n this.type = type\n this.value = value\n this.annotation = annotation\n }\n}\n","import {type Input, type ObjectInput} from '../types'\nimport {wrap} from './index'\n\nexport default class ObjectWrapper<A> implements ObjectInput<A> {\n type = 'object' as const\n value: Record<string, unknown>\n keys: string[]\n annotation: A\n\n private fields: Record<string, Input<A>> = {}\n\n constructor(value: Record<string, unknown>, annotation: A) {\n this.value = filterUndefinedEntries(value)\n this.annotation = annotation\n this.keys = Object.keys(this.value)\n }\n\n get(key: string): Input<A> | undefined {\n const input = this.fields[key]\n if (input) {\n return input\n }\n\n if (!this.value.hasOwnProperty(key)) {\n return undefined\n }\n\n const raw = this.value[key]\n return (this.fields[key] = wrap(raw, this.annotation))\n }\n}\n\nfunction filterUndefinedEntries(value: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(value).filter(([, entryValue]) => typeof entryValue !== 'undefined'),\n )\n}\n","import {type StringInput} from '../types'\n\nexport default class StringWrapper<A> implements StringInput<A> {\n type = 'string' as const\n value: string\n annotation: A\n\n constructor(value: string, annotation: A) {\n this.value = value\n this.annotation = annotation\n }\n\n sliceAnnotation(start: number, end: number): {text: string; annotation: A}[] {\n return [{text: this.value.slice(start, end), annotation: this.annotation}]\n }\n}\n","import {type Input} from '../types'\nimport ArrayWrapper from './array'\nimport BasicWrapper from './basic'\nimport ObjectWrapper from './object'\nimport StringWrapper from './string'\n\n/**\n * Takes an input (any JSON-serializable value) and an annotation, and generates an input\n * object for it, to be used with {@link diffInput | the diffInput() method} and others.\n *\n * @param input - The value to wrap in an input object\n * @param annotation - Annotation attached to the input - will be bound to generated diffs\n * @returns A input object\n * @throws if `input` is not a JSON-serializable type\n * @public\n */\nexport function wrap<A>(input: unknown, annotation: A): Input<A> {\n if (Array.isArray(input)) {\n return new ArrayWrapper(input, annotation)\n } else if (input === null) {\n return new BasicWrapper('null', input, annotation)\n }\n\n const type = typeof input\n switch (type) {\n case 'number':\n return new BasicWrapper(type, input as number, annotation)\n case 'boolean':\n return new BasicWrapper(type, input as boolean, annotation)\n case 'object':\n return new ObjectWrapper(input as Record<string, unknown>, annotation)\n case 'string':\n return new StringWrapper(input as string, annotation)\n default:\n throw new Error(`cannot wrap value of type: ${type}`)\n }\n}\n"],"mappings":";AAAA,SAAgB,gBACd,QACA,MACA,OACG;CAGH,OAFA,OAAO,OAAO,OACd,OAAO,QAAQ,OACR;AACT;ACKA,SAAgB,4BAA+B,UAAe,MAA2B;CAGvF,OADe,UADA,gBAAgB,UAAU,IACX,GAAG,UAAU,IAC/B;AACd;AAEA,SAAS,gBAAmB,UAAe,MAAyB;CAClE,IAAM,OAAO,SAAS,QAChB,OAAO,KAAK,QACd,IAAI,GACJ,IAAI,GAGF,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GAAG;GAAG,YAAY,KAAK;EAAU,CAAC;CAC3E;AACF;;;;;;;;;;;ACCA,SAAgB,KAAQ,OAAgB,YAAyB;CAC/D,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,IAAI,aAAa,OAAO,UAAU;CACpC,IAAI,UAAU,MACnB,OAAO,IAAI,aAAa,QAAQ,OAAO,UAAU;CAGnD,IAAM,OAAO,OAAO;CACpB,QAAQ,MAAR;EACE,KAAK,UACH,OAAO,IAAI,aAAa,MAAM,OAAiB,UAAU;EAC3D,KAAK,WACH,OAAO,IAAI,aAAa,MAAM,OAAkB,UAAU;EAC5D,KAAK,UACH,OAAO,IAAI,cAAc,OAAkC,UAAU;EACvE,KAAK,UACH,OAAO,IAAI,cAAc,OAAiB,UAAU;EACtD,SACE,MAAU,MAAM,8BAA8B,MAAM;CACxD;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/helpers.ts","../src/calculate/diffSimple.ts","../src/calculate/diffString.ts","../src/calculate/lcs.ts","../src/calculate/differs.ts","../src/inputWrappers.ts"],"sourcesContent":["export function replaceProperty<P, V extends P[K], K extends keyof P>(\n parent: P,\n prop: K,\n value: V,\n): V {\n delete parent[prop]\n parent[prop] = value\n return value\n}\n","import {\n type BooleanDiff,\n type BooleanInput,\n type DiffOptions,\n type NumberDiff,\n type NumberInput,\n} from '../types'\n\nexport function diffNumber<A>(\n fromInput: NumberInput<A>,\n toInput: NumberInput<A>,\n options: DiffOptions,\n): NumberDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n const type = fromInput.type\n\n if (fromValue === toValue)\n return {\n type,\n action: 'unchanged',\n fromValue,\n toValue,\n isChanged: false,\n }\n\n return {\n type: fromInput.type,\n action: 'changed',\n isChanged: true,\n fromValue: fromValue,\n toValue: toValue,\n annotation: toInput.annotation,\n }\n}\n\nexport function diffBoolean<A>(\n fromInput: BooleanInput<A>,\n toInput: BooleanInput<A>,\n options: DiffOptions,\n): BooleanDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n const type = fromInput.type\n\n if (fromValue === toValue)\n return {\n type,\n action: 'unchanged',\n fromValue,\n toValue,\n isChanged: false,\n }\n\n return {\n type: fromInput.type,\n action: 'changed',\n isChanged: true,\n fromValue: fromValue,\n toValue: toValue,\n annotation: toInput.annotation,\n }\n}\n","import {\n cleanupSemantic,\n DIFF_DELETE,\n DIFF_EQUAL,\n DIFF_INSERT,\n makeDiff,\n} from '@sanity/diff-match-patch'\n\nimport {replaceProperty} from '../helpers'\nimport {type DiffOptions, type StringDiff, type StringDiffSegment, type StringInput} from '../types'\n\nexport function diffString<A>(\n fromInput: StringInput<A>,\n toInput: StringInput<A>,\n options: DiffOptions,\n): StringDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n if (fromValue === toValue) {\n return {\n type: 'string',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n segments: [{type: 'stringSegment', action: 'unchanged', text: fromValue}],\n }\n }\n\n return {\n type: 'string',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n annotation: toInput.annotation,\n\n // Compute and memoize string segments only when accessed\n get segments(): StringDiffSegment<A>[] {\n const segments = buildSegments(fromInput, toInput)\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n\nfunction buildSegments<A>(\n fromInput: StringInput<A>,\n toInput: StringInput<A>,\n): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = []\n const dmpDiffs = cleanupSemantic(makeDiff(fromInput.value, toInput.value))\n\n let fromIdx = 0\n let toIdx = 0\n\n for (const [op, text] of dmpDiffs) {\n switch (op) {\n case DIFF_EQUAL:\n segments.push({type: 'stringSegment', action: 'unchanged', text})\n fromIdx += text.length\n toIdx += text.length\n break\n case DIFF_DELETE:\n for (const segment of fromInput.sliceAnnotation(fromIdx, fromIdx + text.length)) {\n segments.push({\n type: 'stringSegment',\n action: 'removed',\n text: segment.text,\n annotation: segment.annotation,\n })\n }\n fromIdx += text.length\n break\n case DIFF_INSERT:\n for (const segment of toInput.sliceAnnotation(toIdx, toIdx + text.length)) {\n segments.push({\n type: 'stringSegment',\n action: 'added',\n text: segment.text,\n annotation: segment.annotation,\n })\n }\n toIdx += text.length\n break\n default:\n throw new Error(`Unhandled diff-match-patch operation \"${op}\"`)\n }\n }\n\n return segments\n}\n\nexport function removedString<A>(\n input: StringInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): StringDiff<A> & {action: 'removed'} {\n return {\n type: 'string',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get segments(): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = input\n .sliceAnnotation(0, input.value.length)\n .map((segment) => ({type: 'stringSegment', action: 'removed', ...segment}))\n\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n\nexport function addedString<A>(\n input: StringInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): StringDiff<A> & {action: 'added'} {\n return {\n type: 'string',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get segments(): StringDiffSegment<A>[] {\n const segments: StringDiffSegment<A>[] = input\n .sliceAnnotation(0, input.value.length)\n .map((segment) => ({type: 'stringSegment', action: 'added', ...segment}))\n\n return replaceProperty(this, 'segments', segments)\n },\n }\n}\n","/*\n * Longest common subsequence implementation, for diffing arrays\n * Reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem\n */\n\ntype NumberArray = number[]\ntype LengthMatrix = NumberArray[]\ntype Subsequence<E> = {\n sequence: E[]\n prevIndices: number[]\n nextIndices: number[]\n}\n\nexport function getLongestCommonSubsequence<E>(previous: E[], next: E[]): Subsequence<E> {\n const matrix = getLengthMatrix(previous, next)\n const result = backtrack(matrix, previous, next)\n return result\n}\n\nfunction getLengthMatrix<E>(previous: E[], next: E[]): LengthMatrix {\n const len1 = previous.length\n const len2 = next.length\n let x = 0\n let y = 0\n\n // initialize empty matrix of len1+1 x len2+1\n const matrix: LengthMatrix = new Array(len1 + 1)\n for (x = 0; x < len1 + 1; x++) {\n matrix[x] = [len2 + 1]\n for (y = 0; y < len2 + 1; y++) {\n matrix[x][y] = 0\n }\n }\n\n // save sequence lengths for each coordinate\n for (x = 1; x < len1 + 1; x++) {\n for (y = 1; y < len2 + 1; y++) {\n if (previous[x - 1] === next[y - 1]) {\n matrix[x][y] = matrix[x - 1][y - 1] + 1\n } else {\n matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1])\n }\n }\n }\n\n return matrix\n}\n\nfunction backtrack<E>(matrix: LengthMatrix, previous: E[], next: E[]): Subsequence<E> {\n let prevIndex = previous.length\n let nextIndex = next.length\n const subsequence: Subsequence<E> = {\n sequence: [],\n prevIndices: [],\n nextIndices: [],\n }\n\n while (prevIndex !== 0 && nextIndex !== 0) {\n const areEqual = previous[prevIndex - 1] === next[nextIndex - 1]\n if (areEqual) {\n subsequence.sequence.unshift(previous[prevIndex - 1])\n subsequence.prevIndices.unshift(prevIndex - 1)\n subsequence.nextIndices.unshift(nextIndex - 1)\n --prevIndex\n --nextIndex\n } else {\n const valueAtMatrixAbove = matrix[prevIndex][nextIndex - 1]\n const valueAtMatrixLeft = matrix[prevIndex - 1][nextIndex]\n if (valueAtMatrixAbove > valueAtMatrixLeft) {\n --nextIndex\n } else {\n --prevIndex\n }\n }\n }\n return subsequence\n}\n","import {replaceProperty} from '../helpers'\nimport {\n type ArrayDiff,\n type ArrayInput,\n type BooleanInput,\n type Diff,\n type DiffOptions,\n type Input,\n type ItemDiff,\n type NumberInput,\n type ObjectDiff,\n type ObjectInput,\n type StringInput,\n type TypeChangeDiff,\n} from '../types'\nimport {diffBoolean, diffNumber} from './diffSimple'\nimport {addedString, diffString, removedString} from './diffString'\nimport {getLongestCommonSubsequence} from './lcs'\n\n// The type dispatchers (`diffInput`, `addedInput`, `removedInput`) and the container handlers\n// (`diffArray`, `diffObject`, `diffTypeChange`) are mutually recursive, so they live in the same\n// module to avoid circular imports.\n\n/**\n * Takes a `from` and `to` input and calulates a diff between the two\n *\n * @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an \"input\"\n * @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an \"input\"\n * @param options - Options for the diffing process - currently no options are defined\n * @returns A diff object representing the change\n * @public\n */\nexport function diffInput<A>(\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions = {},\n): Diff<A> {\n if (fromInput.type !== toInput.type) {\n if (fromInput.type === 'null') {\n return addedInput(toInput, null, options)\n }\n\n if (toInput.type === 'null') {\n return removedInput(fromInput, null, options)\n }\n\n return diffTypeChange(fromInput, toInput, options)\n }\n\n return diffWithType(fromInput.type, fromInput, toInput, options)\n}\n\nfunction diffWithType<A>(\n type: Input<A>['type'],\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions,\n): Diff<A> {\n switch (type) {\n case 'null':\n return {\n type: 'null',\n action: 'unchanged',\n isChanged: false,\n toValue: null,\n fromValue: null,\n }\n case 'boolean':\n return diffBoolean(fromInput as BooleanInput<A>, toInput as BooleanInput<A>, options)\n case 'number':\n return diffNumber(fromInput as NumberInput<A>, toInput as NumberInput<A>, options)\n case 'string':\n return diffString(fromInput as StringInput<A>, toInput as StringInput<A>, options)\n case 'array':\n return diffArray(fromInput as ArrayInput<A>, toInput as ArrayInput<A>, options)\n case 'object':\n return diffObject(fromInput as ObjectInput<A>, toInput as ObjectInput<A>, options)\n default:\n // oxlint-disable-next-line restrict-template-expressions - this is a fallback in an edge case scenario, so we can't trust that `type` is truly `never`\n throw new Error(`Unhandled diff type \"${type}\"`)\n }\n}\n\nfunction removedInput<A>(\n input: Input<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): Diff<A> & {action: 'removed'} {\n switch (input.type) {\n case 'null':\n return {\n type: 'null',\n action: 'removed',\n isChanged: true,\n fromValue: null,\n toValue,\n annotation: input.annotation,\n }\n case 'boolean':\n return {\n type: 'boolean',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n }\n case 'number':\n return {\n type: 'number',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n }\n case 'string':\n return removedString(input, toValue, options)\n case 'array':\n return removedArray(input, toValue, options)\n case 'object':\n return removedObject(input, toValue, options)\n default:\n throw new Error('Unhandled diff type')\n }\n}\n\nfunction addedInput<A>(\n input: Input<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): Diff<A> & {action: 'added'} {\n switch (input.type) {\n case 'null':\n return {\n type: 'null',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: null,\n annotation: input.annotation,\n }\n case 'boolean':\n return {\n type: 'boolean',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n }\n case 'number':\n return {\n type: 'number',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n }\n case 'string':\n return addedString(input, fromValue, options)\n case 'array':\n return addedArray(input, fromValue, options)\n case 'object':\n return addedObject(input, fromValue, options)\n default:\n throw new Error('Unhandled diff type')\n }\n}\n\nfunction diffTypeChange<A>(\n fromInput: Input<A>,\n toInput: Input<A>,\n options: DiffOptions,\n): TypeChangeDiff<A> {\n return {\n type: 'typeChange',\n action: 'changed',\n isChanged: true,\n\n fromType: fromInput.type,\n fromValue: fromInput.value,\n fromDiff: removedInput(fromInput, undefined, options),\n\n toType: toInput.type,\n toValue: toInput.value,\n toDiff: addedInput(toInput, undefined, options),\n\n annotation: toInput.annotation,\n }\n}\n\nfunction diffArray<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ArrayDiff<A> {\n if (fromInput === toInput) {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n return {\n type: 'array',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n get items(): ItemDiff<A>[] {\n const items = diffExactByPosition(fromInput, toInput, options)\n if (!items) throw new Error('invariant broken: equivalent input, but diff detected')\n return replaceProperty(this, 'items', items)\n },\n }\n }\n\n // The key-ed approach should handle most cases (_key'ed objects, primitives):\n const keyedA = indexByKey(fromInput)\n const keyedB = indexByKey(toInput)\n\n if (keyedA && keyedB) {\n return diffArrayByKey(fromInput, keyedA, toInput, keyedB, options)\n }\n\n // Check if they are 100% equivalent:\n const items = diffExactByPosition(fromInput, toInput, options)\n if (items) return buildArrayDiff(fromInput, toInput, items, false)\n\n // Otherwise we create a diff where we model it as removing the from-items and adding the to-items.\n return diffArrayByReinsert(fromInput, toInput, options)\n}\n\nfunction buildArrayDiff<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n items: ItemDiff<A>[],\n isChanged: boolean,\n): ArrayDiff<A> {\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n return isChanged\n ? {\n type: 'array',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n items,\n annotation: toInput.annotation,\n }\n : {\n type: 'array',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n items,\n }\n}\n\n/**\n * Diffes the two arrays by position. Returns an `items` array if they are unchanged, or undefined\n * if there are any changes anywhere.\n */\nfunction diffExactByPosition<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ItemDiff<A>[] | undefined {\n if (fromInput.length !== toInput.length) {\n return undefined\n }\n\n const items: ItemDiff<A>[] = []\n\n for (let idx = 0; idx < fromInput.length; idx++) {\n const diff = diffInput(fromInput.at(idx), toInput.at(idx), options)\n if (diff.isChanged) {\n return undefined\n }\n\n items.push({\n fromIndex: idx,\n toIndex: idx,\n hasMoved: false,\n diff,\n annotation: toInput.annotationAt(idx),\n })\n }\n\n return items\n}\n\nfunction diffArrayByReinsert<A>(\n fromInput: ArrayInput<A>,\n toInput: ArrayInput<A>,\n options: DiffOptions,\n): ArrayDiff<A> {\n const items: ItemDiff<A>[] = []\n\n for (let idx = 0; idx < toInput.length; idx++) {\n const input = toInput.at(idx)\n\n items.push({\n fromIndex: undefined,\n toIndex: idx,\n hasMoved: false,\n diff: addedInput(input, undefined, options),\n annotation: input.annotation,\n })\n }\n\n for (let idx = 0; idx < fromInput.length; idx++) {\n const input = fromInput.at(idx)\n\n items.push({\n fromIndex: idx,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(input, undefined, options),\n annotation: input.annotation,\n })\n }\n\n return buildArrayDiff(fromInput, toInput, items, true)\n}\n\ntype Key = string | number | boolean\n\n/**\n * Diff an array when all the elements have _key in the same position.\n */\nfunction diffArrayByKey<A>(\n fromArray: ArrayInput<A>,\n fromKeyIndex: KeyIndex,\n toArray: ArrayInput<A>,\n toKeyIndex: KeyIndex,\n options: DiffOptions,\n): ArrayDiff<A> {\n const items: ItemDiff<A>[] = []\n let isChanged = false\n\n function diffCommon(key: Key, fromIndex: number, toIndex: number, hasMoved: boolean) {\n deletePositionInIndex(fromKeyIndex.index, key, fromIndex)\n deletePositionInIndex(toKeyIndex.index, key, toIndex)\n\n const fromInput = fromArray.at(fromIndex)\n const toInput = toArray.at(toIndex)\n\n const diff = diffInput(fromInput, toInput, options)\n items.push({\n fromIndex,\n toIndex,\n hasMoved,\n diff,\n annotation: toArray.annotationAt(toIndex),\n })\n\n if (diff.isChanged || fromIndex !== toIndex) {\n isChanged = true\n }\n }\n\n const lcs = getLongestCommonSubsequence(fromKeyIndex.keys, toKeyIndex.keys)\n\n for (let fromIndex = 0; fromIndex < fromKeyIndex.keys.length; fromIndex++) {\n const key = fromKeyIndex.keys[fromIndex]\n\n const subsequenceIdx = lcs.prevIndices.indexOf(fromIndex)\n if (subsequenceIdx !== -1) {\n // Part of the common subsequence => hasMoved:false\n diffCommon(key, fromIndex, lcs.nextIndices[subsequenceIdx], false)\n continue\n }\n\n // Not a part of the subsequence. Try to find another item which has the same key\n // and also is not part of the common subsequence.\n const toIndexes = toKeyIndex.index.get(key)\n const toIndex = toIndexes && toIndexes.find((idx) => !lcs.nextIndices.includes(idx))\n if (toIndex !== undefined) {\n diffCommon(key, fromIndex, toIndex, true)\n continue\n }\n\n const input = fromArray.at(fromIndex)\n\n items.push({\n fromIndex,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(input, undefined, options),\n annotation: fromArray.annotationAt(fromIndex),\n })\n\n isChanged = true\n }\n\n // The remaining data in toKeyIndex are the new elements which has been added\n for (const positions of toKeyIndex.index.values()) {\n for (const toIndex of positions) {\n const input = toArray.at(toIndex)\n items.push({\n fromIndex: undefined,\n toIndex,\n hasMoved: false,\n diff: addedInput(input, undefined, options),\n annotation: toArray.annotationAt(toIndex),\n })\n }\n\n isChanged = true\n }\n\n items.sort(compareItemDiff)\n\n return buildArrayDiff(fromArray, toArray, items, isChanged)\n}\n\nfunction compareItemDiff<A>(a: ItemDiff<A>, b: ItemDiff<A>): number {\n if (a.toIndex !== undefined && b.toIndex !== undefined) {\n return a.toIndex - b.toIndex\n }\n\n if (a.fromIndex !== undefined && b.fromIndex !== undefined) {\n return a.fromIndex - b.fromIndex\n }\n\n if (a.fromIndex !== undefined && b.toIndex !== undefined) {\n // A was removed and B was added. Prefer to sort removals last.\n return -1\n }\n\n if (a.toIndex !== undefined && b.fromIndex !== undefined) {\n // A was added and B was removed. Prefer to sort removals last.\n return 1\n }\n\n throw new Error('invalid item diff comparison')\n}\n\nfunction deletePositionInIndex(index: Map<Key, number[]>, key: Key, pos: number) {\n const positions = index.get(key)!\n deleteArrayValue(positions, pos)\n if (positions.length === 0) {\n index.delete(key)\n }\n}\n\nfunction deleteArrayValue<E>(arr: E[], value: E) {\n const idx = arr.indexOf(value)\n if (idx === -1) throw new Error('value not found')\n arr.splice(idx, 1)\n}\n\ntype KeyIndex = {\n keys: Key[]\n index: Map<Key, number[]>\n}\n\n/**\n * Indexes the array by a key. This handles cases where the items are:\n *\n * - Objects with _key\n * - Strings\n * - Numbers\n */\nfunction indexByKey<A>(arr: ArrayInput<A>): KeyIndex | undefined {\n const index = new Map<Key, number[]>()\n const keys: Key[] = []\n const length = arr.length\n\n for (let i = 0; i < length; i++) {\n const item = arr.at(i)\n\n let key: Key | null = null\n\n switch (item.type) {\n case 'string':\n key = `s${item.value}`\n break\n case 'number':\n key = item.value\n break\n case 'boolean':\n key = item.value\n break\n case 'null':\n key = 'n'\n break\n case 'object':\n {\n const keyField = item.get('_key')\n if (keyField && keyField.type === 'string') {\n key = `k${keyField.value}`\n\n // We do not handle duplicate _key\n if (index.has(key)) return undefined\n }\n }\n break\n default:\n }\n\n // No key => abort\n if (key === null) return undefined\n\n keys.push(key)\n let positions = index.get(key)\n if (!positions) {\n positions = []\n index.set(key, positions)\n }\n positions.push(i)\n }\n\n // All is good.\n return {keys, index}\n}\n\nfunction removedArray<A>(\n input: ArrayInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): ArrayDiff<A> & {action: 'removed'} {\n return {\n type: 'array',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get items(): ArrayDiff<A>['items'] {\n const items: ArrayDiff<A>['items'] = []\n for (let i = 0; i < input.length; i++) {\n const item = input.at(i)\n items.push({\n fromIndex: i,\n toIndex: undefined,\n hasMoved: false,\n diff: removedInput(item, undefined, options),\n annotation: input.annotationAt(i),\n })\n }\n\n return replaceProperty(this, 'items', items)\n },\n }\n}\n\nfunction addedArray<A>(\n input: ArrayInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): ArrayDiff<A> & {action: 'added'} {\n return {\n type: 'array',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get items(): ArrayDiff<A>['items'] {\n const items: ArrayDiff<A>['items'] = []\n for (let i = 0; i < input.length; i++) {\n const item = input.at(i)\n items.push({\n fromIndex: undefined,\n toIndex: i,\n hasMoved: false,\n diff: addedInput(item, undefined, options),\n annotation: input.annotationAt(i),\n })\n }\n\n return replaceProperty(this, 'items', items)\n },\n }\n}\n\nconst ignoredFields = new Set(['_id', '_type', '_createdAt', '_updatedAt', '_rev', '_weak'])\n\nfunction diffObject<A>(\n fromInput: ObjectInput<A>,\n toInput: ObjectInput<A>,\n options: DiffOptions,\n): ObjectDiff<A> {\n const fields: ObjectDiff<A>['fields'] = {}\n let isChanged = false\n\n for (const key of fromInput.keys) {\n if (ignoredFields.has(key)) continue\n\n const fromField = fromInput.get(key)!\n\n const toField = toInput.get(key)\n if (toField) {\n const fieldDiff = diffInput(fromField, toField, options)\n fields[key] = fieldDiff\n if (fieldDiff.isChanged) isChanged = true\n } else {\n fields[key] = removedInput(fromField, undefined, options)\n isChanged = true\n }\n }\n\n for (const key of toInput.keys) {\n if (ignoredFields.has(key)) continue\n\n // Already handled above\n if (fromInput.get(key)) continue\n\n const toField = toInput.get(key)!\n fields[key] = addedInput(toField, undefined, options)\n isChanged = true\n }\n\n const fromValue = fromInput.value\n const toValue = toInput.value\n\n if (!isChanged) {\n return {\n type: 'object',\n action: 'unchanged',\n isChanged: false,\n fromValue,\n toValue,\n fields,\n }\n }\n\n return {\n type: 'object',\n action: 'changed',\n isChanged: true,\n fromValue,\n toValue,\n fields,\n annotation: toInput.annotation,\n }\n}\n\nfunction removedObject<A>(\n input: ObjectInput<A>,\n toValue: null | undefined,\n options: DiffOptions,\n): ObjectDiff<A> & {action: 'removed'} {\n return {\n type: 'object',\n action: 'removed',\n isChanged: true,\n fromValue: input.value,\n toValue,\n annotation: input.annotation,\n\n get fields(): ObjectDiff<A>['fields'] {\n const fields: ObjectDiff<A>['fields'] = {}\n for (const key of input.keys) {\n const value = input.get(key)!\n fields[key] = removedInput(value, undefined, options)\n }\n return replaceProperty(this, 'fields', fields)\n },\n }\n}\n\nfunction addedObject<A>(\n input: ObjectInput<A>,\n fromValue: null | undefined,\n options: DiffOptions,\n): ObjectDiff<A> & {action: 'added'} {\n return {\n type: 'object',\n action: 'added',\n isChanged: true,\n fromValue,\n toValue: input.value,\n annotation: input.annotation,\n\n get fields(): ObjectDiff<A>['fields'] {\n const fields: ObjectDiff<A>['fields'] = {}\n for (const key of input.keys) {\n const value = input.get(key)!\n fields[key] = addedInput(value, undefined, options)\n }\n return replaceProperty(this, 'fields', fields)\n },\n }\n}\n","import {type ArrayInput, type Input, type ObjectInput, type StringInput} from './types'\n\n// The wrapper classes and `wrap` are mutually recursive (container wrappers lazily wrap their\n// members), so they live in the same module to avoid circular imports.\n\ntype SimpleType = 'boolean' | 'number' | 'null'\n\nclass BasicWrapper<K extends SimpleType, V, A> {\n type: K\n value: V\n annotation: A\n\n constructor(type: K, value: V, annotation: A) {\n this.type = type\n this.value = value\n this.annotation = annotation\n }\n}\n\nclass StringWrapper<A> implements StringInput<A> {\n type = 'string' as const\n value: string\n annotation: A\n\n constructor(value: string, annotation: A) {\n this.value = value\n this.annotation = annotation\n }\n\n sliceAnnotation(start: number, end: number): {text: string; annotation: A}[] {\n return [{text: this.value.slice(start, end), annotation: this.annotation}]\n }\n}\n\nclass ArrayWrapper<A> implements ArrayInput<A> {\n type = 'array' as const\n length: number\n value: unknown[]\n annotation: A\n\n private elements: Input<A>[] = []\n\n constructor(value: unknown[], annotation: A) {\n this.annotation = annotation\n this.value = value\n this.length = value.length\n }\n\n at(idx: number): Input<A> {\n if (idx >= this.length) throw new Error('out of bounds')\n const input = this.elements[idx]\n if (input) {\n return input\n }\n\n return (this.elements[idx] = wrap(this.value[idx], this.annotation))\n }\n\n annotationAt(): A {\n return this.annotation\n }\n}\n\nclass ObjectWrapper<A> implements ObjectInput<A> {\n type = 'object' as const\n value: Record<string, unknown>\n keys: string[]\n annotation: A\n\n private fields: Record<string, Input<A>> = {}\n\n constructor(value: Record<string, unknown>, annotation: A) {\n this.value = filterUndefinedEntries(value)\n this.annotation = annotation\n this.keys = Object.keys(this.value)\n }\n\n get(key: string): Input<A> | undefined {\n const input = this.fields[key]\n if (input) {\n return input\n }\n\n if (!this.value.hasOwnProperty(key)) {\n return undefined\n }\n\n const raw = this.value[key]\n return (this.fields[key] = wrap(raw, this.annotation))\n }\n}\n\nfunction filterUndefinedEntries(value: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(value).filter(([, entryValue]) => typeof entryValue !== 'undefined'),\n )\n}\n\n/**\n * Takes an input (any JSON-serializable value) and an annotation, and generates an input\n * object for it, to be used with {@link diffInput | the diffInput() method} and others.\n *\n * @param input - The value to wrap in an input object\n * @param annotation - Annotation attached to the input - will be bound to generated diffs\n * @returns A input object\n * @throws if `input` is not a JSON-serializable type\n * @public\n */\nexport function wrap<A>(input: unknown, annotation: A): Input<A> {\n if (Array.isArray(input)) {\n return new ArrayWrapper(input, annotation)\n } else if (input === null) {\n return new BasicWrapper('null', input, annotation)\n }\n\n const type = typeof input\n switch (type) {\n case 'number':\n return new BasicWrapper(type, input as number, annotation)\n case 'boolean':\n return new BasicWrapper(type, input as boolean, annotation)\n case 'object':\n return new ObjectWrapper(input as Record<string, unknown>, annotation)\n case 'string':\n return new StringWrapper(input as string, annotation)\n default:\n throw new Error(`cannot wrap value of type: ${type}`)\n }\n}\n"],"mappings":";AAAA,SAAgB,gBACd,QACA,MACA,OACG;CAGH,OAFA,OAAO,OAAO,OACd,OAAO,QAAQ,OACR;AACT;ACAA,SAAgB,WACd,WACA,SACA,SACe;CACf,IAAM,YAAY,UAAU,OACtB,UAAU,QAAQ,OAClB,OAAO,UAAU;CAWvB,OATI,cAAc,UACT;EACL;EACA,QAAQ;EACR;EACA;EACA,WAAW;CACb,IAEK;EACL,MAAM,UAAU;EAChB,QAAQ;EACR,WAAW;EACA;EACF;EACT,YAAY,QAAQ;CACtB;AACF;AAEA,SAAgB,YACd,WACA,SACA,SACgB;CAChB,IAAM,YAAY,UAAU,OACtB,UAAU,QAAQ,OAClB,OAAO,UAAU;CAWvB,OATI,cAAc,UACT;EACL;EACA,QAAQ;EACR;EACA;EACA,WAAW;CACb,IAEK;EACL,MAAM,UAAU;EAChB,QAAQ;EACR,WAAW;EACA;EACF;EACT,YAAY,QAAQ;CACtB;AACF;ACnDA,SAAgB,WACd,WACA,SACA,SACe;CACf,IAAM,YAAY,UAAU,OACtB,UAAU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5D,KAAK,UACH,OAAO,IAAI,cAAc,OAAkC,UAAU;EACvE,KAAK,UACH,OAAO,IAAI,cAAc,OAAiB,UAAU;EACtD,SACE,MAAU,MAAM,8BAA8B,MAAM;CACxD;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/diff",
3
- "version": "6.9.2-next.9",
3
+ "version": "6.9.3-next.1",
4
4
  "description": "Generates diffs between documents and primitive types",
5
5
  "keywords": [
6
6
  "cms",
@@ -37,8 +37,8 @@
37
37
  "devDependencies": {
38
38
  "tsdown": "^0.22.14",
39
39
  "typescript": "^7.0.2",
40
- "@repo/tsconfig": "6.9.2-next.9+be979bb350",
41
- "@repo/tsdown.config": "6.9.2-next.9+be979bb350"
40
+ "@repo/tsconfig": "6.9.3-next.1+2356a5b92a",
41
+ "@repo/tsdown.config": "6.9.3-next.1+2356a5b92a"
42
42
  },
43
43
  "browserslist": [
44
44
  "node >=22.12",