Browse code

updated build tool koralle

Christian Fraß authored on25/07/2017 08:22:10
Showing2 changed files
... ...
@@ -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;
... ...
@@ -1388,6 +1336,23 @@ var lib_call;
1388 1336
         return (new Promise(executor));
1389 1337
     }
1390 1338
     lib_call.promise_make = promise_make;
1339
+    /**
1340
+     * @author fenris
1341
+     */
1342
+    function promise_then_close(promise, resolver, rejector) {
1343
+        return (promise.then(resolver, rejector));
1344
+    }
1345
+    lib_call.promise_then_close = promise_then_close;
1346
+    /**
1347
+     * @author fenris
1348
+     */
1349
+    function promise_then_append(promise, resolver, rejector = null) {
1350
+        if (rejector == null) {
1351
+            rejector = (reason) => promise_reject(reason);
1352
+        }
1353
+        return (promise.then(resolver, rejector));
1354
+    }
1355
+    lib_call.promise_then_append = promise_then_append;
1391 1356
     /**
1392 1357
      * @author fenris
1393 1358
      */
... ...
@@ -1395,1010 +1360,1552 @@ var lib_call;
1395 1360
         return Promise.all(promises);
1396 1361
     }
1397 1362
     lib_call.promise_all = promise_all;
1398
-})(lib_call || (lib_call = {}));
1399
-
1400
-(function (exports) {
1401
-	
1402
-	/**
1403
-	 * @author fenris
1404
-	 */
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
-		);
1414
-	}
1415
-	exports.promise_chain = promise_chain;
1416
-	
1417
-
1418
-	/**
1419
-	 * @author fenris
1420
-	 */
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
-					)
1433
-				}
1434
-			)
1435
-		);
1436
-	}
1437
-	exports.promise_wrap = promise_wrap;
1438
-
1439
-
1440
-	/**
1441
-	 * @author fenris
1442
-	 */
1443
-	function promise_log(state) {
1444
-		return (
1445
-			new Promise(
1446
-				(resolve, reject) => {
1447
-					lib_log.info(state);
1448
-					resolve(state);
1449
-				}
1450
-			)
1451
-		);
1452
-	}
1453
-	exports.promise_log = promise_log;
1454
-
1455
-
1456
-	/**
1457
-	 * @author fenris
1458
-	 */
1459
-	function promise_attach(
1460
-		state,
1461
-		promise,
1462
-		name
1463
-	) {
1464
-		return (
1465
-			promise_wrap(
1466
-				promise,
1467
-				result => {
1468
-					state[name] = result;
1469
-					return state;
1470
-				}
1471
-			)
1472
-		);
1473
-	}
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 1363
     /**
1482 1364
      * @author fenris
1483 1365
      */
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];
1489
-        }
1490
-        else {
1491
-            switch (escalation) {
1492
-                case 0: {
1493
-                    return fallback;
1494
-                    break;
1495
-                }
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
-                    break;
1502
-                }
1503
-                case 2: {
1504
-                    var message = ("field '" + fieldname + "' not in structure");
1505
-                    throw (new Error(message));
1506
-                    break;
1507
-                }
1508
-                default: {
1509
-                    throw (new Error("invalid escalation level " + escalation));
1510
-                    break;
1511
-                }
1512
-            }
1513
-        }
1366
+    function promise_chain(promises, start = undefined) {
1367
+        return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start)));
1514 1368
     }
1515
-    lib_object.fetch = fetch;
1369
+    lib_call.promise_chain = promise_chain;
1516 1370
     /**
1517 1371
      * @author fenris
1518 1372
      */
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;
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
+        }));
1523 1377
     }
1524
-    lib_object.map = map;
1378
+    lib_call.promise_wrap = promise_wrap;
1525 1379
     /**
1526 1380
      * @author fenris
1527 1381
      */
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;
1382
+    function promise_show(label) {
1383
+        return (result => promise_make((resolve, reject) => {
1384
+            lib_log.info(label + ": " + instance_show(result));
1385
+            resolve(result);
1386
+        }));
1537 1387
     }
