functype-react 2.0.0 → 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.
Files changed (77) hide show
  1. package/dist/async/AsyncState.d.ts +1 -1
  2. package/dist/async/index.d.ts +2 -2
  3. package/dist/async/index.js +1 -1
  4. package/dist/async/index.js.map +1 -1
  5. package/dist/async/useIO.d.ts +1 -1
  6. package/dist/async/useIO.js +1 -1
  7. package/dist/async/useIO.js.map +1 -1
  8. package/dist/async/useIOPromise.js.map +1 -1
  9. package/dist/async/useIOValue.js +1 -1
  10. package/dist/async/useIOValue.js.map +1 -1
  11. package/dist/forms/Validated.js.map +1 -1
  12. package/dist/forms/useValidatedField.d.ts +2 -2
  13. package/dist/forms/useValidatedField.js +1 -1
  14. package/dist/forms/useValidatedField.js.map +1 -1
  15. package/dist/forms/useValidatedForm.d.ts +2 -2
  16. package/dist/forms/useValidatedForm.js +1 -1
  17. package/dist/forms/useValidatedForm.js.map +1 -1
  18. package/dist/hooks/eq.d.ts +1 -1
  19. package/dist/hooks/eq.js.map +1 -1
  20. package/dist/hooks/index.d.ts +9 -9
  21. package/dist/hooks/useEither.d.ts +1 -1
  22. package/dist/hooks/useEither.js.map +1 -1
  23. package/dist/hooks/useList.d.ts +1 -1
  24. package/dist/hooks/useList.js +1 -1
  25. package/dist/hooks/useList.js.map +1 -1
  26. package/dist/hooks/useOption.d.ts +1 -1
  27. package/dist/hooks/useOption.js +1 -1
  28. package/dist/hooks/useOption.js.map +1 -1
  29. package/dist/hooks/useStableCallback.d.ts +1 -1
  30. package/dist/hooks/useStableCallback.js +1 -1
  31. package/dist/hooks/useStableCallback.js.map +1 -1
  32. package/dist/hooks/useStableEffect.d.ts +1 -1
  33. package/dist/hooks/useStableEffect.js +1 -1
  34. package/dist/hooks/useStableEffect.js.map +1 -1
  35. package/dist/hooks/useStableMemo.d.ts +1 -1
  36. package/dist/hooks/useStableMemo.js +1 -1
  37. package/dist/hooks/useStableMemo.js.map +1 -1
  38. package/dist/hooks/useStableState.d.ts +1 -1
  39. package/dist/hooks/useStableState.js +1 -1
  40. package/dist/hooks/useStableState.js.map +1 -1
  41. package/dist/hooks/useTry.d.ts +1 -1
  42. package/dist/hooks/useTry.js +1 -1
  43. package/dist/hooks/useTry.js.map +1 -1
  44. package/dist/{index-Dr09mq-A.d.ts → index-Byicsy1U.d.ts} +1 -1
  45. package/dist/index.d.ts +10 -10
  46. package/dist/index.js +1 -1
  47. package/dist/match/index.d.ts +1 -1
  48. package/dist/match/index.js +1 -1
  49. package/dist/{match-CkGESkj9.js → match-BnD70A5l.js} +1 -1
  50. package/dist/match-BnD70A5l.js.map +1 -0
  51. package/dist/query/IOQueryError.js.map +1 -1
  52. package/dist/query/ioQueryFn.js +1 -1
  53. package/dist/query/ioQueryFn.js.map +1 -1
  54. package/dist/query/queryState.d.ts +1 -1
  55. package/dist/query/queryState.js.map +1 -1
  56. package/dist/query/useIOMutation.d.ts +2 -2
  57. package/dist/query/useIOMutation.js +1 -1
  58. package/dist/query/useIOMutation.js.map +1 -1
  59. package/dist/query/useIOMutationState.d.ts +3 -3
  60. package/dist/query/useIOMutationState.js.map +1 -1
  61. package/dist/query/useIOQuery.d.ts +2 -2
  62. package/dist/query/useIOQuery.js +1 -1
  63. package/dist/query/useIOQuery.js.map +1 -1
  64. package/dist/query/useIOQueryState.d.ts +3 -3
  65. package/dist/query/useIOQueryState.js.map +1 -1
  66. package/dist/{useStableCallback-DPo_3DGi.d.ts → useStableCallback-C4UjxvJ1.d.ts} +1 -1
  67. package/dist/{useStableEffect-C2D6ZQG5.d.ts → useStableEffect-CgkwQ5kY.d.ts} +1 -1
  68. package/dist/{useStableMemo-DUoJxF-7.d.ts → useStableMemo-KbV23mg-.d.ts} +1 -1
  69. package/dist/{useStableState-DLLiFi5r.d.ts → useStableState-B-AaH7WY.d.ts} +1 -1
  70. package/package.json +3 -3
  71. package/dist/match-CkGESkj9.js.map +0 -1
  72. /package/dist/{AsyncState-DxKw9NF6.d.ts → AsyncState-zTPspeWC.d.ts} +0 -0
  73. /package/dist/{eq-CQkAVer1.d.ts → eq-cYnbruZq.d.ts} +0 -0
  74. /package/dist/{useEither-D1Rn_tLR.d.ts → useEither-BveKCnsh.d.ts} +0 -0
  75. /package/dist/{useList-C_7X5OA_.d.ts → useList-B83krQsi.d.ts} +0 -0
  76. /package/dist/{useOption-B8UyOh8h.d.ts → useOption-C1VH3h20.d.ts} +0 -0
  77. /package/dist/{useTry-ie1X0NiH.d.ts → useTry-B9VzXJLg.d.ts} +0 -0
@@ -1,2 +1,2 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
1
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
2
2
  export { AsyncState };
@@ -1,8 +1,8 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
2
3
  import { UseIOResult, useIO } from "./useIO.js";
3
4
  import { useIOPromise } from "./useIOPromise.js";
4
5
  import { useIOValue } from "./useIOValue.js";
5
- import { ReactElement, ReactNode } from "react";
6
6
  type Props = {
7
7
  readonly pending: ReactNode;
8
8
  readonly fallback: (error: unknown, reset: () => void) => ReactNode;
@@ -1,2 +1,2 @@
1
- import{useIO as e}from"./useIO.js";import{useIOPromise as t}from"./useIOPromise.js";import{useIOValue as n}from"./useIOValue.js";import{Component as r,Suspense as i}from"react";import{jsx as a}from"react/jsx-runtime";var o=class extends r{constructor(...e){super(...e),this.state={_tag:`Ok`},this.reset=()=>{this.setState({_tag:`Ok`})}}static getDerivedStateFromError(e){return{_tag:`Errored`,error:e}}componentDidCatch(e,t){}render(){return this.state._tag===`Errored`?this.props.fallback(this.state.error,this.reset):this.props.children}};function s(e){return/* @__PURE__ */ a(o,{fallback:e.fallback,children:/* @__PURE__ */ a(i,{fallback:e.pending,children:e.children})})}export{s as AsyncBoundary,e as useIO,t as useIOPromise,n as useIOValue};
1
+ import{Component as e,Suspense as t}from"react";import{jsx as n}from"react/jsx-runtime";import{useIO as r}from"./useIO.js";import{useIOPromise as i}from"./useIOPromise.js";import{useIOValue as a}from"./useIOValue.js";var o=class extends e{constructor(...e){super(...e),this.state={_tag:`Ok`},this.reset=()=>{this.setState({_tag:`Ok`})}}static getDerivedStateFromError(e){return{_tag:`Errored`,error:e}}componentDidCatch(e,t){}render(){return this.state._tag===`Errored`?this.props.fallback(this.state.error,this.reset):this.props.children}};function s(e){return/* @__PURE__ */ n(o,{fallback:e.fallback,children:/* @__PURE__ */ n(t,{fallback:e.pending,children:e.children})})}export{s as AsyncBoundary,r as useIO,i as useIOPromise,a as useIOValue};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["AsyncErrorBoundary","Component","_args","AsyncBoundary","props","Suspense","useIO","useIOPromise","useIOValue"],"sources":["../../src/async/AsyncBoundary.tsx"],"sourcesContent":["\"use client\"\n\nimport { Component, type ErrorInfo, type ReactElement, type ReactNode, Suspense } from \"react\"\n\ntype Props = {\n readonly pending: ReactNode\n readonly fallback: (error: unknown, reset: () => void) => ReactNode\n readonly children: ReactNode\n}\n\ntype State = { readonly _tag: \"Ok\" } | { readonly _tag: \"Errored\"; readonly error: unknown }\n\nclass AsyncErrorBoundary extends Component<\n { readonly fallback: Props[\"fallback\"]; readonly children: ReactNode },\n State\n> {\n override state: State = { _tag: \"Ok\" }\n\n static getDerivedStateFromError(error: unknown): State {\n return { _tag: \"Errored\", error }\n }\n\n override componentDidCatch(_error: unknown, _info: ErrorInfo): void {\n // hook for telemetry; intentionally noop in v0.1\n }\n\n reset = (): void => {\n this.setState({ _tag: \"Ok\" })\n }\n\n override render(): ReactNode {\n if (this.state._tag === \"Errored\") {\n return this.props.fallback(this.state.error, this.reset)\n }\n return this.props.children\n }\n}\n\n/**\n * Combines `<Suspense>` (for pending effects consumed via `useIOValue`) with\n * an ErrorBoundary that catches thrown failures. The `fallback` render prop\n * receives the thrown value (typed `unknown` — consumers narrow) and a\n * `reset` callback that clears the error so children can be re-attempted.\n *\n * The ErrorBoundary wraps the Suspense, matching React's documented rule\n * (otherwise Suspense would catch errors instead of the boundary).\n */\nexport function AsyncBoundary(props: Props): ReactElement {\n return (\n <AsyncErrorBoundary fallback={props.fallback}>\n <Suspense fallback={props.pending}>{props.children}</Suspense>\n </AsyncErrorBoundary>\n )\n}\n"],"mappings":"A,yNAYA,IAAMA,EAAN,cAAiCC,CAG/B,C,8BACA,KAAS,MAAe,CAAE,KAAM,IAAK,EAUrC,KAAA,UAAoB,CAClB,KAAK,SAAS,CAAE,KAAM,IAAK,CAAC,CAC9B,C,CAVA,OAAO,yBAAyB,EAAuB,CACrD,MAAO,CAAE,KAAM,UAAW,OAAM,CAClC,CAEA,kBAA2B,EAAiB,EAAwB,CAEpE,CAMA,QAA6B,CAI3B,OAHI,KAAK,MAAM,OAAS,UACf,KAAK,MAAM,SAAS,KAAK,MAAM,MAAO,KAAK,KAAK,EAElD,KAAK,MAAM,QACpB,CACF,EAWA,SAAgBE,EAAc,EAA4B,CACxD,MACE,kBAACH,EAAD,CAAoB,SAAUI,EAAM,SAClC,SAAA,kBAACC,EAAD,CAAU,SAAUD,EAAM,QAAU,SAAAA,EAAM,QAAmB,CAAA,CAC3C,CAAA,CAExB,C"}
1
+ {"version":3,"file":"index.js","names":["Component","Suspense","jsx","useIO","useIOPromise","useIOValue","AsyncErrorBoundary","_args","error","_error","_info","AsyncBoundary","props"],"sources":["../../src/async/AsyncBoundary.tsx"],"sourcesContent":["\"use client\"\n\nimport { Component, type ErrorInfo, type ReactElement, type ReactNode, Suspense } from \"react\"\n\ntype Props = {\n readonly pending: ReactNode\n readonly fallback: (error: unknown, reset: () => void) => ReactNode\n readonly children: ReactNode\n}\n\ntype State = { readonly _tag: \"Ok\" } | { readonly _tag: \"Errored\"; readonly error: unknown }\n\nclass AsyncErrorBoundary extends Component<\n { readonly fallback: Props[\"fallback\"]; readonly children: ReactNode },\n State\n> {\n override state: State = { _tag: \"Ok\" }\n\n static getDerivedStateFromError(error: unknown): State {\n return { _tag: \"Errored\", error }\n }\n\n override componentDidCatch(_error: unknown, _info: ErrorInfo): void {\n // hook for telemetry; intentionally noop in v0.1\n }\n\n reset = (): void => {\n this.setState({ _tag: \"Ok\" })\n }\n\n override render(): ReactNode {\n if (this.state._tag === \"Errored\") {\n return this.props.fallback(this.state.error, this.reset)\n }\n return this.props.children\n }\n}\n\n/**\n * Combines `<Suspense>` (for pending effects consumed via `useIOValue`) with\n * an ErrorBoundary that catches thrown failures. The `fallback` render prop\n * receives the thrown value (typed `unknown` — consumers narrow) and a\n * `reset` callback that clears the error so children can be re-attempted.\n *\n * The ErrorBoundary wraps the Suspense, matching React's documented rule\n * (otherwise Suspense would catch errors instead of the boundary).\n */\nexport function AsyncBoundary(props: Props): ReactElement {\n return (\n <AsyncErrorBoundary fallback={props.fallback}>\n <Suspense fallback={props.pending}>{props.children}</Suspense>\n </AsyncErrorBoundary>\n )\n}\n"],"mappings":"A,yNAYA,IAAMM,EAAN,cAAiCN,CAG/B,C,8BACA,KAAS,MAAe,CAAE,KAAM,IAAK,EAUrC,KAAA,UAAoB,CAClB,KAAK,SAAS,CAAE,KAAM,IAAK,CAAC,CAC9B,C,CAVA,OAAO,yBAAyBQ,EAAuB,CACrD,MAAO,CAAE,KAAM,UAAWA,OAAM,CAClC,CAES,kBAAkBC,EAAiBC,EAAwB,CAEpE,CAMS,QAAoB,CAI3B,OAHI,KAAK,MAAM,OAAS,UACf,KAAK,MAAM,SAAS,KAAK,MAAM,MAAO,KAAK,KAAK,EAElD,KAAK,MAAM,QACpB,CACF,EAWA,SAAgBC,EAAcC,EAA4B,CACxD,MACEV,kBAACI,EAAD,CAAoB,SAAUM,EAAM,SAClC,SAAAV,kBAACD,EAAD,CAAU,SAAUW,EAAM,QAAU,SAAAA,EAAM,QAAmB,CAAA,CAC3C,CAAA,CAExB,C"}
@@ -1,5 +1,5 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
2
1
  import { IO } from "functype/io";
