@sanity/client 7.26.2 → 8.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 (130) hide show
  1. package/README.md +5 -377
  2. package/dist/browserUpload-CQgx9YYo.js +86 -0
  3. package/dist/browserUpload-CQgx9YYo.js.map +1 -0
  4. package/dist/browserUpload-icWlVP15.js +86 -0
  5. package/dist/browserUpload-icWlVP15.js.map +1 -0
  6. package/dist/config-a8VajuEY.js +126 -0
  7. package/dist/config-a8VajuEY.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 +107 -6723
  16. package/dist/index.js +2822 -2847
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index.d.cts → index.node.d.ts} +4291 -5328
  19. package/dist/index.node.js +3131 -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-CJxcN16k.js +372 -0
  27. package/dist/request-CJxcN16k.js.map +1 -0
  28. package/dist/request-k7VS_NnC.js +354 -0
  29. package/dist/request-k7VS_NnC.js.map +1 -0
  30. package/dist/resolveEditInfo-sq7yF78q.js +325 -0
  31. package/dist/resolveEditInfo-sq7yF78q.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-B2fGArSf.js +163 -0
  39. package/dist/stegaEncodeSourceMap-B2fGArSf.js.map +1 -0
  40. package/dist/stegaEncodeSourceMap-DkoIlutY.js +367 -0
  41. package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +1 -0
  42. package/dist/{index.browser.d.cts → types-CUxZSgB2.d.ts} +3956 -5256
  43. package/dist/types-CfGzbXrl.d.ts +108 -0
  44. package/package.json +64 -141
  45. package/src/SanityClient.ts +82 -117
  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 +71 -23
  54. package/src/csm/applySourceDocuments.ts +3 -1
  55. package/src/csm/createEditUrl.ts +1 -1
  56. package/src/csm/draftUtils.ts +0 -1
  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 +801 -349
  61. package/src/data/eventsource.ts +13 -10
  62. package/src/data/listen.ts +18 -23
  63. package/src/data/live.ts +44 -27
  64. package/src/data/resolveEventSourceFetch.ts +96 -0
  65. package/src/datasets/DatasetsClient.ts +58 -41
  66. package/src/defineCreateClient.ts +35 -23
  67. package/src/http/browserMiddleware.ts +7 -1
  68. package/src/http/browserUpload.ts +162 -0
  69. package/src/http/errors.ts +60 -6
  70. package/src/http/nodeMiddleware.ts +94 -30
  71. package/src/http/request.ts +310 -87
  72. package/src/http/requestOptions.ts +131 -15
  73. package/src/{index.browser.ts → index.node.ts} +9 -4
  74. package/src/index.ts +4 -3
  75. package/src/mediaLibrary/MediaLibraryVideoClient.ts +26 -11
  76. package/src/projects/ProjectsClient.ts +18 -16
  77. package/src/releases/ReleasesClient.ts +38 -33
  78. package/src/stega/index.ts +1 -2
  79. package/src/stega/stegaEncodeSourceMap.ts +5 -0
  80. package/src/stega/types.ts +2 -2
  81. package/src/types.ts +148 -105
  82. package/src/users/UsersClient.ts +10 -14
  83. package/src/util/shareReplayLatest.ts +1 -1
  84. package/src/warnings.ts +6 -1
  85. package/dist/_chunks-cjs/config.cjs +0 -206
  86. package/dist/_chunks-cjs/config.cjs.map +0 -1
  87. package/dist/_chunks-cjs/isRecord.cjs +0 -6
  88. package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
  89. package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
  90. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
  91. package/dist/_chunks-cjs/stegaClean.cjs +0 -46
  92. package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
  93. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
  94. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
  95. package/dist/_chunks-es/config.js +0 -207
  96. package/dist/_chunks-es/config.js.map +0 -1
  97. package/dist/_chunks-es/isRecord.js +0 -7
  98. package/dist/_chunks-es/isRecord.js.map +0 -1
  99. package/dist/_chunks-es/resolveEditInfo.js +0 -335
  100. package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
  101. package/dist/_chunks-es/stegaClean.js +0 -47
  102. package/dist/_chunks-es/stegaClean.js.map +0 -1
  103. package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
  104. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
  105. package/dist/csm.cjs +0 -99
  106. package/dist/csm.cjs.map +0 -1
  107. package/dist/csm.d.cts +0 -391
  108. package/dist/index.browser.cjs +0 -3106
  109. package/dist/index.browser.cjs.map +0 -1
  110. package/dist/index.browser.d.ts +0 -6802
  111. package/dist/index.browser.js +0 -3082
  112. package/dist/index.browser.js.map +0 -1
  113. package/dist/index.cjs +0 -2946
  114. package/dist/index.cjs.map +0 -1
  115. package/dist/media-library.cjs +0 -20
  116. package/dist/media-library.cjs.map +0 -1
  117. package/dist/media-library.d.cts +0 -117
  118. package/dist/stega.browser.cjs +0 -29
  119. package/dist/stega.browser.cjs.map +0 -1
  120. package/dist/stega.browser.d.cts +0 -7200
  121. package/dist/stega.browser.d.ts +0 -7200
  122. package/dist/stega.browser.js +0 -24
  123. package/dist/stega.browser.js.map +0 -1
  124. package/dist/stega.cjs +0 -29
  125. package/dist/stega.cjs.map +0 -1
  126. package/dist/stega.d.cts +0 -7200
  127. package/src/data/eventsourcePolyfill.ts +0 -7
  128. package/umd/.gitkeep +0 -1
  129. package/umd/sanityClient.js +0 -6543
  130. 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'
