@sanity/sdk-react 0.0.0-alpha.7 → 0.0.0-alpha.9

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/hooks.d.ts CHANGED
@@ -1,15 +1,641 @@
1
+ import {ActionsResult} from '@sanity/sdk'
2
+ import {ApplyActionsOptions} from '@sanity/sdk'
1
3
  import {AuthProvider} from '@sanity/sdk'
2
4
  import {AuthState} from '@sanity/sdk'
5
+ import {ClientOptions} from '@sanity/sdk'
3
6
  import {CurrentUser} from '@sanity/sdk'
7
+ import {DocumentAction} from '@sanity/sdk'
8
+ import {DocumentEvent} from '@sanity/sdk'
4
9
  import {DocumentHandle} from '@sanity/sdk'
5
10
  import {DocumentListOptions} from '@sanity/sdk'
6
11
  import {FrameMessage} from '@sanity/sdk'
12
+ import {JsonMatch} from '@sanity/sdk'
13
+ import {JsonMatchPath} from '@sanity/sdk'
14
+ import {Observable} from 'rxjs'
7
15
  import {PreviewValue} from '@sanity/sdk'
16
+ import {Requester} from 'get-it'
17
+ import {SanityDocument as SanityDocument_2} from '@sanity/types'
18
+ import {SanityDocumentLike} from '@sanity/types'
8
19
  import {SanityInstance} from '@sanity/sdk'
9
20
  import {WindowMessage} from '@sanity/sdk'
10
21
 
22
+ /** @public */
23
+ declare type Action =
24
+ | CreateAction
25
+ | ReplaceDraftAction
26
+ | EditAction
27
+ | DeleteAction
28
+ | DiscardAction
29
+ | PublishAction
30
+ | UnpublishAction
31
+
32
+ /** @internal */
33
+ declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
34
+ returnFirst: false
35
+ returnDocuments: false
36
+ }
37
+
38
+ /** @internal */
39
+ declare type AllDocumentsMutationOptions = BaseMutationOptions & {
40
+ returnFirst: false
41
+ returnDocuments?: true
42
+ }
43
+
44
+ /**
45
+ * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
46
+ * @internal
47
+ */
48
+ declare type Any = any
49
+
50
+ /** @public */
51
+ declare type AssetMetadataType =
52
+ | 'location'
53
+ | 'exif'
54
+ | 'image'
55
+ | 'palette'
56
+ | 'lqip'
57
+ | 'blurhash'
58
+ | 'none'
59
+
60
+ /** @internal */
61
+ declare class AssetsClient {
62
+ #private
63
+ constructor(client: SanityClient, httpRequest: HttpRequest)
64
+ /**
65
+ * Uploads a file asset to the configured dataset
66
+ *
67
+ * @param assetType - Asset type (file)
68
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
69
+ * @param options - Options to use for the upload
70
+ */
71
+ upload(
72
+ assetType: 'file',
73
+ body: UploadBody,
74
+ options?: UploadClientConfig,
75
+ ): Promise<SanityAssetDocument>
76
+ /**
77
+ * Uploads an image asset to the configured dataset
78
+ *
79
+ * @param assetType - Asset type (image)
80
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
81
+ * @param options - Options to use for the upload
82
+ */
83
+ upload(
84
+ assetType: 'image',
85
+ body: UploadBody,
86
+ options?: UploadClientConfig,
87
+ ): Promise<SanityImageAssetDocument>
88
+ /**
89
+ * Uploads a file or an image asset to the configured dataset
90
+ *
91
+ * @param assetType - Asset type (file/image)
92
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
93
+ * @param options - Options to use for the upload
94
+ */
95
+ upload(
96
+ assetType: 'file' | 'image',
97
+ body: UploadBody,
98
+ options?: UploadClientConfig,
99
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
100
+ }
101
+
102
+ /** @internal */
103
+ declare type AttributeSet = {
104
+ [key: string]: Any
105
+ }
106
+
107
+ /** @internal */
108
+ declare type BaseActionOptions = RequestOptions & {
109
+ transactionId?: string
110
+ skipCrossDatasetReferenceValidation?: boolean
111
+ dryRun?: boolean
112
+ }
113
+
114
+ /** @internal */
115
+ declare type BaseMutationOptions = RequestOptions & {
116
+ visibility?: 'sync' | 'async' | 'deferred'
117
+ returnDocuments?: boolean
118
+ returnFirst?: boolean
119
+ dryRun?: boolean
120
+ autoGenerateArrayKeys?: boolean
121
+ skipCrossDatasetReferenceValidation?: boolean
122
+ transactionId?: string
123
+ }
124
+
125
+ /** @internal */
126
+ declare class BasePatch {
127
+ protected selection: PatchSelection
128
+ protected operations: PatchOperations
129
+ constructor(selection: PatchSelection, operations?: PatchOperations)
130
+ /**
131
+ * Sets the given attributes to the document. Does NOT merge objects.
132
+ * The operation is added to the current patch, ready to be commited by `commit()`
133
+ *
134
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
135
+ */
136
+ set(attrs: AttributeSet): this
137
+ /**
138
+ * Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
139
+ * The operation is added to the current patch, ready to be commited by `commit()`
140
+ *
141
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
142
+ */
143
+ setIfMissing(attrs: AttributeSet): this
144
+ /**
145
+ * Performs a "diff-match-patch" operation on the string attributes provided.
146
+ * The operation is added to the current patch, ready to be commited by `commit()`
147
+ *
148
+ * @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
149
+ */
150
+ diffMatchPatch(attrs: AttributeSet): this
151
+ /**
152
+ * Unsets the attribute paths provided.
153
+ * The operation is added to the current patch, ready to be commited by `commit()`
154
+ *
155
+ * @param attrs - Attribute paths to unset.
156
+ */
157
+ unset(attrs: string[]): this
158
+ /**
159
+ * Increment a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
160
+ *
161
+ * @param attrs - Object of attribute paths to increment, values representing the number to increment by.
162
+ */
163
+ inc(attrs: {[key: string]: number}): this
164
+ /**
165
+ * Decrement a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
166
+ *
167
+ * @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
168
+ */
169
+ dec(attrs: {[key: string]: number}): this
170
+ /**
171
+ * Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
172
+ *
173
+ * @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
174
+ * @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
175
+ * @param items - Array of items to insert/replace
176
+ */
177
+ insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
178
+ /**
179
+ * Append the given items to the array at the given JSONPath
180
+ *
181
+ * @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
182
+ * @param items - Array of items to append to the array
183
+ */
184
+ append(selector: string, items: Any[]): this
185
+ /**
186
+ * Prepend the given items to the array at the given JSONPath
187
+ *
188
+ * @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
189
+ * @param items - Array of items to prepend to the array
190
+ */
191
+ prepend(selector: string, items: Any[]): this
192
+ /**
193
+ * Change the contents of an array by removing existing elements and/or adding new elements.
194
+ *
195
+ * @param selector - Attribute or JSONPath expression for array
196
+ * @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
197
+ * @param deleteCount - An integer indicating the number of old array elements to remove.
198
+ * @param items - The elements to add to the array, beginning at the start index. If you don't specify any elements, splice() will only remove elements from the array.
199
+ */
200
+ splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
201
+ /**
202
+ * Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
203
+ *
204
+ * @param rev - Revision to lock the patch to
205
+ */
206
+ ifRevisionId(rev: string): this
207
+ /**
208
+ * Return a plain JSON representation of the patch
209
+ */
210
+ serialize(): PatchMutationOperation
211
+ /**
212
+ * Return a plain JSON representation of the patch
213
+ */
214
+ toJSON(): PatchMutationOperation
215
+ /**
216
+ * Clears the patch of all operations
217
+ */
218
+ reset(): this
219
+ protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
220
+ protected _set(op: keyof PatchOperations, props: Any): this
221
+ }
222
+
223
+ /** @internal */
224
+ declare class BaseTransaction {
225
+ protected operations: Mutation[]
226
+ protected trxId?: string
227
+ constructor(operations?: Mutation[], transactionId?: string)
228
+ /**
229
+ * Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
230
+ * The operation is added to the current transaction, ready to be commited by `commit()`
231
+ *
232
+ * @param doc - Document to create. Requires a `_type` property.
233
+ */
234
+ create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
235
+ /**
236
+ * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
237
+ * The operation is added to the current transaction, ready to be commited by `commit()`
238
+ *
239
+ * @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
240
+ */
241
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
242
+ doc: IdentifiedSanityDocumentStub<R>,
243
+ ): this
244
+ /**
245
+ * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
246
+ * The operation is added to the current transaction, ready to be commited by `commit()`
247
+ *
248
+ * @param doc - Document to create or replace. Requires `_id` and `_type` properties.
249
+ */
250
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
251
+ doc: IdentifiedSanityDocumentStub<R>,
252
+ ): this
253
+ /**
254
+ * Deletes the document with the given document ID
255
+ * The operation is added to the current transaction, ready to be commited by `commit()`
256
+ *
257
+ * @param documentId - Document ID to delete
258
+ */
259
+ delete(documentId: string): this
260
+ /**
261
+ * Gets the current transaction ID, if any
262
+ */
263
+ transactionId(): string | undefined
264
+ /**
265
+ * Set the ID of this transaction.
266
+ *
267
+ * @param id - Transaction ID
268
+ */
269
+ transactionId(id: string): this
270
+ /**
271
+ * Return a plain JSON representation of the transaction
272
+ */
273
+ serialize(): Mutation[]
274
+ /**
275
+ * Return a plain JSON representation of the transaction
276
+ */
277
+ toJSON(): Mutation[]
278
+ /**
279
+ * Clears the transaction of all operations
280
+ */
281
+ reset(): this
282
+ protected _add(mut: Mutation): this
283
+ }
284
+
285
+ /**
286
+ * An error occurred. This is different from a network-level error (which will be emitted as 'error').
287
+ * Possible causes are things such as malformed filters, non-existant datasets or similar.
288
+ *
289
+ * @public
290
+ */
291
+ declare type ChannelErrorEvent = {
292
+ type: 'channelError'
293
+ message: string
294
+ }
295
+
296
+ /** @public */
297
+ declare interface ClientConfig {
298
+ projectId?: string
299
+ dataset?: string
300
+ /** @defaultValue true */
301
+ useCdn?: boolean
302
+ token?: string
303
+ /** @defaultValue 'raw' */
304
+ perspective?: ClientPerspective
305
+ apiHost?: string
306
+ apiVersion?: string
307
+ proxy?: string
308
+ /**
309
+ * Optional request tag prefix for all request tags
310
+ */
311
+ requestTagPrefix?: string
312
+ ignoreBrowserTokenWarning?: boolean
313
+ withCredentials?: boolean
314
+ allowReconfigure?: boolean
315
+ timeout?: number
316
+ /** Number of retries for requests. Defaults to 5. */
317
+ maxRetries?: number
318
+ /**
319
+ * The amount of time, in milliseconds, to wait before retrying, given an attemptNumber (starting at 0).
320
+ *
321
+ * Defaults to exponential back-off, starting at 100ms, doubling for each attempt, together with random
322
+ * jitter between 0 and 100 milliseconds. More specifically the following algorithm is used:
323
+ *
324
+ * Delay = 100 * 2^attemptNumber + randomNumberBetween0and100
325
+ */
326
+ retryDelay?: (attemptNumber: number) => number
327
+ /**
328
+ * @deprecated Don't use
329
+ */
330
+ useProjectHostname?: boolean
331
+ /**
332
+ * @deprecated Don't use
333
+ */
334
+ requester?: Requester
335
+ /**
336
+ * Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
337
+ */
338
+ resultSourceMap?: boolean | 'withKeyArraySelector'
339
+ /**
340
+ *@deprecated set `cache` and `next` options on `client.fetch` instead
341
+ */
342
+ fetch?:
343
+ | {
344
+ cache?: ResponseQueryOptions['cache']
345
+ next?: ResponseQueryOptions['next']
346
+ }
347
+ | boolean
348
+ /**
349
+ * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
350
+ */
351
+ stega?: StegaConfig | boolean
352
+ }
353
+
354
+ /** @public */
355
+ declare type ClientPerspective =
356
+ | 'previewDrafts'
357
+ | 'published'
358
+ | 'drafts'
359
+ | 'raw'
360
+ | ('published' | 'drafts' | ReleaseId)[]
361
+
362
+ /** @public */
363
+ declare type ClientReturn<
364
+ GroqString extends string,
365
+ Fallback = Any,
366
+ > = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
367
+
368
+ /** @public */
369
+ declare interface ContentSourceMap {
370
+ mappings: ContentSourceMapMappings
371
+ documents: ContentSourceMapDocuments_2
372
+ paths: ContentSourceMapPaths
373
+ }
374
+
375
+ /** @public */
376
+ declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase {
377
+ _projectId?: undefined
378
+ _dataset?: undefined
379
+ }
380
+
381
+ /** @public */
382
+ declare interface ContentSourceMapDocument_2 extends ContentSourceMapDocumentBase_2 {
383
+ _projectId?: undefined
384
+ _dataset?: undefined
385
+ }
386
+
387
+ /** @public */
388
+ declare interface ContentSourceMapDocumentBase {
389
+ _id: string
390
+ _type: string
391
+ }
392
+
393
+ /** @public */
394
+ declare interface ContentSourceMapDocumentBase_2 {
395
+ _id: string
396
+ _type: string
397
+ }
398
+
399
+ /** @public */
400
+ declare type ContentSourceMapDocuments = (
401
+ | ContentSourceMapDocument
402
+ | ContentSourceMapRemoteDocument
403
+ )[]
404
+
405
+ /** @public */
406
+ declare type ContentSourceMapDocuments_2 = (
407
+ | ContentSourceMapDocument_2
408
+ | ContentSourceMapRemoteDocument_2
409
+ )[]
410
+
411
+ /**
412
+ * DocumentValueSource is a path to a value within a document
413
+ * @public
414
+ */
415
+ declare interface ContentSourceMapDocumentValueSource {
416
+ type: 'documentValue'
417
+ document: number
418
+ path: number
419
+ }
420
+
421
+ /**
422
+ * When a value is not from a source, its a literal
423
+ * @public
424
+ */
425
+ declare interface ContentSourceMapLiteralSource {
426
+ type: 'literal'
427
+ }
428
+
429
+ /** @public */
430
+ declare type ContentSourceMapMapping = ContentSourceMapValueMapping
431
+
432
+ /** @public */
433
+ declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
434
+
435
+ /** @alpha */
436
+ declare type ContentSourceMapParsedPath = (
437
+ | string
438
+ | number
439
+ | ContentSourceMapParsedPathKeyedSegment
440
+ )[]
441
+
442
+ /** @alpha */
443
+ declare type ContentSourceMapParsedPathKeyedSegment = {
444
+ _key: string
445
+ _index: number
446
+ }
447
+
448
+ /** @public */
449
+ declare type ContentSourceMapPaths = string[]
450
+
451
+ /** @public */
452
+ declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase {
453
+ _projectId: string
454
+ _dataset: string
455
+ }
456
+
457
+ /** @public */
458
+ declare interface ContentSourceMapRemoteDocument_2 extends ContentSourceMapDocumentBase_2 {
459
+ _projectId: string
460
+ _dataset: string
461
+ }
462
+
463
+ /** @public */
464
+ declare type ContentSourceMapSource =
465
+ | ContentSourceMapDocumentValueSource
466
+ | ContentSourceMapLiteralSource
467
+ | ContentSourceMapUnknownSource
468
+
469
+ /**
470
+ * When a field source is unknown
471
+ * @public
472
+ */
473
+ declare interface ContentSourceMapUnknownSource {
474
+ type: 'unknown'
475
+ }
476
+
477
+ /**
478
+ * ValueMapping is a mapping when for value that is from a single source value
479
+ * It may refer to a field within a document or a literal value
480
+ * @public
481
+ */
482
+ declare interface ContentSourceMapValueMapping {
483
+ type: 'value'
484
+ source: ContentSourceMapSource
485
+ }
486
+
487
+ /**
488
+ * Creates a new draft document. The published version of the document must not already exist.
489
+ * If the draft version of the document already exists the action will fail by default, but
490
+ * this can be adjusted to instead leave the existing document in place.
491
+ *
492
+ * @public
493
+ */
494
+ declare type CreateAction = {
495
+ actionType: 'sanity.action.document.create'
496
+ /**
497
+ * ID of the published document to create a draft for.
498
+ */
499
+ publishedId: string
500
+ /**
501
+ * Document to create. Requires a `_type` property.
502
+ */
503
+ attributes: IdentifiedSanityDocumentStub
504
+ /**
505
+ * ifExists controls what to do if the draft already exists
506
+ */
507
+ ifExists: 'fail' | 'ignore'
508
+ }
509
+
510
+ /** @internal */
511
+ declare interface CurrentSanityUser {
512
+ id: string
513
+ name: string
514
+ email: string
515
+ profileImage: string | null
516
+ role: string
517
+ }
518
+
11
519
  export {CurrentUser}
