File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,28 @@ type FastifyCaching = FastifyPluginCallback<fastifyCaching.FastifyCachingPluginO
3535 privacy : fastifyCaching . Privacy ;
3636} ;
3737
38+ type CacheResult < T > = {
39+ item : T ,
40+ stored : number ,
41+ ttl : number ,
42+ } | null ;
43+
3844declare namespace fastifyCaching {
3945 /**
4046 * @link [`abstract-cache` protocol documentation](https://github.com/jsumners/abstract-cache#protocol)
4147 */
4248 export interface AbstractCacheCompliantObject {
43- get (
49+ get < T = unknown > (
4450 key : string | { id : string ; segment : string } ,
45- callback ? : ( error : unknown , result : unknown ) => void
51+ callback : ( error : unknown , result : CacheResult < T > ) => void
4652 ) : void ;
53+ /**
54+ * If AbstractCache is using useAwait = true, then this method-header must be used.
55+ * @param key
56+ */
57+ get < T = unknown > (
58+ key : string | { id : string ; segment : string } ,
59+ ) : Promise < CacheResult < T > > ;
4760 set (
4861 key : string | { id : string ; segment : string } ,
4962 value : unknown ,
Original file line number Diff line number Diff line change @@ -50,3 +50,20 @@ const badCachingOptions = {
5050} ;
5151
5252expectError ( shouldErrorApp . register ( fastifyCaching , badCachingOptions ) ) ;
53+
54+ fastify . get ( '/three' , async ( request , reply ) => {
55+ expectAssignable < Promise < unknown > > (
56+ fastify . cache . get ( 'well-known' )
57+ ) ;
58+ expectAssignable < Promise < { item : string ; stored : number ; ttl : number ; } | null > > (
59+ fastify . cache . get < string > ( 'well-known' )
60+ ) ;
61+ expectType < void > (
62+ fastify . cache . get < string > ( 'well-known' , ( err , value ) => {
63+ expectType < unknown > ( err ) ;
64+ expectAssignable < { item : string ; stored : number ; ttl : number ; } | null > ( value ) ;
65+ } )
66+ ) ;
67+
68+ return { message : 'two' } ;
69+ } ) ;
You can’t perform that action at this time.
0 commit comments