mol_schema 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.test.js CHANGED
@@ -201,6 +201,241 @@ var $;
201
201
  $.$mol_schema_string = $mol_schema_string;
202
202
  })($ || ($ = {}));
203
203
 
204
+ ;
205
+ "use strict";
206
+ var $;
207
+ (function ($) {
208
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
209
+ function $mol_ambient(overrides) {
210
+ return Object.setPrototypeOf(overrides, this || $);
211
+ }
212
+ $.$mol_ambient = $mol_ambient;
213
+ })($ || ($ = {}));
214
+
215
+ ;
216
+ "use strict";
217
+ var $;
218
+ (function ($) {
219
+ const instances = new WeakSet();
220
+ /**
221
+ * Proxy that delegates all to lazy returned target.
222
+ *
223
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
224
+ */
225
+ function $mol_delegate(proto, target) {
226
+ const proxy = new Proxy(proto, {
227
+ get: (_, field) => {
228
+ const obj = target();
229
+ let val = Reflect.get(obj, field);
230
+ if (typeof val === 'function') {
231
+ val = val.bind(obj);
232
+ }
233
+ return val;
234
+ },
235
+ has: (_, field) => Reflect.has(target(), field),
236
+ set: (_, field, value) => Reflect.set(target(), field, value),
237
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
238
+ ownKeys: () => Reflect.ownKeys(target()),
239
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
240
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
241
+ isExtensible: () => Reflect.isExtensible(target()),
242
+ preventExtensions: () => Reflect.preventExtensions(target()),
243
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
244
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
245
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
246
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
247
+ });
248
+ instances.add(proxy);
249
+ return proxy;
250
+ }
251
+ $.$mol_delegate = $mol_delegate;
252
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
253
+ value: (obj) => instances.has(obj),
254
+ });
255
+ })($ || ($ = {}));
256
+
257
+ ;
258
+ "use strict";
259
+ var $;
260
+ (function ($) {
261
+ $.$mol_owning_map = new WeakMap();
262
+ function $mol_owning_allow(having) {
263
+ try {
264
+ if (!having)
265
+ return false;
266
+ if (typeof having !== 'object' && typeof having !== 'function')
267
+ return false;
268
+ if (having instanceof $mol_delegate)
269
+ return false;
270
+ if (typeof having['destructor'] !== 'function')
271
+ return false;
272
+ return true;
273
+ }
274
+ catch {
275
+ return false;
276
+ }
277
+ }
278
+ $.$mol_owning_allow = $mol_owning_allow;
279
+ function $mol_owning_get(having, Owner) {
280
+ if (!$mol_owning_allow(having))
281
+ return null;
282
+ while (true) {
283
+ const owner = $.$mol_owning_map.get(having);
284
+ if (!owner)
285
+ return owner;
286
+ if (!Owner)
287
+ return owner;
288
+ if (owner instanceof Owner)
289
+ return owner;
290
+ having = owner;
291
+ }
292
+ }
293
+ $.$mol_owning_get = $mol_owning_get;
294
+ function $mol_owning_check(owner, having) {
295
+ if (!$mol_owning_allow(having))
296
+ return false;
297
+ if ($.$mol_owning_map.get(having) !== owner)
298
+ return false;
299
+ return true;
300
+ }
301
+ $.$mol_owning_check = $mol_owning_check;
302
+ function $mol_owning_catch(owner, having) {
303
+ if (!$mol_owning_allow(having))
304
+ return false;
305
+ if ($.$mol_owning_map.get(having))
306
+ return false;
307
+ $.$mol_owning_map.set(having, owner);
308
+ return true;
309
+ }
310
+ $.$mol_owning_catch = $mol_owning_catch;
311
+ })($ || ($ = {}));
312
+
313
+ ;
314
+ "use strict";
315
+ var $;
316
+ (function ($) {
317
+ function $mol_fail_hidden(error) {
318
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
319
+ }
320
+ $.$mol_fail_hidden = $mol_fail_hidden;
321
+ })($ || ($ = {}));
322
+
323
+ ;
324
+ "use strict";
325
+
326
+ ;
327
+ "use strict";
328
+ var $;
329
+ (function ($) {
330
+ if (!Symbol.dispose)
331
+ Symbol.dispose = Symbol('Symbol.dispose');
332
+ class $mol_object2 {
333
+ static $ = $;
334
+ [Symbol.toStringTag];
335
+ [$mol_ambient_ref] = null;
336
+ get $() {
337
+ if (this[$mol_ambient_ref])
338
+ return this[$mol_ambient_ref];
339
+ const owner = $mol_owning_get(this);
340
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
341
+ }
342
+ set $(next) {
343
+ if (this[$mol_ambient_ref])
344
+ $mol_fail_hidden(new Error('Context already defined'));
345
+ this[$mol_ambient_ref] = next;
346
+ }
347
+ static create(init) {
348
+ const obj = new this;
349
+ if (init)
350
+ init(obj);
351
+ return obj;
352
+ }
353
+ static [Symbol.toPrimitive]() {
354
+ return this.toString();
355
+ }
356
+ static toString() {
357
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
358
+ }
359
+ static toJSON() {
360
+ return this.toString();
361
+ }
362
+ static [$mol_key_handle]() {
363
+ return this.toString();
364
+ }
365
+ destructor() { }
366
+ static destructor() { }
367
+ [Symbol.dispose]() {
368
+ this.destructor();
369
+ }
370
+ //[ Symbol.toPrimitive ]( hint: string ) {
371
+ // return hint === 'number' ? this.valueOf() : this.toString()
372
+ //}
373
+ toString() {
374
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
375
+ }
376
+ }
377
+ $.$mol_object2 = $mol_object2;
378
+ })($ || ($ = {}));
379
+
380
+ ;
381
+ "use strict";
382
+ var $;
383
+ (function ($) {
384
+ class $mol_wrapper extends $mol_object2 {
385
+ static wrap;
386
+ static run(task) {
387
+ return this.func(task)();
388
+ }
389
+ static func(func) {
390
+ return this.wrap(func);
391
+ }
392
+ static get class() {
393
+ return (Class) => {
394
+ const construct = (target, args) => new Class(...args);
395
+ const handler = {
396
+ construct: this.func(construct)
397
+ };
398
+ handler[Symbol.toStringTag] = Class.name + '#';
399
+ return new Proxy(Class, handler);
400
+ };
401
+ }
402
+ static get method() {
403
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
404
+ descr.value = this.func(descr.value);
405
+ return descr;
406
+ };
407
+ }
408
+ static get field() {
409
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
410
+ descr.get = descr.set = this.func(descr.get);
411
+ return descr;
412
+ };
413
+ }
414
+ }
415
+ $.$mol_wrapper = $mol_wrapper;
416
+ })($ || ($ = {}));
417
+
418
+ ;
419
+ "use strict";
420
+ var $;
421
+ (function ($) {
422
+ class $mol_memo extends $mol_wrapper {
423
+ static wrap(task) {
424
+ const store = new WeakMap();
425
+ const fun = function (next) {
426
+ if (next === undefined && store.has(this ?? fun))
427
+ return store.get(this ?? fun);
428
+ const val = task.call(this, next) ?? next;
429
+ store.set(this ?? fun, val);
430
+ return val;
431
+ };
432
+ Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
433
+ return fun;
434
+ }
435
+ }
436
+ $.$mol_memo = $mol_memo;
437
+ })($ || ($ = {}));
438
+
204
439
  ;
