@nosana/schema-validator
Version:
To install dependencies:
1 lines • 2.33 kB
JavaScript
import e from"ajv";import{parse as l}from"yaml";export{parse as parseYaml,stringify as stringifyYaml}from"yaml";const t={type:"object",properties:{global:{type:"object",nullable:!1,properties:{trigger:{type:"object",nullable:!0,properties:{branch:{type:["array","string"],items:{type:"string"},nullable:!0,uniqueItems:!0}}},secrets:{type:"array",items:{type:"string"},nullable:!0,uniqueItems:!0},environment:{anyOf:[{type:"object",nullable:!0,additionalProperties:{type:"string"}},{type:"object",nullable:!0,properties:{type:{type:"string",nullable:!1},endpoint:{type:"string",nullable:!1},value:{type:"string",nullable:!1}}}]},allow_failure:{type:"boolean",nullable:!0}}},jobs:{type:"array",nullable:!1,items:{type:"object",nullable:!1,properties:{name:{type:"string",nullable:!1},image:{type:"string",nullable:!0,minLength:1,maxLength:4096},secrets:{type:"array",items:{type:"string"},nullable:!0,uniqueItems:!0},environment:{anyOf:[{type:"object",nullable:!0,additionalProperties:{type:"string"}},{type:"object",nullable:!0,properties:{type:{type:"string",nullable:!1},endpoint:{type:"string",nullable:!1},value:{type:"string",nullable:!1}}}]},allow_failure:{type:"boolean",nullable:!0},resources:{type:"array",nullable:!0,items:{type:"object",nullable:!0,properties:{name:{type:"string",nullable:!1},path:{type:"string",nullable:!0}}}},artifacts:{type:"array",nullable:!0,items:{type:"object",nullable:!0,properties:{name:{type:"string",nullable:!1},path:{type:"string",nullable:!0}}}},commands:{type:"array",nullable:!1,additionalItems:!1,items:{anyOf:[{type:"string",nullable:!1},{type:"object",nullable:!1,properties:{cmd:{type:"string",nullable:!1},working_dir:{type:"string",nullable:!0},allow_failure:{type:"boolean",nullable:!0},resources:{type:"array",nullable:!0,items:{type:"object",nullable:!0,properties:{name:{type:"string",nullable:!1},path:{type:"string",nullable:!0}}}},artifacts:{type:"array",nullable:!0,items:{type:"object",nullable:!0,properties:{name:{type:"string",nullable:!1},path:{type:"string",nullable:!1}}}}}}]}}}}}},required:["global","jobs"],additionalProperties:!1},a=new e({allErrors:!0,verbose:!0,allowUnionTypes:!0,strict:!1}),n=e=>{const l=JSON.parse(e),n=a.compile(t);return{valid:n(l),...n}},r=e=>n(JSON.stringify(l(e)));export{t as NosPipelineSchema,n as validateJson,r as validateYaml};