@sanity/client 4.0.0-alpha.esm.6 → 4.0.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 (68) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +23 -16
  3. package/dist/{browser/sanityClient.js → sanityClient.browser.mjs} +305 -1513
  4. package/dist/sanityClient.browser.mjs.map +7 -0
  5. package/index.js +7 -0
  6. package/lib/assets/assetsClient.js +100 -141
  7. package/lib/auth/authClient.js +20 -35
  8. package/lib/config.js +21 -43
  9. package/lib/data/dataMethods.js +32 -55
  10. package/lib/data/encodeQueryString.js +9 -15
  11. package/lib/data/listen.js +24 -53
  12. package/lib/data/patch.js +114 -167
  13. package/lib/data/transaction.js +95 -139
  14. package/lib/datasets/datasetsClient.js +31 -56
  15. package/lib/generateHelpUrl.js +11 -0
  16. package/lib/http/browserMiddleware.js +4 -3
  17. package/lib/http/errors.js +9 -15
  18. package/lib/http/nodeMiddleware.js +6 -10
  19. package/lib/http/queryString.js +4 -7
  20. package/lib/http/request.js +14 -28
  21. package/lib/http/requestOptions.js +7 -10
  22. package/lib/projects/projectsClient.js +19 -34
  23. package/lib/sanityClient.js +98 -153
  24. package/lib/users/usersClient.js +14 -27
  25. package/lib/util/defaults.js +6 -8
  26. package/lib/util/getSelection.js +3 -5
  27. package/lib/util/observable.js +0 -3
  28. package/lib/util/once.js +4 -6
  29. package/lib/util/pick.js +4 -6
  30. package/lib/validators.js +0 -26
  31. package/lib/warnings.js +9 -13
  32. package/package.json +49 -38
  33. package/sanityClient.d.ts +256 -99
  34. package/umd/sanityClient.js +165 -103
  35. package/umd/sanityClient.min.js +1 -1
  36. package/dist/node/sanityClient.js +0 -969
  37. package/src/assets/assetsClient.js +0 -132
  38. package/src/auth/authClient.js +0 -13
  39. package/src/config.js +0 -93
  40. package/src/data/dataMethods.js +0 -182
  41. package/src/data/encodeQueryString.js +0 -18
  42. package/src/data/listen.js +0 -159
  43. package/src/data/patch.js +0 -119
  44. package/src/data/transaction.js +0 -103
  45. package/src/datasets/datasetsClient.js +0 -28
  46. package/src/http/browserMiddleware.js +0 -1
  47. package/src/http/errors.js +0 -53
  48. package/src/http/nodeMiddleware.js +0 -11
  49. package/src/http/queryString.js +0 -10
  50. package/src/http/request.js +0 -50
  51. package/src/http/requestOptions.js +0 -29
  52. package/src/projects/projectsClient.js +0 -13
  53. package/src/sanityClient.js +0 -124
  54. package/src/users/usersClient.js +0 -9
  55. package/src/util/defaults.js +0 -9
  56. package/src/util/getSelection.js +0 -17
  57. package/src/util/observable.js +0 -6
  58. package/src/util/once.js +0 -12
  59. package/src/util/pick.js +0 -9
  60. package/src/validators.js +0 -76
  61. package/src/warnings.js +0 -25
  62. package/test/client.test.js +0 -2561
  63. package/test/encodeQueryString.test.js +0 -38
  64. package/test/fixtures/horsehead-nebula.jpg +0 -0
  65. package/test/fixtures/pdf-sample.pdf +0 -0
  66. package/test/helpers/sseServer.js +0 -27
  67. package/test/listen.test.js +0 -207
  68. package/test/warnings.test.disabled.js +0 -84
package/sanityClient.d.ts CHANGED
@@ -12,6 +12,7 @@ export type AssetMetadataType =
12
12
  export type DatasetAclMode = 'public' | 'private' | 'custom'
13
13
  export type ListenVisibility = 'sync' | 'async' | 'query'
14
14
  export type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
15
+ export type MutationOperation = 'create' | 'delete' | 'update' | 'none'
15
16
 
