feat: generate types for joins (#9054)
### What? Generates types for `joins` property. Example from our `joins` test, keys are type-safe: <img width="708" alt="image" src="https://github.com/user-attachments/assets/f1fbbb9d-7c39-49a2-8aa2-a4793ae4ad7e"> Output in `payload-types.ts`: ```ts collectionsJoins: { categories: { relatedPosts: 'posts'; hasManyPosts: 'posts'; hasManyPostsLocalized: 'posts'; 'group.relatedPosts': 'posts'; 'group.camelCasePosts': 'posts'; filtered: 'posts'; singulars: 'singular'; }; }; ``` Additionally, we include type information about on which collection the join is, it will help when we have types generation for `where` and `sort`. ### Why? It provides a better DX as you don't need to memoize your keys. ### How? Modifies `configToJSONSchema` to generate the json schema for `collectionsJoins`, uses that type within `JoinQuery`
This commit is contained in:
@@ -26,7 +26,30 @@ export interface Config {
|
||||
'payload-preferences': PayloadPreference;
|
||||
'payload-migrations': PayloadMigration;
|
||||
};
|
||||
collectionsSelect?: {
|
||||
collectionsJoins: {
|
||||
categories: {
|
||||
relatedPosts: 'posts';
|
||||
hasManyPosts: 'posts';
|
||||
hasManyPostsLocalized: 'posts';
|
||||
'group.relatedPosts': 'posts';
|
||||
'group.camelCasePosts': 'posts';
|
||||
filtered: 'posts';
|
||||
singulars: 'singular';
|
||||
};
|
||||
uploads: {
|
||||
relatedPosts: 'posts';
|
||||
};
|
||||
'categories-versions': {
|
||||
relatedVersions: 'versions';
|
||||
};
|
||||
'localized-categories': {
|
||||
relatedPosts: 'localized-posts';
|
||||
};
|
||||
'restricted-categories': {
|
||||
restrictedPosts: 'posts';
|
||||
};
|
||||
};
|
||||
collectionsSelect: {
|
||||
posts: PostsSelect<false> | PostsSelect<true>;
|
||||
categories: CategoriesSelect<false> | CategoriesSelect<true>;
|
||||
uploads: UploadsSelect<false> | UploadsSelect<true>;
|
||||
@@ -46,7 +69,7 @@ export interface Config {
|
||||
defaultIDType: string;
|
||||
};
|
||||
globals: {};
|
||||
globalsSelect?: {};
|
||||
globalsSelect: {};
|
||||
locale: 'en' | 'es';
|
||||
user: User & {
|
||||
collection: 'users';
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface Config {
|
||||
'payload-preferences': PayloadPreference;
|
||||
'payload-migrations': PayloadMigration;
|
||||
};
|
||||
collectionsJoins: {};
|
||||
collectionsSelect: {
|
||||
posts: PostsSelect<false> | PostsSelect<true>;
|
||||
'localized-posts': LocalizedPostsSelect<false> | LocalizedPostsSelect<true>;
|
||||
|
||||
Reference in New Issue
Block a user