@sanity/client 5.1.0 → 5.2.1
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 +16 -72
- package/dist/index.browser.cjs +49 -11
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +49 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +50 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +156 -128
- package/dist/index.js +50 -12
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
- package/src/SanityClient.ts +120 -80
- package/src/assets/AssetsClient.ts +4 -4
- package/src/config.ts +1 -1
- package/src/data/dataMethods.ts +31 -31
- package/src/data/encodeQueryString.ts +3 -3
- package/src/data/listen.ts +11 -11
- package/src/data/patch.ts +18 -18
- package/src/data/transaction.ts +13 -15
- package/src/generateHelpUrl.ts +1 -1
- package/src/http/errors.ts +7 -7
- package/src/http/request.ts +4 -4
- package/src/http/requestOptions.ts +3 -3
- package/src/index.browser.ts +9 -1
- package/src/index.ts +9 -1
- package/src/types.ts +27 -28
- package/src/util/defaults.ts +3 -3
- package/src/util/getSelection.ts +1 -1
- package/src/util/once.ts +4 -4
- package/src/util/pick.ts +3 -3
- package/src/validators.ts +4 -4
- package/src/warnings.ts +8 -4
- package/umd/sanityClient.js +49 -11
- package/umd/sanityClient.min.js +3 -3
- package/src/migrationNotice.ts +0 -9
package/src/SanityClient.ts
CHANGED
|
@@ -11,12 +11,12 @@ import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClien
|
|
|
11
11
|
import type {
|
|
12
12
|
AllDocumentIdsMutationOptions,
|
|
13
13
|
AllDocumentsMutationOptions,
|
|
14
|
+
Any,
|
|
14
15
|
BaseMutationOptions,
|
|
15
16
|
ClientConfig,
|
|
16
17
|
FilteredResponseQueryOptions,
|
|
17
18
|
FirstDocumentIdMutationOptions,
|
|
18
19
|
FirstDocumentMutationOptions,
|
|
19
|
-
FIXME,
|
|
20
20
|
HttpRequest,
|
|
21
21
|
IdentifiedSanityDocumentStub,
|
|
22
22
|
InitializedClientConfig,
|
|
@@ -120,14 +120,14 @@ export class ObservableSanityClient {
|
|
|
120
120
|
*
|
|
121
121
|
* @param query - GROQ-query to perform
|
|
122
122
|
*/
|
|
123
|
-
fetch<R =
|
|
123
|
+
fetch<R = Any>(query: string): Observable<R>
|
|
124
124
|
/**
|
|
125
125
|
* Perform a GROQ-query against the configured dataset.
|
|
126
126
|
*
|
|
127
127
|
* @param query - GROQ-query to perform
|
|
128
128
|
* @param params - Query parameters
|
|
129
129
|
*/
|
|
130
|
-
fetch<R =
|
|
130
|
+
fetch<R = Any, Q = QueryParams>(query: string, params: Q): Observable<R>
|
|
131
131
|
/**
|
|
132
132
|
* Perform a GROQ-query against the configured dataset.
|
|
133
133
|
*
|
|
@@ -135,7 +135,7 @@ export class ObservableSanityClient {
|
|
|
135
135
|
* @param params - Query parameters
|
|
136
136
|
* @param options - Request options
|
|
137
137
|
*/
|
|
138
|
-
fetch<R =
|
|
138
|
+
fetch<R = Any, Q = QueryParams>(
|
|
139
139
|
query: string,
|
|
140
140
|
params: Q | undefined,
|
|
141
141
|
options: FilteredResponseQueryOptions
|
|
@@ -147,7 +147,7 @@ export class ObservableSanityClient {
|
|
|
147
147
|
* @param params - Query parameters
|
|
148
148
|
* @param options - Request options
|
|
149
149
|
*/
|
|
150
|
-
fetch<R =
|
|
150
|
+
fetch<R = Any, Q = QueryParams>(
|
|
151
151
|
query: string,
|
|
152
152
|
params: Q | undefined,
|
|
153
153
|
options: UnfilteredResponseQueryOptions
|
|
@@ -166,7 +166,7 @@ export class ObservableSanityClient {
|
|
|
166
166
|
* @param id - Document ID to fetch
|
|
167
167
|
* @param options - Request options
|
|
168
168
|
*/
|
|
169
|
-
getDocument<R extends Record<string,
|
|
169
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
170
170
|
id: string,
|
|
171
171
|
options?: {tag?: string}
|
|
172
172
|
): Observable<SanityDocument<R> | undefined> {
|
|
@@ -182,7 +182,7 @@ export class ObservableSanityClient {
|
|
|
182
182
|
* @param ids - Document IDs to fetch
|
|
183
183
|
* @param options - Request options
|
|
184
184
|
*/
|
|
185
|
-
getDocuments<R extends Record<string,
|
|
185
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
186
186
|
ids: string[],
|
|
187
187
|
options?: {tag?: string}
|
|
188
188
|
): Observable<(SanityDocument<R> | null)[]> {
|
|
@@ -196,7 +196,7 @@ export class ObservableSanityClient {
|
|
|
196
196
|
* @param document - Document to create
|
|
197
197
|
* @param options - Mutation options
|
|
198
198
|
*/
|
|
199
|
-
create<R extends Record<string,
|
|
199
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
200
200
|
document: SanityDocumentStub<R>,
|
|
201
201
|
options: FirstDocumentMutationOptions
|
|
202
202
|
): Observable<SanityDocument<R>>
|
|
@@ -207,7 +207,7 @@ export class ObservableSanityClient {
|
|
|
207
207
|
* @param document - Document to create
|
|
208
208
|
* @param options - Mutation options
|
|
209
209
|
*/
|
|
210
|
-
create<R extends Record<string,
|
|
210
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
211
211
|
document: SanityDocumentStub<R>,
|
|
212
212
|
options: AllDocumentsMutationOptions
|
|
213
213
|
): Observable<SanityDocument<R>[]>
|
|
@@ -218,7 +218,7 @@ export class ObservableSanityClient {
|
|
|
218
218
|
* @param document - Document to create
|
|
219
219
|
* @param options - Mutation options
|
|
220
220
|
*/
|
|
221
|
-
create<R extends Record<string,
|
|
221
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
222
222
|
document: SanityDocumentStub<R>,
|
|
223
223
|
options: FirstDocumentIdMutationOptions
|
|
224
224
|
): Observable<SingleMutationResult>
|
|
@@ -229,7 +229,7 @@ export class ObservableSanityClient {
|
|
|
229
229
|
* @param document - Document to create
|
|
230
230
|
* @param options - Mutation options
|
|
231
231
|
*/
|
|
232
|
-
create<R extends Record<string,
|
|
232
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
233
233
|
document: SanityDocumentStub<R>,
|
|
234
234
|
options: AllDocumentIdsMutationOptions
|
|
235
235
|
): Observable<MultipleMutationResult>
|
|
@@ -240,11 +240,11 @@ export class ObservableSanityClient {
|
|
|
240
240
|
* @param document - Document to create
|
|
241
241
|
* @param options - Mutation options
|
|
242
242
|
*/
|
|
243
|
-
create<R extends Record<string,
|
|
243
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
244
244
|
document: SanityDocumentStub<R>,
|
|
245
245
|
options?: BaseMutationOptions
|
|
246
246
|
): Observable<SanityDocument<R>>
|
|
247
|
-
create<R extends Record<string,
|
|
247
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
248
248
|
document: SanityDocumentStub<R>,
|
|
249
249
|
options?:
|
|
250
250
|
| AllDocumentIdsMutationOptions
|
|
@@ -265,7 +265,7 @@ export class ObservableSanityClient {
|
|
|
265
265
|
* @param document - Document to create
|
|
266
266
|
* @param options - Mutation options
|
|
267
267
|
*/
|
|
268
|
-
createIfNotExists<R extends Record<string,
|
|
268
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
269
269
|
document: IdentifiedSanityDocumentStub<R>,
|
|
270
270
|
options: FirstDocumentMutationOptions
|
|
271
271
|
): Observable<SanityDocument<R>>
|
|
@@ -276,7 +276,7 @@ export class ObservableSanityClient {
|
|
|
276
276
|
* @param document - Document to create
|
|
277
277
|
* @param options - Mutation options
|
|
278
278
|
*/
|
|
279
|
-
createIfNotExists<R extends Record<string,
|
|
279
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
280
280
|
document: IdentifiedSanityDocumentStub<R>,
|
|
281
281
|
options: AllDocumentsMutationOptions
|
|
282
282
|
): Observable<SanityDocument<R>[]>
|
|
@@ -287,7 +287,7 @@ export class ObservableSanityClient {
|
|
|
287
287
|
* @param document - Document to create
|
|
288
288
|
* @param options - Mutation options
|
|
289
289
|
*/
|
|
290
|
-
createIfNotExists<R extends Record<string,
|
|
290
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
291
291
|
document: IdentifiedSanityDocumentStub<R>,
|
|
292
292
|
options: FirstDocumentIdMutationOptions
|
|
293
293
|
): Observable<SingleMutationResult>
|
|
@@ -298,7 +298,7 @@ export class ObservableSanityClient {
|
|
|
298
298
|
* @param document - Document to create
|
|
299
299
|
* @param options - Mutation options
|
|
300
300
|
*/
|
|
301
|
-
createIfNotExists<R extends Record<string,
|
|
301
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
302
302
|
document: IdentifiedSanityDocumentStub<R>,
|
|
303
303
|
options: AllDocumentIdsMutationOptions
|
|
304
304
|
): Observable<MultipleMutationResult>
|
|
@@ -309,11 +309,11 @@ export class ObservableSanityClient {
|
|
|
309
309
|
* @param document - Document to create
|
|
310
310
|
* @param options - Mutation options
|
|
311
311
|
*/
|
|
312
|
-
createIfNotExists<R extends Record<string,
|
|
312
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
313
313
|
document: IdentifiedSanityDocumentStub<R>,
|
|
314
314
|
options?: BaseMutationOptions
|
|
315
315
|
): Observable<SanityDocument<R>>
|
|
316
|
-
createIfNotExists<R extends Record<string,
|
|
316
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
317
317
|
document: IdentifiedSanityDocumentStub<R>,
|
|
318
318
|
options?:
|
|
319
319
|
| AllDocumentIdsMutationOptions
|
|
@@ -334,7 +334,7 @@ export class ObservableSanityClient {
|
|
|
334
334
|
* @param document - Document to either create or replace
|
|
335
335
|
* @param options - Mutation options
|
|
336
336
|
*/
|
|
337
|
-
createOrReplace<R extends Record<string,
|
|
337
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
338
338
|
document: IdentifiedSanityDocumentStub<R>,
|
|
339
339
|
options: FirstDocumentMutationOptions
|
|
340
340
|
): Observable<SanityDocument<R>>
|
|
@@ -345,7 +345,7 @@ export class ObservableSanityClient {
|
|
|
345
345
|
* @param document - Document to either create or replace
|
|
346
346
|
* @param options - Mutation options
|
|
347
347
|
*/
|
|
348
|
-
createOrReplace<R extends Record<string,
|
|
348
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
349
349
|
document: IdentifiedSanityDocumentStub<R>,
|
|
350
350
|
options: AllDocumentsMutationOptions
|
|
351
351
|
): Observable<SanityDocument<R>[]>
|
|
@@ -356,7 +356,7 @@ export class ObservableSanityClient {
|
|
|
356
356
|
* @param document - Document to either create or replace
|
|
357
357
|
* @param options - Mutation options
|
|
358
358
|
*/
|
|
359
|
-
createOrReplace<R extends Record<string,
|
|
359
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
360
360
|
document: IdentifiedSanityDocumentStub<R>,
|
|
361
361
|
options: FirstDocumentIdMutationOptions
|
|
362
362
|
): Observable<SingleMutationResult>
|
|
@@ -367,7 +367,7 @@ export class ObservableSanityClient {
|
|
|
367
367
|
* @param document - Document to either create or replace
|
|
368
368
|
* @param options - Mutation options
|
|
369
369
|
*/
|
|
370
|
-
createOrReplace<R extends Record<string,
|
|
370
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
371
371
|
document: IdentifiedSanityDocumentStub<R>,
|
|
372
372
|
options: AllDocumentIdsMutationOptions
|
|
373
373
|
): Observable<MultipleMutationResult>
|
|
@@ -378,11 +378,11 @@ export class ObservableSanityClient {
|
|
|
378
378
|
* @param document - Document to either create or replace
|
|
379
379
|
* @param options - Mutation options
|
|
380
380
|
*/
|
|
381
|
-
createOrReplace<R extends Record<string,
|
|
381
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
382
382
|
document: IdentifiedSanityDocumentStub<R>,
|
|
383
383
|
options?: BaseMutationOptions
|
|
384
384
|
): Observable<SanityDocument<R>>
|
|
385
|
-
createOrReplace<R extends Record<string,
|
|
385
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
386
386
|
document: IdentifiedSanityDocumentStub<R>,
|
|
387
387
|
options?:
|
|
388
388
|
| AllDocumentIdsMutationOptions
|
|
@@ -403,7 +403,7 @@ export class ObservableSanityClient {
|
|
|
403
403
|
* @param id - Document ID to delete
|
|
404
404
|
* @param options - Options for the mutation
|
|
405
405
|
*/
|
|
406
|
-
delete<R extends Record<string,
|
|
406
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
407
407
|
id: string,
|
|
408
408
|
options: FirstDocumentMutationOptions
|
|
409
409
|
): Observable<SanityDocument<R>>
|
|
@@ -414,7 +414,7 @@ export class ObservableSanityClient {
|
|
|
414
414
|
* @param id - Document ID to delete
|
|
415
415
|
* @param options - Options for the mutation
|
|
416
416
|
*/
|
|
417
|
-
delete<R extends Record<string,
|
|
417
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
418
418
|
id: string,
|
|
419
419
|
options: AllDocumentsMutationOptions
|
|
420
420
|
): Observable<SanityDocument<R>[]>
|
|
@@ -441,7 +441,7 @@ export class ObservableSanityClient {
|
|
|
441
441
|
* @param id - Document ID to delete
|
|
442
442
|
* @param options - Options for the mutation
|
|
443
443
|
*/
|
|
444
|
-
delete<R extends Record<string,
|
|
444
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
445
445
|
id: string,
|
|
446
446
|
options?: BaseMutationOptions
|
|
447
447
|
): Observable<SanityDocument<R>>
|
|
@@ -452,7 +452,7 @@ export class ObservableSanityClient {
|
|
|
452
452
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
453
453
|
* @param options - Options for the mutation
|
|
454
454
|
*/
|
|
455
|
-
delete<R extends Record<string,
|
|
455
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
456
456
|
selection: MutationSelection,
|
|
457
457
|
options: FirstDocumentMutationOptions
|
|
458
458
|
): Observable<SanityDocument<R>>
|
|
@@ -463,7 +463,7 @@ export class ObservableSanityClient {
|
|
|
463
463
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
464
464
|
* @param options - Options for the mutation
|
|
465
465
|
*/
|
|
466
|
-
delete<R extends Record<string,
|
|
466
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
467
467
|
selection: MutationSelection,
|
|
468
468
|
options: AllDocumentsMutationOptions
|
|
469
469
|
): Observable<SanityDocument<R>[]>
|
|
@@ -496,11 +496,11 @@ export class ObservableSanityClient {
|
|
|
496
496
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
497
497
|
* @param options - Options for the mutation
|
|
498
498
|
*/
|
|
499
|
-
delete<R extends Record<string,
|
|
499
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
500
500
|
selection: MutationSelection,
|
|
501
501
|
options?: BaseMutationOptions
|
|
502
502
|
): Observable<SanityDocument<R>>
|
|
503
|
-
delete<R extends Record<string,
|
|
503
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
504
504
|
selection: string | MutationSelection,
|
|
505
505
|
options?:
|
|
506
506
|
| AllDocumentIdsMutationOptions
|
|
@@ -521,7 +521,7 @@ export class ObservableSanityClient {
|
|
|
521
521
|
* @param operations - Mutation operations to execute
|
|
522
522
|
* @param options - Mutation options
|
|
523
523
|
*/
|
|
524
|
-
mutate<R extends Record<string,
|
|
524
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
525
525
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
526
526
|
options: FirstDocumentMutationOptions
|
|
527
527
|
): Observable<SanityDocument<R>>
|
|
@@ -532,7 +532,7 @@ export class ObservableSanityClient {
|
|
|
532
532
|
* @param operations - Mutation operations to execute
|
|
533
533
|
* @param options - Mutation options
|
|
534
534
|
*/
|
|
535
|
-
mutate<R extends Record<string,
|
|
535
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
536
536
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
537
537
|
options: AllDocumentsMutationOptions
|
|
538
538
|
): Observable<SanityDocument<R>[]>
|
|
@@ -543,7 +543,7 @@ export class ObservableSanityClient {
|
|
|
543
543
|
* @param operations - Mutation operations to execute
|
|
544
544
|
* @param options - Mutation options
|
|
545
545
|
*/
|
|
546
|
-
mutate<R extends Record<string,
|
|
546
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
547
547
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
548
548
|
options: FirstDocumentIdMutationOptions
|
|
549
549
|
): Observable<SingleMutationResult>
|
|
@@ -554,7 +554,7 @@ export class ObservableSanityClient {
|
|
|
554
554
|
* @param operations - Mutation operations to execute
|
|
555
555
|
* @param options - Mutation options
|
|
556
556
|
*/
|
|
557
|
-
mutate<R extends Record<string,
|
|
557
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
558
558
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
559
559
|
options: AllDocumentIdsMutationOptions
|
|
560
560
|
): Observable<MultipleMutationResult>
|
|
@@ -565,11 +565,11 @@ export class ObservableSanityClient {
|
|
|
565
565
|
* @param operations - Mutation operations to execute
|
|
566
566
|
* @param options - Mutation options
|
|
567
567
|
*/
|
|
568
|
-
mutate<R extends Record<string,
|
|
568
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
569
569
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
570
570
|
options?: BaseMutationOptions
|
|
571
571
|
): Observable<SanityDocument<R>>
|
|
572
|
-
mutate<R extends Record<string,
|
|
572
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
573
573
|
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
574
574
|
options?:
|
|
575
575
|
| FirstDocumentMutationOptions
|
|
@@ -598,7 +598,7 @@ export class ObservableSanityClient {
|
|
|
598
598
|
*
|
|
599
599
|
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
600
600
|
*/
|
|
601
|
-
transaction<R extends Record<string,
|
|
601
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
602
602
|
operations?: Mutation<R>[]
|
|
603
603
|
): ObservableTransaction {
|
|
604
604
|
return new ObservableTransaction(operations, this)
|
|
@@ -610,9 +610,29 @@ export class ObservableSanityClient {
|
|
|
610
610
|
* @deprecated Use your own request library!
|
|
611
611
|
* @param options - Request options
|
|
612
612
|
*/
|
|
613
|
-
request<R =
|
|
613
|
+
request<R = Any>(options: RawRequestOptions): Observable<R> {
|
|
614
614
|
return dataMethods._request(this, this.#httpRequest, options)
|
|
615
615
|
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Get a Sanity API URL for the URI provided
|
|
619
|
+
*
|
|
620
|
+
* @param uri - URI/path to build URL for
|
|
621
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
622
|
+
*/
|
|
623
|
+
getUrl(uri: string, canUseCdn?: boolean): string {
|
|
624
|
+
return dataMethods._getUrl(this, uri, canUseCdn)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
629
|
+
*
|
|
630
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
631
|
+
* @param path - Path to append after the operation
|
|
632
|
+
*/
|
|
633
|
+
getDataUrl(operation: string, path?: string): string {
|
|
634
|
+
return dataMethods._getDataUrl(this, operation, path)
|
|
635
|
+
}
|
|
616
636
|
}
|
|
617
637
|
|
|
618
638
|
/** @public */
|
|
@@ -699,14 +719,14 @@ export class SanityClient {
|
|
|
699
719
|
*
|
|
700
720
|
* @param query - GROQ-query to perform
|
|
701
721
|
*/
|
|
702
|
-
fetch<R =
|
|
722
|
+
fetch<R = Any>(query: string): Promise<R>
|
|
703
723
|
/**
|
|
704
724
|
* Perform a GROQ-query against the configured dataset.
|
|
705
725
|
*
|
|
706
726
|
* @param query - GROQ-query to perform
|
|
707
727
|
* @param params - Optional query parameters
|
|
708
728
|
*/
|
|
709
|
-
fetch<R =
|
|
729
|
+
fetch<R = Any, Q = QueryParams>(query: string, params: Q): Promise<R>
|
|
710
730
|
/**
|
|
711
731
|
* Perform a GROQ-query against the configured dataset.
|
|
712
732
|
*
|
|
@@ -714,7 +734,7 @@ export class SanityClient {
|
|
|
714
734
|
* @param params - Optional query parameters
|
|
715
735
|
* @param options - Request options
|
|
716
736
|
*/
|
|
717
|
-
fetch<R =
|
|
737
|
+
fetch<R = Any, Q = QueryParams>(
|
|
718
738
|
query: string,
|
|
719
739
|
params: Q | undefined,
|
|
720
740
|
options: FilteredResponseQueryOptions
|
|
@@ -726,7 +746,7 @@ export class SanityClient {
|
|
|
726
746
|
* @param params - Optional query parameters
|
|
727
747
|
* @param options - Request options
|
|
728
748
|
*/
|
|
729
|
-
fetch<R =
|
|
749
|
+
fetch<R = Any, Q = QueryParams>(
|
|
730
750
|
query: string,
|
|
731
751
|
params: Q | undefined,
|
|
732
752
|
options: UnfilteredResponseQueryOptions
|
|
@@ -745,7 +765,7 @@ export class SanityClient {
|
|
|
745
765
|
* @param id - Document ID to fetch
|
|
746
766
|
* @param options - Request options
|
|
747
767
|
*/
|
|
748
|
-
getDocument<R extends Record<string,
|
|
768
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
749
769
|
id: string,
|
|
750
770
|
options?: {tag?: string}
|
|
751
771
|
): Promise<SanityDocument<R> | undefined> {
|
|
@@ -761,7 +781,7 @@ export class SanityClient {
|
|
|
761
781
|
* @param ids - Document IDs to fetch
|
|
762
782
|
* @param options - Request options
|
|
763
783
|
*/
|
|
764
|
-
getDocuments<R extends Record<string,
|
|
784
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
765
785
|
ids: string[],
|
|
766
786
|
options?: {tag?: string}
|
|
767
787
|
): Promise<(SanityDocument<R> | null)[]> {
|
|
@@ -775,7 +795,7 @@ export class SanityClient {
|
|
|
775
795
|
* @param document - Document to create
|
|
776
796
|
* @param options - Mutation options
|
|
777
797
|
*/
|
|
778
|
-
create<R extends Record<string,
|
|
798
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
779
799
|
document: SanityDocumentStub<R>,
|
|
780
800
|
options: FirstDocumentMutationOptions
|
|
781
801
|
): Promise<SanityDocument<R>>
|
|
@@ -786,7 +806,7 @@ export class SanityClient {
|
|
|
786
806
|
* @param document - Document to create
|
|
787
807
|
* @param options - Mutation options
|
|
788
808
|
*/
|
|
789
|
-
create<R extends Record<string,
|
|
809
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
790
810
|
document: SanityDocumentStub<R>,
|
|
791
811
|
options: AllDocumentsMutationOptions
|
|
792
812
|
): Promise<SanityDocument<R>[]>
|
|
@@ -797,7 +817,7 @@ export class SanityClient {
|
|
|
797
817
|
* @param document - Document to create
|
|
798
818
|
* @param options - Mutation options
|
|
799
819
|
*/
|
|
800
|
-
create<R extends Record<string,
|
|
820
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
801
821
|
document: SanityDocumentStub<R>,
|
|
802
822
|
options: FirstDocumentIdMutationOptions
|
|
803
823
|
): Promise<SingleMutationResult>
|
|
@@ -808,7 +828,7 @@ export class SanityClient {
|
|
|
808
828
|
* @param document - Document to create
|
|
809
829
|
* @param options - Mutation options
|
|
810
830
|
*/
|
|
811
|
-
create<R extends Record<string,
|
|
831
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
812
832
|
document: SanityDocumentStub<R>,
|
|
813
833
|
options: AllDocumentIdsMutationOptions
|
|
814
834
|
): Promise<MultipleMutationResult>
|
|
@@ -819,11 +839,11 @@ export class SanityClient {
|
|
|
819
839
|
* @param document - Document to create
|
|
820
840
|
* @param options - Mutation options
|
|
821
841
|
*/
|
|
822
|
-
create<R extends Record<string,
|
|
842
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
823
843
|
document: SanityDocumentStub<R>,
|
|
824
844
|
options?: BaseMutationOptions
|
|
825
845
|
): Promise<SanityDocument<R>>
|
|
826
|
-
create<R extends Record<string,
|
|
846
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
827
847
|
document: SanityDocumentStub<R>,
|
|
828
848
|
options?:
|
|
829
849
|
| AllDocumentIdsMutationOptions
|
|
@@ -846,7 +866,7 @@ export class SanityClient {
|
|
|
846
866
|
* @param document - Document to create
|
|
847
867
|
* @param options - Mutation options
|
|
848
868
|
*/
|
|
849
|
-
createIfNotExists<R extends Record<string,
|
|
869
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
850
870
|
document: IdentifiedSanityDocumentStub<R>,
|
|
851
871
|
options: FirstDocumentMutationOptions
|
|
852
872
|
): Promise<SanityDocument<R>>
|
|
@@ -857,7 +877,7 @@ export class SanityClient {
|
|
|
857
877
|
* @param document - Document to create
|
|
858
878
|
* @param options - Mutation options
|
|
859
879
|
*/
|
|
860
|
-
createIfNotExists<R extends Record<string,
|
|
880
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
861
881
|
document: IdentifiedSanityDocumentStub<R>,
|
|
862
882
|
options: AllDocumentsMutationOptions
|
|
863
883
|
): Promise<SanityDocument<R>[]>
|
|
@@ -868,7 +888,7 @@ export class SanityClient {
|
|
|
868
888
|
* @param document - Document to create
|
|
869
889
|
* @param options - Mutation options
|
|
870
890
|
*/
|
|
871
|
-
createIfNotExists<R extends Record<string,
|
|
891
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
872
892
|
document: IdentifiedSanityDocumentStub<R>,
|
|
873
893
|
options: FirstDocumentIdMutationOptions
|
|
874
894
|
): Promise<SingleMutationResult>
|
|
@@ -879,7 +899,7 @@ export class SanityClient {
|
|
|
879
899
|
* @param document - Document to create
|
|
880
900
|
* @param options - Mutation options
|
|
881
901
|
*/
|
|
882
|
-
createIfNotExists<R extends Record<string,
|
|
902
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
883
903
|
document: IdentifiedSanityDocumentStub<R>,
|
|
884
904
|
options: AllDocumentIdsMutationOptions
|
|
885
905
|
): Promise<MultipleMutationResult>
|
|
@@ -890,11 +910,11 @@ export class SanityClient {
|
|
|
890
910
|
* @param document - Document to create
|
|
891
911
|
* @param options - Mutation options
|
|
892
912
|
*/
|
|
893
|
-
createIfNotExists<R extends Record<string,
|
|
913
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
894
914
|
document: IdentifiedSanityDocumentStub<R>,
|
|
895
915
|
options?: BaseMutationOptions
|
|
896
916
|
): Promise<SanityDocument<R>>
|
|
897
|
-
createIfNotExists<R extends Record<string,
|
|
917
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
898
918
|
document: IdentifiedSanityDocumentStub<R>,
|
|
899
919
|
options?:
|
|
900
920
|
| AllDocumentIdsMutationOptions
|
|
@@ -917,7 +937,7 @@ export class SanityClient {
|
|
|
917
937
|
* @param document - Document to either create or replace
|
|
918
938
|
* @param options - Mutation options
|
|
919
939
|
*/
|
|
920
|
-
createOrReplace<R extends Record<string,
|
|
940
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
921
941
|
document: IdentifiedSanityDocumentStub<R>,
|
|
922
942
|
options: FirstDocumentMutationOptions
|
|
923
943
|
): Promise<SanityDocument<R>>
|
|
@@ -928,7 +948,7 @@ export class SanityClient {
|
|
|
928
948
|
* @param document - Document to either create or replace
|
|
929
949
|
* @param options - Mutation options
|
|
930
950
|
*/
|
|
931
|
-
createOrReplace<R extends Record<string,
|
|
951
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
932
952
|
document: IdentifiedSanityDocumentStub<R>,
|
|
933
953
|
options: AllDocumentsMutationOptions
|
|
934
954
|
): Promise<SanityDocument<R>[]>
|
|
@@ -939,7 +959,7 @@ export class SanityClient {
|
|
|
939
959
|
* @param document - Document to either create or replace
|
|
940
960
|
* @param options - Mutation options
|
|
941
961
|
*/
|
|
942
|
-
createOrReplace<R extends Record<string,
|
|
962
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
943
963
|
document: IdentifiedSanityDocumentStub<R>,
|
|
944
964
|
options: FirstDocumentIdMutationOptions
|
|
945
965
|
): Promise<SingleMutationResult>
|
|
@@ -950,7 +970,7 @@ export class SanityClient {
|
|
|
950
970
|
* @param document - Document to either create or replace
|
|
951
971
|
* @param options - Mutation options
|
|
952
972
|
*/
|
|
953
|
-
createOrReplace<R extends Record<string,
|
|
973
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
954
974
|
document: IdentifiedSanityDocumentStub<R>,
|
|
955
975
|
options: AllDocumentIdsMutationOptions
|
|
956
976
|
): Promise<MultipleMutationResult>
|
|
@@ -961,11 +981,11 @@ export class SanityClient {
|
|
|
961
981
|
* @param document - Document to either create or replace
|
|
962
982
|
* @param options - Mutation options
|
|
963
983
|
*/
|
|
964
|
-
createOrReplace<R extends Record<string,
|
|
984
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
965
985
|
document: IdentifiedSanityDocumentStub<R>,
|
|
966
986
|
options?: BaseMutationOptions
|
|
967
987
|
): Promise<SanityDocument<R>>
|
|
968
|
-
createOrReplace<R extends Record<string,
|
|
988
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
969
989
|
document: IdentifiedSanityDocumentStub<R>,
|
|
970
990
|
options?:
|
|
971
991
|
| AllDocumentIdsMutationOptions
|
|
@@ -988,7 +1008,7 @@ export class SanityClient {
|
|
|
988
1008
|
* @param id - Document ID to delete
|
|
989
1009
|
* @param options - Options for the mutation
|
|
990
1010
|
*/
|
|
991
|
-
delete<R extends Record<string,
|
|
1011
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
992
1012
|
id: string,
|
|
993
1013
|
options: FirstDocumentMutationOptions
|
|
994
1014
|
): Promise<SanityDocument<R>>
|
|
@@ -999,7 +1019,7 @@ export class SanityClient {
|
|
|
999
1019
|
* @param id - Document ID to delete
|
|
1000
1020
|
* @param options - Options for the mutation
|
|
1001
1021
|
*/
|
|
1002
|
-
delete<R extends Record<string,
|
|
1022
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1003
1023
|
id: string,
|
|
1004
1024
|
options: AllDocumentsMutationOptions
|
|
1005
1025
|
): Promise<SanityDocument<R>[]>
|
|
@@ -1026,7 +1046,7 @@ export class SanityClient {
|
|
|
1026
1046
|
* @param id - Document ID to delete
|
|
1027
1047
|
* @param options - Options for the mutation
|
|
1028
1048
|
*/
|
|
1029
|
-
delete<R extends Record<string,
|
|
1049
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1030
1050
|
id: string,
|
|
1031
1051
|
options?: BaseMutationOptions
|
|
1032
1052
|
): Promise<SanityDocument<R>>
|
|
@@ -1037,7 +1057,7 @@ export class SanityClient {
|
|
|
1037
1057
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1038
1058
|
* @param options - Options for the mutation
|
|
1039
1059
|
*/
|
|
1040
|
-
delete<R extends Record<string,
|
|
1060
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1041
1061
|
selection: MutationSelection,
|
|
1042
1062
|
options: FirstDocumentMutationOptions
|
|
1043
1063
|
): Promise<SanityDocument<R>>
|
|
@@ -1048,7 +1068,7 @@ export class SanityClient {
|
|
|
1048
1068
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1049
1069
|
* @param options - Options for the mutation
|
|
1050
1070
|
*/
|
|
1051
|
-
delete<R extends Record<string,
|
|
1071
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1052
1072
|
selection: MutationSelection,
|
|
1053
1073
|
options: AllDocumentsMutationOptions
|
|
1054
1074
|
): Promise<SanityDocument<R>[]>
|
|
@@ -1081,11 +1101,11 @@ export class SanityClient {
|
|
|
1081
1101
|
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1082
1102
|
* @param options - Options for the mutation
|
|
1083
1103
|
*/
|
|
1084
|
-
delete<R extends Record<string,
|
|
1104
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1085
1105
|
selection: MutationSelection,
|
|
1086
1106
|
options?: BaseMutationOptions
|
|
1087
1107
|
): Promise<SanityDocument<R>>
|
|
1088
|
-
delete<R extends Record<string,
|
|
1108
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1089
1109
|
selection: string | MutationSelection,
|
|
1090
1110
|
options?:
|
|
1091
1111
|
| AllDocumentIdsMutationOptions
|
|
@@ -1106,7 +1126,7 @@ export class SanityClient {
|
|
|
1106
1126
|
* @param operations - Mutation operations to execute
|
|
1107
1127
|
* @param options - Mutation options
|
|
1108
1128
|
*/
|
|
1109
|
-
mutate<R extends Record<string,
|
|
1129
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1110
1130
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1111
1131
|
options: FirstDocumentMutationOptions
|
|
1112
1132
|
): Promise<SanityDocument<R>>
|
|
@@ -1117,7 +1137,7 @@ export class SanityClient {
|
|
|
1117
1137
|
* @param operations - Mutation operations to execute
|
|
1118
1138
|
* @param options - Mutation options
|
|
1119
1139
|
*/
|
|
1120
|
-
mutate<R extends Record<string,
|
|
1140
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1121
1141
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1122
1142
|
options: AllDocumentsMutationOptions
|
|
1123
1143
|
): Promise<SanityDocument<R>[]>
|
|
@@ -1128,7 +1148,7 @@ export class SanityClient {
|
|
|
1128
1148
|
* @param operations - Mutation operations to execute
|
|
1129
1149
|
* @param options - Mutation options
|
|
1130
1150
|
*/
|
|
1131
|
-
mutate<R extends Record<string,
|
|
1151
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1132
1152
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1133
1153
|
options: FirstDocumentIdMutationOptions
|
|
1134
1154
|
): Promise<SingleMutationResult>
|
|
@@ -1139,7 +1159,7 @@ export class SanityClient {
|
|
|
1139
1159
|
* @param operations - Mutation operations to execute
|
|
1140
1160
|
* @param options - Mutation options
|
|
1141
1161
|
*/
|
|
1142
|
-
mutate<R extends Record<string,
|
|
1162
|
+
mutate<R extends Record<string, Any>>(
|
|
1143
1163
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1144
1164
|
options: AllDocumentIdsMutationOptions
|
|
1145
1165
|
): Promise<MultipleMutationResult>
|
|
@@ -1150,11 +1170,11 @@ export class SanityClient {
|
|
|
1150
1170
|
* @param operations - Mutation operations to execute
|
|
1151
1171
|
* @param options - Mutation options
|
|
1152
1172
|
*/
|
|
1153
|
-
mutate<R extends Record<string,
|
|
1173
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1154
1174
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1155
1175
|
options?: BaseMutationOptions
|
|
1156
1176
|
): Promise<SanityDocument<R>>
|
|
1157
|
-
mutate<R extends Record<string,
|
|
1177
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1158
1178
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1159
1179
|
options?:
|
|
1160
1180
|
| FirstDocumentMutationOptions
|
|
@@ -1183,7 +1203,7 @@ export class SanityClient {
|
|
|
1183
1203
|
*
|
|
1184
1204
|
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1185
1205
|
*/
|
|
1186
|
-
transaction<R extends Record<string,
|
|
1206
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1187
1207
|
operations?: Mutation<R>[]
|
|
1188
1208
|
): Transaction {
|
|
1189
1209
|
return new Transaction(operations, this)
|
|
@@ -1195,7 +1215,7 @@ export class SanityClient {
|
|
|
1195
1215
|
* @deprecated Use your own request library!
|
|
1196
1216
|
* @param options - Request options
|
|
1197
1217
|
*/
|
|
1198
|
-
request<R =
|
|
1218
|
+
request<R = Any>(options: RawRequestOptions): Promise<R> {
|
|
1199
1219
|
return lastValueFrom(dataMethods._request<R>(this, this.#httpRequest, options))
|
|
1200
1220
|
}
|
|
1201
1221
|
|
|
@@ -1207,7 +1227,27 @@ export class SanityClient {
|
|
|
1207
1227
|
* @param body - Request body
|
|
1208
1228
|
* @param options - Request options
|
|
1209
1229
|
*/
|
|
1210
|
-
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<
|
|
1230
|
+
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
|
|
1211
1231
|
return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
|
|
1212
1232
|
}
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Get a Sanity API URL for the URI provided
|
|
1236
|
+
*
|
|
1237
|
+
* @param uri - URI/path to build URL for
|
|
1238
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1239
|
+
*/
|
|
1240
|
+
getUrl(uri: string, canUseCdn?: boolean): string {
|
|
1241
|
+
return dataMethods._getUrl(this, uri, canUseCdn)
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1246
|
+
*
|
|
1247
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1248
|
+
* @param path - Path to append after the operation
|
|
1249
|
+
*/
|
|
1250
|
+
getDataUrl(operation: string, path?: string): string {
|
|
1251
|
+
return dataMethods._getDataUrl(this, operation, path)
|
|
1252
|
+
}
|
|
1213
1253
|
}
|