functype-react 1.27.2 → 2.1.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 +22 -35
- package/dist/AsyncState-zTPspeWC.d.ts +20 -0
- package/dist/async/AsyncState.d.ts +2 -0
- package/dist/async/index.d.ts +7 -10
- package/dist/async/index.js +1 -1
- package/dist/async/index.js.map +1 -1
- package/dist/async/useIO.d.ts +26 -0
- package/dist/async/useIO.js +2 -0
- package/dist/async/useIO.js.map +1 -0
- package/dist/async/useIOPromise.d.ts +14 -0
- package/dist/async/useIOPromise.js +2 -0
- package/dist/async/useIOPromise.js.map +1 -0
- package/dist/async/useIOValue.d.ts +23 -0
- package/dist/async/useIOValue.js +2 -0
- package/dist/async/useIOValue.js.map +1 -0
- package/dist/{eq-CK6oQqWG.d.ts → eq-cYnbruZq.d.ts} +9 -7
- package/dist/forms/Validated.d.ts +1 -4
- package/dist/forms/Validated.js.map +1 -1
- package/dist/forms/index.d.ts +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/useValidatedField.d.ts +3 -6
- package/dist/forms/useValidatedField.js +1 -1
- package/dist/forms/useValidatedField.js.map +1 -1
- package/dist/forms/useValidatedForm.d.ts +3 -6
- package/dist/forms/useValidatedForm.js +1 -1
- package/dist/forms/useValidatedForm.js.map +1 -1
- package/dist/hooks/eq.d.ts +1 -1
- package/dist/hooks/eq.js +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 +1 -1
- package/dist/hooks/useList.js.map +1 -1
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js +1 -1
- package/dist/hooks/useOption.js.map +1 -1
- package/dist/hooks/useStableCallback.d.ts +1 -1
- package/dist/hooks/useStableCallback.js +1 -1
- package/dist/hooks/useStableCallback.js.map +1 -1
- package/dist/hooks/useStableEffect.d.ts +1 -1
- package/dist/hooks/useStableEffect.js +1 -1
- package/dist/hooks/useStableEffect.js.map +1 -1
- package/dist/hooks/useStableMemo.d.ts +1 -1
- package/dist/hooks/useStableMemo.js +1 -1
- package/dist/hooks/useStableMemo.js.map +1 -1
- package/dist/hooks/useStableState.d.ts +1 -1
- package/dist/hooks/useStableState.js +1 -1
- package/dist/hooks/useStableState.js.map +1 -1
- package/dist/hooks/useTry.d.ts +1 -1
- package/dist/hooks/useTry.js +1 -1
- package/dist/hooks/useTry.js.map +1 -1
- package/dist/{index-DjzwkXMF.d.ts → index-Byicsy1U.d.ts} +2 -11
- package/dist/index.d.ts +18 -10
- package/dist/index.js +1 -1
- package/dist/match/index.d.ts +1 -1
- package/dist/match/index.js +1 -1
- package/dist/{match-CkGESkj9.js → match-BnD70A5l.js} +1 -1
- package/dist/match-BnD70A5l.js.map +1 -0
- package/dist/query/IOQueryError.d.ts +1 -4
- package/dist/query/IOQueryError.js +1 -1
- package/dist/query/IOQueryError.js.map +1 -1
- package/dist/query/index.d.ts +18 -0
- package/dist/query/ioQueryFn.d.ts +4 -6
- package/dist/query/ioQueryFn.js +1 -1
- package/dist/query/ioQueryFn.js.map +1 -1
- package/dist/query/queryState.d.ts +11 -15
- package/dist/query/queryState.js.map +1 -1
- package/dist/query/useIOMutation.d.ts +3 -6
- package/dist/query/useIOMutation.js +1 -1
- package/dist/query/useIOMutation.js.map +1 -1
- package/dist/query/useIOMutationState.d.ts +7 -10
- package/dist/query/useIOMutationState.js.map +1 -1
- package/dist/query/useIOQuery.d.ts +3 -6
- package/dist/query/useIOQuery.js +1 -1
- package/dist/query/useIOQuery.js.map +1 -1
- package/dist/query/useIOQueryState.d.ts +8 -11
- package/dist/query/useIOQueryState.js.map +1 -1
- package/dist/{useEither-DyPW7OaA.d.ts → useEither-BveKCnsh.d.ts} +1 -4
- package/dist/{useList-B5Iox1xv.d.ts → useList-B83krQsi.d.ts} +1 -4
- package/dist/{useOption-CXXNC1_S.d.ts → useOption-C1VH3h20.d.ts} +1 -4
- package/dist/{useStableCallback-CXQQOhl6.d.ts → useStableCallback-C4UjxvJ1.d.ts} +2 -5
- package/dist/{useStableEffect-C-5NCd1T.d.ts → useStableEffect-CgkwQ5kY.d.ts} +2 -5
- package/dist/{useStableMemo-PYyLBWwd.d.ts → useStableMemo-KbV23mg-.d.ts} +2 -5
- package/dist/{useStableState-fi6nURHS.d.ts → useStableState-B-AaH7WY.d.ts} +2 -5
- package/dist/{useTry-B0HIcFFb.d.ts → useTry-B9VzXJLg.d.ts} +1 -4
- package/package.json +10 -11
- package/dist/TaskState-DWxGWqXf.d.ts +0 -24
- package/dist/async/TaskState.d.ts +0 -2
- package/dist/async/useTask.d.ts +0 -24
- package/dist/async/useTask.js +0 -2
- package/dist/async/useTask.js.map +0 -1
- package/dist/async/useTaskPromise.d.ts +0 -14
- package/dist/async/useTaskPromise.js +0 -2
- package/dist/async/useTaskPromise.js.map +0 -1
- package/dist/async/useTaskValue.d.ts +0 -24
- package/dist/async/useTaskValue.js +0 -2
- package/dist/async/useTaskValue.js.map +0 -1
- package/dist/match-CkGESkj9.js.map +0 -1
- /package/dist/async/{TaskState.js → AsyncState.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.js","names":["
|
|
1
|
+
{"version":3,"file":"useList.js","names":["List","useCallback","useMemo","useState","useList","initial","value","setValue","add","a","prev","remove","removeAt","index","clear","map","f","filter","p"],"sources":["../../src/hooks/useList.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype/list\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful immutable List container. All mutators return new state.\n */\nexport function useList<A>(initial?: readonly A[]): {\n readonly value: ListT<A>\n add: (a: A) => void\n remove: (a: A) => void\n removeAt: (index: number) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => ListT<B>\n filter: (p: (a: A) => boolean) => ListT<A>\n} {\n const [value, setValue] = useState<ListT<A>>(() => List<A>(initial ?? []))\n\n const add = useCallback((a: A) => setValue((prev) => prev.add(a) as ListT<A>), [])\n const remove = useCallback((a: A) => setValue((prev) => prev.remove(a)), [])\n const removeAt = useCallback((index: number) => setValue((prev) => prev.removeAt(index)), [])\n const clear = useCallback(() => setValue(List.empty<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const filter = useCallback((p: (a: A) => boolean) => value.filter(p), [value])\n\n return useMemo(\n () => ({ value, add, remove, removeAt, clear, map, filter }),\n [value, add, remove, removeAt, clear, map, filter],\n )\n}\n"],"mappings":"A,iHAQA,SAAgBI,EAAWC,EAQzB,CACA,GAAM,CAACC,EAAOC,GAAYJ,MAAyBH,EAAQK,GAAW,CAAC,CAAC,CAAC,EAEnEG,EAAMP,EAAaQ,GAASF,EAAUG,GAASA,EAAK,IAAID,CAAC,CAAa,EAAG,CAAC,CAAC,EAC3EE,EAASV,EAAaQ,GAASF,EAAUG,GAASA,EAAK,OAAOD,CAAC,CAAC,EAAG,CAAC,CAAC,EACrEG,EAAWX,EAAaY,GAAkBN,EAAUG,GAASA,EAAK,SAASG,CAAK,CAAC,EAAG,CAAC,CAAC,EACtFC,EAAQb,MAAkBM,EAASP,EAAK,MAAS,CAAC,EAAG,CAAC,CAAC,EAEvDe,EAAMd,EAAgBe,GAAmBV,EAAM,IAAIU,CAAC,EAAG,CAACV,CAAK,CAAC,EAC9DW,EAAShB,EAAaiB,GAAyBZ,EAAM,OAAOY,CAAC,EAAG,CAACZ,CAAK,CAAC,EAE7E,OAAOJ,OACE,CAAEI,QAAOE,MAAKG,SAAQC,WAAUE,QAAOC,MAAKE,QAAO,GAC1D,CAACX,EAAOE,EAAKG,EAAQC,EAAUE,EAAOC,EAAKE,CAAM,CACnD,CACF,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useOption } from "../useOption-
|
|
1
|
+
import { t as useOption } from "../useOption-C1VH3h20.js";
|
|
2
2
|
export { useOption };
|
package/dist/hooks/useOption.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{Option as e}from"functype/option";import{useCallback as t,useMemo as n,useState as r}from"react";function i(i){let[a,o]=r(()=>e(i)),s=t(t=>o(e(t)),[]),c=t(()=>o(e.none()),[]),l=t(e=>a.map(e),[a]),u=t((e,t)=>a.fold(e,t),[a]);return n(()=>({value:a,set:s,clear:c,map:l,fold:u}),[a,s,c,l,u])}export{i as useOption};
|
|
2
2
|
//# sourceMappingURL=useOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOption.js","names":["
|
|
1
|
+
{"version":3,"file":"useOption.js","names":["Option","useCallback","useMemo","useState","useOption","initial","value","setValue","set","a","clear","map","f","fold","onNone","onSome"],"sources":["../../src/hooks/useOption.ts"],"sourcesContent":["\"use client\"\n\nimport { Option, type Option as OptionT } from \"functype/option\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Option container. `set(null | undefined)` clears to None.\n *\n * @interop This hook converts nullable JS values into Option, so `initial` and `set` must accept them.\n */\nexport function useOption<A>(initial?: A): {\n readonly value: OptionT<A>\n set: (a: A | null | undefined) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => OptionT<B>\n fold: <R>(onNone: () => R, onSome: (a: A) => R) => R\n} {\n const [value, setValue] = useState<OptionT<A>>(() => Option<A>(initial))\n\n const set = useCallback((a: A | null | undefined) => setValue(Option<A>(a)), [])\n const clear = useCallback(() => setValue(Option.none<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const fold = useCallback(<R>(onNone: () => R, onSome: (a: A) => R) => value.fold(onNone, onSome), [value])\n\n return useMemo(() => ({ value, set, clear, map, fold }), [value, set, clear, map, fold])\n}\n"],"mappings":"A,qHAUA,SAAgBI,EAAaC,EAM3B,CACA,GAAM,CAACC,EAAOC,GAAYJ,MAA2BH,EAAUK,CAAO,CAAC,EAEjEG,EAAMP,EAAaQ,GAA4BF,EAASP,EAAUS,CAAC,CAAC,EAAG,CAAC,CAAC,EACzEC,EAAQT,MAAkBM,EAASP,EAAO,KAAQ,CAAC,EAAG,CAAC,CAAC,EAExDW,EAAMV,EAAgBW,GAAmBN,EAAM,IAAIM,CAAC,EAAG,CAACN,CAAK,CAAC,EAC9DO,EAAOZ,GAAgBa,EAAiBC,IAAwBT,EAAM,KAAKQ,EAAQC,CAAM,EAAG,CAACT,CAAK,CAAC,EAEzG,OAAOJ,OAAe,CAAEI,QAAOE,MAAKE,QAAOC,MAAKE,MAAK,GAAI,CAACP,EAAOE,EAAKE,EAAOC,EAAKE,CAAI,CAAC,CACzF,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableCallback } from "../useStableCallback-
|
|
1
|
+
import { t as useStableCallback } from "../useStableCallback-C4UjxvJ1.js";
|
|
2
2
|
export { useStableCallback };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useCallback as e,useRef as t}from"react";import{referenceEq as n}from"./eq.js";function r(r,i,a){let o=t(null),s=t(0);if(o.current===null)o.current=i,s.current+=1;else{let e=o.current;i.some((t,r)=>!(a?.[r]??n)(e[r],t))&&(o.current=i,s.current+=1)}return e(r,[s.current])}export{r as useStableCallback};
|
|
2
2
|
//# sourceMappingURL=useStableCallback.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableCallback.js","names":["
|
|
1
|
+
{"version":3,"file":"useStableCallback.js","names":["useCallback","useRef","referenceEq","useStableCallback","callback","deps","eqs","prev","tick","stale","d","i"],"sources":["../../src/hooks/useStableCallback.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, useCallback, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useCallback`, but only returns a new function when *some* dep has\n * changed under the supplied (or default) comparator.\n */\nexport function useStableCallback<F extends (...args: never[]) => unknown>(\n callback: F,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): F {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n return useCallback(callback, [tick.current]) as F\n}\n"],"mappings":"A,mGAUA,SAAgBG,EACdC,EACAC,EAEAC,EACG,CACH,IAAMC,EAAON,EAA8B,IAAI,EACzCO,EAAOP,EAAO,CAAC,EAErB,GAAIM,EAAK,UAAY,KACnBA,EAAK,QAAUF,EACfG,EAAK,SAAW,MACX,CACL,IAAMC,EAAQF,EAAK,QACHF,EAAK,MAAMK,EAAGC,IAErB,EADKL,IAAMK,IAAMT,EAAA,CACZO,EAAME,GAAID,CAAC,CAEf,IACRH,EAAK,QAAUF,EACfG,EAAK,SAAW,EAEpB,CAEA,OAAOR,EAAYI,EAAU,CAACI,EAAK,OAAO,CAAC,CAC7C,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableEffect } from "../useStableEffect-
|
|
1
|
+
import { t as useStableEffect } from "../useStableEffect-CgkwQ5kY.js";
|
|
2
2
|
export { useStableEffect };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useEffect as e,useRef as t}from"react";import{referenceEq as n}from"./eq.js";function r(r,i,a){let o=t(null),s=t(0);if(o.current===null)o.current=i,s.current+=1;else{let e=o.current;i.some((t,r)=>!(a?.[r]??n)(e[r],t))&&(o.current=i,s.current+=1)}e(r,[s.current])}export{r as useStableEffect};
|
|
2
2
|
//# sourceMappingURL=useStableEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableEffect.js","names":["
|
|
1
|
+
{"version":3,"file":"useStableEffect.js","names":["useEffect","useRef","referenceEq","useStableEffect","effect","deps","eqs","prev","tick","stale","d","i"],"sources":["../../src/hooks/useStableEffect.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, type EffectCallback, useEffect, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useEffect`, but re-runs only when *some* dep has changed under the\n * supplied (or default) comparator. The `eqs` array is aligned positionally\n * with `deps`; missing entries fall back to `referenceEq`.\n *\n * Useful when deps include functype ADTs (`Option`, `Either`, etc.) whose\n * structural identity is what matters, but whose references churn every render.\n */\nexport function useStableEffect(\n effect: EffectCallback,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): void {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n useEffect(effect, [tick.current])\n}\n"],"mappings":"A,iGAcA,SAAgBG,EACdC,EACAC,EAEAC,EACM,CACN,IAAMC,EAAON,EAA8B,IAAI,EACzCO,EAAOP,EAAO,CAAC,EAErB,GAAIM,EAAK,UAAY,KACnBA,EAAK,QAAUF,EACfG,EAAK,SAAW,MACX,CACL,IAAMC,EAAQF,EAAK,QACHF,EAAK,MAAMK,EAAGC,IAErB,EADKL,IAAMK,IAAMT,EAAA,CACZO,EAAME,GAAID,CAAC,CAEf,IACRH,EAAK,QAAUF,EACfG,EAAK,SAAW,EAEpB,CAEAR,EAAUI,EAAQ,CAACI,EAAK,OAAO,CAAC,CAClC,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableMemo } from "../useStableMemo-
|
|
1
|
+
import { t as useStableMemo } from "../useStableMemo-KbV23mg-.js";
|
|
2
2
|
export { useStableMemo };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useMemo as e,useRef as t}from"react";import{referenceEq as n}from"./eq.js";function r(r,i,a){let o=t(null),s=t(0);if(o.current===null)o.current=i,s.current+=1;else{let e=o.current;i.some((t,r)=>!(a?.[r]??n)(e[r],t))&&(o.current=i,s.current+=1)}return e(r,[s.current])}export{r as useStableMemo};
|
|
2
2
|
//# sourceMappingURL=useStableMemo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableMemo.js","names":["
|
|
1
|
+
{"version":3,"file":"useStableMemo.js","names":["useMemo","useRef","referenceEq","useStableMemo","factory","deps","eqs","prev","tick","stale","d","i"],"sources":["../../src/hooks/useStableMemo.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, useMemo, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useMemo`, but recomputes only when *some* dep has changed under the\n * supplied (or default) comparator. The `eqs` array is aligned positionally\n * with `deps`; missing entries fall back to `referenceEq`.\n */\nexport function useStableMemo<A>(\n factory: () => A,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): A {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n return useMemo(factory, [tick.current])\n}\n"],"mappings":"A,+FAWA,SAAgBG,EACdC,EACAC,EAEAC,EACG,CACH,IAAMC,EAAON,EAA8B,IAAI,EACzCO,EAAOP,EAAO,CAAC,EAErB,GAAIM,EAAK,UAAY,KACnBA,EAAK,QAAUF,EACfG,EAAK,SAAW,MACX,CACL,IAAMC,EAAQF,EAAK,QACHF,EAAK,MAAMK,EAAGC,IAErB,EADKL,IAAMK,IAAMT,EAAA,CACZO,EAAME,GAAID,CAAC,CAEf,IACRH,EAAK,QAAUF,EACfG,EAAK,SAAW,EAEpB,CAEA,OAAOR,EAAQI,EAAS,CAACI,EAAK,OAAO,CAAC,CACxC,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableState } from "../useStableState-
|
|
1
|
+
import { t as useStableState } from "../useStableState-B-AaH7WY.js";
|
|
2
2
|
export { useStableState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useCallback as e,useRef as t,useState as n}from"react";import{referenceEq as r}from"./eq.js";function i(i,a=r){let[o,s]=n(i),c=t(o);return c.current=o,[o,e(e=>{let t=typeof e==`function`?e(c.current):e;a(c.current,t)||s(t)},[a])]}export{i as useStableState};
|
|
2
2
|
//# sourceMappingURL=useStableState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableState.js","names":["
|
|
1
|
+
{"version":3,"file":"useStableState.js","names":["useCallback","useRef","useState","referenceEq","useStableState","initial","eq","value","setValue","ref","next","resolved"],"sources":["../../src/hooks/useStableState.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useRef, useState } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Drop-in replacement for `useState` that no-ops when the next value is equal\n * to the current under `eq`. Defaults to `Object.is` (React's built-in), so the\n * behavior is identical to `useState` unless an `eq` is supplied.\n *\n * @param initial - Initial value or a lazy producer (called once)\n * @param eq - Comparator used to decide whether to skip the update\n */\nexport function useStableState<A>(\n initial: A | (() => A),\n eq: Eq<A> = referenceEq as Eq<A>,\n): readonly [A, (next: A | ((prev: A) => A)) => void] {\n const [value, setValue] = useState<A>(initial)\n const ref = useRef<A>(value)\n ref.current = value\n\n const setStable = useCallback(\n (next: A | ((prev: A) => A)) => {\n const resolved = typeof next === \"function\" ? (next as (prev: A) => A)(ref.current) : next\n if (!eq(ref.current, resolved)) {\n setValue(resolved)\n }\n },\n [eq],\n )\n\n return [value, setStable] as const\n}\n"],"mappings":"A,iHAcA,SAAgBI,EACdC,EACAC,EAAYH,EACwC,CACpD,GAAM,CAACI,EAAOC,GAAYN,EAAYG,CAAO,EACvCI,EAAMR,EAAUM,CAAK,EAa3B,MAZAE,GAAI,QAAUF,EAYP,CAACA,EAVUP,EACfU,GAA+B,CAC9B,IAAMC,EAAW,OAAOD,GAAS,WAAcA,EAAwBD,EAAI,OAAO,EAAIC,EACjFJ,EAAGG,EAAI,QAASE,CAAQ,GAC3BH,EAASG,CAAQ,CAErB,EACA,CAACL,CAAE,CAGkB,CAAC,CAC1B,C"}
|
package/dist/hooks/useTry.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useTry } from "../useTry-
|
|
1
|
+
import { t as useTry } from "../useTry-B9VzXJLg.js";
|
|
2
2
|
export { useTry };
|
package/dist/hooks/useTry.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{Try as e}from"functype/try";import{useCallback as t,useMemo as n,useState as r}from"react";function i(i){let[a,o]=r(()=>i??e.failure(/* @__PURE__ */ Error(`uninitialized`))),s=t(t=>o(e.success(t)),[]),c=t(t=>o(e.failure(t)),[]),l=t((e,t)=>a.fold(e,t),[a]);return n(()=>({value:a,setSuccess:s,setFailure:c,fold:l}),[a,s,c,l])}export{i as useTry};
|
|
2
2
|
//# sourceMappingURL=useTry.js.map
|
package/dist/hooks/useTry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTry.js","names":["
|
|
1
|
+
{"version":3,"file":"useTry.js","names":["Try","useCallback","useMemo","useState","useTry","initial","value","setValue","setSuccess","a","setFailure","e","fold","onFailure","onSuccess"],"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":"A,+GAQA,SAAgBI,EAAUC,EAKxB,CACA,GAAM,CAACC,EAAOC,GAAYJ,MAAwBE,GAAWL,EAAI,QAAW,gBAAI,MAAM,eAAe,CAAC,CAAC,EAEjGQ,EAAaP,EAAaQ,GAASF,EAASP,EAAI,QAAQS,CAAC,CAAC,EAAG,CAAC,CAAC,EAC/DC,EAAaT,EAAaU,GAAaJ,EAASP,EAAI,QAAWW,CAAC,CAAC,EAAG,CAAC,CAAC,EAEtEC,EAAOX,GACPY,EAA4BC,IAA2BR,EAAM,KAAKO,EAAWC,CAAS,EAC1F,CAACR,CAAK,CACR,EAEA,OAAOJ,OAAe,CAAEI,QAAOE,aAAYE,aAAYE,MAAK,GAAI,CAACN,EAAOE,EAAYE,EAAYE,CAAI,CAAC,CACvG,C"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Either } from "functype/either";
|
|
2
1
|
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Either } from "functype/either";
|
|
3
3
|
import { Option } from "functype/option";
|
|
4
4
|
import { Try } from "functype/try";
|
|
5
|
-
//#region src/match/Match.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Maps each `_tag` literal to a handler that receives the narrowed variant.
|
|
8
7
|
*
|
|
@@ -35,8 +34,6 @@ declare function Match<U extends {
|
|
|
35
34
|
readonly value: U;
|
|
36
35
|
readonly children: MatchCases<U>;
|
|
37
36
|
}): ReactElement;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/match/MatchEither.d.ts
|
|
40
37
|
/**
|
|
41
38
|
* Tag-narrowed sugar over `Match` for `Either<L, R>`.
|
|
42
39
|
*/
|
|
@@ -45,8 +42,6 @@ declare function MatchEither<L, R>(props: {
|
|
|
45
42
|
readonly Left: (l: L) => ReactNode;
|
|
46
43
|
readonly Right: (r: R) => ReactNode;
|
|
47
44
|
}): ReactElement;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/match/MatchOption.d.ts
|
|
50
45
|
/**
|
|
51
46
|
* Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the
|
|
52
47
|
* `Some` handler and `None` to the `None` handler.
|
|
@@ -56,8 +51,6 @@ declare function MatchOption<A>(props: {
|
|
|
56
51
|
readonly Some: (a: A) => ReactNode;
|
|
57
52
|
readonly None: () => ReactNode;
|
|
58
53
|
}): ReactElement;
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/match/MatchTry.d.ts
|
|
61
54
|
/**
|
|
62
55
|
* Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the
|
|
63
56
|
* underlying `Error`; `Success` receives the value.
|
|
@@ -67,6 +60,4 @@ declare function MatchTry<A>(props: {
|
|
|
67
60
|
readonly Success: (a: A) => ReactNode;
|
|
68
61
|
readonly Failure: (e: Error) => ReactNode;
|
|
69
62
|
}): ReactElement;
|
|
70
|
-
|
|
71
|
-
export { MatchCases as a, Match as i, MatchOption as n, MatchEither as r, MatchTry as t };
|
|
72
|
-
//# sourceMappingURL=index-DjzwkXMF.d.ts.map
|
|
63
|
+
export { MatchCases as a, Match as i, MatchOption as n, MatchEither as r, MatchTry as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { t as
|
|
1
|
+
/**
|
|
2
|
+
* `functype-react` — React bindings for the functype FP library.
|
|
3
|
+
*
|
|
4
|
+
* The main entry re-exports Tier 1 (stable hooks + ADT hooks) and Tier 2
|
|
5
|
+
* (Match family components) — the surface most apps will touch. Tier 3
|
|
6
|
+
* (`./async`) and Tier 4 (`./forms`) stay subpath-only so that consumers
|
|
7
|
+
* who don't need Suspense/async or applicative forms tree-shake them out.
|
|
8
|
+
*/
|
|
9
|
+
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-cYnbruZq.js";
|
|
10
|
+
import { t as useEither } from "./useEither-BveKCnsh.js";
|
|
11
|
+
import { t as useList } from "./useList-B83krQsi.js";
|
|
12
|
+
import { t as useOption } from "./useOption-C1VH3h20.js";
|
|
13
|
+
import { t as useStableCallback } from "./useStableCallback-C4UjxvJ1.js";
|
|
14
|
+
import { t as useStableEffect } from "./useStableEffect-CgkwQ5kY.js";
|
|
15
|
+
import { t as useStableMemo } from "./useStableMemo-KbV23mg-.js";
|
|
16
|
+
import { t as useStableState } from "./useStableState-B-AaH7WY.js";
|
|
17
|
+
import { t as useTry } from "./useTry-B9VzXJLg.js";
|
|
10
18
|
import "./hooks/index.js";
|
|
11
|
-
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-
|
|
19
|
+
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-Byicsy1U.js";
|
|
12
20
|
export { type Eq, Match, type MatchCases, MatchEither, MatchOption, MatchTry, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{referenceEq as e,structuralEq as t,tagEq as n}from"./hooks/eq.js";import{useEither as r}from"./hooks/useEither.js";import{useList as i}from"./hooks/useList.js";import{useOption as a}from"./hooks/useOption.js";import{useStableCallback as o}from"./hooks/useStableCallback.js";import{useStableEffect as s}from"./hooks/useStableEffect.js";import{useStableMemo as c}from"./hooks/useStableMemo.js";import{useStableState as l}from"./hooks/useStableState.js";import{useTry as u}from"./hooks/useTry.js";import"./hooks/index.js";import{i as d,n as f,r as p,t as m}from"./match-
|
|
1
|
+
import{referenceEq as e,structuralEq as t,tagEq as n}from"./hooks/eq.js";import{useEither as r}from"./hooks/useEither.js";import{useList as i}from"./hooks/useList.js";import{useOption as a}from"./hooks/useOption.js";import{useStableCallback as o}from"./hooks/useStableCallback.js";import{useStableEffect as s}from"./hooks/useStableEffect.js";import{useStableMemo as c}from"./hooks/useStableMemo.js";import{useStableState as l}from"./hooks/useStableState.js";import{useTry as u}from"./hooks/useTry.js";import"./hooks/index.js";import{i as d,n as f,r as p,t as m}from"./match-BnD70A5l.js";export{d as Match,p as MatchEither,f as MatchOption,m as MatchTry,e as referenceEq,t as structuralEq,n as tagEq,r as useEither,i as useList,a as useOption,o as useStableCallback,s as useStableEffect,c as useStableMemo,l as useStableState,u as 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-Byicsy1U.js";
|
|
2
2
|
export { Match, type MatchCases, MatchEither, MatchOption, MatchTry };
|
package/dist/match/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{i as Match,r as MatchEither,n as MatchOption,t as MatchTry}from"../match-BnD70A5l.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{Fragment as e,jsx as t}from"react/jsx-runtime";function n(n){let r=n.children[n.value._tag];return/* @__PURE__ */ t(e,{children:r(n.value)})}function r(n){return/* @__PURE__ */ t(e,{children:n.value.fold(n.Left,n.Right)})}function i(n){return/* @__PURE__ */ t(e,{children:n.value.fold(n.None,n.Some)})}function a(n){return/* @__PURE__ */ t(e,{children:n.value.fold(n.Failure,n.Success)})}export{n as i,i as n,r,a as t};
|
|
2
|
-
//# sourceMappingURL=match-
|
|
2
|
+
//# sourceMappingURL=match-BnD70A5l.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-BnD70A5l.js","names":["Fragment","jsx","Match","props","handler","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":"A,sDA2BA,SAAgBE,EAAkCC,EAGjC,CACf,IAAMC,EAAUD,EAAM,SAASA,EAAM,MAAM,MAC3C,MAAOF,kBAAAD,EAAA,CAAA,SAAGI,EAAQD,EAAM,KAAK,CAAI,CAAA,CACnC,CC3BA,SAAgBE,EAAkBF,EAIjB,CACf,MAAOF,kBAAAD,EAAA,CAAA,SAAGG,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,KAAK,CAAI,CAAA,CACxD,CCLA,SAAgBG,EAAeH,EAId,CACf,MAAOF,kBAAAD,EAAA,CAAA,SAAGG,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,IAAI,CAAI,CAAA,CACvD,CCNA,SAAgBI,EAAYJ,EAIX,CACf,MAAOF,kBAAAD,EAAA,CAAA,SAAGG,EAAM,MAAM,KAAKA,EAAM,QAASA,EAAM,OAAO,CAAI,CAAA,CAC7D,C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/query/IOQueryError.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Derives a human-readable message from an arbitrary error channel value.
|
|
4
3
|
*
|
|
@@ -54,6 +53,4 @@ export declare class IOQueryError<E> extends Error {
|
|
|
54
53
|
constructor(error: E, message?: string, defect?: boolean);
|
|
55
54
|
}
|
|
56
55
|
/** Runtime guard for {@link IOQueryError}. */
|
|
57
|
-
export declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
|
|
58
|
-
//#endregion
|
|
59
|
-
//# sourceMappingURL=IOQueryError.d.ts.map
|
|
56
|
+
export declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Try as e}from"functype";const t=e=>typeof e==`object`&&!!e&&`_tag`in e&&typeof e._tag==`string`,n=n=>{if(n instanceof Error)return n.message;if(t(n)){let e=typeof n.url==`string`?` — ${n.url}`:``;if(typeof n.status==`number`){let t=typeof n.statusText==`string`&&n.statusText.length>0?` ${n.statusText}`:``;return`HTTP ${n.status}${t}${e}`}return typeof n.message==`string`&&n.message.length>0?n.message:`${n._tag}${e}`}return typeof n==`object`&&n?e(()=>JSON.stringify(n)).
|
|
1
|
+
import{Try as e}from"functype";const t=e=>typeof e==`object`&&!!e&&`_tag`in e&&typeof e._tag==`string`,n=n=>{if(n instanceof Error)return n.message;if(t(n)){let e=typeof n.url==`string`?` — ${n.url}`:``;if(typeof n.status==`number`){let t=typeof n.statusText==`string`&&n.statusText.length>0?` ${n.statusText}`:``;return`HTTP ${n.status}${t}${e}`}return typeof n.message==`string`&&n.message.length>0?n.message:`${n._tag}${e}`}return typeof n==`object`&&n?e(()=>JSON.stringify(n)).getOrElse(()=>String(n)):String(n)},r=(e,n)=>n||!t(e)||e._tag.length===0?`IOQueryError`:e._tag===`Throwable`&&typeof e.name==`string`&&e.name.length>0?e.name:e._tag;var i=class extends Error{constructor(e,t,i=!1){super(t??n(e),{cause:e}),this.name=r(e,i),this.error=e,this.defect=i}};const a=e=>e instanceof i;export{i as IOQueryError,n as formatIOError,a as isIOQueryError};
|
|
2
2
|
//# sourceMappingURL=IOQueryError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOQueryError.js","names":["isTaggedError","formatIOError","error","where","statusText","
|
|
1
|
+
{"version":3,"file":"IOQueryError.js","names":["Try","isTaggedError","formatIOError","error","where","statusText","nameOf","defect","IOQueryError","message","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 resolves a typed failure as a `Left` (so RQ never sees it), 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 name?: unknown\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)).getOrElse(() => String(error))\n }\n\n return String(error)\n}\n\n/**\n * What `name` reads for a boxed failure. Error trackers title and group by `name`, so a typed failure\n * takes its cause's tag (`OAuthFlowError`, `HttpStatusError`) and a closed popup doesn't land in the same\n * group as a 500. A defect's cause isn't an `E`, so it stays `IOQueryError`, whatever tag it carries.\n *\n * Every functype `Throwable` shares the tag `Throwable`, so one's specific name is in `.name`: a\n * `TypedError`'s code (`NOT_FOUND`), or a `Throwable`'s `taskInfo.name`.\n */\nconst nameOf = (error: unknown, defect: boolean): string => {\n if (defect || !isTaggedError(error) || error._tag.length === 0) return \"IOQueryError\"\n return error._tag === \"Throwable\" && typeof error.name === \"string\" && error.name.length > 0 ? error.name : error._tag\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 * error.name // \"HttpStatusError\"\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 = nameOf(error, defect)\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":"A,+BAyBA,MAAMC,EAAiB,GACrB,OAAO,GAAM,YAAY,GAAc,SAAU,GAAK,OAAQ,EAAwB,MAAS,SAWpFC,EAAiBC,GAA2B,CACvD,GAAIA,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,EACxBH,MAAU,KAAK,UAAUG,CAAK,CAAC,CAAC,CAAC,cAAgB,OAAOA,CAAK,CAAC,EAGhE,OAAOA,CAAK,CACrB,EAUMG,GAAUH,EAAgBI,IAC1BA,GAAU,CAACN,EAAcE,CAAK,GAAKA,EAAM,KAAK,SAAW,EAAU,eAChEA,EAAM,OAAS,aAAe,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,OAAS,EAAIA,EAAM,KAAOA,EAAM,KAoBpH,IAAaK,EAAb,cAAqC,KAAM,CA2BzC,YAAYL,EAAUM,EAAkBF,EAAS,GAAO,CACtD,MAAME,GAAWP,EAAcC,CAAK,EAAG,CAAE,MAAOA,CAAM,CAAC,EACvD,KAAK,KAAOG,EAAOH,EAAOI,CAAM,EAChC,KAAK,MAAQJ,EACb,KAAK,OAASI,CAChB,CACF,EAGA,MAAaG,EAA+BP,GAA6CA,aAAiBK,E"}
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `functype-react/query` — TanStack Query adapters for `IO`.
|
|
3
|
+
*
|
|
4
|
+
* Bridges `IO<never, E, A>` (e.g. the `Http` client from `functype/fetch`) onto React
|
|
5
|
+
* Query's resolve/reject contract, preserving the typed error channel that both
|
|
6
|
+
* `.run()` (resolves a typed failure as a `Left`) and `.runOrThrow()` (throws a non-`Error` tagged
|
|
7
|
+
* object) lose.
|
|
8
|
+
*
|
|
9
|
+
* Requires `@tanstack/react-query` — an *optional* peer dependency, so consumers who
|
|
10
|
+
* don't import this subpath neither install it nor bundle it.
|
|
11
|
+
*
|
|
12
|
+
* - `ioQueryFn` / `ioMutationFn` — framework-agnostic primitives; drop into any
|
|
13
|
+
* `useQuery` / `useSuspenseQuery` / `prefetchQuery` call for full option control.
|
|
14
|
+
* - `useIOQuery` / `useIOMutation` — the common path, one call.
|
|
15
|
+
* - `toQueryState` / `toMutationState` — project a React Query result onto the
|
|
16
|
+
* `AsyncState` ADT so it can be matched exhaustively with the `<Match>` family,
|
|
17
|
+
* rather than read through `data && !error && !isLoading` flag soup.
|
|
18
|
+
*/
|
|
1
19
|
import { IOQueryError, formatIOError, isIOQueryError } from "./IOQueryError.js";
|
|
2
20
|
import { IOBridgeOptions, IOQueryFnContext, ioMutationFn, ioQueryFn } from "./ioQueryFn.js";
|
|
3
21
|
import { MutationResultView, QueryResultView, toMutationState, toQueryState } from "./queryState.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IO } from "functype/io";
|
|
2
|
-
//#region src/query/ioQueryFn.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Minimal structural view of React Query's `QueryFunctionContext` — the floor that
|
|
5
4
|
* every context satisfies, and the default when nothing wider is inferred.
|
|
@@ -21,8 +20,9 @@ export type IOBridgeOptions<E> = {
|
|
|
21
20
|
* Adapts an `IO<never, E, A>` into a React Query `queryFn`.
|
|
22
21
|
*
|
|
23
22
|
* `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that
|
|
24
|
-
* carries the typed error on `.error`.
|
|
25
|
-
*
|
|
23
|
+
* carries the typed error on `.error`. The effect runs with React Query's `signal`, so a
|
|
24
|
+
* cancelled, unmounted or superseded query stops at its next step. To abort an in-flight
|
|
25
|
+
* request as well, close over the same `signal`:
|
|
26
26
|
*
|
|
27
27
|
* ```ts
|
|
28
28
|
* useQuery({
|
|
@@ -45,6 +45,4 @@ export declare const ioQueryFn: <E, A, TContext extends IOQueryFnContext = IOQue
|
|
|
45
45
|
* })
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
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
|
|
50
|
-
//# sourceMappingURL=ioQueryFn.d.ts.map
|
|
48
|
+
export declare const ioMutationFn: <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (variables: V) => Promise<A>;
|
package/dist/query/ioQueryFn.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Try as e}from"functype";import{InterruptedError as t}from"functype/io";import{IOQueryError as n}from"./IOQueryError.js";const r=async(r,i,a)=>{let o=await e(()=>r()).fold(e=>{throw new n(e,void 0,!0)},e=>e.runExit({signal:a}));if(o.isFailure()){let{error:e}=o.toValue();throw new n(e,i?.formatError?.(e))}if(o.isDie())throw new n(o.toValue().defect,void 0,!0);if(o.isInterrupted())throw new n(new t,void 0,!0);return o.orThrow()},i=(e,t)=>n=>r(()=>e(n),t,n.signal),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":["
|
|
1
|
+
{"version":3,"file":"ioQueryFn.js","names":["Try","InterruptedError","IOQueryError","runBoxed","effect","options","signal","exit","thrown","io","error","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 `runExit()` 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()`. Before 2.0, `run()` put a\n * defect in the `Left`, indistinguishable from a genuine `E` (#259). Since 2.0 it rejects\n * with the raw defect instead, which still carries nothing saying it is one. `Exit` keeps\n * 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>(\n effect: () => IO<never, E, A>,\n options?: IOBridgeOptions<E>,\n signal?: AbortSignal,\n): Promise<A> => {\n const exit = await Try(() => effect()).fold(\n (thrown) => {\n throw new IOQueryError(thrown as E, undefined, true)\n },\n // With the query's signal, a cancelled query stops at the effect's next step instead of\n // running on with its result discarded. It ends `Interrupted`, handled below.\n (io) => io.runExit({ signal }),\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. Before 2.0, `run()` put it in the `Left` with `defect: false`, which had the same\n // problem 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`. The effect runs with React Query's `signal`, so a\n * cancelled, unmounted or superseded query stops at its next step. To abort an in-flight\n * request as well, close over the same `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, context.signal)\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":"A,+HA8CA,MAAMG,EAAW,MACfC,EACAC,EACAC,IACe,CACf,IAAMC,EAAO,MAAMP,MAAUI,EAAO,CAAC,CAAC,CAAC,KACpCI,GAAW,CACV,MAAM,IAAIN,EAAaM,EAAa,IAAA,GAAW,EAAI,CACrD,EAGCC,GAAOA,EAAG,QAAQ,CAAEH,QAAO,CAAC,CAC/B,EAEA,GAAIC,EAAK,UAAU,EAAG,CACpB,GAAM,CAAEG,SAAUH,EAAK,QAAQ,EAC/B,MAAM,IAAIL,EAAaQ,EAAOL,GAAS,cAAcK,CAAK,CAAC,CAC7D,CAEA,GAAIH,EAAK,MAAM,EACb,MAAM,IAAIL,EAAcK,EAAK,QAAQ,CAAC,CAAyB,OAAa,IAAA,GAAW,EAAI,EAG7F,GAAIA,EAAK,cAAc,EAIrB,MAAM,IAAIL,EAAa,IAAID,EAAyB,IAAA,GAAW,EAAI,EAGrE,OAAOM,EAAK,QAAQ,CACtB,EAkBaI,GAETF,EACAJ,IAEDO,GACCT,MAAeM,EAAGG,CAAO,EAAGP,EAASO,EAAQ,MAAM,EAc1CC,GACMJ,EAAuCJ,IACvDS,GACCX,MAAeM,EAAGK,CAAS,EAAGT,CAAO,E"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
//#region src/query/queryState.d.ts
|
|
1
|
+
import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
|
|
3
2
|
/**
|
|
4
3
|
* Structural view of a React Query result — the discriminated shape this module
|
|
5
4
|
* actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the
|
|
@@ -29,7 +28,7 @@ export type MutationResultView<E, A> = {
|
|
|
29
28
|
readonly error: E;
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
32
|
-
* Projects a React Query result onto the package's `
|
|
31
|
+
* Projects a React Query result onto the package's `AsyncState` ADT, so a query can
|
|
33
32
|
* be folded or matched exhaustively instead of read through `data && !error && !isLoading`.
|
|
34
33
|
*
|
|
35
34
|
* This is the whole point of `functype-react`: omitting a case becomes a compile
|
|
@@ -50,11 +49,11 @@ export type MutationResultView<E, A> = {
|
|
|
50
49
|
* ```
|
|
51
50
|
*
|
|
52
51
|
* A disabled query (`enabled: false`, never fetched) projects to `Idle`; an
|
|
53
|
-
* in-flight or paused one to `Pending`. Reuses the same `
|
|
54
|
-
* `functype-react/async`'s `
|
|
52
|
+
* in-flight or paused one to `Pending`. Reuses the same `AsyncState` that
|
|
53
|
+
* `functype-react/async`'s `useIO` returns, so both async surfaces match alike.
|
|
55
54
|
*
|
|
56
55
|
* **Stale data on a failed refetch.** React Query keeps the last successful `data`
|
|
57
|
-
* while setting `status: "error"` when a *background refetch* fails. `
|
|
56
|
+
* while setting `status: "error"` when a *background refetch* fails. `AsyncState` has
|
|
58
57
|
* no variant for "loaded, but the latest fetch failed", so that squashes to `Failure`
|
|
59
58
|
* and the still-held data is not surfaced through the ADT — a transient background
|
|
60
59
|
* failure will flip a loaded view to an error branch. This is the deliberate default:
|
|
@@ -62,16 +61,13 @@ export type MutationResultView<E, A> = {
|
|
|
62
61
|
* read `query.data` directly alongside the projection, or branch on
|
|
63
62
|
* `query.isRefetchError` before projecting.
|
|
64
63
|
*
|
|
65
|
-
* **Interruption.** `
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* than by proof.
|
|
64
|
+
* **Interruption.** `.error` is whatever the query rejected with, so it is `E` by
|
|
65
|
+
* construction rather than by proof. The `ioQueryFn` bridge boxes an interrupted
|
|
66
|
+
* effect, like a defect, as an `IOQueryError` with `defect: true`.
|
|
69
67
|
*/
|
|
70
|
-
export declare const toQueryState: <E, A>(result: QueryResultView<E, A>) =>
|
|
68
|
+
export declare const toQueryState: <E, A>(result: QueryResultView<E, A>) => AsyncState<E, A>;
|
|
71
69
|
/**
|
|
72
|
-
* Projects a React Query mutation result onto `
|
|
70
|
+
* Projects a React Query mutation result onto `AsyncState`. React Query models an
|
|
73
71
|
* unfired mutation as `status: "idle"`, which maps directly onto `Idle`.
|
|
74
72
|
*/
|
|
75
|
-
export declare const toMutationState: <E, A>(result: MutationResultView<E, A>) =>
|
|
76
|
-
//#endregion
|
|
77
|
-
//# sourceMappingURL=queryState.d.ts.map
|
|
73
|
+
export declare const toMutationState: <E, A>(result: MutationResultView<E, A>) => AsyncState<E, A>;
|
|
@@ -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 { AsyncState } from \"../async/AsyncState\"\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 `AsyncState` 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 `AsyncState` that\n * `functype-react/async`'s `useIO` 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. `AsyncState` 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.** `.error` is whatever the query rejected with, so it is `E` by\n * construction rather than by proof. The `ioQueryFn` bridge boxes an interrupted\n * effect, like a defect, as an `IOQueryError` with `defect: true`.\n */\nexport const toQueryState = <E, A>(result: QueryResultView<E, A>): AsyncState<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 `AsyncState`. 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>): AsyncState<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":"AA0DA,MAAaA,EAAsBC,GAAoD,CACrF,OAAQA,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,EAAyBD,GAAuD,CAC3F,OAAQA,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,E"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { IOQueryError } from "./IOQueryError.js";
|
|
2
|
-
import { IO } from "functype/io";
|
|
3
1
|
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
4
|
-
|
|
2
|
+
import { IO } from "functype/io";
|
|
3
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
5
4
|
export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
|
|
6
5
|
/** Override the derived `Error.message` on failure. */
|
|
7
6
|
readonly formatError?: (error: E) => string;
|
|
@@ -21,6 +20,4 @@ export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A,
|
|
|
21
20
|
* React Query does not supply an `AbortSignal` to mutations, so the callback receives
|
|
22
21
|
* only the mutation variables.
|
|
23
22
|
*/
|
|
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
|
|
26
|
-
//# sourceMappingURL=useIOMutation.d.ts.map
|
|
23
|
+
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>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useMutation as e}from"@tanstack/react-query";import{ioMutationFn as t}from"./ioQueryFn.js";function n(n,r){let{formatError:i,...a}=r??{};return e({...a,mutationFn:t(n,{formatError:i})})}export{n as useIOMutation};
|
|
2
2
|
//# sourceMappingURL=useIOMutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOMutation.js","names":["
|
|
1
|
+
{"version":3,"file":"useIOMutation.js","names":["useMutation","ioMutationFn","useIOMutation","io","options","formatError","mutationOptions"],"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":"A,+GAgCA,SAAgBE,EACdC,EACAC,EACoD,CACpD,GAAM,CAAEC,cAAa,GAAGC,GAAoBF,GAAW,CAAC,EAExD,OAAOJ,EAA6C,CAClD,GAAGM,EACH,WAAYL,EAAsBE,EAAI,CAAEE,aAAY,CAAC,CACvD,CAAC,CACH,C"}
|