2
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
3
3
  export type UseIOResult<E, A> = AsyncState<E, A> & {
4
4
  readonly isIdle: boolean;
5
5
  readonly isPending: boolean;
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useEffect as t,useReducer as n,useRef as r,useState as i}from"react";import{Try as a}from"functype";function o(e,t){return t.type===`PENDING`?{_tag:`Pending`}:t.type===`SUCCESS`?{_tag:`Success`,value:t.value}:{_tag:`Failure`,error:t.error}}function s(s,c){let[l,u]=n(o,{_tag:`Idle`}),[d,f]=i(void 0),[p,m]=n(e=>e+1,0),h=r(s);h.current=s,t(()=>{let e=new AbortController;u({type:`PENDING`});let t=t=>{e.signal.aborted||t.fold(e=>u({type:`FAILURE`,error:e}),e=>u({type:`SUCCESS`,value:e}),()=>f({value:/* @__PURE__ */ Error(`useIO: the effect interrupted itself`)}),e=>f({value:e}))};return a(()=>h.current(e.signal)).fold(e=>f({value:e}),n=>void n.runExit({signal:e.signal}).then(t)),()=>e.abort()},[...c,p]);let g=e(()=>m(),[]);if(d)throw d.value;return{...l,isIdle:l._tag===`Idle`,isPending:l._tag===`Pending`,isSuccess:l._tag===`Success`,isFailure:l._tag===`Failure`,refetch:g}}export{s as useIO};
1
+ "use client";import{Try as e}from"functype";import{useCallback as t,useEffect as n,useReducer as r,useRef as i,useState as a}from"react";function o(e,t){return t.type===`PENDING`?{_tag:`Pending`}:t.type===`SUCCESS`?{_tag:`Success`,value:t.value}:{_tag:`Failure`,error:t.error}}function s(s,c){let[l,u]=r(o,{_tag:`Idle`}),[d,f]=a(void 0),[p,m]=r(e=>e+1,0),h=i(s);h.current=s,n(()=>{let t=new AbortController;u({type:`PENDING`});let n=e=>{t.signal.aborted||e.fold(e=>u({type:`FAILURE`,error:e}),e=>u({type:`SUCCESS`,value:e}),()=>f({value:/* @__PURE__ */ Error(`useIO: the effect interrupted itself`)}),e=>f({value:e}))};return e(()=>h.current(t.signal)).fold(e=>f({value:e}),e=>void e.runExit({signal:t.signal}).then(n)),()=>t.abort()},[...c,p]);let g=t(()=>m(),[]);if(d)throw d.value;return{...l,isIdle:l._tag===`Idle`,isPending:l._tag===`Pending`,isSuccess:l._tag===`Success`,isFailure:l._tag===`Failure`,refetch:g}}export{s as useIO};
2
2
  //# sourceMappingURL=useIO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIO.js","names":["reducer","action","useIO","state","dispatch","useReducer","defect","setDefect","useState","refetchTick","forceRefetch","n","ioRef","useRef","io","useEffect","controller","settle","exit","Try","thrown","effect","deps","refetch","useCallback"],"sources":["../../src/async/useIO.ts"],"sourcesContent":["\"use client\"\n\nimport { Try } from \"functype\"\nimport type { Exit, IO } from \"functype/io\"\nimport { useCallback, useEffect, useReducer, useRef, useState } from \"react\"\n\nimport type { AsyncState } from \"./AsyncState\"\n\ntype Action<E, A> =\n | { readonly type: \"PENDING\" }\n | { readonly type: \"SUCCESS\"; readonly value: A }\n | { readonly type: \"FAILURE\"; readonly error: E }\n\nfunction reducer<E, A>(_state: AsyncState<E, A>, action: Action<E, A>): AsyncState<E, A> {\n if (action.type === \"PENDING\") return { _tag: \"Pending\" }\n if (action.type === \"SUCCESS\") return { _tag: \"Success\", value: action.value }\n return { _tag: \"Failure\", error: action.error }\n}\n\nexport type UseIOResult<E, A> = AsyncState<E, A> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n refetch: () => void\n}\n\n/**\n * Runs an `IO<never, E, A>` tied to a component's lifecycle and returns its `AsyncState`,\n * plus boolean flags and a `refetch` trigger.\n *\n * - The factory receives an `AbortSignal` that aborts on unmount or when `deps` change.\n * The effect is cancelled with it: no further step runs once it fires. Also pass it to\n * `Http` / `IO.tryAsync` so an in-flight request aborts too.\n * - A cancelled run's result is discarded, so it never shows up as `Failure`.\n * - A typed failure becomes `Failure` with the effect's `E`.\n * - A defect (a bug: a throw inside the effect, or the factory throwing while building it)\n * is rethrown during render, so the nearest error boundary catches it, the way a bug in\n * any other component would surface.\n * - StrictMode-safe: the cleanup aborts the signal and discards any late result.\n *\n * @interop React reaches an error boundary only through a throw during render, so a defect is rethrown there.\n */\nexport function useIO<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): UseIOResult<E, A> {\n const [state, dispatch] = useReducer(reducer<E, A>, { _tag: \"Idle\" })\n const [defect, setDefect] = useState<{ readonly value: unknown } | undefined>(undefined)\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const ioRef = useRef(io)\n ioRef.current = io\n\n useEffect(() => {\n const controller = new AbortController()\n dispatch({ type: \"PENDING\" })\n\n const settle = (exit: Exit<E, A>): void => {\n if (controller.signal.aborted) return\n exit.fold(\n (error) => dispatch({ type: \"FAILURE\", error }),\n (value) => dispatch({ type: \"SUCCESS\", value }),\n // Interrupted without an abort means the effect interrupted itself (IO.interrupt()):\n // there is no value and no E, so it is reported like a defect.\n () => setDefect({ value: new Error(\"useIO: the effect interrupted itself\") }),\n (defect) => setDefect({ value: defect }),\n )\n }\n\n // The factory is user code and can throw while building the effect; that's a defect too.\n Try(() => ioRef.current(controller.signal)).fold(\n (thrown) => setDefect({ value: thrown }),\n (effect) => void effect.runExit({ signal: controller.signal }).then(settle),\n )\n\n return () => controller.abort()\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\n\n if (defect) throw defect.value\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,\n }\n}\n"],"mappings":"A,yIAaA,SAASA,EAAc,EAA0B,EAAwC,CAGvF,OAFIC,EAAO,OAAS,UAAkB,CAAE,KAAM,SAAU,EACpDA,EAAO,OAAS,UAAkB,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EACtE,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,CAChD,CA0BA,SAAgBC,EACd,EACA,EACmB,CACnB,GAAM,CAACC,EAAOC,GAAYC,EAAWL,EAAe,CAAE,KAAM,MAAO,CAAC,EAC9D,CAACM,EAAQC,GAAaC,EAAkD,IAAA,EAAS,EACjF,CAACC,EAAaC,GAAgBL,EAAY,GAAcM,EAAI,EAAG,CAAC,EAChEC,EAAQC,EAAOC,CAAE,EACvB,EAAM,QAAUA,EAEhBC,MAAgB,CACd,IAAMC,EAAa,IAAI,gBACvBZ,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5B,IAAMa,EAAU,GAA2B,CACrCD,EAAW,OAAO,SACtBE,EAAK,KACF,GAAUd,EAAS,CAAE,KAAM,UAAW,OAAM,CAAC,EAC7C,GAAUA,EAAS,CAAE,KAAM,UAAW,OAAM,CAAC,MAGxCG,EAAU,CAAE,MAAO,gBAAI,MAAM,sCAAsC,CAAE,CAAC,EAC3E,GAAWA,EAAU,CAAE,MAAOD,CAAO,CAAC,CACzC,CACF,EAQA,OALAa,MAAUP,EAAM,QAAQI,EAAW,MAAM,CAAC,CAAC,CAAC,KACzC,GAAWT,EAAU,CAAE,MAAOa,CAAO,CAAC,EACtC,GAAW,KAAKC,EAAO,QAAQ,CAAE,OAAQL,EAAW,MAAO,CAAC,CAAC,CAAC,KAAKC,CAAM,CAC5E,MAEaD,EAAW,MAAM,CAChC,EAAG,CAAC,GAAGM,EAAMb,CAAW,CAAC,EAEzB,IAAMc,EAAUC,MAAkBd,EAAa,EAAG,CAAC,CAAC,EAEpD,GAAIJ,EAAQ,MAAMA,EAAO,MAEzB,MAAO,CACL,GAAGH,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,SACF,CACF,C"}
