@algolia/transporter
Advanced tools
Comparing version 4.0.0-beta.4 to 4.0.0-beta.5
@@ -5,7 +5,9 @@ 'use strict'; | ||
function createHost(url, accept) { | ||
const ttl = 300 * 1000; | ||
// If an host is down, it will remain down for 5 mins. | ||
const DOWNTIME = 5 * 60 * 1000; | ||
function createHost(options) { | ||
const host = { | ||
url, | ||
accept, | ||
protocol: options.protocol || 'https', | ||
url: options.url, | ||
accept: options.accept, | ||
downDate: 0, | ||
@@ -20,3 +22,3 @@ up: true, | ||
isUp() { | ||
if (!host.up && Date.now() - host.downDate > ttl) { | ||
if (!host.up && Date.now() - host.downDate > DOWNTIME) { | ||
// eslint-disable-next-line functional/immutable-data | ||
@@ -83,2 +85,3 @@ host.up = true; | ||
} | ||
const timeoutAdjuster = timeoutRetries + 1; | ||
const payload = { | ||
@@ -93,3 +96,4 @@ data, | ||
}), | ||
timeout: (timeoutRetries + 1) * (requestOptions.timeout ? requestOptions.timeout : 0), | ||
connectTimeout: timeoutAdjuster * transporter.timeouts.connect, | ||
socketTimeout: timeoutAdjuster * (requestOptions.timeout || 0), | ||
}; | ||
@@ -152,3 +156,3 @@ const decisions = { | ||
// eslint-disable-next-line functional/immutable-data | ||
transporter.hosts = values.map(host => createHost(host.url, host.accept)); | ||
transporter.hosts = values.map(hostOptions => createHost(hostOptions)); | ||
}, | ||
@@ -266,3 +270,3 @@ read(request, requestOptions) { | ||
// eslint-disable-next-line functional/no-let | ||
let url = `https://${host.url}/${path}`; | ||
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`; | ||
if (queryParametersAsString.length) { | ||
@@ -269,0 +273,0 @@ url += `?${queryParametersAsString}`; |
@@ -22,3 +22,3 @@ import { Cache } from '@algolia/cache-common'; | ||
export declare function createHost(url: string, accept: CallType): Host; | ||
export declare function createHost(options: HostOptions): Host; | ||
@@ -46,2 +46,3 @@ export declare function createRetryError(stackTrace: readonly StackFrame[]): RetryError; | ||
up: boolean; | ||
readonly protocol: string; | ||
readonly url: string; | ||
@@ -53,2 +54,8 @@ readonly accept: CallType; | ||
export declare type HostOptions = { | ||
readonly url: string; | ||
readonly accept: CallType; | ||
readonly protocol?: string; | ||
}; | ||
export declare type MappedRequestOptions = { | ||
@@ -131,2 +138,3 @@ readonly cacheable: boolean | undefined; | ||
export declare type Timeouts = { | ||
readonly connect: number; | ||
readonly read: number; | ||
@@ -152,6 +160,3 @@ readonly write: number; | ||
readonly addQueryParameters: (queryParameters: QueryParameters) => void; | ||
readonly setHosts: (values: ReadonlyArray<{ | ||
readonly url: string; | ||
readonly accept: CallType; | ||
}>) => void; | ||
readonly setHosts: (values: readonly HostOptions[]) => void; | ||
readonly read: <TResponse>(request: Request, requestOptions?: RequestOptions) => Readonly<Promise<TResponse>>; | ||
@@ -158,0 +163,0 @@ readonly write: <TResponse>(request: Request, requestOptions?: RequestOptions) => Readonly<Promise<TResponse>>; |
@@ -1,6 +0,8 @@ | ||
function createHost(url, accept) { | ||
const ttl = 300 * 1000; | ||
// If an host is down, it will remain down for 5 mins. | ||
const DOWNTIME = 5 * 60 * 1000; | ||
function createHost(options) { | ||
const host = { | ||
url, | ||
accept, | ||
protocol: options.protocol || 'https', | ||
url: options.url, | ||
accept: options.accept, | ||
downDate: 0, | ||
@@ -15,3 +17,3 @@ up: true, | ||
isUp() { | ||
if (!host.up && Date.now() - host.downDate > ttl) { | ||
if (!host.up && Date.now() - host.downDate > DOWNTIME) { | ||
// eslint-disable-next-line functional/immutable-data | ||
@@ -78,2 +80,3 @@ host.up = true; | ||
} | ||
const timeoutAdjuster = timeoutRetries + 1; | ||
const payload = { | ||
@@ -88,3 +91,4 @@ data, | ||
}), | ||
timeout: (timeoutRetries + 1) * (requestOptions.timeout ? requestOptions.timeout : 0), | ||
connectTimeout: timeoutAdjuster * transporter.timeouts.connect, | ||
socketTimeout: timeoutAdjuster * (requestOptions.timeout || 0), | ||
}; | ||
@@ -147,3 +151,3 @@ const decisions = { | ||
// eslint-disable-next-line functional/immutable-data | ||
transporter.hosts = values.map(host => createHost(host.url, host.accept)); | ||
transporter.hosts = values.map(hostOptions => createHost(hostOptions)); | ||
}, | ||
@@ -261,3 +265,3 @@ read(request, requestOptions) { | ||
// eslint-disable-next-line functional/no-let | ||
let url = `https://${host.url}/${path}`; | ||
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`; | ||
if (queryParametersAsString.length) { | ||
@@ -264,0 +268,0 @@ url += `?${queryParametersAsString}`; |
{ | ||
"name": "@algolia/transporter", | ||
"version": "4.0.0-beta.4", | ||
"version": "4.0.0-beta.5", | ||
"private": false, | ||
@@ -11,2 +11,3 @@ "description": "Promise-based transporter layer with embedded retry strategy.", | ||
], | ||
"sideEffects": false, | ||
"main": "index.js", | ||
@@ -16,6 +17,6 @@ "module": "dist/transporter.esm.js", | ||
"dependencies": { | ||
"@algolia/cache-common": "4.0.0-beta.4", | ||
"@algolia/logger-common": "4.0.0-beta.4", | ||
"@algolia/requester-common": "4.0.0-beta.4" | ||
"@algolia/cache-common": "4.0.0-beta.5", | ||
"@algolia/logger-common": "4.0.0-beta.5", | ||
"@algolia/requester-common": "4.0.0-beta.5" | ||
} | ||
} |
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
29804
753
+ Added@algolia/cache-common@4.0.0-beta.5(transitive)
+ Added@algolia/logger-common@4.0.0-beta.5(transitive)
+ Added@algolia/requester-common@4.0.0-beta.5(transitive)
- Removed@algolia/cache-common@4.0.0-beta.4(transitive)
- Removed@algolia/logger-common@4.0.0-beta.4(transitive)
- Removed@algolia/requester-common@4.0.0-beta.4(transitive)