Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/client-common

Package Overview
Dependencies
Maintainers
3
Versions
237
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/client-common - npm Package Compare versions

Comparing version 5.0.0-alpha.3 to 5.0.0-alpha.4

dist/src/createIterablePromise.d.ts

60

dist/client-common.cjs.js

@@ -76,39 +76,39 @@ 'use strict';

const DEFAULT_MAX_RETRIES = 50;
const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
/**
* Return a promise that retry a task until it meets the condition.
* Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
*
* @param createRetryablePromiseOptions - The createRetryablePromise options.
* @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
* @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
* @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
* @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
* @param createIterator - The createIterator options.
* @param createIterator.func - The function to run, which returns a promise.
* @param createIterator.validate - The validator function. It receives the resolved return of `func`.
* @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.
* @param createIterator.error - The `validate` condition to throw an error, and its message.
* @param createIterator.timeout - The function to decide how long to wait between iterations.
*/
function createRetryablePromise({
function createIterablePromise({
func,
validate,
maxRetries = DEFAULT_MAX_RETRIES,
timeout = DEFAULT_TIMEOUT
aggregator,
error,
timeout = () => 0
}) {
let retryCount = 0;
const retry = () => {
const retry = previousResponse => {
return new Promise((resolve, reject) => {
func().then(response => {
const isValid = validate(response);
func(previousResponse).then(response => {
if (aggregator) {
aggregator(response);
}
if (isValid) {
resolve(response);
} else if (retryCount + 1 >= maxRetries) {
reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
} else {
retryCount += 1;
setTimeout(() => {
retry().then(resolve).catch(reject);
}, timeout(retryCount));
if (validate(response)) {
return resolve(response);
}
}).catch(error => {
reject(error);
if (error && error.validate(response)) {
return reject(new Error(error.message(response)));
}
return setTimeout(() => {
retry(response).then(resolve).catch(reject);
}, timeout());
}).catch(err => {
reject(err);
});

@@ -783,6 +783,4 @@ });

exports.DEFAULT_CONNECT_TIMEOUT_NODE = DEFAULT_CONNECT_TIMEOUT_NODE;
exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
exports.DEFAULT_READ_TIMEOUT_BROWSER = DEFAULT_READ_TIMEOUT_BROWSER;
exports.DEFAULT_READ_TIMEOUT_NODE = DEFAULT_READ_TIMEOUT_NODE;
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
exports.DEFAULT_WRITE_TIMEOUT_BROWSER = DEFAULT_WRITE_TIMEOUT_BROWSER;

@@ -798,5 +796,5 @@ exports.DEFAULT_WRITE_TIMEOUT_NODE = DEFAULT_WRITE_TIMEOUT_NODE;

exports.createFallbackableCache = createFallbackableCache;
exports.createIterablePromise = createIterablePromise;
exports.createMemoryCache = createMemoryCache;
exports.createNullCache = createNullCache;
exports.createRetryablePromise = createRetryablePromise;
exports.createStatefulHost = createStatefulHost;

@@ -803,0 +801,0 @@ exports.createTransporter = createTransporter;

@@ -72,39 +72,39 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {

const DEFAULT_MAX_RETRIES = 50;
const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
/**
* Return a promise that retry a task until it meets the condition.
* Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
*
* @param createRetryablePromiseOptions - The createRetryablePromise options.
* @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
* @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
* @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
* @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
* @param createIterator - The createIterator options.
* @param createIterator.func - The function to run, which returns a promise.
* @param createIterator.validate - The validator function. It receives the resolved return of `func`.
* @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.
* @param createIterator.error - The `validate` condition to throw an error, and its message.
* @param createIterator.timeout - The function to decide how long to wait between iterations.
*/
function createRetryablePromise({
function createIterablePromise({
func,
validate,
maxRetries = DEFAULT_MAX_RETRIES,
timeout = DEFAULT_TIMEOUT
aggregator,
error,
timeout = () => 0
}) {
let retryCount = 0;
const retry = () => {
const retry = previousResponse => {
return new Promise((resolve, reject) => {
func().then(response => {
const isValid = validate(response);
func(previousResponse).then(response => {
if (aggregator) {
aggregator(response);
}
if (isValid) {
resolve(response);
} else if (retryCount + 1 >= maxRetries) {
reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
} else {
retryCount += 1;
setTimeout(() => {
retry().then(resolve).catch(reject);
}, timeout(retryCount));
if (validate(response)) {
return resolve(response);
}
}).catch(error => {
reject(error);
if (error && error.validate(response)) {
return reject(new Error(error.message(response)));
}
return setTimeout(() => {
retry(response).then(resolve).catch(reject);
}, timeout());
}).catch(err => {
reject(err);
});

@@ -775,2 +775,2 @@ });

export { AlgoliaError, ApiError, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_MAX_RETRIES, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_TIMEOUT, DEFAULT_WRITE_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_NODE, DeserializationError, ErrorWithStackTrace, RetryError, createAlgoliaAgent, createAuth, createBrowserLocalStorageCache, createEchoRequester, createFallbackableCache, createMemoryCache, createNullCache, createRetryablePromise, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
export { AlgoliaError, ApiError, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_NODE, DeserializationError, ErrorWithStackTrace, RetryError, createAlgoliaAgent, createAuth, createBrowserLocalStorageCache, createEchoRequester, createFallbackableCache, createIterablePromise, createMemoryCache, createNullCache, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
export * from './src/createAuth';
export * from './src/createEchoRequester';
export * from './src/createRetryablePromise';
export * from './src/createIterablePromise';
export * from './src/cache';

@@ -5,0 +5,0 @@ export * from './src/transporter';

@@ -1,7 +0,7 @@

export * from './Cache';
export * from './CreateClient';
export * from './CreateRetryablePromise';
export * from './Host';
export * from './Requester';
export * from './Transporter';
export * from './cache';
export * from './createClient';
export * from './createIterablePromise';
export * from './host';
export * from './requester';
export * from './transporter';
//# sourceMappingURL=index.d.ts.map
export * from './src/createAuth';
export * from './src/createEchoRequester';
export * from './src/createRetryablePromise';
export * from './src/createIterablePromise';
export * from './src/cache';

@@ -5,0 +5,0 @@ export * from './src/transporter';

{
"name": "@algolia/client-common",
"version": "5.0.0-alpha.3",
"version": "5.0.0-alpha.4",
"description": "Common package for the Algolia JavaScript API client.",

@@ -22,3 +22,3 @@ "repository": "algolia/algoliasearch-client-javascript",

"@types/jest": "28.1.6",
"@types/node": "16.11.45",
"@types/node": "16.11.47",
"jest": "28.1.3",

@@ -25,0 +25,0 @@ "jest-environment-jsdom": "28.1.3",

@@ -1,6 +0,6 @@

export * from './Cache';
export * from './CreateClient';
export * from './CreateRetryablePromise';
export * from './Host';
export * from './Requester';
export * from './Transporter';
export * from './cache';
export * from './createClient';
export * from './createIterablePromise';
export * from './host';
export * from './requester';
export * from './transporter';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc