mol_dump_lib 0.0.494 → 0.0.496

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.mjs CHANGED
@@ -2003,7 +2003,11 @@ var $node = new Proxy({ require }, {
2003
2003
  try {
2004
2004
  $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
2005
2005
  }
2006
- catch { }
2006
+ catch (e) {
2007
+ if ($$.$mol_fail_catch(e)) {
2008
+ $$.$mol_fail_log(e);
2009
+ }
2010
+ }
2007
2011
  break;
2008
2012
  }
2009
2013
  else {
@@ -2014,7 +2018,7 @@ var $node = new Proxy({ require }, {
2014
2018
  return target.require(name);
2015
2019
  }
2016
2020
  catch (error) {
2017
- if (error.code === 'ERR_REQUIRE_ESM') {
2021
+ if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
2018
2022
  const module = cache.get(name);
2019
2023
  if (module)
2020
2024
  return module;
@@ -2087,10 +2091,19 @@ var $;
2087
2091
  "use strict";
2088
2092
  var $;
2089
2093
  (function ($) {
2094
+ const factories = new WeakMap();
2095
+ function factory(val) {
2096
+ let make = factories.get(val);
2097
+ if (make)
2098
+ return make;
2099
+ make = $mol_func_name_from((...args) => new val(...args), val);
2100
+ factories.set(val, make);
2101
+ return make;
2102
+ }
2090
2103
  function $mol_wire_sync(obj) {
2091
2104
  return new Proxy(obj, {
2092
2105
  get(obj, field) {
2093
- const val = obj[field];
2106
+ let val = obj[field];
2094
2107
  if (typeof val !== 'function')
2095
2108
  return val;
2096
2109
  const temp = $mol_wire_task.getter(val);
@@ -2099,10 +2112,13 @@ var $;
2099
2112
  return fiber.sync();
2100
2113
  };
2101
2114
  },
2115
+ construct(obj, args) {
2116
+ const temp = $mol_wire_task.getter(factory(obj));
2117
+ return temp(obj, args).sync();
2118
+ },
2102
2119
  apply(obj, self, args) {
2103
2120
  const temp = $mol_wire_task.getter(obj);
2104
- const fiber = temp(self, args);
2105
- return fiber.sync();
2121
+ return temp(self, args).sync();
2106
2122
  },
2107
2123
  });
2108
2124
  }
@@ -2118,9 +2134,19 @@ var $;
2118
2134
  $.$mol_run_error = $mol_run_error;
2119
2135
  const child_process = $node['child_process'];
2120
2136
  $.$mol_run_spawn = child_process.spawn.bind(child_process);
2137
+ $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2121
2138
  function $mol_run_async({ dir, timeout, command, env }) {
2122
2139
  const args_raw = typeof command === 'string' ? command.split(' ') : command;
2123
2140
  const [app, ...args] = args_raw;
2141
+ if (!env?.MOL_RUN_ASYNC) {
2142
+ this.$mol_log3_come({
2143
+ place: '$mol_run_sync',
2144
+ message: 'Run',
2145
+ command: args_raw.join(' '),
2146
+ dir: $node.path.relative('', dir),
2147
+ });
2148
+ return this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2149
+ }
2124
2150
  const sub = this.$mol_run_spawn(app, args, {
2125
2151
  shell: true,
2126
2152
  cwd: dir,
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;
@@ -2078,10 +2082,19 @@ var $;
2078
2082
  "use strict";
2079
2083
  var $;
2080
2084
  (function ($) {
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
+ }
2081
2094
  function $mol_wire_sync(obj) {
2082
2095
  return new Proxy(obj, {
2083
2096
  get(obj, field) {
2084
- const val = obj[field];
2097
+ let val = obj[field];
2085
2098
  if (typeof val !== 'function')
2086
2099
  return val;
2087
2100
  const temp = $mol_wire_task.getter(val);
@@ -2090,10 +2103,13 @@ var $;
2090
2103
  return fiber.sync();
2091
2104
  };
2092
2105
  },
2106
+ construct(obj, args) {
2107
+ const temp = $mol_wire_task.getter(factory(obj));
2108
+ return temp(obj, args).sync();
2109
+ },
2093
2110
  apply(obj, self, args) {
2094
2111
  const temp = $mol_wire_task.getter(obj);
2095
- const fiber = temp(self, args);
2096
- return fiber.sync();
2112
+ return temp(self, args).sync();
2097
2113
  },
2098
2114
  });
2099
2115
  }
@@ -2109,9 +2125,19 @@ var $;
2109
2125
  $.$mol_run_error = $mol_run_error;
2110
2126
  const child_process = $node['child_process'];
2111
2127
  $.$mol_run_spawn = child_process.spawn.bind(child_process);
2128
+ $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2112
2129
  function $mol_run_async({ dir, timeout, command, env }) {
2113
2130
  const args_raw = typeof command === 'string' ? command.split(' ') : command;
2114
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
+ }
2115
2141
  const sub = this.$mol_run_spawn(app, args, {
2116
2142
  shell: true,
2117
2143
  cwd: dir,
@@ -7465,85 +7491,6 @@ var $;
7465
7491
  });
7466
7492
  })($ || ($ = {}));
7467
7493
 
7468
- ;
7469
- "use strict";
7470
- var $;
7471
- (function ($) {
7472
- $mol_test({
7473
- 'auto name'() {
7474
- class Invalid extends $mol_error_mix {
7475
- }
7476
- const mix = new Invalid('foo');
7477
- $mol_assert_equal(mix.name, 'Invalid_Error');
7478
- },
7479
- 'simpe mix'() {
7480
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
7481
- $mol_assert_equal(mix.message, 'foo');
7482
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
7483
- },
7484
- 'provide additional info'() {
7485
- class Invalid extends $mol_error_mix {
7486
- }
7487
- 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' }));
7488
- const hints = [];
7489
- if (mix instanceof $mol_error_mix) {
7490
- for (const er of mix.errors) {
7491
- if (er instanceof Invalid) {
7492
- hints.push(er.cause?.hint ?? '');
7493
- }
7494
- }
7495
- }
7496
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
7497
- },
7498
- });
7499
- })($ || ($ = {}));
7500
-
7501
- ;
7502
- "use strict";
7503
- var $;
7504
- (function ($_1) {
7505
- $mol_test({
7506
- 'test types'($) {
7507
- class A {
7508
- static a() {
7509
- return Promise.resolve('');
7510
- }
7511
- static b() {
7512
- return $mol_wire_sync(this).a();
7513
- }
7514
- }
7515
- },
7516
- });
7517
- })($ || ($ = {}));
7518
-
7519
- ;
7520
- "use strict";
7521
- var $;
7522
- (function ($_1) {
7523
- $mol_test({
7524
- async 'exec timeout auto kill child process'($) {
7525
- let close_mock = () => { };
7526
- const context_mock = $.$mol_ambient({
7527
- $mol_run_spawn: () => ({
7528
- on(name, cb) {
7529
- if (name === 'exit')
7530
- close_mock = cb;
7531
- },
7532
- kill() { close_mock(); }
7533
- })
7534
- });
7535
- let message = '';
7536
- try {
7537
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10 });
7538
- }
7539
- catch (e) {
7540
- message = e.message;
7541
- }
7542
- $mol_assert_equal(message, 'Run error, timeout');
7543
- }
7544
- });
7545
- })($ || ($ = {}));
7546
-
7547
7494
  ;
7548
7495
  "use strict";
7549
7496
  var $;
@@ -7791,6 +7738,39 @@ var $;
7791
7738
  });
7792
7739
  })($ || ($ = {}));
7793
7740
 
7741
+ ;
7742
+ "use strict";
7743
+ var $;
7744
+ (function ($) {
7745
+ $mol_test({
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
+ }
7767
+ }
7768
+ }
7769
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
7770
+ },
7771
+ });
7772
+ })($ || ($ = {}));
7773
+
7794
7774
  ;
