mol_wire_lib 1.0.104 → 1.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.esm.js CHANGED
@@ -1434,5 +1434,566 @@ var $;
1434
1434
  })($ || ($ = {}));
1435
1435
  //mol/wait/timeout/timeout.ts
1436
1436
  ;
1437
+ "use strict";
1438
+ var $;
1439
+ (function ($) {
1440
+ $.$mol_mem = $mol_wire_mem(0);
1441
+ $.$mol_mem_key = $mol_wire_mem(1);
1442
+ $.$mol_mem_key2 = $mol_wire_mem(2);
1443
+ $.$mol_mem_key3 = $mol_wire_mem(3);
1444
+ })($ || ($ = {}));
1445
+ //mol/mem/mem.ts
1446
+ ;
1447
+ "use strict";
1448
+ var $;
1449
+ (function ($) {
1450
+ function $mol_log3_area_lazy(event) {
1451
+ const self = this;
1452
+ const stack = self.$mol_log3_stack;
1453
+ const deep = stack.length;
1454
+ let logged = false;
1455
+ stack.push(() => {
1456
+ logged = true;
1457
+ self.$mol_log3_area.call(self, event);
1458
+ });
1459
+ return () => {
1460
+ if (logged)
1461
+ self.console.groupEnd();
1462
+ if (stack.length > deep)
1463
+ stack.length = deep;
1464
+ };
1465
+ }
1466
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1467
+ $.$mol_log3_stack = [];
1468
+ })($ || ($ = {}));
1469
+ //mol/log3/log3.ts
1470
+ ;
1471
+ "use strict";
1472
+ //node/node.ts
1473
+ ;
1474
+ "use strict";
1475
+ var $node = new Proxy({ require }, {
1476
+ get(target, name, wrapper) {
1477
+ if (target[name])
1478
+ return target[name];
1479
+ const mod = target.require('module');
1480
+ if (mod.builtinModules.indexOf(name) >= 0)
1481
+ return target.require(name);
1482
+ const path = target.require('path');
1483
+ const fs = target.require('fs');
1484
+ let dir = path.resolve('.');
1485
+ const suffix = `./node_modules/${name}`;
1486
+ const $$ = $;
1487
+ while (!fs.existsSync(path.join(dir, suffix))) {
1488
+ const parent = path.resolve(dir, '..');
1489
+ if (parent === dir) {
1490
+ $$.$mol_exec('.', 'npm', 'install', name);
1491
+ try {
1492
+ $$.$mol_exec('.', 'npm', 'install', '@types/' + name);
1493
+ }
1494
+ catch { }
1495
+ break;
1496
+ }
1497
+ else {
1498
+ dir = parent;
1499
+ }
1500
+ }
1501
+ return target.require(name);
1502
+ },
1503
+ set(target, name, value) {
1504
+ target[name] = value;
1505
+ return true;
1506
+ },
1507
+ });
1508
+ require = (req => Object.assign(function require(name) {
1509
+ return $node[name];
1510
+ }, req))(require);
1511
+ //node/node.node.ts
1512
+ ;
1513
+ "use strict";
1514
+ var $;
1515
+ (function ($) {
1516
+ function $mol_deprecated(message) {
1517
+ return (host, field, descr) => {
1518
+ const value = descr.value;
1519
+ let warned = false;
1520
+ descr.value = function $mol_deprecated_wrapper(...args) {
1521
+ if (!warned) {
1522
+ $$.$mol_log3_warn({
1523
+ place: `${host.constructor.name}::${field}`,
1524
+ message: `Deprecated`,
1525
+ hint: message,
1526
+ });
1527
+ warned = true;
1528
+ }
1529
+ return value.call(this, ...args);
1530
+ };
1531
+ };
1532
+ }
1533
+ $.$mol_deprecated = $mol_deprecated;
1534
+ })($ || ($ = {}));
1535
+ //mol/deprecated/deprecated.ts
1536
+ ;
1537
+ "use strict";
1538
+ var $;
1539
+ (function ($) {
1540
+ $.$mol_tree_convert = Symbol('$mol_tree_convert');
1541
+ class $mol_tree extends $mol_object2 {
1542
+ type;
1543
+ data;
1544
+ sub;
1545
+ baseUri;
1546
+ row;
1547
+ col;
1548
+ length;
1549
+ constructor(config = {}) {
1550
+ super();
1551
+ this.type = config.type || '';
1552
+ if (config.value !== undefined) {
1553
+ var sub = $mol_tree.values(config.value);
1554
+ if (config.type || sub.length > 1) {
1555
+ this.sub = [...sub, ...(config.sub || [])];
1556
+ this.data = config.data || '';
1557
+ }
1558
+ else {
1559
+ this.data = sub[0].data;
1560
+ this.sub = config.sub || [];
1561
+ }
1562
+ }
1563
+ else {
1564
+ this.data = config.data || '';
1565
+ this.sub = config.sub || [];
1566
+ }
1567
+ this.baseUri = config.baseUri || '';
1568
+ this.row = config.row || 0;
1569
+ this.col = config.col || 0;
1570
+ this.length = config.length || 0;
1571
+ }
1572
+ static values(str, baseUri) {
1573
+ return str.split('\n').map((data, index) => new $mol_tree({
1574
+ data: data,
1575
+ baseUri: baseUri,
1576
+ row: index + 1,
1577
+ length: data.length,
1578
+ }));
1579
+ }
1580
+ clone(config = {}) {
1581
+ return new $mol_tree({
1582
+ type: ('type' in config) ? config.type : this.type,
1583
+ data: ('data' in config) ? config.data : this.data,
1584
+ sub: ('sub' in config) ? config.sub : this.sub,
1585
+ baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
1586
+ row: ('row' in config) ? config.row : this.row,
1587
+ col: ('col' in config) ? config.col : this.col,
1588
+ length: ('length' in config) ? config.length : this.length,
1589
+ value: config.value
1590
+ });
1591
+ }
1592
+ make(config) {
1593
+ return new $mol_tree({
1594
+ baseUri: this.baseUri,
1595
+ row: this.row,
1596
+ col: this.col,
1597
+ length: this.length,
1598
+ ...config,
1599
+ });
1600
+ }
1601
+ make_data(value, sub) {
1602
+ return this.make({ value, sub });
1603
+ }
1604
+ make_struct(type, sub) {
1605
+ return this.make({ type, sub });
1606
+ }
1607
+ static fromString(str, baseUri) {
1608
+ var root = new $mol_tree({ baseUri: baseUri });
1609
+ var stack = [root];
1610
+ var row = 0;
1611
+ var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
1612
+ var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
1613
+ lines.forEach(line => {
1614
+ ++row;
1615
+ var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
1616
+ if (!chunks || chunks[4])
1617
+ return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
1618
+ var indent = chunks[1];
1619
+ var path = chunks[2];
1620
+ var data = chunks[3];
1621
+ var deep = indent.length;
1622
+ var types = path ? path.replace(/ $/, '').split(/ +/) : [];
1623
+ if (stack.length <= deep)
1624
+ return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
1625
+ stack.length = deep + 1;
1626
+ var parent = stack[deep];
1627
+ let col = deep;
1628
+ types.forEach(type => {
1629
+ if (!type)
1630
+ return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
1631
+ var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
1632
+ const parent_sub = parent.sub;
1633
+ parent_sub.push(next);
1634
+ parent = next;
1635
+ col += type.length + 1;
1636
+ });
1637
+ if (data) {
1638
+ var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
1639
+ const parent_sub = parent.sub;
1640
+ parent_sub.push(next);
1641
+ parent = next;
1642
+ }
1643
+ stack.push(parent);
1644
+ });
1645
+ return root;
1646
+ }
1647
+ static fromJSON(json, baseUri = '') {
1648
+ switch (true) {
1649
+ case typeof json === 'boolean':
1650
+ case typeof json === 'number':
1651
+ case json === null:
1652
+ return new $mol_tree({
1653
+ type: String(json),
1654
+ baseUri: baseUri
1655
+ });
1656
+ case typeof json === 'string':
1657
+ return new $mol_tree({
1658
+ value: json,
1659
+ baseUri: baseUri
1660
+ });
1661
+ case Array.isArray(json):
1662
+ return new $mol_tree({
1663
+ type: "/",
1664
+ sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
1665
+ });
1666
+ case json instanceof Date:
1667
+ return new $mol_tree({
1668
+ value: json.toISOString(),
1669
+ baseUri: baseUri
1670
+ });
1671
+ default:
1672
+ if (typeof json[$.$mol_tree_convert] === 'function') {
1673
+ return json[$.$mol_tree_convert]();
1674
+ }
1675
+ if (typeof json.toJSON === 'function') {
1676
+ return $mol_tree.fromJSON(json.toJSON());
1677
+ }
1678
+ if (json instanceof Error) {
1679
+ const { name, message, stack } = json;
1680
+ json = { ...json, name, message, stack };
1681
+ }
1682
+ var sub = [];
1683
+ for (var key in json) {
1684
+ if (json[key] === undefined)
1685
+ continue;
1686
+ const subsub = $mol_tree.fromJSON(json[key], baseUri);
1687
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1688
+ var child = new $mol_tree({
1689
+ type: key,
1690
+ baseUri: baseUri,
1691
+ sub: [subsub],
1692
+ });
1693
+ }
1694
+ else {
1695
+ var child = new $mol_tree({
1696
+ value: key,
1697
+ baseUri: baseUri,
1698
+ sub: [subsub],
1699
+ });
1700
+ }
1701
+ sub.push(child);
1702
+ }
1703
+ return new $mol_tree({
1704
+ type: "*",
1705
+ sub: sub,
1706
+ baseUri: baseUri
1707
+ });
1708
+ }
1709
+ }
1710
+ get uri() {
1711
+ return this.baseUri + '#' + this.row + ':' + this.col;
1712
+ }
1713
+ toString(prefix = '') {
1714
+ var output = '';
1715
+ if (this.type.length) {
1716
+ if (!prefix.length) {
1717
+ prefix = "\t";
1718
+ }
1719
+ output += this.type;
1720
+ if (this.sub.length == 1) {
1721
+ return output + ' ' + this.sub[0].toString(prefix);
1722
+ }
1723
+ output += "\n";
1724
+ }
1725
+ else if (this.data.length || prefix.length) {
1726
+ output += "\\" + this.data + "\n";
1727
+ }
1728
+ for (var child of this.sub) {
1729
+ output += prefix;
1730
+ output += child.toString(prefix + "\t");
1731
+ }
1732
+ return output;
1733
+ }
1734
+ toJSON() {
1735
+ if (!this.type)
1736
+ return this.value;
1737
+ if (this.type === 'true')
1738
+ return true;
1739
+ if (this.type === 'false')
1740
+ return false;
1741
+ if (this.type === 'null')
1742
+ return null;
1743
+ if (this.type === '*') {
1744
+ var obj = {};
1745
+ for (var child of this.sub) {
1746
+ if (child.type === '-')
1747
+ continue;
1748
+ var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
1749
+ var val = child.sub[child.sub.length - 1].toJSON();
1750
+ if (val !== undefined)
1751
+ obj[key] = val;
1752
+ }
1753
+ return obj;
1754
+ }
1755
+ if (this.type === '/') {
1756
+ var res = [];
1757
+ this.sub.forEach(child => {
1758
+ if (child.type === '-')
1759
+ return;
1760
+ var val = child.toJSON();
1761
+ if (val !== undefined)
1762
+ res.push(val);
1763
+ });
1764
+ return res;
1765
+ }
1766
+ if (this.type === 'time') {
1767
+ return new Date(this.value);
1768
+ }
1769
+ const numb = Number(this.type);
1770
+ if (!Number.isNaN(numb) || this.type === 'NaN')
1771
+ return numb;
1772
+ throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
1773
+ }
1774
+ get value() {
1775
+ var values = [];
1776
+ for (var child of this.sub) {
1777
+ if (child.type)
1778
+ continue;
1779
+ values.push(child.value);
1780
+ }
1781
+ return this.data + values.join("\n");
1782
+ }
1783
+ insert(value, ...path) {
1784
+ if (path.length === 0)
1785
+ return value;
1786
+ const type = path[0];
1787
+ if (typeof type === 'string') {
1788
+ let replaced = false;
1789
+ const sub = this.sub.map((item, index) => {
1790
+ if (item.type !== type)
1791
+ return item;
1792
+ replaced = true;
1793
+ return item.insert(value, ...path.slice(1));
1794
+ });
1795
+ if (!replaced)
1796
+ sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
1797
+ return this.clone({ sub });
1798
+ }
1799
+ else if (typeof type === 'number') {
1800
+ const sub = this.sub.slice();
1801
+ sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
1802
+ return this.clone({ sub });
1803
+ }
1804
+ else {
1805
+ return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
1806
+ }
1807
+ }
1808
+ select(...path) {
1809
+ var next = [this];
1810
+ for (var type of path) {
1811
+ if (!next.length)
1812
+ break;
1813
+ var prev = next;
1814
+ next = [];
1815
+ for (var item of prev) {
1816
+ switch (typeof (type)) {
1817
+ case 'string':
1818
+ for (var child of item.sub) {
1819
+ if (!type || (child.type == type)) {
1820
+ next.push(child);
1821
+ }
1822
+ }
1823
+ break;
1824
+ case 'number':
1825
+ if (type < item.sub.length)
1826
+ next.push(item.sub[type]);
1827
+ break;
1828
+ default: next.push(...item.sub);
1829
+ }
1830
+ }
1831
+ }
1832
+ return new $mol_tree({ sub: next });
1833
+ }
1834
+ filter(path, value) {
1835
+ var sub = this.sub.filter(function (item) {
1836
+ var found = item.select(...path);
1837
+ if (value == null) {
1838
+ return Boolean(found.sub.length);
1839
+ }
1840
+ else {
1841
+ return found.sub.some(child => child.value == value);
1842
+ }
1843
+ });
1844
+ return new $mol_tree({ sub: sub });
1845
+ }
1846
+ transform(visit, stack = []) {
1847
+ const sub_stack = [this, ...stack];
1848
+ return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
1849
+ }
1850
+ hack(context) {
1851
+ const sub = [].concat(...this.sub.map(child => {
1852
+ const handle = context[child.type] || context[''];
1853
+ if (!handle)
1854
+ $mol_fail(child.error('Handler not defined'));
1855
+ return handle(child, context);
1856
+ }));
1857
+ return this.clone({ sub });
1858
+ }
1859
+ error(message) {
1860
+ return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
1861
+ }
1862
+ }
1863
+ __decorate([
1864
+ $mol_deprecated('Use $mol_tree:hack')
1865
+ ], $mol_tree.prototype, "transform", null);
1866
+ $.$mol_tree = $mol_tree;
1867
+ })($ || ($ = {}));
1868
+ //mol/tree/tree.ts
1869
+ ;
1870
+ "use strict";
1871
+ var $;
1872
+ (function ($) {
1873
+ function $mol_log3_node_make(level, output, type, color) {
1874
+ return function $mol_log3_logger(event) {
1875
+ if (!event.time)
1876
+ event = { time: new Date().toISOString(), ...event };
1877
+ const tree = this.$mol_tree.fromJSON(event).clone({ type });
1878
+ let str = tree.toString();
1879
+ if (process[output].isTTY) {
1880
+ str = $node.colorette[color + 'Bright'](str);
1881
+ }
1882
+ ;
1883
+ this.console[level](str);
1884
+ const self = this;
1885
+ return () => self.console.groupEnd();
1886
+ };
1887
+ }
1888
+ $.$mol_log3_node_make = $mol_log3_node_make;
1889
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1890
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1891
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1892
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1893
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1894
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1895
+ })($ || ($ = {}));
1896
+ //mol/log3/log3.node.ts
1897
+ ;
1898
+ "use strict";
1899
+ var $;
1900
+ (function ($) {
1901
+ function $mol_env() {
1902
+ return {};
1903
+ }
1904
+ $.$mol_env = $mol_env;
1905
+ })($ || ($ = {}));
1906
+ //mol/env/env.ts
1907
+ ;
1908
+ "use strict";
1909
+ var $;
1910
+ (function ($) {
1911
+ $.$mol_env = function $mol_env() {
1912
+ return this.process.env;
1913
+ };
1914
+ })($ || ($ = {}));
1915
+ //mol/env/env.node.ts
1916
+ ;
1917
+ "use strict";
1918
+ var $;
1919
+ (function ($) {
1920
+ function $mol_exec(dir, command, ...args) {
1921
+ let [app, ...args0] = command.split(' ');
1922
+ args = [...args0, ...args];
1923
+ this.$mol_log3_come({
1924
+ place: '$mol_exec',
1925
+ dir: $node.path.relative('', dir),
1926
+ message: 'Run',
1927
+ command: `${app} ${args.join(' ')}`,
1928
+ });
1929
+ var res = $node['child_process'].spawnSync(app, args, {
1930
+ cwd: $node.path.resolve(dir),
1931
+ shell: true,
1932
+ env: this.$mol_env(),
1933
+ });
1934
+ if (res.status || res.error)
1935
+ return $mol_fail(res.error || new Error(res.stderr.toString()));
1936
+ if (!res.stdout)
1937
+ res.stdout = Buffer.from([]);
1938
+ return res;
1939
+ }
1940
+ $.$mol_exec = $mol_exec;
1941
+ })($ || ($ = {}));
1942
+ //mol/exec/exec.node.ts
1943
+ ;
1944
+ "use strict";
1945
+ var $;
1946
+ (function ($) {
1947
+ class $mol_wire_log extends $mol_object2 {
1948
+ static watch(task) {
1949
+ return task;
1950
+ }
1951
+ static track(fiber) {
1952
+ const prev = $mol_wire_probe(() => this.track(fiber));
1953
+ let next;
1954
+ try {
1955
+ next = fiber.sync();
1956
+ }
1957
+ finally {
1958
+ for (const pub of fiber.pub_list) {
1959
+ if (pub instanceof $mol_wire_fiber) {
1960
+ this.track(pub);
1961
+ }
1962
+ }
1963
+ }
1964
+ if (prev !== undefined && !$mol_compare_deep(prev, next)) {
1965
+ this.$.$mol_log3_rise({
1966
+ message: 'Changed',
1967
+ place: fiber,
1968
+ });
1969
+ }
1970
+ return next;
1971
+ }
1972
+ static active() {
1973
+ try {
1974
+ this.watch()?.();
1975
+ }
1976
+ finally {
1977
+ for (const pub of $mol_wire_auto().pub_list) {
1978
+ if (pub instanceof $mol_wire_fiber) {
1979
+ this.track(pub);
1980
+ }
1981
+ }
1982
+ }
1983
+ }
1984
+ }
1985
+ __decorate([
1986
+ $mol_mem
1987
+ ], $mol_wire_log, "watch", null);
1988
+ __decorate([
1989
+ $mol_mem_key
1990
+ ], $mol_wire_log, "track", null);
1991
+ __decorate([
1992
+ $mol_mem
1993
+ ], $mol_wire_log, "active", null);
1994
+ $.$mol_wire_log = $mol_wire_log;
1995
+ })($ || ($ = {}));
1996
+ //mol/wire/log/log.ts
1997
+ ;
1437
1998
  export default $
1438
1999
  //# sourceMappingURL=node.esm.js.map