mol_schema 0.0.21 → 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
@@ -82,6 +82,9 @@ var $;
82
82
  return false;
83
83
  }
84
84
  }
85
+ static [Symbol.hasInstance](val) {
86
+ return this.check(val);
87
+ }
85
88
  /** Strict parse. Fails of wrong values. */
86
89
  static guard(value) {
87
90
  return value;
@@ -111,6 +114,60 @@ var $;
111
114
  $.$mol_fail = $mol_fail;
112
115
  })($ || ($ = {}));
113
116
 
117
+ ;
118
+ "use strict";
119
+ var $;
120
+ (function ($) {
121
+ class $mol_schema_float extends $mol_schema_any {
122
+ static guard(value) {
123
+ if (typeof value === 'number')
124
+ return value;
125
+ return $mol_fail(new TypeError('Wrong type', { cause: { value, schema: this } }));
126
+ }
127
+ static default = Number.NaN;
128
+ }
129
+ $.$mol_schema_float = $mol_schema_float;
130
+ })($ || ($ = {}));
131
+
132
+ ;
133
+ "use strict";
134
+ var $;
135
+ (function ($) {
136
+ class $mol_schema_integer extends $mol_schema_float {
137
+ $mol_schema_integer = true;
138
+ static guard(value) {
139
+ const val = super.guard(value);
140
+ if (!Number.isFinite(val))
141
+ return $mol_fail(new TypeError('Non finite', { cause: { value, schema: this } }));
142
+ if (Math.trunc(val) !== val)
143
+ return $mol_fail(new TypeError('Non integer', { cause: { value, schema: this } }));
144
+ return val;
145
+ }
146
+ static default = 0;
147
+ }
148
+ $.$mol_schema_integer = $mol_schema_integer;
149
+ })($ || ($ = {}));
150
+
151
+ ;
152
+ "use strict";
153
+ var $;
154
+ (function ($) {
155
+ class $mol_schema_bigint extends $mol_schema_any {
156
+ static guard(value) {
157
+ if (typeof value === 'bigint')
158
+ return value;
159
+ return $mol_fail(new TypeError('Wrong type', { cause: { value, schema: this } }));
160
+ }
161
+ static cast(value) {
162
+ if (typeof value === 'number')
163
+ return BigInt($mol_schema_integer.cast(value));
164
+ return super.cast(value);
165
+ }
166
+ static default = 0n;
167
+ }
168
+ $.$mol_schema_bigint = $mol_schema_bigint;
169
+ })($ || ($ = {}));
170
+
114
171
  ;
115
172
  "use strict";
116
173
  var $;
@@ -144,6 +201,241 @@ var $;
144
201
  $.$mol_schema_string = $mol_schema_string;
145
202
  })($ || ($ = {}));
146
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
+
147
439
  ;
148
440
  "use strict";
149
441
  var $;
@@ -217,7 +509,32 @@ var $;
217
509
  "use strict";
218
510
  var $;
219
511
  (function ($) {
220
- 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) {
221
538
  return class $mol_schema_pattern_ extends $mol_schema_string {
222
539
  static Pattern = Pattern;
223
540
  static toString() {
@@ -235,42 +552,32 @@ var $;
235
552
  }
236
553
  static default = '';
237
554
  };
238
- }
239
- $.$mol_schema_pattern = $mol_schema_pattern;
240
- })($ || ($ = {}));
241
-
242
- ;
243
- "use strict";
244
- var $;
245
- (function ($) {
246
- class $mol_schema_float extends $mol_schema_any {
247
- static guard(value) {
248
- if (typeof value === 'number')
249
- return value;
250
- return $mol_fail(new TypeError('Wrong type', { cause: { value, schema: this } }));
251
- }
252
- static default = Number.NaN;
253
- }
254
- $.$mol_schema_float = $mol_schema_float;
555
+ });
255
556
  })($ || ($ = {}));
256
557
 
257
558
  ;
258
559
  "use strict";
259
560
  var $;
