hyoo_sync_client 0.0.377 → 0.0.378

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.mjs CHANGED
@@ -244,1568 +244,1124 @@ var $;
244
244
  "use strict";
245
245
  var $;
246
246
  (function ($) {
247
- let $mol_wire_cursor;
248
- (function ($mol_wire_cursor) {
249
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
250
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
251
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
252
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
253
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
247
+ function $mol_promise_like(val) {
248
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
249
+ }
250
+ $.$mol_promise_like = $mol_promise_like;
254
251
  })($ || ($ = {}));
255
252
 
256
253
  ;
257
254
  "use strict";
258
255
  var $;
259
256
  (function ($) {
260
- class $mol_wire_pub extends Object {
261
- data = [];
262
- static get [Symbol.species]() {
263
- return Array;
264
- }
265
- sub_from = 0;
266
- get sub_list() {
267
- const res = [];
268
- for (let i = this.sub_from; i < this.data.length; i += 2) {
269
- res.push(this.data[i]);
270
- }
271
- return res;
272
- }
273
- get sub_empty() {
274
- return this.sub_from === this.data.length;
275
- }
276
- sub_on(sub, pub_pos) {
277
- const pos = this.data.length;
278
- this.data.push(sub, pub_pos);
279
- return pos;
280
- }
281
- sub_off(sub_pos) {
282
- if (!(sub_pos < this.data.length)) {
283
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
284
- }
285
- const end = this.data.length - 2;
286
- if (sub_pos !== end) {
287
- this.peer_move(end, sub_pos);
288
- }
289
- this.data.pop();
290
- this.data.pop();
291
- if (this.data.length === this.sub_from)
292
- this.reap();
293
- }
294
- reap() { }
295
- promote() {
296
- $mol_wire_auto()?.track_next(this);
297
- }
298
- fresh() { }
299
- complete() { }
300
- get incompleted() {
257
+ const catched = new WeakMap();
258
+ function $mol_fail_catch(error) {
259
+ if (typeof error !== 'object')
301
260
  return false;
302
- }
303
- emit(quant = $mol_wire_cursor.stale) {
304
- for (let i = this.sub_from; i < this.data.length; i += 2) {
305
- ;
306
- this.data[i].absorb(quant);
307
- }
308
- }
309
- peer_move(from_pos, to_pos) {
310
- const peer = this.data[from_pos];
311
- const self_pos = this.data[from_pos + 1];
312
- this.data[to_pos] = peer;
313
- this.data[to_pos + 1] = self_pos;
314
- peer.peer_repos(self_pos, to_pos);
315
- }
316
- peer_repos(peer_pos, self_pos) {
317
- this.data[peer_pos + 1] = self_pos;
318
- }
261
+ if ($mol_promise_like(error))
262
+ $mol_fail_hidden(error);
263
+ if (catched.get(error))
264
+ return false;
265
+ catched.set(error, true);
266
+ return true;
319
267
  }
320
- $.$mol_wire_pub = $mol_wire_pub;
268
+ $.$mol_fail_catch = $mol_fail_catch;
321
269
  })($ || ($ = {}));
322
270
 
323
- ;
324
- "use strict";
325
-
326
271
  ;
327
272
  "use strict";
328
273
  var $;
329
274
  (function ($) {
330
- $.$mol_wire_auto_sub = null;
331
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
332
- return $.$mol_wire_auto_sub = next;
275
+ function $mol_fail_log(error) {
276
+ if ($mol_promise_like(error))
277
+ return false;
278
+ if (!$mol_fail_catch(error))
279
+ return false;
280
+ console.error(error);
281
+ return true;
333
282
  }
334
- $.$mol_wire_auto = $mol_wire_auto;
335
- $.$mol_wire_affected = [];
283
+ $.$mol_fail_log = $mol_fail_log;
336
284
  })($ || ($ = {}));
337
285
 
338
286
  ;
339
287
  "use strict";
340
- var $;
341
- (function ($) {
342
- $['devtoolsFormatters'] ||= [];
343
- function $mol_dev_format_register(config) {
344
- $['devtoolsFormatters'].push(config);
345
- }
346
- $.$mol_dev_format_register = $mol_dev_format_register;
347
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
348
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
349
- $mol_dev_format_register({
350
- header: (val, config = false) => {
351
- if (config)
352
- return null;
353
- if (!val)
354
- return null;
355
- if ($.$mol_dev_format_head in val) {
288
+ var $node = new Proxy({ require }, {
289
+ get(target, name, wrapper) {
290
+ if (target[name])
291
+ return target[name];
292
+ const mod = target.require('module');
293
+ if (mod.builtinModules.indexOf(name) >= 0)
294
+ return target.require(name);
295
+ if (name[0] === '.')
296
+ return target.require(name);
297
+ const path = target.require('path');
298
+ const fs = target.require('fs');
299
+ let dir = path.resolve('.');
300
+ const suffix = `./node_modules/${name}`;
301
+ const $$ = $;
302
+ while (!fs.existsSync(path.join(dir, suffix))) {
303
+ const parent = path.resolve(dir, '..');
304
+ if (parent === dir) {
305
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
356
306
  try {
357
- return val[$.$mol_dev_format_head]();
358
- }
359
- catch (error) {
360
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
307
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
361
308
  }
309
+ catch { }
310
+ break;
362
311
  }
363
- if (typeof val === 'function') {
364
- return $mol_dev_format_native(val);
312
+ else {
313
+ dir = parent;
365
314
  }
366
- if (Symbol.toStringTag in val) {
367
- return $mol_dev_format_native(val);
315
+ }
316
+ try {
317
+ return target.require(name);
318
+ }
319
+ catch (error) {
320
+ if (error.code === 'ERR_REQUIRE_ESM') {
321
+ const module = cache.get(name);
322
+ if (module)
323
+ return module;
324
+ throw import(name).then(module => cache.set(name, module));
368
325
  }
326
+ $.$mol_fail_log(error);
369
327
  return null;
370
- },
371
- hasBody: val => val[$.$mol_dev_format_body],
372
- body: val => val[$.$mol_dev_format_body](),
373
- });
374
- function $mol_dev_format_native(obj) {
375
- if (typeof obj === 'undefined')
376
- return $.$mol_dev_format_shade('undefined');
377
- return [
378
- 'object',
379
- {
380
- object: obj,
381
- config: true,
382
- },
383
- ];
384
- }
385
- $.$mol_dev_format_native = $mol_dev_format_native;
386
- function $mol_dev_format_auto(obj) {
387
- if (obj == null)
388
- return $.$mol_dev_format_shade(String(obj));
389
- return [
390
- 'object',
391
- {
392
- object: obj,
393
- config: false,
394
- },
395
- ];
396
- }
397
- $.$mol_dev_format_auto = $mol_dev_format_auto;
398
- function $mol_dev_format_element(element, style, ...content) {
399
- const styles = [];
400
- for (let key in style)
401
- styles.push(`${key} : ${style[key]}`);
402
- return [
403
- element,
404
- {
405
- style: styles.join(' ; '),
406
- },
407
- ...content,
408
- ];
409
- }
410
- $.$mol_dev_format_element = $mol_dev_format_element;
411
- function $mol_dev_format_span(style, ...content) {
412
- return $mol_dev_format_element('span', {
413
- ...style,
414
- }, ...content);
328
+ }
329
+ },
330
+ set(target, name, value) {
331
+ target[name] = value;
332
+ return true;
333
+ },
334
+ });
335
+ const cache = new Map();
336
+ require = (req => Object.assign(function require(name) {
337
+ return $node[name];
338
+ }, req))(require);
339
+
340
+ ;
341
+ "use strict";
342
+ var $;
343
+ (function ($) {
344
+ function $mol_log3_area_lazy(event) {
345
+ const self = this;
346
+ const stack = self.$mol_log3_stack;
347
+ const deep = stack.length;
348
+ let logged = false;
349
+ stack.push(() => {
350
+ logged = true;
351
+ self.$mol_log3_area.call(self, event);
352
+ });
353
+ return () => {
354
+ if (logged)
355
+ self.console.groupEnd();
356
+ if (stack.length > deep)
357
+ stack.length = deep;
358
+ };
415
359
  }
416
- $.$mol_dev_format_span = $mol_dev_format_span;
417
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
418
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
419
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
420
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
421
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
422
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
423
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
424
- 'color': 'magenta',
425
- });
426
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
427
- 'font-weight': 'bold',
428
- });
429
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
430
- 'color': 'green',
431
- });
432
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
433
- 'color': 'gray',
434
- });
435
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
436
- 'margin-left': '13px'
437
- });
360
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
361
+ $.$mol_log3_stack = [];
438
362
  })($ || ($ = {}));
439
363
 
440
364
  ;
441
365
  "use strict";
442
366
  var $;