1538
-    lib_object.filter = filter;
1388
+    lib_call.promise_show = promise_show;
1539 1389
     /**
1540 1390
      * @author fenris
1541 1391
      */
1542
-    function from_array(array) {
1543
-        var object = {};
1544
-        array.forEach(function (entry) { return (object[entry.key] = entry.value); });
1545
-        return object;
1392
+    function promise_log(result) {
1393
+        return promise_show("log");
1546 1394
     }
1547
-    lib_object.from_array = from_array;
1395
+    lib_call.promise_log = promise_log;
1548 1396
     /**
1549 1397
      * @author fenris
1550 1398
      */
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;
1399
+    function promise_attach(state, promise, name) {
1400
+        return (promise_wrap(promise, result => {
1401
+            state[name] = result;
1402
+            return state;
1403
+        }));
1555 1404
     }
1556
-    lib_object.to_array = to_array;
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) {
1557 1412
     /**
1558 1413
      * @author fenris
1559 1414
      */
1560
-    function keys(object) {
1561
-        return Object.keys(object);
1415
+    lib_trait._verbosity = 1;
1416
+    /**
1417
+     * @author fenris
1418
+     */
1419
+    function type_show(type) {
1420
+        return JSON.stringify(type);
1562 1421
     }
1563
-    lib_object.keys = keys;
1564 1422
     /**
1565 1423
      * @author fenris
1566 1424
      */
1567
-    function values(object) {
1568
-        return to_array(object).map(function (entry) { return entry.value; });
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];
1431
+                }
1432
+                else {
1433
+                    var message = "binding missing for variable '" + variable_name + "'";
1434
+                    throw (new Error(message));
1435
+                }
1436
+                break;
1437
+            }
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
+                };
1450
+                break;
1451
+            }
1452
+            default: {
1453
+                return raw;
1454
+                break;
1455
+            }
1456
+        }
1569 1457
     }
1570
-    lib_object.values = values;
1571 1458
     /**
1459
+     * @desc holds all defined traits
1572 1460
      * @author fenris
1573 1461
      */
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"));
1462
+    var _pool = {};
1463
+    /**
1464
+     * @author fenris
1465
+     */
1466
+    var _typechecker;
1467
+    /**
1468
+     * @author fenris
1469
+     */
1470
+    function set_typechecker(typechecker) {
1471
+        _typechecker = typechecker;
1472
+    }
1473
+    lib_trait.set_typechecker = set_typechecker;
1474
+    /**
1475
+     * @author fenris
1476
+     */
1477
+    function domain_instance(domain, value) {
1478
+        return { "domain": domain, "value": value };
1479
+    }
1480
+    lib_trait.domain_instance = domain_instance;
1481
+    /**
1482
+     * @desc adds a trait
1483
+     * @author fenris
1484
+     */
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;
1580 1489
         }
1581 1490
         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);
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;
1586 1501
             });
1587
-            if (reachable) {
1588
-                return object_fetch(position_1, steps[steps.length - 1], fallback, escalation);
1589
-            }
1590
-            else {
1591
-                return object_fetch({}, "_dummy_", fallback, escalation);
1592
-            }
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;
1593 1510
         }
1594 1511
     }
