@sanity/mutator 5.8.0 → 5.8.1-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.
Files changed (2) hide show
  1. package/lib/index.d.ts +146 -122
  2. package/package.json +16 -16
package/lib/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import {CreateIfNotExistsMutation} from '@sanity/types'
2
- import {CreateMutation} from '@sanity/types'
3
- import {CreateOrReplaceMutation} from '@sanity/types'
4
- import {DeleteMutation} from '@sanity/types'
5
- import {PatchMutation} from '@sanity/types'
6
- import {Path} from '@sanity/types'
1
+ import { CreateIfNotExistsMutation } from "@sanity/types";
2
+ import { CreateMutation } from "@sanity/types";
3
+ import { CreateOrReplaceMutation } from "@sanity/types";
4
+ import { DeleteMutation } from "@sanity/types";
5
+ import { PatchMutation } from "@sanity/types";
6
+ import { Path } from "@sanity/types";
7
7
 
8
8
  /**
9
9
  * Converts a path in array form to a JSONPath string
@@ -12,79 +12,95 @@ import {Path} from '@sanity/types'
12
12
  * @returns String representation of the path
13
13
  * @internal
14
14
  */
15
- export declare function arrayToJSONMatchPath(pathArray: Path): string
15
+ export declare function arrayToJSONMatchPath(pathArray: Path): string;
16
16
 
17
17
  /**
18
18
  * @internal
19
19
  */
20
20
  export declare class BufferedDocument {
21
- private mutations
21
+ private mutations;
22
22
  /**
23
23
  * The Document we are wrapping
24
24
  */
25
- document: Document_2
25
+ document: Document_2;
26
26
  /**
27
27
  * The Document with local changes applied
28
28
  */
29
- LOCAL: Doc | null
29
+ LOCAL: Doc | null;
30
30
  /**
31
31
  * Commits that are waiting to be delivered to the server
32
32
  */
33
- private commits
33
+ private commits;
34
34
  /**
35
35
  * Local mutations that are not scheduled to be committed yet
36
36
  */
37
- buffer: SquashingBuffer
37
+ buffer: SquashingBuffer;
38
38
  /**
39
39
  * Assignable event handler for when the buffered document applies a mutation
40
40
  */
41
- onMutation?: (message: {mutation: Mutation; document: Doc | null; remote: boolean}) => void
41
+ onMutation?: (message: {
42
+ mutation: Mutation;
43
+ document: Doc | null;
44
+ remote: boolean;
45
+ }) => void;
42
46
  /**
43
47
  * Assignable event handler for when a remote mutation happened
44
48
  */
45
- onRemoteMutation?: Document_2['onRemoteMutation']
49
+ onRemoteMutation?: Document_2["onRemoteMutation"];
46
50
  /**
47
51
  * Assignable event handler for when the buffered document rebased
48
52
  */
49
- onRebase?: (localDoc: Doc | null, remoteMutations: Mut[], localMutations: Mut[]) => void
53
+ onRebase?: (
54
+ localDoc: Doc | null,
55
+ remoteMutations: Mut[],
56
+ localMutations: Mut[],
57
+ ) => void;
50
58
  /**
51
59
  * Assignable event handler for when the document is deleted
52
60
  */
53
- onDelete?: (doc: Doc | null) => void
61
+ onDelete?: (doc: Doc | null) => void;
54
62
  /**
55
63
  * Assignable event handler for when the state of consistency changed
56
64
  */
57
- onConsistencyChanged?: (isConsistent: boolean) => void
65
+ onConsistencyChanged?: (isConsistent: boolean) => void;
58
66
  /**
59
67
  * Assignable event handler for when the buffered document should commit changes
60
68
  */
61
- commitHandler?: (msg: CommitHandlerMessage) => void
69
+ commitHandler?: (msg: CommitHandlerMessage) => void;
62
70
  /**
63
71
  * Whether or not we are currently commiting
64
72
  */
65
- committerRunning: boolean
66
- constructor(doc: Doc | null)
67
- reset(doc: Doc | null): void
68
- add(mutation: Mutation): void
69
- arrive(mutation: Mutation): void
70
- commit(): Promise<void>
71
- performCommits(): void
72
- _cycleCommitter(): void
73
- handleDocRebase(edge: Doc | null, remoteMutations: Mutation[], localMutations: Mutation[]): void
74
- handleDocumentDeleted(): void
75
- handleDocMutation(msg: {mutation: Mutation; document: Doc | null; remote: boolean}): void
76
- rebase(remoteMutations: Mutation[], localMutations: Mutation[]): void
77
- handleDocConsistencyChanged(isConsistent: boolean): void
73
+ committerRunning: boolean;
74
+ constructor(doc: Doc | null);
75
+ reset(doc: Doc | null): void;
76
+ add(mutation: Mutation): void;
77
+ arrive(mutation: Mutation): void;
78
+ commit(): Promise<void>;
79
+ performCommits(): void;
80
+ _cycleCommitter(): void;
81
+ handleDocRebase(
82
+ edge: Doc | null,
83
+ remoteMutations: Mutation[],
84
+ localMutations: Mutation[],
85
+ ): void;
86
+ handleDocumentDeleted(): void;
87
+ handleDocMutation(msg: {
88
+ mutation: Mutation;
89
+ document: Doc | null;
90
+ remote: boolean;
91
+ }): void;
92
+ rebase(remoteMutations: Mutation[], localMutations: Mutation[]): void;
93
+ handleDocConsistencyChanged(isConsistent: boolean): void;
78
94
  }
