mol_crypto2_lib 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.mjs CHANGED
@@ -69,6 +69,7 @@ var $;
69
69
  var $;
70
70
  (function ($) {
71
71
  function $mol_base64_decode_node(base64Str) {
72
+ // without Uint8Array breaks $mol_compare_deep
72
73
  const buffer = Buffer.from(base64Str, 'base64');
73
74
  return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
74
75
  }
@@ -170,6 +171,7 @@ var $;
170
171
  this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
171
172
  }
172
173
  }
174
+ /** 1-byte signed integer channel for offset. */
173
175
  int8(offset, next) {
174
176
  if (next === undefined)
175
177
  return this.getInt8(offset);
@@ -177,6 +179,7 @@ var $;
177
179
  return this.setInt8(offset, next), next;
178
180
  $mol_fail(new Error(`Wrong int8 value ${next}`));
179
181
  }
182
+ /** 1-byte unsigned integer channel for offset. */
180
183
  uint8(offset, next) {
181
184
  if (next === undefined)
182
185
  return this.getUint8(offset);
@@ -184,6 +187,7 @@ var $;
184
187
  return this.setUint8(offset, next), next;
185
188
  $mol_fail(new Error(`Wrong uint8 value ${next}`));
186
189
  }
190
+ /** 2-byte signed integer little-endian channel for offset. */
187
191
  int16(offset, next) {
188
192
  if (next === undefined)
189
193
  return this.getInt16(offset, true);
@@ -191,6 +195,7 @@ var $;
191
195
  return this.setInt16(offset, next, true), next;
192
196
  $mol_fail(new Error(`Wrong int16 value ${next}`));
193
197
  }
198
+ /** 2-byte unsigned integer little-endian channel for offset. */
194
199
  uint16(offset, next) {
195
200
  if (next === undefined)
196
201
  return this.getUint16(offset, true);
@@ -198,6 +203,7 @@ var $;
198
203
  return this.setUint16(offset, next, true), next;
199
204
  $mol_fail(new Error(`Wrong uint16 value ${next}`));
200
205
  }
206
+ /** 4-byte signed integer little-endian channel for offset. */
201
207
  int32(offset, next) {
202
208
  if (next === undefined)
203
209
  return this.getInt32(offset, true);
@@ -205,6 +211,7 @@ var $;
205
211
  return this.setInt32(offset, next, true), next;
206
212
  $mol_fail(new Error(`Wrong int32 value ${next}`));
207
213
  }
214
+ /** 4-byte unsigned integer little-endian channel for offset. */
208
215
  uint32(offset, next) {
209
216
  if (next === undefined)
210
217
  return this.getUint32(offset, true);
@@ -212,6 +219,7 @@ var $;
212
219
  return this.setUint32(offset, next, true), next;
213
220
  $mol_fail(new Error(`Wrong uint32 value ${next}`));
214
221
  }
222
+ /** 8-byte signed integer little-endian channel for offset. */
215
223
  int64(offset, next) {
216
224
  if (next === undefined)
217
225
  return this.getBigInt64(offset, true);
@@ -219,6 +227,7 @@ var $;
219
227
  return this.setBigInt64(offset, next, true), next;
220
228
  $mol_fail(new Error(`Wrong int64 value ${next}`));
221
229
  }
230
+ /** 6-byte unsigned integer little-endian channel for offset. */
222
231
  uint48(offset, next) {
223
232
  if (next === undefined)
224
233
  return this.getUint48(offset, true);
@@ -226,6 +235,7 @@ var $;
226
235
  return this.setUint48(offset, next, true), next;
227
236
  $mol_fail(new Error(`Wrong uint48 value ${next}`));
228
237
  }
238
+ /** 8-byte unsigned integer little-endian channel for offset. */
229
239
  uint64(offset, next) {
230
240
  if (next === undefined)
231
241
  return this.getBigUint64(offset, true);
@@ -233,24 +243,29 @@ var $;
233
243
  return this.setBigUint64(offset, next, true), next;
234
244
  $mol_fail(new Error(`Wrong uint64 value ${next}`));
235
245
  }
246
+ /** 2-byte float little-endian channel for offset. */
236
247
  float16(offset, next) {
237
248
  if (next !== undefined)
238
249
  this.setFloat16(offset, next, true);
239
250
  return this.getFloat16(offset, true);
240
251
  }
252
+ /** 4-byte float little-endian channel for offset. */
241
253
  float32(offset, next) {
242
254
  if (next !== undefined)
243
255
  this.setFloat32(offset, next, true);
244
256
  return this.getFloat32(offset, true);
245
257
  }
258
+ /** 8-byte float little-endian channel for offset. */
246
259
  float64(offset, next) {
247
260
  if (next !== undefined)
248
261
  this.setFloat64(offset, next, true);
249
262
  return this.getFloat64(offset, true);
250
263
  }
264
+ /** A Uint8Array view for the same buffer. */
251
265
  asArray() {
252
266
  return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
253
267
  }
268
+ /** base64ae string from buffer. */
254
269
  toString() {
255
270
  return $mol_base64_ae_encode(this.asArray());
256
271
  }
@@ -287,6 +302,7 @@ var $;
287
302
  $.$mol_base64_url_encode = $mol_base64_url_encode_node;
288
303
  }
289
304
  function $mol_base64_url_decode_node(str) {
305
+ // without Uint8Array breaks $mol_compare_deep
290
306
  const buffer = Buffer.from(str, 'base64url');
291
307
  return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
292
308
  }
@@ -312,6 +328,11 @@ var $;
312
328
  var $;
