@sanity/client 7.23.2 → 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 +1 -1
- package/src/data/dataMethods.ts +40 -0
- package/src/types.ts +26 -0
- package/umd/sanityClient.js +26 -1
- package/umd/sanityClient.min.js +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -726,6 +726,10 @@ export declare interface ClientConfig {
|
|
|
726
726
|
* @defaultValue 'published'
|
|
727
727
|
*/
|
|
728
728
|
perspective?: ClientPerspective
|
|
729
|
+
/**
|
|
730
|
+
* @beta
|
|
731
|
+
*/
|
|
732
|
+
variant?: ClientVariant
|
|
729
733
|
apiHost?: string
|
|
730
734
|
/**
|
|
731
735
|
@remarks
|
|
@@ -881,6 +885,18 @@ export declare type ClientReturn<
|
|
|
881
885
|
Fallback = Any,
|
|
882
886
|
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
883
887
|
|
|
888
|
+
/**
|
|
889
|
+
* @public
|
|
890
|
+
* @beta
|
|
891
|
+
*/
|
|
892
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* @public
|
|
896
|
+
* @beta
|
|
897
|
+
*/
|
|
898
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
899
|
+
|
|
884
900
|
/**
|
|
885
901
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
886
902
|
*
|
|
@@ -4348,6 +4364,8 @@ export declare interface QueryParams {
|
|
|
4348
4364
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4349
4365
|
perspective?: never
|
|
4350
4366
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4367
|
+
variant?: never
|
|
4368
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4351
4369
|
query?: never
|
|
4352
4370
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4353
4371
|
resultSourceMap?: never
|
|
@@ -4885,6 +4903,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4885
4903
|
returnQuery?: boolean
|
|
4886
4904
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4887
4905
|
perspective?: ClientPerspective
|
|
4906
|
+
/**
|
|
4907
|
+
* @beta
|
|
4908
|
+
*/
|
|
4909
|
+
variant?: ClientVariant
|
|
4888
4910
|
lastLiveEventId?: string
|
|
4889
4911
|
cacheMode?: 'noStale'
|
|
4890
4912
|
}
|
|
@@ -4930,6 +4952,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4930
4952
|
/** @public */
|
|
4931
4953
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4932
4954
|
perspective?: ClientPerspective
|
|
4955
|
+
/**
|
|
4956
|
+
* @beta
|
|
4957
|
+
*/
|
|
4958
|
+
variant?: ClientVariant
|
|
4933
4959
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4934
4960
|
returnQuery?: boolean
|
|
4935
4961
|
useCdn?: boolean
|
package/dist/index.d.ts
CHANGED
|
@@ -726,6 +726,10 @@ export declare interface ClientConfig {
|
|
|
726
726
|
* @defaultValue 'published'
|
|
727
727
|
*/
|
|
728
728
|
perspective?: ClientPerspective
|
|
729
|
+
/**
|
|
730
|
+
* @beta
|
|
731
|
+
*/
|
|
732
|
+
variant?: ClientVariant
|
|
729
733
|
apiHost?: string
|
|
730
734
|
/**
|
|
731
735
|
@remarks
|
|
@@ -881,6 +885,18 @@ export declare type ClientReturn<
|
|
|
881
885
|
Fallback = Any,
|
|
882
886
|
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
883
887
|
|
|
888
|
+
/**
|
|
889
|
+
* @public
|
|
890
|
+
* @beta
|
|
891
|
+
*/
|
|
892
|
+
export declare type ClientVariant = ClientVariantConditions | string
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* @public
|
|
896
|
+
* @beta
|
|
897
|
+
*/
|
|
898
|
+
export declare type ClientVariantConditions = Record<string, string>
|
|
899
|
+
|
|
884
900
|
/**
|
|
885
901
|
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
886
902
|
*
|
|
@@ -4348,6 +4364,8 @@ export declare interface QueryParams {
|
|
|
4348
4364
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4349
4365
|
perspective?: never
|
|
4350
4366
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4367
|
+
variant?: never
|
|
4368
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4351
4369
|
query?: never
|
|
4352
4370
|
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
4353
4371
|
resultSourceMap?: never
|
|
@@ -4885,6 +4903,10 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
|
|
|
4885
4903
|
returnQuery?: boolean
|
|
4886
4904
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4887
4905
|
perspective?: ClientPerspective
|
|
4906
|
+
/**
|
|
4907
|
+
* @beta
|
|
4908
|
+
*/
|
|
4909
|
+
variant?: ClientVariant
|
|
4888
4910
|
lastLiveEventId?: string
|
|
4889
4911
|
cacheMode?: 'noStale'
|
|
4890
4912
|
}
|
|
@@ -4930,6 +4952,10 @@ export declare interface ResponseEvent<T = unknown> {
|
|
|
4930
4952
|
/** @public */
|
|
4931
4953
|
export declare interface ResponseQueryOptions extends RequestOptions {
|
|
4932
4954
|
perspective?: ClientPerspective
|
|
4955
|
+
/**
|
|
4956
|
+
* @beta
|
|
4957
|
+
*/
|
|
4958
|
+
variant?: ClientVariant
|
|
4933
4959
|
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
4934
4960
|
returnQuery?: boolean
|
|
4935
4961
|
useCdn?: boolean
|
package/dist/index.js
CHANGED
|
@@ -928,6 +928,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
928
928
|
tag,
|
|
929
929
|
returnQuery,
|
|
930
930
|
perspective: options.perspective,
|
|
931
|
+
variant: options.variant,
|
|
931
932
|
resultSourceMap: options.resultSourceMap,
|
|
932
933
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
933
934
|
cacheMode,
|
|
@@ -975,7 +976,25 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
975
976
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
976
977
|
...options.query
|
|
977
978
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
978
|
-
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()))
|
|
979
|
+
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
980
|
+
const variantOption = options.variant || config.variant;
|
|
981
|
+
if (typeof variantOption < "u" && (typeof variantOption == "string" && (options.query = {
|
|
982
|
+
variant: variantOption,
|
|
983
|
+
...options.query
|
|
984
|
+
}), typeof variantOption == "object")) {
|
|
985
|
+
const variantConditions = Object.entries(variantOption), searchParams = variantConditionPairsToSearchParams(variantConditions).slice(0, 1);
|
|
986
|
+
if (variantConditions.length > 1) {
|
|
987
|
+
const formatter = new Intl.ListFormat("en");
|
|
988
|
+
console.warn(
|
|
989
|
+
`The Sanity client's beta \`variant\` option currently only supports one condition. Dropped: ${formatter.format(variantConditions.slice(1).map(([subject]) => JSON.stringify(subject)))}.`
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
options.query = {
|
|
993
|
+
...Object.fromEntries(searchParams),
|
|
994
|
+
...options.query
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
979
998
|
}
|
|
980
999
|
const reqOptions = requestOptions(
|
|
981
1000
|
config,
|
|
@@ -1050,6 +1069,12 @@ const resourceDataBase = (config) => {
|
|
|
1050
1069
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
1051
1070
|
}
|
|
1052
1071
|
};
|
|
1072
|
+
function variantConditionPairsToSearchParams(variantConditionPairs) {
|
|
1073
|
+
return variantConditionPairs.map(([condition, value]) => [
|
|
1074
|
+
"variantCondition",
|
|
1075
|
+
`${condition}:${value}`
|
|
1076
|
+
]);
|
|
1077
|
+
}
|
|
1053
1078
|
function _generate(client, httpRequest, request) {
|
|
1054
1079
|
const dataset2 = hasDataset(client.config());
|
|
1055
1080
|
return _request(client, httpRequest, {
|
|
@@ -2854,7 +2879,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2854
2879
|
return printNoDefaultExport(), createClient2(config);
|
|
2855
2880
|
};
|
|
2856
2881
|
}
|
|
2857
|
-
var name = "@sanity/client", version = "7.
|
|
2882
|
+
var name = "@sanity/client", version = "7.24.0";
|
|
2858
2883
|
const middleware = [
|
|
2859
2884
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2860
2885
|
headers({ "User-Agent": `${name} ${version}` }),
|