79
95
 
80
96
  /**
81
97
  * @internal
82
98
  */
83
99
  export declare interface CommitHandlerMessage {
84
- mutation: Mutation
85
- success: () => void
86
- failure: () => void
87
- cancel: (error: Error) => void
100
+ mutation: Mutation;
101
+ success: () => void;
102
+ failure: () => void;
103
+ cancel: (error: Error) => void;
88
104
  }
89
105
 
90
106
  /**
@@ -93,12 +109,12 @@ export declare interface CommitHandlerMessage {
93
109
  * @internal
94
110
  */
95
111
  export declare interface Doc {
96
- _id: string
97
- _type: string
98
- _rev?: string
99
- _updatedAt?: string
100
- _createdAt?: string
101
- [attribute: string]: unknown
112
+ _id: string;
113
+ _type: string;
114
+ _rev?: string;
115
+ _updatedAt?: string;
116
+ _createdAt?: string;
117
+ [attribute: string]: unknown;
102
118
  }
103
119
 
104
120
  /**
@@ -117,52 +133,60 @@ declare class Document_2 {
117
133
  /**
118
134
  * Incoming patches from the server waiting to be applied to HEAD
119
135
  */
120
- incoming: Mutation[]
136
+ incoming: Mutation[];
121
137
  /**
122
138
  * Patches we know has been subitted to the server, but has not been seen yet in the return channel
123
139
  * so we can't be sure about the ordering yet (someone else might have slipped something between them)
124
140
  */
125
- submitted: Mutation[]
141
+ submitted: Mutation[];
126
142
  /**
127
143
  * Pending mutations
128
144
  */
129
- pending: Mutation[]
145
+ pending: Mutation[];
130
146
  /**
131
147
  * Our model of the document according to the incoming patches from the server
132
148
  */
133
- HEAD: Doc | null
149
+ HEAD: Doc | null;
134
150
  /**
135
151
  * Our optimistic model of what the document will probably look like as soon as all our patches
136
152
  * have been processed. Updated every time we stage a new mutation, but also might revert back
137
153
  * to previous states if our mutations fail, or could change if unexpected mutations arrive
138
154
  * between our own. The `onRebase` callback will be called when EDGE changes in this manner.
139
155
  */
140
- EDGE: Doc | null
156
+ EDGE: Doc | null;
141
157
  /**
142
158
  * Called with the EDGE document when that document changes for a reason other than us staging
143
159
  * a new patch or receiving a mutation from the server while our EDGE is in sync with HEAD:
144
160
  * I.e. when EDGE changes because the order of mutations has changed in relation to our
145
161
  * optimistic predictions.
146
162
  */
147
- onRebase?: (edge: Doc | null, incomingMutations: Mutation[], pendingMutations: Mutation[]) => void
163
+ onRebase?: (
164
+ edge: Doc | null,
165
+ incomingMutations: Mutation[],
166
+ pendingMutations: Mutation[],
167
+ ) => void;
148
168
  /**
149
169
  * Called when we receive a patch in the normal order of things, but the mutation is not ours
150
170
  */
151
- onMutation?: (msg: {mutation: Mutation; document: Doc | null; remote: boolean}) => void
171
+ onMutation?: (msg: {
172
+ mutation: Mutation;
173
+ document: Doc | null;
174
+ remote: boolean;
175
+ }) => void;
152
176
  /**
153
177
  * Called when consistency state changes with the boolean value of the current consistency state
154
178
  */
155
- onConsistencyChanged?: (isConsistent: boolean) => void
179
+ onConsistencyChanged?: (isConsistent: boolean) => void;
156
180
  /**
157
181
  * Called whenever a new incoming mutation comes in. These are always ordered correctly.
158
182
  */
