@sanity/client 7.23.1 → 7.24.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/dist/index.browser.cjs +26 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +26 -0
- package/dist/index.browser.d.ts +26 -0
- package/dist/index.browser.js +26 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +27 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +26 -0
- package/dist/stega.browser.d.ts +26 -0
- package/dist/stega.d.cts +26 -0
- package/dist/stega.d.ts +26 -0
- package/package.json +2 -2
- package/src/data/dataMethods.ts +40 -0
- package/src/types.ts +26 -0
- package/umd/sanityClient.js +35 -25
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.browser.d.cts
CHANGED
|
@@ -719,6 +719,10 @@ export declare interface ClientConfig {
|
|
|
719
719
|
* @defaultValue 'published'
|
|
720
720
|
*/
|
|
721
721
|
perspective?: ClientPerspective
|
|
722
|
+
/**
|
|
723
|
+
* @beta
|
|
724
|
+
*/
|
|
725
|
+
variant?: ClientVariant
|
|
722
726
|
apiHost?: string
|
|
723
727
|
/**
|
|
724
728
|
@remarks
|
|
@@ -880,6 +884,18 @@ export declare type ClientReturn<
|
|
|
880
884
|
*/
|
|
881
885
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
882
886
|
|
|
887
|
+
/**
|
|
888
|
+
* @public
|
|
889
|
+
* @beta
|
|
890
|
+
*/
|
|
891
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* @public
|
|
895
|
+
* @beta
|
|
896
|
+
*/
|
|
897
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
898
|
+
|
|
883
899
|
/**
|
|
884
900
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
885
901
|
*
|
|
@@ -4526,6 +4542,8 @@ export declare interface QueryParams {
|
|
|
4526
4542
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4527
4543
|
perspective?: never
|
|
4528
4544
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4545
|
+
variant?: never
|
|
4546
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4529
4547
|
query?: never
|
|
4530
4548
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4531
4549
|
resultSourceMap?: never
|
|
@@ -5066,6 +5084,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
5066
5084
|
returnQuery?: boolean
|
|
5067
5085
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5068
5086
|
perspective?: ClientPerspective
|
|
5087
|
+
/**
|
|
5088
|
+
* @beta
|
|
5089
|
+
*/
|
|
5090
|
+
variant?: ClientVariant
|
|
5069
5091
|
lastLiveEventId?: string
|
|
5070
5092
|
cacheMode?: 'noStale'
|
|
5071
5093
|
}
|
|
@@ -5114,6 +5136,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
5114
5136
|
/** @public */
|
|
5115
5137
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
5116
5138
|
perspective?: ClientPerspective
|
|
5139
|
+
/**
|
|
5140
|
+
* @beta
|
|
5141
|
+
*/
|
|
5142
|
+
variant?: ClientVariant
|
|
5117
5143
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5118
5144
|
returnQuery?: boolean
|
|
5119
5145
|
useCdn?: boolean
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -719,6 +719,10 @@ export declare interface ClientConfig {
|
|
|
719
719
|
* @defaultValue 'published'
|
|
720
720
|
*/
|
|
721
721
|
perspective?: ClientPerspective
|
|
722
|
+
/**
|
|
723
|
+
* @beta
|
|
724
|
+
*/
|
|
725
|
+
variant?: ClientVariant
|
|
722
726
|
apiHost?: string
|
|
723
727
|
/**
|
|
724
728
|
@remarks
|
|
@@ -880,6 +884,18 @@ export declare type ClientReturn<
|
|
|
880
884
|
*/
|
|
881
885
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
882
886
|
|
|
887
|
+
/**
|
|
888
|
+
* @public
|
|
889
|
+
* @beta
|
|
890
|
+
*/
|
|
891
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* @public
|
|
895
|
+
* @beta
|
|
896
|
+
*/
|
|
897
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
898
|
+
|
|
883
899
|
/**
|
|
884
900
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
885
901
|
*
|
|
@@ -4526,6 +4542,8 @@ export declare interface QueryParams {
|
|
|
4526
4542
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4527
4543
|
perspective?: never
|
|
4528
4544
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4545
|
+
variant?: never
|
|
4546
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4529
4547
|
query?: never
|
|
4530
4548
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4531
4549
|
resultSourceMap?: never
|
|
@@ -5066,6 +5084,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
5066
5084
|
returnQuery?: boolean
|
|
5067
5085
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5068
5086
|
perspective?: ClientPerspective
|
|
5087
|
+
/**
|
|
5088
|
+
* @beta
|
|
5089
|
+
*/
|
|
5090
|
+
variant?: ClientVariant
|
|
5069
5091
|
lastLiveEventId?: string
|
|
5070
5092
|
cacheMode?: 'noStale'
|
|
5071
5093
|
}
|
|
@@ -5114,6 +5136,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
5114
5136
|
/** @public */
|
|
5115
5137
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
5116
5138
|
perspective?: ClientPerspective
|
|
5139
|
+
/**
|
|
5140
|
+
* @beta
|
|
5141
|
+
*/
|
|
5142
|
+
variant?: ClientVariant
|
|
5117
5143
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5118
5144
|
returnQuery?: boolean
|
|
5119
5145
|
useCdn?: boolean
|
package/dist/stega.d.cts
CHANGED
|
@@ -719,6 +719,10 @@ export declare interface ClientConfig {
|
|
|
719
719
|
* @defaultValue 'published'
|
|
720
720
|
*/
|
|
721
721
|
perspective?: ClientPerspective
|
|
722
|
+
/**
|
|
723
|
+
* @beta
|
|
724
|
+
*/
|
|
725
|
+
variant?: ClientVariant
|
|
722
726
|
apiHost?: string
|
|
723
727
|
/**
|
|
724
728
|
@remarks
|
|
@@ -880,6 +884,18 @@ export declare type ClientReturn<
|
|
|
880
884
|
*/
|
|
881
885
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
882
886
|
|
|
887
|
+
/**
|
|
888
|
+
* @public
|
|
889
|
+
* @beta
|
|
890
|
+
*/
|
|
891
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* @public
|
|
895
|
+
* @beta
|
|
896
|
+
*/
|
|
897
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
898
|
+
|
|
883
899
|
/**
|
|
884
900
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
885
901
|
*
|
|
@@ -4526,6 +4542,8 @@ export declare interface QueryParams {
|
|
|
4526
4542
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4527
4543
|
perspective?: never
|
|
4528
4544
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4545
|
+
variant?: never
|
|
4546
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4529
4547
|
query?: never
|
|
4530
4548
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4531
4549
|
resultSourceMap?: never
|
|
@@ -5066,6 +5084,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
5066
5084
|
returnQuery?: boolean
|
|
5067
5085
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5068
5086
|
perspective?: ClientPerspective
|
|
5087
|
+
/**
|
|
5088
|
+
* @beta
|
|
5089
|
+
*/
|
|
5090
|
+
variant?: ClientVariant
|
|
5069
5091
|
lastLiveEventId?: string
|
|
5070
5092
|
cacheMode?: 'noStale'
|
|
5071
5093
|
}
|
|
@@ -5114,6 +5136,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
5114
5136
|
/** @public */
|
|
5115
5137
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
5116
5138
|
perspective?: ClientPerspective
|
|
5139
|
+
/**
|
|
5140
|
+
* @beta
|
|
5141
|
+
*/
|
|
5142
|
+
variant?: ClientVariant
|
|
5117
5143
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5118
5144
|
returnQuery?: boolean
|
|
5119
5145
|
useCdn?: boolean
|
package/dist/stega.d.ts
CHANGED
|
@@ -719,6 +719,10 @@ export declare interface ClientConfig {
|
|
|
719
719
|
* @defaultValue 'published'
|
|
720
720
|
*/
|
|
721
721
|
perspective?: ClientPerspective
|
|
722
|
+
/**
|
|
723
|
+
* @beta
|
|
724
|
+
*/
|
|
725
|
+
variant?: ClientVariant
|
|
722
726
|
apiHost?: string
|
|
723
727
|
/**
|
|
724
728
|
@remarks
|
|
@@ -880,6 +884,18 @@ export declare type ClientReturn<
|
|
|
880
884
|
*/
|
|
881
885
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
882
886
|
|
|
887
|
+
/**
|
|
888
|
+
* @public
|
|
889
|
+
* @beta
|
|
890
|
+
*/
|
|
891
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* @public
|
|
895
|
+
* @beta
|
|
896
|
+
*/
|
|
897
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
898
|
+
|
|
883
899
|
/**
|
|
884
900
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
885
901
|
*
|
|
@@ -4526,6 +4542,8 @@ export declare interface QueryParams {
|
|
|
4526
4542
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4527
4543
|
perspective?: never
|
|
4528
4544
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4545
|
+
variant?: never
|
|
4546
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4529
4547
|
query?: never
|
|
4530
4548
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4531
4549
|
resultSourceMap?: never
|
|
@@ -5066,6 +5084,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
5066
5084
|
returnQuery?: boolean
|
|
5067
5085
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5068
5086
|
perspective?: ClientPerspective
|
|
5087
|
+
/**
|
|
5088
|
+
* @beta
|
|
5089
|
+
*/
|
|
5090
|
+
variant?: ClientVariant
|
|
5069
5091
|
lastLiveEventId?: string
|
|
5070
5092
|
cacheMode?: 'noStale'
|
|
5071
5093
|
}
|
|
@@ -5114,6 +5136,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
5114
5136
|
/** @public */
|
|
5115
5137
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
5116
5138
|
perspective?: ClientPerspective
|
|
5139
|
+
/**
|
|
5140
|
+
* @beta
|
|
5141
|
+
*/
|
|
5142
|
+
variant?: ClientVariant
|
|
5117
5143
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
5118
5144
|
returnQuery?: boolean
|
|
5119
5145
|
useCdn?: boolean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.24.0",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"singleQuote": true
|
|
130
130
|
},
|
|
131
131
|
"dependencies": {
|
|
132
|
-
"@sanity/eventsource": "^5.0.
|
|
132
|
+
"@sanity/eventsource": "^5.0.4",
|
|
133
133
|
"get-it": "^8.8.0",
|
|
134
134
|
"nanoid": "^3.3.11",
|
|
135
135
|
"rxjs": "^7.0.0"
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -549,6 +549,7 @@ export function _dataRequest(
|
|
|
549
549
|
tag,
|
|
550
550
|
returnQuery,
|
|
551
551
|
perspective: options.perspective,
|
|
552
|
+
variant: options.variant,
|
|
552
553
|
resultSourceMap: options.resultSourceMap,
|
|
553
554
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
554
555
|
cacheMode: cacheMode,
|
|
@@ -700,6 +701,36 @@ export function _requestObservable<R>(
|
|
|
700
701
|
}
|
|
701
702
|
}
|
|
702
703
|
|
|
704
|
+
const variantOption = options.variant || config.variant
|
|
705
|
+
|
|
706
|
+
if (typeof variantOption !== 'undefined') {
|
|
707
|
+
if (typeof variantOption === 'string') {
|
|
708
|
+
options.query = {
|
|
709
|
+
variant: variantOption,
|
|
710
|
+
...options.query,
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (typeof variantOption === 'object') {
|
|
715
|
+
const variantConditions = Object.entries(variantOption)
|
|
716
|
+
const searchParams = variantConditionPairsToSearchParams(variantConditions).slice(0, 1)
|
|
717
|
+
|
|
718
|
+
if (variantConditions.length > 1) {
|
|
719
|
+
const formatter = new Intl.ListFormat('en')
|
|
720
|
+
|
|
721
|
+
// eslint-disable-next-line no-console -- will be removed in an upcoming version; it's better this behaviour is noisy and obvious
|
|
722
|
+
console.warn(
|
|
723
|
+
`The Sanity client's beta \`variant\` option currently only supports one condition. Dropped: ${formatter.format(variantConditions.slice(1).map(([subject]) => JSON.stringify(subject)))}.`,
|
|
724
|
+
)
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
options.query = {
|
|
728
|
+
...Object.fromEntries(searchParams),
|
|
729
|
+
...options.query,
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
703
734
|
if (options.lastLiveEventId) {
|
|
704
735
|
options.query = {...options.query, lastLiveEventId: options.lastLiveEventId}
|
|
705
736
|
}
|
|
@@ -843,3 +874,12 @@ const resourceDataBase = (config: InitializedClientConfig): string => {
|
|
|
843
874
|
throw new Error(`Unsupported resource type: ${type.toString()}`)
|
|
844
875
|
}
|
|
845
876
|
}
|
|
877
|
+
|
|
878
|
+
function variantConditionPairsToSearchParams(
|
|
879
|
+
variantConditionPairs: string[][],
|
|
880
|
+
): ['variantCondition', `${string}:${string}`][] {
|
|
881
|
+
return variantConditionPairs.map(([condition, value]) => [
|
|
882
|
+
'variantCondition',
|
|
883
|
+
`${condition}:${value}`,
|
|
884
|
+
])
|
|
885
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -55,6 +55,18 @@ export type ClientPerspective =
|
|
|
55
55
|
| 'raw'
|
|
56
56
|
| StackablePerspective[]
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
* @beta
|
|
61
|
+
*/
|
|
62
|
+
export type ClientVariantConditions = Record<string, string>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @public
|
|
66
|
+
* @beta
|
|
67
|
+
*/
|
|
68
|
+
export type ClientVariant = ClientVariantConditions | string
|
|
69
|
+
|
|
58
70
|
type ClientConfigResource =
|
|
59
71
|
| {
|
|
60
72
|
type: 'canvas'
|
|
@@ -111,6 +123,10 @@ export interface ClientConfig {
|
|
|
111
123
|
* @defaultValue 'published'
|
|
112
124
|
*/
|
|
113
125
|
perspective?: ClientPerspective
|
|
126
|
+
/**
|
|
127
|
+
* @beta
|
|
128
|
+
*/
|
|
129
|
+
variant?: ClientVariant
|
|
114
130
|
apiHost?: string
|
|
115
131
|
|
|
116
132
|
/**
|
|
@@ -484,6 +500,10 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
|
|
|
484
500
|
returnQuery?: boolean
|
|
485
501
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
486
502
|
perspective?: ClientPerspective
|
|
503
|
+
/**
|
|
504
|
+
* @beta
|
|
505
|
+
*/
|
|
506
|
+
variant?: ClientVariant
|
|
487
507
|
lastLiveEventId?: string
|
|
488
508
|
cacheMode?: 'noStale'
|
|
489
509
|
}
|
|
@@ -679,6 +699,8 @@ export interface QueryParams {
|
|
|
679
699
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
680
700
|
perspective?: never
|
|
681
701
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
702
|
+
variant?: never
|
|
703
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
682
704
|
query?: never
|
|
683
705
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
684
706
|
resultSourceMap?: never
|
|
@@ -1424,6 +1446,10 @@ export interface ResumableListenOptions extends Omit<ListenOptions, 'events' | '
|
|
|
1424
1446
|
/** @public */
|
|
1425
1447
|
export interface ResponseQueryOptions extends RequestOptions {
|
|
1426
1448
|
perspective?: ClientPerspective
|
|
1449
|
+
/**
|
|
1450
|
+
* @beta
|
|
1451
|
+
*/
|
|
1452
|
+
variant?: ClientVariant
|
|
1427
1453
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
1428
1454
|
returnQuery?: boolean
|
|
1429
1455
|
useCdn?: boolean
|
package/umd/sanityClient.js
CHANGED
|
@@ -4,21 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SanityClient = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function _mergeNamespaces(n, m) {
|
|
8
|
-
m.forEach(function (e) {
|
|
9
|
-
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default' && !(k in n)) {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
7
|
const e=!(typeof navigator>"u")&&"ReactNative"===navigator.product,t={timeout:e?6e4:12e4},r=function(r){const a={...t,..."string"==typeof r?{url:r}:r};if(a.timeout=n$1(a.timeout),a.query){const{url:t,searchParams:r}=function(t){const r=t.indexOf("?");if(-1===r)return {url:t,searchParams:new URLSearchParams};const n=t.slice(0,r),a=t.slice(r+1);if(!e)return {url:n,searchParams:new URLSearchParams(a)};if("function"!=typeof decodeURIComponent)throw new Error("Broken `URLSearchParams` implementation, and `decodeURIComponent` is not defined");const s=new URLSearchParams;for(const e of a.split("&")){const[t,r]=e.split("=");t&&s.append(o$1(t),o$1(r||""));}return {url:n,searchParams:s}}(a.url);for(const[e,o]of Object.entries(a.query)){if(void 0!==o)if(Array.isArray(o))for(const t of o)r.append(e,t);else r.append(e,o);const n=r.toString();n&&(a.url=`${t}?${n}`);}}return a.method=a.body&&!a.method?"POST":(a.method||"GET").toUpperCase(),a};function o$1(e){return decodeURIComponent(e.replace(/\+/g," "))}function n$1(e){if(false===e||0===e)return false;if(e.connect||e.socket)return e;const r=Number(e);return isNaN(r)?n$1(t.timeout):{connect:r,socket:r}}const a$2=/^https?:\/\//i,s$1=function(e){if(!a$2.test(e.url))throw new Error(`"${e.url}" is not a valid URL`)};function c$2(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}
|
|
23
8
|
|
|
24
9
|
const o=["request","response","progress","error","abort"],n=["processOptions","validateOptions","interceptRequest","finalizeOptions","onRequest","onResponse","onError","onReturn","onHeaders"];function s(r$1,i){const a=[],u=n.reduce((e,t)=>(e[t]=e[t]||[],e),{processOptions:[r],validateOptions:[s$1]});function c(e){const t="object"==typeof e&&e.callSiteStack?e.callSiteStack:void 0,r=t?void 0:new Error,n=o.reduce((e,t)=>(e[t]=function(){const e=/* @__PURE__ */Object.create(null);let t=0;return {publish:function(t){for(const r in e)e[r](t);},subscribe:function(r){const o=t++;return e[o]=r,function(){delete e[o];}}}}(),e),{}),s=(e=>function(t,r,...o){const n="onError"===t;let s=r;for(let r=0;r<e[t].length&&(s=(0, e[t][r])(s,...o),!n||s);r++);return s})(u),a=s("processOptions",e);s("validateOptions",a);const c={options:a,channels:n,applyMiddleware:s};let l;const h=n.request.subscribe(e=>{l=i(e,(o,i)=>((e,o,i)=>{let a=e,u=o;if(!a)try{u=s("onResponse",o,i);}catch(e){u=null,a=e;}if(a=a&&s("onError",a,i),a){if(a instanceof Error){const e=t?.stack||r?.stack;if("string"==typeof e){const r=e.split("\n").slice(t?1:2);r.length>0&&(a.stack+="\n"+r.join("\n"));}}n.error.publish(a);}else u&&n.response.publish(u);})(o,i,e));});n.abort.subscribe(()=>{h(),l&&l.abort();});const d=s("onReturn",n,c);return d===n&&n.request.publish(c),d}return c.use=function(e){if(!e)throw new Error("Tried to add middleware that resolved to falsey value");if("function"==typeof e)throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");if(e.onReturn&&u.onReturn.length>0)throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");return n.forEach(t=>{e[t]&&u[t].push(e[t]);}),a.push(e),c},c.clone=()=>s(a,i),r$1.forEach(c.use),c}var i,a$1,u$2=/* @__PURE__ */c$2(function(){if(a$1)return i;a$1=1;var e=function(e){return e.replace(/^\s+|\s+$/g,"")},t=function(e){return "[object Array]"===Object.prototype.toString.call(e)};return i=function(r){if(!r)return {};for(var o=/* @__PURE__ */Object.create(null),n=e(r).split("\n"),s=0;s<n.length;s++){var i=n[s],a=i.indexOf(":"),u=e(i.slice(0,a)).toLowerCase(),c=e(i.slice(a+1));typeof o[u]>"u"?o[u]=c:t(o[u])?o[u].push(c):o[u]=[o[u],c];}return o}}());let c$1 = class c{onabort;onerror;onreadystatechange;ontimeout;readyState=0;response;responseText="";responseType="";status;statusText;withCredentials;#e;#t;#r;#o={};#n;#s={};#i;open(e,t,r){this.#e=e,this.#t=t,this.#r="",this.readyState=1,this.onreadystatechange?.(),this.#n=void 0;}abort(){this.#n&&this.#n.abort();}getAllResponseHeaders(){return this.#r}setRequestHeader(e,t){this.#o[e]=t;}setInit(e,t=true){this.#s=e,this.#i=t;}send(e){const t="arraybuffer"!==this.responseType,r={...this.#s,method:this.#e,headers:this.#o,body:e};"function"==typeof AbortController&&this.#i&&(this.#n=new AbortController,typeof EventTarget<"u"&&this.#n.signal instanceof EventTarget&&(r.signal=this.#n.signal)),typeof document<"u"&&(r.credentials=this.withCredentials?"include":"omit"),fetch(this.#t,r).then(e=>(e.headers.forEach((e,t)=>{this.#r+=`${t}: ${e}\r\n`;}),this.status=e.status,this.statusText=e.statusText,this.readyState=3,this.onreadystatechange?.(),t?e.text():e.arrayBuffer())).then(e=>{"string"==typeof e?this.responseText=e:this.response=e,this.readyState=4,this.onreadystatechange?.();}).catch(e=>{"AbortError"!==e.name?this.onerror?.(e):this.onabort?.();});}};const l$2="function"==typeof XMLHttpRequest?"xhr":"fetch",h$1="xhr"===l$2?XMLHttpRequest:c$1,d$2=(e,t)=>{const r=e.options,o=e.applyMiddleware("finalizeOptions",r),n={},s=e.applyMiddleware("interceptRequest",void 0,{adapter:l$2,context:e});if(s){const e=setTimeout(t,0,null,s);return {abort:()=>clearTimeout(e)}}let i=new h$1;i instanceof c$1&&"object"==typeof o.fetch&&i.setInit(o.fetch,o.useAbortSignal??true);const a=o.headers,d=o.timeout;let p=false,f=false,b=false;if(i.onerror=e=>{m(i instanceof c$1?e instanceof Error?e:new Error(`Request error while attempting to reach ${o.url}`,{cause:e}):new Error(`Request error while attempting to reach is ${o.url}${e.lengthComputable?`(${e.loaded} of ${e.total} bytes transferred)`:""}`));},i.ontimeout=e=>{m(new Error(`Request timeout while attempting to reach ${o.url}${e.lengthComputable?`(${e.loaded} of ${e.total} bytes transferred)`:""}`));},i.onabort=()=>{w(true),p=true;},i.onreadystatechange=function(){d&&(w(),n.socket=setTimeout(()=>y("ESOCKETTIMEDOUT"),d.socket)),!p&&i&&4===i.readyState&&0!==i.status&&function(){if(!(p||f||b)){if(0===i.status)return void m(new Error("Unknown XHR error"));w(),f=true,t(null,{body:i.response||(""===i.responseType||"text"===i.responseType?i.responseText:""),url:o.url,method:o.method,headers:u$2(i.getAllResponseHeaders()),statusCode:i.status,statusMessage:i.statusText});}}();},i.open(o.method,o.url,true),i.withCredentials=!!o.withCredentials,a&&i.setRequestHeader)for(const e in a)a.hasOwnProperty(e)&&i.setRequestHeader(e,a[e]);return o.rawBody&&(i.responseType="arraybuffer"),e.applyMiddleware("onRequest",{options:o,adapter:l$2,request:i,context:e}),i.send(o.body||null),d&&(n.connect=setTimeout(()=>y("ETIMEDOUT"),d.connect)),{abort:function(){p=true,i&&i.abort();}};function y(t){b=true,i.abort();const r=new Error("ESOCKETTIMEDOUT"===t?`Socket timed out on request to ${o.url}`:`Connection timed out on request to ${o.url}`);r.code=t,e.channels.error.publish(r);}function w(e){(e||p||i&&i.readyState>=2&&n.connect)&&clearTimeout(n.connect),n.socket&&clearTimeout(n.socket);}function m(e){if(f)return;w(true),f=true,i=null;const r=e||new Error(`Network error while attempting to reach ${o.url}`);r.isNetworkError=true,r.request=o,t(r);}},p$2=(e=[],t=d$2)=>s(e,t),f="browser";
|
|
@@ -3111,6 +3096,7 @@ ${selectionOpts}`);
|
|
|
3111
3096
|
tag,
|
|
3112
3097
|
returnQuery,
|
|
3113
3098
|
perspective: options.perspective,
|
|
3099
|
+
variant: options.variant,
|
|
3114
3100
|
resultSourceMap: options.resultSourceMap,
|
|
3115
3101
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
3116
3102
|
cacheMode,
|
|
@@ -3158,7 +3144,25 @@ ${selectionOpts}`);
|
|
|
3158
3144
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
3159
3145
|
...options.query
|
|
3160
3146
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
3161
|
-
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning()))
|
|
3147
|
+
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning()));
|
|
3148
|
+
const variantOption = options.variant || config.variant;
|
|
3149
|
+
if (typeof variantOption < "u" && (typeof variantOption == "string" && (options.query = {
|
|
3150
|
+
variant: variantOption,
|
|
3151
|
+
...options.query
|
|
3152
|
+
}), typeof variantOption == "object")) {
|
|
3153
|
+
const variantConditions = Object.entries(variantOption), searchParams = variantConditionPairsToSearchParams(variantConditions).slice(0, 1);
|
|
3154
|
+
if (variantConditions.length > 1) {
|
|
3155
|
+
const formatter = new Intl.ListFormat("en");
|
|
3156
|
+
console.warn(
|
|
3157
|
+
`The Sanity client's beta \`variant\` option currently only supports one condition. Dropped: ${formatter.format(variantConditions.slice(1).map(([subject]) => JSON.stringify(subject)))}.`
|
|
3158
|
+
);
|
|
3159
|
+
}
|
|
3160
|
+
options.query = {
|
|
3161
|
+
...Object.fromEntries(searchParams),
|
|
3162
|
+
...options.query
|
|
3163
|
+
};
|
|
3164
|
+
}
|
|
3165
|
+
options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === false && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
3162
3166
|
}
|
|
3163
3167
|
const reqOptions = requestOptions(
|
|
3164
3168
|
config,
|
|
@@ -3233,6 +3237,12 @@ ${selectionOpts}`);
|
|
|
3233
3237
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
3234
3238
|
}
|
|
3235
3239
|
};
|
|
3240
|
+
function variantConditionPairsToSearchParams(variantConditionPairs) {
|
|
3241
|
+
return variantConditionPairs.map(([condition, value]) => [
|
|
3242
|
+
"variantCondition",
|
|
3243
|
+
`${condition}:${value}`
|
|
3244
|
+
]);
|
|
3245
|
+
}
|
|
3236
3246
|
function _generate(client, httpRequest, request) {
|
|
3237
3247
|
const dataset2 = hasDataset(client.config());
|
|
3238
3248
|
return _request(client, httpRequest, {
|
|
@@ -3431,7 +3441,7 @@ ${selectionOpts}`);
|
|
|
3431
3441
|
);
|
|
3432
3442
|
}
|
|
3433
3443
|
var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
|
|
3434
|
-
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => Promise.resolve().then(function () { return browser
|
|
3444
|
+
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => Promise.resolve().then(function () { return browser; })).pipe(
|
|
3435
3445
|
map(({ default: EventSource2 }) => EventSource2),
|
|
3436
3446
|
shareReplay(1)
|
|
3437
3447
|
), RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
|
|
@@ -6488,23 +6498,23 @@ ${selectionOpts}`);
|
|
|
6488
6498
|
return eventsource$1.exports;
|
|
6489
6499
|
}
|
|
6490
6500
|
|
|
6491
|
-
var browser$
|
|
6501
|
+
var browser$1;
|
|
6492
6502
|
var hasRequiredBrowser;
|
|
6493
6503
|
|
|
6494
6504
|
function requireBrowser () {
|
|
6495
|
-
if (hasRequiredBrowser) return browser$
|
|
6505
|
+
if (hasRequiredBrowser) return browser$1;
|
|
6496
6506
|
hasRequiredBrowser = 1;
|
|
6497
|
-
browser$
|
|
6498
|
-
return browser$
|
|
6507
|
+
browser$1 = requireEventsource().EventSourcePolyfill;
|
|
6508
|
+
return browser$1;
|
|
6499
6509
|
}
|
|
6500
6510
|
|
|
6501
6511
|
var browserExports = /*@__PURE__*/ requireBrowser();
|
|
6502
|
-
var
|
|
6512
|
+
var EventSourcePolyfill = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
6503
6513
|
|
|
6504
|
-
var browser
|
|
6514
|
+
var browser = /*#__PURE__*/Object.freeze({
|
|
6505
6515
|
__proto__: null,
|
|
6506
|
-
default:
|
|
6507
|
-
}
|
|
6516
|
+
default: EventSourcePolyfill
|
|
6517
|
+
});
|
|
6508
6518
|
|
|
6509
6519
|
exports.BasePatch = BasePatch;
|
|
6510
6520
|
exports.BaseTransaction = BaseTransaction;
|