12
520
 
521
+ /** @internal */
522
+ declare type DatasetAclMode = 'public' | 'private' | 'custom'
523
+
524
+ /** @internal */
525
+ declare type DatasetResponse = {
526
+ datasetName: string
527
+ aclMode: DatasetAclMode
528
+ }
529
+
530
+ /** @internal */
531
+ declare class DatasetsClient {
532
+ #private
533
+ constructor(client: SanityClient, httpRequest: HttpRequest)
534
+ /**
535
+ * Create a new dataset with the given name
536
+ *
537
+ * @param name - Name of the dataset to create
538
+ * @param options - Options for the dataset
539
+ */
540
+ create(
541
+ name: string,
542
+ options?: {
543
+ aclMode?: DatasetAclMode
544
+ },
545
+ ): Promise<DatasetResponse>
546
+ /**
547
+ * Edit a dataset with the given name
548
+ *
549
+ * @param name - Name of the dataset to edit
550
+ * @param options - New options for the dataset
551
+ */
552
+ edit(
553
+ name: string,
554
+ options?: {
555
+ aclMode?: DatasetAclMode
556
+ },
557
+ ): Promise<DatasetResponse>
558
+ /**
559
+ * Delete a dataset with the given name
560
+ *
561
+ * @param name - Name of the dataset to delete
562
+ */
563
+ delete(name: string): Promise<{
564
+ deleted: true
565
+ }>
566
+ /**
567
+ * Fetch a list of datasets for the configured project
568
+ */
569
+ list(): Promise<DatasetsResponse>
570
+ }
571
+
572
+ /** @internal */
573
+ declare type DatasetsResponse = {
574
+ name: string
575
+ aclMode: DatasetAclMode
576
+ createdAt: string
577
+ createdByUserId: string
578
+ addonFor: string | null
579
+ datasetProfile: string
580
+ features: string[]
581
+ tags: string[]
582
+ }[]
583
+
584
+ /**
585
+ * Deletes the published version of a document and optionally some (likely all known) draft versions.
586
+ * If any draft version exists that is not specified for deletion this is an error.
587
+ * If the purge flag is set then the document history is also deleted.
588
+ *
589
+ * @public
590
+ */
591
+ declare type DeleteAction = {
592
+ actionType: 'sanity.action.document.delete'
593
+ /**
594
+ * Published document ID to delete
595
+ */
596
+ publishedId: string
597
+ /**
598
+ * Draft document ID to delete
599
+ */
600
+ includeDrafts: string[]
601
+ /**
602
+ * Delete document history
603
+ */
604
+ purge?: boolean
605
+ }
606
+
607
+ /**
608
+ * Delete the draft version of a document.
609
+ * It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
610
+ *
611
+ * @public
612
+ */
613
+ declare type DiscardAction = {
614
+ actionType: 'sanity.action.document.discard'
615
+ /**
616
+ * Draft document ID to delete
617
+ */
618
+ draftId: string
619
+ /**
620
+ * Delete document history
621
+ */
622
+ purge?: boolean
623
+ }
624
+
625
+ /**
626
+ * The listener has been told to explicitly disconnect and not reconnect.
627
+ * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
628
+ * eg in the case of a deleted dataset, a blocked project or similar events.
629
+ *
630
+ * Note that this is not treated as an error on the observable, but will complete the observable.
631
+ *
632
+ * @public
633
+ */
634
+ declare type DisconnectEvent = {
635
+ type: 'disconnect'
636
+ reason: string
637
+ }
638
+
13
639
  /**
14
640
  * @public
15
641
  */
@@ -26,6 +652,95 @@ export declare interface DocumentCollection {
26
652
  count: number
27
653
  }
28
654
 
655
+ /**
656
+ * Modifies an existing draft document.
657
+ * It applies the given patch to the document referenced by draftId.
658
+ * If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
659
+ *
660
+ * @public
661
+ */
662
+ declare type EditAction = {
663
+ actionType: 'sanity.action.document.edit'
664
+ /**
665
+ * Draft document ID to edit
666
+ */
667
+ draftId: string
668
+ /**
669
+ * Published document ID to create draft from, if draft does not exist
670
+ */
671
+ publishedId: string
672
+ /**
673
+ * Patch operations to apply
674
+ */
675
+ patch: PatchOperations
676
+ }
677
+
678
+ /** @public */
679
+ declare type FilterDefault = (props: {
680
+ /**
681
+ * The path to the value in the source document, for example if you queried for a document like this:
682
+ * `*[_type == "author"][0]{"slug": slug.current}`
683
+ * Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
684
+ *
685
+ */
686
+ sourcePath: ContentSourceMapParsedPath
687
+ /**
688
+ * If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
689
+ * for additional metadata.
690
+ * It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
691
+ * It also has `_id` to help you debug and look at the whole document when troubleshooting.
692
+ * Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
693
+ */
694
+ sourceDocument: ContentSourceMapDocuments[number]
695
+ /**
696
+ * If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
697
+ * as it operates on the original shape of a document.
698
+ * In that case `resultPath` can be used, as it mirrors the path to the value in the result.
699
+ * For example in a query like this:
700
+ * `*[_type == "author"][0]{"slug": slug.current}`
701
+ * The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
702
+ */
703
+ resultPath: ContentSourceMapParsedPath
704
+ /**
705
+ * You can also use your own string validation logic to determine if it's safe.
706
+ */
707
+ value: string
708
+ /**
709
+ * If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
710
+ * For example, here all "icon" documents in a Page Builder skips encoding:
711
+ * ```ts
712
+ {
713
+ filter: (props) => {
714
+ switch (props.sourceDocument._type) {
715
+ case 'icon':
716
+ return false
717
+ default:
718
+ return props.filterDefault(props)
719
+ }
720
+ }
721
+ }
722
+ * ```
723
+ */
724
+ filterDefault: FilterDefault
725
+ }) => boolean
726
+
727
+ /** @public */
728
+ declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
729
+ filterResponse?: true
730
+ }
731
+
732
+ /** @internal */
733
+ declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
734
+ returnFirst?: true
735
+ returnDocuments: false
736
+ }
737
+
738
+ /** @internal */
739
+ declare type FirstDocumentMutationOptions = BaseMutationOptions & {
740
+ returnFirst?: true
741
+ returnDocuments?: true
742
+ }
743
+
29
744
  /**
30
745
  * @internal
31
746
  */
@@ -51,6 +766,227 @@ export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
51
766
  ) => void
52
767
  }
53
768
 
