functype-react 1.9.0 → 1.11.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 (50) hide show
  1. package/dist/async/index.d.ts +2 -2
  2. package/dist/async/index.js +1 -1
  3. package/dist/async/index.js.map +1 -1
  4. package/dist/async/useTask.d.ts +2 -3
  5. package/dist/async/useTask.js.map +1 -1
  6. package/dist/async/useTaskPromise.d.ts +1 -2
  7. package/dist/async/useTaskPromise.js.map +1 -1
  8. package/dist/async/useTaskValue.d.ts +3 -2
  9. package/dist/async/useTaskValue.js.map +1 -1
  10. package/dist/forms/Validated.d.ts +3 -4
  11. package/dist/forms/Validated.js.map +1 -1
  12. package/dist/forms/useValidatedField.d.ts +1 -2
  13. package/dist/forms/useValidatedField.js.map +1 -1
  14. package/dist/forms/useValidatedForm.d.ts +1 -2
  15. package/dist/forms/useValidatedForm.js.map +1 -1
  16. package/dist/hooks/eq.js.map +1 -1
  17. package/dist/hooks/index.d.ts +1 -1
  18. package/dist/hooks/useEither.js.map +1 -1
  19. package/dist/hooks/useList.js.map +1 -1
  20. package/dist/hooks/useOption.d.ts +1 -1
  21. package/dist/hooks/useOption.js.map +1 -1
  22. package/dist/hooks/useStableCallback.js.map +1 -1
  23. package/dist/hooks/useStableEffect.js.map +1 -1
  24. package/dist/hooks/useStableMemo.js.map +1 -1
  25. package/dist/hooks/useStableState.js.map +1 -1
  26. package/dist/hooks/useTry.js +1 -1
  27. package/dist/hooks/useTry.js.map +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/match/index.js +1 -1
  31. package/dist/match-CkGESkj9.js +2 -0
  32. package/dist/match-CkGESkj9.js.map +1 -0
  33. package/dist/query/IOQueryError.d.ts +3 -4
  34. package/dist/query/IOQueryError.js.map +1 -1
  35. package/dist/query/ioQueryFn.d.ts +4 -5
  36. package/dist/query/ioQueryFn.js.map +1 -1
  37. package/dist/query/queryState.d.ts +4 -5
  38. package/dist/query/queryState.js.map +1 -1
  39. package/dist/query/useIOMutation.d.ts +2 -3
  40. package/dist/query/useIOMutation.js.map +1 -1
  41. package/dist/query/useIOMutationState.d.ts +2 -3
  42. package/dist/query/useIOMutationState.js.map +1 -1
  43. package/dist/query/useIOQuery.d.ts +2 -3
  44. package/dist/query/useIOQuery.js.map +1 -1
  45. package/dist/query/useIOQueryState.d.ts +2 -3
  46. package/dist/query/useIOQueryState.js.map +1 -1
  47. package/dist/{useOption-ByA_TwP_.d.ts → useOption-CXXNC1_S.d.ts} +3 -1
  48. package/package.json +15 -15
  49. package/dist/match-4aBdbQyD.js +0 -2
  50. package/dist/match-4aBdbQyD.js.map +0 -1
@@ -18,7 +18,7 @@ type Props = {
18
18
  * The ErrorBoundary wraps the Suspense, matching React's documented rule
19
19
  * (otherwise Suspense would catch errors instead of the boundary).
20
20
  */
21
- declare function TaskBoundary(props: Props): ReactElement;
21
+ export declare function TaskBoundary(props: Props): ReactElement;
22
22
  //#endregion
23
- export { TaskBoundary, type TaskState, type UseTaskResult, useTask, useTaskPromise, useTaskValue };
23
+ export { type TaskState, type UseTaskResult, useTask, useTaskPromise, useTaskValue };
24
24
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- import{useTask as e}from"./useTask.js";import{useTaskPromise as t}from"./useTaskPromise.js";import{useTaskValue as n}from"./useTaskValue.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 a(o,{fallback:e.fallback,children:a(i,{fallback:e.pending,children:e.children})})}export{s as TaskBoundary,e as useTask,t as useTaskPromise,n as useTaskValue};
1
+ import{useTask as e}from"./useTask.js";import{useTaskPromise as t}from"./useTaskPromise.js";import{useTaskValue as n}from"./useTaskValue.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 TaskBoundary,e as useTask,t as useTaskPromise,n as useTaskValue};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/async/TaskBoundary.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 TaskErrorBoundary 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 Tasks consumed via `useTaskValue`) 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 TaskBoundary(props: Props): ReactElement {\n return (\n <TaskErrorBoundary fallback={props.fallback}>\n <Suspense fallback={props.pending}>{props.children}</Suspense>\n </TaskErrorBoundary>\n )\n}\n"],"mappings":"qOAYA,IAAM,EAAN,cAAgC,CAG9B,+BACA,KAAS,MAAe,CAAE,KAAM,IAAK,EAUrC,KAAA,UAAoB,CAClB,KAAK,SAAS,CAAE,KAAM,IAAK,CAAC,CAC9B,EAVA,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,SAAgB,EAAa,EAA4B,CACvD,OACE,EAAC,EAAD,CAAmB,SAAU,EAAM,SACjC,SAAA,EAAC,EAAD,CAAU,SAAU,EAAM,QAAU,SAAA,EAAM,QAAmB,CAAA,CAC5C,CAAA,CAEvB"}
1
+ {"version":3,"file":"index.js","names":["TaskErrorBoundary","Component","_args","TaskBoundary","props","Suspense","useTask","useTaskPromise","useTaskValue"],"sources":["../../src/async/TaskBoundary.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 TaskErrorBoundary 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 Tasks consumed via `useTaskValue`) 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 TaskBoundary(props: Props): ReactElement {\n return (\n <TaskErrorBoundary fallback={props.fallback}>\n <Suspense fallback={props.pending}>{props.children}</Suspense>\n </TaskErrorBoundary>\n )\n}\n"],"mappings":"qOAYA,IAAMA,EAAN,cAAgCC,CAG9B,+BACA,KAAS,MAAe,CAAE,KAAM,IAAK,EAUrC,KAAA,UAAoB,CAClB,KAAK,SAAS,CAAE,KAAM,IAAK,CAAC,CAC9B,EAVA,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,EAAa,EAA4B,CACvD,MACE,kBAACH,EAAD,CAAmB,SAAUI,EAAM,SACjC,SAAA,kBAACC,EAAD,CAAU,SAAUD,EAAM,QAAU,SAAAA,EAAM,QAAmB,CAAA,CAC5C,CAAA,CAEvB"}
@@ -1,7 +1,7 @@
1
1
  import { t as TaskState } from "../TaskState-DWxGWqXf.js";
2
2
  import { Throwable } from "functype";
3
3
  //#region src/async/useTask.d.ts
4
- type UseTaskResult<E, A> = TaskState<E, A> & {
4
+ export type UseTaskResult<E, A> = TaskState<E, A> & {
5
5
  readonly isIdle: boolean;
6
6
  readonly isPending: boolean;
7
7
  readonly isSuccess: boolean;
@@ -19,7 +19,6 @@ type UseTaskResult<E, A> = TaskState<E, A> & {
19
19
  * - StrictMode-safe: the cleanup fn cancels the token and discards any
20
20
  * late-arriving result.
21
21
  */
22
- declare function useTask<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): UseTaskResult<Throwable, A>;
22
+ export declare function useTask<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): UseTaskResult<Throwable, A>;
23
23
  //#endregion
24
- export { UseTaskResult, useTask };
25
24
  //# sourceMappingURL=useTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTask.js","names":[],"sources":["../../src/async/useTask.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type Throwable } from \"functype\"\nimport { useCallback, useEffect, useReducer, useRef } from \"react\"\n\nimport type { TaskState } from \"./TaskState\"\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: TaskState<E, A>, action: Action<E, A>): TaskState<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 UseTaskResult<E, A> = TaskState<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 * Run an async operation tied to a React component's lifecycle.\n *\n * - Returns a discriminated `TaskState<Throwable, A>` plus boolean flags and\n * a `refetch` trigger.\n * - The `task` callback receives an `AbortSignal` wired to a cancellation\n * token that fires when the component unmounts or `deps` change. Pass the\n * signal to `fetch` (or any abortable API) to cancel in-flight work.\n * - StrictMode-safe: the cleanup fn cancels the token and discards any\n * late-arriving result.\n */\nexport function useTask<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): UseTaskResult<Throwable, A> {\n const [state, dispatch] = useReducer(reducer<Throwable, A>, { _tag: \"Idle\" })\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const taskRef = useRef(task)\n taskRef.current = task\n\n useEffect(() => {\n const cancelled = { value: false }\n const tokenSource = createCancellationTokenSource()\n dispatch({ type: \"PENDING\" })\n\n void Task<A>()\n .Async<A>(() => taskRef.current(tokenSource.token.signal) as Promise<A>, undefined, undefined, tokenSource.token)\n .then((outcome) => {\n if (cancelled.value) return\n if (outcome.isOk()) {\n dispatch({ type: \"SUCCESS\", value: outcome.value as A })\n } else {\n dispatch({ type: \"FAILURE\", error: outcome.error as Throwable })\n }\n })\n\n return () => {\n cancelled.value = true\n tokenSource.cancel()\n }\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\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":"+JAYA,SAAS,EAAc,EAAyB,EAAuC,CAGrF,OAFI,EAAO,OAAS,UAAkB,CAAE,KAAM,SAAU,EACpD,EAAO,OAAS,UAAkB,CAAE,KAAM,UAAW,MAAO,EAAO,KAAM,EACtE,CAAE,KAAM,UAAW,MAAO,EAAO,KAAM,CAChD,CAqBA,SAAgB,EACd,EACA,EAC6B,CAC7B,GAAM,CAAC,EAAO,GAAY,EAAW,EAAuB,CAAE,KAAM,MAAO,CAAC,EACtE,CAAC,EAAa,GAAgB,EAAY,GAAc,EAAI,EAAG,CAAC,EAChE,EAAU,EAAO,CAAI,EAC3B,EAAQ,QAAU,EAElB,MAAgB,CACd,IAAM,EAAY,CAAE,MAAO,EAAM,EAC3B,EAAc,EAA8B,EAclD,OAbA,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5B,EAAa,CAAC,CACX,UAAe,EAAQ,QAAQ,EAAY,MAAM,MAAM,EAAiB,IAAA,GAAW,IAAA,GAAW,EAAY,KAAK,CAAC,CAChH,KAAM,GAAY,CACb,EAAU,QACV,EAAQ,KAAK,EACf,EAAS,CAAE,KAAM,UAAW,MAAO,EAAQ,KAAW,CAAC,EAEvD,EAAS,CAAE,KAAM,UAAW,MAAO,EAAQ,KAAmB,CAAC,EAEnE,CAAC,MAEU,CACX,EAAU,MAAQ,GAClB,EAAY,OAAO,CACrB,CACF,EAAG,CAAC,GAAG,EAAM,CAAW,CAAC,EAEzB,IAAM,EAAU,MAAkB,EAAa,EAAG,CAAC,CAAC,EAEpD,MAAO,CACL,GAAG,EACH,OAAQ,EAAM,OAAS,OACvB,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,SACF,CACF"}
1
+ {"version":3,"file":"useTask.js","names":["reducer","action","useTask","state","dispatch","useReducer","refetchTick","forceRefetch","n","taskRef","useRef","task","useEffect","cancelled","tokenSource","createCancellationTokenSource","Task","outcome","deps","refetch","useCallback"],"sources":["../../src/async/useTask.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type Throwable } from \"functype\"\nimport { useCallback, useEffect, useReducer, useRef } from \"react\"\n\nimport type { TaskState } from \"./TaskState\"\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: TaskState<E, A>, action: Action<E, A>): TaskState<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 UseTaskResult<E, A> = TaskState<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 * Run an async operation tied to a React component's lifecycle.\n *\n * - Returns a discriminated `TaskState<Throwable, A>` plus boolean flags and\n * a `refetch` trigger.\n * - The `task` callback receives an `AbortSignal` wired to a cancellation\n * token that fires when the component unmounts or `deps` change. Pass the\n * signal to `fetch` (or any abortable API) to cancel in-flight work.\n * - StrictMode-safe: the cleanup fn cancels the token and discards any\n * late-arriving result.\n */\nexport function useTask<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): UseTaskResult<Throwable, A> {\n const [state, dispatch] = useReducer(reducer<Throwable, A>, { _tag: \"Idle\" })\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const taskRef = useRef(task)\n taskRef.current = task\n\n useEffect(() => {\n const cancelled = { value: false }\n const tokenSource = createCancellationTokenSource()\n dispatch({ type: \"PENDING\" })\n\n void Task<A>()\n .Async<A>(() => taskRef.current(tokenSource.token.signal) as Promise<A>, undefined, undefined, tokenSource.token)\n .then((outcome) => {\n if (cancelled.value) return\n if (outcome.isOk()) {\n dispatch({ type: \"SUCCESS\", value: outcome.value as A })\n } else {\n dispatch({ type: \"FAILURE\", error: outcome.error as Throwable })\n }\n })\n\n return () => {\n cancelled.value = true\n tokenSource.cancel()\n }\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\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":"+JAYA,SAASA,EAAc,EAAyB,EAAuC,CAGrF,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,CAqBA,SAAgBC,EACd,EACA,EAC6B,CAC7B,GAAM,CAACC,EAAOC,GAAYC,EAAWL,EAAuB,CAAE,KAAM,MAAO,CAAC,EACtE,CAACM,EAAaC,GAAgBF,EAAY,GAAcG,EAAI,EAAG,CAAC,EAChEC,EAAUC,EAAOC,CAAI,EAC3B,EAAQ,QAAUA,EAElBC,MAAgB,CACd,IAAMC,EAAY,CAAE,MAAO,EAAM,EAC3BC,EAAcC,EAA8B,EAclD,OAbAX,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5BY,EAAa,CAAC,CACX,UAAeP,EAAQ,QAAQK,EAAY,MAAM,MAAM,EAAiB,IAAA,GAAW,IAAA,GAAWA,EAAY,KAAK,CAAC,CAChH,KAAM,GAAY,CACbD,EAAU,QACVI,EAAQ,KAAK,EACfb,EAAS,CAAE,KAAM,UAAW,MAAOa,EAAQ,KAAW,CAAC,EAEvDb,EAAS,CAAE,KAAM,UAAW,MAAOa,EAAQ,KAAmB,CAAC,EAEnE,CAAC,MAEU,CACX,EAAU,MAAQ,GAClBH,EAAY,OAAO,CACrB,CACF,EAAG,CAAC,GAAGI,EAAMZ,CAAW,CAAC,EAEzB,IAAMa,EAAUC,MAAkBb,EAAa,EAAG,CAAC,CAAC,EAEpD,MAAO,CACL,GAAGJ,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,SACF,CACF"}
@@ -9,7 +9,6 @@ import { TaskOutcome } from "functype";
9
9
  * even if it isn't included in `deps`. Encode in `deps` whatever semantically
10
10
  * changes the task's result.
11
11
  */
12
- declare function useTaskPromise<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): Promise<TaskOutcome<A>>;
12
+ export declare function useTaskPromise<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): Promise<TaskOutcome<A>>;
13
13
  //#endregion