205
440
  "use strict";
206
441
  var $;
@@ -274,7 +509,32 @@ var $;
274
509
  "use strict";
275
510
  var $;
276
511
  (function ($) {
277
- function $mol_schema_pattern(Pattern) {
512
+ class $mol_memo_key extends $mol_wrapper {
513
+ static wrap(task) {
514
+ const store = new WeakMap();
515
+ const fun = function (key, next) {
516
+ let store2 = store.get(this ?? fun);
517
+ if (!store2)
518
+ store.set(this ?? fun, store2 = new Map);
519
+ const key_str = $mol_key(key);
520
+ if (next === undefined && store2.has(key_str))
521
+ return store2.get(key_str);
522
+ const val = task.call(this, key, next) ?? next;
523
+ store2.set(key_str, val);
524
+ return val;
525
+ };
526
+ Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
527
+ return fun;
528
+ }
529
+ }
530
+ $.$mol_memo_key = $mol_memo_key;
531
+ })($ || ($ = {}));
532
+
533
+ ;
534
+ "use strict";
535
+ var $;
536
+ (function ($) {
537
+ $.$mol_schema_pattern = $mol_memo_key.func(function $mol_schema_pattern(Pattern) {
278
538
  return class $mol_schema_pattern_ extends $mol_schema_string {
279
539
  static Pattern = Pattern;
280
540
  static toString() {
@@ -292,15 +552,14 @@ var $;
292
552
  }
293
553
  static default = '';
294
554
  };
295
- }
296
- $.$mol_schema_pattern = $mol_schema_pattern;
555
+ });
297
556
  })($ || ($ = {}));
298
557
 
299
558
  ;
300
559
  "use strict";
301
560
  var $;
