perf!: remove DeepRequired from sanitized collection types - #17541
perf!: remove DeepRequired from sanitized collection types#17541AlessioGr wants to merge 4 commits into
Conversation
| export const executeAccess = async ( | ||
| { id, data, disableErrors, isReadingStaticFile = false, req }: OperationArgs, | ||
| access: Access, | ||
| access?: Access, |
There was a problem hiding this comment.
Not all access fns are required, e.g. readVersions. So this is more accurate
| requireUsername?: boolean | ||
| } | ||
|
|
||
| type AuthCookies = { |
There was a problem hiding this comment.
Just extracting it out so we dont have to do NonNullable<IncomingAuthType['cookies']>
There was a problem hiding this comment.
Any benefit in exporting these?
| beforeValidate: hooks?.beforeValidate ?? [], | ||
| me: hooks?.me ?? [], | ||
| refresh: hooks?.refresh ?? [], | ||
| } satisfies SanitizedCollectionConfig['hooks'] |
There was a problem hiding this comment.
By using satisfies, we get proper errors if this does not match the sanitized types. If we had that before, we would have caught the type <=> runtime mismatch
| // disable duplicate for auth enabled collections by default | ||
| sanitized.disableDuplicate = sanitized.disableDuplicate ?? true | ||
|
|
||
| if (sanitized.auth.loginWithUsername) { |
There was a problem hiding this comment.
Moved into defaults.ts
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
| }: { | ||
| deletedAtPath?: string | ||
| enableTrash: boolean | ||
| enableTrash?: boolean |
There was a problem hiding this comment.
Yep, trash became optional, which matches runtime behavior
| Required<Pick<CollectionConfig, 'admin' | 'custom' | 'indexes' | 'timestamps'>> { | ||
| _sanitized: true | ||
| access: Pick<CollectionAccess, 'admin' | 'readVersions'> & | ||
| Required<Pick<CollectionAccess, 'create' | 'delete' | 'read' | 'unlock' | 'update'>> |
There was a problem hiding this comment.
Are these individual props worth extracting out into their own types to make it more explicit what is happening here?
There was a problem hiding this comment.
I thought about that. They were extracted out, but I felt they are simple enough to inline. Less types you have to know
| requireUsername?: boolean | ||
| } | ||
|
|
||
| type AuthCookies = { |
There was a problem hiding this comment.
Any benefit in exporting these?
This PR removes
DeepRequiredfromSanitizedCollectionConfigand its auth type. It uses shallowPick,Omit, andRequiredtypes so only properties populated during sanitization are required.Why
DeepRequiredrecursively processes large field, hook, admin, and conditional types, adding unnecessary TypeScript checker work.It was also inaccurate.
access.readVersions,auth.cookies.domain,auth.useAPIKey, andauth.depthcould be undefined but were typed as required. Meanwhile,auth.forgotPassword,auth.verify, and normalized username-login options were typed as optional despite always being populated.Breaking change
Code using
SanitizedCollectionConfigmay now need to handleundefinedfor properties Payload does not default.