@sanity/mutator 5.8.1-next.9 → 5.8.2-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 +179 -216
  2. package/package.json +6 -6
package/lib/index.d.ts CHANGED
@@ -1,122 +1,87 @@
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
-
1
+ import { CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DeleteMutation, PatchMutation, Path } from "@sanity/types";
8
2
  /**
9
- * Converts a path in array form to a JSONPath string
3
+ * Sanity document with a guaranteed `_id` and `_type`
10
4
  *
11
- * @param pathArray - Array of path segments
12
- * @returns String representation of the path
13
5
  * @internal
14
6
  */
15
- export declare function arrayToJSONMatchPath(pathArray: Path): string;
16
-
7
+ interface Doc {
8
+ _id: string;
9
+ _type: string;
10
+ _rev?: string;
11
+ _updatedAt?: string;
12
+ _createdAt?: string;
13
+ [attribute: string]: unknown;
14
+ }
17
15
  /**
16
+ * Internal mutation body representation - note that theoretically a
17
+ * mutation can only hold one of these operations each, but for sake
18
+ * of simpler code it is bundled together as one here
19
+ *
18
20
  * @internal
19
21
  */
20
- export declare class BufferedDocument {
21
- private mutations;
22
- /**
23
- * The Document we are wrapping
24
- */
25
- document: Document_2;
26
- /**
27
- * The Document with local changes applied
28
- */
29
- LOCAL: Doc | null;
30
- /**
31
- * Commits that are waiting to be delivered to the server
32
- */
33
- private commits;
34
- /**
35
- * Local mutations that are not scheduled to be committed yet
36
- */
37
- buffer: SquashingBuffer;
38
- /**
39
- * Assignable event handler for when the buffered document applies a mutation
40
- */
41
- onMutation?: (message: {
42
- mutation: Mutation;
43
- document: Doc | null;
44
- remote: boolean;
45
- }) => void;
46
- /**
47
- * Assignable event handler for when a remote mutation happened
48
- */
49
- onRemoteMutation?: Document_2["onRemoteMutation"];
50
- /**
51
- * Assignable event handler for when the buffered document rebased
52
- */
53
- onRebase?: (
54
- localDoc: Doc | null,
55
- remoteMutations: Mut[],
56
- localMutations: Mut[],
57
- ) => void;
58
- /**
59
- * Assignable event handler for when the document is deleted
60
- */
61
- onDelete?: (doc: Doc | null) => void;
62
- /**
63
- * Assignable event handler for when the state of consistency changed
64
- */
65
- onConsistencyChanged?: (isConsistent: boolean) => void;
66
- /**
67
- * Assignable event handler for when the buffered document should commit changes
68
- */
69
- commitHandler?: (msg: CommitHandlerMessage) => void;
70
- /**
71
- * Whether or not we are currently commiting
72
- */
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;
22
+ interface Mut {
23
+ create?: CreateMutation['create'];
24
+ createIfNotExists?: CreateIfNotExistsMutation['createIfNotExists'];
25
+ createOrReplace?: CreateOrReplaceMutation['createOrReplace'];
26
+ delete?: DeleteMutation['delete'];
27
+ patch?: PatchMutation['patch'];
94
28
  }
95
-
96
29
  /**
30
+ * Parameters attached to the mutation
31
+ *
97
32
  * @internal
98
33
  */
99
- export declare interface CommitHandlerMessage {
100
- mutation: Mutation;
101
- success: () => void;
102
- failure: () => void;
103
- cancel: (error: Error) => void;
34
+ interface MutationParams {
35
+ transactionId?: string;
36
+ transition?: string;
37
+ identity?: string;
38
+ previousRev?: string;
39
+ resultRev?: string;
40
+ mutations: Mut[];
41
+ timestamp?: string;
42
+ effects?: {
43
+ apply: unknown;
44
+ revert: unknown;
45
+ };
104
46
  }
105
-
106
47
  /**
107
- * Sanity document with a guaranteed `_id` and `_type`
48
+ * A mutation describing a number of operations on a single document.
49
+ * This should be considered an immutable structure. Mutations are compiled
50
+ * on first application, and any changes in properties will not effectively
51
+ * change its behavior after that.
108
52
  *
109
53
  * @internal
110
54
  */
111
- export declare interface Doc {
112
- _id: string;
113
- _type: string;
114
- _rev?: string;
115
- _updatedAt?: string;
116
- _createdAt?: string;
117
- [attribute: string]: unknown;
55
+ declare class Mutation {
56
+ params: MutationParams;
57
+ compiled?: (doc: Doc | null) => Doc | null;
58
+ _appliesToMissingDocument: boolean | undefined;
59
+ constructor(options: MutationParams);
60
+ get transactionId(): string | undefined;
61
+ get transition(): string | undefined;
62
+ get identity(): string | undefined;
63
+ get previousRev(): string | undefined;
64
+ get resultRev(): string | undefined;
65
+ get mutations(): Mut[];
66
+ get timestamp(): Date | undefined;
67
+ get effects(): {
68
+ apply: unknown;
69
+ revert: unknown;
70
+ } | undefined;
71
+ assignRandomTransactionId(): void;
72
+ appliesToMissingDocument(): boolean;
73
+ compile(): void;
74
+ apply(document: Doc | null): Doc | null;
75
+ static applyAll(document: Doc | null, mutations: Mutation[]): Doc | null;
76
+ static squash(document: Doc | null, mutations: Mutation[]): Mutation;
77
+ }
78
+ /**
79
+ * @internal
80
+ */
81
+ interface SubmissionResponder {
82
+ success: () => void;
83
+ failure: () => void;
118
84
  }
119
-
120
85
  /**
121
86
  * Models a document as it is changed by our own local patches and remote patches coming in from
122
87
  * the server. Consolidates incoming patches with our own submitted patches and maintains two
@@ -129,7 +94,7 @@ export declare interface Doc {
129
94
  *
130
95
  * @internal
131
96
  */
132
- declare class Document_2 {
97
+ declare class Document {
133
98
  /**
134
99
  * Incoming patches from the server waiting to be applied to HEAD
135
100
  */
@@ -160,11 +125,7 @@ declare class Document_2 {
160
125
  * I.e. when EDGE changes because the order of mutations has changed in relation to our
161
126
  * optimistic predictions.
162
127
  */
163
- onRebase?: (
164
- edge: Doc | null,
165
- incomingMutations: Mutation[],
166
- pendingMutations: Mutation[],
167
- ) => void;
128
+ onRebase?: (edge: Doc | null, incomingMutations: Mutation[], pendingMutations: Mutation[]) => void;
168
129
  /**
169
130
  * Called when we receive a patch in the normal order of things, but the mutation is not ours
170
131
  */
@@ -225,102 +186,6 @@ declare class Document_2 {
225
186
  pendingFailed(pendingTxnId: string): void;
226
187
  rebase(incomingMutations: Mutation[]): void;
227
188
  }
228
- export { Document_2 as Document };
229
-
230
- /**
231
- * Extracts values matching the given JsonPath
232
- *
233
- * @param path - Path to extract
234
- * @param value - Value to extract from
235
- * @returns An array of values matching the given path
236
- * @public
237
- */
238
- export declare function extract(path: string, value: unknown): unknown[];
239
-
240
- /**
241
- * Extracts a value for the given JsonPath, and includes the specific path of where it was found
242
- *
243
- * @param path - Path to extract
244
- * @param value - Value to extract from
245
- * @returns An array of objects with `path` and `value` keys
246
- * @internal
247
- */
248
- export declare function extractWithPath(
249
- path: string,
250
- value: unknown,
251
- ): {
252
- path: (string | number)[];
253
- value: unknown;
254
- }[];
255
-
256
- /**
257
- * Internal mutation body representation - note that theoretically a
258
- * mutation can only hold one of these operations each, but for sake
259
- * of simpler code it is bundled together as one here
260
- *
261
- * @internal
262
- */
263
- export declare interface Mut {
264
- create?: CreateMutation["create"];
265
- createIfNotExists?: CreateIfNotExistsMutation["createIfNotExists"];
266
- createOrReplace?: CreateOrReplaceMutation["createOrReplace"];
267
- delete?: DeleteMutation["delete"];
268
- patch?: PatchMutation["patch"];
269
- }
270
-
271
- /**
272
- * A mutation describing a number of operations on a single document.
273
- * This should be considered an immutable structure. Mutations are compiled
274
- * on first application, and any changes in properties will not effectively
275
- * change its behavior after that.
276
- *
277
- * @internal
278
- */
279
- export declare class Mutation {
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;
291
- get effects():
292
- | {
293
- apply: unknown;
294
- revert: unknown;
295
- }
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;
303
- }
304
-
305
- /**
306
- * Parameters attached to the mutation
307
- *
308
- * @internal
309
- */
310
- export declare interface MutationParams {
311
- transactionId?: string;
312
- transition?: string;
313
- identity?: string;
314
- previousRev?: string;
315
- resultRev?: string;
316
- mutations: Mut[];
317
- timestamp?: string;
318
- effects?: {
319
- apply: unknown;
320
- revert: unknown;
321
- };
322
- }
323
-
324
189
  /**
325
190
  * Implements a buffer for mutations that incrementally optimises the mutations by
326
191
  * eliminating set-operations that overwrite earlier set-operations, and rewrite
@@ -328,7 +193,7 @@ export declare interface MutationParams {
328
193
  *
329
194
  * @internal
330
195
  */
331
- export declare class SquashingBuffer {
196
+ declare class SquashingBuffer {
332
197
  /**
333
198
  * The document forming the basis of this squash
334
199
  */
@@ -372,13 +237,12 @@ export declare class SquashingBuffer {
372
237
  purge(txnId?: string): Mutation | null;
373
238
  addOperation(op: Mut): void;
374
239
  /**
375
- * Attempt to perform one single set operation in an optimised manner, return value
376
- * reflects whether or not the operation could be performed.
377
-
378
- * @param path - The JSONPath to the set operation in question
379
- * @param nextValue - The value to be set
380
- * @returns True of optimized, false otherwise
381
- */
240
+ * Attempt to perform one single set operation in an optimised manner, return value
241
+ * reflects whether or not the operation could be performed.
242
+ * @param path - The JSONPath to the set operation in question
243
+ * @param nextValue - The value to be set
244
+ * @returns True of optimized, false otherwise
245
+ */
382
246
  optimiseSetOperation(path: string, nextValue: unknown): boolean;
383
247
  stashStagedOperations(): void;
384
248
  /**
@@ -389,13 +253,112 @@ export declare class SquashingBuffer {
389
253
  */
390
254
  rebase(newBasis: Doc | null): Doc | null;
391
255
  }
392
-
393
256
  /**
394
257
  * @internal
395
258
  */
396
- export declare interface SubmissionResponder {
259
+ interface CommitHandlerMessage {
260
+ mutation: Mutation;
397
261
  success: () => void;
398
262
  failure: () => void;
263
+ cancel: (error: Error) => void;
264
+ }
265
+ /**
266
+ * @internal
267
+ */
268
+ declare class BufferedDocument {
269
+ private mutations;
270
+ /**
271
+ * The Document we are wrapping
272
+ */
273
+ document: Document;
274
+ /**
275
+ * The Document with local changes applied
276
+ */
277
+ LOCAL: Doc | null;
278
+ /**
279
+ * Commits that are waiting to be delivered to the server
280
+ */
281
+ private commits;
282
+ /**
283
+ * Local mutations that are not scheduled to be committed yet
284
+ */
285
+ buffer: SquashingBuffer;
286
+ /**
287
+ * Assignable event handler for when the buffered document applies a mutation
288
+ */
289
+ onMutation?: (message: {
290
+ mutation: Mutation;
291
+ document: Doc | null;
292
+ remote: boolean;
293
+ }) => void;
294
+ /**
295
+ * Assignable event handler for when a remote mutation happened
296
+ */
297
+ onRemoteMutation?: Document['onRemoteMutation'];
298
+ /**
299
+ * Assignable event handler for when the buffered document rebased
300
+ */
301
+ onRebase?: (localDoc: Doc | null, remoteMutations: Mut[], localMutations: Mut[]) => void;
302
+ /**
303
+ * Assignable event handler for when the document is deleted
304
+ */
305
+ onDelete?: (doc: Doc | null) => void;
306
+ /**
307
+ * Assignable event handler for when the state of consistency changed
308
+ */
309
+ onConsistencyChanged?: (isConsistent: boolean) => void;
310
+ /**
311
+ * Assignable event handler for when the buffered document should commit changes
312
+ */
313
+ commitHandler?: (msg: CommitHandlerMessage) => void;
314
+ /**
315
+ * Whether or not we are currently commiting
316
+ */
317
+ committerRunning: boolean;
318
+ constructor(doc: Doc | null);
319
+ reset(doc: Doc | null): void;
320
+ add(mutation: Mutation): void;
321
+ arrive(mutation: Mutation): void;
322
+ commit(): Promise<void>;
323
+ performCommits(): void;
324
+ _cycleCommitter(): void;
325
+ handleDocRebase(edge: Doc | null, remoteMutations: Mutation[], localMutations: Mutation[]): void;
326
+ handleDocumentDeleted(): void;
327
+ handleDocMutation(msg: {
328
+ mutation: Mutation;
329
+ document: Doc | null;
330
+ remote: boolean;
331
+ }): void;
332
+ rebase(remoteMutations: Mutation[], localMutations: Mutation[]): void;
333
+ handleDocConsistencyChanged(isConsistent: boolean): void;
399
334
  }
400
-
401
- export {};
335
+ /**
336
+ * Converts a path in array form to a JSONPath string
337
+ *
338
+ * @param pathArray - Array of path segments
339
+ * @returns String representation of the path
340
+ * @internal
341
+ */
342
+ declare function arrayToJSONMatchPath(pathArray: Path): string;
343
+ /**
344
+ * Extracts values matching the given JsonPath
345
+ *
346
+ * @param path - Path to extract
347
+ * @param value - Value to extract from
348
+ * @returns An array of values matching the given path
349
+ * @public
350
+ */
351
+ declare function extract(path: string, value: unknown): unknown[];
352
+ /**
353
+ * Extracts a value for the given JsonPath, and includes the specific path of where it was found
354
+ *
355
+ * @param path - Path to extract
356
+ * @param value - Value to extract from
357
+ * @returns An array of objects with `path` and `value` keys
358
+ * @internal
359
+ */
360
+ declare function extractWithPath(path: string, value: unknown): {
361
+ path: (string | number)[];
362
+ value: unknown;
363
+ }[];
364
+ export { BufferedDocument, type CommitHandlerMessage, type Doc, type Document, type Mut, Mutation, type MutationParams, type SquashingBuffer, type SubmissionResponder, arrayToJSONMatchPath, extract, extractWithPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/mutator",
3
- "version": "5.8.1-next.9+d88907264b",
3
+ "version": "5.8.2-next.1+7a166946ce",
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
6
  "cms",
@@ -37,7 +37,7 @@
37
37
  "@sanity/uuid": "^3.0.2",
38
38
  "debug": "^4.4.3",
39
39
  "lodash-es": "^4.17.22",
40
- "@sanity/types": "5.8.0"
40
+ "@sanity/types": "5.8.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@sanity/pkg-utils": "^10.4.4",
@@ -48,10 +48,10 @@
48
48
  "eslint": "^9.39.2",
49
49
  "rimraf": "^5.0.10",
50
50
  "vitest": "^4.0.18",
51
- "@repo/eslint-config": "5.8.1-next.9+d88907264b",
52
- "@repo/package.config": "5.8.1-next.9+d88907264b",
53
- "@repo/tsconfig": "5.8.1-next.9+d88907264b",
54
- "@repo/test-config": "5.8.1-next.9+d88907264b"
51
+ "@repo/package.config": "5.8.2-next.1+7a166946ce",
52
+ "@repo/eslint-config": "5.8.2-next.1+7a166946ce",
53
+ "@repo/test-config": "5.8.2-next.1+7a166946ce",
54
+ "@repo/tsconfig": "5.8.2-next.1+7a166946ce"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "pkg-utils build --strict --check --clean",