159
- onRemoteMutation?: (mut: Mutation) => void
183
+ onRemoteMutation?: (mut: Mutation) => void;
160
184
  /**
161
185
  * We are consistent when there are no unresolved mutations of our own, and no un-applicable
162
186
  * incoming mutations. When this has been going on for too long, and there has been a while
163
187
  * since we staged a new mutation, it is time to reset your state.
164
188
  */
165
- inconsistentAt: Date | null
189
+ inconsistentAt: Date | null;
166
190
  /**
167
191
  * The last time we staged a patch of our own. If we have been inconsistent for a while, but it
168
192
  * hasn't been long since we staged a new mutation, the reason is probably just because the user
@@ -170,22 +194,22 @@ declare class Document_2 {
170
194
  *
171
195
  * Should be used as a guard against resetting state for inconsistency reasons.
172
196
  */
173
- lastStagedAt: Date | null
174
- constructor(doc: Doc | null)
175
- reset(doc: Doc | null): void
176
- arrive(mutation: Mutation): void
177
- stage(mutation: Mutation, silent?: boolean): SubmissionResponder
178
- isConsistent(): boolean
179
- considerIncoming(): void
180
- updateConsistencyFlag(): void
181
- applyIncoming(mut: Mutation | undefined): boolean
197
+ lastStagedAt: Date | null;
198
+ constructor(doc: Doc | null);
199
+ reset(doc: Doc | null): void;
200
+ arrive(mutation: Mutation): void;
201
+ stage(mutation: Mutation, silent?: boolean): SubmissionResponder;
202
+ isConsistent(): boolean;
203
+ considerIncoming(): void;
204
+ updateConsistencyFlag(): void;
205
+ applyIncoming(mut: Mutation | undefined): boolean;
182
206
  /**
183
207
  * Returns true if there are unresolved mutations between HEAD and EDGE, meaning we have
184
208
  * mutations that are still waiting to be either submitted, or to be confirmed by the server.
185
209
  *
186
210
  * @returns true if there are unresolved mutations between HEAD and EDGE, false otherwise
187
211
  */
188
- hasUnresolvedMutations(): boolean
212
+ hasUnresolvedMutations(): boolean;
189
213
  /**
190
214
  * When an incoming mutation is applied to HEAD, this is called to remove the mutation from
191
215
  * the unresolved state. If the newly applied patch is the next upcoming unresolved mutation,
@@ -196,12 +220,12 @@ declare class Document_2 {
196
220
  * @param txnId - Transaction ID of the remote mutation
197
221
  * @returns true if rebase is needed, false otherwise
198
222
  */
199
- consumeUnresolved(txnId: string): boolean
200
- pendingSuccessfullySubmitted(pendingTxnId: string): void
201
- pendingFailed(pendingTxnId: string): void
202
- rebase(incomingMutations: Mutation[]): void
223
+ consumeUnresolved(txnId: string): boolean;
224
+ pendingSuccessfullySubmitted(pendingTxnId: string): void;
225
+ pendingFailed(pendingTxnId: string): void;
226
+ rebase(incomingMutations: Mutation[]): void;
203
227
  }
204
- export {Document_2 as Document}
228
+ export { Document_2 as Document };
205
229
 
206
230
  /**
207
231
  * Extracts values matching the given JsonPath
@@ -211,7 +235,7 @@ export {Document_2 as Document}
211
235
  * @returns An array of values matching the given path
212
236
  * @public
213
237
  */
214
- export declare function extract(path: string, value: unknown): unknown[]
238
+ export declare function extract(path: string, value: unknown): unknown[];
215
239
 
216
240
  /**
217
241
  * Extracts a value for the given JsonPath, and includes the specific path of where it was found
@@ -225,9 +249,9 @@ export declare function extractWithPath(
225
249
  path: string,
226
250
  value: unknown,
227
251
  ): {
228
- path: (string | number)[]
229
- value: unknown
230
- }[]
252
+ path: (string | number)[];
253
+ value: unknown;
254
+ }[];
231
255
 
232
256
  /**
233
257
  * Internal mutation body representation - note that theoretically a
@@ -237,11 +261,11 @@ export declare function extractWithPath(
237
261
  * @internal
238
262
  */
239
263
  export declare interface Mut {
240
- create?: CreateMutation['create']
241
- createIfNotExists?: CreateIfNotExistsMutation['createIfNotExists']
242
- createOrReplace?: CreateOrReplaceMutation['createOrReplace']
243
- delete?: DeleteMutation['delete']
244
- patch?: PatchMutation['patch']
264
+ create?: CreateMutation["create"];
265
+ createIfNotExists?: CreateIfNotExistsMutation["createIfNotExists"];
266
+ createOrReplace?: CreateOrReplaceMutation["createOrReplace"];
267
+ delete?: DeleteMutation["delete"];
268
+ patch?: PatchMutation["patch"];
245
269
  }
