hyoo_sync_client 0.0.604 → 0.0.605

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/web.js CHANGED
@@ -30,10 +30,9 @@ $.$$ = $
30
30
 
31
31
  ;
32
32
  "use strict";
33
-
34
- ;
35
- "use strict";
36
- let $hyoo_sync_revision = "echo";
33
+ // namespace $ {
34
+ // $mol_report_bugsnag = '18acf016ed2a2a4cc4445daa9dd2dd3c'
35
+ // }
37
36
 
38
37
  ;
39
38
  "use strict";
@@ -51,6 +50,11 @@ var $;
51
50
  var $;
52
51
  (function ($) {
53
52
  const instances = new WeakSet();
53
+ /**
54
+ * Proxy that delegates all to lazy returned target.
55
+ *
56
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
57
+ */
54
58
  function $mol_delegate(proto, target) {
55
59
  const proxy = new Proxy(proto, {
56
60
  get: (_, field) => {
@@ -154,7 +158,7 @@ var $;
154
158
  var $;
155
159
  (function ($) {
156
160
  function $mol_fail_hidden(error) {
157
- throw error;
161
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
158
162
  }
159
163
  $.$mol_fail_hidden = $mol_fail_hidden;
160
164
  })($ || ($ = {}));
@@ -198,6 +202,16 @@ var $;
198
202
  "use strict";
199
203
  var $;
200
204
  (function ($) {
205
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
206
+ $.$mol_key_store = new WeakMap();
207
+ })($ || ($ = {}));
208
+
209
+ ;
210
+ "use strict";
211
+ var $;
212
+ (function ($) {
213
+ if (!Symbol.dispose)
214
+ Symbol.dispose = Symbol('Symbol.dispose');
201
215
  class $mol_object2 {
202
216
  static $ = $;
203
217
  [Symbol.toStringTag];
@@ -206,7 +220,7 @@ var $;
206
220
  if (this[$mol_ambient_ref])
207
221
  return this[$mol_ambient_ref];
208
222
  const owner = $mol_owning_get(this);
209
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
223
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
210
224
  }
211
225
  set $(next) {
212
226
  if (this[$mol_ambient_ref])
@@ -228,8 +242,17 @@ var $;
228
242
  static toJSON() {
229
243
  return this.toString();
230
244
  }
245
+ static [$mol_key_handle]() {
246
+ return this.toString();
247
+ }
231
248
  destructor() { }
232
249
  static destructor() { }
250
+ [Symbol.dispose]() {
251
+ this.destructor();
252
+ }
253
+ //[ Symbol.toPrimitive ]( hint: string ) {
254
+ // return hint === 'number' ? this.valueOf() : this.toString()
255
+ //}
233
256
  toString() {
234
257
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
235
258
  }
@@ -239,21 +262,70 @@ var $;
239
262
 
240
263
  ;
241
264
  "use strict";
242
-
243
- ;
244
- "use strict";
245
- var $node = $node || {};
265
+ var $;
266
+ (function ($) {
267
+ let buf = new Uint8Array(2 ** 12); // 4KB Mem Page
268
+ /** Temporary buffer. Recursive usage isn't supported. */
269
+ function $mol_charset_buffer(size) {
270
+ if (buf.byteLength < size)
271
+ buf = new Uint8Array(size);
272
+ return buf;
273
+ }
274
+ $.$mol_charset_buffer = $mol_charset_buffer;
275
+ })($ || ($ = {}));
246
276
 
247
277
  ;
248
278
  "use strict";
249
279
  var $;
250
280
  (function ($) {
251
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
252
- const encoder = new TextEncoder();
253
- function $mol_charset_encode(value) {
254
- return encoder.encode(value);
281
+ function $mol_charset_encode(str) {
282
+ const buf = $mol_charset_buffer(str.length * 3);
283
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
255
284
  }
256
285
  $.$mol_charset_encode = $mol_charset_encode;
286
+ function $mol_charset_encode_to(str, buf, from = 0) {
287
+ let pos = from;
288
+ for (let i = 0; i < str.length; i++) {
289
+ let code = str.charCodeAt(i);
290
+ if (code < 0x80) { // ASCII - 1 octet
291
+ buf[pos++] = code;
292
+ }
293
+ else if (code < 0x800) { // 2 octet
294
+ buf[pos++] = 0xc0 | (code >> 6);
295
+ buf[pos++] = 0x80 | (code & 0x3f);
296
+ }
297
+ else if (code < 0xd800 || code >= 0xe000) { // 3 octet
298
+ buf[pos++] = 0xe0 | (code >> 12);
299
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
300
+ buf[pos++] = 0x80 | (code & 0x3f);
301
+ }
302
+ else { // surrogate pair
303
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
304
+ buf[pos++] = 0xf0 | (point >> 18);
305
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
306
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
307
+ buf[pos++] = 0x80 | (point & 0x3f);
308
+ }
309
+ }
310
+ return pos - from;
311
+ }
312
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
313
+ function $mol_charset_encode_size(str) {
314
+ let size = 0;
315
+ for (let i = 0; i < str.length; i++) {
316
+ let code = str.charCodeAt(i);
317
+ if (code < 0x80)
318
+ size += 1;
319
+ else if (code < 0x800)
320
+ size += 2;
321
+ else if (code < 0xd800 || code >= 0xe000)
322
+ size += 3;
323
+ else
324
+ size += 4;
325
+ }
326
+ return size;
327
+ }
328
+ $.$mol_charset_encode_size = $mol_charset_encode_size;
257
329
  })($ || ($ = {}));
258
330
 
259
331
  ;
@@ -369,11 +441,12 @@ var $;
369
441
  get: () => stack_get() + '\n' + [
370
442
  this.cause ?? 'no cause',
371
443
  ...this.errors.flatMap(e => [
372
- e.stack,
444
+ String(e.stack),
373
445
  ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
374
446
  ])
375
447
  ].map(frame_normalize).join('\n')
376
448
  });
449
+ // в nodejs, что б не дублировалось cause в консоли
377
450
  Object.defineProperty(this, 'cause', {
378
451
  get: () => cause
379
452
  });
@@ -404,6 +477,10 @@ var $;
404
477
  "use strict";
405
478
  var $;
406
479
  (function ($) {
480
+ /**
481
+ * Checks for value of given enum and returns expected type.
482
+ * @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_enum_demo
483
+ */
407
484
  function $mol_data_enum(name, dict) {
408
485
  const index = {};
409
486
  for (let key in dict) {
@@ -428,12 +505,26 @@ var $;
428
505
  $.$mol_crypto_native = crypto;
429
506
  })($ || ($ = {}));
430
507
 
508
+ ;
509
+ "use strict";
510
+ var $;
511
+ (function ($) {
512
+ function $mol_base64_url_encode(buffer) {
513
+ return buffer.toBase64({ alphabet: 'base64url', omitPadding: true });
514
+ }
515
+ $.$mol_base64_url_encode = $mol_base64_url_encode;
516
+ function $mol_base64_url_decode(str) {
517
+ return Uint8Array.fromBase64(str, { alphabet: 'base64url' });
518
+ }
519
+ $.$mol_base64_url_decode = $mol_base64_url_decode;
520
+ })($ || ($ = {}));
521
+
431
522
  ;
432
523
  "use strict";
433
524
  var $;
434
525
  (function ($) {
435
526
  function $mol_base64_encode(src) {
436
- throw new Error('Not implemented');
527
+ return src.toBase64();
437
528
  }
438
529
  $.$mol_base64_encode = $mol_base64_encode;
439
530
  })($ || ($ = {}));
@@ -477,7 +568,9 @@ var $;
477
568
  return $mol_dom_context.btoa(binary_string(str));
478
569
  }
479
570
  $.$mol_base64_encode_web = $mol_base64_encode_web;
480
- $.$mol_base64_encode = $mol_base64_encode_web;
571
+ if (!('toBase64' in Uint8Array.prototype)) {
572
+ $.$mol_base64_encode = $mol_base64_encode_web;
573
+ }
481
574
  })($ || ($ = {}));
482
575
 
483
576
  ;
@@ -485,7 +578,7 @@ var $;
485
578
  var $;
486
579
  (function ($) {
487
580
  function $mol_base64_decode(base64) {
488
- throw new Error('Not implemented');
581
+ return Uint8Array.fromBase64(base64);
489
582
  }
490
583
  $.$mol_base64_decode = $mol_base64_decode;
491
584
  })($ || ($ = {}));
@@ -495,35 +588,46 @@ var $;
495
588
  var $;
496
589
  (function ($) {
497
590
  function $mol_base64_decode_web(base64Str) {
498
- return new Uint8Array($mol_dom_context.atob(base64Str).split('').map(c => c.charCodeAt(0)));
591
+ const buf = Uint8Array.from($mol_dom_context.atob(base64Str), c => c.charCodeAt(0));
592
+ return buf;
499
593
  }
500
594
  $.$mol_base64_decode_web = $mol_base64_decode_web;
501
- $.$mol_base64_decode = $mol_base64_decode_web;
595
+ if (!('fromBase64' in Uint8Array)) {
596
+ $.$mol_base64_decode = $mol_base64_decode_web;
597
+ }
502
598
  })($ || ($ = {}));
503
599
 
504
600
  ;
505
601
  "use strict";
506
602
  var $;
507
603
  (function ($) {
508
- function $mol_base64_url_encode(buffer) {
604
+ function $mol_base64_url_encode_web(buffer) {
509
605
  return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
510
606
  }
511
- $.$mol_base64_url_encode = $mol_base64_url_encode;
512
- function $mol_base64_url_decode(str) {
607
+ $.$mol_base64_url_encode_web = $mol_base64_url_encode_web;
608
+ if (!('toBase64' in Uint8Array.prototype)) {
609
+ $.$mol_base64_url_encode = $mol_base64_url_encode_web;
610
+ }
611
+ function $mol_base64_url_decode_web(str) {
513
612
  return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
514
613
  }
515
- $.$mol_base64_url_decode = $mol_base64_url_decode;
614
+ $.$mol_base64_url_decode_web = $mol_base64_url_decode_web;
615
+ if (!('fromBase64' in Uint8Array)) {
616
+ $.$mol_base64_url_decode = $mol_base64_url_decode_web;
617
+ }
516
618
  })($ || ($ = {}));
517
619
 
518
620
  ;
519
621
  "use strict";
520
622
  var $;
521
623
  (function ($) {
624
+ /** @FIXME Need polyfill for Safari and Node (https://github.com/microsoft/MSR-JavaScript-Crypto/) */
522
625
  const algorithm = {
523
626
  name: 'ECDSA',
524
627
  hash: 'SHA-256',
525
628
  namedCurve: "P-256",
526
629
  };
630
+ /** Asymmetric signing pair with shortest payload */
527
631
  async function $mol_crypto_auditor_pair() {
528
632
  const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
529
633
  return {
@@ -532,8 +636,10 @@ var $;
532
636
  };
533
637
  }
534
638
  $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
639
+ /** Asymmetric signing public key wrapper with shortest payload */
535
640
  class $mol_crypto_auditor_public extends Object {
536
641
  native;
642
+ /** Key size in bytes. */
537
643
  static size_str = 86;
538
644
  static size_bin = 64;
539
645
  constructor(native) {
@@ -554,10 +660,12 @@ var $;
554
660
  y: serial.slice(43, 86),
555
661
  }, algorithm, true, ['verify']));
556
662
  }
663
+ /** 86 bytes */
557
664
  async serial() {
558
665
  const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
559
666
  return x + y;
560
667
  }
668
+ /** 64 bytes */
561
669
  async toArray() {
562
670
  const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
563
671
  return new Uint8Array([
@@ -570,8 +678,10 @@ var $;
570
678
  }
571
679
  }
572
680
  $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
681
+ /** Asymmetric signing private key wrapper with shortest payload */
573
682
  class $mol_crypto_auditor_private extends Object {
574
683
  native;
684
+ /** Key size in bytes. */
575
685
  static size_str = 129;
576
686
  static size_bin = 96;
577
687
  constructor(native) {
@@ -594,10 +704,12 @@ var $;
594
704
  d: serial.slice(86, 129),
595
705
  }, algorithm, true, ['sign']));
596
706
  }
707
+ /** 129 bytes */
597
708
  async serial() {
598
709
  const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
599
710
  return x + y + d;
600
711
  }
712
+ /** 96 bytes */
601
713
  async toArray() {
602
714
  const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
603
715
  return new Uint8Array([
@@ -606,14 +718,17 @@ var $;
606
718
  ...$mol_base64_url_decode(d),
607
719
  ]);
608
720
  }
721
+ /** 64 bytes */
609
722
  async sign(data) {
610
723
  return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
611
724
  }
725
+ /** Makes public key from private */
612
726
  async public() {
613
727
  return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
614
728
  }
615
729
  }
616
730
  $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
731
+ /** Sign size in bytes. */
617
732
  $.$mol_crypto_auditor_sign_size = 64;
618
733
  function $mol_crypto_auditor_private_to_public(serial) {
619
734
  return serial.slice(0, 86);
@@ -662,6 +777,7 @@ var $;
662
777
  "use strict";
663
778
  var $;
664
779
  (function ($) {
780
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
665
781
  $['devtoolsFormatters'] ||= [];
666
782
  function $mol_dev_format_register(config) {
667
783
  $['devtoolsFormatters'].push(config);
@@ -669,6 +785,17 @@ var $;
669
785
  $.$mol_dev_format_register = $mol_dev_format_register;
670
786
  $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
671
787
  $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
788
+ function $mol_dev_format_button(label, click) {
789
+ return $mol_dev_format_auto({
790
+ [$.$mol_dev_format_head]() {
791
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
792
+ },
793
+ [$.$mol_dev_format_body]() {
794
+ Promise.resolve().then(click);
795
+ return $.$mol_dev_format_span({});
796
+ }
797
+ });
798
+ }
672
799
  $mol_dev_format_register({
673
800
  header: (val, config = false) => {
674
801
  if (config)
@@ -686,17 +813,50 @@ var $;
686
813
  if (typeof val === 'function') {
687
814
  return $mol_dev_format_native(val);
688
815
  }
816
+ if (val instanceof Error) {
817
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
818
+ }
819
+ if (val instanceof Promise) {
820
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
821
+ }
689
822
  if (Symbol.toStringTag in val) {
690
823
  return $mol_dev_format_native(val);
691
824
  }
692
825
  return null;
693
826
  },
694
- hasBody: val => val[$.$mol_dev_format_body],
695
- body: val => val[$.$mol_dev_format_body](),
827
+ hasBody: (val, config = false) => {
828
+ if (config)
829
+ return false;
830
+ if (!val)
831
+ return false;
832
+ // if( Error.isError( val ) ) true
833
+ if (val[$.$mol_dev_format_body])
834
+ return true;
835
+ return false;
836
+ },
837
+ body: (val, config = false) => {
838
+ if (config)
839
+ return null;
840
+ if (!val)
841
+ return null;
842
+ if ($.$mol_dev_format_body in val) {
843
+ try {
844
+ return val[$.$mol_dev_format_body]();
845
+ }
846
+ catch (error) {
847
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
848
+ }
849
+ }
850
+ // if( Error.isError( val ) ) {
851
+ // return $mol_dev_format_native( val )
852
+ // }
853
+ return null;
854
+ },
696
855
  });
697
856
  function $mol_dev_format_native(obj) {
698
857
  if (typeof obj === 'undefined')
699
858
  return $.$mol_dev_format_shade('undefined');
859
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
700
860
  return [
701
861
  'object',
702
862
  {
@@ -731,33 +891,101 @@ var $;
731
891
  ];
732
892
  }
733
893
  $.$mol_dev_format_element = $mol_dev_format_element;
734
- function $mol_dev_format_span(style, ...content) {
735
- return $mol_dev_format_element('span', {
736
- ...style,
737
- }, ...content);
738
- }
739
- $.$mol_dev_format_span = $mol_dev_format_span;
894
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
740
895
  $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
741
896
  $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
742
897
  $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
743
898
  $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
744
899
  $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
745
900
  $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
746
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
901
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
747
902
  'color': 'magenta',
748
903
  });
749
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
904
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
750
905
  'font-weight': 'bold',
751
906
  });
752
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
907
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
753
908
  'color': 'green',
754
909
  });
755
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
910
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
756
911
  'color': 'gray',
757
912
  });
758
913
  $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
759
- 'margin-left': '13px'
914
+ 'margin-inline-start': '13px'
760
915
  });
916
+ class Stack extends Array {
917
+ // [ Symbol.toPrimitive ]() {
918
+ // return this.toString()
919
+ // }
920
+ match(...args) {
921
+ return this.toString().match(...args);
922
+ }
923
+ split(...args) {
924
+ return this.toString().split(...args);
925
+ }
926
+ toString() {
927
+ return this.join('\n');
928
+ }
929
+ }
930
+ class Call extends Object {
931
+ type;
932
+ function;
933
+ method;
934
+ eval;
935
+ source;
936
+ offset;
937
+ pos;
938
+ object;
939
+ flags;
940
+ [Symbol.toStringTag];
941
+ constructor(call) {
942
+ super();
943
+ this.type = call.getTypeName() ?? '';
944
+ this.function = call.getFunctionName() ?? '';
945
+ this.method = call.getMethodName() ?? '';
946
+ if (this.method === this.function)
947
+ this.method = '';
948
+ // const func = c.getFunction()
949
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
950
+ this.eval = call.getEvalOrigin() ?? '';
951
+ this.source = call.getScriptNameOrSourceURL() ?? '';
952
+ this.object = call.getThis();
953
+ this.offset = call.getPosition();
954
+ const flags = [];
955
+ if (call.isAsync())
956
+ flags.push('async');
957
+ if (call.isConstructor())
958
+ flags.push('constructor');
959
+ if (call.isEval())
960
+ flags.push('eval');
961
+ if (call.isNative())
962
+ flags.push('native');
963
+ if (call.isPromiseAll())
964
+ flags.push('PromiseAll');
965
+ if (call.isToplevel())
966
+ flags.push('top');
967
+ this.flags = flags;
968
+ const type = this.type ? this.type + '.' : '';
969
+ const func = this.function || '<anon>';
970
+ const method = this.method ? ' [' + this.method + '] ' : '';
971
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
972
+ }
973
+ [Symbol.toPrimitive]() {
974
+ return this.toString();
975
+ }
976
+ toString() {
977
+ const object = this.object || '';
978
+ const label = this[Symbol.toStringTag];
979
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
980
+ return `\tat ${object}${label} (${source})`;
981
+ }
982
+ [$.$mol_dev_format_head]() {
983
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
984
+ $mol_dev_format_native(this.object),
985
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
986
+ }
987
+ }
988
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
761
989
  })($ || ($ = {}));
