payload 3.32.0-internal.f2e77bd → 3.33.0-internal.d1efdd8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/admin/forms/Form.d.ts +12 -1
  2. package/dist/admin/forms/Form.d.ts.map +1 -1
  3. package/dist/admin/forms/Form.js.map +1 -1
  4. package/dist/admin/functions/index.d.ts +1 -0
  5. package/dist/admin/functions/index.d.ts.map +1 -1
  6. package/dist/admin/functions/index.js.map +1 -1
  7. package/dist/bin/generateImportMap/index.js +3 -3
  8. package/dist/bin/generateImportMap/index.js.map +1 -1
  9. package/dist/bin/generateTypes.js +3 -3
  10. package/dist/bin/generateTypes.js.map +1 -1
  11. package/dist/collections/config/sanitize.d.ts.map +1 -1
  12. package/dist/collections/config/sanitize.js.map +1 -1
  13. package/dist/collections/config/types.d.ts +11 -0
  14. package/dist/collections/config/types.d.ts.map +1 -1
  15. package/dist/collections/config/types.js.map +1 -1
  16. package/dist/config/orderable/fractional-indexing.d.ts +31 -0
  17. package/dist/config/orderable/fractional-indexing.d.ts.map +1 -0
  18. package/dist/config/orderable/fractional-indexing.js +295 -0
  19. package/dist/config/orderable/fractional-indexing.js.map +1 -0
  20. package/dist/config/orderable/index.d.ts +28 -0
  21. package/dist/config/orderable/index.d.ts.map +1 -0
  22. package/dist/config/orderable/index.js +259 -0
  23. package/dist/config/orderable/index.js.map +1 -0
  24. package/dist/config/sanitize.d.ts.map +1 -1
  25. package/dist/config/sanitize.js +3 -0
  26. package/dist/config/sanitize.js.map +1 -1
  27. package/dist/database/defaultUpdateJobs.d.ts.map +1 -1
  28. package/dist/database/defaultUpdateJobs.js +1 -4
  29. package/dist/database/defaultUpdateJobs.js.map +1 -1
  30. package/dist/database/types.d.ts +6 -0
  31. package/dist/database/types.d.ts.map +1 -1
  32. package/dist/database/types.js.map +1 -1
  33. package/dist/fields/config/types.d.ts +12 -1
  34. package/dist/fields/config/types.d.ts.map +1 -1
  35. package/dist/fields/config/types.js.map +1 -1
  36. package/dist/index.d.ts +3 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/queues/config/types/index.d.ts +15 -1
  41. package/dist/queues/config/types/index.d.ts.map +1 -1
  42. package/dist/queues/config/types/index.js.map +1 -1
  43. package/dist/queues/config/types/workflowTypes.d.ts +1 -1
  44. package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
  45. package/dist/queues/config/types/workflowTypes.js.map +1 -1
  46. package/dist/queues/localAPI.d.ts +12 -1
  47. package/dist/queues/localAPI.d.ts.map +1 -1
  48. package/dist/queues/localAPI.js +2 -0
  49. package/dist/queues/localAPI.js.map +1 -1
  50. package/dist/queues/operations/runJobs/index.d.ts +15 -2
  51. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  52. package/dist/queues/operations/runJobs/index.js +30 -4
  53. package/dist/queues/operations/runJobs/index.js.map +1 -1
  54. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
  55. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +5 -1
  56. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  57. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
  58. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +14 -1
  59. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
  60. package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
  61. package/dist/queues/operations/runJobs/runJob/index.js +2 -0
  62. package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
  63. package/dist/queues/utilities/updateJob.d.ts.map +1 -1
  64. package/dist/queues/utilities/updateJob.js +10 -9
  65. package/dist/queues/utilities/updateJob.js.map +1 -1
  66. package/dist/uploads/deleteAssociatedFiles.js +3 -3
  67. package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
  68. package/dist/uploads/fileExists.js +2 -2
  69. package/dist/uploads/fileExists.js.map +1 -1
  70. package/dist/uploads/generateFileData.d.ts.map +1 -1
  71. package/dist/uploads/generateFileData.js +4 -5
  72. package/dist/uploads/generateFileData.js.map +1 -1
  73. package/dist/uploads/getFileByPath.js +3 -3
  74. package/dist/uploads/getFileByPath.js.map +1 -1
  75. package/dist/uploads/getImageSize.js +2 -2
  76. package/dist/uploads/getImageSize.js.map +1 -1
  77. package/dist/uploads/imageResizer.js +2 -2
  78. package/dist/uploads/imageResizer.js.map +1 -1
  79. package/dist/uploads/saveBufferToFile.js +2 -2
  80. package/dist/uploads/saveBufferToFile.js.map +1 -1
  81. package/dist/uploads/tempFile.js +4 -4
  82. package/dist/uploads/tempFile.js.map +1 -1
  83. package/dist/uploads/unlinkTempFiles.d.ts.map +1 -1
  84. package/dist/uploads/unlinkTempFiles.js +2 -4
  85. package/dist/uploads/unlinkTempFiles.js.map +1 -1
  86. package/dist/utilities/configToJSONSchema.js +3 -3
  87. package/dist/utilities/configToJSONSchema.js.map +1 -1
  88. package/dist/utilities/configToJSONSchema.spec.js +29 -0
  89. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  90. package/dist/utilities/flattenAllFields.d.ts +5 -0
  91. package/dist/utilities/flattenAllFields.d.ts.map +1 -1
  92. package/dist/utilities/flattenAllFields.js +5 -1
  93. package/dist/utilities/flattenAllFields.js.map +1 -1
  94. package/package.json +2 -2
  95. package/dist/queues/utilities/sanitizeUpdateData.d.ts +0 -9
  96. package/dist/queues/utilities/sanitizeUpdateData.d.ts.map +0 -1
  97. package/dist/queues/utilities/sanitizeUpdateData.js +0 -25
  98. package/dist/queues/utilities/sanitizeUpdateData.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { I18n } from '@payloadcms/translations'\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 { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: FlattenedField) => {\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((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\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((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}_select`,\n }\n\n return acc\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: [],\n } satisfies JSONSchema4\n\n for (const collectionSlug in joins) {\n for (const join of joins[collectionSlug]) {\n schema.properties[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[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\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 generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\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}\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): {\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 if (isRequired) {\n requiredFieldNames.add(field.name)\n }\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 ),\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 return {\n $ref: `#/definitions/${resolvedBlock.interfaceName ?? resolvedBlock.slug}`,\n }\n }\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\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 (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 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 ),\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 '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 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\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\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 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 // Timezone selects should reference the supportedTimezones definition\n if (isTimezoneField) {\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\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 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): JSONSchema4 {\n if (!collectionIDFieldTypes) {\n collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n }\n\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\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 jsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n mutableFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\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: `${singular(toWords(`${config.slug}`, true))}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((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\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): 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({ config, defaultIDType })\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 )\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 {},\n )\n\n const timezoneDefinitions = timezonesToJSONSchema(config.admin.timezones.supportedTimezones)\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: {} },\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 )\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 ...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 globals: generateEntitySchemas(config.globals || []),\n globalsSelect: generateEntitySelectSchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: [\n 'user',\n 'locale',\n 'collections',\n 'collectionsSelect',\n 'collectionsJoins',\n 'globalsSelect',\n 'globals',\n 'auth',\n 'db',\n 'jobs',\n 'blocks',\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, jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","generateJobsJSONSchemas","toWords","getCollectionIDFieldTypes","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","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","generateAuthEntitySchemas","filter","auth","allOf","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","entityOrFieldToJsDocs","entity","i18n","description","undefined","en","language","fieldsToJSONSchema","collectionIDFieldTypes","fields","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","index","add","name","fieldDescription","baseFieldSchema","fieldSchema","items","interfaceName","set","hasBlocks","blockReferences","blocks","block","resolvedBlock","find","b","blockFieldSchemas","blockSchema","blockType","const","Array","isArray","relationTo","docs","hasNextPage","totalDocs","jsonSchema","hasMany","maxItems","minItems","relation","editor","Error","outputSchema","optionEnums","previousField","isTimezoneField","timezone","includes","typescriptSchema","Map","from","entityToJSONSchema","title","typescript","interface","mutableFields","idField","customIdField","unshift","timestamps","disableLocalStrategy","enableFields","entityDescription","fieldsToSelectJSONSchema","definition","blocksSchema","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","username","password","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","timezonesToJSONSchema","supportedTimezones","generateAuthOperationSchemas","configToJSONSchema","globals","global","entityDefinitions","select","globalType","timezoneDefinitions","timezones","authOperationDefinitions","authCollection","jobsSchemas","jobs","blocksDefinition","definitions","collectionsJoins","collectionsSelect","globalsSelect","user","size","key"],"mappings":"AAAA,oBAAoB;AAGpB,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAUrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB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3BoG,SAASvI,sBAAsBmC,OAAOoG,OAAO,IAAI,EAAE;YACnDe,eAAe5I,4BAA4ByB,OAAOoG,OAAO,IAAI,EAAE;YAC/D5G,QAAQJ,4BAA4BY,OAAOX,YAAY;YACvD+H,MAAM1H,0BAA0BM,OAAOvB,WAAW;QACpD;QACAtB,UAAU;YACR;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACD8G,OAAO;IACT;IAEA,IAAI4C,YAAYG,WAAW,EAAEK,MAAM;QACjC,KAAK,MAAM,CAACC,KAAK1J,MAAM,IAAIiJ,YAAYG,WAAW,CAAE;YAClDhE,WAAWgE,WAAW,CAACM,IAAI,GAAG1J;QAChC;IACF;IACA,IAAIiJ,YAAY9I,UAAU,EAAE;QAC1BiF,WAAWjF,UAAU,CAAC+I,IAAI,GAAG;YAC3B1J,MAAM;YACNgB,sBAAsB;YACtBL,YAAY8I,YAAY9I,UAAU;YAClCZ,UAAU;gBAAC;gBAAS;aAAY;QAClC;IACF;IAEA,IAAI6C,QAAQkE,YAAYtF,QAAQO,QAAQ;QACtC,KAAK,MAAMP,UAAUoB,OAAOkE,UAAU,CAACtF,MAAM,CAAE;YAC7CoE,aAAapE,OAAO;gBAAEmC;gBAAwBf;gBAAQS;gBAAMuC;YAAW;QACzE;IACF;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { I18n } from '@payloadcms/translations'\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 { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: FlattenedField) => {\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((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\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((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}_select`,\n }\n\n return acc\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: [],\n } satisfies JSONSchema4\n\n for (const collectionSlug in joins) {\n for (const join of joins[collectionSlug]) {\n schema.properties[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[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\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 generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\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}\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): {\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 ),\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 return {\n $ref: `#/definitions/${resolvedBlock.interfaceName ?? resolvedBlock.slug}`,\n }\n }\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\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 (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 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 ),\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 '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 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\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\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 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 // Timezone selects should reference the supportedTimezones definition\n if (isTimezoneField) {\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\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): JSONSchema4 {\n if (!collectionIDFieldTypes) {\n collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n }\n\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\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 jsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n mutableFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\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: `${singular(toWords(`${config.slug}`, true))}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((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\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): 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({ config, defaultIDType })\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 )\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 {},\n )\n\n const timezoneDefinitions = timezonesToJSONSchema(config.admin.timezones.supportedTimezones)\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: {} },\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 )\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 ...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 globals: generateEntitySchemas(config.globals || []),\n globalsSelect: generateEntitySelectSchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: [\n 'user',\n 'locale',\n 'collections',\n 'collectionsSelect',\n 'collectionsJoins',\n 'globalsSelect',\n 'globals',\n 'auth',\n 'db',\n 'jobs',\n 'blocks',\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, jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","generateJobsJSONSchemas","toWords","getCollectionIDFieldTypes","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","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","generateAuthEntitySchemas","filter","auth","allOf","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","entityOrFieldToJsDocs","entity","i18n","description","undefined","en","language","fieldsToJSONSchema","collectionIDFieldTypes","fields","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","index","fieldDescription","baseFieldSchema","fieldSchema","items","interfaceName","set","hasBlocks","blockReferences","blocks","block","resolvedBlock","find","b","blockFieldSchemas","blockSchema","blockType","const","Array","isArray","relationTo","docs","hasNextPage","totalDocs","jsonSchema","hasMany","maxItems","minItems","relation","editor","Error","outputSchema","optionEnums","previousField","isTimezoneField","timezone","name","includes","typescriptSchema","add","Map","from","entityToJSONSchema","title","typescript","interface","mutableFields","idField","customIdField","unshift","timestamps","disableLocalStrategy","enableFields","entityDescription","fieldsToSelectJSONSchema","definition","blocksSchema","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","username","password","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","timezonesToJSONSchema","supportedTimezones","generateAuthOperationSchemas","configToJSONSchema","globals","global","entityDefinitions","select","globalType","timezoneDefinitions","timezones","authOperationDefinitions","authCollection","jobsSchemas","jobs","blocksDefinition","definitions","collectionsJoins","collectionsSelect","globalsSelect","user","size","key"],"mappings":"AAAA,oBAAoB;AAGpB,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAUrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe;QACjB,OAAO;IACT;IAEA,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIX,iBAAiBK,UAAUK,kBAAkB;QAC/C,OAAO;IACT;IAEA,wDAAwD;IACxD,IAAI,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tB,UAAU;YACR;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;YACA;SACD;QACD8G,OAAO;IACT;IAEA,IAAI4C,YAAYG,WAAW,EAAEK,MAAM;QACjC,KAAK,MAAM,CAACC,KAAK1J,MAAM,IAAIiJ,YAAYG,WAAW,CAAE;YAClDlE,WAAWkE,WAAW,CAACM,IAAI,GAAG1J;QAChC;IACF;IACA,IAAIiJ,YAAY9I,UAAU,EAAE;QAC1B+E,WAAW/E,UAAU,CAAC+I,IAAI,GAAG;YAC3B1J,MAAM;YACNgB,sBAAsB;YACtBL,YAAY8I,YAAY9I,UAAU;YAClCZ,UAAU;gBAAC;gBAAS;aAAY;QAClC;IACF;IAEA,IAAI6C,QAAQkE,YAAYtF,QAAQO,QAAQ;QACtC,KAAK,MAAMP,UAAUoB,OAAOkE,UAAU,CAACtF,MAAM,CAAE;YAC7CkE,aAAalE,OAAO;gBAAEmC;gBAAwBf;gBAAQS;gBAAMqC;YAAW;QACzE;IACF;IAEA,OAAOA;AACT"}
@@ -450,6 +450,35 @@ describe('configToJSONSchema', ()=>{
450
450
  });
451
451
  expect(schema?.definitions?.SharedBlock).toBeDefined();
452
452
  });
453
+ it('should allow overriding required to false', async ()=>{
454
+ // @ts-expect-error
455
+ const config = {
456
+ collections: [
457
+ {
458
+ slug: 'test',
459
+ fields: [
460
+ {
461
+ name: 'title',
462
+ type: 'text',
463
+ required: true,
464
+ defaultValue: 'test',
465
+ typescriptSchema: [
466
+ ()=>({
467
+ type: 'string',
468
+ required: false
469
+ })
470
+ ]
471
+ }
472
+ ],
473
+ timestamps: false
474
+ }
475
+ ]
476
+ };
477
+ const sanitizedConfig = await sanitizeConfig(config);
478
+ const schema = configToJSONSchema(sanitizedConfig, 'text');
479
+ // @ts-expect-error
480
+ expect(schema.definitions.test.properties.title.required).toStrictEqual(false);
481
+ });
453
482
  });
