@atlasrender/render-plugin
Version:
Atlas Render Farm Manager plugin system.
108 lines • 4.12 kB
JavaScript
;
/*
* 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: 15.11.2020, 15:02
* All rights reserved.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const ValidationError_1 = require("../errors/ValidationError");
const index_1 = require("./index");
/**
* PluginSettingsSpec - class for constructing plugin settings system.
* @class
* @author Danil Andreev
*/
class PluginSettingsSpec extends Array {
/**
* Creates an instance of PluginSettingsSpec
* @param settings - Input object structure to process.
* @constructor
* @author Danil Andreev
*/
constructor(settings) {
if (!Array.isArray(settings)) {
throw new ValidationError_1.default("Fatal: Invalid type of input", undefined, { isFatal: true });
}
super();
const errors = [];
for (const setting of settings) {
try {
const result = this.buildSetting(setting);
if (!result.isValid())
throw result.getValidation();
if (this.find((item) => item.name === result.name))
throw new ValidationError_1.default(`Field with name "${result.name}" already exists in this structure.`, undefined, { isFatal: true });
super.push(result);
}
catch (error) {
if (!(error instanceof ValidationError_1.default))
throw error;
errors.push(error);
}
}
if (errors.length)
throw new ValidationError_1.default("Validation error on input object.").addNested(errors);
}
/**
* buildSetting - method, designed to build and validate plugin settings structure.
* @param setting
* @method
* @author Danil Andreev
*/
buildSetting(setting) {
if (typeof setting !== "object" || typeof setting.type !== "string")
throw new ValidationError_1.default("Fatal: Invalid type of input.", undefined, { isFatal: true });
switch (setting.type) {
case "float":
return new index_1.FloatField(setting);
case "integer":
return new index_1.IntegerField(setting);
case "string":
return new index_1.StringField(setting);
case "boolean":
return new index_1.BooleanField(setting);
case "group":
return new index_1.GroupField(setting);
case "separator":
return new index_1.SeparatorField(setting);
default:
throw new ValidationError_1.default("Fatal: invalid type on one of tokens.", undefined, { isFatal: true });
}
}
map(callback, thisArg) {
const newArray = [...this];
return newArray.map(callback);
}
filter(predicate, thisArg) {
const newArray = [...this];
return newArray.filter(predicate, thisArg);
}
slice(start, end) {
const newArray = [...this];
return newArray.slice(start, end);
}
concat(...items) {
const newArray = [...this].concat(...items);
return new PluginSettingsSpec(newArray);
}
copyWithin(target, start, end) {
throw new Error(`This method is not allowed in PluginSettingSpec object.`);
}
fill(value, start, end) {
throw new Error(`This method is not allowed in PluginSettingSpec object.`);
}
push(...items) {
throw new Error(`This method is not allowed in PluginSettingSpec object.`);
}
splice(start, deleteCount) {
throw new Error(`This method is not allowed in PluginSettingSpec object.`);
}
unshift(...items) {
throw new Error(`This method is not allowed in PluginSettingSpec object.`);
}
}
exports.default = PluginSettingsSpec;
//# sourceMappingURL=PluginSettingsSpec.js.map