@sanity/client 6.20.2-beta.2 → 6.20.2

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.
@@ -601,7 +601,6 @@ function requestOptions(config, overrides = {}) {
601
601
  proxy: overrides.proxy || config.proxy,
602
602
  json: !0,
603
603
  withCredentials,
604
- useDomainSharding: config.useDomainSharding,
605
604
  fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
606
605
  });
607
606
  }
@@ -873,55 +872,6 @@ function optionsFromFile(opts, file) {
873
872
  opts
874
873
  );
875
874
  }
876
- const UNSHARDED_URL_RE = /^https:\/\/([a-z0-9]+)\.api\.(sanity\..*)/, SHARDED_URL_RE = /^https:\/\/[a-z0-9]+\.api\.r(\d+)\.sanity\.(.*)/, domainSharder = getDomainSharder();
877
- function getDomainSharder(initialBuckets) {
878
- const buckets = new Array(3).fill(0, 0);
879
- function incrementBucketForUrl(url) {
880
- const shard = getShardFromUrl(url);
881
- shard !== null && buckets[shard]++;
882
- }
883
- function decrementBucketForUrl(url) {
884
- const shard = getShardFromUrl(url);
885
- shard !== null && buckets[shard]--;
886
- }
887
- function getShardedUrl(url) {
888
- const [isMatch, projectId2, rest] = url.match(UNSHARDED_URL_RE) || [];
889
- if (!isMatch)
890
- return url;
891
- const bucket = buckets.reduce(
892
- (smallest, count, index) => count < buckets[smallest] ? index : smallest,
893
- 0
894
- );
895
- return `https://${projectId2}.api.r${bucket + 1}.${rest}`;
896
- }
897
- function getShardFromUrl(url) {
898
- const [isMatch, shard] = url.match(SHARDED_URL_RE) || [];
899
- return isMatch ? parseInt(shard, 10) - 1 : null;
900
- }
901
- return {
902
- middleware: {
903
- processOptions: (options) => {
904
- if (!useDomainSharding(options))
905
- return options;
906
- const url = getShardedUrl(options.url);
907
- return options.url = url, options;
908
- },
909
- onRequest(req) {
910
- return useDomainSharding(req.options) && incrementBucketForUrl(req.options.url), req;
911
- },
912
- onResponse(res, context) {
913
- return useDomainSharding(context.options) && decrementBucketForUrl(context.options.url), res;
914
- }
915
- },
916
- incrementBucketForUrl,
917
- decrementBucketForUrl,
918
- getShardedUrl,
919
- getBuckets: () => buckets
920
- };
921
- }
922
- function useDomainSharding(options) {
923
- return "useDomainSharding" in options && options.useDomainSharding === !0;
924
- }
925
875
  var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
926
876
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), MAX_URL_LENGTH = 14800, possibleOptions = [
927
877
  "includePreviousRevision",
@@ -933,16 +883,15 @@ const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop]
933
883
  includeResult: !0
934
884
  };
935
885
  function _listen(query, params, opts = {}) {
936
- const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } });
937
- let uri = `${url}${_getDataUrl(this, "listen", qs)}`;
938
- if (this.config().useDomainSharding && (uri = domainSharder.getShardedUrl(uri)), uri.length > MAX_URL_LENGTH)
886
+ const { url, token, withCredentials, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = { ...defaults(opts, defaultOptions), tag }, listenOpts = pick(options, possibleOptions), qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } }), uri = `${url}${_getDataUrl(this, "listen", qs)}`;
887
+ if (uri.length > MAX_URL_LENGTH)
939
888
  return new rxjs.Observable((observer) => observer.error(new Error("Query too large for listener")));
940
889
  const listenFor = options.events ? options.events : ["mutation"], shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1, esOptions = {};
941
890
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
942
891
  Authorization: `Bearer ${token}`
943
892
  }), new rxjs.Observable((observer) => {
944
893
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
945
- domainSharder.incrementBucketForUrl(uri), open();
894
+ open();
946
895
  function onError() {
947
896
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
948
897
  }
@@ -977,7 +926,7 @@ function _listen(query, params, opts = {}) {
977
926
  });
978
927
  }
979
928
  function stop() {
980
- stopped = !0, unsubscribe(), unsubscribed = !0, domainSharder.decrementBucketForUrl(uri);
929
+ stopped = !0, unsubscribe(), unsubscribed = !0;
981
930
  }
982
931
  return stop;
983
932
  });
@@ -1598,7 +1547,7 @@ function defineDeprecatedCreateClient(createClient2) {
1598
1547
  return printNoDefaultExport(), createClient2(config);
1599
1548
  };
1600
1549
  }
1601
- var envMiddleware = [domainSharder.middleware];
1550
+ var envMiddleware = [];
1602
1551
  const exp = defineCreateClientExports(envMiddleware, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
1603
1552
  Object.defineProperty(exports, "unstable__adapter", {
1604
1553
  enumerable: !0,