260
561
  (function ($) {
261
- class $mol_schema_integer extends $mol_schema_float {
262
- $mol_schema_integer = true;
263
- static guard(value) {
264
- const val = super.guard(value);
265
- if (!Number.isFinite(val))
266
- return $mol_fail(new TypeError('Non finite', { cause: { value, schema: this } }));
267
- if (Math.trunc(val) !== val)
268
- return $mol_fail(new TypeError('Non integer', { cause: { value, schema: this } }));
269
- return val;
562
+ $.$mol_schema_instance = $mol_memo_key.func(function $mol_schema_instance(Class, ...args) {
563
+ class $mol_schema_instance_ extends $mol_schema_any {
564
+ static Class = Class;
565
+ static toString() {
566
+ if (this !== $mol_schema_instance_)
567
+ return super.toString();
568
+ return '$mol_schema_instance<' + $$.$mol_func_name(Class) + '>';
569
+ }
570
+ static guard(value) {
571
+ if (value != null && Object(value) instanceof Class)
572
+ return value;
573
+ return $mol_fail(new TypeError('Wrong class', { cause: { value, schema: this } }));
574
+ }
575
+ static default = new Class(...args);
270
576
  }
271
- static default = 0;
272
- }
273
- $.$mol_schema_integer = $mol_schema_integer;
577
+ return ((Class[Symbol.hasInstance] === $mol_schema_any[Symbol.hasInstance])
578
+ ? Class
579
+ : $mol_schema_instance_);
580
+ });
274
581
  })($ || ($ = {}));
275
582
 
276
583
  ;
@@ -280,7 +587,7 @@ var $;
280
587
  "use strict";
281
588
  var $;
282
589
  (function ($) {
283
- function $mol_schema_every(Schemas) {
590
+ $.$mol_schema_every = $mol_memo_key.func(function $mol_schema_every(Schemas) {
284
591
  return class $mol_schema_every_ extends $mol_schema_any {
285
592
  static Schemas = Schemas;
286
593
  static toString() {
@@ -301,50 +608,47 @@ var $;
301
608
  }
302
609
  static default = Schemas.find(Scheme => this.check(Scheme.default));
303
610
  };
304
- }
305
- $.$mol_schema_every = $mol_schema_every;
611
+ });
306
612
  })($ || ($ = {}));
307
613
 
308
614
  ;
309
615
  "use strict";
310
616
  var $;
311
617
  (function ($) {
312
- function $mol_schema_range(Min, Max) {
618
+ $.$mol_schema_range = $mol_memo_key.func(function $mol_schema_range(Range) {
313
619
  return class $mol_schema_range_ extends $mol_schema_any {
314
- static Min = Min;
315
- static Max = Max;
620
+ static Range = Range;
316
621
  static toString() {
317
622
  if (this !== $mol_schema_range_)
318
623
  return super.toString();
319
- return '$mol_schema_range<' + $mol_key(Min) + ',' + $mol_key(Max) + '>';
624
+ return '$mol_schema_range<' + $mol_key(Range) + '>';
320
625
  }
321
626
  static guard(value) {
322
627
  if (typeof value !== 'number' && typeof value !== 'bigint')
323
628
  return $mol_fail(new TypeError('Uncomparable type', { cause: { value, schema: this } }));
324
- if (!(value <= Max))
629
+ if (!(value <= Range[1]))
325
630
  return $mol_fail(new TypeError('Too large', { cause: { value, schema: this } }));
326
- if (!(value >= Min))
631
+ if (!(value >= Range[0]))
327
632
  return $mol_fail(new TypeError('Too small', { cause: { value, schema: this } }));
328
633
  return value;
329
634
  }
330
635
  static cast(val) {
331
- if (val > Max)
332
- return Max;
333
- if (val >= Min)
636
+ if (val > Range[1])
637
+ return Range[1];
638
+ if (val >= Range[0])
334
639
  return val;
335
- return Min;
640
+ return Range[0];
336
641
  }
337
- static default = Min;
642
+ static default = Range[0];
338
643
  };
339
- }
340
- $.$mol_schema_range = $mol_schema_range;
644
+ });
341
645
  })($ || ($ = {}));
342
646
 
343
647
  ;
344
648
  "use strict";
345
649
  var $;
346
650
  (function ($) {
347
- 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]) {
348
652
  }
349
653
  $.$mol_schema_positive = $mol_schema_positive;
350
654
  })($ || ($ = {}));
