@sanity/client 6.13.2 → 6.14.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.
Files changed (55) hide show
  1. package/dist/_chunks/{browserMiddleware-e8tcYvdt.cjs → browserMiddleware-B2MFFa3m.cjs} +14 -5
  2. package/dist/_chunks/browserMiddleware-B2MFFa3m.cjs.map +1 -0
  3. package/dist/_chunks/{browserMiddleware-C0hQLS9X.js → browserMiddleware-nhWQI70y.js} +14 -5
  4. package/dist/_chunks/browserMiddleware-nhWQI70y.js.map +1 -0
  5. package/dist/_chunks/{nodeMiddleware-BhRfWf0W.cjs → nodeMiddleware-CfcASl-f.cjs} +15 -6
  6. package/dist/_chunks/nodeMiddleware-CfcASl-f.cjs.map +1 -0
  7. package/dist/_chunks/{nodeMiddleware-D2afPgJS.js → nodeMiddleware-Me3HWLoB.js} +15 -6
  8. package/dist/_chunks/nodeMiddleware-Me3HWLoB.js.map +1 -0
  9. package/dist/_chunks/{resolveEditInfo-CkO-V0Hb.cjs → resolveEditInfo-CTU2TYdi.cjs} +14 -4
  10. package/dist/_chunks/resolveEditInfo-CTU2TYdi.cjs.map +1 -0
  11. package/dist/_chunks/{resolveEditInfo-BC6qdqZw.js → resolveEditInfo-DX-6auJZ.js} +14 -4
  12. package/dist/_chunks/resolveEditInfo-DX-6auJZ.js.map +1 -0
  13. package/dist/_chunks/{stegaEncodeSourceMap-BfR5oD3Z.js → stegaEncodeSourceMap-B6IscnhR.js} +14 -5
  14. package/dist/_chunks/stegaEncodeSourceMap-B6IscnhR.js.map +1 -0
  15. package/dist/_chunks/{stegaEncodeSourceMap-B3BX9g4D.js → stegaEncodeSourceMap-DS4_14pP.js} +6 -5
  16. package/dist/_chunks/stegaEncodeSourceMap-DS4_14pP.js.map +1 -0
  17. package/dist/_chunks/{stegaEncodeSourceMap-YSe0h4rd.cjs → stegaEncodeSourceMap-DTaF28aJ.cjs} +6 -5
  18. package/dist/_chunks/stegaEncodeSourceMap-DTaF28aJ.cjs.map +1 -0
  19. package/dist/_chunks/{stegaEncodeSourceMap-Ji8dgoO-.cjs → stegaEncodeSourceMap-Do4zj2pO.cjs} +14 -5
  20. package/dist/_chunks/stegaEncodeSourceMap-Do4zj2pO.cjs.map +1 -0
  21. package/dist/csm.cjs +1 -1
  22. package/dist/csm.d.ts +2 -0
  23. package/dist/csm.js +2 -2
  24. package/dist/index.browser.cjs +1 -1
  25. package/dist/index.browser.js +2 -2
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.ts +56 -1
  28. package/dist/index.js +2 -2
  29. package/dist/stega.browser.cjs +2 -2
  30. package/dist/stega.browser.js +3 -3
  31. package/dist/stega.cjs +2 -2
  32. package/dist/stega.d.ts +56 -1
  33. package/dist/stega.js +3 -3
  34. package/package.json +8 -8
  35. package/src/SanityClient.ts +26 -0
  36. package/src/csm/createEditUrl.ts +8 -0
  37. package/src/csm/resolveEditInfo.ts +3 -1
  38. package/src/csm/types.ts +2 -0
  39. package/src/data/dataMethods.ts +10 -1
  40. package/src/data/encodeQueryString.ts +4 -1
  41. package/src/stega/stegaEncodeSourceMap.ts +2 -1
  42. package/src/stega/types.ts +4 -0
  43. package/src/types.ts +29 -1
  44. package/umd/sanityClient.js +26 -8
  45. package/umd/sanityClient.min.js +3 -3
  46. package/dist/_chunks/browserMiddleware-C0hQLS9X.js.map +0 -1
  47. package/dist/_chunks/browserMiddleware-e8tcYvdt.cjs.map +0 -1
  48. package/dist/_chunks/nodeMiddleware-BhRfWf0W.cjs.map +0 -1
  49. package/dist/_chunks/nodeMiddleware-D2afPgJS.js.map +0 -1
  50. package/dist/_chunks/resolveEditInfo-BC6qdqZw.js.map +0 -1
  51. package/dist/_chunks/resolveEditInfo-CkO-V0Hb.cjs.map +0 -1
  52. package/dist/_chunks/stegaEncodeSourceMap-B3BX9g4D.js.map +0 -1
  53. package/dist/_chunks/stegaEncodeSourceMap-BfR5oD3Z.js.map +0 -1
  54. package/dist/_chunks/stegaEncodeSourceMap-Ji8dgoO-.cjs.map +0 -1
  55. package/dist/_chunks/stegaEncodeSourceMap-YSe0h4rd.cjs.map +0 -1
