UNPKG

@nosana/schema-validator

Version:
254 lines (249 loc) 10 kB
'use strict'; var AJV = require('ajv'); var yaml = require('yaml'); const NosPipelineSchema = { type: "object", properties: { global: { type: "object", nullable: false, properties: { trigger: { type: "object", nullable: true, properties: { branch: { type: ["array", "string"], items: { type: "string" }, nullable: true, uniqueItems: true, }, }, }, secrets: { type: "array", items: { type: "string" }, nullable: true, uniqueItems: true, }, environment: { anyOf: [ { type: "object", nullable: true, additionalProperties: { type: "string" }, }, { type: "object", nullable: true, properties: { type: { type: "string", nullable: false, }, endpoint: { type: "string", nullable: false, }, value: { type: "string", nullable: false, }, }, }, ], }, allow_failure: { type: "boolean", nullable: true, }, }, }, jobs: { type: "array", nullable: false, items: { type: "object", nullable: false, properties: { name: { type: "string", nullable: false, }, image: { type: "string", nullable: true, minLength: 1, maxLength: 4096, }, secrets: { type: "array", items: { type: "string" }, nullable: true, uniqueItems: true, }, environment: { anyOf: [ { type: "object", nullable: true, additionalProperties: { type: "string" }, }, { type: "object", nullable: true, properties: { type: { type: "string", nullable: false, }, endpoint: { type: "string", nullable: false, }, value: { type: "string", nullable: false, }, }, }, ], }, allow_failure: { type: "boolean", nullable: true, }, resources: { type: "array", nullable: true, items: { type: "object", nullable: true, properties: { name: { type: "string", nullable: false, }, path: { type: "string", nullable: true, }, }, }, }, artifacts: { type: "array", nullable: true, items: { type: "object", nullable: true, properties: { name: { type: "string", nullable: false, }, path: { type: "string", nullable: true, }, }, }, }, commands: { type: "array", nullable: false, additionalItems: false, items: { anyOf: [ { type: "string", nullable: false, }, { type: "object", nullable: false, properties: { cmd: { type: "string", nullable: false, }, working_dir: { type: "string", nullable: true, }, allow_failure: { type: "boolean", nullable: true, }, resources: { type: "array", nullable: true, items: { type: "object", nullable: true, properties: { name: { type: "string", nullable: false, }, path: { type: "string", nullable: true, }, }, }, }, artifacts: { type: "array", nullable: true, items: { type: "object", nullable: true, properties: { name: { type: "string", nullable: false, }, path: { type: "string", nullable: false, }, }, }, }, }, }, ], }, }, }, }, }, }, required: ["global", "jobs"], additionalProperties: false, }; const ajv = new AJV({ allErrors: true, verbose: true, allowUnionTypes: true, strict: false, }); const validateJson = (schema) => { const parsed = JSON.parse(schema); const validate = ajv.compile(NosPipelineSchema); const valid = validate(parsed); return { valid, ...validate }; }; const validateYaml = (yaml$1) => validateJson(JSON.stringify(yaml.parse(yaml$1))); Object.defineProperty(exports, 'parseYaml', { enumerable: true, get: function () { return yaml.parse; } }); Object.defineProperty(exports, 'stringifyYaml', { enumerable: true, get: function () { return yaml.stringify; } }); exports.NosPipelineSchema = NosPipelineSchema; exports.validateJson = validateJson; exports.validateYaml = validateYaml;