@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.25.0",
3
+ "version": "7.26.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -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 !== 'undefined') {
707
- if (typeof variantOption === 'string') {
708
- options.query = {
709
- variant: variantOption,
710
- ...options.query,
711
- }
707
+ if (typeof variantOption === 'string') {
708
+ options.query = {
709
+ variant: variantOption,
710
+ ...options.query,
712
711
  }
712
+ }
713
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
- }
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 variantConditionPairsToSearchParams(
879
- variantConditionPairs: string[][],
880
- ): ['variantCondition', `${string}:${string}`][] {
881
- return variantConditionPairs.map(([condition, value]) => [
882
- 'variantCondition',
883
- `${condition}:${value}`,
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
  }
@@ -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
- if (typeof variantOption < "u" && (typeof variantOption == "string" && (options.query = {
3149
+ typeof variantOption == "string" && (options.query = {
3150
3150
  variant: variantOption,
3151
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 });
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 variantConditionPairsToSearchParams(variantConditionPairs) {
3241
- return variantConditionPairs.map(([condition, value]) => [
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());