import type { SimpleCache } from '../../domain.objects/SimpleCache'; import { hasForInputProperty, WithExtendableCacheTrigger } from '../../domain.operations/options/shared'; import { type WithSimpleCacheAsyncOptions } from './withSimpleCacheAsync'; export { hasForInputProperty, WithExtendableCacheTrigger }; /** * the shape of logic that was wrapped with extendable cache for an async cache */ export interface LogicWithExtendableCacheAsync< /** * the logic we are wrapping with cache */ L extends (...args: any) => Promise, /** * the type of cache being used */ C extends SimpleCache> { /** * execute the logic with cache */ execute: L; /** * invalidate the cached value for a given input * * note * - applies key serialization on the key input, just like execute */ invalidate: (args: { /** * invalidate the cache for this input */ forInput: Parameters; } | { /** * invalidate the cache for this key */ forKey: string; /** * the cache to use, if the cache must be was defined from input parameters at runtime */ cache?: C; }) => Promise; /** * update the cached value for a given input * * note * - applies key serialization on the key input, just like execute * - applies value serialization on the value output, just like execute */ update: (args: { /** * update the cache for this input */ forInput: Parameters; /** * update the cache to this value */ toValue: Awaited> | ((args: { fromCachedOutput: Awaited> | undefined; }) => ReturnType | Awaited>); } | { /** * update the cache for this string */ forKey: string; /** * update the cache to this value */ toValue: Awaited> | ((args: { fromCachedOutput: Awaited> | undefined; }) => ReturnType | Awaited>); /** * the cache to use, if the cache must be was defined from input parameters at runtime */ cache?: C; }) => Promise; } /** * exposes the cache-wrapped method along with some primitives which enable extending the cache logic * * specifically * - exposes a way to `invalidate` the cache, for a given input (e.g., to support external triggers for invalidation) * - exposes a way to `update` the cache, for a given input (e.g., to support write-through cache and optimistic cache) * * relevance * - when wrapping logic to cache the user is able to specify several cache options (e.g., key serialization method, value serialization method, etc) * - in order to define their own `invalidation` and `update` methods, without this function, the user would need to access these cache options per function elsewhere * - this function makes it easy to utilize and extend cache invalidation + update commands for the wrapped logic, by managing the references to the cache options on behalf of the user */ export declare const withExtendableCacheAsync: Promise, C extends SimpleCache>(logic: L, options: WithSimpleCacheAsyncOptions) => LogicWithExtendableCacheAsync;