{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { FieldAffectingData, FlattenedField, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { generateJobsJSONSchemas } from '../queues/config/generateJobsJSONSchemas.js'\nimport { flattenAllFields } from './flattenAllFields.js'\nimport { formatNames } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\nimport { optionsAreEqual } from './optionsAreEqual.js'\n\nconst fieldIsRequired = (field: FlattenedField): boolean => {\n  const isConditional = Boolean(field?.admin && field?.admin?.condition)\n  if (isConditional) {\n    return false\n  }\n\n  const isMarkedRequired = 'required' in field && field.required === true\n  if (fieldAffectsData(field) && isMarkedRequired) {\n    return true\n  }\n\n  // if any subfields are required, this field is required\n  if ('fields' in field && field.type !== 'array') {\n    return field.flattenedFields.some((subField) => fieldIsRequired(subField))\n  }\n\n  return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n  return options.map((option) => {\n    if (typeof option === 'object' && 'value' in option) {\n      return option.value\n    }\n\n    return option\n  })\n}\n\nfunction generateEntitySchemas(\n  entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n  const properties = [...entities].reduce(\n    (acc, { slug }) => {\n      acc[slug] = {\n        $ref: `#/definitions/${slug}`,\n      }\n\n      return acc\n    },\n    {} as Record<string, JSONSchema4>,\n  )\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties,\n    required: Object.keys(properties),\n  }\n}\n\nfunction generateEntitySelectSchemas(\n  entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n  const properties = [...entities].reduce(\n    (acc, { slug }) => {\n      acc[slug] = {\n        $ref: `#/definitions/${slug}_select`,\n      }\n\n      return acc\n    },\n    {} as Record<string, JSONSchema4>,\n  )\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties,\n    required: Object.keys(properties),\n  }\n}\n\nfunction generateCollectionJoinsSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n  const properties = [...collections].reduce<Record<string, JSONSchema4>>(\n    (acc, { slug, joins, polymorphicJoins }) => {\n      const schema = {\n        type: 'object',\n        additionalProperties: false,\n        properties: {},\n        required: [] as string[],\n      } satisfies JSONSchema4\n\n      for (const collectionSlug in joins) {\n        for (const join of joins[collectionSlug]!) {\n          ;(schema.properties as any)[join.joinPath] = {\n            type: 'string',\n            enum: [collectionSlug],\n          }\n          schema.required.push(join.joinPath)\n        }\n      }\n\n      for (const join of polymorphicJoins) {\n        ;(schema.properties as any)[join.joinPath] = {\n          type: 'string',\n          enum: join.field.collection,\n        }\n        schema.required.push(join.joinPath)\n      }\n\n      if (Object.keys(schema.properties).length > 0) {\n        acc[slug] = schema\n      }\n\n      return acc\n    },\n    {},\n  )\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties,\n    required: Object.keys(properties),\n  }\n}\n\nconst widgetWidths = ['x-small', 'small', 'medium', 'large', 'x-large', 'full'] as const\n\nfunction getAllowedWidgetWidths({\n  maxWidth,\n  minWidth,\n}: {\n  maxWidth?: (typeof widgetWidths)[number]\n  minWidth?: (typeof widgetWidths)[number]\n}): string[] {\n  const minIndex = minWidth ? widgetWidths.indexOf(minWidth) : 0\n  const maxIndex = maxWidth ? widgetWidths.indexOf(maxWidth) : widgetWidths.length - 1\n\n  if (minIndex === -1 || maxIndex === -1 || minIndex > maxIndex) {\n    return [...widgetWidths]\n  }\n\n  return widgetWidths.slice(minIndex, maxIndex + 1)\n}\n\nfunction generateWidgetSchemas({\n  collectionIDFieldTypes,\n  config,\n  i18n,\n  interfaceNameDefinitions,\n  opts = {},\n}: {\n  collectionIDFieldTypes: { [key: string]: 'number' | 'string' }\n  config: SanitizedConfig\n  i18n?: I18n\n  interfaceNameDefinitions: Map<string, JSONSchema4>\n  opts?: ConfigToJSONSchemaOptions\n}): {\n  definitions: Record<string, JSONSchema4>\n  schema: JSONSchema4\n} {\n  const widgets = config.admin?.dashboard?.widgets ?? []\n  const definitions: Record<string, JSONSchema4> = {}\n  const properties: Record<string, JSONSchema4> = {}\n\n  for (const widget of widgets) {\n    const definition = `${widget.slug}_widget`\n    const widthEnum = getAllowedWidgetWidths({\n      maxWidth: widget.maxWidth,\n      minWidth: widget.minWidth,\n    })\n    let dataSchema: JSONSchema4\n\n    if (widget.fields?.length) {\n      const widgetFieldSchemas = fieldsToJSONSchema(\n        collectionIDFieldTypes,\n        flattenAllFields({ fields: widget.fields }),\n        interfaceNameDefinitions,\n        config,\n        i18n,\n        opts,\n      )\n\n      dataSchema = {\n        type: 'object',\n        additionalProperties: false,\n        ...widgetFieldSchemas,\n      }\n    } else {\n      dataSchema = {\n        type: 'object',\n        additionalProperties: true,\n      }\n    }\n\n    definitions[definition] = {\n      type: 'object',\n      additionalProperties: false,\n      properties: {\n        data: dataSchema,\n        width: {\n          type: 'string',\n          enum: widthEnum,\n        },\n      },\n      required: ['width'],\n    }\n\n    properties[widget.slug] = {\n      $ref: `#/definitions/${definition}`,\n    }\n  }\n\n  return {\n    definitions,\n    schema: {\n      type: 'object',\n      additionalProperties: false,\n      properties,\n      required: Object.keys(properties),\n    },\n  }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n  if (localization && 'locales' in localization && localization?.locales) {\n    const localesFromConfig = localization?.locales\n\n    const locales = [...localesFromConfig].map((locale) => {\n      return locale.code\n    }, [])\n\n    return {\n      type: 'string',\n      enum: locales,\n    }\n  }\n\n  return {\n    type: 'null',\n  }\n}\n\nfunction generateFallbackLocaleEntitySchemas(\n  localization: SanitizedConfig['localization'],\n): JSONSchema4 {\n  if (localization && 'localeCodes' in localization && localization?.localeCodes) {\n    const localeCodes = [...localization.localeCodes].map((localeCode) => {\n      return localeCode\n    }, [])\n\n    return {\n      oneOf: [\n        { type: 'string', enum: ['false', 'none', 'null'] },\n        { type: 'boolean', enum: [false] },\n        { type: 'null' },\n        { type: 'string', enum: localeCodes },\n        { type: 'array', items: { type: 'string', enum: localeCodes } },\n      ],\n    }\n  }\n\n  return {\n    type: 'null',\n  }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n  const properties: JSONSchema4[] = [...entities]\n    .filter(({ auth }) => Boolean(auth))\n    .map(({ slug }) => {\n      return { $ref: `#/definitions/${slug}` }\n    }, {})\n\n  return {\n    oneOf: properties,\n  }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n  const defaultIDType: JSONSchema4 =\n    config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties: {\n      defaultIDType,\n    },\n    required: ['defaultIDType'],\n  }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n  fieldType: JSONSchema4TypeName,\n  isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n  const fieldTypes = [fieldType]\n  if (isRequired) {\n    return fieldType\n  }\n  fieldTypes.push('null')\n  return fieldTypes\n}\n\nfunction entityOrFieldToJsDocs({\n  entity,\n  i18n,\n}: {\n  entity: FlattenedField | SanitizedCollectionConfig | SanitizedGlobalConfig\n  i18n?: I18n\n}): string | undefined {\n  let description: string | undefined = undefined\n  if (entity?.admin?.description) {\n    if (typeof entity?.admin?.description === 'string') {\n      description = entity?.admin?.description\n    } else if (typeof entity?.admin?.description === 'object') {\n      if (entity?.admin?.description?.en) {\n        description = entity?.admin?.description?.en\n      } else if (entity?.admin?.description?.[i18n!.language]) {\n        description = entity?.admin?.description?.[i18n!.language]\n      }\n    } else if (typeof entity?.admin?.description === 'function' && i18n) {\n      // do not evaluate description functions for generating JSDocs. The output of\n      // those can differ depending on where and when they are called, creating\n      // inconsistencies in the generated JSDocs.\n    }\n  }\n  return description\n}\n\ntype ConfigToJSONSchemaOptions = {\n  forceInlineBlocks?: boolean\n}\n\nexport function fieldsToJSONSchema(\n  /**\n   * Used for relationship fields, to determine whether to use a string or number type for the ID.\n   * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n   * if they have custom ID fields.\n   */\n  collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n  fields: FlattenedField[],\n  /**\n   * Allows you to define new top-level interfaces that can be re-used in the output schema.\n   */\n  interfaceNameDefinitions: Map<string, JSONSchema4>,\n  config?: SanitizedConfig,\n  i18n?: I18n,\n  opts: ConfigToJSONSchemaOptions = {},\n): {\n  properties: {\n    [k: string]: JSONSchema4\n  }\n  required: string[]\n} {\n  const requiredFieldNames = new Set<string>()\n\n  return {\n    properties: Object.fromEntries(\n      fields.reduce((fieldSchemas, field, index) => {\n        const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n\n        const fieldDescription = entityOrFieldToJsDocs({ entity: field, i18n })\n        const baseFieldSchema: JSONSchema4 = {}\n        if (fieldDescription) {\n          baseFieldSchema.description = fieldDescription\n        }\n\n        let fieldSchema: JSONSchema4\n\n        switch (field.type) {\n          case 'array': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('array', isRequired),\n              items: {\n                type: 'object',\n                additionalProperties: false,\n                ...fieldsToJSONSchema(\n                  collectionIDFieldTypes,\n                  field.flattenedFields,\n                  interfaceNameDefinitions,\n                  config,\n                  i18n,\n                  opts,\n                ),\n              },\n            }\n\n            if (field.interfaceName) {\n              interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n              fieldSchema = {\n                $ref: `#/definitions/${field.interfaceName}`,\n              }\n            }\n            break\n          }\n          case 'blocks': {\n            // Check for a case where no blocks are provided.\n            // We need to generate an empty array for this case, note that JSON schema 4 doesn't support empty arrays\n            // so the best we can get is `unknown[]`\n            const hasBlocks = Boolean(\n              field.blockReferences ? field.blockReferences.length : field.blocks.length,\n            )\n\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('array', isRequired),\n              items: hasBlocks\n                ? {\n                    oneOf: (field.blockReferences ?? field.blocks).map((block) => {\n                      if (typeof block === 'string') {\n                        const resolvedBlock = config?.blocks?.find((b) => b.slug === block)\n\n                        if (!resolvedBlock) {\n                          return {}\n                        }\n\n                        if (!opts.forceInlineBlocks) {\n                          return {\n                            $ref: `#/definitions/${resolvedBlock.interfaceName ?? resolvedBlock.slug}`,\n                          }\n                        }\n\n                        block = resolvedBlock\n                      }\n                      const blockFieldSchemas = fieldsToJSONSchema(\n                        collectionIDFieldTypes,\n                        block.flattenedFields,\n                        interfaceNameDefinitions,\n                        config,\n                        i18n,\n                        opts,\n                      )\n\n                      const blockSchema: JSONSchema4 = {\n                        type: 'object',\n                        additionalProperties: false,\n                        properties: {\n                          ...blockFieldSchemas.properties,\n                          blockType: {\n                            const: block.slug,\n                          },\n                        },\n                        required: ['blockType', ...blockFieldSchemas.required],\n                      }\n\n                      if (!opts.forceInlineBlocks && block.interfaceName) {\n                        interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n                        return {\n                          $ref: `#/definitions/${block.interfaceName}`,\n                        }\n                      }\n\n                      return blockSchema\n                    }),\n                  }\n                : {},\n            }\n            break\n          }\n          case 'checkbox': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('boolean', isRequired),\n            }\n            break\n          }\n          case 'code':\n          case 'date':\n          case 'email':\n          case 'textarea': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('string', isRequired),\n            }\n            break\n          }\n\n          case 'group': {\n            if (fieldAffectsData(field)) {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: 'object',\n                additionalProperties: false,\n                ...fieldsToJSONSchema(\n                  collectionIDFieldTypes,\n                  field.flattenedFields,\n                  interfaceNameDefinitions,\n                  config,\n                  i18n,\n                  opts,\n                ),\n              }\n\n              if (field.interfaceName) {\n                interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n                fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n              }\n            }\n            break\n          }\n\n          case 'join': {\n            let items: JSONSchema4\n\n            if (Array.isArray(field.collection)) {\n              items = {\n                oneOf: field.collection.map((collection) => ({\n                  type: 'object',\n                  additionalProperties: false,\n                  properties: {\n                    relationTo: {\n                      const: collection,\n                    },\n                    value: {\n                      oneOf: [\n                        {\n                          type: collectionIDFieldTypes[collection],\n                        },\n                        {\n                          $ref: `#/definitions/${collection}`,\n                        },\n                      ],\n                    },\n                  },\n                  required: ['collectionSlug', 'value'],\n                })),\n              }\n            } else {\n              items = {\n                oneOf: [\n                  {\n                    type: collectionIDFieldTypes[field.collection],\n                  },\n                  {\n                    $ref: `#/definitions/${field.collection}`,\n                  },\n                ],\n              }\n            }\n\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: 'object',\n              additionalProperties: false,\n              properties: {\n                docs: {\n                  type: 'array',\n                  items,\n                },\n                hasNextPage: { type: 'boolean' },\n                totalDocs: { type: 'number' },\n              },\n            }\n            break\n          }\n\n          case 'json': {\n            fieldSchema = field.jsonSchema?.schema || {\n              ...baseFieldSchema,\n              type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n            }\n            break\n          }\n\n          case 'number': {\n            if (field.hasMany === true) {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('array', isRequired),\n                items: { type: 'number' },\n              }\n            } else {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('number', isRequired),\n              }\n            }\n            break\n          }\n\n          case 'point': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('array', isRequired),\n              items: [\n                {\n                  type: 'number',\n                },\n                {\n                  type: 'number',\n                },\n              ],\n              maxItems: 2,\n              minItems: 2,\n            }\n            break\n          }\n\n          case 'radio': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: withNullableJSONSchemaType('string', isRequired),\n              enum: buildOptionEnums(field.options),\n            }\n\n            if (field.interfaceName) {\n              interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n              fieldSchema = {\n                $ref: `#/definitions/${field.interfaceName}`,\n              }\n            }\n\n            break\n          }\n          case 'relationship':\n          case 'upload': {\n            if (Array.isArray(field.relationTo)) {\n              if (field.hasMany) {\n                fieldSchema = {\n                  ...baseFieldSchema,\n                  type: withNullableJSONSchemaType('array', isRequired),\n                  items: {\n                    oneOf: field.relationTo.map((relation) => {\n                      return {\n                        type: 'object',\n                        additionalProperties: false,\n                        properties: {\n                          relationTo: {\n                            const: relation,\n                          },\n                          value: {\n                            oneOf: [\n                              {\n                                type: collectionIDFieldTypes[relation],\n                              },\n                              {\n                                $ref: `#/definitions/${relation}`,\n                              },\n                            ],\n                          },\n                        },\n                        required: ['value', 'relationTo'],\n                      }\n                    }),\n                  },\n                }\n              } else {\n                fieldSchema = {\n                  ...baseFieldSchema,\n                  oneOf: field.relationTo.map((relation) => {\n                    return {\n                      type: withNullableJSONSchemaType('object', isRequired),\n                      additionalProperties: false,\n                      properties: {\n                        relationTo: {\n                          const: relation,\n                        },\n                        value: {\n                          oneOf: [\n                            {\n                              type: collectionIDFieldTypes[relation],\n                            },\n                            {\n                              $ref: `#/definitions/${relation}`,\n                            },\n                          ],\n                        },\n                      },\n                      required: ['value', 'relationTo'],\n                    }\n                  }),\n                }\n              }\n            } else if (field.hasMany) {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('array', isRequired),\n                items: {\n                  oneOf: [\n                    {\n                      type: collectionIDFieldTypes[field.relationTo],\n                    },\n                    {\n                      $ref: `#/definitions/${field.relationTo}`,\n                    },\n                  ],\n                },\n              }\n            } else {\n              fieldSchema = {\n                ...baseFieldSchema,\n                oneOf: [\n                  {\n                    type: withNullableJSONSchemaType(\n                      collectionIDFieldTypes[field.relationTo]!,\n                      isRequired,\n                    ),\n                  },\n                  { $ref: `#/definitions/${field.relationTo}` },\n                ],\n              }\n            }\n\n            break\n          }\n          case 'richText': {\n            if (!field?.editor) {\n              throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n            }\n            if (typeof field.editor === 'function') {\n              throw new Error('Attempted to access unsanitized rich text editor.')\n            }\n            if (field.editor.outputSchema) {\n              fieldSchema = {\n                ...baseFieldSchema,\n                ...field.editor.outputSchema({\n                  collectionIDFieldTypes,\n                  config,\n                  field,\n                  i18n,\n                  interfaceNameDefinitions,\n                  isRequired,\n                }),\n              }\n            } else {\n              // Maintain backwards compatibility with existing rich text editors\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('array', isRequired),\n                items: {\n                  type: 'object',\n                },\n              }\n            }\n\n            break\n          }\n\n          case 'select': {\n            const optionEnums = buildOptionEnums(field.options)\n            // We get the previous field to check for a date in the case of a timezone select\n            // This works because timezone selects are always inserted right after a date with 'timezone: true'\n            const previousField = fields?.[index - 1]\n            const isTimezoneField =\n              previousField?.type === 'date' && previousField.timezone && field.name.includes('_tz')\n\n            // Check if the timezone field's options match the global config's supported timezones\n            const hasMatchingGlobalTimezones =\n              isTimezoneField &&\n              config &&\n              optionsAreEqual(field.options, config.admin?.timezones?.supportedTimezones)\n\n            // Timezone selects should reference the supportedTimezones definition\n            // only if the field's options match the global config\n            if (isTimezoneField && hasMatchingGlobalTimezones) {\n              fieldSchema = {\n                $ref: `#/definitions/supportedTimezones`,\n              }\n            } else {\n              if (field.hasMany) {\n                fieldSchema = {\n                  ...baseFieldSchema,\n                  type: withNullableJSONSchemaType('array', isRequired),\n                  items: {\n                    type: 'string',\n                  },\n                }\n                if (optionEnums?.length) {\n                  ;(fieldSchema.items as JSONSchema4).enum = optionEnums\n                }\n              } else {\n                fieldSchema = {\n                  ...baseFieldSchema,\n                  type: withNullableJSONSchemaType('string', isRequired),\n                }\n                if (optionEnums?.length) {\n                  fieldSchema.enum = optionEnums\n                }\n              }\n\n              if (field.interfaceName) {\n                interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n                fieldSchema = {\n                  $ref: `#/definitions/${field.interfaceName}`,\n                }\n              }\n              break\n            }\n\n            break\n          }\n          case 'tab': {\n            fieldSchema = {\n              ...baseFieldSchema,\n              type: 'object',\n              additionalProperties: false,\n              ...fieldsToJSONSchema(\n                collectionIDFieldTypes,\n                field.flattenedFields,\n                interfaceNameDefinitions,\n                config,\n                i18n,\n                opts,\n              ),\n            }\n\n            if (field.interfaceName) {\n              interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n              fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n            }\n            break\n          }\n\n          case 'text':\n            if (field.hasMany === true) {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('array', isRequired),\n                items: { type: 'string' },\n              }\n            } else {\n              fieldSchema = {\n                ...baseFieldSchema,\n                type: withNullableJSONSchemaType('string', isRequired),\n              }\n            }\n            break\n\n          default: {\n            break\n          }\n        }\n\n        if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n          for (const schema of field.typescriptSchema) {\n            fieldSchema = schema({ jsonSchema: fieldSchema! })\n          }\n        }\n\n        if (fieldSchema! && fieldAffectsData(field)) {\n          if (isRequired && fieldSchema.required !== false) {\n            requiredFieldNames.add(field.name)\n          }\n          fieldSchemas.set(field.name, fieldSchema)\n        }\n\n        return fieldSchemas\n      }, new Map<string, JSONSchema4>()),\n    ),\n    required: Array.from(requiredFieldNames),\n  }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n  config: SanitizedConfig,\n  entity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n  interfaceNameDefinitions: Map<string, JSONSchema4>,\n  defaultIDType: 'number' | 'text',\n  collectionIDFieldTypes?: { [key: string]: 'number' | 'string' },\n  i18n?: I18n,\n  opts: ConfigToJSONSchemaOptions = {},\n): JSONSchema4 {\n  if (!collectionIDFieldTypes) {\n    collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n  }\n\n  const title = entity.typescript?.interface\n    ? entity.typescript.interface\n    : formatNames(entity.slug).singular\n\n  let mutableFields = [...entity.flattenedFields]\n\n  const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n  const customIdField = mutableFields.find((field) => field.name === 'id') as FieldAffectingData\n\n  if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n    mutableFields = mutableFields.map((field) => {\n      if (field === customIdField) {\n        return { ...field, required: true }\n      }\n\n      return field\n    })\n  } else {\n    mutableFields.unshift(idField)\n  }\n\n  // mark timestamp fields required\n  if ('timestamps' in entity && entity.timestamps !== false) {\n    mutableFields = mutableFields.map((field) => {\n      if (field.name === 'createdAt' || field.name === 'updatedAt') {\n        return {\n          ...field,\n          required: true,\n        }\n      }\n      return field\n    })\n  }\n\n  if (\n    'auth' in entity &&\n    entity.auth &&\n    (!entity.auth?.disableLocalStrategy ||\n      (typeof entity.auth?.disableLocalStrategy === 'object' &&\n        entity.auth.disableLocalStrategy.enableFields))\n  ) {\n    mutableFields.push({\n      name: 'password',\n      type: 'text',\n    })\n  }\n\n  const isAuthCollection = 'auth' in entity && entity.auth\n\n  const fieldsSchema = fieldsToJSONSchema(\n    collectionIDFieldTypes,\n    mutableFields,\n    interfaceNameDefinitions,\n    config,\n    i18n,\n    opts,\n  )\n\n  // Add collection property to auth collections\n  if (isAuthCollection) {\n    fieldsSchema.properties = {\n      ...fieldsSchema.properties,\n      collection: { type: 'string', enum: [entity.slug] },\n    }\n    fieldsSchema.required = [...(fieldsSchema.required || []), 'collection']\n  }\n\n  const jsonSchema: JSONSchema4 = {\n    type: 'object',\n    additionalProperties: false,\n    title,\n    ...fieldsSchema,\n  }\n\n  const entityDescription = entityOrFieldToJsDocs({ entity, i18n })\n\n  if (entityDescription) {\n    jsonSchema.description = entityDescription\n  }\n\n  return jsonSchema\n}\n\nexport function fieldsToSelectJSONSchema({\n  config,\n  fields,\n  interfaceNameDefinitions,\n}: {\n  config: SanitizedConfig\n  fields: FlattenedField[]\n  interfaceNameDefinitions: Map<string, JSONSchema4>\n}): JSONSchema4 {\n  const schema: JSONSchema4 = {\n    type: 'object',\n    additionalProperties: false,\n    properties: {},\n  }\n\n  for (const field of fields) {\n    switch (field.type) {\n      case 'array':\n      case 'group':\n      case 'tab': {\n        let fieldSchema: JSONSchema4 = fieldsToSelectJSONSchema({\n          config,\n          fields: field.flattenedFields,\n          interfaceNameDefinitions,\n        })\n\n        if (field.interfaceName) {\n          const definition = `${field.interfaceName}_select`\n          interfaceNameDefinitions.set(definition, fieldSchema)\n\n          fieldSchema = {\n            $ref: `#/definitions/${definition}`,\n          }\n        }\n\n        schema.properties![field.name] = {\n          oneOf: [\n            {\n              type: 'boolean',\n            },\n            fieldSchema,\n          ],\n        }\n\n        break\n      }\n\n      case 'blocks': {\n        const blocksSchema: JSONSchema4 = {\n          type: 'object',\n          additionalProperties: false,\n          properties: {},\n        }\n\n        for (const block of field.blockReferences ?? field.blocks) {\n          if (typeof block === 'string') {\n            continue // TODO\n          }\n\n          let blockSchema = fieldsToSelectJSONSchema({\n            config,\n            fields: block.flattenedFields,\n            interfaceNameDefinitions,\n          })\n\n          if (block.interfaceName) {\n            const definition = `${block.interfaceName}_select`\n            interfaceNameDefinitions.set(definition, blockSchema)\n            blockSchema = {\n              $ref: `#/definitions/${definition}`,\n            }\n          }\n\n          blocksSchema.properties![block.slug] = {\n            oneOf: [\n              {\n                type: 'boolean',\n              },\n              blockSchema,\n            ],\n          }\n        }\n\n        schema.properties![field.name] = {\n          oneOf: [\n            {\n              type: 'boolean',\n            },\n            blocksSchema,\n          ],\n        }\n\n        break\n      }\n\n      default:\n        schema.properties![field.name] = {\n          type: 'boolean',\n        }\n        break\n    }\n  }\n\n  return schema\n}\n\nconst fieldType: JSONSchema4 = {\n  type: 'string',\n  required: false,\n}\nconst generateAuthFieldTypes = ({\n  type,\n  loginWithUsername,\n}: {\n  loginWithUsername: Auth['loginWithUsername']\n  type: 'forgotOrUnlock' | 'login' | 'register'\n}): JSONSchema4 => {\n  if (loginWithUsername) {\n    switch (type) {\n      case 'forgotOrUnlock': {\n        if (loginWithUsername.allowEmailLogin) {\n          // allow email or username for unlock/forgot-password\n          return {\n            additionalProperties: false,\n            oneOf: [\n              {\n                additionalProperties: false,\n                properties: { email: fieldType },\n                required: ['email'],\n              },\n              {\n                additionalProperties: false,\n                properties: { username: fieldType },\n                required: ['username'],\n              },\n            ],\n          }\n        } else {\n          // allow only username for unlock/forgot-password\n          return {\n            additionalProperties: false,\n            properties: { username: fieldType },\n            required: ['username'],\n          }\n        }\n      }\n\n      case 'login': {\n        if (loginWithUsername.allowEmailLogin) {\n          // allow username or email and require password for login\n          return {\n            additionalProperties: false,\n            oneOf: [\n              {\n                additionalProperties: false,\n                properties: { email: fieldType, password: fieldType },\n                required: ['email', 'password'],\n              },\n              {\n                additionalProperties: false,\n                properties: { password: fieldType, username: fieldType },\n                required: ['username', 'password'],\n              },\n            ],\n          }\n        } else {\n          // allow only username and password for login\n          return {\n            additionalProperties: false,\n            properties: {\n              password: fieldType,\n              username: fieldType,\n            },\n            required: ['username', 'password'],\n          }\n        }\n      }\n\n      case 'register': {\n        const requiredFields: ('email' | 'password' | 'username')[] = ['password']\n        const properties: {\n          email?: JSONSchema4['properties']\n          password?: JSONSchema4['properties']\n          username?: JSONSchema4['properties']\n        } = {\n          password: fieldType,\n          username: fieldType,\n        }\n\n        if (loginWithUsername.requireEmail) {\n          requiredFields.push('email')\n        }\n        if (loginWithUsername.requireUsername) {\n          requiredFields.push('username')\n        }\n        if (loginWithUsername.requireEmail || loginWithUsername.allowEmailLogin) {\n          properties.email = fieldType\n        }\n\n        return {\n          additionalProperties: false,\n          properties,\n          required: requiredFields,\n        }\n      }\n    }\n  }\n\n  // default email (and password for login/register)\n  return {\n    additionalProperties: false,\n    properties: { email: fieldType, password: fieldType },\n    required: ['email', 'password'],\n  }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n  config: SanitizedCollectionConfig,\n): JSONSchema4 {\n  const loginWithUsername = config.auth?.loginWithUsername\n  const loginUserFields: JSONSchema4 = generateAuthFieldTypes({ type: 'login', loginWithUsername })\n  const forgotOrUnlockUserFields: JSONSchema4 = generateAuthFieldTypes({\n    type: 'forgotOrUnlock',\n    loginWithUsername,\n  })\n  const registerUserFields: JSONSchema4 = generateAuthFieldTypes({\n    type: 'register',\n    loginWithUsername,\n  })\n\n  const properties: JSONSchema4['properties'] = {\n    forgotPassword: forgotOrUnlockUserFields,\n    login: loginUserFields,\n    registerFirstUser: registerUserFields,\n    unlock: forgotOrUnlockUserFields,\n  }\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties,\n    required: Object.keys(properties),\n    title: `${formatNames(config.slug).singular}AuthOperations`,\n  }\n}\n\n// Generates the JSON Schema for supported timezones\nexport function timezonesToJSONSchema(\n  supportedTimezones: SanitizedConfig['admin']['timezones']['supportedTimezones'],\n): JSONSchema4 {\n  return {\n    description: 'Supported timezones in IANA format.',\n    enum: supportedTimezones.map((timezone) =>\n      typeof timezone === 'string' ? timezone : timezone.value,\n    ),\n  }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n  const properties = collections.reduce(\n    (acc, collection) => {\n      if (collection.auth) {\n        acc[collection.slug] = {\n          $ref: `#/definitions/auth/${collection.slug}`,\n        }\n      }\n      return acc\n    },\n    {} as Record<string, JSONSchema4>,\n  )\n\n  return {\n    type: 'object',\n    additionalProperties: false,\n    properties,\n    required: Object.keys(properties),\n  }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n  config: SanitizedConfig,\n  defaultIDType?: 'number' | 'text',\n  i18n?: I18n,\n  opts: ConfigToJSONSchemaOptions = {},\n): JSONSchema4 {\n  // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n  const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n  //  Used for relationship fields, to determine whether to use a string or number type for the ID.\n  const collectionIDFieldTypes = getCollectionIDFieldTypes({\n    config,\n    defaultIDType: defaultIDType!,\n  })\n\n  // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n  // types to be inlined inside the `Config` type\n\n  const entities: {\n    entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n    type: 'collection' | 'global'\n  }[] = [\n    ...config.globals.map((global) => ({ type: 'global' as const, entity: global })),\n    ...config.collections.map((collection) => ({\n      type: 'collection' as const,\n      entity: collection,\n    })),\n  ]\n\n  const entityDefinitions: { [k: string]: JSONSchema4 } = entities.reduce(\n    (acc, { type, entity }) => {\n      acc[entity.slug] = entityToJSONSchema(\n        config,\n        entity,\n        interfaceNameDefinitions,\n        defaultIDType!,\n        collectionIDFieldTypes,\n        i18n,\n        opts,\n      )\n      const select = fieldsToSelectJSONSchema({\n        config,\n        fields: entity.flattenedFields,\n        interfaceNameDefinitions,\n      })\n\n      if (type === 'global') {\n        select.properties!.globalType = {\n          type: 'boolean',\n        }\n      }\n\n      acc[`${entity.slug}_select`] = {\n        type: 'object',\n        additionalProperties: false,\n        ...select,\n      }\n\n      return acc\n    },\n    {} as Record<string, JSONSchema4>,\n  )\n\n  const timezoneDefinitions = timezonesToJSONSchema(config.admin.timezones.supportedTimezones)\n  const widgetSchemas = generateWidgetSchemas({\n    collectionIDFieldTypes,\n    config,\n    i18n,\n    interfaceNameDefinitions,\n    opts,\n  })\n\n  const authOperationDefinitions = [...config.collections]\n    .filter(({ auth }) => Boolean(auth))\n    .reduce(\n      (acc, authCollection) => {\n        acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n        return acc\n      },\n      { auth: {} as Record<string, JSONSchema4> },\n    )\n\n  const jobsSchemas = config.jobs\n    ? generateJobsJSONSchemas(\n        config,\n        config.jobs,\n        interfaceNameDefinitions,\n        collectionIDFieldTypes,\n        i18n,\n      )\n    : {}\n\n  const blocksDefinition: JSONSchema4 | undefined = {\n    type: 'object',\n    additionalProperties: false,\n    properties: {},\n    required: [],\n  }\n  if (config?.blocks?.length) {\n    for (const block of config.blocks) {\n      const blockFieldSchemas = fieldsToJSONSchema(\n        collectionIDFieldTypes,\n        block.flattenedFields,\n        interfaceNameDefinitions,\n        config,\n        i18n,\n        opts,\n      )\n\n      const blockSchema: JSONSchema4 = {\n        type: 'object',\n        additionalProperties: false,\n        properties: {\n          ...blockFieldSchemas.properties,\n          blockType: {\n            const: block.slug,\n          },\n        },\n        required: ['blockType', ...blockFieldSchemas.required],\n      }\n\n      const interfaceName = block.interfaceName ?? block.slug\n      interfaceNameDefinitions.set(interfaceName, blockSchema)\n\n      blocksDefinition.properties![block.slug] = {\n        $ref: `#/definitions/${interfaceName}`,\n      }\n      ;(blocksDefinition.required as string[]).push(block.slug)\n    }\n  }\n\n  let jsonSchema: JSONSchema4 = {\n    additionalProperties: false,\n    definitions: {\n      supportedTimezones: timezoneDefinitions,\n      ...entityDefinitions,\n      ...widgetSchemas.definitions,\n      ...Object.fromEntries(interfaceNameDefinitions),\n      ...authOperationDefinitions,\n    },\n    // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n    type: 'object',\n    properties: {\n      auth: generateAuthOperationSchemas(config.collections),\n      blocks: blocksDefinition,\n      collections: generateEntitySchemas(config.collections || []),\n      collectionsJoins: generateCollectionJoinsSchemas(config.collections || []),\n      collectionsSelect: generateEntitySelectSchemas(config.collections || []),\n      db: generateDbEntitySchema(config),\n      fallbackLocale: generateFallbackLocaleEntitySchemas(config.localization),\n      globals: generateEntitySchemas(config.globals || []),\n      globalsSelect: generateEntitySelectSchemas(config.globals || []),\n      locale: generateLocaleEntitySchemas(config.localization),\n      widgets: widgetSchemas.schema,\n      ...(config.typescript?.strictDraftTypes\n        ? {\n            strictDraftTypes: {\n              type: 'boolean',\n              const: true,\n            },\n          }\n        : {}),\n      user: generateAuthEntitySchemas(config.collections),\n    },\n    required: [\n      'user',\n      'locale',\n      'fallbackLocale',\n      'collections',\n      'collectionsSelect',\n      'collectionsJoins',\n      'globalsSelect',\n      ...(config.typescript?.strictDraftTypes ? ['strictDraftTypes'] : []),\n      'globals',\n      'auth',\n      'db',\n      'jobs',\n      'blocks',\n      'widgets',\n    ],\n    title: 'Config',\n  }\n\n  if (jobsSchemas.definitions?.size) {\n    for (const [key, value] of jobsSchemas.definitions) {\n      jsonSchema.definitions![key] = value\n    }\n  }\n  if (jobsSchemas.properties) {\n    jsonSchema.properties!.jobs = {\n      type: 'object',\n      additionalProperties: false,\n      properties: jobsSchemas.properties,\n      required: ['tasks', 'workflows'],\n    }\n  }\n\n  if (config?.typescript?.schema?.length) {\n    for (const schema of config.typescript.schema) {\n      jsonSchema = schema({ collectionIDFieldTypes, config, i18n: i18n!, jsonSchema })\n    }\n  }\n\n  return jsonSchema\n}\n"],"names":["MissingEditorProp","fieldAffectsData","generateJobsJSONSchemas","flattenAllFields","formatNames","getCollectionIDFieldTypes","optionsAreEqual","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","flattenedFields","some","subField","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateEntitySelectSchemas","generateCollectionJoinsSchemas","collections","joins","polymorphicJoins","schema","collectionSlug","join","joinPath","enum","push","collection","length","widgetWidths","getAllowedWidgetWidths","maxWidth","minWidth","minIndex","indexOf","maxIndex","slice","generateWidgetSchemas","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","opts","widgets","dashboard","definitions","widget","definition","widthEnum","dataSchema","fields","widgetFieldSchemas","fieldsToJSONSchema","data","width","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","generateFallbackLocaleEntitySchemas","localeCodes","localeCode","oneOf","items","generateAuthEntitySchemas","filter","auth","generateDbEntitySchema","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","entityOrFieldToJsDocs","entity","description","undefined","en","language","requiredFieldNames","Set","fromEntries","fieldSchemas","index","fieldDescription","baseFieldSchema","fieldSchema","interfaceName","set","hasBlocks","blockReferences","blocks","block","resolvedBlock","find","b","forceInlineBlocks","blockFieldSchemas","blockSchema","blockType","const","Array","isArray","relationTo","docs","hasNextPage","totalDocs","jsonSchema","hasMany","maxItems","minItems","relation","editor","Error","outputSchema","optionEnums","previousField","isTimezoneField","timezone","name","includes","hasMatchingGlobalTimezones","timezones","supportedTimezones","typescriptSchema","add","Map","from","entityToJSONSchema","title","typescript","interface","singular","mutableFields","idField","customIdField","unshift","timestamps","disableLocalStrategy","enableFields","isAuthCollection","fieldsSchema","entityDescription","fieldsToSelectJSONSchema","blocksSchema","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","username","password","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","timezonesToJSONSchema","generateAuthOperationSchemas","configToJSONSchema","globals","global","entityDefinitions","select","globalType","timezoneDefinitions","widgetSchemas","authOperationDefinitions","authCollection","jobsSchemas","jobs","blocksDefinition","collectionsJoins","collectionsSelect","fallbackLocale","globalsSelect","strictDraftTypes","user","size","key"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,MAAMC,kBAAkB,CAACC;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