retuple 1.0.0-next.31 → 1.0.0-next.33
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 +58 -18
- package/dist/index.d.cts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +58 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -601,9 +601,9 @@ class ResultOk extends Array {
|
|
|
601
601
|
$mapErr() {
|
|
602
602
|
return this;
|
|
603
603
|
}
|
|
604
|
-
$mapErrMatching() {
|
|
605
|
-
|
|
606
|
-
}
|
|
604
|
+
// $mapErrMatching(this: ThisOk<T>): ThisOk<T> {
|
|
605
|
+
// return this;
|
|
606
|
+
// }
|
|
607
607
|
$mapOr(_def, f) {
|
|
608
608
|
return Ok(f(this[1]));
|
|
609
609
|
}
|
|
@@ -704,6 +704,18 @@ class ResultOk extends Array {
|
|
|
704
704
|
$andSafeAsync(f, mapError = ensureError) {
|
|
705
705
|
return this.$async().$andSafe(f, mapError);
|
|
706
706
|
}
|
|
707
|
+
$andThroughSafe(f, mapError = ensureError) {
|
|
708
|
+
try {
|
|
709
|
+
f(this[1]);
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
catch (err) {
|
|
713
|
+
return Err(mapError(err));
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
$andThroughSafeAsync(f, mapError = ensureError) {
|
|
717
|
+
return this.$async().$andThroughSafe(f, mapError);
|
|
718
|
+
}
|
|
707
719
|
$andSafePromise(promise, mapError = ensureError) {
|
|
708
720
|
return this.$async().$andSafePromise(promise, mapError);
|
|
709
721
|
}
|
|
@@ -790,15 +802,18 @@ class ResultErr extends Array {
|
|
|
790
802
|
$mapErr(f) {
|
|
791
803
|
return Err(f(this[0]));
|
|
792
804
|
}
|
|
793
|
-
$mapErrMatching
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
805
|
+
// $mapErrMatching<F, C extends new (...args: any[]) => Error>(
|
|
806
|
+
// this: Result<T, E>,
|
|
807
|
+
// { classes, with: f }: MapErrMatchingParams<F, C>,
|
|
808
|
+
// ): Result<never, E | F> {
|
|
809
|
+
// const err = this[0];
|
|
810
|
+
// for (const ctor of classes) {
|
|
811
|
+
// if (err instanceof ctor) {
|
|
812
|
+
// return Err(f(err as InstanceType<C>));
|
|
813
|
+
// }
|
|
814
|
+
// }
|
|
815
|
+
// return this as Result<never, E>;
|
|
816
|
+
// }
|
|
802
817
|
$mapOr(def) {
|
|
803
818
|
return Ok(def);
|
|
804
819
|
}
|
|
@@ -873,6 +888,12 @@ class ResultErr extends Array {
|
|
|
873
888
|
$andSafeAsync() {
|
|
874
889
|
return this.$async();
|
|
875
890
|
}
|
|
891
|
+
$andThroughSafe() {
|
|
892
|
+
return this;
|
|
893
|
+
}
|
|
894
|
+
$andThroughSafeAsync() {
|
|
895
|
+
return this.$async();
|
|
896
|
+
}
|
|
876
897
|
$andSafePromise() {
|
|
877
898
|
return this.$async();
|
|
878
899
|
}
|
|
@@ -1012,12 +1033,17 @@ class ResultAsync {
|
|
|
1012
1033
|
: res;
|
|
1013
1034
|
}));
|
|
1014
1035
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
$mapErrMatching(
|
|
1019
|
-
|
|
1020
|
-
|
|
1036
|
+
// /**
|
|
1037
|
+
// * @TODO
|
|
1038
|
+
// */
|
|
1039
|
+
// $mapErrMatching<F, C extends new (...args: any[]) => Error>(
|
|
1040
|
+
// this: ResultAsync<T, E>,
|
|
1041
|
+
// params: MapErrMatchingParams<F, C>,
|
|
1042
|
+
// ): ResultAsync<T, E | F> {
|
|
1043
|
+
// return new ResultAsync(
|
|
1044
|
+
// this.#inner.then(async (res) => res.$mapErrMatching(params)),
|
|
1045
|
+
// );
|
|
1046
|
+
// }
|
|
1021
1047
|
/**
|
|
1022
1048
|
* The same as {@link Retuple.$mapOr|$mapOr}, except it returns
|
|
1023
1049
|
* {@link ResultAsync}.
|
|
@@ -1183,6 +1209,20 @@ class ResultAsync {
|
|
|
1183
1209
|
}
|
|
1184
1210
|
}));
|
|
1185
1211
|
}
|
|
1212
|
+
$andThroughSafe(f, mapError = ensureError) {
|
|
1213
|
+
return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
|
|
1214
|
+
if (res instanceof ResultErr) {
|
|
1215
|
+
return res;
|
|
1216
|
+
}
|
|
1217
|
+
try {
|
|
1218
|
+
await f(res[1]);
|
|
1219
|
+
return res;
|
|
1220
|
+
}
|
|
1221
|
+
catch (err) {
|
|
1222
|
+
return Err(mapError(err));
|
|
1223
|
+
}
|
|
1224
|
+
}));
|
|
1225
|
+
}
|
|
1186
1226
|
$andSafePromise(promise, mapError = ensureError) {
|
|
1187
1227
|
return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
|
|
1188
1228
|
if (res instanceof ResultErr) {
|
package/dist/index.d.cts
CHANGED
|
@@ -265,10 +265,6 @@ declare class ResultAsync<T, E> {
|
|
|
265
265
|
* {@link ResultAsync}.
|
|
266
266
|
*/
|
|
267
267
|
$mapErr<F = E>(this: ResultAsync<T, E>, f: (err: E) => F): ResultAsync<T, F>;
|
|
268
|
-
/**
|
|
269
|
-
* @TODO
|
|
270
|
-
*/
|
|
271
|
-
$mapErrMatching<F, C extends new (...args: any[]) => Error>(this: ResultAsync<T, E>, params: MapErrMatchingParams<F, C>): ResultAsync<T, E | F>;
|
|
272
268
|
/**
|
|
273
269
|
* The same as {@link Retuple.$mapOr|$mapOr}, except it returns
|
|
274
270
|
* {@link ResultAsync}.
|
|
@@ -379,6 +375,11 @@ declare class ResultAsync<T, E> {
|
|
|
379
375
|
*/
|
|
380
376
|
$andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
|
|
381
377
|
$andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
378
|
+
/**
|
|
379
|
+
* @TODO
|
|
380
|
+
*/
|
|
381
|
+
$andThroughSafe(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
|
|
382
|
+
$andThroughSafe<F = E>(this: ResultAsync<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
|
|
382
383
|
/**
|
|
383
384
|
* Returns {@link ResultAsync} based on the outcome of the promise when this
|
|
384
385
|
* result is `Ok`.
|
|
@@ -1022,13 +1023,6 @@ interface Retuple<T, E> extends ResultLike<T, E> {
|
|
|
1022
1023
|
* ```
|
|
1023
1024
|
*/
|
|
1024
1025
|
$mapErr<F = E>(this: Result<T, E>, f: (err: E) => F): Result<T, F>;
|
|
1025
|
-
/**
|
|
1026
|
-
* @TODO
|
|
1027
|
-
*/
|
|
1028
|
-
$mapErrMatching<F, C extends new (...args: any[]) => Error>(this: Result<T, E>, mapper: {
|
|
1029
|
-
classes: [C, ...C[]];
|
|
1030
|
-
with: (err: InstanceType<C>) => F;
|
|
1031
|
-
}): Result<T, E | F>;
|
|
1032
1026
|
/**
|
|
1033
1027
|
* Returns `Ok` containing the return value of the map function when this
|
|
1034
1028
|
* result is `Ok`.
|
|
@@ -1370,6 +1364,16 @@ interface Retuple<T, E> extends ResultLike<T, E> {
|
|
|
1370
1364
|
*/
|
|
1371
1365
|
$andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
|
|
1372
1366
|
$andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Shorthand for `result.$andThrough((x) => Result.$safe(() => f(x)))`;
|
|
1369
|
+
*/
|
|
1370
|
+
$andThroughSafe(this: Result<T, E>, f: (val: T) => any): Result<T, E | Error>;
|
|
1371
|
+
$andThroughSafe<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): Result<T, E | F>;
|
|
1372
|
+
/**
|
|
1373
|
+
* Shorthand for result.$async().$andThrough(...);
|
|
1374
|
+
*/
|
|
1375
|
+
$andThroughSafeAsync(this: Result<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
|
|
1376
|
+
$andThroughSafeAsync<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
|
|
1373
1377
|
/**
|
|
1374
1378
|
* Shorthand for `result.$async().$andSafePromise(...)`
|
|
1375
1379
|
*/
|
|
@@ -1638,10 +1642,6 @@ type CollectOk<TResults extends Record<string, ResultLikeAwaitable<any, any>>> =
|
|
|
1638
1642
|
[K in keyof TResults]: TResults[K] extends ResultLikeAwaitable<infer T, any> ? T : never;
|
|
1639
1643
|
} & {};
|
|
1640
1644
|
type CollectErr<TResults extends Record<string, ResultLikeAwaitable<any, any>>> = TResults[keyof TResults] extends ResultLikeAwaitable<any, infer E> ? E : never;
|
|
1641
|
-
interface MapErrMatchingParams<F, C extends new (...args: any[]) => Error> {
|
|
1642
|
-
classes: [C, ...C[]];
|
|
1643
|
-
with: (err: InstanceType<C>) => F;
|
|
1644
|
-
}
|
|
1645
1645
|
type Truthy<T> = Exclude<T, false | null | undefined | 0 | 0n | "">;
|
|
1646
1646
|
type Falsey<T> = Extract<T, false | null | undefined | 0 | 0n | "">;
|
|
1647
1647
|
type NonZero<N extends number> = N & (`${N}` extends "0" ? never : N);
|
package/dist/index.d.ts
CHANGED
|
@@ -265,10 +265,6 @@ declare class ResultAsync<T, E> {
|
|
|
265
265
|
* {@link ResultAsync}.
|
|
266
266
|
*/
|
|
267
267
|
$mapErr<F = E>(this: ResultAsync<T, E>, f: (err: E) => F): ResultAsync<T, F>;
|
|
268
|
-
/**
|
|
269
|
-
* @TODO
|
|
270
|
-
*/
|
|
271
|
-
$mapErrMatching<F, C extends new (...args: any[]) => Error>(this: ResultAsync<T, E>, params: MapErrMatchingParams<F, C>): ResultAsync<T, E | F>;
|
|
272
268
|
/**
|
|
273
269
|
* The same as {@link Retuple.$mapOr|$mapOr}, except it returns
|
|
274
270
|
* {@link ResultAsync}.
|
|
@@ -379,6 +375,11 @@ declare class ResultAsync<T, E> {
|
|
|
379
375
|
*/
|
|
380
376
|
$andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
|
|
381
377
|
$andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
378
|
+
/**
|
|
379
|
+
* @TODO
|
|
380
|
+
*/
|
|
381
|
+
$andThroughSafe(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
|
|
382
|
+
$andThroughSafe<F = E>(this: ResultAsync<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
|
|
382
383
|
/**
|
|
383
384
|
* Returns {@link ResultAsync} based on the outcome of the promise when this
|
|
384
385
|
* result is `Ok`.
|
|
@@ -1022,13 +1023,6 @@ interface Retuple<T, E> extends ResultLike<T, E> {
|
|
|
1022
1023
|
* ```
|
|
1023
1024
|
*/
|
|
1024
1025
|
$mapErr<F = E>(this: Result<T, E>, f: (err: E) => F): Result<T, F>;
|
|
1025
|
-
/**
|
|
1026
|
-
* @TODO
|
|
1027
|
-
*/
|
|
1028
|
-
$mapErrMatching<F, C extends new (...args: any[]) => Error>(this: Result<T, E>, mapper: {
|
|
1029
|
-
classes: [C, ...C[]];
|
|
1030
|
-
with: (err: InstanceType<C>) => F;
|
|
1031
|
-
}): Result<T, E | F>;
|
|
1032
1026
|
/**
|
|
1033
1027
|
* Returns `Ok` containing the return value of the map function when this
|
|
1034
1028
|
* result is `Ok`.
|
|
@@ -1370,6 +1364,16 @@ interface Retuple<T, E> extends ResultLike<T, E> {
|
|
|
1370
1364
|
*/
|
|
1371
1365
|
$andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
|
|
1372
1366
|
$andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Shorthand for `result.$andThrough((x) => Result.$safe(() => f(x)))`;
|
|
1369
|
+
*/
|
|
1370
|
+
$andThroughSafe(this: Result<T, E>, f: (val: T) => any): Result<T, E | Error>;
|
|
1371
|
+
$andThroughSafe<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): Result<T, E | F>;
|
|
1372
|
+
/**
|
|
1373
|
+
* Shorthand for result.$async().$andThrough(...);
|
|
1374
|
+
*/
|
|
1375
|
+
$andThroughSafeAsync(this: Result<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
|
|
1376
|
+
$andThroughSafeAsync<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
|
|
1373
1377
|
/**
|
|
1374
1378
|
* Shorthand for `result.$async().$andSafePromise(...)`
|
|
1375
1379
|
*/
|
|
@@ -1638,10 +1642,6 @@ type CollectOk<TResults extends Record<string, ResultLikeAwaitable<any, any>>> =
|
|
|
1638
1642
|
[K in keyof TResults]: TResults[K] extends ResultLikeAwaitable<infer T, any> ? T : never;
|
|
1639
1643
|
} & {};
|
|
1640
1644
|
type CollectErr<TResults extends Record<string, ResultLikeAwaitable<any, any>>> = TResults[keyof TResults] extends ResultLikeAwaitable<any, infer E> ? E : never;
|
|
1641
|
-
interface MapErrMatchingParams<F, C extends new (...args: any[]) => Error> {
|
|
1642
|
-
classes: [C, ...C[]];
|
|
1643
|
-
with: (err: InstanceType<C>) => F;
|
|
1644
|
-
}
|
|
1645
1645
|
type Truthy<T> = Exclude<T, false | null | undefined | 0 | 0n | "">;
|
|
1646
1646
|
type Falsey<T> = Extract<T, false | null | undefined | 0 | 0n | "">;
|
|
1647
1647
|
type NonZero<N extends number> = N & (`${N}` extends "0" ? never : N);
|
package/dist/index.js
CHANGED
|
@@ -587,9 +587,9 @@ class ResultOk extends Array {
|
|
|
587
587
|
$mapErr() {
|
|
588
588
|
return this;
|
|
589
589
|
}
|
|
590
|
-
$mapErrMatching() {
|
|
591
|
-
|
|
592
|
-
}
|
|
590
|
+
// $mapErrMatching(this: ThisOk<T>): ThisOk<T> {
|
|
591
|
+
// return this;
|
|
592
|
+
// }
|
|
593
593
|
$mapOr(_def, f) {
|
|
594
594
|
return Ok(f(this[1]));
|
|
595
595
|
}
|
|
@@ -690,6 +690,18 @@ class ResultOk extends Array {
|
|
|
690
690
|
$andSafeAsync(f, mapError = ensureError) {
|
|
691
691
|
return this.$async().$andSafe(f, mapError);
|
|
692
692
|
}
|
|
693
|
+
$andThroughSafe(f, mapError = ensureError) {
|
|
694
|
+
try {
|
|
695
|
+
f(this[1]);
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
catch (err) {
|
|
699
|
+
return Err(mapError(err));
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
$andThroughSafeAsync(f, mapError = ensureError) {
|
|
703
|
+
return this.$async().$andThroughSafe(f, mapError);
|
|
704
|
+
}
|
|
693
705
|
$andSafePromise(promise, mapError = ensureError) {
|
|
694
706
|
return this.$async().$andSafePromise(promise, mapError);
|
|
695
707
|
}
|
|
@@ -776,15 +788,18 @@ class ResultErr extends Array {
|
|
|
776
788
|
$mapErr(f) {
|
|
777
789
|
return Err(f(this[0]));
|
|
778
790
|
}
|
|
779
|
-
$mapErrMatching
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
}
|
|
791
|
+
// $mapErrMatching<F, C extends new (...args: any[]) => Error>(
|
|
792
|
+
// this: Result<T, E>,
|
|
793
|
+
// { classes, with: f }: MapErrMatchingParams<F, C>,
|
|
794
|
+
// ): Result<never, E | F> {
|
|
795
|
+
// const err = this[0];
|
|
796
|
+
// for (const ctor of classes) {
|
|
797
|
+
// if (err instanceof ctor) {
|
|
798
|
+
// return Err(f(err as InstanceType<C>));
|
|
799
|
+
// }
|
|
800
|
+
// }
|
|
801
|
+
// return this as Result<never, E>;
|
|
802
|
+
// }
|
|
788
803
|
$mapOr(def) {
|
|
789
804
|
return Ok(def);
|
|
790
805
|
}
|
|
@@ -859,6 +874,12 @@ class ResultErr extends Array {
|
|
|
859
874
|
$andSafeAsync() {
|
|
860
875
|
return this.$async();
|
|
861
876
|
}
|
|
877
|
+
$andThroughSafe() {
|
|
878
|
+
return this;
|
|
879
|
+
}
|
|
880
|
+
$andThroughSafeAsync() {
|
|
881
|
+
return this.$async();
|
|
882
|
+
}
|
|
862
883
|
$andSafePromise() {
|
|
863
884
|
return this.$async();
|
|
864
885
|
}
|
|
@@ -998,12 +1019,17 @@ class ResultAsync {
|
|
|
998
1019
|
: res;
|
|
999
1020
|
}));
|
|
1000
1021
|
}
|
|
1001
|
-
/**
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
$mapErrMatching(
|
|
1005
|
-
|
|
1006
|
-
|
|
1022
|
+
// /**
|
|
1023
|
+
// * @TODO
|
|
1024
|
+
// */
|
|
1025
|
+
// $mapErrMatching<F, C extends new (...args: any[]) => Error>(
|
|
1026
|
+
// this: ResultAsync<T, E>,
|
|
1027
|
+
// params: MapErrMatchingParams<F, C>,
|
|
1028
|
+
// ): ResultAsync<T, E | F> {
|
|
1029
|
+
// return new ResultAsync(
|
|
1030
|
+
// this.#inner.then(async (res) => res.$mapErrMatching(params)),
|
|
1031
|
+
// );
|
|
1032
|
+
// }
|
|
1007
1033
|
/**
|
|
1008
1034
|
* The same as {@link Retuple.$mapOr|$mapOr}, except it returns
|
|
1009
1035
|
* {@link ResultAsync}.
|
|
@@ -1169,6 +1195,20 @@ class ResultAsync {
|
|
|
1169
1195
|
}
|
|
1170
1196
|
}));
|
|
1171
1197
|
}
|
|
1198
|
+
$andThroughSafe(f, mapError = ensureError) {
|
|
1199
|
+
return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
|
|
1200
|
+
if (res instanceof ResultErr) {
|
|
1201
|
+
return res;
|
|
1202
|
+
}
|
|
1203
|
+
try {
|
|
1204
|
+
await f(res[1]);
|
|
1205
|
+
return res;
|
|
1206
|
+
}
|
|
1207
|
+
catch (err) {
|
|
1208
|
+
return Err(mapError(err));
|
|
1209
|
+
}
|
|
1210
|
+
}));
|
|
1211
|
+
}
|
|
1172
1212
|
$andSafePromise(promise, mapError = ensureError) {
|
|
1173
1213
|
return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
|
|
1174
1214
|
if (res instanceof ResultErr) {
|