functype 0.20.2 → 0.30.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/README.md +8 -15
- package/README.processed.md +2 -11
- package/dist/{Brand-B-0nKo7I.d.ts → Brand-BPeggBaO.d.ts} +16 -16
- package/dist/{Tuple-CKxIyX7l.d.ts → Tuple-C4maYbiO.d.ts} +8 -8
- package/dist/branded/index.d.ts +1 -1
- package/dist/cli/index.js +6 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/do/index.d.ts +3 -3
- package/dist/do/index.js +1 -1
- package/dist/either/index.d.ts +3 -3
- package/dist/either/index.js +1 -1
- package/dist/fpromise/index.d.ts +3 -3
- package/dist/fpromise/index.js +1 -1
- package/dist/{index-Bnjlo4cT.d.ts → index-BiUAv9kR.d.ts} +1584 -341
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/list/index.d.ts +3 -3
- package/dist/list/index.js +1 -1
- package/dist/map/index.d.ts +3 -3
- package/dist/map/index.js +1 -1
- package/dist/option/index.d.ts +3 -3
- package/dist/option/index.js +1 -1
- package/dist/set/index.d.ts +3 -3
- package/dist/set/index.js +1 -1
- package/dist/src-BeaSFZFq.js +20 -0
- package/dist/src-BeaSFZFq.js.map +1 -0
- package/dist/try/index.d.ts +3 -3
- package/dist/try/index.js +1 -1
- package/dist/tuple/index.d.ts +1 -1
- package/package.json +10 -4
- package/dist/src-BOxI0-73.js +0 -20
- package/dist/src-BOxI0-73.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Brand } from "./Brand-
|
|
2
|
-
import { c as Pipe, l as Foldable, o as Serializable, r as Typeable, t as Tuple, u as Type } from "./Tuple-
|
|
1
|
+
import { t as Brand } from "./Brand-BPeggBaO.js";
|
|
2
|
+
import { c as Pipe, l as Foldable, o as Serializable, r as Typeable, t as Tuple, u as Type } from "./Tuple-C4maYbiO.js";
|
|
3
3
|
|
|
4
4
|
//#region src/do/protocol.d.ts
|
|
5
5
|
|
|
@@ -11,9 +11,9 @@ import { c as Pipe, l as Foldable, o as Serializable, r as Typeable, t as Tuple,
|
|
|
11
11
|
* Result type for Do-notation unwrapping
|
|
12
12
|
* Indicates whether unwrapping succeeded and provides the value or error
|
|
13
13
|
*/
|
|
14
|
-
type DoResult<T
|
|
14
|
+
type DoResult<T> = {
|
|
15
15
|
ok: true;
|
|
16
|
-
value: T
|
|
16
|
+
value: T;
|
|
17
17
|
} | {
|
|
18
18
|
ok: false;
|
|
19
19
|
empty: true;
|
|
@@ -29,8 +29,8 @@ type DoResult<T$1> = {
|
|
|
29
29
|
* The doUnwrap method should return a DoResult indicating success/failure
|
|
30
30
|
* and the contained value or error information
|
|
31
31
|
*/
|
|
32
|
-
interface Doable<T
|
|
33
|
-
doUnwrap(): DoResult<T
|
|
32
|
+
interface Doable<T> {
|
|
33
|
+
doUnwrap(): DoResult<T>;
|
|
34
34
|
}
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/extractable/Extractable.d.ts
|
|
@@ -41,14 +41,14 @@ interface Doable<T$1> {
|
|
|
41
41
|
* @interface Unsafe
|
|
42
42
|
* @template T The type of value that can be extracted
|
|
43
43
|
*/
|
|
44
|
-
interface Unsafe<T
|
|
44
|
+
interface Unsafe<T extends Type> {
|
|
45
45
|
/**
|
|
46
46
|
* Extract the value or throw an error
|
|
47
47
|
* @param error Optional custom error to throw. If not provided, uses type-appropriate default error
|
|
48
48
|
* @throws {Error} The specified error, container's error, or a sensible default
|
|
49
49
|
* @returns The contained value
|
|
50
50
|
*/
|
|
51
|
-
orThrow(error?: Error): T
|
|
51
|
+
orThrow(error?: Error): T;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Extractable type class for data structures that can extract their values
|
|
@@ -59,34 +59,34 @@ interface Unsafe<T$1 extends Type> {
|
|
|
59
59
|
*
|
|
60
60
|
* Extends Unsafe to provide exception-throwing operations alongside safe alternatives.
|
|
61
61
|
*/
|
|
62
|
-
interface Extractable<T
|
|
62
|
+
interface Extractable<T extends Type> extends Unsafe<T> {
|
|
63
63
|
/**
|
|
64
64
|
* Returns the contained value or a default value
|
|
65
65
|
* @param defaultValue - The value to return if extraction fails
|
|
66
66
|
* @returns The contained value or defaultValue
|
|
67
67
|
*/
|
|
68
|
-
orElse(defaultValue: T
|
|
68
|
+
orElse(defaultValue: T): T;
|
|
69
69
|
/**
|
|
70
70
|
* Returns this container if it has a value, otherwise returns the alternative container
|
|
71
71
|
* @param alternative - The alternative container
|
|
72
72
|
* @returns This container or the alternative
|
|
73
73
|
*/
|
|
74
|
-
or(alternative: Extractable<T
|
|
74
|
+
or(alternative: Extractable<T>): Extractable<T>;
|
|
75
75
|
/**
|
|
76
76
|
* Returns the contained value or null
|
|
77
77
|
* @returns The contained value or null
|
|
78
78
|
*/
|
|
79
|
-
orNull(): T
|
|
79
|
+
orNull(): T | null;
|
|
80
80
|
/**
|
|
81
81
|
* Returns the contained value or undefined
|
|
82
82
|
* @returns The contained value or undefined
|
|
83
83
|
*/
|
|
84
|
-
orUndefined(): T
|
|
84
|
+
orUndefined(): T | undefined;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Type guard to check if a value implements Extractable
|
|
88
88
|
*/
|
|
89
|
-
declare function isExtractable<T
|
|
89
|
+
declare function isExtractable<T extends Type>(value: unknown): value is Extractable<T>;
|
|
90
90
|
//#endregion
|
|
91
91
|
//#region src/list/LazyList.d.ts
|
|
92
92
|
/**
|
|
@@ -372,37 +372,37 @@ interface Promisable<A extends Type> {
|
|
|
372
372
|
* Possible types of Try instances
|
|
373
373
|
*/
|
|
374
374
|
type TypeNames = "Success" | "Failure";
|
|
375
|
-
interface Try<T
|
|
375
|
+
interface Try<T> extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
376
376
|
readonly _tag: TypeNames;
|
|
377
377
|
readonly error: Error | undefined;
|
|
378
|
-
isSuccess(): this is Try<T
|
|
378
|
+
isSuccess(): this is Try<T> & {
|
|
379
379
|
readonly _tag: "Success";
|
|
380
380
|
error: undefined;
|
|
381
381
|
};
|
|
382
|
-
isFailure(): this is Try<T
|
|
382
|
+
isFailure(): this is Try<T> & {
|
|
383
383
|
readonly _tag: "Failure";
|
|
384
384
|
error: Error;
|
|
385
385
|
};
|
|
386
|
-
orElse: (defaultValue: T
|
|
387
|
-
orThrow: (error?: Error) => T
|
|
388
|
-
or: (alternative: Try<T
|
|
389
|
-
orNull: () => T
|
|
390
|
-
orUndefined: () => T
|
|
391
|
-
toOption: () => Option<T
|
|
392
|
-
toEither: <E extends Type>(leftValue: E) => Either<E, T
|
|
393
|
-
toList: () => List<T
|
|
394
|
-
toTry: () => Try<T
|
|
395
|
-
map: <U>(f: (value: T
|
|
396
|
-
ap: <U>(ff: Try<(value: T
|
|
397
|
-
flatMap: <U>(f: (value: T
|
|
398
|
-
flatMapAsync: <U>(f: (value: T
|
|
386
|
+
orElse: (defaultValue: T) => T;
|
|
387
|
+
orThrow: (error?: Error) => T;
|
|
388
|
+
or: (alternative: Try<T>) => Try<T>;
|
|
389
|
+
orNull: () => T | null;
|
|
390
|
+
orUndefined: () => T | undefined;
|
|
391
|
+
toOption: () => Option<T>;
|
|
392
|
+
toEither: <E extends Type>(leftValue: E) => Either<E, T>;
|
|
393
|
+
toList: () => List<T>;
|
|
394
|
+
toTry: () => Try<T>;
|
|
395
|
+
map: <U>(f: (value: T) => U) => Try<U>;
|
|
396
|
+
ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
|
|
397
|
+
flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
|
|
398
|
+
flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
|
|
399
399
|
/**
|
|
400
400
|
* Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
|
|
401
401
|
* @param onFailure - Function to apply if the Try is Failure
|
|
402
402
|
* @param onSuccess - Function to apply if the Try is Success
|
|
403
403
|
* @returns The result of applying the appropriate function
|
|
404
404
|
*/
|
|
405
|
-
fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T
|
|
405
|
+
fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
|
|
406
406
|
toString: () => string;
|
|
407
407
|
/**
|
|
408
408
|
* Pattern matches over the Try, applying a handler function based on the variant
|
|
@@ -410,21 +410,21 @@ interface Try<T$1> extends FunctypeBase<T$1, TypeNames>, Extractable<T$1>, Pipe<
|
|
|
410
410
|
* @returns The result of applying the matching handler function
|
|
411
411
|
*/
|
|
412
412
|
match<R$1>(patterns: {
|
|
413
|
-
Success: (value: T
|
|
413
|
+
Success: (value: T) => R$1;
|
|
414
414
|
Failure: (error: Error) => R$1;
|
|
415
415
|
}): R$1;
|
|
416
416
|
toValue(): {
|
|
417
417
|
_tag: TypeNames;
|
|
418
|
-
value: T
|
|
418
|
+
value: T | Error;
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
|
-
declare const Try: (<T
|
|
421
|
+
declare const Try: (<T>(f: () => T) => Try<T>) & {
|
|
422
422
|
/**
|
|
423
423
|
* Type guard to check if a Try is Success
|
|
424
424
|
* @param tryValue - The Try to check
|
|
425
425
|
* @returns True if Try is Success
|
|
426
426
|
*/
|
|
427
|
-
isSuccess: <T
|
|
427
|
+
isSuccess: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
428
428
|
readonly _tag: "Success";
|
|
429
429
|
error: undefined;
|
|
430
430
|
};
|
|
@@ -433,7 +433,7 @@ declare const Try: (<T$1>(f: () => T$1) => Try<T$1>) & {
|
|
|
433
433
|
* @param tryValue - The Try to check
|
|
434
434
|
* @returns True if Try is Failure
|
|
435
435
|
*/
|
|
436
|
-
isFailure: <T
|
|
436
|
+
isFailure: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
437
437
|
readonly _tag: "Failure";
|
|
438
438
|
error: Error;
|
|
439
439
|
};
|
|
@@ -442,19 +442,19 @@ declare const Try: (<T$1>(f: () => T$1) => Try<T$1>) & {
|
|
|
442
442
|
* @param json - The JSON string
|
|
443
443
|
* @returns Try instance
|
|
444
444
|
*/
|
|
445
|
-
fromJSON: <T
|
|
445
|
+
fromJSON: <T>(json: string) => Try<T>;
|
|
446
446
|
/**
|
|
447
447
|
* Creates a Try from YAML string
|
|
448
448
|
* @param yaml - The YAML string
|
|
449
449
|
* @returns Try instance
|
|
450
450
|
*/
|
|
451
|
-
fromYAML: <T
|
|
451
|
+
fromYAML: <T>(yaml: string) => Try<T>;
|
|
452
452
|
/**
|
|
453
453
|
* Creates a Try from binary string
|
|
454
454
|
* @param binary - The binary string
|
|
455
455
|
* @returns Try instance
|
|
456
456
|
*/
|
|
457
|
-
fromBinary: <T
|
|
457
|
+
fromBinary: <T>(binary: string) => Try<T>;
|
|
458
458
|
};
|
|
459
459
|
//#endregion
|
|
460
460
|
//#region src/reshapeable/Reshapeable.d.ts
|
|
@@ -491,7 +491,7 @@ declare const Try: (<T$1>(f: () => T$1) => Try<T$1>) & {
|
|
|
491
491
|
* const asOption = result.toOption()
|
|
492
492
|
* asOption.map(x => x * 2).orElse(0)
|
|
493
493
|
*/
|
|
494
|
-
interface Reshapeable<T
|
|
494
|
+
interface Reshapeable<T extends Type> {
|
|
495
495
|
/**
|
|
496
496
|
* Converts this monad to an Option.
|
|
497
497
|
*
|
|
@@ -503,7 +503,7 @@ interface Reshapeable<T$1 extends Type> {
|
|
|
503
503
|
*
|
|
504
504
|
* @returns An Option containing the value if present, None otherwise
|
|
505
505
|
*/
|
|
506
|
-
toOption(): Option<T
|
|
506
|
+
toOption(): Option<T>;
|
|
507
507
|
/**
|
|
508
508
|
* Converts this monad to an Either.
|
|
509
509
|
*
|
|
@@ -516,7 +516,7 @@ interface Reshapeable<T$1 extends Type> {
|
|
|
516
516
|
* @param leftValue - The value to use for the Left case when the source is empty/none/failure
|
|
517
517
|
* @returns An Either with the value as Right or the provided leftValue as Left
|
|
518
518
|
*/
|
|
519
|
-
toEither<E extends Type>(leftValue: E): Either<E, T
|
|
519
|
+
toEither<E extends Type>(leftValue: E): Either<E, T>;
|
|
520
520
|
/**
|
|
521
521
|
* Converts this monad to a List.
|
|
522
522
|
*
|
|
@@ -528,7 +528,7 @@ interface Reshapeable<T$1 extends Type> {
|
|
|
528
528
|
*
|
|
529
529
|
* @returns A List containing the value(s) if present, empty List otherwise
|
|
530
530
|
*/
|
|
531
|
-
toList(): List<T
|
|
531
|
+
toList(): List<T>;
|
|
532
532
|
/**
|
|
533
533
|
* Converts this monad to a Try.
|
|
534
534
|
*
|
|
@@ -540,22 +540,22 @@ interface Reshapeable<T$1 extends Type> {
|
|
|
540
540
|
*
|
|
541
541
|
* @returns A Try containing Success with the value or Failure with an appropriate error
|
|
542
542
|
*/
|
|
543
|
-
toTry(): Try<T
|
|
543
|
+
toTry(): Try<T>;
|
|
544
544
|
}
|
|
545
545
|
//#endregion
|
|
546
546
|
//#region src/branded/ValidatedBrand.d.ts
|
|
547
|
-
type ValidatedBrand<K$1 extends string, T
|
|
547
|
+
type ValidatedBrand<K$1 extends string, T> = Brand<K$1, T> & {
|
|
548
548
|
readonly __validated: true;
|
|
549
549
|
};
|
|
550
|
-
interface ValidatedBrandCompanion<K$1 extends string, T
|
|
550
|
+
interface ValidatedBrandCompanion<K$1 extends string, T> {
|
|
551
551
|
readonly brand: K$1;
|
|
552
|
-
readonly validate: (value: T
|
|
553
|
-
readonly of: (value: T
|
|
554
|
-
readonly from: (value: T
|
|
555
|
-
readonly unsafeOf: (value: T
|
|
556
|
-
readonly is: (value: unknown) => value is ValidatedBrand<K$1, T
|
|
557
|
-
readonly unwrap: (branded: Brand<K$1, T
|
|
558
|
-
readonly refine: <K2 extends string>(brand: K2, validate: (value: Brand<K$1, T
|
|
552
|
+
readonly validate: (value: T) => boolean;
|
|
553
|
+
readonly of: (value: T) => Option<ValidatedBrand<K$1, T>>;
|
|
554
|
+
readonly from: (value: T) => Either<string, ValidatedBrand<K$1, T>>;
|
|
555
|
+
readonly unsafeOf: (value: T) => ValidatedBrand<K$1, T>;
|
|
556
|
+
readonly is: (value: unknown) => value is ValidatedBrand<K$1, T>;
|
|
557
|
+
readonly unwrap: (branded: Brand<K$1, T>) => T;
|
|
558
|
+
readonly refine: <K2 extends string>(brand: K2, validate: (value: Brand<K$1, T>) => boolean) => ValidatedBrandCompanion<K2, Brand<K$1, T>>;
|
|
559
559
|
}
|
|
560
560
|
/**
|
|
561
561
|
* Create a validated brand with runtime validation
|
|
@@ -590,7 +590,7 @@ interface ValidatedBrandCompanion<K$1 extends string, T$1> {
|
|
|
590
590
|
* // ❌ ValidatedBrand("ValidatedUserId", ...) + Brand<"UserId", string>
|
|
591
591
|
* // ✅ ValidatedBrand("UserId", ...) + Brand<"UserId", string>
|
|
592
592
|
*/
|
|
593
|
-
declare function ValidatedBrand<K$1 extends string, T
|
|
593
|
+
declare function ValidatedBrand<K$1 extends string, T>(brand: K$1, validate: (value: T) => boolean): ValidatedBrandCompanion<K$1, T>;
|
|
594
594
|
/**
|
|
595
595
|
* Positive number brand (> 0)
|
|
596
596
|
* @example
|
|
@@ -703,7 +703,7 @@ declare function Companion<ObjectF extends object, CompanionF extends object>(ob
|
|
|
703
703
|
* // { from: ..., none: ..., fromJSON: ..., etc. }
|
|
704
704
|
* ```
|
|
705
705
|
*/
|
|
706
|
-
type CompanionMethods<T
|
|
706
|
+
type CompanionMethods<T> = T extends ((...args: never[]) => unknown) & infer C ? C : never;
|
|
707
707
|
/**
|
|
708
708
|
* Extracts the instance type from a constructor function
|
|
709
709
|
* @typeParam T - The constructor function type
|
|
@@ -713,7 +713,7 @@ type CompanionMethods<T$1> = T$1 extends ((...args: never[]) => unknown) & infer
|
|
|
713
713
|
* // Option<T>
|
|
714
714
|
* ```
|
|
715
715
|
*/
|
|
716
|
-
type InstanceType<T
|
|
716
|
+
type InstanceType<T> = T extends ((...args: infer Args) => infer R) ? R extends ((...args: unknown[]) => unknown) ? ReturnType<R> : R : never;
|
|
717
717
|
/**
|
|
718
718
|
* Type guard to check if a value is a Companion object (has both constructor and companion methods)
|
|
719
719
|
* @param value - The value to check
|
|
@@ -740,29 +740,29 @@ declare const isCompanion: (value: unknown) => value is ((...args: never[]) => u
|
|
|
740
740
|
* .elseWhen(response.status >= 200, "Success")
|
|
741
741
|
* .else("Unknown")
|
|
742
742
|
*/
|
|
743
|
-
type Cond<T
|
|
743
|
+
type Cond<T extends Type> = {
|
|
744
744
|
/**
|
|
745
745
|
* Add an if condition
|
|
746
746
|
*/
|
|
747
|
-
when: (condition: boolean, value: T
|
|
747
|
+
when: (condition: boolean, value: T | (() => T)) => Cond<T>;
|
|
748
748
|
/**
|
|
749
749
|
* Add an else-if condition
|
|
750
750
|
*/
|
|
751
|
-
elseWhen: (condition: boolean, value: T
|
|
751
|
+
elseWhen: (condition: boolean, value: T | (() => T)) => Cond<T>;
|
|
752
752
|
/**
|
|
753
753
|
* Terminal else clause - required to get the result
|
|
754
754
|
*/
|
|
755
|
-
else: (value: T
|
|
755
|
+
else: (value: T | (() => T)) => T;
|
|
756
756
|
/**
|
|
757
757
|
* Get the result if a condition was met, throws if no condition met
|
|
758
758
|
*/
|
|
759
|
-
orThrow: () => T
|
|
759
|
+
orThrow: () => T;
|
|
760
760
|
};
|
|
761
761
|
/** @internal */
|
|
762
|
-
type LazyCondChain<T
|
|
763
|
-
when: (condition: () => boolean, value: () => T
|
|
764
|
-
elseWhen: (condition: () => boolean, value: () => T
|
|
765
|
-
else: (value: () => T
|
|
762
|
+
type LazyCondChain<T> = {
|
|
763
|
+
when: (condition: () => boolean, value: () => T) => LazyCondChain<T>;
|
|
764
|
+
elseWhen: (condition: () => boolean, value: () => T) => LazyCondChain<T>;
|
|
765
|
+
else: (value: () => T) => T;
|
|
766
766
|
};
|
|
767
767
|
/**
|
|
768
768
|
* Conditional expression builder for functional if/else chains
|
|
@@ -788,7 +788,7 @@ type LazyCondChain<T$1> = {
|
|
|
788
788
|
* .when(() => checkCondition2(), () => "Result 2")
|
|
789
789
|
* .else(() => "Default")
|
|
790
790
|
*/
|
|
791
|
-
declare const Cond: (<T
|
|
791
|
+
declare const Cond: (<T extends Type>() => Cond<T>) & {
|
|
792
792
|
/**
|
|
793
793
|
* Create a conditional expression that must end with else
|
|
794
794
|
* @example
|
|
@@ -806,7 +806,7 @@ declare const Cond: (<T$1 extends Type>() => Cond<T$1>) & {
|
|
|
806
806
|
* .when(isLoyal, () => calculateLoyaltyDiscount())
|
|
807
807
|
* .else(0)
|
|
808
808
|
*/
|
|
809
|
-
of: <T
|
|
809
|
+
of: <T extends Type>() => Cond<T>;
|
|
810
810
|
/**
|
|
811
811
|
* Pattern matching helper that ensures exhaustiveness
|
|
812
812
|
* @example
|
|
@@ -828,7 +828,7 @@ declare const Cond: (<T$1 extends Type>() => Cond<T$1>) & {
|
|
|
828
828
|
* "skip": () => defaultValue
|
|
829
829
|
* })
|
|
830
830
|
*/
|
|
831
|
-
match: <T
|
|
831
|
+
match: <T extends string | number | symbol>(value: T) => <R$1 extends Type>(cases: Record<T, R$1 | (() => R$1)>) => R$1;
|
|
832
832
|
/**
|
|
833
833
|
* Create a lazy conditional that defers evaluation
|
|
834
834
|
* @example
|
|
@@ -851,7 +851,7 @@ declare const Cond: (<T$1 extends Type>() => Cond<T$1>) & {
|
|
|
851
851
|
* )
|
|
852
852
|
* .else(() => ({ type: "guest", permissions: [] }))
|
|
853
853
|
*/
|
|
854
|
-
lazy: <T
|
|
854
|
+
lazy: <T extends Type>() => LazyCondChain<T>;
|
|
855
855
|
};
|
|
856
856
|
//#endregion
|
|
857
857
|
//#region src/conditional/Match.d.ts
|
|
@@ -861,21 +861,21 @@ declare const Cond: (<T$1 extends Type>() => Cond<T$1>) & {
|
|
|
861
861
|
*/
|
|
862
862
|
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
863
863
|
/** @internal */
|
|
864
|
-
type IsUnion<T
|
|
864
|
+
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
865
865
|
/** @internal */
|
|
866
|
-
type RequireExhaustive<T
|
|
866
|
+
type RequireExhaustive<T, Cases> = IsUnion<T> extends true ? (keyof Cases extends T ? (T extends keyof Cases ? Cases : never) : never) : Cases;
|
|
867
867
|
/**
|
|
868
868
|
* Pattern types for nested matching
|
|
869
869
|
* @internal
|
|
870
870
|
*/
|
|
871
|
-
type Pattern<T
|
|
872
|
-
_: (value: T
|
|
871
|
+
type Pattern<T> = T | { [K in keyof T]?: Pattern<T[K]> } | ((value: T) => boolean) | {
|
|
872
|
+
_: (value: T) => boolean;
|
|
873
873
|
};
|
|
874
874
|
/**
|
|
875
875
|
* Extract result from pattern
|
|
876
876
|
* @internal
|
|
877
877
|
*/
|
|
878
|
-
type PatternResult<T
|
|
878
|
+
type PatternResult<T, R$1> = R$1 | ((matched: T) => R$1);
|
|
879
879
|
/**
|
|
880
880
|
* Pattern matching construct similar to Scala's match expressions.
|
|
881
881
|
* Supports exhaustive matching, nested patterns, and guards.
|
|
@@ -903,31 +903,31 @@ type PatternResult<T$1, R$1> = R$1 | ((matched: T$1) => R$1);
|
|
|
903
903
|
* .case({ role: "user" }, u => `User: ${u.name}`)
|
|
904
904
|
* .default("Guest")
|
|
905
905
|
*/
|
|
906
|
-
type Match<T
|
|
906
|
+
type Match<T extends Type, R$1 extends Type> = {
|
|
907
907
|
/**
|
|
908
908
|
* Match against a pattern (value, nested object, or predicate)
|
|
909
909
|
*/
|
|
910
|
-
case: (pattern: Pattern<T
|
|
910
|
+
case: (pattern: Pattern<T>, result: PatternResult<T, R$1>) => Match<T, R$1>;
|
|
911
911
|
/**
|
|
912
912
|
* Add a case that matches a specific value (backward compatibility)
|
|
913
913
|
*/
|
|
914
|
-
caseValue: (match: T
|
|
914
|
+
caseValue: (match: T, result: R$1 | (() => R$1)) => Match<T, R$1>;
|
|
915
915
|
/**
|
|
916
916
|
* Add a case that matches multiple values (backward compatibility)
|
|
917
917
|
*/
|
|
918
|
-
caseValues: (matches: T
|
|
918
|
+
caseValues: (matches: T[], result: R$1 | (() => R$1)) => Match<T, R$1>;
|
|
919
919
|
/**
|
|
920
920
|
* Match with a guard function (alias for readability)
|
|
921
921
|
*/
|
|
922
|
-
when: (guard: (value: T
|
|
922
|
+
when: (guard: (value: T) => boolean, result: PatternResult<T, R$1>) => Match<T, R$1>;
|
|
923
923
|
/**
|
|
924
924
|
* Match multiple patterns (OR operation)
|
|
925
925
|
*/
|
|
926
|
-
caseAny: (patterns: Pattern<T
|
|
926
|
+
caseAny: (patterns: Pattern<T>[], result: PatternResult<T, R$1>) => Match<T, R$1>;
|
|
927
927
|
/**
|
|
928
928
|
* Default case - makes match non-exhaustive
|
|
929
929
|
*/
|
|
930
|
-
default: (result: PatternResult<T
|
|
930
|
+
default: (result: PatternResult<T, R$1>) => R$1;
|
|
931
931
|
/**
|
|
932
932
|
* Force exhaustive matching (compile-time check for union types)
|
|
933
933
|
*/
|
|
@@ -981,7 +981,7 @@ type Match<T$1 extends Type, R$1 extends Type> = {
|
|
|
981
981
|
* .case("error", "Failed!")
|
|
982
982
|
* .exhaustive()
|
|
983
983
|
*/
|
|
984
|
-
declare const Match: (<T
|
|
984
|
+
declare const Match: (<T extends Type, R$1 extends Type>(value: T) => Match<T, R$1>) & {
|
|
985
985
|
/**
|
|
986
986
|
* Create a type-safe exhaustive match for union types
|
|
987
987
|
* @example
|
|
@@ -1005,7 +1005,7 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1005
1005
|
* const compute = ops("multiply").fn
|
|
1006
1006
|
* const result = compute(4, 5) // 20
|
|
1007
1007
|
*/
|
|
1008
|
-
exhaustive: <T
|
|
1008
|
+
exhaustive: <T extends string | number | symbol, R$1 extends Type>(cases: RequireExhaustive<T, Record<T, R$1>>) => (value: T) => R$1;
|
|
1009
1009
|
/**
|
|
1010
1010
|
* Create a partial match that requires a default
|
|
1011
1011
|
* @example
|
|
@@ -1027,8 +1027,8 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1027
1027
|
* }).withDefault((n) => `Number: ${n}`)
|
|
1028
1028
|
* getMessage(5) // "Number: 5"
|
|
1029
1029
|
*/
|
|
1030
|
-
partial: <T
|
|
1031
|
-
withDefault: (defaultValue: R$1 | ((value: T
|
|
1030
|
+
partial: <T extends string | number | symbol, R$1 extends Type>(cases: Partial<Record<T, R$1 | ((value: T) => R$1)>>) => {
|
|
1031
|
+
withDefault: (defaultValue: R$1 | ((value: T) => R$1)) => (value: T) => R$1;
|
|
1032
1032
|
};
|
|
1033
1033
|
/**
|
|
1034
1034
|
* Pattern match with guards
|
|
@@ -1053,8 +1053,8 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1053
1053
|
* ]).withDefault("Unknown")(age)
|
|
1054
1054
|
* // category = "Adult (25 years)"
|
|
1055
1055
|
*/
|
|
1056
|
-
withGuards: <T
|
|
1057
|
-
withDefault: (defaultValue: R$1 | ((value: T
|
|
1056
|
+
withGuards: <T extends Type, R$1 extends Type>(guards: Array<[(value: T) => boolean, R$1 | ((value: T) => R$1)]>) => {
|
|
1057
|
+
withDefault: (defaultValue: R$1 | ((value: T) => R$1)) => (value: T) => R$1;
|
|
1058
1058
|
};
|
|
1059
1059
|
/**
|
|
1060
1060
|
* Pattern matching for objects with specific structure
|
|
@@ -1070,9 +1070,9 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1070
1070
|
* .case({ type: "hover" }, (e) => console.log(`Hovering over ${e.element}`))
|
|
1071
1071
|
* .build()
|
|
1072
1072
|
*/
|
|
1073
|
-
struct: <T
|
|
1074
|
-
case: (pattern: Pattern<T
|
|
1075
|
-
build: () => (value: T
|
|
1073
|
+
struct: <T extends Type, R$1 extends Type>() => {
|
|
1074
|
+
case: (pattern: Pattern<T>, handler: (value: T) => R$1) => /*elided*/any;
|
|
1075
|
+
build: () => (value: T) => R$1;
|
|
1076
1076
|
};
|
|
1077
1077
|
/**
|
|
1078
1078
|
* Create a pattern matcher with guards and nested patterns
|
|
@@ -1089,11 +1089,11 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1089
1089
|
* .default(false)
|
|
1090
1090
|
* .build()
|
|
1091
1091
|
*/
|
|
1092
|
-
builder: <T
|
|
1093
|
-
case: (pattern: Pattern<T
|
|
1094
|
-
when: (guard: (value: T
|
|
1095
|
-
default: (result: PatternResult<T
|
|
1096
|
-
build: () => (value: T
|
|
1092
|
+
builder: <T extends Type, R$1 extends Type>() => {
|
|
1093
|
+
case: (pattern: Pattern<T>, result: PatternResult<T, R$1>) => /*elided*/any;
|
|
1094
|
+
when: (guard: (value: T) => boolean, result: PatternResult<T, R$1>) => /*elided*/any;
|
|
1095
|
+
default: (result: PatternResult<T, R$1>) => {
|
|
1096
|
+
build: () => (value: T) => R$1;
|
|
1097
1097
|
};
|
|
1098
1098
|
};
|
|
1099
1099
|
};
|
|
@@ -1105,7 +1105,7 @@ declare const Match: (<T$1 extends Type, R$1 extends Type>(value: T$1) => Match<
|
|
|
1105
1105
|
* @param type - The type name for the object
|
|
1106
1106
|
* @param body - The implementation body
|
|
1107
1107
|
*/
|
|
1108
|
-
declare function Base<T
|
|
1108
|
+
declare function Base<T extends Record<string, unknown>>(type: string, body: T): T & {
|
|
1109
1109
|
toString(): string;
|
|
1110
1110
|
doUnwrap(): DoResult<unknown>;
|
|
1111
1111
|
_tag: string;
|
|
@@ -1184,22 +1184,22 @@ type ErrorContext = {
|
|
|
1184
1184
|
/**
|
|
1185
1185
|
* FPromise type that defines the function signature and methods
|
|
1186
1186
|
*/
|
|
1187
|
-
type FPromise<T
|
|
1187
|
+
type FPromise<T extends Type, E extends Type = unknown> = PromiseLike<T> & {
|
|
1188
1188
|
readonly _tag: "FPromise";
|
|
1189
|
-
tap: (f: (value: T
|
|
1190
|
-
mapError: <E2>(f: (error: E, context: ErrorContext) => E2) => FPromise<T
|
|
1191
|
-
tapError: (f: (error: E) => void) => FPromise<T
|
|
1192
|
-
recover: (fallback: T
|
|
1193
|
-
recoverWith: (f: (error: E) => T
|
|
1194
|
-
recoverWithF: <E2>(f: (error: E) => FPromise<T
|
|
1195
|
-
filterError: <E2 extends E>(predicate: (error: E) => boolean, handler: (error: E) => FPromise<T
|
|
1196
|
-
logError: (logger: (error: E, context: ErrorContext) => void) => FPromise<T
|
|
1197
|
-
toPromise: () => Promise<T
|
|
1198
|
-
toEither: () => Promise<Either<E, T
|
|
1199
|
-
fold: <R$1 extends Type>(onError: (error: E) => R$1, onSuccess: (value: T
|
|
1200
|
-
map: <U extends Type>(f: (value: T
|
|
1201
|
-
flatMap: <U extends Type>(f: (value: T
|
|
1202
|
-
flatMapAsync: <U extends Type>(f: (value: T
|
|
1189
|
+
tap: (f: (value: T) => void) => FPromise<T, E>;
|
|
1190
|
+
mapError: <E2>(f: (error: E, context: ErrorContext) => E2) => FPromise<T, E2>;
|
|
1191
|
+
tapError: (f: (error: E) => void) => FPromise<T, E>;
|
|
1192
|
+
recover: (fallback: T) => FPromise<T, never>;
|
|
1193
|
+
recoverWith: (f: (error: E) => T) => FPromise<T, never>;
|
|
1194
|
+
recoverWithF: <E2>(f: (error: E) => FPromise<T, E2>) => FPromise<T, E2>;
|
|
1195
|
+
filterError: <E2 extends E>(predicate: (error: E) => boolean, handler: (error: E) => FPromise<T, E2>) => FPromise<T, E>;
|
|
1196
|
+
logError: (logger: (error: E, context: ErrorContext) => void) => FPromise<T, E>;
|
|
1197
|
+
toPromise: () => Promise<T>;
|
|
1198
|
+
toEither: () => Promise<Either<E, T>>;
|
|
1199
|
+
fold: <R$1 extends Type>(onError: (error: E) => R$1, onSuccess: (value: T) => R$1) => FPromise<R$1, never>;
|
|
1200
|
+
map: <U extends Type>(f: (value: T) => U) => FPromise<U, E>;
|
|
1201
|
+
flatMap: <U extends Type>(f: (value: T) => FPromise<U, E> | PromiseLike<U>) => FPromise<U, E>;
|
|
1202
|
+
flatMapAsync: <U extends Type>(f: (value: T) => PromiseLike<U>) => Promise<U>;
|
|
1203
1203
|
};
|
|
1204
1204
|
/**
|
|
1205
1205
|
* Static utility methods for FPromise using the Companion pattern.
|
|
@@ -1218,7 +1218,7 @@ declare const FPromiseCompanion: {
|
|
|
1218
1218
|
* const promise = FPromise.resolve(42)
|
|
1219
1219
|
* // promise resolves to 42
|
|
1220
1220
|
*/
|
|
1221
|
-
resolve: <T
|
|
1221
|
+
resolve: <T, E = never>(value: T | PromiseLike<T>) => FPromise<T, E>;
|
|
1222
1222
|
/**
|
|
1223
1223
|
* Creates an FPromise that rejects with the provided reason.
|
|
1224
1224
|
*
|
|
@@ -1231,7 +1231,7 @@ declare const FPromiseCompanion: {
|
|
|
1231
1231
|
* const promise = FPromise.reject<number, Error>(new Error("Something went wrong"))
|
|
1232
1232
|
* // promise rejects with Error("Something went wrong")
|
|
1233
1233
|
*/
|
|
1234
|
-
reject: <T
|
|
1234
|
+
reject: <T, E = unknown>(reason: E) => FPromise<T, E>;
|
|
1235
1235
|
/**
|
|
1236
1236
|
* Creates an FPromise from a regular Promise.
|
|
1237
1237
|
*
|
|
@@ -1244,7 +1244,7 @@ declare const FPromiseCompanion: {
|
|
|
1244
1244
|
* const promise = FPromise.from(fetch("https://api.example.com/data"))
|
|
1245
1245
|
* // promise is an FPromise that resolves or rejects based on the fetch result
|
|
1246
1246
|
*/
|
|
1247
|
-
from: <T
|
|
1247
|
+
from: <T, E = unknown>(promise: Promise<T>) => FPromise<T, E>;
|
|
1248
1248
|
/**
|
|
1249
1249
|
* Creates an FPromise from an Either.
|
|
1250
1250
|
* If the Either is a Right, the FPromise resolves with the Right value.
|
|
@@ -1275,7 +1275,7 @@ declare const FPromiseCompanion: {
|
|
|
1275
1275
|
* const result = await FPromise.all(promises).toPromise()
|
|
1276
1276
|
* // result is [1, 2, 3]
|
|
1277
1277
|
*/
|
|
1278
|
-
all: <T
|
|
1278
|
+
all: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T> | T>) => FPromise<T[], E>;
|
|
1279
1279
|
/**
|
|
1280
1280
|
* Like Promise.allSettled, returns results of all promises whether they succeed or fail.
|
|
1281
1281
|
* This will always resolve, never reject.
|
|
@@ -1290,7 +1290,7 @@ declare const FPromiseCompanion: {
|
|
|
1290
1290
|
* const result = await FPromise.allSettled(promises).toPromise()
|
|
1291
1291
|
* // result is [Right(1), Left(Error("Failed"))]
|
|
1292
1292
|
*/
|
|
1293
|
-
allSettled: <T
|
|
1293
|
+
allSettled: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<Array<Either<E, T>>, never>;
|
|
1294
1294
|
/**
|
|
1295
1295
|
* Like Promise.race, returns the first promise to settle (either resolve or reject).
|
|
1296
1296
|
*
|
|
@@ -1305,7 +1305,7 @@ declare const FPromiseCompanion: {
|
|
|
1305
1305
|
* const result = await FPromise.race([slow, fast]).toPromise()
|
|
1306
1306
|
* // result is 2
|
|
1307
1307
|
*/
|
|
1308
|
-
race: <T
|
|
1308
|
+
race: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1309
1309
|
/**
|
|
1310
1310
|
* Like Promise.any, returns the first promise to fulfill.
|
|
1311
1311
|
* This will only reject if all promises reject.
|
|
@@ -1324,7 +1324,7 @@ declare const FPromiseCompanion: {
|
|
|
1324
1324
|
* const result = await FPromise.any(promises).toPromise()
|
|
1325
1325
|
* // result is 2
|
|
1326
1326
|
*/
|
|
1327
|
-
any: <T
|
|
1327
|
+
any: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1328
1328
|
/**
|
|
1329
1329
|
* Retries an operation with exponential backoff.
|
|
1330
1330
|
* This is useful for operations that may fail temporarily, such as network requests.
|
|
@@ -1352,11 +1352,11 @@ declare const FPromiseCompanion: {
|
|
|
1352
1352
|
* shouldRetry: (error) => error.message === "Temporary failure"
|
|
1353
1353
|
* }).toPromise()
|
|
1354
1354
|
*/
|
|
1355
|
-
retryWithBackoff: <T
|
|
1355
|
+
retryWithBackoff: <T, E = unknown>(operation: () => FPromise<T, E>, options: {
|
|
1356
1356
|
maxRetries: number;
|
|
1357
1357
|
baseDelay?: number;
|
|
1358
1358
|
shouldRetry?: (error: E, attempt: number) => boolean;
|
|
1359
|
-
}) => FPromise<T
|
|
1359
|
+
}) => FPromise<T, E>;
|
|
1360
1360
|
};
|
|
1361
1361
|
/**
|
|
1362
1362
|
* Creates an FPromise from an executor function.
|
|
@@ -1366,7 +1366,7 @@ declare const FPromiseCompanion: {
|
|
|
1366
1366
|
* @param executor - A function that receives resolve and reject functions
|
|
1367
1367
|
* @returns An FPromise instance
|
|
1368
1368
|
*/
|
|
1369
|
-
declare const FPromise: (<T
|
|
1369
|
+
declare const FPromise: (<T extends Type, E = unknown>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: E) => void) => void) => FPromise<T, E>) & {
|
|
1370
1370
|
/**
|
|
1371
1371
|
* Creates an FPromise that resolves to the provided value.
|
|
1372
1372
|
*
|
|
@@ -1379,7 +1379,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1379
1379
|
* const promise = FPromise.resolve(42)
|
|
1380
1380
|
* // promise resolves to 42
|
|
1381
1381
|
*/
|
|
1382
|
-
resolve: <T
|
|
1382
|
+
resolve: <T, E = never>(value: T | PromiseLike<T>) => FPromise<T, E>;
|
|
1383
1383
|
/**
|
|
1384
1384
|
* Creates an FPromise that rejects with the provided reason.
|
|
1385
1385
|
*
|
|
@@ -1392,7 +1392,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1392
1392
|
* const promise = FPromise.reject<number, Error>(new Error("Something went wrong"))
|
|
1393
1393
|
* // promise rejects with Error("Something went wrong")
|
|
1394
1394
|
*/
|
|
1395
|
-
reject: <T
|
|
1395
|
+
reject: <T, E = unknown>(reason: E) => FPromise<T, E>;
|
|
1396
1396
|
/**
|
|
1397
1397
|
* Creates an FPromise from a regular Promise.
|
|
1398
1398
|
*
|
|
@@ -1405,7 +1405,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1405
1405
|
* const promise = FPromise.from(fetch("https://api.example.com/data"))
|
|
1406
1406
|
* // promise is an FPromise that resolves or rejects based on the fetch result
|
|
1407
1407
|
*/
|
|
1408
|
-
from: <T
|
|
1408
|
+
from: <T, E = unknown>(promise: Promise<T>) => FPromise<T, E>;
|
|
1409
1409
|
/**
|
|
1410
1410
|
* Creates an FPromise from an Either.
|
|
1411
1411
|
* If the Either is a Right, the FPromise resolves with the Right value.
|
|
@@ -1436,7 +1436,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1436
1436
|
* const result = await FPromise.all(promises).toPromise()
|
|
1437
1437
|
* // result is [1, 2, 3]
|
|
1438
1438
|
*/
|
|
1439
|
-
all: <T
|
|
1439
|
+
all: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T> | T>) => FPromise<T[], E>;
|
|
1440
1440
|
/**
|
|
1441
1441
|
* Like Promise.allSettled, returns results of all promises whether they succeed or fail.
|
|
1442
1442
|
* This will always resolve, never reject.
|
|
@@ -1451,7 +1451,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1451
1451
|
* const result = await FPromise.allSettled(promises).toPromise()
|
|
1452
1452
|
* // result is [Right(1), Left(Error("Failed"))]
|
|
1453
1453
|
*/
|
|
1454
|
-
allSettled: <T
|
|
1454
|
+
allSettled: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<Array<Either<E, T>>, never>;
|
|
1455
1455
|
/**
|
|
1456
1456
|
* Like Promise.race, returns the first promise to settle (either resolve or reject).
|
|
1457
1457
|
*
|
|
@@ -1466,7 +1466,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1466
1466
|
* const result = await FPromise.race([slow, fast]).toPromise()
|
|
1467
1467
|
* // result is 2
|
|
1468
1468
|
*/
|
|
1469
|
-
race: <T
|
|
1469
|
+
race: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1470
1470
|
/**
|
|
1471
1471
|
* Like Promise.any, returns the first promise to fulfill.
|
|
1472
1472
|
* This will only reject if all promises reject.
|
|
@@ -1485,7 +1485,7 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1485
1485
|
* const result = await FPromise.any(promises).toPromise()
|
|
1486
1486
|
* // result is 2
|
|
1487
1487
|
*/
|
|
1488
|
-
any: <T
|
|
1488
|
+
any: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1489
1489
|
/**
|
|
1490
1490
|
* Retries an operation with exponential backoff.
|
|
1491
1491
|
* This is useful for operations that may fail temporarily, such as network requests.
|
|
@@ -1513,11 +1513,11 @@ declare const FPromise: (<T$1 extends Type, E = unknown>(executor: (resolve: (va
|
|
|
1513
1513
|
* shouldRetry: (error) => error.message === "Temporary failure"
|
|
1514
1514
|
* }).toPromise()
|
|
1515
1515
|
*/
|
|
1516
|
-
retryWithBackoff: <T
|
|
1516
|
+
retryWithBackoff: <T, E = unknown>(operation: () => FPromise<T, E>, options: {
|
|
1517
1517
|
maxRetries: number;
|
|
1518
1518
|
baseDelay?: number;
|
|
1519
1519
|
shouldRetry?: (error: E, attempt: number) => boolean;
|
|
1520
|
-
}) => FPromise<T
|
|
1520
|
+
}) => FPromise<T, E>;
|
|
1521
1521
|
};
|
|
1522
1522
|
//#endregion
|
|
1523
1523
|
//#region src/core/task/Task.d.ts
|
|
@@ -1544,59 +1544,59 @@ interface TaskMetadata {
|
|
|
1544
1544
|
readonly name: string;
|
|
1545
1545
|
readonly description: string;
|
|
1546
1546
|
}
|
|
1547
|
-
interface TaskOutcome<T
|
|
1547
|
+
interface TaskOutcome<T> extends FunctypeBase<T, "Ok" | "Err">, Extractable<T>, AsyncMonad<T>, Promisable<T>, Doable<T> {
|
|
1548
1548
|
readonly _tag: "Ok" | "Err";
|
|
1549
1549
|
readonly _meta: TaskMetadata;
|
|
1550
|
-
readonly value?: T
|
|
1550
|
+
readonly value?: T;
|
|
1551
1551
|
readonly error?: Throwable;
|
|
1552
|
-
readonly map: <U>(f: (value: T
|
|
1553
|
-
readonly flatMap: <U>(f: (value: T
|
|
1554
|
-
readonly ap: <U>(ff: TaskOutcome<(value: T
|
|
1555
|
-
readonly mapAsync: <U>(f: (value: T
|
|
1556
|
-
readonly flatMapAsync: <U>(f: (value: T
|
|
1557
|
-
readonly mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T
|
|
1558
|
-
readonly recover: (value: T
|
|
1559
|
-
readonly recoverWith: (f: (error: Throwable) => T
|
|
1560
|
-
readonly isSuccess: () => this is Ok<T
|
|
1561
|
-
readonly isFailure: () => this is Err<T
|
|
1562
|
-
readonly isOk: () => this is Ok<T
|
|
1563
|
-
readonly isErr: () => this is Err<T
|
|
1564
|
-
readonly toEither: () => Either<Throwable, T
|
|
1565
|
-
readonly toTry: () => Try<T
|
|
1566
|
-
readonly toOption: () => Option<T
|
|
1567
|
-
readonly toList: () => List<T
|
|
1568
|
-
readonly fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T
|
|
1552
|
+
readonly map: <U>(f: (value: T) => U) => TaskOutcome<U>;
|
|
1553
|
+
readonly flatMap: <U>(f: (value: T) => TaskOutcome<U> | Either<Throwable, U>) => TaskOutcome<U>;
|
|
1554
|
+
readonly ap: <U>(ff: TaskOutcome<(value: T) => U>) => TaskOutcome<U>;
|
|
1555
|
+
readonly mapAsync: <U>(f: (value: T) => Promise<U>) => Promise<TaskOutcome<U>>;
|
|
1556
|
+
readonly flatMapAsync: <U>(f: (value: T) => Promise<TaskOutcome<U>>) => Promise<TaskOutcome<U>>;
|
|
1557
|
+
readonly mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T>;
|
|
1558
|
+
readonly recover: (value: T) => Ok<T>;
|
|
1559
|
+
readonly recoverWith: (f: (error: Throwable) => T) => Ok<T>;
|
|
1560
|
+
readonly isSuccess: () => this is Ok<T>;
|
|
1561
|
+
readonly isFailure: () => this is Err<T>;
|
|
1562
|
+
readonly isOk: () => this is Ok<T>;
|
|
1563
|
+
readonly isErr: () => this is Err<T>;
|
|
1564
|
+
readonly toEither: () => Either<Throwable, T>;
|
|
1565
|
+
readonly toTry: () => Try<T>;
|
|
1566
|
+
readonly toOption: () => Option<T>;
|
|
1567
|
+
readonly toList: () => List<T>;
|
|
1568
|
+
readonly fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U;
|
|
1569
1569
|
readonly match: <U>(patterns: {
|
|
1570
|
-
Ok: (value: T
|
|
1570
|
+
Ok: (value: T) => U;
|
|
1571
1571
|
Err: (error: Throwable) => U;
|
|
1572
1572
|
}) => U;
|
|
1573
1573
|
}
|
|
1574
|
-
interface Ok<T
|
|
1574
|
+
interface Ok<T> extends TaskOutcome<T> {
|
|
1575
1575
|
readonly _tag: "Ok";
|
|
1576
|
-
readonly value: T
|
|
1576
|
+
readonly value: T;
|
|
1577
1577
|
readonly error: undefined;
|
|
1578
1578
|
}
|
|
1579
|
-
interface Err<T
|
|
1579
|
+
interface Err<T> extends TaskOutcome<T> {
|
|
1580
1580
|
readonly _tag: "Err";
|
|
1581
1581
|
readonly value: undefined;
|
|
1582
1582
|
readonly error: Throwable;
|
|
1583
1583
|
}
|
|
1584
|
-
type TaskSuccess<T
|
|
1585
|
-
type TaskFailure<T
|
|
1584
|
+
type TaskSuccess<T> = Ok<T>;
|
|
1585
|
+
type TaskFailure<T> = Err<T>;
|
|
1586
1586
|
/**
|
|
1587
1587
|
* Err constructor - Creates a failed TaskOutcome
|
|
1588
1588
|
* @param error - The error object
|
|
1589
1589
|
* @param data - Additional data related to the error
|
|
1590
1590
|
* @param params - Task parameters
|
|
1591
1591
|
*/
|
|
1592
|
-
declare const Err: <T
|
|
1592
|
+
declare const Err: <T>(error: unknown, data?: unknown, params?: TaskParams) => Err<T>;
|
|
1593
1593
|
/**
|
|
1594
1594
|
* Ok constructor - Creates a successful TaskOutcome
|
|
1595
1595
|
* @param data - The successful value
|
|
1596
1596
|
* @param params - Task parameters
|
|
1597
1597
|
*/
|
|
1598
|
-
declare const Ok: <T
|
|
1599
|
-
type TaskResult<T
|
|
1598
|
+
declare const Ok: <T>(data: T, params?: TaskParams) => Ok<T>;
|
|
1599
|
+
type TaskResult<T> = Promise<TaskOutcome<T>>;
|
|
1600
1600
|
/**
|
|
1601
1601
|
* The CancellationToken is a control structure that allows long-running tasks to be cancelled
|
|
1602
1602
|
* Cancellation is cooperative, meaning the task must check the token and respond to cancellation requests
|
|
@@ -1624,9 +1624,9 @@ type CancellationTokenSource = {
|
|
|
1624
1624
|
* @returns A CancellationTokenSource that can be used to create and control cancellation tokens
|
|
1625
1625
|
*/
|
|
1626
1626
|
declare const createCancellationTokenSource: () => CancellationTokenSource;
|
|
1627
|
-
type Sync<T
|
|
1628
|
-
type Async<T
|
|
1629
|
-
declare const Task: (<T
|
|
1627
|
+
type Sync<T> = TaskOutcome<T>;
|
|
1628
|
+
type Async<T> = TaskResult<T>;
|
|
1629
|
+
declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
1630
1630
|
_type: string;
|
|
1631
1631
|
/**
|
|
1632
1632
|
* Run an async operation with explicit try/catch/finally semantics
|
|
@@ -1637,7 +1637,7 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1637
1637
|
* @param f - Optional finally handler function
|
|
1638
1638
|
* @param cancellationToken - Optional token for cancellation support
|
|
1639
1639
|
*/
|
|
1640
|
-
Async: <U = T
|
|
1640
|
+
Async: <U = T>(t: () => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => FPromise<TaskOutcome<U>>;
|
|
1641
1641
|
/**
|
|
1642
1642
|
* Run a synchronous operation with explicit try/catch/finally semantics
|
|
1643
1643
|
* Returns a TaskOutcome for functional error handling
|
|
@@ -1646,7 +1646,7 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1646
1646
|
* @param e - Optional error handler function
|
|
1647
1647
|
* @param f - Optional finally handler function
|
|
1648
1648
|
*/
|
|
1649
|
-
Sync: <U = T
|
|
1649
|
+
Sync: <U = T>(t: () => U, e?: (error: unknown) => unknown, f?: () => void) => TaskOutcome<U>;
|
|
1650
1650
|
/**
|
|
1651
1651
|
* Run an async operation with progress tracking capabilities
|
|
1652
1652
|
* Returns a Promise and provides progress updates via callback
|
|
@@ -1657,7 +1657,7 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1657
1657
|
* @param f - Optional finally handler function
|
|
1658
1658
|
* @param cancellationToken - Optional token for cancellation support
|
|
1659
1659
|
*/
|
|
1660
|
-
AsyncWithProgress: <U = T
|
|
1660
|
+
AsyncWithProgress: <U = T>(t: (updateProgress: (percent: number) => void) => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, onProgress: (percent: number) => void, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => FPromise<TaskOutcome<U>>;
|
|
1661
1661
|
toString(): string;
|
|
1662
1662
|
doUnwrap(): DoResult<unknown>;
|
|
1663
1663
|
_tag: string;
|
|
@@ -1665,33 +1665,33 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1665
1665
|
/**
|
|
1666
1666
|
* Create a successful Task result
|
|
1667
1667
|
*/
|
|
1668
|
-
success: <T
|
|
1668
|
+
success: <T>(data: T, params?: TaskParams) => Ok<T>;
|
|
1669
1669
|
/**
|
|
1670
1670
|
* Create a failed Task result
|
|
1671
1671
|
*/
|
|
1672
|
-
fail: <T
|
|
1672
|
+
fail: <T>(error: unknown, data?: unknown, params?: TaskParams) => Err<T>;
|
|
1673
1673
|
/**
|
|
1674
1674
|
* Create a successful Task result (alias for success)
|
|
1675
1675
|
* Preferred for new code
|
|
1676
1676
|
*/
|
|
1677
|
-
ok: <T
|
|
1677
|
+
ok: <T>(data: T, params?: TaskParams) => Ok<T>;
|
|
1678
1678
|
/**
|
|
1679
1679
|
* Create a failed Task result (alias for fail)
|
|
1680
1680
|
* Preferred for new code
|
|
1681
1681
|
*/
|
|
1682
|
-
err: <T
|
|
1682
|
+
err: <T>(error: unknown, data?: unknown, params?: TaskParams) => Err<T>;
|
|
1683
1683
|
/**
|
|
1684
1684
|
* Create TaskOutcome from Either
|
|
1685
1685
|
* @param either - Either to convert
|
|
1686
1686
|
* @param params - Task parameters
|
|
1687
1687
|
*/
|
|
1688
|
-
fromEither: <T
|
|
1688
|
+
fromEither: <T>(either: Either<Throwable, T>, params?: TaskParams) => TaskOutcome<T>;
|
|
1689
1689
|
/**
|
|
1690
1690
|
* Create TaskOutcome from Try
|
|
1691
1691
|
* @param tryValue - Try to convert
|
|
1692
1692
|
* @param params - Task parameters
|
|
1693
1693
|
*/
|
|
1694
|
-
fromTry: <T
|
|
1694
|
+
fromTry: <T>(tryValue: Try<T>, params?: TaskParams) => TaskOutcome<T>;
|
|
1695
1695
|
/**
|
|
1696
1696
|
* Extract the error chain from a Throwable error
|
|
1697
1697
|
* Returns an array of errors from outermost to innermost
|
|
@@ -1729,7 +1729,7 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1729
1729
|
* @param params - Task parameters for the race operation
|
|
1730
1730
|
* @returns A promise that resolves with the first task to complete or rejects if all tasks fail
|
|
1731
1731
|
*/
|
|
1732
|
-
race: <T
|
|
1732
|
+
race: <T>(tasks: Array<FPromise<T> | FPromise<TaskOutcome<T>>>, timeoutMs?: number, params?: TaskParams) => FPromise<TaskOutcome<T>>;
|
|
1733
1733
|
/**
|
|
1734
1734
|
* Convert a Node.js style callback function to a Task-compatible function
|
|
1735
1735
|
* Node.js callbacks typically have the signature (error, result) => void
|
|
@@ -1738,7 +1738,7 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1738
1738
|
* @param params - Task parameters
|
|
1739
1739
|
* @returns A function that returns an FPromise
|
|
1740
1740
|
*/
|
|
1741
|
-
fromNodeCallback: <T
|
|
1741
|
+
fromNodeCallback: <T, Args extends unknown[]>(nodeFn: (...args: [...Args, (error: unknown, result: T) => void]) => void, params?: TaskParams) => ((...args: Args) => FPromise<TaskOutcome<T>>);
|
|
1742
1742
|
/**
|
|
1743
1743
|
* Create a cancellation token source
|
|
1744
1744
|
* @returns A cancellation token source that can be used to control task cancellation
|
|
@@ -1751,8 +1751,8 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1751
1751
|
* @param params - Task parameters
|
|
1752
1752
|
* @returns An object with the task and a function to cancel it
|
|
1753
1753
|
*/
|
|
1754
|
-
cancellable: <T
|
|
1755
|
-
task: FPromise<TaskOutcome<T
|
|
1754
|
+
cancellable: <T>(task: (token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, params?: TaskParams) => {
|
|
1755
|
+
task: FPromise<TaskOutcome<T>>;
|
|
1756
1756
|
cancel: () => void;
|
|
1757
1757
|
};
|
|
1758
1758
|
/**
|
|
@@ -1763,13 +1763,13 @@ declare const Task: (<T$1 = unknown>(params?: TaskParams) => {
|
|
|
1763
1763
|
* @param params - Task parameters
|
|
1764
1764
|
* @returns An object with the task, cancel function, and current progress
|
|
1765
1765
|
*/
|
|
1766
|
-
withProgress: <T
|
|
1767
|
-
task: FPromise<TaskOutcome<T
|
|
1766
|
+
withProgress: <T>(task: (updateProgress: (percent: number) => void, token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, onProgress?: (percent: number) => void, params?: TaskParams) => {
|
|
1767
|
+
task: FPromise<TaskOutcome<T>>;
|
|
1768
1768
|
cancel: () => void;
|
|
1769
1769
|
currentProgress: () => number;
|
|
1770
1770
|
};
|
|
1771
1771
|
};
|
|
1772
|
-
type Task = ReturnType<typeof Task>;
|
|
1772
|
+
type Task$1 = ReturnType<typeof Task$1>;
|
|
1773
1773
|
//#endregion
|
|
1774
1774
|
//#region src/error/ErrorFormatter.d.ts
|
|
1775
1775
|
/**
|
|
@@ -1856,64 +1856,64 @@ type ErrorCode = "VALIDATION_FAILED" | "NETWORK_ERROR" | "AUTH_REQUIRED" | "NOT_
|
|
|
1856
1856
|
/**
|
|
1857
1857
|
* Template literal type for error messages based on error code
|
|
1858
1858
|
*/
|
|
1859
|
-
type ErrorMessage<T
|
|
1859
|
+
type ErrorMessage<T extends ErrorCode> = T extends "VALIDATION_FAILED" ? `Validation failed: ${string}` : T extends "NETWORK_ERROR" ? `Network error: ${string}` : T extends "AUTH_REQUIRED" ? `Authentication required: ${string}` : T extends "NOT_FOUND" ? `Not found: ${string}` : T extends "PERMISSION_DENIED" ? `Permission denied: ${string}` : T extends "RATE_LIMITED" ? `Rate limit exceeded: ${string}` : T extends "INTERNAL_ERROR" ? `Internal server error: ${string}` : T extends "BAD_REQUEST" ? `Bad request: ${string}` : T extends "CONFLICT" ? `Conflict: ${string}` : T extends "TIMEOUT" ? `Request timeout: ${string}` : never;
|
|
1860
1860
|
/**
|
|
1861
1861
|
* HTTP status codes mapped to error codes
|
|
1862
1862
|
*/
|
|
1863
|
-
type ErrorStatus<T
|
|
1863
|
+
type ErrorStatus<T extends ErrorCode> = T extends "VALIDATION_FAILED" | "BAD_REQUEST" ? 400 : T extends "AUTH_REQUIRED" ? 401 : T extends "PERMISSION_DENIED" ? 403 : T extends "NOT_FOUND" ? 404 : T extends "CONFLICT" ? 409 : T extends "RATE_LIMITED" ? 429 : T extends "TIMEOUT" ? 408 : T extends "INTERNAL_ERROR" ? 500 : T extends "NETWORK_ERROR" ? 503 : 500;
|
|
1864
1864
|
/**
|
|
1865
1865
|
* Context type for each error code
|
|
1866
1866
|
*/
|
|
1867
|
-
type TypedErrorContext<T
|
|
1867
|
+
type TypedErrorContext<T extends ErrorCode> = T extends "VALIDATION_FAILED" ? {
|
|
1868
1868
|
field: string;
|
|
1869
1869
|
value: unknown;
|
|
1870
1870
|
rule: string;
|
|
1871
|
-
} : T
|
|
1871
|
+
} : T extends "NETWORK_ERROR" ? {
|
|
1872
1872
|
url: string;
|
|
1873
1873
|
method: string;
|
|
1874
1874
|
statusCode?: number;
|
|
1875
|
-
} : T
|
|
1875
|
+
} : T extends "AUTH_REQUIRED" ? {
|
|
1876
1876
|
resource: string;
|
|
1877
1877
|
requiredRole?: string;
|
|
1878
|
-
} : T
|
|
1878
|
+
} : T extends "NOT_FOUND" ? {
|
|
1879
1879
|
resource: string;
|
|
1880
1880
|
id: string | number;
|
|
1881
|
-
} : T
|
|
1881
|
+
} : T extends "PERMISSION_DENIED" ? {
|
|
1882
1882
|
action: string;
|
|
1883
1883
|
resource: string;
|
|
1884
1884
|
userId?: string;
|
|
1885
|
-
} : T
|
|
1885
|
+
} : T extends "RATE_LIMITED" ? {
|
|
1886
1886
|
limit: number;
|
|
1887
1887
|
window: string;
|
|
1888
1888
|
retryAfter?: number;
|
|
1889
|
-
} : T
|
|
1889
|
+
} : T extends "INTERNAL_ERROR" ? {
|
|
1890
1890
|
errorId: string;
|
|
1891
1891
|
timestamp: string;
|
|
1892
|
-
} : T
|
|
1892
|
+
} : T extends "BAD_REQUEST" ? {
|
|
1893
1893
|
reason: string;
|
|
1894
1894
|
expected?: string;
|
|
1895
|
-
} : T
|
|
1895
|
+
} : T extends "CONFLICT" ? {
|
|
1896
1896
|
resource: string;
|
|
1897
1897
|
conflictingValue: string;
|
|
1898
|
-
} : T
|
|
1898
|
+
} : T extends "TIMEOUT" ? {
|
|
1899
1899
|
duration: number;
|
|
1900
1900
|
operation: string;
|
|
1901
1901
|
} : Record<string, unknown>;
|
|
1902
1902
|
/**
|
|
1903
1903
|
* Type-safe error class with template literal types
|
|
1904
1904
|
*/
|
|
1905
|
-
interface TypedError<T
|
|
1906
|
-
readonly code: T
|
|
1907
|
-
readonly message: ErrorMessage<T
|
|
1908
|
-
readonly status: ErrorStatus<T
|
|
1909
|
-
readonly context: TypedErrorContext<T
|
|
1905
|
+
interface TypedError<T extends ErrorCode> extends Throwable {
|
|
1906
|
+
readonly code: T;
|
|
1907
|
+
readonly message: ErrorMessage<T>;
|
|
1908
|
+
readonly status: ErrorStatus<T>;
|
|
1909
|
+
readonly context: TypedErrorContext<T>;
|
|
1910
1910
|
readonly timestamp: string;
|
|
1911
1911
|
readonly traceId?: string;
|
|
1912
1912
|
}
|
|
1913
|
-
declare const TypedError: (<T
|
|
1913
|
+
declare const TypedError: (<T extends ErrorCode>(code: T, message: ErrorMessage<T>, context: TypedErrorContext<T>, options?: {
|
|
1914
1914
|
cause?: unknown;
|
|
1915
1915
|
traceId?: string;
|
|
1916
|
-
}) => TypedError<T
|
|
1916
|
+
}) => TypedError<T>) & {
|
|
1917
1917
|
/**
|
|
1918
1918
|
* Create a validation error
|
|
1919
1919
|
* @example
|
|
@@ -1992,7 +1992,7 @@ declare const TypedError: (<T$1 extends ErrorCode>(code: T$1, message: ErrorMess
|
|
|
1992
1992
|
/**
|
|
1993
1993
|
* Check if a TypedError has a specific code
|
|
1994
1994
|
*/
|
|
1995
|
-
hasCode: <T
|
|
1995
|
+
hasCode: <T extends ErrorCode>(error: TypedError<ErrorCode>, code: T) => error is TypedError<T>;
|
|
1996
1996
|
};
|
|
1997
1997
|
//#endregion
|
|
1998
1998
|
//#region src/error/typed/Validation.d.ts
|
|
@@ -2003,20 +2003,20 @@ type ValidationRule = `min:${number}` | `max:${number}` | `minLength:${number}`
|
|
|
2003
2003
|
/**
|
|
2004
2004
|
* Validator function type
|
|
2005
2005
|
*/
|
|
2006
|
-
type Validator<T
|
|
2006
|
+
type Validator<T> = (value: unknown) => Either<TypedError<"VALIDATION_FAILED">, T>;
|
|
2007
2007
|
/**
|
|
2008
2008
|
* Field validation result
|
|
2009
2009
|
*/
|
|
2010
|
-
type FieldValidation<T
|
|
2010
|
+
type FieldValidation<T> = {
|
|
2011
2011
|
field: string;
|
|
2012
2012
|
value: unknown;
|
|
2013
|
-
result: Either<TypedError<"VALIDATION_FAILED">, T
|
|
2013
|
+
result: Either<TypedError<"VALIDATION_FAILED">, T>;
|
|
2014
2014
|
};
|
|
2015
2015
|
/**
|
|
2016
2016
|
* Form validation result
|
|
2017
2017
|
*/
|
|
2018
|
-
type FormValidation<T
|
|
2019
|
-
declare const Validation: (<T
|
|
2018
|
+
type FormValidation<T extends Record<string, Type>> = Either<List<TypedError<"VALIDATION_FAILED">>, T>;
|
|
2019
|
+
declare const Validation: (<T extends Type>(rule: ValidationRule) => Validator<T>) & {
|
|
2020
2020
|
/**
|
|
2021
2021
|
* Common pre-built validators
|
|
2022
2022
|
*/
|
|
@@ -2036,7 +2036,7 @@ declare const Validation: (<T$1 extends Type>(rule: ValidationRule) => Validator
|
|
|
2036
2036
|
* const result = validator(25) // Right(25)
|
|
2037
2037
|
* const error = validator(15) // Left(TypedError)
|
|
2038
2038
|
*/
|
|
2039
|
-
rule: <T
|
|
2039
|
+
rule: <T extends Type>(rule: ValidationRule) => Validator<T>;
|
|
2040
2040
|
/**
|
|
2041
2041
|
* Combine multiple validators
|
|
2042
2042
|
* @example
|
|
@@ -2046,7 +2046,7 @@ declare const Validation: (<T$1 extends Type>(rule: ValidationRule) => Validator
|
|
|
2046
2046
|
* Validation.rule<string>("maxLength:100")
|
|
2047
2047
|
* )
|
|
2048
2048
|
*/
|
|
2049
|
-
combine: <T
|
|
2049
|
+
combine: <T extends Type>(...validators: Validator<T>[]) => Validator<T>;
|
|
2050
2050
|
/**
|
|
2051
2051
|
* Create a custom validator
|
|
2052
2052
|
* @example
|
|
@@ -2055,7 +2055,7 @@ declare const Validation: (<T$1 extends Type>(rule: ValidationRule) => Validator
|
|
|
2055
2055
|
* "must be an even number"
|
|
2056
2056
|
* )
|
|
2057
2057
|
*/
|
|
2058
|
-
custom: <T
|
|
2058
|
+
custom: <T extends Type>(predicate: (value: unknown) => boolean, errorMessage: string) => Validator<T>;
|
|
2059
2059
|
/**
|
|
2060
2060
|
* Validate a form with multiple fields
|
|
2061
2061
|
* @example
|
|
@@ -2066,7 +2066,7 @@ declare const Validation: (<T$1 extends Type>(rule: ValidationRule) => Validator
|
|
|
2066
2066
|
* }
|
|
2067
2067
|
* const result = Validation.form(schema, { name: "John", email: "john@example.com", age: 25 })
|
|
2068
2068
|
*/
|
|
2069
|
-
form: <T
|
|
2069
|
+
form: <T extends Record<string, Type>>(schema: { [K in keyof T]: Validator<T[K]> }, data: Record<string, unknown>) => FormValidation<T>;
|
|
2070
2070
|
};
|
|
2071
2071
|
//#endregion
|
|
2072
2072
|
//#region src/foldable/index.d.ts
|
|
@@ -2128,8 +2128,8 @@ type TryKind = <A>(a: A) => Try<A>;
|
|
|
2128
2128
|
* Generic container types for type-safe operations
|
|
2129
2129
|
* @internal
|
|
2130
2130
|
*/
|
|
2131
|
-
type Mappable<T
|
|
2132
|
-
map<U>(f: (value: T
|
|
2131
|
+
type Mappable<T> = {
|
|
2132
|
+
map<U>(f: (value: T) => U): unknown;
|
|
2133
2133
|
};
|
|
2134
2134
|
/**
|
|
2135
2135
|
* @internal
|
|
@@ -2140,8 +2140,8 @@ type Flattenable = {
|
|
|
2140
2140
|
/**
|
|
2141
2141
|
* @internal
|
|
2142
2142
|
*/
|
|
2143
|
-
type FlatMappable<T
|
|
2144
|
-
flatMap<U>(f: (value: T
|
|
2143
|
+
type FlatMappable<T> = {
|
|
2144
|
+
flatMap<U>(f: (value: T) => unknown): unknown;
|
|
2145
2145
|
};
|
|
2146
2146
|
/**
|
|
2147
2147
|
* Universal type that includes all potential return types from the HKT functions
|
|
@@ -2170,30 +2170,1273 @@ declare const HKT: {
|
|
|
2170
2170
|
ap<F = unknown, A = unknown, B = unknown>(ff: unknown, fa: unknown): unknown;
|
|
2171
2171
|
sequence<F = unknown, G = unknown, A = unknown>(fga: unknown): unknown;
|
|
2172
2172
|
traverse<F = unknown, G = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => unknown): unknown;
|
|
2173
|
-
isOption: <T
|
|
2174
|
-
isList: <T
|
|
2173
|
+
isOption: <T extends Type>(value: unknown) => value is Option<T> & Mappable<T> & FlatMappable<T>;
|
|
2174
|
+
isList: <T extends Type>(value: unknown) => value is List<T> & Mappable<T> & Flattenable & FlatMappable<T>;
|
|
2175
2175
|
isEither: <E extends Type, A extends Type>(value: unknown) => value is Either<E, A> & Mappable<A> & FlatMappable<A>;
|
|
2176
|
-
isTry: <T
|
|
2176
|
+
isTry: <T extends Type>(value: unknown) => value is Try<T> & Mappable<T> & FlatMappable<T>;
|
|
2177
2177
|
};
|
|
2178
2178
|
//#endregion
|
|
2179
2179
|
//#region src/identity/Identity.d.ts
|
|
2180
|
-
type Identity<T
|
|
2181
|
-
id: T
|
|
2182
|
-
isSame?: (other: Identity<T
|
|
2180
|
+
type Identity<T> = {
|
|
2181
|
+
id: T;
|
|
2182
|
+
isSame?: (other: Identity<T>) => boolean;
|
|
2183
2183
|
};
|
|
2184
|
-
declare const Identity: (<T
|
|
2184
|
+
declare const Identity: (<T>(value: T) => Identity<T>) & {
|
|
2185
2185
|
/**
|
|
2186
2186
|
* Creates an Identity. Alias for Identity constructor.
|
|
2187
2187
|
* @param value - The value to wrap
|
|
2188
2188
|
* @returns Identity instance
|
|
2189
2189
|
*/
|
|
2190
|
-
of: <T
|
|
2190
|
+
of: <T>(value: T) => Identity<T>;
|
|
2191
2191
|
/**
|
|
2192
2192
|
* Creates an Identity. Same as of.
|
|
2193
2193
|
* @param value - The value to wrap
|
|
2194
2194
|
* @returns Identity instance
|
|
2195
2195
|
*/
|
|
2196
|
-
pure: <T
|
|
2196
|
+
pure: <T>(value: T) => Identity<T>;
|
|
2197
|
+
};
|
|
2198
|
+
//#endregion
|
|
2199
|
+
//#region src/io/Tag.d.ts
|
|
2200
|
+
/**
|
|
2201
|
+
* Tag module - service identifiers for dependency injection.
|
|
2202
|
+
* @module Tag
|
|
2203
|
+
* @category IO
|
|
2204
|
+
*
|
|
2205
|
+
* Tags are used to identify services in a type-safe way.
|
|
2206
|
+
* Each Tag has a unique identifier and carries the type of the service.
|
|
2207
|
+
*/
|
|
2208
|
+
/**
|
|
2209
|
+
* A Tag identifies a service type and provides a unique identifier.
|
|
2210
|
+
* Used for dependency injection with IO effects.
|
|
2211
|
+
*
|
|
2212
|
+
* @typeParam S - The service type this tag identifies
|
|
2213
|
+
*
|
|
2214
|
+
* @example
|
|
2215
|
+
* ```typescript
|
|
2216
|
+
* // Define service interfaces
|
|
2217
|
+
* interface UserService {
|
|
2218
|
+
* getUser(id: string): IO<never, Error, User>
|
|
2219
|
+
* }
|
|
2220
|
+
*
|
|
2221
|
+
* // Create a tag for the service
|
|
2222
|
+
* const UserService = Tag<UserService>("UserService")
|
|
2223
|
+
*
|
|
2224
|
+
* // Use in effects
|
|
2225
|
+
* const getUser = (id: string) =>
|
|
2226
|
+
* IO.service(UserService).flatMap(svc => svc.getUser(id))
|
|
2227
|
+
* ```
|
|
2228
|
+
*/
|
|
2229
|
+
interface Tag<S extends Type> {
|
|
2230
|
+
/**
|
|
2231
|
+
* Unique identifier for this tag
|
|
2232
|
+
*/
|
|
2233
|
+
readonly id: string;
|
|
2234
|
+
/**
|
|
2235
|
+
* Phantom type to carry the service type
|
|
2236
|
+
* @internal
|
|
2237
|
+
*/
|
|
2238
|
+
readonly _S?: S;
|
|
2239
|
+
/**
|
|
2240
|
+
* Type brand to distinguish tags
|
|
2241
|
+
* @internal
|
|
2242
|
+
*/
|
|
2243
|
+
readonly _tag: "Tag";
|
|
2244
|
+
/**
|
|
2245
|
+
* String representation
|
|
2246
|
+
*/
|
|
2247
|
+
toString(): string;
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Creates a Tag for identifying a service type.
|
|
2251
|
+
*
|
|
2252
|
+
* @param id - Unique identifier for this tag (usually the service name)
|
|
2253
|
+
* @returns A Tag that can be used to request the service
|
|
2254
|
+
*
|
|
2255
|
+
* @example
|
|
2256
|
+
* ```typescript
|
|
2257
|
+
* interface Logger {
|
|
2258
|
+
* log(message: string): void
|
|
2259
|
+
* }
|
|
2260
|
+
*
|
|
2261
|
+
* const Logger = Tag<Logger>("Logger")
|
|
2262
|
+
*
|
|
2263
|
+
* // Now Logger can be used to request the Logger service
|
|
2264
|
+
* const program = IO.service(Logger).flatMap(logger =>
|
|
2265
|
+
* IO.sync(() => logger.log("Hello!"))
|
|
2266
|
+
* )
|
|
2267
|
+
* ```
|
|
2268
|
+
*/
|
|
2269
|
+
declare const Tag: <S extends Type>(id: string) => Tag<S>;
|
|
2270
|
+
/**
|
|
2271
|
+
* Type helper to extract the service type from a Tag
|
|
2272
|
+
*/
|
|
2273
|
+
type TagService<T> = T extends Tag<infer S> ? S : never;
|
|
2274
|
+
//#endregion
|
|
2275
|
+
//#region src/io/Context.d.ts
|
|
2276
|
+
/**
|
|
2277
|
+
* Context module - service container for dependency injection.
|
|
2278
|
+
* @module Context
|
|
2279
|
+
* @category IO
|
|
2280
|
+
*
|
|
2281
|
+
* Context is an immutable container that holds service implementations
|
|
2282
|
+
* identified by their Tags.
|
|
2283
|
+
*/
|
|
2284
|
+
/**
|
|
2285
|
+
* Context holds service implementations for dependency injection.
|
|
2286
|
+
* It's an immutable container that maps Tags to their implementations.
|
|
2287
|
+
*
|
|
2288
|
+
* @typeParam R - The services contained in this context (intersection type)
|
|
2289
|
+
*
|
|
2290
|
+
* @example
|
|
2291
|
+
* ```typescript
|
|
2292
|
+
* const ctx = Context.empty()
|
|
2293
|
+
* .add(Logger, consoleLogger)
|
|
2294
|
+
* .add(Database, pgDatabase)
|
|
2295
|
+
*
|
|
2296
|
+
* // Access a service
|
|
2297
|
+
* const logger = ctx.get(Logger) // Option<Logger>
|
|
2298
|
+
* const loggerUnsafe = ctx.unsafeGet(Logger) // Logger (throws if missing)
|
|
2299
|
+
* ```
|
|
2300
|
+
*/
|
|
2301
|
+
interface Context<R$1 extends Type> {
|
|
2302
|
+
/**
|
|
2303
|
+
* Type brand
|
|
2304
|
+
* @internal
|
|
2305
|
+
*/
|
|
2306
|
+
readonly _tag: "Context";
|
|
2307
|
+
/**
|
|
2308
|
+
* Phantom type for requirements
|
|
2309
|
+
* @internal
|
|
2310
|
+
*/
|
|
2311
|
+
readonly _R?: R$1;
|
|
2312
|
+
/**
|
|
2313
|
+
* Internal service map
|
|
2314
|
+
* @internal
|
|
2315
|
+
*/
|
|
2316
|
+
readonly services: ReadonlyMap<string, Type>;
|
|
2317
|
+
/**
|
|
2318
|
+
* Gets a service from the context.
|
|
2319
|
+
* @param tag - The tag identifying the service
|
|
2320
|
+
* @returns Some(service) if found, None otherwise
|
|
2321
|
+
*/
|
|
2322
|
+
get<S extends Type>(tag: Tag<S>): Option<S>;
|
|
2323
|
+
/**
|
|
2324
|
+
* Gets a service from the context, throwing if not found.
|
|
2325
|
+
* @param tag - The tag identifying the service
|
|
2326
|
+
* @returns The service
|
|
2327
|
+
* @throws Error if service not found
|
|
2328
|
+
*/
|
|
2329
|
+
unsafeGet<S extends Type>(tag: Tag<S>): S;
|
|
2330
|
+
/**
|
|
2331
|
+
* Checks if a service exists in the context.
|
|
2332
|
+
* @param tag - The tag to check
|
|
2333
|
+
* @returns true if the service exists
|
|
2334
|
+
*/
|
|
2335
|
+
has<S extends Type>(tag: Tag<S>): boolean;
|
|
2336
|
+
/**
|
|
2337
|
+
* Adds a service to the context, returning a new context.
|
|
2338
|
+
* @param tag - The tag for the service
|
|
2339
|
+
* @param service - The service implementation
|
|
2340
|
+
* @returns A new context with the service added
|
|
2341
|
+
*/
|
|
2342
|
+
add<S extends Type>(tag: Tag<S>, service: S): Context<R$1 & S>;
|
|
2343
|
+
/**
|
|
2344
|
+
* Merges another context into this one.
|
|
2345
|
+
* @param other - The context to merge
|
|
2346
|
+
* @returns A new context with all services from both
|
|
2347
|
+
*/
|
|
2348
|
+
merge<R2 extends Type>(other: Context<R2>): Context<R$1 & R2>;
|
|
2349
|
+
/**
|
|
2350
|
+
* Returns the number of services in this context.
|
|
2351
|
+
*/
|
|
2352
|
+
readonly size: number;
|
|
2353
|
+
/**
|
|
2354
|
+
* String representation
|
|
2355
|
+
*/
|
|
2356
|
+
toString(): string;
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Context companion object with utility methods
|
|
2360
|
+
*/
|
|
2361
|
+
declare const Context: {
|
|
2362
|
+
/**
|
|
2363
|
+
* Creates an empty context with no services.
|
|
2364
|
+
*/
|
|
2365
|
+
empty: <R$1 extends Type = never>() => Context<R$1>;
|
|
2366
|
+
/**
|
|
2367
|
+
* Creates a context with a single service.
|
|
2368
|
+
* @param tag - The tag for the service
|
|
2369
|
+
* @param service - The service implementation
|
|
2370
|
+
*/
|
|
2371
|
+
make: <S extends Type>(tag: Tag<S>, service: S) => Context<S>;
|
|
2372
|
+
/**
|
|
2373
|
+
* Checks if a value is a Context.
|
|
2374
|
+
*/
|
|
2375
|
+
isContext: <R$1 extends Type>(value: unknown) => value is Context<R$1>;
|
|
2376
|
+
};
|
|
2377
|
+
/**
|
|
2378
|
+
* Type helper to extract requirements from a Context
|
|
2379
|
+
*/
|
|
2380
|
+
type ContextServices<C> = C extends Context<infer R> ? R : never;
|
|
2381
|
+
/**
|
|
2382
|
+
* Type helper to check if a context provides a service
|
|
2383
|
+
*/
|
|
2384
|
+
type HasService<C, S> = S extends ContextServices<C> ? true : false;
|
|
2385
|
+
//#endregion
|
|
2386
|
+
//#region src/io/Exit.d.ts
|
|
2387
|
+
/**
|
|
2388
|
+
* Exit type module - represents the outcome of running an IO effect.
|
|
2389
|
+
* @module Exit
|
|
2390
|
+
* @category IO
|
|
2391
|
+
*/
|
|
2392
|
+
/**
|
|
2393
|
+
* Possible outcome types for an Exit
|
|
2394
|
+
*/
|
|
2395
|
+
type ExitTag = "Success" | "Failure" | "Interrupted";
|
|
2396
|
+
/**
|
|
2397
|
+
* Exit represents the outcome of running an IO effect.
|
|
2398
|
+
* - Success: The effect completed successfully with a value
|
|
2399
|
+
* - Failure: The effect failed with a typed error
|
|
2400
|
+
* - Interrupted: The effect was cancelled/interrupted
|
|
2401
|
+
*/
|
|
2402
|
+
interface Exit<E extends Type, A extends Type> {
|
|
2403
|
+
readonly _tag: ExitTag;
|
|
2404
|
+
/**
|
|
2405
|
+
* Type guard to check if this is a Success
|
|
2406
|
+
*/
|
|
2407
|
+
isSuccess(): this is Exit<E, A> & {
|
|
2408
|
+
readonly _tag: "Success";
|
|
2409
|
+
value: A;
|
|
2410
|
+
};
|
|
2411
|
+
/**
|
|
2412
|
+
* Type guard to check if this is a Failure
|
|
2413
|
+
*/
|
|
2414
|
+
isFailure(): this is Exit<E, A> & {
|
|
2415
|
+
readonly _tag: "Failure";
|
|
2416
|
+
error: E;
|
|
2417
|
+
};
|
|
2418
|
+
/**
|
|
2419
|
+
* Type guard to check if this is Interrupted
|
|
2420
|
+
*/
|
|
2421
|
+
isInterrupted(): this is Exit<E, A> & {
|
|
2422
|
+
readonly _tag: "Interrupted";
|
|
2423
|
+
fiberId: string;
|
|
2424
|
+
};
|
|
2425
|
+
/**
|
|
2426
|
+
* Maps the success value
|
|
2427
|
+
*/
|
|
2428
|
+
map<B extends Type>(f: (a: A) => B): Exit<E, B>;
|
|
2429
|
+
/**
|
|
2430
|
+
* Maps the error value
|
|
2431
|
+
*/
|
|
2432
|
+
mapError<E2 extends Type>(f: (e: E) => E2): Exit<E2, A>;
|
|
2433
|
+
/**
|
|
2434
|
+
* Maps both error and success values
|
|
2435
|
+
*/
|
|
2436
|
+
mapBoth<E2 extends Type, B extends Type>(onError: (e: E) => E2, onSuccess: (a: A) => B): Exit<E2, B>;
|
|
2437
|
+
/**
|
|
2438
|
+
* Flat maps the success value
|
|
2439
|
+
*/
|
|
2440
|
+
flatMap<B extends Type>(f: (a: A) => Exit<E, B>): Exit<E, B>;
|
|
2441
|
+
/**
|
|
2442
|
+
* Pattern matches over the Exit
|
|
2443
|
+
*/
|
|
2444
|
+
fold<T>(onFailure: (e: E) => T, onSuccess: (a: A) => T, onInterrupted?: (fiberId: string) => T): T;
|
|
2445
|
+
/**
|
|
2446
|
+
* Pattern matches over the Exit with object patterns
|
|
2447
|
+
*/
|
|
2448
|
+
match<T>(patterns: {
|
|
2449
|
+
Success: (value: A) => T;
|
|
2450
|
+
Failure: (error: E) => T;
|
|
2451
|
+
Interrupted: (fiberId: string) => T;
|
|
2452
|
+
}): T;
|
|
2453
|
+
/**
|
|
2454
|
+
* Returns the success value or throws
|
|
2455
|
+
*/
|
|
2456
|
+
orThrow(): A;
|
|
2457
|
+
/**
|
|
2458
|
+
* Returns the success value or a default
|
|
2459
|
+
*/
|
|
2460
|
+
orElse(defaultValue: A): A;
|
|
2461
|
+
/**
|
|
2462
|
+
* Converts to Option (Some for Success, None otherwise)
|
|
2463
|
+
*/
|
|
2464
|
+
toOption(): Option<A>;
|
|
2465
|
+
/**
|
|
2466
|
+
* Converts to Either (Right for Success, Left for Failure)
|
|
2467
|
+
* Throws if Interrupted
|
|
2468
|
+
*/
|
|
2469
|
+
toEither(): Either<E, A>;
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns the raw value for inspection
|
|
2472
|
+
*/
|
|
2473
|
+
toValue(): {
|
|
2474
|
+
_tag: ExitTag;
|
|
2475
|
+
value?: A;
|
|
2476
|
+
error?: E;
|
|
2477
|
+
fiberId?: string;
|
|
2478
|
+
};
|
|
2479
|
+
/**
|
|
2480
|
+
* String representation
|
|
2481
|
+
*/
|
|
2482
|
+
toString(): string;
|
|
2483
|
+
/**
|
|
2484
|
+
* JSON serialization
|
|
2485
|
+
*/
|
|
2486
|
+
toJSON(): {
|
|
2487
|
+
_tag: ExitTag;
|
|
2488
|
+
value?: A;
|
|
2489
|
+
error?: E;
|
|
2490
|
+
fiberId?: string;
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Exit type for representing effect outcomes.
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* ```typescript
|
|
2498
|
+
* const success = Exit.succeed(42)
|
|
2499
|
+
* const failure = Exit.fail(new Error("oops"))
|
|
2500
|
+
* const interrupted = Exit.interrupt("fiber-123")
|
|
2501
|
+
*
|
|
2502
|
+
* success.fold(
|
|
2503
|
+
* (err) => console.error(err),
|
|
2504
|
+
* (value) => console.log(value),
|
|
2505
|
+
* (fiberId) => console.log("interrupted:", fiberId)
|
|
2506
|
+
* )
|
|
2507
|
+
* ```
|
|
2508
|
+
*/
|
|
2509
|
+
declare const Exit: (<E extends Type, A extends Type>(value: A) => Exit<E, A>) & {
|
|
2510
|
+
/**
|
|
2511
|
+
* Creates a Success Exit
|
|
2512
|
+
*/
|
|
2513
|
+
succeed: <E extends Type, A extends Type>(value: A) => Exit<E, A>;
|
|
2514
|
+
/**
|
|
2515
|
+
* Creates a Failure Exit
|
|
2516
|
+
*/
|
|
2517
|
+
fail: <E extends Type, A extends Type>(error: E) => Exit<E, A>;
|
|
2518
|
+
/**
|
|
2519
|
+
* Creates an Interrupted Exit with a fiber ID
|
|
2520
|
+
*/
|
|
2521
|
+
interrupt: <E extends Type, A extends Type>(fiberId: string) => Exit<E, A>;
|
|
2522
|
+
/**
|
|
2523
|
+
* Creates an Interrupted Exit with a default fiber ID
|
|
2524
|
+
*/
|
|
2525
|
+
interrupted: <E extends Type, A extends Type>() => Exit<E, A>;
|
|
2526
|
+
/**
|
|
2527
|
+
* Type guard for Success
|
|
2528
|
+
*/
|
|
2529
|
+
isSuccess: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is Exit<E, A> & {
|
|
2530
|
+
readonly _tag: "Success";
|
|
2531
|
+
value: A;
|
|
2532
|
+
};
|
|
2533
|
+
/**
|
|
2534
|
+
* Type guard for Failure
|
|
2535
|
+
*/
|
|
2536
|
+
isFailure: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is Exit<E, A> & {
|
|
2537
|
+
readonly _tag: "Failure";
|
|
2538
|
+
error: E;
|
|
2539
|
+
};
|
|
2540
|
+
/**
|
|
2541
|
+
* Type guard for Interrupted
|
|
2542
|
+
*/
|
|
2543
|
+
isInterrupted: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is Exit<E, A> & {
|
|
2544
|
+
readonly _tag: "Interrupted";
|
|
2545
|
+
fiberId: string;
|
|
2546
|
+
};
|
|
2547
|
+
/**
|
|
2548
|
+
* Creates an Exit from an Either
|
|
2549
|
+
*/
|
|
2550
|
+
fromEither: <E extends Type, A extends Type>(either: Either<E, A>) => Exit<E, A>;
|
|
2551
|
+
/**
|
|
2552
|
+
* Creates an Exit from an Option
|
|
2553
|
+
*/
|
|
2554
|
+
fromOption: <A extends Type>(option: Option<A>, onNone: () => unknown) => Exit<unknown, A>;
|
|
2555
|
+
/**
|
|
2556
|
+
* Combines two Exits, keeping the first failure or combining successes
|
|
2557
|
+
*/
|
|
2558
|
+
zip: <E extends Type, A extends Type, B extends Type>(exitA: Exit<E, A>, exitB: Exit<E, B>) => Exit<E, readonly [A, B]>;
|
|
2559
|
+
/**
|
|
2560
|
+
* Collects all Exits into an Exit of array
|
|
2561
|
+
*/
|
|
2562
|
+
all: <E extends Type, A extends Type>(exits: readonly Exit<E, A>[]) => Exit<E, readonly A[]>;
|
|
2563
|
+
};
|
|
2564
|
+
//#endregion
|
|
2565
|
+
//#region src/io/Layer.d.ts
|
|
2566
|
+
/**
|
|
2567
|
+
* Layer module - service construction recipes.
|
|
2568
|
+
* @module Layer
|
|
2569
|
+
* @category IO
|
|
2570
|
+
*
|
|
2571
|
+
* Layers describe how to construct services, including their dependencies.
|
|
2572
|
+
* They can be composed to build complex service graphs.
|
|
2573
|
+
*/
|
|
2574
|
+
/**
|
|
2575
|
+
* A Layer describes how to build a service or set of services.
|
|
2576
|
+
*
|
|
2577
|
+
* @typeParam RIn - Required services (dependencies)
|
|
2578
|
+
* @typeParam E - Possible errors during construction
|
|
2579
|
+
* @typeParam ROut - Services provided by this layer
|
|
2580
|
+
*
|
|
2581
|
+
* @example
|
|
2582
|
+
* ```typescript
|
|
2583
|
+
* // A layer that provides a Logger service
|
|
2584
|
+
* const LoggerLive = Layer.succeed(Logger, consoleLogger)
|
|
2585
|
+
*
|
|
2586
|
+
* // A layer that requires Config and provides Database
|
|
2587
|
+
* const DatabaseLive = Layer.fromFunction(Database, (config: Config) =>
|
|
2588
|
+
* createDatabase(config.connectionString)
|
|
2589
|
+
* )
|
|
2590
|
+
* ```
|
|
2591
|
+
*/
|
|
2592
|
+
interface Layer<RIn extends Type, E extends Type, ROut extends Type> {
|
|
2593
|
+
/**
|
|
2594
|
+
* Type brand
|
|
2595
|
+
* @internal
|
|
2596
|
+
*/
|
|
2597
|
+
readonly _tag: "Layer";
|
|
2598
|
+
/**
|
|
2599
|
+
* Phantom types
|
|
2600
|
+
* @internal
|
|
2601
|
+
*/
|
|
2602
|
+
readonly _RIn?: RIn;
|
|
2603
|
+
readonly _E?: E;
|
|
2604
|
+
readonly _ROut?: ROut;
|
|
2605
|
+
/**
|
|
2606
|
+
* The build function that creates the context
|
|
2607
|
+
* @internal
|
|
2608
|
+
*/
|
|
2609
|
+
readonly build: (input: Context<RIn>) => Promise<Context<ROut>>;
|
|
2610
|
+
/**
|
|
2611
|
+
* Composes this layer with another, running them in sequence.
|
|
2612
|
+
* The output of this layer becomes available to the next layer.
|
|
2613
|
+
* @param that - Layer to compose with
|
|
2614
|
+
*/
|
|
2615
|
+
provideToAndMerge<RIn2 extends Type, E2 extends Type, ROut2 extends Type>(that: Layer<RIn2 | ROut, E2, ROut2>): Layer<RIn | Exclude<RIn2, ROut>, E | E2, ROut | ROut2>;
|
|
2616
|
+
/**
|
|
2617
|
+
* Merges two independent layers.
|
|
2618
|
+
* @param that - Layer to merge with
|
|
2619
|
+
*/
|
|
2620
|
+
merge<RIn2 extends Type, E2 extends Type, ROut2 extends Type>(that: Layer<RIn2, E2, ROut2>): Layer<RIn | RIn2, E | E2, ROut | ROut2>;
|
|
2621
|
+
/**
|
|
2622
|
+
* Maps the output of this layer.
|
|
2623
|
+
* @param f - Function to transform the output
|
|
2624
|
+
*/
|
|
2625
|
+
map<ROut2 extends Type>(f: (ctx: Context<ROut>) => Context<ROut2>): Layer<RIn, E, ROut2>;
|
|
2626
|
+
/**
|
|
2627
|
+
* String representation
|
|
2628
|
+
*/
|
|
2629
|
+
toString(): string;
|
|
2630
|
+
}
|
|
2631
|
+
/**
|
|
2632
|
+
* Layer companion object with construction methods
|
|
2633
|
+
*/
|
|
2634
|
+
declare const Layer: {
|
|
2635
|
+
/**
|
|
2636
|
+
* Creates a layer that provides a service with a constant value.
|
|
2637
|
+
* @param tag - The service tag
|
|
2638
|
+
* @param service - The service implementation
|
|
2639
|
+
*/
|
|
2640
|
+
succeed: <S extends Type>(tag: Tag<S>, service: S) => Layer<never, never, S>;
|
|
2641
|
+
/**
|
|
2642
|
+
* Creates a layer from an async function.
|
|
2643
|
+
* @param tag - The service tag
|
|
2644
|
+
* @param f - Async function to create the service
|
|
2645
|
+
*/
|
|
2646
|
+
effect: <S extends Type, E extends Type>(tag: Tag<S>, f: () => Promise<S>) => Layer<never, E, S>;
|
|
2647
|
+
/**
|
|
2648
|
+
* Creates a layer from a sync function.
|
|
2649
|
+
* @param tag - The service tag
|
|
2650
|
+
* @param f - Function to create the service
|
|
2651
|
+
*/
|
|
2652
|
+
sync: <S extends Type>(tag: Tag<S>, f: () => S) => Layer<never, never, S>;
|
|
2653
|
+
/**
|
|
2654
|
+
* Creates a layer that depends on another service.
|
|
2655
|
+
* @param tag - The service tag to provide
|
|
2656
|
+
* @param depTag - The dependency tag
|
|
2657
|
+
* @param f - Function to create the service from the dependency
|
|
2658
|
+
*/
|
|
2659
|
+
fromService: <Dep extends Type, S extends Type>(tag: Tag<S>, depTag: Tag<Dep>, f: (dep: Dep) => S) => Layer<Dep, never, S>;
|
|
2660
|
+
/**
|
|
2661
|
+
* Creates a layer that depends on another service (async).
|
|
2662
|
+
* @param tag - The service tag to provide
|
|
2663
|
+
* @param depTag - The dependency tag
|
|
2664
|
+
* @param f - Async function to create the service from the dependency
|
|
2665
|
+
*/
|
|
2666
|
+
fromServiceEffect: <Dep extends Type, E extends Type, S extends Type>(tag: Tag<S>, depTag: Tag<Dep>, f: (dep: Dep) => Promise<S>) => Layer<Dep, E, S>;
|
|
2667
|
+
/**
|
|
2668
|
+
* Creates a layer from a context.
|
|
2669
|
+
* @param context - The context to use
|
|
2670
|
+
*/
|
|
2671
|
+
fromContext: <R$1 extends Type>(context: Context<R$1>) => Layer<never, never, R$1>;
|
|
2672
|
+
/**
|
|
2673
|
+
* Creates an empty layer that provides nothing.
|
|
2674
|
+
*/
|
|
2675
|
+
empty: () => Layer<never, never, never>;
|
|
2676
|
+
/**
|
|
2677
|
+
* Merges multiple layers into one.
|
|
2678
|
+
* @param layers - Layers to merge
|
|
2679
|
+
*/
|
|
2680
|
+
mergeAll: <Layers extends Layer<Type, Type, Type>[]>(...layers: Layers) => Layer<Layers[number] extends Layer<infer RIn, Type, Type> ? RIn : never, Layers[number] extends Layer<Type, infer E, Type> ? E : never, Layers[number] extends Layer<Type, Type, infer ROut> ? ROut : never>;
|
|
2681
|
+
};
|
|
2682
|
+
/**
|
|
2683
|
+
* Type helper to extract input requirements from a Layer
|
|
2684
|
+
*/
|
|
2685
|
+
type LayerInput<L> = L extends Layer<infer RIn, Type, Type> ? RIn : never;
|
|
2686
|
+
/**
|
|
2687
|
+
* Type helper to extract error type from a Layer
|
|
2688
|
+
*/
|
|
2689
|
+
type LayerError<L> = L extends Layer<Type, infer E, Type> ? E : never;
|
|
2690
|
+
/**
|
|
2691
|
+
* Type helper to extract output services from a Layer
|
|
2692
|
+
*/
|
|
2693
|
+
type LayerOutput<L> = L extends Layer<Type, Type, infer ROut> ? ROut : never;
|
|
2694
|
+
//#endregion
|
|
2695
|
+
//#region src/io/IO.d.ts
|
|
2696
|
+
/**
|
|
2697
|
+
* Error thrown when an effect times out.
|
|
2698
|
+
*/
|
|
2699
|
+
declare class TimeoutError extends Error {
|
|
2700
|
+
readonly duration: number;
|
|
2701
|
+
readonly _tag: "TimeoutError";
|
|
2702
|
+
constructor(duration: number, message?: string);
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Error thrown when an effect is interrupted.
|
|
2706
|
+
*/
|
|
2707
|
+
declare class InterruptedError extends Error {
|
|
2708
|
+
readonly _tag: "InterruptedError";
|
|
2709
|
+
constructor(message?: string);
|
|
2710
|
+
}
|
|
2711
|
+
/**
|
|
2712
|
+
* IO Effect type module - a lazy, composable effect type with typed errors.
|
|
2713
|
+
* @module IO
|
|
2714
|
+
* @category IO
|
|
2715
|
+
*
|
|
2716
|
+
* IO<R, E, A> represents an effectful computation that:
|
|
2717
|
+
* - Requires environment R to run
|
|
2718
|
+
* - May fail with error E
|
|
2719
|
+
* - Produces value A on success
|
|
2720
|
+
*
|
|
2721
|
+
* Key features:
|
|
2722
|
+
* - Lazy execution (nothing runs until explicitly executed)
|
|
2723
|
+
* - Unified sync/async API
|
|
2724
|
+
* - Typed errors at compile time
|
|
2725
|
+
* - Composable via map/flatMap
|
|
2726
|
+
*/
|
|
2727
|
+
/**
|
|
2728
|
+
* Internal effect representation types
|
|
2729
|
+
*/
|
|
2730
|
+
type IOEffect<R$1, E, A> = {
|
|
2731
|
+
readonly _tag: "Sync";
|
|
2732
|
+
readonly thunk: () => A;
|
|
2733
|
+
} | {
|
|
2734
|
+
readonly _tag: "Async";
|
|
2735
|
+
readonly thunk: () => Promise<A>;
|
|
2736
|
+
} | {
|
|
2737
|
+
readonly _tag: "Auto";
|
|
2738
|
+
readonly thunk: () => A | Promise<A>;
|
|
2739
|
+
} | {
|
|
2740
|
+
readonly _tag: "Succeed";
|
|
2741
|
+
readonly value: A;
|
|
2742
|
+
} | {
|
|
2743
|
+
readonly _tag: "Fail";
|
|
2744
|
+
readonly error: E;
|
|
2745
|
+
} | {
|
|
2746
|
+
readonly _tag: "Die";
|
|
2747
|
+
readonly defect: unknown;
|
|
2748
|
+
} | {
|
|
2749
|
+
readonly _tag: "Interrupt";
|
|
2750
|
+
} | {
|
|
2751
|
+
readonly _tag: "FlatMap";
|
|
2752
|
+
readonly effect: IO<R$1, E, unknown>;
|
|
2753
|
+
readonly f: (a: unknown) => IO<R$1, E, A>;
|
|
2754
|
+
} | {
|
|
2755
|
+
readonly _tag: "Map";
|
|
2756
|
+
readonly effect: IO<R$1, E, unknown>;
|
|
2757
|
+
readonly f: (a: unknown) => A;
|
|
2758
|
+
} | {
|
|
2759
|
+
readonly _tag: "MapError";
|
|
2760
|
+
readonly effect: IO<R$1, unknown, A>;
|
|
2761
|
+
readonly f: (e: unknown) => E;
|
|
2762
|
+
} | {
|
|
2763
|
+
readonly _tag: "Recover";
|
|
2764
|
+
readonly effect: IO<R$1, E, A>;
|
|
2765
|
+
readonly fallback: A;
|
|
2766
|
+
} | {
|
|
2767
|
+
readonly _tag: "RecoverWith";
|
|
2768
|
+
readonly effect: IO<R$1, E, A>;
|
|
2769
|
+
readonly f: (e: E) => IO<R$1, E, A>;
|
|
2770
|
+
} | {
|
|
2771
|
+
readonly _tag: "Fold";
|
|
2772
|
+
readonly effect: IO<R$1, E, unknown>;
|
|
2773
|
+
readonly onFailure: (e: E) => A;
|
|
2774
|
+
readonly onSuccess: (a: unknown) => A;
|
|
2775
|
+
} | {
|
|
2776
|
+
readonly _tag: "Bracket";
|
|
2777
|
+
readonly acquire: IO<R$1, E, unknown>;
|
|
2778
|
+
readonly use: (a: unknown) => IO<R$1, E, A>;
|
|
2779
|
+
readonly release: (a: unknown) => IO<R$1, never, void>;
|
|
2780
|
+
} | {
|
|
2781
|
+
readonly _tag: "Race";
|
|
2782
|
+
readonly effects: readonly IO<R$1, E, A>[];
|
|
2783
|
+
} | {
|
|
2784
|
+
readonly _tag: "Timeout";
|
|
2785
|
+
readonly effect: IO<R$1, E, A>;
|
|
2786
|
+
readonly duration: number;
|
|
2787
|
+
} | {
|
|
2788
|
+
readonly _tag: "Service";
|
|
2789
|
+
readonly tag: Tag<A>;
|
|
2790
|
+
} | {
|
|
2791
|
+
readonly _tag: "ProvideContext";
|
|
2792
|
+
readonly effect: IO<R$1, E, A>;
|
|
2793
|
+
readonly context: Context<R$1>;
|
|
2794
|
+
};
|
|
2795
|
+
/**
|
|
2796
|
+
* IO<R, E, A> represents a lazy, composable effect.
|
|
2797
|
+
*
|
|
2798
|
+
* @typeParam R - Requirements (environment/dependencies needed to run)
|
|
2799
|
+
* @typeParam E - Error type (typed failures)
|
|
2800
|
+
* @typeParam A - Success type (value produced on success)
|
|
2801
|
+
*/
|
|
2802
|
+
interface IO<R$1 extends Type, E extends Type, A extends Type> {
|
|
2803
|
+
/**
|
|
2804
|
+
* Internal effect representation
|
|
2805
|
+
* @internal
|
|
2806
|
+
*/
|
|
2807
|
+
readonly _effect: IOEffect<R$1, E, A>;
|
|
2808
|
+
/**
|
|
2809
|
+
* Phantom type for requirements
|
|
2810
|
+
* @internal
|
|
2811
|
+
*/
|
|
2812
|
+
readonly _R?: R$1;
|
|
2813
|
+
/**
|
|
2814
|
+
* Phantom type for error
|
|
2815
|
+
* @internal
|
|
2816
|
+
*/
|
|
2817
|
+
readonly _E?: E;
|
|
2818
|
+
/**
|
|
2819
|
+
* Phantom type for success
|
|
2820
|
+
* @internal
|
|
2821
|
+
*/
|
|
2822
|
+
readonly _A?: A;
|
|
2823
|
+
/**
|
|
2824
|
+
* Transforms the success value.
|
|
2825
|
+
* @param f - Function to apply to the success value
|
|
2826
|
+
* @returns New IO with transformed value
|
|
2827
|
+
*/
|
|
2828
|
+
map<B extends Type>(f: (a: A) => B): IO<R$1, E, B>;
|
|
2829
|
+
/**
|
|
2830
|
+
* Chains another IO effect based on the success value.
|
|
2831
|
+
* @param f - Function returning next IO effect
|
|
2832
|
+
* @returns New IO with combined effects
|
|
2833
|
+
*/
|
|
2834
|
+
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R$1 | R2, E | E2, B>;
|
|
2835
|
+
/**
|
|
2836
|
+
* Applies a side effect without changing the value.
|
|
2837
|
+
* @param f - Side effect function
|
|
2838
|
+
* @returns Same IO for chaining
|
|
2839
|
+
*/
|
|
2840
|
+
tap(f: (a: A) => void): IO<R$1, E, A>;
|
|
2841
|
+
/**
|
|
2842
|
+
* Applies an effectful side effect without changing the value.
|
|
2843
|
+
* @param f - Function returning IO for side effect
|
|
2844
|
+
* @returns Same value after running side effect
|
|
2845
|
+
*/
|
|
2846
|
+
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R$1 | R2, E | E2, A>;
|
|
2847
|
+
/**
|
|
2848
|
+
* Transforms the error value.
|
|
2849
|
+
* @param f - Function to apply to the error
|
|
2850
|
+
* @returns New IO with transformed error
|
|
2851
|
+
*/
|
|
2852
|
+
mapError<E2 extends Type>(f: (e: E) => E2): IO<R$1, E2, A>;
|
|
2853
|
+
/**
|
|
2854
|
+
* Recovers from any error with a fallback value.
|
|
2855
|
+
* @param fallback - Value to use on error
|
|
2856
|
+
* @returns New IO that never fails
|
|
2857
|
+
*/
|
|
2858
|
+
recover<B extends Type>(fallback: B): IO<R$1, never, A | B>;
|
|
2859
|
+
/**
|
|
2860
|
+
* Recovers from error by running another effect.
|
|
2861
|
+
* @param f - Function returning recovery effect
|
|
2862
|
+
* @returns New IO with error handling
|
|
2863
|
+
*/
|
|
2864
|
+
recoverWith<R2 extends Type, E2 extends Type, B extends Type>(f: (e: E) => IO<R2, E2, B>): IO<R$1 | R2, E2, A | B>;
|
|
2865
|
+
/**
|
|
2866
|
+
* Pattern matches on success and failure.
|
|
2867
|
+
* @param onFailure - Handler for failures
|
|
2868
|
+
* @param onSuccess - Handler for successes
|
|
2869
|
+
* @returns New IO with handled result
|
|
2870
|
+
*/
|
|
2871
|
+
fold<B extends Type>(onFailure: (e: E) => B, onSuccess: (a: A) => B): IO<R$1, never, B>;
|
|
2872
|
+
/**
|
|
2873
|
+
* Pattern matches with object pattern syntax.
|
|
2874
|
+
*/
|
|
2875
|
+
match<B extends Type>(patterns: {
|
|
2876
|
+
failure: (e: E) => B;
|
|
2877
|
+
success: (a: A) => B;
|
|
2878
|
+
}): IO<R$1, never, B>;
|
|
2879
|
+
/**
|
|
2880
|
+
* Catches errors with a specific tag and handles them.
|
|
2881
|
+
* @param tag - The error tag to catch
|
|
2882
|
+
* @param handler - Handler for the caught error
|
|
2883
|
+
*/
|
|
2884
|
+
catchTag<K$1 extends (E extends {
|
|
2885
|
+
_tag: string;
|
|
2886
|
+
} ? E["_tag"] : never), R2 extends Type, E2 extends Type, B extends Type>(tag: K$1, handler: (e: Extract<E, {
|
|
2887
|
+
_tag: K$1;
|
|
2888
|
+
}>) => IO<R2, E2, B>): IO<R$1 | R2, Exclude<E, {
|
|
2889
|
+
_tag: K$1;
|
|
2890
|
+
}> | E2, A | B>;
|
|
2891
|
+
/**
|
|
2892
|
+
* Catches all errors (alias for recoverWith).
|
|
2893
|
+
*/
|
|
2894
|
+
catchAll<R2 extends Type, E2 extends Type, B extends Type>(handler: (e: E) => IO<R2, E2, B>): IO<R$1 | R2, E2, A | B>;
|
|
2895
|
+
/**
|
|
2896
|
+
* Retries the effect up to n times on failure.
|
|
2897
|
+
* @param n - Maximum number of retries
|
|
2898
|
+
*/
|
|
2899
|
+
retry(n: number): IO<R$1, E, A>;
|
|
2900
|
+
/**
|
|
2901
|
+
* Retries the effect with a delay between attempts.
|
|
2902
|
+
* @param n - Maximum number of retries
|
|
2903
|
+
* @param delayMs - Delay between retries in milliseconds
|
|
2904
|
+
*/
|
|
2905
|
+
retryWithDelay(n: number, delayMs: number): IO<R$1, E, A>;
|
|
2906
|
+
/**
|
|
2907
|
+
* Sequences two IOs, keeping the second value.
|
|
2908
|
+
*/
|
|
2909
|
+
zipRight<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R$1 | R2, E | E2, B>;
|
|
2910
|
+
/**
|
|
2911
|
+
* Sequences two IOs, keeping the first value.
|
|
2912
|
+
*/
|
|
2913
|
+
zipLeft<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R$1 | R2, E | E2, A>;
|
|
2914
|
+
/**
|
|
2915
|
+
* Zips two IOs into a tuple.
|
|
2916
|
+
*/
|
|
2917
|
+
zip<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R$1 | R2, E | E2, readonly [A, B]>;
|
|
2918
|
+
/**
|
|
2919
|
+
* Flattens a nested IO.
|
|
2920
|
+
*/
|
|
2921
|
+
flatten<R2 extends Type, E2 extends Type, B extends Type>(this: IO<R$1, E, IO<R2, E2, B>>): IO<R$1 | R2, E | E2, B>;
|
|
2922
|
+
/**
|
|
2923
|
+
* Provides a context to satisfy the requirements of this effect.
|
|
2924
|
+
* @param context - The context containing required services
|
|
2925
|
+
*/
|
|
2926
|
+
provideContext<R2 extends R$1>(context: Context<R2>): IO<Exclude<R$1, R2>, E, A>;
|
|
2927
|
+
/**
|
|
2928
|
+
* Provides a single service to satisfy part of the requirements.
|
|
2929
|
+
* @param tag - The service tag
|
|
2930
|
+
* @param service - The service implementation
|
|
2931
|
+
*/
|
|
2932
|
+
provideService<S extends Type>(tag: Tag<S>, service: S): IO<Exclude<R$1, S>, E, A>;
|
|
2933
|
+
/**
|
|
2934
|
+
* Provides services using a layer.
|
|
2935
|
+
* @param layer - The layer that provides services
|
|
2936
|
+
*/
|
|
2937
|
+
provideLayer<RIn extends Type, E2 extends Type, ROut extends R$1>(layer: Layer<RIn, E2, ROut>): IO<RIn | Exclude<R$1, ROut>, E | E2, A>;
|
|
2938
|
+
/**
|
|
2939
|
+
* Runs the effect and returns a Promise of the value.
|
|
2940
|
+
* Throws on error. Requires R = never.
|
|
2941
|
+
*/
|
|
2942
|
+
run(this: IO<never, E, A>): Promise<A>;
|
|
2943
|
+
/**
|
|
2944
|
+
* Runs a sync effect and returns the value.
|
|
2945
|
+
* Throws if the effect is async or has unmet requirements.
|
|
2946
|
+
*/
|
|
2947
|
+
runSync(this: IO<never, E, A>): A;
|
|
2948
|
+
/**
|
|
2949
|
+
* Runs the effect and returns an Either.
|
|
2950
|
+
*/
|
|
2951
|
+
runEither(this: IO<never, E, A>): Promise<Either<E, A>>;
|
|
2952
|
+
/**
|
|
2953
|
+
* Runs the effect and returns an Exit.
|
|
2954
|
+
*/
|
|
2955
|
+
runExit(this: IO<never, E, A>): Promise<Exit<E, A>>;
|
|
2956
|
+
/**
|
|
2957
|
+
* Runs the effect and returns an Option.
|
|
2958
|
+
* Some(value) on success, None on failure.
|
|
2959
|
+
*/
|
|
2960
|
+
runOption(this: IO<never, E, A>): Promise<Option<A>>;
|
|
2961
|
+
/**
|
|
2962
|
+
* Runs the effect and returns a Try.
|
|
2963
|
+
* Success(value) on success, Failure(error) on failure.
|
|
2964
|
+
*/
|
|
2965
|
+
runTry(this: IO<never, E, A>): Promise<ReturnType<typeof Try<A>>>;
|
|
2966
|
+
/**
|
|
2967
|
+
* Pipes the IO through a function.
|
|
2968
|
+
*/
|
|
2969
|
+
pipe<B>(f: (self: IO<R$1, E, A>) => B): B;
|
|
2970
|
+
/**
|
|
2971
|
+
* Delays execution by the specified milliseconds.
|
|
2972
|
+
*/
|
|
2973
|
+
delay(ms: number): IO<R$1, E, A>;
|
|
2974
|
+
/**
|
|
2975
|
+
* Fails with TimeoutError if the effect doesn't complete within the specified duration.
|
|
2976
|
+
* @param ms - Maximum time in milliseconds
|
|
2977
|
+
*/
|
|
2978
|
+
timeout(ms: number): IO<R$1, E | TimeoutError, A>;
|
|
2979
|
+
/**
|
|
2980
|
+
* Returns a fallback value if the effect doesn't complete within the specified duration.
|
|
2981
|
+
* @param ms - Maximum time in milliseconds
|
|
2982
|
+
* @param fallback - Value to return on timeout
|
|
2983
|
+
*/
|
|
2984
|
+
timeoutTo<B extends Type>(ms: number, fallback: B): IO<R$1, E, A | B>;
|
|
2985
|
+
/**
|
|
2986
|
+
* Converts to string representation.
|
|
2987
|
+
*/
|
|
2988
|
+
toString(): string;
|
|
2989
|
+
/**
|
|
2990
|
+
* Converts to JSON representation.
|
|
2991
|
+
*/
|
|
2992
|
+
toJSON(): {
|
|
2993
|
+
_tag: string;
|
|
2994
|
+
effect: unknown;
|
|
2995
|
+
};
|
|
2996
|
+
/**
|
|
2997
|
+
* Makes IO iterable for generator do-notation (yield* syntax).
|
|
2998
|
+
* Yields the IO itself, allowing IO.gen to extract the value.
|
|
2999
|
+
*/
|
|
3000
|
+
[Symbol.iterator](): Generator<IO<R$1, E, A>, A, A>;
|
|
3001
|
+
}
|
|
3002
|
+
/**
|
|
3003
|
+
* Do-builder interface for chaining binds and maps
|
|
3004
|
+
*/
|
|
3005
|
+
interface DoBuilder<R$1 extends Type, E extends Type, Ctx extends Record<string, Type>> {
|
|
3006
|
+
/**
|
|
3007
|
+
* The underlying IO effect
|
|
3008
|
+
*/
|
|
3009
|
+
readonly effect: IO<R$1, E, Ctx>;
|
|
3010
|
+
/**
|
|
3011
|
+
* Binds the result of an effect to a named property in the context.
|
|
3012
|
+
* @param name - The property name to bind to
|
|
3013
|
+
* @param f - Function that returns an IO effect (receives current context)
|
|
3014
|
+
*/
|
|
3015
|
+
bind<N extends string, R2 extends Type, E2 extends Type, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => IO<R2, E2, A>): DoBuilder<R$1 | R2, E | E2, Ctx & Record<N, A>>;
|
|
3016
|
+
/**
|
|
3017
|
+
* Binds a pure value to a named property in the context.
|
|
3018
|
+
* @param name - The property name to bind to
|
|
3019
|
+
* @param f - Function that returns a value (receives current context)
|
|
3020
|
+
*/
|
|
3021
|
+
let<N extends string, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => A): DoBuilder<R$1, E, Ctx & Record<N, A>>;
|
|
3022
|
+
/**
|
|
3023
|
+
* Transforms the final context value.
|
|
3024
|
+
* @param f - Function to transform the context
|
|
3025
|
+
*/
|
|
3026
|
+
map<B extends Type>(f: (ctx: Ctx) => B): IO<R$1, E, B>;
|
|
3027
|
+
/**
|
|
3028
|
+
* Chains to another IO based on the context.
|
|
3029
|
+
* @param f - Function that returns an IO effect
|
|
3030
|
+
*/
|
|
3031
|
+
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): IO<R$1 | R2, E | E2, B>;
|
|
3032
|
+
/**
|
|
3033
|
+
* Executes a side effect without changing the context.
|
|
3034
|
+
* @param f - Side effect function
|
|
3035
|
+
*/
|
|
3036
|
+
tap(f: (ctx: Ctx) => void): DoBuilder<R$1, E, Ctx>;
|
|
3037
|
+
/**
|
|
3038
|
+
* Executes an effectful side effect without changing the context.
|
|
3039
|
+
* @param f - Function returning an IO for the side effect
|
|
3040
|
+
*/
|
|
3041
|
+
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): DoBuilder<R$1 | R2, E | E2, Ctx>;
|
|
3042
|
+
/**
|
|
3043
|
+
* Returns the final context as is.
|
|
3044
|
+
*/
|
|
3045
|
+
done(): IO<R$1, E, Ctx>;
|
|
3046
|
+
}
|
|
3047
|
+
/**
|
|
3048
|
+
* IO effect type for lazy, composable effects with typed errors.
|
|
3049
|
+
*
|
|
3050
|
+
* @example
|
|
3051
|
+
* ```typescript
|
|
3052
|
+
* // Basic usage
|
|
3053
|
+
* const program = IO.sync(() => 42)
|
|
3054
|
+
* .map(x => x * 2)
|
|
3055
|
+
* .flatMap(x => IO.succeed(x + 1))
|
|
3056
|
+
*
|
|
3057
|
+
* const result = await program.run() // 85
|
|
3058
|
+
*
|
|
3059
|
+
* // Error handling
|
|
3060
|
+
* const safe = IO.tryPromise({
|
|
3061
|
+
* try: () => fetch('/api/data'),
|
|
3062
|
+
* catch: (e) => new NetworkError(e)
|
|
3063
|
+
* })
|
|
3064
|
+
* .map(res => res.json())
|
|
3065
|
+
* .recover({ fallback: 'default' })
|
|
3066
|
+
*
|
|
3067
|
+
* // Composition
|
|
3068
|
+
* const composed = IO.all([
|
|
3069
|
+
* IO.succeed(1),
|
|
3070
|
+
* IO.succeed(2),
|
|
3071
|
+
* IO.succeed(3)
|
|
3072
|
+
* ]) // IO<never, never, [1, 2, 3]>
|
|
3073
|
+
* ```
|
|
3074
|
+
*/
|
|
3075
|
+
declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknown, A>) & {
|
|
3076
|
+
/**
|
|
3077
|
+
* Creates an IO from a synchronous thunk.
|
|
3078
|
+
* The function is not executed until the IO is run.
|
|
3079
|
+
*/
|
|
3080
|
+
sync: <A extends Type>(f: () => A) => IO<never, never, A>;
|
|
3081
|
+
/**
|
|
3082
|
+
* Creates an IO that succeeds with the given value.
|
|
3083
|
+
*/
|
|
3084
|
+
succeed: <A extends Type>(value: A) => IO<never, never, A>;
|
|
3085
|
+
/**
|
|
3086
|
+
* Creates an IO that fails with the given error.
|
|
3087
|
+
*/
|
|
3088
|
+
fail: <E extends Type>(error: E) => IO<never, E, never>;
|
|
3089
|
+
/**
|
|
3090
|
+
* Creates an IO that dies with an unrecoverable defect.
|
|
3091
|
+
*/
|
|
3092
|
+
die: (defect: unknown) => IO<never, never, never>;
|
|
3093
|
+
/**
|
|
3094
|
+
* Creates an IO from an async thunk.
|
|
3095
|
+
* The Promise is not created until the IO is run.
|
|
3096
|
+
*/
|
|
3097
|
+
async: <A extends Type>(f: () => Promise<A>) => IO<never, unknown, A>;
|
|
3098
|
+
/**
|
|
3099
|
+
* Creates an IO from a Promise with error handling.
|
|
3100
|
+
*/
|
|
3101
|
+
tryPromise: <A extends Type, E extends Type>(opts: {
|
|
3102
|
+
readonly try: () => Promise<A>;
|
|
3103
|
+
readonly catch: (error: unknown) => E;
|
|
3104
|
+
}) => IO<never, E, A>;
|
|
3105
|
+
/**
|
|
3106
|
+
* Creates an IO from a function that might throw.
|
|
3107
|
+
*/
|
|
3108
|
+
tryCatch: <A extends Type, E extends Type>(f: () => A, onError: (error: unknown) => E) => IO<never, E, A>;
|
|
3109
|
+
/**
|
|
3110
|
+
* Lifts a synchronous function into an IO-returning function.
|
|
3111
|
+
*/
|
|
3112
|
+
liftSync: <Args extends unknown[], A extends Type>(f: (...args: Args) => A) => (...args: Args) => IO<never, never, A>;
|
|
3113
|
+
/**
|
|
3114
|
+
* Lifts a Promise-returning function into an IO-returning function.
|
|
3115
|
+
*/
|
|
3116
|
+
liftPromise: <Args extends unknown[], A extends Type>(f: (...args: Args) => Promise<A>) => (...args: Args) => IO<never, unknown, A>;
|
|
3117
|
+
/**
|
|
3118
|
+
* Creates an IO from an Either.
|
|
3119
|
+
*/
|
|
3120
|
+
fromEither: <E extends Type, A extends Type>(either: Either<E, A>) => IO<never, E, A>;
|
|
3121
|
+
/**
|
|
3122
|
+
* Creates an IO from an Option.
|
|
3123
|
+
*/
|
|
3124
|
+
fromOption: <A extends Type>(option: Option<A>) => IO<never, void, A>;
|
|
3125
|
+
/**
|
|
3126
|
+
* Creates an IO from an Option with custom error.
|
|
3127
|
+
*/
|
|
3128
|
+
fromOptionOrFail: <E extends Type, A extends Type>(option: Option<A>, onNone: () => E) => IO<never, E, A>;
|
|
3129
|
+
/**
|
|
3130
|
+
* Creates an IO from a Try.
|
|
3131
|
+
*/
|
|
3132
|
+
fromTry: <A extends Type>(t: ReturnType<typeof Try<A>>) => IO<never, Error, A>;
|
|
3133
|
+
/**
|
|
3134
|
+
* Creates an IO that requires a service identified by the tag.
|
|
3135
|
+
* The service must be provided before the effect can be run.
|
|
3136
|
+
*
|
|
3137
|
+
* @example
|
|
3138
|
+
* ```typescript
|
|
3139
|
+
* interface Logger {
|
|
3140
|
+
* log(message: string): void
|
|
3141
|
+
* }
|
|
3142
|
+
* const Logger = Tag<Logger>("Logger")
|
|
3143
|
+
*
|
|
3144
|
+
* const program = IO.service(Logger).flatMap(logger =>
|
|
3145
|
+
* IO.sync(() => logger.log("Hello!"))
|
|
3146
|
+
* )
|
|
3147
|
+
*
|
|
3148
|
+
* // Provide the service to run
|
|
3149
|
+
* program.provideService(Logger, consoleLogger).run()
|
|
3150
|
+
* ```
|
|
3151
|
+
*/
|
|
3152
|
+
service: <S extends Type>(tag: Tag<S>) => IO<S, never, S>;
|
|
3153
|
+
/**
|
|
3154
|
+
* Accesses a service and applies a function to it.
|
|
3155
|
+
*/
|
|
3156
|
+
serviceWith: <S extends Type, A extends Type>(tag: Tag<S>, f: (service: S) => A) => IO<S, never, A>;
|
|
3157
|
+
/**
|
|
3158
|
+
* Accesses a service and applies an effectful function to it.
|
|
3159
|
+
*/
|
|
3160
|
+
serviceWithIO: <S extends Type, R$1 extends Type, E extends Type, A extends Type>(tag: Tag<S>, f: (service: S) => IO<R$1, E, A>) => IO<S | R$1, E, A>;
|
|
3161
|
+
/**
|
|
3162
|
+
* Accesses multiple services and applies a function to them.
|
|
3163
|
+
* Provides a convenient way to work with multiple dependencies.
|
|
3164
|
+
*
|
|
3165
|
+
* @example
|
|
3166
|
+
* ```typescript
|
|
3167
|
+
* const program = IO.withServices(
|
|
3168
|
+
* { logger: Logger, db: Database },
|
|
3169
|
+
* ({ logger, db }) => {
|
|
3170
|
+
* logger.log("Querying...")
|
|
3171
|
+
* return db.query("SELECT * FROM users")
|
|
3172
|
+
* }
|
|
3173
|
+
* )
|
|
3174
|
+
* ```
|
|
3175
|
+
*/
|
|
3176
|
+
withServices: <Services extends Record<string, Tag<Type>>, A extends Type>(services: Services, f: (ctx: { [K in keyof Services]: TagService<Services[K]> }) => A | Promise<A>) => IO<TagService<Services[keyof Services]>, unknown, A>;
|
|
3177
|
+
/**
|
|
3178
|
+
* Runs all IOs in parallel and collects results.
|
|
3179
|
+
*/
|
|
3180
|
+
all: <R$1 extends Type, E extends Type, A extends Type>(effects: readonly IO<R$1, E, A>[]) => IO<R$1, E, readonly A[]>;
|
|
3181
|
+
/**
|
|
3182
|
+
* Runs IOs in sequence, returning the first success or last failure.
|
|
3183
|
+
*/
|
|
3184
|
+
firstSuccessOf: <R$1 extends Type, E extends Type, A extends Type>(effects: readonly IO<R$1, E, A>[]) => IO<R$1, E, A>;
|
|
3185
|
+
/**
|
|
3186
|
+
* Creates an IO that sleeps for the specified duration.
|
|
3187
|
+
*/
|
|
3188
|
+
sleep: (ms: number) => IO<never, never, void>;
|
|
3189
|
+
/**
|
|
3190
|
+
* Creates an IO that never completes.
|
|
3191
|
+
*/
|
|
3192
|
+
never: <A extends Type = never>() => IO<never, never, A>;
|
|
3193
|
+
/**
|
|
3194
|
+
* Creates a unit IO.
|
|
3195
|
+
*/
|
|
3196
|
+
readonly unit: IO<never, never, void>;
|
|
3197
|
+
/**
|
|
3198
|
+
* Converts a nullable value to an IO.
|
|
3199
|
+
*/
|
|
3200
|
+
fromNullable: <A extends Type>(value: A | null | undefined) => IO<never, void, A>;
|
|
3201
|
+
/**
|
|
3202
|
+
* Creates an IO that is immediately interrupted.
|
|
3203
|
+
*/
|
|
3204
|
+
interrupt: () => IO<never, never, never>;
|
|
3205
|
+
/**
|
|
3206
|
+
* Ensures a resource is properly released after use.
|
|
3207
|
+
* The release function always runs, even if use fails.
|
|
3208
|
+
*
|
|
3209
|
+
* @example
|
|
3210
|
+
* ```typescript
|
|
3211
|
+
* const withFile = IO.bracket(
|
|
3212
|
+
* IO.sync(() => openFile("data.txt")), // acquire
|
|
3213
|
+
* file => IO.async(() => file.read()), // use
|
|
3214
|
+
* file => IO.sync(() => file.close()) // release
|
|
3215
|
+
* )
|
|
3216
|
+
* ```
|
|
3217
|
+
*/
|
|
3218
|
+
bracket: <R$1 extends Type, E extends Type, A extends Type, B extends Type>(acquire: IO<R$1, E, A>, use: (a: A) => IO<R$1, E, B>, release: (a: A) => IO<R$1, never, void>) => IO<R$1, E, B>;
|
|
3219
|
+
/**
|
|
3220
|
+
* Alias for bracket with a more descriptive name.
|
|
3221
|
+
*/
|
|
3222
|
+
acquireRelease: <R$1 extends Type, E extends Type, A extends Type, B extends Type>(acquire: IO<R$1, E, A>, use: (a: A) => IO<R$1, E, B>, release: (a: A) => IO<R$1, never, void>) => IO<R$1, E, B>;
|
|
3223
|
+
/**
|
|
3224
|
+
* Races multiple effects, returning the first to complete.
|
|
3225
|
+
* Note: Other effects are NOT cancelled (JS limitation).
|
|
3226
|
+
*
|
|
3227
|
+
* @example
|
|
3228
|
+
* ```typescript
|
|
3229
|
+
* const result = await IO.race([
|
|
3230
|
+
* IO.sleep(1000).map(() => "slow"),
|
|
3231
|
+
* IO.sleep(100).map(() => "fast")
|
|
3232
|
+
* ]).run() // "fast"
|
|
3233
|
+
* ```
|
|
3234
|
+
*/
|
|
3235
|
+
race: <R$1 extends Type, E extends Type, A extends Type>(effects: readonly IO<R$1, E, A>[]) => IO<R$1, E, A>;
|
|
3236
|
+
/**
|
|
3237
|
+
* Returns the first effect to succeed, or fails if all fail.
|
|
3238
|
+
*
|
|
3239
|
+
* @example
|
|
3240
|
+
* ```typescript
|
|
3241
|
+
* const result = await IO.any([
|
|
3242
|
+
* IO.fail("error1"),
|
|
3243
|
+
* IO.succeed("success"),
|
|
3244
|
+
* IO.fail("error2")
|
|
3245
|
+
* ]).run() // "success"
|
|
3246
|
+
* ```
|
|
3247
|
+
*/
|
|
3248
|
+
any: <R$1 extends Type, E extends Type, A extends Type>(effects: readonly IO<R$1, E, A>[]) => IO<R$1, E, A>;
|
|
3249
|
+
/**
|
|
3250
|
+
* Executes an effect for each element in the array, collecting results.
|
|
3251
|
+
*
|
|
3252
|
+
* @example
|
|
3253
|
+
* ```typescript
|
|
3254
|
+
* const results = await IO.forEach([1, 2, 3], n =>
|
|
3255
|
+
* IO.sync(() => n * 2)
|
|
3256
|
+
* ).run() // [2, 4, 6]
|
|
3257
|
+
* ```
|
|
3258
|
+
*/
|
|
3259
|
+
forEach: <R$1 extends Type, E extends Type, A extends Type, B extends Type>(items: readonly A[], f: (a: A) => IO<R$1, E, B>) => IO<R$1, E, readonly B[]>;
|
|
3260
|
+
/**
|
|
3261
|
+
* Executes effects for each element in parallel (limited concurrency coming later).
|
|
3262
|
+
* Alias for forEach.
|
|
3263
|
+
*/
|
|
3264
|
+
forEachPar: <R$1 extends Type, E extends Type, A extends Type, B extends Type>(items: readonly A[], f: (a: A) => IO<R$1, E, B>) => IO<R$1, E, readonly B[]>;
|
|
3265
|
+
/**
|
|
3266
|
+
* Creates a timeout effect that fails with TimeoutError.
|
|
3267
|
+
*/
|
|
3268
|
+
timeout: <R$1 extends Type, E extends Type, A extends Type>(effect: IO<R$1, E, A>, ms: number) => IO<R$1, E | TimeoutError, A>;
|
|
3269
|
+
/**
|
|
3270
|
+
* Creates an IO from a generator function.
|
|
3271
|
+
* This enables do-notation style programming.
|
|
3272
|
+
*
|
|
3273
|
+
* @example
|
|
3274
|
+
* ```typescript
|
|
3275
|
+
* const program = IO.gen(function* () {
|
|
3276
|
+
* const a = yield* IO.succeed(1)
|
|
3277
|
+
* const b = yield* IO.succeed(2)
|
|
3278
|
+
* return a + b
|
|
3279
|
+
* })
|
|
3280
|
+
* ```
|
|
3281
|
+
*/
|
|
3282
|
+
gen: <A extends Type>(f: () => Generator<IO<any, any, any>, A, any>) => IO<never, any, A>;
|
|
3283
|
+
/**
|
|
3284
|
+
* Starts a Do-builder context for binding values.
|
|
3285
|
+
* This enables do-notation style programming without generators.
|
|
3286
|
+
*
|
|
3287
|
+
* @example
|
|
3288
|
+
* ```typescript
|
|
3289
|
+
* const program = IO.Do
|
|
3290
|
+
* .bind("user", () => getUser("123"))
|
|
3291
|
+
* .bind("posts", ({ user }) => getPosts(user.id))
|
|
3292
|
+
* .let("count", ({ posts }) => posts.length)
|
|
3293
|
+
* .map(({ user, posts, count }) => ({ user, posts, count }))
|
|
3294
|
+
* ```
|
|
3295
|
+
*/
|
|
3296
|
+
readonly Do: DoBuilder<never, never, Record<never, never>>;
|
|
3297
|
+
};
|
|
3298
|
+
/**
|
|
3299
|
+
* An IO with no requirements and no error
|
|
3300
|
+
*/
|
|
3301
|
+
type UIO<A extends Type> = IO<never, never, A>;
|
|
3302
|
+
/**
|
|
3303
|
+
* An IO with no requirements
|
|
3304
|
+
*/
|
|
3305
|
+
type Task<E extends Type, A extends Type> = IO<never, E, A>;
|
|
3306
|
+
/**
|
|
3307
|
+
* An IO with no error
|
|
3308
|
+
*/
|
|
3309
|
+
type RIO<R$1 extends Type, A extends Type> = IO<R$1, never, A>;
|
|
3310
|
+
//#endregion
|
|
3311
|
+
//#region src/io/TestClock.d.ts
|
|
3312
|
+
/**
|
|
3313
|
+
* TestClock interface for controlling time in tests
|
|
3314
|
+
*/
|
|
3315
|
+
interface TestClock {
|
|
3316
|
+
/**
|
|
3317
|
+
* Current virtual time in milliseconds
|
|
3318
|
+
*/
|
|
3319
|
+
readonly currentTime: number;
|
|
3320
|
+
/**
|
|
3321
|
+
* Advances the clock by the specified duration.
|
|
3322
|
+
* All scheduled tasks with a time <= new current time will be executed.
|
|
3323
|
+
* @param ms - Milliseconds to advance
|
|
3324
|
+
*/
|
|
3325
|
+
advance(ms: number): Promise<void>;
|
|
3326
|
+
/**
|
|
3327
|
+
* Sets the clock to a specific time.
|
|
3328
|
+
* @param ms - The absolute time to set
|
|
3329
|
+
*/
|
|
3330
|
+
setTime(ms: number): Promise<void>;
|
|
3331
|
+
/**
|
|
3332
|
+
* Runs all pending tasks immediately.
|
|
3333
|
+
*/
|
|
3334
|
+
runAll(): Promise<void>;
|
|
3335
|
+
/**
|
|
3336
|
+
* Gets the number of pending scheduled tasks.
|
|
3337
|
+
*/
|
|
3338
|
+
readonly pendingCount: number;
|
|
3339
|
+
/**
|
|
3340
|
+
* Sleeps for the specified duration using virtual time.
|
|
3341
|
+
* @param ms - Milliseconds to sleep
|
|
3342
|
+
*/
|
|
3343
|
+
sleep(ms: number): Promise<void>;
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Service tag for TestClock
|
|
3347
|
+
*/
|
|
3348
|
+
declare const TestClockTag: Tag<TestClock>;
|
|
3349
|
+
/**
|
|
3350
|
+
* TestClock companion object with factory methods
|
|
3351
|
+
*/
|
|
3352
|
+
declare const TestClock: {
|
|
3353
|
+
/**
|
|
3354
|
+
* Creates a new TestClock instance
|
|
3355
|
+
*/
|
|
3356
|
+
make: () => TestClock;
|
|
3357
|
+
/**
|
|
3358
|
+
* Tag for dependency injection
|
|
3359
|
+
*/
|
|
3360
|
+
tag: Tag<TestClock>;
|
|
3361
|
+
/**
|
|
3362
|
+
* Creates a test environment with a TestClock and runs the test function.
|
|
3363
|
+
*
|
|
3364
|
+
* @example
|
|
3365
|
+
* ```typescript
|
|
3366
|
+
* await TestClock.test(async (clock) => {
|
|
3367
|
+
* const result = await IO.sleep(100).map(() => "done")
|
|
3368
|
+
* .pipe(clock.runWithClock)
|
|
3369
|
+
* expect(result).toBe("done")
|
|
3370
|
+
* })
|
|
3371
|
+
* ```
|
|
3372
|
+
*/
|
|
3373
|
+
test: <A>(f: (clock: TestClock) => Promise<A>) => Promise<A>;
|
|
3374
|
+
/**
|
|
3375
|
+
* Creates an IO that accesses the TestClock from the environment.
|
|
3376
|
+
*/
|
|
3377
|
+
get: IO<TestClock, never, TestClock>;
|
|
3378
|
+
/**
|
|
3379
|
+
* Creates an IO that advances the TestClock.
|
|
3380
|
+
*/
|
|
3381
|
+
advance: (ms: number) => IO<TestClock, never, void>;
|
|
3382
|
+
/**
|
|
3383
|
+
* Creates an IO that sets the TestClock time.
|
|
3384
|
+
*/
|
|
3385
|
+
setTime: (ms: number) => IO<TestClock, never, void>;
|
|
3386
|
+
/**
|
|
3387
|
+
* Creates an IO that runs all pending tasks.
|
|
3388
|
+
*/
|
|
3389
|
+
runAll: IO<TestClock, unknown, void>;
|
|
3390
|
+
/**
|
|
3391
|
+
* Creates a context with a TestClock for testing.
|
|
3392
|
+
*/
|
|
3393
|
+
context: () => {
|
|
3394
|
+
clock: TestClock;
|
|
3395
|
+
context: ReturnType<typeof Context.make<TestClock>>;
|
|
3396
|
+
};
|
|
3397
|
+
};
|
|
3398
|
+
/**
|
|
3399
|
+
* TestContext provides a complete test environment with mocked services.
|
|
3400
|
+
*/
|
|
3401
|
+
interface TestContext<R$1 extends Type> {
|
|
3402
|
+
/**
|
|
3403
|
+
* The context containing test services
|
|
3404
|
+
*/
|
|
3405
|
+
readonly context: ReturnType<typeof Context.empty<R$1>>;
|
|
3406
|
+
/**
|
|
3407
|
+
* The TestClock for controlling time
|
|
3408
|
+
*/
|
|
3409
|
+
readonly clock: TestClock;
|
|
3410
|
+
/**
|
|
3411
|
+
* Adds a service to the test context
|
|
3412
|
+
*/
|
|
3413
|
+
withService<S extends Type>(tag: Tag<S>, service: S): TestContext<R$1 & S>;
|
|
3414
|
+
/**
|
|
3415
|
+
* Provides the test context to an IO effect and runs it
|
|
3416
|
+
*/
|
|
3417
|
+
run<E extends Type, A extends Type>(effect: IO<R$1, E, A>): Promise<A>;
|
|
3418
|
+
}
|
|
3419
|
+
/**
|
|
3420
|
+
* Creates a TestContext for testing IO effects with mocked services.
|
|
3421
|
+
*
|
|
3422
|
+
* @example
|
|
3423
|
+
* ```typescript
|
|
3424
|
+
* const ctx = TestContext.make()
|
|
3425
|
+
* .withService(Logger, mockLogger)
|
|
3426
|
+
* .withService(Database, mockDb)
|
|
3427
|
+
*
|
|
3428
|
+
* const result = await ctx.run(myProgram)
|
|
3429
|
+
* ```
|
|
3430
|
+
*/
|
|
3431
|
+
declare const TestContext: {
|
|
3432
|
+
/**
|
|
3433
|
+
* Creates a new empty TestContext
|
|
3434
|
+
*/
|
|
3435
|
+
make: <R$1 extends Type = never>() => TestContext<R$1>;
|
|
3436
|
+
/**
|
|
3437
|
+
* Creates a TestContext with a TestClock already provided
|
|
3438
|
+
*/
|
|
3439
|
+
withClock: () => TestContext<TestClock>;
|
|
2197
3440
|
};
|
|
2198
3441
|
//#endregion
|
|
2199
3442
|
//#region src/lazy/Lazy.d.ts
|
|
@@ -2207,7 +3450,7 @@ declare const Identity: (<T$1>(value: T$1) => Identity<T$1>) & {
|
|
|
2207
3450
|
* It provides memoization and safe evaluation with integration to Option, Either, and Try.
|
|
2208
3451
|
* @typeParam T - The type of the value to be computed
|
|
2209
3452
|
*/
|
|
2210
|
-
interface Lazy<T
|
|
3453
|
+
interface Lazy<T extends Type> extends FunctypeBase<T, "Lazy">, Extractable<T>, Pipe<T> {
|
|
2211
3454
|
/** Tag identifying this as a Lazy type */
|
|
2212
3455
|
readonly _tag: "Lazy";
|
|
2213
3456
|
/** Whether the computation has been evaluated */
|
|
@@ -2217,138 +3460,138 @@ interface Lazy<T$1 extends Type> extends FunctypeBase<T$1, "Lazy">, Extractable<
|
|
|
2217
3460
|
* @param defaultValue - The value to return if computation fails
|
|
2218
3461
|
* @returns The computed value or defaultValue
|
|
2219
3462
|
*/
|
|
2220
|
-
orElse(defaultValue: T
|
|
3463
|
+
orElse(defaultValue: T): T;
|
|
2221
3464
|
/**
|
|
2222
3465
|
* Returns the computed value or null if computation fails
|
|
2223
3466
|
* @returns The computed value or null
|
|
2224
3467
|
*/
|
|
2225
|
-
orNull(): T
|
|
3468
|
+
orNull(): T | null;
|
|
2226
3469
|
/**
|
|
2227
3470
|
* Returns the computed value or throws an error if computation fails
|
|
2228
3471
|
* @param error - Optional custom error to throw. If not provided, throws the computation error or a default error
|
|
2229
3472
|
* @returns The computed value
|
|
2230
3473
|
* @throws The specified error, computation error, or a default error
|
|
2231
3474
|
*/
|
|
2232
|
-
orThrow(error?: Error): T
|
|
3475
|
+
orThrow(error?: Error): T;
|
|
2233
3476
|
/**
|
|
2234
3477
|
* Returns this Lazy if computation succeeds, otherwise returns the alternative Lazy
|
|
2235
3478
|
* @param alternative - The alternative Lazy to use if computation fails
|
|
2236
3479
|
* @returns This Lazy or the alternative
|
|
2237
3480
|
*/
|
|
2238
|
-
or(alternative: Lazy<T
|
|
3481
|
+
or(alternative: Lazy<T>): Lazy<T>;
|
|
2239
3482
|
/**
|
|
2240
3483
|
* Maps the value inside the Lazy using the provided function
|
|
2241
3484
|
* @param f - The mapping function
|
|
2242
3485
|
* @returns A new Lazy containing the mapped value
|
|
2243
3486
|
*/
|
|
2244
|
-
map<U extends Type>(f: (value: T
|
|
3487
|
+
map<U extends Type>(f: (value: T) => U): Lazy<U>;
|
|
2245
3488
|
/**
|
|
2246
3489
|
* Applies a wrapped function to a wrapped value (Applicative pattern)
|
|
2247
3490
|
* @param ff - A Lazy containing a function from T to U
|
|
2248
3491
|
* @returns A new Lazy containing the result
|
|
2249
3492
|
*/
|
|
2250
|
-
ap<U extends Type>(ff: Lazy<(value: T
|
|
3493
|
+
ap<U extends Type>(ff: Lazy<(value: T) => U>): Lazy<U>;
|
|
2251
3494
|
/**
|
|
2252
3495
|
* Maps the value inside the Lazy using an async function
|
|
2253
3496
|
* @param f - The async mapping function
|
|
2254
3497
|
* @returns A Promise of a new Lazy containing the mapped value
|
|
2255
3498
|
*/
|
|
2256
|
-
mapAsync<U extends Type>(f: (value: T
|
|
3499
|
+
mapAsync<U extends Type>(f: (value: T) => Promise<U>): Promise<Lazy<U>>;
|
|
2257
3500
|
/**
|
|
2258
3501
|
* Maps the value using a function that returns a Lazy
|
|
2259
3502
|
* @param f - The mapping function returning a Lazy
|
|
2260
3503
|
* @returns A new Lazy containing the flattened result
|
|
2261
3504
|
*/
|
|
2262
|
-
flatMap<U extends Type>(f: (value: T
|
|
3505
|
+
flatMap<U extends Type>(f: (value: T) => Lazy<U>): Lazy<U>;
|
|
2263
3506
|
/**
|
|
2264
3507
|
* Maps the value using an async function that returns a Lazy
|
|
2265
3508
|
* @param f - The async mapping function returning a Lazy
|
|
2266
3509
|
* @returns A Promise of a new Lazy containing the flattened result
|
|
2267
3510
|
*/
|
|
2268
|
-
flatMapAsync<U extends Type>(f: (value: T
|
|
3511
|
+
flatMapAsync<U extends Type>(f: (value: T) => Promise<Lazy<U>>): Promise<Lazy<U>>;
|
|
2269
3512
|
/**
|
|
2270
3513
|
* Returns a Lazy that filters the value based on a predicate
|
|
2271
3514
|
* @param predicate - The predicate function
|
|
2272
3515
|
* @returns A Lazy containing an Option of the value
|
|
2273
3516
|
*/
|
|
2274
|
-
filter(predicate: (value: T
|
|
3517
|
+
filter(predicate: (value: T) => boolean): Lazy<Option<T>>;
|
|
2275
3518
|
/**
|
|
2276
3519
|
* Recovers from a failed computation by providing an alternative value
|
|
2277
3520
|
* @param f - Function that takes the error and returns a recovery value
|
|
2278
3521
|
* @returns A new Lazy that will use the recovery function if computation fails
|
|
2279
3522
|
*/
|
|
2280
|
-
recover(f: (error: unknown) => T
|
|
3523
|
+
recover(f: (error: unknown) => T): Lazy<T>;
|
|
2281
3524
|
/**
|
|
2282
3525
|
* Recovers from a failed computation by providing an alternative Lazy
|
|
2283
3526
|
* @param f - Function that takes the error and returns a recovery Lazy
|
|
2284
3527
|
* @returns A new Lazy that will use the recovery Lazy if computation fails
|
|
2285
3528
|
*/
|
|
2286
|
-
recoverWith(f: (error: unknown) => Lazy<T
|
|
3529
|
+
recoverWith(f: (error: unknown) => Lazy<T>): Lazy<T>;
|
|
2287
3530
|
/**
|
|
2288
3531
|
* Evaluates the computation and returns it as an Option
|
|
2289
3532
|
* @returns Some containing the value if successful, None if computation fails
|
|
2290
3533
|
*/
|
|
2291
|
-
toOption(): Option<T
|
|
3534
|
+
toOption(): Option<T>;
|
|
2292
3535
|
/**
|
|
2293
3536
|
* Evaluates the computation and returns it as an Either
|
|
2294
3537
|
* @returns Right containing the value if successful, Left containing the error if computation fails
|
|
2295
3538
|
*/
|
|
2296
|
-
toEither(): Either<unknown, T
|
|
3539
|
+
toEither(): Either<unknown, T>;
|
|
2297
3540
|
/**
|
|
2298
3541
|
* Evaluates the computation and returns it as an Either with a mapped error
|
|
2299
3542
|
* @param mapError - Function to map the error
|
|
2300
3543
|
* @returns Right containing the value if successful, Left containing the mapped error if computation fails
|
|
2301
3544
|
*/
|
|
2302
|
-
toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T
|
|
3545
|
+
toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>;
|
|
2303
3546
|
/**
|
|
2304
3547
|
* Evaluates the computation and returns it as a Try
|
|
2305
3548
|
* @returns Try containing the result of the computation
|
|
2306
3549
|
*/
|
|
2307
|
-
toTry(): Try<T
|
|
3550
|
+
toTry(): Try<T>;
|
|
2308
3551
|
/**
|
|
2309
3552
|
* Applies an effect function to the value if computation succeeds
|
|
2310
3553
|
* @param f - The effect function
|
|
2311
3554
|
* @returns This Lazy for chaining
|
|
2312
3555
|
*/
|
|
2313
|
-
tap(f: (value: T
|
|
3556
|
+
tap(f: (value: T) => void): Lazy<T>;
|
|
2314
3557
|
/**
|
|
2315
3558
|
* Applies an effect function to the error if computation fails
|
|
2316
3559
|
* @param f - The effect function for errors
|
|
2317
3560
|
* @returns This Lazy for chaining
|
|
2318
3561
|
*/
|
|
2319
|
-
tapError(f: (error: unknown) => void): Lazy<T
|
|
3562
|
+
tapError(f: (error: unknown) => void): Lazy<T>;
|
|
2320
3563
|
/**
|
|
2321
3564
|
* Pattern matching on the Lazy value
|
|
2322
3565
|
* @param f - Function to apply to the computed value
|
|
2323
3566
|
* @returns The result of applying f to the computed value
|
|
2324
3567
|
*/
|
|
2325
|
-
fold<U>(f: (value: T
|
|
3568
|
+
fold<U>(f: (value: T) => U): U;
|
|
2326
3569
|
/**
|
|
2327
3570
|
* Pattern matching with success and failure handlers
|
|
2328
3571
|
* @param onFailure - Function to handle computation failure
|
|
2329
3572
|
* @param onSuccess - Function to handle successful computation
|
|
2330
3573
|
* @returns The result of the appropriate handler
|
|
2331
3574
|
*/
|
|
2332
|
-
foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T
|
|
3575
|
+
foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T) => U): U;
|
|
2333
3576
|
/**
|
|
2334
3577
|
* Left fold operation
|
|
2335
3578
|
* @param z - Initial value
|
|
2336
3579
|
* @returns Function that takes an operator and applies it
|
|
2337
3580
|
*/
|
|
2338
|
-
foldLeft: <B>(z: B) => (op: (b: B, a: T
|
|
3581
|
+
foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B;
|
|
2339
3582
|
/**
|
|
2340
3583
|
* Right fold operation
|
|
2341
3584
|
* @param z - Initial value
|
|
2342
3585
|
* @returns Function that takes an operator and applies it
|
|
2343
3586
|
*/
|
|
2344
|
-
foldRight: <B>(z: B) => (op: (a: T
|
|
3587
|
+
foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B;
|
|
2345
3588
|
/**
|
|
2346
3589
|
* Pattern matching for the Lazy type
|
|
2347
3590
|
* @param patterns - Object with handler for Lazy pattern
|
|
2348
3591
|
* @returns The result of the matched handler
|
|
2349
3592
|
*/
|
|
2350
3593
|
match<R$1>(patterns: {
|
|
2351
|
-
Lazy: (value: T
|
|
3594
|
+
Lazy: (value: T) => R$1;
|
|
2352
3595
|
}): R$1;
|
|
2353
3596
|
/**
|
|
2354
3597
|
* Creates a string representation of the Lazy
|
|
@@ -2362,7 +3605,7 @@ interface Lazy<T$1 extends Type> extends FunctypeBase<T$1, "Lazy">, Extractable<
|
|
|
2362
3605
|
toValue(): {
|
|
2363
3606
|
_tag: "Lazy";
|
|
2364
3607
|
evaluated: boolean;
|
|
2365
|
-
value?: T
|
|
3608
|
+
value?: T;
|
|
2366
3609
|
};
|
|
2367
3610
|
}
|
|
2368
3611
|
/**
|
|
@@ -2404,50 +3647,50 @@ interface Lazy<T$1 extends Type> extends FunctypeBase<T$1, "Lazy">, Extractable<
|
|
|
2404
3647
|
* .map(user => user.name)
|
|
2405
3648
|
* .orThrow() // "Alice"
|
|
2406
3649
|
*/
|
|
2407
|
-
declare const Lazy: (<T
|
|
3650
|
+
declare const Lazy: (<T extends Type>(thunk: () => T) => Lazy<T>) & {
|
|
2408
3651
|
/**
|
|
2409
3652
|
* Creates a Lazy from a thunk (deferred computation)
|
|
2410
3653
|
* @param thunk - Function that computes the value
|
|
2411
3654
|
* @returns A new Lazy instance
|
|
2412
3655
|
*/
|
|
2413
|
-
of: <T
|
|
3656
|
+
of: <T extends Type>(thunk: () => T) => Lazy<T>;
|
|
2414
3657
|
/**
|
|
2415
3658
|
* Creates a Lazy from an immediate value
|
|
2416
3659
|
* @param value - The value to wrap
|
|
2417
3660
|
* @returns A new Lazy instance that returns the value
|
|
2418
3661
|
*/
|
|
2419
|
-
fromValue: <T
|
|
3662
|
+
fromValue: <T extends Type>(value: T) => Lazy<T>;
|
|
2420
3663
|
/**
|
|
2421
3664
|
* Creates a Lazy from an Option
|
|
2422
3665
|
* @param option - The Option to convert
|
|
2423
3666
|
* @param defaultThunk - Thunk to compute default value if Option is None
|
|
2424
3667
|
* @returns A new Lazy instance
|
|
2425
3668
|
*/
|
|
2426
|
-
fromOption: <T
|
|
3669
|
+
fromOption: <T extends Type>(option: Option<T>, defaultThunk: () => T) => Lazy<T>;
|
|
2427
3670
|
/**
|
|
2428
3671
|
* Creates a Lazy from a Try
|
|
2429
3672
|
* @param tryValue - The Try to convert
|
|
2430
3673
|
* @returns A new Lazy instance
|
|
2431
3674
|
*/
|
|
2432
|
-
fromTry: <T
|
|
3675
|
+
fromTry: <T extends Type>(tryValue: Try<T>) => Lazy<T>;
|
|
2433
3676
|
/**
|
|
2434
3677
|
* Creates a Lazy from an Either
|
|
2435
3678
|
* @param either - The Either to convert
|
|
2436
3679
|
* @returns A new Lazy instance
|
|
2437
3680
|
*/
|
|
2438
|
-
fromEither: <E, T
|
|
3681
|
+
fromEither: <E, T extends Type>(either: Either<E, T>) => Lazy<T>;
|
|
2439
3682
|
/**
|
|
2440
3683
|
* Creates a Lazy that will throw an error since promises need to be awaited first
|
|
2441
3684
|
* @param promise - The Promise to convert
|
|
2442
3685
|
* @returns A new Lazy instance that throws an error
|
|
2443
3686
|
*/
|
|
2444
|
-
fromPromise: <T
|
|
3687
|
+
fromPromise: <T extends Type>(_promise: Promise<T>) => Lazy<T>;
|
|
2445
3688
|
/**
|
|
2446
3689
|
* Creates a failed Lazy that will throw when evaluated
|
|
2447
3690
|
* @param error - The error to throw
|
|
2448
3691
|
* @returns A new Lazy instance that throws the error
|
|
2449
3692
|
*/
|
|
2450
|
-
fail: <T
|
|
3693
|
+
fail: <T extends Type>(error: unknown) => Lazy<T>;
|
|
2451
3694
|
};
|
|
2452
3695
|
//#endregion
|
|
2453
3696
|
//#region src/traversable/Traversable.d.ts
|
|
@@ -2658,42 +3901,42 @@ declare const createCustomSerializer: (data: Record<string, unknown>) => Seriali
|
|
|
2658
3901
|
* @param reconstructor - Function to reconstruct the type from parsed data
|
|
2659
3902
|
* @returns Reconstructed instance
|
|
2660
3903
|
*/
|
|
2661
|
-
declare const fromJSON: <T
|
|
3904
|
+
declare const fromJSON: <T>(json: string, reconstructor: (parsed: {
|
|
2662
3905
|
_tag: string;
|
|
2663
3906
|
[key: string]: unknown;
|
|
2664
|
-
}) => T
|
|
3907
|
+
}) => T) => T;
|
|
2665
3908
|
/**
|
|
2666
3909
|
* Generic deserializer from YAML (simple format)
|
|
2667
3910
|
* @param yaml - The YAML string to parse
|
|
2668
3911
|
* @param reconstructor - Function to reconstruct the type from parsed data
|
|
2669
3912
|
* @returns Reconstructed instance
|
|
2670
3913
|
*/
|
|
2671
|
-
declare const fromYAML: <T
|
|
3914
|
+
declare const fromYAML: <T>(yaml: string, reconstructor: (parsed: {
|
|
2672
3915
|
_tag: string;
|
|
2673
3916
|
[key: string]: unknown;
|
|
2674
|
-
}) => T
|
|
3917
|
+
}) => T) => T;
|
|
2675
3918
|
/**
|
|
2676
3919
|
* Generic deserializer from binary (base64-encoded JSON)
|
|
2677
3920
|
* @param binary - The base64-encoded binary string
|
|
2678
3921
|
* @param reconstructor - Function to reconstruct the type from parsed data
|
|
2679
3922
|
* @returns Reconstructed instance
|
|
2680
3923
|
*/
|
|
2681
|
-
declare const fromBinary: <T
|
|
3924
|
+
declare const fromBinary: <T>(binary: string, reconstructor: (parsed: {
|
|
2682
3925
|
_tag: string;
|
|
2683
3926
|
[key: string]: unknown;
|
|
2684
|
-
}) => T
|
|
3927
|
+
}) => T) => T;
|
|
2685
3928
|
/**
|
|
2686
3929
|
* Creates companion serialization methods for a type
|
|
2687
3930
|
* @param reconstructor - Function to reconstruct the type from parsed data
|
|
2688
3931
|
* @returns Companion methods object with fromJSON, fromYAML, and fromBinary
|
|
2689
3932
|
*/
|
|
2690
|
-
declare const createSerializationCompanion: <T
|
|
3933
|
+
declare const createSerializationCompanion: <T>(reconstructor: (parsed: {
|
|
2691
3934
|
_tag: string;
|
|
2692
3935
|
[key: string]: unknown;
|
|
2693
|
-
}) => T
|
|
2694
|
-
fromJSON: (json: string) => T
|
|
2695
|
-
fromYAML: (yaml: string) => T
|
|
2696
|
-
fromBinary: (binary: string) => T
|
|
3936
|
+
}) => T) => {
|
|
3937
|
+
fromJSON: (json: string) => T;
|
|
3938
|
+
fromYAML: (yaml: string) => T;
|
|
3939
|
+
fromBinary: (binary: string) => T;
|
|
2697
3940
|
};
|
|
2698
3941
|
//#endregion
|
|
2699
3942
|
//#region src/set/Set.d.ts
|
|
@@ -2737,9 +3980,9 @@ declare const Set: (<A>(iterable?: Iterable<A>) => Set<A>) & {
|
|
|
2737
3980
|
/**
|
|
2738
3981
|
* Parameters for creating a Valuable instance
|
|
2739
3982
|
*/
|
|
2740
|
-
type ValuableParams<Tag extends string, T
|
|
2741
|
-
_tag: Tag;
|
|
2742
|
-
impl: T
|
|
3983
|
+
type ValuableParams<Tag$1 extends string, T, V> = {
|
|
3984
|
+
_tag: Tag$1;
|
|
3985
|
+
impl: T;
|
|
2743
3986
|
value: V;
|
|
2744
3987
|
};
|
|
2745
3988
|
/**
|
|
@@ -2748,16 +3991,16 @@ type ValuableParams<Tag extends string, T$1, V> = {
|
|
|
2748
3991
|
* @module Valuable
|
|
2749
3992
|
* @category Utilities
|
|
2750
3993
|
*/
|
|
2751
|
-
declare function Valuable<Tag extends string, V, T
|
|
3994
|
+
declare function Valuable<Tag$1 extends string, V, T = object>(params: ValuableParams<Tag$1, T, V>): T & {
|
|
2752
3995
|
toValue: () => {
|
|
2753
|
-
_tag: Tag;
|
|
3996
|
+
_tag: Tag$1;
|
|
2754
3997
|
value: V;
|
|
2755
3998
|
};
|
|
2756
|
-
_tag: Tag;
|
|
3999
|
+
_tag: Tag$1;
|
|
2757
4000
|
};
|
|
2758
|
-
type Valuable<Tag extends string, V, T
|
|
4001
|
+
type Valuable<Tag$1 extends string, V, T = object> = Typeable<Tag$1, T> & {
|
|
2759
4002
|
toValue: () => {
|
|
2760
|
-
_tag: Tag;
|
|
4003
|
+
_tag: Tag$1;
|
|
2761
4004
|
value: V;
|
|
2762
4005
|
};
|
|
2763
4006
|
};
|
|
@@ -2876,24 +4119,24 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
|
|
|
2876
4119
|
* It's used to handle potentially null or undefined values in a type-safe way.
|
|
2877
4120
|
* @typeParam T - The type of the value contained in the Option
|
|
2878
4121
|
*/
|
|
2879
|
-
interface Option<T
|
|
4122
|
+
interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
2880
4123
|
/** The contained value (undefined for None) */
|
|
2881
|
-
readonly value: T
|
|
4124
|
+
readonly value: T | undefined;
|
|
2882
4125
|
/** Whether this Option contains no value */
|
|
2883
4126
|
isEmpty: boolean;
|
|
2884
4127
|
/**
|
|
2885
4128
|
* Returns true if this Option is a Some (contains a value)
|
|
2886
4129
|
* @returns true if this Option contains a value, false otherwise
|
|
2887
4130
|
*/
|
|
2888
|
-
isSome(): this is Option<T
|
|
2889
|
-
value: T
|
|
4131
|
+
isSome(): this is Option<T> & {
|
|
4132
|
+
value: T;
|
|
2890
4133
|
isEmpty: false;
|
|
2891
4134
|
};
|
|
2892
4135
|
/**
|
|
2893
4136
|
* Returns true if this Option is a None (contains no value)
|
|
2894
4137
|
* @returns true if this Option is empty, false otherwise
|
|
2895
4138
|
*/
|
|
2896
|
-
isNone(): this is Option<T
|
|
4139
|
+
isNone(): this is Option<T> & {
|
|
2897
4140
|
value: undefined;
|
|
2898
4141
|
isEmpty: true;
|
|
2899
4142
|
};
|
|
@@ -2902,102 +4145,102 @@ interface Option<T$1 extends Type> extends Functype<T$1, "Some" | "None">, Promi
|
|
|
2902
4145
|
* @param defaultValue - The value to return if this Option is None
|
|
2903
4146
|
* @returns The contained value or defaultValue
|
|
2904
4147
|
*/
|
|
2905
|
-
orElse(defaultValue: T
|
|
4148
|
+
orElse(defaultValue: T): T;
|
|
2906
4149
|
/**
|
|
2907
4150
|
* Returns the contained value or throws an error if None
|
|
2908
4151
|
* @param error - Optional custom error to throw. If not provided, throws a default error
|
|
2909
4152
|
* @returns The contained value
|
|
2910
4153
|
* @throws The specified error or a default error if the Option is None
|
|
2911
4154
|
*/
|
|
2912
|
-
orThrow(error?: Error): T
|
|
4155
|
+
orThrow(error?: Error): T;
|
|
2913
4156
|
/**
|
|
2914
4157
|
* Returns this Option if it contains a value, otherwise returns the alternative container
|
|
2915
4158
|
* @param alternative - The alternative Option to return if this is None
|
|
2916
4159
|
* @returns This Option or the alternative
|
|
2917
4160
|
*/
|
|
2918
|
-
or(alternative: Option<T
|
|
4161
|
+
or(alternative: Option<T>): Option<T>;
|
|
2919
4162
|
/**
|
|
2920
4163
|
* Returns the contained value or null if None
|
|
2921
4164
|
* @returns The contained value or null
|
|
2922
4165
|
*/
|
|
2923
|
-
orNull(): T
|
|
4166
|
+
orNull(): T | null;
|
|
2924
4167
|
/**
|
|
2925
4168
|
* Returns the contained value or undefined if None
|
|
2926
4169
|
* @returns The contained value or undefined
|
|
2927
4170
|
*/
|
|
2928
|
-
orUndefined(): T
|
|
4171
|
+
orUndefined(): T | undefined;
|
|
2929
4172
|
/**
|
|
2930
4173
|
* Maps the value inside the Option using the provided function
|
|
2931
4174
|
* @param f - The mapping function
|
|
2932
4175
|
* @returns A new Option containing the mapped value, or None if this Option is None
|
|
2933
4176
|
*/
|
|
2934
|
-
map<U extends Type>(f: (value: T
|
|
4177
|
+
map<U extends Type>(f: (value: T) => U): Option<U>;
|
|
2935
4178
|
/**
|
|
2936
4179
|
* Applies a wrapped function to a wrapped value (Applicative pattern)
|
|
2937
4180
|
* @param ff - An Option containing a function from T to U
|
|
2938
4181
|
* @returns A new Option containing the result of applying the function
|
|
2939
4182
|
*/
|
|
2940
|
-
ap<U extends Type>(ff: Option<(value: T
|
|
4183
|
+
ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>;
|
|
2941
4184
|
/**
|
|
2942
4185
|
* Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
|
|
2943
4186
|
* @param predicate - The predicate function to test the value
|
|
2944
4187
|
* @returns This Option or None
|
|
2945
4188
|
*/
|
|
2946
|
-
filter(predicate: (value: T
|
|
4189
|
+
filter(predicate: (value: T) => boolean): Option<T>;
|
|
2947
4190
|
/**
|
|
2948
4191
|
* Maps the value using a function that returns an Option
|
|
2949
4192
|
* @param f - The mapping function returning an Option
|
|
2950
4193
|
* @returns The result of applying f to the contained value, or None if this Option is None
|
|
2951
4194
|
*/
|
|
2952
|
-
flatMap<U extends Type>(f: (value: T
|
|
4195
|
+
flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>;
|
|
2953
4196
|
/**
|
|
2954
4197
|
* Maps the value using an async function that returns an Option
|
|
2955
4198
|
* @param f - The async mapping function returning an Option
|
|
2956
4199
|
* @returns Promise of the result of applying f to the contained value, or None if this Option is None
|
|
2957
4200
|
*/
|
|
2958
|
-
flatMapAsync<U extends Type>(f: (value: T
|
|
4201
|
+
flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>;
|
|
2959
4202
|
/**
|
|
2960
4203
|
* Applies a binary operator to a start value and the contained value
|
|
2961
4204
|
* @param f - The binary operator
|
|
2962
4205
|
* @returns The result of the reduction
|
|
2963
4206
|
*/
|
|
2964
|
-
reduce<U>(f: (acc: U, value: T
|
|
4207
|
+
reduce<U>(f: (acc: U, value: T) => U): U;
|
|
2965
4208
|
/**
|
|
2966
4209
|
* Applies a binary operator to the contained value and a start value
|
|
2967
4210
|
* @param f - The binary operator
|
|
2968
4211
|
* @returns The result of the reduction
|
|
2969
4212
|
*/
|
|
2970
|
-
reduceRight<U>(f: (acc: U, value: T
|
|
4213
|
+
reduceRight<U>(f: (acc: U, value: T) => U): U;
|
|
2971
4214
|
/**
|
|
2972
4215
|
* Pattern matches over the Option, applying onNone if None and onSome if Some
|
|
2973
4216
|
* @param onNone - Function to apply if the Option is None
|
|
2974
4217
|
* @param onSome - Function to apply if the Option has a value
|
|
2975
4218
|
* @returns The result of applying the appropriate function
|
|
2976
4219
|
*/
|
|
2977
|
-
fold<U>(onNone: () => U, onSome: (value: T
|
|
4220
|
+
fold<U>(onNone: () => U, onSome: (value: T) => U): U;
|
|
2978
4221
|
/**
|
|
2979
4222
|
* Left-associative fold using the provided zero value and operation
|
|
2980
4223
|
* @param z - Zero/identity value
|
|
2981
4224
|
* @returns A function that takes an operation to apply
|
|
2982
4225
|
*/
|
|
2983
|
-
foldLeft<B>(z: B): (op: (b: B, a: T
|
|
4226
|
+
foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
|
|
2984
4227
|
/**
|
|
2985
4228
|
* Right-associative fold using the provided zero value and operation
|
|
2986
4229
|
* @param z - Zero/identity value
|
|
2987
4230
|
* @returns A function that takes an operation to apply
|
|
2988
4231
|
*/
|
|
2989
|
-
foldRight<B>(z: B): (op: (a: T
|
|
4232
|
+
foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
|
|
2990
4233
|
/**
|
|
2991
4234
|
* Converts this Option to a List
|
|
2992
4235
|
* @returns A List containing the value if Some, or empty List if None
|
|
2993
4236
|
*/
|
|
2994
|
-
toList(): List<T
|
|
4237
|
+
toList(): List<T>;
|
|
2995
4238
|
/**
|
|
2996
4239
|
* Checks if this Option contains the specified value
|
|
2997
4240
|
* @param value - The value to check for
|
|
2998
4241
|
* @returns true if this Option contains the value, false otherwise
|
|
2999
4242
|
*/
|
|
3000
|
-
contains(value: T
|
|
4243
|
+
contains(value: T): boolean;
|
|
3001
4244
|
/** The number of elements in this Option (0 or 1) */
|
|
3002
4245
|
size: number;
|
|
3003
4246
|
/**
|
|
@@ -3005,7 +4248,7 @@ interface Option<T$1 extends Type> extends Functype<T$1, "Some" | "None">, Promi
|
|
|
3005
4248
|
* @param left - The value to use for Left if this Option is None
|
|
3006
4249
|
* @returns Either.Right with the contained value if Some, or Either.Left with left if None
|
|
3007
4250
|
*/
|
|
3008
|
-
toEither<E>(left: E): Either<E, T
|
|
4251
|
+
toEither<E>(left: E): Either<E, T>;
|
|
3009
4252
|
/**
|
|
3010
4253
|
* Returns a string representation of this Option
|
|
3011
4254
|
* @returns A string representation
|
|
@@ -3017,7 +4260,7 @@ interface Option<T$1 extends Type> extends Functype<T$1, "Some" | "None">, Promi
|
|
|
3017
4260
|
*/
|
|
3018
4261
|
toValue(): {
|
|
3019
4262
|
_tag: "Some" | "None";
|
|
3020
|
-
value: T
|
|
4263
|
+
value: T;
|
|
3021
4264
|
};
|
|
3022
4265
|
/**
|
|
3023
4266
|
* Pattern matches over the Option, applying a handler function based on the variant
|
|
@@ -3025,7 +4268,7 @@ interface Option<T$1 extends Type> extends Functype<T$1, "Some" | "None">, Promi
|
|
|
3025
4268
|
* @returns The result of applying the matching handler function
|
|
3026
4269
|
*/
|
|
3027
4270
|
match<R$1>(patterns: {
|
|
3028
|
-
Some: (value: T
|
|
4271
|
+
Some: (value: T) => R$1;
|
|
3029
4272
|
None: () => R$1;
|
|
3030
4273
|
}): R$1;
|
|
3031
4274
|
}
|
|
@@ -3035,13 +4278,13 @@ interface Option<T$1 extends Type> extends Functype<T$1, "Some" | "None">, Promi
|
|
|
3035
4278
|
* @returns A new Some instance containing the value
|
|
3036
4279
|
* @typeParam T - The type of the value
|
|
3037
4280
|
*/
|
|
3038
|
-
declare const Some: <T
|
|
4281
|
+
declare const Some: <T extends Type>(value: T) => Option<T>;
|
|
3039
4282
|
/**
|
|
3040
4283
|
* Creates a None variant of Option representing absence of a value.
|
|
3041
4284
|
* @returns A new None instance
|
|
3042
4285
|
* @typeParam T - The type that would be contained if this was a Some
|
|
3043
4286
|
*/
|
|
3044
|
-
declare const None: <T
|
|
4287
|
+
declare const None: <T extends Type>() => Option<T>;
|
|
3045
4288
|
/**
|
|
3046
4289
|
* Safely wraps a value that might be null or undefined in an Option.
|
|
3047
4290
|
* Creates Some if the value is defined, None otherwise.
|
|
@@ -3049,28 +4292,28 @@ declare const None: <T$1 extends Type>() => Option<T$1>;
|
|
|
3049
4292
|
* @returns Some(value) if value is defined, None otherwise
|
|
3050
4293
|
* @typeParam T - The type of the value
|
|
3051
4294
|
*/
|
|
3052
|
-
declare const OptionConstructor: <T
|
|
3053
|
-
declare const Option: (<T
|
|
4295
|
+
declare const OptionConstructor: <T extends Type>(value: T | null | undefined) => Option<T>;
|
|
4296
|
+
declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T>) & {
|
|
3054
4297
|
/**
|
|
3055
4298
|
* Creates an Option from any value. Alias for Option function.
|
|
3056
4299
|
* @param value - The value to wrap
|
|
3057
4300
|
* @returns Some(value) if value is defined, None otherwise
|
|
3058
4301
|
* @typeParam T - The type of the value
|
|
3059
4302
|
*/
|
|
3060
|
-
from: <T
|
|
4303
|
+
from: <T>(value: T) => Option<T>;
|
|
3061
4304
|
/**
|
|
3062
4305
|
* Returns a None instance. Alias for None function.
|
|
3063
4306
|
* @returns A None instance
|
|
3064
4307
|
* @typeParam T - The type that would be contained if this was a Some
|
|
3065
4308
|
*/
|
|
3066
|
-
none: <T
|
|
4309
|
+
none: <T>() => Option<T>;
|
|
3067
4310
|
/**
|
|
3068
4311
|
* Type guard to check if an Option is Some
|
|
3069
4312
|
* @param option - The Option to check
|
|
3070
4313
|
* @returns True if Option is Some
|
|
3071
4314
|
*/
|
|
3072
|
-
isSome: <T
|
|
3073
|
-
value: T
|
|
4315
|
+
isSome: <T>(option: Option<T>) => option is Option<T> & {
|
|
4316
|
+
value: T;
|
|
3074
4317
|
isEmpty: false;
|
|
3075
4318
|
};
|
|
3076
4319
|
/**
|
|
@@ -3078,7 +4321,7 @@ declare const Option: (<T$1 extends Type>(value: T$1 | null | undefined) => Opti
|
|
|
3078
4321
|
* @param option - The Option to check
|
|
3079
4322
|
* @returns True if Option is None
|
|
3080
4323
|
*/
|
|
3081
|
-
isNone: <T
|
|
4324
|
+
isNone: <T>(option: Option<T>) => option is Option<T> & {
|
|
3082
4325
|
value: undefined;
|
|
3083
4326
|
isEmpty: true;
|
|
3084
4327
|
};
|
|
@@ -3087,19 +4330,19 @@ declare const Option: (<T$1 extends Type>(value: T$1 | null | undefined) => Opti
|
|
|
3087
4330
|
* @param json - The JSON string
|
|
3088
4331
|
* @returns Option instance
|
|
3089
4332
|
*/
|
|
3090
|
-
fromJSON: <T
|
|
4333
|
+
fromJSON: <T>(json: string) => Option<T>;
|
|
3091
4334
|
/**
|
|
3092
4335
|
* Creates an Option from YAML string
|
|
3093
4336
|
* @param yaml - The YAML string
|
|
3094
4337
|
* @returns Option instance
|
|
3095
4338
|
*/
|
|
3096
|
-
fromYAML: <T
|
|
4339
|
+
fromYAML: <T>(yaml: string) => Option<T>;
|
|
3097
4340
|
/**
|
|
3098
4341
|
* Creates an Option from binary string
|
|
3099
4342
|
* @param binary - The binary string
|
|
3100
4343
|
* @returns Option instance
|
|
3101
4344
|
*/
|
|
3102
|
-
fromBinary: <T
|
|
4345
|
+
fromBinary: <T>(binary: string) => Option<T>;
|
|
3103
4346
|
};
|
|
3104
4347
|
//#endregion
|
|
3105
4348
|
//#region src/list/List.d.ts
|
|
@@ -3114,7 +4357,7 @@ interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<
|
|
|
3114
4357
|
filter(predicate: (a: A) => unknown): List<A>;
|
|
3115
4358
|
filterNot: (p: (a: A) => boolean) => List<A>;
|
|
3116
4359
|
/** @internal */
|
|
3117
|
-
filterType: <T
|
|
4360
|
+
filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>;
|
|
3118
4361
|
remove: (value: A) => List<A>;
|
|
3119
4362
|
removeAt: (index: number) => List<A>;
|
|
3120
4363
|
add: (item: A) => List<A>;
|
|
@@ -3180,8 +4423,8 @@ interface Collection<A> {
|
|
|
3180
4423
|
* }
|
|
3181
4424
|
* ```
|
|
3182
4425
|
*/
|
|
3183
|
-
interface FunctypeBase<A, Tag extends string = string> extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag>, ContainerOps<A> {
|
|
3184
|
-
readonly _tag: Tag;
|
|
4426
|
+
interface FunctypeBase<A, Tag$1 extends string = string> extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag$1>, ContainerOps<A> {
|
|
4427
|
+
readonly _tag: Tag$1;
|
|
3185
4428
|
}
|
|
3186
4429
|
/**
|
|
3187
4430
|
* Interface for single-value containers like Option, Either, Try.
|
|
@@ -3190,9 +4433,9 @@ interface FunctypeBase<A, Tag extends string = string> extends AsyncMonad<A>, Tr
|
|
|
3190
4433
|
* @typeParam A - The type of value contained
|
|
3191
4434
|
* @typeParam Tag - The type tag for pattern matching
|
|
3192
4435
|
*/
|
|
3193
|
-
interface Functype<A, Tag extends string = string> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>, Matchable<A, Tag> {
|
|
4436
|
+
interface Functype<A, Tag$1 extends string = string> extends FunctypeBase<A, Tag$1>, Extractable<A>, Pipe<A>, Matchable<A, Tag$1> {
|
|
3194
4437
|
toValue(): {
|
|
3195
|
-
_tag: Tag;
|
|
4438
|
+
_tag: Tag$1;
|
|
3196
4439
|
value: A;
|
|
3197
4440
|
};
|
|
3198
4441
|
}
|
|
@@ -3203,13 +4446,13 @@ interface Functype<A, Tag extends string = string> extends FunctypeBase<A, Tag>,
|
|
|
3203
4446
|
* @typeParam A - The element type of the collection
|
|
3204
4447
|
* @typeParam Tag - The type tag for pattern matching
|
|
3205
4448
|
*/
|
|
3206
|
-
interface FunctypeCollection<A, Tag extends string = string> extends Omit<FunctypeBase<A, Tag>, "flatMapAsync" | "flatMap">, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag>> {
|
|
4449
|
+
interface FunctypeCollection<A, Tag$1 extends string = string> extends Omit<FunctypeBase<A, Tag$1>, "flatMapAsync" | "flatMap">, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag$1>> {
|
|
3207
4450
|
toValue(): {
|
|
3208
|
-
_tag: Tag;
|
|
4451
|
+
_tag: Tag$1;
|
|
3209
4452
|
value: A[];
|
|
3210
4453
|
};
|
|
3211
|
-
flatMap<B extends Type>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>;
|
|
3212
|
-
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag>>;
|
|
4454
|
+
flatMap<B extends Type>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag$1>;
|
|
4455
|
+
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag$1>>;
|
|
3213
4456
|
}
|
|
3214
4457
|
//#endregion
|
|
3215
4458
|
//#region src/either/Either.d.ts
|
|
@@ -3251,7 +4494,7 @@ interface Either<L extends Type, R$1 extends Type> extends FunctypeBase<R$1, "Le
|
|
|
3251
4494
|
tapLeft: (f: (value: L) => void) => Either<L, R$1>;
|
|
3252
4495
|
mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R$1>;
|
|
3253
4496
|
bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R$1) => R2) => Either<L2, R2>;
|
|
3254
|
-
fold: <T
|
|
4497
|
+
fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R$1) => T) => T;
|
|
3255
4498
|
swap: () => Either<R$1, L>;
|
|
3256
4499
|
/**
|
|
3257
4500
|
* Pipes the value through the provided function based on whether this is a Left or Right
|
|
@@ -3271,10 +4514,10 @@ interface Either<L extends Type, R$1 extends Type> extends FunctypeBase<R$1, "Le
|
|
|
3271
4514
|
* @param patterns - Object with handler functions for Left and Right variants
|
|
3272
4515
|
* @returns The result of applying the matching handler function
|
|
3273
4516
|
*/
|
|
3274
|
-
match<T
|
|
3275
|
-
Left: (value: L) => T
|
|
3276
|
-
Right: (value: R$1) => T
|
|
3277
|
-
}): T
|
|
4517
|
+
match<T>(patterns: {
|
|
4518
|
+
Left: (value: L) => T;
|
|
4519
|
+
Right: (value: R$1) => T;
|
|
4520
|
+
}): T;
|
|
3278
4521
|
/**
|
|
3279
4522
|
* Returns the value and tag for inspection
|
|
3280
4523
|
*/
|
|
@@ -3467,12 +4710,12 @@ type TryLike = {
|
|
|
3467
4710
|
* @param gen - Generator function that yields monads and returns a result
|
|
3468
4711
|
* @returns The same monad type as the first yield
|
|
3469
4712
|
*/
|
|
3470
|
-
declare function Do<T
|
|
4713
|
+
declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
|
|
3471
4714
|
declare function Do<L, R$1>(gen: () => Generator<EitherLike, R$1, unknown>): Either<L, R$1>;
|
|
3472
|
-
declare function Do<T
|
|
3473
|
-
declare function Do<T
|
|
3474
|
-
declare function Do<T
|
|
3475
|
-
declare function Do<T
|
|
4715
|
+
declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
|
|
4716
|
+
declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
|
|
4717
|
+
declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
|
|
4718
|
+
declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
|
|
3476
4719
|
/**
|
|
3477
4720
|
* Executes an async generator-based monadic comprehension
|
|
3478
4721
|
* Returns the same monad type as the first yielded monad
|
|
@@ -3490,18 +4733,18 @@ declare function Do<T$1>(gen: () => Generator<unknown, T$1, unknown>): unknown;
|
|
|
3490
4733
|
* @param gen - Async generator function that yields monads/promises and returns a result
|
|
3491
4734
|
* @returns Promise of the same monad type as first yield
|
|
3492
4735
|
*/
|
|
3493
|
-
declare function DoAsync<T
|
|
4736
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
|
|
3494
4737
|
declare function DoAsync<L, R$1>(gen: () => AsyncGenerator<EitherLike, R$1, unknown>): Promise<Either<L, R$1>>;
|
|
3495
|
-
declare function DoAsync<T
|
|
3496
|
-
declare function DoAsync<T
|
|
3497
|
-
declare function DoAsync<T
|
|
3498
|
-
declare function DoAsync<T
|
|
4738
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
|
|
4739
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
|
|
4740
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
|
|
4741
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
|
|
3499
4742
|
/**
|
|
3500
4743
|
* Helper function to check if a value implements the Doable interface
|
|
3501
4744
|
* @param value - Value to check
|
|
3502
4745
|
* @returns True if the value implements Doable
|
|
3503
4746
|
*/
|
|
3504
|
-
declare function isDoCapable<T
|
|
4747
|
+
declare function isDoCapable<T>(value: unknown): value is Doable<T>;
|
|
3505
4748
|
/**
|
|
3506
4749
|
* Manually unwrap a monad using the Doable interface
|
|
3507
4750
|
* Useful for testing or when you need to unwrap outside of a Do-comprehension
|
|
@@ -3510,7 +4753,7 @@ declare function isDoCapable<T$1>(value: unknown): value is Doable<T$1>;
|
|
|
3510
4753
|
* @returns The unwrapped value
|
|
3511
4754
|
* @throws Error if the monad cannot be unwrapped
|
|
3512
4755
|
*/
|
|
3513
|
-
declare function unwrap<T
|
|
4756
|
+
declare function unwrap<T>(monad: Doable<T>): T;
|
|
3514
4757
|
/**
|
|
3515
4758
|
* Type helper for Do-notation generators.
|
|
3516
4759
|
* Provides better type hints in IDEs.
|
|
@@ -3524,7 +4767,7 @@ declare function unwrap<T$1>(monad: Doable<T$1>): T$1;
|
|
|
3524
4767
|
* })
|
|
3525
4768
|
* ```
|
|
3526
4769
|
*/
|
|
3527
|
-
type DoGenerator<T
|
|
4770
|
+
type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
|
|
3528
4771
|
/**
|
|
3529
4772
|
* Extracts values from monads in Do-notation with type inference.
|
|
3530
4773
|
* The '$' symbol is the universal extraction operator in functional programming.
|
|
@@ -3542,11 +4785,11 @@ type DoGenerator<T$1, TYield = unknown> = Generator<TYield, T$1, unknown>;
|
|
|
3542
4785
|
* @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
|
|
3543
4786
|
* @returns A generator that yields the monad and returns its extracted value
|
|
3544
4787
|
*/
|
|
3545
|
-
declare function $<T
|
|
4788
|
+
declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
|
|
3546
4789
|
declare function $<L, R$1>(monad: Either<L, R$1>): Generator<Either<L, R$1>, R$1, R$1>;
|
|
3547
|
-
declare function $<T
|
|
3548
|
-
declare function $<T
|
|
3549
|
-
declare function $<T
|
|
4790
|
+
declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
|
|
4791
|
+
declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
|
|
4792
|
+
declare function $<T>(monad: Doable<T>): Generator<Doable<T>, T, T>;
|
|
3550
4793
|
declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
|
|
3551
4794
|
type InferYieldType<M> = M extends {
|
|
3552
4795
|
isSome(): boolean;
|
|
@@ -3571,5 +4814,5 @@ interface FailureErrorType extends Error {
|
|
|
3571
4814
|
}
|
|
3572
4815
|
declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
|
|
3573
4816
|
//#endregion
|
|
3574
|
-
export {
|
|
3575
|
-
//# sourceMappingURL=index-
|
|
4817
|
+
export { TestClockTag as $, Task$1 as $t, OptionConstructor as A, PositiveNumber as An, ValidationRule as At, fromBinary as B, Functor as Bn, ErrorWithTaskInfo as Bt, Functype as C, EmailAddress as Cn, OptionKind as Ct, List as D, NonNegativeNumber as Dn, FieldValidation as Dt, Collection as E, NonEmptyString as En, FoldableUtils as Et, Set as F, Try as Fn, TypedError as Ft, MatchableUtils as G, Extractable as Gn, safeStringify as Gt, fromYAML as H, CollectionOps as Hn, createErrorSerializer as Ht, SerializationResult as I, TypeNames as In, TypedErrorContext as It, Map$1 as J, Doable as Jn, CancellationTokenSource as Jt, ESMap as K, isExtractable as Kn, Async as Kt, createCustomSerializer as L, Promisable as Ln, ParseError as Lt, Stack as M, UrlString as Mn, ErrorCode as Mt, Valuable as N, ValidatedBrand as Nn, ErrorMessage as Nt, None as O, PatternString as On, FormValidation as Ot, ValuableParams as P, ValidatedBrandCompanion as Pn, ErrorStatus as Pt, TestClock as Q, TaggedThrowable as Qt, createSerializationCompanion as R, Applicative as Rn, ErrorChainElement as Rt, tryCatchAsync as S, BoundedString as Sn, ListKind as St, FunctypeCollection as T, IntegerNumber as Tn, UniversalContainer as Tt, Ref as U, ContainerOps as Un, formatError as Ut, fromJSON as V, Monad as Vn, TaskErrorInfo as Vt, Matchable as W, LazyList as Wn, formatStackTrace as Wt, Traversable as X, Ok as Xt, SafeTraversable as Y, Err as Yt, Lazy as Z, Sync as Zt, TypeCheckLeft as _, CompanionMethods as _n, TagService as _t, EmptyListError as a, TaskSuccess as an, TimeoutError as at, isRight as b, Companion as bn, HKT as bt, LeftError as c, ErrorContext as cn, LayerError as ct, isDoCapable as d, NAME as dn, Exit as dt, TaskFailure as en, TestContext as et, unwrap as f, Throwable as fn, ExitTag as ft, TestEither as g, Cond as gn, Tag as gt, Right as h, Match as hn, HasService as ht, DoGenerator as i, TaskResult as in, Task as it, Some as j, UUID as jn, Validator as jt, Option as k, PositiveInteger as kn, Validation as kt, LeftErrorType as l, FPromise as ln, LayerInput as lt, Left as m, Base as mn, ContextServices as mt, Do as n, TaskOutcome as nn, InterruptedError as nt, FailureError as o, createCancellationTokenSource as on, UIO as ot, Either as p, ThrowableType as pn, Context as pt, ESMapType as q, DoResult as qn, CancellationToken as qt, DoAsync as r, TaskParams as rn, RIO as rt, FailureErrorType as s, isTaggedThrowable as sn, Layer as st, $ as t, TaskMetadata as tn, IO as tt, NoneError as u, FPromiseCompanion as un, LayerOutput as ut, TypeCheckRight as v, InstanceType as vn, Identity as vt, FunctypeBase as w, ISO8601Date as wn, TryKind as wt, tryCatch as x, BoundedNumber as xn, Kind as xt, isLeft as y, isCompanion as yn, EitherKind as yt, createSerializer as z, AsyncMonad as zn, ErrorFormatterOptions as zt };
|
|
4818
|
+
//# sourceMappingURL=index-BiUAv9kR.d.ts.map
|