443
367
  (function ($) {
444
- class $mol_wire_pub_sub extends $mol_wire_pub {
445
- pub_from = 0;
446
- cursor = $mol_wire_cursor.stale;
447
- get temp() {
448
- return false;
449
- }
450
- get pub_list() {
451
- const res = [];
452
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
453
- for (let i = this.pub_from; i < max; i += 2) {
454
- if (this.data[i])
455
- res.push(this.data[i]);
456
- }
457
- return res;
458
- }
459
- track_on() {
460
- this.cursor = this.pub_from;
461
- const sub = $mol_wire_auto();
462
- $mol_wire_auto(this);
463
- return sub;
464
- }
465
- promote() {
466
- if (this.cursor >= this.pub_from) {
467
- $mol_fail(new Error('Circular subscription'));
468
- }
469
- super.promote();
368
+ class $mol_span extends $mol_object2 {
369
+ uri;
370
+ source;
371
+ row;
372
+ col;
373
+ length;
374
+ constructor(uri, source, row, col, length) {
375
+ super();
376
+ this.uri = uri;
377
+ this.source = source;
378
+ this.row = row;
379
+ this.col = col;
380
+ this.length = length;
381
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
470
382
  }
471
- track_next(pub) {
472
- if (this.cursor < 0)
473
- $mol_fail(new Error('Promo to non begun sub'));
474
- if (this.cursor < this.sub_from) {
475
- const next = this.data[this.cursor];
476
- if (pub === undefined)
477
- return next ?? null;
478
- if (next === pub) {
479
- this.cursor += 2;
480
- return next;
481
- }
482
- if (next) {
483
- if (this.sub_from < this.data.length) {
484
- this.peer_move(this.sub_from, this.data.length);
485
- }
486
- this.peer_move(this.cursor, this.sub_from);
487
- this.sub_from += 2;
488
- }
489
- }
490
- else {
491
- if (pub === undefined)
492
- return null;
493
- if (this.sub_from < this.data.length) {
494
- this.peer_move(this.sub_from, this.data.length);
495
- }
496
- this.sub_from += 2;
497
- }
498
- this.data[this.cursor] = pub;
499
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
500
- this.cursor += 2;
501
- return pub;
383
+ static unknown = $mol_span.begin('?');
384
+ static begin(uri, source = '') {
385
+ return new $mol_span(uri, source, 1, 1, 0);
502
386
  }
503
- track_off(sub) {
504
- $mol_wire_auto(sub);
505
- if (this.cursor < 0) {
506
- $mol_fail(new Error('End of non begun sub'));
507
- }
508
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
509
- const pub = this.data[cursor];
510
- pub.fresh();
511
- }
512
- this.cursor = $mol_wire_cursor.fresh;
387
+ static end(uri, source) {
388
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
513
389
  }
514
- pub_off(sub_pos) {
515
- this.data[sub_pos] = undefined;
516
- this.data[sub_pos + 1] = undefined;
390
+ static entire(uri, source) {
391
+ return new $mol_span(uri, source, 1, 1, source.length);
517
392
  }
518
- destructor() {
519
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
520
- const sub = this.data[cursor];
521
- const pos = this.data[cursor + 1];
522
- sub.pub_off(pos);
523
- this.data.pop();
524
- this.data.pop();
525
- }
526
- this.cursor = this.pub_from;
527
- this.track_cut();
528
- this.cursor = $mol_wire_cursor.final;
393
+ toString() {
394
+ return this[Symbol.toStringTag];
529
395
  }
530
- track_cut() {
531
- if (this.cursor < this.pub_from) {
532
- $mol_fail(new Error('Cut of non begun sub'));
533
- }
534
- let tail = 0;
535
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
536
- const pub = this.data[cursor];
537
- pub?.sub_off(this.data[cursor + 1]);
538
- if (this.sub_from < this.data.length) {
539
- this.peer_move(this.data.length - 2, cursor);
540
- this.data.pop();
541
- this.data.pop();
542
- }
543
- else {
544
- ++tail;
545
- }
546
- }
547
- for (; tail; --tail) {
548
- this.data.pop();
549
- this.data.pop();
550
- }
551
- this.sub_from = this.cursor;
396
+ toJSON() {
397
+ return {
398
+ uri: this.uri,
399
+ row: this.row,
400
+ col: this.col,
401
+ length: this.length
402
+ };
552
403
  }
553
- complete() { }
554
- complete_pubs() {
555
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
556
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
557
- const pub = this.data[cursor];
558
- if (pub?.incompleted)
559
- return;
560
- }
561
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
562
- const pub = this.data[cursor];
563
- pub?.complete();
564
- }
404
+ error(message, Class = Error) {
405
+ return new Class(`${message} (${this})`);
565
406
  }
566
- absorb(quant = $mol_wire_cursor.stale) {
567
- if (this.cursor === $mol_wire_cursor.final)
568
- return;
569
- if (this.cursor >= quant)
570
- return;
571
- this.cursor = quant;
572
- this.emit($mol_wire_cursor.doubt);
407
+ span(row, col, length) {
408
+ return new $mol_span(this.uri, this.source, row, col, length);
573
409
  }
574
- [$mol_dev_format_head]() {
575
- return $mol_dev_format_native(this);
410
+ after(length = 0) {
411
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
576
412
  }
577
- get pub_empty() {
578
- return this.sub_from === this.pub_from;
413
+ slice(begin, end = -1) {
414
+ let len = this.length;
415
+ if (begin < 0)
416
+ begin += len;
417
+ if (end < 0)
418
+ end += len;
419
+ if (begin < 0 || begin > len)
420
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
421
+ if (end < 0 || end > len)
422
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
423
+ if (end < begin)
424
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
425
+ return this.span(this.row, this.col + begin, end - begin);
579
426
  }
580
427
  }
581
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
428
+ $.$mol_span = $mol_span;
582
429
  })($ || ($ = {}));
583
430
 
584
431
  ;
585
432
  "use strict";
586
433
  var $;
587
434
  (function ($) {
588
- class $mol_after_timeout extends $mol_object2 {
589
- delay;
590
- task;
591
- id;
592
- constructor(delay, task) {
593
- super();
594
- this.delay = delay;
595
- this.task = task;
596
- this.id = setTimeout(task, delay);
597
- }
598
- destructor() {
599
- clearTimeout(this.id);
435
+ function $mol_tree2_to_string(tree) {
436
+ let output = [];
437
+ function dump(tree, prefix = '') {
438
+ if (tree.type.length) {
439
+ if (!prefix.length) {
440
+ prefix = "\t";
441
+ }
442
+ output.push(tree.type);
443
+ if (tree.kids.length == 1) {
444
+ output.push(' ');
445
+ dump(tree.kids[0], prefix);
446
+ return;
447
+ }
448
+ output.push("\n");
449
+ }
450
+ else if (tree.value.length || prefix.length) {
451
+ output.push("\\" + tree.value + "\n");
452
+ }
453
+ for (const kid of tree.kids) {
454
+ output.push(prefix);
455
+ dump(kid, prefix + "\t");
456
+ }
600
457
  }
458
+ dump(tree);
459
+ return output.join('');
601
460
  }
602
- $.$mol_after_timeout = $mol_after_timeout;
461
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
603
462
  })($ || ($ = {}));
604
463
 
605
464
  ;
606
465
  "use strict";
607
466
  var $;
608
467
  (function ($) {
609
- class $mol_after_frame extends $mol_after_timeout {
610
- task;
611
- constructor(task) {
612
- super(16, task);
613
- this.task = task;
468
+ class $mol_tree2 extends Object {
469
+ type;
470
+ value;
471
+ kids;
472
+ span;
473
+ constructor(type, value, kids, span) {
474
+ super();
475
+ this.type = type;
476
+ this.value = value;
477
+ this.kids = kids;
478
+ this.span = span;
479
+ this[Symbol.toStringTag] = type || '\\' + value;
614
480
  }
615
- }
616
- $.$mol_after_frame = $mol_after_frame;
617
- })($ || ($ = {}));
618
-
619
- ;
620
- "use strict";
621
- var $;
622
- (function ($) {
623
- function $mol_promise_like(val) {
624
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
625
- }
626
- $.$mol_promise_like = $mol_promise_like;
627
- })($ || ($ = {}));
628
-
629
- ;
630
- "use strict";
631
- var $;
632
- (function ($) {
633
- const handled = new WeakSet();
634
- class $mol_wire_fiber extends $mol_wire_pub_sub {
635
- task;
636
- host;
637
- static warm = true;
638
- static planning = new Set();
639
- static reaping = new Set();
640
- static plan_task = null;
641
- static plan() {
642
- if (this.plan_task)
643
- return;
644
- this.plan_task = new $mol_after_frame(() => {
645
- try {
646
- this.sync();
647
- }
648
- finally {
649
- $mol_wire_fiber.plan_task = null;
650
- }
651
- });
481
+ static list(kids, span = $mol_span.unknown) {
482
+ return new $mol_tree2('', '', kids, span);
652
483
  }
653
- static sync() {
654
- while (this.planning.size) {
655
- for (const fiber of this.planning) {
656
- this.planning.delete(fiber);
657
- if (fiber.cursor >= 0)
658
- continue;
659
- if (fiber.cursor === $mol_wire_cursor.final)
660
- continue;
661
- fiber.fresh();
662
- }
663
- }
664
- while (this.reaping.size) {
665
- const fibers = this.reaping;
666
- this.reaping = new Set;
667
- for (const fiber of fibers) {
668
- if (!fiber.sub_empty)
669
- continue;
670
- fiber.destructor();
671
- }
672
- }
484
+ list(kids) {
485
+ return $mol_tree2.list(kids, this.span);
673
486
  }
674
- [Symbol.toStringTag];
675
- cache = undefined;
676
- get args() {
677
- return this.data.slice(0, this.pub_from);
487
+ static data(value, kids = [], span = $mol_span.unknown) {
488
+ const chunks = value.split('\n');
489
+ if (chunks.length > 1) {
490
+ let kid_span = span.span(span.row, span.col, 0);
491
+ const data = chunks.map(chunk => {
492
+ kid_span = kid_span.after(chunk.length);
493
+ return new $mol_tree2('', chunk, [], kid_span);
494
+ });
495
+ kids = [...data, ...kids];
496
+ value = '';
497
+ }
498
+ return new $mol_tree2('', value, kids, span);
678
499
  }
679
- result() {
680
- if ($mol_promise_like(this.cache))
681
- return;
682
- if (this.cache instanceof Error)
683
- return;
684
- return this.cache;
500
+ data(value, kids = []) {
501
+ return $mol_tree2.data(value, kids, this.span);
685
502
  }
686
- get incompleted() {
687
- return $mol_promise_like(this.cache);
503
+ static struct(type, kids = [], span = $mol_span.unknown) {
504
+ if (/[ \n\t\\]/.test(type)) {
505
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
506
+ }
507
+ return new $mol_tree2(type, '', kids, span);
688
508
  }
689
- field() {
690
- return this.task.name + '<>';
509
+ struct(type, kids = []) {
510
+ return $mol_tree2.struct(type, kids, this.span);
691
511
  }
692
- constructor(id, task, host, args) {
693
- super();
694
- this.task = task;
695
- this.host = host;
696
- if (args)
697
- this.data.push(...args);
698
- this.pub_from = this.sub_from = args?.length ?? 0;
699
- this[Symbol.toStringTag] = id;
512
+ clone(kids, span = this.span) {
513
+ return new $mol_tree2(this.type, this.value, kids, span);
700
514
  }
701
- plan() {
702
- $mol_wire_fiber.planning.add(this);
703
- $mol_wire_fiber.plan();
515
+ text() {
516
+ var values = [];
517
+ for (var kid of this.kids) {
518
+ if (kid.type)
519
+ continue;
520
+ values.push(kid.value);
521
+ }
522
+ return this.value + values.join('\n');
704
523
  }
705
- reap() {
706
- $mol_wire_fiber.reaping.add(this);
707
- $mol_wire_fiber.plan();
524
+ static fromString(str, uri = 'unknown') {
525
+ return $$.$mol_tree2_from_string(str, uri);
708
526
  }
709
527
  toString() {
710
- return this[Symbol.toStringTag];
711
- }
712
- toJSON() {
713
- return this[Symbol.toStringTag];
714
- }
715
- [$mol_dev_format_head]() {
716
- const cursor = {
717
- [$mol_wire_cursor.stale]: '🔴',
718
- [$mol_wire_cursor.doubt]: '🟡',
719
- [$mol_wire_cursor.fresh]: '🟢',
720
- [$mol_wire_cursor.final]: '🔵',
721
- }[this.cursor] ?? this.cursor.toString();
722
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
723
- ? $mol_dev_format_auto({
724
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
725
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
726
- })
727
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
728
- }
729
- get $() {
730
- return (this.host ?? this.task)['$'];
731
- }
732
- emit(quant = $mol_wire_cursor.stale) {
733
- if (this.sub_empty)
734
- this.plan();
735
- else
736
- super.emit(quant);
528
+ return $$.$mol_tree2_to_string(this);
737
529
  }
738
- fresh() {
739
- if (this.cursor === $mol_wire_cursor.fresh)
740
- return;
741
- if (this.cursor === $mol_wire_cursor.final)
742
- return;
743
- check: if (this.cursor === $mol_wire_cursor.doubt) {
744
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
745
- ;
746
- this.data[i]?.fresh();
747
- if (this.cursor !== $mol_wire_cursor.doubt)
748
- break check;
530
+ insert(value, ...path) {
531
+ if (path.length === 0)
532
+ return value;
533
+ const type = path[0];
534
+ if (typeof type === 'string') {
535
+ let replaced = false;
536
+ const sub = this.kids.map((item, index) => {
537
+ if (item.type !== type)
538
+ return item;
539
+ replaced = true;
540
+ return item.insert(value, ...path.slice(1));
541
+ }).filter(Boolean);
542
+ if (!replaced && value) {
543
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
749
544
  }
750
- this.cursor = $mol_wire_cursor.fresh;
751
- return;
545
+ return this.clone(sub);
752
546
  }
753
- const bu = this.track_on();
754
- let result;
755
- try {
756
- switch (this.pub_from) {
757
- case 0:
758
- result = this.task.call(this.host);
759
- break;
760
- case 1:
761
- result = this.task.call(this.host, this.data[0]);
762
- break;
763
- default:
764
- result = this.task.call(this.host, ...this.args);
765
- break;
766
- }
767
- if ($mol_promise_like(result) && !handled.has(result)) {
768
- const put = (res) => {
769
- if (this.cache === result)
770
- this.put(res);
771
- return res;
772
- };
773
- result = result.then(put, put);
547
+ else if (typeof type === 'number') {
548
+ const sub = this.kids.slice();
549
+ sub[type] = (sub[type] || this.list([]))
550
+ .insert(value, ...path.slice(1));
551
+ return this.clone(sub.filter(Boolean));
552
+ }
553
+ else {
554
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
555
+ .map(item => item.insert(value, ...path.slice(1)))
556
+ .filter(Boolean);
557
+ return this.clone(kids);
558
+ }
559
+ }
560
+ select(...path) {
561
+ let next = [this];
562
+ for (const type of path) {
563
+ if (!next.length)
564
+ break;
565
+ const prev = next;
566
+ next = [];
567
+ for (var item of prev) {
568
+ switch (typeof (type)) {
569
+ case 'string':
570
+ for (var child of item.kids) {
571
+ if (child.type == type) {
572
+ next.push(child);
573
+ }
574
+ }
575
+ break;
576
+ case 'number':
577
+ if (type < item.kids.length)
578
+ next.push(item.kids[type]);
579
+ break;
580
+ default: next.push(...item.kids);
581
+ }
774
582
  }
775
583
  }
776
- catch (error) {
777
- if (error instanceof Error || $mol_promise_like(error)) {
778
- result = error;
584
+ return this.list(next);
585
+ }
586
+ filter(path, value) {
587
+ const sub = this.kids.filter(item => {
588
+ var found = item.select(...path);
589
+ if (value === undefined) {
590
+ return Boolean(found.kids.length);
779
591
  }
780
592
  else {
781
- result = new Error(String(error), { cause: error });
782
- }
783
- if ($mol_promise_like(result) && !handled.has(result)) {
784
- result = result.finally(() => {
785
- if (this.cache === result)
786
- this.absorb();
787
- });
593
+ return found.kids.some(child => child.value == value);
788
594
  }
595
+ });
596
+ return this.clone(sub);
597
+ }
598
+ hack_self(belt, context = {}) {
599
+ let handle = belt[this.type] || belt[''];
600
+ if (!handle || handle === Object.prototype[this.type]) {
601
+ handle = (input, belt, context) => [
602
+ input.clone(input.hack(belt, context), context.span)
603
+ ];
789
604
  }
790
- if ($mol_promise_like(result) && !handled.has(result)) {
791
- result = Object.assign(result, {
792
- destructor: result['destructor'] ?? (() => { })
793
- });
794
- handled.add(result);
795
- const error = new Error(`Promise in ${this}`);
796
- Object.defineProperty(result, 'stack', { get: () => error.stack });
605
+ try {
606
+ return handle(this, belt, context);
797
607
  }
798
- if (!$mol_promise_like(result)) {
799
- this.track_cut();
608
+ catch (error) {
609
+ error.message += `\n${this.clone([])}${this.span}`;
610
+ $mol_fail_hidden(error);
800
611
  }
801
- this.track_off(bu);
802
- this.put(result);
803
612
  }
804
- refresh() {
805
- this.cursor = $mol_wire_cursor.stale;
806
- this.fresh();
613
+ hack(belt, context = {}) {
614
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
807
615
  }
808
- sync() {
809
- if (!$mol_wire_fiber.warm) {
810
- return this.result();
811
- }
812
- this.promote();
813
- this.fresh();
814
- if (this.cache instanceof Error) {
815
- return $mol_fail_hidden(this.cache);
616
+ error(message, Class = Error) {
617
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
618
+ }
619
+ }
620
+ $.$mol_tree2 = $mol_tree2;
621
+ class $mol_tree2_empty extends $mol_tree2 {
622
+ constructor() {
623
+ super('', '', [], $mol_span.unknown);
624
+ }
625
+ }
626
+ $.$mol_tree2_empty = $mol_tree2_empty;
627
+ })($ || ($ = {}));
628
+
629
+ ;
630
+ "use strict";
631
+ var $;
632
+ (function ($) {
633
+ class $mol_error_syntax extends SyntaxError {
634
+ reason;
635
+ line;
636
+ span;
637
+ constructor(reason, line, span) {
638
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
639
+ this.reason = reason;
640
+ this.line = line;
641
+ this.span = span;
642
+ }
643
+ }
644
+ $.$mol_error_syntax = $mol_error_syntax;
645
+ })($ || ($ = {}));
646
+
647
+ ;
648
+ "use strict";
649
+ var $;
650
+ (function ($) {
651
+ function $mol_tree2_from_string(str, uri = '?') {
652
+ const span = $mol_span.entire(uri, str);
653
+ var root = $mol_tree2.list([], span);
654
+ var stack = [root];
655
+ var pos = 0, row = 0, min_indent = 0;
656
+ while (str.length > pos) {
657
+ var indent = 0;
658
+ var line_start = pos;
659
+ row++;
660
+ while (str.length > pos && str[pos] == '\t') {
661
+ indent++;
662
+ pos++;
816
663
  }
817
- if ($mol_promise_like(this.cache)) {
818
- return $mol_fail_hidden(this.cache);
664
+ if (!root.kids.length) {
665
+ min_indent = indent;
819
666
  }
820
- return this.cache;
821
- }
822
- async async() {
823
- while (true) {
824
- this.fresh();
825
- if (this.cache instanceof Error) {
826
- $mol_fail_hidden(this.cache);
667
+ indent -= min_indent;
668
+ if (indent < 0 || indent >= stack.length) {
669
+ const sp = span.span(row, 1, pos - line_start);
670
+ while (str.length > pos && str[pos] != '\n') {
671
+ pos++;
827
672
  }
828
- if (!$mol_promise_like(this.cache))
829
- return this.cache;
830
- await Promise.race([this.cache, this.step()]);
831
- if (!$mol_promise_like(this.cache))
832
- return this.cache;
833
- if (this.cursor === $mol_wire_cursor.final) {
834
- await new Promise(() => { });
673
+ if (indent < 0) {
674
+ if (str.length > pos) {
675
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
676
+ }
677
+ }
678
+ else {
679
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
835
680
  }
836
681
  }
682
+ stack.length = indent + 1;
683
+ var parent = stack[indent];
684
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
685
+ var error_start = pos;
686
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
687
+ pos++;
688
+ }
689
+ if (pos > error_start) {
690
+ let line_end = str.indexOf('\n', pos);
691
+ if (line_end === -1)
692
+ line_end = str.length;
693
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
694
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
695
+ }
696
+ var type_start = pos;
697
+ while (str.length > pos &&
698
+ str[pos] != '\\' &&
699
+ str[pos] != ' ' &&
700
+ str[pos] != '\t' &&
701
+ str[pos] != '\n') {
702
+ pos++;
703
+ }
704
+ if (pos > type_start) {
705
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
706
+ const parent_kids = parent.kids;
707
+ parent_kids.push(next);
708
+ parent = next;
709
+ }
710
+ if (str.length > pos && str[pos] == ' ') {
711
+ pos++;
712
+ }
713
+ }
714
+ if (str.length > pos && str[pos] == '\\') {
715
+ var data_start = pos;
716
+ while (str.length > pos && str[pos] != '\n') {
717
+ pos++;
718
+ }
719
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
720
+ const parent_kids = parent.kids;
721
+ parent_kids.push(next);
722
+ parent = next;
723
+ }
724
+ if (str.length === pos && stack.length > 0) {
725
+ const sp = span.span(row, pos - line_start + 1, 1);
726
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
727
+ }
728
+ stack.push(parent);
729
+ pos++;
837
730
  }
838
- step() {
839
- return new Promise(done => {
840
- const sub = new $mol_wire_pub_sub;
841
- const prev = sub.track_on();
842
- sub.track_next(this);
843
- sub.track_off(prev);
844
- sub.absorb = () => {
845
- done(null);
846
- sub.destructor();
847
- };
848
- });
849
- }
731
+ return root;
850
732
  }
851
- $.$mol_wire_fiber = $mol_wire_fiber;
733
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
852
734
  })($ || ($ = {}));
853
735
 
854
736
  ;
855
737
  "use strict";
856
738
  var $;
857
739
  (function ($) {
858
- $.$mol_compare_deep_cache = new WeakMap();
859
- function $mol_compare_deep(left, right) {
860
- if (Object.is(left, right))
861
- return true;
862
- if (left === null)
863
- return false;
864
- if (right === null)
865
- return false;
866
- if (typeof left !== 'object')
867
- return false;
868
- if (typeof right !== 'object')
869
- return false;
870
- const left_proto = Reflect.getPrototypeOf(left);
871
- const right_proto = Reflect.getPrototypeOf(right);
872
- if (left_proto !== right_proto)
873
- return false;
874
- if (left instanceof Boolean)
875
- return Object.is(left.valueOf(), right['valueOf']());
876
- if (left instanceof Number)
877
- return Object.is(left.valueOf(), right['valueOf']());
878
- if (left instanceof String)
879
- return Object.is(left.valueOf(), right['valueOf']());
880
- if (left instanceof Date)
881
- return Object.is(left.valueOf(), right['valueOf']());
882
- if (left instanceof RegExp)
883
- return left.source === right.source && left.flags === right.flags;
884
- if (left instanceof Error)
885
- return left.message === right.message && left.stack === right.stack;
886
- let left_cache = $.$mol_compare_deep_cache.get(left);
887
- if (left_cache) {
888
- const right_cache = left_cache.get(right);
889
- if (typeof right_cache === 'boolean')
890
- return right_cache;
740
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
741
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
742
+ return new $mol_tree2(String(json), '', [], span);
891
743
  }
892
- else {
893
- left_cache = new WeakMap([[right, true]]);
894
- $.$mol_compare_deep_cache.set(left, left_cache);
744
+ if (typeof json === 'string') {
745
+ return $mol_tree2.data(json, [], span);
895
746
  }
896
- let result;
897
- try {
898
- if (!left_proto)
899
- result = compare_pojo(left, right);
900
- else if (!Reflect.getPrototypeOf(left_proto))
901
- result = compare_pojo(left, right);
902
- else if (Symbol.toPrimitive in left)
903
- result = compare_primitive(left, right);
904
- else if (Array.isArray(left))
905
- result = compare_array(left, right);
906
- else if (left instanceof Set)
907
- result = compare_set(left, right);
908
- else if (left instanceof Map)
909
- result = compare_map(left, right);
910
- else if (ArrayBuffer.isView(left))
911
- result = compare_buffer(left, right);
912
- else if (Symbol.iterator in left)
913
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
914
- else
915
- result = false;
747
+ if (Array.isArray(json)) {
748
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
749
+ return new $mol_tree2('/', '', sub, span);
916
750
  }
917
- finally {
918
- left_cache.set(right, result);
751
+ if (ArrayBuffer.isView(json)) {
752
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
753
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
919
754
  }
920
- return result;
921
- }
922
- $.$mol_compare_deep = $mol_compare_deep;
923
- function compare_array(left, right) {
924
- const len = left.length;
925
- if (len !== right.length)
926
- return false;
927
- for (let i = 0; i < len; ++i) {
928
- if (!$mol_compare_deep(left[i], right[i]))
929
- return false;
755
+ if (json instanceof Date) {
756
+ return new $mol_tree2('', json.toISOString(), [], span);
930
757
  }
931
- return true;
932
- }
933
- function compare_buffer(left, right) {
934
- const len = left.byteLength;
935
- if (len !== right.byteLength)
936
- return false;
937
- if (left instanceof DataView)
938
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
939
- for (let i = 0; i < len; ++i) {
940
- if (left[i] !== right[i])
941
- return false;
758
+ if (typeof json.toJSON === 'function') {
759
+ return $mol_tree2_from_json(json.toJSON());
942
760
  }
943
- return true;
944
- }
945
- function compare_iterator(left, right) {
946
- while (true) {
947
- const left_next = left.next();
948
- const right_next = right.next();
949
- if (left_next.done !== right_next.done)
950
- return false;
951
- if (left_next.done)
952
- break;
953
- if (!$mol_compare_deep(left_next.value, right_next.value))
954
- return false;
761
+ if (json.toString !== Object.prototype.toString) {
762
+ return $mol_tree2.data(json.toString(), [], span);
955
763
  }
956
- return true;
957
- }
958
- function compare_set(left, right) {
959
- if (left.size !== right.size)
960
- return false;
961
- return compare_iterator(left.values(), right.values());
962
- }
963
- function compare_map(left, right) {
964
- if (left.size !== right.size)
965
- return false;
966
- return compare_iterator(left.keys(), right.keys())
967
- && compare_iterator(left.values(), right.values());
968
- }
969
- function compare_pojo(left, right) {
970
- const left_keys = Object.getOwnPropertyNames(left);
971
- const right_keys = Object.getOwnPropertyNames(right);
972
- if (!compare_array(left_keys, right_keys))
973
- return false;
974
- for (let key of left_keys) {
975
- if (!$mol_compare_deep(left[key], right[key]))
976
- return false;
764
+ if (json instanceof Error) {
765
+ const { name, message, stack } = json;
766
+ json = { ...json, name, message, stack };
977
767
  }
978
- const left_syms = Object.getOwnPropertySymbols(left);
979
- const right_syms = Object.getOwnPropertySymbols(right);
980
- if (!compare_array(left_syms, right_syms))
981
- return false;
982
- for (let key of left_syms) {
983
- if (!$mol_compare_deep(left[key], right[key]))
984
- return false;
768
+ const sub = [];
769
+ for (var key in json) {
770
+ const val = json[key];
771
+ if (val === undefined)
772
+ continue;
773
+ const subsub = $mol_tree2_from_json(val, span);
774
+ if (/^[^\n\t\\ ]+$/.test(key)) {
775
+ sub.push(new $mol_tree2(key, '', [subsub], span));
776
+ }
777
+ else {
778
+ sub.push($mol_tree2.data(key, [subsub], span));
779
+ }
985
780
  }
986
- return true;
781
+ return new $mol_tree2('*', '', sub, span);
987
782
  }
988
- function compare_primitive(left, right) {
989
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
783
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
784
+ })($ || ($ = {}));
785
+
786
+ ;
787
+ "use strict";
788
+ var $;
789
+ (function ($) {
790
+ class $mol_term_color {
791
+ static reset = this.ansi(0, 0);
792
+ static bold = this.ansi(1, 22);
793
+ static italic = this.ansi(3, 23);
794
+ static underline = this.ansi(4, 24);
795
+ static inverse = this.ansi(7, 27);
796
+ static hidden = this.ansi(8, 28);
797
+ static strike = this.ansi(9, 29);
798
+ static gray = this.ansi(90, 39);
799
+ static red = this.ansi(91, 39);
800
+ static green = this.ansi(92, 39);
801
+ static yellow = this.ansi(93, 39);
802
+ static blue = this.ansi(94, 39);
803
+ static magenta = this.ansi(95, 39);
804
+ static cyan = this.ansi(96, 39);
805
+ static Gray = (str) => this.inverse(this.gray(str));
806
+ static Red = (str) => this.inverse(this.red(str));
807
+ static Green = (str) => this.inverse(this.green(str));
808
+ static Yellow = (str) => this.inverse(this.yellow(str));
809
+ static Blue = (str) => this.inverse(this.blue(str));
810
+ static Magenta = (str) => this.inverse(this.magenta(str));
811
+ static Cyan = (str) => this.inverse(this.cyan(str));
812
+ static ansi(open, close) {
813
+ if (typeof process === 'undefined')
814
+ return String;
815
+ if (!process.stdout.isTTY)
816
+ return String;
817
+ const prefix = `\x1b[${open}m`;
818
+ const postfix = `\x1b[${close}m`;
819
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
820
+ return function colorer(str) {
821
+ str = String(str);
822
+ if (str === '')
823
+ return str;
824
+ const suffix = str.replace(suffix_regexp, prefix);
825
+ return prefix + suffix + postfix;
826
+ };
827
+ }
990
828
  }
829
+ $.$mol_term_color = $mol_term_color;
991
830
  })($ || ($ = {}));
992
831
 
993
832
  ;
994
833
  "use strict";
995
834
  var $;
996
835
  (function ($) {
997
- function $mol_log3_area_lazy(event) {
998
- const self = this;
999
- const stack = self.$mol_log3_stack;
1000
- const deep = stack.length;
1001
- let logged = false;
1002
- stack.push(() => {
1003
- logged = true;
1004
- self.$mol_log3_area.call(self, event);
1005
- });
1006
- return () => {
1007
- if (logged)
1008
- self.console.groupEnd();
1009
- if (stack.length > deep)
1010
- stack.length = deep;
836
+ function $mol_log3_node_make(level, output, type, color) {
837
+ return function $mol_log3_logger(event) {
838
+ if (!event.time)
839
+ event = { time: new Date().toISOString(), ...event };
840
+ let tree = this.$mol_tree2_from_json(event);
841
+ tree = tree.struct(type, tree.kids);
842
+ let str = color(tree.toString());
843
+ this.console[level](str);
844
+ const self = this;
845
+ return () => self.console.groupEnd();
1011
846
  };
1012
847
  }
1013
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1014
- $.$mol_log3_stack = [];
848
+ $.$mol_log3_node_make = $mol_log3_node_make;
849
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
850
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
851
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
852
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
853
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
854
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1015
855
  })($ || ($ = {}));
1016
856
 
1017
857
  ;
1018
858
  "use strict";
1019
859
  var $;
1020
860
  (function ($) {
1021
- class $mol_span extends $mol_object2 {
1022
- uri;
1023
- source;
1024
- row;
1025
- col;
1026
- length;
1027
- constructor(uri, source, row, col, length) {
1028
- super();
1029
- this.uri = uri;
1030
- this.source = source;
1031
- this.row = row;
1032
- this.col = col;
1033
- this.length = length;
1034
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1035
- }
1036
- static unknown = $mol_span.begin('?');
1037
- static begin(uri, source = '') {
1038
- return new $mol_span(uri, source, 1, 1, 0);
1039
- }
1040
- static end(uri, source) {
1041
- return new $mol_span(uri, source, 1, source.length + 1, 0);
1042
- }
1043
- static entire(uri, source) {
1044
- return new $mol_span(uri, source, 1, 1, source.length);
1045
- }
1046
- toString() {
1047
- return this[Symbol.toStringTag];
1048
- }
1049
- toJSON() {
1050
- return {
1051
- uri: this.uri,
1052
- row: this.row,
1053
- col: this.col,
1054
- length: this.length
1055
- };
1056
- }
1057
- error(message, Class = Error) {
1058
- return new Class(`${message} (${this})`);
1059
- }
1060
- span(row, col, length) {
1061
- return new $mol_span(this.uri, this.source, row, col, length);
1062
- }
1063
- after(length = 0) {
1064
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1065
- }
1066
- slice(begin, end = -1) {
1067
- let len = this.length;
1068
- if (begin < 0)
1069
- begin += len;
1070
- if (end < 0)
1071
- end += len;
1072
- if (begin < 0 || begin > len)
1073
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1074
- if (end < 0 || end > len)
1075
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1076
- if (end < begin)
1077
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1078
- return this.span(this.row, this.col + begin, end - begin);
1079
- }
861
+ function $mol_env() {
862
+ return {};
1080
863
  }
1081
- $.$mol_span = $mol_span;
864
+ $.$mol_env = $mol_env;
1082
865
  })($ || ($ = {}));
1083
866
 
1084
867
  ;
1085
868
  "use strict";
1086
869
  var $;
1087
870
  (function ($) {
1088
- function $mol_tree2_to_string(tree) {
1089
- let output = [];
1090
- function dump(tree, prefix = '') {
1091
- if (tree.type.length) {
1092
- if (!prefix.length) {
1093
- prefix = "\t";
1094
- }
1095
- output.push(tree.type);
1096
- if (tree.kids.length == 1) {
1097
- output.push(' ');
1098
- dump(tree.kids[0], prefix);
1099
- return;
1100
- }
1101
- output.push("\n");
1102
- }
1103
- else if (tree.value.length || prefix.length) {
1104
- output.push("\\" + tree.value + "\n");
1105
- }
1106
- for (const kid of tree.kids) {
1107
- output.push(prefix);
1108
- dump(kid, prefix + "\t");
1109
- }
871
+ $.$mol_env = function $mol_env() {
872
+ return this.process.env;
873
+ };
874
+ })($ || ($ = {}));
875
+
876
+ ;
877
+ "use strict";
878
+ var $;
879
+ (function ($) {
880
+ function $mol_exec(dir, command, ...args) {
881
+ let [app, ...args0] = command.split(' ');
882
+ args = [...args0, ...args];
883
+ this.$mol_log3_come({
884
+ place: '$mol_exec',
885
+ dir: $node.path.relative('', dir),
886
+ message: 'Run',
887
+ command: `${app} ${args.join(' ')}`,
888
+ });
889
+ var res = $node['child_process'].spawnSync(app, args, {
890
+ cwd: $node.path.resolve(dir),
891
+ shell: true,
892
+ env: this.$mol_env(),
893
+ });
894
+ if (res.status || res.error) {
895
+ return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1110
896
  }
1111
- dump(tree);
1112
- return output.join('');
897
+ if (!res.stdout)
898
+ res.stdout = Buffer.from([]);
899
+ return res;
1113
900
  }
1114
- $.$mol_tree2_to_string = $mol_tree2_to_string;
901
+ $.$mol_exec = $mol_exec;
1115
902
  })($ || ($ = {}));
1116
903
 
1117
904
  ;
1118
905
  "use strict";
1119
906
  var $;
1120
907
  (function ($) {
1121
- class $mol_tree2 extends Object {
1122
- type;
1123
- value;
1124
- kids;
1125
- span;
1126
- constructor(type, value, kids, span) {
1127
- super();
1128
- this.type = type;
1129
- this.value = value;
1130
- this.kids = kids;
1131
- this.span = span;
1132
- this[Symbol.toStringTag] = type || '\\' + value;
1133
- }
1134
- static list(kids, span = $mol_span.unknown) {
1135
- return new $mol_tree2('', '', kids, span);
1136
- }
1137
- list(kids) {
1138
- return $mol_tree2.list(kids, this.span);
1139
- }
1140
- static data(value, kids = [], span = $mol_span.unknown) {
1141
- const chunks = value.split('\n');
1142
- if (chunks.length > 1) {
1143
- let kid_span = span.span(span.row, span.col, 0);
1144
- const data = chunks.map(chunk => {
1145
- kid_span = kid_span.after(chunk.length);
1146
- return new $mol_tree2('', chunk, [], kid_span);
1147
- });
1148
- kids = [...data, ...kids];
1149
- value = '';
1150
- }
1151
- return new $mol_tree2('', value, kids, span);
1152
- }
1153
- data(value, kids = []) {
1154
- return $mol_tree2.data(value, kids, this.span);
1155
- }
1156
- static struct(type, kids = [], span = $mol_span.unknown) {
1157
- if (/[ \n\t\\]/.test(type)) {
1158
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1159
- }
1160
- return new $mol_tree2(type, '', kids, span);
1161
- }
1162
- struct(type, kids = []) {
1163
- return $mol_tree2.struct(type, kids, this.span);
1164
- }
1165
- clone(kids, span = this.span) {
1166
- return new $mol_tree2(this.type, this.value, kids, span);
1167
- }
1168
- text() {
1169
- var values = [];
1170
- for (var kid of this.kids) {
1171
- if (kid.type)
1172
- continue;
1173
- values.push(kid.value);
1174
- }
1175
- return this.value + values.join('\n');
1176
- }
1177
- static fromString(str, uri = 'unknown') {
1178
- return $$.$mol_tree2_from_string(str, uri);
1179
- }
1180
- toString() {
1181
- return $$.$mol_tree2_to_string(this);
1182
- }
1183
- insert(value, ...path) {
1184
- if (path.length === 0)
1185
- return value;
1186
- const type = path[0];
1187
- if (typeof type === 'string') {
1188
- let replaced = false;
1189
- const sub = this.kids.map((item, index) => {
1190
- if (item.type !== type)
1191
- return item;
1192
- replaced = true;
1193
- return item.insert(value, ...path.slice(1));
1194
- }).filter(Boolean);
1195
- if (!replaced && value) {
1196
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1197
- }
1198
- return this.clone(sub);
1199
- }
1200
- else if (typeof type === 'number') {
1201
- const sub = this.kids.slice();
1202
- sub[type] = (sub[type] || this.list([]))
1203
- .insert(value, ...path.slice(1));
1204
- return this.clone(sub.filter(Boolean));
1205
- }
1206
- else {
1207
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1208
- .map(item => item.insert(value, ...path.slice(1)))
1209
- .filter(Boolean);
1210
- return this.clone(kids);
1211
- }
1212
- }
1213
- select(...path) {
1214
- let next = [this];
1215
- for (const type of path) {
1216
- if (!next.length)
1217
- break;
1218
- const prev = next;
1219
- next = [];
1220
- for (var item of prev) {
1221
- switch (typeof (type)) {
1222
- case 'string':
1223
- for (var child of item.kids) {
1224
- if (child.type == type) {
1225
- next.push(child);
1226
- }
1227
- }
1228
- break;
1229
- case 'number':
1230
- if (type < item.kids.length)
1231
- next.push(item.kids[type]);
1232
- break;
1233
- default: next.push(...item.kids);
1234
- }
1235
- }
1236
- }
1237
- return this.list(next);
1238
- }
1239
- filter(path, value) {
1240
- const sub = this.kids.filter(item => {
1241
- var found = item.select(...path);
1242
- if (value === undefined) {
1243
- return Boolean(found.kids.length);
1244
- }
1245
- else {
1246
- return found.kids.some(child => child.value == value);
1247
- }
1248
- });
1249
- return this.clone(sub);
1250
- }
1251
- hack_self(belt, context = {}) {
1252
- let handle = belt[this.type] || belt[''];
1253
- if (!handle || handle === Object.prototype[this.type]) {
1254
- handle = (input, belt, context) => [
1255
- input.clone(input.hack(belt, context), context.span)
1256
- ];
1257
- }
1258
- try {
1259
- return handle(this, belt, context);
1260
- }
1261
- catch (error) {
1262
- error.message += `\n${this.clone([])}${this.span}`;
1263
- $mol_fail_hidden(error);
1264
- }
908
+ const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
909
+ const encoder = new TextEncoder();
910
+ function $mol_charset_encode(value) {
911
+ return encoder.encode(value);
912
+ }
913
+ $.$mol_charset_encode = $mol_charset_encode;
914
+ })($ || ($ = {}));
915
+
916
+ ;
917
+ "use strict";
918
+ var $;
919
+ (function ($) {
920
+ function $mol_int62_string_ensure(str) {
921
+ if (typeof str !== 'string')
922
+ return null;
923
+ return $mol_int62_from_string(str) && str;
924
+ }
925
+ $.$mol_int62_string_ensure = $mol_int62_string_ensure;
926
+ $.$mol_int62_max = (2 ** 30) - 1;
927
+ $.$mol_int62_min = -(2 ** 30);
928
+ $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
929
+ function $mol_int62_to_string({ lo, hi }) {
930
+ lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
931
+ hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
932
+ return lo.toString(36) + '_' + hi.toString(36);
933
+ }
934
+ $.$mol_int62_to_string = $mol_int62_to_string;
935
+ function $mol_int62_from_string(str) {
936
+ const [str_lo, str_hi] = str.split('_');
937
+ const int_lo = parseInt(str_lo, 36);
938
+ const int_hi = parseInt(str_hi, 36);
939
+ if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
940
+ return null;
1265
941
  }
1266
- hack(belt, context = {}) {
1267
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
942
+ return {
943
+ lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
944
+ hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
945
+ };
946
+ }
947
+ $.$mol_int62_from_string = $mol_int62_from_string;
948
+ function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
949
+ return (right_hi - left_hi) || (right_lo - left_lo);
950
+ }
951
+ $.$mol_int62_compare = $mol_int62_compare;
952
+ function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
953
+ if (lo === max) {
954
+ return { lo: -max, hi: hi + 1 };
1268
955
  }
1269
- error(message, Class = Error) {
1270
- return this.span.error(`${message}\n${this.clone([])}`, Class);
956
+ else {
957
+ return { lo: lo + 1, hi };
1271
958
  }
1272
959
  }
1273
- $.$mol_tree2 = $mol_tree2;
1274
- class $mol_tree2_empty extends $mol_tree2 {
1275
- constructor() {
1276
- super('', '', [], $mol_span.unknown);
960
+ $.$mol_int62_inc = $mol_int62_inc;
961
+ function $mol_int62_random() {
962
+ return {
963
+ lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
964
+ hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
965
+ };
966
+ }
967
+ $.$mol_int62_random = $mol_int62_random;
968
+ function $mol_int62_hash_string(str) {
969
+ return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
970
+ }
971
+ $.$mol_int62_hash_string = $mol_int62_hash_string;
972
+ function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
973
+ let h1 = 0xdeadbeef ^ seed.lo;
974
+ let h2 = 0x41c6ce57 ^ seed.hi;
975
+ for (const byte of buf) {
976
+ h1 = Math.imul(h1 ^ byte, 2654435761);
977
+ h2 = Math.imul(h2 ^ byte, 1597334677);
1277
978
  }
979
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
980
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
981
+ return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
1278
982
  }
1279
- $.$mol_tree2_empty = $mol_tree2_empty;
983
+ $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
1280
984
  })($ || ($ = {}));
1281
985
 
986
+ ;
987
+ "use strict";
988
+
1282
989
  ;
1283
990
  "use strict";
1284
991
  var $;
1285
992
  (function ($) {
1286
- class $mol_error_syntax extends SyntaxError {
1287
- reason;
1288
- line;
1289
- span;
1290
- constructor(reason, line, span) {
1291
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1292
- this.reason = reason;
1293
- this.line = line;
1294
- this.span = span;
993
+ function $mol_data_setup(value, config) {
994
+ return Object.assign(value, {
995
+ config,
996
+ Value: null
997
+ });
998
+ }
999
+ $.$mol_data_setup = $mol_data_setup;
1000
+ })($ || ($ = {}));
1001
+
1002
+ ;
1003
+ "use strict";
1004
+ var $;
1005
+ (function ($) {
1006
+ class $mol_error_mix extends AggregateError {
1007
+ cause;
1008
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
1009
+ constructor(message, cause = {}, ...errors) {
1010
+ super(errors, message, { cause });
1011
+ this.cause = cause;
1012
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
1013
+ Object.defineProperty(this, 'stack', {
1014
+ get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
1015
+ .replace(/at /gm, ' at ')
1016
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
1017
+ });
1295
1018
  }
1296
1019
  }
1297
- $.$mol_error_syntax = $mol_error_syntax;
1020
+ $.$mol_error_mix = $mol_error_mix;
1298
1021
  })($ || ($ = {}));
1299
1022
 
1300
1023
  ;
1301
1024
  "use strict";
1302
1025
  var $;
1303
1026
  (function ($) {
1304
- function $mol_tree2_from_string(str, uri = '?') {
1305
- const span = $mol_span.entire(uri, str);
1306
- var root = $mol_tree2.list([], span);
1307
- var stack = [root];
1308
- var pos = 0, row = 0, min_indent = 0;
1309
- while (str.length > pos) {
1310
- var indent = 0;
1311
- var line_start = pos;
1312
- row++;
1313
- while (str.length > pos && str[pos] == '\t') {
1314
- indent++;
1315
- pos++;
1316
- }
1317
- if (!root.kids.length) {
1318
- min_indent = indent;
1319
- }
1320
- indent -= min_indent;
1321
- if (indent < 0 || indent >= stack.length) {
1322
- const sp = span.span(row, 1, pos - line_start);
1323
- while (str.length > pos && str[pos] != '\n') {
1324
- pos++;
1325
- }
1326
- if (indent < 0) {
1327
- if (str.length > pos) {
1328
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1329
- }
1330
- }
1331
- else {
1332
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1333
- }
1334
- }
1335
- stack.length = indent + 1;
1336
- var parent = stack[indent];
1337
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1338
- var error_start = pos;
1339
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1340
- pos++;
1341
- }
1342
- if (pos > error_start) {
1343
- let line_end = str.indexOf('\n', pos);
1344
- if (line_end === -1)
1345
- line_end = str.length;
1346
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1347
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1348
- }
1349
- var type_start = pos;
1350
- while (str.length > pos &&
1351
- str[pos] != '\\' &&
1352
- str[pos] != ' ' &&
1353
- str[pos] != '\t' &&
1354
- str[pos] != '\n') {
1355
- pos++;
1356
- }
1357
- if (pos > type_start) {
1358
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1359
- const parent_kids = parent.kids;
1360
- parent_kids.push(next);
1361
- parent = next;
1362
- }
1363
- if (str.length > pos && str[pos] == ' ') {
1364
- pos++;
1365
- }
1366
- }
1367
- if (str.length > pos && str[pos] == '\\') {
1368
- var data_start = pos;
1369
- while (str.length > pos && str[pos] != '\n') {
1370
- pos++;
1371
- }
1372
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1373
- const parent_kids = parent.kids;
1374
- parent_kids.push(next);
1375
- parent = next;
1376
- }
1377
- if (str.length === pos && stack.length > 0) {
1378
- const sp = span.span(row, pos - line_start + 1, 1);
1379
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1380
- }
1381
- stack.push(parent);
1382
- pos++;
1383
- }
1384
- return root;
1027
+ class $mol_data_error extends $mol_error_mix {
1385
1028
  }
1386
- $.$mol_tree2_from_string = $mol_tree2_from_string;
1029
+ $.$mol_data_error = $mol_data_error;
1387
1030
  })($ || ($ = {}));
1388
1031
 
1389
1032
  ;
1390
1033
  "use strict";
1391
1034
  var $;
1392
1035
  (function ($) {
1393
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1394
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1395
- return new $mol_tree2(String(json), '', [], span);
1396
- }
1397
- if (typeof json === 'string') {
1398
- return $mol_tree2.data(json, [], span);
1399
- }
1400
- if (Array.isArray(json)) {
1401
- const sub = json.map(json => $mol_tree2_from_json(json, span));
1402
- return new $mol_tree2('/', '', sub, span);
1403
- }
1404
- if (ArrayBuffer.isView(json)) {
1405
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1406
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1407
- }
1408
- if (json instanceof Date) {
1409
- return new $mol_tree2('', json.toISOString(), [], span);
1410
- }
1411
- if (typeof json.toJSON === 'function') {
1412
- return $mol_tree2_from_json(json.toJSON());
1413
- }
1414
- if (json.toString !== Object.prototype.toString) {
1415
- return $mol_tree2.data(json.toString(), [], span);
1416
- }
1417
- if (json instanceof Error) {
1418
- const { name, message, stack } = json;
1419
- json = { ...json, name, message, stack };
1420
- }
1421
- const sub = [];
1422
- for (var key in json) {
1423
- const val = json[key];
1424
- if (val === undefined)
1425
- continue;
1426
- const subsub = $mol_tree2_from_json(val, span);
1427
- if (/^[^\n\t\\ ]+$/.test(key)) {
1428
- sub.push(new $mol_tree2(key, '', [subsub], span));
1429
- }
1430
- else {
1431
- sub.push($mol_tree2.data(key, [subsub], span));
1036
+ function $mol_data_enum(name, dict) {
1037
+ const index = {};
1038
+ for (let key in dict) {
1039
+ if (Number.isNaN(Number(key))) {
1040
+ index[dict[key]] = key;
1432
1041
  }
1433
1042
  }
1434
- return new $mol_tree2('*', '', sub, span);
1043
+ return $mol_data_setup((value) => {
1044
+ if (typeof index[value] !== 'string') {
1045
+ return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
1046
+ }
1047
+ return value;
1048
+ }, { name, dict });
1435
1049
  }
1436
- $.$mol_tree2_from_json = $mol_tree2_from_json;
1050
+ $.$mol_data_enum = $mol_data_enum;
1437
1051
  })($ || ($ = {}));
1438
1052
 
1439
1053
  ;
1440
1054
  "use strict";
1441
1055
  var $;
1442
1056
  (function ($) {
1443
- class $mol_term_color {
1444
- static reset = this.ansi(0, 0);
1445
- static bold = this.ansi(1, 22);
1446
- static italic = this.ansi(3, 23);
1447
- static underline = this.ansi(4, 24);
1448
- static inverse = this.ansi(7, 27);
1449
- static hidden = this.ansi(8, 28);
1450
- static strike = this.ansi(9, 29);
1451
- static gray = this.ansi(90, 39);
1452
- static red = this.ansi(91, 39);
1453
- static green = this.ansi(92, 39);
1454
- static yellow = this.ansi(93, 39);
1455
- static blue = this.ansi(94, 39);
1456
- static magenta = this.ansi(95, 39);
1457
- static cyan = this.ansi(96, 39);
1458
- static Gray = (str) => this.inverse(this.gray(str));
1459
- static Red = (str) => this.inverse(this.red(str));
1460
- static Green = (str) => this.inverse(this.green(str));
1461
- static Yellow = (str) => this.inverse(this.yellow(str));
1462
- static Blue = (str) => this.inverse(this.blue(str));
1463
- static Magenta = (str) => this.inverse(this.magenta(str));
1464
- static Cyan = (str) => this.inverse(this.cyan(str));
1465
- static ansi(open, close) {
1466
- if (typeof process === 'undefined')
1467
- return String;
1468
- if (!process.stdout.isTTY)
1469
- return String;
1470
- const prefix = `\x1b[${open}m`;
1471
- const postfix = `\x1b[${close}m`;
1472
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1473
- return function colorer(str) {
1474
- str = String(str);
1475
- if (str === '')
1476
- return str;
1477
- const suffix = str.replace(suffix_regexp, prefix);
1478
- return prefix + suffix + postfix;
1479
- };
1480
- }
1481
- }
1482
- $.$mol_term_color = $mol_term_color;
1057
+ $.$mol_crypto_native = $node.crypto.webcrypto;
1483
1058
  })($ || ($ = {}));
1484
1059
 
1485
1060
  ;
1486
1061
  "use strict";
1487
1062
  var $;
1488
1063
  (function ($) {
1489
- function $mol_log3_node_make(level, output, type, color) {
1490
- return function $mol_log3_logger(event) {
1491
- if (!event.time)
1492
- event = { time: new Date().toISOString(), ...event };
1493
- let tree = this.$mol_tree2_from_json(event);
1494
- tree = tree.struct(type, tree.kids);
1495
- let str = color(tree.toString());
1496
- this.console[level](str);
1497
- const self = this;
1498
- return () => self.console.groupEnd();
1499
- };
1064
+ function $mol_base64_encode(src) {
1065
+ throw new Error('Not implemented');
1500
1066
  }
1501
- $.$mol_log3_node_make = $mol_log3_node_make;
1502
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1503
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1504
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1505
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1506
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1507
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1067
+ $.$mol_base64_encode = $mol_base64_encode;
1508
1068
  })($ || ($ = {}));
1509
1069
 
1510
1070
  ;
1511
1071
  "use strict";
1512
1072
  var $;
1513
1073
  (function ($) {
1514
- class $mol_wire_task extends $mol_wire_fiber {
1515
- static getter(task) {
1516
- return function $mol_wire_task_get(host, args) {
1517
- const sub = $mol_wire_auto();
1518
- const existen = sub?.track_next();
1519
- reuse: if (existen) {
1520
- if (!existen.temp)
1521
- break reuse;
1522
- if (existen.host !== host)
1523
- break reuse;
1524
- if (existen.task !== task)
1525
- break reuse;
1526
- if (!$mol_compare_deep(existen.args, args))
1527
- break reuse;
1528
- return existen;
1529
- }
1530
- const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
1531
- if (existen?.temp) {
1532
- $$.$mol_log3_warn({
1533
- place: '$mol_wire_task',
1534
- message: `Non idempotency`,
1535
- existen,
1536
- next,
1537
- hint: 'Ignore it',
1538
- });
1539
- }
1540
- return next;
1541
- };
1542
- }
1543
- get temp() {
1544
- return true;
1545
- }
1546
- complete() {
1547
- if ($mol_promise_like(this.cache))
1548
- return;
1549
- this.destructor();
1550
- }
1551
- put(next) {
1552
- const prev = this.cache;
1553
- this.cache = next;
1554
- if ($mol_promise_like(next)) {
1555
- this.cursor = $mol_wire_cursor.fresh;
1556
- if (next !== prev)
1557
- this.emit();
1558
- return next;
1559
- }
1560
- this.cursor = $mol_wire_cursor.final;
1561
- if (this.sub_empty)
1562
- this.destructor();
1563
- else if (next !== prev)
1564
- this.emit();
1565
- return next;
1566
- }
1074
+ function $mol_base64_encode_node(str) {
1075
+ if (!str)
1076
+ return '';
1077
+ if (Buffer.isBuffer(str))
1078
+ return str.toString('base64');
1079
+ return Buffer.from(str).toString('base64');
1567
1080
  }
1568
- $.$mol_wire_task = $mol_wire_task;
1081
+ $.$mol_base64_encode_node = $mol_base64_encode_node;
1082
+ $.$mol_base64_encode = $mol_base64_encode_node;
1569
1083
  })($ || ($ = {}));
1570
1084
 
1571
1085
  ;
1572
1086
  "use strict";
1573
1087
  var $;
1574
1088
  (function ($) {
1575
- function $mol_wire_sync(obj) {
1576
- return new Proxy(obj, {
1577
- get(obj, field) {
1578
- const val = obj[field];
1579
- if (typeof val !== 'function')
1580
- return val;
1581
- const temp = $mol_wire_task.getter(val);
1582
- return function $mol_wire_sync(...args) {
1583
- const fiber = temp(obj, args);
1584
- return fiber.sync();
1585
- };
1586
- },
1587
- apply(obj, self, args) {
1588
- const temp = $mol_wire_task.getter(obj);
1589
- const fiber = temp(self, args);
1590
- return fiber.sync();
1591
- },
1592
- });
1089
+ function $mol_base64_decode(base64) {
1090
+ throw new Error('Not implemented');
1593
1091
  }
1594
- $.$mol_wire_sync = $mol_wire_sync;
1092
+ $.$mol_base64_decode = $mol_base64_decode;
1595
1093
  })($ || ($ = {}));
1596
1094
 
1597
1095
  ;
1598
1096
  "use strict";
1599
1097
  var $;
1600
1098
  (function ($) {
1601
- const catched = new WeakMap();
1602
- function $mol_fail_catch(error) {
1603
- if (typeof error !== 'object')
1604
- return false;
1605
- if ($mol_promise_like(error))
1606
- $mol_fail_hidden(error);
1607
- if (catched.get(error))
1608
- return false;
1609
- catched.set(error, true);
1610
- return true;
1099
+ function $mol_base64_decode_node(base64Str) {
1100
+ base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
1101
+ const buffer = Buffer.from(base64Str, 'base64');
1102
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1611
1103
  }
1612
- $.$mol_fail_catch = $mol_fail_catch;
1104
+ $.$mol_base64_decode_node = $mol_base64_decode_node;
1105
+ $.$mol_base64_decode = $mol_base64_decode_node;
1613
1106
  })($ || ($ = {}));
1614
1107
 
1615
1108
  ;
1616
1109
  "use strict";
1617
1110
  var $;
1618
1111
  (function ($) {
1619
- function $mol_fail_log(error) {
1620
- if ($mol_promise_like(error))
1621
- return false;
1622
- if (!$mol_fail_catch(error))
1623
- return false;
1624
- console.error(error);
1625
- return true;
1112
+ function $mol_base64_url_encode(buffer) {
1113
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1626
1114
  }
1627
- $.$mol_fail_log = $mol_fail_log;
1115
+ $.$mol_base64_url_encode = $mol_base64_url_encode;
1116
+ function $mol_base64_url_decode(str) {
1117
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
1118
+ }
1119
+ $.$mol_base64_url_decode = $mol_base64_url_decode;
1628
1120
  })($ || ($ = {}));
1629
1121
 
1630
1122
  ;
1631
1123
  "use strict";
1632
- var $node = new Proxy({ require }, {
1633
- get(target, name, wrapper) {
1634
- if (target[name])
1635
- return target[name];
1636
- const mod = target.require('module');
1637
- if (mod.builtinModules.indexOf(name) >= 0)
1638
- return target.require(name);
1639
- if (name[0] === '.')
1640
- return target.require(name);
1641
- const path = target.require('path');
1642
- const fs = target.require('fs');
1643
- let dir = path.resolve('.');
1644
- const suffix = `./node_modules/${name}`;
1645
- const $$ = $;
1646
- while (!fs.existsSync(path.join(dir, suffix))) {
1647
- const parent = path.resolve(dir, '..');
1648
- if (parent === dir) {
1649
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1650
- try {
1651
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1652
- }
1653
- catch { }
1654
- break;
1655
- }
1656
- else {
1657
- dir = parent;
1124
+ var $;
1125
+ (function ($) {
1126
+ const algorithm = {
1127
+ name: 'ECDSA',
1128
+ hash: 'SHA-256',
1129
+ namedCurve: "P-256",
1130
+ };
1131
+ async function $mol_crypto_auditor_pair() {
1132
+ const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
1133
+ return {
1134
+ public: new $mol_crypto_auditor_public(pair.publicKey),
1135
+ private: new $mol_crypto_auditor_private(pair.privateKey),
1136
+ };
1137
+ }
1138
+ $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
1139
+ class $mol_crypto_auditor_public extends Object {
1140
+ native;
1141
+ static size_str = 86;
1142
+ static size_bin = 64;
1143
+ constructor(native) {
1144
+ super();
1145
+ this.native = native;
1146
+ }
1147
+ static async from(serial) {
1148
+ if (typeof serial !== 'string') {
1149
+ serial = $mol_base64_url_encode(serial.subarray(0, 32))
1150
+ + $mol_base64_url_encode(serial.subarray(32, 64));
1658
1151
  }
1152
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1153
+ crv: "P-256",
1154
+ ext: true,
1155
+ key_ops: ['verify'],
1156
+ kty: "EC",
1157
+ x: serial.slice(0, 43),
1158
+ y: serial.slice(43, 86),
1159
+ }, algorithm, true, ['verify']));
1659
1160
  }
1660
- try {
1661
- return $.$mol_wire_sync(target).require(name);
1161
+ async serial() {
1162
+ const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1163
+ return x + y;
1662
1164
  }
1663
- catch (error) {
1664
- if (error.code === 'ERR_REQUIRE_ESM') {
1665
- return importSync(name);
1165
+ async toArray() {
1166
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1167
+ return new Uint8Array([
1168
+ ...$mol_base64_url_decode(x),
1169
+ ...$mol_base64_url_decode(y),
1170
+ ]);
1171
+ }
1172
+ async verify(data, sign) {
1173
+ return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
1174
+ }
1175
+ }
1176
+ $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
1177
+ class $mol_crypto_auditor_private extends Object {
1178
+ native;
1179
+ static size_str = 129;
1180
+ static size_bin = 96;
1181
+ constructor(native) {
1182
+ super();
1183
+ this.native = native;
1184
+ }
1185
+ static async from(serial) {
1186
+ if (typeof serial !== 'string') {
1187
+ serial = $mol_base64_url_encode(serial.subarray(0, 32))
1188
+ + $mol_base64_url_encode(serial.subarray(32, 64))
1189
+ + $mol_base64_url_encode(serial.subarray(64));
1666
1190
  }
1667
- $.$mol_fail_log(error);
1668
- return null;
1191
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1192
+ crv: "P-256",
1193
+ ext: true,
1194
+ key_ops: ['sign'],
1195
+ kty: "EC",
1196
+ x: serial.slice(0, 43),
1197
+ y: serial.slice(43, 86),
1198
+ d: serial.slice(86, 129),
1199
+ }, algorithm, true, ['sign']));
1200
+ }
1201
+ async serial() {
1202
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1203
+ return x + y + d;
1204
+ }
1205
+ async toArray() {
1206
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1207
+ return new Uint8Array([
1208
+ ...$mol_base64_url_decode(x),
1209
+ ...$mol_base64_url_decode(y),
1210
+ ...$mol_base64_url_decode(d),
1211
+ ]);
1212
+ }
1213
+ async sign(data) {
1214
+ return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
1215
+ }
1216
+ async public() {
1217
+ return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
1669
1218
  }
1670
- },
1671
- set(target, name, value) {
1672
- target[name] = value;
1673
- return true;
1674
- },
1675
- });
1676
- const importAsync = async (uri) => import(uri);
1677
- const importSync = $.$mol_wire_sync(importAsync);
1678
- require = (req => Object.assign(function require(name) {
1679
- return $node[name];
1680
- }, req))(require);
1681
-
1682
- ;
1683
- "use strict";
1684
- var $;
1685
- (function ($) {
1686
- function $mol_env() {
1687
- return {};
1688
1219
  }
1689
- $.$mol_env = $mol_env;
1690
- })($ || ($ = {}));
1691
-
1692
- ;
1693
- "use strict";
1694
- var $;
1695
- (function ($) {
1696
- $.$mol_env = function $mol_env() {
1697
- return this.process.env;
1698
- };
1220
+ $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
1221
+ $.$mol_crypto_auditor_sign_size = 64;
1222
+ function $mol_crypto_auditor_private_to_public(serial) {
1223
+ return serial.slice(0, 86);
1224
+ }
1225
+ $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
1699
1226
  })($ || ($ = {}));
1700
1227
 
1701
1228
  ;
1702
1229
  "use strict";
1703
1230
  var $;
1704
1231
  (function ($) {
1705
- function $mol_exec(dir, command, ...args) {
1706
- let [app, ...args0] = command.split(' ');
1707
- args = [...args0, ...args];
1708
- this.$mol_log3_come({
1709
- place: '$mol_exec',
1710
- dir: $node.path.relative('', dir),
1711
- message: 'Run',
1712
- command: `${app} ${args.join(' ')}`,
1713
- });
1714
- var res = $node['child_process'].spawnSync(app, args, {
1715
- cwd: $node.path.resolve(dir),
1716
- shell: true,
1717
- env: this.$mol_env(),
1718
- });
1719
- if (res.status || res.error) {
1720
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1232
+ let $hyoo_crowd_peer_level;
1233
+ (function ($hyoo_crowd_peer_level) {
1234
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
1235
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
1236
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
1237
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
1238
+ })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
1239
+ class $hyoo_crowd_peer extends Object {
1240
+ key_public;
1241
+ key_public_serial;
1242
+ key_private;
1243
+ key_private_serial;
1244
+ id;
1245
+ constructor(key_public, key_public_serial, key_private, key_private_serial) {
1246
+ super();
1247
+ this.key_public = key_public;
1248
+ this.key_public_serial = key_public_serial;
1249
+ this.key_private = key_private;
1250
+ this.key_private_serial = key_private_serial;
1251
+ this.id = $mol_int62_hash_string(this.key_public_serial);
1252
+ }
1253
+ static async generate() {
1254
+ const pair = await $$.$mol_crypto_auditor_pair();
1255
+ const serial = await pair.private.serial();
1256
+ return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
1257
+ }
1258
+ static async restore(serial) {
1259
+ return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
1721
1260
  }
1722
- if (!res.stdout)
1723
- res.stdout = Buffer.from([]);
1724
- return res;
1725
1261
  }
1726
- $.$mol_exec = $mol_exec;
1262
+ $.$hyoo_crowd_peer = $hyoo_crowd_peer;
1727
1263
  })($ || ($ = {}));
1728
1264
 
1729
1265
  ;
1730
1266
  "use strict";
1731
1267
  var $;
1732
1268
  (function ($) {
1733
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
1734
- const encoder = new TextEncoder();
1735
- function $mol_charset_encode(value) {
1736
- return encoder.encode(value);
1269
+ $['devtoolsFormatters'] ||= [];
1270
+ function $mol_dev_format_register(config) {
1271
+ $['devtoolsFormatters'].push(config);
1737
1272
  }
1738
- $.$mol_charset_encode = $mol_charset_encode;
1739
- })($ || ($ = {}));
1740
-
1741
- ;
1742
- "use strict";
1743
- var $;
1744
- (function ($) {
1745
- function $mol_int62_string_ensure(str) {
1746
- if (typeof str !== 'string')
1747
- return null;
1748
- return $mol_int62_from_string(str) && str;
1749
- }
1750
- $.$mol_int62_string_ensure = $mol_int62_string_ensure;
1751
- $.$mol_int62_max = (2 ** 30) - 1;
1752
- $.$mol_int62_min = -(2 ** 30);
1753
- $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
1754
- function $mol_int62_to_string({ lo, hi }) {
1755
- lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
1756
- hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
1757
- return lo.toString(36) + '_' + hi.toString(36);
1758
- }
1759
- $.$mol_int62_to_string = $mol_int62_to_string;
1760
- function $mol_int62_from_string(str) {
1761
- const [str_lo, str_hi] = str.split('_');
1762
- const int_lo = parseInt(str_lo, 36);
1763
- const int_hi = parseInt(str_hi, 36);
1764
- if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
1273
+ $.$mol_dev_format_register = $mol_dev_format_register;
1274
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1275
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1276
+ $mol_dev_format_register({
1277
+ header: (val, config = false) => {
1278
+ if (config)
1279
+ return null;
1280
+ if (!val)
1281
+ return null;
1282
+ if ($.$mol_dev_format_head in val) {
1283
+ try {
1284
+ return val[$.$mol_dev_format_head]();
1285
+ }
1286
+ catch (error) {
1287
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1288
+ }
1289
+ }
1290
+ if (typeof val === 'function') {
1291
+ return $mol_dev_format_native(val);
1292
+ }
1293
+ if (Symbol.toStringTag in val) {
1294
+ return $mol_dev_format_native(val);
1295
+ }
1765
1296
  return null;
1766
- }
1767
- return {
1768
- lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1769
- hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1770
- };
1771
- }
1772
- $.$mol_int62_from_string = $mol_int62_from_string;
1773
- function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
1774
- return (right_hi - left_hi) || (right_lo - left_lo);
1775
- }
1776
- $.$mol_int62_compare = $mol_int62_compare;
1777
- function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
1778
- if (lo === max) {
1779
- return { lo: -max, hi: hi + 1 };
1780
- }
1781
- else {
1782
- return { lo: lo + 1, hi };
1783
- }
1297
+ },
1298
+ hasBody: val => val[$.$mol_dev_format_body],
1299
+ body: val => val[$.$mol_dev_format_body](),
1300
+ });
1301
+ function $mol_dev_format_native(obj) {
1302
+ if (typeof obj === 'undefined')
1303
+ return $.$mol_dev_format_shade('undefined');
1304
+ return [
1305
+ 'object',
1306
+ {
1307
+ object: obj,
1308
+ config: true,
1309
+ },
1310
+ ];
1784
1311
  }
1785
- $.$mol_int62_inc = $mol_int62_inc;
1786
- function $mol_int62_random() {
1787
- return {
1788
- lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1789
- hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1790
- };
1312
+ $.$mol_dev_format_native = $mol_dev_format_native;
1313
+ function $mol_dev_format_auto(obj) {
1314
+ if (obj == null)
1315
+ return $.$mol_dev_format_shade(String(obj));
1316
+ return [
1317
+ 'object',
1318
+ {
1319
+ object: obj,
1320
+ config: false,
1321
+ },
1322
+ ];
1791
1323
  }
1792
- $.$mol_int62_random = $mol_int62_random;
1793
- function $mol_int62_hash_string(str) {
1794
- return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
1324
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
1325
+ function $mol_dev_format_element(element, style, ...content) {
1326
+ const styles = [];
1327
+ for (let key in style)
1328
+ styles.push(`${key} : ${style[key]}`);
1329
+ return [
1330
+ element,
1331
+ {
1332
+ style: styles.join(' ; '),
1333
+ },
1334
+ ...content,
1335
+ ];
1795
1336
  }
1796
- $.$mol_int62_hash_string = $mol_int62_hash_string;
1797
- function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
1798
- let h1 = 0xdeadbeef ^ seed.lo;
1799
- let h2 = 0x41c6ce57 ^ seed.hi;
1800
- for (const byte of buf) {
1801
- h1 = Math.imul(h1 ^ byte, 2654435761);
1802
- h2 = Math.imul(h2 ^ byte, 1597334677);
1803
- }
1804
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1805
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1806
- return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
1337
+ $.$mol_dev_format_element = $mol_dev_format_element;
1338
+ function $mol_dev_format_span(style, ...content) {
1339
+ return $mol_dev_format_element('span', {
1340
+ ...style,
1341
+ }, ...content);
1807
1342
  }
1808
- $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
1343
+ $.$mol_dev_format_span = $mol_dev_format_span;
1344
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1345
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1346
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1347
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1348
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1349
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1350
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
1351
+ 'color': 'magenta',
1352
+ });
1353
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
1354
+ 'font-weight': 'bold',
1355
+ });
1356
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
1357
+ 'color': 'green',
1358
+ });
1359
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
1360
+ 'color': 'gray',
1361
+ });
1362
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1363
+ 'margin-left': '13px'
1364
+ });
1809
1365
  })($ || ($ = {}));
1810
1366
 
1811
1367
  ;
@@ -1815,512 +1371,732 @@ var $;
1815
1371
  "use strict";
1816
1372
  var $;
1817
1373
  (function ($) {
1818
- function $mol_data_setup(value, config) {
1819
- return Object.assign(value, {
1820
- config,
1821
- Value: null
1822
- });
1374
+ const decoders = {};
1375
+ function $mol_charset_decode(buffer, encoding = 'utf8') {
1376
+ let decoder = decoders[encoding];
1377
+ if (!decoder)
1378
+ decoder = decoders[encoding] = new TextDecoder(encoding);
1379
+ return decoder.decode(buffer);
1823
1380
  }
1824
- $.$mol_data_setup = $mol_data_setup;
1381
+ $.$mol_charset_decode = $mol_charset_decode;
1825
1382
  })($ || ($ = {}));
1826
1383
 
1827
1384
  ;
1828
1385
  "use strict";
1829
1386
  var $;
1830
1387
  (function ($) {
1831
- class $mol_error_mix extends AggregateError {
1832
- cause;
1833
- name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
1834
- constructor(message, cause = {}, ...errors) {
1835
- super(errors, message, { cause });
1836
- this.cause = cause;
1837
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
1838
- Object.defineProperty(this, 'stack', {
1839
- get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
1840
- .replace(/at /gm, ' at ')
1841
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
1842
- });
1388
+ const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
1389
+ let $hyoo_crowd_unit_kind;
1390
+ (function ($hyoo_crowd_unit_kind) {
1391
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
1392
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
1393
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
1394
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
1395
+ })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
1396
+ let $hyoo_crowd_unit_group;
1397
+ (function ($hyoo_crowd_unit_group) {
1398
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
1399
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
1400
+ })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
1401
+ class $hyoo_crowd_unit extends Object {
1402
+ land;
1403
+ auth;
1404
+ head;
1405
+ self;
1406
+ next;
1407
+ prev;
1408
+ time;
1409
+ data;
1410
+ bin;
1411
+ constructor(land, auth, head, self, next, prev, time, data, bin) {
1412
+ super();
1413
+ this.land = land;
1414
+ this.auth = auth;
1415
+ this.head = head;
1416
+ this.self = self;
1417
+ this.next = next;
1418
+ this.prev = prev;
1419
+ this.time = time;
1420
+ this.data = data;
1421
+ this.bin = bin;
1843
1422
  }
1844
- }
1845
- $.$mol_error_mix = $mol_error_mix;
1846
- })($ || ($ = {}));
1847
-
1848
- ;
1849
- "use strict";
1850
- var $;
1851
- (function ($) {
1852
- class $mol_data_error extends $mol_error_mix {
1853
- }
1854
- $.$mol_data_error = $mol_data_error;
1855
- })($ || ($ = {}));
1856
-
1857
- ;
1858
- "use strict";
1859
- var $;
1860
- (function ($) {
1861
- function $mol_data_enum(name, dict) {
1862
- const index = {};
1863
- for (let key in dict) {
1864
- if (Number.isNaN(Number(key))) {
1865
- index[dict[key]] = key;
1423
+ kind() {
1424
+ if (this.head === this.self && this.auth === this.self) {
1425
+ if (this.head === this.land) {
1426
+ return $hyoo_crowd_unit_kind.grab;
1427
+ }
1428
+ else {
1429
+ return $hyoo_crowd_unit_kind.join;
1430
+ }
1866
1431
  }
1867
- }
1868
- return $mol_data_setup((value) => {
1869
- if (typeof index[value] !== 'string') {
1870
- return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
1432
+ if (this.head === this.land) {
1433
+ return $hyoo_crowd_unit_kind.give;
1871
1434
  }
1872
- return value;
1873
- }, { name, dict });
1874
- }
1875
- $.$mol_data_enum = $mol_data_enum;
1876
- })($ || ($ = {}));
1877
-
1878
- ;
1879
- "use strict";
1880
- var $;
1881
- (function ($) {
1882
- $.$mol_crypto_native = $node.crypto.webcrypto;
1435
+ return $hyoo_crowd_unit_kind.data;
1436
+ }
1437
+ group() {
1438
+ return this.kind() === $hyoo_crowd_unit_kind.data
1439
+ ? $hyoo_crowd_unit_group.data
1440
+ : $hyoo_crowd_unit_group.auth;
1441
+ }
1442
+ level() {
1443
+ switch (this.kind()) {
1444
+ case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
1445
+ case $hyoo_crowd_unit_kind.give: return level(this.data);
1446
+ default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
1447
+ }
1448
+ }
1449
+ [Symbol.toPrimitive]() {
1450
+ return JSON.stringify(this);
1451
+ }
1452
+ [$mol_dev_format_head]() {
1453
+ switch (this.kind()) {
1454
+ case $hyoo_crowd_unit_kind.grab:
1455
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
1456
+ case $hyoo_crowd_unit_kind.join:
1457
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
1458
+ case $hyoo_crowd_unit_kind.give:
1459
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
1460
+ case $hyoo_crowd_unit_kind.data:
1461
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
1462
+ }
1463
+ }
1464
+ }
1465
+ $.$hyoo_crowd_unit = $hyoo_crowd_unit;
1466
+ const offset = {
1467
+ land_lo: 0,
1468
+ land_hi: 4,
1469
+ auth_lo: 8,
1470
+ auth_hi: 12,
1471
+ head_lo: 16,
1472
+ head_hi: 20,
1473
+ self_lo: 24,
1474
+ self_hi: 28,
1475
+ next_lo: 32,
1476
+ next_hi: 36,
1477
+ prev_lo: 40,
1478
+ prev_hi: 44,
1479
+ time: 48,
1480
+ size: 54,
1481
+ data: 56,
1482
+ };
1483
+ class $hyoo_crowd_unit_bin extends DataView {
1484
+ static from_buffer(buffer) {
1485
+ const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
1486
+ return new this(buffer.slice(0, size / 2).buffer);
1487
+ }
1488
+ static from_unit(unit) {
1489
+ if (unit.bin)
1490
+ return unit.bin;
1491
+ const type = unit.data === null
1492
+ ? 0
1493
+ : unit.data instanceof Uint8Array
1494
+ ? -1
1495
+ : 1;
1496
+ const buff = type === 0 ? null
1497
+ : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
1498
+ : unit.data;
1499
+ const size = buff?.byteLength ?? 0;
1500
+ if (type > 0 && size > 2 ** 15 - 1)
1501
+ throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
1502
+ if (type < 0 && size > 2 ** 15)
1503
+ throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
1504
+ const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
1505
+ const mem = new Uint8Array(total);
1506
+ const bin = new $hyoo_crowd_unit_bin(mem.buffer);
1507
+ const land = $mol_int62_from_string(unit.land);
1508
+ bin.setInt32(offset.land_lo, land.lo, true);
1509
+ bin.setInt32(offset.land_hi, land.hi, true);
1510
+ const auth = $mol_int62_from_string(unit.auth);
1511
+ bin.setInt32(offset.auth_lo, auth.lo, true);
1512
+ bin.setInt32(offset.auth_hi, auth.hi, true);
1513
+ const head = $mol_int62_from_string(unit.head);
1514
+ bin.setInt32(offset.head_lo, head.lo, true);
1515
+ bin.setInt32(offset.head_hi, head.hi, true);
1516
+ const self = $mol_int62_from_string(unit.self);
1517
+ bin.setInt32(offset.self_lo, self.lo, true);
1518
+ bin.setInt32(offset.self_hi, self.hi, true);
1519
+ const next = $mol_int62_from_string(unit.next);
1520
+ bin.setInt32(offset.next_lo, next.lo, true);
1521
+ bin.setInt32(offset.next_hi, next.hi, true);
1522
+ const prev = $mol_int62_from_string(unit.prev);
1523
+ bin.setInt32(offset.prev_lo, prev.lo, true);
1524
+ bin.setInt32(offset.prev_hi, prev.hi, true);
1525
+ bin.setInt32(offset.time, unit.time, true);
1526
+ bin.setInt16(offset.size, type * size, true);
1527
+ if (buff)
1528
+ mem.set(buff, offset.data);
1529
+ return bin;
1530
+ }
1531
+ sign(next) {
1532
+ const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
1533
+ const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
1534
+ if (!next)
1535
+ return buff;
1536
+ buff.set(next);
1537
+ return buff;
1538
+ }
1539
+ size() {
1540
+ return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
1541
+ }
1542
+ sens() {
1543
+ return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
1544
+ }
1545
+ unit() {
1546
+ const land = $mol_int62_to_string({
1547
+ lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
1548
+ hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
1549
+ });
1550
+ const auth = $mol_int62_to_string({
1551
+ lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
1552
+ hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
1553
+ });
1554
+ const head = $mol_int62_to_string({
1555
+ lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
1556
+ hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
1557
+ });
1558
+ const self = $mol_int62_to_string({
1559
+ lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
1560
+ hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
1561
+ });
1562
+ const next = $mol_int62_to_string({
1563
+ lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
1564
+ hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
1565
+ });
1566
+ const prev = $mol_int62_to_string({
1567
+ lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
1568
+ hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
1569
+ });
1570
+ const time = this.getInt32(offset.time, true) << 1 >> 1;
1571
+ const type_size = this.getInt16(offset.size, true);
1572
+ let data = null;
1573
+ if (type_size) {
1574
+ try {
1575
+ var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
1576
+ }
1577
+ catch (error) {
1578
+ error['message'] += `\nhead=${head};self=${self}`;
1579
+ $mol_fail_hidden(error);
1580
+ }
1581
+ if (type_size < 0)
1582
+ data = buff;
1583
+ else
1584
+ data = JSON.parse($mol_charset_decode(buff));
1585
+ }
1586
+ return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
1587
+ }
1588
+ }
1589
+ $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
1590
+ function $hyoo_crowd_unit_compare(left, right) {
1591
+ return (left.group() - right.group())
1592
+ || (left.time - right.time)
1593
+ || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
1594
+ || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
1595
+ || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
1596
+ || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
1597
+ || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
1598
+ || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
1599
+ }
1600
+ $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
1883
1601
  })($ || ($ = {}));
1884
1602
 
1885
1603
  ;
1886
1604
  "use strict";
1887
1605
  var $;
1888
1606
  (function ($) {
1889
- function $mol_base64_encode(src) {
1890
- throw new Error('Not implemented');
1891
- }
1892
- $.$mol_base64_encode = $mol_base64_encode;
1607
+ let $mol_wire_cursor;
1608
+ (function ($mol_wire_cursor) {
1609
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
1610
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
1611
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
1612
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
1613
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
1893
1614
  })($ || ($ = {}));
1894
1615
 
1895
1616
  ;
1896
1617
  "use strict";
1897
1618
  var $;
1898
1619
  (function ($) {
1899
- function $mol_base64_encode_node(str) {
1900
- if (!str)
1901
- return '';
1902
- if (Buffer.isBuffer(str))
1903
- return str.toString('base64');
1904
- return Buffer.from(str).toString('base64');
1620
+ class $mol_wire_pub extends Object {
1621
+ data = [];
1622
+ static get [Symbol.species]() {
1623
+ return Array;
1624
+ }
1625
+ sub_from = 0;
1626
+ get sub_list() {
1627
+ const res = [];
1628
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
1629
+ res.push(this.data[i]);
1630
+ }
1631
+ return res;
1632
+ }
1633
+ get sub_empty() {
1634
+ return this.sub_from === this.data.length;
1635
+ }
1636
+ sub_on(sub, pub_pos) {
1637
+ const pos = this.data.length;
1638
+ this.data.push(sub, pub_pos);
1639
+ return pos;
1640
+ }
1641
+ sub_off(sub_pos) {
1642
+ if (!(sub_pos < this.data.length)) {
1643
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
1644
+ }
1645
+ const end = this.data.length - 2;
1646
+ if (sub_pos !== end) {
1647
+ this.peer_move(end, sub_pos);
1648
+ }
1649
+ this.data.pop();
1650
+ this.data.pop();
1651
+ if (this.data.length === this.sub_from)
1652
+ this.reap();
1653
+ }
1654
+ reap() { }
1655
+ promote() {
1656
+ $mol_wire_auto()?.track_next(this);
1657
+ }
1658
+ fresh() { }
1659
+ complete() { }
1660
+ get incompleted() {
1661
+ return false;
1662
+ }
1663
+ emit(quant = $mol_wire_cursor.stale) {
1664
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
1665
+ ;
1666
+ this.data[i].absorb(quant);
1667
+ }
1668
+ }
1669
+ peer_move(from_pos, to_pos) {
1670
+ const peer = this.data[from_pos];
1671
+ const self_pos = this.data[from_pos + 1];
1672
+ this.data[to_pos] = peer;
1673
+ this.data[to_pos + 1] = self_pos;
1674
+ peer.peer_repos(self_pos, to_pos);
1675
+ }
1676
+ peer_repos(peer_pos, self_pos) {
1677
+ this.data[peer_pos + 1] = self_pos;
1678
+ }
1905
1679
  }
1906
- $.$mol_base64_encode_node = $mol_base64_encode_node;
1907
- $.$mol_base64_encode = $mol_base64_encode_node;
1680
+ $.$mol_wire_pub = $mol_wire_pub;
1908
1681
  })($ || ($ = {}));
1909
1682
 
1910
1683
  ;
1911
1684
  "use strict";
1912
- var $;
1913
- (function ($) {
1914
- function $mol_base64_decode(base64) {
1915
- throw new Error('Not implemented');
1916
- }
1917
- $.$mol_base64_decode = $mol_base64_decode;
1918
- })($ || ($ = {}));
1919
1685
 
1920
1686
  ;
1921
1687
  "use strict";
1922
1688
  var $;
1923
1689
  (function ($) {
1924
- function $mol_base64_decode_node(base64Str) {
1925
- base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
1926
- const buffer = Buffer.from(base64Str, 'base64');
1927
- return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1928
- }
1929
- $.$mol_base64_decode_node = $mol_base64_decode_node;
1930
- $.$mol_base64_decode = $mol_base64_decode_node;
1931
- })($ || ($ = {}));
1932
-
1933
- ;
1934
- "use strict";
1935
- var $;
1936
- (function ($) {
1937
- function $mol_base64_url_encode(buffer) {
1938
- return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1939
- }
1940
- $.$mol_base64_url_encode = $mol_base64_url_encode;
1941
- function $mol_base64_url_decode(str) {
1942
- return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
1690
+ $.$mol_wire_auto_sub = null;
1691
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
1692
+ return $.$mol_wire_auto_sub = next;
1943
1693
  }
1944
- $.$mol_base64_url_decode = $mol_base64_url_decode;
1694
+ $.$mol_wire_auto = $mol_wire_auto;
1695
+ $.$mol_wire_affected = [];
1945
1696
  })($ || ($ = {}));
1946
1697
 
1947
1698
  ;
1948
1699
  "use strict";
1949
1700
  var $;
1950
1701
  (function ($) {
1951
- const algorithm = {
1952
- name: 'ECDSA',
1953
- hash: 'SHA-256',
1954
- namedCurve: "P-256",
1955
- };
1956
- async function $mol_crypto_auditor_pair() {
1957
- const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
1958
- return {
1959
- public: new $mol_crypto_auditor_public(pair.publicKey),
1960
- private: new $mol_crypto_auditor_private(pair.privateKey),
1961
- };
1962
- }
1963
- $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
1964
- class $mol_crypto_auditor_public extends Object {
1965
- native;
1966
- static size_str = 86;
1967
- static size_bin = 64;
1968
- constructor(native) {
1969
- super();
1970
- this.native = native;
1702
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1703
+ pub_from = 0;
1704
+ cursor = $mol_wire_cursor.stale;
1705
+ get temp() {
1706
+ return false;
1971
1707
  }
1972
- static async from(serial) {
1973
- if (typeof serial !== 'string') {
1974
- serial = $mol_base64_url_encode(serial.subarray(0, 32))
1975
- + $mol_base64_url_encode(serial.subarray(32, 64));
1708
+ get pub_list() {
1709
+ const res = [];
1710
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1711
+ for (let i = this.pub_from; i < max; i += 2) {
1712
+ if (this.data[i])
1713
+ res.push(this.data[i]);
1976
1714
  }
1977
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1978
- crv: "P-256",
1979
- ext: true,
1980
- key_ops: ['verify'],
1981
- kty: "EC",
1982
- x: serial.slice(0, 43),
1983
- y: serial.slice(43, 86),
1984
- }, algorithm, true, ['verify']));
1715
+ return res;
1985
1716
  }
1986
- async serial() {
1987
- const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1988
- return x + y;
1717
+ track_on() {
1718
+ this.cursor = this.pub_from;
1719
+ const sub = $mol_wire_auto();
1720
+ $mol_wire_auto(this);
1721
+ return sub;
1989
1722
  }
1990
- async toArray() {
1991
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1992
- return new Uint8Array([
1993
- ...$mol_base64_url_decode(x),
1994
- ...$mol_base64_url_decode(y),
1995
- ]);
1723
+ promote() {
1724
+ if (this.cursor >= this.pub_from) {
1725
+ $mol_fail(new Error('Circular subscription'));
1726
+ }
1727
+ super.promote();
1996
1728
  }
1997
- async verify(data, sign) {
1998
- return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
1729
+ track_next(pub) {
1730
+ if (this.cursor < 0)
1731
+ $mol_fail(new Error('Promo to non begun sub'));
1732
+ if (this.cursor < this.sub_from) {
1733
+ const next = this.data[this.cursor];
1734
+ if (pub === undefined)
1735
+ return next ?? null;
1736
+ if (next === pub) {
1737
+ this.cursor += 2;
1738
+ return next;
1739
+ }
1740
+ if (next) {
1741
+ if (this.sub_from < this.data.length) {
1742
+ this.peer_move(this.sub_from, this.data.length);
1743
+ }
1744
+ this.peer_move(this.cursor, this.sub_from);
1745
+ this.sub_from += 2;
1746
+ }
1747
+ }
1748
+ else {
1749
+ if (pub === undefined)
1750
+ return null;
1751
+ if (this.sub_from < this.data.length) {
1752
+ this.peer_move(this.sub_from, this.data.length);
1753
+ }
1754
+ this.sub_from += 2;
1755
+ }
1756
+ this.data[this.cursor] = pub;
1757
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1758
+ this.cursor += 2;
1759
+ return pub;
1999
1760
  }
2000
- }
2001
- $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
2002
- class $mol_crypto_auditor_private extends Object {
2003
- native;
2004
- static size_str = 129;
2005
- static size_bin = 96;
2006
- constructor(native) {
2007
- super();
2008
- this.native = native;
1761
+ track_off(sub) {
1762
+ $mol_wire_auto(sub);
1763
+ if (this.cursor < 0) {
1764
+ $mol_fail(new Error('End of non begun sub'));
1765
+ }
1766
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1767
+ const pub = this.data[cursor];
1768
+ pub.fresh();
1769
+ }
1770
+ this.cursor = $mol_wire_cursor.fresh;
2009
1771
  }
2010
- static async from(serial) {
2011
- if (typeof serial !== 'string') {
2012
- serial = $mol_base64_url_encode(serial.subarray(0, 32))
2013
- + $mol_base64_url_encode(serial.subarray(32, 64))
2014
- + $mol_base64_url_encode(serial.subarray(64));
1772
+ pub_off(sub_pos) {
1773
+ this.data[sub_pos] = undefined;
1774
+ this.data[sub_pos + 1] = undefined;
1775
+ }
1776
+ destructor() {
1777
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1778
+ const sub = this.data[cursor];
1779
+ const pos = this.data[cursor + 1];
1780
+ sub.pub_off(pos);
1781
+ this.data.pop();
1782
+ this.data.pop();
2015
1783
  }
2016
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
2017
- crv: "P-256",
2018
- ext: true,
2019
- key_ops: ['sign'],
2020
- kty: "EC",
2021
- x: serial.slice(0, 43),
2022
- y: serial.slice(43, 86),
2023
- d: serial.slice(86, 129),
2024
- }, algorithm, true, ['sign']));
1784
+ this.cursor = this.pub_from;
1785
+ this.track_cut();
1786
+ this.cursor = $mol_wire_cursor.final;
2025
1787
  }
2026
- async serial() {
2027
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2028
- return x + y + d;
1788
+ track_cut() {
1789
+ if (this.cursor < this.pub_from) {
1790
+ $mol_fail(new Error('Cut of non begun sub'));
1791
+ }
1792
+ let tail = 0;
1793
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1794
+ const pub = this.data[cursor];
1795
+ pub?.sub_off(this.data[cursor + 1]);
1796
+ if (this.sub_from < this.data.length) {
1797
+ this.peer_move(this.data.length - 2, cursor);
1798
+ this.data.pop();
1799
+ this.data.pop();
1800
+ }
1801
+ else {
1802
+ ++tail;
1803
+ }
1804
+ }
1805
+ for (; tail; --tail) {
1806
+ this.data.pop();
1807
+ this.data.pop();
1808
+ }
1809
+ this.sub_from = this.cursor;
2029
1810
  }
2030
- async toArray() {
2031
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2032
- return new Uint8Array([
2033
- ...$mol_base64_url_decode(x),
2034
- ...$mol_base64_url_decode(y),
2035
- ...$mol_base64_url_decode(d),
2036
- ]);
1811
+ complete() { }
1812
+ complete_pubs() {
1813
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1814
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1815
+ const pub = this.data[cursor];
1816
+ if (pub?.incompleted)
1817
+ return;
1818
+ }
1819
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1820
+ const pub = this.data[cursor];
1821
+ pub?.complete();
1822
+ }
2037
1823
  }
2038
- async sign(data) {
2039
- return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
1824
+ absorb(quant = $mol_wire_cursor.stale) {
1825
+ if (this.cursor === $mol_wire_cursor.final)
1826
+ return;
1827
+ if (this.cursor >= quant)
1828
+ return;
1829
+ this.cursor = quant;
1830
+ this.emit($mol_wire_cursor.doubt);
2040
1831
  }
2041
- async public() {
2042
- return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
1832
+ [$mol_dev_format_head]() {
1833
+ return $mol_dev_format_native(this);
1834
+ }
1835
+ get pub_empty() {
1836
+ return this.sub_from === this.pub_from;
2043
1837
  }
2044
1838
  }
2045
- $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
2046
- $.$mol_crypto_auditor_sign_size = 64;
2047
- function $mol_crypto_auditor_private_to_public(serial) {
2048
- return serial.slice(0, 86);
2049
- }
2050
- $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
1839
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
2051
1840
  })($ || ($ = {}));
2052
1841
 
2053
1842
  ;
2054
1843
  "use strict";
2055
1844
  var $;
2056
1845
  (function ($) {
2057
- let $hyoo_crowd_peer_level;
2058
- (function ($hyoo_crowd_peer_level) {
2059
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
2060
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
2061
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
2062
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
2063
- })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
2064
- class $hyoo_crowd_peer extends Object {
2065
- key_public;
2066
- key_public_serial;
2067
- key_private;
2068
- key_private_serial;
1846
+ class $mol_after_timeout extends $mol_object2 {
1847
+ delay;
1848
+ task;
2069
1849
  id;
2070
- constructor(key_public, key_public_serial, key_private, key_private_serial) {
1850
+ constructor(delay, task) {
2071
1851
  super();
2072
- this.key_public = key_public;
2073
- this.key_public_serial = key_public_serial;
2074
- this.key_private = key_private;
2075
- this.key_private_serial = key_private_serial;
2076
- this.id = $mol_int62_hash_string(this.key_public_serial);
2077
- }
2078
- static async generate() {
2079
- const pair = await $$.$mol_crypto_auditor_pair();
2080
- const serial = await pair.private.serial();
2081
- return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
1852
+ this.delay = delay;
1853
+ this.task = task;
1854
+ this.id = setTimeout(task, delay);
2082
1855
  }
2083
- static async restore(serial) {
2084
- return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
1856
+ destructor() {
1857
+ clearTimeout(this.id);
2085
1858
  }
2086
1859
  }
2087
- $.$hyoo_crowd_peer = $hyoo_crowd_peer;
1860
+ $.$mol_after_timeout = $mol_after_timeout;
2088
1861
  })($ || ($ = {}));
2089
1862
 
2090
- ;
2091
- "use strict";
2092
-
2093
1863
  ;
2094
1864
  "use strict";
2095
1865
  var $;
2096
1866
  (function ($) {
2097
- const decoders = {};
2098
- function $mol_charset_decode(buffer, encoding = 'utf8') {
2099
- let decoder = decoders[encoding];
2100
- if (!decoder)
2101
- decoder = decoders[encoding] = new TextDecoder(encoding);
2102
- return decoder.decode(buffer);
1867
+ class $mol_after_frame extends $mol_after_timeout {
1868
+ task;
1869
+ constructor(task) {
1870
+ super(16, task);
1871
+ this.task = task;
1872
+ }
2103
1873
  }
2104
- $.$mol_charset_decode = $mol_charset_decode;
1874
+ $.$mol_after_frame = $mol_after_frame;
2105
1875
  })($ || ($ = {}));
2106
1876
 
2107
1877
  ;
2108
1878
  "use strict";
2109
1879
  var $;
2110
1880
  (function ($) {
2111
- const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
2112
- let $hyoo_crowd_unit_kind;
2113
- (function ($hyoo_crowd_unit_kind) {
2114
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
2115
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
2116
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
2117
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
2118
- })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
2119
- let $hyoo_crowd_unit_group;
2120
- (function ($hyoo_crowd_unit_group) {
2121
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
2122
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
2123
- })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
2124
- class $hyoo_crowd_unit extends Object {
2125
- land;
2126
- auth;
2127
- head;
2128
- self;
2129
- next;
2130
- prev;
2131
- time;
2132
- data;
2133
- bin;
2134
- constructor(land, auth, head, self, next, prev, time, data, bin) {
2135
- super();
2136
- this.land = land;
2137
- this.auth = auth;
2138
- this.head = head;
2139
- this.self = self;
2140
- this.next = next;
2141
- this.prev = prev;
2142
- this.time = time;
2143
- this.data = data;
2144
- this.bin = bin;
2145
- }
2146
- kind() {
2147
- if (this.head === this.self && this.auth === this.self) {
2148
- if (this.head === this.land) {
2149
- return $hyoo_crowd_unit_kind.grab;
1881
+ const handled = new WeakSet();
1882
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1883
+ task;
1884
+ host;
1885
+ static warm = true;
1886
+ static planning = new Set();
1887
+ static reaping = new Set();
1888
+ static plan_task = null;
1889
+ static plan() {
1890
+ if (this.plan_task)
1891
+ return;
1892
+ this.plan_task = new $mol_after_frame(() => {
1893
+ try {
1894
+ this.sync();
2150
1895
  }
2151
- else {
2152
- return $hyoo_crowd_unit_kind.join;
1896
+ finally {
1897
+ $mol_wire_fiber.plan_task = null;
1898
+ }
1899
+ });
1900
+ }
1901
+ static sync() {
1902
+ while (this.planning.size) {
1903
+ for (const fiber of this.planning) {
1904
+ this.planning.delete(fiber);
1905
+ if (fiber.cursor >= 0)
1906
+ continue;
1907
+ if (fiber.cursor === $mol_wire_cursor.final)
1908
+ continue;
1909
+ fiber.fresh();
2153
1910
  }
2154
1911
  }
2155
- if (this.head === this.land) {
2156
- return $hyoo_crowd_unit_kind.give;
1912
+ while (this.reaping.size) {
1913
+ const fibers = this.reaping;
1914
+ this.reaping = new Set;
1915
+ for (const fiber of fibers) {
1916
+ if (!fiber.sub_empty)
1917
+ continue;
1918
+ fiber.destructor();
1919
+ }
2157
1920
  }
2158
- return $hyoo_crowd_unit_kind.data;
2159
1921
  }
2160
- group() {
2161
- return this.kind() === $hyoo_crowd_unit_kind.data
2162
- ? $hyoo_crowd_unit_group.data
2163
- : $hyoo_crowd_unit_group.auth;
1922
+ [Symbol.toStringTag];
1923
+ cache = undefined;
1924
+ get args() {
1925
+ return this.data.slice(0, this.pub_from);
2164
1926
  }
2165
- level() {
2166
- switch (this.kind()) {
2167
- case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
2168
- case $hyoo_crowd_unit_kind.give: return level(this.data);
2169
- default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
2170
- }
1927
+ result() {
1928
+ if ($mol_promise_like(this.cache))
1929
+ return;
1930
+ if (this.cache instanceof Error)
1931
+ return;
1932
+ return this.cache;
2171
1933
  }
2172
- [Symbol.toPrimitive]() {
2173
- return JSON.stringify(this);
1934
+ get incompleted() {
1935
+ return $mol_promise_like(this.cache);
1936
+ }
1937
+ field() {
1938
+ return this.task.name + '<>';
1939
+ }
1940
+ constructor(id, task, host, args) {
1941
+ super();
1942
+ this.task = task;
1943
+ this.host = host;
1944
+ if (args)
1945
+ this.data.push(...args);
1946
+ this.pub_from = this.sub_from = args?.length ?? 0;
1947
+ this[Symbol.toStringTag] = id;
1948
+ }
1949
+ plan() {
1950
+ $mol_wire_fiber.planning.add(this);
1951
+ $mol_wire_fiber.plan();
1952
+ }
1953
+ reap() {
1954
+ $mol_wire_fiber.reaping.add(this);
1955
+ $mol_wire_fiber.plan();
1956
+ }
1957
+ toString() {
1958
+ return this[Symbol.toStringTag];
1959
+ }
1960
+ toJSON() {
1961
+ return this[Symbol.toStringTag];
2174
1962
  }
2175
1963
  [$mol_dev_format_head]() {
2176
- switch (this.kind()) {
2177
- case $hyoo_crowd_unit_kind.grab:
2178
- return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
2179
- case $hyoo_crowd_unit_kind.join:
2180
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
2181
- case $hyoo_crowd_unit_kind.give:
2182
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
2183
- case $hyoo_crowd_unit_kind.data:
2184
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
2185
- }
1964
+ const cursor = {
1965
+ [$mol_wire_cursor.stale]: '🔴',
1966
+ [$mol_wire_cursor.doubt]: '🟡',
1967
+ [$mol_wire_cursor.fresh]: '🟢',
1968
+ [$mol_wire_cursor.final]: '🔵',
1969
+ }[this.cursor] ?? this.cursor.toString();
1970
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1971
+ ? $mol_dev_format_auto({
1972
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1973
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1974
+ })
1975
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
2186
1976
  }
2187
- }
2188
- $.$hyoo_crowd_unit = $hyoo_crowd_unit;
2189
- const offset = {
2190
- land_lo: 0,
2191
- land_hi: 4,
2192
- auth_lo: 8,
2193
- auth_hi: 12,
2194
- head_lo: 16,
2195
- head_hi: 20,
2196
- self_lo: 24,
2197
- self_hi: 28,
2198
- next_lo: 32,
2199
- next_hi: 36,
2200
- prev_lo: 40,
2201
- prev_hi: 44,
2202
- time: 48,
2203
- size: 54,
2204
- data: 56,
2205
- };
2206
- class $hyoo_crowd_unit_bin extends DataView {
2207
- static from_buffer(buffer) {
2208
- const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2209
- return new this(buffer.slice(0, size / 2).buffer);
1977
+ get $() {
1978
+ return (this.host ?? this.task)['$'];
2210
1979
  }
2211
- static from_unit(unit) {
2212
- if (unit.bin)
2213
- return unit.bin;
2214
- const type = unit.data === null
2215
- ? 0
2216
- : unit.data instanceof Uint8Array
2217
- ? -1
2218
- : 1;
2219
- const buff = type === 0 ? null
2220
- : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
2221
- : unit.data;
2222
- const size = buff?.byteLength ?? 0;
2223
- if (type > 0 && size > 2 ** 15 - 1)
2224
- throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
2225
- if (type < 0 && size > 2 ** 15)
2226
- throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
2227
- const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
2228
- const mem = new Uint8Array(total);
2229
- const bin = new $hyoo_crowd_unit_bin(mem.buffer);
2230
- const land = $mol_int62_from_string(unit.land);
2231
- bin.setInt32(offset.land_lo, land.lo, true);
2232
- bin.setInt32(offset.land_hi, land.hi, true);
2233
- const auth = $mol_int62_from_string(unit.auth);
2234
- bin.setInt32(offset.auth_lo, auth.lo, true);
2235
- bin.setInt32(offset.auth_hi, auth.hi, true);
2236
- const head = $mol_int62_from_string(unit.head);
2237
- bin.setInt32(offset.head_lo, head.lo, true);
2238
- bin.setInt32(offset.head_hi, head.hi, true);
2239
- const self = $mol_int62_from_string(unit.self);
2240
- bin.setInt32(offset.self_lo, self.lo, true);
2241
- bin.setInt32(offset.self_hi, self.hi, true);
2242
- const next = $mol_int62_from_string(unit.next);
2243
- bin.setInt32(offset.next_lo, next.lo, true);
2244
- bin.setInt32(offset.next_hi, next.hi, true);
2245
- const prev = $mol_int62_from_string(unit.prev);
2246
- bin.setInt32(offset.prev_lo, prev.lo, true);
2247
- bin.setInt32(offset.prev_hi, prev.hi, true);
2248
- bin.setInt32(offset.time, unit.time, true);
2249
- bin.setInt16(offset.size, type * size, true);
2250
- if (buff)
2251
- mem.set(buff, offset.data);
2252
- return bin;
1980
+ emit(quant = $mol_wire_cursor.stale) {
1981
+ if (this.sub_empty)
1982
+ this.plan();
1983
+ else
1984
+ super.emit(quant);
2253
1985
  }
2254
- sign(next) {
2255
- const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
2256
- const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
2257
- if (!next)
2258
- return buff;
2259
- buff.set(next);
2260
- return buff;
1986
+ fresh() {
1987
+ if (this.cursor === $mol_wire_cursor.fresh)
1988
+ return;
1989
+ if (this.cursor === $mol_wire_cursor.final)
1990
+ return;
1991
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1992
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1993
+ ;
1994
+ this.data[i]?.fresh();
1995
+ if (this.cursor !== $mol_wire_cursor.doubt)
1996
+ break check;
1997
+ }
1998
+ this.cursor = $mol_wire_cursor.fresh;
1999
+ return;
2000
+ }
2001
+ const bu = this.track_on();
2002
+ let result;
2003
+ try {
2004
+ switch (this.pub_from) {
2005
+ case 0:
2006
+ result = this.task.call(this.host);
2007
+ break;
2008
+ case 1:
2009
+ result = this.task.call(this.host, this.data[0]);
2010
+ break;
2011
+ default:
2012
+ result = this.task.call(this.host, ...this.args);
2013
+ break;
2014
+ }
2015
+ if ($mol_promise_like(result) && !handled.has(result)) {
2016
+ const put = (res) => {
2017
+ if (this.cache === result)
2018
+ this.put(res);
2019
+ return res;
2020
+ };
2021
+ result = result.then(put, put);
2022
+ }
2023
+ }
2024
+ catch (error) {
2025
+ if (error instanceof Error || $mol_promise_like(error)) {
2026
+ result = error;
2027
+ }
2028
+ else {
2029
+ result = new Error(String(error), { cause: error });
2030
+ }
2031
+ if ($mol_promise_like(result) && !handled.has(result)) {
2032
+ result = result.finally(() => {
2033
+ if (this.cache === result)
2034
+ this.absorb();
2035
+ });
2036
+ }
2037
+ }
2038
+ if ($mol_promise_like(result) && !handled.has(result)) {
2039
+ result = Object.assign(result, {
2040
+ destructor: result['destructor'] ?? (() => { })
2041
+ });
2042
+ handled.add(result);
2043
+ const error = new Error(`Promise in ${this}`);
2044
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
2045
+ }
2046
+ if (!$mol_promise_like(result)) {
2047
+ this.track_cut();
2048
+ }
2049
+ this.track_off(bu);
2050
+ this.put(result);
2261
2051
  }
2262
- size() {
2263
- return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2052
+ refresh() {
2053
+ this.cursor = $mol_wire_cursor.stale;
2054
+ this.fresh();
2264
2055
  }
2265
- sens() {
2266
- return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
2056
+ sync() {
2057
+ if (!$mol_wire_fiber.warm) {
2058
+ return this.result();
2059
+ }
2060
+ this.promote();
2061
+ this.fresh();
2062
+ if (this.cache instanceof Error) {
2063
+ return $mol_fail_hidden(this.cache);
2064
+ }
2065
+ if ($mol_promise_like(this.cache)) {
2066
+ return $mol_fail_hidden(this.cache);
2067
+ }
2068
+ return this.cache;
2267
2069
  }
2268
- unit() {
2269
- const land = $mol_int62_to_string({
2270
- lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
2271
- hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
2272
- });
2273
- const auth = $mol_int62_to_string({
2274
- lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
2275
- hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
2276
- });
2277
- const head = $mol_int62_to_string({
2278
- lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
2279
- hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
2280
- });
2281
- const self = $mol_int62_to_string({
2282
- lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
2283
- hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
2284
- });
2285
- const next = $mol_int62_to_string({
2286
- lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
2287
- hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
2288
- });
2289
- const prev = $mol_int62_to_string({
2290
- lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
2291
- hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
2292
- });
2293
- const time = this.getInt32(offset.time, true) << 1 >> 1;
2294
- const type_size = this.getInt16(offset.size, true);
2295
- let data = null;
2296
- if (type_size) {
2297
- try {
2298
- var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
2070
+ async async() {
2071
+ while (true) {
2072
+ this.fresh();
2073
+ if (this.cache instanceof Error) {
2074
+ $mol_fail_hidden(this.cache);
2299
2075
  }
2300
- catch (error) {
2301
- error['message'] += `\nhead=${head};self=${self}`;
2302
- $mol_fail_hidden(error);
2076
+ if (!$mol_promise_like(this.cache))
2077
+ return this.cache;
2078
+ await Promise.race([this.cache, this.step()]);
2079
+ if (!$mol_promise_like(this.cache))
2080
+ return this.cache;
2081
+ if (this.cursor === $mol_wire_cursor.final) {
2082
+ await new Promise(() => { });
2303
2083
  }
2304
- if (type_size < 0)
2305
- data = buff;
2306
- else
2307
- data = JSON.parse($mol_charset_decode(buff));
2308
2084
  }
2309
- return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
2085
+ }
2086
+ step() {
2087
+ return new Promise(done => {
2088
+ const sub = new $mol_wire_pub_sub;
2089
+ const prev = sub.track_on();
2090
+ sub.track_next(this);
2091
+ sub.track_off(prev);
2092
+ sub.absorb = () => {
2093
+ done(null);
2094
+ sub.destructor();
2095
+ };
2096
+ });
2310
2097
  }
2311
2098
  }
2312
- $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
2313
- function $hyoo_crowd_unit_compare(left, right) {
2314
- return (left.group() - right.group())
2315
- || (left.time - right.time)
2316
- || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
2317
- || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
2318
- || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
2319
- || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
2320
- || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
2321
- || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
2322
- }
2323
- $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
2099
+ $.$mol_wire_fiber = $mol_wire_fiber;
2324
2100
  })($ || ($ = {}));
2325
2101
 
2326
2102
  ;
@@ -2385,6 +2161,206 @@ var $;
2385
2161
  $.$mol_key = $mol_key;
2386
2162
  })($ || ($ = {}));
2387
2163
 
2164
+ ;
2165
+ "use strict";
2166
+ var $;
2167
+ (function ($) {
2168
+ $.$mol_compare_deep_cache = new WeakMap();
2169
+ function $mol_compare_deep(left, right) {
2170
+ if (Object.is(left, right))
2171
+ return true;
2172
+ if (left === null)
2173
+ return false;
2174
+ if (right === null)
2175
+ return false;
2176
+ if (typeof left !== 'object')
2177
+ return false;
2178
+ if (typeof right !== 'object')
2179
+ return false;
2180
+ const left_proto = Reflect.getPrototypeOf(left);
2181
+ const right_proto = Reflect.getPrototypeOf(right);
2182
+ if (left_proto !== right_proto)
2183
+ return false;
2184
+ if (left instanceof Boolean)
2185
+ return Object.is(left.valueOf(), right['valueOf']());
2186
+ if (left instanceof Number)
2187
+ return Object.is(left.valueOf(), right['valueOf']());
2188
+ if (left instanceof String)
2189
+ return Object.is(left.valueOf(), right['valueOf']());
2190
+ if (left instanceof Date)
2191
+ return Object.is(left.valueOf(), right['valueOf']());
2192
+ if (left instanceof RegExp)
2193
+ return left.source === right.source && left.flags === right.flags;
2194
+ if (left instanceof Error)
2195
+ return left.message === right.message && left.stack === right.stack;
2196
+ let left_cache = $.$mol_compare_deep_cache.get(left);
2197
+ if (left_cache) {
2198
+ const right_cache = left_cache.get(right);
2199
+ if (typeof right_cache === 'boolean')
2200
+ return right_cache;
2201
+ }
2202
+ else {
2203
+ left_cache = new WeakMap([[right, true]]);
2204
+ $.$mol_compare_deep_cache.set(left, left_cache);
2205
+ }
2206
+ let result;
2207
+ try {
2208
+ if (!left_proto)
2209
+ result = compare_pojo(left, right);
2210
+ else if (!Reflect.getPrototypeOf(left_proto))
2211
+ result = compare_pojo(left, right);
2212
+ else if (Symbol.toPrimitive in left)
2213
+ result = compare_primitive(left, right);
2214
+ else if (Array.isArray(left))
2215
+ result = compare_array(left, right);
2216
+ else if (left instanceof Set)
2217
+ result = compare_set(left, right);
2218
+ else if (left instanceof Map)
2219
+ result = compare_map(left, right);
2220
+ else if (ArrayBuffer.isView(left))
2221
+ result = compare_buffer(left, right);
2222
+ else if (Symbol.iterator in left)
2223
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2224
+ else
2225
+ result = false;
2226
+ }
2227
+ finally {
2228
+ left_cache.set(right, result);
2229
+ }
2230
+ return result;
2231
+ }
2232
+ $.$mol_compare_deep = $mol_compare_deep;
2233
+ function compare_array(left, right) {
2234
+ const len = left.length;
2235
+ if (len !== right.length)
2236
+ return false;
2237
+ for (let i = 0; i < len; ++i) {
2238
+ if (!$mol_compare_deep(left[i], right[i]))
2239
+ return false;
2240
+ }
2241
+ return true;
2242
+ }
2243
+ function compare_buffer(left, right) {
2244
+ const len = left.byteLength;
2245
+ if (len !== right.byteLength)
2246
+ return false;
2247
+ if (left instanceof DataView)
2248
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2249
+ for (let i = 0; i < len; ++i) {
2250
+ if (left[i] !== right[i])
2251
+ return false;
2252
+ }
2253
+ return true;
2254
+ }
2255
+ function compare_iterator(left, right) {
2256
+ while (true) {
2257
+ const left_next = left.next();
2258
+ const right_next = right.next();
2259
+ if (left_next.done !== right_next.done)
2260
+ return false;
2261
+ if (left_next.done)
2262
+ break;
2263
+ if (!$mol_compare_deep(left_next.value, right_next.value))
2264
+ return false;
2265
+ }
2266
+ return true;
2267
+ }
2268
+ function compare_set(left, right) {
2269
+ if (left.size !== right.size)
2270
+ return false;
2271
+ return compare_iterator(left.values(), right.values());
2272
+ }
2273
+ function compare_map(left, right) {
2274
+ if (left.size !== right.size)
2275
+ return false;
2276
+ return compare_iterator(left.keys(), right.keys())
2277
+ && compare_iterator(left.values(), right.values());
2278
+ }
2279
+ function compare_pojo(left, right) {
2280
+ const left_keys = Object.getOwnPropertyNames(left);
2281
+ const right_keys = Object.getOwnPropertyNames(right);
2282
+ if (!compare_array(left_keys, right_keys))
2283
+ return false;
2284
+ for (let key of left_keys) {
2285
+ if (!$mol_compare_deep(left[key], right[key]))
2286
+ return false;
2287
+ }
2288
+ const left_syms = Object.getOwnPropertySymbols(left);
2289
+ const right_syms = Object.getOwnPropertySymbols(right);
2290
+ if (!compare_array(left_syms, right_syms))
2291
+ return false;
2292
+ for (let key of left_syms) {
2293
+ if (!$mol_compare_deep(left[key], right[key]))
2294
+ return false;
2295
+ }
2296
+ return true;
2297
+ }
2298
+ function compare_primitive(left, right) {
2299
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2300
+ }
2301
+ })($ || ($ = {}));
2302
+
2303
+ ;
2304
+ "use strict";
2305
+ var $;
2306
+ (function ($) {
2307
+ class $mol_wire_task extends $mol_wire_fiber {
2308
+ static getter(task) {
2309
+ return function $mol_wire_task_get(host, args) {
2310
+ const sub = $mol_wire_auto();
2311
+ const existen = sub?.track_next();
2312
+ reuse: if (existen) {
2313
+ if (!existen.temp)
2314
+ break reuse;
2315
+ if (existen.host !== host)
2316
+ break reuse;
2317
+ if (existen.task !== task)
2318
+ break reuse;
2319
+ if (!$mol_compare_deep(existen.args, args))
2320
+ break reuse;
2321
+ return existen;
2322
+ }
2323
+ const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
2324
+ if (existen?.temp) {
2325
+ $$.$mol_log3_warn({
2326
+ place: '$mol_wire_task',
2327
+ message: `Non idempotency`,
2328
+ existen,
2329
+ next,
2330
+ hint: 'Ignore it',
2331
+ });
2332
+ }
2333
+ return next;
2334
+ };
2335
+ }
2336
+ get temp() {
2337
+ return true;
2338
+ }
2339
+ complete() {
2340
+ if ($mol_promise_like(this.cache))
2341
+ return;
2342
+ this.destructor();
2343
+ }
2344
+ put(next) {
2345
+ const prev = this.cache;
2346
+ this.cache = next;
2347
+ if ($mol_promise_like(next)) {
2348
+ this.cursor = $mol_wire_cursor.fresh;
2349
+ if (next !== prev)
2350
+ this.emit();
2351
+ return next;
2352
+ }
2353
+ this.cursor = $mol_wire_cursor.final;
2354
+ if (this.sub_empty)
2355
+ this.destructor();
2356
+ else if (next !== prev)
2357
+ this.emit();
2358
+ return next;
2359
+ }
2360
+ }
2361
+ $.$mol_wire_task = $mol_wire_task;
2362
+ })($ || ($ = {}));
2363
+
2388
2364
  ;
2389
2365
  "use strict";
2390
2366
  var $;
@@ -2631,6 +2607,32 @@ var $;
2631
2607
  $.$mol_mem_key = $mol_wire_plex;
2632
2608
  })($ || ($ = {}));
2633
2609
 
2610
+ ;
2611
+ "use strict";
2612
+ var $;
2613
+ (function ($) {
2614
+ function $mol_wire_sync(obj) {
2615
+ return new Proxy(obj, {
2616
+ get(obj, field) {
2617
+ const val = obj[field];
2618
+ if (typeof val !== 'function')
2619
+ return val;
2620
+ const temp = $mol_wire_task.getter(val);
2621
+ return function $mol_wire_sync(...args) {
2622
+ const fiber = temp(obj, args);
2623
+ return fiber.sync();
2624
+ };
2625
+ },
2626
+ apply(obj, self, args) {
2627
+ const temp = $mol_wire_task.getter(obj);
2628
+ const fiber = temp(self, args);
2629
+ return fiber.sync();
2630
+ },
2631
+ });
2632
+ }
2633
+ $.$mol_wire_sync = $mol_wire_sync;
2634
+ })($ || ($ = {}));
2635
+
2634
2636
  ;
2635
2637
  "use strict";
2636
2638
  var $;