246
270
 
247
271
  /**
@@ -253,29 +277,29 @@ export declare interface Mut {
253
277
  * @internal
254
278
  */
255
279
  export declare class Mutation {
256
- params: MutationParams
257
- compiled?: (doc: Doc | null) => Doc | null
258
- _appliesToMissingDocument: boolean | undefined
259
- constructor(options: MutationParams)
260
- get transactionId(): string | undefined
261
- get transition(): string | undefined
262
- get identity(): string | undefined
263
- get previousRev(): string | undefined
264
- get resultRev(): string | undefined
265
- get mutations(): Mut[]
266
- get timestamp(): Date | undefined
280
+ params: MutationParams;
281
+ compiled?: (doc: Doc | null) => Doc | null;
282
+ _appliesToMissingDocument: boolean | undefined;
283
+ constructor(options: MutationParams);
284
+ get transactionId(): string | undefined;
285
+ get transition(): string | undefined;
286
+ get identity(): string | undefined;
287
+ get previousRev(): string | undefined;
288
+ get resultRev(): string | undefined;
289
+ get mutations(): Mut[];
290
+ get timestamp(): Date | undefined;
267
291
  get effects():
268
292
  | {
269
- apply: unknown
270
- revert: unknown
293
+ apply: unknown;
294
+ revert: unknown;
271
295
  }
272
- | undefined
273
- assignRandomTransactionId(): void
274
- appliesToMissingDocument(): boolean
275
- compile(): void
276
- apply(document: Doc | null): Doc | null
277
- static applyAll(document: Doc | null, mutations: Mutation[]): Doc | null
278
- static squash(document: Doc | null, mutations: Mutation[]): Mutation
296
+ | undefined;
297
+ assignRandomTransactionId(): void;
298
+ appliesToMissingDocument(): boolean;
299
+ compile(): void;
300
+ apply(document: Doc | null): Doc | null;
301
+ static applyAll(document: Doc | null, mutations: Mutation[]): Doc | null;
302
+ static squash(document: Doc | null, mutations: Mutation[]): Mutation;
279
303
  }
280
304
 
281
305
  /**
@@ -284,17 +308,17 @@ export declare class Mutation {
284
308
  * @internal
285
309
  */
286
310
  export declare interface MutationParams {
287
- transactionId?: string
288
- transition?: string
289
- identity?: string
290
- previousRev?: string
291
- resultRev?: string
292
- mutations: Mut[]
293
- timestamp?: string
311
+ transactionId?: string;
312
+ transition?: string;
313
+ identity?: string;
314
+ previousRev?: string;
315
+ resultRev?: string;
316
+ mutations: Mut[];
317
+ timestamp?: string;
294
318
  effects?: {
295
- apply: unknown
296
- revert: unknown
297
- }
319
+ apply: unknown;
320
+ revert: unknown;
321
+ };
298
322
  }
299
323
 
300
324
  /**
@@ -308,35 +332,35 @@ export declare class SquashingBuffer {
308
332
  /**
309
333
  * The document forming the basis of this squash
310
334
  */
311
- BASIS: Doc | null
335
+ BASIS: Doc | null;
312
336
  /**
313
337
  * The document after the out-Mutation has been applied, but before the staged
314
338
  * operations are committed.
315
339
  */
316
- PRESTAGE: Doc | null
340
+ PRESTAGE: Doc | null;
317
341
  /**
318
342
  * setOperations contain the latest set operation by path. If the set-operations are
319
343
  * updating strings to new strings, they are rewritten as diffMatchPatch operations,
320
344
  * any new set operations on the same paths overwrites any older set operations.
321
345
  * Only set-operations assigning plain values to plain values gets optimized like this.
322
346
  */
323
- setOperations: Record<string, Mut | undefined>
347
+ setOperations: Record<string, Mut | undefined>;
324
348
  /**
325
349
  * `documentPresent` is true whenever we know that the document must be present due
326
350
  * to preceeding mutations. `false` implies that it may or may not already exist.
327
351
  */
328
- documentPresent: boolean
352
+ documentPresent: boolean;
329
353
  /**
330
354
  * The operations in the out-Mutation are not able to be optimized any further
331
355
  */
332
- out: Mut[]
356
+ out: Mut[];
333
357
  /**
334
358
  * Staged mutation operations
335
359
  */
