mol_wire_lib 1.0.178 → 1.0.181

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.js CHANGED
@@ -93,7 +93,7 @@ var $;
93
93
  promote() {
94
94
  $mol_wire_auto()?.track_next(this);
95
95
  }
96
- refresh() { }
96
+ fresh() { }
97
97
  complete() { }
98
98
  emit(quant = $mol_wire_cursor.stale) {
99
99
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -296,7 +296,7 @@ var $;
296
296
  }
297
297
  for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
298
298
  const pub = this.data[cursor];
299
- pub.refresh();
299
+ pub.fresh();
300
300
  }
301
301
  this.cursor = $mol_wire_cursor.fresh;
302
302
  }
@@ -592,7 +592,7 @@ var $;
592
592
  continue;
593
593
  if (fiber.cursor === $mol_wire_cursor.final)
594
594
  continue;
595
- fiber.refresh();
595
+ fiber.fresh();
596
596
  }
597
597
  }
598
598
  while (this.reaping.size) {
@@ -660,7 +660,7 @@ var $;
660
660
  else
661
661
  super.emit(quant);
662
662
  }
663
- refresh() {
663
+ fresh() {
664
664
  if (this.cursor === $mol_wire_cursor.fresh)
665
665
  return;
666
666
  if (this.cursor === $mol_wire_cursor.final)
@@ -668,7 +668,7 @@ var $;
668
668
  check: if (this.cursor === $mol_wire_cursor.doubt) {
669
669
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
670
670
  ;
671
- this.data[i]?.refresh();
671
+ this.data[i]?.fresh();
672
672
  if (this.cursor !== $mol_wire_cursor.doubt)
673
673
  break check;
674
674
  }
@@ -724,12 +724,16 @@ var $;
724
724
  this.track_off(bu);
725
725
  this.put(result);
726
726
  }
727
+ refresh() {
728
+ this.cursor = $mol_wire_cursor.stale;
729
+ this.fresh();
730
+ }
727
731
  sync() {
728
732
  if (!$mol_wire_fiber.warm) {
729
733
  return this.result();
730
734
  }
731
735
  this.promote();
732
- this.refresh();
736
+ this.fresh();
733
737
  if (this.cache instanceof Error) {
734
738
  return $mol_fail_hidden(this.cache);
735
739
  }
@@ -740,7 +744,7 @@ var $;
740
744
  }
741
745
  async async() {
742
746
  while (true) {
743
- this.refresh();
747
+ this.fresh();
744
748
  if (this.cache instanceof Error) {
745
749
  $mol_fail_hidden(this.cache);
746
750
  }
@@ -1042,6 +1046,22 @@ var $;
1042
1046
  };
1043
1047
  }
1044
1048
  }
1049
+ static watching = new Set();
1050
+ static watch() {
1051
+ new $mol_after_frame($mol_wire_atom.watch);
1052
+ for (const atom of $mol_wire_atom.watching) {
1053
+ if (atom.cursor === $mol_wire_cursor.final) {
1054
+ $mol_wire_atom.watching.delete(atom);
1055
+ }
1056
+ else {
1057
+ atom.cursor = $mol_wire_cursor.stale;
1058
+ atom.fresh();
1059
+ }
1060
+ }
1061
+ }
1062
+ watch() {
1063
+ $mol_wire_atom.watching.add(this);
1064
+ }
1045
1065
  resync(args) {
1046
1066
  return this.put(this.task.call(this.host, ...args));
1047
1067
  }
@@ -1096,6 +1116,7 @@ var $;
1096
1116
  $mol_wire_method
1097
1117
  ], $mol_wire_atom.prototype, "once", null);
1098
1118
  $.$mol_wire_atom = $mol_wire_atom;
1119
+ $mol_wire_atom.watch();
1099
1120
  })($ || ($ = {}));
1100
1121
  //mol/wire/atom/atom.ts
1101
1122
  ;
@@ -1129,6 +1150,22 @@ var $;
1129
1150
  ;
1130
1151
  "use strict";
1131
1152
  var $;
1153
+ (function ($) {
1154
+ function $mol_wire_watch() {
1155
+ const atom = $mol_wire_auto();
1156
+ if (atom instanceof $mol_wire_atom) {
1157
+ atom.watch();
1158
+ }
1159
+ else {
1160
+ $mol_fail(new Error('Atom is equired for watching'));
1161
+ }
1162
+ }
1163
+ $.$mol_wire_watch = $mol_wire_watch;
1164
+ })($ || ($ = {}));
1165
+ //mol/wire/watch/watch.ts
1166
+ ;
1167
+ "use strict";
1168
+ var $;
1132
1169
  (function ($) {
1133
1170
  function $mol_wire_sync(obj) {
1134
1171
  return new Proxy(obj, {
@@ -1141,7 +1178,12 @@ var $;
1141
1178
  const fiber = temp(obj, args);
1142
1179
  return fiber.sync();
1143
1180
  };
1144
- }
1181
+ },
1182
+ apply(obj, self, args) {
1183
+ const temp = $mol_wire_task.getter(obj);
1184
+ const fiber = temp(self, args);
1185
+ return fiber.sync();
1186
+ },
1145
1187
  });