@@ -80,6 +80,7 @@ export function _fetch<R, Q>(
80
80
  const params = stega.enabled ? vercelStegaCleanAll(_params) : _params
81
81
  const mapResponse =
82
82
  options.filterResponse === false ? (res: Any) => res : (res: Any) => res.result
83
+
83
84
  const {cache, next, ...opts} = {
84
85
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
85
86
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
@@ -87,6 +88,9 @@ export function _fetch<R, Q>(
87
88
  // Set `resultSourceMap' when stega is enabled, as it's required for encoding.
88
89
  resultSourceMap: stega.enabled ? 'withKeyArraySelector' : options.resultSourceMap,
89
90
  ...options,
91
+ // Default to not returning the query, unless `filterResponse` is `false`,
92
+ // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
93
+ returnQuery: options.filterResponse === false && options.returnQuery !== false,
90
94
  }
91
95
  const reqOpts =
92
96
  typeof cache !== 'undefined' || typeof next !== 'undefined'
@@ -253,7 +257,7 @@ export function _dataRequest(
253
257
  const useGet = !isMutation && strQuery.length < getQuerySizeLimit
254
258
  const stringQuery = useGet ? strQuery : ''
255
259
  const returnFirst = options.returnFirst
256
- const {timeout, token, tag, headers} = options
260
+ const {timeout, token, tag, headers, returnQuery} = options
257
261
 
258
262
  const uri = _getDataUrl(client, endpoint, stringQuery)
259
263
 
@@ -267,6 +271,7 @@ export function _dataRequest(
267
271
  headers,
268
272
  token,
269
273
  tag,
274
+ returnQuery,
270
275
  perspective: options.perspective,
271
276
  resultSourceMap: options.resultSourceMap,
272
277
  canUseCdn: isQuery,
@@ -369,6 +374,10 @@ export function _requestObservable<R>(
369
374
  printCdnPreviewDraftsWarning()
370
375
  }
371
376
  }
377
+
378
+ if (options.returnQuery === false) {
379
+ options.query = {returnQuery: 'false', ...options.query}
380
+ }
372
381
  }
373
382
 
374
383
  const reqOptions = requestOptions(
@@ -11,7 +11,7 @@ export const encodeQueryString = ({
11
11
  }) => {
12
12
  const searchParams = new URLSearchParams()
13
13
  // We generally want tag at the start of the query string
14
- const {tag, ...opts} = options
14
+ const {tag, returnQuery, ...opts} = options
15
15
  // We're using `append` instead of `set` to support React Native: https://github.com/facebook/react-native/blob/1982c4722fcc51aa87e34cf562672ee4aff540f1/packages/react-native/Libraries/Blob/URL.js#L86-L88
16
16
  if (tag) searchParams.append('tag', tag)
17
17
  searchParams.append('query', query)
@@ -26,5 +26,8 @@ export const encodeQueryString = ({
26
26
  if (value) searchParams.append(key, `${value}`)
27
27
  }
28
28
 
29
+ // `returnQuery` is default `true`, so needs an explicit `false` handling
30
+ if (returnQuery === false) searchParams.append('returnQuery', 'false')
31
+
29
32
  return `?${searchParams}`
30
33
  }
@@ -84,7 +84,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
84
84
  : config.studioUrl!,
85
85
  )
86
86
  if (!baseUrl) return value
87
- const {_id: id, _type: type} = sourceDocument
87
+ const {_id: id, _type: type, _projectId: projectId, _dataset: dataset} = sourceDocument
88
88
 
89
89
  return vercelStegaCombine(
90
90
  value,
@@ -97,6 +97,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
97
97
  id,
98
98
  type,
99
99
  path: sourcePath,
100
+ ...(!config.omitCrossDatasetReferenceData && {dataset, projectId}),
100
101
  }),
101
102
  },
102
103
  // We use custom logic to determine if we should skip encoding
@@ -50,6 +50,10 @@ export interface StegaConfig {
50
50
  * Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
51
51
  */
52
52
  logger?: Logger
53
+ /**
54
+ * Set to `true` to omit cross dataset reference specific data from encoded strings
55
+ */
56
+ omitCrossDatasetReferenceData?: boolean
53
57
  }
54
58
 
55
59
  /** @public */
package/src/types.ts CHANGED
@@ -300,6 +300,7 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
300
300
  canUseCdn?: boolean
301
301
  useCdn?: boolean
302
302
  tag?: string
303
+ returnQuery?: boolean
303
304
  resultSourceMap?: boolean | 'withKeyArraySelector'
304
305
  perspective?: ClientPerspective
305
306
  }
