@nkzw/fate-indexeddb 1.5.2 → 1.6.0

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 +51 -155
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -2995,7 +2995,7 @@ _And you are all set. Happy building!_
2995
2995
 
2996
2996
  ## Void Integration
2997
2997
 
2998
- `void-fate` is the first-class [Void](https://void.cloud) adapter for fate to ease integration with the Void SDK and for deploying to the Void platform.
2998
+ `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
2999
 
3000
3000
  Use this integration when your app runs on Void and you want the example app's
3001
3001
  setup without copying its adapter glue.
@@ -3122,14 +3122,29 @@ live.connection('Post.comments', { id: postId }).appendNode('Comment', commentId
3122
3122
 
3123
3123
  ### Routes
3124
3124
 
3125
+ Define a live stream once in a server-only module:
3126
+
3127
+ ```ts
3128
+ // src/fate/live.ts
3129
+ import { defineLiveStream } from 'void/live';
3130
+
3131
+ export const fateStream = defineLiveStream({
3132
+ allowAnonymousControl: true,
3133
+ id: 'fate',
3134
+ });
3135
+ ```
3136
+
3125
3137
  Add one route for fate RPC requests:
3126
3138
 
3127
3139
  ```tsx
3128
3140
  // routes/fate.ts
3129
3141
  import { defineVoidFateRoute } from 'void-fate/server';
3142
+ import { fateStream } from '../src/fate/live.ts';
3130
3143
  import { fateLive, fateServer } from '../src/fate/server.ts';
3131
3144
 
3132
- export const { GET, POST } = defineVoidFateRoute(fateServer, fateLive);
3145
+ export const { GET, POST } = defineVoidFateRoute(fateServer, fateLive, {
3146
+ stream: fateStream,
3147
+ });
3133
3148
  ```
3134
3149
 
3135
3150
  Add a second route for the live SSE transport:
@@ -3137,9 +3152,9 @@ Add a second route for the live SSE transport:
3137
3152
  ```tsx
3138
3153
  // routes/fate-live.ts
3139
3154
  import { defineVoidFateLiveRoute } from 'void-fate/server';
3140
- import { fateLive, fateServer } from '../src/fate/server.ts';
3155
+ import { fateStream } from '../src/fate/live.ts';
3141
3156
 
3142
- export const { GET, POST } = defineVoidFateLiveRoute(fateServer, fateLive);
3157
+ export const { GET, POST } = defineVoidFateLiveRoute(fateStream);
3143
3158
  ```
3144
3159
 
3145
3160
  The live route handles `GET /fate-live` SSE connections and `POST /fate-live`
@@ -3205,13 +3220,7 @@ present.
3205
3220
  ### Custom Paths
3206
3221
 
3207
3222
  The default route pair is `/fate` and `/fate-live`. If your Void app uses
3208
- different paths, configure the same values on the live adapter and client.
3209
-
3210
- ```tsx
3211
- export const fateLive = createVoidFateLive({
3212
- livePath: '/custom-fate-live',
3213
- });
3214
- ```
3223
+ different paths, update your route filenames and configure the matching client paths.
3215
3224
 
3216
3225
  ::: code-group
3217
3226
 
@@ -3247,179 +3256,66 @@ or router configuration matches the paths you pass to the client.
3247
3256
 
3248
3257
  ### Live Transport
3249
3258
 
3250
- Void can run separate request handlers for mutations and long-lived SSE
3251
- connections. `createVoidFateLive` bridges those handlers by publishing live
3252
- events from the request that changed data to the live route.
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.
3259
+ `createVoidFateLive` publishes entity and connection events through the `void/live`
3260
+ stream associated with the current request. Void manages the Durable Object
3261
+ transport that distributes events to connected clients across requests.
3258
3262
 
3259
3263
  The live transport is best-effort and does not replay missed events after a
3260
3264
  client reconnects. This matches fate's default in-memory live event bus.
3261
3265
 
3262
- ## Cloudflare Integration
3263
-
3264
- `cf-fate` is the first-class Cloudflare Workers adapter for Fate native HTTP transport and live views.
3265
-
3266
- Use it when your backend runs directly on Cloudflare Workers and you want fate live views without adopting the Void platform.
3267
-
3268
- ### New Project
3266
+ ### Cloudflare Deployment
3269
3267
 
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.
3268
+ From your project root, run:
3271
3269
 
3272
3270
  ```sh
3273
- vp create fate my-app --template cloudflare
3271
+ vp exec void deploy --platform cloudflare
3274
3272
  ```
3275
3273
 
3276
- Use Vue instead of React with:
3274
+ Void provisions resources and deploys directly to your Cloudflare account. See the [Cloudflare integration](/docs/integrations/cloudflare.md) for setup and migration instructions.
3277
3275
 
3278
- ```sh
3279
- vp create fate my-app --template cloudflare --framework vue
3280
- ```
3276
+ ## Cloudflare Integration
3281
3277
 
3282
- ### Existing Project
3278
+ 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
3279
 
3284
- For an existing Cloudflare Workers project, add the packages directly:
3280
+ ### New Project
3285
3281
 
3286
3282
  ```sh
3287
- pnpm add @nkzw/fate react-fate cf-fate drizzle-orm
3288
- pnpm add -D wrangler
3289
- ```
3290
-
3291
- For Vue clients, replace `react-fate` with `vue-fate`.
3292
-
3293
- ### Server Setup
3294
-
3295
- Create a Cloudflare live stream and pass its Fate live facade to `createFateServer`.
3296
-
3297
- ```ts
3298
- // src/fate/live.ts
3299
- import { defineCloudflareFateLiveStream } from 'cf-fate/server';
3300
-
3301
- export const fateStream = defineCloudflareFateLiveStream({
3302
- allowAnonymousControl: true,
3303
- binding: 'FATE_LIVE',
3304
- id: 'fate',
3305
- });
3306
- ```
3307
-
3308
- ```ts
3309
- // src/fate/server.ts
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);
3283
+ vp create fate my-app --template void
3284
+ cd my-app
3285
+ vp run dev:setup
3286
+ vp run dev
3329
3287
  ```
3330
3288
 
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
- ```
3289
+ Add `--framework vue` to the create command to use Vue instead of React.
3364
3290
 