454
483
 
455
484
  //# sourceMappingURL=configToJSONSchema.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\nimport type { Block, BlocksField, RichTextField } from '../fields/config/types.js'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n type: 'text',\n required: true,\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n type: ['array', 'null'],\n items: {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n },\n },\n },\n required: ['id'],\n title: 'Test',\n })\n })\n\n it('should handle block fields with no blocks', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'blockField',\n type: 'blocks',\n blocks: [],\n },\n {\n name: 'blockFieldRequired',\n type: 'blocks',\n blocks: [],\n required: true,\n },\n {\n name: 'blockFieldWithFields',\n type: 'blocks',\n blocks: [\n {\n slug: 'test',\n fields: [\n {\n name: 'field',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'blockFieldWithFieldsRequired',\n type: 'blocks',\n blocks: [\n {\n slug: 'test',\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n ],\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n blockField: {\n type: ['array', 'null'],\n items: {},\n },\n blockFieldRequired: {\n type: 'array',\n items: {},\n },\n blockFieldWithFields: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n blockName: {\n type: ['string', 'null'],\n },\n blockType: {\n const: 'test',\n },\n field: {\n type: ['string', 'null'],\n },\n },\n required: ['blockType'],\n },\n ],\n },\n },\n blockFieldWithFieldsRequired: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n blockName: {\n type: ['string', 'null'],\n },\n blockType: {\n const: 'test',\n },\n field: {\n type: 'string',\n },\n },\n required: ['blockType', 'field'],\n },\n ],\n },\n },\n },\n required: ['id', 'blockFieldRequired'],\n title: 'Test',\n })\n })\n\n it('should handle tabs and named tabs with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'fieldInUnnamedTab',\n type: 'text',\n },\n ],\n label: 'unnamedTab',\n },\n {\n name: 'namedTab',\n fields: [\n {\n name: 'fieldInNamedTab',\n type: 'text',\n },\n ],\n label: 'namedTab',\n },\n {\n name: 'namedTabWithRequired',\n fields: [\n {\n name: 'fieldInNamedTab',\n type: 'text',\n required: true,\n },\n ],\n label: 'namedTabWithRequired',\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n fieldInUnnamedTab: {\n type: ['string', 'null'],\n },\n namedTab: {\n type: 'object',\n additionalProperties: false,\n properties: {\n fieldInNamedTab: {\n type: ['string', 'null'],\n },\n },\n required: [],\n },\n namedTabWithRequired: {\n type: 'object',\n additionalProperties: false,\n properties: {\n fieldInNamedTab: {\n type: 'string',\n },\n },\n required: ['fieldInNamedTab'],\n },\n },\n required: ['id', 'namedTabWithRequired'],\n title: 'Test',\n })\n })\n\n it('should handle custom typescript schema and JSON field schema', async () => {\n const customSchema: JSONSchema4 = {\n type: 'object',\n properties: {\n id: {\n type: 'number',\n },\n required: ['id'],\n },\n }\n\n const config: Partial<Config> = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'withCustom',\n type: 'text',\n typescriptSchema: [() => customSchema],\n },\n {\n name: 'jsonWithSchema',\n type: 'json',\n jsonSchema: {\n fileMatch: ['a://b/foo.json'],\n schema: customSchema,\n uri: 'a://b/foo.json',\n },\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config as Config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n jsonWithSchema: customSchema,\n withCustom: customSchema,\n },\n required: ['id'],\n title: 'Test',\n })\n })\n\n it('should handle same block object being referenced in both collection and config.blocks', async () => {\n const sharedBlock: Block = {\n slug: 'sharedBlock',\n interfaceName: 'SharedBlock',\n fields: [\n {\n name: 'richText',\n type: 'richText',\n editor: () => {\n // stub rich text editor\n return {\n CellComponent: '',\n FieldComponent: '',\n validate: () => true,\n }\n },\n },\n ],\n }\n\n // @ts-expect-error\n const config: Config = {\n blocks: [sharedBlock],\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'someBlockField',\n type: 'blocks',\n blocks: [sharedBlock],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n // Ensure both rich text editor are sanitized\n const sanitizedConfig = await sanitizeConfig(config)\n expect(typeof (sanitizedConfig?.blocks?.[0]?.fields?.[0] as RichTextField)?.editor).toBe(\n 'object',\n )\n expect(\n typeof (\n (sanitizedConfig.collections[0].fields[0] as BlocksField)?.blocks?.[0]\n ?.fields?.[0] as RichTextField\n )?.editor,\n ).toBe('object')\n\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n title: 'Test',\n properties: {\n id: {\n type: 'string',\n },\n someBlockField: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n $ref: '#/definitions/SharedBlock',\n },\n ],\n },\n },\n },\n required: ['id'],\n })\n\n expect(schema?.definitions?.SharedBlock).toBeDefined()\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","slug","fields","name","type","required","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title","blocks","blockField","blockFieldRequired","blockFieldWithFields","oneOf","blockName","blockType","const","field","blockFieldWithFieldsRequired","tabs","label","fieldInUnnamedTab","namedTab","fieldInNamedTab","namedTabWithRequired","customSchema","typescriptSchema","jsonSchema","fileMatch","uri","jsonWithSchema","withCustom","sharedBlock","interfaceName","editor","CellComponent","FieldComponent","validate","toBe","someBlockField","$ref","SharedBlock","toBeDefined"],"mappings":"AAIA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAG5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNC,UAAU;gCACZ;6BACD;wBACH;qBACD;oBACDC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMZ,eAAeI;QAC7C,MAAMS,SAASZ,mBAAmBW,iBAAiB;QAEnDE,OAAOD,QAAQE,aAAaC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X,MAAM;gBACR;gBACA6C,gBAAgB;oBACd7C,MAAM;wBAAC;wBAAS;qBAAO;oBACvBa,OAAO;wBACLM,OAAO;4BACL;gCACE2B,MAAM;4BACR;yBACD;oBACH;gBACF;YACF;YACA7C,UAAU;gBAAC;aAAK;QAClB;QAEAI,OAAOD,QAAQE,aAAayC,aAAaC,WAAW;IACtD;AACF"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\nimport type { Block, BlocksField, RichTextField } from '../fields/config/types.js'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n type: 'text',\n required: true,\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n type: ['array', 'null'],\n items: {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n },\n },\n },\n required: ['id'],\n title: 'Test',\n })\n })\n\n it('should handle block fields with no blocks', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'blockField',\n type: 'blocks',\n blocks: [],\n },\n {\n name: 'blockFieldRequired',\n type: 'blocks',\n blocks: [],\n required: true,\n },\n {\n name: 'blockFieldWithFields',\n type: 'blocks',\n blocks: [\n {\n slug: 'test',\n fields: [\n {\n name: 'field',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'blockFieldWithFieldsRequired',\n type: 'blocks',\n blocks: [\n {\n slug: 'test',\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n ],\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n blockField: {\n type: ['array', 'null'],\n items: {},\n },\n blockFieldRequired: {\n type: 'array',\n items: {},\n },\n blockFieldWithFields: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n blockName: {\n type: ['string', 'null'],\n },\n blockType: {\n const: 'test',\n },\n field: {\n type: ['string', 'null'],\n },\n },\n required: ['blockType'],\n },\n ],\n },\n },\n blockFieldWithFieldsRequired: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n blockName: {\n type: ['string', 'null'],\n },\n blockType: {\n const: 'test',\n },\n field: {\n type: 'string',\n },\n },\n required: ['blockType', 'field'],\n },\n ],\n },\n },\n },\n required: ['id', 'blockFieldRequired'],\n title: 'Test',\n })\n })\n\n it('should handle tabs and named tabs with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'fieldInUnnamedTab',\n type: 'text',\n },\n ],\n label: 'unnamedTab',\n },\n {\n name: 'namedTab',\n fields: [\n {\n name: 'fieldInNamedTab',\n type: 'text',\n },\n ],\n label: 'namedTab',\n },\n {\n name: 'namedTabWithRequired',\n fields: [\n {\n name: 'fieldInNamedTab',\n type: 'text',\n required: true,\n },\n ],\n label: 'namedTabWithRequired',\n },\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n fieldInUnnamedTab: {\n type: ['string', 'null'],\n },\n namedTab: {\n type: 'object',\n additionalProperties: false,\n properties: {\n fieldInNamedTab: {\n type: ['string', 'null'],\n },\n },\n required: [],\n },\n namedTabWithRequired: {\n type: 'object',\n additionalProperties: false,\n properties: {\n fieldInNamedTab: {\n type: 'string',\n },\n },\n required: ['fieldInNamedTab'],\n },\n },\n required: ['id', 'namedTabWithRequired'],\n title: 'Test',\n })\n })\n\n it('should handle custom typescript schema and JSON field schema', async () => {\n const customSchema: JSONSchema4 = {\n type: 'object',\n properties: {\n id: {\n type: 'number',\n },\n required: ['id'],\n },\n }\n\n const config: Partial<Config> = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'withCustom',\n type: 'text',\n typescriptSchema: [() => customSchema],\n },\n {\n name: 'jsonWithSchema',\n type: 'json',\n jsonSchema: {\n fileMatch: ['a://b/foo.json'],\n schema: customSchema,\n uri: 'a://b/foo.json',\n },\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config as Config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n jsonWithSchema: customSchema,\n withCustom: customSchema,\n },\n required: ['id'],\n title: 'Test',\n })\n })\n\n it('should handle same block object being referenced in both collection and config.blocks', async () => {\n const sharedBlock: Block = {\n slug: 'sharedBlock',\n interfaceName: 'SharedBlock',\n fields: [\n {\n name: 'richText',\n type: 'richText',\n editor: () => {\n // stub rich text editor\n return {\n CellComponent: '',\n FieldComponent: '',\n validate: () => true,\n }\n },\n },\n ],\n }\n\n // @ts-expect-error\n const config: Config = {\n blocks: [sharedBlock],\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'someBlockField',\n type: 'blocks',\n blocks: [sharedBlock],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n // Ensure both rich text editor are sanitized\n const sanitizedConfig = await sanitizeConfig(config)\n expect(typeof (sanitizedConfig?.blocks?.[0]?.fields?.[0] as RichTextField)?.editor).toBe(\n 'object',\n )\n expect(\n typeof (\n (sanitizedConfig.collections[0].fields[0] as BlocksField)?.blocks?.[0]\n ?.fields?.[0] as RichTextField\n )?.editor,\n ).toBe('object')\n\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n type: 'object',\n additionalProperties: false,\n title: 'Test',\n properties: {\n id: {\n type: 'string',\n },\n someBlockField: {\n type: ['array', 'null'],\n items: {\n oneOf: [\n {\n $ref: '#/definitions/SharedBlock',\n },\n ],\n },\n },\n },\n required: ['id'],\n })\n\n expect(schema?.definitions?.SharedBlock).toBeDefined()\n })\n\n it('should allow overriding required to false', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n slug: 'test',\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n defaultValue: 'test',\n typescriptSchema: [\n () => ({\n type: 'string',\n required: false,\n }),\n ],\n },\n ],\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n // @ts-expect-error\n expect(schema.definitions.test.properties.title.required).toStrictEqual(false)\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","slug","fields","name","type","required","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title","blocks","blockField","blockFieldRequired","blockFieldWithFields","oneOf","blockName","blockType","const","field","blockFieldWithFieldsRequired","tabs","label","fieldInUnnamedTab","namedTab","fieldInNamedTab","namedTabWithRequired","customSchema","typescriptSchema","jsonSchema","fileMatch","uri","jsonWithSchema","withCustom","sharedBlock","interfaceName","editor","CellComponent","FieldComponent","validate","toBe","someBlockField","$ref","SharedBlock","toBeDefined","defaultValue"],"mappings":"AAIA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAG5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNC,UAAU;gCACZ;6BACD;wBACH;qBACD;oBACDC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMZ,eAAeI;QAC7C,MAAMS,SAASZ,mBAAmBW,iBAAiB;QAEnDE,OAAOD,QAAQE,aAAaC,MAAMC,aAAa,CAAC;YAC9CR,MAAM;YACNS,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFX,MAAM;gBACR;gBACAY,mBAAmB;oBACjBZ,MAAM;wBAAC;wBAAS;qBAAO;oBACvBa,OAAO;wBACLb,MAAM;wBACNS,sBAAsB;wBACtBC,YAAY;4BACVC,IAAI;gCACFX,MAAM;oCAAC;oCAAU;iCAAO;4BAC1B;4BACAY,mBAAmB;gCACjBZ,MAAM;4BACR;wBACF;wBACAC,UAAU;4BAAC;yBAAoB;oBACjC;gBACF;YACF;YACAA,UAAU;gBAAC;aAAK;YAChBa,OAAO;QACT;IACF;IAEApB,GAAG,6CAA6C;QAC9C,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNe,QAAQ,EAAE;wBACZ;wBACA;4BACEhB,MAAM;4BACNC,MAAM;4BACNe,QAAQ,EAAE;4BACVd,UAAU;wBACZ;wBACA;4BACEF,MAA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U,CAACI,KAAK,CAACb,QAAQ,EAAEO,aAAa,CAAC;IAC1E;AACF"}
