mol_dump_lib 0.0.493 → 0.0.495

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
  })($ || ($ = {}));
@@ -5009,32 +5162,6 @@ var $;
5009
5162
  $.$mol_html_encode = $mol_html_encode;
5010
5163
  })($ || ($ = {}));
5011
5164
 
5012
- ;
5013
- "use strict";
5014
- var $;
5015
- (function ($) {
5016
- function $mol_wire_sync(obj) {
5017
- return new Proxy(obj, {
5018
- get(obj, field) {
5019
- const val = obj[field];
5020
- if (typeof val !== 'function')
5021
- return val;
5022
- const temp = $mol_wire_task.getter(val);
5023
- return function $mol_wire_sync(...args) {
5024
- const fiber = temp(obj, args);
5025
- return fiber.sync();
5026
- };
5027
- },
5028
- apply(obj, self, args) {
5029
- const temp = $mol_wire_task.getter(obj);
5030
- const fiber = temp(self, args);
5031
- return fiber.sync();
5032
- },
5033
- });
5034
- }
5035
- $.$mol_wire_sync = $mol_wire_sync;
5036
- })($ || ($ = {}));
5037
-
5038
5165
  ;
5039
5166
  "use strict";
5040
5167
 
@@ -6574,20 +6701,6 @@ var $;
6574
6701
  $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
6575
6702
  })($ || ($ = {}));
6576
6703
 
6577
- ;
6578
- "use strict";
6579
- var $;
6580
- (function ($_1) {
6581
- $mol_test_mocks.push($ => {
6582
- $.$mol_log3_come = () => { };
6583
- $.$mol_log3_done = () => { };
6584
- $.$mol_log3_fail = () => { };
6585
- $.$mol_log3_warn = () => { };
6586
- $.$mol_log3_rise = () => { };
6587
- $.$mol_log3_area = () => () => { };
6588
- });
6589
- })($ || ($ = {}));
6590
-
6591
6704
  ;
6592
6705
  "use strict";
6593
6706
 
@@ -7350,6 +7463,20 @@ var $;
7350
7463
  });
7351
7464
  })($ || ($ = {}));
7352
7465
 
7466
+ ;
7467
+ "use strict";
7468
+ var $;
7469
+ (function ($_1) {
7470
+ $mol_test_mocks.push($ => {
7471
+ $.$mol_log3_come = () => { };
7472
+ $.$mol_log3_done = () => { };
7473
+ $.$mol_log3_fail = () => { };
7474
+ $.$mol_log3_warn = () => { };
7475
+ $.$mol_log3_rise = () => { };
7476
+ $.$mol_log3_area = () => () => { };
7477
+ });
7478
+ })($ || ($ = {}));
7479
+
7353
7480
  ;
7354
7481
  "use strict";
7355
7482
  var $;
@@ -7616,16 +7743,30 @@ var $;
7616
7743
  var $;
