eden2query 0.1.0 → 0.1.1
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 +10 -5
- package/dist/index.d.ts +1270 -21
- package/dist/index.js +21 -28
- package/dist/index.js.map +1 -0
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -17,10 +17,10 @@ import type { App } from "./server"; // your Elysia app type
|
|
|
17
17
|
|
|
18
18
|
const client = treaty<App>("localhost:3000");
|
|
19
19
|
|
|
20
|
-
// GET → queryOptions
|
|
20
|
+
// GET → queryOptions (fn is a thunk that calls the Eden GET function)
|
|
21
21
|
const resourceQuery = treatyQueryOptions({
|
|
22
22
|
queryKey: ["resource"],
|
|
23
|
-
fn: client.api.resource.get,
|
|
23
|
+
fn: () => client.api.resource.get({ query: { q: "hello" } }),
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
// POST / PUT / DELETE → mutationOptions
|
|
@@ -43,14 +43,19 @@ const mutation = useMutation(createResource);
|
|
|
43
43
|
mutation.mutate({ name: "New item" }); // fully typed input
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
Works with `prefetchQuery`, `ensureQueryData`, `useSuspenseQuery`, etc
|
|
46
|
+
Works with `prefetchQuery`, `ensureQueryData`, `useSuspenseQuery`, etc:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const queryClient = new QueryClient();
|
|
50
|
+
await queryClient.prefetchQuery(resourceQuery);
|
|
51
|
+
```
|
|
47
52
|
|
|
48
53
|
You can also pass any standard React Query options alongside `fn`:
|
|
49
54
|
|
|
50
55
|
```ts
|
|
51
56
|
const resourceQuery = treatyQueryOptions({
|
|
52
57
|
queryKey: ["resource"],
|
|
53
|
-
fn: client.api.resource.get,
|
|
58
|
+
fn: () => client.api.resource.get({ query: { q: "hello" } }),
|
|
54
59
|
refetchInterval: 1000,
|
|
55
60
|
});
|
|
56
61
|
|
|
@@ -62,7 +67,7 @@ const createResource = treatyMutationOptions({
|
|
|
62
67
|
|
|
63
68
|
## API
|
|
64
69
|
|
|
65
|
-
**`treatyQueryOptions({ queryKey, fn, ...queryOptions })`** — wraps an Eden GET
|
|
70
|
+
**`treatyQueryOptions({ queryKey, fn, ...queryOptions })`** — wraps an Eden GET call into `queryOptions`. `fn` is a **thunk** (zero-argument function) that calls the Eden GET function, e.g. `() => client.api.resource.get({ query: { ... } })`. This lets you bind query parameters, headers, or any other Eden options at definition time. Accepts all `queryOptions` fields except `queryFn`. Extracts `data` from the response and throws on `error`.
|
|
66
71
|
|
|
67
72
|
**`treatyMutationOptions({ fn, ...mutationOptions })`** — wraps an Eden mutation function into `mutationOptions`. Accepts all `mutationOptions` fields except `mutationFn` (e.g. `onSuccess`, `onSettled`, `onMutate`). The `mutate` call accepts the same input the Eden function expects.
|
|
68
73
|
|