bucketflow 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -31,12 +31,12 @@ optional rejection message.
31
31
  ```ts
32
32
  import { FixedWindow } from "bucketflow";
33
33
 
34
- const limiter = new FixedWindow("api", "Too many requests", 100, 60_000);
34
+ const limiter = new FixedWindow(100, 60_000);
35
35
  const result = limiter.checkLimit("user-123");
36
36
  ```
37
37
 
38
- The constructor accepts a limiter key, optional rejection message, maximum
39
- requests, and window duration in milliseconds.
38
+ The constructor accepts the maximum number of requests, the window duration
39
+ in milliseconds, and an optional rejection message.
40
40
 
41
41
  ### Sliding window
42
42
 
@@ -48,7 +48,16 @@ const result = limiter.checkLimit("user-123");
48
48
  ```
49
49
 
50
50
  The constructor accepts the window duration, refresh rate, maximum requests,
51
- and an optional rejection message. Durations are in milliseconds.
51
+ and an optional rejection message. Durations and rates are in milliseconds.
52
+
53
+ ## Return values
54
+
55
+ Each limiter returns an object with an `allowed` boolean and a message. The
56
+ additional field depends on the limiter:
57
+
58
+ - `TokenBucket`: `tokens` is the number of tokens remaining.
59
+ - `FixedWindow`: `reqRemaining` is the reported number of requests remaining.
60
+ - `SlidingWindow`: `counter` is the current request counter.
52
61
 
53
62
  ## Framework integrations
54
63
 
@@ -133,14 +142,15 @@ same pattern into a NestJS guard when route-level control is preferred.
133
142
 
134
143
  ## API
135
144
 
136
- The package currently exports:
145
+ The package currently exports these classes:
137
146
 
138
147
  - `TokenBucket`
139
148
  - `FixedWindow`
140
149
  - `SlidingWindow`
141
150
 
142
- All limiters are in-memory and local to the running process. They are not
143
- intended to coordinate limits across multiple Node.js processes or servers.
151
+ All limiters are in-memory and local to the running process. They do not share
152
+ state across multiple Node.js processes or servers, and state is lost when the
153
+ process restarts.
144
154
 
145
155
  ## License
146
156
 
@@ -1,11 +1,10 @@
1
- import { FixedWindowProps, FixedWindowResponse } from "../types";
1
+ import type { FixedWindowProps, FixedWindowResponse } from "../types";
2
2
  export declare class FixedWindow implements FixedWindowProps {
3
- key: string;
4
3
  private store;
5
4
  message: string;
6
5
  maxNum: number;
7
6
  window: number;
8
- constructor(key: string, message: string | undefined, maxNum: number, window: number);
7
+ constructor(maxNum: number, window: number, message?: string);
9
8
  checkLimit(key: string): FixedWindowResponse;
10
9
  }
11
10
  //# sourceMappingURL=fixed-window.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixed-window.d.ts","sourceRoot":"","sources":["../src/fixed-window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAS,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAExE,qBAAa,WAAY,YAAW,gBAAgB;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAEf,YACE,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,YAAsB,EACrC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EAMf;IAED,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CA0C3C;CACF"}
1
+ {"version":3,"file":"fixed-window.d.ts","sourceRoot":"","sources":["../src/fixed-window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE7E,qBAAa,WAAY,YAAW,gBAAgB;IAClD,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAEf,YACE,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAA4B,EAKtC;IACD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CA0C3C;CACF"}
package/dist/index.js CHANGED
@@ -28,9 +28,8 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/fixed-window.ts
30
30
  var FixedWindow = class {
31
- constructor(key, message = "Too many requests", maxNum, window) {
31
+ constructor(maxNum, window, message = "Too many requests") {
32
32
  this.store = /* @__PURE__ */ new Map();
33
- this.key = key;
34
33
  this.message = message;
35
34
  this.maxNum = maxNum;
36
35
  this.window = window;
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  // src/fixed-window.ts
2
2
  var FixedWindow = class {
3
- constructor(key, message = "Too many requests", maxNum, window) {
3
+ constructor(maxNum, window, message = "Too many requests") {
4
4
  this.store = /* @__PURE__ */ new Map();
5
- this.key = key;
6
5
  this.message = message;
7
6
  this.maxNum = maxNum;
8
7
  this.window = window;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bucketflow",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Rate limiting for Node.js with token bucket, fixed window, and leaky bucket algorithms",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [