@reykjavik/webtools 0.3.1 → 0.3.2
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/CHANGELOG.md +6 -4
- package/README.md +24 -0
- package/errorhandling.d.ts +7 -0
- package/esm/errorhandling.d.ts +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.3.
|
|
7
|
+
## 0.3.2
|
|
8
8
|
|
|
9
|
-
_2025-
|
|
9
|
+
_2025-12-01_
|
|
10
10
|
|
|
11
|
-
-
|
|
11
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
12
|
+
- feat: Add type `Result.PayloadOf<T>` to extract the successful payload
|
|
13
|
+
type from a `ResultTuple<T>` or a `ResultTuple`-returning function.
|
|
12
14
|
|
|
13
|
-
## 0.3.0
|
|
15
|
+
## 0.3.0 – 0.3.1
|
|
14
16
|
|
|
15
17
|
_2025-11-10_
|
|
16
18
|
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ bun add @reykjavik/webtools
|
|
|
46
46
|
- [`Result.Success`](#resultsuccess)
|
|
47
47
|
- [`Result.Fail`](#resultfail)
|
|
48
48
|
- [`Result.throw`](#resultthrow)
|
|
49
|
+
- [Type `Result.PayloadOf`](#type-resultpayloadof)
|
|
49
50
|
- [`@reykjavik/webtools/SiteImprove`](#reykjavikwebtoolssiteimprove)
|
|
50
51
|
- [`SiteImprove` component](#siteimprove-component)
|
|
51
52
|
- [`pingSiteImprove` helper](#pingsiteimprove-helper)
|
|
@@ -838,6 +839,29 @@ try {
|
|
|
838
839
|
|
|
839
840
|
This function acts as the inverse of [`Result.catch()`](#resultcatch).
|
|
840
841
|
|
|
842
|
+
### Type `Result.PayloadOf`
|
|
843
|
+
|
|
844
|
+
**Syntax:**
|
|
845
|
+
`Result.PayloadOf<T extends | ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)>`
|
|
846
|
+
|
|
847
|
+
This utility type extracts the successful payload type `T` from a
|
|
848
|
+
`Result.Tuple<T>`-like type, a `Promise` of such type, or a function returning
|
|
849
|
+
either of those.
|
|
850
|
+
|
|
851
|
+
```ts
|
|
852
|
+
import { Result } from '@reykjavik/webtools/errorhandling';
|
|
853
|
+
|
|
854
|
+
type ResTpl = Result.Tuple<string, Error>;
|
|
855
|
+
type ResTplPromise = Promise<Result.Tuple<number, Error>>;
|
|
856
|
+
type ResTplFn = (arg: unknown) => Result.Tuple<boolean, Error>;
|
|
857
|
+
type ResTplPromiseFn = (arg: unknown) => Promise<Result.Tuple<Date, Error>>;
|
|
858
|
+
|
|
859
|
+
type Payload1 = Result.PayloadOf<ResTpl>; // string
|
|
860
|
+
type Payload2 = Result.PayloadOf<ResTplPromise>; // number
|
|
861
|
+
type Payload3 = Result.PayloadOf<ResTplFn>; // boolean
|
|
862
|
+
type Payload4 = Result.PayloadOf<ResTplPromiseFn>; // Date
|
|
863
|
+
```
|
|
864
|
+
|
|
841
865
|
---
|
|
842
866
|
|
|
843
867
|
## `@reykjavik/webtools/SiteImprove`
|
package/errorhandling.d.ts
CHANGED
|
@@ -106,5 +106,12 @@ export declare namespace Result {
|
|
|
106
106
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
107
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
108
|
type FailObj<E extends Error> = FailResult<E>;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
111
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
112
|
+
*
|
|
113
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
114
|
+
*/
|
|
115
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
116
|
}
|
|
110
117
|
export {};
|
package/esm/errorhandling.d.ts
CHANGED
|
@@ -106,5 +106,12 @@ export declare namespace Result {
|
|
|
106
106
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
107
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
108
|
type FailObj<E extends Error> = FailResult<E>;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
111
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
112
|
+
*
|
|
113
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
114
|
+
*/
|
|
115
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
116
|
}
|
|
110
117
|
export {};
|
package/package.json
CHANGED