@sanity/diff 5.8.1-next.13 → 5.8.1-next.2

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