mol_tree2 1.0.1395 → 1.0.1397

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
@@ -35,6 +35,11 @@ var $;
35
35
  var $;
36
36
  (function ($) {
37
37
  const instances = new WeakSet();
38
+ /**
39
+ * Proxy that delegates all to lazy returned target.
40
+ *
41
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
42
+ */
38
43
  function $mol_delegate(proto, target) {
39
44
  const proxy = new Proxy(proto, {
40
45
  get: (_, field) => {
@@ -138,7 +143,7 @@ var $;
138
143
  var $;
139
144
  (function ($) {
140
145
  function $mol_fail_hidden(error) {
141
- throw error;
146
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
142
147
  }
143
148
  $.$mol_fail_hidden = $mol_fail_hidden;
144
149
  })($ || ($ = {}));
@@ -230,6 +235,9 @@ var $;
230
235
  [Symbol.dispose]() {
231
236
  this.destructor();
232
237
  }
238
+ //[ Symbol.toPrimitive ]( hint: string ) {
239
+ // return hint === 'number' ? this.valueOf() : this.toString()
240
+ //}
233
241
  toString() {
234
242
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
235
243
  }
@@ -241,6 +249,7 @@ var $;
241
249
  "use strict";
242
250
  var $;
243
251
  (function ($) {
252
+ /** Position in any resource. */
244
253
  class $mol_span extends $mol_object2 {
245
254
  uri;
246
255
  source;
@@ -256,13 +265,17 @@ var $;
256
265
  this.length = length;
257
266
  this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
258
267
  }
268
+ /** Span for begin of unknown resource */
259
269
  static unknown = $mol_span.begin('?');
270
+ /** Makes new span for begin of resource. */
260
271
  static begin(uri, source = '') {
261
272
  return new $mol_span(uri, source, 1, 1, 0);
262
273
  }
274
+ /** Makes new span for end of resource. */
263
275
  static end(uri, source) {
264
276
  return new $mol_span(uri, source, 1, source.length + 1, 0);
265
277
  }
278
+ /** Makes new span for entire resource. */
266
279
  static entire(uri, source) {
267
280
  return new $mol_span(uri, source, 1, 1, source.length);
268
281
  }
@@ -277,15 +290,19 @@ var $;
277
290
  length: this.length
278
291
  };
279
292
  }
293
+ /** Makes new error for this span. */
280
294
  error(message, Class = Error) {
281
295
  return new Class(`${message} (${this})`);
282
296
  }
297
+ /** Makes new span for same uri. */
283
298
  span(row, col, length) {
284
299
  return new $mol_span(this.uri, this.source, row, col, length);
285
300
  }
301
+ /** Makes new span after end of this. */
286
302
  after(length = 0) {
287
303
  return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
288
304
  }
305
+ /** Makes new span between begin and end. */
289
306
  slice(begin, end = -1) {
290
307
  let len = this.length;
291
308
  if (begin < 0)
@@ -308,6 +325,7 @@ var $;
308
325
  "use strict";
309
326
  var $;
310
327
  (function ($) {
328
+ /** Syntax error with cordinates and source line snippet. */
311
329
  class $mol_error_syntax extends SyntaxError {
312
330
  reason;
313
331
  line;
@@ -326,6 +344,7 @@ var $;
326
344
  "use strict";
327
345
  var $;
328
346
  (function ($) {
347
+ /** Parses tree format from string. */
329
348
  function $mol_tree2_from_string(str, uri = '?') {
330
349
  const span = $mol_span.entire(uri, str);
331
350
  var root = $mol_tree2.list([], span);
@@ -335,6 +354,7 @@ var $;
335
354
  var indent = 0;
336
355
  var line_start = pos;
337
356
  row++;
357
+ // read indent
338
358
  while (str.length > pos && str[pos] == '\t') {
339
359
  indent++;
340
360
  pos++;
@@ -343,8 +363,10 @@ var $;
343
363
  min_indent = indent;
344
364
  }
345
365
  indent -= min_indent;
366
+ // invalid tab size
346
367
  if (indent < 0 || indent >= stack.length) {
347
368
  const sp = span.span(row, 1, pos - line_start);
369
+ // skip error line
348
370
  while (str.length > pos && str[pos] != '\n') {
349
371
  pos++;
350
372
  }
@@ -359,7 +381,9 @@ var $;
359
381
  }
360
382
  stack.length = indent + 1;
361
383
  var parent = stack[indent];
384
+ // parse types
362
385
  while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
386
+ // type can not contain space and tab
363
387
  var error_start = pos;
364
388
  while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
365
389
  pos++;
@@ -371,6 +395,7 @@ var $;
371
395
  const sp = span.span(row, error_start - line_start + 1, pos - error_start);
372
396
  this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
373
397
  }
398
+ // read type
374
399
  var type_start = pos;
375
400
  while (str.length > pos &&
376
401
  str[pos] != '\\' &&
@@ -385,10 +410,12 @@ var $;
385
410
  parent_kids.push(next);
386
411
  parent = next;
387
412
  }
413
+ // read one space if exists
388
414
  if (str.length > pos && str[pos] == ' ') {
389
415
  pos++;
390
416
  }
391
417
  }
418
+ // read data
392
419
  if (str.length > pos && str[pos] == '\\') {
393
420
  var data_start = pos;
394
421
  while (str.length > pos && str[pos] != '\n') {
@@ -399,6 +426,7 @@ var $;
399
426
  parent_kids.push(next);
400
427
  parent = next;
401
428
  }
429
+ // now must be end of text
402
430
  if (str.length === pos && stack.length > 0) {
403
431
  const sp = span.span(row, pos - line_start + 1, 1);
404
432
  this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
@@ -415,6 +443,7 @@ var $;
415
443
  "use strict";
416
444
  var $;
417
445
  (function ($) {
446
+ /** Serializes tree to string in tree format. */
418
447
  function $mol_tree2_to_string(tree) {
419
448
  let output = [];
420
449
  function dump(tree, prefix = '') {
@@ -458,12 +487,25 @@ var $;
458
487
  "use strict";
459
488
  var $;
460
489
  (function ($) {
490
+ /**
491
+ * Abstract Syntax Tree with human readable serialization.
492
+ * Avoid direct instantiation. Use static factories instead.
493
+ * @see https://github.com/nin-jin/tree.d
494
+ */
461
495
  class $mol_tree2 extends Object {
462
496
  type;
463
497
  value;
464
498
  kids;
465
499
  span;
466
- constructor(type, value, kids, span) {
500
+ constructor(
501
+ /** Type of structural node, `value` should be empty */
502
+ type,
503
+ /** Content of data node, `type` should be empty */
504
+ value,
505
+ /** Child nodes */
506
+ kids,
507
+ /** Position in most far source resource */
508
+ span) {
467
509
  super();
468
510
  this.type = type;
469
511
  this.value = value;
@@ -471,12 +513,15 @@ var $;
471
513
  this.span = span;
472
514
  this[Symbol.toStringTag] = type || '\\' + value;
473
515
  }
516
+ /** Makes collection node. */
474
517
  static list(kids, span = $mol_span.unknown) {
475
518
  return new $mol_tree2('', '', kids, span);
476
519
  }
520
+ /** Makes new derived collection node. */
477
521
  list(kids) {
478
522
  return $mol_tree2.list(kids, this.span);
479
523
  }
524
+ /** Makes data node for any string. */
480
525
  static data(value, kids = [], span = $mol_span.unknown) {
481
526
  const chunks = value.split('\n');
482
527
  if (chunks.length > 1) {
@@ -490,21 +535,26 @@ var $;
490
535
  }
491
536
  return new $mol_tree2('', value, kids, span);
492
537
  }
538
+ /** Makes new derived data node. */
493
539
  data(value, kids = []) {
494
540
  return $mol_tree2.data(value, kids, this.span);
495
541
  }
542
+ /** Makes struct node. */
496
543
  static struct(type, kids = [], span = $mol_span.unknown) {
497
544
  if (/[ \n\t\\]/.test(type)) {
498
545
  $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
499
546
  }
500
547
  return new $mol_tree2(type, '', kids, span);
501
548
  }
549
+ /** Makes new derived structural node. */
502
550
  struct(type, kids = []) {
503
551
  return $mol_tree2.struct(type, kids, this.span);
504
552
  }
553
+ /** Makes new derived node with different kids id defined. */
505
554
  clone(kids, span = this.span) {
506
555
  return new $mol_tree2(this.type, this.value, kids, span);
507
556
  }
557
+ /** Returns multiline text content. */
508
558
  text() {
509
559
  var values = [];
510
560
  for (var kid of this.kids) {
@@ -514,15 +564,20 @@ var $;
514
564
  }
515
565
  return this.value + values.join('\n');
516
566
  }
567
+ /** Parses tree format. */
568
+ /** @deprecated Use $mol_tree2_from_string */
517
569
  static fromString(str, uri = 'unknown') {
518
570
  return $$.$mol_tree2_from_string(str, uri);
519
571
  }
572
+ /** Serializes to tree format. */
520
573
  toString() {
521
574
  return $$.$mol_tree2_to_string(this);
522
575
  }
576
+ /** Makes new tree with node overrided by path. */
523
577
  insert(value, ...path) {
524
578
  return this.update($mol_maybe(value), ...path)[0];
525
579
  }
580
+ /** Makes new tree with node overrided by path. */
526
581
  update(value, ...path) {
527
582
  if (path.length === 0)
528
583
  return value;
@@ -555,6 +610,7 @@ var $;
555
610
  return [this.clone(kids)];
556
611
  }
557
612
  }
613
+ /** Query nodes by path. */
558
614
  select(...path) {
559
615
  let next = [this];
560
616
  for (const type of path) {
@@ -581,6 +637,7 @@ var $;
581
637
  }
582
638
  return this.list(next);
583
639
  }
640
+ /** Filter kids by path or value. */
584
641
  filter(path, value) {
585
642
  const sub = this.kids.filter(item => {
586
643
  var found = item.select(...path);
@@ -608,9 +665,11 @@ var $;
608
665
  $mol_fail_hidden(error);
609
666
  }
610
667
  }
668
+ /** Transform tree through context with transformers */
611
669
  hack(belt, context = {}) {
612
670
  return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
613
671
  }
672
+ /** Makes Error with node coordinates. */
614
673
  error(message, Class = Error) {
615
674
  return this.span.error(`${message}\n${this.clone([])}`, Class);
616
675
  }
@@ -907,14 +966,18 @@ var $;
907
966
  ];
908
967
  },
909
968
  '': (input, belt) => {
969
+ // string
910
970
  if (!input.type)
911
971
  return [
912
972
  input.data(JSON.stringify(input.text())),
913
973
  ];
974
+ // variable
914
975
  if (/^[\w$#][\w0-9$]*$/i.test(input.type))
915
976
  return [
916
977
  input.data(input.type),
978
+ // ... input.hack( context ),
917
979
  ];
980
+ // number
918
981
  if ($mol_tree2_js_is_number(input.type))
919
982
  return [
920
983
  input.data(input.type)
@@ -1239,6 +1302,7 @@ var $;
1239
1302
  "use strict";
1240
1303
  var $;
1241
1304
  (function ($) {
1305
+ /** Makes JSON from json.tree. */
1242
1306
  function $mol_tree2_to_json(tree) {
1243
1307
  if (!tree.type) {
1244
1308
  if (tree.kids.every(kid => !kid.type))
@@ -1609,7 +1673,7 @@ var $;
1609
1673
  "use strict";
1610
1674
  var $;
1611
1675
  (function ($) {
1612
- const mod = require('module');
1676
+ const mod = require /****/('module');
1613
1677
  const internals = mod.builtinModules;
1614
1678
  function $node_internal_check(name) {
1615
1679
  if (name.startsWith('node:'))
@@ -1623,8 +1687,8 @@ var $;
1623
1687
  "use strict";
1624
1688
  var $;
1625
1689
  (function ($) {
1626
- const path = require('path');
1627
- const mod = require('module');
1690
+ const path = require /****/('path');
1691
+ const mod = require /****/('module');
1628
1692
  const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
1629
1693
  function $node_autoinstall(name) {
1630
1694
  try {
@@ -1795,6 +1859,12 @@ var $;
1795
1859
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
1796
1860
  };
1797
1861
  $.$mol_jsx_frag = '';
1862
+ /**
1863
+ * JSX adapter that makes DOM tree.
1864
+ * Generates global unique ids for every DOM-element by components tree with ids.
1865
+ * Ensures all local ids are unique.
1866
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
1867
+ */
1798
1868
  function $mol_jsx(Elem, props, ...childNodes) {
1799
1869
  const id = props && props.id || '';
1800
1870
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -1905,6 +1975,8 @@ var $;
1905
1975
 
1906
1976
  ;
1907
1977
  "use strict";
1978
+ /** @jsx $mol_jsx */
1979
+ /** @jsxFrag $mol_jsx_frag */
1908
1980
  var $;
1909
1981
  (function ($) {
1910
1982
  $mol_test({
@@ -2010,6 +2082,7 @@ var $;
2010
2082
  "use strict";
2011
2083
  var $;
2012
2084
  (function ($) {
2085
+ /** Generates unique identifier. */
2013
2086
  function $mol_guid(length = 8, exists = () => false) {
2014
2087
  for (;;) {
2015
2088
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -2025,6 +2098,7 @@ var $;
2025
2098
  "use strict";
2026
2099
  var $;
2027
2100
  (function ($) {
2101
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
2028
2102
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2029
2103
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
2030
2104
  if (typeof item !== 'function') {
@@ -2073,6 +2147,7 @@ var $;
2073
2147
  }
2074
2148
  $.$mol_range2 = $mol_range2;
2075
2149
  class $mol_range2_array extends Array {
2150
+ // Lazy
2076
2151
  concat(...tail) {
2077
2152
  if (tail.length === 0)
2078
2153
  return this;
@@ -2084,6 +2159,7 @@ var $;
2084
2159
  }
2085
2160
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2086
2161
  }
2162
+ // Lazy
2087
2163
  filter(check, context) {
2088
2164
  const filtered = [];
2089
2165
  let cursor = -1;
@@ -2096,13 +2172,16 @@ var $;
2096
2172
  return filtered[index];
2097
2173
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2098
2174
  }
2175
+ // Diligent
2099
2176
  forEach(proceed, context) {
2100
2177
  for (let [key, value] of this.entries())
2101
2178
  proceed.call(context, value, key, this);
2102
2179
  }
2180
+ // Lazy
2103
2181
  map(proceed, context) {
2104
2182
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2105
2183
  }
2184
+ // Diligent
2106
2185
  reduce(merge, result) {
2107
2186
  let index = 0;
2108
2187
  if (arguments.length === 1) {
@@ -2113,12 +2192,15 @@ var $;
2113
2192
  }
2114
2193
  return result;
2115
2194
  }
2195
+ // Lazy
2116
2196
  toReversed() {
2117
2197
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2118
2198
  }
2199
+ // Lazy
2119
2200
  slice(from = 0, to = this.length) {
2120
2201
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2121
2202
  }
2203
+ // Lazy
2122
2204
  some(check, context) {
2123
2205
  for (let index = 0; index < this.length; ++index) {
2124
2206
  if (check.call(context, this[index], index, this))
@@ -2314,6 +2396,10 @@ var $;
2314
2396
  var $;
2315
2397
  (function ($) {
2316
2398
  $.$mol_compare_deep_cache = new WeakMap();
2399
+ /**
2400
+ * Deeply compares two values. Returns true if equal.
2401
+ * Define `Symbol.toPrimitive` to customize.
2402
+ */
2317
2403
  function $mol_compare_deep(left, right) {
2318
2404
  if (Object.is(left, right))
2319
2405
  return true;
@@ -2451,6 +2537,7 @@ var $;
2451
2537
 
2452
2538
  ;
2453
2539
  "use strict";
2540
+ /** @jsx $mol_jsx */
2454
2541
  var $;
2455
2542
  (function ($) {
2456
2543
  $mol_test({
@@ -2512,6 +2599,7 @@ var $;
2512
2599
  const obj3_copy = { test: 3, obj2: obj2_copy };
2513
2600
  obj1.obj3 = obj3;
2514
2601
  obj1_copy.obj3 = obj3_copy;
2602
+ // warmup cache
2515
2603
  $mol_assert_not($mol_compare_deep(obj1, {}));
2516
2604
  $mol_assert_not($mol_compare_deep(obj2, {}));
2517
2605
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -2581,6 +2669,7 @@ var $;
2581
2669
  "use strict";
2582
2670
  var $;
2583
2671
  (function ($) {
2672
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
2584
2673
  $['devtoolsFormatters'] ||= [];
2585
2674
  function $mol_dev_format_register(config) {
2586
2675
  $['devtoolsFormatters'].push(config);
@@ -2632,6 +2721,7 @@ var $;
2632
2721
  return false;
2633
2722
  if (!val)
2634
2723
  return false;
2724
+ // if( Error.isError( val ) ) true
2635
2725
  if (val[$.$mol_dev_format_body])
2636
2726
  return true;
2637
2727
  return false;
@@ -2649,12 +2739,16 @@ var $;
2649
2739
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
2650
2740
  }
2651
2741
  }
2742
+ // if( Error.isError( val ) ) {
2743
+ // return $mol_dev_format_native( val )
2744
+ // }
2652
2745
  return null;
2653
2746
  },
2654
2747
  });
2655
2748
  function $mol_dev_format_native(obj) {
2656
2749
  if (typeof obj === 'undefined')
2657
2750
  return $.$mol_dev_format_shade('undefined');
2751
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
2658
2752
  return [
2659
2753
  'object',
2660
2754
  {
@@ -2712,6 +2806,9 @@ var $;
2712
2806
  'margin-left': '13px'
2713
2807
  });
2714
2808
  class Stack extends Array {
2809
+ // [ Symbol.toPrimitive ]() {
2810
+ // return this.toString()
2811
+ // }
2715
2812
  toString() {
2716
2813
  return this.join('\n');
2717
2814
  }
@@ -2734,6 +2831,7 @@ var $;
2734
2831
  this.method = call.getMethodName() ?? '';
2735
2832
  if (this.method === this.function)
2736
2833
  this.method = '';
2834
+ // const func = c.getFunction()
2737
2835
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
2738
2836
  this.eval = call.getEvalOrigin() ?? '';
2739
2837
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -2780,18 +2878,34 @@ var $;
2780
2878
  "use strict";
2781
2879
  var $;
2782
2880
  (function ($) {
2881
+ /**
2882
+ * Argument must be Truthy
2883
+ * @deprecated use $mol_assert_equal instead
2884
+ */
2783
2885
  function $mol_assert_ok(value) {
2784
2886
  if (value)
2785
2887
  return;
2786
2888
  $mol_fail(new Error(`${value} ≠ true`));
2787
2889
  }
2788
2890
  $.$mol_assert_ok = $mol_assert_ok;
2891
+ /**
2892
+ * Argument must be Falsy
2893
+ * @deprecated use $mol_assert_equal instead
2894
+ */
2789
2895
  function $mol_assert_not(value) {
2790
2896
  if (!value)
2791
2897
  return;
2792
2898
  $mol_fail(new Error(`${value} ≠ false`));
2793
2899
  }
2794
2900
  $.$mol_assert_not = $mol_assert_not;
2901
+ /**
2902
+ * Handler must throw an error.
2903
+ * @example
2904
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
2905
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
2906
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
2907
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
2908
+ */
2795
2909
  function $mol_assert_fail(handler, ErrorRight) {
2796
2910
  const fail = $.$mol_fail;
2797
2911
  try {
@@ -2814,10 +2928,18 @@ var $;
2814
2928
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
2815
2929
  }
2816
2930
  $.$mol_assert_fail = $mol_assert_fail;
2931
+ /** @deprecated Use $mol_assert_equal */
2817
2932
  function $mol_assert_like(...args) {
2818
2933
  $mol_assert_equal(...args);
2819
2934
  }
2820
2935
  $.$mol_assert_like = $mol_assert_like;
2936
+ /**
2937
+ * All arguments must not be structural equal to each other.
2938
+ * @example
2939
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
2940
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
2941
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
2942
+ */
2821
2943
  function $mol_assert_unique(...args) {
2822
2944
  for (let i = 0; i < args.length; ++i) {
2823
2945
  for (let j = 0; j < args.length; ++j) {
@@ -2830,6 +2952,13 @@ var $;
2830
2952
  }
2831
2953
  }
2832
2954
  $.$mol_assert_unique = $mol_assert_unique;
2955
+ /**
2956
+ * All arguments must be structural equal each other.
2957
+ * @example
2958
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
2959
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
2960
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
2961
+ */
2833
2962
  function $mol_assert_equal(...args) {
2834
2963
  for (let i = 1; i < args.length; ++i) {
2835
2964
  if ($mol_compare_deep(args[0], args[i]))
@@ -2882,6 +3011,7 @@ var $;
2882
3011
  "use strict";
2883
3012
  var $;
2884
3013
  (function ($) {
3014
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
2885
3015
  function $mol_log3_area_lazy(event) {
2886
3016
  const self = this.$;
2887
3017
  const stack = self.$mol_log3_stack;
@@ -2906,6 +3036,7 @@ var $;
2906
3036
  "use strict";
2907
3037
  var $;
2908
3038
  (function ($) {
3039
+ /** Module for working with terminal. Text coloring when output in terminal */
2909
3040
  class $mol_term_color {
2910
3041
  static reset = this.ansi(0, 0);
2911
3042
  static bold = this.ansi(1, 22);
@@ -3029,6 +3160,12 @@ var $;
3029
3160
  'return result without errors'() {
3030
3161
  $mol_assert_equal($mol_try(() => false), false);
3031
3162
  },
3163
+ //'return error if thrown'() {
3164
+ //
3165
+ // const error = new Error( '$mol_try test error' )
3166
+ // $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
3167
+ //
3168
+ //} ,
3032
3169
  });
3033
3170
  })($ || ($ = {}));
3034
3171
 
@@ -3152,6 +3289,7 @@ var $;
3152
3289
  ])
3153
3290
  ].map(frame_normalize).join('\n')
3154
3291
  });
3292
+ // в nodejs, что б не дублировалось cause в консоли
3155
3293
  Object.defineProperty(this, 'cause', {
3156
3294
  get: () => cause
3157
3295
  });
@@ -3271,11 +3409,16 @@ var $;
3271
3409
  "use strict";
3272
3410
  var $;
3273
3411
  (function ($) {
3412
+ /** Special status statuses. */
3274
3413
  let $mol_wire_cursor;
3275
3414
  (function ($mol_wire_cursor) {
3415
+ /** Update required. */
3276
3416
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
3417
+ /** Some of (transitive) pub update required. */
3277
3418
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
3419
+ /** Actual state but may be dropped. */
3278
3420
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
3421
+ /** State will never be changed. */
3279
3422
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
3280
3423
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
3281
3424
  })($ || ($ = {}));
@@ -3284,6 +3427,9 @@ var $;
3284
3427
  "use strict";
3285
3428
  var $;
3286
3429
  (function ($) {
3430
+ /**
3431
+ * Collects subscribers in compact array. 28B
3432
+ */
3287
3433
  class $mol_wire_pub extends Object {
3288
3434
  constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
3289
3435
  super();
@@ -3291,10 +3437,17 @@ var $;
3291
3437
  }
3292
3438
  [Symbol.toStringTag];
3293
3439
  data = [];
3440
+ // Derived objects should be Arrays.
3294
3441
  static get [Symbol.species]() {
3295
3442
  return Array;
3296
3443
  }
3297
- sub_from = 0;
3444
+ /**
3445
+ * Index of first subscriber.
3446
+ */
3447
+ sub_from = 0; // 4B
3448
+ /**
3449
+ * All current subscribers.
3450
+ */
3298
3451
  get sub_list() {
3299
3452
  const res = [];
3300
3453
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -3302,14 +3455,23 @@ var $;
3302
3455
  }
3303
3456
  return res;
3304
3457
  }
3458
+ /**
3459
+ * Has any subscribers or not.
3460
+ */
3305
3461
  get sub_empty() {
3306
3462
  return this.sub_from === this.data.length;
3307
3463
  }
3464
+ /**
3465
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
3466
+ */
3308
3467
  sub_on(sub, pub_pos) {
3309
3468
  const pos = this.data.length;
3310
3469
  this.data.push(sub, pub_pos);
3311
3470
  return pos;
3312
3471
  }
3472
+ /**
3473
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
3474
+ */
3313
3475
  sub_off(sub_pos) {
3314
3476
  if (!(sub_pos < this.data.length)) {
3315
3477
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -3322,21 +3484,39 @@ var $;
3322
3484
  if (end === this.sub_from)
3323
3485
  this.reap();
3324
3486
  }
3487
+ /**
3488
+ * Called when last sub was unsubscribed.
3489
+ **/
3325
3490
  reap() { }
3491
+ /**
3492
+ * Autowire this publisher with current subscriber.
3493
+ **/
3326
3494
  promote() {
3327
3495
  $mol_wire_auto()?.track_next(this);
3328
3496
  }
3497
+ /**
3498
+ * Enforce actualization. Should not throw errors.
3499
+ */
3329
3500
  fresh() { }
3501
+ /**
3502
+ * Allow to put data to caches in the subtree.
3503
+ */
3330
3504
  complete() { }
3331
3505
  get incompleted() {
3332
3506
  return false;
3333
3507
  }
3508
+ /**
3509
+ * Notify subscribers about self changes.
3510
+ */
3334
3511
  emit(quant = $mol_wire_cursor.stale) {
3335
3512
  for (let i = this.sub_from; i < this.data.length; i += 2) {
3336
3513
  ;
3337
3514
  this.data[i].absorb(quant, this.data[i + 1]);
3338
3515
  }
3339
3516
  }
3517
+ /**
3518
+ * Moves peer from one position to another. Doesn't clear data at old position!
3519
+ */
3340
3520
  peer_move(from_pos, to_pos) {
3341
3521
  const peer = this.data[from_pos];
3342
3522
  const self_pos = this.data[from_pos + 1];
@@ -3344,6 +3524,9 @@ var $;
3344
3524
  this.data[to_pos + 1] = self_pos;
3345
3525
  peer.peer_repos(self_pos, to_pos);
3346
3526
  }
3527
+ /**
3528
+ * Updates self position in the peer.
3529
+ */
3347
3530
  peer_repos(peer_pos, self_pos) {
3348
3531
  this.data[peer_pos + 1] = self_pos;
3349
3532
  }
@@ -3359,10 +3542,16 @@ var $;
3359
3542
  var $;
3360
3543
  (function ($) {
3361
3544
  $.$mol_wire_auto_sub = null;
3545
+ /**
3546
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
3547
+ */
3362
3548
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
3363
3549
  return $.$mol_wire_auto_sub = next;
3364
3550
  }
3365
3551
  $.$mol_wire_auto = $mol_wire_auto;
3552
+ /**
3553
+ * Affection queue. Used to prevent accidental stack overflow on emit.
3554
+ */
3366
3555
  $.$mol_wire_affected = [];
3367
3556
  })($ || ($ = {}));
3368
3557
 
@@ -3370,9 +3559,16 @@ var $;
3370
3559
  "use strict";
3371
3560
  var $;
3372
3561
  (function ($) {
3562
+ /**
3563
+ * Publisher that can auto collect other publishers. 32B
3564
+ *
3565
+ * P1 P2 P3 P4 S1 S2 S3
3566
+ * ^ ^
3567
+ * pubs_from subs_from
3568
+ */
3373
3569
  class $mol_wire_pub_sub extends $mol_wire_pub {
3374
- pub_from = 0;
3375
- cursor = $mol_wire_cursor.stale;
3570
+ pub_from = 0; // 4B
3571
+ cursor = $mol_wire_cursor.stale; // 4B
3376
3572
  get temp() {
3377
3573
  return false;
3378
3574
  }
@@ -3490,10 +3686,27 @@ var $;
3490
3686
  return;
3491
3687
  this.cursor = quant;
3492
3688
  this.emit($mol_wire_cursor.doubt);
3689
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
3690
+ // const pub = this.data[ pos ] as $mol_wire_pub
3691
+ // if( pub instanceof $mol_wire_task ) return
3692
+ // for(
3693
+ // let cursor = this.pub_from;
3694
+ // cursor < this.sub_from;
3695
+ // cursor += 2
3696
+ // ) {
3697
+ // const pub = this.data[ cursor ] as $mol_wire_pub
3698
+ // if( pub instanceof $mol_wire_task ) {
3699
+ // pub.destructor()
3700
+ // }
3701
+ // }
3702
+ // }
3493
3703
  }
3494
3704
  [$mol_dev_format_head]() {
3495
3705
  return $mol_dev_format_native(this);
3496
3706
  }
3707
+ /**
3708
+ * Is subscribed to any publisher or not.
3709
+ */
3497
3710
  get pub_empty() {
3498
3711
  return this.sub_from === this.pub_from;
3499
3712
  }
@@ -3563,6 +3776,7 @@ var $;
3563
3776
  "use strict";
3564
3777
  var $;
3565
3778
  (function ($) {
3779
+ /// @todo right orderinng
3566
3780
  $.$mol_after_mock_queue = [];
3567
3781
  function $mol_after_mock_warp() {
3568
3782
  const queue = $.$mol_after_mock_queue.splice(0);
@@ -3639,6 +3853,13 @@ var $;
3639
3853
  var $;
3640
3854
  (function ($) {
3641
3855
  const wrappers = new WeakMap();
3856
+ /**
3857
+ * Suspendable task with support both sync/async api.
3858
+ *
3859
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
3860
+ * ^ ^ ^
3861
+ * args_from pubs_from subs_from
3862
+ **/
3642
3863
  class $mol_wire_fiber extends $mol_wire_pub_sub {
3643
3864
  task;
3644
3865
  host;
@@ -3659,6 +3880,7 @@ var $;
3659
3880
  });
3660
3881
  }
3661
3882
  static sync() {
3883
+ // Sync whole fiber graph
3662
3884
  while (this.planning.size) {
3663
3885
  for (const fiber of this.planning) {
3664
3886
  this.planning.delete(fiber);
@@ -3669,6 +3891,7 @@ var $;
3669
3891
  fiber.fresh();
3670
3892
  }
3671
3893
  }
3894
+ // Collect garbage
3672
3895
  while (this.reaping.size) {
3673
3896
  const fibers = this.reaping;
3674
3897
  this.reaping = new Set;
@@ -3820,6 +4043,10 @@ var $;
3820
4043
  this.cursor = $mol_wire_cursor.stale;
3821
4044
  this.fresh();
3822
4045
  }
4046
+ /**
4047
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
4048
+ * Should be called inside SuspenseAPI consumer (ie fiber).
4049
+ */
3823
4050
  sync() {
3824
4051
  if (!$mol_wire_fiber.warm) {
3825
4052
  return this.result();
@@ -3834,6 +4061,10 @@ var $;
3834
4061
  }
3835
4062
  return this.cache;
3836
4063
  }
4064
+ /**
4065
+ * Asynchronous execution.
4066
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
4067
+ */
3837
4068
  async async_raw() {
3838
4069
  while (true) {
3839
4070
  this.fresh();
@@ -3846,6 +4077,7 @@ var $;
3846
4077
  if (!$mol_promise_like(this.cache))
3847
4078
  return this.cache;
3848
4079
  if (this.cursor === $mol_wire_cursor.final) {
4080
+ // never ends on destructed fiber
3849
4081
  await new Promise(() => { });
3850
4082
  }
3851
4083
  }
@@ -3974,6 +4206,7 @@ var $;
3974
4206
  "use strict";
3975
4207
  var $;
3976
4208
  (function ($) {
4209
+ /** One-shot fiber */
3977
4210
  class $mol_wire_task extends $mol_wire_fiber {
3978
4211
  static getter(task) {
3979
4212
  return function $mol_wire_task_get(host, args) {
@@ -3999,6 +4232,7 @@ var $;
3999
4232
  }
4000
4233
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
4001
4234
  const next = new $mol_wire_task(key, task, host, args);
4235
+ // Disabled because non-idempotency is required for try-catch
4002
4236
  if (existen?.temp) {
4003
4237
  $$.$mol_log3_warn({
4004
4238
  place: '$mol_wire_task',
@@ -4031,7 +4265,7 @@ var $;
4031
4265
  try {
4032
4266
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
4033
4267
  }
4034
- catch {
4268
+ catch { // Promises throw in strict mode
4035
4269
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
4036
4270
  }
4037
4271
  }
@@ -4056,6 +4290,7 @@ var $;
4056
4290
  "use strict";
4057
4291
  var $;
4058
4292
  (function ($) {
4293
+ /** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
4059
4294
  function $mol_wire_async(obj) {
4060
4295
  let fiber;
4061
4296
  const temp = $mol_wire_task.getter(obj);
@@ -4139,6 +4374,9 @@ var $;
4139
4374
  "use strict";
4140
4375
  var $;
4141
4376
  (function ($) {
4377
+ /**
4378
+ * Decorates method to fiber to ensure it is executed only once inside other fiber.
4379
+ */
4142
4380
  function $mol_wire_method(host, field, descr) {
4143
4381
  if (!descr)
4144
4382
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -4193,6 +4431,10 @@ var $;
4193
4431
  props[field] = get_val;
4194
4432
  return get_val;
4195
4433
  }
4434
+ /**
4435
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
4436
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
4437
+ */
4196
4438
  function $mol_wire_sync(obj) {
4197
4439
  return new Proxy(obj, {
4198
4440
  get(obj, field) {
@@ -4960,6 +5202,11 @@ var $;
4960
5202
  "use strict";
4961
5203
  var $;
4962
5204
  (function ($) {
5205
+ /**
5206
+ * Combines list of unary functions/classes to one function.
5207
+ *
5208
+ * const reparse = $mol_data_pipe( JSON.stringify , JSON.parse )
5209
+ **/
4963
5210
  function $mol_data_pipe(...funcs) {
4964
5211
  return $mol_data_setup(function (input) {
4965
5212
  let value = input;
@@ -4976,6 +5223,14 @@ var $;
4976
5223
  var $;
4977
5224
  (function ($) {
4978
5225
  $mol_test({
5226
+ // @todo enable on strict
5227
+ // 'no functions'() {
5228
+ // const stringify = $mol_data_pipe()
5229
+ // type Type = $mol_type_assert<
5230
+ // typeof stringify,
5231
+ // ( input : never )=> never
5232
+ // >
5233
+ // },
4979
5234
  'single function'() {
4980
5235
  const stringify = $mol_data_pipe((input) => input.toString());
4981
5236
  $mol_assert_equal(stringify(5), '5');