functype-react 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -8
- package/dist/TaskState-DWxGWqXf.d.ts +24 -0
- package/dist/async/TaskState.d.ts +2 -24
- package/dist/async/index.d.ts +1 -2
- package/dist/async/index.js.map +1 -1
- package/dist/async/useTask.d.ts +1 -2
- package/dist/async/useTaskPromise.d.ts +0 -1
- package/dist/forms/Validated.d.ts +0 -1
- package/dist/forms/useValidatedField.d.ts +0 -1
- package/dist/forms/useValidatedForm.d.ts +0 -1
- package/dist/hooks/eq.js +1 -1
- package/dist/hooks/eq.js.map +1 -1
- package/dist/hooks/index.d.ts +8 -8
- package/dist/hooks/useEither.d.ts +1 -1
- package/dist/hooks/useList.d.ts +1 -1
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useStableCallback.d.ts +1 -1
- package/dist/hooks/useStableEffect.d.ts +1 -1
- package/dist/hooks/useStableMemo.d.ts +1 -1
- package/dist/hooks/useStableState.d.ts +1 -1
- package/dist/hooks/useTry.d.ts +1 -1
- package/dist/{index-B1wI3pNy.d.ts → index-DjzwkXMF.d.ts} +2 -3
- package/dist/index.d.ts +10 -9
- package/dist/match/index.d.ts +1 -1
- package/dist/query/IOQueryError.d.ts +50 -0
- package/dist/query/IOQueryError.js +2 -0
- package/dist/query/IOQueryError.js.map +1 -0
- package/dist/query/index.d.ts +8 -0
- package/dist/query/index.js +1 -0
- package/dist/query/ioQueryFn.d.ts +51 -0
- package/dist/query/ioQueryFn.js +2 -0
- package/dist/query/ioQueryFn.js.map +1 -0
- package/dist/query/queryState.d.ts +78 -0
- package/dist/query/queryState.js +2 -0
- package/dist/query/queryState.js.map +1 -0
- package/dist/query/useIOMutation.d.ts +27 -0
- package/dist/query/useIOMutation.js +2 -0
- package/dist/query/useIOMutation.js.map +1 -0
- package/dist/query/useIOMutationState.d.ts +40 -0
- package/dist/query/useIOMutationState.js +2 -0
- package/dist/query/useIOMutationState.js.map +1 -0
- package/dist/query/useIOQuery.d.ts +39 -0
- package/dist/query/useIOQuery.js +2 -0
- package/dist/query/useIOQuery.js.map +1 -0
- package/dist/query/useIOQueryState.d.ts +45 -0
- package/dist/query/useIOQueryState.js +2 -0
- package/dist/query/useIOQueryState.js.map +1 -0
- package/dist/{useEither-BtjexxmJ.d.ts → useEither-DyPW7OaA.d.ts} +1 -2
- package/dist/{useList-DuZ4s_ax.d.ts → useList-B5Iox1xv.d.ts} +1 -2
- package/dist/{useOption-7xTC5RY_.d.ts → useOption-ByA_TwP_.d.ts} +1 -2
- package/dist/{useStableCallback-BK2Li2tM.d.ts → useStableCallback-CXQQOhl6.d.ts} +1 -2
- package/dist/{useStableEffect-sr_ERDtZ.d.ts → useStableEffect-C-5NCd1T.d.ts} +1 -2
- package/dist/{useStableMemo-INplGjSx.d.ts → useStableMemo-PYyLBWwd.d.ts} +1 -2
- package/dist/{useStableState-DyW-KdNX.d.ts → useStableState-fi6nURHS.d.ts} +1 -2
- package/dist/{useTry-lTpoF5Qy.d.ts → useTry-B0HIcFFb.d.ts} +1 -2
- package/package.json +19 -9
package/README.md
CHANGED
|
@@ -12,18 +12,19 @@ Push the same ADTs (`Option`, `Either`, `Try`, `Task`, `Validated`) you already
|
|
|
12
12
|
pnpm add functype functype-react react react-dom
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`react-dom` is an optional peer (drop it for React Native / RSC-only consumers).
|
|
15
|
+
`react-dom` is an optional peer (drop it for React Native / RSC-only consumers). `@tanstack/react-query` is likewise optional — install it only if you use `functype-react/query`.
|
|
16
16
|
|
|
17
17
|
## Surface
|
|
18
18
|
|
|
19
|
-
| Subpath | Contents
|
|
20
|
-
| ----------------------- |
|
|
21
|
-
| `functype-react` (main) | Stable hooks (`useStable*`), ADT hooks (`useOption`, `useEither`, `useTry`, `useList`), `Match` family components, equality helpers
|
|
22
|
-
| `functype-react/match` | `<Match>`, `<MatchOption>`, `<MatchEither>`, `<MatchTry>` (also re-exported from main)
|
|
23
|
-
| `functype-react/async` | `useTask`, `useTaskPromise`, `useTaskValue` (React 19 `use()` bridge), `<TaskBoundary>`
|
|
24
|
-
| `functype-react/forms` | `Validated<E, A>` type alias, `useValidatedField`, `useValidatedForm`
|
|
19
|
+
| Subpath | Contents |
|
|
20
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `functype-react` (main) | Stable hooks (`useStable*`), ADT hooks (`useOption`, `useEither`, `useTry`, `useList`), `Match` family components, equality helpers |
|
|
22
|
+
| `functype-react/match` | `<Match>`, `<MatchOption>`, `<MatchEither>`, `<MatchTry>` (also re-exported from main) |
|
|
23
|
+
| `functype-react/async` | `useTask`, `useTaskPromise`, `useTaskValue` (React 19 `use()` bridge), `<TaskBoundary>` |
|
|
24
|
+
| `functype-react/forms` | `Validated<E, A>` type alias, `useValidatedField`, `useValidatedForm` |
|
|
25
|
+
| `functype-react/query` | `useIOQuery(State)`, `useIOMutation(State)`, `ioQueryFn`, `ioMutationFn`, `IOQueryError`, `toQueryState` — TanStack Query adapters for `IO` |
|
|
25
26
|
|
|
26
|
-
`./async
|
|
27
|
+
`./async`, `./forms`, and `./query` stay off the main entry so consumers who don't touch Suspense, applicative forms, or React Query tree-shake them out.
|
|
27
28
|
|
|
28
29
|
## Tier 1 — stable hooks + ADT hooks
|
|
29
30
|
|
|
@@ -134,11 +135,129 @@ function Signup() {
|
|
|
134
135
|
|
|
135
136
|
Errors accumulate applicatively — every failing rule is surfaced in one pass, not just the first.
|
|
136
137
|
|
|
138
|
+
## Tier 5 — React Query
|
|
139
|
+
|
|
140
|
+
`Http.get(...)` returns `IO<never, HttpError, HttpResponse<T>>`, and neither `IO` terminal fits TanStack Query: `.run()` never throws (so React Query never sees a failure), and `.runOrThrow()` throws the raw tagged object — which is **not** an `Error`, so the ubiquitous `error instanceof Error ? error.message : fallback` handler silently degrades.
|
|
141
|
+
|
|
142
|
+
`functype-react/query` owns that bridge. Failures arrive boxed as `IOQueryError<E>`: a real `Error` with a populated `.message`, whose `.error` is still the fully discriminable functype error.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { useIOQuery } from "functype-react/query"
|
|
146
|
+
import { Http, HttpErrors, type HttpError } from "functype/fetch"
|
|
147
|
+
|
|
148
|
+
const { data, error } = useIOQuery(
|
|
149
|
+
["connector-limits", userId],
|
|
150
|
+
({ signal }) => Http.get<ConnectorLimits>(url, { headers, signal }),
|
|
151
|
+
{ enabled: !!userId },
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if (error) {
|
|
155
|
+
error instanceof Error // true
|
|
156
|
+
error.message // "HTTP 403 Forbidden — /api/limits"
|
|
157
|
+
|
|
158
|
+
HttpErrors.match(error.error, {
|
|
159
|
+
NetworkError: () => <Offline />,
|
|
160
|
+
HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),
|
|
161
|
+
DecodeError: () => <SchemaDrift />,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Matching instead of flag soup
|
|
167
|
+
|
|
168
|
+
The result above is still React Query's — `data` is `A | undefined`, so the success path needs a `!` or a guard. `toQueryState` projects it onto the same `TaskState` ADT that `functype-react/async` returns, so a query matches exhaustively like any other functype value:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { Match } from "functype-react"
|
|
172
|
+
import { toQueryState, useIOQuery } from "functype-react/query"
|
|
173
|
+
|
|
174
|
+
function UserPanel({ id }: { id: string }) {
|
|
175
|
+
const query = useIOQuery(["user", id], ({ signal }) => Http.get<User>(`/users/${id}`, { signal }))
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<Match value={toQueryState(query)}>
|
|
179
|
+
{{
|
|
180
|
+
Idle: () => null,
|
|
181
|
+
Pending: () => <Spinner />,
|
|
182
|
+
Failure: ({ error }) => <Err e={error.error} />,
|
|
183
|
+
Success: ({ value }) => <Profile user={value} />,
|
|
184
|
+
}}
|
|
185
|
+
</Match>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`Success` hands you a defined `User` — no `!`, no `| undefined` — and omitting a case is a compile error. A disabled query (`enabled: false`, never fetched) projects to `Idle`, an in-flight or paused one to `Pending`. `toMutationState` does the same for mutations, where React Query's own `idle` status maps straight onto `Idle`.
|
|
191
|
+
|
|
192
|
+
The projection is a pure function over the result, so you keep everything else React Query gives you (`refetch`, `isFetching`, `dataUpdatedAt`) on the original object. (Invalidation is a client-level operation — `queryClient.invalidateQueries()` — not a method on the result.)
|
|
193
|
+
|
|
194
|
+
If the ADT is all you need, `useIOQueryState` skips the projection step — it returns `TaskState` directly, plus the `isIdle`/`isPending`/`isSuccess`/`isFailure` flags and `refetch`, mirroring what `useTask` returns in Tier 3:
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
const user = useIOQueryState(["user", id], ({ signal }) => Http.get<User>(url, { signal }))
|
|
198
|
+
|
|
199
|
+
<Match value={user}>
|
|
200
|
+
{{
|
|
201
|
+
Idle: () => null,
|
|
202
|
+
Pending: () => <Spinner />,
|
|
203
|
+
Failure: ({ error }) => <Err e={error.error} />,
|
|
204
|
+
Success: ({ value }) => <Profile user={value} />,
|
|
205
|
+
}}
|
|
206
|
+
</Match>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`useIOMutationState` is the mutation counterpart, carrying `mutate` / `mutateAsync` / `reset` through alongside the state. Reach for `useIOQuery` + `toQueryState` when you need the rest of the result (`isFetching`, `dataUpdatedAt`).
|
|
210
|
+
|
|
211
|
+
Both read only the fields they project. For **queries** that matters: React Query tracks which result properties an observer touches and re-renders only when those change, so projecting a subset keeps that optimization intact rather than subscribing your component to every field. (Tracked props accumulate over an observer's lifetime, so this is a floor, not a guarantee.) **Mutations have no such tracking** in React Query — `MutationObserver` notifies on every change regardless — so for `useIOMutationState` the narrow read is merely tidy, not an optimization.
|
|
212
|
+
|
|
213
|
+
Two behaviours worth knowing before you rely on the ADT:
|
|
214
|
+
|
|
215
|
+
- **A failed background refetch projects to `Failure` even though React Query still holds the last successful `data`.** `TaskState` has no "loaded but stale" variant. This is the deliberate default — it never silently hides a failure — but it does mean a transient refetch error flips a loaded view to the error branch. To keep rendering stale data, read `query.data` alongside the projection or branch on `query.isRefetchError` before projecting.
|
|
216
|
+
- **If your effect factory throws synchronously** (before an `IO` is produced), the rejection is still boxed, but with `defect: true` and `.error` holding the raw thrown value rather than an `E`. Check `defect` before matching on `_tag` if that's reachable in your code.
|
|
217
|
+
|
|
218
|
+
Mutations mirror the shape (React Query supplies no `AbortSignal` to mutations, so the callback takes only the variables):
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
import { useIOMutation } from "functype-react/query"
|
|
222
|
+
|
|
223
|
+
const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {
|
|
224
|
+
onError: (e) => toast(e.message, { detail: e.error._tag }),
|
|
225
|
+
})
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
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:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { ioQueryFn } from "functype-react/query"
|
|
232
|
+
|
|
233
|
+
useQuery({
|
|
234
|
+
queryKey: ["connector-limits", userId],
|
|
235
|
+
queryFn: ioQueryFn(({ signal }) => Http.get<ConnectorLimits>(url, { headers, signal })),
|
|
236
|
+
enabled: !!userId,
|
|
237
|
+
})
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
`ioQueryFn` is generic over the query context, so a richer one flows through unchanged — annotate the callback parameter to reach `pageParam` in an infinite query:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
useInfiniteQuery({
|
|
244
|
+
queryKey: ["events"],
|
|
245
|
+
queryFn: ioQueryFn(({ signal, pageParam }: QueryFunctionContext<QueryKey, number>) =>
|
|
246
|
+
Http.get<Page>(url, { params: { cursor: pageParam }, signal }),
|
|
247
|
+
),
|
|
248
|
+
initialPageParam: 0,
|
|
249
|
+
getNextPageParam: (last) => last.data.nextCursor,
|
|
250
|
+
})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Both the hooks and the primitives are generic over any `IO<never, E, A>` — nothing here is HTTP-specific. `Error.message` is derived structurally (`formatIOError`); pass `formatError` to override it.
|
|
254
|
+
|
|
137
255
|
## Compatibility
|
|
138
256
|
|
|
139
257
|
- **TypeScript**: `strict: true` + `noUncheckedIndexedAccess: true`. Loose configs will silently lose the type-level exhaustiveness guarantees.
|
|
140
258
|
- **React**: peer dep range `>=18 <20`. Tier 3's `useTaskValue` (and consequently anything that depends on React 19's `use()` hook) is React-19-only at runtime; the rest of the package works on both.
|
|
141
259
|
- **SSR / RSC**: hooks are client-only and marked with `"use client"`. `<Match>` family components are pure and render fine in Server Components.
|
|
260
|
+
- **React Query**: Tier 5 targets `@tanstack/react-query` v5 (`>=5.0.0`), an optional peer. The `ioQueryFn` / `ioMutationFn` primitives type their context structurally, so they carry no `@tanstack` types and are unaffected by its major-version churn.
|
|
142
261
|
|
|
143
262
|
## Deferred to v0.2
|
|
144
263
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/async/TaskState.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Lifecycle state of an async operation managed by `useTask`.
|
|
4
|
+
*
|
|
5
|
+
* Note: the tag values are `Idle | Pending | Success | Failure` — these are
|
|
6
|
+
* the consumer-facing lifecycle phases, intentionally broader than functype
|
|
7
|
+
* core's `TaskOutcome<T>` (which has only `Ok | Err`). The hook maps
|
|
8
|
+
* `TaskOutcome.Ok → Success`, `TaskOutcome.Err → Failure`, and adds `Idle`
|
|
9
|
+
* (pre-mount) and `Pending` (in flight) for the rendering side.
|
|
10
|
+
*/
|
|
11
|
+
type TaskState<E, A> = {
|
|
12
|
+
readonly _tag: "Idle";
|
|
13
|
+
} | {
|
|
14
|
+
readonly _tag: "Pending";
|
|
15
|
+
} | {
|
|
16
|
+
readonly _tag: "Success";
|
|
17
|
+
readonly value: A;
|
|
18
|
+
} | {
|
|
19
|
+
readonly _tag: "Failure";
|
|
20
|
+
readonly error: E;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { TaskState as t };
|
|
24
|
+
//# sourceMappingURL=TaskState-DWxGWqXf.d.ts.map
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Lifecycle state of an async operation managed by `useTask`.
|
|
4
|
-
*
|
|
5
|
-
* Note: the tag values are `Idle | Pending | Success | Failure` — these are
|
|
6
|
-
* the consumer-facing lifecycle phases, intentionally broader than functype
|
|
7
|
-
* core's `TaskOutcome<T>` (which has only `Ok | Err`). The hook maps
|
|
8
|
-
* `TaskOutcome.Ok → Success`, `TaskOutcome.Err → Failure`, and adds `Idle`
|
|
9
|
-
* (pre-mount) and `Pending` (in flight) for the rendering side.
|
|
10
|
-
*/
|
|
11
|
-
type TaskState<E, A> = {
|
|
12
|
-
readonly _tag: "Idle";
|
|
13
|
-
} | {
|
|
14
|
-
readonly _tag: "Pending";
|
|
15
|
-
} | {
|
|
16
|
-
readonly _tag: "Success";
|
|
17
|
-
readonly value: A;
|
|
18
|
-
} | {
|
|
19
|
-
readonly _tag: "Failure";
|
|
20
|
-
readonly error: E;
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
23
|
-
export { TaskState };
|
|
24
|
-
//# sourceMappingURL=TaskState.d.ts.map
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
+
export { TaskState };
|
package/dist/async/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { TaskState } from "
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
2
|
import { UseTaskResult, useTask } from "./useTask.js";
|
|
3
3
|
import { useTaskPromise } from "./useTaskPromise.js";
|
|
4
4
|
import { useTaskValue } from "./useTaskValue.js";
|
|
5
5
|
import { ReactElement, ReactNode } from "react";
|
|
6
|
-
|
|
7
6
|
//#region src/async/TaskBoundary.d.ts
|
|
8
7
|
type Props = {
|
|
9
8
|
readonly pending: ReactNode;
|
package/dist/async/index.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/async/useTask.d.ts
CHANGED
package/dist/hooks/eq.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=Object.is,t=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=e._tag,r=t._tag;return n!==void 0&&n===r},n=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!=`object`)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>n(e,t[r]));if(Array.isArray(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length
|
|
1
|
+
const e=Object.is,t=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=e._tag,r=t._tag;return n!==void 0&&n===r},n=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!=`object`)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>n(e,t[r]));if(Array.isArray(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length&&r.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&n(e[r],t[r]))};export{e as referenceEq,n as structuralEq,t as tagEq};
|
|
2
2
|
//# sourceMappingURL=eq.js.map
|
package/dist/hooks/eq.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CK6oQqWG.js";
|
|
2
|
-
import { t as useEither } from "../useEither-
|
|
3
|
-
import { t as useList } from "../useList-
|
|
4
|
-
import { t as useOption } from "../useOption-
|
|
5
|
-
import { t as useStableCallback } from "../useStableCallback-
|
|
6
|
-
import { t as useStableEffect } from "../useStableEffect-
|
|
7
|
-
import { t as useStableMemo } from "../useStableMemo-
|
|
8
|
-
import { t as useStableState } from "../useStableState-
|
|
9
|
-
import { t as useTry } from "../useTry-
|
|
2
|
+
import { t as useEither } from "../useEither-DyPW7OaA.js";
|
|
3
|
+
import { t as useList } from "../useList-B5Iox1xv.js";
|
|
4
|
+
import { t as useOption } from "../useOption-ByA_TwP_.js";
|
|
5
|
+
import { t as useStableCallback } from "../useStableCallback-CXQQOhl6.js";
|
|
6
|
+
import { t as useStableEffect } from "../useStableEffect-C-5NCd1T.js";
|
|
7
|
+
import { t as useStableMemo } from "../useStableMemo-PYyLBWwd.js";
|
|
8
|
+
import { t as useStableState } from "../useStableState-fi6nURHS.js";
|
|
9
|
+
import { t as useTry } from "../useTry-B0HIcFFb.js";
|
|
10
10
|
export { type Eq, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useEither } from "../useEither-
|
|
1
|
+
import { t as useEither } from "../useEither-DyPW7OaA.js";
|
|
2
2
|
export { useEither };
|
package/dist/hooks/useList.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useList } from "../useList-
|
|
1
|
+
import { t as useList } from "../useList-B5Iox1xv.js";
|
|
2
2
|
export { useList };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useOption } from "../useOption-
|
|
1
|
+
import { t as useOption } from "../useOption-ByA_TwP_.js";
|
|
2
2
|
export { useOption };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableCallback } from "../useStableCallback-
|
|
1
|
+
import { t as useStableCallback } from "../useStableCallback-CXQQOhl6.js";
|
|
2
2
|
export { useStableCallback };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableEffect } from "../useStableEffect-
|
|
1
|
+
import { t as useStableEffect } from "../useStableEffect-C-5NCd1T.js";
|
|
2
2
|
export { useStableEffect };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableMemo } from "../useStableMemo-
|
|
1
|
+
import { t as useStableMemo } from "../useStableMemo-PYyLBWwd.js";
|
|
2
2
|
export { useStableMemo };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableState } from "../useStableState-
|
|
1
|
+
import { t as useStableState } from "../useStableState-fi6nURHS.js";
|
|
2
2
|
export { useStableState };
|
package/dist/hooks/useTry.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useTry } from "../useTry-
|
|
1
|
+
import { t as useTry } from "../useTry-B0HIcFFb.js";
|
|
2
2
|
export { useTry };
|
|
@@ -2,7 +2,6 @@ import { Either } from "functype/either";
|
|
|
2
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
3
|
import { Option } from "functype/option";
|
|
4
4
|
import { Try } from "functype/try";
|
|
5
|
-
|
|
6
5
|
//#region src/match/Match.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Maps each `_tag` literal to a handler that receives the narrowed variant.
|
|
@@ -14,7 +13,7 @@ type MatchCases<U extends {
|
|
|
14
13
|
_tag: string;
|
|
15
14
|
}> = { readonly [K in U["_tag"]]: (value: Extract<U, {
|
|
16
15
|
readonly _tag: K;
|
|
17
|
-
}>) => ReactNode };
|
|
16
|
+
}>) => ReactNode; };
|
|
18
17
|
/**
|
|
19
18
|
* Generic discriminated-union matcher for ADTs that follow functype's `_tag`
|
|
20
19
|
* convention. Pass a value and a record of handlers keyed on each tag; the
|
|
@@ -70,4 +69,4 @@ declare function MatchTry<A>(props: {
|
|
|
70
69
|
}): ReactElement;
|
|
71
70
|
//#endregion
|
|
72
71
|
export { MatchCases as a, Match as i, MatchOption as n, MatchEither as r, MatchTry as t };
|
|
73
|
-
//# sourceMappingURL=index-
|
|
72
|
+
//# sourceMappingURL=index-DjzwkXMF.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
|
-
import { t as useEither } from "./useEither-
|
|
3
|
-
import { t as useList } from "./useList-
|
|
4
|
-
import { t as useOption } from "./useOption-
|
|
5
|
-
import { t as useStableCallback } from "./useStableCallback-
|
|
6
|
-
import { t as useStableEffect } from "./useStableEffect-
|
|
7
|
-
import { t as useStableMemo } from "./useStableMemo-
|
|
8
|
-
import { t as useStableState } from "./useStableState-
|
|
9
|
-
import { t as useTry } from "./useTry-
|
|
10
|
-
import
|
|
2
|
+
import { t as useEither } from "./useEither-DyPW7OaA.js";
|
|
3
|
+
import { t as useList } from "./useList-B5Iox1xv.js";
|
|
4
|
+
import { t as useOption } from "./useOption-ByA_TwP_.js";
|
|
5
|
+
import { t as useStableCallback } from "./useStableCallback-CXQQOhl6.js";
|
|
6
|
+
import { t as useStableEffect } from "./useStableEffect-C-5NCd1T.js";
|
|
7
|
+
import { t as useStableMemo } from "./useStableMemo-PYyLBWwd.js";
|
|
8
|
+
import { t as useStableState } from "./useStableState-fi6nURHS.js";
|
|
9
|
+
import { t as useTry } from "./useTry-B0HIcFFb.js";
|
|
10
|
+
import "./hooks/index.js";
|
|
11
|
+
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "./index-DjzwkXMF.js";
|
|
11
12
|
export { type Eq, Match, type MatchCases, MatchEither, MatchOption, MatchTry, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
|
package/dist/match/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "../index-
|
|
1
|
+
import { a as MatchCases, i as Match, n as MatchOption, r as MatchEither, t as MatchTry } from "../index-DjzwkXMF.js";
|
|
2
2
|
export { Match, type MatchCases, MatchEither, MatchOption, MatchTry };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/query/IOQueryError.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Derives a human-readable message from an arbitrary error channel value.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately *structural* — this module does not import `functype/fetch`, so the
|
|
6
|
+
* query bridge stays generic over any `IO<never, E, A>` rather than being HTTP-specific.
|
|
7
|
+
* An `HttpStatusError` is recognized by its shape, not its type.
|
|
8
|
+
*
|
|
9
|
+
* Pass `formatError` to any of the query entry points to override this entirely.
|
|
10
|
+
*/
|
|
11
|
+
declare const formatIOError: (error: unknown) => string;
|
|
12
|
+
/**
|
|
13
|
+
* An `Error` subclass carrying the typed functype error channel.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { error } = useIOQuery(["limits", userId], ({ signal }) => Http.get(url, { signal }))
|
|
17
|
+
*
|
|
18
|
+
* error instanceof Error // true
|
|
19
|
+
* error.message // "HTTP 403 Forbidden — /api/limits"
|
|
20
|
+
*
|
|
21
|
+
* HttpErrors.match(error.error, {
|
|
22
|
+
* NetworkError: (e) => retryBanner(e),
|
|
23
|
+
* HttpStatusError: (e) => (e.status === 403 ? upgradePrompt() : genericFailure(e)),
|
|
24
|
+
* DecodeError: (e) => reportSchemaDrift(e),
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare class IOQueryError<E> extends Error {
|
|
29
|
+
/**
|
|
30
|
+
* The raw functype error channel value — discriminable via its own `_tag`.
|
|
31
|
+
*
|
|
32
|
+
* When {@link defect} is `true` this is **not** an `E`: it is whatever the effect
|
|
33
|
+
* factory threw before an `IO` was ever produced. Check `defect` before matching
|
|
34
|
+
* on `_tag` if your factory can throw synchronously.
|
|
35
|
+
*/
|
|
36
|
+
readonly error: E;
|
|
37
|
+
/**
|
|
38
|
+
* `true` when this wraps an unexpected throw rather than a value from the effect's
|
|
39
|
+
* typed error channel — i.e. the effect factory itself threw. Kept as an explicit
|
|
40
|
+
* flag rather than widening `E` to `unknown`, which would force every consumer to
|
|
41
|
+
* handle a case that should never occur.
|
|
42
|
+
*/
|
|
43
|
+
readonly defect: boolean;
|
|
44
|
+
constructor(error: E, message?: string, defect?: boolean);
|
|
45
|
+
}
|
|
46
|
+
/** Runtime guard for {@link IOQueryError}. */
|
|
47
|
+
declare const isIOQueryError: <E = unknown>(error: unknown) => error is IOQueryError<E>;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { IOQueryError, formatIOError, isIOQueryError };
|
|
50
|
+
//# sourceMappingURL=IOQueryError.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Try as e}from"functype";const t=e=>typeof e==`object`&&!!e&&`_tag`in e&&typeof e._tag==`string`,n=n=>{if(n instanceof Error)return n.message;if(t(n)){let e=typeof n.url==`string`?` — ${n.url}`:``;if(typeof n.status==`number`){let t=typeof n.statusText==`string`&&n.statusText.length>0?` ${n.statusText}`:``;return`HTTP ${n.status}${t}${e}`}return`${n._tag}${e}`}return typeof n==`object`&&n?e(()=>JSON.stringify(n)).orElse(String(n)):String(n)};var r=class extends Error{constructor(e,t,r=!1){super(t??n(e),{cause:e}),this.name=`IOQueryError`,this.error=e,this.defect=r}};const i=e=>e instanceof r;export{r as IOQueryError,n as formatIOError,i as isIOQueryError};
|
|
2
|
+
//# sourceMappingURL=IOQueryError.js.map
|
|
@@ -0,0 +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}\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 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`: it is whatever the effect\n * factory threw before an `IO` was ever produced. Check `defect` before matching\n * on `_tag` if your factory can throw synchronously.\n */\n readonly error: E\n\n /**\n * `true` when this wraps an unexpected throw rather than a value from the effect's\n * typed error channel — i.e. the effect factory itself threw. Kept as an explicit\n * flag rather than widening `E` to `unknown`, which would force every consumer to\n * handle a case that should never occur.\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":"+BAuBA,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,CAEA,MAAO,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,CAkBzC,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IOQueryError, formatIOError, isIOQueryError } from "./IOQueryError.js";
|
|
2
|
+
import { IOBridgeOptions, IOQueryFnContext, ioMutationFn, ioQueryFn } from "./ioQueryFn.js";
|
|
3
|
+
import { MutationResultView, QueryResultView, toMutationState, toQueryState } from "./queryState.js";
|
|
4
|
+
import { UseIOMutationOptions, useIOMutation } from "./useIOMutation.js";
|
|
5
|
+
import { UseIOMutationStateResult, useIOMutationState } from "./useIOMutationState.js";
|
|
6
|
+
import { UseIOQueryOptions, useIOQuery } from "./useIOQuery.js";
|
|
7
|
+
import { UseIOQueryStateResult, useIOQueryState } from "./useIOQueryState.js";
|
|
8
|
+
export { type IOBridgeOptions, IOQueryError, type IOQueryFnContext, type MutationResultView, type QueryResultView, type UseIOMutationOptions, type UseIOMutationStateResult, type UseIOQueryOptions, type UseIOQueryStateResult, formatIOError, ioMutationFn, ioQueryFn, isIOQueryError, toMutationState, toQueryState, useIOMutation, useIOMutationState, useIOQuery, useIOQueryState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{IOQueryError as e,formatIOError as t,isIOQueryError as n}from"./IOQueryError.js";import{ioMutationFn as r,ioQueryFn as i}from"./ioQueryFn.js";import{toMutationState as a,toQueryState as o}from"./queryState.js";import{useIOMutation as s}from"./useIOMutation.js";import{useIOMutationState as c}from"./useIOMutationState.js";import{useIOQuery as l}from"./useIOQuery.js";import{useIOQueryState as u}from"./useIOQueryState.js";export{e as IOQueryError,t as formatIOError,r as ioMutationFn,i as ioQueryFn,n as isIOQueryError,a as toMutationState,o as toQueryState,s as useIOMutation,c as useIOMutationState,l as useIOQuery,u as useIOQueryState};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IO } from "functype/io";
|
|
2
|
+
//#region src/query/ioQueryFn.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Minimal structural view of React Query's `QueryFunctionContext` — the floor that
|
|
5
|
+
* every context satisfies, and the default when nothing wider is inferred.
|
|
6
|
+
*
|
|
7
|
+
* Typed structurally on purpose, so these primitives carry **no**
|
|
8
|
+
* `@tanstack/react-query` type dependency. `ioQueryFn` is generic over the context, so
|
|
9
|
+
* a richer one flows through unchanged: annotate the callback parameter (e.g. with
|
|
10
|
+
* `QueryFunctionContext<QueryKey, number>` for an infinite query) and `pageParam`,
|
|
11
|
+
* `queryKey`, and `meta` are all readable inside the effect factory.
|
|
12
|
+
*/
|
|
13
|
+
type IOQueryFnContext = {
|
|
14
|
+
readonly signal: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
type IOBridgeOptions<E> = {
|
|
17
|
+
/** Override the derived `Error.message`. Defaults to a structural formatter. */
|
|
18
|
+
readonly formatError?: (error: E) => string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Adapts an `IO<never, E, A>` into a React Query `queryFn`.
|
|
22
|
+
*
|
|
23
|
+
* `Right` resolves with the value; `Left` rejects with an {@link IOQueryError} that
|
|
24
|
+
* carries the typed error on `.error`. Wire cancellation by closing over the supplied
|
|
25
|
+
* `signal`:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* useQuery({
|
|
29
|
+
* queryKey: ["connector-limits", userId],
|
|
30
|
+
* queryFn: ioQueryFn(({ signal }) => Http.get<Limits>(url, { headers, signal })),
|
|
31
|
+
* enabled: !!userId,
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
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>;
|
|
36
|
+
/**
|
|
37
|
+
* Adapts a variables-taking `IO<never, E, A>` into a React Query `mutationFn`.
|
|
38
|
+
*
|
|
39
|
+
* React Query does not supply an `AbortSignal` to mutations, so the callback receives
|
|
40
|
+
* only the mutation variables.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* useMutation({
|
|
44
|
+
* mutationFn: ioMutationFn((body: CreateTokenInput) => Http.post<Token>(url, { body })),
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const ioMutationFn: <E, A, V = void>(io: (variables: V) => IO<never, E, A>, options?: IOBridgeOptions<E>) => (variables: V) => Promise<A>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { IOBridgeOptions, IOQueryFnContext, ioMutationFn, ioQueryFn };
|
|
51
|
+
//# sourceMappingURL=ioQueryFn.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{IOQueryError as e}from"./IOQueryError.js";import{Try as t}from"functype";const n=async(n,r)=>{let i=await t(()=>n()).fold(t=>{throw new e(t,void 0,!0)},e=>e.run());if(i.isLeft())throw new e(i.value,r?.formatError?.(i.value));return i.value},r=(e,t)=>r=>n(()=>e(r),t),i=(e,t)=>r=>n(()=>e(r),t);export{i as ioMutationFn,r as ioQueryFn};
|
|
2
|
+
//# sourceMappingURL=ioQueryFn.js.map
|
|
@@ -0,0 +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 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 * Two failure paths converge here:\n * - the effect's typed error channel (`Left`) → boxed with `defect: false`\n * - the factory throwing before an `IO` exists → boxed with `defect: true`\n *\n * The second matters because `.run()` itself never throws (defects raised *inside*\n * the effect are folded into `Left` by the interpreter), but `io(input)` is ordinary\n * user code that can throw while building the effect. Without this, that throw would\n * escape unboxed and `error.error` would be `undefined` despite the declared type.\n */\nconst runBoxed = async <E, A>(effect: () => IO<never, E, A>, options?: IOBridgeOptions<E>): Promise<A> => {\n const result = await Try(() => effect()).fold(\n (thrown) => {\n throw new IOQueryError(thrown as E, undefined, true)\n },\n (io) => io.run(),\n )\n\n if (result.isLeft()) {\n throw new IOQueryError(result.value, options?.formatError?.(result.value))\n }\n\n return result.value\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":"gFA4CA,MAAM,EAAW,MAAa,EAA+B,IAA6C,CACxG,IAAM,EAAS,MAAM,MAAU,EAAO,CAAC,CAAC,CAAC,KACtC,GAAW,CACV,MAAM,IAAI,EAAa,EAAa,IAAA,GAAW,EAAI,CACrD,EACC,GAAO,EAAG,IAAI,CACjB,EAEA,GAAI,EAAO,OAAO,EAChB,MAAM,IAAI,EAAa,EAAO,MAAO,GAAS,cAAc,EAAO,KAAK,CAAC,EAG3E,OAAO,EAAO,KAChB,EAiBa,GAET,EACA,IAED,GACC,MAAe,EAAG,CAAO,EAAG,CAAO,EAc1B,GACM,EAAuC,IACvD,GACC,MAAe,EAAG,CAAS,EAAG,CAAO"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
+
//#region src/query/queryState.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Structural view of a React Query result — the discriminated shape this module
|
|
5
|
+
* actually depends on. Typed structurally (like {@link IOQueryFnContext}) so the
|
|
6
|
+
* projection carries no `@tanstack/react-query` type dependency; `UseQueryResult`
|
|
7
|
+
* satisfies it.
|
|
8
|
+
*/
|
|
9
|
+
type QueryResultView<E, A> = {
|
|
10
|
+
readonly status: "pending";
|
|
11
|
+
readonly fetchStatus: "fetching" | "paused" | "idle";
|
|
12
|
+
} | {
|
|
13
|
+
readonly status: "success";
|
|
14
|
+
readonly data: A;
|
|
15
|
+
} | {
|
|
16
|
+
readonly status: "error";
|
|
17
|
+
readonly error: E;
|
|
18
|
+
};
|
|
19
|
+
/** Structural view of a React Query mutation result. */
|
|
20
|
+
type MutationResultView<E, A> = {
|
|
21
|
+
readonly status: "idle";
|
|
22
|
+
} | {
|
|
23
|
+
readonly status: "pending";
|
|
24
|
+
} | {
|
|
25
|
+
readonly status: "success";
|
|
26
|
+
readonly data: A;
|
|
27
|
+
} | {
|
|
28
|
+
readonly status: "error";
|
|
29
|
+
readonly error: E;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Projects a React Query result onto the package's `TaskState` ADT, so a query can
|
|
33
|
+
* be folded or matched exhaustively instead of read through `data && !error && !isLoading`.
|
|
34
|
+
*
|
|
35
|
+
* This is the whole point of `functype-react`: omitting a case becomes a compile
|
|
36
|
+
* error, and the success branch hands you a defined `A` rather than `A | undefined`
|
|
37
|
+
* that needs a `!`.
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* const query = useIOQuery(["user", id], ({ signal }) => Http.get<User>(url, { signal }))
|
|
41
|
+
*
|
|
42
|
+
* <Match value={toQueryState(query)}>
|
|
43
|
+
* {{
|
|
44
|
+
* Idle: () => null,
|
|
45
|
+
* Pending: () => <Spinner />,
|
|
46
|
+
* Failure: ({ error }) => <Err e={error} />,
|
|
47
|
+
* Success: ({ value }) => <Profile user={value} />,
|
|
48
|
+
* }}
|
|
49
|
+
* </Match>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* A disabled query (`enabled: false`, never fetched) projects to `Idle`; an
|
|
53
|
+
* in-flight or paused one to `Pending`. Reuses the same `TaskState` that
|
|
54
|
+
* `functype-react/async`'s `useTask` returns, so both async surfaces match alike.
|
|
55
|
+
*
|
|
56
|
+
* **Stale data on a failed refetch.** React Query keeps the last successful `data`
|
|
57
|
+
* while setting `status: "error"` when a *background refetch* fails. `TaskState` has
|
|
58
|
+
* no variant for "loaded, but the latest fetch failed", so that squashes to `Failure`
|
|
59
|
+
* and the still-held data is not surfaced through the ADT — a transient background
|
|
60
|
+
* failure will flip a loaded view to an error branch. This is the deliberate default:
|
|
61
|
+
* it never silently hides a failure. If you would rather keep rendering stale data,
|
|
62
|
+
* read `query.data` directly alongside the projection, or branch on
|
|
63
|
+
* `query.isRefetchError` before projecting.
|
|
64
|
+
*
|
|
65
|
+
* **Interruption.** `IO.run()` maps an interrupted effect to `Left(InterruptedError)`,
|
|
66
|
+
* which is not an `E`. Nothing in this subpath interrupts effects, so it will not
|
|
67
|
+
* arise here, but it is worth knowing that `.error` is `E` by construction rather
|
|
68
|
+
* than by proof.
|
|
69
|
+
*/
|
|
70
|
+
declare const toQueryState: <E, A>(result: QueryResultView<E, A>) => TaskState<E, A>;
|
|
71
|
+
/**
|
|
72
|
+
* Projects a React Query mutation result onto `TaskState`. React Query models an
|
|
73
|
+
* unfired mutation as `status: "idle"`, which maps directly onto `Idle`.
|
|
74
|
+
*/
|
|
75
|
+
declare const toMutationState: <E, A>(result: MutationResultView<E, A>) => TaskState<E, A>;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { MutationResultView, QueryResultView, toMutationState, toQueryState };
|
|
78
|
+
//# sourceMappingURL=queryState.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=e=>{switch(e.status){case`success`:return{_tag:`Success`,value:e.data};case`error`:return{_tag:`Failure`,error:e.error};case`pending`:return e.fetchStatus===`idle`?{_tag:`Idle`}:{_tag:`Pending`}}},t=e=>{switch(e.status){case`success`:return{_tag:`Success`,value:e.data};case`error`:return{_tag:`Failure`,error:e.error};case`pending`:return{_tag:`Pending`};case`idle`:return{_tag:`Idle`}}};export{t as toMutationState,e as toQueryState};
|
|
2
|
+
//# sourceMappingURL=queryState.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
2
|
+
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
3
|
+
import { IO } from "functype/io";
|
|
4
|
+
//#region src/query/useIOMutation.d.ts
|
|
5
|
+
type UseIOMutationOptions<A, E, V, TContext> = Omit<UseMutationOptions<A, IOQueryError<E>, V, TContext>, "mutationFn"> & {
|
|
6
|
+
/** Override the derived `Error.message` on failure. */
|
|
7
|
+
readonly formatError?: (error: E) => string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `useMutation` for effects — runs an `IO<never, E, A>` per invocation and threads its
|
|
11
|
+
* typed error channel through to React Query.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const create = useIOMutation((body: CreateTokenInput) => Http.post<Token>(url, { headers, body }), {
|
|
15
|
+
* onError: (e) => toast(e.message, { detail: e.error._tag }),
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* create.mutate({ name: "ci" })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* React Query does not supply an `AbortSignal` to mutations, so the callback receives
|
|
22
|
+
* only the mutation variables.
|
|
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>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { UseIOMutationOptions, useIOMutation };
|
|
27
|
+
//# sourceMappingURL=useIOMutation.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
3
|
+
import { UseIOMutationOptions } from "./useIOMutation.js";
|
|
4
|
+
import { UseMutationResult } from "@tanstack/react-query";
|
|
5
|
+
import { IO } from "functype/io";
|
|
6
|
+
//#region src/query/useIOMutationState.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* `TaskState` plus the flags and the trigger functions. Unlike a query, a mutation is
|
|
9
|
+
* useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried
|
|
10
|
+
* through with React Query's own signatures.
|
|
11
|
+
*/
|
|
12
|
+
type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError<E>, A> & Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, "mutate" | "mutateAsync" | "reset"> & {
|
|
13
|
+
readonly isIdle: boolean;
|
|
14
|
+
readonly isPending: boolean;
|
|
15
|
+
readonly isSuccess: boolean;
|
|
16
|
+
readonly isFailure: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* `useIOMutation` projected onto the `TaskState` ADT, so a mutation's lifecycle matches
|
|
20
|
+
* exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const create = useIOMutationState((body: CreateTokenInput) => Http.post<Token>(url, { body }))
|
|
24
|
+
*
|
|
25
|
+
* <button onClick={() => create.mutate({ name: "ci" })} disabled={create.isPending}>create</button>
|
|
26
|
+
*
|
|
27
|
+
* <Match value={create}>
|
|
28
|
+
* {{
|
|
29
|
+
* Idle: () => null,
|
|
30
|
+
* Pending: () => <Spinner />,
|
|
31
|
+
* Failure: ({ error }) => <Err e={error.error} />,
|
|
32
|
+
* Success: ({ value }) => <TokenRow token={value} />,
|
|
33
|
+
* }}
|
|
34
|
+
* </Match>
|
|
35
|
+
* ```
|
|
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>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { UseIOMutationStateResult, useIOMutationState };
|
|
40
|
+
//# sourceMappingURL=useIOMutationState.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{toMutationState as e}from"./queryState.js";import{useIOMutation as t}from"./useIOMutation.js";function n(n,r){let i=t(n,r),a=e(i);return{...a,isIdle:a._tag===`Idle`,isPending:a._tag===`Pending`,isSuccess:a._tag===`Success`,isFailure:a._tag===`Failure`,mutate:i.mutate,mutateAsync:i.mutateAsync,reset:i.reset}}export{n as useIOMutationState};
|
|
2
|
+
//# sourceMappingURL=useIOMutationState.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
2
|
+
import { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
3
|
+
import { IO } from "functype/io";
|
|
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"> & {
|
|
6
|
+
/** Override the derived `Error.message` on failure. */
|
|
7
|
+
readonly formatError?: (error: E) => string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel
|
|
11
|
+
* through to React Query's `error`.
|
|
12
|
+
*
|
|
13
|
+
* The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and
|
|
14
|
+
* `error.message` behave normally while `error.error` stays fully discriminable:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const { data, error } = useIOQuery(
|
|
18
|
+
* ["connector-limits", userId],
|
|
19
|
+
* ({ signal }) => Http.get<Limits>(url, { headers, signal }),
|
|
20
|
+
* { enabled: !!userId },
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* if (error) {
|
|
24
|
+
* HttpErrors.match(error.error, {
|
|
25
|
+
* NetworkError: () => <Offline />,
|
|
26
|
+
* HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),
|
|
27
|
+
* DecodeError: () => <SchemaDrift />,
|
|
28
|
+
* })
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes
|
|
33
|
+
* through untouched. For full control over the query object — or for
|
|
34
|
+
* `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.
|
|
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>>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { UseIOQueryOptions, useIOQuery };
|
|
39
|
+
//# sourceMappingURL=useIOQuery.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
3
|
+
import { UseIOQueryOptions } from "./useIOQuery.js";
|
|
4
|
+
import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
|
|
5
|
+
import { IO } from "functype/io";
|
|
6
|
+
//#region src/query/useIOQueryState.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* `TaskState` plus the convenience flags and refetch trigger, mirroring
|
|
9
|
+
* `UseTaskResult` from `functype-react/async` so both async surfaces read alike.
|
|
10
|
+
*
|
|
11
|
+
* `refetch` keeps React Query's own signature rather than a lossy re-declaration.
|
|
12
|
+
*/
|
|
13
|
+
type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<UseQueryResult<A, IOQueryError<E>>, "refetch"> & {
|
|
14
|
+
readonly isIdle: boolean;
|
|
15
|
+
readonly isPending: boolean;
|
|
16
|
+
readonly isSuccess: boolean;
|
|
17
|
+
readonly isFailure: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* `useIOQuery` projected straight onto the `TaskState` ADT — the flag-soup-free path
|
|
21
|
+
* in one call.
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const user = useIOQueryState(["user", id], ({ signal }) => Http.get<User>(url, { signal }))
|
|
25
|
+
*
|
|
26
|
+
* <Match value={user}>
|
|
27
|
+
* {{
|
|
28
|
+
* Idle: () => null,
|
|
29
|
+
* Pending: () => <Spinner />,
|
|
30
|
+
* Failure: ({ error }) => <Err e={error.error} />,
|
|
31
|
+
* Success: ({ value }) => <Profile user={value} />,
|
|
32
|
+
* }}
|
|
33
|
+
* </Match>
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Reads only `status` / `fetchStatus` / `data` / `error` / `refetch` off the query, so
|
|
37
|
+
* React Query's tracked-properties optimization still applies — the component is not
|
|
38
|
+
* subscribed to fields it never renders. When you need the rest of the result
|
|
39
|
+
* (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with
|
|
40
|
+
* {@link toQueryState} instead.
|
|
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>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { UseIOQueryStateResult, useIOQueryState };
|
|
45
|
+
//# sourceMappingURL=useIOQueryState.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{toQueryState as e}from"./queryState.js";import{useIOQuery as t}from"./useIOQuery.js";function n(n,r,i){let a=t(n,r,i),o=e(a);return{...o,isIdle:o._tag===`Idle`,isPending:o._tag===`Pending`,isSuccess:o._tag===`Success`,isFailure:o._tag===`Failure`,refetch:a.refetch}}export{n as useIOQueryState};
|
|
2
|
+
//# sourceMappingURL=useIOQueryState.js.map
|
|
@@ -0,0 +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,5 +1,4 @@
|
|
|
1
1
|
import { Either } from "functype/either";
|
|
2
|
-
|
|
3
2
|
//#region src/hooks/useEither.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Stateful Either container. Defaults to Left(undefined) when no initial.
|
|
@@ -12,4 +11,4 @@ declare function useEither<E, A>(initial?: Either<E, A>): {
|
|
|
12
11
|
};
|
|
13
12
|
//#endregion
|
|
14
13
|
export { useEither as t };
|
|
15
|
-
//# sourceMappingURL=useEither-
|
|
14
|
+
//# sourceMappingURL=useEither-DyPW7OaA.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { List } from "functype/list";
|
|
2
|
-
|
|
3
2
|
//#region src/hooks/useList.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Stateful immutable List container. All mutators return new state.
|
|
@@ -15,4 +14,4 @@ declare function useList<A>(initial?: readonly A[]): {
|
|
|
15
14
|
};
|
|
16
15
|
//#endregion
|
|
17
16
|
export { useList as t };
|
|
18
|
-
//# sourceMappingURL=useList-
|
|
17
|
+
//# sourceMappingURL=useList-B5Iox1xv.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Option } from "functype/option";
|
|
2
|
-
|
|
3
2
|
//#region src/hooks/useOption.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Stateful Option container. `set(null | undefined)` clears to None.
|
|
@@ -13,4 +12,4 @@ declare function useOption<A>(initial?: A): {
|
|
|
13
12
|
};
|
|
14
13
|
//#endregion
|
|
15
14
|
export { useOption as t };
|
|
16
|
-
//# sourceMappingURL=useOption-
|
|
15
|
+
//# sourceMappingURL=useOption-ByA_TwP_.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/hooks/useStableCallback.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Like `useCallback`, but only returns a new function when *some* dep has
|
|
@@ -9,4 +8,4 @@ import { DependencyList } from "react";
|
|
|
9
8
|
declare function useStableCallback<F extends (...args: never[]) => unknown>(callback: F, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): F;
|
|
10
9
|
//#endregion
|
|
11
10
|
export { useStableCallback as t };
|
|
12
|
-
//# sourceMappingURL=useStableCallback-
|
|
11
|
+
//# sourceMappingURL=useStableCallback-CXQQOhl6.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList, EffectCallback } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/hooks/useStableEffect.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Like `useEffect`, but re-runs only when *some* dep has changed under the
|
|
@@ -13,4 +12,4 @@ import { DependencyList, EffectCallback } from "react";
|
|
|
13
12
|
declare function useStableEffect(effect: EffectCallback, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): void;
|
|
14
13
|
//#endregion
|
|
15
14
|
export { useStableEffect as t };
|
|
16
|
-
//# sourceMappingURL=useStableEffect-
|
|
15
|
+
//# sourceMappingURL=useStableEffect-C-5NCd1T.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
2
|
import { DependencyList } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/hooks/useStableMemo.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Like `useMemo`, but recomputes only when *some* dep has changed under the
|
|
@@ -10,4 +9,4 @@ import { DependencyList } from "react";
|
|
|
10
9
|
declare function useStableMemo<A>(factory: () => A, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): A;
|
|
11
10
|
//#endregion
|
|
12
11
|
export { useStableMemo as t };
|
|
13
|
-
//# sourceMappingURL=useStableMemo-
|
|
12
|
+
//# sourceMappingURL=useStableMemo-PYyLBWwd.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
|
-
|
|
3
2
|
//#region src/hooks/useStableState.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Drop-in replacement for `useState` that no-ops when the next value is equal
|
|
@@ -12,4 +11,4 @@ import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
|
12
11
|
declare function useStableState<A>(initial: A | (() => A), eq?: Eq<A>): readonly [A, (next: A | ((prev: A) => A)) => void];
|
|
13
12
|
//#endregion
|
|
14
13
|
export { useStableState as t };
|
|
15
|
-
//# sourceMappingURL=useStableState-
|
|
14
|
+
//# sourceMappingURL=useStableState-fi6nURHS.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Try } from "functype/try";
|
|
2
|
-
|
|
3
2
|
//#region src/hooks/useTry.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Stateful Try container. Defaults to Failure(new Error("uninitialized")) when no initial.
|
|
@@ -12,4 +11,4 @@ declare function useTry<A>(initial?: Try<A>): {
|
|
|
12
11
|
};
|
|
13
12
|
//#endregion
|
|
14
13
|
export { useTry as t };
|
|
15
|
-
//# sourceMappingURL=useTry-
|
|
14
|
+
//# sourceMappingURL=useTry-B0HIcFFb.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "React bindings for functype — ADT-aware hooks and exhaustive pattern matching components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"functype",
|
|
@@ -26,29 +26,34 @@
|
|
|
26
26
|
"directory": "packages/functype-react"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
29
30
|
"functype": ">=0.60.0",
|
|
30
31
|
"react": ">=18.0.0 <20.0.0",
|
|
31
32
|
"react-dom": ">=18.0.0 <20.0.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependenciesMeta": {
|
|
35
|
+
"@tanstack/react-query": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
34
38
|
"react-dom": {
|
|
35
39
|
"optional": true
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"devDependencies": {
|
|
43
|
+
"@tanstack/react-query": "^5.101.4",
|
|
39
44
|
"@testing-library/dom": "^10.4.1",
|
|
40
|
-
"@testing-library/jest-dom": "^6.
|
|
45
|
+
"@testing-library/jest-dom": "^6.10.0",
|
|
41
46
|
"@testing-library/react": "^16.3.2",
|
|
42
|
-
"@types/node": "^24.13.
|
|
47
|
+
"@types/node": "^24.13.3",
|
|
43
48
|
"@types/react": "^19.2.17",
|
|
44
49
|
"@types/react-dom": "^19.2.3",
|
|
45
|
-
"fast-check": "^4.
|
|
50
|
+
"fast-check": "^4.9.0",
|
|
46
51
|
"jsdom": "^26.1.0",
|
|
47
|
-
"react": "^19.2.
|
|
48
|
-
"react-dom": "^19.2.
|
|
49
|
-
"ts-builds": "^3.2.
|
|
50
|
-
"tsdown": "^0.22.
|
|
51
|
-
"functype": "^1.
|
|
52
|
+
"react": "^19.2.8",
|
|
53
|
+
"react-dom": "^19.2.8",
|
|
54
|
+
"ts-builds": "^3.2.3",
|
|
55
|
+
"tsdown": "^0.22.14",
|
|
56
|
+
"functype": "^1.7.0"
|
|
52
57
|
},
|
|
53
58
|
"type": "module",
|
|
54
59
|
"main": "./dist/index.js",
|
|
@@ -75,6 +80,11 @@
|
|
|
75
80
|
"types": "./dist/forms/index.d.ts",
|
|
76
81
|
"import": "./dist/forms/index.js",
|
|
77
82
|
"default": "./dist/forms/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./query": {
|
|
85
|
+
"types": "./dist/query/index.d.ts",
|
|
86
|
+
"import": "./dist/query/index.js",
|
|
87
|
+
"default": "./dist/query/index.js"
|
|
78
88
|
}
|
|
79
89
|
},
|
|
80
90
|
"files": [
|