axios-rate-limit 1.2.1 → 1.3.0

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 1.3.0
5
+ * Add TypeScript typings (see https://github.com/aishek/axios-rate-limit/pull/23)
6
+ * Upgrade handlebars to 4.5.3
7
+ * Upgrade acorn to 5.7.4
8
+ * Upgrade lodash to 4.17.19
9
+
4
10
  ## 1.2.1
5
11
  * Fix TypeScript imports (see https://github.com/aishek/axios-rate-limit/pull/19/files)
6
12
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "axios-rate-limit",
3
3
  "description": "Rate limit for axios.",
4
- "version": "1.2.1",
4
+ "version": "1.3.0",
5
5
  "license": "MIT",
6
6
  "bugs": {
7
7
  "url": "https://github.com/aishek/axios-rate-limit/issues"
@@ -108,7 +108,8 @@
108
108
  "maxRPS",
109
109
  "setMaxRPS",
110
110
  "getMaxRPS",
111
- "setRateLimitOptions"
111
+ "setRateLimitOptions",
112
+ "lodash"
112
113
  ]
113
114
  }
114
115
  }
@@ -1,10 +1,45 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
 
3
- interface RateLimitedAxiosInstance extends AxiosInstance {}
3
+ export interface RateLimitedAxiosInstance extends AxiosInstance {
4
+ getMaxRPS(): number,
5
+ setMaxRPS(rps:number): void,
6
+ setRateLimitOptions(options: rateLimitOptions): void,
7
+ // enable(axios: any): void,
8
+ // handleRequest(request:any):any,
9
+ // handleResponse(response: any): any,
10
+ // push(requestHandler:any):any,
11
+ // shiftInitial():any,
12
+ // shift():any
13
+ }
4
14
 
5
- declare function axiosRateLimit(
15
+ type rateLimitOptions = { maxRequests?: number, perMilliseconds?: number, maxRPS?:number };
16
+
17
+ /**
18
+ * Apply rate limit to axios instance.
19
+ *
20
+ * @example
21
+ * import axios from 'axios';
22
+ * import rateLimit from 'axios-rate-limit';
23
+ *
24
+ * // sets max 2 requests per 1 second, other will be delayed
25
+ * // note maxRPS is a shorthand for perMilliseconds: 1000, and it takes precedence
26
+ * // if specified both with maxRequests and perMilliseconds
27
+ * const http = rateLimit(axios.create(), { maxRequests: 2, perMilliseconds: 1000, maxRPS: 2 })
28
+ * http.getMaxRPS() // 2
29
+ * http.get('https://example.com/api/v1/users.json?page=1') // will perform immediately
30
+ * http.get('https://example.com/api/v1/users.json?page=2') // will perform immediately
31
+ * http.get('https://example.com/api/v1/users.json?page=3') // will perform after 1 second from the first one
32
+ * http.setMaxRPS(3)
33
+ * http.getMaxRPS() // 3
34
+ * http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 }) // same options as constructor
35
+ *
36
+ * @param {Object} axios axios instance
37
+ * @param {Object} options options for rate limit, available for live update
38
+ * @param {Number} options.maxRequests max requests to perform concurrently in given amount of time.
39
+ * @param {Number} options.perMilliseconds amount of time to limit concurrent requests.
40
+ * @returns {Object} axios instance with interceptors added
41
+ */
42
+ export default function axiosRateLimit(
6
43
  axiosInstance: AxiosInstance,
7
- options: { maxRequests: number, perMilliseconds: number },
44
+ options: rateLimitOptions
8
45
  ): RateLimitedAxiosInstance;
9
-
10
- export = axiosRateLimit;