@sanity/client 0.0.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1225 -0
  3. package/dist/index.browser.cjs +1760 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.js +1737 -0
  6. package/dist/index.browser.js.map +1 -0
  7. package/dist/index.cjs +1769 -0
  8. package/dist/index.cjs.js +16 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +2234 -0
  11. package/dist/index.js +1746 -0
  12. package/dist/index.js.map +1 -0
  13. package/package.json +127 -0
  14. package/src/SanityClient.ts +1253 -0
  15. package/src/assets/AssetsClient.ts +191 -0
  16. package/src/config.ts +96 -0
  17. package/src/data/dataMethods.ts +416 -0
  18. package/src/data/encodeQueryString.ts +29 -0
  19. package/src/data/listen.ts +196 -0
  20. package/src/data/patch.ts +345 -0
  21. package/src/data/transaction.ts +358 -0
  22. package/src/datasets/DatasetsClient.ts +115 -0
  23. package/src/generateHelpUrl.ts +5 -0
  24. package/src/http/browserMiddleware.ts +1 -0
  25. package/src/http/errors.ts +68 -0
  26. package/src/http/nodeMiddleware.ts +11 -0
  27. package/src/http/request.ts +48 -0
  28. package/src/http/requestOptions.ts +33 -0
  29. package/src/index.browser.ts +28 -0
  30. package/src/index.ts +28 -0
  31. package/src/projects/ProjectsClient.ts +61 -0
  32. package/src/types.ts +575 -0
  33. package/src/users/UsersClient.ts +55 -0
  34. package/src/util/defaults.ts +10 -0
  35. package/src/util/getSelection.ts +21 -0
  36. package/src/util/once.ts +14 -0
  37. package/src/util/pick.ts +11 -0
  38. package/src/validators.ts +78 -0
  39. package/src/warnings.ts +30 -0
  40. package/umd/.gitkeep +1 -0
  41. package/umd/sanityClient.js +4840 -0
  42. package/umd/sanityClient.min.js +14 -0
