Repository: payloadcms/payload
File: packages/payload/src/fields/config/sanitize.ts (TypeScript)

Code before:
import {
  fieldAffectsData as _fieldAffectsData,
  fieldIsLocalized,
  fieldIsVirtual,
  tabHasName,
} from './types.js'

type Args = {
  collectionConfig?: CollectionConfig
  config: Config
  existingFieldNames?: Set<string>
  fields: Field[]
  globalConfig?: GlobalConfig
  /**
   * Used to prevent unnecessary sanitization of fields that are not top-level.
   */
  isTopLevelField?: boolean
  joinPath?: string
  /**
   * When not passed in, assume that join are not supported (globals, arrays, blocks)
   */
  joins?: SanitizedJoins
  parentIsLocalized: boolean
  polymorphicJoins?: SanitizedJoin[]
  /**
   * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.
   *
   * @default false
   */
  requireFieldLevelRichTextEditor?: boolean
  /**
   * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
   * so that you can sanitize them together, after the config has been sanitized.
   */
  richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>
  /**
   * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.
   * This validation will be skipped if validRelationships is null.
   */
  validRelationships: null | string[]
}

export const sanitizeFields = async ({
  collectionConfig,
  config,
  existingFieldNames = new Set(),
  fields,
  globalConfig,
  isTopLevelField = true,
  joinPath = '',
  joins,

Review comment (suggestion):
We already have jsdocs for these properties in the `FieldPaths` type. We should use `Pick` here if we can, or some other way of sharing types so that they don't have to be redefined.

Code after:
  fieldAffectsData as _fieldAffectsData,
  fieldIsLocalized,
  fieldIsVirtual,
  tabHasName,
} from './types.js'

type Args = {
  collectionConfig?: CollectionConfig
  config: Config
  existingFieldNames?: Set<string>
  fields: Field[]
  globalConfig?: GlobalConfig
  /**
   * Used to prevent unnecessary sanitization of fields that are not top-level.
   */
  isTopLevelField?: boolean
  joinPath?: string
  /**
   * When not passed in, assume that join are not supported (globals, arrays, blocks)
   */
  joins?: SanitizedJoins
  /**
   * A string of '-' separated indexes representing where
   * to find this field in a given field schema array.
   */
  parentIndexPath?: string
  parentIsLocalized: boolean
  /**
   * Path for parent fields relative to their position in the schema.
   */
  parentSchemaPath?: string
  polymorphicJoins?: SanitizedJoin[]
  /**
   * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.
   *
   * @default false
   */
  requireFieldLevelRichTextEditor?: boolean
  /**
   * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
   * so that you can sanitize them together, after the config has been sanitized.
   */
  richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>
  /**
   * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.
   * This validation will be skipped if validRelationships is null.
   */
  validRelationships: null | string[]
}

export const sanitizeFields = async ({