functype-react 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -227,10 +227,12 @@ import { Http } from "functype/fetch"
227
227
  import { useIOMutation } from "functype-react/query"
228
228
 
229
229
  const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {
230
- onError: (e) => toast(e.message, { detail: e.error._tag }),
230
+ onError: (e) => toast(e.message, { detail: e.defect ? "unexpected" : e.error._tag }),
231
231
  })
232
232
  ```
233
233
 
234
+ `e` is the `IOQueryError<E>` box, so the typed error is `e.error`, and only when `e.defect` is `false`. To branch on it as an `Option`, write `e.defect ? None<ApiError>() : Some(e.error)`, with your own error type in place of `ApiError`. A bare `None()` makes the result `Option<unknown>`.
235
+
234
236
  For full control over the query object — or for `useSuspenseQuery` / `useInfiniteQuery` / `queryClient.prefetchQuery` — drop to the primitives. They carry no `@tanstack` types at all, so they compose with any of those:
235
237
 
236
238
  ```ts ignore
@@ -11,7 +11,7 @@ export type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A,
11
11
  *
12
12
  * ```ts
13
13
  * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {
14
- * onError: (e) => toast(e.message, { detail: e.error._tag }),
14
+ * onError: (e) => toast(e.message, { detail: e.defect ? "unexpected" : e.error._tag }),
15
15
  * })
16
16
  *
17
17
  * create.mutate({ name: "ci" })
@@ -1 +1 @@
1
- {"version":3,"file":"useIOMutation.js","names":["useMutation","ioMutationFn","useIOMutation","io","options","formatError","mutationOptions"],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"A,+GAgCA,SAAgBE,EACdC,EACAC,EACoD,CACpD,GAAM,CAAEC,cAAa,GAAGC,GAAoBF,GAAW,CAAC,EAExD,OAAOJ,EAA6C,CAClD,GAAGM,EACH,WAAYL,EAAsBE,EAAI,CAAEE,aAAY,CAAC,CACvD,CAAC,CACH,C"}
1
+ {"version":3,"file":"useIOMutation.js","names":["useMutation","ioMutationFn","useIOMutation","io","options","formatError","mutationOptions"],"sources":["../../src/query/useIOMutation.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationOptions, UseMutationResult } from \"@tanstack/react-query\"\nimport { useMutation } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioMutationFn } from \"./ioQueryFn\"\n\nexport type UseIOMutationOptions<A, E, V, TContext> = Omit<\n UseMutationOptions<A, IOQueryError<E>, V, TContext>,\n \"mutationFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its\n * typed error channel through to React Query.\n *\n * ```ts\n * const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {\n * onError: (e) => toast(e.message, { detail: e.defect ? \"unexpected\" : e.error._tag }),\n * })\n *\n * create.mutate({ name: \"ci\" })\n * ```\n *\n * React Query does not supply an `AbortSignal` to mutations, so the callback receives\n * only the mutation variables.\n */\nexport function useIOMutation<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseMutationResult<A, IOQueryError<E>, V, TContext> {\n const { formatError, ...mutationOptions } = options ?? {}\n\n return useMutation<A, IOQueryError<E>, V, TContext>({\n ...mutationOptions,\n mutationFn: ioMutationFn<E, A, V>(io, { formatError }),\n })\n}\n"],"mappings":"A,+GAgCA,SAAgBE,EACdC,EACAC,EACoD,CACpD,GAAM,CAAEC,cAAa,GAAGC,GAAoBF,GAAW,CAAC,EAExD,OAAOJ,EAA6C,CAClD,GAAGM,EACH,WAAYL,EAAsBE,EAAI,CAAEE,aAAY,CAAC,CACvD,CAAC,CACH,C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype-react",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "React bindings for functype — ADT-aware hooks and exhaustive pattern matching components",
5
5
  "keywords": [
6
6
  "functype",
@@ -47,7 +47,7 @@
47
47
  "@types/react": "^19.3.0",
48
48
  "@types/react-dom": "^19.3.0",
49
49
  "fast-check": "^4.10.3",
50
- "functype": "^2.2.1",
50
+ "functype": "^2.2.2",
51
51
  "jsdom": "^31.0.1",
52
52
  "react": "^19.3.1",
53
53
  "react-dom": "^19.3.1",