perf: reduce generated types for select by respecting interfaceName (#9870)

This PR can significantly reduce your `payload-types.ts` file if you
have sharable fields / blocks that use the `interfaceName` property.
Previously we didn't respect it for select types.

Before:
```ts
export interface Collection1Select<T extends boolean = true> {
  testing?: T;
  title?: T;
  meta?:
    | T
    | {
        title?: T;
        description?: T;
        id?: T;
      };
  blocks?:
    | T
    | {
        block1?:
          | T
          | {
              b1title?: T;
              b1description?: T;
              id?: T;
              blockName?: T;
            };
        block2?:
          | T
          | {
              b2title?: T;
              b2description?: T;
              id?: T;
              blockName?: T;
            };
      };
  updatedAt?: T;
  createdAt?: T;
}
```
After:
```ts
export interface Collection1Select<T extends boolean = true> {
  testing?: T;
  title?: T;
  meta?: T | SharedMetaArraySelect<T>;
  blocks?:
    | T
    | {
        block1?: T | SharedMetaBlockSelect<T>;
        block2?: T | AnotherSharedBlockSelect<T>;
      };
  updatedAt?: T;
  createdAt?: T;
}

/**
 * This interface was referenced by `Config`'s JSON-Schema
 * via the `definition` "SharedMetaArray_select".
 */
export interface SharedMetaArraySelect<T extends boolean = true> {
  title?: T;
  description?: T;
  id?: T;
}
/**
 * This interface was referenced by `Config`'s JSON-Schema
 * via the `definition` "SharedMetaBlock_select".
 */
export interface SharedMetaBlockSelect<T extends boolean = true> {
  b1title?: T;
  b1description?: T;
  id?: T;
  blockName?: T;
}
/**
 * This interface was referenced by `Config`'s JSON-Schema
 * via the `definition` "AnotherSharedBlock_select".
 */
export interface AnotherSharedBlockSelect<T extends boolean = true> {
  b2title?: T;
  b2description?: T;
  id?: T;
  blockName?: T;
}
```

Regenerated all the types in `/test`. The diff is noticeable for
`fields` -
https://github.com/payloadcms/payload/pull/9870/files#diff-95beaac24c72c7bd60933e325cdcd94a4c3630a1ce22fabad624ec80cc74fc8c
This commit is contained in:
Sasha
2024-12-16 17:22:17 +02:00
committed by GitHub
parent 727fba7b1c
commit 26a10ed071
7 changed files with 409 additions and 652 deletions

View File

@@ -514,241 +514,16 @@ export interface ArrayField {
*/
export interface BlockField {
id: string;
blocks: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'content';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'subBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'tabs';
}
)[];
duplicate: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'content';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'subBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'tabs';
}
)[];
blocks: (ContentBlock | NumberBlock | SubBlocksBlock | TabsBlock)[];
duplicate: (ContentBlock | NumberBlock | SubBlocksBlock | TabsBlock)[];
collapsedByDefaultBlocks: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedContent';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'localizedNumber';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedSubBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedTabs';
}
)[];
disableSort: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedContent';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'localizedNumber';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedSubBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedTabs';
}
)[];
localizedBlocks: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedContent';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'localizedNumber';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedSubBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedTabs';
}
| LocalizedContentBlock
| LocalizedNumberBlock
| LocalizedSubBlocksBlock
| LocalizedTabsBlock
)[];
disableSort: (LocalizedContentBlock | LocalizedNumberBlock | LocalizedSubBlocksBlock | LocalizedTabsBlock)[];
localizedBlocks: (LocalizedContentBlock | LocalizedNumberBlock | LocalizedSubBlocksBlock | LocalizedTabsBlock)[];
i18nBlocks?:
| {
text?: string | null;
@@ -862,6 +637,128 @@ export interface BlockField {
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "ContentBlock".
*/
export interface ContentBlock {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'content';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "NumberBlock".
*/
export interface NumberBlock {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "SubBlocksBlock".
*/
export interface SubBlocksBlock {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'subBlocks';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "TabsBlock".
*/
export interface TabsBlock {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'tabs';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedContentBlock".
*/
export interface LocalizedContentBlock {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedContent';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedNumberBlock".
*/
export interface LocalizedNumberBlock {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'localizedNumber';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedSubBlocksBlock".
*/
export interface LocalizedSubBlocksBlock {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedSubBlocks';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedTabsBlock".
*/
export interface LocalizedTabsBlock {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedTabs';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "text-fields".
@@ -1563,53 +1460,7 @@ export interface TabsField {
text: string;
id?: string | null;
}[];
blocks: (
| {
text: string;
richText?:
| {
[k: string]: unknown;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'content';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
| {
subBlocks?:
| (
| {
text: string;
id?: string | null;
blockName?: string | null;
blockType: 'text';
}
| {
number: number;
id?: string | null;
blockName?: string | null;
blockType: 'number';
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'subBlocks';
}
| {
textInCollapsible?: string | null;
textInRow?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'tabs';
}
)[];
blocks: (ContentBlock | NumberBlock | SubBlocksBlock | TabsBlock)[];
group: {
number: number;
};
@@ -2200,257 +2051,42 @@ export interface BlockFieldsSelect<T extends boolean = true> {
blocks?:
| T
| {
content?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
subBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
tabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
content?: T | ContentBlockSelect<T>;
number?: T | NumberBlockSelect<T>;
subBlocks?: T | SubBlocksBlockSelect<T>;
tabs?: T | TabsBlockSelect<T>;
};
duplicate?:
| T
| {
content?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
subBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
tabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
content?: T | ContentBlockSelect<T>;
number?: T | NumberBlockSelect<T>;
subBlocks?: T | SubBlocksBlockSelect<T>;
tabs?: T | TabsBlockSelect<T>;
};
collapsedByDefaultBlocks?:
| T
| {
localizedContent?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
localizedNumber?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
localizedSubBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
localizedTabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
localizedContent?: T | LocalizedContentBlockSelect<T>;
localizedNumber?: T | LocalizedNumberBlockSelect<T>;
localizedSubBlocks?: T | LocalizedSubBlocksBlockSelect<T>;
localizedTabs?: T | LocalizedTabsBlockSelect<T>;
};
disableSort?:
| T
| {
localizedContent?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
localizedNumber?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
localizedSubBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
localizedTabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
localizedContent?: T | LocalizedContentBlockSelect<T>;
localizedNumber?: T | LocalizedNumberBlockSelect<T>;
localizedSubBlocks?: T | LocalizedSubBlocksBlockSelect<T>;
localizedTabs?: T | LocalizedTabsBlockSelect<T>;
};
localizedBlocks?:
| T
| {
localizedContent?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
localizedNumber?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
localizedSubBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
localizedTabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
localizedContent?: T | LocalizedContentBlockSelect<T>;
localizedNumber?: T | LocalizedNumberBlockSelect<T>;
localizedSubBlocks?: T | LocalizedSubBlocksBlockSelect<T>;
localizedTabs?: T | LocalizedTabsBlockSelect<T>;
};
i18nBlocks?:
| T
@@ -2588,6 +2224,116 @@ export interface BlockFieldsSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "ContentBlock_select".
*/
export interface ContentBlockSelect<T extends boolean = true> {
text?: T;
richText?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "NumberBlock_select".
*/
export interface NumberBlockSelect<T extends boolean = true> {
number?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "SubBlocksBlock_select".
*/
export interface SubBlocksBlockSelect<T extends boolean = true> {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "TabsBlock_select".
*/
export interface TabsBlockSelect<T extends boolean = true> {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedContentBlock_select".
*/
export interface LocalizedContentBlockSelect<T extends boolean = true> {
text?: T;
richText?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedNumberBlock_select".
*/
export interface LocalizedNumberBlockSelect<T extends boolean = true> {
number?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedSubBlocksBlock_select".
*/
export interface LocalizedSubBlocksBlockSelect<T extends boolean = true> {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "localizedTabsBlock_select".
*/
export interface LocalizedTabsBlockSelect<T extends boolean = true> {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "checkbox-fields_select".
@@ -3145,53 +2891,10 @@ export interface TabsFieldsSelect<T extends boolean = true> {
blocks?:
| T
| {
content?:
| T
| {
text?: T;
richText?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
subBlocks?:
| T
| {
subBlocks?:
| T
| {
text?:
| T
| {
text?: T;
id?: T;
blockName?: T;
};
number?:
| T
| {
number?: T;
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
tabs?:
| T
| {
textInCollapsible?: T;
textInRow?: T;
id?: T;
blockName?: T;
};
content?: T | ContentBlockSelect<T>;
number?: T | NumberBlockSelect<T>;
subBlocks?: T | SubBlocksBlockSelect<T>;
tabs?: T | TabsBlockSelect<T>;
};
group?:
| T
@@ -3201,24 +2904,7 @@ export interface TabsFieldsSelect<T extends boolean = true> {
textInRow?: T;
numberInRow?: T;
json?: T;
tab?:
| T
| {
array?:
| T
| {
text?: T;
id?: T;
};
text?: T;
defaultValue?: T;
arrayInRow?:
| T
| {
textInArrayInRow?: T;
id?: T;
};
};
tab?: T | TabWithNameSelect<T>;
namedTabWithDefaultValue?:
| T
| {
@@ -3268,6 +2954,26 @@ export interface TabsFieldsSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "TabWithName_select".
*/
export interface TabWithNameSelect<T extends boolean = true> {
array?:
| T
| {
text?: T;
id?: T;
};
text?: T;
defaultValue?: T;
arrayInRow?:
| T
| {
textInArrayInRow?: T;
id?: T;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "text-fields_select".