@sanity/client
Advanced tools
Comparing version 6.20.2-beta.1 to 6.20.2-beta.2
{ | ||
"name": "@sanity/client", | ||
"version": "6.20.2-beta.1", | ||
"version": "6.20.2-beta.2", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import type {Middleware, RequestOptions} from 'get-it' | ||
const DEFAULT_NUM_SHARD_BUCKETS = 3 | ||
const UNSHARDED_URL_RE = /^https:\/\/([a-z0-9]+)\.api\.(sanity\..*)/ | ||
const SHARDED_URL_RE = /^https:\/\/[a-z0-9]+\.api\.s(\d+)\.sanity\.(.*)/ | ||
const SHARDED_URL_RE = /^https:\/\/[a-z0-9]+\.api\.r(\d+)\.sanity\.(.*)/ | ||
@@ -17,3 +18,3 @@ /** | ||
export function getDomainSharder(initialBuckets?: number[]) { | ||
const buckets: number[] = initialBuckets || new Array(10).fill(0, 0) | ||
const buckets: number[] = initialBuckets || new Array(DEFAULT_NUM_SHARD_BUCKETS).fill(0, 0) | ||
@@ -46,3 +47,4 @@ function incrementBucketForUrl(url: string) { | ||
return `https://${projectId}.api.s${bucket}.${rest}` | ||
// We start buckets at 1, not zero - so add 1 to the bucket index | ||
return `https://${projectId}.api.r${bucket + 1}.${rest}` | ||
} | ||
@@ -52,3 +54,6 @@ | ||
const [isMatch, shard] = url.match(SHARDED_URL_RE) || [] | ||
return isMatch ? parseInt(shard, 10) : null | ||
// We start buckets at 1, not zero, but buckets are zero-indexed. | ||
// Substract one from the shard number in the URL to get the correct bucket index | ||
return isMatch ? parseInt(shard, 10) - 1 : null | ||
} | ||
@@ -55,0 +60,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2282124
25723