@nkzw/fate 0.0.5 → 0.0.6
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 +2 -4
- package/lib/server.d.mts +8 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -766,7 +766,7 @@ Since clients can send arbitrary selection objects to the server, we need to imp
|
|
|
766
766
|
Create a `views.ts` file next to your root tRPC router that exports the data views for each type. Here is how you can define a `User` data view for Prisma's `User` model:
|
|
767
767
|
|
|
768
768
|
```tsx
|
|
769
|
-
import { dataView,
|
|
769
|
+
import { dataView, type Entity } from '@nkzw/fate/server';
|
|
770
770
|
import type { User as PrismaUser } from '../prisma/prisma-client/client.ts';
|
|
771
771
|
|
|
772
772
|
export const userDataView = dataView<PrismaUser>('User')({
|
|
@@ -775,9 +775,7 @@ export const userDataView = dataView<PrismaUser>('User')({
|
|
|
775
775
|
username: true,
|
|
776
776
|
});
|
|
777
777
|
|
|
778
|
-
export type User =
|
|
779
|
-
__typename: 'User';
|
|
780
|
-
};
|
|
778
|
+
export type User = Entity<typeof userDataView, 'User'>;
|
|
781
779
|
```
|
|
782
780
|
|
|
783
781
|
_Note: Currently, fate provides helpers to integrate with Prisma, but the framework is not coupled to any particular ORM or database. We hope to provide more direct integrations in the future, and are always open to contributions._
|
package/lib/server.d.mts
CHANGED
|
@@ -51,7 +51,7 @@ type DataViewConfig<Item$1 extends AnyRecord, Context> = Record<string, DataFiel
|
|
|
51
51
|
* title: true,
|
|
52
52
|
* });
|
|
53
53
|
*/
|
|
54
|
-
declare function dataView<Item$1 extends AnyRecord, Context = unknown>(typeName
|
|
54
|
+
declare function dataView<Item$1 extends AnyRecord, Context = unknown>(typeName: string): <Fields extends DataViewConfig<Item$1, Context>>(fields: Fields) => DataView<Item$1, Context> & {
|
|
55
55
|
readonly [dataViewFieldsKey]: Fields;
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
@@ -80,10 +80,14 @@ type ViewFieldConfig<V extends DataView<AnyRecord, unknown>> = V extends {
|
|
|
80
80
|
} ? Fields : V['fields'];
|
|
81
81
|
type RawFieldResult<Item$1 extends AnyRecord, Key extends PropertyKey, Field extends DataField<Item$1, unknown>> = Field extends true ? Key extends keyof Item$1 ? Item$1[Key] : never : Field extends DataView<infer ChildItem, unknown> ? Key extends keyof Item$1 ? RelationResult<Item$1[Key], DataView<ChildItem, unknown>> : never : Field extends ResolverField<Item$1, unknown> ? ResolverResult<Field> : never;
|
|
82
82
|
type RawDataViewResult<V extends DataView<AnyRecord, unknown>> = V extends DataView<infer Item, unknown> ? { [K in keyof ViewFieldConfig<V>]: RawFieldResult<Item, K, ViewFieldConfig<V>[K]> } : never;
|
|
83
|
+
type DataViewResult<V extends DataView<AnyRecord, unknown>> = Serializable<RawDataViewResult<V>>;
|
|
84
|
+
type WithTypename<T, Name extends string> = T & {
|
|
85
|
+
__typename: Name;
|
|
86
|
+
};
|
|
83
87
|
/**
|
|
84
|
-
* Resolved
|
|
88
|
+
* Resolved entity type from a data view for client use.
|
|
85
89
|
*/
|
|
86
|
-
type
|
|
90
|
+
type Entity<TView extends DataView<AnyRecord, unknown>, Name extends string, Replacements extends Record<string, unknown> = Record<string, never>> = WithTypename<Omit<DataViewResult<TView>, keyof Replacements> & Replacements, Name>;
|
|
87
91
|
/**
|
|
88
92
|
* Builds a resolver that applies a client's selection to a server data view,
|
|
89
93
|
* filtering fields, running nested resolvers, and shaping selects.
|
|
@@ -160,4 +164,4 @@ declare const withConnection: <TContext>(procedure: ProcedureLike<TContext>) =>
|
|
|
160
164
|
query: QueryFn<TContext, TItem, ConnectionInputWithAdditional<TAdditionalInput>>;
|
|
161
165
|
}) => ReturnType<ReturnType<ProcedureLike<TContext>["input"]>["query"]>;
|
|
162
166
|
//#endregion
|
|
163
|
-
export { type
|
|
167
|
+
export { type Entity, connectionArgs, createResolver, dataView, list, resolver, withConnection };
|