@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.
- package/README.md +63 -341
- package/dist/browserUpload-2tz6Sdqp.js +87 -0
- package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
- package/dist/browserUpload-CwpNx7Vl.js +87 -0
- package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
- package/dist/config-3wiPP-sZ.js +126 -0
- package/dist/config-3wiPP-sZ.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 +112 -6722
- package/dist/index.js +2950 -2848
- package/dist/index.js.map +1 -1
- package/dist/{index.d.cts → index.node.d.ts} +4529 -5322
- package/dist/index.node.js +3264 -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-BhMuKj0D.js +373 -0
- package/dist/request-BhMuKj0D.js.map +1 -0
- package/dist/request-SnMg7nUX.js +355 -0
- package/dist/request-SnMg7nUX.js.map +1 -0
- package/dist/resolveEditInfo-Cz-smq3a.js +339 -0
- package/dist/resolveEditInfo-Cz-smq3a.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-DbM2fTN4.js +373 -0
- package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
- package/dist/stegaEncodeSourceMap-YR3NQ3iz.js +163 -0
- package/dist/stegaEncodeSourceMap-YR3NQ3iz.js.map +1 -0
- package/dist/{index.browser.d.cts → types-BODIEY7F.d.ts} +4196 -5258
- package/dist/types-CfGzbXrl.d.ts +108 -0
- package/package.json +80 -142
- package/src/SanityClient.ts +101 -137
- 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 +121 -24
- package/src/csm/applySourceDocuments.ts +5 -5
- package/src/csm/createEditUrl.ts +1 -1
- package/src/csm/draftUtils.ts +23 -5
- 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 +784 -349
- package/src/data/eventsource.ts +82 -49
- package/src/data/listen.ts +18 -23
- package/src/data/live.ts +60 -35
- package/src/data/resolveEventSourceFetch.ts +104 -0
- package/src/datasets/DatasetsClient.ts +58 -41
- package/src/defineCreateClient.ts +38 -22
- package/src/functions/FunctionsClient.ts +66 -0
- package/src/functions/invoke.ts +176 -0
- package/src/http/browserMiddleware.ts +7 -1
- package/src/http/browserUpload.ts +163 -0
- package/src/http/errors.ts +61 -6
- package/src/http/nodeMiddleware.ts +94 -30
- package/src/http/request.ts +304 -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 +27 -12
- 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 +328 -103
- package/src/users/UsersClient.ts +10 -14
- package/src/util/shareReplayLatest.ts +1 -1
- package/src/validators.ts +1 -1
- package/src/warnings.ts +13 -2
- 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'
|
|
@@ -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.#
|
|
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.#
|
|
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.#
|
|
156
|
+
return new ObservableSanityClient(this.#httpRequest, {
|
|
171
157
|
...thisConfig,
|
|
172
158
|
...newConfig,
|
|
173
159
|
stega: {
|
|
174
|
-
...
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
770
|
+
delete(
|
|
788
771
|
selection: MutationSelection,
|
|
789
772
|
options?: BaseMutationOptions,
|
|
790
|
-
): Observable<
|
|
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.
|
|
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
|
/**
|
|
@@ -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
|
|
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<
|
|
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.
|
|
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
|
/**
|
|
@@ -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.#
|
|
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.#
|
|
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.#
|
|
1233
|
+
return new SanityClient(this.#httpRequest, {
|
|
1247
1234
|
...thisConfig,
|
|
1248
1235
|
...newConfig,
|
|
1249
1236
|
stega: {
|
|
1250
|
-
...
|
|
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
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
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
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
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
|
|
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
|
|
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
|
|
1835
|
+
delete(
|
|
1866
1836
|
selection: MutationSelection,
|
|
1867
1837
|
options?: BaseMutationOptions,
|
|
1868
|
-
): Promise<
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2180
|
+
return dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options)
|
|
2217
2181
|
}
|
|
2218
2182
|
|
|
2219
2183
|
/**
|