import type { Result } from '@expo/results'; import type { IEntityClass } from './Entity.ts'; import type { EntityConstructionUtils } from './EntityConstructionUtils.ts'; import type { EntityPrivacyPolicy } from './EntityPrivacyPolicy.ts'; import type { EntityQueryContext } from './EntityQueryContext.ts'; import type { ReadonlyEntity } from './ReadonlyEntity.ts'; import type { ViewerContext } from './ViewerContext.ts'; /** * An interface that knows how to load many objects from a cache by load params and invalidate * those same load params. */ export interface ISecondaryEntityCache, TLoadParams> { /** * Read-through cache function. * @param loadParamsArray - array of loadParams to load from the cache * @param fetcher - closure used to provide underlying data source objects for loadParams * @returns map from loadParams to the entity field object */ loadManyThroughAsync(loadParamsArray: readonly Readonly[], fetcher: (fetcherLoadParamsArray: readonly Readonly[]) => Promise, Readonly | null>>): Promise, Readonly | null>>; /** * Invalidate the cache for objects cached by loadParams. * * @param loadParamsArray - array of load params objects to invalidate */ invalidateManyAsync(loadParamsArray: readonly Readonly[]): Promise; } /** * A secondary cache loader allows for arbitrary cache keying for load params, which are a set of params used to load * a single entity field object. * * Note that this cache cannot be automatically invalidated like other entity caches so it must be manually invalidated * when the underlying data of a cache key could be stale. * * This is most commonly used to further optimize hot paths that cannot make use of normal entity cache loading * due to use of a non-unique-field-based EntityLoader method like `loadManyByFieldEqualityConjunctionAsync`. */ export declare abstract class EntitySecondaryCacheLoader, TIDField extends keyof NonNullable>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields = keyof TFields> { private readonly secondaryEntityCache; private readonly constructionUtils; constructor(secondaryEntityCache: ISecondaryEntityCache, constructionUtils: EntityConstructionUtils); /** * Load many by load params objects * * @param loadParamsArray - array of loadParams to load through the cache */ loadManyAsync(loadParamsArray: readonly Readonly[]): Promise, Result | null>>; /** * Invalidate the cache for objects cached by loadParams. * * @param loadParamsArray - array of load params objects to invalidate */ invalidateManyAsync(loadParamsArray: readonly Readonly[]): Promise; /** * Load through method called to fetch objects when load params objects are not in the cache * * @param loadParamsArray - array of load params objects to load */ protected abstract fetchObjectsFromDatabaseAsync(loadParamsArray: readonly Readonly[]): Promise>, Readonly | null>>; /** * Helper to get construction utils for instantiating a EntitySecondaryCacheLoader. * * @param entityClass - the entity class for which to get construction utils for * @param viewerContext - the viewer context to use for construction utils * @param queryContext - query context to use for construction utils * @returns construction utils for the given entity class and viewer context */ static getConstructionUtilsForEntityClass, TIDField extends keyof NonNullable>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields = keyof TFields>(entityClass: IEntityClass, viewerContext: TViewerContext, queryContext?: EntityQueryContext): EntityConstructionUtils; }