hyoo_sync_client 0.0.376 → 0.0.377

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