1
+ {"version":3,"file":"useIO.js","names":["Try","useCallback","useEffect","useReducer","useRef","useState","reducer","_state","action","useIO","io","deps","state","dispatch","defect","setDefect","refetchTick","forceRefetch","n","ioRef","controller","settle","exit","error","value","thrown","effect","refetch"],"sources":["../../src/async/useIO.ts"],"sourcesContent":["\"use client\"\n\nimport { Try } from \"functype\"\nimport type { Exit, IO } from \"functype/io\"\nimport { useCallback, useEffect, useReducer, useRef, useState } from \"react\"\n\nimport type { AsyncState } from \"./AsyncState\"\n\ntype Action<E, A> =\n | { readonly type: \"PENDING\" }\n | { readonly type: \"SUCCESS\"; readonly value: A }\n | { readonly type: \"FAILURE\"; readonly error: E }\n\nfunction reducer<E, A>(_state: AsyncState<E, A>, action: Action<E, A>): AsyncState<E, A> {\n if (action.type === \"PENDING\") return { _tag: \"Pending\" }\n if (action.type === \"SUCCESS\") return { _tag: \"Success\", value: action.value }\n return { _tag: \"Failure\", error: action.error }\n}\n\nexport type UseIOResult<E, A> = AsyncState<E, A> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n refetch: () => void\n}\n\n/**\n * Runs an `IO<never, E, A>` tied to a component's lifecycle and returns its `AsyncState`,\n * plus boolean flags and a `refetch` trigger.\n *\n * - The factory receives an `AbortSignal` that aborts on unmount or when `deps` change.\n * The effect is cancelled with it: no further step runs once it fires. Also pass it to\n * `Http` / `IO.tryAsync` so an in-flight request aborts too.\n * - A cancelled run's result is discarded, so it never shows up as `Failure`.\n * - A typed failure becomes `Failure` with the effect's `E`.\n * - A defect (a bug: a throw inside the effect, or the factory throwing while building it)\n * is rethrown during render, so the nearest error boundary catches it, the way a bug in\n * any other component would surface.\n * - StrictMode-safe: the cleanup aborts the signal and discards any late result.\n *\n * @interop React reaches an error boundary only through a throw during render, so a defect is rethrown there.\n */\nexport function useIO<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): UseIOResult<E, A> {\n const [state, dispatch] = useReducer(reducer<E, A>, { _tag: \"Idle\" })\n const [defect, setDefect] = useState<{ readonly value: unknown } | undefined>(undefined)\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const ioRef = useRef(io)\n ioRef.current = io\n\n useEffect(() => {\n const controller = new AbortController()\n dispatch({ type: \"PENDING\" })\n\n const settle = (exit: Exit<E, A>): void => {\n if (controller.signal.aborted) return\n exit.fold(\n (error) => dispatch({ type: \"FAILURE\", error }),\n (value) => dispatch({ type: \"SUCCESS\", value }),\n // Interrupted without an abort means the effect interrupted itself (IO.interrupt()):\n // there is no value and no E, so it is reported like a defect.\n () => setDefect({ value: new Error(\"useIO: the effect interrupted itself\") }),\n (defect) => setDefect({ value: defect }),\n )\n }\n\n // The factory is user code and can throw while building the effect; that's a defect too.\n Try(() => ioRef.current(controller.signal)).fold(\n (thrown) => setDefect({ value: thrown }),\n (effect) => void effect.runExit({ signal: controller.signal }).then(settle),\n )\n\n return () => controller.abort()\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\n\n if (defect) throw defect.value\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,\n }\n}\n"],"mappings":"A,yIAaA,SAASM,EAAcC,EAA0BC,EAAwC,CAGvF,OAFIA,EAAO,OAAS,UAAkB,CAAE,KAAM,SAAU,EACpDA,EAAO,OAAS,UAAkB,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EACtE,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,CAChD,CA0BA,SAAgBC,EACdC,EACAC,EACmB,CACnB,GAAM,CAACC,EAAOC,GAAYV,EAAWG,EAAe,CAAE,KAAM,MAAO,CAAC,EAC9D,CAACQ,EAAQC,GAAaV,EAAkD,IAAA,EAAS,EACjF,CAACW,EAAaC,GAAgBd,EAAYe,GAAcA,EAAI,EAAG,CAAC,EAChEC,EAAQf,EAAOM,CAAE,EACvBS,EAAM,QAAUT,EAEhBR,MAAgB,CACd,IAAMkB,EAAa,IAAI,gBACvBP,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5B,IAAMQ,EAAUC,GAA2B,CACrCF,EAAW,OAAO,SACtBE,EAAK,KACFC,GAAUV,EAAS,CAAE,KAAM,UAAWU,OAAM,CAAC,EAC7CC,GAAUX,EAAS,CAAE,KAAM,UAAWW,OAAM,CAAC,MAGxCT,EAAU,CAAE,MAAO,gBAAI,MAAM,sCAAsC,CAAE,CAAC,EAC3ED,GAAWC,EAAU,CAAE,MAAOD,CAAO,CAAC,CACzC,CACF,EAQA,OALAd,MAAUmB,EAAM,QAAQC,EAAW,MAAM,CAAC,CAAC,CAAC,KACzCK,GAAWV,EAAU,CAAE,MAAOU,CAAO,CAAC,EACtCC,GAAW,KAAKA,EAAO,QAAQ,CAAE,OAAQN,EAAW,MAAO,CAAC,CAAC,CAAC,KAAKC,CAAM,CAC5E,MAEaD,EAAW,MAAM,CAChC,EAAG,CAAC,GAAGT,EAAMK,CAAW,CAAC,EAEzB,IAAMW,EAAU1B,MAAkBgB,EAAa,EAAG,CAAC,CAAC,EAEpD,GAAIH,EAAQ,MAAMA,EAAO,MAEzB,MAAO,CACL,GAAGF,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1Be,SACF,CACF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIOPromise.js","names":["useIOPromise","ioRef","useRef","io","useMemo","controller","deps"],"sources":["../../src/async/useIOPromise.ts"],"sourcesContent":["\"use client\"\n\nimport type { Exit, IO } from \"functype/io\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Starts an `IO<never, E, A>` and returns a `Promise<Exit<E, A>>` that is stable across\n * renders with the same `deps`. Intended for React 19's `use()`: a new promise on each\n * render would suspend forever.\n *\n * `Exit` keeps a typed failure, a defect and an interruption apart, so a consumer can tell\n * them apart; `useIOValue` does that for you.\n *\n * The factory is read through a ref, so the latest closure runs even if it isn't in `deps`.\n * Put in `deps` whatever changes the result. The factory receives an `AbortSignal` for\n * `Http` / `IO.tryAsync`; `useMemo` has no cleanup, so nothing aborts it on unmount.\n */\nexport function useIOPromise<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): Promise<Exit<E, A>> {\n const ioRef = useRef(io)\n ioRef.current = io\n\n return useMemo(() => {\n const controller = new AbortController()\n return ioRef.current(controller.signal).runExit({ signal: controller.signal })\n }, deps)\n}\n"],"mappings":"A,yDAiBA,SAAgBA,EACd,EACA,EACqB,CACrB,IAAMC,EAAQC,EAAOC,CAAE,EAGvB,MAFA,GAAM,QAAUA,EAETC,MAAc,CACnB,IAAMC,EAAa,IAAI,gBACvB,OAAOJ,EAAM,QAAQI,EAAW,MAAM,CAAC,CAAC,QAAQ,CAAE,OAAQA,EAAW,MAAO,CAAC,CAC/E,EAAGC,CAAI,CACT,C"}
1
+ {"version":3,"file":"useIOPromise.js","names":["useMemo","useRef","useIOPromise","io","deps","ioRef","controller"],"sources":["../../src/async/useIOPromise.ts"],"sourcesContent":["\"use client\"\n\nimport type { Exit, IO } from \"functype/io\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Starts an `IO<never, E, A>` and returns a `Promise<Exit<E, A>>` that is stable across\n * renders with the same `deps`. Intended for React 19's `use()`: a new promise on each\n * render would suspend forever.\n *\n * `Exit` keeps a typed failure, a defect and an interruption apart, so a consumer can tell\n * them apart; `useIOValue` does that for you.\n *\n * The factory is read through a ref, so the latest closure runs even if it isn't in `deps`.\n * Put in `deps` whatever changes the result. The factory receives an `AbortSignal` for\n * `Http` / `IO.tryAsync`; `useMemo` has no cleanup, so nothing aborts it on unmount.\n */\nexport function useIOPromise<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): Promise<Exit<E, A>> {\n const ioRef = useRef(io)\n ioRef.current = io\n\n return useMemo(() => {\n const controller = new AbortController()\n return ioRef.current(controller.signal).runExit({ signal: controller.signal })\n }, deps)\n}\n"],"mappings":"A,yDAiBA,SAAgBE,EACdC,EACAC,EACqB,CACrB,IAAMC,EAAQJ,EAAOE,CAAE,EAGvB,MAFAE,GAAM,QAAUF,EAETH,MAAc,CACnB,IAAMM,EAAa,IAAI,gBACvB,OAAOD,EAAM,QAAQC,EAAW,MAAM,CAAC,CAAC,QAAQ,CAAE,OAAQA,EAAW,MAAO,CAAC,CAC/E,EAAGF,CAAI,CACT,C"}
@@ -1,2 +1,2 @@
1
- "use client";import{useIOPromise as e}from"./useIOPromise.js";import{use as t}from"react";import{InterruptedError as n}from"functype/io";function r(r,i){let a=t(e(r,i));if(a.isSuccess())return a.orThrow();throw a.isFailure()?a.toValue().error:a.isDie()?a.toValue().defect:new n}export{r as useIOValue};
1
+ "use client";import{InterruptedError as e}from"functype/io";import{use as t}from"react";import{useIOPromise as n}from"./useIOPromise.js";function r(r,i){let a=t(n(r,i));if(a.isSuccess())return a.orThrow();throw a.isFailure()?a.toValue().error:a.isDie()?a.toValue().defect:new e}export{r as useIOValue};
2
2
  //# sourceMappingURL=useIOValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIOValue.js","names":["useIOValue","exit","use","useIOPromise","io","deps","InterruptedError"],"sources":["../../src/async/useIOValue.ts"],"sourcesContent":["\"use client\"\n\nimport { InterruptedError, type IO } from \"functype/io\"\nimport { use } from \"react\"\n\nimport { useIOPromise } from \"./useIOPromise\"\n\n/**\n * Suspense-aware variant of `useIO` for React 19+. Suspends while the effect is pending and\n * returns its value. On failure it throws the typed error; on a defect, the defect; on an\n * interruption, an `InterruptedError`. All three reach `<AsyncBoundary>` (or a hand-rolled\n * Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useIOPromise` memoizes by `deps`, so\n * passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise Suspense will\n * catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Build the `IO` in a Client Component and call\n * `useIOValue` there.\n *\n * @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.\n *\n * Testing note: React 19's `use()` does not unsuspend reliably under jsdom +\n * @testing-library/react. End-to-end tests of `useIOValue` + `<AsyncBoundary>` require a\n * real browser scheduler (Playwright); unit tests of `useIO` and `useIOPromise` cover the\n * plumbing.\n */\nexport function useIOValue<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): A {\n const exit = use(useIOPromise(io, deps))\n if (exit.isSuccess()) return exit.orThrow()\n if (exit.isFailure()) throw exit.toValue().error\n if (exit.isDie()) throw exit.toValue().defect\n throw new InterruptedError()\n}\n"],"mappings":"A,yIA4BA,SAAgBA,EAAiB,EAA8C,EAAiC,CAC9G,IAAMC,EAAOC,EAAIC,EAAaC,EAAIC,CAAI,CAAC,EACvC,GAAIJ,EAAK,UAAU,EAAG,OAAOA,EAAK,QAAQ,EAG1C,MAFIA,EAAK,UAAU,EAASA,EAAK,QAAQ,CAAC,CAAC,MACvCA,EAAK,MAAM,EAASA,EAAK,QAAQ,CAAC,CAAC,OACjC,IAAIK,CACZ,C"}
