@dereekb/util 11.0.13 → 11.0.14

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util/fetch",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  ".": {
5
5
  "types": "./src/index.d.ts",
6
6
  "node": {
package/index.cjs.js CHANGED
@@ -13762,10 +13762,12 @@ function performTasksFromFactoryInParallelFunction(config) {
13762
13762
  }
13763
13763
 
13764
13764
  function exponentialPromiseRateLimiter(initialConfig) {
13765
+ const DEFAULT_START_LIMIT_AT = 1;
13765
13766
  const DEFAULT_COOLDOWN_RATE = 1;
13766
13767
  const DEFAULT_EXPONENT_RATE = 2;
13767
13768
  const DEFAULT_MAX_WAIT_TIME = MS_IN_HOUR;
13768
13769
  let config = {
13770
+ startLimitAt: DEFAULT_START_LIMIT_AT,
13769
13771
  cooldownRate: DEFAULT_COOLDOWN_RATE,
13770
13772
  exponentRate: DEFAULT_EXPONENT_RATE,
13771
13773
  maxWaitTime: DEFAULT_MAX_WAIT_TIME
@@ -13785,11 +13787,13 @@ function exponentialPromiseRateLimiter(initialConfig) {
13785
13787
  enabled = nextEnabled;
13786
13788
  }
13787
13789
  function setConfig(newConfig, andReset = false) {
13788
- var _newConfig$cooldownRa, _newConfig$maxWaitTim, _newConfig$exponentRa;
13790
+ var _newConfig$startLimit, _newConfig$cooldownRa, _newConfig$maxWaitTim, _newConfig$exponentRa;
13791
+ const startLimitAt = Math.max(0, (_newConfig$startLimit = newConfig.startLimitAt) != null ? _newConfig$startLimit : DEFAULT_START_LIMIT_AT);
13789
13792
  const cooldownRate = (_newConfig$cooldownRa = newConfig.cooldownRate) != null ? _newConfig$cooldownRa : DEFAULT_COOLDOWN_RATE;
13790
13793
  const maxWaitTime = (_newConfig$maxWaitTim = newConfig.maxWaitTime) != null ? _newConfig$maxWaitTim : DEFAULT_MAX_WAIT_TIME;
13791
13794
  const exponentRate = (_newConfig$exponentRa = newConfig.exponentRate) != null ? _newConfig$exponentRa : DEFAULT_EXPONENT_RATE;
13792
13795
  config = {
13796
+ startLimitAt,
13793
13797
  cooldownRate,
13794
13798
  maxWaitTime,
13795
13799
  exponentRate
@@ -13814,14 +13818,15 @@ function exponentialPromiseRateLimiter(initialConfig) {
13814
13818
  const msSinceLastExecution = Date.now() - timeOfLastExecution.getTime();
13815
13819
  const cooldown = msSinceLastExecution * cooldownRate / MS_IN_SECOND; // the cooldown amount
13816
13820
  const count = Math.max(currentCount - cooldown, 0);
13821
+ const effectiveCount = Math.max(0, count - config.startLimitAt);
13817
13822
  if (increasedExecutions) {
13818
13823
  currentCount = count + increasedExecutions;
13819
13824
  timeOfLastExecution = new Date();
13820
13825
  }
13821
- if (count >= countForMaxWaitTime) {
13826
+ if (effectiveCount >= countForMaxWaitTime) {
13822
13827
  return config.maxWaitTime;
13823
13828
  } else {
13824
- return count === 0 ? 0 : Math.pow(config.exponentRate, Math.max(count - 1, 0)) * MS_IN_SECOND;
13829
+ return (Math.pow(config.exponentRate, Math.max(effectiveCount, 0)) - 1) * MS_IN_SECOND;
13825
13830
  }
13826
13831
  }
13827
13832
  function getNextWaitTime(increase) {
package/index.esm.js CHANGED
@@ -15298,10 +15298,12 @@ function performTasksFromFactoryInParallelFunction(config) {
15298
15298
  // MARK: Exponential Limiter
15299
15299
 
15300
15300
  function exponentialPromiseRateLimiter(initialConfig) {
15301
+ const DEFAULT_START_LIMIT_AT = 1;
15301
15302
  const DEFAULT_COOLDOWN_RATE = 1;
15302
15303
  const DEFAULT_EXPONENT_RATE = 2;
15303
15304
  const DEFAULT_MAX_WAIT_TIME = MS_IN_HOUR;
15304
15305
  let config = {
15306
+ startLimitAt: DEFAULT_START_LIMIT_AT,
15305
15307
  cooldownRate: DEFAULT_COOLDOWN_RATE,
15306
15308
  exponentRate: DEFAULT_EXPONENT_RATE,
15307
15309
  maxWaitTime: DEFAULT_MAX_WAIT_TIME
@@ -15321,11 +15323,13 @@ function exponentialPromiseRateLimiter(initialConfig) {
15321
15323
  enabled = nextEnabled;
15322
15324
  }
15323
15325
  function setConfig(newConfig, andReset = false) {
15324
- var _newConfig$cooldownRa, _newConfig$maxWaitTim, _newConfig$exponentRa;
15326
+ var _newConfig$startLimit, _newConfig$cooldownRa, _newConfig$maxWaitTim, _newConfig$exponentRa;
15327
+ const startLimitAt = Math.max(0, (_newConfig$startLimit = newConfig.startLimitAt) != null ? _newConfig$startLimit : DEFAULT_START_LIMIT_AT);
15325
15328
  const cooldownRate = (_newConfig$cooldownRa = newConfig.cooldownRate) != null ? _newConfig$cooldownRa : DEFAULT_COOLDOWN_RATE;
15326
15329
  const maxWaitTime = (_newConfig$maxWaitTim = newConfig.maxWaitTime) != null ? _newConfig$maxWaitTim : DEFAULT_MAX_WAIT_TIME;
15327
15330
  const exponentRate = (_newConfig$exponentRa = newConfig.exponentRate) != null ? _newConfig$exponentRa : DEFAULT_EXPONENT_RATE;
15328
15331
  config = {
15332
+ startLimitAt,
15329
15333
  cooldownRate,
15330
15334
  maxWaitTime,
15331
15335
  exponentRate
@@ -15351,14 +15355,15 @@ function exponentialPromiseRateLimiter(initialConfig) {
15351
15355
  const msSinceLastExecution = Date.now() - timeOfLastExecution.getTime();
15352
15356
  const cooldown = msSinceLastExecution * cooldownRate / MS_IN_SECOND; // the cooldown amount
15353
15357
  const count = Math.max(currentCount - cooldown, 0);
15358
+ const effectiveCount = Math.max(0, count - config.startLimitAt);
15354
15359
  if (increasedExecutions) {
15355
15360
  currentCount = count + increasedExecutions;
15356
15361
  timeOfLastExecution = new Date();
15357
15362
  }
15358
- if (count >= countForMaxWaitTime) {
15363
+ if (effectiveCount >= countForMaxWaitTime) {
15359
15364
  return config.maxWaitTime;
15360
15365
  } else {
15361
- return count === 0 ? 0 : Math.pow(config.exponentRate, Math.max(count - 1, 0)) * MS_IN_SECOND;
15366
+ return (Math.pow(config.exponentRate, Math.max(effectiveCount, 0)) - 1) * MS_IN_SECOND;
15362
15367
  }
15363
15368
  }
15364
15369
  function getNextWaitTime(increase) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -31,6 +31,12 @@ export interface EnableTogglePromiseRateLimiter extends PromiseRateLimiter {
31
31
  setEnabled(enable: boolean): void;
32
32
  }
33
33
  export interface ExponentialPromiseRateLimiterConfig {
34
+ /**
35
+ * The base count to start limiting requests at. Minimum of 0 allowed.
36
+ *
37
+ * Defaults to 0.
38
+ */
39
+ readonly startLimitAt?: number;
34
40
  /**
35
41
  * How fast the cooldown occurs.
36
42
  *
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [11.0.14](https://github.com/dereekb/dbx-components/compare/v11.0.13-dev...v11.0.14) (2024-11-27)
6
+
7
+
8
+
5
9
  ## [11.0.13](https://github.com/dereekb/dbx-components/compare/v11.0.12-dev...v11.0.13) (2024-11-27)
6
10
 
7
11
 
package/test/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  "type": "commonjs",
5
5
  "peerDependencies": {
6
6
  "@dereekb/util": "*"