@@ -452,6 +453,8 @@ export interface QueryParams {
452
453
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
453
454
  resultSourceMap?: never
454
455
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
456
+ returnQuery?: never
457
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
455
458
  signal?: never
456
459
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
457
460
  stega?: never
@@ -721,6 +724,7 @@ export interface ListenOptions {
721
724
  export interface ResponseQueryOptions extends RequestOptions {
722
725
  perspective?: ClientPerspective
723
726
  resultSourceMap?: boolean | 'withKeyArraySelector'
727
+ returnQuery?: boolean
724
728
  useCdn?: boolean
725
729
  stega?: boolean | StegaConfig
726
730
  // The `cache` and `next` options are specific to the Next.js App Router integration
@@ -736,10 +740,31 @@ export interface FilteredResponseQueryOptions extends ResponseQueryOptions {
736
740
  /** @public */
737
741
  export interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
738
742
  filterResponse: false
743
+
744
+ /**
745
+ * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
746
+ * backwards compatibility (on the client side, not from the content lake API).
747
+ * Can also explicitly be set to `true`.
748
+ */
749
+ returnQuery?: true
750
+ }
751
+
752
+ /**
753
+ * When using `filterResponse: false`, but you do not wish to receive back the query from
754
+ * the content lake API.
755
+ *
756
+ * @public
757
+ */
758
+ export interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
759
+ filterResponse: false
760
+ returnQuery: false
739
761
  }
740
762
 
741
763
  /** @public */
742
- export type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
764
+ export type QueryOptions =
765
+ | FilteredResponseQueryOptions
766
+ | UnfilteredResponseQueryOptions
767
+ | UnfilteredResponseWithoutQuery
743
768
 
744
769
  /** @public */
745
770
  export interface RawQueryResponse<R> {
@@ -749,6 +774,9 @@ export interface RawQueryResponse<R> {
749
774
  resultSourceMap?: ContentSourceMap
750
775
  }
751
776
 
777
+ /** @public */
778
+ export type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
779
+
752
780
  /** @internal */
753
781
  export type BaseMutationOptions = RequestOptions & {
754
782
  visibility?: 'sync' | 'async' | 'deferred'
@@ -3409,7 +3409,7 @@
3409
3409
  options = {}
3410
3410
  }) => {
3411
3411
  const searchParams = new URLSearchParams();
3412
- const { tag, ...opts } = options;
3412
+ const { tag, returnQuery, ...opts } = options;
3413
3413
  if (tag)
3414
3414
  searchParams.append("tag", tag);
3415
3415
  searchParams.append("query", query);
@@ -3420,6 +3420,8 @@
3420
3420
  if (value)
3421
3421
  searchParams.append(key, "".concat(value));
3422
3422
  }
3423
+ if (returnQuery === false)
3424
+ searchParams.append("returnQuery", "false");
3423
3425
  return "?".concat(searchParams);
3424
3426
  };
3425
3427
 
@@ -3457,14 +3459,17 @@
3457
3459
  useAbortSignal: typeof options.signal !== "undefined",
3458
3460
  // Set `resultSourceMap' when stega is enabled, as it's required for encoding.
3459
3461
  resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
3460
- ...options
3462
+ ...options,
3463
+ // Default to not returning the query, unless `filterResponse` is `false`,
3464
+ // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
3465
+ returnQuery: options.filterResponse === false && options.returnQuery !== false
3461
3466
  };
