mol_plot_all 1.2.1174 → 1.2.1176

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
@@ -1994,7 +1994,11 @@ var $node = new Proxy({ require }, {
1994
1994
  try {
1995
1995
  $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1996
1996
  }
1997
- catch { }
1997
+ catch (e) {
1998
+ if ($$.$mol_fail_catch(e)) {
1999
+ $$.$mol_fail_log(e);
2000
+ }
2001
+ }
1998
2002
  break;
1999
2003
  }
2000
2004
  else {
@@ -2005,7 +2009,7 @@ var $node = new Proxy({ require }, {
2005
2009
  return target.require(name);
2006
2010
  }
2007
2011
  catch (error) {
2008
- if (error.code === 'ERR_REQUIRE_ESM') {
2012
+ if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
2009
2013
  const module = cache.get(name);
2010
2014
  if (module)
2011
2015
  return module;
@@ -2025,6 +2029,36 @@ require = (req => Object.assign(function require(name) {
2025
2029
  return $node[name];
2026
2030
  }, req))(require);
2027
2031
 
2032
+ ;
2033
+ "use strict";
2034
+ var $;
2035
+ (function ($) {
2036
+ class $mol_error_mix extends AggregateError {
2037
+ cause;
2038
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
2039
+ constructor(message, cause = {}, ...errors) {
2040
+ super(errors, message, { cause });
2041
+ this.cause = cause;
2042
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
2043
+ Object.defineProperty(this, 'stack', {
2044
+ get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
2045
+ .replace(/at /gm, ' at ')
2046
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
2047
+ });
2048
+ }
2049
+ static [Symbol.toPrimitive]() {
2050
+ return this.toString();
2051
+ }
2052
+ static toString() {
2053
+ return $$.$mol_func_name(this);
2054
+ }
2055
+ static make(...params) {
2056
+ return new this(...params);
2057
+ }
2058
+ }
2059
+ $.$mol_error_mix = $mol_error_mix;
2060
+ })($ || ($ = {}));
2061
+
2028
2062
  ;
2029
2063
  "use strict";
2030
2064
  var $;
@@ -2048,26 +2082,145 @@ var $;
2048
2082
  "use strict";
2049
2083
  var $;
2050
2084
  (function ($) {
2051
- function $mol_exec(dir, command, ...args) {
2052
- let [app, ...args0] = command.split(' ');
2053
- args = [...args0, ...args];
2085
+ const factories = new WeakMap();
2086
+ function factory(val) {
2087
+ let make = factories.get(val);
2088
+ if (make)
2089
+ return make;
2090
+ make = $mol_func_name_from((...args) => new val(...args), val);
2091
+ factories.set(val, make);
2092
+ return make;
2093
+ }
2094
+ function $mol_wire_sync(obj) {
2095
+ return new Proxy(obj, {
2096
+ get(obj, field) {
2097
+ let val = obj[field];
2098
+ if (typeof val !== 'function')
2099
+ return val;
2100
+ const temp = $mol_wire_task.getter(val);
2101
+ return function $mol_wire_sync(...args) {
2102
+ const fiber = temp(obj, args);
2103
+ return fiber.sync();
2104
+ };
2105
+ },
2106
+ construct(obj, args) {
2107
+ const temp = $mol_wire_task.getter(factory(obj));
2108
+ return temp(obj, args).sync();
2109
+ },
2110
+ apply(obj, self, args) {
2111
+ const temp = $mol_wire_task.getter(obj);
2112
+ return temp(self, args).sync();
2113
+ },
2114
+ });
2115
+ }
2116
+ $.$mol_wire_sync = $mol_wire_sync;
2117
+ })($ || ($ = {}));
2118
+
2119
+ ;
2120
+ "use strict";
2121
+ var $;
2122
+ (function ($) {
2123
+ class $mol_run_error extends $mol_error_mix {
2124
+ }
2125
+ $.$mol_run_error = $mol_run_error;
2126
+ const child_process = $node['child_process'];
2127
+ $.$mol_run_spawn = child_process.spawn.bind(child_process);
2128
+ $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2129
+ function $mol_run_async({ dir, timeout, command, env }) {
2130
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2131
+ const [app, ...args] = args_raw;
2132
+ if (!env?.MOL_RUN_ASYNC) {
2133
+ this.$mol_log3_come({
2134
+ place: '$mol_run_sync',
2135
+ message: 'Run',
2136
+ command: args_raw.join(' '),
2137
+ dir: $node.path.relative('', dir),
2138
+ });
2139
+ return this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2140
+ }
2141
+ const sub = this.$mol_run_spawn(app, args, {
2142
+ shell: true,
2143
+ cwd: dir,
2144
+ env
2145
+ });
2054
2146
  this.$mol_log3_come({
2055
- place: '$mol_exec',
2056
- dir: $node.path.relative('', dir),
2147
+ place: '$mol_run_async',
2148
+ pid: sub.pid,
2057
2149
  message: 'Run',
2058
- command: `${app} ${args.join(' ')}`,
2150
+ command: args_raw.join(' '),
2151
+ dir: $node.path.relative('', dir),
2059
2152
  });
2060
- var res = $node['child_process'].spawnSync(app, args, {
2061
- cwd: $node.path.resolve(dir),
2062
- shell: true,
2063
- env: this.$mol_env(),
2153
+ let killed = false;
2154
+ let timer;
2155
+ const std_data = [];
2156
+ const error_data = [];
2157
+ const add = (std_chunk, error_chunk) => {
2158
+ if (std_chunk)
2159
+ std_data.push(std_chunk);
2160
+ if (error_chunk)
2161
+ error_data.push(error_chunk);
2162
+ if (!timeout)
2163
+ return;
2164
+ clearTimeout(timer);
2165
+ timer = setTimeout(() => {
2166
+ const signal = killed ? 'SIGKILL' : 'SIGTERM';
2167
+ killed = true;
2168
+ add();
2169
+ sub.kill(signal);
2170
+ }, timeout);
2171
+ };
2172
+ add();
2173
+ sub.stdout?.on('data', data => add(data));
2174
+ sub.stderr?.on('data', data => add(undefined, data));
2175
+ const promise = new Promise((done, fail) => {
2176
+ const close = (error, status = null, signal = null) => {
2177
+ if (!timer && timeout)
2178
+ return;
2179
+ clearTimeout(timer);
2180
+ timer = undefined;
2181
+ const res = {
2182
+ pid: sub.pid,
2183
+ status,
2184
+ signal,
2185
+ get stdout() { return Buffer.concat(std_data); },
2186
+ get stderr() { return Buffer.concat(error_data); }
2187
+ };
2188
+ this.$mol_log3_done({
2189
+ place: '$mol_run_async',
2190
+ pid: sub.pid,
2191
+ message: 'Run',
2192
+ status,
2193
+ command: args_raw.join(' '),
2194
+ dir: $node.path.relative('', dir),
2195
+ });
2196
+ if (error || status || killed)
2197
+ return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
2198
+ done(res);
2199
+ };
2200
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2201
+ sub.on('error', err => close(err));
2202
+ sub.on('exit', (status, signal) => close(null, status, signal));
2064
2203
  });
2065
- if (res.status || res.error) {
2066
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
2067
- }
2068
- if (!res.stdout)
2069
- res.stdout = Buffer.from([]);
2070
- return res;
2204
+ return Object.assign(promise, { destructor: () => {
2205
+ clearTimeout(timer);
2206
+ sub.kill('SIGKILL');
2207
+ } });
2208
+ }
2209
+ $.$mol_run_async = $mol_run_async;
2210
+ function $mol_run(options) {
2211
+ if (!options.env)
2212
+ options = { ...options, env: this.$mol_env() };
2213
+ return $mol_wire_sync(this).$mol_run_async(options);
2214
+ }
2215
+ $.$mol_run = $mol_run;
2216
+ })($ || ($ = {}));
2217
+
2218
+ ;
2219
+ "use strict";
2220
+ var $;
2221
+ (function ($) {
2222
+ function $mol_exec(dir, command, ...args) {
2223
+ return this.$mol_run({ command: [command, ...args], dir });
2071
2224
  }
2072
2225
  $.$mol_exec = $mol_exec;
2073
2226
  })($ || ($ = {}));
@@ -6151,20 +6304,6 @@ var $;
6151
6304
  $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
6152
6305
  })($ || ($ = {}));
6153
6306
 
6154
- ;
6155
- "use strict";
6156
- var $;
6157
- (function ($_1) {
6158
- $mol_test_mocks.push($ => {
6159
- $.$mol_log3_come = () => { };
6160
- $.$mol_log3_done = () => { };
6161
- $.$mol_log3_fail = () => { };
6162
- $.$mol_log3_warn = () => { };
6163
- $.$mol_log3_rise = () => { };
6164
- $.$mol_log3_area = () => () => { };
6165
- });
6166
- })($ || ($ = {}));
6167
-
6168
6307
  ;
6169
6308
  "use strict";
6170
6309
 
@@ -6933,6 +7072,20 @@ var $;
6933
7072
  });
6934
7073
  })($ || ($ = {}));
6935
7074
 
7075
+ ;
7076
+ "use strict";
7077
+ var $;
7078
+ (function ($_1) {
7079
+ $mol_test_mocks.push($ => {
7080
+ $.$mol_log3_come = () => { };
7081
+ $.$mol_log3_done = () => { };
7082
+ $.$mol_log3_fail = () => { };
7083
+ $.$mol_log3_warn = () => { };
7084
+ $.$mol_log3_rise = () => { };
7085
+ $.$mol_log3_area = () => () => { };
7086
+ });
7087
+ })($ || ($ = {}));
7088
+
6936
7089
  ;
6937
7090
  "use strict";
6938
7091
  var $;
@@ -7199,16 +7352,30 @@ var $;
7199
7352
  var $;
7200
7353
  (function ($) {
7201
7354
  $mol_test({
7202
- 'init with overload'() {
7203
- class X extends $mol_object {
7204
- foo() {
7205
- return 1;
7355
+ 'auto name'() {
7356
+ class Invalid extends $mol_error_mix {
7357
+ }
7358
+ const mix = new Invalid('foo');
7359
+ $mol_assert_equal(mix.name, 'Invalid_Error');
7360
+ },
7361
+ 'simpe mix'() {
7362
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
7363
+ $mol_assert_equal(mix.message, 'foo');
7364
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
7365
+ },
7366
+ 'provide additional info'() {
7367
+ class Invalid extends $mol_error_mix {
7368
+ }
7369
+ const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
7370
+ const hints = [];
7371
+ if (mix instanceof $mol_error_mix) {
7372
+ for (const er of mix.errors) {
7373
+ if (er instanceof Invalid) {
7374
+ hints.push(er.cause?.hint ?? '');
7375
+ }
7206
7376
  }
7207
7377
  }
7208
- var x = X.make({
7209
- foo: () => 2,
7210
- });
7211
- $mol_assert_equal(x.foo(), 2);
7378
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
7212
7379
  },
7213
7380
  });
7214
7381
  })($ || ($ = {}));
@@ -7402,6 +7569,109 @@ var $;
7402
7569
 
7403
7570
  ;
7404
7571
  "use strict";
7572
+ var $;
7573
+ (function ($_1) {
7574
+ $mol_test({
7575
+ 'test types'($) {
7576
+ class A {
7577
+ static a() {
7578
+ return '';
7579
+ }
7580
+ static b() {
7581
+ return $mol_wire_async(this).a();
7582
+ }
7583
+ }
7584
+ },
7585
+ async 'Latest method calls wins'($) {
7586
+ class NameLogger extends $mol_object2 {
7587
+ static $ = $;
7588
+ static first = [];
7589
+ static last = [];
7590
+ static send(next) {
7591
+ $mol_wire_sync(this.first).push(next);
7592
+ this.$.$mol_wait_timeout(0);
7593
+ this.last.push(next);
7594
+ }
7595
+ }
7596
+ const name = $mol_wire_async(NameLogger).send;
7597
+ name('john');
7598
+ const promise = name('jin');
7599
+ $.$mol_after_mock_warp();
7600
+ await promise;
7601
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
7602
+ $mol_assert_like(NameLogger.last, ['jin']);
7603
+ },
7604
+ async 'Latest function calls wins'($) {
7605
+ const first = [];
7606
+ const last = [];
7607
+ function send_name(next) {
7608
+ $mol_wire_sync(first).push(next);
7609
+ $.$mol_wait_timeout(0);
7610
+ last.push(next);
7611
+ }
7612
+ const name = $mol_wire_async(send_name);
7613
+ name('john');
7614
+ const promise = name('jin');
7615
+ $.$mol_after_mock_warp();
7616
+ await promise;
7617
+ $mol_assert_like(first, ['john', 'jin']);
7618
+ $mol_assert_like(last, ['jin']);
7619
+ },
7620
+ });
7621
+ })($ || ($ = {}));
7622
+
7623
+ ;
7624
+ "use strict";
7625
+ var $;
7626
+ (function ($_1) {
7627
+ $mol_test({
7628
+ 'test types'($) {
7629
+ class A {
7630
+ static a() {
7631
+ return Promise.resolve('');
7632
+ }
7633
+ static b() {
7634
+ return $mol_wire_sync(this).a();
7635
+ }
7636
+ }
7637
+ },
7638
+ async 'test method from host'($) {
7639
+ let count = 0;
7640
+ class A {
7641
+ static a() {
7642
+ return $mol_wire_sync(this).b();
7643
+ }
7644
+ static b() { return Promise.resolve(++count); }
7645
+ }
7646
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
7647
+ },
7648
+ async 'test function'($) {
7649
+ let count = 0;
7650
+ class A {
7651
+ static a() {
7652
+ return $mol_wire_sync(this.b)();
7653
+ }
7654
+ static b() { return Promise.resolve(++count); }
7655
+ }
7656
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
7657
+ },
7658
+ async 'test construct itself'($) {
7659
+ class A {
7660
+ static instances = [];
7661
+ static a() {
7662
+ const a = new ($mol_wire_sync(A))();
7663
+ this.instances.push(a);
7664
+ $mol_wire_sync(this).b();
7665
+ }
7666
+ static b() { return Promise.resolve(); }
7667
+ }
7668
+ await $mol_wire_async(A).a();
7669
+ $mol_assert_equal(A.instances.length, 2);
7670
+ $mol_assert_equal(A.instances[0] instanceof A);
7671
+ $mol_assert_equal(A.instances[0], A.instances[1]);
7672
+ }
7673
+ });
7674
+ })($ || ($ = {}));
7405
7675
 
7406
7676
  ;
7407
7677
  "use strict";
@@ -7431,50 +7701,6 @@ var $;
7431
7701
  });
7432
7702
  })($ || ($ = {}));
7433
7703
 
7434
- ;
7435
- "use strict";
7436
- var $;
7437
- (function ($) {
7438
- function $mol_wire_sync(obj) {
7439
- return new Proxy(obj, {
7440
- get(obj, field) {
7441
- const val = obj[field];
7442
- if (typeof val !== 'function')
7443
- return val;
7444
- const temp = $mol_wire_task.getter(val);
7445
- return function $mol_wire_sync(...args) {
7446
- const fiber = temp(obj, args);
7447
- return fiber.sync();
7448
- };
7449
- },
7450
- apply(obj, self, args) {
7451
- const temp = $mol_wire_task.getter(obj);
7452
- const fiber = temp(self, args);
7453
- return fiber.sync();
7454
- },
7455
- });
7456
- }
7457
- $.$mol_wire_sync = $mol_wire_sync;
7458
- })($ || ($ = {}));
7459
-
7460
- ;
7461
- "use strict";
7462
- var $;
7463
- (function ($_1) {
7464
- $mol_test({
7465
- 'test types'($) {
7466
- class A {
7467
- static a() {
7468
- return Promise.resolve('');
7469
- }
7470
- static b() {
7471
- return $mol_wire_sync(this).a();
7472
- }
7473
- }
7474
- },
7475
- });
7476
- })($ || ($ = {}));
7477
-
7478
7704
  ;
7479
7705
  "use strict";
7480
7706
  var $;
@@ -7498,54 +7724,51 @@ var $;
7498
7724
  var $;
7499
7725
  (function ($_1) {
7500
7726
  $mol_test({
7501
- 'test types'($) {
7502
- class A {
7503
- static a() {
7504
- return '';
7505
- }
7506
- static b() {
7507
- return $mol_wire_async(this).a();
7508
- }
7727
+ async 'exec timeout auto kill child process'($) {
7728
+ let close_mock = () => { };
7729
+ const context_mock = $.$mol_ambient({
7730
+ $mol_run_spawn: () => ({
7731
+ on(name, cb) {
7732
+ if (name === 'exit')
7733
+ close_mock = cb;
7734
+ },
7735
+ kill() { close_mock(); }
7736
+ })
7737
+ });
7738
+ let message = '';
7739
+ try {
7740
+ const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
7509
7741
  }
7510
- },
7511
- async 'Latest method calls wins'($) {
7512
- class NameLogger extends $mol_object2 {
7513
- static $ = $;
7514
- static first = [];
7515
- static last = [];
7516
- static send(next) {
7517
- $mol_wire_sync(this.first).push(next);
7518
- this.$.$mol_wait_timeout(0);
7519
- this.last.push(next);
7520
- }
7742
+ catch (e) {
7743
+ message = e.message;
7521
7744
  }
7522
- const name = $mol_wire_async(NameLogger).send;
7523
- name('john');
7524
- const promise = name('jin');
7525
- $.$mol_after_mock_warp();
7526
- await promise;
7527
- $mol_assert_like(NameLogger.first, ['john', 'jin']);
7528
- $mol_assert_like(NameLogger.last, ['jin']);
7529
- },
7530
- async 'Latest function calls wins'($) {
7531
- const first = [];
7532
- const last = [];
7533
- function send_name(next) {
7534
- $mol_wire_sync(first).push(next);
7535
- $.$mol_wait_timeout(0);
7536
- last.push(next);
7745
+ $mol_assert_equal(message, 'Run error, timeout');
7746
+ }
7747
+ });
7748
+ })($ || ($ = {}));
7749
+
7750
+ ;
7751
+ "use strict";
7752
+ var $;
7753
+ (function ($) {
7754
+ $mol_test({
7755
+ 'init with overload'() {
7756
+ class X extends $mol_object {
7757
+ foo() {
7758
+ return 1;
7759
+ }
7537
7760
  }
7538
- const name = $mol_wire_async(send_name);
7539
- name('john');
7540
- const promise = name('jin');
7541
- $.$mol_after_mock_warp();
7542
- await promise;
7543
- $mol_assert_like(first, ['john', 'jin']);
7544
- $mol_assert_like(last, ['jin']);
7761
+ var x = X.make({
7762
+ foo: () => 2,
7763
+ });
7764
+ $mol_assert_equal(x.foo(), 2);
7545
7765
  },
7546
7766
  });
7547
7767
  })($ || ($ = {}));
7548
7768
 
7769
+ ;
7770
+ "use strict";
7771
+
7549
7772
  ;
7550
7773
  "use strict";
7551
7774
  var $;