302
561
  (function ($) {
303
- function $mol_schema_instance(Class, ...args) {
562
+ $.$mol_schema_instance = $mol_memo_key.func(function $mol_schema_instance(Class, ...args) {
304
563
  class $mol_schema_instance_ extends $mol_schema_any {
305
564
  static Class = Class;
306
565
  static toString() {
@@ -318,8 +577,7 @@ var $;
318
577
  return ((Class[Symbol.hasInstance] === $mol_schema_any[Symbol.hasInstance])
319
578
  ? Class
320
579
  : $mol_schema_instance_);
321
- }
322
- $.$mol_schema_instance = $mol_schema_instance;
580
+ });
323
581
  })($ || ($ = {}));
324
582
 
325
583
  ;
@@ -329,7 +587,7 @@ var $;
329
587
  "use strict";
330
588
  var $;
331
589
  (function ($) {
332
- function $mol_schema_every(Schemas) {
590
+ $.$mol_schema_every = $mol_memo_key.func(function $mol_schema_every(Schemas) {
333
591
  return class $mol_schema_every_ extends $mol_schema_any {
334
592
  static Schemas = Schemas;
335
593
  static toString() {
@@ -350,50 +608,47 @@ var $;
350
608
  }
351
609
  static default = Schemas.find(Scheme => this.check(Scheme.default));
352
610
  };
353
- }
354
- $.$mol_schema_every = $mol_schema_every;
611
+ });
355
612
  })($ || ($ = {}));
356
613
 
357
614
  ;
358
615
  "use strict";
359
616
  var $;
360
617
  (function ($) {
361
- function $mol_schema_range(Min, Max) {
618
+ $.$mol_schema_range = $mol_memo_key.func(function $mol_schema_range(Range) {
362
619
  return class $mol_schema_range_ extends $mol_schema_any {
363
- static Min = Min;
364
- static Max = Max;
620
+ static Range = Range;
365
621
  static toString() {
366
622
  if (this !== $mol_schema_range_)
367
623
  return super.toString();
368
- return '$mol_schema_range<' + $mol_key(Min) + ',' + $mol_key(Max) + '>';
624
+ return '$mol_schema_range<' + $mol_key(Range) + '>';
369
625
  }
370
626
  static guard(value) {
371
627
  if (typeof value !== 'number' && typeof value !== 'bigint')
372
628
  return $mol_fail(new TypeError('Uncomparable type', { cause: { value, schema: this } }));
373
- if (!(value <= Max))
629
+ if (!(value <= Range[1]))
374
630
  return $mol_fail(new TypeError('Too large', { cause: { value, schema: this } }));
375
- if (!(value >= Min))
631
+ if (!(value >= Range[0]))
376
632
  return $mol_fail(new TypeError('Too small', { cause: { value, schema: this } }));
377
633
  return value;
378
634
  }
379
635
  static cast(val) {
380
- if (val > Max)
381
- return Max;
382
- if (val >= Min)
636
+ if (val > Range[1])
637
+ return Range[1];
638
+ if (val >= Range[0])
383
639
  return val;
384
- return Min;
640
+ return Range[0];
385
641
  }
386
- static default = Min;
642
+ static default = Range[0];
387
643
  };
388
- }
389
- $.$mol_schema_range = $mol_schema_range;
644
+ });
390
645
  })($ || ($ = {}));
391
646
 
392
647
  ;
393
648
  "use strict";
394
649
  var $;
395
650
  (function ($) {
396
- class $mol_schema_positive extends $mol_schema_range(0, Number.POSITIVE_INFINITY) {
651
+ class $mol_schema_positive extends $mol_schema_range([0, Number.POSITIVE_INFINITY]) {
397
652
  }
398
653
  $.$mol_schema_positive = $mol_schema_positive;
399
654
  })($ || ($ = {}));
@@ -414,7 +669,7 @@ var $;
414
669
  "use strict";
415
670
  var $;
416
671
  (function ($) {
417
- function $mol_schema_enum(Options) {
672
+ $.$mol_schema_enum = $mol_memo_key.func(function $mol_schema_enum(Options) {
418
673
  return class $mol_schema_enum_ extends $mol_schema_any {
419
674
  static Options = Options;
420
675
  static toString() {
@@ -434,15 +689,14 @@ var $;
434
689
  }
435
690
  static default = Options[0];
436
691
  };
437
- }
438
- $.$mol_schema_enum = $mol_schema_enum;
692
+ });
439
693
  })($ || ($ = {}));
440
694
 
441
695
  ;
442
696
  "use strict";
443
697
  var $;
444
698
  (function ($) {
445
- class $mol_schema_negative extends $mol_schema_range(Number.NEGATIVE_INFINITY, 0) {
699
+ class $mol_schema_negative extends $mol_schema_range([Number.NEGATIVE_INFINITY, 0]) {
446
700
  }
447
701
  $.$mol_schema_negative = $mol_schema_negative;
448
702
  })($ || ($ = {}));
@@ -451,7 +705,7 @@ var $;
451
705
  "use strict";
452
706
  var $;
453
707
  (function ($) {
454
- function $mol_schema_some(Variants) {
708
+ $.$mol_schema_some = $mol_memo_key.func(function $mol_schema_some(Variants) {
455
709
  return class $mol_schema_some_ extends $mol_schema_any {
456
710
  static Variants = Variants;
457
711
  static toString() {
@@ -481,15 +735,14 @@ var $;
481
735
  }
482
736
  static default = Variants[0].default;
483
737
  };
484
- }
485
- $.$mol_schema_some = $mol_schema_some;
738
+ });
486
739
  })($ || ($ = {}));
487
740
 
488
741
  ;
489
742
  "use strict";
490
743
  var $;
491
744
  (function ($) {
492
- function $mol_schema_maybe(Some) {
745
+ $.$mol_schema_maybe = $mol_memo_key.func(function $mol_schema_maybe(Some) {
493
746
  return class $mol_schema_maybe_ extends $mol_schema_some([$mol_schema_enum([undefined, null]), Some]) {
494
747
  static Some = Some;
495
748
  static toString() {
@@ -498,15 +751,14 @@ var $;
498
751
  return '$mol_schema_maybe<' + $mol_key(Some) + '>';
499
752
  }
500
753
  };
501
- }
502
- $.$mol_schema_maybe = $mol_schema_maybe;
754
+ });
503
755
  })($ || ($ = {}));
504
756
 
505
757
  ;
506
758
  "use strict";
507
759
  var $;
508
760
  (function ($) {
509
- function $mol_schema_list(Item) {
761
+ $.$mol_schema_list = $mol_memo_key.func(function $mol_schema_list(Item) {
510
762
  return class $mol_schema_list_ extends $mol_schema_any {
511
763
  static Item = Item;
512
764
  static toString() {
@@ -534,22 +786,20 @@ var $;
534
786
  }
535
787
  static default = [];
536
788
  };
537
- }
538
- $.$mol_schema_list = $mol_schema_list;
789
+ });
539
790
  })($ || ($ = {}));
540
791
 
541
792
  ;
542
793
  "use strict";
543
794
  var $;
544
795
  (function ($) {
545
- function $mol_schema_dict(Key, Val) {
796
+ $.$mol_schema_dict = $mol_memo_key.func(function $mol_schema_dict(Pair) {
546
797
  return class $mol_schema_dict_ extends $mol_schema_any {
547
- static Key = Key;
548
- static Val = Val;
798
+ static Pair = Pair;
549
799
  static toString() {
550
800
  if (this !== $mol_schema_dict_)
551
801
  return super.toString();
552
- return '$mol_schema_dict<' + $mol_key(Key) + ',' + $mol_key(Key) + '>';
802
+ return '$mol_schema_dict<' + $mol_key(Pair) + '>';
553
803
  }
554
804
  static guard(value) {
555
805
  if (Object.getPrototypeOf(Object.getPrototypeOf(value))) {
@@ -557,13 +807,13 @@ var $;
557
807
  }
558
808
  for (const key in value) {
559
809
  try {
560
- Key.guard(key);
810
+ Pair[0].guard(key);
561
811
  }
562
812
  catch (error) {
563
813
  return $mol_fail(new TypeError('Wrong key', { cause: { key, error, value, schema: this } }));
564
814
  }
565
815
  try {
566
- Val.guard(value[key]);
816
+ Pair[1].guard(value[key]);
567
817
  }
568
818
  catch (error) {
569
819
  return $mol_fail(new TypeError('Wrong val', { cause: { key, error, value, schema: this } }));
@@ -576,23 +826,22 @@ var $;
576
826
  return this.default;
577
827
  const res = {};
578
828
  for (const key in value) {
579
- if (!Key.check(key))
829
+ if (!Pair[0].check(key))
580
830
  continue;
581
- res[key] = Val.cast(value[key]);
831
+ res[key] = Pair[1].cast(value[key]);
582
832
  }
583
833
  return res;
584
834
  }
585
835
  static default = {};
586
836
  };
587
- }
588
- $.$mol_schema_dict = $mol_schema_dict;
837
+ });
589
838
  })($ || ($ = {}));
590
839
 
591
840
  ;
592
841
  "use strict";
593
842
  var $;
594
843
  (function ($) {
595
- function $mol_schema_record(Fields) {
844
+ $.$mol_schema_record = $mol_memo_key.func(function $mol_schema_record(Fields) {
596
845
  return class $mol_schema_record_ extends $mol_schema_any {
597
846
  static Fields = Fields;
598
847
  static toString() {
@@ -624,8 +873,7 @@ var $;
624
873
  }
625
874
  static default = Object.fromEntries(Object.entries(Fields).map(([field, Field]) => [field, Field.default]));
626
875
  };
627
- }
628
- $.$mol_schema_record = $mol_schema_record;
876
+ });
629
877
  })($ || ($ = {}));
630
878
 
631
879
  ;
@@ -663,16 +911,6 @@ var $;
663
911
  $.$mol_promise_like = $mol_promise_like;
664
912
  })($ || ($ = {}));
665
913
 
666
- ;
667
- "use strict";
668
- var $;
669
- (function ($) {
670
- function $mol_fail_hidden(error) {
671
- throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
672
- }
673
- $.$mol_fail_hidden = $mol_fail_hidden;
674
- })($ || ($ = {}));
675
-
676
914
  ;
677
915
  "use strict";
678
916
  var $;
@@ -938,79 +1176,6 @@ var $;
938
1176
  });
939
1177
  })($ || ($ = {}));