762
990
 
763
991
  ;
@@ -784,16 +1012,23 @@ var $;
784
1012
  const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
785
1013
  let $hyoo_crowd_unit_kind;
786
1014
  (function ($hyoo_crowd_unit_kind) {
1015
+ /** Grab Land by King */
787
1016
  $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
1017
+ /** Join Peer to Land */
788
1018
  $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
1019
+ /* Give Level for Peer for Land */
789
1020
  $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
1021
+ /** Add Data to Land by joined Peer with right Level */
790
1022
  $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
791
1023
  })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
792
1024
  let $hyoo_crowd_unit_group;
793
1025
  (function ($hyoo_crowd_unit_group) {
1026
+ /** Join and Give units */
794
1027
  $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
1028
+ /** Data units */
795
1029
  $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
796
1030
  })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
1031
+ /** Independent part of data. */
797
1032
  class $hyoo_crowd_unit extends Object {
798
1033
  land;
799
1034
  auth;
@@ -804,7 +1039,24 @@ var $;
804
1039
  time;
805
1040
  data;
806
1041
  bin;
807
- constructor(land, auth, head, self, next, prev, time, data, bin) {
1042
+ constructor(
1043
+ /** Identifier of land. */
1044
+ land,
1045
+ /** Identifier of auth. */
1046
+ auth,
1047
+ /** Identifier of head node. */
1048
+ head,
1049
+ /** Self identifier inside head after prev before next. */
1050
+ self,
1051
+ /** Identifier of next node. */
1052
+ next,
1053
+ /** Identifier of prev node. */
1054
+ prev,
1055
+ /** Monotonic real clock. 4B / info = 31b */
1056
+ time,
1057
+ /** type-size = bin<0 | null=0 | json>0 */
1058
+ /** Associated atomic data. mem = 4B+ / bin = (0|8B)+ / type-size-info = 16b */
1059
+ data, bin) {
808
1060
  super();
809
1061
  this.land = land;
810
1062
  this.auth = auth;
@@ -932,9 +1184,28 @@ var $;
932
1184
  buff.set(next);
933
1185
  return buff;
934
1186
  }
1187
+ // land( next?: $mol_int62_pair ) {
1188
+ // if( next ) {
1189
+ // this.setInt32( offset.land_lo, next.lo, true )
1190
+ // this.setInt32( offset.land_hi, next.hi, true )
1191
+ // return next
1192
+ // } else {
1193
+ // return {
1194
+ // lo: this.getInt32( offset.land_lo, true ),
1195
+ // hi: this.getInt32( offset.land_hi, true ),
1196
+ // }
1197
+ // }
1198
+ // }
935
1199
  size() {
936
1200
  return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
937
1201
  }
1202
+ // data() {
1203
+ // const info = this.getUint16( offset.data )
1204
+ // const size = Math.abs( info )
1205
+ // const buf = new Uint8Array( this.buffer, this.byteOffset + offset.sens, size )
1206
+ // const data = info > 0 ? JSON.parse( $mol_charset_decode( buf ) ) : info < 0 ? buf : null
1207
+ // return data
1208
+ // }
938
1209
  sens() {
939
1210
  return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
940
1211
  }
@@ -1000,11 +1271,32 @@ var $;
1000
1271
  "use strict";
1001
1272
  var $;
1002
1273
  (function ($) {
1274
+ /** Generates unique identifier. */
1275
+ function $mol_guid(length = 8, exists = () => false) {
1276
+ for (;;) {
1277
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1278
+ if (exists(id))
1279
+ continue;
1280
+ return id;
1281
+ }
1282
+ }
1283
+ $.$mol_guid = $mol_guid;
1284
+ })($ || ($ = {}));
1285
+
1286
+ ;
1287
+ "use strict";
1288
+ var $;
1289
+ (function ($) {
1290
+ /** Special status statuses. */
1003
1291
  let $mol_wire_cursor;
1004
1292
  (function ($mol_wire_cursor) {
1293
+ /** Update required. */
1005
1294
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
1295
+ /** Some of (transitive) pub update required. */
1006
1296
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
1297
+ /** Actual state but may be dropped. */
1007
1298
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
1299
+ /** State will never be changed. */
1008
1300
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
1009
1301
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
1010
1302
  })($ || ($ = {}));
@@ -1013,12 +1305,27 @@ var $;
1013
1305
  "use strict";
1014
1306
  var $;
1015
1307
  (function ($) {
1308
+ /**
1309
+ * Collects subscribers in compact array. 28B
1310
+ */
1016
1311
  class $mol_wire_pub extends Object {
1312
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
1313
+ super();
1314
+ this[Symbol.toStringTag] = id;
1315
+ }
1316
+ [Symbol.toStringTag];
1017
1317
  data = [];
1318
+ // Derived objects should be Arrays.
1018
1319
  static get [Symbol.species]() {
1019
1320
  return Array;
1020
1321
  }
1021
- sub_from = 0;
1322
+ /**
1323
+ * Index of first subscriber.
1324
+ */
1325
+ sub_from = 0; // 4B
1326
+ /**
1327
+ * All current subscribers.
1328
+ */
1022
1329
  get sub_list() {
1023
1330
  const res = [];
1024
1331
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -1026,14 +1333,23 @@ var $;
1026
1333
  }
1027
1334
  return res;
1028
1335
  }
1336
+ /**
1337
+ * Has any subscribers or not.
1338
+ */
1029
1339
  get sub_empty() {
1030
1340
  return this.sub_from === this.data.length;
1031
1341
  }
1342
+ /**
1343
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
1344
+ */
1032
1345
  sub_on(sub, pub_pos) {
1033
1346
  const pos = this.data.length;
1034
1347
  this.data.push(sub, pub_pos);
1035
1348
  return pos;
1036
1349
  }
1350
+ /**
1351
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
1352
+ */
1037
1353
  sub_off(sub_pos) {
1038
1354
  if (!(sub_pos < this.data.length)) {
1039
1355
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -1046,21 +1362,39 @@ var $;
1046
1362
  if (end === this.sub_from)
1047
1363
  this.reap();
1048
1364
  }
1365
+ /**
1366
+ * Called when last sub was unsubscribed.
1367
+ **/
1049
1368
  reap() { }
1369
+ /**
1370
+ * Autowire this publisher with current subscriber.
1371
+ **/
1050
1372
  promote() {
1051
1373
  $mol_wire_auto()?.track_next(this);
1052
1374
  }
1375
+ /**
1376
+ * Enforce actualization. Should not throw errors.
1377
+ */
1053
1378
  fresh() { }
1379
+ /**
1380
+ * Allow to put data to caches in the subtree.
1381
+ */
1054
1382
  complete() { }
1055
1383
  get incompleted() {
1056
1384
  return false;
1057
1385
  }
1386
+ /**
1387
+ * Notify subscribers about self changes.
1388
+ */
1058
1389
  emit(quant = $mol_wire_cursor.stale) {
1059
1390
  for (let i = this.sub_from; i < this.data.length; i += 2) {
1060
1391
  ;
1061
- this.data[i].absorb(quant);
1392
+ this.data[i].absorb(quant, this.data[i + 1]);
1062
1393
  }
1063
1394
  }
1395
+ /**
1396
+ * Moves peer from one position to another. Doesn't clear data at old position!
1397
+ */
1064
1398
  peer_move(from_pos, to_pos) {
1065
1399
  const peer = this.data[from_pos];
1066
1400
  const self_pos = this.data[from_pos + 1];
@@ -1068,6 +1402,9 @@ var $;
1068
1402
  this.data[to_pos + 1] = self_pos;
1069
1403
  peer.peer_repos(self_pos, to_pos);
1070
1404
  }
1405
+ /**
1406
+ * Updates self position in the peer.
1407
+ */
1071
1408
  peer_repos(peer_pos, self_pos) {
1072
1409
  this.data[peer_pos + 1] = self_pos;
1073
1410
  }
@@ -1083,10 +1420,16 @@ var $;
1083
1420
  var $;
1084
1421
  (function ($) {
1085
1422
  $.$mol_wire_auto_sub = null;
1423
+ /**
1424
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
1425
+ */
1086
1426
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
1087
1427
  return $.$mol_wire_auto_sub = next;
1088
1428
  }
1089
1429
  $.$mol_wire_auto = $mol_wire_auto;
1430
+ /**
1431
+ * Affection queue. Used to prevent accidental stack overflow on emit.
1432
+ */
1090
1433
  $.$mol_wire_affected = [];
1091
1434
  })($ || ($ = {}));
1092
1435
 
@@ -1094,9 +1437,16 @@ var $;
1094
1437
  "use strict";
1095
1438
  var $;
1096
1439
  (function ($) {
1440
+ /**
1441
+ * Publisher that can auto collect other publishers. 32B
1442
+ *
1443
+ * P1 P2 P3 P4 S1 S2 S3
1444
+ * ^ ^
1445
+ * pubs_from subs_from
1446
+ */
1097
1447
  class $mol_wire_pub_sub extends $mol_wire_pub {
1098
- pub_from = 0;
1099
- cursor = $mol_wire_cursor.stale;
1448
+ pub_from = 0; // 4B
1449
+ cursor = $mol_wire_cursor.stale; // 4B
1100
1450
  get temp() {
1101
1451
  return false;
1102
1452
  }
@@ -1177,7 +1527,7 @@ var $;
1177
1527
  this.data.length = this.sub_from;
1178
1528
  this.cursor = this.pub_from;
1179
1529
  this.track_cut();
1180
- this.cursor = $mol_wire_cursor.final;
1530
+ this.cursor = $mol_wire_cursor.stale;
1181
1531
  }
1182
1532
  track_cut() {
1183
1533
  if (this.cursor < this.pub_from) {
@@ -1207,17 +1557,34 @@ var $;
1207
1557
  pub?.complete();
1208
1558
  }
1209
1559
  }
1210
- absorb(quant = $mol_wire_cursor.stale) {
1560
+ absorb(quant = $mol_wire_cursor.stale, pos = -1) {
1211
1561
  if (this.cursor === $mol_wire_cursor.final)
1212
1562
  return;
1213
1563
  if (this.cursor >= quant)
1214
1564
  return;
1215
1565
  this.cursor = quant;
1216
1566
  this.emit($mol_wire_cursor.doubt);
1567
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
1568
+ // const pub = this.data[ pos ] as $mol_wire_pub
1569
+ // if( pub instanceof $mol_wire_task ) return
1570
+ // for(
1571
+ // let cursor = this.pub_from;
1572
+ // cursor < this.sub_from;
1573
+ // cursor += 2
1574
+ // ) {
1575
+ // const pub = this.data[ cursor ] as $mol_wire_pub
1576
+ // if( pub instanceof $mol_wire_task ) {
1577
+ // pub.destructor()
1578
+ // }
1579
+ // }
1580
+ // }
1217
1581
  }
1218
1582
  [$mol_dev_format_head]() {
1219
1583
  return $mol_dev_format_native(this);
1220
1584
  }
1585
+ /**
1586
+ * Is subscribed to any publisher or not.
1587
+ */
1221
1588
  get pub_empty() {
1222
1589
  return this.sub_from === this.pub_from;
1223
1590
  }
@@ -1273,6 +1640,13 @@ var $;
1273
1640
  var $;
1274
1641
  (function ($) {
1275
1642
  const wrappers = new WeakMap();
1643
+ /**
1644
+ * Suspendable task with support both sync/async api.
1645
+ *
1646
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
1647
+ * ^ ^ ^
1648
+ * args_from pubs_from subs_from
1649
+ **/
1276
1650
  class $mol_wire_fiber extends $mol_wire_pub_sub {
1277
1651
  task;
1278
1652
  host;
@@ -1293,6 +1667,7 @@ var $;
1293
1667
  });
1294
1668
  }
1295
1669
  static sync() {
1670
+ // Sync whole fiber graph
1296
1671
  while (this.planning.size) {
1297
1672
  for (const fiber of this.planning) {
1298
1673
  this.planning.delete(fiber);
@@ -1303,6 +1678,7 @@ var $;
1303
1678
  fiber.fresh();
1304
1679
  }
1305
1680
  }
1681
+ // Collect garbage
1306
1682
  while (this.reaping.size) {
1307
1683
  const fibers = this.reaping;
1308
1684
  this.reaping = new Set;
@@ -1313,7 +1689,6 @@ var $;
1313
1689
  }
1314
1690
  }
1315
1691
  }
1316
- [Symbol.toStringTag];
1317
1692
  cache = undefined;
1318
1693
  get args() {
1319
1694
  return this.data.slice(0, this.pub_from);
@@ -1329,16 +1704,15 @@ var $;
1329
1704
  return $mol_promise_like(this.cache);
1330
1705
  }
1331
1706
  field() {
1332
- return this.task.name + '<>';
1707
+ return this.task.name + '()';
1333
1708
  }
1334
1709
  constructor(id, task, host, args) {
1335
- super();
1710
+ super(id);
1336
1711
  this.task = task;
1337
1712
  this.host = host;
1338
1713
  if (args)
1339
1714
  this.data.push(...args);
1340
1715
  this.pub_from = this.sub_from = args?.length ?? 0;
1341
- this[Symbol.toStringTag] = id;
1342
1716
  }
1343
1717
  plan() {
1344
1718
  $mol_wire_fiber.planning.add(this);
@@ -1363,12 +1737,10 @@ var $;
1363
1737
  [$mol_wire_cursor.final]: '🔵',
1364
1738
  }[this.cursor] ?? this.cursor.toString();
1365
1739
  return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1366
- ? $mol_dev_format_auto({
1367
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1368
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1369
- })
1370
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1740
+ ? $mol_dev_format_shade(cursor)
1741
+ : $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
1371
1742
  }
1743
+ [$mol_dev_format_body]() { return null; }
1372
1744
  get $() {
1373
1745
  return (this.host ?? this.task)['$'];
1374
1746
  }
@@ -1436,10 +1808,12 @@ var $;
1436
1808
  result = wrappers.get(result);
1437
1809
  }
1438
1810
  else {
1439
- wrappers.set(result, result = Object.assign(result.finally(() => {
1811
+ const put = (v) => {
1440
1812
  if (this.cache === result)
1441
1813
  this.absorb();
1442
- }), { destructor: result.destructor || (() => { }) }));
1814
+ return v;
1815
+ };
1816
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1443
1817
  const error = new Error(`Promise in ${this}`);
1444
1818
  Object.defineProperty(result, 'stack', { get: () => error.stack });
1445
1819
  }
@@ -1456,6 +1830,10 @@ var $;
1456
1830
  this.cursor = $mol_wire_cursor.stale;
1457
1831
  this.fresh();
1458
1832
  }
1833
+ /**
1834
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
1835
+ * Should be called inside SuspenseAPI consumer (ie fiber).
1836
+ */
1459
1837
  sync() {
1460
1838
  if (!$mol_wire_fiber.warm) {
1461
1839
  return this.result();
@@ -1470,6 +1848,10 @@ var $;
1470
1848
  }
1471
1849
  return this.cache;
1472
1850
  }
1851
+ /**
1852
+ * Asynchronous execution.
1853
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
1854
+ */
1473
1855
  async async_raw() {
1474
1856
  while (true) {
1475
1857
  this.fresh();
@@ -1482,6 +1864,7 @@ var $;
1482
1864
  if (!$mol_promise_like(this.cache))
1483
1865
  return this.cache;
1484
1866
  if (this.cursor === $mol_wire_cursor.final) {
1867
+ // never ends on destructed fiber
1485
1868
  await new Promise(() => { });
1486
1869
  }
1487
1870
  }
@@ -1506,9 +1889,19 @@ var $;
1506
1889
  }
1507
1890
  destructor() {
1508
1891
  super.destructor();
1509
- if ($mol_owning_check(this, this.cache)) {
1892
+ $mol_wire_fiber.planning.delete(this);
1893
+ if (!$mol_owning_check(this, this.cache))
1894
+ return;
1895
+ try {
1510
1896
  this.cache.destructor();
1511
1897
  }
1898
+ catch (result) {
1899
+ if ($mol_promise_like(result)) {
1900
+ const error = new Error(`Promise in ${this}.destructor()`);
1901
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1902
+ }
1903
+ $mol_fail_hidden(result);
1904
+ }
1512
1905
  }
1513
1906
  }
1514
1907
  $.$mol_wire_fiber = $mol_wire_fiber;
@@ -1518,61 +1911,51 @@ var $;
1518
1911
  "use strict";
1519
1912
  var $;
1520
1913
  (function ($) {
1521
- function $mol_guid(length = 8, exists = () => false) {
1522
- for (;;) {
1523
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1524
- if (exists(id))
1525
- continue;
1526
- return id;
1527
- }
1528
- }
1529
- $.$mol_guid = $mol_guid;
1530
- })($ || ($ = {}));
1531
-
1532
- ;
1533
- "use strict";
1534
- var $;
1535
- (function ($) {
1536
- $.$mol_key_store = new WeakMap();
1537
1914
  const TypedArray = Object.getPrototypeOf(Uint8Array);
1915
+ /** Returns string key for any value. */
1538
1916
  function $mol_key(value) {
1539
- if (typeof value === 'bigint')
1540
- return value.toString() + 'n';
1541
- if (typeof value === 'symbol')
1542
- return value.description;
1543
- if (!value)
1544
- return JSON.stringify(value);
1545
- if (typeof value !== 'object' && typeof value !== 'function')
1546
- return JSON.stringify(value);
1547
- return JSON.stringify(value, (field, value) => {
1917
+ primitives: {
1548
1918
  if (typeof value === 'bigint')
1549
1919
  return value.toString() + 'n';
1550
1920
  if (typeof value === 'symbol')
1551
- return value.description;
1921
+ return `Symbol(${value.description})`;
1552
1922
  if (!value)
1553
- return value;
1923
+ return JSON.stringify(value); // 0, null, ""
1554
1924
  if (typeof value !== 'object' && typeof value !== 'function')
1555
- return value;
1925
+ return JSON.stringify(value); // boolean, number, string
1926
+ }
1927
+ caching: {
1928
+ let key = $mol_key_store.get(value);
1929
+ if (key)
1930
+ return key;
1931
+ }
1932
+ objects: {
1933
+ if (value instanceof TypedArray) {
1934
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1935
+ }
1556
1936
  if (Array.isArray(value))
1557
- return value;
1558
- const proto = Reflect.getPrototypeOf(value);
1559
- if (!proto)
1560
- return value;
1561
- if (Reflect.getPrototypeOf(proto) === null)
1562
- return value;
1563
- if ('toJSON' in value)
1564
- return value;
1937
+ return `[${value.map(v => $mol_key(v))}]`;
1565
1938
  if (value instanceof RegExp)
1566
1939
  return value.toString();
1567
- if (value instanceof TypedArray)
1568
- return [...value];
1569
- let key = $.$mol_key_store.get(value);
1570
- if (key)
1571
- return key;
1572
- key = $mol_guid();
1573
- $.$mol_key_store.set(value, key);
1940
+ if (value instanceof Date)
1941
+ return `Date(${value.valueOf()})`;
1942
+ }
1943
+ structures: {
1944
+ const proto = Reflect.getPrototypeOf(value);
1945
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
1946
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1947
+ }
1948
+ }
1949
+ handlers: {
1950
+ if ($mol_key_handle in value) {
1951
+ return value[$mol_key_handle]();
1952
+ }
1953
+ }
1954
+ containers: {
1955
+ const key = JSON.stringify('#' + $mol_guid());
1956
+ $mol_key_store.set(value, key);
1574
1957
  return key;
1575
- });
1958
+ }
1576
1959
  }
1577
1960
  $.$mol_key = $mol_key;
1578
1961
  })($ || ($ = {}));
@@ -1623,6 +2006,10 @@ var $;
1623
2006
  var $;
1624
2007
  (function ($) {
1625
2008
  $.$mol_compare_deep_cache = new WeakMap();
2009
+ /**
2010
+ * Deeply compares two values. Returns true if equal.
2011
+ * Define `Symbol.toPrimitive` to customize.
2012
+ */
1626
2013
  function $mol_compare_deep(left, right) {
1627
2014
  if (Object.is(left, right))
1628
2015
  return true;
@@ -1649,7 +2036,7 @@ var $;
1649
2036
  if (left instanceof RegExp)
1650
2037
  return left.source === right.source && left.flags === right.flags;
1651
2038
  if (left instanceof Error)
1652
- return left.message === right.message && left.stack === right.stack;
2039
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1653
2040
  let left_cache = $.$mol_compare_deep_cache.get(left);
1654
2041
  if (left_cache) {
1655
2042
  const right_cache = left_cache.get(right);
@@ -1703,7 +2090,7 @@ var $;
1703
2090
  if (len !== right.byteLength)
1704
2091
  return false;
1705
2092
  if (left instanceof DataView)
1706
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2093
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1707
2094
  for (let i = 0; i < len; ++i) {
1708
2095
  if (left[i] !== right[i])
1709
2096
  return false;
@@ -1762,8 +2149,9 @@ var $;
1762
2149
  "use strict";
1763
2150
  var $;
1764
2151
  (function ($) {
2152
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1765
2153
  function $mol_log3_area_lazy(event) {
1766
- const self = this;
2154
+ const self = this.$;
1767
2155
  const stack = self.$mol_log3_stack;
1768
2156
  const deep = stack.length;
1769
2157
  let logged = false;
@@ -1818,32 +2206,41 @@ var $;
1818
2206
  "use strict";
1819
2207
  var $;
1820
2208
  (function ($) {
2209
+ /** One-shot fiber */
1821
2210
  class $mol_wire_task extends $mol_wire_fiber {
1822
2211
  static getter(task) {
1823
2212
  return function $mol_wire_task_get(host, args) {
1824
2213
  const sub = $mol_wire_auto();
1825
2214
  const existen = sub?.track_next();
2215
+ let cause = '';
1826
2216
  reuse: if (existen) {
1827
2217
  if (!existen.temp)
1828
2218
  break reuse;
1829
- if (existen.host !== host)
2219
+ if (existen.host !== host) {
2220
+ cause = 'host';
1830
2221
  break reuse;
1831
- if (existen.task !== task)
2222
+ }
2223
+ if (existen.task !== task) {
2224
+ cause = 'task';
1832
2225
  break reuse;
1833
- if (!$mol_compare_deep(existen.args, args))
2226
+ }
2227
+ if (!$mol_compare_deep(existen.args, args)) {
2228
+ cause = 'args';
1834
2229
  break reuse;
2230
+ }
1835
2231
  return existen;
1836
2232
  }
1837
2233
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1838
2234
  const next = new $mol_wire_task(key, task, host, args);
2235
+ // Disabled because non-idempotency is required for try-catch
1839
2236
  if (existen?.temp) {
1840
2237
  $$.$mol_log3_warn({
1841
2238
  place: '$mol_wire_task',
1842
- message: `Non idempotency`,
2239
+ message: `Different ${cause} on restart`,
1843
2240
  sub,
1844
- pubs: [...sub?.pub_list ?? [], existen],
2241
+ prev: existen,
1845
2242
  next,
1846
- hint: 'Ignore it',
2243
+ hint: 'Maybe required additional memoization',
1847
2244
  });
1848
2245
  }
1849
2246
  return next;
@@ -1868,7 +2265,7 @@ var $;
1868
2265
  try {
1869
2266
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
1870
2267
  }
1871
- catch {
2268
+ catch { // Promises throw in strict mode
1872
2269
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1873
2270
  }
1874
2271
  }
@@ -1881,6 +2278,10 @@ var $;
1881
2278
  this.emit();
1882
2279
  return next;
1883
2280
  }
2281
+ destructor() {
2282
+ super.destructor();
2283
+ this.cursor = $mol_wire_cursor.final;
2284
+ }
1884
2285
  }
1885
2286
  $.$mol_wire_task = $mol_wire_task;
1886
2287
  })($ || ($ = {}));
@@ -1889,6 +2290,9 @@ var $;
1889
2290
  "use strict";
1890
2291
  var $;
1891
2292
  (function ($) {
2293
+ /**
2294
+ * Decorates method to fiber to ensure it is executed only once inside other fiber.
2295
+ */
1892
2296
  function $mol_wire_method(host, field, descr) {
1893
2297
  if (!descr)
1894
2298
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -1921,20 +2325,65 @@ var $;
1921
2325
  "use strict";
1922
2326
  var $;
1923
2327
  (function ($) {
1924
- const catched = new WeakMap();
2328
+ const catched = new WeakSet();
1925
2329
  function $mol_fail_catch(error) {
1926
2330
  if (typeof error !== 'object')
1927
2331
  return false;
1928
2332
  if ($mol_promise_like(error))
1929
2333
  $mol_fail_hidden(error);
1930
- if (catched.get(error))
2334
+ if (catched.has(error))
1931
2335
  return false;
1932
- catched.set(error, true);
2336
+ catched.add(error);
1933
2337
  return true;
1934
2338
  }
1935
2339
  $.$mol_fail_catch = $mol_fail_catch;
1936
2340
  })($ || ($ = {}));
1937
2341
 
2342
+ ;
2343
+ "use strict";
2344
+ var $;
2345
+ (function ($) {
2346
+ function $mol_try(handler) {
2347
+ try {
2348
+ return handler();
2349
+ }
2350
+ catch (error) {
2351
+ console.error(error);
2352
+ return error;
2353
+ }
2354
+ }
2355
+ $.$mol_try = $mol_try;
2356
+ })($ || ($ = {}));
2357
+
2358
+ ;
2359
+ "use strict";
2360
+ var $;
2361
+ (function ($) {
2362
+ let error;
2363
+ let result;
2364
+ let handler;
2365
+ /// Debugger will stop at exceptions but exception will be returned normally
2366
+ function $mol_try_web(handler2) {
2367
+ handler = handler2;
2368
+ error = undefined;
2369
+ result = undefined;
2370
+ self.dispatchEvent(new Event('$mol_try'));
2371
+ const error2 = error;
2372
+ const result2 = result;
2373
+ error = undefined;
2374
+ result = undefined;
2375
+ return error2 || result2;
2376
+ }
2377
+ $.$mol_try_web = $mol_try_web;
2378
+ $.$mol_try = $mol_try_web;
2379
+ self.addEventListener('$mol_try', (event) => {
2380
+ result = handler();
2381
+ }, true);
2382
+ self.addEventListener('error', (event) => {
2383
+ error = event.error;
2384
+ }, true);
2385
+ })($ || ($ = {}));
2386
+
1938
2387
  ;
1939
2388
  "use strict";
1940
2389
  var $;
@@ -1944,7 +2393,7 @@ var $;
1944
2393
  return false;
1945
2394
  if (!$mol_fail_catch(error))
1946
2395
  return false;
1947
- console.error(error);
2396
+ $mol_try(() => { $mol_fail_hidden(error); });
1948
2397
  return true;
1949
2398
  }
1950
2399
  $.$mol_fail_log = $mol_fail_log;
@@ -1954,20 +2403,21 @@ var $;
1954
2403
  "use strict";
1955
2404
  var $;
1956
2405
  (function ($) {
2406
+ /** Long-living fiber. */
1957
2407
  class $mol_wire_atom extends $mol_wire_fiber {
1958
2408
  static solo(host, task) {
1959
- const field = task.name + '<>';
2409
+ const field = task.name + '()';
1960
2410
  const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1961
2411
  if (existen)
1962
2412
  return existen;
1963
2413
  const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1964
- const key = prefix + ('.' + field);
2414
+ const key = prefix + ('.' + task.name + '<>');
1965
2415
  const fiber = new $mol_wire_atom(key, task, host, []);
1966
2416
  (host ?? task)[field] = fiber;
1967
2417
  return fiber;
1968
2418
  }
1969
2419
  static plex(host, task, key) {
1970
- const field = task.name + '<>';
2420
+ const field = task.name + '()';
1971
2421
  let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1972
2422
  const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1973
2423
  const key_str = $mol_key(key);
@@ -2004,7 +2454,17 @@ var $;
2004
2454
  }
2005
2455
  $mol_wire_atom.watching.add(this);
2006
2456
  }
2457
+ /**
2458
+ * Update atom value through another temp fiber.
2459
+ */
2007
2460
  resync(args) {
2461
+ // enforce pulling tasks abort
2462
+ for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
2463
+ const pub = this.data[cursor];
2464
+ if (pub && pub instanceof $mol_wire_task) {
2465
+ pub.destructor();
2466
+ }
2467
+ }
2008
2468
  return this.put(this.task.call(this.host, ...args));
2009
2469
  }
2010
2470
  once() {
@@ -2031,8 +2491,15 @@ var $;
2031
2491
  (this.host ?? this.task)[this.field()] = null;
2032
2492
  }
2033
2493
  else {
2034
- ;
2035
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
2494
+ const key = $mol_key(this.args[0]);
2495
+ const map = (this.host ?? this.task)[this.field()];
2496
+ if (!map.has(key))
2497
+ this.$.$mol_log3_warn({
2498
+ place: this,
2499
+ message: 'Absent key on destruction',
2500
+ hint: 'Check for $mol_key(key) is not changed',
2501
+ });
2502
+ map.delete(key);
2036
2503
  }
2037
2504
  }
2038
2505
  put(next) {
@@ -2052,7 +2519,7 @@ var $;
2052
2519
  try {
2053
2520
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
2054
2521
  }
2055
- catch {
2522
+ catch { // Promises throw in strict mode
2056
2523
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2057
2524
  }
2058
2525
  }
@@ -2080,6 +2547,7 @@ var $;
2080
2547
  "use strict";
2081
2548
  var $;
2082
2549
  (function ($) {
2550
+ /** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
2083
2551
  function $mol_wire_solo(host, field, descr) {
2084
2552
  if (!descr)
2085
2553
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -2118,6 +2586,7 @@ var $;
2118
2586
  "use strict";
2119
2587
  var $;
2120
2588
  (function ($) {
2589
+ /** Reactive memoizing multiplexed property decorator. */
2121
2590
  function $mol_wire_plex(host, field, descr) {
2122
2591
  if (!descr)
2123
2592
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -2156,7 +2625,25 @@ var $;
2156
2625
  "use strict";
2157
2626
  var $;
2158
2627
  (function ($) {
2628
+ /**
2629
+ * Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
2630
+ * @example
2631
+ * '@' $mol_mem
2632
+ * name(next?: string) {
2633
+ * return next ?? 'default'
2634
+ * }
2635
+ * @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
2636
+ */
2159
2637
  $.$mol_mem = $mol_wire_solo;
2638
+ /**
2639
+ * Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
2640
+ * @example
2641
+ * '@' $mol_mem_key
2642
+ * name(id: number, next?: string) {
2643
+ * return next ?? 'default'
2644
+ * }
2645
+ * @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
2646
+ */
2160
2647
  $.$mol_mem_key = $mol_wire_plex;
2161
2648
  })($ || ($ = {}));
2162
2649
 
@@ -2173,18 +2660,46 @@ var $;
2173
2660
  factories.set(val, make);
2174
2661
  return make;
2175
2662
  }
2663
+ const getters = new WeakMap();
2664
+ function get_prop(host, field) {
2665
+ let props = getters.get(host);
2666
+ let get_val = props?.[field];
2667
+ if (get_val)
2668
+ return get_val;
2669
+ get_val = (next) => {
2670
+ if (next !== undefined)
2671
+ host[field] = next;
2672
+ return host[field];
2673
+ };
2674
+ Object.defineProperty(get_val, 'name', { value: field });
2675
+ if (!props) {
2676
+ props = {};
2677
+ getters.set(host, props);
2678
+ }
2679
+ props[field] = get_val;
2680
+ return get_val;
2681
+ }
2682
+ /**
2683
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
2684
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
2685
+ */
2176
2686
  function $mol_wire_sync(obj) {
2177
2687
  return new Proxy(obj, {
2178
2688
  get(obj, field) {
2179
2689
  let val = obj[field];
2690
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
2180
2691
  if (typeof val !== 'function')
2181
- return val;
2182
- const temp = $mol_wire_task.getter(val);
2692
+ return temp(obj, []).sync();
2183
2693
  return function $mol_wire_sync(...args) {
2184
2694
  const fiber = temp(obj, args);
2185
2695
  return fiber.sync();
2186
2696
  };
2187
2697
  },
2698
+ set(obj, field, next) {
2699
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
2700
+ temp(obj, [next]).sync();
2701
+ return true;
2702
+ },
2188
2703
  construct(obj, args) {
2189
2704
  const temp = $mol_wire_task.getter(factory(obj));
2190
2705
  return temp(obj, args).sync();
@@ -2269,6 +2784,12 @@ var $;
2269
2784
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2270
2785
  };
2271
2786
  $.$mol_jsx_frag = '';
2787
+ /**
2788
+ * JSX adapter that makes DOM tree.
2789
+ * Generates global unique ids for every DOM-element by components tree with ids.
2790
+ * Ensures all local ids are unique.
2791
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
2792
+ */
2272
2793
  function $mol_jsx(Elem, props, ...childNodes) {
2273
2794
  const id = props && props.id || '';
2274
2795
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -2401,6 +2922,51 @@ var $;
2401
2922
  "use strict";
2402
2923
  var $;
2403
2924
  (function ($) {
2925
+ class $mol_storage extends $mol_object2 {
2926
+ /** Is storage a long term. */
2927
+ static persisted(next) {
2928
+ return false;
2929
+ }
2930
+ /** Total storage quota in bytes. */
2931
+ static total() {
2932
+ return 0;
2933
+ }
2934
+ /** Total storage usage in bytes. */
2935
+ static used() {
2936
+ return 0;
2937
+ }
2938
+ /** Minimum available free space in bytes. */
2939
+ static free() {
2940
+ return this.total() - this.used();
2941
+ }
2942
+ /** Fulfillness of storage. */
2943
+ static portion() {
2944
+ const total = this.total();
2945
+ if (!total)
2946
+ return 1;
2947
+ return this.used() / total;
2948
+ }
2949
+ /**
2950
+ * Fulfillness logarithmic level.
2951
+ * `0` - empty
2952
+ * `1` - half free
2953
+ * `2` - quart free
2954
+ * `Infinity` - fulfilled
2955
+ */
2956
+ static level() {
2957
+ return Math.floor(-Math.log2(1 - this.portion()));
2958
+ }
2959
+ }
2960
+ $.$mol_storage = $mol_storage;
2961
+ })($ || ($ = {}));
2962
+
2963
+ ;
2964
+ "use strict";
2965
+ var $;
2966
+ (function ($) {
2967
+ /**
2968
+ * Disable reaping of current subscriber
2969
+ */
2404
2970
  function $mol_wire_solid() {
2405
2971
  let current = $mol_wire_auto();
2406
2972
  if (current.temp)
@@ -2426,6 +2992,7 @@ var $;
2426
2992
  "use strict";
2427
2993
  var $;
2428
2994
  (function ($) {
2995
+ /** Run code without state changes */
2429
2996
  function $mol_wire_probe(task, def) {
2430
2997
  const warm = $mol_wire_fiber.warm;
2431
2998
  try {
@@ -2453,7 +3020,73 @@ var $;
2453
3020
  "use strict";
2454
3021
  var $;
2455
3022
  (function ($) {
2456
- class $mol_storage extends $mol_object2 {
3023
+ function $mol_wait_user_async() {
3024
+ return new Promise(done => $mol_dom.addEventListener('click', function onclick() {
3025
+ $mol_dom.removeEventListener('click', onclick);
3026
+ done(null);
3027
+ }));
3028
+ }
3029
+ $.$mol_wait_user_async = $mol_wait_user_async;
3030
+ function $mol_wait_user() {
3031
+ return this.$mol_wire_sync(this).$mol_wait_user_async();
3032
+ }
3033
+ $.$mol_wait_user = $mol_wait_user;
3034
+ })($ || ($ = {}));
3035
+
3036
+ ;
3037
+ "use strict";
3038
+ var $;
3039
+ (function ($) {
3040
+ class $mol_after_timeout extends $mol_object2 {
3041
+ delay;
3042
+ task;
3043
+ id;
3044
+ constructor(delay, task) {
3045
+ super();
3046
+ this.delay = delay;
3047
+ this.task = task;
3048
+ this.id = setTimeout(task, delay);
3049
+ }
3050
+ destructor() {
3051
+ clearTimeout(this.id);
3052
+ }
3053
+ }
3054
+ $.$mol_after_timeout = $mol_after_timeout;
3055
+ })($ || ($ = {}));
3056
+
3057
+ ;
3058
+ "use strict";
3059
+ var $;
3060
+ (function ($) {
3061
+ /** State of time moment */
3062
+ class $mol_state_time extends $mol_object {
3063
+ static task(precision, reset) {
3064
+ if (precision) {
3065
+ return new $mol_after_timeout(precision, () => this.task(precision, null));
3066
+ }
3067
+ else {
3068
+ return new $mol_after_frame(() => this.task(precision, null));
3069
+ }
3070
+ }
3071
+ static now(precision) {
3072
+ this.task(precision);
3073
+ return Date.now();
3074
+ }
3075
+ }
3076
+ __decorate([
3077
+ $mol_mem_key
3078
+ ], $mol_state_time, "task", null);
3079
+ __decorate([
3080
+ $mol_mem_key
3081
+ ], $mol_state_time, "now", null);
3082
+ $.$mol_state_time = $mol_state_time;
3083
+ })($ || ($ = {}));
3084
+
3085
+ ;
3086
+ "use strict";
3087
+ var $;
3088
+ (function ($) {
3089
+ class $mol_storage_web extends $mol_storage {
2457
3090
  static native() {
2458
3091
  return this.$.$mol_dom_context.navigator.storage ?? {
2459
3092
  persisted: async () => false,
@@ -2468,7 +3101,9 @@ var $;
2468
3101
  return Boolean(next);
2469
3102
  const native = this.native();
2470
3103
  if (next && !$mol_mem_cached(() => this.persisted())) {
2471
- native.persist().then(actual => {
3104
+ this.$.$mol_wait_user_async()
3105
+ .then(() => native.persist())
3106
+ .then(actual => {
2472
3107
  setTimeout(() => this.persisted(actual, 'cache'), 5000);
2473
3108
  if (actual)
2474
3109
  this.$.$mol_log3_done({ place: `$mol_storage`, message: `Persist: Yes` });
@@ -2479,19 +3114,40 @@ var $;
2479
3114
  return next ?? $mol_wire_sync(native).persisted();
2480
3115
  }
2481
3116
  static estimate() {
3117
+ $mol_state_time.now(1000);
2482
3118
  return $mol_wire_sync(this.native() ?? {}).estimate();
2483
3119
  }
3120
+ static total() {
3121
+ return this.estimate().quota ?? 0;
3122
+ }
3123
+ static used() {
3124
+ return this.estimate().usage ?? 0;
3125
+ }
3126
+ static free() {
3127
+ const { usage = 0, quota = 0 } = this.estimate();
3128
+ return quota - usage;
3129
+ }
3130
+ static portion() {
3131
+ const { usage = 0, quota = 0 } = this.estimate();
3132
+ if (!quota)
3133
+ return 1;
3134
+ return usage / quota;
3135
+ }
2484
3136
  static dir() {
2485
3137
  return $mol_wire_sync(this.native()).getDirectory();
2486
3138
  }
2487
3139
  }
2488
3140
  __decorate([
2489
3141
  $mol_mem
2490
- ], $mol_storage, "native", null);
3142
+ ], $mol_storage_web, "native", null);
2491
3143
  __decorate([
2492
3144
  $mol_mem
2493
- ], $mol_storage, "persisted", null);
2494
- $.$mol_storage = $mol_storage;
3145
+ ], $mol_storage_web, "persisted", null);
3146
+ __decorate([
3147
+ $mol_mem
3148
+ ], $mol_storage_web, "estimate", null);
3149
+ $.$mol_storage_web = $mol_storage_web;
3150
+ $.$mol_storage = $.$mol_storage_web;
2495
3151
  })($ || ($ = {}));
2496
3152
 
2497
3153
  ;
@@ -2563,6 +3219,7 @@ var $;
2563
3219
 
2564
3220
  ;
2565
3221
  "use strict";
3222
+ /** @jsx $mol_jsx */
2566
3223
  var $;
2567
3224
  (function ($) {
2568
3225
  async function $hyoo_sync_peer(path, next) {
@@ -2632,13 +3289,13 @@ var $;
2632
3289
  };
2633
3290
  }
2634
3291
  static get method() {
2635
- return (obj, name, descr) => {
3292
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
2636
3293
  descr.value = this.func(descr.value);
2637
3294
  return descr;
2638
3295
  };
2639
3296
  }
2640
3297
  static get field() {
2641
- return (obj, name, descr) => {
3298
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
2642
3299
  descr.get = descr.set = this.func(descr.get);
2643
3300
  return descr;
2644
3301
  };
@@ -2655,10 +3312,10 @@ var $;
2655
3312
  static wrap(task) {
2656
3313
  const store = new WeakMap();
2657
3314
  const fun = function (next) {
2658
- if (next === undefined && store.has(this))
2659
- return store.get(this);
3315
+ if (next === undefined && store.has(this ?? fun))
3316
+ return store.get(this ?? fun);
2660
3317
  const val = task.call(this, next) ?? next;
2661
- store.set(this, val);
3318
+ store.set(this ?? fun, val);
2662
3319
  return val;
2663
3320
  };
2664
3321
  Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
@@ -2672,10 +3329,12 @@ var $;
2672
3329
  "use strict";
2673
3330
  var $;
2674
3331
  (function ($) {
3332
+ /** Internal int31 representation of current time. */
2675
3333
  function $hyoo_crowd_time_now() {
2676
3334
  return Math.floor(Date.now() / 100) - 1767e7;
2677
3335
  }
2678
3336
  $.$hyoo_crowd_time_now = $hyoo_crowd_time_now;
3337
+ /** Returns unix timestamp for internal time representation. */
2679
3338
  function $hyoo_crowd_time_stamp(time) {
2680
3339
  return 1767e9 + time * 100;
2681
3340
  }
@@ -2686,8 +3345,10 @@ var $;
2686
3345
  "use strict";
2687
3346
  var $;
2688
3347
  (function ($) {
3348
+ /** Vector clock. Stores real timestamps. */
2689
3349
  class $hyoo_crowd_clock extends Map {
2690
3350
  static begin = -1 * 2 ** 30;
3351
+ /** Maximum time for all peers. */
2691
3352
  last_time = $hyoo_crowd_clock.begin;
2692
3353
  constructor(entries) {
2693
3354
  super(entries);
@@ -2697,16 +3358,19 @@ var $;
2697
3358
  this.see_time(time);
2698
3359
  }
2699
3360
  }
3361
+ /** Synchronize this clock with another. */
2700
3362
  sync(right) {
2701
3363
  for (const [peer, time] of right) {
2702
3364
  this.see_peer(peer, time);
2703
3365
  }
2704
3366
  }
3367
+ /** Increase `last` to latest. */
2705
3368
  see_time(time) {
2706
3369
  if (time < this.last_time)
2707
3370
  return;
2708
3371
  this.last_time = time;
2709
3372
  }
3373
+ /** Add new `time` for `peer` and increase `last`. */
2710
3374
  see_peer(peer, time) {
2711
3375
  if (!this.fresh(peer, time))
2712
3376
  return;
@@ -2721,9 +3385,11 @@ var $;
2721
3385
  }), bin.getInt32(cursor + 8 + 4 * group, true));
2722
3386
  }
2723
3387
  }
3388
+ /** Checks if time from future. */
2724
3389
  fresh(peer, time) {
2725
3390
  return time > this.time(peer);
2726
3391
  }
3392
+ /** Checks if this clock from future of another. */
2727
3393
  ahead(clock) {
2728
3394
  for (const [peer, time] of this) {
2729
3395
  if (clock.fresh(peer, time))
@@ -2740,6 +3406,7 @@ var $;
2740
3406
  last_stamp() {
2741
3407
  return $hyoo_crowd_time_stamp(this.last_time);
2742
3408
  }
3409
+ /** Gererates new time for peer that greater then other seen. */
2743
3410
  tick(peer) {
2744
3411
  let time = this.now();
2745
3412
  if (time <= this.last_time) {
@@ -2796,6 +3463,7 @@ var $;
2796
3463
  "use strict";
2797
3464
  var $;
2798
3465
  (function ($) {
3466
+ /** Stateless non-unique adapter to CROWD Tree for given Head. */
2799
3467
  class $hyoo_crowd_node extends $mol_object2 {
2800
3468
  land;
2801
3469
  head;
@@ -2818,16 +3486,20 @@ var $;
2818
3486
  world() {
2819
3487
  return this.land.world();
2820
3488
  }
3489
+ /** Returns another representation of this node. */
2821
3490
  as(Node) {
2822
3491
  return this.world()?.Fund(Node).Item(`${this.land.id()}!${this.head}`) ?? new Node(this.land, this.head);
2823
3492
  }
3493
+ /** Ordered inner alive Units. */
2824
3494
  units() {
2825
3495
  return this.land.unit_alives(this.head);
2826
3496
  }
3497
+ /** Ordered inner alive Node. */
2827
3498
  nodes(Node) {
2828
3499
  const fund = this.world()?.Fund(Node);
2829
3500
  return this.units().map(unit => fund?.Item(`${this.land.id()}!${unit.self}`) ?? new Node(this.land, unit.self));
2830
3501
  }
3502
+ /** Returns true when node value is never changed. */
2831
3503
  virgin() {
2832
3504
  return this.land.unit_list(this.head).length === 0;
2833
3505
  }
@@ -2855,6 +3527,7 @@ var $;
2855
3527
  var $;
2856
3528
  (function ($) {
2857
3529
  class $hyoo_crowd_reg extends $hyoo_crowd_node {
3530
+ /** Atomic value. */
2858
3531
  value(next) {
2859
3532
  const unit = this.units().at(-1);
2860
3533
  if (next === undefined)
@@ -2864,12 +3537,15 @@ var $;
2864
3537
  this.land.put(this.head, unit?.self ?? this.land.id_new(), '0_0', next);
2865
3538
  return next;
2866
3539
  }
3540
+ /** Atomic string. */
2867
3541
  str(next) {
2868
3542
  return String(this.value(next) ?? '');
2869
3543
  }
3544
+ /** Atomic number. */
2870
3545
  numb(next) {
2871
3546
  return Number(this.value(next));
2872
3547
  }
3548
+ /** Atomic boolean. */
2873
3549
  bool(next) {
2874
3550
  return Boolean(this.value(next));
2875
3551
  }
@@ -2894,6 +3570,7 @@ var $;
2894
3570
  var $;
2895
3571
  (function ($) {
2896
3572
  class $hyoo_crowd_struct extends $hyoo_crowd_node {
3573
+ /** Returns inner node for key. */
2897
3574
  sub(key, Node) {
2898
3575
  const head = $mol_int62_hash_string(key + '\n' + this.head);
2899
3576
  return this.world()?.Fund(Node).Item(`${this.land.id()}!${head}`) ?? new Node(this.land, head);
@@ -2910,6 +3587,11 @@ var $;
2910
3587
  "use strict";
2911
3588
  var $;
2912
3589
  (function ($) {
3590
+ /**
3591
+ * Returns closure that returns constant value.
3592
+ * @example
3593
+ * const rnd = $mol_const( Math.random() )
3594
+ */
2913
3595
  function $mol_const(value) {
2914
3596
  const getter = (() => value);
2915
3597
  getter['()'] = value;
@@ -2924,6 +3606,7 @@ var $;
2924
3606
  "use strict";
2925
3607
  var $;
2926
3608
  (function ($) {
3609
+ /** Conflict-free Reinterpretable Ordered Washed Data Tree */
2927
3610
  class $hyoo_crowd_land extends $mol_object {
2928
3611
  id() {
2929
3612
  return $mol_int62_to_string($mol_int62_random());
@@ -2957,21 +3640,26 @@ var $;
2957
3640
  }
2958
3641
  pub = new $mol_wire_pub;
2959
3642
  _clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
3643
+ /** unit by head + self */
2960
3644
  _unit_all = new Map();
2961
3645
  unit(head, self) {
2962
3646
  return this._unit_all.get(`${head}!${self}`);
2963
3647
  }
3648
+ /** units by head */
2964
3649
  _unit_lists = new Map();
3650
+ /** Units by Head without tombstones */
2965
3651
  _unit_alives = new Map();
2966
3652
  size() {
2967
3653
  return this._unit_all.size;
2968
3654
  }
3655
+ /** Returns list of all Units for Node. */
2969
3656
  unit_list(head) {
2970
3657
  let kids = this._unit_lists.get(head);
2971
3658
  if (!kids)
2972
3659
  this._unit_lists.set(head, kids = Object.assign([], { dirty: false }));
2973
3660
  return kids;
2974
3661
  }
3662
+ /** Returns list of alive Units for Node. */
2975
3663
  unit_alives(head) {
2976
3664
  this.pub.promote();
2977
3665
  let kids = this._unit_alives.get(head);
@@ -2984,23 +3672,27 @@ var $;
2984
3672
  }
2985
3673
  return kids;
2986
3674
  }
3675
+ /** Node by id and type. */
2987
3676
  node(head, Node) {
2988
3677
  return new Node(this, head);
2989
3678
  }
3679
+ /** Root Node. */
2990
3680
  chief = this.node('0_0', $hyoo_crowd_struct);
3681
+ /** Generates new identifier. */
2991
3682
  id_new() {
2992
3683
  for (let i = 0; i < 1000; ++i) {
2993
3684
  const id = $mol_int62_to_string($mol_int62_random());
2994
3685
  if (id === '0_0')
2995
- continue;
3686
+ continue; // zero reserved for empty
2996
3687
  if (id === this.id())
2997
- continue;
3688
+ continue; // reserved for rights
2998
3689
  if (this._unit_lists.has(id))
2999
- continue;
3690
+ continue; // skip already exists
3000
3691
  return id;
3001
3692
  }
3002
3693
  throw new Error(`Can't generate ID after 1000 times`);
3003
3694
  }
3695
+ /** Makes independent clone with defined peer. */
3004
3696
  fork(auth) {
3005
3697
  const fork = $hyoo_crowd_land.make({
3006
3698
  id: $mol_const(this.id()),
@@ -3008,6 +3700,7 @@ var $;
3008
3700
  });
3009
3701
  return fork.apply(this.delta());
3010
3702
  }
3703
+ /** Makes Delta bettween Clock and now. */
3011
3704
  delta(clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]) {
3012
3705
  this.pub.promote();
3013
3706
  const delta = [];
@@ -3068,6 +3761,7 @@ var $;
3068
3761
  kids.dirty = false;
3069
3762
  return kids;
3070
3763
  }
3764
+ /** Applies Delta to current state. */
3071
3765
  apply(delta) {
3072
3766
  for (const next of delta) {
3073
3767
  this._clocks[next.group()].see_peer(next.auth, next.time);
@@ -3091,6 +3785,7 @@ var $;
3091
3785
  return this;
3092
3786
  }
3093
3787
  _joined = false;
3788
+ /** Register public key of current peer **/
3094
3789
  join() {
3095
3790
  if (this._joined)
3096
3791
  return;
@@ -3109,6 +3804,7 @@ var $;
3109
3804
  this._joined = true;
3110
3805
  this.pub.emit();
3111
3806
  }
3807
+ /** Unregister public key of current peer **/
3112
3808
  leave() {
3113
3809
  const auth = this.peer();
3114
3810
  if (!auth)
@@ -3137,6 +3833,7 @@ var $;
3137
3833
  level_base(next) {
3138
3834
  this.level('0_0', next);
3139
3835
  }
3836
+ /** Access level for peer. Use empty string for current peer. **/
3140
3837
  level(peer, next) {
3141
3838
  if (next)
3142
3839
  this.join();
@@ -3167,6 +3864,7 @@ var $;
3167
3864
  this.pub.promote();
3168
3865
  return this._unit_all.size > 0;
3169
3866
  }
3867
+ /** All peers who have special rights to write o land. */
3170
3868
  peers() {
3171
3869
  this.pub.promote();
3172
3870
  const lords = [];
@@ -3179,6 +3877,7 @@ var $;
3179
3877
  }
3180
3878
  return lords;
3181
3879
  }
3880
+ /** All peers who joined to land except king. */
3182
3881
  residents() {
3183
3882
  this.pub.promote();
3184
3883
  const lords = [];
@@ -3191,6 +3890,7 @@ var $;
3191
3890
  }
3192
3891
  return lords;
3193
3892
  }
3893
+ /** All peers who have alive data inside land. */
3194
3894
  authors() {
3195
3895
  this.pub.promote();
3196
3896
  const authors = new Set();
@@ -3222,6 +3922,7 @@ var $;
3222
3922
  selection(peer) {
3223
3923
  return this.world().land_sync(peer).chief.sub('$hyoo_crowd_land..selection', $hyoo_crowd_reg);
3224
3924
  }
3925
+ /** Places data to tree. */
3225
3926
  put(head, self, prev, data) {
3226
3927
  this.join();
3227
3928
  const old_id = `${head}!${self}`;
@@ -3239,18 +3940,25 @@ var $;
3239
3940
  const unit_new = new $hyoo_crowd_unit(this.id(), auth, head, self, next, prev, time, data, null);
3240
3941
  this._unit_all.set(old_id, unit_new);
3241
3942
  unit_list.splice(seat, 0, unit_new);
3943
+ // unit_list.dirty = true
3242
3944
  this._unit_alives.set(head, undefined);
3945
+ // this.apply([ unit_new ])
3243
3946
  this.pub.emit();
3244
3947
  return unit_new;
3245
3948
  }
3949
+ /** Marks unit as deleted and wipes its data. */
3246
3950
  wipe(unit) {
3247
3951
  if (unit.data === null)
3248
3952
  return unit;
3953
+ // for( const kid of this.unit_list( unit.self ) ) {
3954
+ // this.wipe( kid )
3955
+ // }
3249
3956
  const unit_list = this.unit_list(unit.head);
3250
3957
  const seat = unit_list.indexOf(unit);
3251
3958
  const prev = seat > 0 ? unit_list[seat - 1].self : seat < 0 ? unit.prev : '0_0';
3252
3959
  return this.put(unit.head, unit.self, prev, null);
3253
3960
  }
3961
+ /** Moves Unit after another Prev inside some Head. */
3254
3962
  move(unit, head, prev) {
3255
3963
  const unit_list = this.unit_list(unit.head);
3256
3964
  const seat = unit_list.indexOf(unit);
@@ -3260,6 +3968,7 @@ var $;
3260
3968
  this.put(next.head, next.self, unit_list[unit_list.indexOf(next) - 2]?.self ?? '0_0', next.data);
3261
3969
  this.put(head, unit.self, prev, unit.data);
3262
3970
  }
3971
+ /** Moves Unit at given Seat inside given Head. */
3263
3972
  insert(unit, head, seat) {
3264
3973
  const list = this.unit_list(head);
3265
3974
  const prev = seat ? list[seat - 1].self : '0_0';
@@ -3279,6 +3988,10 @@ var $;
3279
3988
  "use strict";
3280
3989
  var $;
3281
3990
  (function ($) {
3991
+ /**
3992
+ * Decorates method to fiber to ensure it is executed only once inside other fiber from [mol_wire](../wire/README.md)
3993
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
3994
+ */
3282
3995
  $.$mol_action = $mol_wire_method;
3283
3996
  })($ || ($ = {}));
3284
3997
 
@@ -3286,6 +3999,7 @@ var $;
3286
3999
  "use strict";
3287
4000
  var $;
3288
4001
  (function ($) {
4002
+ /** Registry of nodes as domain entities. */
3289
4003
  class $hyoo_crowd_fund extends $mol_object {
3290
4004
  world;
3291
4005
  node_class;
@@ -3318,7 +4032,11 @@ var $;
3318
4032
  "use strict";
3319
4033
  var $;
3320
4034
  (function ($) {
4035
+ /** @deprecated */
3321
4036
  $.$mol_dict_key = $mol_key;
4037
+ /**
4038
+ * Dictionary with extended keys support
4039
+ */
3322
4040
  class $mol_dict extends Map {
3323
4041
  get(key) {
3324
4042
  return super.get($mol_key(key));
@@ -3365,6 +4083,7 @@ var $;
3365
4083
  if (iteration.done)
3366
4084
  return iteration;
3367
4085
  iteration.value = [JSON.parse(iteration.value[0]), iteration.value[1]];
4086
+ // iteration.value[0] = JSON.parse( iteration.value[0] as any as string )
3368
4087
  return iteration;
3369
4088
  }
3370
4089
  };
@@ -3421,6 +4140,7 @@ var $;
3421
4140
  _knights = new $mol_dict();
3422
4141
  _signs = new WeakMap();
3423
4142
  async grab(law = [''], mod = [], add = []) {
4143
+ // if( !law.length && !mod.length && !add.length ) $mol_fail( new Error( 'Grabbing dead land' ) )
3424
4144
  const knight = await $hyoo_crowd_peer.generate();
3425
4145
  this._knights.set(knight.id, knight);
3426
4146
  const land_inner = this.land(knight.id);
@@ -3501,7 +4221,7 @@ var $;
3501
4221
  }
3502
4222
  async audit_delta(land, delta) {
3503
4223
  const all = new Map();
3504
- const desync = 60 * 60 * 10;
4224
+ const desync = 60 * 60 * 10; // 1 hour
3505
4225
  const deadline = land.clock_data.now() + desync;
3506
4226
  const get_unit = (id) => {
3507
4227
  return all.get(id) ?? land._unit_all.get(id);
@@ -3618,27 +4338,6 @@ var $;
3618
4338
  $.$mol_promise = $mol_promise;
3619
4339
  })($ || ($ = {}));
3620
4340
 
3621
- ;
3622
- "use strict";
3623
- var $;
3624
- (function ($) {
3625
- class $mol_after_timeout extends $mol_object2 {
3626
- delay;
3627
- task;
3628
- id;
3629
- constructor(delay, task) {
3630
- super();
3631
- this.delay = delay;
3632
- this.task = task;
3633
- this.id = setTimeout(task, delay);
3634
- }
3635
- destructor() {
3636
- clearTimeout(this.id);
3637
- }
3638
- }
3639
- $.$mol_after_timeout = $mol_after_timeout;
3640
- })($ || ($ = {}));
3641
-
3642
4341
  ;
3643
4342
  "use strict";
3644
4343
  var $;
@@ -3661,6 +4360,7 @@ var $;
3661
4360
  "use strict";
3662
4361
  var $;
3663
4362
  (function ($) {
4363
+ /** Starts subtasks concurrently instead of serial. */
3664
4364
  function $mol_wire_race(...tasks) {
3665
4365
  const results = tasks.map(task => {
3666
4366
  try {
@@ -3687,7 +4387,7 @@ var $;
3687
4387
  (function ($) {
3688
4388
  $.$hyoo_sync_masters = [
3689
4389
  `sync.hyoo.ru`,
3690
- `sync-pmzz.onrender.com`,
4390
+ //`sync-pmzz.onrender.com`,
3691
4391
  ];
3692
4392
  })($ || ($ = {}));
3693
4393
 
@@ -3695,6 +4395,7 @@ var $;
3695
4395
  "use strict";
3696
4396
  var $;
3697
4397
  (function ($) {
4398
+ /** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
3698
4399
  function $mol_wire_async(obj) {
3699
4400
  let fiber;
3700
4401
  const temp = $mol_wire_task.getter(obj);
@@ -3838,6 +4539,12 @@ var $;
3838
4539
  $mol_wire_sync(this).db_land_save(land, units);
3839
4540
  for (const unit of units)
3840
4541
  this.db_unit_persisted.add(unit);
4542
+ // this.$.$mol_log3_rise({
4543
+ // place: this,
4544
+ // land: land.id(),
4545
+ // message: 'Base Save',
4546
+ // units: this.log_pack( units ),
4547
+ // })
3841
4548
  }
3842
4549
  db_land_init(land) {
3843
4550
  try {
@@ -3857,6 +4564,12 @@ var $;
3857
4564
  this.db_unit_persisted.add(unit);
3858
4565
  units.sort($hyoo_crowd_unit_compare);
3859
4566
  land.apply(units);
4567
+ // this.$.$mol_log3_rise({
4568
+ // place: this,
4569
+ // land: land.id(),
4570
+ // message: 'Base Load',
4571
+ // units: this.log_pack( units ),
4572
+ // })
3860
4573
  }
3861
4574
  async db_land_load(land) {
3862
4575
  return [];
@@ -3889,6 +4602,11 @@ var $;
3889
4602
  }
3890
4603
  line_land_clocks({ line, land }, next) {
3891
4604
  $mol_wire_solid();
4605
+ // try{
4606
+ // this.master()
4607
+ // } catch( error ) {
4608
+ // $mol_fail_log( error )
4609
+ // }
3892
4610
  return next;
3893
4611
  }
3894
4612
  line_sync(line) {
@@ -3903,13 +4621,29 @@ var $;
3903
4621
  if (!units.length)
3904
4622
  return;
3905
4623
  this.line_send_units(line, units);
4624
+ /*this.$.$mol_log3_rise({
4625
+ place: this,
4626
+ land: land.id(),
4627
+ message: 'Sync Sent',
4628
+ line: $mol_key( line ),
4629
+ units: this.log_pack( units ),
4630
+ })*/
3906
4631
  for (const unit of units) {
3907
4632
  clocks[unit.group()].see_peer(unit.auth, unit.time);
3908
4633
  }
3909
4634
  }
3910
4635
  line_land_init({ line, land }) {
3911
4636
  this.db_land_init(land);
4637
+ // const lands = this.line_land_clocks({ line, land })
4638
+ // if( lands ) return
3912
4639
  this.line_send_clocks(line, land);
4640
+ // this.$.$mol_log3_come({
4641
+ // place: this,
4642
+ // land: land.id(),
4643
+ // message: 'Sync Open',
4644
+ // line: $mol_key( line ),
4645
+ // clocks: land._clocks,
4646
+ // })
3913
4647
  }
3914
4648
  line_land_neck({ line, land }, next = []) {
3915
4649
  return next;
@@ -3953,6 +4687,13 @@ var $;
3953
4687
  }
3954
4688
  else {
3955
4689
  this.line_lands(line, [...lands, land]);
4690
+ // this.$.$mol_log3_done({
4691
+ // place: this,
4692
+ // land: land.id(),
4693
+ // message: 'Sync Pair',
4694
+ // line: $mol_key( line ),
4695
+ // clocks,
4696
+ // })
3956
4697
  }
3957
4698
  return;
3958
4699
  }
@@ -4057,6 +4798,7 @@ var $;
4057
4798
  "use strict";
4058
4799
  var $;
4059
4800
  (function ($) {
4801
+ /** Converts IDBResult to Promise */
4060
4802
  function $mol_db_response(request) {
4061
4803
  return new Promise((done, fail) => {
4062
4804
  request.onerror = () => fail(new Error(request.error.message));
@@ -4070,6 +4812,7 @@ var $;
4070
4812
  "use strict";
4071
4813
  var $;
4072
4814
  (function ($) {
4815
+ /** IndexedDB ObjectStore wrapper. */
4073
4816
  class $mol_db_store {
4074
4817
  native;
4075
4818
  constructor(native) {
@@ -4084,6 +4827,7 @@ var $;
4084
4827
  get incremental() {
4085
4828
  return this.native.autoIncrement;
4086
4829
  }
4830
+ /** Returns dictionary of all existen Indexes. */
4087
4831
  get indexes() {
4088
4832
  return new Proxy({}, {
4089
4833
  ownKeys: () => [...this.native.indexNames],
@@ -4091,9 +4835,11 @@ var $;
4091
4835
  get: (_, name) => new $mol_db_index(this.native.index(name))
4092
4836
  });
4093
4837
  }
4838
+ /** Creates new Index */
4094
4839
  index_make(name, path = [], unique = false, multiEntry = false) {
4095
4840
  return this.native.createIndex(name, path, { multiEntry, unique });
4096
4841
  }
4842
+ /** Drops existen Index */
4097
4843
  index_drop(name) {
4098
4844
  this.native.deleteIndex(name);
4099
4845
  return this;
@@ -4104,21 +4850,27 @@ var $;
4104
4850
  get db() {
4105
4851
  return this.transaction.db;
4106
4852
  }
4853
+ /** Deletes all stored Documents */
4107
4854
  clear() {
4108
4855
  return $mol_db_response(this.native.clear());
4109
4856
  }
4857
+ /** Counts Documents by primary key(s) */
4110
4858
  count(keys) {
4111
4859
  return $mol_db_response(this.native.count(keys));
4112
4860
  }
4861
+ /** Stores single Document by primary key. */
4113
4862
  put(doc, key) {
4114
4863
  return $mol_db_response(this.native.put(doc, key));
4115
4864
  }
4865
+ /** Returns Document by primary key. */
4116
4866
  get(key) {
4117
4867
  return $mol_db_response(this.native.get(key));
4118
4868
  }
4869
+ /** Selects Documents by primary keys. */
4119
4870
  select(key, count) {
4120
4871
  return $mol_db_response(this.native.getAll(key, count));
4121
4872
  }
4873
+ /** Deletes Documents by primary key(s). */
4122
4874
  drop(keys) {
4123
4875
  return $mol_db_response(this.native.delete(keys));
4124
4876
  }
@@ -4133,6 +4885,7 @@ var $;
4133
4885
  "use strict";
4134
4886
  var $;
4135
4887
  (function ($) {
4888
+ /** IndexedDB Index wrapper. */
4136
4889
  class $mol_db_index {
4137
4890
  native;
4138
4891
  constructor(native) {
@@ -4159,12 +4912,15 @@ var $;
4159
4912
  get db() {
4160
4913
  return this.store.db;
4161
4914
  }
4915
+ /** Counts Documents by key(s) */
4162
4916
  count(keys) {
4163
4917
  return $mol_db_response(this.native.count(keys));
4164
4918
  }
4919
+ /** Returns Document by primary key. */
4165
4920
  get(key) {
4166
4921
  return $mol_db_response(this.native.get(key));
4167
4922
  }
4923
+ /** Selects Documents by primary keys. */
4168
4924
  select(key, count) {
4169
4925
  return $mol_db_response(this.native.getAll(key, count));
4170
4926
  }
@@ -4179,6 +4935,14 @@ var $;
4179
4935
  "use strict";
4180
4936
  var $;
4181
4937
  (function ($) {
4938
+ /**
4939
+ * Creates new or returns existen database with automatic schema migration.
4940
+ * Schema version is based on migrations count.
4941
+ * Migrations code mustn't be changed after deploy.
4942
+ * Only adding migrations at the end is allowed.
4943
+ * Only new migrations will be applyed to existen DB.
4944
+ * Schema changes allowed only through migratios.
4945
+ */
4182
4946
  async function $mol_db(name, ...migrations) {
4183
4947
  const request = this.$mol_dom_context.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
4184
4948
  request.onupgradeneeded = event => {
@@ -4200,32 +4964,46 @@ var $;
4200
4964
  "use strict";
4201
4965
  var $;
4202
4966
  (function ($) {
4967
+ /** IndexedDB instance wrapper. */
4203
4968
  class $mol_db_database {
4204
4969
  native;
4205
4970
  constructor(native) {
4206
4971
  this.native = native;
4207
4972
  }
4973
+ /** Returns database name. */
4208
4974
  get name() {
4209
4975
  return this.native.name;
4210
4976
  }
4977
+ /** Returns database schema version. */
4211
4978
  get version() {
4212
4979
  return this.native.version;
4213
4980
  }
4981
+ /** Returns all stores names. */
4214
4982
  get stores() {
4215
4983
  return [...this.native.objectStoreNames];
4216
4984
  }
4985
+ /** Create read-only transaction. */
4217
4986
  read(...names) {
4218
4987
  return new $mol_db_transaction(this.native.transaction(names, 'readonly', { durability: 'relaxed' })).stores;
4219
4988
  }
4989
+ /** Create read/write transaction. */
4220
4990
  change(...names) {
4221
4991
  return new $mol_db_transaction(this.native.transaction(names, 'readwrite', { durability: 'relaxed' }));
4222
4992
  }
4993
+ /**
4994
+ * Deletes database.
4995
+ * DB can be deleted only after end of all transactions.
4996
+ */
4223
4997
  kill() {
4224
4998
  this.native.close();
4225
4999
  const request = $mol_dom_context.indexedDB.deleteDatabase(this.name);
4226
5000
  request.onblocked = console.warn;
4227
5001
  return $mol_db_response(request);
4228
5002
  }
5003
+ /**
5004
+ * Closes DB connection.
5005
+ * Connection really be closed only after end of all transactions.
5006
+ */
4229
5007
  destructor() {
4230
5008
  this.native.close();
4231
5009
  }
@@ -4237,11 +5015,13 @@ var $;
4237
5015
  "use strict";
4238
5016
  var $;
4239
5017
  (function ($) {
5018
+ /** IndexedDB Transaction wrapper. */
4240
5019
  class $mol_db_transaction {
4241
5020
  native;
4242
5021
  constructor(native) {
4243
5022
  this.native = native;
4244
5023
  }
5024
+ /** Returns dictionary of all existen Stores. */
4245
5025
  get stores() {
4246
5026
  return new Proxy({}, {
4247
5027
  ownKeys: () => [...this.native.objectStoreNames],
@@ -4251,18 +5031,22 @@ var $;
4251
5031
  : undefined,
4252
5032
  });
4253
5033
  }
5034
+ /** Creates new Store */
4254
5035
  store_make(name) {
4255
5036
  return this.native.db.createObjectStore(name, { autoIncrement: true });
4256
5037
  }
5038
+ /** Drops existen Store */
4257
5039
  store_drop(name) {
4258
5040
  this.native.db.deleteObjectStore(name);
4259
5041
  return this;
4260
5042
  }
5043
+ /** Instant abort transaction. Any errors aborts transactions automatically. */
4261
5044
  abort() {
4262
5045
  if (this.native.error)
4263
5046
  return;
4264
5047
  this.native.abort();
4265
5048
  }
5049
+ /** Instant commits transaction. Without errors commit proceed automatically later. */
4266
5050
  commit() {
4267
5051
  this.native.commit?.();
4268
5052
  return new Promise((done, fail) => {
@@ -4383,6 +5167,29 @@ var $;
4383
5167
  };
4384
5168
  });
4385
5169
  }
5170
+ // @ $mol_mem
5171
+ // server() {
5172
+ // return new $mol_dom_listener(
5173
+ // $mol_dom_context,
5174
+ // 'message',
5175
+ // $mol_wire_async( ( event: MessageEvent<[ string, $mol_int62_string, readonly $hyoo_crowd_unit[] ]> )=> {
5176
+ // if( !event ) return
5177
+ // if( !Array.isArray( event.data ) ) return
5178
+ // switch( event.data[0] ) {
5179
+ // case 'hyoo_sync_units': {
5180
+ // const [, land_id, units ] = event.data
5181
+ // const line = event.source! as Window
5182
+ // const land = this.land( land_id )
5183
+ // land.apply( units )
5184
+ // this.slaves([ ... new Set([ ... this.slaves(), line ]) ])
5185
+ // this.line_lands( line, [ ... new Set([ ... this.line_lands( line ), land ]) ] )
5186
+ // this.line_land_clocks({ line, land })
5187
+ // line.postMessage([ 'hyoo_sync_units', land.id(), [] ])
5188
+ // }
5189
+ // }
5190
+ // } )
5191
+ // )
5192
+ // }
4386
5193
  line_send_clocks(line, land) {
4387
5194
  if (line instanceof WebSocket) {
4388
5195
  line.send(land.clocks_bin);