@sapphire/result 2.8.0-next.6abc5522 → 2.8.0-next.f3515ea3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +0 -48
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -115
- package/dist/esm/index.d.mts +1 -115
- package/dist/esm/index.mjs +0 -48
- package/dist/esm/index.mjs.map +1 -1
- package/dist/iife/index.global.js +0 -48
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -3,7 +3,6 @@ type If<Value extends boolean, TrueResult, FalseResult> = Value extends true ? T
|
|
|
3
3
|
|
|
4
4
|
declare const ValueProperty$1: unique symbol;
|
|
5
5
|
declare const SuccessProperty: unique symbol;
|
|
6
|
-
declare const UnwrapSafeProperty: unique symbol;
|
|
7
6
|
/**
|
|
8
7
|
* A type used to express computations that can fail, it can be used for returning and propagating errors. This is a
|
|
9
8
|
* type union with the variants `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error
|
|
@@ -442,7 +441,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
442
441
|
* @seealso {@link unwrapOrElse}
|
|
443
442
|
* @seealso {@link unwrapErr}
|
|
444
443
|
* @seealso {@link unwrapRaw}
|
|
445
|
-
* @seealso {@link unwrapSafe}
|
|
446
444
|
*
|
|
447
445
|
* @example
|
|
448
446
|
* ```typescript
|
|
@@ -470,7 +468,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
470
468
|
* @seealso {@link unwrapOr}
|
|
471
469
|
* @seealso {@link unwrapOrElse}
|
|
472
470
|
* @seealso {@link unwrapRaw}
|
|
473
|
-
* @seealso {@link unwrapSafe}
|
|
474
471
|
*
|
|
475
472
|
* @example
|
|
476
473
|
* ```typescript
|
|
@@ -499,7 +496,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
499
496
|
* @seealso {@link unwrapOrElse}
|
|
500
497
|
* @seealso {@link unwrapErr}
|
|
501
498
|
* @seealso {@link unwrapRaw}
|
|
502
|
-
* @seealso {@link unwrapSafe}
|
|
503
499
|
*
|
|
504
500
|
* @param defaultValue The default value.
|
|
505
501
|
*
|
|
@@ -523,7 +519,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
523
519
|
* @seealso {@link unwrapOr}
|
|
524
520
|
* @seealso {@link unwrapErr}
|
|
525
521
|
* @seealso {@link unwrapRaw}
|
|
526
|
-
* @seealso {@link unwrapSafe}
|
|
527
522
|
*
|
|
528
523
|
* @param op The predicate.
|
|
529
524
|
*
|
|
@@ -546,7 +541,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
546
541
|
* @seealso {@link unwrapOr}
|
|
547
542
|
* @seealso {@link unwrapOrElse}
|
|
548
543
|
* @seealso {@link unwrapErr}
|
|
549
|
-
* @seealso {@link unwrapSafe}
|
|
550
544
|
*
|
|
551
545
|
* @example
|
|
552
546
|
* ```typescript
|
|
@@ -564,20 +558,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
564
558
|
* ```
|
|
565
559
|
*/
|
|
566
560
|
unwrapRaw(): If<Success, T, never>;
|
|
567
|
-
/**
|
|
568
|
-
* Returns the contained `Ok` value or yelds the contained `Err` value.
|
|
569
|
-
* Emulates Rust's `?` operator in `safeTry`'s body. See also {@link Result.safeTry}.
|
|
570
|
-
*
|
|
571
|
-
* If used outside of a `safeTry`'s' body, throws the contained error.
|
|
572
|
-
* @seealso {@link unwrap}
|
|
573
|
-
* @seealso {@link unwrapOr}
|
|
574
|
-
* @seealso {@link unwrapErr}
|
|
575
|
-
* @seealso {@link unwrapRaw}
|
|
576
|
-
* @seealso {@link unwrapSafe}
|
|
577
|
-
*
|
|
578
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_safe}
|
|
579
|
-
*/
|
|
580
|
-
unwrapSafe(): Generator<Err<E, T>, T>;
|
|
581
561
|
/**
|
|
582
562
|
* Returns `result` if the result is `Ok`, otherwise returns the `Err` value of itself.
|
|
583
563
|
* @param result The result to check.
|
|
@@ -859,14 +839,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
859
839
|
*/
|
|
860
840
|
[Symbol.iterator](): Generator<T>;
|
|
861
841
|
get [Symbol.toStringTag](): If<Success, 'Ok', 'Err'>;
|
|
862
|
-
/**
|
|
863
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
864
|
-
* Rust's ? operator.
|
|
865
|
-
*
|
|
866
|
-
* @see {@link Result.safeTry}
|
|
867
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.safeTry}
|
|
868
|
-
*/
|
|
869
|
-
get [UnwrapSafeProperty](): Generator<Err<E, T>, T>;
|
|
870
842
|
static ok<T = undefined, E = any>(this: void, value?: T): Ok<T, E>;
|
|
871
843
|
static err<E = undefined, T = any>(this: void, value?: E): Err<E, T>;
|
|
872
844
|
/**
|
|
@@ -947,88 +919,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
947
919
|
* @returns A new {@link Result}.
|
|
948
920
|
*/
|
|
949
921
|
static any<const Entries extends readonly AnyResult[]>(this: void, results: Entries): Result<UnwrapOk<Entries[number]>, UnwrapErrArray<Entries>>;
|
|
950
|
-
/**
|
|
951
|
-
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
952
|
-
* whichever comes first.
|
|
953
|
-
*
|
|
954
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
955
|
-
* Rust's ? operator.
|
|
956
|
-
*
|
|
957
|
-
* @example
|
|
958
|
-
* ```typescript
|
|
959
|
-
* const result = Result.safeTry(function* ({ $ }) {
|
|
960
|
-
* const first = yield* ok(1)[$];
|
|
961
|
-
* const second = yield* ok(1)[$];
|
|
962
|
-
*
|
|
963
|
-
* return ok(first + second);
|
|
964
|
-
* });
|
|
965
|
-
*
|
|
966
|
-
* result.match({
|
|
967
|
-
* ok: (value) => value, // 2
|
|
968
|
-
* err: (error) => {}
|
|
969
|
-
* });
|
|
970
|
-
*```
|
|
971
|
-
*
|
|
972
|
-
* @example
|
|
973
|
-
* ```typescript
|
|
974
|
-
* const resultAsync = Result.safeTry(async function* ({ $async }) {
|
|
975
|
-
* const first = yield* $async(Result.fromAsync(() => Promise.resolve(1)));
|
|
976
|
-
* const second = yield* ok(1)[$];
|
|
977
|
-
*
|
|
978
|
-
* return ok(first + second);
|
|
979
|
-
* });
|
|
980
|
-
*
|
|
981
|
-
* resultAsync.match({
|
|
982
|
-
* ok: (value) => value, // 2
|
|
983
|
-
* err: (error) => {}
|
|
984
|
-
* });
|
|
985
|
-
* ```
|
|
986
|
-
* @param body - What is evaluated. In body, `yield* result[$]` works as
|
|
987
|
-
* Rust's `result?` expression.
|
|
988
|
-
* @returns The first occurence of either an yielded Err or a returned Result.
|
|
989
|
-
*/
|
|
990
|
-
static safeTry<T, E>(body: (options: SafeTryOptions) => Generator<Err<E>, Result<T, E>>): Result<T, E>;
|
|
991
|
-
/**
|
|
992
|
-
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
993
|
-
* whichever comes first.
|
|
994
|
-
*
|
|
995
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
996
|
-
* Rust's ? operator.
|
|
997
|
-
*
|
|
998
|
-
* @example
|
|
999
|
-
* ```typescript
|
|
1000
|
-
* const result = Result.safeTry(function* ({ $ }) {
|
|
1001
|
-
* const first = yield* ok(1)[$];
|
|
1002
|
-
* const second = yield* ok(1)[$];
|
|
1003
|
-
*
|
|
1004
|
-
* return ok(first + second);
|
|
1005
|
-
* });
|
|
1006
|
-
*
|
|
1007
|
-
* result.match({
|
|
1008
|
-
* ok: (value) => value, // 2
|
|
1009
|
-
* err: (error) => {}
|
|
1010
|
-
* });
|
|
1011
|
-
*```
|
|
1012
|
-
*
|
|
1013
|
-
* @example
|
|
1014
|
-
* ```typescript
|
|
1015
|
-
* const resultAsync = Result.safeTry(async function* ({ $async }) {
|
|
1016
|
-
* const first = yield* $async(Result.fromAsync(() => Promise.resolve(1)));
|
|
1017
|
-
* const second = yield* ok(1)[$];
|
|
1018
|
-
*
|
|
1019
|
-
* return ok(first + second);
|
|
1020
|
-
* });
|
|
1021
|
-
*
|
|
1022
|
-
* resultAsync.match({
|
|
1023
|
-
* ok: (value) => value, // 2
|
|
1024
|
-
* err: (error) => {}
|
|
1025
|
-
* });
|
|
1026
|
-
* ```
|
|
1027
|
-
* @param body - What is evaluated. In body, `yield* result[$]` works as
|
|
1028
|
-
* Rust's `result?` expression.
|
|
1029
|
-
* @returns The first occurence of either an yielded Err or a returned Result.
|
|
1030
|
-
*/
|
|
1031
|
-
static safeTry<T, E>(body: (options: SafeTryOptions) => AsyncGenerator<Err<E>, Result<T, E>>): Promise<Result<T, E>>;
|
|
1032
922
|
}
|
|
1033
923
|
declare namespace Result {
|
|
1034
924
|
type Ok<T, E = any> = Result<T, E, true>;
|
|
@@ -1054,10 +944,6 @@ type UnwrapOk<T extends AnyResult> = Result.UnwrapOk<T>;
|
|
|
1054
944
|
type UnwrapErr<T extends AnyResult> = Result.UnwrapErr<T>;
|
|
1055
945
|
type UnwrapOkArray<T extends readonly AnyResult[] | []> = Result.UnwrapOkArray<T>;
|
|
1056
946
|
type UnwrapErrArray<T extends readonly AnyResult[] | []> = Result.UnwrapErrArray<T>;
|
|
1057
|
-
interface SafeTryOptions {
|
|
1058
|
-
$: typeof UnwrapSafeProperty;
|
|
1059
|
-
$async: <T, E>(result: Promise<Result<T, E>>) => AsyncGenerator<Err<E>, T>;
|
|
1060
|
-
}
|
|
1061
947
|
|
|
1062
948
|
declare const ValueProperty: unique symbol;
|
|
1063
949
|
declare const ExistsProperty: unique symbol;
|
|
@@ -1907,4 +1793,4 @@ declare class ResultError<E> extends Error {
|
|
|
1907
1793
|
get name(): string;
|
|
1908
1794
|
}
|
|
1909
1795
|
|
|
1910
|
-
export { type AnyOption, type AnyResult, type Err, type None, type Ok, Option, OptionError, type OptionResolvable, Result, ResultError, type ResultResolvable, type
|
|
1796
|
+
export { type AnyOption, type AnyResult, type Err, type None, type Ok, Option, OptionError, type OptionResolvable, Result, ResultError, type ResultResolvable, type Some, type UnwrapErr, type UnwrapErrArray, type UnwrapOk, type UnwrapOkArray, type UnwrapSome, type UnwrapSomeArray, err, none, ok, some };
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -3,7 +3,6 @@ type If<Value extends boolean, TrueResult, FalseResult> = Value extends true ? T
|
|
|
3
3
|
|
|
4
4
|
declare const ValueProperty$1: unique symbol;
|
|
5
5
|
declare const SuccessProperty: unique symbol;
|
|
6
|
-
declare const UnwrapSafeProperty: unique symbol;
|
|
7
6
|
/**
|
|
8
7
|
* A type used to express computations that can fail, it can be used for returning and propagating errors. This is a
|
|
9
8
|
* type union with the variants `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error
|
|
@@ -442,7 +441,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
442
441
|
* @seealso {@link unwrapOrElse}
|
|
443
442
|
* @seealso {@link unwrapErr}
|
|
444
443
|
* @seealso {@link unwrapRaw}
|
|
445
|
-
* @seealso {@link unwrapSafe}
|
|
446
444
|
*
|
|
447
445
|
* @example
|
|
448
446
|
* ```typescript
|
|
@@ -470,7 +468,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
470
468
|
* @seealso {@link unwrapOr}
|
|
471
469
|
* @seealso {@link unwrapOrElse}
|
|
472
470
|
* @seealso {@link unwrapRaw}
|
|
473
|
-
* @seealso {@link unwrapSafe}
|
|
474
471
|
*
|
|
475
472
|
* @example
|
|
476
473
|
* ```typescript
|
|
@@ -499,7 +496,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
499
496
|
* @seealso {@link unwrapOrElse}
|
|
500
497
|
* @seealso {@link unwrapErr}
|
|
501
498
|
* @seealso {@link unwrapRaw}
|
|
502
|
-
* @seealso {@link unwrapSafe}
|
|
503
499
|
*
|
|
504
500
|
* @param defaultValue The default value.
|
|
505
501
|
*
|
|
@@ -523,7 +519,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
523
519
|
* @seealso {@link unwrapOr}
|
|
524
520
|
* @seealso {@link unwrapErr}
|
|
525
521
|
* @seealso {@link unwrapRaw}
|
|
526
|
-
* @seealso {@link unwrapSafe}
|
|
527
522
|
*
|
|
528
523
|
* @param op The predicate.
|
|
529
524
|
*
|
|
@@ -546,7 +541,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
546
541
|
* @seealso {@link unwrapOr}
|
|
547
542
|
* @seealso {@link unwrapOrElse}
|
|
548
543
|
* @seealso {@link unwrapErr}
|
|
549
|
-
* @seealso {@link unwrapSafe}
|
|
550
544
|
*
|
|
551
545
|
* @example
|
|
552
546
|
* ```typescript
|
|
@@ -564,20 +558,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
564
558
|
* ```
|
|
565
559
|
*/
|
|
566
560
|
unwrapRaw(): If<Success, T, never>;
|
|
567
|
-
/**
|
|
568
|
-
* Returns the contained `Ok` value or yelds the contained `Err` value.
|
|
569
|
-
* Emulates Rust's `?` operator in `safeTry`'s body. See also {@link Result.safeTry}.
|
|
570
|
-
*
|
|
571
|
-
* If used outside of a `safeTry`'s' body, throws the contained error.
|
|
572
|
-
* @seealso {@link unwrap}
|
|
573
|
-
* @seealso {@link unwrapOr}
|
|
574
|
-
* @seealso {@link unwrapErr}
|
|
575
|
-
* @seealso {@link unwrapRaw}
|
|
576
|
-
* @seealso {@link unwrapSafe}
|
|
577
|
-
*
|
|
578
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_safe}
|
|
579
|
-
*/
|
|
580
|
-
unwrapSafe(): Generator<Err<E, T>, T>;
|
|
581
561
|
/**
|
|
582
562
|
* Returns `result` if the result is `Ok`, otherwise returns the `Err` value of itself.
|
|
583
563
|
* @param result The result to check.
|
|
@@ -859,14 +839,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
859
839
|
*/
|
|
860
840
|
[Symbol.iterator](): Generator<T>;
|
|
861
841
|
get [Symbol.toStringTag](): If<Success, 'Ok', 'Err'>;
|
|
862
|
-
/**
|
|
863
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
864
|
-
* Rust's ? operator.
|
|
865
|
-
*
|
|
866
|
-
* @see {@link Result.safeTry}
|
|
867
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.safeTry}
|
|
868
|
-
*/
|
|
869
|
-
get [UnwrapSafeProperty](): Generator<Err<E, T>, T>;
|
|
870
842
|
static ok<T = undefined, E = any>(this: void, value?: T): Ok<T, E>;
|
|
871
843
|
static err<E = undefined, T = any>(this: void, value?: E): Err<E, T>;
|
|
872
844
|
/**
|
|
@@ -947,88 +919,6 @@ declare class Result<T, E, const Success extends boolean = boolean> {
|
|
|
947
919
|
* @returns A new {@link Result}.
|
|
948
920
|
*/
|
|
949
921
|
static any<const Entries extends readonly AnyResult[]>(this: void, results: Entries): Result<UnwrapOk<Entries[number]>, UnwrapErrArray<Entries>>;
|
|
950
|
-
/**
|
|
951
|
-
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
952
|
-
* whichever comes first.
|
|
953
|
-
*
|
|
954
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
955
|
-
* Rust's ? operator.
|
|
956
|
-
*
|
|
957
|
-
* @example
|
|
958
|
-
* ```typescript
|
|
959
|
-
* const result = Result.safeTry(function* ({ $ }) {
|
|
960
|
-
* const first = yield* ok(1)[$];
|
|
961
|
-
* const second = yield* ok(1)[$];
|
|
962
|
-
*
|
|
963
|
-
* return ok(first + second);
|
|
964
|
-
* });
|
|
965
|
-
*
|
|
966
|
-
* result.match({
|
|
967
|
-
* ok: (value) => value, // 2
|
|
968
|
-
* err: (error) => {}
|
|
969
|
-
* });
|
|
970
|
-
*```
|
|
971
|
-
*
|
|
972
|
-
* @example
|
|
973
|
-
* ```typescript
|
|
974
|
-
* const resultAsync = Result.safeTry(async function* ({ $async }) {
|
|
975
|
-
* const first = yield* $async(Result.fromAsync(() => Promise.resolve(1)));
|
|
976
|
-
* const second = yield* ok(1)[$];
|
|
977
|
-
*
|
|
978
|
-
* return ok(first + second);
|
|
979
|
-
* });
|
|
980
|
-
*
|
|
981
|
-
* resultAsync.match({
|
|
982
|
-
* ok: (value) => value, // 2
|
|
983
|
-
* err: (error) => {}
|
|
984
|
-
* });
|
|
985
|
-
* ```
|
|
986
|
-
* @param body - What is evaluated. In body, `yield* result[$]` works as
|
|
987
|
-
* Rust's `result?` expression.
|
|
988
|
-
* @returns The first occurence of either an yielded Err or a returned Result.
|
|
989
|
-
*/
|
|
990
|
-
static safeTry<T, E>(body: (options: SafeTryOptions) => Generator<Err<E>, Result<T, E>>): Result<T, E>;
|
|
991
|
-
/**
|
|
992
|
-
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
993
|
-
* whichever comes first.
|
|
994
|
-
*
|
|
995
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
996
|
-
* Rust's ? operator.
|
|
997
|
-
*
|
|
998
|
-
* @example
|
|
999
|
-
* ```typescript
|
|
1000
|
-
* const result = Result.safeTry(function* ({ $ }) {
|
|
1001
|
-
* const first = yield* ok(1)[$];
|
|
1002
|
-
* const second = yield* ok(1)[$];
|
|
1003
|
-
*
|
|
1004
|
-
* return ok(first + second);
|
|
1005
|
-
* });
|
|
1006
|
-
*
|
|
1007
|
-
* result.match({
|
|
1008
|
-
* ok: (value) => value, // 2
|
|
1009
|
-
* err: (error) => {}
|
|
1010
|
-
* });
|
|
1011
|
-
*```
|
|
1012
|
-
*
|
|
1013
|
-
* @example
|
|
1014
|
-
* ```typescript
|
|
1015
|
-
* const resultAsync = Result.safeTry(async function* ({ $async }) {
|
|
1016
|
-
* const first = yield* $async(Result.fromAsync(() => Promise.resolve(1)));
|
|
1017
|
-
* const second = yield* ok(1)[$];
|
|
1018
|
-
*
|
|
1019
|
-
* return ok(first + second);
|
|
1020
|
-
* });
|
|
1021
|
-
*
|
|
1022
|
-
* resultAsync.match({
|
|
1023
|
-
* ok: (value) => value, // 2
|
|
1024
|
-
* err: (error) => {}
|
|
1025
|
-
* });
|
|
1026
|
-
* ```
|
|
1027
|
-
* @param body - What is evaluated. In body, `yield* result[$]` works as
|
|
1028
|
-
* Rust's `result?` expression.
|
|
1029
|
-
* @returns The first occurence of either an yielded Err or a returned Result.
|
|
1030
|
-
*/
|
|
1031
|
-
static safeTry<T, E>(body: (options: SafeTryOptions) => AsyncGenerator<Err<E>, Result<T, E>>): Promise<Result<T, E>>;
|
|
1032
922
|
}
|
|
1033
923
|
declare namespace Result {
|
|
1034
924
|
type Ok<T, E = any> = Result<T, E, true>;
|
|
@@ -1054,10 +944,6 @@ type UnwrapOk<T extends AnyResult> = Result.UnwrapOk<T>;
|
|
|
1054
944
|
type UnwrapErr<T extends AnyResult> = Result.UnwrapErr<T>;
|
|
1055
945
|
type UnwrapOkArray<T extends readonly AnyResult[] | []> = Result.UnwrapOkArray<T>;
|
|
1056
946
|
type UnwrapErrArray<T extends readonly AnyResult[] | []> = Result.UnwrapErrArray<T>;
|
|
1057
|
-
interface SafeTryOptions {
|
|
1058
|
-
$: typeof UnwrapSafeProperty;
|
|
1059
|
-
$async: <T, E>(result: Promise<Result<T, E>>) => AsyncGenerator<Err<E>, T>;
|
|
1060
|
-
}
|
|
1061
947
|
|
|
1062
948
|
declare const ValueProperty: unique symbol;
|
|
1063
949
|
declare const ExistsProperty: unique symbol;
|
|
@@ -1907,4 +1793,4 @@ declare class ResultError<E> extends Error {
|
|
|
1907
1793
|
get name(): string;
|
|
1908
1794
|
}
|
|
1909
1795
|
|
|
1910
|
-
export { type AnyOption, type AnyResult, type Err, type None, type Ok, Option, OptionError, type OptionResolvable, Result, ResultError, type ResultResolvable, type
|
|
1796
|
+
export { type AnyOption, type AnyResult, type Err, type None, type Ok, Option, OptionError, type OptionResolvable, Result, ResultError, type ResultResolvable, type Some, type UnwrapErr, type UnwrapErrArray, type UnwrapOk, type UnwrapOkArray, type UnwrapSome, type UnwrapSomeArray, err, none, ok, some };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -39,7 +39,6 @@ var ResultError = _ResultError;
|
|
|
39
39
|
// src/lib/Result.ts
|
|
40
40
|
var ValueProperty = Symbol.for("@sapphire/result:Result.value");
|
|
41
41
|
var SuccessProperty = Symbol.for("@sapphire/result:Result.success");
|
|
42
|
-
var UnwrapSafeProperty = Symbol.for("@sapphire/result:Result.safeUnwrap");
|
|
43
42
|
var _a, _b;
|
|
44
43
|
var _Result = class _Result {
|
|
45
44
|
constructor(value, success) {
|
|
@@ -466,7 +465,6 @@ var _Result = class _Result {
|
|
|
466
465
|
* @seealso {@link unwrapOrElse}
|
|
467
466
|
* @seealso {@link unwrapErr}
|
|
468
467
|
* @seealso {@link unwrapRaw}
|
|
469
|
-
* @seealso {@link unwrapSafe}
|
|
470
468
|
*
|
|
471
469
|
* @example
|
|
472
470
|
* ```typescript
|
|
@@ -497,7 +495,6 @@ var _Result = class _Result {
|
|
|
497
495
|
* @seealso {@link unwrapOr}
|
|
498
496
|
* @seealso {@link unwrapOrElse}
|
|
499
497
|
* @seealso {@link unwrapRaw}
|
|
500
|
-
* @seealso {@link unwrapSafe}
|
|
501
498
|
*
|
|
502
499
|
* @example
|
|
503
500
|
* ```typescript
|
|
@@ -529,7 +526,6 @@ var _Result = class _Result {
|
|
|
529
526
|
* @seealso {@link unwrapOrElse}
|
|
530
527
|
* @seealso {@link unwrapErr}
|
|
531
528
|
* @seealso {@link unwrapRaw}
|
|
532
|
-
* @seealso {@link unwrapSafe}
|
|
533
529
|
*
|
|
534
530
|
* @param defaultValue The default value.
|
|
535
531
|
*
|
|
@@ -555,7 +551,6 @@ var _Result = class _Result {
|
|
|
555
551
|
* @seealso {@link unwrapOr}
|
|
556
552
|
* @seealso {@link unwrapErr}
|
|
557
553
|
* @seealso {@link unwrapRaw}
|
|
558
|
-
* @seealso {@link unwrapSafe}
|
|
559
554
|
*
|
|
560
555
|
* @param op The predicate.
|
|
561
556
|
*
|
|
@@ -580,7 +575,6 @@ var _Result = class _Result {
|
|
|
580
575
|
* @seealso {@link unwrapOr}
|
|
581
576
|
* @seealso {@link unwrapOrElse}
|
|
582
577
|
* @seealso {@link unwrapErr}
|
|
583
|
-
* @seealso {@link unwrapSafe}
|
|
584
578
|
*
|
|
585
579
|
* @example
|
|
586
580
|
* ```typescript
|
|
@@ -601,26 +595,6 @@ var _Result = class _Result {
|
|
|
601
595
|
if (this.isErr()) throw this[ValueProperty];
|
|
602
596
|
return this[ValueProperty];
|
|
603
597
|
}
|
|
604
|
-
/**
|
|
605
|
-
* Returns the contained `Ok` value or yelds the contained `Err` value.
|
|
606
|
-
* Emulates Rust's `?` operator in `safeTry`'s body. See also {@link Result.safeTry}.
|
|
607
|
-
*
|
|
608
|
-
* If used outside of a `safeTry`'s' body, throws the contained error.
|
|
609
|
-
* @seealso {@link unwrap}
|
|
610
|
-
* @seealso {@link unwrapOr}
|
|
611
|
-
* @seealso {@link unwrapErr}
|
|
612
|
-
* @seealso {@link unwrapRaw}
|
|
613
|
-
* @seealso {@link unwrapSafe}
|
|
614
|
-
*
|
|
615
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_safe}
|
|
616
|
-
*/
|
|
617
|
-
*unwrapSafe() {
|
|
618
|
-
if (this.isOk()) {
|
|
619
|
-
return this[ValueProperty];
|
|
620
|
-
}
|
|
621
|
-
yield this;
|
|
622
|
-
throw new ResultError("Should not be used outside of a safe try generator", this[ValueProperty]);
|
|
623
|
-
}
|
|
624
598
|
/**
|
|
625
599
|
* Returns `result` if the result is `Ok`, otherwise returns the `Err` value of itself.
|
|
626
600
|
* @param result The result to check.
|
|
@@ -895,16 +869,6 @@ var _Result = class _Result {
|
|
|
895
869
|
get [Symbol.toStringTag]() {
|
|
896
870
|
return this.match({ ok: /* @__PURE__ */ __name(() => "Ok", "ok"), err: /* @__PURE__ */ __name(() => "Err", "err") });
|
|
897
871
|
}
|
|
898
|
-
/**
|
|
899
|
-
* This function, in combination with `[$]`, is intended to emulate
|
|
900
|
-
* Rust's ? operator.
|
|
901
|
-
*
|
|
902
|
-
* @see {@link Result.safeTry}
|
|
903
|
-
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.safeTry}
|
|
904
|
-
*/
|
|
905
|
-
get [UnwrapSafeProperty]() {
|
|
906
|
-
return this.unwrapSafe();
|
|
907
|
-
}
|
|
908
872
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
909
873
|
static ok(value) {
|
|
910
874
|
return new _Result(value, true);
|
|
@@ -1024,13 +988,6 @@ var _Result = class _Result {
|
|
|
1024
988
|
}
|
|
1025
989
|
return err(errors);
|
|
1026
990
|
}
|
|
1027
|
-
static safeTry(body) {
|
|
1028
|
-
const n = body({ $: UnwrapSafeProperty, $async: unwrapSafeAsync }).next();
|
|
1029
|
-
if (n instanceof Promise) {
|
|
1030
|
-
return n.then((r) => r.value);
|
|
1031
|
-
}
|
|
1032
|
-
return n.value;
|
|
1033
|
-
}
|
|
1034
991
|
};
|
|
1035
992
|
__name(_Result, "Result");
|
|
1036
993
|
var Result = _Result;
|
|
@@ -1039,11 +996,6 @@ function resolve(value) {
|
|
|
1039
996
|
return Result.isResult(value) ? value : ok(value);
|
|
1040
997
|
}
|
|
1041
998
|
__name(resolve, "resolve");
|
|
1042
|
-
async function* unwrapSafeAsync(result) {
|
|
1043
|
-
const _result = await result;
|
|
1044
|
-
return yield* _result.unwrapSafe();
|
|
1045
|
-
}
|
|
1046
|
-
__name(unwrapSafeAsync, "unwrapSafeAsync");
|
|
1047
999
|
|
|
1048
1000
|
// src/lib/Option.ts
|
|
1049
1001
|
var ValueProperty2 = Symbol.for("@sapphire/result:Option.value");
|