940
1178
 
941
- ;
942
- "use strict";
943
- var $;
944
- (function ($) {
945
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
946
- function $mol_ambient(overrides) {
947
- return Object.setPrototypeOf(overrides, this || $);
948
- }
949
- $.$mol_ambient = $mol_ambient;
950
- })($ || ($ = {}));
951
-
952
- ;
953
- "use strict";
954
- var $;
955
- (function ($) {
956
- $.$mol_owning_map = new WeakMap();
957
- function $mol_owning_allow(having) {
958
- try {
959
- if (!having)
960
- return false;
961
- if (typeof having !== 'object' && typeof having !== 'function')
962
- return false;
963
- if (having instanceof $mol_delegate)
964
- return false;
965
- if (typeof having['destructor'] !== 'function')
966
- return false;
967
- return true;
968
- }
969
- catch {
970
- return false;
971
- }
972
- }
973
- $.$mol_owning_allow = $mol_owning_allow;
974
- function $mol_owning_get(having, Owner) {
975
- if (!$mol_owning_allow(having))
976
- return null;
977
- while (true) {
978
- const owner = $.$mol_owning_map.get(having);
979
- if (!owner)
980
- return owner;
981
- if (!Owner)
982
- return owner;
983
- if (owner instanceof Owner)
984
- return owner;
985
- having = owner;
986
- }
987
- }
988
- $.$mol_owning_get = $mol_owning_get;
989
- function $mol_owning_check(owner, having) {
990
- if (!$mol_owning_allow(having))
991
- return false;
992
- if ($.$mol_owning_map.get(having) !== owner)
993
- return false;
994
- return true;
995
- }
996
- $.$mol_owning_check = $mol_owning_check;
997
- function $mol_owning_catch(owner, having) {
998
- if (!$mol_owning_allow(having))
999
- return false;
1000
- if ($.$mol_owning_map.get(having))
1001
- return false;
1002
- $.$mol_owning_map.set(having, owner);
1003
- return true;
1004
- }
1005
- $.$mol_owning_catch = $mol_owning_catch;
1006
- })($ || ($ = {}));
1007
-
1008
- ;
1009
- "use strict";
1010
-
1011
- ;
1012
- "use strict";
1013
-
1014
1179
  ;