769
+ /** @public */
770
+ declare type HttpRequest = {
771
+ (options: RequestOptions, requester: Requester): ReturnType<Requester>
772
+ }
773
+
774
+ /** @public */
775
+ declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
776
+
777
+ /** @public */
778
+ declare type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
779
+ [P in keyof T]: T[P]
780
+ } & {
781
+ _id: string
782
+ } & SanityDocumentStub
783
+
784
+ /** @public */
785
+ declare interface InitializedClientConfig extends ClientConfig {
786
+ apiHost: string
787
+ apiVersion: string
788
+ useProjectHostname: boolean
789
+ useCdn: boolean
790
+ /**
791
+ * @deprecated Internal, don't use
792
+ */
793
+ isDefaultApi: boolean
794
+ /**
795
+ * @deprecated Internal, don't use
796
+ */
797
+ url: string
798
+ /**
799
+ * @deprecated Internal, don't use
800
+ */
801
+ cdnUrl: string
802
+ /**
803
+ * The fully initialized stega config, can be used to check if stega is enabled
804
+ */
805
+ stega: InitializedStegaConfig
806
+ }
807
+
808
+ /** @public */
809
+ declare type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
810
+ Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
811
+
812
+ /** @internal */
813
+ declare type InsertPatch =
814
+ | {
815
+ before: string
816
+ items: Any[]
817
+ }
818
+ | {
819
+ after: string
820
+ items: Any[]
821
+ }
822
+ | {
823
+ replace: string
824
+ items: Any[]
825
+ }
826
+
827
+ /**
828
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
829
+ *
830
+ * @param query - GROQ-filter to listen to changes for
831
+ * @param params - Optional query parameters
832
+ * @param options - Optional listener options
833
+ * @public
834
+ */
835
+ declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
836
+ this: SanityClient | ObservableSanityClient,
837
+ query: string,
838
+ params?: ListenParams,
839
+ ): Observable<MutationEvent_2<R>>
840
+
841
+ /**
842
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
843
+ *
844
+ * @param query - GROQ-filter to listen to changes for
845
+ * @param params - Optional query parameters
846
+ * @param options - Optional listener options
847
+ * @public
848
+ */
849
+ declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
850
+ this: SanityClient | ObservableSanityClient,
851
+ query: string,
852
+ params?: ListenParams,
853
+ options?: ListenOptions,
854
+ ): Observable<ListenEvent<R>>
855
+
856
+ /** @public */
857
+ declare type ListenEvent<R extends Record<string, Any>> =
858
+ | MutationEvent_2<R>
859
+ | ChannelErrorEvent
860
+ | DisconnectEvent
861
+ | ReconnectEvent
862
+ | WelcomeEvent
863
+ | OpenEvent
864
+
865
+ /** @public */
866
+ declare type ListenEventName =
867
+ /** A mutation was performed */
868
+ | 'mutation'
869
+ /** The listener has been (re)established */
870
+ | 'welcome'
871
+ /** The listener has been disconnected, and a reconnect attempt is scheduled */
872
+ | 'reconnect'
873
+
874
+ /** @public */
875
+ declare interface ListenOptions {
876
+ /**
877
+ * Whether or not to include the resulting document in addition to the mutations performed.
878
+ * If you do not need the actual document, set this to `false` to reduce bandwidth usage.
879
+ * The result will be available on the `.result` property of the events.
880
+ * @defaultValue `true`
881
+ */
882
+ includeResult?: boolean
883
+ /**
884
+ * Whether or not to include the mutations that was performed.
885
+ * If you do not need the mutations, set this to `false` to reduce bandwidth usage.
886
+ * @defaultValue `true`
887
+ */
888
+ includeMutations?: boolean
889
+ /**
890
+ * Whether or not to include the document as it looked before the mutation event.
891
+ * The previous revision will be available on the `.previous` property of the events,
892
+ * and may be `null` in the case of a new document.
893
+ * @defaultValue `false`
894
+ */
895
+ includePreviousRevision?: boolean
896
+ /**
897
+ * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
898
+ * or only after they are available for queries (query). Note that this is on a best-effort basis,
899
+ * and listeners with `query` may in certain cases (notably with deferred transactions) receive events
900
+ * that are not yet visible to queries.
901
+ *
902
+ * @defaultValue `'transaction'`
903
+ */
904
+ visibility?: 'transaction' | 'query'
905
+ /**
906
+ * Array of event names to include in the observable. By default, only mutation events are included.
907
+ *
908
+ * @defaultValue `['mutation']`
909
+ */
910
+ events?: ListenEventName[]
911
+ /**
912
+ * Format of "effects", eg the resulting changes of a mutation.
913
+ * Currently only `mendoza` is supported, and (if set) will include `apply` and `revert` arrays
914
+ * in the mutation events under the `effects` property.
915
+ *
916
+ * See {@link https://github.com/sanity-io/mendoza | The mendoza docs} for more info
917
+ *
918
+ * @defaultValue `undefined`
919
+ */
920
+ effectFormat?: 'mendoza'
921
+ /**
922
+ * Optional request tag for the listener. Use to identify the request in logs.
923
+ *
924
+ * @defaultValue `undefined`
925
+ */
926
+ tag?: string
927
+ }
928
+
929
+ /** @public */
930
+ declare type ListenParams = {
931
+ [key: string]: Any
932
+ }
933
+
934
+ /**
935
+ * @public
936
+ */
937
+ declare class LiveClient {
938
+ #private
939
+ constructor(client: SanityClient | ObservableSanityClient)
940
+ /**
941
+ * Requires `apiVersion` to be `2021-03-25` or later.
942
+ */
943
+ events({
944
+ includeDrafts,
945
+ tag: _tag,
946
+ }?: {
947
+ includeDrafts?: boolean
948
+ /**
949
+ * Optional request tag for the listener. Use to identify the request in logs.
950
+ *
951
+ * @defaultValue `undefined`
952
+ */
953
+ tag?: string
954
+ }): Observable<LiveEvent>
955
+ }
956
+
957
+ /** @public */
958
+ declare type LiveEvent = LiveEventRestart | LiveEventReconnect | LiveEventMessage | LiveEventWelcome
959
+
960
+ /** @public */
961
+ declare interface LiveEventMessage {
962
+ type: 'message'
963
+ id: string
964
+ tags: SyncTag[]
965
+ }
966
+
967
+ /** @public */
968
+ declare interface LiveEventReconnect {
969
+ type: 'reconnect'
970
+ }
971
+
972
+ /** @public */
973
+ declare interface LiveEventRestart {
974
+ type: 'restart'
975
+ id: string
976
+ }
977
+
978
+ /** @public */
979
+ declare interface LiveEventWelcome {
980
+ type: 'welcome'
981
+ }
982
+
983
+ /** @public */
984
+ declare type Logger =
985
+ | typeof console
986
+ | Partial<
987
+ Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
988
+ >
989
+
54
990
  /**
55
991
  * @internal
56
992
  */
@@ -58,6 +994,2122 @@ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
58
994
  event: TWindowMessage['data'],
59
995
  ) => TWindowMessage['response'] | Promise<TWindowMessage['response']>
60
996
 
