payload 3.0.0-beta.85 → 3.0.0-beta.87

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 (104) hide show
  1. package/dist/admin/fields/Array.d.ts +12 -8
  2. package/dist/admin/fields/Array.d.ts.map +1 -1
  3. package/dist/admin/fields/Array.js.map +1 -1
  4. package/dist/admin/fields/Blocks.d.ts +12 -8
  5. package/dist/admin/fields/Blocks.d.ts.map +1 -1
  6. package/dist/admin/fields/Blocks.js.map +1 -1
  7. package/dist/admin/fields/Checkbox.d.ts +12 -8
  8. package/dist/admin/fields/Checkbox.d.ts.map +1 -1
  9. package/dist/admin/fields/Checkbox.js.map +1 -1
  10. package/dist/admin/fields/Code.d.ts +12 -8
  11. package/dist/admin/fields/Code.d.ts.map +1 -1
  12. package/dist/admin/fields/Code.js.map +1 -1
  13. package/dist/admin/fields/Collapsible.d.ts +12 -9
  14. package/dist/admin/fields/Collapsible.d.ts.map +1 -1
  15. package/dist/admin/fields/Collapsible.js.map +1 -1
  16. package/dist/admin/fields/Date.d.ts +12 -8
  17. package/dist/admin/fields/Date.d.ts.map +1 -1
  18. package/dist/admin/fields/Date.js.map +1 -1
  19. package/dist/admin/fields/Email.d.ts +12 -8
  20. package/dist/admin/fields/Email.d.ts.map +1 -1
  21. package/dist/admin/fields/Email.js.map +1 -1
  22. package/dist/admin/fields/Group.d.ts +12 -9
  23. package/dist/admin/fields/Group.d.ts.map +1 -1
  24. package/dist/admin/fields/Group.js.map +1 -1
  25. package/dist/admin/fields/Hidden.d.ts +1 -5
  26. package/dist/admin/fields/Hidden.d.ts.map +1 -1
  27. package/dist/admin/fields/Hidden.js.map +1 -1
  28. package/dist/admin/fields/JSON.d.ts +12 -8
  29. package/dist/admin/fields/JSON.d.ts.map +1 -1
  30. package/dist/admin/fields/JSON.js.map +1 -1
  31. package/dist/admin/fields/Number.d.ts +12 -8
  32. package/dist/admin/fields/Number.d.ts.map +1 -1
  33. package/dist/admin/fields/Number.js.map +1 -1
  34. package/dist/admin/fields/Point.d.ts +12 -8
  35. package/dist/admin/fields/Point.d.ts.map +1 -1
  36. package/dist/admin/fields/Point.js.map +1 -1
  37. package/dist/admin/fields/Radio.d.ts +12 -8
  38. package/dist/admin/fields/Radio.d.ts.map +1 -1
  39. package/dist/admin/fields/Radio.js.map +1 -1
  40. package/dist/admin/fields/Relationship.d.ts +12 -8
  41. package/dist/admin/fields/Relationship.d.ts.map +1 -1
  42. package/dist/admin/fields/Relationship.js.map +1 -1
  43. package/dist/admin/fields/RichText.d.ts +12 -8
  44. package/dist/admin/fields/RichText.d.ts.map +1 -1
  45. package/dist/admin/fields/RichText.js.map +1 -1
  46. package/dist/admin/fields/Row.d.ts +13 -10
  47. package/dist/admin/fields/Row.d.ts.map +1 -1
  48. package/dist/admin/fields/Row.js.map +1 -1
  49. package/dist/admin/fields/Select.d.ts +12 -8
  50. package/dist/admin/fields/Select.d.ts.map +1 -1
  51. package/dist/admin/fields/Select.js.map +1 -1
  52. package/dist/admin/fields/Tabs.d.ts +11 -9
  53. package/dist/admin/fields/Tabs.d.ts.map +1 -1
  54. package/dist/admin/fields/Tabs.js.map +1 -1
  55. package/dist/admin/fields/Text.d.ts +12 -8
  56. package/dist/admin/fields/Text.d.ts.map +1 -1
  57. package/dist/admin/fields/Text.js.map +1 -1
  58. package/dist/admin/fields/Textarea.d.ts +12 -8
  59. package/dist/admin/fields/Textarea.d.ts.map +1 -1
  60. package/dist/admin/fields/Textarea.js.map +1 -1
  61. package/dist/admin/fields/Upload.d.ts +12 -8
  62. package/dist/admin/fields/Upload.d.ts.map +1 -1
  63. package/dist/admin/fields/Upload.js.map +1 -1
  64. package/dist/admin/forms/Description.d.ts +24 -0
  65. package/dist/admin/forms/Description.d.ts.map +1 -0
  66. package/dist/admin/forms/Description.js +3 -0
  67. package/dist/admin/forms/Description.js.map +1 -0
  68. package/dist/admin/forms/Error.d.ts +12 -5
  69. package/dist/admin/forms/Error.d.ts.map +1 -1
  70. package/dist/admin/forms/Error.js.map +1 -1
  71. package/dist/admin/forms/Field.d.ts +12 -10
  72. package/dist/admin/forms/Field.d.ts.map +1 -1
  73. package/dist/admin/forms/Field.js +0 -1
  74. package/dist/admin/forms/Field.js.map +1 -1
  75. package/dist/admin/forms/Label.d.ts +13 -6
  76. package/dist/admin/forms/Label.d.ts.map +1 -1
  77. package/dist/admin/forms/Label.js.map +1 -1
  78. package/dist/admin/types.d.ts +32 -26
  79. package/dist/admin/types.d.ts.map +1 -1
  80. package/dist/admin/types.js.map +1 -1
  81. package/dist/collections/config/client.d.ts +2 -2
  82. package/dist/collections/config/client.d.ts.map +1 -1
  83. package/dist/collections/config/client.js.map +1 -1
  84. package/dist/config/types.d.ts +8 -8
  85. package/dist/config/types.d.ts.map +1 -1
  86. package/dist/config/types.js.map +1 -1
  87. package/dist/exports/shared.d.ts.map +1 -1
  88. package/dist/exports/shared.js.map +1 -1
  89. package/dist/fields/config/types.d.ts +49 -48
  90. package/dist/fields/config/types.d.ts.map +1 -1
  91. package/dist/fields/config/types.js.map +1 -1
  92. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  93. package/dist/utilities/configToJSONSchema.js +6 -2
  94. package/dist/utilities/configToJSONSchema.js.map +1 -1
  95. package/dist/utilities/configToJSONSchema.spec.js +160 -0
  96. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  97. package/dist/utilities/flattenTopLevelFields.d.ts +2 -2
  98. package/dist/utilities/flattenTopLevelFields.d.ts.map +1 -1
  99. package/dist/utilities/flattenTopLevelFields.js.map +1 -1
  100. package/package.json +2 -2
  101. package/dist/admin/forms/FieldDescription.d.ts +0 -17
  102. package/dist/admin/forms/FieldDescription.d.ts.map +0 -1
  103. package/dist/admin/forms/FieldDescription.js +0 -3
  104. package/dist/admin/forms/FieldDescription.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\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 { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\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 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) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\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): {\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) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\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 = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\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 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 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 oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\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 break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\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\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\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 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 incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\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 return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\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 '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 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 }\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\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): 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 // 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 const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\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 collections: generateEntitySchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth', 'db'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","password","username","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAQrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe,OAAO;IAE1B,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIZ,iBAAiBM,UAAUK,kBAAkB,OAAO;IAExD,wDAAwD;IACxD,IAAI,YAAYL,SAASA,MAAMO,IAAI,KAAK,SAAS;QAC/C,OAAOP,MAAMQ,MAAM,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;IACzD;IAEA,oEAAoE;IACpE,IAAIV,MAAMO,IAAI,KAAK,QAAQ;QACzB,OAAOP,MAAMW,IAAI,CAACF,IAAI,CAAC,CAACG;YACtB,IAAI,UAAUA,KAAK;gBACjB,OAAOA,IAAIJ,MAAM,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;YACvD;YACA,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OAAO,IAAI,EAAE;YACnD7F,QAAQJ,4BAA4Bc,OAAOb,YAAY;YACvDoG,MAAM9F,0BAA0BO,OAAOgF,WAAW;QACpD;QACApH,UAAU;YAAC;YAAQ;YAAU;YAAe;YAAW;YAAQ;SAAK;QACpEyF,OAAO;IACT;IAEA,IAAIrD,QAAQsD,YAAYjC,QAAQ0B,QAAQ;QACtC,KAAK,MAAM1B,UAAUrB,OAAOsD,UAAU,CAACjC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\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 { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\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 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) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\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): {\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) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\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 = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\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 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 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 oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\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(field.blocks.length)\n\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: hasBlocks\n ? {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\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\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\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\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\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 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 incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\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 return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\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 '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 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 }\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\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): 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 // 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 const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\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 collections: generateEntitySchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth', 'db'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","hasBlocks","blocks","length","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","Map","from","entityToJSONSchema","incomingEntity","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","password","username","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAQrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QA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IAAI,CAAC,GAAGsE,mBAAmBnD,QAAQqD,QAAQ3C,0BAA0BT;QAChF,OAAOrB;IACT,GAAG,CAAC;IAEJ,MAAMyG,2BAA2B;WAAIrF,OAAOiF,WAAW;KAAC,CACrDvF,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKnC,QAAQmC,OAC7BhB,MAAM,CACL,CAACC,KAAK0G;QACJ1G,IAAIe,IAAI,CAAC2F,eAAezG,IAAI,CAAC,GAAG2F,qCAAqCc;QACrE,OAAO1G;IACT,GACA;QAAEe,MAAM,CAAC;IAAE;IAGf,IAAIyB,aAA0B;QAC5BrC,sBAAsB;QACtBwG,aAAa;YACX,GAAGJ,iBAAiB;YACpB,GAAGnG,OAAO6B,WAAW,CAACH,yBAAyB;YAC/C,GAAG2E,wBAAwB;QAC7B;QACA,wJAAwJ;QACxJxH,MAAM;QACNa,YAAY;YACViB,MAAMqF,6BAA6BhF,OAAOiF,WAAW;YACrDA,aAAazG,sBAAsBwB,OAAOiF,WAAW,IAAI,EAAE;YAC3D/E,IAAIH,uBAAuBC;YAC3BoF,SAAS5G,sBAAsBwB,OAAOoF,OAAO,IAAI,EAAE;YACnD9F,QAAQJ,4BAA4Bc,OAAOb,YAAY;YACvDqG,MAAM/F,0BAA0BO,OAAOiF,WAAW;QACpD;QACArH,UAAU;YAAC;YAAQ;YAAU;YAAe;YAAW;YAAQ;SAAK;QACpE0F,OAAO;IACT;IAEA,IAAItD,QAAQuD,YAAYlC,QAAQc,QAAQ;QACtC,KAAK,MAAMd,UAAUrB,OAAOuD,UAAU,CAAClC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
@@ -64,6 +64,166 @@ describe('configToJSONSchema', ()=>{
64
64
  title: 'Test'
65
65
  });
66
66
  });
