Files
payloadcms/test/fields-relationship/payload-types.ts
Jacob Fletcher c96fa613bc feat!: on demand rsc (#8364)
Currently, Payload renders all custom components on initial compile of
the admin panel. This is problematic for two key reasons:
1. Custom components do not receive contextual data, i.e. fields do not
receive their field data, edit views do not receive their document data,
etc.
2. Components are unnecessarily rendered before they are used

This was initially required to support React Server Components within
the Payload Admin Panel for two key reasons:
1. Fields can be dynamically rendered within arrays, blocks, etc.
2. Documents can be recursively rendered within a "drawer" UI, i.e.
relationship fields
3. Payload supports server/client component composition 

In order to achieve this, components need to be rendered on the server
and passed as "slots" to the client. Currently, the pattern for this is
to render custom server components in the "client config". Then when a
view or field is needed to be rendered, we first check the client config
for a "pre-rendered" component, otherwise render our client-side
fallback component.

But for the reasons listed above, this pattern doesn't exactly make
custom server components very useful within the Payload Admin Panel,
which is where this PR comes in. Now, instead of pre-rendering all
components on initial compile, we're able to render custom components
_on demand_, only as they are needed.

To achieve this, we've established [this
pattern](https://github.com/payloadcms/payload/pull/8481) of React
Server Functions in the Payload Admin Panel. With Server Functions, we
can iterate the Payload Config and return JSX through React's
`text/x-component` content-type. This means we're able to pass
contextual props to custom components, such as data for fields and
views.

## Breaking Changes

1. Add the following to your root layout file, typically located at
`(app)/(payload)/layout.tsx`:

    ```diff
    /* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
    /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
    + import type { ServerFunctionClient } from 'payload'

    import config from '@payload-config'
    import { RootLayout } from '@payloadcms/next/layouts'
    import { handleServerFunctions } from '@payloadcms/next/utilities'
    import React from 'react'

    import { importMap } from './admin/importMap.js'
    import './custom.scss'

    type Args = {
      children: React.ReactNode
    }

+ const serverFunctions: ServerFunctionClient = async function (args) {
    +  'use server'
    +  return handleServerFunctions({
    +    ...args,
    +    config,
    +    importMap,
    +  })
    + }

    const Layout = ({ children }: Args) => (
      <RootLayout
        config={config}
        importMap={importMap}
    +  serverFunctions={serverFunctions}
      >
        {children}
      </RootLayout>
    )

    export default Layout
    ```

2. If you were previously posting to the `/api/form-state` endpoint, it
no longer exists. Instead, you'll need to invoke the `form-state` Server
Function, which can be done through the _new_ `getFormState` utility:

    ```diff
    - import { getFormState } from '@payloadcms/ui'
    - const { state } = await getFormState({
    -   apiRoute: '',
    -   body: {
    -     // ...
    -   },
    -   serverURL: ''
    - })

    + const { getFormState } = useServerFunctions()
    +
    + const { state } = await getFormState({
    +   // ...
    + })
    ```

## Breaking Changes

```diff
- useFieldProps()
- useCellProps()
```

More details coming soon.

---------

Co-authored-by: Alessio Gravili <alessio@gravili.de>
Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
Co-authored-by: James <james@trbl.design>
2024-11-11 13:59:05 -05:00

643 lines
16 KiB
TypeScript

/* tslint:disable */
/* eslint-disable */
/**
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/
export interface Config {
auth: {
users: UserAuthOperations;
};
collections: {
'fields-relationship': FieldsRelationship;
'relation-filter-false': RelationFilterFalse;
'relation-filter-true': RelationFilterTrue;
'relation-one': RelationOne;
'relation-two': RelationTwo;
'relation-restricted': RelationRestricted;
'relation-with-title': RelationWithTitle;
'relation-updated-externally': RelationUpdatedExternally;
'collection-1': Collection1;
'collection-2': Collection2;
videos: Video;
podcasts: Podcast;
'mixed-media': MixedMedia;
'versioned-relationship-field': VersionedRelationshipField;
users: User;
'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration;
};
collectionsJoins: {};
collectionsSelect: {
'fields-relationship': FieldsRelationshipSelect<false> | FieldsRelationshipSelect<true>;
'relation-filter-false': RelationFilterFalseSelect<false> | RelationFilterFalseSelect<true>;
'relation-filter-true': RelationFilterTrueSelect<false> | RelationFilterTrueSelect<true>;
'relation-one': RelationOneSelect<false> | RelationOneSelect<true>;
'relation-two': RelationTwoSelect<false> | RelationTwoSelect<true>;
'relation-restricted': RelationRestrictedSelect<false> | RelationRestrictedSelect<true>;
'relation-with-title': RelationWithTitleSelect<false> | RelationWithTitleSelect<true>;
'relation-updated-externally': RelationUpdatedExternallySelect<false> | RelationUpdatedExternallySelect<true>;
'collection-1': Collection1Select<false> | Collection1Select<true>;
'collection-2': Collection2Select<false> | Collection2Select<true>;
videos: VideosSelect<false> | VideosSelect<true>;
podcasts: PodcastsSelect<false> | PodcastsSelect<true>;
'mixed-media': MixedMediaSelect<false> | MixedMediaSelect<true>;
'versioned-relationship-field': VersionedRelationshipFieldSelect<false> | VersionedRelationshipFieldSelect<true>;
users: UsersSelect<false> | UsersSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
};
db: {
defaultIDType: string;
};
globals: {};
globalsSelect: {};
locale: 'en';
user: User & {
collection: 'users';
};
jobs?: {
tasks: unknown;
workflows?: unknown;
};
}
export interface UserAuthOperations {
forgotPassword: {
email: string;
password: string;
};
login: {
email: string;
password: string;
};
registerFirstUser: {
email: string;
password: string;
};
unlock: {
email: string;
password: string;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "fields-relationship".
*/
export interface FieldsRelationship {
id: string;
relationship?: (string | null) | RelationOne;
relationshipHasMany?: (string | RelationOne)[] | null;
relationshipMultiple?:
| ({
relationTo: 'relation-one';
value: string | RelationOne;
} | null)
| ({
relationTo: 'relation-two';
value: string | RelationTwo;
} | null);
relationshipHasManyMultiple?:
| (
| {
relationTo: 'relation-one';
value: string | RelationOne;
}
| {
relationTo: 'relation-two';
value: string | RelationTwo;
}
)[]
| null;
relationshipRestricted?: (string | null) | RelationRestricted;
relationshipWithTitle?: (string | null) | RelationWithTitle;
relationshipFiltered?: (string | null) | RelationOne;
relationshipFilteredAsync?: (string | null) | RelationOne;
relationshipManyFiltered?:
| (
| {
relationTo: 'relation-with-title';
value: string | RelationWithTitle;
}
| {
relationTo: 'relation-filter-false';
value: string | RelationFilterFalse;
}
| {
relationTo: 'relation-filter-true';
value: string | RelationFilterTrue;
}
| {
relationTo: 'relation-one';
value: string | RelationOne;
}
)[]
| null;
filter?: string | null;
relationshipReadOnly?: (string | null) | RelationOne;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-one".
*/
export interface RelationOne {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-two".
*/
export interface RelationTwo {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-restricted".
*/
export interface RelationRestricted {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-with-title".
*/
export interface RelationWithTitle {
id: string;
name?: string | null;
meta?: {
title?: string | null;
};
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-filter-false".
*/
export interface RelationFilterFalse {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-filter-true".
*/
export interface RelationFilterTrue {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-updated-externally".
*/
export interface RelationUpdatedExternally {
id: string;
relationPrePopulate?: (string | null) | Collection1;
relationHasMany?: (string | Collection1)[] | null;
relationToManyHasMany?:
| (
| {
relationTo: 'collection-1';
value: string | Collection1;
}
| {
relationTo: 'collection-2';
value: string | Collection2;
}
)[]
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collection-1".
*/
export interface Collection1 {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collection-2".
*/
export interface Collection2 {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "videos".
*/
export interface Video {
id: number;
title?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "podcasts".
*/
export interface Podcast {
id: number;
title?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "mixed-media".
*/
export interface MixedMedia {
id: string;
relatedMedia?:
| (
| {
relationTo: 'videos';
value: number | Video;
}
| {
relationTo: 'podcasts';
value: number | Podcast;
}
)[]
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "versioned-relationship-field".
*/
export interface VersionedRelationshipField {
id: string;
title: string;
relationshipField?:
| {
relationTo: 'collection-1';
value: string | Collection1;
}[]
| null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: string;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents".
*/
export interface PayloadLockedDocument {
id: string;
document?:
| ({
relationTo: 'fields-relationship';
value: string | FieldsRelationship;
} | null)
| ({
relationTo: 'relation-filter-false';
value: string | RelationFilterFalse;
} | null)
| ({
relationTo: 'relation-filter-true';
value: string | RelationFilterTrue;
} | null)
| ({
relationTo: 'relation-one';
value: string | RelationOne;
} | null)
| ({
relationTo: 'relation-two';
value: string | RelationTwo;
} | null)
| ({
relationTo: 'relation-restricted';
value: string | RelationRestricted;
} | null)
| ({
relationTo: 'relation-with-title';
value: string | RelationWithTitle;
} | null)
| ({
relationTo: 'relation-updated-externally';
value: string | RelationUpdatedExternally;
} | null)
| ({
relationTo: 'collection-1';
value: string | Collection1;
} | null)
| ({
relationTo: 'collection-2';
value: string | Collection2;
} | null)
| ({
relationTo: 'videos';
value: number | Video;
} | null)
| ({
relationTo: 'podcasts';
value: number | Podcast;
} | null)
| ({
relationTo: 'mixed-media';
value: string | MixedMedia;
} | null)
| ({
relationTo: 'versioned-relationship-field';
value: string | VersionedRelationshipField;
} | null)
| ({
relationTo: 'users';
value: string | User;
} | null);
globalSlug?: string | null;
user: {
relationTo: 'users';
value: string | User;
};
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences".
*/
export interface PayloadPreference {
id: string;
user: {
relationTo: 'users';
value: string | User;
};
key?: string | null;
value?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-migrations".
*/
export interface PayloadMigration {
id: string;
name?: string | null;
batch?: number | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "fields-relationship_select".
*/
export interface FieldsRelationshipSelect<T extends boolean = true> {
relationship?: T;
relationshipHasMany?: T;
relationshipMultiple?: T;
relationshipHasManyMultiple?: T;
relationshipRestricted?: T;
relationshipWithTitle?: T;
relationshipFiltered?: T;
relationshipFilteredAsync?: T;
relationshipManyFiltered?: T;
filter?: T;
relationshipReadOnly?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-filter-false_select".
*/
export interface RelationFilterFalseSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-filter-true_select".
*/
export interface RelationFilterTrueSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-one_select".
*/
export interface RelationOneSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-two_select".
*/
export interface RelationTwoSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-restricted_select".
*/
export interface RelationRestrictedSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-with-title_select".
*/
export interface RelationWithTitleSelect<T extends boolean = true> {
name?: T;
meta?:
| T
| {
title?: T;
};
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "relation-updated-externally_select".
*/
export interface RelationUpdatedExternallySelect<T extends boolean = true> {
relationPrePopulate?: T;
prePopulate?: T;
relationHasMany?: T;
prePopulateRelationHasMany?: T;
relationToManyHasMany?: T;
prePopulateToMany?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collection-1_select".
*/
export interface Collection1Select<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collection-2_select".
*/
export interface Collection2Select<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "videos_select".
*/
export interface VideosSelect<T extends boolean = true> {
id?: T;
title?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "podcasts_select".
*/
export interface PodcastsSelect<T extends boolean = true> {
id?: T;
title?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "mixed-media_select".
*/
export interface MixedMediaSelect<T extends boolean = true> {
relatedMedia?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "versioned-relationship-field_select".
*/
export interface VersionedRelationshipFieldSelect<T extends boolean = true> {
title?: T;
relationshipField?: T;
updatedAt?: T;
createdAt?: T;
_status?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select".
*/
export interface PayloadLockedDocumentsSelect<T extends boolean = true> {
document?: T;
globalSlug?: T;
user?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences_select".
*/
export interface PayloadPreferencesSelect<T extends boolean = true> {
user?: T;
key?: T;
value?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-migrations_select".
*/
export interface PayloadMigrationsSelect<T extends boolean = true> {
name?: T;
batch?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "auth".
*/
export interface Auth {
[k: string]: unknown;
}
declare module 'payload' {
// @ts-ignore
export interface GeneratedTypes extends Config {}
}