/* 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 { AnyPluginManifest, PluginManifest, PluginManifestFormats, } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; import { ILogger } from "@polywrap/logging-js"; export function migratePluginManifest( manifest: AnyPluginManifest, to: PluginManifestFormats, logger?: ILogger ): PluginManifest { let from = manifest.format as PluginManifestFormats; if (!(Object.values(PluginManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized PluginManifestFormat "${manifest.format}"`); } if (!(Object.values(PluginManifestFormats).some(x => x === to))) { throw new Error(`Unrecognized PluginManifestFormat "${to}"`); } const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( `Migration path from PluginManifestFormat "${from}" to "${to}" is not available` ); } let newManifest = manifest; for(const migrator of migrationPath){ newManifest = migrator.migrate(newManifest, logger) as AnyPluginManifest; } return newManifest as PluginManifest; }