/* eslint-disable */ /** * This file was automatically generated by scripts/manifest/validate-ts.mustache. * DO NOT MODIFY IT BY HAND. Instead, modify scripts/manifest/validate-ts.mustache, * and run node ./scripts/manifest/generateFormatTypes.js to regenerate this file. */ import { AnyPolywrapWorkflow, PolywrapWorkflowFormats } from "."; import PolywrapWorkflowSchema_0_1_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.test/0.1.0.json"; import PolywrapWorkflowSchema_0_2_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.test/0.2.0.json"; import { Schema, Validator, ValidationError, ValidatorResult } from "jsonschema"; type PolywrapWorkflowSchemas = { [key in PolywrapWorkflowFormats]: Schema | undefined }; const schemas: PolywrapWorkflowSchemas = { // NOTE: Patch fix for backwards compatability "0.1": PolywrapWorkflowSchema_0_1_0, "0.1.0": PolywrapWorkflowSchema_0_1_0, "0.2.0": PolywrapWorkflowSchema_0_2_0, }; const validator = new Validator(); export function validatePolywrapWorkflow( manifest: AnyPolywrapWorkflow, extSchema: Schema | undefined = undefined ): void { const schema = schemas[manifest.format as PolywrapWorkflowFormats]; if (!schema) { throw Error(`Unrecognized PolywrapWorkflow schema format "${manifest.format}"\nmanifest: ${JSON.stringify(manifest, null, 2)}`); } const throwIfErrors = (result: ValidatorResult) => { if (result.errors.length) { throw new Error([ `Validation errors encountered while sanitizing PolywrapWorkflow format ${manifest.format}`, ...result.errors.map((error: ValidationError) => error.toString()) ].join("\n")); } }; throwIfErrors(validator.validate(manifest, schema)); if (extSchema) { throwIfErrors(validator.validate(manifest, extSchema)); } }