@sanity/client 6.23.0 → 6.24.0-canary.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.
@@ -390,7 +390,12 @@ export declare class ClientError extends Error {
390
390
  }
391
391
 
392
392
  /** @public */
393
- export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
393
+ export declare type ClientPerspective =
394
+ | 'previewDrafts'
395
+ | 'published'
396
+ | 'drafts'
397
+ | 'raw'
398
+ | ('published' | 'drafts' | ReleaseId)[]
394
399
 
395
400
  /** @public */
396
401
  export declare type ClientReturn<
@@ -2116,6 +2121,9 @@ export declare type ReconnectEvent = {
2116
2121
  type: 'reconnect'
2117
2122
  }
2118
2123
 
2124
+ /** @public */
2125
+ export declare type ReleaseId = `r${string}`
2126
+
2119
2127
  /**
2120
2128
  * Replaces an existing draft document.
2121
2129
  * At least one of the draft or published versions of the document must exist.
@@ -390,7 +390,12 @@ export declare class ClientError extends Error {
390
390
  }
391
391
 
392
392
  /** @public */
393
- export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
393
+ export declare type ClientPerspective =
394
+ | 'previewDrafts'
395
+ | 'published'
396
+ | 'drafts'
397
+ | 'raw'
398
+ | ('published' | 'drafts' | ReleaseId)[]
394
399
 
395
400
  /** @public */
396
401
  export declare type ClientReturn<
@@ -2116,6 +2121,9 @@ export declare type ReconnectEvent = {
2116
2121
  type: 'reconnect'
2117
2122
  }
2118
2123
 
2124
+ /** @public */
2125
+ export declare type ReleaseId = `r${string}`
2126
+
2119
2127
  /**
2120
2128
  * Replaces an existing draft document.
2121
2129
  * At least one of the draft or published versions of the document must exist.
@@ -522,8 +522,17 @@ function validateApiVersion(apiVersion) {
522
522
  throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
523
523
  }
524
524
  const validateApiPerspective = function(perspective) {
525
+ if (Array.isArray(perspective)) {
526
+ for (const perspectiveValue of perspective)
527
+ if (perspectiveValue !== "published" && perspectiveValue !== "drafts" && !(typeof perspectiveValue == "string" && perspectiveValue.startsWith("r") && perspectiveValue !== "raw"))
528
+ throw new TypeError(
529
+ "Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string"
530
+ );
531
+ return;
532
+ }
525
533
  switch (perspective) {
526
534
  case "previewDrafts":
535
+ case "drafts":
527
536
  case "published":
528
537
  case "raw":
529
538
  return;
@@ -552,7 +561,7 @@ const validateApiPerspective = function(perspective) {
552
561
  }
553
562
  if (projectBased && !newConfig.projectId)
554
563
  throw new Error("Configuration must contain `projectId`");
555
- if (typeof newConfig.perspective == "string" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
564
+ if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
556
565
  throw new Error(
557
566
  "It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
558
567
  );
@@ -748,8 +757,11 @@ function _requestObservable(client, httpRequest, options) {
748
757
  if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
749
758
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
750
759
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
751
- const perspective = options.perspective || config.perspective;
752
- typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), 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 });
760
+ const perspectiveOption = options.perspective || config.perspective;
761
+ typeof perspectiveOption < "u" && (validateApiPerspective(perspectiveOption), options.query = {
762
+ perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
763
+ ...options.query
764
+ }, perspectiveOption === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), 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 });
753
765
  }
754
766
  const reqOptions = requestOptions(
755
767
  config,