forked from limitd/limitdb
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: improve jsdoc types #69
Open
LeweyM
wants to merge
4
commits into
elevated_limits_quota_on_params
Choose a base branch
from
types-refactor
base: elevated_limits_quota_on_params
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−93
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// --- Public Types --- | ||
|
||
/** | ||
* @typedef {Object} LimitDBParams | ||
* uri nodes buckets prefix | ||
* @property {string} [params.uri] Address of Redis. | ||
* @property {Object.<string, object>} [params.nodes] Redis Cluster Configuration https://github.com/luin/ioredis#cluster". | ||
* @property {Object.<string, Bucket>} [params.types] The buckets configuration. | ||
* @property {string} [params.prefix] Prefix keys in Redis. | ||
* @property {Bucket} [params.configOverride] Bucket configuration override | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} Bucket | ||
* @property {number} [per_interval] The number of tokens to add per interval. | ||
* @property {number} [interval] The length of the interval in milliseconds. | ||
* @property {number} [size] The maximum number of tokens in the bucket. | ||
* @property {number} [per_second] The number of tokens to add per second. Equivalent to "interval: 1000, per_interval: x". | ||
* @property {number} [per_minute] The number of tokens to add per minute. Equivalent to "interval: 60000, per_interval: x". | ||
* @property {number} [per_hour] The number of tokens to add per hour. Equivalent to "interval: 3600000, per_interval: x". | ||
* @property {number} [per_day] The number of tokens to add per day. Equivalent to "interval: 86400000, per_interval: x". | ||
* @property {number} [unlimited] the maximum number of tokens in the bucket. equivalent to "size: x". | ||
* @property {number} [skip_n_calls] the number of calls to skip. equivalent to "size: x". | ||
* @property {ElevatedLimitParams} [elevated_limits] The elevated limit configuration. | ||
*/ | ||
|
||
/** | ||
* @typedef TakeParams | ||
* @property {string} type The name of the bucket type. | ||
* @property {string} key The key of the bucket instance. | ||
* @property {number} [count=1] The number of tokens to take from the bucket. | ||
* @property {Bucket} configOverride Externally provided bucket configuration | ||
*/ | ||
|
||
/** | ||
* @typedef TakeResult | ||
* @property {boolean} conformant Returns true if there is enough capacity in the bucket and the tokens has been removed. | ||
* @property {number} remaining The number of tokens remaining in the bucket. | ||
* @property {number} reset A unix timestamp indicating when the bucket is going to be full. | ||
* @property {number} limit The size of the bucket. | ||
*/ | ||
/** | ||
|
||
* @typedef WaitParams | ||
* @property {string} type The name of the bucket type. | ||
* @property {string} key The key of the bucket instance. | ||
* @property {number} [count=1] The number of tokens to wait for. | ||
* @property {Bucket} configOverride Externally provided bucket configuration | ||
*/ | ||
|
||
/** | ||
* @typedef WaitResult | ||
* @property {number} remaining The number of tokens remaining in the bucket. | ||
* @property {number} reset A unix timestamp indicating when the bucket is going to be full. | ||
* @property {number} limit The size of the bucket. | ||
*/ | ||
|
||
/** | ||
* @typedef PutParams | ||
* @property {string} type The name of the bucket type. | ||
* @property {string} key The key of the bucket instance. | ||
* @property {number} [count=SIZE] The number of tokens to put in the bucket. Defaults to the size of the bucket. | ||
* @property {Bucket} configOverride Externally provided bucket configruation | ||
*/ | ||
|
||
/** | ||
* @typedef PutResult | ||
* @property {number} remaining The number of tokens remaining in the bucket. | ||
* @property {number} reset A unix timestamp indicating when the bucket is going to be full. | ||
* @property {number} limit The size of the bucket. | ||
*/ | ||
|
||
/** | ||
* @typedef GetParams | ||
* @property {string} type The name of the bucket type. | ||
* @property {string} key The key of the bucket instance. | ||
* @property {Bucket} configOverride Externally provided bucket configuration | ||
*/ | ||
|
||
/** | ||
* @typedef GetResult | ||
* @property {number} remaining The number of tokens remaining in the bucket. | ||
* @property {number} reset A unix timestamp indicating when the bucket is going to be full. | ||
* @property {number} limit The size of the bucket. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} TakeElevatedParams | ||
* @property {string} type - The name of the bucket type. | ||
* @property {string} key - The key of the bucket instance. | ||
* @property {number} [count=1] - The number of tokens to take from the bucket. | ||
* @property {ElevatedLimitParams} [elevated_limits] - (Optional) The elevated limit configuration. | ||
* @property {Bucket} configOverride Externally provided bucket configuration | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ElevatedLimitParams | ||
* @property {string} erl_is_active_key - The key to check if the elevated limits are active. | ||
* @property {string} erl_quota_key - The key to store the quota for the elevated limits. | ||
* @property {number} erl_activation_period_seconds - The activation period for the elevated limits in seconds. | ||
* // temporal options | ||
* @property {number} [per_interval] The number of tokens to add per interval. | ||
* @property {number} [interval] The length of the interval in milliseconds. | ||
* @property {number} [size] The maximum number of tokens in the bucket. | ||
* @property {number} [per_second] The number of tokens to add per second. Equivalent to "interval: 1000, per_interval: x". | ||
* @property {number} [per_minute] The number of tokens to add per minute. Equivalent to "interval: 60000, per_interval: x". | ||
* @property {number} [per_hour] The number of tokens to add per hour. Equivalent to "interval: 3600000, per_interval: x". | ||
* @property {number} [per_day] The number of tokens to add per day. Equivalent to "interval: 86400000, per_interval: x". | ||
* @property {number} [unlimited] The maximum number of tokens in the bucket. Equivalent to "size: x". | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} TakeElevatedResult | ||
* @property {boolean} conformant - Returns true if there is enough capacity in the bucket and the tokens has been removed. | ||
* @property {number} remaining - The number of tokens remaining in the bucket. | ||
* @property {number} reset - A unix timestamp indicating when the bucket is going to be full. | ||
* @property {number} limit - The size of the bucket. | ||
* @property {boolean} delayed - Indicates if the operation was delayed. | ||
* @property {Elevated_result} elevated_limits - The elevated limit result | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} Elevated_result | ||
* @property {boolean} erl_configured_for_bucket - Indicates if the bucket is configured for elevated limits. | ||
* @property {boolean} triggered - Indicates if the elevated limits were triggered. | ||
* @property {boolean} activated - Indicates if the elevated limits were activated. | ||
* @property {number} quota_remaining - The remaining quota for elevated limits. | ||
* @property {number} quota_allocated - The allocated quota for elevated limits. | ||
* @property {number} erl_activation_period_seconds - The activation period for elevated limits in seconds. | ||
*/ | ||
|
||
// --- Internal Types --- | ||
|
||
/** | ||
* @typedef {Object} NormalizedType -- the internal representation of a bucket | ||
* @property {number} [per_interval] The number of tokens to add per interval. | ||
* @property {number} [interval] The length of the interval in milliseconds. | ||
* @property {number} [size] The maximum number of tokens in the bucket. | ||
* @property {number} [ttl] The time to live for the bucket in seconds. | ||
* @property {number} [ms_per_interval] The number of milliseconds per interval. | ||
* @property {number} [drip_interval] The interval for the drip in milliseconds. | ||
* @property {number} [unlimited] the maximum number of tokens in the bucket. equivalent to "size: x". | ||
* @property {number} [skip_n_calls] the number of calls to skip. equivalent to "size: x". | ||
* @property {NormalizedType} [elevated_limits] The elevated limit configuration. | ||
* @property {boolean} [erl_configured_for_bucket] Indicates if the bucket is configured for elevated limits. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ElevatedLimitConfiguration | ||
* @property {string} erl_is_active_key - The key to check if the elevated limits are active. | ||
* @property {string} erl_quota_key - The key to store the quota for the elevated limits. | ||
* @property {number} erl_activation_period_seconds - The activation period for the elevated limits in seconds. | ||
* @property {number} erl_quota - The quota for the elevated limits. | ||
* @property {string} erl_quota_interval - The interval for the quota. | ||
*/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: I have not seen this before with jsdocs, what is it doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its to reference types defined in another file. like a
require
for types.Not sure if this is the best way though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I had no idea importing them was actually required!