565e59b15de1b2a7cd53e52e63c9d8acd2f84281
Christian Fraß [add] client

Christian Fraß authored 3 years ago

1) /*
2) This file is part of »bacterio-plankton:trait«.
3) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

4) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

5) 
6) »bacterio-plankton:trait« is free software: you can redistribute it and/or modify
7) it under the terms of the GNU Lesser General Public License as published by
8) the Free Software Foundation, either version 3 of the License, or
9) (at your option) any later version.
10) 
11) »bacterio-plankton:trait« is distributed in the hope that it will be callful,
12) but WITHOUT ANY WARRANTY; without even the implied warranty of
13) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14) GNU Lesser General Public License for more details.
15) 
16) You should have received a copy of the GNU Lesser General Public License
17) along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>.
18)  */
19) var lib_trait;
20) (function (lib_trait) {
21)     /**
22)      * @author fenris
23)      */
24)     function domain_make(_a, _make) {
25)         var _b = _a["soft"], soft = _b === void 0 ? false : _b, kind = _a["kind"];
26)         return {
27)             "soft": soft,
28)             "kind": kind
29)         };
30)     }
31)     /**
32)      * @author fenris
33)      */
34)     function domain_inspect(parameters, value, _inspect) {
35)         var inspection = lib_shape.inspection_create();
36)         if (value == undefined) {
37)             if (parameters.soft) {
38)                 // all good
39)             }
40)             else {
41)                 lib_shape.inspection_add(inspection, "null is not allowed");
42)             }
43)         }
44)         else {
45)             var jstype_actual = typeof (value);
46)             var jstype_expected = "object";
47)             if (jstype_actual === jstype_expected) {
48)                 if ("domain" in value) {
49)                     var domain_actual = value["domain"]["kind"];
50)                     var domain_expected = parameters.kind;
51)                     if (domain_actual == domain_expected) {
52)                         // all good?
53)                     }
54)                     else {
55)                         lib_shape.inspection_add(inspection, "expected domain-kind '" + domain_expected + "' but got '" + domain_actual + "'");
56)                     }
57)                 }
58)                 else {
59)                     lib_shape.inspection_add(inspection, "field 'domain' missing");
60)                 }
61)             }
62)             else {
63)                 lib_shape.inspection_add(inspection, "expected JS-type '" + jstype_expected + "' but got '" + jstype_actual + "'");
64)             }
65)         }
66)         return inspection;
67)     }
68)     /**
69)      * @author fenris
70)      */
71)     function domain_stance(parameters, bindings, _stance) {
72)         return {
73)             "name": "domain",
74)             "parameters": {
75)                 "soft": parameters.soft,
76)                 "kind": parameters.kind
77)             }
78)         };
79)     }
80)     /**
81)      * @author fenris
82)      */
83)     function domain_show(parameters, _show) {
84)         var str;
85)         // core
86)         {
87)             str = ("#" + parameters.kind);
88)         }
89)         /*
90)         // parameters
91)         {
92)             str += (":" + JSON.stringify(parameters.parameters))
93)         }
94)          */
95)         // soft
96)         {
97)             if (parameters.soft) {
98)                 str = "~" + str;
99)             }
100)         }
101)         return str;
102)     }
103)     /**
104)      * @author fenris
105)      */
106)     lib_shape.register({
107)         "name": "domain",
108)         "make": domain_make,
109)         "inspect": domain_inspect,
110)         "stance": domain_stance,
111)         "show": domain_show
112)     });
113) })(lib_trait || (lib_trait = {}));
114) /*
115) This file is part of »bacterio-plankton:trait«.
116) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

117) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

118) 
119) »bacterio-plankton:trait« is free software: you can redistribute it and/or modify
120) it under the terms of the GNU Lesser General Public License as published by
121) the Free Software Foundation, either version 3 of the License, or
122) (at your option) any later version.
123) 
124) »bacterio-plankton:trait« is distributed in the hope that it will be callful,
125) but WITHOUT ANY WARRANTY; without even the implied warranty of
126) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127) GNU Lesser General Public License for more details.
128) 
129) You should have received a copy of the GNU Lesser General Public License
130) along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>.
131)  */
132) /**
133)  * @author fenris
134)  */
135) var lib_trait;
136) (function (lib_trait) {
137)     /**
138)      * @author fenris
139)      */
140)     lib_trait._verbosity = 1;
141)     /**
142)      * @author fenris
143)      */
144)     lib_trait._logprefix = "[lib_trait] ";
145)     /**
146)      * @desc holds all defined traits
147)      * @author fenris
148)      */
149)     var _pool = {};
150)     /**
151)      * @author fenris
152)      */
153)     var _typechecker = function (value, shape, logger) {
154)         var messages = lib_shape.inspect(shape, value).messages;
155)         messages.forEach(logger);
156)         return (messages.length === 0);
157)     };
158)     /**
159)      * @author fenris
160)      */
161)     function log(_a) {
162)         var message = _a["message"], _b = _a["kind"], kind = _b === void 0 ? "log" : _b, _c = _a["level"], level = _c === void 0 ? 0 : _c;
163)         if (level <= lib_trait._verbosity) {
164)             var message_ = "" + lib_trait._logprefix + message;
165)             switch (kind) {
166)                 default:
167)                 case "log": {
168)                     console.log(message_);
169)                     break;
170)                 }
171)                 case "information":
172)                 case "info": {
173)                     console.info(message_);
174)                     break;
175)                 }
176)                 case "warning":
177)                 case "warn": {
178)                     console.warn(message_);
179)                     break;
180)                 }
181)                 case "error":
182)                 case "err": {
183)                     console.error(message_);
184)                     break;
185)                 }
186)             }
187)         }
188)     }
189)     /**
190)      * @author fenris
191)      */
192)     function set_typechecker(typechecker) {
193)         _typechecker = typechecker;
194)     }
195)     lib_trait.set_typechecker = set_typechecker;
196)     /**
197)      * @author fenris
198)      */
199)     function domain_instance(domain, value) {
200)         return { "domain": domain, "value": value };
201)     }
202)     lib_trait.domain_instance = domain_instance;
203)     /**
204)      * @desc adds a trait
205)      * @author fenris
206)      */
207)     function define(trait_id, variable_conditions, facets_raw) {
208)         if (trait_id in _pool) {
209)             var message = "trait '" + trait_id + "' already registered";
210)             throw (new Error(message));
211)         }
212)         else {
213)             var trait_1 = {
214)                 "variables": {},
215)                 "facets": {},
216)                 "attendants": {}
217)             };
218)             Object.keys(variable_conditions).forEach(function (variable_name) {
219)                 var variable = {
220)                     "conditions": variable_conditions[variable_name],
221)                     "bindings": {}
222)                 };
223)                 trait_1.variables[variable_name] = variable;
224)             });
225)             Object.keys(facets_raw).forEach(function (facet_name) {
226)                 var facet_raw = facets_raw[facet_name];
227)                 var facet = {
228)                     "shape": lib_shape.make(facet_raw.shape || { "name": "any" }),
229)                     "description": facet_raw.description,
230)                     "implementation": facet_raw.implementation,
231)                     "handlers": {}
232)                 };
233)                 trait_1.facets[facet_name] = facet;
234)             });
235)             _pool[trait_id] = trait_1;
236)         }
237)     }
238)     lib_trait.define = define;
239)     /**
240)      * @desc adhoc binding
241)      * @author fenris
242)      */
243)     function attend(trait_id, domain_kind, bindings, handlers, condition) {
244)         if (condition === void 0) { condition = null; }
245)         var strict_binding = true;
246)         var strict_handling = true;
247)         if (!_pool.hasOwnProperty(trait_id)) {
248)             var message = "no trait '" + trait_id + "'";
249)             throw (new Error(message));
250)         }
251)         else {
252)             var trait_2 = _pool[trait_id];
253)             // assignments
254)             {
255)                 // variables
256)                 {
257)                     Object.keys(bindings).forEach(function (variable_name) {
258)                         if (!trait_2.variables.hasOwnProperty(variable_name)) {
259)                             var message = "";
260)                             message += "no variable '" + variable_name + "'";
261)                             message += " to bind in trait '" + trait_id + "'";
262)                             log({ "message": message, "kind": "warning" });
263)                             // throw (new Error(message));
264)                         }
265)                         else {
266)                             var variable = trait_2.variables[variable_name];
267)                             if (variable.bindings.hasOwnProperty(domain_kind)) {
268)                                 var message = "";
269)                                 message += "variable '" + variable_name + "'";
270)                                 message += " already bound for domain '" + domain_kind + "'";
271)                                 message += " in trait '" + trait_id + "'";
272)                                 throw (new Error(message));
273)                             }
274)                             else {
275)                                 variable.bindings[domain_kind] = lib_shape.make(bindings[variable_name]);
276)                             }
277)                         }
278)                     });
279)                 }
280)                 // facets
281)                 {
282)                     Object.keys(handlers).forEach(function (facet_name) {
283)                         if (!trait_2.facets.hasOwnProperty(facet_name)) {
284)                             var message = "";
285)                             message += "no facet '" + facet_name + "'";
286)                             message += " to implement at trait '" + trait_id + "'";
287)                             log({ "kind": "warning", "message": message });
288)                             // throw (new Error(message));
289)                         }
290)                         else {
291)                             var facet = trait_2.facets[facet_name];
292)                             var intrinsic = (facet.implementation != undefined);
293)                             if (intrinsic) {
294)                                 var message = "shadowing intrinsic facet '" + facet_name + "'";
295)                                 console.warn(message);
296)                             }
297)                             else {
298)                                 // do nothing
299)                             }
300)                             if (facet.handlers.hasOwnProperty(domain_kind)) {
301)                                 var message = "";
302)                                 message += "facet '" + facet_name + "'";
303)                                 message += " already implemented in domain '" + domain_kind + "'";
304)                                 message += " at trait '" + trait_id + "'";
305)                                 throw (new Error(message));
306)                             }
307)                             else {
308)                                 facet.handlers[domain_kind] = handlers[facet_name];
309)                             }
310)                         }
311)                     });
312)                 }
313)                 // attendants
314)                 {
315)                     trait_2.attendants[domain_kind] = {
316)                         "condition": condition
317)                     };
318)                 }
319)             }
320)             // checks
321)             {
322)                 var messages_1 = [];
323)                 // variables
324)                 {
325)                     if (strict_binding) {
326)                         var variable_names_given_1 = Object.keys(bindings);
327)                         var variable_names_present = Object.keys(trait_2.variables);
328)                         var variable_names_missing = variable_names_present.filter(function (variable_name) { return (!variable_names_given_1.some(function (variable_name_) { return (variable_name == variable_name_); })); });
329)                         variable_names_missing.forEach(function (variable_name) {
330)                             var message = "binding missing for variable '" + variable_name + "'";
331)                             messages_1.push(message);
332)                         });
333)                     }
334)                     else {
335)                         // do nothing
336)                     }
337)                 }
338)                 // facets
339)                 {
340)                     if (strict_handling) {
341)                         var facet_names_given_1 = Object.keys(handlers);
342)                         var facet_names_needed = (Object.keys(trait_2.facets).filter(function (facet_name) { return (trait_2.facets[facet_name].implementation == undefined); }));
343)                         var facet_names_missing = (facet_names_needed.filter(function (facet_name) { return (!facet_names_given_1.some(function (facet_name_) { return (facet_name === facet_name_); })); }));
344)                         facet_names_missing.forEach(function (facet_name) {
345)                             var message = "implementation missing for the facet '" + facet_name + "'";
346)                             messages_1.push(message);
347)                         });
348)                     }
349)                     else {
350)                         // do nothing
351)                     }
352)                 }
353)                 if (messages_1.length > 0) {
354)                     var message = "";
355)                     message += "assignment of domain '" + domain_kind + "'";
356)                     message += " to trait '" + trait_id + "'";
357)                     message += " incomplete: " + messages_1.join(", ");
358)                     throw (new Error(message));
359)                 }
360)             }
361)         }
362)     }
363)     lib_trait.attend = attend;
364)     /**
365)      * @desc calls a facet from a trait according to a given domain
366)      * @author fenris
367)      */
368)     function call(trait_id, facet_name, domain, check) {
369)         if (check === void 0) { check = true; }
370)         if (!_pool.hasOwnProperty(trait_id)) {
371)             var message = "no trait '" + trait_id + "'";
372)             throw (new Error(message));
373)         }
374)         else {
375)             var trait_3 = _pool[trait_id];
376)             if (!trait_3.facets.hasOwnProperty(facet_name)) {
377)                 var message = "no facet '" + facet_name + "' in trait '" + trait_id + "'";
378)                 throw (new Error(message));
379)             }
380)             else {
381)                 var facet = trait_3.facets[facet_name];
382)                 var intrinsic = (facet.implementation !== undefined);
383)                 var result = void 0;
384)                 if (intrinsic) {
385)                     result = facet.implementation(function (facet_name_) { return call(trait_id, facet_name_, domain, check); });
386)                 }
387)                 else {
388)                     if (!facet.handlers.hasOwnProperty(domain.kind)) {
389)                         var message = "";
390)                         message += "implementation missing";
391)                         message += " at trait '" + trait_id + "'";
392)                         message += " for facet '" + facet_name + "'";
393)                         message += " in domain '" + domain.kind + "'";
394)                         throw (new Error(message));
395)                     }
396)                     else {
397)                         var show_shape = (function (shape) { return lib_shape.show(shape); });
398)                         var handler = facet.handlers[domain.kind];
399)                         var bindings_1 = {};
400)                         Object.keys(trait_3.variables).forEach(function (variable_name) {
401)                             bindings_1[variable_name] = trait_3.variables[variable_name].bindings[domain.kind];
402)                         });
403)                         result = handler(domain.parameters);
404)                         if (check
405)                             &&
406)                                 (_typechecker !== null)
407)                             &&
408)                                 (facet.shape !== undefined)) {
409)                             var shape = lib_shape.stance(facet.shape, bindings_1);
410)                             // console.info("expected shape of result: " + lib_shape.show(shape)); console.info("result: ", result);
411)                             var valid = _typechecker(result, shape, function (message) { return log({ "kind": "warning", "message": "[typechecker] [result] " + message }); });
412)                             if (!valid) {
413)                                 var message = "";
414)                                 message += "result '" + instance_show(result) + "'";
415)                                 message += " doesn't match the expected type '" + show_shape(shape) + "'";
416)                                 message += " at trait '" + trait_id + "'";
417)                                 message += " for facet '" + facet_name + "'";
418)                                 message += " in domain '" + domain.kind + "'";
419)                                 log({ "kind": "warning", "message": message });
420)                             }
421)                             {
422)                                 var condition = trait_3.attendants[domain.kind].condition;
423)                                 if (condition != null) {
424)                                     var attends = function (trait_id_, domain_) {
425)                                         return (_pool.hasOwnProperty(trait_id_) && _pool[trait_id_].attendants.hasOwnProperty(domain_.kind));
426)                                     };
427)                                     if (!condition(attends)(domain.parameters)) {
428)                                         var message = "";
429)                                         message += "condition not fulfilled";
430)                                         message += " at trait '" + trait_id + "'";
431)                                         message += " for facet '" + facet_name + "'";
432)                                         message += " in domain '" + domain.kind + "'";
433)                                         log({ "kind": "warning", "message": message });
434)                                     }
435)                                     else {
436)                                         // do nothing
437)                                     }
438)                                 }
439)                                 else {
440)                                     // do nothing
441)                                 }
442)                             }
443)                         }
444)                     }
445)                 }
446)                 return result;
447)             }
448)         }
449)     }
450)     lib_trait.call = call;
451)     /**
452)      * @author fenris
453)      */
454)     function explain(trait_id) {
455)         if (!_pool.hasOwnProperty(trait_id)) {
456)             var message = "no trait '" + trait_id + "'";
457)             throw (new Error(message));
458)         }
459)         else {
460)             var trait_4 = _pool[trait_id];
461)             var str_1 = "";
462)             // head
463)             {
464)                 str_1 += "<<" + trait_id + ">>";
465)                 str_1 += (" "
466)                     +
467)                         "("
468)                     +
469)                         (Object.keys(trait_4.variables)
470)                             .map(function (variable_name) {
471)                             var shape = lib_shape.make({
472)                                 "name": "variable",
473)                                 "parameters": {
474)                                     "name": variable_name
475)                                 }
476)                             });
477)                             return lib_shape.show(shape);
478)                         })
479)                             .join(","))
480)                     +
481)                         ")");
482)                 str_1 += "\n";
483)             }
484)             // facets
485)             {
486)                 Object.keys(trait_4.facets)
487)                     .forEach(function (facet_name) {
488)                     var facet = trait_4.facets[facet_name];
489)                     // str += "\t";
490)                     str_1 += "* ";
491)                     str_1 += ((facet.implementation != undefined) ? ("[" + facet_name + "]") : facet_name);
492)                     str_1 += (" : " + lib_shape.show(facet.shape));
493)                     if (facet.description !== undefined) {
494)                         str_1 += (" ~ " + "" + facet.description + "");
495)                     }
496)                     str_1 += "\n";
497)                 });
498)             }
499)             return str_1;
500)         }
501)     }
502)     lib_trait.explain = explain;
503)     /**
504)      * @author fenris
505)      */
506)     function explain_all() {
507)         return Object.keys(_pool).map(function (trait_id) { return explain(trait_id); }).join("\n");
508)     }
509)     lib_trait.explain_all = explain_all;
510) })(lib_trait || (lib_trait = {}));
511) /*
512) This file is part of »bacterio-plankton:trait«.
513) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

514) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

515) 
516) »bacterio-plankton:trait« is free software: you can redistribute it and/or modify
517) it under the terms of the GNU Lesser General Public License as published by
518) the Free Software Foundation, either version 3 of the License, or
519) (at your option) any later version.
520) 
521) »bacterio-plankton:trait« is distributed in the hope that it will be callful,
522) but WITHOUT ANY WARRANTY; without even the implied warranty of
523) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
524) GNU Lesser General Public License for more details.
525) 
526) You should have received a copy of the GNU Lesser General Public License
527) along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>.
528)  */
529) /**
530)  * @author fenris
531)  */
532) var lib_trait;
533) (function (lib_trait) {
534)     /**
535)      * @desc the ability to check for equality with another element of the same domain
536)      * @author fenris
537)      */
538)     function define_collatable() {
539)         lib_trait.define("collatable", {
540)             "value": []
541)         }, {
542)             "collate": {
543)                 "shape": {
544)                     "name": "function",
545)                     "parameters": {
546)                         "shape_input": {
547)                             "name": "variable",
548)                             "parameters": {
549)                                 "name": "value"
550)                             }
551)                         },
552)                         "shape_output": {
553)                             "name": "function",
554)                             "parameters": {
555)                                 "shape_input": {
556)                                     "name": "variable",
557)                                     "parameters": {
558)                                         "name": "value"
559)                                     }
560)                                 },
561)                                 "shape_output": {
562)                                     "name": "boolean"
563)                                 }
564)                             }
565)                         }
566)                     }
567)                 }
568)             }
569)         });
570)         lib_trait.attend("collatable", "crude", {
571)             "value": {
572)                 "name": "any"
573)             }
574)         }, {
575)             "collate": function () { return function (instance) { return function (other) {
576)                 if (typeof (instance) === "object") {
577)                     if (instance == null) {
578)                         return (other == null);
579)                     }
580)                     else {
581)                         if ("_collate" in instance) {
582)                             return instance["_collate"](other);
583)                         }
584)                         else {
585)                             var message = ("[collate]" + " " + "object has no such method");
586)                             throw (new Error(message));
587)                         }
588)                     }
589)                 }
590)                 else {
591)                     if (lib_trait._verbosity >= 1) {
592)                         var message = ("[collate]" + " " + "primitive value; using default implementation");
593)                         console.warn(message);
594)                     }
595)                     return (instance === other);
596)                 }
597)             }; }; }
598)         });
599)     }
600)     lib_trait.define_collatable = define_collatable;
601)     /**
602)      * @author fenris
603)      */
604)     function _collate(instance, other, domain) {
605)         if (domain === void 0) { domain = { "kind": "crude" }; }
606)         return lib_trait.call("collatable", "collate", domain)(instance)(other);
607)     }
608)     lib_trait._collate = _collate;
609)     define_collatable();
610) })(lib_trait || (lib_trait = {}));
611) /*
612) This file is part of »bacterio-plankton:trait«.
613) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

614) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

615) 
616) »bacterio-plankton:trait« is free software: you can redistribute it and/or modify
617) it under the terms of the GNU Lesser General Public License as published by
618) the Free Software Foundation, either version 3 of the License, or
619) (at your option) any later version.
620) 
621) »bacterio-plankton:trait« is distributed in the hope that it will be callful,
622) but WITHOUT ANY WARRANTY; without even the implied warranty of
623) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
624) GNU Lesser General Public License for more details.
625) 
626) You should have received a copy of the GNU Lesser General Public License
627) along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>.
628)  */
629) /**
630)  * @author fenris
631)  */
632) var lib_trait;
633) (function (lib_trait) {
634)     /**
635)      * @desc the ability to compare with another element of the same domain for determining if the first is "smaller than or equal to" the latter
636)      * @author fenris
637)      */
638)     function define_comparable() {
639)         lib_trait.define("comparable", {
640)             "value": []
641)         }, {
642)             "compare": {
643)                 "shape": {
644)                     "name": "function",
645)                     "parameters": {
646)                         "shape_input": {
647)                             "name": "variable",
648)                             "parameters": {
649)                                 "name": "value"
650)                             }
651)                         },
652)                         "shape_output": {
653)                             "name": "function",
654)                             "parameters": {
655)                                 "shape_input": {
656)                                     "name": "variable",
657)                                     "parameters": {
658)                                         "name": "value"
659)                                     }
660)                                 },
661)                                 "shape_output": {
662)                                     "name": "boolean"
663)                                 }
664)                             }
665)                         }
666)                     }
667)                 }
668)             }
669)         });
670)         lib_trait.attend("comparable", "crude", {
671)             "value": {
672)                 "name": "any"
673)             }
674)         }, {
675)             "compare": function () { return function (instance) { return function (other) {
676)                 if (typeof (instance) === "object") {
677)                     if ("_compare" in instance) {
678)                         return instance["_compare"](other);
679)                     }
680)                     else {
681)                         throw (new Error("[compare]" + " " + "object has no such method"));
682)                     }
683)                 }
684)                 else {
685)                     if (lib_trait._verbosity >= 1) {
686)                         console.warn("[compare]" + " " + "primitive value; using default implementation");
687)                     }
688)                     return (instance <= other);
689)                 }
690)             }; }; }
691)         });
692)     }
693)     lib_trait.define_comparable = define_comparable;
694)     /**
695)      * @author fenris
696)      */
697)     function _compare(instance, other, domain) {
698)         if (domain === void 0) { domain = { "kind": "crude" }; }
699)         return lib_trait.call("comparable", "compare", domain)(instance)(other);
700)     }
701)     lib_trait._compare = _compare;
702)     define_comparable();
703) })(lib_trait || (lib_trait = {}));
704) /*
705) This file is part of »bacterio-plankton:trait«.
706) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

707) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

708) 
709) »bacterio-plankton:trait« is free software: you can redistribute it and/or modify
710) it under the terms of the GNU Lesser General Public License as published by
711) the Free Software Foundation, either version 3 of the License, or
712) (at your option) any later version.
713) 
714) »bacterio-plankton:trait« is distributed in the hope that it will be callful,
715) but WITHOUT ANY WARRANTY; without even the implied warranty of
716) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
717) GNU Lesser General Public License for more details.
718) 
719) You should have received a copy of the GNU Lesser General Public License
720) along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>.
721)  */
722) /**
723)  * @author fenris
724)  */
725) var lib_trait;
726) (function (lib_trait) {
727)     /**
728)      * @desc the ability to create an exact copy
729)      * @author fenris
730)      */
731)     function define_clonable() {
732)         lib_trait.define("clonable", {
733)             "value": []
734)         }, {
735)             "clone": {
736)                 "shape": {
737)                     "name": "function",
738)                     "parameters": {
739)                         "shape_input": {
740)                             "name": "variable",
741)                             "parameters": {
742)                                 "name": "value"
743)                             }
744)                         },
745)                         "shape_output": {
746)                             "name": "variable",
747)                             "parameters": {
748)                                 "name": "value"
749)                             }
750)                         }
751)                     }
752)                 }
753)             }
754)         });
755)         lib_trait.attend("clonable", "crude", {
756)             "value": {
757)                 "name": "any"
758)             }
759)         }, {
760)             "clone": function () { return function (instance) {
761)                 if (typeof (instance) === "object") {
762)                     if ("_clone" in instance) {
763)                         return instance["_clone"]();
764)                     }
765)                     else {
766)                         throw (new Error("[clone]" + " " + "object has no such method"));
767)                     }
768)                 }
769)                 else {
770)                     if (lib_trait._verbosity >= 1) {
771)                         console.warn("[clone]" + " " + "primitive value; using default implementation");
772)                     }
773)                     return instance;
774)                 }
775)             }; }
776)         });
777)     }
778)     lib_trait.define_clonable = define_clonable;
779)     /**
780)      * @author fenris
781)      */
782)     function _clone(instance, domain) {
783)         if (domain === void 0) { domain = { "kind": "crude" }; }
784)         return lib_trait.call("clonable", "clone", domain)(instance);
785)     }
786)     lib_trait._clone = _clone;
787)     define_clonable();
788) })(lib_trait || (lib_trait = {}));
789) /*
790) This file is part of »bacterio-plankton:trait«.
791) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

792) Copyright 2016-2021 greenscale <info@greenscale.de>
Christian Fraß [add] client

Christian Fraß authored 3 years ago

793) 
794) »bacterio-plankton:trait« 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:trait« is distributed in the hope that it will be callful,
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:trait«. If not, see <http://www.gnu.org/licenses/>.
806)  */
807) /**
808)  * @author fenris
809)  */
810) var lib_trait;
811) (function (lib_trait) {
812)     /**
813)      * @desc the ability to generate a string out of the element, which identifies it to a high degree
814)      * @author fenris
815)      */
816)     function define_hashable() {
817)         lib_trait.define("hashable", {
818)             "value": []
819)         }, {
820)             "hash": {
821)                 "shape": {
822)                     "name": "function",
823)                     "parameters": {
824)                         "shape_input": {
825)                             "name": "variable",
826)                             "parameters": {
827)                                 "name": "value"
828)                             }
829)                         },
830)                         "shape_output": {
831)                             "name": "string"
832)                         }
833)                     }
834)                 }
835)             }
836)         });
837)         lib_trait.attend("hashable", "crude", {
838)             "value": {
839)                 "name": "any"
840)             }
841)         }, {
842)             "hash": function () { return function (thing) {
843)                 if (typeof (thing) === "object") {
844)                     if ("_hash" in thing) {
845)                         return thing["_hash"]();
846)                     }
847)                     else {
848)                         var message = ("[hash]" + " " + "object has no such method");
849)                         throw (new Error(message));
850)                     }
851)                 }
852)                 else {
853)                     if (lib_trait._verbosity >= 1) {
854)                         var message = ("[hash]" + " " + "primitive value; using default implementation");
855)                         console.warn(message);
856)                     }
857)                     return String(thing);
858)                 }
859)             }; }
860)         });
861)     }
862)     lib_trait.define_hashable = define_hashable;
863)     /**
864)      * @author fenris
865)      */
866)     function _hash(instance, domain) {
867)         if (domain === void 0) { domain = { "kind": "crude" }; }
868)         return lib_trait.call("hashable", "hash", domain)(instance);
869)     }
870)     lib_trait._hash = _hash;
871)     define_hashable();
872) })(lib_trait || (lib_trait = {}));
873) /*
874) This file is part of »bacterio-plankton:trait«.
875) 
Christian Fraß [upd] client:lib:plankton

Christian Fraß authored 3 years ago

876) Copyright 2016-2021 greenscale <info@greenscale.de>