@@ -31,28 +31,30 @@ const getThrottler = memoize((rate, globalThrottler) =>
31
31
/**
32
32
* Determine if a call to a client function will trigger a read (`GET`) or a write (`POST`, `PATCH`, etc...) request.
33
33
*
34
+ * @param {String } limitKey The key to find the limit rate for the API endpoint and method.
34
35
* @param {String } endpoint The client API enpoint (for example the endpoint for a call to `github.repos.get` is `repos`).
35
36
* @param {String } command The client API command (for example the command for a call to `github.repos.get` is `get`).
36
37
*
37
38
* @return {String } `write` or `read` if there is rate limit configuration for this `endpoint` and `command`, `undefined` otherwise.
38
39
*/
39
- const getAccess = ( endpoint , command ) => {
40
+ const getAccess = ( limitKey , endpoint , command ) => {
40
41
const method = GH_ROUTES [ endpoint ] && GH_ROUTES [ endpoint ] [ command ] && GH_ROUTES [ endpoint ] [ command ] . method ;
41
42
const access = method && method === 'GET' ? 'read' : 'write' ;
42
- return RATE_LIMITS [ endpoint ] [ access ] && access ;
43
+ return RATE_LIMITS [ limitKey ] [ access ] && access ;
43
44
} ;
44
45
45
46
/**
46
47
* Get the limiter identifier associated with a client API call.
47
48
*
49
+ * @param {String } limitKey The key to find the limit rate for the API endpoint and method.
48
50
* @param {String } endpoint The client API enpoint (for example the endpoint for a call to `github.repos.get` is `repos`).
49
51
* @param {String } command The client API command (for example the command for a call to `github.repos.get` is `get`).
50
52
*
51
53
* @return {String } A string identifying the limiter to use for this `endpoint` and `command` (e.g. `search` or `core.write`).
52
54
*/
53
- const getLimitKey = ( endpoint , command ) => {
54
- return endpoint
55
- ? [ endpoint , RATE_LIMITS [ endpoint ] && getAccess ( endpoint , command ) ] . filter ( Boolean ) . join ( '.' )
55
+ const getLimitKey = ( limitKey , endpoint , command ) => {
56
+ return limitKey
57
+ ? [ limitKey , RATE_LIMITS [ limitKey ] && getAccess ( limitKey , endpoint , command ) ] . filter ( Boolean ) . join ( '.' )
56
58
: RATE_LIMITS [ command ]
57
59
? command
58
60
: 'core' ;
@@ -65,10 +67,11 @@ const getLimitKey = (endpoint, command) => {
65
67
*
66
68
* @param {Throttler } globalThrottler The throller function for the global rate limit.
67
69
* @param {String } limitKey The key to find the limit rate for the API endpoint and method.
70
+ * @param {String } endpoint The client API enpoint (for example the endpoint for a call to `github.repos.get` is `repos`).
68
71
*
69
72
* @return {Function } The `handler` for a `Proxy` wrapping an Octokit instance.
70
73
*/
71
- const handler = ( globalThrottler , limitKey ) => ( {
74
+ const handler = ( globalThrottler , limitKey , endpoint ) => ( {
72
75
/**
73
76
* If the target has the property as own, determine the rate limit based on the property name and recursively wrap the value in a `Proxy`. Otherwise returns the property value.
74
77
*
@@ -80,7 +83,7 @@ const handler = (globalThrottler, limitKey) => ({
80
83
*/
81
84
get : ( target , name , receiver ) =>
82
85
Reflect . apply ( Object . prototype . hasOwnProperty , target , [ name ] )
83
- ? new Proxy ( target [ name ] , handler ( globalThrottler , getLimitKey ( limitKey , name ) ) )
86
+ ? new Proxy ( target [ name ] , handler ( globalThrottler , getLimitKey ( limitKey , endpoint , name ) , endpoint || name ) )
84
87
: Reflect . get ( target , name , receiver ) ,
85
88
86
89
/**
0 commit comments