import { Client, Dependency, Maintainer, Package, URLBuilder, Version } from "./client.mjs"; import { Registry } from "./registry.mjs"; import { Storage } from "unstorage"; /** * Resolve the cache directory using the current platform convention. * * @returns {string} The absolute cache directory path. */ export declare function getCacheDir(): string; /** * Configure the storage backend before the first cache operation. * * @param storage - Storage backend to use. */ export declare function configureStorage(storage: Storage): void; /** * Get or create the shared storage backend. * * @returns {Storage} The configured or filesystem-backed storage. */ export declare function getStorage(): Storage; /** * Get storage scoped to one registry ecosystem. * * @param ecosystem - Registry ecosystem key. * @returns {Storage} Namespaced storage for the ecosystem. */ export declare function getEcosystemStorage(ecosystem: string): Storage; /** * Compute a SHA-256 integrity value for JSON-serializable data. * * @param value - Value to hash. * @returns {string} The prefixed hexadecimal digest. */ export declare function computeIntegrity(value: unknown): string; /** Dispose the storage instance. Call on process exit. */ export declare function disposeStorage(): Promise; /** Clear all cached data. */ export declare function clearStorage(): Promise; /** * CachedRegistry wraps any Registry and adds caching backed by unstorage * with a lockfile for freshness tracking. * * Pass a custom `storage` to use a non-default driver (e.g. Cloudflare KV). * If omitted, uses the globally configured storage (see `configureStorage()`). */ export declare class CachedRegistry extends Registry { readonly inner: Registry; readonly storage: Storage; private readonly lockfileStorage; private readonly inflight; constructor(inner: Registry, storage?: Storage); ecosystem(): string; urls(): URLBuilder; fetchPackage(name: string, signal?: AbortSignal): Promise; fetchVersions(name: string, signal?: AbortSignal): Promise; fetchDependencies(name: string, version: string, signal?: AbortSignal): Promise; fetchMaintainers(name: string, signal?: AbortSignal): Promise; /** * Read a fresh cached value or fetch and persist its replacement. * * @param name - Package name. * @param type - Cached data type. * @param version - Package version when the cache entry is versioned. * @param fetcher - Upstream operation used after a cache miss. * @param signal - Optional cancellation signal. * @param extraMeta - Optional lockfile metadata derived from the fetched value. * @returns {Promise} The cached or freshly fetched value. */ private cached; } /** Default TTL per data type (seconds). */ export declare const DEFAULT_TTL: { readonly package: 3600; readonly versions: 1800; readonly dependencies: 86400; readonly maintainers: 86400; }; export type EntryType = keyof typeof DEFAULT_TTL; /** A single cached entry tracked in the lockfile. */ export interface LockfileEntry { /** PURL-style key: 'npm:lodash', 'cargo:serde' */ key: string; /** What kind of data: package, versions, dependencies, maintainers */ type: EntryType; /** Unix timestamp (ms) when fetched */ fetchedAt: number; /** TTL in seconds */ ttl: number; /** Latest version at time of caching (for package entries) */ latestVersion?: string; /** Content hash (sha256 of JSON-serialized value) for integrity */ integrity: string; } /** The full lockfile structure. */ export interface Lockfile { version: number; entries: Record; } /** * Read the lockfile, falling back to an empty valid structure. * * @param storage - Optional storage backend. * @returns {Promise} The stored or empty lockfile. */ export declare function readLockfile(storage?: Storage): Promise; /** * Persist the lockfile. * * @param lockfile - Lockfile to persist. * @param storage - Optional storage backend. */ export declare function writeLockfile(lockfile: Lockfile, storage?: Storage): Promise; /** * Build a stable cache key. * * @param ecosystem - Registry ecosystem. * @param name - Package name. * @param type - Cached data type. * @param version - Optional package version. * @returns {string} The cache key. */ export declare function cacheKey(ecosystem: string, name: string, type: EntryType, version?: string): string; /** * Check whether a lockfile entry is fresh. * * @param entry - Entry to inspect. * @returns {boolean} Whether the entry is still valid. */ export declare function isFresh(entry: LockfileEntry): boolean; /** * Read a fresh lockfile entry. * * @param lockfile - Lockfile to inspect. * @param key - Cache key. * @returns {LockfileEntry | null} The fresh entry, or null. */ export declare function getFreshEntry(lockfile: Lockfile, key: string): LockfileEntry | null; /** * Upsert an in-memory lockfile entry without persisting it. * * @param lockfile - Lockfile to mutate. * @param entry - Entry to store. */ export declare function setEntry(lockfile: Lockfile, entry: LockfileEntry): void; /** * Remove an in-memory lockfile entry. * * @param lockfile - Lockfile to mutate. * @param key - Cache key to remove. */ export declare function removeEntry(lockfile: Lockfile, key: string): void; /** * Remove every stale in-memory entry. * * @param lockfile - Lockfile to prune. * @returns {number} The number of removed entries. */ export declare function pruneStale(lockfile: Lockfile): number; /** Options for creating a cached registry. */ export interface CreateCachedOptions { /** Custom base URL for the registry API. */ baseURL?: string; /** Custom HTTP client. */ client?: Client; /** Custom unstorage instance. Overrides the globally configured storage. */ storage?: Storage; } /** * Create a registry with cache and lockfile tracking. * * @param ecosystem - Registry ecosystem key. * @param options - Optional registry, client, and storage overrides. * @returns {Promise} A cached registry instance. */ export declare function createCached(ecosystem: string, options?: CreateCachedOptions): Promise; //# sourceMappingURL=index2.d.mts.map