@nkzw/fate-indexeddb 1.16.0 → 1.16.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.
Files changed (2) hide show
  1. package/README.md +20 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -71,7 +71,7 @@ Explore the [fate stack](https://fate.technology/#stack) to see the tools includ
71
71
 
72
72
  Choose a backend in the template selector: Void, tRPC with Drizzle or Prisma, GraphQL with Prisma, or a client for an existing GraphQL server. React is the default. Choose Vue in the selector or pass `--framework vue`.
73
73
 
74
- Choose **Client Only** or pass `--template client-only` to start with a static Void app that saves its data in IndexedDB. See [Persisting Client State](/docs/guide/client-state.md#persisting-client-state).
74
+ If you want to build an app entirely with client state, choose **Client Only** or pass `--template client-only`. This template includes Void Pages Routing and a task list saved in IndexedDB. Try editing a task and reloading the page to see persistence in action. See [Client State](/docs/guide/client-state.md).
75
75
 
76
76
  ### Manual Installation
77
77
 
@@ -1239,6 +1239,8 @@ fate does not provide hooks for mutations like traditional data fetching librari
1239
1239
 
1240
1240
  fate's Vite plugin makes your server mutations available on the client. The API works the same way with native HTTP, tRPC, GraphQL, and Void.
1241
1241
 
1242
+ You can also define mutations for [Client State](/docs/guide/client-state.md). Components call them through the same `fate.actions` and `fate.mutations` APIs.
1243
+
1242
1244
  If you have a mutation named `post.like`, a `LikeButton` component using fate Actions and an async component library could look like this:
1243
1245
 
1244
1246
  ```tsx
@@ -1353,6 +1355,8 @@ const result = await fate.mutations.comment.add({
1353
1355
 
1354
1356
  The options are the same as for Actions, including `optimistic`, `insert`, `remove`, `invalidate`, and `view`. The call returns a promise. Handle pending state and errors in the calling code.
1355
1357
 
1358
+ If a mutation doesn't take any input, you can omit the arguments entirely. For example, our [client counter](/docs/guide/client-state.md#reading-and-updating-state) increments with `fate.mutations.counter.increment()`. You can still pass options such as `{ view: CounterView }`. Actions take an options object, so dispatch the same mutation with `increment({})` inside a React Action or transition. Mutations that declare input fields still require `input`, even if every field is optional.
1359
+
1356
1360
  ### Mutation Server Implementation
1357
1361
 
1358
1362
  Define mutations in your backend and return the fields requested by the client. See [Server Integration](/docs/integrations/server.md#custom-mutations) for native HTTP and tRPC, [GraphQL Integration](/docs/integrations/graphql.md#mutations) for an existing GraphQL API, or [Void Integration](/docs/integrations/void.md) for a Void app.
@@ -1518,6 +1522,8 @@ When the mutation succeeds, fate marks the post's cached fields stale. A `cache-
1518
1522
 
1519
1523
  fate can keep data across page reloads and save mutations while a user is offline. When they come back, their views can show previously loaded data and their pending changes continue where they left off.
1520
1524
 
1525
+ The same persistence setup can save [Client State](/docs/guide/client-state.md#persisting-client-state), such as drafts or bookmarks. Client data stays saved when the remote cache expires or is cleared. You can use [migrations](/docs/guide/client-state.md#migrations) to update its shape as your app changes.
1526
+
1521
1527
  ### Client Setup
1522
1528
 
1523
1529
  For a browser app, install the IndexedDB adapter:
@@ -1606,7 +1612,7 @@ Pending mutations are never evicted to make room for cached data. If a new mutat
1606
1612
 
1607
1613
  ### Actions & Mutations
1608
1614
 
1609
- With persistence and a durable mutation transport configured, fate saves server mutations before applying their optimistic updates or sending them to the server. The API is the same as for regular [Actions](/docs/guide/actions.md):
1615
+ Let's say a user wants to like a post while offline. With persistence and a [durable mutation transport](#server-deduplication) configured, fate saves the mutation before applying its optimistic update or sending it to the server. We can use the same API as for regular [Actions](/docs/guide/actions.md):
1610
1616
 
1611
1617
  ```tsx
1612
1618
  const [result, like] = useActionState(fate.actions.post.like, null);
@@ -1712,7 +1718,11 @@ return idempotency.execute({
1712
1718
 
1713
1719
  Forward the entire identity on every attempt. When `identity.replayOnly` is true, the endpoint must return the saved result or a 404 without running the mutation. `createMutationIdempotency` handles this for you.
1714
1720
 
1715
- Without a durable adapter, server mutations send immediately by default. Use `persist: true` to require durable delivery. The call fails before sending if persistence or the adapter is missing. Existing queued mutations stay saved and report a delivery error until the adapter is available again. Remote read caching and client state persistence work independently of the adapter.
1721
+ For a GraphQL adapter that supports only some mutations, pass `durableMutations: ['setLocale', 'updateSettings']` alongside `mutateDurably`. Other mutations send immediately. Explicit `persist: true` fails for an unsupported mutation, and previously queued calls remain saved if the adapter stops supporting them. Omitting the list means the adapter supports every mutation.
1722
+
1723
+ You can use persistence for cached reads and client state before adding a durable mutation adapter. Server mutations send immediately by default in that setup. Pass `persist: true` when a call must be saved before delivery. It fails before sending if persistence or the adapter is missing.
1724
+
1725
+ Mutations that were already queued stay saved and report a delivery error until the adapter is available again.
1716
1726
 
1717
1727
  For GraphQL, return a standard `extensions.code` or numeric `extensions.http.status` for terminal client errors. Unrecognized execution errors remain retryable for saved mutations.
1718
1728
 
@@ -1767,7 +1777,7 @@ To remove the saved read cache, call `clearCache()`:
1767
1777
  await fate.persistence!.clearCache();
1768
1778
  ```
1769
1779
 
1770
- This leaves in-memory data and queued mutations intact.
1780
+ This leaves in-memory data, queued mutations, and saved client state intact. For example, clearing cached posts keeps the bookmarks defined in your client schema.
1771
1781
 
1772
1782
  Change `hydrationScope` when deploying incompatible data models or mutation inputs. Incompatible saved reads are discarded; incompatible queued mutations remain visible as failures so the app can handle them.
1773
1783
 
@@ -3109,7 +3119,7 @@ For Prisma, pass Prisma query options such as `{ where: { ... } }` in `extra` in
3109
3119
 
3110
3120
  ### Data View Resolvers
3111
3121
 
3112
- fate data views support computed fields. Use `computed` to describe the hidden data needed to resolve a public field.
3122
+ Data views can define computed fields with their own data dependencies. Let's say we want to show a user's email only to that user, and include a comment count on each post. We can define both fields with `computed`:
3113
3123
 
3114
3124
  ```tsx
3115
3125
  import { computed, count } from '@nkzw/fate/server';
@@ -3136,7 +3146,9 @@ export const postDataView = dataView<PostItem>('Post')({
3136
3146
  });
3137
3147
  ```
3138
3148
 
3139
- Set a dependency to `true` to select a field by the same name. Use `field('path')` for aliases or nested paths and `count('relation')` for relation counts. The adapters fetch these dependencies for you. This keeps private fields like `email` available to the resolver without exposing them to the client selection.
3149
+ The `select` object describes what each resolver needs. `email: true` selects the user's stored email, and `count('comments')` asks the adapter to count the post's comments. The resolver receives those values in its second argument. Annotating the first argument with `UserItem` or `PostItem` lets TypeScript infer the dependency types.
3150
+
3151
+ Use `field('path')` to give a dependency a different name or read through a relationship. The adapters fetch the dependencies for you, while the client only receives the computed field's result. The same `dataView` and `computed` helpers are available for [client computed fields](/docs/guide/client-state.md#computed-fields).
3140
3152
 
3141
3153
  ### Connecting the Client
3142
3154
 
@@ -3571,9 +3583,9 @@ See [Void's Cloudflare deployment guide](https://void.cloud/integrations/cloudfl
3571
3583
 
3572
3584
  ### Client-only Apps
3573
3585
 
3574
- Choose `--template client-only` when creating the app. The template uses Void Pages Routing and prerenders both routes as static shells. IndexedDB stores application data in each browser.
3586
+ You can also deploy an app built entirely with [Client State](/docs/guide/client-state.md). Choose `--template client-only` when creating the app. The template includes Void Pages Routing and saves each user's data in their browser with IndexedDB.
3575
3587
 
3576
- Run `vp exec void deploy --platform cloudflare` from the generated app to deploy the assets. You can also run `vp run build` and serve `dist/client/` from another static host that supports clean URLs.
3588
+ Run `vp exec void deploy --platform cloudflare` from the generated app to deploy its static pages and assets. You can also run `vp run build` and serve `dist/client/` from another static host that supports clean URLs.
3577
3589
 
3578
3590
  ### Migrating from cf-fate
3579
3591
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/fate-indexeddb",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Optional IndexedDB persistence adapter for fate.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "idb": "^8.0.4"
20
20
  },
21
21
  "devDependencies": {
22
- "@nkzw/fate": "1.16.0",
22
+ "@nkzw/fate": "1.16.1",
23
23
  "fake-indexeddb": "^6.2.7",
24
24
  "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
25
25
  "vite-plus": "1.5.0"