1
+ {"version":3,"file":"useIOValue.js","names":["InterruptedError","use","useIOPromise","useIOValue","io","deps","exit"],"sources":["../../src/async/useIOValue.ts"],"sourcesContent":["\"use client\"\n\nimport { InterruptedError, type IO } from \"functype/io\"\nimport { use } from \"react\"\n\nimport { useIOPromise } from \"./useIOPromise\"\n\n/**\n * Suspense-aware variant of `useIO` for React 19+. Suspends while the effect is pending and\n * returns its value. On failure it throws the typed error; on a defect, the defect; on an\n * interruption, an `InterruptedError`. All three reach `<AsyncBoundary>` (or a hand-rolled\n * Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useIOPromise` memoizes by `deps`, so\n * passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise Suspense will\n * catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Build the `IO` in a Client Component and call\n * `useIOValue` there.\n *\n * @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.\n *\n * Testing note: React 19's `use()` does not unsuspend reliably under jsdom +\n * @testing-library/react. End-to-end tests of `useIOValue` + `<AsyncBoundary>` require a\n * real browser scheduler (Playwright); unit tests of `useIO` and `useIOPromise` cover the\n * plumbing.\n */\nexport function useIOValue<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): A {\n const exit = use(useIOPromise(io, deps))\n if (exit.isSuccess()) return exit.orThrow()\n if (exit.isFailure()) throw exit.toValue().error\n if (exit.isDie()) throw exit.toValue().defect\n throw new InterruptedError()\n}\n"],"mappings":"A,yIA4BA,SAAgBG,EAAiBC,EAA8CC,EAAiC,CAC9G,IAAMC,EAAOL,EAAIC,EAAaE,EAAIC,CAAI,CAAC,EACvC,GAAIC,EAAK,UAAU,EAAG,OAAOA,EAAK,QAAQ,EAG1C,MAFIA,EAAK,UAAU,EAASA,EAAK,QAAQ,CAAC,CAAC,MACvCA,EAAK,MAAM,EAASA,EAAK,QAAQ,CAAC,CAAC,OACjC,IAAIN,CACZ,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"Validated.js","names":["valid","Right","value","invalid","list","errors","List","Left"],"sources":["../../src/forms/Validated.ts"],"sourcesContent":["import { type Either, Left, List, type List as ListT, Right } from \"functype\"\n\n/**\n * Applicative-error-accumulating result for form validation.\n *\n * Encoded as `Either<List<E>, A>` — the same shape Scala's cats uses for\n * `ValidatedNel`. Multiple field errors accumulate via `List.concat`; on\n * success, the validated value rides in the `Right` channel.\n *\n * functype core already exposes this pattern via `FormValidation<T>` in\n * `packages/functype/src/error/typed/Validation.ts`; this alias just gives\n * the React-facing surface an ergonomic name.\n */\nexport type Validated<E, A> = Either<ListT<E>, A>\n\n/** Construct a `Valid` (Right) result. */\nexport function valid<A>(value: A): Validated<never, A> {\n return Right<ListT<never>, A>(value)\n}\n\n/** Construct an `Invalid` (Left) result from an iterable of errors. */\nexport function invalid<E>(errors: ListT<E> | ReadonlyArray<E>): Validated<E, never> {\n const list = errors instanceof Array ? List<E>(errors) : (errors as ListT<E>)\n return Left<ListT<E>, never>(list)\n}\n"],"mappings":"A,qDAgBA,SAAgBA,EAAS,EAA+B,CACtD,OAAOC,EAAuBC,CAAK,CACrC,CAGA,SAAgBC,EAAW,EAA0D,CACnF,IAAMC,EAAOC,aAAkB,MAAQC,EAAQD,CAAM,EAAKA,EAC1D,OAAOE,EAAsBH,CAAI,CACnC,C"}
1
+ {"version":3,"file":"Validated.js","names":["Left","List","Right","valid","value","invalid","errors","list"],"sources":["../../src/forms/Validated.ts"],"sourcesContent":["import { type Either, Left, List, type List as ListT, Right } from \"functype\"\n\n/**\n * Applicative-error-accumulating result for form validation.\n *\n * Encoded as `Either<List<E>, A>` — the same shape Scala's cats uses for\n * `ValidatedNel`. Multiple field errors accumulate via `List.concat`; on\n * success, the validated value rides in the `Right` channel.\n *\n * functype core already exposes this pattern via `FormValidation<T>` in\n * `packages/functype/src/error/typed/Validation.ts`; this alias just gives\n * the React-facing surface an ergonomic name.\n */\nexport type Validated<E, A> = Either<ListT<E>, A>\n\n/** Construct a `Valid` (Right) result. */\nexport function valid<A>(value: A): Validated<never, A> {\n return Right<ListT<never>, A>(value)\n}\n\n/** Construct an `Invalid` (Left) result from an iterable of errors. */\nexport function invalid<E>(errors: ListT<E> | ReadonlyArray<E>): Validated<E, never> {\n const list = errors instanceof Array ? List<E>(errors) : (errors as ListT<E>)\n return Left<ListT<E>, never>(list)\n}\n"],"mappings":"A,qDAgBA,SAAgBG,EAASC,EAA+B,CACtD,OAAOF,EAAuBE,CAAK,CACrC,CAGA,SAAgBC,EAAWC,EAA0D,CACnF,IAAMC,EAAOD,aAAkB,MAAQL,EAAQK,CAAM,EAAKA,EAC1D,OAAON,EAAsBO,CAAI,CACnC,C"}
@@ -1,6 +1,6 @@
1
- import { Validated } from "./Validated.js";
2
- import { ChangeEvent } from "react";
3
1
  import { List } from "functype";
2
+ import { ChangeEvent } from "react";
3
+ import { Validated } from "./Validated.js";
4
4
  /**
5
5
  * Single-field state container with continuously-derived validation.
6
6
  *
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useMemo as t,useState as n}from"react";import{List as r}from"functype";function i(i){let[a,o]=n(i.initial),s=t(()=>i.validate(a),[i,a]);return{value:a,setValue:o,validation:s,errors:t(()=>s.fold(e=>e,()=>r.empty()),[s]),isValid:s.isRight(),bind:e(()=>({value:a,onChange:e=>o(e.target.value)}),[a])}}export{i as useValidatedField};
1
+ "use client";import{List as e}from"functype";import{useCallback as t,useMemo as n,useState as r}from"react";function i(i){let[a,o]=r(i.initial),s=n(()=>i.validate(a),[i,a]);return{value:a,setValue:o,validation:s,errors:n(()=>s.fold(e=>e,()=>e.empty()),[s]),isValid:s.isRight(),bind:t(()=>({value:a,onChange:e=>o(e.target.value)}),[a])}}export{i as useValidatedField};
2
2
  //# sourceMappingURL=useValidatedField.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useValidatedField.js","names":["useValidatedField","value","setValue","useState","opts","validation","useMemo","es","List","useCallback"],"sources":["../../src/forms/useValidatedField.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type ChangeEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Single-field state container with continuously-derived validation.\n *\n * `validation` is re-derived from `validate(value)` on every render — keep\n * `validate` cheap or memoize the callback.\n *\n * `bind()` returns props ready to spread onto a native `<input>`. The\n * generic `A` may be any value type; `bind` is most useful when `A` is\n * string-shaped. For non-string fields, wire `value`/`setValue` directly.\n */\nexport function useValidatedField<A, E = string>(opts: {\n readonly initial: A\n readonly validate: (a: A) => Validated<E, A>\n}): {\n readonly value: A\n setValue: (a: A) => void\n readonly validation: Validated<E, A>\n readonly errors: ListT<E>\n readonly isValid: boolean\n bind: () => { value: A; onChange: (e: ChangeEvent<HTMLInputElement>) => void }\n} {\n const [value, setValue] = useState<A>(opts.initial)\n\n const validation = useMemo(() => opts.validate(value), [opts, value])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const bind = useCallback(\n () => ({\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value as unknown as A),\n }),\n [value],\n )\n\n return { value, setValue, validation, errors, isValid, bind }\n}\n"],"mappings":"A,4GAiBA,SAAgBA,EAAiC,EAU/C,CACA,GAAM,CAACC,EAAOC,GAAYC,EAAYC,EAAK,OAAO,EAE5CC,EAAaC,MAAcF,EAAK,SAASH,CAAK,EAAG,CAACG,EAAMH,CAAK,CAAC,EAmBpE,MAAO,CAAE,QAAO,WAAU,aAAY,OAlBvBK,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAY8B,EAAG,QAV9BA,EAAW,QAUyB,EAAG,KAR1CI,OACJ,CACL,QACA,SAAW,GAAqCP,EAAS,EAAE,OAAO,KAAqB,CACzF,GACA,CAACD,CAAK,CAGkD,CAAE,CAC9D,C"}
1
+ {"version":3,"file":"useValidatedField.js","names":["List","useCallback","useMemo","useState","useValidatedField","opts","value","setValue","validation","es"],"sources":["../../src/forms/useValidatedField.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type ChangeEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Single-field state container with continuously-derived validation.\n *\n * `validation` is re-derived from `validate(value)` on every render — keep\n * `validate` cheap or memoize the callback.\n *\n * `bind()` returns props ready to spread onto a native `<input>`. The\n * generic `A` may be any value type; `bind` is most useful when `A` is\n * string-shaped. For non-string fields, wire `value`/`setValue` directly.\n */\nexport function useValidatedField<A, E = string>(opts: {\n readonly initial: A\n readonly validate: (a: A) => Validated<E, A>\n}): {\n readonly value: A\n setValue: (a: A) => void\n readonly validation: Validated<E, A>\n readonly errors: ListT<E>\n readonly isValid: boolean\n bind: () => { value: A; onChange: (e: ChangeEvent<HTMLInputElement>) => void }\n} {\n const [value, setValue] = useState<A>(opts.initial)\n\n const validation = useMemo(() => opts.validate(value), [opts, value])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const bind = useCallback(\n () => ({\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value as unknown as A),\n }),\n [value],\n )\n\n return { value, setValue, validation, errors, isValid, bind }\n}\n"],"mappings":"A,4GAiBA,SAAgBI,EAAiCC,EAU/C,CACA,GAAM,CAACC,EAAOC,GAAYJ,EAAYE,EAAK,OAAO,EAE5CG,EAAaN,MAAcG,EAAK,SAASC,CAAK,EAAG,CAACD,EAAMC,CAAK,CAAC,EAmBpE,MAAO,CAAEA,QAAOC,WAAUC,aAAY,OAlBvBN,MAEXM,EAAW,KACRC,GAAOA,MACFT,EAAK,MAAS,CACtB,EACF,CAACQ,CAAU,CAY8B,EAAG,QAV9BA,EAAW,QAUyB,EAAG,KAR1CP,OACJ,CACLK,QACA,SAAW,GAAqCC,EAAS,EAAE,OAAO,KAAqB,CACzF,GACA,CAACD,CAAK,CAGkD,CAAE,CAC9D,C"}
@@ -1,6 +1,6 @@
1
- import { Validated } from "./Validated.js";
2
- import { FormEvent } from "react";
3
1
  import { List } from "functype";