14
- export { useTaskPromise };
15
14
  //# sourceMappingURL=useTaskPromise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTaskPromise.js","names":[],"sources":["../../src/async/useTaskPromise.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type TaskOutcome } from \"functype\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Returns a `Promise<TaskOutcome<A>>` that is stable across renders with the\n * same `deps`. Intended for consumers of React 19's `use()` hook — providing\n * a new promise reference on each render would infinite-suspend.\n *\n * The `task` callback is read through a ref, so the latest closure is invoked\n * even if it isn't included in `deps`. Encode in `deps` whatever semantically\n * changes the task's result.\n */\nexport function useTaskPromise<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): Promise<TaskOutcome<A>> {\n const taskRef = useRef(task)\n taskRef.current = task\n\n return useMemo(() => {\n const tokenSource = createCancellationTokenSource()\n return Task<A>().Async<A>(\n () => taskRef.current(tokenSource.token.signal) as Promise<A>,\n undefined,\n undefined,\n tokenSource.token,\n )\n }, deps)\n}\n"],"mappings":"4HAcA,SAAgB,EACd,EACA,EACyB,CACzB,IAAM,EAAU,EAAO,CAAI,EAG3B,MAFA,GAAQ,QAAU,EAEX,MAAc,CACnB,IAAM,EAAc,EAA8B,EAClD,OAAO,EAAQ,CAAC,CAAC,UACT,EAAQ,QAAQ,EAAY,MAAM,MAAM,EAC9C,IAAA,GACA,IAAA,GACA,EAAY,KACd,CACF,EAAG,CAAI,CACT"}
1
+ {"version":3,"file":"useTaskPromise.js","names":["useTaskPromise","taskRef","useRef","task","useMemo","tokenSource","createCancellationTokenSource","Task","deps"],"sources":["../../src/async/useTaskPromise.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type TaskOutcome } from \"functype\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Returns a `Promise<TaskOutcome<A>>` that is stable across renders with the\n * same `deps`. Intended for consumers of React 19's `use()` hook — providing\n * a new promise reference on each render would infinite-suspend.\n *\n * The `task` callback is read through a ref, so the latest closure is invoked\n * even if it isn't included in `deps`. Encode in `deps` whatever semantically\n * changes the task's result.\n */\nexport function useTaskPromise<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): Promise<TaskOutcome<A>> {\n const taskRef = useRef(task)\n taskRef.current = task\n\n return useMemo(() => {\n const tokenSource = createCancellationTokenSource()\n return Task<A>().Async<A>(\n () => taskRef.current(tokenSource.token.signal) as Promise<A>,\n undefined,\n undefined,\n tokenSource.token,\n )\n }, deps)\n}\n"],"mappings":"4HAcA,SAAgBA,EACd,EACA,EACyB,CACzB,IAAMC,EAAUC,EAAOC,CAAI,EAG3B,MAFA,GAAQ,QAAUA,EAEXC,MAAc,CACnB,IAAMC,EAAcC,EAA8B,EAClD,OAAOC,EAAQ,CAAC,CAAC,UACTN,EAAQ,QAAQI,EAAY,MAAM,MAAM,EAC9C,IAAA,GACA,IAAA,GACAA,EAAY,KACd,CACF,EAAGG,CAAI,CACT"}
@@ -12,12 +12,13 @@
12
12
  * 3. Do not call this on the server. Pass the underlying `Task` (or its
13
13
  * promise) into a Client Component and call `useTaskValue` there.
14
14
  *
15
+ * @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.
16
+ *
15
17
  * Testing note: React 19's `use()` does not unsuspend reliably under jsdom +
16
18
  * @testing-library/react. End-to-end tests of `useTaskValue` + `<TaskBoundary>`
17
19
  * require a real browser scheduler (Playwright); unit tests of `useTask` and
18
20
  * `useTaskPromise` cover the Task plumbing.
19
21
  */
20
- declare function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A;
22
+ export declare function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A;
21
23
  //#endregion
22
- export { useTaskValue };
23
24
  //# sourceMappingURL=useTaskValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTaskValue.js","names":[],"sources":["../../src/async/useTaskValue.ts"],"sourcesContent":["\"use client\"\n/* eslint-disable functype/prefer-either -- the throw is the contract: React's `use()` semantics require errors to propagate to the nearest ErrorBoundary via throw, not via an Either return. */\n\nimport { use } from \"react\"\n\nimport { useTaskPromise } from \"./useTaskPromise\"\n\n/**\n * Suspense-aware variant of `useTask` for React 19+. Suspends the component\n * while the task is pending and throws on failure — both behaviors integrate\n * with `<TaskBoundary>` (or a hand-rolled Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useTaskPromise` memoizes by\n * `deps`, so passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise\n * Suspense will catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Pass the underlying `Task` (or its\n * promise) into a Client Component and call `useTaskValue` there.\n *\n * Testing note: React 19's `use()` does not unsuspend reliably under jsdom +\n * @testing-library/react. End-to-end tests of `useTaskValue` + `<TaskBoundary>`\n * require a real browser scheduler (Playwright); unit tests of `useTask` and\n * `useTaskPromise` cover the Task plumbing.\n */\nexport function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A {\n const outcome = use(useTaskPromise(task, deps))\n if (outcome.isErr()) {\n throw outcome.error\n }\n return outcome.value as A\n}\n"],"mappings":"8FAyBA,SAAgB,EAAgB,EAA+C,EAAiC,CAC9G,IAAM,EAAU,EAAI,EAAe,EAAM,CAAI,CAAC,EAC9C,GAAI,EAAQ,MAAM,EAChB,MAAM,EAAQ,MAEhB,OAAO,EAAQ,KACjB"}
1
+ {"version":3,"file":"useTaskValue.js","names":["useTaskValue","outcome","use","useTaskPromise","task","deps"],"sources":["../../src/async/useTaskValue.ts"],"sourcesContent":["\"use client\"\n\nimport { use } from \"react\"\n\nimport { useTaskPromise } from \"./useTaskPromise\"\n\n/**\n * Suspense-aware variant of `useTask` for React 19+. Suspends the component\n * while the task is pending and throws on failure — both behaviors integrate\n * with `<TaskBoundary>` (or a hand-rolled Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useTaskPromise` memoizes by\n * `deps`, so passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise\n * Suspense will catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Pass the underlying `Task` (or its\n * promise) into a Client Component and call `useTaskValue` 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 `useTaskValue` + `<TaskBoundary>`\n * require a real browser scheduler (Playwright); unit tests of `useTask` and\n * `useTaskPromise` cover the Task plumbing.\n */\nexport function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A {\n const outcome = use(useTaskPromise(task, deps))\n if (outcome.isErr()) {\n throw outcome.error\n }\n return outcome.value as A\n}\n"],"mappings":"8FA0BA,SAAgBA,EAAgB,EAA+C,EAAiC,CAC9G,IAAMC,EAAUC,EAAIC,EAAeC,EAAMC,CAAI,CAAC,EAC9C,GAAIJ,EAAQ,MAAM,EAChB,MAAMA,EAAQ,MAEhB,OAAOA,EAAQ,KACjB"}
@@ -11,11 +11,10 @@ import { Either, List } from "functype";
11
11
  * `packages/functype/src/error/typed/Validation.ts`; this alias just gives
12
12
  * the React-facing surface an ergonomic name.
13
13
  */
14
- type Validated<E, A> = Either<List<E>, A>;
14
+ export type Validated<E, A> = Either<List<E>, A>;
15
15
  /** Construct a `Valid` (Right) result. */
16
- declare function valid<A>(value: A): Validated<never, A>;
16
+ export declare function valid<A>(value: A): Validated<never, A>;
17
17
  /** Construct an `Invalid` (Left) result from an iterable of errors. */
18
- declare function invalid<E>(errors: List<E> | ReadonlyArray<E>): Validated<E, never>;
18
+ export declare function invalid<E>(errors: List<E> | ReadonlyArray<E>): Validated<E, never>;
19
19
  //#endregion
20
- export { Validated, invalid, valid };
21
20
  //# sourceMappingURL=Validated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Validated.js","names":[],"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":"qDAgBA,SAAgB,EAAS,EAA+B,CACtD,OAAO,EAAuB,CAAK,CACrC,CAGA,SAAgB,EAAW,EAA0D,CACnF,IAAM,EAAO,aAAkB,MAAQ,EAAQ,CAAM,EAAK,EAC1D,OAAO,EAAsB,CAAI,CACnC"}
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":"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"}
@@ -12,7 +12,7 @@ import { List } from "functype";
12
12
  * generic `A` may be any value type; `bind` is most useful when `A` is
13
13
  * string-shaped. For non-string fields, wire `value`/`setValue` directly.
14
14
  */
