functype-react 1.21.0 → 1.21.1
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 +17 -20
- package/dist/TaskState-DWxGWqXf.d.ts +24 -0
- package/dist/async/TaskState.d.ts +2 -0
- package/dist/async/index.d.ts +9 -7
- package/dist/async/index.js +1 -1
- package/dist/async/index.js.map +1 -1
- package/dist/async/useTask.d.ts +24 -0
- package/dist/async/useTask.js +2 -0
- package/dist/async/useTask.js.map +1 -0
- package/dist/async/useTaskPromise.d.ts +14 -0
- package/dist/async/useTaskPromise.js +2 -0
- package/dist/async/useTaskPromise.js.map +1 -0
- package/dist/async/useTaskValue.d.ts +24 -0
- package/dist/async/useTaskValue.js +2 -0
- package/dist/async/useTaskValue.js.map +1 -0
- package/dist/{eq-CR56QmPb.d.ts → eq-CK6oQqWG.d.ts} +3 -1
- package/dist/forms/Validated.d.ts +2 -0
- package/dist/forms/Validated.js.map +1 -1
- package/dist/forms/useValidatedField.d.ts +2 -0
- package/dist/forms/useValidatedField.js.map +1 -1
- package/dist/forms/useValidatedForm.d.ts +2 -0
- package/dist/forms/useValidatedForm.js.map +1 -1
- package/dist/hooks/eq.d.ts +1 -1
- package/dist/hooks/eq.js.map +1 -1
- package/dist/hooks/index.d.ts +9 -9
- package/dist/hooks/useEither.d.ts +1 -1
- package/dist/hooks/useEither.js.map +1 -1
- package/dist/hooks/useList.d.ts +1 -1
- package/dist/hooks/useList.js.map +1 -1
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js.map +1 -1
- package/dist/hooks/useStableCallback.d.ts +1 -1
- package/dist/hooks/useStableCallback.js.map +1 -1
- package/dist/hooks/useStableEffect.d.ts +1 -1
- package/dist/hooks/useStableEffect.js.map +1 -1
- package/dist/hooks/useStableMemo.d.ts +1 -1
- package/dist/hooks/useStableMemo.js.map +1 -1
- package/dist/hooks/useStableState.d.ts +1 -1
- package/dist/hooks/useStableState.js.map +1 -1
- package/dist/hooks/useTry.d.ts +1 -1
- package/dist/hooks/useTry.js.map +1 -1
- package/dist/{index-Dr09mq-A.d.ts → index-DjzwkXMF.d.ts} +9 -1
- package/dist/index.d.ts +10 -10
- package/dist/match/index.d.ts +1 -1
- package/dist/match/index.js +1 -1
- package/dist/match-CkGESkj9.js.map +1 -1
- package/dist/query/IOQueryError.d.ts +2 -0
- package/dist/query/IOQueryError.js.map +1 -1
- package/dist/query/ioQueryFn.d.ts +4 -3
- package/dist/query/ioQueryFn.js +1 -1
- package/dist/query/ioQueryFn.js.map +1 -1
- package/dist/query/queryState.d.ts +10 -8
- package/dist/query/queryState.js.map +1 -1
- package/dist/query/useIOMutation.d.ts +2 -0
- package/dist/query/useIOMutation.js.map +1 -1
- package/dist/query/useIOMutationState.d.ts +6 -4
- package/dist/query/useIOMutationState.js.map +1 -1
- package/dist/query/useIOQuery.d.ts +2 -0
- package/dist/query/useIOQuery.js.map +1 -1
- package/dist/query/useIOQueryState.d.ts +7 -5
- package/dist/query/useIOQueryState.js.map +1 -1
- package/dist/{useEither-D1Rn_tLR.d.ts → useEither-DyPW7OaA.d.ts} +3 -1
- package/dist/{useList-C_7X5OA_.d.ts → useList-B5Iox1xv.d.ts} +3 -1
- package/dist/{useOption-B8UyOh8h.d.ts → useOption-CXXNC1_S.d.ts} +3 -1
- package/dist/{useStableCallback-C5jd1hKf.d.ts → useStableCallback-CXQQOhl6.d.ts} +4 -2
- package/dist/{useStableEffect-BiDhoNpC.d.ts → useStableEffect-C-5NCd1T.d.ts} +4 -2
- package/dist/{useStableMemo-DCeNIpt5.d.ts → useStableMemo-PYyLBWwd.d.ts} +4 -2
- package/dist/{useStableState-BPVQ-XMX.d.ts → useStableState-fi6nURHS.d.ts} +4 -2
- package/dist/{useTry-ie1X0NiH.d.ts → useTry-B0HIcFFb.d.ts} +3 -1
- package/package.json +10 -10
- package/dist/AsyncState-DxKw9NF6.d.ts +0 -21
- package/dist/async/AsyncState.d.ts +0 -2
- package/dist/async/useIO.d.ts +0 -27
- package/dist/async/useIO.js +0 -2
- package/dist/async/useIO.js.map +0 -1
- package/dist/async/useIOPromise.d.ts +0 -15
- package/dist/async/useIOPromise.js +0 -2
- package/dist/async/useIOPromise.js.map +0 -1
- package/dist/async/useIOValue.d.ts +0 -24
- package/dist/async/useIOValue.js +0 -2
- package/dist/async/useIOValue.js.map +0 -1
- /package/dist/async/{AsyncState.js → TaskState.js} +0 -0
package/dist/hooks/useTry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTry.js","names":["useTry","value","setValue","useState","initial","Try","setSuccess","useCallback","a","setFailure","fold","onFailure","onSuccess","useMemo"],"sources":["../../src/hooks/useTry.ts"],"sourcesContent":["\"use client\"\n\nimport { Try, type Try as TryT } from \"functype/try\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Try container. Defaults to Failure(new Error(\"uninitialized\")) when no initial.\n */\nexport function useTry<A>(initial?: TryT<A>): {\n readonly value: TryT<A>\n setSuccess: (a: A) => void\n setFailure: (e: Error) => void\n fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R\n} {\n const [value, setValue] = useState<TryT<A>>(() => initial ?? Try.failure<A>(new Error(\"uninitialized\")))\n\n const setSuccess = useCallback((a: A) => setValue(Try.success(a)), [])\n const setFailure = useCallback((e: Error) => setValue(Try.failure<A>(e)), [])\n\n const fold = useCallback(\n <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => value.fold(onFailure, onSuccess),\n [value],\n )\n\n return useMemo(() => ({ value, setSuccess, setFailure, fold }), [value, setSuccess, setFailure, fold])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTry.js","names":["useTry","value","setValue","useState","initial","Try","setSuccess","useCallback","a","setFailure","fold","onFailure","onSuccess","useMemo"],"sources":["../../src/hooks/useTry.ts"],"sourcesContent":["\"use client\"\n\nimport { Try, type Try as TryT } from \"functype/try\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Try container. Defaults to Failure(new Error(\"uninitialized\")) when no initial.\n */\nexport function useTry<A>(initial?: TryT<A>): {\n readonly value: TryT<A>\n setSuccess: (a: A) => void\n setFailure: (e: Error) => void\n fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R\n} {\n const [value, setValue] = useState<TryT<A>>(() => initial ?? Try.failure<A>(new Error(\"uninitialized\")))\n\n const setSuccess = useCallback((a: A) => setValue(Try.success(a)), [])\n const setFailure = useCallback((e: Error) => setValue(Try.failure<A>(e)), [])\n\n const fold = useCallback(\n <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => value.fold(onFailure, onSuccess),\n [value],\n )\n\n return useMemo(() => ({ value, setSuccess, setFailure, fold }), [value, setSuccess, setFailure, fold])\n}\n"],"mappings":"+GAQA,SAAgBA,EAAU,EAKxB,CACA,GAAM,CAACC,EAAOC,GAAYC,MAAwBC,GAAWC,EAAI,QAAW,gBAAI,MAAM,eAAe,CAAC,CAAC,EAEjGC,EAAaC,EAAa,GAASL,EAASG,EAAI,QAAQG,CAAC,CAAC,EAAG,CAAC,CAAC,EAC/DC,EAAaF,EAAa,GAAaL,EAASG,EAAI,QAAW,CAAC,CAAC,EAAG,CAAC,CAAC,EAEtEK,EAAOH,GACP,EAA4B,IAA2BN,EAAM,KAAKU,EAAWC,CAAS,EAC1F,CAACX,CAAK,CACR,EAEA,OAAOY,OAAe,CAAE,QAAO,aAAY,aAAY,MAAK,GAAI,CAACZ,EAAOK,EAAYG,EAAYC,CAAI,CAAC,CACvG"}
|
|
@@ -2,6 +2,7 @@ import { Either } from "functype/either";
|
|
|
2
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
3
|
import { Option } from "functype/option";
|
|
4
4
|
import { Try } from "functype/try";
|
|
5
|
+
//#region src/match/Match.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Maps each `_tag` literal to a handler that receives the narrowed variant.
|
|
7
8
|
*
|
|
@@ -34,6 +35,8 @@ declare function Match<U extends {
|
|
|
34
35
|
readonly value: U;
|
|
35
36
|
readonly children: MatchCases<U>;
|
|
36
37
|
}): ReactElement;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/match/MatchEither.d.ts
|
|
37
40
|
/**
|
|
38
41
|
* Tag-narrowed sugar over `Match` for `Either<L, R>`.
|
|
39
42
|
*/
|
|
@@ -42,6 +45,8 @@ declare function MatchEither<L, R>(props: {
|
|
|
42
45
|
readonly Left: (l: L) => ReactNode;
|
|
43
46
|
readonly Right: (r: R) => ReactNode;
|
|
44
47
|
}): ReactElement;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/match/MatchOption.d.ts
|
|
45
50
|
/**
|
|
46
51
|
* Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the
|
|
47
52
|
* `Some` handler and `None` to the `None` handler.
|
|
@@ -51,6 +56,8 @@ declare function MatchOption<A>(props: {
|
|
|
51
56
|
readonly Some: (a: A) => ReactNode;
|
|
52
57
|
readonly None: () => ReactNode;
|
|
53
58
|
}): ReactElement;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/match/MatchTry.d.ts
|
|
54
61
|
/**
|
|
55
62
|
* Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the
|
|
56
63
|
* underlying `Error`; `Success` receives the value.
|
|
@@ -60,5 +67,6 @@ declare function MatchTry<A>(props: {
|
|
|
60
67
|
readonly Success: (a: A) => ReactNode;
|
|
61
68
|
readonly Failure: (e: Error) => ReactNode;
|
|
62
69
|
}): ReactElement;
|
|
70
|
+
//#endregion
|
|
63
71
|
export { MatchCases as a, Match as i, MatchOption as n, MatchEither as r, MatchTry as t };
|
|
64
|
-
//# sourceMappingURL=index-
|
|
72
|
+
//# sourceMappingURL=index-DjzwkXMF.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-
|
|
2
|
-
import { t as useEither } from "./useEither-
|
|
3
|
-
import { t as useList } from "./useList-
|
|
4
|
-
import { t as useOption } from "./useOption-
|
|
5
|
-
import { t as useStableCallback } from "./useStableCallback-
|
|
6
|
-
import { t as useStableEffect } from "./useStableEffect-
|
|
7
|
-
import { t as useStableMemo } from "./useStableMemo-
|
|
8
|
-
import { t as useStableState } from "./useStableState-
|
|
9
|
-
import { t as useTry } from "./useTry-
|
|
1
|
+
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
|
+
import { t as useEither } from "./useEither-DyPW7OaA.js";
|
|
3
|
+
import { t as useList } from "./useList-B5Iox1xv.js";
|
|
4
|
+
import { t as useOption } from "./useOption-CXXNC1_S.js";
|
|
5
|
+
import { t as useStableCallback } from "./useStableCallback-CXQQOhl6.js";
|
|
6
|
+
import { t as useStableEffect } from "./useStableEffect-C-5NCd1T.js";
|
|
7
|
+
import { t as useStableMemo } from "./useStableMemo-PYyLBWwd.js";
|
|
8
|
+
import { t as useStableState } from "./useStableState-fi6nURHS.js";
|
|
9
|
+
import { t as useTry } from "./useTry-B0HIcFFb.js";
|
|
10
10
|
import "./hooks/index.js";
|
|
11
|
-
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-
|
|
11
|
+
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-DjzwkXMF.js";
|
|
12
12
|
export { type Eq, Match, type MatchCases, MatchEither, MatchOption, MatchTry, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
|
package/dist/match/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "../index-
|
|
1
|
+
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "../index-DjzwkXMF.js";
|
|
2
2
|
export { Match, type MatchCases, MatchEither, MatchOption, MatchTry };
|
package/dist/match/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"../match-CkGESkj9.js";export{e as Match,n as MatchEither,t as MatchOption,r as MatchTry};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-CkGESkj9.js","names":["Match","handler","props","Fragment","MatchEither","MatchOption","MatchTry"],"sources":["../src/match/Match.tsx","../src/match/MatchEither.tsx","../src/match/MatchOption.tsx","../src/match/MatchTry.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Maps each `_tag` literal to a handler that receives the narrowed variant.\n *\n * TypeScript enforces exhaustiveness: omitting a case from `children` is a\n * compile error.\n */\nexport type MatchCases<U extends { _tag: string }> = {\n readonly [K in U[\"_tag\"]]: (value: Extract<U, { readonly _tag: K }>) => ReactNode\n}\n\n/**\n * Generic discriminated-union matcher for ADTs that follow functype's `_tag`\n * convention. Pass a value and a record of handlers keyed on each tag; the\n * matching handler is invoked with the narrowed variant.\n *\n * ```tsx\n * <Match value={state}>\n * {{\n * Loading: () => <Spinner />,\n * Success: ({ data }) => <Result data={data} />,\n * Failure: ({ error }) => <Err err={error} />,\n * }}\n * </Match>\n * ```\n */\nexport function Match<U extends { _tag: string }>(props: {\n readonly value: U\n readonly children: MatchCases<U>\n}): ReactElement {\n const handler = props.children[props.value._tag as U[\"_tag\"]] as (value: U) => ReactNode\n return <>{handler(props.value)}</>\n}\n","import type { Either } from \"functype/either\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Either<L, R>`.\n */\nexport function MatchEither<L, R>(props: {\n readonly value: Either<L, R>\n readonly Left: (l: L) => ReactNode\n readonly Right: (r: R) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Left, props.Right)}</>\n}\n","import type { Option } from \"functype/option\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the\n * `Some` handler and `None` to the `None` handler.\n */\nexport function MatchOption<A>(props: {\n readonly value: Option<A>\n readonly Some: (a: A) => ReactNode\n readonly None: () => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.None, props.Some)}</>\n}\n","import type { Try } from \"functype/try\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the\n * underlying `Error`; `Success` receives the value.\n */\nexport function MatchTry<A>(props: {\n readonly value: Try<A>\n readonly Success: (a: A) => ReactNode\n readonly Failure: (e: Error) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Failure, props.Success)}</>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"match-CkGESkj9.js","names":["Match","handler","props","Fragment","MatchEither","MatchOption","MatchTry"],"sources":["../src/match/Match.tsx","../src/match/MatchEither.tsx","../src/match/MatchOption.tsx","../src/match/MatchTry.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Maps each `_tag` literal to a handler that receives the narrowed variant.\n *\n * TypeScript enforces exhaustiveness: omitting a case from `children` is a\n * compile error.\n */\nexport type MatchCases<U extends { _tag: string }> = {\n readonly [K in U[\"_tag\"]]: (value: Extract<U, { readonly _tag: K }>) => ReactNode\n}\n\n/**\n * Generic discriminated-union matcher for ADTs that follow functype's `_tag`\n * convention. Pass a value and a record of handlers keyed on each tag; the\n * matching handler is invoked with the narrowed variant.\n *\n * ```tsx\n * <Match value={state}>\n * {{\n * Loading: () => <Spinner />,\n * Success: ({ data }) => <Result data={data} />,\n * Failure: ({ error }) => <Err err={error} />,\n * }}\n * </Match>\n * ```\n */\nexport function Match<U extends { _tag: string }>(props: {\n readonly value: U\n readonly children: MatchCases<U>\n}): ReactElement {\n const handler = props.children[props.value._tag as U[\"_tag\"]] as (value: U) => ReactNode\n return <>{handler(props.value)}</>\n}\n","import type { Either } from \"functype/either\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Either<L, R>`.\n */\nexport function MatchEither<L, R>(props: {\n readonly value: Either<L, R>\n readonly Left: (l: L) => ReactNode\n readonly Right: (r: R) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Left, props.Right)}</>\n}\n","import type { Option } from \"functype/option\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the\n * `Some` handler and `None` to the `None` handler.\n */\nexport function MatchOption<A>(props: {\n readonly value: Option<A>\n readonly Some: (a: A) => ReactNode\n readonly None: () => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.None, props.Some)}</>\n}\n","import type { Try } from \"functype/try\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the\n * underlying `Error`; `Success` receives the value.\n */\nexport function MatchTry<A>(props: {\n readonly value: Try<A>\n readonly Success: (a: A) => ReactNode\n readonly Failure: (e: Error) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Failure, props.Success)}</>\n}\n"],"mappings":"sDA2BA,SAAgBA,EAAkC,EAGjC,CACf,IAAMC,EAAUC,EAAM,SAASA,EAAM,MAAM,MAC3C,MAAO,kBAAAC,EAAA,CAAA,SAAGF,EAAQC,EAAM,KAAK,CAAI,CAAA,CACnC,CC3BA,SAAgBE,EAAkB,EAIjB,CACf,MAAO,kBAAAD,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,KAAK,CAAI,CAAA,CACxD,CCLA,SAAgBG,EAAe,EAId,CACf,MAAO,kBAAAF,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,IAAI,CAAI,CAAA,CACvD,CCNA,SAAgBI,EAAY,EAIX,CACf,MAAO,kBAAAH,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,QAASA,EAAM,OAAO,CAAI,CAAA,CAC7D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/query/IOQueryError.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Derives a human-readable message from an arbitrary error channel value.
|
|
3
4
|
*
|
|
@@ -53,4 +54,5 @@ export declare class IOQueryError<E> extends Error {
|
|
|
53
54
|
}
|
|
54
55
|
/** Runtime guard for {@link IOQueryError}. */
|
|
55
56
|
export declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
|
|
57
|
+
//#endregion
|
|
56
58
|
//# sourceMappingURL=IOQueryError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOQueryError.js","names":["isTaggedError","formatIOError","error","where","statusText","Try","IOQueryError","message","defect","isIOQueryError"],"sources":["../../src/query/IOQueryError.ts"],"sourcesContent":["/**\n * Error boxing for the React Query bridge.\n *\n * `IO`'s own terminals don't fit React Query's contract: `.run()` returns\n * `Promise<Either<E, A>>` and never throws (so RQ never sees a failure), while\n * `.runOrThrow()` throws the *raw* tagged error object — `{ _tag: \"NetworkError\", ... }`\n * is not an `Error` instance, so the ubiquitous\n * `error instanceof Error ? error.message : fallback` handler silently degrades.\n *\n * `IOQueryError` boxes the typed error so both worlds work: `instanceof Error` and\n * `.message` behave as any React Query consumer expects, while `.error` preserves the\n * fully discriminable functype `E`.\n */\nimport { Try } from \"functype\"\n\n/** Structural view of a tagged functype error (e.g. any `HttpError` variant). */\ntype TaggedError = {\n readonly _tag: string\n readonly url?: unknown\n readonly status?: unknown\n readonly statusText?: unknown\n readonly message?: unknown\n}\n\nconst isTaggedError = (e: unknown): e is TaggedError =>\n typeof e === \"object\" && e !== null && \"_tag\" in e && typeof (e as { _tag: unknown })._tag === \"string\"\n\n/**\n * Derives a human-readable message from an arbitrary error channel value.\n *\n * Deliberately *structural* — this module does not import `functype/fetch`, so the\n * query bridge stays generic over any `IO<never, E, A>` rather than being HTTP-specific.\n * An `HttpStatusError` is recognized by its shape, not its type.\n *\n * Pass `formatError` to any of the query entry points to override this entirely.\n */\nexport const formatIOError = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message\n }\n\n if (isTaggedError(error)) {\n const where = typeof error.url === \"string\" ? ` — ${error.url}` : \"\"\n\n if (typeof error.status === \"number\") {\n const statusText =\n typeof error.statusText === \"string\" && error.statusText.length > 0 ? ` ${error.statusText}` : \"\"\n return `HTTP ${error.status}${statusText}${where}`\n }\n\n // A tagged error carrying its own `message` is the normal shape for a domain error\n // in the `IO` channel, and that message is what the author wrote for a human to\n // read. Falling back to the bare tag was the one case where information already\n // present got discarded — a raw `Error` gets `.message`, an untagged object gets\n // JSON, but a tagged one got neither. None of functype's own `HttpError` variants\n // carry a `message`, so the HTTP renderings above are unaffected.\n if (typeof error.message === \"string\" && error.message.length > 0) {\n return error.message\n }\n\n return `${error._tag}${where}`\n }\n\n // `String({})` is \"[object Object]\", which tells a reader nothing. Prefer a JSON\n // rendering for plain objects, falling back to String() for cycles and symbols.\n if (typeof error === \"object\" && error !== null) {\n return Try(() => JSON.stringify(error)).orElse(String(error))\n }\n\n return String(error)\n}\n\n/**\n * An `Error` subclass carrying the typed functype error channel.\n *\n * ```ts\n * const { error } = useIOQuery([\"limits\", userId], ({ signal }) => Http.get(url, { signal }))\n *\n * error instanceof Error // true\n * error.message // \"HTTP 403 Forbidden — /api/limits\"\n *\n * HttpErrors.match(error.error, {\n * NetworkError: (e) => retryBanner(e),\n * HttpStatusError: (e) => (e.status === 403 ? upgradePrompt() : genericFailure(e)),\n * DecodeError: (e) => reportSchemaDrift(e),\n * })\n * ```\n */\nexport class IOQueryError<E> extends Error {\n /**\n * The raw functype error channel value — discriminable via its own `_tag`.\n *\n * When {@link defect} is `true` this is **not** an `E`. Check `defect` before\n * matching on `_tag`.\n */\n readonly error: E\n\n /**\n * `true` when {@link error} is *not* a value from the effect's typed error channel.\n * Three things set it:\n *\n * - the effect factory threw before an `IO` was ever produced\n * - the effect produced a defect (`Exit.Die`) — a throwing `IO.sync` thunk, a\n * throwing `map` / `flatMap` / `mapError` callback, or `IO.die`\n * - the effect was interrupted, so `error` is an `InterruptedError`\n *\n * Kept as an explicit flag rather than widening `E` to `unknown`, which would force\n * every consumer to handle a case that should never occur.\n *\n * `defect: false` genuinely means `error` is an `E`. Before 1.8.0 it did not: a\n * defect reached the adapter as an ordinary `Left` and was indistinguishable from a\n * typed failure, so the documented guard didn't guard anything (#259).\n */\n readonly defect: boolean\n\n constructor(error: E, message?: string, defect = false) {\n super(message ?? formatIOError(error), { cause: error })\n this.name = \"IOQueryError\"\n this.error = error\n this.defect = defect\n }\n}\n\n/** Runtime guard for {@link IOQueryError}. */\nexport const isIOQueryError = <E = unknown>(error: unknown): error is IOQueryError<E> => error instanceof IOQueryError\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IOQueryError.js","names":["isTaggedError","formatIOError","error","where","statusText","Try","IOQueryError","message","defect","isIOQueryError"],"sources":["../../src/query/IOQueryError.ts"],"sourcesContent":["/**\n * Error boxing for the React Query bridge.\n *\n * `IO`'s own terminals don't fit React Query's contract: `.run()` returns\n * `Promise<Either<E, A>>` and never throws (so RQ never sees a failure), while\n * `.runOrThrow()` throws the *raw* tagged error object — `{ _tag: \"NetworkError\", ... }`\n * is not an `Error` instance, so the ubiquitous\n * `error instanceof Error ? error.message : fallback` handler silently degrades.\n *\n * `IOQueryError` boxes the typed error so both worlds work: `instanceof Error` and\n * `.message` behave as any React Query consumer expects, while `.error` preserves the\n * fully discriminable functype `E`.\n */\nimport { Try } from \"functype\"\n\n/** Structural view of a tagged functype error (e.g. any `HttpError` variant). */\ntype TaggedError = {\n readonly _tag: string\n readonly url?: unknown\n readonly status?: unknown\n readonly statusText?: unknown\n readonly message?: unknown\n}\n\nconst isTaggedError = (e: unknown): e is TaggedError =>\n typeof e === \"object\" && e !== null && \"_tag\" in e && typeof (e as { _tag: unknown })._tag === \"string\"\n\n/**\n * Derives a human-readable message from an arbitrary error channel value.\n *\n * Deliberately *structural* — this module does not import `functype/fetch`, so the\n * query bridge stays generic over any `IO<never, E, A>` rather than being HTTP-specific.\n * An `HttpStatusError` is recognized by its shape, not its type.\n *\n * Pass `formatError` to any of the query entry points to override this entirely.\n */\nexport const formatIOError = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message\n }\n\n if (isTaggedError(error)) {\n const where = typeof error.url === \"string\" ? ` — ${error.url}` : \"\"\n\n if (typeof error.status === \"number\") {\n const statusText =\n typeof error.statusText === \"string\" && error.statusText.length > 0 ? ` ${error.statusText}` : \"\"\n return `HTTP ${error.status}${statusText}${where}`\n }\n\n // A tagged error carrying its own `message` is the normal shape for a domain error\n // in the `IO` channel, and that message is what the author wrote for a human to\n // read. Falling back to the bare tag was the one case where information already\n // present got discarded — a raw `Error` gets `.message`, an untagged object gets\n // JSON, but a tagged one got neither. None of functype's own `HttpError` variants\n // carry a `message`, so the HTTP renderings above are unaffected.\n if (typeof error.message === \"string\" && error.message.length > 0) {\n return error.message\n }\n\n return `${error._tag}${where}`\n }\n\n // `String({})` is \"[object Object]\", which tells a reader nothing. Prefer a JSON\n // rendering for plain objects, falling back to String() for cycles and symbols.\n if (typeof error === \"object\" && error !== null) {\n return Try(() => JSON.stringify(error)).orElse(String(error))\n }\n\n return String(error)\n}\n\n/**\n * An `Error` subclass carrying the typed functype error channel.\n *\n * ```ts\n * const { error } = useIOQuery([\"limits\", userId], ({ signal }) => Http.get(url, { signal }))\n *\n * error instanceof Error // true\n * error.message // \"HTTP 403 Forbidden — /api/limits\"\n *\n * HttpErrors.match(error.error, {\n * NetworkError: (e) => retryBanner(e),\n * HttpStatusError: (e) => (e.status === 403 ? upgradePrompt() : genericFailure(e)),\n * DecodeError: (e) => reportSchemaDrift(e),\n * })\n * ```\n */\nexport class IOQueryError<E> extends Error {\n /**\n * The raw functype error channel value — discriminable via its own `_tag`.\n *\n * When {@link defect} is `true` this is **not** an `E`. Check `defect` before\n * matching on `_tag`.\n */\n readonly error: E\n\n /**\n * `true` when {@link error} is *not* a value from the effect's typed error channel.\n * Three things set it:\n *\n * - the effect factory threw before an `IO` was ever produced\n * - the effect produced a defect (`Exit.Die`) — a throwing `IO.sync` thunk, a\n * throwing `map` / `flatMap` / `mapError` callback, or `IO.die`\n * - the effect was interrupted, so `error` is an `InterruptedError`\n *\n * Kept as an explicit flag rather than widening `E` to `unknown`, which would force\n * every consumer to handle a case that should never occur.\n *\n * `defect: false` genuinely means `error` is an `E`. Before 1.8.0 it did not: a\n * defect reached the adapter as an ordinary `Left` and was indistinguishable from a\n * typed failure, so the documented guard didn't guard anything (#259).\n */\n readonly defect: boolean\n\n constructor(error: E, message?: string, defect = false) {\n super(message ?? formatIOError(error), { cause: error })\n this.name = \"IOQueryError\"\n this.error = error\n this.defect = defect\n }\n}\n\n/** Runtime guard for {@link IOQueryError}. */\nexport const isIOQueryError = <E = unknown>(error: unknown): error is IOQueryError<E> => error instanceof IOQueryError\n"],"mappings":"+BAwBA,MAAMA,EAAiB,GACrB,OAAO,GAAM,YAAY,GAAc,SAAU,GAAK,OAAQ,EAAwB,MAAS,SAWpFC,EAAiB,GAA2B,CACvD,GAAIC,aAAiB,MACnB,OAAOA,EAAM,QAGf,GAAIF,EAAcE,CAAK,EAAG,CACxB,IAAMC,EAAQ,OAAOD,EAAM,KAAQ,SAAW,MAAMA,EAAM,MAAQ,GAElE,GAAI,OAAOA,EAAM,QAAW,SAAU,CACpC,IAAME,EACJ,OAAOF,EAAM,YAAe,UAAYA,EAAM,WAAW,OAAS,EAAI,IAAIA,EAAM,aAAe,GACjG,MAAO,QAAQA,EAAM,SAASE,IAAaD,GAC7C,CAYA,OAJI,OAAOD,EAAM,SAAY,UAAYA,EAAM,QAAQ,OAAS,EACvDA,EAAM,QAGR,GAAGA,EAAM,OAAOC,GACzB,CAQA,OAJI,OAAOD,GAAU,UAAYA,EACxBG,MAAU,KAAK,UAAUH,CAAK,CAAC,CAAC,CAAC,OAAO,OAAOA,CAAK,CAAC,EAGvD,OAAOA,CAAK,CACrB,EAkBA,IAAaI,EAAb,cAAqC,KAAM,CA2BzC,YAAY,EAAU,EAAkB,EAAS,GAAO,CACtD,MAAMC,GAAWN,EAAcC,CAAK,EAAG,CAAE,MAAOA,CAAM,CAAC,EACvD,KAAK,KAAO,eACZ,KAAK,MAAQA,EACb,KAAK,OAASM,CAChB,CACF,EAGA,MAAaC,EAA+B,GAA6CP,aAAiBI"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IO } from "functype/io";
|
|
2
|
+
//#region src/query/ioQueryFn.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Minimal structural view of React Query's `QueryFunctionContext` — the floor that
|
|
4
5
|
* every context satisfies, and the default when nothing wider is inferred.
|
|
@@ -20,9 +21,8 @@ export type IOBridgeOptions<E> = {
|
|
|
20
21
|
* Adapts an `IO<never, E, A>` into a React Query `queryFn`.
|
|
21
22
|
*
|
|
22
23
|
* `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that
|
|
23
|
-
* carries the typed error on `.error`.
|
|
24
|
-
*
|
|
25
|
-
* request as well, close over the same `signal`:
|
|
24
|
+
* carries the typed error on `.error`. Wire cancellation by closing over the supplied
|
|
25
|
+
* `signal`:
|
|
26
26
|
*
|
|
27
27
|
* ```ts
|
|
28
28
|
* useQuery({
|
|
@@ -46,4 +46,5 @@ export declare const ioQueryFn: <E, A, TContext extends IOQueryFnContext = IOQue
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export declare const ioMutationFn: <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (variables: V) => Promise<A>;
|
|
49
|
+
//#endregion
|
|
49
50
|
//# sourceMappingURL=ioQueryFn.d.ts.map
|
package/dist/query/ioQueryFn.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{IOQueryError as e}from"./IOQueryError.js";import{Try as t}from"functype";import{InterruptedError as n}from"functype/io";const r=async(r,i
|
|
1
|
+
import{IOQueryError as e}from"./IOQueryError.js";import{Try as t}from"functype";import{InterruptedError as n}from"functype/io";const r=async(r,i)=>{let a=await t(()=>r()).fold(t=>{throw new e(t,void 0,!0)},e=>e.runExit());if(a.isFailure()){let{error:t}=a.toValue();throw new e(t,i?.formatError?.(t))}if(a.isDie())throw new e(a.toValue().defect,void 0,!0);if(a.isInterrupted())throw new e(new n,void 0,!0);return a.orThrow()},i=(e,t)=>n=>r(()=>e(n),t),a=(e,t)=>n=>r(()=>e(n),t);export{a as ioMutationFn,i as ioQueryFn};
|
|
2
2
|
//# sourceMappingURL=ioQueryFn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ioQueryFn.js","names":["runBoxed","exit","Try","effect","IOQueryError","thrown","io","error","options","InterruptedError","ioQueryFn","context","ioMutationFn","variables"],"sources":["../../src/query/ioQueryFn.ts"],"sourcesContent":["import { Try } from \"functype\"\nimport { InterruptedError, type IO } from \"functype/io\"\n\nimport { IOQueryError } from \"./IOQueryError\"\n\n/**\n * Minimal structural view of React Query's `QueryFunctionContext` — the floor that\n * every context satisfies, and the default when nothing wider is inferred.\n *\n * Typed structurally on purpose, so these primitives carry **no**\n * `@tanstack/react-query` type dependency. `ioQueryFn` is generic over the context, so\n * a richer one flows through unchanged: annotate the callback parameter (e.g. with\n * `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,\n * `queryKey`, and `meta` are all readable inside the effect factory.\n */\nexport type IOQueryFnContext = {\n readonly signal: AbortSignal\n}\n\nexport type IOBridgeOptions<E> = {\n /** Override the derived `Error.message`. Defaults to a structural formatter. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * Runs an effect and returns its value, or throws a boxed {@link IOQueryError}.\n *\n * Three failure paths converge here:\n * - the effect's typed error channel (`Failure`) → boxed with `defect: false`\n * - a defect raised *inside* the effect (`Die`) → boxed with `defect: true`\n * - the factory throwing before an `IO` exists → boxed with `defect: true`\n *\n * The third matters because running an effect never throws, but `io(input)` is\n * ordinary user code that can throw while building the effect. Without this, that\n * throw would escape unboxed and `error.error` would be `undefined` despite the\n * declared type.\n *\n * The second is why this uses `runExit()` rather than `run()`. `run()` returns\n * `Either<E, A>`, which has nowhere to put a defect — a throwing `mapError` handler or\n * `IO.sync` thunk arrived as `Left` and was indistinguishable from a genuine `E`, so\n * `defect` read `false` while `.error` held something that was not an `E` at all\n * (#259). `Exit` keeps the two apart, so the flag can be accurate.\n *\n * The throws are confined to this function so no caller ever writes one.\n *\n * @interop React Query signals failure only by promise rejection; an Either return reads as success (#239).\n */\nconst runBoxed = async <E, A>(
|
|
1
|
+
{"version":3,"file":"ioQueryFn.js","names":["runBoxed","exit","Try","effect","IOQueryError","thrown","io","error","options","InterruptedError","ioQueryFn","context","ioMutationFn","variables"],"sources":["../../src/query/ioQueryFn.ts"],"sourcesContent":["import { Try } from \"functype\"\nimport { InterruptedError, type IO } from \"functype/io\"\n\nimport { IOQueryError } from \"./IOQueryError\"\n\n/**\n * Minimal structural view of React Query's `QueryFunctionContext` — the floor that\n * every context satisfies, and the default when nothing wider is inferred.\n *\n * Typed structurally on purpose, so these primitives carry **no**\n * `@tanstack/react-query` type dependency. `ioQueryFn` is generic over the context, so\n * a richer one flows through unchanged: annotate the callback parameter (e.g. with\n * `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,\n * `queryKey`, and `meta` are all readable inside the effect factory.\n */\nexport type IOQueryFnContext = {\n readonly signal: AbortSignal\n}\n\nexport type IOBridgeOptions<E> = {\n /** Override the derived `Error.message`. Defaults to a structural formatter. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * Runs an effect and returns its value, or throws a boxed {@link IOQueryError}.\n *\n * Three failure paths converge here:\n * - the effect's typed error channel (`Failure`) → boxed with `defect: false`\n * - a defect raised *inside* the effect (`Die`) → boxed with `defect: true`\n * - the factory throwing before an `IO` exists → boxed with `defect: true`\n *\n * The third matters because running an effect never throws, but `io(input)` is\n * ordinary user code that can throw while building the effect. Without this, that\n * throw would escape unboxed and `error.error` would be `undefined` despite the\n * declared type.\n *\n * The second is why this uses `runExit()` rather than `run()`. `run()` returns\n * `Either<E, A>`, which has nowhere to put a defect — a throwing `mapError` handler or\n * `IO.sync` thunk arrived as `Left` and was indistinguishable from a genuine `E`, so\n * `defect` read `false` while `.error` held something that was not an `E` at all\n * (#259). `Exit` keeps the two apart, so the flag can be accurate.\n *\n * The throws are confined to this function so no caller ever writes one.\n *\n * @interop React Query signals failure only by promise rejection; an Either return reads as success (#239).\n */\nconst runBoxed = async <E, A>(effect: () => IO<never, E, A>, options?: IOBridgeOptions<E>): Promise<A> => {\n const exit = await Try(() => effect()).fold(\n (thrown) => {\n throw new IOQueryError(thrown as E, undefined, true)\n },\n (io) => io.runExit(),\n )\n\n if (exit.isFailure()) {\n const { error } = exit.toValue() as { error: E }\n throw new IOQueryError(error, options?.formatError?.(error))\n }\n\n if (exit.isDie()) {\n throw new IOQueryError((exit.toValue() as { defect: unknown }).defect as E, undefined, true)\n }\n\n if (exit.isInterrupted()) {\n // An `InterruptedError` is no more an `E` than a defect is, so it carries the same\n // flag. `run()` put it in the `Left` with `defect: false`, which had the same problem\n // the rest of this fix is about.\n throw new IOQueryError(new InterruptedError() as E, undefined, true)\n }\n\n return exit.orThrow()\n}\n\n/**\n * Adapts an `IO<never, E, A>` into a React Query `queryFn`.\n *\n * `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that\n * carries the typed error on `.error`. Wire cancellation by closing over the supplied\n * `signal`:\n *\n * ```ts\n * useQuery({\n * queryKey: [\"connector-limits\", userId],\n * queryFn: ioQueryFn(({ signal }) => Http.get<Limits>(url, { headers, signal })),\n * enabled: !!userId,\n * })\n * ```\n */\nexport const ioQueryFn =\n <E, A, TContext extends IOQueryFnContext = IOQueryFnContext>(\n io: (context: TContext) => IO<never, E, A>,\n options?: IOBridgeOptions<E>,\n ) =>\n (context: TContext): Promise<A> =>\n runBoxed(() => io(context), options)\n\n/**\n * Adapts a variables-taking `IO<never, E, A>` into a React Query `mutationFn`.\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n *\n * ```ts\n * useMutation({\n * mutationFn: ioMutationFn((body: CreateTokenInput) => Http.post<Token>(url, { body })),\n * })\n * ```\n */\nexport const ioMutationFn =\n <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) =>\n (variables: V): Promise<A> =>\n runBoxed(() => io(variables), options)\n"],"mappings":"+HA+CA,MAAMA,EAAW,MAAa,EAA+B,IAA6C,CACxG,IAAMC,EAAO,MAAMC,MAAUC,EAAO,CAAC,CAAC,CAAC,KACpC,GAAW,CACV,MAAM,IAAIC,EAAaC,EAAa,IAAA,GAAW,EAAI,CACrD,EACC,GAAOC,EAAG,QAAQ,CACrB,EAEA,GAAIL,EAAK,UAAU,EAAG,CACpB,GAAM,CAAE,SAAUA,EAAK,QAAQ,EAC/B,MAAM,IAAIG,EAAaG,EAAOC,GAAS,cAAcD,CAAK,CAAC,CAC7D,CAEA,GAAIN,EAAK,MAAM,EACb,MAAM,IAAIG,EAAcH,EAAK,QAAQ,CAAC,CAAyB,OAAa,IAAA,GAAW,EAAI,EAG7F,GAAIA,EAAK,cAAc,EAIrB,MAAM,IAAIG,EAAa,IAAIK,EAAyB,IAAA,GAAW,EAAI,EAGrE,OAAOR,EAAK,QAAQ,CACtB,EAiBaS,GAET,EACA,IAED,GACCV,MAAeM,EAAGK,CAAO,EAAGH,CAAO,EAc1BI,GACM,EAAuC,IACvD,GACCZ,MAAeM,EAAGO,CAAS,EAAGL,CAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
+
//#region src/query/queryState.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Structural view of a React Query result — the discriminated shape this module
|
|
4
5
|
* actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the
|
|
@@ -28,7 +29,7 @@ export type MutationResultView<E, A> = {
|
|
|
28
29
|
readonly error: E;
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
|
-
* Projects a React Query result onto the package's `
|
|
32
|
+
* Projects a React Query result onto the package's `TaskState` ADT, so a query can
|
|
32
33
|
* be folded or matched exhaustively instead of read through `data && !error && !isLoading`.
|
|
33
34
|
*
|
|
34
35
|
* This is the whole point of `functype-react`: omitting a case becomes a compile
|
|
@@ -49,11 +50,11 @@ export type MutationResultView<E, A> = {
|
|
|
49
50
|
* ```
|
|
50
51
|
*
|
|
51
52
|
* A disabled query (`enabled: false`, never fetched) projects to `Idle`; an
|
|
52
|
-
* in-flight or paused one to `Pending`. Reuses the same `
|
|
53
|
-
* `functype-react/async`'s `
|
|
53
|
+
* in-flight or paused one to `Pending`. Reuses the same `TaskState` that
|
|
54
|
+
* `functype-react/async`'s `useTask` returns, so both async surfaces match alike.
|
|
54
55
|
*
|
|
55
56
|
* **Stale data on a failed refetch.** React Query keeps the last successful `data`
|
|
56
|
-
* while setting `status: "error"` when a *background refetch* fails. `
|
|
57
|
+
* while setting `status: "error"` when a *background refetch* fails. `TaskState` has
|
|
57
58
|
* no variant for "loaded, but the latest fetch failed", so that squashes to `Failure`
|
|
58
59
|
* and the still-held data is not surfaced through the ADT — a transient background
|
|
59
60
|
* failure will flip a loaded view to an error branch. This is the deliberate default:
|
|
@@ -66,10 +67,11 @@ export type MutationResultView<E, A> = {
|
|
|
66
67
|
* arise here, but it is worth knowing that `.error` is `E` by construction rather
|
|
67
68
|
* than by proof.
|
|
68
69
|
*/
|
|
69
|
-
export declare const toQueryState: <E, A>(result: QueryResultView<E, A>) =>
|
|
70
|
+
export declare const toQueryState: <E, A>(result: QueryResultView<E, A>) => TaskState<E, A>;
|
|
70
71
|
/**
|
|
71
|
-
* Projects a React Query mutation result onto `
|
|
72
|
+
* Projects a React Query mutation result onto `TaskState`. React Query models an
|
|
72
73
|
* unfired mutation as `status: "idle"`, which maps directly onto `Idle`.
|
|
73
74
|
*/
|
|
74
|
-
export declare const toMutationState: <E, A>(result: MutationResultView<E, A>) =>
|
|
75
|
+
export declare const toMutationState: <E, A>(result: MutationResultView<E, A>) => TaskState<E, A>;
|
|
76
|
+
//#endregion
|
|
75
77
|
//# sourceMappingURL=queryState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryState.js","names":["toQueryState","result","toMutationState"],"sources":["../../src/query/queryState.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"queryState.js","names":["toQueryState","result","toMutationState"],"sources":["../../src/query/queryState.ts"],"sourcesContent":["import type { TaskState } from \"../async/TaskState\"\n\n/**\n * Structural view of a React Query result — the discriminated shape this module\n * actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the\n * projection carries no `@tanstack/react-query` type dependency; `UseQueryResult`\n * satisfies it.\n */\nexport type QueryResultView<E, A> =\n | { readonly status: \"pending\"; readonly fetchStatus: \"fetching\" | \"paused\" | \"idle\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/** Structural view of a React Query mutation result. */\nexport type MutationResultView<E, A> =\n | { readonly status: \"idle\" }\n | { readonly status: \"pending\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/**\n * Projects a React Query result onto the package's `TaskState` ADT, so a query can\n * be folded or matched exhaustively instead of read through `data && !error && !isLoading`.\n *\n * This is the whole point of `functype-react`: omitting a case becomes a compile\n * error, and the success branch hands you a defined `A` rather than `A | undefined`\n * that needs a `!`.\n *\n * ```tsx\n * const query = useIOQuery([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={toQueryState(query)}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * A disabled query (`enabled: false`, never fetched) projects to `Idle`; an\n * in-flight or paused one to `Pending`. Reuses the same `TaskState` that\n * `functype-react/async`'s `useTask` returns, so both async surfaces match alike.\n *\n * **Stale data on a failed refetch.** React Query keeps the last successful `data`\n * while setting `status: \"error\"` when a *background refetch* fails. `TaskState` has\n * no variant for \"loaded, but the latest fetch failed\", so that squashes to `Failure`\n * and the still-held data is not surfaced through the ADT — a transient background\n * failure will flip a loaded view to an error branch. This is the deliberate default:\n * it never silently hides a failure. If you would rather keep rendering stale data,\n * read `query.data` directly alongside the projection, or branch on\n * `query.isRefetchError` before projecting.\n *\n * **Interruption.** `IO.run()` maps an interrupted effect to `Left(InterruptedError)`,\n * which is not an `E`. Nothing in this subpath interrupts effects, so it will not\n * arise here, but it is worth knowing that `.error` is `E` by construction rather\n * than by proof.\n */\nexport const toQueryState = <E, A>(result: QueryResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return result.fetchStatus === \"idle\" ? { _tag: \"Idle\" } : { _tag: \"Pending\" }\n }\n}\n\n/**\n * Projects a React Query mutation result onto `TaskState`. React Query models an\n * unfired mutation as `status: \"idle\"`, which maps directly onto `Idle`.\n */\nexport const toMutationState = <E, A>(result: MutationResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return { _tag: \"Pending\" }\n case \"idle\":\n return { _tag: \"Idle\" }\n }\n}\n"],"mappings":"AA2DA,MAAaA,EAAsB,GAAmD,CACpF,OAAQC,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EAChD,IAAK,UACH,OAAOA,EAAO,cAAgB,OAAS,CAAE,KAAM,MAAO,EAAI,CAAE,KAAM,SAAU,CAChF,CACF,EAMaC,EAAyB,GAAsD,CAC1F,OAAQD,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EAChD,IAAK,UACH,MAAO,CAAE,KAAM,SAAU,EAC3B,IAAK,OACH,MAAO,CAAE,KAAM,MAAO,CAC1B,CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IOQueryError } from "./IOQueryError.js";
|
|
2
2
|
import { IO } from "functype/io";
|
|
3
3
|
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
4
|
+
//#region src/query/useIOMutation.d.ts
|
|
4
5
|
export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
|
|
5
6
|
/** Override the derived `Error.message` on failure. */
|
|
6
7
|
readonly formatError?: (error: E) => string;
|
|
@@ -21,4 +22,5 @@ export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A,
|
|
|
21
22
|
* only the mutation variables.
|
|
22
23
|
*/
|
|
23
24
|
export declare function useIOMutation<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseMutationResult<A, IOQueryError<E>, V, TContext>;
|
|
25
|
+
//#endregion
|
|
24
26
|
//# sourceMappingURL=useIOMutation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOMutation.js","names":["useIOMutation","mutationOptions","options","useMutation","ioMutationFn","io"],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIOMutation.js","names":["useIOMutation","mutationOptions","options","useMutation","ioMutationFn","io"],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"+GAgCA,SAAgBA,EACd,EACA,EACoD,CACpD,GAAM,CAAE,cAAa,GAAGC,GAAoBC,GAAW,CAAC,EAExD,OAAOC,EAA6C,CAClD,GAAGF,EACH,WAAYG,EAAsBC,EAAI,CAAE,aAAY,CAAC,CACvD,CAAC,CACH"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
2
|
import { IOQueryError } from "./IOQueryError.js";
|
|
3
3
|
import { UseIOMutationOptions } from "./useIOMutation.js";
|
|
4
4
|
import { IO } from "functype/io";
|
|
5
5
|
import { UseMutationResult } from "@tanstack/react-query";
|
|
6
|
+
//#region src/query/useIOMutationState.d.ts
|
|
6
7
|
/**
|
|
7
|
-
* `
|
|
8
|
+
* `TaskState` plus the flags and the trigger functions. Unlike a query, a mutation is
|
|
8
9
|
* useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried
|
|
9
10
|
* through with React Query's own signatures.
|
|
10
11
|
*/
|
|
11
|
-
export type UseIOMutationStateResult<A, E, V, TContext> =
|
|
12
|
+
export type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> & Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, "mutate" | "mutateAsync" | "reset"> & {
|
|
12
13
|
readonly isIdle: boolean;
|
|
13
14
|
readonly isPending: boolean;
|
|
14
15
|
readonly isSuccess: boolean;
|
|
15
16
|
readonly isFailure: boolean;
|
|
16
17
|
};
|
|
17
18
|
/**
|
|
18
|
-
* `useIOMutation` projected onto the `
|
|
19
|
+
* `useIOMutation` projected onto the `TaskState` ADT, so a mutation's lifecycle matches
|
|
19
20
|
* exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.
|
|
20
21
|
*
|
|
21
22
|
* ```tsx
|
|
@@ -34,4 +35,5 @@ export type UseIOMutationStateResult<A, E, V, TContext> = AsyncState<IOQueryErro
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
export declare function useIOMutationState<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseIOMutationStateResult<A, E, V, TContext>;
|
|
38
|
+
//#endregion
|
|
37
39
|
//# sourceMappingURL=useIOMutationState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOMutationState.js","names":["useIOMutationState","mutation","useIOMutation","io","options","state","toMutationState"],"sources":["../../src/query/useIOMutationState.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useIOMutationState.js","names":["useIOMutationState","mutation","useIOMutation","io","options","state","toMutationState"],"sources":["../../src/query/useIOMutationState.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `TaskState` plus the flags and the trigger functions. Unlike a query, a mutation is\n * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried\n * through with React Query's own signatures.\n */\nexport type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> &\n Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, \"mutate\" | \"mutateAsync\" | \"reset\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOMutation` projected onto the `TaskState` ADT, so a mutation's lifecycle matches\n * exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.\n *\n * ```tsx\n * const create = useIOMutationState((body: CreateTokenInput) => Http.post<Token>(url, { body }))\n *\n * <button onClick={() => create.mutate({ name: \"ci\" })} disabled={create.isPending}>create</button>\n *\n * <Match value={create}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <TokenRow token={value} />,\n * }}\n * </Match>\n * ```\n */\nexport function useIOMutationState<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseIOMutationStateResult<A, E, V, TContext> {\n const mutation = useIOMutation(io, options)\n const state = toMutationState(mutation)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n reset: mutation.reset,\n }\n}\n"],"mappings":"kHA2CA,SAAgBA,EACd,EACA,EAC6C,CAC7C,IAAMC,EAAWC,EAAcC,EAAIC,CAAO,EACpCC,EAAQC,EAAgBL,CAAQ,EAEtC,MAAO,CACL,GAAGI,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,OAAQJ,EAAS,OACjB,YAAaA,EAAS,YACtB,MAAOA,EAAS,KAClB,CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IOQueryError } from "./IOQueryError.js";
|
|
2
2
|
import { IO } from "functype/io";
|
|
3
3
|
import { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
+
//#region src/query/useIOQuery.d.ts
|
|
4
5
|
export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>, "queryKey" | "queryFn"> & {
|
|
5
6
|
/** Override the derived `Error.message` on failure. */
|
|
6
7
|
readonly formatError?: (error: E) => string;
|
|
@@ -33,4 +34,5 @@ export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<Us
|
|
|
33
34
|
* `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.
|
|
34
35
|
*/
|
|
35
36
|
export declare function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseQueryResult<TData, IOQueryError<E>>;
|
|
37
|
+
//#endregion
|
|
36
38
|
//# sourceMappingURL=useIOQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOQuery.js","names":["useIOQuery","queryOptions","options","useQuery","ioQueryFn","io"],"sources":["../../src/query/useIOQuery.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from \"@tanstack/react-query\"\nimport { useQuery } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioQueryFn } from \"./ioQueryFn\"\n\nexport type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<\n UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>,\n \"queryKey\" | \"queryFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel\n * through to React Query's `error`.\n *\n * The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and\n * `error.message` behave normally while `error.error` stays fully discriminable:\n *\n * ```ts\n * const { data, error } = useIOQuery(\n * [\"connector-limits\", userId],\n * ({ signal }) => Http.get<Limits>(url, { headers, signal }),\n * { enabled: !!userId },\n * )\n *\n * if (error) {\n * HttpErrors.match(error.error, {\n * NetworkError: () => <Offline />,\n * HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),\n * DecodeError: () => <SchemaDrift />,\n * })\n * }\n * ```\n *\n * Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes\n * through untouched. For full control over the query object — or for\n * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.\n */\nexport function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseQueryResult<TData, IOQueryError<E>> {\n const { formatError, ...queryOptions } = options ?? {}\n\n return useQuery<A, IOQueryError<E>, TData, TQueryKey>({\n ...queryOptions,\n queryKey,\n queryFn: ioQueryFn<E, A, QueryFunctionContext<TQueryKey>>(io, { formatError }),\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIOQuery.js","names":["useIOQuery","queryOptions","options","useQuery","ioQueryFn","io"],"sources":["../../src/query/useIOQuery.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from \"@tanstack/react-query\"\nimport { useQuery } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioQueryFn } from \"./ioQueryFn\"\n\nexport type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<\n UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>,\n \"queryKey\" | \"queryFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel\n * through to React Query's `error`.\n *\n * The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and\n * `error.message` behave normally while `error.error` stays fully discriminable:\n *\n * ```ts\n * const { data, error } = useIOQuery(\n * [\"connector-limits\", userId],\n * ({ signal }) => Http.get<Limits>(url, { headers, signal }),\n * { enabled: !!userId },\n * )\n *\n * if (error) {\n * HttpErrors.match(error.error, {\n * NetworkError: () => <Offline />,\n * HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),\n * DecodeError: () => <SchemaDrift />,\n * })\n * }\n * ```\n *\n * Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes\n * through untouched. For full control over the query object — or for\n * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.\n */\nexport function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseQueryResult<TData, IOQueryError<E>> {\n const { formatError, ...queryOptions } = options ?? {}\n\n return useQuery<A, IOQueryError<E>, TData, TQueryKey>({\n ...queryOptions,\n queryKey,\n queryFn: ioQueryFn<E, A, QueryFunctionContext<TQueryKey>>(io, { formatError }),\n })\n}\n"],"mappings":"yGA4CA,SAAgBA,EACd,EACA,EACA,EACwC,CACxC,GAAM,CAAE,cAAa,GAAGC,GAAiBC,GAAW,CAAC,EAErD,OAAOC,EAA+C,CACpD,GAAGF,EACH,WACA,QAASG,EAAiDC,EAAI,CAAE,aAAY,CAAC,CAC/E,CAAC,CACH"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
2
|
import { IOQueryError } from "./IOQueryError.js";
|
|
3
3
|
import { UseIOQueryOptions } from "./useIOQuery.js";
|
|
4
4
|
import { IO } from "functype/io";
|
|
5
5
|
import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
|
|
6
|
+
//#region src/query/useIOQueryState.d.ts
|
|
6
7
|
/**
|
|
7
|
-
* `
|
|
8
|
-
* `
|
|
8
|
+
* `TaskState` plus the convenience flags and refetch trigger, mirroring
|
|
9
|
+
* `UseTaskResult` from `functype-react/async` so both async surfaces read alike.
|
|
9
10
|
*
|
|
10
11
|
* `refetch` keeps React Query's own signature rather than a lossy re-declaration.
|
|
11
12
|
*/
|
|
12
|
-
export type UseIOQueryStateResult<A, E> =
|
|
13
|
+
export type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<UseQueryResult<A, IOQueryError<E>>, "refetch"> & {
|
|
13
14
|
readonly isIdle: boolean;
|
|
14
15
|
readonly isPending: boolean;
|
|
15
16
|
readonly isSuccess: boolean;
|
|
16
17
|
readonly isFailure: boolean;
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
|
-
* `useIOQuery` projected straight onto the `
|
|
20
|
+
* `useIOQuery` projected straight onto the `TaskState` ADT — the flag-soup-free path
|
|
20
21
|
* in one call.
|
|
21
22
|
*
|
|
22
23
|
* ```tsx
|
|
@@ -39,4 +40,5 @@ export type UseIOQueryStateResult<A, E> = AsyncState<IOQueryError<E>, A> & Pick<
|
|
|
39
40
|
* {@link toQueryState} instead.
|
|
40
41
|
*/
|
|
41
42
|
export declare function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseIOQueryStateResult<TData, E>;
|
|
43
|
+
//#endregion
|
|
42
44
|
//# sourceMappingURL=useIOQueryState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOQueryState.js","names":["useIOQueryState","query","useIOQuery","queryKey","io","options","state","toQueryState"],"sources":["../../src/query/useIOQueryState.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useIOQueryState.js","names":["useIOQueryState","query","useIOQuery","queryKey","io","options","state","toQueryState"],"sources":["../../src/query/useIOQueryState.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `TaskState` plus the convenience flags and refetch trigger, mirroring\n * `UseTaskResult` from `functype-react/async` so both async surfaces read alike.\n *\n * `refetch` keeps React Query's own signature rather than a lossy re-declaration.\n */\nexport type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> &\n Pick<UseQueryResult<A, IOQueryError<E>>, \"refetch\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOQuery` projected straight onto the `TaskState` ADT — the flag-soup-free path\n * in one call.\n *\n * ```tsx\n * const user = useIOQueryState([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={user}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * Reads only `status` / `fetchStatus` / `data` / `error` / `refetch` off the query, so\n * React Query's tracked-properties optimization still applies — the component is not\n * subscribed to fields it never renders. When you need the rest of the result\n * (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with\n * {@link toQueryState} instead.\n */\nexport function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseIOQueryStateResult<TData, E> {\n const query = useIOQuery(queryKey, io, options)\n const state = toQueryState(query)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n refetch: query.refetch,\n }\n}\n"],"mappings":"yGAgDA,SAAgBA,EACd,EACA,EACA,EACiC,CACjC,IAAMC,EAAQC,EAAWC,EAAUC,EAAIC,CAAO,EACxCC,EAAQC,EAAaN,CAAK,EAEhC,MAAO,CACL,GAAGK,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,QAASL,EAAM,OACjB,CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Either } from "functype/either";
|
|
2
|
+
//#region src/hooks/useEither.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Stateful Either container. Defaults to Left(undefined) when no initial.
|
|
4
5
|
*/
|
|
@@ -8,5 +9,6 @@ declare function useEither<E, A>(initial?: Either<E, A>): {
|
|
|
8
9
|
setLeft: (e: E) => void;
|
|
9
10
|
fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R;
|
|
10
11
|
};
|
|
12
|
+
//#endregion
|
|
11
13
|
export { useEither as t };
|
|
12
|
-
//# sourceMappingURL=useEither-
|
|
14
|
+
//# sourceMappingURL=useEither-DyPW7OaA.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { List } from "functype/list";
|
|
2
|
+
//#region src/hooks/useList.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Stateful immutable List container. All mutators return new state.
|
|
4
5
|
*/
|
|
@@ -11,5 +12,6 @@ declare function useList<A>(initial?: readonly A[]): {
|
|
|
11
12
|
map: <B>(f: (a: A) => B) => List<B>;
|
|
12
13
|
filter: (p: (a: A) => boolean) => List<A>;
|
|
13
14
|
};
|
|
15
|
+
//#endregion
|
|
14
16
|
export { useList as t };
|
|
15
|
-
//# sourceMappingURL=useList-
|
|
17
|
+
//# sourceMappingURL=useList-B5Iox1xv.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Option } from "functype/option";
|
|
2
|
+
//#region src/hooks/useOption.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Stateful Option container. `set(null | undefined)` clears to None.
|
|
4
5
|
*
|
|
@@ -11,5 +12,6 @@ declare function useOption<A>(initial?: A): {
|
|
|
11
12
|
map: <B>(f: (a: A) => B) => Option<B>;
|
|
12
13
|
fold: <R>(onNone: () => R, onSome: (a: A) => R) => R;
|
|
13
14
|
};
|
|
15
|
+
//#endregion
|
|
14
16
|
export { useOption as t };
|
|
15
|
-
//# sourceMappingURL=useOption-
|
|
17
|
+
//# sourceMappingURL=useOption-CXXNC1_S.d.ts.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-
|
|
1
|
+
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList } from "react";
|
|
3
|
+
//#region src/hooks/useStableCallback.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Like `useCallback`, but only returns a new function when *some* dep has
|
|
5
6
|
* changed under the supplied (or default) comparator.
|
|
6
7
|
*/
|
|
7
8
|
declare function useStableCallback<F extends (...args: never[]) => unknown>(callback: F, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): F;
|
|
9
|
+
//#endregion
|
|
8
10
|
export { useStableCallback as t };
|
|
9
|
-
//# sourceMappingURL=useStableCallback-
|
|
11
|
+
//# sourceMappingURL=useStableCallback-CXQQOhl6.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-
|
|
1
|
+
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList, EffectCallback } from "react";
|
|
3
|
+
//#region src/hooks/useStableEffect.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Like `useEffect`, but re-runs only when *some* dep has changed under the
|
|
5
6
|
* supplied (or default) comparator. The `eqs` array is aligned positionally
|
|
@@ -9,5 +10,6 @@ import { DependencyList, EffectCallback } from "react";
|
|
|
9
10
|
* structural identity is what matters, but whose references churn every render.
|
|
10
11
|
*/
|
|
11
12
|
declare function useStableEffect(effect: EffectCallback, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): void;
|
|
13
|
+
//#endregion
|
|
12
14
|
export { useStableEffect as t };
|
|
13
|
-
//# sourceMappingURL=useStableEffect-
|
|
15
|
+
//# sourceMappingURL=useStableEffect-C-5NCd1T.d.ts.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-
|
|
1
|
+
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList } from "react";
|
|
3
|
+
//#region src/hooks/useStableMemo.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Like `useMemo`, but recomputes only when *some* dep has changed under the
|
|
5
6
|
* supplied (or default) comparator. The `eqs` array is aligned positionally
|
|
6
7
|
* with `deps`; missing entries fall back to `referenceEq`.
|
|
7
8
|
*/
|
|
8
9
|
declare function useStableMemo<A>(factory: () => A, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): A;
|
|
10
|
+
//#endregion
|
|
9
11
|
export { useStableMemo as t };
|
|
10
|
-
//# sourceMappingURL=useStableMemo-
|
|
12
|
+
//# sourceMappingURL=useStableMemo-PYyLBWwd.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-
|
|
1
|
+
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
|
+
//#region src/hooks/useStableState.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Drop-in replacement for `useState` that no-ops when the next value is equal
|
|
4
5
|
* to the current under `eq`. Defaults to `Object.is` (React's built-in), so the
|
|
@@ -8,5 +9,6 @@ import { t as Eq } from "./eq-CR56QmPb.js";
|
|
|
8
9
|
* @param eq - Comparator used to decide whether to skip the update
|
|
9
10
|
*/
|
|
10
11
|
declare function useStableState<A>(initial: A | (() => A), eq?: Eq<A>): readonly [A, (next: A | ((prev: A) => A)) => void];
|
|
12
|
+
//#endregion
|
|
11
13
|
export { useStableState as t };
|
|
12
|
-
//# sourceMappingURL=useStableState-
|
|
14
|
+
//# sourceMappingURL=useStableState-fi6nURHS.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Try } from "functype/try";
|
|
2
|
+
//#region src/hooks/useTry.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Stateful Try container. Defaults to Failure(new Error("uninitialized")) when no initial.
|
|
4
5
|
*/
|
|
@@ -8,5 +9,6 @@ declare function useTry<A>(initial?: Try<A>): {
|
|
|
8
9
|
setFailure: (e: Error) => void;
|
|
9
10
|
fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R;
|
|
10
11
|
};
|
|
12
|
+
//#endregion
|
|
11
13
|
export { useTry as t };
|
|
12
|
-
//# sourceMappingURL=useTry-
|
|
14
|
+
//# sourceMappingURL=useTry-B0HIcFFb.d.ts.map
|