git.schokokeks.org
Repositories
Help
Report an Issue
wirc-backend.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
c972b0c
Branches
Tags
master
wirc-backend.git
lib
plankton
plankton.js
[ini]
Christian Fraß
commited
c972b0c
at 2021-11-18 23:53:54
plankton.js
Blame
History
Raw
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ // } /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ /** * @author fenris */ /*export*/ function pseudopointer_null() { return { "value": null }; } /** * @author fenris */ /*export*/ function pseudopointer_make(value) { return { "value": value }; } /** * @author fenris */ /*export*/ function pseudopointer_isset(pseudopointer) { return (pseudopointer.value != null); } /** * @author fenris */ /*export*/ function pseudopointer_read(pseudopointer) { if (pseudopointer.value != null) { return pseudopointer.value; } else { var message = "nullpointer dereferencation"; throw (new Error(message)); } } /** * @author fenris */ /*export*/ function pseudopointer_write(pseudopointer, value) { pseudopointer.value = value; } /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ ; var lib_base; (function (lib_base) { /** * @author fenris */ function environment() { var entries = [ { "id": "web", "name": "Web", "predicate": function () { return (typeof (document) !== "undefined"); }, }, { "id": "node", "name": "Node.js", "predicate": function () { return (typeof (process) !== "undefined"); }, }, { "id": "rhino", "name": "Rhino", "predicate": function () { return (typeof (java) !== "undefined"); }, }, { "id": "webworker", "name": "WebWorker", "predicate": function () { return (typeof (self["WorkerNavigator"]) !== "undefined"); } } ]; var id; var found = entries.some(function (entry) { if (entry.predicate()) { id = entry.id; return true; } else { return false; } }); if (found) { return id; } else { throw (new Error("unknown environment")); } } lib_base.environment = environment; })(lib_base || (lib_base = {})); /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ /** * @author fenris */ var instance_verbosity = 0; /** * @author fenris */ function instance_collate(value1, value2) { if (typeof (value1) === "object") { if (value1 == null) { return (value2 == null); } else { if ("_collate" in value1) { return value1["_collate"](value2); } else { throw (new Error("[collate]" + " " + "object has no such method")); } } } else { if (instance_verbosity >= 1) { lib_log.warn("[collate]" + " " + "primitive value; using default implementation"); } return (value1 === value2); } } /** * @author fenris */ function instance_compare(value1, value2) { if (typeof (value1) === "object") { if ("_compare" in value1) { return value1["_compare"](value2); } else { throw (new Error("[compare]" + " " + "object has no such method")); } } else { if (instance_verbosity >= 1) { lib_log.warn("[compare]" + " " + "primitive value; using default implementation"); } return (value1 <= value2); } } /** * @author fenris */ function instance_clone(value) { if (typeof (value) === "object") { if ("_clone" in value) { return value["_clone"](); } else { throw (new Error("[clone]" + " " + "object has no such method")); } } else { if (instance_verbosity >= 1) { lib_log.warn("[clone]" + " " + "primitive value; using default implementation"); } return value; } } /** * @desc the ability to generate a string out of the element, which identifies it to a high degree * @author fenris */ function instance_hash(value) { if (typeof (value) === "object") { if ("_hash" in value) { return value["_hash"](); } else { throw (new Error("[hash]" + " " + "object has no such method")); } } else { if (instance_verbosity >= 1) { lib_log.warn("[hash]" + " " + "primitive value; using default implementation"); } return String(value); } } /** * @desc the ability to map the element to a textual representation (most likely not injective) * @author fenris */ function instance_show(value) { if (typeof (value) === "object") { if (value == null) { return "NULL"; } else { if ("_show" in value) { return value["_show"](); } else { // throw (new Error("[show]" + " " + "object has no such method")); return JSON.stringify(value); } } } else { if (instance_verbosity >= 1) { lib_log.warn("[show]" + " " + "primitive value; using default implementation"); } return String(value); } } /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ /** * @todo outsource to dedicated plankton-lib */ var lib_log; (function (lib_log) { /** * @author fenris */ function log() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } /*window.*/ console.log.apply(console, args); } lib_log.log = log; /** * @author fenris */ function info() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } /*window.*/ console.info.apply(console, args); } lib_log.info = info; /** * @author fenris */ function warn() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } /*window.*/ console.warn.apply(console, args); } lib_log.warn = warn; /** * @author fenris */ function error() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } /*window.*/ console.error.apply(console, args); } lib_log.error = error; })(lib_log || (lib_log = {})); /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ /** * @author frac */ var class_observer = /** @class */ (function () { /** * @author frac */ function class_observer() { this.counter = 0; this.actions = {}; this.buffer = []; } /** * @author frac */ class_observer.prototype.empty = function () { return (Object.keys(this.actions).length == 0); }; /** * @author frac */ class_observer.prototype.flush = function () { this.actions = {}; }; /** * @author frac */ class_observer.prototype.set = function (id, action) { this.actions[id] = action; }; /** * @author frac */ class_observer.prototype.del = function (id) { delete this.actions[id]; }; /** * @author frac */ class_observer.prototype.add = function (action) { this.set((this.counter++).toString(), action); }; /** * @author frac */ class_observer.prototype.notify = function (information, delayed) { var _this = this; if (information === void 0) { information = {}; } if (delayed === void 0) { delayed = false; } if (delayed) { this.buffer.push(information); } else { Object.keys(this.actions).forEach(function (id) { return _this.actions[id](information); }); } }; /** * @author frac */ class_observer.prototype.rollout = function () { var _this = this; this.buffer.forEach(function (information) { return _this.notify(information, false); }); this.buffer = []; }; return class_observer; }()); /** * @author frac */ /* export interface interface_readable<type_value> { |** * @author frac *| read() : type_executor<type_value, Error>; } */ /** * @author frac */ /* export interface interface_writeable<type_value> { |** * @author frac *| write(value : type_value) : type_executor<void, Error>; } */ /* This file is part of »bacterio-plankton:base«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ 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_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 "<- " + 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 "<+ " + 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-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »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 <http://www.gnu.org/licenses/>. */ /** * @author frac */ var class_error = /** @class */ (function (_super) { __extends(class_error, _super); /** * @author frac */ function class_error(message, suberrors) { if (suberrors === void 0) { suberrors = []; } var _this = _super.call(this, message) || this; _this.suberrors = suberrors; _this.mess = message; return _this; } /** * @override * @author frac */ class_error.prototype.toString = function () { return ( /*super.toString()*/this.mess + " " + ("[" + this.suberrors.map(function (x) { return x.toString(); }).join(",") + "]")); }; return class_error; }(Error)); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ function inverse_encode(decode, to) { return decode(to); } lib_code.inverse_encode = inverse_encode; /** * @author fenris */ function inverse_decode(encode, from) { return encode(from); } lib_code.inverse_decode = inverse_decode; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ var class_code_inverse = /** @class */ (function () { /** * @author fenris */ function class_code_inverse(subject) { this.subject = subject; } /** * @implementation * @author fenris */ class_code_inverse.prototype.encode = function (to) { var _this = this; return lib_code.inverse_encode(function (x) { return _this.subject.decode(x); }, to); }; /** * @implementation * @author fenris */ class_code_inverse.prototype.decode = function (from) { var _this = this; return lib_code.inverse_decode(function (x) { return _this.subject.encode(x); }, from); }; return class_code_inverse; }()); lib_code.class_code_inverse = class_code_inverse; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ function pair_encode(encode_first, encode_second, from) { var between = encode_first(from); var to = encode_second(between); return to; } lib_code.pair_encode = pair_encode; /** * @author fenris */ function pair_decode(decode_first, decode_second, to) { var between = decode_second(to); var from = decode_first(between); return from; } lib_code.pair_decode = pair_decode; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ var class_code_pair = /** @class */ (function () { /** * @author fenris */ function class_code_pair(first, second) { this.first = first; this.second = second; } /** * @implementation * @author fenris */ class_code_pair.prototype.encode = function (from) { var _this = this; return lib_code.pair_encode(function (x) { return _this.first.encode(x); }, function (x) { return _this.second.encode(x); }, from); }; /** * @implementation * @author fenris */ class_code_pair.prototype.decode = function (to) { var _this = this; return lib_code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to); }; return class_code_pair; }()); lib_code.class_code_pair = class_code_pair; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ function chain_encode(encode_links, from) { var value = from; encode_links .forEach(function (link) { value = link(value); }); return value; } lib_code.chain_encode = chain_encode; /** * @author fenris */ function chain_decode(decode_links, to) { var value = to; decode_links .reverse() .forEach(function (link) { value = link(value); }); return value; } lib_code.chain_decode = chain_decode; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ var class_code_chain = /** @class */ (function () { /** * @author fenris */ function class_code_chain(links) { this.links = links; } /** * @implementation * @author fenris */ class_code_chain.prototype.encode = function (from) { return lib_code.chain_encode(this.links.map(function (link) { return (function (x) { return link.encode(x); }); }), from); }; /** * @implementation * @author fenris */ class_code_chain.prototype.decode = function (to) { return lib_code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to); }; return class_code_chain; }()); lib_code.class_code_chain = class_code_chain; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author Christian Fraß <frass@greenscale.de> */ function flatten_encode(from, keys) { if (keys === void 0) { keys = null; } if (keys === null) { if (from.length > 0) { keys = Object.keys(from[0]); } else { throw (new Error("encoding impossible")); } } return { "keys": keys, "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }) }; } lib_code.flatten_encode = flatten_encode; /** * @author Christian Fraß <frass@greenscale.de> */ function flatten_decode(to) { return (to.data .map(function (dataset) { var dataset_ = {}; dataset .forEach(function (value, index) { var name = to.keys[index]; dataset_[name] = value; }); return dataset_; })); } lib_code.flatten_decode = flatten_decode; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:code«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:code« 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:code« 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:code«. If not, see <http://www.gnu.org/licenses/>. */ var lib_code; (function (lib_code) { /** * @author fenris */ var class_code_flatten = /** @class */ (function () { /** * @author fenris */ function class_code_flatten() { } /** * @implementation * @author fenris */ class_code_flatten.prototype.encode = function (x) { return lib_code.flatten_encode(x); }; /** * @implementation * @author fenris */ class_code_flatten.prototype.decode = function (x) { return lib_code.flatten_decode(x); }; return class_code_flatten; }()); lib_code.class_code_flatten = class_code_flatten; })(lib_code || (lib_code = {})); /* This file is part of »bacterio-plankton:http«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:http« 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:http« 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:http«. If not, see <http://www.gnu.org/licenses/>. */ var lib_http; (function (lib_http) { /** * @author fenris <frass@greenscale.de> */ let enum_method; (function (enum_method) { enum_method["get"] = "get"; enum_method["post"] = "post"; enum_method["options"] = "options"; // put = "put", // delete = "delete", // head = "head", })(enum_method = lib_http.enum_method || (lib_http.enum_method = {})); })(lib_http || (lib_http = {})); /* This file is part of »bacterio-plankton:http«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:http« 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:http« 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:http«. If not, see <http://www.gnu.org/licenses/>. */ var lib_http; (function (lib_http) { /** * @author fenris <frass@greenscale.de> */ const linebreak = "\r\n"; /** * @author fenris <frass@greenscale.de> */ function encode_method(method) { switch (method) { case lib_http.enum_method.get: return "GET"; case lib_http.enum_method.post: return "POST"; case lib_http.enum_method.options: return "OPTIONS"; default: throw (new Error("impossible")); } } /** * @author fenris <frass@greenscale.de> */ function decode_method(method_raw) { switch (method_raw) { case "GET": return lib_http.enum_method.get; case "POST": return lib_http.enum_method.post; case "OPTIONS": return lib_http.enum_method.options; default: throw (new Error("unhandled method: " + method_raw)); } } /** * @author fenris <frass@greenscale.de> */ function get_statustext(statuscode) { switch (statuscode) { case 100: return "Continue"; case 101: return "Switching Protocols"; case 103: return "Early Hints"; case 200: return "OK"; case 201: return "Created"; case 202: return "Accepted"; case 203: return "Non-Authoritative Information"; case 204: return "No Content"; case 205: return "Reset Content"; case 206: return "Partial Content"; case 300: return "Multiple Choices"; case 301: return "Moved Permanently"; case 302: return "Found"; case 303: return "See Other"; case 304: return "Not Modified"; case 307: return "Temporary Redirect"; case 308: return "Permanent Redirect"; case 400: return "Bad Request"; case 401: return "Unauthorized"; case 402: return "Payment Required"; case 403: return "Forbidden"; case 404: return "Not Found"; case 405: return "Method Not Allowed"; case 406: return "Not Acceptable"; case 407: return "Proxy Authentication Required"; case 408: return "Request Timeout"; case 409: return "Conflict"; case 410: return "Gone"; case 411: return "Length Required"; case 412: return "Precondition Failed"; case 413: return "Payload Too Large"; case 414: return "URI Too Long"; case 415: return "Unsupported Media Type"; case 416: return "Range Not Satisfiable"; case 417: return "Expectation Failed"; case 418: return "I'm a teapot"; case 422: return "Unprocessable Entity"; case 425: return "Too Early"; case 426: return "Upgrade Required"; case 428: return "Precondition Required"; case 429: return "Too Many Requests"; case 431: return "Request Header Fields Too Large"; case 451: return "Unavailable For Legal Reasons"; case 500: return "Internal Server Error"; case 501: return "Not Implemented"; case 502: return "Bad Gateway"; case 503: return "Service Unavailable"; case 504: return "Gateway Timeout"; case 505: return "HTTP Version Not Supported"; case 506: return "Variant Also Negotiates"; case 507: return "Insufficient Storage"; case 508: return "Loop Detected"; case 510: return "Not Extended"; case 511: return "Network Authentication"; default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0))); } } /** * @author fenris <frass@greenscale.de> */ function encode_request(request) { let request_raw = ""; request_raw += (encode_method(request.method) + " " + request.query + " " + "HTTP/1.1" + linebreak); request_raw += ("Host: " + request.host + linebreak); for (const [key, value] of Object.entries(request.headers)) { request_raw += (key + ": " + value + linebreak); } request_raw += linebreak; request_raw += request.body; return request_raw; } lib_http.encode_request = encode_request; /** * @author fenris <frass@greenscale.de> */ function decode_request(request_raw) { const lines = request_raw.split(linebreak); const first = lines.shift(); const [method_raw, query, version] = first.split(" "); let headers = {}; while (true) { const line = lines.shift(); if (line === "") { break; } else { const [key, value] = line.split(": ", 2); headers[key] = value; } } const body = lines.join(linebreak); const request = { "host": headers["Host"], "query": query, "method": decode_method(method_raw), "headers": headers, "body": body, }; return request; } lib_http.decode_request = decode_request; /** * @author fenris <frass@greenscale.de> */ function encode_response(response) { let response_raw = ""; response_raw += ("HTTP/1.1" + " " + response.statuscode + " " + get_statustext(response.statuscode) + linebreak); for (const [key, value] of Object.entries(response.headers)) { response_raw += (key + ": " + value + linebreak); } response_raw += linebreak; response_raw += response.body; return response_raw; } lib_http.encode_response = encode_response; /** * @author fenris <frass@greenscale.de> */ function decode_response(response_raw) { const lines = response_raw.split(linebreak); const first = lines.shift(); const statuscode = parseInt(first.split(" ")[1]); let headers = {}; while (true) { const line = lines.shift(); if (line === "") { break; } else { const [key, value] = line.split(": ", 2); headers[key] = value; } } const body = lines.join(linebreak); const response = { "statuscode": statuscode, "headers": headers, "body": body, }; return response; } lib_http.decode_response = decode_response; })(lib_http || (lib_http = {})); /* This file is part of »bacterio-plankton:http«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:http« 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:http« 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:http«. If not, see <http://www.gnu.org/licenses/>. */ var lib_http; (function (lib_http) { /** * @author fenris */ class class_http_request { /** * @author fenris */ constructor() { } /** * @implementation * @author fenris */ encode(x) { return lib_http.encode_request(x); } /** * @implementation * @author fenris */ decode(x) { return lib_http.decode_request(x); } } lib_http.class_http_request = class_http_request; /** * @author fenris */ class class_http_response { /** * @author fenris */ constructor() { } /** * @implementation * @author fenris */ encode(x) { return lib_http.encode_response(x); } /** * @implementation * @author fenris */ decode(x) { return lib_http.decode_response(x); } } lib_http.class_http_response = class_http_response; })(lib_http || (lib_http = {})); /* This file is part of »bacterio-plankton:server«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:server« 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:server« 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:server«. If not, see <http://www.gnu.org/licenses/>. */ var lib_server; (function (lib_server) { /** * @author fenris */ function make(port, handle, verbosity = 1) { return { "port": port, "handle": handle, "verbosity": verbosity, "serverobj": undefined, }; } lib_server.make = make; /** * @author fenris */ function log(subject, level, message) { if (subject.verbosity >= level) { console.log("[server]", message); } else { // do nothing } } /** * @author fenris */ function start(subject) { const net = require("net"); return (new Promise((resolve, reject) => { subject.serverobj = net.createServer((socket) => { log(subject, 2, "client connected"); socket.on("readable", () => { let chunk; while (!((chunk = socket.read()) === null)) { const input = chunk.toString(); log(subject, 3, "reading: " + input); subject.handle(input) .then((output) => { log(subject, 3, "writing: " + output); socket.write(output); socket.end(); }); } }); socket.on("end", () => { log(subject, 2, "client disconnected"); }); }); subject.serverobj.on("error", (error) => { throw error; }); subject.serverobj.listen(subject.port, () => { log(subject, 1, "listening on port " + subject.port.toFixed(0)); resolve(undefined); }); })); } lib_server.start = start; /** * @author fenris */ function kill(subject) { subject.serverobj.close(); } lib_server.kill = kill; })(lib_server || (lib_server = {})); /* This file is part of »bacterio-plankton:server«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:server« 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:server« 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:server«. If not, see <common://www.gnu.org/licenses/>. */ var lib_server; (function (lib_server) { /** * @author fenris */ class class_server { /** * @author fenris */ constructor(port, handle, verbosity = undefined) { this.subject = lib_server.make(port, handle, verbosity); } /** * @author fenris */ start() { return lib_server.start(this.subject); } /** * @author fenris */ kill() { return lib_server.kill(this.subject); } } lib_server.class_server = class_server; })(lib_server || (lib_server = {}));