997
+ /** @internal */
998
+ declare interface MultipleActionResult {
999
+ transactionId: string
1000
+ }
1001
+
1002
+ /** @internal */
1003
+ declare interface MultipleMutationResult {
1004
+ transactionId: string
1005
+ documentIds: string[]
1006
+ results: {
1007
+ id: string
1008
+ operation: MutationOperation
1009
+ }[]
1010
+ }
1011
+
1012
+ /** @public */
1013
+ declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
1014
+ | {
1015
+ create: SanityDocumentStub<R>
1016
+ }
1017
+ | {
1018
+ createOrReplace: IdentifiedSanityDocumentStub<R>
1019
+ }
1020
+ | {
1021
+ createIfNotExists: IdentifiedSanityDocumentStub<R>
1022
+ }
1023
+ | {
1024
+ delete: MutationSelection
1025
+ }
1026
+ | {
1027
+ patch: PatchMutationOperation
1028
+ }
1029
+
1030
+ /**
1031
+ * A mutation was performed. Note that when updating multiple documents in a transaction,
1032
+ * each document affected will get a separate mutation event.
1033
+ *
1034
+ * @public
1035
+ */
1036
+ declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
1037
+ type: 'mutation'
1038
+ /**
1039
+ * The ID of the document that was affected
1040
+ */
1041
+ documentId: string
1042
+ /**
1043
+ * A unique ID for this event
1044
+ */
1045
+ eventId: string
1046
+ /**
1047
+ * The user ID of the user that performed the mutation
1048
+ */
1049
+ identity: string
1050
+ /**
1051
+ * An array of mutations that were performed. Note that this can differ slightly from the
1052
+ * mutations sent to the server, as the server may perform some mutations automatically.
1053
+ */
1054
+ mutations: Mutation[]
1055
+ /**
1056
+ * The revision ID of the document before the mutation was performed
1057
+ */
1058
+ previousRev?: string
1059
+ /**
1060
+ * The revision ID of the document after the mutation was performed
1061
+ */
1062
+ resultRev?: string
1063
+ /**
1064
+ * The document as it looked after the mutation was performed. This is only included if
1065
+ * the listener was configured with `includeResult: true`.
1066
+ */
1067
+ result?: SanityDocument<R>
1068
+ /**
1069
+ * The document as it looked before the mutation was performed. This is only included if
1070
+ * the listener was configured with `includePreviousRevision: true`.
1071
+ */
1072
+ previous?: SanityDocument<R> | null
1073
+ /**
1074
+ * The effects of the mutation, if the listener was configured with `effectFormat: 'mendoza'`.
1075
+ * Object with `apply` and `revert` arrays, see {@link https://github.com/sanity-io/mendoza}.
1076
+ */
1077
+ effects?: {
1078
+ apply: unknown[]
1079
+ revert: unknown[]
1080
+ }
1081
+ /**
1082
+ * A timestamp for when the mutation was performed
1083
+ */
1084
+ timestamp: string
1085
+ /**
1086
+ * The transaction ID for the mutation
1087
+ */
1088
+ transactionId: string
1089
+ /**
1090
+ * The type of transition the document went through.
1091
+ *
1092
+ * - `update` means the document was previously part of the subscribed set of documents,
1093
+ * and still is.
1094
+ * - `appear` means the document was not previously part of the subscribed set of documents,
1095
+ * but is now. This can happen both on create or if updating to a state where it now matches
1096
+ * the filter provided to the listener.
1097
+ * - `disappear` means the document was previously part of the subscribed set of documents,
1098
+ * but is no longer. This can happen both on delete or if updating to a state where it no
1099
+ * longer matches the filter provided to the listener.
1100
+ */
1101
+ transition: 'update' | 'appear' | 'disappear'
1102
+ /**
1103
+ * Whether the change that triggered this event is visible to queries (query) or only to
1104
+ * subsequent transactions (transaction). The listener client can specify a preferred visibility
1105
+ * through the `visibility` parameter on the listener, but this is only on a best-effort basis,
1106
+ * and may yet not be accurate.
1107
+ */
1108
+ visibility: 'query' | 'transaction'
1109
+ /**
1110
+ * The total number of events that will be sent for this transaction.
1111
+ * Note that this may differ from the amount of _documents_ affected by the transaction, as this
1112
+ * number only includes the documents that matches the given filter.
1113
+ *
1114
+ * This can be useful if you need to perform changes to all matched documents atomically,
1115
+ * eg you would wait for `transactionTotalEvents` events with the same `transactionId` before
1116
+ * applying the changes locally.
1117
+ */
1118
+ transactionTotalEvents: number
1119
+ /**
1120
+ * The index of this event within the transaction. Note that events may be delivered out of order,
1121
+ * and that the index is zero-based.
1122
+ */
1123
+ transactionCurrentEvent: number
1124
+ }
1125
+
1126
+ /** @internal */
1127
+ declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
1128
+
1129
+ /** @internal */
1130
+ declare type MutationSelection =
1131
+ | {
1132
+ query: string
1133
+ params?: MutationSelectionQueryParams
1134
+ }
1135
+ | {
1136
+ id: string | string[]
1137
+ }
1138
+
1139
+ /** @internal */
1140
+ declare type MutationSelectionQueryParams = {
1141
+ [key: string]: Any
1142
+ }
1143
+
1144
+ /** @internal */
1145
+ declare class ObservableAssetsClient {
1146
+ #private
1147
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1148
+ /**
1149
+ * Uploads a file asset to the configured dataset
1150
+ *
1151
+ * @param assetType - Asset type (file)
1152
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1153
+ * @param options - Options to use for the upload
1154
+ */
1155
+ upload(
1156
+ assetType: 'file',
1157
+ body: UploadBody,
1158
+ options?: UploadClientConfig,
1159
+ ): Observable<
1160
+ HttpRequestEvent<{
1161
+ document: SanityAssetDocument
1162
+ }>
1163
+ >
1164
+ /**
1165
+ * Uploads an image asset to the configured dataset
1166
+ *
1167
+ * @param assetType - Asset type (image)
1168
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1169
+ * @param options - Options to use for the upload
1170
+ */
1171
+ upload(
1172
+ assetType: 'image',
1173
+ body: UploadBody,
1174
+ options?: UploadClientConfig,
1175
+ ): Observable<
1176
+ HttpRequestEvent<{
1177
+ document: SanityImageAssetDocument
1178
+ }>
1179
+ >
1180
+ /**
1181
+ * Uploads a file or an image asset to the configured dataset
1182
+ *
1183
+ * @param assetType - Asset type (file/image)
1184
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1185
+ * @param options - Options to use for the upload
1186
+ */
1187
+ upload(
1188
+ assetType: 'file' | 'image',
1189
+ body: UploadBody,
1190
+ options?: UploadClientConfig,
1191
+ ): Observable<
1192
+ HttpRequestEvent<{
1193
+ document: SanityAssetDocument | SanityImageAssetDocument
1194
+ }>
1195
+ >
1196
+ }
1197
+
1198
+ /** @internal */
1199
+ declare class ObservableDatasetsClient {
1200
+ #private
1201
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1202
+ /**
1203
+ * Create a new dataset with the given name
1204
+ *
1205
+ * @param name - Name of the dataset to create
1206
+ * @param options - Options for the dataset
1207
+ */
1208
+ create(
1209
+ name: string,
1210
+ options?: {
1211
+ aclMode?: DatasetAclMode
1212
+ },
1213
+ ): Observable<DatasetResponse>
1214
+ /**
1215
+ * Edit a dataset with the given name
1216
+ *
1217
+ * @param name - Name of the dataset to edit
1218
+ * @param options - New options for the dataset
1219
+ */
1220
+ edit(
1221
+ name: string,
1222
+ options?: {
1223
+ aclMode?: DatasetAclMode
1224
+ },
1225
+ ): Observable<DatasetResponse>
1226
+ /**
1227
+ * Delete a dataset with the given name
1228
+ *
1229
+ * @param name - Name of the dataset to delete
1230
+ */
1231
+ delete(name: string): Observable<{
1232
+ deleted: true
1233
+ }>
1234
+ /**
1235
+ * Fetch a list of datasets for the configured project
1236
+ */
1237
+ list(): Observable<DatasetsResponse>
1238
+ }
1239
+
1240
+ /** @public */
1241
+ declare class ObservablePatch extends BasePatch {
1242
+ #private
1243
+ constructor(
1244
+ selection: PatchSelection,
1245
+ operations?: PatchOperations,
1246
+ client?: ObservableSanityClient,
1247
+ )
1248
+ /**
1249
+ * Clones the patch
1250
+ */
1251
+ clone(): ObservablePatch
1252
+ /**
1253
+ * Commit the patch, returning an observable that produces the first patched document
1254
+ *
1255
+ * @param options - Options for the mutation operation
1256
+ */
1257
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1258
+ options: FirstDocumentMutationOptions,
1259
+ ): Observable<SanityDocument<R>>
1260
+ /**
1261
+ * Commit the patch, returning an observable that produces an array of the mutated documents
1262
+ *
1263
+ * @param options - Options for the mutation operation
1264
+ */
1265
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1266
+ options: AllDocumentsMutationOptions,
1267
+ ): Observable<SanityDocument<R>[]>
1268
+ /**
1269
+ * Commit the patch, returning an observable that produces a mutation result object
1270
+ *
1271
+ * @param options - Options for the mutation operation
1272
+ */
1273
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1274
+ /**
1275
+ * Commit the patch, returning an observable that produces a mutation result object
1276
+ *
1277
+ * @param options - Options for the mutation operation
1278
+ */
1279
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1280
+ /**
1281
+ * Commit the patch, returning an observable that produces the first patched document
1282
+ *
1283
+ * @param options - Options for the mutation operation
1284
+ */
1285
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1286
+ options?: BaseMutationOptions,
1287
+ ): Observable<SanityDocument<R>>
1288
+ }
1289
+
1290
+ /** @public */
1291
+ declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
1292
+
1293
+ /** @internal */
1294
+ declare class ObservableProjectsClient {
1295
+ #private
1296
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1297
+ /**
1298
+ * Fetch a list of projects the authenticated user has access to.
1299
+ *
1300
+ * @param options - Options for the list request
1301
+ * @param options.includeMembers - Whether to include members in the response (default: true)
1302
+ */
1303
+ list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1304
+ list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1305
+ /**
1306
+ * Fetch a project by project ID
1307
+ *
1308
+ * @param projectId - ID of the project to fetch
1309
+ */
1310
+ getById(projectId: string): Observable<SanityProject>
1311
+ }
1312
+
1313
+ /** @public */
1314
+ declare class ObservableSanityClient {
1315
+ #private
1316
+ assets: ObservableAssetsClient
1317
+ datasets: ObservableDatasetsClient
1318
+ live: LiveClient
1319
+ projects: ObservableProjectsClient
1320
+ users: ObservableUsersClient
1321
+ /**
1322
+ * Instance properties
1323
+ */
1324
+ listen: typeof _listen
1325
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
1326
+ /**
1327
+ * Clone the client - returns a new instance
1328
+ */
1329
+ clone(): ObservableSanityClient
1330
+ /**
1331
+ * Returns the current client configuration
1332
+ */
1333
+ config(): InitializedClientConfig
1334
+ /**
1335
+ * Reconfigure the client. Note that this _mutates_ the current client.
1336
+ */
1337
+ config(newConfig?: Partial<ClientConfig>): this
1338
+ /**
1339
+ * Clone the client with a new (partial) configuration.
1340
+ *
1341
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1342
+ */
1343
+ withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
1344
+ /**
1345
+ * Perform a GROQ-query against the configured dataset.
1346
+ *
1347
+ * @param query - GROQ-query to perform
1348
+ */
1349
+ fetch<
1350
+ R = Any,
1351
+ Q extends QueryWithoutParams = QueryWithoutParams,
1352
+ const G extends string = string,
1353
+ >(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
1354
+ /**
1355
+ * Perform a GROQ-query against the configured dataset.
1356
+ *
1357
+ * @param query - GROQ-query to perform
1358
+ * @param params - Optional query parameters
1359
+ * @param options - Optional request options
1360
+ */
1361
+ fetch<
1362
+ R = Any,
1363
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1364
+ const G extends string = string,
1365
+ >(
1366
+ query: G,
1367
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1368
+ options?: FilteredResponseQueryOptions,
1369
+ ): Observable<ClientReturn<G, R>>
1370
+ /**
1371
+ * Perform a GROQ-query against the configured dataset.
1372
+ *
1373
+ * @param query - GROQ-query to perform
1374
+ * @param params - Optional query parameters
1375
+ * @param options - Request options
1376
+ */
1377
+ fetch<
1378
+ R = Any,
1379
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1380
+ const G extends string = string,
1381
+ >(
1382
+ query: string,
1383
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1384
+ options: UnfilteredResponseQueryOptions,
1385
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
1386
+ /**
1387
+ * Perform a GROQ-query against the configured dataset.
1388
+ *
1389
+ * @param query - GROQ-query to perform
1390
+ * @param params - Optional query parameters
1391
+ * @param options - Request options
1392
+ */
1393
+ fetch<
1394
+ R = Any,
1395
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
1396
+ const G extends string = string,
1397
+ >(
1398
+ query: G,
1399
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1400
+ options: UnfilteredResponseWithoutQuery,
1401
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
1402
+ /**
1403
+ * Fetch a single document with the given ID.
1404
+ *
1405
+ * @param id - Document ID to fetch
1406
+ * @param options - Request options
1407
+ */
1408
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
1409
+ id: string,
1410
+ options?: {
1411
+ tag?: string
1412
+ },
1413
+ ): Observable<SanityDocument<R> | undefined>
1414
+ /**
1415
+ * Fetch multiple documents in one request.
1416
+ * Should be used sparingly - performing a query is usually a better option.
1417
+ * The order/position of documents is preserved based on the original array of IDs.
1418
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
1419
+ *
1420
+ * @param ids - Document IDs to fetch
1421
+ * @param options - Request options
1422
+ */
1423
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
1424
+ ids: string[],
1425
+ options?: {
1426
+ tag?: string
1427
+ },
1428
+ ): Observable<(SanityDocument<R> | null)[]>
1429
+ /**
1430
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1431
+ * Returns an observable that resolves to the created document.
1432
+ *
1433
+ * @param document - Document to create
1434
+ * @param options - Mutation options
1435
+ */
1436
+ create<R extends Record<string, Any> = Record<string, Any>>(
1437
+ document: SanityDocumentStub<R>,
1438
+ options: FirstDocumentMutationOptions,
1439
+ ): Observable<SanityDocument<R>>
1440
+ /**
1441
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1442
+ * Returns an observable that resolves to an array containing the created document.
1443
+ *
1444
+ * @param document - Document to create
1445
+ * @param options - Mutation options
1446
+ */
1447
+ create<R extends Record<string, Any> = Record<string, Any>>(
1448
+ document: SanityDocumentStub<R>,
1449
+ options: AllDocumentsMutationOptions,
1450
+ ): Observable<SanityDocument<R>[]>
1451
+ /**
1452
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1453
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1454
+ *
1455
+ * @param document - Document to create
1456
+ * @param options - Mutation options
1457
+ */
1458
+ create<R extends Record<string, Any> = Record<string, Any>>(
1459
+ document: SanityDocumentStub<R>,
1460
+ options: FirstDocumentIdMutationOptions,
1461
+ ): Observable<SingleMutationResult>
1462
+ /**
1463
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1464
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1465
+ *
1466
+ * @param document - Document to create
1467
+ * @param options - Mutation options
1468
+ */
1469
+ create<R extends Record<string, Any> = Record<string, Any>>(
1470
+ document: SanityDocumentStub<R>,
1471
+ options: AllDocumentIdsMutationOptions,
1472
+ ): Observable<MultipleMutationResult>
1473
+ /**
1474
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1475
+ * Returns an observable that resolves to the created document.
1476
+ *
1477
+ * @param document - Document to create
1478
+ * @param options - Mutation options
1479
+ */
1480
+ create<R extends Record<string, Any> = Record<string, Any>>(
1481
+ document: SanityDocumentStub<R>,
1482
+ options?: BaseMutationOptions,
1483
+ ): Observable<SanityDocument<R>>
1484
+ /**
1485
+ * Create a document if no document with the same ID already exists.
1486
+ * Returns an observable that resolves to the created document.
1487
+ *
1488
+ * @param document - Document to create
1489
+ * @param options - Mutation options
1490
+ */
1491
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1492
+ document: IdentifiedSanityDocumentStub<R>,
1493
+ options: FirstDocumentMutationOptions,
1494
+ ): Observable<SanityDocument<R>>
1495
+ /**
1496
+ * Create a document if no document with the same ID already exists.
1497
+ * Returns an observable that resolves to an array containing the created document.
1498
+ *
1499
+ * @param document - Document to create
1500
+ * @param options - Mutation options
1501
+ */
1502
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1503
+ document: IdentifiedSanityDocumentStub<R>,
1504
+ options: AllDocumentsMutationOptions,
1505
+ ): Observable<SanityDocument<R>[]>
1506
+ /**
1507
+ * Create a document if no document with the same ID already exists.
1508
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1509
+ *
1510
+ * @param document - Document to create
1511
+ * @param options - Mutation options
1512
+ */
1513
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1514
+ document: IdentifiedSanityDocumentStub<R>,
1515
+ options: FirstDocumentIdMutationOptions,
1516
+ ): Observable<SingleMutationResult>
1517
+ /**
1518
+ * Create a document if no document with the same ID already exists.
1519
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1520
+ *
1521
+ * @param document - Document to create
1522
+ * @param options - Mutation options
1523
+ */
1524
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1525
+ document: IdentifiedSanityDocumentStub<R>,
1526
+ options: AllDocumentIdsMutationOptions,
1527
+ ): Observable<MultipleMutationResult>
1528
+ /**
1529
+ * Create a document if no document with the same ID already exists.
1530
+ * Returns an observable that resolves to the created document.
1531
+ *
1532
+ * @param document - Document to create
1533
+ * @param options - Mutation options
1534
+ */
1535
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1536
+ document: IdentifiedSanityDocumentStub<R>,
1537
+ options?: BaseMutationOptions,
1538
+ ): Observable<SanityDocument<R>>
1539
+ /**
1540
+ * Create a document if it does not exist, or replace a document with the same document ID
1541
+ * Returns an observable that resolves to the created document.
1542
+ *
1543
+ * @param document - Document to either create or replace
1544
+ * @param options - Mutation options
1545
+ */
1546
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1547
+ document: IdentifiedSanityDocumentStub<R>,
1548
+ options: FirstDocumentMutationOptions,
1549
+ ): Observable<SanityDocument<R>>
1550
+ /**
1551
+ * Create a document if it does not exist, or replace a document with the same document ID
1552
+ * Returns an observable that resolves to an array containing the created document.
1553
+ *
1554
+ * @param document - Document to either create or replace
1555
+ * @param options - Mutation options
1556
+ */
1557
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1558
+ document: IdentifiedSanityDocumentStub<R>,
1559
+ options: AllDocumentsMutationOptions,
1560
+ ): Observable<SanityDocument<R>[]>
1561
+ /**
1562
+ * Create a document if it does not exist, or replace a document with the same document ID
1563
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
1564
+ *
1565
+ * @param document - Document to either create or replace
1566
+ * @param options - Mutation options
1567
+ */
1568
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1569
+ document: IdentifiedSanityDocumentStub<R>,
1570
+ options: FirstDocumentIdMutationOptions,
1571
+ ): Observable<SingleMutationResult>
1572
+ /**
1573
+ * Create a document if it does not exist, or replace a document with the same document ID
1574
+ * Returns an observable that resolves to a mutation result object containing the created document ID.
1575
+ *
1576
+ * @param document - Document to either create or replace
1577
+ * @param options - Mutation options
1578
+ */
1579
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1580
+ document: IdentifiedSanityDocumentStub<R>,
1581
+ options: AllDocumentIdsMutationOptions,
1582
+ ): Observable<MultipleMutationResult>
1583
+ /**
1584
+ * Create a document if it does not exist, or replace a document with the same document ID
1585
+ * Returns an observable that resolves to the created document.
1586
+ *
1587
+ * @param document - Document to either create or replace
1588
+ * @param options - Mutation options
1589
+ */
1590
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1591
+ document: IdentifiedSanityDocumentStub<R>,
1592
+ options?: BaseMutationOptions,
1593
+ ): Observable<SanityDocument<R>>
1594
+ /**
1595
+ * Deletes a document with the given document ID.
1596
+ * Returns an observable that resolves to the deleted document.
1597
+ *
1598
+ * @param id - Document ID to delete
1599
+ * @param options - Options for the mutation
1600
+ */
1601
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1602
+ id: string,
1603
+ options: FirstDocumentMutationOptions,
1604
+ ): Observable<SanityDocument<R>>
1605
+ /**
1606
+ * Deletes a document with the given document ID.
1607
+ * Returns an observable that resolves to an array containing the deleted document.
1608
+ *
1609
+ * @param id - Document ID to delete
1610
+ * @param options - Options for the mutation
1611
+ */
1612
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1613
+ id: string,
1614
+ options: AllDocumentsMutationOptions,
1615
+ ): Observable<SanityDocument<R>[]>
1616
+ /**
1617
+ * Deletes a document with the given document ID.
1618
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1619
+ *
1620
+ * @param id - Document ID to delete
1621
+ * @param options - Options for the mutation
1622
+ */
1623
+ delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1624
+ /**
1625
+ * Deletes a document with the given document ID.
1626
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1627
+ *
1628
+ * @param id - Document ID to delete
1629
+ * @param options - Options for the mutation
1630
+ */
1631
+ delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1632
+ /**
1633
+ * Deletes a document with the given document ID.
1634
+ * Returns an observable that resolves to the deleted document.
1635
+ *
1636
+ * @param id - Document ID to delete
1637
+ * @param options - Options for the mutation
1638
+ */
1639
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1640
+ id: string,
1641
+ options?: BaseMutationOptions,
1642
+ ): Observable<SanityDocument<R>>
1643
+ /**
1644
+ * Deletes one or more documents matching the given query or document ID.
1645
+ * Returns an observable that resolves to first deleted document.
1646
+ *
1647
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1648
+ * @param options - Options for the mutation
1649
+ */
1650
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1651
+ selection: MutationSelection,
1652
+ options: FirstDocumentMutationOptions,
1653
+ ): Observable<SanityDocument<R>>
1654
+ /**
1655
+ * Deletes one or more documents matching the given query or document ID.
1656
+ * Returns an observable that resolves to an array containing the deleted documents.
1657
+ *
1658
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1659
+ * @param options - Options for the mutation
1660
+ */
1661
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1662
+ selection: MutationSelection,
1663
+ options: AllDocumentsMutationOptions,
1664
+ ): Observable<SanityDocument<R>[]>
1665
+ /**
1666
+ * Deletes one or more documents matching the given query or document ID.
1667
+ * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
1668
+ *
1669
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1670
+ * @param options - Options for the mutation
1671
+ */
1672
+ delete(
1673
+ selection: MutationSelection,
1674
+ options: FirstDocumentIdMutationOptions,
1675
+ ): Observable<SingleMutationResult>
1676
+ /**
1677
+ * Deletes one or more documents matching the given query or document ID.
1678
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
1679
+ *
1680
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1681
+ * @param options - Options for the mutation
1682
+ */
1683
+ delete(
1684
+ selection: MutationSelection,
1685
+ options: AllDocumentIdsMutationOptions,
1686
+ ): Observable<MultipleMutationResult>
1687
+ /**
1688
+ * Deletes one or more documents matching the given query or document ID.
1689
+ * Returns an observable that resolves to first deleted document.
1690
+ *
1691
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1692
+ * @param options - Options for the mutation
1693
+ */
1694
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1695
+ selection: MutationSelection,
1696
+ options?: BaseMutationOptions,
1697
+ ): Observable<SanityDocument<R>>
1698
+ /**
1699
+ * Perform mutation operations against the configured dataset
1700
+ * Returns an observable that resolves to the first mutated document.
1701
+ *
1702
+ * @param operations - Mutation operations to execute
1703
+ * @param options - Mutation options
1704
+ */
1705
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1706
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1707
+ options: FirstDocumentMutationOptions,
1708
+ ): Observable<SanityDocument<R>>
1709
+ /**
1710
+ * Perform mutation operations against the configured dataset.
1711
+ * Returns an observable that resolves to an array of the mutated documents.
1712
+ *
1713
+ * @param operations - Mutation operations to execute
1714
+ * @param options - Mutation options
1715
+ */
1716
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1717
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1718
+ options: AllDocumentsMutationOptions,
1719
+ ): Observable<SanityDocument<R>[]>
1720
+ /**
1721
+ * Perform mutation operations against the configured dataset
1722
+ * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
1723
+ *
1724
+ * @param operations - Mutation operations to execute
1725
+ * @param options - Mutation options
1726
+ */
1727
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1728
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1729
+ options: FirstDocumentIdMutationOptions,
1730
+ ): Observable<SingleMutationResult>
1731
+ /**
1732
+ * Perform mutation operations against the configured dataset
1733
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
1734
+ *
1735
+ * @param operations - Mutation operations to execute
1736
+ * @param options - Mutation options
1737
+ */
1738
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1739
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1740
+ options: AllDocumentIdsMutationOptions,
1741
+ ): Observable<MultipleMutationResult>
1742
+ /**
1743
+ * Perform mutation operations against the configured dataset
1744
+ * Returns an observable that resolves to the first mutated document.
1745
+ *
1746
+ * @param operations - Mutation operations to execute
1747
+ * @param options - Mutation options
1748
+ */
1749
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1750
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1751
+ options?: BaseMutationOptions,
1752
+ ): Observable<SanityDocument<R>>
1753
+ /**
1754
+ * Create a new buildable patch of operations to perform
1755
+ *
1756
+ * @param documentId - Document ID to patch
1757
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1758
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1759
+ */
1760
+ patch(documentId: string, operations?: PatchOperations): ObservablePatch
1761
+ /**
1762
+ * Create a new buildable patch of operations to perform
1763
+ *
1764
+ * @param documentIds - Array of document IDs to patch
1765
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1766
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1767
+ */
1768
+ patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
1769
+ /**
1770
+ * Create a new buildable patch of operations to perform
1771
+ *
1772
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
1773
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1774
+ * @returns Patch instance - call `.commit()` to perform the operations defined
1775
+ */
1776
+ patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
1777
+ /**
1778
+ * Create a new transaction of mutations
1779
+ *
1780
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
1781
+ */
1782
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
1783
+ operations?: Mutation<R>[],
1784
+ ): ObservableTransaction
1785
+ /**
1786
+ * Perform action operations against the configured dataset
1787
+ *
1788
+ * @param operations - Action operation(s) to execute
1789
+ * @param options - Action options
1790
+ */
1791
+ action(
1792
+ operations: Action | Action[],
1793
+ options?: BaseActionOptions,
1794
+ ): Observable<SingleActionResult | MultipleActionResult>
1795
+ /**
1796
+ * Perform an HTTP request against the Sanity API
1797
+ *
1798
+ * @param options - Request options
1799
+ */
1800
+ request<R = Any>(options: RawRequestOptions): Observable<R>
1801
+ /**
1802
+ * Get a Sanity API URL for the URI provided
1803
+ *
1804
+ * @param uri - URI/path to build URL for
1805
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1806
+ */
1807
+ getUrl(uri: string, canUseCdn?: boolean): string
1808
+ /**
1809
+ * Get a Sanity API URL for the data operation and path provided
1810
+ *
1811
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1812
+ * @param path - Path to append after the operation
1813
+ */
1814
+ getDataUrl(operation: string, path?: string): string
1815
+ }
1816
+
1817
+ /** @public */
1818
+ declare class ObservableTransaction extends BaseTransaction {
1819
+ #private
1820
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
1821
+ /**
1822
+ * Clones the transaction
1823
+ */
1824
+ clone(): ObservableTransaction
1825
+ /**
1826
+ * Commit the transaction, returning an observable that produces the first mutated document
1827
+ *
1828
+ * @param options - Options for the mutation operation
1829
+ */
1830
+ commit<R extends Record<string, Any>>(
1831
+ options: TransactionFirstDocumentMutationOptions,
1832
+ ): Observable<SanityDocument<R>>
1833
+ /**
1834
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
1835
+ *
1836
+ * @param options - Options for the mutation operation
1837
+ */
1838
+ commit<R extends Record<string, Any>>(
1839
+ options: TransactionAllDocumentsMutationOptions,
1840
+ ): Observable<SanityDocument<R>[]>
1841
+ /**
1842
+ * Commit the transaction, returning an observable that produces a mutation result object
1843
+ *
1844
+ * @param options - Options for the mutation operation
1845
+ */
1846
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1847
+ /**
1848
+ * Commit the transaction, returning an observable that produces a mutation result object
1849
+ *
1850
+ * @param options - Options for the mutation operation
1851
+ */
1852
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1853
+ /**
1854
+ * Commit the transaction, returning an observable that produces a mutation result object
1855
+ *
1856
+ * @param options - Options for the mutation operation
1857
+ */
1858
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
1859
+ /**
1860
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
1861
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1862
+ *
1863
+ * @param documentId - Document ID to perform the patch operation on
1864
+ * @param patchOps - Operations to perform, or a builder function
1865
+ */
1866
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
1867
+ /**
1868
+ * Adds the given patch instance to the transaction.
1869
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1870
+ *
1871
+ * @param patch - ObservablePatch to execute
1872
+ */
1873
+ patch(patch: ObservablePatch): this
1874
+ }
1875
+
1876
+ /** @public */
1877
+ declare class ObservableUsersClient {
1878
+ #private
1879
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1880
+ /**
1881
+ * Fetch a user by user ID
1882
+ *
1883
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
1884
+ */
1885
+ getById<T extends 'me' | string>(
1886
+ id: T,
1887
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
1888
+ }
1889
+
1890
+ /**
1891
+ * The listener connection has been established
1892
+ * note: it's usually a better option to use the 'welcome' event
1893
+ * @public
1894
+ */
1895
+ declare type OpenEvent = {
1896
+ type: 'open'
1897
+ }
1898
+
1899
+ /** @public */
1900
+ declare class Patch extends BasePatch {
1901
+ #private
1902
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
1903
+ /**
1904
+ * Clones the patch
1905
+ */
1906
+ clone(): Patch
1907
+ /**
1908
+ * Commit the patch, returning a promise that resolves to the first patched document
1909
+ *
1910
+ * @param options - Options for the mutation operation
1911
+ */
1912
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1913
+ options: FirstDocumentMutationOptions,
1914
+ ): Promise<SanityDocument<R>>
1915
+ /**
1916
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
1917
+ *
1918
+ * @param options - Options for the mutation operation
1919
+ */
1920
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1921
+ options: AllDocumentsMutationOptions,
1922
+ ): Promise<SanityDocument<R>[]>
1923
+ /**
1924
+ * Commit the patch, returning a promise that resolves to a mutation result object
1925
+ *
1926
+ * @param options - Options for the mutation operation
1927
+ */
1928
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
1929
+ /**
1930
+ * Commit the patch, returning a promise that resolves to a mutation result object
1931
+ *
1932
+ * @param options - Options for the mutation operation
1933
+ */
1934
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1935
+ /**
1936
+ * Commit the patch, returning a promise that resolves to the first patched document
1937
+ *
1938
+ * @param options - Options for the mutation operation
1939
+ */
1940
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1941
+ options?: BaseMutationOptions,
1942
+ ): Promise<SanityDocument<R>>
1943
+ }
1944
+
1945
+ /** @public */
1946
+ declare type PatchBuilder = (patch: Patch) => Patch
1947
+
1948
+ /** @internal */
1949
+ declare type PatchMutationOperation = PatchOperations & MutationSelection
1950
+
1951
+ /** @internal */
1952
+ declare interface PatchOperations {
1953
+ set?: {
1954
+ [key: string]: Any
1955
+ }
1956
+ setIfMissing?: {
1957
+ [key: string]: Any
1958
+ }
1959
+ diffMatchPatch?: {
1960
+ [key: string]: Any
1961
+ }
1962
+ unset?: string[]
1963
+ inc?: {
1964
+ [key: string]: number
1965
+ }
1966
+ dec?: {
1967
+ [key: string]: number
1968
+ }
1969
+ insert?: InsertPatch
1970
+ ifRevisionID?: string
1971
+ }
1972
+
1973
+ /** @internal */
1974
+ declare type PatchSelection = string | string[] | MutationSelection
1975
+
1976
+ /** @public */
1977
+ declare interface ProgressEvent_2 {
1978
+ type: 'progress'
1979
+ stage: 'upload' | 'download'
1980
+ percent: number
1981
+ total?: number
1982
+ loaded?: number
1983
+ lengthComputable: boolean
1984
+ }
1985
+
1986
+ /** @internal */
1987
+ declare class ProjectsClient {
1988
+ #private
1989
+ constructor(client: SanityClient, httpRequest: HttpRequest)
1990
+ /**
1991
+ * Fetch a list of projects the authenticated user has access to.
1992
+ *
1993
+ * @param options - Options for the list request
1994
+ * @param options.includeMembers - Whether to include members in the response (default: true)
1995
+ */
1996
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
1997
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
1998
+ /**
1999
+ * Fetch a project by project ID
2000
+ *
2001
+ * @param projectId - ID of the project to fetch
2002
+ */
2003
+ getById(projectId: string): Promise<SanityProject>
2004
+ }
2005
+
2006
+ /**
2007
+ * Publishes a draft document.
2008
+ * If a published version of the document already exists this is replaced by the current draft document.
2009
+ * In either case the draft document is deleted.
2010
+ * The optional revision id parameters can be used for optimistic locking to ensure
2011
+ * that the draft and/or published versions of the document have not been changed by another client.
2012
+ *
2013
+ * @public
2014
+ */
2015
+ declare type PublishAction = {
2016
+ actionType: 'sanity.action.document.publish'
2017
+ /**
2018
+ * Draft document ID to publish
2019
+ */
2020
+ draftId: string
2021
+ /**
2022
+ * Draft revision ID to match
2023
+ */
2024
+ ifDraftRevisionId?: string
2025
+ /**
2026
+ * Published document ID to replace
2027
+ */
2028
+ publishedId: string
2029
+ /**
2030
+ * Published revision ID to match
2031
+ */
2032
+ ifPublishedRevisionId?: string
2033
+ }
2034
+
2035
+ /** @public */
2036
+ declare interface QueryParams {
2037
+ [key: string]: any
2038
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2039
+ body?: never
2040
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2041
+ cache?: 'next' extends keyof RequestInit ? never : any
2042
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2043
+ filterResponse?: never
2044
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2045
+ headers?: never
2046
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2047
+ method?: never
2048
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2049
+ next?: 'next' extends keyof RequestInit ? never : any
2050
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2051
+ perspective?: never
2052
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2053
+ query?: never
2054
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2055
+ resultSourceMap?: never
2056
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2057
+ returnQuery?: never
2058
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2059
+ signal?: never
2060
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2061
+ stega?: never
2062
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2063
+ tag?: never
2064
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2065
+ timeout?: never
2066
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2067
+ token?: never
2068
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2069
+ useCdn?: never
2070
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2071
+ lastLiveEventId?: never
2072
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2073
+ cacheMode?: never
2074
+ }
2075
+
2076
+ /**
2077
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2078
+ * @public
2079
+ */
2080
+ declare type QueryWithoutParams = Record<string, never> | undefined
2081
+
2082
+ /** @public */
2083
+ declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2084
+
2085
+ /** @public */
2086
+ declare interface RawQueryResponse<R> {
2087
+ query: string
2088
+ ms: number
2089
+ result: R
2090
+ resultSourceMap?: ContentSourceMap
2091
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
2092
+ syncTags?: SyncTag[]
2093
+ }
2094
+
2095
+ /** @internal */
2096
+ declare interface RawRequestOptions {
2097
+ url?: string
2098
+ uri?: string
2099
+ method?: string
2100
+ token?: string
2101
+ json?: boolean
2102
+ tag?: string
2103
+ useGlobalApi?: boolean
2104
+ withCredentials?: boolean
2105
+ query?: {
2106
+ [key: string]: string | string[]
2107
+ }
2108
+ headers?: {
2109
+ [key: string]: string
2110
+ }
2111
+ timeout?: number
2112
+ proxy?: string
2113
+ body?: Any
2114
+ maxRedirects?: number
2115
+ signal?: AbortSignal
2116
+ }
2117
+
2118
+ /**
2119
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
2120
+ *
2121
+ * @public
2122
+ */
2123
+ declare type ReconnectEvent = {
2124
+ type: 'reconnect'
2125
+ }
2126
+
2127
+ /** @public */
2128
+ declare type ReleaseId = `r${string}`
2129
+
2130
+ /**
2131
+ * Replaces an existing draft document.
2132
+ * At least one of the draft or published versions of the document must exist.
2133
+ *
2134
+ * @public
2135
+ */
2136
+ declare type ReplaceDraftAction = {
2137
+ actionType: 'sanity.action.document.replaceDraft'
2138
+ /**
2139
+ * Published document ID to create draft from, if draft does not exist
2140
+ */
2141
+ publishedId: string
2142
+ /**
2143
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2144
+ */
2145
+ attributes: IdentifiedSanityDocumentStub
2146
+ }
2147
+
2148
+ /** @public */
2149
+ declare interface RequestOptions {
2150
+ timeout?: number
2151
+ token?: string
2152
+ tag?: string
2153
+ headers?: Record<string, string>
2154
+ method?: string
2155
+ query?: Any
2156
+ body?: Any
2157
+ signal?: AbortSignal
2158
+ }
2159
+
2160
+ /** @alpha */
2161
+ declare type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments[number]) => StudioUrl
2162
+
2163
+ /** @public */
2164
+ declare interface ResponseEvent<T = unknown> {
2165
+ type: 'response'
2166
+ body: T
2167
+ url: string
2168
+ method: string
2169
+ statusCode: number
2170
+ statusMessage?: string
2171
+ headers: Record<string, string>
2172
+ }
2173
+
2174
+ /** @public */
2175
+ declare interface ResponseQueryOptions extends RequestOptions {
2176
+ perspective?: ClientPerspective
2177
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2178
+ returnQuery?: boolean
2179
+ useCdn?: boolean
2180
+ stega?: boolean | StegaConfig
2181
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
2182
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
2183
+ lastLiveEventId?: string | string[] | null
2184
+ /**
2185
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
2186
+ * Tradeoff between latency and freshness of content.
2187
+ *
2188
+ * Only to be used with live content queries and when useCdn is true.
2189
+ */
2190
+ cacheMode?: 'noStale'
2191
+ }
2192
+
2193
+ /** @internal */
2194
+ declare interface SanityAssetDocument extends SanityDocument {
2195
+ url: string
2196
+ path: string
2197
+ size: number
2198
+ assetId: string
2199
+ mimeType: string
2200
+ sha1hash: string
2201
+ extension: string
2202
+ uploadId?: string
2203
+ originalFilename?: string
2204
+ }
2205
+
2206
+ /** @public */
2207
+ declare class SanityClient {
2208
+ #private
2209
+ assets: AssetsClient
2210
+ datasets: DatasetsClient
2211
+ live: LiveClient
2212
+ projects: ProjectsClient
2213
+ users: UsersClient
2214
+ /**
2215
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
2216
+ */
2217
+ observable: ObservableSanityClient
2218
+ /**
2219
+ * Instance properties
2220
+ */
2221
+ listen: typeof _listen
2222
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
2223
+ /**
2224
+ * Clone the client - returns a new instance
2225
+ */
2226
+ clone(): SanityClient
2227
+ /**
2228
+ * Returns the current client configuration
2229
+ */
2230
+ config(): InitializedClientConfig
2231
+ /**
2232
+ * Reconfigure the client. Note that this _mutates_ the current client.
2233
+ */
2234
+ config(newConfig?: Partial<ClientConfig>): this
2235
+ /**
2236
+ * Clone the client with a new (partial) configuration.
2237
+ *
2238
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2239
+ */
2240
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
2241
+ /**
2242
+ * Perform a GROQ-query against the configured dataset.
2243
+ *
2244
+ * @param query - GROQ-query to perform
2245
+ */
2246
+ fetch<
2247
+ R = Any,
2248
+ Q extends QueryWithoutParams = QueryWithoutParams,
2249
+ const G extends string = string,
2250
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
2251
+ /**
2252
+ * Perform a GROQ-query against the configured dataset.
2253
+ *
2254
+ * @param query - GROQ-query to perform
2255
+ * @param params - Optional query parameters
2256
+ * @param options - Optional request options
2257
+ */
2258
+ fetch<
2259
+ R = Any,
2260
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2261
+ const G extends string = string,
2262
+ >(
2263
+ query: G,
2264
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2265
+ options?: FilteredResponseQueryOptions,
2266
+ ): Promise<ClientReturn<G, R>>
2267
+ /**
2268
+ * Perform a GROQ-query against the configured dataset.
2269
+ *
2270
+ * @param query - GROQ-query to perform
2271
+ * @param params - Optional query parameters
2272
+ * @param options - Request options
2273
+ */
2274
+ fetch<
2275
+ R = Any,
2276
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2277
+ const G extends string = string,
2278
+ >(
2279
+ query: G,
2280
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2281
+ options: UnfilteredResponseQueryOptions,
2282
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
2283
+ /**
2284
+ * Perform a GROQ-query against the configured dataset.
2285
+ *
2286
+ * @param query - GROQ-query to perform
2287
+ * @param params - Optional query parameters
2288
+ * @param options - Request options
2289
+ */
2290
+ fetch<
2291
+ R = Any,
2292
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2293
+ const G extends string = string,
2294
+ >(
2295
+ query: G,
2296
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2297
+ options: UnfilteredResponseWithoutQuery,
2298
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2299
+ /**
2300
+ * Fetch a single document with the given ID.
2301
+ *
2302
+ * @param id - Document ID to fetch
2303
+ * @param options - Request options
2304
+ */
2305
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
2306
+ id: string,
2307
+ options?: {
2308
+ signal?: AbortSignal
2309
+ tag?: string
2310
+ },
2311
+ ): Promise<SanityDocument<R> | undefined>
2312
+ /**
2313
+ * Fetch multiple documents in one request.
2314
+ * Should be used sparingly - performing a query is usually a better option.
2315
+ * The order/position of documents is preserved based on the original array of IDs.
2316
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2317
+ *
2318
+ * @param ids - Document IDs to fetch
2319
+ * @param options - Request options
2320
+ */
2321
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2322
+ ids: string[],
2323
+ options?: {
2324
+ signal?: AbortSignal
2325
+ tag?: string
2326
+ },
2327
+ ): Promise<(SanityDocument<R> | null)[]>
2328
+ /**
2329
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2330
+ * Returns a promise that resolves to the created document.
2331
+ *
2332
+ * @param document - Document to create
2333
+ * @param options - Mutation options
2334
+ */
2335
+ create<R extends Record<string, Any> = Record<string, Any>>(
2336
+ document: SanityDocumentStub<R>,
2337
+ options: FirstDocumentMutationOptions,
2338
+ ): Promise<SanityDocument<R>>
2339
+ /**
2340
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2341
+ * Returns a promise that resolves to an array containing the created document.
2342
+ *
2343
+ * @param document - Document to create
2344
+ * @param options - Mutation options
2345
+ */
2346
+ create<R extends Record<string, Any> = Record<string, Any>>(
2347
+ document: SanityDocumentStub<R>,
2348
+ options: AllDocumentsMutationOptions,
2349
+ ): Promise<SanityDocument<R>[]>
2350
+ /**
2351
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2352
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2353
+ *
2354
+ * @param document - Document to create
2355
+ * @param options - Mutation options
2356
+ */
2357
+ create<R extends Record<string, Any> = Record<string, Any>>(
2358
+ document: SanityDocumentStub<R>,
2359
+ options: FirstDocumentIdMutationOptions,
2360
+ ): Promise<SingleMutationResult>
2361
+ /**
2362
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2363
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2364
+ *
2365
+ * @param document - Document to create
2366
+ * @param options - Mutation options
2367
+ */
2368
+ create<R extends Record<string, Any> = Record<string, Any>>(
2369
+ document: SanityDocumentStub<R>,
2370
+ options: AllDocumentIdsMutationOptions,
2371
+ ): Promise<MultipleMutationResult>
2372
+ /**
2373
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2374
+ * Returns a promise that resolves to the created document.
2375
+ *
2376
+ * @param document - Document to create
2377
+ * @param options - Mutation options
2378
+ */
2379
+ create<R extends Record<string, Any> = Record<string, Any>>(
2380
+ document: SanityDocumentStub<R>,
2381
+ options?: BaseMutationOptions,
2382
+ ): Promise<SanityDocument<R>>
2383
+ /**
2384
+ * Create a document if no document with the same ID already exists.
2385
+ * Returns a promise that resolves to the created document.
2386
+ *
2387
+ * @param document - Document to create
2388
+ * @param options - Mutation options
2389
+ */
2390
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2391
+ document: IdentifiedSanityDocumentStub<R>,
2392
+ options: FirstDocumentMutationOptions,
2393
+ ): Promise<SanityDocument<R>>
2394
+ /**
2395
+ * Create a document if no document with the same ID already exists.
2396
+ * Returns a promise that resolves to an array containing the created document.
2397
+ *
2398
+ * @param document - Document to create
2399
+ * @param options - Mutation options
2400
+ */
2401
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2402
+ document: IdentifiedSanityDocumentStub<R>,
2403
+ options: AllDocumentsMutationOptions,
2404
+ ): Promise<SanityDocument<R>[]>
2405
+ /**
2406
+ * Create a document if no document with the same ID already exists.
2407
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2408
+ *
2409
+ * @param document - Document to create
2410
+ * @param options - Mutation options
2411
+ */
2412
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2413
+ document: IdentifiedSanityDocumentStub<R>,
2414
+ options: FirstDocumentIdMutationOptions,
2415
+ ): Promise<SingleMutationResult>
2416
+ /**
2417
+ * Create a document if no document with the same ID already exists.
2418
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2419
+ *
2420
+ * @param document - Document to create
2421
+ * @param options - Mutation options
2422
+ */
2423
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2424
+ document: IdentifiedSanityDocumentStub<R>,
2425
+ options: AllDocumentIdsMutationOptions,
2426
+ ): Promise<MultipleMutationResult>
2427
+ /**
2428
+ * Create a document if no document with the same ID already exists.
2429
+ * Returns a promise that resolves to the created document.
2430
+ *
2431
+ * @param document - Document to create
2432
+ * @param options - Mutation options
2433
+ */
2434
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2435
+ document: IdentifiedSanityDocumentStub<R>,
2436
+ options?: BaseMutationOptions,
2437
+ ): Promise<SanityDocument<R>>
2438
+ /**
2439
+ * Create a document if it does not exist, or replace a document with the same document ID
2440
+ * Returns a promise that resolves to the created document.
2441
+ *
2442
+ * @param document - Document to either create or replace
2443
+ * @param options - Mutation options
2444
+ */
2445
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2446
+ document: IdentifiedSanityDocumentStub<R>,
2447
+ options: FirstDocumentMutationOptions,
2448
+ ): Promise<SanityDocument<R>>
2449
+ /**
2450
+ * Create a document if it does not exist, or replace a document with the same document ID
2451
+ * Returns a promise that resolves to an array containing the created document.
2452
+ *
2453
+ * @param document - Document to either create or replace
2454
+ * @param options - Mutation options
2455
+ */
2456
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2457
+ document: IdentifiedSanityDocumentStub<R>,
2458
+ options: AllDocumentsMutationOptions,
2459
+ ): Promise<SanityDocument<R>[]>
2460
+ /**
2461
+ * Create a document if it does not exist, or replace a document with the same document ID
2462
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
2463
+ *
2464
+ * @param document - Document to either create or replace
2465
+ * @param options - Mutation options
2466
+ */
2467
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2468
+ document: IdentifiedSanityDocumentStub<R>,
2469
+ options: FirstDocumentIdMutationOptions,
2470
+ ): Promise<SingleMutationResult>
2471
+ /**
2472
+ * Create a document if it does not exist, or replace a document with the same document ID
2473
+ * Returns a promise that resolves to a mutation result object containing the created document ID.
2474
+ *
2475
+ * @param document - Document to either create or replace
2476
+ * @param options - Mutation options
2477
+ */
2478
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2479
+ document: IdentifiedSanityDocumentStub<R>,
2480
+ options: AllDocumentIdsMutationOptions,
2481
+ ): Promise<MultipleMutationResult>
2482
+ /**
2483
+ * Create a document if it does not exist, or replace a document with the same document ID
2484
+ * Returns a promise that resolves to the created document.
2485
+ *
2486
+ * @param document - Document to either create or replace
2487
+ * @param options - Mutation options
2488
+ */
2489
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2490
+ document: IdentifiedSanityDocumentStub<R>,
2491
+ options?: BaseMutationOptions,
2492
+ ): Promise<SanityDocument<R>>
2493
+ /**
2494
+ * Deletes a document with the given document ID.
2495
+ * Returns a promise that resolves to the deleted document.
2496
+ *
2497
+ * @param id - Document ID to delete
2498
+ * @param options - Options for the mutation
2499
+ */
2500
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2501
+ id: string,
2502
+ options: FirstDocumentMutationOptions,
2503
+ ): Promise<SanityDocument<R>>
2504
+ /**
2505
+ * Deletes a document with the given document ID.
2506
+ * Returns a promise that resolves to an array containing the deleted document.
2507
+ *
2508
+ * @param id - Document ID to delete
2509
+ * @param options - Options for the mutation
2510
+ */
2511
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2512
+ id: string,
2513
+ options: AllDocumentsMutationOptions,
2514
+ ): Promise<SanityDocument<R>[]>
2515
+ /**
2516
+ * Deletes a document with the given document ID.
2517
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
2518
+ *
2519
+ * @param id - Document ID to delete
2520
+ * @param options - Options for the mutation
2521
+ */
2522
+ delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2523
+ /**
2524
+ * Deletes a document with the given document ID.
2525
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
2526
+ *
2527
+ * @param id - Document ID to delete
2528
+ * @param options - Options for the mutation
2529
+ */
2530
+ delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2531
+ /**
2532
+ * Deletes a document with the given document ID.
2533
+ * Returns a promise that resolves to the deleted document.
2534
+ *
2535
+ * @param id - Document ID to delete
2536
+ * @param options - Options for the mutation
2537
+ */
2538
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2539
+ id: string,
2540
+ options?: BaseMutationOptions,
2541
+ ): Promise<SanityDocument<R>>
2542
+ /**
2543
+ * Deletes one or more documents matching the given query or document ID.
2544
+ * Returns a promise that resolves to first deleted document.
2545
+ *
2546
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2547
+ * @param options - Options for the mutation
2548
+ */
2549
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2550
+ selection: MutationSelection,
2551
+ options: FirstDocumentMutationOptions,
2552
+ ): Promise<SanityDocument<R>>
2553
+ /**
2554
+ * Deletes one or more documents matching the given query or document ID.
2555
+ * Returns a promise that resolves to an array containing the deleted documents.
2556
+ *
2557
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2558
+ * @param options - Options for the mutation
2559
+ */
2560
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2561
+ selection: MutationSelection,
2562
+ options: AllDocumentsMutationOptions,
2563
+ ): Promise<SanityDocument<R>[]>
2564
+ /**
2565
+ * Deletes one or more documents matching the given query or document ID.
2566
+ * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
2567
+ *
2568
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2569
+ * @param options - Options for the mutation
2570
+ */
2571
+ delete(
2572
+ selection: MutationSelection,
2573
+ options: FirstDocumentIdMutationOptions,
2574
+ ): Promise<SingleMutationResult>
2575
+ /**
2576
+ * Deletes one or more documents matching the given query or document ID.
2577
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
2578
+ *
2579
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2580
+ * @param options - Options for the mutation
2581
+ */
2582
+ delete(
2583
+ selection: MutationSelection,
2584
+ options: AllDocumentIdsMutationOptions,
2585
+ ): Promise<MultipleMutationResult>
2586
+ /**
2587
+ * Deletes one or more documents matching the given query or document ID.
2588
+ * Returns a promise that resolves to first deleted document.
2589
+ *
2590
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2591
+ * @param options - Options for the mutation
2592
+ */
2593
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2594
+ selection: MutationSelection,
2595
+ options?: BaseMutationOptions,
2596
+ ): Promise<SanityDocument<R>>
2597
+ /**
2598
+ * Perform mutation operations against the configured dataset
2599
+ * Returns a promise that resolves to the first mutated document.
2600
+ *
2601
+ * @param operations - Mutation operations to execute
2602
+ * @param options - Mutation options
2603
+ */
2604
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2605
+ operations: Mutation<R>[] | Patch | Transaction,
2606
+ options: FirstDocumentMutationOptions,
2607
+ ): Promise<SanityDocument<R>>
2608
+ /**
2609
+ * Perform mutation operations against the configured dataset.
2610
+ * Returns a promise that resolves to an array of the mutated documents.
2611
+ *
2612
+ * @param operations - Mutation operations to execute
2613
+ * @param options - Mutation options
2614
+ */
2615
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2616
+ operations: Mutation<R>[] | Patch | Transaction,
2617
+ options: AllDocumentsMutationOptions,
2618
+ ): Promise<SanityDocument<R>[]>
2619
+ /**
2620
+ * Perform mutation operations against the configured dataset
2621
+ * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
2622
+ *
2623
+ * @param operations - Mutation operations to execute
2624
+ * @param options - Mutation options
2625
+ */
2626
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2627
+ operations: Mutation<R>[] | Patch | Transaction,
2628
+ options: FirstDocumentIdMutationOptions,
2629
+ ): Promise<SingleMutationResult>
2630
+ /**
2631
+ * Perform mutation operations against the configured dataset
2632
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
2633
+ *
2634
+ * @param operations - Mutation operations to execute
2635
+ * @param options - Mutation options
2636
+ */
2637
+ mutate<R extends Record<string, Any>>(
2638
+ operations: Mutation<R>[] | Patch | Transaction,
2639
+ options: AllDocumentIdsMutationOptions,
2640
+ ): Promise<MultipleMutationResult>
2641
+ /**
2642
+ * Perform mutation operations against the configured dataset
2643
+ * Returns a promise that resolves to the first mutated document.
2644
+ *
2645
+ * @param operations - Mutation operations to execute
2646
+ * @param options - Mutation options
2647
+ */
2648
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2649
+ operations: Mutation<R>[] | Patch | Transaction,
2650
+ options?: BaseMutationOptions,
2651
+ ): Promise<SanityDocument<R>>
2652
+ /**
2653
+ * Create a new buildable patch of operations to perform
2654
+ *
2655
+ * @param documentId - Document ID to patch
2656
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2657
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2658
+ */
2659
+ patch(documentId: string, operations?: PatchOperations): Patch
2660
+ /**
2661
+ * Create a new buildable patch of operations to perform
2662
+ *
2663
+ * @param documentIds - Array of document IDs to patch
2664
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2665
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2666
+ */
2667
+ patch(documentIds: string[], operations?: PatchOperations): Patch
2668
+ /**
2669
+ * Create a new buildable patch of operations to perform
2670
+ *
2671
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2672
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2673
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2674
+ */
2675
+ patch(selection: MutationSelection, operations?: PatchOperations): Patch
2676
+ /**
2677
+ * Create a new transaction of mutations
2678
+ *
2679
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
2680
+ */
2681
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
2682
+ operations?: Mutation<R>[],
2683
+ ): Transaction
2684
+ /**
2685
+ * Perform action operations against the configured dataset
2686
+ * Returns a promise that resolves to the transaction result
2687
+ *
2688
+ * @param operations - Action operation(s) to execute
2689
+ * @param options - Action options
2690
+ */
2691
+ action(
2692
+ operations: Action | Action[],
2693
+ options?: BaseActionOptions,
2694
+ ): Promise<SingleActionResult | MultipleActionResult>
2695
+ /**
2696
+ * Perform a request against the Sanity API
2697
+ * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
2698
+ *
2699
+ * @param options - Request options
2700
+ * @returns Promise resolving to the response body
2701
+ */
2702
+ request<R = Any>(options: RawRequestOptions): Promise<R>
2703
+ /**
2704
+ * Perform an HTTP request a `/data` sub-endpoint
2705
+ * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
2706
+ *
2707
+ * @deprecated - Use `request()` or your own HTTP library instead
2708
+ * @param endpoint - Endpoint to hit (mutate, query etc)
2709
+ * @param body - Request body
2710
+ * @param options - Request options
2711
+ * @internal
2712
+ */
2713
+ dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
2714
+ /**
2715
+ * Get a Sanity API URL for the URI provided
2716
+ *
2717
+ * @param uri - URI/path to build URL for
2718
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
2719
+ */
2720
+ getUrl(uri: string, canUseCdn?: boolean): string
2721
+ /**
2722
+ * Get a Sanity API URL for the data operation and path provided
2723
+ *
2724
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
2725
+ * @param path - Path to append after the operation
2726
+ */
2727
+ getDataUrl(operation: string, path?: string): string
2728
+ }
2729
+
2730
+ /** @internal */
2731
+ declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = {
2732
+ [P in keyof T]: T[P]
2733
+ } & {
2734
+ _id: string
2735
+ _rev: string
2736
+ _type: string
2737
+ _createdAt: string
2738
+ _updatedAt: string
2739
+ /**
2740
+ * Present when `perspective` is set to `previewDrafts`
2741
+ */
2742
+ _originalId?: string
2743
+ }
2744
+
2745
+ /** @public */
2746
+ declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
2747
+ [P in keyof T]: T[P]
2748
+ } & {
2749
+ _type: string
2750
+ }
2751
+
2752
+ /** @internal */
2753
+ declare interface SanityImageAssetDocument extends SanityAssetDocument {
2754
+ metadata: {
2755
+ _type: 'sanity.imageMetadata'
2756
+ hasAlpha: boolean
2757
+ isOpaque: boolean
2758
+ lqip?: string
2759
+ blurHash?: string
2760
+ dimensions: {
2761
+ _type: 'sanity.imageDimensions'
2762
+ aspectRatio: number
2763
+ height: number
2764
+ width: number
2765
+ }
2766
+ palette?: {
2767
+ _type: 'sanity.imagePalette'
2768
+ darkMuted?: SanityImagePalette
2769
+ darkVibrant?: SanityImagePalette
2770
+ dominant?: SanityImagePalette
2771
+ lightMuted?: SanityImagePalette
2772
+ lightVibrant?: SanityImagePalette
2773
+ muted?: SanityImagePalette
2774
+ vibrant?: SanityImagePalette
2775
+ }
2776
+ image?: {
2777
+ _type: 'sanity.imageExifTags'
2778
+ [key: string]: Any
2779
+ }
2780
+ exif?: {
2781
+ _type: 'sanity.imageExifMetadata'
2782
+ [key: string]: Any
2783
+ }
2784
+ }
2785
+ }
2786
+
2787
+ /** @internal */
2788
+ declare interface SanityImagePalette {
2789
+ background: string
2790
+ foreground: string
2791
+ population: number
2792
+ title: string
2793
+ }
2794
+
2795
+ /** @internal */
2796
+ declare interface SanityProject {
2797
+ id: string
2798
+ displayName: string
2799
+ /**
2800
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
2801
+ * @see https://www.sanity.io/help/studio-host-user-applications
2802
+ */
2803
+ studioHost: string | null
2804
+ organizationId: string | null
2805
+ isBlocked: boolean
2806
+ isDisabled: boolean
2807
+ isDisabledByUser: boolean
2808
+ createdAt: string
2809
+ pendingInvites?: number
2810
+ maxRetentionDays?: number
2811
+ members: SanityProjectMember[]
2812
+ metadata: {
2813
+ cliInitializedAt?: string
2814
+ color?: string
2815
+ /**
2816
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
2817
+ * @see https://www.sanity.io/help/studio-host-user-applications
2818
+ */
2819
+ externalStudioHost?: string
2820
+ }
2821
+ }
2822
+
2823
+ /** @internal */
2824
+ declare interface SanityProjectMember {
2825
+ id: string
2826
+ role: string
2827
+ isRobot: boolean
2828
+ isCurrentUser: boolean
2829
+ }
2830
+
2831
+ /** @public */
2832
+ declare interface SanityQueries {}
2833
+
2834
+ /** @internal */
2835
+ declare interface SanityUser {
2836
+ id: string
2837
+ projectId: string
2838
+ displayName: string
2839
+ familyName: string | null
2840
+ givenName: string | null
2841
+ middleName: string | null
2842
+ imageUrl: string | null
2843
+ createdAt: string
2844
+ updatedAt: string
2845
+ isCurrentUser: boolean
2846
+ }
2847
+
2848
+ /** @internal */
2849
+ declare interface SingleActionResult {
2850
+ transactionId: string
2851
+ }
2852
+
2853
+ /** @internal */
2854
+ declare interface SingleMutationResult {
2855
+ transactionId: string
2856
+ documentId: string
2857
+ results: {
2858
+ id: string
2859
+ operation: MutationOperation
2860
+ }[]
2861
+ }
2862
+
2863
+ /** @public */
2864
+ declare interface StegaConfig {
2865
+ /**
2866
+ * Enable or disable stega encoded strings in query results
2867
+ * ```ts
2868
+ {
2869
+ enabled: process.env.VERCEL_ENV !== 'production'
2870
+ }
2871
+ * ```
2872
+ * @defaultValue `false`
2873
+ */
2874
+ enabled?: boolean
2875
+ /**
2876
+ * Where the Studio is hosted.
2877
+ * If it's embedded in the app, use the base path for example `/studio`.
2878
+ * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
2879
+ *
2880
+ */
2881
+ studioUrl?: StudioUrl | ResolveStudioUrl
2882
+ filter?: FilterDefault
2883
+ /**
2884
+ * Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
2885
+ */
2886
+ logger?: Logger
2887
+ /**
2888
+ * Set to `true` to omit cross dataset reference specific data from encoded strings
2889
+ */
2890
+ omitCrossDatasetReferenceData?: boolean
2891
+ }
2892
+
2893
+ /** @public */
2894
+ declare type StegaConfigRequiredKeys = Extract<keyof StegaConfig, 'enabled'>
2895
+
2896
+ /** @alpha */
2897
+ declare type StudioBaseRoute = {
2898
+ baseUrl: StudioBaseUrl
2899
+ workspace?: string
2900
+ tool?: string
2901
+ }
2902
+
2903
+ /** @alpha */
2904
+ declare type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | string
2905
+
2906
+ /** @alpha */
2907
+ declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
2908
+
2909
+ /** @public */
2910
+ declare type SyncTag = `s1:${string}`
2911
+
2912
+ /** @public */
2913
+ declare class Transaction extends BaseTransaction {
2914
+ #private
2915
+ constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
2916
+ /**
2917
+ * Clones the transaction
2918
+ */
2919
+ clone(): Transaction
2920
+ /**
2921
+ * Commit the transaction, returning a promise that resolves to the first mutated document
2922
+ *
2923
+ * @param options - Options for the mutation operation
2924
+ */
2925
+ commit<R extends Record<string, Any>>(
2926
+ options: TransactionFirstDocumentMutationOptions,
2927
+ ): Promise<SanityDocument<R>>
2928
+ /**
2929
+ * Commit the transaction, returning a promise that resolves to an array of the mutated documents
2930
+ *
2931
+ * @param options - Options for the mutation operation
2932
+ */
2933
+ commit<R extends Record<string, Any>>(
2934
+ options: TransactionAllDocumentsMutationOptions,
2935
+ ): Promise<SanityDocument<R>[]>
2936
+ /**
2937
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2938
+ *
2939
+ * @param options - Options for the mutation operation
2940
+ */
2941
+ commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2942
+ /**
2943
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2944
+ *
2945
+ * @param options - Options for the mutation operation
2946
+ */
2947
+ commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2948
+ /**
2949
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2950
+ *
2951
+ * @param options - Options for the mutation operation
2952
+ */
2953
+ commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
2954
+ /**
2955
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2956
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2957
+ *
2958
+ * @param documentId - Document ID to perform the patch operation on
2959
+ * @param patchOps - Operations to perform, or a builder function
2960
+ */
2961
+ patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
2962
+ /**
2963
+ * Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
2964
+ *
2965
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2966
+ * @param patchOps - Operations to perform, or a builder function
2967
+ */
2968
+ patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
2969
+ /**
2970
+ * Adds the given patch instance to the transaction.
2971
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2972
+ *
2973
+ * @param patch - Patch to execute
2974
+ */
2975
+ patch(patch: Patch): this
2976
+ }
2977
+
2978
+ /** @internal */
2979
+ declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
2980
+ returnFirst?: false
2981
+ returnDocuments?: false
2982
+ }
2983
+
2984
+ /** @internal */
2985
+ declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
2986
+ returnFirst?: false
2987
+ returnDocuments: true
2988
+ }
2989
+
2990
+ /** @internal */
2991
+ declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
2992
+ returnFirst: true
2993
+ returnDocuments?: false
2994
+ }
2995
+
2996
+ /** @internal */
2997
+ declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
2998
+ returnFirst: true
2999
+ returnDocuments: true
3000
+ }
3001
+
3002
+ /** @public */
3003
+ declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
3004
+ filterResponse: false
3005
+ /**
3006
+ * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
3007
+ * backwards compatibility (on the client side, not from the content lake API).
3008
+ * Can also explicitly be set to `true`.
3009
+ */
3010
+ returnQuery?: true
3011
+ }
3012
+
3013
+ /**
3014
+ * When using `filterResponse: false`, but you do not wish to receive back the query from
3015
+ * the content lake API.
3016
+ *
3017
+ * @public
3018
+ */
3019
+ declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
3020
+ filterResponse: false
3021
+ returnQuery: false
3022
+ }
3023
+
3024
+ /**
3025
+ * Retract a published document.
3026
+ * If there is no draft version then this is created from the published version.
3027
+ * In either case the published version is deleted.
3028
+ *
3029
+ * @public
3030
+ */
3031
+ declare type UnpublishAction = {
3032
+ actionType: 'sanity.action.document.unpublish'
3033
+ /**
3034
+ * Draft document ID to replace the published document with
3035
+ */
3036
+ draftId: string
3037
+ /**
3038
+ * Published document ID to delete
3039
+ */
3040
+ publishedId: string
3041
+ }
3042
+
3043
+ /** @public */
3044
+ declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
3045
+
3046
+ /** @public */
3047
+ declare interface UploadClientConfig {
3048
+ /**
3049
+ * Optional request tag for the upload
3050
+ */
3051
+ tag?: string
3052
+ /**
3053
+ * Whether or not to preserve the original filename (default: true)
3054
+ */
3055
+ preserveFilename?: boolean
3056
+ /**
3057
+ * Filename for this file (optional)
3058
+ */
3059
+ filename?: string
3060
+ /**
3061
+ * Milliseconds to wait before timing the request out
3062
+ */
3063
+ timeout?: number
3064
+ /**
3065
+ * Mime type of the file
3066
+ */
3067
+ contentType?: string
3068
+ /**
3069
+ * Array of metadata parts to extract from asset
3070
+ */
3071
+ extract?: AssetMetadataType[]
3072
+ /**
3073
+ * Optional freeform label for the asset. Generally not used.
3074
+ */
3075
+ label?: string
3076
+ /**
3077
+ * Optional title for the asset
3078
+ */
3079
+ title?: string
3080
+ /**
3081
+ * Optional description for the asset
3082
+ */
3083
+ description?: string
3084
+ /**
3085
+ * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
3086
+ */
3087
+ creditLine?: string
3088
+ /**
3089
+ * Source data (when the asset is from an external service)
3090
+ */
3091
+ source?: {
3092
+ /**
3093
+ * The (u)id of the asset within the source, i.e. 'i-f323r1E'
3094
+ */
3095
+ id: string
3096
+ /**
3097
+ * The name of the source, i.e. 'unsplash'
3098
+ */
3099
+ name: string
3100
+ /**
3101
+ * A url to where to find the asset, or get more info about it in the source
3102
+ */
3103
+ url?: string
3104
+ }
3105
+ }
3106
+
3107
+ /** @beta */
3108
+ export declare function useApplyActions(): <TDocument extends SanityDocument_2>(
3109
+ action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
3110
+ options?: ApplyActionsOptions,
3111
+ ) => Promise<ActionsResult<TDocument>>
3112
+
61
3113
  /**
62
3114
  * @internal
63
3115
  * A React hook that subscribes to authentication state changes.
@@ -90,6 +3142,33 @@ export declare const useAuthState: () => AuthState
90
3142
  */