2
+ import { FormEvent } from "react";
3
+ import { Validated } from "./Validated.js";
4
4
  /**
5
5
  * Form-level state container with applicative error accumulation.
6
6
  *
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useMemo as t,useState as n}from"react";import{List as r}from"functype";function i(i){let[a,o]=n(i.initial),s=e((e,t)=>{o(n=>({...n,[e]:t}))},[]),c=e(()=>o(i.initial),[i.initial]),l=t(()=>i.validate(a),[i,a]);return{values:a,setField:s,validation:l,errors:t(()=>l.fold(e=>e,()=>r.empty()),[l]),isValid:l.isRight(),reset:c,handleSubmit:e(e=>t=>{t.preventDefault(),l.fold(()=>void 0,t=>{e(t)})},[l])}}export{i as useValidatedForm};
1
+ "use client";import{List as e}from"functype";import{useCallback as t,useMemo as n,useState as r}from"react";function i(i){let[a,o]=r(i.initial),s=t((e,t)=>{o(n=>({...n,[e]:t}))},[]),c=t(()=>o(i.initial),[i.initial]),l=n(()=>i.validate(a),[i,a]);return{values:a,setField:s,validation:l,errors:n(()=>l.fold(e=>e,()=>e.empty()),[l]),isValid:l.isRight(),reset:c,handleSubmit:t(e=>t=>{t.preventDefault(),l.fold(()=>void 0,t=>{e(t)})},[l])}}export{i as useValidatedForm};
2
2
  //# sourceMappingURL=useValidatedForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useValidatedForm.js","names":["useValidatedForm","values","setValues","useState","opts","setField","useCallback","prev","key","value","reset","validation","useMemo","es","List","e","onValid","s"],"sources":["../../src/forms/useValidatedForm.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type FormEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Form-level state container with applicative error accumulation.\n *\n * The consumer-provided `validate` is the canonical place to accumulate\n * field-level errors. A common pattern:\n *\n * ```ts\n * const validate = (s: Form): Validated<string, Form> => {\n * const errs = List<string>([])\n * .concat(s.email.includes(\"@\") ? List([]) : List([\"email must contain @\"]))\n * .concat(s.age >= 18 ? List([]) : List([\"age must be 18+\"]))\n * return errs.isEmpty ? valid(s) : invalid(errs)\n * }\n * ```\n *\n * `handleSubmit(onValid)` returns an event handler that calls `e.preventDefault()`\n * and only invokes `onValid` when the current form value passes validation.\n */\nexport function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {\n readonly initial: S\n readonly validate: (s: S) => Validated<E, S>\n}): {\n readonly values: S\n setField: <K extends keyof S>(key: K, value: S[K]) => void\n readonly validation: Validated<E, S>\n readonly errors: ListT<E>\n readonly isValid: boolean\n reset: () => void\n handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void\n} {\n const [values, setValues] = useState<S>(opts.initial)\n\n const setField = useCallback(<K extends keyof S>(key: K, value: S[K]) => {\n setValues((prev) => ({ ...prev, [key]: value }))\n }, [])\n\n const reset = useCallback(() => setValues(opts.initial), [opts.initial])\n\n const validation = useMemo(() => opts.validate(values), [opts, values])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const handleSubmit = useCallback(\n (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => {\n e.preventDefault()\n validation.fold(\n () => undefined,\n (s) => {\n void onValid(s)\n },\n )\n },\n [validation],\n )\n\n return { values, setField, validation, errors, isValid, reset, handleSubmit }\n}\n"],"mappings":"A,4GAyBA,SAAgBA,EAAgE,EAW9E,CACA,GAAM,CAACC,EAAQC,GAAaC,EAAYC,EAAK,OAAO,EAE9CC,EAAWC,GAAgC,EAAQ,IAAgB,CACvEJ,EAAW,IAAU,CAAE,GAAGK,GAAOC,GAAMC,CAAM,EAAE,CACjD,EAAG,CAAC,CAAC,EAECC,EAAQJ,MAAkBJ,EAAUE,EAAK,OAAO,EAAG,CAACA,EAAK,OAAO,CAAC,EAEjEO,EAAaC,MAAcR,EAAK,SAASH,CAAM,EAAG,CAACG,EAAMH,CAAM,CAAC,EAwBtE,MAAO,CAAE,SAAQ,WAAU,aAAY,OAvBxBW,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAiB+B,EAAG,QAf/BA,EAAW,QAe0B,EAAG,QAAO,aAb1CL,EAClB,GAA6C,GAAiB,CAC7DS,EAAE,eAAe,EACjBJ,EAAW,SACH,IAAA,GACL,GAAM,CACLK,EAAaC,CAAC,CAChB,CACF,CACF,EACA,CAACN,CAAU,CAG6D,CAAE,CAC9E,C"}
1
+ {"version":3,"file":"useValidatedForm.js","names":["List","useCallback","useMemo","useState","useValidatedForm","opts","values","setValues","setField","key","value","prev","reset","validation","es","onValid","e","s"],"sources":["../../src/forms/useValidatedForm.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type FormEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Form-level state container with applicative error accumulation.\n *\n * The consumer-provided `validate` is the canonical place to accumulate\n * field-level errors. A common pattern:\n *\n * ```ts\n * const validate = (s: Form): Validated<string, Form> => {\n * const errs = List<string>([])\n * .concat(s.email.includes(\"@\") ? List([]) : List([\"email must contain @\"]))\n * .concat(s.age >= 18 ? List([]) : List([\"age must be 18+\"]))\n * return errs.isEmpty ? valid(s) : invalid(errs)\n * }\n * ```\n *\n * `handleSubmit(onValid)` returns an event handler that calls `e.preventDefault()`\n * and only invokes `onValid` when the current form value passes validation.\n */\nexport function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {\n readonly initial: S\n readonly validate: (s: S) => Validated<E, S>\n}): {\n readonly values: S\n setField: <K extends keyof S>(key: K, value: S[K]) => void\n readonly validation: Validated<E, S>\n readonly errors: ListT<E>\n readonly isValid: boolean\n reset: () => void\n handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void\n} {\n const [values, setValues] = useState<S>(opts.initial)\n\n const setField = useCallback(<K extends keyof S>(key: K, value: S[K]) => {\n setValues((prev) => ({ ...prev, [key]: value }))\n }, [])\n\n const reset = useCallback(() => setValues(opts.initial), [opts.initial])\n\n const validation = useMemo(() => opts.validate(values), [opts, values])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const handleSubmit = useCallback(\n (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => {\n e.preventDefault()\n validation.fold(\n () => undefined,\n (s) => {\n void onValid(s)\n },\n )\n },\n [validation],\n )\n\n return { values, setField, validation, errors, isValid, reset, handleSubmit }\n}\n"],"mappings":"A,4GAyBA,SAAgBI,EAAgEC,EAW9E,CACA,GAAM,CAACC,EAAQC,GAAaJ,EAAYE,EAAK,OAAO,EAE9CG,EAAWP,GAAgCQ,EAAQC,IAAgB,CACvEH,EAAWI,IAAU,CAAE,GAAGA,GAAOF,GAAMC,CAAM,EAAE,CACjD,EAAG,CAAC,CAAC,EAECE,EAAQX,MAAkBM,EAAUF,EAAK,OAAO,EAAG,CAACA,EAAK,OAAO,CAAC,EAEjEQ,EAAaX,MAAcG,EAAK,SAASC,CAAM,EAAG,CAACD,EAAMC,CAAM,CAAC,EAwBtE,MAAO,CAAEA,SAAQE,WAAUK,aAAY,OAvBxBX,MAEXW,EAAW,KACRC,GAAOA,MACFd,EAAK,MAAS,CACtB,EACF,CAACa,CAAU,CAiB+B,EAAG,QAf/BA,EAAW,QAe0B,EAAGD,QAAO,aAb1CX,EAClBc,GAA6CC,GAAiB,CAC7DA,EAAE,eAAe,EACjBH,EAAW,SACH,IAAA,GACLI,GAAM,CACAF,EAAQE,CAAC,CAChB,CACF,CACF,EACA,CAACJ,CAAU,CAG6D,CAAE,CAC9E,C"}
@@ -1,2 +1,2 @@
1
- import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CQkAVer1.js";
1
+ import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-cYnbruZq.js";
2
2
  export { Eq, referenceEq, structuralEq, tagEq };
@@ -1 +1 @@
1
- {"version":3,"file":"eq.js","names":["referenceEq","tagEq","a","b","ta","tb","structuralEq","item","i","m","k","v","set","e","ka","proto","kb"],"sources":["../../src/hooks/eq.ts"],"sourcesContent":["/**\n * Equality comparators for use with `useStable*` hooks.\n *\n * functype core doesn't ship an Eq typeclass; instead, comparators are passed\n * explicitly. The default everywhere is `referenceEq` (Object.is), matching\n * React's built-in dependency comparison.\n */\n\nexport type Eq<A> = (a: A, b: A) => boolean\n\n/**\n * Reference equality, identical to React's default `Object.is` for hook deps.\n */\nexport const referenceEq: Eq<unknown> = Object.is\n\n/**\n * Compares two functype ADTs by their `_tag` literal only.\n *\n * Useful when you only care about variant changes (e.g., re-render when an\n * `Option` flips between Some and None, but not on payload changes). Returns\n * false for non-tagged values.\n */\nexport const tagEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== \"object\" || a === null) return false\n if (typeof b !== \"object\" || b === null) return false\n const ta = (a as { _tag?: unknown })._tag\n const tb = (b as { _tag?: unknown })._tag\n return ta !== undefined && ta === tb\n}\n\n/**\n * Recursive structural equality. Handles primitives, arrays, plain objects, tagged ADTs, `Date`,\n * `Error`, `RegExp`, `Map` and `Set` (whose members compare by reference). Any other object with no\n * enumerable own keys, such as a URL, is equal only to itself. Two objects with different prototypes are never equal. Cycles are not detected — passing\n * cyclic structures is undefined behavior. Functions compare by reference.\n *\n * functype values keep only their data as own properties (functype 2.0), so the walk below sees\n * `_tag` and `value`. A `Date` or `Error` has no enumerable own keys, so it gets compared first;\n * otherwise `Some(new Date(0))` and `Some(new Date(1))` would look equal.\n */\nexport const structuralEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== typeof b) return false\n if (a === null || b === null) return false\n if (typeof a !== \"object\") return false\n\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false\n return a.every((item, i) => structuralEq(item, b[i]))\n }\n if (Array.isArray(b)) return false\n if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime()\n if (a instanceof RegExp) return a.source === (b as RegExp).source && a.flags === (b as RegExp).flags\n if (a instanceof Map) {\n const m = b as ReadonlyMap<unknown, unknown>\n return a.size === m.size && [...a].every(([k, v]) => m.has(k) && structuralEq(v, m.get(k)))\n }\n if (a instanceof Set) {\n const set = b as ReadonlySet<unknown>\n return a.size === set.size && [...a].every((item) => set.has(item))\n }\n if (a instanceof Error) {\n const e = b as Error\n if (a.name !== e.name || a.message !== e.message || !structuralEq(a.cause, e.cause)) return false\n }\n\n const ka = Object.keys(a as object)\n // Any other built-in, such as a URL, keeps its state where the key walk can't see it, and was\n // already found not to be the same reference. Call it unequal, the safe direction for a hook.\n const proto: unknown = Object.getPrototypeOf(a)\n if (ka.length === 0 && proto !== Object.prototype && proto !== null && !(a instanceof Error)) return false\n const kb = Object.keys(b as object)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n Object.prototype.hasOwnProperty.call(b, k) &&\n structuralEq((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n}\n"],"mappings":"AAaA,MAAaA,EAA2B,OAAO,GASlCC,GAAsB,EAAG,IAAM,CAC1C,GAAI,OAAO,GAAGC,EAAGC,CAAC,EAAG,MAAO,GAE5B,GADI,OAAOD,GAAM,WAAYA,GACzB,OAAOC,GAAM,WAAYA,EAAY,MAAO,GAChD,IAAMC,EAAMF,EAAyB,KAC/BG,EAAMF,EAAyB,KACrC,OAAOC,IAAO,IAAA,IAAaA,IAAOC,CACpC,EAYaC,GAA6B,EAAG,IAAM,CACjD,GAAI,OAAO,GAAGJ,EAAGC,CAAC,EAAG,MAAO,GAG5B,GAFI,OAAOD,GAAM,OAAOC,GACpBD,IAAM,MAAQC,IAAM,MACpB,OAAOD,GAAM,SAAU,MAAO,GAElC,GAAI,MAAM,QAAQA,CAAC,EAEjB,MADI,CAAC,MAAM,QAAQC,CAAC,GAAKD,EAAE,SAAWC,EAAE,OAAe,GAChDD,EAAE,OAAO,EAAM,IAAMI,EAAaC,EAAMJ,EAAEK,EAAE,CAAC,EAGtD,GADI,MAAM,QAAQL,CAAC,GACf,OAAO,eAAeD,CAAC,IAAM,OAAO,eAAeC,CAAC,EAAG,MAAO,GAElE,GAAID,aAAa,KAAM,OAAOA,EAAE,QAAQ,IAAOC,EAAW,QAAQ,EAClE,GAAID,aAAa,OAAQ,OAAOA,EAAE,SAAYC,EAAa,QAAUD,EAAE,QAAWC,EAAa,MAC/F,GAAID,aAAa,IAAK,CACpB,IAAMO,EAAIN,EACV,OAAOD,EAAE,OAASO,EAAE,MAAQ,CAAC,GAAGP,CAAC,CAAC,CAAC,OAAO,CAACQ,EAAGC,KAAOF,EAAE,IAAIC,CAAC,GAAKJ,EAAaK,EAAGF,EAAE,IAAIC,CAAC,CAAC,CAAC,CAC5F,CACA,GAAIR,aAAa,IAAK,CACpB,IAAMU,EAAMT,EACZ,OAAOD,EAAE,OAASU,EAAI,MAAQ,CAAC,GAAGV,CAAC,CAAC,CAAC,MAAO,GAASU,EAAI,IAAIL,CAAI,CAAC,CACpE,CACA,GAAIL,aAAa,MAAO,CACtB,IAAMW,EAAIV,EACV,GAAID,EAAE,OAASW,EAAE,MAAQX,EAAE,UAAYW,EAAE,SAAW,CAACP,EAAaJ,EAAE,MAAOW,EAAE,KAAK,EAAG,MAAO,EAC9F,CAEA,IAAMC,EAAK,OAAO,KAAKZ,CAAW,EAG5Ba,EAAiB,OAAO,eAAeb,CAAC,EAC9C,GAAIY,EAAG,SAAW,GAAKC,IAAU,OAAO,WAAaA,IAAU,MAAQ,EAAEb,aAAa,OAAQ,MAAO,GACrG,IAAMc,EAAK,OAAO,KAAKb,CAAW,EAElC,OADIW,EAAG,SAAWE,EAAG,QACdF,EAAG,MACP,GACC,OAAO,UAAU,eAAe,KAAKX,EAAGO,CAAC,GACzCJ,EAAcJ,EAA8BQ,GAAKP,EAA8BO,EAAE,CACrF,CACF,E"}
1
+ {"version":3,"file":"eq.js","names":["referenceEq","tagEq","a","b","ta","tb","structuralEq","item","i","m","k","v","set","e","ka","proto","kb"],"sources":["../../src/hooks/eq.ts"],"sourcesContent":["/**\n * Equality comparators for use with `useStable*` hooks.\n *\n * functype core doesn't ship an Eq typeclass; instead, comparators are passed\n * explicitly. The default everywhere is `referenceEq` (Object.is), matching\n * React's built-in dependency comparison.\n */\n\nexport type Eq<A> = (a: A, b: A) => boolean\n\n/**\n * Reference equality, identical to React's default `Object.is` for hook deps.\n */\nexport const referenceEq: Eq<unknown> = Object.is\n\n/**\n * Compares two functype ADTs by their `_tag` literal only.\n *\n * Useful when you only care about variant changes (e.g., re-render when an\n * `Option` flips between Some and None, but not on payload changes). Returns\n * false for non-tagged values.\n */\nexport const tagEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== \"object\" || a === null) return false\n if (typeof b !== \"object\" || b === null) return false\n const ta = (a as { _tag?: unknown })._tag\n const tb = (b as { _tag?: unknown })._tag\n return ta !== undefined && ta === tb\n}\n\n/**\n * Recursive structural equality. Handles primitives, arrays, plain objects, tagged ADTs, `Date`,\n * `Error`, `RegExp`, `Map` and `Set` (whose members compare by reference). Any other object with no\n * enumerable own keys, such as a URL, is equal only to itself. Two objects with different prototypes are never equal. Cycles are not detected — passing\n * cyclic structures is undefined behavior. Functions compare by reference.\n *\n * functype values keep only their data as own properties (functype 2.0), so the walk below sees\n * `_tag` and `value`. A `Date` or `Error` has no enumerable own keys, so it gets compared first;\n * otherwise `Some(new Date(0))` and `Some(new Date(1))` would look equal.\n */\nexport const structuralEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== typeof b) return false\n if (a === null || b === null) return false\n if (typeof a !== \"object\") return false\n\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false\n return a.every((item, i) => structuralEq(item, b[i]))\n }\n if (Array.isArray(b)) return false\n if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime()\n if (a instanceof RegExp) return a.source === (b as RegExp).source && a.flags === (b as RegExp).flags\n if (a instanceof Map) {\n const m = b as ReadonlyMap<unknown, unknown>\n return a.size === m.size && [...a].every(([k, v]) => m.has(k) && structuralEq(v, m.get(k)))\n }\n if (a instanceof Set) {\n const set = b as ReadonlySet<unknown>\n return a.size === set.size && [...a].every((item) => set.has(item))\n }\n if (a instanceof Error) {\n const e = b as Error\n if (a.name !== e.name || a.message !== e.message || !structuralEq(a.cause, e.cause)) return false\n }\n\n const ka = Object.keys(a as object)\n // Any other built-in, such as a URL, keeps its state where the key walk can't see it, and was\n // already found not to be the same reference. Call it unequal, the safe direction for a hook.\n const proto: unknown = Object.getPrototypeOf(a)\n if (ka.length === 0 && proto !== Object.prototype && proto !== null && !(a instanceof Error)) return false\n const kb = Object.keys(b as object)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n Object.prototype.hasOwnProperty.call(b, k) &&\n structuralEq((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n}\n"],"mappings":"AAaA,MAAaA,EAA2B,OAAO,GASlCC,GAAsBC,EAAGC,IAAM,CAC1C,GAAI,OAAO,GAAGD,EAAGC,CAAC,EAAG,MAAO,GAE5B,GADI,OAAOD,GAAM,WAAYA,GACzB,OAAOC,GAAM,WAAYA,EAAY,MAAO,GAChD,IAAMC,EAAMF,EAAyB,KAC/BG,EAAMF,EAAyB,KACrC,OAAOC,IAAO,IAAA,IAAaA,IAAOC,CACpC,EAYaC,GAA6BJ,EAAGC,IAAM,CACjD,GAAI,OAAO,GAAGD,EAAGC,CAAC,EAAG,MAAO,GAG5B,GAFI,OAAOD,GAAM,OAAOC,GACpBD,IAAM,MAAQC,IAAM,MACpB,OAAOD,GAAM,SAAU,MAAO,GAElC,GAAI,MAAM,QAAQA,CAAC,EAEjB,MADI,CAAC,MAAM,QAAQC,CAAC,GAAKD,EAAE,SAAWC,EAAE,OAAe,GAChDD,EAAE,OAAOK,EAAMC,IAAMF,EAAaC,EAAMJ,EAAEK,EAAE,CAAC,EAGtD,GADI,MAAM,QAAQL,CAAC,GACf,OAAO,eAAeD,CAAC,IAAM,OAAO,eAAeC,CAAC,EAAG,MAAO,GAElE,GAAID,aAAa,KAAM,OAAOA,EAAE,QAAQ,IAAOC,EAAW,QAAQ,EAClE,GAAID,aAAa,OAAQ,OAAOA,EAAE,SAAYC,EAAa,QAAUD,EAAE,QAAWC,EAAa,MAC/F,GAAID,aAAa,IAAK,CACpB,IAAMO,EAAIN,EACV,OAAOD,EAAE,OAASO,EAAE,MAAQ,CAAC,GAAGP,CAAC,CAAC,CAAC,OAAO,CAACQ,EAAGC,KAAOF,EAAE,IAAIC,CAAC,GAAKJ,EAAaK,EAAGF,EAAE,IAAIC,CAAC,CAAC,CAAC,CAC5F,CACA,GAAIR,aAAa,IAAK,CACpB,IAAMU,EAAMT,EACZ,OAAOD,EAAE,OAASU,EAAI,MAAQ,CAAC,GAAGV,CAAC,CAAC,CAAC,MAAOK,GAASK,EAAI,IAAIL,CAAI,CAAC,CACpE,CACA,GAAIL,aAAa,MAAO,CACtB,IAAMW,EAAIV,EACV,GAAID,EAAE,OAASW,EAAE,MAAQX,EAAE,UAAYW,EAAE,SAAW,CAACP,EAAaJ,EAAE,MAAOW,EAAE,KAAK,EAAG,MAAO,EAC9F,CAEA,IAAMC,EAAK,OAAO,KAAKZ,CAAW,EAG5Ba,EAAiB,OAAO,eAAeb,CAAC,EAC9C,GAAIY,EAAG,SAAW,GAAKC,IAAU,OAAO,WAAaA,IAAU,MAAQ,EAAEb,aAAa,OAAQ,MAAO,GACrG,IAAMc,EAAK,OAAO,KAAKb,CAAW,EAElC,OADIW,EAAG,SAAWE,EAAG,QACdF,EAAG,MACPJ,GACC,OAAO,UAAU,eAAe,KAAKP,EAAGO,CAAC,GACzCJ,EAAcJ,EAA8BQ,GAAKP,EAA8BO,EAAE,CACrF,CACF,E"}
@@ -1,10 +1,10 @@
1
- import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CQkAVer1.js";
2
- import { t as useEither } from "../useEither-D1Rn_tLR.js";
3
- import { t as useList } from "../useList-C_7X5OA_.js";
4
- import { t as useOption } from "../useOption-B8UyOh8h.js";
5
- import { t as useStableCallback } from "../useStableCallback-DPo_3DGi.js";
6
- import { t as useStableEffect } from "../useStableEffect-C2D6ZQG5.js";
7
- import { t as useStableMemo } from "../useStableMemo-DUoJxF-7.js";
8
- import { t as useStableState } from "../useStableState-DLLiFi5r.js";
9
- import { t as useTry } from "../useTry-ie1X0NiH.js";
1
+ import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-cYnbruZq.js";
2
+ import { t as useEither } from "../useEither-BveKCnsh.js";
3
+ import { t as useList } from "../useList-B83krQsi.js";
4
+ import { t as useOption } from "../useOption-C1VH3h20.js";
5
+ import { t as useStableCallback } from "../useStableCallback-C4UjxvJ1.js";
6
+ import { t as useStableEffect } from "../useStableEffect-CgkwQ5kY.js";
7
+ import { t as useStableMemo } from "../useStableMemo-KbV23mg-.js";
8
+ import { t as useStableState } from "../useStableState-B-AaH7WY.js";
9
+ import { t as useTry } from "../useTry-B9VzXJLg.js";
10
10
  export { type Eq, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
@@ -1,2 +1,2 @@
1
- import { t as useEither } from "../useEither-D1Rn_tLR.js";
1
+ import { t as useEither } from "../useEither-BveKCnsh.js";
2
2
  export { useEither };
@@ -1 +1 @@
1
- {"version":3,"file":"useEither.js","names":["useEither","value","setValue","useState","initial","Left","setRight","useCallback","Right","a","setLeft","e","fold","onLeft","onRight","useMemo"],"sources":["../../src/hooks/useEither.ts"],"sourcesContent":["\"use client\"\n\nimport { type Either, Left, Right } from \"functype/either\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Either container. Defaults to Left(undefined) when no initial.\n */\nexport function useEither<E, A>(\n initial?: Either<E, A>,\n): {\n readonly value: Either<E, A>\n setRight: (a: A) => void\n setLeft: (e: E) => void\n fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R\n} {\n const [value, setValue] = useState<Either<E, A>>(() => initial ?? Left<E, A>(undefined as unknown as E))\n\n const setRight = useCallback((a: A) => setValue(Right<E, A>(a)), [])\n const setLeft = useCallback((e: E) => setValue(Left<E, A>(e)), [])\n\n const fold = useCallback(<R>(onLeft: (e: E) => R, onRight: (a: A) => R) => value.fold(onLeft, onRight), [value])\n\n return useMemo(() => ({ value, setRight, setLeft, fold }), [value, setRight, setLeft, fold])\n}\n"],"mappings":"A,8HAQA,SAAgBA,EACd,EAMA,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA6BC,GAAWC,EAAW,IAAA,EAAyB,CAAC,EAEjGC,EAAWC,EAAa,GAASL,EAASM,EAAYC,CAAC,CAAC,EAAG,CAAC,CAAC,EAC7DC,EAAUH,EAAa,GAASL,EAASG,EAAWM,CAAC,CAAC,EAAG,CAAC,CAAC,EAE3DC,EAAOL,GAAgB,EAAqB,IAAyBN,EAAM,KAAKY,EAAQC,CAAO,EAAG,CAACb,CAAK,CAAC,EAE/G,OAAOc,OAAe,CAAE,QAAO,WAAU,UAAS,MAAK,GAAI,CAACd,EAAOK,EAAUI,EAASE,CAAI,CAAC,CAC7F,C"}
1
+ {"version":3,"file":"useEither.js","names":["Left","Right","useCallback","useMemo","useState","useEither","initial","value","setValue","setRight","a","setLeft","e","fold","onLeft","onRight"],"sources":["../../src/hooks/useEither.ts"],"sourcesContent":["\"use client\"\n\nimport { type Either, Left, Right } from \"functype/either\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Either container. Defaults to Left(undefined) when no initial.\n */\nexport function useEither<E, A>(\n initial?: Either<E, A>,\n): {\n readonly value: Either<E, A>\n setRight: (a: A) => void\n setLeft: (e: E) => void\n fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R\n} {\n const [value, setValue] = useState<Either<E, A>>(() => initial ?? Left<E, A>(undefined as unknown as E))\n\n const setRight = useCallback((a: A) => setValue(Right<E, A>(a)), [])\n const setLeft = useCallback((e: E) => setValue(Left<E, A>(e)), [])\n\n const fold = useCallback(<R>(onLeft: (e: E) => R, onRight: (a: A) => R) => value.fold(onLeft, onRight), [value])\n\n return useMemo(() => ({ value, setRight, setLeft, fold }), [value, setRight, setLeft, fold])\n}\n"],"mappings":"A,8HAQA,SAAgBK,EACdC,EAMA,CACA,GAAM,CAACC,EAAOC,GAAYJ,MAA6BE,GAAWN,EAAW,IAAA,EAAyB,CAAC,EAEjGS,EAAWP,EAAaQ,GAASF,EAASP,EAAYS,CAAC,CAAC,EAAG,CAAC,CAAC,EAC7DC,EAAUT,EAAaU,GAASJ,EAASR,EAAWY,CAAC,CAAC,EAAG,CAAC,CAAC,EAE3DC,EAAOX,GAAgBY,EAAqBC,IAAyBR,EAAM,KAAKO,EAAQC,CAAO,EAAG,CAACR,CAAK,CAAC,EAE/G,OAAOJ,OAAe,CAAEI,QAAOE,WAAUE,UAASE,MAAK,GAAI,CAACN,EAAOE,EAAUE,EAASE,CAAI,CAAC,CAC7F,C"}
@@ -1,2 +1,2 @@
1
- import { t as useList } from "../useList-C_7X5OA_.js";
1
+ import { t as useList } from "../useList-B83krQsi.js";
2
2
  export { useList };
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useMemo as t,useState as n}from"react";import{List as r}from"functype/list";function i(i){let[a,o]=n(()=>r(i??[])),s=e(e=>o(t=>t.add(e)),[]),c=e(e=>o(t=>t.remove(e)),[]),l=e(e=>o(t=>t.removeAt(e)),[]),u=e(()=>o(r.empty()),[]),d=e(e=>a.map(e),[a]),f=e(e=>a.filter(e),[a]);return t(()=>({value:a,add:s,remove:c,removeAt:l,clear:u,map:d,filter:f}),[a,s,c,l,u,d,f])}export{i as useList};
1
+ "use client";import{List as e}from"functype/list";import{useCallback as t,useMemo as n,useState as r}from"react";function i(i){let[a,o]=r(()=>e(i??[])),s=t(e=>o(t=>t.add(e)),[]),c=t(e=>o(t=>t.remove(e)),[]),l=t(e=>o(t=>t.removeAt(e)),[]),u=t(()=>o(e.empty()),[]),d=t(e=>a.map(e),[a]),f=t(e=>a.filter(e),[a]);return n(()=>({value:a,add:s,remove:c,removeAt:l,clear:u,map:d,filter:f}),[a,s,c,l,u,d,f])}export{i as useList};
2
2
  //# sourceMappingURL=useList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useList.js","names":["useList","value","setValue","useState","List","initial","add","useCallback","prev","a","remove","removeAt","index","clear","map","f","filter","p","useMemo"],"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,SAAgBA,EAAW,EAQzB,CACA,GAAM,CAACC,EAAOC,GAAYC,MAAyBC,EAAQC,GAAW,CAAC,CAAC,CAAC,EAEnEC,EAAMC,EAAa,GAASL,EAAU,GAASM,EAAK,IAAIC,CAAC,CAAa,EAAG,CAAC,CAAC,EAC3EC,EAASH,EAAa,GAASL,EAAU,GAASM,EAAK,OAAOC,CAAC,CAAC,EAAG,CAAC,CAAC,EACrEE,EAAWJ,EAAa,GAAkBL,EAAU,GAASM,EAAK,SAASI,CAAK,CAAC,EAAG,CAAC,CAAC,EACtFC,EAAQN,MAAkBL,EAASE,EAAK,MAAS,CAAC,EAAG,CAAC,CAAC,EAEvDU,EAAMP,EAAgB,GAAmBN,EAAM,IAAIc,CAAC,EAAG,CAACd,CAAK,CAAC,EAC9De,EAAST,EAAa,GAAyBN,EAAM,OAAOgB,CAAC,EAAG,CAAChB,CAAK,CAAC,EAE7E,OAAOiB,OACE,CAAE,QAAO,MAAK,SAAQ,WAAU,QAAO,MAAK,QAAO,GAC1D,CAACjB,EAAOK,EAAKI,EAAQC,EAAUE,EAAOC,EAAKE,CAAM,CACnD,CACF,C"}
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-B8UyOh8h.js";
1
+ import { t as useOption } from "../useOption-C1VH3h20.js";
2
2
  export { useOption };
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useMemo as t,useState as n}from"react";import{Option as r}from"functype/option";function i(i){let[a,o]=n(()=>r(i)),s=e(e=>o(r(e)),[]),c=e(()=>o(r.none()),[]),l=e(e=>a.map(e),[a]),u=e((e,t)=>a.fold(e,t),[a]);return t(()=>({value:a,set:s,clear:c,map:l,fold:u}),[a,s,c,l,u])}export{i as useOption};
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":["useOption","value","setValue","useState","Option","initial","set","useCallback","a","clear","map","f","fold","onNone","onSome","useMemo"],"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,SAAgBA,EAAa,EAM3B,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA2BC,EAAUC,CAAO,CAAC,EAEjEC,EAAMC,EAAa,GAA4BL,EAASE,EAAUI,CAAC,CAAC,EAAG,CAAC,CAAC,EACzEC,EAAQF,MAAkBL,EAASE,EAAO,KAAQ,CAAC,EAAG,CAAC,CAAC,EAExDM,EAAMH,EAAgB,GAAmBN,EAAM,IAAIU,CAAC,EAAG,CAACV,CAAK,CAAC,EAC9DW,EAAOL,GAAgB,EAAiB,IAAwBN,EAAM,KAAKY,EAAQC,CAAM,EAAG,CAACb,CAAK,CAAC,EAEzG,OAAOc,OAAe,CAAE,QAAO,MAAK,QAAO,MAAK,MAAK,GAAI,CAACd,EAAOK,EAAKG,EAAOC,EAAKE,CAAI,CAAC,CACzF,C"}
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-DPo_3DGi.js";
1
+ import { t as useStableCallback } from "../useStableCallback-C4UjxvJ1.js";
2
2
  export { useStableCallback };
