UNPKG

@nosana/schema-validator

Version:
1 lines 2.59 kB
"use strict";var AJV=require("ajv"),yaml=require("yaml");const NosPipelineSchema={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},ajv=new AJV({allErrors:!0,verbose:!0,allowUnionTypes:!0,strict:!1}),validateJson=e=>{const l=JSON.parse(e),t=ajv.compile(NosPipelineSchema);return{valid:t(l),...t}},validateYaml=e=>validateJson(JSON.stringify(yaml.parse(e)));Object.defineProperty(exports,"parseYaml",{enumerable:!0,get:function(){return yaml.parse}}),Object.defineProperty(exports,"stringifyYaml",{enumerable:!0,get:function(){return yaml.stringify}}),exports.NosPipelineSchema=NosPipelineSchema,exports.validateJson=validateJson,exports.validateYaml=validateYaml;