From e2e2481c63b7d83d83584d8075e6fdbe452874e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Sat, 18 Jan 2025 09:49:29 +0100 Subject: [PATCH] [upd] sindri --- tools/sindri/sindri | 2050 +++++++++++++++++++++++++++++++++---------- 1 file changed, 1581 insertions(+), 469 deletions(-) diff --git a/tools/sindri/sindri b/tools/sindri/sindri index e58c3b8..0f0fffe 100755 --- a/tools/sindri/sindri +++ b/tools/sindri/sindri @@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -37,7 +37,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -70,7 +70,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -129,7 +129,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -260,7 +260,7 @@ function instance_show(value) { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -371,262 +371,7 @@ export interface interface_writeable { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:base« 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:base« 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:base«. If not, see . - */ -var lib_maybe; -(function (lib_maybe) { - /** - * @author fenris - */ - function make_nothing() { - return { - "kind": "nothing", - "parameters": {} - }; - } - lib_maybe.make_nothing = make_nothing; - /** - * @author fenris - */ - function make_just(value) { - return { - "kind": "just", - "parameters": { - "value": value - } - }; - } - lib_maybe.make_just = make_just; - /** - * @author fenris - */ - function is_nothing(maybe) { - return (maybe.kind === "nothing"); - } - lib_maybe.is_nothing = is_nothing; - /** - * @author fenris - */ - function is_just(maybe) { - return (maybe.kind === "just"); - } - lib_maybe.is_just = is_just; - /** - * @author fenris - */ - function cull(maybe) { - if (!is_just(maybe)) { - var message = "cull from nothing"; - throw (new Error(message)); - } - else { - var value = maybe.parameters["value"]; - return value; - } - } - lib_maybe.cull = cull; - /** - * @author fenris - */ - function propagate(maybe, function_) { - if (!is_just(maybe)) { - } - else { - var value = maybe.parameters["value"]; - var maybe_ = function_(value); - return maybe_; - } - } - lib_maybe.propagate = propagate; -})(lib_maybe || (lib_maybe = {})); -/** - * @author fenris - */ -/*export*/ var class_maybe = /** @class */ (function () { - function class_maybe() { - } - /** - * @desc whether the wrapper is nothing - * @author fenris - */ - class_maybe.prototype.is_nothing = function () { - throw (new Error("not implemented: class_maybe.is_nothing")); - }; - /** - * @desc whether the wrapper is just - * @author fenris - */ - class_maybe.prototype.is_just = function () { - throw (new Error("not implemented: class_maybe.is_just")); - }; - /** - * @desc return the value, stored in the maybe-wrapper - * @author fenris - */ - class_maybe.prototype.cull = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.toString = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - throw (new Error("not implemented: class_maybe.distinguish")); - }; - /** - * @author fenris - */ - class_maybe.prototype.propagate = function (action) { - throw (new Error("not implemented: class_maybe.propagate")); - }; - /** - * @desc [implementation] - * @author fenris - */ - class_maybe.prototype._show = function () { - return this.toString(); - }; - return class_maybe; -}()); -/** - * @author fenris - */ -/*export*/ var class_nothing = /** @class */ (function (_super) { - __extends(class_nothing, _super); - /** - * @author fenris - */ - function class_nothing(reason) { - if (reason === void 0) { reason = null; } - var _this = _super.call(this) || this; - _this.reason = reason; - return _this; - } - /** - * @author fenris - */ - class_nothing.prototype.is_nothing = function () { - return true; - }; - /** - * @author fenris - */ - class_nothing.prototype.is_just = function () { - return false; - }; - /** - * @author fenris - */ - class_nothing.prototype.cull = function () { - var message = "you shouldn't cull a nothing-value …"; - // lib_plankton.log.warn(message); - return null; - }; - /** - * @author fenris - */ - class_nothing.prototype.toString = function () { - return "<\u00B7>"; - }; - /** - * @author fenris - */ - class_nothing.prototype.reason_get = function () { - var content = ((this.reason == null) ? "·" : this.reason); - return "<- ".concat(content, " ->"); - }; - /** - * @author fenris - */ - class_nothing.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_nothing(this.reason); - }; - /** - * @author fenris - */ - class_nothing.prototype.propagate = function (action) { - return (new class_nothing(this.reason)); - }; - return class_nothing; -}(class_maybe)); -/** - * @author fenris - */ -/*export*/ var class_just = /** @class */ (function (_super) { - __extends(class_just, _super); - /** - * @author fenris - */ - function class_just(value) { - var _this = _super.call(this) || this; - _this.value = value; - return _this; - } - /** - * @author fenris - */ - class_just.prototype.is_nothing = function () { - return false; - }; - /** - * @author fenris - */ - class_just.prototype.is_just = function () { - return true; - }; - /** - * @author fenris - */ - class_just.prototype.cull = function () { - return this.value; - }; - /** - * @author fenris - */ - class_just.prototype.toString = function () { - var content = instance_show(this.value); - return "<+ ".concat(content, " +>"); - }; - /** - * @author fenris - */ - class_just.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_just(this.value); - }; - /** - * @author fenris - */ - class_just.prototype.propagate = function (action) { - return action(this.value); - }; - return class_just; -}(class_maybe)); -/* -This file is part of »bacterio-plankton:base«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -666,6 +411,25 @@ var class_error = /** @class */ (function (_super) { }; return class_error; }(Error)); +/* +This file is part of »bacterio-plankton:base«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:base« 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:base« 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:base«. If not, see . + */ var lib_plankton; (function (lib_plankton) { var base; @@ -690,6 +454,100 @@ var lib_plankton; base.object_merge = object_merge; })(base = lib_plankton.base || (lib_plankton.base = {})); })(lib_plankton || (lib_plankton = {})); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +/* +This file is part of »bacterio-plankton:email«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:email« 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:lang« 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:email«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var email; + (function (email) { + /** + */ + function send(smtp_credentials, sender, receivers, subject, content) { + return __awaiter(this, void 0, void 0, function () { + var nm_nodemailer, transporter, info; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + nm_nodemailer = require("nodemailer"); + transporter = nm_nodemailer.createTransport({ + "host": smtp_credentials.host, + "port": smtp_credentials.port, + "secure": false, + "auth": { + "user": smtp_credentials.username, + "pass": smtp_credentials.password + }, + "debug": true + }); + return [4 /*yield*/, transporter.sendMail({ + "from": sender, + "to": receivers.join(", "), + "subject": subject, + "text": content + })]; + case 1: + info = _a.sent(); + return [2 /*return*/]; + } + }); + }); + } + email.send = send; + })(email = lib_plankton.email || (lib_plankton.email = {})); +})(lib_plankton || (lib_plankton = {})); var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -708,7 +566,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -763,7 +621,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -847,7 +705,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -880,7 +738,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -935,7 +793,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -962,9 +820,10 @@ var lib_plankton; /** * [constructor] */ - function class_channel_file(path) { + function class_channel_file(path, human_readable) { var _this = _super.call(this) || this; _this.path = path; + _this.human_readable = human_readable; return _this; } /** @@ -972,24 +831,40 @@ var lib_plankton; class_channel_file.prototype.add = function (entry) { var _this = this; var nm_fs = require("fs"); - nm_fs.writeFile(this.path, { + var line = (this.human_readable + ? (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") + + + " " + + + ("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "") + + + ": " + + + JSON.stringify(entry.details, undefined, " ") + + + "\n") + : (JSON.stringify({ + "timestamp": lib_plankton.base.get_current_timestamp(), + "level_number": entry.level, + "level_name": log.level_show(entry.level), + "incident": entry.incident, + "details": entry.details + }) + + + "\n")); + nm_fs.writeFile(this.path, line, { "flag": "a+" - }, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") - + - " " - + - ("[" + log.level_show(entry.level) + "]") - + - " " - + - ("" + entry.incident + "") - + - ": " - + - JSON.stringify(entry.details, undefined, " ") - + - "\n"), function (error) { - process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n"); + }, function (error) { + if (error !== null) { + process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n"); + } + else { + // do nothing + } }); }; return class_channel_file; @@ -1000,7 +875,59 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« 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:lang« 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:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var class_channel_email = /** @class */ (function (_super) { + __extends(class_channel_email, _super); + /** + * [constructor] + */ + function class_channel_email(smtp_credentials, sender, receivers) { + var _this = _super.call(this) || this; + _this.smtp_credentials = smtp_credentials; + _this.sender = sender; + _this.receivers = receivers; + return _this; + } + /** + */ + class_channel_email.prototype.add = function (entry) { + var nm_fs = require("fs"); + lib_plankton.email.send(this.smtp_credentials, this.sender, this.receivers, (("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "")), JSON.stringify(entry.details, undefined, " ")); + }; + return class_channel_email; + }(log.class_channel)); + log.class_channel_email = class_channel_email; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1067,7 +994,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1118,7 +1045,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1152,7 +1079,7 @@ var lib_plankton; /** */ function channel_make(description) { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; switch (description.kind) { default: { throw (new Error("unhandled log channel kind: " + description.kind)); @@ -1163,11 +1090,15 @@ var lib_plankton; break; } case "file": { - return (new log.class_channel_minlevel(new log.class_channel_file((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug"))); + return (new log.class_channel_minlevel(new log.class_channel_file(((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), false), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug"))); + break; + } + case "email": { + return (new log.class_channel_minlevel(new log.class_channel_email(description.data["smtp_credentials"], description.data["sender"], description.data["receivers"]), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug"))); break; } case "notify": { - return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug"))); + return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_e = description.data["threshold"]) !== null && _e !== void 0 ? _e : "debug"))); break; } } @@ -1187,7 +1118,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1290,9 +1221,44 @@ var lib_plankton; })(log = lib_plankton.log || (lib_plankton.log = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« 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:lang« 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:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + log.conf_push([ + log.channel_make({ + "kind": "stdout", + "data": { + "threshold": "info" + } + }), + ]); + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1451,7 +1417,7 @@ var make_eml_body = (function () { /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1812,7 +1778,7 @@ var lib_string; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -2076,7 +2042,7 @@ var printf = lib_plankton.string.printf; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -2208,7 +2174,7 @@ var make_logger = (function () { /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2227,7 +2193,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2246,7 +2212,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2285,7 +2251,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2339,7 +2305,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2382,7 +2348,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2437,7 +2403,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2487,7 +2453,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2539,7 +2505,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2599,7 +2565,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2650,7 +2616,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2673,23 +2639,36 @@ var lib_plankton; /** * @author fenris */ - function encode(x, formatted = false) { - return JSON.stringify(x, undefined, formatted ? "\t" : undefined); + function encode(source, options = {}) { + options = Object.assign({ + "formatted": false, + }, options); + return JSON.stringify(source, undefined, (options.formatted ? "\t" : undefined)); } json.encode = encode; /** * @author fenris */ - function decode(x) { - return JSON.parse(x); + function decode(target) { + return JSON.parse(target); } json.decode = decode; + /** + * @author fenris + */ + function implementation_code() { + return { + "encode": x => encode(x), + "decode": decode, + }; + } + json.implementation_code = implementation_code; })(json = lib_plankton.json || (lib_plankton.json = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2737,9 +2716,1109 @@ var lib_plankton; })(json = lib_plankton.json || (lib_plankton.json = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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:pod« 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:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod_1) { + /** + * @author fenris + */ + function make_empty() { + return { + "kind": "empty" + }; + } + pod_1.make_empty = make_empty; + /** + * @author fenris + */ + function make_filled(value) { + return { + "kind": "filled", + "value": value + }; + } + pod_1.make_filled = make_filled; + /** + * whether the pod is filled + * + * @author fenris + */ + function is_filled(pod) { + return (pod.kind === "filled"); + } + pod_1.is_filled = is_filled; + /** + * return the value, stored in the pod-wrapper + * + * @author fenris + */ + function cull(pod) { + if (!is_filled(pod)) { + throw (new Error("cull from empty")); + } + else { + return pod.value; + } + } + pod_1.cull = cull; + /** + * to pass on a empty-pod or to use a filled-pod + * + * @author fenris + */ + function propagate(pod, function_) { + if (!is_filled(pod)) { + return make_empty(); + } + else { + return make_filled(function_(pod.value)); + } + } + pod_1.propagate = propagate; + /** + * @author fenris + */ + function distinguish(pod, function_empty, function_filled) { + return ((!is_filled(pod)) + ? function_empty() + : function_filled(pod.value)); + } + pod_1.distinguish = distinguish; + /** + */ + function show(pod, options = {}) { + options = Object.assign({ + "show_value": value => String(value), + }, options); + if (!is_filled(pod)) { + return "<·>"; + } + else { + return ("<- " + options.show_value(pod.value) + " ->"); + } + } + pod_1.show = show; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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:pod« 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:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod) { + /** + */ + class class_pod { + constructor(subject) { this.subject = subject; } + tear() { return this.subject; } + static empty() { return (new class_pod(pod.make_empty())); } + static filled(value) { return (new class_pod(pod.make_filled(value))); } + is_empty() { return (!pod.is_filled(this.subject)); } + is_filled() { return pod.is_filled(this.subject); } + cull() { return pod.cull(this.subject); } + show(show_value = undefined) { return pod.show(this.subject, show_value); } + toString() { return this.show(); } + propagate(function_) { return new class_pod(pod.propagate(this.subject, function_)); } + distinguish(function_empty, function_filled) { return pod.distinguish(this.subject, function_empty, function_filled); } + } + pod.class_pod = class_pod; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +/** + * might be completely obsolete + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + function promise_reject(reason) { + return Promise.reject(reason); + } + call.promise_reject = promise_reject; + /** + * @author fenris + */ + function promise_resolve(result) { + return Promise.resolve(result); + } + call.promise_resolve = promise_resolve; + /** + * @author fenris + */ + function promise_make(executor) { + return (new Promise(executor)); + } + call.promise_make = promise_make; + /** + * @author fenris + */ + function promise_then_close(promise, resolver, rejector) { + promise.then(resolver, rejector); + } + call.promise_then_close = promise_then_close; + /** + * @author fenris + */ + function promise_then_append(promise, resolver, rejector = null) { + if (rejector == null) { + rejector = (reason) => promise_reject(reason); + } + return (promise.then(resolver, rejector)); + } + call.promise_then_append = promise_then_append; + /** + * @author fenris + */ + function promise_all(promises) { + return Promise.all(promises); + } + call.promise_all = promise_all; + /** + * @author fenris + */ + function promise_chain(promises, start = undefined) { + return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start))); + } + call.promise_chain = promise_chain; + /** + * @author fenris + */ + function promise_condense(promises) { + return (promise_chain(promises.map(promise => result => promise_then_append(promise(), element => promise_resolve(result.concat([element])))), [])); + } + call.promise_condense = promise_condense; + /** + * @author fenris + */ + function promise_group(promises, options = { + "serial": false, + }) { + const decorate = function (promise, name) { + return (() => promise_then_append(promise(), value => promise_resolve({ "key": name, "value": value }))); + }; + if (options.serial) { + return (promise_then_append(promise_condense(Object.keys(promises) + .map(name => decorate(promises[name], name))), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value])))))); + } + else { + return (promise_then_append(promise_all(Object.keys(promises) + .map(name => decorate(promises[name], name)) + .map(promise => promise())), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value])))))); + } + } + call.promise_group = promise_group; + /** + * @author fenris + */ + function promise_wrap(promise, transformator_result, transformator_reason = lib_plankton.call.id) { + return (promise_make((resolve, reject) => { + promise_then_close(promise, result => resolve(transformator_result(result)), reason => reject(transformator_reason(reason))); + })); + } + call.promise_wrap = promise_wrap; + /** + * @author fenris + */ + /* + export function promise_show(label : string) : (result : type_result)=>type_promise { + return ( + result => promise_make( + (resolve, reject) => { + // lib_plankton.log.info(label + ": " + instance_show(result)); + process.stdout.write(label + ": " + instance_show(result)); + resolve(result); + } + ) + ); + } + */ + /** + * @author fenris + */ + /* + export function promise_log(result : type_result) : (result : type_result)=>type_promise { + return promise_show("log"); + } + */ + /** + * @author fenris + */ + function promise_attach(state, promise, name) { + return (promise_wrap(promise, result => { + state[name] = result; + return state; + })); + } + call.promise_attach = promise_attach; + /** + * @author fenris + */ + function promise_delay(promise, delay) { + return promise_make((resolve, reject) => { + call.timeout(() => { + promise_then_close(promise, resolve, reject); + return null; + }, delay); + }); + } + call.promise_delay = promise_delay; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + */ + class CancellablePromise extends Promise { + /** + */ + constructor(executor) { + super((resolve, reject) => { }); + this.subject = (new Promise((resolve, reject) => { + Promise.race([ + new Promise(executor), + new Promise((resolve_, reject_) => { + this.interval = setInterval(() => { + if (!this.cancelled) { + // do nothing + } + else { + reject_(new Error("cancelled")); + this.clear(); + } + }, 0); + }), + ]) + .then(resolve, reject); + })); + this.cancelled = false; + this.interval = null; + } + /** + */ + clear() { + if (this.interval === null) { + // do nothing + } + else { + clearInterval(this.interval); + this.interval = null; + } + } + /** + */ + then(onfulfilled, onrejected) { + this.clear(); + return this.subject.then(onfulfilled, onrejected); + } + /** + */ + catch(x) { + this.clear(); + return this.subject.catch(x); + } + /** + */ + cancel() { + this.cancelled = true; + this.clear(); + } + } + call.CancellablePromise = CancellablePromise; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +/** + * initializer might be obsolete, since promises are reusable after having been resolved or rejected + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + let enum_initializer_state; + (function (enum_initializer_state) { + enum_initializer_state[enum_initializer_state["initial"] = 0] = "initial"; + enum_initializer_state[enum_initializer_state["waiting"] = 1] = "waiting"; + enum_initializer_state[enum_initializer_state["successful"] = 2] = "successful"; + enum_initializer_state[enum_initializer_state["failed"] = 3] = "failed"; + })(enum_initializer_state = call.enum_initializer_state || (call.enum_initializer_state = {})); + /** + * @author fenris + */ + function initializer_make(fetcher) { + let subject = { + "fetcher": fetcher, + "state": enum_initializer_state.initial, + "queue": [], + "result": undefined, + "reason": undefined, + }; + return subject; + } + call.initializer_make = initializer_make; + /** + * @author fenris + */ + function initializer_actuate(subject) { + switch (subject.state) { + case enum_initializer_state.successful: { + subject.queue.forEach(entry => entry.resolve(subject.result)); + break; + } + case enum_initializer_state.failed: { + subject.queue.forEach(entry => entry.reject(subject.reason)); + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + /** + * @author fenris + */ + function initializer_reset(subject) { + subject.state = enum_initializer_state.initial; + subject.queue = []; + } + call.initializer_reset = initializer_reset; + /** + * @author fenris + */ + function initializer_state(subject) { + return subject.state; + } + call.initializer_state = initializer_state; + /** + * @author fenris + */ + function initializer_get(subject) { + switch (subject.state) { + case enum_initializer_state.initial: { + subject.state = enum_initializer_state.waiting; + return (call.promise_make((resolve, reject) => { + subject.queue.push({ "resolve": resolve, "reject": reject }); + subject.fetcher().then(result => { + subject.state = enum_initializer_state.successful; + subject.result = result; + initializer_actuate(subject); + }, reason => { + subject.state = enum_initializer_state.failed; + subject.reason = reason; + initializer_actuate(subject); + }); + })); + break; + } + case enum_initializer_state.waiting: { + return (call.promise_make((resolve, reject) => { + subject.queue.push({ "resolve": resolve, "reject": reject }); + })); + break; + } + case enum_initializer_state.successful: { + return (call.promise_resolve(subject.result)); + break; + } + case enum_initializer_state.failed: { + return (call.promise_reject(subject.reason)); + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + call.initializer_get = initializer_get; + /** + * @author fenris + */ + function initializer_get_sync(subject) { + switch (subject.state) { + case enum_initializer_state.successful: { + return subject.result; + break; + } + case enum_initializer_state.failed: { + throw subject.reason; + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + /** + * @author fenris + */ + function initializer_set_sync(subject, result) { + switch (subject.state) { + case enum_initializer_state.successful: { + subject.result = result; + break; + } + case enum_initializer_state.failed: { + subject.state = enum_initializer_state.successful; + subject.result = result; + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /* + The core idea of this library is to provide means for asynchronous program flow. The old-school way to do is, + is to use callbacks. While this approach is simple and easy to understand, it has some disadvantages. As an + attempt to relief and improve this, the promise-system was introduced. In principle it solves most of the + problems found in the callback-approach; however it has some downsides as well: + + - Convolution of multiple principles + Promises unite the ideas of asynchronous program flow and error handling. + + - Instant execution + Creating a promise results in the instant execution of the given executor prodecure. While this might be + convenient in some cases, it can be quite disturbing and counter-intuitive in others. + + - Broken typing + The Promise system doesn't distinguish between an appending "then" (i.e. passing a function, which returns a + new promise) and a closing "then" (i.e. passing a function, which has no return value). On top of that it + allows returning simple values in an appending "then", which results in an implicit call of the executors + "resolve"-function. The price for these "pragmatic" features is that the whole system can't be typed well. + And even though JavaScript is not a strictly typed language, it was a quite questionable decision to design + the promise system in a way, which breaks typing from the start. + + The deferral-system forseeks to solve these issues while retaining the advantages of the promise-system. + */ + /** + * @author fenris + * @desc activates the deferral and handles its output according to a given procedure + * @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument + */ + function deferral_use(deferral, input, procedure) { + deferral.representation(input).then(value => { + procedure(value); + }, reason => { + throw reason; + }); + } + call.deferral_use = deferral_use; + /** + * @author fenris + * @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject") + */ + function deferral_make(handler) { + return ({ + "representation": ((input) => (new Promise((resolve, reject) => { + handler(input, resolve); + }))) + }); + } + call.deferral_make = deferral_make; + /** + * @author fenris + * @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject") + */ + function deferral_wrap(function_) { + return (deferral_make((input, convey) => convey(function_(input)))); + } + call.deferral_wrap = deferral_wrap; + /** + * @author fenris + */ + function deferral_id() { + return (deferral_make((input, convey) => convey(input))); + } + call.deferral_id = deferral_id; + /** + * @author fenris + */ + function deferral_const(value) { + return (deferral_make((input, convey) => convey(value))); + } + call.deferral_const = deferral_const; + /** + * @author fenris + */ + function deferral_delay(output, delay) { + return (deferral_make((input, convey) => { + setTimeout(() => convey(output), delay); + })); + } + call.deferral_delay = deferral_delay; + /** + * @author fenris + * @desc connects two deferrals to form a new one; the output of the first is taken as input for the second + * (similar to "Promise.then" when passing a function which returns a new promise) + * @param {type_deferral} first a simple deferral + * @param {(value1 : type_value1)=>type_deferral} second a function depending from a value returning a deferral + */ + function deferral_compose_serial(first, second) { + return { + "representation": ((input) => first.representation(input).then((between) => second.representation(between))) + }; + } + call.deferral_compose_serial = deferral_compose_serial; + /** + * @author fenris + */ + function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) { + return (deferral_make((input, convey) => { + let object = { + "left": lib_plankton.pod.make_empty(), + "right": lib_plankton.pod.make_empty(), + }; + let finish = function () { + if (lib_plankton.pod.is_filled(object.left) + && + lib_plankton.pod.is_filled(object.right)) { + let result = { + "left": lib_plankton.pod.cull(object.left), + "right": lib_plankton.pod.cull(object.right), + }; + convey(result); + } + else { + // do nothing + } + }; + deferral_use(deferral_left, input, output_left => { + object.left = lib_plankton.pod.make_filled(output_left); + finish(); + }); + deferral_use(deferral_right, input, output_right => { + object.right = lib_plankton.pod.make_filled(output_right); + finish(); + }); + })); + } + call.deferral_compose_parallel = deferral_compose_parallel; + /** + * @author fenris + * @desc repeatedly applied serial composition + */ + function deferral_chain(members) { + return (members.reduce( + // (result, current) => deferral_compose_serial(result, current), + deferral_compose_serial, deferral_id())); + } + call.deferral_chain = deferral_chain; + /** + * @author fenris + */ + /* + export function deferral_bunch( + members : {[name : string] : type_deferral} + ) : type_deferral { + + } + */ + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + class class_deferral { + /** + * @author fenris + */ + constructor(subject) { + this.subject = subject; + } + /** + * @author fenris + */ + static _cram(subject) { + return (new class_deferral(subject)); + } + /** + * @author fenris + */ + static _tear(instance) { + return instance.subject; + } + /** + * @author fenris + */ + static make(handler) { + return (class_deferral._cram(call.deferral_make(handler))); + } + /** + * @author fenris + */ + use(input, procedure) { + return (call.deferral_use(class_deferral._tear(this), input, procedure)); + } + /** + * @author fenris + */ + compose_serial(second) { + return (class_deferral._cram(call.deferral_compose_serial(class_deferral._tear(this), class_deferral._tear(second)))); + } + /** + * @author fenris + */ + static chain(members) { + return (class_deferral._cram(call.deferral_chain(members.map(member => class_deferral._tear(member))))); + } + /** + * @author fenris + */ + static wrap(function_) { + return (class_deferral._cram(call.deferral_wrap(function_))); + } + /** + * @author fenris + */ + static const_(value) { + return (class_deferral._cram(call.deferral_const(value))); + } + /** + * @author fenris + */ + static delay(output, delay) { + return (class_deferral._cram(call.deferral_delay(output, delay))); + } + } + call.class_deferral = class_deferral; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« 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:call« 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:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * converts the "arguments"-map into an array + * + * @param {Object} args + * @author fenris + */ + function args2list(args) { + return Object.keys(args).map(key => args[key]); + } + call.args2list = args2list; + /** + * just the empty function; useful for some callbacks etc. + * + * @author fenris + */ + function nothing() { + } + call.nothing = nothing; + /** + * just the identity; useful for some callbacks etc.; defined as function instead of const for using type parameters + * + * @author fenris + */ + function id(x) { + return x; + } + call.id = id; + /** + * just the identity; useful for some callbacks etc. + * + * @author fenris + */ + function const_(x) { + return (y => x); + } + call.const_ = const_; + /** + * composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) + * + * @param {function} function_f + * @param {function} function_g + * @author fenris + */ + function compose(function_f, function_g) { + return (function (x) { + // return function_g(function_f(x)); + return function_g(function_f.apply(function_f, args2list(arguments))); + }); + } + call.compose = compose; + /** + * @author fenris + */ + function curryfy_real(f, n) { + switch (n) { + case 0: { + throw (new Error("[curryfy] impossible")); + // break; + } + case 1: { + return f; + // break; + } + default: { + return (function (x) { + return (curryfy_real(function () { return f.apply(f, [x].concat(args2list(arguments))); }, n - 1)); + }); + // break; + } + } + } + /** + * transforms a function with sequential input to a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) + * + * @param {function} f + * @return {function} the currified version of the in put function + * @author fenris + */ + function curryfy(f) { + return curryfy_real(f, f.length); + } + call.curryfy = curryfy; + /** + * @author fenris + */ + function convey(value, functions) { + let result = value; + functions.forEach(function_ => { + result = function_(result); + }); + return result; + } + call.convey = convey; + /** + * @author fenris + */ + function timeout(procedure, delay_in_seconds) { + return ( + /*window.*/ setTimeout(procedure, Math.floor(delay_in_seconds * 1000))); + } + call.timeout = timeout; + /** + * Promise version of "setTimeout" + * + * @author fenris + */ + function defer(seconds, action) { + return (new Promise((resolve, reject) => { + setTimeout(() => resolve(action()), Math.floor(seconds * 1000)); + })); + } + call.defer = defer; + /** + * a definition for a value being "defined" + * + * @author neuc + */ + function is_def(obj, options = {}) { + options = Object.assign({ + "null_is_valid": false, + }, options); + return (!((typeof (obj) === "undefined") + || + (!options.null_is_valid && (obj === null)))); + } + call.is_def = is_def; + /** + * returns the value if set and, when a type is specified, if the type is correct, if not return default_value + * + * @author neuc + */ + function def_val(value, default_value, options = {}) { + options = Object.assign({ + "type": null, + "null_is_valid": false, + }, options); + if (is_def(value, { "null_is_valid": options.null_is_valid }) + && + (is_def(options.type) + ? ((typeof (value) === options.type) + || + ((value === null) + && + options.null_is_valid)) + : true)) { + return value; + } + else { + return default_value; + } + } + call.def_val = def_val; + ; + /** + * provides the call for an attribute of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the attribute + * @return {function} + * @author fenris + */ + function attribute(name) { + return (object => object[name]); + } + call.attribute = attribute; + /** + * provides a method of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the method + * @return {function} + * @author fenris + */ + function method(name) { + return (function (object) { return object[name].apply(object, args2list(arguments).slice(1)); }); + } + call.method = method; + /** + * @author fenris + */ + function distinguish(coproduct, handlers, options = {}) { + options = Object.assign({ + "fallback": null, + }, options); + if (coproduct.kind in handlers) { + const handler = handlers[coproduct.kind]; + return handler(coproduct.data); + } + else { + const message = ("unhandled kind '" + coproduct.kind + "'"); + if (options.fallback !== null) { + console.warn(message); + return options.fallback(coproduct); + } + else { + throw (new Error(message)); + } + } + } + call.distinguish = distinguish; + /** + * rate limiting algorithm, based on the idea of mana (magic power) in video games: + * - an actor has a fixed mana capacity, i.e. the maximum amount of available power + * - an actor has a fixed rate of mana regeneration, i.e. how fast the power is filled up (linear growth) + * - an action has a defined mana heft, i.e. how much power is required and deducted in order to execute it + * - mana states are represented by snapshots, i.e. the amount of power at a certain point in time + * + * @author fenris + */ + async function rate_limit_check(setup, heft) { + if (heft > setup.capacity) { + return Promise.resolve({ + "granted": false, + "seconds": null, + }); + } + else { + // get current value + const current_timestamp = (Date.now() / 1000); + const old_snapshot_raw = (await setup.get_snapshot()); + const old_snapshot = (old_snapshot_raw + ?? + { "timestamp": current_timestamp, "value": setup.capacity }); + const seconds_passed = (current_timestamp - old_snapshot.timestamp); + const current_value = Math.min(setup.capacity, (old_snapshot.value + + + (setup.regeneration_rate + * + seconds_passed))); + // analyze + if (current_value < heft) { + // too less + const seconds_needed = ((setup.regeneration_rate <= 0) + ? null + : ((heft - old_snapshot.value) / setup.regeneration_rate)); + return Promise.resolve({ + "granted": false, + "seconds": ((seconds_needed === null) ? null : (seconds_needed - seconds_passed)), + }); + } + else { + // enough -> update snapshot + const new_value = (current_value - heft); + // set_snapshot + if (old_snapshot_raw === null) { + await setup.set_snapshot({ "timestamp": current_timestamp, "value": new_value }); + } + else { + await setup.update_snapshot(current_timestamp, (new_value - old_snapshot.value)); + } + return Promise.resolve({ + "granted": true, + "seconds": 0, + }); + } + } + } + call.rate_limit_check = rate_limit_check; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:file«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:file« is free software: you can redistribute it and/or modify @@ -2759,6 +3838,23 @@ var lib_plankton; (function (lib_plankton) { var file; (function (file) { + /** + * @author fenris + */ + function exists(path) { + var nm_fs = require("fs"); + return (new Promise(function (resolve, reject) { + nm_fs.stat(path, function (error, stats) { + if (error) { + resolve(false); + } + else { + resolve(true); + } + }); + })); + } + file.exists = exists; /** * @author fenris */ @@ -2767,7 +3863,7 @@ var lib_plankton; return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { "encoding": "utf8", - "flag": "r", + "flag": "r" }, function (error, content) { if (error == null) { resolve(content); @@ -2786,7 +3882,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { - "flag": "r", + "flag": "r" }, function (error, content) { if (error == null) { resolve(content); @@ -2823,13 +3919,13 @@ var lib_plankton; function write(path, content, options) { if (options === void 0) { options = {}; } options = Object.assign({ - "encoding": "utf-8", + "encoding": "utf-8" }, options); var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { "encoding": options.encoding, - "flag": "w", + "flag": "w" }, function (error) { if (error == null) { resolve(undefined); @@ -2850,7 +3946,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { - "flag": "w", + "flag": "w" }, function (error) { if (error == null) { resolve(undefined); @@ -2893,7 +3989,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2926,7 +4022,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2963,7 +4059,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2998,7 +4094,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3033,7 +4129,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3068,7 +4164,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3103,7 +4199,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3138,7 +4234,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3175,7 +4271,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3213,7 +4309,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3250,7 +4346,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3285,7 +4381,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3323,7 +4419,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3361,7 +4457,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3396,7 +4492,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3429,7 +4525,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3466,7 +4562,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3503,7 +4599,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3540,7 +4636,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3577,7 +4673,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3622,7 +4718,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3661,7 +4757,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3699,7 +4795,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3737,7 +4833,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3775,7 +4871,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3812,7 +4908,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3850,7 +4946,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3883,7 +4979,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3921,7 +5017,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3958,7 +5054,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3986,12 +5082,12 @@ var lib_plankton; if (options === void 0) { options = {}; } var _this = this; options = Object.assign({ - "export": false, + "export": false }, options); _this = _super.call(this) || this; _this.name = name; _this.type = type; - _this.export_ = options.export; + _this.export_ = options["export"]; return _this; } return struct_statement_type_definition; @@ -4002,7 +5098,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4030,14 +5126,14 @@ var lib_plankton; if (options === void 0) { options = {}; } var _this = this; options = Object.assign({ - "export": false, + "export": false }, options); _this = _super.call(this) || this; _this.constant = constant; _this.name = name; _this.type = type; _this.value = value; - _this.export_ = options.export; + _this.export_ = options["export"]; return _this; } return struct_statement_declaration; @@ -4048,7 +5144,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4086,7 +5182,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4124,7 +5220,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4170,7 +5266,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4207,7 +5303,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4241,7 +5337,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4260,7 +5356,7 @@ along with »bacterio-plankton:prog«. If not, see »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4295,45 +5391,45 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": true, - "level": 0, + "level": 0 }, options); if (type instanceof prog.struct_type_literal) { var type_literal = type; return lib_plankton.string.coin("{{indentation}}{{value}}", { "indentation": indentation(options.indent, options.level), "value": render_expression(type_literal.value, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_any) { var type_any = type; return lib_plankton.string.coin("{{indentation}}any", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_void) { var type_void = type; return lib_plankton.string.coin("{{indentation}}void", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_boolean) { var type_boolean = type; return lib_plankton.string.coin("{{indentation}}boolean", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_integer) { var type_integer = type; return lib_plankton.string.coin("{{indentation}}number", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_string) { var type_string = type; return lib_plankton.string.coin("{{indentation}}string", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_list) { @@ -4361,10 +5457,10 @@ var lib_plankton; "assignment": (field.mandatory ? ":" : "?:"), "type": render_type(field.type, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(";\n")), + .join(";\n")) }); } else if (type instanceof prog.struct_type_function) { @@ -4374,12 +5470,12 @@ var lib_plankton; "indentation2": indentation(true, options.level), "arguments": (type_function.arguments .map(function (argument) { return render_type(argument, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) .join(", ")), "target": render_type(type_function.target, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_construction) { @@ -4393,10 +5489,10 @@ var lib_plankton; "indentation": indentation(true, options.level), "arguments": (type_construction.arguments .map(function (argument) { return render_type(argument, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join(",\n")), - })), + .join(",\n")) + })) }); } else if (type instanceof prog.struct_type_union) { @@ -4406,11 +5502,11 @@ var lib_plankton; "indentation2": indentation(true, options.level), "indentation3": indentation(true, options.level + 1), "left": render_type(type_union.left, { - "level": (options.level + 1), + "level": (options.level + 1) }), "right": render_type(type_union.right, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_intersection) { @@ -4419,11 +5515,11 @@ var lib_plankton; "indentation1": indentation(options.indent, options.level), "indentation2": indentation(true, options.level + 1), "left": render_type(type_intersection.left, { - "level": (options.level + 1), + "level": (options.level + 1) }), "right": render_type(type_intersection.right, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else { @@ -4437,20 +5533,20 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": false, - "level": 0, + "level": 0 }, options); if (expression instanceof prog.struct_expression_variable) { var expression_variable = expression; return lib_plankton.string.coin("{{indentation}}{{name}}", { "indentation": indentation(options.indent, options.level), - "name": expression.name, + "name": expression.name }); } else if (expression instanceof prog.struct_expression_literal) { var expression_literal = expression; return lib_plankton.string.coin("{{indentation}}{{value}}", { "indentation": indentation(options.indent, options.level), - "value": JSON.stringify(expression_literal.value), + "value": JSON.stringify(expression_literal.value) }); } else if (expression instanceof prog.struct_expression_list) { @@ -4463,10 +5559,10 @@ var lib_plankton; "indentation": indentation(true, options.level + 1), "value": render_expression(element, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_dict) { @@ -4480,10 +5576,10 @@ var lib_plankton; "key": field.key, "value": render_expression(field.value, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_abstraction) { @@ -4501,7 +5597,7 @@ var lib_plankton; ? "" : lib_plankton.string.coin(" : {{type}}", { "type": render_type(argument.type) - })), + })) }); }) .join(", ")), "macro_output_type": ((expression_abstraction.output_type === null) @@ -4509,14 +5605,14 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(expression_abstraction.output_type, { "indent": false, - "level": (options.level + 1), + "level": (options.level + 1) }) })), "body": (expression_abstraction.body .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (expression instanceof prog.struct_expression_function_application) { @@ -4526,16 +5622,16 @@ var lib_plankton; "indentation2": indentation(true, options.level), "name": render_expression(expression_function_application.head, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "arguments": (expression_function_application.arguments .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { "argument": render_expression(argument, { "indent": true, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_projection) { @@ -4543,7 +5639,7 @@ var lib_plankton; return lib_plankton.string.coin("{{indentation}}{{source}}[{{index}}]", { "indentation": indentation(options.indent, options.level), "source": render_expression(expression_projection.source), - "index": render_expression(expression_projection.index), + "index": render_expression(expression_projection.index) }); } else if (expression instanceof prog.struct_expression_fieldaccess) { @@ -4551,9 +5647,9 @@ var lib_plankton; return lib_plankton.string.coin("{{indentation}}{{structure}}.{{fieldname}}", { "indentation": indentation(options.indent, options.level), "structure": render_expression(expression_fieldaccess.structure, { - "level": (options.level + 1), + "level": (options.level + 1) }), - "fieldname": expression_fieldaccess.fieldname, + "fieldname": expression_fieldaccess.fieldname }); } else if (expression instanceof prog.struct_expression_operation_comparison) { @@ -4562,12 +5658,12 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "left": render_expression(expression_operation_comparison.left, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "right": render_expression(expression_operation_comparison.right, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (expression instanceof prog.struct_expression_await) { @@ -4576,8 +5672,8 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "target": render_expression(expression_await.target, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (expression instanceof prog.struct_expression_cast) { @@ -4586,12 +5682,12 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "expression": render_expression(expression_cast.expression, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "type": render_type(expression_cast.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else { @@ -4605,7 +5701,7 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": true, - "level": 0, + "level": 0 }, options); if (statement instanceof prog.struct_statement_comment) { var statement_comment = statement; @@ -4615,17 +5711,17 @@ var lib_plankton; "lines": (statement_comment.lines .map(function (line) { return lib_plankton.string.coin("{{indentation}} * {{line}}\n", { "indentation": indentation(options.indent, options.level), - "line": line, + "line": line }); }) - .join("")), + .join("")) }) : lib_plankton.string.coin("{{lines}}", { "lines": (statement_comment.lines .map(function (line) { return lib_plankton.string.coin("{{indentation}}// {{line}}\n", { "indentation": indentation(options.indent, options.level), - "line": line, + "line": line }); }) - .join("")), + .join("")) })); } else if (statement instanceof prog.struct_statement_block) { @@ -4634,9 +5730,9 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "statements": (statement_block.statements .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (statement instanceof prog.struct_statement_type_definition) { @@ -4649,8 +5745,8 @@ var lib_plankton; : "export "), "type": render_type(statement_type_definition.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (statement instanceof prog.struct_statement_declaration) { @@ -4669,17 +5765,17 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(statement_declaration.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) })), "macro_value": ((statement_declaration.value === null) ? "" : lib_plankton.string.coin(" = {{value}}", { "value": render_expression(statement_declaration.value, { "indent": false, - "level": (options.level + 0), - }), - })), + "level": (options.level + 0) + }) + })) }); } else if (statement instanceof prog.struct_statement_assignment) { @@ -4689,8 +5785,8 @@ var lib_plankton; "name": statement_assignment.name, "value": render_expression(statement_assignment.value, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (statement instanceof prog.struct_statement_procedure_call) { @@ -4700,16 +5796,16 @@ var lib_plankton; "indentation2": indentation(true, options.level), "name": render_expression(statement_procedure_call.head, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "arguments": (statement_procedure_call.arguments .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { "argument": render_expression(argument, { "indent": true, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (statement instanceof prog.struct_statement_function_definition) { @@ -4730,9 +5826,9 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(argument.type, { "indent": false, - "level": (options.level + 2), + "level": (options.level + 2) }) - })), + })) }); }) .join(",\n")), "macro_output_type": ((statement_function_definition.output_type === null) @@ -4740,15 +5836,15 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(statement_function_definition.output_type, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }) })), "body": (statement_function_definition.body .map(function (statement) { return render_statement(statement, { "indent": true, - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (statement instanceof prog.struct_statement_return) { @@ -4757,8 +5853,8 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "expression": render_expression(statement_return.expression, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else { @@ -4772,7 +5868,7 @@ var lib_plankton; return (program.statements .map(function (statement) { return render_statement(statement, { "indent": true, - "level": 0, + "level": 0 }); }) .join("\n")); } @@ -4784,7 +5880,7 @@ var lib_plankton; "render_expression": render_expression, "render_type": render_type, "render_statement": render_statement, - "render_program": render_program, + "render_program": render_program }; } typescript.output_typescript = output_typescript; @@ -4794,7 +5890,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -4853,7 +5949,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -4914,8 +6010,8 @@ var lib_plankton; "info": info, "hidden": hidden, "parameters": { - "index": index, - }, + "index": index + } })); }; /** @@ -4933,8 +6029,8 @@ var lib_plankton; "hidden": hidden, "parameters": { "indicators_short": indicators_short, - "indicators_long": indicators_long, - }, + "indicators_long": indicators_long + } })); }; /** @@ -5151,7 +6247,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -5180,17 +6276,17 @@ var lib_plankton; "symbols": { "delimiter": " ", "prefix": "--", - "assignment": "=", - }, + "assignment": "=" + } }, "url": { "symbols": { "delimiter": "&", "prefix": "", - "assignment": "=", + "assignment": "=" } } - }, + } }; /** * @author fenris @@ -5267,14 +6363,14 @@ var lib_plankton; "pattern_from": pattern_from, "pattern_to": pattern_to, "input": input, - "result": result, + "result": result }); input = result; } } } lib_plankton.log.debug("lib_args:read:current_input", { - "input": input, + "input": input }); } // parsing @@ -5285,18 +6381,18 @@ var lib_plankton; var index_expected_1 = 0; parts.forEach(function (part) { lib_plankton.log.debug("lib_args:read:analyzing", { - "part": part, + "part": part }); var found = [ function () { lib_plankton.log.debug("lib_args:read:probing_as_volatile", { - "part": part, + "part": part }); for (var _i = 0, _a = Object.entries(_this.filter(args.enum_kind.volatile)); _i < _a.length; _i++) { var _b = _a[_i], name = _b[0], argument = _b[1]; lib_plankton.log.debug("lib_args:read:probing_as_volatile:trying", { "part": part, - "argument": argument.toString(), + "argument": argument.toString() }); var pattern = ""; { @@ -5315,12 +6411,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern, + "pattern": pattern }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { - "matching": matching, + "matching": matching }); if (matching == null) { // do nothing @@ -5334,7 +6430,7 @@ var lib_plankton; }, function () { lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part, + "part": part }); var positional = _this.filter(args.enum_kind.positional); for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) { @@ -5345,7 +6441,7 @@ var lib_plankton; else { lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { "part": part, - "argument": argument.toString(), + "argument": argument.toString() }); var pattern = ""; { @@ -5354,12 +6450,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", { - "pattern": pattern, + "pattern": pattern }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_positional:matching", { - "matching": matching, + "matching": matching }); if (matching == null) { return false; @@ -5376,7 +6472,7 @@ var lib_plankton; ].some(function (x) { return x(); }); if (!found) { lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part, + "part": part }); } }); @@ -5692,7 +6788,9 @@ var _sindri; }, } ]); - })), true); + })), { + "formatted": true + }); } jsonschema.render = render; })(jsonschema = other.jsonschema || (other.jsonschema = {})); @@ -6026,7 +7124,7 @@ var _sindri; .concat((domain.key_field === null) ? [] : lib_plankton.string.coin("{{name}} {{parameters}}", { - "name": domain.key_field.name, + "name": ('"' + domain.key_field.name + '"'), "parameters": ([ "SERIAL", ] @@ -6035,7 +7133,7 @@ var _sindri; // data fields .concat(domain.data_fields .map((data_field) => lib_plankton.string.coin("{{name}} {{parameters}}", { - "name": data_field.name, + "name": ('"' + data_field.name + '"'), "parameters": (( // type [ @@ -6063,6 +7161,20 @@ var _sindri; }))) // constraints .concat(domain["constraints"] + .concat((domain.key_field === null) + ? + [] + : + [ + { + "kind": "unique", + "parameters": { + "fields": [ + domain.key_field.name, + ] + } + }, + ]) .map((constraint) => { switch (constraint.kind) { default: { @@ -6072,11 +7184,11 @@ var _sindri; case "foreign_key": { return lib_plankton.string.coin("FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})", { "fields": (constraint.parameters["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",")), - "reference_name": constraint.parameters["reference"]["name"], + "reference_name": ('"' + constraint.parameters["reference"]["name"] + '"'), "reference_fields": (constraint.parameters["reference"]["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",")), }); break; @@ -6084,7 +7196,7 @@ var _sindri; case "unique": { return lib_plankton.string.coin("UNIQUE ({{fields}})", { "fields": (constraint.parameters["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",")), }); break;