Skip to article
Documentation

src/programs/snap-negative/rule-versions.ts

Linked repository file from this build.

import { RuleError } from "@/lib/errors";
/** Immutable implementation identifiers. Add a dispatcher branch before publishing a new version. */
export const LEGACY_CALC_VERSION = "snap-negative-ordinary-2026-v1";
export const LEGACY_CHECK_VERSION = "snap-negative-basic-v1";
export const PREVIOUS_CALC_VERSION = "snap-negative-ordinary-2026-v2";
export const EDUCATION_CALC_VERSION = "snap-negative-ordinary-2026-v3";
export const CURRENT_CALC_VERSION = "snap-negative-ordinary-2026-v4";
export const PREVIOUS_CHECK_VERSION = "snap-negative-full-v2";
export const CURRENT_CHECK_VERSION = "snap-negative-full-v3";

const SUPPORTED_CALC_VERSIONS = new Set([
  LEGACY_CALC_VERSION,
  PREVIOUS_CALC_VERSION,
  EDUCATION_CALC_VERSION,
  CURRENT_CALC_VERSION,
]);
const SUPPORTED_CHECK_VERSIONS = new Set([
  LEGACY_CHECK_VERSION,
  PREVIOUS_CHECK_VERSION,
  CURRENT_CHECK_VERSION,
]);

export function assertCalcVersion(version: string) {
  if (!SUPPORTED_CALC_VERSIONS.has(version))
    throw new RuleError(
      `Unsupported calculation version: ${version}. Apply supported rules before calculating.`,
    );
}
export function assertCheckVersion(version: string) {
  if (!SUPPORTED_CHECK_VERSIONS.has(version))
    throw new RuleError(
      `Unsupported edit-check version: ${version}. Apply supported rules before checking.`,
    );
}

export function isLegacyCheckVersion(version: string): boolean {
  return version === LEGACY_CHECK_VERSION;
}