@sanity/client 7.25.0 → 7.26.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 +7 -20
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +7 -20
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/dataMethods.ts +16 -30
- package/umd/sanityClient.js +7 -20
- package/umd/sanityClient.min.js +1 -1
package/package.json
CHANGED
package/src/data/dataMethods.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
Any,
|
|
14
14
|
BaseActionOptions,
|
|
15
15
|
BaseMutationOptions,
|
|
16
|
+
ClientVariantConditions,
|
|
16
17
|
CreateVersionAction,
|
|
17
18
|
DiscardVersionAction,
|
|
18
19
|
FirstDocumentIdMutationOptions,
|
|
@@ -703,31 +704,17 @@ export function _requestObservable<R>(
|
|
|
703
704
|
|
|
704
705
|
const variantOption = options.variant || config.variant
|
|
705
706
|
|
|
706
|
-
if (typeof variantOption
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
...options.query,
|
|
711
|
-
}
|
|
707
|
+
if (typeof variantOption === 'string') {
|
|
708
|
+
options.query = {
|
|
709
|
+
variant: variantOption,
|
|
710
|
+
...options.query,
|
|
712
711
|
}
|
|
712
|
+
}
|
|
713
713
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
-
}
|
|
714
|
+
if (typeof variantOption === 'object') {
|
|
715
|
+
options.query = {
|
|
716
|
+
variantCondition: variantConditionsToQueryArray(variantOption),
|
|
717
|
+
...options.query,
|
|
731
718
|
}
|
|
732
719
|
}
|
|
733
720
|
|
|
@@ -875,11 +862,10 @@ const resourceDataBase = (config: InitializedClientConfig): string => {
|
|
|
875
862
|
}
|
|
876
863
|
}
|
|
877
864
|
|
|
878
|
-
function
|
|
879
|
-
|
|
880
|
-
):
|
|
881
|
-
return
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
])
|
|
865
|
+
function variantConditionsToQueryArray(
|
|
866
|
+
variantConditions: ClientVariantConditions,
|
|
867
|
+
): `${string}:${string}`[] {
|
|
868
|
+
return Object.entries(variantConditions)
|
|
869
|
+
.map<`${string}:${string}`>(([condition, value]) => `${condition}:${value}`)
|
|
870
|
+
.toSorted()
|
|
885
871
|
}
|
package/umd/sanityClient.js
CHANGED
|
@@ -3146,23 +3146,13 @@ ${selectionOpts}`);
|
|
|
3146
3146
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
3147
3147
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning()));
|
|
3148
3148
|
const variantOption = options.variant || config.variant;
|
|
3149
|
-
|
|
3149
|
+
typeof variantOption == "string" && (options.query = {
|
|
3150
3150
|
variant: variantOption,
|
|
3151
3151
|
...options.query
|
|
3152
|
-
}), typeof variantOption == "object"
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
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 });
|
|
3152
|
+
}), typeof variantOption == "object" && (options.query = {
|
|
3153
|
+
variantCondition: variantConditionsToQueryArray(variantOption),
|
|
3154
|
+
...options.query
|
|
3155
|
+
}), 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 });
|
|
3166
3156
|
}
|
|
3167
3157
|
const reqOptions = requestOptions(
|
|
3168
3158
|
config,
|
|
@@ -3237,11 +3227,8 @@ ${selectionOpts}`);
|
|
|
3237
3227
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
3238
3228
|
}
|
|
3239
3229
|
};
|
|
3240
|
-
function
|
|
3241
|
-
return
|
|
3242
|
-
"variantCondition",
|
|
3243
|
-
`${condition}:${value}`
|
|
3244
|
-
]);
|
|
3230
|
+
function variantConditionsToQueryArray(variantConditions) {
|
|
3231
|
+
return Object.entries(variantConditions).map(([condition, value]) => `${condition}:${value}`).toSorted();
|
|
3245
3232
|
}
|
|
3246
3233
|
function _generate(client, httpRequest, request) {
|
|
3247
3234
|
const dataset2 = hasDataset(client.config());
|