import { B as Value, C as Selector, G as MaybePromise, K as Constrain, N as Path, a as StoreOptions, b as Duration, k as AnyPath, n as Calculate, r as Store } from "./store-Cq1PqvEo.js"; //#region src/lib/cacheState.d.ts type ValueState = { status: "value"; value: T; error?: undefined; }; type ErrorState = { status: "error"; value?: undefined; error: unknown; }; type PendingState = { status: "pending"; value?: undefined; error?: undefined; }; type CacheState = (ValueState | ErrorState | PendingState) & { isStale: boolean; isUpdating: boolean; isConnected: boolean; }; //#endregion //#region src/core/resourceGroup.d.ts interface Resource { invalidateAll(): void; clearAll(): void; } declare class ResourceGroup { readonly name?: string | undefined; private refMap; private refSet; private timer; private registry; constructor(name?: string | undefined); add(resource: Resource): void; delete(resource: Resource): void; invalidateAll(): void; clearAll(): void; cleanup(): void; stop(): void; } declare const allResources: ResourceGroup; declare function createResourceGroup(name?: string): ResourceGroup; //#endregion //#region src/core/cache.d.ts interface CacheGetOptions { /** * How to handle the cache when getting the value. * - `whenMissing`: Only fetch a new value if there is no cached value. * - `whenStale`: Fetch a new value if there is no cached value or if the cached value is stale. * - `force`: Always fetch a new value, regardless of the cache state. */ update?: "whenMissing" | "whenStale" | "force"; /** * If set to `true`, the cache will be updated in the background. * This means that a stale value will be returned immediately, if available, while the new value is being fetched. */ backgroundUpdate?: boolean; } interface CacheFunction { (...args: Args): Promise | Calculate>; } interface CacheOptions extends StoreOptions> { /** * How long to keep the cache entry before it is considered stale. * If set to `undefined` or `null`, the cache entry will never be invalidated automatically. * * @example * ```typescript * createCache(fetchData, { * invalidateAfter: { seconds: 10 }, * }); * ``` */ invalidateAfter?: Duration | ((state: ValueState | ErrorState) => Duration | null) | null; /** * If set, the cache will be invalidated when the window gets focused. * This is useful for caches that are used in a browser environment and might become stale when the user switches tabs. */ invalidateOnWindowFocus?: boolean; /** * If set, the cache will be invalidated when it becomes active - e.g. when it is subscribed to or a component using the cache mounts. */ invalidateOnActivation?: boolean; /** * If set, the cached value will be cleared when the cache is invalidated. * Without this option, the cache will keep the last value as stale until a new value becomes available. */ clearOnInvalidate?: boolean; /** * If set, cache entries will be cleared after approximately the specified duration. * This is useful for long lived pages or applications and helps to prevent memory leaks. * The exact time when the entry is cleared is not guaranteed, since it will be cleared during garbage collection. */ clearUnusedAfter?: Duration | null; /** * Add the cache to the specified resource group(s). * This allows you to invalidate or clear multiple caches that belong to the same group. * All caches are always added to the `allResources` group. */ resourceGroup?: ResourceGroup | ResourceGroup[]; /** * Function to generate a custom cache key based on the provided arguments. * This allows you to control how cache entries are identified and reused. * By default, the arguments array is used as the cache key. * * @example * ```typescript * // Will use the same instance when provided with `undefined`, `{ num: 0 }`, `{ bool: false }`, etc. * createCache((filter?: { num?: number, bool?: boolean }) => fetchData(filter), { * getCacheKey: (filter?) => ({ * num: filter?.num ?? 0, * bool: filter?.bool ?? false, * }), * }); * ``` */ getCacheKey?: (...args: Args) => unknown; } declare class Cache extends Store> { readonly args: Args; readonly options: CacheOptions; readonly derivedFromCache?: { cache: Cache; selectors: (Selector | AnyPath)[]; } | undefined; readonly state: Store>; protected stalePromise?: Promise; protected invalidationTimer?: ReturnType; constructor(getter: Calculate>, args: Args, options?: CacheOptions, derivedFromCache?: { cache: Cache; selectors: (Selector | AnyPath)[]; } | undefined); get({ update, backgroundUpdate }?: CacheGetOptions): Promise; updateValue(value: MaybePromise | ((value: T | undefined) => T)): void; updateError(error: unknown): void; invalidate(recursive?: boolean): void; clear(recursive?: boolean): void; mapValue(selector: Selector): Cache; mapValue(selector: P extends Path ? P : Path): Cache, Args>; protected watchPromise(): void; protected setTimers(): void; protected watchFocus(): void; protected onActivation(): void; } type CreateCacheResult> = [] extends Args ? CacheBundle & TCache : CacheBundle; interface InvalidationOptions> { filter?: (cache: TCache) => boolean; } type CacheBundle> = { (...args: Args): TCache; mapCache(selector: Selector): CreateCacheResult>; mapValue(selector: Constrain>): CreateCacheResult, Args, Cache, Args>>; invalidateAll: (options?: InvalidationOptions) => void; clearAll: (options?: InvalidationOptions) => void; getInstances: () => TCache[]; }; declare function create(cacheFunction: CacheFunction, options?: NoInfer>): CreateCacheResult>; declare const createCache: typeof create & { defaultOptions: CacheOptions; }; //#endregion //#region src/core/scope.d.ts declare class Scope { readonly defaultValue: T; constructor(defaultValue: T); } declare function createScope(defaultValue: T): Scope; //#endregion export { ValueState as _, CacheFunction as a, CreateCacheResult as c, ResourceGroup as d, allResources as f, PendingState as g, ErrorState as h, CacheBundle as i, createCache as l, CacheState as m, createScope as n, CacheGetOptions as o, createResourceGroup as p, Cache as r, CacheOptions as s, Scope as t, Resource as u }; //# sourceMappingURL=scope-qdOAlRWQ.d.ts.map