67
+ it('should handle block fields with no blocks', async ()=>{
68
+ // @ts-expect-error
69
+ const config = {
70
+ collections: [
71
+ {
72
+ slug: 'test',
73
+ fields: [
74
+ {
75
+ name: 'blockField',
76
+ type: 'blocks',
77
+ blocks: []
78
+ },
79
+ {
80
+ name: 'blockFieldRequired',
81
+ type: 'blocks',
82
+ blocks: [],
83
+ required: true
84
+ },
85
+ {
86
+ name: 'blockFieldWithFields',
87
+ type: 'blocks',
88
+ blocks: [
89
+ {
90
+ slug: 'test',
91
+ fields: [
92
+ {
93
+ name: 'field',
94
+ type: 'text'
95
+ }
96
+ ]
97
+ }
98
+ ]
99
+ },
100
+ {
101
+ name: 'blockFieldWithFieldsRequired',
102
+ type: 'blocks',
103
+ blocks: [
104
+ {
105
+ slug: 'test',
106
+ fields: [
107
+ {
108
+ name: 'field',
109
+ type: 'text',
110
+ required: true
111
+ }
112
+ ]
113
+ }
114
+ ]
115
+ }
116
+ ],
117
+ timestamps: false
118
+ }
119
+ ]
120
+ };
121
+ const sanitizedConfig = await sanitizeConfig(config);
122
+ const schema = configToJSONSchema(sanitizedConfig, 'text');
123
+ expect(schema?.definitions?.test).toStrictEqual({
124
+ type: 'object',
125
+ additionalProperties: false,
126
+ properties: {
127
+ id: {
128
+ type: 'string'
129
+ },
130
+ blockField: {
131
+ type: [
132
+ 'array',
133
+ 'null'
134
+ ],
135
+ items: {}
136
+ },
137
+ blockFieldRequired: {
138
+ type: 'array',
139
+ items: {}
140
+ },
141
+ blockFieldWithFields: {
142
+ type: [
143
+ 'array',
144
+ 'null'
145
+ ],
146
+ items: {
147
+ oneOf: [
148
+ {
149
+ type: 'object',
150
+ additionalProperties: false,
151
+ properties: {
152
+ id: {
153
+ type: [
154
+ 'string',
155
+ 'null'
156
+ ]
157
+ },
158
+ blockName: {
159
+ type: [
160
+ 'string',
161
+ 'null'
162
+ ]
163
+ },
164
+ blockType: {
165
+ const: 'test'
166
+ },
167
+ field: {
168
+ type: [
169
+ 'string',
170
+ 'null'
171
+ ]
172
+ }
173
+ },
174
+ required: [
175
+ 'blockType'
176
+ ]
177
+ }
178
+ ]
179
+ }
180
+ },
181
+ blockFieldWithFieldsRequired: {
182
+ type: [
183
+ 'array',
184
+ 'null'
185
+ ],
186
+ items: {
187
+ oneOf: [
188
+ {
189
+ type: 'object',
190
+ additionalProperties: false,
191
+ properties: {
192
+ id: {
193
+ type: [
194
+ 'string',
195
+ 'null'
196
+ ]
197
+ },
198
+ blockName: {
199
+ type: [
200
+ 'string',
201
+ 'null'
202
+ ]
203
+ },
204
+ blockType: {
205
+ const: 'test'
206
+ },
207
+ field: {
208
+ type: 'string'
209
+ }
210
+ },
211
+ required: [
212
+ 'blockType',
213
+ 'field'
214
+ ]
215
+ }
216
+ ]
217
+ }
218
+ }
219
+ },
220
+ required: [
221
+ 'id',
222
+ 'blockFieldRequired'
223
+ ],
224
+ title: 'Test'
225
+ });
226
+ });
67
227
  it('should handle tabs and named tabs with required fields', async ()=>{
68
228
  // @ts-expect-error
69
229
  const config = {
@@ -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'\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 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"],"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","tabs","label","fieldInUnnamedTab","namedTab","fieldInNamedTab","namedTabWithRequired","customSchema","typescriptSchema","jsonSchema","fileMatch","uri","jsonWithSchema","withCustom"],"mappings":"AAIA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5DC,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;Y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AAU;oBAAC;iBAAK;YAClB;QACF;QAEA,MAAMN,SAA0B;YAC9BC,aAAa;gBACX;oBACEC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNsB,kBAAkB;gCAAC,IAAMD;6BAAa;wBACxC;wBACA;4BACEtB,MAAM;4BACNC,MAAM;4BACNuB,YAAY;gCACVC,WAAW;oCAAC;iCAAiB;gCAC7BpB,QAAQiB;gCACRI,KAAK;4BACP;wBACF;qBACD;oBACDvB,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;gBACA0B,gBAAgBL;gBAChBM,YAAYN;YACd;YACApB,UAAU;gBAAC;aAAK;YAChBa,OAAO;QACT;IACF;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'\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"],"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"],"mappings":"AAIA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5DC,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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1
  import type { ClientField } from '../fields/config/client.js';
2
2
  import type { Field, FieldAffectingData, FieldAffectingDataClient, FieldPresentationalOnly, FieldPresentationalOnlyClient } from '../fields/config/types.js';
3
- type FlattenedField<T> = T extends ClientField ? FieldAffectingDataClient | FieldPresentationalOnlyClient : FieldAffectingData | FieldPresentationalOnly;
3
+ type FlattenedField<TField> = TField extends ClientField ? FieldAffectingDataClient | FieldPresentationalOnlyClient : FieldAffectingData | FieldPresentationalOnly;
4
4
  /**
5
5
  * Flattens a collection's fields into a single array of fields, as long
6
6
  * as the fields do not affect data.
@@ -8,6 +8,6 @@ type FlattenedField<T> = T extends ClientField ? FieldAffectingDataClient | Fiel
8
8
  * @param fields
9
9
  * @param keepPresentationalFields if true, will skip flattening fields that are presentational only
10
10
  */
11
- declare function flattenFields<T extends ClientField | Field>(fields: T[], keepPresentationalFields?: boolean): FlattenedField<T>[];
11
+ declare function flattenFields<TField extends ClientField | Field>(fields: TField[], keepPresentationalFields?: boolean): FlattenedField<TField>[];
12
12
  export default flattenFields;
13
13
  //# sourceMappingURL=flattenTopLevelFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flattenTopLevelFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenTopLevelFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,6BAA6B,EAE9B,MAAM,2BAA2B,CAAA;AAUlC,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,GAC1C,wBAAwB,GAAG,6BAA6B,GACxD,kBAAkB,GAAG,uBAAuB,CAAA;AAIhD;;;;;;GAMG;AACH,iBAAS,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK,EAClD,MAAM,EAAE,CAAC,EAAE,EACX,wBAAwB,CAAC,EAAE,OAAO,GACjC,cAAc,CAAC,CAAC,CAAC,EAAE,CAyBrB;AAED,eAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"flattenTopLevelFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenTopLevelFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,6BAA6B,EAE9B,MAAM,2BAA2B,CAAA;AASlC,KAAK,cAAc,CAAC,MAAM,IAAI,MAAM,SAAS,WAAW,GACpD,wBAAwB,GAAG,6BAA6B,GACxD,kBAAkB,GAAG,uBAAuB,CAAA;AAIhD;;;;;;GAMG;AACH,iBAAS,aAAa,CAAC,MAAM,SAAS,WAAW,GAAG,KAAK,EACvD,MAAM,EAAE,MAAM,EAAE,EAChB,wBAAwB,CAAC,EAAE,OAAO,GACjC,cAAc,CAAC,MAAM,CAAC,EAAE,CA4B1B;AAED,eAAe,aAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/flattenTopLevelFields.ts"],"sourcesContent":["import type { ClientField } from '../fields/config/client.js'\nimport type {\n Field,\n FieldAffectingData,\n FieldAffectingDataClient,\n FieldPresentationalOnly,\n FieldPresentationalOnlyClient,\n Tab,\n} from '../fields/config/types.js'\n\nimport {\n fieldAffectsData,\n fieldHasSubFields,\n fieldIsPresentationalOnly,\n tabHasName,\n} from '../fields/config/types.js'\nimport { ClientTab } from '../admin/fields/Tabs.js'\n\ntype FlattenedField<T> = T extends ClientField\n ? FieldAffectingDataClient | FieldPresentationalOnlyClient\n : FieldAffectingData | FieldPresentationalOnly\n\ntype TabType<T> = T extends ClientField ? ClientTab : Tab\n\n/**\n * Flattens a collection's fields into a single array of fields, as long\n * as the fields do not affect data.\n *\n * @param fields\n * @param keepPresentationalFields if true, will skip flattening fields that are presentational only\n */\nfunction flattenFields<T extends ClientField | Field>(\n fields: T[],\n keepPresentationalFields?: boolean,\n): FlattenedField<T>[] {\n return fields.reduce<FlattenedField<T>[]>((fieldsToUse, field) => {\n if (fieldAffectsData(field) || (keepPresentationalFields && fieldIsPresentationalOnly(field))) {\n return [...fieldsToUse, field as FlattenedField<T>]\n }\n\n if (fieldHasSubFields(field)) {\n return [...fieldsToUse, ...flattenFields(field.fields as T[], keepPresentationalFields)]\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce<FlattenedField<T>[]>((tabFields, tab: TabType<T>) => {\n if (tabHasName(tab)) {\n return [...tabFields, { ...tab, type: 'tab' } as unknown as FlattenedField<T>]\n } else {\n return [...tabFields, ...flattenFields(tab.fields as T[], keepPresentationalFields)]\n }\n }, []),\n ]\n }\n\n return fieldsToUse\n }, [])\n}\n\nexport default flattenFields\n"],"names":["fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","tabHasName","flattenFields","fields","keepPresentationalFields","reduce","fieldsToUse","field","type","tabs","tabFields","tab"],"mappings":"AAUA,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,yBAAyB,EACzBC,UAAU,QACL,4BAA2B;AASlC;;;;;;CAMC,GACD,SAASC,cACPC,MAAW,EACXC,wBAAkC;IAElC,OAAOD,OAAOE,MAAM,CAAsB,CAACC,aAAaC;QACtD,IAAIT,iBAAiBS,UAAWH,4BAA4BJ,0BAA0BO,QAAS;YAC7F,OAAO;mBAAID;gBAAaC;aAA2B;QACrD;QAEA,IAAIR,kBAAkBQ,QAAQ;YAC5B,OAAO;mBAAID;mBAAgBJ,cAAcK,MAAMJ,MAAM,EAASC;aAA0B;QAC1F;QAEA,IAAIG,MAAMC,IAAI,KAAK,UAAU,UAAUD,OAAO;YAC5C,OAAO;mBACFD;mBACAC,MAAME,IAAI,CAACJ,MAAM,CAAsB,CAACK,WAAWC;oBACpD,IAAIV,WAAWU,MAAM;wBACnB,OAAO;+BAAID;4BAAW;gCAAE,GAAGC,GAAG;gCAAEH,MAAM;4BAAM;yBAAkC;oBAChF,OAAO;wBACL,OAAO;+BAAIE;+BAAcR,cAAcS,IAAIR,MAAM,EAASC;yBAA0B;oBACtF;gBACF,GAAG,EAAE;aACN;QACH;QAEA,OAAOE;IACT,GAAG,EAAE;AACP;AAEA,eAAeJ,cAAa"}
1
+ {"version":3,"sources":["../../src/utilities/flattenTopLevelFields.ts"],"sourcesContent":["import type { ClientTab } from '../admin/fields/Tabs.js'\nimport type { ClientField } from '../fields/config/client.js'\nimport type {\n Field,\n FieldAffectingData,\n FieldAffectingDataClient,\n FieldPresentationalOnly,\n FieldPresentationalOnlyClient,\n Tab,\n} from '../fields/config/types.js'\n\nimport {\n fieldAffectsData,\n fieldHasSubFields,\n fieldIsPresentationalOnly,\n tabHasName,\n} from '../fields/config/types.js'\n\ntype FlattenedField<TField> = TField extends ClientField\n ? FieldAffectingDataClient | FieldPresentationalOnlyClient\n : FieldAffectingData | FieldPresentationalOnly\n\ntype TabType<TField> = TField extends ClientField ? ClientTab : Tab\n\n/**\n * Flattens a collection's fields into a single array of fields, as long\n * as the fields do not affect data.\n *\n * @param fields\n * @param keepPresentationalFields if true, will skip flattening fields that are presentational only\n */\nfunction flattenFields<TField extends ClientField | Field>(\n fields: TField[],\n keepPresentationalFields?: boolean,\n): FlattenedField<TField>[] {\n return fields.reduce<FlattenedField<TField>[]>((fieldsToUse, field) => {\n if (fieldAffectsData(field) || (keepPresentationalFields && fieldIsPresentationalOnly(field))) {\n return [...fieldsToUse, field as FlattenedField<TField>]\n }\n\n if (fieldHasSubFields(field)) {\n return [...fieldsToUse, ...flattenFields(field.fields as TField[], keepPresentationalFields)]\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...fieldsToUse,\n ...field.tabs.reduce<FlattenedField<TField>[]>((tabFields, tab: TabType<TField>) => {\n if (tabHasName(tab)) {\n return [...tabFields, { ...tab, type: 'tab' } as unknown as FlattenedField<TField>]\n } else {\n return [\n ...tabFields,\n ...flattenFields(tab.fields as TField[], keepPresentationalFields),\n ]\n }\n }, []),\n ]\n }\n\n return fieldsToUse\n }, [])\n}\n\nexport default flattenFields\n"],"names":["fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","tabHasName","flattenFields","fields","keepPresentationalFields","reduce","fieldsToUse","field","type","tabs","tabFields","tab"],"mappings":"AAWA,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,yBAAyB,EACzBC,UAAU,QACL,4BAA2B;AAQlC;;;;;;CAMC,GACD,SAASC,cACPC,MAAgB,EAChBC,wBAAkC;IAElC,OAAOD,OAAOE,MAAM,CAA2B,CAACC,aAAaC;QAC3D,IAAIT,iBAAiBS,UAAWH,4BAA4BJ,0BAA0BO,QAAS;YAC7F,OAAO;mBAAID;gBAAaC;aAAgC;QAC1D;QAEA,IAAIR,kBAAkBQ,QAAQ;YAC5B,OAAO;mBAAID;mBAAgBJ,cAAcK,MAAMJ,MAAM,EAAcC;aAA0B;QAC/F;QAEA,IAAIG,MAAMC,IAAI,KAAK,UAAU,UAAUD,OAAO;YAC5C,OAAO;mBACFD;mBACAC,MAAME,IAAI,CAACJ,MAAM,CAA2B,CAACK,WAAWC;oBACzD,IAAIV,WAAWU,MAAM;wBACnB,OAAO;+BAAID;4BAAW;gCAAE,GAAGC,GAAG;gCAAEH,MAAM;4BAAM;yBAAuC;oBACrF,OAAO;wBACL,OAAO;+BACFE;+BACAR,cAAcS,IAAIR,MAAM,EAAcC;yBAC1C;oBACH;gBACF,GAAG,EAAE;aACN;QACH;QAEA,OAAOE;IACT,GAAG,EAAE;AACP;AAEA,eAAeJ,cAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.0.0-beta.85",
3
+ "version": "3.0.0-beta.87",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -95,7 +95,7 @@
95
95
  "ts-essentials": "7.0.3",
96
96
  "tsx": "4.17.0",
97
97
  "uuid": "10.0.0",
98
- "@payloadcms/translations": "3.0.0-beta.85"
98
+ "@payloadcms/translations": "3.0.0-beta.87"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@hyrious/esbuild-plugin-commonjs": "^0.2.4",
@@ -1,17 +0,0 @@
1
- import type { CustomComponent, LabelFunction, ServerProps } from '../../config/types.js';
2
- import type { FieldTypes } from '../../fields/config/types.js';
3
- import type { MappedComponent } from '../types.js';
4
- export type DescriptionFunction = LabelFunction;
5
- export type DescriptionComponent<T extends 'hidden' | FieldTypes = any> = CustomComponent<FieldDescriptionProps<T>>;
6
- export type StaticDescription = Record<string, string> | string;
7
- export type Description = DescriptionFunction | StaticDescription;
8
- export type GenericDescriptionProps = {
9
- readonly Description?: MappedComponent;
10
- readonly className?: string;
11
- readonly description?: StaticDescription;
12
- readonly marginPlacement?: 'bottom' | 'top';
13
- };
14
- export type FieldDescriptionProps<T extends 'hidden' | FieldTypes = any> = {
15
- type: T;
16
- } & GenericDescriptionProps & Partial<ServerProps>;
17
- //# sourceMappingURL=FieldDescription.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldDescription.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/FieldDescription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAA;AAE/C,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,GAAG,IAAI,eAAe,CACvF,qBAAqB,CAAC,CAAC,CAAC,CACzB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;AAE/D,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,iBAAiB,CAAA;AACjE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAA;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAA;IACxC,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CAC5C,CAAA;AACD,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,GAAG,IAAI;IACzE,IAAI,EAAE,CAAC,CAAA;CACR,GAAG,uBAAuB,GACzB,OAAO,CAAC,WAAW,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=FieldDescription.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/admin/forms/FieldDescription.ts"],"sourcesContent":["import type { CustomComponent, LabelFunction, ServerProps } from '../../config/types.js'\nimport type { FieldTypes } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\n\nexport type DescriptionFunction = LabelFunction\n\nexport type DescriptionComponent<T extends 'hidden' | FieldTypes = any> = CustomComponent<\n FieldDescriptionProps<T>\n>\n\nexport type StaticDescription = Record<string, string> | string\n\nexport type Description = DescriptionFunction | StaticDescription\nexport type GenericDescriptionProps = {\n readonly Description?: MappedComponent\n readonly className?: string\n readonly description?: StaticDescription\n readonly marginPlacement?: 'bottom' | 'top'\n}\nexport type FieldDescriptionProps<T extends 'hidden' | FieldTypes = any> = {\n type: T\n} & GenericDescriptionProps &\n Partial<ServerProps>\n"],"names":[],"mappings":"AAmBA,WAGsB"}