1015
1180
  "use strict";
1016
1181
 
@@ -1028,57 +1193,6 @@ var $;
1028
1193
 
1029
1194
  ;
1030
1195
  "use strict";
1031
- var $;
1032
- (function ($) {
1033
- if (!Symbol.dispose)
1034
- Symbol.dispose = Symbol('Symbol.dispose');
1035
- class $mol_object2 {
1036
- static $ = $;
1037
- [Symbol.toStringTag];
1038
- [$mol_ambient_ref] = null;
1039
- get $() {
1040
- if (this[$mol_ambient_ref])
1041
- return this[$mol_ambient_ref];
1042
- const owner = $mol_owning_get(this);
1043
- return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
1044
- }
1045
- set $(next) {
1046
- if (this[$mol_ambient_ref])
1047
- $mol_fail_hidden(new Error('Context already defined'));
1048
- this[$mol_ambient_ref] = next;
1049
- }
1050
- static create(init) {
1051
- const obj = new this;
1052
- if (init)
1053
- init(obj);
1054
- return obj;
1055
- }
1056
- static [Symbol.toPrimitive]() {
1057
- return this.toString();
1058
- }
1059
- static toString() {
1060
- return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
1061
- }
1062
- static toJSON() {
1063
- return this.toString();
1064
- }
1065
- static [$mol_key_handle]() {
1066
- return this.toString();
1067
- }
1068
- destructor() { }
1069
- static destructor() { }
1070
- [Symbol.dispose]() {
1071
- this.destructor();
1072
- }
1073
- //[ Symbol.toPrimitive ]( hint: string ) {
1074
- // return hint === 'number' ? this.valueOf() : this.toString()
1075
- //}
1076
- toString() {
1077
- return this[Symbol.toStringTag] || this.constructor.name + '<>';
1078
- }
1079
- }
1080
- $.$mol_object2 = $mol_object2;
1081
- })($ || ($ = {}));
1082
1196
 
1083
1197
  ;
1084
1198
  "use strict";
@@ -3919,6 +4033,149 @@ var $;
3919
4033
  });
3920
4034
  })($ || ($ = {}));
3921
4035
 