7617
7744
  (function ($) {
7618
7745
  $mol_test({
7619
- 'init with overload'() {
7620
- class X extends $mol_object {
7621
- foo() {
7622
- return 1;
7746
+ 'auto name'() {
7747
+ class Invalid extends $mol_error_mix {
7748
+ }
7749
+ const mix = new Invalid('foo');
7750
+ $mol_assert_equal(mix.name, 'Invalid_Error');
7751
+ },
7752
+ 'simpe mix'() {
7753
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
7754
+ $mol_assert_equal(mix.message, 'foo');
7755
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
7756
+ },
7757
+ 'provide additional info'() {
7758
+ class Invalid extends $mol_error_mix {
7759
+ }
7760
+ 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' }));
7761
+ const hints = [];
7762
+ if (mix instanceof $mol_error_mix) {
7763
+ for (const er of mix.errors) {
7764
+ if (er instanceof Invalid) {
7765
+ hints.push(er.cause?.hint ?? '');
7766
+ }
7623
7767
  }
7624
7768
  }
7625
- var x = X.make({
7626
- foo: () => 2,
7627
- });
7628
- $mol_assert_equal(x.foo(), 2);
7769
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
7629
7770
  },
7630
7771
  });
7631
7772
  })($ || ($ = {}));
@@ -7819,6 +7960,109 @@ var $;
7819
7960
 
7820
7961
  ;
7821
7962
  "use strict";
7963
+ var $;
7964
+ (function ($_1) {
7965
+ $mol_test({
7966
+ 'test types'($) {
7967
+ class A {
7968
+ static a() {
7969
+ return '';
7970
+ }
7971
+ static b() {
7972
+ return $mol_wire_async(this).a();
7973
+ }
7974
+ }
7975
+ },
7976
+ async 'Latest method calls wins'($) {
7977
+ class NameLogger extends $mol_object2 {
7978
+ static $ = $;
7979
+ static first = [];
7980
+ static last = [];
7981
+ static send(next) {
7982
+ $mol_wire_sync(this.first).push(next);
7983
+ this.$.$mol_wait_timeout(0);
7984
+ this.last.push(next);
7985
+ }
7986
+ }
7987
+ const name = $mol_wire_async(NameLogger).send;
7988
+ name('john');
7989
+ const promise = name('jin');
7990
+ $.$mol_after_mock_warp();
7991
+ await promise;
7992
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
7993
+ $mol_assert_like(NameLogger.last, ['jin']);
7994
+ },
7995
+ async 'Latest function calls wins'($) {
7996
+ const first = [];
7997
+ const last = [];
7998
+ function send_name(next) {
7999
+ $mol_wire_sync(first).push(next);
8000
+ $.$mol_wait_timeout(0);
8001
+ last.push(next);
8002
+ }
8003
+ const name = $mol_wire_async(send_name);
8004
+ name('john');
8005
+ const promise = name('jin');
8006
+ $.$mol_after_mock_warp();
8007
+ await promise;
8008
+ $mol_assert_like(first, ['john', 'jin']);
8009
+ $mol_assert_like(last, ['jin']);
8010
+ },
8011
+ });
8012
+ })($ || ($ = {}));
8013
+
8014
+ ;
8015
+ "use strict";
8016
+ var $;
8017
+ (function ($_1) {
8018
+ $mol_test({
8019
+ 'test types'($) {
8020
+ class A {
8021
+ static a() {
8022
+ return Promise.resolve('');
8023
+ }
8024
+ static b() {
8025
+ return $mol_wire_sync(this).a();
8026
+ }
8027
+ }
8028
+ },
8029
+ async 'test method from host'($) {
8030
+ let count = 0;
8031
+ class A {
8032
+ static a() {
8033
+ return $mol_wire_sync(this).b();
8034
+ }
8035
+ static b() { return Promise.resolve(++count); }
8036
+ }
8037
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
8038
+ },
8039
+ async 'test function'($) {
8040
+ let count = 0;
8041
+ class A {
8042
+ static a() {
8043
+ return $mol_wire_sync(this.b)();
8044
+ }
8045
+ static b() { return Promise.resolve(++count); }
8046
+ }
8047
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
8048
+ },
8049
+ async 'test construct itself'($) {
8050
+ class A {
8051
+ static instances = [];
8052
+ static a() {
8053
+ const a = new ($mol_wire_sync(A))();
8054
+ this.instances.push(a);
8055
+ $mol_wire_sync(this).b();
8056
+ }
8057
+ static b() { return Promise.resolve(); }
8058
+ }
8059
+ await $mol_wire_async(A).a();
8060
+ $mol_assert_equal(A.instances.length, 2);
8061
+ $mol_assert_equal(A.instances[0] instanceof A);
8062
+ $mol_assert_equal(A.instances[0], A.instances[1]);
8063
+ }
8064
+ });
8065
+ })($ || ($ = {}));
7822
8066
 
7823
8067
  ;
7824
8068
  "use strict";
@@ -7848,24 +8092,6 @@ var $;
7848
8092
  });
7849
8093
  })($ || ($ = {}));