1595
-    lib_object.path_read = path_read;
1512
+    lib_trait.describe = describe;
1596 1513
     /**
1514
+     * @desc adhoc binding
1597 1515
      * @author fenris
1598 1516
      */
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"));
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];
1531
+                            }
1532
+                            else {
1533
+                                var message = "variable '" + variable_name + "' already bound for domain '" + domain_kind + "' in trait '" + trait_id + "'";
1534
+                                throw (new Error(message));
1535
+                            }
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));
1541
+                        }
1542
+                    });
1543
+                }
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];
1551
+                            }
1552
+                            else {
1553
+                                var message = "facet '" + facet_name + "' already implemented for domain '" + domain_kind + "' in trait '" + trait_id + "'";
1554
+                                throw (new Error(message));
1555
+                            }
1556
+                        }
1557
+                        else {
1558
+                            var message = "no facet '" + facet_name + "' to implement in trait '" + trait_id + "'";
1559
+                            console.warn(message);
1560
+                            // throw (new Error(message));
1561
+                        }
1562
+                    });
1563
+                }
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);
1577
+                        });
1578
+                    }
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
+                        });
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));
1594
+                    }
1595
+                }
1596
+            }
1604 1597
         }
1605 1598
         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;
1599
+            var message = "no trait '" + trait_id + "'";
1600
+            throw (new Error(message));
1601
+        }
1602
+    }
1603
+    lib_trait.assign = assign;
1604
+    /**
1605
+     * @author fenris
1606
+     */
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);
1624
+                        }
1614 1625
                     }
1615
-                    else {
1616
-                        return false;
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);
1633
+                        }
1617 1634
                     }
1635
+                    return output;
1618 1636
                 }
1619 1637
                 else {
1620
-                    position_2 = position_;
1621
-                    return true;
1638
+                    var message = "implementation for facet '" + facet_name + "' missing for domain '" + domain.kind + "' belonging to the trait '" + trait_id + "'";
1639
+                    throw (new Error(message));
1622 1640
                 }
1623
-            });
1624
-            if (reachable) {
1625
-                position_2[steps[steps.length - 1]] = value;
1626 1641
             }
1627 1642
             else {
1628
-                throw (new Error("path " + path + " does not exist and may not be constructed"));
1643
+                var message = "no facet '" + facet_name + "' in trait '" + trait_id + "'";
1644
+                throw (new Error(message));
1629 1645
             }
1630 1646
         }
1647
+        else {
1648
+            var message = "no trait '" + trait_id + "'";
1649
+            throw (new Error(message));
1650
+        }
1631 1651
     }
1632
-    lib_object.path_write = path_write;
1652
+    lib_trait.call = call;
1633 1653
     /**
1634 1654
      * @author fenris
1635 1655
      */
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]); });
1656
+    function show() {
1657
+        console.info(JSON.stringify(_pool, undefined, "\t"));
1658
+        // console.info(_pool);
1639 1659
     }
1640
-    lib_object.matches = matches;
1660
+    lib_trait.show = show;
1661
+})(lib_trait || (lib_trait = {}));
1662
+/**
1663
+ * @author fenris
1664
+ */
1665
+var lib_trait;
1666
+(function (lib_trait) {
1641 1667
     /**
1668
+     * @desc the ability to check for equality with another element of the same domain
1642 1669
      * @author fenris
1643 1670
      */
1644
-    function flatten(value) {
1645
-        var integrate = function (result, key_, value_) {
1646
-            if (value_ == null) {
1647
-                result[key_] = value_;
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"
1703
+                }
1648 1704
             }
1649
-            else {
1650
-                if (typeof (value_) != "object") {
1651
-                    result[key_] = value_;
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);
1716
+                    }
1717
+                    else {
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
+                    }
1652 1725
                 }
1653 1726
                 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
-                    });
1727
+                    if (lib_trait._verbosity >= 1) {
1728
+                        console.warn("[collate]" + " " + "primitive value; using default implementation");
1729
+                    }
1730
+                    return (x === y);
1659 1731
                 }