@@ -2,6 +2,11 @@ import type { Block, Field, FlattenedBlock, FlattenedField } from '../fields/con
2
2
  export declare const flattenBlock: ({ block }: {
3
3
  block: Block;
4
4
  }) => FlattenedBlock;
5
+ /**
6
+ * Flattens all fields in a collection, preserving the nested field structure.
7
+ * @param cache
8
+ * @param fields
9
+ */
5
10
  export declare const flattenAllFields: ({ cache, fields, }: {
6
11
  /** Allows you to get FlattenedField[] from Field[] anywhere without performance overhead by caching. */
7
12
  cache?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"flattenAllFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenAllFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,KAAK,EACL,cAAc,EAEd,cAAc,EAEf,MAAM,2BAA2B,CAAA;AAIlC,eAAO,MAAM,YAAY,cAAe;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,KAAG,cAK1D,CAAA;AAID,eAAO,MAAM,gBAAgB,uBAG1B;IACD,wGAAwG;IACxG,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,KAAG,cAAc,EA2FjB,CAAA"}
1
+ {"version":3,"file":"flattenAllFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenAllFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,KAAK,EACL,cAAc,EAEd,cAAc,EAEf,MAAM,2BAA2B,CAAA;AAIlC,eAAO,MAAM,YAAY,cAAe;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,KAAG,cAK1D,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,uBAG1B;IACD,wGAAwG;IACxG,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,KAAG,cAAc,EA2FjB,CAAA"}
@@ -8,7 +8,11 @@ export const flattenBlock = ({ block })=>{
8
8
  };
9
9
  };
