/** * The following code is modified based on * https://github.com/webpack/webpack/blob/4b4ca3b/lib/CacheFacade.js * * MIT Licensed * Author Tobias Koppers @sokra * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ import type { Cache, CallbackCache, Etag } from './Cache.js'; import type { HashableObject, HashConstructor } from './cache/getLazyHashedEtag.js'; import type WebpackError from './WebpackError.js'; type CallbackNormalErrorCache = (err?: WebpackError | null, result?: T) => void; declare abstract class BaseCache { abstract get(callback: CallbackCache): void; abstract getPromise(): Promise; abstract store(data: T, callback: CallbackCache): void; abstract storePromise(data: T): Promise; } export declare class ItemCacheFacade implements BaseCache { _cache: Cache; _name: string; _etag: Etag | null; /** * @param cache the root cache * @param name the child cache item name * @param etag the etag * @returns */ constructor(cache: Cache, name: string, etag: Etag | null); /** * @param callback signals when the value is retrieved * @returns */ get(callback: CallbackCache): void; /** * @returns promise with the data */ getPromise(): Promise; /** * @param data the value to store * @param callback signals when the value is stored * @returns */ store(data: T, callback: CallbackCache): void; /** * @param data the value to store * @returns promise signals when the value is stored */ storePromise(data: T): Promise; /** * @param computer function to compute the value if not cached * @param callback signals when the value is retrieved * @returns */ provide(computer: (callback: CallbackNormalErrorCache) => void, callback: CallbackNormalErrorCache): void; /** * @param computer function to compute the value if not cached * @returns promise with the data */ providePromise(computer: () => Promise | T): Promise; } export declare class CacheFacade { _name: string; _cache: Cache; _hashFunction: string | HashConstructor; /** * @param cache the root cache * @param name the child cache name * @param hashFunction the hash function to use */ constructor(cache: Cache, name: string, hashFunction: string | HashConstructor); /** * @param name the child cache name# * @returns child cache */ getChildCache(name: string): CacheFacade; /** * @param identifier the cache identifier * @param etag the etag * @returns item cache */ getItemCache(identifier: string, etag: Etag | null): ItemCacheFacade; /** * @param obj an hashable object * @returns an etag that is lazy hashed */ getLazyHashedEtag(obj: HashableObject): Etag; /** * @param a an etag * @param b another etag * @returns an etag that represents both */ mergeEtags(a: Etag, b: Etag): Etag; /** * @param identifier the cache identifier * @param etag the etag * @param callback signals when the value is retrieved * @returns */ get(identifier: string, etag: Etag | null, callback: CallbackCache): void; /** * @param identifier the cache identifier * @param etag the etag * @returns promise with the data */ getPromise(identifier: string, etag: Etag | null): Promise; /** * @param identifier the cache identifier * @param etag the etag * @param data the value to store * @param callback signals when the value is stored * @returns */ store(identifier: string, etag: Etag | null, data: T, callback: CallbackCache): void; /** * @param identifier the cache identifier * @param etag the etag * @param data the value to store * @returns promise signals when the value is stored */ storePromise(identifier: string, etag: Etag | null, data: T): Promise; /** * @param identifier the cache identifier * @param etag the etag * @param computer function to compute the value if not cached * @param callback signals when the value is retrieved * @returns */ provide(identifier: string, etag: Etag | null, computer: (callback: CallbackNormalErrorCache) => void, callback: CallbackNormalErrorCache): void; /** * @param identifier the cache identifier * @param etag the etag * @param computer function to compute the value if not cached * @returns promise with the data */ providePromise(identifier: string, etag: Etag | null, computer: () => Promise | T): Promise; } export default CacheFacade;