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