@nkzw/fate 1.2.0 → 1.3.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.
- package/docs/api/classes/FateClient.md +40 -40
- package/docs/api/functions/clientRoot.md +1 -1
- package/docs/api/functions/createClient.md +1 -1
- package/docs/api/functions/createGraphQLTransport.md +1 -1
- package/docs/api/functions/createHTTPTransport.md +1 -1
- package/docs/api/functions/createTRPCTransport.md +1 -1
- package/docs/api/functions/defer.md +1 -1
- package/docs/api/functions/getDeferredMetadata.md +1 -1
- package/docs/api/functions/getListEntries.md +1 -1
- package/docs/api/functions/getSelectionPlan.md +1 -1
- package/docs/api/functions/graphqlMutation.md +1 -1
- package/docs/api/functions/isDeferred.md +1 -1
- package/docs/api/functions/isRecord.md +1 -1
- package/docs/api/functions/isViewTag.md +1 -1
- package/docs/api/functions/liveConnectionTopic.md +1 -1
- package/docs/api/functions/liveEntityTopic.md +1 -1
- package/docs/api/functions/liveGlobalConnectionTopic.md +1 -1
- package/docs/api/functions/mutation.md +1 -1
- package/docs/api/functions/toEntityId.md +1 -1
- package/docs/api/functions/view.md +1 -1
- package/docs/api/interfaces/FateThenable.md +3 -3
- package/docs/api/interfaces/Transport.md +7 -7
- package/docs/api/server/classes/FateRequestError.md +5 -5
- package/docs/api/server/drizzle/functions/createDrizzleFate.md +1 -1
- package/docs/api/server/drizzle/functions/createDrizzleSourceAdapter.md +1 -1
- package/docs/api/server/drizzle/functions/createDrizzleSourceRegistry.md +1 -1
- package/docs/api/server/drizzle/type-aliases/DrizzleManyToManyConfig.md +1 -1
- package/docs/api/server/drizzle/type-aliases/DrizzleManyToManyInput.md +1 -1
- package/docs/api/server/drizzle/type-aliases/DrizzleQueryExtra.md +3 -3
- package/docs/api/server/drizzle/type-aliases/DrizzleSourceAdapter.md +9 -9
- package/docs/api/server/drizzle/type-aliases/DrizzleViewConfig.md +1 -1
- package/docs/api/server/functions/bindSourceProcedures.md +1 -1
- package/docs/api/server/functions/computed.md +1 -1
- package/docs/api/server/functions/count.md +1 -1
- package/docs/api/server/functions/createFateFetchHandler.md +1 -1
- package/docs/api/server/functions/createFateServer.md +1 -1
- package/docs/api/server/functions/createHonoFateHandler.md +1 -1
- package/docs/api/server/functions/createLiveEventBus.md +1 -1
- package/docs/api/server/functions/createNestedSourcePlan.md +1 -1
- package/docs/api/server/functions/createResolver.md +1 -1
- package/docs/api/server/functions/createSourcePlan.md +1 -1
- package/docs/api/server/functions/createSourceProcedures.md +1 -1
- package/docs/api/server/functions/dataView.md +1 -1
- package/docs/api/server/functions/field.md +1 -1
- package/docs/api/server/functions/getNestedSelection.md +1 -1
- package/docs/api/server/functions/getScopedArgs.md +1 -1
- package/docs/api/server/functions/hasNestedSelection.md +1 -1
- package/docs/api/server/functions/list.md +1 -1
- package/docs/api/server/functions/refetchSourceById.md +1 -1
- package/docs/api/server/functions/resolveSourceById.md +1 -1
- package/docs/api/server/functions/resolveSourceByIds.md +1 -1
- package/docs/api/server/functions/resolveSourceConnection.md +1 -1
- package/docs/api/server/functions/resolver.md +1 -1
- package/docs/api/server/functions/toPrismaSelect.md +1 -1
- package/docs/api/server/functions/withConnection.md +1 -1
- package/docs/api/server/prisma/functions/createPrismaFate.md +1 -1
- package/docs/api/server/prisma/functions/createPrismaSourceAdapter.md +1 -1
- package/docs/api/server/prisma/functions/createPrismaSourceRegistry.md +1 -1
- package/docs/api/server/prisma/functions/prismaConnectionArgs.md +1 -1
- package/docs/api/server/prisma/type-aliases/PrismaDelegate.md +4 -4
- package/docs/api/server/prisma/type-aliases/PrismaQueryExtra.md +1 -1
- package/docs/api/server/prisma/type-aliases/PrismaSourceAdapter.md +9 -9
- package/docs/api/server/prisma/type-aliases/PrismaViewConfig.md +1 -1
- package/docs/api/server/type-aliases/ComputedField.md +5 -5
- package/docs/api/server/type-aliases/ComputedSelection.md +1 -1
- package/docs/api/server/type-aliases/ConnectionItem.md +3 -3
- package/docs/api/server/type-aliases/ConnectionPagination.md +5 -5
- package/docs/api/server/type-aliases/ConnectionResult.md +3 -3
- package/docs/api/server/type-aliases/CountSelection.md +4 -4
- package/docs/api/server/type-aliases/CountWhere.md +1 -1
- package/docs/api/server/type-aliases/DataViewListOptions.md +2 -2
- package/docs/api/server/type-aliases/DataViewOrderBy.md +1 -1
- package/docs/api/server/type-aliases/DataViewOrderDirection.md +1 -1
- package/docs/api/server/type-aliases/DataViewResult.md +1 -1
- package/docs/api/server/type-aliases/Entity.md +1 -1
- package/docs/api/server/type-aliases/FateServer.md +5 -5
- package/docs/api/server/type-aliases/FateServerManifest.md +1 -1
- package/docs/api/server/type-aliases/FieldSelection.md +3 -3
- package/docs/api/server/type-aliases/LiveConnectionEventType.md +1 -1
- package/docs/api/server/type-aliases/LiveConnectionSourceEvent.md +1 -1
- package/docs/api/server/type-aliases/LiveEventBus.md +1 -1
- package/docs/api/server/type-aliases/LiveEventType.md +1 -1
- package/docs/api/server/type-aliases/LiveSourceEvent.md +1 -1
- package/docs/api/server/type-aliases/NativeFateAPI.md +4 -4
- package/docs/api/server/type-aliases/OrderDirection.md +1 -1
- package/docs/api/server/type-aliases/SourceConfig.md +6 -6
- package/docs/api/server/type-aliases/SourceDefinition.md +6 -6
- package/docs/api/server/type-aliases/SourceOrder.md +1 -1
- package/docs/api/server/type-aliases/SourceOrderField.md +3 -3
- package/docs/api/server/type-aliases/SourcePlan.md +1 -1
- package/docs/api/server/type-aliases/SourcePlanNode.md +1 -1
- package/docs/api/server/type-aliases/SourceRegistry.md +1 -1
- package/docs/api/server/type-aliases/SourceRelation.md +1 -1
- package/docs/api/server/type-aliases/SourceRelationConfig.md +1 -1
- package/docs/api/server/variables/byIdInput.md +1 -1
- package/docs/api/server/variables/connectionArgs.md +1 -1
- package/docs/api/type-aliases/ConnectionMetadata.md +1 -1
- package/docs/api/type-aliases/ConnectionRef.md +1 -1
- package/docs/api/type-aliases/Deferred.md +1 -1
- package/docs/api/type-aliases/DeferredMetadata.md +1 -1
- package/docs/api/type-aliases/DeferredSelection.md +1 -1
- package/docs/api/type-aliases/DeferredSnapshot.md +1 -1
- package/docs/api/type-aliases/Entity.md +2 -2
- package/docs/api/type-aliases/EntityId.md +1 -1
- package/docs/api/type-aliases/FateDehydratedState.md +1 -1
- package/docs/api/type-aliases/FateLiveConnectionEvent.md +1 -1
- package/docs/api/type-aliases/FateLiveEvent.md +1 -1
- package/docs/api/type-aliases/FateMutations.md +1 -1
- package/docs/api/type-aliases/FateOperation.md +1 -1
- package/docs/api/type-aliases/FateProtocolRequest.md +1 -1
- package/docs/api/type-aliases/FateProtocolResponse.md +1 -1
- package/docs/api/type-aliases/FateRecord.md +1 -1
- package/docs/api/type-aliases/FateRoots.md +1 -1
- package/docs/api/type-aliases/GraphQLMutationDefinition.md +1 -1
- package/docs/api/type-aliases/GraphQLMutationInput.md +1 -1
- package/docs/api/type-aliases/GraphQLMutationMap.md +1 -1
- package/docs/api/type-aliases/GraphQLMutationOutput.md +1 -1
- package/docs/api/type-aliases/GraphQLTransportOptions.md +11 -11
- package/docs/api/type-aliases/HydrateOptions.md +1 -1
- package/docs/api/type-aliases/HydrationLimits.md +1 -1
- package/docs/api/type-aliases/InferFateAPI.md +1 -1
- package/docs/api/type-aliases/List.md +1 -1
- package/docs/api/type-aliases/ListEntry.md +1 -1
- package/docs/api/type-aliases/ListItem.md +1 -1
- package/docs/api/type-aliases/Mask.md +1 -1
- package/docs/api/type-aliases/MutationDefinition.md +1 -1
- package/docs/api/type-aliases/MutationEntity.md +1 -1
- package/docs/api/type-aliases/MutationIdentifier.md +1 -1
- package/docs/api/type-aliases/MutationInput.md +1 -1
- package/docs/api/type-aliases/MutationResult.md +1 -1
- package/docs/api/type-aliases/NodesItem.md +1 -1
- package/docs/api/type-aliases/Pagination.md +5 -5
- package/docs/api/type-aliases/Request.md +1 -1
- package/docs/api/type-aliases/RequestMode.md +1 -1
- package/docs/api/type-aliases/RequestOptions.md +1 -1
- package/docs/api/type-aliases/RequestResult.md +1 -1
- package/docs/api/type-aliases/Selection.md +1 -1
- package/docs/api/type-aliases/Snapshot.md +1 -1
- package/docs/api/type-aliases/TypeConfig.md +4 -4
- package/docs/api/type-aliases/View.md +1 -1
- package/docs/api/type-aliases/ViewData.md +1 -1
- package/docs/api/type-aliases/ViewEntity.md +1 -1
- package/docs/api/type-aliases/ViewEntityName.md +1 -1
- package/docs/api/type-aliases/ViewRef.md +1 -1
- package/docs/api/type-aliases/ViewSelection.md +1 -1
- package/docs/api/type-aliases/ViewSnapshot.md +1 -1
- package/docs/api/type-aliases/ViewTag.md +1 -1
- package/docs/api/variables/ConnectionTag.md +1 -1
- package/docs/api/variables/DeferTag.md +1 -1
- package/docs/api/variables/DeferredTag.md +1 -1
- package/docs/integrations/cloudflare.md +143 -0
- package/lib/vite.d.mts +1 -1
- package/lib/vite.mjs +27 -7
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **RequestResult**\<`R`, `Q`\> = `{ [K in keyof Q]: K extends keyof R ? ListResult<Q[K], RootType<R[K]>, RootResult<R[K]>> : never }`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:424](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:424](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L424)
|
|
6
6
|
|
|
7
7
|
The result of a `FateClient.request` and `useRequest` call, mapping each
|
|
8
8
|
request key to its corresponding result.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **Selection**\<`T`\> = `SelectionShape`\<`T`\> & `SelectionViewSpread`\<`T`\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:229](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:229](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L229)
|
|
6
6
|
|
|
7
7
|
Declarative selection of the fields a view needs from an entity.
|
|
8
8
|
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> **Snapshot** = `Readonly`\<\{ `mask?`: `FieldMask`; `record?`: [`FateRecord`](FateRecord.md); \}\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:513](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:513](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L513)
|
|
6
6
|
|
|
7
7
|
Snapshot captured before mutating the cache, used to roll back on errors.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **TypeConfig** = `object`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:124](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:124](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L124)
|
|
6
6
|
|
|
7
7
|
Configuration for a server entity type used by the client cache.
|
|
8
8
|
|
|
@@ -12,7 +12,7 @@ Configuration for a server entity type used by the client cache.
|
|
|
12
12
|
|
|
13
13
|
> `optional` **fields?**: `Record`\<`string`, `RelationDescriptor`\>
|
|
14
14
|
|
|
15
|
-
Defined in: [packages/fate/src/types.ts:125](https://github.com/nkzw-tech/fate/blob/
|
|
15
|
+
Defined in: [packages/fate/src/types.ts:125](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L125)
|
|
16
16
|
|
|
17
17
|
***
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ Defined in: [packages/fate/src/types.ts:125](https://github.com/nkzw-tech/fate/b
|
|
|
20
20
|
|
|
21
21
|
> **getId**: (`record`) => `string` \| `number`
|
|
22
22
|
|
|
23
|
-
Defined in: [packages/fate/src/types.ts:126](https://github.com/nkzw-tech/fate/blob/
|
|
23
|
+
Defined in: [packages/fate/src/types.ts:126](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L126)
|
|
24
24
|
|
|
25
25
|
#### Parameters
|
|
26
26
|
|
|
@@ -38,4 +38,4 @@ Defined in: [packages/fate/src/types.ts:126](https://github.com/nkzw-tech/fate/b
|
|
|
38
38
|
|
|
39
39
|
> **type**: `string`
|
|
40
40
|
|
|
41
|
-
Defined in: [packages/fate/src/types.ts:127](https://github.com/nkzw-tech/fate/blob/
|
|
41
|
+
Defined in: [packages/fate/src/types.ts:127](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L127)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **View**\<`T`, `S`\> = `Readonly`\<\{\[`viewTag`: `` `__fate-view__${string}` ``\]: `Readonly`\<\{ `[ViewKind]`: `true`; `select`: `S`; \}\>; \}\> & `__ViewEntityAnchor`\<`T`\> & `__ViewSelectionAnchor`\<`S`\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:245](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:245](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L245)
|
|
6
6
|
|
|
7
7
|
Definition of a view over an entity type, including the selection of fields.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewData**\<`T`, `S`\> = `Readonly`\<`S` *extends* [`Selection`](Selection.md)\<`T`\> ? [`Mask`](Mask.md)\<`T`, `S`\> : `T` & `object`\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:261](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:261](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L261)
|
|
6
6
|
|
|
7
7
|
Data returned from a resolved view with masking applied and view tags
|
|
8
8
|
attached for downstream composition.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewEntity**\<`V`\> = `V` *extends* [`View`](View.md)\<infer T, `any`\> ? `T` : `never`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:335](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:335](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L335)
|
|
6
6
|
|
|
7
7
|
Entity type captured from a view definition.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewEntityName**\<`V`\> = [`ViewEntity`](ViewEntity.md)\<`V`\>\[`"__typename"`\] & `string`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:338](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:338](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L338)
|
|
6
6
|
|
|
7
7
|
Name of the entity type captured from a view definition.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewRef**\<`TName`\> = `Readonly`\<\{ `__typename`: `TName`; `[ViewsTag]`: `Set`\<`string`\>; `id`: `string` \| `number`; \}\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:108](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:108](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L108)
|
|
6
6
|
|
|
7
7
|
Reference to a normalized entity instance that can be resolved against one or more view tags.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewSelection**\<`V`\> = `V` *extends* `object` ? `S` : `never`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:341](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:341](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L341)
|
|
6
6
|
|
|
7
7
|
Selection captured from a view definition.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewSnapshot**\<`T`, `S`\> = `Readonly`\<\{ `coverage`: `ReadonlyArray`\<readonly \[[`EntityId`](EntityId.md), `ReadonlySet`\<`string`\>\]\>; `data`: [`ViewData`](ViewData.md)\<`T`, `S`\>; \}\>
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:271](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:271](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L271)
|
|
6
6
|
|
|
7
7
|
Snapshot returned by the cache for a view, including the masked data and all
|
|
8
8
|
referenced entity IDs.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> **ViewTag** = `` `__fate-view__${string}` ``
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:56](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:56](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L56)
|
|
6
6
|
|
|
7
7
|
Unique key that identifies a view composition entry inside a selection or reference.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> `const` **ConnectionTag**: *typeof* `ConnectionTag`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:20](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:20](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L20)
|
|
6
6
|
|
|
7
7
|
Symbol attached to connection results so pagination helpers can find their metadata.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> `const` **DeferTag**: *typeof* `DeferTag`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:23](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:23](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L23)
|
|
6
6
|
|
|
7
7
|
Symbol used to mark a selection as deferred.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> `const` **DeferredTag**: *typeof* `DeferredTag`
|
|
4
4
|
|
|
5
|
-
Defined in: [packages/fate/src/types.ts:26](https://github.com/nkzw-tech/fate/blob/
|
|
5
|
+
Defined in: [packages/fate/src/types.ts:26](https://github.com/nkzw-tech/fate/blob/4876b00b02cd1ef9ae7fd82b8a3c27d82fc6c232/packages/fate/src/types.ts#L26)
|
|
6
6
|
|
|
7
7
|
Symbol attached to deferred values returned from masked views.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Cloudflare Integration
|
|
2
|
+
|
|
3
|
+
`cf-fate` is the first-class Cloudflare Workers adapter for Fate native HTTP transport and live views.
|
|
4
|
+
|
|
5
|
+
Use it when your backend runs directly on Cloudflare Workers and you want fate live views without adopting the Void platform.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @nkzw/fate react-fate cf-fate drizzle-orm
|
|
11
|
+
pnpm add -D wrangler
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Server Setup
|
|
15
|
+
|
|
16
|
+
Create a Cloudflare live stream and pass its Fate live facade to `createFateServer`.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// src/fate/live.ts
|
|
20
|
+
import { defineCloudflareFateLiveStream } from 'cf-fate/server';
|
|
21
|
+
|
|
22
|
+
export const fateStream = defineCloudflareFateLiveStream({
|
|
23
|
+
allowAnonymousControl: true,
|
|
24
|
+
binding: 'FATE_LIVE',
|
|
25
|
+
id: 'fate',
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// src/fate/server.ts
|
|
31
|
+
import { createFateServer } from '@nkzw/fate/server';
|
|
32
|
+
import { createCloudflareFateLive } from 'cf-fate/server';
|
|
33
|
+
|
|
34
|
+
export const fateLive = createCloudflareFateLive();
|
|
35
|
+
export const { live } = fateLive;
|
|
36
|
+
|
|
37
|
+
export const fateServer = createFateServer({
|
|
38
|
+
live,
|
|
39
|
+
// context,
|
|
40
|
+
// roots,
|
|
41
|
+
// sources,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Publish from mutations through the normal Fate live bus:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
live.update('Post', postId, { changed: ['likes'] });
|
|
49
|
+
live.connection('Post.comments', { id: postId }).appendNode('Comment', commentId);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Worker Routes
|
|
53
|
+
|
|
54
|
+
Expose one route for Fate RPC and one route for the SSE live stream.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import {
|
|
58
|
+
createCloudflareFateLiveDurableObject,
|
|
59
|
+
defineCloudflareFateLiveRoute,
|
|
60
|
+
defineCloudflareFateRoute,
|
|
61
|
+
} from 'cf-fate/server';
|
|
62
|
+
import { fateStream } from './fate/live';
|
|
63
|
+
import { fateLive, fateServer } from './fate/server';
|
|
64
|
+
|
|
65
|
+
const fateRoute = defineCloudflareFateRoute(fateServer, fateLive, { stream: fateStream });
|
|
66
|
+
const fateLiveRoute = defineCloudflareFateLiveRoute(fateStream);
|
|
67
|
+
|
|
68
|
+
export const FateLiveDurableObject = createCloudflareFateLiveDurableObject({
|
|
69
|
+
binding: 'FATE_LIVE',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export default {
|
|
73
|
+
fetch(request, env, ctx) {
|
|
74
|
+
const url = new URL(request.url);
|
|
75
|
+
if (url.pathname === '/fate') {
|
|
76
|
+
return fateRoute.fetch(request, env, ctx);
|
|
77
|
+
}
|
|
78
|
+
if (url.pathname === '/fate-live') {
|
|
79
|
+
return fateLiveRoute.fetch(request, env, ctx);
|
|
80
|
+
}
|
|
81
|
+
return new Response('Not Found', { status: 404 });
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Wrangler
|
|
87
|
+
|
|
88
|
+
Add a Durable Object binding and migration. `cf-fate` uses `node:async_hooks`, so the Worker must enable Node compatibility.
|
|
89
|
+
|
|
90
|
+
```jsonc
|
|
91
|
+
{
|
|
92
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
93
|
+
"durable_objects": {
|
|
94
|
+
"bindings": [
|
|
95
|
+
{
|
|
96
|
+
"name": "FATE_LIVE",
|
|
97
|
+
"class_name": "FateLiveDurableObject",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
"migrations": [
|
|
102
|
+
{
|
|
103
|
+
"tag": "fate-live-v1",
|
|
104
|
+
"new_sqlite_classes": ["FateLiveDurableObject"],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Client
|
|
111
|
+
|
|
112
|
+
Use the Cloudflare transport in the Fate Vite plugin:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { fate } from 'react-fate/vite';
|
|
116
|
+
|
|
117
|
+
fate({
|
|
118
|
+
module: './src/fate/server.ts',
|
|
119
|
+
transport: 'cloudflare',
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Then point the generated client at the Worker endpoints:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { FateClient } from 'react-fate';
|
|
127
|
+
import { createFateClient } from 'react-fate/client';
|
|
128
|
+
|
|
129
|
+
const fate = createFateClient({
|
|
130
|
+
liveUrl: 'http://localhost:8787/fate-live',
|
|
131
|
+
url: 'http://localhost:8787/fate',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export function App({ children }) {
|
|
135
|
+
return <FateClient client={fate}>{children}</FateClient>;
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Semantics
|
|
140
|
+
|
|
141
|
+
`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.
|
|
142
|
+
|
|
143
|
+
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.
|
package/lib/vite.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
2
|
|
|
3
3
|
//#region src/viteTypes.d.ts
|
|
4
|
-
type FateViteTransport = 'graphql' | 'native' | 'trpc' | 'void';
|
|
4
|
+
type FateViteTransport = 'cloudflare' | 'graphql' | 'native' | 'trpc' | 'void';
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/vite.d.ts
|
|
7
7
|
type ClientRuntime = '@nkzw/fate' | 'react-fate' | 'vue-fate';
|
package/lib/vite.mjs
CHANGED
|
@@ -87,11 +87,20 @@ const createClientSource = ({ clientModule = "react-fate", moduleExports, module
|
|
|
87
87
|
});
|
|
88
88
|
if (transport === "native" || transport === "void") return createNativeClientSource({
|
|
89
89
|
clientModule,
|
|
90
|
+
cloudflareTransport: false,
|
|
90
91
|
moduleExports,
|
|
91
92
|
moduleName,
|
|
92
93
|
runtimeModuleName,
|
|
93
94
|
voidTransport: transport === "void"
|
|
94
95
|
});
|
|
96
|
+
if (transport === "cloudflare") return createNativeClientSource({
|
|
97
|
+
clientModule,
|
|
98
|
+
cloudflareTransport: true,
|
|
99
|
+
moduleExports,
|
|
100
|
+
moduleName,
|
|
101
|
+
runtimeModuleName,
|
|
102
|
+
voidTransport: false
|
|
103
|
+
});
|
|
95
104
|
const { appRouter, Root } = moduleExports;
|
|
96
105
|
const { roots, types } = createSchema(Object.values(moduleExports).filter(isDataView), Root ?? {});
|
|
97
106
|
const routerRecord = appRouter._def?.record ?? {};
|
|
@@ -412,7 +421,7 @@ type GeneratedCreateFateClient = typeof createFateClient;
|
|
|
412
421
|
${generatedClientTypes}
|
|
413
422
|
`;
|
|
414
423
|
};
|
|
415
|
-
const createNativeClientSource = ({ clientModule, moduleExports, moduleName, runtimeModuleName, voidTransport }) => {
|
|
424
|
+
const createNativeClientSource = ({ clientModule, cloudflareTransport, moduleExports, moduleName, runtimeModuleName, voidTransport }) => {
|
|
416
425
|
const { Root } = moduleExports;
|
|
417
426
|
const fateExportName = moduleExports.fate?.manifest ? "fate" : moduleExports.fateServer?.manifest ? "fateServer" : null;
|
|
418
427
|
const fateServer = fateExportName ? moduleExports[fateExportName] : null;
|
|
@@ -510,7 +519,17 @@ const createVoidFetch = (options: {
|
|
|
510
519
|
});
|
|
511
520
|
};
|
|
512
521
|
` : "";
|
|
513
|
-
const
|
|
522
|
+
const cloudflareHelpers = cloudflareTransport ? `
|
|
523
|
+
const defaultCloudflareFateRpcPath = '/fate';
|
|
524
|
+
const defaultCloudflareFateLivePath = '/fate-live';
|
|
525
|
+
|
|
526
|
+
const getDefaultOrigin = () =>
|
|
527
|
+
typeof window === 'undefined' ? 'http://localhost' : window.location.origin;
|
|
528
|
+
|
|
529
|
+
const toEndpointUrl = (url: string | URL | undefined, path: string, origin: string | URL) =>
|
|
530
|
+
url ?? new URL(path, origin);
|
|
531
|
+
` : "";
|
|
532
|
+
const createClientOptions = voidTransport || cloudflareTransport ? `options: {
|
|
514
533
|
fetch?: typeof fetch;
|
|
515
534
|
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
516
535
|
livePath?: string;
|
|
@@ -529,7 +548,7 @@ const createVoidFetch = (options: {
|
|
|
529
548
|
onLiveError?: (error: unknown) => void;
|
|
530
549
|
url: string | URL;
|
|
531
550
|
}`;
|
|
532
|
-
const clientSetup = voidTransport ? ` => {
|
|
551
|
+
const clientSetup = voidTransport || cloudflareTransport ? ` => {
|
|
533
552
|
const origin = options.origin ?? getDefaultOrigin();
|
|
534
553
|
|
|
535
554
|
return createClient<[GeneratedClientRoots, GeneratedClientMutations], typeof hydrationScope>({
|
|
@@ -538,16 +557,16 @@ const createVoidFetch = (options: {
|
|
|
538
557
|
onLiveError: options.onLiveError,
|
|
539
558
|
roots,
|
|
540
559
|
transport: createHTTPTransport<FateAPI>({
|
|
541
|
-
fetch: createVoidFetch(options),
|
|
560
|
+
fetch: ${voidTransport ? "createVoidFetch(options)" : "options.fetch"},
|
|
542
561
|
headers: options.headers,
|
|
543
|
-
live: ${hasLive ? "connectLiveStream" : "false"},
|
|
562
|
+
live: ${hasLive ? voidTransport ? "connectLiveStream" : "connectCloudflareFateStream" : "false"},
|
|
544
563
|
liveRetryMs: options.liveRetryMs,
|
|
545
564
|
liveUrl: toEndpointUrl(
|
|
546
565
|
options.liveUrl,
|
|
547
|
-
options.livePath ?? defaultVoidFateLivePath,
|
|
566
|
+
options.livePath ?? ${voidTransport ? "defaultVoidFateLivePath" : "defaultCloudflareFateLivePath"},
|
|
548
567
|
origin,
|
|
549
568
|
),
|
|
550
|
-
url: toEndpointUrl(options.url, options.rpcPath ?? defaultVoidFateRpcPath, origin),
|
|
569
|
+
url: toEndpointUrl(options.url, options.rpcPath ?? ${voidTransport ? "defaultVoidFateRpcPath" : "defaultCloudflareFateRpcPath"}, origin),
|
|
551
570
|
}),
|
|
552
571
|
types: ${typesBlock.trimStart()},
|
|
553
572
|
});
|
|
@@ -581,6 +600,7 @@ declare module '${clientDeclarationModule}' {
|
|
|
581
600
|
import type { ${importedTypes.join(", ")} } from '${moduleName}';
|
|
582
601
|
import { clientRoot, createClient, createHTTPTransport, mutation, type InferFateAPI } from '${clientModule}';
|
|
583
602
|
${voidTransport && hasLive ? "import { connectLiveStream } from 'void/live/client';\n" : ""}${voidServerFetch}
|
|
603
|
+
${cloudflareTransport && hasLive ? "import { connectCloudflareFateStream } from 'cf-fate/client';\n" : ""}${cloudflareHelpers}
|
|
584
604
|
|
|
585
605
|
type FateAPI = InferFateAPI<typeof fateServer>;
|
|
586
606
|
|