4036
+ ;
4037
+ "use strict";
4038
+ var $;
4039
+ (function ($) {
4040
+ $mol_test({
4041
+ 'run callback'() {
4042
+ class Plus1 extends $mol_wrapper {
4043
+ static wrap(task) {
4044
+ return function (...args) {
4045
+ return task.call(this, ...args) + 1;
4046
+ };
4047
+ }
4048
+ }
4049
+ $mol_assert_equal(Plus1.run(() => 2), 3);
4050
+ },
4051
+ 'wrap function'() {
4052
+ class Plus1 extends $mol_wrapper {
4053
+ static wrap(task) {
4054
+ return function (...args) {
4055
+ return task.call(this, ...args) + 1;
4056
+ };
4057
+ }
4058
+ }
4059
+ const obj = {
4060
+ level: 2,
4061
+ pow: Plus1.func(function (a) {
4062
+ return a ** this.level;
4063
+ })
4064
+ };
4065
+ $mol_assert_equal(obj.pow(2), 5);
4066
+ },
4067
+ 'decorate field getter'() {
4068
+ class Plus1 extends $mol_wrapper {
4069
+ static last = 0;
4070
+ static wrap(task) {
4071
+ return function (...args) {
4072
+ return Plus1.last = (task.call(this, ...args) || 0) + 1;
4073
+ };
4074
+ }
4075
+ }
4076
+ class Foo {
4077
+ static get two() {
4078
+ return 1;
4079
+ }
4080
+ static set two(next) { }
4081
+ }
4082
+ __decorate([
4083
+ Plus1.field
4084
+ ], Foo, "two", null);
4085
+ $mol_assert_equal(Foo.two, 2);
4086
+ Foo.two = 3;
4087
+ $mol_assert_equal(Plus1.last, 2);
4088
+ $mol_assert_equal(Foo.two, 2);
4089
+ },
4090
+ 'decorate instance method'() {
4091
+ class Plus1 extends $mol_wrapper {
4092
+ static wrap(task) {
4093
+ return function (...args) {
4094
+ return task.call(this, ...args) + 1;
4095
+ };
4096
+ }
4097
+ }
4098
+ class Foo1 {
4099
+ level = 2;
4100
+ pow(a) {
4101
+ return a ** this.level;
4102
+ }
4103
+ }
4104
+ __decorate([
4105
+ Plus1.method
4106
+ ], Foo1.prototype, "pow", null);
4107
+ const Foo2 = Foo1;
4108
+ const foo = new Foo2;
4109
+ $mol_assert_equal(foo.pow(2), 5);
4110
+ },
4111
+ 'decorate static method'() {
4112
+ class Plus1 extends $mol_wrapper {
4113
+ static wrap(task) {
4114
+ return function (...args) {
4115
+ return task.call(this, ...args) + 1;
4116
+ };
4117
+ }
4118
+ }
4119
+ class Foo {
4120
+ static level = 2;
4121
+ static pow(a) {
4122
+ return a ** this.level;
4123
+ }
4124
+ }
4125
+ __decorate([
4126
+ Plus1.method
4127
+ ], Foo, "pow", null);
4128
+ $mol_assert_equal(Foo.pow(2), 5);
4129
+ },
4130
+ 'decorate class'() {
4131
+ class BarInc extends $mol_wrapper {
4132
+ static wrap(task) {
4133
+ return function (...args) {
4134
+ const foo = task.call(this, ...args);
4135
+ foo.bar++;
4136
+ return foo;
4137
+ };
4138
+ }
4139
+ }
4140
+ let Foo = class Foo {
4141
+ bar;
4142
+ constructor(bar) {
4143
+ this.bar = bar;
4144
+ }
4145
+ };
4146
+ Foo = __decorate([
4147
+ BarInc.class
4148
+ ], Foo);
4149
+ $mol_assert_equal(new Foo(2).bar, 3);
4150
+ },
4151
+ });
4152
+ })($ || ($ = {}));
4153
+
4154
+ ;
4155
+ "use strict";
4156
+ var $;
4157
+ (function ($) {
4158
+ $mol_test({
4159
+ 'memoize field'() {
4160
+ class Foo {
4161
+ static one = 1;
4162
+ static get two() {
4163
+ return ++this.one;
4164
+ }
4165
+ static set two(next) { }
4166
+ }
4167
+ __decorate([
4168
+ $mol_memo.field
4169
+ ], Foo, "two", null);
4170
+ $mol_assert_equal(Foo.two, 2);
4171
+ $mol_assert_equal(Foo.two, 2);
4172
+ Foo.two = 3;
4173
+ $mol_assert_equal(Foo.two, 3);
4174
+ $mol_assert_equal(Foo.two, 3);
4175
+ },
4176
+ });
4177
+ })($ || ($ = {}));
4178
+
3922
4179
  ;
3923
4180
  "use strict";
3924
4181
  /** @jsx $mol_jsx */
@@ -3994,6 +4251,10 @@ var $;
3994
4251
  var $$;