@@ -365,7 +669,7 @@ var $;
365
669
  "use strict";
366
670
  var $;
367
671
  (function ($) {
368
- function $mol_schema_enum(Options) {
672
+ $.$mol_schema_enum = $mol_memo_key.func(function $mol_schema_enum(Options) {
369
673
  return class $mol_schema_enum_ extends $mol_schema_any {
370
674
  static Options = Options;
371
675
  static toString() {
@@ -385,15 +689,14 @@ var $;
385
689
  }
386
690
  static default = Options[0];
387
691
  };
388
- }
389
- $.$mol_schema_enum = $mol_schema_enum;
692
+ });
390
693
  })($ || ($ = {}));
391
694
 
392
695
  ;
393
696
  "use strict";
394
697
  var $;
395
698
  (function ($) {
396
- 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]) {
397
700
  }
398
701
  $.$mol_schema_negative = $mol_schema_negative;
399
702
  })($ || ($ = {}));
@@ -402,7 +705,7 @@ var $;
402
705
  "use strict";
403
706
  var $;
404
707
  (function ($) {
405
- function $mol_schema_some(Variants) {
708
+ $.$mol_schema_some = $mol_memo_key.func(function $mol_schema_some(Variants) {
406
709
  return class $mol_schema_some_ extends $mol_schema_any {
407
710
  static Variants = Variants;
408
711
  static toString() {
@@ -432,15 +735,14 @@ var $;
432
735
  }
433
736
  static default = Variants[0].default;
434
737
  };
435
- }
436
- $.$mol_schema_some = $mol_schema_some;
738
+ });
437
739
  })($ || ($ = {}));
438
740
 
439
741
  ;
440
742
  "use strict";
441
743
  var $;
442
744
  (function ($) {
443
- function $mol_schema_maybe(Some) {
745
+ $.$mol_schema_maybe = $mol_memo_key.func(function $mol_schema_maybe(Some) {
444
746
  return class $mol_schema_maybe_ extends $mol_schema_some([$mol_schema_enum([undefined, null]), Some]) {
445
747
  static Some = Some;
446
748
  static toString() {
@@ -449,15 +751,14 @@ var $;
449
751
  return '$mol_schema_maybe<' + $mol_key(Some) + '>';
450
752
  }
451
753
  };
452
- }
453
- $.$mol_schema_maybe = $mol_schema_maybe;
754
+ });
454
755
  })($ || ($ = {}));
455
756
 
456
757
  ;
457
758
  "use strict";
458
759
  var $;
459
760
  (function ($) {
460
- function $mol_schema_list(Item) {
761
+ $.$mol_schema_list = $mol_memo_key.func(function $mol_schema_list(Item) {
461
762
  return class $mol_schema_list_ extends $mol_schema_any {
462
763
  static Item = Item;
463
764
  static toString() {
@@ -485,22 +786,20 @@ var $;
485
786
  }
486
787
  static default = [];
487
788
  };
488
- }
489
- $.$mol_schema_list = $mol_schema_list;
789
+ });
490
790
  })($ || ($ = {}));
491
791
 
492
792
  ;
493
793
  "use strict";
494
794
  var $;