1660
-            }
1661
-        };
1662
-        if (value == null) {
1663
-            return null;
1664
-        }
1665
-        else {
1666
-            var result_2 = {};
1667
-            if (typeof (value) != "object") {
1668
-                result_2["value"] = value;
1669
-            }
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
-                }
1675
-                else {
1676
-                    var object_1 = (value);
1677
-                    Object.keys(object_1).forEach(function (key) { return integrate(result_2, key, object_1[key]); });
1678
-                }
1679
-            }
1680
-            return result_2;
1681
-        }
1682
-    }
1683
-    lib_object.flatten = flatten;
1684
-    /**
1685
-     * @author fenris
1686
-     */
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"); });
1691
-        }
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
-                }
1702
-            }
1703
-            else {
1704
-                z[key] = y[key];
1705
-            }
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 = {}));
1737
+/**
1738
+ * @author fenris
1739
+ */
1740
+var lib_trait;
1741
+(function (lib_trait) {
1710 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
1711 1744
      * @author fenris
1712 1745
      */
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);
1718
-        }
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_);
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"
1761
+                                    }
1732 1762
                                 }
1733
-                                else {
1734
-                                    core[key].push(element);
1763
+                            },
1764
+                            {
1765
+                                "name": "right",
1766
+                                "type": {
1767
+                                    "kind": "variable",
1768
+                                    "parameters": {
1769
+                                        "name": "value"
1770
+                                    }
1735 1771
                                 }
1736
-                            });
1737
-                        }
1738
-                        else {
1739
-                            core[key] = {};
1740
-                            patch(core[key], value_mantle, deep, path_);
1741
-                        }
1772
+                            }
1773
+                        ]
1774
+                    }
1775
+                },
1776
+                "type_output": {
1777
+                    "kind": "boolean"
1778
+                }
1779
+            }
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);
1742 1791
                     }
1743 1792
                     else {
1744
-                        core[key] = value_mantle;
1793
+                        throw (new Error("[compare]" + " " + "object has no such method"));
1745 1794
                     }
1746 1795
                 }
1747 1796
                 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_);
1752
-                        }
1753
-                        else {
1754
-                            core[key] = value_mantle;
1755
-                        }
1756
-                    }
1757
-                    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
                 }
1764
-            });
1765
-        }
1766
-    }
1767
-    lib_object.patch = patch;
1768
-    /**
1769
-     * @author fenris
1770
-     */
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;
1779
-    /**
1780
-     * @author fenris
1781
-     */
1782
-    function attached(object, key, value) {
1783
-        var mantle = {};
1784
-        mantle[key] = value;
1785
-        return patched(object, mantle, false);
1802
+            }; }
1803
+        });
1786 1804
     }
1787
-    lib_object.attached = attached;
1805
+    lib_trait.define_comparable = define_comparable;
1806
+})(lib_trait || (lib_trait = {}));
1807
+/**
1808
+ * @author fenris
1809
+ */
1810
+var lib_trait;
1811
+(function (lib_trait) {
1788 1812
     /**
1813
+     * @desc the ability to create an exact copy
1789 1814
      * @author fenris
1790 1815
      */
1791
-    function copy(object) {
1792
-        return patched({}, object);
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"
1825
+                    }
1826
+                },
1827
+                "type_output": {
1828
+                    "kind": "variable",
1829
+                    "parameters": {
1830
+                        "name": "value"
1831
+                    }
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
+        });
1793 1857
     }
1794
-    lib_object.copy = copy;
1795
-})(lib_object || (lib_object = {}));
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
-};
1819
-/**
1820
- * @param {Array} array
1821
- * @return {string}
1822
- * @author frac
1823
- */
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);
1829
-        }
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;
1846
-    }
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
-                        }
1860
-                        else {
1861
-                            value = {};
1862
-                        }
1863
+var lib_trait;
1864
+(function (lib_trait) {
1865
+    /**
1866
+     * @desc the ability to generate a string out of the element, which identifies it to a high degree
1867
+     * @author fenris
1868
+     */
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"
1878
+                    }
1879
+                },
1880
+                "type_output": {
1881
+                    "kind": "string"
1882
+                }
1883
+            }
1884
+        });
1885
+        lib_trait.assign("auto", "hashable", {
1886
+            "value": {
1887
+                "kind": "any"
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);
1904
+                }
1905
+            }; }
1906
+        });
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"
1878 1928
                     }
