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.test.js CHANGED
@@ -85,7 +85,7 @@ var $;
85
85
  promote() {
86
86
  $mol_wire_auto()?.track_next(this);
87
87
  }
88
- refresh() { }
88
+ fresh() { }
89
89
  complete() { }
90
90
  emit(quant = $mol_wire_cursor.stale) {
91
91
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -288,7 +288,7 @@ var $;
288
288
  }
289
289
  for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
290
290
  const pub = this.data[cursor];
291
- pub.refresh();
291
+ pub.fresh();
292
292
  }
293
293
  this.cursor = $mol_wire_cursor.fresh;
294
294
  }
@@ -584,7 +584,7 @@ var $;
584
584
  continue;
585
585
  if (fiber.cursor === $mol_wire_cursor.final)
586
586
  continue;
587
- fiber.refresh();
587
+ fiber.fresh();
588
588
  }
589
589
  }
590
590
  while (this.reaping.size) {
@@ -652,7 +652,7 @@ var $;
652
652
  else
653
653
  super.emit(quant);
654
654
  }
655
- refresh() {
655
+ fresh() {
656
656
  if (this.cursor === $mol_wire_cursor.fresh)
657
657
  return;
658
658
  if (this.cursor === $mol_wire_cursor.final)
@@ -660,7 +660,7 @@ var $;
660
660
  check: if (this.cursor === $mol_wire_cursor.doubt) {
661
661
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
662
662
  ;
663
- this.data[i]?.refresh();
663
+ this.data[i]?.fresh();
664
664
  if (this.cursor !== $mol_wire_cursor.doubt)
665
665
  break check;
666
666
  }
@@ -716,12 +716,16 @@ var $;
716
716
  this.track_off(bu);
717
717
  this.put(result);
718
718
  }
719
+ refresh() {
720
+ this.cursor = $mol_wire_cursor.stale;
721
+ this.fresh();
722
+ }
719
723
  sync() {
720
724
  if (!$mol_wire_fiber.warm) {
721
725
  return this.result();
722
726
  }
723
727
  this.promote();
724
- this.refresh();
728
+ this.fresh();
725
729
  if (this.cache instanceof Error) {
726
730
  return $mol_fail_hidden(this.cache);
727
731
  }
@@ -732,7 +736,7 @@ var $;
732
736
  }
733
737
  async async() {
734
738
  while (true) {
735
- this.refresh();
739
+ this.fresh();
736
740
  if (this.cache instanceof Error) {
737
741
  $mol_fail_hidden(this.cache);
738
742
  }
@@ -1034,6 +1038,22 @@ var $;
1034
1038
  };
1035
1039
  }
1036
1040
  }
1041
+ static watching = new Set();
1042
+ static watch() {
1043
+ new $mol_after_frame($mol_wire_atom.watch);
1044
+ for (const atom of $mol_wire_atom.watching) {
1045
+ if (atom.cursor === $mol_wire_cursor.final) {
1046
+ $mol_wire_atom.watching.delete(atom);
1047
+ }
1048
+ else {
1049
+ atom.cursor = $mol_wire_cursor.stale;
1050
+ atom.fresh();
1051
+ }
1052
+ }
1053
+ }
1054
+ watch() {
1055
+ $mol_wire_atom.watching.add(this);
1056
+ }
1037
1057
  resync(args) {
1038
1058
  return this.put(this.task.call(this.host, ...args));
1039
1059
  }
@@ -1088,6 +1108,7 @@ var $;
1088
1108
  $mol_wire_method
1089
1109
  ], $mol_wire_atom.prototype, "once", null);
1090
1110
  $.$mol_wire_atom = $mol_wire_atom;
1111
+ $mol_wire_atom.watch();
1091
1112
  })($ || ($ = {}));
1092
1113
  //mol/wire/atom/atom.ts
1093
1114
  ;
@@ -1121,6 +1142,22 @@ var $;
1121
1142
  ;
1122
1143
  "use strict";
1123
1144
  var $;