15
- declare function useValidatedField<A, E = string>(opts: {
15
+ export declare function useValidatedField<A, E = string>(opts: {
16
16
  readonly initial: A;
17
17
  readonly validate: (a: A) => Validated<E, A>;
18
18
  }): {
@@ -27,5 +27,4 @@ declare function useValidatedField<A, E = string>(opts: {
27
27
  };
28
28
  };
29
29
  //#endregion
30
- export { useValidatedField };
31
30
  //# sourceMappingURL=useValidatedField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useValidatedField.js","names":[],"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":"4GAiBA,SAAgB,EAAiC,EAU/C,CACA,GAAM,CAAC,EAAO,GAAY,EAAY,EAAK,OAAO,EAE5C,EAAa,MAAc,EAAK,SAAS,CAAK,EAAG,CAAC,EAAM,CAAK,CAAC,EAmBpE,MAAO,CAAE,QAAO,WAAU,aAAY,OAlBvB,MAEX,EAAW,KACR,GAAO,MACF,EAAK,MAAS,CACtB,EACF,CAAC,CAAU,CAY8B,EAAG,QAV9B,EAAW,QAUyB,EAAG,KAR1C,OACJ,CACL,QACA,SAAW,GAAqC,EAAS,EAAE,OAAO,KAAqB,CACzF,GACA,CAAC,CAAK,CAGkD,CAAE,CAC9D"}
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":"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"}
@@ -20,7 +20,7 @@ import { List } from "functype";
20
20
  * `handleSubmit(onValid)` returns an event handler that calls `e.preventDefault()`
21
21
  * and only invokes `onValid` when the current form value passes validation.
22
22
  */
23
- declare function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {
23
+ export declare function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {
24
24
  readonly initial: S;
25
25
  readonly validate: (s: S) => Validated<E, S>;
26
26
  }): {
@@ -33,5 +33,4 @@ declare function useValidatedForm<S extends Record<string, unknown>, E = string>
33
33
  handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void;
34
34
  };
35
35
  //#endregion
36
- export { useValidatedForm };
37
36
  //# sourceMappingURL=useValidatedForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useValidatedForm.js","names":[],"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":"4GAyBA,SAAgB,EAAgE,EAW9E,CACA,GAAM,CAAC,EAAQ,GAAa,EAAY,EAAK,OAAO,EAE9C,EAAW,GAAgC,EAAQ,IAAgB,CACvE,EAAW,IAAU,CAAE,GAAG,GAAO,GAAM,CAAM,EAAE,CACjD,EAAG,CAAC,CAAC,EAEC,EAAQ,MAAkB,EAAU,EAAK,OAAO,EAAG,CAAC,EAAK,OAAO,CAAC,EAEjE,EAAa,MAAc,EAAK,SAAS,CAAM,EAAG,CAAC,EAAM,CAAM,CAAC,EAwBtE,MAAO,CAAE,SAAQ,WAAU,aAAY,OAvBxB,MAEX,EAAW,KACR,GAAO,MACF,EAAK,MAAS,CACtB,EACF,CAAC,CAAU,CAiB+B,EAAG,QAf/B,EAAW,QAe0B,EAAG,QAAO,aAb1C,EAClB,GAA6C,GAAiB,CAC7D,EAAE,eAAe,EACjB,EAAW,SACH,IAAA,GACL,GAAM,CACL,EAAa,CAAC,CAChB,CACF,CACF,EACA,CAAC,CAAU,CAG6D,CAAE,CAC9E"}
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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"eq.js","names":[],"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, and\n * tagged ADTs. Cycles are not detected — passing cyclic structures is undefined\n * behavior. Functions compare by reference.\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\n const ka = Object.keys(a as object)\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,MAAa,EAA2B,OAAO,GASlC,GAAsB,EAAG,IAAM,CAC1C,GAAI,OAAO,GAAG,EAAG,CAAC,EAAG,MAAO,GAE5B,GADI,OAAO,GAAM,WAAY,GACzB,OAAO,GAAM,WAAY,EAAY,MAAO,GAChD,IAAM,EAAM,EAAyB,KAC/B,EAAM,EAAyB,KACrC,OAAO,IAAO,IAAA,IAAa,IAAO,CACpC,EAOa,GAA6B,EAAG,IAAM,CACjD,GAAI,OAAO,GAAG,EAAG,CAAC,EAAG,MAAO,GAG5B,GAFI,OAAO,GAAM,OAAO,GACpB,IAAM,MAAQ,IAAM,MACpB,OAAO,GAAM,SAAU,MAAO,GAElC,GAAI,MAAM,QAAQ,CAAC,EAEjB,MADI,CAAC,MAAM,QAAQ,CAAC,GAAK,EAAE,SAAW,EAAE,OAAe,GAChD,EAAE,OAAO,EAAM,IAAM,EAAa,EAAM,EAAE,EAAE,CAAC,EAEtD,GAAI,MAAM,QAAQ,CAAC,EAAG,MAAO,GAE7B,IAAM,EAAK,OAAO,KAAK,CAAW,EAC5B,EAAK,OAAO,KAAK,CAAW,EAElC,OADI,EAAG,SAAW,EAAG,QACd,EAAG,MACP,GACC,OAAO,UAAU,eAAe,KAAK,EAAG,CAAC,GACzC,EAAc,EAA8B,GAAK,EAA8B,EAAE,CACrF,CACF"}
1
+ {"version":3,"file":"eq.js","names":["referenceEq","tagEq","a","b","ta","tb","structuralEq","item","i","ka","kb","k"],"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, and\n * tagged ADTs. Cycles are not detected — passing cyclic structures is undefined\n * behavior. Functions compare by reference.\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\n const ka = Object.keys(a as object)\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,EAOaC,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,EAEtD,GAAI,MAAM,QAAQL,CAAC,EAAG,MAAO,GAE7B,IAAMM,EAAK,OAAO,KAAKP,CAAW,EAC5BQ,EAAK,OAAO,KAAKP,CAAW,EAElC,OADIM,EAAG,SAAWC,EAAG,QACdD,EAAG,MACP,GACC,OAAO,UAAU,eAAe,KAAKN,EAAGQ,CAAC,GACzCL,EAAcJ,EAA8BS,GAAKR,EAA8BQ,EAAE,CACrF,CACF"}
@@ -1,7 +1,7 @@
1
1
  import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CK6oQqWG.js";
2
2
  import { t as useEither } from "../useEither-DyPW7OaA.js";
3
3
  import { t as useList } from "../useList-B5Iox1xv.js";
4
- import { t as useOption } from "../useOption-ByA_TwP_.js";
4
+ import { t as useOption } from "../useOption-CXXNC1_S.js";
5
5
  import { t as useStableCallback } from "../useStableCallback-CXQQOhl6.js";
6
6
  import { t as useStableEffect } from "../useStableEffect-C-5NCd1T.js";
7
7
  import { t as useStableMemo } from "../useStableMemo-PYyLBWwd.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useEither.js","names":[],"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":"8HAQA,SAAgB,EACd,EAMA,CACA,GAAM,CAAC,EAAO,GAAY,MAA6B,GAAW,EAAW,IAAA,EAAyB,CAAC,EAEjG,EAAW,EAAa,GAAS,EAAS,EAAY,CAAC,CAAC,EAAG,CAAC,CAAC,EAC7D,EAAU,EAAa,GAAS,EAAS,EAAW,CAAC,CAAC,EAAG,CAAC,CAAC,EAE3D,EAAO,GAAgB,EAAqB,IAAyB,EAAM,KAAK,EAAQ,CAAO,EAAG,CAAC,CAAK,CAAC,EAE/G,OAAO,OAAe,CAAE,QAAO,WAAU,UAAS,MAAK,GAAI,CAAC,EAAO,EAAU,EAAS,CAAI,CAAC,CAC7F"}
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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useList.js","names":[],"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":"iHAQA,SAAgB,EAAW,EAQzB,CACA,GAAM,CAAC,EAAO,GAAY,MAAyB,EAAQ,GAAW,CAAC,CAAC,CAAC,EAEnE,EAAM,EAAa,GAAS,EAAU,GAAS,EAAK,IAAI,CAAC,CAAa,EAAG,CAAC,CAAC,EAC3E,EAAS,EAAa,GAAS,EAAU,GAAS,EAAK,OAAO,CAAC,CAAC,EAAG,CAAC,CAAC,EACrE,EAAW,EAAa,GAAkB,EAAU,GAAS,EAAK,SAAS,CAAK,CAAC,EAAG,CAAC,CAAC,EACtF,EAAQ,MAAkB,EAAS,EAAK,MAAS,CAAC,EAAG,CAAC,CAAC,EAEvD,EAAM,EAAgB,GAAmB,EAAM,IAAI,CAAC,EAAG,CAAC,CAAK,CAAC,EAC9D,EAAS,EAAa,GAAyB,EAAM,OAAO,CAAC,EAAG,CAAC,CAAK,CAAC,EAE7E,OAAO,OACE,CAAE,QAAO,MAAK,SAAQ,WAAU,QAAO,MAAK,QAAO,GAC1D,CAAC,EAAO,EAAK,EAAQ,EAAU,EAAO,EAAK,CAAM,CACnD,CACF"}
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":"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"}
@@ -1,2 +1,2 @@
1
- import { t as useOption } from "../useOption-ByA_TwP_.js";
1
+ import { t as useOption } from "../useOption-CXXNC1_S.js";
2
2
  export { useOption };
@@ -1 +1 @@
1
- {"version":3,"file":"useOption.js","names":[],"sources":["../../src/hooks/useOption.ts"],"sourcesContent":["\"use client\"\n/* eslint-disable functype/prefer-option -- this hook's job is to convert nullable JS values into Option, so its inputs must be nullable. */\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 */\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":"qHASA,SAAgB,EAAa,EAM3B,CACA,GAAM,CAAC,EAAO,GAAY,MAA2B,EAAU,CAAO,CAAC,EAEjE,EAAM,EAAa,GAA4B,EAAS,EAAU,CAAC,CAAC,EAAG,CAAC,CAAC,EACzE,EAAQ,MAAkB,EAAS,EAAO,KAAQ,CAAC,EAAG,CAAC,CAAC,EAExD,EAAM,EAAgB,GAAmB,EAAM,IAAI,CAAC,EAAG,CAAC,CAAK,CAAC,EAC9D,EAAO,GAAgB,EAAiB,IAAwB,EAAM,KAAK,EAAQ,CAAM,EAAG,CAAC,CAAK,CAAC,EAEzG,OAAO,OAAe,CAAE,QAAO,MAAK,QAAO,MAAK,MAAK,GAAI,CAAC,EAAO,EAAK,EAAO,EAAK,CAAI,CAAC,CACzF"}
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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStableCallback.js","names":[],"sources":["../../src/hooks/useStableCallback.ts"],"sourcesContent":["\"use client\"\n/* eslint-disable functype/prefer-option, functype/prefer-fold -- React hooks must accept idiomatic optional params and use ref-init sentinels; wrapping in Option would change the public API shape consumers expect. */\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 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":"mGAWA,SAAgB,EACd,EACA,EACA,EACG,CACH,IAAM,EAAO,EAA8B,IAAI,EACzC,EAAO,EAAO,CAAC,EAErB,GAAI,EAAK,UAAY,KACnB,EAAK,QAAU,EACf,EAAK,SAAW,MACX,CACL,IAAM,EAAQ,EAAK,QACH,EAAK,MAAM,EAAG,IAErB,EADK,IAAM,IAAM,EAAA,CACZ,EAAM,GAAI,CAAC,CAEf,IACR,EAAK,QAAU,EACf,EAAK,SAAW,EAEpB,CAEA,OAAO,EAAY,EAAU,CAAC,EAAK,OAAO,CAAC,CAC7C"}
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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStableEffect.js","names":[],"sources":["../../src/hooks/useStableEffect.ts"],"sourcesContent":["\"use client\"\n/* eslint-disable functype/prefer-option, functype/prefer-fold -- React hooks must accept idiomatic optional params and use ref-init sentinels; wrapping in Option would change the public API shape consumers expect. */\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 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":"iGAeA,SAAgB,EACd,EACA,EACA,EACM,CACN,IAAM,EAAO,EAA8B,IAAI,EACzC,EAAO,EAAO,CAAC,EAErB,GAAI,EAAK,UAAY,KACnB,EAAK,QAAU,EACf,EAAK,SAAW,MACX,CACL,IAAM,EAAQ,EAAK,QACH,EAAK,MAAM,EAAG,IAErB,EADK,IAAM,IAAM,EAAA,CACZ,EAAM,GAAI,CAAC,CAEf,IACR,EAAK,QAAU,EACf,EAAK,SAAW,EAEpB,CAEA,EAAU,EAAQ,CAAC,EAAK,OAAO,CAAC,CAClC"}
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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStableMemo.js","names":[],"sources":["../../src/hooks/useStableMemo.ts"],"sourcesContent":["\"use client\"\n/* eslint-disable functype/prefer-option, functype/prefer-fold -- React hooks must accept idiomatic optional params and use ref-init sentinels; wrapping in Option would change the public API shape consumers expect. */\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 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":"+FAYA,SAAgB,EACd,EACA,EACA,EACG,CACH,IAAM,EAAO,EAA8B,IAAI,EACzC,EAAO,EAAO,CAAC,EAErB,GAAI,EAAK,UAAY,KACnB,EAAK,QAAU,EACf,EAAK,SAAW,MACX,CACL,IAAM,EAAQ,EAAK,QACH,EAAK,MAAM,EAAG,IAErB,EADK,IAAM,IAAM,EAAA,CACZ,EAAM,GAAI,CAAC,CAEf,IACR,EAAK,QAAU,EACf,EAAK,SAAW,EAEpB,CAEA,OAAO,EAAQ,EAAS,CAAC,EAAK,OAAO,CAAC,CACxC"}
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":"+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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStableState.js","names":[],"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":"iHAcA,SAAgB,EACd,EACA,EAAY,EACwC,CACpD,GAAM,CAAC,EAAO,GAAY,EAAY,CAAO,EACvC,EAAM,EAAU,CAAK,EAa3B,MAZA,GAAI,QAAU,EAYP,CAAC,EAVU,EACf,GAA+B,CAC9B,IAAM,EAAW,OAAO,GAAS,WAAc,EAAwB,EAAI,OAAO,EAAI,EACjF,EAAG,EAAI,QAAS,CAAQ,GAC3B,EAAS,CAAQ,CAErB,EACA,CAAC,CAAE,CAGkB,CAAC,CAC1B"}
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":"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"}
@@ -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(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{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};
2
2
  //# sourceMappingURL=useTry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTry.js","names":[],"sources":["../../src/hooks/useTry.ts"],"sourcesContent":["\"use client\"\n\nimport { Try, type Try as TryT } from \"functype/try\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Try container. Defaults to Failure(new Error(\"uninitialized\")) when no initial.\n */\nexport function useTry<A>(initial?: TryT<A>): {\n readonly value: TryT<A>\n setSuccess: (a: A) => void\n setFailure: (e: Error) => void\n fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R\n} {\n const [value, setValue] = useState<TryT<A>>(() => initial ?? Try.failure<A>(new Error(\"uninitialized\")))\n\n const setSuccess = useCallback((a: A) => setValue(Try.success(a)), [])\n const setFailure = useCallback((e: Error) => setValue(Try.failure<A>(e)), [])\n\n const fold = useCallback(\n <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => value.fold(onFailure, onSuccess),\n [value],\n )\n\n return useMemo(() => ({ value, setSuccess, setFailure, fold }), [value, setSuccess, setFailure, fold])\n}\n"],"mappings":"+GAQA,SAAgB,EAAU,EAKxB,CACA,GAAM,CAAC,EAAO,GAAY,MAAwB,GAAW,EAAI,QAAe,MAAM,eAAe,CAAC,CAAC,EAEjG,EAAa,EAAa,GAAS,EAAS,EAAI,QAAQ,CAAC,CAAC,EAAG,CAAC,CAAC,EAC/D,EAAa,EAAa,GAAa,EAAS,EAAI,QAAW,CAAC,CAAC,EAAG,CAAC,CAAC,EAEtE,EAAO,GACP,EAA4B,IAA2B,EAAM,KAAK,EAAW,CAAS,EAC1F,CAAC,CAAK,CACR,EAEA,OAAO,OAAe,CAAE,QAAO,aAAY,aAAY,MAAK,GAAI,CAAC,EAAO,EAAY,EAAY,CAAI,CAAC,CACvG"}
1
+ {"version":3,"file":"useTry.js","names":["useTry","value","setValue","useState","initial","Try","setSuccess","useCallback","a","setFailure","fold","onFailure","onSuccess","useMemo"],"sources":["../../src/hooks/useTry.ts"],"sourcesContent":["\"use client\"\n\nimport { Try, type Try as TryT } from \"functype/try\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Try container. Defaults to Failure(new Error(\"uninitialized\")) when no initial.\n */\nexport function useTry<A>(initial?: TryT<A>): {\n readonly value: TryT<A>\n setSuccess: (a: A) => void\n setFailure: (e: Error) => void\n fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R\n} {\n const [value, setValue] = useState<TryT<A>>(() => initial ?? Try.failure<A>(new Error(\"uninitialized\")))\n\n const setSuccess = useCallback((a: A) => setValue(Try.success(a)), [])\n const setFailure = useCallback((e: Error) => setValue(Try.failure<A>(e)), [])\n\n const fold = useCallback(\n <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => value.fold(onFailure, onSuccess),\n [value],\n )\n\n return useMemo(() => ({ value, setSuccess, setFailure, fold }), [value, setSuccess, setFailure, fold])\n}\n"],"mappings":"+GAQA,SAAgBA,EAAU,EAKxB,CACA,GAAM,CAACC,EAAOC,GAAYC,MAAwBC,GAAWC,EAAI,QAAW,gBAAI,MAAM,eAAe,CAAC,CAAC,EAEjGC,EAAaC,EAAa,GAASL,EAASG,EAAI,QAAQG,CAAC,CAAC,EAAG,CAAC,CAAC,EAC/DC,EAAaF,EAAa,GAAaL,EAASG,EAAI,QAAW,CAAC,CAAC,EAAG,CAAC,CAAC,EAEtEK,EAAOH,GACP,EAA4B,IAA2BN,EAAM,KAAKU,EAAWC,CAAS,EAC1F,CAACX,CAAK,CACR,EAEA,OAAOY,OAAe,CAAE,QAAO,aAAY,aAAY,MAAK,GAAI,CAACZ,EAAOK,EAAYG,EAAYC,CAAI,CAAC,CACvG"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-CK6oQqWG.js";
2
2
  import { t as useEither } from "./useEither-DyPW7OaA.js";
3
3
  import { t as useList } from "./useList-B5Iox1xv.js";
4
- import { t as useOption } from "./useOption-ByA_TwP_.js";
4
+ import { t as useOption } from "./useOption-CXXNC1_S.js";
5
5
  import { t as useStableCallback } from "./useStableCallback-CXQQOhl6.js";
6
6
  import { t as useStableEffect } from "./useStableEffect-C-5NCd1T.js";
7
7
  import { t as useStableMemo } from "./useStableMemo-PYyLBWwd.js";
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-4aBdbQyD.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-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 +1 @@
1
- import{i as e,n as t,r as n,t as r}from"../match-4aBdbQyD.js";export{e as Match,n as MatchEither,t as MatchOption,r as MatchTry};
1
+ import{i as e,n as t,r as n,t as r}from"../match-CkGESkj9.js";export{e as Match,n as MatchEither,t as MatchOption,r as MatchTry};
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-CkGESkj9.js","names":["Match","handler","props","Fragment","MatchEither","MatchOption","MatchTry"],"sources":["../src/match/Match.tsx","../src/match/MatchEither.tsx","../src/match/MatchOption.tsx","../src/match/MatchTry.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Maps each `_tag` literal to a handler that receives the narrowed variant.\n *\n * TypeScript enforces exhaustiveness: omitting a case from `children` is a\n * compile error.\n */\nexport type MatchCases<U extends { _tag: string }> = {\n readonly [K in U[\"_tag\"]]: (value: Extract<U, { readonly _tag: K }>) => ReactNode\n}\n\n/**\n * Generic discriminated-union matcher for ADTs that follow functype's `_tag`\n * convention. Pass a value and a record of handlers keyed on each tag; the\n * matching handler is invoked with the narrowed variant.\n *\n * ```tsx\n * <Match value={state}>\n * {{\n * Loading: () => <Spinner />,\n * Success: ({ data }) => <Result data={data} />,\n * Failure: ({ error }) => <Err err={error} />,\n * }}\n * </Match>\n * ```\n */\nexport function Match<U extends { _tag: string }>(props: {\n readonly value: U\n readonly children: MatchCases<U>\n}): ReactElement {\n const handler = props.children[props.value._tag as U[\"_tag\"]] as (value: U) => ReactNode\n return <>{handler(props.value)}</>\n}\n","import type { Either } from \"functype/either\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Either<L, R>`.\n */\nexport function MatchEither<L, R>(props: {\n readonly value: Either<L, R>\n readonly Left: (l: L) => ReactNode\n readonly Right: (r: R) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Left, props.Right)}</>\n}\n","import type { Option } from \"functype/option\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the\n * `Some` handler and `None` to the `None` handler.\n */\nexport function MatchOption<A>(props: {\n readonly value: Option<A>\n readonly Some: (a: A) => ReactNode\n readonly None: () => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.None, props.Some)}</>\n}\n","import type { Try } from \"functype/try\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the\n * underlying `Error`; `Success` receives the value.\n */\nexport function MatchTry<A>(props: {\n readonly value: Try<A>\n readonly Success: (a: A) => ReactNode\n readonly Failure: (e: Error) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Failure, props.Success)}</>\n}\n"],"mappings":"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"}
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Pass `formatError` to any of the query entry points to override this entirely.
10
10
  */
11
- declare const formatIOError: (error: unknown) => string;
11
+ export declare const formatIOError: (error: unknown) => string;
12
12
  /**
13
13
  * An `Error` subclass carrying the typed functype error channel.
14
14
  *
@@ -25,7 +25,7 @@ declare const formatIOError: (error: unknown) => string;
25
25
  * })
26
26
  * ```
27
27
  */
28
- declare class IOQueryError<E> extends Error {
28
+ export declare class IOQueryError<E> extends Error {
29
29
  /**
30
30
  * The raw functype error channel value — discriminable via its own `_tag`.
31
31
  *
@@ -53,7 +53,6 @@ declare class IOQueryError<E> extends Error {
53
53
  constructor(error: E, message?: string, defect?: boolean);
54
54
  }
55
55
  /** Runtime guard for {@link IOQueryError}. */
56
- declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
56
+ export declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
57
57
  //#endregion
58
- export { IOQueryError, formatIOError, isIOQueryError };
59
58
  //# sourceMappingURL=IOQueryError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IOQueryError.js","names":[],"sources":["../../src/query/IOQueryError.ts"],"sourcesContent":["/**\n * Error boxing for the React Query bridge.\n *\n * `IO`'s own terminals don't fit React Query's contract: `.run()` returns\n * `Promise<Either<E, A>>` and never throws (so RQ never sees a failure), while\n * `.runOrThrow()` throws the *raw* tagged error object — `{ _tag: \"NetworkError\", ... }`\n * is not an `Error` instance, so the ubiquitous\n * `error instanceof Error ? error.message : fallback` handler silently degrades.\n *\n * `IOQueryError` boxes the typed error so both worlds work: `instanceof Error` and\n * `.message` behave as any React Query consumer expects, while `.error` preserves the\n * fully discriminable functype `E`.\n */\nimport { Try } from \"functype\"\n\n/** Structural view of a tagged functype error (e.g. any `HttpError` variant). */\ntype TaggedError = {\n readonly _tag: string\n readonly url?: unknown\n readonly status?: unknown\n readonly statusText?: unknown\n readonly message?: unknown\n}\n\nconst isTaggedError = (e: unknown): e is TaggedError =>\n typeof e === \"object\" && e !== null && \"_tag\" in e && typeof (e as { _tag: unknown })._tag === \"string\"\n\n/**\n * Derives a human-readable message from an arbitrary error channel value.\n *\n * Deliberately *structural* — this module does not import `functype/fetch`, so the\n * query bridge stays generic over any `IO<never, E, A>` rather than being HTTP-specific.\n * An `HttpStatusError` is recognized by its shape, not its type.\n *\n * Pass `formatError` to any of the query entry points to override this entirely.\n */\nexport const formatIOError = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message\n }\n\n if (isTaggedError(error)) {\n const where = typeof error.url === \"string\" ? ` — ${error.url}` : \"\"\n\n if (typeof error.status === \"number\") {\n const statusText =\n typeof error.statusText === \"string\" && error.statusText.length > 0 ? ` ${error.statusText}` : \"\"\n return `HTTP ${error.status}${statusText}${where}`\n }\n\n // A tagged error carrying its own `message` is the normal shape for a domain error\n // in the `IO` channel, and that message is what the author wrote for a human to\n // read. Falling back to the bare tag was the one case where information already\n // present got discarded — a raw `Error` gets `.message`, an untagged object gets\n // JSON, but a tagged one got neither. None of functype's own `HttpError` variants\n // carry a `message`, so the HTTP renderings above are unaffected.\n if (typeof error.message === \"string\" && error.message.length > 0) {\n return error.message\n }\n\n return `${error._tag}${where}`\n }\n\n // `String({})` is \"[object Object]\", which tells a reader nothing. Prefer a JSON\n // rendering for plain objects, falling back to String() for cycles and symbols.\n if (typeof error === \"object\" && error !== null) {\n return Try(() => JSON.stringify(error)).orElse(String(error))\n }\n\n return String(error)\n}\n\n/**\n * An `Error` subclass carrying the typed functype error channel.\n *\n * ```ts\n * const { error } = useIOQuery([\"limits\", userId], ({ signal }) => Http.get(url, { signal }))\n *\n * error instanceof Error // true\n * error.message // \"HTTP 403 Forbidden — /api/limits\"\n *\n * HttpErrors.match(error.error, {\n * NetworkError: (e) => retryBanner(e),\n * HttpStatusError: (e) => (e.status === 403 ? upgradePrompt() : genericFailure(e)),\n * DecodeError: (e) => reportSchemaDrift(e),\n * })\n * ```\n */\nexport class IOQueryError<E> extends Error {\n /**\n * The raw functype error channel value — discriminable via its own `_tag`.\n *\n * When {@link defect} is `true` this is **not** an `E`. Check `defect` before\n * matching on `_tag`.\n */\n readonly error: E\n\n /**\n * `true` when {@link error} is *not* a value from the effect's typed error channel.\n * Three things set it:\n *\n * - the effect factory threw before an `IO` was ever produced\n * - the effect produced a defect (`Exit.Die`) — a throwing `IO.sync` thunk, a\n * throwing `map` / `flatMap` / `mapError` callback, or `IO.die`\n * - the effect was interrupted, so `error` is an `InterruptedError`\n *\n * Kept as an explicit flag rather than widening `E` to `unknown`, which would force\n * every consumer to handle a case that should never occur.\n *\n * `defect: false` genuinely means `error` is an `E`. Before 1.8.0 it did not: a\n * defect reached the adapter as an ordinary `Left` and was indistinguishable from a\n * typed failure, so the documented guard didn't guard anything (#259).\n */\n readonly defect: boolean\n\n constructor(error: E, message?: string, defect = false) {\n super(message ?? formatIOError(error), { cause: error })\n this.name = \"IOQueryError\"\n this.error = error\n this.defect = defect\n }\n}\n\n/** Runtime guard for {@link IOQueryError}. */\nexport const isIOQueryError = <E = unknown>(error: unknown): error is IOQueryError<E> => error instanceof IOQueryError\n"],"mappings":"+BAwBA,MAAM,EAAiB,GACrB,OAAO,GAAM,YAAY,GAAc,SAAU,GAAK,OAAQ,EAAwB,MAAS,SAWpF,EAAiB,GAA2B,CACvD,GAAI,aAAiB,MACnB,OAAO,EAAM,QAGf,GAAI,EAAc,CAAK,EAAG,CACxB,IAAM,EAAQ,OAAO,EAAM,KAAQ,SAAW,MAAM,EAAM,MAAQ,GAElE,GAAI,OAAO,EAAM,QAAW,SAAU,CACpC,IAAM,EACJ,OAAO,EAAM,YAAe,UAAY,EAAM,WAAW,OAAS,EAAI,IAAI,EAAM,aAAe,GACjG,MAAO,QAAQ,EAAM,SAAS,IAAa,GAC7C,CAYA,OAJI,OAAO,EAAM,SAAY,UAAY,EAAM,QAAQ,OAAS,EACvD,EAAM,QAGR,GAAG,EAAM,OAAO,GACzB,CAQA,OAJI,OAAO,GAAU,UAAY,EACxB,MAAU,KAAK,UAAU,CAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAK,CAAC,EAGvD,OAAO,CAAK,CACrB,EAkBA,IAAa,EAAb,cAAqC,KAAM,CA2BzC,YAAY,EAAU,EAAkB,EAAS,GAAO,CACtD,MAAM,GAAW,EAAc,CAAK,EAAG,CAAE,MAAO,CAAM,CAAC,EACvD,KAAK,KAAO,eACZ,KAAK,MAAQ,EACb,KAAK,OAAS,CAChB,CACF,EAGA,MAAa,EAA+B,GAA6C,aAAiB"}
1
+ {"version":3,"file":"IOQueryError.js","names":["isTaggedError","formatIOError","error","where","statusText","Try","IOQueryError","message","defect","isIOQueryError"],"sources":["../../src/query/IOQueryError.ts"],"sourcesContent":["/**\n * Error boxing for the React Query bridge.\n *\n * `IO`'s own terminals don't fit React Query's contract: `.run()` returns\n * `Promise<Either<E, A>>` and never throws (so RQ never sees a failure), while\n * `.runOrThrow()` throws the *raw* tagged error object — `{ _tag: \"NetworkError\", ... }`\n * is not an `Error` instance, so the ubiquitous\n * `error instanceof Error ? error.message : fallback` handler silently degrades.\n *\n * `IOQueryError` boxes the typed error so both worlds work: `instanceof Error` and\n * `.message` behave as any React Query consumer expects, while `.error` preserves the\n * fully discriminable functype `E`.\n */\nimport { Try } from \"functype\"\n\n/** Structural view of a tagged functype error (e.g. any `HttpError` variant). */\ntype TaggedError = {\n readonly _tag: string\n readonly url?: unknown\n readonly status?: unknown\n readonly statusText?: unknown\n readonly message?: unknown\n}\n\nconst isTaggedError = (e: unknown): e is TaggedError =>\n typeof e === \"object\" && e !== null && \"_tag\" in e && typeof (e as { _tag: unknown })._tag === \"string\"\n\n/**\n * Derives a human-readable message from an arbitrary error channel value.\n *\n * Deliberately *structural* — this module does not import `functype/fetch`, so the\n * query bridge stays generic over any `IO<never, E, A>` rather than being HTTP-specific.\n * An `HttpStatusError` is recognized by its shape, not its type.\n *\n * Pass `formatError` to any of the query entry points to override this entirely.\n */\nexport const formatIOError = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message\n }\n\n if (isTaggedError(error)) {\n const where = typeof error.url === \"string\" ? ` — ${error.url}` : \"\"\n\n if (typeof error.status === \"number\") {\n const statusText =\n typeof error.statusText === \"string\" && error.statusText.length > 0 ? ` ${error.statusText}` : \"\"\n return `HTTP ${error.status}${statusText}${where}`\n }\n\n // A tagged error carrying its own `message` is the normal shape for a domain error\n // in the `IO` channel, and that message is what the author wrote for a human to\n // read. Falling back to the bare tag was the one case where information already\n // present got discarded — a raw `Error` gets `.message`, an untagged object gets\n // JSON, but a tagged one got neither. None of functype's own `HttpError` variants\n // carry a `message`, so the HTTP renderings above are unaffected.\n if (typeof error.message === \"string\" && error.message.length > 0) {\n return error.message\n }\n\n return `${error._tag}${where}`\n }\n\n // `String({})` is \"[object Object]\", which tells a reader nothing. Prefer a JSON\n // rendering for plain objects, falling back to String() for cycles and symbols.\n if (typeof error === \"object\" && error !== null) {\n return Try(() => JSON.stringify(error)).orElse(String(error))\n }\n\n return String(error)\n}\n\n/**\n * An `Error` subclass carrying the typed functype error channel.\n *\n * ```ts\n * const { error } = useIOQuery([\"limits\", userId], ({ signal }) => Http.get(url, { signal }))\n *\n * error instanceof Error // true\n * error.message // \"HTTP 403 Forbidden — /api/limits\"\n *\n * HttpErrors.match(error.error, {\n * NetworkError: (e) => retryBanner(e),\n * HttpStatusError: (e) => (e.status === 403 ? upgradePrompt() : genericFailure(e)),\n * DecodeError: (e) => reportSchemaDrift(e),\n * })\n * ```\n */\nexport class IOQueryError<E> extends Error {\n /**\n * The raw functype error channel value — discriminable via its own `_tag`.\n *\n * When {@link defect} is `true` this is **not** an `E`. Check `defect` before\n * matching on `_tag`.\n */\n readonly error: E\n\n /**\n * `true` when {@link error} is *not* a value from the effect's typed error channel.\n * Three things set it:\n *\n * - the effect factory threw before an `IO` was ever produced\n * - the effect produced a defect (`Exit.Die`) — a throwing `IO.sync` thunk, a\n * throwing `map` / `flatMap` / `mapError` callback, or `IO.die`\n * - the effect was interrupted, so `error` is an `InterruptedError`\n *\n * Kept as an explicit flag rather than widening `E` to `unknown`, which would force\n * every consumer to handle a case that should never occur.\n *\n * `defect: false` genuinely means `error` is an `E`. Before 1.8.0 it did not: a\n * defect reached the adapter as an ordinary `Left` and was indistinguishable from a\n * typed failure, so the documented guard didn't guard anything (#259).\n */\n readonly defect: boolean\n\n constructor(error: E, message?: string, defect = false) {\n super(message ?? formatIOError(error), { cause: error })\n this.name = \"IOQueryError\"\n this.error = error\n this.defect = defect\n }\n}\n\n/** Runtime guard for {@link IOQueryError}. */\nexport const isIOQueryError = <E = unknown>(error: unknown): error is IOQueryError<E> => error instanceof IOQueryError\n"],"mappings":"+BAwBA,MAAMA,EAAiB,GACrB,OAAO,GAAM,YAAY,GAAc,SAAU,GAAK,OAAQ,EAAwB,MAAS,SAWpFC,EAAiB,GAA2B,CACvD,GAAIC,aAAiB,MACnB,OAAOA,EAAM,QAGf,GAAIF,EAAcE,CAAK,EAAG,CACxB,IAAMC,EAAQ,OAAOD,EAAM,KAAQ,SAAW,MAAMA,EAAM,MAAQ,GAElE,GAAI,OAAOA,EAAM,QAAW,SAAU,CACpC,IAAME,EACJ,OAAOF,EAAM,YAAe,UAAYA,EAAM,WAAW,OAAS,EAAI,IAAIA,EAAM,aAAe,GACjG,MAAO,QAAQA,EAAM,SAASE,IAAaD,GAC7C,CAYA,OAJI,OAAOD,EAAM,SAAY,UAAYA,EAAM,QAAQ,OAAS,EACvDA,EAAM,QAGR,GAAGA,EAAM,OAAOC,GACzB,CAQA,OAJI,OAAOD,GAAU,UAAYA,EACxBG,MAAU,KAAK,UAAUH,CAAK,CAAC,CAAC,CAAC,OAAO,OAAOA,CAAK,CAAC,EAGvD,OAAOA,CAAK,CACrB,EAkBA,IAAaI,EAAb,cAAqC,KAAM,CA2BzC,YAAY,EAAU,EAAkB,EAAS,GAAO,CACtD,MAAMC,GAAWN,EAAcC,CAAK,EAAG,CAAE,MAAOA,CAAM,CAAC,EACvD,KAAK,KAAO,eACZ,KAAK,MAAQA,EACb,KAAK,OAASM,CAChB,CACF,EAGA,MAAaC,EAA+B,GAA6CP,aAAiBI"}
@@ -10,10 +10,10 @@ import { IO } from "functype/io";
10
10
  * `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,
11
11
  * `queryKey`, and `meta` are all readable inside the effect factory.
12
12
  */
13
- type IOQueryFnContext = {
13
+ export type IOQueryFnContext = {
14
14
  readonly signal: AbortSignal;
15
15
  };
16
- type IOBridgeOptions<E> = {
16
+ export type IOBridgeOptions<E> = {
17
17
  /** Override the derived `Error.message`. Defaults to a structural formatter. */
18
18
  readonly formatError?: (error: E) => string;
19
19
  };
@@ -32,7 +32,7 @@ type IOBridgeOptions<E> = {
32
32
  * })
33
33
  * ```
34
34
  */
35
- declare const ioQueryFn: <E, A, TContext extends IOQueryFnContext = IOQueryFnContext>(io: (context: TContext) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (context: TContext) => Promise<A>;
35
+ export declare const ioQueryFn: <E, A, TContext extends IOQueryFnContext = IOQueryFnContext>(io: (context: TContext) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (context: TContext) => Promise<A>;
36
36
  /**
37
37
  * Adapts a variables-taking `IO<never, E, A>` into a React Query `mutationFn`.
38
38
  *
@@ -45,7 +45,6 @@ declare const ioQueryFn: <E, A, TContext extends IOQueryFnContext = IOQueryFnCon
45
45
  * })
46
46
  * ```
47
47
  */
48
- declare const ioMutationFn: <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (variables: V) => Promise<A>;
48
+ export declare const ioMutationFn: <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (variables: V) => Promise<A>;
49
49
  //#endregion
50
- export { IOBridgeOptions, IOQueryFnContext, ioMutationFn, ioQueryFn };
51
50
  //# sourceMappingURL=ioQueryFn.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ioQueryFn.js","names":[],"sources":["../../src/query/ioQueryFn.ts"],"sourcesContent":["/* eslint-disable functype/prefer-either -- This module IS the Either→rejection bridge.\n * React Query signals failure exclusively by promise rejection: `isError`, `onError`,\n * and retry all key off a rejected queryFn. Returning an `Either` here would be\n * indistinguishable from success to React Query — the very bug (see #239) that makes\n * `.run()` unusable as a `queryFn`. The throw is the contract, and it is confined to\n * `runBoxed` so no caller ever has to write it. Scoped to the file rather than to each\n * `throw` because the rule also fires on the enclosing function: three scattered\n * suppressions would read as incidental exceptions rather than one deliberate design. */\nimport { Try } from \"functype\"\nimport { InterruptedError, type IO } from \"functype/io\"\n\nimport { IOQueryError } from \"./IOQueryError\"\n\n/**\n * Minimal structural view of React Query's `QueryFunctionContext` — the floor that\n * every context satisfies, and the default when nothing wider is inferred.\n *\n * Typed structurally on purpose, so these primitives carry **no**\n * `@tanstack/react-query` type dependency. `ioQueryFn` is generic over the context, so\n * a richer one flows through unchanged: annotate the callback parameter (e.g. with\n * `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,\n * `queryKey`, and `meta` are all readable inside the effect factory.\n */\nexport type IOQueryFnContext = {\n readonly signal: AbortSignal\n}\n\nexport type IOBridgeOptions<E> = {\n /** Override the derived `Error.message`. Defaults to a structural formatter. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * Runs an effect and returns its value, or throws a boxed {@link IOQueryError}.\n *\n * Three failure paths converge here:\n * - the effect's typed error channel (`Failure`) → boxed with `defect: false`\n * - a defect raised *inside* the effect (`Die`) → boxed with `defect: true`\n * - the factory throwing before an `IO` exists → boxed with `defect: true`\n *\n * The third matters because running an effect never throws, but `io(input)` is\n * ordinary user code that can throw while building the effect. Without this, that\n * throw would escape unboxed and `error.error` would be `undefined` despite the\n * declared type.\n *\n * The second is why this uses `runExit()` rather than `run()`. `run()` returns\n * `Either<E, A>`, which has nowhere to put a defect — a throwing `mapError` handler or\n * `IO.sync` thunk arrived as `Left` and was indistinguishable from a genuine `E`, so\n * `defect` read `false` while `.error` held something that was not an `E` at all\n * (#259). `Exit` keeps the two apart, so the flag can be accurate.\n */\nconst runBoxed = async <E, A>(effect: () => IO<never, E, A>, options?: IOBridgeOptions<E>): Promise<A> => {\n const exit = await Try(() => effect()).fold(\n (thrown) => {\n throw new IOQueryError(thrown as E, undefined, true)\n },\n (io) => io.runExit(),\n )\n\n if (exit.isFailure()) {\n const { error } = exit.toValue() as { error: E }\n throw new IOQueryError(error, options?.formatError?.(error))\n }\n\n if (exit.isDie()) {\n throw new IOQueryError((exit.toValue() as { defect: unknown }).defect as E, undefined, true)\n }\n\n if (exit.isInterrupted()) {\n // An `InterruptedError` is no more an `E` than a defect is, so it carries the same\n // flag. `run()` put it in the `Left` with `defect: false`, which had the same problem\n // the rest of this fix is about.\n throw new IOQueryError(new InterruptedError() as E, undefined, true)\n }\n\n return exit.orThrow()\n}\n\n/**\n * Adapts an `IO<never, E, A>` into a React Query `queryFn`.\n *\n * `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that\n * carries the typed error on `.error`. Wire cancellation by closing over the supplied\n * `signal`:\n *\n * ```ts\n * useQuery({\n * queryKey: [\"connector-limits\", userId],\n * queryFn: ioQueryFn(({ signal }) => Http.get<Limits>(url, { headers, signal })),\n * enabled: !!userId,\n * })\n * ```\n */\nexport const ioQueryFn =\n <E, A, TContext extends IOQueryFnContext = IOQueryFnContext>(\n io: (context: TContext) => IO<never, E, A>,\n options?: IOBridgeOptions<E>,\n ) =>\n (context: TContext): Promise<A> =>\n runBoxed(() => io(context), options)\n\n/**\n * Adapts a variables-taking `IO<never, E, A>` into a React Query `mutationFn`.\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n *\n * ```ts\n * useMutation({\n * mutationFn: ioMutationFn((body: CreateTokenInput) => Http.post<Token>(url, { body })),\n * })\n * ```\n */\nexport const ioMutationFn =\n <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) =>\n (variables: V): Promise<A> =>\n runBoxed(() => io(variables), options)\n"],"mappings":"+HAmDA,MAAM,EAAW,MAAa,EAA+B,IAA6C,CACxG,IAAM,EAAO,MAAM,MAAU,EAAO,CAAC,CAAC,CAAC,KACpC,GAAW,CACV,MAAM,IAAI,EAAa,EAAa,IAAA,GAAW,EAAI,CACrD,EACC,GAAO,EAAG,QAAQ,CACrB,EAEA,GAAI,EAAK,UAAU,EAAG,CACpB,GAAM,CAAE,SAAU,EAAK,QAAQ,EAC/B,MAAM,IAAI,EAAa,EAAO,GAAS,cAAc,CAAK,CAAC,CAC7D,CAEA,GAAI,EAAK,MAAM,EACb,MAAM,IAAI,EAAc,EAAK,QAAQ,CAAC,CAAyB,OAAa,IAAA,GAAW,EAAI,EAG7F,GAAI,EAAK,cAAc,EAIrB,MAAM,IAAI,EAAa,IAAI,EAAyB,IAAA,GAAW,EAAI,EAGrE,OAAO,EAAK,QAAQ,CACtB,EAiBa,GAET,EACA,IAED,GACC,MAAe,EAAG,CAAO,EAAG,CAAO,EAc1B,GACM,EAAuC,IACvD,GACC,MAAe,EAAG,CAAS,EAAG,CAAO"}
1
+ {"version":3,"file":"ioQueryFn.js","names":["runBoxed","exit","Try","effect","IOQueryError","thrown","io","error","options","InterruptedError","ioQueryFn","context","ioMutationFn","variables"],"sources":["../../src/query/ioQueryFn.ts"],"sourcesContent":["import { Try } from \"functype\"\nimport { InterruptedError, type IO } from \"functype/io\"\n\nimport { IOQueryError } from \"./IOQueryError\"\n\n/**\n * Minimal structural view of React Query's `QueryFunctionContext` — the floor that\n * every context satisfies, and the default when nothing wider is inferred.\n *\n * Typed structurally on purpose, so these primitives carry **no**\n * `@tanstack/react-query` type dependency. `ioQueryFn` is generic over the context, so\n * a richer one flows through unchanged: annotate the callback parameter (e.g. with\n * `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,\n * `queryKey`, and `meta` are all readable inside the effect factory.\n */\nexport type IOQueryFnContext = {\n readonly signal: AbortSignal\n}\n\nexport type IOBridgeOptions<E> = {\n /** Override the derived `Error.message`. Defaults to a structural formatter. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * Runs an effect and returns its value, or throws a boxed {@link IOQueryError}.\n *\n * Three failure paths converge here:\n * - the effect's typed error channel (`Failure`) → boxed with `defect: false`\n * - a defect raised *inside* the effect (`Die`) → boxed with `defect: true`\n * - the factory throwing before an `IO` exists → boxed with `defect: true`\n *\n * The third matters because running an effect never throws, but `io(input)` is\n * ordinary user code that can throw while building the effect. Without this, that\n * throw would escape unboxed and `error.error` would be `undefined` despite the\n * declared type.\n *\n * The second is why this uses `runExit()` rather than `run()`. `run()` returns\n * `Either<E, A>`, which has nowhere to put a defect — a throwing `mapError` handler or\n * `IO.sync` thunk arrived as `Left` and was indistinguishable from a genuine `E`, so\n * `defect` read `false` while `.error` held something that was not an `E` at all\n * (#259). `Exit` keeps the two apart, so the flag can be accurate.\n *\n * The throws are confined to this function so no caller ever writes one.\n *\n * @interop React Query signals failure only by promise rejection; an Either return reads as success (#239).\n */\nconst runBoxed = async <E, A>(effect: () => IO<never, E, A>, options?: IOBridgeOptions<E>): Promise<A> => {\n const exit = await Try(() => effect()).fold(\n (thrown) => {\n throw new IOQueryError(thrown as E, undefined, true)\n },\n (io) => io.runExit(),\n )\n\n if (exit.isFailure()) {\n const { error } = exit.toValue() as { error: E }\n throw new IOQueryError(error, options?.formatError?.(error))\n }\n\n if (exit.isDie()) {\n throw new IOQueryError((exit.toValue() as { defect: unknown }).defect as E, undefined, true)\n }\n\n if (exit.isInterrupted()) {\n // An `InterruptedError` is no more an `E` than a defect is, so it carries the same\n // flag. `run()` put it in the `Left` with `defect: false`, which had the same problem\n // the rest of this fix is about.\n throw new IOQueryError(new InterruptedError() as E, undefined, true)\n }\n\n return exit.orThrow()\n}\n\n/**\n * Adapts an `IO<never, E, A>` into a React Query `queryFn`.\n *\n * `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that\n * carries the typed error on `.error`. Wire cancellation by closing over the supplied\n * `signal`:\n *\n * ```ts\n * useQuery({\n * queryKey: [\"connector-limits\", userId],\n * queryFn: ioQueryFn(({ signal }) => Http.get<Limits>(url, { headers, signal })),\n * enabled: !!userId,\n * })\n * ```\n */\nexport const ioQueryFn =\n <E, A, TContext extends IOQueryFnContext = IOQueryFnContext>(\n io: (context: TContext) => IO<never, E, A>,\n options?: IOBridgeOptions<E>,\n ) =>\n (context: TContext): Promise<A> =>\n runBoxed(() => io(context), options)\n\n/**\n * Adapts a variables-taking `IO<never, E, A>` into a React Query `mutationFn`.\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n *\n * ```ts\n * useMutation({\n * mutationFn: ioMutationFn((body: CreateTokenInput) => Http.post<Token>(url, { body })),\n * })\n * ```\n */\nexport const ioMutationFn =\n <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) =>\n (variables: V): Promise<A> =>\n runBoxed(() => io(variables), options)\n"],"mappings":"+HA+CA,MAAMA,EAAW,MAAa,EAA+B,IAA6C,CACxG,IAAMC,EAAO,MAAMC,MAAUC,EAAO,CAAC,CAAC,CAAC,KACpC,GAAW,CACV,MAAM,IAAIC,EAAaC,EAAa,IAAA,GAAW,EAAI,CACrD,EACC,GAAOC,EAAG,QAAQ,CACrB,EAEA,GAAIL,EAAK,UAAU,EAAG,CACpB,GAAM,CAAE,SAAUA,EAAK,QAAQ,EAC/B,MAAM,IAAIG,EAAaG,EAAOC,GAAS,cAAcD,CAAK,CAAC,CAC7D,CAEA,GAAIN,EAAK,MAAM,EACb,MAAM,IAAIG,EAAcH,EAAK,QAAQ,CAAC,CAAyB,OAAa,IAAA,GAAW,EAAI,EAG7F,GAAIA,EAAK,cAAc,EAIrB,MAAM,IAAIG,EAAa,IAAIK,EAAyB,IAAA,GAAW,EAAI,EAGrE,OAAOR,EAAK,QAAQ,CACtB,EAiBaS,GAET,EACA,IAED,GACCV,MAAeM,EAAGK,CAAO,EAAGH,CAAO,EAc1BI,GACM,EAAuC,IACvD,GACCZ,MAAeM,EAAGO,CAAS,EAAGL,CAAO"}
@@ -6,7 +6,7 @@ import { t as TaskState } from "../TaskState-DWxGWqXf.js";
6
6
  * projection carries no `@tanstack/react-query` type dependency; `UseQueryResult`
7
7
  * satisfies it.
8
8
  */
9
- type QueryResultView<E, A> = {
9
+ export type QueryResultView<E, A> = {
10
10
  readonly status: "pending";
11
11
  readonly fetchStatus: "fetching" | "paused" | "idle";
12
12
  } | {
@@ -17,7 +17,7 @@ type QueryResultView<E, A> = {
17
17
  readonly error: E;
18
18
  };
19
19
  /** Structural view of a React Query mutation result. */
20
- type MutationResultView<E, A> = {
20
+ export type MutationResultView<E, A> = {
21
21
  readonly status: "idle";
22
22
  } | {
23
23
  readonly status: "pending";
@@ -67,12 +67,11 @@ type MutationResultView<E, A> = {
67
67
  * arise here, but it is worth knowing that `.error` is `E` by construction rather
68
68
  * than by proof.
69
69
  */
70
- declare const toQueryState: <E, A>(result: QueryResultView<E, A>) => TaskState<E, A>;
70
+ export declare const toQueryState: <E, A>(result: QueryResultView<E, A>) => TaskState<E, A>;
71
71
  /**
72
72
  * Projects a React Query mutation result onto `TaskState`. React Query models an
73
73
  * unfired mutation as `status: "idle"`, which maps directly onto `Idle`.
74
74
  */
75
- declare const toMutationState: <E, A>(result: MutationResultView<E, A>) => TaskState<E, A>;
75
+ export declare const toMutationState: <E, A>(result: MutationResultView<E, A>) => TaskState<E, A>;
76
76
  //#endregion
77
- export { MutationResultView, QueryResultView, toMutationState, toQueryState };
78
77
  //# sourceMappingURL=queryState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryState.js","names":[],"sources":["../../src/query/queryState.ts"],"sourcesContent":["import type { TaskState } from \"../async/TaskState\"\n\n/**\n * Structural view of a React Query result — the discriminated shape this module\n * actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the\n * projection carries no `@tanstack/react-query` type dependency; `UseQueryResult`\n * satisfies it.\n */\nexport type QueryResultView<E, A> =\n | { readonly status: \"pending\"; readonly fetchStatus: \"fetching\" | \"paused\" | \"idle\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/** Structural view of a React Query mutation result. */\nexport type MutationResultView<E, A> =\n | { readonly status: \"idle\" }\n | { readonly status: \"pending\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/**\n * Projects a React Query result onto the package's `TaskState` ADT, so a query can\n * be folded or matched exhaustively instead of read through `data && !error && !isLoading`.\n *\n * This is the whole point of `functype-react`: omitting a case becomes a compile\n * error, and the success branch hands you a defined `A` rather than `A | undefined`\n * that needs a `!`.\n *\n * ```tsx\n * const query = useIOQuery([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={toQueryState(query)}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * A disabled query (`enabled: false`, never fetched) projects to `Idle`; an\n * in-flight or paused one to `Pending`. Reuses the same `TaskState` that\n * `functype-react/async`'s `useTask` returns, so both async surfaces match alike.\n *\n * **Stale data on a failed refetch.** React Query keeps the last successful `data`\n * while setting `status: \"error\"` when a *background refetch* fails. `TaskState` has\n * no variant for \"loaded, but the latest fetch failed\", so that squashes to `Failure`\n * and the still-held data is not surfaced through the ADT — a transient background\n * failure will flip a loaded view to an error branch. This is the deliberate default:\n * it never silently hides a failure. If you would rather keep rendering stale data,\n * read `query.data` directly alongside the projection, or branch on\n * `query.isRefetchError` before projecting.\n *\n * **Interruption.** `IO.run()` maps an interrupted effect to `Left(InterruptedError)`,\n * which is not an `E`. Nothing in this subpath interrupts effects, so it will not\n * arise here, but it is worth knowing that `.error` is `E` by construction rather\n * than by proof.\n */\nexport const toQueryState = <E, A>(result: QueryResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return result.fetchStatus === \"idle\" ? { _tag: \"Idle\" } : { _tag: \"Pending\" }\n }\n}\n\n/**\n * Projects a React Query mutation result onto `TaskState`. React Query models an\n * unfired mutation as `status: \"idle\"`, which maps directly onto `Idle`.\n */\nexport const toMutationState = <E, A>(result: MutationResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return { _tag: \"Pending\" }\n case \"idle\":\n return { _tag: \"Idle\" }\n }\n}\n"],"mappings":"AA2DA,MAAa,EAAsB,GAAmD,CACpF,OAAQ,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAO,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAO,EAAO,KAAM,EAChD,IAAK,UACH,OAAO,EAAO,cAAgB,OAAS,CAAE,KAAM,MAAO,EAAI,CAAE,KAAM,SAAU,CAChF,CACF,EAMa,EAAyB,GAAsD,CAC1F,OAAQ,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAO,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAO,EAAO,KAAM,EAChD,IAAK,UACH,MAAO,CAAE,KAAM,SAAU,EAC3B,IAAK,OACH,MAAO,CAAE,KAAM,MAAO,CAC1B,CACF"}
1
+ {"version":3,"file":"queryState.js","names":["toQueryState","result","toMutationState"],"sources":["../../src/query/queryState.ts"],"sourcesContent":["import type { TaskState } from \"../async/TaskState\"\n\n/**\n * Structural view of a React Query result — the discriminated shape this module\n * actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the\n * projection carries no `@tanstack/react-query` type dependency; `UseQueryResult`\n * satisfies it.\n */\nexport type QueryResultView<E, A> =\n | { readonly status: \"pending\"; readonly fetchStatus: \"fetching\" | \"paused\" | \"idle\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/** Structural view of a React Query mutation result. */\nexport type MutationResultView<E, A> =\n | { readonly status: \"idle\" }\n | { readonly status: \"pending\" }\n | { readonly status: \"success\"; readonly data: A }\n | { readonly status: \"error\"; readonly error: E }\n\n/**\n * Projects a React Query result onto the package's `TaskState` ADT, so a query can\n * be folded or matched exhaustively instead of read through `data && !error && !isLoading`.\n *\n * This is the whole point of `functype-react`: omitting a case becomes a compile\n * error, and the success branch hands you a defined `A` rather than `A | undefined`\n * that needs a `!`.\n *\n * ```tsx\n * const query = useIOQuery([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={toQueryState(query)}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * A disabled query (`enabled: false`, never fetched) projects to `Idle`; an\n * in-flight or paused one to `Pending`. Reuses the same `TaskState` that\n * `functype-react/async`'s `useTask` returns, so both async surfaces match alike.\n *\n * **Stale data on a failed refetch.** React Query keeps the last successful `data`\n * while setting `status: \"error\"` when a *background refetch* fails. `TaskState` has\n * no variant for \"loaded, but the latest fetch failed\", so that squashes to `Failure`\n * and the still-held data is not surfaced through the ADT — a transient background\n * failure will flip a loaded view to an error branch. This is the deliberate default:\n * it never silently hides a failure. If you would rather keep rendering stale data,\n * read `query.data` directly alongside the projection, or branch on\n * `query.isRefetchError` before projecting.\n *\n * **Interruption.** `IO.run()` maps an interrupted effect to `Left(InterruptedError)`,\n * which is not an `E`. Nothing in this subpath interrupts effects, so it will not\n * arise here, but it is worth knowing that `.error` is `E` by construction rather\n * than by proof.\n */\nexport const toQueryState = <E, A>(result: QueryResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return result.fetchStatus === \"idle\" ? { _tag: \"Idle\" } : { _tag: \"Pending\" }\n }\n}\n\n/**\n * Projects a React Query mutation result onto `TaskState`. React Query models an\n * unfired mutation as `status: \"idle\"`, which maps directly onto `Idle`.\n */\nexport const toMutationState = <E, A>(result: MutationResultView<E, A>): TaskState<E, A> => {\n switch (result.status) {\n case \"success\":\n return { _tag: \"Success\", value: result.data }\n case \"error\":\n return { _tag: \"Failure\", error: result.error }\n case \"pending\":\n return { _tag: \"Pending\" }\n case \"idle\":\n return { _tag: \"Idle\" }\n }\n}\n"],"mappings":"AA2DA,MAAaA,EAAsB,GAAmD,CACpF,OAAQC,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EAChD,IAAK,UACH,OAAOA,EAAO,cAAgB,OAAS,CAAE,KAAM,MAAO,EAAI,CAAE,KAAM,SAAU,CAChF,CACF,EAMaC,EAAyB,GAAsD,CAC1F,OAAQD,EAAO,OAAf,CACE,IAAK,UACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,IAAK,EAC/C,IAAK,QACH,MAAO,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EAChD,IAAK,UACH,MAAO,CAAE,KAAM,SAAU,EAC3B,IAAK,OACH,MAAO,CAAE,KAAM,MAAO,CAC1B,CACF"}
@@ -2,7 +2,7 @@ import { IOQueryError } from "./IOQueryError.js";
2
2
  import { IO } from "functype/io";
3
3
  import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
4
4
  //#region src/query/useIOMutation.d.ts
5
- type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
5
+ export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
6
6
  /** Override the derived `Error.message` on failure. */
7
7
  readonly formatError?: (error: E) => string;
8
8
  };
@@ -21,7 +21,6 @@ type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQuer
21
21
  * React Query does not supply an `AbortSignal` to mutations, so the callback receives
22
22
  * only the mutation variables.
23
23
  */
24
- declare function useIOMutation<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseMutationResult<A, IOQueryError<E>, V, TContext>;
24
+ export declare function useIOMutation<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseMutationResult<A, IOQueryError<E>, V, TContext>;
25
25
  //#endregion
26
- export { UseIOMutationOptions, useIOMutation };
27
26
  //# sourceMappingURL=useIOMutation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIOMutation.js","names":[],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"+GAgCA,SAAgB,EACd,EACA,EACoD,CACpD,GAAM,CAAE,cAAa,GAAG,GAAoB,GAAW,CAAC,EAExD,OAAO,EAA6C,CAClD,GAAG,EACH,WAAY,EAAsB,EAAI,CAAE,aAAY,CAAC,CACvD,CAAC,CACH"}
1
+ {"version":3,"file":"useIOMutation.js","names":["useIOMutation","mutationOptions","options","useMutation","ioMutationFn","io"],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"+GAgCA,SAAgBA,EACd,EACA,EACoD,CACpD,GAAM,CAAE,cAAa,GAAGC,GAAoBC,GAAW,CAAC,EAExD,OAAOC,EAA6C,CAClD,GAAGF,EACH,WAAYG,EAAsBC,EAAI,CAAE,aAAY,CAAC,CACvD,CAAC,CACH"}
@@ -9,7 +9,7 @@ import { UseMutationResult } from "@tanstack/react-query";
9
9
  * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried
10
10
  * through with React Query's own signatures.
11
11
  */
12
- type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> & Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, "mutate" | "mutateAsync" | "reset"> & {
12
+ export type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> & Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, "mutate" | "mutateAsync" | "reset"> & {
13
13
  readonly isIdle: boolean;
14
14
  readonly isPending: boolean;
15
15
  readonly isSuccess: boolean;
@@ -34,7 +34,6 @@ type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A>
34
34
  * </Match>
35
35
  * ```
36
36
  */
37
- declare function useIOMutationState<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseIOMutationStateResult<A, E, V, TContext>;
37
+ export declare function useIOMutationState<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseIOMutationStateResult<A, E, V, TContext>;
38
38
  //#endregion
39
- export { UseIOMutationStateResult, useIOMutationState };
40
39
  //# sourceMappingURL=useIOMutationState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIOMutationState.js","names":[],"sources":["../../src/query/useIOMutationState.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `TaskState` plus the flags and the trigger functions. Unlike a query, a mutation is\n * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried\n * through with React Query's own signatures.\n */\nexport type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> &\n Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, \"mutate\" | \"mutateAsync\" | \"reset\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOMutation` projected onto the `TaskState` ADT, so a mutation's lifecycle matches\n * exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.\n *\n * ```tsx\n * const create = useIOMutationState((body: CreateTokenInput) => Http.post<Token>(url, { body }))\n *\n * <button onClick={() => create.mutate({ name: \"ci\" })} disabled={create.isPending}>create</button>\n *\n * <Match value={create}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <TokenRow token={value} />,\n * }}\n * </Match>\n * ```\n */\nexport function useIOMutationState<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseIOMutationStateResult<A, E, V, TContext> {\n const mutation = useIOMutation(io, options)\n const state = toMutationState(mutation)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n reset: mutation.reset,\n }\n}\n"],"mappings":"kHA2CA,SAAgB,EACd,EACA,EAC6C,CAC7C,IAAM,EAAW,EAAc,EAAI,CAAO,EACpC,EAAQ,EAAgB,CAAQ,EAEtC,MAAO,CACL,GAAG,EACH,OAAQ,EAAM,OAAS,OACvB,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,OAAQ,EAAS,OACjB,YAAa,EAAS,YACtB,MAAO,EAAS,KAClB,CACF"}
1
+ {"version":3,"file":"useIOMutationState.js","names":["useIOMutationState","mutation","useIOMutation","io","options","state","toMutationState"],"sources":["../../src/query/useIOMutationState.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `TaskState` plus the flags and the trigger functions. Unlike a query, a mutation is\n * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried\n * through with React Query's own signatures.\n */\nexport type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> &\n Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, \"mutate\" | \"mutateAsync\" | \"reset\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOMutation` projected onto the `TaskState` ADT, so a mutation's lifecycle matches\n * exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.\n *\n * ```tsx\n * const create = useIOMutationState((body: CreateTokenInput) => Http.post<Token>(url, { body }))\n *\n * <button onClick={() => create.mutate({ name: \"ci\" })} disabled={create.isPending}>create</button>\n *\n * <Match value={create}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <TokenRow token={value} />,\n * }}\n * </Match>\n * ```\n */\nexport function useIOMutationState<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseIOMutationStateResult<A, E, V, TContext> {\n const mutation = useIOMutation(io, options)\n const state = toMutationState(mutation)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n reset: mutation.reset,\n }\n}\n"],"mappings":"kHA2CA,SAAgBA,EACd,EACA,EAC6C,CAC7C,IAAMC,EAAWC,EAAcC,EAAIC,CAAO,EACpCC,EAAQC,EAAgBL,CAAQ,EAEtC,MAAO,CACL,GAAGI,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,OAAQJ,EAAS,OACjB,YAAaA,EAAS,YACtB,MAAOA,EAAS,KAClB,CACF"}
@@ -2,7 +2,7 @@ import { IOQueryError } from "./IOQueryError.js";
2
2
  import { IO } from "functype/io";
3
3
  import { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
4
4
  //#region src/query/useIOQuery.d.ts
5
- type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>, "queryKey" | "queryFn"> & {
5
+ export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>, "queryKey" | "queryFn"> & {
6
6
  /** Override the derived `Error.message` on failure. */
7
7
  readonly formatError?: (error: E) => string;
8
8
  };
@@ -33,7 +33,6 @@ type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryO
33
33
  * through untouched. For full control over the query object — or for
34
34
  * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.
35
35
  */
36
- declare function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseQueryResult<TData, IOQueryError<E>>;
36
+ export declare function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseQueryResult<TData, IOQueryError<E>>;
37
37
  //#endregion
38
- export { UseIOQueryOptions, useIOQuery };
39
38
  //# sourceMappingURL=useIOQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIOQuery.js","names":[],"sources":["../../src/query/useIOQuery.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from \"@tanstack/react-query\"\nimport { useQuery } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioQueryFn } from \"./ioQueryFn\"\n\nexport type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<\n UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>,\n \"queryKey\" | \"queryFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel\n * through to React Query's `error`.\n *\n * The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and\n * `error.message` behave normally while `error.error` stays fully discriminable:\n *\n * ```ts\n * const { data, error } = useIOQuery(\n * [\"connector-limits\", userId],\n * ({ signal }) => Http.get<Limits>(url, { headers, signal }),\n * { enabled: !!userId },\n * )\n *\n * if (error) {\n * HttpErrors.match(error.error, {\n * NetworkError: () => <Offline />,\n * HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),\n * DecodeError: () => <SchemaDrift />,\n * })\n * }\n * ```\n *\n * Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes\n * through untouched. For full control over the query object — or for\n * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.\n */\nexport function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseQueryResult<TData, IOQueryError<E>> {\n const { formatError, ...queryOptions } = options ?? {}\n\n return useQuery<A, IOQueryError<E>, TData, TQueryKey>({\n ...queryOptions,\n queryKey,\n queryFn: ioQueryFn<E, A, QueryFunctionContext<TQueryKey>>(io, { formatError }),\n })\n}\n"],"mappings":"yGA4CA,SAAgB,EACd,EACA,EACA,EACwC,CACxC,GAAM,CAAE,cAAa,GAAG,GAAiB,GAAW,CAAC,EAErD,OAAO,EAA+C,CACpD,GAAG,EACH,WACA,QAAS,EAAiD,EAAI,CAAE,aAAY,CAAC,CAC/E,CAAC,CACH"}
1
+ {"version":3,"file":"useIOQuery.js","names":["useIOQuery","queryOptions","options","useQuery","ioQueryFn","io"],"sources":["../../src/query/useIOQuery.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from \"@tanstack/react-query\"\nimport { useQuery } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioQueryFn } from \"./ioQueryFn\"\n\nexport type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<\n UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>,\n \"queryKey\" | \"queryFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel\n * through to React Query's `error`.\n *\n * The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and\n * `error.message` behave normally while `error.error` stays fully discriminable:\n *\n * ```ts\n * const { data, error } = useIOQuery(\n * [\"connector-limits\", userId],\n * ({ signal }) => Http.get<Limits>(url, { headers, signal }),\n * { enabled: !!userId },\n * )\n *\n * if (error) {\n * HttpErrors.match(error.error, {\n * NetworkError: () => <Offline />,\n * HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),\n * DecodeError: () => <SchemaDrift />,\n * })\n * }\n * ```\n *\n * Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes\n * through untouched. For full control over the query object — or for\n * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.\n */\nexport function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseQueryResult<TData, IOQueryError<E>> {\n const { formatError, ...queryOptions } = options ?? {}\n\n return useQuery<A, IOQueryError<E>, TData, TQueryKey>({\n ...queryOptions,\n queryKey,\n queryFn: ioQueryFn<E, A, QueryFunctionContext<TQueryKey>>(io, { formatError }),\n })\n}\n"],"mappings":"yGA4CA,SAAgBA,EACd,EACA,EACA,EACwC,CACxC,GAAM,CAAE,cAAa,GAAGC,GAAiBC,GAAW,CAAC,EAErD,OAAOC,EAA+C,CACpD,GAAGF,EACH,WACA,QAASG,EAAiDC,EAAI,CAAE,aAAY,CAAC,CAC/E,CAAC,CACH"}
@@ -10,7 +10,7 @@ import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-
10
10
  *
11
11
  * `refetch` keeps React Query's own signature rather than a lossy re-declaration.
12
12
  */
13
- type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<UseQueryResult<A, IOQueryError<E>>, "refetch"> & {
13
+ export type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<UseQueryResult<A, IOQueryError<E>>, "refetch"> & {
14
14
  readonly isIdle: boolean;
15
15
  readonly isPending: boolean;
16
16
  readonly isSuccess: boolean;
@@ -39,7 +39,6 @@ type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<UseQuery
39
39
  * (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with
40
40
  * {@link toQueryState} instead.
41
41
  */
42
- declare function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseIOQueryStateResult<TData, E>;
42
+ export declare function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseIOQueryStateResult<TData, E>;
43
43
  //#endregion
44
- export { UseIOQueryStateResult, useIOQueryState };
45
44
  //# sourceMappingURL=useIOQueryState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIOQueryState.js","names":[],"sources":["../../src/query/useIOQueryState.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `TaskState` plus the convenience flags and refetch trigger, mirroring\n * `UseTaskResult` from `functype-react/async` so both async surfaces read alike.\n *\n * `refetch` keeps React Query's own signature rather than a lossy re-declaration.\n */\nexport type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> &\n Pick<UseQueryResult<A, IOQueryError<E>>, \"refetch\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOQuery` projected straight onto the `TaskState` ADT — the flag-soup-free path\n * in one call.\n *\n * ```tsx\n * const user = useIOQueryState([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={user}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * Reads only `status` / `fetchStatus` / `data` / `error` / `refetch` off the query, so\n * React Query's tracked-properties optimization still applies — the component is not\n * subscribed to fields it never renders. When you need the rest of the result\n * (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with\n * {@link toQueryState} instead.\n */\nexport function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseIOQueryStateResult<TData, E> {\n const query = useIOQuery(queryKey, io, options)\n const state = toQueryState(query)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n refetch: query.refetch,\n }\n}\n"],"mappings":"yGAgDA,SAAgB,EACd,EACA,EACA,EACiC,CACjC,IAAM,EAAQ,EAAW,EAAU,EAAI,CAAO,EACxC,EAAQ,EAAa,CAAK,EAEhC,MAAO,CACL,GAAG,EACH,OAAQ,EAAM,OAAS,OACvB,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,UAAW,EAAM,OAAS,UAC1B,QAAS,EAAM,OACjB,CACF"}
1
+ {"version":3,"file":"useIOQueryState.js","names":["useIOQueryState","query","useIOQuery","queryKey","io","options","state","toQueryState"],"sources":["../../src/query/useIOQueryState.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { TaskState } from \"../async/TaskState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `TaskState` plus the convenience flags and refetch trigger, mirroring\n * `UseTaskResult` from `functype-react/async` so both async surfaces read alike.\n *\n * `refetch` keeps React Query's own signature rather than a lossy re-declaration.\n */\nexport type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> &\n Pick<UseQueryResult<A, IOQueryError<E>>, \"refetch\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOQuery` projected straight onto the `TaskState` ADT — the flag-soup-free path\n * in one call.\n *\n * ```tsx\n * const user = useIOQueryState([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={user}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * Reads only `status` / `fetchStatus` / `data` / `error` / `refetch` off the query, so\n * React Query's tracked-properties optimization still applies — the component is not\n * subscribed to fields it never renders. When you need the rest of the result\n * (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with\n * {@link toQueryState} instead.\n */\nexport function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseIOQueryStateResult<TData, E> {\n const query = useIOQuery(queryKey, io, options)\n const state = toQueryState(query)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n refetch: query.refetch,\n }\n}\n"],"mappings":"yGAgDA,SAAgBA,EACd,EACA,EACA,EACiC,CACjC,IAAMC,EAAQC,EAAWC,EAAUC,EAAIC,CAAO,EACxCC,EAAQC,EAAaN,CAAK,EAEhC,MAAO,CACL,GAAGK,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,QAASL,EAAM,OACjB,CACF"}
@@ -2,6 +2,8 @@ import { Option } from "functype/option";
2
2
  //#region src/hooks/useOption.d.ts
3
3
  /**
4
4
  * Stateful Option container. `set(null | undefined)` clears to None.
5
+ *
6
+ * @interop This hook converts nullable JS values into Option, so `initial` and `set` must accept them.
5
7
  */
6
8
  declare function useOption<A>(initial?: A): {
7
9
  readonly value: Option<A>;
@@ -12,4 +14,4 @@ declare function useOption<A>(initial?: A): {
12
14
  };
13
15
  //#endregion
14
16
  export { useOption as t };
15
- //# sourceMappingURL=useOption-ByA_TwP_.d.ts.map
17
+ //# sourceMappingURL=useOption-CXXNC1_S.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype-react",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "React bindings for functype — ADT-aware hooks and exhaustive pattern matching components",
5
5
  "keywords": [
6
6
  "functype",
@@ -40,20 +40,20 @@
40
40
  }
41
41
  },
42
42
  "devDependencies": {
43
- "@tanstack/react-query": "^5.101.4",
44
- "@testing-library/dom": "^10.4.1",
45
- "@testing-library/jest-dom": "^6.10.0",
46
- "@testing-library/react": "^16.3.2",
47
- "@types/node": "^24.13.3",
48
- "@types/react": "^19.2.18",
49
- "@types/react-dom": "^19.2.4",
50
- "fast-check": "^4.9.0",
51
- "jsdom": "^26.1.0",
52
- "react": "^19.2.8",
53
- "react-dom": "^19.2.8",
54
- "ts-builds": "^3.4.1",
55
- "tsdown": "^0.22.14",
56
- "functype": "^1.9.0"
43
+ "@tanstack/react-query": "^5.104.0",
44
+ "@testing-library/dom": "^10.4.2",
45
+ "@testing-library/jest-dom": "^7.0.1",
46
+ "@testing-library/react": "^16.3.3",
47
+ "@types/node": "^24.19.0",
48
+ "@types/react": "^19.3.0",
49
+ "@types/react-dom": "^19.3.0",
50
+ "fast-check": "^4.10.2",
51
+ "functype": "^1.11.0",
52
+ "jsdom": "^30.1.1",
53
+ "react": "^19.3.0",
54
+ "react-dom": "^19.3.0",
55
+ "ts-builds": "^3.4.3",
56
+ "tsdown": "^0.23.0"
57
57
  },
58
58
  "type": "module",
59
59
  "main": "./dist/index.js",
@@ -1,2 +0,0 @@
1
- import{Fragment as e,jsx as t}from"react/jsx-runtime";function n(n){let r=n.children[n.value._tag];return t(e,{children:r(n.value)})}function r(n){return t(e,{children:n.value.fold(n.Left,n.Right)})}function i(n){return t(e,{children:n.value.fold(n.None,n.Some)})}function a(n){return t(e,{children:n.value.fold(n.Failure,n.Success)})}export{n as i,i as n,r,a as t};
2
- //# sourceMappingURL=match-4aBdbQyD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"match-4aBdbQyD.js","names":[],"sources":["../src/match/Match.tsx","../src/match/MatchEither.tsx","../src/match/MatchOption.tsx","../src/match/MatchTry.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Maps each `_tag` literal to a handler that receives the narrowed variant.\n *\n * TypeScript enforces exhaustiveness: omitting a case from `children` is a\n * compile error.\n */\nexport type MatchCases<U extends { _tag: string }> = {\n readonly [K in U[\"_tag\"]]: (value: Extract<U, { readonly _tag: K }>) => ReactNode\n}\n\n/**\n * Generic discriminated-union matcher for ADTs that follow functype's `_tag`\n * convention. Pass a value and a record of handlers keyed on each tag; the\n * matching handler is invoked with the narrowed variant.\n *\n * ```tsx\n * <Match value={state}>\n * {{\n * Loading: () => <Spinner />,\n * Success: ({ data }) => <Result data={data} />,\n * Failure: ({ error }) => <Err err={error} />,\n * }}\n * </Match>\n * ```\n */\nexport function Match<U extends { _tag: string }>(props: {\n readonly value: U\n readonly children: MatchCases<U>\n}): ReactElement {\n const handler = props.children[props.value._tag as U[\"_tag\"]] as (value: U) => ReactNode\n return <>{handler(props.value)}</>\n}\n","import type { Either } from \"functype/either\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Either<L, R>`.\n */\nexport function MatchEither<L, R>(props: {\n readonly value: Either<L, R>\n readonly Left: (l: L) => ReactNode\n readonly Right: (r: R) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Left, props.Right)}</>\n}\n","import type { Option } from \"functype/option\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the\n * `Some` handler and `None` to the `None` handler.\n */\nexport function MatchOption<A>(props: {\n readonly value: Option<A>\n readonly Some: (a: A) => ReactNode\n readonly None: () => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.None, props.Some)}</>\n}\n","import type { Try } from \"functype/try\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the\n * underlying `Error`; `Success` receives the value.\n */\nexport function MatchTry<A>(props: {\n readonly value: Try<A>\n readonly Success: (a: A) => ReactNode\n readonly Failure: (e: Error) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Failure, props.Success)}</>\n}\n"],"mappings":"sDA2BA,SAAgB,EAAkC,EAGjC,CACf,IAAM,EAAU,EAAM,SAAS,EAAM,MAAM,MAC3C,OAAO,EAAA,EAAA,CAAA,SAAG,EAAQ,EAAM,KAAK,CAAI,CAAA,CACnC,CC3BA,SAAgB,EAAkB,EAIjB,CACf,OAAO,EAAA,EAAA,CAAA,SAAG,EAAM,MAAM,KAAK,EAAM,KAAM,EAAM,KAAK,CAAI,CAAA,CACxD,CCLA,SAAgB,EAAe,EAId,CACf,OAAO,EAAA,EAAA,CAAA,SAAG,EAAM,MAAM,KAAK,EAAM,KAAM,EAAM,IAAI,CAAI,CAAA,CACvD,CCNA,SAAgB,EAAY,EAIX,CACf,OAAO,EAAA,EAAA,CAAA,SAAG,EAAM,MAAM,KAAK,EAAM,QAAS,EAAM,OAAO,CAAI,CAAA,CAC7D"}