1929
+                },
1930
+                "type_output": {
1931
+                    "kind": "string"
1879 1932
                 }
1880 1933
             }
1881
-        }
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
-        }
1888
-    }
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] = {};
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";
1896 1944
                     }
1897 1945
                     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;
1946
+                        if ("_show" in x) {
1947
+                            return x["_show"]();
1903 1948
                         }
1904 1949
                         else {
1905
-                            throw (new Error(message));
1950
+                            // throw (new Error("[show]" + " " + "object has no such method"));
1951
+                            return JSON.stringify(x);
1906 1952
                         }
1907 1953
                     }
1908 1954
                 }
1909
-                return position[step];
1910
-            },
1911
-            object
1912
-        )
1913
-    );
1914
-     */
1915
-};
1955
+                else {
1956
+                    if (lib_trait._verbosity >= 1) {
1957
+                        console.warn("[show]" + " " + "primitive value; using default implementation");
1958
+                    }
1959
+                    return String(x);
1960
+                }
1961
+            }; }
1962
+        });
1963
+    }
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
1919
- */
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
-};
1924
-/**
1925
- * @desc writes a branch/leaf to an object-tree
1926
- * @author frac
1967
+ * @author fenris
1927 1968
  */
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");
1969
+var lib_trait;
1970
+(function (lib_trait) {
1971
+    /**
1972
+     * @author fenris
1973
+     */
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();
1935 1980
     }
1936
-    else {
1937
-        position[steps[steps.length - 1]] = value;
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];
1994
+        }
1995
+        else {
1996
+            switch (escalation) {
1997
+                case 0: {
1998
+                    return fallback;
1999
+                    break;
2000
+                }
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;
2007
+                }
2008
+                case 2: {
2009
+                    var message = ("field '" + fieldname + "' not in structure");
2010
+                    throw (new Error(message));
2011
+                    break;
2012
+                }
2013
+                default: {
2014
+                    throw (new Error("invalid escalation level " + escalation));
2015
+                    break;
2016
+                }
2017
+            }
2018
+        }
1938 2019
     }
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]] = [];
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;
2028
+    }
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;
2039
+            }
2040
+        });
2041
+        return object_to;
2042
+    }
2043
+    lib_object.filter = filter;
2044
+    /**
2045
+     * @author fenris
2046
+     */
2047
+    function from_array(array) {
2048
+        var object = {};
2049
+        array.forEach(function (entry) { return (object[entry.key] = entry.value); });
2050
+        return object;
2051
+    }
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;
2060
+    }
2061
+    lib_object.to_array = to_array;
2062
+    /**
2063
+     * @author fenris
2064
+     */
2065
+    function keys(object) {
2066
+        return Object.keys(object);
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; });
2074
+    }
2075
+    lib_object.values = values;
2076
+    /**
2077
+     * @author fenris
2078
+     */
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"));
2085
+        }
2086
+        else {
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);
1948 2094
             }
1949 2095
             else {
1950
-                ref[paths[i]] = {};
2096
+                return object_fetch({}, "_dummy_", fallback, escalation);
1951 2097
             }
1952 2098
         }
1953
-        ref = ref[paths[i]];
1954 2099
     }
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
-        }
1971
-        catch (exception) {
1972
-            console.warn(exception);
1973
-        }
1974
-        if (value != null) {
1975
-            object_path_write(result, path, value);
2100
+    lib_object.path_read = path_read;
2101
+    /**
2102
+     * @author fenris
2103
+     */
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"));
1976 2109
         }
1977 2110
         else {
1978
-            console.warn("skipped path \"" + path + "\" while filtering");
1979
-        }
1980
-    });
1981
-    return result;
1982
-};
1983
-/**
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
1988
- */
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));
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;
2119
+                    }
2120
+                    else {
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;
2000 2131
             }
