@nkzw/fate-indexeddb 2.0.0 → 2.0.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 +116 -0
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -2153,6 +2153,122 @@ Use Vue refs or your application state library to track pending and error state.
2153
2153
 
2154
2154
  Views, requests, caching, and mutations work the same way in both adapters. Vue composables return reactive resources; await `ready()` to use Suspense, or read their pending and error state. For mutations, use `fate.mutations` and Vue refs for local state instead of React Actions.
2155
2155
 
2156
+ ## Devtools
2157
+
2158
+ _fate_ comes with devtools that show what your client is doing while you build your app. They run as a panel in [Vite DevTools](https://devtools.vite.dev/), next to the other tools for your app.
2159
+
2160
+ <p align="center">
2161
+ <img alt="The fate devtools panel in Vite DevTools" src="/public/devtools.png#gh-light-mode-only" width="100%">
2162
+ <img alt="The fate devtools panel in Vite DevTools" src="/public/devtools-dark.png#gh-dark-mode-only" width="100%">
2163
+ </p>
2164
+
2165
+ The panel shows:
2166
+
2167
+ - **Cache:** every normalized record, grouped by type. For each record you can see the fields fate has loaded, which fields are stale, which lists contain it, and which records refer to it. Click a reference to jump to that record.
2168
+ - **Requests:** the requests your screens keep alive, their roots and arguments, the fields they select, and how many components are observing them.
2169
+ - **Network:** every call fate makes through its transport (`byId`, `list`, `query`, mutations, and live subscriptions), with timing, selections, arguments, and responses or errors.
2170
+ - **Lists:** connection and list state, including items, cursors, and pagination.
2171
+ - **Changes:** a log of cache writes, including invalidations and optimistic updates.
2172
+
2173
+ From the panel you can invalidate or remove a record, log a record to the browser console (as `$fate`), and run garbage collection.
2174
+
2175
+ ### Installation
2176
+
2177
+ Install the devtools and Vite DevTools as development dependencies of your client:
2178
+
2179
+ ::: code-group
2180
+
2181
+ ```bash [npm]
2182
+ npm add -D @nkzw/fate-devtools @vitejs/devtools
2183
+ ```
2184
+
2185
+ ```bash [pnpm]
2186
+ pnpm add -D @nkzw/fate-devtools @vitejs/devtools
2187
+ ```
2188
+
2189
+ ```bash [yarn]
2190
+ yarn add -D @nkzw/fate-devtools @vitejs/devtools
2191
+ ```
2192
+
2193
+ :::
2194
+
2195
+ ### Vite Plugin
2196
+
2197
+ Enable Vite DevTools and add the devtools plugin to your Vite config:
2198
+
2199
+ ```ts
2200
+ import { fateDevtools } from '@nkzw/fate-devtools/vite';
2201
+ import { fate } from 'react-fate/vite';
2202
+ import { defineConfig } from 'vite';
2203
+
2204
+ export default defineConfig({
2205
+ devtools: true,
2206
+ plugins: [
2207
+ fate({
2208
+ module: '@your-org/server/trpc/router.ts',
2209
+ }),
2210
+ fateDevtools(),
2211
+ ],
2212
+ });
2213
+ ```
2214
+
2215
+ The plugin only runs during development. It adds a _fate_ entry to the Vite DevTools dock and serves the panel at `/__fate-devtools/`. You can also open that URL in its own tab, which is handy when you don't use Vite DevTools or want the panel on a second screen.
2216
+
2217
+ ### Connecting a Client
2218
+
2219
+ With React, render `<FateDevtools />` inside your `<FateClient>`. It connects the client from context and renders nothing:
2220
+
2221
+ ```tsx
2222
+ import { FateDevtools } from '@nkzw/fate-devtools/react';
2223
+ import { FateClient } from 'react-fate';
2224
+
2225
+ export function App() {
2226
+ return (
2227
+ <FateClient client={fate}>
2228
+ {import.meta.env.DEV && <FateDevtools />}
2229
+ <Root />
2230
+ </FateClient>
2231
+ );
2232
+ }
2233
+ ```
2234
+
2235
+ For Vue or other setups, call `connectFateDevtools` with your client. It returns a function that disconnects the client again:
2236
+
2237
+ ```ts
2238
+ import { connectFateDevtools } from '@nkzw/fate-devtools';
2239
+
2240
+ if (import.meta.env.DEV) {
2241
+ connectFateDevtools(fate);
2242
+ }
2243
+ ```
2244
+
2245
+ Guard the devtools with `import.meta.env.DEV` so they are not included in production builds. If your app creates more than one client, pass a `name` to tell them apart in the panel:
2246
+
2247
+ ```tsx
2248
+ <FateDevtools name="admin" />
2249
+ ```
2250
+
2251
+ ### Server-Rendered Apps
2252
+
2253
+ Vite DevTools adds its dock to pages through Vite's HTML transform. Frameworks that render HTML on the server, such as [Void](/docs/integrations/void.md), don't run that transform, so load the dock yourself in development:
2254
+
2255
+ ```ts
2256
+ if (import.meta.env.DEV && typeof document !== 'undefined') {
2257
+ const script = document.createElement('script');
2258
+ script.type = 'module';
2259
+ script.src = '/__devtools/embedded.js';
2260
+ document.head.append(script);
2261
+ }
2262
+ ```
2263
+
2264
+ The first time you open Vite DevTools in a browser, it asks you to authorize that browser with a code printed in your terminal.
2265
+
2266
+ ### How It Works
2267
+
2268
+ The devtools don't change how _fate_ behaves. When you connect a client, the devtools wrap its transport to record network activity and listen to cache changes. The page then sends snapshots to the panel over a [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel). Snapshots are only sent while a panel is open. When you disconnect, the client's original transport is restored.
2269
+
2270
+ Because the panel and your app talk over a `BroadcastChannel`, the panel works anywhere on the same origin: in the Vite DevTools dock, in a separate tab, or in a popup. When more than one page or client is connected, use the picker in the panel's toolbar to switch between them.
2271
+
2156
2272
  ## GraphQL Integration
2157
2273
 
2158
2274
  If your backend already exposes GraphQL, you can use it with fate. Define views and call requests and mutations as usual; fate builds the GraphQL operations for you.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/fate-indexeddb",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Optional IndexedDB persistence adapter for fate.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -19,12 +19,12 @@
19
19
  "idb": "^8.0.4"
20
20
  },
21
21
  "devDependencies": {
22
- "@nkzw/fate": "2.0.0",
22
+ "@nkzw/fate": "2.0.1",
23
23
  "fake-indexeddb": "^6.2.8",
24
24
  "vite": "npm:@voidzero-dev/vite-plus-core@1.6.0",
25
25
  "vite-plus": "1.6.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "@nkzw/fate": "^1.5.1"
28
+ "@nkzw/fate": "^2.0.0"
29
29
  }
30
30
  }