91
3143
  export declare const useAuthToken: () => string | null
92
3144
 
3145
+ /**
3146
+ * A React hook that provides a client that subscribes to changes in your application,
3147
+ * such as user authentication changes.
3148
+ *
3149
+ * @remarks
3150
+ * The hook uses `useSyncExternalStore` to safely subscribe to changes
3151
+ * and ensure consistency between server and client rendering.
3152
+ *
3153
+ * @returns A Sanity client
3154
+ *
3155
+ * @example
3156
+ * ```tsx
3157
+ * function MyComponent() {
3158
+ * const client = useClient()
3159
+ * const [document, setDocument] = useState(null)
3160
+ * useEffect(async () => {
3161
+ * const doc = client.fetch('*[_id == "myDocumentId"]')
3162
+ * setDocument(doc)
3163
+ * }, [])
3164
+ * return <div>{JSON.stringify(document) ?? 'Loading...'}</div>
3165
+ * }
3166
+ * ```
3167
+ *
3168
+ * @public
3169
+ */
3170
+ export declare function useClient(options: ClientOptions): SanityClient
3171
+
93
3172
  /**
94
3173
  * @TODO This should suspend! And possibly not return `null`?
95
3174
  *
@@ -114,6 +3193,20 @@ export declare const useAuthToken: () => string | null
114
3193
  */