7795
7775
  "use strict";
7796
7776
  var $;
@@ -7978,6 +7958,112 @@ var $;
7978
7958
  });
7979
7959
  })($ || ($ = {}));
7980
7960
 
7961
+ ;
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
+ })($ || ($ = {}));
8066
+
7981
8067
  ;
7982
8068
  "use strict";
7983
8069
  var $;
@@ -8029,51 +8115,26 @@ var $;
8029
8115
  var $;
8030
8116
  (function ($_1) {
8031
8117
  $mol_test({
8032
- 'test types'($) {
8033
- class A {
8034
- static a() {
8035
- return '';
8036
- }
8037
- static b() {
8038
- return $mol_wire_async(this).a();
8039
- }
8040
- }
8041
- },
8042
- async 'Latest method calls wins'($) {
8043
- class NameLogger extends $mol_object2 {
8044
- static $ = $;
8045
- static first = [];
8046
- static last = [];
8047
- static send(next) {
8048
- $mol_wire_sync(this.first).push(next);
8049
- this.$.$mol_wait_timeout(0);
8050
- this.last.push(next);
8051
- }
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' } });
8052
8132
  }
8053
- const name = $mol_wire_async(NameLogger).send;
8054
- name('john');
8055
- const promise = name('jin');
8056
- $.$mol_after_mock_warp();
8057
- await promise;
8058
- $mol_assert_like(NameLogger.first, ['john', 'jin']);
8059
- $mol_assert_like(NameLogger.last, ['jin']);
8060
- },
8061
- async 'Latest function calls wins'($) {
8062
- const first = [];
8063
- const last = [];
8064
- function send_name(next) {
8065
- $mol_wire_sync(first).push(next);
8066
- $.$mol_wait_timeout(0);
8067
- last.push(next);
8133
+ catch (e) {
8134
+ message = e.message;
8068
8135
  }
8069
- const name = $mol_wire_async(send_name);
8070
- name('john');
8071
- const promise = name('jin');
8072
- $.$mol_after_mock_warp();
8073
- await promise;
8074
- $mol_assert_like(first, ['john', 'jin']);
8075
- $mol_assert_like(last, ['jin']);
8076
- },
8136
+ $mol_assert_equal(message, 'Run error, timeout');
8137
+ }
8077
8138
  });
8078
8139
  })($ || ($ = {}));
8079
8140