import { IPersistor, MemRedis as InMemoryPersistor } from "@sebspark/memredis";
import { add, sub } from "date-fns";
//#region src/types.d.ts
/**
* Defines the expiration strategy for cached values.
*
* - A `number` is interpreted as a TTL (time-to-live) in **milliseconds**.
* - A `Date` represents an **exact expiration timestamp**.
* - If omitted, the cache entry **never expires**.
*/
type Expiry = number | Date;
/**
* Options for caching a function's result.
* @template A - Argument types of the function.
*/
type CachingOptions = {
/**
* A fixed key or a function that generates a key based on function arguments.
*/
key: string | ((...args: A) => string);
/**
* Defines how long the cached value remains valid before expiring.
*
* - A **number** is treated as a TTL (time-to-live) in **milliseconds**.
* - A **Date** sets an **exact expiration timestamp**.
* - A **function** dynamically determines the expiration based on:
* - `args` - The function arguments.
* - `response` - The function result.
* - If omitted, the cache entry **does not expire**.
*/
expiry?: Expiry | ((args: A, response: R) => Expiry);
};
/**
* Represents a caching system that wraps asynchronous functions.
*/
type Cache = {
/**
* The underlying persistor used for caching.
*/
persistor: IPersistor;
/**
* Wraps an asynchronous function to enable caching.
* @template A - Argument types.
* @template R - Return type.
* @param {Delegate} delegate - The function to wrap.
* @param {CachingOptions} options - Caching options, including key strategy.
* @returns {Delegate} A new function that caches results.
*/
wrap(delegate: (...args: A) => R | Promise, options: CachingOptions): (...args: A) => Promise;
};
//#endregion
//#region src/cache.d.ts
/**
* Creates a cache instance using a given persistor.
* @param {IPersistor} persistor - The underlying storage for caching.
* @param {string?} prefix - An optional prefix that will be prepended to the key, formatted as `prefix:key`.
* @returns {Cache} A cache instance.
*/
declare const createCache: (persistor: IPersistor, prefix?: string) => Cache;
declare namespace serializer_d_exports {
export { deserialize, serialize };
}
declare const serialize: (data: T) => string;
declare const deserialize: (serialized: string | null) => T | null;
declare namespace time_d_exports {
export { DAY, HOUR, MINUTE, SECOND, WEEK, add, days, hours, minutes, seconds, sub, today, tomorrow, weeks };
}
declare const SECOND = 1000;
declare const MINUTE: number;
declare const HOUR: number;
declare const DAY: number;
declare const WEEK: number;
declare const seconds: (num: number) => number;
declare const minutes: (num: number) => number;
declare const hours: (num: number) => number;
declare const days: (num: number) => number;
declare const weeks: (num: number) => number;
declare const today: (hours?: number, minutes?: number, seconds?: number) => Date;
declare const tomorrow: (hours?: number, minutes?: number, seconds?: number) => Date;
//#endregion
export { type Cache, type CachingOptions, InMemoryPersistor, createCache, serializer_d_exports as serializer, time_d_exports as time };
//# sourceMappingURL=index.d.mts.map