7850
8094
 
7851
- ;
7852
- "use strict";
7853
- var $;
7854
- (function ($_1) {
7855
- $mol_test({
7856
- 'test types'($) {
7857
- class A {
7858
- static a() {
7859
- return Promise.resolve('');
7860
- }
7861
- static b() {
7862
- return $mol_wire_sync(this).a();
7863
- }
7864
- }
7865
- },
7866
- });
7867
- })($ || ($ = {}));
7868
-
7869
8095
  ;
7870
8096
  "use strict";
7871
8097
  var $;
@@ -7889,54 +8115,51 @@ var $;
7889
8115
  var $;
7890
8116
  (function ($_1) {
7891
8117
  $mol_test({
7892
- 'test types'($) {
7893
- class A {
7894
- static a() {
7895
- return '';
7896
- }
7897
- static b() {
7898
- return $mol_wire_async(this).a();
7899
- }
8118
+ async 'exec timeout auto kill child process'($) {
8119
+ let close_mock = () => { };
8120
+ const context_mock = $.$mol_ambient({
8121
+ $mol_run_spawn: () => ({
8122
+ on(name, cb) {
8123
+ if (name === 'exit')
8124
+ close_mock = cb;
8125
+ },
8126
+ kill() { close_mock(); }
8127
+ })
8128
+ });
8129
+ let message = '';
8130
+ try {
8131
+ const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
7900
8132
  }
7901
- },
7902
- async 'Latest method calls wins'($) {
7903
- class NameLogger extends $mol_object2 {
7904
- static $ = $;
7905
- static first = [];
7906
- static last = [];
7907
- static send(next) {
7908
- $mol_wire_sync(this.first).push(next);
7909
- this.$.$mol_wait_timeout(0);
7910
- this.last.push(next);
7911
- }
8133
+ catch (e) {
8134
+ message = e.message;
7912
8135
  }
7913
- const name = $mol_wire_async(NameLogger).send;
7914
- name('john');
7915
- const promise = name('jin');
7916
- $.$mol_after_mock_warp();
7917
- await promise;
7918
- $mol_assert_like(NameLogger.first, ['john', 'jin']);
7919
- $mol_assert_like(NameLogger.last, ['jin']);
7920
- },
7921
- async 'Latest function calls wins'($) {
7922
- const first = [];
7923
- const last = [];
7924
- function send_name(next) {
7925
- $mol_wire_sync(first).push(next);
7926
- $.$mol_wait_timeout(0);
7927
- last.push(next);
8136
+ $mol_assert_equal(message, 'Run error, timeout');
8137
+ }
8138
+ });
8139
+ })($ || ($ = {}));
8140
+
8141
+ ;
8142
+ "use strict";
8143
+ var $;
8144
+ (function ($) {
8145
+ $mol_test({
8146
+ 'init with overload'() {
8147
+ class X extends $mol_object {
8148
+ foo() {
8149
+ return 1;
8150
+ }
7928
8151
  }
7929
- const name = $mol_wire_async(send_name);
7930
- name('john');
7931
- const promise = name('jin');
7932
- $.$mol_after_mock_warp();
7933
- await promise;
7934
- $mol_assert_like(first, ['john', 'jin']);
7935
- $mol_assert_like(last, ['jin']);
8152
+ var x = X.make({
8153
+ foo: () => 2,
8154
+ });
8155
+ $mol_assert_equal(x.foo(), 2);
7936
8156
  },
7937
8157
  });
7938
8158
  })($ || ($ = {}));
7939
8159
 
8160
+ ;
8161
+ "use strict";
8162
+
7940
8163
  ;
7941
8164
  "use strict";
7942
8165
  var $;