@sanity/diff 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.7

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.mts DELETED
@@ -1,417 +0,0 @@
1
- /**
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.
4
- *
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.
7
- * @public
8
- */
9
- export declare interface AddedDiff<A, V> {
10
- action: 'added'
11
- isChanged: true
12
- fromValue: null | undefined
13
- toValue: V
14
- annotation: A
15
- }
16
-
17
- /**
18
- * Diff for an array value.
19
- *
20
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
21
- * @typeParam V - Item value type.
22
- * @public
23
- */
24
- export declare type ArrayDiff<A, V = unknown> = FullDiff<A, V[]> & {
25
- type: 'array'
26
- items: ItemDiff<A>[]
27
- }
28
-
29
- /**
30
- * Input type for array values. Helper functions are available for getting the item and/or
31
- * annotation at a given index.
32
- *
33
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
34
- * @public
35
- */
36
- export declare interface ArrayInput<A> extends BaseInput<A> {
37
- type: 'array'
38
- /**
39
- * The actual array value
40
- */
41
- value: unknown[]
42
- /**
43
- * The length of the array
44
- */
45
- length: number
46
- /**
47
- * Retrieve the value at the given `index`, automatically wrapping it in an input container.
48
- *
49
- * @param index - The index of the item to retrieve
50
- * @returns Typed input container, or `undefined` if the item does not exist
51
- */
52
- at(index: number): Input<A>
53
- /**
54
- * Retrieve the _annotation_ for an item at the given index
55
- *
56
- * @param index - The index of the item to fetch the annotation for
57
- * @returns The annotation at the given index, or `undefined` if the item does not exist
58
- */
59
- annotationAt(index: number): A
60
- }
61
-
62
- /**
63
- * Shared properties for all input types
64
- *
65
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
66
- * @public
67
- */
68
- export declare interface BaseInput<A> {
69
- annotation: A
70
- }
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
- /**
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
91
- }
92
-
93
- /**
94
- * Diff for something that has changed - eg it was not added or removed, but the
95
- * value has changed "in place". Note that {@link TypeChangeDiff} is used for values that change
96
- * their _type_, thus the `V` type parameter represents both the source and the destination value
97
- * in this type.
98
- *
99
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
100
- * @typeParam V - Value. The type of the value.
101
- * @public
102
- */
103
- export declare interface ChangedDiff<A, V> {
104
- action: 'changed'
105
- isChanged: true
106
- fromValue: V
107
- toValue: V
108
- annotation: A
109
- }
110
-
111
- /**
112
- * Diff for any value type.
113
- *
114
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
115
- * @public
116
- */
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
-
148
- /**
149
- * Diff with all the possible diff types.
150
- *
151
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
152
- * @typeParam V - Value. Type of the value repesented in the diff.
153
- * @public
154
- */
155
- export declare type FullDiff<A, V> =
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
-
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`.
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.
196
- *
197
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
198
- * @public
199
- */
200
- export declare type NullDiff<A> = FullDiff<A, null> & {
201
- type: 'null'
202
- }
203
-
204
- /**
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.
217
- *
218
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
219
- * @public
220
- */
221
- export declare type NumberDiff<A> = FullDiff<A, number> & {
222
- type: 'number'
223
- }
224
-
225
- /**
226
- * Input type for numbers.
227
- *
228
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
229
- * @public
230
- */
231
- export declare interface NumberInput<A> extends BaseInput<A> {
232
- type: 'number'
233
- value: number
234
- }
235
-
236
- /**
237
- * Diff for an object value.
238
- *
239
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
240
- * @typeParam T - Value type.
241
- * @public
242
- */
243
- export declare type ObjectDiff<A, T extends object = Record<string, any>> = FullDiff<A, T> & {
244
- type: 'object'
245
- fields: Record<keyof T, Diff<A>>
246
- }
247
-
248
- /**
249
- * Input type for object values. Caches the available keys, and allows retrieval of properties,
250
- * while automatically wrapping the retrieved property in a typed input container.
251
- *
252
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
253
- * @public
254
- */
255
- export declare interface ObjectInput<A> extends BaseInput<A> {
256
- type: 'object'
257
- /**
258
- * The actual object value
259
- */
260
- value: Record<string, unknown>
261
- /**
262
- * The keys of the object
263
- */
264
- keys: string[]
265
- /**
266
- * Retrieve the property with the given `key`, automatically wrapping it in an input container.
267
- *
268
- * @param key - The key of the property you want to retrieve.
269
- * @returns Typed input container, or `undefined` if the property does not exist
270
- */
271
- get(key: string): Input<A> | undefined
272
- }
273
-
274
- /**
275
- * Diff for something that has been removed - eg a property in an object,
276
- * an item in an array, a segment of a string or similar.
277
- *
278
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
279
- * @typeParam V - Value. The type of the source (eg `before` or `from`) value.
280
- * @public
281
- */
282
- export declare interface RemovedDiff<A, V> {
283
- action: 'removed'
284
- isChanged: true
285
- fromValue: V
286
- toValue: null | undefined
287
- annotation: A
288
- }
289
-
290
- /**
291
- * Diff of a string. Holds an additional array of string _segments_,
292
- * indicating which portions of the string is changed/unchanged.
293
- *
294
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
295
- * @public
296
- */
297
- export declare type StringDiff<A> = FullDiff<A, string> & {
298
- type: 'string'
299
- segments: StringDiffSegment<A>[]
300
- }
301
-
302
- /**
303
- * Diff of a string segment (eg a portion/slice), and whether or not it was changed or unchanged.
304
- *
305
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
306
- * @public
307
- */
308
- export declare type StringDiffSegment<A> = StringSegmentChanged<A> | StringSegmentUnchanged
309
-
310
- /**
311
- * Input type for strings, which supports slicing parts of the string while maintaining the
312
- * annotation of the parent.
313
- *
314
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
315
- * @public
316
- */
317
- export declare interface StringInput<A> extends BaseInput<A> {
318
- type: 'string'
319
- value: string
320
- sliceAnnotation(
321
- start: number,
322
- end: number,
323
- ): {
324
- text: string
325
- annotation: A
326
- }[]
327
- }
328
-
329
- /**
330
- * Diff of a string segment that has changed.
331
- *
332
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
333
- * @public
334
- */
335
- export declare interface StringSegmentChanged<A> {
336
- type: 'stringSegment'
337
- action: 'added' | 'removed'
338
- text: string
339
- annotation: A
340
- }
341
-
342
- /**
343
- * Diff of a string segment that is unchanged.
344
- *
345
- * @public
346
- */
347
- export declare interface StringSegmentUnchanged {
348
- type: 'stringSegment'
349
- action: 'unchanged'
350
- text: string
351
- }
352
-
353
- /**
354
- * Diff for a value that has changed from one type to another.
355
- * For example, an object property going from `null` to `string`.
356
- *
357
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
358
- * @public
359
- */
360
- export declare interface TypeChangeDiff<A> {
361
- type: 'typeChange'
362
- action: 'changed'
363
- isChanged: true
364
- fromType: string
365
- fromValue: unknown
366
- fromDiff: Diff<A> & {
367
- action: 'removed'
368
- }
369
- toType: string
370
- toValue: unknown
371
- toDiff: Diff<A> & {
372
- action: 'added'
373
- }
374
- annotation: A
375
- }
376
-
377
- /**
378
- * Diff (or lack thereof, in this case) for a value that has _not_ changed.
379
- *
380
- * @typeParam A - Annotation. Timestamps, author and similar info is attached by Sanity, but anything is allowed.
381
- * @typeParam V - Value. The type of the destination (eg `after`) value.
382
- * @public
383
- */
384
- export declare interface UnchangedDiff<A, V> {
385
- action: 'unchanged'
386
- isChanged: false
387
- fromValue: V
388
- toValue: V
389
- }
390
-
391
- /**
392
- * The recognized diff value types
393
- *
394
- * @public
395
- */
396
- export declare type ValueType =
397
- | 'array'
398
- | 'boolean'
399
- | 'null'
400
- | 'number'
401
- | 'object'
402
- | 'string'
403
- | 'undefined'
404
-
405
- /**
406
- * Takes an input (any JSON-serializable value) and an annotation, and generates an input
407
- * object for it, to be used with {@link diffInput | the diffInput() method} and others.
408
- *
409
- * @param input - The value to wrap in an input object
410
- * @param annotation - Annotation attached to the input - will be bound to generated diffs
411
- * @returns A input object
412
- * @throws if `input` is not a JSON-serializable type
413
- * @public
414
- */
415
- export declare function wrap<A>(input: unknown, annotation: A): Input<A>
416
-
417
- export {}