mol_data_all 1.1.1785 → 1.1.1787

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.test.js CHANGED
@@ -224,6 +224,12 @@ var $;
224
224
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
225
225
  };
226
226
  $.$mol_jsx_frag = '';
227
+ /**
228
+ * JSX adapter that makes DOM tree.
229
+ * Generates global unique ids for every DOM-element by components tree with ids.
230
+ * Ensures all local ids are unique.
231
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
232
+ */
227
233
  function $mol_jsx(Elem, props, ...childNodes) {
228
234
  const id = props && props.id || '';
229
235
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -334,6 +340,8 @@ var $;
334
340
 
335
341
  ;
336
342
  "use strict";
343
+ /** @jsx $mol_jsx */
344
+ /** @jsxFrag $mol_jsx_frag */
337
345
  var $;
338
346
  (function ($) {
339
347
  $mol_test({
@@ -439,6 +447,7 @@ var $;
439
447
  "use strict";
440
448
  var $;
441
449
  (function ($) {
450
+ /** Generates unique identifier. */
442
451
  function $mol_guid(length = 8, exists = () => false) {
443
452
  for (;;) {
444
453
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -454,6 +463,7 @@ var $;
454
463
  "use strict";
455
464
  var $;
456
465
  (function ($) {
466
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
457
467
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
458
468
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
459
469
  if (typeof item !== 'function') {
@@ -502,6 +512,7 @@ var $;
502
512
  }
503
513
  $.$mol_range2 = $mol_range2;
504
514
  class $mol_range2_array extends Array {
515
+ // Lazy
505
516
  concat(...tail) {
506
517
  if (tail.length === 0)
507
518
  return this;
@@ -513,6 +524,7 @@ var $;
513
524
  }
514
525
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
515
526
  }
527
+ // Lazy
516
528
  filter(check, context) {
517
529
  const filtered = [];
518
530
  let cursor = -1;
@@ -525,13 +537,16 @@ var $;
525
537
  return filtered[index];
526
538
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
527
539
  }
540
+ // Diligent
528
541
  forEach(proceed, context) {
529
542
  for (let [key, value] of this.entries())
530
543
  proceed.call(context, value, key, this);
531
544
  }
545
+ // Lazy
532
546
  map(proceed, context) {
533
547
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
534
548
  }
549
+ // Diligent
535
550
  reduce(merge, result) {
536
551
  let index = 0;
537
552
  if (arguments.length === 1) {
@@ -542,12 +557,15 @@ var $;
542
557
  }
543
558
  return result;
544
559
  }
560
+ // Lazy
545
561
  toReversed() {
546
562
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
547
563
  }
564
+ // Lazy
548
565
  slice(from = 0, to = this.length) {
549
566
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
550
567
  }
568
+ // Lazy
551
569
  some(check, context) {
552
570
  for (let index = 0; index < this.length; ++index) {
553
571
  if (check.call(context, this[index], index, this))
@@ -740,6 +758,7 @@ var $;
740
758
 
741
759
  ;
742
760
  "use strict";
761
+ /** @jsx $mol_jsx */
743
762
  var $;
744
763
  (function ($) {
745
764
  $mol_test({
@@ -801,6 +820,7 @@ var $;
801
820
  const obj3_copy = { test: 3, obj2: obj2_copy };
802
821
  obj1.obj3 = obj3;
803
822
  obj1_copy.obj3 = obj3_copy;
823
+ // warmup cache
804
824
  $mol_assert_not($mol_compare_deep(obj1, {}));
805
825
  $mol_assert_not($mol_compare_deep(obj2, {}));
806
826
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -870,6 +890,7 @@ var $;
870
890
  "use strict";
871
891
  var $;
872
892
  (function ($) {
893
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
873
894
  $['devtoolsFormatters'] ||= [];
874
895
  function $mol_dev_format_register(config) {
875
896
  $['devtoolsFormatters'].push(config);
@@ -921,6 +942,7 @@ var $;
921
942
  return false;
922
943
  if (!val)
923
944
  return false;
945
+ // if( Error.isError( val ) ) true
924
946
  if (val[$.$mol_dev_format_body])
925
947
  return true;
926
948
  return false;
@@ -938,12 +960,16 @@ var $;
938
960
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
939
961
  }
940
962
  }
963
+ // if( Error.isError( val ) ) {
964
+ // return $mol_dev_format_native( val )
965
+ // }
941
966
  return null;
942
967
  },
943
968
  });
944
969
  function $mol_dev_format_native(obj) {
945
970
  if (typeof obj === 'undefined')
946
971
  return $.$mol_dev_format_shade('undefined');
972
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
947
973
  return [
948
974
  'object',
949
975
  {
@@ -1001,6 +1027,9 @@ var $;
1001
1027
  'margin-left': '13px'
1002
1028
  });
1003
1029
  class Stack extends Array {
1030
+ // [ Symbol.toPrimitive ]() {
1031
+ // return this.toString()
1032
+ // }
1004
1033
  toString() {
1005
1034
  return this.join('\n');
1006
1035
  }
@@ -1023,6 +1052,7 @@ var $;
1023
1052
  this.method = call.getMethodName() ?? '';
1024
1053
  if (this.method === this.function)
1025
1054
  this.method = '';
1055
+ // const func = c.getFunction()
1026
1056
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
1027
1057
  this.eval = call.getEvalOrigin() ?? '';
1028
1058
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -1069,18 +1099,34 @@ var $;
1069
1099
  "use strict";
1070
1100
  var $;
1071
1101
  (function ($) {
1102
+ /**
1103
+ * Argument must be Truthy
1104
+ * @deprecated use $mol_assert_equal instead
1105
+ */
1072
1106
  function $mol_assert_ok(value) {
1073
1107
  if (value)
1074
1108
  return;
1075
1109
  $mol_fail(new Error(`${value} ≠ true`));
1076
1110
  }
1077
1111
  $.$mol_assert_ok = $mol_assert_ok;
1112
+ /**
1113
+ * Argument must be Falsy
1114
+ * @deprecated use $mol_assert_equal instead
1115
+ */
1078
1116
  function $mol_assert_not(value) {
1079
1117
  if (!value)
1080
1118
  return;
1081
1119
  $mol_fail(new Error(`${value} ≠ false`));
1082
1120
  }
1083
1121
  $.$mol_assert_not = $mol_assert_not;
1122
+ /**
1123
+ * Handler must throw an error.
1124
+ * @example
1125
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
1126
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
1127
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
1128
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
1129
+ */
1084
1130
  function $mol_assert_fail(handler, ErrorRight) {
1085
1131
  const fail = $.$mol_fail;
1086
1132
  try {
@@ -1103,10 +1149,18 @@ var $;
1103
1149
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
1104
1150
  }
1105
1151
  $.$mol_assert_fail = $mol_assert_fail;
1152
+ /** @deprecated Use $mol_assert_equal */
1106
1153
  function $mol_assert_like(...args) {
1107
1154
  $mol_assert_equal(...args);
1108
1155
  }
1109
1156
  $.$mol_assert_like = $mol_assert_like;
1157
+ /**
1158
+ * All arguments must not be structural equal to each other.
1159
+ * @example
1160
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
1161
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
1162
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
1163
+ */
1110
1164
  function $mol_assert_unique(...args) {
1111
1165
  for (let i = 0; i < args.length; ++i) {
1112
1166
  for (let j = 0; j < args.length; ++j) {
@@ -1119,6 +1173,13 @@ var $;
1119
1173
  }
1120
1174
  }
1121
1175
  $.$mol_assert_unique = $mol_assert_unique;
1176
+ /**
1177
+ * All arguments must be structural equal each other.
1178
+ * @example
1179
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
1180
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
1181
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
1182
+ */
1122
1183
  function $mol_assert_equal(...args) {
1123
1184
  for (let i = 1; i < args.length; ++i) {
1124
1185
  if ($mol_compare_deep(args[0], args[i]))
@@ -1171,6 +1232,7 @@ var $;
1171
1232
  "use strict";
1172
1233
  var $;
1173
1234
  (function ($) {
1235
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1174
1236
  function $mol_log3_area_lazy(event) {
1175
1237
  const self = this.$;
1176
1238
  const stack = self.$mol_log3_stack;
@@ -1477,6 +1539,9 @@ var $;
1477
1539
  gender["bisexual"] = "bisexual";
1478
1540
  gender["trans"] = "transgender";
1479
1541
  })(gender || (gender = {}));
1542
+ // Test disabled due https://github.com/microsoft/TypeScript/issues/46112
1543
+ // const Sex = $mol_data_enum( 'sex' , sex )
1544
+ // type sex_value = $mol_type_assert< typeof Sex.Value , sex >
1480
1545
  $mol_test({
1481
1546
  'config of enum'() {
1482
1547
  const Sex = $mol_data_enum('sex', sex);
@@ -1506,6 +1571,8 @@ var $;
1506
1571
  $mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
1507
1572
  },
1508
1573
  });
1574
+ // Test disabled due https://github.com/microsoft/TypeScript/issues/46112
1575
+ // type gender_value = $mol_type_assert< typeof Gender.Value , gender >
1509
1576
  $mol_test({
1510
1577
  'config of enum'() {
1511
1578
  const Gender = $mol_data_enum('gender', gender);
@@ -1621,11 +1688,14 @@ var $;
1621
1688
  Weight: $mol_data_integer,
1622
1689
  Length: $mol_data_integer,
1623
1690
  });
1624
- Length(20);
1625
- let len = Length(10);
1626
- len = 20;
1627
- let num = len;
1628
- len = Length(Weight(20));
1691
+ Length(20); // Validate
1692
+ let len = Length(10); // Inferred type
1693
+ len = 20; // Explicit type
1694
+ let num = len; // Implicit cast
1695
+ len = Length(Weight(20)); // Explicit cast
1696
+ // len = 20 // Compile time error
1697
+ // len = Weight( 20 ) // Compile time error
1698
+ // len = Length( 20.1 ) // Run time error
1629
1699
  },
1630
1700
  });
1631
1701
  })($ || ($ = {}));
@@ -1678,6 +1748,9 @@ var $;
1678
1748
  ;
1679
1749
  "use strict";
1680
1750
 
1751
+ ;
1752
+ "use strict";
1753
+
1681
1754
  ;
1682
1755
  "use strict";
1683
1756
  var $;
@@ -1691,6 +1764,21 @@ var $;
1691
1764
  const User = $mol_data_record({ age: $mol_data_number });
1692
1765
  User({ age: 0, name: 'Jin' });
1693
1766
  },
1767
+ // 'Recursive record' () {
1768
+ // const User = $mol_data_record({
1769
+ // name : $mol_data_string ,
1770
+ // get kids() { return $mol_data_array( User ) } ,
1771
+ // })
1772
+ // User({
1773
+ // name : 'Jin' ,
1774
+ // kids : [
1775
+ // {
1776
+ // name : 'John' ,
1777
+ // kids : [] ,
1778
+ // }
1779
+ // ] ,
1780
+ // })
1781
+ // } ,
1694
1782
  'Shrinks record'() {
1695
1783
  $mol_assert_fail(() => {
1696
1784
  const User = $mol_data_record({ age: $mol_data_number, name: $mol_data_string });
@@ -1799,6 +1887,14 @@ var $;
1799
1887
  var $;
1800
1888
  (function ($) {
1801
1889
  $mol_test({
1890
+ // @todo enable on strict
1891
+ // 'no functions'() {
1892
+ // const stringify = $mol_data_pipe()
1893
+ // type Type = $mol_type_assert<
1894
+ // typeof stringify,
1895
+ // ( input : never )=> never
1896
+ // >
1897
+ // },
1802
1898
  'single function'() {
1803
1899
  const stringify = $mol_data_pipe((input) => input.toString());
1804
1900
  $mol_assert_equal(stringify(5), '5');