import * as Rx from "rxjs"; import { Snowflake } from "../../types"; import { WatchOp } from "../resources"; export interface CacheStore { size: () => Promise; sizeForParent: (parentId: Snowflake) => Promise; get: (resourceId: string) => Promise; getSync?: (resourceId: string) => T | undefined; getForParent: (parentId: Snowflake) => Promise>; set: (parentId: Snowflake, resourceId: string, resource: T) => Promise; delete: (parentId: Snowflake, resourceId: string) => Promise; parentDelete: (parentId: Snowflake) => Promise; effects$?: Rx.Observable; } export interface CacheStoreWithTTL extends CacheStore { refreshTTL: (resourceId: string) => Promise; } export interface NonParentCacheStore { size: () => Promise; get: (resourceId: string) => Promise; getSync?: (resourceId: string) => T | undefined; set: (resourceId: string, resource: T) => Promise; delete: (resourceId: string) => Promise; effects$?: Rx.Observable; } export interface NonParentCacheStoreWithTTL extends NonParentCacheStore { refreshTTL: (resourceId: string) => Promise; } export type AnyCacheStore = CacheStore | CacheStoreWithTTL; export type AnyNonParentStore = NonParentCacheStore | NonParentCacheStoreWithTTL; type FallbackFn = (id: Snowflake) => Promise; export type NonParentGetOrFn = (fn: FallbackFn) => FallbackFn; export type GetOrFn = (fn: FallbackFn, parentId: (item: T) => Snowflake) => FallbackFn; export type GetForParentOrFn = (fn: FallbackFn, id: (item: T) => string) => FallbackFn>; export interface CacheStoreHelpers { watch$: Rx.Observable>; getOr: GetOrFn; getForParentOr: GetForParentOrFn; } export interface NonParentCacheStoreHelpers { watch$: Rx.Observable>; getOr: NonParentGetOrFn; } export type CacheStoreWithHelpers = CacheStore & CacheStoreHelpers; export type TTLCacheStoreWithHelpers = CacheStoreWithTTL & CacheStoreHelpers; export type NonParentCacheStoreWithHelpers = NonParentCacheStore & NonParentCacheStoreHelpers; export type TTLNonParentCacheStoreWithHelpers = NonParentCacheStoreWithTTL & NonParentCacheStoreHelpers; export type CacheStoreFactory = = CacheStore>(store?: S) => readonly [S & CacheStoreHelpers, Rx.Observable]; export type NonParentCacheStoreFactory = = NonParentCacheStore>(store?: S) => readonly [S & NonParentCacheStoreHelpers, Rx.Observable]; export declare const addHelpers: >(store: S) => S & CacheStoreHelpers; export declare const addNonParentHelpers: >(store: S) => S & NonParentCacheStoreHelpers; export declare const fromWatch: (watch$: Rx.Observable>) => CacheStoreFactory; export declare const fromWatchNonParent: (watch$: Rx.Observable>) => NonParentCacheStoreFactory; type WithCachesResult; }> = { [K in keyof M]: M[K] extends WithCachesFn ? V : never; }; type WithCachesFn = (guildId: Snowflake) => Promise; export declare const withCaches: ; }>(stores: M) => (getParentId: (resource: T) => Snowflake | undefined) => (source$: Rx.Observable) => Rx.Observable | undefined]>; export declare const onlyWithCacheResults: () => (source$: Rx.Observable) => Rx.Observable; export {};