@sanity/diff 5.8.1-next.8 → 5.8.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.d.ts +185 -250
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,31 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Options available for doing diffs. Currently no options are defined.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
type DiffOptions = Record<string, never>;
|
|
7
|
+
/**
|
|
8
|
+
* The recognized diff value types
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
type ValueType = 'array' | 'boolean' | 'null' | 'number' | 'object' | 'string' | 'undefined';
|
|
13
|
+
/**
|
|
14
|
+
* An "input" holds the _type_ of the value, the actual value, an optional annotation,
|
|
15
|
+
* along with potential helper methods and properties, which vary dependending on the type
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
type Input<T> = NumberInput<T> | BooleanInput<T> | StringInput<T> | NullInput<T> | ObjectInput<T> | ArrayInput<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Shared properties for all input types
|
|
4
22
|
*
|
|
5
23
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
6
|
-
* @typeParam V - Value. The type of the destination (eg `after` or `to`) value.
|
|
7
24
|
* @public
|
|
8
25
|
*/
|
|
9
|
-
|
|
10
|
-
action: "added";
|
|
11
|
-
isChanged: true;
|
|
12
|
-
fromValue: null | undefined;
|
|
13
|
-
toValue: V;
|
|
26
|
+
interface BaseInput<A> {
|
|
14
27
|
annotation: A;
|
|
15
28
|
}
|
|
16
|
-
|
|
17
29
|
/**
|
|
18
|
-
*
|
|
30
|
+
* Input type for strings, which supports slicing parts of the string while maintaining the
|
|
31
|
+
* annotation of the parent.
|
|
19
32
|
*
|
|
20
33
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
21
|
-
* @typeParam V - Item value type.
|
|
22
34
|
* @public
|
|
23
35
|
*/
|
|
24
|
-
|
|
25
|
-
type:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
interface StringInput<A> extends BaseInput<A> {
|
|
37
|
+
type: 'string';
|
|
38
|
+
value: string;
|
|
39
|
+
sliceAnnotation(start: number, end: number): {
|
|
40
|
+
text: string;
|
|
41
|
+
annotation: A;
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Input type for numbers.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
interface NumberInput<A> extends BaseInput<A> {
|
|
51
|
+
type: 'number';
|
|
52
|
+
value: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Input type for booleans.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
interface BooleanInput<A> extends BaseInput<A> {
|
|
61
|
+
type: 'boolean';
|
|
62
|
+
value: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Input type for `null` values.
|
|
66
|
+
*
|
|
67
|
+
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
interface NullInput<A> extends BaseInput<A> {
|
|
71
|
+
type: 'null';
|
|
72
|
+
value: null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Input type for object values. Caches the available keys, and allows retrieval of properties,
|
|
76
|
+
* while automatically wrapping the retrieved property in a typed input container.
|
|
77
|
+
*
|
|
78
|
+
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface ObjectInput<A> extends BaseInput<A> {
|
|
82
|
+
type: 'object';
|
|
83
|
+
/**
|
|
84
|
+
* The actual object value
|
|
85
|
+
*/
|
|
86
|
+
value: Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* The keys of the object
|
|
89
|
+
*/
|
|
90
|
+
keys: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Retrieve the property with the given `key`, automatically wrapping it in an input container.
|
|
93
|
+
*
|
|
94
|
+
* @param key - The key of the property you want to retrieve.
|
|
95
|
+
* @returns Typed input container, or `undefined` if the property does not exist
|
|
96
|
+
*/
|
|
97
|
+
get(key: string): Input<A> | undefined;
|
|
98
|
+
}
|
|
29
99
|
/**
|
|
30
100
|
* Input type for array values. Helper functions are available for getting the item and/or
|
|
31
101
|
* annotation at a given index.
|
|
@@ -33,8 +103,8 @@ export declare type ArrayDiff<A, V = unknown> = FullDiff<A, V[]> & {
|
|
|
33
103
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
34
104
|
* @public
|
|
35
105
|
*/
|
|
36
|
-
|
|
37
|
-
type:
|
|
106
|
+
interface ArrayInput<A> extends BaseInput<A> {
|
|
107
|
+
type: 'array';
|
|
38
108
|
/**
|
|
39
109
|
* The actual array value
|
|
40
110
|
*/
|
|
@@ -58,38 +128,36 @@ export declare interface ArrayInput<A> extends BaseInput<A> {
|
|
|
58
128
|
*/
|
|
59
129
|
annotationAt(index: number): A;
|
|
60
130
|
}
|
|
61
|
-
|
|
62
131
|
/**
|
|
63
|
-
*
|
|
132
|
+
* Diff for something that has been added - eg a property in an object,
|
|
133
|
+
* an item in an array, a segment of a string or similar.
|
|
64
134
|
*
|
|
65
135
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
136
|
+
* @typeParam V - Value. The type of the destination (eg `after` or `to`) value.
|
|
66
137
|
* @public
|
|
67
138
|
*/
|
|
68
|
-
|
|
139
|
+
interface AddedDiff<A, V> {
|
|
140
|
+
action: 'added';
|
|
141
|
+
isChanged: true;
|
|
142
|
+
fromValue: null | undefined;
|
|
143
|
+
toValue: V;
|
|
69
144
|
annotation: A;
|
|
70
145
|
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Diff of a boolean.
|
|
74
|
-
*
|
|
75
|
-
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
export declare type BooleanDiff<A> = FullDiff<A, boolean> & {
|
|
79
|
-
type: "boolean";
|
|
80
|
-
};
|
|
81
|
-
|
|
82
146
|
/**
|
|
83
|
-
*
|
|
147
|
+
* Diff for something that has been removed - eg a property in an object,
|
|
148
|
+
* an item in an array, a segment of a string or similar.
|
|
84
149
|
*
|
|
85
150
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
151
|
+
* @typeParam V - Value. The type of the source (eg `before` or `from`) value.
|
|
86
152
|
* @public
|
|
87
153
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
154
|
+
interface RemovedDiff<A, V> {
|
|
155
|
+
action: 'removed';
|
|
156
|
+
isChanged: true;
|
|
157
|
+
fromValue: V;
|
|
158
|
+
toValue: null | undefined;
|
|
159
|
+
annotation: A;
|
|
91
160
|
}
|
|
92
|
-
|
|
93
161
|
/**
|
|
94
162
|
* Diff for something that has changed - eg it was not added or removed, but the
|
|
95
163
|
* value has changed "in place". Note that {@link TypeChangeDiff} is used for values that change
|
|
@@ -100,51 +168,26 @@ export declare interface BooleanInput<A> extends BaseInput<A> {
|
|
|
100
168
|
* @typeParam V - Value. The type of the value.
|
|
101
169
|
* @public
|
|
102
170
|
*/
|
|
103
|
-
|
|
104
|
-
action:
|
|
171
|
+
interface ChangedDiff<A, V> {
|
|
172
|
+
action: 'changed';
|
|
105
173
|
isChanged: true;
|
|
106
174
|
fromValue: V;
|
|
107
175
|
toValue: V;
|
|
108
176
|
annotation: A;
|
|
109
177
|
}
|
|
110
|
-
|
|
111
178
|
/**
|
|
112
|
-
* Diff for
|
|
179
|
+
* Diff (or lack thereof, in this case) for a value that has _not_ changed.
|
|
113
180
|
*
|
|
114
181
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
182
|
+
* @typeParam V - Value. The type of the destination (eg `after`) value.
|
|
115
183
|
* @public
|
|
116
184
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
| ArrayDiff<A>
|
|
124
|
-
| TypeChangeDiff<A>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Takes a `from` and `to` input and calulates a diff between the two
|
|
128
|
-
*
|
|
129
|
-
* @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an "input"
|
|
130
|
-
* @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an "input"
|
|
131
|
-
* @param options - Options for the diffing process - currently no options are defined
|
|
132
|
-
* @returns A diff object representing the change
|
|
133
|
-
* @public
|
|
134
|
-
*/
|
|
135
|
-
export declare function diffInput<A>(
|
|
136
|
-
fromInput: Input<A>,
|
|
137
|
-
toInput: Input<A>,
|
|
138
|
-
options?: DiffOptions,
|
|
139
|
-
): Diff<A>;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Options available for doing diffs. Currently no options are defined.
|
|
143
|
-
*
|
|
144
|
-
* @public
|
|
145
|
-
*/
|
|
146
|
-
export declare type DiffOptions = Record<string, never>;
|
|
147
|
-
|
|
185
|
+
interface UnchangedDiff<A, V> {
|
|
186
|
+
action: 'unchanged';
|
|
187
|
+
isChanged: false;
|
|
188
|
+
fromValue: V;
|
|
189
|
+
toValue: V;
|
|
190
|
+
}
|
|
148
191
|
/**
|
|
149
192
|
* Diff with all the possible diff types.
|
|
150
193
|
*
|
|
@@ -152,87 +195,59 @@ export declare type DiffOptions = Record<string, never>;
|
|
|
152
195
|
* @typeParam V - Value. Type of the value repesented in the diff.
|
|
153
196
|
* @public
|
|
154
197
|
*/
|
|
155
|
-
|
|
156
|
-
| AddedDiff<A, V>
|
|
157
|
-
| RemovedDiff<A, V>
|
|
158
|
-
| ChangedDiff<A, V>
|
|
159
|
-
| UnchangedDiff<A, V>;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* An "input" holds the _type_ of the value, the actual value, an optional annotation,
|
|
163
|
-
* along with potential helper methods and properties, which vary dependending on the type
|
|
164
|
-
*
|
|
165
|
-
* @public
|
|
166
|
-
*/
|
|
167
|
-
export declare type Input<T> =
|
|
168
|
-
| NumberInput<T>
|
|
169
|
-
| BooleanInput<T>
|
|
170
|
-
| StringInput<T>
|
|
171
|
-
| NullInput<T>
|
|
172
|
-
| ObjectInput<T>
|
|
173
|
-
| ArrayInput<T>;
|
|
174
|
-
|
|
198
|
+
type FullDiff<A, V> = AddedDiff<A, V> | RemovedDiff<A, V> | ChangedDiff<A, V> | UnchangedDiff<A, V>;
|
|
175
199
|
/**
|
|
176
|
-
* Diff of
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* If not moved, `fromIndex` and `toIndex` will have the same value.
|
|
180
|
-
* If the item was added, `fromIndex` will be `undefined`.
|
|
181
|
-
* If the item was removed, `toIndex` will be `undefined`.
|
|
182
|
-
*
|
|
183
|
-
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
184
|
-
* @public
|
|
185
|
-
*/
|
|
186
|
-
export declare interface ItemDiff<A> {
|
|
187
|
-
fromIndex: number | undefined;
|
|
188
|
-
toIndex: number | undefined;
|
|
189
|
-
hasMoved: boolean;
|
|
190
|
-
diff: Diff<A>;
|
|
191
|
-
annotation: A;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Diff for a `null` value.
|
|
200
|
+
* Diff of a string. Holds an additional array of string _segments_,
|
|
201
|
+
* indicating which portions of the string is changed/unchanged.
|
|
196
202
|
*
|
|
197
203
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
198
204
|
* @public
|
|
199
205
|
*/
|
|
200
|
-
|
|
201
|
-
type:
|
|
206
|
+
type StringDiff<A> = FullDiff<A, string> & {
|
|
207
|
+
type: 'string';
|
|
208
|
+
segments: StringDiffSegment<A>[];
|
|
202
209
|
};
|
|
203
|
-
|
|
204
210
|
/**
|
|
205
|
-
*
|
|
211
|
+
* Diff of a number.
|
|
206
212
|
*
|
|
207
213
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
208
214
|
* @public
|
|
209
215
|
*/
|
|
210
|
-
|
|
211
|
-
type:
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
216
|
+
type NumberDiff<A> = FullDiff<A, number> & {
|
|
217
|
+
type: 'number';
|
|
218
|
+
};
|
|
215
219
|
/**
|
|
216
|
-
* Diff of a
|
|
220
|
+
* Diff of a boolean.
|
|
217
221
|
*
|
|
218
222
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
219
223
|
* @public
|
|
220
224
|
*/
|
|
221
|
-
|
|
222
|
-
type:
|
|
225
|
+
type BooleanDiff<A> = FullDiff<A, boolean> & {
|
|
226
|
+
type: 'boolean';
|
|
223
227
|
};
|
|
224
|
-
|
|
225
228
|
/**
|
|
226
|
-
*
|
|
229
|
+
* Diff for a value that has changed from one type to another.
|
|
230
|
+
* For example, an object property going from `null` to `string`.
|
|
227
231
|
*
|
|
228
232
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
229
233
|
* @public
|
|
230
234
|
*/
|
|
231
|
-
|
|
232
|
-
type:
|
|
233
|
-
|
|
235
|
+
interface TypeChangeDiff<A> {
|
|
236
|
+
type: 'typeChange';
|
|
237
|
+
action: 'changed';
|
|
238
|
+
isChanged: true;
|
|
239
|
+
fromType: string;
|
|
240
|
+
fromValue: unknown;
|
|
241
|
+
fromDiff: Diff<A> & {
|
|
242
|
+
action: 'removed';
|
|
243
|
+
};
|
|
244
|
+
toType: string;
|
|
245
|
+
toValue: unknown;
|
|
246
|
+
toDiff: Diff<A> & {
|
|
247
|
+
action: 'added';
|
|
248
|
+
};
|
|
249
|
+
annotation: A;
|
|
234
250
|
}
|
|
235
|
-
|
|
236
251
|
/**
|
|
237
252
|
* Diff for an object value.
|
|
238
253
|
*
|
|
@@ -240,173 +255,94 @@ export declare interface NumberInput<A> extends BaseInput<A> {
|
|
|
240
255
|
* @typeParam T - Value type.
|
|
241
256
|
* @public
|
|
242
257
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
T extends object = Record<string, any>,
|
|
246
|
-
> = FullDiff<A, T> & {
|
|
247
|
-
type: "object";
|
|
258
|
+
type ObjectDiff<A, T extends object = Record<string, any>> = FullDiff<A, T> & {
|
|
259
|
+
type: 'object';
|
|
248
260
|
fields: Record<keyof T, Diff<A>>;
|
|
249
261
|
};
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Input type for object values. Caches the available keys, and allows retrieval of properties,
|
|
253
|
-
* while automatically wrapping the retrieved property in a typed input container.
|
|
254
|
-
*
|
|
255
|
-
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
256
|
-
* @public
|
|
257
|
-
*/
|
|
258
|
-
export declare interface ObjectInput<A> extends BaseInput<A> {
|
|
259
|
-
type: "object";
|
|
260
|
-
/**
|
|
261
|
-
* The actual object value
|
|
262
|
-
*/
|
|
263
|
-
value: Record<string, unknown>;
|
|
264
|
-
/**
|
|
265
|
-
* The keys of the object
|
|
266
|
-
*/
|
|
267
|
-
keys: string[];
|
|
268
|
-
/**
|
|
269
|
-
* Retrieve the property with the given `key`, automatically wrapping it in an input container.
|
|
270
|
-
*
|
|
271
|
-
* @param key - The key of the property you want to retrieve.
|
|
272
|
-
* @returns Typed input container, or `undefined` if the property does not exist
|
|
273
|
-
*/
|
|
274
|
-
get(key: string): Input<A> | undefined;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
262
|
/**
|
|
278
|
-
* Diff for
|
|
279
|
-
* an item in an array, a segment of a string or similar.
|
|
263
|
+
* Diff for an array value.
|
|
280
264
|
*
|
|
281
265
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
282
|
-
* @typeParam V -
|
|
266
|
+
* @typeParam V - Item value type.
|
|
283
267
|
* @public
|
|
284
268
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
toValue: null | undefined;
|
|
290
|
-
annotation: A;
|
|
291
|
-
}
|
|
292
|
-
|
|
269
|
+
type ArrayDiff<A, V = unknown> = FullDiff<A, V[]> & {
|
|
270
|
+
type: 'array';
|
|
271
|
+
items: ItemDiff<A>[];
|
|
272
|
+
};
|
|
293
273
|
/**
|
|
294
|
-
* Diff
|
|
295
|
-
* indicating which portions of the string is changed/unchanged.
|
|
274
|
+
* Diff for a `null` value.
|
|
296
275
|
*
|
|
297
276
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
298
277
|
* @public
|
|
299
278
|
*/
|
|
300
|
-
|
|
301
|
-
type:
|
|
302
|
-
segments: StringDiffSegment<A>[];
|
|
279
|
+
type NullDiff<A> = FullDiff<A, null> & {
|
|
280
|
+
type: 'null';
|
|
303
281
|
};
|
|
304
|
-
|
|
305
282
|
/**
|
|
306
|
-
* Diff
|
|
283
|
+
* Diff for any value type.
|
|
307
284
|
*
|
|
308
285
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
309
286
|
* @public
|
|
310
287
|
*/
|
|
311
|
-
|
|
312
|
-
| StringSegmentChanged<A>
|
|
313
|
-
| StringSegmentUnchanged;
|
|
314
|
-
|
|
288
|
+
type Diff<A> = NullDiff<A> | StringDiff<A> | NumberDiff<A> | BooleanDiff<A> | ObjectDiff<A> | ArrayDiff<A> | TypeChangeDiff<A>;
|
|
315
289
|
/**
|
|
316
|
-
*
|
|
317
|
-
* annotation of the parent.
|
|
290
|
+
* Diff of a string segment (eg a portion/slice), and whether or not it was changed or unchanged.
|
|
318
291
|
*
|
|
319
292
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
320
293
|
* @public
|
|
321
294
|
*/
|
|
322
|
-
|
|
323
|
-
type: "string";
|
|
324
|
-
value: string;
|
|
325
|
-
sliceAnnotation(
|
|
326
|
-
start: number,
|
|
327
|
-
end: number,
|
|
328
|
-
): {
|
|
329
|
-
text: string;
|
|
330
|
-
annotation: A;
|
|
331
|
-
}[];
|
|
332
|
-
}
|
|
333
|
-
|
|
295
|
+
type StringDiffSegment<A> = StringSegmentChanged<A> | StringSegmentUnchanged;
|
|
334
296
|
/**
|
|
335
297
|
* Diff of a string segment that has changed.
|
|
336
298
|
*
|
|
337
299
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
338
300
|
* @public
|
|
339
301
|
*/
|
|
340
|
-
|
|
341
|
-
type:
|
|
342
|
-
action:
|
|
302
|
+
interface StringSegmentChanged<A> {
|
|
303
|
+
type: 'stringSegment';
|
|
304
|
+
action: 'added' | 'removed';
|
|
343
305
|
text: string;
|
|
344
306
|
annotation: A;
|
|
345
307
|
}
|
|
346
|
-
|
|
347
308
|
/**
|
|
348
309
|
* Diff of a string segment that is unchanged.
|
|
349
310
|
*
|
|
350
311
|
* @public
|
|
351
312
|
*/
|
|
352
|
-
|
|
353
|
-
type:
|
|
354
|
-
action:
|
|
313
|
+
interface StringSegmentUnchanged {
|
|
314
|
+
type: 'stringSegment';
|
|
315
|
+
action: 'unchanged';
|
|
355
316
|
text: string;
|
|
356
317
|
}
|
|
357
|
-
|
|
358
318
|
/**
|
|
359
|
-
* Diff
|
|
360
|
-
*
|
|
319
|
+
* Diff of an item in an array, representing whether or not it has moved within the array,
|
|
320
|
+
* and if so, which index it was moved from/to.
|
|
361
321
|
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
|
|
365
|
-
export declare interface TypeChangeDiff<A> {
|
|
366
|
-
type: "typeChange";
|
|
367
|
-
action: "changed";
|
|
368
|
-
isChanged: true;
|
|
369
|
-
fromType: string;
|
|
370
|
-
fromValue: unknown;
|
|
371
|
-
fromDiff: Diff<A> & {
|
|
372
|
-
action: "removed";
|
|
373
|
-
};
|
|
374
|
-
toType: string;
|
|
375
|
-
toValue: unknown;
|
|
376
|
-
toDiff: Diff<A> & {
|
|
377
|
-
action: "added";
|
|
378
|
-
};
|
|
379
|
-
annotation: A;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Diff (or lack thereof, in this case) for a value that has _not_ changed.
|
|
322
|
+
* If not moved, `fromIndex` and `toIndex` will have the same value.
|
|
323
|
+
* If the item was added, `fromIndex` will be `undefined`.
|
|
324
|
+
* If the item was removed, `toIndex` will be `undefined`.
|
|
384
325
|
*
|
|
385
326
|
* @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
|
|
386
|
-
* @typeParam V - Value. The type of the destination (eg `after`) value.
|
|
387
327
|
* @public
|
|
388
328
|
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
329
|
+
interface ItemDiff<A> {
|
|
330
|
+
fromIndex: number | undefined;
|
|
331
|
+
toIndex: number | undefined;
|
|
332
|
+
hasMoved: boolean;
|
|
333
|
+
diff: Diff<A>;
|
|
334
|
+
annotation: A;
|
|
394
335
|
}
|
|
395
|
-
|
|
396
336
|
/**
|
|
397
|
-
*
|
|
337
|
+
* Takes a `from` and `to` input and calulates a diff between the two
|
|
398
338
|
*
|
|
339
|
+
* @param fromInput - The source (`from`) input - use {@link wrap | the wrap() method} to generate an "input"
|
|
340
|
+
* @param toInput - The destination (`to`) input - use {@link wrap | the wrap() method} to generate an "input"
|
|
341
|
+
* @param options - Options for the diffing process - currently no options are defined
|
|
342
|
+
* @returns A diff object representing the change
|
|
399
343
|
* @public
|
|
400
344
|
*/
|
|
401
|
-
|
|
402
|
-
| "array"
|
|
403
|
-
| "boolean"
|
|
404
|
-
| "null"
|
|
405
|
-
| "number"
|
|
406
|
-
| "object"
|
|
407
|
-
| "string"
|
|
408
|
-
| "undefined";
|
|
409
|
-
|
|
345
|
+
declare function diffInput<A>(fromInput: Input<A>, toInput: Input<A>, options?: DiffOptions): Diff<A>;
|
|
410
346
|
/**
|
|
411
347
|
* Takes an input (any JSON-serializable value) and an annotation, and generates an input
|
|
412
348
|
* object for it, to be used with {@link diffInput | the diffInput() method} and others.
|
|
@@ -417,6 +353,5 @@ export declare type ValueType =
|
|
|
417
353
|
* @throws if `input` is not a JSON-serializable type
|
|
418
354
|
* @public
|
|
419
355
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
export {};
|
|
356
|
+
declare function wrap<A>(input: unknown, annotation: A): Input<A>;
|
|
357
|
+
export { AddedDiff, ArrayDiff, ArrayInput, BaseInput, BooleanDiff, BooleanInput, ChangedDiff, Diff, DiffOptions, FullDiff, Input, ItemDiff, NullDiff, NullInput, NumberDiff, NumberInput, ObjectDiff, ObjectInput, RemovedDiff, StringDiff, StringDiffSegment, StringInput, StringSegmentChanged, StringSegmentUnchanged, TypeChangeDiff, UnchangedDiff, ValueType, diffInput, wrap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/diff",
|
|
3
|
-
"version": "5.8.1
|
|
3
|
+
"version": "5.8.1",
|
|
4
4
|
"description": "Generates diffs between documents and primitive types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@typescript/native-preview": "7.0.0-dev.20260112.1",
|
|
41
41
|
"eslint": "^9.39.2",
|
|
42
42
|
"rimraf": "^5.0.10",
|
|
43
|
-
"@repo/eslint-config": "5.8.1
|
|
44
|
-
"@repo/package.config": "5.8.1
|
|
45
|
-
"@repo/tsconfig": "5.8.1
|
|
43
|
+
"@repo/eslint-config": "5.8.1",
|
|
44
|
+
"@repo/package.config": "5.8.1",
|
|
45
|
+
"@repo/tsconfig": "5.8.1"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=20.19 <22 || >=22.12"
|