336
- staged: Mut[]
337
- constructor(doc: Doc | null)
338
- add(mut: Mutation): void
339
- hasChanges(): boolean
360
+ staged: Mut[];
361
+ constructor(doc: Doc | null);
362
+ add(mut: Mutation): void;
363
+ hasChanges(): boolean;
340
364
  /**
341
365
  * Extracts the mutations in this buffer.
342
366
  * After this is done, the buffer lifecycle is over and the client should
@@ -345,8 +369,8 @@ export declare class SquashingBuffer {
345
369
  * @param txnId - Transaction ID
346
370
  * @returns A `Mutation` instance if we had outgoing mutations pending, null otherwise
347
371
  */
348
- purge(txnId?: string): Mutation | null
349
- addOperation(op: Mut): void
372
+ purge(txnId?: string): Mutation | null;
373
+ addOperation(op: Mut): void;
350
374
  /**
351
375
  * Attempt to perform one single set operation in an optimised manner, return value
352
376
  * reflects whether or not the operation could be performed.
@@ -355,23 +379,23 @@ export declare class SquashingBuffer {
355
379
  * @param nextValue - The value to be set
356
380
  * @returns True of optimized, false otherwise
357
381
  */
358
- optimiseSetOperation(path: string, nextValue: unknown): boolean
359
- stashStagedOperations(): void
382
+ optimiseSetOperation(path: string, nextValue: unknown): boolean;
383
+ stashStagedOperations(): void;
360
384
  /**
361
385
  * Rebases given the new base-document
362
386
  *
363
387
  * @param newBasis - New base document to rebase on
364
388
  * @returns New "edge" document with buffered changes integrated
365
389
  */
366
- rebase(newBasis: Doc | null): Doc | null
390
+ rebase(newBasis: Doc | null): Doc | null;
367
391
  }
368
392
 
369
393
  /**
370
394
  * @internal
371
395
  */
372
396
  export declare interface SubmissionResponder {
373
- success: () => void
374
- failure: () => void
397
+ success: () => void;
398
+ failure: () => void;
375
399
  }
376
400
 
377
- export {}
401
+ export {};
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
2
  "name": "@sanity/mutator",
3
- "version": "5.8.0",
3
+ "version": "5.8.1-next.1+a2c187ff7a",
4
4
  "description": "A set of models to make it easier to utilize the powerful real time collaborative features of Sanity",
5
5
  "keywords": [
6
- "sanity",
7
6
  "cms",
7
+ "content",
8
8
  "headless",
9
+ "mutator",
9
10
  "realtime",
10
- "content",
11
- "mutator"
11
+ "sanity"
12
12
  ],
13
13
  "homepage": "https://www.sanity.io/",
14
14
  "bugs": {
15
15
  "url": "https://github.com/sanity-io/sanity/issues"
16
16
  },
17
+ "license": "MIT",
18
+ "author": "Sanity.io <hello@sanity.io>",
17
19
  "repository": {
18
20
  "type": "git",
19
21
  "url": "git+https://github.com/sanity-io/sanity.git",
20
22
  "directory": "packages/@sanity/mutator"
21
23
  },
22
- "license": "MIT",
23
- "author": "Sanity.io <hello@sanity.io>",
24
- "sideEffects": false,
24
+ "files": [
25
+ "lib"
26
+ ],
25
27
  "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./lib/index.js",
30
+ "types": "./lib/index.d.ts",
26
31
  "exports": {
27
32
  ".": "./lib/index.js",
28
33
  "./package.json": "./package.json"
29
34
  },
30
- "main": "./lib/index.js",
31
- "types": "./lib/index.d.ts",
32
- "files": [
33
- "lib"
34
- ],
35
35
  "dependencies": {
36
36
  "@sanity/diff-match-patch": "^3.2.0",
37
37
  "@sanity/uuid": "^3.0.2",
@@ -48,10 +48,10 @@
48
48
  "eslint": "^9.39.2",
49
49
  "rimraf": "^5.0.10",
50
50
  "vitest": "^4.0.18",
51
- "@repo/package.config": "5.8.0",
52
- "@repo/tsconfig": "5.8.0",
53
- "@repo/eslint-config": "5.8.0",
54
- "@repo/test-config": "5.8.0"
51
+ "@repo/eslint-config": "5.8.1-next.1+a2c187ff7a",
52
+ "@repo/package.config": "5.8.1-next.1+a2c187ff7a",
53
+ "@repo/test-config": "5.8.1-next.1+a2c187ff7a",
54
+ "@repo/tsconfig": "5.8.1-next.1+a2c187ff7a"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "pkg-utils build --strict --check --clean",