@nlozgachev/pipelined 0.19.0 → 0.21.0

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/dist/index.js CHANGED
@@ -28,6 +28,7 @@ __export(src_exports, {
28
28
  Logged: () => Logged,
29
29
  Maybe: () => Maybe,
30
30
  Num: () => Num,
31
+ Op: () => Op,
31
32
  Optional: () => Optional,
32
33
  Predicate: () => Predicate,
33
34
  Reader: () => Reader,
@@ -288,15 +289,13 @@ var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
288
289
  var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
289
290
 
290
291
  // src/Core/Deferred.ts
291
- var _store = /* @__PURE__ */ new WeakMap();
292
292
  var Deferred;
293
293
  ((Deferred2) => {
294
- Deferred2.fromPromise = (p) => {
295
- const d = { then: ((f) => p.then(f)) };
296
- _store.set(d, p);
297
- return d;
298
- };
299
- Deferred2.toPromise = (d) => _store.get(d) ?? new Promise((resolve) => d.then(resolve));
294
+ Deferred2.fromPromise = (p) => (
295
+ // eslint-disable-next-line unicorn/no-thenable -- Deferred is intentionally thenable; it is the mechanism that makes Task awaitable
296
+ { then: ((f) => p.then(f)) }
297
+ );
298
+ Deferred2.toPromise = (d) => new Promise((resolve) => d.then(resolve));
300
299
  })(Deferred || (Deferred = {}));
301
300
 
302
301
  // src/Core/Lens.ts
@@ -406,6 +405,880 @@ var Maybe;
406
405
  Maybe2.ap = (arg) => (data) => (0, Maybe2.isSome)(data) && (0, Maybe2.isSome)(arg) ? (0, Maybe2.some)(data.value(arg.value)) : (0, Maybe2.none)();
407
406
  })(Maybe || (Maybe = {}));
408
407
 
