react-fate 0.0.6 → 0.0.7
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 +5 -2
- package/lib/index.d.mts +8 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -526,6 +526,7 @@ Let's assume that our `Post` entity has a tRPC mutation for liking a post called
|
|
|
526
526
|
|
|
527
527
|
```tsx
|
|
528
528
|
const LikeButton = ({ post }: { post: { id: string; likes: number } }) => {
|
|
529
|
+
const fate = useFateClient();
|
|
529
530
|
const [result, like] = useActionState(fate.actions.post.like, null);
|
|
530
531
|
|
|
531
532
|
return (
|
|
@@ -540,6 +541,7 @@ If you are not using an async component library, you can use React's `useTransit
|
|
|
540
541
|
|
|
541
542
|
```tsx
|
|
542
543
|
const LikeButton = ({ post }: { post: { id: string; likes: number } }) => {
|
|
544
|
+
const fate = useFateClient();
|
|
543
545
|
const [, startTransition] = useTransition();
|
|
544
546
|
const [result, like, isPending] = useActionState(
|
|
545
547
|
fate.actions.post.like,
|
|
@@ -959,10 +961,10 @@ export type AppRouter = typeof appRouter;
|
|
|
959
961
|
export * from './views.ts';
|
|
960
962
|
```
|
|
961
963
|
|
|
962
|
-
_Note: We try to keep magic to a minimum and you can handwrite the [generated client](https://github.com/nkzw-tech/fate/blob/main/example/client/src/
|
|
964
|
+
_Note: We try to keep magic to a minimum and you can handwrite the [generated client](https://github.com/nkzw-tech/fate/blob/main/example/client/src/fate.ts) if you prefer._
|
|
963
965
|
|
|
964
966
|
```bash
|
|
965
|
-
pnpm fate generate @your-org/server/trpc/router.ts client/src/
|
|
967
|
+
pnpm fate generate @your-org/server/trpc/router.ts client/src/fate.ts
|
|
966
968
|
```
|
|
967
969
|
|
|
968
970
|
_Note: fate uses the specified server module name to extract the server types it needs and uses the same module name to import the views into the generated client. Make sure that the module is available both at the root where you are running the CLI and in the client package._
|
|
@@ -1041,5 +1043,6 @@ Probably. One day. _Maybe._
|
|
|
1041
1043
|
|
|
1042
1044
|
- [Relay](https://relay.dev/), [Isograph](https://isograph.dev/) & [GraphQL](https://graphql.org/) for inspiration
|
|
1043
1045
|
- [Ricky Hanlon](https://x.com/rickyfm) for guidance on Async React
|
|
1046
|
+
- [Anthony Powell](https://x.com/Cephalization) for testing fate and providing feedback
|
|
1044
1047
|
|
|
1045
1048
|
**_fate_** was created by [@cnakazawa](https://x.com/cnakazawa) and is maintained by [Nakazawa Tech](https://nakazawa.tech/).
|
package/lib/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ConnectionRef, FateClient as FateClient$1, Pagination, Request, RequestOptions, RequestResult, View, ViewData, ViewEntity, ViewEntityName, ViewRef, ViewRef as ViewRef$1, ViewSelection, createClient, createTRPCTransport, mutation, view } from "@nkzw/fate";
|
|
1
|
+
import { ConnectionRef, FateClient as FateClient$1, FateMutations, Pagination, Request, RequestOptions, RequestResult, View, ViewData, ViewEntity, ViewEntityName, ViewRef, ViewRef as ViewRef$1, ViewSelection, createClient, createTRPCTransport, mutation, view } from "@nkzw/fate";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
4
|
|
|
5
5
|
//#region src/context.d.ts
|
|
6
|
+
type Mutations = keyof ClientMutations extends never ? FateMutations : ClientMutations;
|
|
6
7
|
/**
|
|
7
8
|
* Provider component that supplies a configured `FateClient` to React hooks.
|
|
8
9
|
*/
|
|
@@ -11,12 +12,12 @@ declare function FateClient({
|
|
|
11
12
|
client
|
|
12
13
|
}: {
|
|
13
14
|
children: ReactNode;
|
|
14
|
-
client: FateClient$1
|
|
15
|
+
client: FateClient$1<any>;
|
|
15
16
|
}): react_jsx_runtime0.JSX.Element;
|
|
16
17
|
/**
|
|
17
18
|
* Returns the nearest `FateClient` from context.
|
|
18
19
|
*/
|
|
19
|
-
declare function useFateClient(): FateClient$1
|
|
20
|
+
declare function useFateClient<M extends Mutations>(): FateClient$1<M>;
|
|
20
21
|
//#endregion
|
|
21
22
|
//#region src/useView.d.ts
|
|
22
23
|
type ViewEntityWithTypename<V extends View<any, any>> = ViewEntity<V> & {
|
|
@@ -59,4 +60,7 @@ declare function useListView<C extends {
|
|
|
59
60
|
pagination?: Pagination;
|
|
60
61
|
} | null | undefined>(selection: ConnectionSelection, connection: C): [ConnectionItems<NonNullable<C>>, LoadMoreFn | null, LoadMoreFn | null];
|
|
61
62
|
//#endregion
|
|
62
|
-
|
|
63
|
+
//#region src/index.d.ts
|
|
64
|
+
interface ClientMutations {}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { ClientMutations, type ConnectionRef, FateClient, type ViewRef, createClient, createTRPCTransport, mutation, useFateClient, useListView, useRequest, useView, view };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-fate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "fate is a modern data client for React.",
|
|
5
5
|
"homepage": "https://github.com/nkzw-tech/fate",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lib"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@nkzw/fate": "^0.0.
|
|
31
|
+
"@nkzw/fate": "^0.0.7"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/react": "^19.2.7",
|