495
795
  (function ($) {
496
- function $mol_schema_dict(Key, Val) {
796
+ $.$mol_schema_dict = $mol_memo_key.func(function $mol_schema_dict(Pair) {
497
797
  return class $mol_schema_dict_ extends $mol_schema_any {
498
- static Key = Key;
499
- static Val = Val;
798
+ static Pair = Pair;
500
799
  static toString() {
501
800
  if (this !== $mol_schema_dict_)
502
801
  return super.toString();
503
- return '$mol_schema_dict<' + $mol_key(Key) + ',' + $mol_key(Key) + '>';
802
+ return '$mol_schema_dict<' + $mol_key(Pair) + '>';
504
803
  }
505
804
  static guard(value) {
506
805
  if (Object.getPrototypeOf(Object.getPrototypeOf(value))) {
@@ -508,13 +807,13 @@ var $;
508
807
  }
509
808
  for (const key in value) {
510
809
  try {
511
- Key.guard(key);
810
+ Pair[0].guard(key);
512
811
  }
513
812
  catch (error) {
514
813
  return $mol_fail(new TypeError('Wrong key', { cause: { key, error, value, schema: this } }));
515
814
  }
516
815
  try {
517
- Val.guard(value[key]);
816
+ Pair[1].guard(value[key]);
518
817
  }
519
818
  catch (error) {
520
819
  return $mol_fail(new TypeError('Wrong val', { cause: { key, error, value, schema: this } }));
@@ -527,23 +826,22 @@ var $;
527
826
  return this.default;
528
827
  const res = {};
529
828
  for (const key in value) {
530
- if (!Key.check(key))
829
+ if (!Pair[0].check(key))
531
830
  continue;
532
- res[key] = Val.cast(value[key]);
831
+ res[key] = Pair[1].cast(value[key]);
533
832
  }
534
833
  return res;
535
834
  }
536
835
  static default = {};
537
836
  };
538
- }
539
- $.$mol_schema_dict = $mol_schema_dict;
837
+ });
540
838
  })($ || ($ = {}));
541
839
 
542
840
  ;
543
841
  "use strict";
544
842
  var $;
545
843
  (function ($) {
546
- function $mol_schema_record(Fields) {
844
+ $.$mol_schema_record = $mol_memo_key.func(function $mol_schema_record(Fields) {
547
845
  return class $mol_schema_record_ extends $mol_schema_any {
548
846
  static Fields = Fields;
549
847
  static toString() {
@@ -575,8 +873,7 @@ var $;
575
873
  }
576
874
  static default = Object.fromEntries(Object.entries(Fields).map(([field, Field]) => [field, Field.default]));
577
875
  };
578
- }
579
- $.$mol_schema_record = $mol_schema_record;
876
+ });
580
877
  })($ || ($ = {}));
581
878
 
582
879
  ;
@@ -606,22 +903,12 @@ var $;
606
903
  function $mol_promise_like(val) {
607
904
  try {
608
905
  return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
609
- }
610
- catch {
611
- return false;
612
- }
613
- }
614
- $.$mol_promise_like = $mol_promise_like;
615
- })($ || ($ = {}));
616
-
617
- ;
618
- "use strict";
619
- var $;
620
- (function ($) {
621
- function $mol_fail_hidden(error) {
622
- throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
906
+ }
907
+ catch {
908
+ return false;
909
+ }
623
910
  }
624
- $.$mol_fail_hidden = $mol_fail_hidden;
911
+ $.$mol_promise_like = $mol_promise_like;
625
912
  })($ || ($ = {}));
626
913
 
627
914
  ;
@@ -889,76 +1176,6 @@ var $;
889
1176
  });
890
1177
  })($ || ($ = {}));
891
1178
 
892
- ;
893
- "use strict";
894
- var $;
895
- (function ($) {
896
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
897
- function $mol_ambient(overrides) {
898
- return Object.setPrototypeOf(overrides, this || $);
899
- }
900
- $.$mol_ambient = $mol_ambient;
901
- })($ || ($ = {}));
902
-
903
- ;
904
- "use strict";
905
- var $;
906
- (function ($) {
907
- $.$mol_owning_map = new WeakMap();
908
- function $mol_owning_allow(having) {
909
- try {
910
- if (!having)
911
- return false;
912
- if (typeof having !== 'object' && typeof having !== 'function')
913
- return false;
914
- if (having instanceof $mol_delegate)
915
- return false;
916
- if (typeof having['destructor'] !== 'function')
917
- return false;
918
- return true;
919
- }
920
- catch {
921
- return false;
922
- }
923
- }
924
- $.$mol_owning_allow = $mol_owning_allow;
925
- function $mol_owning_get(having, Owner) {
926
- if (!$mol_owning_allow(having))
927
- return null;
928
- while (true) {
929
- const owner = $.$mol_owning_map.get(having);
930
- if (!owner)
931
- return owner;
932
- if (!Owner)
933
- return owner;
934
- if (owner instanceof Owner)
935
- return owner;
936
- having = owner;
937
- }
938
- }
939
- $.$mol_owning_get = $mol_owning_get;
940
- function $mol_owning_check(owner, having) {
941
- if (!$mol_owning_allow(having))
942
- return false;
943
- if ($.$mol_owning_map.get(having) !== owner)
944
- return false;
945
- return true;
946
- }
947
- $.$mol_owning_check = $mol_owning_check;
948
- function $mol_owning_catch(owner, having) {
949
- if (!$mol_owning_allow(having))
950
- return false;
951
- if ($.$mol_owning_map.get(having))
952
- return false;
953
- $.$mol_owning_map.set(having, owner);
954
- return true;
955
- }
956
- $.$mol_owning_catch = $mol_owning_catch;
957
- })($ || ($ = {}));
958
-
959
- ;
960
- "use strict";
961
-
962
1179
  ;