408
+ // src/internal/Op.util.ts
409
+ var _abortedNil = { kind: "Nil", reason: "aborted" };
410
+ var _droppedNil = { kind: "Nil", reason: "dropped" };
411
+ var _replacedNil = { kind: "Nil", reason: "replaced" };
412
+ var _evictedNil = { kind: "Nil", reason: "evicted" };
413
+ var _idle = { kind: "Idle" };
414
+ var _pending = { kind: "Pending" };
415
+ var ok = (value) => ({ kind: "Ok", value });
416
+ var err = (error) => ({ kind: "Err", error });
417
+ var cancellableWait = (ms, signal) => {
418
+ if (ms <= 0) return Promise.resolve();
419
+ return new Promise((resolve) => {
420
+ const id = setTimeout(resolve, ms);
421
+ signal.addEventListener("abort", () => {
422
+ clearTimeout(id);
423
+ resolve();
424
+ }, { once: true });
425
+ });
426
+ };
427
+ var runWithRetry = (op, input, signal, options, onRetrying) => {
428
+ const { attempts, backoff, when: shouldRetry } = options;
429
+ const getDelay = (n) => backoff === void 0 ? 0 : typeof backoff === "function" ? backoff(n) : backoff;
430
+ const attempt = async (left) => {
431
+ const result = await Deferred.toPromise(op._factory(input, signal));
432
+ if (result === null || signal.aborted) return null;
433
+ if (result.kind === "Ok") return result;
434
+ if (left <= 1) return result;
435
+ if (shouldRetry !== void 0 && !shouldRetry(result.error)) return result;
436
+ const attemptNumber = attempts - left + 1;
437
+ const ms = getDelay(attemptNumber);
438
+ onRetrying({
439
+ kind: "Retrying",
440
+ attempt: attemptNumber,
441
+ lastError: result.error,
442
+ ...ms > 0 ? { nextRetryIn: ms } : {}
443
+ });
444
+ await cancellableWait(ms, signal);
445
+ if (signal.aborted) return null;
446
+ return attempt(left - 1);
447
+ };
448
+ return attempt(attempts);
449
+ };
450
+ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying) => {
451
+ const { signal } = controller;
452
+ const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
453
+ const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.toPromise(op._factory(input, signal)).then(toOutcome);
454
+ if (timeoutOptions === void 0) return Deferred.fromPromise(runPromise);
455
+ let timerId;
456
+ return Deferred.fromPromise(Promise.race([
457
+ runPromise.then((outcome) => {
458
+ clearTimeout(timerId);
459
+ return outcome;
460
+ }),
461
+ new Promise((resolve) => {
462
+ timerId = setTimeout(() => {
463
+ controller.abort();
464
+ resolve(err(timeoutOptions.onTimeout()));
465
+ }, timeoutOptions.ms);
466
+ })
467
+ ]));
468
+ };
469
+ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
470
+ let currentState = _idle;
471
+ let currentController;
472
+ let currentResolve;
473
+ let waitController;
474
+ let lastStartTime = 0;
475
+ const subscribers = /* @__PURE__ */ new Set();
476
+ const emit = (state) => {
477
+ currentState = state;
478
+ subscribers.forEach((cb) => cb(state));
479
+ };
480
+ const run = (input) => Deferred.fromPromise(
481
+ new Promise((resolve) => {
482
+ waitController?.abort();
483
+ waitController = void 0;
484
+ currentController?.abort();
485
+ const prev = currentResolve;
486
+ currentResolve = resolve;
487
+ currentController = new AbortController();
488
+ const controller = currentController;
489
+ prev?.(_replacedNil);
490
+ const startExecution = () => {
491
+ if (currentController !== controller) return;
492
+ lastStartTime = Date.now();
493
+ emit(_pending);
494
+ const onRetrying = retryOptions ? (r) => {
495
+ if (currentController === controller) emit(r);
496
+ } : void 0;
497
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
498
+ if (currentController !== controller) return;
499
+ const r = currentResolve;
500
+ currentResolve = void 0;
501
+ currentController = void 0;
502
+ emit(outcome);
503
+ r?.(outcome);
504
+ });
505
+ };
506
+ const gap = minInterval !== void 0 ? Math.max(0, minInterval - (Date.now() - lastStartTime)) : 0;
507
+ if (gap > 0) {
508
+ waitController = new AbortController();
509
+ const wc = waitController;
510
+ cancellableWait(gap, wc.signal).then(() => {
511
+ if (waitController === wc) waitController = void 0;
512
+ startExecution();
513
+ });
514
+ } else {
515
+ startExecution();
516
+ }
517
+ })
518
+ );
519
+ const abort = () => {
520
+ waitController?.abort();
521
+ waitController = void 0;
522
+ currentController?.abort();
523
+ currentController = void 0;
524
+ const r = currentResolve;
525
+ currentResolve = void 0;
526
+ if (currentState.kind !== "Idle") emit(_abortedNil);
527
+ r?.(_abortedNil);
528
+ };
529
+ return {
530
+ get state() {
531
+ return currentState;
532
+ },
533
+ run,
534
+ abort,
535
+ subscribe: (cb) => {
536
+ subscribers.add(cb);
537
+ if (currentState.kind !== "Idle") cb(currentState);
538
+ return () => subscribers.delete(cb);
539
+ }
540
+ };
541
+ };
542
+ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
543
+ let currentState = _idle;
544
+ let currentController;
545
+ let currentResolve;
546
+ let cooldownTimer;
547
+ const subscribers = /* @__PURE__ */ new Set();
548
+ const emit = (state) => {
549
+ currentState = state;
550
+ subscribers.forEach((cb) => cb(state));
551
+ };
552
+ const run = (input) => {
553
+ if (currentController !== void 0 || cooldownTimer !== void 0) {
554
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
555
+ }
556
+ return Deferred.fromPromise(
557
+ new Promise((resolve) => {
558
+ currentResolve = resolve;
559
+ currentController = new AbortController();
560
+ const controller = currentController;
561
+ emit(_pending);
562
+ const onRetrying = retryOptions ? (r) => {
563
+ if (currentController === controller) emit(r);
564
+ } : void 0;
565
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
566
+ if (currentController !== controller) return;
567
+ const r = currentResolve;
568
+ currentResolve = void 0;
569
+ currentController = void 0;
570
+ emit(outcome);
571
+ r?.(outcome);
572
+ if (cooldown !== void 0 && cooldown > 0) {
573
+ cooldownTimer = setTimeout(() => {
574
+ cooldownTimer = void 0;
575
+ }, cooldown);
576
+ }
577
+ });
578
+ })
579
+ );
580
+ };
581
+ const abort = () => {
582
+ if (cooldownTimer !== void 0) {
583
+ clearTimeout(cooldownTimer);
584
+ cooldownTimer = void 0;
585
+ }
586
+ currentController?.abort();
587
+ currentController = void 0;
588
+ const r = currentResolve;
589
+ currentResolve = void 0;
590
+ if (currentState.kind !== "Idle") emit(_abortedNil);
591
+ r?.(_abortedNil);
592
+ };
593
+ return {
594
+ get state() {
595
+ return currentState;
596
+ },
597
+ run,
598
+ abort,
599
+ subscribe: (cb) => {
600
+ subscribers.add(cb);
601
+ if (currentState.kind !== "Idle") cb(currentState);
602
+ return () => subscribers.delete(cb);
603
+ }
604
+ };
605
+ };
606
+ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeoutOptions) => {
607
+ const maxConcurrency = concurrency ?? 1;
608
+ let currentState = _idle;
609
+ let generation = 0;
610
+ let inFlight = 0;
611
+ const queue = [];
612
+ const inflightControllers = /* @__PURE__ */ new Set();
613
+ const inflightResolvers = [];
614
+ const subscribers = /* @__PURE__ */ new Set();
615
+ const emit = (state) => {
616
+ currentState = state;
617
+ subscribers.forEach((cb) => cb(state));
618
+ };
619
+ const startOne = (input, resolve, myGeneration) => {
620
+ inFlight++;
621
+ const controller = new AbortController();
622
+ inflightControllers.add(controller);
623
+ inflightResolvers.push(resolve);
624
+ emit(_pending);
625
+ const onRetrying = retryOptions ? (r) => {
626
+ if (generation === myGeneration && inflightControllers.has(controller)) emit(r);
627
+ } : void 0;
628
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
629
+ inflightControllers.delete(controller);
630
+ const idx = inflightResolvers.indexOf(resolve);
631
+ if (idx !== -1) inflightResolvers.splice(idx, 1);
632
+ if (generation !== myGeneration) {
633
+ resolve(_abortedNil);
634
+ return;
635
+ }
636
+ inFlight--;
637
+ emit(outcome);
638
+ resolve(outcome);
639
+ if (queue.length > 0) {
640
+ const next = queue.shift();
641
+ startOne(next.input, next.resolve, generation);
642
+ }
643
+ });
644
+ };
645
+ const run = (input) => {
646
+ const myGeneration = generation;
647
+ if (dedupe !== void 0) {
648
+ const idx = queue.findIndex((item) => dedupe(input, item.input));
649
+ if (idx !== -1) {
650
+ const dup = queue.splice(idx, 1)[0];
651
+ dup.resolve(_droppedNil);
652
+ }
653
+ }
654
+ if (inFlight < maxConcurrency) {
655
+ return Deferred.fromPromise(
656
+ new Promise((resolve) => {
657
+ startOne(input, resolve, myGeneration);
658
+ })
659
+ );
660
+ }
661
+ if (maxSize === void 0 || queue.length < maxSize) {
662
+ return Deferred.fromPromise(
663
+ new Promise((resolve) => {
664
+ queue.push({ input, resolve });
665
+ emit({ kind: "Queued", position: queue.length - 1 });
666
+ })
667
+ );
668
+ }
669
+ if (overflow === "replace-last") {
670
+ return Deferred.fromPromise(
671
+ new Promise((resolve) => {
672
+ const tail = queue.pop();
673
+ tail.resolve(_evictedNil);
674
+ queue.push({ input, resolve });
675
+ emit({ kind: "Queued", position: queue.length - 1 });
676
+ })
677
+ );
678
+ }
679
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
680
+ };
681
+ const abort = () => {
682
+ generation++;
683
+ inflightControllers.forEach((c) => c.abort());
684
+ inflightControllers.clear();
685
+ const toResolve = inflightResolvers.splice(0);
686
+ const queuedResolvers = queue.splice(0).map((item) => item.resolve);
687
+ inFlight = 0;
688
+ if (currentState.kind !== "Idle") emit(_abortedNil);
689
+ toResolve.forEach((r) => r(_abortedNil));
690
+ queuedResolvers.forEach((r) => r(_abortedNil));
691
+ };
692
+ return {
693
+ get state() {
694
+ return currentState;
695
+ },
696
+ run,
697
+ abort,
698
+ subscribe: (cb) => {
699
+ subscribers.add(cb);
700
+ if (currentState.kind !== "Idle") cb(currentState);
701
+ return () => subscribers.delete(cb);
702
+ }
703
+ };
704
+ };
705
+ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
706
+ const bufferSize = size ?? 1;
707
+ let currentState = _idle;
708
+ let currentController;
709
+ let currentResolve;
710
+ const buffer = [];
711
+ const subscribers = /* @__PURE__ */ new Set();
712
+ const emit = (state) => {
713
+ currentState = state;
714
+ subscribers.forEach((cb) => cb(state));
715
+ };
716
+ const startRun = (input, resolve) => {
717
+ currentResolve = resolve;
718
+ currentController = new AbortController();
719
+ const controller = currentController;
720
+ emit(_pending);
721
+ const onRetrying = retryOptions ? (r) => {
722
+ if (currentController === controller) emit(r);
723
+ } : void 0;
724
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
725
+ if (currentController !== controller) return;
726
+ const r = currentResolve;
727
+ currentResolve = void 0;
728
+ currentController = void 0;
729
+ emit(outcome);
730
+ r?.(outcome);
731
+ if (buffer.length > 0) {
732
+ const next = buffer.shift();
733
+ startRun(next.input, next.resolve);
734
+ }
735
+ });
736
+ };
737
+ const run = (input) => Deferred.fromPromise(
738
+ new Promise((resolve) => {
739
+ if (currentController === void 0) {
740
+ startRun(input, resolve);
741
+ } else if (buffer.length < bufferSize) {
742
+ buffer.push({ input, resolve });
743
+ emit({ kind: "Queued", position: buffer.length - 1 });
744
+ } else {
745
+ const evicted = buffer.shift();
746
+ evicted.resolve(_evictedNil);
747
+ buffer.push({ input, resolve });
748
+ emit({ kind: "Queued", position: buffer.length - 1 });
749
+ }
750
+ })
751
+ );
752
+ const abort = () => {
753
+ currentController?.abort();
754
+ currentController = void 0;
755
+ const cr = currentResolve;
756
+ currentResolve = void 0;
757
+ const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
758
+ if (currentState.kind !== "Idle") emit(_abortedNil);
759
+ cr?.(_abortedNil);
760
+ bufferedResolvers.forEach((r) => r(_abortedNil));
761
+ };
762
+ return {
763
+ get state() {
764
+ return currentState;
765
+ },
766
+ run,
767
+ abort,
768
+ subscribe: (cb) => {
769
+ subscribers.add(cb);
770
+ if (currentState.kind !== "Idle") cb(currentState);
771
+ return () => subscribers.delete(cb);
772
+ }
773
+ };
774
+ };
775
+ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) => {
776
+ let currentState = _idle;
777
+ let currentController;
778
+ let currentResolve;
779
+ let leadingController;
780
+ let leadingResolve;
781
+ let pendingResolve;
782
+ let timerId;
783
+ let pendingInput;
784
+ let firstCallAt = 0;
785
+ const subscribers = /* @__PURE__ */ new Set();
786
+ const emit = (state) => {
787
+ currentState = state;
788
+ subscribers.forEach((cb) => cb(state));
789
+ };
790
+ const fireLeading = (input, resolve) => {
791
+ leadingController = new AbortController();
792
+ const controller = leadingController;
793
+ leadingResolve = resolve;
794
+ emit(_pending);
795
+ const onRetrying = retryOptions ? (r) => {
796
+ if (leadingController === controller) emit(r);
797
+ } : void 0;
798
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
799
+ if (leadingController !== controller) return;
800
+ const r = leadingResolve;
801
+ leadingResolve = void 0;
802
+ leadingController = void 0;
803
+ emit(outcome);
804
+ r?.(outcome);
805
+ });
806
+ };
807
+ const fireTrailing = () => {
808
+ timerId = void 0;
809
+ firstCallAt = 0;
810
+ const capturedResolve = pendingResolve;
811
+ pendingResolve = void 0;
812
+ if (capturedResolve === void 0) return;
813
+ currentResolve = capturedResolve;
814
+ const toRun = pendingInput;
815
+ pendingInput = void 0;
816
+ currentController = new AbortController();
817
+ const controller = currentController;
818
+ emit(_pending);
819
+ const onRetrying = retryOptions ? (r) => {
820
+ if (currentController === controller) emit(r);
821
+ } : void 0;
822
+ execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
823
+ if (currentController !== controller) return;
824
+ const r = currentResolve;
825
+ currentResolve = void 0;
826
+ currentController = void 0;
827
+ emit(outcome);
828
+ r?.(outcome);
829
+ });
830
+ };
831
+ const scheduleTrailing = () => {
832
+ if (timerId !== void 0) clearTimeout(timerId);
833
+ let delay = ms;
834
+ if (maxWait !== void 0 && firstCallAt > 0) {
835
+ const maxDelay = firstCallAt + maxWait - Date.now();
836
+ delay = Math.min(ms, Math.max(0, maxDelay));
837
+ }
838
+ timerId = setTimeout(fireTrailing, delay);
839
+ };
840
+ const inDebounceWindow = () => timerId !== void 0 || leadingController !== void 0 || currentController !== void 0;
841
+ const run = (input) => Deferred.fromPromise(
842
+ new Promise((resolve) => {
843
+ if (!inDebounceWindow()) {
844
+ firstCallAt = Date.now();
845
+ if (leading) {
846
+ fireLeading(input, resolve);
847
+ scheduleTrailing();
848
+ } else {
849
+ pendingInput = input;
850
+ pendingResolve = resolve;
851
+ scheduleTrailing();
852
+ }
853
+ } else {
854
+ const prev = pendingResolve;
855
+ pendingInput = input;
856
+ pendingResolve = resolve;
857
+ prev?.(_evictedNil);
858
+ scheduleTrailing();
859
+ }
860
+ })
861
+ );
862
+ const abort = () => {
863
+ if (timerId !== void 0) {
864
+ clearTimeout(timerId);
865
+ timerId = void 0;
866
+ pendingInput = void 0;
867
+ firstCallAt = 0;
868
+ }
869
+ const pr = pendingResolve;
870
+ pendingResolve = void 0;
871
+ const cr = currentResolve;
872
+ currentResolve = void 0;
873
+ currentController?.abort();
874
+ currentController = void 0;
875
+ const lr = leadingResolve;
876
+ leadingResolve = void 0;
877
+ leadingController?.abort();
878
+ leadingController = void 0;
879
+ if (currentState.kind !== "Idle") emit(_abortedNil);
880
+ pr?.(_abortedNil);
881
+ cr?.(_abortedNil);
882
+ lr?.(_abortedNil);
883
+ };
884
+ return {
885
+ get state() {
886
+ return currentState;
887
+ },
888
+ run,
889
+ abort,
890
+ subscribe: (cb) => {
891
+ subscribers.add(cb);
892
+ if (currentState.kind !== "Idle") cb(currentState);
893
+ return () => subscribers.delete(cb);
894
+ }
895
+ };
896
+ };
897
+ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
898
+ let currentState = _idle;
899
+ let currentController;
900
+ let currentResolve;
901
+ let cooldownTimer;
902
+ let pendingInput;
903
+ let pendingResolve;
904
+ const subscribers = /* @__PURE__ */ new Set();
905
+ const emit = (state) => {
906
+ currentState = state;
907
+ subscribers.forEach((cb) => cb(state));
908
+ };
909
+ const fireOp = (input, resolve) => {
910
+ currentResolve = resolve;
911
+ currentController = new AbortController();
912
+ const controller = currentController;
913
+ emit(_pending);
914
+ const onRetrying = retryOptions ? (r) => {
915
+ if (currentController === controller) emit(r);
916
+ } : void 0;
917
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
918
+ if (currentController !== controller) return;
919
+ const r = currentResolve;
920
+ currentResolve = void 0;
921
+ currentController = void 0;
922
+ emit(outcome);
923
+ r?.(outcome);
924
+ });
925
+ };
926
+ const startCooldown = () => {
927
+ cooldownTimer = setTimeout(() => {
928
+ cooldownTimer = void 0;
929
+ if (trailing && pendingInput !== void 0) {
930
+ const input = pendingInput;
931
+ const resolve = pendingResolve;
932
+ pendingInput = void 0;
933
+ pendingResolve = void 0;
934
+ fireOp(input, resolve);
935
+ startCooldown();
936
+ }
937
+ }, ms);
938
+ };
939
+ const run = (input) => {
940
+ if (cooldownTimer !== void 0) {
941
+ if (!trailing) {
942
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
943
+ }
944
+ return Deferred.fromPromise(
945
+ new Promise((resolve) => {
946
+ const prev = pendingResolve;
947
+ pendingInput = input;
948
+ pendingResolve = resolve;
949
+ prev?.(_evictedNil);
950
+ })
951
+ );
952
+ }
953
+ return Deferred.fromPromise(
954
+ new Promise((resolve) => {
955
+ fireOp(input, resolve);
956
+ startCooldown();
957
+ })
958
+ );
959
+ };
960
+ const abort = () => {
961
+ if (cooldownTimer !== void 0) {
962
+ clearTimeout(cooldownTimer);
963
+ cooldownTimer = void 0;
964
+ }
965
+ currentController?.abort();
966
+ currentController = void 0;
967
+ const cr = currentResolve;
968
+ currentResolve = void 0;
969
+ const pr = pendingResolve;
970
+ pendingResolve = void 0;
971
+ pendingInput = void 0;
972
+ if (currentState.kind !== "Idle") emit(_abortedNil);
973
+ cr?.(_abortedNil);
974
+ pr?.(_abortedNil);
975
+ };
976
+ return {
977
+ get state() {
978
+ return currentState;
979
+ },
980
+ run,
981
+ abort,
982
+ subscribe: (cb) => {
983
+ subscribers.add(cb);
984
+ if (currentState.kind !== "Idle") cb(currentState);
985
+ return () => subscribers.delete(cb);
986
+ }
987
+ };
988
+ };
989
+ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
990
+ let currentState = _idle;
991
+ let inflight = 0;
992
+ let generation = 0;
993
+ const controllers = /* @__PURE__ */ new Set();
994
+ const inflightResolvers = [];
995
+ const overflowQueue = [];
996
+ const subscribers = /* @__PURE__ */ new Set();
997
+ const emit = (state) => {
998
+ currentState = state;
999
+ subscribers.forEach((cb) => cb(state));
1000
+ };
1001
+ const startOne = (input, resolve, myGeneration) => {
1002
+ inflight++;
1003
+ const controller = new AbortController();
1004
+ controllers.add(controller);
1005
+ inflightResolvers.push(resolve);
1006
+ emit(_pending);
1007
+ const onRetrying = retryOptions ? (r) => {
1008
+ if (generation === myGeneration && controllers.has(controller)) emit(r);
1009
+ } : void 0;
1010
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1011
+ controllers.delete(controller);
1012
+ const idx = inflightResolvers.indexOf(resolve);
1013
+ if (idx !== -1) inflightResolvers.splice(idx, 1);
1014
+ if (generation !== myGeneration) {
1015
+ resolve(_abortedNil);
1016
+ return;
1017
+ }
1018
+ inflight--;
1019
+ emit(outcome);
1020
+ resolve(outcome);
1021
+ if (overflowQueue.length > 0) {
1022
+ const next = overflowQueue.shift();
1023
+ startOne(next.input, next.resolve, generation);
1024
+ }
1025
+ });
1026
+ };
1027
+ const run = (input) => {
1028
+ const myGeneration = generation;
1029
+ if (inflight < n) {
1030
+ return Deferred.fromPromise(
1031
+ new Promise((resolve) => {
1032
+ startOne(input, resolve, myGeneration);
1033
+ })
1034
+ );
1035
+ }
1036
+ if (overflow === "drop") {
1037
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
1038
+ }
1039
+ return Deferred.fromPromise(
1040
+ new Promise((resolve) => {
1041
+ overflowQueue.push({ input, resolve });
1042
+ emit({ kind: "Queued", position: overflowQueue.length - 1 });
1043
+ })
1044
+ );
1045
+ };
1046
+ const abort = () => {
1047
+ generation++;
1048
+ controllers.forEach((c) => c.abort());
1049
+ controllers.clear();
1050
+ const toResolve = inflightResolvers.splice(0);
1051
+ const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
1052
+ inflight = 0;
1053
+ if (currentState.kind !== "Idle") emit(_abortedNil);
1054
+ toResolve.forEach((r) => r(_abortedNil));
1055
+ queuedResolvers.forEach((r) => r(_abortedNil));
1056
+ };
1057
+ return {
1058
+ get state() {
1059
+ return currentState;
1060
+ },
1061
+ run,
1062
+ abort,
1063
+ subscribe: (cb) => {
1064
+ subscribers.add(cb);
1065
+ if (currentState.kind !== "Idle") cb(currentState);
1066
+ return () => subscribers.delete(cb);
1067
+ }
1068
+ };
1069
+ };
1070
+ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1071
+ const stateMap = /* @__PURE__ */ new Map();
1072
+ const slots = /* @__PURE__ */ new Map();
1073
+ const subscribers = /* @__PURE__ */ new Set();
1074
+ const emitSnapshot = () => {
1075
+ const snapshot = new Map(stateMap);
1076
+ subscribers.forEach((cb) => cb(snapshot));
1077
+ };
1078
+ const run = (input) => {
1079
+ const k = keyFn(input);
1080
+ if (slots.has(k)) {
1081
+ if (perKey === "exclusive") {
1082
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
1083
+ }
1084
+ const existing = slots.get(k);
1085
+ existing.controller.abort();
1086
+ const prev = existing.resolve;
1087
+ slots.delete(k);
1088
+ prev(_replacedNil);
1089
+ }
1090
+ return Deferred.fromPromise(
1091
+ new Promise((resolve) => {
1092
+ const controller = new AbortController();
1093
+ slots.set(k, { controller, resolve });
1094
+ stateMap.set(k, _pending);
1095
+ emitSnapshot();
1096
+ execute(op, input, controller, void 0, timeoutOptions, void 0).then((outcome) => {
1097
+ const slot = slots.get(k);
1098
+ if (!slot || slot.controller !== controller) {
1099
+ resolve(_abortedNil);
1100
+ return;
1101
+ }
1102
+ slots.delete(k);
1103
+ stateMap.set(k, outcome);
1104
+ emitSnapshot();
1105
+ resolve(outcome);
1106
+ });
1107
+ })
1108
+ );
1109
+ };
1110
+ const abort = (key) => {
1111
+ if (key !== void 0) {
1112
+ const slot = slots.get(key);
1113
+ if (slot) {
1114
+ slot.controller.abort();
1115
+ const r = slot.resolve;
1116
+ slots.delete(key);
1117
+ stateMap.set(key, _abortedNil);
1118
+ emitSnapshot();
1119
+ r(_abortedNil);
1120
+ }
1121
+ } else {
1122
+ const toResolve = [];
1123
+ for (const [k, slot] of slots) {
1124
+ slot.controller.abort();
1125
+ toResolve.push(slot.resolve);
1126
+ stateMap.set(k, _abortedNil);
1127
+ }
1128
+ slots.clear();
1129
+ if (toResolve.length > 0) emitSnapshot();
1130
+ toResolve.forEach((r) => r(_abortedNil));
1131
+ }
1132
+ };
1133
+ return {
1134
+ get state() {
1135
+ return new Map(stateMap);
1136
+ },
1137
+ run,
1138
+ abort,
1139
+ subscribe: (cb) => {
1140
+ subscribers.add(cb);
1141
+ if (stateMap.size > 0) cb(new Map(stateMap));
1142
+ return () => subscribers.delete(cb);
1143
+ }
1144
+ };
1145
+ };
1146
+ var makeOnce = (op, retryOptions, timeoutOptions) => {
1147
+ let currentState = _idle;
1148
+ let currentController;
1149
+ let currentResolve;
1150
+ const subscribers = /* @__PURE__ */ new Set();
1151
+ const emit = (state) => {
1152
+ currentState = state;
1153
+ subscribers.forEach((cb) => cb(state));
1154
+ };
1155
+ const run = (input) => {
1156
+ if (currentState.kind !== "Idle") {
1157
+ return Deferred.fromPromise(Promise.resolve(_droppedNil));
1158
+ }
1159
+ return Deferred.fromPromise(
1160
+ new Promise((resolve) => {
1161
+ currentResolve = resolve;
1162
+ currentController = new AbortController();
1163
+ const controller = currentController;
1164
+ emit(_pending);
1165
+ const onRetrying = retryOptions ? (r) => {
1166
+ if (currentController === controller) emit(r);
1167
+ } : void 0;
1168
+ execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1169
+ if (currentController !== controller) return;
1170
+ const r = currentResolve;
1171
+ currentResolve = void 0;
1172
+ currentController = void 0;
1173
+ emit(outcome);
1174
+ r?.(outcome);
1175
+ });
1176
+ })
1177
+ );
1178
+ };
1179
+ const abort = () => {
1180
+ currentController?.abort();
1181
+ currentController = void 0;
1182
+ const r = currentResolve;
1183
+ currentResolve = void 0;
1184
+ if (currentState.kind !== "Idle") emit(_abortedNil);
1185
+ r?.(_abortedNil);
1186
+ };
1187
+ return {
1188
+ get state() {
1189
+ return currentState;
1190
+ },
1191
+ run,
1192
+ abort,
1193
+ subscribe: (cb) => {
1194
+ subscribers.add(cb);
1195
+ if (currentState.kind !== "Idle") cb(currentState);
1196
+ return () => subscribers.delete(cb);
1197
+ }
1198
+ };
1199
+ };
1200
+
1201
+ // src/Core/Op.ts
1202
+ var Op;
1203
+ ((Op2) => {
1204
+ Op2.nil = (reason) => ({ kind: "Nil", reason });
1205
+ Op2.create = (factory, onError) => ({
1206
+ _factory: (input, signal) => Deferred.fromPromise(
1207
+ factory(input, signal).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.err(onError(e)))
1208
+ )
1209
+ });
1210
+ Op2.ok = (value) => ({ kind: "Ok", value });
1211
+ Op2.err = (error) => ({ kind: "Err", error });
1212
+ Op2.isOk = (outcome) => outcome.kind === "Ok";
1213
+ Op2.isErr = (outcome) => outcome.kind === "Err";
1214
+ Op2.isNil = (outcome) => outcome.kind === "Nil";
1215
+ Op2.match = (cases) => (outcome) => {
1216
+ if (outcome.kind === "Ok") return cases.ok(outcome.value);
1217
+ if (outcome.kind === "Err") return cases.err(outcome.error);
1218
+ return cases.nil();
1219
+ };
1220
+ Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1221
+ if (outcome.kind === "Ok") return onOk(outcome.value);
1222
+ if (outcome.kind === "Err") return onErr(outcome.error);
1223
+ return onNil();
1224
+ };
1225
+ Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "Ok" ? outcome.value : defaultValue();
1226
+ Op2.map = (f) => (outcome) => outcome.kind === "Ok" ? (0, Op2.ok)(f(outcome.value)) : outcome;
1227
+ Op2.mapError = (f) => (outcome) => outcome.kind === "Err" ? (0, Op2.err)(f(outcome.error)) : outcome;
1228
+ Op2.chain = (f) => (outcome) => outcome.kind === "Ok" ? f(outcome.value) : outcome;
1229
+ Op2.tap = (f) => (outcome) => {
1230
+ if (outcome.kind === "Ok") f(outcome.value);
1231
+ return outcome;
1232
+ };
1233
+ Op2.recover = (f) => (outcome) => outcome.kind === "Err" ? f(outcome.error) : outcome;
1234
+ Op2.toResult = (onNil) => (outcome) => {
1235
+ if (outcome.kind === "Ok") return Result.ok(outcome.value);
1236
+ if (outcome.kind === "Err") return Result.err(outcome.error);
1237
+ return Result.err(onNil());
1238
+ };
1239
+ Op2.toMaybe = (outcome) => outcome.kind === "Ok" ? Maybe.some(outcome.value) : Maybe.none();
1240
+ Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
1241
+ Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
1242
+ function interpret(op, options) {
1243
+ const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
1244
+ switch (strategy) {
1245
+ case "once":
1246
+ return makeOnce(op, retryOptions, timeoutOptions);
1247
+ case "restartable":
1248
+ return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
1249
+ case "exclusive":
1250
+ return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
1251
+ case "queue":
1252
+ return makeQueue(
1253
+ op,
1254
+ options.maxSize,
1255
+ options.overflow,
1256
+ options.concurrency,
1257
+ options.dedupe,
1258
+ retryOptions,
1259
+ timeoutOptions
1260
+ );
1261
+ case "buffered":
1262
+ return makeBuffered(op, options.size, retryOptions, timeoutOptions);
1263
+ case "debounced":
1264
+ return makeDebounced(op, options.ms ?? 0, options.leading ?? false, options.maxWait, retryOptions, timeoutOptions);
1265
+ case "throttled":
1266
+ return makeThrottled(op, options.ms ?? 0, options.trailing ?? false, retryOptions, timeoutOptions);
1267
+ case "concurrent":
1268
+ return makeConcurrent(
1269
+ op,
1270
+ options.n ?? 1,
1271
+ options.overflow ?? "drop",
1272
+ retryOptions,
1273
+ timeoutOptions
1274
+ );
1275
+ case "keyed":
1276
+ return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
1277
+ }
1278
+ }
1279
+ Op2.interpret = interpret;
1280
+ })(Op || (Op = {}));
1281
+
409
1282
  // src/Core/Optional.ts
