import type { SerializableObject } from 'with-cache-normalization/dist/domain/NormalizeCacheValueMethod'; import type { SimpleCache } from 'with-simple-cache'; import type { LogMethod } from '../domain/constants'; import type { DomainDrivenQueryDependsOn } from '../domain/DomainDrivenQueryDependsOn'; export declare const DEFAULT_REFERENCE_SECONDS_UNTIL_EXPIRATION: number; /** * adds domain driven caching to a domain.logic.query * * features * - ✨ automatic cache updates are enabled out of the box, due to [domain.object dereferencing](../../readme.md) * - ✨ automatic cache invalidation can be easily enabled by defining what your query dependsOn, due to [dependency pointers](../../readme.md) * - 🔭 observable tracing of underlying operations can be easily enabled by passing in the logMethod you'd like operations to be reported to * * note * - ⚠️ ensure all of the domain.object relationships and identities your domain.logic.query depends on are explicitly defined via the `dependsOn` attribute, to activate automated cache invalidation */ export declare const withQueryCaching: (logic: (...args: I) => Promise, options: { /** * the cache to use */ cache: SimpleCache; /** * the logical dependencies of your domain.logic.query * * note * - the dependencies listed here drive the automatic cache invalidation ✨ * - ensure all logical dependencies are listed to prevent stale data in the cache ⚠️ * * for example * - a query called `getPaymentByUuid({ uuid }) => Payment | null` will likely have a dependency on `{ identity: { dobj: Payment, uuid: ({ input }) => input[0].uuid } }` * - a query called `getLastPaymentOfUser({ userUuid }) => Payment` will likely have a dependency on `{ relationship: { from: { dobj: User, uuid: ({ input }) => input[0].uuid }, to: { dobj: Payment }, via: { dobj: Payment, prop: 'userUuid' } }` * * tips * - you can see the dependency pointers your query will be invalidated by, by searching for logs with the message `ddcache.query.set`. if `logDebug` is set, this log will be emitted each time your query is set to the cache */ dependsOn: DomainDrivenQueryDependsOn; /** * the serialization strategy to use */ serialize?: { /** * the key serialization strategy to use * * note * - if you expect to use this with [simple-lambda-client](https://github.com/ehmpathy/simple-lambda-client), be sure to use it's `getSimpleLambdaClientCacheKey` method */ key: (...args: I) => string; }; /** * a method to define whether the the results are valid to cache * * for example * - invalidate null results from the start -> queries will hit underlying data store until result is found */ valid?: ({ input, output }: { input: I; output: O; }) => boolean; /** * a custom seconds until expiration to use for this query, if desired */ secondsUntilExpiration?: number; /** * the log method via which to report debug logs, if observability is desired 🔭 */ logDebug?: LogMethod; }) => ((...args: I) => Promise);