3995
4252
  (function ($$) {
3996
4253
  $mol_test({
4254
+ "Cache of enum schema"($) {
4255
+ $mol_assert_equal($mol_schema_enum(['foo']), $mol_schema_enum(['foo']));
4256
+ $mol_assert_unique($mol_schema_enum(['foo']), $mol_schema_enum(['bar']));
4257
+ },
3997
4258
  "Enum options"($) {
3998
4259
  const Config = $mol_schema_enum([123, 'foo']);
3999
4260
  $mol_assert_equal('$mol_schema_enum<[123,"foo"]>', Config + '', $mol_key(Config));
@@ -4061,6 +4322,10 @@ var $;
4061
4322
  var $$;
4062
4323
  (function ($$) {
4063
4324
  $mol_test({
4325
+ "Cache of some schema"($) {
4326
+ $mol_assert_equal($mol_schema_some([$mol_schema_float]), $mol_schema_some([$mol_schema_float]));
4327
+ $mol_assert_unique($mol_schema_some([$mol_schema_float]), $mol_schema_some([$mol_schema_string]));
4328
+ },
4064
4329
  "Some variant"($) {
4065
4330
  const Config = $mol_schema_some([$mol_schema_float, $mol_schema_string]);
4066
4331
  $mol_assert_equal('$mol_schema_some<[$mol_schema_float,$mol_schema_string]>', Config + '');
@@ -4084,6 +4349,10 @@ var $;
4084
4349
  var $$;
4085
4350
  (function ($$) {
4086
4351
  $mol_test({
4352
+ "Cache of maybe schema"($) {
4353
+ $mol_assert_equal($mol_schema_maybe($mol_schema_float), $mol_schema_maybe($mol_schema_float));
4354
+ $mol_assert_unique($mol_schema_maybe($mol_schema_float), $mol_schema_maybe($mol_schema_string));
4355
+ },
4087
4356
  "Optional value"($) {
4088
4357
  const Config = $mol_schema_maybe($mol_schema_string);
4089
4358
  $mol_assert_equal('$mol_schema_maybe<$mol_schema_string>', Config + '');
@@ -4139,8 +4408,12 @@ var $;
4139
4408
  var $$;
4140
4409
  (function ($$) {
4141
4410
  $mol_test({
4411
+ "Cache of range schema"($) {
4412
+ $mol_assert_equal($mol_schema_range([0, 1]), $mol_schema_range([0, 1]));
4413
+ $mol_assert_unique($mol_schema_range([0, 1]), $mol_schema_range([0, 2]));
4414
+ },
4142
4415
  "Float range schema"($) {
4143
- const Range = $mol_schema_range(4, 8);
4416
+ const Range = $mol_schema_range([4, 8]);
4144
4417
  $mol_assert_equal(true, Range.check(5.5));
4145
4418
  $mol_assert_equal(true, Range.check(4));
4146
4419
  $mol_assert_equal(true, Range.check(8));
@@ -4165,9 +4438,13 @@ var $;
4165
4438
  var $$;
4166
4439
  (function ($$) {
4167
4440
  $mol_test({
4441
+ "Cache of every schema"($) {
4442
+ $mol_assert_equal($mol_schema_every([$mol_schema_float]), $mol_schema_every([$mol_schema_float]));
4443
+ $mol_assert_unique($mol_schema_every([$mol_schema_float]), $mol_schema_every([$mol_schema_string]));
4444
+ },
4168
4445
  "Range intersection"($) {
4169
- const Narrow = $mol_schema_every([$mol_schema_integer, $mol_schema_range(1, 8), $mol_schema_range(4, 10)]);
4170
- $mol_assert_equal('$mol_schema_every<[$mol_schema_integer,$mol_schema_range<1,8>,$mol_schema_range<4,10>]>', Narrow + '');
4446
+ const Narrow = $mol_schema_every([$mol_schema_integer, $mol_schema_range([1, 8]), $mol_schema_range([4, 10])]);
4447
+ $mol_assert_equal('$mol_schema_every<[$mol_schema_integer,$mol_schema_range<[1,8]>,$mol_schema_range<[4,10]>]>', Narrow + '');
4171
4448
  $mol_assert_equal(true, Narrow.check(6));
4172
4449
  $mol_assert_equal(true, Narrow.check(4));
4173
4450
  $mol_assert_equal(true, Narrow.check(8));
@@ -4193,6 +4470,10 @@ var $;
4193
4470
  var $$;
4194
4471
  (function ($$) {
4195
4472
  $mol_test({
4473
+ "Cache of list schema"($) {
4474
+ $mol_assert_equal($mol_schema_list($mol_schema_float), $mol_schema_list($mol_schema_float));
4475
+ $mol_assert_unique($mol_schema_list($mol_schema_float), $mol_schema_list($mol_schema_string));
4476
+ },
4196
4477
  "Array schema"($) {
4197
4478
  const Vector = $mol_schema_list($mol_schema_float);
4198
4479
  $mol_assert_equal('$mol_schema_list<$mol_schema_float>', Vector + '');
@@ -4217,6 +4498,10 @@ var $;
4217
4498
  var $$;
4218
4499
  (function ($$) {
4219
4500
  $mol_test({
4501
+ "Cache of pattern schema"($) {
4502
+ $mol_assert_equal($mol_schema_pattern(/foo/), $mol_schema_pattern(/foo/));
4503
+ $mol_assert_unique($mol_schema_pattern(/foo/), $mol_schema_pattern(/bar/));
4504
+ },
4220
4505
  "String pattern schema"($) {
4221
4506
  const Email = $mol_schema_pattern(/^.*@.*$/);
4222
4507
  $mol_assert_equal('$mol_schema_pattern</^.*@.*$/>', Email + '', $mol_key(Email));
@@ -4260,8 +4545,12 @@ var $;
4260
4545
  var $;
4261
4546
  (function ($_1) {
4262
4547
  $mol_test({
4548
+ "Cache of dict schema"($) {
4549
+ $mol_assert_equal($mol_schema_dict([$mol_schema_string, $mol_schema_float]), $mol_schema_dict([$mol_schema_string, $mol_schema_float]));
4550
+ $mol_assert_unique($mol_schema_dict([$mol_schema_string, $mol_schema_float]), $mol_schema_dict([$mol_schema_string, $mol_schema_string]));
4551
+ },
4263
4552
  "Dictionary schema"($) {
4264
- const Flags = $mol_schema_dict($mol_schema_pattern(/^[a-z]+$/), $mol_schema_boolean);
4553
+ const Flags = $mol_schema_dict([$mol_schema_pattern(/^[a-z]+$/), $mol_schema_boolean]);
4265
4554
  $mol_assert_equal(true, Flags.check({}));
4266
4555
  $mol_assert_equal(true, Flags.check({ foo: false }));
4267
4556
  $mol_assert_equal(false, Flags.check({ f00: false }));
@@ -4284,6 +4573,10 @@ var $;
4284
4573
  var $$;
4285
4574
  (function ($$) {
4286
4575
  $mol_test({
4576
+ "Cache of record schema"($) {
4577
+ $mol_assert_equal($mol_schema_record({ foo: $mol_schema_float }), $mol_schema_record({ foo: $mol_schema_float }));
4578
+ $mol_assert_unique($mol_schema_record({ foo: $mol_schema_float }), $mol_schema_record({ foo: $mol_schema_string }));
4579
+ },
4287
4580
  "Record schema"($) {
4288
4581
  const User = $mol_schema_record({
4289
4582
  name: $mol_schema_string,
@@ -4369,6 +4662,10 @@ var $;
4369
4662
  var $$;
4370
4663
  (function ($$) {
4371
4664
  $mol_test({
4665
+ "Cache of instance schema"($) {
4666
+ $mol_assert_equal($mol_schema_instance(Uint8Array), $mol_schema_instance(Uint8Array));
4667
+ $mol_assert_unique($mol_schema_instance(Uint8Array), $mol_schema_instance(Int8Array));
4668
+ },
4372
4669
  "Class instance schema"($) {
4373
4670
  const Blob = $mol_schema_instance(Uint8Array);
4374
4671
  $mol_assert_equal('$mol_schema_instance<Uint8Array>', Blob + '', $mol_key(Blob));
@@ -4398,48 +4695,6 @@ var $;
4398
4695
  })($$ = $_1.$$ || ($_1.$$ = {}));
4399
4696
  })($ || ($ = {}));
4400
4697
 
4401
- ;
4402
- "use strict";
4403
- var $;
4404
- (function ($) {
4405
- const instances = new WeakSet();
4406
- /**
4407
- * Proxy that delegates all to lazy returned target.
4408
- *
4409
- * $mol_delegate( Array.prototype , ()=> fetch_array() )
4410
- */
4411
- function $mol_delegate(proto, target) {
4412
- const proxy = new Proxy(proto, {
4413
- get: (_, field) => {
4414
- const obj = target();
4415
- let val = Reflect.get(obj, field);
4416
- if (typeof val === 'function') {
4417
- val = val.bind(obj);
4418
- }
4419
- return val;
4420
- },
4421
- has: (_, field) => Reflect.has(target(), field),
4422
- set: (_, field, value) => Reflect.set(target(), field, value),
4423
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
4424
- ownKeys: () => Reflect.ownKeys(target()),
4425
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
4426
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
4427
- isExtensible: () => Reflect.isExtensible(target()),
4428
- preventExtensions: () => Reflect.preventExtensions(target()),
4429
- apply: (_, self, args) => Reflect.apply(target(), self, args),
4430
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
4431
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
4432
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
4433
- });
4434
- instances.add(proxy);
4435
- return proxy;
4436
- }
4437
- $.$mol_delegate = $mol_delegate;
4438
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
4439
- value: (obj) => instances.has(obj),
4440
- });
4441
- })($ || ($ = {}));
4442
-
4443
4698
  ;
4444
4699
  "use strict";
4445
4700
  var $;
@@ -5371,7 +5626,7 @@ var $;
5371
5626
  } + '', class Some extends $mol_schema_maybe($mol_schema_float) {
5372
5627
  } + '', class Some extends $mol_schema_every([$mol_schema_float]) {
5373
5628
  } + '', class Some extends $mol_schema_list($mol_schema_float) {
5374
- } + '', class Some extends $mol_schema_dict($mol_schema_string, $mol_schema_string) {
5629
+ } + '', class Some extends $mol_schema_dict([$mol_schema_string, $mol_schema_string]) {
5375
5630
  } + '', class Some extends $mol_schema_record({ name: $mol_schema_string }) {
5376
5631
  } + '', class Some extends $mol_schema_partial({ name: $mol_schema_string }) {
5377
5632
  } + '');