1145
+ (function ($) {
1146
+ function $mol_wire_watch() {
1147
+ const atom = $mol_wire_auto();
1148
+ if (atom instanceof $mol_wire_atom) {
1149
+ atom.watch();
1150
+ }
1151
+ else {
1152
+ $mol_fail(new Error('Atom is equired for watching'));
1153
+ }
1154
+ }
1155
+ $.$mol_wire_watch = $mol_wire_watch;
1156
+ })($ || ($ = {}));
1157
+ //mol/wire/watch/watch.ts
1158
+ ;
1159
+ "use strict";
1160
+ var $;
1124
1161
  (function ($) {
1125
1162
  function $mol_wire_sync(obj) {
1126
1163
  return new Proxy(obj, {
@@ -1133,7 +1170,12 @@ var $;
1133
1170
  const fiber = temp(obj, args);
1134
1171
  return fiber.sync();
1135
1172
  };
1136
- }
1173
+ },
1174
+ apply(obj, self, args) {
1175
+ const temp = $mol_wire_task.getter(obj);
1176
+ const fiber = temp(self, args);
1177
+ return fiber.sync();
1178
+ },
1137
1179
  });
1138
1180
  }
1139
1181
  $.$mol_wire_sync = $mol_wire_sync;
@@ -1156,7 +1198,12 @@ var $;
1156
1198
  fiber = temp(obj, args);
1157
1199
  return fiber.async();
1158
1200
  };
1159
- }
1201
+ },
1202
+ apply(obj, self, args) {
1203
+ const temp = $mol_wire_task.getter(obj);
1204
+ const fiber = temp(self, args);
1205
+ return fiber.async();
1206
+ },
1160
1207
  });
1161
1208
  }
1162
1209
  $.$mol_wire_async = $mol_wire_async;
@@ -1260,6 +1307,39 @@ var $;
1260
1307
  ;
1261
1308
  "use strict";
1262
1309
  var $;
