@sanity/client 6.15.6 → 6.15.7

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