Skip to content

Commit bfe1e15

Browse files
feat: Add a PenaltyBox JavaScript Class which can be used standalone for adding and checking if an entry is in the penalty-box (#731)
Co-authored-by: Trevor Elliott <telliott@fastly.com>
1 parent 4928243 commit bfe1e15

File tree

13 files changed

+870
-1
lines changed

13 files changed

+870
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# `PenaltyBox()`
8+
9+
The **`PenaltyBox` constructor** can be used with a [Edge Rate Limiter](../EdgeRateLimiter/EdgeRateLimiter.mdx) or standalone for adding and checking if some entry is in the dataset.
10+
11+
>**Note**: Can only be used when processing requests, not during build-time initialization.
12+
13+
## Syntax
14+
15+
```js
16+
new PenaltyBox(name)
17+
```
18+
19+
> **Note:** `PenaltyBox()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).
20+
21+
### Parameters
22+
23+
- `name` _: string_
24+
- Open a PenaltyBox with the given name
25+
26+
27+
### Return value
28+
29+
A new `PenaltyBox` object instance.
30+
31+
### Exceptions
32+
33+
- `TypeError`
34+
- Thrown if the provided `name` value can not be coerced into a string
35+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# PenaltyBox.prototype.has
8+
9+
Add an `entry` into the PenaltyBox for the duration of the given `timeToLive`.
10+
11+
## Syntax
12+
```js
13+
add(entry, timeToLive)
14+
```
15+
16+
### Parameters
17+
18+
- `entry` _: string_
19+
- The name of the entry to look up
20+
- `timeToLive` _: number_
21+
- In minutes, how long the entry should be added into the PenaltyBox
22+
- Valid `timeToLive` is 1 minute to 60 minutes and `timeToLive` value is truncated to the nearest minute.
23+
24+
25+
### Return value
26+
27+
Returns `undefined`.
28+
29+
### Exceptions
30+
31+
- `TypeError`
32+
- Thrown if the provided `entry` value can not be coerced into a string
33+
- Thrown if the provided `timeToLive` value is not either, a number between 1 and 60 inclusively.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# PenaltyBox.prototype.has
8+
9+
Check if the given entry is contained in in the PenaltyBox instance.
10+
11+
## Syntax
12+
```js
13+
has(entry)
14+
```
15+
16+
### Parameters
17+
18+
- `entry` _: string_
19+
- The name of the entry to look up
20+
21+
22+
### Return value
23+
24+
Returns `true` if the entry is contained in the PenaltyBox instance, otherwise returns `false`.
25+
26+
### Exceptions
27+
28+
- `TypeError`
29+
- Thrown if the provided `entry` value can not be coerced into a string

0 commit comments

Comments
 (0)