@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.
- package/README.md +5 -377
- package/dist/browserUpload-CQgx9YYo.js +86 -0
- package/dist/browserUpload-CQgx9YYo.js.map +1 -0
- package/dist/browserUpload-icWlVP15.js +86 -0
- package/dist/browserUpload-icWlVP15.js.map +1 -0
- package/dist/config-a8VajuEY.js +126 -0
- package/dist/config-a8VajuEY.js.map +1 -0
- package/dist/csm.d.ts +122 -335
- package/dist/csm.js +79 -91
- package/dist/csm.js.map +1 -1
- package/dist/dist-C9ExSk2R.js +73 -0
- package/dist/dist-C9ExSk2R.js.map +1 -0
- package/dist/dist-Z8cIRxoB.js +69 -0
- package/dist/dist-Z8cIRxoB.js.map +1 -0
- package/dist/index.d.ts +107 -6723
- package/dist/index.js +2822 -2847
- package/dist/index.js.map +1 -1
- package/dist/{index.d.cts → index.node.d.ts} +4291 -5328
- package/dist/index.node.js +3131 -0
- package/dist/index.node.js.map +1 -0
- package/dist/isRecord-Kfmt-nk-.js +7 -0
- package/dist/isRecord-Kfmt-nk-.js.map +1 -0
- package/dist/media-library.d.ts +9 -100
- package/dist/media-library.js +36 -14
- package/dist/media-library.js.map +1 -1
- package/dist/request-CJxcN16k.js +372 -0
- package/dist/request-CJxcN16k.js.map +1 -0
- package/dist/request-k7VS_NnC.js +354 -0
- package/dist/request-k7VS_NnC.js.map +1 -0
- package/dist/resolveEditInfo-sq7yF78q.js +325 -0
- package/dist/resolveEditInfo-sq7yF78q.js.map +1 -0
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/stega.d.ts +78 -7137
- package/dist/stega.js +27 -20
- package/dist/stega.js.map +1 -1
- package/dist/stegaClean-C18wLWau.js +21 -0
- package/dist/stegaClean-C18wLWau.js.map +1 -0
- package/dist/stegaEncodeSourceMap-B2fGArSf.js +163 -0
- package/dist/stegaEncodeSourceMap-B2fGArSf.js.map +1 -0
- package/dist/stegaEncodeSourceMap-DkoIlutY.js +367 -0
- package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +1 -0
- package/dist/{index.browser.d.cts → types-CUxZSgB2.d.ts} +3956 -5256
- package/dist/types-CfGzbXrl.d.ts +108 -0
- package/package.json +64 -141
- package/src/SanityClient.ts +82 -117
- package/src/agent/actions/AgentActionsClient.ts +12 -12
- package/src/agent/actions/commonTypes.ts +2 -1
- package/src/agent/actions/generate.ts +26 -6
- package/src/agent/actions/patch.ts +27 -7
- package/src/agent/actions/prompt.ts +19 -5
- package/src/agent/actions/transform.ts +23 -5
- package/src/agent/actions/translate.ts +23 -5
- package/src/assets/AssetsClient.ts +71 -23
- package/src/csm/applySourceDocuments.ts +3 -1
- package/src/csm/createEditUrl.ts +1 -1
- package/src/csm/draftUtils.ts +0 -1
- package/src/csm/index.ts +2 -2
- package/src/csm/studioPath.ts +2 -1
- package/src/csm/types.ts +8 -2
- package/src/data/dataMethods.ts +801 -349
- package/src/data/eventsource.ts +13 -10
- package/src/data/listen.ts +18 -23
- package/src/data/live.ts +44 -27
- package/src/data/resolveEventSourceFetch.ts +96 -0
- package/src/datasets/DatasetsClient.ts +58 -41
- package/src/defineCreateClient.ts +35 -23
- package/src/http/browserMiddleware.ts +7 -1
- package/src/http/browserUpload.ts +162 -0
- package/src/http/errors.ts +60 -6
- package/src/http/nodeMiddleware.ts +94 -30
- package/src/http/request.ts +310 -87
- package/src/http/requestOptions.ts +131 -15
- package/src/{index.browser.ts → index.node.ts} +9 -4
- package/src/index.ts +4 -3
- package/src/mediaLibrary/MediaLibraryVideoClient.ts +26 -11
- package/src/projects/ProjectsClient.ts +18 -16
- package/src/releases/ReleasesClient.ts +38 -33
- package/src/stega/index.ts +1 -2
- package/src/stega/stegaEncodeSourceMap.ts +5 -0
- package/src/stega/types.ts +2 -2
- package/src/types.ts +148 -105
- package/src/users/UsersClient.ts +10 -14
- package/src/util/shareReplayLatest.ts +1 -1
- package/src/warnings.ts +6 -1
- package/dist/_chunks-cjs/config.cjs +0 -206
- package/dist/_chunks-cjs/config.cjs.map +0 -1
- package/dist/_chunks-cjs/isRecord.cjs +0 -6
- package/dist/_chunks-cjs/isRecord.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs +0 -334
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +0 -1
- package/dist/_chunks-cjs/stegaClean.cjs +0 -46
- package/dist/_chunks-cjs/stegaClean.cjs.map +0 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +0 -388
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +0 -1
- package/dist/_chunks-es/config.js +0 -207
- package/dist/_chunks-es/config.js.map +0 -1
- package/dist/_chunks-es/isRecord.js +0 -7
- package/dist/_chunks-es/isRecord.js.map +0 -1
- package/dist/_chunks-es/resolveEditInfo.js +0 -335
- package/dist/_chunks-es/resolveEditInfo.js.map +0 -1
- package/dist/_chunks-es/stegaClean.js +0 -47
- package/dist/_chunks-es/stegaClean.js.map +0 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +0 -389
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +0 -1
- package/dist/csm.cjs +0 -99
- package/dist/csm.cjs.map +0 -1
- package/dist/csm.d.cts +0 -391
- package/dist/index.browser.cjs +0 -3106
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.ts +0 -6802
- package/dist/index.browser.js +0 -3082
- package/dist/index.browser.js.map +0 -1
- package/dist/index.cjs +0 -2946
- package/dist/index.cjs.map +0 -1
- package/dist/media-library.cjs +0 -20
- package/dist/media-library.cjs.map +0 -1
- package/dist/media-library.d.cts +0 -117
- package/dist/stega.browser.cjs +0 -29
- package/dist/stega.browser.cjs.map +0 -1
- package/dist/stega.browser.d.cts +0 -7200
- package/dist/stega.browser.d.ts +0 -7200
- package/dist/stega.browser.js +0 -24
- package/dist/stega.browser.js.map +0 -1
- package/dist/stega.cjs +0 -29
- package/dist/stega.cjs.map +0 -1
- package/dist/stega.d.cts +0 -7200
- package/src/data/eventsourcePolyfill.ts +0 -7
- package/umd/.gitkeep +0 -1
- package/umd/sanityClient.js +0 -6543
- package/umd/sanityClient.min.js +0 -6
package/src/SanityClient.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {getPublishedId, getVersionId} from '@sanity/client/csm'
|
|
2
|
-
import {
|
|
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.#
|
|
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.#
|
|
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.#
|
|
153
|
+
return new ObservableSanityClient(this.#httpRequest, {
|
|
171
154
|
...thisConfig,
|
|
172
155
|
...newConfig,
|
|
173
156
|
stega: {
|
|
174
|
-
...
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.#
|
|
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.#
|
|
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.#
|
|
1231
|
+
return new SanityClient(this.#httpRequest, {
|
|
1247
1232
|
...thisConfig,
|
|
1248
1233
|
...newConfig,
|
|
1249
1234
|
stega: {
|
|
1250
|
-
...
|
|
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
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
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
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2181
|
+
return dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options)
|
|
2217
2182
|
}
|
|
2218
2183
|
|
|
2219
2184
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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}
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
290
|
+
| GenerateSyncInstruction<T>
|
|
291
|
+
| GenerateAsyncInstruction<T>
|
|
289
292
|
|
|
290
|
-
export function
|
|
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
|
-
|
|
322
|
+
url: `/agent/action/generate/${dataset}`,
|
|
303
323
|
body: request,
|
|
304
324
|
})
|
|
305
325
|
}
|