import { ExtendedVersion, VersionRange } from '../../../base/lib/exver'; import * as T from '../../../base/lib/types'; import { InitScript, UninitScript } from '../../../base/lib/inits'; import { VersionInfo } from './VersionInfo'; /** * Read the current data version from the effects system. * @param effects - The effects context * @returns The parsed ExtendedVersion or VersionRange, or null if no version is set */ export declare function getDataVersion(effects: T.Effects): Promise; /** * Persist a data version to the effects system. * @param effects - The effects context * @param version - The version to set, or null to clear it */ export declare function setDataVersion(effects: T.Effects, version: ExtendedVersion | VersionRange | null): Promise; /** * Check whether two version specifiers overlap (i.e. share at least one common version). * Works with any combination of ExtendedVersion and VersionRange. * * @param a - First version or range * @param b - Second version or range * @returns True if the two specifiers overlap */ export declare function overlaps(a: ExtendedVersion | VersionRange, b: ExtendedVersion | VersionRange): boolean; /** * A directed graph of service versions and their migration paths. * * Builds a graph from {@link VersionInfo} definitions, then uses shortest-path * search to find and execute migration sequences between any two versions. * Implements both {@link InitScript} (for install/update migrations) and * {@link UninitScript} (for uninstall/downgrade migrations). * * @typeParam CurrentVersion - The string literal type of the current service version */ export declare class VersionGraph implements InitScript, UninitScript { readonly current: VersionInfo; protected initFn: (effects: T.Effects) => Promise; protected uninitFn: (effects: T.Effects, target: VersionRange | ExtendedVersion | null) => Promise; private readonly graph; /** Dump the version graph as a human-readable string for debugging */ dump(): string; private constructor(); currentVersion: () => ExtendedVersion; /** * Each exported `VersionInfo.of()` should be imported and provided as an argument to this function. * * ** The current version must be the FIRST argument. ** */ static of>>(options: { current: VersionInfo; other: OtherVersions; }): VersionGraph; /** * Execute the shortest migration path between two versions. * * Finds the shortest path in the version graph from `from` to `to`, * executes each migration step in order, and updates the data version after each step. * * @param options.effects - The effects context * @param options.from - The source version or range * @param options.to - The target version or range * @returns The final data version after migration * @throws If no migration path exists between the two versions */ migrate({ effects, from, to, }: { effects: T.Effects; from: ExtendedVersion | VersionRange; to: ExtendedVersion | VersionRange; }): Promise; /** * Compute the version range from which the current version can be reached via migration. * Uses reverse breadth-first search from the current version vertex. */ canMigrateFrom: () => VersionRange; /** * Compute the version range that the current version can migrate to. * Uses forward breadth-first search from the current version vertex. */ canMigrateTo: () => VersionRange; /** * InitScript implementation: migrate from the stored data version to the current version. * If no data version exists (fresh install), sets it to the current version. * @param effects - The effects context */ init(effects: T.Effects): Promise; /** * UninitScript implementation: migrate from the current data version to the target version. * Used during uninstall or downgrade to prepare data for the target version. * * @param effects - The effects context * @param target - The target version to migrate to, or null to clear the data version */ uninit(effects: T.Effects, target: VersionRange | ExtendedVersion | null): Promise; } export type EnsureUniqueId = B extends [] ? A : B extends [VersionInfo, ...infer Rest] ? (Version extends OtherVersions ? "One or more versions are not unique"[] : EnsureUniqueId) : "There exists a migration that is not a Migration"[];