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/node.d.ts +129 -2
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +79 -1
- package/node.js.map +1 -1
- package/node.mjs +79 -1
- package/node.test.js +358 -14
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +129 -2
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +79 -1
- package/web.js.map +1 -1
- package/web.mjs +79 -1
- package/web.test.js +101 -5
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -109,6 +109,7 @@ var $;
|
|
|
109
109
|
])
|
|
110
110
|
].map(frame_normalize).join('\n')
|
|
111
111
|
});
|
|
112
|
+
// в nodejs, что б не дублировалось cause в консоли
|
|
112
113
|
Object.defineProperty(this, 'cause', {
|
|
113
114
|
get: () => cause
|
|
114
115
|
});
|
|
@@ -140,7 +141,7 @@ var $;
|
|
|
140
141
|
var $;
|
|
141
142
|
(function ($) {
|
|
142
143
|
function $mol_fail_hidden(error) {
|
|
143
|
-
throw error;
|
|
144
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
144
145
|
}
|
|
145
146
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
146
147
|
})($ || ($ = {}));
|
|
@@ -149,6 +150,10 @@ var $;
|
|
|
149
150
|
"use strict";
|
|
150
151
|
var $;
|
|
151
152
|
(function ($) {
|
|
153
|
+
/**
|
|
154
|
+
* Checks for array of given runtype and returns expected type.
|
|
155
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_array_demo
|
|
156
|
+
*/
|
|
152
157
|
function $mol_data_array(sub) {
|
|
153
158
|
return $mol_data_setup((val) => {
|
|
154
159
|
if (!Array.isArray(val))
|
|
@@ -173,6 +178,10 @@ var $;
|
|
|
173
178
|
"use strict";
|
|
174
179
|
var $;
|
|
175
180
|
(function ($) {
|
|
181
|
+
/**
|
|
182
|
+
* Checks for boolean and returns boolean type.
|
|
183
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_boolean_demo
|
|
184
|
+
*/
|
|
176
185
|
$.$mol_data_boolean = (val) => {
|
|
177
186
|
if (typeof val === 'boolean')
|
|
178
187
|
return val;
|
|
@@ -185,6 +194,10 @@ var $;
|
|
|
185
194
|
var $;
|
|
186
195
|
(function ($) {
|
|
187
196
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
197
|
+
/**
|
|
198
|
+
* Deeply compares two values. Returns true if equal.
|
|
199
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
200
|
+
*/
|
|
188
201
|
function $mol_compare_deep(left, right) {
|
|
189
202
|
if (Object.is(left, right))
|
|
190
203
|
return true;
|
|
@@ -324,6 +337,10 @@ var $;
|
|
|
324
337
|
"use strict";
|
|
325
338
|
var $;
|
|
326
339
|
(function ($) {
|
|
340
|
+
/**
|
|
341
|
+
* Checks for equality to given value and returns expected type.
|
|
342
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_const_demo
|
|
343
|
+
*/
|
|
327
344
|
function $mol_data_const(ref) {
|
|
328
345
|
return $mol_data_setup((val) => {
|
|
329
346
|
if ($mol_compare_deep(val, ref))
|
|
@@ -338,6 +355,10 @@ var $;
|
|
|
338
355
|
"use strict";
|
|
339
356
|
var $;
|
|
340
357
|
(function ($) {
|
|
358
|
+
/**
|
|
359
|
+
* Checks for string and returns string type.
|
|
360
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_string_demo
|
|
361
|
+
*/
|
|
341
362
|
$.$mol_data_string = (val) => {
|
|
342
363
|
if (typeof val === 'string')
|
|
343
364
|
return val;
|
|
@@ -349,6 +370,10 @@ var $;
|
|
|
349
370
|
"use strict";
|
|
350
371
|
var $;
|
|
351
372
|
(function ($) {
|
|
373
|
+
/**
|
|
374
|
+
* Checks for matching to given regular expression.
|
|
375
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_pattern_demo
|
|
376
|
+
*/
|
|
352
377
|
function $mol_data_pattern(pattern) {
|
|
353
378
|
return $mol_data_setup((val) => {
|
|
354
379
|
const val2 = $mol_data_string(val);
|
|
@@ -364,6 +389,10 @@ var $;
|
|
|
364
389
|
"use strict";
|
|
365
390
|
var $;
|
|
366
391
|
(function ($) {
|
|
392
|
+
/**
|
|
393
|
+
* Checks for E-Mail and returns string type.
|
|
394
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_email_demo
|
|
395
|
+
*/
|
|
367
396
|
$.$mol_data_email = $mol_data_pattern(/.+@.+/);
|
|
368
397
|
})($ || ($ = {}));
|
|
369
398
|
|
|
@@ -371,6 +400,10 @@ var $;
|
|
|
371
400
|
"use strict";
|
|
372
401
|
var $;
|
|
373
402
|
(function ($) {
|
|
403
|
+
/**
|
|
404
|
+
* Checks for value of given enum and returns expected type.
|
|
405
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_enum_demo
|
|
406
|
+
*/
|
|
374
407
|
function $mol_data_enum(name, dict) {
|
|
375
408
|
const index = {};
|
|
376
409
|
for (let key in dict) {
|
|
@@ -392,6 +425,10 @@ var $;
|
|
|
392
425
|
"use strict";
|
|
393
426
|
var $;
|
|
394
427
|
(function ($) {
|
|
428
|
+
/**
|
|
429
|
+
* Checks for instance of given class and returns narrowed type.
|
|
430
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_instance_demo
|
|
431
|
+
*/
|
|
395
432
|
function $mol_data_instance(Instance) {
|
|
396
433
|
return $mol_data_setup((val) => {
|
|
397
434
|
if (val instanceof Instance)
|
|
@@ -406,6 +443,10 @@ var $;
|
|
|
406
443
|
"use strict";
|
|
407
444
|
var $;
|
|
408
445
|
(function ($) {
|
|
446
|
+
/**
|
|
447
|
+
* Checks for number and returns number type.
|
|
448
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_number_demo
|
|
449
|
+
*/
|
|
409
450
|
$.$mol_data_number = (val) => {
|
|
410
451
|
if (typeof val === 'number')
|
|
411
452
|
return val;
|
|
@@ -417,6 +458,10 @@ var $;
|
|
|
417
458
|
"use strict";
|
|
418
459
|
var $;
|
|
419
460
|
(function ($) {
|
|
461
|
+
/**
|
|
462
|
+
* Checks for integer and returns number type.
|
|
463
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_integer_demo
|
|
464
|
+
*/
|
|
420
465
|
function $mol_data_integer(val) {
|
|
421
466
|
const val2 = $mol_data_number(val);
|
|
422
467
|
if (Math.floor(val2) === val2)
|
|
@@ -430,6 +475,10 @@ var $;
|
|
|
430
475
|
"use strict";
|
|
431
476
|
var $;
|
|
432
477
|
(function ($) {
|
|
478
|
+
/**
|
|
479
|
+
* Checks for include inside given range of values and returns expected type.
|
|
480
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_range_demo
|
|
481
|
+
*/
|
|
433
482
|
function $mol_data_range(from, to) {
|
|
434
483
|
return $mol_data_setup((val) => {
|
|
435
484
|
if (val > from && val < to)
|
|
@@ -444,6 +493,10 @@ var $;
|
|
|
444
493
|
"use strict";
|
|
445
494
|
var $;
|
|
446
495
|
(function ($) {
|
|
496
|
+
/**
|
|
497
|
+
* Checks for given runtype and returns tagged version of returned type.
|
|
498
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_tagged_demo
|
|
499
|
+
*/
|
|
447
500
|
function $mol_data_tagged(config) {
|
|
448
501
|
return config;
|
|
449
502
|
}
|
|
@@ -454,6 +507,10 @@ var $;
|
|
|
454
507
|
"use strict";
|
|
455
508
|
var $;
|
|
456
509
|
(function ($) {
|
|
510
|
+
/**
|
|
511
|
+
* Checks for null or passing given runtype.
|
|
512
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_nullable_demo
|
|
513
|
+
*/
|
|
457
514
|
function $mol_data_nullable(sub) {
|
|
458
515
|
return $mol_data_setup((val) => {
|
|
459
516
|
if (val === null)
|
|
@@ -468,6 +525,10 @@ var $;
|
|
|
468
525
|
"use strict";
|
|
469
526
|
var $;
|
|
470
527
|
(function ($) {
|
|
528
|
+
/**
|
|
529
|
+
* Checks for undefined or passing given runtype.
|
|
530
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_optional_demo
|
|
531
|
+
*/
|
|
471
532
|
function $mol_data_optional(sub, fallback) {
|
|
472
533
|
return $mol_data_setup((val) => {
|
|
473
534
|
if (val === undefined) {
|
|
@@ -495,6 +556,10 @@ var $;
|
|
|
495
556
|
"use strict";
|
|
496
557
|
var $;
|
|
497
558
|
(function ($) {
|
|
559
|
+
/**
|
|
560
|
+
* Checks for record of given fields with by its runtypes and returns expected type.
|
|
561
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_record_demo
|
|
562
|
+
*/
|
|
498
563
|
function $mol_data_record(sub) {
|
|
499
564
|
return $mol_data_setup((val) => {
|
|
500
565
|
let res = {};
|
|
@@ -520,6 +585,10 @@ var $;
|
|
|
520
585
|
"use strict";
|
|
521
586
|
var $;
|
|
522
587
|
(function ($) {
|
|
588
|
+
/**
|
|
589
|
+
* Checks for dictionary which maps strings to given runtype and returns expected type.
|
|
590
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_dict_demo
|
|
591
|
+
*/
|
|
523
592
|
function $mol_data_dict(sub) {
|
|
524
593
|
return $mol_data_setup((val) => {
|
|
525
594
|
if (Object.getPrototypeOf(val) !== Object.prototype) {
|
|
@@ -547,6 +616,10 @@ var $;
|
|
|
547
616
|
"use strict";
|
|
548
617
|
var $;
|
|
549
618
|
(function ($) {
|
|
619
|
+
/**
|
|
620
|
+
* Checks for some of given runtype or throws error.
|
|
621
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_variant_demo
|
|
622
|
+
*/
|
|
550
623
|
function $mol_data_variant(...sub) {
|
|
551
624
|
return $mol_data_setup((val) => {
|
|
552
625
|
const errors = [];
|
|
@@ -601,6 +674,11 @@ var $;
|
|
|
601
674
|
"use strict";
|
|
602
675
|
var $;
|
|
603
676
|
(function ($) {
|
|
677
|
+
/**
|
|
678
|
+
* Combines list of unary functions/classes to one function.
|
|
679
|
+
*
|
|
680
|
+
* const reparse = $mol_data_pipe( JSON.stringify , JSON.parse )
|
|
681
|
+
**/
|
|
604
682
|
function $mol_data_pipe(...funcs) {
|
|
605
683
|
return $mol_data_setup(function (input) {
|
|
606
684
|
let value = input;
|
|
@@ -737,7 +815,7 @@ var $;
|
|
|
737
815
|
"use strict";
|
|
738
816
|
var $;
|
|
739
817
|
(function ($) {
|
|
740
|
-
const mod = require('module');
|
|
818
|
+
const mod = require /****/('module');
|
|
741
819
|
const internals = mod.builtinModules;
|
|
742
820
|
function $node_internal_check(name) {
|
|
743
821
|
if (name.startsWith('node:'))
|
|
@@ -751,8 +829,8 @@ var $;
|
|
|
751
829
|
"use strict";
|
|
752
830
|
var $;
|
|
753
831
|
(function ($) {
|
|
754
|
-
const path = require('path');
|
|
755
|
-
const mod = require('module');
|
|
832
|
+
const path = require /****/('path');
|
|
833
|
+
const mod = require /****/('module');
|
|
756
834
|
const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
|
|
757
835
|
function $node_autoinstall(name) {
|
|
758
836
|
try {
|
|
@@ -979,6 +1057,9 @@ var $;
|
|
|
979
1057
|
[Symbol.dispose]() {
|
|
980
1058
|
this.destructor();
|
|
981
1059
|
}
|
|
1060
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
1061
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
1062
|
+
//}
|
|
982
1063
|
toString() {
|
|
983
1064
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
984
1065
|
}
|
|
@@ -1055,6 +1136,7 @@ var $;
|
|
|
1055
1136
|
"use strict";
|
|
1056
1137
|
var $;
|
|
1057
1138
|
(function ($) {
|
|
1139
|
+
/** Generates unique identifier. */
|
|
1058
1140
|
function $mol_guid(length = 8, exists = () => false) {
|
|
1059
1141
|
for (;;) {
|
|
1060
1142
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -1070,11 +1152,16 @@ var $;
|
|
|
1070
1152
|
"use strict";
|
|
1071
1153
|
var $;
|
|
1072
1154
|
(function ($) {
|
|
1155
|
+
/** Special status statuses. */
|
|
1073
1156
|
let $mol_wire_cursor;
|
|
1074
1157
|
(function ($mol_wire_cursor) {
|
|
1158
|
+
/** Update required. */
|
|
1075
1159
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
1160
|
+
/** Some of (transitive) pub update required. */
|
|
1076
1161
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
1162
|
+
/** Actual state but may be dropped. */
|
|
1077
1163
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
1164
|
+
/** State will never be changed. */
|
|
1078
1165
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
1079
1166
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
1080
1167
|
})($ || ($ = {}));
|
|
@@ -1083,6 +1170,9 @@ var $;
|
|
|
1083
1170
|
"use strict";
|
|
1084
1171
|
var $;
|
|
1085
1172
|
(function ($) {
|
|
1173
|
+
/**
|
|
1174
|
+
* Collects subscribers in compact array. 28B
|
|
1175
|
+
*/
|
|
1086
1176
|
class $mol_wire_pub extends Object {
|
|
1087
1177
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
1088
1178
|
super();
|
|
@@ -1090,10 +1180,17 @@ var $;
|
|
|
1090
1180
|
}
|
|
1091
1181
|
[Symbol.toStringTag];
|
|
1092
1182
|
data = [];
|
|
1183
|
+
// Derived objects should be Arrays.
|
|
1093
1184
|
static get [Symbol.species]() {
|
|
1094
1185
|
return Array;
|
|
1095
1186
|
}
|
|
1096
|
-
|
|
1187
|
+
/**
|
|
1188
|
+
* Index of first subscriber.
|
|
1189
|
+
*/
|
|
1190
|
+
sub_from = 0; // 4B
|
|
1191
|
+
/**
|
|
1192
|
+
* All current subscribers.
|
|
1193
|
+
*/
|
|
1097
1194
|
get sub_list() {
|
|
1098
1195
|
const res = [];
|
|
1099
1196
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -1101,14 +1198,23 @@ var $;
|
|
|
1101
1198
|
}
|
|
1102
1199
|
return res;
|
|
1103
1200
|
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Has any subscribers or not.
|
|
1203
|
+
*/
|
|
1104
1204
|
get sub_empty() {
|
|
1105
1205
|
return this.sub_from === this.data.length;
|
|
1106
1206
|
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
1209
|
+
*/
|
|
1107
1210
|
sub_on(sub, pub_pos) {
|
|
1108
1211
|
const pos = this.data.length;
|
|
1109
1212
|
this.data.push(sub, pub_pos);
|
|
1110
1213
|
return pos;
|
|
1111
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
1217
|
+
*/
|
|
1112
1218
|
sub_off(sub_pos) {
|
|
1113
1219
|
if (!(sub_pos < this.data.length)) {
|
|
1114
1220
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -1121,21 +1227,39 @@ var $;
|
|
|
1121
1227
|
if (end === this.sub_from)
|
|
1122
1228
|
this.reap();
|
|
1123
1229
|
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Called when last sub was unsubscribed.
|
|
1232
|
+
**/
|
|
1124
1233
|
reap() { }
|
|
1234
|
+
/**
|
|
1235
|
+
* Autowire this publisher with current subscriber.
|
|
1236
|
+
**/
|
|
1125
1237
|
promote() {
|
|
1126
1238
|
$mol_wire_auto()?.track_next(this);
|
|
1127
1239
|
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Enforce actualization. Should not throw errors.
|
|
1242
|
+
*/
|
|
1128
1243
|
fresh() { }
|
|
1244
|
+
/**
|
|
1245
|
+
* Allow to put data to caches in the subtree.
|
|
1246
|
+
*/
|
|
1129
1247
|
complete() { }
|
|
1130
1248
|
get incompleted() {
|
|
1131
1249
|
return false;
|
|
1132
1250
|
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Notify subscribers about self changes.
|
|
1253
|
+
*/
|
|
1133
1254
|
emit(quant = $mol_wire_cursor.stale) {
|
|
1134
1255
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
1135
1256
|
;
|
|
1136
1257
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
1137
1258
|
}
|
|
1138
1259
|
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
1262
|
+
*/
|
|
1139
1263
|
peer_move(from_pos, to_pos) {
|
|
1140
1264
|
const peer = this.data[from_pos];
|
|
1141
1265
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -1143,6 +1267,9 @@ var $;
|
|
|
1143
1267
|
this.data[to_pos + 1] = self_pos;
|
|
1144
1268
|
peer.peer_repos(self_pos, to_pos);
|
|
1145
1269
|
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Updates self position in the peer.
|
|
1272
|
+
*/
|
|
1146
1273
|
peer_repos(peer_pos, self_pos) {
|
|
1147
1274
|
this.data[peer_pos + 1] = self_pos;
|
|
1148
1275
|
}
|
|
@@ -1158,10 +1285,16 @@ var $;
|
|
|
1158
1285
|
var $;
|
|
1159
1286
|
(function ($) {
|
|
1160
1287
|
$.$mol_wire_auto_sub = null;
|
|
1288
|
+
/**
|
|
1289
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
1290
|
+
*/
|
|
1161
1291
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
1162
1292
|
return $.$mol_wire_auto_sub = next;
|
|
1163
1293
|
}
|
|
1164
1294
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
1295
|
+
/**
|
|
1296
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
1297
|
+
*/
|
|
1165
1298
|
$.$mol_wire_affected = [];
|
|
1166
1299
|
})($ || ($ = {}));
|
|
1167
1300
|
|
|
@@ -1169,6 +1302,7 @@ var $;
|
|
|
1169
1302
|
"use strict";
|
|
1170
1303
|
var $;
|
|
1171
1304
|
(function ($) {
|
|
1305
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
1172
1306
|
$['devtoolsFormatters'] ||= [];
|
|
1173
1307
|
function $mol_dev_format_register(config) {
|
|
1174
1308
|
$['devtoolsFormatters'].push(config);
|
|
@@ -1220,6 +1354,7 @@ var $;
|
|
|
1220
1354
|
return false;
|
|
1221
1355
|
if (!val)
|
|
1222
1356
|
return false;
|
|
1357
|
+
// if( Error.isError( val ) ) true
|
|
1223
1358
|
if (val[$.$mol_dev_format_body])
|
|
1224
1359
|
return true;
|
|
1225
1360
|
return false;
|
|
@@ -1237,12 +1372,16 @@ var $;
|
|
|
1237
1372
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
1238
1373
|
}
|
|
1239
1374
|
}
|
|
1375
|
+
// if( Error.isError( val ) ) {
|
|
1376
|
+
// return $mol_dev_format_native( val )
|
|
1377
|
+
// }
|
|
1240
1378
|
return null;
|
|
1241
1379
|
},
|
|
1242
1380
|
});
|
|
1243
1381
|
function $mol_dev_format_native(obj) {
|
|
1244
1382
|
if (typeof obj === 'undefined')
|
|
1245
1383
|
return $.$mol_dev_format_shade('undefined');
|
|
1384
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
1246
1385
|
return [
|
|
1247
1386
|
'object',
|
|
1248
1387
|
{
|
|
@@ -1300,6 +1439,9 @@ var $;
|
|
|
1300
1439
|
'margin-left': '13px'
|
|
1301
1440
|
});
|
|
1302
1441
|
class Stack extends Array {
|
|
1442
|
+
// [ Symbol.toPrimitive ]() {
|
|
1443
|
+
// return this.toString()
|
|
1444
|
+
// }
|
|
1303
1445
|
toString() {
|
|
1304
1446
|
return this.join('\n');
|
|
1305
1447
|
}
|
|
@@ -1322,6 +1464,7 @@ var $;
|
|
|
1322
1464
|
this.method = call.getMethodName() ?? '';
|
|
1323
1465
|
if (this.method === this.function)
|
|
1324
1466
|
this.method = '';
|
|
1467
|
+
// const func = c.getFunction()
|
|
1325
1468
|
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
1326
1469
|
this.eval = call.getEvalOrigin() ?? '';
|
|
1327
1470
|
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
@@ -1368,9 +1511,16 @@ var $;
|
|
|
1368
1511
|
"use strict";
|
|
1369
1512
|
var $;
|
|
1370
1513
|
(function ($) {
|
|
1514
|
+
/**
|
|
1515
|
+
* Publisher that can auto collect other publishers. 32B
|
|
1516
|
+
*
|
|
1517
|
+
* P1 P2 P3 P4 S1 S2 S3
|
|
1518
|
+
* ^ ^
|
|
1519
|
+
* pubs_from subs_from
|
|
1520
|
+
*/
|
|
1371
1521
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
1372
|
-
pub_from = 0;
|
|
1373
|
-
cursor = $mol_wire_cursor.stale;
|
|
1522
|
+
pub_from = 0; // 4B
|
|
1523
|
+
cursor = $mol_wire_cursor.stale; // 4B
|
|
1374
1524
|
get temp() {
|
|
1375
1525
|
return false;
|
|
1376
1526
|
}
|
|
@@ -1488,10 +1638,27 @@ var $;
|
|
|
1488
1638
|
return;
|
|
1489
1639
|
this.cursor = quant;
|
|
1490
1640
|
this.emit($mol_wire_cursor.doubt);
|
|
1641
|
+
// if( pos >= 0 && pos < this.sub_from - 2 ) {
|
|
1642
|
+
// const pub = this.data[ pos ] as $mol_wire_pub
|
|
1643
|
+
// if( pub instanceof $mol_wire_task ) return
|
|
1644
|
+
// for(
|
|
1645
|
+
// let cursor = this.pub_from;
|
|
1646
|
+
// cursor < this.sub_from;
|
|
1647
|
+
// cursor += 2
|
|
1648
|
+
// ) {
|
|
1649
|
+
// const pub = this.data[ cursor ] as $mol_wire_pub
|
|
1650
|
+
// if( pub instanceof $mol_wire_task ) {
|
|
1651
|
+
// pub.destructor()
|
|
1652
|
+
// }
|
|
1653
|
+
// }
|
|
1654
|
+
// }
|
|
1491
1655
|
}
|
|
1492
1656
|
[$mol_dev_format_head]() {
|
|
1493
1657
|
return $mol_dev_format_native(this);
|
|
1494
1658
|
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Is subscribed to any publisher or not.
|
|
1661
|
+
*/
|
|
1495
1662
|
get pub_empty() {
|
|
1496
1663
|
return this.sub_from === this.pub_from;
|
|
1497
1664
|
}
|
|
@@ -1561,6 +1728,7 @@ var $;
|
|
|
1561
1728
|
"use strict";
|
|
1562
1729
|
var $;
|
|
1563
1730
|
(function ($) {
|
|
1731
|
+
/// @todo right orderinng
|
|
1564
1732
|
$.$mol_after_mock_queue = [];
|
|
1565
1733
|
function $mol_after_mock_warp() {
|
|
1566
1734
|
const queue = $.$mol_after_mock_queue.splice(0);
|
|
@@ -1637,6 +1805,13 @@ var $;
|
|
|
1637
1805
|
var $;
|
|
1638
1806
|
(function ($) {
|
|
1639
1807
|
const wrappers = new WeakMap();
|
|
1808
|
+
/**
|
|
1809
|
+
* Suspendable task with support both sync/async api.
|
|
1810
|
+
*
|
|
1811
|
+
* A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
|
|
1812
|
+
* ^ ^ ^
|
|
1813
|
+
* args_from pubs_from subs_from
|
|
1814
|
+
**/
|
|
1640
1815
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
1641
1816
|
task;
|
|
1642
1817
|
host;
|
|
@@ -1657,6 +1832,7 @@ var $;
|
|
|
1657
1832
|
});
|
|
1658
1833
|
}
|
|
1659
1834
|
static sync() {
|
|
1835
|
+
// Sync whole fiber graph
|
|
1660
1836
|
while (this.planning.size) {
|
|
1661
1837
|
for (const fiber of this.planning) {
|
|
1662
1838
|
this.planning.delete(fiber);
|
|
@@ -1667,6 +1843,7 @@ var $;
|
|
|
1667
1843
|
fiber.fresh();
|
|
1668
1844
|
}
|
|
1669
1845
|
}
|
|
1846
|
+
// Collect garbage
|
|
1670
1847
|
while (this.reaping.size) {
|
|
1671
1848
|
const fibers = this.reaping;
|
|
1672
1849
|
this.reaping = new Set;
|
|
@@ -1818,6 +1995,10 @@ var $;
|
|
|
1818
1995
|
this.cursor = $mol_wire_cursor.stale;
|
|
1819
1996
|
this.fresh();
|
|
1820
1997
|
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
|
|
2000
|
+
* Should be called inside SuspenseAPI consumer (ie fiber).
|
|
2001
|
+
*/
|
|
1821
2002
|
sync() {
|
|
1822
2003
|
if (!$mol_wire_fiber.warm) {
|
|
1823
2004
|
return this.result();
|
|
@@ -1832,6 +2013,10 @@ var $;
|
|
|
1832
2013
|
}
|
|
1833
2014
|
return this.cache;
|
|
1834
2015
|
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Asynchronous execution.
|
|
2018
|
+
* It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
|
|
2019
|
+
*/
|
|
1835
2020
|
async async_raw() {
|
|
1836
2021
|
while (true) {
|
|
1837
2022
|
this.fresh();
|
|
@@ -1844,6 +2029,7 @@ var $;
|
|
|
1844
2029
|
if (!$mol_promise_like(this.cache))
|
|
1845
2030
|
return this.cache;
|
|
1846
2031
|
if (this.cursor === $mol_wire_cursor.final) {
|
|
2032
|
+
// never ends on destructed fiber
|
|
1847
2033
|
await new Promise(() => { });
|
|
1848
2034
|
}
|
|
1849
2035
|
}
|
|
@@ -1972,6 +2158,7 @@ var $;
|
|
|
1972
2158
|
"use strict";
|
|
1973
2159
|
var $;
|
|
1974
2160
|
(function ($) {
|
|
2161
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1975
2162
|
function $mol_log3_area_lazy(event) {
|
|
1976
2163
|
const self = this.$;
|
|
1977
2164
|
const stack = self.$mol_log3_stack;
|
|
@@ -1996,6 +2183,7 @@ var $;
|
|
|
1996
2183
|
"use strict";
|
|
1997
2184
|
var $;
|
|
1998
2185
|
(function ($) {
|
|
2186
|
+
/** Module for working with terminal. Text coloring when output in terminal */
|
|
1999
2187
|
class $mol_term_color {
|
|
2000
2188
|
static reset = this.ansi(0, 0);
|
|
2001
2189
|
static bold = this.ansi(1, 22);
|
|
@@ -2081,6 +2269,7 @@ var $;
|
|
|
2081
2269
|
"use strict";
|
|
2082
2270
|
var $;
|
|
2083
2271
|
(function ($) {
|
|
2272
|
+
/** One-shot fiber */
|
|
2084
2273
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
2085
2274
|
static getter(task) {
|
|
2086
2275
|
return function $mol_wire_task_get(host, args) {
|
|
@@ -2106,6 +2295,7 @@ var $;
|
|
|
2106
2295
|
}
|
|
2107
2296
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
2108
2297
|
const next = new $mol_wire_task(key, task, host, args);
|
|
2298
|
+
// Disabled because non-idempotency is required for try-catch
|
|
2109
2299
|
if (existen?.temp) {
|
|
2110
2300
|
$$.$mol_log3_warn({
|
|
2111
2301
|
place: '$mol_wire_task',
|
|
@@ -2138,7 +2328,7 @@ var $;
|
|
|
2138
2328
|
try {
|
|
2139
2329
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
2140
2330
|
}
|
|
2141
|
-
catch {
|
|
2331
|
+
catch { // Promises throw in strict mode
|
|
2142
2332
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
2143
2333
|
}
|
|
2144
2334
|
}
|
|
@@ -2163,6 +2353,9 @@ var $;
|
|
|
2163
2353
|
"use strict";
|
|
2164
2354
|
var $;
|
|
2165
2355
|
(function ($) {
|
|
2356
|
+
/**
|
|
2357
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber.
|
|
2358
|
+
*/
|
|
2166
2359
|
function $mol_wire_method(host, field, descr) {
|
|
2167
2360
|
if (!descr)
|
|
2168
2361
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2189,6 +2382,7 @@ var $;
|
|
|
2189
2382
|
"use strict";
|
|
2190
2383
|
var $;
|
|
2191
2384
|
(function ($) {
|
|
2385
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
2192
2386
|
function $mol_wire_async(obj) {
|
|
2193
2387
|
let fiber;
|
|
2194
2388
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -2300,6 +2494,10 @@ var $;
|
|
|
2300
2494
|
props[field] = get_val;
|
|
2301
2495
|
return get_val;
|
|
2302
2496
|
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
2499
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
2500
|
+
*/
|
|
2303
2501
|
function $mol_wire_sync(obj) {
|
|
2304
2502
|
return new Proxy(obj, {
|
|
2305
2503
|
get(obj, field) {
|
|
@@ -2801,6 +2999,12 @@ var $;
|
|
|
2801
2999
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
2802
3000
|
};
|
|
2803
3001
|
$.$mol_jsx_frag = '';
|
|
3002
|
+
/**
|
|
3003
|
+
* JSX adapter that makes DOM tree.
|
|
3004
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
3005
|
+
* Ensures all local ids are unique.
|
|
3006
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
3007
|
+
*/
|
|
2804
3008
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
2805
3009
|
const id = props && props.id || '';
|
|
2806
3010
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -2911,6 +3115,8 @@ var $;
|
|
|
2911
3115
|
|
|
2912
3116
|
;
|
|
2913
3117
|
"use strict";
|
|
3118
|
+
/** @jsx $mol_jsx */
|
|
3119
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
2914
3120
|
var $;
|
|
2915
3121
|
(function ($) {
|
|
2916
3122
|
$mol_test({
|
|
@@ -3016,6 +3222,7 @@ var $;
|
|
|
3016
3222
|
"use strict";
|
|
3017
3223
|
var $;
|
|
3018
3224
|
(function ($) {
|
|
3225
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
3019
3226
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
3020
3227
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
3021
3228
|
if (typeof item !== 'function') {
|
|
@@ -3064,6 +3271,7 @@ var $;
|
|
|
3064
3271
|
}
|
|
3065
3272
|
$.$mol_range2 = $mol_range2;
|
|
3066
3273
|
class $mol_range2_array extends Array {
|
|
3274
|
+
// Lazy
|
|
3067
3275
|
concat(...tail) {
|
|
3068
3276
|
if (tail.length === 0)
|
|
3069
3277
|
return this;
|
|
@@ -3075,6 +3283,7 @@ var $;
|
|
|
3075
3283
|
}
|
|
3076
3284
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
3077
3285
|
}
|
|
3286
|
+
// Lazy
|
|
3078
3287
|
filter(check, context) {
|
|
3079
3288
|
const filtered = [];
|
|
3080
3289
|
let cursor = -1;
|
|
@@ -3087,13 +3296,16 @@ var $;
|
|
|
3087
3296
|
return filtered[index];
|
|
3088
3297
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
3089
3298
|
}
|
|
3299
|
+
// Diligent
|
|
3090
3300
|
forEach(proceed, context) {
|
|
3091
3301
|
for (let [key, value] of this.entries())
|
|
3092
3302
|
proceed.call(context, value, key, this);
|
|
3093
3303
|
}
|
|
3304
|
+
// Lazy
|
|
3094
3305
|
map(proceed, context) {
|
|
3095
3306
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
3096
3307
|
}
|
|
3308
|
+
// Diligent
|
|
3097
3309
|
reduce(merge, result) {
|
|
3098
3310
|
let index = 0;
|
|
3099
3311
|
if (arguments.length === 1) {
|
|
@@ -3104,12 +3316,15 @@ var $;
|
|
|
3104
3316
|
}
|
|
3105
3317
|
return result;
|
|
3106
3318
|
}
|
|
3319
|
+
// Lazy
|
|
3107
3320
|
toReversed() {
|
|
3108
3321
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
3109
3322
|
}
|
|
3323
|
+
// Lazy
|
|
3110
3324
|
slice(from = 0, to = this.length) {
|
|
3111
3325
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
3112
3326
|
}
|
|
3327
|
+
// Lazy
|
|
3113
3328
|
some(check, context) {
|
|
3114
3329
|
for (let index = 0; index < this.length; ++index) {
|
|
3115
3330
|
if (check.call(context, this[index], index, this))
|
|
@@ -3302,6 +3517,7 @@ var $;
|
|
|
3302
3517
|
|
|
3303
3518
|
;
|
|
3304
3519
|
"use strict";
|
|
3520
|
+
/** @jsx $mol_jsx */
|
|
3305
3521
|
var $;
|
|
3306
3522
|
(function ($) {
|
|
3307
3523
|
$mol_test({
|
|
@@ -3363,6 +3579,7 @@ var $;
|
|
|
3363
3579
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
3364
3580
|
obj1.obj3 = obj3;
|
|
3365
3581
|
obj1_copy.obj3 = obj3_copy;
|
|
3582
|
+
// warmup cache
|
|
3366
3583
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
3367
3584
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
3368
3585
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -3432,18 +3649,34 @@ var $;
|
|
|
3432
3649
|
"use strict";
|
|
3433
3650
|
var $;
|
|
3434
3651
|
(function ($) {
|
|
3652
|
+
/**
|
|
3653
|
+
* Argument must be Truthy
|
|
3654
|
+
* @deprecated use $mol_assert_equal instead
|
|
3655
|
+
*/
|
|
3435
3656
|
function $mol_assert_ok(value) {
|
|
3436
3657
|
if (value)
|
|
3437
3658
|
return;
|
|
3438
3659
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
3439
3660
|
}
|
|
3440
3661
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
3662
|
+
/**
|
|
3663
|
+
* Argument must be Falsy
|
|
3664
|
+
* @deprecated use $mol_assert_equal instead
|
|
3665
|
+
*/
|
|
3441
3666
|
function $mol_assert_not(value) {
|
|
3442
3667
|
if (!value)
|
|
3443
3668
|
return;
|
|
3444
3669
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
3445
3670
|
}
|
|
3446
3671
|
$.$mol_assert_not = $mol_assert_not;
|
|
3672
|
+
/**
|
|
3673
|
+
* Handler must throw an error.
|
|
3674
|
+
* @example
|
|
3675
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
3676
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
3677
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
3678
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3679
|
+
*/
|
|
3447
3680
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
3448
3681
|
const fail = $.$mol_fail;
|
|
3449
3682
|
try {
|
|
@@ -3466,10 +3699,18 @@ var $;
|
|
|
3466
3699
|
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
3467
3700
|
}
|
|
3468
3701
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
3702
|
+
/** @deprecated Use $mol_assert_equal */
|
|
3469
3703
|
function $mol_assert_like(...args) {
|
|
3470
3704
|
$mol_assert_equal(...args);
|
|
3471
3705
|
}
|
|
3472
3706
|
$.$mol_assert_like = $mol_assert_like;
|
|
3707
|
+
/**
|
|
3708
|
+
* All arguments must not be structural equal to each other.
|
|
3709
|
+
* @example
|
|
3710
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
3711
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
3712
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3713
|
+
*/
|
|
3473
3714
|
function $mol_assert_unique(...args) {
|
|
3474
3715
|
for (let i = 0; i < args.length; ++i) {
|
|
3475
3716
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -3482,6 +3723,13 @@ var $;
|
|
|
3482
3723
|
}
|
|
3483
3724
|
}
|
|
3484
3725
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
3726
|
+
/**
|
|
3727
|
+
* All arguments must be structural equal each other.
|
|
3728
|
+
* @example
|
|
3729
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
3730
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
3731
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3732
|
+
*/
|
|
3485
3733
|
function $mol_assert_equal(...args) {
|
|
3486
3734
|
for (let i = 1; i < args.length; ++i) {
|
|
3487
3735
|
if ($mol_compare_deep(args[0], args[i]))
|
|
@@ -3535,6 +3783,11 @@ var $;
|
|
|
3535
3783
|
var $;
|
|
3536
3784
|
(function ($) {
|
|
3537
3785
|
const instances = new WeakSet();
|
|
3786
|
+
/**
|
|
3787
|
+
* Proxy that delegates all to lazy returned target.
|
|
3788
|
+
*
|
|
3789
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
3790
|
+
*/
|
|
3538
3791
|
function $mol_delegate(proto, target) {
|
|
3539
3792
|
const proxy = new Proxy(proto, {
|
|
3540
3793
|
get: (_, field) => {
|
|
@@ -3634,6 +3887,7 @@ var $;
|
|
|
3634
3887
|
"use strict";
|
|
3635
3888
|
var $;
|
|
3636
3889
|
(function ($) {
|
|
3890
|
+
/** Position in any resource. */
|
|
3637
3891
|
class $mol_span extends $mol_object2 {
|
|
3638
3892
|
uri;
|
|
3639
3893
|
source;
|
|
@@ -3649,13 +3903,17 @@ var $;
|
|
|
3649
3903
|
this.length = length;
|
|
3650
3904
|
this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
|
|
3651
3905
|
}
|
|
3906
|
+
/** Span for begin of unknown resource */
|
|
3652
3907
|
static unknown = $mol_span.begin('?');
|
|
3908
|
+
/** Makes new span for begin of resource. */
|
|
3653
3909
|
static begin(uri, source = '') {
|
|
3654
3910
|
return new $mol_span(uri, source, 1, 1, 0);
|
|
3655
3911
|
}
|
|
3912
|
+
/** Makes new span for end of resource. */
|
|
3656
3913
|
static end(uri, source) {
|
|
3657
3914
|
return new $mol_span(uri, source, 1, source.length + 1, 0);
|
|
3658
3915
|
}
|
|
3916
|
+
/** Makes new span for entire resource. */
|
|
3659
3917
|
static entire(uri, source) {
|
|
3660
3918
|
return new $mol_span(uri, source, 1, 1, source.length);
|
|
3661
3919
|
}
|
|
@@ -3670,15 +3928,19 @@ var $;
|
|
|
3670
3928
|
length: this.length
|
|
3671
3929
|
};
|
|
3672
3930
|
}
|
|
3931
|
+
/** Makes new error for this span. */
|
|
3673
3932
|
error(message, Class = Error) {
|
|
3674
3933
|
return new Class(`${message} (${this})`);
|
|
3675
3934
|
}
|
|
3935
|
+
/** Makes new span for same uri. */
|
|
3676
3936
|
span(row, col, length) {
|
|
3677
3937
|
return new $mol_span(this.uri, this.source, row, col, length);
|
|
3678
3938
|
}
|
|
3939
|
+
/** Makes new span after end of this. */
|
|
3679
3940
|
after(length = 0) {
|
|
3680
3941
|
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
3681
3942
|
}
|
|
3943
|
+
/** Makes new span between begin and end. */
|
|
3682
3944
|
slice(begin, end = -1) {
|
|
3683
3945
|
let len = this.length;
|
|
3684
3946
|
if (begin < 0)
|
|
@@ -3753,6 +4015,7 @@ var $;
|
|
|
3753
4015
|
"use strict";
|
|
3754
4016
|
var $;
|
|
3755
4017
|
(function ($) {
|
|
4018
|
+
/** Serializes tree to string in tree format. */
|
|
3756
4019
|
function $mol_tree2_to_string(tree) {
|
|
3757
4020
|
let output = [];
|
|
3758
4021
|
function dump(tree, prefix = '') {
|
|
@@ -3812,12 +4075,25 @@ var $;
|
|
|
3812
4075
|
"use strict";
|
|
3813
4076
|
var $;
|
|
3814
4077
|
(function ($) {
|
|
4078
|
+
/**
|
|
4079
|
+
* Abstract Syntax Tree with human readable serialization.
|
|
4080
|
+
* Avoid direct instantiation. Use static factories instead.
|
|
4081
|
+
* @see https://github.com/nin-jin/tree.d
|
|
4082
|
+
*/
|
|
3815
4083
|
class $mol_tree2 extends Object {
|
|
3816
4084
|
type;
|
|
3817
4085
|
value;
|
|
3818
4086
|
kids;
|
|
3819
4087
|
span;
|
|
3820
|
-
constructor(
|
|
4088
|
+
constructor(
|
|
4089
|
+
/** Type of structural node, `value` should be empty */
|
|
4090
|
+
type,
|
|
4091
|
+
/** Content of data node, `type` should be empty */
|
|
4092
|
+
value,
|
|
4093
|
+
/** Child nodes */
|
|
4094
|
+
kids,
|
|
4095
|
+
/** Position in most far source resource */
|
|
4096
|
+
span) {
|
|
3821
4097
|
super();
|
|
3822
4098
|
this.type = type;
|
|
3823
4099
|
this.value = value;
|
|
@@ -3825,12 +4101,15 @@ var $;
|
|
|
3825
4101
|
this.span = span;
|
|
3826
4102
|
this[Symbol.toStringTag] = type || '\\' + value;
|
|
3827
4103
|
}
|
|
4104
|
+
/** Makes collection node. */
|
|
3828
4105
|
static list(kids, span = $mol_span.unknown) {
|
|
3829
4106
|
return new $mol_tree2('', '', kids, span);
|
|
3830
4107
|
}
|
|
4108
|
+
/** Makes new derived collection node. */
|
|
3831
4109
|
list(kids) {
|
|
3832
4110
|
return $mol_tree2.list(kids, this.span);
|
|
3833
4111
|
}
|
|
4112
|
+
/** Makes data node for any string. */
|
|
3834
4113
|
static data(value, kids = [], span = $mol_span.unknown) {
|
|
3835
4114
|
const chunks = value.split('\n');
|
|
3836
4115
|
if (chunks.length > 1) {
|
|
@@ -3844,21 +4123,26 @@ var $;
|
|
|
3844
4123
|
}
|
|
3845
4124
|
return new $mol_tree2('', value, kids, span);
|
|
3846
4125
|
}
|
|
4126
|
+
/** Makes new derived data node. */
|
|
3847
4127
|
data(value, kids = []) {
|
|
3848
4128
|
return $mol_tree2.data(value, kids, this.span);
|
|
3849
4129
|
}
|
|
4130
|
+
/** Makes struct node. */
|
|
3850
4131
|
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
3851
4132
|
if (/[ \n\t\\]/.test(type)) {
|
|
3852
4133
|
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
3853
4134
|
}
|
|
3854
4135
|
return new $mol_tree2(type, '', kids, span);
|
|
3855
4136
|
}
|
|
4137
|
+
/** Makes new derived structural node. */
|
|
3856
4138
|
struct(type, kids = []) {
|
|
3857
4139
|
return $mol_tree2.struct(type, kids, this.span);
|
|
3858
4140
|
}
|
|
4141
|
+
/** Makes new derived node with different kids id defined. */
|
|
3859
4142
|
clone(kids, span = this.span) {
|
|
3860
4143
|
return new $mol_tree2(this.type, this.value, kids, span);
|
|
3861
4144
|
}
|
|
4145
|
+
/** Returns multiline text content. */
|
|
3862
4146
|
text() {
|
|
3863
4147
|
var values = [];
|
|
3864
4148
|
for (var kid of this.kids) {
|
|
@@ -3868,15 +4152,20 @@ var $;
|
|
|
3868
4152
|
}
|
|
3869
4153
|
return this.value + values.join('\n');
|
|
3870
4154
|
}
|
|
4155
|
+
/** Parses tree format. */
|
|
4156
|
+
/** @deprecated Use $mol_tree2_from_string */
|
|
3871
4157
|
static fromString(str, uri = 'unknown') {
|
|
3872
4158
|
return $$.$mol_tree2_from_string(str, uri);
|
|
3873
4159
|
}
|
|
4160
|
+
/** Serializes to tree format. */
|
|
3874
4161
|
toString() {
|
|
3875
4162
|
return $$.$mol_tree2_to_string(this);
|
|
3876
4163
|
}
|
|
4164
|
+
/** Makes new tree with node overrided by path. */
|
|
3877
4165
|
insert(value, ...path) {
|
|
3878
4166
|
return this.update($mol_maybe(value), ...path)[0];
|
|
3879
4167
|
}
|
|
4168
|
+
/** Makes new tree with node overrided by path. */
|
|
3880
4169
|
update(value, ...path) {
|
|
3881
4170
|
if (path.length === 0)
|
|
3882
4171
|
return value;
|
|
@@ -3909,6 +4198,7 @@ var $;
|
|
|
3909
4198
|
return [this.clone(kids)];
|
|
3910
4199
|
}
|
|
3911
4200
|
}
|
|
4201
|
+
/** Query nodes by path. */
|
|
3912
4202
|
select(...path) {
|
|
3913
4203
|
let next = [this];
|
|
3914
4204
|
for (const type of path) {
|
|
@@ -3935,6 +4225,7 @@ var $;
|
|
|
3935
4225
|
}
|
|
3936
4226
|
return this.list(next);
|
|
3937
4227
|
}
|
|
4228
|
+
/** Filter kids by path or value. */
|
|
3938
4229
|
filter(path, value) {
|
|
3939
4230
|
const sub = this.kids.filter(item => {
|
|
3940
4231
|
var found = item.select(...path);
|
|
@@ -3962,9 +4253,11 @@ var $;
|
|
|
3962
4253
|
$mol_fail_hidden(error);
|
|
3963
4254
|
}
|
|
3964
4255
|
}
|
|
4256
|
+
/** Transform tree through context with transformers */
|
|
3965
4257
|
hack(belt, context = {}) {
|
|
3966
4258
|
return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
|
|
3967
4259
|
}
|
|
4260
|
+
/** Makes Error with node coordinates. */
|
|
3968
4261
|
error(message, Class = Error) {
|
|
3969
4262
|
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
3970
4263
|
}
|
|
@@ -4120,6 +4413,7 @@ var $;
|
|
|
4120
4413
|
"use strict";
|
|
4121
4414
|
var $;
|
|
4122
4415
|
(function ($) {
|
|
4416
|
+
/** Syntax error with cordinates and source line snippet. */
|
|
4123
4417
|
class $mol_error_syntax extends SyntaxError {
|
|
4124
4418
|
reason;
|
|
4125
4419
|
line;
|
|
@@ -4138,6 +4432,7 @@ var $;
|
|
|
4138
4432
|
"use strict";
|
|
4139
4433
|
var $;
|
|
4140
4434
|
(function ($) {
|
|
4435
|
+
/** Parses tree format from string. */
|
|
4141
4436
|
function $mol_tree2_from_string(str, uri = '?') {
|
|
4142
4437
|
const span = $mol_span.entire(uri, str);
|
|
4143
4438
|
var root = $mol_tree2.list([], span);
|
|
@@ -4147,6 +4442,7 @@ var $;
|
|
|
4147
4442
|
var indent = 0;
|
|
4148
4443
|
var line_start = pos;
|
|
4149
4444
|
row++;
|
|
4445
|
+
// read indent
|
|
4150
4446
|
while (str.length > pos && str[pos] == '\t') {
|
|
4151
4447
|
indent++;
|
|
4152
4448
|
pos++;
|
|
@@ -4155,8 +4451,10 @@ var $;
|
|
|
4155
4451
|
min_indent = indent;
|
|
4156
4452
|
}
|
|
4157
4453
|
indent -= min_indent;
|
|
4454
|
+
// invalid tab size
|
|
4158
4455
|
if (indent < 0 || indent >= stack.length) {
|
|
4159
4456
|
const sp = span.span(row, 1, pos - line_start);
|
|
4457
|
+
// skip error line
|
|
4160
4458
|
while (str.length > pos && str[pos] != '\n') {
|
|
4161
4459
|
pos++;
|
|
4162
4460
|
}
|
|
@@ -4171,7 +4469,9 @@ var $;
|
|
|
4171
4469
|
}
|
|
4172
4470
|
stack.length = indent + 1;
|
|
4173
4471
|
var parent = stack[indent];
|
|
4472
|
+
// parse types
|
|
4174
4473
|
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
4474
|
+
// type can not contain space and tab
|
|
4175
4475
|
var error_start = pos;
|
|
4176
4476
|
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
4177
4477
|
pos++;
|
|
@@ -4183,6 +4483,7 @@ var $;
|
|
|
4183
4483
|
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
4184
4484
|
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
4185
4485
|
}
|
|
4486
|
+
// read type
|
|
4186
4487
|
var type_start = pos;
|
|
4187
4488
|
while (str.length > pos &&
|
|
4188
4489
|
str[pos] != '\\' &&
|
|
@@ -4197,10 +4498,12 @@ var $;
|
|
|
4197
4498
|
parent_kids.push(next);
|
|
4198
4499
|
parent = next;
|
|
4199
4500
|
}
|
|
4501
|
+
// read one space if exists
|
|
4200
4502
|
if (str.length > pos && str[pos] == ' ') {
|
|
4201
4503
|
pos++;
|
|
4202
4504
|
}
|
|
4203
4505
|
}
|
|
4506
|
+
// read data
|
|
4204
4507
|
if (str.length > pos && str[pos] == '\\') {
|
|
4205
4508
|
var data_start = pos;
|
|
4206
4509
|
while (str.length > pos && str[pos] != '\n') {
|
|
@@ -4211,6 +4514,7 @@ var $;
|
|
|
4211
4514
|
parent_kids.push(next);
|
|
4212
4515
|
parent = next;
|
|
4213
4516
|
}
|
|
4517
|
+
// now must be end of text
|
|
4214
4518
|
if (str.length === pos && stack.length > 0) {
|
|
4215
4519
|
const sp = span.span(row, pos - line_start + 1, 1);
|
|
4216
4520
|
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
@@ -4403,6 +4707,12 @@ var $;
|
|
|
4403
4707
|
'return result without errors'() {
|
|
4404
4708
|
$mol_assert_equal($mol_try(() => false), false);
|
|
4405
4709
|
},
|
|
4710
|
+
//'return error if thrown'() {
|
|
4711
|
+
//
|
|
4712
|
+
// const error = new Error( '$mol_try test error' )
|
|
4713
|
+
// $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
|
|
4714
|
+
//
|
|
4715
|
+
//} ,
|
|
4406
4716
|
});
|
|
4407
4717
|
})($ || ($ = {}));
|
|
4408
4718
|
|
|
@@ -4615,6 +4925,9 @@ var $;
|
|
|
4615
4925
|
gender["bisexual"] = "bisexual";
|
|
4616
4926
|
gender["trans"] = "transgender";
|
|
4617
4927
|
})(gender || (gender = {}));
|
|
4928
|
+
// Test disabled due https://github.com/microsoft/TypeScript/issues/46112
|
|
4929
|
+
// const Sex = $mol_data_enum( 'sex' , sex )
|
|
4930
|
+
// type sex_value = $mol_type_assert< typeof Sex.Value , sex >
|
|
4618
4931
|
$mol_test({
|
|
4619
4932
|
'config of enum'() {
|
|
4620
4933
|
const Sex = $mol_data_enum('sex', sex);
|
|
@@ -4644,6 +4957,8 @@ var $;
|
|
|
4644
4957
|
$mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
|
|
4645
4958
|
},
|
|
4646
4959
|
});
|
|
4960
|
+
// Test disabled due https://github.com/microsoft/TypeScript/issues/46112
|
|
4961
|
+
// type gender_value = $mol_type_assert< typeof Gender.Value , gender >
|
|
4647
4962
|
$mol_test({
|
|
4648
4963
|
'config of enum'() {
|
|
4649
4964
|
const Gender = $mol_data_enum('gender', gender);
|
|
@@ -4759,11 +5074,14 @@ var $;
|
|
|
4759
5074
|
Weight: $mol_data_integer,
|
|
4760
5075
|
Length: $mol_data_integer,
|
|
4761
5076
|
});
|
|
4762
|
-
Length(20);
|
|
4763
|
-
let len = Length(10);
|
|
4764
|
-
len = 20;
|
|
4765
|
-
let num = len;
|
|
4766
|
-
len = Length(Weight(20));
|
|
5077
|
+
Length(20); // Validate
|
|
5078
|
+
let len = Length(10); // Inferred type
|
|
5079
|
+
len = 20; // Explicit type
|
|
5080
|
+
let num = len; // Implicit cast
|
|
5081
|
+
len = Length(Weight(20)); // Explicit cast
|
|
5082
|
+
// len = 20 // Compile time error
|
|
5083
|
+
// len = Weight( 20 ) // Compile time error
|
|
5084
|
+
// len = Length( 20.1 ) // Run time error
|
|
4767
5085
|
},
|
|
4768
5086
|
});
|
|
4769
5087
|
})($ || ($ = {}));
|
|
@@ -4816,6 +5134,9 @@ var $;
|
|
|
4816
5134
|
;
|
|
4817
5135
|
"use strict";
|
|
4818
5136
|
|
|
5137
|
+
;
|
|
5138
|
+
"use strict";
|
|
5139
|
+
|
|
4819
5140
|
;
|
|
4820
5141
|
"use strict";
|
|
4821
5142
|
var $;
|
|
@@ -4829,6 +5150,21 @@ var $;
|
|
|
4829
5150
|
const User = $mol_data_record({ age: $mol_data_number });
|
|
4830
5151
|
User({ age: 0, name: 'Jin' });
|
|
4831
5152
|
},
|
|
5153
|
+
// 'Recursive record' () {
|
|
5154
|
+
// const User = $mol_data_record({
|
|
5155
|
+
// name : $mol_data_string ,
|
|
5156
|
+
// get kids() { return $mol_data_array( User ) } ,
|
|
5157
|
+
// })
|
|
5158
|
+
// User({
|
|
5159
|
+
// name : 'Jin' ,
|
|
5160
|
+
// kids : [
|
|
5161
|
+
// {
|
|
5162
|
+
// name : 'John' ,
|
|
5163
|
+
// kids : [] ,
|
|
5164
|
+
// }
|
|
5165
|
+
// ] ,
|
|
5166
|
+
// })
|
|
5167
|
+
// } ,
|
|
4832
5168
|
'Shrinks record'() {
|
|
4833
5169
|
$mol_assert_fail(() => {
|
|
4834
5170
|
const User = $mol_data_record({ age: $mol_data_number, name: $mol_data_string });
|
|
@@ -4937,6 +5273,14 @@ var $;
|
|
|
4937
5273
|
var $;
|
|
4938
5274
|
(function ($) {
|
|
4939
5275
|
$mol_test({
|
|
5276
|
+
// @todo enable on strict
|
|
5277
|
+
// 'no functions'() {
|
|
5278
|
+
// const stringify = $mol_data_pipe()
|
|
5279
|
+
// type Type = $mol_type_assert<
|
|
5280
|
+
// typeof stringify,
|
|
5281
|
+
// ( input : never )=> never
|
|
5282
|
+
// >
|
|
5283
|
+
// },
|
|
4940
5284
|
'single function'() {
|
|
4941
5285
|
const stringify = $mol_data_pipe((input) => input.toString());
|
|
4942
5286
|
$mol_assert_equal(stringify(5), '5');
|