@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.
- package/dist/index.browser.cjs +5 -56
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +0 -7
- package/dist/index.browser.d.ts +0 -7
- package/dist/index.browser.js +5 -56
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +5 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +5 -57
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/listen.ts +1 -13
- package/src/http/browserMiddleware.ts +1 -3
- package/src/http/nodeMiddleware.ts +0 -3
- package/src/http/requestOptions.ts +0 -1
- package/src/types.ts +0 -8
- package/umd/sanityClient.js +5 -56
- package/umd/sanityClient.min.js +3 -3
- package/src/http/domainSharding.ts +0 -101
package/dist/index.browser.d.cts
CHANGED
|
@@ -336,13 +336,6 @@ export declare interface ClientConfig {
|
|
|
336
336
|
apiHost?: string
|
|
337
337
|
apiVersion?: string
|
|
338
338
|
proxy?: string
|
|
339
|
-
/**
|
|
340
|
-
* Spread the requests over a number of hostnames to work around HTTP/1.1 limitations.
|
|
341
|
-
* Only applicable in browsers, and for certain allowed projects.
|
|
342
|
-
*
|
|
343
|
-
* @alpha
|
|
344
|
-
*/
|
|
345
|
-
useDomainSharding?: boolean
|
|
346
339
|
/**
|
|
347
340
|
* Optional request tag prefix for all request tags
|
|
348
341
|
*/
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -336,13 +336,6 @@ export declare interface ClientConfig {
|
|
|
336
336
|
apiHost?: string
|
|
337
337
|
apiVersion?: string
|
|
338
338
|
proxy?: string
|
|
339
|
-
/**
|
|
340
|
-
* Spread the requests over a number of hostnames to work around HTTP/1.1 limitations.
|
|
341
|
-
* Only applicable in browsers, and for certain allowed projects.
|
|
342
|
-
*
|
|
343
|
-
* @alpha
|
|
344
|
-
*/
|
|
345
|
-
useDomainSharding?: boolean
|
|
346
339
|
/**
|
|
347
340
|
* Optional request tag prefix for all request tags
|
|
348
341
|
*/
|
package/dist/index.browser.js
CHANGED
|
@@ -586,7 +586,6 @@ function requestOptions(config, overrides = {}) {
|
|
|
586
586
|
proxy: overrides.proxy || config.proxy,
|
|
587
587
|
json: !0,
|
|
588
588
|
withCredentials,
|
|
589
|
-
useDomainSharding: config.useDomainSharding,
|
|
590
589
|
fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
591
590
|
});
|
|
592
591
|
}
|
|
@@ -856,55 +855,6 @@ function optionsFromFile(opts, file) {
|
|
|
856
855
|
opts
|
|
857
856
|
);
|
|
858
857
|
}
|
|
859
|
-
const UNSHARDED_URL_RE = /^https:\/\/([a-z0-9]+)\.api\.(sanity\..*)/, SHARDED_URL_RE = /^https:\/\/[a-z0-9]+\.api\.r(\d+)\.sanity\.(.*)/, domainSharder = getDomainSharder();
|
|
860
|
-
function getDomainSharder(initialBuckets) {
|
|
861
|
-
const buckets = new Array(3).fill(0, 0);
|
|
862
|
-
function incrementBucketForUrl(url) {
|
|
863
|
-
const shard = getShardFromUrl(url);
|
|
864
|
-
shard !== null && buckets[shard]++;
|
|
865
|
-
}
|
|
866
|
-
function decrementBucketForUrl(url) {
|
|
867
|
-
const shard = getShardFromUrl(url);
|
|
868
|
-
shard !== null && buckets[shard]--;
|
|
869
|
-
}
|
|
870
|
-
function getShardedUrl(url) {
|
|
871
|
-
const [isMatch, projectId2, rest] = url.match(UNSHARDED_URL_RE) || [];
|
|
872
|
-
if (!isMatch)
|
|
873
|
-
return url;
|
|
874
|
-
const bucket = buckets.reduce(
|
|
875
|
-
(smallest, count, index) => count < buckets[smallest] ? index : smallest,
|
|
876
|
-
0
|
|
877
|
-
);
|
|
878
|
-
return `https://${projectId2}.api.r${bucket + 1}.${rest}`;
|
|
879
|
-
}
|
|
880
|
-
function getShardFromUrl(url) {
|
|
881
|
-
const [isMatch, shard] = url.match(SHARDED_URL_RE) || [];
|
|
882
|
-
return isMatch ? parseInt(shard, 10) - 1 : null;
|
|
883
|
-
}
|
|
884
|
-
return {
|
|
885
|
-
middleware: {
|
|
886
|
-
processOptions: (options) => {
|
|
887
|
-
if (!useDomainSharding(options))
|
|
888
|
-
return options;
|
|
889
|
-
const url = getShardedUrl(options.url);
|
|
890
|
-
return options.url = url, options;
|
|
891
|
-
},
|
|
892
|
-
onRequest(req) {
|
|
893
|
-
return useDomainSharding(req.options) && incrementBucketForUrl(req.options.url), req;
|
|
894
|
-
},
|
|
895
|
-
onResponse(res, context) {
|
|
896
|
-
return useDomainSharding(context.options) && decrementBucketForUrl(context.options.url), res;
|
|
897
|
-
}
|
|
898
|
-
},
|
|
899
|
-
incrementBucketForUrl,
|
|
900
|
-
decrementBucketForUrl,
|
|
901
|
-
getShardedUrl,
|
|
902
|
-
getBuckets: () => buckets
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
function useDomainSharding(options) {
|
|
906
|
-
return "useDomainSharding" in options && options.useDomainSharding === !0;
|
|
907
|
-
}
|
|
908
858
|
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), {});
|
|
909
859
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
910
860
|
"includePreviousRevision",
|
|
@@ -916,16 +866,15 @@ const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop]
|
|
|
916
866
|
includeResult: !0
|
|
917
867
|
};
|
|
918
868
|
function _listen(query, params, opts = {}) {
|
|
919
|
-
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 } })
|
|
920
|
-
|
|
921
|
-
if (this.config().useDomainSharding && (uri = domainSharder.getShardedUrl(uri)), uri.length > MAX_URL_LENGTH)
|
|
869
|
+
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)}`;
|
|
870
|
+
if (uri.length > MAX_URL_LENGTH)
|
|
922
871
|
return new Observable((observer) => observer.error(new Error("Query too large for listener")));
|
|
923
872
|
const listenFor = options.events ? options.events : ["mutation"], shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1, esOptions = {};
|
|
924
873
|
return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
925
874
|
Authorization: `Bearer ${token}`
|
|
926
875
|
}), new Observable((observer) => {
|
|
927
876
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
928
|
-
|
|
877
|
+
open();
|
|
929
878
|
function onError() {
|
|
930
879
|
stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
|
|
931
880
|
}
|
|
@@ -960,7 +909,7 @@ function _listen(query, params, opts = {}) {
|
|
|
960
909
|
});
|
|
961
910
|
}
|
|
962
911
|
function stop() {
|
|
963
|
-
stopped = !0, unsubscribe(), unsubscribed = !0
|
|
912
|
+
stopped = !0, unsubscribe(), unsubscribed = !0;
|
|
964
913
|
}
|
|
965
914
|
return stop;
|
|
966
915
|
});
|
|
@@ -1581,7 +1530,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1581
1530
|
return printNoDefaultExport(), createClient2(config);
|
|
1582
1531
|
};
|
|
1583
1532
|
}
|
|
1584
|
-
var envMiddleware = [
|
|
1533
|
+
var envMiddleware = [];
|
|
1585
1534
|
const exp = defineCreateClientExports(envMiddleware, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
|
|
1586
1535
|
export {
|
|
1587
1536
|
BasePatch,
|