mol_dump_lib 0.0.539 → 0.0.541

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
@@ -2140,97 +2140,115 @@ var $;
2140
2140
  class $mol_run_error extends $mol_error_mix {
2141
2141
  }
2142
2142
  $.$mol_run_error = $mol_run_error;
2143
- const child_process = $node['child_process'];
2144
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
2145
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2146
- function $mol_run_async({ dir, timeout, command, env }) {
2147
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
2148
- const [app, ...args] = args_raw;
2149
- if (!env?.MOL_RUN_ASYNC) {
2150
- this.$mol_log3_come({
2151
- place: '$mol_run_sync',
2143
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
2144
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
2145
+ class $mol_run extends $mol_object {
2146
+ static async_enabled() {
2147
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
2148
+ }
2149
+ static spawn(options) {
2150
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
2151
+ const env = options.env ?? this.$.$mol_env();
2152
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
2153
+ }
2154
+ static spawn_async({ dir, sync, timeout, command, env }) {
2155
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2156
+ const [app, ...args] = args_raw;
2157
+ const opts = { shell: true, cwd: dir, env };
2158
+ const log_object = {
2159
+ place: `${this}.spawn()`,
2152
2160
  message: 'Run',
2153
2161
  command: args_raw.join(' '),
2154
2162
  dir: $node.path.relative('', dir),
2163
+ };
2164
+ if (sync) {
2165
+ this.$.$mol_log3_come({
2166
+ hint: 'Run inside fiber',
2167
+ ...log_object
2168
+ });
2169
+ let error;
2170
+ let res;
2171
+ try {
2172
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
2173
+ error = res.error;
2174
+ }
2175
+ catch (err) {
2176
+ error = err;
2177
+ }
2178
+ if (!res || error || res.status) {
2179
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
2180
+ }
2181
+ return res;
2182
+ }
2183
+ let sub;
2184
+ try {
2185
+ sub = this.$.$mol_run_spawn(app, args, {
2186
+ ...opts,
2187
+ stdio: ['pipe', 'inherit', 'inherit'],
2188
+ });
2189
+ }
2190
+ catch (error) {
2191
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
2192
+ }
2193
+ const pid = sub.pid ?? 0;
2194
+ this.$.$mol_log3_come({
2195
+ ...log_object,
2196
+ pid,
2155
2197
  });
2156
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2157
- if (res.status)
2158
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
2159
- return res;
2160
- }
2161
- const sub = this.$mol_run_spawn(app, args, {
2162
- shell: true,
2163
- cwd: dir,
2164
- env
2165
- });
2166
- this.$mol_log3_come({
2167
- place: '$mol_run_async',
2168
- pid: sub.pid,
2169
- message: 'Run',
2170
- command: args_raw.join(' '),
2171
- dir: $node.path.relative('', dir),
2172
- });
2173
- let killed = false;
2174
- let timer;
2175
- const std_data = [];
2176
- const error_data = [];
2177
- const add = (std_chunk, error_chunk) => {
2178
- if (std_chunk)
2179
- std_data.push(std_chunk);
2180
- if (error_chunk)
2181
- error_data.push(error_chunk);
2182
- if (!timeout)
2183
- return;
2184
- clearTimeout(timer);
2185
- timer = setTimeout(() => {
2186
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
2187
- killed = true;
2188
- add();
2189
- sub.kill(signal);
2190
- }, timeout);
2191
- };
2192
- add();
2193
- sub.stdout?.on('data', data => add(data));
2194
- sub.stderr?.on('data', data => add(undefined, data));
2195
- const promise = new Promise((done, fail) => {
2196
- const close = (error, status = null, signal = null) => {
2197
- if (!timer && timeout)
2198
+ let timeout_kill = false;
2199
+ let timer;
2200
+ const std_data = [];
2201
+ const error_data = [];
2202
+ const add = (std_chunk, error_chunk) => {
2203
+ if (std_chunk)
2204
+ std_data.push(std_chunk);
2205
+ if (error_chunk)
2206
+ error_data.push(error_chunk);
2207
+ if (!timeout)
2198
2208
  return;
2199
2209
  clearTimeout(timer);
2200
- timer = undefined;
2201
- const res = {
2202
- pid: sub.pid,
2203
- status,
2204
- signal,
2205
- get stdout() { return Buffer.concat(std_data); },
2206
- get stderr() { return Buffer.concat(error_data); }
2207
- };
2208
- this.$mol_log3_done({
2209
- place: '$mol_run_async',
2210
- pid: sub.pid,
2211
- message: 'Run',
2212
- status,
2213
- command: args_raw.join(' '),
2214
- dir: $node.path.relative('', dir),
2215
- });
2216
- if (error || status || killed)
2217
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
2218
- done(res);
2210
+ timer = setTimeout(() => {
2211
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
2212
+ timeout_kill = true;
2213
+ add();
2214
+ sub.kill(signal);
2215
+ }, timeout);
2219
2216
  };
2220
- sub.on('disconnect', () => close(new Error('Disconnected')));
2221
- sub.on('error', err => close(err));
2222
- sub.on('exit', (status, signal) => close(null, status, signal));
2223
- });
2224
- return Object.assign(promise, { destructor: () => {
2225
- clearTimeout(timer);
2226
- sub.kill('SIGKILL');
2227
- } });
2228
- }
2229
- $.$mol_run_async = $mol_run_async;
2230
- function $mol_run(options) {
2231
- if (!options.env)
2232
- options = { ...options, env: this.$mol_env() };
2233
- return $mol_wire_sync(this).$mol_run_async(options);
2217
+ add();
2218
+ sub.stdout?.on('data', data => add(data));
2219
+ sub.stderr?.on('data', data => add(undefined, data));
2220
+ const result_promise = new Promise((done, fail) => {
2221
+ const close = (error, status = null, signal = null) => {
2222
+ if (!timer && timeout)
2223
+ return;
2224
+ clearTimeout(timer);
2225
+ timer = undefined;
2226
+ const res = {
2227
+ pid,
2228
+ signal,
2229
+ get stdout() { return Buffer.concat(std_data); },
2230
+ get stderr() { return Buffer.concat(error_data); }
2231
+ };
2232
+ if (error || status || timeout_kill)
2233
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
2234
+ this.$.$mol_log3_done({
2235
+ ...log_object,
2236
+ pid,
2237
+ });
2238
+ done(res);
2239
+ };
2240
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2241
+ sub.on('error', err => close(err));
2242
+ sub.on('exit', (status, signal) => close(null, status, signal));
2243
+ });
2244
+ return Object.assign(result_promise, { destructor: () => {
2245
+ clearTimeout(timer);
2246
+ sub.kill('SIGKILL');
2247
+ } });
2248
+ }
2249
+ static error_message(res) {
2250
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
2251
+ }
2234
2252
  }
2235
2253
  $.$mol_run = $mol_run;
2236
2254
  })($ || ($ = {}));
@@ -2240,7 +2258,7 @@ var $;
2240
2258
  var $;
2241
2259
  (function ($) {
2242
2260
  function $mol_exec(dir, command, ...args) {
2243
- return this.$mol_run({ command: [command, ...args], dir });
2261
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
2244
2262
  }
2245
2263
  $.$mol_exec = $mol_exec;
2246
2264
  })($ || ($ = {}));
@@ -5331,6 +5349,65 @@ var $;
5331
5349
  $.$mol_state_local = $mol_state_local;
5332
5350
  })($ || ($ = {}));