3462
3467
  const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
3463
3468
  const $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
3464
3469
  return stega.enabled ? $request.pipe(
3465
3470
  combineLatestWith(
3466
3471
  from(
3467
- Promise.resolve().then(function () { return stegaEncodeSourceMapBfR5oD3Z; }).then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
3472
+ Promise.resolve().then(function () { return stegaEncodeSourceMapB6IscnhR; }).then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
3468
3473
  ({ stegaEncodeSourceMap }) => stegaEncodeSourceMap
3469
3474
  )
3470
3475
  )
@@ -3531,7 +3536,7 @@
3531
3536
  const useGet = !isMutation && strQuery.length < getQuerySizeLimit;
3532
3537
  const stringQuery = useGet ? strQuery : "";
3533
3538
  const returnFirst = options.returnFirst;
3534
- const { timeout, token, tag, headers } = options;
3539
+ const { timeout, token, tag, headers, returnQuery } = options;
3535
3540
  const uri = _getDataUrl(client, endpoint, stringQuery);
3536
3541
  const reqOptions = {
3537
3542
  method: useGet ? "GET" : "POST",
@@ -3543,6 +3548,7 @@
3543
3548
  headers,
3544
3549
  token,
3545
3550
  tag,
3551
+ returnQuery,
3546
3552
  perspective: options.perspective,
3547
3553
  resultSourceMap: options.resultSourceMap,
3548
3554
  canUseCdn: isQuery,
@@ -3601,6 +3607,9 @@
3601
3607
  printCdnPreviewDraftsWarning();
3602
3608
  }
3603
3609
  }
3610
+ if (options.returnQuery === false) {
3611
+ options.query = { returnQuery: "false", ...options.query };
3612
+ }
3604
3613
  }
3605
3614
  const reqOptions = requestOptions(
3606
3615
  config,
@@ -4743,7 +4752,9 @@
4743
4752
  tool: _tool = "default",
4744
4753
  id: _id,
4745
4754
  type,
4746
- path
4755
+ path,
4756
+ projectId,
4757
+ dataset
4747
4758
  } = options;
4748
4759
  if (!baseUrl) {
4749
4760
  throw new Error("baseUrl is required");
@@ -4773,6 +4784,12 @@
4773
4784
  if (tool) {
4774
4785
  searchParams.set("tool", tool);
4775
4786
  }
4787
+ if (projectId) {
4788
+ searchParams.set("projectId", projectId);
4789
+ }
4790
+ if (dataset) {
4791
+ searchParams.set("dataset", dataset);
4792
+ }
4776
4793
  const segments = [baseUrl === "/" ? "" : baseUrl];
4777
4794
  if (workspace) {
4778
4795
  segments.push(workspace);
@@ -4935,7 +4952,7 @@
4935
4952
  );
4936
4953
  if (!baseUrl)
4937
4954
  return value;
4938
- const { _id: id, _type: type } = sourceDocument;
4955
+ const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
4939
4956
  return b(
4940
4957
  value,
4941
4958
  {
@@ -4946,7 +4963,8 @@
4946
4963
  tool,
4947
4964
  id,
4948
4965
  type,
4949
- path: sourcePath
4966
+ path: sourcePath,
4967
+ ...!config.omitCrossDatasetReferenceData && { dataset, projectId }
4950
4968
  })
4951
4969
  },
4952
4970
  // We use custom logic to determine if we should skip encoding
@@ -4990,7 +5008,7 @@
4990
5008
  stegaEncodeSourceMap: stegaEncodeSourceMap
4991
5009
  });
4992
5010
 
4993
- var stegaEncodeSourceMapBfR5oD3Z = /*#__PURE__*/Object.freeze({
5011
+ var stegaEncodeSourceMapB6IscnhR = /*#__PURE__*/Object.freeze({
4994
5012
  __proto__: null,
4995
5013
  encodeIntoResult: encodeIntoResult,
4996
5014
  stegaEncodeSourceMap: stegaEncodeSourceMap,