mol_crypto_lib 0.1.1336 → 0.1.1337

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
@@ -202,30 +202,6 @@ var $;
202
202
  $.$mol_error_mix = $mol_error_mix;
203
203
  })($ || ($ = {}));
204
204
 
205
- ;
206
- "use strict";
207
- var $;
208
- (function ($) {
209
- function $mol_log3_area_lazy(event) {
210
- const self = this;
211
- const stack = self.$mol_log3_stack;
212
- const deep = stack.length;
213
- let logged = false;
214
- stack.push(() => {
215
- logged = true;
216
- self.$mol_log3_area.call(self, event);
217
- });
218
- return () => {
219
- if (logged)
220
- self.console.groupEnd();
221
- if (stack.length > deep)
222
- stack.length = deep;
223
- };
224
- }
225
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
226
- $.$mol_log3_stack = [];
227
- })($ || ($ = {}));
228
-
229
205
  ;
230
206
  "use strict";
231
207
  var $;
@@ -379,656 +355,183 @@ var $;
379
355
  ;
380
356
  "use strict";
381
357
  var $;
382
- (function ($) {
383
- class $mol_span extends $mol_object2 {
384
- uri;
385
- source;
386
- row;
387
- col;
388
- length;
389
- constructor(uri, source, row, col, length) {
390
- super();
391
- this.uri = uri;
392
- this.source = source;
393
- this.row = row;
394
- this.col = col;
395
- this.length = length;
396
- this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
397
- }
398
- static unknown = $mol_span.begin('?');
399
- static begin(uri, source = '') {
400
- return new $mol_span(uri, source, 1, 1, 0);
401
- }
402
- static end(uri, source) {
403
- return new $mol_span(uri, source, 1, source.length + 1, 0);
404
- }
405
- static entire(uri, source) {
406
- return new $mol_span(uri, source, 1, 1, source.length);
407
- }
408
- toString() {
409
- return this[Symbol.toStringTag];
410
- }
411
- toJSON() {
412
- return {
413
- uri: this.uri,
414
- row: this.row,
415
- col: this.col,
416
- length: this.length
417
- };
418
- }
419
- error(message, Class = Error) {
420
- return new Class(`${message} (${this})`);
421
- }
422
- span(row, col, length) {
423
- return new $mol_span(this.uri, this.source, row, col, length);
424
- }
425
- after(length = 0) {
426
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
427
- }
428
- slice(begin, end = -1) {
429
- let len = this.length;
430
- if (begin < 0)
431
- begin += len;
432
- if (end < 0)
433
- end += len;
434
- if (begin < 0 || begin > len)
435
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
436
- if (end < 0 || end > len)
437
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
438
- if (end < begin)
439
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
440
- return this.span(this.row, this.col + begin, end - begin);
358
+ (function ($_1) {
359
+ let $$;
360
+ (function ($$) {
361
+ let $;
362
+ })($$ = $_1.$$ || ($_1.$$ = {}));
363
+ $_1.$mol_object_field = Symbol('$mol_object_field');
364
+ class $mol_object extends $mol_object2 {
365
+ static make(config) {
366
+ return super.create(obj => {
367
+ for (let key in config)
368
+ obj[key] = config[key];
369
+ });
441
370
  }
442
371
  }
443
- $.$mol_span = $mol_span;
372
+ $_1.$mol_object = $mol_object;
444
373
  })($ || ($ = {}));
445
374
 
446
375
  ;
447
376
  "use strict";
448
377
  var $;
449
378
  (function ($) {
450
- function $mol_tree2_to_string(tree) {
451
- let output = [];
452
- function dump(tree, prefix = '') {
453
- if (tree.type.length) {
454
- if (!prefix.length) {
455
- prefix = "\t";
456
- }
457
- output.push(tree.type);
458
- if (tree.kids.length == 1) {
459
- output.push(' ');
460
- dump(tree.kids[0], prefix);
461
- return;
462
- }
463
- output.push("\n");
464
- }
465
- else if (tree.value.length || prefix.length) {
466
- output.push("\\" + tree.value + "\n");
467
- }
468
- for (const kid of tree.kids) {
469
- output.push(prefix);
470
- dump(kid, prefix + "\t");
471
- }
472
- }
473
- dump(tree);
474
- return output.join('');
379
+ function $mol_env() {
380
+ return {};
475
381
  }
476
- $.$mol_tree2_to_string = $mol_tree2_to_string;
382
+ $.$mol_env = $mol_env;
477
383
  })($ || ($ = {}));
478
384
 
479
385
  ;
480
386
  "use strict";
481
387
  var $;
482
388
  (function ($) {
483
- class $mol_tree2 extends Object {
484
- type;
485
- value;
486
- kids;
487
- span;
488
- constructor(type, value, kids, span) {
489
- super();
490
- this.type = type;
491
- this.value = value;
492
- this.kids = kids;
493
- this.span = span;
494
- this[Symbol.toStringTag] = type || '\\' + value;
495
- }
496
- static list(kids, span = $mol_span.unknown) {
497
- return new $mol_tree2('', '', kids, span);
498
- }
499
- list(kids) {
500
- return $mol_tree2.list(kids, this.span);
389
+ $.$mol_env = function $mol_env() {
390
+ return this.process.env;
391
+ };
392
+ })($ || ($ = {}));
393
+
394
+ ;
395
+ "use strict";
396
+ var $;
397
+ (function ($) {
398
+ let $mol_wire_cursor;
399
+ (function ($mol_wire_cursor) {
400
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
401
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
402
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
403
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
404
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
405
+ })($ || ($ = {}));
406
+
407
+ ;
408
+ "use strict";
409
+ var $;
410
+ (function ($) {
411
+ class $mol_wire_pub extends Object {
412
+ data = [];
413
+ static get [Symbol.species]() {
414
+ return Array;
501
415
  }
502
- static data(value, kids = [], span = $mol_span.unknown) {
503
- const chunks = value.split('\n');
504
- if (chunks.length > 1) {
505
- let kid_span = span.span(span.row, span.col, 0);
506
- const data = chunks.map(chunk => {
507
- kid_span = kid_span.after(chunk.length);
508
- return new $mol_tree2('', chunk, [], kid_span);
509
- });
510
- kids = [...data, ...kids];
511
- value = '';
416
+ sub_from = 0;
417
+ get sub_list() {
418
+ const res = [];
419
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
420
+ res.push(this.data[i]);
512
421
  }
513
- return new $mol_tree2('', value, kids, span);
422
+ return res;
514
423
  }
515
- data(value, kids = []) {
516
- return $mol_tree2.data(value, kids, this.span);
424
+ get sub_empty() {
425
+ return this.sub_from === this.data.length;
517
426
  }
518
- static struct(type, kids = [], span = $mol_span.unknown) {
519
- if (/[ \n\t\\]/.test(type)) {
520
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
427
+ sub_on(sub, pub_pos) {
428
+ const pos = this.data.length;
429
+ this.data.push(sub, pub_pos);
430
+ return pos;
431
+ }
432
+ sub_off(sub_pos) {
433
+ if (!(sub_pos < this.data.length)) {
434
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
521
435
  }
522
- return new $mol_tree2(type, '', kids, span);
436
+ const end = this.data.length - 2;
437
+ if (sub_pos !== end) {
438
+ this.peer_move(end, sub_pos);
439
+ }
440
+ this.data.pop();
441
+ this.data.pop();
442
+ if (this.data.length === this.sub_from)
443
+ this.reap();
523
444
  }
524
- struct(type, kids = []) {
525
- return $mol_tree2.struct(type, kids, this.span);
445
+ reap() { }
446
+ promote() {
447
+ $mol_wire_auto()?.track_next(this);
526
448
  }
527
- clone(kids, span = this.span) {
528
- return new $mol_tree2(this.type, this.value, kids, span);
449
+ fresh() { }
450
+ complete() { }
451
+ get incompleted() {
452
+ return false;
529
453
  }
530
- text() {
531
- var values = [];
532
- for (var kid of this.kids) {
533
- if (kid.type)
534
- continue;
535
- values.push(kid.value);
454
+ emit(quant = $mol_wire_cursor.stale) {
455
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
456
+ ;
457
+ this.data[i].absorb(quant);
536
458
  }
537
- return this.value + values.join('\n');
538
459
  }
539
- static fromString(str, uri = 'unknown') {
540
- return $$.$mol_tree2_from_string(str, uri);
460
+ peer_move(from_pos, to_pos) {
461
+ const peer = this.data[from_pos];
462
+ const self_pos = this.data[from_pos + 1];
463
+ this.data[to_pos] = peer;
464
+ this.data[to_pos + 1] = self_pos;
465
+ peer.peer_repos(self_pos, to_pos);
541
466
  }
542
- toString() {
543
- return $$.$mol_tree2_to_string(this);
544
- }
545
- insert(value, ...path) {
546
- if (path.length === 0)
547
- return value;
548
- const type = path[0];
549
- if (typeof type === 'string') {
550
- let replaced = false;
551
- const sub = this.kids.map((item, index) => {
552
- if (item.type !== type)
553
- return item;
554
- replaced = true;
555
- return item.insert(value, ...path.slice(1));
556
- }).filter(Boolean);
557
- if (!replaced && value) {
558
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
559
- }
560
- return this.clone(sub);
561
- }
562
- else if (typeof type === 'number') {
563
- const sub = this.kids.slice();
564
- sub[type] = (sub[type] || this.list([]))
565
- .insert(value, ...path.slice(1));
566
- return this.clone(sub.filter(Boolean));
567
- }
568
- else {
569
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
570
- .map(item => item.insert(value, ...path.slice(1)))
571
- .filter(Boolean);
572
- return this.clone(kids);
573
- }
574
- }
575
- select(...path) {
576
- let next = [this];
577
- for (const type of path) {
578
- if (!next.length)
579
- break;
580
- const prev = next;
581
- next = [];
582
- for (var item of prev) {
583
- switch (typeof (type)) {
584
- case 'string':
585
- for (var child of item.kids) {
586
- if (child.type == type) {
587
- next.push(child);
588
- }
589
- }
590
- break;
591
- case 'number':
592
- if (type < item.kids.length)
593
- next.push(item.kids[type]);
594
- break;
595
- default: next.push(...item.kids);
596
- }
597
- }
598
- }
599
- return this.list(next);
600
- }
601
- filter(path, value) {
602
- const sub = this.kids.filter(item => {
603
- var found = item.select(...path);
604
- if (value === undefined) {
605
- return Boolean(found.kids.length);
606
- }
607
- else {
608
- return found.kids.some(child => child.value == value);
609
- }
610
- });
611
- return this.clone(sub);
612
- }
613
- hack_self(belt, context = {}) {
614
- let handle = belt[this.type] || belt[''];
615
- if (!handle || handle === Object.prototype[this.type]) {
616
- handle = (input, belt, context) => [
617
- input.clone(input.hack(belt, context), context.span)
618
- ];
619
- }
620
- try {
621
- return handle(this, belt, context);
622
- }
623
- catch (error) {
624
- error.message += `\n${this.clone([])}${this.span}`;
625
- $mol_fail_hidden(error);
626
- }
627
- }
628
- hack(belt, context = {}) {
629
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
630
- }
631
- error(message, Class = Error) {
632
- return this.span.error(`${message}\n${this.clone([])}`, Class);
633
- }
634
- }
635
- $.$mol_tree2 = $mol_tree2;
636
- class $mol_tree2_empty extends $mol_tree2 {
637
- constructor() {
638
- super('', '', [], $mol_span.unknown);
467
+ peer_repos(peer_pos, self_pos) {
468
+ this.data[peer_pos + 1] = self_pos;
639
469
  }
640
470
  }
641
- $.$mol_tree2_empty = $mol_tree2_empty;
471
+ $.$mol_wire_pub = $mol_wire_pub;
642
472
  })($ || ($ = {}));
643
473
 
474
+ ;
475
+ "use strict";
476
+
644
477
  ;
645
478
  "use strict";
646
479
  var $;
647
480
  (function ($) {
648
- class $mol_error_syntax extends SyntaxError {
649
- reason;
650
- line;
651
- span;
652
- constructor(reason, line, span) {
653
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
654
- this.reason = reason;
655
- this.line = line;
656
- this.span = span;
657
- }
481
+ $.$mol_wire_auto_sub = null;
482
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
483
+ return $.$mol_wire_auto_sub = next;
658
484
  }
659
- $.$mol_error_syntax = $mol_error_syntax;
485
+ $.$mol_wire_auto = $mol_wire_auto;
486
+ $.$mol_wire_affected = [];
660
487
  })($ || ($ = {}));
661
488
 
662
489
  ;
663
490
  "use strict";
664
491
  var $;
665
492
  (function ($) {
666
- function $mol_tree2_from_string(str, uri = '?') {
667
- const span = $mol_span.entire(uri, str);
668
- var root = $mol_tree2.list([], span);
669
- var stack = [root];
670
- var pos = 0, row = 0, min_indent = 0;
671
- while (str.length > pos) {
672
- var indent = 0;
673
- var line_start = pos;
674
- row++;
675
- while (str.length > pos && str[pos] == '\t') {
676
- indent++;
677
- pos++;
678
- }
679
- if (!root.kids.length) {
680
- min_indent = indent;
681
- }
682
- indent -= min_indent;
683
- if (indent < 0 || indent >= stack.length) {
684
- const sp = span.span(row, 1, pos - line_start);
685
- while (str.length > pos && str[pos] != '\n') {
686
- pos++;
687
- }
688
- if (indent < 0) {
689
- if (str.length > pos) {
690
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
691
- }
692
- }
693
- else {
694
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
695
- }
696
- }
697
- stack.length = indent + 1;
698
- var parent = stack[indent];
699
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
700
- var error_start = pos;
701
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
702
- pos++;
703
- }
704
- if (pos > error_start) {
705
- let line_end = str.indexOf('\n', pos);
706
- if (line_end === -1)
707
- line_end = str.length;
708
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
709
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
710
- }
711
- var type_start = pos;
712
- while (str.length > pos &&
713
- str[pos] != '\\' &&
714
- str[pos] != ' ' &&
715
- str[pos] != '\t' &&
716
- str[pos] != '\n') {
717
- pos++;
718
- }
719
- if (pos > type_start) {
720
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
721
- const parent_kids = parent.kids;
722
- parent_kids.push(next);
723
- parent = next;
493
+ $['devtoolsFormatters'] ||= [];
494
+ function $mol_dev_format_register(config) {
495
+ $['devtoolsFormatters'].push(config);
496
+ }
497
+ $.$mol_dev_format_register = $mol_dev_format_register;
498
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
499
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
500
+ $mol_dev_format_register({
501
+ header: (val, config = false) => {
502
+ if (config)
503
+ return null;
504
+ if (!val)
505
+ return null;
506
+ if ($.$mol_dev_format_head in val) {
507
+ try {
508
+ return val[$.$mol_dev_format_head]();
724
509
  }
725
- if (str.length > pos && str[pos] == ' ') {
726
- pos++;
510
+ catch (error) {
511
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
727
512
  }
728
513
  }
729
- if (str.length > pos && str[pos] == '\\') {
730
- var data_start = pos;
731
- while (str.length > pos && str[pos] != '\n') {
732
- pos++;
733
- }
734
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
735
- const parent_kids = parent.kids;
736
- parent_kids.push(next);
737
- parent = next;
514
+ if (typeof val === 'function') {
515
+ return $mol_dev_format_native(val);
738
516
  }
739
- if (str.length === pos && stack.length > 0) {
740
- const sp = span.span(row, pos - line_start + 1, 1);
741
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
517
+ if (Symbol.toStringTag in val) {
518
+ return $mol_dev_format_native(val);
742
519
  }
743
- stack.push(parent);
744
- pos++;
745
- }
746
- return root;
747
- }
748
- $.$mol_tree2_from_string = $mol_tree2_from_string;
749
- })($ || ($ = {}));
750
-
751
- ;
752
- "use strict";
753
- var $;
754
- (function ($) {
755
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
756
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
757
- return new $mol_tree2(String(json), '', [], span);
758
- }
759
- if (typeof json === 'string') {
760
- return $mol_tree2.data(json, [], span);
761
- }
762
- if (typeof json.toJSON === 'function') {
763
- return $mol_tree2_from_json(json.toJSON());
764
- }
765
- if (Array.isArray(json)) {
766
- const sub = json.map(json => $mol_tree2_from_json(json, span));
767
- return new $mol_tree2('/', '', sub, span);
768
- }
769
- if (ArrayBuffer.isView(json)) {
770
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
771
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
772
- }
773
- if (json instanceof Date) {
774
- return new $mol_tree2('', json.toISOString(), [], span);
775
- }
776
- if (json.toString !== Object.prototype.toString) {
777
- return $mol_tree2.data(json.toString(), [], span);
778
- }
779
- if (json instanceof Error) {
780
- const { name, message, stack } = json;
781
- json = { ...json, name, message, stack };
782
- }
783
- const sub = [];
784
- for (var key in json) {
785
- const val = json[key];
786
- if (val === undefined)
787
- continue;
788
- const subsub = $mol_tree2_from_json(val, span);
789
- if (/^[^\n\t\\ ]+$/.test(key)) {
790
- sub.push(new $mol_tree2(key, '', [subsub], span));
791
- }
792
- else {
793
- sub.push($mol_tree2.data(key, [subsub], span));
794
- }
795
- }
796
- return new $mol_tree2('*', '', sub, span);
797
- }
798
- $.$mol_tree2_from_json = $mol_tree2_from_json;
799
- })($ || ($ = {}));
800
-
801
- ;
802
- "use strict";
803
- var $;
804
- (function ($) {
805
- class $mol_term_color {
806
- static reset = this.ansi(0, 0);
807
- static bold = this.ansi(1, 22);
808
- static italic = this.ansi(3, 23);
809
- static underline = this.ansi(4, 24);
810
- static inverse = this.ansi(7, 27);
811
- static hidden = this.ansi(8, 28);
812
- static strike = this.ansi(9, 29);
813
- static gray = this.ansi(90, 39);
814
- static red = this.ansi(91, 39);
815
- static green = this.ansi(92, 39);
816
- static yellow = this.ansi(93, 39);
817
- static blue = this.ansi(94, 39);
818
- static magenta = this.ansi(95, 39);
819
- static cyan = this.ansi(96, 39);
820
- static Gray = (str) => this.inverse(this.gray(str));
821
- static Red = (str) => this.inverse(this.red(str));
822
- static Green = (str) => this.inverse(this.green(str));
823
- static Yellow = (str) => this.inverse(this.yellow(str));
824
- static Blue = (str) => this.inverse(this.blue(str));
825
- static Magenta = (str) => this.inverse(this.magenta(str));
826
- static Cyan = (str) => this.inverse(this.cyan(str));
827
- static ansi(open, close) {
828
- if (typeof process === 'undefined')
829
- return String;
830
- if (!process.stdout.isTTY)
831
- return String;
832
- const prefix = `\x1b[${open}m`;
833
- const postfix = `\x1b[${close}m`;
834
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
835
- return function colorer(str) {
836
- str = String(str);
837
- if (str === '')
838
- return str;
839
- const suffix = str.replace(suffix_regexp, prefix);
840
- return prefix + suffix + postfix;
841
- };
842
- }
843
- }
844
- $.$mol_term_color = $mol_term_color;
845
- })($ || ($ = {}));
846
-
847
- ;
848
- "use strict";
849
- var $;
850
- (function ($) {
851
- function $mol_log3_node_make(level, output, type, color) {
852
- return function $mol_log3_logger(event) {
853
- if (!event.time)
854
- event = { time: new Date().toISOString(), ...event };
855
- let tree = this.$mol_tree2_from_json(event);
856
- tree = tree.struct(type, tree.kids);
857
- let str = color(tree.toString());
858
- this.console[level](str);
859
- const self = this;
860
- return () => self.console.groupEnd();
861
- };
862
- }
863
- $.$mol_log3_node_make = $mol_log3_node_make;
864
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
865
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
866
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
867
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
868
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
869
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
870
- })($ || ($ = {}));
871
-
872
- ;
873
- "use strict";
874
- var $;
875
- (function ($) {
876
- function $mol_env() {
877
- return {};
878
- }
879
- $.$mol_env = $mol_env;
880
- })($ || ($ = {}));
881
-
882
- ;
883
- "use strict";
884
- var $;
885
- (function ($) {
886
- $.$mol_env = function $mol_env() {
887
- return this.process.env;
888
- };
889
- })($ || ($ = {}));
890
-
891
- ;
892
- "use strict";
893
- var $;
894
- (function ($) {
895
- let $mol_wire_cursor;
896
- (function ($mol_wire_cursor) {
897
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
898
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
899
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
900
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
901
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
902
- })($ || ($ = {}));
903
-
904
- ;
905
- "use strict";
906
- var $;
907
- (function ($) {
908
- class $mol_wire_pub extends Object {
909
- data = [];
910
- static get [Symbol.species]() {
911
- return Array;
912
- }
913
- sub_from = 0;
914
- get sub_list() {
915
- const res = [];
916
- for (let i = this.sub_from; i < this.data.length; i += 2) {
917
- res.push(this.data[i]);
918
- }
919
- return res;
920
- }
921
- get sub_empty() {
922
- return this.sub_from === this.data.length;
923
- }
924
- sub_on(sub, pub_pos) {
925
- const pos = this.data.length;
926
- this.data.push(sub, pub_pos);
927
- return pos;
928
- }
929
- sub_off(sub_pos) {
930
- if (!(sub_pos < this.data.length)) {
931
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
932
- }
933
- const end = this.data.length - 2;
934
- if (sub_pos !== end) {
935
- this.peer_move(end, sub_pos);
936
- }
937
- this.data.pop();
938
- this.data.pop();
939
- if (this.data.length === this.sub_from)
940
- this.reap();
941
- }
942
- reap() { }
943
- promote() {
944
- $mol_wire_auto()?.track_next(this);
945
- }
946
- fresh() { }
947
- complete() { }
948
- get incompleted() {
949
- return false;
950
- }
951
- emit(quant = $mol_wire_cursor.stale) {
952
- for (let i = this.sub_from; i < this.data.length; i += 2) {
953
- ;
954
- this.data[i].absorb(quant);
955
- }
956
- }
957
- peer_move(from_pos, to_pos) {
958
- const peer = this.data[from_pos];
959
- const self_pos = this.data[from_pos + 1];
960
- this.data[to_pos] = peer;
961
- this.data[to_pos + 1] = self_pos;
962
- peer.peer_repos(self_pos, to_pos);
963
- }
964
- peer_repos(peer_pos, self_pos) {
965
- this.data[peer_pos + 1] = self_pos;
966
- }
967
- }
968
- $.$mol_wire_pub = $mol_wire_pub;
969
- })($ || ($ = {}));
970
-
971
- ;
972
- "use strict";
973
-
974
- ;
975
- "use strict";
976
- var $;
977
- (function ($) {
978
- $.$mol_wire_auto_sub = null;
979
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
980
- return $.$mol_wire_auto_sub = next;
981
- }
982
- $.$mol_wire_auto = $mol_wire_auto;
983
- $.$mol_wire_affected = [];
984
- })($ || ($ = {}));
985
-
986
- ;
987
- "use strict";
988
- var $;
989
- (function ($) {
990
- $['devtoolsFormatters'] ||= [];
991
- function $mol_dev_format_register(config) {
992
- $['devtoolsFormatters'].push(config);
993
- }
994
- $.$mol_dev_format_register = $mol_dev_format_register;
995
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
996
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
997
- $mol_dev_format_register({
998
- header: (val, config = false) => {
999
- if (config)
1000
- return null;
1001
- if (!val)
1002
- return null;
1003
- if ($.$mol_dev_format_head in val) {
1004
- try {
1005
- return val[$.$mol_dev_format_head]();
1006
- }
1007
- catch (error) {
1008
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1009
- }
1010
- }
1011
- if (typeof val === 'function') {
1012
- return $mol_dev_format_native(val);
1013
- }
1014
- if (Symbol.toStringTag in val) {
1015
- return $mol_dev_format_native(val);
1016
- }
1017
- return null;
1018
- },
1019
- hasBody: val => val[$.$mol_dev_format_body],
1020
- body: val => val[$.$mol_dev_format_body](),
1021
- });
1022
- function $mol_dev_format_native(obj) {
1023
- if (typeof obj === 'undefined')
1024
- return $.$mol_dev_format_shade('undefined');
1025
- return [
1026
- 'object',
1027
- {
1028
- object: obj,
1029
- config: true,
1030
- },
1031
- ];
520
+ return null;
521
+ },
522
+ hasBody: val => val[$.$mol_dev_format_body],
523
+ body: val => val[$.$mol_dev_format_body](),
524
+ });
525
+ function $mol_dev_format_native(obj) {
526
+ if (typeof obj === 'undefined')
527
+ return $.$mol_dev_format_shade('undefined');
528
+ return [
529
+ 'object',
530
+ {
531
+ object: obj,
532
+ config: true,
533
+ },
534
+ ];
1032
535
  }
1033
536
  $.$mol_dev_format_native = $mol_dev_format_native;
1034
537
  function $mol_dev_format_auto(obj) {
@@ -1500,147 +1003,664 @@ var $;
1500
1003
  }
1501
1004
  }
1502
1005
  }
1503
- $.$mol_wire_fiber = $mol_wire_fiber;
1006
+ $.$mol_wire_fiber = $mol_wire_fiber;
1007
+ })($ || ($ = {}));
1008
+
1009
+ ;
1010
+ "use strict";
1011
+ var $;
1012
+ (function ($) {
1013
+ $.$mol_compare_deep_cache = new WeakMap();
1014
+ function $mol_compare_deep(left, right) {
1015
+ if (Object.is(left, right))
1016
+ return true;
1017
+ if (left === null)
1018
+ return false;
1019
+ if (right === null)
1020
+ return false;
1021
+ if (typeof left !== 'object')
1022
+ return false;
1023
+ if (typeof right !== 'object')
1024
+ return false;
1025
+ const left_proto = Reflect.getPrototypeOf(left);
1026
+ const right_proto = Reflect.getPrototypeOf(right);
1027
+ if (left_proto !== right_proto)
1028
+ return false;
1029
+ if (left instanceof Boolean)
1030
+ return Object.is(left.valueOf(), right['valueOf']());
1031
+ if (left instanceof Number)
1032
+ return Object.is(left.valueOf(), right['valueOf']());
1033
+ if (left instanceof String)
1034
+ return Object.is(left.valueOf(), right['valueOf']());
1035
+ if (left instanceof Date)
1036
+ return Object.is(left.valueOf(), right['valueOf']());
1037
+ if (left instanceof RegExp)
1038
+ return left.source === right.source && left.flags === right.flags;
1039
+ if (left instanceof Error)
1040
+ return left.message === right.message && left.stack === right.stack;
1041
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1042
+ if (left_cache) {
1043
+ const right_cache = left_cache.get(right);
1044
+ if (typeof right_cache === 'boolean')
1045
+ return right_cache;
1046
+ }
1047
+ else {
1048
+ left_cache = new WeakMap();
1049
+ $.$mol_compare_deep_cache.set(left, left_cache);
1050
+ }
1051
+ left_cache.set(right, true);
1052
+ let result;
1053
+ try {
1054
+ if (!left_proto)
1055
+ result = compare_pojo(left, right);
1056
+ else if (!Reflect.getPrototypeOf(left_proto))
1057
+ result = compare_pojo(left, right);
1058
+ else if (Symbol.toPrimitive in left)
1059
+ result = compare_primitive(left, right);
1060
+ else if (Array.isArray(left))
1061
+ result = compare_array(left, right);
1062
+ else if (left instanceof Set)
1063
+ result = compare_set(left, right);
1064
+ else if (left instanceof Map)
1065
+ result = compare_map(left, right);
1066
+ else if (ArrayBuffer.isView(left))
1067
+ result = compare_buffer(left, right);
1068
+ else if (Symbol.iterator in left)
1069
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1070
+ else
1071
+ result = false;
1072
+ }
1073
+ finally {
1074
+ left_cache.set(right, result);
1075
+ }
1076
+ return result;
1077
+ }
1078
+ $.$mol_compare_deep = $mol_compare_deep;
1079
+ function compare_array(left, right) {
1080
+ const len = left.length;
1081
+ if (len !== right.length)
1082
+ return false;
1083
+ for (let i = 0; i < len; ++i) {
1084
+ if (!$mol_compare_deep(left[i], right[i]))
1085
+ return false;
1086
+ }
1087
+ return true;
1088
+ }
1089
+ function compare_buffer(left, right) {
1090
+ const len = left.byteLength;
1091
+ if (len !== right.byteLength)
1092
+ return false;
1093
+ if (left instanceof DataView)
1094
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1095
+ for (let i = 0; i < len; ++i) {
1096
+ if (left[i] !== right[i])
1097
+ return false;
1098
+ }
1099
+ return true;
1100
+ }
1101
+ function compare_iterator(left, right) {
1102
+ while (true) {
1103
+ const left_next = left.next();
1104
+ const right_next = right.next();
1105
+ if (left_next.done !== right_next.done)
1106
+ return false;
1107
+ if (left_next.done)
1108
+ break;
1109
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1110
+ return false;
1111
+ }
1112
+ return true;
1113
+ }
1114
+ function compare_set(left, right) {
1115
+ if (left.size !== right.size)
1116
+ return false;
1117
+ return compare_iterator(left.values(), right.values());
1118
+ }
1119
+ function compare_map(left, right) {
1120
+ if (left.size !== right.size)
1121
+ return false;
1122
+ return compare_iterator(left.keys(), right.keys())
1123
+ && compare_iterator(left.values(), right.values());
1124
+ }
1125
+ function compare_pojo(left, right) {
1126
+ const left_keys = Object.getOwnPropertyNames(left);
1127
+ const right_keys = Object.getOwnPropertyNames(right);
1128
+ if (!compare_array(left_keys, right_keys))
1129
+ return false;
1130
+ for (let key of left_keys) {
1131
+ if (!$mol_compare_deep(left[key], right[key]))
1132
+ return false;
1133
+ }
1134
+ const left_syms = Object.getOwnPropertySymbols(left);
1135
+ const right_syms = Object.getOwnPropertySymbols(right);
1136
+ if (!compare_array(left_syms, right_syms))
1137
+ return false;
1138
+ for (let key of left_syms) {
1139
+ if (!$mol_compare_deep(left[key], right[key]))
1140
+ return false;
1141
+ }
1142
+ return true;
1143
+ }
1144
+ function compare_primitive(left, right) {
1145
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1146
+ }
1147
+ })($ || ($ = {}));
1148
+
1149
+ ;
1150
+ "use strict";
1151
+ var $;
1152
+ (function ($) {
1153
+ function $mol_log3_area_lazy(event) {
1154
+ const self = this;
1155
+ const stack = self.$mol_log3_stack;
1156
+ const deep = stack.length;
1157
+ let logged = false;
1158
+ stack.push(() => {
1159
+ logged = true;
1160
+ self.$mol_log3_area.call(self, event);
1161
+ });
1162
+ return () => {
1163
+ if (logged)
1164
+ self.console.groupEnd();
1165
+ if (stack.length > deep)
1166
+ stack.length = deep;
1167
+ };
1168
+ }
1169
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1170
+ $.$mol_log3_stack = [];
1171
+ })($ || ($ = {}));
1172
+
1173
+ ;
1174
+ "use strict";
1175
+ var $;
1176
+ (function ($) {
1177
+ class $mol_span extends $mol_object2 {
1178
+ uri;
1179
+ source;
1180
+ row;
1181
+ col;
1182
+ length;
1183
+ constructor(uri, source, row, col, length) {
1184
+ super();
1185
+ this.uri = uri;
1186
+ this.source = source;
1187
+ this.row = row;
1188
+ this.col = col;
1189
+ this.length = length;
1190
+ this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1191
+ }
1192
+ static unknown = $mol_span.begin('?');
1193
+ static begin(uri, source = '') {
1194
+ return new $mol_span(uri, source, 1, 1, 0);
1195
+ }
1196
+ static end(uri, source) {
1197
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1198
+ }
1199
+ static entire(uri, source) {
1200
+ return new $mol_span(uri, source, 1, 1, source.length);
1201
+ }
1202
+ toString() {
1203
+ return this[Symbol.toStringTag];
1204
+ }
1205
+ toJSON() {
1206
+ return {
1207
+ uri: this.uri,
1208
+ row: this.row,
1209
+ col: this.col,
1210
+ length: this.length
1211
+ };
1212
+ }
1213
+ error(message, Class = Error) {
1214
+ return new Class(`${message} (${this})`);
1215
+ }
1216
+ span(row, col, length) {
1217
+ return new $mol_span(this.uri, this.source, row, col, length);
1218
+ }
1219
+ after(length = 0) {
1220
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1221
+ }
1222
+ slice(begin, end = -1) {
1223
+ let len = this.length;
1224
+ if (begin < 0)
1225
+ begin += len;
1226
+ if (end < 0)
1227
+ end += len;
1228
+ if (begin < 0 || begin > len)
1229
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1230
+ if (end < 0 || end > len)
1231
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1232
+ if (end < begin)
1233
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1234
+ return this.span(this.row, this.col + begin, end - begin);
1235
+ }
1236
+ }
1237
+ $.$mol_span = $mol_span;
1238
+ })($ || ($ = {}));
1239
+
1240
+ ;
1241
+ "use strict";
1242
+ var $;
1243
+ (function ($) {
1244
+ function $mol_tree2_to_string(tree) {
1245
+ let output = [];
1246
+ function dump(tree, prefix = '') {
1247
+ if (tree.type.length) {
1248
+ if (!prefix.length) {
1249
+ prefix = "\t";
1250
+ }
1251
+ output.push(tree.type);
1252
+ if (tree.kids.length == 1) {
1253
+ output.push(' ');
1254
+ dump(tree.kids[0], prefix);
1255
+ return;
1256
+ }
1257
+ output.push("\n");
1258
+ }
1259
+ else if (tree.value.length || prefix.length) {
1260
+ output.push("\\" + tree.value + "\n");
1261
+ }
1262
+ for (const kid of tree.kids) {
1263
+ output.push(prefix);
1264
+ dump(kid, prefix + "\t");
1265
+ }
1266
+ }
1267
+ dump(tree);
1268
+ return output.join('');
1269
+ }
1270
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1271
+ })($ || ($ = {}));
1272
+
1273
+ ;
1274
+ "use strict";
1275
+ var $;
1276
+ (function ($) {
1277
+ class $mol_tree2 extends Object {
1278
+ type;
1279
+ value;
1280
+ kids;
1281
+ span;
1282
+ constructor(type, value, kids, span) {
1283
+ super();
1284
+ this.type = type;
1285
+ this.value = value;
1286
+ this.kids = kids;
1287
+ this.span = span;
1288
+ this[Symbol.toStringTag] = type || '\\' + value;
1289
+ }
1290
+ static list(kids, span = $mol_span.unknown) {
1291
+ return new $mol_tree2('', '', kids, span);
1292
+ }
1293
+ list(kids) {
1294
+ return $mol_tree2.list(kids, this.span);
1295
+ }
1296
+ static data(value, kids = [], span = $mol_span.unknown) {
1297
+ const chunks = value.split('\n');
1298
+ if (chunks.length > 1) {
1299
+ let kid_span = span.span(span.row, span.col, 0);
1300
+ const data = chunks.map(chunk => {
1301
+ kid_span = kid_span.after(chunk.length);
1302
+ return new $mol_tree2('', chunk, [], kid_span);
1303
+ });
1304
+ kids = [...data, ...kids];
1305
+ value = '';
1306
+ }
1307
+ return new $mol_tree2('', value, kids, span);
1308
+ }
1309
+ data(value, kids = []) {
1310
+ return $mol_tree2.data(value, kids, this.span);
1311
+ }
1312
+ static struct(type, kids = [], span = $mol_span.unknown) {
1313
+ if (/[ \n\t\\]/.test(type)) {
1314
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1315
+ }
1316
+ return new $mol_tree2(type, '', kids, span);
1317
+ }
1318
+ struct(type, kids = []) {
1319
+ return $mol_tree2.struct(type, kids, this.span);
1320
+ }
1321
+ clone(kids, span = this.span) {
1322
+ return new $mol_tree2(this.type, this.value, kids, span);
1323
+ }
1324
+ text() {
1325
+ var values = [];
1326
+ for (var kid of this.kids) {
1327
+ if (kid.type)
1328
+ continue;
1329
+ values.push(kid.value);
1330
+ }
1331
+ return this.value + values.join('\n');
1332
+ }
1333
+ static fromString(str, uri = 'unknown') {
1334
+ return $$.$mol_tree2_from_string(str, uri);
1335
+ }
1336
+ toString() {
1337
+ return $$.$mol_tree2_to_string(this);
1338
+ }
1339
+ insert(value, ...path) {
1340
+ if (path.length === 0)
1341
+ return value;
1342
+ const type = path[0];
1343
+ if (typeof type === 'string') {
1344
+ let replaced = false;
1345
+ const sub = this.kids.map((item, index) => {
1346
+ if (item.type !== type)
1347
+ return item;
1348
+ replaced = true;
1349
+ return item.insert(value, ...path.slice(1));
1350
+ }).filter(Boolean);
1351
+ if (!replaced && value) {
1352
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1353
+ }
1354
+ return this.clone(sub);
1355
+ }
1356
+ else if (typeof type === 'number') {
1357
+ const sub = this.kids.slice();
1358
+ sub[type] = (sub[type] || this.list([]))
1359
+ .insert(value, ...path.slice(1));
1360
+ return this.clone(sub.filter(Boolean));
1361
+ }
1362
+ else {
1363
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1364
+ .map(item => item.insert(value, ...path.slice(1)))
1365
+ .filter(Boolean);
1366
+ return this.clone(kids);
1367
+ }
1368
+ }
1369
+ select(...path) {
1370
+ let next = [this];
1371
+ for (const type of path) {
1372
+ if (!next.length)
1373
+ break;
1374
+ const prev = next;
1375
+ next = [];
1376
+ for (var item of prev) {
1377
+ switch (typeof (type)) {
1378
+ case 'string':
1379
+ for (var child of item.kids) {
1380
+ if (child.type == type) {
1381
+ next.push(child);
1382
+ }
1383
+ }
1384
+ break;
1385
+ case 'number':
1386
+ if (type < item.kids.length)
1387
+ next.push(item.kids[type]);
1388
+ break;
1389
+ default: next.push(...item.kids);
1390
+ }
1391
+ }
1392
+ }
1393
+ return this.list(next);
1394
+ }
1395
+ filter(path, value) {
1396
+ const sub = this.kids.filter(item => {
1397
+ var found = item.select(...path);
1398
+ if (value === undefined) {
1399
+ return Boolean(found.kids.length);
1400
+ }
1401
+ else {
1402
+ return found.kids.some(child => child.value == value);
1403
+ }
1404
+ });
1405
+ return this.clone(sub);
1406
+ }
1407
+ hack_self(belt, context = {}) {
1408
+ let handle = belt[this.type] || belt[''];
1409
+ if (!handle || handle === Object.prototype[this.type]) {
1410
+ handle = (input, belt, context) => [
1411
+ input.clone(input.hack(belt, context), context.span)
1412
+ ];
1413
+ }
1414
+ try {
1415
+ return handle(this, belt, context);
1416
+ }
1417
+ catch (error) {
1418
+ error.message += `\n${this.clone([])}${this.span}`;
1419
+ $mol_fail_hidden(error);
1420
+ }
1421
+ }
1422
+ hack(belt, context = {}) {
1423
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1424
+ }
1425
+ error(message, Class = Error) {
1426
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1427
+ }
1428
+ }
1429
+ $.$mol_tree2 = $mol_tree2;
1430
+ class $mol_tree2_empty extends $mol_tree2 {
1431
+ constructor() {
1432
+ super('', '', [], $mol_span.unknown);
1433
+ }
1434
+ }
1435
+ $.$mol_tree2_empty = $mol_tree2_empty;
1436
+ })($ || ($ = {}));
1437
+
1438
+ ;
1439
+ "use strict";
1440
+ var $;
1441
+ (function ($) {
1442
+ class $mol_error_syntax extends SyntaxError {
1443
+ reason;
1444
+ line;
1445
+ span;
1446
+ constructor(reason, line, span) {
1447
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1448
+ this.reason = reason;
1449
+ this.line = line;
1450
+ this.span = span;
1451
+ }
1452
+ }
1453
+ $.$mol_error_syntax = $mol_error_syntax;
1454
+ })($ || ($ = {}));
1455
+
1456
+ ;
1457
+ "use strict";
1458
+ var $;
1459
+ (function ($) {
1460
+ function $mol_tree2_from_string(str, uri = '?') {
1461
+ const span = $mol_span.entire(uri, str);
1462
+ var root = $mol_tree2.list([], span);
1463
+ var stack = [root];
1464
+ var pos = 0, row = 0, min_indent = 0;
1465
+ while (str.length > pos) {
1466
+ var indent = 0;
1467
+ var line_start = pos;
1468
+ row++;
1469
+ while (str.length > pos && str[pos] == '\t') {
1470
+ indent++;
1471
+ pos++;
1472
+ }
1473
+ if (!root.kids.length) {
1474
+ min_indent = indent;
1475
+ }
1476
+ indent -= min_indent;
1477
+ if (indent < 0 || indent >= stack.length) {
1478
+ const sp = span.span(row, 1, pos - line_start);
1479
+ while (str.length > pos && str[pos] != '\n') {
1480
+ pos++;
1481
+ }
1482
+ if (indent < 0) {
1483
+ if (str.length > pos) {
1484
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1485
+ }
1486
+ }
1487
+ else {
1488
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1489
+ }
1490
+ }
1491
+ stack.length = indent + 1;
1492
+ var parent = stack[indent];
1493
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1494
+ var error_start = pos;
1495
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1496
+ pos++;
1497
+ }
1498
+ if (pos > error_start) {
1499
+ let line_end = str.indexOf('\n', pos);
1500
+ if (line_end === -1)
1501
+ line_end = str.length;
1502
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1503
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1504
+ }
1505
+ var type_start = pos;
1506
+ while (str.length > pos &&
1507
+ str[pos] != '\\' &&
1508
+ str[pos] != ' ' &&
1509
+ str[pos] != '\t' &&
1510
+ str[pos] != '\n') {
1511
+ pos++;
1512
+ }
1513
+ if (pos > type_start) {
1514
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1515
+ const parent_kids = parent.kids;
1516
+ parent_kids.push(next);
1517
+ parent = next;
1518
+ }
1519
+ if (str.length > pos && str[pos] == ' ') {
1520
+ pos++;
1521
+ }
1522
+ }
1523
+ if (str.length > pos && str[pos] == '\\') {
1524
+ var data_start = pos;
1525
+ while (str.length > pos && str[pos] != '\n') {
1526
+ pos++;
1527
+ }
1528
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1529
+ const parent_kids = parent.kids;
1530
+ parent_kids.push(next);
1531
+ parent = next;
1532
+ }
1533
+ if (str.length === pos && stack.length > 0) {
1534
+ const sp = span.span(row, pos - line_start + 1, 1);
1535
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1536
+ }
1537
+ stack.push(parent);
1538
+ pos++;
1539
+ }
1540
+ return root;
1541
+ }
1542
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1543
+ })($ || ($ = {}));
1544
+
1545
+ ;
1546
+ "use strict";
1547
+ var $;
1548
+ (function ($) {
1549
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1550
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1551
+ return new $mol_tree2(String(json), '', [], span);
1552
+ }
1553
+ if (typeof json === 'string') {
1554
+ return $mol_tree2.data(json, [], span);
1555
+ }
1556
+ if (typeof json.toJSON === 'function') {
1557
+ return $mol_tree2_from_json(json.toJSON());
1558
+ }
1559
+ if (Array.isArray(json)) {
1560
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1561
+ return new $mol_tree2('/', '', sub, span);
1562
+ }
1563
+ if (ArrayBuffer.isView(json)) {
1564
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1565
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1566
+ }
1567
+ if (json instanceof Date) {
1568
+ return new $mol_tree2('', json.toISOString(), [], span);
1569
+ }
1570
+ if (json.toString !== Object.prototype.toString) {
1571
+ return $mol_tree2.data(json.toString(), [], span);
1572
+ }
1573
+ if (json instanceof Error) {
1574
+ const { name, message, stack } = json;
1575
+ json = { ...json, name, message, stack };
1576
+ }
1577
+ const sub = [];
1578
+ for (var key in json) {
1579
+ const val = json[key];
1580
+ if (val === undefined)
1581
+ continue;
1582
+ const subsub = $mol_tree2_from_json(val, span);
1583
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1584
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1585
+ }
1586
+ else {
1587
+ sub.push($mol_tree2.data(key, [subsub], span));
1588
+ }
1589
+ }
1590
+ return new $mol_tree2('*', '', sub, span);
1591
+ }
1592
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1504
1593
  })($ || ($ = {}));
1505
1594
 
1506
1595
  ;
1507
1596
  "use strict";
1508
1597
  var $;
1509
1598
  (function ($) {
1510
- $.$mol_compare_deep_cache = new WeakMap();
1511
- function $mol_compare_deep(left, right) {
1512
- if (Object.is(left, right))
1513
- return true;
1514
- if (left === null)
1515
- return false;
1516
- if (right === null)
1517
- return false;
1518
- if (typeof left !== 'object')
1519
- return false;
1520
- if (typeof right !== 'object')
1521
- return false;
1522
- const left_proto = Reflect.getPrototypeOf(left);
1523
- const right_proto = Reflect.getPrototypeOf(right);
1524
- if (left_proto !== right_proto)
1525
- return false;
1526
- if (left instanceof Boolean)
1527
- return Object.is(left.valueOf(), right['valueOf']());
1528
- if (left instanceof Number)
1529
- return Object.is(left.valueOf(), right['valueOf']());
1530
- if (left instanceof String)
1531
- return Object.is(left.valueOf(), right['valueOf']());
1532
- if (left instanceof Date)
1533
- return Object.is(left.valueOf(), right['valueOf']());
1534
- if (left instanceof RegExp)
1535
- return left.source === right.source && left.flags === right.flags;
1536
- if (left instanceof Error)
1537
- return left.message === right.message && left.stack === right.stack;
1538
- let left_cache = $.$mol_compare_deep_cache.get(left);
1539
- if (left_cache) {
1540
- const right_cache = left_cache.get(right);
1541
- if (typeof right_cache === 'boolean')
1542
- return right_cache;
1543
- }
1544
- else {
1545
- left_cache = new WeakMap();
1546
- $.$mol_compare_deep_cache.set(left, left_cache);
1547
- }
1548
- left_cache.set(right, true);
1549
- let result;
1550
- try {
1551
- if (!left_proto)
1552
- result = compare_pojo(left, right);
1553
- else if (!Reflect.getPrototypeOf(left_proto))
1554
- result = compare_pojo(left, right);
1555
- else if (Symbol.toPrimitive in left)
1556
- result = compare_primitive(left, right);
1557
- else if (Array.isArray(left))
1558
- result = compare_array(left, right);
1559
- else if (left instanceof Set)
1560
- result = compare_set(left, right);
1561
- else if (left instanceof Map)
1562
- result = compare_map(left, right);
1563
- else if (ArrayBuffer.isView(left))
1564
- result = compare_buffer(left, right);
1565
- else if (Symbol.iterator in left)
1566
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1567
- else
1568
- result = false;
1569
- }
1570
- finally {
1571
- left_cache.set(right, result);
1572
- }
1573
- return result;
1574
- }
1575
- $.$mol_compare_deep = $mol_compare_deep;
1576
- function compare_array(left, right) {
1577
- const len = left.length;
1578
- if (len !== right.length)
1579
- return false;
1580
- for (let i = 0; i < len; ++i) {
1581
- if (!$mol_compare_deep(left[i], right[i]))
1582
- return false;
1583
- }
1584
- return true;
1585
- }
1586
- function compare_buffer(left, right) {
1587
- const len = left.byteLength;
1588
- if (len !== right.byteLength)
1589
- return false;
1590
- if (left instanceof DataView)
1591
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1592
- for (let i = 0; i < len; ++i) {
1593
- if (left[i] !== right[i])
1594
- return false;
1595
- }
1596
- return true;
1597
- }
1598
- function compare_iterator(left, right) {
1599
- while (true) {
1600
- const left_next = left.next();
1601
- const right_next = right.next();
1602
- if (left_next.done !== right_next.done)
1603
- return false;
1604
- if (left_next.done)
1605
- break;
1606
- if (!$mol_compare_deep(left_next.value, right_next.value))
1607
- return false;
1608
- }
1609
- return true;
1610
- }
1611
- function compare_set(left, right) {
1612
- if (left.size !== right.size)
1613
- return false;
1614
- return compare_iterator(left.values(), right.values());
1615
- }
1616
- function compare_map(left, right) {
1617
- if (left.size !== right.size)
1618
- return false;
1619
- return compare_iterator(left.keys(), right.keys())
1620
- && compare_iterator(left.values(), right.values());
1621
- }
1622
- function compare_pojo(left, right) {
1623
- const left_keys = Object.getOwnPropertyNames(left);
1624
- const right_keys = Object.getOwnPropertyNames(right);
1625
- if (!compare_array(left_keys, right_keys))
1626
- return false;
1627
- for (let key of left_keys) {
1628
- if (!$mol_compare_deep(left[key], right[key]))
1629
- return false;
1630
- }
1631
- const left_syms = Object.getOwnPropertySymbols(left);
1632
- const right_syms = Object.getOwnPropertySymbols(right);
1633
- if (!compare_array(left_syms, right_syms))
1634
- return false;
1635
- for (let key of left_syms) {
1636
- if (!$mol_compare_deep(left[key], right[key]))
1637
- return false;
1599
+ class $mol_term_color {
1600
+ static reset = this.ansi(0, 0);
1601
+ static bold = this.ansi(1, 22);
1602
+ static italic = this.ansi(3, 23);
1603
+ static underline = this.ansi(4, 24);
1604
+ static inverse = this.ansi(7, 27);
1605
+ static hidden = this.ansi(8, 28);
1606
+ static strike = this.ansi(9, 29);
1607
+ static gray = this.ansi(90, 39);
1608
+ static red = this.ansi(91, 39);
1609
+ static green = this.ansi(92, 39);
1610
+ static yellow = this.ansi(93, 39);
1611
+ static blue = this.ansi(94, 39);
1612
+ static magenta = this.ansi(95, 39);
1613
+ static cyan = this.ansi(96, 39);
1614
+ static Gray = (str) => this.inverse(this.gray(str));
1615
+ static Red = (str) => this.inverse(this.red(str));
1616
+ static Green = (str) => this.inverse(this.green(str));
1617
+ static Yellow = (str) => this.inverse(this.yellow(str));
1618
+ static Blue = (str) => this.inverse(this.blue(str));
1619
+ static Magenta = (str) => this.inverse(this.magenta(str));
1620
+ static Cyan = (str) => this.inverse(this.cyan(str));
1621
+ static ansi(open, close) {
1622
+ if (typeof process === 'undefined')
1623
+ return String;
1624
+ if (!process.stdout.isTTY)
1625
+ return String;
1626
+ const prefix = `\x1b[${open}m`;
1627
+ const postfix = `\x1b[${close}m`;
1628
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1629
+ return function colorer(str) {
1630
+ str = String(str);
1631
+ if (str === '')
1632
+ return str;
1633
+ const suffix = str.replace(suffix_regexp, prefix);
1634
+ return prefix + suffix + postfix;
1635
+ };
1638
1636
  }
1639
- return true;
1640
1637
  }
1641
- function compare_primitive(left, right) {
1642
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1638
+ $.$mol_term_color = $mol_term_color;
1639
+ })($ || ($ = {}));
1640
+
1641
+ ;
1642
+ "use strict";
1643
+ var $;
1644
+ (function ($) {
1645
+ function $mol_log3_node_make(level, output, type, color) {
1646
+ return function $mol_log3_logger(event) {
1647
+ if (!event.time)
1648
+ event = { time: new Date().toISOString(), ...event };
1649
+ let tree = this.$mol_tree2_from_json(event);
1650
+ tree = tree.struct(type, tree.kids);
1651
+ let str = color(tree.toString());
1652
+ this.console[level](str);
1653
+ const self = this;
1654
+ return () => self.console.groupEnd();
1655
+ };
1643
1656
  }
1657
+ $.$mol_log3_node_make = $mol_log3_node_make;
1658
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1659
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1660
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1661
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1662
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1663
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1644
1664
  })($ || ($ = {}));
1645
1665
 
1646
1666
  ;
@@ -1759,97 +1779,115 @@ var $;
1759
1779
  class $mol_run_error extends $mol_error_mix {
1760
1780
  }
1761
1781
  $.$mol_run_error = $mol_run_error;
1762
- const child_process = $node['child_process'];
1763
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
1764
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
1765
- function $mol_run_async({ dir, timeout, command, env }) {
1766
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
1767
- const [app, ...args] = args_raw;
1768
- if (!env?.MOL_RUN_ASYNC) {
1769
- this.$mol_log3_come({
1770
- place: '$mol_run_sync',
1782
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
1783
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
1784
+ class $mol_run extends $mol_object {
1785
+ static async_enabled() {
1786
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
1787
+ }
1788
+ static spawn(options) {
1789
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
1790
+ const env = options.env ?? this.$.$mol_env();
1791
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
1792
+ }
1793
+ static spawn_async({ dir, sync, timeout, command, env }) {
1794
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1795
+ const [app, ...args] = args_raw;
1796
+ const opts = { shell: true, cwd: dir, env };
1797
+ const log_object = {
1798
+ place: `${this}.spawn()`,
1771
1799
  message: 'Run',
1772
1800
  command: args_raw.join(' '),
1773
1801
  dir: $node.path.relative('', dir),
1802
+ };
1803
+ if (sync) {
1804
+ this.$.$mol_log3_come({
1805
+ hint: 'Run inside fiber',
1806
+ ...log_object
1807
+ });
1808
+ let error;
1809
+ let res;
1810
+ try {
1811
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
1812
+ error = res.error;
1813
+ }
1814
+ catch (err) {
1815
+ error = err;
1816
+ }
1817
+ if (!res || error || res.status) {
1818
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
1819
+ }
1820
+ return res;
1821
+ }
1822
+ let sub;
1823
+ try {
1824
+ sub = this.$.$mol_run_spawn(app, args, {
1825
+ ...opts,
1826
+ stdio: ['pipe', 'inherit', 'inherit'],
1827
+ });
1828
+ }
1829
+ catch (error) {
1830
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
1831
+ }
1832
+ const pid = sub.pid ?? 0;
1833
+ this.$.$mol_log3_come({
1834
+ ...log_object,
1835
+ pid,
1774
1836
  });
1775
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
1776
- if (res.status)
1777
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
1778
- return res;
1779
- }
1780
- const sub = this.$mol_run_spawn(app, args, {
1781
- shell: true,
1782
- cwd: dir,
1783
- env
1784
- });
1785
- this.$mol_log3_come({
1786
- place: '$mol_run_async',
1787
- pid: sub.pid,
1788
- message: 'Run',
1789
- command: args_raw.join(' '),
1790
- dir: $node.path.relative('', dir),
1791
- });
1792
- let killed = false;
1793
- let timer;
1794
- const std_data = [];
1795
- const error_data = [];
1796
- const add = (std_chunk, error_chunk) => {
1797
- if (std_chunk)
1798
- std_data.push(std_chunk);
1799
- if (error_chunk)
1800
- error_data.push(error_chunk);
1801
- if (!timeout)
1802
- return;
1803
- clearTimeout(timer);
1804
- timer = setTimeout(() => {
1805
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
1806
- killed = true;
1807
- add();
1808
- sub.kill(signal);
1809
- }, timeout);
1810
- };
1811
- add();
1812
- sub.stdout?.on('data', data => add(data));
1813
- sub.stderr?.on('data', data => add(undefined, data));
1814
- const promise = new Promise((done, fail) => {
1815
- const close = (error, status = null, signal = null) => {
1816
- if (!timer && timeout)
1837
+ let timeout_kill = false;
1838
+ let timer;
1839
+ const std_data = [];
1840
+ const error_data = [];
1841
+ const add = (std_chunk, error_chunk) => {
1842
+ if (std_chunk)
1843
+ std_data.push(std_chunk);
1844
+ if (error_chunk)
1845
+ error_data.push(error_chunk);
1846
+ if (!timeout)
1817
1847
  return;
1818
1848
  clearTimeout(timer);
1819
- timer = undefined;
1820
- const res = {
1821
- pid: sub.pid,
1822
- status,
1823
- signal,
1824
- get stdout() { return Buffer.concat(std_data); },
1825
- get stderr() { return Buffer.concat(error_data); }
1826
- };
1827
- this.$mol_log3_done({
1828
- place: '$mol_run_async',
1829
- pid: sub.pid,
1830
- message: 'Run',
1831
- status,
1832
- command: args_raw.join(' '),
1833
- dir: $node.path.relative('', dir),
1834
- });
1835
- if (error || status || killed)
1836
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1837
- done(res);
1849
+ timer = setTimeout(() => {
1850
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
1851
+ timeout_kill = true;
1852
+ add();
1853
+ sub.kill(signal);
1854
+ }, timeout);
1838
1855
  };
1839
- sub.on('disconnect', () => close(new Error('Disconnected')));
1840
- sub.on('error', err => close(err));
1841
- sub.on('exit', (status, signal) => close(null, status, signal));
1842
- });
1843
- return Object.assign(promise, { destructor: () => {
1844
- clearTimeout(timer);
1845
- sub.kill('SIGKILL');
1846
- } });
1847
- }
1848
- $.$mol_run_async = $mol_run_async;
1849
- function $mol_run(options) {
1850
- if (!options.env)
1851
- options = { ...options, env: this.$mol_env() };
1852
- return $mol_wire_sync(this).$mol_run_async(options);
1856
+ add();
1857
+ sub.stdout?.on('data', data => add(data));
1858
+ sub.stderr?.on('data', data => add(undefined, data));
1859
+ const result_promise = new Promise((done, fail) => {
1860
+ const close = (error, status = null, signal = null) => {
1861
+ if (!timer && timeout)
1862
+ return;
1863
+ clearTimeout(timer);
1864
+ timer = undefined;
1865
+ const res = {
1866
+ pid,
1867
+ signal,
1868
+ get stdout() { return Buffer.concat(std_data); },
1869
+ get stderr() { return Buffer.concat(error_data); }
1870
+ };
1871
+ if (error || status || timeout_kill)
1872
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
1873
+ this.$.$mol_log3_done({
1874
+ ...log_object,
1875
+ pid,
1876
+ });
1877
+ done(res);
1878
+ };
1879
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1880
+ sub.on('error', err => close(err));
1881
+ sub.on('exit', (status, signal) => close(null, status, signal));
1882
+ });
1883
+ return Object.assign(result_promise, { destructor: () => {
1884
+ clearTimeout(timer);
1885
+ sub.kill('SIGKILL');
1886
+ } });
1887
+ }
1888
+ static error_message(res) {
1889
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
1890
+ }
1853
1891
  }
1854
1892
  $.$mol_run = $mol_run;
1855
1893
  })($ || ($ = {}));
@@ -1859,7 +1897,7 @@ var $;
1859
1897
  var $;
1860
1898
  (function ($) {
1861
1899
  function $mol_exec(dir, command, ...args) {
1862
- return this.$mol_run({ command: [command, ...args], dir });
1900
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
1863
1901
  }
1864
1902
  $.$mol_exec = $mol_exec;
1865
1903
  })($ || ($ = {}));
@@ -3018,6 +3056,25 @@ var $;
3018
3056
  });
3019
3057
  })($ || ($ = {}));
3020
3058
 
3059
+ ;
3060
+ "use strict";
3061
+ var $;
3062
+ (function ($) {
3063
+ $mol_test({
3064
+ 'init with overload'() {
3065
+ class X extends $mol_object {
3066
+ foo() {
3067
+ return 1;
3068
+ }
3069
+ }
3070
+ var x = X.make({
3071
+ foo: () => 2,
3072
+ });
3073
+ $mol_assert_equal(x.foo(), 2);
3074
+ },
3075
+ });
3076
+ })($ || ($ = {}));
3077
+
3021
3078
  ;
3022
3079
  "use strict";
3023
3080
  var $;
@@ -4240,23 +4297,49 @@ var $;
4240
4297
  $mol_test({
4241
4298
  async 'exec timeout auto kill child process'($) {
4242
4299
  let close_mock = () => { };
4243
- const context_mock = $.$mol_ambient({
4244
- $mol_run_spawn: () => ({
4300
+ const error_message = 'Run error, timeout';
4301
+ function mol_run_spawn_sync_mock() {
4302
+ return {
4303
+ output: [],
4304
+ stdout: error_message,
4305
+ stderr: '',
4306
+ status: 0,
4307
+ signal: null,
4308
+ pid: 123,
4309
+ };
4310
+ }
4311
+ function mol_run_spawn_mock() {
4312
+ return {
4245
4313
  on(name, cb) {
4246
4314
  if (name === 'exit')
4247
4315
  close_mock = cb;
4248
4316
  },
4249
4317
  kill() { close_mock(); }
4250
- })
4318
+ };
4319
+ }
4320
+ const context_mock = $.$mol_ambient({
4321
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
4322
+ $mol_run_spawn: mol_run_spawn_mock
4251
4323
  });
4324
+ class $mol_run_mock extends $mol_run {
4325
+ static get $() { return context_mock; }
4326
+ static async_enabled() {
4327
+ return true;
4328
+ }
4329
+ }
4252
4330
  let message = '';
4253
4331
  try {
4254
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
4332
+ const res = await $mol_wire_async($mol_run_mock).spawn({
4333
+ command: 'sleep 10',
4334
+ dir: '.',
4335
+ timeout: 10,
4336
+ env: { 'MOL_RUN_ASYNC': '1' }
4337
+ });
4255
4338
  }
4256
4339
  catch (e) {
4257
4340
  message = e.message;
4258
4341
  }
4259
- $mol_assert_equal(message, 'Run error, timeout');
4342
+ $mol_assert_equal(message, error_message);
4260
4343
  }
4261
4344
  });
4262
4345
  })($ || ($ = {}));