payload 3.78.0-internal-debug.f663370 → 3.78.0-internal.ab11ffa
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.
- package/dist/admin/forms/Form.d.ts +6 -0
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/views/dashboard.d.ts +19 -4
- package/dist/admin/views/dashboard.d.ts.map +1 -1
- package/dist/admin/views/dashboard.js.map +1 -1
- package/dist/admin/views/list.d.ts +2 -0
- package/dist/admin/views/list.d.ts.map +1 -1
- package/dist/admin/views/list.js.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.js +10 -0
- package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
- package/dist/collections/config/types.d.ts +0 -1
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +2 -0
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +2 -0
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/config/client.d.ts +4 -2
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +10 -2
- package/dist/config/client.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +13 -0
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +14 -5
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +4 -0
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/exports/shared.d.ts +1 -0
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -0
- package/dist/exports/shared.js.map +1 -1
- package/dist/index.bundled.d.ts +60 -11
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.js +4 -1
- package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
- package/dist/uploads/generateFileData.js +1 -1
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +7 -5
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +105 -6
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +36 -4
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/filterDataToSelectedLocales.d.ts.map +1 -1
- package/dist/utilities/filterDataToSelectedLocales.js +7 -1
- package/dist/utilities/filterDataToSelectedLocales.js.map +1 -1
- package/dist/utilities/filterDataToSelectedLocales.spec.js +193 -0
- package/dist/utilities/filterDataToSelectedLocales.spec.js.map +1 -0
- package/dist/utilities/mergeLocalizedData.d.ts.map +1 -1
- package/dist/utilities/mergeLocalizedData.js +51 -16
- package/dist/utilities/mergeLocalizedData.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.spec.js +324 -0
- package/dist/utilities/mergeLocalizedData.spec.js.map +1 -1
- package/dist/utilities/sanitizeFilename.d.ts +6 -0
- package/dist/utilities/sanitizeFilename.d.ts.map +1 -0
- package/dist/utilities/sanitizeFilename.js +22 -0
- package/dist/utilities/sanitizeFilename.js.map +1 -0
- package/dist/versions/saveVersion.js +1 -1
- package/dist/versions/saveVersion.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { FieldAffectingData, FlattenedField, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { generateJobsJSONSchemas } from '../queues/config/generateJobsJSONSchemas.js'\nimport { formatNames } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\nimport { optionsAreEqual } from './optionsAreEqual.js'\n\nconst fieldIsRequired = (field: FlattenedField): boolean => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) {\n return false\n }\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) {\n return true\n }\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.flattenedFields.some((subField) => fieldIsRequired(subField))\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce(\n (acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateEntitySelectSchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce(\n (acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}_select`,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateCollectionJoinsSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = [...collections].reduce<Record<string, JSONSchema4>>(\n (acc, { slug, joins, polymorphicJoins }) => {\n const schema = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n required: [] as string[],\n } satisfies JSONSchema4\n\n for (const collectionSlug in joins) {\n for (const join of joins[collectionSlug]!) {\n ;(schema.properties as any)[join.joinPath] = {\n type: 'string',\n enum: [collectionSlug],\n }\n schema.required.push(join.joinPath)\n }\n }\n\n for (const join of polymorphicJoins) {\n ;(schema.properties as any)[join.joinPath] = {\n type: 'string',\n enum: join.field.collection,\n }\n schema.required.push(join.joinPath)\n }\n\n if (Object.keys(schema.properties).length > 0) {\n acc[slug] = schema\n }\n\n return acc\n },\n {},\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateFallbackLocaleEntitySchemas(\n localization: SanitizedConfig['localization'],\n): JSONSchema4 {\n if (localization && 'localeCodes' in localization && localization?.localeCodes) {\n const localeCodes = [...localization.localeCodes].map((localeCode) => {\n return localeCode\n }, [])\n\n return {\n oneOf: [\n { type: 'string', enum: ['false', 'none', 'null'] },\n { type: 'boolean', enum: [false] },\n { type: 'null' },\n { type: 'string', enum: localeCodes },\n { type: 'array', items: { type: 'string', enum: localeCodes } },\n ],\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return { $ref: `#/definitions/${slug}` }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n const defaultIDType: JSONSchema4 =\n config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n defaultIDType,\n },\n required: ['defaultIDType'],\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) {\n return fieldType\n }\n fieldTypes.push('null')\n return fieldTypes\n}\n\nfunction entityOrFieldToJsDocs({\n entity,\n i18n,\n}: {\n entity: FlattenedField | SanitizedCollectionConfig | SanitizedGlobalConfig\n i18n?: I18n\n}): string | undefined {\n let description: string | undefined = undefined\n if (entity?.admin?.description) {\n if (typeof entity?.admin?.description === 'string') {\n description = entity?.admin?.description\n } else if (typeof entity?.admin?.description === 'object') {\n if (entity?.admin?.description?.en) {\n description = entity?.admin?.description?.en\n } else if (entity?.admin?.description?.[i18n!.language]) {\n description = entity?.admin?.description?.[i18n!.language]\n }\n } else if (typeof entity?.admin?.description === 'function' && i18n) {\n // do not evaluate description functions for generating JSDocs. The output of\n // those can differ depending on where and when they are called, creating\n // inconsistencies in the generated JSDocs.\n }\n }\n return description\n}\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 if (fieldAffectsData(field)) {\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n }\n }\n break\n }\n\n case 'join': {\n let items: JSONSchema4\n\n if (Array.isArray(field.collection)) {\n items = {\n oneOf: field.collection.map((collection) => ({\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: collection,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[collection],\n },\n {\n $ref: `#/definitions/${collection}`,\n },\n ],\n },\n },\n required: ['collectionSlug', 'value'],\n })),\n }\n } else {\n items = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.collection],\n },\n {\n $ref: `#/definitions/${field.collection}`,\n },\n ],\n }\n }\n\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n properties: {\n docs: {\n type: 'array',\n items,\n },\n hasNextPage: { type: 'boolean' },\n totalDocs: { type: 'number' },\n },\n }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n ...baseFieldSchema,\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('number', isRequired),\n }\n }\n break\n }\n\n case 'point': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'radio': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n\n break\n }\n case 'relationship':\n case 'upload': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo]!,\n isRequired,\n ),\n },\n { $ref: `#/definitions/${field.relationTo}` },\n ],\n }\n }\n\n break\n }\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = {\n ...baseFieldSchema,\n ...field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n i18n,\n interfaceNameDefinitions,\n isRequired,\n }),\n }\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n // We get the previous field to check for a date in the case of a timezone select\n // This works because timezone selects are always inserted right after a date with 'timezone: true'\n const previousField = fields?.[index - 1]\n const isTimezoneField =\n previousField?.type === 'date' && previousField.timezone && field.name.includes('_tz')\n\n // Check if the timezone field's options match the global config's supported timezones\n const hasMatchingGlobalTimezones =\n isTimezoneField &&\n config &&\n optionsAreEqual(field.options, config.admin?.timezones?.supportedTimezones)\n\n // Timezone selects should reference the supportedTimezones definition\n // only if the field's options match the global config\n if (isTimezoneField && hasMatchingGlobalTimezones) {\n fieldSchema = {\n $ref: `#/definitions/supportedTimezones`,\n }\n } else {\n if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n },\n }\n if (optionEnums?.length) {\n ;(fieldSchema.items as JSONSchema4).enum = optionEnums\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n }\n if (optionEnums?.length) {\n fieldSchema.enum = optionEnums\n }\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n break\n }\n case 'tab': {\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n }\n break\n }\n\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n }\n }\n break\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema! })\n }\n }\n\n if (fieldSchema! && fieldAffectsData(field)) {\n if (isRequired && fieldSchema.required !== false) {\n requiredFieldNames.add(field.name)\n }\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n collectionIDFieldTypes?: { [key: string]: 'number' | 'string' },\n i18n?: I18n,\n): JSONSchema4 {\n if (!collectionIDFieldTypes) {\n collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n }\n\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : formatNames(entity.slug).singular\n\n let mutableFields = [...entity.flattenedFields]\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = mutableFields.find((field) => field.name === 'id') as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n mutableFields = mutableFields.map((field) => {\n if (field === customIdField) {\n return { ...field, required: true }\n }\n\n return field\n })\n } else {\n mutableFields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n mutableFields = mutableFields.map((field) => {\n if (field.name === 'createdAt' || field.name === 'updatedAt') {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if (\n 'auth' in entity &&\n entity.auth &&\n (!entity.auth?.disableLocalStrategy ||\n (typeof entity.auth?.disableLocalStrategy === 'object' &&\n entity.auth.disableLocalStrategy.enableFields))\n ) {\n mutableFields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n const isAuthCollection = 'auth' in entity && entity.auth\n\n const fieldsSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n mutableFields,\n interfaceNameDefinitions,\n config,\n i18n,\n )\n\n // Add collection property to auth collections\n if (isAuthCollection) {\n fieldsSchema.properties = {\n ...fieldsSchema.properties,\n collection: { type: 'string', enum: [entity.slug] },\n }\n fieldsSchema.required = [...(fieldsSchema.required || []), 'collection']\n }\n\n const jsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsSchema,\n }\n\n const entityDescription = entityOrFieldToJsDocs({ entity, i18n })\n\n if (entityDescription) {\n jsonSchema.description = entityDescription\n }\n\n return jsonSchema\n}\n\nexport function fieldsToSelectJSONSchema({\n config,\n fields,\n interfaceNameDefinitions,\n}: {\n config: SanitizedConfig\n fields: FlattenedField[]\n interfaceNameDefinitions: Map<string, JSONSchema4>\n}): JSONSchema4 {\n const schema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n }\n\n for (const field of fields) {\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n let fieldSchema: JSONSchema4 = fieldsToSelectJSONSchema({\n config,\n fields: field.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (field.interfaceName) {\n const definition = `${field.interfaceName}_select`\n interfaceNameDefinitions.set(definition, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${definition}`,\n }\n }\n\n schema.properties![field.name] = {\n oneOf: [\n {\n type: 'boolean',\n },\n fieldSchema,\n ],\n }\n\n break\n }\n\n case 'blocks': {\n const blocksSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n }\n\n for (const block of field.blockReferences ?? field.blocks) {\n if (typeof block === 'string') {\n continue // TODO\n }\n\n let blockSchema = fieldsToSelectJSONSchema({\n config,\n fields: block.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (block.interfaceName) {\n const definition = `${block.interfaceName}_select`\n interfaceNameDefinitions.set(definition, blockSchema)\n blockSchema = {\n $ref: `#/definitions/${definition}`,\n }\n }\n\n blocksSchema.properties![block.slug] = {\n oneOf: [\n {\n type: 'boolean',\n },\n blockSchema,\n ],\n }\n }\n\n schema.properties![field.name] = {\n oneOf: [\n {\n type: 'boolean',\n },\n blocksSchema,\n ],\n }\n\n break\n }\n\n default:\n schema.properties![field.name] = {\n type: 'boolean',\n }\n break\n }\n }\n\n return schema\n}\n\nconst fieldType: JSONSchema4 = {\n type: 'string',\n required: false,\n}\nconst generateAuthFieldTypes = ({\n type,\n loginWithUsername,\n}: {\n loginWithUsername: Auth['loginWithUsername']\n type: 'forgotOrUnlock' | 'login' | 'register'\n}): JSONSchema4 => {\n if (loginWithUsername) {\n switch (type) {\n case 'forgotOrUnlock': {\n if (loginWithUsername.allowEmailLogin) {\n // allow email or username for unlock/forgot-password\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType },\n required: ['email'],\n },\n {\n additionalProperties: false,\n properties: { username: fieldType },\n required: ['username'],\n },\n ],\n }\n } else {\n // allow only username for unlock/forgot-password\n return {\n additionalProperties: false,\n properties: { username: fieldType },\n required: ['username'],\n }\n }\n }\n\n case 'login': {\n if (loginWithUsername.allowEmailLogin) {\n // allow username or email and require password for login\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType, password: fieldType },\n required: ['email', 'password'],\n },\n {\n additionalProperties: false,\n properties: { password: fieldType, username: fieldType },\n required: ['username', 'password'],\n },\n ],\n }\n } else {\n // allow only username and password for login\n return {\n additionalProperties: false,\n properties: {\n password: fieldType,\n username: fieldType,\n },\n required: ['username', 'password'],\n }\n }\n }\n\n case 'register': {\n const requiredFields: ('email' | 'password' | 'username')[] = ['password']\n const properties: {\n email?: JSONSchema4['properties']\n password?: JSONSchema4['properties']\n username?: JSONSchema4['properties']\n } = {\n password: fieldType,\n username: fieldType,\n }\n\n if (loginWithUsername.requireEmail) {\n requiredFields.push('email')\n }\n if (loginWithUsername.requireUsername) {\n requiredFields.push('username')\n }\n if (loginWithUsername.requireEmail || loginWithUsername.allowEmailLogin) {\n properties.email = fieldType\n }\n\n return {\n additionalProperties: false,\n properties,\n required: requiredFields,\n }\n }\n }\n }\n\n // default email (and password for login/register)\n return {\n additionalProperties: false,\n properties: { email: fieldType, password: fieldType },\n required: ['email', 'password'],\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const loginWithUsername = config.auth?.loginWithUsername\n const loginUserFields: JSONSchema4 = generateAuthFieldTypes({ type: 'login', loginWithUsername })\n const forgotOrUnlockUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'forgotOrUnlock',\n loginWithUsername,\n })\n const registerUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'register',\n loginWithUsername,\n })\n\n const properties: JSONSchema4['properties'] = {\n forgotPassword: forgotOrUnlockUserFields,\n login: loginUserFields,\n registerFirstUser: registerUserFields,\n unlock: forgotOrUnlockUserFields,\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${formatNames(config.slug).singular}AuthOperations`,\n }\n}\n\n// Generates the JSON Schema for supported timezones\nexport function timezonesToJSONSchema(\n supportedTimezones: SanitizedConfig['admin']['timezones']['supportedTimezones'],\n): JSONSchema4 {\n return {\n description: 'Supported timezones in IANA format.',\n enum: supportedTimezones.map((timezone) =>\n typeof timezone === 'string' ? timezone : timezone.value,\n ),\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce(\n (acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n i18n?: I18n,\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({\n config,\n defaultIDType: defaultIDType!,\n })\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n\n const entities: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n type: 'collection' | 'global'\n }[] = [\n ...config.globals.map((global) => ({ type: 'global' as const, entity: global })),\n ...config.collections.map((collection) => ({\n type: 'collection' as const,\n entity: collection,\n })),\n ]\n\n const entityDefinitions: { [k: string]: JSONSchema4 } = entities.reduce(\n (acc, { type, entity }) => {\n acc[entity.slug] = entityToJSONSchema(\n config,\n entity,\n interfaceNameDefinitions,\n defaultIDType!,\n collectionIDFieldTypes,\n i18n,\n )\n const select = fieldsToSelectJSONSchema({\n config,\n fields: entity.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (type === 'global') {\n select.properties!.globalType = {\n type: 'boolean',\n }\n }\n\n acc[`${entity.slug}_select`] = {\n type: 'object',\n additionalProperties: false,\n ...select,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n const timezoneDefinitions = timezonesToJSONSchema(config.admin.timezones.supportedTimezones)\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} as Record<string, JSONSchema4> },\n )\n\n const jobsSchemas = config.jobs\n ? generateJobsJSONSchemas(\n config,\n config.jobs,\n interfaceNameDefinitions,\n collectionIDFieldTypes,\n i18n,\n )\n : {}\n\n const blocksDefinition: JSONSchema4 | undefined = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n required: [],\n }\n if (config?.blocks?.length) {\n for (const block of config.blocks) {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n )\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 fallbackLocale: generateFallbackLocaleEntitySchemas(config.localization),\n globals: generateEntitySchemas(config.globals || []),\n globalsSelect: generateEntitySelectSchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n ...(config.typescript?.strictDraftTypes\n ? {\n strictDraftTypes: {\n type: 'boolean',\n const: true,\n },\n }\n : {}),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: [\n 'user',\n 'locale',\n 'fallbackLocale',\n 'collections',\n 'collectionsSelect',\n 'collectionsJoins',\n 'globalsSelect',\n ...(config.typescript?.strictDraftTypes ? ['strictDraftTypes'] : []),\n 'globals',\n 'auth',\n 'db',\n 'jobs',\n 'blocks',\n ],\n title: 'Config',\n }\n\n if (jobsSchemas.definitions?.size) {\n for (const [key, value] of jobsSchemas.definitions) {\n jsonSchema.definitions![key] = value\n }\n }\n if (jobsSchemas.properties) {\n jsonSchema.properties!.jobs = {\n type: 'object',\n additionalProperties: false,\n properties: jobsSchemas.properties,\n required: ['tasks', 'workflows'],\n }\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ collectionIDFieldTypes, config, i18n: i18n!, jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["MissingEditorProp","fieldAffectsData","generateJobsJSONSchemas","formatNames","getCollectionIDFieldTypes","optionsAreEqual","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","flattenedFields","some","subField","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateEntitySelectSchemas","generateCollectionJoinsSchemas","collections","joins","polymorphicJoins","schema","collectionSlug","join","joinPath","enum","push","collection","length","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","generateFallbackLocaleEntitySchemas","localeCodes","localeCode","oneOf","items","generateAuthEntitySchemas","filter","auth","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","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","hasMatchingGlobalTimezones","timezones","supportedTimezones","typescriptSchema","add","Map","from","entityToJSONSchema","title","typescript","interface","singular","mutableFields","idField","customIdField","unshift","timestamps","disableLocalStrategy","enableFields","isAuthCollection","fieldsSchema","entityDescription","fieldsToSelectJSONSchema","definition","blocksSchema","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","username","password","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","timezonesToJSONSchema","generateAuthOperationSchemas","configToJSONSchema","globals","global","entityDefinitions","select","globalType","timezoneDefinitions","authOperationDefinitions","authCollection","jobsSchemas","jobs","blocksDefinition","definitions","collectionsJoins","collectionsSelect","fallbackLocale","globalsSelect","strictDraftTypes","user","size","key"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,WAAW,QAAQ,oB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
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { FieldAffectingData, FlattenedField, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { generateJobsJSONSchemas } from '../queues/config/generateJobsJSONSchemas.js'\nimport { flattenAllFields } from './flattenAllFields.js'\nimport { formatNames } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\nimport { optionsAreEqual } from './optionsAreEqual.js'\n\nconst fieldIsRequired = (field: FlattenedField): boolean => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) {\n return false\n }\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) {\n return true\n }\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.flattenedFields.some((subField) => fieldIsRequired(subField))\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce(\n (acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateEntitySelectSchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce(\n (acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}_select`,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateCollectionJoinsSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = [...collections].reduce<Record<string, JSONSchema4>>(\n (acc, { slug, joins, polymorphicJoins }) => {\n const schema = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n required: [] as string[],\n } satisfies JSONSchema4\n\n for (const collectionSlug in joins) {\n for (const join of joins[collectionSlug]!) {\n ;(schema.properties as any)[join.joinPath] = {\n type: 'string',\n enum: [collectionSlug],\n }\n schema.required.push(join.joinPath)\n }\n }\n\n for (const join of polymorphicJoins) {\n ;(schema.properties as any)[join.joinPath] = {\n type: 'string',\n enum: join.field.collection,\n }\n schema.required.push(join.joinPath)\n }\n\n if (Object.keys(schema.properties).length > 0) {\n acc[slug] = schema\n }\n\n return acc\n },\n {},\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nconst widgetWidths = ['x-small', 'small', 'medium', 'large', 'x-large', 'full'] as const\n\nfunction getAllowedWidgetWidths({\n maxWidth,\n minWidth,\n}: {\n maxWidth?: (typeof widgetWidths)[number]\n minWidth?: (typeof widgetWidths)[number]\n}): string[] {\n const minIndex = minWidth ? widgetWidths.indexOf(minWidth) : 0\n const maxIndex = maxWidth ? widgetWidths.indexOf(maxWidth) : widgetWidths.length - 1\n\n if (minIndex === -1 || maxIndex === -1 || minIndex > maxIndex) {\n return [...widgetWidths]\n }\n\n return widgetWidths.slice(minIndex, maxIndex + 1)\n}\n\nfunction generateWidgetSchemas({\n collectionIDFieldTypes,\n config,\n i18n,\n interfaceNameDefinitions,\n}: {\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' }\n config: SanitizedConfig\n i18n?: I18n\n interfaceNameDefinitions: Map<string, JSONSchema4>\n}): {\n definitions: Record<string, JSONSchema4>\n schema: JSONSchema4\n} {\n const widgets = config.admin?.dashboard?.widgets ?? []\n const definitions: Record<string, JSONSchema4> = {}\n const properties: Record<string, JSONSchema4> = {}\n\n for (const widget of widgets) {\n const definition = `${widget.slug}_widget`\n const widthEnum = getAllowedWidgetWidths({\n maxWidth: widget.maxWidth,\n minWidth: widget.minWidth,\n })\n let dataSchema: JSONSchema4\n\n if (widget.fields?.length) {\n const widgetFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n flattenAllFields({ fields: widget.fields }),\n interfaceNameDefinitions,\n config,\n i18n,\n )\n\n dataSchema = {\n type: 'object',\n additionalProperties: false,\n ...widgetFieldSchemas,\n }\n } else {\n dataSchema = {\n type: 'object',\n additionalProperties: true,\n }\n }\n\n definitions[definition] = {\n type: 'object',\n additionalProperties: false,\n properties: {\n data: dataSchema,\n width: {\n type: 'string',\n enum: widthEnum,\n },\n },\n required: ['width'],\n }\n\n properties[widget.slug] = {\n $ref: `#/definitions/${definition}`,\n }\n }\n\n return {\n definitions,\n schema: {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n },\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateFallbackLocaleEntitySchemas(\n localization: SanitizedConfig['localization'],\n): JSONSchema4 {\n if (localization && 'localeCodes' in localization && localization?.localeCodes) {\n const localeCodes = [...localization.localeCodes].map((localeCode) => {\n return localeCode\n }, [])\n\n return {\n oneOf: [\n { type: 'string', enum: ['false', 'none', 'null'] },\n { type: 'boolean', enum: [false] },\n { type: 'null' },\n { type: 'string', enum: localeCodes },\n { type: 'array', items: { type: 'string', enum: localeCodes } },\n ],\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return { $ref: `#/definitions/${slug}` }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n const defaultIDType: JSONSchema4 =\n config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n defaultIDType,\n },\n required: ['defaultIDType'],\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) {\n return fieldType\n }\n fieldTypes.push('null')\n return fieldTypes\n}\n\nfunction entityOrFieldToJsDocs({\n entity,\n i18n,\n}: {\n entity: FlattenedField | SanitizedCollectionConfig | SanitizedGlobalConfig\n i18n?: I18n\n}): string | undefined {\n let description: string | undefined = undefined\n if (entity?.admin?.description) {\n if (typeof entity?.admin?.description === 'string') {\n description = entity?.admin?.description\n } else if (typeof entity?.admin?.description === 'object') {\n if (entity?.admin?.description?.en) {\n description = entity?.admin?.description?.en\n } else if (entity?.admin?.description?.[i18n!.language]) {\n description = entity?.admin?.description?.[i18n!.language]\n }\n } else if (typeof entity?.admin?.description === 'function' && i18n) {\n // do not evaluate description functions for generating JSDocs. The output of\n // those can differ depending on where and when they are called, creating\n // inconsistencies in the generated JSDocs.\n }\n }\n return description\n}\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 if (!resolvedBlock) {\n return {}\n }\n\n const resolvedBlockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n resolvedBlock.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n )\n\n const resolvedBlockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...resolvedBlockFieldSchemas.properties,\n blockType: {\n const: resolvedBlock.slug,\n },\n },\n required: ['blockType', ...resolvedBlockFieldSchemas.required],\n }\n\n if (resolvedBlock.interfaceName) {\n interfaceNameDefinitions.set(\n resolvedBlock.interfaceName,\n resolvedBlockSchema,\n )\n }\n\n return resolvedBlockSchema\n }\n\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\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 return blockSchema\n }\n\n return blockSchema\n }),\n }\n : {},\n }\n break\n }\n case 'checkbox': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('boolean', isRequired),\n }\n break\n }\n case 'code':\n case 'date':\n case 'email':\n case 'textarea': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n }\n break\n }\n\n case 'group': {\n if (fieldAffectsData(field)) {\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n }\n }\n break\n }\n\n case 'join': {\n let items: JSONSchema4\n\n if (Array.isArray(field.collection)) {\n items = {\n oneOf: field.collection.map((collection) => ({\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: collection,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[collection],\n },\n {\n $ref: `#/definitions/${collection}`,\n },\n ],\n },\n },\n required: ['collectionSlug', 'value'],\n })),\n }\n } else {\n items = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.collection],\n },\n {\n $ref: `#/definitions/${field.collection}`,\n },\n ],\n }\n }\n\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n properties: {\n docs: {\n type: 'array',\n items,\n },\n hasNextPage: { type: 'boolean' },\n totalDocs: { type: 'number' },\n },\n }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n ...baseFieldSchema,\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('number', isRequired),\n }\n }\n break\n }\n\n case 'point': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'radio': {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n\n break\n }\n case 'relationship':\n case 'upload': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo]!,\n isRequired,\n ),\n },\n { $ref: `#/definitions/${field.relationTo}` },\n ],\n }\n }\n\n break\n }\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = {\n ...baseFieldSchema,\n ...field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n i18n,\n interfaceNameDefinitions,\n isRequired,\n }),\n }\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n // We get the previous field to check for a date in the case of a timezone select\n // This works because timezone selects are always inserted right after a date with 'timezone: true'\n const previousField = fields?.[index - 1]\n const isTimezoneField =\n previousField?.type === 'date' && previousField.timezone && field.name.includes('_tz')\n\n // Check if the timezone field's options match the global config's supported timezones\n const hasMatchingGlobalTimezones =\n isTimezoneField &&\n config &&\n optionsAreEqual(field.options, config.admin?.timezones?.supportedTimezones)\n\n // Timezone selects should reference the supportedTimezones definition\n // only if the field's options match the global config\n if (isTimezoneField && hasMatchingGlobalTimezones) {\n fieldSchema = {\n $ref: `#/definitions/supportedTimezones`,\n }\n } else {\n if (field.hasMany) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n },\n }\n if (optionEnums?.length) {\n ;(fieldSchema.items as JSONSchema4).enum = optionEnums\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n }\n if (optionEnums?.length) {\n fieldSchema.enum = optionEnums\n }\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n break\n }\n case 'tab': {\n fieldSchema = {\n ...baseFieldSchema,\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = { $ref: `#/definitions/${field.interfaceName}` }\n }\n break\n }\n\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = {\n ...baseFieldSchema,\n type: withNullableJSONSchemaType('string', isRequired),\n }\n }\n break\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema! })\n }\n }\n\n if (fieldSchema! && fieldAffectsData(field)) {\n if (isRequired && fieldSchema.required !== false) {\n requiredFieldNames.add(field.name)\n }\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n collectionIDFieldTypes?: { [key: string]: 'number' | 'string' },\n i18n?: I18n,\n): JSONSchema4 {\n if (!collectionIDFieldTypes) {\n collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n }\n\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : formatNames(entity.slug).singular\n\n let mutableFields = [...entity.flattenedFields]\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = mutableFields.find((field) => field.name === 'id') as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n mutableFields = mutableFields.map((field) => {\n if (field === customIdField) {\n return { ...field, required: true }\n }\n\n return field\n })\n } else {\n mutableFields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n mutableFields = mutableFields.map((field) => {\n if (field.name === 'createdAt' || field.name === 'updatedAt') {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if (\n 'auth' in entity &&\n entity.auth &&\n (!entity.auth?.disableLocalStrategy ||\n (typeof entity.auth?.disableLocalStrategy === 'object' &&\n entity.auth.disableLocalStrategy.enableFields))\n ) {\n mutableFields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n const isAuthCollection = 'auth' in entity && entity.auth\n\n const fieldsSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n mutableFields,\n interfaceNameDefinitions,\n config,\n i18n,\n )\n\n // Add collection property to auth collections\n if (isAuthCollection) {\n fieldsSchema.properties = {\n ...fieldsSchema.properties,\n collection: { type: 'string', enum: [entity.slug] },\n }\n fieldsSchema.required = [...(fieldsSchema.required || []), 'collection']\n }\n\n const jsonSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsSchema,\n }\n\n const entityDescription = entityOrFieldToJsDocs({ entity, i18n })\n\n if (entityDescription) {\n jsonSchema.description = entityDescription\n }\n\n return jsonSchema\n}\n\nexport function fieldsToSelectJSONSchema({\n config,\n fields,\n interfaceNameDefinitions,\n}: {\n config: SanitizedConfig\n fields: FlattenedField[]\n interfaceNameDefinitions: Map<string, JSONSchema4>\n}): JSONSchema4 {\n const schema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n }\n\n for (const field of fields) {\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n let fieldSchema: JSONSchema4 = fieldsToSelectJSONSchema({\n config,\n fields: field.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (field.interfaceName) {\n const definition = `${field.interfaceName}_select`\n interfaceNameDefinitions.set(definition, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${definition}`,\n }\n }\n\n schema.properties![field.name] = {\n oneOf: [\n {\n type: 'boolean',\n },\n fieldSchema,\n ],\n }\n\n break\n }\n\n case 'blocks': {\n const blocksSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n }\n\n for (const block of field.blockReferences ?? field.blocks) {\n if (typeof block === 'string') {\n continue // TODO\n }\n\n let blockSchema = fieldsToSelectJSONSchema({\n config,\n fields: block.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (block.interfaceName) {\n const definition = `${block.interfaceName}_select`\n interfaceNameDefinitions.set(definition, blockSchema)\n blockSchema = {\n $ref: `#/definitions/${definition}`,\n }\n }\n\n blocksSchema.properties![block.slug] = {\n oneOf: [\n {\n type: 'boolean',\n },\n blockSchema,\n ],\n }\n }\n\n schema.properties![field.name] = {\n oneOf: [\n {\n type: 'boolean',\n },\n blocksSchema,\n ],\n }\n\n break\n }\n\n default:\n schema.properties![field.name] = {\n type: 'boolean',\n }\n break\n }\n }\n\n return schema\n}\n\nconst fieldType: JSONSchema4 = {\n type: 'string',\n required: false,\n}\nconst generateAuthFieldTypes = ({\n type,\n loginWithUsername,\n}: {\n loginWithUsername: Auth['loginWithUsername']\n type: 'forgotOrUnlock' | 'login' | 'register'\n}): JSONSchema4 => {\n if (loginWithUsername) {\n switch (type) {\n case 'forgotOrUnlock': {\n if (loginWithUsername.allowEmailLogin) {\n // allow email or username for unlock/forgot-password\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType },\n required: ['email'],\n },\n {\n additionalProperties: false,\n properties: { username: fieldType },\n required: ['username'],\n },\n ],\n }\n } else {\n // allow only username for unlock/forgot-password\n return {\n additionalProperties: false,\n properties: { username: fieldType },\n required: ['username'],\n }\n }\n }\n\n case 'login': {\n if (loginWithUsername.allowEmailLogin) {\n // allow username or email and require password for login\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType, password: fieldType },\n required: ['email', 'password'],\n },\n {\n additionalProperties: false,\n properties: { password: fieldType, username: fieldType },\n required: ['username', 'password'],\n },\n ],\n }\n } else {\n // allow only username and password for login\n return {\n additionalProperties: false,\n properties: {\n password: fieldType,\n username: fieldType,\n },\n required: ['username', 'password'],\n }\n }\n }\n\n case 'register': {\n const requiredFields: ('email' | 'password' | 'username')[] = ['password']\n const properties: {\n email?: JSONSchema4['properties']\n password?: JSONSchema4['properties']\n username?: JSONSchema4['properties']\n } = {\n password: fieldType,\n username: fieldType,\n }\n\n if (loginWithUsername.requireEmail) {\n requiredFields.push('email')\n }\n if (loginWithUsername.requireUsername) {\n requiredFields.push('username')\n }\n if (loginWithUsername.requireEmail || loginWithUsername.allowEmailLogin) {\n properties.email = fieldType\n }\n\n return {\n additionalProperties: false,\n properties,\n required: requiredFields,\n }\n }\n }\n }\n\n // default email (and password for login/register)\n return {\n additionalProperties: false,\n properties: { email: fieldType, password: fieldType },\n required: ['email', 'password'],\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const loginWithUsername = config.auth?.loginWithUsername\n const loginUserFields: JSONSchema4 = generateAuthFieldTypes({ type: 'login', loginWithUsername })\n const forgotOrUnlockUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'forgotOrUnlock',\n loginWithUsername,\n })\n const registerUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'register',\n loginWithUsername,\n })\n\n const properties: JSONSchema4['properties'] = {\n forgotPassword: forgotOrUnlockUserFields,\n login: loginUserFields,\n registerFirstUser: registerUserFields,\n unlock: forgotOrUnlockUserFields,\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${formatNames(config.slug).singular}AuthOperations`,\n }\n}\n\n// Generates the JSON Schema for supported timezones\nexport function timezonesToJSONSchema(\n supportedTimezones: SanitizedConfig['admin']['timezones']['supportedTimezones'],\n): JSONSchema4 {\n return {\n description: 'Supported timezones in IANA format.',\n enum: supportedTimezones.map((timezone) =>\n typeof timezone === 'string' ? timezone : timezone.value,\n ),\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce(\n (acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n i18n?: I18n,\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({\n config,\n defaultIDType: defaultIDType!,\n })\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n\n const entities: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n type: 'collection' | 'global'\n }[] = [\n ...config.globals.map((global) => ({ type: 'global' as const, entity: global })),\n ...config.collections.map((collection) => ({\n type: 'collection' as const,\n entity: collection,\n })),\n ]\n\n const entityDefinitions: { [k: string]: JSONSchema4 } = entities.reduce(\n (acc, { type, entity }) => {\n acc[entity.slug] = entityToJSONSchema(\n config,\n entity,\n interfaceNameDefinitions,\n defaultIDType!,\n collectionIDFieldTypes,\n i18n,\n )\n const select = fieldsToSelectJSONSchema({\n config,\n fields: entity.flattenedFields,\n interfaceNameDefinitions,\n })\n\n if (type === 'global') {\n select.properties!.globalType = {\n type: 'boolean',\n }\n }\n\n acc[`${entity.slug}_select`] = {\n type: 'object',\n additionalProperties: false,\n ...select,\n }\n\n return acc\n },\n {} as Record<string, JSONSchema4>,\n )\n\n const timezoneDefinitions = timezonesToJSONSchema(config.admin.timezones.supportedTimezones)\n const widgetSchemas = generateWidgetSchemas({\n collectionIDFieldTypes,\n config,\n i18n,\n interfaceNameDefinitions,\n })\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} as Record<string, JSONSchema4> },\n )\n\n const jobsSchemas = config.jobs\n ? generateJobsJSONSchemas(\n config,\n config.jobs,\n interfaceNameDefinitions,\n collectionIDFieldTypes,\n i18n,\n )\n : {}\n\n const blocksDefinition: JSONSchema4 | undefined = {\n type: 'object',\n additionalProperties: false,\n properties: {},\n required: [],\n }\n if (config?.blocks?.length) {\n for (const block of config.blocks) {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.flattenedFields,\n interfaceNameDefinitions,\n config,\n i18n,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n const interfaceName = block.interfaceName ?? block.slug\n interfaceNameDefinitions.set(interfaceName, blockSchema)\n\n blocksDefinition.properties![block.slug] = {\n $ref: `#/definitions/${interfaceName}`,\n }\n ;(blocksDefinition.required as string[]).push(block.slug)\n }\n }\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n supportedTimezones: timezoneDefinitions,\n ...entityDefinitions,\n ...widgetSchemas.definitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n blocks: blocksDefinition,\n collections: generateEntitySchemas(config.collections || []),\n collectionsJoins: generateCollectionJoinsSchemas(config.collections || []),\n collectionsSelect: generateEntitySelectSchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n fallbackLocale: generateFallbackLocaleEntitySchemas(config.localization),\n globals: generateEntitySchemas(config.globals || []),\n globalsSelect: generateEntitySelectSchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n widgets: widgetSchemas.schema,\n ...(config.typescript?.strictDraftTypes\n ? {\n strictDraftTypes: {\n type: 'boolean',\n const: true,\n },\n }\n : {}),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: [\n 'user',\n 'locale',\n 'fallbackLocale',\n 'collections',\n 'collectionsSelect',\n 'collectionsJoins',\n 'globalsSelect',\n ...(config.typescript?.strictDraftTypes ? ['strictDraftTypes'] : []),\n 'globals',\n 'auth',\n 'db',\n 'jobs',\n 'blocks',\n 'widgets',\n ],\n title: 'Config',\n }\n\n if (jobsSchemas.definitions?.size) {\n for (const [key, value] of jobsSchemas.definitions) {\n jsonSchema.definitions![key] = value\n }\n }\n if (jobsSchemas.properties) {\n jsonSchema.properties!.jobs = {\n type: 'object',\n additionalProperties: false,\n properties: jobsSchemas.properties,\n required: ['tasks', 'workflows'],\n }\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ collectionIDFieldTypes, config, i18n: i18n!, jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["MissingEditorProp","fieldAffectsData","generateJobsJSONSchemas","flattenAllFields","formatNames","getCollectionIDFieldTypes","optionsAreEqual","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","flattenedFields","some","subField","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateEntitySelectSchemas","generateCollectionJoinsSchemas","collections","joins","polymorphicJoins","schema","collectionSlug","join","joinPath","enum","push","collection","length","widgetWidths","getAllowedWidgetWidths","maxWidth","minWidth","minIndex","indexOf","maxIndex","slice","generateWidgetSchemas","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","widgets","dashboard","definitions","widget","definition","widthEnum","dataSchema","fields","widgetFieldSchemas","fieldsToJSONSchema","data","width","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","generateFallbackLocaleEntitySchemas","localeCodes","localeCode","oneOf","items","generateAuthEntitySchemas","filter","auth","generateDbEntitySchema","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","entityOrFieldToJsDocs","entity","description","undefined","en","language","requiredFieldNames","Set","fromEntries","fieldSchemas","index","fieldDescription","baseFieldSchema","fieldSchema","interfaceName","set","hasBlocks","blockReferences","blocks","block","resolvedBlock","find","b","resolvedBlockFieldSchemas","resolvedBlockSchema","blockType","const","blockFieldSchemas","blockSchema","Array","isArray","relationTo","docs","hasNextPage","totalDocs","jsonSchema","hasMany","maxItems","minItems","relation","editor","Error","outputSchema","optionEnums","previousField","isTimezoneField","timezone","name","includes","hasMatchingGlobalTimezones","timezones","supportedTimezones","typescriptSchema","add","Map","from","entityToJSONSchema","title","typescript","interface","singular","mutableFields","idField","customIdField","unshift","timestamps","disableLocalStrategy","enableFields","isAuthCollection","fieldsSchema","entityDescription","fieldsToSelectJSONSchema","blocksSchema","generateAuthFieldTypes","loginWithUsername","allowEmailLogin","email","username","password","requiredFields","requireEmail","requireUsername","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","timezonesToJSONSchema","generateAuthOperationSchemas","configToJSONSchema","globals","global","entityDefinitions","select","globalType","timezoneDefinitions","widgetSchemas","authOperationDefinitions","authCollection","jobsSchemas","jobs","blocksDefinition","collectionsJoins","collectionsSelect","fallbackLocale","globalsSelect","strictDraftTypes","user","size","key"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe;QACjB,OAAO;IACT;IAEA,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIb,iBAAiBO,UAAUK,kBAAkB;QAC/C,OAAO;IACT;IAEA,wDAAwD;IACxD,IAAI,YAAYL,SAASA,MAAMO,IAAI,KAAK,SAAS;QAC/C,OAAOP,MAAMQ,eAAe,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;IAClE;IAEA,OAAO;AACT;AAEA,SAASC,iBAAiBC,OAA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YAAYzK,UAAU;YAClCZ,UAAU;gBAAC;gBAAS;aAAY;QAClC;IACF;IAEA,IAAI2C,QAAQ8F,YAAYhH,QAAQO,QAAQ;QACtC,KAAK,MAAMP,UAAUkB,OAAO8F,UAAU,CAAChH,MAAM,CAAE;YAC7CyF,aAAazF,OAAO;gBAAEiB;gBAAwBC;gBAAQC,MAAMA;gBAAOsE;YAAW;QAChF;IACF;IAEA,OAAOA;AACT"}
|
|
@@ -423,6 +423,39 @@ describe('configToJSONSchema', ()=>{
|
|
|
423
423
|
expect(typeof sanitizedConfig?.blocks?.[0]?.fields?.[0]?.editor).toBe('object');
|
|
424
424
|
expect(typeof sanitizedConfig.collections[0].fields[0]?.blocks?.[0]?.fields?.[0]?.editor).toBe('object');
|
|
425
425
|
const schema = configToJSONSchema(sanitizedConfig, 'text');
|
|
426
|
+
const expectedBlockSchema = {
|
|
427
|
+
type: 'object',
|
|
428
|
+
additionalProperties: false,
|
|
429
|
+
properties: {
|
|
430
|
+
id: {
|
|
431
|
+
type: [
|
|
432
|
+
'string',
|
|
433
|
+
'null'
|
|
434
|
+
]
|
|
435
|
+
},
|
|
436
|
+
blockName: {
|
|
437
|
+
type: [
|
|
438
|
+
'string',
|
|
439
|
+
'null'
|
|
440
|
+
]
|
|
441
|
+
},
|
|
442
|
+
blockType: {
|
|
443
|
+
const: 'sharedBlock'
|
|
444
|
+
},
|
|
445
|
+
richText: {
|
|
446
|
+
type: [
|
|
447
|
+
'array',
|
|
448
|
+
'null'
|
|
449
|
+
],
|
|
450
|
+
items: {
|
|
451
|
+
type: 'object'
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
required: [
|
|
456
|
+
'blockType'
|
|
457
|
+
]
|
|
458
|
+
};
|
|
426
459
|
expect(schema?.definitions?.test).toStrictEqual({
|
|
427
460
|
type: 'object',
|
|
428
461
|
additionalProperties: false,
|
|
@@ -438,9 +471,7 @@ describe('configToJSONSchema', ()=>{
|
|
|
438
471
|
],
|
|
439
472
|
items: {
|
|
440
473
|
oneOf: [
|
|
441
|
-
|
|
442
|
-
$ref: '#/definitions/SharedBlock'
|
|
443
|
-
}
|
|
474
|
+
expectedBlockSchema
|
|
444
475
|
]
|
|
445
476
|
}
|
|
446
477
|
}
|
|
@@ -449,7 +480,8 @@ describe('configToJSONSchema', ()=>{
|
|
|
449
480
|
'id'
|
|
450
481
|
]
|
|
451
482
|
});
|
|
452
|
-
|
|
483
|
+
// The definition should still be registered for TypeScript type generation
|
|
484
|
+
expect(schema?.definitions?.SharedBlock).toStrictEqual(expectedBlockSchema);
|
|
453
485
|
});
|
|
454
486
|
it('should allow overriding required to false', async ()=>{
|
|
455
487
|
// @ts-expect-error
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport { describe, it, expect } from 'vitest'\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":["describe","it","expect","sanitizeConfig","configToJSONSchema","config","collections","slug","fields","name","type","required","timestamps","sanitizedConfig","schema","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":"AACA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAI7C,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAG5DJ,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMI,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,MAAMV,eAAeE;QAC7C,MAAMS,SAASV,mBAAmBS,iBAAiB;QAEnDX,OAAOY,QAAQC,aAAaC,MAAMC,aAAa,CAAC;YAC9CP,MAAM;YACNQ,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFV,MAAM;gBACR;gBACAW,mBAAmB;oBACjBX,MAAM;wBAAC;wBAAS;qBAAO;oBACvBY,OAAO;wBACLZ,MAAM;wBACNQ,sBAAsB;wBACtBC,YAAY;4BACVC,IAAI;gCACFV,MAAM;oCAAC;oCAAU;iCAAO;4BAC1B;4BACAW,mBAAmB;gCACjBX,MAAM;4BACR;wBACF;wBACAC,UAAU;4BAAC;yBAAoB;oBAC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BACEC,MAAM;4BACNC,MAAM;4BACNC,UAAU;4BACV+C,cAAc;4BACdjB,kBAAkB;gCAChB,IAAO,CAAA;wCACL/B,MAAM;wCACNC,UAAU;oCACZ,CAAA;6BACD;wBACH;qBACD;oBACDC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMV,eAAeE;QAC7C,MAAMS,SAASV,mBAAmBS,iBAAiB;QAEnD,mBAAmB;QACnBX,OAAOY,OAAOC,WAAW,CAACC,IAAI,CAACG,UAAU,CAACI,KAAK,CAACZ,QAAQ,EAAEM,aAAa,CAAC;IAC1E;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport { describe, it, expect } from 'vitest'\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 const expectedBlockSchema = {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: { type: ['string', 'null'] },\n blockName: { type: ['string', 'null'] },\n blockType: { const: 'sharedBlock' },\n richText: { type: ['array', 'null'], items: { type: 'object' } },\n },\n required: ['blockType'],\n }\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: [expectedBlockSchema],\n },\n },\n },\n required: ['id'],\n })\n\n // The definition should still be registered for TypeScript type generation\n expect(schema?.definitions?.SharedBlock).toStrictEqual(expectedBlockSchema)\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":["describe","it","expect","sanitizeConfig","configToJSONSchema","config","collections","slug","fields","name","type","required","timestamps","sanitizedConfig","schema","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","expectedBlockSchema","richText","someBlockField","SharedBlock","defaultValue"],"mappings":"AACA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAI7C,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAG5DJ,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMI,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,MAAMV,eAAeE;QAC7C,MAAMS,SAASV,mBAAmBS,iBAAiB;QAEnDX,OAAOY,QAAQC,aAAaC,MAAMC,aAAa,CAAC;YAC9CP,MAAM;YACNQ,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFV,MAAM;gBACR;gBACAW,mBAAmB;oBACjBX,MAAM;wBAAC;wBAAS;qBAAO;oBACvBY,OAAO;wBACLZ,MAAM;wBACNQ,sBAAsB;wBACtBC,YAAY;4BACVC,IAAI;gCACFV,MAAM;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;QAEAT,OAAOY,QAAQC,aAAaC,MAAMC,aAAa,CAAC;YAC9CP,MAAM;YACNQ,sBAAsB;YACtBK,OAAO;YACPJ,YAAY;gBACVC,IAAI;oBACFV,MAAM;gBACR;gBACA8C,gBAAgB;oBACd9C,MAAM;wBAAC;wBAAS;qBAAO;oBACvBY,OAAO;wBACLM,OAAO;4BAAC0B;yBAAoB;oBAC9B;gBACF;YACF;YACA3C,UAAU;gBAAC;aAAK;QAClB;QAEA,2EAA2E;QAC3ET,OAAOY,QAAQC,aAAa0C,aAAaxC,aAAa,CAACqC;IACzD;IAEArD,GAAG,6CAA6C;QAC9C,mBAAmB;QACnB,MAAMI,SAAiB;YACrBC,aAAa;gBACX;oBACEC,MAAM;oBACNC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNC,UAAU;4BACV+C,cAAc;4BACdjB,kBAAkB;gCAChB,IAAO,CAAA;wCACL/B,MAAM;wCACNC,UAAU;oCACZ,CAAA;6BACD;wBACH;qBACD;oBACDC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMV,eAAeE;QAC7C,MAAMS,SAASV,mBAAmBS,iBAAiB;QAEnD,mBAAmB;QACnBX,OAAOY,OAAOC,WAAW,CAACC,IAAI,CAACG,UAAU,CAACI,KAAK,CAACZ,QAAQ,EAAEM,aAAa,CAAC;IAC1E;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterDataToSelectedLocales.d.ts","sourceRoot":"","sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,KAAK,EAAkB,MAAM,2BAA2B,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD,KAAK,+BAA+B,GAAG;IACrC,qBAAqB,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;IAChD,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,iBAAyB,EACzB,eAAe,GAChB,EAAE,+BAA+B,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"filterDataToSelectedLocales.d.ts","sourceRoot":"","sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,KAAK,EAAkB,MAAM,2BAA2B,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD,KAAK,+BAA+B,GAAG;IACrC,qBAAqB,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;IAChD,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,iBAAyB,EACzB,eAAe,GAChB,EAAE,+BAA+B,GAAG,UAAU,CA8K9C"}
|
|
@@ -46,13 +46,19 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
46
46
|
block = field.blocks.find((b)=>b.slug === blockData.blockType);
|
|
47
47
|
}
|
|
48
48
|
if (block) {
|
|
49
|
-
|
|
49
|
+
const filtered = filterDataToSelectedLocales({
|
|
50
50
|
configBlockReferences,
|
|
51
51
|
docWithLocales: blockData,
|
|
52
52
|
fields: block?.fields || [],
|
|
53
53
|
parentIsLocalized: fieldIsLocalized,
|
|
54
54
|
selectedLocales
|
|
55
55
|
});
|
|
56
|
+
// blockType, id, blockName are set by Payload internally
|
|
57
|
+
// and not part of block.fields, so they must be preserved explicitly
|
|
58
|
+
filtered.blockType = blockData.blockType;
|
|
59
|
+
filtered.id = blockData.id;
|
|
60
|
+
filtered.blockName = blockData.blockName;
|
|
61
|
+
return filtered;
|
|
56
62
|
}
|
|
57
63
|
return blockData;
|
|
58
64
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"sourcesContent":["import type { Block, Field, FlattenedBlock } from '../fields/config/types.js'\nimport type { SanitizedConfig } from '../index.js'\nimport type { JsonObject } from '../types/index.js'\n\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js'\n\ntype FilterDataToSelectedLocalesArgs = {\n configBlockReferences: SanitizedConfig['blocks']\n docWithLocales: JsonObject\n fields: Field[]\n parentIsLocalized?: boolean\n selectedLocales: string[]\n}\n\n/**\n * Filters localized field data to only include specified locales.\n * For non-localized fields, returns all data as-is.\n * For localized fields, if selectedLocales is provided, returns only those locales.\n * If selectedLocales is not provided and field is localized, returns all locales.\n */\nexport function filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields,\n parentIsLocalized = false,\n selectedLocales,\n}: FilterDataToSelectedLocalesArgs): JsonObject {\n if (!docWithLocales || typeof docWithLocales !== 'object') {\n return docWithLocales\n }\n\n const result: JsonObject = {}\n\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n const fieldIsLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n switch (field.type) {\n case 'array': {\n if (Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((item: JsonObject) =>\n filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: item,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n }),\n )\n }\n break\n }\n\n case 'blocks': {\n if (field.name in docWithLocales && Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((blockData: JsonObject) => {\n let block: Block | FlattenedBlock | undefined\n if (configBlockReferences && field.blockReferences) {\n for (const blockOrReference of field.blockReferences) {\n if (typeof blockOrReference === 'string') {\n block = configBlockReferences.find((b) => b.slug === blockData.blockType)\n } else {\n block = blockOrReference\n }\n }\n } else if (field.blocks) {\n block = field.blocks.find((b) => b.slug === blockData.blockType)\n }\n\n if (block) {\n return filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: blockData,\n fields: block?.fields || [],\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n }\n\n return blockData\n })\n }\n break\n }\n\n case 'group': {\n // Named groups create a nested data structure\n if (\n fieldAffectsData(field) &&\n field.name in docWithLocales &&\n typeof docWithLocales[field.name] === 'object'\n ) {\n result[field.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[field.name] as JsonObject,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n } else {\n // Unnamed groups pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n break\n }\n\n default: {\n // For all other data-affecting fields (text, number, select, etc.)\n if (field.name in docWithLocales) {\n const value = docWithLocales[field.name]\n\n // If the field is localized and has locale data\n if (fieldIsLocalized && value && typeof value === 'object' && !Array.isArray(value)) {\n // If selectedLocales is provided, filter to only those locales\n if (selectedLocales && selectedLocales.length > 0) {\n const filtered: Record<string, unknown> = {}\n for (const locale of selectedLocales) {\n if (locale in value) {\n filtered[locale] = value[locale]\n }\n }\n if (Object.keys(filtered).length > 0) {\n result[field.name] = filtered\n }\n } else {\n // If no selectedLocales, include all locales\n result[field.name] = value\n }\n } else {\n // Non-localized field or non-object value\n result[field.name] = value\n }\n }\n break\n }\n }\n } else {\n // Layout-only fields that don't affect data structure\n switch (field.type) {\n case 'collapsible':\n case 'row': {\n // These pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n // Named tabs create a nested data structure\n if (tab.name in docWithLocales && typeof docWithLocales[tab.name] === 'object') {\n result[tab.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[tab.name],\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n }\n } else {\n // Unnamed tabs pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","filterDataToSelectedLocales","configBlockReferences","docWithLocales","fields","parentIsLocalized","selectedLocales","result","field","fieldIsLocalized","type","Array","isArray","name","map","item","blockData","block","blockReferences","blockOrReference","find","b","slug","blockType","blocks","nestedResult","Object","assign","value","length","filtered","locale","keys","tab","tabs"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAUhG;;;;;CAKC,GACD,OAAO,SAASC,4BAA4B,EAC1CC,qBAAqB,EACrBC,cAAc,EACdC,MAAM,EACNC,oBAAoB,KAAK,EACzBC,eAAe,EACiB;IAChC,IAAI,CAACH,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,OAAOA;IACT;IAEA,MAAMI,SAAqB,CAAC;IAE5B,KAAK,MAAMC,SAASJ,OAAQ;QAC1B,IAAIN,iBAAiBU,QAAQ;YAC3B,MAAMC,mBAAmBV,uBAAuB;gBAAES;gBAAOH;YAAkB;YAE3E,OAAQG,MAAME,IAAI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B,KAAK;gBACL,KAAK;oBAAO;wBACV,yCAAyC;wBACzC,MAAMe,eAAexB,4BAA4B;4BAC/CC;4BACAC;4BACAC,QAAQI,MAAMJ,MAAM;4BACpBC;4BACAC;wBACF;wBACAoB,OAAOC,MAAM,CAACpB,QAAQkB;wBACtB;oBACF;gBAEA,KAAK;oBAAQ;wBACX,KAAK,MAAMQ,OAAOzB,MAAM0B,IAAI,CAAE;4BAC5B,IAAIlC,WAAWiC,MAAM;gCACnB,4CAA4C;gCAC5C,IAAIA,IAAIpB,IAAI,IAAIV,kBAAkB,OAAOA,cAAc,CAAC8B,IAAIpB,IAAI,CAAC,KAAK,UAAU;oCAC9EN,MAAM,CAAC0B,IAAIpB,IAAI,CAAC,GAAGZ,4BAA4B;wCAC7CC;wCACAC,gBAAgBA,cAAc,CAAC8B,IAAIpB,IAAI,CAAC;wCACxCT,QAAQ6B,IAAI7B,MAAM;wCAClBC;wCACAC;oCACF;gCACF;4BACF,OAAO;gCACL,gDAAgD;gCAChD,MAAMmB,eAAexB,4BAA4B;oCAC/CC;oCACAC;oCACAC,QAAQ6B,IAAI7B,MAAM;oCAClBC;oCACAC;gCACF;gCACAoB,OAAOC,MAAM,CAACpB,QAAQkB;4BACxB;wBACF;wBACA;oBACF;YACF;QACF;IACF;IAEA,OAAOlB;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"sourcesContent":["import type { Block, Field, FlattenedBlock } from '../fields/config/types.js'\nimport type { SanitizedConfig } from '../index.js'\nimport type { JsonObject } from '../types/index.js'\n\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js'\n\ntype FilterDataToSelectedLocalesArgs = {\n configBlockReferences: SanitizedConfig['blocks']\n docWithLocales: JsonObject\n fields: Field[]\n parentIsLocalized?: boolean\n selectedLocales: string[]\n}\n\n/**\n * Filters localized field data to only include specified locales.\n * For non-localized fields, returns all data as-is.\n * For localized fields, if selectedLocales is provided, returns only those locales.\n * If selectedLocales is not provided and field is localized, returns all locales.\n */\nexport function filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields,\n parentIsLocalized = false,\n selectedLocales,\n}: FilterDataToSelectedLocalesArgs): JsonObject {\n if (!docWithLocales || typeof docWithLocales !== 'object') {\n return docWithLocales\n }\n\n const result: JsonObject = {}\n\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n const fieldIsLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n switch (field.type) {\n case 'array': {\n if (Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((item: JsonObject) =>\n filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: item,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n }),\n )\n }\n break\n }\n\n case 'blocks': {\n if (field.name in docWithLocales && Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((blockData: JsonObject) => {\n let block: Block | FlattenedBlock | undefined\n if (configBlockReferences && field.blockReferences) {\n for (const blockOrReference of field.blockReferences) {\n if (typeof blockOrReference === 'string') {\n block = configBlockReferences.find((b) => b.slug === blockData.blockType)\n } else {\n block = blockOrReference\n }\n }\n } else if (field.blocks) {\n block = field.blocks.find((b) => b.slug === blockData.blockType)\n }\n\n if (block) {\n const filtered = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: blockData,\n fields: block?.fields || [],\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n\n // blockType, id, blockName are set by Payload internally\n // and not part of block.fields, so they must be preserved explicitly\n filtered.blockType = blockData.blockType\n filtered.id = blockData.id\n filtered.blockName = blockData.blockName\n\n return filtered\n }\n\n return blockData\n })\n }\n break\n }\n\n case 'group': {\n // Named groups create a nested data structure\n if (\n fieldAffectsData(field) &&\n field.name in docWithLocales &&\n typeof docWithLocales[field.name] === 'object'\n ) {\n result[field.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[field.name] as JsonObject,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n } else {\n // Unnamed groups pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n break\n }\n\n default: {\n // For all other data-affecting fields (text, number, select, etc.)\n if (field.name in docWithLocales) {\n const value = docWithLocales[field.name]\n\n // If the field is localized and has locale data\n if (fieldIsLocalized && value && typeof value === 'object' && !Array.isArray(value)) {\n // If selectedLocales is provided, filter to only those locales\n if (selectedLocales && selectedLocales.length > 0) {\n const filtered: Record<string, unknown> = {}\n for (const locale of selectedLocales) {\n if (locale in value) {\n filtered[locale] = value[locale]\n }\n }\n if (Object.keys(filtered).length > 0) {\n result[field.name] = filtered\n }\n } else {\n // If no selectedLocales, include all locales\n result[field.name] = value\n }\n } else {\n // Non-localized field or non-object value\n result[field.name] = value\n }\n }\n break\n }\n }\n } else {\n // Layout-only fields that don't affect data structure\n switch (field.type) {\n case 'collapsible':\n case 'row': {\n // These pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n // Named tabs create a nested data structure\n if (tab.name in docWithLocales && typeof docWithLocales[tab.name] === 'object') {\n result[tab.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[tab.name],\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n }\n } else {\n // Unnamed tabs pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","filterDataToSelectedLocales","configBlockReferences","docWithLocales","fields","parentIsLocalized","selectedLocales","result","field","fieldIsLocalized","type","Array","isArray","name","map","item","blockData","block","blockReferences","blockOrReference","find","b","slug","blockType","blocks","filtered","id","blockName","nestedResult","Object","assign","value","length","locale","keys","tab","tabs"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAUhG;;;;;CAKC,GACD,OAAO,SAASC,4BAA4B,EAC1CC,qBAAqB,EACrBC,cAAc,EACdC,MAAM,EACNC,oBAAoB,KAAK,EACzBC,eAAe,EACiB;IAChC,IAAI,CAACH,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,OAAOA;IACT;IAEA,MAAMI,SAAqB,CAAC;IAE5B,KAAK,MAAMC,SAASJ,OAAQ;QAC1B,IAAIN,iBAAiBU,QAAQ;YAC3B,MAAMC,mBAAmBV,uBAAuB;gBAAES;gBAAOH;YAAkB;YAE3E,OAAQG,MAAME,IAAI;gBAChB,KAAK;oBAAS;wBACZ,IAAIC,MAAMC,OAAO,CAACT,cAAc,CAACK,MAAMK,IAAI,CAAC,GAAG;4BAC7CN,MAAM,CAACC,MAAMK,IAAI,CAAC,GAAGV,cAAc,CAACK,MAAMK,IAAI,CAAC,CAACC,GAAG,CAAC,CAACC,OACnDd,4BAA4B;oCAC1BC;oCACAC,gBAAgBY;oCAChBX,QAAQI,MAAMJ,MAAM;oCACpBC,mBAAmBI;oCACnBH;gCACF;wBAEJ;wBACA;oBACF;gBAEA,KAAK;oBAAU;wBACb,IAAIE,MAAMK,IAAI,IAAIV,kBAAkBQ,MAAMC,OAAO,CAACT,cAAc,CAACK,MAAMK,IAAI,CAAC,GAAG;4BAC7EN,MAAM,CAACC,MAAMK,IAAI,CAAC,GAAGV,cAAc,CAACK,MAAMK,IAAI,CAAC,CAACC,GAAG,CAAC,CAACE;gCACnD,IAAIC;gCACJ,IAAIf,yBAAyBM,MAAMU,eAAe,E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