forked from sanity-io/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanityClient.d.ts
2256 lines (1998 loc) · 69.9 KB
/
sanityClient.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable no-dupe-class-members, @typescript-eslint/no-misused-new */
import type {Observable} from 'rxjs'
export type AssetMetadataType =
| 'location'
| 'exif'
| 'image'
| 'palette'
| 'lqip'
| 'blurhash'
| 'none'
export type DatasetAclMode = 'public' | 'private' | 'custom'
export type ListenVisibility = 'sync' | 'async' | 'query'
export type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
export type MutationOperation = 'create' | 'delete' | 'update' | 'none'
export interface ResponseEvent<T = unknown> {
type: 'response'
body: T
url: string
method: string
statusCode: number
statusMessage?: string
headers: Record<string, string>
}
export interface ProgressEvent {
type: 'progress'
stage: 'upload' | 'download'
percent: number
total?: number
loaded?: number
lengthComputable: boolean
}
type AttributeSet = {[key: string]: any}
type QueryParams = {[key: string]: any}
type MutationSelection = {query: string; params?: QueryParams} | {id: string}
type SanityReference = {_ref: string}
interface RawRequestOptions {
url?: string
uri?: string
method?: string
token?: string
json?: boolean
tag?: string
useGlobalApi?: boolean
withCredentials?: boolean
query?: {[key: string]: string | string[]}
headers?: {[key: string]: string}
timeout?: number
proxy?: string
body?: any
maxRedirects?: number
}
interface AuthProvider {
name: string
title: string
url: string
}
interface SanityUser {
id: string
projectId: string
displayName: string
familyName: string | null
givenName: string | null
middleName: string | null
imageUrl: string | null
createdAt: string
updatedAt: string
isCurrentUser: boolean
}
interface CurrentSanityUser {
id: string
name: string
email: string
profileImage: string | null
role: string
}
interface SanityProjectMember {
id: string
role: string
isRobot: boolean
isCurrentUser: boolean
}
interface SanityProject {
id: string
displayName: string
studioHost: string | null
organizationId: string | null
isBlocked: boolean
isDisabled: boolean
isDisabledByUser: boolean
createdAt: string
pendingInvites?: number
maxRetentionDays?: number
members: SanityProjectMember[]
metadata: {
color?: string
externalStudioHost?: string
}
}
type GetItRequester = {
use: (middleware: any) => GetItRequester
clone(): GetItRequester
}
export interface UploadOptions {
/**
* Optional request tag for the upload
*/
tag?: string
/**
* Whether or not to preserve the original filename (default: true)
*/
preserveFilename?: boolean
/**
* Filename for this file (optional)
*/
filename?: string
/**
* Milliseconds to wait before timing the request out
*/
timeout?: number
/**
* Mime type of the file
*/
contentType?: string
/**
* Array of metadata parts to extract from asset
*/
extract?: AssetMetadataType[]
/**
* Optional freeform label for the asset. Generally not used.
*/
label?: string
/**
* Optional title for the asset
*/
title?: string
/**
* Optional description for the asset
*/
description?: string
/**
* The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
*/
creditLine?: string
/**
* Source data (when the asset is from an external service)
*/
source?: {
/**
* The (u)id of the asset within the source, i.e. 'i-f323r1E'
*/
id: string
/**
* The name of the source, i.e. 'unsplash'
*/
name: string
/**
* A url to where to find the asset, or get more info about it in the source
*/
url?: string
}
}
export type InsertPatch =
| {before: string; items: any[]}
| {after: string; items: any[]}
| {replace: string; items: any[]}
// Note: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
export interface PatchOperations {
set?: {[key: string]: any}
setIfMissing?: {[key: string]: any}
diffMatchPatch?: {[key: string]: any}
unset?: string[]
inc?: {[key: string]: number}
dec?: {[key: string]: number}
insert?: InsertPatch
ifRevisionID?: string
}
export type PatchBuilder = (patch: Patch) => Patch
export type PatchMutationOperation = PatchOperations & MutationSelection
export type Mutation<R extends Record<string, any> = Record<string, any>> =
| {create: SanityDocumentStub<R>}
| {createOrReplace: IdentifiedSanityDocumentStub<R>}
| {createIfNotExists: IdentifiedSanityDocumentStub<R>}
| {delete: MutationSelection}
| {patch: PatchMutationOperation}
export interface SingleMutationResult {
transactionId: string
documentId: string
results: {id: string; operation: MutationOperation}[]
}
export interface MultipleMutationResult {
transactionId: string
documentIds: string[]
results: {id: string; operation: MutationOperation}[]
}
export abstract class BasePatch {
/**
* DEPRECATED: Don't use.
* The operation is added to the current patch, ready to be commited by `commit()`
*
* @deprecated
* @param attrs Attributes to replace
*/
replace(attrs: AttributeSet): this
/**
* Sets the given attributes to the document. Does NOT merge objects.
* The operation is added to the current patch, ready to be commited by `commit()`
*
* @param attrs Attributes to set. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "value"}
*/
set(attrs: AttributeSet): this
/**
* Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
* The operation is added to the current patch, ready to be commited by `commit()`
*
* @param attrs Attributes to set. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "value"}
*/
setIfMissing(attrs: AttributeSet): this
/**
* Performs a "diff-match-patch" operation on the string attributes provided.
* The operation is added to the current patch, ready to be commited by `commit()`
*
* @param attrs Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "dmp"}
*/
diffMatchPatch(attrs: AttributeSet): this
/**
* Unsets the attribute paths provided.
* The operation is added to the current patch, ready to be commited by `commit()`
*
* @param attrs Attribute paths to unset.
*/
unset(attrs: string[]): this
/**
* 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.
*
* @param attrs Object of attribute paths to increment, values representing the number to increment by.
*/
inc(attrs: {[key: string]: number}): this
/**
* 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.
*
* @param attrs Object of attribute paths to decrement, values representing the number to decrement by.
*/
dec(attrs: {[key: string]: number}): this
/**
* Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
*
* @param at Location to insert at, relative to the given selector, or 'replace' the matched path
* @param selector JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
* @param items Array of items to insert/replace
*/
insert(at: 'before' | 'after' | 'replace', selector: string, items: any[]): this
/**
* Append the given items to the array at the given JSONPath
*
* @param selector Attribute/path to append to, eg `comments` or `person.hobbies`
* @param items Array of items to append to the array
*/
append(selector: string, items: any[]): this
/**
* Prepend the given items to the array at the given JSONPath
*
* @param selector Attribute/path to prepend to, eg `comments` or `person.hobbies`
* @param items Array of items to prepend to the array
*/
prepend(selector: string, items: any[]): this
/**
* Change the contents of an array by removing existing elements and/or adding new elements.
*
* @param selector Attribute or JSONPath expression for array
* @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
* @param deleteCount An integer indicating the number of old array elements to remove.
* @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.
*/
splice(selector: string, start: number, deleteCount: number, items: any[]): this
/**
* Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
*
* @param rev Revision to lock the patch to
*/
ifRevisionId(rev: string): this
/**
* Return a plain JSON representation of the patch
*/
serialize(): PatchMutationOperation
/**
* Return a plain JSON representation of the patch
*/
toJSON(): PatchMutationOperation
/**
* Clears the patch of all operations
*/
reset(): this
}
export class Patch extends BasePatch {
constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
/**
* Clones the patch
*/
clone(): Patch
/**
* Commit the patch, returning a promise that resolves to the first patched document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options: FirstDocumentMutationOptions
): Promise<SanityDocument<R>>
/**
* Commit the patch, returning a promise that resolves to an array of the mutated documents
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options: AllDocumentsMutationOptions
): Promise<SanityDocument<R>[]>
/**
* Commit the patch, returning a promise that resolves to a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
/**
* Commit the patch, returning a promise that resolves to a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
/**
* Commit the patch, returning a promise that resolves to the first patched document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options?: BaseMutationOptions
): Promise<SanityDocument<R>>
}
export class ObservablePatch extends BasePatch {
constructor(documentId: string, operations?: PatchOperations, client?: ObservableSanityClient)
/**
* Clones the patch
*/
clone(): ObservablePatch
/**
* Commit the patch, returning an observable that produces the first patched document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options: FirstDocumentMutationOptions
): Observable<SanityDocument<R>>
/**
* Commit the patch, returning an observable that produces an array of the mutated documents
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options: AllDocumentsMutationOptions
): Observable<SanityDocument<R>[]>
/**
* Commit the patch, returning an observable that produces a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
/**
* Commit the patch, returning an observable that produces a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
/**
* Commit the patch, returning an observable that produces the first patched document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any> = Record<string, any>>(
options?: BaseMutationOptions
): Observable<SanityDocument<R>>
}
export abstract class BaseTransaction {
/**
* 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.
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param doc Document to create. Requires a `_type` property.
*/
create<R extends Record<string, any> = Record<string, any>>(doc: SanityDocumentStub<R>): this
/**
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param doc Document to create if it does not already exist. Requires `_id` and `_type` properties.
*/
createIfNotExists<R extends Record<string, any> = Record<string, any>>(
doc: IdentifiedSanityDocumentStub<R>
): this
/**
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param doc Document to create or replace. Requires `_id` and `_type` properties.
*/
createOrReplace<R extends Record<string, any> = Record<string, any>>(
doc: IdentifiedSanityDocumentStub<R>
): this
/**
* Deletes the document with the given document ID
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param documentId Document ID to delete
*/
delete(documentId: string): this
/**
* Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param documentId Document ID to perform the patch operation on
* @param patchOps Operations to perform, or a builder function
*/
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
/**
* Adds the given patch instance to the transaction.
* The operation is added to the current transaction, ready to be commited by `commit()`
*
* @param patch Patch to execute
*/
patch(patch: Patch): this
/**
* Set or gets the ID of this transaction.
* Should generally not be specified.
* If no ID is specified, the currently configured ID will be returned, if any.
*
* @param id Transaction ID
*/
transactionId<T extends string | undefined>(id: T): T extends string ? this : string | undefined
/**
* Return a plain JSON representation of the transaction
*/
serialize(): Mutation[]
/**
* Return a plain JSON representation of the transaction
*/
toJSON(): Mutation[]
/**
* Clears the transaction of all operations
*/
reset(): this
}
export class Transaction extends BaseTransaction {
constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
/**
* Clones the transaction
*/
clone(): Transaction
/**
* Commit the transaction, returning a promise that resolves to the first mutated document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any>>(
options: TransactionFirstDocumentMutationOptions
): Promise<SanityDocument<R>>
/**
* Commit the transaction, returning a promise that resolves to an array of the mutated documents
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any>>(
options: TransactionAllDocumentsMutationOptions
): Promise<SanityDocument<R>[]>
/**
* Commit the transaction, returning a promise that resolves to a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
/**
* Commit the transaction, returning a promise that resolves to a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
/**
* Commit the transaction, returning a promise that resolves to a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
}
export class ObservableTransaction extends BaseTransaction {
constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
/**
* Clones the transaction
*/
clone(): ObservableTransaction
/**
* Commit the transaction, returning an observable that produces the first mutated document
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any>>(
options: TransactionFirstDocumentMutationOptions
): Observable<SanityDocument<R>>
/**
* Commit the transaction, returning an observable that produces an array of the mutated documents
*
* @param options Options for the mutation operation
*/
commit<R extends Record<string, any>>(
options: TransactionAllDocumentsMutationOptions
): Observable<SanityDocument<R>[]>
/**
* Commit the transaction, returning an observable that produces a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
/**
* Commit the transaction, returning an observable that produces a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
/**
* Commit the transaction, returning an observable that produces a mutation result object
*
* @param options Options for the mutation operation
*/
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
}
export interface ClientConfig {
projectId?: string
dataset?: string
useCdn?: boolean
token?: string
apiHost?: string
apiVersion?: string
proxy?: string
requestTagPrefix?: string
ignoreBrowserTokenWarning?: boolean
withCredentials?: boolean
allowReconfigure?: boolean
timeout?: number
/**
* @deprecated Don't use
*/
useProjectHostname?: boolean
/**
* @deprecated Don't use
*/
requester?: GetItRequester
}
/**
* @deprecated Don't use
*/
export type ProjectlessClientConfig = ClientConfig & {useProjectHostname: false}
/**
* @deprecated Don't use
*/
export type ProjectClientConfig = ClientConfig & {
useProjectHostname?: true
projectId: string
}
export interface RequestOptions {
timeout?: number
token?: string
tag?: string
headers?: Record<string, string>
}
type BaseMutationOptions = RequestOptions & {
visibility?: 'sync' | 'async' | 'deferred'
returnDocuments?: boolean
returnFirst?: boolean
dryRun?: boolean
autoGenerateArrayKeys?: boolean
skipCrossDatasetReferenceValidation?: boolean
}
export type MutationEvent<R extends Record<string, any> = Record<string, any>> = {
type: 'mutation'
documentId: string
eventId: string
identity: string
mutations: Mutation[]
previousRev?: string
resultRev?: string
result?: SanityDocument<R>
previous?: SanityDocument<R> | null
effects?: {apply: unknown[]; revert: unknown[]}
timestamp: string
transactionId: string
transition: 'update' | 'appear' | 'disappear'
visibility: 'query' | 'transaction'
}
export type ChannelErrorEvent = {
type: 'channelError'
message: string
}
export type DisconnectEvent = {
type: 'disconnect'
reason: string
}
export type ReconnectEvent = {
type: 'reconnect'
}
export type WelcomeEvent = {
type: 'welcome'
}
export type ListenEvent<R extends Record<string, any>> =
| MutationEvent<R>
| ChannelErrorEvent
| DisconnectEvent
| ReconnectEvent
| WelcomeEvent
export interface ListenOptions {
includeResult?: boolean
includePreviousRevision?: boolean
visibility?: 'sync' | 'async' | 'query'
events?: ListenEventName[]
effectFormat?: 'mendoza'
tag?: string
}
export type PreviousNextListenOptions = ListenOptions & {
includeResult: true
includePreviousRevision: true
}
export type PreviousListenOptions = ListenOptions & {
includePreviousRevision: true
includeResult: false
}
export type NextListenOptions = ListenOptions & {
includePreviousRevision: false
includeResult: true
}
export type ResultlessListenOptions = ListenOptions & {
includeResult: false
includePreviousRevision: false
}
export type FilteredResponseQueryOptions = RequestOptions & {
filterResponse?: true
}
export type UnfilteredResponseQueryOptions = RequestOptions & {
filterResponse: false
}
export type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
type FirstDocumentMutationOptions = BaseMutationOptions & {
returnFirst?: true
returnDocuments?: true
}
type FirstDocumentIdMutationOptions = BaseMutationOptions & {
returnFirst?: true
returnDocuments: false
}
type AllDocumentsMutationOptions = BaseMutationOptions & {
returnFirst: false
returnDocuments?: true
}
type AllDocumentIdsMutationOptions = BaseMutationOptions & {
returnFirst: false
returnDocuments: false
}
export type MutationOptions =
| FirstDocumentMutationOptions
| FirstDocumentIdMutationOptions
| AllDocumentsMutationOptions
| AllDocumentIdsMutationOptions
type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
returnFirst: true
returnDocuments: true
}
type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
returnFirst: true
returnDocuments?: false
}
type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
returnFirst?: false
returnDocuments: true
}
type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
returnFirst?: false
returnDocuments?: false
}
export type TransactionMutationOptions =
| TransactionFirstDocumentMutationOptions
| TransactionFirstDocumentIdMutationOptions
| TransactionAllDocumentsMutationOptions
| TransactionAllDocumentIdsMutationOptions
export interface RawQueryResponse<R> {
q: string
ms: number
result: R
}
export type SanityDocument<T extends Record<string, any> = Record<string, any>> = {
[P in keyof T]: T[P]
} & {
_id: string
_rev: string
_type: string
_createdAt: string
_updatedAt: string
}
export type SanityDocumentStub<T extends Record<string, any> = Record<string, any>> = {
[P in keyof T]: T[P]
} & {
_type: string
}
export type IdentifiedSanityDocumentStub<T extends Record<string, any> = Record<string, any>> = {
[P in keyof T]: T[P]
} & {
_id: string
} & SanityDocumentStub
export interface SanityAssetDocument extends SanityDocument {
url: string
path: string
size: number
assetId: string
mimeType: string
sha1hash: string
extension: string
uploadId?: string
originalFilename?: string
}
export interface SanityImagePalette {
background: string
foreground: string
population: number
title: string
}
export interface SanityImageAssetDocument extends SanityAssetDocument {
metadata: {
_type: 'sanity.imageMetadata'
hasAlpha: boolean
isOpaque: boolean
lqip?: string
blurHash?: string
dimensions: {
_type: 'sanity.imageDimensions'
aspectRatio: number
height: number
width: number
}
palette?: {
_type: 'sanity.imagePalette'
darkMuted?: SanityImagePalette
darkVibrant?: SanityImagePalette
dominant?: SanityImagePalette
lightMuted?: SanityImagePalette
lightVibrant?: SanityImagePalette
muted?: SanityImagePalette
vibrant?: SanityImagePalette
}
image?: {
_type: 'sanity.imageExifTags'
[key: string]: any
}
exif?: {
_type: 'sanity.imageExifMetadata'
[key: string]: any
}
}
}
export class ClientError extends Error {
response: any
statusCode: number
responseBody?: any
details?: any
}
export class ServerError extends Error {
response: any
statusCode: number
responseBody?: any
details?: any
}
export class ObservableSanityClient {
static Patch: typeof Patch
static Transaction: typeof Transaction
static ClientError: typeof ClientError
static ServerError: typeof ServerError
static requester: GetItRequester
// Client/configuration
constructor(config: ClientConfig)
/**
* Clone the client - returns a new instance
*/
clone(): ObservableSanityClient
/**
* Returns the current client configuration
*/
config(): ClientConfig
/**
* Reconfigure the client. Note that this _mutates_ the current client.
*
* @param newConfig New client configuration properties
*/
config(newConfig?: Partial<ClientConfig>): this
/**
* Clone the client with a new (partial) configuration.
*
* @param newConfig New client configuration properties, shallowly merged with existing configuration
*/
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
/**
* @deprecated Use `client.config()` instead
*/
clientConfig: ClientConfig
assets: {
/**
* Uploads a file asset to the configured dataset
*
* @param assetType Asset type (file/image)
* @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
* @param options Options to use for the upload
*/
upload(
assetType: 'file' | 'image',
body: File | Blob | Buffer | ReadableStream,
options?: UploadOptions
): Observable<
ResponseEvent<{document: SanityAssetDocument | SanityImageAssetDocument}> | ProgressEvent
>
/**
* Uploads a file asset to the configured dataset
*
* @param assetType Asset type (file/image)
* @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
* @param options Options to use for the upload
*/
upload(
assetType: 'file',
body: File | Blob | Buffer | ReadableStream,
options?: UploadOptions
): Observable<ResponseEvent<{document: SanityAssetDocument}> | ProgressEvent>
/**
* Uploads an image asset to the configured dataset
*
* @param assetType Asset type (file/image)
* @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
* @param options Options to use for the upload
*/
upload(
assetType: 'image',
body: File | Blob | Buffer | ReadableStream,
options?: UploadOptions
): Observable<ResponseEvent<{document: SanityImageAssetDocument}> | ProgressEvent>
/**
* DEPRECATED: Deletes an asset of the given type and ID
*
* @deprecated Use `client.delete(assetDocumentId)` instead
* @param assetType Asset type (file/image)
* @param id Document ID or asset document to delete
*/
delete(
assetType: 'file' | 'image',
id: string | IdentifiedSanityDocumentStub
): Observable<SanityAssetDocument | undefined>
/**
* DEPRECATED: Returns the URL for an asset with a given document ID
*
* @deprecated Use the `@sanity/image-url` module instead
* @param id Document ID or asset reference to get URL for
* @param query Optional object of query string parameters to append
*/
getImageUrl(id: string | SanityReference, query: {[key: string]: string | number}): string
}