git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
99941cf
Branches
Tags
develop-client_server
master
typescript
fs-words.git
server
lib
plankton
shape
logic-impl.js
[upd] server:lib:plankton
Christian Fraß
commited
99941cf
at 2021-03-12 00:46:54
logic-impl.js
Blame
History
Raw
/* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ var _pool = {}; /** * @author fenris */ var _aliases = {}; /** * @author fenris */ function list() { return [].concat(Object.keys(_pool)).concat(Object.keys(_aliases)); } lib_shape.list = list; /** * @author fenris */ function inspection_create() { return { "messages": [] }; } lib_shape.inspection_create = inspection_create; /** * @author fenris */ function inspection_add(main, message) { main.messages.push(message); } lib_shape.inspection_add = inspection_add; /** * @author fenris */ function inspection_extend(main, prefix, sub) { main.messages = main.messages.concat(sub.messages.map(message => `${prefix}: ${message}`)); } lib_shape.inspection_extend = inspection_extend; /** * @author fenris * @todo check for existing */ function register({ "name": name, "make": make, "inspect": _inspect, "stance": _stance, "show": _show, }) { const entry = { "name": name, "make": make, "inspect": _inspect, "stance": _stance, "show": _show, }; _pool[name] = entry; } lib_shape.register = register; /** * @author fenris * @todo check for existing */ function define_alias({ "name": name, "target": target, }) { const entry = { "name": "alias", "target": target, }; _aliases[name] = entry; } lib_shape.define_alias = define_alias; /** * @author fenris * @todo check for existing */ /* export function inspect_jstype( inspection, jstype_expected : string, value : any ) : void { let jstype_actual : string = typeof(value); if (jstype_actual === jstype_expected) { // all good } else { inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } */ /** * @author fenris */ function make(raw) { const name = raw["name"]; if (_aliases.hasOwnProperty(name)) { const alias = _aliases[name]; return alias.target; } else { if (_pool.hasOwnProperty(name)) { const entry = _pool[name]; const parameters = entry.make(raw["parameters"] || {}, make); return { "name": name, "parameters": parameters, }; } else { const message = `no shape registered with name '${name}'`; throw (new Error(message)); } } } lib_shape.make = make; /** * @author fenris */ function inspect(shape, value) { if (_pool.hasOwnProperty(shape.name)) { const entry = _pool[shape.name]; return entry.inspect(shape.parameters, value, inspect); } else { const message = `no shape registered with name '${shape.name}'`; throw (new Error(message)); } } lib_shape.inspect = inspect; /** * @author fenris */ function check(shape, value) { if (_pool.hasOwnProperty(shape.name)) { const entry = _pool[shape.name]; const inspection = inspect(shape, value); inspection.messages .forEach((message) => { console.warn(message); }); return (inspection.messages.length === 0); } else { const message = `no shape registered with name '${shape.name}'`; throw (new Error(message)); } } lib_shape.check = check; /** * @author fenris */ function stance(shape, bindings) { if (_pool.hasOwnProperty(shape.name)) { const entry = _pool[shape.name]; return entry.stance(shape.parameters, bindings, stance); } else { const message = `no shape registered with name '${shape.name}'`; throw (new Error(message)); } } lib_shape.stance = stance; /** * @author fenris */ function show(shape) { if (_pool.hasOwnProperty(shape.name)) { const entry = _pool[shape.name]; return entry.show(shape.parameters, show); } else { const message = `no shape registered with name '${shape.name}'`; throw (new Error(message)); } } lib_shape.show = show; })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function variable_make({ "name": name }) { if (name == undefined) { let message = `mandatory parameter 'name' missing`; throw (new Error(message)); } else { return { "name": name, }; } } /** * @author fenris */ function variable_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); let message = "cannot inspect a value against a type variable"; console.warn(message + "; will just pass ..."); // throw (new Error(message)); return inspection; } /** * @author fenris */ function variable_stance(parameters, bindings, _stance) { if (parameters.name in bindings) { return bindings[parameters.name]; } else { return { "name": "variable", "parameters": parameters }; } } /** * @author fenris */ function variable_show(parameters, _show) { let str; // core { str = ("$" + parameters.name); } return str; } /** * @author fenris */ lib_shape.register({ "name": "variable", "make": variable_make, "inspect": variable_inspect, "stance": variable_stance, "show": variable_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function function_make({ "soft": soft = false, "shape_input": shape_input, "shape_output": shape_output, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_input === undefined) { let message = `mandatory parameter 'shape_input' missing`; throw (new Error(message)); } if (shape_output === undefined) { let message = `mandatory parameter 'shape_output' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : (x => x)); } return { "soft": soft, "shape_input": _make(shape_input), "shape_output": _make(shape_output), "defaultvalue": defaultvalue, }; } /** * @author fenris */ function function_stance(parameters, bindings, _stance) { return { "name": "function", "parameters": { "soft": parameters.soft, "shape_input": _stance(parameters.shape_input, bindings), "shape_output": _stance(parameters.shape_output, bindings) } }; } /** * @author fenris * @todo closer look not possible? */ function function_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "function"; if (jstype_actual === jstype_expected) { // all good? } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function function_show(parameters, _show) { let str; /* // core { str = "function"; } // in/out { str += ( "<" + [ _show(parameters.shape_input), _show(parameters.shape_output), ].join(",") + ">" ); } */ str = ""; str += ("(" + _show(parameters.shape_input) + " => " + _show(parameters.shape_output) + ")"); // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "function", "make": function_make, "inspect": function_inspect, "stance": function_stance, "show": function_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function void_make({ "soft": soft = true, }) { return { "soft": soft, }; } /** * @author fenris */ function void_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { // all good } return inspection; } /** * @author fenris */ function void_stance(parameters, bindings, _stance) { return { "name": "void", "parameters": parameters }; } /** * @author fenris */ function void_show(parameters, _show) { let str; // core { str = "void"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "void", "make": void_make, "inspect": void_inspect, "stance": void_stance, "show": void_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function any_make({ "soft": soft = true, "mutable": mutable = true, "defaultvalue": defaultvalue = null, }) { return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function any_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { // all good } return inspection; } /** * @author fenris */ function any_stance(parameters, bindings, _stance) { return { "name": "any", "parameters": parameters }; } /** * @author fenris */ function any_show(parameters, _show) { let str; // core { str = "any"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "any", "make": any_make, "inspect": any_inspect, "stance": any_stance, "show": any_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function boolean_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : false); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function boolean_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "boolean"; if (jstype_actual === jstype_expected) { // all good } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function boolean_stance(parameters, bindings, _stance) { return { "name": "boolean", "parameters": parameters }; } /** * @author fenris */ function boolean_show(parameters, _show) { let str; // core { str = "boolean"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "boolean", "make": boolean_make, "inspect": boolean_inspect, "stance": boolean_stance, "show": boolean_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function int_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "minimum": minimum = null, "maximum": maximum = null, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : 0); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, "minimum": minimum, "maximum": maximum, }; } /** * @author fenris */ function int_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "number"; if (jstype_actual === jstype_expected) { if (!isNaN(parseInt(value))) { if ((parameters.minimum === null) || (value >= parameters.minimum)) { if ((parameters.maximum === null) || (value <= parameters.maximum)) { // all good } else { lib_shape.inspection_add(inspection, `value is beyond maximum`); } } else { lib_shape.inspection_add(inspection, `value is below minimum`); } } else { lib_shape.inspection_add(inspection, `value is not parsable into a valid int`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function int_stance(parameters, bindings, _stance) { return { "name": "int", "parameters": parameters }; } /** * @author fenris */ function int_show(parameters, _show) { let str; // core { str = "int"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "int", "make": int_make, "inspect": int_inspect, "stance": int_stance, "show": int_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function float_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : 0.0); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function float_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "number"; if (jstype_actual === jstype_expected) { if (!isNaN(parseFloat(value))) { // all good } else { lib_shape.inspection_add(inspection, `value is not parsable into a valid float`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function float_stance(parameters, bindings, _stance) { return { "name": "float", "parameters": parameters }; } /** * @author fenris */ function float_show(parameters, _show) { let str; // core { str = "float"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "float", "make": float_make, "inspect": float_inspect, "stance": float_stance, "show": float_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function string_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "long": long = false, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : ""); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, "long": long, }; } /** * @author fenris */ function string_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "string"; if (jstype_actual === jstype_expected) { // all good } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function string_stance(parameters, bindings, _stance) { return { "name": "string", "parameters": parameters }; } /** * @author fenris */ function string_show(parameters, _show) { let str; // core { str = "string"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "string", "make": string_make, "inspect": string_inspect, "stance": string_stance, "show": string_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function email_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : ""); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function email_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "string"; if (jstype_actual === jstype_expected) { // all good } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function email_stance(parameters, bindings, _stance) { return { "name": "email", "parameters": parameters }; } /** * @author fenris */ function email_show(parameters, _show) { let str; // core { str = "email"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "email", "make": email_make, "inspect": email_inspect, "stance": email_stance, "show": email_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function url_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : ""); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, "type": type, }; } /** * @author fenris */ function url_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "string"; if (jstype_actual === jstype_expected) { // all good } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function url_stance(parameters, bindings, _stance) { return { "name": "url", "parameters": parameters }; } /** * @author fenris */ function url_show(parameters, _show) { let str; // core { str = "url"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "url", "make": url_make, "inspect": url_inspect, "stance": url_stance, "show": url_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function markdown_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : ""); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, "type": type, }; } /** * @author fenris */ function markdown_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "string"; if (jstype_actual === jstype_expected) { // all good } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function markdown_stance(parameters, bindings, _stance) { return { "name": "markdown", "parameters": parameters }; } /** * @author fenris */ function markdown_show(parameters, _show) { let str; // core { str = "markdown"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "markdown", "make": markdown_make, "inspect": markdown_inspect, "stance": markdown_stance, "show": markdown_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function time_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : ""); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function time_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { // all good? } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function time_stance(parameters, bindings, _stance) { return { "name": "time", "parameters": parameters }; } /** * @author fenris */ function time_show(parameters, _show) { let str; // core { str = "time"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "time", "make": time_make, "inspect": time_inspect, "stance": time_stance, "show": time_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function array_make({ "soft": soft = false, "mutable": mutable = true, "shape_element": shape_element, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_element === undefined) { let message = `mandatory parameter 'shape_element' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : []); } return { "soft": soft, "mutable": mutable, "shape_element": _make(shape_element), "defaultvalue": defaultvalue, }; } /** * @author fenris */ function array_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { if (value instanceof Array) { value.forEach((element, index) => { lib_shape.inspection_extend(inspection, `element #${index.toFixed(0)}`, _inspect(parameters.shape_element, element)); }); } else { lib_shape.inspection_add(inspection, `value does not seem to be an array-instance`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function array_stance(parameters, bindings, _stance) { return { "name": "array", "parameters": { "soft": parameters.soft, "shape_element": _stance(parameters.shape_element, bindings) } }; } /** * @author fenris */ function array_show(parameters, _show) { let str; // core { str = "array"; } // shape_element { str += ("<" + _show(parameters.shape_element) + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "array", "make": array_make, "inspect": array_inspect, "stance": array_stance, "show": array_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function enumeration_make({ "soft": soft = false, "mutable": mutable = true, "shape_option": shape_option, "options": options, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_option === undefined) { let message = `mandatory parameter 'shape_option' missing`; throw (new Error(message)); } if (options === undefined) { let message = `mandatory parameter 'options' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : options[0].value); } return { "soft": soft, "mutable": mutable, "shape_option": _make(shape_option), "options": options, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function enumeration_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { lib_shape.inspection_extend(inspection, `given value for enumeration`, _inspect(parameters.shape_option, value)); // TODO: check if corresponding option exists } return inspection; } /** * @author fenris */ function enumeration_stance(parameters, bindings, _stance) { return { "name": "enumeration", "parameters": { "soft": parameters.soft, "shape_option": _stance(parameters.shape_option, bindings), "options": parameters.options, } }; } /** * @author fenris */ function enumeration_show(parameters, _show) { let str; // core { str = "enumeration"; } // shape_option { str += ("<" + parameters.options.map(option => String(option)).join(",") + ":" + _show(parameters.shape_option) + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "enumeration", "make": enumeration_make, "inspect": enumeration_inspect, "stance": enumeration_stance, "show": enumeration_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function date_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { if (defaultvalue === undefined) { defaultvalue = (soft ? null : (new Date(Date.now()))); } return { "soft": soft, "mutable": mutable, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function date_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { if (value instanceof Date) { // all gode } else { lib_shape.inspection_add(inspection, `value does not seem to be a date-instance`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function date_stance(parameters, bindings, _stance) { return { "name": "date", "parameters": parameters }; } /** * @author fenris */ function date_show(parameters, _show) { let str; // core { str = "date"; } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "date", "make": date_make, "inspect": date_inspect, "stance": date_stance, "show": date_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function record_make({ "soft": soft = false, "mutable": mutable = true, "fields": fields = [], "defaultvalue": defaultvalue = undefined, }, _make) { let fields_ = (fields .map((field) => ({ "name": field.name, "shape": _make(field.shape) }))); if (defaultvalue === undefined) { if (soft) { defaultvalue = null; } else { defaultvalue = {}; fields_.forEach(field => { defaultvalue[field.name] = field.shape.parameters["defaultvalue"]; }); } } return { "soft": soft, "mutable": mutable, "fields": fields_, "defaultvalue": defaultvalue, }; } /** * @author fenris */ function record_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { parameters.fields.forEach(field => { let value_ = value[field.name]; lib_shape.inspection_extend(inspection, `field '${field.name}'`, _inspect(field.shape, value_)); }); } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function record_stance(parameters, bindings, _stance) { return { "name": "record", "parameters": { "soft": parameters.soft, "fields": parameters.fields.map(field => { return { "name": field.name, "shape": _stance(field.shape, bindings) }; }) } }; } /** * @author fenris */ function record_show(parameters, _show) { let str; // core { str = "record"; } // fields { str += ("<" + parameters.fields.map(field => (field.name + ":" + _show(field.shape))).join(",") + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "record", "make": record_make, "inspect": record_inspect, "stance": record_stance, "show": record_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function map_make({ "soft": soft = false, "mutable": mutable = true, "shape_key": shape_key, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_key === undefined) { let message = `mandatory parameter 'shape_key' missing`; throw (new Error(message)); } if (shape_value === undefined) { let message = `mandatory parameter 'shape_value' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : {}); } return { "soft": soft, "mutable": mutable, "shape_key": _make(shape_key), "shape_value": _make(shape_value), "defaultvalue": defaultvalue, }; } /** * @author fenris */ function map_stance(parameters, bindings, _stance) { return { "name": "map", "parameters": { "soft": parameters.soft, "shape_key": _stance(parameters.shape_key, bindings), "shape_value": _stance(parameters.shape_value, bindings) } }; } /** * @author fenris * @todo closer look not possible? */ function map_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { Object.keys(value).forEach(key => { lib_shape.inspection_extend(inspection, `key '${key}'`, _inspect(parameters.shape_key, key)); let value_ = value[key]; lib_shape.inspection_extend(inspection, `value for key '${key}'`, _inspect(parameters.shape_value, value_)); }); } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function map_show(parameters, _show) { let str; // core { str = "map"; } // in/out { str += ("<" + [ _show(parameters.shape_key), _show(parameters.shape_value), ].join(",") + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "map", "make": map_make, "inspect": map_inspect, "stance": map_stance, "show": map_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function maybe_make({ "soft": soft = false, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_value === undefined) { let message = `mandatory parameter 'shape_value' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : { "kind": "nothing" }); } return { "soft": soft, "shape_value": _make(shape_value), "defaultvalue": defaultvalue, }; } /** * @author fenris */ function maybe_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { if ("kind" in value) { // all good? } else { lib_shape.inspection_add(inspection, `field 'kind' missing`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function maybe_stance(parameters, bindings, _stance) { return { "name": "maybe", "parameters": { "soft": parameters.soft, "shape_value": _stance(parameters.shape_value, bindings) } }; } /** * @author fenris */ function maybe_show(parameters, _show) { let str; // core { str = "maybe"; } // shape_value { str += ("<" + _show(parameters.shape_value) + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "maybe", "make": maybe_make, "inspect": maybe_inspect, "stance": maybe_stance, "show": maybe_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris */ function promise_make({ "soft": soft = false, "shape_result": shape_result, "shape_reason": shape_reason, "defaultvalue": defaultvalue = undefined, }, _make) { if (shape_result === undefined) { let message = `mandatory parameter 'shape_result' missing`; throw (new Error(message)); } if (shape_reason === undefined) { let message = `mandatory parameter 'shape_reason' missing`; throw (new Error(message)); } if (defaultvalue === undefined) { defaultvalue = (soft ? null : Promise.resolve(null)); } return { "soft": soft, "shape_result": _make(shape_result), "shape_reason": _make(shape_reason), "defaultvalue": defaultvalue, }; } /** * @author fenris */ function promise_stance(parameters, bindings, _stance) { return { "name": "promise", "parameters": { "soft": parameters.soft, "shape_result": _stance(parameters.shape_result, bindings), "shape_reason": _stance(parameters.shape_reason, bindings) } }; } /** * @author fenris * @todo closer look not possible? */ function promise_inspect(parameters, value, _inspect) { let inspection = lib_shape.inspection_create(); if (value == undefined) { if (parameters.soft) { // all good } else { lib_shape.inspection_add(inspection, "null is not allowed"); } } else { let jstype_actual = typeof (value); let jstype_expected = "object"; if (jstype_actual === jstype_expected) { if (value instanceof Promise /*<any, any>*/) { // all good? } else { lib_shape.inspection_add(inspection, `values is not an Promise-instance`); } } else { lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); } } return inspection; } /** * @author fenris */ function promise_show(parameters, _show) { let str; // core { str = "promise"; } // in/out { str += ("<" + [ _show(parameters.shape_result), _show(parameters.shape_reason), ].join(",") + ">"); } // soft { if (parameters.soft) { str = `~${str}`; } } return str; } /** * @author fenris */ lib_shape.register({ "name": "promise", "make": promise_make, "inspect": promise_inspect, "stance": promise_stance, "show": promise_show, }); })(lib_shape || (lib_shape = {})); /* This file is part of »bacterio-plankton:shape«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:shape« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:shape« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. */ var lib_shape; (function (lib_shape) { /** * @author fenris * @todo use a treemap-function (but first make one :P) */ function adjust_labels(shape, transformator) { if (false) { } else if (shape.name === "enumeration") { return { "name": "enumeration", "parameters": { "soft": shape.parameters["soft"], "shape_option": adjust_labels(shape.parameters["shape_option"], transformator), "options": shape.parameters["options"].map(option => { return { "value": option.value, "label": transformator(option.label), }; }), "defaultvalue": shape.parameters["defaultvalue"], } }; } else if (shape.name === "array") { return { "name": "array", "parameters": { "soft": shape.parameters["soft"], "shape_element": adjust_labels(shape.parameters["shape_element"], transformator), "defaultvalue": shape.parameters["defaultvalue"], } }; } else if (shape.name === "record") { return { "name": "record", "parameters": { "soft": shape.parameters["soft"], "fields": shape.parameters["fields"].map(field => { return { "name": field.name, "shape": adjust_labels(field.shape, transformator), "label": transformator(field.label), }; }), "defaultvalue": shape.parameters["defaultvalue"], } }; } // lil' hacky … else { // shape["label"] = ((shape["label"] == null) ? null : transformator(shape["label"])); return shape; } } lib_shape.adjust_labels = adjust_labels; /** * @author fenris */ function register_(id, factory) { const message = "not implemented; dummy impl"; console.warn(message); } lib_shape.register_ = register_; /** * @author fenris */ function retrieve_(id) { const message = "not implemented; returning dummy"; console.warn(message); return { "name": "any" }; } lib_shape.retrieve_ = retrieve_; })(lib_shape || (lib_shape = {}));