import { type ModuleFilePath, type PatchId, type SelectorSource, type ValModule } from "@valbuild/core"; import { z } from "zod"; /** * What a module's content IS: the schema it is read and patched with, the * base it starts from, and the chain of patches on top. Three parts because * each kind of change moves exactly one of them (see * `docs/plans/one-content-model.md`, "A version, per module, with the code in * it"): * * - a schema change, or a new engine (`@valbuild/*` upgraded), moves `schema`; * - a publish, a content version, a literal edited in code, moves `base`; * - an edit, a discard, a publish (which empties the chain) moves `chain`. * * Two answers with the same version are the same content, wherever they came * from. That is the whole point: comparing contents becomes comparing three * strings. * * Computed when content CHANGES -- a module evaluated, a base adopted, a patch * appended -- never when it is read (risk 3 in the plan): every function here * that hashes counts itself ({@link versionHashCount}), so a reader that * hashes is caught by a counted budget rather than by a profile. */ export type ModuleVersion = { /** sha(engine + serialized schema): what the content is read and patched with. */ schema: string; /** sha(the module's base source): from the build, a content version or a publish. */ base: string; /** * A fold of this module's patch ids on top of `base`, in chain order: the * IDENTITY of the chain, not its order -- that is `seq`. {@link EMPTY_CHAIN} * for no patches, so a base is a version with an empty chain. */ chain: string; }; /** * What a project answer is relative to: which build served it, and how far * along the project's changes it is. */ export type ProjectVersion = { /** * The build serving it: the evaluated modules (schemas, sources and config) * it started from, so two processes running the same code agree. Hosted, * the commit or the platform's build (`publishBuild`) is part of it. */ build: string; /** * ORDER only: bumped by every write, delete and publish, and once by each * new build. Of two answers, the one with the higher `seq` is newer. In * http mode it is the content service's `headVersion`. */ seq: number; }; /** * What the schema version of a module staged after the build serving a * proposal starts with: `staged:`. Val's server has not got that * module's schema, so it names the staging instead; a Studio compares no * build's code against it. */ export declare const STAGED_SCHEMA_PREFIX = "staged:"; /** The chain of no patches. */ export declare const EMPTY_CHAIN = ""; /** * The engine: how patches are applied and content is read. Part of every * schema version, because content read by another engine is not the same * content even under the same schema. */ export declare const ENGINE: string; /** * How many times a version has been hashed in this process: the counted * budget behind "versions are computed when content changes, never when it * is read" (`version:hash`). A test takes it before and after a read. */ export declare function versionHashCount(): number; /** A chain one patch longer. */ export declare function extendChain(prev: string, id: PatchId): string; /** The chain of these patch ids, in order, on top of a base. */ export declare function chainOf(ids: readonly PatchId[]): string; /** * A module's schema version, from its serialized schema. The same function * on the server (from what `extractValModules` serialized) and in the Studio * (from what it holds in `SchemaStore`), so the two compare. */ export declare function schemaVersionOf(serializedSchema: unknown): string; /** * The version of the schema a reader's own code has for a module: what the * readers hold relayed or drafted content's version against (`layered`'s * schema rule), so content is never read with a schema it was not made for. * The server readers (`fetchVal`) and the page's hooks (`useVal`) alike. * Hashed once per module object, which a build makes once: a load cost, not * a read cost. */ export declare function readerSchemaVersion(module: ValModule): string | null; /** * A module's base version, from its base source: what the module evaluates * to, or what a content version or a publish put in its place. `.jsonValues()` * entries are markers here; an entry's own version comes with entries stored * as modules of their own (phase 6). */ export declare function baseVersionOf(source: unknown): string; /** The address of a module's content. Never changes meaning. */ export declare function moduleKey(path: ModuleFilePath, v: ModuleVersion): string; /** Whether two versions name the same content. */ export declare function sameModuleVersion(a: ModuleVersion, b: ModuleVersion): boolean; /** * The chains of every module, from the patches a draft applies (in chain * order), folded incrementally. * * A read asks for the chains every time; the fold is extended only by the * patches the chain has gained since the last call, and a call that finds the * chain as it was hashes nothing. A chain that changed anywhere but at its end * (a discard in the middle, a publish) is folded again from the start -- * once, when that is first noticed. */ export declare class ChainFold { private ids; private paths; private chains; /** * Every module's chain after each of its patches, in order: what * {@link chainAt} answers for a module whose content stopped part way * along its chain (a patch that does not apply). Kept as the chains are * extended, so asking hashes nothing. */ private prefixes; /** * Bumped whenever the chains move: a cheap identity for "the same chains as * before", in-process. With {@link instance} in front, two folds never name * one epoch: two processes (or isolates) holding the same chains answer * differently, which only costs a cache a miss, where two holding * DIFFERENT chains at the same count must never answer alike (an ETag * answered 304 for content the caller does not have). */ private epochValue; private readonly instance; /** Every module's chain, for these patches. Modules with none are absent. */ chainsOf(patches: readonly { patchId: PatchId; path: ModuleFilePath; }[]): ReadonlyMap; /** * A module's chain after its first `count` patches, of those the last * {@link chainsOf} was given: the version of content that stopped at a * patch that does not apply, so the version names the chain the content * is AT. Hashes nothing. */ chainAt(path: ModuleFilePath, count: number): string; /** See {@link epochValue}. */ epoch(): string; } /** {@link ModuleVersion} on the wire. */ export declare const ModuleVersionSchema: z.ZodObject<{ schema: z.ZodString; base: z.ZodString; chain: z.ZodString; }, z.core.$strip>; /** {@link ProjectVersion} on the wire. */ export declare const ProjectVersionSchema: z.ZodObject<{ build: z.ZodString; seq: z.ZodNumber; }, z.core.$strip>;