2001 2132
             else {
2002
-                result.push({ "key": key_, "value": value });
2133
+                throw (new Error("path " + path + " does not exist and may not be constructed"));
2003 2134
             }
2004 2135
         }
2005 2136
     }
2006
-    return result;
2007
-};
2008
-/**
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
2013
- */
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;
2137
+    lib_object.path_write = path_write;
2138
+    /**
2139
+     * @author fenris
2140
+     */
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]); });
2144
+    }
2145
+    lib_object.matches = matches;
2146
+    /**
2147
+     * @author fenris
2148
+     */
2149
+    function flatten(value) {
2150
+        var integrate = function (result, key_, value_) {
2151
+            if (value_ == null) {
2152
+                result[key_] = value_;
2028 2153
             }
2029 2154
             else {
2030
-                _path += [path, key].join(".");
2155
+                if (typeof (value_) != "object") {
2156
+                    result[key_] = value_;
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
+                    });
2164
+                }
2031 2165
             }
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);
2166
+        };
2167
+        if (value == null) {
2168
+            return null;
2169
+        }
2170
+        else {
2171
+            var result_2 = {};
2172
+            if (typeof (value) != "object") {
2173
+                result_2["value"] = value;
2038 2174
             }
2039 2175
             else {
2040
-                if (leafs_only)
2041
-                    callback(_path, elem, key);
2176
+                if (value instanceof Array) {
2177
+                    var array = (value);
2178
+                    array.forEach(function (element, index) { return integrate(result_2, "element_" + index, element); });
2179
+                }
2180
+                else {
2181
+                    var object_1 = (value);
2182
+                    Object.keys(object_1).forEach(function (key) { return integrate(result_2, key, object_1[key]); });
2183
+                }
2042 2184
             }
2185
+            return result_2;
2043 2186
         }
2044
-    });
2045
-    var func;
2046
-    while (func = next.shift()) {
2047
-        func();
2048 2187
     }
2049
-};
2050
-/**
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
2055
- */
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;
2188
+    lib_object.flatten = flatten;
2189
+    /**
2190
+     * @author fenris
2191
+     */
2192
+    function clash(x, y, _a) {
2193
+        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;
2194
+        if (hook_existing == null) {
2195
+            (function (key, value_old, value_new) { return console.warn("field " + key + " already defined"); });
2196
+        }
2197
+        var z = {};
2198
+        Object.keys(x).forEach(function (key) {
2199
+            z[key] = x[key];
2200
+        });
2201
+        Object.keys(y).forEach(function (key) {
2202
+            if (key in z) {
2203
+                hook_existing(key, z[key], y[key]);
2204
+                if (overwrite) {
2205
+                    z[key] = y[key];
2206
+                }
2073 2207
             }
2074 2208
             else {
2075
-                if ((typeof (value) === "object") && (value != null)) {
2076
-                    return leafs.concat(getLeafs(value).map(function (leaf) { return (key + "." + leaf); }));
2209
+                z[key] = y[key];
2210
+            }
2211
+        });
2212
+        return z;
2213
+    }
2214
+    lib_object.clash = clash;
2215
+    /**
2216
+     * @author fenris
2217
+     */
2218
+    function patch(core, mantle, deep, path) {
2219
+        if (deep === void 0) { deep = true; }
2220
+        if (path === void 0) { path = null; }
2221
+        if (mantle == null) {
2222
+            console.warn("mantle is null; core was", core);
2223
+        }
2224
+        else {
2225
+            Object.keys(mantle).forEach(function (key) {
2226
+                var path_ = ((path == null) ? key : path + "." + key);
2227
+                var value_mantle = mantle[key];
2228
+                if (!(key in core)) {
2229
+                    if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) {
2230
+                        if (value_mantle instanceof Array) {
2231
+                            core[key] = [];
2232
+                            value_mantle.forEach(function (element) {
2233
+                                if ((typeof (element) == "object") && (element != null)) {
2234
+                                    var element_ = {};
2235
+                                    patch(element_, element);
2236
+                                    core[key].push(element_);
2237
+                                }
2238
+                                else {
2239
+                                    core[key].push(element);
2240
+                                }
2241
+                            });
2242
+                        }
2243
+                        else {
2244
+                            core[key] = {};
2245
+                            patch(core[key], value_mantle, deep, path_);
2246
+                        }
2247
+                    }
2248
+                    else {
2249
+                        core[key] = value_mantle;
2250
+                    }
2077 2251
                 }
2078 2252
                 else {
2079
-                    return leafs.concat([key]);
2253
+                    var value_core = core[key];
2254
+                    if (typeof (value_core) == typeof (value_mantle)) {
2255
+                        if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) {
2256
+                            patch(core[key], value_mantle, deep, path_);
2257
+                        }
2258
+                        else {
2259
+                            core[key] = value_mantle;
2260
+                        }
2261
+                    }
2262
+                    else {
2263
+                        if ((value_core != null) && (value_mantle != null)) {
2264
+                            var message = "objects have different shapes at path '" + path_ + "'; core has type '" + typeof (value_core) + "' and mantle has type '" + typeof (value_mantle) + "'";
2265
+                            console.warn(message);
2266
+                        }
2267
+                        core[key] = value_mantle;
2268
+                        // throw (new Error(message));
2269
+                    }
2080 2270
                 }
2081
-            }
2082
-        }
2083
-        catch (exception) {
2084
-            console.warn(exception);
2085
-            console.info("key: ", key);
2086
-            return null;
2271
+            });
2087 2272
         }
