hyoo_sync_client 0.0.549 → 0.0.551

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
@@ -359,1295 +359,1315 @@ var $;
359
359
  $.$mol_error_mix = $mol_error_mix;
360
360
  })($ || ($ = {}));
361
361
 
362
+ ;
363
+ "use strict";
364
+ var $;
365
+ (function ($_1) {
366
+ let $$;
367
+ (function ($$) {
368
+ let $;
369
+ })($$ = $_1.$$ || ($_1.$$ = {}));
370
+ $_1.$mol_object_field = Symbol('$mol_object_field');
371
+ class $mol_object extends $mol_object2 {
372
+ static make(config) {
373
+ return super.create(obj => {
374
+ for (let key in config)
375
+ obj[key] = config[key];
376
+ });
377
+ }
378
+ }
379
+ $_1.$mol_object = $mol_object;
380
+ })($ || ($ = {}));
381
+
362
382
  ;
363
383
  "use strict";
364
384
  var $;
365
385
  (function ($) {
366
- function $mol_log3_area_lazy(event) {
367
- const self = this;
368
- const stack = self.$mol_log3_stack;
369
- const deep = stack.length;
370
- let logged = false;
371
- stack.push(() => {
372
- logged = true;
373
- self.$mol_log3_area.call(self, event);
374
- });
375
- return () => {
376
- if (logged)
377
- self.console.groupEnd();
378
- if (stack.length > deep)
379
- stack.length = deep;
380
- };
386
+ function $mol_env() {
387
+ return {};
381
388
  }
382
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
383
- $.$mol_log3_stack = [];
389
+ $.$mol_env = $mol_env;
384
390
  })($ || ($ = {}));
385
391
 
386
392
  ;
387
393
  "use strict";
388
394
  var $;
389
395
  (function ($) {
390
- class $mol_span extends $mol_object2 {
391
- uri;
392
- source;
393
- row;
394
- col;
395
- length;
396
- constructor(uri, source, row, col, length) {
397
- super();
398
- this.uri = uri;
399
- this.source = source;
400
- this.row = row;
401
- this.col = col;
402
- this.length = length;
403
- this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
396
+ $.$mol_env = function $mol_env() {
397
+ return this.process.env;
398
+ };
399
+ })($ || ($ = {}));
400
+
401
+ ;
402
+ "use strict";
403
+ var $;
404
+ (function ($) {
405
+ let $mol_wire_cursor;
406
+ (function ($mol_wire_cursor) {
407
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
408
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
409
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
410
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
411
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
412
+ })($ || ($ = {}));
413
+
414
+ ;
415
+ "use strict";
416
+ var $;
417
+ (function ($) {
418
+ class $mol_wire_pub extends Object {
419
+ data = [];
420
+ static get [Symbol.species]() {
421
+ return Array;
404
422
  }
405
- static unknown = $mol_span.begin('?');
406
- static begin(uri, source = '') {
407
- return new $mol_span(uri, source, 1, 1, 0);
423
+ sub_from = 0;
424
+ get sub_list() {
425
+ const res = [];
426
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
427
+ res.push(this.data[i]);
428
+ }
429
+ return res;
408
430
  }
409
- static end(uri, source) {
410
- return new $mol_span(uri, source, 1, source.length + 1, 0);
431
+ get sub_empty() {
432
+ return this.sub_from === this.data.length;
411
433
  }
412
- static entire(uri, source) {
413
- return new $mol_span(uri, source, 1, 1, source.length);
434
+ sub_on(sub, pub_pos) {
435
+ const pos = this.data.length;
436
+ this.data.push(sub, pub_pos);
437
+ return pos;
414
438
  }
415
- toString() {
416
- return this[Symbol.toStringTag];
439
+ sub_off(sub_pos) {
440
+ if (!(sub_pos < this.data.length)) {
441
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
442
+ }
443
+ const end = this.data.length - 2;
444
+ if (sub_pos !== end) {
445
+ this.peer_move(end, sub_pos);
446
+ }
447
+ this.data.pop();
448
+ this.data.pop();
449
+ if (this.data.length === this.sub_from)
450
+ this.reap();
417
451
  }
418
- toJSON() {
419
- return {
420
- uri: this.uri,
421
- row: this.row,
422
- col: this.col,
423
- length: this.length
424
- };
452
+ reap() { }
453
+ promote() {
454
+ $mol_wire_auto()?.track_next(this);
425
455
  }
426
- error(message, Class = Error) {
427
- return new Class(`${message} (${this})`);
456
+ fresh() { }
457
+ complete() { }
458
+ get incompleted() {
459
+ return false;
428
460
  }
429
- span(row, col, length) {
430
- return new $mol_span(this.uri, this.source, row, col, length);
461
+ emit(quant = $mol_wire_cursor.stale) {
462
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
463
+ ;
464
+ this.data[i].absorb(quant);
465
+ }
431
466
  }
432
- after(length = 0) {
433
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
467
+ peer_move(from_pos, to_pos) {
468
+ const peer = this.data[from_pos];
469
+ const self_pos = this.data[from_pos + 1];
470
+ this.data[to_pos] = peer;
471
+ this.data[to_pos + 1] = self_pos;
472
+ peer.peer_repos(self_pos, to_pos);
434
473
  }
435
- slice(begin, end = -1) {
436
- let len = this.length;
437
- if (begin < 0)
438
- begin += len;
439
- if (end < 0)
440
- end += len;
441
- if (begin < 0 || begin > len)
442
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
443
- if (end < 0 || end > len)
444
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
445
- if (end < begin)
446
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
447
- return this.span(this.row, this.col + begin, end - begin);
474
+ peer_repos(peer_pos, self_pos) {
475
+ this.data[peer_pos + 1] = self_pos;
448
476
  }
449
477
  }
450
- $.$mol_span = $mol_span;
478
+ $.$mol_wire_pub = $mol_wire_pub;
451
479
  })($ || ($ = {}));
452
480
 
481
+ ;
482
+ "use strict";
483
+
453
484
  ;
454
485
  "use strict";
455
486
  var $;
456
487
  (function ($) {
457
- function $mol_tree2_to_string(tree) {
458
- let output = [];
459
- function dump(tree, prefix = '') {
460
- if (tree.type.length) {
461
- if (!prefix.length) {
462
- prefix = "\t";
463
- }
464
- output.push(tree.type);
465
- if (tree.kids.length == 1) {
466
- output.push(' ');
467
- dump(tree.kids[0], prefix);
468
- return;
469
- }
470
- output.push("\n");
471
- }
472
- else if (tree.value.length || prefix.length) {
473
- output.push("\\" + tree.value + "\n");
474
- }
475
- for (const kid of tree.kids) {
476
- output.push(prefix);
477
- dump(kid, prefix + "\t");
478
- }
479
- }
480
- dump(tree);
481
- return output.join('');
488
+ $.$mol_wire_auto_sub = null;
489
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
490
+ return $.$mol_wire_auto_sub = next;
482
491
  }
483
- $.$mol_tree2_to_string = $mol_tree2_to_string;
492
+ $.$mol_wire_auto = $mol_wire_auto;
493
+ $.$mol_wire_affected = [];
484
494
  })($ || ($ = {}));
485
495
 
486
496
  ;
487
497
  "use strict";
488
498
  var $;
489
499
  (function ($) {
490
- class $mol_tree2 extends Object {
491
- type;
492
- value;
493
- kids;
494
- span;
495
- constructor(type, value, kids, span) {
496
- super();
497
- this.type = type;
498
- this.value = value;
499
- this.kids = kids;
500
- this.span = span;
501
- this[Symbol.toStringTag] = type || '\\' + value;
502
- }
503
- static list(kids, span = $mol_span.unknown) {
504
- return new $mol_tree2('', '', kids, span);
505
- }
506
- list(kids) {
507
- return $mol_tree2.list(kids, this.span);
508
- }
509
- static data(value, kids = [], span = $mol_span.unknown) {
510
- const chunks = value.split('\n');
511
- if (chunks.length > 1) {
512
- let kid_span = span.span(span.row, span.col, 0);
513
- const data = chunks.map(chunk => {
514
- kid_span = kid_span.after(chunk.length);
515
- return new $mol_tree2('', chunk, [], kid_span);
516
- });
517
- kids = [...data, ...kids];
518
- value = '';
500
+ $['devtoolsFormatters'] ||= [];
501
+ function $mol_dev_format_register(config) {
502
+ $['devtoolsFormatters'].push(config);
503
+ }
504
+ $.$mol_dev_format_register = $mol_dev_format_register;
505
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
506
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
507
+ $mol_dev_format_register({
508
+ header: (val, config = false) => {
509
+ if (config)
510
+ return null;
511
+ if (!val)
512
+ return null;
513
+ if ($.$mol_dev_format_head in val) {
514
+ try {
515
+ return val[$.$mol_dev_format_head]();
516
+ }
517
+ catch (error) {
518
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
519
+ }
519
520
  }
520
- return new $mol_tree2('', value, kids, span);
521
- }
522
- data(value, kids = []) {
523
- return $mol_tree2.data(value, kids, this.span);
524
- }
525
- static struct(type, kids = [], span = $mol_span.unknown) {
526
- if (/[ \n\t\\]/.test(type)) {
527
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
521
+ if (typeof val === 'function') {
522
+ return $mol_dev_format_native(val);
528
523
  }
529
- return new $mol_tree2(type, '', kids, span);
530
- }
531
- struct(type, kids = []) {
532
- return $mol_tree2.struct(type, kids, this.span);
533
- }
534
- clone(kids, span = this.span) {
535
- return new $mol_tree2(this.type, this.value, kids, span);
524
+ if (Symbol.toStringTag in val) {
525
+ return $mol_dev_format_native(val);
526
+ }
527
+ return null;
528
+ },
529
+ hasBody: val => val[$.$mol_dev_format_body],
530
+ body: val => val[$.$mol_dev_format_body](),
531
+ });
532
+ function $mol_dev_format_native(obj) {
533
+ if (typeof obj === 'undefined')
534
+ return $.$mol_dev_format_shade('undefined');
535
+ return [
536
+ 'object',
537
+ {
538
+ object: obj,
539
+ config: true,
540
+ },
541
+ ];
542
+ }
543
+ $.$mol_dev_format_native = $mol_dev_format_native;
544
+ function $mol_dev_format_auto(obj) {
545
+ if (obj == null)
546
+ return $.$mol_dev_format_shade(String(obj));
547
+ return [
548
+ 'object',
549
+ {
550
+ object: obj,
551
+ config: false,
552
+ },
553
+ ];
554
+ }
555
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
556
+ function $mol_dev_format_element(element, style, ...content) {
557
+ const styles = [];
558
+ for (let key in style)
559
+ styles.push(`${key} : ${style[key]}`);
560
+ return [
561
+ element,
562
+ {
563
+ style: styles.join(' ; '),
564
+ },
565
+ ...content,
566
+ ];
567
+ }
568
+ $.$mol_dev_format_element = $mol_dev_format_element;
569
+ function $mol_dev_format_span(style, ...content) {
570
+ return $mol_dev_format_element('span', {
571
+ ...style,
572
+ }, ...content);
573
+ }
574
+ $.$mol_dev_format_span = $mol_dev_format_span;
575
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
576
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
577
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
578
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
579
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
580
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
581
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
582
+ 'color': 'magenta',
583
+ });
584
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
585
+ 'font-weight': 'bold',
586
+ });
587
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
588
+ 'color': 'green',
589
+ });
590
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
591
+ 'color': 'gray',
592
+ });
593
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
594
+ 'margin-left': '13px'
595
+ });
596
+ })($ || ($ = {}));
597
+
598
+ ;
599
+ "use strict";
600
+ var $;
601
+ (function ($) {
602
+ class $mol_wire_pub_sub extends $mol_wire_pub {
603
+ pub_from = 0;
604
+ cursor = $mol_wire_cursor.stale;
605
+ get temp() {
606
+ return false;
536
607
  }
537
- text() {
538
- var values = [];
539
- for (var kid of this.kids) {
540
- if (kid.type)
541
- continue;
542
- values.push(kid.value);
608
+ get pub_list() {
609
+ const res = [];
610
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
611
+ for (let i = this.pub_from; i < max; i += 2) {
612
+ if (this.data[i])
613
+ res.push(this.data[i]);
543
614
  }
544
- return this.value + values.join('\n');
615
+ return res;
545
616
  }
546
- static fromString(str, uri = 'unknown') {
547
- return $$.$mol_tree2_from_string(str, uri);
617
+ track_on() {
618
+ this.cursor = this.pub_from;
619
+ const sub = $mol_wire_auto();
620
+ $mol_wire_auto(this);
621
+ return sub;
548
622
  }
549
- toString() {
550
- return $$.$mol_tree2_to_string(this);
623
+ promote() {
624
+ if (this.cursor >= this.pub_from) {
625
+ $mol_fail(new Error('Circular subscription'));
626
+ }
627
+ super.promote();
551
628
  }
552
- insert(value, ...path) {
553
- if (path.length === 0)
554
- return value;
555
- const type = path[0];
556
- if (typeof type === 'string') {
557
- let replaced = false;
558
- const sub = this.kids.map((item, index) => {
559
- if (item.type !== type)
560
- return item;
561
- replaced = true;
562
- return item.insert(value, ...path.slice(1));
563
- }).filter(Boolean);
564
- if (!replaced && value) {
565
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
629
+ track_next(pub) {
630
+ if (this.cursor < 0)
631
+ $mol_fail(new Error('Promo to non begun sub'));
632
+ if (this.cursor < this.sub_from) {
633
+ const next = this.data[this.cursor];
634
+ if (pub === undefined)
635
+ return next ?? null;
636
+ if (next === pub) {
637
+ this.cursor += 2;
638
+ return next;
639
+ }
640
+ if (next) {
641
+ if (this.sub_from < this.data.length) {
642
+ this.peer_move(this.sub_from, this.data.length);
643
+ }
644
+ this.peer_move(this.cursor, this.sub_from);
645
+ this.sub_from += 2;
566
646
  }
567
- return this.clone(sub);
568
- }
569
- else if (typeof type === 'number') {
570
- const sub = this.kids.slice();
571
- sub[type] = (sub[type] || this.list([]))
572
- .insert(value, ...path.slice(1));
573
- return this.clone(sub.filter(Boolean));
574
647
  }
575
648
  else {
576
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
577
- .map(item => item.insert(value, ...path.slice(1)))
578
- .filter(Boolean);
579
- return this.clone(kids);
649
+ if (pub === undefined)
650
+ return null;
651
+ if (this.sub_from < this.data.length) {
652
+ this.peer_move(this.sub_from, this.data.length);
653
+ }
654
+ this.sub_from += 2;
580
655
  }
656
+ this.data[this.cursor] = pub;
657
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
658
+ this.cursor += 2;
659
+ return pub;
581
660
  }
582
- select(...path) {
583
- let next = [this];
584
- for (const type of path) {
585
- if (!next.length)
586
- break;
587
- const prev = next;
588
- next = [];
589
- for (var item of prev) {
590
- switch (typeof (type)) {
591
- case 'string':
592
- for (var child of item.kids) {
593
- if (child.type == type) {
594
- next.push(child);
595
- }
596
- }
597
- break;
598
- case 'number':
599
- if (type < item.kids.length)
600
- next.push(item.kids[type]);
601
- break;
602
- default: next.push(...item.kids);
603
- }
604
- }
661
+ track_off(sub) {
662
+ $mol_wire_auto(sub);
663
+ if (this.cursor < 0) {
664
+ $mol_fail(new Error('End of non begun sub'));
605
665
  }
606
- return this.list(next);
666
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
667
+ const pub = this.data[cursor];
668
+ pub.fresh();
669
+ }
670
+ this.cursor = $mol_wire_cursor.fresh;
607
671
  }
608
- filter(path, value) {
609
- const sub = this.kids.filter(item => {
610
- var found = item.select(...path);
611
- if (value === undefined) {
612
- return Boolean(found.kids.length);
672
+ pub_off(sub_pos) {
673
+ this.data[sub_pos] = undefined;
674
+ this.data[sub_pos + 1] = undefined;
675
+ }
676
+ destructor() {
677
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
678
+ const sub = this.data[cursor];
679
+ const pos = this.data[cursor + 1];
680
+ sub.pub_off(pos);
681
+ this.data.pop();
682
+ this.data.pop();
683
+ }
684
+ this.cursor = this.pub_from;
685
+ this.track_cut();
686
+ this.cursor = $mol_wire_cursor.final;
687
+ }
688
+ track_cut() {
689
+ if (this.cursor < this.pub_from) {
690
+ $mol_fail(new Error('Cut of non begun sub'));
691
+ }
692
+ let tail = 0;
693
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
694
+ const pub = this.data[cursor];
695
+ pub?.sub_off(this.data[cursor + 1]);
696
+ if (this.sub_from < this.data.length) {
697
+ this.peer_move(this.data.length - 2, cursor);
698
+ this.data.pop();
699
+ this.data.pop();
613
700
  }
614
701
  else {
615
- return found.kids.some(child => child.value == value);
702
+ ++tail;
616
703
  }
617
- });
618
- return this.clone(sub);
619
- }
620
- hack_self(belt, context = {}) {
621
- let handle = belt[this.type] || belt[''];
622
- if (!handle || handle === Object.prototype[this.type]) {
623
- handle = (input, belt, context) => [
624
- input.clone(input.hack(belt, context), context.span)
625
- ];
626
- }
627
- try {
628
- return handle(this, belt, context);
629
704
  }
630
- catch (error) {
631
- error.message += `\n${this.clone([])}${this.span}`;
632
- $mol_fail_hidden(error);
705
+ for (; tail; --tail) {
706
+ this.data.pop();
707
+ this.data.pop();
633
708
  }
709
+ this.sub_from = this.cursor;
634
710
  }
635
- hack(belt, context = {}) {
636
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
711
+ complete() { }
712
+ complete_pubs() {
713
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
714
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
715
+ const pub = this.data[cursor];
716
+ if (pub?.incompleted)
717
+ return;
718
+ }
719
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
720
+ const pub = this.data[cursor];
721
+ pub?.complete();
722
+ }
637
723
  }
638
- error(message, Class = Error) {
639
- return this.span.error(`${message}\n${this.clone([])}`, Class);
724
+ absorb(quant = $mol_wire_cursor.stale) {
725
+ if (this.cursor === $mol_wire_cursor.final)
726
+ return;
727
+ if (this.cursor >= quant)
728
+ return;
729
+ this.cursor = quant;
730
+ this.emit($mol_wire_cursor.doubt);
640
731
  }
641
- }
642
- $.$mol_tree2 = $mol_tree2;
643
- class $mol_tree2_empty extends $mol_tree2 {
644
- constructor() {
645
- super('', '', [], $mol_span.unknown);
732
+ [$mol_dev_format_head]() {
733
+ return $mol_dev_format_native(this);
734
+ }
735
+ get pub_empty() {
736
+ return this.sub_from === this.pub_from;
646
737
  }
647
738
  }
648
- $.$mol_tree2_empty = $mol_tree2_empty;
739
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
649
740
  })($ || ($ = {}));
650
741
 
651
742
  ;
652
743
  "use strict";
653
744
  var $;
654
745
  (function ($) {
655
- class $mol_error_syntax extends SyntaxError {
656
- reason;
657
- line;
658
- span;
659
- constructor(reason, line, span) {
660
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
661
- this.reason = reason;
662
- this.line = line;
663
- this.span = span;
746
+ class $mol_after_tick extends $mol_object2 {
747
+ task;
748
+ static promise = null;
749
+ cancelled = false;
750
+ constructor(task) {
751
+ super();
752
+ this.task = task;
753
+ if (!$mol_after_tick.promise)
754
+ $mol_after_tick.promise = Promise.resolve().then(() => {
755
+ $mol_after_tick.promise = null;
756
+ });
757
+ $mol_after_tick.promise.then(() => {
758
+ if (this.cancelled)
759
+ return;
760
+ task();
761
+ });
762
+ }
763
+ destructor() {
764
+ this.cancelled = true;
664
765
  }
665
766
  }
666
- $.$mol_error_syntax = $mol_error_syntax;
767
+ $.$mol_after_tick = $mol_after_tick;
667
768
  })($ || ($ = {}));
668
769
 
669
770
  ;
670
771
  "use strict";
671
772
  var $;
672
773
  (function ($) {
673
- function $mol_tree2_from_string(str, uri = '?') {
674
- const span = $mol_span.entire(uri, str);
675
- var root = $mol_tree2.list([], span);
676
- var stack = [root];
677
- var pos = 0, row = 0, min_indent = 0;
678
- while (str.length > pos) {
679
- var indent = 0;
680
- var line_start = pos;
681
- row++;
682
- while (str.length > pos && str[pos] == '\t') {
683
- indent++;
684
- pos++;
685
- }
686
- if (!root.kids.length) {
687
- min_indent = indent;
688
- }
689
- indent -= min_indent;
690
- if (indent < 0 || indent >= stack.length) {
691
- const sp = span.span(row, 1, pos - line_start);
692
- while (str.length > pos && str[pos] != '\n') {
693
- pos++;
694
- }
695
- if (indent < 0) {
696
- if (str.length > pos) {
697
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
698
- }
699
- }
700
- else {
701
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
702
- }
703
- }
704
- stack.length = indent + 1;
705
- var parent = stack[indent];
706
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
707
- var error_start = pos;
708
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
709
- pos++;
710
- }
711
- if (pos > error_start) {
712
- let line_end = str.indexOf('\n', pos);
713
- if (line_end === -1)
714
- line_end = str.length;
715
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
716
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
717
- }
718
- var type_start = pos;
719
- while (str.length > pos &&
720
- str[pos] != '\\' &&
721
- str[pos] != ' ' &&
722
- str[pos] != '\t' &&
723
- str[pos] != '\n') {
724
- pos++;
774
+ const wrappers = new WeakMap();
775
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
776
+ task;
777
+ host;
778
+ static warm = true;
779
+ static planning = new Set();
780
+ static reaping = new Set();
781
+ static plan_task = null;
782
+ static plan() {
783
+ if (this.plan_task)
784
+ return;
785
+ this.plan_task = new $mol_after_tick(() => {
786
+ try {
787
+ this.sync();
725
788
  }
726
- if (pos > type_start) {
727
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
728
- const parent_kids = parent.kids;
729
- parent_kids.push(next);
730
- parent = next;
789
+ finally {
790
+ $mol_wire_fiber.plan_task = null;
731
791
  }
732
- if (str.length > pos && str[pos] == ' ') {
733
- pos++;
792
+ });
793
+ }
794
+ static sync() {
795
+ while (this.planning.size) {
796
+ for (const fiber of this.planning) {
797
+ this.planning.delete(fiber);
798
+ if (fiber.cursor >= 0)
799
+ continue;
800
+ if (fiber.cursor === $mol_wire_cursor.final)
801
+ continue;
802
+ fiber.fresh();
734
803
  }
735
804
  }
736
- if (str.length > pos && str[pos] == '\\') {
737
- var data_start = pos;
738
- while (str.length > pos && str[pos] != '\n') {
739
- pos++;
805
+ while (this.reaping.size) {
806
+ const fibers = this.reaping;
807
+ this.reaping = new Set;
808
+ for (const fiber of fibers) {
809
+ if (!fiber.sub_empty)
810
+ continue;
811
+ fiber.destructor();
740
812
  }
741
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
742
- const parent_kids = parent.kids;
743
- parent_kids.push(next);
744
- parent = next;
745
- }
746
- if (str.length === pos && stack.length > 0) {
747
- const sp = span.span(row, pos - line_start + 1, 1);
748
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
749
813
  }
750
- stack.push(parent);
751
- pos++;
752
814
  }
753
- return root;
754
- }
755
- $.$mol_tree2_from_string = $mol_tree2_from_string;
756
- })($ || ($ = {}));
757
-
758
- ;
759
- "use strict";
760
- var $;
761
- (function ($) {
762
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
763
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
764
- return new $mol_tree2(String(json), '', [], span);
815
+ [Symbol.toStringTag];
816
+ cache = undefined;
817
+ get args() {
818
+ return this.data.slice(0, this.pub_from);
765
819
  }
766
- if (typeof json === 'string') {
767
- return $mol_tree2.data(json, [], span);
820
+ result() {
821
+ if ($mol_promise_like(this.cache))
822
+ return;
823
+ if (this.cache instanceof Error)
824
+ return;
825
+ return this.cache;
768
826
  }
769
- if (typeof json.toJSON === 'function') {
770
- return $mol_tree2_from_json(json.toJSON());
827
+ get incompleted() {
828
+ return $mol_promise_like(this.cache);
771
829
  }
772
- if (Array.isArray(json)) {
773
- const sub = json.map(json => $mol_tree2_from_json(json, span));
774
- return new $mol_tree2('/', '', sub, span);
830
+ field() {
831
+ return this.task.name + '<>';
775
832
  }
776
- if (ArrayBuffer.isView(json)) {
777
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
778
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
833
+ constructor(id, task, host, args) {
834
+ super();
835
+ this.task = task;
836
+ this.host = host;
837
+ if (args)
838
+ this.data.push(...args);
839
+ this.pub_from = this.sub_from = args?.length ?? 0;
840
+ this[Symbol.toStringTag] = id;
779
841
  }
780
- if (json instanceof Date) {
781
- return new $mol_tree2('', json.toISOString(), [], span);
842
+ plan() {
843
+ $mol_wire_fiber.planning.add(this);
844
+ $mol_wire_fiber.plan();
845
+ return this;
782
846
  }
783
- if (json.toString !== Object.prototype.toString) {
784
- return $mol_tree2.data(json.toString(), [], span);
847
+ reap() {
848
+ $mol_wire_fiber.reaping.add(this);
849
+ $mol_wire_fiber.plan();
785
850
  }
786
- if (json instanceof Error) {
787
- const { name, message, stack } = json;
788
- json = { ...json, name, message, stack };
851
+ toString() {
852
+ return this[Symbol.toStringTag];
789
853
  }
790
- const sub = [];
791
- for (var key in json) {
792
- const val = json[key];
793
- if (val === undefined)
794
- continue;
795
- const subsub = $mol_tree2_from_json(val, span);
796
- if (/^[^\n\t\\ ]+$/.test(key)) {
797
- sub.push(new $mol_tree2(key, '', [subsub], span));
798
- }
799
- else {
800
- sub.push($mol_tree2.data(key, [subsub], span));
801
- }
854
+ toJSON() {
855
+ return this[Symbol.toStringTag];
802
856
  }
803
- return new $mol_tree2('*', '', sub, span);
804
- }
805
- $.$mol_tree2_from_json = $mol_tree2_from_json;
806
- })($ || ($ = {}));
807
-
808
- ;
809
- "use strict";
810
- var $;
811
- (function ($) {
812
- class $mol_term_color {
813
- static reset = this.ansi(0, 0);
814
- static bold = this.ansi(1, 22);
815
- static italic = this.ansi(3, 23);
816
- static underline = this.ansi(4, 24);
817
- static inverse = this.ansi(7, 27);
818
- static hidden = this.ansi(8, 28);
819
- static strike = this.ansi(9, 29);
820
- static gray = this.ansi(90, 39);
821
- static red = this.ansi(91, 39);
822
- static green = this.ansi(92, 39);
823
- static yellow = this.ansi(93, 39);
824
- static blue = this.ansi(94, 39);
825
- static magenta = this.ansi(95, 39);
826
- static cyan = this.ansi(96, 39);
827
- static Gray = (str) => this.inverse(this.gray(str));
828
- static Red = (str) => this.inverse(this.red(str));
829
- static Green = (str) => this.inverse(this.green(str));
830
- static Yellow = (str) => this.inverse(this.yellow(str));
831
- static Blue = (str) => this.inverse(this.blue(str));
832
- static Magenta = (str) => this.inverse(this.magenta(str));
833
- static Cyan = (str) => this.inverse(this.cyan(str));
834
- static ansi(open, close) {
835
- if (typeof process === 'undefined')
836
- return String;
837
- if (!process.stdout.isTTY)
838
- return String;
839
- const prefix = `\x1b[${open}m`;
840
- const postfix = `\x1b[${close}m`;
841
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
842
- return function colorer(str) {
843
- str = String(str);
844
- if (str === '')
845
- return str;
846
- const suffix = str.replace(suffix_regexp, prefix);
847
- return prefix + suffix + postfix;
848
- };
849
- }
850
- }
851
- $.$mol_term_color = $mol_term_color;
852
- })($ || ($ = {}));
853
-
854
- ;
855
- "use strict";
856
- var $;
857
- (function ($) {
858
- function $mol_log3_node_make(level, output, type, color) {
859
- return function $mol_log3_logger(event) {
860
- if (!event.time)
861
- event = { time: new Date().toISOString(), ...event };
862
- let tree = this.$mol_tree2_from_json(event);
863
- tree = tree.struct(type, tree.kids);
864
- let str = color(tree.toString());
865
- this.console[level](str);
866
- const self = this;
867
- return () => self.console.groupEnd();
868
- };
869
- }
870
- $.$mol_log3_node_make = $mol_log3_node_make;
871
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
872
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
873
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
874
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
875
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
876
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
877
- })($ || ($ = {}));
878
-
879
- ;
880
- "use strict";
881
- var $;
882
- (function ($) {
883
- function $mol_env() {
884
- return {};
885
- }
886
- $.$mol_env = $mol_env;
887
- })($ || ($ = {}));
888
-
889
- ;
890
- "use strict";
891
- var $;
892
- (function ($) {
893
- $.$mol_env = function $mol_env() {
894
- return this.process.env;
895
- };
896
- })($ || ($ = {}));
897
-
898
- ;
899
- "use strict";
900
- var $;
901
- (function ($) {
902
- let $mol_wire_cursor;
903
- (function ($mol_wire_cursor) {
904
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
905
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
906
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
907
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
908
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
909
- })($ || ($ = {}));
910
-
911
- ;
912
- "use strict";
913
- var $;
914
- (function ($) {
915
- class $mol_wire_pub extends Object {
916
- data = [];
917
- static get [Symbol.species]() {
918
- return Array;
919
- }
920
- sub_from = 0;
921
- get sub_list() {
922
- const res = [];
923
- for (let i = this.sub_from; i < this.data.length; i += 2) {
924
- res.push(this.data[i]);
925
- }
926
- return res;
857
+ [$mol_dev_format_head]() {
858
+ const cursor = {
859
+ [$mol_wire_cursor.stale]: '🔴',
860
+ [$mol_wire_cursor.doubt]: '🟡',
861
+ [$mol_wire_cursor.fresh]: '🟢',
862
+ [$mol_wire_cursor.final]: '🔵',
863
+ }[this.cursor] ?? this.cursor.toString();
864
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
865
+ ? $mol_dev_format_auto({
866
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
867
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
868
+ })
869
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
927
870
  }
928
- get sub_empty() {
929
- return this.sub_from === this.data.length;
871
+ get $() {
872
+ return (this.host ?? this.task)['$'];
930
873
  }
931
- sub_on(sub, pub_pos) {
932
- const pos = this.data.length;
933
- this.data.push(sub, pub_pos);
934
- return pos;
874
+ emit(quant = $mol_wire_cursor.stale) {
875
+ if (this.sub_empty)
876
+ this.plan();
877
+ else
878
+ super.emit(quant);
935
879
  }
936
- sub_off(sub_pos) {
937
- if (!(sub_pos < this.data.length)) {
938
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
880
+ fresh() {
881
+ if (this.cursor === $mol_wire_cursor.fresh)
882
+ return;
883
+ if (this.cursor === $mol_wire_cursor.final)
884
+ return;
885
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
886
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
887
+ ;
888
+ this.data[i]?.fresh();
889
+ if (this.cursor !== $mol_wire_cursor.doubt)
890
+ break check;
891
+ }
892
+ this.cursor = $mol_wire_cursor.fresh;
893
+ return;
939
894
  }
940
- const end = this.data.length - 2;
941
- if (sub_pos !== end) {
942
- this.peer_move(end, sub_pos);
895
+ const bu = this.track_on();
896
+ let result;
897
+ try {
898
+ switch (this.pub_from) {
899
+ case 0:
900
+ result = this.task.call(this.host);
901
+ break;
902
+ case 1:
903
+ result = this.task.call(this.host, this.data[0]);
904
+ break;
905
+ default:
906
+ result = this.task.call(this.host, ...this.args);
907
+ break;
908
+ }
909
+ if ($mol_promise_like(result)) {
910
+ if (wrappers.has(result)) {
911
+ result = wrappers.get(result).then(a => a);
912
+ }
913
+ else {
914
+ const put = (res) => {
915
+ if (this.cache === result)
916
+ this.put(res);
917
+ return res;
918
+ };
919
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
920
+ wrappers.set(result, result);
921
+ const error = new Error(`Promise in ${this}`);
922
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
923
+ }
924
+ }
943
925
  }
944
- this.data.pop();
945
- this.data.pop();
946
- if (this.data.length === this.sub_from)
947
- this.reap();
948
- }
949
- reap() { }
950
- promote() {
951
- $mol_wire_auto()?.track_next(this);
952
- }
953
- fresh() { }
954
- complete() { }
955
- get incompleted() {
956
- return false;
957
- }
958
- emit(quant = $mol_wire_cursor.stale) {
959
- for (let i = this.sub_from; i < this.data.length; i += 2) {
960
- ;
961
- this.data[i].absorb(quant);
926
+ catch (error) {
927
+ if (error instanceof Error || $mol_promise_like(error)) {
928
+ result = error;
929
+ }
930
+ else {
931
+ result = new Error(String(error), { cause: error });
932
+ }
933
+ if ($mol_promise_like(result)) {
934
+ if (wrappers.has(result)) {
935
+ result = wrappers.get(result);
936
+ }
937
+ else {
938
+ wrappers.set(result, result = Object.assign(result.finally(() => {
939
+ if (this.cache === result)
940
+ this.absorb();
941
+ }), { destructor: result.destructor || (() => { }) }));
942
+ const error = new Error(`Promise in ${this}`);
943
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
944
+ }
945
+ }
946
+ }
947
+ if (!$mol_promise_like(result)) {
948
+ this.track_cut();
962
949
  }
950
+ this.track_off(bu);
951
+ this.put(result);
952
+ return this;
963
953
  }
964
- peer_move(from_pos, to_pos) {
965
- const peer = this.data[from_pos];
966
- const self_pos = this.data[from_pos + 1];
967
- this.data[to_pos] = peer;
968
- this.data[to_pos + 1] = self_pos;
969
- peer.peer_repos(self_pos, to_pos);
954
+ refresh() {
955
+ this.cursor = $mol_wire_cursor.stale;
956
+ this.fresh();
970
957
  }
971
- peer_repos(peer_pos, self_pos) {
972
- this.data[peer_pos + 1] = self_pos;
958
+ sync() {
959
+ if (!$mol_wire_fiber.warm) {
960
+ return this.result();
961
+ }
962
+ this.promote();
963
+ this.fresh();
964
+ if (this.cache instanceof Error) {
965
+ return $mol_fail_hidden(this.cache);
966
+ }
967
+ if ($mol_promise_like(this.cache)) {
968
+ return $mol_fail_hidden(this.cache);
969
+ }
970
+ return this.cache;
973
971
  }
974
- }
975
- $.$mol_wire_pub = $mol_wire_pub;
976
- })($ || ($ = {}));
977
-
978
- ;
979
- "use strict";
980
-
981
- ;
982
- "use strict";
983
- var $;
984
- (function ($) {
985
- $.$mol_wire_auto_sub = null;
986
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
987
- return $.$mol_wire_auto_sub = next;
988
- }
989
- $.$mol_wire_auto = $mol_wire_auto;
990
- $.$mol_wire_affected = [];
991
- })($ || ($ = {}));
992
-
993
- ;
994
- "use strict";
995
- var $;
996
- (function ($) {
997
- $['devtoolsFormatters'] ||= [];
998
- function $mol_dev_format_register(config) {
999
- $['devtoolsFormatters'].push(config);
1000
- }
1001
- $.$mol_dev_format_register = $mol_dev_format_register;
1002
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1003
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1004
- $mol_dev_format_register({
1005
- header: (val, config = false) => {
1006
- if (config)
1007
- return null;
1008
- if (!val)
1009
- return null;
1010
- if ($.$mol_dev_format_head in val) {
1011
- try {
1012
- return val[$.$mol_dev_format_head]();
972
+ async async_raw() {
973
+ while (true) {
974
+ this.fresh();
975
+ if (this.cache instanceof Error) {
976
+ $mol_fail_hidden(this.cache);
1013
977
  }
1014
- catch (error) {
1015
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
978
+ if (!$mol_promise_like(this.cache))
979
+ return this.cache;
980
+ await Promise.race([this.cache, this.step()]);
981
+ if (!$mol_promise_like(this.cache))
982
+ return this.cache;
983
+ if (this.cursor === $mol_wire_cursor.final) {
984
+ await new Promise(() => { });
1016
985
  }
1017
986
  }
1018
- if (typeof val === 'function') {
1019
- return $mol_dev_format_native(val);
1020
- }
1021
- if (Symbol.toStringTag in val) {
1022
- return $mol_dev_format_native(val);
987
+ }
988
+ async() {
989
+ const promise = this.async_raw();
990
+ if (!promise.destructor)
991
+ promise.destructor = () => this.destructor();
992
+ return promise;
993
+ }
994
+ step() {
995
+ return new Promise(done => {
996
+ const sub = new $mol_wire_pub_sub;
997
+ const prev = sub.track_on();
998
+ sub.track_next(this);
999
+ sub.track_off(prev);
1000
+ sub.absorb = () => {
1001
+ done(null);
1002
+ setTimeout(() => sub.destructor());
1003
+ };
1004
+ });
1005
+ }
1006
+ destructor() {
1007
+ super.destructor();
1008
+ if ($mol_owning_check(this, this.cache)) {
1009
+ this.cache.destructor();
1023
1010
  }
1024
- return null;
1025
- },
1026
- hasBody: val => val[$.$mol_dev_format_body],
1027
- body: val => val[$.$mol_dev_format_body](),
1028
- });
1029
- function $mol_dev_format_native(obj) {
1030
- if (typeof obj === 'undefined')
1031
- return $.$mol_dev_format_shade('undefined');
1032
- return [
1033
- 'object',
1034
- {
1035
- object: obj,
1036
- config: true,
1037
- },
1038
- ];
1039
- }
1040
- $.$mol_dev_format_native = $mol_dev_format_native;
1041
- function $mol_dev_format_auto(obj) {
1042
- if (obj == null)
1043
- return $.$mol_dev_format_shade(String(obj));
1044
- return [
1045
- 'object',
1046
- {
1047
- object: obj,
1048
- config: false,
1049
- },
1050
- ];
1051
- }
1052
- $.$mol_dev_format_auto = $mol_dev_format_auto;
1053
- function $mol_dev_format_element(element, style, ...content) {
1054
- const styles = [];
1055
- for (let key in style)
1056
- styles.push(`${key} : ${style[key]}`);
1057
- return [
1058
- element,
1059
- {
1060
- style: styles.join(' ; '),
1061
- },
1062
- ...content,
1063
- ];
1064
- }
1065
- $.$mol_dev_format_element = $mol_dev_format_element;
1066
- function $mol_dev_format_span(style, ...content) {
1067
- return $mol_dev_format_element('span', {
1068
- ...style,
1069
- }, ...content);
1011
+ }
1070
1012
  }
1071
- $.$mol_dev_format_span = $mol_dev_format_span;
1072
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1073
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1074
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1075
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1076
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1077
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1078
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
1079
- 'color': 'magenta',
1080
- });
1081
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
1082
- 'font-weight': 'bold',
1083
- });
1084
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
1085
- 'color': 'green',
1086
- });
1087
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
1088
- 'color': 'gray',
1089
- });
1090
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1091
- 'margin-left': '13px'
1092
- });
1013
+ $.$mol_wire_fiber = $mol_wire_fiber;
1093
1014
  })($ || ($ = {}));
1094
1015
 
1095
1016
  ;
1096
1017
  "use strict";
1097
1018
  var $;
1098
1019
  (function ($) {
1099
- class $mol_wire_pub_sub extends $mol_wire_pub {
1100
- pub_from = 0;
1101
- cursor = $mol_wire_cursor.stale;
1102
- get temp() {
1020
+ $.$mol_compare_deep_cache = new WeakMap();
1021
+ function $mol_compare_deep(left, right) {
1022
+ if (Object.is(left, right))
1023
+ return true;
1024
+ if (left === null)
1103
1025
  return false;
1026
+ if (right === null)
1027
+ return false;
1028
+ if (typeof left !== 'object')
1029
+ return false;
1030
+ if (typeof right !== 'object')
1031
+ return false;
1032
+ const left_proto = Reflect.getPrototypeOf(left);
1033
+ const right_proto = Reflect.getPrototypeOf(right);
1034
+ if (left_proto !== right_proto)
1035
+ return false;
1036
+ if (left instanceof Boolean)
1037
+ return Object.is(left.valueOf(), right['valueOf']());
1038
+ if (left instanceof Number)
1039
+ return Object.is(left.valueOf(), right['valueOf']());
1040
+ if (left instanceof String)
1041
+ return Object.is(left.valueOf(), right['valueOf']());
1042
+ if (left instanceof Date)
1043
+ return Object.is(left.valueOf(), right['valueOf']());
1044
+ if (left instanceof RegExp)
1045
+ return left.source === right.source && left.flags === right.flags;
1046
+ if (left instanceof Error)
1047
+ return left.message === right.message && left.stack === right.stack;
1048
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1049
+ if (left_cache) {
1050
+ const right_cache = left_cache.get(right);
1051
+ if (typeof right_cache === 'boolean')
1052
+ return right_cache;
1104
1053
  }
1105
- get pub_list() {
1106
- const res = [];
1107
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1108
- for (let i = this.pub_from; i < max; i += 2) {
1109
- if (this.data[i])
1110
- res.push(this.data[i]);
1111
- }
1112
- return res;
1113
- }
1114
- track_on() {
1115
- this.cursor = this.pub_from;
1116
- const sub = $mol_wire_auto();
1117
- $mol_wire_auto(this);
1118
- return sub;
1119
- }
1120
- promote() {
1121
- if (this.cursor >= this.pub_from) {
1122
- $mol_fail(new Error('Circular subscription'));
1123
- }
1124
- super.promote();
1125
- }
1126
- track_next(pub) {
1127
- if (this.cursor < 0)
1128
- $mol_fail(new Error('Promo to non begun sub'));
1129
- if (this.cursor < this.sub_from) {
1130
- const next = this.data[this.cursor];
1131
- if (pub === undefined)
1132
- return next ?? null;
1133
- if (next === pub) {
1134
- this.cursor += 2;
1135
- return next;
1136
- }
1137
- if (next) {
1138
- if (this.sub_from < this.data.length) {
1139
- this.peer_move(this.sub_from, this.data.length);
1140
- }
1141
- this.peer_move(this.cursor, this.sub_from);
1142
- this.sub_from += 2;
1143
- }
1144
- }
1145
- else {
1146
- if (pub === undefined)
1147
- return null;
1148
- if (this.sub_from < this.data.length) {
1149
- this.peer_move(this.sub_from, this.data.length);
1150
- }
1151
- this.sub_from += 2;
1152
- }
1153
- this.data[this.cursor] = pub;
1154
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1155
- this.cursor += 2;
1156
- return pub;
1157
- }
1158
- track_off(sub) {
1159
- $mol_wire_auto(sub);
1160
- if (this.cursor < 0) {
1161
- $mol_fail(new Error('End of non begun sub'));
1162
- }
1163
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1164
- const pub = this.data[cursor];
1165
- pub.fresh();
1166
- }
1167
- this.cursor = $mol_wire_cursor.fresh;
1054
+ else {
1055
+ left_cache = new WeakMap();
1056
+ $.$mol_compare_deep_cache.set(left, left_cache);
1168
1057
  }
1169
- pub_off(sub_pos) {
1170
- this.data[sub_pos] = undefined;
1171
- this.data[sub_pos + 1] = undefined;
1058
+ left_cache.set(right, true);
1059
+ let result;
1060
+ try {
1061
+ if (!left_proto)
1062
+ result = compare_pojo(left, right);
1063
+ else if (!Reflect.getPrototypeOf(left_proto))
1064
+ result = compare_pojo(left, right);
1065
+ else if (Symbol.toPrimitive in left)
1066
+ result = compare_primitive(left, right);
1067
+ else if (Array.isArray(left))
1068
+ result = compare_array(left, right);
1069
+ else if (left instanceof Set)
1070
+ result = compare_set(left, right);
1071
+ else if (left instanceof Map)
1072
+ result = compare_map(left, right);
1073
+ else if (ArrayBuffer.isView(left))
1074
+ result = compare_buffer(left, right);
1075
+ else if (Symbol.iterator in left)
1076
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1077
+ else
1078
+ result = false;
1172
1079
  }
1173
- destructor() {
1174
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1175
- const sub = this.data[cursor];
1176
- const pos = this.data[cursor + 1];
1177
- sub.pub_off(pos);
1178
- this.data.pop();
1179
- this.data.pop();
1180
- }
1181
- this.cursor = this.pub_from;
1182
- this.track_cut();
1183
- this.cursor = $mol_wire_cursor.final;
1080
+ finally {
1081
+ left_cache.set(right, result);
1184
1082
  }
1185
- track_cut() {
1186
- if (this.cursor < this.pub_from) {
1187
- $mol_fail(new Error('Cut of non begun sub'));
1188
- }
1189
- let tail = 0;
1190
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1191
- const pub = this.data[cursor];
1192
- pub?.sub_off(this.data[cursor + 1]);
1193
- if (this.sub_from < this.data.length) {
1194
- this.peer_move(this.data.length - 2, cursor);
1195
- this.data.pop();
1196
- this.data.pop();
1197
- }
1198
- else {
1199
- ++tail;
1200
- }
1201
- }
1202
- for (; tail; --tail) {
1203
- this.data.pop();
1204
- this.data.pop();
1205
- }
1206
- this.sub_from = this.cursor;
1083
+ return result;
1084
+ }
1085
+ $.$mol_compare_deep = $mol_compare_deep;
1086
+ function compare_array(left, right) {
1087
+ const len = left.length;
1088
+ if (len !== right.length)
1089
+ return false;
1090
+ for (let i = 0; i < len; ++i) {
1091
+ if (!$mol_compare_deep(left[i], right[i]))
1092
+ return false;
1207
1093
  }
1208
- complete() { }
1209
- complete_pubs() {
1210
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1211
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1212
- const pub = this.data[cursor];
1213
- if (pub?.incompleted)
1214
- return;
1215
- }
1216
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1217
- const pub = this.data[cursor];
1218
- pub?.complete();
1219
- }
1094
+ return true;
1095
+ }
1096
+ function compare_buffer(left, right) {
1097
+ const len = left.byteLength;
1098
+ if (len !== right.byteLength)
1099
+ return false;
1100
+ if (left instanceof DataView)
1101
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1102
+ for (let i = 0; i < len; ++i) {
1103
+ if (left[i] !== right[i])
1104
+ return false;
1220
1105
  }
1221
- absorb(quant = $mol_wire_cursor.stale) {
1222
- if (this.cursor === $mol_wire_cursor.final)
1223
- return;
1224
- if (this.cursor >= quant)
1225
- return;
1226
- this.cursor = quant;
1227
- this.emit($mol_wire_cursor.doubt);
1106
+ return true;
1107
+ }
1108
+ function compare_iterator(left, right) {
1109
+ while (true) {
1110
+ const left_next = left.next();
1111
+ const right_next = right.next();
1112
+ if (left_next.done !== right_next.done)
1113
+ return false;
1114
+ if (left_next.done)
1115
+ break;
1116
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1117
+ return false;
1228
1118
  }
1229
- [$mol_dev_format_head]() {
1230
- return $mol_dev_format_native(this);
1119
+ return true;
1120
+ }
1121
+ function compare_set(left, right) {
1122
+ if (left.size !== right.size)
1123
+ return false;
1124
+ return compare_iterator(left.values(), right.values());
1125
+ }
1126
+ function compare_map(left, right) {
1127
+ if (left.size !== right.size)
1128
+ return false;
1129
+ return compare_iterator(left.keys(), right.keys())
1130
+ && compare_iterator(left.values(), right.values());
1131
+ }
1132
+ function compare_pojo(left, right) {
1133
+ const left_keys = Object.getOwnPropertyNames(left);
1134
+ const right_keys = Object.getOwnPropertyNames(right);
1135
+ if (!compare_array(left_keys, right_keys))
1136
+ return false;
1137
+ for (let key of left_keys) {
1138
+ if (!$mol_compare_deep(left[key], right[key]))
1139
+ return false;
1231
1140
  }
1232
- get pub_empty() {
1233
- return this.sub_from === this.pub_from;
1141
+ const left_syms = Object.getOwnPropertySymbols(left);
1142
+ const right_syms = Object.getOwnPropertySymbols(right);
1143
+ if (!compare_array(left_syms, right_syms))
1144
+ return false;
1145
+ for (let key of left_syms) {
1146
+ if (!$mol_compare_deep(left[key], right[key]))
1147
+ return false;
1234
1148
  }
1149
+ return true;
1150
+ }
1151
+ function compare_primitive(left, right) {
1152
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1235
1153
  }
1236
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1237
1154
  })($ || ($ = {}));
1238
1155
 
1239
1156
  ;
1240
1157
  "use strict";
1241
1158
  var $;
1242
1159
  (function ($) {
1243
- class $mol_after_tick extends $mol_object2 {
1244
- task;
1245
- static promise = null;
1246
- cancelled = false;
1247
- constructor(task) {
1160
+ function $mol_log3_area_lazy(event) {
1161
+ const self = this;
1162
+ const stack = self.$mol_log3_stack;
1163
+ const deep = stack.length;
1164
+ let logged = false;
1165
+ stack.push(() => {
1166
+ logged = true;
1167
+ self.$mol_log3_area.call(self, event);
1168
+ });
1169
+ return () => {
1170
+ if (logged)
1171
+ self.console.groupEnd();
1172
+ if (stack.length > deep)
1173
+ stack.length = deep;
1174
+ };
1175
+ }
1176
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1177
+ $.$mol_log3_stack = [];
1178
+ })($ || ($ = {}));
1179
+
1180
+ ;
1181
+ "use strict";
1182
+ var $;
1183
+ (function ($) {
1184
+ class $mol_span extends $mol_object2 {
1185
+ uri;
1186
+ source;
1187
+ row;
1188
+ col;
1189
+ length;
1190
+ constructor(uri, source, row, col, length) {
1248
1191
  super();
1249
- this.task = task;
1250
- if (!$mol_after_tick.promise)
1251
- $mol_after_tick.promise = Promise.resolve().then(() => {
1252
- $mol_after_tick.promise = null;
1253
- });
1254
- $mol_after_tick.promise.then(() => {
1255
- if (this.cancelled)
1256
- return;
1257
- task();
1258
- });
1192
+ this.uri = uri;
1193
+ this.source = source;
1194
+ this.row = row;
1195
+ this.col = col;
1196
+ this.length = length;
1197
+ this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1259
1198
  }
1260
- destructor() {
1261
- this.cancelled = true;
1199
+ static unknown = $mol_span.begin('?');
1200
+ static begin(uri, source = '') {
1201
+ return new $mol_span(uri, source, 1, 1, 0);
1202
+ }
1203
+ static end(uri, source) {
1204
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1205
+ }
1206
+ static entire(uri, source) {
1207
+ return new $mol_span(uri, source, 1, 1, source.length);
1208
+ }
1209
+ toString() {
1210
+ return this[Symbol.toStringTag];
1211
+ }
1212
+ toJSON() {
1213
+ return {
1214
+ uri: this.uri,
1215
+ row: this.row,
1216
+ col: this.col,
1217
+ length: this.length
1218
+ };
1219
+ }
1220
+ error(message, Class = Error) {
1221
+ return new Class(`${message} (${this})`);
1222
+ }
1223
+ span(row, col, length) {
1224
+ return new $mol_span(this.uri, this.source, row, col, length);
1225
+ }
1226
+ after(length = 0) {
1227
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1228
+ }
1229
+ slice(begin, end = -1) {
1230
+ let len = this.length;
1231
+ if (begin < 0)
1232
+ begin += len;
1233
+ if (end < 0)
1234
+ end += len;
1235
+ if (begin < 0 || begin > len)
1236
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1237
+ if (end < 0 || end > len)
1238
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1239
+ if (end < begin)
1240
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1241
+ return this.span(this.row, this.col + begin, end - begin);
1262
1242
  }
1263
1243
  }
1264
- $.$mol_after_tick = $mol_after_tick;
1244
+ $.$mol_span = $mol_span;
1265
1245
  })($ || ($ = {}));
1266
1246
 
1267
1247
  ;
1268
1248
  "use strict";
1269
1249
  var $;
1270
1250
  (function ($) {
1271
- const wrappers = new WeakMap();
1272
- class $mol_wire_fiber extends $mol_wire_pub_sub {
1273
- task;
1274
- host;
1275
- static warm = true;
1276
- static planning = new Set();
1277
- static reaping = new Set();
1278
- static plan_task = null;
1279
- static plan() {
1280
- if (this.plan_task)
1281
- return;
1282
- this.plan_task = new $mol_after_tick(() => {
1283
- try {
1284
- this.sync();
1285
- }
1286
- finally {
1287
- $mol_wire_fiber.plan_task = null;
1251
+ function $mol_tree2_to_string(tree) {
1252
+ let output = [];
1253
+ function dump(tree, prefix = '') {
1254
+ if (tree.type.length) {
1255
+ if (!prefix.length) {
1256
+ prefix = "\t";
1288
1257
  }
1289
- });
1290
- }
1291
- static sync() {
1292
- while (this.planning.size) {
1293
- for (const fiber of this.planning) {
1294
- this.planning.delete(fiber);
1295
- if (fiber.cursor >= 0)
1296
- continue;
1297
- if (fiber.cursor === $mol_wire_cursor.final)
1298
- continue;
1299
- fiber.fresh();
1258
+ output.push(tree.type);
1259
+ if (tree.kids.length == 1) {
1260
+ output.push(' ');
1261
+ dump(tree.kids[0], prefix);
1262
+ return;
1300
1263
  }
1264
+ output.push("\n");
1301
1265
  }
1302
- while (this.reaping.size) {
1303
- const fibers = this.reaping;
1304
- this.reaping = new Set;
1305
- for (const fiber of fibers) {
1306
- if (!fiber.sub_empty)
1307
- continue;
1308
- fiber.destructor();
1309
- }
1266
+ else if (tree.value.length || prefix.length) {
1267
+ output.push("\\" + tree.value + "\n");
1268
+ }
1269
+ for (const kid of tree.kids) {
1270
+ output.push(prefix);
1271
+ dump(kid, prefix + "\t");
1310
1272
  }
1311
1273
  }
1312
- [Symbol.toStringTag];
1313
- cache = undefined;
1314
- get args() {
1315
- return this.data.slice(0, this.pub_from);
1316
- }
1317
- result() {
1318
- if ($mol_promise_like(this.cache))
1319
- return;
1320
- if (this.cache instanceof Error)
1321
- return;
1322
- return this.cache;
1274
+ dump(tree);
1275
+ return output.join('');
1276
+ }
1277
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1278
+ })($ || ($ = {}));
1279
+
1280
+ ;
1281
+ "use strict";
1282
+ var $;
1283
+ (function ($) {
1284
+ class $mol_tree2 extends Object {
1285
+ type;
1286
+ value;
1287
+ kids;
1288
+ span;
1289
+ constructor(type, value, kids, span) {
1290
+ super();
1291
+ this.type = type;
1292
+ this.value = value;
1293
+ this.kids = kids;
1294
+ this.span = span;
1295
+ this[Symbol.toStringTag] = type || '\\' + value;
1323
1296
  }
1324
- get incompleted() {
1325
- return $mol_promise_like(this.cache);
1297
+ static list(kids, span = $mol_span.unknown) {
1298
+ return new $mol_tree2('', '', kids, span);
1326
1299
  }
1327
- field() {
1328
- return this.task.name + '<>';
1300
+ list(kids) {
1301
+ return $mol_tree2.list(kids, this.span);
1329
1302
  }
1330
- constructor(id, task, host, args) {
1331
- super();
1332
- this.task = task;
1333
- this.host = host;
1334
- if (args)
1335
- this.data.push(...args);
1336
- this.pub_from = this.sub_from = args?.length ?? 0;
1337
- this[Symbol.toStringTag] = id;
1303
+ static data(value, kids = [], span = $mol_span.unknown) {
1304
+ const chunks = value.split('\n');
1305
+ if (chunks.length > 1) {
1306
+ let kid_span = span.span(span.row, span.col, 0);
1307
+ const data = chunks.map(chunk => {
1308
+ kid_span = kid_span.after(chunk.length);
1309
+ return new $mol_tree2('', chunk, [], kid_span);
1310
+ });
1311
+ kids = [...data, ...kids];
1312
+ value = '';
1313
+ }
1314
+ return new $mol_tree2('', value, kids, span);
1338
1315
  }
1339
- plan() {
1340
- $mol_wire_fiber.planning.add(this);
1341
- $mol_wire_fiber.plan();
1342
- return this;
1316
+ data(value, kids = []) {
1317
+ return $mol_tree2.data(value, kids, this.span);
1343
1318
  }
1344
- reap() {
1345
- $mol_wire_fiber.reaping.add(this);
1346
- $mol_wire_fiber.plan();
1319
+ static struct(type, kids = [], span = $mol_span.unknown) {
1320
+ if (/[ \n\t\\]/.test(type)) {
1321
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1322
+ }
1323
+ return new $mol_tree2(type, '', kids, span);
1347
1324
  }
1348
- toString() {
1349
- return this[Symbol.toStringTag];
1325
+ struct(type, kids = []) {
1326
+ return $mol_tree2.struct(type, kids, this.span);
1350
1327
  }
1351
- toJSON() {
1352
- return this[Symbol.toStringTag];
1328
+ clone(kids, span = this.span) {
1329
+ return new $mol_tree2(this.type, this.value, kids, span);
1353
1330
  }
1354
- [$mol_dev_format_head]() {
1355
- const cursor = {
1356
- [$mol_wire_cursor.stale]: '🔴',
1357
- [$mol_wire_cursor.doubt]: '🟡',
1358
- [$mol_wire_cursor.fresh]: '🟢',
1359
- [$mol_wire_cursor.final]: '🔵',
1360
- }[this.cursor] ?? this.cursor.toString();
1361
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1362
- ? $mol_dev_format_auto({
1363
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1364
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1365
- })
1366
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1331
+ text() {
1332
+ var values = [];
1333
+ for (var kid of this.kids) {
1334
+ if (kid.type)
1335
+ continue;
1336
+ values.push(kid.value);
1337
+ }
1338
+ return this.value + values.join('\n');
1367
1339
  }
1368
- get $() {
1369
- return (this.host ?? this.task)['$'];
1340
+ static fromString(str, uri = 'unknown') {
1341
+ return $$.$mol_tree2_from_string(str, uri);
1370
1342
  }
1371
- emit(quant = $mol_wire_cursor.stale) {
1372
- if (this.sub_empty)
1373
- this.plan();
1374
- else
1375
- super.emit(quant);
1343
+ toString() {
1344
+ return $$.$mol_tree2_to_string(this);
1376
1345
  }
1377
- fresh() {
1378
- if (this.cursor === $mol_wire_cursor.fresh)
1379
- return;
1380
- if (this.cursor === $mol_wire_cursor.final)
1381
- return;
1382
- check: if (this.cursor === $mol_wire_cursor.doubt) {
1383
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
1384
- ;
1385
- this.data[i]?.fresh();
1386
- if (this.cursor !== $mol_wire_cursor.doubt)
1387
- break check;
1346
+ insert(value, ...path) {
1347
+ if (path.length === 0)
1348
+ return value;
1349
+ const type = path[0];
1350
+ if (typeof type === 'string') {
1351
+ let replaced = false;
1352
+ const sub = this.kids.map((item, index) => {
1353
+ if (item.type !== type)
1354
+ return item;
1355
+ replaced = true;
1356
+ return item.insert(value, ...path.slice(1));
1357
+ }).filter(Boolean);
1358
+ if (!replaced && value) {
1359
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1388
1360
  }
1389
- this.cursor = $mol_wire_cursor.fresh;
1390
- return;
1361
+ return this.clone(sub);
1391
1362
  }
1392
- const bu = this.track_on();
1393
- let result;
1394
- try {
1395
- switch (this.pub_from) {
1396
- case 0:
1397
- result = this.task.call(this.host);
1398
- break;
1399
- case 1:
1400
- result = this.task.call(this.host, this.data[0]);
1401
- break;
1402
- default:
1403
- result = this.task.call(this.host, ...this.args);
1404
- break;
1405
- }
1406
- if ($mol_promise_like(result)) {
1407
- if (wrappers.has(result)) {
1408
- result = wrappers.get(result).then(a => a);
1409
- }
1410
- else {
1411
- const put = (res) => {
1412
- if (this.cache === result)
1413
- this.put(res);
1414
- return res;
1415
- };
1416
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1417
- wrappers.set(result, result);
1418
- const error = new Error(`Promise in ${this}`);
1419
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1363
+ else if (typeof type === 'number') {
1364
+ const sub = this.kids.slice();
1365
+ sub[type] = (sub[type] || this.list([]))
1366
+ .insert(value, ...path.slice(1));
1367
+ return this.clone(sub.filter(Boolean));
1368
+ }
1369
+ else {
1370
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1371
+ .map(item => item.insert(value, ...path.slice(1)))
1372
+ .filter(Boolean);
1373
+ return this.clone(kids);
1374
+ }
1375
+ }
1376
+ select(...path) {
1377
+ let next = [this];
1378
+ for (const type of path) {
1379
+ if (!next.length)
1380
+ break;
1381
+ const prev = next;
1382
+ next = [];
1383
+ for (var item of prev) {
1384
+ switch (typeof (type)) {
1385
+ case 'string':
1386
+ for (var child of item.kids) {
1387
+ if (child.type == type) {
1388
+ next.push(child);
1389
+ }
1390
+ }
1391
+ break;
1392
+ case 'number':
1393
+ if (type < item.kids.length)
1394
+ next.push(item.kids[type]);
1395
+ break;
1396
+ default: next.push(...item.kids);
1420
1397
  }
1421
1398
  }
1422
1399
  }
1423
- catch (error) {
1424
- if (error instanceof Error || $mol_promise_like(error)) {
1425
- result = error;
1400
+ return this.list(next);
1401
+ }
1402
+ filter(path, value) {
1403
+ const sub = this.kids.filter(item => {
1404
+ var found = item.select(...path);
1405
+ if (value === undefined) {
1406
+ return Boolean(found.kids.length);
1426
1407
  }
1427
1408
  else {
1428
- result = new Error(String(error), { cause: error });
1429
- }
1430
- if ($mol_promise_like(result)) {
1431
- if (wrappers.has(result)) {
1432
- result = wrappers.get(result);
1433
- }
1434
- else {
1435
- wrappers.set(result, result = Object.assign(result.finally(() => {
1436
- if (this.cache === result)
1437
- this.absorb();
1438
- }), { destructor: result.destructor || (() => { }) }));
1439
- const error = new Error(`Promise in ${this}`);
1440
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1441
- }
1409
+ return found.kids.some(child => child.value == value);
1442
1410
  }
1411
+ });
1412
+ return this.clone(sub);
1413
+ }
1414
+ hack_self(belt, context = {}) {
1415
+ let handle = belt[this.type] || belt[''];
1416
+ if (!handle || handle === Object.prototype[this.type]) {
1417
+ handle = (input, belt, context) => [
1418
+ input.clone(input.hack(belt, context), context.span)
1419
+ ];
1443
1420
  }
1444
- if (!$mol_promise_like(result)) {
1445
- this.track_cut();
1421
+ try {
1422
+ return handle(this, belt, context);
1423
+ }
1424
+ catch (error) {
1425
+ error.message += `\n${this.clone([])}${this.span}`;
1426
+ $mol_fail_hidden(error);
1446
1427
  }
1447
- this.track_off(bu);
1448
- this.put(result);
1449
- return this;
1450
1428
  }
1451
- refresh() {
1452
- this.cursor = $mol_wire_cursor.stale;
1453
- this.fresh();
1429
+ hack(belt, context = {}) {
1430
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1454
1431
  }
1455
- sync() {
1456
- if (!$mol_wire_fiber.warm) {
1457
- return this.result();
1432
+ error(message, Class = Error) {
1433
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1434
+ }
1435
+ }
1436
+ $.$mol_tree2 = $mol_tree2;
1437
+ class $mol_tree2_empty extends $mol_tree2 {
1438
+ constructor() {
1439
+ super('', '', [], $mol_span.unknown);
1440
+ }
1441
+ }
1442
+ $.$mol_tree2_empty = $mol_tree2_empty;
1443
+ })($ || ($ = {}));
1444
+
1445
+ ;
1446
+ "use strict";
1447
+ var $;
1448
+ (function ($) {
1449
+ class $mol_error_syntax extends SyntaxError {
1450
+ reason;
1451
+ line;
1452
+ span;
1453
+ constructor(reason, line, span) {
1454
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1455
+ this.reason = reason;
1456
+ this.line = line;
1457
+ this.span = span;
1458
+ }
1459
+ }
1460
+ $.$mol_error_syntax = $mol_error_syntax;
1461
+ })($ || ($ = {}));
1462
+
1463
+ ;
1464
+ "use strict";
1465
+ var $;
1466
+ (function ($) {
1467
+ function $mol_tree2_from_string(str, uri = '?') {
1468
+ const span = $mol_span.entire(uri, str);
1469
+ var root = $mol_tree2.list([], span);
1470
+ var stack = [root];
1471
+ var pos = 0, row = 0, min_indent = 0;
1472
+ while (str.length > pos) {
1473
+ var indent = 0;
1474
+ var line_start = pos;
1475
+ row++;
1476
+ while (str.length > pos && str[pos] == '\t') {
1477
+ indent++;
1478
+ pos++;
1458
1479
  }
1459
- this.promote();
1460
- this.fresh();
1461
- if (this.cache instanceof Error) {
1462
- return $mol_fail_hidden(this.cache);
1480
+ if (!root.kids.length) {
1481
+ min_indent = indent;
1463
1482
  }
1464
- if ($mol_promise_like(this.cache)) {
1465
- return $mol_fail_hidden(this.cache);
1483
+ indent -= min_indent;
1484
+ if (indent < 0 || indent >= stack.length) {
1485
+ const sp = span.span(row, 1, pos - line_start);
1486
+ while (str.length > pos && str[pos] != '\n') {
1487
+ pos++;
1488
+ }
1489
+ if (indent < 0) {
1490
+ if (str.length > pos) {
1491
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1492
+ }
1493
+ }
1494
+ else {
1495
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1496
+ }
1466
1497
  }
1467
- return this.cache;
1468
- }
1469
- async async_raw() {
1470
- while (true) {
1471
- this.fresh();
1472
- if (this.cache instanceof Error) {
1473
- $mol_fail_hidden(this.cache);
1498
+ stack.length = indent + 1;
1499
+ var parent = stack[indent];
1500
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1501
+ var error_start = pos;
1502
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1503
+ pos++;
1474
1504
  }
1475
- if (!$mol_promise_like(this.cache))
1476
- return this.cache;
1477
- await Promise.race([this.cache, this.step()]);
1478
- if (!$mol_promise_like(this.cache))
1479
- return this.cache;
1480
- if (this.cursor === $mol_wire_cursor.final) {
1481
- await new Promise(() => { });
1505
+ if (pos > error_start) {
1506
+ let line_end = str.indexOf('\n', pos);
1507
+ if (line_end === -1)
1508
+ line_end = str.length;
1509
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1510
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1511
+ }
1512
+ var type_start = pos;
1513
+ while (str.length > pos &&
1514
+ str[pos] != '\\' &&
1515
+ str[pos] != ' ' &&
1516
+ str[pos] != '\t' &&
1517
+ str[pos] != '\n') {
1518
+ pos++;
1519
+ }
1520
+ if (pos > type_start) {
1521
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1522
+ const parent_kids = parent.kids;
1523
+ parent_kids.push(next);
1524
+ parent = next;
1525
+ }
1526
+ if (str.length > pos && str[pos] == ' ') {
1527
+ pos++;
1528
+ }
1529
+ }
1530
+ if (str.length > pos && str[pos] == '\\') {
1531
+ var data_start = pos;
1532
+ while (str.length > pos && str[pos] != '\n') {
1533
+ pos++;
1482
1534
  }
1535
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1536
+ const parent_kids = parent.kids;
1537
+ parent_kids.push(next);
1538
+ parent = next;
1539
+ }
1540
+ if (str.length === pos && stack.length > 0) {
1541
+ const sp = span.span(row, pos - line_start + 1, 1);
1542
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1483
1543
  }
1544
+ stack.push(parent);
1545
+ pos++;
1484
1546
  }
1485
- async() {
1486
- const promise = this.async_raw();
1487
- if (!promise.destructor)
1488
- promise.destructor = () => this.destructor();
1489
- return promise;
1547
+ return root;
1548
+ }
1549
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1550
+ })($ || ($ = {}));
1551
+
1552
+ ;
1553
+ "use strict";
1554
+ var $;
1555
+ (function ($) {
1556
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1557
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1558
+ return new $mol_tree2(String(json), '', [], span);
1490
1559
  }
1491
- step() {
1492
- return new Promise(done => {
1493
- const sub = new $mol_wire_pub_sub;
1494
- const prev = sub.track_on();
1495
- sub.track_next(this);
1496
- sub.track_off(prev);
1497
- sub.absorb = () => {
1498
- done(null);
1499
- setTimeout(() => sub.destructor());
1500
- };
1501
- });
1560
+ if (typeof json === 'string') {
1561
+ return $mol_tree2.data(json, [], span);
1502
1562
  }
1503
- destructor() {
1504
- super.destructor();
1505
- if ($mol_owning_check(this, this.cache)) {
1506
- this.cache.destructor();
1563
+ if (typeof json.toJSON === 'function') {
1564
+ return $mol_tree2_from_json(json.toJSON());
1565
+ }
1566
+ if (Array.isArray(json)) {
1567
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1568
+ return new $mol_tree2('/', '', sub, span);
1569
+ }
1570
+ if (ArrayBuffer.isView(json)) {
1571
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1572
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1573
+ }
1574
+ if (json instanceof Date) {
1575
+ return new $mol_tree2('', json.toISOString(), [], span);
1576
+ }
1577
+ if (json.toString !== Object.prototype.toString) {
1578
+ return $mol_tree2.data(json.toString(), [], span);
1579
+ }
1580
+ if (json instanceof Error) {
1581
+ const { name, message, stack } = json;
1582
+ json = { ...json, name, message, stack };
1583
+ }
1584
+ const sub = [];
1585
+ for (var key in json) {
1586
+ const val = json[key];
1587
+ if (val === undefined)
1588
+ continue;
1589
+ const subsub = $mol_tree2_from_json(val, span);
1590
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1591
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1592
+ }
1593
+ else {
1594
+ sub.push($mol_tree2.data(key, [subsub], span));
1507
1595
  }
1508
1596
  }
1597
+ return new $mol_tree2('*', '', sub, span);
1509
1598
  }
1510
- $.$mol_wire_fiber = $mol_wire_fiber;
1599
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1511
1600
  })($ || ($ = {}));
1512
1601
 
1513
1602
  ;
1514
1603
  "use strict";
1515
1604
  var $;
1516
1605
  (function ($) {
1517
- $.$mol_compare_deep_cache = new WeakMap();
1518
- function $mol_compare_deep(left, right) {
1519
- if (Object.is(left, right))
1520
- return true;
1521
- if (left === null)
1522
- return false;
1523
- if (right === null)
1524
- return false;
1525
- if (typeof left !== 'object')
1526
- return false;
1527
- if (typeof right !== 'object')
1528
- return false;
1529
- const left_proto = Reflect.getPrototypeOf(left);
1530
- const right_proto = Reflect.getPrototypeOf(right);
1531
- if (left_proto !== right_proto)
1532
- return false;
1533
- if (left instanceof Boolean)
1534
- return Object.is(left.valueOf(), right['valueOf']());
1535
- if (left instanceof Number)
1536
- return Object.is(left.valueOf(), right['valueOf']());
1537
- if (left instanceof String)
1538
- return Object.is(left.valueOf(), right['valueOf']());
1539
- if (left instanceof Date)
1540
- return Object.is(left.valueOf(), right['valueOf']());
1541
- if (left instanceof RegExp)
1542
- return left.source === right.source && left.flags === right.flags;
1543
- if (left instanceof Error)
1544
- return left.message === right.message && left.stack === right.stack;
1545
- let left_cache = $.$mol_compare_deep_cache.get(left);
1546
- if (left_cache) {
1547
- const right_cache = left_cache.get(right);
1548
- if (typeof right_cache === 'boolean')
1549
- return right_cache;
1550
- }
1551
- else {
1552
- left_cache = new WeakMap();
1553
- $.$mol_compare_deep_cache.set(left, left_cache);
1554
- }
1555
- left_cache.set(right, true);
1556
- let result;
1557
- try {
1558
- if (!left_proto)
1559
- result = compare_pojo(left, right);
1560
- else if (!Reflect.getPrototypeOf(left_proto))
1561
- result = compare_pojo(left, right);
1562
- else if (Symbol.toPrimitive in left)
1563
- result = compare_primitive(left, right);
1564
- else if (Array.isArray(left))
1565
- result = compare_array(left, right);
1566
- else if (left instanceof Set)
1567
- result = compare_set(left, right);
1568
- else if (left instanceof Map)
1569
- result = compare_map(left, right);
1570
- else if (ArrayBuffer.isView(left))
1571
- result = compare_buffer(left, right);
1572
- else if (Symbol.iterator in left)
1573
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1574
- else
1575
- result = false;
1576
- }
1577
- finally {
1578
- left_cache.set(right, result);
1579
- }
1580
- return result;
1581
- }
1582
- $.$mol_compare_deep = $mol_compare_deep;
1583
- function compare_array(left, right) {
1584
- const len = left.length;
1585
- if (len !== right.length)
1586
- return false;
1587
- for (let i = 0; i < len; ++i) {
1588
- if (!$mol_compare_deep(left[i], right[i]))
1589
- return false;
1590
- }
1591
- return true;
1592
- }
1593
- function compare_buffer(left, right) {
1594
- const len = left.byteLength;
1595
- if (len !== right.byteLength)
1596
- return false;
1597
- if (left instanceof DataView)
1598
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1599
- for (let i = 0; i < len; ++i) {
1600
- if (left[i] !== right[i])
1601
- return false;
1602
- }
1603
- return true;
1604
- }
1605
- function compare_iterator(left, right) {
1606
- while (true) {
1607
- const left_next = left.next();
1608
- const right_next = right.next();
1609
- if (left_next.done !== right_next.done)
1610
- return false;
1611
- if (left_next.done)
1612
- break;
1613
- if (!$mol_compare_deep(left_next.value, right_next.value))
1614
- return false;
1615
- }
1616
- return true;
1617
- }
1618
- function compare_set(left, right) {
1619
- if (left.size !== right.size)
1620
- return false;
1621
- return compare_iterator(left.values(), right.values());
1622
- }
1623
- function compare_map(left, right) {
1624
- if (left.size !== right.size)
1625
- return false;
1626
- return compare_iterator(left.keys(), right.keys())
1627
- && compare_iterator(left.values(), right.values());
1628
- }
1629
- function compare_pojo(left, right) {
1630
- const left_keys = Object.getOwnPropertyNames(left);
1631
- const right_keys = Object.getOwnPropertyNames(right);
1632
- if (!compare_array(left_keys, right_keys))
1633
- return false;
1634
- for (let key of left_keys) {
1635
- if (!$mol_compare_deep(left[key], right[key]))
1636
- return false;
1637
- }
1638
- const left_syms = Object.getOwnPropertySymbols(left);
1639
- const right_syms = Object.getOwnPropertySymbols(right);
1640
- if (!compare_array(left_syms, right_syms))
1641
- return false;
1642
- for (let key of left_syms) {
1643
- if (!$mol_compare_deep(left[key], right[key]))
1644
- return false;
1606
+ class $mol_term_color {
1607
+ static reset = this.ansi(0, 0);
1608
+ static bold = this.ansi(1, 22);
1609
+ static italic = this.ansi(3, 23);
1610
+ static underline = this.ansi(4, 24);
1611
+ static inverse = this.ansi(7, 27);
1612
+ static hidden = this.ansi(8, 28);
1613
+ static strike = this.ansi(9, 29);
1614
+ static gray = this.ansi(90, 39);
1615
+ static red = this.ansi(91, 39);
1616
+ static green = this.ansi(92, 39);
1617
+ static yellow = this.ansi(93, 39);
1618
+ static blue = this.ansi(94, 39);
1619
+ static magenta = this.ansi(95, 39);
1620
+ static cyan = this.ansi(96, 39);
1621
+ static Gray = (str) => this.inverse(this.gray(str));
1622
+ static Red = (str) => this.inverse(this.red(str));
1623
+ static Green = (str) => this.inverse(this.green(str));
1624
+ static Yellow = (str) => this.inverse(this.yellow(str));
1625
+ static Blue = (str) => this.inverse(this.blue(str));
1626
+ static Magenta = (str) => this.inverse(this.magenta(str));
1627
+ static Cyan = (str) => this.inverse(this.cyan(str));
1628
+ static ansi(open, close) {
1629
+ if (typeof process === 'undefined')
1630
+ return String;
1631
+ if (!process.stdout.isTTY)
1632
+ return String;
1633
+ const prefix = `\x1b[${open}m`;
1634
+ const postfix = `\x1b[${close}m`;
1635
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1636
+ return function colorer(str) {
1637
+ str = String(str);
1638
+ if (str === '')
1639
+ return str;
1640
+ const suffix = str.replace(suffix_regexp, prefix);
1641
+ return prefix + suffix + postfix;
1642
+ };
1645
1643
  }
1646
- return true;
1647
1644
  }
1648
- function compare_primitive(left, right) {
1649
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1645
+ $.$mol_term_color = $mol_term_color;
1646
+ })($ || ($ = {}));
1647
+
1648
+ ;
1649
+ "use strict";
1650
+ var $;
1651
+ (function ($) {
1652
+ function $mol_log3_node_make(level, output, type, color) {
1653
+ return function $mol_log3_logger(event) {
1654
+ if (!event.time)
1655
+ event = { time: new Date().toISOString(), ...event };
1656
+ let tree = this.$mol_tree2_from_json(event);
1657
+ tree = tree.struct(type, tree.kids);
1658
+ let str = color(tree.toString());
1659
+ this.console[level](str);
1660
+ const self = this;
1661
+ return () => self.console.groupEnd();
1662
+ };
1650
1663
  }
1664
+ $.$mol_log3_node_make = $mol_log3_node_make;
1665
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1666
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1667
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1668
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1669
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1670
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1651
1671
  })($ || ($ = {}));
1652
1672
 
1653
1673
  ;
@@ -1766,97 +1786,115 @@ var $;
1766
1786
  class $mol_run_error extends $mol_error_mix {
1767
1787
  }
1768
1788
  $.$mol_run_error = $mol_run_error;
1769
- const child_process = $node['child_process'];
1770
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
1771
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
1772
- function $mol_run_async({ dir, timeout, command, env }) {
1773
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
1774
- const [app, ...args] = args_raw;
1775
- if (!env?.MOL_RUN_ASYNC) {
1776
- this.$mol_log3_come({
1777
- place: '$mol_run_sync',
1789
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
1790
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
1791
+ class $mol_run extends $mol_object {
1792
+ static async_enabled() {
1793
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
1794
+ }
1795
+ static spawn(options) {
1796
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
1797
+ const env = options.env ?? this.$.$mol_env();
1798
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
1799
+ }
1800
+ static spawn_async({ dir, sync, timeout, command, env }) {
1801
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1802
+ const [app, ...args] = args_raw;
1803
+ const opts = { shell: true, cwd: dir, env };
1804
+ const log_object = {
1805
+ place: `${this}.spawn()`,
1778
1806
  message: 'Run',
1779
1807
  command: args_raw.join(' '),
1780
1808
  dir: $node.path.relative('', dir),
1809
+ };
1810
+ if (sync) {
1811
+ this.$.$mol_log3_come({
1812
+ hint: 'Run inside fiber',
1813
+ ...log_object
1814
+ });
1815
+ let error;
1816
+ let res;
1817
+ try {
1818
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
1819
+ error = res.error;
1820
+ }
1821
+ catch (err) {
1822
+ error = err;
1823
+ }
1824
+ if (!res || error || res.status) {
1825
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
1826
+ }
1827
+ return res;
1828
+ }
1829
+ let sub;
1830
+ try {
1831
+ sub = this.$.$mol_run_spawn(app, args, {
1832
+ ...opts,
1833
+ stdio: ['pipe', 'inherit', 'inherit'],
1834
+ });
1835
+ }
1836
+ catch (error) {
1837
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
1838
+ }
1839
+ const pid = sub.pid ?? 0;
1840
+ this.$.$mol_log3_come({
1841
+ ...log_object,
1842
+ pid,
1781
1843
  });
1782
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
1783
- if (res.status)
1784
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
1785
- return res;
1786
- }
1787
- const sub = this.$mol_run_spawn(app, args, {
1788
- shell: true,
1789
- cwd: dir,
1790
- env
1791
- });
1792
- this.$mol_log3_come({
1793
- place: '$mol_run_async',
1794
- pid: sub.pid,
1795
- message: 'Run',
1796
- command: args_raw.join(' '),
1797
- dir: $node.path.relative('', dir),
1798
- });
1799
- let killed = false;
1800
- let timer;
1801
- const std_data = [];
1802
- const error_data = [];
1803
- const add = (std_chunk, error_chunk) => {
1804
- if (std_chunk)
1805
- std_data.push(std_chunk);
1806
- if (error_chunk)
1807
- error_data.push(error_chunk);
1808
- if (!timeout)
1809
- return;
1810
- clearTimeout(timer);
1811
- timer = setTimeout(() => {
1812
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
1813
- killed = true;
1814
- add();
1815
- sub.kill(signal);
1816
- }, timeout);
1817
- };
1818
- add();
1819
- sub.stdout?.on('data', data => add(data));
1820
- sub.stderr?.on('data', data => add(undefined, data));
1821
- const promise = new Promise((done, fail) => {
1822
- const close = (error, status = null, signal = null) => {
1823
- if (!timer && timeout)
1844
+ let timeout_kill = false;
1845
+ let timer;
1846
+ const std_data = [];
1847
+ const error_data = [];
1848
+ const add = (std_chunk, error_chunk) => {
1849
+ if (std_chunk)
1850
+ std_data.push(std_chunk);
1851
+ if (error_chunk)
1852
+ error_data.push(error_chunk);
1853
+ if (!timeout)
1824
1854
  return;
1825
1855
  clearTimeout(timer);
1826
- timer = undefined;
1827
- const res = {
1828
- pid: sub.pid,
1829
- status,
1830
- signal,
1831
- get stdout() { return Buffer.concat(std_data); },
1832
- get stderr() { return Buffer.concat(error_data); }
1833
- };
1834
- this.$mol_log3_done({
1835
- place: '$mol_run_async',
1836
- pid: sub.pid,
1837
- message: 'Run',
1838
- status,
1839
- command: args_raw.join(' '),
1840
- dir: $node.path.relative('', dir),
1841
- });
1842
- if (error || status || killed)
1843
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1844
- done(res);
1856
+ timer = setTimeout(() => {
1857
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
1858
+ timeout_kill = true;
1859
+ add();
1860
+ sub.kill(signal);
1861
+ }, timeout);
1845
1862
  };
1846
- sub.on('disconnect', () => close(new Error('Disconnected')));
1847
- sub.on('error', err => close(err));
1848
- sub.on('exit', (status, signal) => close(null, status, signal));
1849
- });
1850
- return Object.assign(promise, { destructor: () => {
1851
- clearTimeout(timer);
1852
- sub.kill('SIGKILL');
1853
- } });
1854
- }
1855
- $.$mol_run_async = $mol_run_async;
1856
- function $mol_run(options) {
1857
- if (!options.env)
1858
- options = { ...options, env: this.$mol_env() };
1859
- return $mol_wire_sync(this).$mol_run_async(options);
1863
+ add();
1864
+ sub.stdout?.on('data', data => add(data));
1865
+ sub.stderr?.on('data', data => add(undefined, data));
1866
+ const result_promise = new Promise((done, fail) => {
1867
+ const close = (error, status = null, signal = null) => {
1868
+ if (!timer && timeout)
1869
+ return;
1870
+ clearTimeout(timer);
1871
+ timer = undefined;
1872
+ const res = {
1873
+ pid,
1874
+ signal,
1875
+ get stdout() { return Buffer.concat(std_data); },
1876
+ get stderr() { return Buffer.concat(error_data); }
1877
+ };
1878
+ if (error || status || timeout_kill)
1879
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
1880
+ this.$.$mol_log3_done({
1881
+ ...log_object,
1882
+ pid,
1883
+ });
1884
+ done(res);
1885
+ };
1886
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1887
+ sub.on('error', err => close(err));
1888
+ sub.on('exit', (status, signal) => close(null, status, signal));
1889
+ });
1890
+ return Object.assign(result_promise, { destructor: () => {
1891
+ clearTimeout(timer);
1892
+ sub.kill('SIGKILL');
1893
+ } });
1894
+ }
1895
+ static error_message(res) {
1896
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
1897
+ }
1860
1898
  }
1861
1899
  $.$mol_run = $mol_run;
1862
1900
  })($ || ($ = {}));
@@ -1866,7 +1904,7 @@ var $;
1866
1904
  var $;
1867
1905
  (function ($) {
1868
1906
  function $mol_exec(dir, command, ...args) {
1869
- return this.$mol_run({ command: [command, ...args], dir });
1907
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
1870
1908
  }
1871
1909
  $.$mol_exec = $mol_exec;
1872
1910
  })($ || ($ = {}));
@@ -2783,28 +2821,8 @@ var $;
2783
2821
  "use strict";
2784
2822
  var $;
2785
2823
  (function ($) {
2786
- $.$mol_mem = $mol_wire_solo;
2787
- $.$mol_mem_key = $mol_wire_plex;
2788
- })($ || ($ = {}));
2789
-
2790
- ;
2791
- "use strict";
2792
- var $;
2793
- (function ($_1) {
2794
- let $$;
2795
- (function ($$) {
2796
- let $;
2797
- })($$ = $_1.$$ || ($_1.$$ = {}));
2798
- $_1.$mol_object_field = Symbol('$mol_object_field');
2799
- class $mol_object extends $mol_object2 {
2800
- static make(config) {
2801
- return super.create(obj => {
2802
- for (let key in config)
2803
- obj[key] = config[key];
2804
- });
2805
- }
2806
- }
2807
- $_1.$mol_object = $mol_object;
2824
+ $.$mol_mem = $mol_wire_solo;
2825
+ $.$mol_mem_key = $mol_wire_plex;
2808
2826
  })($ || ($ = {}));
2809
2827
 
2810
2828
  ;
@@ -2981,12 +2999,185 @@ var $;
2981
2999
  "use strict";
2982
3000
  var $;
2983
3001
  (function ($) {
2984
- class $mol_file_not_found extends Error {
3002
+ function $mol_const(value) {
3003
+ const getter = (() => value);
3004
+ getter['()'] = value;
3005
+ getter[Symbol.toStringTag] = value;
3006
+ getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
3007
+ return getter;
3008
+ }
3009
+ $.$mol_const = $mol_const;
3010
+ })($ || ($ = {}));
3011
+
3012
+ ;
3013
+ "use strict";
3014
+ var $;
3015
+ (function ($) {
3016
+ $.$mol_action = $mol_wire_method;
3017
+ })($ || ($ = {}));
3018
+
3019
+ ;
3020
+ "use strict";
3021
+ var $;
3022
+ (function ($) {
3023
+ function $mol_wire_async(obj) {
3024
+ let fiber;
3025
+ const temp = $mol_wire_task.getter(obj);
3026
+ return new Proxy(obj, {
3027
+ get(obj, field) {
3028
+ const val = obj[field];
3029
+ if (typeof val !== 'function')
3030
+ return val;
3031
+ let fiber;
3032
+ const temp = $mol_wire_task.getter(val);
3033
+ return function $mol_wire_async(...args) {
3034
+ fiber?.destructor();
3035
+ fiber = temp(obj, args);
3036
+ return fiber.async();
3037
+ };
3038
+ },
3039
+ apply(obj, self, args) {
3040
+ fiber?.destructor();
3041
+ fiber = temp(self, args);
3042
+ return fiber.async();
3043
+ },
3044
+ });
3045
+ }
3046
+ $.$mol_wire_async = $mol_wire_async;
3047
+ })($ || ($ = {}));
3048
+
3049
+ ;
3050
+ "use strict";
3051
+ var $;
3052
+ (function ($) {
3053
+ class $mol_lock extends $mol_object {
3054
+ promise = null;
3055
+ async wait() {
3056
+ let next = () => { };
3057
+ let destructed = false;
3058
+ const task = $mol_wire_auto();
3059
+ if (!task)
3060
+ return next;
3061
+ const destructor = task.destructor.bind(task);
3062
+ task.destructor = () => {
3063
+ destructor();
3064
+ destructed = true;
3065
+ next();
3066
+ };
3067
+ let promise;
3068
+ do {
3069
+ promise = this.promise;
3070
+ await promise;
3071
+ if (destructed)
3072
+ return next;
3073
+ } while (promise !== this.promise);
3074
+ this.promise = new Promise(done => { next = done; });
3075
+ return next;
3076
+ }
3077
+ grab() { return $mol_wire_sync(this).wait(); }
3078
+ }
3079
+ $.$mol_lock = $mol_lock;
3080
+ })($ || ($ = {}));
3081
+
3082
+ ;
3083
+ "use strict";
3084
+ var $;
3085
+ (function ($) {
3086
+ function $mol_compare_array(a, b) {
3087
+ if (a === b)
3088
+ return true;
3089
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
3090
+ return false;
3091
+ if (a.length !== b.length)
3092
+ return false;
3093
+ for (let i = 0; i < a.length; i++)
3094
+ if (a[i] !== b[i])
3095
+ return false;
3096
+ return true;
3097
+ }
3098
+ $.$mol_compare_array = $mol_compare_array;
3099
+ })($ || ($ = {}));
3100
+
3101
+ ;
3102
+ "use strict";
3103
+ var $;
3104
+ (function ($) {
3105
+ class $mol_file_transaction extends $mol_object {
3106
+ path() { return ''; }
3107
+ modes() { return []; }
3108
+ write(options) {
3109
+ return 0;
3110
+ }
3111
+ read() {
3112
+ return new Uint8Array();
3113
+ }
3114
+ truncate(size) { }
3115
+ close() { }
3116
+ destructor() {
3117
+ this.close();
3118
+ }
3119
+ }
3120
+ $.$mol_file_transaction = $mol_file_transaction;
3121
+ })($ || ($ = {}));
3122
+
3123
+ ;
3124
+ "use strict";
3125
+ var $;
3126
+ (function ($) {
3127
+ let file_modes;
3128
+ (function (file_modes) {
3129
+ file_modes[file_modes["create"] = $node.fs.constants.O_CREAT] = "create";
3130
+ file_modes[file_modes["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
3131
+ file_modes[file_modes["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
3132
+ file_modes[file_modes["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
3133
+ file_modes[file_modes["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
3134
+ file_modes[file_modes["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
3135
+ file_modes[file_modes["append"] = $node.fs.constants.O_APPEND] = "append";
3136
+ })(file_modes || (file_modes = {}));
3137
+ function mode_mask(modes) {
3138
+ return modes.reduce((res, mode) => res | file_modes[mode], 0);
2985
3139
  }
2986
- $.$mol_file_not_found = $mol_file_not_found;
2987
- class $mol_file extends $mol_object {
3140
+ class $mol_file_transaction_node extends $mol_file_transaction {
3141
+ descr() {
3142
+ $mol_wire_solid();
3143
+ return $node.fs.openSync(this.path(), mode_mask(this.modes()));
3144
+ }
3145
+ write({ buffer, offset = 0, length, position = null }) {
3146
+ if (Array.isArray(buffer)) {
3147
+ return $node.fs.writevSync(this.descr(), buffer, position ?? undefined);
3148
+ }
3149
+ if (typeof buffer === 'string') {
3150
+ return $node.fs.writeSync(this.descr(), buffer, position);
3151
+ }
3152
+ length = length ?? buffer.byteLength;
3153
+ return $node.fs.writeSync(this.descr(), buffer, offset, length, position);
3154
+ }
3155
+ truncate(size) {
3156
+ $node.fs.ftruncateSync(this.descr());
3157
+ }
3158
+ read() {
3159
+ return $mol_file_node_buffer_normalize($node.fs.readFileSync(this.descr()));
3160
+ }
3161
+ close() {
3162
+ $node.fs.closeSync(this.descr());
3163
+ }
3164
+ }
3165
+ __decorate([
3166
+ $mol_mem
3167
+ ], $mol_file_transaction_node.prototype, "descr", null);
3168
+ $.$mol_file_transaction_node = $mol_file_transaction_node;
3169
+ $.$mol_file_transaction = $mol_file_transaction_node;
3170
+ })($ || ($ = {}));
3171
+
3172
+ ;
3173
+ "use strict";
3174
+ var $;
3175
+ (function ($) {
3176
+ class $mol_file_base extends $mol_object {
2988
3177
  static absolute(path) {
2989
- throw new Error('Not implemented yet');
3178
+ return this.make({
3179
+ path: $mol_const(path)
3180
+ });
2990
3181
  }
2991
3182
  static relative(path) {
2992
3183
  throw new Error('Not implemented yet');
@@ -2998,27 +3189,164 @@ var $;
2998
3189
  parent() {
2999
3190
  return this.resolve('..');
3000
3191
  }
3001
- reset() {
3002
- try {
3003
- this.stat(null);
3192
+ exists_cut() { return this.exists(); }
3193
+ root() {
3194
+ const path = this.path();
3195
+ const base = this.constructor.base;
3196
+ return base.startsWith(path) || this == this.parent();
3197
+ }
3198
+ stat(next, virt) {
3199
+ const path = this.path();
3200
+ const parent = this.parent();
3201
+ if (!this.root()) {
3202
+ parent.version();
3004
3203
  }
3005
- catch (error) {
3006
- if (error instanceof $mol_file_not_found)
3204
+ parent.watcher();
3205
+ if (virt)
3206
+ return next ?? null;
3207
+ return next ?? this.info(path);
3208
+ }
3209
+ static changed = new Set;
3210
+ static frame = null;
3211
+ static changed_add(type, path) {
3212
+ if (/([\/\\]\.|___$)/.test(path))
3213
+ return;
3214
+ const file = this.relative(path.at(-1) === '/' ? path.slice(0, -1) : path);
3215
+ this.changed.add(file);
3216
+ if (!this.watching)
3217
+ return;
3218
+ this.frame?.destructor();
3219
+ this.frame = new this.$.$mol_after_timeout(this.watch_debounce(), () => {
3220
+ if (!this.watching)
3007
3221
  return;
3008
- return $mol_fail_hidden(error);
3222
+ this.watching = false;
3223
+ $mol_wire_async(this).flush();
3224
+ });
3225
+ }
3226
+ static watch_debounce() { return 500; }
3227
+ static flush() {
3228
+ for (const file of this.changed) {
3229
+ const parent = file.parent();
3230
+ try {
3231
+ if ($mol_wire_probe(() => parent.sub()))
3232
+ parent.sub(null);
3233
+ file.reset();
3234
+ }
3235
+ catch (error) {
3236
+ if ($mol_fail_catch(error))
3237
+ $mol_fail_log(error);
3238
+ }
3239
+ }
3240
+ this.changed.clear();
3241
+ this.watching = true;
3242
+ }
3243
+ static watching = true;
3244
+ static lock = new $mol_lock;
3245
+ static watch_off(path) {
3246
+ this.watching = false;
3247
+ this.flush();
3248
+ this.watching = false;
3249
+ this.changed.add(this.absolute(path));
3250
+ }
3251
+ static unwatched(side_effect, affected_dir) {
3252
+ const unlock = this.lock.grab();
3253
+ this.watch_off(affected_dir);
3254
+ try {
3255
+ const result = side_effect();
3256
+ this.flush();
3257
+ unlock();
3258
+ return result;
3259
+ }
3260
+ catch (e) {
3261
+ if (!$mol_promise_like(e)) {
3262
+ this.flush();
3263
+ unlock();
3264
+ }
3265
+ $mol_fail_hidden(e);
3009
3266
  }
3010
3267
  }
3268
+ reset() {
3269
+ this.stat(null);
3270
+ }
3271
+ modified() { return this.stat()?.mtime ?? null; }
3011
3272
  version() {
3012
- return this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
3273
+ const next = this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
3274
+ return next;
3275
+ }
3276
+ info(path) { return null; }
3277
+ ensure() { }
3278
+ drop() { }
3279
+ copy(to) { }
3280
+ read() { return new Uint8Array; }
3281
+ write(buffer) { }
3282
+ kids() {
3283
+ return [];
3284
+ }
3285
+ readable(opts) {
3286
+ return new ReadableStream;
3287
+ }
3288
+ writable(opts) {
3289
+ return new WritableStream;
3290
+ }
3291
+ buffer(next) {
3292
+ let readed = new Uint8Array();
3293
+ if (next === undefined) {
3294
+ if (this.version())
3295
+ readed = this.read();
3296
+ }
3297
+ const prev = $mol_mem_cached(() => this.buffer());
3298
+ const changed = prev === undefined || !$mol_compare_array(prev, next ?? readed);
3299
+ if (prev !== undefined && changed) {
3300
+ this.$.$mol_log3_rise({
3301
+ place: `$mol_file_node.buffer()`,
3302
+ message: 'Changed',
3303
+ path: this.relate(),
3304
+ });
3305
+ }
3306
+ if (next === undefined)
3307
+ return changed ? readed : prev;
3308
+ if (!changed && this.exists())
3309
+ return prev;
3310
+ this.parent().exists(true);
3311
+ this.stat(this.stat_make(next.length), 'virt');
3312
+ this.write(next);
3313
+ return next;
3314
+ }
3315
+ stat_make(size) {
3316
+ const now = new Date();
3317
+ return {
3318
+ type: 'file',
3319
+ size,
3320
+ atime: now,
3321
+ mtime: now,
3322
+ ctime: now,
3323
+ };
3324
+ }
3325
+ clone(to) {
3326
+ if (!this.exists())
3327
+ return null;
3328
+ const target = this.constructor.absolute(to);
3329
+ try {
3330
+ this.version();
3331
+ target.parent().exists(true);
3332
+ this.copy(to);
3333
+ target.reset();
3334
+ return target;
3335
+ }
3336
+ catch (error) {
3337
+ if ($mol_fail_catch(error)) {
3338
+ console.error(error);
3339
+ }
3340
+ }
3341
+ return null;
3013
3342
  }
3014
3343
  watcher() {
3015
- console.warn('$mol_file_web.watcher() not implemented');
3016
3344
  return {
3017
3345
  destructor() { }
3018
3346
  };
3019
3347
  }
3020
3348
  exists(next) {
3021
- let exists = Boolean(this.stat());
3349
+ const exists = Boolean(this.stat());
3022
3350
  if (next === undefined)
3023
3351
  return exists;
3024
3352
  if (next === exists)
@@ -3044,26 +3372,40 @@ var $;
3044
3372
  return match ? match[1].substring(1) : '';
3045
3373
  }
3046
3374
  text(next, virt) {
3375
+ if (next !== undefined)
3376
+ this.exists();
3377
+ return this.text_int(next, virt);
3378
+ }
3379
+ text_int(next, virt) {
3047
3380
  if (virt) {
3048
- const now = new Date;
3049
- this.stat({
3050
- type: 'file',
3051
- size: 0,
3052
- atime: now,
3053
- mtime: now,
3054
- ctime: now,
3055
- }, 'virt');
3381
+ this.stat(this.stat_make(0), 'virt');
3056
3382
  return next;
3057
3383
  }
3058
3384
  if (next === undefined) {
3059
- return $mol_charset_decode(this.buffer(undefined));
3385
+ return $mol_charset_decode(this.buffer());
3060
3386
  }
3061
3387
  else {
3062
- const buffer = next === undefined ? undefined : $mol_charset_encode(next);
3388
+ const buffer = $mol_charset_encode(next);
3063
3389
  this.buffer(buffer);
3064
3390
  return next;
3065
3391
  }
3066
3392
  }
3393
+ sub(reset) {
3394
+ if (!this.exists())
3395
+ return [];
3396
+ if (this.type() !== 'dir')
3397
+ return [];
3398
+ this.version();
3399
+ return this.kids().filter(file => file.exists());
3400
+ }
3401
+ resolve(path) {
3402
+ throw new Error('implement');
3403
+ }
3404
+ relate(base = this.constructor.relative('.')) {
3405
+ const base_path = base.path();
3406
+ const path = this.path();
3407
+ return path.startsWith(base_path) ? path.slice(base_path.length) : path;
3408
+ }
3067
3409
  find(include, exclude) {
3068
3410
  const found = [];
3069
3411
  const sub = this.sub();
@@ -3087,63 +3429,80 @@ var $;
3087
3429
  default: return 0;
3088
3430
  }
3089
3431
  }
3090
- open(...modes) {
3091
- return 0;
3092
- }
3093
3432
  toJSON() {
3094
3433
  return this.path();
3095
3434
  }
3435
+ open(...modes) {
3436
+ return this.$.$mol_file_transaction.make({
3437
+ path: () => this.path(),
3438
+ modes: () => modes
3439
+ });
3440
+ }
3096
3441
  }
3442
+ __decorate([
3443
+ $mol_action
3444
+ ], $mol_file_base.prototype, "exists_cut", null);
3445
+ __decorate([
3446
+ $mol_mem
3447
+ ], $mol_file_base.prototype, "stat", null);
3097
3448
  __decorate([
3098
3449
  $mol_mem
3099
- ], $mol_file.prototype, "exists", null);
3450
+ ], $mol_file_base.prototype, "modified", null);
3100
3451
  __decorate([
3101
3452
  $mol_mem
3102
- ], $mol_file.prototype, "text", null);
3453
+ ], $mol_file_base.prototype, "version", null);
3103
3454
  __decorate([
3104
3455
  $mol_mem_key
3105
- ], $mol_file, "absolute", null);
3106
- $.$mol_file = $mol_file;
3107
- })($ || ($ = {}));
3108
-
3109
- ;
3110
- "use strict";
3111
- var $;
3112
- (function ($) {
3113
- function $mol_const(value) {
3114
- const getter = (() => value);
3115
- getter['()'] = value;
3116
- getter[Symbol.toStringTag] = value;
3117
- getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
3118
- return getter;
3119
- }
3120
- $.$mol_const = $mol_const;
3121
- })($ || ($ = {}));
3122
-
3123
- ;
3124
- "use strict";
3125
- var $;
3126
- (function ($) {
3127
- $.$mol_action = $mol_wire_method;
3456
+ ], $mol_file_base.prototype, "readable", null);
3457
+ __decorate([
3458
+ $mol_mem_key
3459
+ ], $mol_file_base.prototype, "writable", null);
3460
+ __decorate([
3461
+ $mol_mem
3462
+ ], $mol_file_base.prototype, "buffer", null);
3463
+ __decorate([
3464
+ $mol_action
3465
+ ], $mol_file_base.prototype, "stat_make", null);
3466
+ __decorate([
3467
+ $mol_mem_key
3468
+ ], $mol_file_base.prototype, "clone", null);
3469
+ __decorate([
3470
+ $mol_mem
3471
+ ], $mol_file_base.prototype, "exists", null);
3472
+ __decorate([
3473
+ $mol_mem
3474
+ ], $mol_file_base.prototype, "type", null);
3475
+ __decorate([
3476
+ $mol_mem
3477
+ ], $mol_file_base.prototype, "text_int", null);
3478
+ __decorate([
3479
+ $mol_mem
3480
+ ], $mol_file_base.prototype, "sub", null);
3481
+ __decorate([
3482
+ $mol_mem
3483
+ ], $mol_file_base.prototype, "size", null);
3484
+ __decorate([
3485
+ $mol_action
3486
+ ], $mol_file_base.prototype, "open", null);
3487
+ __decorate([
3488
+ $mol_mem_key
3489
+ ], $mol_file_base, "absolute", null);
3490
+ __decorate([
3491
+ $mol_action
3492
+ ], $mol_file_base, "flush", null);
3493
+ __decorate([
3494
+ $mol_action
3495
+ ], $mol_file_base, "watch_off", null);
3496
+ $.$mol_file_base = $mol_file_base;
3128
3497
  })($ || ($ = {}));
3129
3498
 
3130
3499
  ;
3131
3500
  "use strict";
3132
3501
  var $;
3133
3502
  (function ($) {
3134
- function $mol_compare_array(a, b) {
3135
- if (a === b)
3136
- return true;
3137
- if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
3138
- return false;
3139
- if (a.length !== b.length)
3140
- return false;
3141
- for (let i = 0; i < a.length; i++)
3142
- if (a[i] !== b[i])
3143
- return false;
3144
- return true;
3503
+ class $mol_file extends $mol_file_base {
3145
3504
  }
3146
- $.$mol_compare_array = $mol_compare_array;
3505
+ $.$mol_file = $mol_file;
3147
3506
  })($ || ($ = {}));
3148
3507
 
3149
3508
  ;
@@ -3170,186 +3529,183 @@ var $;
3170
3529
  ctime: stat.ctime
3171
3530
  };
3172
3531
  }
3173
- function buffer_normalize(buf) {
3532
+ function $mol_file_node_buffer_normalize(buf) {
3174
3533
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
3175
3534
  }
3176
- let $mol_file_mode_open;
3177
- (function ($mol_file_mode_open) {
3178
- $mol_file_mode_open[$mol_file_mode_open["create"] = $node.fs.constants.O_CREAT] = "create";
3179
- $mol_file_mode_open[$mol_file_mode_open["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
3180
- $mol_file_mode_open[$mol_file_mode_open["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
3181
- $mol_file_mode_open[$mol_file_mode_open["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
3182
- $mol_file_mode_open[$mol_file_mode_open["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
3183
- $mol_file_mode_open[$mol_file_mode_open["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
3184
- $mol_file_mode_open[$mol_file_mode_open["append"] = $node.fs.constants.O_APPEND] = "append";
3185
- })($mol_file_mode_open = $.$mol_file_mode_open || ($.$mol_file_mode_open = {}));
3535
+ $.$mol_file_node_buffer_normalize = $mol_file_node_buffer_normalize;
3186
3536
  class $mol_file_node extends $mol_file {
3187
- static absolute(path) {
3188
- return this.make({
3189
- path: $mol_const(path)
3190
- });
3191
- }
3192
3537
  static relative(path) {
3193
3538
  return this.absolute($node.path.resolve(this.base, path).replace(/\\/g, '/'));
3194
3539
  }
3195
- watcher() {
3196
- if (/\/\./.test(this.path()))
3197
- return { destructor() { } };
3198
- const watcher = $node.chokidar.watch(this.path(), {
3199
- persistent: true,
3200
- ignored: path => /([\/\\]\.|___$)/.test(path),
3201
- depth: 0,
3202
- ignoreInitial: true,
3203
- awaitWriteFinish: {
3204
- stabilityThreshold: 100,
3205
- },
3206
- });
3207
- watcher
3208
- .on('all', (type, path) => {
3209
- const file = $mol_file.relative(path.replace(/\\/g, '/'));
3210
- file.reset();
3211
- if (type === 'change') {
3212
- this.stat(null);
3213
- }
3214
- else {
3215
- file.parent().reset();
3540
+ watcher(reset) {
3541
+ const path = this.path();
3542
+ const root = this.root();
3543
+ if (!root && !this.exists())
3544
+ return super.watcher();
3545
+ let watcher;
3546
+ try {
3547
+ watcher = $node.fs.watch(path);
3548
+ }
3549
+ catch (error) {
3550
+ if (!(error instanceof Error))
3551
+ error = new Error('Unknown watch error', { cause: error });
3552
+ error.message += '\n' + path;
3553
+ if (root || error.code !== 'ENOENT') {
3554
+ this.$.$mol_fail_log(error);
3216
3555
  }
3217
- })
3218
- .on('error', $mol_fail_log);
3556
+ return super.watcher();
3557
+ }
3558
+ watcher.on('change', (type, name) => {
3559
+ if (!name)
3560
+ return;
3561
+ const path = $node.path.join(this.path(), name.toString());
3562
+ this.constructor.changed_add(type, path);
3563
+ });
3564
+ watcher.on('error', e => this.$.$mol_fail_log(e));
3565
+ let destructed = false;
3566
+ watcher.on('close', () => {
3567
+ if (!destructed)
3568
+ setTimeout(() => $mol_wire_async(this).watcher(null), 500);
3569
+ });
3219
3570
  return {
3220
3571
  destructor() {
3572
+ destructed = true;
3221
3573
  watcher.close();
3222
3574
  }
3223
3575
  };
3224
3576
  }
3225
- stat(next, virt) {
3226
- let stat = next;
3227
- const path = this.path();
3228
- this.parent().watcher();
3229
- if (virt)
3230
- return next;
3577
+ info(path) {
3231
3578
  try {
3232
- stat = next ?? stat_convert($node.fs.statSync(path, { throwIfNoEntry: false }));
3579
+ return stat_convert($node.fs.statSync(path));
3233
3580
  }
3234
3581
  catch (error) {
3235
- if (error.code === 'ENOENT')
3236
- error = new $mol_file_not_found(`File not found`);
3237
- error.message += '\n' + path;
3238
- return this.$.$mol_fail_hidden(error);
3582
+ if (this.$.$mol_fail_catch(error)) {
3583
+ if (error.code === 'ENOENT')
3584
+ return null;
3585
+ error.message += '\n' + path;
3586
+ this.$.$mol_fail_hidden(error);
3587
+ }
3239
3588
  }
3240
- return stat;
3589
+ return null;
3241
3590
  }
3242
3591
  ensure() {
3243
3592
  const path = this.path();
3244
3593
  try {
3245
- $node.fs.mkdirSync(path);
3594
+ $node.fs.mkdirSync(path, { recursive: true });
3595
+ return null;
3246
3596
  }
3247
3597
  catch (e) {
3248
- e.message += '\n' + path;
3249
- this.$.$mol_fail_hidden(e);
3598
+ if (this.$.$mol_fail_catch(e)) {
3599
+ if (e.code === 'EEXIST')
3600
+ return null;
3601
+ e.message += '\n' + path;
3602
+ this.$.$mol_fail_hidden(e);
3603
+ }
3250
3604
  }
3251
3605
  }
3606
+ copy(to) {
3607
+ $node.fs.copyFileSync(this.path(), to);
3608
+ }
3252
3609
  drop() {
3253
3610
  $node.fs.unlinkSync(this.path());
3254
3611
  }
3255
- buffer(next) {
3612
+ read() {
3256
3613
  const path = this.path();
3257
- if (next === undefined) {
3258
- if (!this.stat())
3259
- return new Uint8Array;
3260
- try {
3261
- const prev = $mol_mem_cached(() => this.buffer());
3262
- next = buffer_normalize($node.fs.readFileSync(path));
3263
- if (prev !== undefined && !$mol_compare_array(prev, next)) {
3264
- this.$.$mol_log3_rise({
3265
- place: `$mol_file_node..buffer()`,
3266
- message: 'Changed',
3267
- path: this.relate(),
3268
- });
3269
- }
3270
- return next;
3271
- }
3272
- catch (error) {
3614
+ try {
3615
+ return $mol_file_node_buffer_normalize($node.fs.readFileSync(path));
3616
+ }
3617
+ catch (error) {
3618
+ if (!$mol_promise_like(error)) {
3273
3619
  error.message += '\n' + path;
3274
- return this.$.$mol_fail_hidden(error);
3275
3620
  }
3621
+ $mol_fail_hidden(error);
3276
3622
  }
3277
- this.parent().exists(true);
3278
- const now = new Date;
3279
- this.stat({
3280
- type: 'file',
3281
- size: next.length,
3282
- atime: now,
3283
- mtime: now,
3284
- ctime: now,
3285
- }, 'virt');
3623
+ }
3624
+ write(buffer) {
3625
+ const path = this.path();
3286
3626
  try {
3287
- $node.fs.writeFileSync(path, next);
3627
+ $node.fs.writeFileSync(path, buffer);
3288
3628
  }
3289
3629
  catch (error) {
3290
- error.message += '\n' + path;
3630
+ if (this.$.$mol_fail_catch(error)) {
3631
+ error.message += '\n' + path;
3632
+ }
3291
3633
  return this.$.$mol_fail_hidden(error);
3292
3634
  }
3293
- return next;
3294
3635
  }
3295
- sub() {
3296
- if (!this.exists())
3297
- return [];
3298
- if (this.type() !== 'dir')
3299
- return [];
3636
+ kids() {
3300
3637
  const path = this.path();
3301
- this.stat();
3302
3638
  try {
3303
- return $node.fs.readdirSync(path)
3639
+ const kids = $node.fs.readdirSync(path)
3304
3640
  .filter(name => !/^\.+$/.test(name))
3305
3641
  .map(name => this.resolve(name));
3642
+ return kids;
3306
3643
  }
3307
3644
  catch (e) {
3308
- e.message += '\n' + path;
3309
- return this.$.$mol_fail_hidden(e);
3645
+ if (this.$.$mol_fail_catch(e)) {
3646
+ if (e.code === 'ENOENT')
3647
+ return [];
3648
+ e.message += '\n' + path;
3649
+ }
3650
+ $mol_fail_hidden(e);
3310
3651
  }
3311
3652
  }
3312
3653
  resolve(path) {
3313
- return this.constructor.relative($node.path.join(this.path(), path));
3654
+ return this.constructor
3655
+ .relative($node.path.join(this.path(), path));
3314
3656
  }
3315
3657
  relate(base = this.constructor.relative('.')) {
3316
3658
  return $node.path.relative(base.path(), this.path()).replace(/\\/g, '/');
3317
3659
  }
3318
- append(next) {
3319
- const path = this.path();
3320
- try {
3321
- $node.fs.appendFileSync(path, next);
3322
- }
3323
- catch (e) {
3324
- e.message += '\n' + path;
3325
- return this.$.$mol_fail_hidden(e);
3326
- }
3327
- }
3328
- open(...modes) {
3329
- return $node.fs.openSync(this.path(), modes.reduce((res, mode) => res | $mol_file_mode_open[mode], 0));
3660
+ readable(opts) {
3661
+ const { Readable } = $node['node:stream'];
3662
+ const stream = $node.fs.createReadStream(this.path(), {
3663
+ flags: 'r',
3664
+ autoClose: true,
3665
+ start: opts?.start,
3666
+ end: opts?.end,
3667
+ encoding: 'binary',
3668
+ });
3669
+ return Readable.toWeb(stream);
3670
+ }
3671
+ writable(opts) {
3672
+ const { Writable } = $node['node:stream'];
3673
+ const stream = $node.fs.createWriteStream(this.path(), {
3674
+ flags: 'w+',
3675
+ autoClose: true,
3676
+ start: opts?.start,
3677
+ encoding: 'binary',
3678
+ });
3679
+ return Writable.toWeb(stream);
3330
3680
  }
3331
3681
  }
3332
3682
  __decorate([
3333
3683
  $mol_mem
3334
3684
  ], $mol_file_node.prototype, "watcher", null);
3335
3685
  __decorate([
3336
- $mol_mem
3337
- ], $mol_file_node.prototype, "stat", null);
3686
+ $mol_action
3687
+ ], $mol_file_node.prototype, "info", null);
3338
3688
  __decorate([
3339
- $mol_mem
3689
+ $mol_action
3340
3690
  ], $mol_file_node.prototype, "ensure", null);
3691
+ __decorate([
3692
+ $mol_action
3693
+ ], $mol_file_node.prototype, "copy", null);
3341
3694
  __decorate([
3342
3695
  $mol_action
3343
3696
  ], $mol_file_node.prototype, "drop", null);
3344
3697
  __decorate([
3345
- $mol_mem
3346
- ], $mol_file_node.prototype, "buffer", null);
3698
+ $mol_action
3699
+ ], $mol_file_node.prototype, "read", null);
3347
3700
  __decorate([
3348
- $mol_mem
3349
- ], $mol_file_node.prototype, "sub", null);
3701
+ $mol_action
3702
+ ], $mol_file_node.prototype, "write", null);
3350
3703
  __decorate([
3351
3704
  $mol_mem_key
3352
- ], $mol_file_node, "absolute", null);
3705
+ ], $mol_file_node.prototype, "readable", null);
3706
+ __decorate([
3707
+ $mol_mem
3708
+ ], $mol_file_node.prototype, "writable", null);
3353
3709
  $.$mol_file_node = $mol_file_node;
3354
3710
  $.$mol_file = $mol_file_node;
3355
3711
  })($ || ($ = {}));
@@ -4436,36 +4792,6 @@ var $;
4436
4792
  ];
4437
4793
  })($ || ($ = {}));
4438
4794
 
4439
- ;
4440
- "use strict";
4441
- var $;
4442
- (function ($) {
4443
- function $mol_wire_async(obj) {
4444
- let fiber;
4445
- const temp = $mol_wire_task.getter(obj);
4446
- return new Proxy(obj, {
4447
- get(obj, field) {
4448
- const val = obj[field];
4449
- if (typeof val !== 'function')
4450
- return val;
4451
- let fiber;
4452
- const temp = $mol_wire_task.getter(val);
4453
- return function $mol_wire_async(...args) {
4454
- fiber?.destructor();
4455
- fiber = temp(obj, args);
4456
- return fiber.async();
4457
- };
4458
- },
4459
- apply(obj, self, args) {
4460
- fiber?.destructor();
4461
- fiber = temp(self, args);
4462
- return fiber.async();
4463
- },
4464
- });
4465
- }
4466
- $.$mol_wire_async = $mol_wire_async;
4467
- })($ || ($ = {}));
4468
-
4469
4795
  ;
4470
4796
  "use strict";
4471
4797
  var $;
@@ -5289,152 +5615,9 @@ var $;
5289
5615
  'FQN of anon function'($) {
5290
5616
  const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
5291
5617
  $mol_assert_equal($$.$mol_func_name_test.name, '');
5292
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
5293
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
5294
- },
5295
- });
5296
- })($ || ($ = {}));
5297
-
5298
- ;
5299
- "use strict";
5300
- var $;
5301
- (function ($) {
5302
- $mol_test({
5303
- 'auto name'() {
5304
- class Invalid extends $mol_error_mix {
5305
- }
5306
- const mix = new Invalid('foo');
5307
- $mol_assert_equal(mix.name, 'Invalid_Error');
5308
- },
5309
- 'simpe mix'() {
5310
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
5311
- $mol_assert_equal(mix.message, 'foo');
5312
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
5313
- },
5314
- 'provide additional info'() {
5315
- class Invalid extends $mol_error_mix {
5316
- }
5317
- 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' }));
5318
- const hints = [];
5319
- if (mix instanceof $mol_error_mix) {
5320
- for (const er of mix.errors) {
5321
- if (er instanceof Invalid) {
5322
- hints.push(er.cause?.hint ?? '');
5323
- }
5324
- }
5325
- }
5326
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
5327
- },
5328
- });
5329
- })($ || ($ = {}));
5330
-
5331
- ;
5332
- "use strict";
5333
- var $;
5334
- (function ($_1) {
5335
- $mol_test_mocks.push($ => {
5336
- $.$mol_log3_come = () => { };
5337
- $.$mol_log3_done = () => { };
5338
- $.$mol_log3_fail = () => { };
5339
- $.$mol_log3_warn = () => { };
5340
- $.$mol_log3_rise = () => { };
5341
- $.$mol_log3_area = () => () => { };
5342
- });
5343
- })($ || ($ = {}));
5344
-
5345
- ;
5346
- "use strict";
5347
-
5348
- ;
5349
- "use strict";
5350
-
5351
- ;
5352
- "use strict";
5353
-
5354
- ;
5355
- "use strict";
5356
-
5357
- ;
5358
- "use strict";
5359
-
5360
- ;
5361
- "use strict";
5362
- var $;
5363
- (function ($_1) {
5364
- $mol_test({
5365
- 'test types'($) {
5366
- class A {
5367
- static a() {
5368
- return Promise.resolve('');
5369
- }
5370
- static b() {
5371
- return $mol_wire_sync(this).a();
5372
- }
5373
- }
5374
- },
5375
- async 'test method from host'($) {
5376
- let count = 0;
5377
- class A {
5378
- static a() {
5379
- return $mol_wire_sync(this).b();
5380
- }
5381
- static b() { return Promise.resolve(++count); }
5382
- }
5383
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
5384
- },
5385
- async 'test function'($) {
5386
- let count = 0;
5387
- class A {
5388
- static a() {
5389
- return $mol_wire_sync(this.b)();
5390
- }
5391
- static b() { return Promise.resolve(++count); }
5392
- }
5393
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
5394
- },
5395
- async 'test construct itself'($) {
5396
- class A {
5397
- static instances = [];
5398
- static a() {
5399
- const a = new ($mol_wire_sync(A))();
5400
- this.instances.push(a);
5401
- $mol_wire_sync(this).b();
5402
- }
5403
- static b() { return Promise.resolve(); }
5404
- }
5405
- await $mol_wire_async(A).a();
5406
- $mol_assert_equal(A.instances.length, 2);
5407
- $mol_assert_equal(A.instances[0] instanceof A);
5408
- $mol_assert_equal(A.instances[0], A.instances[1]);
5409
- }
5410
- });
5411
- })($ || ($ = {}));
5412
-
5413
- ;
5414
- "use strict";
5415
- var $;
5416
- (function ($_1) {
5417
- $mol_test({
5418
- async 'exec timeout auto kill child process'($) {
5419
- let close_mock = () => { };
5420
- const context_mock = $.$mol_ambient({
5421
- $mol_run_spawn: () => ({
5422
- on(name, cb) {
5423
- if (name === 'exit')
5424
- close_mock = cb;
5425
- },
5426
- kill() { close_mock(); }
5427
- })
5428
- });
5429
- let message = '';
5430
- try {
5431
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
5432
- }
5433
- catch (e) {
5434
- message = e.message;
5435
- }
5436
- $mol_assert_equal(message, 'Run error, timeout');
5437
- }
5618
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
5619
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
5620
+ },
5438
5621
  });
5439
5622
  })($ || ($ = {}));
5440
5623
 
@@ -5499,6 +5682,21 @@ var $;
5499
5682
  ;
5500
5683
  "use strict";
5501
5684
 
5685
+ ;
5686
+ "use strict";
5687
+
5688
+ ;
5689
+ "use strict";
5690
+
5691
+ ;
5692
+ "use strict";
5693
+
5694
+ ;
5695
+ "use strict";
5696
+
5697
+ ;
5698
+ "use strict";
5699
+
5502
5700
  ;
5503
5701
  "use strict";
5504
5702
  var $;
@@ -6270,6 +6468,20 @@ var $;
6270
6468
  });
6271
6469
  })($ || ($ = {}));
6272
6470
 
6471
+ ;
6472
+ "use strict";
6473
+ var $;
6474
+ (function ($_1) {
6475
+ $mol_test_mocks.push($ => {
6476
+ $.$mol_log3_come = () => { };
6477
+ $.$mol_log3_done = () => { };
6478
+ $.$mol_log3_fail = () => { };
6479
+ $.$mol_log3_warn = () => { };
6480
+ $.$mol_log3_rise = () => { };
6481
+ $.$mol_log3_area = () => () => { };
6482
+ });
6483
+ })($ || ($ = {}));
6484
+
6273
6485
  ;
6274
6486
  "use strict";
6275
6487
  var $;
@@ -6361,6 +6573,39 @@ var $;
6361
6573
  });
6362
6574
  })($ || ($ = {}));
6363
6575
 
6576
+ ;
6577
+ "use strict";
6578
+ var $;
6579
+ (function ($) {
6580
+ $mol_test({
6581
+ 'auto name'() {
6582
+ class Invalid extends $mol_error_mix {
6583
+ }
6584
+ const mix = new Invalid('foo');
6585
+ $mol_assert_equal(mix.name, 'Invalid_Error');
6586
+ },
6587
+ 'simpe mix'() {
6588
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
6589
+ $mol_assert_equal(mix.message, 'foo');
6590
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
6591
+ },
6592
+ 'provide additional info'() {
6593
+ class Invalid extends $mol_error_mix {
6594
+ }
6595
+ 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' }));
6596
+ const hints = [];
6597
+ if (mix instanceof $mol_error_mix) {
6598
+ for (const er of mix.errors) {
6599
+ if (er instanceof Invalid) {
6600
+ hints.push(er.cause?.hint ?? '');
6601
+ }
6602
+ }
6603
+ }
6604
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
6605
+ },
6606
+ });
6607
+ })($ || ($ = {}));
6608
+
6364
6609
  ;
6365
6610
  "use strict";
6366
6611
  var $;
@@ -6742,6 +6987,112 @@ var $;
6742
6987
  });
6743
6988
  })($ || ($ = {}));
6744
6989
 
6990
+ ;
6991
+ "use strict";
6992
+ var $;
6993
+ (function ($_1) {
6994
+ $mol_test({
6995
+ 'test types'($) {
6996
+ class A {
6997
+ static a() {
6998
+ return '';
6999
+ }
7000
+ static b() {
7001
+ return $mol_wire_async(this).a();
7002
+ }
7003
+ }
7004
+ },
7005
+ async 'Latest method calls wins'($) {
7006
+ class NameLogger extends $mol_object2 {
7007
+ static $ = $;
7008
+ static first = [];
7009
+ static last = [];
7010
+ static send(next) {
7011
+ $mol_wire_sync(this.first).push(next);
7012
+ $$.$mol_wait_timeout(0);
7013
+ this.last.push(next);
7014
+ }
7015
+ }
7016
+ const name = $mol_wire_async(NameLogger).send;
7017
+ name('john');
7018
+ const promise = name('jin');
7019
+ $.$mol_after_mock_warp();
7020
+ await promise;
7021
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
7022
+ $mol_assert_equal(NameLogger.last, ['jin']);
7023
+ },
7024
+ async 'Latest function calls wins'($) {
7025
+ const first = [];
7026
+ const last = [];
7027
+ function send_name(next) {
7028
+ $mol_wire_sync(first).push(next);
7029
+ $$.$mol_wait_timeout(0);
7030
+ last.push(next);
7031
+ }
7032
+ const name = $mol_wire_async(send_name);
7033
+ name('john');
7034
+ const promise = name('jin');
7035
+ $.$mol_after_mock_warp();
7036
+ await promise;
7037
+ $mol_assert_equal(first, ['john', 'jin']);
7038
+ $mol_assert_equal(last, ['jin']);
7039
+ },
7040
+ });
7041
+ })($ || ($ = {}));
7042
+
7043
+ ;
7044
+ "use strict";
7045
+ var $;
7046
+ (function ($_1) {
7047
+ $mol_test({
7048
+ 'test types'($) {
7049
+ class A {
7050
+ static a() {
7051
+ return Promise.resolve('');
7052
+ }
7053
+ static b() {
7054
+ return $mol_wire_sync(this).a();
7055
+ }
7056
+ }
7057
+ },
7058
+ async 'test method from host'($) {
7059
+ let count = 0;
7060
+ class A {
7061
+ static a() {
7062
+ return $mol_wire_sync(this).b();
7063
+ }
7064
+ static b() { return Promise.resolve(++count); }
7065
+ }
7066
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
7067
+ },
7068
+ async 'test function'($) {
7069
+ let count = 0;
7070
+ class A {
7071
+ static a() {
7072
+ return $mol_wire_sync(this.b)();
7073
+ }
7074
+ static b() { return Promise.resolve(++count); }
7075
+ }
7076
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
7077
+ },
7078
+ async 'test construct itself'($) {
7079
+ class A {
7080
+ static instances = [];
7081
+ static a() {
7082
+ const a = new ($mol_wire_sync(A))();
7083
+ this.instances.push(a);
7084
+ $mol_wire_sync(this).b();
7085
+ }
7086
+ static b() { return Promise.resolve(); }
7087
+ }
7088
+ await $mol_wire_async(A).a();
7089
+ $mol_assert_equal(A.instances.length, 2);
7090
+ $mol_assert_equal(A.instances[0] instanceof A);
7091
+ $mol_assert_equal(A.instances[0], A.instances[1]);
7092
+ }
7093
+ });
7094
+ })($ || ($ = {}));
7095
+
6745
7096
  ;
6746
7097
  "use strict";
6747
7098
  var $;
@@ -6817,59 +7168,6 @@ var $;
6817
7168
  })($$ = $_1.$$ || ($_1.$$ = {}));
6818
7169
  })($ || ($ = {}));
6819
7170
 
6820
- ;
6821
- "use strict";
6822
- var $;
6823
- (function ($_1) {
6824
- $mol_test({
6825
- 'test types'($) {
6826
- class A {
6827
- static a() {
6828
- return '';
6829
- }
6830
- static b() {
6831
- return $mol_wire_async(this).a();
6832
- }
6833
- }
6834
- },
6835
- async 'Latest method calls wins'($) {
6836
- class NameLogger extends $mol_object2 {
6837
- static $ = $;
6838
- static first = [];
6839
- static last = [];
6840
- static send(next) {
6841
- $mol_wire_sync(this.first).push(next);
6842
- $$.$mol_wait_timeout(0);
6843
- this.last.push(next);
6844
- }
6845
- }
6846
- const name = $mol_wire_async(NameLogger).send;
6847
- name('john');
6848
- const promise = name('jin');
6849
- $.$mol_after_mock_warp();
6850
- await promise;
6851
- $mol_assert_equal(NameLogger.first, ['john', 'jin']);
6852
- $mol_assert_equal(NameLogger.last, ['jin']);
6853
- },
6854
- async 'Latest function calls wins'($) {
6855
- const first = [];
6856
- const last = [];
6857
- function send_name(next) {
6858
- $mol_wire_sync(first).push(next);
6859
- $$.$mol_wait_timeout(0);
6860
- last.push(next);
6861
- }
6862
- const name = $mol_wire_async(send_name);
6863
- name('john');
6864
- const promise = name('jin');
6865
- $.$mol_after_mock_warp();
6866
- await promise;
6867
- $mol_assert_equal(first, ['john', 'jin']);
6868
- $mol_assert_equal(last, ['jin']);
6869
- },
6870
- });
6871
- })($ || ($ = {}));
6872
-
6873
7171
  ;
6874
7172
  "use strict";
6875
7173
  var $;
@@ -9938,6 +10236,60 @@ var $;
9938
10236
  });
9939
10237
  })($ || ($ = {}));
9940
10238
 
10239
+ ;
10240
+ "use strict";
10241
+ var $;
10242
+ (function ($_1) {
10243
+ $mol_test({
10244
+ async 'exec timeout auto kill child process'($) {
10245
+ let close_mock = () => { };
10246
+ const error_message = 'Run error, timeout';
10247
+ function mol_run_spawn_sync_mock() {
10248
+ return {
10249
+ output: [],
10250
+ stdout: error_message,
10251
+ stderr: '',
10252
+ status: 0,
10253
+ signal: null,
10254
+ pid: 123,
10255
+ };
10256
+ }
10257
+ function mol_run_spawn_mock() {
10258
+ return {
10259
+ on(name, cb) {
10260
+ if (name === 'exit')
10261
+ close_mock = cb;
10262
+ },
10263
+ kill() { close_mock(); }
10264
+ };
10265
+ }
10266
+ const context_mock = $.$mol_ambient({
10267
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
10268
+ $mol_run_spawn: mol_run_spawn_mock
10269
+ });
10270
+ class $mol_run_mock extends $mol_run {
10271
+ static get $() { return context_mock; }
10272
+ static async_enabled() {
10273
+ return true;
10274
+ }
10275
+ }
10276
+ let message = '';
10277
+ try {
10278
+ const res = await $mol_wire_async($mol_run_mock).spawn({
10279
+ command: 'sleep 10',
10280
+ dir: '.',
10281
+ timeout: 10,
10282
+ env: { 'MOL_RUN_ASYNC': '1' }
10283
+ });
10284
+ }
10285
+ catch (e) {
10286
+ message = e.message;
10287
+ }
10288
+ $mol_assert_equal(message, error_message);
10289
+ }
10290
+ });
10291
+ })($ || ($ = {}));
10292
+
9941
10293
  ;
9942
10294
  "use strict";
9943
10295
  var $;