410
1283
  var Optional;
411
1284
  ((Optional2) => {
@@ -573,77 +1446,99 @@ var RemoteData;
573
1446
  })(RemoteData || (RemoteData = {}));
574
1447
 
575
1448
  // src/Core/Task.ts
576
- var toPromise = (task) => Deferred.toPromise(task());
1449
+ var toPromise = (task, signal) => Deferred.toPromise(task(signal));
577
1450
  var Task;
578
1451
  ((Task2) => {
579
1452
  Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
580
- Task2.from = (f) => () => Deferred.fromPromise(f());
581
- Task2.map = (f) => (data) => (0, Task2.from)(() => toPromise(data).then(f));
582
- Task2.chain = (f) => (data) => (0, Task2.from)(() => toPromise(data).then((a) => toPromise(f(a))));
1453
+ Task2.from = (f) => (signal) => Deferred.fromPromise(f(signal));
1454
+ Task2.map = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then(f));
1455
+ Task2.chain = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
583
1456
  Task2.ap = (arg) => (data) => (0, Task2.from)(
584
- () => Promise.all([
585
- toPromise(data),
586
- toPromise(arg)
1457
+ (signal) => Promise.all([
1458
+ toPromise(data, signal),
1459
+ toPromise(arg, signal)
587
1460
  ]).then(([f, a]) => f(a))
588
1461
  );
589
1462
  Task2.tap = (f) => (data) => (0, Task2.from)(
590
- () => toPromise(data).then((a) => {
1463
+ (signal) => toPromise(data, signal).then((a) => {
591
1464
  f(a);
592
1465
  return a;
593
1466
  })
594
1467
  );
595
1468
  Task2.all = (tasks) => (0, Task2.from)(
596
- () => Promise.all(tasks.map((t) => toPromise(t)))
1469
+ (signal) => Promise.all(tasks.map((t) => toPromise(t, signal)))
597
1470
  );
598
1471
  Task2.delay = (ms) => (data) => (0, Task2.from)(
599
- () => new Promise(
1472
+ (signal) => new Promise(
600
1473
  (resolve2) => setTimeout(
601
- () => toPromise(data).then(resolve2),
1474
+ () => toPromise(data, signal).then(resolve2),
602
1475
  ms
603
1476
  )
604
1477
  )
605
1478
  );
606
- Task2.repeat = (options) => (task) => (0, Task2.from)(() => {
1479
+ Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
607
1480
  const { times, delay: ms } = options;
608
1481
  if (times <= 0) return Promise.resolve([]);
609
1482
  const results = [];
610
1483
  const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
611
- const run = (left) => toPromise(task).then((a) => {
1484
+ const run = (left) => toPromise(task, signal).then((a) => {
612
1485
  results.push(a);
613
1486
  if (left <= 1) return results;
614
1487
  return wait().then(() => run(left - 1));
615
1488
  });
616
1489
  return run(times);
617
1490
  });
618
- Task2.repeatUntil = (options) => (task) => (0, Task2.from)(() => {
1491
+ Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
619
1492
  const { when: predicate, delay: ms } = options;
620
1493
  const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
621
- const run = () => toPromise(task).then((a) => {
1494
+ const run = () => toPromise(task, signal).then((a) => {
622
1495
  if (predicate(a)) return a;
623
1496
  return wait().then(run);
624
1497
  });
625
1498
  return run();
626
1499
  });
627
- Task2.race = (tasks) => (0, Task2.from)(() => Promise.race(tasks.map(toPromise)));
628
- Task2.sequential = (tasks) => (0, Task2.from)(async () => {
1500
+ Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
1501
+ Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
629
1502
  const results = [];
630
1503
  for (const task of tasks) {
631
- results.push(await toPromise(task));
1504
+ results.push(await toPromise(task, signal));
632
1505
  }
633
1506
  return results;
634
1507
  });
635
- Task2.timeout = (ms, onTimeout) => (task) => (0, Task2.from)(() => {
1508
+ Task2.timeout = (ms, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
1509
+ const controller = new AbortController();
1510
+ const onOuterAbort = () => controller.abort();
1511
+ outerSignal?.addEventListener("abort", onOuterAbort, { once: true });
636
1512
  let timerId;
637
1513
  return Promise.race([
638
- toPromise(task).then((a) => {
1514
+ toPromise(task, controller.signal).then((a) => {
639
1515
  clearTimeout(timerId);
1516
+ outerSignal?.removeEventListener("abort", onOuterAbort);
640
1517
  return Result.ok(a);
641
1518
  }),
642
1519
  new Promise((resolve2) => {
643
- timerId = setTimeout(() => resolve2(Result.err(onTimeout())), ms);
1520
+ timerId = setTimeout(() => {
1521
+ controller.abort();
1522
+ outerSignal?.removeEventListener("abort", onOuterAbort);
1523
+ resolve2(Result.err(onTimeout()));
1524
+ }, ms);
644
1525
  })
645
1526
  ]);
646
1527
  });
1528
+ Task2.abortable = (factory) => {
1529
+ const controller = new AbortController();
1530
+ const task = (outerSignal) => {
1531
+ if (outerSignal) {
1532
+ if (outerSignal.aborted) {
1533
+ controller.abort(outerSignal.reason);
1534
+ } else {
1535
+ outerSignal.addEventListener("abort", () => controller.abort(outerSignal.reason), { once: true });
1536
+ }
1537
+ }
1538
+ return Deferred.fromPromise(factory(controller.signal));
1539
+ };
1540
+ return { task, abort: () => controller.abort() };
1541
+ };
647
1542
  })(Task || (Task = {}));
648
1543
 
649
1544
  // src/Core/Resource.ts
@@ -743,7 +1638,7 @@ var TaskResult;
743
1638
  TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
744
1639
  TaskResult2.err = (error) => Task.resolve(Result.err(error));
745
1640
  TaskResult2.tryCatch = (f, onError) => Task.from(
746
- () => f().then(Result.ok).catch((e) => Result.err(onError(e)))
1641
+ (signal) => f(signal).then(Result.ok).catch((e) => Result.err(onError(e)))
747
1642
  );
748
1643
  TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
749
1644
  TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
@@ -757,43 +1652,6 @@ var TaskResult;
757
1652
  )(data);
758
1653
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
759
1654
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
760
- TaskResult2.retry = (options) => (data) => Task.from(() => {
761
- const { attempts, backoff, when: shouldRetry } = options;
762
- const getDelay = (n) => backoff === void 0 ? 0 : typeof backoff === "function" ? backoff(n) : backoff;
763
- const run = (left) => Deferred.toPromise(data()).then((result) => {
764
- if (Result.isOk(result)) return result;
765
- if (left <= 1) return result;
766
- if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
767
- return result;
768
- }
769
- const ms = getDelay(attempts - left + 1);
770
- return (ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve()).then(() => run(left - 1));
771
- });
772
- return run(attempts);
773
- });
774
- TaskResult2.pollUntil = (options) => (task) => Task.from(() => {
775
- const { when: predicate, delay } = options;
776
- const getDelay = (attempt) => delay === void 0 ? 0 : typeof delay === "function" ? delay(attempt) : delay;
777
- const run = (attempt) => Deferred.toPromise(task()).then((result) => {
778
- if (Result.isErr(result)) return result;
779
- if (predicate(result.value)) return result;
780
- const ms = getDelay(attempt);
781
- return (ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve()).then(() => run(attempt + 1));
782
- });
783
- return run(1);
784
- });
785
- TaskResult2.timeout = (ms, onTimeout) => (data) => Task.from(() => {
786
- let timerId;
787
- return Promise.race([
788
- Deferred.toPromise(data()).then((result) => {
789
- clearTimeout(timerId);
790
- return result;
791
- }),
792
- new Promise((resolve) => {
793
- timerId = setTimeout(() => resolve(Result.err(onTimeout())), ms);
794
- })
795
- ]);
796
- });
797
1655
  })(TaskResult || (TaskResult = {}));
798
1656
 
799
1657
  // src/Core/Validation.ts
@@ -830,7 +1688,7 @@ var Validation;
830
1688
  return data;
831
1689
  };
832
1690
  Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
833
- Validation2.recoverUnless = (blockedErrors, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some((err) => blockedErrors.includes(err)) ? fallback() : data;
1691
+ Validation2.recoverUnless = (blockedErrors, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some((err2) => blockedErrors.includes(err2)) ? fallback() : data;
834
1692
  Validation2.product = (first, second) => {
835
1693
  if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
836
1694
  const errors = [
@@ -1333,7 +2191,7 @@ var Rec;
1333
2191
  const vals = Object.values(data);
1334
2192
  const result = {};
1335
2193
  for (let i = 0; i < keys2.length; i++) {
1336
- result[keys2[i]] = f(vals[i]);
2194
+ Object.defineProperty(result, keys2[i], { value: f(vals[i]), writable: true, enumerable: true, configurable: true });
1337
2195
  }
1338
2196
  return result;
1339
2197
  };
@@ -1342,21 +2200,30 @@ var Rec;
1342
2200
  const vals = Object.values(data);
1343
2201
  const result = {};
1344
2202
  for (let i = 0; i < keys2.length; i++) {
1345
- result[keys2[i]] = f(keys2[i], vals[i]);
2203
+ Object.defineProperty(result, keys2[i], {
2204
+ value: f(keys2[i], vals[i]),
2205
+ writable: true,
2206
+ enumerable: true,
2207
+ configurable: true
2208
+ });
1346
2209
  }
1347
2210
  return result;
1348
2211
  };
1349
2212
  Rec2.filter = (predicate) => (data) => {
1350
2213
  const result = {};
1351
2214
  for (const [k, v] of Object.entries(data)) {
1352
- if (predicate(v)) result[k] = v;
2215
+ if (predicate(v)) {
2216
+ Object.defineProperty(result, k, { value: v, writable: true, enumerable: true, configurable: true });
2217
+ }
1353
2218
  }
1354
2219
  return result;
1355
2220
  };
1356
2221
  Rec2.filterWithKey = (predicate) => (data) => {
1357
2222
  const result = {};
1358
2223
  for (const [k, v] of Object.entries(data)) {
1359
- if (predicate(k, v)) result[k] = v;
2224
+ if (predicate(k, v)) {
2225
+ Object.defineProperty(result, k, { value: v, writable: true, enumerable: true, configurable: true });
2226
+ }
1360
2227
  }
1361
2228
  return result;
1362
2229
  };
@@ -1369,8 +2236,11 @@ var Rec;
1369
2236
  const result = {};
1370
2237
  for (const item of items) {
1371
2238
  const key = keyFn(item);
1372
- if (key in result) result[key].push(item);
1373
- else result[key] = [item];
2239
+ if (Object.hasOwn(result, key)) {
2240
+ result[key].push(item);
2241
+ } else {
2242
+ Object.defineProperty(result, key, { value: [item], writable: true, enumerable: true, configurable: true });
2243
+ }
1374
2244
  }
1375
2245
  return result;
1376
2246
  };
@@ -1378,7 +2248,7 @@ var Rec;
1378
2248
  const result = {};
1379
2249
  for (const key of pickedKeys) {
1380
2250
  if (Object.hasOwn(data, key)) {
1381
- result[key] = data[key];
2251
+ Object.defineProperty(result, key, { value: data[key], writable: true, enumerable: true, configurable: true });
1382
2252
  }
1383
2253
  }
1384
2254
  return result;
@@ -1388,7 +2258,12 @@ var Rec;
1388
2258
  const result = {};
1389
2259
  for (const key of Object.keys(data)) {
1390
2260
  if (!omitSet.has(key)) {
1391
- result[key] = data[key];
2261
+ Object.defineProperty(result, key, {
2262
+ value: data[key],
2263
+ writable: true,
2264
+ enumerable: true,
2265
+ configurable: true
2266
+ });
1392
2267
  }
1393
2268
  }
1394
2269
  return result;
@@ -1402,14 +2277,16 @@ var Rec;
1402
2277
  Rec2.mapKeys = (f) => (data) => {
1403
2278
  const result = {};
1404
2279
  for (const [k, v] of Object.entries(data)) {
1405
- result[f(k)] = v;
2280
+ Object.defineProperty(result, f(k), { value: v, writable: true, enumerable: true, configurable: true });
1406
2281
  }
1407
2282
  return result;
1408
2283
  };
1409
2284
  Rec2.compact = (data) => {
1410
2285
  const result = {};
1411
2286
  for (const [k, v] of Object.entries(data)) {
1412
- if (v.kind === "Some") result[k] = v.value;
2287
+ if (v.kind === "Some") {
2288
+ Object.defineProperty(result, k, { value: v.value, writable: true, enumerable: true, configurable: true });
2289
+ }
1413
2290
  }
1414
2291
  return result;
1415
2292
  };
@@ -1542,6 +2419,7 @@ var Uniq;
1542
2419
  Logged,
1543
2420
  Maybe,
1544
2421
  Num,
2422
+ Op,
1545
2423
  Optional,
1546
2424
  Predicate,
1547
2425
  Reader,