import type { SimpleCacheSync } from '../../domain.objects/SimpleCache'; import { hasForInputProperty, WithExtendableCacheTrigger } from '../../domain.operations/options/shared'; import { type WithSimpleCacheOptions } from './withSimpleCache'; export { hasForInputProperty, WithExtendableCacheTrigger }; /** * the shape of logic that was wrapped with extendable cache for a sync cache */ export interface LogicWithExtendableCache< /** * the logic we are adding cache for */ L extends (...args: any) => any, /** * the type of cache being used */ C extends SimpleCacheSync> { /** * 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; }) => void; /** * 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: ReturnType | ((args: { fromCachedOutput: ReturnType | undefined; }) => ReturnType); } | { /** * update the cache for this string */ forKey: string; /** * update the cache to this value */ toValue: ReturnType | ((args: { fromCachedOutput: ReturnType | undefined; }) => ReturnType); /** * the cache to use, if the cache must be was defined from input parameters at runtime */ cache?: C; }) => void; } /** * 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 withExtendableCache: any, C extends SimpleCacheSync>(logic: L, options: WithSimpleCacheOptions) => LogicWithExtendableCache;