Christian Fraß commited on 2017-07-25 08:22:10
Zeige 2 geänderte Dateien mit 6503 Einfügungen und 4384 Löschungen.
... | ... |
@@ -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; |
|
2153 | 2169 |
} |
2154 |
- else if (object2[key] === null) { |
|
2155 |
- if (!ignore_null) |
|
2156 |
- object1[key] = null; |
|
2170 |
+ else { |
|
2171 |
+ var result_2 = {}; |
|
2172 |
+ if (typeof (value) != "object") { |
|
2173 |
+ result_2["value"] = value; |
|
2157 | 2174 |
} |
2158 |
- else if ((typeof (object2[key]) === "object") && ((typeof (object1[key]) === "object") || (typeof (object1[key]) === "undefined"))) { |
|
2159 |
- object1[key] = object_merge_objects(object1[key], object2[key], ignore_keys, do_not_overwrite_existing_values, ignore_null, path); |
|
2175 |
+ else { |
|
2176 |
+ if (value instanceof Array) { |
|
2177 |
+ var array = (value); |
|
2178 |
+ array.forEach(function (element, index) { return integrate(result_2, "element_" + index, element); }); |
|
2160 | 2179 |
} |
2161 | 2180 |
else { |
2162 |
- if ((do_not_overwrite_existing_values === false) || (typeof (object1[key]) === "undefined")) { |
|
2163 |
- object1[key] = object2[key]; |
|
2181 |
+ var object_1 = (value); |
|
2182 |
+ Object.keys(object_1).forEach(function (key) { return integrate(result_2, key, object_1[key]); }); |
|
2164 | 2183 |
} |
2165 | 2184 |
} |
2185 |
+ return result_2; |
|
2166 | 2186 |
} |
2167 |
- return object1; |
|
2168 |
-}; |
|
2169 |
-/* |
|
2170 |
- * @param {object} recipie ex: { "name" : { extract : function(o) { return o["name"]; }}} |
|
2171 |
- * */ |
|
2172 |
-var flatten_object = function (obj, recipie, drop_key) { |
|
2173 |
- if (drop_key === void 0) { drop_key = (function (k) { return ["parents", "parent", "children"].indexOf(k) > -1; }); } |
|
2174 |
- var ret = {}; |
|
2175 |
- for (var key in recipie) { |
|
2176 |
- if (!drop_key(key)) { |
|
2177 |
- var prefix = (recipie[key].prefix || ""); |
|
2178 |
- var recursive = (recipie[key].recursive || -1); |
|
2179 |
- var extract = (recipie[key].extract || (function (x) { return x; })); |
|
2180 |
- var _obj = extract(obj[key]); |
|
2181 |
- if ((_obj !== null) && ((typeof _obj == "object") || (obj[key] instanceof Array)) && (!(recursive == 0))) { |
|
2182 |
- var tmp = {}; |
|
2183 |
- var _recipie = {}; |
|
2184 |
- for (var _i = 0, _a = Object.keys(_obj); _i < _a.length; _i++) { |
|
2185 |
- var k = _a[_i]; |
|
2186 |
- _recipie[k] = { |
|
2187 |
- "prefix": (prefix + key + "."), |
|
2188 |
- "recursive": (recursive - 1), |
|
2189 |
- "extract": (function (x) { return x; }) |
|
2190 |
- }; |
|
2191 | 2187 |
} |
2192 |
- tmp = flatten_object(_obj, _recipie, drop_key); |
|
2193 |
- ret = object_merge_objects(ret, tmp); |
|
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"); }); |
|
2194 | 2196 |
} |
2195 |
- else { |
|
2196 |
- ret[prefix + key] = _obj; |
|
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]; |
|
2197 | 2206 |
} |
2198 | 2207 |
} |
2208 |
+ else { |
|
2209 |
+ z[key] = y[key]; |
|
2199 | 2210 |
} |
2200 |
- return ret; |
|
2201 |
-}; |
|
2211 |
+ }); |
|
2212 |
+ return z; |
|
2213 |
+ } |
|
2214 |
+ lib_object.clash = clash; |
|
2202 | 2215 |
/** |
2203 |
- * use the complete path of an objects entry as key to make an one dimensional object |
|
2204 |
- * @param {object} object the object which should be moade flat |
|
2205 |
- * @param {string} [path] for the recursive call the current path |
|
2216 |
+ * @author fenris |
|
2206 | 2217 |
*/ |
2207 |
-/*export*/ var object_make_flat = function (object, path, filter, split_char, objects) { |
|
2218 |
+ function patch(core, mantle, deep, path) { |
|
2219 |
+ if (deep === void 0) { deep = true; } |
|
2208 | 2220 |
if (path === void 0) { path = null; } |
2209 |
- if (filter === void 0) { filter = ["parent", "children"]; } |
|
2210 |
- if (split_char === void 0) { split_char = "."; } |
|
2211 |
- if (objects === void 0) { objects = []; } |
|
2212 |
- if (object.toFlat != undefined) { |
|
2213 |
- return object.toFlat(); |
|
2221 |
+ if (mantle == null) { |
|
2222 |
+ console.warn("mantle is null; core was", core); |
|
2214 | 2223 |
} |
2215 | 2224 |
else { |
2216 |
- var ret = {}; |
|
2217 |
- var default_visited_key = "___visited_path___"; |
|
2218 |
- var visited_key; |
|
2219 |
- if (object != void 0) { |
|
2220 |
- var iterate = function (key) { |
|
2221 |
- var newkey = key; |
|
2222 |
- if ((path != undefined) && (path !== "")) { |
|
2223 |
- newkey = path + split_char + newkey; |
|
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_); |
|
2224 | 2237 |
} |
2225 |
- // do not touch objects we alrdy know |
|
2226 |
- if ((obj_ref[key] != undefined) && (!objects.some(function (e) { return (e === obj_ref); }))) { |
|
2227 |
- //if (lib_call.is_def(obj_ref[key]) && (! obj_ref[key].hasOwnProperty(visited_key)) && (key !== visited_key)) { |
|
2228 |
- if (typeof obj_ref[key] === "object") { |
|
2229 |
- ret = object_merge_objects(ret, object_make_flat(obj_ref[key], newkey, filter, split_char, objects.concat(object))); |
|
2238 |
+ else { |
|
2239 |
+ core[key].push(element); |
|
2230 | 2240 |
} |
2231 |
- else if (typeof obj_ref[key] === "function") { |
|
2232 |
- // o.O a function ... doing nothing might be the best choice |
|
2241 |
+ }); |
|
2233 | 2242 |
} |
2234 | 2243 |
else { |
2235 |
- var value = obj_ref[key]; |
|
2236 |
- ret[newkey] = value; |
|
2244 |
+ core[key] = {}; |
|
2245 |
+ patch(core[key], value_mantle, deep, path_); |
|
2237 | 2246 |
} |
2238 | 2247 |
} |
2239 |
- }; |
|
2240 |
- visited_key = default_visited_key; |
|
2241 |
- //object[visited_key] = true; |
|
2242 |
- var obj_ref = object; |
|
2243 |
- Object.keys(object).filter(function (key) { return (filter.indexOf(key) < 0); }).forEach(iterate); |
|
2244 |
- if (typeof object.getComputedValues == "function") { |
|
2245 |
- visited_key = default_visited_key + "_" + Math.random().toString(); |
|
2246 |
- obj_ref = object.getComputedValues(); |
|
2247 |
- obj_ref[visited_key] = true; |
|
2248 |
- Object.keys(obj_ref).filter(function (key) { return (filter.indexOf(key) < 0); }).forEach(iterate); |
|
2248 |
+ else { |
|
2249 |
+ core[key] = value_mantle; |
|
2249 | 2250 |
} |
2250 | 2251 |
} |
2251 | 2252 |
else { |
2252 |
- //console.warn("something went wrong with that object: ", object, "on this path:", path); |
|
2253 |
- } |
|
2254 |
- return ret; |
|
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_); |
|
2255 | 2257 |
} |
2256 |
-}; |
|
2257 |
-/** |
|
2258 |
- * splits a flat oject into an array of objects if there are paths containing numbers, which indicates |
|
2259 |
- * that there might be an array |
|
2260 |
- * used for normalisation of imports |
|
2261 |
- * @param entry |
|
2262 |
- * @param number_replace_string |
|
2263 |
- * @param {function} [match_function] how to test key if it causes a split |
|
2264 |
- * @returns {Array} |
|
2265 |
- */ |
|
2266 |
-var object_split_flat_object = function (entry, number_replace_string, fab_function, match_function) { |
|
2267 |
- if (typeof (match_function) === "undefined") { |
|
2268 |
- match_function = function (key) { |
|
2269 |
- return (!key.match(/^custom/)) && key.match(/\.[0-9]+\./); |
|
2270 |
- }; |
|
2258 |
+ else { |
|
2259 |
+ core[key] = value_mantle; |
|
2271 | 2260 |
} |
2272 |
- if (typeof (fab_function) === "undefined") { |
|
2273 |
- fab_function = function (obj, e) { |
|
2274 |
- return obj; |
|
2275 |
- }; |
|
2276 | 2261 |
} |
2277 |
- if (typeof (number_replace_string) === "undefined") { |
|
2278 |
- number_replace_string = "%d"; |
|
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); |
|
2279 | 2266 |
} |
2280 |
- var ret = {}; |
|
2281 |
- var _ret = []; |
|
2282 |
- var keys = Object.keys(entry); |
|
2283 |
- var group_keys = keys.filter(match_function); |
|
2284 |
- keys.forEach(function (key) { |
|
2285 |
- var index = 0; |
|
2286 |
- var nkey = key; |
|
2287 |
- if (match_function(key)) { |
|
2288 |
- index = Number(key.match(/[0-9]+/)[0]).valueOf(); |
|
2289 |
- nkey = key.replace(/\.[0-9]+\./, "." + number_replace_string + "."); |
|
2267 |
+ core[key] = value_mantle; |
|
2268 |
+ // throw (new Error(message)); |
|
2290 | 2269 |
} |
2291 |
- if (!ret[index]) { |
|
2292 |
- ret[index] = {}; |
|
2293 | 2270 |
} |
2294 |
- ret[index][nkey] = entry[key]; |
|
2295 | 2271 |
}); |
2296 |
- keys = Object.keys(ret).sort(); |
|
2297 |
- _ret.push(ret[0]); |
|
2298 |
- for (var index = 1; index < keys.length; index++) { |
|
2299 |
- _ret.push(fab_function(ret[keys[index]], entry)); |
|
2300 | 2272 |
} |
2301 |
- _ret[0] = object_merge_objects(_ret[0], ret[0]); |
|
2302 |
- return _ret; |
|
2303 |
-}; |
|
2304 |
-// TODO: move to exporter, it's to specific |
|
2305 |
-// to normalize the objects convert paths of a tree-like structure to a |
|
2306 |
-// key-value list with complete paths as key |
|
2307 |
-// the info object is passed to the next function as it is |
|
2308 |
-// and a flat_object (key : value) |
|
2309 |
-/*export*/ var object_make_flat_async = function (data, callback, on_progress) { |
|
2310 |
- setTimeout((function (_obj, _cb, _info) { |
|
2311 |
- return (function () { |
|
2312 |
- var ret = _obj.map(function (o) { return object_make_flat(o); }); |
|
2313 |
- _cb({ "flat_object": ret, "objects": ret, "info": _info }); |
|
2314 |
- }); |
|
2315 |
- })((typeof (data.processed.objects) === "undefined") ? data.processed.source_object : data.processed.objects, callback, data.processed.info), 0); |
|
2316 |
-}; |
|
2317 |
-var object_flatten = function (object, paths, prefix) { |
|
2318 |
- if (prefix === void 0) { prefix = ""; } |
|
2319 |
- var ret = {}; |
|
2320 |
- var paths_ = paths.reduce(function (prev, current) { |
|
2321 |
- if (current.split(".").some(function (x) { return (x === "%d"); })) { |
|
2322 |
- var path = current.split(".%d").shift(); |
|
2323 |
- var len = object_path_read(object, path).length; |
|
2324 |
- for (var i = 0; i < len; i++) { |
|
2325 |
- // prev.push(sprintf(current, [i])); |
|
2326 |
- prev.push(current.replace(new RegExp("%d"), i.toFixed(0))); |
|
2327 |
- } |
|
2328 |
- } |
|
2329 |
- else { |
|
2330 |
- prev.push(current); |
|
2331 |
- } |
|
2332 |
- return prev; |
|
2333 |
- }, []); |
|
2334 |
- for (var _i = 0, paths_1 = paths_; _i < paths_1.length; _i++) { |
|
2335 |
- var path = paths_1[_i]; |
|
2336 |
- var tmp = object_path_read(object, path, true); |
|
2337 |
- if ((tmp != undefined) && (tmp.toFlat != undefined)) { |
|
2338 |
- var tmp_ = tmp.toFlat([path, "."].join("")); |
|
2339 |
- for (var key in tmp_) { |
|
2340 |
- ret[key] = tmp_[key]; |
|
2341 | 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; |
|
2342 | 2284 |
} |
2343 |
- else { |
|
2344 |
- ret[prefix + path] = tmp; |
|
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); |
|
2345 | 2293 |
} |
2294 |
+ lib_object.attached = attached; |
|
2295 |
+ /** |
|
2296 |
+ * @author fenris |
|
2297 |
+ */ |
|
2298 |
+ function copy(object) { |
|
2299 |
+ return patched({}, object); |
|
2346 | 2300 |
} |
2347 |
- return ret; |
|
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 |
+ + ""); |
|
2348 | 2325 |
}; |
2349 | 2326 |
/** |
2350 |
- * parse |
|
2351 |
- * @param {String} value |
|
2352 |
- * @returns {Object} |
|
2327 |
+ * @param {Array} array |
|
2328 |
+ * @return {string} |
|
2329 |
+ * @author frac |
|
2353 | 2330 |
*/ |
2354 |
-var object_parse = function (value) { |
|
2355 |
- var content = JSON.parse(value); |
|
2356 |
- var m = { "root": content }; |
|
2357 |
- (new Mapper()).mapClasses(m); |
|
2358 |
- return m["root"]; |
|
2331 |
+/*export*/ var object_array2string = function (array) { |
|
2332 |
+ return ("" + array.map(function (element, index) { |
|
2333 |
+ switch (typeof (element)) { |
|
2334 |
+ case "object": return object_map2string(element); |
|
2335 |
+ default: return String(element); |
|
2336 |
+ } |
|
2337 |
+ }).join(",") + ""); |
|
2359 | 2338 |
}; |
2360 | 2339 |
/** |
2361 |
- * stringify |
|
2362 |
- * |
|
2363 |
- * @description stringify object as JSON |
|
2340 |
+ * @desc follows a path in an object-tree |
|
2341 |
+ * @param {Object} object the object in which the path lies |
|
2342 |
+ * @param {string} path the steps |
|
2343 |
+ * @param {boolean} [create] whether to create not yet existing branches |
|
2344 |
+ * @return {Object} {'successful': successful, 'position': position} where the branch or leaf at the end of the path |
|
2345 |
+ * @author frac |
|
2364 | 2346 |
*/ |
2365 |
-var object_stringify = function (object, readable) { |
|
2366 |
- if (readable === void 0) { readable = false; } |
|
2367 |
- return (JSON.stringify(object, function (key, value) { |
|
2368 |
- if ((key == "parents") && (value !== null)) { |
|
2347 |
+var object_path_walk = function (object, path, create, null_on_missing) { |
|
2348 |
+ if (create === void 0) { create = true; } |
|
2349 |
+ if (null_on_missing === void 0) { null_on_missing = false; } |
|
2350 |
+ var steps = ((path == "") ? [] : path.split(".")); |
|
2351 |
+ if (steps.length == 0) { |
|
2352 |
+ return object; |
|
2353 |
+ } |
|
2354 |
+ else { |
|
2355 |
+ var head = steps[0]; |
|
2356 |
+ // create |
|
2357 |
+ { |
|
2358 |
+ if (!(head in object)) { |
|
2359 |
+ if (create) { |
|
2360 |
+ var value = null; |
|
2361 |
+ if (steps.length >= 2) { |
|
2362 |
+ var next = steps[1]; |
|
2363 |
+ var index = parseInt(next); |
|
2364 |
+ if (!isNaN(index)) { |
|
2365 |
+ value = []; |
|
2366 |
+ } |
|
2367 |
+ else { |
|
2368 |
+ value = {}; |
|
2369 |
+ } |
|
2370 |
+ } |
|
2371 |
+ else { |
|
2372 |
+ value = {}; |
|
2373 |
+ } |
|
2374 |
+ object[head] = value; |
|
2375 |
+ } |
|
2376 |
+ else { |
|
2377 |
+ // console.info("[object_path_walk] object is ", object); |
|
2378 |
+ var message = "[object_path_walk] can not walk step \u00BB" + head + "\u00AB in path \u00BB" + path + "\u00AB on object"; |
|
2379 |
+ if (null_on_missing) { |
|
2380 |
+ console.warn(message); |
|
2369 | 2381 |
return null; |
2370 | 2382 |
} |
2371 |
- if (key == "changeActions") { |
|
2372 |
- return undefined; |
|
2383 |
+ else { |
|
2384 |
+ throw (new Error(message)); |
|
2373 | 2385 |
} |
2374 |
- if (key == "observer") { |
|
2375 |
- return undefined; |
|
2376 | 2386 |
} |
2377 |
- if (key == "isMapped") { |
|
2378 |
- return undefined; |
|
2387 |
+ } |
|
2388 |
+ } |
|
2389 |
+ // execute rest |
|
2390 |
+ { |
|
2391 |
+ var object_ = object[head]; |
|
2392 |
+ var path_ = steps.slice(1).join("."); |
|
2393 |
+ return object_path_walk(object_, path_, create, null_on_missing); |
|
2394 |
+ } |
|
2379 | 2395 |
} |
2380 | 2396 |
/* |
2381 |
- if (value === null) { |
|
2382 |
- return undefined; |
|
2397 |
+ return ( |
|
2398 |
+ string_split(path, ".").reduce( |
|
2399 |
+ function (position : any, step : string) : any { |
|
2400 |
+ if (! lib_call.is_def(position[step], true)) { |
|
2401 |
+ if (create) { |
|
2402 |
+ position[step] = {}; |
|
2403 |
+ } |
|
2404 |
+ else { |
|
2405 |
+ // console.info("[object_path_walk] object is ", object); |
|
2406 |
+ let message : string = sprintf("[object_path_walk] can not walk step »%s« in path »%s« on object", [step, path]); |
|
2407 |
+ if (null_on_missing) { |
|
2408 |
+ console.warn(message); |
|
2409 |
+ return null; |
|
2410 |
+ } |
|
2411 |
+ else { |
|
2412 |
+ throw (new Error(message)); |
|
2413 |
+ } |
|
2414 |
+ } |
|
2383 | 2415 |
} |
2416 |
+ return position[step]; |
|
2417 |
+ }, |
|
2418 |
+ object |
|
2419 |
+ ) |
|
2420 |
+ ); |
|
2384 | 2421 |
*/ |
2385 |
- return value; |
|
2386 |
- }, readable ? 1 : 0)); |
|
2387 |
-}; |
|
2388 |
-var __extends = (this && this.__extends) || (function () { |
|
2389 |
- var extendStatics = Object.setPrototypeOf || |
|
2390 |
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
2391 |
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
2392 |
- return function (d, b) { |
|
2393 |
- extendStatics(d, b); |
|
2394 |
- function __() { this.constructor = d; } |
|
2395 |
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
2396 | 2422 |
}; |
2397 |
-})(); |
|
2398 |
-var lib_meta; |
|
2399 |
-(function (lib_meta) { |
|
2400 |
- /** |
|
2401 |
- * @author frac |
|
2402 |
- */ |
|
2403 |
- function type_toString(type) { |
|
2404 |
- // return ("<" + type.id + ">"); |
|
2405 |
- return JSON.stringify(type); |
|
2406 |
- } |
|
2407 |
- lib_meta.type_toString = type_toString; |
|
2408 | 2423 |
/** |
2424 |
+ * @desc reads a branch/leaf from an object-tree |
|
2409 | 2425 |
* @author frac |
2410 | 2426 |
*/ |
2411 |
- var class_pool = {}; |
|
2427 |
+/*export*/ var object_path_read = function (object, path, null_on_missing) { |
|
2428 |
+ if (null_on_missing === void 0) { null_on_missing = false; } |
|
2429 |
+ return object_path_walk(object, path, false, null_on_missing); |
|
2430 |
+}; |
|
2412 | 2431 |
/** |
2432 |
+ * @desc writes a branch/leaf to an object-tree |
|
2413 | 2433 |
* @author frac |
2414 | 2434 |
*/ |
2415 |
- function class_set(name, class_) { |
|
2416 |
- class_pool[name] = class_; |
|
2435 |
+/*export*/ var object_path_write = function (object, path, value) { |
|
2436 |
+ // for "initializing" the object (important if the value to write is an entry in a yet not existing array) |
|
2437 |
+ /*let old : any = */ object_path_walk(object, path, true, true); |
|
2438 |
+ var steps = ((path == "") ? [] : path.split(".")); |
|
2439 |
+ var position = object_path_walk(object, steps.slice(0, steps.length - 1).join("."), true); |
|
2440 |
+ if (position == undefined) { |
|
2441 |
+ console.warn("can't set \u00BB" + steps[steps.length - 1] + "\u00AB in undefined"); |
|
2417 | 2442 |
} |
2418 |
- lib_meta.class_set = class_set; |
|
2419 |
- /** |
|
2420 |
- * @author frac |
|
2421 |
- */ |
|
2422 |
- function class_get(name) { |
|
2423 |
- if (name in class_pool) { |
|
2424 |
- return class_pool[name]; |
|
2443 |
+ else { |
|
2444 |
+ position[steps[steps.length - 1]] = value; |
|
2445 |
+ } |
|
2446 |
+}; |
|
2447 |
+/*export*/ var object_object_path_write_ex = function (obj, path, val) { |
|
2448 |
+ var ref = obj; |
|
2449 |
+ var paths = path.split("."); |
|
2450 |
+ var i; |
|
2451 |
+ for (i = 0; i < paths.length - 1; i++) { |
|
2452 |
+ if (ref[paths[i]] === void 0) { |
|
2453 |
+ if (/^(0|[1-9][0-9]*)$/.test(paths[i + 1])) { |
|
2454 |
+ ref[paths[i]] = []; |
|
2425 | 2455 |
} |
2426 | 2456 |
else { |
2427 |
- throw (new Error("no class registered for name '" + name + "'")); |
|
2457 |
+ ref[paths[i]] = {}; |
|
2428 | 2458 |
} |
2429 | 2459 |
} |
2430 |
- lib_meta.class_get = class_get; |
|
2460 |
+ ref = ref[paths[i]]; |
|
2461 |
+ } |
|
2462 |
+ ref[paths[i]] = val; |
|
2463 |
+}; |
|
2431 | 2464 |
/** |
2465 |
+ * @desc filters branches from an object |
|
2466 |
+ * @param {Object} object the object to read from |
|
2467 |
+ * @param {Array} paths a list of string-lists, that are the paths to be propagated |
|
2468 |
+ * @return {Object} the object with only the selected branches |
|
2432 | 2469 |
* @author frac |
2433 | 2470 |
*/ |
2434 |
- function transform_field(name, attributes) { |
|
2435 |
- var type = attributes["type"]; |
|
2436 |
- var path = name; |
|
2437 |
- var label = ((attributes["title"] != undefined) ? attributes["title"] : name); |
|
2438 |
- var display = ((attributes["display"] != undefined) ? attributes["display"] : true); |
|
2439 |
- return ({ |
|
2440 |
- "path": path, |
|
2441 |
- "type": type, |
|
2442 |
- "label": label, |
|
2443 |
- "display": display |
|
2444 |
- }); |
|
2445 |
- } |
|
2446 |
- lib_meta.transform_field = transform_field; |
|
2447 |
- /** |
|
2448 |
- * @author frac |
|
2449 |
- */ |
|
2450 |
- function transform_description(label, description, groups_raw) { |
|
2451 |
- if (groups_raw === void 0) { groups_raw = null; } |
|
2452 |
- var fieldmap; |
|
2453 |
- var fields = Object.keys(description).map(function (key) { return transform_field(key, description[key]); }); |
|
2454 |
- var groups = ((groups_raw == null) |
|
2455 |
- ? |
|
2456 |
- null |
|
2457 |
- : |
|
2458 |
- groups_raw.map(function (group_raw) { |
|
2459 |
- return { |
|
2460 |
- "label": group_raw["label"], |
|
2461 |
- "fields": group_raw["fields"].map(function (field_name) { |
|
2462 |
- var index = fields["findIndex"](function (field) { return (field.path == field_name); }); |
|
2463 |
- if (index < 0) { |
|
2464 |
- throw (new Error("field " + field_name + " not found in model-description")); |
|
2465 |
- } |
|
2466 |
- return index; |
|
2467 |
- }) |
|
2468 |
- }; |
|
2469 |
- })); |
|
2470 |
- return { |
|
2471 |
- "fields": fields, |
|
2472 |
- "description": null, |
|
2473 |
- "title": label, |
|
2474 |
- "groups": groups |
|
2475 |
- }; |
|
2471 |
+/*export*/ var object_path_filter = function (object, paths) { |
|
2472 |
+ var result = {}; |
|
2473 |
+ paths.forEach(function (path) { |
|
2474 |
+ var value = null; |
|
2475 |
+ try { |
|
2476 |
+ value = object_path_read(object, path); |
|
2476 | 2477 |
} |
2477 |
- lib_meta.transform_description = transform_description; |
|
2478 |
- /** |
|
2479 |
- * @author frac |
|
2480 |
- */ |
|
2481 |
- function transform_description_groups(label, description_model, description_groups) { |
|
2482 |
- return ({ |
|
2483 |
- "label": label, |
|
2484 |
- "groups": description_groups.map(function (group_raw) { |
|
2485 |
- return { |
|
2486 |
- "label": group_raw["label"], |
|
2487 |
- "fields": group_raw["fields"].map(function (path) { |
|
2488 |
- var field_raw = description_model[path]; |
|
2489 |
- return transform_field(path, field_raw); |
|
2490 |
- }) |
|
2491 |
- }; |
|
2492 |
- }) |
|
2493 |
- }); |
|
2478 |
+ catch (exception) { |
|
2479 |
+ console.warn(exception); |
|
2494 | 2480 |
} |
2495 |
- lib_meta.transform_description_groups = transform_description_groups; |
|
2496 |
-})(lib_meta || (lib_meta = {})); |
|
2497 |
-/// <reference path="../../base/build/logic-decl.d.ts"/> |
|
2498 |
-/// <reference path="../../object/build/logic-decl.d.ts"/> |
|
2499 |
-var lib_meta; |
|
2500 |
-(function (lib_meta) { |
|
2501 |
- /** |
|
2502 |
- * @author fenris |
|
2503 |
- */ |
|
2504 |
- lib_meta._logprefix = "[lib_meta] "; |
|
2505 |
- /** |
|
2506 |
- * @author fenris |
|
2507 |
- */ |
|
2508 |
- lib_meta._verbosity = 1; |
|
2509 |
-})(lib_meta || (lib_meta = {})); |
|
2510 |
-var lib_meta; |
|
2511 |
-(function (lib_meta) { |
|
2512 |
- /** |
|
2513 |
- * @author fenris |
|
2514 |
- */ |
|
2515 |
- var class_shape = (function () { |
|
2516 |
- /** |
|
2517 |
- * @desc [constructor] |
|
2518 |
- * @author fenris |
|
2519 |
- */ |
|
2520 |
- function class_shape(_a) { |
|
2521 |
- var _b = _a["primitive"], primitive = _b === void 0 ? false : _b, _c = _a["soft"], soft = _c === void 0 ? true : _c, _d = _a["defaultvalue"], defaultvalue = _d === void 0 ? null : _d; |
|
2522 |
- /* |
|
2523 |
- if ((! soft) && (defaultvalue == null)) { |
|
2524 |
- throw (new Error("'null' is not a valid defaultvalue for hard shapes")); |
|
2481 |
+ if (value != null) { |
|
2482 |
+ object_path_write(result, path, value); |
|
2525 | 2483 |
} |
2526 |
- */ |
|
2527 |
- this.primitive = primitive; |
|
2528 |
- this.soft = soft; |
|
2529 |
- this.defaultvalue = defaultvalue; |
|
2484 |
+ else { |
|
2485 |
+ console.warn("skipped path \"" + path + "\" while filtering"); |
|
2530 | 2486 |
} |
2531 |
- /** |
|
2532 |
- * @desc [accessor] [getter] |
|
2533 |
- * @author fenris |
|
2534 |
- */ |
|
2535 |
- class_shape.prototype.primitive_get = function () { |
|
2536 |
- return this.primitive; |
|
2537 |
- }; |
|
2538 |
- /** |
|
2539 |
- * @desc [accessor] [getter] |
|
2540 |
- * @author fenris |
|
2541 |
- */ |
|
2542 |
- class_shape.prototype.soft_get = function () { |
|
2543 |
- return this.soft; |
|
2544 |
- }; |
|
2545 |
- /** |
|
2546 |
- * @desc [accessor] [getter] |
|
2547 |
- * @author fenris |
|
2548 |
- */ |
|
2549 |
- class_shape.prototype.defaultvalue_get = function () { |
|
2550 |
- return this.defaultvalue; |
|
2487 |
+ }); |
|
2488 |
+ return result; |
|
2551 | 2489 |
}; |
2552 | 2490 |
/** |
2553 |
- * @desc [accessor] |
|
2554 |
- * @author fenris |
|
2491 |
+ * @desc dunno… returns a list of object-paths? |
|
2492 |
+ * @param {Object} object |
|
2493 |
+ * @param {string} p |
|
2494 |
+ * @todo can probably be merged with getLeafg |
|
2555 | 2495 |
*/ |
2556 |
- class_shape.prototype.inspect = function (value) { |
|
2557 |
- var messages = []; |
|
2558 |
- if ((!this.soft) && (value == null)) { |
|
2559 |
- messages.push("shape does not allow 'null' as value"); |
|
2496 |
+/*export*/ var object_path_list = function (object, path, visited) { |
|
2497 |
+ if (path === void 0) { path = null; } |
|
2498 |
+ if (visited === void 0) { visited = []; } |
|
2499 |
+ var result = []; |
|
2500 |
+ visited.push(object); |
|
2501 |
+ for (var key in object) { |
|
2502 |
+ var value = object[key]; |
|
2503 |
+ if (visited.indexOf(value) === -1) { |
|
2504 |
+ var key_ = (path == null) ? key : (path + "." + key); |
|
2505 |
+ if (typeof (value) === "object") { |
|
2506 |
+ result = result.concat(object_path_list(value, key_, visited)); |
|
2560 | 2507 |
} |
2561 |
- return messages; |
|
2562 |
- }; |
|
2563 |
- /** |
|
2564 |
- * @desc [accessor] |
|
2565 |
- * @author fenris |
|
2566 |
- */ |
|
2567 |
- class_shape.prototype.check = function (value) { |
|
2568 |
- var messages = this.inspect(value); |
|
2569 |
- if (lib_meta._verbosity >= 1) { |
|
2570 |
- messages.forEach(function (message) { return console.warn("" + lib_meta._logprefix + message); }); |
|
2508 |
+ else { |
|
2509 |
+ result.push({ "key": key_, "value": value }); |
|
2571 | 2510 |
} |
2572 |
- return (messages.length == 0); |
|
2573 |
- }; |
|
2574 |
- return class_shape; |
|
2575 |
- }()); |
|
2576 |
- lib_meta.class_shape = class_shape; |
|
2577 |
- /** |
|
2578 |
- * @author fenris |
|
2579 |
- */ |
|
2580 |
- var class_shape_buildin = (function (_super) { |
|
2581 |
- __extends(class_shape_buildin, _super); |
|
2582 |
- /** |
|
2583 |
- * @author fenris |
|
2584 |
- */ |
|
2585 |
- function class_shape_buildin(_a) { |
|
2586 |
- var typename = _a["typename"], _b = _a["primitive"], primitive = _b === void 0 ? undefined : _b, _c = _a["soft"], soft = _c === void 0 ? undefined : _c, _d = _a["defaultvalue"], defaultvalue = _d === void 0 ? undefined : _d; |
|
2587 |
- var _this = _super.call(this, { |
|
2588 |
- "primitive": primitive, |
|
2589 |
- "soft": soft, |
|
2590 |
- "defaultvalue": defaultvalue |
|
2591 |
- }) || this; |
|
2592 |
- _this.typename = typename; |
|
2593 |
- return _this; |
|
2594 | 2511 |
} |
2595 |
- /** |
|
2596 |
- * @override |
|
2597 |
- * @author fenris |
|
2598 |
- */ |
|
2599 |
- class_shape_buildin.prototype.inspect = function (value) { |
|
2600 |
- var messages = _super.prototype.inspect.call(this, value); |
|
2601 |
- if ((!this.soft) && (typeof (value) != this.typename)) { |
|
2602 |
- messages.push("typename is not '" + this.typename + "'"); |
|
2603 | 2512 |
} |
2604 |
- return messages; |
|
2513 |
+ return result; |
|
2605 | 2514 |
}; |
2606 | 2515 |
/** |
2607 |
- * @desc [implementation] |
|
2608 |
- * @author fenris |
|
2516 |
+ * theroreticaly loop prof walk through all elements and subelements of an object |
|
2517 |
+ * and call a callback for each entry |
|
2518 |
+ * @param {object} obj object to iterate through |
|
2519 |
+ * @param {function} callback |
|
2609 | 2520 |
*/ |
2610 |
- class_shape_buildin.prototype._show = function () { |
|
2611 |
- var str = ""; |
|
2612 |
- str = this.typename; |
|
2613 |
- if (!this.soft) { |
|
2614 |
- str = str + "_or_null"; |
|
2615 |
- } |
|
2616 |
- return str; |
|
2521 |
+/*export*/ var object_iterate = function (obj, callback, leafs_only, path, visited) { |
|
2522 |
+ if (leafs_only === void 0) { leafs_only = false; } |
|
2523 |
+ if (visited === void 0) { visited = []; } |
|
2524 |
+ var have_seen = function (ob) { |
|
2525 |
+ return visited.some(function (e) { return ((typeof (ob) === "object") && (ob !== null) && (e === ob)); }); |
|
2617 | 2526 |
}; |
2618 |
- return class_shape_buildin; |
|
2619 |
- }(class_shape)); |
|
2620 |
- lib_meta.class_shape_buildin = class_shape_buildin; |
|
2621 |
- /** |
|
2622 |
- * @author fenris |
|
2623 |
- */ |
|
2624 |
- var _pool = {}; |
|
2625 |
- /** |
|
2626 |
- * @author fenris |
|
2627 |
- */ |
|
2628 |
- function register(id, factory) { |
|
2629 |
- if (id in _pool) { |
|
2630 |
- var message = "shape '" + id + "' already registered"; |
|
2631 |
- throw (new Error(message)); |
|
2527 |
+ var next = []; |
|
2528 |
+ Object.keys(obj).forEach(function (key) { |
|
2529 |
+ var elem = obj[key]; |
|
2530 |
+ if (!have_seen(elem)) { |
|
2531 |
+ visited.push(elem); |
|
2532 |
+ var _path = ""; |
|
2533 |
+ if (typeof path === "undefined") { |
|
2534 |
+ _path = key; |
|
2632 | 2535 |
} |
2633 | 2536 |
else { |
2634 |
- _pool[id] = factory; |
|
2635 |
- } |
|
2537 |
+ _path += [path, key].join("."); |
|
2636 | 2538 |
} |
2637 |
- lib_meta.register = register; |
|
2638 |
- /** |
|
2639 |
- * @author fenris |
|
2640 |
- */ |
|
2641 |
- function construct(id, parameters) { |
|
2642 |
- if (parameters === void 0) { parameters = {}; } |
|
2643 |
- if (!(id in _pool)) { |
|
2644 |
- var message = "no shape found with id " + id; |
|
2645 |
- throw (new Error(message)); |
|
2539 |
+ if (!leafs_only) |
|
2540 |
+ callback(_path, elem, key); |
|
2541 |
+ if (typeof (elem) === "object") { |
|
2542 |
+ (function (elem_, callback_, _path_, visited_) { |
|
2543 |
+ next.push(function () { object_iterate(elem_, callback_, leafs_only, _path_, visited_); }); |
|
2544 |
+ })(elem, callback, _path, visited); |
|
2646 | 2545 |
} |
2647 | 2546 |
else { |
2648 |
- return _pool[id](parameters); |
|
2547 |
+ if (leafs_only) |
|
2548 |
+ callback(_path, elem, key); |
|
2649 | 2549 |
} |
2650 | 2550 |
} |
2651 |
- lib_meta.construct = construct; |
|
2652 |
- /** |
|
2653 |
- * @author fenris |
|
2654 |
- */ |
|
2655 |
- function from_raw(shape_raw) { |
|
2656 |
- return construct(shape_raw.id, shape_raw.parameters); |
|
2551 |
+ }); |
|
2552 |
+ var func; |
|
2553 |
+ while (func = next.shift()) { |
|
2554 |
+ func(); |
|
2657 | 2555 |
} |
2658 |
- lib_meta.from_raw = from_raw; |
|
2556 |
+}; |
|
2659 | 2557 |
/** |
2660 |
- * @author fenris |
|
2558 |
+ * @desc get the leaf-nodes of an object |
|
2559 |
+ * @param {object} object |
|
2560 |
+ * @return {Array<string>} a list containing all leaf-nodes |
|
2561 |
+ * @author frac |
|
2661 | 2562 |
*/ |
2662 |
- function define(id, shape_raw) { |
|
2663 |
- register(id, function (parameters) { return from_raw(shape_raw); }); |
|
2563 |
+/*export*/ var getLeafs = function (object) { |
|
2564 |
+ var skip = { |
|
2565 |
+ "className": true, |
|
2566 |
+ "timeStamp": true, |
|
2567 |
+ "parentId": true, |
|
2568 |
+ "transactionID": true, |
|
2569 |
+ "guid": true, |
|
2570 |
+ "_id": true, |
|
2571 |
+ "parents": true, |
|
2572 |
+ "children": true |
|
2573 |
+ }; |
|
2574 |
+ return (Object.keys(object).reduce(function (leafs, key) { |
|
2575 |
+ try { |
|
2576 |
+ var value = object[key]; |
|
2577 |
+ if (key in skip) { |
|
2578 |
+ console.warn("skipping field \"" + key + "\""); |
|
2579 |
+ return leafs; |
|
2664 | 2580 |
} |
2665 |
- lib_meta.define = define; |
|
2666 |
- /** |
|
2667 |
- * @author fenris |
|
2668 |
- */ |
|
2669 |
- function retrieve(id) { |
|
2670 |
- return construct(id, {}); |
|
2581 |
+ else { |
|
2582 |
+ if ((typeof (value) === "object") && (value != null)) { |
|
2583 |
+ return leafs.concat(getLeafs(value).map(function (leaf) { return (key + "." + leaf); })); |
|
2671 | 2584 |
} |
2672 |
- lib_meta.retrieve = retrieve; |
|
2673 |
-})(lib_meta || (lib_meta = {})); |
|
2674 |
-var lib_meta; |
|
2675 |
-(function (lib_meta) { |
|
2676 |
- /** |
|
2677 |
- * @author fenris |
|
2678 |
- */ |
|
2679 |
- var class_shape_boolean = (function (_super) { |
|
2680 |
- __extends(class_shape_boolean, _super); |
|
2681 |
- /** |
|
2682 |
- * @author fenris |
|
2683 |
- */ |
|
2684 |
- function class_shape_boolean(_a) { |
|
2685 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? false : _c; |
|
2686 |
- return _super.call(this, { |
|
2687 |
- "typename": "boolean", |
|
2688 |
- "primitive": true, |
|
2689 |
- "soft": soft, |
|
2690 |
- "defaultvalue": defaultvalue |
|
2691 |
- }) || this; |
|
2585 |
+ else { |
|
2586 |
+ return leafs.concat([key]); |
|
2692 | 2587 |
} |
2693 |
- /** |
|
2694 |
- * @override |
|
2695 |
- * @author fenris |
|
2696 |
- */ |
|
2697 |
- class_shape_boolean.prototype.to_raw = function () { |
|
2698 |
- return { |
|
2699 |
- "id": "boolean", |
|
2700 |
- "parameters": { |
|
2701 |
- "soft": this.soft |
|
2702 | 2588 |
} |
2703 |
- }; |
|
2704 |
- }; |
|
2705 |
- return class_shape_boolean; |
|
2706 |
- }(lib_meta.class_shape_buildin)); |
|
2707 |
- lib_meta.class_shape_boolean = class_shape_boolean; |
|
2708 |
- lib_meta.register("boolean", function (parameters) { |
|
2709 |
- return (new class_shape_boolean({ |
|
2710 |
- "soft": parameters["soft"] |
|
2711 |
- })); |
|
2712 |
- }); |
|
2713 |
- lib_meta.register("bool", function (parameters) { return lib_meta.construct("boolean", parameters); }); |
|
2714 |
-})(lib_meta || (lib_meta = {})); |
|
2715 |
-var lib_meta; |
|
2716 |
-(function (lib_meta) { |
|
2717 |
- /** |
|
2718 |
- * @author fenris |
|
2719 |
- */ |
|
2720 |
- var class_shape_integer = (function (_super) { |
|
2721 |
- __extends(class_shape_integer, _super); |
|
2722 |
- /** |
|
2723 |
- * @author fenris |
|
2724 |
- */ |
|
2725 |
- function class_shape_integer(_a) { |
|
2726 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? 0 : _c, _d = _a["min"], min = _d === void 0 ? null : _d, _e = _a["max"], max = _e === void 0 ? null : _e; |
|
2727 |
- var _this = _super.call(this, { |
|
2728 |
- "typename": "number", |
|
2729 |
- "primitive": true, |
|
2730 |
- "soft": soft, |
|
2731 |
- "defaultvalue": defaultvalue |
|
2732 |
- }) || this; |
|
2733 |
- _this.min = min; |
|
2734 |
- _this.max = max; |
|
2735 |
- return _this; |
|
2736 | 2589 |
} |
2737 |
- /** |
|
2738 |
- * @desc [accessor] [getter] |
|
2739 |
- * @author fenris |
|
2740 |
- */ |
|
2741 |
- class_shape_integer.prototype.min_get = function () { |
|
2742 |
- return this.min; |
|
2743 |
- }; |
|
2744 |
- /** |
|
2745 |
- * @desc [accessor] [getter] |
|
2746 |
- * @author fenris |
|
2747 |
- */ |
|
2748 |
- class_shape_integer.prototype.max_get = function () { |
|
2749 |
- return this.max; |
|
2590 |
+ catch (exception) { |
|
2591 |
+ console.warn(exception); |
|
2592 |
+ console.info("key: ", key); |
|
2593 |
+ return null; |
|
2594 |
+ } |
|
2595 |
+ }, new Array())); |
|
2750 | 2596 |
}; |
2751 | 2597 |
/** |
2752 |
- * @override |
|
2753 |
- * @author fenris |
|
2598 |
+ * |
|
2599 |
+ * @desc merges two arrays by probing |
|
2600 |
+ * @param {Array} core |
|
2601 |
+ * @param {Array} mantle |
|
2602 |
+ * @param {function} match |
|
2754 | 2603 |
*/ |
2755 |
- class_shape_integer.prototype.inspect = function (value) { |
|
2756 |
- var messages = _super.prototype.inspect.call(this, value); |
|
2757 |
- if (value != null) { |
|
2758 |
- if ((this.min != null) && (value < this.min)) { |
|
2759 |
- messages.push("value is below minimum of " + this.min.toString()); |
|
2760 |
- } |
|
2761 |
- if ((this.max != null) && (value > this.max)) { |
|
2762 |
- messages.push("value is over maximum of " + this.max.toString()); |
|
2604 |
+/*export*/ var merge_array = function (core, mantle, match) { |
|
2605 |
+ if (match === void 0) { match = (function (x, y) { return (x === y); }); } |
|
2606 |
+ if ((core == undefined) || (mantle == undefined)) { |
|
2607 |
+ throw (new Error("Error: " |
|
2608 |
+ + ((core == undefined) ? " core must be an array and not '" + typeof (core) + "'" : "") |
|
2609 |
+ + ((mantle == undefined) ? " mantle must be an array and not '" + typeof (mantle) + "'" : ""))); |
|
2763 | 2610 |
} |
2611 |
+ var ret = core; |
|
2612 |
+ for (var i = 0; i < mantle.length; i++) { |
|
2613 |
+ var entry = mantle[i]; |
|
2614 |
+ try { |
|
2615 |
+ var matching_index = core.find(function (element) { return match(element, entry); }); |
|
2616 |
+ ret[matching_index] = object_merge_objects(core[matching_index], entry); |
|
2764 | 2617 |
} |
2765 |
- return messages; |
|
2766 |
- }; |
|
2767 |
- /** |
|
2768 |
- * @override |
|
2769 |
- * @author fenris |
|
2770 |
- */ |
|
2771 |
- class_shape_integer.prototype.to_raw = function () { |
|
2772 |
- return { |
|
2773 |
- "id": "integer", |
|
2774 |
- "parameters": { |
|
2775 |
- "soft": this.soft, |
|
2776 |
- "min": this.min, |
|
2777 |
- "max": this.max |
|
2618 |
+ catch (e) { |
|
2619 |
+ ret.push(entry); |
|
2778 | 2620 |
} |
2779 |
- }; |
|
2780 |
- }; |
|
2781 |
- return class_shape_integer; |
|
2782 |
- }(lib_meta.class_shape_buildin)); |
|
2783 |
- lib_meta.class_shape_integer = class_shape_integer; |
|
2784 |
- lib_meta.register("integer", function (parameters) { |
|
2785 |
- return (new class_shape_integer({ |
|
2786 |
- "min": parameters["min"], |
|
2787 |
- "max": parameters["max"], |
|
2788 |
- "soft": parameters["soft"] |
|
2789 |
- })); |
|
2790 |
- }); |
|
2791 |
- lib_meta.register("int", function (parameters) { return lib_meta.construct("integer", parameters); }); |
|
2792 |
-})(lib_meta || (lib_meta = {})); |
|
2793 |
-var lib_meta; |
|
2794 |
-(function (lib_meta) { |
|
2795 |
- /** |
|
2796 |
- * @author fenris |
|
2797 |
- */ |
|
2798 |
- var class_shape_float = (function (_super) { |
|
2799 |
- __extends(class_shape_float, _super); |
|
2800 |
- /** |
|
2801 |
- * @author fenris |
|
2802 |
- */ |
|
2803 |
- function class_shape_float(_a) { |
|
2804 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? 0.0 : _c, _d = _a["min"], min = _d === void 0 ? null : _d, _e = _a["max"], max = _e === void 0 ? null : _e; |
|
2805 |
- var _this = _super.call(this, { |
|
2806 |
- "typename": "number", |
|
2807 |
- "primitive": true, |
|
2808 |
- "soft": soft, |
|
2809 |
- "defaultvalue": defaultvalue |
|
2810 |
- }) || this; |
|
2811 |
- _this.min = min; |
|
2812 |
- _this.max = max; |
|
2813 |
- return _this; |
|
2814 | 2621 |
} |
2815 |
- /** |
|
2816 |
- * @desc [accessor] [getter] |
|
2817 |
- * @author fenris |
|
2818 |
- */ |
|
2819 |
- class_shape_float.prototype.min_get = function () { |
|
2820 |
- return this.min; |
|
2821 |
- }; |
|
2822 |
- /** |
|
2823 |
- * @desc [accessor] [getter] |
|
2824 |
- * @author fenris |
|
2825 |
- */ |
|
2826 |
- class_shape_float.prototype.max_get = function () { |
|
2827 |
- return this.max; |
|
2622 |
+ return ret; |
|
2828 | 2623 |
}; |
2829 | 2624 |
/** |
2830 |
- * @override |
|
2831 |
- * @author fenris |
|
2625 |
+ * @desc merges two objects recursivly |
|
2626 |
+ * @param {Object} object1 core |
|
2627 |
+ * @param {Object} object2 mantle |
|
2628 |
+ * @param {Array} [ignore_keys] |
|
2629 |
+ * @param [do_not_overwrite_existing_values] |
|
2630 |
+ * @returns {Object} a clone of object1 will be returned |
|
2832 | 2631 |
*/ |
2833 |
- class_shape_float.prototype.inspect = function (value) { |
|
2834 |
- var messages = _super.prototype.inspect.call(this, value); |
|
2835 |
- if (value != null) { |
|
2836 |
- if ((this.min != null) && (value < this.min)) { |
|
2837 |
- messages.push("value is below minimum of " + this.min.toString()); |
|
2632 |
+/*export*/ var object_merge_objects = function (object1, object2, ignore_keys, do_not_overwrite_existing_values, ignore_null, path) { |
|
2633 |
+ if (object1 === void 0) { object1 = null; } |
|
2634 |
+ if (object2 === void 0) { object2 = null; } |
|
2635 |
+ if (ignore_keys === void 0) { ignore_keys = ["parents"]; } |
|
2636 |
+ if (do_not_overwrite_existing_values === void 0) { do_not_overwrite_existing_values = false; } |
|
2637 |
+ if (ignore_null === void 0) { ignore_null = false; } |
|
2638 |
+ if (path === void 0) { path = []; } |
|
2639 |
+ if (object1 == null) { |
|
2640 |
+ if (object2 instanceof Array) { |
|
2641 |
+ object1 = []; |
|
2838 | 2642 |
} |
2839 |
- if ((this.max != null) && (value > this.max)) { |
|
2840 |
- messages.push("value is over maximum of " + this.max.toString()); |
|
2643 |
+ else { |
|
2644 |
+ object1 = {}; |
|
2841 | 2645 |
} |
2842 | 2646 |
} |
2843 |
- return messages; |
|
2844 |
- }; |
|
2845 |
- /** |
|
2846 |
- * @override |
|
2847 |
- * @author fenris |
|
2848 |
- */ |
|
2849 |
- class_shape_float.prototype.to_raw = function () { |
|
2850 |
- return { |
|
2851 |
- "id": "float", |
|
2852 |
- "parameters": { |
|
2853 |
- "soft": this.soft, |
|
2854 |
- "min": this.min, |
|
2855 |
- "max": this.max |
|
2647 |
+ var iteration_keys = Object.keys(object2); |
|
2648 |
+ if (ignore_keys === []) { |
|
2649 |
+ if (path.indexOf(object2) >= 0) |
|
2650 |
+ return undefined; |
|
2651 |
+ path.push(object2); |
|
2856 | 2652 |
} |
2857 |
- }; |
|
2858 |
- }; |
|
2859 |
- return class_shape_float; |
|
2860 |
- }(lib_meta.class_shape_buildin)); |
|
2861 |
- lib_meta.class_shape_float = class_shape_float; |
|
2862 |
- lib_meta.register("float", function (parameters) { |
|
2863 |
- return (new class_shape_float({ |
|
2864 |
- "min": parameters["min"], |
|
2865 |
- "max": parameters["max"], |
|
2866 |
- "soft": parameters["soft"] |
|
2867 |
- })); |
|
2868 |
- }); |
|
2869 |
-})(lib_meta || (lib_meta = {})); |
|
2870 |
-var lib_meta; |
|
2871 |
-(function (lib_meta) { |
|
2872 |
- /** |
|
2873 |
- * @author fenris |
|
2874 |
- */ |
|
2875 |
- var class_shape_string = (function (_super) { |
|
2876 |
- __extends(class_shape_string, _super); |
|
2877 |
- /** |
|
2878 |
- * @author fenris |
|
2879 |
- */ |
|
2880 |
- function class_shape_string(_a) { |
|
2881 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? "" : _c; |
|
2882 |
- return _super.call(this, { |
|
2883 |
- "typename": "string", |
|
2884 |
- "primitive": true, |
|
2885 |
- "soft": soft, |
|
2886 |
- "defaultvalue": defaultvalue |
|
2887 |
- }) || this; |
|
2653 |
+ // |
|
2654 |
+ for (var i = 0; i < iteration_keys.length; i += 1) { |
|
2655 |
+ var key = iteration_keys[i]; |
|
2656 |
+ if (ignore_keys.some(function (k) { |
|
2657 |
+ return key == k; |
|
2658 |
+ })) { |
|
2659 |
+ // |
|
2888 | 2660 |
} |
2889 |
- /** |
|
2890 |
- * @override |
|
2891 |
- * @author fenris |
|
2892 |
- */ |
|
2893 |
- class_shape_string.prototype.to_raw = function () { |
|
2894 |
- return { |
|
2895 |
- "id": "string", |
|
2896 |
- "parameters": { |
|
2897 |
- "soft": this.soft |
|
2661 |
+ else if (object2[key] === null) { |
|
2662 |
+ if (!ignore_null) |
|
2663 |
+ object1[key] = null; |
|
2898 | 2664 |
} |
2899 |
- }; |
|
2900 |
- }; |
|
2901 |
- return class_shape_string; |
|
2902 |
- }(lib_meta.class_shape_buildin)); |
|
2903 |
- lib_meta.class_shape_string = class_shape_string; |
|
2904 |
- lib_meta.register("string", function (parameters) { |
|
2905 |
- return (new class_shape_string({ |
|
2906 |
- "soft": parameters["soft"] |
|
2907 |
- })); |
|
2908 |
- }); |
|
2909 |
- lib_meta.register("str", function (parameters) { return lib_meta.construct("string", parameters); }); |
|
2910 |
-})(lib_meta || (lib_meta = {})); |
|
2911 |
-var lib_meta; |
|
2912 |
-(function (lib_meta) { |
|
2913 |
- /** |
|
2914 |
- * @author fenris |
|
2915 |
- */ |
|
2916 |
- var class_shape_email = (function (_super) { |
|
2917 |
- __extends(class_shape_email, _super); |
|
2918 |
- /** |
|
2919 |
- * @author fenris |
|
2920 |
- */ |
|
2921 |
- function class_shape_email(_a) { |
|
2922 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? "" : _c; |
|
2923 |
- return _super.call(this, { |
|
2924 |
- "primitive": true, |
|
2925 |
- "soft": soft, |
|
2926 |
- "defaultvalue": defaultvalue |
|
2927 |
- }) || this; |
|
2665 |
+ else if ((typeof (object2[key]) === "object") && ((typeof (object1[key]) === "object") || (typeof (object1[key]) === "undefined"))) { |
|
2666 |
+ object1[key] = object_merge_objects(object1[key], object2[key], ignore_keys, do_not_overwrite_existing_values, ignore_null, path); |
|
2928 | 2667 |
} |
2929 |
- /** |
|
2930 |
- * @override |
|
2931 |
- * @author fenris |
|
2932 |
- */ |
|
2933 |
- class_shape_email.prototype.to_raw = function () { |
|
2934 |
- return { |
|
2935 |
- "id": "email", |
|
2936 |
- "parameters": { |
|
2937 |
- "soft": this.soft |
|
2668 |
+ else { |
|
2669 |
+ if ((do_not_overwrite_existing_values === false) || (typeof (object1[key]) === "undefined")) { |
|
2670 |
+ object1[key] = object2[key]; |
|
2938 | 2671 |
} |
2672 |
+ } |
|
2673 |
+ } |
|
2674 |
+ return object1; |
|
2939 | 2675 |
}; |
2676 |
+/* |
|
2677 |
+ * @param {object} recipie ex: { "name" : { extract : function(o) { return o["name"]; }}} |
|
2678 |
+ * */ |
|
2679 |
+var flatten_object = function (obj, recipie, drop_key) { |
|
2680 |
+ if (drop_key === void 0) { drop_key = (function (k) { return ["parents", "parent", "children"].indexOf(k) > -1; }); } |
|
2681 |
+ var ret = {}; |
|
2682 |
+ for (var key in recipie) { |
|
2683 |
+ if (!drop_key(key)) { |
|
2684 |
+ var prefix = (recipie[key].prefix || ""); |
|
2685 |
+ var recursive = (recipie[key].recursive || -1); |
|
2686 |
+ var extract = (recipie[key].extract || (function (x) { return x; })); |
|
2687 |
+ var _obj = extract(obj[key]); |
|
2688 |
+ if ((_obj !== null) && ((typeof _obj == "object") || (obj[key] instanceof Array)) && (!(recursive == 0))) { |
|
2689 |
+ var tmp = {}; |
|
2690 |
+ var _recipie = {}; |
|
2691 |
+ for (var _i = 0, _a = Object.keys(_obj); _i < _a.length; _i++) { |
|
2692 |
+ var k = _a[_i]; |
|
2693 |
+ _recipie[k] = { |
|
2694 |
+ "prefix": (prefix + key + "."), |
|
2695 |
+ "recursive": (recursive - 1), |
|
2696 |
+ "extract": (function (x) { return x; }) |
|
2940 | 2697 |
}; |
2941 |
- /** |
|
2942 |
- * @desc [implementation] |
|
2943 |
- * @author fenris |
|
2944 |
- */ |
|
2945 |
- class_shape_email.prototype._show = function () { |
|
2946 |
- var str = "email"; |
|
2947 |
- return str; |
|
2948 |
- }; |
|
2949 |
- return class_shape_email; |
|
2950 |
- }(lib_meta.class_shape)); |
|
2951 |
- lib_meta.class_shape_email = class_shape_email; |
|
2952 |
- lib_meta.register("email", function (parameters) { |
|
2953 |
- return (new class_shape_email({ |
|
2954 |
- "soft": parameters["soft"] |
|
2955 |
- })); |
|
2956 |
- }); |
|
2957 |
-})(lib_meta || (lib_meta = {})); |
|
2958 |
-var lib_meta; |
|
2959 |
-(function (lib_meta) { |
|
2960 |
- /** |
|
2961 |
- * @author fenris |
|
2962 |
- */ |
|
2963 |
- var class_shape_array = (function (_super) { |
|
2964 |
- __extends(class_shape_array, _super); |
|
2965 |
- /** |
|
2966 |
- * @author fenris |
|
2967 |
- */ |
|
2968 |
- function class_shape_array(_a) { |
|
2969 |
- var shape_element = _a["shape_element"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? [] : _c; |
|
2970 |
- var _this = _super.call(this, { |
|
2971 |
- "primitive": false, |
|
2972 |
- "soft": soft, |
|
2973 |
- "defaultvalue": defaultvalue |
|
2974 |
- }) || this; |
|
2975 |
- _this.shape_element = shape_element; |
|
2976 |
- return _this; |
|
2977 | 2698 |
} |
2978 |
- /** |
|
2979 |
- * @desc [accessor] [getter] |
|
2980 |
- * @author fenris |
|
2981 |
- */ |
|
2982 |
- class_shape_array.prototype.shape_element_get = function () { |
|
2983 |
- return this.shape_element; |
|
2984 |
- }; |
|
2985 |
- /** |
|
2986 |
- * @override |
|
2987 |
- * @author fenris |
|
2988 |
- */ |
|
2989 |
- class_shape_array.prototype.inspect = function (value) { |
|
2990 |
- var _this = this; |
|
2991 |
- var messages = _super.prototype.inspect.call(this, value); |
|
2992 |
- if (value != null) { |
|
2993 |
- if (!((typeof (value) == "object") && (value instanceof Array))) { |
|
2994 |
- messages.push("value is not an array"); |
|
2699 |
+ tmp = flatten_object(_obj, _recipie, drop_key); |
|
2700 |
+ ret = object_merge_objects(ret, tmp); |
|
2995 | 2701 |
} |
2996 | 2702 |
else { |
2997 |
- var array = (value); |
|
2998 |
- array.forEach(function (element, index) { |
|
2999 |
- messages = messages.concat(_this.shape_element.inspect(element).map(function (message) { return "array element #" + index.toString() + ": " + message; })); |
|
3000 |
- }); |
|
2703 |
+ ret[prefix + key] = _obj; |
|
3001 | 2704 |
} |
3002 | 2705 |
} |
3003 |
- return messages; |
|
2706 |
+ } |
|
2707 |
+ return ret; |
|
3004 | 2708 |
}; |
3005 | 2709 |
/** |
3006 |
- * @override |
|
3007 |
- * @author fenris |
|
2710 |
+ * use the complete path of an objects entry as key to make an one dimensional object |
|
2711 |
+ * @param {object} object the object which should be moade flat |
|
2712 |
+ * @param {string} [path] for the recursive call the current path |
|
3008 | 2713 |
*/ |
3009 |
- class_shape_array.prototype.to_raw = function () { |
|
3010 |
- return { |
|
3011 |
- "id": "array", |
|
3012 |
- "parameters": { |
|
3013 |
- "shape_element": this.shape_element.to_raw(), |
|
3014 |
- "soft": this.soft |
|
2714 |
+/*export*/ var object_make_flat = function (object, path, filter, split_char, objects) { |
|
2715 |
+ if (path === void 0) { path = null; } |
|
2716 |
+ if (filter === void 0) { filter = ["parent", "children"]; } |
|
2717 |
+ if (split_char === void 0) { split_char = "."; } |
|
2718 |
+ if (objects === void 0) { objects = []; } |
|
2719 |
+ if (object.toFlat != undefined) { |
|
2720 |
+ return object.toFlat(); |
|
2721 |
+ } |
|
2722 |
+ else { |
|
2723 |
+ var ret = {}; |
|
2724 |
+ var default_visited_key = "___visited_path___"; |
|
2725 |
+ var visited_key; |
|
2726 |
+ if (object != void 0) { |
|
2727 |
+ var iterate = function (key) { |
|
2728 |
+ var newkey = key; |
|
2729 |
+ if ((path != undefined) && (path !== "")) { |
|
2730 |
+ newkey = path + split_char + newkey; |
|
2731 |
+ } |
|
2732 |
+ // do not touch objects we alrdy know |
|
2733 |
+ if ((obj_ref[key] != undefined) && (!objects.some(function (e) { return (e === obj_ref); }))) { |
|
2734 |
+ //if (lib_call.is_def(obj_ref[key]) && (! obj_ref[key].hasOwnProperty(visited_key)) && (key !== visited_key)) { |
|
2735 |
+ if (typeof obj_ref[key] === "object") { |
|
2736 |
+ ret = object_merge_objects(ret, object_make_flat(obj_ref[key], newkey, filter, split_char, objects.concat(object))); |
|
2737 |
+ } |
|
2738 |
+ else if (typeof obj_ref[key] === "function") { |
|
2739 |
+ // o.O a function ... doing nothing might be the best choice |
|
2740 |
+ } |
|
2741 |
+ else { |
|
2742 |
+ var value = obj_ref[key]; |
|
2743 |
+ ret[newkey] = value; |
|
2744 |
+ } |
|
3015 | 2745 |
} |
3016 | 2746 |
}; |
2747 |
+ visited_key = default_visited_key; |
|
2748 |
+ //object[visited_key] = true; |
|
2749 |
+ var obj_ref = object; |
|
2750 |
+ Object.keys(object).filter(function (key) { return (filter.indexOf(key) < 0); }).forEach(iterate); |
|
2751 |
+ if (typeof object.getComputedValues == "function") { |
|
2752 |
+ visited_key = default_visited_key + "_" + Math.random().toString(); |
|
2753 |
+ obj_ref = object.getComputedValues(); |
|
2754 |
+ obj_ref[visited_key] = true; |
|
2755 |
+ Object.keys(obj_ref).filter(function (key) { return (filter.indexOf(key) < 0); }).forEach(iterate); |
|
2756 |
+ } |
|
2757 |
+ } |
|
2758 |
+ else { |
|
2759 |
+ //console.warn("something went wrong with that object: ", object, "on this path:", path); |
|
2760 |
+ } |
|
2761 |
+ return ret; |
|
2762 |
+ } |
|
3017 | 2763 |
}; |
3018 | 2764 |
/** |
3019 |
- * @desc [implementation] |
|
3020 |
- * @author fenris |
|
2765 |
+ * splits a flat oject into an array of objects if there are paths containing numbers, which indicates |
|
2766 |
+ * that there might be an array |
|
2767 |
+ * used for normalisation of imports |
|
2768 |
+ * @param entry |
|
2769 |
+ * @param number_replace_string |
|
2770 |
+ * @param {function} [match_function] how to test key if it causes a split |
|
2771 |
+ * @returns {Array} |
|
3021 | 2772 |
*/ |
3022 |
- class_shape_array.prototype._show = function () { |
|
3023 |
- var str = "array"; |
|
3024 |
- str += "<" + instance_show(this.shape_element) + ">"; |
|
3025 |
- return str; |
|
2773 |
+var object_split_flat_object = function (entry, number_replace_string, fab_function, match_function) { |
|
2774 |
+ if (typeof (match_function) === "undefined") { |
|
2775 |
+ match_function = function (key) { |
|
2776 |
+ return (!key.match(/^custom/)) && key.match(/\.[0-9]+\./); |
|
3026 | 2777 |
}; |
3027 |
- return class_shape_array; |
|
3028 |
- }(lib_meta.class_shape)); |
|
3029 |
- lib_meta.class_shape_array = class_shape_array; |
|
3030 |
- lib_meta.register("array", function (parameters) { |
|
3031 |
- var shape_element_raw = lib_object.fetch(parameters, "shape_element", null, 2); |
|
3032 |
- var shape_element = lib_meta.from_raw(shape_element_raw); |
|
3033 |
- return (new class_shape_array({ |
|
3034 |
- "shape_element": shape_element, |
|
3035 |
- "soft": parameters["soft"] |
|
3036 |
- })); |
|
2778 |
+ } |
|
2779 |
+ if (typeof (fab_function) === "undefined") { |
|
2780 |
+ fab_function = function (obj, e) { |
|
2781 |
+ return obj; |
|
2782 |
+ }; |
|
2783 |
+ } |
|
2784 |
+ if (typeof (number_replace_string) === "undefined") { |
|
2785 |
+ number_replace_string = "%d"; |
|
2786 |
+ } |
|
2787 |
+ var ret = {}; |
|
2788 |
+ var _ret = []; |
|
2789 |
+ var keys = Object.keys(entry); |
|
2790 |
+ var group_keys = keys.filter(match_function); |
|
2791 |
+ keys.forEach(function (key) { |
|
2792 |
+ var index = 0; |
|
2793 |
+ var nkey = key; |
|
2794 |
+ if (match_function(key)) { |
|
2795 |
+ index = Number(key.match(/[0-9]+/)[0]).valueOf(); |
|
2796 |
+ nkey = key.replace(/\.[0-9]+\./, "." + number_replace_string + "."); |
|
2797 |
+ } |
|
2798 |
+ if (!ret[index]) { |
|
2799 |
+ ret[index] = {}; |
|
2800 |
+ } |
|
2801 |
+ ret[index][nkey] = entry[key]; |
|
3037 | 2802 |
}); |
3038 |
- lib_meta.register("arr", function (parameters) { return lib_meta.construct("array", parameters); }); |
|
3039 |
-})(lib_meta || (lib_meta = {})); |
|
3040 |
-var lib_meta; |
|
3041 |
-(function (lib_meta) { |
|
3042 |
- /** |
|
3043 |
- * @author fenris |
|
3044 |
- */ |
|
3045 |
- var class_shape_object = (function (_super) { |
|
3046 |
- __extends(class_shape_object, _super); |
|
3047 |
- /** |
|
3048 |
- * @author fenris |
|
3049 |
- */ |
|
3050 |
- function class_shape_object(_a) { |
|
3051 |
- var fields = _a["fields"], _b = _a["soft"], soft = _b === void 0 ? true : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? null : _c; |
|
3052 |
- var _this = this; |
|
3053 |
- if (defaultvalue == null) { |
|
3054 |
- defaultvalue = {}; |
|
3055 |
- fields.forEach(function (field) { |
|
3056 |
- defaultvalue[field.name] = field.shape.defaultvalue_get(); |
|
2803 |
+ keys = Object.keys(ret).sort(); |
|
2804 |
+ _ret.push(ret[0]); |
|
2805 |
+ for (var index = 1; index < keys.length; index++) { |
|
2806 |
+ _ret.push(fab_function(ret[keys[index]], entry)); |
|
2807 |
+ } |
|
2808 |
+ _ret[0] = object_merge_objects(_ret[0], ret[0]); |
|
2809 |
+ return _ret; |
|
2810 |
+}; |
|
2811 |
+// TODO: move to exporter, it's to specific |
|
2812 |
+// to normalize the objects convert paths of a tree-like structure to a |
|
2813 |
+// key-value list with complete paths as key |
|
2814 |
+// the info object is passed to the next function as it is |
|
2815 |
+// and a flat_object (key : value) |
|
2816 |
+/*export*/ var object_make_flat_async = function (data, callback, on_progress) { |
|
2817 |
+ setTimeout((function (_obj, _cb, _info) { |
|
2818 |
+ return (function () { |
|
2819 |
+ var ret = _obj.map(function (o) { return object_make_flat(o); }); |
|
2820 |
+ _cb({ "flat_object": ret, "objects": ret, "info": _info }); |
|
3057 | 2821 |
}); |
2822 |
+ })((typeof (data.processed.objects) === "undefined") ? data.processed.source_object : data.processed.objects, callback, data.processed.info), 0); |
|
2823 |
+}; |
|
2824 |
+var object_flatten = function (object, paths, prefix) { |
|
2825 |
+ if (prefix === void 0) { prefix = ""; } |
|
2826 |
+ var ret = {}; |
|
2827 |
+ var paths_ = paths.reduce(function (prev, current) { |
|
2828 |
+ if (current.split(".").some(function (x) { return (x === "%d"); })) { |
|
2829 |
+ var path = current.split(".%d").shift(); |
|
2830 |
+ var len = object_path_read(object, path).length; |
|
2831 |
+ for (var i = 0; i < len; i++) { |
|
2832 |
+ // prev.push(sprintf(current, [i])); |
|
2833 |
+ prev.push(current.replace(new RegExp("%d"), i.toFixed(0))); |
|
3058 | 2834 |
} |
3059 |
- _this = _super.call(this, { |
|
3060 |
- "typename": "object", |
|
3061 |
- "primitive": false, |
|
3062 |
- "soft": soft, |
|
3063 |
- "defaultvalue": defaultvalue |
|
3064 |
- }) || this; |
|
3065 |
- _this.fields = fields; |
|
3066 |
- return _this; |
|
3067 | 2835 |
} |
3068 |
- /** |
|
3069 |
- * @desc [accessor] [getter] |
|
3070 |
- * @author fenris |
|
3071 |
- */ |
|
3072 |
- class_shape_object.prototype.fields_get = function () { |
|
3073 |
- return this.fields; |
|
2836 |
+ else { |
|
2837 |
+ prev.push(current); |
|
2838 |
+ } |
|
2839 |
+ return prev; |
|
2840 |
+ }, []); |
|
2841 |
+ for (var _i = 0, paths_1 = paths_; _i < paths_1.length; _i++) { |
|
2842 |
+ var path = paths_1[_i]; |
|
2843 |
+ var tmp = object_path_read(object, path, true); |
|
2844 |
+ if ((tmp != undefined) && (tmp.toFlat != undefined)) { |
|
2845 |
+ var tmp_ = tmp.toFlat([path, "."].join("")); |
|
2846 |
+ for (var key in tmp_) { |
|
2847 |
+ ret[key] = tmp_[key]; |
|
2848 |
+ } |
|
2849 |
+ } |
|
2850 |
+ else { |
|
2851 |
+ ret[prefix + path] = tmp; |
|
2852 |
+ } |
|
2853 |
+ } |
|
2854 |
+ return ret; |
|
3074 | 2855 |
}; |
3075 | 2856 |
/** |
3076 |
- * @override |
|
3077 |
- * @author fenris |
|
3078 |
- * @todo check for superfluous fields? |
|
2857 |
+ * parse |
|
2858 |
+ * @param {String} value |
|
2859 |
+ * @returns {Object} |
|
3079 | 2860 |
*/ |
3080 |
- class_shape_object.prototype.inspect = function (value) { |
|
3081 |
- var messages = _super.prototype.inspect.call(this, value); |
|
3082 |
- if (value != null) { |
|
3083 |
- this.fields.forEach(function (field, index) { |
|
3084 |
- var value_ = value[field.name]; |
|
3085 |
- messages = messages.concat(field.shape.inspect(value_).map(function (message) { return "object field '" + field.name + "': " + message; })); |
|
3086 |
- }); |
|
3087 |
- } |
|
3088 |
- return messages; |
|
2861 |
+var object_parse = function (value) { |
|
2862 |
+ var content = JSON.parse(value); |
|
2863 |
+ var m = { "root": content }; |
|
2864 |
+ (new Mapper()).mapClasses(m); |
|
2865 |
+ return m["root"]; |
|
3089 | 2866 |
}; |
3090 | 2867 |
/** |
3091 |
- * @override |
|
3092 |
- * @author fenris |
|
2868 |
+ * stringify |
|
2869 |
+ * |
|
2870 |
+ * @description stringify object as JSON |
|
3093 | 2871 |
*/ |
3094 |
- class_shape_object.prototype.to_raw = function () { |
|
3095 |
- return { |
|
3096 |
- "id": "object", |
|
3097 |
- "parameters": { |
|
3098 |
- "soft": this.soft, |
|
3099 |
- "fields": this.fields.map(function (field) { |
|
3100 |
- return { |
|
3101 |
- "name": field.name, |
|
3102 |
- "shape": field.shape.to_raw(), |
|
3103 |
- "label": field.label |
|
3104 |
- }; |
|
3105 |
- }) |
|
2872 |
+var object_stringify = function (object, readable) { |
|
2873 |
+ if (readable === void 0) { readable = false; } |
|
2874 |
+ return (JSON.stringify(object, function (key, value) { |
|
2875 |
+ if ((key == "parents") && (value !== null)) { |
|
2876 |
+ return null; |
|
2877 |
+ } |
|
2878 |
+ if (key == "changeActions") { |
|
2879 |
+ return undefined; |
|
2880 |
+ } |
|
2881 |
+ if (key == "observer") { |
|
2882 |
+ return undefined; |
|
2883 |
+ } |
|
2884 |
+ if (key == "isMapped") { |
|
2885 |
+ return undefined; |
|
2886 |
+ } |
|
2887 |
+ /* |
|
2888 |
+ if (value === null) { |
|
2889 |
+ return undefined; |
|
3106 | 2890 |
} |
3107 |
- }; |
|
3108 |
- }; |
|
3109 |
- /** |
|
3110 |
- * @desc [implementation] |
|
3111 |
- * @author fenris |
|
3112 | 2891 |
*/ |
3113 |
- class_shape_object.prototype._show = function () { |
|
3114 |
- var str = _super.prototype._show.call(this); |
|
3115 |
- var str_ = this.fields.map(function (field) { return field.name + ":" + instance_show(field.shape); }).join(","); |
|
3116 |
- str = str + "<" + str_ + ">"; |
|
3117 |
- return str; |
|
2892 |
+ return value; |
|
2893 |
+ }, readable ? 1 : 0)); |
|
3118 | 2894 |
}; |
3119 |
- return class_shape_object; |
|
3120 |
- }(lib_meta.class_shape_buildin)); |
|
3121 |
- lib_meta.class_shape_object = class_shape_object; |
|
3122 |
- lib_meta.register("object", function (parameters) { |
|
3123 |
- var fields_ = lib_object.fetch(parameters, "fields", [], 1); |
|
3124 |
- return (new class_shape_object({ |
|
3125 |
- "fields": fields_.map(function (field_) { |
|
3126 |
- var name = lib_object.fetch(field_, "name", null, 2); |
|
3127 |
- var shape_raw = lib_object.fetch(field_, "shape", null, 2); |
|
3128 |
- var shape = lib_meta.construct(shape_raw.id, shape_raw.parameters); |
|
3129 |
- var label = lib_object.fetch(field_, "label", null, 1); |
|
3130 |
- return { |
|
3131 |
- "name": name, |
|
3132 |
- "shape": shape, |
|
3133 |
- "label": label |
|
2895 |
+var __extends = (this && this.__extends) || (function () { |
|
2896 |
+ var extendStatics = Object.setPrototypeOf || |
|
2897 |
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
2898 |
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
2899 |
+ return function (d, b) { |
|
2900 |
+ extendStatics(d, b); |
|
2901 |
+ function __() { this.constructor = d; } |
|
2902 |
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
3134 | 2903 |
}; |
3135 |
- }), |
|
3136 |
- "soft": parameters["soft"] |
|
3137 |
- })); |
|
3138 |
- }); |
|
3139 |
- lib_meta.register("obj", function (parameters) { return lib_meta.construct("object", parameters); }); |
|
3140 |
-})(lib_meta || (lib_meta = {})); |
|
2904 |
+})(); |
|
3141 | 2905 |
var lib_meta; |
3142 | 2906 |
(function (lib_meta) { |
3143 | 2907 |
/** |
3144 |
- * @author fenris |
|
2908 |
+ * @author frac |
|
3145 | 2909 |
*/ |
3146 |
- var class_shape_date = (function (_super) { |
|
3147 |
- __extends(class_shape_date, _super); |
|
2910 |
+ function type_toString(type) { |
|
2911 |
+ // return ("<" + type.id + ">"); |
|
2912 |
+ return JSON.stringify(type); |
|
2913 |
+ } |
|
2914 |
+ lib_meta.type_toString = type_toString; |
|
3148 | 2915 |
/** |
3149 |
- * @author fenris |
|
2916 |
+ * @author frac |
|
3150 | 2917 |
*/ |
3151 |
- function class_shape_date(_a) { |
|
3152 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? new Date(Date.now()) : _c; |
|
3153 |
- return _super.call(this, { |
|
3154 |
- "primitive": true, |
|
3155 |
- "soft": soft, |
|
3156 |
- "defaultvalue": defaultvalue |
|
3157 |
- }) || this; |
|
2918 |
+ var class_pool = {}; |
|
2919 |
+ /** |
|
2920 |
+ * @author frac |
|
2921 |
+ */ |
|
2922 |
+ function class_set(name, class_) { |
|
2923 |
+ class_pool[name] = class_; |
|
3158 | 2924 |
} |
2925 |
+ lib_meta.class_set = class_set; |
|
3159 | 2926 |
/** |
3160 |
- * @override |
|
3161 |
- * @author fenris |
|
2927 |
+ * @author frac |
|
3162 | 2928 |
*/ |
3163 |
- class_shape_date.prototype.inspect = function (value) { |
|
3164 |
- var messages = _super.prototype.inspect.call(this, value); |
|
3165 |
- if (value != null) { |
|
3166 |
- if (!((typeof (value) == "object") && (value instanceof Date))) { |
|
3167 |
- messages.push("value is not a date"); |
|
2929 |
+ function class_get(name) { |
|
2930 |
+ if (name in class_pool) { |
|
2931 |
+ return class_pool[name]; |
|
3168 | 2932 |
} |
2933 |
+ else { |
|
2934 |
+ throw (new Error("no class registered for name '" + name + "'")); |
|
3169 | 2935 |
} |
3170 |
- return messages; |
|
3171 |
- }; |
|
2936 |
+ } |
|
2937 |
+ lib_meta.class_get = class_get; |
|
3172 | 2938 |
/** |
3173 |
- * @override |
|
3174 |
- * @author fenris |
|
2939 |
+ * @author frac |
|
3175 | 2940 |
*/ |
3176 |
- class_shape_date.prototype.to_raw = function () { |
|
3177 |
- return { |
|
2941 |
+ function transform_field(name, attributes) { |
|
2942 |
+ var type = attributes["type"]; |
|
2943 |
+ var path = name; |
|
2944 |
+ var label = ((attributes["title"] != undefined) ? attributes["title"] : name); |
|
2945 |
+ var display = ((attributes["display"] != undefined) ? attributes["display"] : true); |
|
2946 |
+ return ({ |
|
2947 |
+ "path": path, |
|
2948 |
+ "type": type, |
|
2949 |
+ "label": label, |
|
2950 |
+ "display": display |
|
2951 |
+ }); |
|
2952 |
+ } |
|
2953 |
+ lib_meta.transform_field = transform_field; |
|
2954 |
+ /** |
|
2955 |
+ * @author frac |
|
2956 |
+ */ |
|
2957 |
+ function transform_description(label, description, groups_raw) { |
|
2958 |
+ if (groups_raw === void 0) { groups_raw = null; } |
|
2959 |
+ var fieldmap; |
|
2960 |
+ var fields = Object.keys(description).map(function (key) { return transform_field(key, description[key]); }); |
|
2961 |
+ var groups = ((groups_raw == null) |
|
2962 |
+ ? |
|
2963 |
+ null |
|
2964 |
+ : |
|
2965 |
+ groups_raw.map(function (group_raw) { |
|
2966 |
+ return { |
|
2967 |
+ "label": group_raw["label"], |
|
2968 |
+ "fields": group_raw["fields"].map(function (field_name) { |
|
2969 |
+ var index = fields["findIndex"](function (field) { return (field.path == field_name); }); |
|
2970 |
+ if (index < 0) { |
|
2971 |
+ throw (new Error("field " + field_name + " not found in model-description")); |
|
2972 |
+ } |
|
2973 |
+ return index; |
|
2974 |
+ }) |
|
2975 |
+ }; |
|
2976 |
+ })); |
|
2977 |
+ return { |
|
2978 |
+ "fields": fields, |
|
2979 |
+ "description": null, |
|
2980 |
+ "title": label, |
|
2981 |
+ "groups": groups |
|
2982 |
+ }; |
|
2983 |
+ } |
|
2984 |
+ lib_meta.transform_description = transform_description; |
|
2985 |
+ /** |
|
2986 |
+ * @author frac |
|
2987 |
+ */ |
|
2988 |
+ function transform_description_groups(label, description_model, description_groups) { |
|
2989 |
+ return ({ |
|
2990 |
+ "label": label, |
|
2991 |
+ "groups": description_groups.map(function (group_raw) { |
|
2992 |
+ return { |
|
2993 |
+ "label": group_raw["label"], |
|
2994 |
+ "fields": group_raw["fields"].map(function (path) { |
|
2995 |
+ var field_raw = description_model[path]; |
|
2996 |
+ return transform_field(path, field_raw); |
|
2997 |
+ }) |
|
2998 |
+ }; |
|
2999 |
+ }) |
|
3000 |
+ }); |
|
3001 |
+ } |
|
3002 |
+ lib_meta.transform_description_groups = transform_description_groups; |
|
3003 |
+})(lib_meta || (lib_meta = {})); |
|
3004 |
+/// <reference path="../../base/build/logic-decl.d.ts"/> |
|
3005 |
+/// <reference path="../../object/build/logic-decl.d.ts"/> |
|
3006 |
+var lib_meta; |
|
3007 |
+(function (lib_meta) { |
|
3008 |
+ /** |
|
3009 |
+ * @author fenris |
|
3010 |
+ */ |
|
3011 |
+ lib_meta._logprefix = "[lib_meta] "; |
|
3012 |
+ /** |
|
3013 |
+ * @author fenris |
|
3014 |
+ */ |
|
3015 |
+ lib_meta._verbosity = 1; |
|
3016 |
+})(lib_meta || (lib_meta = {})); |
|
3017 |
+var lib_meta; |
|
3018 |
+(function (lib_meta) { |
|
3019 |
+ /** |
|
3020 |
+ * @author fenris |
|
3021 |
+ */ |
|
3022 |
+ var class_shape = (function () { |
|
3023 |
+ /** |
|
3024 |
+ * @desc [constructor] |
|
3025 |
+ * @author fenris |
|
3026 |
+ */ |
|
3027 |
+ function class_shape(_a) { |
|
3028 |
+ var _b = _a["primitive"], primitive = _b === void 0 ? false : _b, _c = _a["soft"], soft = _c === void 0 ? true : _c, _d = _a["defaultvalue"], defaultvalue = _d === void 0 ? null : _d; |
|
3029 |
+ /* |
|
3030 |
+ if ((! soft) && (defaultvalue == null)) { |
|
3031 |
+ throw (new Error("'null' is not a valid defaultvalue for hard shapes")); |
|
3032 |
+ } |
|
3033 |
+ */ |
|
3034 |
+ this.primitive = primitive; |
|
3035 |
+ this.soft = soft; |
|
3036 |
+ this.defaultvalue = defaultvalue; |
|
3037 |
+ } |
|
3038 |
+ /** |
|
3039 |
+ * @desc [accessor] [getter] |
|
3040 |
+ * @author fenris |
|
3041 |
+ */ |
|
3042 |
+ class_shape.prototype.primitive_get = function () { |
|
3043 |
+ return this.primitive; |
|
3044 |
+ }; |
|
3045 |
+ /** |
|
3046 |
+ * @desc [accessor] [getter] |
|
3047 |
+ * @author fenris |
|
3048 |
+ */ |
|
3049 |
+ class_shape.prototype.soft_get = function () { |
|
3050 |
+ return this.soft; |
|
3051 |
+ }; |
|
3052 |
+ /** |
|
3053 |
+ * @desc [accessor] [getter] |
|
3054 |
+ * @author fenris |
|
3055 |
+ */ |
|
3056 |
+ class_shape.prototype.defaultvalue_get = function () { |
|
3057 |
+ return this.defaultvalue; |
|
3058 |
+ }; |
|
3059 |
+ /** |
|
3060 |
+ * @desc [accessor] |
|
3061 |
+ * @author fenris |
|
3062 |
+ */ |
|
3063 |
+ class_shape.prototype.inspect = function (value) { |
|
3064 |
+ var messages = []; |
|
3065 |
+ if ((!this.soft) && (value == null)) { |
|
3066 |
+ messages.push("shape does not allow 'null' as value"); |
|
3067 |
+ } |
|
3068 |
+ return messages; |
|
3069 |
+ }; |
|
3070 |
+ /** |
|
3071 |
+ * @desc [accessor] |
|
3072 |
+ * @author fenris |
|
3073 |
+ */ |
|
3074 |
+ class_shape.prototype.check = function (value) { |
|
3075 |
+ var messages = this.inspect(value); |
|
3076 |
+ if (lib_meta._verbosity >= 1) { |
|
3077 |
+ messages.forEach(function (message) { return console.warn("" + lib_meta._logprefix + message); }); |
|
3078 |
+ } |
|
3079 |
+ return (messages.length == 0); |
|
3080 |
+ }; |
|
3081 |
+ return class_shape; |
|
3082 |
+ }()); |
|
3083 |
+ lib_meta.class_shape = class_shape; |
|
3084 |
+ /** |
|
3085 |
+ * @author fenris |
|
3086 |
+ */ |
|
3087 |
+ var class_shape_buildin = (function (_super) { |
|
3088 |
+ __extends(class_shape_buildin, _super); |
|
3089 |
+ /** |
|
3090 |
+ * @author fenris |
|
3091 |
+ */ |
|
3092 |
+ function class_shape_buildin(_a) { |
|
3093 |
+ var typename = _a["typename"], _b = _a["primitive"], primitive = _b === void 0 ? undefined : _b, _c = _a["soft"], soft = _c === void 0 ? undefined : _c, _d = _a["defaultvalue"], defaultvalue = _d === void 0 ? undefined : _d; |
|
3094 |
+ var _this = _super.call(this, { |
|
3095 |
+ "primitive": primitive, |
|
3096 |
+ "soft": soft, |
|
3097 |
+ "defaultvalue": defaultvalue |
|
3098 |
+ }) || this; |
|
3099 |
+ _this.typename = typename; |
|
3100 |
+ return _this; |
|
3101 |
+ } |
|
3102 |
+ /** |
|
3103 |
+ * @override |
|
3104 |
+ * @author fenris |
|
3105 |
+ */ |
|
3106 |
+ class_shape_buildin.prototype.inspect = function (value) { |
|
3107 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3108 |
+ if ((!this.soft) && (typeof (value) != this.typename)) { |
|
3109 |
+ messages.push("typename is not '" + this.typename + "'"); |
|
3110 |
+ } |
|
3111 |
+ return messages; |
|
3112 |
+ }; |
|
3113 |
+ /** |
|
3114 |
+ * @desc [implementation] |
|
3115 |
+ * @author fenris |
|
3116 |
+ */ |
|
3117 |
+ class_shape_buildin.prototype._show = function () { |
|
3118 |
+ var str = ""; |
|
3119 |
+ str = this.typename; |
|
3120 |
+ if (this.soft) { |
|
3121 |
+ str = str + "_or_null"; |
|
3122 |
+ } |
|
3123 |
+ return str; |
|
3124 |
+ }; |
|
3125 |
+ return class_shape_buildin; |
|
3126 |
+ }(class_shape)); |
|
3127 |
+ lib_meta.class_shape_buildin = class_shape_buildin; |
|
3128 |
+ /** |
|
3129 |
+ * @author fenris |
|
3130 |
+ */ |
|
3131 |
+ var _pool = {}; |
|
3132 |
+ /** |
|
3133 |
+ * @author fenris |
|
3134 |
+ */ |
|
3135 |
+ function register(id, factory) { |
|
3136 |
+ if (id in _pool) { |
|
3137 |
+ var message = "shape '" + id + "' already registered"; |
|
3138 |
+ throw (new Error(message)); |
|
3139 |
+ } |
|
3140 |
+ else { |
|
3141 |
+ _pool[id] = factory; |
|
3142 |
+ } |
|
3143 |
+ } |
|
3144 |
+ lib_meta.register = register; |
|
3145 |
+ /** |
|
3146 |
+ * @author fenris |
|
3147 |
+ */ |
|
3148 |
+ function construct(id, parameters) { |
|
3149 |
+ if (parameters === void 0) { parameters = {}; } |
|
3150 |
+ if (!(id in _pool)) { |
|
3151 |
+ var message = "no shape found with id " + id; |
|
3152 |
+ throw (new Error(message)); |
|
3153 |
+ } |
|
3154 |
+ else { |
|
3155 |
+ return _pool[id](parameters); |
|
3156 |
+ } |
|
3157 |
+ } |
|
3158 |
+ lib_meta.construct = construct; |
|
3159 |
+ /** |
|
3160 |
+ * @author fenris |
|
3161 |
+ */ |
|
3162 |
+ function from_raw(shape_raw) { |
|
3163 |
+ return construct(shape_raw.id, shape_raw.parameters); |
|
3164 |
+ } |
|
3165 |
+ lib_meta.from_raw = from_raw; |
|
3166 |
+ /** |
|
3167 |
+ * @author fenris |
|
3168 |
+ */ |
|
3169 |
+ function define(id, shape_raw) { |
|
3170 |
+ register(id, function (parameters) { return from_raw(shape_raw); }); |
|
3171 |
+ } |
|
3172 |
+ lib_meta.define = define; |
|
3173 |
+ /** |
|
3174 |
+ * @author fenris |
|
3175 |
+ */ |
|
3176 |
+ function retrieve(id) { |
|
3177 |
+ return construct(id, {}); |
|
3178 |
+ } |
|
3179 |
+ lib_meta.retrieve = retrieve; |
|
3180 |
+})(lib_meta || (lib_meta = {})); |
|
3181 |
+var lib_meta; |
|
3182 |
+(function (lib_meta) { |
|
3183 |
+ /** |
|
3184 |
+ * @author fenris |
|
3185 |
+ */ |
|
3186 |
+ var class_shape_any = (function (_super) { |
|
3187 |
+ __extends(class_shape_any, _super); |
|
3188 |
+ /** |
|
3189 |
+ * @author fenris |
|
3190 |
+ */ |
|
3191 |
+ function class_shape_any(_a) { |
|
3192 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? 0 : _c; |
|
3193 |
+ return _super.call(this, { |
|
3194 |
+ "soft": soft, |
|
3195 |
+ "defaultvalue": defaultvalue |
|
3196 |
+ }) || this; |
|
3197 |
+ } |
|
3198 |
+ /** |
|
3199 |
+ * @override |
|
3200 |
+ * @author fenris |
|
3201 |
+ */ |
|
3202 |
+ class_shape_any.prototype.inspect = function (value) { |
|
3203 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3204 |
+ return messages; |
|
3205 |
+ }; |
|
3206 |
+ /** |
|
3207 |
+ * @override |
|
3208 |
+ * @author fenris |
|
3209 |
+ */ |
|
3210 |
+ class_shape_any.prototype.to_raw = function () { |
|
3211 |
+ return { |
|
3212 |
+ "id": "any", |
|
3213 |
+ "parameters": { |
|
3214 |
+ "soft": this.soft |
|
3215 |
+ } |
|
3216 |
+ }; |
|
3217 |
+ }; |
|
3218 |
+ /** |
|
3219 |
+ * @desc [implementation] |
|
3220 |
+ * @author fenris |
|
3221 |
+ */ |
|
3222 |
+ class_shape_any.prototype._show = function () { |
|
3223 |
+ var str = "any"; |
|
3224 |
+ return str; |
|
3225 |
+ }; |
|
3226 |
+ return class_shape_any; |
|
3227 |
+ }(lib_meta.class_shape)); |
|
3228 |
+ lib_meta.class_shape_any = class_shape_any; |
|
3229 |
+ lib_meta.register("any", function (parameters) { |
|
3230 |
+ return (new class_shape_any({ |
|
3231 |
+ "soft": parameters["soft"] |
|
3232 |
+ })); |
|
3233 |
+ }); |
|
3234 |
+})(lib_meta || (lib_meta = {})); |
|
3235 |
+var lib_meta; |
|
3236 |
+(function (lib_meta) { |
|
3237 |
+ /** |
|
3238 |
+ * @author fenris |
|
3239 |
+ */ |
|
3240 |
+ var class_shape_boolean = (function (_super) { |
|
3241 |
+ __extends(class_shape_boolean, _super); |
|
3242 |
+ /** |
|
3243 |
+ * @author fenris |
|
3244 |
+ */ |
|
3245 |
+ function class_shape_boolean(_a) { |
|
3246 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? false : _c; |
|
3247 |
+ return _super.call(this, { |
|
3248 |
+ "typename": "boolean", |
|
3249 |
+ "primitive": true, |
|
3250 |
+ "soft": soft, |
|
3251 |
+ "defaultvalue": defaultvalue |
|
3252 |
+ }) || this; |
|
3253 |
+ } |
|
3254 |
+ /** |
|
3255 |
+ * @override |
|
3256 |
+ * @author fenris |
|
3257 |
+ */ |
|
3258 |
+ class_shape_boolean.prototype.to_raw = function () { |
|
3259 |
+ return { |
|
3260 |
+ "id": "boolean", |
|
3261 |
+ "parameters": { |
|
3262 |
+ "soft": this.soft |
|
3263 |
+ } |
|
3264 |
+ }; |
|
3265 |
+ }; |
|
3266 |
+ return class_shape_boolean; |
|
3267 |
+ }(lib_meta.class_shape_buildin)); |
|
3268 |
+ lib_meta.class_shape_boolean = class_shape_boolean; |
|
3269 |
+ lib_meta.register("boolean", function (parameters) { |
|
3270 |
+ return (new class_shape_boolean({ |
|
3271 |
+ "soft": parameters["soft"] |
|
3272 |
+ })); |
|
3273 |
+ }); |
|
3274 |
+ lib_meta.register("bool", function (parameters) { return lib_meta.construct("boolean", parameters); }); |
|
3275 |
+})(lib_meta || (lib_meta = {})); |
|
3276 |
+var lib_meta; |
|
3277 |
+(function (lib_meta) { |
|
3278 |
+ /** |
|
3279 |
+ * @author fenris |
|
3280 |
+ */ |
|
3281 |
+ var class_shape_integer = (function (_super) { |
|
3282 |
+ __extends(class_shape_integer, _super); |
|
3283 |
+ /** |
|
3284 |
+ * @author fenris |
|
3285 |
+ */ |
|
3286 |
+ function class_shape_integer(_a) { |
|
3287 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? 0 : _c, _d = _a["min"], min = _d === void 0 ? null : _d, _e = _a["max"], max = _e === void 0 ? null : _e; |
|
3288 |
+ var _this = _super.call(this, { |
|
3289 |
+ "typename": "number", |
|
3290 |
+ "primitive": true, |
|
3291 |
+ "soft": soft, |
|
3292 |
+ "defaultvalue": defaultvalue |
|
3293 |
+ }) || this; |
|
3294 |
+ _this.min = min; |
|
3295 |
+ _this.max = max; |
|
3296 |
+ return _this; |
|
3297 |
+ } |
|
3298 |
+ /** |
|
3299 |
+ * @desc [accessor] [getter] |
|
3300 |
+ * @author fenris |
|
3301 |
+ */ |
|
3302 |
+ class_shape_integer.prototype.min_get = function () { |
|
3303 |
+ return this.min; |
|
3304 |
+ }; |
|
3305 |
+ /** |
|
3306 |
+ * @desc [accessor] [getter] |
|
3307 |
+ * @author fenris |
|
3308 |
+ */ |
|
3309 |
+ class_shape_integer.prototype.max_get = function () { |
|
3310 |
+ return this.max; |
|
3311 |
+ }; |
|
3312 |
+ /** |
|
3313 |
+ * @override |
|
3314 |
+ * @author fenris |
|
3315 |
+ */ |
|
3316 |
+ class_shape_integer.prototype.inspect = function (value) { |
|
3317 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3318 |
+ if (value != null) { |
|
3319 |
+ if ((this.min != null) && (value < this.min)) { |
|
3320 |
+ messages.push("value is below minimum of " + this.min.toString()); |
|
3321 |
+ } |
|
3322 |
+ if ((this.max != null) && (value > this.max)) { |
|
3323 |
+ messages.push("value is over maximum of " + this.max.toString()); |
|
3324 |
+ } |
|
3325 |
+ } |
|
3326 |
+ return messages; |
|
3327 |
+ }; |
|
3328 |
+ /** |
|
3329 |
+ * @override |
|
3330 |
+ * @author fenris |
|
3331 |
+ */ |
|
3332 |
+ class_shape_integer.prototype.to_raw = function () { |
|
3333 |
+ return { |
|
3334 |
+ "id": "integer", |
|
3335 |
+ "parameters": { |
|
3336 |
+ "soft": this.soft, |
|
3337 |
+ "min": this.min, |
|
3338 |
+ "max": this.max |
|
3339 |
+ } |
|
3340 |
+ }; |
|
3341 |
+ }; |
|
3342 |
+ return class_shape_integer; |
|
3343 |
+ }(lib_meta.class_shape_buildin)); |
|
3344 |
+ lib_meta.class_shape_integer = class_shape_integer; |
|
3345 |
+ lib_meta.register("integer", function (parameters) { |
|
3346 |
+ return (new class_shape_integer({ |
|
3347 |
+ "min": parameters["min"], |
|
3348 |
+ "max": parameters["max"], |
|
3349 |
+ "soft": parameters["soft"] |
|
3350 |
+ })); |
|
3351 |
+ }); |
|
3352 |
+ lib_meta.register("int", function (parameters) { return lib_meta.construct("integer", parameters); }); |
|
3353 |
+})(lib_meta || (lib_meta = {})); |
|
3354 |
+var lib_meta; |
|
3355 |
+(function (lib_meta) { |
|
3356 |
+ /** |
|
3357 |
+ * @author fenris |
|
3358 |
+ */ |
|
3359 |
+ var class_shape_float = (function (_super) { |
|
3360 |
+ __extends(class_shape_float, _super); |
|
3361 |
+ /** |
|
3362 |
+ * @author fenris |
|
3363 |
+ */ |
|
3364 |
+ function class_shape_float(_a) { |
|
3365 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? 0.0 : _c, _d = _a["min"], min = _d === void 0 ? null : _d, _e = _a["max"], max = _e === void 0 ? null : _e; |
|
3366 |
+ var _this = _super.call(this, { |
|
3367 |
+ "typename": "number", |
|
3368 |
+ "primitive": true, |
|
3369 |
+ "soft": soft, |
|
3370 |
+ "defaultvalue": defaultvalue |
|
3371 |
+ }) || this; |
|
3372 |
+ _this.min = min; |
|
3373 |
+ _this.max = max; |
|
3374 |
+ return _this; |
|
3375 |
+ } |
|
3376 |
+ /** |
|
3377 |
+ * @desc [accessor] [getter] |
|
3378 |
+ * @author fenris |
|
3379 |
+ */ |
|
3380 |
+ class_shape_float.prototype.min_get = function () { |
|
3381 |
+ return this.min; |
|
3382 |
+ }; |
|
3383 |
+ /** |
|
3384 |
+ * @desc [accessor] [getter] |
|
3385 |
+ * @author fenris |
|
3386 |
+ */ |
|
3387 |
+ class_shape_float.prototype.max_get = function () { |
|
3388 |
+ return this.max; |
|
3389 |
+ }; |
|
3390 |
+ /** |
|
3391 |
+ * @override |
|
3392 |
+ * @author fenris |
|
3393 |
+ */ |
|
3394 |
+ class_shape_float.prototype.inspect = function (value) { |
|
3395 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3396 |
+ if (value != null) { |
|
3397 |
+ if ((this.min != null) && (value < this.min)) { |
|
3398 |
+ messages.push("value is below minimum of " + this.min.toString()); |
|
3399 |
+ } |
|
3400 |
+ if ((this.max != null) && (value > this.max)) { |
|
3401 |
+ messages.push("value is over maximum of " + this.max.toString()); |
|
3402 |
+ } |
|
3403 |
+ } |
|
3404 |
+ return messages; |
|
3405 |
+ }; |
|
3406 |
+ /** |
|
3407 |
+ * @override |
|
3408 |
+ * @author fenris |
|
3409 |
+ */ |
|
3410 |
+ class_shape_float.prototype.to_raw = function () { |
|
3411 |
+ return { |
|
3412 |
+ "id": "float", |
|
3413 |
+ "parameters": { |
|
3414 |
+ "soft": this.soft, |
|
3415 |
+ "min": this.min, |
|
3416 |
+ "max": this.max |
|
3417 |
+ } |
|
3418 |
+ }; |
|
3419 |
+ }; |
|
3420 |
+ return class_shape_float; |
|
3421 |
+ }(lib_meta.class_shape_buildin)); |
|
3422 |
+ lib_meta.class_shape_float = class_shape_float; |
|
3423 |
+ lib_meta.register("float", function (parameters) { |
|
3424 |
+ return (new class_shape_float({ |
|
3425 |
+ "min": parameters["min"], |
|
3426 |
+ "max": parameters["max"], |
|
3427 |
+ "soft": parameters["soft"] |
|
3428 |
+ })); |
|
3429 |
+ }); |
|
3430 |
+})(lib_meta || (lib_meta = {})); |
|
3431 |
+var lib_meta; |
|
3432 |
+(function (lib_meta) { |
|
3433 |
+ /** |
|
3434 |
+ * @author fenris |
|
3435 |
+ */ |
|
3436 |
+ var class_shape_string = (function (_super) { |
|
3437 |
+ __extends(class_shape_string, _super); |
|
3438 |
+ /** |
|
3439 |
+ * @author fenris |
|
3440 |
+ */ |
|
3441 |
+ function class_shape_string(_a) { |
|
3442 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? "" : _c; |
|
3443 |
+ return _super.call(this, { |
|
3444 |
+ "typename": "string", |
|
3445 |
+ "primitive": true, |
|
3446 |
+ "soft": soft, |
|
3447 |
+ "defaultvalue": defaultvalue |
|
3448 |
+ }) || this; |
|
3449 |
+ } |
|
3450 |
+ /** |
|
3451 |
+ * @override |
|
3452 |
+ * @author fenris |
|
3453 |
+ */ |
|
3454 |
+ class_shape_string.prototype.to_raw = function () { |
|
3455 |
+ return { |
|
3456 |
+ "id": "string", |
|
3457 |
+ "parameters": { |
|
3458 |
+ "soft": this.soft |
|
3459 |
+ } |
|
3460 |
+ }; |
|
3461 |
+ }; |
|
3462 |
+ return class_shape_string; |
|
3463 |
+ }(lib_meta.class_shape_buildin)); |
|
3464 |
+ lib_meta.class_shape_string = class_shape_string; |
|
3465 |
+ /** |
|
3466 |
+ * @author fenris |
|
3467 |
+ */ |
|
3468 |
+ lib_meta.register("string", function (parameters) { |
|
3469 |
+ return (new class_shape_string({ |
|
3470 |
+ "soft": parameters["soft"] |
|
3471 |
+ })); |
|
3472 |
+ }); |
|
3473 |
+ lib_meta.register("str", function (parameters) { return lib_meta.construct("string", parameters); }); |
|
3474 |
+})(lib_meta || (lib_meta = {})); |
|
3475 |
+var lib_meta; |
|
3476 |
+(function (lib_meta) { |
|
3477 |
+ /** |
|
3478 |
+ * @author fenris |
|
3479 |
+ */ |
|
3480 |
+ var class_shape_email = (function (_super) { |
|
3481 |
+ __extends(class_shape_email, _super); |
|
3482 |
+ /** |
|
3483 |
+ * @author fenris |
|
3484 |
+ */ |
|
3485 |
+ function class_shape_email(_a) { |
|
3486 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? "" : _c; |
|
3487 |
+ return _super.call(this, { |
|
3488 |
+ "primitive": true, |
|
3489 |
+ "soft": soft, |
|
3490 |
+ "defaultvalue": defaultvalue |
|
3491 |
+ }) || this; |
|
3492 |
+ } |
|
3493 |
+ /** |
|
3494 |
+ * @override |
|
3495 |
+ * @author fenris |
|
3496 |
+ */ |
|
3497 |
+ class_shape_email.prototype.to_raw = function () { |
|
3498 |
+ return { |
|
3499 |
+ "id": "email", |
|
3500 |
+ "parameters": { |
|
3501 |
+ "soft": this.soft |
|
3502 |
+ } |
|
3503 |
+ }; |
|
3504 |
+ }; |
|
3505 |
+ /** |
|
3506 |
+ * @desc [implementation] |
|
3507 |
+ * @author fenris |
|
3508 |
+ */ |
|
3509 |
+ class_shape_email.prototype._show = function () { |
|
3510 |
+ var str = "email"; |
|
3511 |
+ return str; |
|
3512 |
+ }; |
|
3513 |
+ return class_shape_email; |
|
3514 |
+ }(lib_meta.class_shape)); |
|
3515 |
+ lib_meta.class_shape_email = class_shape_email; |
|
3516 |
+ lib_meta.register("email", function (parameters) { |
|
3517 |
+ return (new class_shape_email({ |
|
3518 |
+ "soft": parameters["soft"] |
|
3519 |
+ })); |
|
3520 |
+ }); |
|
3521 |
+})(lib_meta || (lib_meta = {})); |
|
3522 |
+var lib_meta; |
|
3523 |
+(function (lib_meta) { |
|
3524 |
+ /** |
|
3525 |
+ * @author fenris |
|
3526 |
+ */ |
|
3527 |
+ var class_shape_array = (function (_super) { |
|
3528 |
+ __extends(class_shape_array, _super); |
|
3529 |
+ /** |
|
3530 |
+ * @author fenris |
|
3531 |
+ */ |
|
3532 |
+ function class_shape_array(_a) { |
|
3533 |
+ var shape_element = _a["shape_element"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? [] : _c; |
|
3534 |
+ var _this = _super.call(this, { |
|
3535 |
+ "primitive": false, |
|
3536 |
+ "soft": soft, |
|
3537 |
+ "defaultvalue": defaultvalue |
|
3538 |
+ }) || this; |
|
3539 |
+ _this.shape_element = shape_element; |
|
3540 |
+ return _this; |
|
3541 |
+ } |
|
3542 |
+ /** |
|
3543 |
+ * @desc [accessor] [getter] |
|
3544 |
+ * @author fenris |
|
3545 |
+ */ |
|
3546 |
+ class_shape_array.prototype.shape_element_get = function () { |
|
3547 |
+ return this.shape_element; |
|
3548 |
+ }; |
|
3549 |
+ /** |
|
3550 |
+ * @override |
|
3551 |
+ * @author fenris |
|
3552 |
+ */ |
|
3553 |
+ class_shape_array.prototype.inspect = function (value) { |
|
3554 |
+ var _this = this; |
|
3555 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3556 |
+ if (value != null) { |
|
3557 |
+ if (!((typeof (value) == "object") && (value instanceof Array))) { |
|
3558 |
+ messages.push("value is not an array"); |
|
3559 |
+ } |
|
3560 |
+ else { |
|
3561 |
+ var array = (value); |
|
3562 |
+ array.forEach(function (element, index) { |
|
3563 |
+ messages = messages.concat(_this.shape_element.inspect(element).map(function (message) { return "array element #" + index.toString() + ": " + message; })); |
|
3564 |
+ }); |
|
3565 |
+ } |
|
3566 |
+ } |
|
3567 |
+ return messages; |
|
3568 |
+ }; |
|
3569 |
+ /** |
|
3570 |
+ * @override |
|
3571 |
+ * @author fenris |
|
3572 |
+ */ |
|
3573 |
+ class_shape_array.prototype.to_raw = function () { |
|
3574 |
+ return { |
|
3575 |
+ "id": "array", |
|
3576 |
+ "parameters": { |
|
3577 |
+ "shape_element": this.shape_element.to_raw(), |
|
3578 |
+ "soft": this.soft |
|
3579 |
+ } |
|
3580 |
+ }; |
|
3581 |
+ }; |
|
3582 |
+ /** |
|
3583 |
+ * @desc [implementation] |
|
3584 |
+ * @author fenris |
|
3585 |
+ */ |
|
3586 |
+ class_shape_array.prototype._show = function () { |
|
3587 |
+ var str = "array"; |
|
3588 |
+ str += "<" + instance_show(this.shape_element) + ">"; |
|
3589 |
+ return str; |
|
3590 |
+ }; |
|
3591 |
+ return class_shape_array; |
|
3592 |
+ }(lib_meta.class_shape)); |
|
3593 |
+ lib_meta.class_shape_array = class_shape_array; |
|
3594 |
+ lib_meta.register("array", function (parameters) { |
|
3595 |
+ var shape_element_raw = lib_object.fetch(parameters, "shape_element", null, 2); |
|
3596 |
+ var shape_element = lib_meta.from_raw(shape_element_raw); |
|
3597 |
+ return (new class_shape_array({ |
|
3598 |
+ "shape_element": shape_element, |
|
3599 |
+ "soft": parameters["soft"] |
|
3600 |
+ })); |
|
3601 |
+ }); |
|
3602 |
+ lib_meta.register("arr", function (parameters) { return lib_meta.construct("array", parameters); }); |
|
3603 |
+})(lib_meta || (lib_meta = {})); |
|
3604 |
+var lib_meta; |
|
3605 |
+(function (lib_meta) { |
|
3606 |
+ /** |
|
3607 |
+ * @author fenris |
|
3608 |
+ */ |
|
3609 |
+ var class_shape_object = (function (_super) { |
|
3610 |
+ __extends(class_shape_object, _super); |
|
3611 |
+ /** |
|
3612 |
+ * @author fenris |
|
3613 |
+ */ |
|
3614 |
+ function class_shape_object(_a) { |
|
3615 |
+ var fields = _a["fields"], _b = _a["soft"], soft = _b === void 0 ? true : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? null : _c; |
|
3616 |
+ var _this = this; |
|
3617 |
+ if (defaultvalue == null) { |
|
3618 |
+ defaultvalue = {}; |
|
3619 |
+ fields.forEach(function (field) { |
|
3620 |
+ defaultvalue[field.name] = field.shape.defaultvalue_get(); |
|
3621 |
+ }); |
|
3622 |
+ } |
|
3623 |
+ _this = _super.call(this, { |
|
3624 |
+ "typename": "object", |
|
3625 |
+ "primitive": false, |
|
3626 |
+ "soft": soft, |
|
3627 |
+ "defaultvalue": defaultvalue |
|
3628 |
+ }) || this; |
|
3629 |
+ _this.fields = fields; |
|
3630 |
+ return _this; |
|
3631 |
+ } |
|
3632 |
+ /** |
|
3633 |
+ * @desc [accessor] [getter] |
|
3634 |
+ * @author fenris |
|
3635 |
+ */ |
|
3636 |
+ class_shape_object.prototype.fields_get = function () { |
|
3637 |
+ return this.fields; |
|
3638 |
+ }; |
|
3639 |
+ /** |
|
3640 |
+ * @override |
|
3641 |
+ * @author fenris |
|
3642 |
+ * @todo check for superfluous fields? |
|
3643 |
+ */ |
|
3644 |
+ class_shape_object.prototype.inspect = function (value) { |
|
3645 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3646 |
+ if (value != null) { |
|
3647 |
+ this.fields.forEach(function (field, index) { |
|
3648 |
+ var value_ = value[field.name]; |
|
3649 |
+ messages = messages.concat(field.shape.inspect(value_).map(function (message) { return "object field '" + field.name + "': " + message; })); |
|
3650 |
+ }); |
|
3651 |
+ } |
|
3652 |
+ return messages; |
|
3653 |
+ }; |
|
3654 |
+ /** |
|
3655 |
+ * @override |
|
3656 |
+ * @author fenris |
|
3657 |
+ */ |
|
3658 |
+ class_shape_object.prototype.to_raw = function () { |
|
3659 |
+ return { |
|
3660 |
+ "id": "object", |
|
3661 |
+ "parameters": { |
|
3662 |
+ "soft": this.soft, |
|
3663 |
+ "fields": this.fields.map(function (field) { |
|
3664 |
+ return { |
|
3665 |
+ "name": field.name, |
|
3666 |
+ "shape": field.shape.to_raw(), |
|
3667 |
+ "label": field.label |
|
3668 |
+ }; |
|
3669 |
+ }) |
|
3670 |
+ } |
|
3671 |
+ }; |
|
3672 |
+ }; |
|
3673 |
+ /** |
|
3674 |
+ * @desc [implementation] |
|
3675 |
+ * @author fenris |
|
3676 |
+ */ |
|
3677 |
+ class_shape_object.prototype._show = function () { |
|
3678 |
+ var str = _super.prototype._show.call(this); |
|
3679 |
+ var str_ = this.fields.map(function (field) { return field.name + ":" + instance_show(field.shape); }).join(","); |
|
3680 |
+ str = str + "<" + str_ + ">"; |
|
3681 |
+ return str; |
|
3682 |
+ }; |
|
3683 |
+ return class_shape_object; |
|
3684 |
+ }(lib_meta.class_shape_buildin)); |
|
3685 |
+ lib_meta.class_shape_object = class_shape_object; |
|
3686 |
+ lib_meta.register("object", function (parameters) { |
|
3687 |
+ var fields_ = lib_object.fetch(parameters, "fields", [], 1); |
|
3688 |
+ return (new class_shape_object({ |
|
3689 |
+ "fields": fields_.map(function (field_) { |
|
3690 |
+ var name = lib_object.fetch(field_, "name", null, 2); |
|
3691 |
+ var shape_raw = lib_object.fetch(field_, "shape", null, 2); |
|
3692 |
+ var shape = lib_meta.construct(shape_raw.id, shape_raw.parameters); |
|
3693 |
+ var label = lib_object.fetch(field_, "label", null, 1); |
|
3694 |
+ return { |
|
3695 |
+ "name": name, |
|
3696 |
+ "shape": shape, |
|
3697 |
+ "label": label |
|
3698 |
+ }; |
|
3699 |
+ }), |
|
3700 |
+ "soft": parameters["soft"] |
|
3701 |
+ })); |
|
3702 |
+ }); |
|
3703 |
+ lib_meta.register("obj", function (parameters) { return lib_meta.construct("object", parameters); }); |
|
3704 |
+})(lib_meta || (lib_meta = {})); |
|
3705 |
+var lib_meta; |
|
3706 |
+(function (lib_meta) { |
|
3707 |
+ /** |
|
3708 |
+ * @author fenris |
|
3709 |
+ */ |
|
3710 |
+ var class_shape_date = (function (_super) { |
|
3711 |
+ __extends(class_shape_date, _super); |
|
3712 |
+ /** |
|
3713 |
+ * @author fenris |
|
3714 |
+ */ |
|
3715 |
+ function class_shape_date(_a) { |
|
3716 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? new Date(Date.now()) : _c; |
|
3717 |
+ return _super.call(this, { |
|
3718 |
+ "primitive": true, |
|
3719 |
+ "soft": soft, |
|
3720 |
+ "defaultvalue": defaultvalue |
|
3721 |
+ }) || this; |
|
3722 |
+ } |
|
3723 |
+ /** |
|
3724 |
+ * @override |
|
3725 |
+ * @author fenris |
|
3726 |
+ */ |
|
3727 |
+ class_shape_date.prototype.inspect = function (value) { |
|
3728 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3729 |
+ if (value != null) { |
|
3730 |
+ if (!((typeof (value) == "object") && (value instanceof Date))) { |
|
3731 |
+ messages.push("value is not a date"); |
|
3732 |
+ } |
|
3733 |
+ } |
|
3734 |
+ return messages; |
|
3735 |
+ }; |
|
3736 |
+ /** |
|
3737 |
+ * @override |
|
3738 |
+ * @author fenris |
|
3739 |
+ */ |
|
3740 |
+ class_shape_date.prototype.to_raw = function () { |
|
3741 |
+ return { |
|
3178 | 3742 |
"id": "date", |
3179 | 3743 |
"parameters": { |
3180 | 3744 |
"soft": this.soft |
3181 | 3745 |
} |
3182 | 3746 |
}; |
3183 | 3747 |
}; |
3184 |
- /** |
|
3185 |
- * @desc [implementation] |
|
3186 |
- * @author fenris |
|
3187 |
- */ |
|
3188 |
- class_shape_date.prototype._show = function () { |
|
3189 |
- var str = "date"; |
|
3190 |
- return str; |
|
3748 |
+ /** |
|
3749 |
+ * @desc [implementation] |
|
3750 |
+ * @author fenris |
|
3751 |
+ */ |
|
3752 |
+ class_shape_date.prototype._show = function () { |
|
3753 |
+ var str = "date"; |
|
3754 |
+ return str; |
|
3755 |
+ }; |
|
3756 |
+ return class_shape_date; |
|
3757 |
+ }(lib_meta.class_shape)); |
|
3758 |
+ lib_meta.class_shape_date = class_shape_date; |
|
3759 |
+ lib_meta.register("date", function (parameters) { |
|
3760 |
+ return (new class_shape_date({ |
|
3761 |
+ "soft": parameters["soft"] |
|
3762 |
+ })); |
|
3763 |
+ }); |
|
3764 |
+})(lib_meta || (lib_meta = {})); |
|
3765 |
+var lib_meta; |
|
3766 |
+(function (lib_meta) { |
|
3767 |
+ /** |
|
3768 |
+ * @desc represented as milliseconds of day |
|
3769 |
+ * @author fenris |
|
3770 |
+ */ |
|
3771 |
+ var class_shape_time = (function (_super) { |
|
3772 |
+ __extends(class_shape_time, _super); |
|
3773 |
+ /** |
|
3774 |
+ * @author fenris |
|
3775 |
+ */ |
|
3776 |
+ function class_shape_time(_a) { |
|
3777 |
+ var _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? class_shape_time.from_timestamp(Date.now()) : _c; |
|
3778 |
+ return _super.call(this, { |
|
3779 |
+ "primitive": true, |
|
3780 |
+ "soft": soft, |
|
3781 |
+ "defaultvalue": defaultvalue |
|
3782 |
+ }) || this; |
|
3783 |
+ } |
|
3784 |
+ /** |
|
3785 |
+ * @override |
|
3786 |
+ * @author fenris |
|
3787 |
+ */ |
|
3788 |
+ class_shape_time.prototype.inspect = function (value) { |
|
3789 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3790 |
+ if (value != null) { |
|
3791 |
+ if (!(typeof (value) == "object")) { |
|
3792 |
+ messages.push("value is not a time"); |
|
3793 |
+ } |
|
3794 |
+ else { |
|
3795 |
+ if (!("hours" in value)) { |
|
3796 |
+ messages.push("hour is missing"); |
|
3797 |
+ } |
|
3798 |
+ if (!("minutes" in value)) { |
|
3799 |
+ messages.push("minutes is missing"); |
|
3800 |
+ } |
|
3801 |
+ if (!("seconds" in value)) { |
|
3802 |
+ messages.push("seconds is missing"); |
|
3803 |
+ } |
|
3804 |
+ } |
|
3805 |
+ } |
|
3806 |
+ return messages; |
|
3807 |
+ }; |
|
3808 |
+ /** |
|
3809 |
+ * @override |
|
3810 |
+ * @author fenris |
|
3811 |
+ */ |
|
3812 |
+ class_shape_time.prototype.to_raw = function () { |
|
3813 |
+ return { |
|
3814 |
+ "id": "time", |
|
3815 |
+ "parameters": { |
|
3816 |
+ "soft": this.soft |
|
3817 |
+ } |
|
3818 |
+ }; |
|
3819 |
+ }; |
|
3820 |
+ /** |
|
3821 |
+ * @desc [implementation] |
|
3822 |
+ * @author fenris |
|
3823 |
+ */ |
|
3824 |
+ class_shape_time.prototype._show = function () { |
|
3825 |
+ var str = "time"; |
|
3826 |
+ return str; |
|
3827 |
+ }; |
|
3828 |
+ /** |
|
3829 |
+ * @author fenris |
|
3830 |
+ */ |
|
3831 |
+ class_shape_time.from_date = function (date) { |
|
3832 |
+ var hours = date.getHours(); |
|
3833 |
+ var minutes = date.getMinutes(); |
|
3834 |
+ var seconds = date.getSeconds(); |
|
3835 |
+ return { "hours": hours, "minutes": minutes, "seconds": seconds }; |
|
3836 |
+ }; |
|
3837 |
+ /** |
|
3838 |
+ * @author fenris |
|
3839 |
+ */ |
|
3840 |
+ class_shape_time.from_timestamp = function (timestamp) { |
|
3841 |
+ var date = new Date(timestamp); |
|
3842 |
+ return this.from_date(date); |
|
3843 |
+ }; |
|
3844 |
+ /** |
|
3845 |
+ * @author fenris |
|
3846 |
+ */ |
|
3847 |
+ class_shape_time.now = function () { |
|
3848 |
+ return this.from_timestamp(Date.now()); |
|
3849 |
+ }; |
|
3850 |
+ return class_shape_time; |
|
3851 |
+ }(lib_meta.class_shape)); |
|
3852 |
+ lib_meta.class_shape_time = class_shape_time; |
|
3853 |
+ /** |
|
3854 |
+ * @author fenris |
|
3855 |
+ */ |
|
3856 |
+ lib_meta.register("time", function (parameters) { |
|
3857 |
+ return (new class_shape_time({ |
|
3858 |
+ "soft": parameters["soft"] |
|
3859 |
+ })); |
|
3860 |
+ }); |
|
3861 |
+})(lib_meta || (lib_meta = {})); |
|
3862 |
+var lib_meta; |
|
3863 |
+(function (lib_meta) { |
|
3864 |
+ /** |
|
3865 |
+ * @author fenris |
|
3866 |
+ */ |
|
3867 |
+ var class_shape_enumeration = (function (_super) { |
|
3868 |
+ __extends(class_shape_enumeration, _super); |
|
3869 |
+ /** |
|
3870 |
+ * @author fenris |
|
3871 |
+ */ |
|
3872 |
+ function class_shape_enumeration(_a) { |
|
3873 |
+ var shape_option = _a["shape_option"], options = _a["options"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? undefined : _c; |
|
3874 |
+ var _this = this; |
|
3875 |
+ if (defaultvalue === undefined) { |
|
3876 |
+ if (soft) { |
|
3877 |
+ defaultvalue = null; |
|
3878 |
+ } |
|
3879 |
+ else { |
|
3880 |
+ if (options.length == 0) { |
|
3881 |
+ throw (new Error("a hard enumeration must have at least one option")); |
|
3882 |
+ } |
|
3883 |
+ else { |
|
3884 |
+ defaultvalue = options[0].value; |
|
3885 |
+ } |
|
3886 |
+ } |
|
3887 |
+ } |
|
3888 |
+ _this = _super.call(this, { |
|
3889 |
+ "primitive": true, |
|
3890 |
+ "soft": soft, |
|
3891 |
+ "defaultvalue": defaultvalue |
|
3892 |
+ }) || this; |
|
3893 |
+ _this.shape_option = shape_option; |
|
3894 |
+ _this.options = options; |
|
3895 |
+ return _this; |
|
3896 |
+ } |
|
3897 |
+ /** |
|
3898 |
+ * @desc [accessor] [getter] |
|
3899 |
+ * @author fenris |
|
3900 |
+ */ |
|
3901 |
+ class_shape_enumeration.prototype.shape_option_get = function () { |
|
3902 |
+ return this.shape_option; |
|
3903 |
+ }; |
|
3904 |
+ /** |
|
3905 |
+ * @desc [accessor] [getter] |
|
3906 |
+ * @author fenris |
|
3907 |
+ */ |
|
3908 |
+ class_shape_enumeration.prototype.options_get = function () { |
|
3909 |
+ return this.options; |
|
3910 |
+ }; |
|
3911 |
+ /** |
|
3912 |
+ * @override |
|
3913 |
+ * @author fenris |
|
3914 |
+ */ |
|
3915 |
+ class_shape_enumeration.prototype.inspect = function (value) { |
|
3916 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
3917 |
+ if (value != null) { |
|
3918 |
+ if (!this.shape_option.check(value)) { |
|
3919 |
+ messages.push("value has not the specified option shape"); |
|
3920 |
+ } |
|
3921 |
+ else { |
|
3922 |
+ var found = this.options.some(function (option) { return instance_collate(option.value, value); }); |
|
3923 |
+ if (!found) { |
|
3924 |
+ messages.push("value is not one of the specified options"); |
|
3925 |
+ } |
|
3926 |
+ } |
|
3927 |
+ } |
|
3928 |
+ return messages; |
|
3929 |
+ }; |
|
3930 |
+ /** |
|
3931 |
+ * @override |
|
3932 |
+ * @author fenris |
|
3933 |
+ */ |
|
3934 |
+ class_shape_enumeration.prototype.to_raw = function () { |
|
3935 |
+ return { |
|
3936 |
+ "id": "enumeration", |
|
3937 |
+ "parameters": { |
|
3938 |
+ "shape_option": this.shape_option.to_raw(), |
|
3939 |
+ "options": this.options.map(function (option) { |
|
3940 |
+ return { |
|
3941 |
+ "value": option.value, |
|
3942 |
+ "label": option.label |
|
3943 |
+ }; |
|
3944 |
+ }), |
|
3945 |
+ "soft": this.soft |
|
3946 |
+ } |
|
3947 |
+ }; |
|
3948 |
+ }; |
|
3949 |
+ /** |
|
3950 |
+ * @desc [implementation] |
|
3951 |
+ * @author fenris |
|
3952 |
+ */ |
|
3953 |
+ class_shape_enumeration.prototype._show = function () { |
|
3954 |
+ var str = "enumeration"; |
|
3955 |
+ { |
|
3956 |
+ str = str + "<" + instance_show(this.shape_option) + ">"; |
|
3957 |
+ } |
|
3958 |
+ { |
|
3959 |
+ var str_ = this.options.map(function (option) { return instance_show(option.value); }).join(","); |
|
3960 |
+ str = str + "[" + str_ + "]"; |
|
3961 |
+ } |
|
3962 |
+ return str; |
|
3963 |
+ }; |
|
3964 |
+ return class_shape_enumeration; |
|
3965 |
+ }(lib_meta.class_shape)); |
|
3966 |
+ lib_meta.class_shape_enumeration = class_shape_enumeration; |
|
3967 |
+ lib_meta.register("enumeration", function (parameters) { |
|
3968 |
+ var shape_option_raw = lib_object.fetch(parameters, "shape_option", null, 2); |
|
3969 |
+ var shape_option = lib_meta.from_raw(shape_option_raw); |
|
3970 |
+ var options = lib_object.fetch(parameters, "options", [], 2); |
|
3971 |
+ return (new class_shape_enumeration({ |
|
3972 |
+ "shape_option": shape_option, |
|
3973 |
+ "options": options, |
|
3974 |
+ "soft": parameters["soft"] |
|
3975 |
+ })); |
|
3976 |
+ }); |
|
3977 |
+})(lib_meta || (lib_meta = {})); |
|
3978 |
+var lib_meta; |
|
3979 |
+(function (lib_meta) { |
|
3980 |
+ /** |
|
3981 |
+ * @author fenris |
|
3982 |
+ */ |
|
3983 |
+ var class_shape_map = (function (_super) { |
|
3984 |
+ __extends(class_shape_map, _super); |
|
3985 |
+ /** |
|
3986 |
+ * @author fenris |
|
3987 |
+ */ |
|
3988 |
+ function class_shape_map(_a) { |
|
3989 |
+ var shape_key = _a["shape_key"], shape_value = _a["shape_value"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? {} : _c; |
|
3990 |
+ var _this = _super.call(this, { |
|
3991 |
+ "primitive": true, |
|
3992 |
+ "soft": soft, |
|
3993 |
+ "defaultvalue": defaultvalue |
|
3994 |
+ }) || this; |
|
3995 |
+ _this.shape_key = shape_key; |
|
3996 |
+ _this.shape_value = shape_value; |
|
3997 |
+ return _this; |
|
3998 |
+ } |
|
3999 |
+ /** |
|
4000 |
+ * @desc [accessor] [getter] |
|
4001 |
+ * @author fenris |
|
4002 |
+ */ |
|
4003 |
+ class_shape_map.prototype.shape_key_get = function () { |
|
4004 |
+ return this.shape_key; |
|
4005 |
+ }; |
|
4006 |
+ /** |
|
4007 |
+ * @desc [accessor] [getter] |
|
4008 |
+ * @author fenris |
|
4009 |
+ */ |
|
4010 |
+ class_shape_map.prototype.shape_value_get = function () { |
|
4011 |
+ return this.shape_value; |
|
4012 |
+ }; |
|
4013 |
+ /** |
|
4014 |
+ * @override |
|
4015 |
+ * @author fenris |
|
4016 |
+ */ |
|
4017 |
+ class_shape_map.prototype.inspect = function (value) { |
|
4018 |
+ var _this = this; |
|
4019 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
4020 |
+ if (value != null) { |
|
4021 |
+ if (typeof (value) != "object") { |
|
4022 |
+ messages.push("value is not an object"); |
|
4023 |
+ } |
|
4024 |
+ else { |
|
4025 |
+ Object.keys(value).forEach(function (key, index) { |
|
4026 |
+ var value_ = value[key]; |
|
4027 |
+ messages = messages.concat(_this.shape_key.inspect(key).map(function (message) { return "map entry #" + index.toString() + " key: " + message; })); |
|
4028 |
+ messages = messages.concat(_this.shape_value.inspect(value_).map(function (message) { return "map entry #" + index.toString() + " value: " + message; })); |
|
4029 |
+ }); |
|
4030 |
+ } |
|
4031 |
+ } |
|
4032 |
+ return messages; |
|
4033 |
+ }; |
|
4034 |
+ /** |
|
4035 |
+ * @override |
|
4036 |
+ * @author fenris |
|
4037 |
+ */ |
|
4038 |
+ class_shape_map.prototype.to_raw = function () { |
|
4039 |
+ return { |
|
4040 |
+ "id": "map", |
|
4041 |
+ "parameters": { |
|
4042 |
+ "shape_key": this.shape_key.to_raw(), |
|
4043 |
+ "shape_value": this.shape_value.to_raw(), |
|
4044 |
+ "soft": this.soft |
|
4045 |
+ } |
|
4046 |
+ }; |
|
4047 |
+ }; |
|
4048 |
+ /** |
|
4049 |
+ * @desc [implementation] |
|
4050 |
+ * @author fenris |
|
4051 |
+ */ |
|
4052 |
+ class_shape_map.prototype._show = function () { |
|
4053 |
+ var str = "map"; |
|
4054 |
+ str += "<" + instance_show(this.shape_key) + "," + instance_show(this.shape_value) + ">"; |
|
4055 |
+ return str; |
|
4056 |
+ }; |
|
4057 |
+ return class_shape_map; |
|
4058 |
+ }(lib_meta.class_shape)); |
|
4059 |
+ lib_meta.class_shape_map = class_shape_map; |
|
4060 |
+ lib_meta.register("map", function (parameters) { |
|
4061 |
+ var shape_key_raw = lib_object.fetch(parameters, "shape_key", null, 2); |
|
4062 |
+ var shape_key = lib_meta.construct(shape_key_raw.id, shape_key_raw.parameters); |
|
4063 |
+ var shape_value_raw = lib_object.fetch(parameters, "shape_value", null, 2); |
|
4064 |
+ var shape_value = lib_meta.from_raw(shape_value_raw); |
|
4065 |
+ return (new class_shape_map({ |
|
4066 |
+ "shape_key": shape_key, |
|
4067 |
+ "shape_value": shape_value, |
|
4068 |
+ "soft": parameters["soft"] |
|
4069 |
+ })); |
|
4070 |
+ }); |
|
4071 |
+})(lib_meta || (lib_meta = {})); |
|
4072 |
+var lib_meta; |
|
4073 |
+(function (lib_meta) { |
|
4074 |
+ /** |
|
4075 |
+ * @author fenris |
|
4076 |
+ */ |
|
4077 |
+ var class_shape_function = (function (_super) { |
|
4078 |
+ __extends(class_shape_function, _super); |
|
4079 |
+ /** |
|
4080 |
+ * @author fenris |
|
4081 |
+ */ |
|
4082 |
+ function class_shape_function(_a) { |
|
4083 |
+ var shape_input = _a["shape_input"], shape_output = _a["shape_output"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? {} : _c; |
|
4084 |
+ var _this = _super.call(this, { |
|
4085 |
+ "primitive": true, |
|
4086 |
+ "soft": soft, |
|
4087 |
+ "defaultvalue": defaultvalue |
|
4088 |
+ }) || this; |
|
4089 |
+ _this.shape_input = shape_input; |
|
4090 |
+ _this.shape_output = shape_output; |
|
4091 |
+ return _this; |
|
4092 |
+ } |
|
4093 |
+ /** |
|
4094 |
+ * @desc [accessor] [getter] |
|
4095 |
+ * @author fenris |
|
4096 |
+ */ |
|
4097 |
+ class_shape_function.prototype.shape_input_get = function () { |
|
4098 |
+ return this.shape_input; |
|
4099 |
+ }; |
|
4100 |
+ /** |
|
4101 |
+ * @desc [accessor] [getter] |
|
4102 |
+ * @author fenris |
|
4103 |
+ */ |
|
4104 |
+ class_shape_function.prototype.shape_output_get = function () { |
|
4105 |
+ return this.shape_output; |
|
4106 |
+ }; |
|
4107 |
+ /** |
|
4108 |
+ * @override |
|
4109 |
+ * @author fenris |
|
4110 |
+ */ |
|
4111 |
+ class_shape_function.prototype.inspect = function (value) { |
|
4112 |
+ var messages = _super.prototype.inspect.call(this, value); |
|
4113 |
+ if (value != null) { |
|
4114 |
+ if (typeof (value) != "function") { |
|
4115 |
+ messages.push("value is not an object"); |
|
4116 |
+ } |
|
4117 |
+ else { |
|
4118 |
+ } |
|
4119 |
+ } |
|
4120 |
+ return messages; |
|
4121 |
+ }; |
|
4122 |
+ /** |
|
4123 |
+ * @override |
|
4124 |
+ * @author fenris |
|
4125 |
+ */ |
|
4126 |
+ class_shape_function.prototype.to_raw = function () { |
|
4127 |
+ return { |
|
4128 |
+ "id": "function", |
|
4129 |
+ "parameters": { |
|
4130 |
+ "shape_input": this.shape_input.to_raw(), |
|
4131 |
+ "shape_output": this.shape_output.to_raw(), |
|
4132 |
+ "soft": this.soft |
|
4133 |
+ } |
|
4134 |
+ }; |
|
4135 |
+ }; |
|
4136 |
+ /** |
|
4137 |
+ * @desc [implementation] |
|
4138 |
+ * @author fenris |
|
4139 |
+ */ |
|
4140 |
+ class_shape_function.prototype._show = function () { |
|
4141 |
+ var str = "function"; |
|
4142 |
+ str += "<" + instance_show(this.shape_input) + "," + instance_show(this.shape_output) + ">"; |
|
4143 |
+ return str; |
|
4144 |
+ }; |
|
4145 |
+ return class_shape_function; |
|
4146 |
+ }(lib_meta.class_shape)); |
|
4147 |
+ lib_meta.class_shape_function = class_shape_function; |
|
4148 |
+ lib_meta.register("function", function (parameters) { |
|
4149 |
+ var shape_input_raw = lib_object.fetch(parameters, "shape_input", null, 2); |
|
4150 |
+ var shape_input = lib_meta.construct(shape_input_raw.id, shape_input_raw.parameters); |
|
4151 |
+ var shape_output_raw = lib_object.fetch(parameters, "shape_output", null, 2); |
|
4152 |
+ var shape_output = lib_meta.from_raw(shape_output_raw); |
|
4153 |
+ return (new class_shape_function({ |
|
4154 |
+ "shape_input": shape_input, |
|
4155 |
+ "shape_output": shape_output, |
|
4156 |
+ "soft": parameters["soft"] |
|
4157 |
+ })); |
|
4158 |
+ }); |
|
4159 |
+})(lib_meta || (lib_meta = {})); |
|
4160 |
+var lib_meta; |
|
4161 |
+(function (lib_meta) { |
|
4162 |
+ /** |
|
4163 |
+ * @author fenris |
|
4164 |
+ * @todo use a treemap-function (but first make one :P) |
|
4165 |
+ */ |
|
4166 |
+ function adjust_labels(shape, transformator) { |
|
4167 |
+ if (false) { |
|
4168 |
+ } |
|
4169 |
+ else if (shape instanceof lib_meta.class_shape_enumeration) { |
|
4170 |
+ var shape_ = (shape); |
|
4171 |
+ return (new lib_meta.class_shape_enumeration({ |
|
4172 |
+ "shape_option": adjust_labels(shape_.shape_option_get(), transformator), |
|
4173 |
+ "options": shape_.options_get().map(function (option) { |
|
4174 |
+ return { |
|
4175 |
+ "value": option.value, |
|
4176 |
+ "label": transformator(option.label) |
|
4177 |
+ }; |
|
4178 |
+ }), |
|
4179 |
+ "soft": shape_.soft_get(), |
|
4180 |
+ "defaultvalue": shape_.defaultvalue_get() |
|
4181 |
+ })); |
|
4182 |
+ } |
|
4183 |
+ else if (shape instanceof lib_meta.class_shape_array) { |
|
4184 |
+ var shape_ = (shape); |
|
4185 |
+ return (new lib_meta.class_shape_array({ |
|
4186 |
+ "shape_element": adjust_labels(shape_.shape_element_get(), transformator), |
|
4187 |
+ "soft": shape_.soft_get(), |
|
4188 |
+ "defaultvalue": shape_.defaultvalue_get() |
|
4189 |
+ })); |
|
4190 |
+ } |
|
4191 |
+ else if (shape instanceof lib_meta.class_shape_object) { |
|
4192 |
+ var shape_ = (shape); |
|
4193 |
+ return (new lib_meta.class_shape_object({ |
|
4194 |
+ "fields": shape_.fields_get().map(function (field) { |
|
4195 |
+ return { |
|
4196 |
+ "name": field.name, |
|
4197 |
+ "shape": adjust_labels(field.shape, transformator), |
|
4198 |
+ "label": transformator(field.label) |
|
4199 |
+ }; |
|
4200 |
+ }), |
|
4201 |
+ "soft": shape_.soft_get(), |
|
4202 |
+ "defaultvalue": shape_.defaultvalue_get() |
|
4203 |
+ })); |
|
4204 |
+ } |
|
4205 |
+ else { |
|
4206 |
+ // shape["label"] = ((shape["label"] == null) ? null : transformator(shape["label"])); |
|
4207 |
+ return shape; |
|
4208 |
+ } |
|
4209 |
+ } |
|
4210 |
+ lib_meta.adjust_labels = adjust_labels; |
|
4211 |
+})(lib_meta || (lib_meta = {})); |
|
4212 |
+var plain_text_to_html = function (text) { |
|
4213 |
+ var ret = text; |
|
4214 |
+ ret = ret.replace(/ /g, " "); // convert multiple whitespace to forced ones |
|
4215 |
+ ret = ret.split("\n").join("<br/>"); |
|
4216 |
+ return ret; |
|
4217 |
+}; |
|
4218 |
+/** |
|
4219 |
+ * @desc makes a valid |
|
4220 |
+ */ |
|
4221 |
+var format_sentence = function (str, rtl, caseSense) { |
|
4222 |
+ if (rtl === void 0) { rtl = false; } |
|
4223 |
+ if (caseSense === void 0) { caseSense = true; } |
|
4224 |
+ if (str === "") { |
|
4225 |
+ return str; |
|
4226 |
+ } |
|
4227 |
+ else { |
|
4228 |
+ var marks = { |
|
4229 |
+ ".": true, |
|
4230 |
+ "?": true, |
|
4231 |
+ "!": true |
|
4232 |
+ }; |
|
4233 |
+ var default_mark = "."; |
|
4234 |
+ var ret = str.split(""); |
|
4235 |
+ if (!rtl) { |
|
4236 |
+ ret[0] = ret[0].toLocaleUpperCase(); |
|
4237 |
+ if (!(ret[ret.length - 1] in marks)) { |
|
4238 |
+ ret.push(default_mark); |
|
4239 |
+ } |
|
4240 |
+ } |
|
4241 |
+ else { |
|
4242 |
+ ret[ret.length - 1] = ret[ret.length - 1].toLocaleUpperCase(); |
|
4243 |
+ if (!(ret[0] in marks)) { |
|
4244 |
+ ret.unshift(default_mark); |
|
4245 |
+ } |
|
4246 |
+ } |
|
4247 |
+ return ret.join(""); |
|
4248 |
+ } |
|
4249 |
+}; |
|
4250 |
+var fill_string_template = function (template_string, object, fabric, delimiter, default_string, sloppy) { |
|
4251 |
+ if (fabric === void 0) { fabric = function (object, key) { return object[key]; }; } |
|
4252 |
+ if (delimiter === void 0) { delimiter = "%"; } |
|
4253 |
+ if (default_string === void 0) { default_string = null; } |
|
4254 |
+ function get_tags(str) { |
|
4255 |
+ var r = new RegExp(delimiter + "[^\\s^" + delimiter + "]+" + delimiter, "gi"); |
|
4256 |
+ return ((str.match(r) || []).map(function (e) { |
|
4257 |
+ return e.slice(delimiter.length, e.length - delimiter.length); |
|
4258 |
+ })); |
|
4259 |
+ } |
|
4260 |
+ function replace_tag(str, tag, value) { |
|
4261 |
+ var r = new RegExp(delimiter + tag + delimiter, "gi"); |
|
4262 |
+ return str.replace(r, value); |
|
4263 |
+ } |
|
4264 |
+ function replace_tags(str, obj) { |
|
4265 |
+ return (get_tags(str).reduce(function (ret, key) { |
|
4266 |
+ var value = ""; |
|
4267 |
+ try { |
|
4268 |
+ value = fabric(obj, key); |
|
4269 |
+ if ((!sloppy && (value === void 0)) || (sloppy && (value == void 0))) { |
|
4270 |
+ value = default_string; |
|
4271 |
+ } |
|
4272 |
+ } |
|
4273 |
+ catch (e) { |
|
4274 |
+ console.warn("invalid placeholder " + key); |
|
4275 |
+ value = default_string; |
|
4276 |
+ } |
|
4277 |
+ return replace_tag(ret, key, value); |
|
4278 |
+ }, str)); |
|
4279 |
+ } |
|
4280 |
+ return replace_tags(template_string, object); |
|
4281 |
+}; |
|
4282 |
+var make_string_template = function (_template, _fabrics) { |
|
4283 |
+ if (_fabrics === void 0) { _fabrics = {}; } |
|
4284 |
+ function replace_tag(str, tag, value) { |
|
4285 |
+ var r = new RegExp("%" + tag + "%", "gi"); |
|
4286 |
+ return str.replace(r, value); |
|
4287 |
+ } |
|
4288 |
+ function replace_tags(str, obj) { |
|
4289 |
+ return (Object.keys(obj).reduce(function (ret, key) { |
|
4290 |
+ return replace_tag(ret, key, _fabrics[key] || obj[key]); |
|
4291 |
+ }, str)); |
|
4292 |
+ } |
|
4293 |
+ return (function (tags) { |
|
4294 |
+ return replace_tags(_template, tags); |
|
4295 |
+ }); |
|
4296 |
+}; |
|
4297 |
+var make_eml_header = (function () { |
|
4298 |
+ var _template = ""; |
|
4299 |
+ _template += "From: %from%\n"; |
|
4300 |
+ _template += "To: %recipient%\n"; |
|
4301 |
+ _template += "Subject: %subject%\n"; |
|
4302 |
+ _template += "X-Mailer: greenscale-plankton.emlgen\n"; |
|
4303 |
+ return make_string_template(_template); |
|
4304 |
+})(); |
|
4305 |
+var make_eml_body = (function () { |
|
4306 |
+ var exports = {}; |
|
4307 |
+ exports["simple_body"] = make_string_template("Content-Type: %contenttype%\n\n%body%\n\n"); |
|
4308 |
+ // very basic implementation |
|
4309 |
+ // parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}] |
|
4310 |
+ exports["body_boundrary"] = function (parts, boundrary) { |
|
4311 |
+ var _template = ""; |
|
4312 |
+ _template += "--%boundrary%\n"; |
|
4313 |
+ _template += "Content-Type: %contenttype%\n\n%body%\n\n"; |
|
4314 |
+ //_template += "--%boundrary%--\n\n"; |
|
4315 |
+ var maker = make_string_template(_template); |
|
4316 |
+ return (parts.reduce(function (prev, curr) { |
|
4317 |
+ curr.boundrary = boundrary; |
|
4318 |
+ return [prev, maker(curr)].join(""); |
|
4319 |
+ }, "")); |
|
4320 |
+ }; |
|
4321 |
+ // body must be base64 encoded! |
|
4322 |
+ exports["attachment_boundrary"] = function (parts, boundrary) { |
|
4323 |
+ var _template = ""; |
|
4324 |
+ _template += "--%boundrary%\n"; |
|
4325 |
+ _template += "Content-Type: %contenttype%\n"; |
|
4326 |
+ _template += "Content-Transfer-Encoding: base64\n"; |
|
4327 |
+ _template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n"; |
|
4328 |
+ _template += "%body%\n\n"; |
|
4329 |
+ //_template += "--%boundrary%--\n\n"; |
|
4330 |
+ var maker = make_string_template(_template); |
|
4331 |
+ return (parts.reduce(function (prev, curr) { |
|
4332 |
+ curr.boundrary = boundrary; |
|
4333 |
+ if (curr.disposition === void 0) |
|
4334 |
+ curr.disposition = "inline"; |
|
4335 |
+ return [prev, maker(curr)].join(""); |
|
4336 |
+ }, "")); |
|
4337 |
+ }; |
|
4338 |
+ exports["gen_boundrary"] = function () { |
|
4339 |
+ return ("xxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) { |
|
4340 |
+ var r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8); |
|
4341 |
+ return v.toString(16); |
|
4342 |
+ })); |
|
4343 |
+ }; |
|
4344 |
+ // simple implementation without alternatives (old rfc) |
|
4345 |
+ exports["complete_boundrary"] = function (bodyparts, attachments) { |
|
4346 |
+ var ret = ""; |
|
4347 |
+ var boundrary = exports["gen_boundrary"](); |
|
4348 |
+ ret += exports["body_boundrary"](bodyparts, boundrary); |
|
4349 |
+ ret += exports["attachment_boundrary"](attachments, boundrary); |
|
4350 |
+ ret += "--" + boundrary + "--\n\nINVISIBLE!!!!"; |
|
4351 |
+ return (exports["simple_body"]({ |
|
4352 |
+ "contenttype": sprintf("multipart/mixed; boundary=%s", [boundrary]), |
|
4353 |
+ "body": ret |
|
4354 |
+ })); |
|
4355 |
+ }; |
|
4356 |
+ return exports; |
|
4357 |
+})(); |
|
4358 |
+///<reference path="../../base/build/logic-decl.d.ts"/> |
|
4359 |
+var lib_string; |
|
4360 |
+(function (lib_string) { |
|
4361 |
+ /** |
|
4362 |
+ * @author frac |
|
4363 |
+ */ |
|
4364 |
+ var hexdigits = 4; |
|
4365 |
+ /** |
|
4366 |
+ * @author frac |
|
4367 |
+ */ |
|
4368 |
+ var index_max = 1 << (4 * hexdigits); |
|
4369 |
+ /** |
|
4370 |
+ * @author frac |
|
4371 |
+ */ |
|
4372 |
+ var index_is = 0; |
|
4373 |
+ /** |
|
4374 |
+ * @author neuc,frac |
|
4375 |
+ */ |
|
4376 |
+ function empty(str) { |
|
4377 |
+ var tmp = str.trim(); |
|
4378 |
+ return (tmp === ""); |
|
4379 |
+ } |
|
4380 |
+ lib_string.empty = empty; |
|
4381 |
+ /** |
|
4382 |
+ * @desc returns a unique string |
|
4383 |
+ * @param {string} prefix an optional prefix for the generated string |
|
4384 |
+ * @return {string} |
|
4385 |
+ * @author frac |
|
4386 |
+ */ |
|
4387 |
+ function generate(prefix) { |
|
4388 |
+ if (prefix === void 0) { prefix = "string_"; } |
|
4389 |
+ if (index_is > index_max) { |
|
4390 |
+ throw (new Error("[string_generate] out of valid indices")); |
|
4391 |
+ } |
|
4392 |
+ else { |
|
4393 |
+ return lib_string.sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]); |
|
4394 |
+ } |
|
4395 |
+ } |
|
4396 |
+ lib_string.generate = generate; |
|
4397 |
+ /** |
|
4398 |
+ * @desc splits a string, but returns an empty list, if the string is empty |
|
4399 |
+ * @param {string} chain |
|
4400 |
+ * @param {string} separator |
|
4401 |
+ * @return {Array<string>} |
|
4402 |
+ * @author frac |
|
4403 |
+ */ |
|
4404 |
+ function split(chain, separator) { |
|
4405 |
+ if (separator === void 0) { separator = " "; } |
|
4406 |
+ if (chain.length == 0) { |
|
4407 |
+ return []; |
|
4408 |
+ } |
|
4409 |
+ else { |
|
4410 |
+ return chain.split(separator); |
|
4411 |
+ } |
|
4412 |
+ } |
|
4413 |
+ lib_string.split = split; |
|
4414 |
+ /** |
|
4415 |
+ * @desc concats a given word with itself n times |
|
4416 |
+ * @param {string} word |
|
4417 |
+ * @param {int} |
|
4418 |
+ * @return {string} |
|
4419 |
+ * @author frac |
|
4420 |
+ */ |
|
4421 |
+ function repeat(word, count) { |
|
4422 |
+ return ((count == 0) ? "" : (word + repeat(word, count - 1))); |
|
4423 |
+ } |
|
4424 |
+ lib_string.repeat = repeat; |
|
4425 |
+ /** |
|
4426 |
+ * @desc lengthens a string by repeatedly appending or prepending another string |
|
4427 |
+ * @param {string} word the string to pad |
|
4428 |
+ * @param {int} length the length, which the result shall have |
|
4429 |
+ * @param {string} symbol the string, which will be added (multiple times) |
|
4430 |
+ * @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false |
|
4431 |
+ * @return {string} the padded string |
|
4432 |
+ * @author frac |
|
4433 |
+ */ |
|
4434 |
+ function pad(word, length, symbol, prepend) { |
|
4435 |
+ if (prepend === void 0) { prepend = false; } |
|
4436 |
+ if (prepend) { |
|
4437 |
+ while (word.length < length) |
|
4438 |
+ word = symbol + word; |
|
4439 |
+ return word.substring(word.length - length); |
|
4440 |
+ } |
|
4441 |
+ else { |
|
4442 |
+ while (word.length < length) |
|
4443 |
+ word = word + symbol; |
|
4444 |
+ return word.substring(0, length); |
|
4445 |
+ } |
|
4446 |
+ } |
|
4447 |
+ lib_string.pad = pad; |
|
4448 |
+ /** |
|
4449 |
+ * @desc checks if a given string conttains a certain substring |
|
4450 |
+ * @param {string} string |
|
4451 |
+ * @param {string} part |
|
4452 |
+ * @return {boolean} |
|
4453 |
+ * @author frac |
|
4454 |
+ */ |
|
4455 |
+ function contains(chain, part) { |
|
4456 |
+ if (typeof (chain) !== "string") |
|
4457 |
+ return false; |
|
4458 |
+ return (chain.indexOf(part) >= 0); |
|
4459 |
+ } |
|
4460 |
+ lib_string.contains = contains; |
|
4461 |
+ /** |
|
4462 |
+ * @desc checks if a given string starts with a certain substring |
|
4463 |
+ * @param {string} string |
|
4464 |
+ * @param {string} part |
|
4465 |
+ * @return {boolean} |
|
4466 |
+ * @author frac |
|
4467 |
+ */ |
|
4468 |
+ function startsWith(chain, part) { |
|
4469 |
+ if (typeof (chain) !== "string") |
|
4470 |
+ return false; |
|
4471 |
+ // return (string.indexOf(part) === 0); |
|
4472 |
+ return ((function (m, n) { |
|
4473 |
+ if (n == 0) { |
|
4474 |
+ return true; |
|
4475 |
+ } |
|
4476 |
+ else { |
|
4477 |
+ if (m == 0) { |
|
4478 |
+ return false; |
|
4479 |
+ } |
|
4480 |
+ else { |
|
4481 |
+ return ((chain[0] == part[0]) && startsWith(chain.substring(1), part.substring(1))); |
|
4482 |
+ } |
|
4483 |
+ } |
|
4484 |
+ })(chain.length, part.length)); |
|
4485 |
+ } |
|
4486 |
+ lib_string.startsWith = startsWith; |
|
4487 |
+ /** |
|
4488 |
+ * @desc checks if a given string ends with a certain substring |
|
4489 |
+ * @param {string} string |
|
4490 |
+ * @param {string} part |
|
4491 |
+ * @return {boolean} |
|
4492 |
+ * @author frac |
|
4493 |
+ */ |
|
4494 |
+ function endsWith(chain, part) { |
|
4495 |
+ if (typeof (chain) !== "string") |
|
4496 |
+ return false; |
|
4497 |
+ // return (string.lastIndexOf(part) === string.length-part.length); |
|
4498 |
+ return ((function (m, n) { |
|
4499 |
+ if (n == 0) { |
|
4500 |
+ return true; |
|
4501 |
+ } |
|
4502 |
+ else { |
|
4503 |
+ if (m == 0) { |
|
4504 |
+ return false; |
|
4505 |
+ } |
|
4506 |
+ else { |
|
4507 |
+ // console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1])); |
|
4508 |
+ return ((chain[m - 1] == part[n - 1]) && endsWith(chain.substring(0, m - 1), part.substring(0, n - 1))); |
|
4509 |
+ } |
|
4510 |
+ } |
|
4511 |
+ })(chain.length, part.length)); |
|
4512 |
+ } |
|
4513 |
+ lib_string.endsWith = endsWith; |
|
4514 |
+ /** |
|
4515 |
+ * @desc count the occourrences of a string in a string |
|
4516 |
+ * @param string haystack_string the string wich should be examined |
|
4517 |
+ * @param string needle_string the string which should be counted |
|
4518 |
+ * @author neuc |
|
4519 |
+ */ |
|
4520 |
+ function count_occourrences(haystack_string, needle_string, check_escape) { |
|
4521 |
+ var cnt = 0; |
|
4522 |
+ var pos = -1; |
|
4523 |
+ do { |
|
4524 |
+ pos = haystack_string.indexOf(needle_string, pos + 1); |
|
4525 |
+ if ((!check_escape) || (haystack_string[pos - 1] != "\\")) { |
|
4526 |
+ cnt++; |
|
4527 |
+ } |
|
4528 |
+ } while (pos >= 0); |
|
4529 |
+ return cnt - 1; |
|
4530 |
+ } |
|
4531 |
+ lib_string.count_occourrences = count_occourrences; |
|
4532 |
+ ; |
|
4533 |
+ /** |
|
4534 |
+ * @author fenris |
|
4535 |
+ */ |
|
4536 |
+ function stance(str, args) { |
|
4537 |
+ Object.keys(args).forEach(function (key) { |
|
4538 |
+ var value = args[key]; |
|
4539 |
+ var regexp_argument = new RegExp("\\${" + key + "}"); |
|
4540 |
+ str = str.replace(regexp_argument, value); |
|
4541 |
+ }); |
|
4542 |
+ return str; |
|
4543 |
+ } |
|
4544 |
+ lib_string.stance = stance; |
|
4545 |
+ /** |
|
4546 |
+ * @author fenris |
|
4547 |
+ */ |
|
4548 |
+ function make_url(_a) { |
|
4549 |
+ var _b = _a === void 0 ? {} : _a, _c = _b["protocol"], protocol = _c === void 0 ? null : _c, _d = _b["host"], host = _d === void 0 ? null : _d, _e = _b["port"], port = _e === void 0 ? null : _e, _f = _b["path"], path = _f === void 0 ? null : _f, _g = _b["arguments"], arguments_ = _g === void 0 ? null : _g; |
|
4550 |
+ var url = ""; |
|
4551 |
+ // protocol |
|
4552 |
+ { |
|
4553 |
+ if (protocol != null) { |
|
4554 |
+ url = protocol + ":" + url; |
|
4555 |
+ } |
|
4556 |
+ } |
|
4557 |
+ // host |
|
4558 |
+ { |
|
4559 |
+ if (host != null) { |
|
4560 |
+ url = url + "//" + host; |
|
4561 |
+ } |
|
4562 |
+ } |
|
4563 |
+ // port |
|
4564 |
+ { |
|
4565 |
+ if (port != null) { |
|
4566 |
+ url = url + ":" + port.toString(); |
|
4567 |
+ } |
|
4568 |
+ } |
|
4569 |
+ // path |
|
4570 |
+ { |
|
4571 |
+ if (path != null) { |
|
4572 |
+ url = url + "/" + path; |
|
4573 |
+ } |
|
4574 |
+ } |
|
4575 |
+ // arguments |
|
4576 |
+ { |
|
4577 |
+ if (arguments_ != null) { |
|
4578 |
+ var suffix = Object.keys(arguments_).map(function (key) { return key + "=" + arguments_[key]; }).join("&"); |
|
4579 |
+ url = url + "?" + suffix; |
|
4580 |
+ } |
|
4581 |
+ } |
|
4582 |
+ return url; |
|
4583 |
+ } |
|
4584 |
+ lib_string.make_url = make_url; |
|
4585 |
+})(lib_string || (lib_string = {})); |
|
4586 |
+/** |
|
4587 |
+ * @desc adapters for old syntax |
|
4588 |
+ */ |
|
4589 |
+var string_generate = lib_string.generate; |
|
4590 |
+var string_split = lib_string.split; |
|
4591 |
+var string_repeat = lib_string.repeat; |
|
4592 |
+var string_pad = lib_string.pad; |
|
4593 |
+var string_contains = lib_string.contains; |
|
4594 |
+var string_startsWith = lib_string.startsWith; |
|
4595 |
+var string_endsWith = lib_string.endsWith; |
|
4596 |
+var string_count_occourrences = lib_string.count_occourrences; |
|
4597 |
+var lib_string; |
|
4598 |
+(function (lib_string) { |
|
4599 |
+ var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/; |
|
4600 |
+ var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g; |
|
4601 |
+ function split_format(format) { |
|
4602 |
+ var tmp = format.match(pattern); |
|
4603 |
+ if (tmp === null) |
|
4604 |
+ return null; |
|
4605 |
+ return { |
|
4606 |
+ 'flags': tmp[1].split(""), |
|
4607 |
+ 'width': Number(tmp[2]), |
|
4608 |
+ 'precision': tmp[3] === '' ? null : Number(tmp[3]), |
|
4609 |
+ 'specifier': tmp[4], |
|
4610 |
+ 'string': format |
|
4611 |
+ }; |
|
4612 |
+ } |
|
4613 |
+ function make_err(format, arg, should) { |
|
4614 |
+ return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!"); |
|
4615 |
+ } |
|
4616 |
+ function test_arg(format, arg, should) { |
|
4617 |
+ if (typeof arg !== should) { |
|
4618 |
+ console.warn(make_err(format, arg, should)); |
|
4619 |
+ return false; |
|
4620 |
+ } |
|
4621 |
+ return true; |
|
4622 |
+ } |
|
4623 |
+ function string_fill(str, char, len, left) { |
|
4624 |
+ while (str.length < len) { |
|
4625 |
+ if (left) { |
|
4626 |
+ str += char; |
|
4627 |
+ } |
|
4628 |
+ else { |
|
4629 |
+ str = char + str; |
|
4630 |
+ } |
|
4631 |
+ } |
|
4632 |
+ return str; |
|
4633 |
+ } |
|
4634 |
+ /** |
|
4635 |
+ * the known_parameters are used to parse the different identifiers for the welln known syntax: |
|
4636 |
+ * flag width precision identifier |
|
4637 |
+ * %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn] |
|
4638 |
+ * flags: |
|
4639 |
+ * 0 - fill with '0' instead of ' ' if the string length < width |
|
4640 |
+ * # - not implemented |
|
4641 |
+ * - - left-justified -> fill on the right side to reach width |
|
4642 |
+ * + - force using '+' on positive numbers |
|
4643 |
+ * ' ' - add a single space before positive numbers |
|
4644 |
+ * |
|
4645 |
+ * identifiers |
|
4646 |
+ * %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the |
|
4647 |
+ * resulting string is too short, precision: cut more then given decimal places |
|
4648 |
+ * %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision: |
|
4649 |
+ * fill with '0' on right side until length given in precision is reached |
|
4650 |
+ * %e - interpret as float and write as scientifical number, width & precision like in float |
|
4651 |
+ * %E - same es %e but uppercase 'E' |
|
4652 |
+ * %g - use the shortest string of %f or %e |
|
4653 |
+ * %G - use the shortest string of %E or %E |
|
4654 |
+ * %s - simply print a string |
|
4655 |
+ * %o - print the given number in octal notation |
|
4656 |
+ * %x - print the given number in hex notation |
|
4657 |
+ * %X - same as %x but with uppercase characters |
|
4658 |
+ * %a - alias to %x |
|
4659 |
+ * %A - alias to %X |
|
4660 |
+ * %n - just print nothing |
|
4661 |
+ * @type {{}} |
|
4662 |
+ */ |
|
4663 |
+ var known_params = {}; |
|
4664 |
+ known_params["f"] = function (format, arg) { |
|
4665 |
+ if (!test_arg(format, arg, "number")) |
|
4666 |
+ return "Ø"; |
|
4667 |
+ var tmp = Math.abs(arg); |
|
4668 |
+ var sign = (arg < 0) ? -1 : 1; |
|
4669 |
+ var tmp_result = null; |
|
4670 |
+ if (format.precision !== null) { |
|
4671 |
+ tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision); |
|
4672 |
+ var tmp_ = (tmp * sign).toString().split("."); |
|
4673 |
+ if (tmp_.length === 1) |
|
4674 |
+ tmp_.push(""); |
|
4675 |
+ tmp_[1] = string_fill(tmp_[1], "0", format.precision, true); |
|
4676 |
+ tmp_result = tmp_.join("."); |
|
4677 |
+ } |
|
4678 |
+ else { |
|
4679 |
+ tmp_result = (sign * tmp).toString(); |
|
4680 |
+ } |
|
4681 |
+ if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) { |
|
4682 |
+ tmp_result = " " + tmp; |
|
4683 |
+ } |
|
4684 |
+ else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) { |
|
4685 |
+ tmp_result = "+" + tmp; |
|
4686 |
+ } |
|
4687 |
+ tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0)); |
|
4688 |
+ return tmp_result; |
|
4689 |
+ }; |
|
4690 |
+ known_params["F"] = known_params["f"]; |
|
4691 |
+ known_params["d"] = function (format, arg) { |
|
4692 |
+ if (!test_arg(format, arg, 'number')) |
|
4693 |
+ return 'Ø'; |
|
4694 |
+ var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString(); |
|
4695 |
+ if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
4696 |
+ tmp = ' ' + tmp; |
|
4697 |
+ } |
|
4698 |
+ else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
4699 |
+ tmp = '+' + tmp; |
|
4700 |
+ } |
|
4701 |
+ tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
4702 |
+ tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false); |
|
4703 |
+ return tmp; |
|
4704 |
+ }; |
|
4705 |
+ known_params["i"] = known_params["d"]; |
|
4706 |
+ known_params["u"] = known_params["d"]; |
|
4707 |
+ known_params["e"] = function (format, arg) { |
|
4708 |
+ if (!test_arg(format, arg, 'number')) |
|
4709 |
+ return 'Ø'; |
|
4710 |
+ var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString(); |
|
4711 |
+ if (format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
4712 |
+ tmp = ' ' + tmp; |
|
4713 |
+ } |
|
4714 |
+ else if (format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
4715 |
+ tmp = '+' + tmp; |
|
4716 |
+ } |
|
4717 |
+ tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
4718 |
+ return tmp; |
|
4719 |
+ }; |
|
4720 |
+ known_params["E"] = function (format, arg) { |
|
4721 |
+ return known_params["e"](format, arg).toUpperCase(); |
|
4722 |
+ }; |
|
4723 |
+ known_params["g"] = function (format, arg) { |
|
4724 |
+ if (!test_arg(format, arg, 'number')) |
|
4725 |
+ return 'Ø'; |
|
4726 |
+ var tmpf = known_params["f"](format, arg); |
|
4727 |
+ var tmpe = known_params["e"](format, arg); |
|
4728 |
+ if (tmpf.length < tmpe.length) { |
|
4729 |
+ return tmpf; |
|
4730 |
+ } |
|
4731 |
+ else { |
|
4732 |
+ return tmpe; |
|
4733 |
+ } |
|
4734 |
+ }; |
|
4735 |
+ known_params["G"] = function (format, arg) { |
|
4736 |
+ return known_params["g"](format, arg).toUpperCase(); |
|
4737 |
+ }; |
|
4738 |
+ known_params["s"] = function (format, arg) { |
|
4739 |
+ if (!test_arg(format, arg, 'string')) |
|
4740 |
+ return 'o.O'; |
|
4741 |
+ var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg; |
|
4742 |
+ tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
4743 |
+ return tmp; |
|
4744 |
+ }; |
|
4745 |
+ known_params["o"] = function (format, arg) { |
|
4746 |
+ if (!test_arg(format, arg, 'number')) |
|
4747 |
+ return 'Ø'; |
|
4748 |
+ var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
4749 |
+ return known_params["s"](format, tmp.toString(8)); |
|
4750 |
+ }; |
|
4751 |
+ known_params["x"] = function (format, arg) { |
|
4752 |
+ if (!test_arg(format, arg, 'number')) |
|
4753 |
+ return 'Ø'; |
|
4754 |
+ var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
4755 |
+ return known_params["s"](format, tmp.toString(16)); |
|
4756 |
+ }; |
|
4757 |
+ known_params["a"] = known_params["x"]; |
|
4758 |
+ known_params["X"] = function (format, arg) { |
|
4759 |
+ if (!test_arg(format, arg, 'number')) |
|
4760 |
+ return 'Ø'; |
|
4761 |
+ return known_params["x"](format, arg).toUpperCase(); |
|
4762 |
+ }; |
|
4763 |
+ known_params["A"] = known_params["X"]; |
|
4764 |
+ known_params["c"] = function (format, arg) { |
|
4765 |
+ var tmp = ""; |
|
4766 |
+ if (typeof arg === "number") { |
|
4767 |
+ tmp = String.fromCharCode(arg); |
|
4768 |
+ } |
|
4769 |
+ else if ((typeof arg === "string") && (arg.length === 1)) { |
|
4770 |
+ tmp = arg[0]; |
|
4771 |
+ } |
|
4772 |
+ else { |
|
4773 |
+ console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!"); |
|
4774 |
+ } |
|
4775 |
+ return known_params["s"](format, tmp); |
|
4776 |
+ }; |
|
4777 |
+ known_params["n"] = function () { |
|
4778 |
+ return ""; |
|
4779 |
+ }; |
|
4780 |
+ var decompose = function (chain, regexp) { |
|
4781 |
+ var result = regexp.exec(chain); |
|
4782 |
+ if (result == null) { |
|
4783 |
+ return null; |
|
4784 |
+ } |
|
4785 |
+ else { |
|
4786 |
+ var front = chain.substring(0, result.index); |
|
4787 |
+ var back = chain.substring(result.index + result[0].length); |
|
4788 |
+ return { "front": front, "match": result[0], "back": back }; |
|
4789 |
+ } |
|
4790 |
+ }; |
|
4791 |
+ /** |
|
4792 |
+ * an implementation of c sprintf |
|
4793 |
+ * @param {string} string format string |
|
4794 |
+ * @param {array} args arguments which should be filled into |
|
4795 |
+ * @returns {string} |
|
4796 |
+ */ |
|
4797 |
+ lib_string.sprintf = function (input, args, original) { |
|
4798 |
+ if (args === void 0) { args = []; } |
|
4799 |
+ if (original === void 0) { original = null; } |
|
4800 |
+ if (original == null) |
|
4801 |
+ original = input; |
|
4802 |
+ var components = decompose(input, pattern); |
|
4803 |
+ if (components == null) { |
|
4804 |
+ if (args.length > 0) { |
|
4805 |
+ console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args); |
|
4806 |
+ } |
|
4807 |
+ return input; |
|
4808 |
+ } |
|
4809 |
+ else { |
|
4810 |
+ var arg; |
|
4811 |
+ var rest; |
|
4812 |
+ if (args.length > 0) { |
|
4813 |
+ arg = args[0]; |
|
4814 |
+ rest = args.slice(1); |
|
4815 |
+ } |
|
4816 |
+ else { |
|
4817 |
+ console.warn("[sprintf] out of arguments while formatting '" + original + "'"); |
|
4818 |
+ arg = null; |
|
4819 |
+ rest = []; |
|
4820 |
+ return input; |
|
4821 |
+ } |
|
4822 |
+ var fmt = split_format(components["match"]); |
|
4823 |
+ return (components["front"] |
|
4824 |
+ + known_params[fmt.specifier](fmt, arg) |
|
4825 |
+ + lib_string.sprintf(components["back"], rest, original)); |
|
4826 |
+ } |
|
4827 |
+ }; |
|
4828 |
+ /** |
|
4829 |
+ * an implementation of c printf |
|
4830 |
+ * @param {string} string format string |
|
4831 |
+ * @param {array} args arguments which should be filled into |
|
4832 |
+ * @returns {string} |
|
4833 |
+ */ |
|
4834 |
+ function printf(format, args) { |
|
4835 |
+ console.log(lib_string.sprintf(format, args)); |
|
4836 |
+ } |
|
4837 |
+ lib_string.printf = printf; |
|
4838 |
+})(lib_string || (lib_string = {})); |
|
4839 |
+var sprintf = lib_string.sprintf; |
|
4840 |
+var printf = lib_string.printf; |
|
4841 |
+/** |
|
4842 |
+ * @author neuc |
|
4843 |
+ */ |
|
4844 |
+var strftime; |
|
4845 |
+(function (strftime) { |
|
4846 |
+ var currentDate = new Date(); |
|
4847 |
+ var days = [ |
|
4848 |
+ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" |
|
4849 |
+ ]; |
|
4850 |
+ var months = [ |
|
4851 |
+ "January", "February", "March", "April", "May", "June", "July", "August", "September", |
|
4852 |
+ "October", "November", "December" |
|
4853 |
+ ]; |
|
4854 |
+ function set_days(day_names) { |
|
4855 |
+ days = day_names; |
|
4856 |
+ } |
|
4857 |
+ strftime.set_days = set_days; |
|
4858 |
+ function set_months(month_names) { |
|
4859 |
+ months = month_names; |
|
4860 |
+ } |
|
4861 |
+ strftime.set_months = set_months; |
|
4862 |
+ // source: https://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366 |
|
4863 |
+ function helper_dayOfYear(date) { |
|
4864 |
+ var start = new Date(date.getFullYear(), 0, 0); |
|
4865 |
+ var diff = date - start; |
|
4866 |
+ var oneDay = 1000 * 60 * 60 * 24; |
|
4867 |
+ return Math.floor(diff / oneDay); |
|
4868 |
+ } |
|
4869 |
+ // source: http://weeknumber.net/how-to/javascript |
|
4870 |
+ function helper_weekOfYear(date_) { |
|
4871 |
+ var date = new Date(date_.getTime()); |
|
4872 |
+ date.setHours(0, 0, 0, 0); |
|
4873 |
+ // Thursday in current week decides the year. |
|
4874 |
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); |
|
4875 |
+ // January 4 is always in week 1. |
|
4876 |
+ var week1 = new Date(date.getFullYear(), 0, 4); |
|
4877 |
+ // Adjust to Thursday in week 1 and count number of weeks from date to week1. |
|
4878 |
+ return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 |
|
4879 |
+ - 3 + (week1.getDay() + 6) % 7) / 7); |
|
4880 |
+ } |
|
4881 |
+ function helper_englishWeekOfYear(date) { |
|
4882 |
+ var nr = helper_weekOfYear(date); |
|
4883 |
+ if (date.getDay() === 0) { |
|
4884 |
+ nr = nr - 1; |
|
4885 |
+ } |
|
4886 |
+ return nr; |
|
4887 |
+ } |
|
4888 |
+ function set_currentDate(date) { |
|
4889 |
+ currentDate = date; |
|
4890 |
+ } |
|
4891 |
+ strftime.set_currentDate = set_currentDate; |
|
4892 |
+ function parse(format, date) { |
|
4893 |
+ if (!date) { |
|
4894 |
+ date = currentDate; |
|
4895 |
+ } |
|
4896 |
+ var ret = format; |
|
4897 |
+ var re = new RegExp("%[a-z]", "gi"); |
|
4898 |
+ var match; |
|
4899 |
+ while (match = re.exec(format)) { |
|
4900 |
+ ret = ret.replace(match[0], parse_segment(match[0], date)); |
|
4901 |
+ } |
|
4902 |
+ return ret; |
|
4903 |
+ } |
|
4904 |
+ strftime.parse = parse; |
|
4905 |
+ function parse_segment(segment, date) { |
|
4906 |
+ if (!date) { |
|
4907 |
+ date = currentDate; |
|
4908 |
+ } |
|
4909 |
+ var hm_segments = { |
|
4910 |
+ "%a": function () { return days[date.getDay()].slice(0, 3); }, |
|
4911 |
+ "%A": function () { return days[date.getDay()]; }, |
|
4912 |
+ "%b": function () { return days[date.getMonth()].slice(0, 3); }, |
|
4913 |
+ "%B": function () { return days[date.getMonth()]; }, |
|
4914 |
+ "%c": function () { return date.toLocaleString(); }, |
|
4915 |
+ "%C": function () { return Math.floor((date.getFullYear()) / 100).toString(); }, |
|
4916 |
+ "%d": function () { return sprintf("%02d", [date.getDate()]); }, |
|
4917 |
+ "%D": function () { return parse("%m/%d/%y", date); }, |
|
4918 |
+ "%e": function () { return sprintf("%2d", [date.getDate()]); }, |
|
4919 |
+ "%F": function () { return parse("%Y-%m-%d", date); }, |
|
4920 |
+ "%g": function () { return sprintf("%02d", [date.getFullYear() % 1000]); }, |
|
4921 |
+ "%G": function () { return date.getFullYear().toString(); }, |
|
4922 |
+ "%h": function () { return parse("%b", date); }, |
|
4923 |
+ "%H": function () { return sprintf("%02d", [date.getHours()]); }, |
|
4924 |
+ "%I": function () { |
|
4925 |
+ return sprintf("%02d", [ |
|
4926 |
+ (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()) |
|
4927 |
+ ]); |
|
4928 |
+ }, |
|
4929 |
+ "%j": function () { return sprintf("%03d", [helper_dayOfYear(date)]); }, |
|
4930 |
+ "%m": function () { return sprintf("%02d", [date.getMonth() + 1]); }, |
|
4931 |
+ "%M": function () { return sprintf("%02d", [date.getMinutes()]); }, |
|
4932 |
+ "%n": function () { return "\n"; }, |
|
4933 |
+ "%p": function () { return (date.getHours() > 12 ? "PM" : "AM"); }, |
|
4934 |
+ "%r": function () { return parse("%I:%M:%S %p", date); }, |
|
4935 |
+ "%R": function () { return parse("%H:%M", date); }, |
|
4936 |
+ "%S": function () { return date.getSeconds().toString(); }, |
|
4937 |
+ "%t": function () { return "\t"; }, |
|
4938 |
+ "%T": function () { return parse("%H:%M:%S", date); }, |
|
4939 |
+ "%u": function () { return sprintf("%02d", [(date.getDay() === 0 ? 7 : date.getDay())]); }, |
|
4940 |
+ "%U": function () { return sprintf("%02d", [helper_englishWeekOfYear(date)]); }, |
|
4941 |
+ "%V": function () { return sprintf("%02d", [helper_weekOfYear(date)]); }, |
|
4942 |
+ "%w": function () { return sprintf("%02d", [date.getDay().toString()]); }, |
|
4943 |
+ "%W": function () { return parse("%w", date); }, |
|
4944 |
+ "%x": function () { return parse("%m/%d/%G", date); }, |
|
4945 |
+ "%X": function () { return parse("%T", date); }, |
|
4946 |
+ "%y": function () { return parse("%g", date); }, |
|
4947 |
+ "%Y": function () { return parse("%G", date); }, |
|
4948 |
+ "%z": function () { return date.getTimezoneOffset().toString(); }, |
|
4949 |
+ "%Z": function () { return date.toUTCString().split(' ').pop(); }, |
|
4950 |
+ "%%": function () { return "%"; } |
|
4951 |
+ }; |
|
4952 |
+ if (!(segment in hm_segments)) { |
|
4953 |
+ throw "unknown format argument '" + segment + "'"; |
|
4954 |
+ } |
|
4955 |
+ return hm_segments[segment](); |
|
4956 |
+ } |
|
4957 |
+})(strftime || (strftime = {})); |
|
4958 |
+function locale_date(date, ignore_error) { |
|
4959 |
+ if (date === void 0) { date = new Date(); } |
|
4960 |
+ if (ignore_error === void 0) { ignore_error = false; } |
|
4961 |
+ if (!(date instanceof Date)) { |
|
4962 |
+ if (!ignore_error) { |
|
4963 |
+ throw new SyntaxError("date must be instance of Date"); |
|
4964 |
+ } |
|
4965 |
+ else { |
|
4966 |
+ console.warn("'" + date + "' seems not to be instance of Date try to force convert."); |
|
4967 |
+ var tmp = date; |
|
4968 |
+ date = new Date(tmp); |
|
4969 |
+ if ((date.toString() === "Invalid Date") || |
|
4970 |
+ (!(date < new Date(0)) && !(date > new Date(0)))) { |
|
4971 |
+ console.warn("conversion didn't work, returning default value"); |
|
4972 |
+ return "Ø"; |
|
4973 |
+ } |
|
4974 |
+ } |
|
4975 |
+ } |
|
4976 |
+ var conf = global_config.get_value("date") || { |
|
4977 |
+ "use_locale_date": true, |
|
4978 |
+ "format_string": "%d.%m.%Y" |
|
4979 |
+ }; |
|
4980 |
+ if (conf.use_locale_date) { |
|
4981 |
+ return date.toLocaleDateString(); |
|
4982 |
+ } |
|
4983 |
+ else { |
|
4984 |
+ return strftime.parse(conf.format_string, date); |
|
4985 |
+ } |
|
4986 |
+} |
|
4987 |
+; |
|
4988 |
+var make_logger = (function () { |
|
4989 |
+ var _loggers = {}; |
|
4990 |
+ var make_logger = function (prefix, current_loglevel) { |
|
4991 |
+ var log = []; |
|
4992 |
+ var level = [ |
|
4993 |
+ "LOG", "INFO", "WARNING", "DEBUG" |
|
4994 |
+ ]; |
|
4995 |
+ var logger = function (obj, lvl) { |
|
4996 |
+ var txt = obj.txt || obj; |
|
4997 |
+ if (lvl == void 0) |
|
4998 |
+ lvl = 0; |
|
4999 |
+ var date = new Date(); |
|
5000 |
+ log.push({ |
|
5001 |
+ "message": sprintf("%s [%s:%s] %s", [date.toString(), level[lvl], prefix, txt]), |
|
5002 |
+ "timeStamp": +(date) |
|
5003 |
+ }); |
|
5004 |
+ if (lvl <= current_loglevel) { |
|
5005 |
+ var msg = ["[" + prefix + "]", txt]; |
|
5006 |
+ if (obj.arg) |
|
5007 |
+ msg = ["[" + prefix + "]"].concat(Array.prototype.slice.call(obj.arg)); |
|
5008 |
+ if (lvl === 0) |
|
5009 |
+ console["_log"].apply(console, msg); |
|
5010 |
+ else if (lvl === 1) |
|
5011 |
+ console["_info"].apply(console, msg); |
|
5012 |
+ else if (lvl === 2) |
|
5013 |
+ console["_warn"].apply(console, msg); |
|
5014 |
+ else if (lvl >= 3) |
|
5015 |
+ console["_log"].apply(console, msg); |
|
5016 |
+ } |
|
5017 |
+ }; |
|
5018 |
+ _loggers[prefix] = { |
|
5019 |
+ "logger": logger, |
|
5020 |
+ "log": log |
|
5021 |
+ }; |
|
5022 |
+ return logger; |
|
3191 | 5023 |
}; |
3192 |
- return class_shape_date; |
|
3193 |
- }(lib_meta.class_shape)); |
|
3194 |
- lib_meta.class_shape_date = class_shape_date; |
|
3195 |
- lib_meta.register("date", function (parameters) { |
|
3196 |
- return (new class_shape_date({ |
|
3197 |
- "soft": parameters["soft"] |
|
3198 |
- })); |
|
5024 |
+ make_logger["loggers"] = _loggers; |
|
5025 |
+ make_logger["complete_log"] = function () { |
|
5026 |
+ var logs = Object.keys(_loggers) |
|
5027 |
+ .reduce(function (p, c) { |
|
5028 |
+ return [].concat(p, _loggers[c].log); |
|
5029 |
+ }, []); |
|
5030 |
+ logs.sort(function (x, y) { |
|
5031 |
+ return ((x.timeStamp > y.timeStamp) ? -1 : +1); |
|
3199 | 5032 |
}); |
3200 |
-})(lib_meta || (lib_meta = {})); |
|
3201 |
-var lib_meta; |
|
3202 |
-(function (lib_meta) { |
|
3203 |
- /** |
|
3204 |
- * @author fenris |
|
3205 |
- */ |
|
3206 |
- var class_shape_enumeration = (function (_super) { |
|
3207 |
- __extends(class_shape_enumeration, _super); |
|
3208 |
- /** |
|
3209 |
- * @author fenris |
|
3210 |
- */ |
|
3211 |
- function class_shape_enumeration(_a) { |
|
3212 |
- var shape_option = _a["shape_option"], options = _a["options"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? undefined : _c; |
|
3213 |
- var _this = this; |
|
3214 |
- if (defaultvalue === undefined) { |
|
3215 |
- if (soft) { |
|
3216 |
- defaultvalue = null; |
|
3217 |
- } |
|
3218 |
- else { |
|
3219 |
- if (options.length == 0) { |
|
3220 |
- throw (new Error("a hard enumeration must have at least one option")); |
|
5033 |
+ return logs.map(function (x, i, a) { |
|
5034 |
+ return x.message; |
|
5035 |
+ }); |
|
5036 |
+ }; |
|
5037 |
+ if (true) { |
|
5038 |
+ var _log_all = function (log, lvl, next) { |
|
5039 |
+ if (next === void 0) { next = function () { }; } |
|
5040 |
+ return function () { |
|
5041 |
+ var msg = []; |
|
5042 |
+ for (var i = 0; i < arguments.length; i++) { |
|
5043 |
+ if (typeof arguments[i] === "string") { |
|
5044 |
+ msg.push(arguments[i]); |
|
3221 | 5045 |
} |
3222 | 5046 |
else { |
3223 |
- defaultvalue = options[0].value; |
|
3224 |
- } |
|
3225 |
- } |
|
5047 |
+ msg.push(JSON.stringify(arguments[i])); |
|
3226 | 5048 |
} |
3227 |
- _this = _super.call(this, { |
|
3228 |
- "primitive": true, |
|
3229 |
- "soft": soft, |
|
3230 |
- "defaultvalue": defaultvalue |
|
3231 |
- }) || this; |
|
3232 |
- _this.shape_option = shape_option; |
|
3233 |
- _this.options = options; |
|
3234 |
- return _this; |
|
3235 | 5049 |
} |
3236 |
- /** |
|
3237 |
- * @desc [accessor] [getter] |
|
3238 |
- * @author fenris |
|
3239 |
- */ |
|
3240 |
- class_shape_enumeration.prototype.shape_option_get = function () { |
|
3241 |
- return this.shape_option; |
|
5050 |
+ var obj = { |
|
5051 |
+ txt: msg.join("\t"), |
|
5052 |
+ arg: arguments |
|
3242 | 5053 |
}; |
3243 |
- /** |
|
3244 |
- * @desc [accessor] [getter] |
|
3245 |
- * @author fenris |
|
3246 |
- */ |
|
3247 |
- class_shape_enumeration.prototype.options_get = function () { |
|
3248 |
- return this.options; |
|
5054 |
+ log(obj, lvl); |
|
5055 |
+ next(); |
|
3249 | 5056 |
}; |
3250 |
- /** |
|
3251 |
- * @override |
|
3252 |
- * @author fenris |
|
5057 |
+ }; |
|
5058 |
+ { |
|
5059 |
+ var __warn = make_logger("deprecated console.warn", 99); |
|
5060 |
+ var __error = make_logger("deprecated console.error", 99); |
|
5061 |
+ var __log = make_logger("deprecated console.log", 99); |
|
5062 |
+ var __info = make_logger("deprecated console.info", 99); |
|
5063 |
+ // bad ass |
|
5064 |
+ console["_log"] = console.log; |
|
5065 |
+ console["_error"] = console.error; |
|
5066 |
+ console["_warn"] = console.warn; |
|
5067 |
+ console["_info"] = console.info; |
|
5068 |
+ /* |
|
5069 |
+ console["log"] = _log_all(__log, 0); |
|
5070 |
+ console["error"] = _log_all(__error, 2); |
|
5071 |
+ console["warn"] = _log_all(__warn, 2); |
|
5072 |
+ console["info"] = _log_all(__info, 0); |
|
3253 | 5073 |
*/ |
3254 |
- class_shape_enumeration.prototype.inspect = function (value) { |
|
3255 |
- var messages = _super.prototype.inspect.call(this, value); |
|
3256 |
- if (value != null) { |
|
3257 |
- if (!this.shape_option.check(value)) { |
|
3258 |
- messages.push("value has not the specified option shape"); |
|
3259 | 5074 |
} |
3260 |
- else { |
|
3261 |
- var found = this.options.some(function (option) { return instance_collate(option.value, value); }); |
|
3262 |
- if (!found) { |
|
3263 |
- messages.push("value is not one of the specified options"); |
|
5075 |
+ /* |
|
5076 |
+ { |
|
5077 |
+ make_logger["send_log"] = function(){ |
|
5078 |
+ eml_log( |
|
5079 |
+ function () { |
|
5080 |
+ alert("fehlerbericht wurde gesendet!"); |
|
5081 |
+ } |
|
5082 |
+ ); |
|
5083 |
+ }; |
|
5084 |
+ var error_log = make_logger("global.error", 99); |
|
5085 |
+ window.onerror = _log_all( |
|
5086 |
+ error_log, |
|
5087 |
+ 1, |
|
5088 |
+ function(){ |
|
5089 |
+ if (global_config == undefined) { |
|
5090 |
+ return false; |
|
5091 |
+ } |
|
5092 |
+ if (global_config.report_error) { |
|
5093 |
+ make_logger["send_log"](); |
|
3264 | 5094 |
} |
3265 | 5095 |
} |
5096 |
+ ); |
|
3266 | 5097 |
} |
3267 |
- return messages; |
|
5098 |
+ */ |
|
5099 |
+ } |
|
5100 |
+ return make_logger; |
|
5101 |
+})(); |
|
5102 |
+var __extends = (this && this.__extends) || (function () { |
|
5103 |
+ var extendStatics = Object.setPrototypeOf || |
|
5104 |
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
5105 |
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
5106 |
+ return function (d, b) { |
|
5107 |
+ extendStatics(d, b); |
|
5108 |
+ function __() { this.constructor = d; } |
|
5109 |
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
3268 | 5110 |
}; |
5111 |
+})(); |
|
5112 |
+///<reference path="../../base/build/logic-decl.d.ts"/> |
|
5113 |
+///<reference path="../../string/build/logic-decl.d.ts"/> |
|
3269 | 5114 |
/** |
3270 |
- * @override |
|
3271 | 5115 |
* @author fenris |
3272 | 5116 |
*/ |
3273 |
- class_shape_enumeration.prototype.to_raw = function () { |
|
3274 |
- return { |
|
3275 |
- "id": "enumeration", |
|
3276 |
- "parameters": { |
|
3277 |
- "shape_option": this.shape_option.to_raw(), |
|
3278 |
- "options": this.options.map(function (option) { |
|
3279 |
- return { |
|
3280 |
- "value": option.value, |
|
3281 |
- "label": option.label |
|
3282 |
- }; |
|
3283 |
- }), |
|
3284 |
- "soft": this.soft |
|
3285 |
- } |
|
3286 |
- }; |
|
3287 |
- }; |
|
5117 |
+var lib_xml; |
|
5118 |
+(function (lib_xml) { |
|
3288 | 5119 |
/** |
3289 |
- * @desc [implementation] |
|
3290 | 5120 |
* @author fenris |
3291 | 5121 |
*/ |
3292 |
- class_shape_enumeration.prototype._show = function () { |
|
3293 |
- var str = "enumeration"; |
|
3294 |
- { |
|
3295 |
- str = str + "<" + instance_show(this.shape_option) + ">"; |
|
3296 |
- } |
|
3297 |
- { |
|
3298 |
- var str_ = this.options.map(function (option) { return instance_show(option.value); }).join(","); |
|
3299 |
- str = str + "[" + str_ + "]"; |
|
5122 |
+ var class_node = (function () { |
|
5123 |
+ function class_node() { |
|
3300 | 5124 |
} |
3301 |
- return str; |
|
3302 |
- }; |
|
3303 |
- return class_shape_enumeration; |
|
3304 |
- }(lib_meta.class_shape)); |
|
3305 |
- lib_meta.class_shape_enumeration = class_shape_enumeration; |
|
3306 |
- lib_meta.register("enumeration", function (parameters) { |
|
3307 |
- var shape_option_raw = lib_object.fetch(parameters, "shape_option", null, 2); |
|
3308 |
- var shape_option = lib_meta.from_raw(shape_option_raw); |
|
3309 |
- var options = lib_object.fetch(parameters, "options", [], 2); |
|
3310 |
- return (new class_shape_enumeration({ |
|
3311 |
- "shape_option": shape_option, |
|
3312 |
- "options": options, |
|
3313 |
- "soft": parameters["soft"] |
|
3314 |
- })); |
|
3315 |
- }); |
|
3316 |
-})(lib_meta || (lib_meta = {})); |
|
3317 |
-var lib_meta; |
|
3318 |
-(function (lib_meta) { |
|
5125 |
+ return class_node; |
|
5126 |
+ }()); |
|
5127 |
+ lib_xml.class_node = class_node; |
|
3319 | 5128 |
/** |
3320 | 5129 |
* @author fenris |
3321 | 5130 |
*/ |
3322 |
- var class_shape_map = (function (_super) { |
|
3323 |
- __extends(class_shape_map, _super); |
|
5131 |
+ var class_node_text = (function (_super) { |
|
5132 |
+ __extends(class_node_text, _super); |
|
3324 | 5133 |
/** |
3325 | 5134 |
* @author fenris |
3326 | 5135 |
*/ |
3327 |
- function class_shape_map(_a) { |
|
3328 |
- var shape_key = _a["shape_key"], shape_value = _a["shape_value"], _b = _a["soft"], soft = _b === void 0 ? false : _b, _c = _a["defaultvalue"], defaultvalue = _c === void 0 ? {} : _c; |
|
3329 |
- var _this = _super.call(this, { |
|
3330 |
- "primitive": true, |
|
3331 |
- "soft": soft, |
|
3332 |
- "defaultvalue": defaultvalue |
|
3333 |
- }) || this; |
|
3334 |
- _this.shape_key = shape_key; |
|
3335 |
- _this.shape_value = shape_value; |
|
5136 |
+ function class_node_text(content) { |
|
5137 |
+ var _this = _super.call(this) || this; |
|
5138 |
+ _this.content = content; |
|
3336 | 5139 |
return _this; |
3337 | 5140 |
} |
3338 | 5141 |
/** |
3339 |
- * @desc [accessor] [getter] |
|
3340 | 5142 |
* @author fenris |
3341 | 5143 |
*/ |
3342 |
- class_shape_map.prototype.shape_key_get = function () { |
|
3343 |
- return this.shape_key; |
|
5144 |
+ class_node_text.prototype.compile = function (depth) { |
|
5145 |
+ if (depth === void 0) { depth = 0; } |
|
5146 |
+ return (lib_string.repeat("\t", depth) + this.content + "\n"); |
|
3344 | 5147 |
}; |
5148 |
+ return class_node_text; |
|
5149 |
+ }(class_node)); |
|
5150 |
+ lib_xml.class_node_text = class_node_text; |
|
3345 | 5151 |
/** |
3346 |
- * @desc [accessor] [getter] |
|
3347 | 5152 |
* @author fenris |
3348 | 5153 |
*/ |
3349 |
- class_shape_map.prototype.shape_value_get = function () { |
|
3350 |
- return this.shape_value; |
|
3351 |
- }; |
|
5154 |
+ var class_node_comment = (function (_super) { |
|
5155 |
+ __extends(class_node_comment, _super); |
|
3352 | 5156 |
/** |
3353 |
- * @override |
|
3354 | 5157 |
* @author fenris |
3355 | 5158 |
*/ |
3356 |
- class_shape_map.prototype.inspect = function (value) { |
|
3357 |
- var _this = this; |
|
3358 |
- var messages = _super.prototype.inspect.call(this, value); |
|
3359 |
- if (value != null) { |
|
3360 |
- if (typeof (value) != "object") { |
|
3361 |
- messages.push("value is not an object"); |
|
3362 |
- } |
|
3363 |
- else { |
|
3364 |
- Object.keys(value).forEach(function (key, index) { |
|
3365 |
- var value_ = value[key]; |
|
3366 |
- messages = messages.concat(_this.shape_key.inspect(key).map(function (message) { return "map entry #" + index.toString() + " key: " + message; })); |
|
3367 |
- messages = messages.concat(_this.shape_value.inspect(value).map(function (message) { return "map entry #" + index.toString() + " value: " + message; })); |
|
3368 |
- }); |
|
3369 |
- } |
|
5159 |
+ function class_node_comment(content) { |
|
5160 |
+ var _this = _super.call(this) || this; |
|
5161 |
+ _this.content = content; |
|
5162 |
+ return _this; |
|
3370 | 5163 |
} |
3371 |
- return messages; |
|
3372 |
- }; |
|
3373 | 5164 |
/** |
3374 |
- * @override |
|
3375 | 5165 |
* @author fenris |
3376 | 5166 |
*/ |
3377 |
- class_shape_map.prototype.to_raw = function () { |
|
3378 |
- return { |
|
3379 |
- "id": "map", |
|
3380 |
- "parameters": { |
|
3381 |
- "shape_key": this.shape_key.to_raw(), |
|
3382 |
- "shape_value": this.shape_value.to_raw(), |
|
3383 |
- "soft": this.soft |
|
3384 |
- } |
|
3385 |
- }; |
|
5167 |
+ class_node_comment.prototype.compile = function (depth) { |
|
5168 |
+ if (depth === void 0) { depth = 0; } |
|
5169 |
+ return (lib_string.repeat("\t", depth) + "<!-- " + this.content + " -->" + "\n"); |
|
3386 | 5170 |
}; |
5171 |
+ return class_node_comment; |
|
5172 |
+ }(class_node)); |
|
5173 |
+ lib_xml.class_node_comment = class_node_comment; |
|
3387 | 5174 |
/** |
3388 |
- * @desc [implementation] |
|
3389 | 5175 |
* @author fenris |
3390 | 5176 |
*/ |
3391 |
- class_shape_map.prototype._show = function () { |
|
3392 |
- var str = "map"; |
|
3393 |
- str += "<" + instance_show(this.shape_key) + "," + instance_show(this.shape_value) + ">"; |
|
3394 |
- return str; |
|
3395 |
- }; |
|
3396 |
- return class_shape_map; |
|
3397 |
- }(lib_meta.class_shape)); |
|
3398 |
- lib_meta.class_shape_map = class_shape_map; |
|
3399 |
- lib_meta.register("map", function (parameters) { |
|
3400 |
- var shape_key_raw = lib_object.fetch(parameters, "shape_key", null, 2); |
|
3401 |
- var shape_key = lib_meta.construct(shape_key_raw.id, shape_key_raw.parameters); |
|
3402 |
- var shape_value_raw = lib_object.fetch(parameters, "shape_value", null, 2); |
|
3403 |
- var shape_value = lib_meta.from_raw(shape_value_raw); |
|
3404 |
- return (new class_shape_map({ |
|
3405 |
- "shape_key": shape_key, |
|
3406 |
- "shape_value": shape_value, |
|
3407 |
- "soft": parameters["soft"] |
|
3408 |
- })); |
|
3409 |
- }); |
|
3410 |
-})(lib_meta || (lib_meta = {})); |
|
3411 |
-var lib_meta; |
|
3412 |
-(function (lib_meta) { |
|
5177 |
+ var class_node_complex = (function (_super) { |
|
5178 |
+ __extends(class_node_complex, _super); |
|
3413 | 5179 |
/** |
3414 | 5180 |
* @author fenris |
3415 |
- * @todo use a treemap-function (but first make one :P) |
|
3416 | 5181 |
*/ |
3417 |
- function adjust_labels(shape, transformator) { |
|
3418 |
- if (false) { |
|
3419 |
- } |
|
3420 |
- else if (shape instanceof lib_meta.class_shape_enumeration) { |
|
3421 |
- var shape_ = (shape); |
|
3422 |
- return (new lib_meta.class_shape_enumeration({ |
|
3423 |
- "shape_option": adjust_labels(shape_.shape_option_get(), transformator), |
|
3424 |
- "options": shape_.options_get().map(function (option) { |
|
3425 |
- return { |
|
3426 |
- "value": option.value, |
|
3427 |
- "label": transformator(option.label) |
|
3428 |
- }; |
|
3429 |
- }), |
|
3430 |
- "soft": shape_.soft_get(), |
|
3431 |
- "defaultvalue": shape_.defaultvalue_get() |
|
3432 |
- })); |
|
3433 |
- } |
|
3434 |
- else if (shape instanceof lib_meta.class_shape_array) { |
|
3435 |
- var shape_ = (shape); |
|
3436 |
- return (new lib_meta.class_shape_array({ |
|
3437 |
- "shape_element": adjust_labels(shape_.shape_element_get(), transformator), |
|
3438 |
- "soft": shape_.soft_get(), |
|
3439 |
- "defaultvalue": shape_.defaultvalue_get() |
|
3440 |
- })); |
|
3441 |
- } |
|
3442 |
- else if (shape instanceof lib_meta.class_shape_object) { |
|
3443 |
- var shape_ = (shape); |
|
3444 |
- return (new lib_meta.class_shape_object({ |
|
3445 |
- "fields": shape_.fields_get().map(function (field) { |
|
3446 |
- return { |
|
3447 |
- "name": field.name, |
|
3448 |
- "shape": adjust_labels(field.shape, transformator), |
|
3449 |
- "label": transformator(field.label) |
|
3450 |
- }; |
|
3451 |
- }), |
|
3452 |
- "soft": shape_.soft_get(), |
|
3453 |
- "defaultvalue": shape_.defaultvalue_get() |
|
3454 |
- })); |
|
3455 |
- } |
|
3456 |
- else { |
|
3457 |
- // shape["label"] = ((shape["label"] == null) ? null : transformator(shape["label"])); |
|
3458 |
- return shape; |
|
3459 |
- } |
|
5182 |
+ function class_node_complex(name, attributes, children) { |
|
5183 |
+ if (attributes === void 0) { attributes = {}; } |
|
5184 |
+ if (children === void 0) { children = []; } |
|
5185 |
+ var _this = _super.call(this) || this; |
|
5186 |
+ _this.name = name; |
|
5187 |
+ _this.attributes = attributes; |
|
5188 |
+ _this.children = children; |
|
5189 |
+ return _this; |
|
3460 | 5190 |
} |
3461 |
- lib_meta.adjust_labels = adjust_labels; |
|
3462 |
-})(lib_meta || (lib_meta = {})); |
|
3463 |
-var plain_text_to_html = function (text) { |
|
3464 |
- var ret = text; |
|
3465 |
- ret = ret.replace(/ /g, " "); // convert multiple whitespace to forced ones |
|
3466 |
- ret = ret.split("\n").join("<br/>"); |
|
3467 |
- return ret; |
|
3468 |
-}; |
|
3469 | 5191 |
/** |
3470 |
- * @desc makes a valid |
|
5192 |
+ * @author fenris |
|
3471 | 5193 |
*/ |
3472 |
-var format_sentence = function (str, rtl, caseSense) { |
|
3473 |
- if (rtl === void 0) { rtl = false; } |
|
3474 |
- if (caseSense === void 0) { caseSense = true; } |
|
3475 |
- if (str === "") { |
|
3476 |
- return str; |
|
3477 |
- } |
|
3478 |
- else { |
|
3479 |
- var marks = { |
|
3480 |
- ".": true, |
|
3481 |
- "?": true, |
|
3482 |
- "!": true |
|
3483 |
- }; |
|
3484 |
- var default_mark = "."; |
|
3485 |
- var ret = str.split(""); |
|
3486 |
- if (!rtl) { |
|
3487 |
- ret[0] = ret[0].toLocaleUpperCase(); |
|
3488 |
- if (!(ret[ret.length - 1] in marks)) { |
|
3489 |
- ret.push(default_mark); |
|
3490 |
- } |
|
3491 |
- } |
|
3492 |
- else { |
|
3493 |
- ret[ret.length - 1] = ret[ret.length - 1].toLocaleUpperCase(); |
|
3494 |
- if (!(ret[0] in marks)) { |
|
3495 |
- ret.unshift(default_mark); |
|
3496 |
- } |
|
3497 |
- } |
|
3498 |
- return ret.join(""); |
|
3499 |
- } |
|
3500 |
-}; |
|
3501 |
-var fill_string_template = function (template_string, object, fabric, delimiter, default_string, sloppy) { |
|
3502 |
- if (fabric === void 0) { fabric = function (object, key) { return object[key]; }; } |
|
3503 |
- if (delimiter === void 0) { delimiter = "%"; } |
|
3504 |
- if (default_string === void 0) { default_string = null; } |
|
3505 |
- function get_tags(str) { |
|
3506 |
- var r = new RegExp(delimiter + "[^\\s^" + delimiter + "]+" + delimiter, "gi"); |
|
3507 |
- return ((str.match(r) || []).map(function (e) { |
|
3508 |
- return e.slice(delimiter.length, e.length - delimiter.length); |
|
3509 |
- })); |
|
3510 |
- } |
|
3511 |
- function replace_tag(str, tag, value) { |
|
3512 |
- var r = new RegExp(delimiter + tag + delimiter, "gi"); |
|
3513 |
- return str.replace(r, value); |
|
3514 |
- } |
|
3515 |
- function replace_tags(str, obj) { |
|
3516 |
- return (get_tags(str).reduce(function (ret, key) { |
|
3517 |
- var value = ""; |
|
3518 |
- try { |
|
3519 |
- value = fabric(obj, key); |
|
3520 |
- if ((!sloppy && (value === void 0)) || (sloppy && (value == void 0))) { |
|
3521 |
- value = default_string; |
|
3522 |
- } |
|
3523 |
- } |
|
3524 |
- catch (e) { |
|
3525 |
- console.warn("invalid placeholder " + key); |
|
3526 |
- value = default_string; |
|
3527 |
- } |
|
3528 |
- return replace_tag(ret, key, value); |
|
3529 |
- }, str)); |
|
3530 |
- } |
|
3531 |
- return replace_tags(template_string, object); |
|
3532 |
-}; |
|
3533 |
-var make_string_template = function (_template, _fabrics) { |
|
3534 |
- if (_fabrics === void 0) { _fabrics = {}; } |
|
3535 |
- function replace_tag(str, tag, value) { |
|
3536 |
- var r = new RegExp("%" + tag + "%", "gi"); |
|
3537 |
- return str.replace(r, value); |
|
3538 |
- } |
|
3539 |
- function replace_tags(str, obj) { |
|
3540 |
- return (Object.keys(obj).reduce(function (ret, key) { |
|
3541 |
- return replace_tag(ret, key, _fabrics[key] || obj[key]); |
|
3542 |
- }, str)); |
|
3543 |
- } |
|
3544 |
- return (function (tags) { |
|
3545 |
- return replace_tags(_template, tags); |
|
3546 |
- }); |
|
3547 |
-}; |
|
3548 |
-var make_eml_header = (function () { |
|
3549 |
- var _template = ""; |
|
3550 |
- _template += "From: %from%\n"; |
|
3551 |
- _template += "To: %recipient%\n"; |
|
3552 |
- _template += "Subject: %subject%\n"; |
|
3553 |
- _template += "X-Mailer: greenscale-plankton.emlgen\n"; |
|
3554 |
- return make_string_template(_template); |
|
3555 |
-})(); |
|
3556 |
-var make_eml_body = (function () { |
|
3557 |
- var exports = {}; |
|
3558 |
- exports["simple_body"] = make_string_template("Content-Type: %contenttype%\n\n%body%\n\n"); |
|
3559 |
- // very basic implementation |
|
3560 |
- // parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}] |
|
3561 |
- exports["body_boundrary"] = function (parts, boundrary) { |
|
3562 |
- var _template = ""; |
|
3563 |
- _template += "--%boundrary%\n"; |
|
3564 |
- _template += "Content-Type: %contenttype%\n\n%body%\n\n"; |
|
3565 |
- //_template += "--%boundrary%--\n\n"; |
|
3566 |
- var maker = make_string_template(_template); |
|
3567 |
- return (parts.reduce(function (prev, curr) { |
|
3568 |
- curr.boundrary = boundrary; |
|
3569 |
- return [prev, maker(curr)].join(""); |
|
3570 |
- }, "")); |
|
3571 |
- }; |
|
3572 |
- // body must be base64 encoded! |
|
3573 |
- exports["attachment_boundrary"] = function (parts, boundrary) { |
|
3574 |
- var _template = ""; |
|
3575 |
- _template += "--%boundrary%\n"; |
|
3576 |
- _template += "Content-Type: %contenttype%\n"; |
|
3577 |
- _template += "Content-Transfer-Encoding: base64\n"; |
|
3578 |
- _template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n"; |
|
3579 |
- _template += "%body%\n\n"; |
|
3580 |
- //_template += "--%boundrary%--\n\n"; |
|
3581 |
- var maker = make_string_template(_template); |
|
3582 |
- return (parts.reduce(function (prev, curr) { |
|
3583 |
- curr.boundrary = boundrary; |
|
3584 |
- if (curr.disposition === void 0) |
|
3585 |
- curr.disposition = "inline"; |
|
3586 |
- return [prev, maker(curr)].join(""); |
|
3587 |
- }, "")); |
|
3588 |
- }; |
|
3589 |
- exports["gen_boundrary"] = function () { |
|
3590 |
- return ("xxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) { |
|
3591 |
- var r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8); |
|
3592 |
- return v.toString(16); |
|
3593 |
- })); |
|
5194 |
+ class_node_complex.prototype.compile = function (depth) { |
|
5195 |
+ var _this = this; |
|
5196 |
+ if (depth === void 0) { depth = 0; } |
|
5197 |
+ var output = ""; |
|
5198 |
+ var attributes = Object.keys(this.attributes).map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }).join(""); |
|
5199 |
+ output += (lib_string.repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n"); |
|
5200 |
+ this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); |
|
5201 |
+ output += (lib_string.repeat("\t", depth) + "</" + this.name + ">" + "\n"); |
|
5202 |
+ return output; |
|
3594 | 5203 |
}; |
3595 |
- // simple implementation without alternatives (old rfc) |
|
3596 |
- exports["complete_boundrary"] = function (bodyparts, attachments) { |
|
3597 |
- var ret = ""; |
|
3598 |
- var boundrary = exports["gen_boundrary"](); |
|
3599 |
- ret += exports["body_boundrary"](bodyparts, boundrary); |
|
3600 |
- ret += exports["attachment_boundrary"](attachments, boundrary); |
|
3601 |
- ret += "--" + boundrary + "--\n\nINVISIBLE!!!!"; |
|
3602 |
- return (exports["simple_body"]({ |
|
3603 |
- "contenttype": sprintf("multipart/mixed; boundary=%s", [boundrary]), |
|
3604 |
- "body": ret |
|
3605 |
- })); |
|
5204 |
+ return class_node_complex; |
|
5205 |
+ }(class_node)); |
|
5206 |
+ lib_xml.class_node_complex = class_node_complex; |
|
5207 |
+})(lib_xml || (lib_xml = {})); |
|
5208 |
+var __extends = (this && this.__extends) || (function () { |
|
5209 |
+ var extendStatics = Object.setPrototypeOf || |
|
5210 |
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
5211 |
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
5212 |
+ return function (d, b) { |
|
5213 |
+ extendStatics(d, b); |
|
5214 |
+ function __() { this.constructor = d; } |
|
5215 |
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
3606 | 5216 |
}; |
3607 |
- return exports; |
|
3608 | 5217 |
})(); |
3609 |
-///<reference path="../../base/build/logic-decl.d.ts"/> |
|
3610 |
-var lib_string; |
|
3611 |
-(function (lib_string) { |
|
5218 |
+var lib_path; |
|
5219 |
+(function (lib_path) { |
|
3612 | 5220 |
/** |
3613 |
- * @author frac |
|
5221 |
+ * @author fenris |
|
3614 | 5222 |
*/ |
3615 |
- var hexdigits = 4; |
|
5223 |
+ var class_step = (function () { |
|
5224 |
+ function class_step() { |
|
5225 |
+ } |
|
5226 |
+ return class_step; |
|
5227 |
+ }()); |
|
5228 |
+ lib_path.class_step = class_step; |
|
3616 | 5229 |
/** |
3617 |
- * @author frac |
|
5230 |
+ * @author fenris |
|
3618 | 5231 |
*/ |
3619 |
- var index_max = 1 << (4 * hexdigits); |
|
5232 |
+ var class_step_stay = (function (_super) { |
|
5233 |
+ __extends(class_step_stay, _super); |
|
5234 |
+ function class_step_stay() { |
|
5235 |
+ return _super !== null && _super.apply(this, arguments) || this; |
|
5236 |
+ } |
|
3620 | 5237 |
/** |
3621 |
- * @author frac |
|
5238 |
+ * @author fenris |
|
3622 | 5239 |
*/ |
3623 |
- var index_is = 0; |
|
5240 |
+ class_step_stay.prototype.invert = function () { |
|
5241 |
+ return (new class_step_stay()); |
|
5242 |
+ }; |
|
3624 | 5243 |
/** |
3625 |
- * @author neuc,frac |
|
5244 |
+ * @author fenris |
|
3626 | 5245 |
*/ |
3627 |
- function empty(str) { |
|
3628 |
- var tmp = str.trim(); |
|
3629 |
- return (tmp === ""); |
|
3630 |
- } |
|
3631 |
- lib_string.empty = empty; |
|
5246 |
+ class_step_stay.prototype.toString = function () { |
|
5247 |
+ return "."; |
|
5248 |
+ }; |
|
5249 |
+ return class_step_stay; |
|
5250 |
+ }(class_step)); |
|
5251 |
+ lib_path.class_step_stay = class_step_stay; |
|
3632 | 5252 |
/** |
3633 |
- * @desc returns a unique string |
|
3634 |
- * @param {string} prefix an optional prefix for the generated string |
|
3635 |
- * @return {string} |
|
3636 |
- * @author frac |
|
5253 |
+ * @author fenris |
|
3637 | 5254 |
*/ |
3638 |
- function generate(prefix) { |
|
3639 |
- if (prefix === void 0) { prefix = "string_"; } |
|
3640 |
- if (index_is > index_max) { |
|
3641 |
- throw (new Error("[string_generate] out of valid indices")); |
|
3642 |
- } |
|
3643 |
- else { |
|
3644 |
- return lib_string.sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]); |
|
3645 |
- } |
|
5255 |
+ var class_step_back = (function (_super) { |
|
5256 |
+ __extends(class_step_back, _super); |
|
5257 |
+ function class_step_back() { |
|
5258 |
+ return _super !== null && _super.apply(this, arguments) || this; |
|
3646 | 5259 |
} |
3647 |
- lib_string.generate = generate; |
|
3648 | 5260 |
/** |
3649 |
- * @desc splits a string, but returns an empty list, if the string is empty |
|
3650 |
- * @param {string} chain |
|
3651 |
- * @param {string} separator |
|
3652 |
- * @return {Array<string>} |
|
3653 |
- * @author frac |
|
5261 |
+ * @author fenris |
|
3654 | 5262 |
*/ |
3655 |
- function split(chain, separator) { |
|
3656 |
- if (separator === void 0) { separator = " "; } |
|
3657 |
- if (chain.length == 0) { |
|
3658 |
- return []; |
|
3659 |
- } |
|
3660 |
- else { |
|
3661 |
- return chain.split(separator); |
|
3662 |
- } |
|
3663 |
- } |
|
3664 |
- lib_string.split = split; |
|
5263 |
+ class_step_back.prototype.invert = function () { |
|
5264 |
+ throw (new Error("impossible")); |
|
5265 |
+ }; |
|
3665 | 5266 |
/** |
3666 |
- * @desc concats a given word with itself n times |
|
3667 |
- * @param {string} word |
|
3668 |
- * @param {int} |
|
3669 |
- * @return {string} |
|
3670 |
- * @author frac |
|
5267 |
+ * @author fenris |
|
3671 | 5268 |
*/ |
3672 |
- function repeat(word, count) { |
|
3673 |
- return ((count == 0) ? "" : (word + repeat(word, count - 1))); |
|
3674 |
- } |
|
3675 |
- lib_string.repeat = repeat; |
|
5269 |
+ class_step_back.prototype.toString = function () { |
|
5270 |
+ return ".."; |
|
5271 |
+ }; |
|
5272 |
+ return class_step_back; |
|
5273 |
+ }(class_step)); |
|
5274 |
+ lib_path.class_step_back = class_step_back; |
|
3676 | 5275 |
/** |
3677 |
- * @desc lengthens a string by repeatedly appending or prepending another string |
|
3678 |
- * @param {string} word the string to pad |
|
3679 |
- * @param {int} length the length, which the result shall have |
|
3680 |
- * @param {string} symbol the string, which will be added (multiple times) |
|
3681 |
- * @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false |
|
3682 |
- * @return {string} the padded string |
|
3683 |
- * @author frac |
|
5276 |
+ * @author fenris |
|
3684 | 5277 |
*/ |
3685 |
- function pad(word, length, symbol, prepend) { |
|
3686 |
- if (prepend === void 0) { prepend = false; } |
|
3687 |
- if (prepend) { |
|
3688 |
- while (word.length < length) |
|
3689 |
- word = symbol + word; |
|
3690 |
- return word.substring(word.length - length); |
|
3691 |
- } |
|
3692 |
- else { |
|
3693 |
- while (word.length < length) |
|
3694 |
- word = word + symbol; |
|
3695 |
- return word.substring(0, length); |
|
3696 |
- } |
|
3697 |
- } |
|
3698 |
- lib_string.pad = pad; |
|
5278 |
+ var class_step_regular = (function (_super) { |
|
5279 |
+ __extends(class_step_regular, _super); |
|
3699 | 5280 |
/** |
3700 |
- * @desc checks if a given string conttains a certain substring |
|
3701 |
- * @param {string} string |
|
3702 |
- * @param {string} part |
|
3703 |
- * @return {boolean} |
|
3704 |
- * @author frac |
|
5281 |
+ * @author fenris |
|
3705 | 5282 |
*/ |
3706 |
- function contains(chain, part) { |
|
3707 |
- if (typeof (chain) !== "string") |
|
3708 |
- return false; |
|
3709 |
- return (chain.indexOf(part) >= 0); |
|
5283 |
+ function class_step_regular(name) { |
|
5284 |
+ var _this = _super.call(this) || this; |
|
5285 |
+ _this.name = name; |
|
5286 |
+ return _this; |
|
3710 | 5287 |
} |
3711 |
- lib_string.contains = contains; |
|
3712 | 5288 |
/** |
3713 |
- * @desc checks if a given string starts with a certain substring |
|
3714 |
- * @param {string} string |
|
3715 |
- * @param {string} part |
|
3716 |
- * @return {boolean} |
|
3717 |
- * @author frac |
|
5289 |
+ * @author fenris |
|
3718 | 5290 |
*/ |
3719 |
- function startsWith(chain, part) { |
|
3720 |
- if (typeof (chain) !== "string") |
|
3721 |
- return false; |
|
3722 |
- // return (string.indexOf(part) === 0); |
|
3723 |
- return ((function (m, n) { |
|
3724 |
- if (n == 0) { |
|
3725 |
- return true; |
|
3726 |
- } |
|
3727 |
- else { |
|
3728 |
- if (m == 0) { |
|
3729 |
- return false; |
|
3730 |
- } |
|
3731 |
- else { |
|
3732 |
- return ((chain[0] == part[0]) && startsWith(chain.substring(1), part.substring(1))); |
|
3733 |
- } |
|
3734 |
- } |
|
3735 |
- })(chain.length, part.length)); |
|
3736 |
- } |
|
3737 |
- lib_string.startsWith = startsWith; |
|
5291 |
+ class_step_regular.prototype.invert = function () { |
|
5292 |
+ return (new class_step_back()); |
|
5293 |
+ }; |
|
3738 | 5294 |
/** |
3739 |
- * @desc checks if a given string ends with a certain substring |
|
3740 |
- * @param {string} string |
|
3741 |
- * @param {string} part |
|
3742 |
- * @return {boolean} |
|
3743 |
- * @author frac |
|
5295 |
+ * @author fenris |
|
3744 | 5296 |
*/ |
3745 |
- function endsWith(chain, part) { |
|
3746 |
- if (typeof (chain) !== "string") |
|
3747 |
- return false; |
|
3748 |
- // return (string.lastIndexOf(part) === string.length-part.length); |
|
3749 |
- return ((function (m, n) { |
|
3750 |
- if (n == 0) { |
|
3751 |
- return true; |
|
3752 |
- } |
|
3753 |
- else { |
|
3754 |
- if (m == 0) { |
|
3755 |
- return false; |
|
3756 |
- } |
|
3757 |
- else { |
|
3758 |
- // console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1])); |
|
3759 |
- return ((chain[m - 1] == part[n - 1]) && endsWith(chain.substring(0, m - 1), part.substring(0, n - 1))); |
|
5297 |
+ class_step_regular.prototype.toString = function () { |
|
5298 |
+ return this.name; |
|
5299 |
+ }; |
|
5300 |
+ return class_step_regular; |
|
5301 |
+ }(class_step)); |
|
5302 |
+ lib_path.class_step_regular = class_step_regular; |
|
5303 |
+ /** |
|
5304 |
+ * @author fenris |
|
5305 |
+ */ |
|
5306 |
+ function step_read(s) { |
|
5307 |
+ switch (s) { |
|
5308 |
+ case ".": { |
|
5309 |
+ return (new class_step_stay()); |
|
5310 |
+ // break; |
|
3760 | 5311 |
} |
5312 |
+ case "..": { |
|
5313 |
+ return (new class_step_back()); |
|
5314 |
+ // break; |
|
3761 | 5315 |
} |
3762 |
- })(chain.length, part.length)); |
|
5316 |
+ default: { |
|
5317 |
+ return (new class_step_regular(s)); |
|
5318 |
+ // break; |
|
3763 | 5319 |
} |
3764 |
- lib_string.endsWith = endsWith; |
|
3765 |
- /** |
|
3766 |
- * @desc count the occourrences of a string in a string |
|
3767 |
- * @param string haystack_string the string wich should be examined |
|
3768 |
- * @param string needle_string the string which should be counted |
|
3769 |
- * @author neuc |
|
3770 |
- */ |
|
3771 |
- function count_occourrences(haystack_string, needle_string, check_escape) { |
|
3772 |
- var cnt = 0; |
|
3773 |
- var pos = -1; |
|
3774 |
- do { |
|
3775 |
- pos = haystack_string.indexOf(needle_string, pos + 1); |
|
3776 |
- if ((!check_escape) || (haystack_string[pos - 1] != "\\")) { |
|
3777 |
- cnt++; |
|
3778 | 5320 |
} |
3779 |
- } while (pos >= 0); |
|
3780 |
- return cnt - 1; |
|
3781 | 5321 |
} |
3782 |
- lib_string.count_occourrences = count_occourrences; |
|
3783 |
- ; |
|
5322 |
+ lib_path.step_read = step_read; |
|
5323 |
+})(lib_path || (lib_path = {})); |
|
5324 |
+///<reference path="../../../plankton/object/build/logic-decl.d.ts"/> |
|
5325 |
+var lib_path; |
|
5326 |
+(function (lib_path) { |
|
3784 | 5327 |
/** |
3785 | 5328 |
* @author fenris |
3786 | 5329 |
*/ |
3787 |
- function stance(str, args) { |
|
3788 |
- Object.keys(args).forEach(function (key) { |
|
3789 |
- var value = args[key]; |
|
3790 |
- var regexp_argument = new RegExp("\\${" + key + "}"); |
|
3791 |
- str = str.replace(regexp_argument, value); |
|
3792 |
- }); |
|
3793 |
- return str; |
|
5330 |
+ var class_chain = (function () { |
|
5331 |
+ /** |
|
5332 |
+ * @author fenris |
|
5333 |
+ */ |
|
5334 |
+ function class_chain(steps) { |
|
5335 |
+ if (steps === void 0) { steps = []; } |
|
5336 |
+ this.steps = steps; |
|
3794 | 5337 |
} |
3795 |
- lib_string.stance = stance; |
|
3796 |
-})(lib_string || (lib_string = {})); |
|
3797 | 5338 |
/** |
3798 |
- * @desc adapters for old syntax |
|
5339 |
+ * @author fenris |
|
3799 | 5340 |
*/ |
3800 |
-var string_generate = lib_string.generate; |
|
3801 |
-var string_split = lib_string.split; |
|
3802 |
-var string_repeat = lib_string.repeat; |
|
3803 |
-var string_pad = lib_string.pad; |
|
3804 |
-var string_contains = lib_string.contains; |
|
3805 |
-var string_startsWith = lib_string.startsWith; |
|
3806 |
-var string_endsWith = lib_string.endsWith; |
|
3807 |
-var string_count_occourrences = lib_string.count_occourrences; |
|
3808 |
-var lib_string; |
|
3809 |
-(function (lib_string) { |
|
3810 |
- var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/; |
|
3811 |
- var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g; |
|
3812 |
- function split_format(format) { |
|
3813 |
- var tmp = format.match(pattern); |
|
3814 |
- if (tmp === null) |
|
3815 |
- return null; |
|
3816 |
- return { |
|
3817 |
- 'flags': tmp[1].split(""), |
|
3818 |
- 'width': Number(tmp[2]), |
|
3819 |
- 'precision': tmp[3] === '' ? null : Number(tmp[3]), |
|
3820 |
- 'specifier': tmp[4], |
|
3821 |
- 'string': format |
|
5341 |
+ class_chain.splitter = function (system) { |
|
5342 |
+ if (system === void 0) { system = "linux"; } |
|
5343 |
+ return (object_fetch({ |
|
5344 |
+ "linux": "/", |
|
5345 |
+ "bsd": "/", |
|
5346 |
+ "win": "\\" |
|
5347 |
+ }, system, "/", 2)); |
|
3822 | 5348 |
}; |
5349 |
+ /** |
|
5350 |
+ * @desc removes superfluent steps from the chain, e.g. infix ".." |
|
5351 |
+ * @author fenris |
|
5352 |
+ */ |
|
5353 |
+ class_chain.prototype.normalize = function () { |
|
5354 |
+ var steps = this.steps; |
|
5355 |
+ // filter "stay" |
|
5356 |
+ { |
|
5357 |
+ steps = steps.filter(function (step) { return (!(step instanceof lib_path.class_step_stay)); }); |
|
3823 | 5358 |
} |
3824 |
- function make_err(format, arg, should) { |
|
3825 |
- return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!"); |
|
3826 |
- } |
|
3827 |
- function test_arg(format, arg, should) { |
|
3828 |
- if (typeof arg !== should) { |
|
3829 |
- console.warn(make_err(format, arg, should)); |
|
3830 |
- return false; |
|
5359 |
+ // filter "regular-back" |
|
5360 |
+ { |
|
5361 |
+ var _loop_1 = function () { |
|
5362 |
+ if (steps.length < 1) { |
|
5363 |
+ return "break"; |
|
3831 | 5364 |
} |
5365 |
+ else { |
|
5366 |
+ var last_1 = steps[0]; |
|
5367 |
+ var found = steps.slice(1).some(function (step, index) { |
|
5368 |
+ if (step instanceof lib_path.class_step_back) { |
|
5369 |
+ if (last_1 instanceof lib_path.class_step_regular) { |
|
5370 |
+ steps.splice(index, 2); |
|
3832 | 5371 |
return true; |
3833 | 5372 |
} |
3834 |
- function string_fill(str, char, len, left) { |
|
3835 |
- while (str.length < len) { |
|
3836 |
- if (left) { |
|
3837 |
- str += char; |
|
3838 | 5373 |
} |
3839 |
- else { |
|
3840 |
- str = char + str; |
|
5374 |
+ last_1 = step; |
|
5375 |
+ return false; |
|
5376 |
+ }); |
|
5377 |
+ if (!found) { |
|
5378 |
+ return "break"; |
|
3841 | 5379 |
} |
3842 | 5380 |
} |
3843 |
- return str; |
|
5381 |
+ }; |
|
5382 |
+ while (true) { |
|
5383 |
+ var state_1 = _loop_1(); |
|
5384 |
+ if (state_1 === "break") |
|
5385 |
+ break; |
|
5386 |
+ } |
|
3844 | 5387 |
} |
5388 |
+ return (new class_chain(steps)); |
|
5389 |
+ }; |
|
3845 | 5390 |
/** |
3846 |
- * the known_parameters are used to parse the different identifiers for the welln known syntax: |
|
3847 |
- * flag width precision identifier |
|
3848 |
- * %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn] |
|
3849 |
- * flags: |
|
3850 |
- * 0 - fill with '0' instead of ' ' if the string length < width |
|
3851 |
- * # - not implemented |
|
3852 |
- * - - left-justified -> fill on the right side to reach width |
|
3853 |
- * + - force using '+' on positive numbers |
|
3854 |
- * ' ' - add a single space before positive numbers |
|
3855 |
- * |
|
3856 |
- * identifiers |
|
3857 |
- * %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the |
|
3858 |
- * resulting string is too short, precision: cut more then given decimal places |
|
3859 |
- * %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision: |
|
3860 |
- * fill with '0' on right side until length given in precision is reached |
|
3861 |
- * %e - interpret as float and write as scientifical number, width & precision like in float |
|
3862 |
- * %E - same es %e but uppercase 'E' |
|
3863 |
- * %g - use the shortest string of %f or %e |
|
3864 |
- * %G - use the shortest string of %E or %E |
|
3865 |
- * %s - simply print a string |
|
3866 |
- * %o - print the given number in octal notation |
|
3867 |
- * %x - print the given number in hex notation |
|
3868 |
- * %X - same as %x but with uppercase characters |
|
3869 |
- * %a - alias to %x |
|
3870 |
- * %A - alias to %X |
|
3871 |
- * %n - just print nothing |
|
3872 |
- * @type {{}} |
|
5391 |
+ * @author fenris |
|
3873 | 5392 |
*/ |
3874 |
- var known_params = {}; |
|
3875 |
- known_params["f"] = function (format, arg) { |
|
3876 |
- if (!test_arg(format, arg, "number")) |
|
3877 |
- return "Ø"; |
|
3878 |
- var tmp = Math.abs(arg); |
|
3879 |
- var sign = (arg < 0) ? -1 : 1; |
|
3880 |
- var tmp_result = null; |
|
3881 |
- if (format.precision !== null) { |
|
3882 |
- tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision); |
|
3883 |
- var tmp_ = (tmp * sign).toString().split("."); |
|
3884 |
- if (tmp_.length === 1) |
|
3885 |
- tmp_.push(""); |
|
3886 |
- tmp_[1] = string_fill(tmp_[1], "0", format.precision, true); |
|
3887 |
- tmp_result = tmp_.join("."); |
|
3888 |
- } |
|
3889 |
- else { |
|
3890 |
- tmp_result = (sign * tmp).toString(); |
|
3891 |
- } |
|
3892 |
- if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) { |
|
3893 |
- tmp_result = " " + tmp; |
|
3894 |
- } |
|
3895 |
- else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) { |
|
3896 |
- tmp_result = "+" + tmp; |
|
3897 |
- } |
|
3898 |
- tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0)); |
|
3899 |
- return tmp_result; |
|
5393 |
+ class_chain.prototype.invert = function () { |
|
5394 |
+ return (new class_chain(this.steps.map(function (step) { return step.invert(); }))); |
|
3900 | 5395 |
}; |
3901 |
- known_params["F"] = known_params["f"]; |
|
3902 |
- known_params["d"] = function (format, arg) { |
|
3903 |
- if (!test_arg(format, arg, 'number')) |
|
3904 |
- return 'Ø'; |
|
3905 |
- var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString(); |
|
3906 |
- if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
3907 |
- tmp = ' ' + tmp; |
|
3908 |
- } |
|
3909 |
- else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
3910 |
- tmp = '+' + tmp; |
|
3911 |
- } |
|
3912 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
3913 |
- tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false); |
|
3914 |
- return tmp; |
|
5396 |
+ /** |
|
5397 |
+ * @author fenris |
|
5398 |
+ */ |
|
5399 |
+ class_chain.prototype.add = function (step) { |
|
5400 |
+ return (new class_chain(this.steps.concat([step]))).normalize(); |
|
3915 | 5401 |
}; |
3916 |
- known_params["i"] = known_params["d"]; |
|
3917 |
- known_params["u"] = known_params["d"]; |
|
3918 |
- known_params["e"] = function (format, arg) { |
|
3919 |
- if (!test_arg(format, arg, 'number')) |
|
3920 |
- return 'Ø'; |
|
3921 |
- var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString(); |
|
3922 |
- if (format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
3923 |
- tmp = ' ' + tmp; |
|
3924 |
- } |
|
3925 |
- else if (format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
3926 |
- tmp = '+' + tmp; |
|
3927 |
- } |
|
3928 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
3929 |
- return tmp; |
|
5402 |
+ /** |
|
5403 |
+ * @author fenris |
|
5404 |
+ */ |
|
5405 |
+ class_chain.prototype.extend = function (chain) { |
|
5406 |
+ return (new class_chain(this.steps.concat(chain.steps))).normalize(); |
|
3930 | 5407 |
}; |
3931 |
- known_params["E"] = function (format, arg) { |
|
3932 |
- return known_params["e"](format, arg).toUpperCase(); |
|
5408 |
+ /** |
|
5409 |
+ * @author fenris |
|
5410 |
+ */ |
|
5411 |
+ class_chain.prototype.as_string = function (system) { |
|
5412 |
+ if (system === void 0) { system = "linux"; } |
|
5413 |
+ var splitter = class_chain.splitter(system); |
|
5414 |
+ return ((this.steps.length == 0) ? ("." + splitter) : this.steps.map(function (step) { return (step.toString() + splitter); }).join("")); |
|
3933 | 5415 |
}; |
3934 |
- known_params["g"] = function (format, arg) { |
|
3935 |
- if (!test_arg(format, arg, 'number')) |
|
3936 |
- return 'Ø'; |
|
3937 |
- var tmpf = known_params["f"](format, arg); |
|
3938 |
- var tmpe = known_params["e"](format, arg); |
|
3939 |
- if (tmpf.length < tmpe.length) { |
|
3940 |
- return tmpf; |
|
5416 |
+ /** |
|
5417 |
+ * @author fenris |
|
5418 |
+ */ |
|
5419 |
+ class_chain.prototype.toString = function () { |
|
5420 |
+ return this.as_string(); |
|
5421 |
+ }; |
|
5422 |
+ return class_chain; |
|
5423 |
+ }()); |
|
5424 |
+ lib_path.class_chain = class_chain; |
|
5425 |
+ /** |
|
5426 |
+ * @author fenris |
|
5427 |
+ */ |
|
5428 |
+ function chain_read(str, system) { |
|
5429 |
+ if (system === void 0) { system = "linux"; } |
|
5430 |
+ var splitter = class_chain.splitter(system); |
|
5431 |
+ var parts = str.split(splitter); |
|
5432 |
+ if (parts[parts.length - 1] == "") |
|
5433 |
+ parts.pop(); |
|
5434 |
+ return (new class_chain(parts.map(lib_path.step_read))); |
|
3941 | 5435 |
} |
3942 |
- else { |
|
3943 |
- return tmpe; |
|
5436 |
+ lib_path.chain_read = chain_read; |
|
5437 |
+})(lib_path || (lib_path = {})); |
|
5438 |
+///<reference path="../../../plankton/object/build/logic-decl.d.ts"/> |
|
5439 |
+var lib_path; |
|
5440 |
+(function (lib_path) { |
|
5441 |
+ /** |
|
5442 |
+ * @author fenris |
|
5443 |
+ */ |
|
5444 |
+ var class_location = (function () { |
|
5445 |
+ /** |
|
5446 |
+ * @author fenris |
|
5447 |
+ */ |
|
5448 |
+ function class_location(anchor, chain) { |
|
5449 |
+ this.anchor = anchor; |
|
5450 |
+ this.chain = chain; |
|
3944 | 5451 |
} |
5452 |
+ /** |
|
5453 |
+ * @author fenris |
|
5454 |
+ */ |
|
5455 |
+ class_location.anchorpattern = function (system) { |
|
5456 |
+ if (system === void 0) { system = "linux"; } |
|
5457 |
+ return (object_fetch({ |
|
5458 |
+ "linux": new RegExp("/"), |
|
5459 |
+ "bsd": new RegExp("/"), |
|
5460 |
+ "win": new RegExp("[A-Z]:\\\\>") |
|
5461 |
+ }, system, new RegExp("/"), 1)); |
|
3945 | 5462 |
}; |
3946 |
- known_params["G"] = function (format, arg) { |
|
3947 |
- return known_params["g"](format, arg).toUpperCase(); |
|
3948 |
- }; |
|
3949 |
- known_params["s"] = function (format, arg) { |
|
3950 |
- if (!test_arg(format, arg, 'string')) |
|
3951 |
- return 'o.O'; |
|
3952 |
- var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg; |
|
3953 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
3954 |
- return tmp; |
|
3955 |
- }; |
|
3956 |
- known_params["o"] = function (format, arg) { |
|
3957 |
- if (!test_arg(format, arg, 'number')) |
|
3958 |
- return 'Ø'; |
|
3959 |
- var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
3960 |
- return known_params["s"](format, tmp.toString(8)); |
|
5463 |
+ /** |
|
5464 |
+ * @desc [accessor] |
|
5465 |
+ * @author fenris |
|
5466 |
+ */ |
|
5467 |
+ class_location.prototype.is_absolute = function () { |
|
5468 |
+ return (this.anchor != null); |
|
3961 | 5469 |
}; |
3962 |
- known_params["x"] = function (format, arg) { |
|
3963 |
- if (!test_arg(format, arg, 'number')) |
|
3964 |
- return 'Ø'; |
|
3965 |
- var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
3966 |
- return known_params["s"](format, tmp.toString(16)); |
|
5470 |
+ /** |
|
5471 |
+ * @author fenris |
|
5472 |
+ */ |
|
5473 |
+ class_location.prototype.normalize = function () { |
|
5474 |
+ return (new class_location(this.anchor, this.chain.normalize())); |
|
3967 | 5475 |
}; |
3968 |
- known_params["a"] = known_params["x"]; |
|
3969 |
- known_params["X"] = function (format, arg) { |
|
3970 |
- if (!test_arg(format, arg, 'number')) |
|
3971 |
- return 'Ø'; |
|
3972 |
- return known_params["x"](format, arg).toUpperCase(); |
|
5476 |
+ /** |
|
5477 |
+ * @author fenris |
|
5478 |
+ */ |
|
5479 |
+ class_location.prototype.extend = function (chain) { |
|
5480 |
+ return (new class_location(this.anchor, this.chain.extend(chain))); |
|
3973 | 5481 |
}; |
3974 |
- known_params["A"] = known_params["X"]; |
|
3975 |
- known_params["c"] = function (format, arg) { |
|
3976 |
- var tmp = ""; |
|
3977 |
- if (typeof arg === "number") { |
|
3978 |
- tmp = String.fromCharCode(arg); |
|
3979 |
- } |
|
3980 |
- else if ((typeof arg === "string") && (arg.length === 1)) { |
|
3981 |
- tmp = arg[0]; |
|
5482 |
+ /** |
|
5483 |
+ * @desc [accessor] |
|
5484 |
+ * @author fenris |
|
5485 |
+ */ |
|
5486 |
+ class_location.prototype.relocate = function (location) { |
|
5487 |
+ if (this.is_absolute()) { |
|
5488 |
+ return (new class_location(this.anchor, this.chain)); |
|
3982 | 5489 |
} |
3983 | 5490 |
else { |
3984 |
- console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!"); |
|
5491 |
+ return location.extend(this.chain); |
|
3985 | 5492 |
} |
3986 |
- return known_params["s"](format, tmp); |
|
3987 | 5493 |
}; |
3988 |
- known_params["n"] = function () { |
|
3989 |
- return ""; |
|
5494 |
+ /** |
|
5495 |
+ * @author fenris |
|
5496 |
+ */ |
|
5497 |
+ class_location.prototype.go_thither = function () { |
|
5498 |
+ // console.error(">>", this.toString()); |
|
5499 |
+ process.chdir(this.toString()); |
|
3990 | 5500 |
}; |
3991 |
- var decompose = function (chain, regexp) { |
|
3992 |
- var result = regexp.exec(chain); |
|
3993 |
- if (result == null) { |
|
3994 |
- return null; |
|
5501 |
+ /** |
|
5502 |
+ * @author fenris |
|
5503 |
+ */ |
|
5504 |
+ class_location.prototype.expedition = function (core) { |
|
5505 |
+ var that = this; |
|
5506 |
+ var current = location_read(process.cwd()); |
|
5507 |
+ function begin() { |
|
5508 |
+ // (new class_message("changing directory to '" + that.toString() + "'")).stderr(); |
|
5509 |
+ that.go_thither(); |
|
3995 | 5510 |
} |
3996 |
- else { |
|
3997 |
- var front = chain.substring(0, result.index); |
|
3998 |
- var back = chain.substring(result.index + result[0].length); |
|
3999 |
- return { "front": front, "match": result[0], "back": back }; |
|
5511 |
+ function end() { |
|
5512 |
+ // (new class_message("changing directory to '" + current.toString() + "'")).stderr(); |
|
5513 |
+ current.go_thither(); |
|
4000 | 5514 |
} |
5515 |
+ begin(); |
|
5516 |
+ core(end); |
|
4001 | 5517 |
}; |
4002 | 5518 |
/** |
4003 |
- * an implementation of c sprintf |
|
4004 |
- * @param {string} string format string |
|
4005 |
- * @param {array} args arguments which should be filled into |
|
4006 |
- * @returns {string} |
|
5519 |
+ * @author fenris |
|
4007 | 5520 |
*/ |
4008 |
- lib_string.sprintf = function (input, args, original) { |
|
4009 |
- if (args === void 0) { args = []; } |
|
4010 |
- if (original === void 0) { original = null; } |
|
4011 |
- if (original == null) |
|
4012 |
- original = input; |
|
4013 |
- var components = decompose(input, pattern); |
|
4014 |
- if (components == null) { |
|
4015 |
- if (args.length > 0) { |
|
4016 |
- console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args); |
|
4017 |
- } |
|
4018 |
- return input; |
|
5521 |
+ class_location.prototype.as_string = function (system) { |
|
5522 |
+ if (system === void 0) { system = "linux"; } |
|
5523 |
+ return (((this.anchor != null) ? this.anchor : "") + this.chain.as_string(system)); |
|
5524 |
+ }; |
|
5525 |
+ /** |
|
5526 |
+ * @author fenris |
|
5527 |
+ */ |
|
5528 |
+ class_location.prototype.toString = function () { |
|
5529 |
+ return this.as_string(); |
|
5530 |
+ }; |
|
5531 |
+ /** |
|
5532 |
+ * @author fenris |
|
5533 |
+ */ |
|
5534 |
+ class_location.current = function () { |
|
5535 |
+ // return class_location.read(process.cwd()); |
|
5536 |
+ return location_read(process.cwd()); |
|
5537 |
+ }; |
|
5538 |
+ /** |
|
5539 |
+ * @author fenris |
|
5540 |
+ */ |
|
5541 |
+ class_location.tempfolder = function (system) { |
|
5542 |
+ if (system === void 0) { system = "linux"; } |
|
5543 |
+ return (object_fetch({ |
|
5544 |
+ "linux": new class_location("/", new lib_path.class_chain([new lib_path.class_step_regular("tmp")])), |
|
5545 |
+ "bsd": new class_location("/", new lib_path.class_chain([new lib_path.class_step_regular("tmp")])), |
|
5546 |
+ "win": new class_location(null, new lib_path.class_chain([new lib_path.class_step_regular("%TEMP%")])) |
|
5547 |
+ }, system, null, 2)); |
|
5548 |
+ }; |
|
5549 |
+ return class_location; |
|
5550 |
+ }()); |
|
5551 |
+ lib_path.class_location = class_location; |
|
5552 |
+ /** |
|
5553 |
+ * @author fenris |
|
5554 |
+ */ |
|
5555 |
+ function location_read(str, system) { |
|
5556 |
+ if (system === void 0) { system = "linux"; } |
|
5557 |
+ var regexp = class_location.anchorpattern(system); |
|
5558 |
+ var matching = regexp.exec(str); |
|
5559 |
+ if ((matching == null) || (matching.index > 0)) { |
|
5560 |
+ return (new class_location(null, lib_path.chain_read(str, system))); |
|
4019 | 5561 |
} |
4020 | 5562 |
else { |
4021 |
- var arg; |
|
4022 |
- var rest; |
|
4023 |
- if (args.length > 0) { |
|
4024 |
- arg = args[0]; |
|
4025 |
- rest = args.slice(1); |
|
5563 |
+ return (new class_location(matching[0], lib_path.chain_read(str.slice(matching[0].length), system))); |
|
4026 | 5564 |
} |
4027 |
- else { |
|
4028 |
- console.warn("[sprintf] out of arguments while formatting '" + original + "'"); |
|
4029 |
- arg = null; |
|
4030 |
- rest = []; |
|
4031 |
- return input; |
|
4032 | 5565 |
} |
4033 |
- var fmt = split_format(components["match"]); |
|
4034 |
- return (components["front"] |
|
4035 |
- + known_params[fmt.specifier](fmt, arg) |
|
4036 |
- + lib_string.sprintf(components["back"], rest, original)); |
|
5566 |
+ lib_path.location_read = location_read; |
|
5567 |
+})(lib_path || (lib_path = {})); |
|
5568 |
+var lib_path; |
|
5569 |
+(function (lib_path) { |
|
5570 |
+ /** |
|
5571 |
+ * @author fenris |
|
5572 |
+ */ |
|
5573 |
+ var class_filepointer = (function () { |
|
5574 |
+ /** |
|
5575 |
+ * @author fenris |
|
5576 |
+ */ |
|
5577 |
+ function class_filepointer(location, filename) { |
|
5578 |
+ this.location = location; |
|
5579 |
+ this.filename = filename; |
|
4037 | 5580 |
} |
5581 |
+ /** |
|
5582 |
+ * @author fenris |
|
5583 |
+ */ |
|
5584 |
+ class_filepointer.prototype.normalize = function () { |
|
5585 |
+ return (new class_filepointer(this.location.normalize(), this.filename)); |
|
4038 | 5586 |
}; |
4039 | 5587 |
/** |
4040 |
- * an implementation of c printf |
|
4041 |
- * @param {string} string format string |
|
4042 |
- * @param {array} args arguments which should be filled into |
|
4043 |
- * @returns {string} |
|
5588 |
+ * @author fenris |
|
4044 | 5589 |
*/ |
4045 |
- function printf(format, args) { |
|
4046 |
- console.log(lib_string.sprintf(format, args)); |
|
4047 |
- } |
|
4048 |
- lib_string.printf = printf; |
|
4049 |
-})(lib_string || (lib_string = {})); |
|
4050 |
-var sprintf = lib_string.sprintf; |
|
4051 |
-var printf = lib_string.printf; |
|
5590 |
+ class_filepointer.prototype.foo = function (filepointer) { |
|
5591 |
+ return (new class_filepointer(this.location.extend(filepointer.location.chain), filepointer.filename)); |
|
5592 |
+ }; |
|
4052 | 5593 |
/** |
4053 |
- * @author neuc |
|
5594 |
+ * @desc [accessor] |
|
5595 |
+ * @author fenris |
|
4054 | 5596 |
*/ |
4055 |
-var strftime; |
|
4056 |
-(function (strftime) { |
|
4057 |
- var currentDate = new Date(); |
|
4058 |
- var days = [ |
|
4059 |
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" |
|
4060 |
- ]; |
|
4061 |
- var months = [ |
|
4062 |
- "January", "February", "March", "April", "May", "June", "July", "August", "September", |
|
4063 |
- "October", "November", "December" |
|
4064 |
- ]; |
|
4065 |
- function set_days(day_names) { |
|
4066 |
- days = day_names; |
|
4067 |
- } |
|
4068 |
- strftime.set_days = set_days; |
|
4069 |
- function set_months(month_names) { |
|
4070 |
- months = month_names; |
|
4071 |
- } |
|
4072 |
- strftime.set_months = set_months; |
|
4073 |
- // source: https://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366 |
|
4074 |
- function helper_dayOfYear(date) { |
|
4075 |
- var start = new Date(date.getFullYear(), 0, 0); |
|
4076 |
- var diff = date - start; |
|
4077 |
- var oneDay = 1000 * 60 * 60 * 24; |
|
4078 |
- return Math.floor(diff / oneDay); |
|
4079 |
- } |
|
4080 |
- // source: http://weeknumber.net/how-to/javascript |
|
4081 |
- function helper_weekOfYear(date_) { |
|
4082 |
- var date = new Date(date_.getTime()); |
|
4083 |
- date.setHours(0, 0, 0, 0); |
|
4084 |
- // Thursday in current week decides the year. |
|
4085 |
- date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); |
|
4086 |
- // January 4 is always in week 1. |
|
4087 |
- var week1 = new Date(date.getFullYear(), 0, 4); |
|
4088 |
- // Adjust to Thursday in week 1 and count number of weeks from date to week1. |
|
4089 |
- return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 |
|
4090 |
- - 3 + (week1.getDay() + 6) % 7) / 7); |
|
4091 |
- } |
|
4092 |
- function helper_englishWeekOfYear(date) { |
|
4093 |
- var nr = helper_weekOfYear(date); |
|
4094 |
- if (date.getDay() === 0) { |
|
4095 |
- nr = nr - 1; |
|
5597 |
+ class_filepointer.prototype.relocate = function (location) { |
|
5598 |
+ return (new class_filepointer(this.location.relocate(location), this.filename)); |
|
5599 |
+ }; |
|
5600 |
+ /** |
|
5601 |
+ * @author fenris |
|
5602 |
+ */ |
|
5603 |
+ class_filepointer.prototype.as_string = function (system) { |
|
5604 |
+ if (system === void 0) { system = "linux"; } |
|
5605 |
+ return (this.location.as_string(system) /* + "/"*/ + ((this.filename == null) ? "" : this.filename)); |
|
5606 |
+ }; |
|
5607 |
+ /** |
|
5608 |
+ * @author fenris |
|
5609 |
+ */ |
|
5610 |
+ class_filepointer.prototype.toString = function () { |
|
5611 |
+ return this.as_string(); |
|
5612 |
+ }; |
|
5613 |
+ return class_filepointer; |
|
5614 |
+ }()); |
|
5615 |
+ lib_path.class_filepointer = class_filepointer; |
|
5616 |
+ /** |
|
5617 |
+ * @author fenris |
|
5618 |
+ */ |
|
5619 |
+ function filepointer_read(str, system) { |
|
5620 |
+ if (system === void 0) { system = "linux"; } |
|
5621 |
+ var splitter = lib_path.class_chain.splitter(system); |
|
5622 |
+ var parts = str.split(splitter); |
|
5623 |
+ var last = parts[parts.length - 1]; |
|
5624 |
+ if (last == "") { |
|
5625 |
+ return (new class_filepointer(lib_path.location_read(parts.join(splitter), system), null)); |
|
4096 | 5626 |
} |
4097 |
- return nr; |
|
5627 |
+ else { |
|
5628 |
+ return (new class_filepointer(lib_path.location_read(parts.slice(0, parts.length - 1).join(splitter), system), last)); |
|
4098 | 5629 |
} |
4099 |
- function set_currentDate(date) { |
|
4100 |
- currentDate = date; |
|
4101 | 5630 |
} |
4102 |
- strftime.set_currentDate = set_currentDate; |
|
4103 |
- function parse(format, date) { |
|
4104 |
- if (!date) { |
|
4105 |
- date = currentDate; |
|
5631 |
+ lib_path.filepointer_read = filepointer_read; |
|
5632 |
+})(lib_path || (lib_path = {})); |
|
5633 |
+///<reference path="../../call/build/logic-decl.d.ts"/> |
|
5634 |
+var lib_file; |
|
5635 |
+(function (lib_file) { |
|
5636 |
+ /** |
|
5637 |
+ * @author fenris |
|
5638 |
+ */ |
|
5639 |
+ class class_file_abstract { |
|
5640 |
+ /** |
|
5641 |
+ * @desc reads a json file |
|
5642 |
+ * @author fenris |
|
5643 |
+ */ |
|
5644 |
+ read_json(path) { |
|
5645 |
+ return ((resolve, reject) => { |
|
5646 |
+ lib_call.executor_chain({}, [ |
|
5647 |
+ state => (resolve_, reject_) => { |
|
5648 |
+ this.read(path)(content => { |
|
5649 |
+ state.content = content; |
|
5650 |
+ resolve_(state); |
|
5651 |
+ }, reject_); |
|
5652 |
+ }, |
|
5653 |
+ state => (resolve_, reject_) => { |
|
5654 |
+ let error; |
|
5655 |
+ try { |
|
5656 |
+ state.data = JSON.parse(state.content); |
|
5657 |
+ error = null; |
|
4106 | 5658 |
} |
4107 |
- var ret = format; |
|
4108 |
- var re = new RegExp("%[a-z]", "gi"); |
|
4109 |
- var match; |
|
4110 |
- while (match = re.exec(format)) { |
|
4111 |
- ret = ret.replace(match[0], parse_segment(match[0], date)); |
|
5659 |
+ catch (exception) { |
|
5660 |
+ error = new class_error("invalid json '" + path + "'", [exception]); |
|
4112 | 5661 |
} |
4113 |
- return ret; |
|
5662 |
+ if (error == null) { |
|
5663 |
+ resolve_(state); |
|
4114 | 5664 |
} |
4115 |
- strftime.parse = parse; |
|
4116 |
- function parse_segment(segment, date) { |
|
4117 |
- if (!date) { |
|
4118 |
- date = currentDate; |
|
5665 |
+ else { |
|
5666 |
+ reject_(error); |
|
4119 | 5667 |
} |
4120 |
- var hm_segments = { |
|
4121 |
- "%a": function () { return days[date.getDay()].slice(0, 3); }, |
|
4122 |
- "%A": function () { return days[date.getDay()]; }, |
|
4123 |
- "%b": function () { return days[date.getMonth()].slice(0, 3); }, |
|
4124 |
- "%B": function () { return days[date.getMonth()]; }, |
|
4125 |
- "%c": function () { return date.toLocaleString(); }, |
|
4126 |
- "%C": function () { return Math.floor((date.getFullYear()) / 100).toString(); }, |
|
4127 |
- "%d": function () { return sprintf("%02d", [date.getDate()]); }, |
|
4128 |
- "%D": function () { return parse("%m/%d/%y", date); }, |
|
4129 |
- "%e": function () { return sprintf("%2d", [date.getDate()]); }, |
|
4130 |
- "%F": function () { return parse("%Y-%m-%d", date); }, |
|
4131 |
- "%g": function () { return sprintf("%02d", [date.getFullYear() % 1000]); }, |
|
4132 |
- "%G": function () { return date.getFullYear().toString(); }, |
|
4133 |
- "%h": function () { return parse("%b", date); }, |
|
4134 |
- "%H": function () { return sprintf("%02d", [date.getHours()]); }, |
|
4135 |
- "%I": function () { |
|
4136 |
- return sprintf("%02d", [ |
|
4137 |
- (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()) |
|
4138 |
- ]); |
|
4139 | 5668 |
}, |
4140 |
- "%j": function () { return sprintf("%03d", [helper_dayOfYear(date)]); }, |
|
4141 |
- "%m": function () { return sprintf("%02d", [date.getMonth() + 1]); }, |
|
4142 |
- "%M": function () { return sprintf("%02d", [date.getMinutes()]); }, |
|
4143 |
- "%n": function () { return "\n"; }, |
|
4144 |
- "%p": function () { return (date.getHours() > 12 ? "PM" : "AM"); }, |
|
4145 |
- "%r": function () { return parse("%I:%M:%S %p", date); }, |
|
4146 |
- "%R": function () { return parse("%H:%M", date); }, |
|
4147 |
- "%S": function () { return date.getSeconds().toString(); }, |
|
4148 |
- "%t": function () { return "\t"; }, |
|
4149 |
- "%T": function () { return parse("%H:%M:%S", date); }, |
|
4150 |
- "%u": function () { return sprintf("%02d", [(date.getDay() === 0 ? 7 : date.getDay())]); }, |
|
4151 |
- "%U": function () { return sprintf("%02d", [helper_englishWeekOfYear(date)]); }, |
|
4152 |
- "%V": function () { return sprintf("%02d", [helper_weekOfYear(date)]); }, |
|
4153 |
- "%w": function () { return sprintf("%02d", [date.getDay().toString()]); }, |
|
4154 |
- "%W": function () { return parse("%w", date); }, |
|
4155 |
- "%x": function () { return parse("%m/%d/%G", date); }, |
|
4156 |
- "%X": function () { return parse("%T", date); }, |
|
4157 |
- "%y": function () { return parse("%g", date); }, |
|
4158 |
- "%Y": function () { return parse("%G", date); }, |
|
4159 |
- "%z": function () { return date.getTimezoneOffset().toString(); }, |
|
4160 |
- "%Z": function () { return date.toUTCString().split(' ').pop(); }, |
|
4161 |
- "%%": function () { return "%"; } |
|
4162 |
- }; |
|
4163 |
- if (!(segment in hm_segments)) { |
|
4164 |
- throw "unknown format argument '" + segment + "'"; |
|
5669 |
+ ])(state => resolve(state.data), reject); |
|
5670 |
+ }); |
|
4165 | 5671 |
} |
4166 |
- return hm_segments[segment](); |
|
5672 |
+ /** |
|
5673 |
+ * @desc writes a json file |
|
5674 |
+ * @author fenris |
|
5675 |
+ */ |
|
5676 |
+ write_json(path, data) { |
|
5677 |
+ return this.write(path, JSON.stringify(data, undefined, "\t")); |
|
4167 | 5678 |
} |
4168 |
-})(strftime || (strftime = {})); |
|
4169 |
-function locale_date(date, ignore_error) { |
|
4170 |
- if (date === void 0) { date = new Date(); } |
|
4171 |
- if (ignore_error === void 0) { ignore_error = false; } |
|
4172 |
- if (!(date instanceof Date)) { |
|
4173 |
- if (!ignore_error) { |
|
4174 |
- throw new SyntaxError("date must be instance of Date"); |
|
4175 | 5679 |
} |
4176 |
- else { |
|
4177 |
- console.warn("'" + date + "' seems not to be instance of Date try to force convert."); |
|
4178 |
- var tmp = date; |
|
4179 |
- date = new Date(tmp); |
|
4180 |
- if ((date.toString() === "Invalid Date") || |
|
4181 |
- (!(date < new Date(0)) && !(date > new Date(0)))) { |
|
4182 |
- console.warn("conversion didn't work, returning default value"); |
|
4183 |
- return "Ø"; |
|
5680 |
+ lib_file.class_file_abstract = class_file_abstract; |
|
5681 |
+})(lib_file || (lib_file = {})); |
|
5682 |
+///<reference path="../../call/build/logic-decl.d.ts"/> |
|
5683 |
+var lib_file; |
|
5684 |
+(function (lib_file) { |
|
5685 |
+ /** |
|
5686 |
+ * @author fenris |
|
5687 |
+ */ |
|
5688 |
+ class class_file_node extends lib_file.class_file_abstract { |
|
5689 |
+ /** |
|
5690 |
+ * @author maspr |
|
5691 |
+ */ |
|
5692 |
+ determine_handler(path) { |
|
5693 |
+ if (/^https?:\/\//.test(path)) { |
|
5694 |
+ return "http"; |
|
4184 | 5695 |
} |
5696 |
+ else { |
|
5697 |
+ return "file"; |
|
4185 | 5698 |
} |
4186 | 5699 |
} |
4187 |
- var conf = global_config.get_value("date") || { |
|
4188 |
- "use_locale_date": true, |
|
4189 |
- "format_string": "%d.%m.%Y" |
|
4190 |
- }; |
|
4191 |
- if (conf.use_locale_date) { |
|
4192 |
- return date.toLocaleDateString(); |
|
5700 |
+ /** |
|
5701 |
+ * @override |
|
5702 |
+ * @author fenris,maspr |
|
5703 |
+ * @todo clear up if http(s)-handling belongs here or not |
|
5704 |
+ */ |
|
5705 |
+ read(path, skip_error = false) { |
|
5706 |
+ switch (this.determine_handler(path)) { |
|
5707 |
+ case "file": |
|
5708 |
+ { |
|
5709 |
+ let nm_fs = require("fs"); |
|
5710 |
+ return ((resolve, reject) => { |
|
5711 |
+ nm_fs.readFile(path, { |
|
5712 |
+ "encoding": "utf8", |
|
5713 |
+ "flag": "r", |
|
5714 |
+ }, (error, content) => { |
|
5715 |
+ if (error == null) { |
|
5716 |
+ resolve(content); |
|
4193 | 5717 |
} |
4194 | 5718 |
else { |
4195 |
- return strftime.parse(conf.format_string, date); |
|
4196 |
- } |
|
5719 |
+ reject(error); |
|
4197 | 5720 |
} |
4198 |
-; |
|
4199 |
-var make_logger = (function () { |
|
4200 |
- var _loggers = {}; |
|
4201 |
- var make_logger = function (prefix, current_loglevel) { |
|
4202 |
- var log = []; |
|
4203 |
- var level = [ |
|
4204 |
- "LOG", "INFO", "WARNING", "DEBUG" |
|
4205 |
- ]; |
|
4206 |
- var logger = function (obj, lvl) { |
|
4207 |
- var txt = obj.txt || obj; |
|
4208 |
- if (lvl == void 0) |
|
4209 |
- lvl = 0; |
|
4210 |
- var date = new Date(); |
|
4211 |
- log.push({ |
|
4212 |
- "message": sprintf("%s [%s:%s] %s", [date.toString(), level[lvl], prefix, txt]), |
|
4213 |
- "timeStamp": +(date) |
|
4214 | 5721 |
}); |
4215 |
- if (lvl <= current_loglevel) { |
|
4216 |
- var msg = ["[" + prefix + "]", txt]; |
|
4217 |
- if (obj.arg) |
|
4218 |
- msg = ["[" + prefix + "]"].concat(Array.prototype.slice.call(obj.arg)); |
|
4219 |
- if (lvl === 0) |
|
4220 |
- console["_log"].apply(console, msg); |
|
4221 |
- else if (lvl === 1) |
|
4222 |
- console["_info"].apply(console, msg); |
|
4223 |
- else if (lvl === 2) |
|
4224 |
- console["_warn"].apply(console, msg); |
|
4225 |
- else if (lvl >= 3) |
|
4226 |
- console["_log"].apply(console, msg); |
|
5722 |
+ }); |
|
4227 | 5723 |
} |
5724 |
+ break; |
|
5725 |
+ case "http": |
|
5726 |
+ { |
|
5727 |
+ return (resolve, reject) => { |
|
5728 |
+ let nm_http = require("http"); |
|
5729 |
+ let nm_https = require("https"); |
|
5730 |
+ let nm_url = require("url"); |
|
5731 |
+ let parsed_url = nm_url.parse(path, false, true); |
|
5732 |
+ let client = (parsed_url.protocol == "https:") ? nm_https : nm_http; |
|
5733 |
+ let default_port = ((parsed_url.protocol == "https:") ? 443 : 80); |
|
5734 |
+ let options = { |
|
5735 |
+ hostname: parsed_url.hostname, |
|
5736 |
+ port: parsed_url.port || default_port, |
|
5737 |
+ path: parsed_url.path, |
|
5738 |
+ method: "GET" |
|
4228 | 5739 |
}; |
4229 |
- _loggers[prefix] = { |
|
4230 |
- "logger": logger, |
|
4231 |
- "log": log |
|
4232 |
- }; |
|
4233 |
- return logger; |
|
5740 |
+ let req = client.request(options, (res) => { |
|
5741 |
+ let data = ""; // @todo |
|
5742 |
+ res.on("data", (chunk) => { |
|
5743 |
+ data += chunk; |
|
5744 |
+ }); |
|
5745 |
+ res.on("end", () => { |
|
5746 |
+ resolve(data); |
|
5747 |
+ }); |
|
5748 |
+ }); |
|
5749 |
+ req.end(); |
|
5750 |
+ req.on("error", (error) => { |
|
5751 |
+ reject(error); |
|
5752 |
+ }); |
|
4234 | 5753 |
}; |
4235 |
- make_logger["loggers"] = _loggers; |
|
4236 |
- make_logger["complete_log"] = function () { |
|
4237 |
- var logs = Object.keys(_loggers) |
|
4238 |
- .reduce(function (p, c) { |
|
4239 |
- return [].concat(p, _loggers[c].log); |
|
4240 |
- }, []); |
|
4241 |
- logs.sort(function (x, y) { |
|
4242 |
- return ((x.timeStamp > y.timeStamp) ? -1 : +1); |
|
5754 |
+ } |
|
5755 |
+ break; |
|
5756 |
+ default: { |
|
5757 |
+ return ((resolve, reject) => reject(new Error("unhandled protocol"))); |
|
5758 |
+ } |
|
5759 |
+ } |
|
5760 |
+ } |
|
5761 |
+ /** |
|
5762 |
+ * @override |
|
5763 |
+ * @author fenris |
|
5764 |
+ */ |
|
5765 |
+ write(path, content) { |
|
5766 |
+ let nm_fs = require("fs"); |
|
5767 |
+ return ((resolve, reject) => { |
|
5768 |
+ nm_fs.writeFile(path, content, { |
|
5769 |
+ "encoding": "utf8", |
|
5770 |
+ "flag": "w", |
|
5771 |
+ }, (error) => { |
|
5772 |
+ if (error == null) { |
|
5773 |
+ resolve(undefined); |
|
5774 |
+ } |
|
5775 |
+ else { |
|
5776 |
+ reject(error); |
|
5777 |
+ } |
|
4243 | 5778 |
}); |
4244 |
- return logs.map(function (x, i, a) { |
|
4245 |
- return x.message; |
|
4246 | 5779 |
}); |
4247 |
- }; |
|
4248 |
- if (true) { |
|
4249 |
- var _log_all = function (log, lvl, next) { |
|
4250 |
- if (next === void 0) { next = function () { }; } |
|
4251 |
- return function () { |
|
4252 |
- var msg = []; |
|
4253 |
- for (var i = 0; i < arguments.length; i++) { |
|
4254 |
- if (typeof arguments[i] === "string") { |
|
4255 |
- msg.push(arguments[i]); |
|
5780 |
+ } |
|
5781 |
+ } |
|
5782 |
+ lib_file.class_file_node = class_file_node; |
|
5783 |
+})(lib_file || (lib_file = {})); |
|
5784 |
+///<reference path="../../call/build/logic-decl.d.ts"/> |
|
5785 |
+var lib_file; |
|
5786 |
+(function (lib_file) { |
|
5787 |
+ /** |
|
5788 |
+ * @author fenris |
|
5789 |
+ * @todo move to a dedicated lib (e.g. "http", "transport", etc.) |
|
5790 |
+ */ |
|
5791 |
+ function ajax({ "target": target /*: string*/, "data": data /*: {[key : string] : string}*/ = null, "method": method /* : string*/ = "GET" }) { |
|
5792 |
+ method = method.toLowerCase(); |
|
5793 |
+ return ((resolve, reject) => { |
|
5794 |
+ let datastring = ((data == null) ? null : Object.keys(data).map(key => `${key}=${data[key]}`).join("&")); |
|
5795 |
+ let suffix = ((method == "get") ? ("?" + datastring) : ""); |
|
5796 |
+ let sending = ((method == "get") ? null : datastring); |
|
5797 |
+ let request = new XMLHttpRequest(); |
|
5798 |
+ request.open(method.toUpperCase(), target + suffix, true); |
|
5799 |
+ request.onreadystatechange = function () { |
|
5800 |
+ if (request.readyState === 4) { |
|
5801 |
+ if (request.status === 200) { |
|
5802 |
+ resolve(request.responseText); |
|
4256 | 5803 |
} |
4257 | 5804 |
else { |
4258 |
- msg.push(JSON.stringify(arguments[i])); |
|
5805 |
+ reject(new Error("XMLHttpRequest failed")); |
|
4259 | 5806 |
} |
4260 | 5807 |
} |
4261 |
- var obj = { |
|
4262 |
- txt: msg.join("\t"), |
|
4263 |
- arg: arguments |
|
4264 |
- }; |
|
4265 |
- log(obj, lvl); |
|
4266 |
- next(); |
|
4267 | 5808 |
}; |
4268 |
- }; |
|
4269 |
- { |
|
4270 |
- var __warn = make_logger("deprecated console.warn", 99); |
|
4271 |
- var __error = make_logger("deprecated console.error", 99); |
|
4272 |
- var __log = make_logger("deprecated console.log", 99); |
|
4273 |
- var __info = make_logger("deprecated console.info", 99); |
|
4274 |
- // bad ass |
|
4275 |
- console["_log"] = console.log; |
|
4276 |
- console["_error"] = console.error; |
|
4277 |
- console["_warn"] = console.warn; |
|
4278 |
- console["_info"] = console.info; |
|
4279 |
- /* |
|
4280 |
- console["log"] = _log_all(__log, 0); |
|
4281 |
- console["error"] = _log_all(__error, 2); |
|
4282 |
- console["warn"] = _log_all(__warn, 2); |
|
4283 |
- console["info"] = _log_all(__info, 0); |
|
5809 |
+ request.send(sending); |
|
5810 |
+ }); |
|
5811 |
+ } |
|
5812 |
+ /** |
|
5813 |
+ * @author fenris |
|
5814 |
+ */ |
|
5815 |
+ class class_file_web extends lib_file.class_file_abstract { |
|
5816 |
+ /** |
|
5817 |
+ * @override |
|
5818 |
+ * @author fenris |
|
4284 | 5819 |
*/ |
5820 |
+ read(path, skip_error = false) { |
|
5821 |
+ return ((resolve, reject) => { |
|
5822 |
+ ajax({ |
|
5823 |
+ "target": path, |
|
5824 |
+ "method": "GET", |
|
5825 |
+ })(resolve, reason => (skip_error ? resolve(null) : reject(reason))); |
|
5826 |
+ }); |
|
4285 | 5827 |
} |
4286 |
- /* |
|
4287 |
- { |
|
4288 |
- make_logger["send_log"] = function(){ |
|
4289 |
- eml_log( |
|
4290 |
- function () { |
|
4291 |
- alert("fehlerbericht wurde gesendet!"); |
|
5828 |
+ /** |
|
5829 |
+ * @override |
|
5830 |
+ * @author fenris |
|
5831 |
+ */ |
|
5832 |
+ write(path, content) { |
|
5833 |
+ return ((resolve, reject) => { |
|
5834 |
+ reject(new Error("not implemented / not possible")); |
|
5835 |
+ }); |
|
4292 | 5836 |
} |
4293 |
- ); |
|
4294 |
- }; |
|
4295 |
- var error_log = make_logger("global.error", 99); |
|
4296 |
- window.onerror = _log_all( |
|
4297 |
- error_log, |
|
4298 |
- 1, |
|
4299 |
- function(){ |
|
4300 |
- if (global_config == undefined) { |
|
4301 |
- return false; |
|
4302 | 5837 |
} |
4303 |
- if (global_config.report_error) { |
|
4304 |
- make_logger["send_log"](); |
|
5838 |
+ lib_file.class_file_web = class_file_web; |
|
5839 |
+})(lib_file || (lib_file = {})); |
|
5840 |
+///<reference path="../../base/build/logic-decl.d.ts"/> |
|
5841 |
+///<reference path="../../call/build/logic-decl.d.ts"/> |
|
5842 |
+var lib_file; |
|
5843 |
+(function (lib_file) { |
|
5844 |
+ /** |
|
5845 |
+ * @desc selects the implementation which fits for the detected environment |
|
5846 |
+ * @author fenris |
|
5847 |
+ */ |
|
5848 |
+ function auto() { |
|
5849 |
+ let environment = lib_base.environment(); |
|
5850 |
+ switch (environment) { |
|
5851 |
+ case "node": { |
|
5852 |
+ return (new lib_file.class_file_node()); |
|
5853 |
+ break; |
|
4305 | 5854 |
} |
5855 |
+ case "web": { |
|
5856 |
+ return (new lib_file.class_file_web()); |
|
5857 |
+ break; |
|
5858 |
+ } |
|
5859 |
+ default: { |
|
5860 |
+ throw (new Error(`no implementation for environment '${environment}'`)); |
|
5861 |
+ break; |
|
4306 | 5862 |
} |
4307 |
- ); |
|
4308 | 5863 |
} |
5864 |
+ } |
|
5865 |
+ lib_file.auto = auto; |
|
5866 |
+ /** |
|
5867 |
+ * @author fenris |
|
5868 |
+ */ |
|
5869 |
+ class class_file extends lib_file.class_file_abstract { |
|
5870 |
+ /** |
|
5871 |
+ * @author fenris |
|
4309 | 5872 |
*/ |
5873 |
+ constructor() { |
|
5874 |
+ super(); |
|
5875 |
+ this.core = auto(); |
|
4310 | 5876 |
} |
4311 |
- return make_logger; |
|
4312 |
-})(); |
|
4313 |
-var __extends = (this && this.__extends) || (function () { |
|
4314 |
- var extendStatics = Object.setPrototypeOf || |
|
4315 |
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
4316 |
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
4317 |
- return function (d, b) { |
|
4318 |
- extendStatics(d, b); |
|
4319 |
- function __() { this.constructor = d; } |
|
4320 |
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
4321 |
- }; |
|
4322 |
-})(); |
|
4323 |
-///<reference path="../../base/build/logic-decl.d.ts"/> |
|
4324 |
-///<reference path="../../string/build/logic-decl.d.ts"/> |
|
4325 | 5877 |
/** |
5878 |
+ * @override |
|
4326 | 5879 |
* @author fenris |
4327 | 5880 |
*/ |
4328 |
-var lib_xml; |
|
4329 |
-(function (lib_xml) { |
|
5881 |
+ read(path, skip_error = false) { |
|
5882 |
+ return this.core.read(path, skip_error); |
|
5883 |
+ } |
|
4330 | 5884 |
/** |
5885 |
+ * @override |
|
4331 | 5886 |
* @author fenris |
4332 | 5887 |
*/ |
4333 |
- var class_node = (function () { |
|
4334 |
- function class_node() { |
|
5888 |
+ write(path, content) { |
|
5889 |
+ return this.core.write(path, content); |
|
4335 | 5890 |
} |
4336 |
- return class_node; |
|
4337 |
- }()); |
|
4338 |
- lib_xml.class_node = class_node; |
|
5891 |
+ } |
|
5892 |
+ lib_file.class_file = class_file; |
|
4339 | 5893 |
/** |
4340 | 5894 |
* @author fenris |
4341 | 5895 |
*/ |
4342 |
- var class_node_text = (function (_super) { |
|
4343 |
- __extends(class_node_text, _super); |
|
5896 |
+ var instance = auto(); |
|
4344 | 5897 |
/** |
4345 | 5898 |
* @author fenris |
4346 | 5899 |
*/ |
4347 |
- function class_node_text(content) { |
|
4348 |
- var _this = _super.call(this) || this; |
|
4349 |
- _this.content = content; |
|
4350 |
- return _this; |
|
5900 |
+ function read(path, skip_error = false) { |
|
5901 |
+ return instance.read(path, skip_error); |
|
4351 | 5902 |
} |
5903 |
+ lib_file.read = read; |
|
4352 | 5904 |
/** |
4353 | 5905 |
* @author fenris |
4354 | 5906 |
*/ |
4355 |
- class_node_text.prototype.compile = function (depth) { |
|
4356 |
- if (depth === void 0) { depth = 0; } |
|
4357 |
- return (lib_string.repeat("\t", depth) + this.content + "\n"); |
|
4358 |
- }; |
|
4359 |
- return class_node_text; |
|
4360 |
- }(class_node)); |
|
4361 |
- lib_xml.class_node_text = class_node_text; |
|
5907 |
+ function write(path, content) { |
|
5908 |
+ return instance.write(path, content); |
|
5909 |
+ } |
|
5910 |
+ lib_file.write = write; |
|
4362 | 5911 |
/** |
4363 | 5912 |
* @author fenris |
4364 | 5913 |
*/ |
4365 |
- var class_node_comment = (function (_super) { |
|
4366 |
- __extends(class_node_comment, _super); |
|
5914 |
+ function read_json(path) { |
|
5915 |
+ return instance.read_json(path); |
|
5916 |
+ } |
|
5917 |
+ lib_file.read_json = read_json; |
|
4367 | 5918 |
/** |
4368 | 5919 |
* @author fenris |
4369 | 5920 |
*/ |
4370 |
- function class_node_comment(content) { |
|
4371 |
- var _this = _super.call(this) || this; |
|
4372 |
- _this.content = content; |
|
4373 |
- return _this; |
|
5921 |
+ function write_json(path, data) { |
|
5922 |
+ return instance.write_json(path, data); |
|
4374 | 5923 |
} |
5924 |
+ lib_file.write_json = write_json; |
|
5925 |
+})(lib_file || (lib_file = {})); |
|
5926 |
+var lib_dot; |
|
5927 |
+(function (lib_dot) { |
|
4375 | 5928 |
/** |
4376 | 5929 |
* @author fenris |
4377 | 5930 |
*/ |
4378 |
- class_node_comment.prototype.compile = function (depth) { |
|
4379 |
- if (depth === void 0) { depth = 0; } |
|
4380 |
- return (lib_string.repeat("\t", depth) + "<!-- " + this.content + " -->" + "\n"); |
|
4381 |
- }; |
|
4382 |
- return class_node_comment; |
|
4383 |
- }(class_node)); |
|
4384 |
- lib_xml.class_node_comment = class_node_comment; |
|
5931 |
+ function make_line(head, attributes) { |
|
5932 |
+ let list = ((object => { |
|
5933 |
+ let list = []; |
|
5934 |
+ Object.keys(object).forEach(key => (list.push({ "key": key, "value": object[key] }))); |
|
5935 |
+ return list; |
|
5936 |
+ })(attributes)); |
|
5937 |
+ let attributes_ = list |
|
5938 |
+ .filter(entry => (entry.value != null)) |
|
5939 |
+ .map(entry => `${entry.key}="${entry.value}"`) |
|
5940 |
+ .join(", "); |
|
5941 |
+ return (`${head} [${attributes_}];`); |
|
5942 |
+ } |
|
4385 | 5943 |
/** |
4386 | 5944 |
* @author fenris |
4387 | 5945 |
*/ |
4388 |
- var class_node_complex = (function (_super) { |
|
4389 |
- __extends(class_node_complex, _super); |
|
5946 |
+ function format_line(line) { |
|
5947 |
+ return `\t${line}\n`; |
|
5948 |
+ } |
|
4390 | 5949 |
/** |
4391 | 5950 |
* @author fenris |
4392 | 5951 |
*/ |
4393 |
- function class_node_complex(name, attributes, children) { |
|
4394 |
- if (attributes === void 0) { attributes = {}; } |
|
4395 |
- if (children === void 0) { children = []; } |
|
4396 |
- var _this = _super.call(this) || this; |
|
4397 |
- _this.name = name; |
|
4398 |
- _this.attributes = attributes; |
|
4399 |
- _this.children = children; |
|
4400 |
- return _this; |
|
5952 |
+ function format_lines(lines) { |
|
5953 |
+ return lines.map(format_line).join(""); |
|
4401 | 5954 |
} |
4402 | 5955 |
/** |
4403 | 5956 |
* @author fenris |
4404 | 5957 |
*/ |
4405 |
- class_node_complex.prototype.compile = function (depth) { |
|
4406 |
- var _this = this; |
|
4407 |
- if (depth === void 0) { depth = 0; } |
|
4408 |
- var output = ""; |
|
4409 |
- var attributes = Object.keys(this.attributes).map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }).join(""); |
|
4410 |
- output += (lib_string.repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n"); |
|
4411 |
- this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); |
|
4412 |
- output += (lib_string.repeat("\t", depth) + "</" + this.name + ">" + "\n"); |
|
5958 |
+ function generate_graph(graphdefinition) { |
|
5959 |
+ let attributes = {}; |
|
5960 |
+ if (graphdefinition.fontname != undefined) { |
|
5961 |
+ attributes["fontname"] = graphdefinition.fontname; |
|
5962 |
+ } |
|
5963 |
+ if (graphdefinition.dimensions != undefined) { |
|
5964 |
+ attributes["dimen"] = graphdefinition.dimensions.toFixed(0); |
|
5965 |
+ } |
|
5966 |
+ if (graphdefinition.bgcolor != undefined) { |
|
5967 |
+ attributes["bgcolor"] = graphdefinition.bgcolor; |
|
5968 |
+ } |
|
5969 |
+ return format_lines([make_line("graph", attributes)] |
|
5970 |
+ .concat([])); |
|
5971 |
+ } |
|
5972 |
+ /** |
|
5973 |
+ * @author fenris |
|
5974 |
+ */ |
|
5975 |
+ function generate_nodes(nodedefinition) { |
|
5976 |
+ return format_lines([make_line("node", nodedefinition.head)] |
|
5977 |
+ .concat(nodedefinition.list.map(node => make_line(node.id, node.attributes)))); |
|
5978 |
+ } |
|
5979 |
+ /** |
|
5980 |
+ * @author fenris |
|
5981 |
+ */ |
|
5982 |
+ function generate_edges(edgedefinition, directed) { |
|
5983 |
+ let connector = (directed ? "->" : "--"); |
|
5984 |
+ return format_lines([make_line("edge", edgedefinition.head)] |
|
5985 |
+ .concat(edgedefinition.list.map(edge => make_line(`${edge.id_from} ${connector} ${edge.id_to}`, edge.attributes)))); |
|
5986 |
+ } |
|
5987 |
+ /** |
|
5988 |
+ * @author fenris |
|
5989 |
+ */ |
|
5990 |
+ function generate({ "name": name = null, "directed": directed = true, "common": graphdefinition = {}, "nodes": nodedefinition, "edges": edgedefinition } = {}) { |
|
5991 |
+ let output = ""; |
|
5992 |
+ output += ((directed ? "digraph" : "graph") + ((name == null) ? "" : (" " + name)) + "\n"); |
|
5993 |
+ output += `{\n`; |
|
5994 |
+ output += generate_graph(graphdefinition); |
|
5995 |
+ output += `\t\n`; |
|
5996 |
+ output += generate_nodes(nodedefinition); |
|
5997 |
+ output += `\t\n`; |
|
5998 |
+ output += generate_edges(edgedefinition, directed); |
|
5999 |
+ output += `}\n`; |
|
4413 | 6000 |
return output; |
4414 |
- }; |
|
4415 |
- return class_node_complex; |
|
4416 |
- }(class_node)); |
|
4417 |
- lib_xml.class_node_complex = class_node_complex; |
|
4418 |
-})(lib_xml || (lib_xml = {})); |
|
4419 |
-var __extends = (this && this.__extends) || function (d, b) { |
|
4420 |
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; |
|
6001 |
+ } |
|
6002 |
+ lib_dot.generate = generate; |
|
6003 |
+})(lib_dot || (lib_dot = {})); |
|
6004 |
+var __extends = (this && this.__extends) || (function () { |
|
6005 |
+ var extendStatics = Object.setPrototypeOf || |
|
6006 |
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
6007 |
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
6008 |
+ return function (d, b) { |
|
6009 |
+ extendStatics(d, b); |
|
4421 | 6010 |
function __() { this.constructor = d; } |
4422 | 6011 |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
4423 | 6012 |
}; |
4424 |
-var lib_path; |
|
4425 |
-(function (lib_path) { |
|
6013 |
+})(); |
|
6014 |
+var lib_structures; |
|
6015 |
+(function (lib_structures) { |
|
4426 | 6016 |
/** |
4427 | 6017 |
* @author fenris |
4428 | 6018 |
*/ |
4429 |
- var class_step = (function () { |
|
4430 |
- function class_step() { |
|
4431 |
- } |
|
4432 |
- return class_step; |
|
4433 |
- }()); |
|
4434 |
- lib_path.class_step = class_step; |
|
6019 |
+ var class_pair = (function () { |
|
4435 | 6020 |
/** |
4436 | 6021 |
* @author fenris |
4437 | 6022 |
*/ |
4438 |
- var class_step_stay = (function (_super) { |
|
4439 |
- __extends(class_step_stay, _super); |
|
4440 |
- function class_step_stay() { |
|
4441 |
- return _super !== null && _super.apply(this, arguments) || this; |
|
6023 |
+ function class_pair(first, second) { |
|
6024 |
+ this.first = first; |
|
6025 |
+ this.second = second; |
|
4442 | 6026 |
} |
4443 | 6027 |
/** |
6028 |
+ * @desc [accessor] [getter] |
|
4444 | 6029 |
* @author fenris |
4445 | 6030 |
*/ |
4446 |
- class_step_stay.prototype.invert = function () { |
|
4447 |
- return (new class_step_stay()); |
|
6031 |
+ class_pair.prototype.first_get = function () { |
|
6032 |
+ return this.first; |
|
4448 | 6033 |
}; |
4449 | 6034 |
/** |
6035 |
+ * @desc [accessor] [getter] |
|
4450 | 6036 |
* @author fenris |
4451 | 6037 |
*/ |
4452 |
- class_step_stay.prototype.toString = function () { |
|
4453 |
- return "."; |
|
6038 |
+ class_pair.prototype.second_get = function () { |
|
6039 |
+ return this.second; |
|
4454 | 6040 |
}; |
4455 |
- return class_step_stay; |
|
4456 |
- }(class_step)); |
|
4457 |
- lib_path.class_step_stay = class_step_stay; |
|
4458 | 6041 |
/** |
6042 |
+ * @desc [mutator] [setter] |
|
4459 | 6043 |
* @author fenris |
4460 | 6044 |
*/ |
4461 |
- var class_step_back = (function (_super) { |
|
4462 |
- __extends(class_step_back, _super); |
|
4463 |
- function class_step_back() { |
|
4464 |
- return _super !== null && _super.apply(this, arguments) || this; |
|
4465 |
- } |
|
6045 |
+ class_pair.prototype.first_set = function (first) { |
|
6046 |
+ this.first = first; |
|
6047 |
+ }; |
|
4466 | 6048 |
/** |
6049 |
+ * @desc [mutator] [setter] |
|
4467 | 6050 |
* @author fenris |
4468 | 6051 |
*/ |
4469 |
- class_step_back.prototype.invert = function () { |
|
4470 |
- throw (new Error("impossible")); |
|
6052 |
+ class_pair.prototype.second_set = function (second) { |
|
6053 |
+ this.second = second; |
|
4471 | 6054 |
}; |
4472 | 6055 |
/** |
6056 |
+ * @desc [accessor] |
|
4473 | 6057 |
* @author fenris |
4474 | 6058 |
*/ |
4475 |
- class_step_back.prototype.toString = function () { |
|
4476 |
- return ".."; |
|
6059 |
+ class_pair.prototype.swap = function () { |
|
6060 |
+ return (new class_pair(this.second, this.first)); |
|
4477 | 6061 |
}; |
4478 |
- return class_step_back; |
|
4479 |
- }(class_step)); |
|
4480 |
- lib_path.class_step_back = class_step_back; |
|
4481 | 6062 |
/** |
6063 |
+ * @desc [accessor] |
|
4482 | 6064 |
* @author fenris |
4483 | 6065 |
*/ |
4484 |
- var class_step_regular = (function (_super) { |
|
4485 |
- __extends(class_step_regular, _super); |
|
6066 |
+ class_pair.prototype.transform = function (transform_first, transform_second) { |
|
6067 |
+ return (new class_pair(transform_first(this.first), transform_second(this.second))); |
|
6068 |
+ }; |
|
4486 | 6069 |
/** |
6070 |
+ * @desc [accessor] [implementation] |
|
4487 | 6071 |
* @author fenris |
4488 | 6072 |
*/ |
4489 |
- function class_step_regular(name) { |
|
4490 |
- var _this = _super.call(this) || this; |
|
4491 |
- _this.name = name; |
|
4492 |
- return _this; |
|
4493 |
- } |
|
6073 |
+ class_pair.prototype._clone = function () { |
|
6074 |
+ return (new class_pair(instance_clone(this.first), instance_clone(this.second))); |
|
6075 |
+ }; |
|
4494 | 6076 |
/** |
6077 |
+ * @desc [accessor] [implementation] |
|
4495 | 6078 |
* @author fenris |
4496 | 6079 |
*/ |
4497 |
- class_step_regular.prototype.invert = function () { |
|
4498 |
- return (new class_step_back()); |
|
6080 |
+ class_pair.prototype._hash = function () { |
|
6081 |
+ return ("pair_" + instance_hash(this.first) + "_" + instance_hash(this.second) + ""); |
|
4499 | 6082 |
}; |
4500 | 6083 |
/** |
6084 |
+ * @desc [accessor] [implementation] |
|
4501 | 6085 |
* @author fenris |
4502 | 6086 |
*/ |
4503 |
- class_step_regular.prototype.toString = function () { |
|
4504 |
- return this.name; |
|
6087 |
+ class_pair.prototype._collate = function (pair) { |
|
6088 |
+ return (instance_collate(this.first, pair.first) |
|
6089 |
+ && |
|
6090 |
+ instance_collate(this.second, pair.second)); |
|
4505 | 6091 |
}; |
4506 |
- return class_step_regular; |
|
4507 |
- }(class_step)); |
|
4508 |
- lib_path.class_step_regular = class_step_regular; |
|
4509 | 6092 |
/** |
6093 |
+ * @desc [accessor] [implementation] |
|
4510 | 6094 |
* @author fenris |
4511 | 6095 |
*/ |
4512 |
- function step_read(s) { |
|
4513 |
- switch (s) { |
|
4514 |
- case ".": { |
|
4515 |
- return (new class_step_stay()); |
|
4516 |
- } |
|
4517 |
- case "..": { |
|
4518 |
- return (new class_step_back()); |
|
4519 |
- } |
|
4520 |
- default: { |
|
4521 |
- return (new class_step_regular(s)); |
|
4522 |
- } |
|
4523 |
- } |
|
4524 |
- } |
|
4525 |
- lib_path.step_read = step_read; |
|
4526 |
-})(lib_path || (lib_path = {})); |
|
4527 |
-///<reference path="../../../plankton/object/build/logic-decl.d.ts"/> |
|
4528 |
-var lib_path; |
|
4529 |
-(function (lib_path) { |
|
6096 |
+ class_pair.prototype._show = function () { |
|
6097 |
+ return ("(" + instance_show(this.first) + "," + instance_show(this.second) + ")"); |
|
6098 |
+ }; |
|
6099 |
+ return class_pair; |
|
6100 |
+ }()); |
|
6101 |
+ lib_structures.class_pair = class_pair; |
|
6102 |
+})(lib_structures || (lib_structures = {})); |
|
6103 |
+var lib_structures; |
|
6104 |
+(function (lib_structures) { |
|
4530 | 6105 |
/** |
4531 | 6106 |
* @author fenris |
4532 | 6107 |
*/ |
4533 |
- var class_chain = (function () { |
|
6108 |
+ var class_set = (function () { |
|
4534 | 6109 |
/** |
4535 | 6110 |
* @author fenris |
4536 | 6111 |
*/ |
4537 |
- function class_chain(steps) { |
|
4538 |
- if (steps === void 0) { steps = []; } |
|
4539 |
- this.steps = steps; |
|
6112 |
+ function class_set(elements_, equality /*<type_element>*/) { |
|
6113 |
+ if (elements_ === void 0) { elements_ = []; } |
|
6114 |
+ if (equality === void 0) { equality = instance_collate; } /*<type_element>*/ |
|
6115 |
+ var _this = this; |
|
6116 |
+ this.elements = []; |
|
6117 |
+ this.equality = equality; |
|
6118 |
+ elements_.forEach(function (element) { return _this.add(element); }); |
|
4540 | 6119 |
} |
4541 | 6120 |
/** |
6121 |
+ * @desc [accessor] |
|
4542 | 6122 |
* @author fenris |
4543 | 6123 |
*/ |
4544 |
- class_chain.splitter = function (system) { |
|
4545 |
- if (system === void 0) { system = "linux"; } |
|
4546 |
- return (object_fetch({ |
|
4547 |
- "linux": "/", |
|
4548 |
- "bsd": "/", |
|
4549 |
- "win": "\\" |
|
4550 |
- }, system, "/", 2)); |
|
6124 |
+ class_set.prototype.size = function () { |
|
6125 |
+ return this.elements.length; |
|
4551 | 6126 |
}; |
4552 | 6127 |
/** |
4553 |
- * @desc removes superfluent steps from the chain, e.g. infix ".." |
|
6128 |
+ * @desc [accessor] |
|
4554 | 6129 |
* @author fenris |
4555 | 6130 |
*/ |
4556 |
- class_chain.prototype.normalize = function () { |
|
4557 |
- var steps = this.steps; |
|
4558 |
- // filter "stay" |
|
4559 |
- { |
|
4560 |
- steps = steps.filter(function (step) { return (!(step instanceof lib_path.class_step_stay)); }); |
|
4561 |
- } |
|
4562 |
- // filter "regular-back" |
|
4563 |
- { |
|
4564 |
- var _loop_1 = function () { |
|
4565 |
- if (steps.length < 1) { |
|
4566 |
- return "break"; |
|
4567 |
- } |
|
4568 |
- else { |
|
4569 |
- var last_1 = steps[0]; |
|
4570 |
- var found = steps.slice(1).some(function (step, index) { |
|
4571 |
- if (step instanceof lib_path.class_step_back) { |
|
4572 |
- if (last_1 instanceof lib_path.class_step_regular) { |
|
4573 |
- steps.splice(index, 2); |
|
4574 |
- return true; |
|
4575 |
- } |
|
4576 |
- } |
|
4577 |
- last_1 = step; |
|
4578 |
- return false; |
|
4579 |
- }); |
|
4580 |
- if (!found) { |
|
4581 |
- return "break"; |
|
4582 |
- } |
|
6131 |
+ class_set.prototype.has = function (element) { |
|
6132 |
+ var _this = this; |
|
6133 |
+ return this.elements.some(function (element_) { return _this.equality(element, element_); }); |
|
6134 |
+ }; |
|
6135 |
+ /** |
|
6136 |
+ * @desc [mutator] |
|
6137 |
+ * @author fenris |
|
6138 |
+ */ |
|
6139 |
+ class_set.prototype.add = function (element) { |
|
6140 |
+ if (!this.has(element)) { |
|
6141 |
+ this.elements.push(element); |
|
4583 | 6142 |
} |
4584 | 6143 |
}; |
4585 |
- while (true) { |
|
4586 |
- var state_1 = _loop_1(); |
|
4587 |
- if (state_1 === "break") |
|
4588 |
- break; |
|
6144 |
+ /** |
|
6145 |
+ * @desc [mutator] |
|
6146 |
+ * @author fenris |
|
6147 |
+ */ |
|
6148 |
+ class_set.prototype.pop = function () { |
|
6149 |
+ if (this.elements.length == 0) { |
|
6150 |
+ return (new class_nothing()); |
|
4589 | 6151 |
} |
6152 |
+ else { |
|
6153 |
+ return (new class_just(this.elements.pop())); |
|
4590 | 6154 |
} |
4591 |
- return (new class_chain(steps)); |
|
4592 | 6155 |
}; |
4593 | 6156 |
/** |
6157 |
+ * @desc [accessor] |
|
4594 | 6158 |
* @author fenris |
4595 | 6159 |
*/ |
4596 |
- class_chain.prototype.invert = function () { |
|
4597 |
- return (new class_chain(this.steps.map(function (step) { return step.invert(); }))); |
|
6160 |
+ class_set.prototype.forEach = function (function_) { |
|
6161 |
+ this.elements.forEach(function (element) { return function_(element); }); |
|
4598 | 6162 |
}; |
4599 | 6163 |
/** |
6164 |
+ * @desc [accessor] |
|
4600 | 6165 |
* @author fenris |
4601 | 6166 |
*/ |
4602 |
- class_chain.prototype.add = function (step) { |
|
4603 |
- return (new class_chain(this.steps.concat([step]))).normalize(); |
|
6167 |
+ class_set.prototype.map = function (transformator) { |
|
6168 |
+ return (new class_set(this.elements.map(transformator))); |
|
4604 | 6169 |
}; |
4605 | 6170 |
/** |
6171 |
+ * @desc [accessor] |
|
4606 | 6172 |
* @author fenris |
4607 | 6173 |
*/ |
4608 |
- class_chain.prototype.extend = function (chain) { |
|
4609 |
- return (new class_chain(this.steps.concat(chain.steps))).normalize(); |
|
6174 |
+ class_set.prototype.filter = function (predicate) { |
|
6175 |
+ return (new class_set(this.elements.filter(predicate))); |
|
4610 | 6176 |
}; |
4611 | 6177 |
/** |
6178 |
+ * @desc [accessor] |
|
4612 | 6179 |
* @author fenris |
4613 | 6180 |
*/ |
4614 |
- class_chain.prototype.as_string = function (system) { |
|
4615 |
- if (system === void 0) { system = "linux"; } |
|
4616 |
- var splitter = class_chain.splitter(system); |
|
4617 |
- return ((this.steps.length == 0) ? ("." + splitter) : this.steps.map(function (step) { return (step.toString() + splitter); }).join("")); |
|
6181 |
+ class_set.prototype.dump = function () { |
|
6182 |
+ return this.elements; |
|
4618 | 6183 |
}; |
4619 | 6184 |
/** |
6185 |
+ * @desc [accessor] |
|
4620 | 6186 |
* @author fenris |
4621 | 6187 |
*/ |
4622 |
- class_chain.prototype.toString = function () { |
|
4623 |
- return this.as_string(); |
|
6188 |
+ class_set.prototype.subset = function (set) { |
|
6189 |
+ var _this = this; |
|
6190 |
+ return set.elements.every(function (element) { return _this.has(element); }); |
|
4624 | 6191 |
}; |
4625 |
- return class_chain; |
|
4626 |
- }()); |
|
4627 |
- lib_path.class_chain = class_chain; |
|
4628 | 6192 |
/** |
6193 |
+ * @desc [accessor] |
|
4629 | 6194 |
* @author fenris |
4630 | 6195 |
*/ |
4631 |
- function chain_read(str, system) { |
|
4632 |
- if (system === void 0) { system = "linux"; } |
|
4633 |
- var splitter = class_chain.splitter(system); |
|
4634 |
- var parts = str.split(splitter); |
|
4635 |
- if (parts[parts.length - 1] == "") |
|
4636 |
- parts.pop(); |
|
4637 |
- return (new class_chain(parts.map(lib_path.step_read))); |
|
4638 |
- } |
|
4639 |
- lib_path.chain_read = chain_read; |
|
4640 |
-})(lib_path || (lib_path = {})); |
|
4641 |
-///<reference path="../../../plankton/object/build/logic-decl.d.ts"/> |
|
4642 |
-var lib_path; |
|
4643 |
-(function (lib_path) { |
|
6196 |
+ class_set.prototype.superset = function (set) { |
|
6197 |
+ return this.elements.every(function (element) { return set.has(element); }); |
|
6198 |
+ }; |
|
4644 | 6199 |
/** |
6200 |
+ * @desc [accessor] |
|
4645 | 6201 |
* @author fenris |
4646 | 6202 |
*/ |
4647 |
- var class_location = (function () { |
|
6203 |
+ class_set.prototype.equals = function (set) { |
|
6204 |
+ return (this.subset(set) && this.superset(set)); |
|
6205 |
+ }; |
|
4648 | 6206 |
/** |
6207 |
+ * @desc [accessor] |
|
4649 | 6208 |
* @author fenris |
4650 | 6209 |
*/ |
4651 |
- function class_location(anchor, chain) { |
|
4652 |
- this.anchor = anchor; |
|
4653 |
- this.chain = chain; |
|
4654 |
- } |
|
6210 |
+ class_set.prototype.toString = function () { |
|
6211 |
+ return ("{" + this.elements.map(instance_show /*<type_element>*/).join(",") + "}"); |
|
6212 |
+ }; |
|
4655 | 6213 |
/** |
6214 |
+ * @desc [accessor] |
|
4656 | 6215 |
* @author fenris |
4657 | 6216 |
*/ |
4658 |
- class_location.anchorpattern = function (system) { |
|
4659 |
- if (system === void 0) { system = "linux"; } |
|
4660 |
- return (object_fetch({ |
|
4661 |
- "linux": new RegExp("/"), |
|
4662 |
- "bsd": new RegExp("/"), |
|
4663 |
- "win": new RegExp("[A-Z]:\\\\>") |
|
4664 |
- }, system, new RegExp("/"), 1)); |
|
6217 |
+ class_set.prototype.empty = function () { |
|
6218 |
+ return (this.elements.length == 0); |
|
4665 | 6219 |
}; |
4666 | 6220 |
/** |
4667 | 6221 |
* @desc [accessor] |
4668 | 6222 |
* @author fenris |
4669 | 6223 |
*/ |
4670 |
- class_location.prototype.is_absolute = function () { |
|
4671 |
- return (this.anchor != null); |
|
6224 |
+ class_set.prototype.union = function (set) { |
|
6225 |
+ var set_ = new class_set([], this.equality); |
|
6226 |
+ this.elements.forEach(function (element) { return set_.add(element); }); |
|
6227 |
+ set.elements.forEach(function (element) { return set_.add(element); }); |
|
6228 |
+ return set_; |
|
4672 | 6229 |
}; |
4673 | 6230 |
/** |
6231 |
+ * @desc [accessor] |
|
4674 | 6232 |
* @author fenris |
4675 | 6233 |
*/ |
4676 |
- class_location.prototype.normalize = function () { |
|
4677 |
- return (new class_location(this.anchor, this.chain.normalize())); |
|
6234 |
+ class_set.prototype.intersection = function (set) { |
|
6235 |
+ var set_ = new class_set([], this.equality); |
|
6236 |
+ this.elements |
|
6237 |
+ .filter(function (element) { return set.has(element); }) |
|
6238 |
+ .forEach(function (element) { return set_.add(element); }); |
|
6239 |
+ return set_; |
|
4678 | 6240 |
}; |
4679 | 6241 |
/** |
6242 |
+ * @desc [accessor] |
|
4680 | 6243 |
* @author fenris |
4681 | 6244 |
*/ |
4682 |
- class_location.prototype.extend = function (chain) { |
|
4683 |
- return (new class_location(this.anchor, this.chain.extend(chain))); |
|
6245 |
+ class_set.prototype.difference = function (set) { |
|
6246 |
+ var set_ = new class_set([], this.equality); |
|
6247 |
+ this.elements |
|
6248 |
+ .filter(function (element) { return !set.has(element); }) |
|
6249 |
+ .forEach(function (element) { return set_.add(element); }); |
|
6250 |
+ return set_; |
|
4684 | 6251 |
}; |
4685 | 6252 |
/** |
4686 | 6253 |
* @desc [accessor] |
4687 | 6254 |
* @author fenris |
4688 | 6255 |
*/ |
4689 |
- class_location.prototype.relocate = function (location) { |
|
4690 |
- if (this.is_absolute()) { |
|
4691 |
- return (new class_location(this.anchor, this.chain)); |
|
4692 |
- } |
|
4693 |
- else { |
|
4694 |
- return location.extend(this.chain); |
|
4695 |
- } |
|
6256 |
+ class_set.prototype.symmetric_difference = function (set) { |
|
6257 |
+ return this.difference(set).union(set.difference(this)); |
|
4696 | 6258 |
}; |
4697 | 6259 |
/** |
6260 |
+ * @desc [accessor] [implementation] |
|
4698 | 6261 |
* @author fenris |
4699 | 6262 |
*/ |
4700 |
- class_location.prototype.go_thither = function () { |
|
4701 |
- // console.error(">>", this.toString()); |
|
4702 |
- process.chdir(this.toString()); |
|
6263 |
+ class_set.prototype._collate = function (set) { |
|
6264 |
+ return this.equals(set); |
|
4703 | 6265 |
}; |
4704 | 6266 |
/** |
6267 |
+ * @desc [accessor] [implementation] |
|
4705 | 6268 |
* @author fenris |
4706 | 6269 |
*/ |
4707 |
- class_location.prototype.expedition = function (core) { |
|
4708 |
- var that = this; |
|
4709 |
- var current = location_read(process.cwd()); |
|
4710 |
- function begin() { |
|
4711 |
- // (new class_message("changing directory to '" + that.toString() + "'")).stderr(); |
|
4712 |
- that.go_thither(); |
|
6270 |
+ class_set.prototype._show = function () { |
|
6271 |
+ return this.toString(); |
|
6272 |
+ }; |
|
6273 |
+ /** |
|
6274 |
+ * @author fenris |
|
6275 |
+ */ |
|
6276 |
+ class_set.union_all = function (sets) { |
|
6277 |
+ return (sets.reduce(function (x, y) { return ((x == null) ? y : x.union(y)); }, null)); |
|
6278 |
+ }; |
|
6279 |
+ /** |
|
6280 |
+ * @author fenris |
|
6281 |
+ */ |
|
6282 |
+ class_set.intersection_all = function (sets) { |
|
6283 |
+ return (sets.reduce(function (x, y) { return ((x == null) ? y : x.intersection(y)); }, null)); |
|
6284 |
+ }; |
|
6285 |
+ return class_set; |
|
6286 |
+ }()); |
|
6287 |
+ lib_structures.class_set = class_set; |
|
6288 |
+})(lib_structures || (lib_structures = {})); |
|
6289 |
+var lib_structures; |
|
6290 |
+(function (lib_structures) { |
|
6291 |
+ /** |
|
6292 |
+ * @author fenris |
|
6293 |
+ */ |
|
6294 |
+ var class_map_abstract = (function () { |
|
6295 |
+ function class_map_abstract() { |
|
4713 | 6296 |
} |
4714 |
- function end() { |
|
4715 |
- // (new class_message("changing directory to '" + current.toString() + "'")).stderr(); |
|
4716 |
- current.go_thither(); |
|
6297 |
+ /** |
|
6298 |
+ * @desc [mutator] [syntactic sugar] |
|
6299 |
+ * @author fenris |
|
6300 |
+ */ |
|
6301 |
+ class_map_abstract.prototype.del = function (key) { |
|
6302 |
+ return this["delete"](key); |
|
6303 |
+ }; |
|
6304 |
+ /** |
|
6305 |
+ * @desc [accessor] |
|
6306 |
+ * @author fenris |
|
6307 |
+ */ |
|
6308 |
+ class_map_abstract.prototype.map = function (transformator) { |
|
6309 |
+ var map_ = this.spawn(); |
|
6310 |
+ this.forEach(function (value, key) { |
|
6311 |
+ var value_ = transformator(value); |
|
6312 |
+ map_.set(key, value_); |
|
6313 |
+ }); |
|
6314 |
+ return map_; |
|
6315 |
+ }; |
|
6316 |
+ /** |
|
6317 |
+ * @desc [accessor] |
|
6318 |
+ * @author fenris |
|
6319 |
+ */ |
|
6320 |
+ class_map_abstract.prototype.filter = function (predicate) { |
|
6321 |
+ var map_ = this.spawn(); |
|
6322 |
+ this.forEach(function (value, key) { |
|
6323 |
+ if (predicate(value)) { |
|
6324 |
+ map_.set(key, value); |
|
4717 | 6325 |
} |
4718 |
- begin(); |
|
4719 |
- core(end); |
|
6326 |
+ }); |
|
6327 |
+ return map_; |
|
6328 |
+ }; |
|
6329 |
+ /** |
|
6330 |
+ * @desc [accessor] |
|
6331 |
+ * @author fenris |
|
6332 |
+ */ |
|
6333 |
+ class_map_abstract.prototype.pairs = function () { |
|
6334 |
+ var set = new lib_structures.class_set(); |
|
6335 |
+ this.forEach(function (value, key) { |
|
6336 |
+ set.add(new lib_structures.class_pair(key, value)); |
|
6337 |
+ }); |
|
6338 |
+ return set; |
|
6339 |
+ }; |
|
6340 |
+ /** |
|
6341 |
+ * @desc [accessor] |
|
6342 |
+ * @author fenris |
|
6343 |
+ */ |
|
6344 |
+ class_map_abstract.prototype.keys = function () { |
|
6345 |
+ var set = new lib_structures.class_set(); |
|
6346 |
+ this.forEach(function (value, key) { |
|
6347 |
+ set.add(key); |
|
6348 |
+ }); |
|
6349 |
+ return set; |
|
4720 | 6350 |
}; |
4721 | 6351 |
/** |
6352 |
+ * @desc [accessor] |
|
4722 | 6353 |
* @author fenris |
4723 | 6354 |
*/ |
4724 |
- class_location.prototype.as_string = function (system) { |
|
4725 |
- if (system === void 0) { system = "linux"; } |
|
4726 |
- return (((this.anchor != null) ? this.anchor : "") + this.chain.as_string(system)); |
|
6355 |
+ class_map_abstract.prototype.values = function () { |
|
6356 |
+ var set = new lib_structures.class_set(); |
|
6357 |
+ this.forEach(function (value, key) { |
|
6358 |
+ set.add(value); |
|
6359 |
+ }); |
|
6360 |
+ return set; |
|
4727 | 6361 |
}; |
6362 |
+ return class_map_abstract; |
|
6363 |
+ }()); |
|
6364 |
+ lib_structures.class_map_abstract = class_map_abstract; |
|
4728 | 6365 |
/** |
4729 | 6366 |
* @author fenris |
4730 | 6367 |
*/ |
4731 |
- class_location.prototype.toString = function () { |
|
4732 |
- return this.as_string(); |
|
6368 |
+ var class_map_simple = (function (_super) { |
|
6369 |
+ __extends(class_map_simple, _super); |
|
6370 |
+ /** |
|
6371 |
+ * @author fenris |
|
6372 |
+ */ |
|
6373 |
+ function class_map_simple() { |
|
6374 |
+ var _this = _super.call(this) || this; |
|
6375 |
+ _this.object = {}; |
|
6376 |
+ return _this; |
|
6377 |
+ } |
|
6378 |
+ /** |
|
6379 |
+ * @desc [accessor] |
|
6380 |
+ * @author fenris |
|
6381 |
+ */ |
|
6382 |
+ class_map_simple.from_object = function (object) { |
|
6383 |
+ var map = new class_map_simple(); |
|
6384 |
+ Object.keys(object).forEach(function (key) { return map.set(key, object[key]); }); |
|
6385 |
+ return map; |
|
4733 | 6386 |
}; |
4734 | 6387 |
/** |
6388 |
+ * @override |
|
4735 | 6389 |
* @author fenris |
4736 | 6390 |
*/ |
4737 |
- class_location.current = function () { |
|
4738 |
- // return class_location.read(process.cwd()); |
|
4739 |
- return location_read(process.cwd()); |
|
6391 |
+ class_map_simple.prototype.spawn = function () { |
|
6392 |
+ return (new class_map_simple()); |
|
4740 | 6393 |
}; |
4741 | 6394 |
/** |
6395 |
+ * @override |
|
4742 | 6396 |
* @author fenris |
4743 | 6397 |
*/ |
4744 |
- class_location.tempfolder = function (system) { |
|
4745 |
- if (system === void 0) { system = "linux"; } |
|
4746 |
- return (object_fetch({ |
|
4747 |
- "linux": new class_location("/", new lib_path.class_chain([new lib_path.class_step_regular("tmp")])), |
|
4748 |
- "bsd": new class_location("/", new lib_path.class_chain([new lib_path.class_step_regular("tmp")])), |
|
4749 |
- "win": new class_location(null, new lib_path.class_chain([new lib_path.class_step_regular("%TEMP%")])) |
|
4750 |
- }, system, null, 2)); |
|
6398 |
+ class_map_simple.prototype.has = function (key) { |
|
6399 |
+ return (key in this.object); |
|
4751 | 6400 |
}; |
4752 |
- return class_location; |
|
4753 |
- }()); |
|
4754 |
- lib_path.class_location = class_location; |
|
4755 | 6401 |
/** |
6402 |
+ * @override |
|
4756 | 6403 |
* @author fenris |
4757 | 6404 |
*/ |
4758 |
- function location_read(str, system) { |
|
4759 |
- if (system === void 0) { system = "linux"; } |
|
4760 |
- var regexp = class_location.anchorpattern(system); |
|
4761 |
- var matching = regexp.exec(str); |
|
4762 |
- if ((matching == null) || (matching.index > 0)) { |
|
4763 |
- return (new class_location(null, lib_path.chain_read(str, system))); |
|
6405 |
+ class_map_simple.prototype.get = function (key, strict, fallback) { |
|
6406 |
+ if (this.has(key)) { |
|
6407 |
+ return this.object[key]; |
|
4764 | 6408 |
} |
4765 | 6409 |
else { |
4766 |
- return (new class_location(matching[0], lib_path.chain_read(str.slice(matching[0].length), system))); |
|
6410 |
+ if (strict) { |
|
6411 |
+ throw (new Error("key not found")); |
|
4767 | 6412 |
} |
6413 |
+ else { |
|
6414 |
+ return fallback; |
|
4768 | 6415 |
} |
4769 |
- lib_path.location_read = location_read; |
|
4770 |
-})(lib_path || (lib_path = {})); |
|
4771 |
-var lib_path; |
|
4772 |
-(function (lib_path) { |
|
6416 |
+ } |
|
6417 |
+ }; |
|
4773 | 6418 |
/** |
6419 |
+ * @override |
|
4774 | 6420 |
* @author fenris |
4775 | 6421 |
*/ |
4776 |
- var class_filepointer = (function () { |
|
6422 |
+ class_map_simple.prototype.set = function (key, value) { |
|
6423 |
+ this.object[key] = value; |
|
6424 |
+ }; |
|
4777 | 6425 |
/** |
6426 |
+ * @override |
|
4778 | 6427 |
* @author fenris |
4779 | 6428 |
*/ |
4780 |
- function class_filepointer(location, filename) { |
|
4781 |
- this.location = location; |
|
4782 |
- this.filename = filename; |
|
4783 |
- } |
|
6429 |
+ class_map_simple.prototype.clear = function () { |
|
6430 |
+ this.object = {}; |
|
6431 |
+ }; |
|
4784 | 6432 |
/** |
6433 |
+ * @override |
|
4785 | 6434 |
* @author fenris |
4786 | 6435 |
*/ |
4787 |
- class_filepointer.prototype.normalize = function () { |
|
4788 |
- return (new class_filepointer(this.location.normalize(), this.filename)); |
|
6436 |
+ class_map_simple.prototype["delete"] = function (key) { |
|
6437 |
+ delete this.object[key]; |
|
4789 | 6438 |
}; |
4790 | 6439 |
/** |
6440 |
+ * @override |
|
4791 | 6441 |
* @author fenris |
4792 | 6442 |
*/ |
4793 |
- class_filepointer.prototype.foo = function (filepointer) { |
|
4794 |
- return (new class_filepointer(this.location.extend(filepointer.location.chain), filepointer.filename)); |
|
6443 |
+ class_map_simple.prototype.forEach = function (function_) { |
|
6444 |
+ var _this = this; |
|
6445 |
+ Object.keys(this.object).forEach(function (key) { |
|
6446 |
+ var value = _this.object[key]; |
|
6447 |
+ function_(value, key); |
|
6448 |
+ }); |
|
4795 | 6449 |
}; |
4796 | 6450 |
/** |
4797 | 6451 |
* @desc [accessor] |
4798 | 6452 |
* @author fenris |
6453 |
+ * @todo implement |
|
4799 | 6454 |
*/ |
4800 |
- class_filepointer.prototype.relocate = function (location) { |
|
4801 |
- return (new class_filepointer(this.location.relocate(location), this.filename)); |
|
6455 |
+ /* |
|
6456 |
+ public equals(map : class_map_simple<type_value>) : boolean { |
|
6457 |
+ |
|
6458 |
+ } |
|
6459 |
+ */ |
|
6460 |
+ /** |
|
6461 |
+ * @desc [accessor] |
|
6462 |
+ * @author fenris |
|
6463 |
+ */ |
|
6464 |
+ class_map_simple.prototype.toString = function () { |
|
6465 |
+ return ("{" + this.pairs().map(function (pair) { return instance_show(pair.first_get()) + " -> " + instance_show(pair.second_get()); }).dump().join(", ") + "}"); |
|
4802 | 6466 |
}; |
4803 | 6467 |
/** |
6468 |
+ * @desc [accessor] [implementation] |
|
4804 | 6469 |
* @author fenris |
4805 | 6470 |
*/ |
4806 |
- class_filepointer.prototype.as_string = function (system) { |
|
4807 |
- if (system === void 0) { system = "linux"; } |
|
4808 |
- return (this.location.as_string(system) /* + "/"*/ + ((this.filename == null) ? "" : this.filename)); |
|
6471 |
+ class_map_simple.prototype._clone = function () { |
|
6472 |
+ return (this.map(function (value) { return instance_clone(value); })); |
|
4809 | 6473 |
}; |
4810 | 6474 |
/** |
6475 |
+ * @desc [accessor] [implementation] |
|
4811 | 6476 |
* @author fenris |
4812 | 6477 |
*/ |
4813 |
- class_filepointer.prototype.toString = function () { |
|
4814 |
- return this.as_string(); |
|
6478 |
+ class_map_simple.prototype._show = function () { |
|
6479 |
+ return this.toString(); |
|
4815 | 6480 |
}; |
4816 |
- return class_filepointer; |
|
4817 |
- }()); |
|
4818 |
- lib_path.class_filepointer = class_filepointer; |
|
6481 |
+ return class_map_simple; |
|
6482 |
+ }(class_map_abstract)); |
|
6483 |
+ lib_structures.class_map_simple = class_map_simple; |
|
4819 | 6484 |
/** |
4820 | 6485 |
* @author fenris |
4821 | 6486 |
*/ |
4822 |
- function filepointer_read(str, system) { |
|
4823 |
- if (system === void 0) { system = "linux"; } |
|
4824 |
- var splitter = lib_path.class_chain.splitter(system); |
|
4825 |
- var parts = str.split(splitter); |
|
4826 |
- var last = parts[parts.length - 1]; |
|
4827 |
- if (last == "") { |
|
4828 |
- return (new class_filepointer(lib_path.location_read(parts.join(splitter), system), null)); |
|
4829 |
- } |
|
4830 |
- else { |
|
4831 |
- return (new class_filepointer(lib_path.location_read(parts.slice(0, parts.length - 1).join(splitter), system), last)); |
|
4832 |
- } |
|
6487 |
+ var class_map_equality = (function (_super) { |
|
6488 |
+ __extends(class_map_equality, _super); |
|
6489 |
+ /** |
|
6490 |
+ * @author fenris |
|
6491 |
+ */ |
|
6492 |
+ function class_map_equality(collate /*<type_key>*/) { |
|
6493 |
+ if (collate === void 0) { collate = instance_collate; } /*<type_key>*/ |
|
6494 |
+ var _this = _super.call(this) || this; |
|
6495 |
+ _this.pairs_ = []; |
|
6496 |
+ _this.collate = collate; |
|
6497 |
+ return _this; |
|
4833 | 6498 |
} |
4834 |
- lib_path.filepointer_read = filepointer_read; |
|
4835 |
-})(lib_path || (lib_path = {})); |
|
4836 |
-///<reference path="../../call/build/logic-decl.d.ts"/> |
|
4837 |
-var lib_file; |
|
4838 |
-(function (lib_file) { |
|
4839 | 6499 |
/** |
6500 |
+ * @override |
|
4840 | 6501 |
* @author fenris |
4841 | 6502 |
*/ |
4842 |
- class class_file_abstract { |
|
6503 |
+ class_map_equality.prototype.spawn = function () { |
|
6504 |
+ return (new class_map_equality(this.collate)); |
|
6505 |
+ }; |
|
4843 | 6506 |
/** |
4844 |
- * @desc reads a json file |
|
6507 |
+ * @override |
|
4845 | 6508 |
* @author fenris |
4846 | 6509 |
*/ |
4847 |
- read_json(path) { |
|
4848 |
- return ((resolve, reject) => { |
|
4849 |
- lib_call.executor_chain({}, [ |
|
4850 |
- state => (resolve_, reject_) => { |
|
4851 |
- this.read(path)(content => { |
|
4852 |
- state.content = content; |
|
4853 |
- resolve_(state); |
|
4854 |
- }, reject_); |
|
4855 |
- }, |
|
4856 |
- state => (resolve_, reject_) => { |
|
4857 |
- let error; |
|
4858 |
- try { |
|
4859 |
- state.data = JSON.parse(state.content); |
|
4860 |
- error = null; |
|
4861 |
- } |
|
4862 |
- catch (exception) { |
|
4863 |
- error = new class_error("invalid json '" + path + "'", [exception]); |
|
4864 |
- } |
|
4865 |
- if (error == null) { |
|
4866 |
- resolve_(state); |
|
6510 |
+ class_map_equality.prototype.has = function (key) { |
|
6511 |
+ var _this = this; |
|
6512 |
+ return this.pairs_.some(function (pair) { return _this.collate(pair.first_get(), key); }); |
|
6513 |
+ }; |
|
6514 |
+ /** |
|
6515 |
+ * @override |
|
6516 |
+ * @author fenris |
|
6517 |
+ */ |
|
6518 |
+ class_map_equality.prototype.get = function (key, strict, fallback) { |
|
6519 |
+ var _this = this; |
|
6520 |
+ if (strict === void 0) { strict = false; } |
|
6521 |
+ if (fallback === void 0) { fallback = null; } |
|
6522 |
+ var value; |
|
6523 |
+ var found = this.pairs_.some(function (pair) { |
|
6524 |
+ if (_this.collate(pair.first_get(), key)) { |
|
6525 |
+ value = pair.second_get(); |
|
6526 |
+ return true; |
|
4867 | 6527 |
} |
4868 | 6528 |
else { |
4869 |
- reject_(error); |
|
6529 |
+ return false; |
|
4870 | 6530 |
} |
4871 |
- }, |
|
4872 |
- ])(state => resolve(state.data), reject); |
|
4873 | 6531 |
}); |
6532 |
+ if (!found) { |
|
6533 |
+ if (strict) { |
|
6534 |
+ throw (new Error("key not found")); |
|
4874 | 6535 |
} |
4875 |
- /** |
|
4876 |
- * @desc writes a json file |
|
4877 |
- * @author fenris |
|
4878 |
- */ |
|
4879 |
- write_json(path, data) { |
|
4880 |
- return this.write(path, JSON.stringify(data, undefined, "\t")); |
|
6536 |
+ else { |
|
6537 |
+ value = fallback; |
|
4881 | 6538 |
} |
4882 | 6539 |
} |
4883 |
- lib_file.class_file_abstract = class_file_abstract; |
|
4884 |
-})(lib_file || (lib_file = {})); |
|
4885 |
-///<reference path="../../call/build/logic-decl.d.ts"/> |
|
4886 |
-var lib_file; |
|
4887 |
-(function (lib_file) { |
|
6540 |
+ return value; |
|
6541 |
+ }; |
|
4888 | 6542 |
/** |
6543 |
+ * @override |
|
4889 | 6544 |
* @author fenris |
4890 | 6545 |
*/ |
4891 |
- class class_file_node extends lib_file.class_file_abstract { |
|
4892 |
- /** |
|
4893 |
- * @author maspr |
|
4894 |
- */ |
|
4895 |
- determine_handler(path) { |
|
4896 |
- if (/^https?:\/\//.test(path)) { |
|
4897 |
- return "http"; |
|
6546 |
+ class_map_equality.prototype.set = function (key, value) { |
|
6547 |
+ var _this = this; |
|
6548 |
+ var found = this.pairs_.some(function (pair) { |
|
6549 |
+ if (_this.collate(pair.first_get(), key)) { |
|
6550 |
+ pair.second_set(value); |
|
6551 |
+ return true; |
|
4898 | 6552 |
} |
4899 | 6553 |
else { |
4900 |
- return "file"; |
|
6554 |
+ return false; |
|
4901 | 6555 |
} |
6556 |
+ }); |
|
6557 |
+ if (!found) { |
|
6558 |
+ this.pairs_.push(new lib_structures.class_pair(key, value)); |
|
4902 | 6559 |
} |
6560 |
+ }; |
|
4903 | 6561 |
/** |
4904 | 6562 |
* @override |
4905 |
- * @author fenris,maspr |
|
4906 |
- * @todo clear up if http(s)-handling belongs here or not |
|
6563 |
+ * @author fenris |
|
4907 | 6564 |
*/ |
4908 |
- read(path, skip_error = false) { |
|
4909 |
- switch (this.determine_handler(path)) { |
|
4910 |
- case "file": |
|
4911 |
- { |
|
4912 |
- let nm_fs = require("fs"); |
|
4913 |
- return ((resolve, reject) => { |
|
4914 |
- nm_fs.readFile(path, { |
|
4915 |
- "encoding": "utf8", |
|
4916 |
- "flag": "r", |
|
4917 |
- }, (error, content) => { |
|
4918 |
- if (error == null) { |
|
4919 |
- resolve(content); |
|
6565 |
+ class_map_equality.prototype.clear = function () { |
|
6566 |
+ this.pairs_ = []; |
|
6567 |
+ }; |
|
6568 |
+ /** |
|
6569 |
+ * @override |
|
6570 |
+ * @author fenris |
|
6571 |
+ */ |
|
6572 |
+ class_map_equality.prototype["delete"] = function (key) { |
|
6573 |
+ var _this = this; |
|
6574 |
+ var index; |
|
6575 |
+ var found = this.pairs_.some(function (pair, index_) { |
|
6576 |
+ if (_this.collate(pair.first_get(), key)) { |
|
6577 |
+ index = index_; |
|
6578 |
+ return true; |
|
4920 | 6579 |
} |
4921 | 6580 |
else { |
4922 |
- reject(error); |
|
6581 |
+ return false; |
|
4923 | 6582 |
} |
4924 | 6583 |
}); |
4925 |
- }); |
|
6584 |
+ if (found) { |
|
6585 |
+ this.pairs_.splice(index, 1); |
|
4926 | 6586 |
} |
4927 |
- break; |
|
4928 |
- case "http": |
|
4929 |
- { |
|
4930 |
- return (resolve, reject) => { |
|
4931 |
- let nm_http = require("http"); |
|
4932 |
- let nm_https = require("https"); |
|
4933 |
- let nm_url = require("url"); |
|
4934 |
- let parsed_url = nm_url.parse(path, false, true); |
|
4935 |
- let client = (parsed_url.protocol == "https:") ? nm_https : nm_http; |
|
4936 |
- let default_port = ((parsed_url.protocol == "https:") ? 443 : 80); |
|
4937 |
- let options = { |
|
4938 |
- hostname: parsed_url.hostname, |
|
4939 |
- port: parsed_url.port || default_port, |
|
4940 |
- path: parsed_url.path, |
|
4941 |
- method: "GET" |
|
4942 | 6587 |
}; |
4943 |
- let req = client.request(options, (res) => { |
|
4944 |
- let data = ""; // @todo |
|
4945 |
- res.on("data", (chunk) => { |
|
4946 |
- data += chunk; |
|
4947 |
- }); |
|
4948 |
- res.on("end", () => { |
|
4949 |
- resolve(data); |
|
4950 |
- }); |
|
4951 |
- }); |
|
4952 |
- req.end(); |
|
4953 |
- req.on("error", (error) => { |
|
4954 |
- reject(error); |
|
4955 |
- }); |
|
6588 |
+ /** |
|
6589 |
+ * @desc [accessor] |
|
6590 |
+ * @author fenris |
|
6591 |
+ */ |
|
6592 |
+ class_map_equality.prototype.forEach = function (function_) { |
|
6593 |
+ this.pairs_.forEach(function (pair) { return function_(pair.second_get(), pair.first_get()); }); |
|
4956 | 6594 |
}; |
6595 |
+ return class_map_equality; |
|
6596 |
+ }(class_map_abstract)); |
|
6597 |
+ lib_structures.class_map_equality = class_map_equality; |
|
6598 |
+ /** |
|
6599 |
+ * @author fenris |
|
6600 |
+ */ |
|
6601 |
+ var class_map = (function (_super) { |
|
6602 |
+ __extends(class_map, _super); |
|
6603 |
+ function class_map() { |
|
6604 |
+ return _super !== null && _super.apply(this, arguments) || this; |
|
4957 | 6605 |
} |
4958 |
- break; |
|
4959 |
- default: { |
|
4960 |
- return ((resolve, reject) => reject(new Error("unhandled protocol"))); |
|
4961 |
- } |
|
6606 |
+ return class_map; |
|
6607 |
+ }(class_map_equality)); |
|
6608 |
+ lib_structures.class_map = class_map; |
|
6609 |
+})(lib_structures || (lib_structures = {})); |
|
6610 |
+var lib_structures; |
|
6611 |
+(function (lib_structures) { |
|
6612 |
+ /** |
|
6613 |
+ * @author fenris |
|
6614 |
+ */ |
|
6615 |
+ var class_store = (function () { |
|
6616 |
+ function class_store() { |
|
4962 | 6617 |
} |
6618 |
+ return class_store; |
|
6619 |
+ }()); |
|
6620 |
+ lib_structures.class_store = class_store; |
|
6621 |
+})(lib_structures || (lib_structures = {})); |
|
6622 |
+var lib_structures; |
|
6623 |
+(function (lib_structures) { |
|
6624 |
+ /** |
|
6625 |
+ * @author fenris |
|
6626 |
+ */ |
|
6627 |
+ var class_stack = (function (_super) { |
|
6628 |
+ __extends(class_stack, _super); |
|
6629 |
+ /** |
|
6630 |
+ * @author fenris |
|
6631 |
+ */ |
|
6632 |
+ function class_stack() { |
|
6633 |
+ var _this = _super.call(this) || this; |
|
6634 |
+ _this.elements = []; |
|
6635 |
+ return _this; |
|
4963 | 6636 |
} |
4964 | 6637 |
/** |
4965 | 6638 |
* @override |
4966 | 6639 |
* @author fenris |
4967 | 6640 |
*/ |
4968 |
- write(path, content) { |
|
4969 |
- let nm_fs = require("fs"); |
|
4970 |
- return ((resolve, reject) => { |
|
4971 |
- nm_fs.writeFile(path, content, { |
|
4972 |
- "encoding": "utf8", |
|
4973 |
- "flag": "w", |
|
4974 |
- }, (error) => { |
|
4975 |
- if (error == null) { |
|
4976 |
- resolve(undefined); |
|
4977 |
- } |
|
4978 |
- else { |
|
4979 |
- reject(error); |
|
4980 |
- } |
|
4981 |
- }); |
|
4982 |
- }); |
|
4983 |
- } |
|
4984 |
- } |
|
4985 |
- lib_file.class_file_node = class_file_node; |
|
4986 |
-})(lib_file || (lib_file = {})); |
|
4987 |
-///<reference path="../../call/build/logic-decl.d.ts"/> |
|
4988 |
-var lib_file; |
|
4989 |
-(function (lib_file) { |
|
6641 |
+ class_stack.prototype.size = function () { |
|
6642 |
+ return this.elements.length; |
|
6643 |
+ }; |
|
4990 | 6644 |
/** |
6645 |
+ * @override |
|
4991 | 6646 |
* @author fenris |
4992 |
- * @todo move to a dedicated lib (e.g. "http", "transport", etc.) |
|
4993 | 6647 |
*/ |
4994 |
- function ajax({ "target": target /*: string*/, "data": data /*: {[key : string] : string}*/ = null, "method": method /* : string*/ = "GET" }) { |
|
4995 |
- method = method.toLowerCase(); |
|
4996 |
- return ((resolve, reject) => { |
|
4997 |
- let datastring = ((data == null) ? null : Object.keys(data).map(key => `${key}=${data[key]}`).join("&")); |
|
4998 |
- let suffix = ((method == "get") ? ("?" + datastring) : ""); |
|
4999 |
- let sending = ((method == "get") ? null : datastring); |
|
5000 |
- let request = new XMLHttpRequest(); |
|
5001 |
- request.open(method.toUpperCase(), target + suffix, true); |
|
5002 |
- request.onreadystatechange = function () { |
|
5003 |
- if (request.readyState === 4) { |
|
5004 |
- if (request.status === 200) { |
|
5005 |
- resolve(request.responseText); |
|
6648 |
+ class_stack.prototype.scan = function () { |
|
6649 |
+ if (this.size() == 0) { |
|
6650 |
+ throw (new Error("empty")); |
|
5006 | 6651 |
} |
5007 | 6652 |
else { |
5008 |
- reject(new Error("XMLHttpRequest failed")); |
|
5009 |
- } |
|
6653 |
+ return this.elements[this.elements.length - 1]; |
|
5010 | 6654 |
} |
5011 | 6655 |
}; |
5012 |
- request.send(sending); |
|
5013 |
- }); |
|
5014 |
- } |
|
5015 | 6656 |
/** |
6657 |
+ * @override |
|
5016 | 6658 |
* @author fenris |
5017 | 6659 |
*/ |
5018 |
- class class_file_web extends lib_file.class_file_abstract { |
|
6660 |
+ class_stack.prototype.give = function (element) { |
|
6661 |
+ this.elements.push(element); |
|
6662 |
+ }; |
|
5019 | 6663 |
/** |
5020 | 6664 |
* @override |
5021 | 6665 |
* @author fenris |
5022 | 6666 |
*/ |
5023 |
- read(path, skip_error = false) { |
|
5024 |
- return ((resolve, reject) => { |
|
5025 |
- ajax({ |
|
5026 |
- "target": path, |
|
5027 |
- "method": "GET", |
|
5028 |
- })(resolve, reason => (skip_error ? resolve(null) : reject(reason))); |
|
5029 |
- }); |
|
5030 |
- } |
|
6667 |
+ class_stack.prototype.take = function () { |
|
6668 |
+ var element = this.scan(); |
|
6669 |
+ this.elements.pop(); |
|
6670 |
+ return element; |
|
6671 |
+ }; |
|
6672 |
+ return class_stack; |
|
6673 |
+ }(lib_structures.class_store)); |
|
6674 |
+ lib_structures.class_stack = class_stack; |
|
6675 |
+})(lib_structures || (lib_structures = {})); |
|
6676 |
+var lib_structures; |
|
6677 |
+(function (lib_structures) { |
|
5031 | 6678 |
/** |
5032 |
- * @override |
|
5033 | 6679 |
* @author fenris |
5034 | 6680 |
*/ |
5035 |
- write(path, content) { |
|
5036 |
- return ((resolve, reject) => { |
|
5037 |
- reject(new Error("not implemented / not possible")); |
|
5038 |
- }); |
|
5039 |
- } |
|
5040 |
- } |
|
5041 |
- lib_file.class_file_web = class_file_web; |
|
5042 |
-})(lib_file || (lib_file = {})); |
|
5043 |
-///<reference path="../../base/build/logic-decl.d.ts"/> |
|
5044 |
-///<reference path="../../call/build/logic-decl.d.ts"/> |
|
5045 |
-var lib_file; |
|
5046 |
-(function (lib_file) { |
|
6681 |
+ var class_queue = (function (_super) { |
|
6682 |
+ __extends(class_queue, _super); |
|
5047 | 6683 |
/** |
5048 |
- * @desc selects the implementation which fits for the detected environment |
|
5049 | 6684 |
* @author fenris |
5050 | 6685 |
*/ |
5051 |
- function auto() { |
|
5052 |
- let environment = lib_base.environment(); |
|
5053 |
- switch (environment) { |
|
5054 |
- case "node": { |
|
5055 |
- return (new lib_file.class_file_node()); |
|
5056 |
- break; |
|
5057 |
- } |
|
5058 |
- case "web": { |
|
5059 |
- return (new lib_file.class_file_web()); |
|
5060 |
- break; |
|
5061 |
- } |
|
5062 |
- default: { |
|
5063 |
- throw (new Error(`no implementation for environment '${environment}'`)); |
|
5064 |
- break; |
|
5065 |
- } |
|
5066 |
- } |
|
6686 |
+ function class_queue() { |
|
6687 |
+ var _this = _super.call(this) || this; |
|
6688 |
+ _this.elements = []; |
|
6689 |
+ return _this; |
|
5067 | 6690 |
} |
5068 |
- lib_file.auto = auto; |
|
5069 | 6691 |
/** |
6692 |
+ * @override |
|
5070 | 6693 |
* @author fenris |
5071 | 6694 |
*/ |
5072 |
- class class_file extends lib_file.class_file_abstract { |
|
6695 |
+ class_queue.prototype.size = function () { |
|
6696 |
+ return this.elements.length; |
|
6697 |
+ }; |
|
5073 | 6698 |
/** |
6699 |
+ * @override |
|
5074 | 6700 |
* @author fenris |
5075 | 6701 |
*/ |
5076 |
- constructor() { |
|
5077 |
- super(); |
|
5078 |
- this.core = auto(); |
|
6702 |
+ class_queue.prototype.scan = function () { |
|
6703 |
+ if (this.size() == 0) { |
|
6704 |
+ throw (new Error("empty")); |
|
6705 |
+ } |
|
6706 |
+ else { |
|
6707 |
+ return this.elements[0]; |
|
5079 | 6708 |
} |
6709 |
+ }; |
|
5080 | 6710 |
/** |
5081 | 6711 |
* @override |
5082 | 6712 |
* @author fenris |
5083 | 6713 |
*/ |
5084 |
- read(path, skip_error = false) { |
|
5085 |
- return this.core.read(path, skip_error); |
|
5086 |
- } |
|
6714 |
+ class_queue.prototype.give = function (element) { |
|
6715 |
+ this.elements.push(element); |
|
6716 |
+ }; |
|
5087 | 6717 |
/** |
5088 | 6718 |
* @override |
5089 | 6719 |
* @author fenris |
5090 | 6720 |
*/ |
5091 |
- write(path, content) { |
|
5092 |
- return this.core.write(path, content); |
|
6721 |
+ class_queue.prototype.take = function () { |
|
6722 |
+ var element = this.scan(); |
|
6723 |
+ this.elements.shift(); |
|
6724 |
+ return element; |
|
6725 |
+ }; |
|
6726 |
+ return class_queue; |
|
6727 |
+ }(lib_structures.class_store)); |
|
6728 |
+ lib_structures.class_queue = class_queue; |
|
6729 |
+})(lib_structures || (lib_structures = {})); |
|
6730 |
+var lib_structures; |
|
6731 |
+(function (lib_structures) { |
|
6732 |
+ /** |
|
6733 |
+ * @author fenris |
|
6734 |
+ */ |
|
6735 |
+ var class_graph = (function () { |
|
6736 |
+ /** |
|
6737 |
+ * @author fenris |
|
6738 |
+ */ |
|
6739 |
+ function class_graph(equality, nodes, edges) { |
|
6740 |
+ if (equality === void 0) { equality = null; } |
|
6741 |
+ if (nodes === void 0) { nodes = []; } |
|
6742 |
+ if (edges === void 0) { edges = []; } |
|
6743 |
+ if (equality == null) { |
|
6744 |
+ // equality = ((node1, node2) => lib_trait.call("collatable", "collate", {"kind": "auto"}, {"first": node1, "second": node2})); |
|
6745 |
+ equality = instance_collate /*<type_node>*/; |
|
5093 | 6746 |
} |
6747 |
+ this.equality = equality; |
|
6748 |
+ this.nodes = nodes; |
|
6749 |
+ this.edges = edges; |
|
5094 | 6750 |
} |
5095 |
- lib_file.class_file = class_file; |
|
5096 | 6751 |
/** |
6752 |
+ * @desc [accessor] [getter] |
|
5097 | 6753 |
* @author fenris |
5098 | 6754 |
*/ |
5099 |
- var instance = auto(); |
|
6755 |
+ class_graph.prototype.nodes_get = function () { |
|
6756 |
+ return this.nodes; |
|
6757 |
+ }; |
|
5100 | 6758 |
/** |
6759 |
+ * @desc [mutator] |
|
5101 | 6760 |
* @author fenris |
5102 | 6761 |
*/ |
5103 |
- function read(path, skip_error = false) { |
|
5104 |
- return instance.read(path, skip_error); |
|
5105 |
- } |
|
5106 |
- lib_file.read = read; |
|
6762 |
+ class_graph.prototype.add_node = function (node) { |
|
6763 |
+ this.nodes.push(node); |
|
6764 |
+ }; |
|
5107 | 6765 |
/** |
6766 |
+ * @desc [accessor] [getter] |
|
5108 | 6767 |
* @author fenris |
5109 | 6768 |
*/ |
5110 |
- function write(path, content) { |
|
5111 |
- return instance.write(path, content); |
|
5112 |
- } |
|
5113 |
- lib_file.write = write; |
|
6769 |
+ class_graph.prototype.edges_get = function () { |
|
6770 |
+ return this.edges; |
|
6771 |
+ }; |
|
5114 | 6772 |
/** |
6773 |
+ * @desc [mutator] |
|
5115 | 6774 |
* @author fenris |
5116 | 6775 |
*/ |
5117 |
- function read_json(path) { |
|
5118 |
- return instance.read_json(path); |
|
6776 |
+ class_graph.prototype.add_edge = function (edge) { |
|
6777 |
+ this.edges.push(edge); |
|
6778 |
+ }; |
|
6779 |
+ /** |
|
6780 |
+ * @desc [accessor] |
|
6781 |
+ * @author fenris |
|
6782 |
+ */ |
|
6783 |
+ class_graph.prototype.has = function (node) { |
|
6784 |
+ var _this = this; |
|
6785 |
+ return this.nodes.some(function (node_) { return _this.equality(node, node_); }); |
|
6786 |
+ }; |
|
6787 |
+ /** |
|
6788 |
+ * @desc [accessor] |
|
6789 |
+ * @author fenris |
|
6790 |
+ */ |
|
6791 |
+ class_graph.prototype.outgoing = function (node) { |
|
6792 |
+ var _this = this; |
|
6793 |
+ return this.edges.filter(function (edge) { return _this.equality(edge.from, node); }); |
|
6794 |
+ }; |
|
6795 |
+ /** |
|
6796 |
+ * @desc [accessor] |
|
6797 |
+ * @author fenris |
|
6798 |
+ */ |
|
6799 |
+ class_graph.prototype.incoming = function (node) { |
|
6800 |
+ var _this = this; |
|
6801 |
+ return this.edges.filter(function (edge) { return _this.equality(edge.to, node); }); |
|
6802 |
+ }; |
|
6803 |
+ /** |
|
6804 |
+ * @desc [accessor] |
|
6805 |
+ * @author fenris |
|
6806 |
+ */ |
|
6807 |
+ class_graph.prototype.without = function (pivot) { |
|
6808 |
+ var _this = this; |
|
6809 |
+ return (new class_graph(this.equality, this.nodes.filter(function (node) { return (!_this.equality(node, pivot)); }), this.edges.filter(function (edge) { return ((!_this.equality(edge.from, pivot)) && (!_this.equality(edge.to, pivot))); }))); |
|
6810 |
+ }; |
|
6811 |
+ /** |
|
6812 |
+ * @desc [accessor] returns the topologic sorting of the nodes (if it exists) |
|
6813 |
+ * @author fenris |
|
6814 |
+ */ |
|
6815 |
+ class_graph.prototype.topsort = function () { |
|
6816 |
+ var _this = this; |
|
6817 |
+ var graph = this; |
|
6818 |
+ if (graph.nodes.length == 0) { |
|
6819 |
+ return []; |
|
5119 | 6820 |
} |
5120 |
- lib_file.read_json = read_json; |
|
6821 |
+ else { |
|
6822 |
+ var pivot_1; |
|
6823 |
+ var found = graph.nodes.some(function (node) { |
|
6824 |
+ var count = graph.edges.filter(function (edge) { return _this.equality(edge.to, node); }).length; |
|
6825 |
+ if (count == 0) { |
|
6826 |
+ pivot_1 = node; |
|
6827 |
+ return true; |
|
6828 |
+ } |
|
6829 |
+ else { |
|
6830 |
+ // console.info("'" + String(node) + "' has " + count.toString() + " incoming edges"); |
|
6831 |
+ return false; |
|
6832 |
+ } |
|
6833 |
+ }); |
|
6834 |
+ if (found) { |
|
6835 |
+ return [pivot_1].concat(graph.without(pivot_1).topsort()); |
|
6836 |
+ } |
|
6837 |
+ else { |
|
6838 |
+ throw (new Error("circular dependencies found")); |
|
6839 |
+ } |
|
6840 |
+ } |
|
6841 |
+ }; |
|
5121 | 6842 |
/** |
6843 |
+ * @desc [accessor] returns the reduced version of a graph representing an order relation (implicit transitivity) |
|
5122 | 6844 |
* @author fenris |
5123 | 6845 |
*/ |
5124 |
- function write_json(path, data) { |
|
5125 |
- return instance.write_json(path, data); |
|
6846 |
+ class_graph.prototype.hasse = function () { |
|
6847 |
+ var _this = this; |
|
6848 |
+ return (new class_graph(this.equality, this.nodes, this.edges.filter(function (edge) { |
|
6849 |
+ var reachable = (_this.outgoing(edge.from).map(function (edge_) { return edge_.to; }) |
|
6850 |
+ .map(function (node) { return _this.outgoing(node).map(function (edge_) { return edge_.to; }); }) |
|
6851 |
+ .reduce(function (x, y) { return x.concat(y); }, [])); |
|
6852 |
+ return (!reachable.some(function (node) { return _this.equality(node, edge.to); })); |
|
6853 |
+ }))); |
|
6854 |
+ }; |
|
6855 |
+ /** |
|
6856 |
+ * @author fenris |
|
6857 |
+ */ |
|
6858 |
+ class_graph.prototype.output_dot = function (_a) { |
|
6859 |
+ var _this = this; |
|
6860 |
+ var _b = _a === void 0 ? {} : _a, _c = _b["extract_id"], extract_id = _c === void 0 ? null : _c, _d = _b["extract_label"], extract_label = _d === void 0 ? null : _d; |
|
6861 |
+ var index = function (node) { |
|
6862 |
+ var i = -1; |
|
6863 |
+ var found = _this.nodes.some(function (node_, i_) { |
|
6864 |
+ if (_this.equality(node, node_)) { |
|
6865 |
+ i = i_; |
|
6866 |
+ return true; |
|
5126 | 6867 |
} |
5127 |
- lib_file.write_json = write_json; |
|
5128 |
-})(lib_file || (lib_file = {})); |
|
6868 |
+ else { |
|
6869 |
+ return false; |
|
6870 |
+ } |
|
6871 |
+ }); |
|
6872 |
+ return i; |
|
6873 |
+ }; |
|
6874 |
+ if (extract_id == null) { |
|
6875 |
+ // instance_hash |
|
6876 |
+ extract_id = (function (node) { return index(node).toFixed(0); }); |
|
6877 |
+ } |
|
6878 |
+ if (extract_label == null) { |
|
6879 |
+ extract_label = instance_show; |
|
6880 |
+ } |
|
6881 |
+ var nodeid = function (node) { |
|
6882 |
+ return ("node_" + extract_id(node)); |
|
6883 |
+ }; |
|
6884 |
+ return (lib_dot.generate({ |
|
6885 |
+ "common": { |
|
6886 |
+ "fontname": "Monospace" |
|
6887 |
+ }, |
|
6888 |
+ "nodes": { |
|
6889 |
+ "head": { |
|
6890 |
+ "fontname": "Monospace", |
|
6891 |
+ "style": "filled", |
|
6892 |
+ "fillcolor": "0.35+0.6+0.8" |
|
6893 |
+ }, |
|
6894 |
+ "list": this.nodes_get() |
|
6895 |
+ .map(function (node, index) { |
|
6896 |
+ return { |
|
6897 |
+ "id": nodeid(node), |
|
6898 |
+ "attributes": { |
|
6899 |
+ "label": extract_label(node) |
|
6900 |
+ } |
|
6901 |
+ }; |
|
6902 |
+ }) |
|
6903 |
+ }, |
|
6904 |
+ "edges": { |
|
6905 |
+ "head": { |
|
6906 |
+ "fontname": "Monospace" |
|
6907 |
+ }, |
|
6908 |
+ "list": this.edges_get() |
|
6909 |
+ .map(function (edge, index) { |
|
6910 |
+ return { |
|
6911 |
+ "id_from": nodeid(edge.from), |
|
6912 |
+ "id_to": nodeid(edge.to), |
|
6913 |
+ "attributes": {} |
|
6914 |
+ }; |
|
6915 |
+ }) |
|
6916 |
+ } |
|
6917 |
+ })); |
|
6918 |
+ }; |
|
6919 |
+ return class_graph; |
|
6920 |
+ }()); |
|
6921 |
+ lib_structures.class_graph = class_graph; |
|
6922 |
+})(lib_structures || (lib_structures = {})); |
|
5129 | 6923 |
var lib_args; |
5130 | 6924 |
(function (lib_args) { |
5131 | 6925 |
/** |
... | ... |
@@ -5672,21 +7466,11 @@ var lib_args; |
5672 | 7466 |
} |
5673 | 7467 |
return output; |
5674 | 7468 |
}; |
5675 |
- return class_handler; |
|
5676 |
- }()); |
|
5677 |
- lib_args.class_handler = class_handler; |
|
5678 |
-})(lib_args || (lib_args = {})); |
|
5679 |
- |
|
5680 |
-var __extends = (this && this.__extends) || (function () { |
|
5681 |
- var extendStatics = Object.setPrototypeOf || |
|
5682 |
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
5683 |
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
5684 |
- return function (d, b) { |
|
5685 |
- extendStatics(d, b); |
|
5686 |
- function __() { this.constructor = d; } |
|
5687 |
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
5688 |
- }; |
|
5689 |
-})(); |
|
7469 |
+ return class_handler; |
|
7470 |
+ }()); |
|
7471 |
+ lib_args.class_handler = class_handler; |
|
7472 |
+})(lib_args || (lib_args = {})); |
|
7473 |
+ |
|
5690 | 7474 |
var nm_child_process = require("child_process"); |
5691 | 7475 |
var nm_fs = require("fs"); |
5692 | 7476 |
/** |
... | ... |
@@ -5709,7 +7493,7 @@ function dirwrap(location, core) { |
5709 | 7493 |
return core; |
5710 | 7494 |
} |
5711 | 7495 |
else { |
5712 |
- return "cd " + location.as_string(globalvars.configuration.system) + " > /dev/null && " + core + " ; cd - > /dev/null"; |
|
7496 |
+ return `cd ${location.as_string(globalvars.configuration.system)} > /dev/null && ${core} ; cd - > /dev/null`; |
|
5713 | 7497 |
} |
5714 | 7498 |
} |
5715 | 7499 |
/** |
... | ... |
@@ -5721,8 +7505,7 @@ function filepointer_adjust(filepointer, location) { |
5721 | 7505 |
/** |
5722 | 7506 |
* @author fenris |
5723 | 7507 |
*/ |
5724 |
-function path_augment(path, step, aggregate) { |
|
5725 |
- if (aggregate === void 0) { aggregate = true; } |
|
7508 |
+function path_augment(path, step, aggregate = true) { |
|
5726 | 7509 |
if (aggregate) { |
5727 | 7510 |
return path.concat([step]); |
5728 | 7511 |
} |
... | ... |
@@ -5739,12 +7522,11 @@ function path_dump(path) { |
5739 | 7522 |
/** |
5740 | 7523 |
* @author fenris |
5741 | 7524 |
*/ |
5742 |
-var class_message = (function () { |
|
7525 |
+class class_message { |
|
5743 | 7526 |
/** |
5744 | 7527 |
* @author fenris |
5745 | 7528 |
*/ |
5746 |
- function class_message(content, parameters) { |
|
5747 |
- if (parameters === void 0) { parameters = {}; } |
|
7529 |
+ constructor(content, parameters = {}) { |
|
5748 | 7530 |
/** |
5749 | 7531 |
* @author fenris |
5750 | 7532 |
*/ |
... | ... |
@@ -5758,9 +7540,8 @@ var class_message = (function () { |
5758 | 7540 |
/** |
5759 | 7541 |
* @author fenris |
5760 | 7542 |
*/ |
5761 |
- class_message.prototype.generate = function (with_type) { |
|
5762 |
- if (with_type === void 0) { with_type = true; } |
|
5763 |
- var output = ""; |
|
7543 |
+ generate(with_type = true) { |
|
7544 |
+ let output = ""; |
|
5764 | 7545 |
if (with_type) { |
5765 | 7546 |
if (this.type != null) { |
5766 | 7547 |
output += ("[" + this.type + "]" + " "); |
... | ... |
@@ -5775,23 +7556,23 @@ var class_message = (function () { |
5775 | 7556 |
output += "\n"; |
5776 | 7557 |
} |
5777 | 7558 |
return output; |
5778 |
- }; |
|
7559 |
+ } |
|
5779 | 7560 |
/** |
5780 | 7561 |
* @author fenris |
5781 | 7562 |
*/ |
5782 |
- class_message.prototype.stdout = function () { |
|
7563 |
+ stdout() { |
|
5783 | 7564 |
console.log(this.generate(true)); |
5784 |
- }; |
|
7565 |
+ } |
|
5785 | 7566 |
/** |
5786 | 7567 |
* @author fenris |
5787 | 7568 |
*/ |
5788 |
- class_message.prototype.stderr = function () { |
|
7569 |
+ stderr() { |
|
5789 | 7570 |
console.error(this.generate(true)); |
5790 |
- }; |
|
7571 |
+ } |
|
5791 | 7572 |
/** |
5792 | 7573 |
* @author fenris |
5793 | 7574 |
*/ |
5794 |
- class_message.prototype.console = function () { |
|
7575 |
+ console() { |
|
5795 | 7576 |
switch (this.type) { |
5796 | 7577 |
case "log": { |
5797 | 7578 |
console.log(this.generate(false)); |
... | ... |
@@ -5813,188 +7594,49 @@ var class_message = (function () { |
5813 | 7594 |
throw (new Error("unhandled type '" + this.type + "'")); |
5814 | 7595 |
} |
5815 | 7596 |
} |
5816 |
- }; |
|
5817 |
- return class_message; |
|
5818 |
-}()); |
|
7597 |
+ } |
|
7598 |
+} |
|
5819 | 7599 |
/** |
5820 | 7600 |
* @author fenris |
5821 | 7601 |
*/ |
5822 |
-var class_cliout = (function () { |
|
5823 |
- function class_cliout() { |
|
5824 |
- } |
|
7602 |
+class class_cliout { |
|
5825 | 7603 |
/** |
5826 | 7604 |
* @author fenris |
5827 | 7605 |
*/ |
5828 |
- class_cliout.stdout = function (content, depth) { |
|
5829 |
- if (depth === void 0) { depth = 0; } |
|
7606 |
+ static stdout(content, depth = 0) { |
|
5830 | 7607 |
console.log(lib_string.repeat("\t", depth) + content); |
5831 |
- }; |
|
7608 |
+ } |
|
5832 | 7609 |
/** |
5833 | 7610 |
* @author fenris |
5834 | 7611 |
*/ |
5835 |