/* eslint-disable */ /** * This file was automatically generated by scripts/manifest/deserialize-ts.mustache. * DO NOT MODIFY IT BY HAND. Instead, modify scripts/manifest/deserialize-ts.mustache, * and run node ./scripts/manifest/generateFormatTypes.js to regenerate this file. */ import { PolywrapManifest, AnyPolywrapManifest, migratePolywrapManifest, validatePolywrapManifest, latestPolywrapManifestFormat, } from "."; import { DeserializeManifestOptions } from "../../"; import * as Semver from "semver"; import YAML from "yaml"; export function deserializePolywrapManifest( manifest: string, options?: DeserializeManifestOptions ): PolywrapManifest { let anyPolywrapManifest: AnyPolywrapManifest | undefined; try { anyPolywrapManifest = JSON.parse(manifest) as AnyPolywrapManifest; } catch (_) { try { anyPolywrapManifest = YAML.parse(manifest) as AnyPolywrapManifest; } catch (_) { } } if (!anyPolywrapManifest) { throw Error(`Unable to parse PolywrapManifest: ${manifest}`); } if (!options || !options.noValidate) { validatePolywrapManifest(anyPolywrapManifest, options?.extSchema); } anyPolywrapManifest.__type = "PolywrapManifest"; const versionCompare = Semver.compare( Semver.coerce(anyPolywrapManifest.format) || anyPolywrapManifest.format, Semver.coerce(latestPolywrapManifestFormat) || latestPolywrapManifestFormat ); if (versionCompare === -1) { // Warn user to migrate their manifest options?.logger?.warn(`PolywrapManifest is using an older version of the manifest format (${anyPolywrapManifest.format}). Please update your manifest to the latest version (${latestPolywrapManifestFormat}) by using the "polywrap manifest migrate " command.`); // Upgrade return migratePolywrapManifest(anyPolywrapManifest, latestPolywrapManifestFormat, options?.logger); } else if (versionCompare === 1) { // Downgrade throw Error( `Cannot downgrade Polywrap version ${anyPolywrapManifest.format}, please upgrade your PolywrapClient package.` ); } else { // Latest return anyPolywrapManifest as PolywrapManifest; } }