1146
1188
  }
1147
1189
  $.$mol_wire_sync = $mol_wire_sync;
@@ -1164,7 +1206,12 @@ var $;
1164
1206
  fiber = temp(obj, args);
1165
1207
  return fiber.async();
1166
1208
  };
1167
- }
1209
+ },
1210
+ apply(obj, self, args) {
1211
+ const temp = $mol_wire_task.getter(obj);
1212
+ const fiber = temp(self, args);
1213
+ return fiber.async();
1214
+ },
1168
1215
  });
1169
1216
  }
1170
1217
  $.$mol_wire_async = $mol_wire_async;
@@ -1268,6 +1315,39 @@ var $;
1268
1315
  ;
1269
1316
  "use strict";
1270
1317
  var $;
1318
+ (function ($) {
1319
+ function $mol_wire_patch(obj) {
1320
+ for (const field of Reflect.ownKeys(obj)) {
1321
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1322
+ if (!descr.configurable)
1323
+ continue;
1324
+ if (!descr.get)
1325
+ continue;
1326
+ const get = descr.get ?? (() => descr.value);
1327
+ const set = descr.set ?? (next => descr.value = next);
1328
+ const persist = $mol_wire_atom.getter(get, 0);
1329
+ Reflect.defineProperty(obj, field, {
1330
+ configurable: true,
1331
+ enumerable: descr.enumerable,
1332
+ get() {
1333
+ const atom = persist(obj, []);
1334
+ atom.watch();
1335
+ return atom.sync();
1336
+ },
1337
+ set(next) {
1338
+ const atom = persist(obj, []);
1339
+ set.call(this, next);
1340
+ atom.refresh();
1341
+ },
1342
+ });
1343
+ }
1344
+ }
1345
+ $.$mol_wire_patch = $mol_wire_patch;
1346
+ })($ || ($ = {}));
1347
+ //mol/wire/patch/patch.ts
1348
+ ;
1349
+ "use strict";
1350
+ var $;
1271
1351
  (function ($) {
1272
1352
  class $mol_wire_set extends Set {
1273
1353
  pub = new $mol_wire_pub;
@@ -1474,48 +1554,6 @@ var $;
1474
1554
  //mol/log3/log3.ts
1475
1555
  ;
1476
1556
  "use strict";
1477
- //node/node.ts
1478
- ;
1479
- "use strict";
1480
- var $node = new Proxy({ require }, {
1481
- get(target, name, wrapper) {
1482
- if (target[name])
1483
- return target[name];
1484
- const mod = target.require('module');
1485
- if (mod.builtinModules.indexOf(name) >= 0)
1486
- return target.require(name);
1487
- const path = target.require('path');
1488
- const fs = target.require('fs');
1489
- let dir = path.resolve('.');
1490
- const suffix = `./node_modules/${name}`;
1491
- const $$ = $;
1492
- while (!fs.existsSync(path.join(dir, suffix))) {
1493
- const parent = path.resolve(dir, '..');
1494
- if (parent === dir) {
1495
- $$.$mol_exec('.', 'npm', 'install', name);
1496
- try {
1497
- $$.$mol_exec('.', 'npm', 'install', '@types/' + name);
1498
- }
1499
- catch { }
1500
- break;
1501
- }
1502
- else {
1503
- dir = parent;
1504
- }
1505
- }
1506
- return target.require(name);
1507
- },
1508
- set(target, name, value) {
1509
- target[name] = value;
1510
- return true;
1511
- },
1512
- });
1513
- require = (req => Object.assign(function require(name) {
1514
- return $node[name];
1515
- }, req))(require);
1516
- //node/node.node.ts
1517
- ;
1518
- "use strict";
1519
1557
  var $;
1520
1558
  (function ($) {
1521
1559
  $.$mol_tree_convert = Symbol('$mol_tree_convert');
@@ -1847,80 +1885,77 @@ var $;
1847
1885
  ;
1848
1886
  "use strict";
1849
1887
  var $;
1888
+ (function ($) {
1889
+ class $mol_term_color {
1890
+ static reset = this.ansi(0, 0);
1891
+ static bold = this.ansi(1, 22);
1892
+ static italic = this.ansi(3, 23);
1893
+ static underline = this.ansi(4, 24);
1894
+ static inverse = this.ansi(7, 27);
1895
+ static hidden = this.ansi(8, 28);
1896
+ static strike = this.ansi(9, 29);
1897
+ static gray = this.ansi(90, 39);
1898
+ static red = this.ansi(91, 39);
1899
+ static green = this.ansi(92, 39);
1900
+ static yellow = this.ansi(93, 39);
1901
+ static blue = this.ansi(94, 39);
1902
+ static magenta = this.ansi(95, 39);
1903
+ static cyan = this.ansi(96, 39);
1904
+ static white = this.ansi(97, 39);
1905
+ static Red = (str) => this.inverse(this.red(str));
1906
+ static Green = (str) => this.inverse(this.green(str));
1907
+ static Yellow = (str) => this.inverse(this.yellow(str));
1908
+ static Blue = (str) => this.inverse(this.blue(str));
1909
+ static Magenta = (str) => this.inverse(this.magenta(str));
1910
+ static Cyan = (str) => this.inverse(this.cyan(str));
1911
+ static White = (str) => this.inverse(this.white(str));
1912
+ static ansi(open, close) {
1913
+ if (typeof process === 'undefined')
1914
+ return String;
1915
+ if (!process.stdout.isTTY)
1916
+ return String;
1917
+ const prefix = `\x1b[${open}m`;
1918
+ const postfix = `\x1b[${close}m`;
1919
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1920
+ return function colorer(str) {
1921
+ str = String(str);
1922
+ if (str === '')
1923
+ return str;
1924
+ const suffix = str.replace(suffix_regexp, prefix);
1925
+ return prefix + suffix + postfix;
1926
+ };
1927
+ }
1928
+ }
1929
+ $.$mol_term_color = $mol_term_color;
1930
+ })($ || ($ = {}));
1931
+ //mol/term/color/color.ts
1932
+ ;
1933
+ "use strict";
1934
+ var $;
1850
1935
  (function ($) {
1851
1936
  function $mol_log3_node_make(level, output, type, color) {
1852
1937
  return function $mol_log3_logger(event) {
1853
1938
  if (!event.time)
1854
1939
  event = { time: new Date().toISOString(), ...event };
1855
1940
  const tree = this.$mol_tree.fromJSON(event).clone({ type });
1856
- let str = tree.toString();
1857
- if (process[output].isTTY) {
1858
- str = $node.colorette[color + 'Bright'](str);
1859
- }
1860
- ;
1941
+ let str = color(tree.toString());
1861
1942
  this.console[level](str);
1862
1943
  const self = this;
1863
1944
  return () => self.console.groupEnd();
1864
1945
  };
1865
1946
  }
1866
1947
  $.$mol_log3_node_make = $mol_log3_node_make;
1867
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1868
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1869
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1870
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1871
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1872
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1948
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1949
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1950
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1951
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1952
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1953
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1873
1954
  })($ || ($ = {}));
1874
1955
  //mol/log3/log3.node.ts
1875
1956
  ;
1876
1957
  "use strict";
1877
1958
  var $;
1878
- (function ($) {
1879
- function $mol_env() {
1880
- return {};
1881
- }
1882
- $.$mol_env = $mol_env;
1883
- })($ || ($ = {}));
1884
- //mol/env/env.ts
1885
- ;
1886
- "use strict";
1887
- var $;
1888
- (function ($) {
1889
- $.$mol_env = function $mol_env() {
1890
- return this.process.env;
1891
- };
1892
- })($ || ($ = {}));
1893
- //mol/env/env.node.ts
1894
- ;
1895
- "use strict";
1896
- var $;
1897
- (function ($) {
1898
- function $mol_exec(dir, command, ...args) {
1899
- let [app, ...args0] = command.split(' ');
1900
- args = [...args0, ...args];
1901
- this.$mol_log3_come({
1902
- place: '$mol_exec',
1903
- dir: $node.path.relative('', dir),
1904
- message: 'Run',
1905
- command: `${app} ${args.join(' ')}`,
1906
- });
1907
- var res = $node['child_process'].spawnSync(app, args, {
1908
- cwd: $node.path.resolve(dir),
1909
- shell: true,
1910
- env: this.$mol_env(),
1911
- });
1912
- if (res.status || res.error)
1913
- return $mol_fail(res.error || new Error(res.stderr.toString()));
1914
- if (!res.stdout)
1915
- res.stdout = Buffer.from([]);
1916
- return res;
1917
- }
1918
- $.$mol_exec = $mol_exec;
1919
- })($ || ($ = {}));
1920
- //mol/exec/exec.node.ts
1921
- ;
1922
- "use strict";
1923
- var $;
1924
1959
  (function ($) {
1925
1960
  class $mol_wire_log extends $mol_object2 {
1926
1961
  static watch(task) {