@@ -0,0 +1,2234 @@
1
+ /// <reference types="node" />
2
+
3
+ import {Observable} from 'rxjs'
4
+ import {Requester} from 'get-it'
5
+
6
+ /** @internal */
7
+ export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
8
+ returnFirst: false
9
+ returnDocuments: false
10
+ }
11
+
12
+ /** @internal */
13
+ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
14
+ returnFirst: false
15
+ returnDocuments?: true
16
+ }
17
+
18
+ /**
19
+ * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
20
+ * @internal
21
+ */
22
+ export declare type Any = any
23
+
24
+ /** @public */
25
+ export declare type AssetMetadataType =
26
+ | 'location'
27
+ | 'exif'
28
+ | 'image'
29
+ | 'palette'
30
+ | 'lqip'
31
+ | 'blurhash'
32
+ | 'none'
33
+
34
+ /** @internal */
35
+ export declare class AssetsClient {
36
+ #private
37
+ constructor(client: SanityClient, httpRequest: HttpRequest)
38
+ /**
39
+ * Uploads a file asset to the configured dataset
40
+ *
41
+ * @param assetType - Asset type (file)
42
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
43
+ * @param options - Options to use for the upload
44
+ */
45
+ upload(
46
+ assetType: 'file',
47
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
48
+ options?: UploadClientConfig
49
+ ): Promise<SanityAssetDocument>
50
+ /**
51
+ * Uploads an image asset to the configured dataset
52
+ *
53
+ * @param assetType - Asset type (image)
54
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
55
+ * @param options - Options to use for the upload
56
+ */
57
+ upload(
58
+ assetType: 'image',
59
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
60
+ options?: UploadClientConfig
61
+ ): Promise<SanityImageAssetDocument>
62
+ /**
63
+ * Uploads a file or an image asset to the configured dataset
64
+ *
65
+ * @param assetType - Asset type (file/image)
66
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
67
+ * @param options - Options to use for the upload
68
+ */
69
+ upload(
70
+ assetType: 'file' | 'image',
71
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
72
+ options?: UploadClientConfig
73
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
74
+ }
75
+
76
+ /** @internal */
77
+ export declare type AttributeSet = {
78
+ [key: string]: Any
79
+ }
80
+
81
+ /** @internal */
82
+ export declare interface AuthProvider {
83
+ name: string
84
+ title: string
85
+ url: string
86
+ }
87
+
88
+ /** @internal */
89
+ export declare type AuthProviderResponse = {
90
+ providers: AuthProvider[]
91
+ }
92
+
93
+ /** @internal */
94
+ export declare type BaseMutationOptions = RequestOptions & {
95
+ visibility?: 'sync' | 'async' | 'deferred'
96
+ returnDocuments?: boolean
97
+ returnFirst?: boolean
98
+ dryRun?: boolean
99
+ autoGenerateArrayKeys?: boolean
100
+ skipCrossDatasetReferenceValidation?: boolean
101
+ }
102
+
103
+ /** @internal */
104
+ export declare class BasePatch {
105
+ protected selection: PatchSelection
106
+ protected operations: PatchOperations
107
+ constructor(selection: PatchSelection, operations?: PatchOperations)
108
+ /**
109
+ * Sets the given attributes to the document. Does NOT merge objects.
110
+ * The operation is added to the current patch, ready to be commited by `commit()`
111
+ *
112
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
113
+ */
114
+ set(attrs: AttributeSet): this
115
+ /**
116
+ * Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
117
+ * The operation is added to the current patch, ready to be commited by `commit()`
118
+ *
119
+ * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
120
+ */
121
+ setIfMissing(attrs: AttributeSet): this
122
+ /**
123
+ * Performs a "diff-match-patch" operation on the string attributes provided.
124
+ * The operation is added to the current patch, ready to be commited by `commit()`
125
+ *
126
+ * @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
127
+ */
128
+ diffMatchPatch(attrs: AttributeSet): this
129
+ /**
130
+ * Unsets the attribute paths provided.
131
+ * The operation is added to the current patch, ready to be commited by `commit()`
132
+ *
133
+ * @param attrs - Attribute paths to unset.
134
+ */
135
+ unset(attrs: string[]): this
136
+ /**
137
+ * 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.
138
+ *
139
+ * @param attrs - Object of attribute paths to increment, values representing the number to increment by.
140
+ */
141
+ inc(attrs: {[key: string]: number}): this
142
+ /**
143
+ * 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.
144
+ *
145
+ * @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
146
+ */
147
+ dec(attrs: {[key: string]: number}): this
148
+ /**
149
+ * Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
150
+ *
151
+ * @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
152
+ * @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
153
+ * @param items - Array of items to insert/replace
154
+ */
155
+ insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
156
+ /**
157
+ * Append the given items to the array at the given JSONPath
158
+ *
159
+ * @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
160
+ * @param items - Array of items to append to the array
161
+ */
162
+ append(selector: string, items: Any[]): this
163
+ /**
164
+ * Prepend the given items to the array at the given JSONPath
165
+ *
166
+ * @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
167
+ * @param items - Array of items to prepend to the array
168
+ */
169
+ prepend(selector: string, items: Any[]): this
170
+ /**
171
+ * Change the contents of an array by removing existing elements and/or adding new elements.
172
+ *
173
+ * @param selector - Attribute or JSONPath expression for array
174
+ * @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
175
+ * @param deleteCount - An integer indicating the number of old array elements to remove.
176
+ * @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.
177
+ */
178
+ splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
179
+ /**
180
+ * Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
181
+ *
182
+ * @param rev - Revision to lock the patch to
183
+ */
184
+ ifRevisionId(rev: string): this
185
+ /**
186
+ * Return a plain JSON representation of the patch
187
+ */
188
+ serialize(): PatchMutationOperation
189
+ /**
190
+ * Return a plain JSON representation of the patch
191
+ */
192
+ toJSON(): PatchMutationOperation
193
+ /**
194
+ * Clears the patch of all operations
195
+ */
196
+ reset(): this
197
+ protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
198
+ protected _set(op: keyof PatchOperations, props: Any): this
199
+ }
200
+
201
+ /** @internal */
202
+ export declare class BaseTransaction {
203
+ protected operations: Mutation[]
204
+ protected trxId?: string
205
+ constructor(operations?: Mutation[], transactionId?: string)
206
+ /**
207
+ * 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.
208
+ * The operation is added to the current transaction, ready to be commited by `commit()`
209
+ *
210
+ * @param doc - Document to create. Requires a `_type` property.
211
+ */
212
+ create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
213
+ /**
214
+ * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
215
+ * The operation is added to the current transaction, ready to be commited by `commit()`
216
+ *
217
+ * @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
218
+ */
219
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
220
+ doc: IdentifiedSanityDocumentStub<R>
221
+ ): this
222
+ /**
223
+ * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
224
+ * The operation is added to the current transaction, ready to be commited by `commit()`
225
+ *
226
+ * @param doc - Document to create or replace. Requires `_id` and `_type` properties.
227
+ */
228
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
229
+ doc: IdentifiedSanityDocumentStub<R>
230
+ ): this
231
+ /**
232
+ * Deletes the document with the given document ID
233
+ * The operation is added to the current transaction, ready to be commited by `commit()`
234
+ *
235
+ * @param documentId - Document ID to delete
236
+ */
237
+ delete(documentId: string): this
238
+ /**
239
+ * Gets the current transaction ID, if any
240
+ */
241
+ transactionId(): string | undefined
242
+ /**
243
+ * Set the ID of this transaction.
244
+ *
245
+ * @param id - Transaction ID
246
+ */
247
+ transactionId(id: string): this
248
+ /**
249
+ * Return a plain JSON representation of the transaction
250
+ */
251
+ serialize(): Mutation[]
252
+ /**
253
+ * Return a plain JSON representation of the transaction
254
+ */
255
+ toJSON(): Mutation[]
256
+ /**
257
+ * Clears the transaction of all operations
258
+ */
259
+ reset(): this
260
+ protected _add(mut: Mutation): this
261
+ }
262
+
263
+ /** @public */
264
+ export declare type ChannelErrorEvent = {
265
+ type: 'channelError'
266
+ message: string
267
+ }
268
+
269
+ /** @public */
270
+ export declare interface ClientConfig {
271
+ projectId?: string
272
+ dataset?: string
273
+ useCdn?: boolean
274
+ token?: string
275
+ apiHost?: string
276
+ apiVersion?: string
277
+ proxy?: string
278
+ requestTagPrefix?: string
279
+ ignoreBrowserTokenWarning?: boolean
280
+ withCredentials?: boolean
281
+ allowReconfigure?: boolean
282
+ timeout?: number
283
+ /**
284
+ * @deprecated Don't use
285
+ */
286
+ useProjectHostname?: boolean
287
+ /**
288
+ * @deprecated Don't use
289
+ */
290
+ requester?: Requester
291
+ /**
292
+ * Experimental, requires apiVersion: 'X' and will overlay drafts on top of published documents
293
+ * which lets you preview your query on what it'll look like after every document is published.
294
+ * @alpha
295
+ */
296
+ unstable_overlayDrafts?: boolean
297
+ }
298
+
299
+ /** @public */
300
+ export declare class ClientError extends Error {
301
+ response: ErrorProps['response']
302
+ statusCode: ErrorProps['statusCode']
303
+ responseBody: ErrorProps['responseBody']
304
+ details: ErrorProps['details']
305
+ constructor(res: Any)
306
+ }
307
+
308
+ /** @public */
309
+ export declare const createClient: (config: ClientConfig) => SanityClient
310
+
311
+ /** @internal */
312
+ export declare interface CurrentSanityUser {
313
+ id: string
314
+ name: string
315
+ email: string
316
+ profileImage: string | null
317
+ role: string
318
+ }
319
+
320
+ /** @internal */
321
+ export declare type DatasetAclMode = 'public' | 'private' | 'custom'
322
+
323
+ /** @internal */
324
+ export declare type DatasetResponse = {
325
+ datasetName: string
326
+ aclMode: DatasetAclMode
327
+ }
328
+
329
+ /** @internal */
330
+ export declare class DatasetsClient {
331
+ #private
332
+ constructor(client: SanityClient, httpRequest: HttpRequest)
333
+ /**
334
+ * Create a new dataset with the given name
335
+ *
336
+ * @param name - Name of the dataset to create
337
+ * @param options - Options for the dataset
338
+ */
339
+ create(
340
+ name: string,
341
+ options?: {
342
+ aclMode?: DatasetAclMode
343
+ }
344
+ ): Promise<DatasetResponse>
345
+ /**
346
+ * Edit a dataset with the given name
347
+ *
348
+ * @param name - Name of the dataset to edit
349
+ * @param options - New options for the dataset
350
+ */
351
+ edit(
352
+ name: string,
353
+ options?: {
354
+ aclMode?: DatasetAclMode
355
+ }
356
+ ): Promise<DatasetResponse>
357
+ /**
358
+ * Delete a dataset with the given name
359
+ *
360
+ * @param name - Name of the dataset to delete
361
+ */
362
+ delete(name: string): Promise<{
363
+ deleted: true
364
+ }>
365
+ /**
366
+ * Fetch a list of datasets for the configured project
367
+ */
368
+ list(): Promise<DatasetsResponse>
369
+ }
370
+
371
+ /** @internal */
372
+ export declare type DatasetsResponse = {
373
+ name: string
374
+ aclMode: DatasetAclMode
375
+ }[]
376
+
377
+ /**
378
+ * @public
379
+ * @deprecated Use the named export `createClient` instead of the `default` export
380
+ */
381
+ declare function deprecatedCreateClient(config: ClientConfig): SanityClient
382
+ export default deprecatedCreateClient
383
+
384
+ /** @public */
385
+ export declare type DisconnectEvent = {
386
+ type: 'disconnect'
387
+ reason: string
388
+ }
389
+
390
+ /** @public */
391
+ export declare interface ErrorProps {
392
+ message: string
393
+ response: Any
394
+ statusCode: number
395
+ responseBody: Any
396
+ details: Any
397
+ }
398
+
399
+ /** @internal */
400
+ export declare type FilteredResponseQueryOptions = RequestOptions & {
401
+ filterResponse?: true
402
+ }
403
+
404
+ /** @internal */
405
+ export declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
406
+ returnFirst?: true
407
+ returnDocuments: false
408
+ }
409
+
410
+ /** @internal */
411
+ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
412
+ returnFirst?: true
413
+ returnDocuments?: true
414
+ }
415
+
416
+ /** @public */
417
+ export declare type HttpRequest = {
418
+ defaultRequester: Requester
419
+ (options: RequestOptions, requester: Requester): ReturnType<Requester>
420
+ }
421
+
422
+ /** @public */
423
+ export declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
424
+
425
+ /** @public */
426
+ export declare type IdentifiedSanityDocumentStub<
427
+ T extends Record<string, Any> = Record<string, Any>
428
+ > = {
429
+ [P in keyof T]: T[P]
430
+ } & {
431
+ _id: string
432
+ } & SanityDocumentStub
433
+
434
+ /** @public */
435
+ export declare interface InitializedClientConfig extends ClientConfig {
436
+ apiHost: string
437
+ apiVersion: string
438
+ useProjectHostname: boolean
439
+ useCdn: boolean
440
+ /**
441
+ * @deprecated Internal, don't use
442
+ */
443
+ isDefaultApi: boolean
444
+ /**
445
+ * @deprecated Internal, don't use
446
+ */
447
+ url: string
448
+ /**
449
+ * @deprecated Internal, don't use
450
+ */
451
+ cdnUrl: string
452
+ }
453
+
454
+ /** @internal */
455
+ export declare type InsertPatch =
456
+ | {
457
+ before: string
458
+ items: Any[]
459
+ }
460
+ | {
461
+ after: string
462
+ items: Any[]
463
+ }
464
+ | {
465
+ replace: string
466
+ items: Any[]
467
+ }
468
+
469
+ /**
470
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
471
+ *
472
+ * @param query - GROQ-filter to listen to changes for
473
+ * @param params - Optional query parameters
474
+ * @param options - Listener options
475
+ * @internal
476
+ */
477
+ export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
478
+ this: SanityClient | ObservableSanityClient,
479
+ query: string,
480
+ params?: QueryParams
481
+ ): Observable<MutationEvent_2<R>>
482
+
483
+ /**
484
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
485
+ *
486
+ * @param query - GROQ-filter to listen to changes for
487
+ * @param params - Optional query parameters
488
+ * @param options - Listener options
489
+ * @internal
490
+ */
491
+ export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
492
+ this: SanityClient | ObservableSanityClient,
493
+ query: string,
494
+ params?: QueryParams,
495
+ options?: ListenOptions
496
+ ): Observable<ListenEvent<R>>
497
+
498
+ /** @public */
499
+ export declare type ListenEvent<R extends Record<string, Any>> =
500
+ | MutationEvent_2<R>
501
+ | ChannelErrorEvent
502
+ | DisconnectEvent
503
+ | ReconnectEvent
504
+ | WelcomeEvent
505
+
506
+ /** @public */
507
+ export declare type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
508
+
509
+ /** @public */
510
+ export declare interface ListenOptions {
511
+ includeResult?: boolean
512
+ includePreviousRevision?: boolean
513
+ visibility?: 'sync' | 'async' | 'query'
514
+ events?: ListenEventName[]
515
+ effectFormat?: 'mendoza'
516
+ tag?: string
517
+ }
518
+
519
+ /** @internal */
520
+ export declare interface MultipleMutationResult {
521
+ transactionId: string
522
+ documentIds: string[]
523
+ results: {
524
+ id: string
525
+ operation: MutationOperation
526
+ }[]
527
+ }
528
+
529
+ /** @public */
530
+ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
531
+ | {
532
+ create: SanityDocumentStub<R>
533
+ }
534
+ | {
535
+ createOrReplace: IdentifiedSanityDocumentStub<R>
536
+ }
537
+ | {
538
+ createIfNotExists: IdentifiedSanityDocumentStub<R>
539
+ }
540
+ | {
541
+ delete: MutationSelection
542
+ }
543
+ | {
544
+ patch: PatchMutationOperation
545
+ }
546
+
547
+ /** @public */
548
+ declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
549
+ type: 'mutation'
550
+ documentId: string
551
+ eventId: string
552
+ identity: string
553
+ mutations: Mutation[]
554
+ previousRev?: string
555
+ resultRev?: string
556
+ result?: SanityDocument<R>
557
+ previous?: SanityDocument<R> | null
558
+ effects?: {
559
+ apply: unknown[]
560
+ revert: unknown[]
561
+ }
562
+ timestamp: string
563
+ transactionId: string
564
+ transition: 'update' | 'appear' | 'disappear'
565
+ visibility: 'query' | 'transaction'
566
+ }
567
+ export {MutationEvent_2 as MutationEvent}
568
+
569
+ /** @internal */
570
+ export declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
571
+
572
+ /** @internal */
573
+ export declare type MutationSelection =
574
+ | {
575
+ query: string
576
+ params?: QueryParams
577
+ }
578
+ | {
579
+ id: string | string[]
580
+ }
581
+
582
+ /** @internal */
583
+ export declare class ObservableAssetsClient {
584
+ #private
585
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
586
+ /**
587
+ * Uploads a file asset to the configured dataset
588
+ *
589
+ * @param assetType - Asset type (file)
590
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
591
+ * @param options - Options to use for the upload
592
+ */
593
+ upload(
594
+ assetType: 'file',
595
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
596
+ options?: UploadClientConfig
597
+ ): Observable<
598
+ HttpRequestEvent<{
599
+ document: SanityAssetDocument
600
+ }>
601
+ >
602
+ /**
603
+ * Uploads an image asset to the configured dataset
604
+ *
605
+ * @param assetType - Asset type (image)
606
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
607
+ * @param options - Options to use for the upload
608
+ */
609
+ upload(
610
+ assetType: 'image',
611
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
612
+ options?: UploadClientConfig
613
+ ): Observable<
614
+ HttpRequestEvent<{
615
+ document: SanityImageAssetDocument
616
+ }>
617
+ >
618
+ /**
619
+ * Uploads a file or an image asset to the configured dataset
620
+ *
621
+ * @param assetType - Asset type (file/image)
622
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
623
+ * @param options - Options to use for the upload
624
+ */
625
+ upload(
626
+ assetType: 'file' | 'image',
627
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
628
+ options?: UploadClientConfig
629
+ ): Observable<
630
+ HttpRequestEvent<{
631
+ document: SanityAssetDocument | SanityImageAssetDocument
632
+ }>
633
+ >
634
+ }
635
+
636
+ /** @internal */
637
+ export declare class ObservableDatasetsClient {
638
+ #private
639
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
640
+ /**
641
+ * Create a new dataset with the given name
642
+ *
643
+ * @param name - Name of the dataset to create
644
+ * @param options - Options for the dataset
645
+ */
646
+ create(
647
+ name: string,
648
+ options?: {
649
+ aclMode?: DatasetAclMode
650
+ }
651
+ ): Observable<DatasetResponse>
652
+ /**
653
+ * Edit a dataset with the given name
654
+ *
655
+ * @param name - Name of the dataset to edit
656
+ * @param options - New options for the dataset
657
+ */
658
+ edit(
659
+ name: string,
660
+ options?: {
661
+ aclMode?: DatasetAclMode
662
+ }
663
+ ): Observable<DatasetResponse>
664
+ /**
665
+ * Delete a dataset with the given name
666
+ *
667
+ * @param name - Name of the dataset to delete
668
+ */
669
+ delete(name: string): Observable<{
670
+ deleted: true
671
+ }>
672
+ /**
673
+ * Fetch a list of datasets for the configured project
674
+ */
675
+ list(): Observable<DatasetsResponse>
676
+ }
677
+
678
+ /** @public */
679
+ export declare class ObservablePatch extends BasePatch {
680
+ #private
681
+ constructor(
682
+ selection: PatchSelection,
683
+ operations?: PatchOperations,
684
+ client?: ObservableSanityClient
685
+ )
686
+ /**
687
+ * Clones the patch
688
+ */
689
+ clone(): ObservablePatch
690
+ /**
691
+ * Commit the patch, returning an observable that produces the first patched document
692
+ *
693
+ * @param options - Options for the mutation operation
694
+ */
695
+ commit<R extends Record<string, Any> = Record<string, Any>>(
696
+ options: FirstDocumentMutationOptions
697
+ ): Observable<SanityDocument<R>>
698
+ /**
699
+ * Commit the patch, returning an observable that produces an array of the mutated documents
700
+ *
701
+ * @param options - Options for the mutation operation
702
+ */
703
+ commit<R extends Record<string, Any> = Record<string, Any>>(
704
+ options: AllDocumentsMutationOptions
705
+ ): Observable<SanityDocument<R>[]>
706
+ /**
707
+ * Commit the patch, returning an observable that produces a mutation result object
708
+ *
709
+ * @param options - Options for the mutation operation
710
+ */
711
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
712
+ /**
713
+ * Commit the patch, returning an observable that produces a mutation result object
714
+ *
715
+ * @param options - Options for the mutation operation
716
+ */
717
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
718
+ /**
719
+ * Commit the patch, returning an observable that produces the first patched document
720
+ *
721
+ * @param options - Options for the mutation operation
722
+ */
723
+ commit<R extends Record<string, Any> = Record<string, Any>>(
724
+ options?: BaseMutationOptions
725
+ ): Observable<SanityDocument<R>>
726
+ }
727
+
728
+ /** @public */
729
+ export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
730
+
731
+ /** @internal */
732
+ export declare class ObservableProjectsClient {
733
+ #private
734
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
735
+ /**
736
+ * Fetch a list of projects the authenticated user has access to
737
+ */
738
+ list(): Observable<SanityProject[]>
739
+ /**
740
+ * Fetch a project by project ID
741
+ *
742
+ * @param projectId - ID of the project to fetch
743
+ */
744
+ getById(projectId: string): Observable<SanityProject>
745
+ }
746
+
747
+ /** @public */
748
+ export declare class ObservableSanityClient {
749
+ #private
750
+ assets: ObservableAssetsClient
751
+ datasets: ObservableDatasetsClient
752
+ projects: ObservableProjectsClient
753
+ users: ObservableUsersClient
754
+ /**
755
+ * Instance properties
756
+ */
757
+ listen: typeof _listen
758
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
759
+ /**
760
+ * Clone the client - returns a new instance
761
+ */
762
+ clone(): ObservableSanityClient
763
+ /**
764
+ * Returns the current client configuration
765
+ */
766
+ config(): InitializedClientConfig
767
+ /**
768
+ * Reconfigure the client. Note that this _mutates_ the current client.
769
+ */
770
+ config(newConfig?: Partial<ClientConfig>): this
771
+ /**
772
+ * Clone the client with a new (partial) configuration.
773
+ *
774
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
775
+ */
776
+ withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
777
+ /**
778
+ * Perform a GROQ-query against the configured dataset.
779
+ *
780
+ * @param query - GROQ-query to perform
781
+ */
782
+ fetch<R = Any>(query: string): Observable<R>
783
+ /**
784
+ * Perform a GROQ-query against the configured dataset.
785
+ *
786
+ * @param query - GROQ-query to perform
787
+ * @param params - Query parameters
788
+ */
789
+ fetch<R = Any, Q = QueryParams>(query: string, params: Q): Observable<R>
790
+ /**
791
+ * Perform a GROQ-query against the configured dataset.
792
+ *
793
+ * @param query - GROQ-query to perform
794
+ * @param params - Query parameters
795
+ * @param options - Request options
796
+ */
797
+ fetch<R = Any, Q = QueryParams>(
798
+ query: string,
799
+ params: Q | undefined,
800
+ options: FilteredResponseQueryOptions
801
+ ): Observable<R>
802
+ /**
803
+ * Perform a GROQ-query against the configured dataset.
804
+ *
805
+ * @param query - GROQ-query to perform
806
+ * @param params - Query parameters
807
+ * @param options - Request options
808
+ */
809
+ fetch<R = Any, Q = QueryParams>(
810
+ query: string,
811
+ params: Q | undefined,
812
+ options: UnfilteredResponseQueryOptions
813
+ ): Observable<RawQueryResponse<R>>
814
+ /**
815
+ * Fetch a single document with the given ID.
816
+ *
817
+ * @param id - Document ID to fetch
818
+ * @param options - Request options
819
+ */
820
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
821
+ id: string,
822
+ options?: {
823
+ tag?: string
824
+ }
825
+ ): Observable<SanityDocument<R> | undefined>
826
+ /**
827
+ * Fetch multiple documents in one request.
828
+ * Should be used sparingly - performing a query is usually a better option.
829
+ * The order/position of documents is preserved based on the original array of IDs.
830
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
831
+ *
832
+ * @param ids - Document IDs to fetch
833
+ * @param options - Request options
834
+ */
835
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
836
+ ids: string[],
837
+ options?: {
838
+ tag?: string
839
+ }
840
+ ): Observable<(SanityDocument<R> | null)[]>
841
+ /**
842
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
843
+ * Returns an observable that resolves to the created document.
844
+ *
845
+ * @param document - Document to create
846
+ * @param options - Mutation options
847
+ */
848
+ create<R extends Record<string, Any> = Record<string, Any>>(
849
+ document: SanityDocumentStub<R>,
850
+ options: FirstDocumentMutationOptions
851
+ ): Observable<SanityDocument<R>>
852
+ /**
853
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
854
+ * Returns an observable that resolves to an array containing the created document.
855
+ *
856
+ * @param document - Document to create
857
+ * @param options - Mutation options
858
+ */
859
+ create<R extends Record<string, Any> = Record<string, Any>>(
860
+ document: SanityDocumentStub<R>,
861
+ options: AllDocumentsMutationOptions
862
+ ): Observable<SanityDocument<R>[]>
863
+ /**
864
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
865
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
866
+ *
867
+ * @param document - Document to create
868
+ * @param options - Mutation options
869
+ */
870
+ create<R extends Record<string, Any> = Record<string, Any>>(
871
+ document: SanityDocumentStub<R>,
872
+ options: FirstDocumentIdMutationOptions
873
+ ): Observable<SingleMutationResult>
874
+ /**
875
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
876
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
877
+ *
878
+ * @param document - Document to create
879
+ * @param options - Mutation options
880
+ */
881
+ create<R extends Record<string, Any> = Record<string, Any>>(
882
+ document: SanityDocumentStub<R>,
883
+ options: AllDocumentIdsMutationOptions
884
+ ): Observable<MultipleMutationResult>
885
+ /**
886
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
887
+ * Returns an observable that resolves to the created document.
888
+ *
889
+ * @param document - Document to create
890
+ * @param options - Mutation options
891
+ */
892
+ create<R extends Record<string, Any> = Record<string, Any>>(
893
+ document: SanityDocumentStub<R>,
894
+ options?: BaseMutationOptions
895
+ ): Observable<SanityDocument<R>>
896
+ /**
897
+ * Create a document if no document with the same ID already exists.
898
+ * Returns an observable that resolves to the created document.
899
+ *
900
+ * @param document - Document to create
901
+ * @param options - Mutation options
902
+ */
903
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
904
+ document: IdentifiedSanityDocumentStub<R>,
905
+ options: FirstDocumentMutationOptions
906
+ ): Observable<SanityDocument<R>>
907
+ /**
908
+ * Create a document if no document with the same ID already exists.
909
+ * Returns an observable that resolves to an array containing the created document.
910
+ *
911
+ * @param document - Document to create
912
+ * @param options - Mutation options
913
+ */
914
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
915
+ document: IdentifiedSanityDocumentStub<R>,
916
+ options: AllDocumentsMutationOptions
917
+ ): Observable<SanityDocument<R>[]>
918
+ /**
919
+ * Create a document if no document with the same ID already exists.
920
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
921
+ *
922
+ * @param document - Document to create
923
+ * @param options - Mutation options
924
+ */
925
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
926
+ document: IdentifiedSanityDocumentStub<R>,
927
+ options: FirstDocumentIdMutationOptions
928
+ ): Observable<SingleMutationResult>
929
+ /**
930
+ * Create a document if no document with the same ID already exists.
931
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
932
+ *
933
+ * @param document - Document to create
934
+ * @param options - Mutation options
935
+ */
936
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
937
+ document: IdentifiedSanityDocumentStub<R>,
938
+ options: AllDocumentIdsMutationOptions
939
+ ): Observable<MultipleMutationResult>
940
+ /**
941
+ * Create a document if no document with the same ID already exists.
942
+ * Returns an observable that resolves to the created document.
943
+ *
944
+ * @param document - Document to create
945
+ * @param options - Mutation options
946
+ */
947
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
948
+ document: IdentifiedSanityDocumentStub<R>,
949
+ options?: BaseMutationOptions
950
+ ): Observable<SanityDocument<R>>
951
+ /**
952
+ * Create a document if it does not exist, or replace a document with the same document ID
953
+ * Returns an observable that resolves to the created document.
954
+ *
955
+ * @param document - Document to either create or replace
956
+ * @param options - Mutation options
957
+ */
958
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
959
+ document: IdentifiedSanityDocumentStub<R>,
960
+ options: FirstDocumentMutationOptions
961
+ ): Observable<SanityDocument<R>>
962
+ /**
963
+ * Create a document if it does not exist, or replace a document with the same document ID
964
+ * Returns an observable that resolves to an array containing the created document.
965
+ *
966
+ * @param document - Document to either create or replace
967
+ * @param options - Mutation options
968
+ */
969
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
970
+ document: IdentifiedSanityDocumentStub<R>,
971
+ options: AllDocumentsMutationOptions
972
+ ): Observable<SanityDocument<R>[]>
973
+ /**
974
+ * Create a document if it does not exist, or replace a document with the same document ID
975
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
976
+ *
977
+ * @param document - Document to either create or replace
978
+ * @param options - Mutation options
979
+ */
980
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
981
+ document: IdentifiedSanityDocumentStub<R>,
982
+ options: FirstDocumentIdMutationOptions
983
+ ): Observable<SingleMutationResult>
984
+ /**
985
+ * Create a document if it does not exist, or replace a document with the same document ID
986
+ * Returns an observable that resolves to a mutation result object containing the created document ID.
987
+ *
988
+ * @param document - Document to either create or replace
989
+ * @param options - Mutation options
990
+ */
991
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
992
+ document: IdentifiedSanityDocumentStub<R>,
993
+ options: AllDocumentIdsMutationOptions
994
+ ): Observable<MultipleMutationResult>
995
+ /**
996
+ * Create a document if it does not exist, or replace a document with the same document ID
997
+ * Returns an observable that resolves to the created document.
998
+ *
999
+ * @param document - Document to either create or replace
1000
+ * @param options - Mutation options
1001
+ */
1002
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1003
+ document: IdentifiedSanityDocumentStub<R>,
1004
+ options?: BaseMutationOptions
1005
+ ): Observable<SanityDocument<R>>
1006
+ /**
1007
+ * Deletes a document with the given document ID.
1008
+ * Returns an observable that resolves to the deleted document.
1009
+ *
1010
+ * @param id - Document ID to delete
1011
+ * @param options - Options for the mutation
1012
+ */
1013
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1014
+ id: string,
1015
+ options: FirstDocumentMutationOptions
1016
+ ): Observable<SanityDocument<R>>
1017
+ /**
1018
+ * Deletes a document with the given document ID.
1019
+ * Returns an observable that resolves to an array containing the deleted document.
1020
+ *
1021
+ * @param id - Document ID to delete
1022
+ * @param options - Options for the mutation
1023
+ */
1024
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1025
+ id: string,
1026
+ options: AllDocumentsMutationOptions
1027
+ ): Observable<SanityDocument<R>[]>
1028
+ /**
1029
+ * Deletes a document with the given document ID.
1030
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1031
+ *
1032
+ * @param id - Document ID to delete
1033
+ * @param options - Options for the mutation
1034
+ */
1035
+ delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1036
+ /**
1037
+ * Deletes a document with the given document ID.
1038
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
1039
+ *
1040
+ * @param id - Document ID to delete
1041
+ * @param options - Options for the mutation
1042
+ */
1043
+ delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1044
+ /**
1045
+ * Deletes a document with the given document ID.
1046
+ * Returns an observable that resolves to the deleted document.
1047
+ *
1048
+ * @param id - Document ID to delete
1049
+ * @param options - Options for the mutation
1050
+ */
1051
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1052
+ id: string,
1053
+ options?: BaseMutationOptions
1054
+ ): Observable<SanityDocument<R>>
1055
+ /**
1056
+ * Deletes one or more documents matching the given query or document ID.
1057
+ * Returns an observable that resolves to first deleted document.
1058
+ *
1059
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1060
+ * @param options - Options for the mutation
1061
+ */
1062
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1063
+ selection: MutationSelection,
1064
+ options: FirstDocumentMutationOptions
1065
+ ): Observable<SanityDocument<R>>
1066
+ /**
1067
+ * Deletes one or more documents matching the given query or document ID.
1068
+ * Returns an observable that resolves to an array containing the deleted documents.
1069
+ *
1070
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1071
+ * @param options - Options for the mutation
1072
+ */
1073
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1074
+ selection: MutationSelection,
1075
+ options: AllDocumentsMutationOptions
1076
+ ): Observable<SanityDocument<R>[]>
1077
+ /**
1078
+ * Deletes one or more documents matching the given query or document ID.
1079
+ * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
1080
+ *
1081
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1082
+ * @param options - Options for the mutation
1083
+ */
1084
+ delete(
1085
+ selection: MutationSelection,
1086
+ options: FirstDocumentIdMutationOptions
1087
+ ): Observable<SingleMutationResult>
1088
+ /**
1089
+ * Deletes one or more documents matching the given query or document ID.
1090
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
1091
+ *
1092
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1093
+ * @param options - Options for the mutation
1094
+ */
1095
+ delete(
1096
+ selection: MutationSelection,
1097
+ options: AllDocumentIdsMutationOptions
1098
+ ): Observable<MultipleMutationResult>
1099
+ /**
1100
+ * Deletes one or more documents matching the given query or document ID.
1101
+ * Returns an observable that resolves to first deleted document.
1102
+ *
1103
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1104
+ * @param options - Options for the mutation
1105
+ */
1106
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1107
+ selection: MutationSelection,
1108
+ options?: BaseMutationOptions
1109
+ ): Observable<SanityDocument<R>>
1110
+ /**
1111
+ * Perform mutation operations against the configured dataset
1112
+ * Returns an observable that resolves to the first mutated document.
1113
+ *
1114
+ * @param operations - Mutation operations to execute
1115
+ * @param options - Mutation options
1116
+ */
1117
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1118
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1119
+ options: FirstDocumentMutationOptions
1120
+ ): Observable<SanityDocument<R>>
1121
+ /**
1122
+ * Perform mutation operations against the configured dataset.
1123
+ * Returns an observable that resolves to an array of the mutated documents.
1124
+ *
1125
+ * @param operations - Mutation operations to execute
1126
+ * @param options - Mutation options
1127
+ */
1128
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1129
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1130
+ options: AllDocumentsMutationOptions
1131
+ ): Observable<SanityDocument<R>[]>
1132
+ /**
1133
+ * Perform mutation operations against the configured dataset
1134
+ * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
1135
+ *
1136
+ * @param operations - Mutation operations to execute
1137
+ * @param options - Mutation options
1138
+ */
1139
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1140
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1141
+ options: FirstDocumentIdMutationOptions
1142
+ ): Observable<SingleMutationResult>
1143
+ /**
1144
+ * Perform mutation operations against the configured dataset
1145
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
1146
+ *
1147
+ * @param operations - Mutation operations to execute
1148
+ * @param options - Mutation options
1149
+ */
1150
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1151
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1152
+ options: AllDocumentIdsMutationOptions
1153
+ ): Observable<MultipleMutationResult>
1154
+ /**
1155
+ * Perform mutation operations against the configured dataset
1156
+ * Returns an observable that resolves to the first mutated document.
1157
+ *
1158
+ * @param operations - Mutation operations to execute
1159
+ * @param options - Mutation options
1160
+ */
1161
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1162
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1163
+ options?: BaseMutationOptions
1164
+ ): Observable<SanityDocument<R>>
1165
+ /**
1166
+ * Create a new buildable patch of operations to perform
1167
+ *
1168
+ * @param documentId - Document ID(s) to patch
1169
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1170
+ */
1171
+ patch(documentId: PatchSelection, operations?: PatchOperations): ObservablePatch
1172
+ /**
1173
+ * Create a new transaction of mutations
1174
+ *
1175
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
1176
+ */
1177
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
1178
+ operations?: Mutation<R>[]
1179
+ ): ObservableTransaction
1180
+ /**
1181
+ * DEPRECATED: Perform an HTTP request against the Sanity API
1182
+ *
1183
+ * @deprecated Use your own request library!
1184
+ * @param options - Request options
1185
+ */
1186
+ request<R = Any>(options: RawRequestOptions): Observable<R>
1187
+ /**
1188
+ * Get a Sanity API URL for the URI provided
1189
+ *
1190
+ * @param uri - URI/path to build URL for
1191
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1192
+ */
1193
+ getUrl(uri: string, canUseCdn?: boolean): string
1194
+ /**
1195
+ * Get a Sanity API URL for the data operation and path provided
1196
+ *
1197
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1198
+ * @param path - Path to append after the operation
1199
+ */
1200
+ getDataUrl(operation: string, path?: string): string
1201
+ }
1202
+
1203
+ /** @public */
1204
+ export declare class ObservableTransaction extends BaseTransaction {
1205
+ #private
1206
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
1207
+ /**
1208
+ * Clones the transaction
1209
+ */
1210
+ clone(): ObservableTransaction
1211
+ /**
1212
+ * Commit the transaction, returning an observable that produces the first mutated document
1213
+ *
1214
+ * @param options - Options for the mutation operation
1215
+ */
1216
+ commit<R extends Record<string, Any>>(
1217
+ options: TransactionFirstDocumentMutationOptions
1218
+ ): Observable<SanityDocument<R>>
1219
+ /**
1220
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
1221
+ *
1222
+ * @param options - Options for the mutation operation
1223
+ */
1224
+ commit<R extends Record<string, Any>>(
1225
+ options: TransactionAllDocumentsMutationOptions
1226
+ ): Observable<SanityDocument<R>[]>
1227
+ /**
1228
+ * Commit the transaction, returning an observable that produces a mutation result object
1229
+ *
1230
+ * @param options - Options for the mutation operation
1231
+ */
1232
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1233
+ /**
1234
+ * Commit the transaction, returning an observable that produces a mutation result object
1235
+ *
1236
+ * @param options - Options for the mutation operation
1237
+ */
1238
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1239
+ /**
1240
+ * Commit the transaction, returning an observable that produces a mutation result object
1241
+ *
1242
+ * @param options - Options for the mutation operation
1243
+ */
1244
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
1245
+ /**
1246
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
1247
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1248
+ *
1249
+ * @param documentId - Document ID to perform the patch operation on
1250
+ * @param patchOps - Operations to perform, or a builder function
1251
+ */
1252
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
1253
+ /**
1254
+ * Adds the given patch instance to the transaction.
1255
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1256
+ *
1257
+ * @param patch - ObservablePatch to execute
1258
+ */
1259
+ patch(patch: ObservablePatch): this
1260
+ }
1261
+
1262
+ /** @public */
1263
+ export declare class ObservableUsersClient {
1264
+ #private
1265
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1266
+ /**
1267
+ * Fetch a user by user ID
1268
+ *
1269
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
1270
+ */
1271
+ getById<T extends 'me' | string>(
1272
+ id: T
1273
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
1274
+ }
1275
+
1276
+ /** @public */
1277
+ export declare class Patch extends BasePatch {
1278
+ #private
1279
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
1280
+ /**
1281
+ * Clones the patch
1282
+ */
1283
+ clone(): Patch
1284
+ /**
1285
+ * Commit the patch, returning a promise that resolves to the first patched document
1286
+ *
1287
+ * @param options - Options for the mutation operation
1288
+ */
1289
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1290
+ options: FirstDocumentMutationOptions
1291
+ ): Promise<SanityDocument<R>>
1292
+ /**
1293
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
1294
+ *
1295
+ * @param options - Options for the mutation operation
1296
+ */
1297
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1298
+ options: AllDocumentsMutationOptions
1299
+ ): Promise<SanityDocument<R>[]>
1300
+ /**
1301
+ * Commit the patch, returning a promise that resolves to a mutation result object
1302
+ *
1303
+ * @param options - Options for the mutation operation
1304
+ */
1305
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
1306
+ /**
1307
+ * Commit the patch, returning a promise that resolves to a mutation result object
1308
+ *
1309
+ * @param options - Options for the mutation operation
1310
+ */
1311
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1312
+ /**
1313
+ * Commit the patch, returning a promise that resolves to the first patched document
1314
+ *
1315
+ * @param options - Options for the mutation operation
1316
+ */
1317
+ commit<R extends Record<string, Any> = Record<string, Any>>(
1318
+ options?: BaseMutationOptions
1319
+ ): Promise<SanityDocument<R>>
1320
+ }
1321
+
1322
+ /** @public */
1323
+ export declare type PatchBuilder = (patch: Patch) => Patch
1324
+
1325
+ /** @internal */
1326
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
1327
+
1328
+ /** @internal */
1329
+ export declare interface PatchOperations {
1330
+ set?: {
1331
+ [key: string]: Any
1332
+ }
1333
+ setIfMissing?: {
1334
+ [key: string]: Any
1335
+ }
1336
+ diffMatchPatch?: {
1337
+ [key: string]: Any
1338
+ }
1339
+ unset?: string[]
1340
+ inc?: {
1341
+ [key: string]: number
1342
+ }
1343
+ dec?: {
1344
+ [key: string]: number
1345
+ }
1346
+ insert?: InsertPatch
1347
+ ifRevisionID?: string
1348
+ }
1349
+
1350
+ /** @internal */
1351
+ export declare type PatchSelection = string | string[] | MutationSelection
1352
+
1353
+ /** @public */
1354
+ declare interface ProgressEvent_2 {
1355
+ type: 'progress'
1356
+ stage: 'upload' | 'download'
1357
+ percent: number
1358
+ total?: number
1359
+ loaded?: number
1360
+ lengthComputable: boolean
1361
+ }
1362
+ export {ProgressEvent_2 as ProgressEvent}
1363
+
1364
+ /** @internal */
1365
+ export declare class ProjectsClient {
1366
+ #private
1367
+ constructor(client: SanityClient, httpRequest: HttpRequest)
1368
+ /**
1369
+ * Fetch a list of projects the authenticated user has access to
1370
+ */
1371
+ list(): Promise<SanityProject[]>
1372
+ /**
1373
+ * Fetch a project by project ID
1374
+ *
1375
+ * @param projectId - ID of the project to fetch
1376
+ */
1377
+ getById(projectId: string): Promise<SanityProject>
1378
+ }
1379
+
1380
+ /** @public */
1381
+ export declare type QueryParams = {
1382
+ [key: string]: Any
1383
+ }
1384
+
1385
+ /** @internal */
1386
+ export declare interface RawQueryResponse<R> {
1387
+ q: string
1388
+ ms: number
1389
+ result: R
1390
+ }
1391
+
1392
+ /** @internal */
1393
+ export declare interface RawRequestOptions {
1394
+ url?: string
1395
+ uri?: string
1396
+ method?: string
1397
+ token?: string
1398
+ json?: boolean
1399
+ tag?: string
1400
+ useGlobalApi?: boolean
1401
+ withCredentials?: boolean
1402
+ query?: {
1403
+ [key: string]: string | string[]
1404
+ }
1405
+ headers?: {
1406
+ [key: string]: string
1407
+ }
1408
+ timeout?: number
1409
+ proxy?: string
1410
+ body?: Any
1411
+ maxRedirects?: number
1412
+ }
1413
+
1414
+ /** @public */
1415
+ export declare type ReconnectEvent = {
1416
+ type: 'reconnect'
1417
+ }
1418
+
1419
+ /** @public */
1420
+ export declare const requester: Requester
1421
+
1422
+ /** @internal */
1423
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
1424
+ url?: string
1425
+ uri?: string
1426
+ canUseCdn?: boolean
1427
+ tag?: string
1428
+ }
1429
+
1430
+ /** @public */
1431
+ export declare interface RequestOptions {
1432
+ timeout?: number
1433
+ token?: string
1434
+ tag?: string
1435
+ headers?: Record<string, string>
1436
+ method?: string
1437
+ query?: Any
1438
+ body?: Any
1439
+ signal?: AbortSignal
1440
+ }
1441
+
1442
+ /** @public */
1443
+ export declare interface ResponseEvent<T = unknown> {
1444
+ type: 'response'
1445
+ body: T
1446
+ url: string
1447
+ method: string
1448
+ statusCode: number
1449
+ statusMessage?: string
1450
+ headers: Record<string, string>
1451
+ }
1452
+
1453
+ /** @internal */
1454
+ export declare interface SanityAssetDocument extends SanityDocument {
1455
+ url: string
1456
+ path: string
1457
+ size: number
1458
+ assetId: string
1459
+ mimeType: string
1460
+ sha1hash: string
1461
+ extension: string
1462
+ uploadId?: string
1463
+ originalFilename?: string
1464
+ }
1465
+
1466
+ /** @public */
1467
+ export declare class SanityClient {
1468
+ #private
1469
+ assets: AssetsClient
1470
+ datasets: DatasetsClient
1471
+ projects: ProjectsClient
1472
+ users: UsersClient
1473
+ /**
1474
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
1475
+ */
1476
+ observable: ObservableSanityClient
1477
+ /**
1478
+ * Instance properties
1479
+ */
1480
+ listen: typeof _listen
1481
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
1482
+ /**
1483
+ * Clone the client - returns a new instance
1484
+ */
1485
+ clone(): SanityClient
1486
+ /**
1487
+ * Returns the current client configuration
1488
+ */
1489
+ config(): InitializedClientConfig
1490
+ /**
1491
+ * Reconfigure the client. Note that this _mutates_ the current client.
1492
+ */
1493
+ config(newConfig?: Partial<ClientConfig>): this
1494
+ /**
1495
+ * Clone the client with a new (partial) configuration.
1496
+ *
1497
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1498
+ */
1499
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
1500
+ /**
1501
+ * Perform a GROQ-query against the configured dataset.
1502
+ *
1503
+ * @param query - GROQ-query to perform
1504
+ */
1505
+ fetch<R = Any>(query: string): Promise<R>
1506
+ /**
1507
+ * Perform a GROQ-query against the configured dataset.
1508
+ *
1509
+ * @param query - GROQ-query to perform
1510
+ * @param params - Optional query parameters
1511
+ */
1512
+ fetch<R = Any, Q = QueryParams>(query: string, params: Q): Promise<R>
1513
+ /**
1514
+ * Perform a GROQ-query against the configured dataset.
1515
+ *
1516
+ * @param query - GROQ-query to perform
1517
+ * @param params - Optional query parameters
1518
+ * @param options - Request options
1519
+ */
1520
+ fetch<R = Any, Q = QueryParams>(
1521
+ query: string,
1522
+ params: Q | undefined,
1523
+ options: FilteredResponseQueryOptions
1524
+ ): Promise<R>
1525
+ /**
1526
+ * Perform a GROQ-query against the configured dataset.
1527
+ *
1528
+ * @param query - GROQ-query to perform
1529
+ * @param params - Optional query parameters
1530
+ * @param options - Request options
1531
+ */
1532
+ fetch<R = Any, Q = QueryParams>(
1533
+ query: string,
1534
+ params: Q | undefined,
1535
+ options: UnfilteredResponseQueryOptions
1536
+ ): Promise<RawQueryResponse<R>>
1537
+ /**
1538
+ * Fetch a single document with the given ID.
1539
+ *
1540
+ * @param id - Document ID to fetch
1541
+ * @param options - Request options
1542
+ */
1543
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
1544
+ id: string,
1545
+ options?: {
1546
+ tag?: string
1547
+ }
1548
+ ): Promise<SanityDocument<R> | undefined>
1549
+ /**
1550
+ * Fetch multiple documents in one request.
1551
+ * Should be used sparingly - performing a query is usually a better option.
1552
+ * The order/position of documents is preserved based on the original array of IDs.
1553
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
1554
+ *
1555
+ * @param ids - Document IDs to fetch
1556
+ * @param options - Request options
1557
+ */
1558
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
1559
+ ids: string[],
1560
+ options?: {
1561
+ tag?: string
1562
+ }
1563
+ ): Promise<(SanityDocument<R> | null)[]>
1564
+ /**
1565
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1566
+ * Returns a promise that resolves to the created document.
1567
+ *
1568
+ * @param document - Document to create
1569
+ * @param options - Mutation options
1570
+ */
1571
+ create<R extends Record<string, Any> = Record<string, Any>>(
1572
+ document: SanityDocumentStub<R>,
1573
+ options: FirstDocumentMutationOptions
1574
+ ): Promise<SanityDocument<R>>
1575
+ /**
1576
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1577
+ * Returns a promise that resolves to an array containing the created document.
1578
+ *
1579
+ * @param document - Document to create
1580
+ * @param options - Mutation options
1581
+ */
1582
+ create<R extends Record<string, Any> = Record<string, Any>>(
1583
+ document: SanityDocumentStub<R>,
1584
+ options: AllDocumentsMutationOptions
1585
+ ): Promise<SanityDocument<R>[]>
1586
+ /**
1587
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1588
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
1589
+ *
1590
+ * @param document - Document to create
1591
+ * @param options - Mutation options
1592
+ */
1593
+ create<R extends Record<string, Any> = Record<string, Any>>(
1594
+ document: SanityDocumentStub<R>,
1595
+ options: FirstDocumentIdMutationOptions
1596
+ ): Promise<SingleMutationResult>
1597
+ /**
1598
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1599
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
1600
+ *
1601
+ * @param document - Document to create
1602
+ * @param options - Mutation options
1603
+ */
1604
+ create<R extends Record<string, Any> = Record<string, Any>>(
1605
+ document: SanityDocumentStub<R>,
1606
+ options: AllDocumentIdsMutationOptions
1607
+ ): Promise<MultipleMutationResult>
1608
+ /**
1609
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1610
+ * Returns a promise that resolves to the created document.
1611
+ *
1612
+ * @param document - Document to create
1613
+ * @param options - Mutation options
1614
+ */
1615
+ create<R extends Record<string, Any> = Record<string, Any>>(
1616
+ document: SanityDocumentStub<R>,
1617
+ options?: BaseMutationOptions
1618
+ ): Promise<SanityDocument<R>>
1619
+ /**
1620
+ * Create a document if no document with the same ID already exists.
1621
+ * Returns a promise that resolves to the created document.
1622
+ *
1623
+ * @param document - Document to create
1624
+ * @param options - Mutation options
1625
+ */
1626
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1627
+ document: IdentifiedSanityDocumentStub<R>,
1628
+ options: FirstDocumentMutationOptions
1629
+ ): Promise<SanityDocument<R>>
1630
+ /**
1631
+ * Create a document if no document with the same ID already exists.
1632
+ * Returns a promise that resolves to an array containing the created document.
1633
+ *
1634
+ * @param document - Document to create
1635
+ * @param options - Mutation options
1636
+ */
1637
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1638
+ document: IdentifiedSanityDocumentStub<R>,
1639
+ options: AllDocumentsMutationOptions
1640
+ ): Promise<SanityDocument<R>[]>
1641
+ /**
1642
+ * Create a document if no document with the same ID already exists.
1643
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
1644
+ *
1645
+ * @param document - Document to create
1646
+ * @param options - Mutation options
1647
+ */
1648
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1649
+ document: IdentifiedSanityDocumentStub<R>,
1650
+ options: FirstDocumentIdMutationOptions
1651
+ ): Promise<SingleMutationResult>
1652
+ /**
1653
+ * Create a document if no document with the same ID already exists.
1654
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
1655
+ *
1656
+ * @param document - Document to create
1657
+ * @param options - Mutation options
1658
+ */
1659
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1660
+ document: IdentifiedSanityDocumentStub<R>,
1661
+ options: AllDocumentIdsMutationOptions
1662
+ ): Promise<MultipleMutationResult>
1663
+ /**
1664
+ * Create a document if no document with the same ID already exists.
1665
+ * Returns a promise that resolves to the created document.
1666
+ *
1667
+ * @param document - Document to create
1668
+ * @param options - Mutation options
1669
+ */
1670
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
1671
+ document: IdentifiedSanityDocumentStub<R>,
1672
+ options?: BaseMutationOptions
1673
+ ): Promise<SanityDocument<R>>
1674
+ /**
1675
+ * Create a document if it does not exist, or replace a document with the same document ID
1676
+ * Returns a promise that resolves to the created document.
1677
+ *
1678
+ * @param document - Document to either create or replace
1679
+ * @param options - Mutation options
1680
+ */
1681
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1682
+ document: IdentifiedSanityDocumentStub<R>,
1683
+ options: FirstDocumentMutationOptions
1684
+ ): Promise<SanityDocument<R>>
1685
+ /**
1686
+ * Create a document if it does not exist, or replace a document with the same document ID
1687
+ * Returns a promise that resolves to an array containing the created document.
1688
+ *
1689
+ * @param document - Document to either create or replace
1690
+ * @param options - Mutation options
1691
+ */
1692
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1693
+ document: IdentifiedSanityDocumentStub<R>,
1694
+ options: AllDocumentsMutationOptions
1695
+ ): Promise<SanityDocument<R>[]>
1696
+ /**
1697
+ * Create a document if it does not exist, or replace a document with the same document ID
1698
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
1699
+ *
1700
+ * @param document - Document to either create or replace
1701
+ * @param options - Mutation options
1702
+ */
1703
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1704
+ document: IdentifiedSanityDocumentStub<R>,
1705
+ options: FirstDocumentIdMutationOptions
1706
+ ): Promise<SingleMutationResult>
1707
+ /**
1708
+ * Create a document if it does not exist, or replace a document with the same document ID
1709
+ * Returns a promise that resolves to a mutation result object containing the created document ID.
1710
+ *
1711
+ * @param document - Document to either create or replace
1712
+ * @param options - Mutation options
1713
+ */
1714
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1715
+ document: IdentifiedSanityDocumentStub<R>,
1716
+ options: AllDocumentIdsMutationOptions
1717
+ ): Promise<MultipleMutationResult>
1718
+ /**
1719
+ * Create a document if it does not exist, or replace a document with the same document ID
1720
+ * Returns a promise that resolves to the created document.
1721
+ *
1722
+ * @param document - Document to either create or replace
1723
+ * @param options - Mutation options
1724
+ */
1725
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
1726
+ document: IdentifiedSanityDocumentStub<R>,
1727
+ options?: BaseMutationOptions
1728
+ ): Promise<SanityDocument<R>>
1729
+ /**
1730
+ * Deletes a document with the given document ID.
1731
+ * Returns a promise that resolves to the deleted document.
1732
+ *
1733
+ * @param id - Document ID to delete
1734
+ * @param options - Options for the mutation
1735
+ */
1736
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1737
+ id: string,
1738
+ options: FirstDocumentMutationOptions
1739
+ ): Promise<SanityDocument<R>>
1740
+ /**
1741
+ * Deletes a document with the given document ID.
1742
+ * Returns a promise that resolves to an array containing the deleted document.
1743
+ *
1744
+ * @param id - Document ID to delete
1745
+ * @param options - Options for the mutation
1746
+ */
1747
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1748
+ id: string,
1749
+ options: AllDocumentsMutationOptions
1750
+ ): Promise<SanityDocument<R>[]>
1751
+ /**
1752
+ * Deletes a document with the given document ID.
1753
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
1754
+ *
1755
+ * @param id - Document ID to delete
1756
+ * @param options - Options for the mutation
1757
+ */
1758
+ delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
1759
+ /**
1760
+ * Deletes a document with the given document ID.
1761
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
1762
+ *
1763
+ * @param id - Document ID to delete
1764
+ * @param options - Options for the mutation
1765
+ */
1766
+ delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1767
+ /**
1768
+ * Deletes a document with the given document ID.
1769
+ * Returns a promise that resolves to the deleted document.
1770
+ *
1771
+ * @param id - Document ID to delete
1772
+ * @param options - Options for the mutation
1773
+ */
1774
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1775
+ id: string,
1776
+ options?: BaseMutationOptions
1777
+ ): Promise<SanityDocument<R>>
1778
+ /**
1779
+ * Deletes one or more documents matching the given query or document ID.
1780
+ * Returns a promise that resolves to first deleted document.
1781
+ *
1782
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1783
+ * @param options - Options for the mutation
1784
+ */
1785
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1786
+ selection: MutationSelection,
1787
+ options: FirstDocumentMutationOptions
1788
+ ): Promise<SanityDocument<R>>
1789
+ /**
1790
+ * Deletes one or more documents matching the given query or document ID.
1791
+ * Returns a promise that resolves to an array containing the deleted documents.
1792
+ *
1793
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1794
+ * @param options - Options for the mutation
1795
+ */
1796
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1797
+ selection: MutationSelection,
1798
+ options: AllDocumentsMutationOptions
1799
+ ): Promise<SanityDocument<R>[]>
1800
+ /**
1801
+ * Deletes one or more documents matching the given query or document ID.
1802
+ * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
1803
+ *
1804
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1805
+ * @param options - Options for the mutation
1806
+ */
1807
+ delete(
1808
+ selection: MutationSelection,
1809
+ options: FirstDocumentIdMutationOptions
1810
+ ): Promise<SingleMutationResult>
1811
+ /**
1812
+ * Deletes one or more documents matching the given query or document ID.
1813
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
1814
+ *
1815
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1816
+ * @param options - Options for the mutation
1817
+ */
1818
+ delete(
1819
+ selection: MutationSelection,
1820
+ options: AllDocumentIdsMutationOptions
1821
+ ): Promise<MultipleMutationResult>
1822
+ /**
1823
+ * Deletes one or more documents matching the given query or document ID.
1824
+ * Returns a promise that resolves to first deleted document.
1825
+ *
1826
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1827
+ * @param options - Options for the mutation
1828
+ */
1829
+ delete<R extends Record<string, Any> = Record<string, Any>>(
1830
+ selection: MutationSelection,
1831
+ options?: BaseMutationOptions
1832
+ ): Promise<SanityDocument<R>>
1833
+ /**
1834
+ * Perform mutation operations against the configured dataset
1835
+ * Returns a promise that resolves to the first mutated document.
1836
+ *
1837
+ * @param operations - Mutation operations to execute
1838
+ * @param options - Mutation options
1839
+ */
1840
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1841
+ operations: Mutation<R>[] | Patch | Transaction,
1842
+ options: FirstDocumentMutationOptions
1843
+ ): Promise<SanityDocument<R>>
1844
+ /**
1845
+ * Perform mutation operations against the configured dataset.
1846
+ * Returns a promise that resolves to an array of the mutated documents.
1847
+ *
1848
+ * @param operations - Mutation operations to execute
1849
+ * @param options - Mutation options
1850
+ */
1851
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1852
+ operations: Mutation<R>[] | Patch | Transaction,
1853
+ options: AllDocumentsMutationOptions
1854
+ ): Promise<SanityDocument<R>[]>
1855
+ /**
1856
+ * Perform mutation operations against the configured dataset
1857
+ * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
1858
+ *
1859
+ * @param operations - Mutation operations to execute
1860
+ * @param options - Mutation options
1861
+ */
1862
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1863
+ operations: Mutation<R>[] | Patch | Transaction,
1864
+ options: FirstDocumentIdMutationOptions
1865
+ ): Promise<SingleMutationResult>
1866
+ /**
1867
+ * Perform mutation operations against the configured dataset
1868
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
1869
+ *
1870
+ * @param operations - Mutation operations to execute
1871
+ * @param options - Mutation options
1872
+ */
1873
+ mutate<R extends Record<string, Any>>(
1874
+ operations: Mutation<R>[] | Patch | Transaction,
1875
+ options: AllDocumentIdsMutationOptions
1876
+ ): Promise<MultipleMutationResult>
1877
+ /**
1878
+ * Perform mutation operations against the configured dataset
1879
+ * Returns a promise that resolves to the first mutated document.
1880
+ *
1881
+ * @param operations - Mutation operations to execute
1882
+ * @param options - Mutation options
1883
+ */
1884
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
1885
+ operations: Mutation<R>[] | Patch | Transaction,
1886
+ options?: BaseMutationOptions
1887
+ ): Promise<SanityDocument<R>>
1888
+ /**
1889
+ * Create a new buildable patch of operations to perform
1890
+ *
1891
+ * @param documentId - Document ID(s)to patch
1892
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1893
+ */
1894
+ patch(documentId: PatchSelection, operations?: PatchOperations): Patch
1895
+ /**
1896
+ * Create a new transaction of mutations
1897
+ *
1898
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
1899
+ */
1900
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
1901
+ operations?: Mutation<R>[]
1902
+ ): Transaction
1903
+ /**
1904
+ * DEPRECATED: Perform an HTTP request against the Sanity API
1905
+ *
1906
+ * @deprecated Use your own request library!
1907
+ * @param options - Request options
1908
+ */
1909
+ request<R = Any>(options: RawRequestOptions): Promise<R>
1910
+ /**
1911
+ * DEPRECATED: Perform an HTTP request a `/data` sub-endpoint
1912
+ *
1913
+ * @deprecated Use your own request library!
1914
+ * @param endpoint - Endpoint to hit (mutate, query etc)
1915
+ * @param body - Request body
1916
+ * @param options - Request options
1917
+ */
1918
+ dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
1919
+ /**
1920
+ * Get a Sanity API URL for the URI provided
1921
+ *
1922
+ * @param uri - URI/path to build URL for
1923
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1924
+ */
1925
+ getUrl(uri: string, canUseCdn?: boolean): string
1926
+ /**
1927
+ * Get a Sanity API URL for the data operation and path provided
1928
+ *
1929
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1930
+ * @param path - Path to append after the operation
1931
+ */
1932
+ getDataUrl(operation: string, path?: string): string
1933
+ }
1934
+
1935
+ /** @internal */
1936
+ export declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = {
1937
+ [P in keyof T]: T[P]
1938
+ } & {
1939
+ _id: string
1940
+ _rev: string
1941
+ _type: string
1942
+ _createdAt: string
1943
+ _updatedAt: string
1944
+ }
1945
+
1946
+ /** @public */
1947
+ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
1948
+ [P in keyof T]: T[P]
1949
+ } & {
1950
+ _type: string
1951
+ }
1952
+
1953
+ /** @internal */
1954
+ export declare interface SanityImageAssetDocument extends SanityAssetDocument {
1955
+ metadata: {
1956
+ _type: 'sanity.imageMetadata'
1957
+ hasAlpha: boolean
1958
+ isOpaque: boolean
1959
+ lqip?: string
1960
+ blurHash?: string
1961
+ dimensions: {
1962
+ _type: 'sanity.imageDimensions'
1963
+ aspectRatio: number
1964
+ height: number
1965
+ width: number
1966
+ }
1967
+ palette?: {
1968
+ _type: 'sanity.imagePalette'
1969
+ darkMuted?: SanityImagePalette
1970
+ darkVibrant?: SanityImagePalette
1971
+ dominant?: SanityImagePalette
1972
+ lightMuted?: SanityImagePalette
1973
+ lightVibrant?: SanityImagePalette
1974
+ muted?: SanityImagePalette
1975
+ vibrant?: SanityImagePalette
1976
+ }
1977
+ image?: {
1978
+ _type: 'sanity.imageExifTags'
1979
+ [key: string]: Any
1980
+ }
1981
+ exif?: {
1982
+ _type: 'sanity.imageExifMetadata'
1983
+ [key: string]: Any
1984
+ }
1985
+ }
1986
+ }
1987
+
1988
+ /** @internal */
1989
+ export declare interface SanityImagePalette {
1990
+ background: string
1991
+ foreground: string
1992
+ population: number
1993
+ title: string
1994
+ }
1995
+
1996
+ /** @internal */
1997
+ export declare interface SanityProject {
1998
+ id: string
1999
+ displayName: string
2000
+ studioHost: string | null
2001
+ organizationId: string | null
2002
+ isBlocked: boolean
2003
+ isDisabled: boolean
2004
+ isDisabledByUser: boolean
2005
+ createdAt: string
2006
+ pendingInvites?: number
2007
+ maxRetentionDays?: number
2008
+ members: SanityProjectMember[]
2009
+ metadata: {
2010
+ color?: string
2011
+ externalStudioHost?: string
2012
+ }
2013
+ }
2014
+
2015
+ /** @internal */
2016
+ export declare interface SanityProjectMember {
2017
+ id: string
2018
+ role: string
2019
+ isRobot: boolean
2020
+ isCurrentUser: boolean
2021
+ }
2022
+
2023
+ /** @internal */
2024
+ export declare interface SanityReference {
2025
+ _ref: string
2026
+ }
2027
+
2028
+ /** @internal */
2029
+ export declare interface SanityUser {
2030
+ id: string
2031
+ projectId: string
2032
+ displayName: string
2033
+ familyName: string | null
2034
+ givenName: string | null
2035
+ middleName: string | null
2036
+ imageUrl: string | null
2037
+ createdAt: string
2038
+ updatedAt: string
2039
+ isCurrentUser: boolean
2040
+ }
2041
+
2042
+ /** @public */
2043
+ export declare class ServerError extends Error {
2044
+ response: ErrorProps['response']
2045
+ statusCode: ErrorProps['statusCode']
2046
+ responseBody: ErrorProps['responseBody']
2047
+ details: ErrorProps['details']
2048
+ constructor(res: Any)
2049
+ }
2050
+
2051
+ /** @internal */
2052
+ export declare interface SingleMutationResult {
2053
+ transactionId: string
2054
+ documentId: string
2055
+ results: {
2056
+ id: string
2057
+ operation: MutationOperation
2058
+ }[]
2059
+ }
2060
+
2061
+ /** @public */
2062
+ export declare class Transaction extends BaseTransaction {
2063
+ #private
2064
+ constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
2065
+ /**
2066
+ * Clones the transaction
2067
+ */
2068
+ clone(): Transaction
2069
+ /**
2070
+ * Commit the transaction, returning a promise that resolves to the first mutated document
2071
+ *
2072
+ * @param options - Options for the mutation operation
2073
+ */
2074
+ commit<R extends Record<string, Any>>(
2075
+ options: TransactionFirstDocumentMutationOptions
2076
+ ): Promise<SanityDocument<R>>
2077
+ /**
2078
+ * Commit the transaction, returning a promise that resolves to an array of the mutated documents
2079
+ *
2080
+ * @param options - Options for the mutation operation
2081
+ */
2082
+ commit<R extends Record<string, Any>>(
2083
+ options: TransactionAllDocumentsMutationOptions
2084
+ ): Promise<SanityDocument<R>[]>
2085
+ /**
2086
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2087
+ *
2088
+ * @param options - Options for the mutation operation
2089
+ */
2090
+ commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2091
+ /**
2092
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2093
+ *
2094
+ * @param options - Options for the mutation operation
2095
+ */
2096
+ commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2097
+ /**
2098
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2099
+ *
2100
+ * @param options - Options for the mutation operation
2101
+ */
2102
+ commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
2103
+ /**
2104
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2105
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2106
+ *
2107
+ * @param documentId - Document ID to perform the patch operation on
2108
+ * @param patchOps - Operations to perform, or a builder function
2109
+ */
2110
+ patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
2111
+ /**
2112
+ * Adds the given patch instance to the transaction.
2113
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2114
+ *
2115
+ * @param patch - Patch to execute
2116
+ */
2117
+ patch(patch: Patch): this
2118
+ }
2119
+
2120
+ /** @internal */
2121
+ export declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
2122
+ returnFirst?: false
2123
+ returnDocuments?: false
2124
+ }
2125
+
2126
+ /** @internal */
2127
+ export declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
2128
+ returnFirst?: false
2129
+ returnDocuments: true
2130
+ }
2131
+
2132
+ /** @internal */
2133
+ export declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
2134
+ returnFirst: true
2135
+ returnDocuments?: false
2136
+ }
2137
+
2138
+ /** @internal */
2139
+ export declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
2140
+ returnFirst: true
2141
+ returnDocuments: true
2142
+ }
2143
+
2144
+ /** @internal */
2145
+ export declare type TransactionMutationOptions =
2146
+ | TransactionFirstDocumentMutationOptions
2147
+ | TransactionFirstDocumentIdMutationOptions
2148
+ | TransactionAllDocumentsMutationOptions
2149
+ | TransactionAllDocumentIdsMutationOptions
2150
+
2151
+ /** @internal */
2152
+ export declare type UnfilteredResponseQueryOptions = RequestOptions & {
2153
+ filterResponse: false
2154
+ }
2155
+
2156
+ /** @public */
2157
+ export declare interface UploadClientConfig {
2158
+ /**
2159
+ * Optional request tag for the upload
2160
+ */
2161
+ tag?: string
2162
+ /**
2163
+ * Whether or not to preserve the original filename (default: true)
2164
+ */
2165
+ preserveFilename?: boolean
2166
+ /**
2167
+ * Filename for this file (optional)
2168
+ */
2169
+ filename?: string
2170
+ /**
2171
+ * Milliseconds to wait before timing the request out
2172
+ */
2173
+ timeout?: number
2174
+ /**
2175
+ * Mime type of the file
2176
+ */
2177
+ contentType?: string
2178
+ /**
2179
+ * Array of metadata parts to extract from asset
2180
+ */
2181
+ extract?: AssetMetadataType[]
2182
+ /**
2183
+ * Optional freeform label for the asset. Generally not used.
2184
+ */
2185
+ label?: string
2186
+ /**
2187
+ * Optional title for the asset
2188
+ */
2189
+ title?: string
2190
+ /**
2191
+ * Optional description for the asset
2192
+ */
2193
+ description?: string
2194
+ /**
2195
+ * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
2196
+ */
2197
+ creditLine?: string
2198
+ /**
2199
+ * Source data (when the asset is from an external service)
2200
+ */
2201
+ source?: {
2202
+ /**
2203
+ * The (u)id of the asset within the source, i.e. 'i-f323r1E'
2204
+ */
2205
+ id: string
2206
+ /**
2207
+ * The name of the source, i.e. 'unsplash'
2208
+ */
2209
+ name: string
2210
+ /**
2211
+ * A url to where to find the asset, or get more info about it in the source
2212
+ */
2213
+ url?: string
2214
+ }
2215
+ }
2216
+
2217
+ /** @public */
2218
+ export declare class UsersClient {
2219
+ #private
2220
+ constructor(client: SanityClient, httpRequest: HttpRequest)
2221
+ /**
2222
+ * Fetch a user by user ID
2223
+ *
2224
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2225
+ */
2226
+ getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
2227
+ }
2228
+
2229
+ /** @public */
2230
+ export declare type WelcomeEvent = {
2231
+ type: 'welcome'
2232
+ }
2233
+
2234
+ export {}