1310
+ (function ($) {
1311
+ function $mol_wire_patch(obj) {
1312
+ for (const field of Reflect.ownKeys(obj)) {
1313
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1314
+ if (!descr.configurable)
1315
+ continue;
1316
+ if (!descr.get)
1317
+ continue;
1318
+ const get = descr.get ?? (() => descr.value);
1319
+ const set = descr.set ?? (next => descr.value = next);
1320
+ const persist = $mol_wire_atom.getter(get, 0);
1321
+ Reflect.defineProperty(obj, field, {
1322
+ configurable: true,
1323
+ enumerable: descr.enumerable,
1324
+ get() {
1325
+ const atom = persist(obj, []);
1326
+ atom.watch();
1327
+ return atom.sync();
1328
+ },
1329
+ set(next) {
1330
+ const atom = persist(obj, []);
1331
+ set.call(this, next);
1332
+ atom.refresh();
1333
+ },
1334
+ });
1335
+ }
1336
+ }
1337
+ $.$mol_wire_patch = $mol_wire_patch;
1338
+ })($ || ($ = {}));
1339
+ //mol/wire/patch/patch.ts
1340
+ ;
1341
+ "use strict";
1342
+ var $;
1263
1343
  (function ($) {
1264
1344
  class $mol_wire_set extends Set {
1265
1345
  pub = new $mol_wire_pub;
@@ -1466,48 +1546,6 @@ var $;
1466
1546
  //mol/log3/log3.ts
1467
1547
  ;
1468
1548
  "use strict";
1469
- //node/node.ts
1470
- ;
1471
- "use strict";
1472
- var $node = new Proxy({ require }, {
1473
- get(target, name, wrapper) {
1474
- if (target[name])
1475
- return target[name];
1476
- const mod = target.require('module');
1477
- if (mod.builtinModules.indexOf(name) >= 0)
1478
- return target.require(name);
1479
- const path = target.require('path');
1480
- const fs = target.require('fs');
1481
- let dir = path.resolve('.');
1482
- const suffix = `./node_modules/${name}`;
1483
- const $$ = $;
1484
- while (!fs.existsSync(path.join(dir, suffix))) {
1485
- const parent = path.resolve(dir, '..');
1486
- if (parent === dir) {
1487
- $$.$mol_exec('.', 'npm', 'install', name);
1488
- try {
1489
- $$.$mol_exec('.', 'npm', 'install', '@types/' + name);
1490
- }
1491
- catch { }
1492
- break;
1493
- }
1494
- else {
1495
- dir = parent;
1496
- }
1497
- }
1498
- return target.require(name);
1499
- },
1500
- set(target, name, value) {
1501
- target[name] = value;
1502
- return true;
1503
- },
1504
- });
1505
- require = (req => Object.assign(function require(name) {
1506
- return $node[name];
1507
- }, req))(require);
1508
- //node/node.node.ts
1509
- ;
1510
- "use strict";
1511
1549
  var $;
1512
1550
  (function ($) {
1513
1551
  $.$mol_tree_convert = Symbol('$mol_tree_convert');
@@ -1839,80 +1877,77 @@ var $;
1839
1877
  ;
1840
1878
  "use strict";
1841
1879
  var $;
1880
+ (function ($) {
1881
+ class $mol_term_color {
1882
+ static reset = this.ansi(0, 0);
1883
+ static bold = this.ansi(1, 22);
1884
+ static italic = this.ansi(3, 23);
1885
+ static underline = this.ansi(4, 24);
1886
+ static inverse = this.ansi(7, 27);
1887
+ static hidden = this.ansi(8, 28);
1888
+ static strike = this.ansi(9, 29);
1889
+ static gray = this.ansi(90, 39);
1890
+ static red = this.ansi(91, 39);
1891
+ static green = this.ansi(92, 39);
1892
+ static yellow = this.ansi(93, 39);
1893
+ static blue = this.ansi(94, 39);
1894
+ static magenta = this.ansi(95, 39);
1895
+ static cyan = this.ansi(96, 39);
1896
+ static white = this.ansi(97, 39);
1897
+ static Red = (str) => this.inverse(this.red(str));
1898
+ static Green = (str) => this.inverse(this.green(str));
1899
+ static Yellow = (str) => this.inverse(this.yellow(str));
1900
+ static Blue = (str) => this.inverse(this.blue(str));
1901
+ static Magenta = (str) => this.inverse(this.magenta(str));
1902
+ static Cyan = (str) => this.inverse(this.cyan(str));
1903
+ static White = (str) => this.inverse(this.white(str));
1904
+ static ansi(open, close) {
1905
+ if (typeof process === 'undefined')
1906
+ return String;
1907
+ if (!process.stdout.isTTY)
1908
+ return String;
1909
+ const prefix = `\x1b[${open}m`;
1910
+ const postfix = `\x1b[${close}m`;
1911
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1912
+ return function colorer(str) {
1913
+ str = String(str);
1914
+ if (str === '')
1915
+ return str;
1916
+ const suffix = str.replace(suffix_regexp, prefix);
1917
+ return prefix + suffix + postfix;
1918
+ };
1919
+ }
1920
+ }
1921
+ $.$mol_term_color = $mol_term_color;
1922
+ })($ || ($ = {}));
1923
+ //mol/term/color/color.ts
1924
+ ;
1925
+ "use strict";
1926
+ var $;
1842
1927
  (function ($) {
1843
1928
  function $mol_log3_node_make(level, output, type, color) {
1844
1929
  return function $mol_log3_logger(event) {
1845
1930
  if (!event.time)
1846
1931
  event = { time: new Date().toISOString(), ...event };
1847
1932
  const tree = this.$mol_tree.fromJSON(event).clone({ type });
1848
- let str = tree.toString();
1849
- if (process[output].isTTY) {
1850
- str = $node.colorette[color + 'Bright'](str);
1851
- }
1852
- ;
1933
+ let str = color(tree.toString());
1853
1934
  this.console[level](str);
1854
1935
  const self = this;
1855
1936
  return () => self.console.groupEnd();
1856
1937
  };
1857
1938
  }
1858
1939
  $.$mol_log3_node_make = $mol_log3_node_make;
1859
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1860
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1861
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1862
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1863
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1864
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1940
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1941
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1942
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1943
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1944
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1945
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1865
1946
  })($ || ($ = {}));
1866
1947
  //mol/log3/log3.node.ts
1867
1948
  ;
1868
1949
  "use strict";
1869
1950
  var $;
1870
- (function ($) {
1871
- function $mol_env() {
1872
- return {};
1873
- }
1874
- $.$mol_env = $mol_env;
1875
- })($ || ($ = {}));
1876
- //mol/env/env.ts
1877
- ;
1878
- "use strict";
1879
- var $;
1880
- (function ($) {
1881
- $.$mol_env = function $mol_env() {
1882
- return this.process.env;
1883
- };
1884
- })($ || ($ = {}));
1885
- //mol/env/env.node.ts
1886
- ;
1887
- "use strict";
1888
- var $;
1889
- (function ($) {
1890
- function $mol_exec(dir, command, ...args) {
1891
- let [app, ...args0] = command.split(' ');
1892
- args = [...args0, ...args];
1893
- this.$mol_log3_come({
1894
- place: '$mol_exec',
1895
- dir: $node.path.relative('', dir),
1896
- message: 'Run',
1897
- command: `${app} ${args.join(' ')}`,
1898
- });
1899
- var res = $node['child_process'].spawnSync(app, args, {
1900
- cwd: $node.path.resolve(dir),
1901
- shell: true,
1902
- env: this.$mol_env(),
1903
- });
1904
- if (res.status || res.error)
1905
- return $mol_fail(res.error || new Error(res.stderr.toString()));
1906
- if (!res.stdout)
1907
- res.stdout = Buffer.from([]);
1908
- return res;
1909
- }
1910
- $.$mol_exec = $mol_exec;
1911
- })($ || ($ = {}));
1912
- //mol/exec/exec.node.ts
1913
- ;
1914
- "use strict";
1915
- var $;
1916
1951
  (function ($) {
1917
1952
  class $mol_wire_log extends $mol_object2 {
1918
1953
  static watch(task) {
@@ -2073,6 +2108,110 @@ var $;
2073
2108
  //mol/dom/context/context.ts
2074
2109
  ;
2075
2110
  "use strict";
2111
+ //node/node.ts
2112
+ ;
2113
+ "use strict";
2114
+ var $node = new Proxy({ require }, {
2115
+ get(target, name, wrapper) {
2116
+ if (target[name])
2117
+ return target[name];
2118
+ const mod = target.require('module');
2119
+ if (mod.builtinModules.indexOf(name) >= 0)
2120
+ return target.require(name);
2121
+ if (name[0] === '.')
2122
+ return target.require(name);
2123
+ const path = target.require('path');
2124
+ const fs = target.require('fs');
2125
+ let dir = path.resolve('.');
2126
+ const suffix = `./node_modules/${name}`;
2127
+ const $$ = $;
2128
+ while (!fs.existsSync(path.join(dir, suffix))) {
2129
+ const parent = path.resolve(dir, '..');
2130
+ if (parent === dir) {
2131
+ $$.$mol_exec('.', 'npm', 'install', name);
2132
+ try {
2133
+ $$.$mol_exec('.', 'npm', 'install', '@types/' + name);
2134
+ }
2135
+ catch { }
2136
+ break;
2137
+ }
2138
+ else {
2139
+ dir = parent;
2140
+ }
2141
+ }
2142
+ return target.require(name);
2143
+ },
2144
+ set(target, name, value) {
2145
+ target[name] = value;
2146
+ return true;
2147
+ },
2148
+ });
2149
+ require = (req => Object.assign(function require(name) {
2150
+ return $node[name];
2151
+ }, req))(require);
2152
+ //node/node.node.ts
2153
+ ;
2154
+ "use strict";
2155
+ var $;
2156
+ (function ($_1) {
2157
+ $mol_test_mocks.push($ => {
2158
+ $.$mol_log3_come = () => { };
2159
+ $.$mol_log3_done = () => { };
2160
+ $.$mol_log3_fail = () => { };
2161
+ $.$mol_log3_warn = () => { };
2162
+ $.$mol_log3_rise = () => { };
2163
+ $.$mol_log3_area = () => () => { };
2164
+ });
2165
+ })($ || ($ = {}));
2166
+ //mol/log3/log3.test.ts
2167
+ ;
2168
+ "use strict";
2169
+ var $;
2170
+ (function ($) {
2171
+ function $mol_env() {
2172
+ return {};
2173
+ }
2174
+ $.$mol_env = $mol_env;
2175
+ })($ || ($ = {}));
2176
+ //mol/env/env.ts
2177
+ ;
2178
+ "use strict";
2179
+ var $;
2180
+ (function ($) {
2181
+ $.$mol_env = function $mol_env() {
2182
+ return this.process.env;
2183
+ };
2184
+ })($ || ($ = {}));
2185
+ //mol/env/env.node.ts
2186
+ ;
2187
+ "use strict";
2188
+ var $;
2189
+ (function ($) {
2190
+ function $mol_exec(dir, command, ...args) {
2191
+ let [app, ...args0] = command.split(' ');
2192
+ args = [...args0, ...args];
2193
+ this.$mol_log3_come({
2194
+ place: '$mol_exec',
2195
+ dir: $node.path.relative('', dir),
2196
+ message: 'Run',
2197
+ command: `${app} ${args.join(' ')}`,
2198
+ });
2199
+ var res = $node['child_process'].spawnSync(app, args, {
2200
+ cwd: $node.path.resolve(dir),
2201
+ shell: true,
2202
+ env: this.$mol_env(),
2203
+ });
2204
+ if (res.status || res.error)
2205
+ return $mol_fail(res.error || new Error(res.stderr.toString()));
2206
+ if (!res.stdout)
2207
+ res.stdout = Buffer.from([]);
2208
+ return res;
2209
+ }
2210
+ $.$mol_exec = $mol_exec;
2211
+ })($ || ($ = {}));
2212
+ //mol/exec/exec.node.ts
2213
+ ;
2214
+ "use strict";
2076
2215
  var $;
2077
2216
  (function ($) {
2078
2217
  $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
@@ -2537,20 +2676,6 @@ var $;
2537
2676
  ;
2538
2677
  "use strict";
2539
2678
  var $;
2540
- (function ($_1) {
2541
- $mol_test_mocks.push($ => {
2542
- $.$mol_log3_come = () => { };
2543
- $.$mol_log3_done = () => { };
2544
- $.$mol_log3_fail = () => { };
2545
- $.$mol_log3_warn = () => { };
2546
- $.$mol_log3_rise = () => { };
2547
- $.$mol_log3_area = () => () => { };
2548
- });
2549
- })($ || ($ = {}));
2550
- //mol/log3/log3.test.ts
2551
- ;
2552
- "use strict";
2553
- var $;
2554
2679
  (function ($) {
2555
2680
  $mol_test({
2556
2681
  'get'() {
@@ -2773,6 +2898,15 @@ var $;
2773
2898
  ;
2774
2899
  "use strict";
2775
2900
  var $;
2901
+ (function ($_1) {
2902
+ $mol_test_mocks.push($ => {
2903
+ $.$mol_after_timeout = $mol_after_mock_timeout;
2904
+ });
2905
+ })($ || ($ = {}));
2906
+ //mol/after/timeout/timeout.test.ts
2907
+ ;
2908
+ "use strict";
2909
+ var $;
2776
2910
  (function ($_1) {
2777
2911
  $mol_test({
2778
2912
  async 'Latest Calls Wins on Concurrency'($) {
@@ -2794,21 +2928,21 @@ var $;
2794
2928
  $mol_assert_like(NameLogger.first, ['john', 'jin']);
2795
2929
  $mol_assert_like(NameLogger.last, ['jin']);
2796
2930
  },
2931
+ async 'Wrap function'($) {
2932
+ const name = $mol_wire_async(function (name) {
2933
+ $.$mol_wait_timeout(0);
2934
+ return name;
2935
+ });
2936
+ const promise = name('jin');
2937
+ $.$mol_after_mock_warp();
2938
+ $mol_assert_like(await promise, 'jin');
2939
+ },
2797
2940
  });
2798
2941
  })($ || ($ = {}));
2799
2942
  //mol/wire/async/async.test.ts
2800
2943
  ;
2801
2944
  "use strict";
2802
2945
  var $;
2803
- (function ($_1) {
2804
- $mol_test_mocks.push($ => {
2805
- $.$mol_after_timeout = $mol_after_mock_timeout;
2806
- });
2807
- })($ || ($ = {}));
2808
- //mol/after/timeout/timeout.test.ts
2809
- ;
2810
- "use strict";
2811
- var $;
2812
2946
  (function ($_1) {
2813
2947
  $mol_test_mocks.push($ => {
2814
2948
  $.$mol_after_frame = $mol_after_mock_commmon;