@@ -1,2 +1,2 @@
1
- "use client";import{referenceEq as e}from"./eq.js";import{useCallback as t,useRef as n}from"react";function r(r,i,a){let o=n(null),s=n(0);if(o.current===null)o.current=i,s.current+=1;else{let t=o.current;i.some((n,r)=>!(a?.[r]??e)(t[r],n))&&(o.current=i,s.current+=1)}return t(r,[s.current])}export{r as useStableCallback};
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":["useStableCallback","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useCallback","callback"],"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,SAAgBA,EACd,EACA,EAEA,EACG,CACH,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEA,OAAOM,EAAYC,EAAU,CAACR,EAAK,OAAO,CAAC,CAC7C,C"}
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-C2D6ZQG5.js";
1
+ import { t as useStableEffect } from "../useStableEffect-CgkwQ5kY.js";
2
2
  export { useStableEffect };
@@ -1,2 +1,2 @@
1
- "use client";import{referenceEq as e}from"./eq.js";import{useEffect as t,useRef as n}from"react";function r(r,i,a){let o=n(null),s=n(0);if(o.current===null)o.current=i,s.current+=1;else{let t=o.current;i.some((n,r)=>!(a?.[r]??e)(t[r],n))&&(o.current=i,s.current+=1)}t(r,[s.current])}export{r as useStableEffect};
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":["useStableEffect","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useEffect","effect"],"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,SAAgBA,EACd,EACA,EAEA,EACM,CACN,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEAM,EAAUC,EAAQ,CAACR,EAAK,OAAO,CAAC,CAClC,C"}
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-DUoJxF-7.js";
1
+ import { t as useStableMemo } from "../useStableMemo-KbV23mg-.js";
2
2
  export { useStableMemo };
