updated build tool koralle
Christian Fraß

Christian Fraß commited on 2017-07-25 08:22:10
Zeige 2 geänderte Dateien mit 6503 Einfügungen und 4384 Löschungen.

... ...
@@ -1,4 +1,4 @@
1 1
 #!/usr/bin/env sh
2 2
 
3
-node tools/koralle.js -x
3
+node tools/koralle.js tools/project.json -x
4 4
 
... ...
@@ -211,7 +211,7 @@ var lib_log;
211 211
         for (var _i = 0; _i < arguments.length; _i++) {
212 212
             args[_i] = arguments[_i];
213 213
         }
214
-        /*window.*/ console.log(args);
214
+        /*window.*/ console.log.apply(console, args);
215 215
     }
216 216
     lib_log.log = log;
217 217
     /**
... ...
@@ -222,7 +222,7 @@ var lib_log;
222 222
         for (var _i = 0; _i < arguments.length; _i++) {
223 223
             args[_i] = arguments[_i];
224 224
         }
225
-        /*window.*/ console.info(args);
225
+        /*window.*/ console.info.apply(console, args);
226 226
     }
227 227
     lib_log.info = info;
228 228
     /**
... ...
@@ -233,7 +233,7 @@ var lib_log;
233 233
         for (var _i = 0; _i < arguments.length; _i++) {
234 234
             args[_i] = arguments[_i];
235 235
         }
236
-        /*window.*/ console.warn(args);
236
+        /*window.*/ console.warn.apply(console, args);
237 237
     }
238 238
     lib_log.warn = warn;
239 239
     /**
... ...
@@ -244,7 +244,7 @@ var lib_log;
244 244
         for (var _i = 0; _i < arguments.length; _i++) {
245 245
             args[_i] = arguments[_i];
246 246
         }
247
-        /*window.*/ console.error(args);
247
+        /*window.*/ console.error.apply(console, args);
248 248
     }
249 249
     lib_log.error = error;
250 250
 })(lib_log || (lib_log = {}));
... ...
@@ -534,7 +534,6 @@ var class_error = (function (_super) {
534 534
     };
535 535
     return class_error;
536 536
 }(Error));
537
-///<reference path="../../base/build/logic-decl.d.ts"/>
538 537
 var lib_call;
539 538
 (function (lib_call) {
540 539
     /**
... ...
@@ -560,104 +559,6 @@ var lib_call;
560 559
     }
561 560
     lib_call.schedule = schedule;
562 561
 })(lib_call || (lib_call = {}));
563
-///<reference path="../../base/build/logic-decl.d.ts"/>
564
-var lib_call;
565
-(function (lib_call) {
566
-    /**
567
-     * @author frac
568
-     * @todo could possibly be replaced by Promise-system
569
-     */
570
-    class class_wait {
571
-    }
572
-    lib_call.class_wait = class_wait;
573
-    /**
574
-     * @author frac
575
-     * @todo could possibly be replaced by Promise-system
576
-     */
577
-    class class_wait_sequential extends class_wait {
578
-        /**
579
-         * @author frac
580
-         */
581
-        constructor(dependencies, action = function () { lib_log.log("all done"); }) {
582
-            super();
583
-            this.dependencies = dependencies;
584
-            this.action = action;
585
-        }
586
-        /**
587
-         * @author frac
588
-         */
589
-        run_(dependencies) {
590
-            if (dependencies.length > 0) {
591
-                dependencies[0](() => this.run_(dependencies.slice(1)));
592
-            }
593
-            else {
594
-                this.action();
595
-            }
596
-        }
597
-        /**
598
-         * @author frac
599
-         */
600
-        run() {
601
-            this.run_(this.dependencies);
602
-        }
603
-    }
604
-    lib_call.class_wait_sequential = class_wait_sequential;
605
-    /**
606
-     * @author frac
607
-     * @todo could possibly be replaced by Promise-system
608
-     */
609
-    class class_wait_parallel extends class_wait {
610
-        /**
611
-         * @author frac
612
-         */
613
-        constructor(dependencies, action = function () { lib_log.log("all done"); }) {
614
-            super();
615
-            this.index = 0;
616
-            this.dependencies = {};
617
-            this.action = action;
618
-            dependencies.forEach(dependency => this.add_dependency(dependency));
619
-        }
620
-        /**
621
-         * @author frac
622
-         */
623
-        add_dependency(dependency) {
624
-            this.dependencies["dependency_" + this.index.toString()] = dependency;
625
-            this.index += 1;
626
-        }
627
-        /**
628
-         * @author frac
629
-         */
630
-        remove_dependency(id) {
631
-            if (!(id in this.dependencies)) {
632
-                throw (new Error("dependency does not exist"));
633
-            }
634
-            else {
635
-                delete this.dependencies[id];
636
-                if (Object.keys(this.dependencies).length == 0) {
637
-                    this.action();
638
-                }
639
-            }
640
-        }
641
-        /**
642
-         * @author frac
643
-         */
644
-        run() {
645
-            let that = this;
646
-            if (Object.keys(this.dependencies).length == 0) {
647
-                this.action();
648
-            }
649
-            else {
650
-                Object.keys(this.dependencies).forEach(function (id) {
651
-                    let dependency = that.dependencies[id];
652
-                    dependency(function () {
653
-                        that.remove_dependency(id);
654
-                    });
655
-                });
656
-            }
657
-        }
658
-    }
659
-    lib_call.class_wait_parallel = class_wait_parallel;
660
-})(lib_call || (lib_call = {}));
661 562
 var lib_call;
662 563
 (function (lib_call) {
663 564
     /**
... ...
@@ -789,15 +690,6 @@ var lib_call;
789 690
         }
790 691
     }
791 692
     lib_call.curryfy = curryfy;
792
-    /**
793
-     * @desc adapter for old syntax
794
-     * @author fenris
795
-     */
796
-    function wait(dependencies, action = function () { lib_log.log("all done"); }, parallel = true) {
797
-        let wait = (parallel ? (new lib_call.class_wait_parallel(dependencies, action)) : (new lib_call.class_wait_sequential(dependencies, action)));
798
-        wait.run();
799
-    }
800
-    lib_call.wait = wait;
801 693
     /**
802 694
      * returns a function which goes through a process step by step
803 695
      * a process is an array of objects like { func : {function}, state : {string}}
... ...
@@ -1015,6 +907,135 @@ var lib_call;
1015 907
         })));
1016 908
     }
1017 909
     lib_call.executor_reduce = executor_reduce;
910
+    /**
911
+     * @desc useful for e.g. asynchronous singletons
912
+     * @author fenris
913
+     */
914
+    class class_executor_initializer {
915
+        /**
916
+         * @author fenris
917
+         */
918
+        constructor(fetcher) {
919
+            /**
920
+             * @author fenris
921
+             * 0 : initial
922
+             * 1 : waiting
923
+             * 2 : done, successful
924
+             * 3 : done, failed
925
+             */
926
+            this.state = 0;
927
+            this.fetcher = fetcher;
928
+            this.state = 0;
929
+            this.queue = [];
930
+            this.output = null;
931
+            this.error = null;
932
+        }
933
+        /**
934
+         * @author fenris
935
+         */
936
+        actuate() {
937
+            switch (this.state) {
938
+                case 2: {
939
+                    this.queue.forEach(entry => entry.resolve(this.output));
940
+                    break;
941
+                }
942
+                case 3: {
943
+                    this.queue.forEach(entry => entry.reject(this.error));
944
+                    break;
945
+                }
946
+                default: {
947
+                    throw (new Error(`unhandled state ${this.state}`));
948
+                    break;
949
+                }
950
+            }
951
+        }
952
+        /**
953
+         * @author fenris
954
+         */
955
+        reset() {
956
+            this.state = 0;
957
+            this.queue = [];
958
+        }
959
+        /**
960
+         * @author fenris
961
+         */
962
+        get() {
963
+            switch (this.state) {
964
+                case 0: {
965
+                    this.state = 1;
966
+                    return ((resolve, reject) => {
967
+                        this.queue.push({ "resolve": resolve, "reject": reject });
968
+                        this.fetcher(output => {
969
+                            this.state = 2;
970
+                            this.output = output;
971
+                            this.actuate();
972
+                        }, error => {
973
+                            this.state = 3;
974
+                            this.error = error;
975
+                            this.actuate();
976
+                        });
977
+                    });
978
+                    break;
979
+                }
980
+                case 1: {
981
+                    return ((resolve, reject) => this.queue.push({ "resolve": resolve, "reject": reject }));
982
+                    break;
983
+                }
984
+                case 2: {
985
+                    return executor_resolve(this.output);
986
+                    break;
987
+                }
988
+                case 3: {
989
+                    return executor_reject(this.error);
990
+                    break;
991
+                }
992
+                default: {
993
+                    throw (new Error(`unhandled state ${this.state}`));
994
+                    break;
995
+                }
996
+            }
997
+        }
998
+        /**
999
+         * @author fenris
1000
+         */
1001
+        get_sync() {
1002
+            switch (this.state) {
1003
+                case 2: {
1004
+                    return this.output;
1005
+                    break;
1006
+                }
1007
+                case 3: {
1008
+                    throw this.error;
1009
+                    break;
1010
+                }
1011
+                default: {
1012
+                    throw (new Error(`unhandled state ${this.state}`));
1013
+                    break;
1014
+                }
1015
+            }
1016
+        }
1017
+        /**
1018
+         * @author fenris
1019
+         */
1020
+        set_sync(output) {
1021
+            switch (this.state) {
1022
+                case 2: {
1023
+                    this.output = output;
1024
+                    break;
1025
+                }
1026
+                case 3: {
1027
+                    this.state = 2;
1028
+                    this.output = output;
1029
+                    break;
1030
+                }
1031
+                default: {
1032
+                    throw (new Error(`unhandled state ${this.state}`));
1033
+                    break;
1034
+                }
1035
+            }
1036
+        }
1037
+    }
1038
+    lib_call.class_executor_initializer = class_executor_initializer;
1018 1039
 })(lib_call || (lib_call = {}));