313
329
  (function ($) {
314
330
  const instances = new WeakSet();
331
+ /**
332
+ * Proxy that delegates all to lazy returned target.
333
+ *
334
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
335
+ */
315
336
  function $mol_delegate(proto, target) {
316
337
  const proxy = new Proxy(proto, {
317
338
  get: (_, field) => {
@@ -405,7 +426,7 @@ var $;
405
426
  var $;
406
427
  (function ($) {
407
428
  function $mol_fail_hidden(error) {
408
- throw error;
429
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
409
430
  }
410
431
  $.$mol_fail_hidden = $mol_fail_hidden;
411
432
  })($ || ($ = {}));
@@ -465,6 +486,9 @@ var $;
465
486
  [Symbol.dispose]() {
466
487
  this.destructor();
467
488
  }
489
+ //[ Symbol.toPrimitive ]( hint: string ) {
490
+ // return hint === 'number' ? this.valueOf() : this.toString()
491
+ //}
468
492
  toString() {
469
493
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
470
494
  }
@@ -535,9 +559,11 @@ var $;
535
559
  "use strict";
536
560
  var $;
537
561
  (function ($) {
562
+ /** Base class for crypto keys. */
538
563
  class $mol_crypto2_key extends $mol_buffer {
539
564
  static size_str = 43;
540
565
  static size_bin = 32;
566
+ /** Kakes key from different params. */
541
567
  static from(serial) {
542
568
  if (typeof serial === 'string') {
543
569
  serial = new Uint8Array(serial.match(/.{43}/g)
@@ -549,6 +575,7 @@ var $;
549
575
  }
550
576
  return super.from(serial);
551
577
  }
578
+ /** Array view of public part. */
552
579
  asArray() {
553
580
  const size = this.constructor.size_bin;
554
581
  if (this.byteLength < size) {
@@ -559,6 +586,7 @@ var $;
559
586
  }
560
587
  return new Uint8Array(this.buffer, this.byteOffset, size);
561
588
  }
589
+ /** String representation of public part. */
562
590
  toString() {
563
591
  return $mol_base64_url_encode(this.asArray());
564
592
  }
@@ -576,7 +604,7 @@ var $;
576
604
  "use strict";
577
605
  var $;
578
606
  (function ($) {
579
- const mod = require('module');
607
+ const mod = require /****/('module');
580
608
  const internals = mod.builtinModules;
581
609
  function $node_internal_check(name) {
582
610
  if (name.startsWith('node:'))
@@ -654,8 +682,8 @@ var $;
654
682
  "use strict";
655
683
  var $;
656
684
  (function ($) {
657
- const path = require('path');
658
- const mod = require('module');
685
+ const path = require /****/('path');
686
+ const mod = require /****/('module');
659
687
  const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
660
688
  function $node_autoinstall(name) {
661
689
  try {
@@ -730,6 +758,7 @@ var $;
730
758
  ])
731
759
  ].map(frame_normalize).join('\n')
732
760
  });
761
+ // в nodejs, что б не дублировалось cause в консоли
733
762
  Object.defineProperty(this, 'cause', {
734
763
  get: () => cause
735
764
  });
@@ -790,6 +819,7 @@ var $;
790
819
  "use strict";
791
820
  var $;
792
821
  (function ($) {
822
+ /** Generates unique identifier. */
793
823
  function $mol_guid(length = 8, exists = () => false) {
794
824
  for (;;) {
795
825
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -805,11 +835,16 @@ var $;
805
835
  "use strict";
806
836
  var $;
807
837
  (function ($) {
838
+ /** Special status statuses. */
808
839
  let $mol_wire_cursor;
809
840
  (function ($mol_wire_cursor) {
841
+ /** Update required. */
810
842
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
843
+ /** Some of (transitive) pub update required. */
811
844
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
845
+ /** Actual state but may be dropped. */
812
846
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
847
+ /** State will never be changed. */
813
848
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
814
849
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
815
850
  })($ || ($ = {}));
@@ -818,6 +853,9 @@ var $;
818
853
  "use strict";
819
854
  var $;
820
855
  (function ($) {
856
+ /**
857
+ * Collects subscribers in compact array. 28B
858
+ */
821
859
  class $mol_wire_pub extends Object {
822
860
  constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
823
861
  super();
@@ -825,10 +863,17 @@ var $;
825
863
  }
826
864
  [Symbol.toStringTag];
827
865
  data = [];
866
+ // Derived objects should be Arrays.
828
867
  static get [Symbol.species]() {
829
868
  return Array;
830
869
  }
831
- sub_from = 0;
870
+ /**
871
+ * Index of first subscriber.
872
+ */
873
+ sub_from = 0; // 4B
874
+ /**
875
+ * All current subscribers.
876
+ */
832
877
  get sub_list() {
833
878
  const res = [];
834
879
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -836,14 +881,23 @@ var $;
836
881
  }
837
882
  return res;
838
883
  }
884
+ /**
885
+ * Has any subscribers or not.
886
+ */
839
887
  get sub_empty() {
840
888
  return this.sub_from === this.data.length;
841
889
  }
890
+ /**
891
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
892
+ */
842
893
  sub_on(sub, pub_pos) {
843
894
  const pos = this.data.length;
844
895
  this.data.push(sub, pub_pos);
845
896
  return pos;
846
897
  }
898
+ /**
899
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
900
+ */
847
901
  sub_off(sub_pos) {
848
902
  if (!(sub_pos < this.data.length)) {
849
903
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -856,21 +910,39 @@ var $;
856
910
  if (end === this.sub_from)
857
911
  this.reap();
858
912
  }
913
+ /**
914
+ * Called when last sub was unsubscribed.
915
+ **/
859
916
  reap() { }
917
+ /**
918
+ * Autowire this publisher with current subscriber.
919
+ **/
860
920
  promote() {
861
921
  $mol_wire_auto()?.track_next(this);
862
922
  }
923
+ /**
924
+ * Enforce actualization. Should not throw errors.
925
+ */
863
926
  fresh() { }
927
+ /**
928
+ * Allow to put data to caches in the subtree.
929
+ */
864
930
  complete() { }
865
931
  get incompleted() {
866
932
  return false;
867
933
  }
934
+ /**
935
+ * Notify subscribers about self changes.
936
+ */
868
937
  emit(quant = $mol_wire_cursor.stale) {
869
938
  for (let i = this.sub_from; i < this.data.length; i += 2) {
870
939
  ;
871
940
  this.data[i].absorb(quant, this.data[i + 1]);
872
941
  }
873
942
  }
943
+ /**
944
+ * Moves peer from one position to another. Doesn't clear data at old position!
945
+ */
874
946
  peer_move(from_pos, to_pos) {
875
947
  const peer = this.data[from_pos];
876
948
  const self_pos = this.data[from_pos + 1];
@@ -878,6 +950,9 @@ var $;
878
950
  this.data[to_pos + 1] = self_pos;
879
951
  peer.peer_repos(self_pos, to_pos);
880
952
  }
953
+ /**
954
+ * Updates self position in the peer.
955
+ */
881
956
  peer_repos(peer_pos, self_pos) {
882
957
  this.data[peer_pos + 1] = self_pos;
883
958
  }
@@ -893,10 +968,16 @@ var $;
893
968
  var $;
894
969
  (function ($) {
895
970
  $.$mol_wire_auto_sub = null;
971
+ /**
972
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
973
+ */
896
974
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
897
975
  return $.$mol_wire_auto_sub = next;
898
976
  }
899
977
  $.$mol_wire_auto = $mol_wire_auto;
978
+ /**
979
+ * Affection queue. Used to prevent accidental stack overflow on emit.
980
+ */
900
981
  $.$mol_wire_affected = [];
901
982
  })($ || ($ = {}));
902
983
 
@@ -904,6 +985,7 @@ var $;
904
985
  "use strict";
905
986
  var $;
906
987
  (function ($) {
988
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
907
989
  $['devtoolsFormatters'] ||= [];
908
990
  function $mol_dev_format_register(config) {
909
991
  $['devtoolsFormatters'].push(config);
@@ -955,6 +1037,7 @@ var $;
955
1037
  return false;
956
1038
  if (!val)
957
1039
  return false;
1040
+ // if( Error.isError( val ) ) true
958
1041
  if (val[$.$mol_dev_format_body])
959
1042
  return true;
960
1043
  return false;
@@ -972,12 +1055,16 @@ var $;
972
1055
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
973
1056
  }
974
1057
  }
1058
+ // if( Error.isError( val ) ) {
1059
+ // return $mol_dev_format_native( val )
1060
+ // }
975
1061
  return null;
976
1062
  },
977
1063
  });
978
1064
  function $mol_dev_format_native(obj) {
979
1065
  if (typeof obj === 'undefined')
980
1066
  return $.$mol_dev_format_shade('undefined');
1067
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
981
1068
  return [
982
1069
  'object',
983
1070
  {
@@ -1035,6 +1122,9 @@ var $;
1035
1122
  'margin-left': '13px'
1036
1123
  });
1037
1124
  class Stack extends Array {
1125
+ // [ Symbol.toPrimitive ]() {
1126
+ // return this.toString()
1127
+ // }
1038
1128
  toString() {
1039
1129
  return this.join('\n');
1040
1130
  }
@@ -1057,6 +1147,7 @@ var $;
1057
1147
  this.method = call.getMethodName() ?? '';
1058
1148
  if (this.method === this.function)
1059
1149
  this.method = '';
1150
+ // const func = c.getFunction()
1060
1151
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
1061
1152
  this.eval = call.getEvalOrigin() ?? '';
1062
1153
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -1103,9 +1194,16 @@ var $;
1103
1194
  "use strict";
1104
1195
  var $;
1105
1196
  (function ($) {
1197
+ /**
1198
+ * Publisher that can auto collect other publishers. 32B
1199
+ *
1200
+ * P1 P2 P3 P4 S1 S2 S3
1201
+ * ^ ^
1202
+ * pubs_from subs_from
1203
+ */
1106
1204
  class $mol_wire_pub_sub extends $mol_wire_pub {
1107
- pub_from = 0;
1108
- cursor = $mol_wire_cursor.stale;
1205
+ pub_from = 0; // 4B
1206
+ cursor = $mol_wire_cursor.stale; // 4B
1109
1207
  get temp() {
1110
1208
  return false;
1111
1209
  }
@@ -1223,10 +1321,27 @@ var $;
1223
1321
  return;
1224
1322
  this.cursor = quant;
1225
1323
  this.emit($mol_wire_cursor.doubt);
1324
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
1325
+ // const pub = this.data[ pos ] as $mol_wire_pub
1326
+ // if( pub instanceof $mol_wire_task ) return
1327
+ // for(
1328
+ // let cursor = this.pub_from;
1329
+ // cursor < this.sub_from;
1330
+ // cursor += 2
1331
+ // ) {
1332
+ // const pub = this.data[ cursor ] as $mol_wire_pub
1333
+ // if( pub instanceof $mol_wire_task ) {
1334
+ // pub.destructor()
1335
+ // }
1336
+ // }
1337
+ // }
1226
1338
  }
1227
1339
  [$mol_dev_format_head]() {
1228
1340
  return $mol_dev_format_native(this);
1229
1341
  }
1342
+ /**
1343
+ * Is subscribed to any publisher or not.
1344
+ */
1230
1345
  get pub_empty() {
1231
1346
  return this.sub_from === this.pub_from;
1232
1347
  }
@@ -1267,6 +1382,13 @@ var $;
1267
1382
  var $;
1268
1383
  (function ($) {
1269
1384
  const wrappers = new WeakMap();
1385
+ /**
1386
+ * Suspendable task with support both sync/async api.
1387
+ *
1388
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
1389
+ * ^ ^ ^
1390
+ * args_from pubs_from subs_from
1391
+ **/
1270
1392
  class $mol_wire_fiber extends $mol_wire_pub_sub {
1271
1393
  task;
1272
1394
  host;
@@ -1287,6 +1409,7 @@ var $;
1287
1409
  });
1288
1410
  }
1289
1411
  static sync() {
1412
+ // Sync whole fiber graph
1290
1413
  while (this.planning.size) {
1291
1414
  for (const fiber of this.planning) {
1292
1415
  this.planning.delete(fiber);
@@ -1297,6 +1420,7 @@ var $;
1297
1420
  fiber.fresh();
1298
1421
  }
1299
1422
  }
1423
+ // Collect garbage
1300
1424
  while (this.reaping.size) {
1301
1425
  const fibers = this.reaping;
1302
1426
  this.reaping = new Set;
@@ -1448,6 +1572,10 @@ var $;
1448
1572
  this.cursor = $mol_wire_cursor.stale;
1449
1573
  this.fresh();
1450
1574
  }
1575
+ /**
1576
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
1577
+ * Should be called inside SuspenseAPI consumer (ie fiber).
1578
+ */
1451
1579
  sync() {
1452
1580
  if (!$mol_wire_fiber.warm) {
1453
1581
  return this.result();
@@ -1462,6 +1590,10 @@ var $;
1462
1590
  }
1463
1591
  return this.cache;
1464
1592
  }
1593
+ /**
1594
+ * Asynchronous execution.
1595
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
1596
+ */
1465
1597
  async async_raw() {
1466
1598
  while (true) {
1467
1599
  this.fresh();
@@ -1474,6 +1606,7 @@ var $;
1474
1606
  if (!$mol_promise_like(this.cache))
1475
1607
  return this.cache;
1476
1608
  if (this.cursor === $mol_wire_cursor.final) {
1609
+ // never ends on destructed fiber
1477
1610
  await new Promise(() => { });
1478
1611
  }
1479
1612
  }
@@ -1521,6 +1654,10 @@ var $;
1521
1654
  var $;
1522
1655
  (function ($) {
1523
1656
  $.$mol_compare_deep_cache = new WeakMap();
1657
+ /**
1658
+ * Deeply compares two values. Returns true if equal.
1659
+ * Define `Symbol.toPrimitive` to customize.
1660
+ */
1524
1661
  function $mol_compare_deep(left, right) {
1525
1662
  if (Object.is(left, right))
1526
1663
  return true;
@@ -1660,6 +1797,7 @@ var $;
1660
1797
  "use strict";
1661
1798
  var $;
1662
1799
  (function ($) {
1800
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1663
1801
  function $mol_log3_area_lazy(event) {
1664
1802
  const self = this.$;
1665
1803
  const stack = self.$mol_log3_stack;
@@ -1684,6 +1822,7 @@ var $;
1684
1822
  "use strict";
1685
1823
  var $;
1686
1824
  (function ($) {
1825
+ /** Position in any resource. */
1687
1826
  class $mol_span extends $mol_object2 {
1688
1827
  uri;
1689
1828
  source;
@@ -1699,13 +1838,17 @@ var $;
1699
1838
  this.length = length;
1700
1839
  this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1701
1840
  }
1841
+ /** Span for begin of unknown resource */
1702
1842
  static unknown = $mol_span.begin('?');
1843
+ /** Makes new span for begin of resource. */
1703
1844
  static begin(uri, source = '') {
1704
1845
  return new $mol_span(uri, source, 1, 1, 0);
1705
1846
  }
1847
+ /** Makes new span for end of resource. */
1706
1848
  static end(uri, source) {
1707
1849
  return new $mol_span(uri, source, 1, source.length + 1, 0);
1708
1850
  }
1851
+ /** Makes new span for entire resource. */
1709
1852
  static entire(uri, source) {
1710
1853
  return new $mol_span(uri, source, 1, 1, source.length);
1711
1854
  }
@@ -1720,15 +1863,19 @@ var $;
1720
1863
  length: this.length
1721
1864
  };
1722
1865
  }
1866
+ /** Makes new error for this span. */
1723
1867
  error(message, Class = Error) {
1724
1868
  return new Class(`${message} (${this})`);
1725
1869
  }
1870
+ /** Makes new span for same uri. */
1726
1871
  span(row, col, length) {
1727
1872
  return new $mol_span(this.uri, this.source, row, col, length);
1728
1873
  }
1874
+ /** Makes new span after end of this. */
1729
1875
  after(length = 0) {
1730
1876
  return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1731
1877
  }
1878
+ /** Makes new span between begin and end. */
1732
1879
  slice(begin, end = -1) {
1733
1880
  let len = this.length;
1734
1881
  if (begin < 0)
@@ -1751,6 +1898,7 @@ var $;
1751
1898
  "use strict";
1752
1899
  var $;
1753
1900
  (function ($) {
1901
+ /** Serializes tree to string in tree format. */
1754
1902
  function $mol_tree2_to_string(tree) {
1755
1903
  let output = [];
1756
1904
  function dump(tree, prefix = '') {
@@ -1794,12 +1942,25 @@ var $;
1794
1942
  "use strict";
1795
1943
  var $;
1796
1944
  (function ($) {
1945
+ /**
1946
+ * Abstract Syntax Tree with human readable serialization.
1947
+ * Avoid direct instantiation. Use static factories instead.
1948
+ * @see https://github.com/nin-jin/tree.d
1949
+ */
1797
1950
  class $mol_tree2 extends Object {
1798
1951
  type;
1799
1952
  value;
1800
1953
  kids;
1801
1954
  span;
1802
- constructor(type, value, kids, span) {
1955
+ constructor(
1956
+ /** Type of structural node, `value` should be empty */
1957
+ type,
1958
+ /** Content of data node, `type` should be empty */
1959
+ value,
1960
+ /** Child nodes */
1961
+ kids,
1962
+ /** Position in most far source resource */
1963
+ span) {
1803
1964
  super();
1804
1965
  this.type = type;
1805
1966
  this.value = value;
@@ -1807,12 +1968,15 @@ var $;
1807
1968
  this.span = span;
1808
1969
  this[Symbol.toStringTag] = type || '\\' + value;
1809
1970
  }
1971
+ /** Makes collection node. */
1810
1972
  static list(kids, span = $mol_span.unknown) {
1811
1973
  return new $mol_tree2('', '', kids, span);
1812
1974
  }
1975
+ /** Makes new derived collection node. */
1813
1976
  list(kids) {
1814
1977
  return $mol_tree2.list(kids, this.span);
1815
1978
  }
1979
+ /** Makes data node for any string. */
1816
1980
  static data(value, kids = [], span = $mol_span.unknown) {
1817
1981
  const chunks = value.split('\n');
1818
1982
  if (chunks.length > 1) {
@@ -1826,21 +1990,26 @@ var $;
1826
1990
  }
1827
1991
  return new $mol_tree2('', value, kids, span);
1828
1992
  }
1993
+ /** Makes new derived data node. */
1829
1994
  data(value, kids = []) {
1830
1995
  return $mol_tree2.data(value, kids, this.span);
1831
1996
  }
1997
+ /** Makes struct node. */
1832
1998
  static struct(type, kids = [], span = $mol_span.unknown) {
1833
1999
  if (/[ \n\t\\]/.test(type)) {
1834
2000
  $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1835
2001
  }
1836
2002
  return new $mol_tree2(type, '', kids, span);
1837
2003
  }
2004
+ /** Makes new derived structural node. */
1838
2005
  struct(type, kids = []) {
1839
2006
  return $mol_tree2.struct(type, kids, this.span);
1840
2007
  }
2008
+ /** Makes new derived node with different kids id defined. */
1841
2009
  clone(kids, span = this.span) {
1842
2010
  return new $mol_tree2(this.type, this.value, kids, span);
1843
2011
  }
2012
+ /** Returns multiline text content. */
1844
2013
  text() {
1845
2014
  var values = [];
1846
2015
  for (var kid of this.kids) {
@@ -1850,15 +2019,20 @@ var $;
1850
2019
  }
1851
2020
  return this.value + values.join('\n');
1852
2021
  }
2022
+ /** Parses tree format. */
2023
+ /** @deprecated Use $mol_tree2_from_string */
1853
2024
  static fromString(str, uri = 'unknown') {
1854
2025
  return $$.$mol_tree2_from_string(str, uri);
1855
2026
  }
2027
+ /** Serializes to tree format. */
1856
2028
  toString() {
1857
2029
  return $$.$mol_tree2_to_string(this);
1858
2030
  }
2031
+ /** Makes new tree with node overrided by path. */
1859
2032
  insert(value, ...path) {
1860
2033
  return this.update($mol_maybe(value), ...path)[0];
1861
2034
  }
2035
+ /** Makes new tree with node overrided by path. */
1862
2036
  update(value, ...path) {
1863
2037
  if (path.length === 0)
1864
2038
  return value;
@@ -1891,6 +2065,7 @@ var $;
1891
2065
  return [this.clone(kids)];
1892
2066
  }
1893
2067
  }
2068
+ /** Query nodes by path. */
1894
2069
  select(...path) {
1895
2070
  let next = [this];
1896
2071
  for (const type of path) {
@@ -1917,6 +2092,7 @@ var $;
1917
2092
  }
1918
2093
  return this.list(next);
1919
2094
  }
2095
+ /** Filter kids by path or value. */
1920
2096
  filter(path, value) {
1921
2097
  const sub = this.kids.filter(item => {
1922
2098
  var found = item.select(...path);
@@ -1944,9 +2120,11 @@ var $;
1944
2120
  $mol_fail_hidden(error);
1945
2121
  }
1946
2122
  }
2123
+ /** Transform tree through context with transformers */
1947
2124
  hack(belt, context = {}) {
1948
2125
  return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1949
2126
  }
2127
+ /** Makes Error with node coordinates. */
1950
2128
  error(message, Class = Error) {
1951
2129
  return this.span.error(`${message}\n${this.clone([])}`, Class);
1952
2130
  }
@@ -1964,6 +2142,7 @@ var $;
1964
2142
  "use strict";
1965
2143
  var $;
1966
2144
  (function ($) {
2145
+ /** Syntax error with cordinates and source line snippet. */
1967
2146
  class $mol_error_syntax extends SyntaxError {
1968
2147
  reason;
1969
2148
  line;
@@ -1982,6 +2161,7 @@ var $;
1982
2161
  "use strict";
1983
2162
  var $;
1984
2163
  (function ($) {
2164
+ /** Parses tree format from string. */
1985
2165
  function $mol_tree2_from_string(str, uri = '?') {
1986
2166
  const span = $mol_span.entire(uri, str);
1987
2167
  var root = $mol_tree2.list([], span);
@@ -1991,6 +2171,7 @@ var $;
1991
2171
  var indent = 0;
1992
2172
  var line_start = pos;
1993
2173
  row++;
2174
+ // read indent
1994
2175
  while (str.length > pos && str[pos] == '\t') {
1995
2176
  indent++;
1996
2177
  pos++;
@@ -1999,8 +2180,10 @@ var $;
1999
2180
  min_indent = indent;
2000
2181
  }
2001
2182
  indent -= min_indent;
2183
+ // invalid tab size
2002
2184
  if (indent < 0 || indent >= stack.length) {
2003
2185
  const sp = span.span(row, 1, pos - line_start);
2186
+ // skip error line
2004
2187
  while (str.length > pos && str[pos] != '\n') {
2005
2188
  pos++;
2006
2189
  }
@@ -2015,7 +2198,9 @@ var $;
2015
2198
  }
2016
2199
  stack.length = indent + 1;
2017
2200
  var parent = stack[indent];
2201
+ // parse types
2018
2202
  while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
2203
+ // type can not contain space and tab
2019
2204
  var error_start = pos;
2020
2205
  while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
2021
2206
  pos++;
@@ -2027,6 +2212,7 @@ var $;
2027
2212
  const sp = span.span(row, error_start - line_start + 1, pos - error_start);
2028
2213
  this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
2029
2214
  }
2215
+ // read type
2030
2216
  var type_start = pos;
2031
2217
  while (str.length > pos &&
2032
2218
  str[pos] != '\\' &&
@@ -2041,10 +2227,12 @@ var $;
2041
2227
  parent_kids.push(next);
2042
2228
  parent = next;
2043
2229
  }
2230
+ // read one space if exists
2044
2231
  if (str.length > pos && str[pos] == ' ') {
2045
2232
  pos++;
2046
2233
  }
2047
2234
  }
2235
+ // read data
2048
2236
  if (str.length > pos && str[pos] == '\\') {
2049
2237
  var data_start = pos;
2050
2238
  while (str.length > pos && str[pos] != '\n') {
@@ -2055,6 +2243,7 @@ var $;
2055
2243
  parent_kids.push(next);
2056
2244
  parent = next;
2057
2245
  }
2246
+ // now must be end of text
2058
2247
  if (str.length === pos && stack.length > 0) {
2059
2248
  const sp = span.span(row, pos - line_start + 1, 1);
2060
2249
  this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
@@ -2147,6 +2336,7 @@ var $;
2147
2336
  "use strict";
2148
2337
  var $;
2149
2338
  (function ($) {
2339
+ /** Module for working with terminal. Text coloring when output in terminal */
2150
2340
  class $mol_term_color {
2151
2341
  static reset = this.ansi(0, 0);
2152
2342
  static bold = this.ansi(1, 22);
@@ -2218,6 +2408,7 @@ var $;
2218
2408
  "use strict";
2219
2409
  var $;
2220
2410
  (function ($) {
2411
+ /** One-shot fiber */
2221
2412
  class $mol_wire_task extends $mol_wire_fiber {
2222
2413
  static getter(task) {
2223
2414
  return function $mol_wire_task_get(host, args) {
@@ -2243,6 +2434,7 @@ var $;
2243
2434
  }
2244
2435
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
2245
2436
  const next = new $mol_wire_task(key, task, host, args);
2437
+ // Disabled because non-idempotency is required for try-catch
2246
2438
  if (existen?.temp) {
2247
2439
  $$.$mol_log3_warn({
2248
2440
  place: '$mol_wire_task',
@@ -2275,7 +2467,7 @@ var $;
2275
2467
  try {
2276
2468
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
2277
2469
  }
2278
- catch {
2470
+ catch { // Promises throw in strict mode
2279
2471
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2280
2472
  }
2281
2473
  }
@@ -2328,6 +2520,10 @@ var $;
2328
2520
  props[field] = get_val;
2329
2521
  return get_val;
2330
2522
  }
2523
+ /**
2524
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
2525
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
2526
+ */
2331
2527
  function $mol_wire_sync(obj) {
2332
2528
  return new Proxy(obj, {
2333
2529
  get(obj, field) {
@@ -2489,6 +2685,7 @@ var $;
2489
2685
  "use strict";
2490
2686
  var $;
2491
2687
  (function ($) {
2688
+ /** Derived debuggable error with stack */
2492
2689
  function $mol_crypto_restack(error) {
2493
2690
  error = new Error(error instanceof Error ? error.message : String(error), { cause: error });
2494
2691
  $mol_fail_hidden(error);
@@ -2500,7 +2697,9 @@ var $;
2500
2697
  "use strict";
2501
2698
  var $;
2502
2699
  (function ($) {
2700
+ /** Ed25519 public key for sign verifying. */
2503
2701
  class $mol_crypto2_auditor extends $mol_crypto2_key {
2702
+ /** Native WebAPI public key. */
2504
2703
  async native() {
2505
2704
  return $mol_crypto_native.subtle.importKey('jwk', {
2506
2705
  crv: "Ed25519",
@@ -2510,6 +2709,7 @@ var $;
2510
2709
  x: this.toString(),
2511
2710
  }, "Ed25519", Boolean('extractable'), ['verify']).catch($mol_crypto_restack);
2512
2711
  }
2712
+ /** Verifies signature of data. */
2513
2713
  async verify(data, sign) {
2514
2714
  return await $mol_crypto_native.subtle.verify("Ed25519", await this.native(), sign, data).catch($mol_crypto_restack);
2515
2715
  }
@@ -2524,13 +2724,16 @@ var $;
2524
2724
  "use strict";
2525
2725
  var $;
2526
2726
  (function ($) {
2727
+ /** Ed25519 private key for data signing. */
2527
2728
  class $mol_crypto2_signer extends $mol_crypto2_auditor {
2528
2729
  static size_sign = 64;
2730
+ /** Generates new Signer. */
2529
2731
  static async generate() {
2530
2732
  const pair = await $mol_crypto_native.subtle.generateKey("Ed25519", Boolean('extractable'), ['sign', 'verify']).catch($mol_crypto_restack);
2531
2733
  const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
2532
2734
  return this.from(x + d);
2533
2735
  }
2736
+ /** Native WebAPI private key. */
2534
2737
  async nativePrivate() {
2535
2738
  return await $mol_crypto_native.subtle.importKey('jwk', {
2536
2739
  crv: "Ed25519",
@@ -2541,15 +2744,19 @@ var $;
2541
2744
  d: this.toStringPrivate(),
2542
2745
  }, "Ed25519", Boolean('extractable'), ['sign']).catch($mol_crypto_restack);
2543
2746
  }
2747
+ /** Array view of private part. */
2544
2748
  asArrayPrivate() {
2545
2749
  return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
2546
2750
  }
2751
+ /** String representation of private part. */
2547
2752
  toStringPrivate() {
2548
2753
  return $mol_base64_url_encode(this.asArrayPrivate());
2549
2754
  }
2755
+ /** Returns Auditor from this Signer. */
2550
2756
  auditor() {
2551
2757
  return $mol_crypto2_auditor.from(this.asArray());
2552
2758
  }
2759
+ /** Makes Signature for data. */
2553
2760
  async sign(data) {
2554
2761
  return new Uint8Array(await $mol_crypto_native.subtle.sign("Ed25519", await this.nativePrivate(), data).catch($mol_crypto_restack));
2555
2762
  }
@@ -2570,7 +2777,9 @@ var $;
2570
2777
  "use strict";
2571
2778
  var $;
2572
2779
  (function ($) {
2780
+ /** x25519 public key for data encryption. */
2573
2781
  class $mol_crypto2_socket extends $mol_crypto2_key {
2782
+ /** Native WebAPI public key. */
2574
2783
  async native() {
2575
2784
  return await $mol_crypto_native.subtle.importKey('jwk', {
2576
2785
  crv: 'X25519',
@@ -2591,6 +2800,7 @@ var $;
2591
2800
  "use strict";
2592
2801
  var $;
2593
2802
  (function ($) {
2803
+ /** 16 unique bytes. */
2594
2804
  function $mol_crypto2_nonce() {
2595
2805
  return $mol_crypto_native.getRandomValues(new Uint8Array(16));
2596
2806
  }
@@ -2601,6 +2811,7 @@ var $;
2601
2811
  "use strict";
2602
2812
  var $;
2603
2813
  (function ($) {
2814
+ /** @deprecated Use $mol_crypto2_nonce */
2604
2815
  $.$mol_crypto_salt = $mol_crypto2_nonce;
2605
2816
  })($ || ($ = {}));
2606
2817
 
@@ -2608,11 +2819,15 @@ var $;
2608
2819
  "use strict";
2609
2820
  var $;
2610
2821
  (function ($) {
2822
+ /** Symmetric cipher with shortest payload. */
2611
2823
  class $mol_crypto_sacred extends $mol_buffer {
2824
+ /** Key size in bytes. */
2612
2825
  static size = 16;
2826
+ /** Makes new random secret. */
2613
2827
  static make() {
2614
2828
  return this.from($mol_crypto_salt());
2615
2829
  }
2830
+ /** Makes from string of buffer view. */
2616
2831
  static from(serial) {
2617
2832
  if (typeof serial === 'string') {
2618
2833
  serial = new Uint8Array([
@@ -2642,12 +2857,14 @@ var $;
2642
2857
  return $mol_base64_url_encode(this.asArray());
2643
2858
  }
2644
2859
  _native;
2860
+ /** Native crypto secret */
2645
2861
  async native() {
2646
2862
  return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
2647
2863
  name: 'AES-CBC',
2648
2864
  length: 128,
2649
2865
  }, true, ['encrypt', 'decrypt']).catch($mol_crypto_restack));
2650
2866
  }
2867
+ /** Encrypt any binary message. 16n bytes */
2651
2868
  async encrypt(open, salt) {
2652
2869
  return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
2653
2870
  name: 'AES-CBC',
@@ -2656,6 +2873,7 @@ var $;
2656
2873
  iv: salt,
2657
2874
  }, await this.native(), open).catch($mol_crypto_restack));
2658
2875
  }
2876
+ /** Decrypt any binary message. */
2659
2877
  async decrypt(closed, salt) {
2660
2878
  return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
2661
2879
  name: 'AES-CBC',
@@ -2664,12 +2882,14 @@ var $;
2664
2882
  iv: salt,
2665
2883
  }, await this.native(), closed).catch($mol_crypto_restack));
2666
2884
  }
2885
+ /** Encrypts 0xFF prefixed buffer. 16 bytes */
2667
2886
  async close(opened, salt) {
2668
2887
  if (opened.getUint8(0) !== 0xFF)
2669
2888
  throw new Error('Closable buffer should starts with 0xFF');
2670
2889
  const trimed = new Uint8Array(opened.buffer, opened.byteOffset + 1, opened.byteLength - 1);
2671
2890
  return this.encrypt(trimed, salt);
2672
2891
  }
2892
+ /** Decrypts 0xFF prefixed buffer. 16 bytes */
2673
2893
  async open(closed, salt) {
2674
2894
  const trimed = await this.decrypt(closed, salt);
2675
2895
  if (trimed.byteLength !== closed.byteLength - 1)
@@ -2690,13 +2910,16 @@ var $;
2690
2910
  "use strict";
2691
2911
  var $;
2692
2912
  (function ($) {
2913
+ /** x25519 private key for data encryption. */
2693
2914
  class $mol_crypto2_cipher extends $mol_crypto2_socket {
2694
2915
  static size_secret = 16;
2916
+ /** Generates new Cipher. */
2695
2917
  static async generate() {
2696
2918
  const pair = await $mol_crypto_native.subtle.generateKey("X25519", Boolean('extractable'), ['deriveKey']).catch($mol_crypto_restack);
2697
2919
  const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
2698
2920
  return this.from(x + d);
2699
2921
  }
2922
+ /** Native WebAPI private key. */
2700
2923
  async nativePrivate() {
2701
2924
  return $mol_crypto_native.subtle.importKey('jwk', {
2702
2925
  crv: 'X25519',
@@ -2707,15 +2930,19 @@ var $;
2707
2930
  d: this.toStringPrivate(),
2708
2931
  }, "X25519", Boolean('extractable'), ['deriveKey', 'deriveBits']).catch($mol_crypto_restack);
2709
2932
  }
2933
+ /** Array view of private part. */
2710
2934
  asArrayPrivate() {
2711
2935
  return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
2712
2936
  }
2937
+ /** String representation of private part. */
2713
2938
  toStringPrivate() {
2714
2939
  return $mol_base64_url_encode(this.asArrayPrivate());
2715
2940
  }
2941
+ /** Returns Socket from this Chipher. */
2716
2942
  socket() {
2717
2943
  return $mol_crypto2_socket.from(this.asArray());
2718
2944
  }
2945
+ /** Makes shared secret for combination of Chiper and Soacket. */
2719
2946
  async secret(pub) {
2720
2947
  return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
2721
2948
  name: "X25519",
@@ -2739,12 +2966,15 @@ var $;
2739
2966
  "use strict";
2740
2967
  var $;
2741
2968
  (function ($) {
2969
+ /** Compose public key for verifying and encryption, based on Curve25519. */
2742
2970
  class $mol_crypto2_public extends $mol_crypto2_key {
2743
2971
  static size_str = 86;
2744
2972
  static size_bin = 64;
2973
+ /** Return Auditor part. */
2745
2974
  auditor() {
2746
2975
  return $mol_crypto2_auditor.from(this.asArray().subarray(0, 32));
2747
2976
  }
2977
+ /** Return Socket part. */
2748
2978
  socket() {
2749
2979
  return $mol_crypto2_socket.from(this.asArray().subarray(32, 64));
2750
2980
  }
@@ -2768,7 +2998,9 @@ var $;
2768
2998
  "use strict";
2769
2999
  var $;
2770
3000
  (function ($) {
3001
+ /** Compose private key for signing and encryption, based on Curve25519. */
2771
3002
  class $mol_crypto2_private extends $mol_crypto2_public {
3003
+ /** Generates new private key. */
2772
3004
  static async generate() {
2773
3005
  const [signer, cipher] = await Promise.all([
2774
3006
  $mol_crypto2_signer.generate(),
@@ -2781,24 +3013,29 @@ var $;
2781
3013
  key.asArrayPrivate().set(cipher.asArrayPrivate(), 32);
2782
3014
  return key;
2783
3015
  }
3016
+ /** Return Signer part. */
2784
3017
  signer() {
2785
3018
  const signer = $mol_crypto2_signer.from($mol_crypto2_auditor.size_bin + $mol_crypto2_signer.size_bin);
2786
3019
  signer.asArray().set(this.asArray().subarray(0, 32));
2787
3020
  signer.asArrayPrivate().set(this.asArrayPrivate().subarray(0, 32));
2788
3021
  return signer;
2789
3022
  }
3023
+ /** Return Cipher part. */
2790
3024
  cipher() {
2791
3025
  const cipher = $mol_crypto2_cipher.from($mol_crypto2_socket.size_bin + $mol_crypto2_cipher.size_bin);
2792
3026
  cipher.asArray().set(this.asArray().subarray(32, 64));
2793
3027
  cipher.asArrayPrivate().set(this.asArrayPrivate().subarray(32, 64));
2794
3028
  return cipher;
2795
3029
  }
3030
+ /** Return Public part. */
2796
3031
  public() {
2797
3032
  return $mol_crypto2_public.from(this.asArray());
2798
3033
  }
3034
+ /** Array view of private part. */
2799
3035
  asArrayPrivate() {
2800
3036
  return new Uint8Array(this.buffer, this.byteOffset + 64, 64);
2801
3037
  }
3038
+ /** String representation of private part. */
2802
3039
  toStringPrivate() {
2803
3040
  return this.signer().toStringPrivate() + this.cipher().toStringPrivate();
2804
3041
  }