a277bab9fa0053c0d3222f2462bdfcb896c21a17
Christian Fraß [ini]

Christian Fraß authored 2 years ago

1) var __extends = (this && this.__extends) || (function () {
2)     var extendStatics = function (d, b) {
3)         extendStatics = Object.setPrototypeOf ||
4)             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5)             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6)         return extendStatics(d, b);
7)     };
8)     return function (d, b) {
9)         extendStatics(d, b);
10)         function __() { this.constructor = d; }
11)         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12)     };
13) })();
14) /*
15) This file is part of »bacterio-plankton:base«.
16) 
17) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
18) <info@greenscale.de>
19) 
20) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
21) it under the terms of the GNU Lesser General Public License as published by
22) the Free Software Foundation, either version 3 of the License, or
23) (at your option) any later version.
24) 
25) »bacterio-plankton:base« is distributed in the hope that it will be useful,
26) but WITHOUT ANY WARRANTY; without even the implied warranty of
27) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28) GNU Lesser General Public License for more details.
29) 
30) You should have received a copy of the GNU Lesser General Public License
31) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
32)  */
33) // }
34) /*
35) This file is part of »bacterio-plankton:base«.
36) 
37) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
38) <info@greenscale.de>
39) 
40) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
41) it under the terms of the GNU Lesser General Public License as published by
42) the Free Software Foundation, either version 3 of the License, or
43) (at your option) any later version.
44) 
45) »bacterio-plankton:base« is distributed in the hope that it will be useful,
46) but WITHOUT ANY WARRANTY; without even the implied warranty of
47) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48) GNU Lesser General Public License for more details.
49) 
50) You should have received a copy of the GNU Lesser General Public License
51) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
52)  */
53) /**
54)  * @author fenris
55)  */
56) /*export*/ function pseudopointer_null() {
57)     return {
58)         "value": null
59)     };
60) }
61) /**
62)  * @author fenris
63)  */
64) /*export*/ function pseudopointer_make(value) {
65)     return {
66)         "value": value
67)     };
68) }
69) /**
70)  * @author fenris
71)  */
72) /*export*/ function pseudopointer_isset(pseudopointer) {
73)     return (pseudopointer.value != null);
74) }
75) /**
76)  * @author fenris
77)  */
78) /*export*/ function pseudopointer_read(pseudopointer) {
79)     if (pseudopointer.value != null) {
80)         return pseudopointer.value;
81)     }
82)     else {
83)         var message = "nullpointer dereferencation";
84)         throw (new Error(message));
85)     }
86) }
87) /**
88)  * @author fenris
89)  */
90) /*export*/ function pseudopointer_write(pseudopointer, value) {
91)     pseudopointer.value = value;
92) }
93) /*
94) This file is part of »bacterio-plankton:base«.
95) 
96) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
97) <info@greenscale.de>
98) 
99) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
100) it under the terms of the GNU Lesser General Public License as published by
101) the Free Software Foundation, either version 3 of the License, or
102) (at your option) any later version.
103) 
104) »bacterio-plankton:base« is distributed in the hope that it will be useful,
105) but WITHOUT ANY WARRANTY; without even the implied warranty of
106) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107) GNU Lesser General Public License for more details.
108) 
109) You should have received a copy of the GNU Lesser General Public License
110) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
111)  */
112) ;
113) var lib_base;
114) (function (lib_base) {
115)     /**
116)      * @author fenris
117)      */
118)     function environment() {
119)         var entries = [
120)             {
121)                 "id": "web",
122)                 "name": "Web",
123)                 "predicate": function () { return (typeof (document) !== "undefined"); },
124)             },
125)             {
126)                 "id": "node",
127)                 "name": "Node.js",
128)                 "predicate": function () { return (typeof (process) !== "undefined"); },
129)             },
130)             {
131)                 "id": "rhino",
132)                 "name": "Rhino",
133)                 "predicate": function () { return (typeof (java) !== "undefined"); },
134)             },
135)             {
136)                 "id": "webworker",
137)                 "name": "WebWorker",
138)                 "predicate": function () { return (typeof (self["WorkerNavigator"]) !== "undefined"); }
139)             }
140)         ];
141)         var id;
142)         var found = entries.some(function (entry) {
143)             if (entry.predicate()) {
144)                 id = entry.id;
145)                 return true;
146)             }
147)             else {
148)                 return false;
149)             }
150)         });
151)         if (found) {
152)             return id;
153)         }
154)         else {
155)             throw (new Error("unknown environment"));
156)         }
157)     }
158)     lib_base.environment = environment;
159) })(lib_base || (lib_base = {}));
160) /*
161) This file is part of »bacterio-plankton:base«.
162) 
163) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
164) <info@greenscale.de>
165) 
166) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
167) it under the terms of the GNU Lesser General Public License as published by
168) the Free Software Foundation, either version 3 of the License, or
169) (at your option) any later version.
170) 
171) »bacterio-plankton:base« is distributed in the hope that it will be useful,
172) but WITHOUT ANY WARRANTY; without even the implied warranty of
173) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174) GNU Lesser General Public License for more details.
175) 
176) You should have received a copy of the GNU Lesser General Public License
177) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
178)  */
179) /**
180)  * @author fenris
181)  */
182) var instance_verbosity = 0;
183) /**
184)  * @author fenris
185)  */
186) function instance_collate(value1, value2) {
187)     if (typeof (value1) === "object") {
188)         if (value1 == null) {
189)             return (value2 == null);
190)         }
191)         else {
192)             if ("_collate" in value1) {
193)                 return value1["_collate"](value2);
194)             }
195)             else {
196)                 throw (new Error("[collate]" + " " + "object has no such method"));
197)             }
198)         }
199)     }
200)     else {
201)         if (instance_verbosity >= 1) {
202)             lib_log.warn("[collate]" + " " + "primitive value; using default implementation");
203)         }
204)         return (value1 === value2);
205)     }
206) }
207) /**
208)  * @author fenris
209)  */
210) function instance_compare(value1, value2) {
211)     if (typeof (value1) === "object") {
212)         if ("_compare" in value1) {
213)             return value1["_compare"](value2);
214)         }
215)         else {
216)             throw (new Error("[compare]" + " " + "object has no such method"));
217)         }
218)     }
219)     else {
220)         if (instance_verbosity >= 1) {
221)             lib_log.warn("[compare]" + " " + "primitive value; using default implementation");
222)         }
223)         return (value1 <= value2);
224)     }
225) }
226) /**
227)  * @author fenris
228)  */
229) function instance_clone(value) {
230)     if (typeof (value) === "object") {
231)         if ("_clone" in value) {
232)             return value["_clone"]();
233)         }
234)         else {
235)             throw (new Error("[clone]" + " " + "object has no such method"));
236)         }
237)     }
238)     else {
239)         if (instance_verbosity >= 1) {
240)             lib_log.warn("[clone]" + " " + "primitive value; using default implementation");
241)         }
242)         return value;
243)     }
244) }
245) /**
246)  * @desc the ability to generate a string out of the element, which identifies it to a high degree
247)  * @author fenris
248)  */
249) function instance_hash(value) {
250)     if (typeof (value) === "object") {
251)         if ("_hash" in value) {
252)             return value["_hash"]();
253)         }
254)         else {
255)             throw (new Error("[hash]" + " " + "object has no such method"));
256)         }
257)     }
258)     else {
259)         if (instance_verbosity >= 1) {
260)             lib_log.warn("[hash]" + " " + "primitive value; using default implementation");
261)         }
262)         return String(value);
263)     }
264) }
265) /**
266)  * @desc the ability to map the element to a textual representation (most likely not injective)
267)  * @author fenris
268)  */
269) function instance_show(value) {
270)     if (typeof (value) === "object") {
271)         if (value == null) {
272)             return "NULL";
273)         }
274)         else {
275)             if ("_show" in value) {
276)                 return value["_show"]();
277)             }
278)             else {
279)                 // throw (new Error("[show]" + " " + "object has no such method"));
280)                 return JSON.stringify(value);
281)             }
282)         }
283)     }
284)     else {
285)         if (instance_verbosity >= 1) {
286)             lib_log.warn("[show]" + " " + "primitive value; using default implementation");
287)         }
288)         return String(value);
289)     }
290) }
291) /*
292) This file is part of »bacterio-plankton:base«.
293) 
294) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
295) <info@greenscale.de>
296) 
297) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
298) it under the terms of the GNU Lesser General Public License as published by
299) the Free Software Foundation, either version 3 of the License, or
300) (at your option) any later version.
301) 
302) »bacterio-plankton:base« is distributed in the hope that it will be useful,
303) but WITHOUT ANY WARRANTY; without even the implied warranty of
304) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
305) GNU Lesser General Public License for more details.
306) 
307) You should have received a copy of the GNU Lesser General Public License
308) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
309)  */
310) /**
311)  * @todo outsource to dedicated plankton-lib
312)  */
313) var lib_log;
314) (function (lib_log) {
315)     /**
316)      * @author fenris
317)      */
318)     function log() {
319)         var args = [];
320)         for (var _i = 0; _i < arguments.length; _i++) {
321)             args[_i] = arguments[_i];
322)         }
323)         /*window.*/ console.log.apply(console, args);
324)     }
325)     lib_log.log = log;
326)     /**
327)      * @author fenris
328)      */
329)     function info() {
330)         var args = [];
331)         for (var _i = 0; _i < arguments.length; _i++) {
332)             args[_i] = arguments[_i];
333)         }
334)         /*window.*/ console.info.apply(console, args);
335)     }
336)     lib_log.info = info;
337)     /**
338)      * @author fenris
339)      */
340)     function warn() {
341)         var args = [];
342)         for (var _i = 0; _i < arguments.length; _i++) {
343)             args[_i] = arguments[_i];
344)         }
345)         /*window.*/ console.warn.apply(console, args);
346)     }
347)     lib_log.warn = warn;
348)     /**
349)      * @author fenris
350)      */
351)     function error() {
352)         var args = [];
353)         for (var _i = 0; _i < arguments.length; _i++) {
354)             args[_i] = arguments[_i];
355)         }
356)         /*window.*/ console.error.apply(console, args);
357)     }
358)     lib_log.error = error;
359) })(lib_log || (lib_log = {}));
360) /*
361) This file is part of »bacterio-plankton:base«.
362) 
363) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
364) <info@greenscale.de>
365) 
366) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
367) it under the terms of the GNU Lesser General Public License as published by
368) the Free Software Foundation, either version 3 of the License, or
369) (at your option) any later version.
370) 
371) »bacterio-plankton:base« is distributed in the hope that it will be useful,
372) but WITHOUT ANY WARRANTY; without even the implied warranty of
373) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
374) GNU Lesser General Public License for more details.
375) 
376) You should have received a copy of the GNU Lesser General Public License
377) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
378)  */
379) /**
380)  * @author frac
381)  */
382) var class_observer = /** @class */ (function () {
383)     /**
384)      * @author frac
385)      */
386)     function class_observer() {
387)         this.counter = 0;
388)         this.actions = {};
389)         this.buffer = [];
390)     }
391)     /**
392)      * @author frac
393)      */
394)     class_observer.prototype.empty = function () {
395)         return (Object.keys(this.actions).length == 0);
396)     };
397)     /**
398)      * @author frac
399)      */
400)     class_observer.prototype.flush = function () {
401)         this.actions = {};
402)     };
403)     /**
404)      * @author frac
405)      */
406)     class_observer.prototype.set = function (id, action) {
407)         this.actions[id] = action;
408)     };
409)     /**
410)      * @author frac
411)      */
412)     class_observer.prototype.del = function (id) {
413)         delete this.actions[id];
414)     };
415)     /**
416)      * @author frac
417)      */
418)     class_observer.prototype.add = function (action) {
419)         this.set((this.counter++).toString(), action);
420)     };
421)     /**
422)      * @author frac
423)      */
424)     class_observer.prototype.notify = function (information, delayed) {
425)         var _this = this;
426)         if (information === void 0) { information = {}; }
427)         if (delayed === void 0) { delayed = false; }
428)         if (delayed) {
429)             this.buffer.push(information);
430)         }
431)         else {
432)             Object.keys(this.actions).forEach(function (id) { return _this.actions[id](information); });
433)         }
434)     };
435)     /**
436)      * @author frac
437)      */
438)     class_observer.prototype.rollout = function () {
439)         var _this = this;
440)         this.buffer.forEach(function (information) { return _this.notify(information, false); });
441)         this.buffer = [];
442)     };
443)     return class_observer;
444) }());
445) /**
446)  * @author frac
447)  */
448) /*
449) export interface interface_readable<type_value> {
450) 
451)     |**
452)      * @author frac
453)      *|
454)     read() : type_executor<type_value, Error>;
455) 
456) }
457)  */
458) /**
459)  * @author frac
460)  */
461) /*
462) export interface interface_writeable<type_value> {
463) 
464)     |**
465)      * @author frac
466)      *|
467)     write(value : type_value) : type_executor<void, Error>;
468) 
469) }
470)  */
471) /*
472) This file is part of »bacterio-plankton:base«.
473) 
474) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
475) <info@greenscale.de>
476) 
477) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
478) it under the terms of the GNU Lesser General Public License as published by
479) the Free Software Foundation, either version 3 of the License, or
480) (at your option) any later version.
481) 
482) »bacterio-plankton:base« is distributed in the hope that it will be useful,
483) but WITHOUT ANY WARRANTY; without even the implied warranty of
484) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
485) GNU Lesser General Public License for more details.
486) 
487) You should have received a copy of the GNU Lesser General Public License
488) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
489)  */
490) var lib_maybe;
491) (function (lib_maybe) {
492)     /**
493)      * @author fenris
494)      */
495)     function make_nothing() {
496)         return {
497)             "kind": "nothing",
498)             "parameters": {}
499)         };
500)     }
501)     lib_maybe.make_nothing = make_nothing;
502)     /**
503)      * @author fenris
504)      */
505)     function make_just(value) {
506)         return {
507)             "kind": "just",
508)             "parameters": {
509)                 "value": value
510)             }
511)         };
512)     }
513)     lib_maybe.make_just = make_just;
514)     /**
515)      * @author fenris
516)      */
517)     function is_nothing(maybe) {
518)         return (maybe.kind === "nothing");
519)     }
520)     lib_maybe.is_nothing = is_nothing;
521)     /**
522)      * @author fenris
523)      */
524)     function is_just(maybe) {
525)         return (maybe.kind === "just");
526)     }
527)     lib_maybe.is_just = is_just;
528)     /**
529)      * @author fenris
530)      */
531)     function cull(maybe) {
532)         if (!is_just(maybe)) {
533)             var message = "cull from nothing";
534)             throw (new Error(message));
535)         }
536)         else {
537)             var value = maybe.parameters["value"];
538)             return value;
539)         }
540)     }
541)     lib_maybe.cull = cull;
542)     /**
543)      * @author fenris
544)      */
545)     function propagate(maybe, function_) {
546)         if (!is_just(maybe)) {
547)         }
548)         else {
549)             var value = maybe.parameters["value"];
550)             var maybe_ = function_(value);
551)             return maybe_;
552)         }
553)     }
554)     lib_maybe.propagate = propagate;
555) })(lib_maybe || (lib_maybe = {}));
556) /**
557)  * @author fenris
558)  */
559) /*export*/ var class_maybe = /** @class */ (function () {
560)     function class_maybe() {
561)     }
562)     /**
563)      * @desc whether the wrapper is nothing
564)      * @author fenris
565)      */
566)     class_maybe.prototype.is_nothing = function () {
567)         throw (new Error("not implemented: class_maybe.is_nothing"));
568)     };
569)     /**
570)      * @desc whether the wrapper is just
571)      * @author fenris
572)      */
573)     class_maybe.prototype.is_just = function () {
574)         throw (new Error("not implemented: class_maybe.is_just"));
575)     };
576)     /**
577)      * @desc return the value, stored in the maybe-wrapper
578)      * @author fenris
579)      */
580)     class_maybe.prototype.cull = function () {
581)         throw (new Error("not implemented: class_maybe.cull"));
582)     };
583)     /**
584)      * @author fenris
585)      */
586)     class_maybe.prototype.toString = function () {
587)         throw (new Error("not implemented: class_maybe.cull"));
588)     };
589)     /**
590)      * @author fenris
591)      */
592)     class_maybe.prototype.distinguish = function (action_just, action_nothing) {
593)         if (action_nothing === void 0) { action_nothing = function () { }; }
594)         throw (new Error("not implemented: class_maybe.distinguish"));
595)     };
596)     /**
597)      * @author fenris
598)      */
599)     class_maybe.prototype.propagate = function (action) {
600)         throw (new Error("not implemented: class_maybe.propagate"));
601)     };
602)     /**
603)      * @desc [implementation]
604)      * @author fenris
605)      */
606)     class_maybe.prototype._show = function () {
607)         return this.toString();
608)     };
609)     return class_maybe;
610) }());
611) /**
612)  * @author fenris
613)  */
614) /*export*/ var class_nothing = /** @class */ (function (_super) {
615)     __extends(class_nothing, _super);
616)     /**
617)      * @author fenris
618)      */
619)     function class_nothing(reason) {
620)         if (reason === void 0) { reason = null; }
621)         var _this = _super.call(this) || this;
622)         _this.reason = reason;
623)         return _this;
624)     }
625)     /**
626)      * @author fenris
627)      */
628)     class_nothing.prototype.is_nothing = function () {
629)         return true;
630)     };
631)     /**
632)      * @author fenris
633)      */
634)     class_nothing.prototype.is_just = function () {
635)         return false;
636)     };
637)     /**
638)      * @author fenris
639)      */
640)     class_nothing.prototype.cull = function () {
641)         var message = "you shouldn't cull a nothing-value …";
642)         lib_log.warn(message);
643)         return null;
644)     };
645)     /**
646)      * @author fenris
647)      */
648)     class_nothing.prototype.toString = function () {
649)         return "<\u00B7>";
650)     };
651)     /**
652)      * @author fenris
653)      */
654)     class_nothing.prototype.reason_get = function () {
655)         var content = ((this.reason == null) ? "·" : this.reason);
656)         return "<- " + content + " ->";
657)     };
658)     /**
659)      * @author fenris
660)      */
661)     class_nothing.prototype.distinguish = function (action_just, action_nothing) {
662)         if (action_nothing === void 0) { action_nothing = function () { }; }
663)         action_nothing(this.reason);
664)     };
665)     /**
666)      * @author fenris
667)      */
668)     class_nothing.prototype.propagate = function (action) {
669)         return (new class_nothing(this.reason));
670)     };
671)     return class_nothing;
672) }(class_maybe));
673) /**
674)  * @author fenris
675)  */
676) /*export*/ var class_just = /** @class */ (function (_super) {
677)     __extends(class_just, _super);
678)     /**
679)      * @author fenris
680)      */
681)     function class_just(value) {
682)         var _this = _super.call(this) || this;
683)         _this.value = value;
684)         return _this;
685)     }
686)     /**
687)      * @author fenris
688)      */
689)     class_just.prototype.is_nothing = function () {
690)         return false;
691)     };
692)     /**
693)      * @author fenris
694)      */
695)     class_just.prototype.is_just = function () {
696)         return true;
697)     };
698)     /**
699)      * @author fenris
700)      */
701)     class_just.prototype.cull = function () {
702)         return this.value;
703)     };
704)     /**
705)      * @author fenris
706)      */
707)     class_just.prototype.toString = function () {
708)         var content = instance_show(this.value);
709)         return "<+ " + content + " +>";
710)     };
711)     /**
712)      * @author fenris
713)      */
714)     class_just.prototype.distinguish = function (action_just, action_nothing) {
715)         if (action_nothing === void 0) { action_nothing = function () { }; }
716)         action_just(this.value);
717)     };
718)     /**
719)      * @author fenris
720)      */
721)     class_just.prototype.propagate = function (action) {
722)         return action(this.value);
723)     };
724)     return class_just;
725) }(class_maybe));
726) /*
727) This file is part of »bacterio-plankton:base«.
728) 
729) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
730) <info@greenscale.de>
731) 
732) »bacterio-plankton:base« is free software: you can redistribute it and/or modify
733) it under the terms of the GNU Lesser General Public License as published by
734) the Free Software Foundation, either version 3 of the License, or
735) (at your option) any later version.
736) 
737) »bacterio-plankton:base« is distributed in the hope that it will be useful,
738) but WITHOUT ANY WARRANTY; without even the implied warranty of
739) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
740) GNU Lesser General Public License for more details.
741) 
742) You should have received a copy of the GNU Lesser General Public License
743) along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
744)  */
745) /**
746)  * @author frac
747)  */
748) var class_error = /** @class */ (function (_super) {
749)     __extends(class_error, _super);
750)     /**
751)      * @author frac
752)      */
753)     function class_error(message, suberrors) {
754)         if (suberrors === void 0) { suberrors = []; }
755)         var _this = _super.call(this, message) || this;
756)         _this.suberrors = suberrors;
757)         _this.mess = message;
758)         return _this;
759)     }
760)     /**
761)      * @override
762)      * @author frac
763)      */
764)     class_error.prototype.toString = function () {
765)         return ( /*super.toString()*/this.mess + " " + ("[" + this.suberrors.map(function (x) { return x.toString(); }).join(",") + "]"));
766)     };
767)     return class_error;
768) }(Error));
769) /*
770) This file is part of »bacterio-plankton:code«.
771) 
772) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
773) <info@greenscale.de>
774) 
775) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
776) it under the terms of the GNU Lesser General Public License as published by
777) the Free Software Foundation, either version 3 of the License, or
778) (at your option) any later version.
779) 
780) »bacterio-plankton:code« is distributed in the hope that it will be useful,
781) but WITHOUT ANY WARRANTY; without even the implied warranty of
782) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
783) GNU Lesser General Public License for more details.
784) 
785) You should have received a copy of the GNU Lesser General Public License
786) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
787)  */
788) /*
789) This file is part of »bacterio-plankton:code«.
790) 
791) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
792) <info@greenscale.de>
793) 
794) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
795) it under the terms of the GNU Lesser General Public License as published by
796) the Free Software Foundation, either version 3 of the License, or
797) (at your option) any later version.
798) 
799) »bacterio-plankton:code« is distributed in the hope that it will be useful,
800) but WITHOUT ANY WARRANTY; without even the implied warranty of
801) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
802) GNU Lesser General Public License for more details.
803) 
804) You should have received a copy of the GNU Lesser General Public License
805) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
806)  */
807) /*
808) This file is part of »bacterio-plankton:code«.
809) 
810) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
811) <info@greenscale.de>
812) 
813) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
814) it under the terms of the GNU Lesser General Public License as published by
815) the Free Software Foundation, either version 3 of the License, or
816) (at your option) any later version.
817) 
818) »bacterio-plankton:code« is distributed in the hope that it will be useful,
819) but WITHOUT ANY WARRANTY; without even the implied warranty of
820) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
821) GNU Lesser General Public License for more details.
822) 
823) You should have received a copy of the GNU Lesser General Public License
824) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
825)  */
826) var lib_code;
827) (function (lib_code) {
828)     /**
829)      * @author fenris
830)      */
831)     function inverse_encode(decode, to) {
832)         return decode(to);
833)     }
834)     lib_code.inverse_encode = inverse_encode;
835)     /**
836)      * @author fenris
837)      */
838)     function inverse_decode(encode, from) {
839)         return encode(from);
840)     }
841)     lib_code.inverse_decode = inverse_decode;
842) })(lib_code || (lib_code = {}));
843) /*
844) This file is part of »bacterio-plankton:code«.
845) 
846) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
847) <info@greenscale.de>
848) 
849) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
850) it under the terms of the GNU Lesser General Public License as published by
851) the Free Software Foundation, either version 3 of the License, or
852) (at your option) any later version.
853) 
854) »bacterio-plankton:code« is distributed in the hope that it will be useful,
855) but WITHOUT ANY WARRANTY; without even the implied warranty of
856) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
857) GNU Lesser General Public License for more details.
858) 
859) You should have received a copy of the GNU Lesser General Public License
860) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
861)  */
862) var lib_code;
863) (function (lib_code) {
864)     /**
865)      * @author fenris
866)      */
867)     var class_code_inverse = /** @class */ (function () {
868)         /**
869)          * @author fenris
870)          */
871)         function class_code_inverse(subject) {
872)             this.subject = subject;
873)         }
874)         /**
875)          * @implementation
876)          * @author fenris
877)          */
878)         class_code_inverse.prototype.encode = function (to) {
879)             var _this = this;
880)             return lib_code.inverse_encode(function (x) { return _this.subject.decode(x); }, to);
881)         };
882)         /**
883)          * @implementation
884)          * @author fenris
885)          */
886)         class_code_inverse.prototype.decode = function (from) {
887)             var _this = this;
888)             return lib_code.inverse_decode(function (x) { return _this.subject.encode(x); }, from);
889)         };
890)         return class_code_inverse;
891)     }());
892)     lib_code.class_code_inverse = class_code_inverse;
893) })(lib_code || (lib_code = {}));
894) /*
895) This file is part of »bacterio-plankton:code«.
896) 
897) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
898) <info@greenscale.de>
899) 
900) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
901) it under the terms of the GNU Lesser General Public License as published by
902) the Free Software Foundation, either version 3 of the License, or
903) (at your option) any later version.
904) 
905) »bacterio-plankton:code« is distributed in the hope that it will be useful,
906) but WITHOUT ANY WARRANTY; without even the implied warranty of
907) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
908) GNU Lesser General Public License for more details.
909) 
910) You should have received a copy of the GNU Lesser General Public License
911) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
912)  */
913) var lib_code;
914) (function (lib_code) {
915)     /**
916)      * @author fenris
917)      */
918)     function pair_encode(encode_first, encode_second, from) {
919)         var between = encode_first(from);
920)         var to = encode_second(between);
921)         return to;
922)     }
923)     lib_code.pair_encode = pair_encode;
924)     /**
925)      * @author fenris
926)      */
927)     function pair_decode(decode_first, decode_second, to) {
928)         var between = decode_second(to);
929)         var from = decode_first(between);
930)         return from;
931)     }
932)     lib_code.pair_decode = pair_decode;
933) })(lib_code || (lib_code = {}));
934) /*
935) This file is part of »bacterio-plankton:code«.
936) 
937) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
938) <info@greenscale.de>
939) 
940) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
941) it under the terms of the GNU Lesser General Public License as published by
942) the Free Software Foundation, either version 3 of the License, or
943) (at your option) any later version.
944) 
945) »bacterio-plankton:code« is distributed in the hope that it will be useful,
946) but WITHOUT ANY WARRANTY; without even the implied warranty of
947) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
948) GNU Lesser General Public License for more details.
949) 
950) You should have received a copy of the GNU Lesser General Public License
951) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
952)  */
953) var lib_code;
954) (function (lib_code) {
955)     /**
956)      * @author fenris
957)      */
958)     var class_code_pair = /** @class */ (function () {
959)         /**
960)          * @author fenris
961)          */
962)         function class_code_pair(first, second) {
963)             this.first = first;
964)             this.second = second;
965)         }
966)         /**
967)          * @implementation
968)          * @author fenris
969)          */
970)         class_code_pair.prototype.encode = function (from) {
971)             var _this = this;
972)             return lib_code.pair_encode(function (x) { return _this.first.encode(x); }, function (x) { return _this.second.encode(x); }, from);
973)         };
974)         /**
975)          * @implementation
976)          * @author fenris
977)          */
978)         class_code_pair.prototype.decode = function (to) {
979)             var _this = this;
980)             return lib_code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to);
981)         };
982)         return class_code_pair;
983)     }());
984)     lib_code.class_code_pair = class_code_pair;
985) })(lib_code || (lib_code = {}));
986) /*
987) This file is part of »bacterio-plankton:code«.
988) 
989) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
990) <info@greenscale.de>
991) 
992) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
993) it under the terms of the GNU Lesser General Public License as published by
994) the Free Software Foundation, either version 3 of the License, or
995) (at your option) any later version.
996) 
997) »bacterio-plankton:code« is distributed in the hope that it will be useful,
998) but WITHOUT ANY WARRANTY; without even the implied warranty of
999) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1000) GNU Lesser General Public License for more details.
1001) 
1002) You should have received a copy of the GNU Lesser General Public License
1003) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
1004)  */
1005) var lib_code;
1006) (function (lib_code) {
1007)     /**
1008)      * @author fenris
1009)      */
1010)     function chain_encode(encode_links, from) {
1011)         var value = from;
1012)         encode_links
1013)             .forEach(function (link) {
1014)             value = link(value);
1015)         });
1016)         return value;
1017)     }
1018)     lib_code.chain_encode = chain_encode;
1019)     /**
1020)      * @author fenris
1021)      */
1022)     function chain_decode(decode_links, to) {
1023)         var value = to;
1024)         decode_links
1025)             .reverse()
1026)             .forEach(function (link) {
1027)             value = link(value);
1028)         });
1029)         return value;
1030)     }
1031)     lib_code.chain_decode = chain_decode;
1032) })(lib_code || (lib_code = {}));
1033) /*
1034) This file is part of »bacterio-plankton:code«.
1035) 
1036) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1037) <info@greenscale.de>
1038) 
1039) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
1040) it under the terms of the GNU Lesser General Public License as published by
1041) the Free Software Foundation, either version 3 of the License, or
1042) (at your option) any later version.
1043) 
1044) »bacterio-plankton:code« is distributed in the hope that it will be useful,
1045) but WITHOUT ANY WARRANTY; without even the implied warranty of
1046) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1047) GNU Lesser General Public License for more details.
1048) 
1049) You should have received a copy of the GNU Lesser General Public License
1050) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
1051)  */
1052) var lib_code;
1053) (function (lib_code) {
1054)     /**
1055)      * @author fenris
1056)      */
1057)     var class_code_chain = /** @class */ (function () {
1058)         /**
1059)          * @author fenris
1060)          */
1061)         function class_code_chain(links) {
1062)             this.links = links;
1063)         }
1064)         /**
1065)          * @implementation
1066)          * @author fenris
1067)          */
1068)         class_code_chain.prototype.encode = function (from) {
1069)             return lib_code.chain_encode(this.links.map(function (link) { return (function (x) { return link.encode(x); }); }), from);
1070)         };
1071)         /**
1072)          * @implementation
1073)          * @author fenris
1074)          */
1075)         class_code_chain.prototype.decode = function (to) {
1076)             return lib_code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to);
1077)         };
1078)         return class_code_chain;
1079)     }());
1080)     lib_code.class_code_chain = class_code_chain;
1081) })(lib_code || (lib_code = {}));
1082) /*
1083) This file is part of »bacterio-plankton:code«.
1084) 
1085) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1086) <info@greenscale.de>
1087) 
1088) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
1089) it under the terms of the GNU Lesser General Public License as published by
1090) the Free Software Foundation, either version 3 of the License, or
1091) (at your option) any later version.
1092) 
1093) »bacterio-plankton:code« is distributed in the hope that it will be useful,
1094) but WITHOUT ANY WARRANTY; without even the implied warranty of
1095) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1096) GNU Lesser General Public License for more details.
1097) 
1098) You should have received a copy of the GNU Lesser General Public License
1099) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
1100)  */
1101) var lib_code;
1102) (function (lib_code) {
1103)     /**
1104)      * @author Christian Fraß <frass@greenscale.de>
1105)      */
1106)     function flatten_encode(from, keys) {
1107)         if (keys === void 0) { keys = null; }
1108)         if (keys === null) {
1109)             if (from.length > 0) {
1110)                 keys = Object.keys(from[0]);
1111)             }
1112)             else {
1113)                 throw (new Error("encoding impossible"));
1114)             }
1115)         }
1116)         return {
1117)             "keys": keys,
1118)             "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); })
1119)         };
1120)     }
1121)     lib_code.flatten_encode = flatten_encode;
1122)     /**
1123)      * @author Christian Fraß <frass@greenscale.de>
1124)      */
1125)     function flatten_decode(to) {
1126)         return (to.data
1127)             .map(function (dataset) {
1128)             var dataset_ = {};
1129)             dataset
1130)                 .forEach(function (value, index) {
1131)                 var name = to.keys[index];
1132)                 dataset_[name] = value;
1133)             });
1134)             return dataset_;
1135)         }));
1136)     }
1137)     lib_code.flatten_decode = flatten_decode;
1138) })(lib_code || (lib_code = {}));
1139) /*
1140) This file is part of »bacterio-plankton:code«.
1141) 
1142) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1143) <info@greenscale.de>
1144) 
1145) »bacterio-plankton:code« is free software: you can redistribute it and/or modify
1146) it under the terms of the GNU Lesser General Public License as published by
1147) the Free Software Foundation, either version 3 of the License, or
1148) (at your option) any later version.
1149) 
1150) »bacterio-plankton:code« is distributed in the hope that it will be useful,
1151) but WITHOUT ANY WARRANTY; without even the implied warranty of
1152) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1153) GNU Lesser General Public License for more details.
1154) 
1155) You should have received a copy of the GNU Lesser General Public License
1156) along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
1157)  */
1158) var lib_code;
1159) (function (lib_code) {
1160)     /**
1161)      * @author fenris
1162)      */
1163)     var class_code_flatten = /** @class */ (function () {
1164)         /**
1165)          * @author fenris
1166)          */
1167)         function class_code_flatten() {
1168)         }
1169)         /**
1170)          * @implementation
1171)          * @author fenris
1172)          */
1173)         class_code_flatten.prototype.encode = function (x) {
1174)             return lib_code.flatten_encode(x);
1175)         };
1176)         /**
1177)          * @implementation
1178)          * @author fenris
1179)          */
1180)         class_code_flatten.prototype.decode = function (x) {
1181)             return lib_code.flatten_decode(x);
1182)         };
1183)         return class_code_flatten;
1184)     }());
1185)     lib_code.class_code_flatten = class_code_flatten;
1186) })(lib_code || (lib_code = {}));
1187) /*
Christian Fraß [mod] logging [mod] code st...

Christian Fraß authored 2 years ago

1188) This file is part of »bacterio-plankton:json«.
1189) 
1190) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1191) <info@greenscale.de>
1192) 
1193) »bacterio-plankton:json« is free software: you can redistribute it and/or modify
1194) it under the terms of the GNU Lesser General Public License as published by
1195) the Free Software Foundation, either version 3 of the License, or
1196) (at your option) any later version.
1197) 
1198) »bacterio-plankton:json« is distributed in the hope that it will be useful,
1199) but WITHOUT ANY WARRANTY; without even the implied warranty of
1200) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1201) GNU Lesser General Public License for more details.
1202) 
1203) You should have received a copy of the GNU Lesser General Public License
1204) along with »bacterio-plankton:json«. If not, see <http://www.gnu.org/licenses/>.
1205)  */
1206) var lib_json;
1207) (function (lib_json) {
1208)     /**
1209)      * @author fenris
1210)      */
1211)     function encode(x, formatted = false) {
1212)         return JSON.stringify(x, undefined, formatted ? "\t" : undefined);
1213)     }
1214)     lib_json.encode = encode;
1215)     /**
1216)      * @author fenris
1217)      */
1218)     function decode(x) {
1219)         return JSON.parse(x);
1220)     }
1221)     lib_json.decode = decode;
1222) })(lib_json || (lib_json = {}));
1223) /*
1224) This file is part of »bacterio-plankton:json«.
1225) 
1226) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1227) <info@greenscale.de>
1228) 
1229) »bacterio-plankton:json« is free software: you can redistribute it and/or modify
1230) it under the terms of the GNU Lesser General Public License as published by
1231) the Free Software Foundation, either version 3 of the License, or
1232) (at your option) any later version.
1233) 
1234) »bacterio-plankton:json« is distributed in the hope that it will be useful,
1235) but WITHOUT ANY WARRANTY; without even the implied warranty of
1236) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1237) GNU Lesser General Public License for more details.
1238) 
1239) You should have received a copy of the GNU Lesser General Public License
1240) along with »bacterio-plankton:json«. If not, see <http://www.gnu.org/licenses/>.
1241)  */
1242) var lib_json;
1243) (function (lib_json) {
1244)     /**
1245)      * @author fenris
1246)      */
1247)     class class_json {
1248)         /**
1249)          * @author fenris
1250)          */
1251)         constructor() {
1252)         }
1253)         /**
1254)          * @implementation
1255)          * @author fenris
1256)          */
1257)         encode(x) {
1258)             return lib_json.encode(x);
1259)         }
1260)         /**
1261)          * @implementation
1262)          * @author fenris
1263)          */
1264)         decode(x) {
1265)             return lib_json.decode(x);
1266)         }
1267)     }
1268)     lib_json.class_json = class_json;
1269) })(lib_json || (lib_json = {}));
1270) /*
1271) This file is part of »bacterio-plankton:sha256«.
1272) 
1273) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1274) <info@greenscale.de>
1275) 
1276) »bacterio-plankton:sha256« is free software: you can redistribute it and/or modify
1277) it under the terms of the GNU Lesser General Public License as published by
1278) the Free Software Foundation, either version 3 of the License, or
1279) (at your option) any later version.
1280) 
1281) »bacterio-plankton:sha256« is distributed in the hope that it will be useful,
1282) but WITHOUT ANY WARRANTY; without even the implied warranty of
1283) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1284) GNU Lesser General Public License for more details.
1285) 
1286) You should have received a copy of the GNU Lesser General Public License
1287) along with »bacterio-plankton:sha256«. If not, see <http://www.gnu.org/licenses/>.
1288)  */
1289) var lib_sha256;
1290) (function (lib_sha256) {
1291)     /**
1292)      * @author fenris
1293)      */
1294)     function get(value, secret = "") {
1295)         const nm_crypto = require("crypto");
1296)         const sha256Hasher = nm_crypto.createHmac("sha256", secret);
1297)         const hash = sha256Hasher.update(value).digest("hex");
1298)         return hash;
1299)     }
1300)     lib_sha256.get = get;
1301) })(lib_sha256 || (lib_sha256 = {}));
1302) /*
1303) This file is part of »bacterio-plankton:file«.
1304) 
1305) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1306) <info@greenscale.de>
1307) 
1308) »bacterio-plankton:file« is free software: you can redistribute it and/or modify
1309) it under the terms of the GNU Lesser General Public License as published by
1310) the Free Software Foundation, either version 3 of the License, or
1311) (at your option) any later version.
1312) 
1313) »bacterio-plankton:file« is distributed in the hope that it will be useful,
1314) but WITHOUT ANY WARRANTY; without even the implied warranty of
1315) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1316) GNU Lesser General Public License for more details.
1317) 
1318) You should have received a copy of the GNU Lesser General Public License
1319) along with »bacterio-plankton:file«. If not, see <http://www.gnu.org/licenses/>.
1320)  */
1321) var lib_plankton;
1322) (function (lib_plankton) {
1323)     var file;
1324)     (function (file) {
1325)         /**
1326)          * @author fenris
1327)          */
1328)         function read(path) {
1329)             var nm_fs = require("fs");
1330)             return (new Promise(function (resolve, reject) {
1331)                 nm_fs.readFile(path, {
1332)                     "encoding": "utf8",
1333)                     "flag": "r"
1334)                 }, function (error, content) {
1335)                     if (error == null) {
1336)                         resolve(content);
1337)                     }
1338)                     else {
1339)                         reject(error);
1340)                     }
1341)                 });
1342)             }));
1343)         }
1344)         file.read = read;
1345)         /**
1346)          * @author fenris
1347)          */
1348)         function read_stdin() {
1349)             return (new Promise(function (resolve, reject) {
1350)                 var input_raw = "";
1351)                 process.stdin.setEncoding("utf8");
1352)                 process.stdin.on("readable", function () {
1353)                     var chunk;
1354)                     while ((chunk = process.stdin.read()) !== null) {
1355)                         input_raw += chunk;
1356)                     }
1357)                 });
1358)                 process.stdin.on("end", function () {
1359)                     resolve(input_raw);
1360)                 });
1361)             }));
1362)         }
1363)         file.read_stdin = read_stdin;
1364)         /**
1365)          * @author fenris
1366)          */
1367)         function write(path, content) {
1368)             var nm_fs = require("fs");
1369)             return (new Promise(function (resolve, reject) {
1370)                 nm_fs.writeFile(path, content, {
1371)                     "encoding": "utf8",
1372)                     "flag": "w"
1373)                 }, function (error) {
1374)                     if (error == null) {
1375)                         resolve(undefined);
1376)                     }
1377)                     else {
1378)                         reject(error);
1379)                     }
1380)                 });
1381)             }));
1382)         }
1383)         file.write = write;
1384)     })(file = lib_plankton.file || (lib_plankton.file = {}));
1385) })(lib_plankton || (lib_plankton = {}));
1386) /*
Christian Fraß [ini]

Christian Fraß authored 2 years ago

1387) This file is part of »bacterio-plankton:http«.
1388) 
1389) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1390) <info@greenscale.de>
1391) 
1392) »bacterio-plankton:http« is free software: you can redistribute it and/or modify
1393) it under the terms of the GNU Lesser General Public License as published by
1394) the Free Software Foundation, either version 3 of the License, or
1395) (at your option) any later version.
1396) 
1397) »bacterio-plankton:http« is distributed in the hope that it will be useful,
1398) but WITHOUT ANY WARRANTY; without even the implied warranty of
1399) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1400) GNU Lesser General Public License for more details.
1401) 
1402) You should have received a copy of the GNU Lesser General Public License
1403) along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
1404)  */
1405) var lib_http;
1406) (function (lib_http) {
1407)     /**
1408)      * @author fenris <frass@greenscale.de>
1409)      */
1410)     let enum_method;
1411)     (function (enum_method) {
1412)         enum_method["get"] = "get";
1413)         enum_method["post"] = "post";
1414)         enum_method["options"] = "options";
1415)         // put = "put",
1416)         // delete = "delete",
1417)         // head = "head",
1418)     })(enum_method = lib_http.enum_method || (lib_http.enum_method = {}));
1419) })(lib_http || (lib_http = {}));
1420) /*
1421) This file is part of »bacterio-plankton:http«.
1422) 
1423) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1424) <info@greenscale.de>
1425) 
1426) »bacterio-plankton:http« is free software: you can redistribute it and/or modify
1427) it under the terms of the GNU Lesser General Public License as published by
1428) the Free Software Foundation, either version 3 of the License, or
1429) (at your option) any later version.
1430) 
1431) »bacterio-plankton:http« is distributed in the hope that it will be useful,
1432) but WITHOUT ANY WARRANTY; without even the implied warranty of
1433) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1434) GNU Lesser General Public License for more details.
1435) 
1436) You should have received a copy of the GNU Lesser General Public License
1437) along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
1438)  */
1439) var lib_http;
1440) (function (lib_http) {
1441)     /**
1442)      * @author fenris <frass@greenscale.de>
1443)      */
1444)     const linebreak = "\r\n";
1445)     /**
1446)      * @author fenris <frass@greenscale.de>
1447)      */
1448)     function encode_method(method) {
1449)         switch (method) {
1450)             case lib_http.enum_method.get: return "GET";
1451)             case lib_http.enum_method.post: return "POST";
1452)             case lib_http.enum_method.options: return "OPTIONS";
1453)             default: throw (new Error("impossible"));
1454)         }
1455)     }
1456)     /**
1457)      * @author fenris <frass@greenscale.de>
1458)      */
1459)     function decode_method(method_raw) {
1460)         switch (method_raw) {
1461)             case "GET": return lib_http.enum_method.get;
1462)             case "POST": return lib_http.enum_method.post;
1463)             case "OPTIONS": return lib_http.enum_method.options;
1464)             default: throw (new Error("unhandled method: " + method_raw));
1465)         }
1466)     }
1467)     /**
1468)      * @author fenris <frass@greenscale.de>
1469)      */
1470)     function get_statustext(statuscode) {
1471)         switch (statuscode) {
1472)             case 100: return "Continue";
1473)             case 101: return "Switching Protocols";
1474)             case 103: return "Early Hints";
1475)             case 200: return "OK";
1476)             case 201: return "Created";
1477)             case 202: return "Accepted";
1478)             case 203: return "Non-Authoritative Information";
1479)             case 204: return "No Content";
1480)             case 205: return "Reset Content";
1481)             case 206: return "Partial Content";
1482)             case 300: return "Multiple Choices";
1483)             case 301: return "Moved Permanently";
1484)             case 302: return "Found";
1485)             case 303: return "See Other";
1486)             case 304: return "Not Modified";
1487)             case 307: return "Temporary Redirect";
1488)             case 308: return "Permanent Redirect";
1489)             case 400: return "Bad Request";
1490)             case 401: return "Unauthorized";
1491)             case 402: return "Payment Required";
1492)             case 403: return "Forbidden";
1493)             case 404: return "Not Found";
1494)             case 405: return "Method Not Allowed";
1495)             case 406: return "Not Acceptable";
1496)             case 407: return "Proxy Authentication Required";
1497)             case 408: return "Request Timeout";
1498)             case 409: return "Conflict";
1499)             case 410: return "Gone";
1500)             case 411: return "Length Required";
1501)             case 412: return "Precondition Failed";
1502)             case 413: return "Payload Too Large";
1503)             case 414: return "URI Too Long";
1504)             case 415: return "Unsupported Media Type";
1505)             case 416: return "Range Not Satisfiable";
1506)             case 417: return "Expectation Failed";
1507)             case 418: return "I'm a teapot";
1508)             case 422: return "Unprocessable Entity";
1509)             case 425: return "Too Early";
1510)             case 426: return "Upgrade Required";
1511)             case 428: return "Precondition Required";
1512)             case 429: return "Too Many Requests";
1513)             case 431: return "Request Header Fields Too Large";
1514)             case 451: return "Unavailable For Legal Reasons";
1515)             case 500: return "Internal Server Error";
1516)             case 501: return "Not Implemented";
1517)             case 502: return "Bad Gateway";
1518)             case 503: return "Service Unavailable";
1519)             case 504: return "Gateway Timeout";
1520)             case 505: return "HTTP Version Not Supported";
1521)             case 506: return "Variant Also Negotiates";
1522)             case 507: return "Insufficient Storage";
1523)             case 508: return "Loop Detected";
1524)             case 510: return "Not Extended";
1525)             case 511: return "Network Authentication";
1526)             default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0)));
1527)         }
1528)     }
1529)     /**
1530)      * @author fenris <frass@greenscale.de>
1531)      */
1532)     function encode_request(request) {
1533)         let request_raw = "";
1534)         request_raw += (encode_method(request.method) + " " + request.query + " " + "HTTP/1.1" + linebreak);
1535)         request_raw += ("Host: " + request.host + linebreak);
1536)         for (const [key, value] of Object.entries(request.headers)) {
1537)             request_raw += (key + ": " + value + linebreak);
1538)         }
1539)         request_raw += linebreak;
1540)         request_raw += request.body;
1541)         return request_raw;
1542)     }
1543)     lib_http.encode_request = encode_request;
1544)     /**
1545)      * @author fenris <frass@greenscale.de>
1546)      */
1547)     function decode_request(request_raw) {
1548)         const lines = request_raw.split(linebreak);
1549)         const first = lines.shift();
1550)         const [method_raw, query, version] = first.split(" ");
1551)         let headers = {};
1552)         while (true) {
1553)             const line = lines.shift();
1554)             if (line === "") {
1555)                 break;
1556)             }
1557)             else {
1558)                 const [key, value] = line.split(": ", 2);
1559)                 headers[key] = value;
1560)             }
1561)         }
1562)         const body = lines.join(linebreak);
1563)         const request = {
1564)             "host": headers["Host"],
1565)             "query": query,
1566)             "method": decode_method(method_raw),
1567)             "headers": headers,
1568)             "body": body,
1569)         };
1570)         return request;
1571)     }
1572)     lib_http.decode_request = decode_request;
1573)     /**
1574)      * @author fenris <frass@greenscale.de>
1575)      */
1576)     function encode_response(response) {
1577)         let response_raw = "";
1578)         response_raw += ("HTTP/1.1" + " " + response.statuscode + " " + get_statustext(response.statuscode) + linebreak);
1579)         for (const [key, value] of Object.entries(response.headers)) {
1580)             response_raw += (key + ": " + value + linebreak);
1581)         }
1582)         response_raw += linebreak;
1583)         response_raw += response.body;
1584)         return response_raw;
1585)     }
1586)     lib_http.encode_response = encode_response;
1587)     /**
1588)      * @author fenris <frass@greenscale.de>
1589)      */
1590)     function decode_response(response_raw) {
1591)         const lines = response_raw.split(linebreak);
1592)         const first = lines.shift();
1593)         const statuscode = parseInt(first.split(" ")[1]);
1594)         let headers = {};
1595)         while (true) {
1596)             const line = lines.shift();
1597)             if (line === "") {
1598)                 break;
1599)             }
1600)             else {
1601)                 const [key, value] = line.split(": ", 2);
1602)                 headers[key] = value;
1603)             }
1604)         }
1605)         const body = lines.join(linebreak);
1606)         const response = {
1607)             "statuscode": statuscode,
1608)             "headers": headers,
1609)             "body": body,
1610)         };
1611)         return response;
1612)     }
1613)     lib_http.decode_response = decode_response;
1614) })(lib_http || (lib_http = {}));
1615) /*
1616) This file is part of »bacterio-plankton:http«.
1617) 
1618) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1619) <info@greenscale.de>
1620) 
1621) »bacterio-plankton:http« is free software: you can redistribute it and/or modify
1622) it under the terms of the GNU Lesser General Public License as published by
1623) the Free Software Foundation, either version 3 of the License, or
1624) (at your option) any later version.
1625) 
1626) »bacterio-plankton:http« is distributed in the hope that it will be useful,
1627) but WITHOUT ANY WARRANTY; without even the implied warranty of
1628) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1629) GNU Lesser General Public License for more details.
1630) 
1631) You should have received a copy of the GNU Lesser General Public License
1632) along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
1633)  */
1634) var lib_http;
1635) (function (lib_http) {
1636)     /**
1637)      * @author fenris
1638)      */
1639)     class class_http_request {
1640)         /**
1641)          * @author fenris
1642)          */
1643)         constructor() {
1644)         }
1645)         /**
1646)          * @implementation
1647)          * @author fenris
1648)          */
1649)         encode(x) {
1650)             return lib_http.encode_request(x);
1651)         }
1652)         /**
1653)          * @implementation
1654)          * @author fenris
1655)          */
1656)         decode(x) {
1657)             return lib_http.decode_request(x);
1658)         }
1659)     }
1660)     lib_http.class_http_request = class_http_request;
1661)     /**
1662)      * @author fenris
1663)      */
1664)     class class_http_response {
1665)         /**
1666)          * @author fenris
1667)          */
1668)         constructor() {
1669)         }
1670)         /**
1671)          * @implementation
1672)          * @author fenris
1673)          */
1674)         encode(x) {
1675)             return lib_http.encode_response(x);
1676)         }
1677)         /**
1678)          * @implementation
1679)          * @author fenris
1680)          */
1681)         decode(x) {
1682)             return lib_http.decode_response(x);
1683)         }
1684)     }
1685)     lib_http.class_http_response = class_http_response;
1686) })(lib_http || (lib_http = {}));
1687) /*
1688) This file is part of »bacterio-plankton:server«.
1689) 
1690) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
1691) <info@greenscale.de>
1692) 
1693) »bacterio-plankton:server« is free software: you can redistribute it and/or modify
1694) it under the terms of the GNU Lesser General Public License as published by
1695) the Free Software Foundation, either version 3 of the License, or
1696) (at your option) any later version.
1697) 
1698) »bacterio-plankton:server« is distributed in the hope that it will be useful,
1699) but WITHOUT ANY WARRANTY; without even the implied warranty of
1700) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1701) GNU Lesser General Public License for more details.
1702) 
1703) You should have received a copy of the GNU Lesser General Public License
1704) along with »bacterio-plankton:server«. If not, see <http://www.gnu.org/licenses/>.
1705)  */
1706) var lib_server;
1707) (function (lib_server) {
1708)     /**
1709)      * @author fenris
1710)      */
1711)     function make(port, handle, verbosity = 1) {
1712)         return {
1713)             "port": port,
1714)             "handle": handle,
1715)             "verbosity": verbosity,
1716)             "serverobj": undefined,
1717)         };
1718)     }
1719)     lib_server.make = make;
1720)     /**
1721)      * @author fenris
1722)      */
1723)     function log(subject, level, message) {
1724)         if (subject.verbosity >= level) {
1725)             console.log("[server]", message);
1726)         }
1727)         else {
1728)             // do nothing
1729)         }
1730)     }
1731)     /**
1732)      * @author fenris
1733)      */
1734)     function start(subject) {
1735)         const net = require("net");
1736)         return (new Promise((resolve, reject) => {
1737)             subject.serverobj = net.createServer((socket) => {
1738)                 log(subject, 2, "client connected");
1739)                 socket.on("readable", () => {
1740)                     let chunk;
1741)                     while (!((chunk = socket.read()) === null)) {
1742)                         const input = chunk.toString();
1743)                         log(subject, 3, "reading: " + input);
Christian Fraß [mod] logging [mod] code st...

Christian Fraß authored 2 years ago

1744)                         const metadata = {
1745)                             "ip_address": socket.remoteAddress,
1746)                         };
1747)                         subject.handle(input, metadata)