@@ -43,7 +43,6 @@ import type {
43
43
  RawQuerylessQueryResponse,
44
44
  RawQueryResponse,
45
45
  RawRequestOptions,
46
- RequestOptions,
47
46
  SanityDocument,
48
47
  SanityDocumentStub,
49
48
  SingleActionResult,
@@ -88,7 +87,6 @@ export class ObservableSanityClient {
88
87
  * Private properties
89
88
  */
90
89
  #clientConfig: InitializedClientConfig
91
- #originalHttpRequest: HttpRequest
92
90
  #httpRequest: HttpRequest
93
91
 
94
92
  /**
@@ -99,22 +97,7 @@ export class ObservableSanityClient {
99
97
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
100
98
  this.config(config)
101
99
 
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
100
+ this.#httpRequest = httpRequest
118
101
 
119
102
  this.assets = new ObservableAssetsClient(this, this.#httpRequest)
120
103
  this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
@@ -134,7 +117,7 @@ export class ObservableSanityClient {
134
117
  * Clone the client - returns a new instance
135
118
  */
136
119
  clone(): ObservableSanityClient {
137
- return new ObservableSanityClient(this.#originalHttpRequest, this.config())
120
+ return new ObservableSanityClient(this.#httpRequest, this.config())
138
121
  }
139
122
 
140
123
  /**
@@ -167,11 +150,11 @@ export class ObservableSanityClient {
167
150
  */
168
151
  withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
169
152
  const thisConfig = this.config()
170
- return new ObservableSanityClient(this.#originalHttpRequest, {
153
+ return new ObservableSanityClient(this.#httpRequest, {
171
154
  ...thisConfig,
172
155
  ...newConfig,
173
156
  stega: {
174
- ...(thisConfig.stega || {}),
157
+ ...thisConfig.stega,
175
158
  ...(typeof newConfig?.stega === 'boolean'
176
159
  ? {enabled: newConfig.stega}
177
160
  : newConfig?.stega || {}),
@@ -242,7 +225,7 @@ export class ObservableSanityClient {
242
225
  params?: Q,
243
226
  options?: QueryOptions,
244
227
  ): Observable<RawQueryResponse<R> | R> {
245
- return dataMethods._fetch<R, Q>(
228
+ return dataMethods._fetchObservable<R, Q>(
246
229
  this,
247
230
  this.#httpRequest,
248
231
  this.#clientConfig.stega,
@@ -293,7 +276,7 @@ export class ObservableSanityClient {
293
276
  ): Observable<SanityDocument<R> | undefined | SanityDocument<R>[]> {
294
277
  // Implementation needs to handle union type safely
295
278
  if (options?.includeAllVersions === true) {
296
- return dataMethods._getDocument<R>(this, this.#httpRequest, id, {
279
+ return dataMethods._getDocumentObservable<R>(this, this.#httpRequest, id, {
297
280
  ...options,
298
281
  includeAllVersions: true,
299
282
  })
@@ -305,7 +288,7 @@ export class ObservableSanityClient {
305
288
  releaseId: options?.releaseId,
306
289
  ...(options && 'includeAllVersions' in options ? {includeAllVersions: false as const} : {}),
307
290
  }
308
- return dataMethods._getDocument<R>(this, this.#httpRequest, id, opts)
291
+ return dataMethods._getDocumentObservable<R>(this, this.#httpRequest, id, opts)
309
292
  }
310
293
 
311
294
  /**
@@ -321,7 +304,7 @@ export class ObservableSanityClient {
321
304
  ids: string[],
322
305
  options?: {tag?: string},
323
306
  ): Observable<(SanityDocument<R> | null)[]> {
324
- return dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options)
307
+ return dataMethods._getDocumentsObservable<R>(this, this.#httpRequest, ids, options)
325
308
  }
326
309
 
327
310
  /**
@@ -335,7 +318,7 @@ export class ObservableSanityClient {
335
318
  ids: string[],
336
319
  options?: {signal?: AbortSignal; tag?: string},
337
320
  ): Observable<Set<string>> {
338
- return dataMethods._documentsExists(this, this.#httpRequest, ids, options)
321
+ return dataMethods._documentsExistsObservable(this, this.#httpRequest, ids, options)
339
322
  }
340
323
 
341
324
  /**
@@ -404,7 +387,7 @@ export class ObservableSanityClient {
404
387
  ): Observable<
405
388
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
406
389
  > {
407
- return dataMethods._create<R>(this, this.#httpRequest, document, 'create', options)
390
+ return dataMethods._createObservable<R>(this, this.#httpRequest, document, 'create', options)
408
391
  }
409
392
 
410
393
  /**
@@ -473,7 +456,7 @@ export class ObservableSanityClient {
473
456
  ): Observable<
474
457
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
475
458
  > {
476
- return dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options)
459
+ return dataMethods._createIfNotExistsObservable<R>(this, this.#httpRequest, document, options)
477
460
  }
478
461
 
479
462
  /**
@@ -542,7 +525,7 @@ export class ObservableSanityClient {
542
525
  ): Observable<
543
526
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
544
527
  > {
545
- return dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options)
528
+ return dataMethods._createOrReplaceObservable<R>(this, this.#httpRequest, document, options)
546
529
  }
547
530
 
548
531
  /**
@@ -655,7 +638,7 @@ export class ObservableSanityClient {
655
638
  options?: BaseActionOptions,
656
639
  ): Observable<SingleActionResult | MultipleActionResult> {
657
640
  if (!document) {
658
- return dataMethods._createVersionFromBase(
641
+ return dataMethods._createVersionFromBaseObservable(
659
642
  this,
660
643
  this.#httpRequest,
661
644
  publishedId,
@@ -675,7 +658,7 @@ export class ObservableSanityClient {
675
658
  const documentVersion = {...document, _id: documentVersionId}
676
659
  const versionPublishedId = publishedId || getPublishedId(document._id)
677
660
 
678
- return dataMethods._createVersion<R>(
661
+ return dataMethods._createVersionObservable<R>(
679
662
  this,
680
663
  this.#httpRequest,
681
664
  documentVersion,
@@ -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
  /**
@@ -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
  /**
@@ -1159,7 +1159,6 @@ export class SanityClient {
1159
1159
  * Private properties
1160
1160
  */
1161
1161
  #clientConfig: InitializedClientConfig
1162
- #originalHttpRequest: HttpRequest
1163
1162
  #httpRequest: HttpRequest
1164
1163
 
1165
1164
  /**
@@ -1170,21 +1169,7 @@ export class SanityClient {
1170
1169
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
1171
1170
  this.config(config)
1172
1171
 
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
1172
+ this.#httpRequest = httpRequest
1188
1173
 
1189
1174
  this.assets = new AssetsClient(this, this.#httpRequest)
1190
1175
  this.datasets = new DatasetsClient(this, this.#httpRequest)
@@ -1206,7 +1191,7 @@ export class SanityClient {
1206
1191
  * Clone the client - returns a new instance
1207
1192
  */
1208
1193
  clone(): SanityClient {
1209
- return new SanityClient(this.#originalHttpRequest, this.config())
1194
+ return new SanityClient(this.#httpRequest, this.config())
1210
1195
  }
1211
1196
 
1212
1197
  /**
@@ -1243,11 +1228,11 @@ export class SanityClient {
1243
1228
  */
1244
1229
  withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
1245
1230
  const thisConfig = this.config()
1246
- return new SanityClient(this.#originalHttpRequest, {
1231
+ return new SanityClient(this.#httpRequest, {
1247
1232
  ...thisConfig,
1248
1233
  ...newConfig,
1249
1234
  stega: {
1250
- ...(thisConfig.stega || {}),
1235
+ ...thisConfig.stega,
1251
1236
  ...(typeof newConfig?.stega === 'boolean'
1252
1237
  ? {enabled: newConfig.stega}
1253
1238
  : newConfig?.stega || {}),
@@ -1318,15 +1303,13 @@ export class SanityClient {
1318
1303
  params?: Q,
1319
1304
  options?: QueryOptions,
1320
1305
  ): 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
- ),
1306
+ return dataMethods._fetch<ClientReturn<G, R>, Q>(
1307
+ this,
1308
+ this.#httpRequest,
1309
+ this.#clientConfig.stega,
1310
+ query,
1311
+ params,
1312
+ options,
1330
1313
  )
1331
1314
  }
1332
1315
 
@@ -1371,12 +1354,10 @@ export class SanityClient {
1371
1354
  ): Promise<SanityDocument<R> | undefined | SanityDocument<R>[]> {
1372
1355
  // Implementation needs to handle union type safely
1373
1356
  if (options?.includeAllVersions === true) {
1374
- return lastValueFrom(
1375
- dataMethods._getDocument<R>(this, this.#httpRequest, id, {
1376
- ...options,
1377
- includeAllVersions: true,
1378
- }),
1379
- )
1357
+ return dataMethods._getDocument<R>(this, this.#httpRequest, id, {
1358
+ ...options,
1359
+ includeAllVersions: true,
1360
+ })
1380
1361
  }
1381
1362
  // When includeAllVersions is not true, pass options but only include includeAllVersions if it was explicitly set
1382
1363
  const opts = {
@@ -1385,7 +1366,7 @@ export class SanityClient {
1385
1366
  releaseId: options?.releaseId,
1386
1367
  ...(options && 'includeAllVersions' in options ? {includeAllVersions: false as const} : {}),
1387
1368
  }
1388
- return lastValueFrom(dataMethods._getDocument<R>(this, this.#httpRequest, id, opts))
1369
+ return dataMethods._getDocument<R>(this, this.#httpRequest, id, opts)
1389
1370
  }
1390
1371
 
1391
1372
  /**
@@ -1401,7 +1382,7 @@ export class SanityClient {
1401
1382
  ids: string[],
1402
1383
  options?: {signal?: AbortSignal; tag?: string},
1403
1384
  ): Promise<(SanityDocument<R> | null)[]> {
1404
- return lastValueFrom(dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options))
1385
+ return dataMethods._getDocuments<R>(this, this.#httpRequest, ids, options)
1405
1386
  }
1406
1387
 
1407
1388
  /**
@@ -1415,7 +1396,7 @@ export class SanityClient {
1415
1396
  ids: string[],
1416
1397
  options?: {signal?: AbortSignal; tag?: string},
1417
1398
  ): Promise<Set<string>> {
1418
- return lastValueFrom(dataMethods._documentsExists(this, this.#httpRequest, ids, options))
1399
+ return dataMethods._documentsExists(this, this.#httpRequest, ids, options)
1419
1400
  }
1420
1401
 
1421
1402
  /**
@@ -1484,9 +1465,7 @@ export class SanityClient {
1484
1465
  ): Promise<
1485
1466
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1486
1467
  > {
1487
- return lastValueFrom(
1488
- dataMethods._create<R>(this, this.#httpRequest, document, 'create', options),
1489
- )
1468
+ return dataMethods._create<R>(this, this.#httpRequest, document, 'create', options)
1490
1469
  }
1491
1470
 
1492
1471
  /**
@@ -1555,9 +1534,7 @@ export class SanityClient {
1555
1534
  ): Promise<
1556
1535
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1557
1536
  > {
1558
- return lastValueFrom(
1559
- dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options),
1560
- )
1537
+ return dataMethods._createIfNotExists<R>(this, this.#httpRequest, document, options)
1561
1538
  }
1562
1539
 
1563
1540
  /**
@@ -1626,9 +1603,7 @@ export class SanityClient {
1626
1603
  ): Promise<
1627
1604
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1628
1605
  > {
1629
- return lastValueFrom(
1630
- dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options),
1631
- )
1606
+ return dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options)
1632
1607
  }
1633
1608
 
1634
1609
  /**
@@ -1729,16 +1704,14 @@ export class SanityClient {
1729
1704
  options?: BaseActionOptions,
1730
1705
  ): Promise<SingleActionResult | MultipleActionResult> {
1731
1706
  if (!document) {
1732
- return firstValueFrom(
1733
- dataMethods._createVersionFromBase(
1734
- this,
1735
- this.#httpRequest,
1736
- publishedId,
1737
- baseId,
1738
- releaseId,
1739
- ifBaseRevisionId,
1740
- options,
1741
- ),
1707
+ return dataMethods._createVersionFromBase(
1708
+ this,
1709
+ this.#httpRequest,
1710
+ publishedId,
1711
+ baseId,
1712
+ releaseId,
1713
+ ifBaseRevisionId,
1714
+ options,
1742
1715
  )
1743
1716
  }
1744
1717
 
@@ -1751,14 +1724,12 @@ export class SanityClient {
1751
1724
  const documentVersion = {...document, _id: documentVersionId}
1752
1725
  const versionPublishedId = publishedId || getPublishedId(document._id)
1753
1726
 
1754
- return firstValueFrom(
1755
- dataMethods._createVersion<R>(
1756
- this,
1757
- this.#httpRequest,
1758
- documentVersion,
1759
- versionPublishedId,
1760
- options,
1761
- ),
1727
+ return dataMethods._createVersion<R>(
1728
+ this,
1729
+ this.#httpRequest,
1730
+ documentVersion,
1731
+ versionPublishedId,
1732
+ options,
1762
1733
  )
1763
1734
  }
1764
1735
 
@@ -1877,7 +1848,7 @@ export class SanityClient {
1877
1848
  ): Promise<
1878
1849
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
1879
1850
  > {
1880
- return lastValueFrom(dataMethods._delete<R>(this, this.#httpRequest, selection, options))
1851
+ return dataMethods._delete<R>(this, this.#httpRequest, selection, options)
1881
1852
  }
1882
1853
 
1883
1854
  /**
@@ -1915,9 +1886,7 @@ export class SanityClient {
1915
1886
  ): Promise<SingleActionResult | MultipleActionResult> {
1916
1887
  const documentVersionId = getDocumentVersionId(publishedId, releaseId)
1917
1888
 
1918
- return lastValueFrom(
1919
- dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options),
1920
- )
1889
+ return dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
1921
1890
  }
1922
1891
 
1923
1892
  /**
@@ -2022,9 +1991,7 @@ export class SanityClient {
2022
1991
 
2023
1992
  const documentVersion = {...document, _id: documentVersionId}
2024
1993
 
2025
- return firstValueFrom(
2026
- dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options),
2027
- )
1994
+ return dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options)
2028
1995
  }
2029
1996
 
2030
1997
  /**
@@ -2054,9 +2021,7 @@ export class SanityClient {
2054
2021
  ): Promise<SingleActionResult | MultipleActionResult> {
2055
2022
  const versionId = getVersionId(publishedId, releaseId)
2056
2023
 
2057
- return lastValueFrom(
2058
- dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options),
2059
- )
2024
+ return dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
2060
2025
  }
2061
2026
 
2062
2027
  /**
@@ -2125,7 +2090,7 @@ export class SanityClient {
2125
2090
  ): Promise<
2126
2091
  SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
2127
2092
  > {
2128
- return lastValueFrom(dataMethods._mutate<R>(this, this.#httpRequest, operations, options))
2093
+ return dataMethods._mutate<R>(this, this.#httpRequest, operations, options)
2129
2094
  }
2130
2095
 
2131
2096
  /**
@@ -2188,7 +2153,7 @@ export class SanityClient {
2188
2153
  operations: Action | Action[],
2189
2154
  options?: BaseActionOptions,
2190
2155
  ): Promise<SingleActionResult | MultipleActionResult> {
2191
- return lastValueFrom(dataMethods._action(this, this.#httpRequest, operations, options))
2156
+ return dataMethods._action(this, this.#httpRequest, operations, options)
2192
2157
  }
2193
2158
 
2194
2159
  /**
@@ -2199,7 +2164,7 @@ export class SanityClient {
2199
2164
  * @returns Promise resolving to the response body
2200
2165
  */
2201
2166
  request<R = Any>(options: RawRequestOptions): Promise<R> {
2202
- return lastValueFrom(dataMethods._request<R>(this, this.#httpRequest, options))
2167
+ return dataMethods._request<R>(this, this.#httpRequest, options)
2203
2168
  }
2204
2169
 
2205
2170
  /**
@@ -2213,7 +2178,7 @@ export class SanityClient {
2213
2178
  * @internal
2214
2179
  */
2215
2180
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
2216
- return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
2181
+ return dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options)
2217
2182
  }
2218
2183
 
2219
2184
  /**
@@ -1,12 +1,12 @@
1
- import {lastValueFrom, type Observable} from 'rxjs'
1
+ import {type Observable} from 'rxjs'
2
2
 
3
3
  import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
4
4
  import type {Any, HttpRequest, IdentifiedSanityDocumentStub} from '../../types'
5
- import {_generate, type GenerateInstruction} from './generate'
5
+ import {_generate, _generateObservable, type GenerateInstruction} from './generate'
6
6
  import {_patch, type PatchDocument} from './patch'
7
7
  import {_prompt, type PromptRequest} from './prompt'
8
- import {_transform, type TransformDocument} from './transform'
9
- import {_translate, type TranslateDocument} from './translate'
8
+ import {_transform, _transformObservable, type TransformDocument} from './transform'
9
+ import {_translate, _translateObservable, type TranslateDocument} from './translate'
10
10
 
11
11
  /** @public */
12
12
  export class ObservableAgentsActionClient {
@@ -28,7 +28,7 @@ export class ObservableAgentsActionClient {
28
28
  ? {_id: string}
29
29
  : IdentifiedSanityDocumentStub & DocumentShape
30
30
  > {
31
- return _generate(this.#client, this.#httpRequest, request)
31
+ return _generateObservable(this.#client, this.#httpRequest, request)
32
32
  }
33
33
 
34
34
  /**
@@ -42,7 +42,7 @@ export class ObservableAgentsActionClient {
42
42
  ? {_id: string}
43
43
  : IdentifiedSanityDocumentStub & DocumentShape
44
44
  > {
45
- return _transform(this.#client, this.#httpRequest, request)
45
+ return _transformObservable(this.#client, this.#httpRequest, request)
46
46
  }
47
47
 
48
48
  /**
@@ -56,7 +56,7 @@ export class ObservableAgentsActionClient {
56
56
  ? {_id: string}
57
57
  : IdentifiedSanityDocumentStub & DocumentShape
58
58
  > {
59
- return _translate(this.#client, this.#httpRequest, request)
59
+ return _translateObservable(this.#client, this.#httpRequest, request)
60
60
  }
61
61
  }
62
62
 
@@ -80,7 +80,7 @@ export class AgentActionsClient {
80
80
  ? {_id: string}
81
81
  : IdentifiedSanityDocumentStub & DocumentShape
82
82
  > {
83
- return lastValueFrom(_generate(this.#client, this.#httpRequest, request))
83
+ return _generate(this.#client, this.#httpRequest, request)
84
84
  }
85
85
 
86
86
  /**
@@ -94,7 +94,7 @@ export class AgentActionsClient {
94
94
  ? {_id: string}
95
95
  : IdentifiedSanityDocumentStub & DocumentShape
96
96
  > {
97
- return lastValueFrom(_transform(this.#client, this.#httpRequest, request))
97
+ return _transform(this.#client, this.#httpRequest, request)
98
98
  }
99
99
 
100
100
  /**
@@ -108,7 +108,7 @@ export class AgentActionsClient {
108
108
  ? {_id: string}
109
109
  : IdentifiedSanityDocumentStub & DocumentShape
110
110
  > {
111
- return lastValueFrom(_translate(this.#client, this.#httpRequest, request))
111
+ return _translate(this.#client, this.#httpRequest, request)
112
112
  }
113
113
 
114
114
  /**
@@ -118,7 +118,7 @@ export class AgentActionsClient {
118
118
  prompt<const DocumentShape extends Record<string, Any>>(
119
119
  request: PromptRequest<DocumentShape>,
120
120
  ): Promise<(typeof request)['format'] extends 'json' ? DocumentShape : string> {
121
- return lastValueFrom(_prompt(this.#client, this.#httpRequest, request))
121
+ return _prompt(this.#client, this.#httpRequest, request)
122
122
  }
123
123
 
124
124
  /**
@@ -133,6 +133,6 @@ export class AgentActionsClient {
133
133
  ? {_id: string}
134
134
  : IdentifiedSanityDocumentStub & DocumentShape
135
135
  > {
136
- return lastValueFrom(_patch(this.#client, this.#httpRequest, request))
136
+ return _patch(this.#client, this.#httpRequest, request)
137
137
  }
138
138
  }
@@ -135,7 +135,8 @@ export interface GroqAgentActionParam {
135
135
 
136
136
  /** @beta */
137
137
  export type AgentActionTypeConfig =
138
- {include: string[]; exclude?: never} | {exclude: string[]; include?: never}
138
+ | {include: string[]; exclude?: never}
139
+ | {exclude: string[]; include?: never}
139
140
 
140
141
  /** @beta */
141
142
  export type AgentActionPathSegment = string | {_key: string}
@@ -1,6 +1,6 @@
1
1
  import {type Observable} from 'rxjs'
2
2
 
3
- import {_request} from '../../data/dataMethods'
3
+ import {_request, _requestObservable} from '../../data/dataMethods'
4
4
  import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
5
5
  import type {AgentActionParams, Any, HttpRequest, IdentifiedSanityDocumentStub} from '../../types'
6
6
  import {hasDataset} from '../../validators'
@@ -271,23 +271,26 @@ interface GenerateTargetDocumentRequest<T extends Record<string, Any> = Record<s
271
271
 
272
272
  /** @beta */
273
273
  export type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
274
- GenerateExistingDocumentRequest | GenerateTargetDocumentRequest<T>
274
+ | GenerateExistingDocumentRequest
275
+ | GenerateTargetDocumentRequest<T>
275
276
  ) &
276
277
  GenerateRequestBase &
277
278
  AgentActionSync
278
279
 
279
280
  /** @beta */
280
281
  export type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
281
- GenerateExistingDocumentRequest | GenerateTargetDocumentRequest<T>
282
+ | GenerateExistingDocumentRequest
283
+ | GenerateTargetDocumentRequest<T>
282
284
  ) &
283
285
  GenerateRequestBase &
284
286
  AgentActionAsync
285
287
 
286
288
  /** @beta */
287
289
  export type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
288
- GenerateSyncInstruction<T> | GenerateAsyncInstruction<T>
290
+ | GenerateSyncInstruction<T>
291
+ | GenerateAsyncInstruction<T>
289
292
 
290
- export function _generate<DocumentShape extends Record<string, Any>>(
293
+ export function _generateObservable<DocumentShape extends Record<string, Any>>(
291
294
  client: SanityClient | ObservableSanityClient,
292
295
  httpRequest: HttpRequest,
293
296
  request: GenerateInstruction<DocumentShape>,
@@ -295,11 +298,28 @@ export function _generate<DocumentShape extends Record<string, Any>>(
295
298
  (typeof request)['async'] extends true
296
299
  ? {_id: string}
297
300
  : IdentifiedSanityDocumentStub & DocumentShape
301
+ > {
302
+ const dataset = hasDataset(client.config())
303
+ return _requestObservable(client, httpRequest, {
304
+ method: 'POST',
305
+ url: `/agent/action/generate/${dataset}`,
306
+ body: request,
307
+ })
308
+ }
309
+
310
+ export function _generate<DocumentShape extends Record<string, Any>>(
311
+ client: SanityClient | ObservableSanityClient,
312
+ httpRequest: HttpRequest,
313
+ request: GenerateInstruction<DocumentShape>,
314
+ ): Promise<
315
+ (typeof request)['async'] extends true
316
+ ? {_id: string}
317
+ : IdentifiedSanityDocumentStub & DocumentShape
298
318
  > {
299
319
  const dataset = hasDataset(client.config())
300
320
  return _request(client, httpRequest, {
301
321
  method: 'POST',
302
- uri: `/agent/action/generate/${dataset}`,
322
+ url: `/agent/action/generate/${dataset}`,
303
323
  body: request,
304
324
  })
305
325
  }