import { EntitiesManager } from '@src/api/managers/EntitiesManager' ; import { Client } from '@src/core' ; import { EntityKey } from '@src/api/entities/interfaces' ; import { EntitiesCacheManagerData } from '@src/api/managers/interfaces' ; import { CacheManagerForEachOptions , CacheManagerDeleteOptions , CacheManagerFilterOptions , CacheManagerCountsOptions , CacheManagerSweepOptions , CacheManagerCountOptions , CacheManagerClearOptions , CacheManagerSizeOptions , CacheManagerFindOptions , CacheManagerGetOptions , CacheManagerHasOptions , CacheManagerMapOptions , CacheManagerSetOptions , CacheOptions , CachePointer , } from '@src/cache/interfaces' ; import { CacheProvider , CacheStorageKey } from '@discordoo/providers' ; export class EntitiesCacheManager < Entity > extends EntitiesManager { private readonly entityKey : EntityKey ; private readonly policy : keyof CacheOptions ; public readonly keyspace : string ; public readonly storage : CacheStorageKey ; constructor ( client , data ) { super ( client ) ; this . entityKey = data . entity ; this . keyspace = data . keyspace ; this . storage = data . storage ; this . policy = data . policy ?? 'global' ; } async delete ( key , options ? ) { return this . client . internals . cache . delete < string > ( this . keyspace , this . storage , key , options ) ; } async filter ( predicate , options ? ) { return this . client . internals . cache . filter < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async find ( predicate , options ? ) { return this . client . internals . cache . find < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async forEach ( predicate , options ? ) { return this . client . internals . cache . forEach < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async get < T = Entity > ( key , options ? ) { return this . client . internals . cache . get < string , T > ( this . keyspace , this . storage , this . entityKey , key , options ) ; } async has ( key , options ? ) { return this . client . internals . cache . has < string > ( this . keyspace , this . storage , key , options ) ; } async map < R > ( predicate , options ? ) { return this . client . internals . cache . map < string , Entity , R > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async set ( key , value , options ? ) { await this . client . internals . cache . set < string , Entity > ( this . keyspace , this . storage , this . entityKey , this . policy , key , value , options ) ; return this ; } async size ( options ? ) { return this . client . internals . cache . size ( this . keyspace , this . storage , options ) ; } async sweep ( predicate , options ? ) { return this . client . internals . cache . sweep < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async clear ( options ? ) { return this . client . internals . cache . clear ( this . keyspace , this . storage , options ) ; } async count ( predicate , options ? ) { return this . client . internals . cache . count < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicate , options ) ; } async counts ( predicates , options ? ) { return this . client . internals . cache . counts < string , Entity > ( this . keyspace , this . storage , this . entityKey , predicates , options ) ; } }