retuple 1.0.0-next.7 → 1.0.0-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -955,6 +955,19 @@ class ResultAsync {
955
955
  }
956
956
  }));
957
957
  }
958
+ $orSafePromise(promise, mapError = ensureError) {
959
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
960
+ if (res instanceof ResultOk) {
961
+ return res;
962
+ }
963
+ try {
964
+ return Ok(await promise);
965
+ }
966
+ catch (err) {
967
+ return Err(mapError(err));
968
+ }
969
+ }));
970
+ }
958
971
  $and(and) {
959
972
  return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
960
973
  return res instanceof ResultOk ? await and : res;
@@ -989,6 +1002,19 @@ class ResultAsync {
989
1002
  }
990
1003
  }));
991
1004
  }
1005
+ $andSafePromise(promise, mapError = ensureError) {
1006
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
1007
+ if (res instanceof ResultErr) {
1008
+ return res;
1009
+ }
1010
+ try {
1011
+ return Ok(await promise);
1012
+ }
1013
+ catch (err) {
1014
+ return Err(mapError(err));
1015
+ }
1016
+ }));
1017
+ }
992
1018
  /**
993
1019
  * The same as {@link Retuple.$peek|$peek}, except it:
994
1020
  *
package/dist/index.d.cts CHANGED
@@ -864,6 +864,11 @@ declare class ResultAsync<T, E> {
864
864
  */
865
865
  $orSafe<U = T>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
866
866
  $orSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
867
+ /**
868
+ * @TODO
869
+ */
870
+ $orSafePromise<U = T>(this: ResultAsync<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
871
+ $orSafePromise<U = T, F = E>(this: ResultAsync<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
867
872
  /**
868
873
  * The same as {@link Retuple.$and|$and}, except it:
869
874
  *
@@ -893,6 +898,11 @@ declare class ResultAsync<T, E> {
893
898
  */
894
899
  $andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
895
900
  $andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
901
+ /**
902
+ * @TODO
903
+ */
904
+ $andSafePromise<U = T>(this: ResultAsync<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
905
+ $andSafePromise<U = T, F = E>(this: ResultAsync<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
896
906
  /**
897
907
  * The same as {@link Retuple.$peek|$peek}, except it:
898
908
  *
@@ -1309,7 +1319,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1309
1319
  * assert.equal(asserted.$unwrapErr(), "test");
1310
1320
  * ```
1311
1321
  */
1312
- $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>): Result<Truthy<T>, E | F>;
1322
+ $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>): Result<Truthy<T> | U, E | F>;
1313
1323
  $assertOr<U = T, F = E, A extends T = T>(this: Result<T, E>, def: Result<U, F>, predicate: (val: T) => val is A): Result<U | A, E | F>;
1314
1324
  $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>, condition: (val: T) => unknown): Result<T | U, E | F>;
1315
1325
  /**
@@ -1392,7 +1402,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1392
1402
  * assert.equal(asserted.$unwrapErr(), "test");
1393
1403
  * ```
1394
1404
  */
1395
- $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>): Result<Truthy<T>, E | F>;
1405
+ $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>): Result<Truthy<T> | U, E | F>;
1396
1406
  $assertOrElse<U = T, F = E, A extends T = T>(this: Result<T, E>, def: (val: T) => Result<U, F>, predicate: (val: T) => val is A): Result<U | A, E | F>;
1397
1407
  $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>, condition: (val: T) => unknown): Result<T | U, E | F>;
1398
1408
  /**
@@ -1583,7 +1593,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1583
1593
  */
1584
1594
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => Result<U, F>): Result<T | U, F>;
1585
1595
  /**
1586
- * Returns a result based on the outcome of the safe function when this
1596
+ * Returns a `Result` based on the outcome of the safe function when this
1587
1597
  * result is `Err`.
1588
1598
  *
1589
1599
  * Otherwise, returns `Ok` containing the current ok value.
@@ -1716,6 +1726,9 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1716
1726
  */
1717
1727
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1718
1728
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1729
+ /**
1730
+ * @TODO
1731
+ */
1719
1732
  /**
1720
1733
  * Calls the peek function and returns `Result` equivalent to this result.
1721
1734
  *
package/dist/index.d.ts CHANGED
@@ -864,6 +864,11 @@ declare class ResultAsync<T, E> {
864
864
  */
865
865
  $orSafe<U = T>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