963
1180
  "use strict";
964
1181
 
@@ -977,60 +1194,6 @@ var $;
977
1194
  ;
978
1195
  "use strict";
979
1196
 
980
- ;
981
- "use strict";
982
- var $;
983
- (function ($) {
984
- if (!Symbol.dispose)
985
- Symbol.dispose = Symbol('Symbol.dispose');
986
- class $mol_object2 {
987
- static $ = $;
988
- [Symbol.toStringTag];
989
- [$mol_ambient_ref] = null;
990
- get $() {
991
- if (this[$mol_ambient_ref])
992
- return this[$mol_ambient_ref];
993
- const owner = $mol_owning_get(this);
994
- return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
995
- }
996
- set $(next) {
997
- if (this[$mol_ambient_ref])
998
- $mol_fail_hidden(new Error('Context already defined'));
999
- this[$mol_ambient_ref] = next;
1000
- }
1001
- static create(init) {
1002
- const obj = new this;
1003
- if (init)
1004
- init(obj);
1005
- return obj;
1006
- }
1007
- static [Symbol.toPrimitive]() {
1008
- return this.toString();
1009
- }
1010
- static toString() {
1011
- return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
1012
- }
1013
- static toJSON() {
1014
- return this.toString();
1015
- }
1016
- static [$mol_key_handle]() {
1017
- return this.toString();
1018
- }
1019
- destructor() { }
1020
- static destructor() { }
1021
- [Symbol.dispose]() {
1022
- this.destructor();
1023
- }
1024
- //[ Symbol.toPrimitive ]( hint: string ) {
1025
- // return hint === 'number' ? this.valueOf() : this.toString()
1026
- //}
1027
- toString() {
1028
- return this[Symbol.toStringTag] || this.constructor.name + '<>';
1029
- }
1030
- }
1031
- $.$mol_object2 = $mol_object2;
1032
- })($ || ($ = {}));
1033
-
1034
1197
  ;
1035
1198
  "use strict";
1036
1199
  var $;
@@ -3870,6 +4033,149 @@ var $;
3870
4033
  });
3871
4034
  })($ || ($ = {}));
3872
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
+
3873
4179
  ;
3874
4180
  "use strict";
3875
4181
  /** @jsx $mol_jsx */
@@ -3945,6 +4251,10 @@ var $;
3945
4251
  var $$;
