UNPKG

@dressed/ws

Version:

Communicate with the Discord Gateway

21 lines (20 loc) 1.26 kB
import type { CachedFunctions, CacheLogic, DefaultLogic } from "./types.ts"; type DesiredProps<F extends CachedFunctions> = Partial<{ [K in keyof F as Awaited<ReturnType<F[K]>> extends object ? Awaited<ReturnType<F[K]>> extends string[] ? never : K : never]: (keyof Awaited<ReturnType<F[K]>>)[]; }>; export type Cache<F extends CachedFunctions, D extends DesiredProps<F> = object, L extends CacheLogic<F> = DefaultLogic<F>> = { [K in keyof F]: (K extends keyof D ? (...a: Parameters<F[K]>) => Promise<Pick<Awaited<ReturnType<F[K]>>, (D[K] extends string[] ? D[K] : [])[number]> & Partial<Awaited<ReturnType<F[K]>>>> : F[K]) & { /** Delete the cached value corresponding to the parameters */ clear: (...a: Parameters<F[K]>) => ReturnType<L["delete"]>; }; }; export declare function createCache<F extends CachedFunctions, D extends DesiredProps<F> = object, L extends CacheLogic<F> = DefaultLogic<F>>( /** The functions to cache */ functions: F, { desiredProps, logic, }?: { /** Only store the specified props for that function */ desiredProps?: D; /** Functions for creating a custom cache implementation */ logic?: L; }): Cache<F, D, L>; export * from "./default-logic.ts"; export * as getters from "./getters.ts";