866
866
  $orSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
867
+ /**
868
+ * @TODO
869
+ */
870
+ $orSafePromise<U = T>(this: ResultAsync<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
871
+ $orSafePromise<U = T, F = E>(this: ResultAsync<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
867
872
  /**
868
873
  * The same as {@link Retuple.$and|$and}, except it:
869
874
  *
@@ -893,6 +898,11 @@ declare class ResultAsync<T, E> {
893
898
  */
894
899
  $andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
895
900
  $andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
901
+ /**
902
+ * @TODO
903
+ */
904
+ $andSafePromise<U = T>(this: ResultAsync<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
905
+ $andSafePromise<U = T, F = E>(this: ResultAsync<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
896
906
  /**
897
907
  * The same as {@link Retuple.$peek|$peek}, except it:
898
908
  *
@@ -1309,7 +1319,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1309
1319
  * assert.equal(asserted.$unwrapErr(), "test");
1310
1320
  * ```
1311
1321
  */
1312
- $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>): Result<Truthy<T>, E | F>;
1322
+ $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>): Result<Truthy<T> | U, E | F>;
1313
1323
  $assertOr<U = T, F = E, A extends T = T>(this: Result<T, E>, def: Result<U, F>, predicate: (val: T) => val is A): Result<U | A, E | F>;
1314
1324
  $assertOr<U = T, F = E>(this: Result<T, E>, def: Result<U, F>, condition: (val: T) => unknown): Result<T | U, E | F>;
1315
1325
  /**
@@ -1392,7 +1402,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1392
1402
  * assert.equal(asserted.$unwrapErr(), "test");
1393
1403
  * ```
1394
1404
  */
1395
- $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>): Result<Truthy<T>, E | F>;
1405
+ $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>): Result<Truthy<T> | U, E | F>;
1396
1406
  $assertOrElse<U = T, F = E, A extends T = T>(this: Result<T, E>, def: (val: T) => Result<U, F>, predicate: (val: T) => val is A): Result<U | A, E | F>;
1397
1407
  $assertOrElse<U = T, F = E>(this: Result<T, E>, def: (val: T) => Result<U, F>, condition: (val: T) => unknown): Result<T | U, E | F>;
1398
1408
  /**
@@ -1583,7 +1593,7 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1583
1593
  */
1584
1594
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => Result<U, F>): Result<T | U, F>;
1585
1595
  /**
1586
- * Returns a result based on the outcome of the safe function when this
1596
+ * Returns a `Result` based on the outcome of the safe function when this
1587
1597
  * result is `Err`.
1588
1598
  *
1589
1599
  * Otherwise, returns `Ok` containing the current ok value.
@@ -1716,6 +1726,9 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined> {
1716
1726
  */
1717
1727
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1718
1728
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1729
+ /**
1730
+ * @TODO
1731
+ */
1719
1732
  /**
1720
1733
  * Calls the peek function and returns `Result` equivalent to this result.
1721
1734
  *
package/dist/index.js CHANGED
@@ -937,6 +937,19 @@ class ResultAsync {
937
937
  }
938
938
  }));
939
939
  }
940
+ $orSafePromise(promise, mapError = ensureError) {
941
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
942
+ if (res instanceof ResultOk) {
943
+ return res;
944
+ }
945
+ try {
946
+ return Ok(await promise);
947
+ }
948
+ catch (err) {
949
+ return Err(mapError(err));
950
+ }
951
+ }));
952
+ }
940
953
  $and(and) {
941
954
  return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
942
955
  return res instanceof ResultOk ? await and : res;
@@ -971,6 +984,19 @@ class ResultAsync {
971
984
  }
972
985
  }));
973
986
  }
987
+ $andSafePromise(promise, mapError = ensureError) {
988
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
989
+ if (res instanceof ResultErr) {
990
+ return res;
991
+ }
992
+ try {
993
+ return Ok(await promise);
994
+ }
995
+ catch (err) {
996
+ return Err(mapError(err));
997
+ }
998
+ }));
999
+ }
974
1000
  /**
975
1001
  * The same as {@link Retuple.$peek|$peek}, except it:
976
1002
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retuple",
3
- "version": "1.0.0-next.7",
3
+ "version": "1.0.0-next.9",
4
4
  "scripts": {
5
5
  "test": "vitest",
6
6
  "lint": "eslint . --ext .ts -c eslint.config.mjs --fix",