/* eslint-disable */ /** * This file was automatically generated by scripts/manifest/migrate-ts.mustache. * DO NOT MODIFY IT BY HAND. Instead, modify scripts/manifest/migrate-ts.mustache, * and run node ./scripts/manifest/generateFormatTypes.js to regenerate this file. */ import { AnyDocsManifest, DocsManifest, DocsManifestFormats, } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; import { ILogger } from "@polywrap/logging-js"; export function migrateDocsManifest( manifest: AnyDocsManifest, to: DocsManifestFormats, logger?: ILogger ): DocsManifest { let from = manifest.format as DocsManifestFormats; if (!(Object.values(DocsManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized DocsManifestFormat "${manifest.format}"`); } if (!(Object.values(DocsManifestFormats).some(x => x === to))) { throw new Error(`Unrecognized DocsManifestFormat "${to}"`); } const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( `Migration path from DocsManifestFormat "${from}" to "${to}" is not available` ); } let newManifest = manifest; for(const migrator of migrationPath){ newManifest = migrator.migrate(newManifest, logger) as AnyDocsManifest; } return newManifest as DocsManifest; }