1019 1040
 var lib_call;
1020 1041
 (function (lib_call) {
... ...
@@ -1275,92 +1296,19 @@ var lib_call;
1275 1296
          * @author fenris
1276 1297
          */
1277 1298
         constructor(fetcher) {
1278
-            /**
1279
-             * @author fenris
1280
-             * 0 : initial
1281
-             * 1 : waiting
1282
-             * 2 : done, successful
1283
-             * 3 : done, failed
1284
-             */
1285
-            this.state = 0;
1286
-            /**
1287
-             * @author fenris
1288
-             */
1289
-            this.output = null;
1290
-            /**
1291
-             * @author fenris
1292
-             */
1293
-            this.error = null;
1294
-            this.fetcher = fetcher;
1295
-            this.state = 0;
1296
-            this.queue = [];
1297
-            this.output = null;
1298
-            this.error = null;
1299
-        }
1300
-        /**
1301
-         * @author fenris
1302
-         */
1303
-        actuate() {
1304
-            switch (this.state) {
1305
-                case 2: {
1306
-                    this.queue.forEach(entry => entry.resolve(this.output));
1307
-                    break;
1308
-                }
1309
-                case 3: {
1310
-                    this.queue.forEach(entry => entry.reject(this.error));
1311
-                    break;
1312
-                }
1313
-                default: {
1314
-                    throw (new Error(`unhandled state ${this.state}`));
1315
-                    break;
1316
-                }
1317
-            }
1299
+            this.core = new lib_call.class_executor_initializer(fetcher(null));
1318 1300
         }
1319 1301
         /**
1320 1302
          * @author fenris
1321 1303
          */
1322 1304
         reset() {
1323
-            this.state = 0;
1324
-            this.queue = [];
1305
+            this.core.reset();
1325 1306
         }
1326 1307
         /**
1327 1308
          * @author fenris
1328 1309
          */
1329 1310
         get(input) {
1330
-            switch (this.state) {
1331
-                case 0: {
1332
-                    this.state = 1;
1333
-                    return (_ => (resolve, reject) => {
1334
-                        this.queue.push({ "resolve": resolve, "reject": reject });
1335
-                        this.fetcher(input)(output => {
1336
-                            this.state = 2;
1337
-                            this.output = output;
1338
-                            this.actuate();
1339
-                        }, error => {
1340
-                            this.state = 3;
1341
-                            this.error = error;
1342
-                            this.actuate();
1343
-                        });
1344
-                    });
1345
-                    break;
1346
-                }
1347
-                case 1: {
1348
-                    return (_ => (resolve, reject) => this.queue.push({ "resolve": resolve, "reject": reject }));
1349
-                    break;
1350
-                }
1351
-                case 2: {
1352
-                    return knot_resolver(this.output);
1353
-                    break;
1354
-                }
1355
-                case 3: {
1356
-                    return knot_rejector(this.error);
1357
-                    break;
1358
-                }
1359
-                default: {
1360
-                    throw (new Error(`unhandled state ${this.state}`));
1361
-                    break;
1362
-                }
1363
-            }
1311
+            return (_ => this.core.get());
1364 1312
         }
1365 1313
     }
1366 1314
     lib_call.class_knot_initializer = class_knot_initializer;
... ...
@@ -1391,3741 +1339,5587 @@ var lib_call;
1391 1339
     /**
1392 1340
      * @author fenris
1393 1341
      */
1394
-    function promise_all(promises) {
1395
-        return Promise.all(promises);
1342
+    function promise_then_close(promise, resolver, rejector) {
1343
+        return (promise.then(resolver, rejector));
1396 1344
     }
1397
-    lib_call.promise_all = promise_all;
1398
-})(lib_call || (lib_call = {}));
1399
-
1400
-(function (exports) {
1401
-	
1345
+    lib_call.promise_then_close = promise_then_close;
1402 1346
     /**
1403 1347
      * @author fenris
1404 1348
      */
1405
-	function promise_chain(
1406
-		microprograms
1407
-	) {
1408
-		return (
1409
-			input => microprograms.reduce(
1410
-				(x, y) => x.then(y),
1411
-				Promise.resolve(input)
1412
-			)
1413
-		);
1349
+    function promise_then_append(promise, resolver, rejector = null) {
1350
+        if (rejector == null) {
1351
+            rejector = (reason) => promise_reject(reason);
1414 1352
         }
1415
-	exports.promise_chain = promise_chain;
1416
-	
1417
-
1353
+        return (promise.then(resolver, rejector));
1354
+    }
1355
+    lib_call.promise_then_append = promise_then_append;
1418 1356
     /**
1419 1357
      * @author fenris
1420 1358
      */
1421
-	function promise_wrap(
1422
-		promise,
1423
-		transformator_result,
1424
-		transformator_reason = lib_call.id
1425
-	) {
1426
-		return (
1427
-			new Promise(
1428
-				(resolve, reject) => {
1429
-					promise.then(
1430
-						result => resolve(transformator_result(result)),
1431
-						reason => reject(transformator_reason(reason))
1432
-					)
1359
+    function promise_all(promises) {
1360
+        return Promise.all(promises);
1433 1361
     }
1434
-			)
1435
-		);
1362
+    lib_call.promise_all = promise_all;
1363
+    /**
1364
+     * @author fenris
1365
+     */
1366
+    function promise_chain(promises, start = undefined) {
1367
+        return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start)));
1436 1368
     }
1437
-	exports.promise_wrap = promise_wrap;
1438
-
1439
-
1369
+    lib_call.promise_chain = promise_chain;
1440 1370
     /**
1441 1371
      * @author fenris
1442 1372
      */
1443
-	function promise_log(state) {
1444
-		return (
1445
-			new Promise(
1446
-				(resolve, reject) => {
1447
-					lib_log.info(state);
1448
-					resolve(state);
1373
+    function promise_wrap(promise, transformator_result, transformator_reason = lib_call.id) {
1374
+        return (promise_make((resolve, reject) => {
1375
+            promise_then_close(promise, result => resolve(transformator_result(result)), reason => reject(transformator_reason(reason)));
1376
+        }));
1449 1377
     }
1450
-			)
1451
-		);
1378
+    lib_call.promise_wrap = promise_wrap;
1379
+    /**
1380
+     * @author fenris
1381
+     */
1382
+    function promise_show(label) {
1383
+        return (result => promise_make((resolve, reject) => {
1384
+            lib_log.info(label + ": " + instance_show(result));
1385
+            resolve(result);
1386
+        }));
1452 1387
     }
1453
-	exports.promise_log = promise_log;
1454
-
1455
-
1388
+    lib_call.promise_show = promise_show;
1456 1389
     /**
1457 1390
      * @author fenris
1458 1391
      */
1459
-	function promise_attach(
1460
-		state,
1461
-		promise,
1462
-		name
1463
-	) {
1464
-		return (
1465
-			promise_wrap(
1466
-				promise,
1467
-				result => {
1392
+    function promise_log(result) {
1393
+        return promise_show("log");
1394
+    }
1395
+    lib_call.promise_log = promise_log;
1396
+    /**
1397
+     * @author fenris
1398
+     */
1399
+    function promise_attach(state, promise, name) {
1400
+        return (promise_wrap(promise, result => {
1468 1401
             state[name] = result;
1469 1402
             return state;
1403
+        }));
1470 1404
     }
1471
-			)
1472
-		);
1405
+    lib_call.promise_attach = promise_attach;
1406
+})(lib_call || (lib_call = {}));
1407
+/**
1408
+ * @author fenris
1409
+ */
1410
+var lib_trait;
1411
+(function (lib_trait) {
1412
+    /**
1413
+     * @author fenris
1414
+     */
1415
+    lib_trait._verbosity = 1;
1416
+    /**
1417
+     * @author fenris
1418
+     */
1419
+    function type_show(type) {
1420
+        return JSON.stringify(type);
1473 1421
     }
1474
-	exports.promise_attach = promise_attach;
1475
-	
1476
-}) (lib_call || (lib_call == {}));
1477
-
1478
-///<reference path="../../base/build/logic-decl.d.ts"/>
1479
-var lib_object;
1480
-(function (lib_object) {
1481 1422
     /**
1482 1423
      * @author fenris
1483 1424
      */
1484
-    function fetch(object, fieldname, fallback, escalation) {
1485
-        if (fallback === void 0) { fallback = null; }
1486
-        if (escalation === void 0) { escalation = 1; }
1487
-        if ((fieldname in object) && (object[fieldname] !== undefined)) {
1488
-            return object[fieldname];
1425
+    function type_resolve(raw, bindings) {
1426
+        switch (raw.kind) {
1427
+            case "variable": {
1428
+                var variable_name = raw.parameters["name"];
1429
+                if (variable_name in bindings) {
1430
+                    return bindings[variable_name];
1489 1431
                 }
1490 1432
                 else {
1491
-            switch (escalation) {
1492
-                case 0: {
1493
-                    return fallback;
1494
-                    break;
1433
+                    var message = "binding missing for variable '" + variable_name + "'";
1434
+                    throw (new Error(message));
1495 1435
                 }
1496
-                case 1: {
1497
-                    var message = ("field '" + fieldname + "' not in structure");
1498
-                    message += ("; using fallback value '" + String(fallback) + "'");
1499
-                    // console.warn(message);
1500
-                    return fallback;
1501 1436
                 break;
1502 1437
             }
1503
-                case 2: {
1504
-                    var message = ("field '" + fieldname + "' not in structure");
1505
-                    throw (new Error(message));
1438
+            case "object": {
1439
+                return {
1440
+                    "kind": "object",
1441
+                    "parameters": {
1442
+                        "fields": raw.parameters["fields"].map(function (field) {
1443
+                            return {
1444
+                                "name": field.name,
1445
+                                "type": type_resolve(field.type, bindings)
1446
+                            };
1447
+                        })
1448
+                    }
1449
+                };
1506 1450
                 break;
1507 1451
             }
1508 1452
             default: {
1509
-                    throw (new Error("invalid escalation level " + escalation));
1453
+                return raw;
1510 1454
                 break;
1511 1455
             }
1512 1456
         }
1513 1457
     }
1514
-    }
1515
-    lib_object.fetch = fetch;
1516 1458
     /**
1459
+     * @desc holds all defined traits
1517 1460
      * @author fenris
1518 1461
      */
1519
-    function map(object_from, transformator) {
1520
-        var object_to = {};
1521
-        Object.keys(object_from).forEach(function (key) { return (object_to[key] = transformator(object_from[key], key)); });
1522
-        return object_to;
1523
-    }
1524
-    lib_object.map = map;
1462
+    var _pool = {};
1525 1463
     /**
1526 1464
      * @author fenris
1527 1465
      */
1528
-    function filter(object_from, predicate) {
1529
-        var object_to = {};
1530
-        Object.keys(object_from).forEach(function (key) {
1531
-            var value = object_from[key];
1532
-            if (predicate(value, key)) {
1533
-                object_to[key] = value;
1534
-            }
1535
-        });
1536
-        return object_to;
1537
-    }
1538
-    lib_object.filter = filter;
1466
+    var _typechecker;
1539 1467
     /**
1540 1468
      * @author fenris
1541 1469
      */
1542
-    function from_array(array) {
1543
-        var object = {};
1544
-        array.forEach(function (entry) { return (object[entry.key] = entry.value); });
1545
-        return object;
1470
+    function set_typechecker(typechecker) {
1471
+        _typechecker = typechecker;
1546 1472
     }
1547
-    lib_object.from_array = from_array;
1473
+    lib_trait.set_typechecker = set_typechecker;
1548 1474
     /**
1549 1475
      * @author fenris
1550 1476
      */
1551
-    function to_array(object) {
1552
-        var array = [];
1553
-        Object.keys(object).forEach(function (key) { return array.push({ "key": key, "value": object[key] }); });
1554
-        return array;
1477
+    function domain_instance(domain, value) {
1478
+        return { "domain": domain, "value": value };
1555 1479
     }
1556
-    lib_object.to_array = to_array;
1480
+    lib_trait.domain_instance = domain_instance;
1557 1481
     /**
1482
+     * @desc adds a trait
1558 1483
      * @author fenris
1559 1484
      */
1560
-    function keys(object) {
1561
-        return Object.keys(object);
1485
+    function describe(trait_id, variable_conditions, facet_signatures) {
1486
+        if (trait_id in _pool) {
1487
+            var error = new Error("trait '" + trait_id + "' already registered");
1488
+            throw error;
1562 1489
         }
1563
-    lib_object.keys = keys;
1564
-    /**
1565
-     * @author fenris
1566
-     */
1567
-    function values(object) {
1568
-        return to_array(object).map(function (entry) { return entry.value; });
1490
+        else {
1491
+            var trait_1 = {
1492
+                "variables": {},
1493
+                "facets": {}
1494
+            };
1495
+            Object.keys(variable_conditions).forEach(function (variable_name) {
1496
+                var variable = {
1497
+                    "conditions": variable_conditions[variable_name],
1498
+                    "bindings": {}
1499
+                };
1500
+                trait_1.variables[variable_name] = variable;
1501
+            });
1502
+            Object.keys(facet_signatures).forEach(function (facet_name) {
1503
+                var facet = {
1504
+                    "signature": facet_signatures[facet_name],
1505
+                    "handlers": {}
1506
+                };
1507
+                trait_1.facets[facet_name] = facet;
1508
+            });
1509
+            _pool[trait_id] = trait_1;
1569 1510
         }
1570
-    lib_object.values = values;
1511
+    }
1512
+    lib_trait.describe = describe;
1571 1513
     /**
1514
+     * @desc adhoc binding
1572 1515
      * @author fenris
1573 1516
      */
1574
-    function path_read(object, path, fallback, escalation) {
1575
-        if (fallback === void 0) { fallback = null; }
1576
-        if (escalation === void 0) { escalation = 1; }
1577
-        var steps = ((path.length == 0) ? [] : path.split("."));
1578
-        if (steps.length == 0) {
1579
-            throw (new Error("empty path"));
1517
+    function assign(domain_kind, trait_id, bindings, handlers, strict_binding, strict_handling) {
1518
+        if (strict_binding === void 0) { strict_binding = true; }
1519
+        if (strict_handling === void 0) { strict_handling = true; }
1520
+        if (trait_id in _pool) {
1521
+            var trait_2 = _pool[trait_id];
1522
+            // assignments
1523
+            {
1524
+                // variables
1525
+                {
1526
+                    Object.keys(bindings).forEach(function (variable_name) {
1527
+                        if (variable_name in trait_2.variables) {
1528
+                            var variable = trait_2.variables[variable_name];
1529
+                            if (!(domain_kind in variable.bindings)) {
1530
+                                variable.bindings[domain_kind] = bindings[variable_name];
1580 1531
                             }
1581 1532
                             else {
1582
-            var position_1 = object;
1583
-            var reachable = steps.slice(0, steps.length - 1).every(function (step) {
1584
-                position_1 = object_fetch(position_1, step, null, 0);
1585
-                return (position_1 != null);
1586
-            });
1587
-            if (reachable) {
1588
-                return object_fetch(position_1, steps[steps.length - 1], fallback, escalation);
1533
+                                var message = "variable '" + variable_name + "' already bound for domain '" + domain_kind + "' in trait '" + trait_id + "'";
1534
+                                throw (new Error(message));
1589 1535
                             }
1590
-            else {
1591
-                return object_fetch({}, "_dummy_", fallback, escalation);
1592 1536
                         }
1537
+                        else {
1538
+                            var message = "no variable '" + variable_name + "' to bind in trait '" + trait_id + "'";
1539
+                            console.warn(message);
1540
+                            // throw (new Error(message));
1593 1541
                         }
1542
+                    });
1594 1543
                 }
1595
-    lib_object.path_read = path_read;
1596
-    /**
1597
-     * @author fenris
1598
-     */
1599
-    function path_write(object, path, value, construct) {
1600
-        if (construct === void 0) { construct = true; }
1601
-        var steps = ((path.length == 0) ? [] : path.split("."));
1602
-        if (steps.length == 0) {
1603
-            throw (new Error("empty path"));
1544
+                // facets
1545
+                {
1546
+                    Object.keys(handlers).forEach(function (facet_name) {
1547
+                        if (facet_name in trait_2.facets) {
1548
+                            var facet = trait_2.facets[facet_name];
1549
+                            if (!(domain_kind in facet.handlers)) {
1550
+                                facet.handlers[domain_kind] = handlers[facet_name];
1604 1551
                             }
1605 1552
                             else {
1606
-            var position_2 = object;
1607
-            var reachable = steps.slice(0, steps.length - 1).every(function (step) {
1608
-                var position_ = object_fetch(position_2, step, null, 0);
1609
-                if (position_ == null) {
1610
-                    if (construct) {
1611
-                        position_2[step] = {};
1612
-                        position_2 = position_2[step];
1613
-                        return true;
1553
+                                var message = "facet '" + facet_name + "' already implemented for domain '" + domain_kind + "' in trait '" + trait_id + "'";
1554
+                                throw (new Error(message));
1555
+                            }
1614 1556
                         }
1615 1557
                         else {
1616
-                        return false;
1558
+                            var message = "no facet '" + facet_name + "' to implement in trait '" + trait_id + "'";
1559
+                            console.warn(message);
1560
+                            // throw (new Error(message));
1617 1561
                         }
1562
+                    });
1618 1563
                 }
1619
-                else {
1620
-                    position_2 = position_;
1621
-                    return true;
1622 1564
             }
1565
+            // checks
1566
+            {
1567
+                var messages_1 = [];
1568
+                if (strict_binding) {
1569
+                    // variables
1570
+                    {
1571
+                        var variable_names_given_1 = Object.keys(bindings);
1572
+                        var variable_names_present = Object.keys(trait_2.variables);
1573
+                        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_); }); });
1574
+                        variable_names_missing.forEach(function (variable_name) {
1575
+                            var message = "binding missing for variable '" + variable_name + "'";
1576
+                            messages_1.push(message);
1623 1577
                         });
1624
-            if (reachable) {
1625
-                position_2[steps[steps.length - 1]] = value;
1626 1578
                     }
1627
-            else {
1628
-                throw (new Error("path " + path + " does not exist and may not be constructed"));
1629 1579
                 }
1580
+                if (strict_handling) {
1581
+                    // facets
1582
+                    {
1583
+                        var facet_names_given_1 = Object.keys(handlers);
1584
+                        var facet_names_present = Object.keys(trait_2.facets);
1585
+                        var facet_names_missing = facet_names_present.filter(function (facet_name) { return !facet_names_given_1.some(function (facet_name_) { return (facet_name == facet_name_); }); });
1586
+                        facet_names_missing.forEach(function (facet_name) {
1587
+                            var message = "implementations missing for the facet '" + facet_name + "'";
1588
+                            messages_1.push(message);
1589
+                        });
1630 1590
                     }
1591
+                    if (messages_1.length > 0) {
1592
+                        var message = "assignment of domain '" + domain_kind + "' to trait '" + trait_id + "' incomplete: " + messages_1.join(", ");
1593
+                        throw (new Error(message));
1631 1594
                     }
1632
-    lib_object.path_write = path_write;
1633
-    /**
1634
-     * @author fenris
1635
-     */
1636
-    function matches(object, pattern, collate) {
1637
-        if (collate === void 0) { collate = instance_collate; }
1638
-        return Object.keys(pattern).every(function (key) { return collate(pattern[key], object[key]); });
1639 1595
                 }
1640
-    lib_object.matches = matches;
1596
+            }
1597
+        }
1598
+        else {
1599
+            var message = "no trait '" + trait_id + "'";
1600
+            throw (new Error(message));
1601
+        }
1602
+    }
1603
+    lib_trait.assign = assign;
1641 1604
     /**
1642 1605
      * @author fenris
1643 1606
      */
1644
-    function flatten(value) {
1645
-        var integrate = function (result, key_, value_) {
1646
-            if (value_ == null) {
1647
-                result[key_] = value_;
1607
+    function call(trait_id, facet_name, domain, input) {
1608
+        if (trait_id in _pool) {
1609
+            var trait_3 = _pool[trait_id];
1610
+            if (facet_name in trait_3.facets) {
1611
+                var facet = trait_3.facets[facet_name];
1612
+                if (domain.kind in facet.handlers) {
1613
+                    var handler = facet.handlers[domain.kind];
1614
+                    var bindings_1 = {};
1615
+                    Object.keys(trait_3.variables).forEach(function (variable_name) {
1616
+                        bindings_1[variable_name] = trait_3.variables[variable_name].bindings[domain.kind];
1617
+                    });
1618
+                    if ((_typechecker != null) && (facet.signature.type_input != undefined)) {
1619
+                        var type = type_resolve(facet.signature.type_input, bindings_1);
1620
+                        var valid_input = _typechecker(input, type);
1621
+                        if (!valid_input) {
1622
+                            var message = "input '" + String(input) + "' for domain '" + domain.kind + "' implementing facet '" + facet_name + "' in trait '" + trait_id + "' doesn't match the expected type '" + type_show(type) + "'";
1623
+                            console.warn(message);
1648 1624
                         }
1649
-            else {
1650
-                if (typeof (value_) != "object") {
1651
-                    result[key_] = value_;
1652 1625
                     }
1653
-                else {
1654
-                    var result_1 = flatten(value_);
1655
-                    Object.keys(result_1).forEach(function (key__) {
1656
-                        var value__ = result_1[key__];
1657
-                        result[key_ + "." + key__] = value__;
1658
-                    });
1626
+                    var output = handler(domain.parameters)(input);
1627
+                    if ((_typechecker != null) && (facet.signature.type_output != undefined)) {
1628
+                        var type = type_resolve(facet.signature.type_output, bindings_1);
1629
+                        var valid_output = _typechecker(output, type);
1630
+                        if (!valid_output) {
1631
+                            var message = "output '" + String(output) + "' for domain '" + domain.kind + "' implementing facet '" + facet_name + "' in trait '" + trait_id + "' doesn't match the expected type '" + type_show(type) + "'";
1632
+                            console.warn(message);
1659 1633
                         }
1660 1634
                     }
1661
-        };
1662
-        if (value == null) {
1663
-            return null;
1635
+                    return output;
1664 1636
                 }
1665 1637
                 else {
1666
-            var result_2 = {};
1667
-            if (typeof (value) != "object") {
1668
-                result_2["value"] = value;
1638
+                    var message = "implementation for facet '" + facet_name + "' missing for domain '" + domain.kind + "' belonging to the trait '" + trait_id + "'";
1639
+                    throw (new Error(message));
1669 1640
                 }
1670
-            else {
1671
-                if (value instanceof Array) {
1672
-                    var array = (value);
1673
-                    array.forEach(function (element, index) { return integrate(result_2, "element_" + index, element); });
1674 1641
             }
1675 1642
             else {
1676
-                    var object_1 = (value);
1677
-                    Object.keys(object_1).forEach(function (key) { return integrate(result_2, key, object_1[key]); });
1643
+                var message = "no facet '" + facet_name + "' in trait '" + trait_id + "'";
1644
+                throw (new Error(message));
1678 1645
             }
1679 1646
         }
1680
-            return result_2;
1647
+        else {
1648
+            var message = "no trait '" + trait_id + "'";
1649
+            throw (new Error(message));
1681 1650
         }
1682 1651
     }
1683
-    lib_object.flatten = flatten;
1652
+    lib_trait.call = call;
1684 1653
     /**
1685 1654
      * @author fenris
1686 1655
      */
1687
-    function clash(x, y, _a) {
1688
-        var _b = _a === void 0 ? {} : _a, _c = _b["overwrite"], overwrite = _c === void 0 ? true : _c, _d = _b["hooks"]["existing"], hook_existing = _d === void 0 ? null : _d;
1689
-        if (hook_existing == null) {
1690
-            (function (key, value_old, value_new) { return console.warn("field " + key + " already defined"); });
1656
+    function show() {
1657
+        console.info(JSON.stringify(_pool, undefined, "\t"));
1658
+        // console.info(_pool);
1659
+    }
1660
+    lib_trait.show = show;
1661
+})(lib_trait || (lib_trait = {}));
1662
+/**
1663
+ * @author fenris
1664
+ */
1665
+var lib_trait;
1666
+(function (lib_trait) {
1667
+    /**
1668
+     * @desc the ability to check for equality with another element of the same domain
1669
+     * @author fenris
1670
+     */
1671
+    function define_collatable() {
1672
+        lib_trait.describe("collatable", {
1673
+            "value": []
1674
+        }, {
1675
+            "collate": {
1676
+                "type_input": {
1677
+                    "kind": "object",
1678
+                    "parameters": {
1679
+                        "fields": [
1680
+                            {
1681
+                                "name": "left",
1682
+                                "type": {
1683
+                                    "kind": "variable",
1684
+                                    "parameters": {
1685
+                                        "name": "value"
1686
+                                    }
1687
+                                }
1688
+                            },
1689
+                            {
1690
+                                "name": "right",
1691
+                                "type": {
1692
+                                    "kind": "variable",
1693
+                                    "parameters": {
1694
+                                        "name": "value"
1695
+                                    }
1696
+                                }
1697
+                            }
1698
+                        ]
1699
+                    }
1700
+                },
1701
+                "type_output": {
1702
+                    "kind": "boolean"
1691 1703
                 }
1692
-        var z = {};
1693
-        Object.keys(x).forEach(function (key) {
1694
-            z[key] = x[key];
1695
-        });
1696
-        Object.keys(y).forEach(function (key) {
1697
-            if (key in z) {
1698
-                hook_existing(key, z[key], y[key]);
1699
-                if (overwrite) {
1700
-                    z[key] = y[key];
1701 1704
             }
1705
+        });
1706
+        lib_trait.assign("auto", "collatable", {
1707
+            "value": {
1708
+                "kind": "any"
1709
+            }
1710
+        }, {
1711
+            "collate": function (_) { return function (_a) {
1712
+                var x = _a["left"], y = _a["right"];
1713
+                if (typeof (x) === "object") {
1714
+                    if (x == null) {
1715
+                        return (y == null);
1702 1716
                     }
1703 1717
                     else {
1704
-                z[key] = y[key];
1718
+                        if ("_collate" in x) {
1719
+                            return x["_collate"](y);
1720
+                        }
1721
+                        else {
1722
+                            throw (new Error("[collate]" + " " + "object has no such method"));
1723
+                        }
1724
+                    }
1705 1725
                 }
1726
+                else {
1727
+                    if (lib_trait._verbosity >= 1) {
1728
+                        console.warn("[collate]" + " " + "primitive value; using default implementation");
1729
+                    }
1730
+                    return (x === y);
1731
+                }
1732
+            }; }
1706 1733
         });
1707
-        return z;
1708 1734
     }
1709
-    lib_object.clash = clash;
1735
+    lib_trait.define_collatable = define_collatable;
1736
+})(lib_trait || (lib_trait = {}));
1710 1737
 /**
1711 1738
  * @author fenris
1712 1739
  */
1713
-    function patch(core, mantle, deep, path) {
1714
-        if (deep === void 0) { deep = true; }
1715
-        if (path === void 0) { path = null; }
1716
-        if (mantle == null) {
1717
-            console.warn("mantle is null; core was", core);
1740
+var lib_trait;
1741
+(function (lib_trait) {
1742
+    /**
1743
+     * @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
1744
+     * @author fenris
1745
+     */
1746
+    function define_comparable() {
1747
+        lib_trait.describe("comparable", {
1748
+            "value": []
1749
+        }, {
1750
+            "compare": {
1751
+                "type_input": {
1752
+                    "kind": "object",
1753
+                    "parameters": {
1754
+                        "fields": [
1755
+                            {
1756
+                                "name": "left",
1757
+                                "type": {
1758
+                                    "kind": "variable",
1759
+                                    "parameters": {
1760
+                                        "name": "value"
1718 1761
                                     }
1719
-        else {
1720
-            Object.keys(mantle).forEach(function (key) {
1721
-                var path_ = ((path == null) ? key : path + "." + key);
1722
-                var value_mantle = mantle[key];
1723
-                if (!(key in core)) {
1724
-                    if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) {
1725
-                        if (value_mantle instanceof Array) {
1726
-                            core[key] = [];
1727
-                            value_mantle.forEach(function (element) {
1728
-                                if ((typeof (element) == "object") && (element != null)) {
1729
-                                    var element_ = {};
1730
-                                    patch(element_, element);
1731
-                                    core[key].push(element_);
1732 1762
                                 }
1733
-                                else {
1734
-                                    core[key].push(element);
1763
+                            },
1764
+                            {
1765
+                                "name": "right",
1766
+                                "type": {
1767
+                                    "kind": "variable",
1768
+                                    "parameters": {
1769
+                                        "name": "value"
1735 1770
                                     }
1736
-                            });
1737 1771
                                 }
1738
-                        else {
1739
-                            core[key] = {};
1740
-                            patch(core[key], value_mantle, deep, path_);
1741 1772
                             }
1773
+                        ]
1742 1774
                     }
1743
-                    else {
1744
-                        core[key] = value_mantle;
1775
+                },
1776
+                "type_output": {
1777
+                    "kind": "boolean"
1745 1778
                 }
1746 1779
             }
1747
-                else {
1748
-                    var value_core = core[key];
1749
-                    if (typeof (value_mantle) == typeof (value_core)) {
1750
-                        if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) {
1751
-                            patch(core[key], value_mantle, deep, path_);
1780
+        });
1781
+        lib_trait.assign("auto", "comparable", {
1782
+            "value": {
1783
+                "kind": "any"
1784
+            }
1785
+        }, {
1786
+            "compare": function (_) { return function (_a) {
1787
+                var x = _a["left"], y = _a["right"];
1788
+                if (typeof (x) === "object") {
1789
+                    if ("_compare" in x) {
1790
+                        return x["_compare"](y);
1752 1791
                     }
1753 1792
                     else {
1754
-                            core[key] = value_mantle;
1793
+                        throw (new Error("[compare]" + " " + "object has no such method"));
1755 1794
                     }
1756 1795
                 }
1757 1796
                 else {
1758
-                        var message = "objects have different shapes at path '" + path_ + "'; core has type '" + typeof (value_core) + "' and mantle has type '" + typeof (value_mantle) + "'";
1759
-                        console.warn(message);
1760
-                        core[key] = value_mantle;
1761
-                        // throw (new Error(message));
1797
+                    if (lib_trait._verbosity >= 1) {
1798
+                        console.warn("[compare]" + " " + "primitive value; using default implementation");
1762 1799
                     }
1800
+                    return (x <= y);
1763 1801
                 }
1802
+            }; }
1764 1803
         });
1765 1804
     }
1766
-    }
1767
-    lib_object.patch = patch;
1805
+    lib_trait.define_comparable = define_comparable;
1806
+})(lib_trait || (lib_trait = {}));
1768 1807
 /**
1769 1808
  * @author fenris
1770 1809
  */
1771
-    function patched(core, mantle, deep) {
1772
-        if (deep === void 0) { deep = undefined; }
1773
-        var result = {};
1774
-        patch(result, core, deep);
1775
-        patch(result, mantle, deep);
1776
-        return result;
1777
-    }
1778
-    lib_object.patched = patched;
1810
+var lib_trait;
1811
+(function (lib_trait) {
1779 1812
     /**
1813
+     * @desc the ability to create an exact copy
1780 1814
      * @author fenris
1781 1815
      */
1782
-    function attached(object, key, value) {
1783
-        var mantle = {};
1784
-        mantle[key] = value;
1785
-        return patched(object, mantle, false);
1816
+    function define_clonable() {
1817
+        lib_trait.describe("clonable", {
1818
+            "value": []
1819
+        }, {
1820
+            "clone": {
1821
+                "type_input": {
1822
+                    "kind": "variable",
1823
+                    "parameters": {
1824
+                        "name": "value"
1786 1825
                     }
1787
-    lib_object.attached = attached;
1788
-    /**
1789
-     * @author fenris
1790
-     */
1791
-    function copy(object) {
1792
-        return patched({}, object);
1826
+                },
1827
+                "type_output": {
1828
+                    "kind": "variable",
1829
+                    "parameters": {
1830
+                        "name": "value"
1793 1831
                     }
1794
-    lib_object.copy = copy;
1795
-})(lib_object || (lib_object = {}));
1832
+                }
1833
+            }
1834
+        });
1835
+        lib_trait.assign("auto", "clonable", {
1836
+            "value": {
1837
+                "kind": "any"
1838
+            }
1839
+        }, {
1840
+            "clone": function (_) { return function (x) {
1841
+                if (typeof (x) === "object") {
1842
+                    if ("_clone" in x) {
1843
+                        return x["_clone"]();
1844
+                    }
1845
+                    else {
1846
+                        throw (new Error("[clone]" + " " + "object has no such method"));
1847
+                    }
1848
+                }
1849
+                else {
1850
+                    if (lib_trait._verbosity >= 1) {
1851
+                        console.warn("[clone]" + " " + "primitive value; using default implementation");
1852
+                    }
1853
+                    return x;
1854
+                }
1855
+            }; }
1856
+        });
1857
+    }
1858
+    lib_trait.define_clonable = define_clonable;
1859
+})(lib_trait || (lib_trait = {}));
1796 1860
 /**
1797
- * @desc adapters for old syntax
1798 1861
  * @author fenris
1799 1862
  */
1800
-var object_fetch = lib_object.fetch;
1801
-var object_map = lib_object.map;
1802
-var object_a2o = lib_object.from_array;
1803
-var object_o2a = lib_object.to_array;
1804
-var object_matches = lib_object.matches;
1805
-var object_clash = lib_object.clash;
1806
-///<reference path="../../base/build/logic-decl.d.ts"/>
1807
-/**
1808
- * @param {Object} map
1809
- * @return {string}
1810
- * @author frac
1811
- */
1812
-/*export*/ var object_map2string = function (map) {
1813
-    return (" " + Object.keys(map)
1814
-        .filter(function (key) { return (key != "isMapped"); })
1815
-        .map(function (key) { return ("" + ((map[key] == null) ? "-" : map[key].toString()) + ""); })
1816
-        .join(" ")
1817
-        + "");
1818
-};
1863
+var lib_trait;
1864
+(function (lib_trait) {
1819 1865
     /**
1820
- * @param {Array} array
1821
- * @return {string}
1822
- * @author frac
1866
+     * @desc the ability to generate a string out of the element, which identifies it to a high degree
1867
+     * @author fenris
1823 1868
      */
1824
-/*export*/ var object_array2string = function (array) {
1825
-    return ("" + array.map(function (element, index) {
1826
-        switch (typeof (element)) {
1827
-            case "object": return object_map2string(element);
1828
-            default: return String(element);
1869
+    function define_hashable() {
1870
+        lib_trait.describe("hashable", {
1871
+            "value": []
1872
+        }, {
1873
+            "hash": {
1874
+                "type_input": {
1875
+                    "kind": "variable",
1876
+                    "parameters": {
1877
+                        "name": "value"
1829 1878
                     }
1830
-    }).join(",") + "");
1831
-};
1832
-/**
1833
- * @desc follows a path in an object-tree
1834
- * @param {Object} object the object in which the path lies
1835
- * @param {string} path the steps
1836
- * @param {boolean} [create] whether to create not yet existing branches
1837
- * @return {Object} {'successful': successful, 'position': position} where the branch or leaf at the end of the path
1838
- * @author frac
1839
- */
1840
-var object_path_walk = function (object, path, create, null_on_missing) {
1841
-    if (create === void 0) { create = true; }
1842
-    if (null_on_missing === void 0) { null_on_missing = false; }
1843
-    var steps = ((path == "") ? [] : path.split("."));
1844
-    if (steps.length == 0) {
1845
-        return object;
1879
+                },
1880
+                "type_output": {
1881
+                    "kind": "string"
1846 1882
                 }
1847
-    else {
1848
-        var head = steps[0];
1849
-        // create
1850
-        {
1851
-            if (!(head in object)) {
1852
-                if (create) {
1853
-                    var value = null;
1854
-                    if (steps.length >= 2) {
1855
-                        var next = steps[1];
1856
-                        var index = parseInt(next);
1857
-                        if (!isNaN(index)) {
1858
-                            value = [];
1859 1883
             }
1860
-                        else {
1861
-                            value = {};
1884
+        });
1885
+        lib_trait.assign("auto", "hashable", {
1886
+            "value": {
1887
+                "kind": "any"
1862 1888
             }
1889
+        }, {
1890
+            "hash": function (_) { return function (x) {
1891
+                if (typeof (x) === "object") {
1892
+                    if ("_hash" in x) {
1893
+                        return x["_hash"]();
1863 1894
                     }
1864 1895
                     else {
1865
-                        value = {};
1896
+                        throw (new Error("[hash]" + " " + "object has no such method"));
1866 1897
                     }
1867
-                    object[head] = value;
1868 1898
                 }
1869 1899
                 else {
1870
-                    // console.info("[object_path_walk] object is ", object);
1871
-                    var message = "[object_path_walk] can not walk step \u00BB" + head + "\u00AB in path \u00BB" + path + "\u00AB on object";
1872
-                    if (null_on_missing) {
1873
-                        console.warn(message);
1874
-                        return null;
1900
+                    if (lib_trait._verbosity >= 1) {
1901
+                        console.warn("[hash]" + " " + "primitive value; using default implementation");
1875 1902
                     }
1876
-                    else {
1877
-                        throw (new Error(message));
1903
+                    return String(x);
1878 1904
                 }
1905
+            }; }
1906
+        });
1879 1907
     }
1908
+    lib_trait.define_hashable = define_hashable;
1909
+})(lib_trait || (lib_trait = {}));
1910
+/**
1911
+ * @author fenris
1912
+ */
1913
+var lib_trait;
1914
+(function (lib_trait) {
1915
+    /**
1916
+     * @desc the ability to map the element to a textual representation (most likely not injective)
1917
+     * @author fenris
1918
+     */
1919
+    function define_showable() {
1920
+        lib_trait.describe("showable", {
1921
+            "value": []
1922
+        }, {
1923
+            "show": {
1924
+                "type_input": {
1925
+                    "kind": "variable",
1926
+                    "parameters": {
1927
+                        "name": "value"
1880 1928
                     }
1929
+                },
1930
+                "type_output": {
1931
+                    "kind": "string"
1881 1932
                 }
1882
-        // execute rest
1883
-        {
1884
-            var object_ = object[head];
1885
-            var path_ = steps.slice(1).join(".");
1886
-            return object_path_walk(object_, path_, create, null_on_missing);
1887 1933
             }
1934
+        });
1935
+        lib_trait.assign("auto", "showable", {
1936
+            "value": {
1937
+                "kind": "any"
1938
+            }
1939
+        }, {
1940
+            "show": function (_) { return function (x) {
1941
+                if (typeof (x) === "object") {
1942
+                    if (x == null) {
1943
+                        return "NULL";
1888 1944
                     }
1889
-    /*
1890
-    return (
1891
-        string_split(path, ".").reduce(
1892
-            function (position : any, step : string) : any {
1893
-                if (! lib_call.is_def(position[step], true)) {
1894
-                    if (create) {
1895
-                        position[step] = {};
1945
+                    else {
1946
+                        if ("_show" in x) {
1947
+                            return x["_show"]();
1896 1948
                         }
1897 1949
                         else {
1898
-                        // console.info("[object_path_walk] object is ", object);
1899
-                        let message : string = sprintf("[object_path_walk] can not walk step »%s« in path »%s« on object", [step, path]);
1900
-                        if (null_on_missing) {
1901
-                            console.warn(message);
1902
-                            return null;
1950
+                            // throw (new Error("[show]" + " " + "object has no such method"));
1951
+                            return JSON.stringify(x);
1952
+                        }
1953
+                    }
1903 1954
                 }
1904 1955
                 else {
1905
-                            throw (new Error(message));
1956
+                    if (lib_trait._verbosity >= 1) {
1957
+                        console.warn("[show]" + " " + "primitive value; using default implementation");
1906 1958
                     }
1959
+                    return String(x);
1907 1960
                 }
1961
+            }; }
1962
+        });
1908 1963
     }
1909
-                return position[step];
1910
-            },
1911
-            object
1912
-        )
1913
-    );
1914
-     */
1915
-};
1964
+    lib_trait.define_showable = define_showable;
1965
+})(lib_trait || (lib_trait = {}));
1916 1966
 /**
1917
- * @desc reads a branch/leaf from an object-tree
1918
- * @author frac
1967
+ * @author fenris
1919 1968
  */
1920
-/*export*/ var object_path_read = function (object, path, null_on_missing) {
1921
-    if (null_on_missing === void 0) { null_on_missing = false; }
1922
-    return object_path_walk(object, path, false, null_on_missing);
1923
-};
1969
+var lib_trait;
1970
+(function (lib_trait) {
1924 1971
     /**
1925
- * @desc writes a branch/leaf to an object-tree
1926
- * @author frac
1972
+     * @author fenris
1927 1973
      */
1928
-/*export*/ var object_path_write = function (object, path, value) {
1929
-    // for "initializing" the object (important if the value to write is an entry in a yet not existing array)
1930
-    /*let old : any = */ object_path_walk(object, path, true, true);
1931
-    var steps = ((path == "") ? [] : path.split("."));
1932
-    var position = object_path_walk(object, steps.slice(0, steps.length - 1).join("."), true);
1933
-    if (position == undefined) {
1934
-        console.warn("can't set \u00BB" + steps[steps.length - 1] + "\u00AB in undefined");
1974
+    function define_common() {
1975
+        lib_trait.define_collatable();
1976
+        lib_trait.define_comparable();
1977
+        lib_trait.define_clonable();
1978
+        lib_trait.define_hashable();
1979
+        lib_trait.define_showable();
1980
+    }
1981
+    lib_trait.define_common = define_common;
1982
+})(lib_trait || (lib_trait = {}));
1983
+///<reference path="../../base/build/logic-decl.d.ts"/>
1984
+var lib_object;
1985
+(function (lib_object) {
1986
+    /**
1987
+     * @author fenris
1988
+     */
1989
+    function fetch(object, fieldname, fallback, escalation) {
1990
+        if (fallback === void 0) { fallback = null; }
1991
+        if (escalation === void 0) { escalation = 1; }
1992
+        if ((fieldname in object) && (object[fieldname] !== undefined)) {
1993
+            return object[fieldname];
1935 1994
         }
1936 1995
         else {
1937
-        position[steps[steps.length - 1]] = value;
1996
+            switch (escalation) {
1997
+                case 0: {
1998
+                    return fallback;
1999
+                    break;
1938 2000
                 }
1939
-};
1940
-/*export*/ var object_object_path_write_ex = function (obj, path, val) {
1941
-    var ref = obj;
1942
-    var paths = path.split(".");
1943
-    var i;
1944
-    for (i = 0; i < paths.length - 1; i++) {
1945
-        if (ref[paths[i]] === void 0) {
1946
-            if (/^(0|[1-9][0-9]*)$/.test(paths[i + 1])) {
1947
-                ref[paths[i]] = [];
2001
+                case 1: {
2002
+                    var message = ("field '" + fieldname + "' not in structure");
2003
+                    message += ("; using fallback value '" + String(fallback) + "'");
2004
+                    // console.warn(message);
2005
+                    return fallback;
2006
+                    break;
1948 2007
                 }
1949
-            else {
1950
-                ref[paths[i]] = {};
2008
+                case 2: {
2009
+                    var message = ("field '" + fieldname + "' not in structure");
2010
+                    throw (new Error(message));
2011
+                    break;
1951 2012
                 }
2013
+                default: {
2014
+                    throw (new Error("invalid escalation level " + escalation));
2015
+                    break;
1952 2016
                 }
1953
-        ref = ref[paths[i]];
1954 2017
             }
1955
-    ref[paths[i]] = val;
1956
-};
1957
-/**
1958
- * @desc filters branches from an object
1959
- * @param {Object} object the object to read from
1960
- * @param {Array} paths a list of string-lists, that are the paths to be propagated
1961
- * @return {Object} the object with only the selected branches
1962
- * @author frac
1963
- */
1964
-/*export*/ var object_path_filter = function (object, paths) {
1965
-    var result = {};
1966
-    paths.forEach(function (path) {
1967
-        var value = null;
1968
-        try {
1969
-            value = object_path_read(object, path);
1970 2018
         }
1971
-        catch (exception) {
1972
-            console.warn(exception);
1973 2019
     }
1974
-        if (value != null) {
1975
-            object_path_write(result, path, value);
2020
+    lib_object.fetch = fetch;
2021
+    /**
2022
+     * @author fenris
2023
+     */
2024
+    function map(object_from, transformator) {
2025
+        var object_to = {};
2026
+        Object.keys(object_from).forEach(function (key) { return (object_to[key] = transformator(object_from[key], key)); });
2027
+        return object_to;
1976 2028
     }
1977
-        else {
1978
-            console.warn("skipped path \"" + path + "\" while filtering");
2029
+    lib_object.map = map;
2030
+    /**
2031
+     * @author fenris
2032
+     */
2033
+    function filter(object_from, predicate) {
2034
+        var object_to = {};
2035
+        Object.keys(object_from).forEach(function (key) {
2036
+            var value = object_from[key];
2037
+            if (predicate(value, key)) {
2038
+                object_to[key] = value;
1979 2039
             }
1980 2040
         });
1981
-    return result;
1982
-};
2041
+        return object_to;
2042
+    }
2043
+    lib_object.filter = filter;
1983 2044
     /**
1984
- * @desc dunno… returns a list of object-paths?
1985
- * @param {Object} object
1986
- * @param {string} p
1987
- * @todo can probably be merged with getLeafg
2045
+     * @author fenris
1988 2046
      */
1989
-/*export*/ var object_path_list = function (object, path, visited) {
1990
-    if (path === void 0) { path = null; }
1991
-    if (visited === void 0) { visited = []; }
1992
-    var result = [];
1993
-    visited.push(object);
1994
-    for (var key in object) {
1995
-        var value = object[key];
1996
-        if (visited.indexOf(value) === -1) {
1997
-            var key_ = (path == null) ? key : (path + "." + key);
1998
-            if (typeof (value) === "object") {
1999
-                result = result.concat(object_path_list(value, key_, visited));
2047
+    function from_array(array) {
2048
+        var object = {};
2049
+        array.forEach(function (entry) { return (object[entry.key] = entry.value); });
2050
+        return object;
2000 2051
     }
2001
-            else {
2002
-                result.push({ "key": key_, "value": value });
2052
+    lib_object.from_array = from_array;
2053
+    /**
2054
+     * @author fenris
2055
+     */
2056
+    function to_array(object) {
2057
+        var array = [];
2058
+        Object.keys(object).forEach(function (key) { return array.push({ "key": key, "value": object[key] }); });
2059
+        return array;
2003 2060
     }
2061
+    lib_object.to_array = to_array;
2062
+    /**
2063
+     * @author fenris
2064
+     */
2065
+    function keys(object) {
2066
+        return Object.keys(object);
2004 2067
     }
2068
+    lib_object.keys = keys;
2069
+    /**
2070
+     * @author fenris
2071
+     */
2072
+    function values(object) {
2073
+        return to_array(object).map(function (entry) { return entry.value; });
2005 2074
     }
2006
-    return result;
2007
-};
2075
+    lib_object.values = values;
2008 2076
     /**
2009
- * theroreticaly loop prof walk through all elements and subelements of an object
2010
- * and call a callback for each entry
2011
- * @param {object} obj object to iterate through
2012
- * @param {function} callback
2077
+     * @author fenris
2013 2078
      */
2014
-/*export*/ var object_iterate = function (obj, callback, leafs_only, path, visited) {
2015
-    if (leafs_only === void 0) { leafs_only = false; }
2016
-    if (visited === void 0) { visited = []; }
2017
-    var have_seen = function (ob) {
2018
-        return visited.some(function (e) { return ((typeof (ob) === "object") && (ob !== null) && (e === ob)); });
2019
-    };
2020
-    var next = [];
2021
-    Object.keys(obj).forEach(function (key) {
2022
-        var elem = obj[key];
2023
-        if (!have_seen(elem)) {
2024
-            visited.push(elem);
2025
-            var _path = "";
2026
-            if (typeof path === "undefined") {
2027
-                _path = key;
2079
+    function path_read(object, path, fallback, escalation) {
2080
+        if (fallback === void 0) { fallback = null; }
2081
+        if (escalation === void 0) { escalation = 1; }
2082
+        var steps = ((path.length == 0) ? [] : path.split("."));
2083
+        if (steps.length == 0) {
2084
+            throw (new Error("empty path"));
2028 2085
         }
2029 2086
         else {
2030
-                _path += [path, key].join(".");
2031
-            }
2032
-            if (!leafs_only)
2033
-                callback(_path, elem, key);
2034
-            if (typeof (elem) === "object") {
2035
-                (function (elem_, callback_, _path_, visited_) {
2036
-                    next.push(function () { object_iterate(elem_, callback_, leafs_only, _path_, visited_); });
2037
-                })(elem, callback, _path, visited);
2087
+            var position_1 = object;
2088
+            var reachable = (position_1 != null) && steps.slice(0, steps.length - 1).every(function (step) {
2089
+                position_1 = object_fetch(position_1, step, null, 0);
2090
+                return (position_1 != null);
2091
+            });
2092
+            if (reachable) {
2093
+                return object_fetch(position_1, steps[steps.length - 1], fallback, escalation);
2038 2094
             }
2039 2095
             else {
2040
-                if (leafs_only)
2041
-                    callback(_path, elem, key);
2096
+                return object_fetch({}, "_dummy_", fallback, escalation);
2042 2097
             }
2043 2098
         }
2044
-    });
2045
-    var func;
2046
-    while (func = next.shift()) {
2047
-        func();
2048 2099
     }
2049
-};
2100
+    lib_object.path_read = path_read;
2050 2101
     /**
2051
- * @desc get the leaf-nodes of an object
2052
- * @param {object} object
2053
- * @return {Array<string>} a list containing all leaf-nodes
2054
- * @author frac
2102
+     * @author fenris
2055 2103
      */
2056
-/*export*/ var getLeafs = function (object) {
2057
-    var skip = {
2058
-        "className": true,
2059
-        "timeStamp": true,
2060
-        "parentId": true,
2061
-        "transactionID": true,
2062
-        "guid": true,
2063
-        "_id": true,
2064
-        "parents": true,
2065
-        "children": true
2066
-    };
2067
-    return (Object.keys(object).reduce(function (leafs, key) {
2068
-        try {
2069
-            var value = object[key];
2070
-            if (key in skip) {
2071
-                console.warn("skipping field \"" + key + "\"");
2072
-                return leafs;
2104
+    function path_write(object, path, value, construct) {
2105
+        if (construct === void 0) { construct = true; }
2106
+        var steps = ((path.length == 0) ? [] : path.split("."));
2107
+        if (steps.length == 0) {
2108
+            throw (new Error("empty path"));
2073 2109
         }
2074 2110
         else {
2075
-                if ((typeof (value) === "object") && (value != null)) {
2076
-                    return leafs.concat(getLeafs(value).map(function (leaf) { return (key + "." + leaf); }));
2111
+            var position_2 = object;
2112
+            var reachable = steps.slice(0, steps.length - 1).every(function (step) {
2113
+                var position_ = object_fetch(position_2, step, null, 0);
2114
+                if (position_ == null) {
2115
+                    if (construct) {
2116
+                        position_2[step] = {};
2117
+                        position_2 = position_2[step];
2118
+                        return true;
2077 2119
                     }
2078 2120
                     else {
2079
-                    return leafs.concat([key]);
2121
+                        return false;
2122
+                    }
2123
+                }
2124
+                else {
2125
+                    position_2 = position_;
2126
+                    return true;
2127
+                }
2128
+            });
2129
+            if (reachable) {
2130
+                position_2[steps[steps.length - 1]] = value;
2080 2131
             }
2132
+            else {
2133
+                throw (new Error("path " + path + " does not exist and may not be constructed"));
2081 2134
             }
2082 2135
         }
2083
-        catch (exception) {
2084
-            console.warn(exception);
2085
-            console.info("key: ", key);
2086
-            return null;
2087 2136
     }
2088
-    }, new Array()));
2089
-};
2137
+    lib_object.path_write = path_write;
2090 2138
     /**
2091
- *
2092
- * @desc merges two arrays by probing
2093
- * @param {Array} core
2094
- * @param {Array} mantle
2095
- * @param {function} match
2139
+     * @author fenris
2096 2140
      */
2097
-/*export*/ var merge_array = function (core, mantle, match) {
2098
-    if (match === void 0) { match = (function (x, y) { return (x === y); }); }
2099
-    if ((core == undefined) || (mantle == undefined)) {
2100
-        throw (new Error("Error: "
2101
-            + ((core == undefined) ? " core must be an array and not '" + typeof (core) + "'" : "")
2102
-            + ((mantle == undefined) ? " mantle must be an array and not '" + typeof (mantle) + "'" : "")));
2141
+    function matches(object, pattern, collate) {
2142
+        if (collate === void 0) { collate = instance_collate; }
2143
+        return Object.keys(pattern).every(function (key) { return collate(pattern[key], object[key]); });
2103 2144
     }
2104
-    var ret = core;
2105
-    for (var i = 0; i < mantle.length; i++) {
2106
-        var entry = mantle[i];
2107
-        try {
2108
-            var matching_index = core.find(function (element) { return match(element, entry); });
2109
-            ret[matching_index] = object_merge_objects(core[matching_index], entry);
2110
-        }
2111
-        catch (e) {
2112
-            ret.push(entry);
2113
-        }
2114
-    }
2115
-    return ret;
2116
-};
2145
+    lib_object.matches = matches;
2117 2146
     /**
2118
- * @desc merges two objects recursivly
2119
- * @param {Object} object1 core
2120
- * @param {Object} object2 mantle
2121
- * @param {Array} [ignore_keys]
2122
- * @param [do_not_overwrite_existing_values]
2123
- * @returns {Object} a clone of object1 will be returned
2147
+     * @author fenris
2124 2148
      */
2125
-/*export*/ var object_merge_objects = function (object1, object2, ignore_keys, do_not_overwrite_existing_values, ignore_null, path) {
2126
-    if (object1 === void 0) { object1 = null; }
2127
-    if (object2 === void 0) { object2 = null; }
2128
-    if (ignore_keys === void 0) { ignore_keys = ["parents"]; }
2129
-    if (do_not_overwrite_existing_values === void 0) { do_not_overwrite_existing_values = false; }
2130
-    if (ignore_null === void 0) { ignore_null = false; }
2131
-    if (path === void 0) { path = []; }
2132
-    if (object1 == null) {
2133
-        if (object2 instanceof Array) {
2134
-            object1 = [];
2149
+    function flatten(value) {
2150
+        var integrate = function (result, key_, value_) {
2151
+            if (value_ == null) {
2152
+                result[key_] = value_;
2135 2153
             }
2136 2154
             else {
2137
-            object1 = {};
2155
+                if (typeof (value_) != "object") {
2156
+                    result[key_] = value_;
2138 2157
                 }
2158
+                else {
2159
+                    var result_1 = flatten(value_);
2160
+                    Object.keys(result_1).forEach(function (key__) {
2161
+                        var value__ = result_1[key__];
2162
+                        result[key_ + "." + key__] = value__;
2163
+                    });
2139 2164
                 }
2140
-    var iteration_keys = Object.keys(object2);
2141
-    if (ignore_keys === []) {
2142
-        if (path.indexOf(object2) >= 0)
2143
-            return undefined;
2144
-        path.push(object2);
2145 2165
             }
2146
-    //
2147
-    for (var i = 0; i < iteration_keys.length; i += 1) {
2148
-        var key = iteration_keys[i];
2149
-        if (ignore_keys.some(function (k) {
2150
-            return key == k;
2151
-        })) {
2152
-            //
2166
+        };
2167
+        if (value == null) {
2168
+            return null;