5333
5351
 
5352
+ ;
5353
+ "use strict";
5354
+ var $;
5355
+ (function ($) {
5356
+ $.$mol_action = $mol_wire_method;
5357
+ })($ || ($ = {}));
5358
+
5359
+ ;
5360
+ "use strict";
5361
+ var $;
5362
+ (function ($) {
5363
+ class $mol_lock extends $mol_object {
5364
+ promise = null;
5365
+ async wait() {
5366
+ let next = () => { };
5367
+ let destructed = false;
5368
+ const task = $mol_wire_auto();
5369
+ if (!task)
5370
+ return next;
5371
+ const destructor = task.destructor.bind(task);
5372
+ task.destructor = () => {
5373
+ destructor();
5374
+ destructed = true;
5375
+ next();
5376
+ };
5377
+ let promise;
5378
+ do {
5379
+ promise = this.promise;
5380
+ await promise;
5381
+ if (destructed)
5382
+ return next;
5383
+ } while (promise !== this.promise);
5384
+ this.promise = new Promise(done => { next = done; });
5385
+ return next;
5386
+ }
5387
+ grab() { return $mol_wire_sync(this).wait(); }
5388
+ }
5389
+ $.$mol_lock = $mol_lock;
5390
+ })($ || ($ = {}));
5391
+
5392
+ ;
5393
+ "use strict";
5394
+ var $;
5395
+ (function ($) {
5396
+ function $mol_compare_array(a, b) {
5397
+ if (a === b)
5398
+ return true;
5399
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
5400
+ return false;
5401
+ if (a.length !== b.length)
5402
+ return false;
5403
+ for (let i = 0; i < a.length; i++)
5404
+ if (a[i] !== b[i])
5405
+ return false;
5406
+ return true;
5407
+ }
5408
+ $.$mol_compare_array = $mol_compare_array;
5409
+ })($ || ($ = {}));
5410
+
5334
5411
  ;
5335
5412
  "use strict";
5336
5413
 
@@ -5364,12 +5441,82 @@ var $;
5364
5441
  "use strict";
5365
5442
  var $;
