@sanity/client 7.26.2 → 8.1.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 (133) hide show
  1. package/README.md +63 -341
  2. package/dist/browserUpload-2tz6Sdqp.js +87 -0
  3. package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
  4. package/dist/browserUpload-CwpNx7Vl.js +87 -0
  5. package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
  6. package/dist/config-3wiPP-sZ.js +126 -0
  7. package/dist/config-3wiPP-sZ.js.map +1 -0
  8. package/dist/csm.d.ts +122 -335
  9. package/dist/csm.js +79 -91
  10. package/dist/csm.js.map +1 -1
  11. package/dist/dist-C9ExSk2R.js +73 -0
  12. package/dist/dist-C9ExSk2R.js.map +1 -0
  13. package/dist/dist-Z8cIRxoB.js +69 -0
  14. package/dist/dist-Z8cIRxoB.js.map +1 -0
  15. package/dist/index.d.ts +112 -6722
  16. package/dist/index.js +2950 -2848
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index.d.cts → index.node.d.ts} +4529 -5322
  19. package/dist/index.node.js +3264 -0
  20. package/dist/index.node.js.map +1 -0
  21. package/dist/isRecord-Kfmt-nk-.js +7 -0
  22. package/dist/isRecord-Kfmt-nk-.js.map +1 -0
  23. package/dist/media-library.d.ts +9 -100
  24. package/dist/media-library.js +36 -14
  25. package/dist/media-library.js.map +1 -1
  26. package/dist/request-BhMuKj0D.js +373 -0
  27. package/dist/request-BhMuKj0D.js.map +1 -0
  28. package/dist/request-SnMg7nUX.js +355 -0
  29. package/dist/request-SnMg7nUX.js.map +1 -0
  30. package/dist/resolveEditInfo-Cz-smq3a.js +339 -0
  31. package/dist/resolveEditInfo-Cz-smq3a.js.map +1 -0
  32. package/dist/rolldown-runtime-vyAXikos.js +9 -0
  33. package/dist/stega.d.ts +78 -7137
  34. package/dist/stega.js +27 -20
  35. package/dist/stega.js.map +1 -1
  36. package/dist/stegaClean-C18wLWau.js +21 -0
  37. package/dist/stegaClean-C18wLWau.js.map +1 -0
  38. package/dist/stegaEncodeSourceMap-DbM2fTN4.js +373 -0
  39. package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
  40. package/dist/stegaEncodeSourceMap-YR3NQ3iz.js +163 -0
  41. package/dist/stegaEncodeSourceMap-YR3NQ3iz.js.map +1 -0
  42. package/dist/{index.browser.d.cts → types-BODIEY7F.d.ts} +4196 -5258
  43. package/dist/types-CfGzbXrl.d.ts +108 -0
  44. package/package.json +80 -142
  45. package/src/SanityClient.ts +101 -137
  46. package/src/agent/actions/AgentActionsClient.ts +12 -12
  47. package/src/agent/actions/commonTypes.ts +2 -1
  48. package/src/agent/actions/generate.ts +26 -6
  49. package/src/agent/actions/patch.ts +27 -7
  50. package/src/agent/actions/prompt.ts +19 -5
  51. package/src/agent/actions/transform.ts +23 -5
  52. package/src/agent/actions/translate.ts +23 -5
  53. package/src/assets/AssetsClient.ts +121 -24
  54. package/src/csm/applySourceDocuments.ts +5 -5
  55. package/src/csm/createEditUrl.ts +1 -1
  56. package/src/csm/draftUtils.ts +23 -5
  57. package/src/csm/index.ts +2 -2
  58. package/src/csm/studioPath.ts +2 -1
  59. package/src/csm/types.ts +8 -2
  60. package/src/data/dataMethods.ts +784 -349
  61. package/src/data/eventsource.ts +82 -49
  62. package/src/data/listen.ts +18 -23
  63. package/src/data/live.ts +60 -35
  64. package/src/data/resolveEventSourceFetch.ts +104 -0
  65. package/src/datasets/DatasetsClient.ts +58 -41
  66. package/src/defineCreateClient.ts +38 -22
  67. package/src/functions/FunctionsClient.ts +66 -0
  68. package/src/functions/invoke.ts +176 -0
  69. package/src/http/browserMiddleware.ts +7 -1
  70. package/src/http/browserUpload.ts +163 -0
  71. package/src/http/errors.ts +61 -6
  72. package/src/http/nodeMiddleware.ts +94 -30
  73. package/src/http/request.ts +304 -87
  74. package/src/http/requestOptions.ts +131 -15
  75. package/src/{index.browser.ts → index.node.ts} +9 -4
  76. package/src/index.ts +4 -3
  77. package/src/mediaLibrary/MediaLibraryVideoClient.ts +27 -12
  78. package/src/projects/ProjectsClient.ts +18 -16
  79. package/src/releases/ReleasesClient.ts +38 -33
  80. package/src/stega/index.ts +1 -2
  81. package/src/stega/stegaEncodeSourceMap.ts +5 -0
  82. package/src/stega/types.ts +2 -2
  83. package/src/types.ts +328 -103
  84. package/src/users/UsersClient.ts +10 -14
  85. package/src/util/shareReplayLatest.ts +1 -1
  86. package/src/validators.ts +1 -1
  87. package/src/warnings.ts +13 -2
  88. package/dist/_chunks-cjs/config.cjs +0 -206
  89. package/dist/_chunks-cjs/config.cjs.map +0 -1
  90. package/dist/_chunks-cjs/isRecord.cjs +0 -6
  91. package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
  92. package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
  93. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
  94. package/dist/_chunks-cjs/stegaClean.cjs +0 -46
  95. package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
  96. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
  97. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
  98. package/dist/_chunks-es/config.js +0 -207
  99. package/dist/_chunks-es/config.js.map +0 -1
  100. package/dist/_chunks-es/isRecord.js +0 -7
  101. package/dist/_chunks-es/isRecord.js.map +0 -1
  102. package/dist/_chunks-es/resolveEditInfo.js +0 -335
  103. package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
  104. package/dist/_chunks-es/stegaClean.js +0 -47
  105. package/dist/_chunks-es/stegaClean.js.map +0 -1
  106. package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
  107. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
  108. package/dist/csm.cjs +0 -99
  109. package/dist/csm.cjs.map +0 -1
  110. package/dist/csm.d.cts +0 -391
  111. package/dist/index.browser.cjs +0 -3106
  112. package/dist/index.browser.cjs.map +0 -1
  113. package/dist/index.browser.d.ts +0 -6802
  114. package/dist/index.browser.js +0 -3082
  115. package/dist/index.browser.js.map +0 -1
  116. package/dist/index.cjs +0 -2946
  117. package/dist/index.cjs.map +0 -1
  118. package/dist/media-library.cjs +0 -20
  119. package/dist/media-library.cjs.map +0 -1
  120. package/dist/media-library.d.cts +0 -117
  121. package/dist/stega.browser.cjs +0 -29
  122. package/dist/stega.browser.cjs.map +0 -1
  123. package/dist/stega.browser.d.cts +0 -7200
  124. package/dist/stega.browser.d.ts +0 -7200
  125. package/dist/stega.browser.js +0 -24
  126. package/dist/stega.browser.js.map +0 -1
  127. package/dist/stega.cjs +0 -29
  128. package/dist/stega.cjs.map +0 -1
  129. package/dist/stega.d.cts +0 -7200
  130. package/src/data/eventsourcePolyfill.ts +0 -7
  131. package/umd/.gitkeep +0 -1
  132. package/umd/sanityClient.js +0 -6543
  133. package/umd/sanityClient.min.js +0 -6
