react-fate 0.0.5 → 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 +7 -6
- 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,
|
|
@@ -766,7 +768,7 @@ Since clients can send arbitrary selection objects to the server, we need to imp
|
|
|
766
768
|
Create a `views.ts` file next to your root tRPC router that exports the data views for each type. Here is how you can define a `User` data view for Prisma's `User` model:
|
|
767
769
|
|
|
768
770
|
```tsx
|
|
769
|
-
import { dataView,
|
|
771
|
+
import { dataView, type Entity } from '@nkzw/fate/server';
|
|
770
772
|
import type { User as PrismaUser } from '../prisma/prisma-client/client.ts';
|
|
771
773
|
|
|
772
774
|
export const userDataView = dataView<PrismaUser>('User')({
|
|
@@ -775,9 +777,7 @@ export const userDataView = dataView<PrismaUser>('User')({
|
|
|
775
777
|
username: true,
|
|
776
778
|
});
|
|
777
779
|
|
|
778
|
-
export type User =
|
|
779
|
-
__typename: 'User';
|
|
780
|
-
};
|
|
780
|
+
export type User = Entity<typeof userDataView, 'User'>;
|
|
781
781
|
```
|
|
782
782
|
|
|
783
783
|
_Note: Currently, fate provides helpers to integrate with Prisma, but the framework is not coupled to any particular ORM or database. We hope to provide more direct integrations in the future, and are always open to contributions._
|
|
@@ -961,10 +961,10 @@ export type AppRouter = typeof appRouter;
|
|
|
961
961
|
export * from './views.ts';
|
|
962
962
|
```
|
|
963
963
|
|
|
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/
|
|
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._
|
|
965
965
|
|
|
966
966
|
```bash
|
|
967
|
-
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
|
|
968
968
|
```
|
|
969
969
|
|
|
970
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._
|
|
@@ -1043,5 +1043,6 @@ Probably. One day. _Maybe._
|
|
|
1043
1043
|
|
|
1044
1044
|
- [Relay](https://relay.dev/), [Isograph](https://isograph.dev/) & [GraphQL](https://graphql.org/) for inspiration
|
|
1045
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
|
|
1046
1047
|
|
|
1047
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",
|