import type { Json, ModuleFilePath, PatchId } from "@valbuild/core"; import { type ModuleContent } from "./applyChain.js"; import { type ModuleVersion } from "./version.js"; /** One module's content at one version, as a tier holds it. */ export type StoredModule = { readonly path: ModuleFilePath; readonly version: ModuleVersion; readonly content: ModuleContent; /** * The patch ids the version's chain is made of, in chain order: empty for a * base. What a newer version of the same chain is extended from, and what a * delta between two versions is made of. */ readonly patches: readonly PatchId[]; /** * What holding this costs beyond what is held anyway: the containers the * engine copied and the values the patches brought, never the base the * build holds for every visitor. Zero for the bundle's own module. */ readonly bytes: number; }; export interface ModuleTier { /** `memory`, `bundle`, `base`, `origin`: goes into counted work and test frames. */ readonly name: string; get(key: string): StoredModule | null | Promise; put?(key: string, value: StoredModule, bytes: number): void; } /** * What the stores in this process have answered, by tier, and how often * none of them had a key: a test takes it before and after. Never reset. */ export declare function storeWork(): { hits: Readonly>; misses: number; }; /** * Asks each tier in turn; what a slower tier answers is written to the faster * ones before it. A tier that answers `null` has no say. */ export declare function tiered(tiers: readonly ModuleTier[]): ModuleTier; export type MemoryTier = ModuleTier & { put(key: string, value: StoredModule, bytes: number): void; /** * The newest version held of a module, whatever its key: what the next * version of the same chain is extended from rather than replayed. */ latest(path: ModuleFilePath): StoredModule | null; /** What it holds now. */ stats(): MemoryTierStats; /** * Charge a held key for something added to it after it was put (an entry * resolved on it), so the budget sees it. */ charge(key: string, bytes: number): void; }; export type MemoryTierStats = { /** Bytes held, by the measure each value was put with. */ bytes: number; /** Versions held: values a chain made (not bases written up from a slower tier). */ versions: number; /** Modules with at least one version held. */ modules: number; /** The most versions held of any one module. */ mostVersionsOfOneModule: number; /** The most bytes held for any one module, all its versions together. */ mostBytesOfOneModule: number; /** Values let go so far, for the budget or the ring. */ evicted: number; }; /** * Bounded by bytes; keeps the last `lastPerModule` versions per module path * (and, apart from them, the last `lastPerModule` bases), and lets go of the least recently read value when over `budgetBytes`. A * value bigger than the whole budget is still held while it is the newest, * so the read that made it is answered; the next put lets it go. */ export declare function memoryTier(opts: { budgetBytes: number; lastPerModule: number; name?: string; }): MemoryTier; /** * The build's own modules, free: answers only a key whose version is the * bundle's -- its schema, its base and the empty chain -- with the bundle's * own object, which the process holds for every visitor anyway. `bundle` * says what the build evaluated each module to; `null` for a module the * build does not have. */ export declare function bundleTier(bundle: (path: ModuleFilePath) => { version: ModuleVersion; source: Json; } | null | Promise<{ version: ModuleVersion; source: Json; } | null>, name?: string): ModuleTier; /** The module a {@link moduleKey} is the address of, or `null` for none. */ export declare function pathOfModuleKey(key: string): ModuleFilePath | null; /** * The version a {@link moduleKey} names, or `null` when it is not one. The * three parts are hex or empty, so the split is unambiguous. */ export declare function parseModuleKey(key: string): { path: ModuleFilePath; version: ModuleVersion; } | null; /** * A `.jsonValues()` entry's version: the record's schema and base, the * entry's key, and the chain of the record's patches that touched THIS * entry -- so an entry no patch touched keeps its version while the record's * chain grows, and two reads at one entry version are the same content. * Entries are stored on their own, so a large record is not copied because * one entry changed. */ export type EntryVersion = ModuleVersion & { key: string; }; /** The address of an entry's content. Never changes meaning. */ export declare function entryAddress(path: ModuleFilePath, v: EntryVersion): string; /** Whether two entry versions name the same content. */ export declare function sameEntryVersion(a: EntryVersion, b: EntryVersion): boolean;