wellcrafted 0.43.0 → 0.44.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 +157 -203
- package/dist/error/index.d.ts +3 -3
- package/dist/error/index.js +2 -2
- package/dist/{error-Dy9wXt5_.js → error-BkeqDeUq.js} +2 -2
- package/dist/{error-Dy9wXt5_.js.map → error-BkeqDeUq.js.map} +1 -1
- package/dist/{index-B9PnZCTt.d.ts → index-ByVX3bXz.d.ts} +2 -2
- package/dist/{index-B9PnZCTt.d.ts.map → index-ByVX3bXz.d.ts.map} +1 -1
- package/dist/{index-DnoV2ZDO.d.ts → index-D0f5JWiT.d.ts} +2 -2
- package/dist/{index-DnoV2ZDO.d.ts.map → index-D0f5JWiT.d.ts.map} +1 -1
- package/dist/json.d.ts +5 -5
- package/dist/json.js +4 -4
- package/dist/logger/index.d.ts +3 -3
- package/dist/logger/index.js +2 -2
- package/dist/query/index.d.ts +19 -19
- package/dist/query/index.d.ts.map +1 -1
- package/dist/query/index.js +15 -15
- package/dist/query/index.js.map +1 -1
- package/dist/result/index.d.ts +3 -3
- package/dist/result/index.js +3 -3
- package/dist/{result-C5cJ1_WU.js → result-C_ph_izC.js} +5 -5
- package/dist/result-C_ph_izC.js.map +1 -0
- package/dist/{result-DKwq9BCr.d.ts → result-_socO0Ud.d.ts} +5 -5
- package/dist/{result-DKwq9BCr.d.ts.map → result-_socO0Ud.d.ts.map} +1 -1
- package/dist/{result-C9V2Knvt.js → result-pV2mfn0W.js} +2 -2
- package/dist/{result-C9V2Knvt.js.map → result-pV2mfn0W.js.map} +1 -1
- package/dist/{tap-err-CP-re1HT.js → tap-err-BENAkFsH.js} +2 -2
- package/dist/{tap-err-CP-re1HT.js.map → tap-err-BENAkFsH.js.map} +1 -1
- package/dist/{tap-err-CFhHBPfH.d.ts → tap-err-C0xfVXtz.d.ts} +2 -2
- package/dist/{tap-err-CFhHBPfH.d.ts.map → tap-err-C0xfVXtz.d.ts.map} +1 -1
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +4 -4
- package/dist/{types-tXXk7K9Q.d.ts → types-ojNaDB4n.d.ts} +2 -2
- package/dist/{types-tXXk7K9Q.d.ts.map → types-ojNaDB4n.d.ts.map} +1 -1
- package/package.json +5 -2
- package/dist/result-C5cJ1_WU.js.map +0 -1
package/dist/query/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Result } from "../result-
|
|
2
|
-
import "../tap-err-
|
|
3
|
-
import "../index-
|
|
1
|
+
import { Result } from "../result-_socO0Ud.js";
|
|
2
|
+
import "../tap-err-C0xfVXtz.js";
|
|
3
|
+
import "../index-D0f5JWiT.js";
|
|
4
4
|
import { DefaultError, MutationKey, MutationObserverOptions, QueryClient, QueryFunction, QueryKey, QueryObserverOptions } from "@tanstack/query-core";
|
|
5
5
|
|
|
6
6
|
//#region src/query/utils.d.ts
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Input for `
|
|
9
|
+
* Input for `resultQueryOptions` and `defineQuery`.
|
|
10
10
|
*
|
|
11
11
|
* Mirrors TanStack Query's `QueryObserverOptions` but expects `queryFn` to
|
|
12
12
|
* return a Wellcrafted `Result`. The Result is unwrapped into TanStack's
|
|
13
|
-
* throwing data/error contract by `
|
|
13
|
+
* throwing data/error contract by `resultQueryOptions`.
|
|
14
14
|
*
|
|
15
15
|
* @template TQueryFnData - The success type produced by `queryFn`
|
|
16
16
|
* @template TError - The error type carried by the Result
|
|
@@ -23,11 +23,11 @@ type QueryOptionsInput<TQueryFnData = unknown, TError = DefaultError, TData = TQ
|
|
|
23
23
|
queryFn: QueryFunction<Result<TQueryFnData, TError>, TQueryKey>;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Input for `
|
|
26
|
+
* Input for `resultMutationOptions` and `defineMutation`.
|
|
27
27
|
*
|
|
28
28
|
* Mirrors TanStack Query's `MutationObserverOptions` but expects `mutationFn`
|
|
29
29
|
* to return a Wellcrafted `Result`. The Result is unwrapped into TanStack's
|
|
30
|
-
* throwing data/error contract by `
|
|
30
|
+
* throwing data/error contract by `resultMutationOptions`.
|
|
31
31
|
*
|
|
32
32
|
* @template TData - The success type produced by `mutationFn`
|
|
33
33
|
* @template TError - The error type carried by the Result
|
|
@@ -50,20 +50,20 @@ type MutationOptionsInput<TData, TError, TVariables = void, TContext = unknown,
|
|
|
50
50
|
* `QueryClient`-bound imperative helpers from `defineQuery`:
|
|
51
51
|
*
|
|
52
52
|
* ```ts
|
|
53
|
-
* const query = createQuery(() =>
|
|
53
|
+
* const query = createQuery(() => resultQueryOptions({
|
|
54
54
|
* queryKey: ['user', userId],
|
|
55
55
|
* queryFn: () => services.getUser(userId),
|
|
56
56
|
* }));
|
|
57
57
|
* ```
|
|
58
58
|
*
|
|
59
59
|
* `defineQuery` composes through this helper, so the `.options` it returns
|
|
60
|
-
* is the same shape `
|
|
60
|
+
* is the same shape `resultQueryOptions` produces.
|
|
61
61
|
*
|
|
62
62
|
* @param input - Result-aware query configuration
|
|
63
63
|
* @returns TanStack Query `QueryObserverOptions` with `queryFn` rewired to
|
|
64
64
|
* resolve `Ok` and throw `Err`
|
|
65
65
|
*/
|
|
66
|
-
declare function
|
|
66
|
+
declare function resultQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, const TQueryKey extends QueryKey = QueryKey>(input: QueryOptionsInput<TQueryFnData, TError, TData, TQueryData, TQueryKey>): QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
|
|
67
67
|
/**
|
|
68
68
|
* Adapter from a Result-returning mutation function to TanStack Query options.
|
|
69
69
|
*
|
|
@@ -75,26 +75,26 @@ declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TDa
|
|
|
75
75
|
* `QueryClient`-bound imperative helpers from `defineMutation`:
|
|
76
76
|
*
|
|
77
77
|
* ```ts
|
|
78
|
-
* const save = createMutation(() =>
|
|
78
|
+
* const save = createMutation(() => resultMutationOptions({
|
|
79
79
|
* mutationKey: ['saveUser'],
|
|
80
80
|
* mutationFn: (input: SaveUserInput) => services.saveUser(input),
|
|
81
81
|
* }));
|
|
82
82
|
* ```
|
|
83
83
|
*
|
|
84
84
|
* `defineMutation` composes through this helper, so the `.options` it
|
|
85
|
-
* returns is the same shape `
|
|
85
|
+
* returns is the same shape `resultMutationOptions` produces.
|
|
86
86
|
*
|
|
87
87
|
* @param input - Result-aware mutation configuration
|
|
88
88
|
* @returns TanStack Query `MutationObserverOptions` with `mutationFn` rewired
|
|
89
89
|
* to resolve `Ok` and throw `Err`
|
|
90
90
|
*/
|
|
91
|
-
declare function
|
|
91
|
+
declare function resultMutationOptions<TData, TError, TVariables = void, TContext = unknown, const TMutationKey extends MutationKey = MutationKey>(input: MutationOptionsInput<TData, TError, TVariables, TContext, TMutationKey>): MutationObserverOptions<TData, TError, TVariables, TContext>;
|
|
92
92
|
/**
|
|
93
93
|
* Output of `defineQuery`.
|
|
94
94
|
*
|
|
95
95
|
* Query imperative reads require an explicit cache policy.
|
|
96
96
|
*
|
|
97
|
-
* - `options`: Options shape produced by `
|
|
97
|
+
* - `options`: Options shape produced by `resultQueryOptions`, ready for hooks.
|
|
98
98
|
* - `fetch()`: Always evaluates freshness; refetches if stale.
|
|
99
99
|
* - `ensure()`: Prefers cached data; fetches only when missing.
|
|
100
100
|
*/
|
|
@@ -109,7 +109,7 @@ type DefineQueryOutput<TQueryFnData = unknown, TError = DefaultError, TData = TQ
|
|
|
109
109
|
* The returned function directly executes the mutation.
|
|
110
110
|
*
|
|
111
111
|
* - `(variables)` (callable): Imperatively runs the mutation, returning a Result.
|
|
112
|
-
* - `options`: Options shape produced by `
|
|
112
|
+
* - `options`: Options shape produced by `resultMutationOptions`, ready for hooks.
|
|
113
113
|
*/
|
|
114
114
|
type DefineMutationOutput<TData, TError, TVariables = void, TContext = unknown> = ((variables: TVariables) => Promise<Result<TData, TError>>) & {
|
|
115
115
|
options: MutationObserverOptions<TData, TError, TVariables, TContext>;
|
|
@@ -120,11 +120,11 @@ type DefineMutationOutput<TData, TError, TVariables = void, TContext = unknown>
|
|
|
120
120
|
* Use this when you want a reusable query/mutation definition that carries
|
|
121
121
|
* its own imperative query helpers (`.fetch`, `.ensure`) and callable mutation
|
|
122
122
|
* execution powered by a specific client. For local one-shot options that only need
|
|
123
|
-
* to flow into a framework hook, prefer `
|
|
123
|
+
* to flow into a framework hook, prefer `resultQueryOptions` / `resultMutationOptions`
|
|
124
124
|
* directly: those are platform-agnostic and do not require a `QueryClient`.
|
|
125
125
|
*
|
|
126
|
-
* Both `defineQuery` and `defineMutation` compose through `
|
|
127
|
-
* `
|
|
126
|
+
* Both `defineQuery` and `defineMutation` compose through `resultQueryOptions` and
|
|
127
|
+
* `resultMutationOptions`, so there is exactly one place that unwraps `Result`
|
|
128
128
|
* into TanStack's throwing contract.
|
|
129
129
|
*
|
|
130
130
|
* @param queryClient - The TanStack `QueryClient` to bind imperative helpers to
|
|
@@ -180,5 +180,5 @@ declare function createQueryFactories(queryClient: QueryClient): {
|
|
|
180
180
|
*/
|
|
181
181
|
declare function defineKeys<const TKeys extends Record<string, readonly [unknown, ...unknown[]] | ((...args: never[]) => readonly [unknown, ...unknown[]])>>(keys: TKeys): TKeys;
|
|
182
182
|
//#endregion
|
|
183
|
-
export { createQueryFactories, defineKeys,
|
|
183
|
+
export { createQueryFactories, defineKeys, resultMutationOptions, resultQueryOptions };
|
|
184
184
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/query/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAUmE;;;;;;;;;KAe9D,iBAOuC,CAAA,eAAA,OAAA,EAAA,SALlC,YAKkC,EAAA,QAJnC,YAImC,EAAA,aAH9B,YAG8B,EAAA,kBAFzB,QAEyB,GAFd,QAEc,CAAA,GADxC,IACwC,CAA3C,oBAA2C,CAAtB,YAAsB,EAAR,MAAQ,EAAA,KAAA,EAAO,UAAP,EAAmB,SAAnB,CAAA,EAAA,SAAA,CAAA,GAAA;EAAK,QAAE,EAGxC,SAHwC;EAAU,OAAE,EAIrD,aAJqD,CAIvC,MAJuC,CAIhC,YAJgC,EAIlB,MAJkB,CAAA,EAIT,SAJS,CAAA;CAAS;;;;;;;;AAIjD;AAAA;;;;;KAgBlB,oBAO2B,CAAA,KAAA,EAAA,MAAA,EAAA,aAAA,IAAA,EAAA,WAAA,OAAA,EAAA,qBAFV,WAEU,GAFI,WAEJ,CAAA,GAD5B,IAC4B,CAA/B,uBAA+B,CAAP,KAAO,EAAA,MAAA,EAAQ,UAAR,EAAoB,QAApB,CAAA,EAAA,YAAA,CAAA,GAAA;EAAM,WAAE,EAG1B,YAH0B;EAAU,UAAE,EAAA,CAAA,SAAA,EAKvC,UALuC,EAAA,GAM9C,MAN8C,CAMvC,KANuC,EAMhC,MANgC,CAAA,GAMtB,OANsB,CAMd,MANc,CAMP,KANO,EAMA,MANA,CAAA,CAAA;CAAQ;;;;;;;;;;;AAMvB;AA2BrC;;;;;;;;;;;;;AAQwB,iBARR,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/query/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAUmE;;;;;;;;;KAe9D,iBAOuC,CAAA,eAAA,OAAA,EAAA,SALlC,YAKkC,EAAA,QAJnC,YAImC,EAAA,aAH9B,YAG8B,EAAA,kBAFzB,QAEyB,GAFd,QAEc,CAAA,GADxC,IACwC,CAA3C,oBAA2C,CAAtB,YAAsB,EAAR,MAAQ,EAAA,KAAA,EAAO,UAAP,EAAmB,SAAnB,CAAA,EAAA,SAAA,CAAA,GAAA;EAAK,QAAE,EAGxC,SAHwC;EAAU,OAAE,EAIrD,aAJqD,CAIvC,MAJuC,CAIhC,YAJgC,EAIlB,MAJkB,CAAA,EAIT,SAJS,CAAA;CAAS;;;;;;;;AAIjD;AAAA;;;;;KAgBlB,oBAO2B,CAAA,KAAA,EAAA,MAAA,EAAA,aAAA,IAAA,EAAA,WAAA,OAAA,EAAA,qBAFV,WAEU,GAFI,WAEJ,CAAA,GAD5B,IAC4B,CAA/B,uBAA+B,CAAP,KAAO,EAAA,MAAA,EAAQ,UAAR,EAAoB,QAApB,CAAA,EAAA,YAAA,CAAA,GAAA;EAAM,WAAE,EAG1B,YAH0B;EAAU,UAAE,EAAA,CAAA,SAAA,EAKvC,UALuC,EAAA,GAM9C,MAN8C,CAMvC,KANuC,EAMhC,MANgC,CAAA,GAMtB,OANsB,CAMd,MANc,CAMP,KANO,EAMA,MANA,CAAA,CAAA;CAAQ;;;;;;;;;;;AAMvB;AA2BrC;;;;;;;;;;;;;AAQwB,iBARR,kBAQQ,CAAA,eAAA,OAAA,EAAA,SANd,YAMc,EAAA,QALf,YAKe,EAAA,aAJV,YAIU,EAAA,wBAHC,QAGD,GAHY,QAGZ,CAAA,CAAA,KAAA,EADhB,iBACgB,CADE,YACF,EADgB,MAChB,EADwB,KACxB,EAD+B,UAC/B,EAD2C,SAC3C,CAAA,CAAA,EAArB,oBAAqB,CAAA,YAAA,EAAc,MAAd,EAAsB,KAAtB,EAA6B,UAA7B,EAAyC,SAAzC,CAAA;;;;;;AAAD;AAqCvB;;;;;;;;;;;;;;;AAc0B;AAMzB;;AAaS,iBAjCM,qBAiCN,CAAA,KAAA,EAAA,MAAA,EAAA,aAAA,IAAA,EAAA,WAAA,OAAA,EAAA,2BA5BkB,WA4BlB,GA5BgC,WA4BhC,CAAA,CAAA,KAAA,EA1BF,oBA0BE,CAzBR,KAyBQ,EAxBR,MAwBQ,EAvBR,UAuBQ,EAtBR,QAsBQ,EArBR,YAqBQ,CAAA,CAAA,EAnBP,uBAmBO,CAnBiB,KAmBjB,EAnBwB,MAmBxB,EAnBgC,UAmBhC,EAnB4C,QAmB5C,CAAA;;;;;;;;;;KAFL,iBAOK,CAAA,eAAA,OAAA,EAAA,SALA,YAKA,EAAA,QAJD,YAIC,EAAA,aAHI,YAGJ,EAAA,kBAFS,QAET,GAFoB,QAEpB,CAAA,GAAA;EAAoB,OAOD,EAPnB,oBAOmB,CAN3B,YAM2B,EAL3B,MAK2B,EAJ3B,KAI2B,EAH3B,UAG2B,EAF3B,SAE2B,CAAA;EAAU,KAAE,EAAA,GAAA,GAA3B,OAA2B,CAAnB,MAAmB,CAAZ,UAAY,EAAA,MAAA,CAAA,CAAA;EAAM,MAAzB,EAAA,GAAA,GACP,OADO,CACC,MADD,CACQ,UADR,EACoB,MADpB,CAAA,CAAA;CAAM;;;;;AACN;AAAA;;;KAWjB,oBAK0C,CAAA,KAAA,EAAA,MAAA,EAAA,aAAA,IAAA,EAAA,WAAA,OAAA,CAAA,GAAA,CAAA,CAAA,SAAA,EAA9B,UAA8B,EAAA,GAAf,OAAe,CAAP,MAAO,CAAA,KAAA,EAAO,MAAP,CAAA,CAAA,CAAA,GAAA;EAAK,OAAE,EAC5C,uBAD4C,CACpB,KADoB,EACb,MADa,EACL,UADK,EACO,QADP,CAAA;CAAM;;;;;;;AAC3B;AAmCjC;;;;;;;;;;;;;;;;;;;;;;;;;AA8DS,iBA9DO,oBAAA,CA8DP,WAAA,EA9DyC,WA8DzC,CAAA,EAAA;EAAoB,WAOJ,EAAA,CAAA,eAAA,OAAA,EAAA,SAlEjB,KAkEiB,EAAA,QAjElB,YAiEkB,EAAA,aAhEb,YAgEa,EAAA,wBA/DC,QA+DD,GAAA,SAAA,OAAA,EAAA,CAAA,CAAA,KAAA,EA7DhB,iBA6DgB,CA5DtB,YA4DsB,EA3DtB,MA2DsB,EA1DtB,KA0DsB,EAzDtB,UAyDsB,EAxDtB,SAwDsB,CAAA,EAAA,GAtDrB,iBAsDqB,CAtDH,YAsDG,EAtDW,MAsDX,EAtDmB,KAsDnB,EAtD0B,UAsD1B,EAtDsC,SAsDtC,CAAA;EAAK,cAAE,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,aAAA,IAAA,EAAA,WAAA,OAAA,EAAA,2BATH,WASG,GAAA,SAAA,OAAA,EAAA,CAAA,CAAA,KAAA,EAPvB,oBAOuB,CAN7B,KAM6B,EAL7B,MAK6B,EAJ7B,UAI6B,EAH7B,QAG6B,EAF7B,YAE6B,CAAA,EAAA,GAA5B,oBAA4B,CAAP,KAAO,EAAA,MAAA,EAAQ,UAAR,EAAoB,QAApB,CAAA;CAAM;;;AAAd;AAkExB;;;;;AAMqB;;;;;;;;;;;;;;;;;;;;iBANL,+BACK,mHAKb,QAAQ"}
|
package/dist/query/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Err, Ok, resolve } from "../result-
|
|
2
|
-
import "../tap-err-
|
|
3
|
-
import "../result-
|
|
1
|
+
import { Err, Ok, resolve } from "../result-C_ph_izC.js";
|
|
2
|
+
import "../tap-err-BENAkFsH.js";
|
|
3
|
+
import "../result-pV2mfn0W.js";
|
|
4
4
|
|
|
5
5
|
//#region src/query/utils.ts
|
|
6
6
|
/**
|
|
@@ -14,20 +14,20 @@ import "../result-C9V2Knvt.js";
|
|
|
14
14
|
* `QueryClient`-bound imperative helpers from `defineQuery`:
|
|
15
15
|
*
|
|
16
16
|
* ```ts
|
|
17
|
-
* const query = createQuery(() =>
|
|
17
|
+
* const query = createQuery(() => resultQueryOptions({
|
|
18
18
|
* queryKey: ['user', userId],
|
|
19
19
|
* queryFn: () => services.getUser(userId),
|
|
20
20
|
* }));
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* `defineQuery` composes through this helper, so the `.options` it returns
|
|
24
|
-
* is the same shape `
|
|
24
|
+
* is the same shape `resultQueryOptions` produces.
|
|
25
25
|
*
|
|
26
26
|
* @param input - Result-aware query configuration
|
|
27
27
|
* @returns TanStack Query `QueryObserverOptions` with `queryFn` rewired to
|
|
28
28
|
* resolve `Ok` and throw `Err`
|
|
29
29
|
*/
|
|
30
|
-
function
|
|
30
|
+
function resultQueryOptions(input) {
|
|
31
31
|
return {
|
|
32
32
|
...input,
|
|
33
33
|
queryFn: async (context) => resolve(await input.queryFn(context))
|
|
@@ -44,20 +44,20 @@ function queryOptions(input) {
|
|
|
44
44
|
* `QueryClient`-bound imperative helpers from `defineMutation`:
|
|
45
45
|
*
|
|
46
46
|
* ```ts
|
|
47
|
-
* const save = createMutation(() =>
|
|
47
|
+
* const save = createMutation(() => resultMutationOptions({
|
|
48
48
|
* mutationKey: ['saveUser'],
|
|
49
49
|
* mutationFn: (input: SaveUserInput) => services.saveUser(input),
|
|
50
50
|
* }));
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
53
|
* `defineMutation` composes through this helper, so the `.options` it
|
|
54
|
-
* returns is the same shape `
|
|
54
|
+
* returns is the same shape `resultMutationOptions` produces.
|
|
55
55
|
*
|
|
56
56
|
* @param input - Result-aware mutation configuration
|
|
57
57
|
* @returns TanStack Query `MutationObserverOptions` with `mutationFn` rewired
|
|
58
58
|
* to resolve `Ok` and throw `Err`
|
|
59
59
|
*/
|
|
60
|
-
function
|
|
60
|
+
function resultMutationOptions(input) {
|
|
61
61
|
return {
|
|
62
62
|
...input,
|
|
63
63
|
mutationFn: async (variables) => resolve(await input.mutationFn(variables))
|
|
@@ -69,11 +69,11 @@ function mutationOptions(input) {
|
|
|
69
69
|
* Use this when you want a reusable query/mutation definition that carries
|
|
70
70
|
* its own imperative query helpers (`.fetch`, `.ensure`) and callable mutation
|
|
71
71
|
* execution powered by a specific client. For local one-shot options that only need
|
|
72
|
-
* to flow into a framework hook, prefer `
|
|
72
|
+
* to flow into a framework hook, prefer `resultQueryOptions` / `resultMutationOptions`
|
|
73
73
|
* directly: those are platform-agnostic and do not require a `QueryClient`.
|
|
74
74
|
*
|
|
75
|
-
* Both `defineQuery` and `defineMutation` compose through `
|
|
76
|
-
* `
|
|
75
|
+
* Both `defineQuery` and `defineMutation` compose through `resultQueryOptions` and
|
|
76
|
+
* `resultMutationOptions`, so there is exactly one place that unwraps `Result`
|
|
77
77
|
* into TanStack's throwing contract.
|
|
78
78
|
*
|
|
79
79
|
* @param queryClient - The TanStack `QueryClient` to bind imperative helpers to
|
|
@@ -97,7 +97,7 @@ function mutationOptions(input) {
|
|
|
97
97
|
*/
|
|
98
98
|
function createQueryFactories(queryClient) {
|
|
99
99
|
const defineQuery = (input) => {
|
|
100
|
-
const options =
|
|
100
|
+
const options = resultQueryOptions(input);
|
|
101
101
|
async function fetch() {
|
|
102
102
|
try {
|
|
103
103
|
return Ok(await queryClient.fetchQuery(options));
|
|
@@ -119,7 +119,7 @@ function createQueryFactories(queryClient) {
|
|
|
119
119
|
};
|
|
120
120
|
};
|
|
121
121
|
const defineMutation = (input) => {
|
|
122
|
-
const options =
|
|
122
|
+
const options = resultMutationOptions(input);
|
|
123
123
|
async function run(variables) {
|
|
124
124
|
try {
|
|
125
125
|
return Ok(await runMutation(queryClient, options, variables));
|
|
@@ -178,5 +178,5 @@ function defineKeys(keys) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
//#endregion
|
|
181
|
-
export { createQueryFactories, defineKeys,
|
|
181
|
+
export { createQueryFactories, defineKeys, resultMutationOptions, resultQueryOptions };
|
|
182
182
|
//# sourceMappingURL=index.js.map
|
package/dist/query/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["input: QueryOptionsInput<TQueryFnData, TError, TData, TQueryData, TQueryKey>","input: MutationOptionsInput<\n\t\tTData,\n\t\tTError,\n\t\tTVariables,\n\t\tTContext,\n\t\tTMutationKey\n\t>","variables: TVariables","queryClient: QueryClient","input: QueryOptionsInput<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryData,\n\t\t\tTQueryKey\n\t\t>","input: MutationOptionsInput<\n\t\t\tTData,\n\t\t\tTError,\n\t\t\tTVariables,\n\t\t\tTContext,\n\t\t\tTMutationKey\n\t\t>","options: MutationOptions<TData, TError, TVariables, TContext>","keys: TKeys"],"sources":["../../src/query/utils.ts"],"sourcesContent":["import type {\n\tDefaultError,\n\tMutationKey,\n\tMutationObserverOptions,\n\tMutationOptions,\n\tQueryClient,\n\tQueryFunction,\n\tQueryKey,\n\tQueryObserverOptions,\n} from \"@tanstack/query-core\";\nimport { Err, Ok, type Result, resolve } from \"../result/index.js\";\n\n/**\n * Input for `queryOptions` and `defineQuery`.\n *\n * Mirrors TanStack Query's `QueryObserverOptions` but expects `queryFn` to\n * return a Wellcrafted `Result`. The Result is unwrapped into TanStack's\n * throwing data/error contract by `queryOptions`.\n *\n * @template TQueryFnData - The success type produced by `queryFn`\n * @template TError - The error type carried by the Result\n * @template TData - The type seen by consumers after `select`\n * @template TQueryData - The type stored in the cache (usually `TQueryFnData`)\n * @template TQueryKey - The literal query key tuple\n */\ntype QueryOptionsInput<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tTQueryKey extends QueryKey = QueryKey,\n> = Omit<\n\tQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n\t\"queryFn\"\n> & {\n\tqueryKey: TQueryKey;\n\tqueryFn: QueryFunction<Result<TQueryFnData, TError>, TQueryKey>;\n};\n\n/**\n * Input for `mutationOptions` and `defineMutation`.\n *\n * Mirrors TanStack Query's `MutationObserverOptions` but expects `mutationFn`\n * to return a Wellcrafted `Result`. The Result is unwrapped into TanStack's\n * throwing data/error contract by `mutationOptions`.\n *\n * @template TData - The success type produced by `mutationFn`\n * @template TError - The error type carried by the Result\n * @template TVariables - The variables passed to `mutationFn`\n * @template TContext - The context type for optimistic updates\n * @template TMutationKey - The literal mutation key tuple\n */\ntype MutationOptionsInput<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n\tTMutationKey extends MutationKey = MutationKey,\n> = Omit<\n\tMutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\"mutationFn\"\n> & {\n\tmutationKey: TMutationKey;\n\tmutationFn: (\n\t\tvariables: TVariables,\n\t) => Result<TData, TError> | Promise<Result<TData, TError>>;\n};\n\n/**\n * Adapter from a Result-returning query function to TanStack Query options.\n *\n * This is the single canonical place where `Result<TQueryFnData, TError>`\n * is converted into TanStack's contract: `Ok(data)` resolves with `data`,\n * `Err(error)` throws `error` into the query error channel.\n *\n * Use this directly with framework hooks when you do not need the\n * `QueryClient`-bound imperative helpers from `defineQuery`:\n *\n * ```ts\n * const query = createQuery(() => queryOptions({\n * queryKey: ['user', userId],\n * queryFn: () => services.getUser(userId),\n * }));\n * ```\n *\n * `defineQuery` composes through this helper, so the `.options` it returns\n * is the same shape `queryOptions` produces.\n *\n * @param input - Result-aware query configuration\n * @returns TanStack Query `QueryObserverOptions` with `queryFn` rewired to\n * resolve `Ok` and throw `Err`\n */\nexport function queryOptions<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tconst TQueryKey extends QueryKey = QueryKey,\n>(\n\tinput: QueryOptionsInput<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n): QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {\n\treturn {\n\t\t...input,\n\t\tqueryFn: async (context) => resolve(await input.queryFn(context)),\n\t} satisfies QueryObserverOptions<\n\t\tTQueryFnData,\n\t\tTError,\n\t\tTData,\n\t\tTQueryData,\n\t\tTQueryKey\n\t>;\n}\n\n/**\n * Adapter from a Result-returning mutation function to TanStack Query options.\n *\n * This is the single canonical place where `Result<TData, TError>` is\n * converted into TanStack's contract: `Ok(data)` resolves with `data`,\n * `Err(error)` throws `error` into the mutation error channel.\n *\n * Use this directly with framework hooks when you do not need the\n * `QueryClient`-bound imperative helpers from `defineMutation`:\n *\n * ```ts\n * const save = createMutation(() => mutationOptions({\n * mutationKey: ['saveUser'],\n * mutationFn: (input: SaveUserInput) => services.saveUser(input),\n * }));\n * ```\n *\n * `defineMutation` composes through this helper, so the `.options` it\n * returns is the same shape `mutationOptions` produces.\n *\n * @param input - Result-aware mutation configuration\n * @returns TanStack Query `MutationObserverOptions` with `mutationFn` rewired\n * to resolve `Ok` and throw `Err`\n */\nexport function mutationOptions<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n\tconst TMutationKey extends MutationKey = MutationKey,\n>(\n\tinput: MutationOptionsInput<\n\t\tTData,\n\t\tTError,\n\t\tTVariables,\n\t\tTContext,\n\t\tTMutationKey\n\t>,\n): MutationObserverOptions<TData, TError, TVariables, TContext> {\n\treturn {\n\t\t...input,\n\t\tmutationFn: async (variables: TVariables) =>\n\t\t\tresolve(await input.mutationFn(variables)),\n\t} satisfies MutationObserverOptions<TData, TError, TVariables, TContext>;\n}\n\n/**\n * Output of `defineQuery`.\n *\n * Query imperative reads require an explicit cache policy.\n *\n * - `options`: Options shape produced by `queryOptions`, ready for hooks.\n * - `fetch()`: Always evaluates freshness; refetches if stale.\n * - `ensure()`: Prefers cached data; fetches only when missing.\n */\ntype DefineQueryOutput<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tTQueryKey extends QueryKey = QueryKey,\n> = {\n\toptions: QueryObserverOptions<\n\t\tTQueryFnData,\n\t\tTError,\n\t\tTData,\n\t\tTQueryData,\n\t\tTQueryKey\n\t>;\n\tfetch: () => Promise<Result<TQueryData, TError>>;\n\tensure: () => Promise<Result<TQueryData, TError>>;\n};\n\n/**\n * Output of `defineMutation`.\n *\n * The returned function directly executes the mutation.\n *\n * - `(variables)` (callable): Imperatively runs the mutation, returning a Result.\n * - `options`: Options shape produced by `mutationOptions`, ready for hooks.\n */\ntype DefineMutationOutput<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n> = ((variables: TVariables) => Promise<Result<TData, TError>>) & {\n\toptions: MutationObserverOptions<TData, TError, TVariables, TContext>;\n};\n\n/**\n * Creates `defineQuery` and `defineMutation` bound to a specific `QueryClient`.\n *\n * Use this when you want a reusable query/mutation definition that carries\n * its own imperative query helpers (`.fetch`, `.ensure`) and callable mutation\n * execution powered by a specific client. For local one-shot options that only need\n * to flow into a framework hook, prefer `queryOptions` / `mutationOptions`\n * directly: those are platform-agnostic and do not require a `QueryClient`.\n *\n * Both `defineQuery` and `defineMutation` compose through `queryOptions` and\n * `mutationOptions`, so there is exactly one place that unwraps `Result`\n * into TanStack's throwing contract.\n *\n * @param queryClient - The TanStack `QueryClient` to bind imperative helpers to\n *\n * @example\n * ```ts\n * const queryClient = new QueryClient();\n * const { defineQuery, defineMutation } = createQueryFactories(queryClient);\n *\n * const userQuery = defineQuery({\n * queryKey: ['user', userId],\n * queryFn: () => services.getUser(userId),\n * });\n *\n * // Reactive\n * const query = createQuery(() => userQuery.options);\n *\n * // Imperative\n * const { data, error } = await userQuery.fetch();\n * ```\n */\nexport function createQueryFactories(queryClient: QueryClient) {\n\tconst defineQuery = <\n\t\tTQueryFnData = unknown,\n\t\tTError = DefaultError,\n\t\tTData = TQueryFnData,\n\t\tTQueryData = TQueryFnData,\n\t\tconst TQueryKey extends QueryKey = QueryKey,\n\t>(\n\t\tinput: QueryOptionsInput<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryData,\n\t\t\tTQueryKey\n\t\t>,\n\t): DefineQueryOutput<TQueryFnData, TError, TData, TQueryData, TQueryKey> => {\n\t\tconst options = queryOptions(input);\n\n\t\tasync function fetch(): Promise<Result<TQueryData, TError>> {\n\t\t\ttry {\n\t\t\t\treturn Ok(\n\t\t\t\t\tawait queryClient.fetchQuery<\n\t\t\t\t\t\tTQueryFnData,\n\t\t\t\t\t\tTError,\n\t\t\t\t\t\tTQueryData,\n\t\t\t\t\t\tTQueryKey\n\t\t\t\t\t>(options),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\tasync function ensure(): Promise<Result<TQueryData, TError>> {\n\t\t\ttry {\n\t\t\t\treturn Ok(\n\t\t\t\t\tawait queryClient.ensureQueryData<\n\t\t\t\t\t\tTQueryFnData,\n\t\t\t\t\t\tTError,\n\t\t\t\t\t\tTQueryData,\n\t\t\t\t\t\tTQueryKey\n\t\t\t\t\t>(options),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\toptions,\n\t\t\tfetch,\n\t\t\tensure,\n\t\t};\n\t};\n\n\tconst defineMutation = <\n\t\tTData,\n\t\tTError,\n\t\tTVariables = void,\n\t\tTContext = unknown,\n\t\tconst TMutationKey extends MutationKey = MutationKey,\n\t>(\n\t\tinput: MutationOptionsInput<\n\t\t\tTData,\n\t\t\tTError,\n\t\t\tTVariables,\n\t\t\tTContext,\n\t\t\tTMutationKey\n\t\t>,\n\t): DefineMutationOutput<TData, TError, TVariables, TContext> => {\n\t\tconst options = mutationOptions(input);\n\n\t\tasync function run(variables: TVariables) {\n\t\t\ttry {\n\t\t\t\treturn Ok(await runMutation(queryClient, options, variables));\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\treturn Object.assign(run, {\n\t\t\toptions,\n\t\t});\n\t};\n\n\treturn {\n\t\tdefineQuery,\n\t\tdefineMutation,\n\t};\n}\n\n/**\n * Internal helper that executes a mutation directly using the query client's\n * mutation cache. Powers the callable behavior on mutations returned from\n * `defineMutation`.\n *\n * @internal\n */\nfunction runMutation<TData, TError, TVariables, TContext>(\n\tqueryClient: QueryClient,\n\toptions: MutationOptions<TData, TError, TVariables, TContext>,\n\tvariables: TVariables,\n) {\n\tconst mutation = queryClient.getMutationCache().build(queryClient, options);\n\treturn mutation.execute(variables);\n}\n\n/**\n * Identity helper for declaring a TanStack Query key map while preserving\n * tuple types.\n *\n * - **Static entries** like `['users', 'active']` are narrowed to readonly\n * tuples with full literal precision (e.g. `readonly ['users', 'active']`)\n * via the `const` type parameter modifier. No per-line `as const` needed.\n *\n * - **Factory entries** like `(id: string) => ['users', id]` are narrowed to\n * tuple SHAPE (e.g. `[string, string]` with correct arity), not widened to\n * `string[]`. This happens because the strict tuple constraint provides\n * contextual typing into the function body. Literal positions still widen\n * without `as const` (TS does not propagate literal narrowing through\n * contextual typing). Add `as const` to the body when you need the literal:\n * `(id) => ['users', id] as const` -> `readonly ['users', string]`.\n *\n * Empty arrays and non-key values are rejected at the type level.\n *\n * @example\n * ```ts\n * const userKeys = defineKeys({\n * all: ['users'], // readonly ['users']\n * active: ['users', 'active'], // readonly ['users', 'active']\n * detail: (id: string) => ['users', id], // [string, string] (tuple shape kept)\n * page: (n: number) => ['users', n] as const, // readonly ['users', number]\n * });\n * ```\n */\nexport function defineKeys<\n\tconst TKeys extends Record<\n\t\tstring,\n\t\t| readonly [unknown, ...unknown[]]\n\t\t| ((...args: never[]) => readonly [unknown, ...unknown[]])\n\t>,\n>(keys: TKeys): TKeys {\n\treturn keys;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,aAOfA,OAC2E;AAC3E,QAAO;EACN,GAAG;EACH,SAAS,OAAO,YAAY,QAAQ,MAAM,MAAM,QAAQ,QAAQ,CAAC;CACjE;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,SAAgB,gBAOfC,OAO+D;AAC/D,QAAO;EACN,GAAG;EACH,YAAY,OAAOC,cAClB,QAAQ,MAAM,MAAM,WAAW,UAAU,CAAC;CAC3C;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8ED,SAAgB,qBAAqBC,aAA0B;CAC9D,MAAM,cAAc,CAOnBC,UAO2E;EAC3E,MAAM,UAAU,aAAa,MAAM;EAEnC,eAAe,QAA6C;AAC3D,OAAI;AACH,WAAO,GACN,MAAM,YAAY,WAKhB,QAAQ,CACV;GACD,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;EAED,eAAe,SAA8C;AAC5D,OAAI;AACH,WAAO,GACN,MAAM,YAAY,gBAKhB,QAAQ,CACV;GACD,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;AAED,SAAO;GACN;GACA;GACA;EACA;CACD;CAED,MAAM,iBAAiB,CAOtBC,UAO+D;EAC/D,MAAM,UAAU,gBAAgB,MAAM;EAEtC,eAAe,IAAIH,WAAuB;AACzC,OAAI;AACH,WAAO,GAAG,MAAM,YAAY,aAAa,SAAS,UAAU,CAAC;GAC7D,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;AAED,SAAO,OAAO,OAAO,KAAK,EACzB,QACA,EAAC;CACF;AAED,QAAO;EACN;EACA;CACA;AACD;;;;;;;;AASD,SAAS,YACRC,aACAG,SACAJ,WACC;CACD,MAAM,WAAW,YAAY,kBAAkB,CAAC,MAAM,aAAa,QAAQ;AAC3E,QAAO,SAAS,QAAQ,UAAU;AAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BD,SAAgB,WAMdK,MAAoB;AACrB,QAAO;AACP"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["input: QueryOptionsInput<TQueryFnData, TError, TData, TQueryData, TQueryKey>","input: MutationOptionsInput<\n\t\tTData,\n\t\tTError,\n\t\tTVariables,\n\t\tTContext,\n\t\tTMutationKey\n\t>","variables: TVariables","queryClient: QueryClient","input: QueryOptionsInput<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryData,\n\t\t\tTQueryKey\n\t\t>","input: MutationOptionsInput<\n\t\t\tTData,\n\t\t\tTError,\n\t\t\tTVariables,\n\t\t\tTContext,\n\t\t\tTMutationKey\n\t\t>","options: MutationOptions<TData, TError, TVariables, TContext>","keys: TKeys"],"sources":["../../src/query/utils.ts"],"sourcesContent":["import type {\n\tDefaultError,\n\tMutationKey,\n\tMutationObserverOptions,\n\tMutationOptions,\n\tQueryClient,\n\tQueryFunction,\n\tQueryKey,\n\tQueryObserverOptions,\n} from \"@tanstack/query-core\";\nimport { Err, Ok, type Result, resolve } from \"../result/index.js\";\n\n/**\n * Input for `resultQueryOptions` and `defineQuery`.\n *\n * Mirrors TanStack Query's `QueryObserverOptions` but expects `queryFn` to\n * return a Wellcrafted `Result`. The Result is unwrapped into TanStack's\n * throwing data/error contract by `resultQueryOptions`.\n *\n * @template TQueryFnData - The success type produced by `queryFn`\n * @template TError - The error type carried by the Result\n * @template TData - The type seen by consumers after `select`\n * @template TQueryData - The type stored in the cache (usually `TQueryFnData`)\n * @template TQueryKey - The literal query key tuple\n */\ntype QueryOptionsInput<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tTQueryKey extends QueryKey = QueryKey,\n> = Omit<\n\tQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n\t\"queryFn\"\n> & {\n\tqueryKey: TQueryKey;\n\tqueryFn: QueryFunction<Result<TQueryFnData, TError>, TQueryKey>;\n};\n\n/**\n * Input for `resultMutationOptions` and `defineMutation`.\n *\n * Mirrors TanStack Query's `MutationObserverOptions` but expects `mutationFn`\n * to return a Wellcrafted `Result`. The Result is unwrapped into TanStack's\n * throwing data/error contract by `resultMutationOptions`.\n *\n * @template TData - The success type produced by `mutationFn`\n * @template TError - The error type carried by the Result\n * @template TVariables - The variables passed to `mutationFn`\n * @template TContext - The context type for optimistic updates\n * @template TMutationKey - The literal mutation key tuple\n */\ntype MutationOptionsInput<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n\tTMutationKey extends MutationKey = MutationKey,\n> = Omit<\n\tMutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\"mutationFn\"\n> & {\n\tmutationKey: TMutationKey;\n\tmutationFn: (\n\t\tvariables: TVariables,\n\t) => Result<TData, TError> | Promise<Result<TData, TError>>;\n};\n\n/**\n * Adapter from a Result-returning query function to TanStack Query options.\n *\n * This is the single canonical place where `Result<TQueryFnData, TError>`\n * is converted into TanStack's contract: `Ok(data)` resolves with `data`,\n * `Err(error)` throws `error` into the query error channel.\n *\n * Use this directly with framework hooks when you do not need the\n * `QueryClient`-bound imperative helpers from `defineQuery`:\n *\n * ```ts\n * const query = createQuery(() => resultQueryOptions({\n * queryKey: ['user', userId],\n * queryFn: () => services.getUser(userId),\n * }));\n * ```\n *\n * `defineQuery` composes through this helper, so the `.options` it returns\n * is the same shape `resultQueryOptions` produces.\n *\n * @param input - Result-aware query configuration\n * @returns TanStack Query `QueryObserverOptions` with `queryFn` rewired to\n * resolve `Ok` and throw `Err`\n */\nexport function resultQueryOptions<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tconst TQueryKey extends QueryKey = QueryKey,\n>(\n\tinput: QueryOptionsInput<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n): QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {\n\treturn {\n\t\t...input,\n\t\tqueryFn: async (context) => resolve(await input.queryFn(context)),\n\t} satisfies QueryObserverOptions<\n\t\tTQueryFnData,\n\t\tTError,\n\t\tTData,\n\t\tTQueryData,\n\t\tTQueryKey\n\t>;\n}\n\n/**\n * Adapter from a Result-returning mutation function to TanStack Query options.\n *\n * This is the single canonical place where `Result<TData, TError>` is\n * converted into TanStack's contract: `Ok(data)` resolves with `data`,\n * `Err(error)` throws `error` into the mutation error channel.\n *\n * Use this directly with framework hooks when you do not need the\n * `QueryClient`-bound imperative helpers from `defineMutation`:\n *\n * ```ts\n * const save = createMutation(() => resultMutationOptions({\n * mutationKey: ['saveUser'],\n * mutationFn: (input: SaveUserInput) => services.saveUser(input),\n * }));\n * ```\n *\n * `defineMutation` composes through this helper, so the `.options` it\n * returns is the same shape `resultMutationOptions` produces.\n *\n * @param input - Result-aware mutation configuration\n * @returns TanStack Query `MutationObserverOptions` with `mutationFn` rewired\n * to resolve `Ok` and throw `Err`\n */\nexport function resultMutationOptions<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n\tconst TMutationKey extends MutationKey = MutationKey,\n>(\n\tinput: MutationOptionsInput<\n\t\tTData,\n\t\tTError,\n\t\tTVariables,\n\t\tTContext,\n\t\tTMutationKey\n\t>,\n): MutationObserverOptions<TData, TError, TVariables, TContext> {\n\treturn {\n\t\t...input,\n\t\tmutationFn: async (variables: TVariables) =>\n\t\t\tresolve(await input.mutationFn(variables)),\n\t} satisfies MutationObserverOptions<TData, TError, TVariables, TContext>;\n}\n\n/**\n * Output of `defineQuery`.\n *\n * Query imperative reads require an explicit cache policy.\n *\n * - `options`: Options shape produced by `resultQueryOptions`, ready for hooks.\n * - `fetch()`: Always evaluates freshness; refetches if stale.\n * - `ensure()`: Prefers cached data; fetches only when missing.\n */\ntype DefineQueryOutput<\n\tTQueryFnData = unknown,\n\tTError = DefaultError,\n\tTData = TQueryFnData,\n\tTQueryData = TQueryFnData,\n\tTQueryKey extends QueryKey = QueryKey,\n> = {\n\toptions: QueryObserverOptions<\n\t\tTQueryFnData,\n\t\tTError,\n\t\tTData,\n\t\tTQueryData,\n\t\tTQueryKey\n\t>;\n\tfetch: () => Promise<Result<TQueryData, TError>>;\n\tensure: () => Promise<Result<TQueryData, TError>>;\n};\n\n/**\n * Output of `defineMutation`.\n *\n * The returned function directly executes the mutation.\n *\n * - `(variables)` (callable): Imperatively runs the mutation, returning a Result.\n * - `options`: Options shape produced by `resultMutationOptions`, ready for hooks.\n */\ntype DefineMutationOutput<\n\tTData,\n\tTError,\n\tTVariables = void,\n\tTContext = unknown,\n> = ((variables: TVariables) => Promise<Result<TData, TError>>) & {\n\toptions: MutationObserverOptions<TData, TError, TVariables, TContext>;\n};\n\n/**\n * Creates `defineQuery` and `defineMutation` bound to a specific `QueryClient`.\n *\n * Use this when you want a reusable query/mutation definition that carries\n * its own imperative query helpers (`.fetch`, `.ensure`) and callable mutation\n * execution powered by a specific client. For local one-shot options that only need\n * to flow into a framework hook, prefer `resultQueryOptions` / `resultMutationOptions`\n * directly: those are platform-agnostic and do not require a `QueryClient`.\n *\n * Both `defineQuery` and `defineMutation` compose through `resultQueryOptions` and\n * `resultMutationOptions`, so there is exactly one place that unwraps `Result`\n * into TanStack's throwing contract.\n *\n * @param queryClient - The TanStack `QueryClient` to bind imperative helpers to\n *\n * @example\n * ```ts\n * const queryClient = new QueryClient();\n * const { defineQuery, defineMutation } = createQueryFactories(queryClient);\n *\n * const userQuery = defineQuery({\n * queryKey: ['user', userId],\n * queryFn: () => services.getUser(userId),\n * });\n *\n * // Reactive\n * const query = createQuery(() => userQuery.options);\n *\n * // Imperative\n * const { data, error } = await userQuery.fetch();\n * ```\n */\nexport function createQueryFactories(queryClient: QueryClient) {\n\tconst defineQuery = <\n\t\tTQueryFnData = unknown,\n\t\tTError = DefaultError,\n\t\tTData = TQueryFnData,\n\t\tTQueryData = TQueryFnData,\n\t\tconst TQueryKey extends QueryKey = QueryKey,\n\t>(\n\t\tinput: QueryOptionsInput<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryData,\n\t\t\tTQueryKey\n\t\t>,\n\t): DefineQueryOutput<TQueryFnData, TError, TData, TQueryData, TQueryKey> => {\n\t\tconst options = resultQueryOptions(input);\n\n\t\tasync function fetch(): Promise<Result<TQueryData, TError>> {\n\t\t\ttry {\n\t\t\t\treturn Ok(\n\t\t\t\t\tawait queryClient.fetchQuery<\n\t\t\t\t\t\tTQueryFnData,\n\t\t\t\t\t\tTError,\n\t\t\t\t\t\tTQueryData,\n\t\t\t\t\t\tTQueryKey\n\t\t\t\t\t>(options),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\tasync function ensure(): Promise<Result<TQueryData, TError>> {\n\t\t\ttry {\n\t\t\t\treturn Ok(\n\t\t\t\t\tawait queryClient.ensureQueryData<\n\t\t\t\t\t\tTQueryFnData,\n\t\t\t\t\t\tTError,\n\t\t\t\t\t\tTQueryData,\n\t\t\t\t\t\tTQueryKey\n\t\t\t\t\t>(options),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\toptions,\n\t\t\tfetch,\n\t\t\tensure,\n\t\t};\n\t};\n\n\tconst defineMutation = <\n\t\tTData,\n\t\tTError,\n\t\tTVariables = void,\n\t\tTContext = unknown,\n\t\tconst TMutationKey extends MutationKey = MutationKey,\n\t>(\n\t\tinput: MutationOptionsInput<\n\t\t\tTData,\n\t\t\tTError,\n\t\t\tTVariables,\n\t\t\tTContext,\n\t\t\tTMutationKey\n\t\t>,\n\t): DefineMutationOutput<TData, TError, TVariables, TContext> => {\n\t\tconst options = resultMutationOptions(input);\n\n\t\tasync function run(variables: TVariables) {\n\t\t\ttry {\n\t\t\t\treturn Ok(await runMutation(queryClient, options, variables));\n\t\t\t} catch (error) {\n\t\t\t\treturn Err(error as TError);\n\t\t\t}\n\t\t}\n\n\t\treturn Object.assign(run, {\n\t\t\toptions,\n\t\t});\n\t};\n\n\treturn {\n\t\tdefineQuery,\n\t\tdefineMutation,\n\t};\n}\n\n/**\n * Internal helper that executes a mutation directly using the query client's\n * mutation cache. Powers the callable behavior on mutations returned from\n * `defineMutation`.\n *\n * @internal\n */\nfunction runMutation<TData, TError, TVariables, TContext>(\n\tqueryClient: QueryClient,\n\toptions: MutationOptions<TData, TError, TVariables, TContext>,\n\tvariables: TVariables,\n) {\n\tconst mutation = queryClient.getMutationCache().build(queryClient, options);\n\treturn mutation.execute(variables);\n}\n\n/**\n * Identity helper for declaring a TanStack Query key map while preserving\n * tuple types.\n *\n * - **Static entries** like `['users', 'active']` are narrowed to readonly\n * tuples with full literal precision (e.g. `readonly ['users', 'active']`)\n * via the `const` type parameter modifier. No per-line `as const` needed.\n *\n * - **Factory entries** like `(id: string) => ['users', id]` are narrowed to\n * tuple SHAPE (e.g. `[string, string]` with correct arity), not widened to\n * `string[]`. This happens because the strict tuple constraint provides\n * contextual typing into the function body. Literal positions still widen\n * without `as const` (TS does not propagate literal narrowing through\n * contextual typing). Add `as const` to the body when you need the literal:\n * `(id) => ['users', id] as const` -> `readonly ['users', string]`.\n *\n * Empty arrays and non-key values are rejected at the type level.\n *\n * @example\n * ```ts\n * const userKeys = defineKeys({\n * all: ['users'], // readonly ['users']\n * active: ['users', 'active'], // readonly ['users', 'active']\n * detail: (id: string) => ['users', id], // [string, string] (tuple shape kept)\n * page: (n: number) => ['users', n] as const, // readonly ['users', number]\n * });\n * ```\n */\nexport function defineKeys<\n\tconst TKeys extends Record<\n\t\tstring,\n\t\t| readonly [unknown, ...unknown[]]\n\t\t| ((...args: never[]) => readonly [unknown, ...unknown[]])\n\t>,\n>(keys: TKeys): TKeys {\n\treturn keys;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,mBAOfA,OAC2E;AAC3E,QAAO;EACN,GAAG;EACH,SAAS,OAAO,YAAY,QAAQ,MAAM,MAAM,QAAQ,QAAQ,CAAC;CACjE;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,SAAgB,sBAOfC,OAO+D;AAC/D,QAAO;EACN,GAAG;EACH,YAAY,OAAOC,cAClB,QAAQ,MAAM,MAAM,WAAW,UAAU,CAAC;CAC3C;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8ED,SAAgB,qBAAqBC,aAA0B;CAC9D,MAAM,cAAc,CAOnBC,UAO2E;EAC3E,MAAM,UAAU,mBAAmB,MAAM;EAEzC,eAAe,QAA6C;AAC3D,OAAI;AACH,WAAO,GACN,MAAM,YAAY,WAKhB,QAAQ,CACV;GACD,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;EAED,eAAe,SAA8C;AAC5D,OAAI;AACH,WAAO,GACN,MAAM,YAAY,gBAKhB,QAAQ,CACV;GACD,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;AAED,SAAO;GACN;GACA;GACA;EACA;CACD;CAED,MAAM,iBAAiB,CAOtBC,UAO+D;EAC/D,MAAM,UAAU,sBAAsB,MAAM;EAE5C,eAAe,IAAIH,WAAuB;AACzC,OAAI;AACH,WAAO,GAAG,MAAM,YAAY,aAAa,SAAS,UAAU,CAAC;GAC7D,SAAQ,OAAO;AACf,WAAO,IAAI,MAAgB;GAC3B;EACD;AAED,SAAO,OAAO,OAAO,KAAK,EACzB,QACA,EAAC;CACF;AAED,QAAO;EACN;EACA;CACA;AACD;;;;;;;;AASD,SAAS,YACRC,aACAG,SACAJ,WACC;CACD,MAAM,WAAW,YAAY,kBAAkB,CAAC,MAAM,aAAa,QAAQ;AAC3E,QAAO,SAAS,QAAQ,UAAU;AAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BD,SAAgB,WAMdK,MAAoB;AACrB,QAAO;AACP"}
|
package/dist/result/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Err, Ok, Result, UnwrapErr, UnwrapOk, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap } from "../result-
|
|
2
|
-
import { tapErr } from "../tap-err-
|
|
3
|
-
import { partitionResults } from "../index-
|
|
1
|
+
import { Err, Ok, Result, UnwrapErr, UnwrapOk, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap } from "../result-_socO0Ud.js";
|
|
2
|
+
import { tapErr } from "../tap-err-C0xfVXtz.js";
|
|
3
|
+
import { partitionResults } from "../index-D0f5JWiT.js";
|
|
4
4
|
export { Err, Ok, Result, UnwrapErr, UnwrapOk, isErr, isOk, isResult, partitionResults, resolve, tapErr, tryAsync, trySync, unwrap };
|
package/dist/result/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Err, Ok, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap } from "../result-
|
|
2
|
-
import { tapErr } from "../tap-err-
|
|
3
|
-
import { partitionResults } from "../result-
|
|
1
|
+
import { Err, Ok, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap } from "../result-C_ph_izC.js";
|
|
2
|
+
import { tapErr } from "../tap-err-BENAkFsH.js";
|
|
3
|
+
import { partitionResults } from "../result-pV2mfn0W.js";
|
|
4
4
|
|
|
5
5
|
export { Err, Ok, isErr, isOk, isResult, partitionResults, resolve, tapErr, tryAsync, trySync, unwrap };
|
|
@@ -23,7 +23,7 @@ const Ok = (data) => ({
|
|
|
23
23
|
*
|
|
24
24
|
* Wraps the provided `error` (the failure value) and sets `data` to `null`.
|
|
25
25
|
*
|
|
26
|
-
* **Don't call `Err(null)`.** It produces `{ data: null, error: null }
|
|
26
|
+
* **Don't call `Err(null)`.** It produces `{ data: null, error: null }`,
|
|
27
27
|
* structurally identical to `Ok(null)`. The built-in `isErr` check
|
|
28
28
|
* (`result.error !== null`) reads it as Ok, silently misclassifying your
|
|
29
29
|
* failure as success. `Err(undefined)` is also discouraged: the discriminator
|
|
@@ -34,9 +34,9 @@ const Ok = (data) => ({
|
|
|
34
34
|
* what you meant was success-with-no-payload.
|
|
35
35
|
*
|
|
36
36
|
* At `catch (error: unknown)` boundaries, wrap the caught value in a tagged
|
|
37
|
-
* error rather than passing it through
|
|
38
|
-
* is always non-null by construction,
|
|
39
|
-
* of what was thrown.
|
|
37
|
+
* error rather than passing it through. A `defineErrors` factory like
|
|
38
|
+
* `MyError.Unexpected({ cause: error })` is always non-null by construction,
|
|
39
|
+
* so the discriminator works regardless of what was thrown.
|
|
40
40
|
*
|
|
41
41
|
* See `docs/philosophy/err-null-is-ok-null.md` for the full rationale.
|
|
42
42
|
*
|
|
@@ -361,4 +361,4 @@ function resolve(value) {
|
|
|
361
361
|
|
|
362
362
|
//#endregion
|
|
363
363
|
export { Err, Ok, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap };
|
|
364
|
-
//# sourceMappingURL=result-
|
|
364
|
+
//# sourceMappingURL=result-C_ph_izC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-C_ph_izC.js","names":["data: T","error: E","value: unknown","result: Result<T, E>","value: T | Result<T, E>"],"sources":["../src/result/result.ts"],"sourcesContent":["/**\n * Represents the successful outcome of an operation, encapsulating the success value.\n *\n * This is the 'Ok' variant of the `Result` type. It holds a `data` property\n * of type `T` (the success value) and an `error` property explicitly set to `null`,\n * signifying no error occurred.\n *\n * Use this type in conjunction with `Err<E>` and `Result<T, E>`.\n *\n * @template T - The type of the success value contained within.\n */\nexport type Ok<T> = { data: T; error: null };\n\n/**\n * Represents the failure outcome of an operation, encapsulating the error value.\n *\n * This is the 'Err' variant of the `Result` type. It holds an `error` property\n * of type `E` (the error value) and a `data` property explicitly set to `null`,\n * signifying that no success value is present due to the failure.\n *\n * Use this type in conjunction with `Ok<T>` and `Result<T, E>`.\n *\n * @template E - The type of the error value contained within.\n */\nexport type Err<E> = { error: E; data: null };\n\n/**\n * A type that represents the outcome of an operation that can either succeed or fail.\n *\n * `Result<T, E>` is a discriminated union type with two possible variants:\n * - `Ok<T>`: Represents a successful outcome, containing a `data` field with the success value of type `T`.\n * In this case, the `error` field is `null`.\n * - `Err<E>`: Represents a failure outcome, containing an `error` field with the error value of type `E`.\n * In this case, the `data` field is `null`.\n *\n * This type promotes explicit error handling by requiring developers to check\n * the variant of the `Result` before accessing its potential value or error.\n * It helps avoid runtime errors often associated with implicit error handling (e.g., relying on `try-catch` for all errors).\n *\n * @template T - The type of the success value if the operation is successful (held in `Ok<T>`).\n * @template E - The type of the error value if the operation fails (held in `Err<E>`).\n * @example\n * ```ts\n * function divide(numerator: number, denominator: number): Result<number, string> {\n * if (denominator === 0) {\n * return Err(\"Cannot divide by zero\");\n * }\n * return Ok(numerator / denominator);\n * }\n *\n * const result1 = divide(10, 2);\n * if (isOk(result1)) {\n * console.log(\"Success:\", result1.data); // Output: Success: 5\n * }\n *\n * const result2 = divide(10, 0);\n * if (isErr(result2)) {\n * console.error(\"Failure:\", result2.error); // Output: Failure: Cannot divide by zero\n * }\n * ```\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Constructs an `Ok<T>` variant, representing a successful outcome.\n *\n * This factory function creates the success variant of a `Result`.\n * It wraps the provided `data` (the success value) and ensures the `error` property is `null`.\n *\n * @template T - The type of the success value.\n * @param data - The success value to be wrapped in the `Ok` variant.\n * @returns An `Ok<T>` object with the provided data and `error` set to `null`.\n * @example\n * ```ts\n * const successfulResult = Ok(\"Operation completed successfully\");\n * // successfulResult is { data: \"Operation completed successfully\", error: null }\n * ```\n */\nexport const Ok = <T>(data: T): Ok<T> => ({ data, error: null });\n\n/**\n * Constructs an `Err<E>` variant, representing a failure outcome.\n *\n * Wraps the provided `error` (the failure value) and sets `data` to `null`.\n *\n * **Don't call `Err(null)`.** It produces `{ data: null, error: null }`,\n * structurally identical to `Ok(null)`. The built-in `isErr` check\n * (`result.error !== null`) reads it as Ok, silently misclassifying your\n * failure as success. `Err(undefined)` is also discouraged: the discriminator\n * technically works (`undefined !== null`), but `undefined` is falsy, so\n * downstream `if (error)` checks trip and the error carries no information\n * anyway. Pass a meaningful error value (a string, a tagged error from\n * `defineErrors`, an `Error` instance), or use `Ok(null)`/`Ok(undefined)` if\n * what you meant was success-with-no-payload.\n *\n * At `catch (error: unknown)` boundaries, wrap the caught value in a tagged\n * error rather than passing it through. A `defineErrors` factory like\n * `MyError.Unexpected({ cause: error })` is always non-null by construction,\n * so the discriminator works regardless of what was thrown.\n *\n * See `docs/philosophy/err-null-is-ok-null.md` for the full rationale.\n *\n * @template E - The type of the error value.\n * @param error - The error value to wrap. Don't pass `null` or `undefined`.\n * @returns An `Err<E>` object with the provided error and `data` set to `null`.\n * @example\n * ```ts\n * const failedResult = Err(new TypeError(\"Invalid input\"));\n * // failedResult is { error: TypeError(\"Invalid input\"), data: null }\n * ```\n */\nexport const Err = <E>(error: E): Err<E> => ({ error, data: null });\n\n/**\n * Utility type to extract the success value's type `T` from a `Result<T, E>` type.\n *\n * If `R` is an `Ok<T>` variant (or a `Result<T, E>` that could be an `Ok<T>`),\n * this type resolves to `T`. If `R` can only be an `Err<E>` variant, it resolves to `never`.\n * This is useful for obtaining the type of the `data` field when you know you have a success.\n *\n * @template R - The `Result<T, E>` type from which to extract the success value's type.\n * Must extend `Result<unknown, unknown>`.\n * @example\n * ```ts\n * type MyResult = Result<number, string>;\n * type SuccessValueType = UnwrapOk<MyResult>; // SuccessValueType is number\n *\n * type MyErrorResult = Err<string>;\n * type ErrorValueType = UnwrapOk<MyErrorResult>; // ErrorValueType is never\n * ```\n */\nexport type UnwrapOk<R extends Result<unknown, unknown>> = R extends Ok<infer U>\n\t? U\n\t: never;\n\n/**\n * Utility type to extract the error value's type `E` from a `Result<T, E>` type.\n *\n * If `R` is an `Err<E>` variant (or a `Result<T, E>` that could be an `Err<E>`),\n * this type resolves to `E`. If `R` can only be an `Ok<T>` variant, it resolves to `never`.\n * This is useful for obtaining the type of the `error` field when you know you have a failure.\n *\n * @template R - The `Result<T, E>` type from which to extract the error value's type.\n * Must extend `Result<unknown, unknown>`.\n * @example\n * ```ts\n * type MyResult = Result<number, string>;\n * type ErrorValueType = UnwrapErr<MyResult>; // ErrorValueType is string\n *\n * type MySuccessResult = Ok<number>;\n * type SuccessValueType = UnwrapErr<MySuccessResult>; // SuccessValueType is never\n * ```\n */\nexport type UnwrapErr<R extends Result<unknown, unknown>> = R extends Err<\n\tinfer E\n>\n\t? E\n\t: never;\n\n/**\n * Type guard to runtime check if an unknown value is a valid `Result<T, E>`.\n *\n * A value is considered a valid `Result` if:\n * 1. It is a non-null object.\n * 2. It has both `data` and `error` properties.\n *\n * The `error` property is the runtime discriminant:\n * - `error === null` represents `Ok<T>`, even when `data` is also `null` (`Ok(null)`).\n * - `error !== null` represents `Err<E>`, even if external data also includes a non-null `data` value.\n *\n * This function checks only the Result shape. It does not validate the\n * success or error payload types.\n *\n * @template T - The expected type of the success value if the value is an `Ok` variant (defaults to `unknown`).\n * @template E - The expected type of the error value if the value is an `Err` variant (defaults to `unknown`).\n * @param value - The value to check.\n * @returns `true` if the value conforms to the `Result` structure, `false` otherwise.\n * If `true`, TypeScript's type system will narrow `value` to `Result<T, E>`.\n * @example\n * ```ts\n * declare const someValue: unknown;\n *\n * if (isResult<string, Error>(someValue)) {\n * // someValue is now typed as Result<string, Error>\n * if (isOk(someValue)) {\n * console.log(someValue.data); // string\n * } else {\n * console.error(someValue.error); // Error\n * }\n * }\n * ```\n */\nexport function isResult<T = unknown, E = unknown>(\n\tvalue: unknown,\n): value is Result<T, E> {\n\tconst isNonNullObject = typeof value === \"object\" && value !== null;\n\tif (!isNonNullObject) return false;\n\n\tconst hasDataProperty = \"data\" in value;\n\tconst hasErrorProperty = \"error\" in value;\n\tif (!hasDataProperty || !hasErrorProperty) return false;\n\n\treturn true;\n}\n\n/**\n * Type guard to runtime check if a `Result<T, E>` is an `Ok<T>` variant.\n *\n * This function narrows the type of a `Result` to `Ok<T>` if it represents a successful outcome.\n * An `Ok<T>` variant is identified by its `error` property being `null`.\n *\n * @template T - The success value type.\n * @template E - The error value type.\n * @param result - The `Result<T, E>` to check.\n * @returns `true` if the `result` is an `Ok<T>` variant, `false` otherwise.\n * If `true`, TypeScript's type system will narrow `result` to `Ok<T>`.\n * @example\n * ```ts\n * declare const myResult: Result<number, string>;\n *\n * if (isOk(myResult)) {\n * // myResult is now typed as Ok<number>\n * console.log(\"Success value:\", myResult.data); // myResult.data is number\n * }\n * ```\n */\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T> {\n\treturn result.error === null;\n}\n\n/**\n * Type guard to runtime check if a `Result<T, E>` is an `Err<E>` variant.\n *\n * This function narrows the type of a `Result` to `Err<E>` if it represents a failure outcome.\n * An `Err<E>` variant is identified by its `error` property being non-`null`.\n * The error side is the reliable discriminator because `Ok(null)` is valid.\n *\n * @template T - The success value type.\n * @template E - The error value type.\n * @param result - The `Result<T, E>` to check.\n * @returns `true` if the `result` is an `Err<E>` variant, `false` otherwise.\n * If `true`, TypeScript's type system will narrow `result` to `Err<E>`.\n * @example\n * ```ts\n * declare const myResult: Result<number, string>;\n *\n * if (isErr(myResult)) {\n * // myResult is now typed as Err<string>\n * console.error(\"Error value:\", myResult.error); // myResult.error is string\n * }\n * ```\n */\nexport function isErr<T, E>(result: Result<T, E>): result is Err<E> {\n\treturn result.error !== null;\n}\n\n/**\n * Executes a synchronous operation and wraps its outcome in a Result type.\n *\n * This function attempts to execute the `try` operation:\n * - If the `try` operation completes successfully, its return value is wrapped in an `Ok<T>` variant.\n * - If the `try` operation throws an exception, the caught exception (of type `unknown`) is passed to\n * the `catch` function, which transforms it into either an `Ok<T>` (recovery) or `Err<E>` (propagation).\n *\n * The return type is automatically determined by what your catch function returns:\n * - If catch always returns `Ok<T>`, the return type collapses to `Ok<T>` (guaranteed success)\n * - If catch always returns `Err<E>`, the return type is `Ok<T> | Err<E>` (may succeed or fail)\n * - If catch returns a union like `Err<A> | Err<B>`, the return type is `Ok<T> | Err<A> | Err<B>` (union propagation)\n * - If catch can return either `Ok<T>` or `Err<E>`, the return type is `Ok<T> | Err<E>` (conditional recovery)\n *\n * @template T - The success value type\n * @template R - The return type of the catch handler (`Ok<T>` for recovery, `Err<E>` for propagation, or a union)\n * @param options - Configuration object\n * @param options.try - The operation to execute\n * @param options.catch - Error handler that transforms caught exceptions into either `Ok<T>` (recovery) or `Err<E>` (propagation)\n * @returns `Ok<T> | R` — the union of the success path and whatever the catch handler returns\n *\n * @example\n * ```ts\n * // Returns Ok<string> - guaranteed success since catch always returns Ok\n * const alwaysOk = trySync({\n * try: () => JSON.parse(input),\n * catch: () => Ok(\"fallback\") // Always Ok<T>\n * });\n *\n * // Returns Result<object, string> - may fail since catch always returns Err\n * const mayFail = trySync({\n * try: () => JSON.parse(input),\n * catch: (err) => Err(\"Parse failed\") // Returns Err<E>\n * });\n *\n * // Returns Result<void, MyError> - conditional recovery based on error type\n * const conditional = trySync({\n * try: () => riskyOperation(),\n * catch: (err) => {\n * if (isRecoverable(err)) return Ok(undefined);\n * return MyErr({ message: \"Unrecoverable\" });\n * }\n * });\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: required for union type inference in catch handlers\nexport function trySync<T, R extends Ok<T> | Err<any>>({\n\ttry: operation,\n\tcatch: catchFn,\n}: {\n\ttry: () => T;\n\tcatch: (error: unknown) => R;\n}): Ok<T> | R {\n\ttry {\n\t\tconst data = operation();\n\t\treturn Ok(data);\n\t} catch (error) {\n\t\treturn catchFn(error);\n\t}\n}\n\n/**\n * Executes an asynchronous operation and wraps its outcome in a Promise<Result>.\n *\n * This function attempts to execute the `try` operation:\n * - If the `try` operation resolves successfully, its resolved value is wrapped in an `Ok<T>` variant.\n * - If the `try` operation rejects or throws an exception, the caught error (of type `unknown`) is passed to\n * the `catch` function, which transforms it into either an `Ok<T>` (recovery) or `Err<E>` (propagation).\n *\n * The return type is automatically determined by what your catch function returns:\n * - If catch always returns `Ok<T>`, the return type collapses to `Promise<Ok<T>>` (guaranteed success)\n * - If catch always returns `Err<E>`, the return type is `Promise<Ok<T> | Err<E>>` (may succeed or fail)\n * - If catch returns a union like `Err<A> | Err<B>`, the return type is `Promise<Ok<T> | Err<A> | Err<B>>` (union propagation)\n * - If catch can return either `Ok<T>` or `Err<E>`, the return type is `Promise<Ok<T> | Err<E>>` (conditional recovery)\n *\n * @template T - The success value type\n * @template R - The return type of the catch handler (`Ok<T>` for recovery, `Err<E>` for propagation, or a union)\n * @param options - Configuration object\n * @param options.try - The async operation to execute\n * @param options.catch - Error handler that transforms caught exceptions/rejections into either `Ok<T>` (recovery) or `Err<E>` (propagation)\n * @returns `Promise<Ok<T> | R>` — the union of the success path and whatever the catch handler returns\n *\n * @example\n * ```ts\n * // Returns Promise<Ok<Response>> - guaranteed success since catch always returns Ok\n * const alwaysOk = tryAsync({\n * try: async () => fetch(url),\n * catch: () => Ok(new Response()) // Always Ok<T>\n * });\n *\n * // Returns Promise<Result<Response, Error>> - may fail since catch always returns Err\n * const mayFail = tryAsync({\n * try: async () => fetch(url),\n * catch: (err) => Err(new Error(\"Fetch failed\")) // Returns Err<E>\n * });\n *\n * // Returns Promise<Result<void, BlobError>> - conditional recovery based on error type\n * const conditional = await tryAsync({\n * try: async () => {\n * await deleteFile(filename);\n * },\n * catch: (err) => {\n * if ((err as { name?: string }).name === 'NotFoundError') {\n * return Ok(undefined); // Already deleted, that's fine\n * }\n * return BlobErr({ message: \"Delete failed\" });\n * }\n * });\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: required for union type inference in catch handlers\nexport async function tryAsync<T, R extends Ok<T> | Err<any>>({\n\ttry: operation,\n\tcatch: catchFn,\n}: {\n\ttry: () => Promise<T>;\n\tcatch: (error: unknown) => R;\n}): Promise<Ok<T> | R> {\n\ttry {\n\t\tconst data = await operation();\n\t\treturn Ok(data);\n\t} catch (error) {\n\t\treturn catchFn(error);\n\t}\n}\n\n/**\n * Resolves a value that may or may not be wrapped in a `Result`, returning the final value.\n *\n * This function handles the common pattern where a value might be a `Result<T, E>` or a plain `T`:\n * - If `value` is an `Ok<T>` variant, returns the contained success value.\n * - If `value` is an `Err<E>` variant, throws the contained error value.\n * - If `value` is not a `Result` (i.e., it's already a plain value of type `T`),\n * returns it as-is.\n *\n * This is useful when working with APIs that might return either direct values or Results,\n * allowing you to normalize them to the actual value or propagate errors via throwing.\n *\n * Use `resolve` when the input might or might not be a Result.\n * Use `unwrap` when you know the input is definitely a Result.\n *\n * @template T - The type of the success value (if `value` is `Ok<T>`) or the type of the plain value.\n * @template E - The type of the error value (if `value` is `Err<E>`).\n * @param value - The value to resolve. Can be a `Result<T, E>` or a plain value of type `T`.\n * @returns The final value of type `T` if `value` is `Ok<T>` or if `value` is already a plain `T`.\n * @throws The error value `E` if `value` is an `Err<E>` variant.\n *\n * @example\n * ```ts\n * // Example with an Ok variant\n * const okResult = Ok(\"success data\");\n * const resolved = resolve(okResult); // \"success data\"\n *\n * // Example with an Err variant\n * const errResult = Err(new Error(\"failure\"));\n * try {\n * resolve(errResult);\n * } catch (e) {\n * console.error(e.message); // \"failure\"\n * }\n *\n * // Example with a plain value\n * const plainValue = \"plain data\";\n * const resolved = resolve(plainValue); // \"plain data\"\n *\n * // Example with a function that might return Result or plain value\n * declare function mightReturnResult(): string | Result<string, Error>;\n * const outcome = mightReturnResult();\n * try {\n * const finalValue = resolve(outcome); // handles both cases\n * console.log(\"Final value:\", finalValue);\n * } catch (e) {\n * console.error(\"Operation failed:\", e);\n * }\n * ```\n */\n/**\n * Unwraps a `Result<T, E>`, returning the success value or throwing the error.\n *\n * This function extracts the data from a `Result`:\n * - If the `Result` is an `Ok<T>` variant, returns the contained success value of type `T`.\n * - If the `Result` is an `Err<E>` variant, throws the contained error value of type `E`.\n *\n * Unlike `resolve`, this function expects the input to always be a `Result` type,\n * making it more direct for cases where you know you're working with a `Result`.\n *\n * @template T - The type of the success value contained in the `Ok<T>` variant.\n * @template E - The type of the error value contained in the `Err<E>` variant.\n * @param result - The `Result<T, E>` to unwrap.\n * @returns The success value of type `T` if the `Result` is `Ok<T>`.\n * @throws The error value of type `E` if the `Result` is `Err<E>`.\n *\n * @example\n * ```ts\n * // Example with an Ok variant\n * const okResult = Ok(\"success data\");\n * const value = unwrap(okResult); // \"success data\"\n *\n * // Example with an Err variant\n * const errResult = Err(new Error(\"something went wrong\"));\n * try {\n * unwrap(errResult);\n * } catch (error) {\n * console.error(error.message); // \"something went wrong\"\n * }\n *\n * // Usage in a function that returns Result\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) return Err(\"Division by zero\");\n * return Ok(a / b);\n * }\n *\n * try {\n * const result = unwrap(divide(10, 2)); // 5\n * console.log(\"Result:\", result);\n * } catch (error) {\n * console.error(\"Division failed:\", error);\n * }\n * ```\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n\tif (isOk(result)) {\n\t\treturn result.data;\n\t}\n\tthrow result.error;\n}\n\nexport function resolve<T, E>(value: T | Result<T, E>): T {\n\tif (isResult<T, E>(value)) {\n\t\tif (isOk(value)) {\n\t\t\treturn value.data;\n\t\t}\n\t\t// If it's a Result and not Ok, it must be Err.\n\t\t// The type guard isResult<T,E>(value) and isOk(value) already refine the type.\n\t\t// So, 'value' here is known to be Err<E>.\n\t\tthrow value.error;\n\t}\n\n\t// If it's not a Result type, return the value as-is.\n\t// 'value' here is known to be of type T.\n\treturn value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8EA,MAAa,KAAK,CAAIA,UAAoB;CAAE;CAAM,OAAO;AAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiC/D,MAAa,MAAM,CAAIC,WAAsB;CAAE;CAAO,MAAM;AAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFlE,SAAgB,SACfC,OACwB;CACxB,MAAM,yBAAyB,UAAU,YAAY,UAAU;AAC/D,MAAK,gBAAiB,QAAO;CAE7B,MAAM,kBAAkB,UAAU;CAClC,MAAM,mBAAmB,WAAW;AACpC,MAAK,oBAAoB,iBAAkB,QAAO;AAElD,QAAO;AACP;;;;;;;;;;;;;;;;;;;;;;AAuBD,SAAgB,KAAWC,QAAuC;AACjE,QAAO,OAAO,UAAU;AACxB;;;;;;;;;;;;;;;;;;;;;;;AAwBD,SAAgB,MAAYA,QAAwC;AACnE,QAAO,OAAO,UAAU;AACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDD,SAAgB,QAAuC,EACtD,KAAK,WACL,OAAO,SAIP,EAAa;AACb,KAAI;EACH,MAAM,OAAO,WAAW;AACxB,SAAO,GAAG,KAAK;CACf,SAAQ,OAAO;AACf,SAAO,QAAQ,MAAM;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDD,eAAsB,SAAwC,EAC7D,KAAK,WACL,OAAO,SAIP,EAAsB;AACtB,KAAI;EACH,MAAM,OAAO,MAAM,WAAW;AAC9B,SAAO,GAAG,KAAK;CACf,SAAQ,OAAO;AACf,SAAO,QAAQ,MAAM;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGD,SAAgB,OAAaA,QAAyB;AACrD,KAAI,KAAK,OAAO,CACf,QAAO,OAAO;AAEf,OAAM,OAAO;AACb;AAED,SAAgB,QAAcC,OAA4B;AACzD,KAAI,SAAe,MAAM,EAAE;AAC1B,MAAI,KAAK,MAAM,CACd,QAAO,MAAM;AAKd,QAAM,MAAM;CACZ;AAID,QAAO;AACP"}
|
|
@@ -86,7 +86,7 @@ declare const Ok: <T>(data: T) => Ok<T>;
|
|
|
86
86
|
*
|
|
87
87
|
* Wraps the provided `error` (the failure value) and sets `data` to `null`.
|
|
88
88
|
*
|
|
89
|
-
* **Don't call `Err(null)`.** It produces `{ data: null, error: null }
|
|
89
|
+
* **Don't call `Err(null)`.** It produces `{ data: null, error: null }`,
|
|
90
90
|
* structurally identical to `Ok(null)`. The built-in `isErr` check
|
|
91
91
|
* (`result.error !== null`) reads it as Ok, silently misclassifying your
|
|
92
92
|
* failure as success. `Err(undefined)` is also discouraged: the discriminator
|
|
@@ -97,9 +97,9 @@ declare const Ok: <T>(data: T) => Ok<T>;
|
|
|
97
97
|
* what you meant was success-with-no-payload.
|
|
98
98
|
*
|
|
99
99
|
* At `catch (error: unknown)` boundaries, wrap the caught value in a tagged
|
|
100
|
-
* error rather than passing it through
|
|
101
|
-
* is always non-null by construction,
|
|
102
|
-
* of what was thrown.
|
|
100
|
+
* error rather than passing it through. A `defineErrors` factory like
|
|
101
|
+
* `MyError.Unexpected({ cause: error })` is always non-null by construction,
|
|
102
|
+
* so the discriminator works regardless of what was thrown.
|
|
103
103
|
*
|
|
104
104
|
* See `docs/philosophy/err-null-is-ok-null.md` for the full rationale.
|
|
105
105
|
*
|
|
@@ -437,4 +437,4 @@ declare function resolve<T, E>(value: T | Result<T, E>): T;
|
|
|
437
437
|
//# sourceMappingURL=result.d.ts.map
|
|
438
438
|
//#endregion
|
|
439
439
|
export { Err, Ok, Result, UnwrapErr, UnwrapOk, isErr, isOk, isResult, resolve, tryAsync, trySync, unwrap };
|
|
440
|
-
//# sourceMappingURL=result-
|
|
440
|
+
//# sourceMappingURL=result-_socO0Ud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-
|
|
1
|
+
{"version":3,"file":"result-_socO0Ud.d.ts","names":[],"sources":["../src/result/result.ts"],"sourcesContent":[],"mappings":";;AAWA;AAaA;AAqCA;;;;;;AAAsC;AAiBtC;AAAgE,KAnEpD,EAmEoD,CAAA,CAAA,CAAA,GAAA;EAAA,IAApC,EAnEA,CAmEA;EAAC,KAAM,EAAA,IAAA;CAAC;AAAF;AAiClC;;;;;AAAqC;AAoBrC;;;;AAAqE,KA3GzD,GA2GyD,CAAA,CAAA,CAAA,GAAA;EAAE,KACpE,EA5G2B,CA4G3B;EAAC,IAAA,EAAA,IAAA;AAqBJ,CAAA;;;;;;AAGI;AAoCJ;;;;;AAEkB;AAgClB;;;;;;;AAA8D;AA0B9D;;;;;;;AAAgE;AAkDhE;;;;;;;AAIY,KArPA,MAqPA,CAAA,CAAA,EAAA,CAAA,CAAA,GArPe,EAqPf,CArPkB,CAqPlB,CAAA,GArPuB,GAqPvB,CArP2B,CAqP3B,CAAA;;;;;AAEC;AA2Db;;;;;;;;;;AAMe,cAvSF,EAuSE,EAAA,CAAA,CAAA,CAAA,CAAA,IAAA,EAvSa,CAuSb,EAAA,GAvSiB,EAuSjB,CAvSoB,CAuSpB,CAAA;;;;AAAJ;AAuGX;;;;;;AAAqD;AAOrD;;;;;;;AAAyD;;;;;;;;;;;;;cApX5C,gBAAiB,MAAI,IAAI;;;;;;;;;;;;;;;;;;;KAoB1B,mBAAmB,4BAA4B,UAAU,cAClE;;;;;;;;;;;;;;;;;;;KAqBS,oBAAoB,4BAA4B,UAAU,eAGnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoCa,6DAEJ,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;iBAgCN,mBAAmB,OAAO,GAAG,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;iBA0B/C,oBAAoB,OAAO,GAAG,eAAe,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDjD,qBAAqB,GAAG,KAAK;OACvC;SACE;;aAEI;6BACgB;IACxB,GAAG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DU,sBAAsB,GAAG,KAAK;OAC9C;SACE;;aAEI,QAAQ;6BACQ;IACxB,QAAQ,GAAG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuGJ,qBAAqB,OAAO,GAAG,KAAK;iBAOpC,qBAAqB,IAAI,OAAO,GAAG,KAAK"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isOk } from "./result-
|
|
1
|
+
import { isOk } from "./result-C_ph_izC.js";
|
|
2
2
|
|
|
3
3
|
//#region src/result/utils.ts
|
|
4
4
|
/**
|
|
@@ -27,4 +27,4 @@ function partitionResults(results) {
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
export { partitionResults };
|
|
30
|
-
//# sourceMappingURL=result-
|
|
30
|
+
//# sourceMappingURL=result-pV2mfn0W.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-
|
|
1
|
+
{"version":3,"file":"result-pV2mfn0W.js","names":["results: Result<T, E>[]"],"sources":["../src/result/utils.ts"],"sourcesContent":["import type { Err, Ok, Result } from \"./result.js\";\nimport { isOk } from \"./result.js\";\n\n/**\n * Partitions an array of Result objects into two separate arrays based on their status.\n *\n * @template T - The success type\n * @template E - The error type\n * @param results - An array of Result objects to partition\n * @returns An object containing two arrays:\n * - `oks`: Array of successful Result objects (Ok<T>[])\n * - `errs`: Array of error Result objects (Err<E>[])\n *\n * @example\n * const results = [Ok(1), Err(\"error\"), Ok(2)];\n * const { oks, errs } = partitionResults(results);\n * // oks = [Ok(1), Ok(2)]\n * // errs = [Err(\"error\")]\n */\nexport function partitionResults<T, E>(results: Result<T, E>[]) {\n\treturn {\n\t\toks: [],\n\t\terrs: [],\n\t\t...Object.groupBy(results, (result) => (isOk(result) ? \"oks\" : \"errs\")),\n\t} as { oks: Ok<T>[]; errs: Err<E>[] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAuBA,SAAyB;AAC/D,QAAO;EACN,KAAK,CAAE;EACP,MAAM,CAAE;EACR,GAAG,OAAO,QAAQ,SAAS,CAAC,WAAY,KAAK,OAAO,GAAG,QAAQ,OAAQ;CACvE;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isErr } from "./result-
|
|
1
|
+
import { isErr } from "./result-C_ph_izC.js";
|
|
2
2
|
|
|
3
3
|
//#region src/result/tap-err.ts
|
|
4
4
|
/**
|
|
@@ -34,4 +34,4 @@ function tapErr(logFn) {
|
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
36
36
|
export { tapErr };
|
|
37
|
-
//# sourceMappingURL=tap-err-
|
|
37
|
+
//# sourceMappingURL=tap-err-BENAkFsH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-err-
|
|
1
|
+
{"version":3,"file":"tap-err-BENAkFsH.js","names":["logFn: (err: E) => void"],"sources":["../src/result/tap-err.ts"],"sourcesContent":["import { isErr } from \"./result.js\";\nimport type { Result } from \"./result.js\";\n\n/**\n * Result-flow combinator. Logs on the `Err` branch and returns the `Result`\n * unchanged. Mirrors Rust's `Result::inspect_err` and Effect's\n * `tapErrorCause`.\n *\n * Takes a log **method**, not a whole logger. The caller picks the level at\n * the pipeline site — the same typed error can be logged as `warn` inside a\n * retry loop and as `error` on the last attempt, without the variant itself\n * carrying level. This is the `tracing::warn!(?err)` vs\n * `tracing::error!(?err)` idiom translated to Result-flow.\n *\n * No message argument. The typed error owns its message; a message\n * parameter here would drift away from the variant's template over time.\n *\n * @example\n * const result = await tryAsync({\n * try: () => writeTable(path),\n * catch: (cause) => MarkdownError.TableWrite({ path, cause }),\n * }).then(tapErr(log.warn));\n *\n * @example Level chosen at call site\n * await tryAttempt().then(tapErr(log.warn)); // inside retry\n * await tryFinal().then(tapErr(log.error)); // last try, giving up\n */\nexport function tapErr<T, E>(\n\tlogFn: (err: E) => void,\n): (result: Result<T, E>) => Result<T, E> {\n\treturn (result) => {\n\t\tif (isErr(result)) logFn(result.error);\n\t\treturn result;\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,OACfA,OACyC;AACzC,QAAO,CAAC,WAAW;AAClB,MAAI,MAAM,OAAO,CAAE,OAAM,OAAO,MAAM;AACtC,SAAO;CACP;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result } from "./result-
|
|
1
|
+
import { Result } from "./result-_socO0Ud.js";
|
|
2
2
|
|
|
3
3
|
//#region src/result/tap-err.d.ts
|
|
4
4
|
|
|
@@ -30,4 +30,4 @@ declare function tapErr<T, E>(logFn: (err: E) => void): (result: Result<T, E>) =
|
|
|
30
30
|
//# sourceMappingURL=tap-err.d.ts.map
|
|
31
31
|
//#endregion
|
|
32
32
|
export { tapErr };
|
|
33
|
-
//# sourceMappingURL=tap-err-
|
|
33
|
+
//# sourceMappingURL=tap-err-C0xfVXtz.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap-err-
|
|
1
|
+
{"version":3,"file":"tap-err-C0xfVXtz.d.ts","names":[],"sources":["../src/result/tap-err.ts"],"sourcesContent":[],"mappings":";;;;;;AA2BA;;;;;;;;;AAEmC;;;;;;;;;;;;;iBAFnB,0BACF,sBACF,OAAO,GAAG,OAAO,OAAO,GAAG"}
|
package/dist/testing.d.ts
CHANGED
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isErr, isOk } from "./result-
|
|
2
|
-
import { extractErrorMessage } from "./error-
|
|
3
|
-
import "./tap-err-
|
|
4
|
-
import "./result-
|
|
1
|
+
import { isErr, isOk } from "./result-C_ph_izC.js";
|
|
2
|
+
import { extractErrorMessage } from "./error-BkeqDeUq.js";
|
|
3
|
+
import "./tap-err-BENAkFsH.js";
|
|
4
|
+
import "./result-pV2mfn0W.js";
|
|
5
5
|
|
|
6
6
|
//#region src/testing.ts
|
|
7
7
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Err } from "./result-
|
|
1
|
+
import { Err } from "./result-_socO0Ud.js";
|
|
2
2
|
|
|
3
3
|
//#region src/error/types.d.ts
|
|
4
4
|
|
|
@@ -44,4 +44,4 @@ type InferError<T> = T extends ((...args: any[]) => Err<infer R>) ? R : never;
|
|
|
44
44
|
type InferErrors<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => Err<infer R>) ? R : never }[keyof T];
|
|
45
45
|
//#endregion
|
|
46
46
|
export { AnyTaggedError, DefineErrorsReturn, ErrorBody, ErrorsConfig, InferError, InferErrors, ValidatedConfig };
|
|
47
|
-
//# sourceMappingURL=types-
|
|
47
|
+
//# sourceMappingURL=types-ojNaDB4n.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-ojNaDB4n.d.ts","names":[],"sources":["../src/error/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAWY,KAXA,cAAA,GAWS;EAQhB,IAAA,EAAA,MAAA;EAOO,OAAA,EAAA,MAAY;CAAA;;;AAAS;AAGjC;;AAAsC,KAlB1B,SAAA,GAkB0B;EAAY,OAErC,EAAA,MAAA;CAAC;;;;;;;KAZT,iBAcC,CAAA,UAAA,MAAA,CAAA,GAAA;EAAC,OAAA,EAAA,MAAA;EAIF,IAAA,CAAA,EAAA,kCAhBqC,CAgBzB,eAAA;CAAA;;AAKV,KAhBK,YAAA,GAAe,MAgBpB,CAAA,MAAA,EAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAhBuD,SAgBvD,CAAA;;AACI,KAdC,eAcD,CAAA,UAd2B,YAc3B,CAAA,GAAA,QACgB,MAbd,CAac,GAAA,MAAA,GAbD,CAaC,CAbC,CAaD,CAAA,UAAA,CAAA,GAAA,IAAA,EAAA,KAAA,EAAA,EAAA,GAAA,KAAA,EAAA,IAAA,CAAA,GAAA,IAAA,EAZb,CAYa,EAAA,GAZP,CAYO,GAZH,iBAYG,CAZe,CAYf,CAAA,GAXvB,CAWuB,CAXrB,CAWqB,CAAA,EAAK;;KAP3B,YAOK,CAAA,cAAA,MAAA,EAAA,YAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAJuB,SAIvB,CAAA,GAAA,QAFH,KAED,GAAA,CAAA,GAAA,IAAA,EADK,UACL,CADgB,GAChB,CAAA,EAAA,GAAA,GAAA,CAAI,QAAJ,CAAA;EAAG,IAAA,EAAkB,KAAlB;AAIJ,CAAA,GAJgC,UAIhC,CAJ2C,GAI3C,CAAA,CAAA,CAAA,EAAmB;KAAnB,mBAA0B,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,SAAA,GAAA,GAAA,CAAA,CAAA,EAAoB,CAApB,EAAA,GAAA,IAAA,GAAA,KAAA,CAAA,UAAA,CAAA,CAAA,EAAA,KAAA,EAAA,EAAA,GAAA,IAAA,IAG5B,CAH4B,GAAA,KAAA;;AAG5B,KAIS,kBAJT,CAAA,gBAI4C,YAJ5C,CAAA,GAKF,mBALE,CAAA,QAAC,MAOW,OAPX,GAAA,MAAA,GAO8B,YAP9B,CAO2C,CAP3C,EAO8C,OAP9C,CAOsD,CAPtD,CAAA,CAAA,EAIJ,CAAA,MAIU,OAJE,GAAA,MAAA,CAAkB,CAAA;;AAAiB,KAQnC,UARmC,CAAA,CAAA,CAAA,GAU9C,CAV8C,UAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAUhB,GAVgB,CAAA,KAAA,EAAA,CAAA,IAUD,CAVC,GAAA,KAAA;;AAGA,KAUnC,WAVmC,CAAA,CAAA,CAAA,GAAA,QAAG,MAYrC,CAZqC,GAYjC,CAZiC,CAY/B,CAZ+B,CAAA,UAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAYA,GAZA,CAAA,KAAA,EAAA,CAAA,IAYe,CAZf,GAAA,KAAA,EAAO,CAAA,MAajD,CAbkD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wellcrafted",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "Delightful TypeScript patterns for elegant, type-safe applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -53,7 +53,10 @@
|
|
|
53
53
|
"test": "bun test",
|
|
54
54
|
"test:watch": "bun test --watch",
|
|
55
55
|
"typecheck": "tsc --noEmit",
|
|
56
|
-
"release": "bun run build && changeset version && changeset publish"
|
|
56
|
+
"release": "bun run build && changeset version && changeset publish",
|
|
57
|
+
"docs:dev": "bunx mint dev",
|
|
58
|
+
"docs:validate": "bunx mint validate",
|
|
59
|
+
"docs:links": "bunx mint broken-links"
|
|
57
60
|
},
|
|
58
61
|
"keywords": [
|
|
59
62
|
"typescript",
|