hono-rate-limiter 0.5.1 → 0.5.3
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/dist/index.cjs +6 -3
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +6 -3
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -525,9 +525,12 @@ class UnstorageStore {
|
|
|
525
525
|
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
|
526
526
|
*/
|
|
527
527
|
async get(key) {
|
|
528
|
-
const result = await this.storage.get(this.prefixKey(key)).then(
|
|
529
|
-
(
|
|
530
|
-
|
|
528
|
+
const result = await this.storage.get(this.prefixKey(key)).then((value) => {
|
|
529
|
+
if (typeof value === "object") {
|
|
530
|
+
return value;
|
|
531
|
+
}
|
|
532
|
+
return value ? JSON.parse(String(value)) : void 0;
|
|
533
|
+
});
|
|
531
534
|
return result;
|
|
532
535
|
}
|
|
533
536
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { Env, Input, Context, Next, MiddlewareHandler } from 'hono';
|
|
|
2
2
|
import { HandlerResponse, Env as Env$1, Input as Input$1 } from 'hono/types';
|
|
3
3
|
import { StatusCode } from 'hono/utils/http-status';
|
|
4
4
|
import { WSContext, WSEvents } from 'hono/ws';
|
|
5
|
-
import { Storage } from 'unstorage';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Data returned from the `Store` when a client's hit counter is incremented.
|
|
@@ -502,6 +501,11 @@ declare class RedisStore<E extends Env$1 = Env$1, P extends string = string, I e
|
|
|
502
501
|
resetKey(key: string): Promise<void>;
|
|
503
502
|
}
|
|
504
503
|
|
|
504
|
+
type UnstorageInstance = {
|
|
505
|
+
get: (key: string) => Promise<any>;
|
|
506
|
+
set: (key: string, value: any) => Promise<void>;
|
|
507
|
+
remove: (key: string) => Promise<void>;
|
|
508
|
+
};
|
|
505
509
|
/**
|
|
506
510
|
* A `Store` that stores the hit count for each client using Unstorage
|
|
507
511
|
*
|
|
@@ -519,14 +523,14 @@ declare class UnstorageStore<E extends Env$1 = Env$1, P extends string = string,
|
|
|
519
523
|
/**
|
|
520
524
|
* The unstorage storage instance.
|
|
521
525
|
*/
|
|
522
|
-
storage:
|
|
526
|
+
storage: UnstorageInstance;
|
|
523
527
|
/**
|
|
524
528
|
* @constructor for `UnstorageStore`.
|
|
525
529
|
*
|
|
526
530
|
* @param options {Options} - The configuration options for the store.
|
|
527
531
|
*/
|
|
528
532
|
constructor(options: {
|
|
529
|
-
storage:
|
|
533
|
+
storage: UnstorageInstance;
|
|
530
534
|
prefix?: string;
|
|
531
535
|
});
|
|
532
536
|
/**
|
|
@@ -598,4 +602,4 @@ declare class UnstorageStore<E extends Env$1 = Env$1, P extends string = string,
|
|
|
598
602
|
declare function webSocketLimiter<E extends Env = Env, P extends string = string, I extends Input = Input>(config: WSConfigProps<E, P, I>): (createEvents: (c: Context<E, P, I>) => WSEvents | Promise<WSEvents>) => (c: Context<E, P, I>) => Promise<WSEvents>;
|
|
599
603
|
|
|
600
604
|
export { MemoryStore, RedisStore, UnstorageStore, rateLimiter, webSocketLimiter };
|
|
601
|
-
export type { ClientRateLimitInfo, CloudflareConfigProps, CloudflareConfigType, ConfigProps, ConfigType, HonoConfigProps, HonoConfigType, Options, Promisify, RateLimitExceededEventHandler, RateLimitInfo, RedisClient, RedisReply, Store, WSConfigProps, WSConfigType, WSRateLimitExceededEventHandler, WSStatusCode };
|
|
605
|
+
export type { ClientRateLimitInfo, CloudflareConfigProps, CloudflareConfigType, ConfigProps, ConfigType, HonoConfigProps, HonoConfigType, Options, Promisify, RateLimitExceededEventHandler, RateLimitInfo, RedisClient, RedisReply, Store, UnstorageInstance, WSConfigProps, WSConfigType, WSRateLimitExceededEventHandler, WSStatusCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Env, Input, Context, Next, MiddlewareHandler } from 'hono';
|
|
|
2
2
|
import { HandlerResponse, Env as Env$1, Input as Input$1 } from 'hono/types';
|
|
3
3
|
import { StatusCode } from 'hono/utils/http-status';
|
|
4
4
|
import { WSContext, WSEvents } from 'hono/ws';
|
|
5
|
-
import { Storage } from 'unstorage';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Data returned from the `Store` when a client's hit counter is incremented.
|
|
@@ -502,6 +501,11 @@ declare class RedisStore<E extends Env$1 = Env$1, P extends string = string, I e
|
|
|
502
501
|
resetKey(key: string): Promise<void>;
|
|
503
502
|
}
|
|
504
503
|
|
|
504
|
+
type UnstorageInstance = {
|
|
505
|
+
get: (key: string) => Promise<any>;
|
|
506
|
+
set: (key: string, value: any) => Promise<void>;
|
|
507
|
+
remove: (key: string) => Promise<void>;
|
|
508
|
+
};
|
|
505
509
|
/**
|
|
506
510
|
* A `Store` that stores the hit count for each client using Unstorage
|
|
507
511
|
*
|
|
@@ -519,14 +523,14 @@ declare class UnstorageStore<E extends Env$1 = Env$1, P extends string = string,
|
|
|
519
523
|
/**
|
|
520
524
|
* The unstorage storage instance.
|
|
521
525
|
*/
|
|
522
|
-
storage:
|
|
526
|
+
storage: UnstorageInstance;
|
|
523
527
|
/**
|
|
524
528
|
* @constructor for `UnstorageStore`.
|
|
525
529
|
*
|
|
526
530
|
* @param options {Options} - The configuration options for the store.
|
|
527
531
|
*/
|
|
528
532
|
constructor(options: {
|
|
529
|
-
storage:
|
|
533
|
+
storage: UnstorageInstance;
|
|
530
534
|
prefix?: string;
|
|
531
535
|
});
|
|
532
536
|
/**
|
|
@@ -598,4 +602,4 @@ declare class UnstorageStore<E extends Env$1 = Env$1, P extends string = string,
|
|
|
598
602
|
declare function webSocketLimiter<E extends Env = Env, P extends string = string, I extends Input = Input>(config: WSConfigProps<E, P, I>): (createEvents: (c: Context<E, P, I>) => WSEvents | Promise<WSEvents>) => (c: Context<E, P, I>) => Promise<WSEvents>;
|
|
599
603
|
|
|
600
604
|
export { MemoryStore, RedisStore, UnstorageStore, rateLimiter, webSocketLimiter };
|
|
601
|
-
export type { ClientRateLimitInfo, CloudflareConfigProps, CloudflareConfigType, ConfigProps, ConfigType, HonoConfigProps, HonoConfigType, Options, Promisify, RateLimitExceededEventHandler, RateLimitInfo, RedisClient, RedisReply, Store, WSConfigProps, WSConfigType, WSRateLimitExceededEventHandler, WSStatusCode };
|
|
605
|
+
export type { ClientRateLimitInfo, CloudflareConfigProps, CloudflareConfigType, ConfigProps, ConfigType, HonoConfigProps, HonoConfigType, Options, Promisify, RateLimitExceededEventHandler, RateLimitInfo, RedisClient, RedisReply, Store, UnstorageInstance, WSConfigProps, WSConfigType, WSRateLimitExceededEventHandler, WSStatusCode };
|
package/dist/index.js
CHANGED
|
@@ -523,9 +523,12 @@ class UnstorageStore {
|
|
|
523
523
|
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
|
524
524
|
*/
|
|
525
525
|
async get(key) {
|
|
526
|
-
const result = await this.storage.get(this.prefixKey(key)).then(
|
|
527
|
-
(
|
|
528
|
-
|
|
526
|
+
const result = await this.storage.get(this.prefixKey(key)).then((value) => {
|
|
527
|
+
if (typeof value === "object") {
|
|
528
|
+
return value;
|
|
529
|
+
}
|
|
530
|
+
return value ? JSON.parse(String(value)) : void 0;
|
|
531
|
+
});
|
|
529
532
|
return result;
|
|
530
533
|
}
|
|
531
534
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-rate-limiter",
|
|
3
3
|
"description": "Rate limit middleware for Hono.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"hono": "^4.10.8",
|
|
45
45
|
"unstorage": "^1.17.3"
|
|
46
46
|
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"unstorage": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
47
52
|
"devDependencies": {
|
|
48
53
|
"@biomejs/biome": "^2.3.8",
|
|
49
54
|
"@hono/node-server": "^1.19.7",
|