@sanity/sdk 2.16.0 → 2.18.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/_chunks-es/version.js +1 -1
- package/dist/index.d.ts +69 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +282 -52
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/_exports/index.ts +2 -0
- package/src/document/actions.ts +36 -0
- package/src/document/documentStore.concurrency.test.ts +1015 -0
- package/src/document/documentStore.test.ts +143 -1
- package/src/document/documentStore.ts +8 -1
- package/src/document/events.ts +32 -0
- package/src/document/listen.test.ts +56 -0
- package/src/document/listen.ts +73 -20
- package/src/document/listenerEventOperators.test.ts +311 -0
- package/src/document/listenerEventOperators.ts +217 -0
- package/src/document/patchOperations.test.ts +49 -2
- package/src/document/patchOperations.ts +50 -0
- package/src/document/processActions/edit.ts +26 -14
- package/src/document/processActions/shared.ts +165 -8
- package/src/document/processActions.test.ts +330 -1
- package/src/document/reducers.test.ts +519 -0
- package/src/document/reducers.ts +99 -3
- package/src/document/sharedListener.test.ts +2 -1
- package/src/document/sharedListener.ts +12 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK",
|
|
6
6
|
"keywords": [
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@sanity/telemetry": "^1.1.0",
|
|
63
63
|
"@sanity/types": "^6.2.0",
|
|
64
64
|
"groq": "3.88.1-typegen-experimental.0",
|
|
65
|
-
"groq-js": "^1.30.
|
|
65
|
+
"groq-js": "^1.30.3",
|
|
66
66
|
"reselect": "^5.1.1",
|
|
67
67
|
"rxjs": "^7.8.2",
|
|
68
68
|
"zustand": "^5.0.13"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@sanity/browserslist-config": "^1.0.5",
|
|
72
72
|
"@sanity/pkg-utils": "^10.5.8",
|
|
73
|
-
"@types/node": "^24.
|
|
73
|
+
"@types/node": "^24.13.3",
|
|
74
74
|
"@vitest/coverage-v8": "^4.1.10",
|
|
75
75
|
"eslint": "^10.6.0",
|
|
76
76
|
"oxfmt": "^0.58.0",
|
|
@@ -78,11 +78,11 @@
|
|
|
78
78
|
"typescript": "^6.0.3",
|
|
79
79
|
"vite": "^8.1.4",
|
|
80
80
|
"vitest": "^4.1.10",
|
|
81
|
+
"@repo/config-test": "0.0.1",
|
|
81
82
|
"@repo/config-eslint": "0.0.0",
|
|
82
|
-
"@repo/package.bundle": "3.82.0",
|
|
83
83
|
"@repo/package.config": "0.0.1",
|
|
84
84
|
"@repo/tsconfig": "0.0.1",
|
|
85
|
-
"@repo/
|
|
85
|
+
"@repo/package.bundle": "3.82.0"
|
|
86
86
|
},
|
|
87
87
|
"browserslist": "extends @sanity/browserslist-config",
|
|
88
88
|
"scripts": {
|
package/src/_exports/index.ts
CHANGED
|
@@ -129,6 +129,7 @@ export {
|
|
|
129
129
|
type DocumentAction,
|
|
130
130
|
editDocument,
|
|
131
131
|
type EditDocumentAction,
|
|
132
|
+
type EditDocumentOptions,
|
|
132
133
|
editRelease,
|
|
133
134
|
type EditReleaseAction,
|
|
134
135
|
publishDocument,
|
|
@@ -167,6 +168,7 @@ export {
|
|
|
167
168
|
type DocumentEditedEvent,
|
|
168
169
|
type DocumentEvent,
|
|
169
170
|
type DocumentPublishedEvent,
|
|
171
|
+
type DocumentRemotePatchesEvent,
|
|
170
172
|
type DocumentTransactionSubmissionResult,
|
|
171
173
|
type DocumentUnpublishedEvent,
|
|
172
174
|
type TransactionAcceptedEvent,
|
package/src/document/actions.ts
CHANGED
|
@@ -68,6 +68,21 @@ export interface EditDocumentAction<
|
|
|
68
68
|
> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
|
|
69
69
|
type: 'document.edit'
|
|
70
70
|
patches?: PatchOperations[]
|
|
71
|
+
/**
|
|
72
|
+
* When `true`, the given `patches` are forwarded verbatim to the server and
|
|
73
|
+
* applied as-is locally, instead of being re-derived by diffing document
|
|
74
|
+
* snapshots. This preserves the operational intent of the patches (e.g.
|
|
75
|
+
* keyed array inserts/unsets), which lets concurrent edits from other
|
|
76
|
+
* clients interleave coherently instead of being overwritten by
|
|
77
|
+
* position-based patches computed from a stale snapshot.
|
|
78
|
+
*
|
|
79
|
+
* Use this when the patches were produced by an editor that tracks its own
|
|
80
|
+
* operations (e.g. a collaborative text editor). During a rebase onto a
|
|
81
|
+
* changed remote document, preserved patches are re-applied operationally;
|
|
82
|
+
* if a patch can no longer apply, the transaction is skipped and reported
|
|
83
|
+
* as a `rebase-error` document event.
|
|
84
|
+
*/
|
|
85
|
+
preserveOperations?: boolean
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
/**
|
|
@@ -201,12 +216,25 @@ function convertSanityMutatePatch(
|
|
|
201
216
|
})
|
|
202
217
|
}
|
|
203
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Options for creating an `EditDocumentAction`.
|
|
221
|
+
* @beta
|
|
222
|
+
*/
|
|
223
|
+
export interface EditDocumentOptions {
|
|
224
|
+
/**
|
|
225
|
+
* Forward the given patches verbatim instead of re-deriving them by
|
|
226
|
+
* diffing document snapshots. See {@link EditDocumentAction.preserveOperations}.
|
|
227
|
+
*/
|
|
228
|
+
preserveOperations?: boolean
|
|
229
|
+
}
|
|
230
|
+
|
|
204
231
|
/**
|
|
205
232
|
* Creates an `EditDocumentAction` object with patches for modifying a document.
|
|
206
233
|
* Accepts patches in either the standard `PatchOperations` format or as a `SanityMutatePatchMutation` from `@sanity/mutate`.
|
|
207
234
|
*
|
|
208
235
|
* @param doc - A handle uniquely identifying the document to be edited.
|
|
209
236
|
* @param sanityMutatePatch - A patch mutation object from `@sanity/mutate`.
|
|
237
|
+
* @param options - Options controlling how the patches are processed.
|
|
210
238
|
* @returns An `EditDocumentAction` object ready for dispatch.
|
|
211
239
|
* @beta
|
|
212
240
|
*/
|
|
@@ -217,12 +245,14 @@ export function editDocument<
|
|
|
217
245
|
>(
|
|
218
246
|
doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
|
|
219
247
|
sanityMutatePatch: SanityMutatePatchMutation,
|
|
248
|
+
options?: EditDocumentOptions,
|
|
220
249
|
): EditDocumentAction<TDocumentType, TDataset, TProjectId>
|
|
221
250
|
/**
|
|
222
251
|
* Creates an `EditDocumentAction` object with patches for modifying a document.
|
|
223
252
|
*
|
|
224
253
|
* @param doc - A handle uniquely identifying the document to be edited.
|
|
225
254
|
* @param patches - A single patch operation or an array of patch operations.
|
|
255
|
+
* @param options - Options controlling how the patches are processed.
|
|
226
256
|
* @returns An `EditDocumentAction` object ready for dispatch.
|
|
227
257
|
* @beta
|
|
228
258
|
*/
|
|
@@ -233,6 +263,7 @@ export function editDocument<
|
|
|
233
263
|
>(
|
|
234
264
|
doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
|
|
235
265
|
patches?: PatchOperations | PatchOperations[],
|
|
266
|
+
options?: EditDocumentOptions,
|
|
236
267
|
): EditDocumentAction<TDocumentType, TDataset, TProjectId>
|
|
237
268
|
/**
|
|
238
269
|
* Creates an `EditDocumentAction` object with patches for modifying a document.
|
|
@@ -240,6 +271,7 @@ export function editDocument<
|
|
|
240
271
|
*
|
|
241
272
|
* @param doc - A handle uniquely identifying the document to be edited.
|
|
242
273
|
* @param patches - Patches in various formats (`PatchOperations`, `PatchOperations[]`, or `SanityMutatePatchMutation`).
|
|
274
|
+
* @param options - Options controlling how the patches are processed.
|
|
243
275
|
* @returns An `EditDocumentAction` object ready for dispatch.
|
|
244
276
|
*/
|
|
245
277
|
export function editDocument<
|
|
@@ -249,8 +281,10 @@ export function editDocument<
|
|
|
249
281
|
>(
|
|
250
282
|
doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
|
|
251
283
|
patches?: PatchOperations | PatchOperations[] | SanityMutatePatchMutation,
|
|
284
|
+
options?: EditDocumentOptions,
|
|
252
285
|
): EditDocumentAction<TDocumentType, TDataset, TProjectId> {
|
|
253
286
|
const effectiveDocumentId = getEffectiveDocumentId(doc)
|
|
287
|
+
const preserveOperations = options?.preserveOperations && {preserveOperations: true as const}
|
|
254
288
|
|
|
255
289
|
if (isSanityMutatePatch(patches)) {
|
|
256
290
|
const converted = convertSanityMutatePatch(patches) ?? []
|
|
@@ -259,6 +293,7 @@ export function editDocument<
|
|
|
259
293
|
type: 'document.edit',
|
|
260
294
|
documentId: effectiveDocumentId,
|
|
261
295
|
patches: converted,
|
|
296
|
+
...preserveOperations,
|
|
262
297
|
}
|
|
263
298
|
}
|
|
264
299
|
|
|
@@ -267,6 +302,7 @@ export function editDocument<
|
|
|
267
302
|
type: 'document.edit',
|
|
268
303
|
documentId: effectiveDocumentId,
|
|
269
304
|
...(patches && {patches: Array.isArray(patches) ? patches : [patches]}),
|
|
305
|
+
...preserveOperations,
|
|
270
306
|
}
|
|
271
307
|
}
|
|
272
308
|
|