@nkzw/fate-indexeddb 1.5.2 → 1.6.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 +56 -168
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ _[Learn more](/docs/guide/getting-started.md) about fate's core concepts or crea
|
|
|
65
65
|
Create a new fate app with Vite+:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
vp create fate
|
|
68
|
+
vp create fate
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Explore the [fate stack](https://stack.fate.technology) to see the tools included in your new project.
|
|
@@ -128,14 +128,6 @@ yarn add @nkzw/fate
|
|
|
128
128
|
|
|
129
129
|
:::
|
|
130
130
|
|
|
131
|
-
> [!WARNING]
|
|
132
|
-
>
|
|
133
|
-
> **_fate_** is currently in alpha and not production ready. If something doesn't work for you, please open a pull request.
|
|
134
|
-
|
|
135
|
-
If you'd like to try the example app in GitHub Codespaces, click the button below:
|
|
136
|
-
|
|
137
|
-
[](https://github.com/codespaces/new?repo=nkzw-tech/fate)
|
|
138
|
-
|
|
139
131
|
## Core Concepts
|
|
140
132
|
|
|
141
133
|
**_fate_** has a minimal API surface and is aimed at reducing data fetching complexity.
|
|
@@ -1926,13 +1918,13 @@ Use the GraphQL transport when your backend already exposes GraphQL and you want
|
|
|
1926
1918
|
Create a client for an existing GraphQL server with:
|
|
1927
1919
|
|
|
1928
1920
|
```bash
|
|
1929
|
-
vp create fate
|
|
1921
|
+
vp create fate -- --template graphql-client
|
|
1930
1922
|
```
|
|
1931
1923
|
|
|
1932
1924
|
Create a full GraphQL + Prisma example app with:
|
|
1933
1925
|
|
|
1934
1926
|
```bash
|
|
1935
|
-
vp create fate
|
|
1927
|
+
vp create fate -- --template graphql
|
|
1936
1928
|
```
|
|
1937
1929
|
|
|
1938
1930
|
The client-only template is the smallest reference for the integration. It contains a `src/fate/graphql.ts` file that maps your GraphQL schema to fate views and roots.
|
|
@@ -2995,7 +2987,7 @@ _And you are all set. Happy building!_
|
|
|
2995
2987
|
|
|
2996
2988
|
## Void Integration
|
|
2997
2989
|
|
|
2998
|
-
`void-fate` is the
|
|
2990
|
+
`void-fate` is the [Void](https://void.cloud) adapter for fate. Deploy your app directly to your own Cloudflare account or to the Void platform with the same integration.
|
|
2999
2991
|
|
|
3000
2992
|
Use this integration when your app runs on Void and you want the example app's
|
|
3001
2993
|
setup without copying its adapter glue.
|
|
@@ -3005,13 +2997,13 @@ setup without copying its adapter glue.
|
|
|
3005
2997
|
For a new Void app, start from the Void template. It includes the client, Void routes, Drizzle setup, live transport, auth wiring, and generated fate client setup.
|
|
3006
2998
|
|
|
3007
2999
|
```sh
|
|
3008
|
-
vp create fate
|
|
3000
|
+
vp create fate -- --template void
|
|
3009
3001
|
```
|
|
3010
3002
|
|
|
3011
3003
|
Use Vue instead of React with:
|
|
3012
3004
|
|
|
3013
3005
|
```sh
|
|
3014
|
-
vp create fate
|
|
3006
|
+
vp create fate -- --template void --framework vue
|
|
3015
3007
|
```
|
|
3016
3008
|
|
|
3017
3009
|
### Existing Project
|
|
@@ -3122,14 +3114,29 @@ live.connection('Post.comments', { id: postId }).appendNode('Comment', commentId
|
|
|
3122
3114
|
|
|
3123
3115
|
### Routes
|
|
3124
3116
|
|
|
3117
|
+
Define a live stream once in a server-only module:
|
|
3118
|
+
|
|
3119
|
+
```ts
|
|
3120
|
+
// src/fate/live.ts
|
|
3121
|
+
import { defineLiveStream } from 'void/live';
|
|
3122
|
+
|
|
3123
|
+
export const fateStream = defineLiveStream({
|
|
3124
|
+
allowAnonymousControl: true,
|
|
3125
|
+
id: 'fate',
|
|
3126
|
+
});
|
|
3127
|
+
```
|
|
3128
|
+
|
|
3125
3129
|
Add one route for fate RPC requests:
|
|
3126
3130
|
|
|
3127
3131
|
```tsx
|
|
3128
3132
|
// routes/fate.ts
|
|
3129
3133
|
import { defineVoidFateRoute } from 'void-fate/server';
|
|
3134
|
+
import { fateStream } from '../src/fate/live.ts';
|
|
3130
3135
|
import { fateLive, fateServer } from '../src/fate/server.ts';
|
|
3131
3136
|
|
|
3132
|
-
export const { GET, POST } = defineVoidFateRoute(fateServer, fateLive
|
|
3137
|
+
export const { GET, POST } = defineVoidFateRoute(fateServer, fateLive, {
|
|
3138
|
+
stream: fateStream,
|
|
3139
|
+
});
|
|
3133
3140
|
```
|
|
3134
3141
|
|
|
3135
3142
|
Add a second route for the live SSE transport:
|
|
@@ -3137,9 +3144,9 @@ Add a second route for the live SSE transport:
|
|
|
3137
3144
|
```tsx
|
|
3138
3145
|
// routes/fate-live.ts
|
|
3139
3146
|
import { defineVoidFateLiveRoute } from 'void-fate/server';
|
|
3140
|
-
import {
|
|
3147
|
+
import { fateStream } from '../src/fate/live.ts';
|
|
3141
3148
|
|
|
3142
|
-
export const { GET, POST } = defineVoidFateLiveRoute(
|
|
3149
|
+
export const { GET, POST } = defineVoidFateLiveRoute(fateStream);
|
|
3143
3150
|
```
|
|
3144
3151
|
|
|
3145
3152
|
The live route handles `GET /fate-live` SSE connections and `POST /fate-live`
|
|
@@ -3205,13 +3212,7 @@ present.
|
|
|
3205
3212
|
### Custom Paths
|
|
3206
3213
|
|
|
3207
3214
|
The default route pair is `/fate` and `/fate-live`. If your Void app uses
|
|
3208
|
-
different paths,
|
|
3209
|
-
|
|
3210
|
-
```tsx
|
|
3211
|
-
export const fateLive = createVoidFateLive({
|
|
3212
|
-
livePath: '/custom-fate-live',
|
|
3213
|
-
});
|
|
3214
|
-
```
|
|
3215
|
+
different paths, update your route filenames and configure the matching client paths.
|
|
3215
3216
|
|
|
3216
3217
|
::: code-group
|
|
3217
3218
|
|
|
@@ -3247,179 +3248,66 @@ or router configuration matches the paths you pass to the client.
|
|
|
3247
3248
|
|
|
3248
3249
|
### Live Transport
|
|
3249
3250
|
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
In local development, `void-fate` uses a development token for that internal
|
|
3255
|
-
publish request. Outside local development, Void must provide `__VOID_PROXY_TOKEN`
|
|
3256
|
-
in the route environment. If no internal publish token is available, the adapter
|
|
3257
|
-
falls back to the in-memory live bus for the current request context.
|
|
3251
|
+
`createVoidFateLive` publishes entity and connection events through the `void/live`
|
|
3252
|
+
stream associated with the current request. Void manages the Durable Object
|
|
3253
|
+
transport that distributes events to connected clients across requests.
|
|
3258
3254
|
|
|
3259
3255
|
The live transport is best-effort and does not replay missed events after a
|
|
3260
3256
|
client reconnects. This matches fate's default in-memory live event bus.
|
|
3261
3257
|
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
`cf-fate` is the first-class Cloudflare Workers adapter for Fate native HTTP transport and live views.
|
|
3258
|
+
### Cloudflare Deployment
|
|
3265
3259
|
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
### New Project
|
|
3269
|
-
|
|
3270
|
-
For a new Cloudflare Workers app, start from the Cloudflare template. It includes the client, Worker server, D1 migrations, Wrangler config, Durable Object live transport, auth wiring, and generated fate client setup.
|
|
3260
|
+
From your project root, run:
|
|
3271
3261
|
|
|
3272
3262
|
```sh
|
|
3273
|
-
vp
|
|
3263
|
+
vp exec void deploy --platform cloudflare
|
|
3274
3264
|
```
|
|
3275
3265
|
|
|
3276
|
-
|
|
3266
|
+
Void provisions resources and deploys directly to your Cloudflare account. See the [Cloudflare integration](/docs/integrations/cloudflare.md) for setup and migration instructions.
|
|
3277
3267
|
|
|
3278
|
-
|
|
3279
|
-
vp create fate my-app --template cloudflare --framework vue
|
|
3280
|
-
```
|
|
3268
|
+
## Cloudflare Integration
|
|
3281
3269
|
|
|
3282
|
-
|
|
3270
|
+
Deploy fate directly to your own Cloudflare account with [Void](/docs/integrations/void.md). The Void template includes the app, D1 database, Drizzle migrations, Better Auth, and live updates through `void-fate` and `void/live`.
|
|
3283
3271
|
|
|
3284
|
-
|
|
3272
|
+
### New Project
|
|
3285
3273
|
|
|
3286
3274
|
```sh
|
|
3287
|
-
|
|
3288
|
-
|
|
3275
|
+
vp create fate -- my-app --template void
|
|
3276
|
+
cd my-app
|
|
3277
|
+
vp run dev:setup
|
|
3278
|
+
vp run dev
|
|
3289
3279
|
```
|
|
3290
3280
|
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
### Server Setup
|
|
3294
|
-
|
|
3295
|
-
Create a Cloudflare live stream and pass its Fate live facade to `createFateServer`.
|
|
3281
|
+
Add `--framework vue` to the create command to use Vue instead of React.
|
|
3296
3282
|
|
|
3297
|
-
|
|
3298
|
-
// src/fate/live.ts
|
|
3299
|
-
import { defineCloudflareFateLiveStream } from 'cf-fate/server';
|
|
3283
|
+
### Deploy
|
|
3300
3284
|
|
|
3301
|
-
|
|
3302
|
-
allowAnonymousControl: true,
|
|
3303
|
-
binding: 'FATE_LIVE',
|
|
3304
|
-
id: 'fate',
|
|
3305
|
-
});
|
|
3306
|
-
```
|
|
3285
|
+
From the project root:
|
|
3307
3286
|
|
|
3308
|
-
```
|
|
3309
|
-
|
|
3310
|
-
import { createFateServer } from '@nkzw/fate/server';
|
|
3311
|
-
import { createCloudflareFateLive } from 'cf-fate/server';
|
|
3312
|
-
|
|
3313
|
-
export const fateLive = createCloudflareFateLive();
|
|
3314
|
-
export const { live } = fateLive;
|
|
3315
|
-
|
|
3316
|
-
export const fateServer = createFateServer({
|
|
3317
|
-
live,
|
|
3318
|
-
// context,
|
|
3319
|
-
// roots,
|
|
3320
|
-
// sources,
|
|
3321
|
-
});
|
|
3322
|
-
```
|
|
3323
|
-
|
|
3324
|
-
Publish from mutations through the normal Fate live bus:
|
|
3325
|
-
|
|
3326
|
-
```ts
|
|
3327
|
-
live.update('Post', postId, { changed: ['likes'] });
|
|
3328
|
-
live.connection('Post.comments', { id: postId }).appendNode('Comment', commentId);
|
|
3329
|
-
```
|
|
3330
|
-
|
|
3331
|
-
### Worker Routes
|
|
3332
|
-
|
|
3333
|
-
Expose one route for Fate RPC and one route for the SSE live stream.
|
|
3334
|
-
|
|
3335
|
-
```ts
|
|
3336
|
-
import {
|
|
3337
|
-
createCloudflareFateLiveDurableObject,
|
|
3338
|
-
defineCloudflareFateLiveRoute,
|
|
3339
|
-
defineCloudflareFateRoute,
|
|
3340
|
-
} from 'cf-fate/server';
|
|
3341
|
-
import { fateStream } from './fate/live';
|
|
3342
|
-
import { fateLive, fateServer } from './fate/server';
|
|
3343
|
-
|
|
3344
|
-
const fateRoute = defineCloudflareFateRoute(fateServer, fateLive, { stream: fateStream });
|
|
3345
|
-
const fateLiveRoute = defineCloudflareFateLiveRoute(fateStream);
|
|
3346
|
-
|
|
3347
|
-
export const FateLiveDurableObject = createCloudflareFateLiveDurableObject({
|
|
3348
|
-
binding: 'FATE_LIVE',
|
|
3349
|
-
});
|
|
3350
|
-
|
|
3351
|
-
export default {
|
|
3352
|
-
fetch(request, env, ctx) {
|
|
3353
|
-
const url = new URL(request.url);
|
|
3354
|
-
if (url.pathname === '/fate') {
|
|
3355
|
-
return fateRoute.fetch(request, env, ctx);
|
|
3356
|
-
}
|
|
3357
|
-
if (url.pathname === '/fate-live') {
|
|
3358
|
-
return fateLiveRoute.fetch(request, env, ctx);
|
|
3359
|
-
}
|
|
3360
|
-
return new Response('Not Found', { status: 404 });
|
|
3361
|
-
},
|
|
3362
|
-
};
|
|
3363
|
-
```
|
|
3364
|
-
|
|
3365
|
-
### Wrangler
|
|
3366
|
-
|
|
3367
|
-
Add a Durable Object binding and migration. `cf-fate` uses `node:async_hooks`, so the Worker must enable Node compatibility.
|
|
3368
|
-
|
|
3369
|
-
```jsonc
|
|
3370
|
-
{
|
|
3371
|
-
"compatibility_flags": ["nodejs_compat"],
|
|
3372
|
-
"durable_objects": {
|
|
3373
|
-
"bindings": [
|
|
3374
|
-
{
|
|
3375
|
-
"name": "FATE_LIVE",
|
|
3376
|
-
"class_name": "FateLiveDurableObject",
|
|
3377
|
-
},
|
|
3378
|
-
],
|
|
3379
|
-
},
|
|
3380
|
-
"migrations": [
|
|
3381
|
-
{
|
|
3382
|
-
"tag": "fate-live-v1",
|
|
3383
|
-
"new_sqlite_classes": ["FateLiveDurableObject"],
|
|
3384
|
-
},
|
|
3385
|
-
],
|
|
3386
|
-
}
|
|
3287
|
+
```sh
|
|
3288
|
+
vp exec void deploy --platform cloudflare
|
|
3387
3289
|
```
|
|
3388
3290
|
|
|
3389
|
-
|
|
3291
|
+
Void signs you into Cloudflare when needed, lets you select your account, provisions resources, applies checked-in database migrations, and deploys the app. It saves resource IDs in the root `wrangler.jsonc`; commit that updated config for subsequent deployments. A Void platform account is not required.
|
|
3390
3292
|
|
|
3391
|
-
|
|
3293
|
+
The template includes the `VOID_LIVE` Durable Object binding and its class migration. Keep them in `wrangler.jsonc` so live subscriptions can receive updates across requests. RPC requests use `/fate`, and live updates use `/fate-live`.
|
|
3392
3294
|
|
|
3393
|
-
|
|
3394
|
-
import { fate } from 'react-fate/vite';
|
|
3295
|
+
After changing your database schema or auth configuration, run `vp run db:generate`, review and commit the generated migrations, then deploy. The migrations must include the Better Auth schema used in production.
|
|
3395
3296
|
|
|
3396
|
-
|
|
3397
|
-
module: './src/fate/server.ts',
|
|
3398
|
-
transport: 'cloudflare',
|
|
3399
|
-
});
|
|
3400
|
-
```
|
|
3401
|
-
|
|
3402
|
-
Then point the generated client at the Worker endpoints:
|
|
3403
|
-
|
|
3404
|
-
```tsx
|
|
3405
|
-
import { FateClient } from 'react-fate';
|
|
3406
|
-
import { createFateClient } from 'react-fate/client';
|
|
3297
|
+
See [Void's Cloudflare deployment guide](https://void.cloud/integrations/cloudflare) for custom domains, secrets, and CI configuration.
|
|
3407
3298
|
|
|
3408
|
-
|
|
3409
|
-
liveUrl: 'http://localhost:8787/fate-live',
|
|
3410
|
-
url: 'http://localhost:8787/fate',
|
|
3411
|
-
});
|
|
3299
|
+
### Migrating from cf-fate
|
|
3412
3300
|
|
|
3413
|
-
|
|
3414
|
-
return <FateClient client={fate}>{children}</FateClient>;
|
|
3415
|
-
}
|
|
3416
|
-
```
|
|
3301
|
+
Fate 1.6 replaces the standalone Cloudflare adapter and template with the Void integration. Use `--template void` for new projects and `transport: 'void'` in the fate Vite plugin.
|
|
3417
3302
|
|
|
3418
|
-
|
|
3303
|
+
For an existing app, move the Worker routes into Void's `routes/` directory and follow the [Void integration](/docs/integrations/void.md) for the complete setup:
|
|
3419
3304
|
|
|
3420
|
-
|
|
3305
|
+
- Define the live stream with `defineLiveStream` from `void/live`.
|
|
3306
|
+
- Use `createVoidFateLive`, `defineVoidFateRoute`, and `defineVoidFateLiveRoute` from `void-fate/server`.
|
|
3307
|
+
- Let the generated client use `void/live/client` for live connections.
|
|
3308
|
+
- Remove the `cf-fate` dependency and the custom Worker entry point.
|
|
3421
3309
|
|
|
3422
|
-
|
|
3310
|
+
Deploy the Void app as a new Worker with its `VOID_LIVE` binding and class migration. The old `FATE_LIVE` Durable Object class and its active connections are not migrated. Preserve existing database IDs and migration history when reusing your database, and reconnect clients to the new app after deployment.
|
|
3423
3311
|
|
|
3424
3312
|
## Frequently Asked Questions
|
|
3425
3313
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/fate-indexeddb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Optional IndexedDB persistence adapter for fate.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"idb": "^8.0.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nkzw/fate": "
|
|
22
|
+
"@nkzw/fate": "1.6.1",
|
|
23
23
|
"fake-indexeddb": "^6.2.5",
|
|
24
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.
|
|
25
|
-
"vite-plus": "0.3.
|
|
24
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
|
|
25
|
+
"vite-plus": "0.3.3"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@nkzw/fate": "^1.5.1"
|