@sanity/client 6.25.0-alpha.0 → 6.25.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 (41) hide show
  1. package/dist/_chunks-cjs/resolveEditInfo.cjs +1 -2
  2. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
  3. package/dist/_chunks-cjs/stegaClean.cjs +1 -2
  4. package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
  5. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +1 -2
  6. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
  7. package/dist/_chunks-es/resolveEditInfo.js +1 -2
  8. package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
  9. package/dist/_chunks-es/stegaClean.js +1 -2
  10. package/dist/_chunks-es/stegaClean.js.map +1 -1
  11. package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -2
  12. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
  13. package/dist/csm.cjs +1 -2
  14. package/dist/csm.cjs.map +1 -1
  15. package/dist/csm.d.cts +99 -34
  16. package/dist/csm.d.ts +99 -34
  17. package/dist/csm.js +1 -2
  18. package/dist/csm.js.map +1 -1
  19. package/dist/index.browser.cjs +31 -20
  20. package/dist/index.browser.cjs.map +1 -1
  21. package/dist/index.browser.d.cts +11 -4
  22. package/dist/index.browser.d.ts +11 -4
  23. package/dist/index.browser.js +31 -20
  24. package/dist/index.browser.js.map +1 -1
  25. package/dist/index.cjs +32 -21
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +11 -4
  28. package/dist/index.d.ts +11 -4
  29. package/dist/index.js +32 -21
  30. package/dist/index.js.map +1 -1
  31. package/dist/stega.browser.d.cts +3419 -96
  32. package/dist/stega.browser.d.ts +3419 -96
  33. package/dist/stega.d.cts +3419 -96
  34. package/dist/stega.d.ts +3419 -96
  35. package/package.json +8 -8
  36. package/src/data/transaction.ts +26 -1
  37. package/src/defineCreateClient.ts +5 -3
  38. package/src/http/request.ts +15 -8
  39. package/src/types.ts +1 -0
  40. package/umd/sanityClient.js +156 -161
  41. package/umd/sanityClient.min.js +2 -2
@@ -97,17 +97,23 @@ const httpError = {
97
97
  throw new ClientError(res);
98
98
  return res;
99
99
  }
100
- }, printWarnings = {
101
- onResponse: (res) => {
102
- const warn = res.headers["x-sanity-warning"];
103
- return (Array.isArray(warn) ? warn : [warn]).filter(Boolean).forEach((msg) => console.warn(msg)), res;
104
- }
105
100
  };
101
+ function printWarnings() {
102
+ const seen = {};
103
+ return {
104
+ onResponse: (res) => {
105
+ const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
106
+ for (const msg of warnings)
107
+ !msg || seen[msg] || (seen[msg] = !0, console.warn(msg));
108
+ return res;
109
+ }
110
+ };
111
+ }
106
112
  function defineHttpRequest(envMiddleware2) {
107
113
  return getIt.getIt([
108
114
  middleware.retry({ shouldRetry }),
109
115
  ...envMiddleware2,
110
- printWarnings,
116
+ printWarnings(),
111
117
  middleware.jsonRequest(),
112
118
  middleware.jsonResponse(),
113
119
  middleware.progress(),
@@ -116,8 +122,7 @@ function defineHttpRequest(envMiddleware2) {
116
122
  ]);
117
123
  }
118
124
  function shouldRetry(err, attempt, options) {
119
- if (options.maxRetries === 0)
120
- return !1;
125
+ if (options.maxRetries === 0) return !1;
121
126
  const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
122
127
  return (isSafe || isQuery) && isRetriableResponse ? !0 : middleware.retry.shouldRetry(err, attempt, options);
123
128
  }
@@ -659,8 +664,8 @@ class Transaction extends BaseTransaction {
659
664
  );
660
665
  }
661
666
  patch(patchOrDocumentId, patchOps) {
662
- const isBuilder = typeof patchOps == "function";
663
- if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
667
+ const isBuilder = typeof patchOps == "function", isPatch = typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch, isMutationSelection = typeof patchOrDocumentId == "object" && ("query" in patchOrDocumentId || "id" in patchOrDocumentId);
668
+ if (isPatch)
664
669
  return this._add({ patch: patchOrDocumentId.serialize() });
665
670
  if (isBuilder) {
666
671
  const patch = patchOps(new Patch(patchOrDocumentId, {}, this.#client));
@@ -668,6 +673,10 @@ class Transaction extends BaseTransaction {
668
673
  throw new Error("function passed to `patch()` must return the patch");
669
674
  return this._add({ patch: patch.serialize() });
670
675
  }
676
+ if (isMutationSelection) {
677
+ const patch = new Patch(patchOrDocumentId, patchOps || {}, this.#client);
678
+ return this._add({ patch: patch.serialize() });
679
+ }
671
680
  return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
672
681
  }
673
682
  }
@@ -1617,16 +1626,18 @@ class SanityClient {
1617
1626
  }
1618
1627
  }
1619
1628
  function defineCreateClientExports(envMiddleware2, ClassConstructor) {
1620
- const defaultRequester = defineHttpRequest(envMiddleware2);
1621
- return { requester: defaultRequester, createClient: (config) => new ClassConstructor(
1622
- (options, requester2) => (requester2 || defaultRequester)({
1623
- maxRedirects: 0,
1624
- maxRetries: config.maxRetries,
1625
- retryDelay: config.retryDelay,
1626
- ...options
1627
- }),
1628
- config
1629
- ) };
1629
+ return { requester: defineHttpRequest(envMiddleware2), createClient: (config) => {
1630
+ const clientRequester = defineHttpRequest(envMiddleware2);
1631
+ return new ClassConstructor(
1632
+ (options, requester2) => (requester2 || clientRequester)({
1633
+ maxRedirects: 0,
1634
+ maxRetries: config.maxRetries,
1635
+ retryDelay: config.retryDelay,
1636
+ ...options
1637
+ }),
1638
+ config
1639
+ );
1640
+ } };
1630
1641
  }
1631
1642
  function defineDeprecatedCreateClient(createClient2) {
1632
1643
  return function(config) {