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

@@ -229,67 +229,68 @@ export interface PayloadMigration {
export interface Collection1Select<T extends boolean = true> {
testing?: T;
title?: T;
meta?:
| T
| {
title?: T;
description?: T;
id?: T;
};
meta?: T | SharedMetaArraySelect<T>;
blocks?:
| T
| {
block1?:
| T
| {
b1title?: T;
b1description?: T;
id?: T;
blockName?: T;
};
block2?:
| T
| {
b2title?: T;
b2description?: T;
id?: T;
blockName?: 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;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "collection2_select".
*/
export interface Collection2Select<T extends boolean = true> {
metaArray?:
| T
| {
title?: T;
description?: T;
id?: T;
};
metaGroup?:
| T
| {
title?: T;
description?: T;
};
metaArray?: T | SharedMetaArraySelect<T>;
metaGroup?: T | SharedMetaSelect<T>;
nestedGroup?:
| T
| {
meta?:
| T
| {
title?: T;
description?: T;
};
meta?: T | SharedMetaSelect<T>;
};
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "SharedMeta_select".
*/
export interface SharedMetaSelect<T extends boolean = true> {
title?: T;
description?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "no-graphql_select".