3365
- ### Wrangler
3291
+ ### Deploy
3366
3292
 
3367
- Add a Durable Object binding and migration. `cf-fate` uses `node:async_hooks`, so the Worker must enable Node compatibility.
3293
+ From the project root:
3368
3294
 
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
- }
3295
+ ```sh
3296
+ vp exec void deploy --platform cloudflare
3387
3297
  ```
3388
3298
 
3389
- ### Client
3299
+ 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
3300
 
3391
- Use the Cloudflare transport in the Fate Vite plugin:
3301
+ 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
3302
 
3393
- ```ts
3394
- import { fate } from 'react-fate/vite';
3303
+ 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
3304
 
3396
- fate({
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';
3305
+ See [Void's Cloudflare deployment guide](https://void.cloud/integrations/cloudflare) for custom domains, secrets, and CI configuration.
3407
3306
 
3408
- const fate = createFateClient({
3409
- liveUrl: 'http://localhost:8787/fate-live',
3410
- url: 'http://localhost:8787/fate',
3411
- });
3307
+ ### Migrating from cf-fate
3412
3308
 
3413
- export function App({ children }) {
3414
- return <FateClient client={fate}>{children}</FateClient>;
3415
- }
3416
- ```
3309
+ 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
3310
 
3418
- ### Semantics
3311
+ 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
3312
 
3420
- `cf-fate` uses one browser `EventSource` per Fate client and multiplexes entity and connection topics over that stream. Durable Objects keep connection and topic subscription state so later requests, mutations, scheduled handlers, and queue consumers can publish to already-connected clients.
3313
+ - Define the live stream with `defineLiveStream` from `void/live`.
3314
+ - Use `createVoidFateLive`, `defineVoidFateRoute`, and `defineVoidFateLiveRoute` from `void-fate/server`.
3315
+ - Let the generated client use `void/live/client` for live connections.
3316
+ - Remove the `cf-fate` dependency and the custom Worker entry point.
3421
3317
 
3422
- Delivery is at-most-once. Events are ordered within one topic, but events are not durably replayed after a disconnect. Use authoritative refetching or application-owned replay storage if missed events must be recovered.
3318
+ 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
3319
 
3424
3320
  ## Frequently Asked Questions
3425
3321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/fate-indexeddb",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
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": "^1.5.1",
22
+ "@nkzw/fate": "1.6.0",
23
23
  "fake-indexeddb": "^6.2.5",
24
- "vite": "npm:@voidzero-dev/vite-plus-core@0.3.2",
25
- "vite-plus": "0.3.2"
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"