2088
-    }, new Array()));
2273
+    }
2274
+    lib_object.patch = patch;
2275
+    /**
2276
+     * @author fenris
2277
+     */
2278
+    function patched(core, mantle, deep) {
2279
+        if (deep === void 0) { deep = undefined; }
2280
+        var result = {};
2281
+        patch(result, core, deep);
2282
+        patch(result, mantle, deep);
2283
+        return result;
2284
+    }
2285
+    lib_object.patched = patched;
2286
+    /**
2287
+     * @author fenris
2288
+     */
2289
+    function attached(object, key, value) {
2290
+        var mantle = {};
2291
+        mantle[key] = value;
2292
+        return patched(object, mantle, false);
2293
+    }
2294
+    lib_object.attached = attached;
2295
+    /**
2296
+     * @author fenris
2297
+     */
2298
+    function copy(object) {
2299
+        return patched({}, object);
2300
+    }
2301
+    lib_object.copy = copy;
2302
+})(lib_object || (lib_object = {}));
2303
+/**
2304
+ * @desc adapters for old syntax
2305
+ * @author fenris
2306
+ */
2307
+var object_fetch = lib_object.fetch;
2308
+var object_map = lib_object.map;
2309
+var object_a2o = lib_object.from_array;
2310
+var object_o2a = lib_object.to_array;
2311
+var object_matches = lib_object.matches;
2312
+var object_clash = lib_object.clash;
2313
+///<reference path="../../base/build/logic-decl.d.ts"/>
2314
+/**
2315
+ * @param {Object} map
2316
+ * @return {string}
2317
+ * @author frac
2318
+ */
2319
+/*export*/ var object_map2string = function (map) {
2320
+    return (" " + Object.keys(map)
2321
+        .filter(function (key) { return (key != "isMapped"); })
2322
+        .map(function (key) { return ("" + ((map[key] == null) ? "-" : map[key].toString()) + ""); })
2323
+        .join(" ")
2324
+        + "");
2089 2325
 };
2090 2326
 /**
2091
- *
2092
- * @desc merges two arrays by probing
2093
- * @param {Array} core
2094
- * @param {Array} mantle
2095
- * @param {function} match
2327
+ * @param {Array} array
2328
+ * @return {string}
2329
+ * @author frac
2096 2330
  */