16
17
  export interface ResponseEvent<T = unknown> {
17
18
  type: 'response'
@@ -34,7 +35,7 @@ export interface ProgressEvent {
34
35
 
35
36
  type AttributeSet = {[key: string]: any}
36
37
  type QueryParams = {[key: string]: any}
37
- type MutationSelection = {query: string} | {id: string}
38
+ type MutationSelection = {query: string; params?: QueryParams} | {id: string}
38
39
  type SanityReference = {_ref: string}
39
40
 
40
41
  interface RawRequestOptions {
@@ -204,7 +205,7 @@ export type PatchBuilder = (patch: Patch) => Patch
204
205
 
205
206
  export type PatchMutationOperation = PatchOperations & MutationSelection
206
207
 
207
- export type Mutation<R = any> =
208
+ export type Mutation<R extends Record<string, any> = Record<string, any>> =
208
209
  | {create: SanityDocumentStub<R>}
209
210
  | {createOrReplace: IdentifiedSanityDocumentStub<R>}
210
211
  | {createIfNotExists: IdentifiedSanityDocumentStub<R>}
@@ -214,23 +215,16 @@ export type Mutation<R = any> =
214
215
  export interface SingleMutationResult {
215
216
  transactionId: string
216
217
  documentId: string
217
- results: {id: string}[]
218
+ results: {id: string; operation: MutationOperation}[]
218
219
  }
219
220
 
220
221
  export interface MultipleMutationResult {
221
222
  transactionId: string
222
223
  documentIds: string[]
223
- results: {id: string}[]
224
+ results: {id: string; operation: MutationOperation}[]
224
225
  }
225
226
 
226
- export class Patch {
227
- constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
228
-
229
- /**
230
- * Clones the patch
231
- */
232
- clone(): Patch
233
-
227
+ export abstract class BasePatch {
234
228
  /**
235
229
  * DEPRECATED: Don't use.
236
230
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -338,19 +332,37 @@ export class Patch {
338
332
  */
339
333
  toJSON(): PatchMutationOperation
340
334
 
335
+ /**
336
+ * Clears the patch of all operations
337
+ */
338
+ reset(): this
339
+ }
340
+
341
+ export class Patch extends BasePatch {
342
+ constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
343
+
344
+ /**
345
+ * Clones the patch
346
+ */
347
+ clone(): Patch
348
+
341
349
  /**
342
350
  * Commit the patch, returning a promise that resolves to the first patched document
343
351
  *
344
352
  * @param options Options for the mutation operation
345
353
  */
346
- commit<R = any>(options: FirstDocumentMutationOptions): Promise<SanityDocument<R>>
354
+ commit<R extends Record<string, any> = Record<string, any>>(
355
+ options: FirstDocumentMutationOptions
356
+ ): Promise<SanityDocument<R>>
347
357
 
348
358
  /**
349
359
  * Commit the patch, returning a promise that resolves to an array of the mutated documents
350
360
  *
351
361
  * @param options Options for the mutation operation
352
362
  */
353
- commit<R = any>(options: AllDocumentsMutationOptions): Promise<SanityDocument<R>[]>
363
+ commit<R extends Record<string, any> = Record<string, any>>(
364
+ options: AllDocumentsMutationOptions
365
+ ): Promise<SanityDocument<R>[]>
354
366
 
355
367
  /**
356
368
  * Commit the patch, returning a promise that resolves to a mutation result object
@@ -371,25 +383,69 @@ export class Patch {
371
383
  *
372
384
  * @param options Options for the mutation operation
373
385
  */
374
- commit<R = any>(options?: BaseMutationOptions): Promise<SanityDocument<R>>
386
+ commit<R extends Record<string, any> = Record<string, any>>(
387
+ options?: BaseMutationOptions
388
+ ): Promise<SanityDocument<R>>
389
+ }
390
+
391
+ export class ObservablePatch extends BasePatch {
392
+ constructor(documentId: string, operations?: PatchOperations, client?: ObservableSanityClient)
375
393
 
376
394
  /**
377
- * Clears the patch of all operations
395
+ * Clones the patch
378
396
  */
379
- reset(): this
380
- }
397
+ clone(): ObservablePatch
381
398
 
382
- export class Transaction {
383
- constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
384
- clone(): Transaction
399
+ /**
400
+ * Commit the patch, returning an observable that produces the first patched document
401
+ *
402
+ * @param options Options for the mutation operation
403
+ */
404
+ commit<R extends Record<string, any> = Record<string, any>>(
405
+ options: FirstDocumentMutationOptions
406
+ ): Observable<SanityDocument<R>>
407
+
408
+ /**
409
+ * Commit the patch, returning an observable that produces an array of the mutated documents
410
+ *
411
+ * @param options Options for the mutation operation
412
+ */
413
+ commit<R extends Record<string, any> = Record<string, any>>(
414
+ options: AllDocumentsMutationOptions
415
+ ): Observable<SanityDocument<R>[]>
385
416
 
417
+ /**
418
+ * Commit the patch, returning an observable that produces a mutation result object
419
+ *
420
+ * @param options Options for the mutation operation
421
+ */
422
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
423
+
424
+ /**
425
+ * Commit the patch, returning an observable that produces a mutation result object
426
+ *
427
+ * @param options Options for the mutation operation
428
+ */
429
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
430
+
431
+ /**
432
+ * Commit the patch, returning an observable that produces the first patched document
433
+ *
434
+ * @param options Options for the mutation operation
435
+ */
436
+ commit<R extends Record<string, any> = Record<string, any>>(
437
+ options?: BaseMutationOptions
438
+ ): Observable<SanityDocument<R>>
439
+ }
440
+
441
+ export abstract class BaseTransaction {
386
442
  /**
387
443
  * 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.
388
444
  * The operation is added to the current transaction, ready to be commited by `commit()`
389
445
  *
390
446
  * @param doc Document to create. Requires a `_type` property.
391
447
  */
392
- create<R = any>(doc: SanityDocumentStub<R>): this
448
+ create<R extends Record<string, any> = Record<string, any>>(doc: SanityDocumentStub<R>): this
393
449
 
394
450
  /**
395
451
  * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
@@ -397,7 +453,9 @@ export class Transaction {
397
453
  *
398
454
  * @param doc Document to create if it does not already exist. Requires `_id` and `_type` properties.
399
455
  */
400
- createIfNotExists<R = any>(doc: IdentifiedSanityDocumentStub<R>): this
456
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
457
+ doc: IdentifiedSanityDocumentStub<R>
458
+ ): this
401
459
 
402
460
  /**
403
461
  * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
@@ -405,7 +463,9 @@ export class Transaction {
405
463
  *
406
464
  * @param doc Document to create or replace. Requires `_id` and `_type` properties.
407
465
  */
408
- createOrReplace<R = any>(doc: IdentifiedSanityDocumentStub<R>): this
466
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
467
+ doc: IdentifiedSanityDocumentStub<R>
468
+ ): this
409
469
 
410
470
  /**
411
471
  * Deletes the document with the given document ID
@@ -451,19 +511,37 @@ export class Transaction {
451
511
  */
452
512
  toJSON(): Mutation[]
453
513
 
514
+ /**
515
+ * Clears the transaction of all operations
516
+ */
517
+ reset(): this
518
+ }
519
+
520
+ export class Transaction extends BaseTransaction {
521
+ constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
522
+
523
+ /**
524
+ * Clones the transaction
525
+ */
526
+ clone(): Transaction
527
+
454
528
  /**
455
529
  * Commit the transaction, returning a promise that resolves to the first mutated document
456
530
  *
457
531
  * @param options Options for the mutation operation
458
532
  */
459
- commit<R>(options: TransactionFirstDocumentMutationOptions): Promise<SanityDocument<R>>
533
+ commit<R extends Record<string, any>>(
534
+ options: TransactionFirstDocumentMutationOptions
535
+ ): Promise<SanityDocument<R>>
460
536
 
461
537
  /**
462
538
  * Commit the transaction, returning a promise that resolves to an array of the mutated documents
463
539
  *
464
540
  * @param options Options for the mutation operation
465
541
  */
466
- commit<R>(options: TransactionAllDocumentsMutationOptions): Promise<SanityDocument<R>[]>
542
+ commit<R extends Record<string, any>>(
543
+ options: TransactionAllDocumentsMutationOptions
544
+ ): Promise<SanityDocument<R>[]>
467
545
 
468
546
  /**
469
547
  * Commit the transaction, returning a promise that resolves to a mutation result object
@@ -485,11 +563,54 @@ export class Transaction {
485
563
  * @param options Options for the mutation operation
486
564
  */
487
565
  commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
566
+ }
567
+
568
+ export class ObservableTransaction extends BaseTransaction {
569
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
488
570
 
489
571
  /**
490
- * Clears the transaction of all operations
572
+ * Clones the transaction
491
573
  */
492
- reset(): this
574
+ clone(): ObservableTransaction
575
+
576
+ /**
577
+ * Commit the transaction, returning an observable that produces the first mutated document
578
+ *
579
+ * @param options Options for the mutation operation
580
+ */
581
+ commit<R extends Record<string, any>>(
582
+ options: TransactionFirstDocumentMutationOptions
583
+ ): Observable<SanityDocument<R>>
584
+
585
+ /**
586
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
587
+ *
588
+ * @param options Options for the mutation operation
589
+ */
590
+ commit<R extends Record<string, any>>(
591
+ options: TransactionAllDocumentsMutationOptions
592
+ ): Observable<SanityDocument<R>[]>
593
+
594
+ /**
595
+ * Commit the transaction, returning an observable that produces a mutation result object
596
+ *
597
+ * @param options Options for the mutation operation
598
+ */
599
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
600
+
601
+ /**
602
+ * Commit the transaction, returning an observable that produces a mutation result object
603
+ *
604
+ * @param options Options for the mutation operation
605
+ */
606
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
607
+
608
+ /**
609
+ * Commit the transaction, returning an observable that produces a mutation result object
610
+ *
611
+ * @param options Options for the mutation operation
612
+ */
613
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
493
614
  }
494
615
 
495
616
  export interface ClientConfig {
@@ -503,6 +624,7 @@ export interface ClientConfig {
503
624
  requestTagPrefix?: string
504
625
  ignoreBrowserTokenWarning?: boolean
505
626
  withCredentials?: boolean
627
+ allowReconfigure?: boolean
506
628
  timeout?: number
507
629
 
508
630
  /**
@@ -545,7 +667,7 @@ type BaseMutationOptions = RequestOptions & {
545
667
  skipCrossDatasetReferenceValidation?: boolean
546
668
  }
547
669
 
548
- export type MutationEvent<R = any> = {
670
+ export type MutationEvent<R extends Record<string, any> = Record<string, any>> = {
549
671
  type: 'mutation'
550
672
  documentId: string
551
673
  eventId: string
@@ -580,7 +702,7 @@ export type WelcomeEvent = {
580
702
  type: 'welcome'
581
703
  }
582
704
 
583
- export type ListenEvent<R> =
705
+ export type ListenEvent<R extends Record<string, any>> =
584
706
  | MutationEvent<R>
585
707
  | ChannelErrorEvent
586
708
  | DisconnectEvent
@@ -1014,7 +1136,7 @@ export class ObservableSanityClient {
1014
1136
  * @param id Document ID to fetch
1015
1137
  * @param options Request options
1016
1138
  */
1017
- getDocument<R = any>(
1139
+ getDocument<R extends Record<string, any> = Record<string, any>>(
1018
1140
  id: string,
1019
1141
  options?: {tag?: string}
1020
1142
  ): Observable<SanityDocument<R> | undefined>
@@ -1028,7 +1150,7 @@ export class ObservableSanityClient {
1028
1150
  * @param ids Document IDs to fetch
1029
1151
  * @param options Request options
1030
1152
  */
1031
- getDocuments<R = any>(
1153
+ getDocuments<R extends Record<string, any> = Record<string, any>>(
1032
1154
  ids: string[],
1033
1155
  options?: {tag?: string}
1034
1156
  ): Observable<(SanityDocument<R> | null)[]>
@@ -1040,7 +1162,7 @@ export class ObservableSanityClient {
1040
1162
  * @param document Document to create
1041
1163
  * @param options Mutation options
1042
1164
  */
1043
- create<R = any>(
1165
+ create<R extends Record<string, any> = Record<string, any>>(
1044
1166
  document: SanityDocumentStub<R>,
1045
1167
  options: FirstDocumentMutationOptions
1046
1168
  ): Observable<SanityDocument<R>>
@@ -1052,7 +1174,7 @@ export class ObservableSanityClient {
1052
1174
  * @param document Document to create
1053
1175
  * @param options Mutation options
1054
1176
  */
1055
- create<R = any>(
1177
+ create<R extends Record<string, any> = Record<string, any>>(
1056
1178
  document: SanityDocumentStub<R>,
1057
1179
  options: AllDocumentsMutationOptions
1058
1180
  ): Observable<SanityDocument<R>[]>
@@ -1064,7 +1186,7 @@ export class ObservableSanityClient {
1064
1186
  * @param document Document to create
1065
1187
  * @param options Mutation options
1066
1188
  */
1067
- create<R = any>(
1189
+ create<R extends Record<string, any> = Record<string, any>>(
1068
1190
  document: SanityDocumentStub<R>,
1069
1191
  options: FirstDocumentIdMutationOptions
1070
1192
  ): Observable<SingleMutationResult>
@@ -1076,7 +1198,7 @@ export class ObservableSanityClient {
1076
1198
  * @param document Document to create
1077
1199
  * @param options Mutation options
1078
1200
  */
1079
- create<R = any>(
1201
+ create<R extends Record<string, any> = Record<string, any>>(
1080
1202
  document: SanityDocumentStub<R>,
1081
1203
  options: AllDocumentIdsMutationOptions
1082
1204
  ): Observable<MultipleMutationResult>
@@ -1088,7 +1210,7 @@ export class ObservableSanityClient {
1088
1210
  * @param document Document to create
1089
1211
  * @param options Mutation options
1090
1212
  */
1091
- create<R = any>(
1213
+ create<R extends Record<string, any> = Record<string, any>>(
1092
1214
  document: SanityDocumentStub<R>,
1093
1215
  options?: BaseMutationOptions
1094
1216
  ): Observable<SanityDocument<R>>
@@ -1100,7 +1222,7 @@ export class ObservableSanityClient {
1100
1222
  * @param document Document to create
1101
1223
  * @param options Mutation options
1102
1224
  */
1103
- createIfNotExists<R = any>(
1225
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1104
1226
  document: IdentifiedSanityDocumentStub<R>,
1105
1227
  options: FirstDocumentMutationOptions
1106
1228
  ): Observable<SanityDocument<R>>
@@ -1112,7 +1234,7 @@ export class ObservableSanityClient {
1112
1234
  * @param document Document to create
1113
1235
  * @param options Mutation options
1114
1236
  */
1115
- createIfNotExists<R = any>(
1237
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1116
1238
  document: IdentifiedSanityDocumentStub<R>,
1117
1239
  options: AllDocumentsMutationOptions
1118
1240
  ): Observable<SanityDocument<R>[]>
@@ -1124,7 +1246,7 @@ export class ObservableSanityClient {
1124
1246
  * @param document Document to create
1125
1247
  * @param options Mutation options
1126
1248
  */
1127
- createIfNotExists<R = any>(
1249
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1128
1250
  document: IdentifiedSanityDocumentStub<R>,
1129
1251
  options: FirstDocumentIdMutationOptions
1130
1252
  ): Observable<SingleMutationResult>
@@ -1136,7 +1258,7 @@ export class ObservableSanityClient {
1136
1258
  * @param document Document to create
1137
1259
  * @param options Mutation options
1138
1260
  */
1139
- createIfNotExists<R = any>(
1261
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1140
1262
  document: IdentifiedSanityDocumentStub<R>,
1141
1263
  options: AllDocumentIdsMutationOptions
1142
1264
  ): Observable<MultipleMutationResult>
@@ -1148,7 +1270,7 @@ export class ObservableSanityClient {
1148
1270
  * @param document Document to create
1149
1271
  * @param options Mutation options
1150
1272
  */
1151
- createIfNotExists<R = any>(
1273
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1152
1274
  document: IdentifiedSanityDocumentStub<R>,
1153
1275
  options?: BaseMutationOptions
1154
1276
  ): Observable<SanityDocument<R>>
@@ -1160,7 +1282,7 @@ export class ObservableSanityClient {
1160
1282
  * @param document Document to either create or replace
1161
1283
  * @param options Mutation options
1162
1284
  */
1163
- createOrReplace<R = any>(
1285
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1164
1286
  document: IdentifiedSanityDocumentStub<R>,
1165
1287
  options: FirstDocumentMutationOptions
1166
1288
  ): Observable<SanityDocument<R>>
@@ -1172,7 +1294,7 @@ export class ObservableSanityClient {
1172
1294
  * @param document Document to either create or replace
1173
1295
  * @param options Mutation options
1174
1296
  */
1175
- createOrReplace<R = any>(
1297
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1176
1298
  document: IdentifiedSanityDocumentStub<R>,
1177
1299
  options: AllDocumentsMutationOptions
1178
1300
  ): Observable<SanityDocument<R>[]>
@@ -1184,7 +1306,7 @@ export class ObservableSanityClient {
1184
1306
  * @param document Document to either create or replace
1185
1307
  * @param options Mutation options
1186
1308
  */
1187
- createOrReplace<R = any>(
1309
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1188
1310
  document: IdentifiedSanityDocumentStub<R>,
1189
1311
  options: FirstDocumentIdMutationOptions
1190
1312
  ): Observable<SingleMutationResult>
@@ -1196,7 +1318,7 @@ export class ObservableSanityClient {
1196
1318
  * @param document Document to either create or replace
1197
1319
  * @param options Mutation options
1198
1320
  */
1199
- createOrReplace<R = any>(
1321
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1200
1322
  document: IdentifiedSanityDocumentStub<R>,
1201
1323
  options: AllDocumentIdsMutationOptions
1202
1324
  ): Observable<MultipleMutationResult>
@@ -1208,7 +1330,7 @@ export class ObservableSanityClient {
1208
1330
  * @param document Document to either create or replace
1209
1331
  * @param options Mutation options
1210
1332
  */
1211
- createOrReplace<R = any>(
1333
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1212
1334
  document: IdentifiedSanityDocumentStub<R>,
1213
1335
  options?: BaseMutationOptions
1214
1336
  ): Observable<SanityDocument<R>>
@@ -1220,7 +1342,10 @@ export class ObservableSanityClient {
1220
1342
  * @param id Document ID to delete
1221
1343
  * @param options Options for the mutation
1222
1344
  */
1223
- delete<R = any>(id: string, options: FirstDocumentMutationOptions): Observable<SanityDocument<R>>
1345
+ delete<R extends Record<string, any> = Record<string, any>>(
1346
+ id: string,
1347
+ options: FirstDocumentMutationOptions
1348
+ ): Observable<SanityDocument<R>>
1224
1349
 
1225
1350
  /**
1226
1351
  * Deletes a document with the given document ID.
@@ -1229,7 +1354,10 @@ export class ObservableSanityClient {
1229
1354
  * @param id Document ID to delete
1230
1355
  * @param options Options for the mutation
1231
1356
  */
1232
- delete<R = any>(id: string, options: AllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
1357
+ delete<R extends Record<string, any> = Record<string, any>>(
1358
+ id: string,
1359
+ options: AllDocumentsMutationOptions
1360
+ ): Observable<SanityDocument<R>[]>
1233
1361
 
1234
1362
  /**
1235
1363
  * Deletes a document with the given document ID.
@@ -1256,7 +1384,10 @@ export class ObservableSanityClient {
1256
1384
  * @param id Document ID to delete
1257
1385
  * @param options Options for the mutation
1258
1386
  */
1259
- delete<R = any>(id: string, options?: BaseMutationOptions): Observable<SanityDocument<R>>
1387
+ delete<R extends Record<string, any> = Record<string, any>>(
1388
+ id: string,
1389
+ options?: BaseMutationOptions
1390
+ ): Observable<SanityDocument<R>>
1260
1391
 
1261
1392
  /**
1262
1393
  * Deletes one or more documents matching the given query or document ID.
@@ -1265,7 +1396,7 @@ export class ObservableSanityClient {
1265
1396
  * @param selection An object with either an `id` or `query` key defining what to delete
1266
1397
  * @param options Options for the mutation
1267
1398
  */
1268
- delete<R = any>(
1399
+ delete<R extends Record<string, any> = Record<string, any>>(
1269
1400
  selection: MutationSelection,
1270
1401
  options: FirstDocumentMutationOptions
1271
1402
  ): Observable<SanityDocument<R>>
@@ -1277,7 +1408,7 @@ export class ObservableSanityClient {
1277
1408
  * @param selection An object with either an `id` or `query` key defining what to delete
1278
1409
  * @param options Options for the mutation
1279
1410
  */
1280
- delete<R = any>(
1411
+ delete<R extends Record<string, any> = Record<string, any>>(
1281
1412
  selection: MutationSelection,
1282
1413
  options: AllDocumentsMutationOptions
1283
1414
  ): Observable<SanityDocument<R>[]>
@@ -1313,7 +1444,7 @@ export class ObservableSanityClient {
1313
1444
  * @param selection An object with either an `id` or `query` key defining what to delete
1314
1445
  * @param options Options for the mutation
1315
1446
  */
1316
- delete<R = any>(
1447
+ delete<R extends Record<string, any> = Record<string, any>>(
1317
1448
  selection: MutationSelection,
1318
1449
  options?: BaseMutationOptions
1319
1450
  ): Observable<SanityDocument<R>>
@@ -1325,7 +1456,7 @@ export class ObservableSanityClient {
1325
1456
  * @param operations Mutation operations to execute
1326
1457
  * @param options Mutation options
1327
1458
  */
1328
- mutate<R = any>(
1459
+ mutate<R extends Record<string, any> = Record<string, any>>(
1329
1460
  operations: Mutation<R>[] | Patch | Transaction,
1330
1461
  options: FirstDocumentMutationOptions
1331
1462
  ): Observable<SanityDocument<R>>
@@ -1337,7 +1468,7 @@ export class ObservableSanityClient {
1337
1468
  * @param operations Mutation operations to execute
1338
1469
  * @param options Mutation options
1339
1470
  */
1340
- mutate<R = any>(
1471
+ mutate<R extends Record<string, any> = Record<string, any>>(
1341
1472
  operations: Mutation<R>[] | Patch | Transaction,
1342
1473
  options: AllDocumentsMutationOptions
1343
1474
  ): Observable<SanityDocument<R>[]>
@@ -1349,7 +1480,7 @@ export class ObservableSanityClient {
1349
1480
  * @param operations Mutation operations to execute
1350
1481
  * @param options Mutation options
1351
1482
  */
1352
- mutate<R = any>(
1483
+ mutate<R extends Record<string, any> = Record<string, any>>(
1353
1484
  operations: Mutation<R>[] | Patch | Transaction,
1354
1485
  options: FirstDocumentIdMutationOptions
1355
1486
  ): Observable<SingleMutationResult>
@@ -1361,7 +1492,7 @@ export class ObservableSanityClient {
1361
1492
  * @param operations Mutation operations to execute
1362
1493
  * @param options Mutation options
1363
1494
  */
1364
- mutate<R = any>(
1495
+ mutate<R extends Record<string, any> = Record<string, any>>(
1365
1496
  operations: Mutation<R>[] | Patch | Transaction,
1366
1497
  options: AllDocumentIdsMutationOptions
1367
1498
  ): Observable<MultipleMutationResult>
@@ -1373,7 +1504,7 @@ export class ObservableSanityClient {
1373
1504
  * @param operations Mutation operations to execute
1374
1505
  * @param options Mutation options
1375
1506
  */
1376
- mutate<R = any>(
1507
+ mutate<R extends Record<string, any> = Record<string, any>>(
1377
1508
  operations: Mutation<R>[] | Patch | Transaction,
1378
1509
  options?: BaseMutationOptions
1379
1510
  ): Observable<SanityDocument<R>>
@@ -1384,14 +1515,16 @@ export class ObservableSanityClient {
1384
1515
  * @param documentId Document ID to patch
1385
1516
  * @param operations Optional object of patch operations to initialize the patch instance with
1386
1517
  */
1387
- patch(documentId: string | MutationSelection, operations?: PatchOperations): Patch
1518
+ patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
1388
1519
 
1389
1520
  /**
1390
1521
  * Create a new transaction of mutations
1391
1522
  *
1392
1523
  * @param operations Optional array of mutation operations to initialize the transaction instance with
1393
1524
  */
1394
- transaction<R = any>(operations?: Mutation<R>[]): Transaction
1525
+ transaction<R extends Record<string, any> = Record<string, any>>(
1526
+ operations?: Mutation<R>[]
1527
+ ): ObservableTransaction
1395
1528
 
1396
1529
  // "Internals", should generally not be used externally
1397
1530
  /**
@@ -1428,14 +1561,9 @@ export class ObservableSanityClient {
1428
1561
  request<T = any>(options: RawRequestOptions): Observable<T>
1429
1562
  }
1430
1563
 
1431
- export class SanityClient {
1432
- static Patch: typeof Patch
1433
- static Transaction: typeof Transaction
1434
- static ClientError: typeof ClientError
1435
- static ServerError: typeof ServerError
1436
- static requester: GetItRequester
1564
+ export interface SanityClient {
1437
1565
  // Client/configuration
1438
- constructor(config: ClientConfig)
1566
+ constructor(config: ClientConfig): SanityClient
1439
1567
 
1440
1568
  /**
1441
1569
  * Clone the client - returns a new instance
@@ -1613,7 +1741,10 @@ export class SanityClient {
1613
1741
  * @param params Optional query parameters
1614
1742
  * @param options Listener options
1615
1743
  */
1616
- listen<R = any>(query: string, params?: QueryParams): Observable<MutationEvent<R>>
1744
+ listen<R extends Record<string, any> = Record<string, any>>(
1745
+ query: string,
1746
+ params?: QueryParams
1747
+ ): Observable<MutationEvent<R>>
1617
1748
 
1618
1749
  /**
1619
1750
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
@@ -1622,7 +1753,7 @@ export class SanityClient {
1622
1753
  * @param params Optional query parameters
1623
1754
  * @param options Listener options
1624
1755
  */
1625
- listen<R = any>(
1756
+ listen<R extends Record<string, any> = Record<string, any>>(
1626
1757
  query: string,
1627
1758
  params?: QueryParams,
1628
1759
  options?: ListenOptions
@@ -1675,7 +1806,10 @@ export class SanityClient {
1675
1806
  * @param id Document ID to fetch
1676
1807
  * @param options Request options
1677
1808
  */
1678
- getDocument<R = any>(id: string, options?: {tag?: string}): Promise<SanityDocument<R> | undefined>
1809
+ getDocument<R extends Record<string, any> = Record<string, any>>(
1810
+ id: string,
1811
+ options?: {tag?: string}
1812
+ ): Promise<SanityDocument<R> | undefined>
1679
1813
 
1680
1814
  /**
1681
1815
  * Fetch multiple documents in one request.
@@ -1686,7 +1820,7 @@ export class SanityClient {
1686
1820
  * @param ids Document IDs to fetch
1687
1821
  * @param options Request options
1688
1822
  */
1689
- getDocuments<R = any>(
1823
+ getDocuments<R extends Record<string, any> = Record<string, any>>(
1690
1824
  ids: string[],
1691
1825
  options?: {tag?: string}
1692
1826
  ): Promise<(SanityDocument<R> | null)[]>
@@ -1698,7 +1832,7 @@ export class SanityClient {
1698
1832
  * @param document Document to create
1699
1833
  * @param options Mutation options
1700
1834
  */
1701
- create<R = any>(
1835
+ create<R extends Record<string, any> = Record<string, any>>(
1702
1836
  document: SanityDocumentStub<R>,
1703
1837
  options: FirstDocumentMutationOptions
1704
1838
  ): Promise<SanityDocument<R>>
@@ -1710,7 +1844,7 @@ export class SanityClient {
1710
1844
  * @param document Document to create
1711
1845
  * @param options Mutation options
1712
1846
  */
1713
- create<R = any>(
1847
+ create<R extends Record<string, any> = Record<string, any>>(
1714
1848
  document: SanityDocumentStub<R>,
1715
1849
  options: AllDocumentsMutationOptions
1716
1850
  ): Promise<SanityDocument<R>[]>
@@ -1722,7 +1856,7 @@ export class SanityClient {
1722
1856
  * @param document Document to create
1723
1857
  * @param options Mutation options
1724
1858
  */
1725
- create<R = any>(
1859
+ create<R extends Record<string, any> = Record<string, any>>(
1726
1860
  document: SanityDocumentStub<R>,
1727
1861
  options: FirstDocumentIdMutationOptions
1728
1862
  ): Promise<SingleMutationResult>
@@ -1734,7 +1868,7 @@ export class SanityClient {
1734
1868
  * @param document Document to create
1735
1869
  * @param options Mutation options
1736
1870
  */
1737
- create<R = any>(
1871
+ create<R extends Record<string, any> = Record<string, any>>(
1738
1872
  document: SanityDocumentStub<R>,
1739
1873
  options: AllDocumentIdsMutationOptions
1740
1874
  ): Promise<MultipleMutationResult>
@@ -1746,7 +1880,7 @@ export class SanityClient {
1746
1880
  * @param document Document to create
1747
1881
  * @param options Mutation options
1748
1882
  */
1749
- create<R = any>(
1883
+ create<R extends Record<string, any> = Record<string, any>>(
1750
1884
  document: SanityDocumentStub<R>,
1751
1885
  options?: BaseMutationOptions
1752
1886
  ): Promise<SanityDocument<R>>
@@ -1758,7 +1892,7 @@ export class SanityClient {
1758
1892
  * @param document Document to create
1759
1893
  * @param options Mutation options
1760
1894
  */
1761
- createIfNotExists<R = any>(
1895
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1762
1896
  document: IdentifiedSanityDocumentStub<R>,
1763
1897
  options: FirstDocumentMutationOptions
1764
1898
  ): Promise<SanityDocument<R>>
@@ -1770,7 +1904,7 @@ export class SanityClient {
1770
1904
  * @param document Document to create
1771
1905
  * @param options Mutation options
1772
1906
  */
1773
- createIfNotExists<R = any>(
1907
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1774
1908
  document: IdentifiedSanityDocumentStub<R>,
1775
1909
  options: AllDocumentsMutationOptions
1776
1910
  ): Promise<SanityDocument<R>[]>
@@ -1782,7 +1916,7 @@ export class SanityClient {
1782
1916
  * @param document Document to create
1783
1917
  * @param options Mutation options
1784
1918
  */
1785
- createIfNotExists<R = any>(
1919
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1786
1920
  document: IdentifiedSanityDocumentStub<R>,
1787
1921
  options: FirstDocumentIdMutationOptions
1788
1922
  ): Promise<SingleMutationResult>
@@ -1794,7 +1928,7 @@ export class SanityClient {
1794
1928
  * @param document Document to create
1795
1929
  * @param options Mutation options
1796
1930
  */
1797
- createIfNotExists<R = any>(
1931
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1798
1932
  document: IdentifiedSanityDocumentStub<R>,
1799
1933
  options: AllDocumentIdsMutationOptions
1800
1934
  ): Promise<MultipleMutationResult>
@@ -1806,7 +1940,7 @@ export class SanityClient {
1806
1940
  * @param document Document to create
1807
1941
  * @param options Mutation options
1808
1942
  */
1809
- createIfNotExists<R = any>(
1943
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
1810
1944
  document: IdentifiedSanityDocumentStub<R>,
1811
1945
  options?: BaseMutationOptions
1812
1946
  ): Promise<SanityDocument<R>>
@@ -1818,7 +1952,7 @@ export class SanityClient {
1818
1952
  * @param document Document to either create or replace
1819
1953
  * @param options Mutation options
1820
1954
  */
1821
- createOrReplace<R = any>(
1955
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1822
1956
  document: IdentifiedSanityDocumentStub<R>,
1823
1957
  options: FirstDocumentMutationOptions
1824
1958
  ): Promise<SanityDocument<R>>
@@ -1830,7 +1964,7 @@ export class SanityClient {
1830
1964
  * @param document Document to either create or replace
1831
1965
  * @param options Mutation options
1832
1966
  */
1833
- createOrReplace<R = any>(
1967
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1834
1968
  document: IdentifiedSanityDocumentStub<R>,
1835
1969
  options: AllDocumentsMutationOptions
1836
1970
  ): Promise<SanityDocument<R>[]>
@@ -1842,7 +1976,7 @@ export class SanityClient {
1842
1976
  * @param document Document to either create or replace
1843
1977
  * @param options Mutation options
1844
1978
  */
1845
- createOrReplace<R = any>(
1979
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1846
1980
  document: IdentifiedSanityDocumentStub<R>,
1847
1981
  options: FirstDocumentIdMutationOptions
1848
1982
  ): Promise<SingleMutationResult>
@@ -1854,7 +1988,7 @@ export class SanityClient {
1854
1988
  * @param document Document to either create or replace
1855
1989
  * @param options Mutation options
1856
1990
  */
1857
- createOrReplace<R = any>(
1991
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1858
1992
  document: IdentifiedSanityDocumentStub<R>,
1859
1993
  options: AllDocumentIdsMutationOptions
1860
1994
  ): Promise<MultipleMutationResult>
@@ -1866,7 +2000,7 @@ export class SanityClient {
1866
2000
  * @param document Document to either create or replace
1867
2001
  * @param options Mutation options
1868
2002
  */
1869
- createOrReplace<R = any>(
2003
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
1870
2004
  document: IdentifiedSanityDocumentStub<R>,
1871
2005
  options?: BaseMutationOptions
1872
2006
  ): Promise<SanityDocument<R>>
@@ -1878,7 +2012,10 @@ export class SanityClient {
1878
2012
  * @param id Document ID to delete
1879
2013
  * @param options Options for the mutation
1880
2014
  */
1881
- delete<R = any>(id: string, options: FirstDocumentMutationOptions): Promise<SanityDocument<R>>
2015
+ delete<R extends Record<string, any> = Record<string, any>>(
2016
+ id: string,
2017
+ options: FirstDocumentMutationOptions
2018
+ ): Promise<SanityDocument<R>>
1882
2019
 
1883
2020
  /**
1884
2021
  * Deletes a document with the given document ID.
@@ -1887,7 +2024,10 @@ export class SanityClient {
1887
2024
  * @param id Document ID to delete
1888
2025
  * @param options Options for the mutation
1889
2026
  */
1890
- delete<R = any>(id: string, options: AllDocumentsMutationOptions): Promise<SanityDocument<R>[]>
2027
+ delete<R extends Record<string, any> = Record<string, any>>(
2028
+ id: string,
2029
+ options: AllDocumentsMutationOptions
2030
+ ): Promise<SanityDocument<R>[]>
1891
2031
 
1892
2032
  /**
1893
2033
  * Deletes a document with the given document ID.
@@ -1914,7 +2054,10 @@ export class SanityClient {
1914
2054
  * @param id Document ID to delete
1915
2055
  * @param options Options for the mutation
1916
2056
  */
1917
- delete<R = any>(id: string, options?: BaseMutationOptions): Promise<SanityDocument<R>>
2057
+ delete<R extends Record<string, any> = Record<string, any>>(
2058
+ id: string,
2059
+ options?: BaseMutationOptions
2060
+ ): Promise<SanityDocument<R>>
1918
2061
 
1919
2062
  /**
1920
2063
  * Deletes one or more documents matching the given query or document ID.
@@ -1923,7 +2066,7 @@ export class SanityClient {
1923
2066
  * @param selection An object with either an `id` or `query` key defining what to delete
1924
2067
  * @param options Options for the mutation
1925
2068
  */
1926
- delete<R = any>(
2069
+ delete<R extends Record<string, any> = Record<string, any>>(
1927
2070
  selection: MutationSelection,
1928
2071
  options: FirstDocumentMutationOptions
1929
2072
  ): Promise<SanityDocument<R>>
@@ -1935,7 +2078,7 @@ export class SanityClient {
1935
2078
  * @param selection An object with either an `id` or `query` key defining what to delete
1936
2079
  * @param options Options for the mutation
1937
2080
  */
1938
- delete<R = any>(
2081
+ delete<R extends Record<string, any> = Record<string, any>>(
1939
2082
  selection: MutationSelection,
1940
2083
  options: AllDocumentsMutationOptions
1941
2084
  ): Promise<SanityDocument<R>[]>
@@ -1971,7 +2114,7 @@ export class SanityClient {
1971
2114
  * @param selection An object with either an `id` or `query` key defining what to delete
1972
2115
  * @param options Options for the mutation
1973
2116
  */
1974
- delete<R = any>(
2117
+ delete<R extends Record<string, any> = Record<string, any>>(
1975
2118
  selection: MutationSelection,
1976
2119
  options?: BaseMutationOptions
1977
2120
  ): Promise<SanityDocument<R>>
@@ -1983,7 +2126,7 @@ export class SanityClient {
1983
2126
  * @param operations Mutation operations to execute
1984
2127
  * @param options Mutation options
1985
2128
  */
1986
- mutate<R = any>(
2129
+ mutate<R extends Record<string, any> = Record<string, any>>(
1987
2130
  operations: Mutation<R>[] | Patch | Transaction,
1988
2131
  options: FirstDocumentMutationOptions
1989
2132
  ): Promise<SanityDocument<R>>
@@ -1995,7 +2138,7 @@ export class SanityClient {
1995
2138
  * @param operations Mutation operations to execute
1996
2139
  * @param options Mutation options
1997
2140
  */
1998
- mutate<R = any>(
2141
+ mutate<R extends Record<string, any> = Record<string, any>>(
1999
2142
  operations: Mutation<R>[] | Patch | Transaction,
2000
2143
  options: AllDocumentsMutationOptions
2001
2144
  ): Promise<SanityDocument<R>[]>
@@ -2007,7 +2150,7 @@ export class SanityClient {
2007
2150
  * @param operations Mutation operations to execute
2008
2151
  * @param options Mutation options
2009
2152
  */
2010
- mutate<R = any>(
2153
+ mutate<R extends Record<string, any> = Record<string, any>>(
2011
2154
  operations: Mutation<R>[] | Patch | Transaction,
2012
2155
  options: FirstDocumentIdMutationOptions
2013
2156
  ): Promise<SingleMutationResult>
@@ -2019,7 +2162,7 @@ export class SanityClient {
2019
2162
  * @param operations Mutation operations to execute
2020
2163
  * @param options Mutation options
2021
2164
  */
2022
- mutate<R>(
2165
+ mutate<R extends Record<string, any>>(
2023
2166
  operations: Mutation<R>[] | Patch | Transaction,
2024
2167
  options: AllDocumentIdsMutationOptions
2025
2168
  ): Promise<MultipleMutationResult>
@@ -2031,7 +2174,7 @@ export class SanityClient {
2031
2174
  * @param operations Mutation operations to execute
2032
2175
  * @param options Mutation options
2033
2176
  */
2034
- mutate<R = any>(
2177
+ mutate<R extends Record<string, any> = Record<string, any>>(
2035
2178
  operations: Mutation<R>[] | Patch | Transaction,
2036
2179
  options?: BaseMutationOptions
2037
2180
  ): Promise<SanityDocument<R>>
@@ -2049,7 +2192,9 @@ export class SanityClient {
2049
2192
  *
2050
2193
  * @param operations Optional array of mutation operations to initialize the transaction instance with
2051
2194
  */
2052
- transaction<R = any>(operations?: Mutation<R>[]): Transaction
2195
+ transaction<R extends Record<string, any> = Record<string, any>>(
2196
+ operations?: Mutation<R>[]
2197
+ ): Transaction
2053
2198
 
2054
2199
  // "Internals", should generally not be used externally
2055
2200
  /**
@@ -2096,4 +2241,16 @@ export class SanityClient {
2096
2241
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<any>
2097
2242
  }
2098
2243
 
2099
- export function createClient(config: ClientConfig): SanityClient
2244
+ export interface ClientConstructor {
2245
+ Patch: typeof Patch
2246
+ Transaction: typeof Transaction
2247
+ ClientError: typeof ClientError
2248
+ ServerError: typeof ServerError
2249
+ requester: GetItRequester
2250
+
2251
+ new (config: ClientConfig): SanityClient
2252
+ (config: ClientConfig): SanityClient
2253
+ }
2254
+
2255
+ declare const SanityClientConstructor: ClientConstructor
2256
+ export default SanityClientConstructor