UNPKG

@atlasrender/render-plugin

Version:

Atlas Render Farm Manager plugin system.

66 lines 2.45 kB
"use strict"; /* * Copyright (c) 2020. This code created and belongs to Pathfinder render manager project. * Owner and project architect: Danil Andreev | danssg08@gmail.com | https://github.com/DanilAndreev * File creator: Danil Andreev * Project: atlas-render-plugin * File last modified: 11/12/20, 5:23 PM * All rights reserved. */ Object.defineProperty(exports, "__esModule", { value: true }); const PluginSetting_1 = require("./PluginSetting"); const ValidationError_1 = require("../errors/ValidationError"); const index_1 = require("./index"); /** * GroupField - class, designed to create plugin setting groups. * @class * @author Danil Andreev */ class GroupField extends PluginSetting_1.default { /** * Creates an instance of GroupField. * @param setting - Object with payload to construct entity. * @throws ValidationError * @author Danil Andreev */ constructor(setting) { super("group", setting); if (!Array.isArray(setting.nested)) this.validation.reject("nested", "array", { got: typeof setting.default }); this.nested = []; try { this.nested = new index_1.PluginSettingsSpec(setting.nested); } catch (error) { if (!(error instanceof ValidationError_1.default)) throw error; this.validation.reject("nested", "array", { nested: error.getNested() }); } } validatePayload(payload) { const validationError = new ValidationError_1.default("Incorrect payload.", undefined, { id: this.id }); if (typeof payload !== "object") throw validationError.failValidation(); const interpreted = this.nested.reduce((result, token) => { try { result[token.name] = token.validatePayload(payload[token.name]); } catch (error) { if (!(error instanceof ValidationError_1.default)) throw error; validationError.addNested(error); } finally { return result; } }, {}); if (validationError.hasErrors()) throw validationError; return interpreted; } getJSON() { return Object.assign(Object.assign({}, super.getJSON()), { nested: this.nested.map(item => item.getJSON()) }); } } exports.default = GroupField; //# sourceMappingURL=GroupField.js.map