@algolia/client-common 5.0.0-alpha.1 → 5.0.0-alpha.10

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.
Files changed (61) hide show
  1. package/dist/client-common.cjs.js +34 -34
  2. package/dist/client-common.esm.node.js +34 -32
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/src/cache/createBrowserLocalStorageCache.d.ts.map +1 -1
  6. package/dist/src/cache/createFallbackableCache.d.ts.map +1 -1
  7. package/dist/src/cache/createMemoryCache.d.ts.map +1 -1
  8. package/dist/src/cache/createNullCache.d.ts.map +1 -1
  9. package/dist/src/cache/index.d.ts.map +1 -1
  10. package/dist/src/constants.d.ts.map +1 -1
  11. package/dist/src/createAlgoliaAgent.d.ts.map +1 -1
  12. package/dist/src/createAuth.d.ts.map +1 -1
  13. package/dist/src/createEchoRequester.d.ts.map +1 -1
  14. package/dist/src/createIterablePromise.d.ts +13 -0
  15. package/dist/src/createIterablePromise.d.ts.map +1 -0
  16. package/dist/src/getAlgoliaAgent.d.ts.map +1 -1
  17. package/dist/src/transporter/createStatefulHost.d.ts.map +1 -1
  18. package/dist/src/transporter/createTransporter.d.ts.map +1 -1
  19. package/dist/src/transporter/errors.d.ts.map +1 -1
  20. package/dist/src/transporter/helpers.d.ts.map +1 -1
  21. package/dist/src/transporter/index.d.ts.map +1 -1
  22. package/dist/src/transporter/responses.d.ts.map +1 -1
  23. package/dist/src/transporter/stackTrace.d.ts.map +1 -1
  24. package/dist/src/types/{Cache.d.ts → cache.d.ts} +1 -1
  25. package/dist/src/types/cache.d.ts.map +1 -0
  26. package/dist/src/types/{CreateClient.d.ts → createClient.d.ts} +3 -3
  27. package/dist/src/types/createClient.d.ts.map +1 -0
  28. package/dist/src/types/createIterablePromise.d.ts +36 -0
  29. package/dist/src/types/createIterablePromise.d.ts.map +1 -0
  30. package/dist/src/types/{Host.d.ts → host.d.ts} +1 -1
  31. package/dist/src/types/host.d.ts.map +1 -0
  32. package/dist/src/types/index.d.ts +6 -6
  33. package/dist/src/types/index.d.ts.map +1 -1
  34. package/dist/src/types/{Requester.d.ts → requester.d.ts} +2 -2
  35. package/dist/src/types/requester.d.ts.map +1 -0
  36. package/dist/src/types/{Transporter.d.ts → transporter.d.ts} +4 -4
  37. package/dist/src/types/transporter.d.ts.map +1 -0
  38. package/index.ts +1 -1
  39. package/package.json +4 -3
  40. package/src/__tests__/create-iterable-promise.test.ts +238 -0
  41. package/src/createIterablePromise.ts +47 -0
  42. package/src/transporter/createTransporter.ts +4 -1
  43. package/src/types/{Cache.ts → cache.ts} +0 -0
  44. package/src/types/{CreateClient.ts → createClient.ts} +2 -2
  45. package/src/types/createIterablePromise.ts +40 -0
  46. package/src/types/{Host.ts → host.ts} +0 -0
  47. package/src/types/index.ts +6 -6
  48. package/src/types/{Requester.ts → requester.ts} +1 -1
  49. package/src/types/{Transporter.ts → transporter.ts} +3 -3
  50. package/dist/src/createRetryablePromise.d.ts +0 -14
  51. package/dist/src/createRetryablePromise.d.ts.map +0 -1
  52. package/dist/src/types/Cache.d.ts.map +0 -1
  53. package/dist/src/types/CreateClient.d.ts.map +0 -1
  54. package/dist/src/types/CreateRetryablePromise.d.ts +0 -19
  55. package/dist/src/types/CreateRetryablePromise.d.ts.map +0 -1
  56. package/dist/src/types/Host.d.ts.map +0 -1
  57. package/dist/src/types/Requester.d.ts.map +0 -1
  58. package/dist/src/types/Transporter.d.ts.map +0 -1
  59. package/src/__tests__/create-retryable-promise.test.ts +0 -86
  60. package/src/createRetryablePromise.ts +0 -52
  61. package/src/types/CreateRetryablePromise.ts +0 -21
@@ -73,43 +73,43 @@ function createEchoRequester({
73
73
  };
74
74
  }
75
75
 
76
- const DEFAULT_MAX_RETRIES = 50;
77
- const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
78
76
  /**
79
- * Return a promise that retry a task until it meets the condition.
77
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
80
78
  *
81
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
82
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
83
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
84
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
85
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
79
+ * @param createIterator - The createIterator options.
80
+ * @param createIterator.func - The function to run, which returns a promise.
81
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
82
+ * @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`.
83
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
84
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
86
85
  */