5366
5443
  (function ($) {
5367
- class $mol_file_not_found extends Error {
5444
+ class $mol_file_transaction extends $mol_object {
5445
+ path() { return ''; }
5446
+ modes() { return []; }
5447
+ write(options) {
5448
+ return 0;
5449
+ }
5450
+ read() {
5451
+ return new Uint8Array();
5452
+ }
5453
+ truncate(size) { }
5454
+ close() { }
5455
+ destructor() {
5456
+ this.close();
5457
+ }
5458
+ }
5459
+ $.$mol_file_transaction = $mol_file_transaction;
5460
+ })($ || ($ = {}));
5461
+
5462
+ ;
5463
+ "use strict";
5464
+ var $;
5465
+ (function ($) {
5466
+ let file_modes;
5467
+ (function (file_modes) {
5468
+ file_modes[file_modes["create"] = $node.fs.constants.O_CREAT] = "create";
5469
+ file_modes[file_modes["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
5470
+ file_modes[file_modes["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
5471
+ file_modes[file_modes["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
5472
+ file_modes[file_modes["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
5473
+ file_modes[file_modes["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
5474
+ file_modes[file_modes["append"] = $node.fs.constants.O_APPEND] = "append";
5475
+ })(file_modes || (file_modes = {}));
5476
+ function mode_mask(modes) {
5477
+ return modes.reduce((res, mode) => res | file_modes[mode], 0);
5478
+ }
5479
+ class $mol_file_transaction_node extends $mol_file_transaction {
5480
+ descr() {
5481
+ $mol_wire_solid();
5482
+ return $node.fs.openSync(this.path(), mode_mask(this.modes()));
5483
+ }
5484
+ write({ buffer, offset = 0, length, position = null }) {
5485
+ if (Array.isArray(buffer)) {
5486
+ return $node.fs.writevSync(this.descr(), buffer, position ?? undefined);
5487
+ }
5488
+ if (typeof buffer === 'string') {
5489
+ return $node.fs.writeSync(this.descr(), buffer, position);
5490
+ }
5491
+ length = length ?? buffer.byteLength;
5492
+ return $node.fs.writeSync(this.descr(), buffer, offset, length, position);
5493
+ }
5494
+ truncate(size) {
5495
+ $node.fs.ftruncateSync(this.descr());
5496
+ }
5497
+ read() {
5498
+ return $mol_file_node_buffer_normalize($node.fs.readFileSync(this.descr()));
5499
+ }
5500
+ close() {
5501
+ $node.fs.closeSync(this.descr());
5502
+ }
5368
5503
  }
5369
- $.$mol_file_not_found = $mol_file_not_found;
5370
- class $mol_file extends $mol_object {
5504
+ __decorate([
5505
+ $mol_mem
5506
+ ], $mol_file_transaction_node.prototype, "descr", null);
5507
+ $.$mol_file_transaction_node = $mol_file_transaction_node;
5508
+ $.$mol_file_transaction = $mol_file_transaction_node;
5509
+ })($ || ($ = {}));
5510
+
5511
+ ;
5512
+ "use strict";
5513
+ var $;
5514
+ (function ($) {
5515
+ class $mol_file_base extends $mol_object {
5371
5516
  static absolute(path) {
5372
- throw new Error('Not implemented yet');
5517
+ return this.make({
5518
+ path: $mol_const(path)
5519
+ });
5373
5520
  }
5374
5521
  static relative(path) {
5375
5522
  throw new Error('Not implemented yet');
@@ -5381,27 +5528,164 @@ var $;
5381
5528
  parent() {
5382
5529
  return this.resolve('..');
5383
5530
  }
5384
- reset() {
5385
- try {
5386
- this.stat(null);
5531
+ exists_cut() { return this.exists(); }
5532
+ root() {
5533
+ const path = this.path();
5534
+ const base = this.constructor.base;
5535
+ return base.startsWith(path) || this == this.parent();
5536
+ }
5537
+ stat(next, virt) {
5538
+ const path = this.path();
5539
+ const parent = this.parent();
5540
+ if (!this.root()) {
5541
+ parent.version();
5387
5542
  }
5388
- catch (error) {
5389
- if (error instanceof $mol_file_not_found)
5543
+ parent.watcher();
5544
+ if (virt)
5545
+ return next ?? null;
5546
+ return next ?? this.info(path);
5547
+ }
5548
+ static changed = new Set;
5549
+ static frame = null;
5550
+ static changed_add(type, path) {
5551
+ if (/([\/\\]\.|___$)/.test(path))
5552
+ return;
5553
+ const file = this.relative(path.at(-1) === '/' ? path.slice(0, -1) : path);
5554
+ this.changed.add(file);
5555
+ if (!this.watching)
5556
+ return;
5557
+ this.frame?.destructor();
5558
+ this.frame = new this.$.$mol_after_timeout(this.watch_debounce(), () => {
5559
+ if (!this.watching)
5390
5560
  return;
5391
- return $mol_fail_hidden(error);
5561
+ this.watching = false;
5562
+ $mol_wire_async(this).flush();
5563
+ });
5564
+ }
5565
+ static watch_debounce() { return 500; }
5566
+ static flush() {
5567
+ for (const file of this.changed) {
5568
+ const parent = file.parent();
5569
+ try {
5570
+ if ($mol_wire_probe(() => parent.sub()))
5571
+ parent.sub(null);
5572
+ file.reset();
5573
+ }
5574
+ catch (error) {
5575
+ if ($mol_fail_catch(error))
5576
+ $mol_fail_log(error);
5577
+ }
5392
5578
  }
5579
+ this.changed.clear();
5580
+ this.watching = true;
5581
+ }
5582
+ static watching = true;
5583
+ static lock = new $mol_lock;
5584
+ static watch_off(path) {
5585
+ this.watching = false;
5586
+ this.flush();
5587
+ this.watching = false;
5588
+ this.changed.add(this.absolute(path));
5589
+ }
5590
+ static unwatched(side_effect, affected_dir) {
5591
+ const unlock = this.lock.grab();
5592
+ this.watch_off(affected_dir);
5593
+ try {
5594
+ const result = side_effect();
5595
+ this.flush();
5596
+ unlock();
5597
+ return result;
5598
+ }
5599
+ catch (e) {
5600
+ if (!$mol_promise_like(e)) {
5601
+ this.flush();
5602
+ unlock();
5603
+ }
5604
+ $mol_fail_hidden(e);
5605
+ }
5606
+ }
5607
+ reset() {
5608
+ this.stat(null);
5393
5609
  }
5610
+ modified() { return this.stat()?.mtime ?? null; }
5394
5611
  version() {
5395
- return this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
5612
+ const next = this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
5613
+ return next;
5614
+ }
5615
+ info(path) { return null; }
5616
+ ensure() { }
5617
+ drop() { }
5618
+ copy(to) { }
5619
+ read() { return new Uint8Array; }
5620
+ write(buffer) { }
5621
+ kids() {
5622
+ return [];
5623
+ }
5624
+ readable(opts) {
5625
+ return new ReadableStream;
5626
+ }
5627
+ writable(opts) {
5628
+ return new WritableStream;
5629
+ }
5630
+ buffer(next) {
5631
+ let readed = new Uint8Array();
5632
+ if (next === undefined) {
5633
+ if (this.version())
5634
+ readed = this.read();
5635
+ }
5636
+ const prev = $mol_mem_cached(() => this.buffer());
5637
+ const changed = prev === undefined || !$mol_compare_array(prev, next ?? readed);
5638
+ if (prev !== undefined && changed) {
5639
+ this.$.$mol_log3_rise({
5640
+ place: `$mol_file_node.buffer()`,
5641
+ message: 'Changed',
5642
+ path: this.relate(),
5643
+ });
5644
+ }
5645
+ if (next === undefined)
5646
+ return changed ? readed : prev;
5647
+ if (!changed && this.exists())
5648
+ return prev;
5649
+ this.parent().exists(true);
5650
+ this.stat(this.stat_make(next.length), 'virt');
5651
+ this.write(next);
5652
+ return next;
5653
+ }
5654
+ stat_make(size) {
5655
+ const now = new Date();
5656
+ return {
5657
+ type: 'file',
5658
+ size,
5659
+ atime: now,
5660
+ mtime: now,
5661
+ ctime: now,
5662
+ };
5663
+ }
5664
+ clone(to) {
5665
+ if (!this.exists())
5666
+ return null;
5667
+ const target = this.constructor.absolute(to);
5668
+ try {
5669
+ this.version();
5670
+ target.parent().exists(true);
5671
+ this.copy(to);
5672
+ target.reset();
5673
+ return target;
5674
+ }
5675
+ catch (error) {
5676
+ if ($mol_fail_catch(error)) {
5677
+ console.error(error);
5678
+ }
5679
+ }
5680
+ return null;
5396
5681
  }
5397
5682
  watcher() {
5398
- console.warn('$mol_file_web.watcher() not implemented');
5399
5683
  return {
5400
5684
  destructor() { }
5401
5685
  };
5402
5686
  }
5403
5687
  exists(next) {
5404
- let exists = Boolean(this.stat());
5688
+ const exists = Boolean(this.stat());
5405
5689
  if (next === undefined)
5406
5690
  return exists;
5407
5691
  if (next === exists)
@@ -5427,26 +5711,40 @@ var $;
5427
5711
  return match ? match[1].substring(1) : '';
5428
5712
  }
5429
5713
  text(next, virt) {
5714
+ if (next !== undefined)
5715
+ this.exists();
5716
+ return this.text_int(next, virt);
5717
+ }
5718
+ text_int(next, virt) {
5430
5719
  if (virt) {
5431
- const now = new Date;
5432
- this.stat({
5433
- type: 'file',
5434
- size: 0,
5435
- atime: now,
5436
- mtime: now,
5437
- ctime: now,
5438
- }, 'virt');
5720
+ this.stat(this.stat_make(0), 'virt');
5439
5721
  return next;
5440
5722
  }
5441
5723
  if (next === undefined) {
5442
- return $mol_charset_decode(this.buffer(undefined));
5724
+ return $mol_charset_decode(this.buffer());
5443
5725
  }
5444
5726
  else {
5445
- const buffer = next === undefined ? undefined : $mol_charset_encode(next);
5727
+ const buffer = $mol_charset_encode(next);
5446
5728
  this.buffer(buffer);
5447
5729
  return next;
5448
5730
  }
5449
5731
  }
5732
+ sub(reset) {
5733
+ if (!this.exists())
5734
+ return [];
5735
+ if (this.type() !== 'dir')
5736
+ return [];
5737
+ this.version();
5738
+ return this.kids().filter(file => file.exists());
5739
+ }
5740
+ resolve(path) {
5741
+ throw new Error('implement');
5742
+ }
5743
+ relate(base = this.constructor.relative('.')) {
5744
+ const base_path = base.path();
5745
+ const path = this.path();
5746
+ return path.startsWith(base_path) ? path.slice(base_path.length) : path;
5747
+ }
5450
5748
  find(include, exclude) {
5451
5749
  const found = [];
5452
5750
  const sub = this.sub();
@@ -5470,49 +5768,80 @@ var $;
5470
5768
  default: return 0;
5471
5769
  }
5472
5770
  }
5473
- open(...modes) {
5474
- return 0;
5475
- }
5476
5771
  toJSON() {
5477
5772
  return this.path();
5478
5773
  }
5774
+ open(...modes) {
5775
+ return this.$.$mol_file_transaction.make({
5776
+ path: () => this.path(),
5777
+ modes: () => modes
5778
+ });
5779
+ }
5479
5780
  }
5781
+ __decorate([
5782
+ $mol_action
5783
+ ], $mol_file_base.prototype, "exists_cut", null);
5784
+ __decorate([
5785
+ $mol_mem
5786
+ ], $mol_file_base.prototype, "stat", null);
5480
5787
  __decorate([
5481
5788
  $mol_mem
5482
- ], $mol_file.prototype, "exists", null);
5789
+ ], $mol_file_base.prototype, "modified", null);
5483
5790
  __decorate([
5484
5791
  $mol_mem
5485
- ], $mol_file.prototype, "text", null);
5792
+ ], $mol_file_base.prototype, "version", null);
5486
5793
  __decorate([
5487
5794
  $mol_mem_key
5488
- ], $mol_file, "absolute", null);
5489
- $.$mol_file = $mol_file;
5490
- })($ || ($ = {}));
5491
-
5492
- ;
5493
- "use strict";
5494
- var $;
5495
- (function ($) {
5496
- $.$mol_action = $mol_wire_method;
5795
+ ], $mol_file_base.prototype, "readable", null);
5796
+ __decorate([
5797
+ $mol_mem_key
5798
+ ], $mol_file_base.prototype, "writable", null);
5799
+ __decorate([
5800
+ $mol_mem
5801
+ ], $mol_file_base.prototype, "buffer", null);
5802
+ __decorate([
5803
+ $mol_action
5804
+ ], $mol_file_base.prototype, "stat_make", null);
5805
+ __decorate([
5806
+ $mol_mem_key
5807
+ ], $mol_file_base.prototype, "clone", null);
5808
+ __decorate([
5809
+ $mol_mem
5810
+ ], $mol_file_base.prototype, "exists", null);
5811
+ __decorate([
5812
+ $mol_mem
5813
+ ], $mol_file_base.prototype, "type", null);
5814
+ __decorate([
5815
+ $mol_mem
5816
+ ], $mol_file_base.prototype, "text_int", null);
5817
+ __decorate([
5818
+ $mol_mem
5819
+ ], $mol_file_base.prototype, "sub", null);
5820
+ __decorate([
5821
+ $mol_mem
5822
+ ], $mol_file_base.prototype, "size", null);
5823
+ __decorate([
5824
+ $mol_action
5825
+ ], $mol_file_base.prototype, "open", null);
5826
+ __decorate([
5827
+ $mol_mem_key
5828
+ ], $mol_file_base, "absolute", null);
5829
+ __decorate([
5830
+ $mol_action
5831
+ ], $mol_file_base, "flush", null);
5832
+ __decorate([
5833
+ $mol_action
5834
+ ], $mol_file_base, "watch_off", null);
5835
+ $.$mol_file_base = $mol_file_base;
5497
5836
  })($ || ($ = {}));
5498
5837
 
5499
5838
  ;
5500
5839
  "use strict";
5501
5840
  var $;
5502
5841
  (function ($) {
5503
- function $mol_compare_array(a, b) {
5504
- if (a === b)
5505
- return true;
5506
- if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
5507
- return false;
5508
- if (a.length !== b.length)
5509
- return false;
5510
- for (let i = 0; i < a.length; i++)
5511
- if (a[i] !== b[i])
5512
- return false;
5513
- return true;
5842
+ class $mol_file extends $mol_file_base {
5514
5843
  }
5515
- $.$mol_compare_array = $mol_compare_array;
5844
+ $.$mol_file = $mol_file;
5516
5845
  })($ || ($ = {}));
5517
5846
 
5518
5847
  ;
@@ -5539,186 +5868,183 @@ var $;
5539
5868
  ctime: stat.ctime
5540
5869
  };
5541
5870
  }
5542
- function buffer_normalize(buf) {
5871
+ function $mol_file_node_buffer_normalize(buf) {
5543
5872
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
5544
5873
  }
5545
- let $mol_file_mode_open;
5546
- (function ($mol_file_mode_open) {
5547
- $mol_file_mode_open[$mol_file_mode_open["create"] = $node.fs.constants.O_CREAT] = "create";
5548
- $mol_file_mode_open[$mol_file_mode_open["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
5549
- $mol_file_mode_open[$mol_file_mode_open["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
5550
- $mol_file_mode_open[$mol_file_mode_open["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
5551
- $mol_file_mode_open[$mol_file_mode_open["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
5552
- $mol_file_mode_open[$mol_file_mode_open["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
5553
- $mol_file_mode_open[$mol_file_mode_open["append"] = $node.fs.constants.O_APPEND] = "append";
5554
- })($mol_file_mode_open = $.$mol_file_mode_open || ($.$mol_file_mode_open = {}));
5874
+ $.$mol_file_node_buffer_normalize = $mol_file_node_buffer_normalize;
5555
5875
  class $mol_file_node extends $mol_file {
5556
- static absolute(path) {
5557
- return this.make({
5558
- path: $mol_const(path)
5559
- });
5560
- }
5561
5876
  static relative(path) {
5562
5877
  return this.absolute($node.path.resolve(this.base, path).replace(/\\/g, '/'));
5563
5878
  }
5564
- watcher() {
5565
- if (/\/\./.test(this.path()))
5566
- return { destructor() { } };
5567
- const watcher = $node.chokidar.watch(this.path(), {
5568
- persistent: true,
5569
- ignored: path => /([\/\\]\.|___$)/.test(path),
5570
- depth: 0,
5571
- ignoreInitial: true,
5572
- awaitWriteFinish: {
5573
- stabilityThreshold: 100,
5574
- },
5575
- });
5576
- watcher
5577
- .on('all', (type, path) => {
5578
- const file = $mol_file.relative(path.replace(/\\/g, '/'));
5579
- file.reset();
5580
- if (type === 'change') {
5581
- this.stat(null);
5582
- }
5583
- else {
5584
- file.parent().reset();
5879
+ watcher(reset) {
5880
+ const path = this.path();
5881
+ const root = this.root();
5882
+ if (!root && !this.exists())
5883
+ return super.watcher();
5884
+ let watcher;
5885
+ try {
5886
+ watcher = $node.fs.watch(path);
5887
+ }
5888
+ catch (error) {
5889
+ if (!(error instanceof Error))
5890
+ error = new Error('Unknown watch error', { cause: error });
5891
+ error.message += '\n' + path;
5892
+ if (root || error.code !== 'ENOENT') {
5893
+ this.$.$mol_fail_log(error);
5585
5894
  }
5586
- })
5587
- .on('error', $mol_fail_log);
5895
+ return super.watcher();
5896
+ }
5897
+ watcher.on('change', (type, name) => {
5898
+ if (!name)
5899
+ return;
5900
+ const path = $node.path.join(this.path(), name.toString());
5901
+ this.constructor.changed_add(type, path);
5902
+ });
5903
+ watcher.on('error', e => this.$.$mol_fail_log(e));
5904
+ let destructed = false;
5905
+ watcher.on('close', () => {
5906
+ if (!destructed)
5907
+ setTimeout(() => $mol_wire_async(this).watcher(null), 500);
5908
+ });
5588
5909
  return {
5589
5910
  destructor() {
5911
+ destructed = true;
5590
5912
  watcher.close();
5591
5913
  }
5592
5914
  };
5593
5915
  }
5594
- stat(next, virt) {
5595
- let stat = next;
5596
- const path = this.path();
5597
- this.parent().watcher();
5598
- if (virt)
5599
- return next;
5916
+ info(path) {
5600
5917
  try {
5601
- stat = next ?? stat_convert($node.fs.statSync(path, { throwIfNoEntry: false }));
5918
+ return stat_convert($node.fs.statSync(path));
5602
5919
  }
5603
5920
  catch (error) {
5604
- if (error.code === 'ENOENT')
5605
- error = new $mol_file_not_found(`File not found`);
5606
- error.message += '\n' + path;
5607
- return this.$.$mol_fail_hidden(error);
5608
- }
5609
- return stat;
5921
+ if (this.$.$mol_fail_catch(error)) {
5922
+ if (error.code === 'ENOENT')
5923
+ return null;
5924
+ error.message += '\n' + path;
5925
+ this.$.$mol_fail_hidden(error);
5926
+ }
5927
+ }
5928
+ return null;
5610
5929
  }
5611
5930
  ensure() {
5612
5931
  const path = this.path();
5613
5932
  try {
5614
- $node.fs.mkdirSync(path);
5933
+ $node.fs.mkdirSync(path, { recursive: true });
5934
+ return null;
5615
5935
  }
5616
5936
  catch (e) {
5617
- e.message += '\n' + path;
5618
- this.$.$mol_fail_hidden(e);
5937
+ if (this.$.$mol_fail_catch(e)) {
5938
+ if (e.code === 'EEXIST')
5939
+ return null;
5940
+ e.message += '\n' + path;
5941
+ this.$.$mol_fail_hidden(e);
5942
+ }
5619
5943
  }
5620
5944
  }
5945
+ copy(to) {
5946
+ $node.fs.copyFileSync(this.path(), to);
5947
+ }
5621
5948
  drop() {
5622
5949
  $node.fs.unlinkSync(this.path());
5623
5950
  }
5624
- buffer(next) {
5951
+ read() {
5625
5952
  const path = this.path();
5626
- if (next === undefined) {
5627
- if (!this.stat())
5628
- return new Uint8Array;
5629
- try {
5630
- const prev = $mol_mem_cached(() => this.buffer());
5631
- next = buffer_normalize($node.fs.readFileSync(path));
5632
- if (prev !== undefined && !$mol_compare_array(prev, next)) {
5633
- this.$.$mol_log3_rise({
5634
- place: `$mol_file_node..buffer()`,
5635
- message: 'Changed',
5636
- path: this.relate(),
5637
- });
5638
- }
5639
- return next;
5640
- }
5641
- catch (error) {
5953
+ try {
5954
+ return $mol_file_node_buffer_normalize($node.fs.readFileSync(path));
5955
+ }
5956
+ catch (error) {
5957
+ if (!$mol_promise_like(error)) {
5642
5958
  error.message += '\n' + path;
5643
- return this.$.$mol_fail_hidden(error);
5644
5959
  }
5960
+ $mol_fail_hidden(error);
5645
5961
  }
5646
- this.parent().exists(true);
5647
- const now = new Date;
5648
- this.stat({
5649
- type: 'file',
5650
- size: next.length,
5651
- atime: now,
5652
- mtime: now,
5653
- ctime: now,
5654
- }, 'virt');
5962
+ }
5963
+ write(buffer) {
5964
+ const path = this.path();
5655
5965
  try {
5656
- $node.fs.writeFileSync(path, next);
5966
+ $node.fs.writeFileSync(path, buffer);
5657
5967
  }
5658
5968
  catch (error) {
5659
- error.message += '\n' + path;
5969
+ if (this.$.$mol_fail_catch(error)) {
5970
+ error.message += '\n' + path;
5971
+ }
5660
5972
  return this.$.$mol_fail_hidden(error);
5661
5973
  }
5662
- return next;
5663
5974
  }
5664
- sub() {
5665
- if (!this.exists())
5666
- return [];
5667
- if (this.type() !== 'dir')
5668
- return [];
5975
+ kids() {
5669
5976
  const path = this.path();
5670
- this.stat();
5671
5977
  try {
5672
- return $node.fs.readdirSync(path)
5978
+ const kids = $node.fs.readdirSync(path)
5673
5979
  .filter(name => !/^\.+$/.test(name))
5674
5980
  .map(name => this.resolve(name));
5981
+ return kids;
5675
5982
  }
5676
5983
  catch (e) {
5677
- e.message += '\n' + path;
5678
- return this.$.$mol_fail_hidden(e);
5984
+ if (this.$.$mol_fail_catch(e)) {
5985
+ if (e.code === 'ENOENT')
5986
+ return [];
5987
+ e.message += '\n' + path;
5988
+ }
5989
+ $mol_fail_hidden(e);
5679
5990
  }
5680
5991
  }
5681
5992
  resolve(path) {
5682
- return this.constructor.relative($node.path.join(this.path(), path));
5993
+ return this.constructor
5994
+ .relative($node.path.join(this.path(), path));
5683
5995
  }
5684
5996
  relate(base = this.constructor.relative('.')) {
5685
5997
  return $node.path.relative(base.path(), this.path()).replace(/\\/g, '/');
5686
5998
  }
5687
- append(next) {
5688
- const path = this.path();
5689
- try {
5690
- $node.fs.appendFileSync(path, next);
5691
- }
5692
- catch (e) {
5693
- e.message += '\n' + path;
5694
- return this.$.$mol_fail_hidden(e);
5695
- }
5696
- }
5697
- open(...modes) {
5698
- return $node.fs.openSync(this.path(), modes.reduce((res, mode) => res | $mol_file_mode_open[mode], 0));
5999
+ readable(opts) {
6000
+ const { Readable } = $node['node:stream'];
6001
+ const stream = $node.fs.createReadStream(this.path(), {
6002
+ flags: 'r',
6003
+ autoClose: true,
6004
+ start: opts?.start,
6005
+ end: opts?.end,
6006
+ encoding: 'binary',
6007
+ });
6008
+ return Readable.toWeb(stream);
6009
+ }
6010
+ writable(opts) {
6011
+ const { Writable } = $node['node:stream'];
6012
+ const stream = $node.fs.createWriteStream(this.path(), {
6013
+ flags: 'w+',
6014
+ autoClose: true,
6015
+ start: opts?.start,
6016
+ encoding: 'binary',
6017
+ });
6018
+ return Writable.toWeb(stream);
5699
6019
  }
5700
6020
  }
5701
6021
  __decorate([
5702
6022
  $mol_mem
5703
6023
  ], $mol_file_node.prototype, "watcher", null);
5704
6024
  __decorate([
5705
- $mol_mem
5706
- ], $mol_file_node.prototype, "stat", null);
6025
+ $mol_action
6026
+ ], $mol_file_node.prototype, "info", null);
5707
6027
  __decorate([
5708
- $mol_mem
6028
+ $mol_action
5709
6029
  ], $mol_file_node.prototype, "ensure", null);
6030
+ __decorate([
6031
+ $mol_action
6032
+ ], $mol_file_node.prototype, "copy", null);
5710
6033
  __decorate([
5711
6034
  $mol_action
5712
6035
  ], $mol_file_node.prototype, "drop", null);
5713
6036
  __decorate([
5714
- $mol_mem
5715
- ], $mol_file_node.prototype, "buffer", null);
6037
+ $mol_action
6038
+ ], $mol_file_node.prototype, "read", null);
5716
6039
  __decorate([
5717
- $mol_mem
5718
- ], $mol_file_node.prototype, "sub", null);
6040
+ $mol_action
6041
+ ], $mol_file_node.prototype, "write", null);
5719
6042
  __decorate([
5720
6043
  $mol_mem_key
5721
- ], $mol_file_node, "absolute", null);
6044
+ ], $mol_file_node.prototype, "readable", null);
6045
+ __decorate([
6046
+ $mol_mem
6047
+ ], $mol_file_node.prototype, "writable", null);
5722
6048
  $.$mol_file_node = $mol_file_node;
5723
6049
  $.$mol_file = $mol_file_node;
5724
6050
  })($ || ($ = {}));
@@ -6741,50 +7067,9 @@ var $;
6741
7067
 
6742
7068
  ;
6743
7069
  "use strict";
6744
- var $;
6745
- (function ($) {
6746
- $mol_test({
6747
- 'auto name'() {
6748
- class Invalid extends $mol_error_mix {
6749
- }
6750
- const mix = new Invalid('foo');
6751
- $mol_assert_equal(mix.name, 'Invalid_Error');
6752
- },
6753
- 'simpe mix'() {
6754
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
6755
- $mol_assert_equal(mix.message, 'foo');
6756
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
6757
- },
6758
- 'provide additional info'() {
6759
- class Invalid extends $mol_error_mix {
6760
- }
6761
- 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' }));
6762
- const hints = [];
6763
- if (mix instanceof $mol_error_mix) {
6764
- for (const er of mix.errors) {
6765
- if (er instanceof Invalid) {
6766
- hints.push(er.cause?.hint ?? '');
6767
- }
6768
- }
6769
- }
6770
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
6771
- },
6772
- });
6773
- })($ || ($ = {}));
6774
7070
 
6775
7071
  ;
6776
7072
  "use strict";
6777
- var $;
6778
- (function ($_1) {
6779
- $mol_test_mocks.push($ => {
6780
- $.$mol_log3_come = () => { };
6781
- $.$mol_log3_done = () => { };
6782
- $.$mol_log3_fail = () => { };
6783
- $.$mol_log3_warn = () => { };
6784
- $.$mol_log3_rise = () => { };
6785
- $.$mol_log3_area = () => () => { };
6786
- });
6787
- })($ || ($ = {}));
6788
7073
 
6789
7074
  ;
6790
7075
  "use strict";
@@ -6795,93 +7080,6 @@ var $;
6795
7080
  ;
6796
7081
  "use strict";
6797
7082
 
6798
- ;
6799
- "use strict";
6800
- var $;
6801
- (function ($_1) {
6802
- $mol_test({
6803
- 'test types'($) {
6804
- class A {
6805
- static a() {
6806
- return Promise.resolve('');
6807
- }
6808
- static b() {
6809
- return $mol_wire_sync(this).a();
6810
- }
6811
- }
6812
- },
6813
- async 'test method from host'($) {
6814
- let count = 0;
6815
- class A {
6816
- static a() {
6817
- return $mol_wire_sync(this).b();
6818
- }
6819
- static b() { return Promise.resolve(++count); }
6820
- }
6821
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
6822
- },
6823
- async 'test function'($) {
6824
- let count = 0;
6825
- class A {
6826
- static a() {
6827
- return $mol_wire_sync(this.b)();
6828
- }
6829
- static b() { return Promise.resolve(++count); }
6830
- }
6831
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
6832
- },
6833
- async 'test construct itself'($) {
6834
- class A {
6835
- static instances = [];
6836
- static a() {
6837
- const a = new ($mol_wire_sync(A))();
6838
- this.instances.push(a);
6839
- $mol_wire_sync(this).b();
6840
- }
6841
- static b() { return Promise.resolve(); }
6842
- }
6843
- await $mol_wire_async(A).a();
6844
- $mol_assert_equal(A.instances.length, 2);
6845
- $mol_assert_equal(A.instances[0] instanceof A);
6846
- $mol_assert_equal(A.instances[0], A.instances[1]);
6847
- }
6848
- });
6849
- })($ || ($ = {}));
6850
-
6851
- ;
6852
- "use strict";
6853
- var $;
6854
- (function ($_1) {
6855
- $mol_test({
6856
- async 'exec timeout auto kill child process'($) {
6857
- let close_mock = () => { };
6858
- const context_mock = $.$mol_ambient({
6859
- $mol_run_spawn: () => ({
6860
- on(name, cb) {
6861
- if (name === 'exit')
6862
- close_mock = cb;
6863
- },
6864
- kill() { close_mock(); }
6865
- })
6866
- });
6867
- let message = '';
6868
- try {
6869
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
6870
- }
6871
- catch (e) {
6872
- message = e.message;
6873
- }
6874
- $mol_assert_equal(message, 'Run error, timeout');
6875
- }
6876
- });
6877
- })($ || ($ = {}));
6878
-
6879
- ;
6880
- "use strict";
6881
-
6882
- ;
6883
- "use strict";
6884
-
6885
7083
  ;
6886
7084
  "use strict";
6887
7085
  var $;
@@ -7653,6 +7851,20 @@ var $;
7653
7851
  });
7654
7852
  })($ || ($ = {}));
7655
7853
 
7854
+ ;
7855
+ "use strict";
7856
+ var $;
7857
+ (function ($_1) {
7858
+ $mol_test_mocks.push($ => {
7859
+ $.$mol_log3_come = () => { };
7860
+ $.$mol_log3_done = () => { };
7861
+ $.$mol_log3_fail = () => { };
7862
+ $.$mol_log3_warn = () => { };
7863
+ $.$mol_log3_rise = () => { };
7864
+ $.$mol_log3_area = () => () => { };
7865
+ });
7866
+ })($ || ($ = {}));
7867
+
7656
7868
  ;
7657
7869
  "use strict";
7658
7870
  var $;
@@ -7900,6 +8112,58 @@ var $;
7900
8112
  });
7901
8113
  })($ || ($ = {}));
7902
8114
 
8115
+ ;
8116
+ "use strict";
8117
+ var $;
8118
+ (function ($) {
8119
+ $mol_test({
8120
+ 'init with overload'() {
8121
+ class X extends $mol_object {
8122
+ foo() {
8123
+ return 1;
8124
+ }
8125
+ }
8126
+ var x = X.make({
8127
+ foo: () => 2,
8128
+ });
8129
+ $mol_assert_equal(x.foo(), 2);
8130
+ },
8131
+ });
8132
+ })($ || ($ = {}));
8133
+
8134
+ ;
8135
+ "use strict";
8136
+ var $;
8137
+ (function ($) {
8138
+ $mol_test({
8139
+ 'auto name'() {
8140
+ class Invalid extends $mol_error_mix {
8141
+ }
8142
+ const mix = new Invalid('foo');
8143
+ $mol_assert_equal(mix.name, 'Invalid_Error');
8144
+ },
8145
+ 'simpe mix'() {
8146
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
8147
+ $mol_assert_equal(mix.message, 'foo');
8148
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
8149
+ },
8150
+ 'provide additional info'() {
8151
+ class Invalid extends $mol_error_mix {
8152
+ }
8153
+ 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' }));
8154
+ const hints = [];
8155
+ if (mix instanceof $mol_error_mix) {
8156
+ for (const er of mix.errors) {
8157
+ if (er instanceof Invalid) {
8158
+ hints.push(er.cause?.hint ?? '');
8159
+ }
8160
+ }
8161
+ }
8162
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
8163
+ },
8164
+ });
8165
+ })($ || ($ = {}));
8166
+
7903
8167
  ;
7904
8168
  "use strict";
7905
8169
  var $;
@@ -8087,6 +8351,112 @@ var $;
8087
8351
  });
8088
8352
  })($ || ($ = {}));
8089
8353
 
8354
+ ;
8355
+ "use strict";
8356
+ var $;
8357
+ (function ($_1) {
8358
+ $mol_test({
8359
+ 'test types'($) {
8360
+ class A {
8361
+ static a() {
8362
+ return '';
8363
+ }
8364
+ static b() {
8365
+ return $mol_wire_async(this).a();
8366
+ }
8367
+ }
8368
+ },
8369
+ async 'Latest method calls wins'($) {
8370
+ class NameLogger extends $mol_object2 {
8371
+ static $ = $;
8372
+ static first = [];
8373
+ static last = [];
8374
+ static send(next) {
8375
+ $mol_wire_sync(this.first).push(next);
8376
+ $$.$mol_wait_timeout(0);
8377
+ this.last.push(next);
8378
+ }
8379
+ }
8380
+ const name = $mol_wire_async(NameLogger).send;
8381
+ name('john');
8382
+ const promise = name('jin');
8383
+ $.$mol_after_mock_warp();
8384
+ await promise;
8385
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
8386
+ $mol_assert_equal(NameLogger.last, ['jin']);
8387
+ },
8388
+ async 'Latest function calls wins'($) {
8389
+ const first = [];
8390
+ const last = [];
8391
+ function send_name(next) {
8392
+ $mol_wire_sync(first).push(next);
8393
+ $$.$mol_wait_timeout(0);
8394
+ last.push(next);
8395
+ }
8396
+ const name = $mol_wire_async(send_name);
8397
+ name('john');
8398
+ const promise = name('jin');
8399
+ $.$mol_after_mock_warp();
8400
+ await promise;
8401
+ $mol_assert_equal(first, ['john', 'jin']);
8402
+ $mol_assert_equal(last, ['jin']);
8403
+ },
8404
+ });
8405
+ })($ || ($ = {}));
8406
+
8407
+ ;
8408
+ "use strict";
8409
+ var $;
8410
+ (function ($_1) {
8411
+ $mol_test({
8412
+ 'test types'($) {
8413
+ class A {
8414
+ static a() {
8415
+ return Promise.resolve('');
8416
+ }
8417
+ static b() {
8418
+ return $mol_wire_sync(this).a();
8419
+ }
8420
+ }
8421
+ },
8422
+ async 'test method from host'($) {
8423
+ let count = 0;
8424
+ class A {
8425
+ static a() {
8426
+ return $mol_wire_sync(this).b();
8427
+ }
8428
+ static b() { return Promise.resolve(++count); }
8429
+ }
8430
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
8431
+ },
8432
+ async 'test function'($) {
8433
+ let count = 0;
8434
+ class A {
8435
+ static a() {
8436
+ return $mol_wire_sync(this.b)();
8437
+ }
8438
+ static b() { return Promise.resolve(++count); }
8439
+ }
8440
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
8441
+ },
8442
+ async 'test construct itself'($) {
8443
+ class A {
8444
+ static instances = [];
8445
+ static a() {
8446
+ const a = new ($mol_wire_sync(A))();
8447
+ this.instances.push(a);
8448
+ $mol_wire_sync(this).b();
8449
+ }
8450
+ static b() { return Promise.resolve(); }
8451
+ }
8452
+ await $mol_wire_async(A).a();
8453
+ $mol_assert_equal(A.instances.length, 2);
8454
+ $mol_assert_equal(A.instances[0] instanceof A);
8455
+ $mol_assert_equal(A.instances[0], A.instances[1]);
8456
+ }
8457
+ });
8458
+ })($ || ($ = {}));
8459
+
8090
8460
  ;
8091
8461
  "use strict";
8092
8462
  var $;
@@ -8213,70 +8583,52 @@ var $;
8213
8583
  var $;
8214
8584
  (function ($_1) {
8215
8585
  $mol_test({
8216
- 'test types'($) {
8217
- class A {
8218
- static a() {
8219
- return '';
8220
- }
8221
- static b() {
8222
- return $mol_wire_async(this).a();
8223
- }
8586
+ async 'exec timeout auto kill child process'($) {
8587
+ let close_mock = () => { };
8588
+ const error_message = 'Run error, timeout';
8589
+ function mol_run_spawn_sync_mock() {
8590
+ return {
8591
+ output: [],
8592
+ stdout: error_message,
8593
+ stderr: '',
8594
+ status: 0,
8595
+ signal: null,
8596
+ pid: 123,
8597
+ };
8224
8598
  }
8225
- },
8226
- async 'Latest method calls wins'($) {
8227
- class NameLogger extends $mol_object2 {
8228
- static $ = $;
8229
- static first = [];
8230
- static last = [];
8231
- static send(next) {
8232
- $mol_wire_sync(this.first).push(next);
8233
- $$.$mol_wait_timeout(0);
8234
- this.last.push(next);
8599
+ function mol_run_spawn_mock() {
8600
+ return {
8601
+ on(name, cb) {
8602
+ if (name === 'exit')
8603
+ close_mock = cb;
8604
+ },
8605
+ kill() { close_mock(); }
8606
+ };
8607
+ }
8608
+ const context_mock = $.$mol_ambient({
8609
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
8610
+ $mol_run_spawn: mol_run_spawn_mock
8611
+ });
8612
+ class $mol_run_mock extends $mol_run {
8613
+ static get $() { return context_mock; }
8614
+ static async_enabled() {
8615
+ return true;
8235
8616
  }
8236
8617
  }
8237
- const name = $mol_wire_async(NameLogger).send;
8238
- name('john');
8239
- const promise = name('jin');
8240
- $.$mol_after_mock_warp();
8241
- await promise;
8242
- $mol_assert_equal(NameLogger.first, ['john', 'jin']);
8243
- $mol_assert_equal(NameLogger.last, ['jin']);
8244
- },
8245
- async 'Latest function calls wins'($) {
8246
- const first = [];
8247
- const last = [];
8248
- function send_name(next) {
8249
- $mol_wire_sync(first).push(next);
8250
- $$.$mol_wait_timeout(0);
8251
- last.push(next);
8618
+ let message = '';
8619
+ try {
8620
+ const res = await $mol_wire_async($mol_run_mock).spawn({
8621
+ command: 'sleep 10',
8622
+ dir: '.',
8623
+ timeout: 10,
8624
+ env: { 'MOL_RUN_ASYNC': '1' }
8625
+ });
8252
8626
  }
8253
- const name = $mol_wire_async(send_name);
8254
- name('john');
8255
- const promise = name('jin');
8256
- $.$mol_after_mock_warp();
8257
- await promise;
8258
- $mol_assert_equal(first, ['john', 'jin']);
8259
- $mol_assert_equal(last, ['jin']);
8260
- },
8261
- });
8262
- })($ || ($ = {}));
8263
-
8264
- ;
8265
- "use strict";
8266
- var $;
8267
- (function ($) {
8268
- $mol_test({
8269
- 'init with overload'() {
8270
- class X extends $mol_object {
8271
- foo() {
8272
- return 1;
8273
- }
8627
+ catch (e) {
8628
+ message = e.message;
8274
8629
  }
8275
- var x = X.make({
8276
- foo: () => 2,
8277
- });
8278
- $mol_assert_equal(x.foo(), 2);
8279
- },
8630
+ $mol_assert_equal(message, error_message);
8631
+ }
8280
8632
  });
8281
8633
  })($ || ($ = {}));
8282
8634
 
@@ -9976,6 +10328,24 @@ var $;
9976
10328
  })($$ = $_1.$$ || ($_1.$$ = {}));
9977
10329
  })($ || ($ = {}));
9978
10330
 
10331
+ ;
10332
+ "use strict";
10333
+ var $;
10334
+ (function ($) {
10335
+ class TestClass extends Uint8Array {
10336
+ }
10337
+ $mol_test({
10338
+ 'Uint8Array vs itself'() {
10339
+ $mol_assert_ok($mol_compare_array(new Uint8Array, new Uint8Array));
10340
+ $mol_assert_ok($mol_compare_array(new Uint8Array([0]), new Uint8Array([0])));
10341
+ $mol_assert_not($mol_compare_array(new Uint8Array([0]), new Uint8Array([1])));
10342
+ },
10343
+ 'Uint8Array vs subclassed array'() {
10344
+ $mol_assert_not($mol_compare_array(new Uint8Array, new TestClass));
10345
+ },
10346
+ });
10347
+ })($ || ($ = {}));
10348
+
9979
10349
  ;
9980
10350
  "use strict";
9981
10351
  var $;
@@ -10007,24 +10377,6 @@ var $;
10007
10377
  });
10008
10378
  })($ || ($ = {}));
10009
10379
 
10010
- ;
10011
- "use strict";
10012
- var $;
10013
- (function ($) {
10014
- class TestClass extends Uint8Array {
10015
- }
10016
- $mol_test({
10017
- 'Uint8Array vs itself'() {
10018
- $mol_assert_ok($mol_compare_array(new Uint8Array, new Uint8Array));
10019
- $mol_assert_ok($mol_compare_array(new Uint8Array([0]), new Uint8Array([0])));
10020
- $mol_assert_not($mol_compare_array(new Uint8Array([0]), new Uint8Array([1])));
10021
- },
10022
- 'Uint8Array vs subclassed array'() {
10023
- $mol_assert_not($mol_compare_array(new Uint8Array, new TestClass));
10024
- },
10025
- });
10026
- })($ || ($ = {}));
10027
-
10028
10380
  ;
10029
10381
  "use strict";
10030
10382
  var $;