@@ -1,2 +1,2 @@
1
- "use client";import{referenceEq as e}from"./eq.js";import{useMemo as t,useRef as n}from"react";function r(r,i,a){let o=n(null),s=n(0);if(o.current===null)o.current=i,s.current+=1;else{let t=o.current;i.some((n,r)=>!(a?.[r]??e)(t[r],n))&&(o.current=i,s.current+=1)}return t(r,[s.current])}export{r as useStableMemo};
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":["useStableMemo","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useMemo","factory"],"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,SAAgBA,EACd,EACA,EAEA,EACG,CACH,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEA,OAAOM,EAAQC,EAAS,CAACR,EAAK,OAAO,CAAC,CACxC,C"}
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-DLLiFi5r.js";
1
+ import { t as useStableState } from "../useStableState-B-AaH7WY.js";
2
2
  export { useStableState };
@@ -1,2 +1,2 @@
1
- "use client";import{referenceEq as e}from"./eq.js";import{useCallback as t,useRef as n,useState as r}from"react";function i(i,a=e){let[o,s]=r(i),c=n(o);return c.current=o,[o,t(e=>{let t=typeof e==`function`?e(c.current):e;a(c.current,t)||s(t)},[a])]}export{i as useStableState};
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":["useStableState","referenceEq","value","setValue","useState","initial","ref","useRef","useCallback","resolved","next","eq"],"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,SAAgBA,EACd,EACA,EAAYC,EACwC,CACpD,GAAM,CAACC,EAAOC,GAAYC,EAAYC,CAAO,EACvCC,EAAMC,EAAUL,CAAK,EAa3B,MAZA,GAAI,QAAUA,EAYP,CAACA,EAVUM,EACf,GAA+B,CAC9B,IAAMC,EAAW,OAAOC,GAAS,WAAcA,EAAwBJ,EAAI,OAAO,EAAII,EACjFC,EAAGL,EAAI,QAASG,CAAQ,GAC3BN,EAASM,CAAQ,CAErB,EACA,CAACE,CAAE,CAGkB,CAAC,CAC1B,C"}
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"}
@@ -1,2 +1,2 @@
1
- import { t as useTry } from "../useTry-ie1X0NiH.js";
1
+ import { t as useTry } from "../useTry-B9VzXJLg.js";
2
2
  export { useTry };