3946
4252
  (function ($$) {
3947
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
+ },
3948
4258
  "Enum options"($) {
3949
4259
  const Config = $mol_schema_enum([123, 'foo']);
3950
4260
  $mol_assert_equal('$mol_schema_enum<[123,"foo"]>', Config + '', $mol_key(Config));
@@ -3953,9 +4263,9 @@ var $;
3953
4263
  $mol_assert_equal(false, Config.check(true));
3954
4264
  $mol_assert_equal(false, Config.check(321));
3955
4265
  $mol_assert_equal(false, Config.check('bar'));
3956
- $mol_assert_equal(123, Config.cast(123));
3957
- $mol_assert_equal('foo', Config.cast('foo'));
3958
- $mol_assert_equal(123, Config.cast('bar'));
4266
+ $mol_assert_equal(Config.cast(123), 123);
4267
+ $mol_assert_equal(Config.cast('foo'), 'foo');
4268
+ $mol_assert_equal(Config.cast('bar'), 123);
3959
4269
  $mol_assert_equal(123, Config.guard(123));
3960
4270
  $mol_assert_fail(() => Config.guard(321), 'No one option');
3961
4271
  },
@@ -4012,6 +4322,10 @@ var $;
4012
4322
  var $$;
4013
4323
  (function ($$) {
4014
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
+ },
4015
4329
  "Some variant"($) {
4016
4330
  const Config = $mol_schema_some([$mol_schema_float, $mol_schema_string]);
4017
4331
  $mol_assert_equal('$mol_schema_some<[$mol_schema_float,$mol_schema_string]>', Config + '');
@@ -4035,6 +4349,10 @@ var $;
4035
4349
  var $$;
4036
4350
  (function ($$) {
4037
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
+ },
4038
4356
  "Optional value"($) {
4039
4357
  const Config = $mol_schema_maybe($mol_schema_string);
4040
4358
  $mol_assert_equal('$mol_schema_maybe<$mol_schema_string>', Config + '');
@@ -4090,8 +4408,12 @@ var $;
4090
4408
  var $$;
4091
4409
  (function ($$) {
4092
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
+ },
4093
4415
  "Float range schema"($) {
4094
- const Range = $mol_schema_range(4, 8);
4416
+ const Range = $mol_schema_range([4, 8]);
4095
4417
  $mol_assert_equal(true, Range.check(5.5));
4096
4418
  $mol_assert_equal(true, Range.check(4));
4097
4419
  $mol_assert_equal(true, Range.check(8));
@@ -4116,9 +4438,13 @@ var $;
4116
4438
  var $$;
4117
4439
  (function ($$) {
4118
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
+ },
4119
4445
  "Range intersection"($) {
4120
- const Narrow = $mol_schema_every([$mol_schema_integer, $mol_schema_range(1, 8), $mol_schema_range(4, 10)]);
4121
- $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 + '');
4122
4448
  $mol_assert_equal(true, Narrow.check(6));
4123
4449
  $mol_assert_equal(true, Narrow.check(4));
4124
4450
  $mol_assert_equal(true, Narrow.check(8));
@@ -4144,6 +4470,10 @@ var $;
4144
4470
  var $$;
4145
4471
  (function ($$) {
4146
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
+ },
4147
4477
  "Array schema"($) {
4148
4478
  const Vector = $mol_schema_list($mol_schema_float);
4149
4479
  $mol_assert_equal('$mol_schema_list<$mol_schema_float>', Vector + '');
@@ -4168,6 +4498,10 @@ var $;
4168
4498
  var $$;
4169
4499
  (function ($$) {
4170
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
+ },
4171
4505
  "String pattern schema"($) {
4172
4506
  const Email = $mol_schema_pattern(/^.*@.*$/);
4173
4507
  $mol_assert_equal('$mol_schema_pattern</^.*@.*$/>', Email + '', $mol_key(Email));
@@ -4211,8 +4545,12 @@ var $;
4211
4545
  var $;
4212
4546
  (function ($_1) {
4213
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
+ },
4214
4552
  "Dictionary schema"($) {
4215
- 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]);
4216
4554
  $mol_assert_equal(true, Flags.check({}));
4217
4555
  $mol_assert_equal(true, Flags.check({ foo: false }));
4218
4556
  $mol_assert_equal(false, Flags.check({ f00: false }));
@@ -4235,6 +4573,10 @@ var $;
4235
4573
  var $$;
4236
4574
  (function ($$) {
4237
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
+ },
4238
4580
  "Record schema"($) {
4239
4581
  const User = $mol_schema_record({
4240
4582
  name: $mol_schema_string,
@@ -4296,43 +4638,61 @@ var $;
4296
4638
  ;
4297
4639
  "use strict";
4298
4640
  var $;
4299
- (function ($) {
4300
- const instances = new WeakSet();
4301
- /**
4302
- * Proxy that delegates all to lazy returned target.
4303
- *
4304
- * $mol_delegate( Array.prototype , ()=> fetch_array() )
4305
- */
4306
- function $mol_delegate(proto, target) {
4307
- const proxy = new Proxy(proto, {
4308
- get: (_, field) => {
4309
- const obj = target();
4310
- let val = Reflect.get(obj, field);
4311
- if (typeof val === 'function') {
4312
- val = val.bind(obj);
4313
- }
4314
- return val;
4641
+ (function ($_1) {
4642
+ var $$;
4643
+ (function ($$) {
4644
+ $mol_test({
4645
+ "BigInt schema"($) {
4646
+ $mol_assert_equal('$mol_schema_bigint', $mol_schema_bigint + '', $mol_key($mol_schema_bigint));
4647
+ $mol_assert_equal(true, $mol_schema_bigint.check(0n));
4648
+ $mol_assert_equal(false, $mol_schema_bigint.check(0));
4649
+ $mol_assert_equal(1n, $mol_schema_bigint.cast(1n));
4650
+ $mol_assert_equal(1n, $mol_schema_bigint.cast(1));
4651
+ $mol_assert_equal(0n, $mol_schema_bigint.guard(0n));
4652
+ $mol_assert_fail(() => $mol_schema_bigint.guard(1), 'Wrong type');
4315
4653
  },
4316
- has: (_, field) => Reflect.has(target(), field),
4317
- set: (_, field, value) => Reflect.set(target(), field, value),
4318
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
4319
- ownKeys: () => Reflect.ownKeys(target()),
4320
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
4321
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
4322
- isExtensible: () => Reflect.isExtensible(target()),
4323
- preventExtensions: () => Reflect.preventExtensions(target()),
4324
- apply: (_, self, args) => Reflect.apply(target(), self, args),
4325
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
4326
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
4327
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
4328
4654
  });
4329
- instances.add(proxy);
4330
- return proxy;
4331
- }
4332
- $.$mol_delegate = $mol_delegate;
4333
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
4334
- value: (obj) => instances.has(obj),
4335
- });
4655
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4656
+ })($ || ($ = {}));
4657
+
4658
+ ;
4659
+ "use strict";
4660
+ var $;
4661
+ (function ($_1) {
4662
+ var $$;
4663
+ (function ($$) {
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
+ },
4669
+ "Class instance schema"($) {
4670
+ const Blob = $mol_schema_instance(Uint8Array);
4671
+ $mol_assert_equal('$mol_schema_instance<Uint8Array>', Blob + '', $mol_key(Blob));
4672
+ $mol_assert_equal(true, Blob.check(new Uint8Array));
4673
+ $mol_assert_equal(false, Blob.check(new Int8Array));
4674
+ $mol_assert_equal(false, Blob.check(null));
4675
+ $mol_assert_equal(new Uint8Array([0, 1]), Blob.cast(new Uint8Array([0, 1])));
4676
+ $mol_assert_equal(new Uint8Array, Blob.cast(new Int8Array([1, -1])));
4677
+ $mol_assert_equal(new Uint8Array, Blob.guard(new Uint8Array));
4678
+ $mol_assert_fail(() => Blob.guard(new Int8Array), 'Wrong class');
4679
+ },
4680
+ "Boxed instance schema"($) {
4681
+ const Str = $mol_schema_instance(String);
4682
+ $mol_assert_equal('$mol_schema_instance<String>', Str + '', $mol_key(Str));
4683
+ $mol_assert_equal(true, Str.check(Object('')));
4684
+ $mol_assert_equal(true, Str.check(''));
4685
+ $mol_assert_equal(true, Object('') instanceof Str);
4686
+ },
4687
+ "Schema instance schema"($) {
4688
+ const Str = $mol_schema_instance($mol_schema_instance(String));
4689
+ $mol_assert_equal('$mol_schema_instance<String>', Str + '', $mol_key(Str));
4690
+ $mol_assert_equal(true, Str.check(Object('')));
4691
+ $mol_assert_equal(true, Str.check(''));
4692
+ $mol_assert_equal(true, Object('') instanceof Str);
4693
+ },
4694
+ });
4695
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4336
4696
  })($ || ($ = {}));
4337
4697
 
4338
4698
  ;
@@ -5266,7 +5626,7 @@ var $;
5266
5626
  } + '', class Some extends $mol_schema_maybe($mol_schema_float) {
5267
5627
  } + '', class Some extends $mol_schema_every([$mol_schema_float]) {
5268
5628
  } + '', class Some extends $mol_schema_list($mol_schema_float) {
5269
- } + '', 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]) {
5270
5630
  } + '', class Some extends $mol_schema_record({ name: $mol_schema_string }) {
5271
5631
  } + '', class Some extends $mol_schema_partial({ name: $mol_schema_string }) {
5272
5632
  } + '');