11import type { Env , Input } from "hono/types" ;
2- import type { Storage } from "unstorage" ;
32import type { ClientRateLimitInfo , HonoConfigType , Store } from "../types.ts" ;
43
4+ export type UnstorageInstance = {
5+ get : ( key : string ) => Promise < any > ;
6+ set : ( key : string , value : any ) => Promise < void > ;
7+ remove : ( key : string ) => Promise < void > ;
8+ } ;
9+
510/**
611 * A `Store` that stores the hit count for each client using Unstorage
712 *
@@ -10,7 +15,7 @@ import type { ClientRateLimitInfo, HonoConfigType, Store } from "../types.ts";
1015export class UnstorageStore <
1116 E extends Env = Env ,
1217 P extends string = string ,
13- I extends Input = Input ,
18+ I extends Input = Input
1419> implements Store < E , P , I >
1520{
1621 /**
@@ -26,14 +31,14 @@ export class UnstorageStore<
2631 /**
2732 * The unstorage storage instance.
2833 */
29- storage : Storage ;
34+ storage : UnstorageInstance ;
3035
3136 /**
3237 * @constructor for `UnstorageStore`.
3338 *
3439 * @param options {Options} - The configuration options for the store.
3540 */
36- constructor ( options : { storage : Storage ; prefix ?: string } ) {
41+ constructor ( options : { storage : UnstorageInstance ; prefix ?: string } ) {
3742 this . storage = options . storage ;
3843 this . prefix = options . prefix ?? "hrl:" ;
3944 }
@@ -69,7 +74,7 @@ export class UnstorageStore<
6974 const result = await this . storage
7075 . get ( this . prefixKey ( key ) )
7176 . then ( ( value ) =>
72- value ? ( JSON . parse ( String ( value ) ) as ClientRateLimitInfo ) : undefined ,
77+ value ? ( JSON . parse ( String ( value ) ) as ClientRateLimitInfo ) : undefined
7378 ) ;
7479
7580 return result ;
@@ -152,7 +157,7 @@ export class UnstorageStore<
152157 */
153158 private async updateRecord (
154159 key : string ,
155- payload : ClientRateLimitInfo ,
160+ payload : ClientRateLimitInfo
156161 ) : Promise < void > {
157162 await this . storage . set ( this . prefixKey ( key ) , JSON . stringify ( payload ) ) ;
158163 }
0 commit comments