87
-
88
- function createRetryablePromise({
86
+ function createIterablePromise({
89
87
  func,
90
88
  validate,
91
- maxRetries = DEFAULT_MAX_RETRIES,
92
- timeout = DEFAULT_TIMEOUT
89
+ aggregator,
90
+ error,
91
+ timeout = () => 0
93
92
  }) {
94
- let retryCount = 0;
95
-
96
- const retry = () => {
93
+ const retry = previousResponse => {
97
94
  return new Promise((resolve, reject) => {
98
- func().then(response => {
99
- const isValid = validate(response);
95
+ func(previousResponse).then(response => {
96
+ if (aggregator) {
97
+ aggregator(response);
98
+ }
100
99
 
101
- if (isValid) {
102
- resolve(response);
103
- } else if (retryCount + 1 >= maxRetries) {
104
- reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
105
- } else {
106
- retryCount += 1;
107
- setTimeout(() => {
108
- retry().then(resolve).catch(reject);
109
- }, timeout(retryCount));
100
+ if (validate(response)) {
101
+ return resolve(response);
110
102
  }
111
- }).catch(error => {
112
- reject(error);
103
+
104
+ if (error && error.validate(response)) {
105
+ return reject(new Error(error.message(response)));
106
+ }
107
+
108
+ return setTimeout(() => {
109
+ retry(response).then(resolve).catch(reject);
110
+ }, timeout());
111
+ }).catch(err => {
112
+ reject(err);
113
113
  });
114
114
  });
115
115
  };
@@ -530,13 +530,15 @@ function createTransporter({
530
530
  const dataQueryParameters = request.method === 'GET' ? { ...request.data,
531
531
  ...requestOptions.data
532
532
  } : {};
533
- const queryParameters = {
534
- 'x-algolia-agent': algoliaAgent.value,
535
- ...baseQueryParameters,
533
+ const queryParameters = { ...baseQueryParameters,
536
534
  ...request.queryParameters,
537
535
  ...dataQueryParameters
538
536
  };
539
537
 
538
+ if (algoliaAgent.value) {
539
+ queryParameters['x-algolia-agent'] = algoliaAgent.value;
540
+ }
541
+
540
542
  if (requestOptions && requestOptions.queryParameters) {
541
543
  for (const key of Object.keys(requestOptions.queryParameters)) {
542
544
  // We want to keep `undefined` and `null` values,
@@ -779,10 +781,8 @@ exports.AlgoliaError = AlgoliaError;
779
781
  exports.ApiError = ApiError;
780
782
  exports.DEFAULT_CONNECT_TIMEOUT_BROWSER = DEFAULT_CONNECT_TIMEOUT_BROWSER;
781
783
  exports.DEFAULT_CONNECT_TIMEOUT_NODE = DEFAULT_CONNECT_TIMEOUT_NODE;
782
- exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
783
784
  exports.DEFAULT_READ_TIMEOUT_BROWSER = DEFAULT_READ_TIMEOUT_BROWSER;
784
785
  exports.DEFAULT_READ_TIMEOUT_NODE = DEFAULT_READ_TIMEOUT_NODE;
785
- exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
786
786
  exports.DEFAULT_WRITE_TIMEOUT_BROWSER = DEFAULT_WRITE_TIMEOUT_BROWSER;
787
787
  exports.DEFAULT_WRITE_TIMEOUT_NODE = DEFAULT_WRITE_TIMEOUT_NODE;
788
788
  exports.DeserializationError = DeserializationError;
@@ -793,9 +793,9 @@ exports.createAuth = createAuth;
793
793
  exports.createBrowserLocalStorageCache = createBrowserLocalStorageCache;
794
794
  exports.createEchoRequester = createEchoRequester;
795
795
  exports.createFallbackableCache = createFallbackableCache;
796
+ exports.createIterablePromise = createIterablePromise;
796
797
  exports.createMemoryCache = createMemoryCache;
797
798
  exports.createNullCache = createNullCache;
798
- exports.createRetryablePromise = createRetryablePromise;
799
799
  exports.createStatefulHost = createStatefulHost;
800
800
  exports.createTransporter = createTransporter;
801
801
  exports.deserializeFailure = deserializeFailure;
@@ -69,43 +69,43 @@ function createEchoRequester({
69
69
  };
70
70
  }
71
71
 
72
- const DEFAULT_MAX_RETRIES = 50;
73
- const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
74
72
  /**
75
- * Return a promise that retry a task until it meets the condition.
73
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
76
74
  *
77
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
78
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
79
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
80
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
81
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
75
+ * @param createIterator - The createIterator options.
76
+ * @param createIterator.func - The function to run, which returns a promise.
77
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
78
+ * @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`.
79
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
80
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
82
81
  */
83
-
84
- function createRetryablePromise({
82
+ function createIterablePromise({
85
83
  func,
86
84
  validate,
87
- maxRetries = DEFAULT_MAX_RETRIES,
88
- timeout = DEFAULT_TIMEOUT
85
+ aggregator,
86
+ error,
87
+ timeout = () => 0
89
88
  }) {
90
- let retryCount = 0;
91
-
92
- const retry = () => {
89
+ const retry = previousResponse => {
93
90
  return new Promise((resolve, reject) => {
94
- func().then(response => {
95
- const isValid = validate(response);
91
+ func(previousResponse).then(response => {
92
+ if (aggregator) {
93
+ aggregator(response);
94
+ }
96
95
 
97
- if (isValid) {
98
- resolve(response);
99
- } else if (retryCount + 1 >= maxRetries) {
100
- reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
101
- } else {
102
- retryCount += 1;
103
- setTimeout(() => {
104
- retry().then(resolve).catch(reject);
105
- }, timeout(retryCount));
96
+ if (validate(response)) {
97
+ return resolve(response);
106
98
  }
107
- }).catch(error => {
108
- reject(error);
99
+
100
+ if (error && error.validate(response)) {
101
+ return reject(new Error(error.message(response)));
102
+ }
103
+
104
+ return setTimeout(() => {
105
+ retry(response).then(resolve).catch(reject);
106
+ }, timeout());
107
+ }).catch(err => {
108
+ reject(err);
109
109
  });
110
110
  });
111
111
  };
@@ -526,13 +526,15 @@ function createTransporter({
526
526
  const dataQueryParameters = request.method === 'GET' ? { ...request.data,
527
527
  ...requestOptions.data
528
528
  } : {};
529
- const queryParameters = {
530
- 'x-algolia-agent': algoliaAgent.value,
531
- ...baseQueryParameters,
529
+ const queryParameters = { ...baseQueryParameters,
532
530
  ...request.queryParameters,
533
531
  ...dataQueryParameters
534
532
  };
535
533
 
534
+ if (algoliaAgent.value) {
535
+ queryParameters['x-algolia-agent'] = algoliaAgent.value;
536
+ }
537
+
536
538
  if (requestOptions && requestOptions.queryParameters) {
537
539
  for (const key of Object.keys(requestOptions.queryParameters)) {
538
540
  // We want to keep `undefined` and `null` values,
@@ -771,4 +773,4 @@ const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
771
773
  const DEFAULT_READ_TIMEOUT_NODE = 5000;
772
774
  const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
773
775
 
774
- 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 };
776
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './src/createAuth';
2
2
  export * from './src/createEchoRequester';
3
- export * from './src/createRetryablePromise';
3
+ export * from './src/createIterablePromise';
4
4
  export * from './src/cache';
5
5
  export * from './src/transporter';
6
6
  export * from './src/createAlgoliaAgent';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createBrowserLocalStorageCache.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/cache/createBrowserLocalStorageCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAE/E,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,0BAA0B,GAClC,KAAK,CAqEP"}
1
+ {"version":3,"file":"createBrowserLocalStorageCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createBrowserLocalStorageCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAE/E,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,0BAA0B,GAClC,KAAK,CAqEP"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFallbackableCache.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/cache/createFallbackableCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAI7E,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,KAAK,CA8CP"}
1
+ {"version":3,"file":"createFallbackableCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createFallbackableCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAI7E,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,KAAK,CA8CP"}
@@ -1 +1 @@
1
- {"version":3,"file":"createMemoryCache.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/cache/createMemoryCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEvE,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAA2C,GACnD,KAAK,CAmDP"}
1
+ {"version":3,"file":"createMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createMemoryCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEvE,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAA2C,GACnD,KAAK,CAmDP"}
@@ -1 +1 @@
1
- {"version":3,"file":"createNullCache.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/cache/createNullCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAEnD,wBAAgB,eAAe,IAAI,KAAK,CA+BvC"}
1
+ {"version":3,"file":"createNullCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createNullCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAEnD,wBAAgB,eAAe,IAAI,KAAK,CA+BvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,OAAO,CAAC;AACpD,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAEnD,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,0BAA0B,QAAQ,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,OAAO,CAAC;AACpD,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAEnD,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,0BAA0B,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/createAlgoliaAgent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAiBhE"}
1
+ {"version":3,"file":"createAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/createAlgoliaAgent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAiBhE"}
@@ -1 +1 @@
1
- {"version":3,"file":"createAuth.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/createAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElE,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,QAA0B,GACnC;IACD,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;IAChC,QAAQ,CAAC,eAAe,EAAE,MAAM,eAAe,CAAC;CACjD,CAeA"}
1
+ {"version":3,"file":"createAuth.d.ts","sourceRoot":"","sources":["../../src/createAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElE,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,QAA0B,GACnC;IACD,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;IAChC,QAAQ,CAAC,eAAe,EAAE,MAAM,eAAe,CAAC;CACjD,CAeA"}
@@ -1 +1 @@
1
- {"version":3,"file":"createEchoRequester.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/createEchoRequester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,SAAS,EAAY,MAAM,SAAS,CAAC;AAE7E,oBAAY,mBAAmB,GAAG;IAChC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA2BF,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,MAAY,GACb,EAAE,mBAAmB,GAAG,SAAS,CAuBjC"}
1
+ {"version":3,"file":"createEchoRequester.d.ts","sourceRoot":"","sources":["../../src/createEchoRequester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,SAAS,EAAY,MAAM,SAAS,CAAC;AAE7E,oBAAY,mBAAmB,GAAG;IAChC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA2BF,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,MAAY,GACb,EAAE,mBAAmB,GAAG,SAAS,CAuBjC"}
@@ -0,0 +1,13 @@
1
+ import type { CreateIterablePromise } from './types/createIterablePromise';
2
+ /**
3
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
4
+ *
5
+ * @param createIterator - The createIterator options.
6
+ * @param createIterator.func - The function to run, which returns a promise.
7
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
8
+ * @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`.
9
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
10
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
11
+ */
12
+ export declare function createIterablePromise<TResponse>({ func, validate, aggregator, error, timeout, }: CreateIterablePromise<TResponse>): Promise<TResponse>;
13
+ //# sourceMappingURL=createIterablePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIterablePromise.d.ts","sourceRoot":"","sources":["../../src/createIterablePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,EAC/C,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,KAAK,EACL,OAAyB,GAC1B,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CA4BvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"getAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/getAlgoliaAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,oBAAY,eAAe,GAAG;IAC5B,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,aAAa,EACb,MAAM,EACN,OAAO,GACR,EAAE,eAAe,GAAG,YAAY,CAWhC"}
1
+ {"version":3,"file":"getAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/getAlgoliaAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,oBAAY,eAAe,GAAG;IAC5B,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,aAAa,EACb,MAAM,EACN,OAAO,GACR,EAAE,eAAe,GAAG,YAAY,CAWhC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createStatefulHost.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/createStatefulHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,YAAY,CAAC,QAAQ,CAAQ,GACpC,YAAY,CAcd"}
1
+ {"version":3,"file":"createStatefulHost.d.ts","sourceRoot":"","sources":["../../../src/transporter/createStatefulHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,YAAY,CAAC,QAAQ,CAAQ,GACpC,YAAY,CAcd"}
@@ -1 +1 @@
1
- {"version":3,"file":"createTransporter.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/createTransporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAOV,kBAAkB,EAClB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAsBlB,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,EACb,cAAc,GACf,EAAE,kBAAkB,GAAG,WAAW,CAgTlC"}
1
+ {"version":3,"file":"createTransporter.d.ts","sourceRoot":"","sources":["../../../src/transporter/createTransporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAOV,kBAAkB,EAClB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAsBlB,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,EACb,cAAc,GACf,EAAE,kBAAkB,GAAG,WAAW,CAmTlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAkB;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAO1C;AAED,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,UAAU,EAAE,UAAU,EAAE,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM;CAKpE;AAED,qBAAa,UAAW,SAAQ,mBAAmB;gBACrC,UAAU,EAAE,UAAU,EAAE;CAOrC;AAED,qBAAa,QAAS,SAAQ,mBAAmB;IAC/C,MAAM,EAAE,MAAM,CAAC;gBAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE;CAItE;AAED,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,QAAQ,EAAE,QAAQ,CAAC;gBAEP,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/transporter/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAkB;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAO1C;AAED,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,UAAU,EAAE,UAAU,EAAE,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM;CAKpE;AAED,qBAAa,UAAW,SAAQ,mBAAmB;gBACrC,UAAU,EAAE,UAAU,EAAE;CAOrC;AAED,qBAAa,QAAS,SAAQ,mBAAmB;IAC/C,MAAM,EAAE,MAAM,CAAC;gBAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE;CAItE;AAED,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,QAAQ,EAAE,QAAQ,CAAC;gBAEP,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,EACX,MAAM,UAAU,CAAC;AAIlB,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,eAAe,GAC/B,MAAM,CAWR;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,CAe5E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,GAC7B,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAeT;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMvE;AAED,wBAAgB,kBAAkB,CAChC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAC7B,UAAU,EAAE,UAAU,EAAE,GACvB,KAAK,CAQP"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,EACX,MAAM,UAAU,CAAC;AAIlB,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,eAAe,GAC/B,MAAM,CAWR;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,CAe5E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,GAC7B,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAeT;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMvE;AAED,wBAAgB,kBAAkB,CAChC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAC7B,UAAU,EAAE,UAAU,EAAE,GACvB,KAAK,CAQP"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transporter/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAErC;AAED,wBAAgB,WAAW,CAAC,EAC1B,UAAU,EACV,MAAM,GACP,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAMrC;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,OAAO,CAEvE"}
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../src/transporter/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAErC;AAED,wBAAgB,WAAW,CAAC,EAC1B,UAAU,EACV,MAAM,GACP,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAMrC;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,OAAO,CAEvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/transporter/stackTrace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,EAAE,GACvB,UAAU,EAAE,CAId;AAED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,GACrB,UAAU,CAiBZ"}
1
+ {"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../../src/transporter/stackTrace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,EAAE,GACvB,UAAU,EAAE,CAId;AAED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,GACrB,UAAU,CAiBZ"}
@@ -44,4 +44,4 @@ export declare type FallbackableCacheOptions = {
44
44
  */
45
45
  caches: Cache[];
46
46
  };
47
- //# sourceMappingURL=Cache.d.ts.map
47
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/types/cache.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG;IAClB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,oBAAY,WAAW,CAAC,MAAM,IAAI;IAChC;;OAEG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,oBAAY,0BAA0B,GAAG;IACvC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AlgoliaAgentOptions, TransporterOptions } from './Transporter';
1
+ import type { AlgoliaAgentOptions, TransporterOptions } from './transporter';
2
2
  export declare type AuthMode = 'WithinHeaders' | 'WithinQueryParameters';
3
3
  declare type OverriddenTransporterOptions = 'baseHeaders' | 'baseQueryParameters' | 'hosts';
4
4
  export declare type CreateClientOptions = Omit<TransporterOptions, OverriddenTransporterOptions | 'algoliaAgent'> & Partial<Pick<TransporterOptions, OverriddenTransporterOptions>> & {
@@ -7,6 +7,6 @@ export declare type CreateClientOptions = Omit<TransporterOptions, OverriddenTra
7
7
  authMode?: AuthMode;
8
8
  algoliaAgents: AlgoliaAgentOptions[];
9
9
  };
10
- export declare type InitClientOptions = Partial<Omit<CreateClientOptions, 'apiKey' | 'appId'>>;
10
+ export declare type ClientOptions = Partial<Omit<CreateClientOptions, 'apiKey' | 'appId'>>;
11
11
  export {};
12
- //# sourceMappingURL=CreateClient.d.ts.map
12
+ //# sourceMappingURL=createClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/types/createClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE7E,oBAAY,QAAQ,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEjE,aAAK,4BAA4B,GAC7B,aAAa,GACb,qBAAqB,GACrB,OAAO,CAAC;AAEZ,oBAAY,mBAAmB,GAAG,IAAI,CACpC,kBAAkB,EAClB,4BAA4B,GAAG,cAAc,CAC9C,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,4BAA4B,CAAC,CAAC,GAAG;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,aAAa,EAAE,mBAAmB,EAAE,CAAC;CACtC,CAAC;AAEJ,oBAAY,aAAa,GAAG,OAAO,CACjC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,OAAO,CAAC,CAC9C,CAAC"}
@@ -0,0 +1,36 @@
1
+ export declare type IterableOptions<TResponse> = Partial<{
2
+ /**
3
+ * The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
4
+ */
5
+ aggregator: (response: TResponse) => void;
6
+ /**
7
+ * The `validate` condition to throw an error and its message.
8
+ */
9
+ error: {
10
+ /**
11
+ * The function to validate the error condition.
12
+ */
13
+ validate: (response: TResponse) => boolean;
14
+ /**
15
+ * The error message to throw.
16
+ */
17
+ message: (response: TResponse) => string;
18
+ };
19
+ /**
20
+ * The function to decide how long to wait between iterations.
21
+ */
22
+ timeout: () => number;
23
+ }>;
24
+ export declare type CreateIterablePromise<TResponse> = IterableOptions<TResponse> & {
25
+ /**
26
+ * The function to run, which returns a promise.
27
+ *
28
+ * The `previousResponse` parameter (`undefined` on the first call) allows you to build your request with incremental logic, to iterate on `page` or `cursor` for example.
29
+ */
30
+ func: (previousResponse?: TResponse) => Promise<TResponse>;
31
+ /**
32
+ * The validator function. It receive the resolved return of the API call.
33
+ */
34
+ validate: (response: TResponse) => boolean;
35
+ };
36
+ //# sourceMappingURL=createIterablePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIterablePromise.d.ts","sourceRoot":"","sources":["../../../src/types/createIterablePromise.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,CAAC,SAAS,IAAI,OAAO,CAAC;IAC/C;;OAEG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC;IAE1C;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC;QAE3C;;WAEG;QACH,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,CAAC;KAC1C,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,MAAM,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH,oBAAY,qBAAqB,CAAC,SAAS,IAAI,eAAe,CAAC,SAAS,CAAC,GAAG;IAC1E;;;;OAIG;IACH,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,SAAS,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAE3D;;OAEG;IACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC;CAC5C,CAAC"}
@@ -30,4 +30,4 @@ export declare type StatefulHost = Host & {
30
30
  */
31
31
  isTimedOut: () => boolean;
32
32
  };
33
- //# sourceMappingURL=Host.d.ts.map
33
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/types/host.ts"],"names":[],"mappings":"AAAA,oBAAY,IAAI,GAAG;IACjB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,oBAAY,YAAY,GAAG,IAAI,GAAG;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;CAC3B,CAAC"}
@@ -1,7 +1,7 @@
1
- export * from './Cache';
2
- export * from './CreateClient';
3
- export * from './CreateRetryablePromise';
4
- export * from './Host';
5
- export * from './Requester';
6
- export * from './Transporter';
1
+ export * from './cache';
2
+ export * from './createClient';
3
+ export * from './createIterablePromise';
4
+ export * from './host';
5
+ export * from './requester';
6
+ export * from './transporter';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { Headers, QueryParameters } from './Transporter';
1
+ import type { Headers, QueryParameters } from './transporter';
2
2
  /**
3
3
  * The method of the request.
4
4
  */
@@ -63,4 +63,4 @@ export declare type EchoResponse = Omit<EndRequest, 'data'> & Pick<Request, 'dat
63
63
  algoliaAgent: string;
64
64
  searchParams?: Record<string, string>;
65
65
  };
66
- //# sourceMappingURL=Requester.d.ts.map
66
+ //# sourceMappingURL=requester.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requester.d.ts","sourceRoot":"","sources":["../../../src/types/requester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE9D;;GAEG;AACH,oBAAY,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjE,oBAAY,OAAO,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,oBAAY,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IAC7D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClD,CAAC;AAEF,oBAAY,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GACjD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { Cache } from './Cache';
2
- import type { Host } from './Host';
3
- import type { Request, Requester, EndRequest, Response } from './Requester';
1
+ import type { Cache } from './cache';
2
+ import type { Host } from './host';
3
+ import type { Request, Requester, EndRequest, Response } from './requester';
4
4
  export declare type Headers = Record<string, string>;
5
5
  export declare type QueryParameters = Record<string, any>;
6
6
  export declare type RequestOptions = Pick<Request, 'cacheable'> & {
@@ -125,4 +125,4 @@ export declare type Transporter = TransporterOptions & {
125
125
  */
126
126
  request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
127
127
  };
128
- //# sourceMappingURL=Transporter.d.ts.map
128
+ //# sourceMappingURL=transporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transporter.d.ts","sourceRoot":"","sources":["../../../src/types/transporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5E,oBAAY,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElD,oBAAY,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG;IACxD;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzD,CAAC;AAEF,oBAAY,UAAU,GAAG;IACvB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,YAAY,CAAC;CACrD,CAAC;AAEF,oBAAY,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,UAAU,EAAE,KAAK,CAAC;IAElB;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;OAKG;IACH,aAAa,EAAE,KAAK,CAAC;IAErB;;;;OAIG;IACH,cAAc,EAAE,KAAK,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;;OAIG;IACH,mBAAmB,EAAE,eAAe,CAAC;IAErC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,oBAAY,WAAW,GAAG,kBAAkB,GAAG;IAC7C;;;OAGG;IACH,OAAO,EAAE,CAAC,SAAS,EACjB,WAAW,EAAE,OAAO,EACpB,kBAAkB,CAAC,EAAE,cAAc,KAChC,OAAO,CAAC,SAAS,CAAC,CAAC;CACzB,CAAC"}
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './src/createAuth';
2
2
  export * from './src/createEchoRequester';
3
- export * from './src/createRetryablePromise';
3
+ export * from './src/createIterablePromise';
4
4
  export * from './src/cache';
5
5
  export * from './src/transporter';
6
6
  export * from './src/createAlgoliaAgent';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/client-common",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.10",
4
4
  "description": "Common package for the Algolia JavaScript API client.",
5
5
  "repository": "algolia/algoliasearch-client-javascript",
6
6
  "license": "MIT",
@@ -14,12 +14,13 @@
14
14
  "index.ts"
15
15
  ],
16
16
  "scripts": {
17
- "clean": "rm -rf dist/",
17
+ "build": "yarn clean && rollup --config",
18
+ "clean": "rm -rf ./dist || true",
18
19
  "test": "jest"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@types/jest": "28.1.6",
22
- "@types/node": "16.11.45",
23
+ "@types/node": "16.11.47",
23
24
  "jest": "28.1.3",
24
25
  "jest-environment-jsdom": "28.1.3",
25
26
  "ts-jest": "28.0.7",
@@ -0,0 +1,238 @@
1
+ import { createIterablePromise } from '../createIterablePromise';
2
+
3
+ describe('createIterablePromise', () => {
4
+ describe('func', () => {
5
+ it('provides the `previousResponse` parameter', async () => {
6
+ const responses: Array<string | undefined> = [];
7
+ const promise = createIterablePromise<string | undefined>({
8
+ func: (previousResponse) => {
9
+ return new Promise((resolve) => {
10
+ resolve(previousResponse === undefined ? 'yes' : 'no');
11
+ });
12
+ },
13
+ validate: () => responses.length === 3,
14
+ aggregator: (response) => responses.push(response),
15
+ });
16
+
17
+ await expect(promise).resolves.toEqual('no');
18
+ expect(responses).toEqual(['yes', 'no', 'no']);
19
+ });
20
+ });
21
+
22
+ describe('validate', () => {
23
+ it('iterates on a `func` until `validate` is met', async () => {
24
+ let calls = 0;
25
+ const promise = createIterablePromise({
26
+ func: () => {
27
+ return new Promise((resolve) => {
28
+ calls += 1;
29
+ resolve(`success #${calls}`);
30
+ });
31
+ },
32
+ validate: () => calls >= 3,
33
+ });
34
+
35
+ await expect(promise).resolves.toEqual('success #3');
36
+ expect(calls).toBe(3);
37
+ });
38
+
39
+ it('forward the response of the `func`', async () => {
40
+ let calls = 0;
41
+ const promise = createIterablePromise<number>({
42
+ func: () => {
43
+ return new Promise((resolve) => {
44
+ calls += 1;
45
+ resolve(calls);
46
+ });
47
+ },
48
+ validate: (response) => response >= 3,
49
+ });
50
+
51
+ await expect(promise).resolves.toEqual(3);
52
+ expect(calls).toBe(3);
53
+ });
54
+ });
55
+
56
+ describe('aggregator', () => {
57
+ it('is called before iterating', async () => {
58
+ let calls = 0;
59
+ let count = 0;
60
+ const promise = createIterablePromise({
61
+ func: () => {
62
+ return new Promise((resolve) => {
63
+ calls += 1;
64
+ resolve(`success #${calls}`);
65
+ });
66
+ },
67
+ validate: () => calls >= 3,
68
+ aggregator: () => (count += 3),
69
+ });
70
+
71
+ await expect(promise).resolves.toEqual('success #3');
72
+ expect(calls).toBe(3);
73
+ expect(count).toBe(3 * 3);
74
+ });
75
+
76
+ it('forward the response of the `func`', async () => {
77
+ let calls = 0;
78
+ const responses: string[] = [];
79
+ const promise = createIterablePromise<string>({
80
+ func: () => {
81
+ return new Promise((resolve) => {
82
+ calls += 1;
83
+ resolve(`success #${calls}`);
84
+ });
85
+ },
86
+ validate: () => calls >= 3,
87
+ aggregator: (response) => {
88
+ responses.push(response);
89
+ },
90
+ });
91
+
92
+ await expect(promise).resolves.toEqual('success #3');
93
+ expect(calls).toBe(3);
94
+ expect(responses).toEqual(['success #1', 'success #2', 'success #3']);
95
+ });
96
+ });
97
+
98
+ describe('timeout', () => {
99
+ it('defaults to no timeout (0)', async () => {
100
+ let calls = 0;
101
+ const before = Date.now();
102
+ const promise = createIterablePromise({
103
+ func: () => {
104
+ return new Promise((resolve) => {
105
+ calls += 1;
106
+ resolve(`success #${calls}`);
107
+ });
108
+ },
109
+ validate: () => calls >= 2,
110
+ });
111
+
112
+ await expect(promise).resolves.toEqual('success #2');
113
+
114
+ expect(Date.now() - before).toBeGreaterThanOrEqual(0);
115
+ expect(Date.now() - before).toBeLessThanOrEqual(10);
116
+ expect(calls).toBe(2);
117
+ });
118
+
119
+ it('waits before calling the `func` again', async () => {
120
+ let calls = 0;
121
+ const before = Date.now();
122
+ const promise = createIterablePromise({
123
+ func: () => {
124
+ return new Promise((resolve) => {
125
+ calls += 1;
126
+ resolve(`success #${calls}`);
127
+ });
128
+ },
129
+ validate: () => calls >= 2,
130
+ timeout: () => 2000,
131
+ });
132
+
133
+ await expect(promise).resolves.toEqual('success #2');
134
+
135
+ expect(Date.now() - before).toBeGreaterThanOrEqual(2000);
136
+ expect(Date.now() - before).toBeLessThanOrEqual(2010);
137
+ expect(calls).toBe(2);
138
+ });
139
+ });
140
+
141
+ describe('error', () => {
142
+ it('gets the rejection of the given promise via reject', async () => {
143
+ let calls = 0;
144
+
145
+ const promise = createIterablePromise({
146
+ func: () => {
147
+ return new Promise((resolve, reject) => {
148
+ calls += 1;
149
+ if (calls <= 3) {
150
+ resolve('okay');
151
+ } else {
152
+ reject(new Error('nope'));
153
+ }
154
+ });
155
+ },
156
+ validate: () => false,
157
+ });
158
+
159
+ await expect(promise).rejects.toEqual(
160
+ expect.objectContaining({ message: 'nope' })
161
+ );
162
+ });
163
+
164
+ it('gets the rejection of the given promise via throw', async () => {
165
+ let calls = 0;
166
+
167
+ const promise = createIterablePromise({
168
+ func: () => {
169
+ return new Promise((resolve) => {
170
+ calls += 1;
171
+ if (calls <= 3) {
172
+ resolve('okay');
173
+ } else {
174
+ throw new Error('nope');
175
+ }
176
+ });
177
+ },
178
+ validate: () => false,
179
+ });
180
+
181
+ await expect(promise).rejects.toEqual(
182
+ expect.objectContaining({ message: 'nope' })
183
+ );
184
+ });
185
+
186
+ it('rejects with the given `message` when `validate` hits', async () => {
187
+ const MAX_RETRIES = 3;
188
+ let calls = 0;
189
+
190
+ const promise = createIterablePromise({
191
+ func: () => {
192
+ return new Promise((resolve) => {
193
+ calls += 1;
194
+ resolve('okay');
195
+ });
196
+ },
197
+ validate: () => false,
198
+ error: {
199
+ validate: () => calls >= MAX_RETRIES,
200
+ message: () => `Error is thrown: ${calls}/${MAX_RETRIES}`,
201
+ },
202
+ });
203
+
204
+ await expect(promise).rejects.toEqual(
205
+ expect.objectContaining({
206
+ message: 'Error is thrown: 3/3',
207
+ })
208
+ );
209
+ expect(calls).toBe(MAX_RETRIES);
210
+ });
211
+
212
+ it('forward the response of the `func`', async () => {
213
+ const MAX_RETRIES = 3;
214
+ let calls = 0;
215
+
216
+ const promise = createIterablePromise<number>({
217
+ func: () => {
218
+ return new Promise((resolve) => {
219
+ calls += 1;
220
+ resolve(calls);
221
+ });
222
+ },
223
+ validate: () => false,
224
+ error: {
225
+ validate: (response) => response >= MAX_RETRIES,
226
+ message: (response) => `Error is thrown: ${response}/${MAX_RETRIES}`,
227
+ },
228
+ });
229
+
230
+ await expect(promise).rejects.toEqual(
231
+ expect.objectContaining({
232
+ message: 'Error is thrown: 3/3',
233
+ })
234
+ );
235
+ expect(calls).toBe(MAX_RETRIES);
236
+ });
237
+ });
238
+ });
@@ -0,0 +1,47 @@
1
+ import type { CreateIterablePromise } from './types/createIterablePromise';
2
+
3
+ /**
4
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
5
+ *
6
+ * @param createIterator - The createIterator options.
7
+ * @param createIterator.func - The function to run, which returns a promise.
8
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
9
+ * @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`.
10
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
11
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
12
+ */
13
+ export function createIterablePromise<TResponse>({
14
+ func,
15
+ validate,
16
+ aggregator,
17
+ error,
18
+ timeout = (): number => 0,
19
+ }: CreateIterablePromise<TResponse>): Promise<TResponse> {
20
+ const retry = (previousResponse?: TResponse): Promise<TResponse> => {
21
+ return new Promise<TResponse>((resolve, reject) => {
22
+ func(previousResponse)
23
+ .then((response) => {
24
+ if (aggregator) {
25
+ aggregator(response);
26
+ }
27
+
28
+ if (validate(response)) {
29
+ return resolve(response);
30
+ }
31
+
32
+ if (error && error.validate(response)) {
33
+ return reject(new Error(error.message(response)));
34
+ }
35
+
36
+ return setTimeout(() => {
37
+ retry(response).then(resolve).catch(reject);
38
+ }, timeout());
39
+ })
40
+ .catch((err) => {
41
+ reject(err);
42
+ });
43
+ });
44
+ };
45
+
46
+ return retry();
47
+ }
@@ -110,12 +110,15 @@ export function createTransporter({
110
110
  : {};
111
111
 
112
112
  const queryParameters: QueryParameters = {
113
- 'x-algolia-agent': algoliaAgent.value,
114
113
  ...baseQueryParameters,
115
114
  ...request.queryParameters,
116
115
  ...dataQueryParameters,
117
116
  };
118
117
 
118
+ if (algoliaAgent.value) {
119
+ queryParameters['x-algolia-agent'] = algoliaAgent.value;
120
+ }
121
+
119
122
  if (requestOptions && requestOptions.queryParameters) {
120
123
  for (const key of Object.keys(requestOptions.queryParameters)) {
121
124
  // We want to keep `undefined` and `null` values,
File without changes
@@ -1,4 +1,4 @@
1
- import type { AlgoliaAgentOptions, TransporterOptions } from './Transporter';
1
+ import type { AlgoliaAgentOptions, TransporterOptions } from './transporter';
2
2
 
3
3
  export type AuthMode = 'WithinHeaders' | 'WithinQueryParameters';
4
4
 
@@ -18,6 +18,6 @@ export type CreateClientOptions = Omit<
18
18
  algoliaAgents: AlgoliaAgentOptions[];
19
19
  };
20
20
 
21
- export type InitClientOptions = Partial<
21
+ export type ClientOptions = Partial<
22
22
  Omit<CreateClientOptions, 'apiKey' | 'appId'>
23
23
  >;
@@ -0,0 +1,40 @@
1
+ export type IterableOptions<TResponse> = Partial<{
2
+ /**
3
+ * The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
4
+ */
5
+ aggregator: (response: TResponse) => void;
6
+
7
+ /**
8
+ * The `validate` condition to throw an error and its message.
9
+ */
10
+ error: {
11
+ /**
12
+ * The function to validate the error condition.
13
+ */
14
+ validate: (response: TResponse) => boolean;
15
+
16
+ /**
17
+ * The error message to throw.
18
+ */
19
+ message: (response: TResponse) => string;
20
+ };
21
+
22
+ /**
23
+ * The function to decide how long to wait between iterations.
24
+ */
25
+ timeout: () => number;
26
+ }>;
27
+
28
+ export type CreateIterablePromise<TResponse> = IterableOptions<TResponse> & {
29
+ /**
30
+ * The function to run, which returns a promise.
31
+ *
32
+ * The `previousResponse` parameter (`undefined` on the first call) allows you to build your request with incremental logic, to iterate on `page` or `cursor` for example.
33
+ */
34
+ func: (previousResponse?: TResponse) => Promise<TResponse>;
35
+
36
+ /**
37
+ * The validator function. It receive the resolved return of the API call.
38
+ */
39
+ validate: (response: TResponse) => boolean;
40
+ };
File without changes
@@ -1,6 +1,6 @@
1
- export * from './Cache';
2
- export * from './CreateClient';
3
- export * from './CreateRetryablePromise';
4
- export * from './Host';
5
- export * from './Requester';
6
- export * from './Transporter';
1
+ export * from './cache';
2
+ export * from './createClient';
3
+ export * from './createIterablePromise';
4
+ export * from './host';
5
+ export * from './requester';
6
+ export * from './transporter';
@@ -1,4 +1,4 @@
1
- import type { Headers, QueryParameters } from './Transporter';
1
+ import type { Headers, QueryParameters } from './transporter';
2
2
 
3
3
  /**
4
4
  * The method of the request.
@@ -1,6 +1,6 @@
1
- import type { Cache } from './Cache';
2
- import type { Host } from './Host';
3
- import type { Request, Requester, EndRequest, Response } from './Requester';
1
+ import type { Cache } from './cache';
2
+ import type { Host } from './host';
3
+ import type { Request, Requester, EndRequest, Response } from './requester';
4
4
 
5
5
  export type Headers = Record<string, string>;
6
6
  export type QueryParameters = Record<string, any>;
@@ -1,14 +0,0 @@
1
- import type { CreateRetryablePromiseOptions } from './types/CreateRetryablePromise';
2
- export declare const DEFAULT_MAX_RETRIES = 50;
3
- export declare const DEFAULT_TIMEOUT: (retryCount: number) => number;
4
- /**
5
- * Return a promise that retry a task until it meets the condition.
6
- *
7
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
8
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
9
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
10
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
11
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
12
- */
13
- export declare function createRetryablePromise<TResponse>({ func, validate, maxRetries, timeout, }: CreateRetryablePromiseOptions<TResponse>): Promise<TResponse>;
14
- //# sourceMappingURL=createRetryablePromise.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRetryablePromise.d.ts","sourceRoot":"","sources":["../../../../packages/client-common/src/createRetryablePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAEpF,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,eAAe,eAAgB,MAAM,KAAG,MACnB,CAAC;AAEnC;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,EAChD,IAAI,EACJ,QAAQ,EACR,UAAgC,EAChC,OAAyB,GAC1B,EAAE,6BAA6B,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CA+B/D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/Cache.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG;IAClB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,oBAAY,WAAW,CAAC,MAAM,IAAI;IAChC;;OAEG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,oBAAY,0BAA0B,GAAG;IACvC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CreateClient.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/CreateClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE7E,oBAAY,QAAQ,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEjE,aAAK,4BAA4B,GAC7B,aAAa,GACb,qBAAqB,GACrB,OAAO,CAAC;AAEZ,oBAAY,mBAAmB,GAAG,IAAI,CACpC,kBAAkB,EAClB,4BAA4B,GAAG,cAAc,CAC9C,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,4BAA4B,CAAC,CAAC,GAAG;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,aAAa,EAAE,mBAAmB,EAAE,CAAC;CACtC,CAAC;AAEJ,oBAAY,iBAAiB,GAAG,OAAO,CACrC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,OAAO,CAAC,CAC9C,CAAC"}
@@ -1,19 +0,0 @@
1
- export declare type CreateRetryablePromiseOptions<TResponse> = {
2
- /**
3
- * The function to run, which returns a promise.
4
- */
5
- func: () => Promise<TResponse>;
6
- /**
7
- * The validator function. It receives the resolved return of `func`.
8
- */
9
- validate: (response: TResponse) => boolean;
10
- /**
11
- * The maximum number of retry. 50 by default.
12
- */
13
- maxRetries?: number;
14
- /**
15
- * The function to decide how long to wait between retries.
16
- */
17
- timeout?: (retryCount: number) => number;
18
- };
19
- //# sourceMappingURL=CreateRetryablePromise.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CreateRetryablePromise.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/CreateRetryablePromise.ts"],"names":[],"mappings":"AAAA,oBAAY,6BAA6B,CAAC,SAAS,IAAI;IACrD;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;IAE/B;;OAEG;IACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC;IAE3C;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;CAC1C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Host.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/Host.ts"],"names":[],"mappings":"AAAA,oBAAY,IAAI,GAAG;IACjB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,oBAAY,YAAY,GAAG,IAAI,GAAG;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;CAC3B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Requester.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/Requester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE9D;;GAEG;AACH,oBAAY,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjE,oBAAY,OAAO,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,oBAAY,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IAC7D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClD,CAAC;AAEF,oBAAY,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GACjD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Transporter.d.ts","sourceRoot":"","sources":["../../../../../packages/client-common/src/types/Transporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5E,oBAAY,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElD,oBAAY,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG;IACxD;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzD,CAAC;AAEF,oBAAY,UAAU,GAAG;IACvB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,YAAY,CAAC;CACrD,CAAC;AAEF,oBAAY,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,UAAU,EAAE,KAAK,CAAC;IAElB;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;OAKG;IACH,aAAa,EAAE,KAAK,CAAC;IAErB;;;;OAIG;IACH,cAAc,EAAE,KAAK,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;;OAIG;IACH,mBAAmB,EAAE,eAAe,CAAC;IAErC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,oBAAY,WAAW,GAAG,kBAAkB,GAAG;IAC7C;;;OAGG;IACH,OAAO,EAAE,CAAC,SAAS,EACjB,WAAW,EAAE,OAAO,EACpB,kBAAkB,CAAC,EAAE,cAAc,KAChC,OAAO,CAAC,SAAS,CAAC,CAAC;CACzB,CAAC"}
@@ -1,86 +0,0 @@
1
- import { createRetryablePromise } from '../createRetryablePromise';
2
-
3
- describe('createRetryablePromise', () => {
4
- it('resolves promise after some retries', async () => {
5
- let calls = 0;
6
- const promise = createRetryablePromise({
7
- func: () => {
8
- return new Promise((resolve) => {
9
- calls += 1;
10
- resolve(`success #${calls}`);
11
- });
12
- },
13
- validate: () => calls >= 3,
14
- });
15
-
16
- await expect(promise).resolves.toEqual('success #3');
17
- expect(calls).toBe(3);
18
- });
19
-
20
- it('gets the rejection of the given promise via reject', async () => {
21
- let calls = 0;
22
-
23
- const promise = createRetryablePromise({
24
- func: () => {
25
- return new Promise((resolve, reject) => {
26
- calls += 1;
27
- if (calls <= 3) {
28
- resolve('okay');
29
- } else {
30
- reject(new Error('nope'));
31
- }
32
- });
33
- },
34
- validate: () => false,
35
- });
36
-
37
- await expect(promise).rejects.toEqual(
38
- expect.objectContaining({ message: 'nope' })
39
- );
40
- });
41
-
42
- it('gets the rejection of the given promise via throw', async () => {
43
- let calls = 0;
44
-
45
- const promise = createRetryablePromise({
46
- func: () => {
47
- return new Promise((resolve) => {
48
- calls += 1;
49
- if (calls <= 3) {
50
- resolve('okay');
51
- } else {
52
- throw new Error('nope');
53
- }
54
- });
55
- },
56
- validate: () => false,
57
- });
58
-
59
- await expect(promise).rejects.toEqual(
60
- expect.objectContaining({ message: 'nope' })
61
- );
62
- });
63
-
64
- it('gets the rejection when it exceeds the max retries number', async () => {
65
- const MAX_RETRIES = 3;
66
- let calls = 0;
67
-
68
- const promise = createRetryablePromise({
69
- func: () => {
70
- return new Promise((resolve) => {
71
- calls += 1;
72
- resolve('okay');
73
- });
74
- },
75
- validate: () => false,
76
- maxRetries: MAX_RETRIES,
77
- });
78
-
79
- await expect(promise).rejects.toEqual(
80
- expect.objectContaining({
81
- message: 'The maximum number of retries exceeded. (3/3)',
82
- })
83
- );
84
- expect(calls).toBe(MAX_RETRIES);
85
- });
86
- });
@@ -1,52 +0,0 @@
1
- import type { CreateRetryablePromiseOptions } from './types/CreateRetryablePromise';
2
-
3
- export const DEFAULT_MAX_RETRIES = 50;
4
- export const DEFAULT_TIMEOUT = (retryCount: number): number =>
5
- Math.min(retryCount * 200, 5000);
6
-
7
- /**
8
- * Return a promise that retry a task until it meets the condition.
9
- *
10
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
11
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
12
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
13
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
14
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
15
- */
16
- export function createRetryablePromise<TResponse>({
17
- func,
18
- validate,
19
- maxRetries = DEFAULT_MAX_RETRIES,
20
- timeout = DEFAULT_TIMEOUT,
21
- }: CreateRetryablePromiseOptions<TResponse>): Promise<TResponse> {
22
- let retryCount = 0;
23
- const retry = (): Promise<TResponse> => {
24
- return new Promise<TResponse>((resolve, reject) => {
25
- func()
26
- .then((response) => {
27
- const isValid = validate(response);
28
- if (isValid) {
29
- resolve(response);
30
- } else if (retryCount + 1 >= maxRetries) {
31
- reject(
32
- new Error(
33
- `The maximum number of retries exceeded. (${
34
- retryCount + 1
35
- }/${maxRetries})`
36
- )
37
- );
38
- } else {
39
- retryCount += 1;
40
- setTimeout(() => {
41
- retry().then(resolve).catch(reject);
42
- }, timeout(retryCount));
43
- }
44
- })
45
- .catch((error) => {
46
- reject(error);
47
- });
48
- });
49
- };
50
-
51
- return retry();
52
- }
@@ -1,21 +0,0 @@
1
- export type CreateRetryablePromiseOptions<TResponse> = {
2
- /**
3
- * The function to run, which returns a promise.
4
- */
5
- func: () => Promise<TResponse>;
6
-
7
- /**
8
- * The validator function. It receives the resolved return of `func`.
9
- */
10
- validate: (response: TResponse) => boolean;
11
-
12
- /**
13
- * The maximum number of retry. 50 by default.
14
- */
15
- maxRetries?: number;
16
-
17
- /**
18
- * The function to decide how long to wait between retries.
19
- */
20
- timeout?: (retryCount: number) => number;
21
- };