10
10
  const flattenedFieldsCache = new Map();
11
- export const flattenAllFields = ({ cache, fields })=>{
11
+ /**
12
+ * Flattens all fields in a collection, preserving the nested field structure.
13
+ * @param cache
14
+ * @param fields
15
+ */ export const flattenAllFields = ({ cache, fields })=>{
12
16
  if (cache) {
13
17
  const maybeFields = flattenedFieldsCache.get(fields);
14
18
  if (maybeFields) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/flattenAllFields.ts"],"sourcesContent":["import type {\n Block,\n Field,\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n FlattenedJoinField,\n} from '../fields/config/types.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\nexport const flattenBlock = ({ block }: { block: Block }): FlattenedBlock => {\n return {\n ...block,\n flattenedFields: flattenAllFields({ fields: block.fields }),\n }\n}\n\nconst flattenedFieldsCache = new Map<Field[], FlattenedField[]>()\n\nexport const flattenAllFields = ({\n cache,\n fields,\n}: {\n /** Allows you to get FlattenedField[] from Field[] anywhere without performance overhead by caching. */\n cache?: boolean\n fields: Field[]\n}): FlattenedField[] => {\n if (cache) {\n const maybeFields = flattenedFieldsCache.get(fields)\n if (maybeFields) {\n return maybeFields\n }\n }\n\n const result: FlattenedField[] = []\n\n for (const field of fields) {\n switch (field.type) {\n case 'array':\n case 'group': {\n result.push({ ...field, flattenedFields: flattenAllFields({ fields: field.fields }) })\n break\n }\n\n case 'blocks': {\n const blocks: FlattenedBlock[] = []\n let blockReferences: (FlattenedBlock | string)[] | undefined = undefined\n if (field.blockReferences) {\n blockReferences = []\n for (const block of field.blockReferences) {\n if (typeof block === 'string') {\n blockReferences.push(block)\n continue\n }\n blockReferences.push(flattenBlock({ block }))\n }\n } else {\n for (const block of field.blocks) {\n if (typeof block === 'string') {\n blocks.push(block)\n continue\n }\n blocks.push(flattenBlock({ block }))\n }\n }\n\n const resultField: FlattenedBlocksField = {\n ...field,\n blockReferences,\n blocks,\n }\n\n result.push(resultField)\n break\n }\n\n case 'collapsible':\n case 'row': {\n for (const nestedField of flattenAllFields({ fields: field.fields })) {\n result.push(nestedField)\n }\n break\n }\n\n case 'join': {\n result.push(field as FlattenedJoinField)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (!tabHasName(tab)) {\n for (const nestedField of flattenAllFields({ fields: tab.fields })) {\n result.push(nestedField)\n }\n } else {\n result.push({\n ...tab,\n type: 'tab',\n flattenedFields: flattenAllFields({ fields: tab.fields }),\n })\n }\n }\n break\n }\n\n default: {\n if (field.type !== 'ui') {\n result.push(field)\n }\n }\n }\n }\n\n flattenedFieldsCache.set(fields, result)\n\n return result\n}\n"],"names":["tabHasName","flattenBlock","block","flattenedFields","flattenAllFields","fields","flattenedFieldsCache","Map","cache","maybeFields","get","result","field","type","push","blocks","blockReferences","undefined","resultField","nestedField","tab","tabs","set"],"mappings":"AASA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,eAAe,CAAC,EAAEC,KAAK,EAAoB;IACtD,OAAO;QACL,GAAGA,KAAK;QACRC,iBAAiBC,iBAAiB;YAAEC,QAAQH,MAAMG,MAAM;QAAC;IAC3D;AACF,EAAC;AAED,MAAMC,uBAAuB,IAAIC;AAEjC,OAAO,MAAMH,mBAAmB,CAAC,EAC/BI,KAAK,EACLH,MAAM,EAKP;IACC,IAAIG,OAAO;QACT,MAAMC,cAAcH,qBAAqBI,GAAG,CAACL;QAC7C,IAAII,aAAa;YACf,OAAOA;QACT;IACF;IAEA,MAAME,SAA2B,EAAE;IAEnC,KAAK,MAAMC,SAASP,OAAQ;QAC1B,OAAQO,MAAMC,IAAI;YAChB,KAAK;YACL,KAAK;gBAAS;oBACZF,OAAOG,IAAI,CAAC;wBAAE,GAAGF,KAAK;wBAAET,iBAAiBC,iBAAiB;4BAAEC,QAAQO,MAAMP,MAAM;wBAAC;oBAAG;oBACpF;gBACF;YAEA,KAAK;gBAAU;oBACb,MAAMU,SAA2B,E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I,CAACF;oBACd;gBACF;QACF;IACF;IAEAN,qBAAqBgB,GAAG,CAACjB,QAAQM;IAEjC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/flattenAllFields.ts"],"sourcesContent":["import type {\n Block,\n Field,\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n FlattenedJoinField,\n} from '../fields/config/types.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\nexport const flattenBlock = ({ block }: { block: Block }): FlattenedBlock => {\n return {\n ...block,\n flattenedFields: flattenAllFields({ fields: block.fields }),\n }\n}\n\nconst flattenedFieldsCache = new Map<Field[], FlattenedField[]>()\n\n/**\n * Flattens all fields in a collection, preserving the nested field structure.\n * @param cache\n * @param fields\n */\nexport const flattenAllFields = ({\n cache,\n fields,\n}: {\n /** Allows you to get FlattenedField[] from Field[] anywhere without performance overhead by caching. */\n cache?: boolean\n fields: Field[]\n}): FlattenedField[] => {\n if (cache) {\n const maybeFields = flattenedFieldsCache.get(fields)\n if (maybeFields) {\n return maybeFields\n }\n }\n\n const result: FlattenedField[] = []\n\n for (const field of fields) {\n switch (field.type) {\n case 'array':\n case 'group': {\n result.push({ ...field, flattenedFields: flattenAllFields({ fields: field.fields }) })\n break\n }\n\n case 'blocks': {\n const blocks: FlattenedBlock[] = []\n let blockReferences: (FlattenedBlock | string)[] | undefined = undefined\n if (field.blockReferences) {\n blockReferences = []\n for (const block of field.blockReferences) {\n if (typeof block === 'string') {\n blockReferences.push(block)\n continue\n }\n blockReferences.push(flattenBlock({ block }))\n }\n } else {\n for (const block of field.blocks) {\n if (typeof block === 'string') {\n blocks.push(block)\n continue\n }\n blocks.push(flattenBlock({ block }))\n }\n }\n\n const resultField: FlattenedBlocksField = {\n ...field,\n blockReferences,\n blocks,\n }\n\n result.push(resultField)\n break\n }\n\n case 'collapsible':\n case 'row': {\n for (const nestedField of flattenAllFields({ fields: field.fields })) {\n result.push(nestedField)\n }\n break\n }\n\n case 'join': {\n result.push(field as FlattenedJoinField)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (!tabHasName(tab)) {\n for (const nestedField of flattenAllFields({ fields: tab.fields })) {\n result.push(nestedField)\n }\n } else {\n result.push({\n ...tab,\n type: 'tab',\n flattenedFields: flattenAllFields({ fields: tab.fields }),\n })\n }\n }\n break\n }\n\n default: {\n if (field.type !== 'ui') {\n result.push(field)\n }\n }\n }\n }\n\n flattenedFieldsCache.set(fields, result)\n\n return result\n}\n"],"names":["tabHasName","flattenBlock","block","flattenedFields","flattenAllFields","fields","flattenedFieldsCache","Map","cache","maybeFields","get","result","field","type","push","blocks","blockReferences","undefined","resultField","nestedField","tab","tabs","set"],"mappings":"AASA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,eAAe,CAAC,EAAEC,KAAK,EAAoB;IACtD,OAAO;QACL,GAAGA,KAAK;QACRC,iBAAiBC,iBAAiB;YAAEC,QAAQH,MAAMG,MAAM;QAAC;IAC3D;AACF,EAAC;AAED,MAAMC,uBAAuB,IAAIC;AAEjC;;;;CAIC,GACD,OAAO,MAAMH,mBAAmB,CAAC,EAC/BI,KAAK,EACLH,MAAM,EAKP;IACC,IAAIG,OAAO;QACT,MAAMC,cAAcH,qBAAqBI,GAAG,CAACL;QAC7C,IAAII,aAAa;YACf,OAAOA;QACT;IACF;IAEA,MAAME,SAA2B,EAAE;IAEnC,KAAK,MAAMC,SAASP,OAAQ;QAC1B,OAAQO,MAAMC,IAAI;YAChB,KAAK;YACL,KAAK;gBAAS;oBACZF,OAAOG,IAAI,CAAC;wBAAE,GAAGF,KAAK;wBAAET,iBAAiBC,iBAAiB;4BAAEC,QAAQO,MAAMP,MAAM;wBAAC;oBAAG;oBACpF;gBACF;YAEA,KAAK;gBAAU;oBACb,MAAMU,SAA2B,EAAE;oBACnC,IAAIC,kBAA2DC;oBAC/D,IAAIL,MAAMI,eAAe,EAAE;wBACzBA,kBAAkB,EAAE;wBACpB,KAAK,MAAMd,SAASU,MA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,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.32.0-internal.f2e77bd",
3
+ "version": "3.33.0-internal.d1efdd8",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -99,7 +99,7 @@
99
99
  "tsx": "4.19.2",
100
100
  "uuid": "10.0.0",
101
101
  "ws": "^8.16.0",
102
- "@payloadcms/translations": "3.32.0-internal.f2e77bd"
102
+ "@payloadcms/translations": "3.33.0-internal.d1efdd8"
103
103
  },
104
104
  "devDependencies": {
105
105
  "@hyrious/esbuild-plugin-commonjs": "^0.2.4",
@@ -1,9 +0,0 @@
1
- import type { BaseJob } from '../config/types/workflowTypes.js';
2
- /**
3
- * Our payload operations sanitize the input data to, for example, add missing IDs to array rows.
4
- * This function is used to manually sanitize the data for direct db adapter operations
5
- */
6
- export declare function sanitizeUpdateData({ data }: {
7
- data: Partial<BaseJob>;
8
- }): Partial<BaseJob>;
9
- //# sourceMappingURL=sanitizeUpdateData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitizeUpdateData.d.ts","sourceRoot":"","sources":["../../../src/queues/utilities/sanitizeUpdateData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAA;AAK/D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBzF"}
@@ -1,25 +0,0 @@
1
- import ObjectIdImport from 'bson-objectid';
2
- const ObjectId = ObjectIdImport.default || ObjectIdImport;
3
- /**
4
- * Our payload operations sanitize the input data to, for example, add missing IDs to array rows.
5
- * This function is used to manually sanitize the data for direct db adapter operations
6
- */ export function sanitizeUpdateData({ data }) {
7
- if (data.log) {
8
- const sanitizedData = {
9
- ...data
10
- };
11
- sanitizedData.log = sanitizedData?.log?.map((log)=>{
12
- if (log.id) {
13
- return log;
14
- }
15
- return {
16
- ...log,
17
- id: new ObjectId().toHexString()
18
- };
19
- });
20
- return sanitizedData;
21
- }
22
- return data;
23
- }
24
-
25
- //# sourceMappingURL=sanitizeUpdateData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/queues/utilities/sanitizeUpdateData.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { BaseJob } from '../config/types/workflowTypes.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\n/**\n * Our payload operations sanitize the input data to, for example, add missing IDs to array rows.\n * This function is used to manually sanitize the data for direct db adapter operations\n */\nexport function sanitizeUpdateData({ data }: { data: Partial<BaseJob> }): Partial<BaseJob> {\n if (data.log) {\n const sanitizedData = { ...data }\n sanitizedData.log = sanitizedData?.log?.map((log) => {\n if (log.id) {\n return log\n }\n return {\n ...log,\n id: new ObjectId().toHexString(),\n }\n })\n return sanitizedData\n }\n\n return data\n}\n"],"names":["ObjectIdImport","ObjectId","default","sanitizeUpdateData","data","log","sanitizedData","map","id","toHexString"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAI1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AAEF;;;CAGC,GACD,OAAO,SAASG,mBAAmB,EAAEC,IAAI,EAA8B;IACrE,IAAIA,KAAKC,GAAG,EAAE;QACZ,MAAMC,gBAAgB;YAAE,GAAGF,IAAI;QAAC;QAChCE,cAAcD,GAAG,GAAGC,eAAeD,KAAKE,IAAI,CAACF;YAC3C,IAAIA,IAAIG,EAAE,EAAE;gBACV,OAAOH;YACT;YACA,OAAO;gBACL,GAAGA,GAAG;gBACNG,IAAI,IAAIP,WAAWQ,WAAW;YAChC;QACF;QACA,OAAOH;IACT;IAEA,OAAOF;AACT"}