115
3194
  export declare const useCurrentUser: () => CurrentUser | null
116
3195
 
3196
+ /** @beta */
3197
+ export declare function useDocument<
3198
+ TDocument extends SanityDocument_2,
3199
+ TPath extends JsonMatchPath<TDocument>,
3200
+ >(doc: string | DocumentHandle<TDocument>, path: TPath): JsonMatch<TDocument, TPath> | undefined
3201
+
3202
+ /** @beta */
3203
+ export declare function useDocument<TDocument extends SanityDocument_2>(
3204
+ doc: string | DocumentHandle<TDocument>,
3205
+ ): TDocument | null
3206
+
3207
+ /** @beta */
3208
+ export declare function useDocumentEvent(handler: (documentEvent: DocumentEvent) => void): void
3209
+
117
3210
  /**
118
3211
  * @public
119
3212
  *
@@ -167,6 +3260,25 @@ export declare const useCurrentUser: () => CurrentUser | null
167
3260
  */
168
3261
  export declare function useDocuments(options?: DocumentListOptions): DocumentCollection
169
3262
 
3263
+ /** @beta */
3264
+ export declare const useDocumentSyncStatus: (
3265
+ doc: string | DocumentHandle<SanityDocumentLike>,
3266
+ ) => boolean | undefined
3267
+
3268
+ /** @beta */
3269
+ export declare function useEditDocument<
3270
+ TDocument extends SanityDocument_2,
3271
+ TPath extends JsonMatchPath<TDocument>,
3272
+ >(
3273
+ doc: string | DocumentHandle<TDocument>,
3274
+ path: TPath,
3275
+ ): (nextValue: JsonMatch<TDocument, TPath>) => Promise<ActionsResult<TDocument>>
3276
+
3277
+ /** @beta */
3278
+ export declare function useEditDocument<TDocument extends SanityDocument_2>(
3279
+ doc: string | DocumentHandle<TDocument>,
3280
+ ): (nextValue: Partial<TDocument>) => Promise<ActionsResult<TDocument>>
3281
+
170
3282
  /**
171
3283
  * @internal
172
3284
  */
@@ -343,6 +3455,18 @@ export declare interface UsePreviewResults {
343
3455
  isPending: boolean
344
3456
  }
345
3457
 
3458
+ /** @public */
3459
+ declare class UsersClient {
3460
+ #private
3461
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3462
+ /**
3463
+ * Fetch a user by user ID
3464
+ *
3465
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
3466
+ */
3467
+ getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
3468
+ }
3469
+
346
3470
  /**
347
3471
  * `useSanityInstance` returns the current Sanity instance from the application context.
348
3472
  * This must be called from within a `SanityProvider` component.
@@ -372,6 +3496,17 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
372
3496
  onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
373
3497
  }
374
3498
 
3499
+ /**
3500
+ * The listener has been established, and will start receiving events.
3501
+ * Note that this is also emitted upon _reconnection_.
3502
+ *
3503
+ * @public
3504
+ */
3505
+ declare type WelcomeEvent = {
3506
+ type: 'welcome'
3507
+ listenerName: string
3508
+ }
3509
+
375
3510
  /**
376
3511
  * @internal
377
3512
  */