@@ -1,5 +1,5 @@
1
1
  import {getPublishedId, getVersionId} from '@sanity/client/csm'
2
- import {firstValueFrom, lastValueFrom, Observable} from 'rxjs'
2
+ import {Observable} from 'rxjs'
3
3
 
4
4
  import {AgentActionsClient, ObservableAgentsActionClient} from './agent/actions/AgentActionsClient'
5
5
  import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
@@ -10,6 +10,7 @@ import {LiveClient} from './data/live'
10
10
  import {ObservablePatch, Patch} from './data/patch'
11
11
  import {ObservableTransaction, Transaction} from './data/transaction'
12
12
  import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
13
+ import {FunctionsClient, ObservableFunctionsClient} from './functions/FunctionsClient'
13
14
  import {
14
15
  MediaLibraryVideoClient,
15
16
  ObservableMediaLibraryVideoClient,
@@ -43,7 +44,6 @@ import type {
43
44
  RawQuerylessQueryResponse,
44
45
  RawQueryResponse,
45
46
  RawRequestOptions,
46
- RequestOptions,
47
47
  SanityDocument,
48
48
  SanityDocumentStub,
49
49
  SingleActionResult,
@@ -82,13 +82,13 @@ export class ObservableSanityClient {
82
82
  agent: {
83
83
  action: ObservableAgentsActionClient
84
84
  }
85
+ functions: ObservableFunctionsClient
85
86
  releases: ObservableReleasesClient
86
87
 
87
88
  /**
88
89
  * Private properties
89
90
  */
90
91
  #clientConfig: InitializedClientConfig
91
- #originalHttpRequest: HttpRequest
92
92
  #httpRequest: HttpRequest
93
93
 
94
94
  /**
@@ -99,22 +99,7 @@ export class ObservableSanityClient {
99
99
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
100
100
  this.config(config)
101
101
 
102
- this.#originalHttpRequest = httpRequest
103
- const requestHandler = config._requestHandler
104
-
105
- this.#httpRequest = requestHandler
106
- ? (() => {
107
- let bareClient: SanityClient | undefined
108
- const wrapped: HttpRequest = (options, requester) => {
109
- const opts = options as RequestOptions & {url: string}
110
- if (!bareClient) {
111
- bareClient = new SanityClient(httpRequest, {...config, _requestHandler: undefined})
112
- }
113
- return requestHandler(opts, (o) => httpRequest(o, requester), bareClient)
114
- }
115
- return wrapped
116
- })()
117
- : httpRequest
102
+ this.#httpRequest = httpRequest
118
103
 
119
104
  this.assets = new ObservableAssetsClient(this, this.#httpRequest)
120
105
  this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
@@ -127,6 +112,7 @@ export class ObservableSanityClient {
127
112
  this.agent = {
128
113
  action: new ObservableAgentsActionClient(this, this.#httpRequest),
129
114
  }
115
+ this.functions = new ObservableFunctionsClient(this, this.#httpRequest)
130
116
  this.releases = new ObservableReleasesClient(this, this.#httpRequest)
131
117
  }
132
118
 
@@ -134,7 +120,7 @@ export class ObservableSanityClient {
134
120
  * Clone the client - returns a new instance
135
121
  */
136
122
  clone(): ObservableSanityClient {
137
- return new ObservableSanityClient(this.#originalHttpRequest, this.config())
123
+ return new ObservableSanityClient(this.#httpRequest, this.config())
138
124
  }
139
125
 
140
126
  /**
@@ -167,11 +153,11 @@ export class ObservableSanityClient {
167
153
  */
168
154
  withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
169
155
  const thisConfig = this.config()
170
- return new ObservableSanityClient(this.#originalHttpRequest, {
156
+ return new ObservableSanityClient(this.#httpRequest, {
171
157
  ...thisConfig,
172
158
  ...newConfig,
173
159
  stega: {
174
- ...(thisConfig.stega || {}),
160
+ ...thisConfig.stega,
175
161
  ...(typeof newConfig?.stega === 'boolean'
176
162
  ? {enabled: newConfig.stega}
177
163
  : newConfig?.stega || {}),
@@ -242,7 +228,7 @@ export class ObservableSanityClient {
242
228
  params?: Q,
243
229
  options?: QueryOptions,
244
230
  ): Observable<RawQueryResponse<R> | R> {
245
- return dataMethods._fetch<R, Q>(
231
+ return dataMethods._fetchObservable<R, Q>(
246
232
  this,
247
233
  this.#httpRequest,
248
234
  this.#clientConfig.stega,
@@ -293,7 +279,7 @@ export class ObservableSanityClient {
293
279
  ): Observable<SanityDocument<R> | undefined | SanityDocument<R>[]> {
294
280
  // Implementation needs to handle union type safely
295
281
  if (options?.includeAllVersions === true) {
296
- return dataMethods._getDocument<R>(this, this.#httpRequest, id, {
282
+ return dataMethods._getDocumentObservable<R>(this, this.#httpRequest, id, {
297
283
  ...options,
298
284
  includeAllVersions: true,
299
285
  })
@@ -305,7 +291,7 @@ export class ObservableSanityClient {
305
291
  releaseId: options?.releaseId,
306
292
  ...(options && 'includeAllVersions' in options ? {includeAllVersions: false as const} : {}),
307
293
  }
308
- return dataMethods._getDocument<R>(this, this.#httpRequest, id, opts)
294
+ return dataMethods._getDocumentObservable<R>(this, this.#httpRequest, id, opts)
309
295
  }
310
296
 
311
297
  /**
@@ -321,7 +307,7 @@ export class ObservableSanityClient {
321
307
  ids: string[],
322
308
  options?: {tag?: string},
323
309
  ): Observable<(SanityDocument<R> | null)[]> {
324
- return dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options)
310
+ return dataMethods._getDocumentsObservable<R>(this, this.#httpRequest, ids, options)
325
311
  }
326
312
 
327
313
  /**
@@ -335,7 +321,7 @@ export class ObservableSanityClient {
335
321
  ids: string[],
336
322
  options?: {signal?: AbortSignal; tag?: string},
337
323
  ): Observable<Set<string>> {
338
- return dataMethods._documentsExists(this, this.#httpRequest, ids, options)
324
+ return dataMethods._documentsExistsObservable(this, this.#httpRequest, ids, options)
339
325
  }
340
326
 
341
327
  /**
@@ -404,7 +390,7 @@ export class ObservableSanityClient {
404
390
  ): Observable<
405
391
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
406
392
  > {
407
- return dataMethods._create<R>(this, this.#httpRequest, document, 'create', options)
393
+ return dataMethods._createObservable<R>(this, this.#httpRequest, document, 'create', options)
408
394
  }
409
395
 
410
396
  /**
@@ -473,7 +459,7 @@ export class ObservableSanityClient {
473
459
  ): Observable<
474
460
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
475
461
  > {
476
- return dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options)
462
+ return dataMethods._createIfNotExistsObservable<R>(this, this.#httpRequest, document, options)
477
463
  }
478
464
 
479
465
  /**
@@ -542,7 +528,7 @@ export class ObservableSanityClient {
542
528
  ): Observable<
543
529
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
544
530
  > {
545
- return dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options)
531
+ return dataMethods._createOrReplaceObservable<R>(this, this.#httpRequest, document, options)
546
532
  }
547
533
 
548
534
  /**
@@ -655,7 +641,7 @@ export class ObservableSanityClient {
655
641
  options?: BaseActionOptions,
656
642
  ): Observable<SingleActionResult | MultipleActionResult> {
657
643
  if (!document) {
658
- return dataMethods._createVersionFromBase(
644
+ return dataMethods._createVersionFromBaseObservable(
659
645
  this,
660
646
  this.#httpRequest,
661
647
  publishedId,
@@ -675,7 +661,7 @@ export class ObservableSanityClient {
675
661
  const documentVersion = {...document, _id: documentVersionId}
676
662
  const versionPublishedId = publishedId || getPublishedId(document._id)
677
663
 
678
- return dataMethods._createVersion<R>(
664
+ return dataMethods._createVersionObservable<R>(
679
665
  this,
680
666
  this.#httpRequest,
681
667
  documentVersion,
@@ -724,15 +710,12 @@ export class ObservableSanityClient {
724
710
  delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
725
711
  /**
726
712
  * Deletes a document with the given document ID.
727
- * Returns an observable that resolves to the deleted document.
713
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
728
714
  *
729
715
  * @param id - Document ID to delete
730
716
  * @param options - Options for the mutation
731
717
  */
732
- delete<R extends Record<string, Any> = Record<string, Any>>(
733
- id: string,
734
- options?: BaseMutationOptions,
735
- ): Observable<SanityDocument<R>>
718
+ delete(id: string, options?: BaseMutationOptions): Observable<MultipleMutationResult>
736
719
  /**
737
720
  * Deletes one or more documents matching the given query or document ID.
738
721
  * Returns an observable that resolves to first deleted document.
@@ -779,15 +762,15 @@ export class ObservableSanityClient {
779
762
  ): Observable<MultipleMutationResult>
780
763
  /**
781
764
  * Deletes one or more documents matching the given query or document ID.
782
- * Returns an observable that resolves to first deleted document.
765
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
783
766
  *
784
767
  * @param selection - An object with either an `id` or `query` key defining what to delete
785
768
  * @param options - Options for the mutation
786
769
  */
787
- delete<R extends Record<string, Any> = Record<string, Any>>(
770
+ delete(
788
771
  selection: MutationSelection,
789
772
  options?: BaseMutationOptions,
790
- ): Observable<SanityDocument<R>>
773
+ ): Observable<MultipleMutationResult>
791
774
  delete<R extends Record<string, Any> = Record<string, Any>>(
792
775
  selection: string | MutationSelection,
793
776
  options?:
@@ -799,7 +782,7 @@ export class ObservableSanityClient {
799
782
  ): Observable<
800
783
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
801
784
  > {
802
- return dataMethods._delete<R>(this, this.#httpRequest, selection, options)
785
+ return dataMethods._deleteObservable<R>(this, this.#httpRequest, selection, options)
803
786
  }
804
787
 
805
788
  /**
@@ -837,7 +820,13 @@ export class ObservableSanityClient {
837
820
  ): Observable<SingleActionResult | MultipleActionResult> {
838
821
  const documentVersionId = getDocumentVersionId(publishedId, releaseId)
839
822
 
840
- return dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
823
+ return dataMethods._discardVersionObservable(
824
+ this,
825
+ this.#httpRequest,
826
+ documentVersionId,
827
+ purge,
828
+ options,
829
+ )
841
830
  }
842
831
 
843
832
  /**
@@ -941,7 +930,12 @@ export class ObservableSanityClient {
941
930
 
942
931
  const documentVersion = {...document, _id: documentVersionId}
943
932
 
944
- return dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options)
933
+ return dataMethods._replaceVersionObservable<R>(
934
+ this,
935
+ this.#httpRequest,
936
+ documentVersion,
937
+ options,
938
+ )
945
939
  }
946
940
 
947
941
  /**
@@ -971,7 +965,13 @@ export class ObservableSanityClient {
971
965
  ): Observable<SingleActionResult | MultipleActionResult> {
972
966
  const versionId = getVersionId(publishedId, releaseId)
973
967
 
974
- return dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
968
+ return dataMethods._unpublishVersionObservable(
969
+ this,
970
+ this.#httpRequest,
971
+ versionId,
972
+ publishedId,
973
+ options,
974
+ )
975
975
  }
976
976
 
977
977
  /**
@@ -1020,7 +1020,7 @@ export class ObservableSanityClient {
1020
1020
  ): Observable<MultipleMutationResult>
1021
1021
  /**
1022
1022
  * Perform mutation operations against the configured dataset
1023
- * Returns an observable that resolves to the first mutated document.
1023
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
1024
1024
  *
1025
1025
  * @param operations - Mutation operations to execute
1026
1026
  * @param options - Mutation options
@@ -1028,7 +1028,7 @@ export class ObservableSanityClient {
1028
1028
  mutate<R extends Record<string, Any> = Record<string, Any>>(
1029
1029
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1030
1030
  options?: BaseMutationOptions,
1031
- ): Observable<SanityDocument<R>>
1031
+ ): Observable<MultipleMutationResult>
1032
1032
  mutate<R extends Record<string, Any> = Record<string, Any>>(
1033
1033
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1034
1034
  options?:
@@ -1040,7 +1040,7 @@ export class ObservableSanityClient {
1040
1040
  ): Observable<
1041
1041
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1042
1042
  > {
1043
- return dataMethods._mutate<R>(this, this.#httpRequest, operations, options)
1043
+ return dataMethods._mutateObservable<R>(this, this.#httpRequest, operations, options)
1044
1044
  }
1045
1045
 
1046
1046
  /**
@@ -1102,7 +1102,7 @@ export class ObservableSanityClient {
1102
1102
  operations: Action | Action[],
1103
1103
  options?: BaseActionOptions,
1104
1104
  ): Observable<SingleActionResult | MultipleActionResult> {
1105
- return dataMethods._action(this, this.#httpRequest, operations, options)
1105
+ return dataMethods._actionObservable(this, this.#httpRequest, operations, options)
1106
1106
  }
1107
1107
 
1108
1108
  /**
@@ -1111,7 +1111,7 @@ export class ObservableSanityClient {
1111
1111
  * @param options - Request options
1112
1112
  */
1113
1113
  request<R = Any>(options: RawRequestOptions): Observable<R> {
1114
- return dataMethods._request(this, this.#httpRequest, options)
1114
+ return dataMethods._requestObservable(this, this.#httpRequest, options)
1115
1115
  }
1116
1116
 
1117
1117
  /**
@@ -1148,6 +1148,7 @@ export class SanityClient {
1148
1148
  agent: {
1149
1149
  action: AgentActionsClient
1150
1150
  }
1151
+ functions: FunctionsClient
1151
1152
  releases: ReleasesClient
1152
1153
 
1153
1154
  /**
@@ -1159,7 +1160,6 @@ export class SanityClient {
1159
1160
  * Private properties
1160
1161
  */
1161
1162
  #clientConfig: InitializedClientConfig
1162
- #originalHttpRequest: HttpRequest
1163
1163
  #httpRequest: HttpRequest
1164
1164
 
1165
1165
  /**
@@ -1170,21 +1170,7 @@ export class SanityClient {
1170
1170
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
1171
1171
  this.config(config)
1172
1172
 
1173
- this.#originalHttpRequest = httpRequest
1174
- const requestHandler = config._requestHandler
1175
- this.#httpRequest = requestHandler
1176
- ? (() => {
1177
- let bareClient: SanityClient | undefined
1178
- const wrapped: HttpRequest = (options, requester) => {
1179
- const opts = options as RequestOptions & {url: string}
1180
- if (!bareClient) {
1181
- bareClient = new SanityClient(httpRequest, {...config, _requestHandler: undefined})
1182
- }
1183
- return requestHandler(opts, (o) => httpRequest(o, requester), bareClient)
1184
- }
1185
- return wrapped
1186
- })()
1187
- : httpRequest
1173
+ this.#httpRequest = httpRequest
1188
1174
 
1189
1175
  this.assets = new AssetsClient(this, this.#httpRequest)
1190
1176
  this.datasets = new DatasetsClient(this, this.#httpRequest)
@@ -1197,6 +1183,7 @@ export class SanityClient {
1197
1183
  this.agent = {
1198
1184
  action: new AgentActionsClient(this, this.#httpRequest),
1199
1185
  }
1186
+ this.functions = new FunctionsClient(this, this.#httpRequest)
1200
1187
  this.releases = new ReleasesClient(this, this.#httpRequest)
1201
1188
 
1202
1189
  this.observable = new ObservableSanityClient(httpRequest, config)
@@ -1206,7 +1193,7 @@ export class SanityClient {
1206
1193
  * Clone the client - returns a new instance
1207
1194
  */
1208
1195
  clone(): SanityClient {
1209
- return new SanityClient(this.#originalHttpRequest, this.config())
1196
+ return new SanityClient(this.#httpRequest, this.config())
1210
1197
  }
1211
1198
 
1212
1199
  /**
@@ -1243,11 +1230,11 @@ export class SanityClient {
1243
1230
  */
1244
1231
  withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
1245
1232
  const thisConfig = this.config()
1246
- return new SanityClient(this.#originalHttpRequest, {
1233
+ return new SanityClient(this.#httpRequest, {
1247
1234
  ...thisConfig,
1248
1235
  ...newConfig,
1249
1236
  stega: {
1250
- ...(thisConfig.stega || {}),
1237
+ ...thisConfig.stega,
1251
1238
  ...(typeof newConfig?.stega === 'boolean'
1252
1239
  ? {enabled: newConfig.stega}
1253
1240
  : newConfig?.stega || {}),
@@ -1318,15 +1305,13 @@ export class SanityClient {
1318
1305
  params?: Q,
1319
1306
  options?: QueryOptions,
1320
1307
  ): Promise<RawQueryResponse<ClientReturn<G, R>> | ClientReturn<G, R>> {
1321
- return lastValueFrom(
1322
- dataMethods._fetch<ClientReturn<G, R>, Q>(
1323
- this,
1324
- this.#httpRequest,
1325
- this.#clientConfig.stega,
1326
- query,
1327
- params,
1328
- options,
1329
- ),
1308
+ return dataMethods._fetch<ClientReturn<G, R>, Q>(
1309
+ this,
1310
+ this.#httpRequest,
1311
+ this.#clientConfig.stega,
1312
+ query,
1313
+ params,
1314
+ options,
1330
1315
  )
1331
1316
  }
1332
1317
 
@@ -1371,12 +1356,10 @@ export class SanityClient {
1371
1356
  ): Promise<SanityDocument<R> | undefined | SanityDocument<R>[]> {
1372
1357
  // Implementation needs to handle union type safely
1373
1358
  if (options?.includeAllVersions === true) {
1374
- return lastValueFrom(
1375
- dataMethods._getDocument<R>(this, this.#httpRequest, id, {
1376
- ...options,
1377
- includeAllVersions: true,
1378
- }),
1379
- )
1359
+ return dataMethods._getDocument<R>(this, this.#httpRequest, id, {
1360
+ ...options,
1361
+ includeAllVersions: true,
1362
+ })
1380
1363
  }
1381
1364
  // When includeAllVersions is not true, pass options but only include includeAllVersions if it was explicitly set
1382
1365
  const opts = {
@@ -1385,7 +1368,7 @@ export class SanityClient {
1385
1368
  releaseId: options?.releaseId,
1386
1369
  ...(options && 'includeAllVersions' in options ? {includeAllVersions: false as const} : {}),
1387
1370
  }
1388
- return lastValueFrom(dataMethods._getDocument<R>(this, this.#httpRequest, id, opts))
1371
+ return dataMethods._getDocument<R>(this, this.#httpRequest, id, opts)
1389
1372
  }
1390
1373
 
1391
1374
  /**
@@ -1401,7 +1384,7 @@ export class SanityClient {
1401
1384
  ids: string[],
1402
1385
  options?: {signal?: AbortSignal; tag?: string},
1403
1386
  ): Promise<(SanityDocument<R> | null)[]> {
1404
- return lastValueFrom(dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options))
1387
+ return dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options)
1405
1388
  }
1406
1389
 
1407
1390
  /**
@@ -1415,7 +1398,7 @@ export class SanityClient {
1415
1398
  ids: string[],
1416
1399
  options?: {signal?: AbortSignal; tag?: string},
1417
1400
  ): Promise<Set<string>> {
1418
- return lastValueFrom(dataMethods._documentsExists(this, this.#httpRequest, ids, options))
1401
+ return dataMethods._documentsExists(this, this.#httpRequest, ids, options)
1419
1402
  }
1420
1403
 
1421
1404
  /**
@@ -1484,9 +1467,7 @@ export class SanityClient {
1484
1467
  ): Promise<
1485
1468
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1486
1469
  > {
1487
- return lastValueFrom(
1488
- dataMethods._create<R>(this, this.#httpRequest, document, 'create', options),
1489
- )
1470
+ return dataMethods._create<R>(this, this.#httpRequest, document, 'create', options)
1490
1471
  }
1491
1472
 
1492
1473
  /**
@@ -1555,9 +1536,7 @@ export class SanityClient {
1555
1536
  ): Promise<
1556
1537
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1557
1538
  > {
1558
- return lastValueFrom(
1559
- dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options),
1560
- )
1539
+ return dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options)
1561
1540
  }
1562
1541
 
1563
1542
  /**
@@ -1626,9 +1605,7 @@ export class SanityClient {
1626
1605
  ): Promise<
1627
1606
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1628
1607
  > {
1629
- return lastValueFrom(
1630
- dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options),
1631
- )
1608
+ return dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options)
1632
1609
  }
1633
1610
 
1634
1611
  /**
@@ -1729,16 +1706,14 @@ export class SanityClient {
1729
1706
  options?: BaseActionOptions,
1730
1707
  ): Promise<SingleActionResult | MultipleActionResult> {
1731
1708
  if (!document) {
1732
- return firstValueFrom(
1733
- dataMethods._createVersionFromBase(
1734
- this,
1735
- this.#httpRequest,
1736
- publishedId,
1737
- baseId,
1738
- releaseId,
1739
- ifBaseRevisionId,
1740
- options,
1741
- ),
1709
+ return dataMethods._createVersionFromBase(
1710
+ this,
1711
+ this.#httpRequest,
1712
+ publishedId,
1713
+ baseId,
1714
+ releaseId,
1715
+ ifBaseRevisionId,
1716
+ options,
1742
1717
  )
1743
1718
  }
1744
1719
 
@@ -1751,14 +1726,12 @@ export class SanityClient {
1751
1726
  const documentVersion = {...document, _id: documentVersionId}
1752
1727
  const versionPublishedId = publishedId || getPublishedId(document._id)
1753
1728
 
1754
- return firstValueFrom(
1755
- dataMethods._createVersion<R>(
1756
- this,
1757
- this.#httpRequest,
1758
- documentVersion,
1759
- versionPublishedId,
1760
- options,
1761
- ),
1729
+ return dataMethods._createVersion<R>(
1730
+ this,
1731
+ this.#httpRequest,
1732
+ documentVersion,
1733
+ versionPublishedId,
1734
+ options,
1762
1735
  )
1763
1736
  }
1764
1737
 
@@ -1802,15 +1775,12 @@ export class SanityClient {
1802
1775
  delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1803
1776
  /**
1804
1777
  * Deletes a document with the given document ID.
1805
- * Returns a promise that resolves to the deleted document.
1778
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
1806
1779
  *
1807
1780
  * @param id - Document ID to delete
1808
1781
  * @param options - Options for the mutation
1809
1782
  */
1810
- delete<R extends Record<string, Any> = Record<string, Any>>(
1811
- id: string,
1812
- options?: BaseMutationOptions,
1813
- ): Promise<SanityDocument<R>>
1783
+ delete(id: string, options?: BaseMutationOptions): Promise<MultipleMutationResult>
1814
1784
  /**
1815
1785
  * Deletes one or more documents matching the given query or document ID.
1816
1786
  * Returns a promise that resolves to first deleted document.
@@ -1857,15 +1827,15 @@ export class SanityClient {
1857
1827
  ): Promise<MultipleMutationResult>
1858
1828
  /**
1859
1829
  * Deletes one or more documents matching the given query or document ID.
1860
- * Returns a promise that resolves to first deleted document.
1830
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
1861
1831
  *
1862
1832
  * @param selection - An object with either an `id` or `query` key defining what to delete
1863
1833
  * @param options - Options for the mutation
1864
1834
  */
1865
- delete<R extends Record<string, Any> = Record<string, Any>>(
1835
+ delete(
1866
1836
  selection: MutationSelection,
1867
1837
  options?: BaseMutationOptions,
1868
- ): Promise<SanityDocument<R>>
1838
+ ): Promise<MultipleMutationResult>
1869
1839
  delete<R extends Record<string, Any> = Record<string, Any>>(
1870
1840
  selection: string | MutationSelection,
1871
1841
  options?:
@@ -1877,7 +1847,7 @@ export class SanityClient {
1877
1847
  ): Promise<
1878
1848
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1879
1849
  > {
1880
- return lastValueFrom(dataMethods._delete<R>(this, this.#httpRequest, selection, options))
1850
+ return dataMethods._delete<R>(this, this.#httpRequest, selection, options)
1881
1851
  }
1882
1852
 
1883
1853
  /**
@@ -1915,9 +1885,7 @@ export class SanityClient {
1915
1885
  ): Promise<SingleActionResult | MultipleActionResult> {
1916
1886
  const documentVersionId = getDocumentVersionId(publishedId, releaseId)
1917
1887
 
1918
- return lastValueFrom(
1919
- dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options),
1920
- )
1888
+ return dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
1921
1889
  }
1922
1890
 
1923
1891
  /**
@@ -2022,9 +1990,7 @@ export class SanityClient {
2022
1990
 
2023
1991
  const documentVersion = {...document, _id: documentVersionId}
2024
1992
 
2025
- return firstValueFrom(
2026
- dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options),
2027
- )
1993
+ return dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options)
2028
1994
  }
2029
1995
 
2030
1996
  /**
@@ -2054,9 +2020,7 @@ export class SanityClient {
2054
2020
  ): Promise<SingleActionResult | MultipleActionResult> {
2055
2021
  const versionId = getVersionId(publishedId, releaseId)
2056
2022
 
2057
- return lastValueFrom(
2058
- dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options),
2059
- )
2023
+ return dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
2060
2024
  }
2061
2025
 
2062
2026
  /**
@@ -2105,7 +2069,7 @@ export class SanityClient {
2105
2069
  ): Promise<MultipleMutationResult>
2106
2070
  /**
2107
2071
  * Perform mutation operations against the configured dataset
2108
- * Returns a promise that resolves to the first mutated document.
2072
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
2109
2073
  *
2110
2074
  * @param operations - Mutation operations to execute
2111
2075
  * @param options - Mutation options
@@ -2113,7 +2077,7 @@ export class SanityClient {
2113
2077
  mutate<R extends Record<string, Any> = Record<string, Any>>(
2114
2078
  operations: Mutation<R>[] | Patch | Transaction,
2115
2079
  options?: BaseMutationOptions,
2116
- ): Promise<SanityDocument<R>>
2080
+ ): Promise<MultipleMutationResult>
2117
2081
  mutate<R extends Record<string, Any> = Record<string, Any>>(
2118
2082
  operations: Mutation<R>[] | Patch | Transaction,
2119
2083
  options?:
@@ -2125,7 +2089,7 @@ export class SanityClient {
2125
2089
  ): Promise<
2126
2090
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
2127
2091
  > {
2128
- return lastValueFrom(dataMethods._mutate<R>(this, this.#httpRequest, operations, options))
2092
+ return dataMethods._mutate<R>(this, this.#httpRequest, operations, options)
2129
2093
  }
2130
2094
 
2131
2095
  /**
@@ -2188,7 +2152,7 @@ export class SanityClient {
2188
2152
  operations: Action | Action[],
2189
2153
  options?: BaseActionOptions,
2190
2154
  ): Promise<SingleActionResult | MultipleActionResult> {
2191
- return lastValueFrom(dataMethods._action(this, this.#httpRequest, operations, options))
2155
+ return dataMethods._action(this, this.#httpRequest, operations, options)
2192
2156
  }
2193
2157
 
2194
2158
  /**
@@ -2199,7 +2163,7 @@ export class SanityClient {
2199
2163
  * @returns Promise resolving to the response body
2200
2164
  */
2201
2165
  request<R = Any>(options: RawRequestOptions): Promise<R> {
2202
- return lastValueFrom(dataMethods._request<R>(this, this.#httpRequest, options))
2166
+ return dataMethods._request<R>(this, this.#httpRequest, options)
2203
2167
  }
2204
2168
 
2205
2169
  /**
@@ -2213,7 +2177,7 @@ export class SanityClient {
2213
2177
  * @internal
2214
2178
  */
2215
2179
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
2216
- return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
2180
+ return dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options)
2217
2181
  }
2218
2182
 
2219
2183
  /**