@@ -1,2 +1,2 @@
1
- "use client";import{useCallback as e,useMemo as t,useState as n}from"react";import{Try as r}from"functype/try";function i(i){let[a,o]=n(()=>i??r.failure(/* @__PURE__ */ Error(`uninitialized`))),s=e(e=>o(r.success(e)),[]),c=e(e=>o(r.failure(e)),[]),l=e((e,t)=>a.fold(e,t),[a]);return t(()=>({value:a,setSuccess:s,setFailure:c,fold:l}),[a,s,c,l])}export{i as useTry};
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
@@ -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":"A,+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,C"}
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,5 +1,5 @@
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
5
  /**
package/dist/index.d.ts CHANGED
@@ -6,15 +6,15 @@
6
6
  * (`./async`) and Tier 4 (`./forms`) stay subpath-only so that consumers
7
7
  * who don't need Suspense/async or applicative forms tree-shake them out.
8
8
  */
9
- import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-CQkAVer1.js";
10
- import { t as useEither } from "./useEither-D1Rn_tLR.js";
11
- import { t as useList } from "./useList-C_7X5OA_.js";
12
- import { t as useOption } from "./useOption-B8UyOh8h.js";
13
- import { t as useStableCallback } from "./useStableCallback-DPo_3DGi.js";
14
- import { t as useStableEffect } from "./useStableEffect-C2D6ZQG5.js";
15
- import { t as useStableMemo } from "./useStableMemo-DUoJxF-7.js";
16
- import { t as useStableState } from "./useStableState-DLLiFi5r.js";
17
- import { t as useTry } from "./useTry-ie1X0NiH.js";
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";
18
18
  import "./hooks/index.js";
19
- import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-Dr09mq-A.js";
19
+ import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-Byicsy1U.js";
20
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-CkGESkj9.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};
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};
@@ -1,2 +1,2 @@
1
- import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "../index-Dr09mq-A.js";
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 };
@@ -1 +1 @@
1
- export{i as Match,r as MatchEither,n as MatchOption,t as MatchTry}from"../match-CkGESkj9.js";
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-CkGESkj9.js.map
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 +1 @@
1
- {"version":3,"file":"IOQueryError.js","names":["isTaggedError","formatIOError","error","where","statusText","Try","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,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,cAAgB,OAAOA,CAAK,CAAC,EAGhE,OAAOA,CAAK,CACrB,EAUMI,GAAU,EAAgB,IAC1BC,GAAU,CAACP,EAAcE,CAAK,GAAKA,EAAM,KAAK,SAAW,EAAU,eAChEA,EAAM,OAAS,aAAe,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,OAAS,EAAIA,EAAM,KAAOA,EAAM,KAoBpH,IAAaM,EAAb,cAAqC,KAAM,CA2BzC,YAAY,EAAU,EAAkB,EAAS,GAAO,CACtD,MAAMC,GAAWR,EAAcC,CAAK,EAAG,CAAE,MAAOA,CAAM,CAAC,EACvD,KAAK,KAAOI,EAAOJ,EAAOK,CAAM,EAChC,KAAK,MAAQL,EACb,KAAK,OAASK,CAChB,CACF,EAGA,MAAaG,EAA+B,GAA6CR,aAAiBM,E"}
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"}
@@ -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,a)=>{let o=await t(()=>r()).fold(t=>{throw new e(t,void 0,!0)},e=>e.runExit({signal:a}));if(o.isFailure()){let{error:t}=o.toValue();throw new e(t,i?.formatError?.(t))}if(o.isDie())throw new e(o.toValue().defect,void 0,!0);if(o.isInterrupted())throw new e(new n,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};
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":["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 `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,MAAMA,EAAW,MACf,EACA,EACA,IACe,CACf,IAAMC,EAAO,MAAMC,MAAUC,EAAO,CAAC,CAAC,CAAC,KACpC,GAAW,CACV,MAAM,IAAIC,EAAaC,EAAa,IAAA,GAAW,EAAI,CACrD,EAGC,GAAOC,EAAG,QAAQ,CAAE,QAAO,CAAC,CAC/B,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,EAkBaS,GAET,EACA,IAED,GACCV,MAAeM,EAAGK,CAAO,EAAGH,EAASG,EAAQ,MAAM,EAc1CC,GACM,EAAuC,IACvD,GACCZ,MAAeM,EAAGO,CAAS,EAAGL,CAAO,E"}
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,4 +1,4 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
1
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
2
2
  /**
3
3
  * Structural view of a React Query result — the discriminated shape this module
4
4
  * actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the
@@ -1 +1 @@
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,EAAsB,GAAoD,CACrF,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,GAAuD,CAC3F,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,E"}
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,6 +1,6 @@
1
- import { IOQueryError } from "./IOQueryError.js";
2
- import { IO } from "functype/io";
3
1
  import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
2
+ import { IO } from "functype/io";
3
+ import { IOQueryError } from "./IOQueryError.js";
4
4
  export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
5
5
  /** Override the derived `Error.message` on failure. */
6
6
  readonly formatError?: (error: E) => string;
@@ -1,2 +1,2 @@
1
- "use client";import{ioMutationFn as e}from"./ioQueryFn.js";import{useMutation as t}from"@tanstack/react-query";function n(n,r){let{formatError:i,...a}=r??{};return t({...a,mutationFn:e(n,{formatError:i})})}export{n as useIOMutation};
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":["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":"A,+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,C"}
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"}
@@ -1,8 +1,8 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
1
+ import { UseMutationResult } from "@tanstack/react-query";
2
+ import { IO } from "functype/io";
3
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
2
4
  import { IOQueryError } from "./IOQueryError.js";
3
5
  import { UseIOMutationOptions } from "./useIOMutation.js";
4
- import { IO } from "functype/io";
5
- import { UseMutationResult } from "@tanstack/react-query";
6
6
  /**
7
7
  * `AsyncState` plus the flags and the trigger functions. Unlike a query, a mutation is
8
8
  * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried
@@ -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 { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `AsyncState` 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> = AsyncState<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 `AsyncState` 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":"A,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,C"}
1
+ {"version":3,"file":"useIOMutationState.js","names":["toMutationState","useIOMutation","useIOMutationState","io","options","mutation","state"],"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 { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `AsyncState` 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> = AsyncState<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 `AsyncState` 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":"A,kHA2CA,SAAgBE,EACdC,EACAC,EAC6C,CAC7C,IAAMC,EAAWJ,EAAcE,EAAIC,CAAO,EACpCE,EAAQN,EAAgBK,CAAQ,EAEtC,MAAO,CACL,GAAGC,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,OAAQD,EAAS,OACjB,YAAaA,EAAS,YACtB,MAAOA,EAAS,KAClB,CACF,C"}
@@ -1,6 +1,6 @@
1
- import { IOQueryError } from "./IOQueryError.js";
2
- import { IO } from "functype/io";
3
1
  import { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
2
+ import { IO } from "functype/io";
3
+ import { IOQueryError } from "./IOQueryError.js";
4
4
  export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>, "queryKey" | "queryFn"> & {
5
5
  /** Override the derived `Error.message` on failure. */
6
6
  readonly formatError?: (error: E) => string;
@@ -1,2 +1,2 @@
1
- "use client";import{ioQueryFn as e}from"./ioQueryFn.js";import{useQuery as t}from"@tanstack/react-query";function n(n,r,i){let{formatError:a,...o}=i??{};return t({...o,queryKey:n,queryFn:e(r,{formatError:a})})}export{n as useIOQuery};
1
+ "use client";import{useQuery as e}from"@tanstack/react-query";import{ioQueryFn as t}from"./ioQueryFn.js";function n(n,r,i){let{formatError:a,...o}=i??{};return e({...o,queryKey:n,queryFn:t(r,{formatError:a})})}export{n as useIOQuery};
2
2
  //# sourceMappingURL=useIOQuery.js.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":"A,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,C"}
1
+ {"version":3,"file":"useIOQuery.js","names":["useQuery","ioQueryFn","useIOQuery","queryKey","io","options","formatError","queryOptions"],"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":"A,yGA4CA,SAAgBE,EACdC,EACAC,EACAC,EACwC,CACxC,GAAM,CAAEC,cAAa,GAAGC,GAAiBF,GAAW,CAAC,EAErD,OAAOL,EAA+C,CACpD,GAAGO,EACHJ,WACA,QAASF,EAAiDG,EAAI,CAAEE,aAAY,CAAC,CAC/E,CAAC,CACH,C"}
@@ -1,8 +1,8 @@
1
- import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
1
+ import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
2
+ import { IO } from "functype/io";
3
+ import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
2
4
  import { IOQueryError } from "./IOQueryError.js";
3
5
  import { UseIOQueryOptions } from "./useIOQuery.js";
4
- import { IO } from "functype/io";
5
- import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
6
6
  /**
7
7
  * `AsyncState` plus the convenience flags and refetch trigger, mirroring
8
8
  * `UseIOResult` from `functype-react/async` so both async surfaces read alike.
@@ -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 { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `AsyncState` plus the convenience flags and refetch trigger, mirroring\n * `UseIOResult` 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> = AsyncState<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 `AsyncState` 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":"A,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,C"}
1
+ {"version":3,"file":"useIOQueryState.js","names":["toQueryState","useIOQuery","useIOQueryState","queryKey","io","options","query","state"],"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 { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `AsyncState` plus the convenience flags and refetch trigger, mirroring\n * `UseIOResult` 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> = AsyncState<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 `AsyncState` 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":"A,yGAgDA,SAAgBE,EACdC,EACAC,EACAC,EACiC,CACjC,IAAMC,EAAQL,EAAWE,EAAUC,EAAIC,CAAO,EACxCE,EAAQP,EAAaM,CAAK,EAEhC,MAAO,CACL,GAAGC,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,QAASD,EAAM,OACjB,CACF,C"}
@@ -1,5 +1,5 @@
1
- import { t as Eq } from "./eq-CQkAVer1.js";
2
1
  import { DependencyList } from "react";
2
+ import { t as Eq } from "./eq-cYnbruZq.js";
3
3
  /**
4
4
  * Like `useCallback`, but only returns a new function when *some* dep has
5
5
  * changed under the supplied (or default) comparator.
@@ -1,5 +1,5 @@
1
- import { t as Eq } from "./eq-CQkAVer1.js";
2
1
  import { DependencyList, EffectCallback } from "react";
2
+ import { t as Eq } from "./eq-cYnbruZq.js";
3
3
  /**
4
4
  * Like `useEffect`, but re-runs only when *some* dep has changed under the
5
5
  * supplied (or default) comparator. The `eqs` array is aligned positionally
@@ -1,5 +1,5 @@
1
- import { t as Eq } from "./eq-CQkAVer1.js";
2
1
  import { DependencyList } from "react";
2
+ import { t as Eq } from "./eq-cYnbruZq.js";
3
3
  /**
4
4
  * Like `useMemo`, but recomputes only when *some* dep has changed under the
5
5
  * supplied (or default) comparator. The `eqs` array is aligned positionally
@@ -1,4 +1,4 @@
1
- import { t as Eq } from "./eq-CQkAVer1.js";
1
+ import { t as Eq } from "./eq-cYnbruZq.js";
2
2
  /**
3
3
  * Drop-in replacement for `useState` that no-ops when the next value is equal
4
4
  * to the current under `eq`. Defaults to `Object.is` (React's built-in), so the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype-react",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "React bindings for functype — ADT-aware hooks and exhaustive pattern matching components",
5
5
  "keywords": [
6
6
  "functype",
@@ -47,11 +47,11 @@
47
47
  "@types/react": "^19.3.0",
48
48
  "@types/react-dom": "^19.3.0",
49
49
  "fast-check": "^4.10.2",
50
- "functype": "^2.0.0",
50
+ "functype": "^2.1.0",
51
51
  "jsdom": "^31.0.1",
52
52
  "react": "^19.3.1",
53
53
  "react-dom": "^19.3.1",
54
- "ts-builds": "^4.5.0",
54
+ "ts-builds": "^5.0.0",
55
55
  "tsdown": "^0.23.7"
56
56
  },
57
57
  "type": "module",
@@ -1 +0,0 @@
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":"A,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,C"}
File without changes