@sanity/diff-patch 5.0.0 → 7.0.0

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/dist/index.d.cts DELETED
@@ -1,299 +0,0 @@
1
- /**
2
- * Represents an error that occurred during a diff process.
3
- * Contains `path`, `value` and `serializedPath` properties,
4
- * which is helpful for debugging and showing friendly messages.
5
- *
6
- * @public
7
- */
8
- export declare class DiffError extends Error {
9
- path: Path
10
- value: unknown
11
- serializedPath: string
12
- constructor(message: string, path: Path, value?: unknown)
13
- }
14
-
15
- /**
16
- * Diffs two items and returns an array of patches.
17
- * Note that this is different from `diffPatch`, which generates _mutations_.
18
- *
19
- * @param itemA - The first item to compare
20
- * @param itemB - The second item to compare
21
- * @param opts - Options for the diff generation
22
- * @param path - Path to the current item
23
- * @param patches - Array of patches to append the results to. Note that this is MUTATED.
24
- * @returns Array of patches
25
- * @public
26
- */
27
- export declare function diffItem(
28
- itemA: unknown,
29
- itemB: unknown,
30
- opts?: DiffOptions,
31
- path?: Path,
32
- patches?: Patch[],
33
- ): Patch[]
34
-
35
- /**
36
- * A `diffMatchPatch` operation
37
- * Applies the given `value` (unidiff format) to the given path. Must be a string.
38
- * Note: NOT a serializable mutation, see {@link SanityDiffMatchPatch} for that
39
- *
40
- * @public
41
- */
42
- export declare interface DiffMatchPatch {
43
- op: 'diffMatchPatch'
44
- path: Path
45
- value: string
46
- }
47
-
48
- /**
49
- * Options for the diff-match-patch algorithm.
50
- *
51
- * @public
52
- */
53
- export declare interface DiffMatchPatchOptions {
54
- /**
55
- * Whether or not to use diff-match-patch at all
56
- *
57
- * @defaultValue `true`
58
- */
59
- enabled: boolean
60
- /**
61
- * Threshold at which to start using diff-match-patch instead of a regular `set` patch.
62
- *
63
- * @defaultValue `30`
64
- */
65
- lengthThresholdAbsolute: number
66
- /**
67
- * Only use generated diff-match-patch if the patch length is less than or equal to
68
- * (targetString * relative). Example: A 100 character target with a relative factor
69
- * of 1.2 will allow a 120 character diff-match-patch. If larger than this number,
70
- * it will fall back to a regular `set` patch.
71
- *
72
- * @defaultValue `1.2`
73
- */
74
- lengthThresholdRelative: number
75
- }
76
-
77
- /**
78
- * Options for diff generation, where all DMP properties are required
79
- *
80
- * @public
81
- */
82
- export declare type DiffOptions = PatchOptions & {
83
- diffMatchPatch: Required<DiffMatchPatchOptions>
84
- }
85
-
86
- /**
87
- * Generates an array of mutations for Sanity, based on the differences between
88
- * the two passed documents/trees.
89
- *
90
- * @param itemA - The first document/tree to compare
91
- * @param itemB - The second document/tree to compare
92
- * @param opts - Options for the diff generation
93
- * @returns Array of mutations
94
- * @public
95
- */
96
- export declare function diffPatch(
97
- itemA: DocumentStub,
98
- itemB: DocumentStub,
99
- opts?: PatchOptions,
100
- ): SanityPatchMutation[]
101
-
102
- /**
103
- * Represents a partial Sanity document (eg a "stub").
104
- *
105
- * @public
106
- */
107
- export declare interface DocumentStub {
108
- _id?: string
109
- _type?: string
110
- _rev?: string
111
- _createdAt?: string
112
- _updatedAt?: string
113
- [key: string]: unknown
114
- }
115
-
116
- /**
117
- * A `insert` operation
118
- * Inserts the given items _after_ the given path
119
- * Note: NOT a serializable mutation, see {@link SanityInsertPatch} for that
120
- *
121
- * @public
122
- */
123
- export declare interface InsertAfterPatch {
124
- op: 'insert'
125
- after: Path
126
- items: any[]
127
- }
128
-
129
- /**
130
- * A patch containing either a Sanity set, unset, insert or diffMatchPatch operation
131
- *
132
- * @public
133
- */
134
- export declare type Patch = SetPatch | UnsetPatch | InsertAfterPatch | DiffMatchPatch
135
-
136
- /**
137
- * Options for the patch generator
138
- *
139
- * @public
140
- */
141
- export declare interface PatchOptions {
142
- /**
143
- * Document ID to apply the patch to.
144
- *
145
- * @defaultValue `undefined` - tries to extract `_id` from passed document
146
- */
147
- id?: string
148
- /**
149
- * Base path to apply the patch to - useful if diffing sub-branches of a document.
150
- *
151
- * @defaultValue `[]` - eg root of the document
152
- */
153
- basePath?: Path
154
- /**
155
- * Only apply the patch if the document revision matches this value.
156
- * If the property is the boolean value `true`, it will attempt to extract
157
- * the revision from the document `_rev` property.
158
- *
159
- * @defaultValue `undefined` (do not apply revision check)
160
- */
161
- ifRevisionID?: string | true
162
- /**
163
- * Whether or not to hide warnings during the diff process.
164
- *
165
- * @defaultValue `false`
166
- */
167
- hideWarnings?: boolean
168
- /**
169
- * Options for the diff-match-patch algorithm.
170
- */
171
- diffMatchPatch?: Partial<DiffMatchPatchOptions>
172
- }
173
-
174
- /**
175
- * An array of path segments representing a path in a document
176
- *
177
- * @public
178
- */
179
- export declare type Path = PathSegment[]
180
-
181
- /**
182
- * A segment of a path
183
- *
184
- * @public
185
- */
186
- export declare type PathSegment =
187
- | string
188
- | number
189
- | {
190
- _key: string
191
- }
192
- | [number | '', number | '']
193
-
194
- /**
195
- * A Sanity `diffMatchPatch` patch mutation operation
196
- * Patches the given path with the given unidiff string.
197
- *
198
- * @public
199
- */
200
- export declare interface SanityDiffMatchPatch {
201
- id: string
202
- diffMatchPatch: {
203
- [key: string]: string
204
- }
205
- }
206
-
207
- /**
208
- * A Sanity `insert` patch mutation operation
209
- * Inserts the given items at the given path (before/after)
210
- *
211
- * @public
212
- */
213
- export declare interface SanityInsertPatch {
214
- id: string
215
- insert:
216
- | {
217
- before: string
218
- items: any[]
219
- }
220
- | {
221
- after: string
222
- items: any[]
223
- }
224
- | {
225
- replace: string
226
- items: any[]
227
- }
228
- }
229
-
230
- /**
231
- * A patch containing either a set, unset, insert or diffMatchPatch operation
232
- *
233
- * @public
234
- */
235
- export declare type SanityPatch =
236
- | SanitySetPatch
237
- | SanityUnsetPatch
238
- | SanityInsertPatch
239
- | SanityDiffMatchPatch
240
-
241
- /**
242
- * A mutation containing a single patch
243
- *
244
- * @public
245
- */
246
- export declare interface SanityPatchMutation {
247
- patch: SanityPatch
248
- }
249
-
250
- /**
251
- * A Sanity `set` patch mutation operation
252
- * Replaces the current path, does not merge
253
- *
254
- * @public
255
- */
256
- export declare interface SanitySetPatch {
257
- id: string
258
- set: {
259
- [key: string]: any
260
- }
261
- }
262
-
263
- /**
264
- * A Sanity `unset` patch mutation operation
265
- * Unsets the entire value of the given path
266
- *
267
- * @public
268
- */
269
- export declare interface SanityUnsetPatch {
270
- id: string
271
- unset: string[]
272
- }
273
-
274
- /**
275
- * A `set` operation
276
- * Replaces the current path, does not merge
277
- * Note: NOT a serializable mutation, see {@link SanitySetPatch} for that
278
- *
279
- * @public
280
- */
281
- export declare interface SetPatch {
282
- op: 'set'
283
- path: Path
284
- value: unknown
285
- }
286
-
287
- /**
288
- * A `unset` operation
289
- * Unsets the entire value of the given path
290
- * Note: NOT a serializable mutation, see {@link SanityUnsetPatch} for that
291
- *
292
- * @public
293
- */
294
- export declare interface UnsetPatch {
295
- op: 'unset'
296
- path: Path
297
- }
298
-
299
- export {}