@strapi/content-type-builder 5.58.0 → 5.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/admin/components/AIChat/FeedbackModal.js +13 -7
  2. package/dist/admin/components/AIChat/FeedbackModal.js.map +1 -1
  3. package/dist/admin/components/AIChat/FeedbackModal.mjs +14 -8
  4. package/dist/admin/components/AIChat/FeedbackModal.mjs.map +1 -1
  5. package/dist/admin/components/AIChat/UploadCodeModal.js +12 -6
  6. package/dist/admin/components/AIChat/UploadCodeModal.js.map +1 -1
  7. package/dist/admin/components/AIChat/UploadCodeModal.mjs +13 -7
  8. package/dist/admin/components/AIChat/UploadCodeModal.mjs.map +1 -1
  9. package/dist/admin/components/AIChat/UploadFigmaModal.js +12 -6
  10. package/dist/admin/components/AIChat/UploadFigmaModal.js.map +1 -1
  11. package/dist/admin/components/AIChat/UploadFigmaModal.mjs +13 -7
  12. package/dist/admin/components/AIChat/UploadFigmaModal.mjs.map +1 -1
  13. package/dist/admin/components/AIChat/components/Attachments/components/Attachment.js +6 -3
  14. package/dist/admin/components/AIChat/components/Attachments/components/Attachment.js.map +1 -1
  15. package/dist/admin/components/AIChat/components/Attachments/components/Attachment.mjs +7 -4
  16. package/dist/admin/components/AIChat/components/Attachments/components/Attachment.mjs.map +1 -1
  17. package/dist/admin/components/AIChat/components/Collapsible.js +9 -4
  18. package/dist/admin/components/AIChat/components/Collapsible.js.map +1 -1
  19. package/dist/admin/components/AIChat/components/Collapsible.mjs +10 -5
  20. package/dist/admin/components/AIChat/components/Collapsible.mjs.map +1 -1
  21. package/dist/admin/components/AIChat/components/Dropzone.js +13 -6
  22. package/dist/admin/components/AIChat/components/Dropzone.js.map +1 -1
  23. package/dist/admin/components/AIChat/components/Dropzone.mjs +14 -7
  24. package/dist/admin/components/AIChat/components/Dropzone.mjs.map +1 -1
  25. package/dist/admin/components/AIChat/components/FloatingPanel.js +11 -4
  26. package/dist/admin/components/AIChat/components/FloatingPanel.js.map +1 -1
  27. package/dist/admin/components/AIChat/components/FloatingPanel.mjs +12 -5
  28. package/dist/admin/components/AIChat/components/FloatingPanel.mjs.map +1 -1
  29. package/dist/admin/components/AIChat/components/FullScreenImage.js +16 -8
  30. package/dist/admin/components/AIChat/components/FullScreenImage.js.map +1 -1
  31. package/dist/admin/components/AIChat/components/FullScreenImage.mjs +17 -9
  32. package/dist/admin/components/AIChat/components/FullScreenImage.mjs.map +1 -1
  33. package/dist/admin/components/AIChat/components/Input.js +6 -3
  34. package/dist/admin/components/AIChat/components/Input.js.map +1 -1
  35. package/dist/admin/components/AIChat/components/Input.mjs +7 -4
  36. package/dist/admin/components/AIChat/components/Input.mjs.map +1 -1
  37. package/dist/admin/components/AIChat/components/Messages/Message.js +88 -12
  38. package/dist/admin/components/AIChat/components/Messages/Message.js.map +1 -1
  39. package/dist/admin/components/AIChat/components/Messages/Message.mjs +87 -13
  40. package/dist/admin/components/AIChat/components/Messages/Message.mjs.map +1 -1
  41. package/dist/admin/components/AIChat/components/StepModal.js +44 -17
  42. package/dist/admin/components/AIChat/components/StepModal.js.map +1 -1
  43. package/dist/admin/components/AIChat/components/StepModal.mjs +45 -18
  44. package/dist/admin/components/AIChat/components/StepModal.mjs.map +1 -1
  45. package/dist/admin/components/AIChat/providers/ChatProvider.js +79 -27
  46. package/dist/admin/components/AIChat/providers/ChatProvider.js.map +1 -1
  47. package/dist/admin/components/AIChat/providers/ChatProvider.mjs +80 -28
  48. package/dist/admin/components/AIChat/providers/ChatProvider.mjs.map +1 -1
  49. package/dist/admin/components/AIChat/providers/SchemaProvider.js +6 -3
  50. package/dist/admin/components/AIChat/providers/SchemaProvider.js.map +1 -1
  51. package/dist/admin/components/AIChat/providers/SchemaProvider.mjs +7 -4
  52. package/dist/admin/components/AIChat/providers/SchemaProvider.mjs.map +1 -1
  53. package/dist/admin/components/AttributeOptions/AttributeOption.js +2 -2
  54. package/dist/admin/components/AttributeOptions/AttributeOption.js.map +1 -1
  55. package/dist/admin/components/AttributeOptions/AttributeOption.mjs +2 -2
  56. package/dist/admin/components/AttributeOptions/AttributeOption.mjs.map +1 -1
  57. package/dist/admin/components/ContentTypeBuilderNav/lib/buildFolderTree.js.map +1 -1
  58. package/dist/admin/components/ContentTypeBuilderNav/lib/buildFolderTree.mjs.map +1 -1
  59. package/dist/admin/components/ContentTypeBuilderNav/lib/dropProjection.js.map +1 -1
  60. package/dist/admin/components/ContentTypeBuilderNav/lib/dropProjection.mjs.map +1 -1
  61. package/dist/admin/components/CustomRadioGroup/CustomRadioGroup.js +2 -1
  62. package/dist/admin/components/CustomRadioGroup/CustomRadioGroup.js.map +1 -1
  63. package/dist/admin/components/CustomRadioGroup/CustomRadioGroup.mjs +2 -1
  64. package/dist/admin/components/CustomRadioGroup/CustomRadioGroup.mjs.map +1 -1
  65. package/dist/admin/components/DataManager/DataManagerProvider.js +317 -275
  66. package/dist/admin/components/DataManager/DataManagerProvider.js.map +1 -1
  67. package/dist/admin/components/DataManager/DataManagerProvider.mjs +319 -277
  68. package/dist/admin/components/DataManager/DataManagerProvider.mjs.map +1 -1
  69. package/dist/admin/components/DataManager/RenameMigrationModal.js.map +1 -1
  70. package/dist/admin/components/DataManager/RenameMigrationModal.mjs.map +1 -1
  71. package/dist/admin/components/DataManager/reducer.js +31 -4
  72. package/dist/admin/components/DataManager/reducer.js.map +1 -1
  73. package/dist/admin/components/DataManager/reducer.mjs +31 -4
  74. package/dist/admin/components/DataManager/reducer.mjs.map +1 -1
  75. package/dist/admin/components/DynamicZoneList.js +2 -1
  76. package/dist/admin/components/DynamicZoneList.js.map +1 -1
  77. package/dist/admin/components/DynamicZoneList.mjs +2 -1
  78. package/dist/admin/components/DynamicZoneList.mjs.map +1 -1
  79. package/dist/admin/components/FormModal/attributes/ConditionForm.js +2 -1
  80. package/dist/admin/components/FormModal/attributes/ConditionForm.js.map +1 -1
  81. package/dist/admin/components/FormModal/attributes/ConditionForm.mjs +2 -1
  82. package/dist/admin/components/FormModal/attributes/ConditionForm.mjs.map +1 -1
  83. package/dist/admin/components/FormModal/attributes/types.js +2 -2
  84. package/dist/admin/components/FormModal/attributes/types.js.map +1 -1
  85. package/dist/admin/components/FormModal/attributes/types.mjs +2 -2
  86. package/dist/admin/components/FormModal/attributes/types.mjs.map +1 -1
  87. package/dist/admin/components/FormModal/forms/forms.js +1 -1
  88. package/dist/admin/components/FormModal/forms/forms.js.map +1 -1
  89. package/dist/admin/components/FormModal/forms/forms.mjs +1 -1
  90. package/dist/admin/components/FormModal/forms/forms.mjs.map +1 -1
  91. package/dist/admin/components/GenericInputs.js +2 -1
  92. package/dist/admin/components/GenericInputs.js.map +1 -1
  93. package/dist/admin/components/GenericInputs.mjs +2 -1
  94. package/dist/admin/components/GenericInputs.mjs.map +1 -1
  95. package/dist/admin/components/TabForm.js.map +1 -1
  96. package/dist/admin/components/TabForm.mjs.map +1 -1
  97. package/dist/admin/src/components/AIChat/components/FullScreenImage.d.ts +8 -0
  98. package/dist/admin/src/components/AIChat/components/Messages/Message.d.ts +20 -0
  99. package/dist/admin/utils/folderTelemetry.js.map +1 -1
  100. package/dist/admin/utils/folderTelemetry.mjs.map +1 -1
  101. package/dist/admin/utils/formAPI.js.map +1 -1
  102. package/dist/admin/utils/formAPI.mjs.map +1 -1
  103. package/dist/server/controllers/validation/schema.js +3 -2
  104. package/dist/server/controllers/validation/schema.js.map +1 -1
  105. package/dist/server/controllers/validation/schema.mjs +4 -3
  106. package/dist/server/controllers/validation/schema.mjs.map +1 -1
  107. package/dist/server/register.js.map +1 -1
  108. package/dist/server/register.mjs.map +1 -1
  109. package/dist/server/services/migration-builder/index.js.map +1 -1
  110. package/dist/server/services/migration-builder/index.mjs.map +1 -1
  111. package/dist/server/services/schema.js +34 -1
  112. package/dist/server/services/schema.js.map +1 -1
  113. package/dist/server/services/schema.mjs +34 -1
  114. package/dist/server/services/schema.mjs.map +1 -1
  115. package/dist/server/src/controllers/validation/schema.d.ts.map +1 -1
  116. package/dist/server/src/register.d.ts.map +1 -1
  117. package/dist/server/src/services/migration-builder/index.d.ts.map +1 -1
  118. package/dist/server/src/services/schema-builder/types.d.ts.map +1 -1
  119. package/dist/server/src/services/schema.d.ts.map +1 -1
  120. package/dist/server/src/utils/uid-target.d.ts +18 -0
  121. package/dist/server/src/utils/uid-target.d.ts.map +1 -0
  122. package/dist/server/utils/uid-target.js +34 -0
  123. package/dist/server/utils/uid-target.js.map +1 -0
  124. package/dist/server/utils/uid-target.mjs +31 -0
  125. package/dist/server/utils/uid-target.mjs.map +1 -0
  126. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sources":["../../../server/src/services/schema.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport { mapValues } from 'lodash';\n\nimport type { Schema } from '@strapi/types';\n\nimport createBuilder from './schema-builder';\nimport { createMigrationBuilder } from './migration-builder';\nimport type {\n AttributeRenamesMapping,\n RenameAttributeDefinition,\n UnsupportedRename,\n} from './migration-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { getService } from '../utils';\nimport { validateUpdateSchema } from '../controllers/validation/schema';\nimport type { Schema as CTBSchema } from '../controllers/validation/schema';\nimport type { AttributeRenameMigrationMode } from '../config';\nimport {\n assertCTBOwnedApplicationContentType,\n getRestrictRelationsTo,\n isContentTypeVisible,\n} from './content-types';\nimport type { CoreContentStructureService } from './content-structure';\n\ntype ContentTypeKind = 'collectionType' | 'singleType';\n\nconst removeEmptyDefaultsOnUpdates = (schema: CTBSchema) => {\n schema.components.forEach((component) => {\n if (component.action === 'delete') {\n return;\n }\n\n component.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n};\n\nconst removeDeletedUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if (\n properties.type === 'uid' &&\n properties.targetField &&\n !contentType.attributes.find((attr) => attr.name === properties.targetField)\n ) {\n properties.targetField = undefined;\n }\n }\n });\n });\n};\n\n/**\n * Composes the ordered rename hops of an updated type into an origin -> final\n * name map (`a -> b, b -> c` gives `a -> c`).\n */\nconst composeRenames = (hops: { oldName?: string; newName?: string }[]): Map<string, string> => {\n const originByName = new Map<string, string>();\n\n hops.forEach(({ oldName, newName }) => {\n if (!oldName || !newName || oldName === newName) {\n return;\n }\n\n const origin = originByName.get(oldName) ?? oldName;\n originByName.delete(oldName);\n originByName.set(newName, origin);\n });\n\n return new Map([...originByName].map(([name, origin]) => [origin, name]));\n};\n\n/**\n * Makes field conditions follow the renames of this save: a condition whose\n * `var` still names the origin of a rename is pointed at the field's final name.\n *\n * A `var` that names an attribute of the saved type is left alone: the caller\n * already rewrote it, or (in a swap) it cannot be told apart from one that was.\n */\nconst renameConditionVarsOnUpdates = (schema: CTBSchema) => {\n type AttributeEntry = {\n action?: string;\n name?: string;\n properties?: { conditions?: { visible?: Record<string, unknown> } };\n };\n type Entry = {\n action?: string;\n renames?: { oldName?: string; newName?: string }[];\n attributes?: AttributeEntry[];\n };\n\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n entries.forEach((entry) => {\n if (entry.action !== 'update' || !Array.isArray(entry.renames)) {\n return;\n }\n\n const renames = composeRenames(entry.renames);\n const savedAttributes = (entry.attributes ?? []).filter(\n (attribute) => attribute.action !== 'delete'\n );\n const saved = new Set(savedAttributes.map((attribute) => attribute.name));\n\n savedAttributes.forEach((attribute) => {\n Object.values(attribute.properties?.conditions?.visible ?? {}).forEach((rule) => {\n const fieldVar: unknown = Array.isArray(rule) ? rule[0] : undefined;\n\n if (\n typeof fieldVar !== 'object' ||\n fieldVar === null ||\n !('var' in fieldVar) ||\n typeof fieldVar.var !== 'string' ||\n saved.has(fieldVar.var)\n ) {\n return;\n }\n\n const finalName = renames.get(fieldVar.var);\n\n if (finalName !== undefined && saved.has(finalName)) {\n fieldVar.var = finalName;\n }\n });\n });\n });\n};\n\ninterface CollectedRename {\n uid: string;\n oldName: string;\n newName: string;\n newAttribute?: RenameAttributeDefinition;\n}\n\nconst getAttributeRenameMigrationMode = (): AttributeRenameMigrationMode => {\n return strapi\n .plugin('content-type-builder')\n .config('renameMigrations.attributes', 'prompt-before-save');\n};\n\n/**\n * Collects attribute renames from the update-schema payload. The admin sends an\n * ordered `renames` array per updated content-type / component: the exact path\n * of rename hops the user performed (e.g. `a -> tmp`, `b -> a`, `tmp -> b` for a\n * swap). Order is preserved so the generated migration can replay each hop\n * verbatim — which is inherently collision-free because the Content-Type Builder\n * never allows two fields to share a name at any instant.\n */\nconst collectRenames = (schema: CTBSchema): CollectedRename[] => {\n const renames: CollectedRename[] = [];\n\n type RenameHop = { oldName?: string; newName?: string };\n type AttributeEntry = { action?: string; name?: string; properties?: RenameAttributeDefinition };\n type RenameAwareEntry = {\n action?: string;\n uid: string;\n renames?: RenameHop[];\n attributes?: AttributeEntry[];\n };\n\n const collectFrom = (entries: RenameAwareEntry[]) => {\n entries\n .filter((entry) => entry.action === 'update' && Array.isArray(entry.renames))\n .forEach((entry) => {\n // Only the last hop onto a name produces the field that carries the\n // final definition: in `a -> b, b -> c, x -> b` the first `b` is `a`'s\n // intermediate name and the final `b` is `x`'s field.\n const lastHopByNewName = new Map<string, number>();\n entry.renames!.forEach((hop, index) => {\n if (hop.newName) {\n lastHopByNewName.set(hop.newName, index);\n }\n });\n\n entry.renames!.forEach((hop, index) => {\n if (hop.oldName && hop.newName && hop.oldName !== hop.newName) {\n // The definition the field ends up with in this save, so the builder\n // can refuse hops that also change the field's storage (type,\n // relation target, component…). Intermediate hops of a chain get no\n // definition and are checked when the chain completes.\n const newAttribute =\n lastHopByNewName.get(hop.newName) === index\n ? entry.attributes?.find(\n (attribute) => attribute.action !== 'delete' && attribute.name === hop.newName\n )?.properties\n : undefined;\n\n renames.push({\n uid: entry.uid,\n oldName: hop.oldName,\n newName: hop.newName,\n newAttribute,\n });\n }\n });\n });\n };\n\n collectFrom(schema.contentTypes as unknown as RenameAwareEntry[]);\n collectFrom(schema.components as unknown as RenameAwareEntry[]);\n\n return renames;\n};\n\n/**\n * Drops renames whose final name is not an attribute after this save (it was\n * deleted in the same save), so no store is pointed at a field that is gone.\n */\nconst keepSavedAttributes = (\n schema: CTBSchema,\n mapping: AttributeRenamesMapping\n): AttributeRenamesMapping => {\n type Entry = { action?: string; uid: string; attributes?: { action?: string; name?: string }[] };\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n const result: AttributeRenamesMapping = {};\n\n for (const [uid, renames] of Object.entries(mapping)) {\n const entry = entries.find((candidate) => candidate.uid === uid);\n const saved = new Set(\n (entry?.attributes ?? [])\n .filter((attribute) => attribute.action !== 'delete' && attribute.name)\n .map((attribute) => attribute.name as string)\n );\n\n for (const [origin, final] of Object.entries(renames)) {\n if (saved.has(final)) {\n result[uid] ??= {};\n result[uid][origin] = final;\n }\n }\n }\n\n return result;\n};\n\nconst describeUnsupportedReason = (reason: UnsupportedRename['reason']): string => {\n switch (reason) {\n case 'type-changed':\n return 'the field type, relation or component also changed';\n case 'unsupported-type':\n return 'the field type cannot be migrated (e.g. polymorphic relation)';\n case 'attribute-not-found':\n return 'the field is not in the current schema';\n case 'target-occupied':\n return 'the target field still exists in the current schema';\n case 'model-not-found':\n default:\n return 'the type is not in the current schema';\n }\n};\n\n/**\n * Generates a single data-preserving rename migration for the accepted renames\n * in this save. Must run before the server reloads, while `strapi.db.metadata`\n * still reflects the old (pre-rename) schema. Resolves to the written file's\n * path (so a failed save can remove it), or `null` when nothing was written.\n */\nconst generateRenameMigrations = async (schema: CTBSchema): Promise<string | null> => {\n // In prompt modes the admin strips refused renames before sending the payload.\n if (getAttributeRenameMigrationMode() === 'never') {\n return null;\n }\n\n const renames = collectRenames(schema);\n if (renames.length === 0) {\n return null;\n }\n\n const migrationBuilder = createMigrationBuilder({ strapi });\n\n for (const { uid, oldName, newName, newAttribute } of renames) {\n migrationBuilder.addRenameAttribute(uid, { oldName, newName, newAttribute });\n }\n\n const attributeRenames = keepSavedAttributes(schema, migrationBuilder.attributeRenamesMapping());\n if (Object.keys(attributeRenames).length > 0) {\n migrationBuilder.addAttributeRenames(attributeRenames);\n }\n\n const unsupported = migrationBuilder.getUnsupported();\n if (unsupported.length > 0) {\n const fields = unsupported\n .map((u) => `${u.uid}.${u.oldName} (${describeUnsupportedReason(u.reason)})`)\n .join(', ');\n strapi.log.warn(\n `[content-type-builder] Could not generate a rename migration for ${unsupported.length} field(s): ${fields}. Data in these fields may not be preserved.`\n );\n }\n\n if (migrationBuilder.hasChanges()) {\n return migrationBuilder.writeFiles();\n }\n\n return null;\n};\n\n/**\n * Renames a single attribute on a content-type or component and generates the\n * data-preserving migration in one step. Used by the `strapi rename:field` CLI\n * command so scripted / non-UI workflows get the same behaviour as the admin.\n *\n * It reuses the regular `updateSchema` path (and therefore the same rename\n * resolver via `generateRenameMigrations`), so the migration is resolved against\n * the pre-reload `strapi.db.metadata` exactly like the admin save. The caller is\n * responsible for not reloading before this resolves (the CLI simply exits).\n *\n * Unlike the admin, there is no one to confirm a data-losing rename, so it\n * refuses before touching the schema when the rename cannot be migrated.\n */\nexport const renameAttribute = async (\n uid: string,\n oldName: string,\n newName: string\n): Promise<void> => {\n const { ApplicationError } = errors;\n\n if (!oldName || !newName) {\n throw new ApplicationError('Both an old and a new attribute name are required');\n }\n\n if (oldName === newName) {\n throw new ApplicationError(`Cannot rename \"${oldName}\" to itself`);\n }\n\n if (getAttributeRenameMigrationMode() === 'never') {\n throw new ApplicationError(\n 'Rename migrations are disabled (`renameMigrations.attributes: never`); rename the field in the Content-Type Builder instead'\n );\n }\n\n const contentType = (strapi.contentTypes as Record<string, any>)[uid];\n const component = (strapi.components as Record<string, any>)[uid];\n const model = contentType ?? component;\n\n if (!model) {\n throw new ApplicationError(`No content-type or component found for uid \"${uid}\"`);\n }\n\n if (!model.attributes?.[oldName]) {\n throw new ApplicationError(`Attribute \"${oldName}\" does not exist on \"${uid}\"`);\n }\n\n if (model.attributes?.[newName]) {\n throw new ApplicationError(`Attribute \"${newName}\" already exists on \"${uid}\"`);\n }\n\n // Reuse the formatted, CTB-visible attributes (same shape the admin sends) so\n // the schema edit matches an admin save and the renamed key is the only change.\n const formattedSchema = await getSchema();\n const isComponent = Boolean(component);\n const entry = isComponent\n ? (formattedSchema.components as Record<string, any>)[uid]\n : (formattedSchema.contentTypes as Record<string, any>)[uid];\n\n // Custom fields are exposed with their underlying type; the admin sends them\n // back as `customField` so the schema file keeps them as custom fields.\n const toPayloadProperties = (properties: Record<string, any>) =>\n properties.customField ? { ...properties, type: 'customField' } : properties;\n\n const attributes = entry.attributes.map(({ name, ...properties }: Record<string, any>) => ({\n action: 'update',\n name: name === oldName ? newName : name,\n properties: toPayloadProperties(properties),\n }));\n\n // Dry run: the field keeps its definition, so only the rename itself can be\n // refused (system attribute, unsupported relation, occupied target…).\n const { name: _name, ...oldProperties } = entry.attributes.find(\n (attribute: Record<string, any>) => attribute.name === oldName\n ) ?? { name: oldName };\n const probe = createMigrationBuilder({ strapi });\n probe.addRenameAttribute(uid, {\n oldName,\n newName,\n newAttribute: toPayloadProperties(oldProperties),\n });\n\n const refused = probe.getUnsupported();\n if (refused.length > 0) {\n throw new ApplicationError(\n `Cannot rename \"${oldName}\" on \"${uid}\" without losing its data: ${refused\n .map(({ reason }) => describeUnsupportedReason(reason))\n .join(', ')}`\n );\n }\n\n const renames = [{ oldName, newName }];\n\n const payload = isComponent\n ? {\n contentTypes: [],\n components: [\n {\n action: 'update',\n uid,\n category: model.category,\n displayName: model.info?.displayName,\n icon: model.info?.icon,\n description: model.info?.description,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n }\n : {\n contentTypes: [\n {\n action: 'update',\n uid,\n kind: model.kind,\n displayName: model.info?.displayName,\n description: model.info?.description,\n draftAndPublish: Boolean(model.options?.draftAndPublish),\n options: model.options,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n components: [],\n };\n\n // Same checks as an admin save (name rules, reserved names, snake-case\n // uniqueness: `fooBar` next to an existing `foo_bar` would share a column).\n const { data } = await validateUpdateSchema({ data: payload });\n\n await updateSchema(data as CTBSchema);\n};\n\nconst formatAttributes = (model: any) => {\n const { getVisibleAttributes } = contentTypesUtils;\n\n // only get attributes that can be seen in the CTB\n return getVisibleAttributes(model).map((key) => {\n return { ...formatAttribute(model.attributes[key]), name: key };\n });\n};\n\nexport const formatAttribute = (attribute: Schema.Attribute.AnyAttribute & Record<string, any>) => {\n if (attribute.type === 'relation') {\n return {\n ...attribute,\n targetAttribute: attribute.inversedBy || attribute.mappedBy || null,\n // Explicitly preserve conditions if they exist\n ...(attribute.conditions && { conditions: attribute.conditions }),\n };\n }\n\n return attribute;\n};\n\nexport const getSchema = async () => {\n const contentTypes = mapValues(strapi.contentTypes, (contentType) => {\n const {\n uid,\n options,\n globalId,\n pluginOptions,\n kind,\n modelName,\n plugin,\n collectionName,\n info,\n modelType,\n } = contentType;\n\n return {\n uid,\n modelName,\n kind,\n globalId,\n options,\n pluginOptions,\n plugin,\n collectionName,\n info,\n modelType,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n };\n });\n\n const components = mapValues(strapi.components, (component) => {\n const { uid, globalId, modelName, collectionName, info, category, modelType } = component;\n\n return {\n uid,\n modelName,\n globalId,\n modelType,\n collectionName,\n category,\n info,\n attributes: formatAttributes(component),\n };\n });\n\n const coreContentStructure: CoreContentStructureService = strapi.get('content-structure');\n const contentStructure = await coreContentStructure.getCleanedFile();\n\n return {\n contentStructure,\n contentTypes,\n components,\n settings: {\n renameMigrations: {\n attributes: getAttributeRenameMigrationMode(),\n },\n },\n };\n};\n\nexport const updateSchema = async (schema: CTBSchema) => {\n const builder = createBuilder();\n const apiHandler = getService('api-handler') as typeof import('./api-handler');\n\n const { components, contentTypes, contentStructure } = schema;\n\n // Reject protected/plugin deletes before builders, API backups, or folder reconciliation can\n // mutate anything. This is the server-side invariant for crafted update requests.\n contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .forEach((contentType) => assertCTBOwnedApplicationContentType(contentType.uid));\n\n // pre-process data\n removeEmptyDefaultsOnUpdates(schema);\n removeDeletedUIDTargetFieldsOnUpdates(schema);\n renameConditionVarsOnUpdates(schema);\n\n const upsertedUids = new Map<string, ContentTypeKind>();\n const deletedUids = new Set<string>();\n const generatedApiNames: string[] = [];\n const backedUpApiUids: string[] = [];\n let schemaAlreadyRolledBack = false;\n let migrationFilePath: string | null = null;\n const APIsToDelete = contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .map((contentType) => contentType.uid);\n\n try {\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n upsertedUids.set(contentType.uid, contentType.kind ?? 'collectionType');\n } else if (contentType.action === 'update' && contentType.kind) {\n // A kind switch in the same save must override the registry's stale kind,\n // otherwise a folder assignment into the new section fails validation.\n upsertedUids.set(contentType.uid, contentType.kind);\n } else if (contentType.action === 'delete') {\n deletedUids.add(contentType.uid);\n }\n }\n\n // Validate folder references before anything is written. This will throw if invalid.\n getService('content-structure').validateFromUpdate({\n incomingStructure: contentStructure,\n upsertedUids,\n deletedUids,\n });\n\n // we pre create empty typesk\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n builder.createContentType({\n ...contentType,\n attributes: {},\n });\n }\n }\n\n // we pre create empty types\n for (const component of components) {\n if (component.action === 'create') {\n builder.createComponent({\n ...component,\n attributes: {},\n });\n }\n }\n\n for (const contentType of contentTypes) {\n const { action, uid } = contentType;\n\n if (action === 'create') {\n builder.createContentTypeAttributes(\n uid,\n contentType.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n\n if (!contentType.plugin) {\n // Track before generation because a generator failure can leave a partial skeleton.\n generatedApiNames.push(contentType.singularName);\n await getService('content-types').generateAPI({\n displayName: contentType!.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n }\n }\n\n if (action === 'update') {\n builder.editContentType({\n ...contentType,\n attributes: contentType.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteContentType(uid);\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n }\n }\n\n for (const component of components) {\n const { action, uid } = component;\n\n if (action === 'create') {\n builder.createComponentAttributes(\n uid,\n component.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n }\n\n if (action === 'update') {\n builder.editComponent({\n ...component,\n attributes: component.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteComponent(uid);\n }\n }\n\n // run sanity checks on the schema\n // Relations target existing types\n // Bidirectional relation have their counterpart in the schema\n // Components target existing components\n // Nested components target existing components\n // Dynamic zones target existing components\n\n // Generate rename migrations before reloading, while strapi.db.metadata still\n // reflects the pre-rename schema (the controller triggers the reload after this).\n migrationFilePath = await generateRenameMigrations(schema);\n\n const schemaFilesWritten = await builder.writeFiles();\n\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new errors.ApplicationError('Invalid schema edition');\n }\n\n for (const uid of APIsToDelete) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n // Commit the single folder file last. Every preceding filesystem mutation can be restored.\n await getService('content-structure').commitFromUpdate({\n incomingStructure: contentStructure,\n deletedUids,\n });\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n generatedApiNames,\n schemaAlreadyRolledBack,\n migrationFilePath,\n });\n\n throw error;\n }\n\n // Backup cleanup is deliberately outside the compensating boundary: at this point all\n // user-visible artifacts, including groups.json, have committed.\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of contentTypes) {\n if (contentType.action === 'delete') {\n strapi.eventHub.emit('content-type.delete', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'update') {\n strapi.eventHub.emit('content-type.update', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'create') {\n strapi.eventHub.emit('content-type.create', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n }\n\n for (const component of components) {\n if (component.action === 'delete') {\n strapi.eventHub.emit('component.delete', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'update') {\n strapi.eventHub.emit('component.update', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'create') {\n strapi.eventHub.emit('component.create', {\n component: builder.components.get(component.uid),\n });\n }\n }\n};\n"],"names":["removeEmptyDefaultsOnUpdates","schema","components","forEach","component","action","attributes","attribute","properties","default","undefined","contentTypes","contentType","removeDeletedUIDTargetFieldsOnUpdates","type","targetField","find","attr","name","composeRenames","hops","originByName","Map","oldName","newName","origin","get","delete","set","map","renameConditionVarsOnUpdates","entries","entry","Array","isArray","renames","savedAttributes","filter","saved","Set","Object","values","conditions","visible","rule","fieldVar","var","has","finalName","getAttributeRenameMigrationMode","strapi","plugin","config","collectRenames","collectFrom","lastHopByNewName","hop","index","newAttribute","push","uid","keepSavedAttributes","mapping","result","candidate","final","describeUnsupportedReason","reason","generateRenameMigrations","length","migrationBuilder","createMigrationBuilder","addRenameAttribute","attributeRenames","attributeRenamesMapping","keys","addAttributeRenames","unsupported","getUnsupported","fields","u","join","log","warn","hasChanges","writeFiles","renameAttribute","ApplicationError","errors","model","formattedSchema","getSchema","isComponent","Boolean","toPayloadProperties","customField","_name","oldProperties","probe","refused","payload","category","displayName","info","icon","description","pluginOptions","kind","draftAndPublish","options","data","validateUpdateSchema","updateSchema","formatAttributes","getVisibleAttributes","contentTypesUtils","key","formatAttribute","targetAttribute","inversedBy","mappedBy","mapValues","globalId","modelName","collectionName","modelType","isContentTypeVisible","restrictRelationsTo","getRestrictRelationsTo","coreContentStructure","contentStructure","getCleanedFile","settings","renameMigrations","builder","createBuilder","apiHandler","getService","assertCTBOwnedApplicationContentType","upsertedUids","deletedUids","generatedApiNames","backedUpApiUids","schemaAlreadyRolledBack","migrationFilePath","APIsToDelete","add","validateFromUpdate","incomingStructure","createContentType","createComponent","createContentTypeAttributes","reduce","acc","singularName","generateAPI","pluralName","editContentType","deleteContentType","backup","createComponentAttributes","editComponent","deleteComponent","schemaFilesWritten","clear","preserveBackup","commitFromUpdate","error","rollbackSchemaMutation","finalizeSchemaMutation","eventHub","emit"],"mappings":";;;;;;;;;;;AA0BA,MAAMA,+BAA+B,CAACC,MAAAA,GAAAA;AACpCA,IAAAA,MAAAA,CAAOC,UAAU,CAACC,OAAO,CAAC,CAACC,SAAAA,GAAAA;QACzB,IAAIA,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC,YAAA;AACF,QAAA;AAEAD,QAAAA,SAAAA,CAAUE,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC5B,IAAIA,SAAAA,CAAUF,MAAM,KAAK,QAAA,EAAU;gBACjC,MAAM,EAAEG,UAAU,EAAE,GAAGD,SAAAA;AAEvB,gBAAA,IAAI,SAAA,IAAaC,UAAAA,IAAcA,UAAAA,CAAWC,OAAO,KAAK,EAAA,EAAI;AACxDD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QAEA,IAAIhD,WAAAA,CAAYP,MAAM,KAAK,QAAA,EAAU;AACnC6C,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,qBAAA,EAAuB;AAC1C/J,gBAAAA,WAAAA,EAAa0H,QAAQ3H,YAAY,CAACe,GAAG,CAACd,YAAYgD,GAAG;AACvD,aAAA,CAAA;AACF,QAAA;AACF,IAAA;IAEA,KAAK,MAAMxD,aAAaF,UAAAA,CAAY;QAClC,IAAIE,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC6C,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;AACvCvK,gBAAAA,SAAAA,EAAWkI,QAAQpI,UAAU,CAACwB,GAAG,CAACtB,UAAUwD,GAAG;AACjD,aAAA,CAAA;AACF,QAAA;QAEA,IAAIxD,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC6C,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;AACvCvK,gBAAAA,SAAAA,EAAWkI,QAAQpI,UAAU,CAACwB,GAAG,CAACtB,UAAUwD,GAAG;AACjD,aAAA,CAAA;AACF,QAAA;QAEA,IAAIxD,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC6C,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;AACvCvK,gBAAAA,SAAAA,EAAWkI,QAAQpI,UAAU,CAACwB,GAAG,CAACtB,UAAUwD,GAAG;AACjD,aAAA,CAAA;AACF,QAAA;AACF,IAAA;AACF;;;;;;;"}
1
+ {"version":3,"file":"schema.js","sources":["../../../server/src/services/schema.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport { mapValues } from 'lodash';\n\nimport type { Schema } from '@strapi/types';\n\nimport createBuilder from './schema-builder';\nimport { createMigrationBuilder } from './migration-builder';\nimport type {\n AttributeRenamesMapping,\n RenameAttributeDefinition,\n UnsupportedRename,\n} from './migration-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { getService } from '../utils';\nimport { isValidUidTarget } from '../utils/uid-target';\nimport { validateUpdateSchema } from '../controllers/validation/schema';\nimport type { Schema as CTBSchema } from '../controllers/validation/schema';\nimport type { AttributeRenameMigrationMode } from '../config';\nimport {\n assertCTBOwnedApplicationContentType,\n getRestrictRelationsTo,\n isContentTypeVisible,\n} from './content-types';\nimport type { CoreContentStructureService } from './content-structure';\n\ntype ContentTypeKind = 'collectionType' | 'singleType';\n\nconst removeEmptyDefaultsOnUpdates = (schema: CTBSchema) => {\n schema.components.forEach((component) => {\n if (component.action === 'delete') {\n return;\n }\n\n component.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n};\n\nconst removeDeletedUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if (\n properties.type === 'uid' &&\n properties.targetField &&\n !contentType.attributes.some(\n (attr) => attr.action !== 'delete' && attr.name === properties.targetField\n )\n ) {\n properties.targetField = undefined;\n }\n }\n });\n });\n};\n\n/**\n * Composes the ordered rename hops of an updated type into an origin -> final\n * name map (`a -> b, b -> c` gives `a -> c`).\n */\nconst composeRenames = (hops: { oldName?: string; newName?: string }[]): Map<string, string> => {\n const originByName = new Map<string, string>();\n\n hops.forEach(({ oldName, newName }) => {\n if (!oldName || !newName || oldName === newName) {\n return;\n }\n\n const origin = originByName.get(oldName) ?? oldName;\n originByName.delete(oldName);\n originByName.set(newName, origin);\n });\n\n return new Map([...originByName].map(([name, origin]) => [origin, name]));\n};\n\n/**\n * Makes field conditions follow the renames of this save: a condition whose\n * `var` still names the origin of a rename is pointed at the field's final name.\n *\n * A `var` that names an attribute of the saved type is left alone: the caller\n * already rewrote it, or (in a swap) it cannot be told apart from one that was.\n */\nconst renameConditionVarsOnUpdates = (schema: CTBSchema) => {\n type AttributeEntry = {\n action?: string;\n name?: string;\n properties?: { conditions?: { visible?: Record<string, unknown> } };\n };\n type Entry = {\n action?: string;\n renames?: { oldName?: string; newName?: string }[];\n attributes?: AttributeEntry[];\n };\n\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n entries.forEach((entry) => {\n if (entry.action !== 'update' || !Array.isArray(entry.renames)) {\n return;\n }\n\n const renames = composeRenames(entry.renames);\n const savedAttributes = (entry.attributes ?? []).filter(\n (attribute) => attribute.action !== 'delete'\n );\n const saved = new Set(savedAttributes.map((attribute) => attribute.name));\n\n savedAttributes.forEach((attribute) => {\n Object.values(attribute.properties?.conditions?.visible ?? {}).forEach((rule) => {\n const fieldVar: unknown = Array.isArray(rule) ? rule[0] : undefined;\n\n if (\n typeof fieldVar !== 'object' ||\n fieldVar === null ||\n !('var' in fieldVar) ||\n typeof fieldVar.var !== 'string' ||\n saved.has(fieldVar.var)\n ) {\n return;\n }\n\n const finalName = renames.get(fieldVar.var);\n\n if (finalName !== undefined && saved.has(finalName)) {\n fieldVar.var = finalName;\n }\n });\n });\n });\n};\n\n/**\n * Keeps a uid field attached to its target when that target is renamed in this\n * save. A `targetField` that names a saved (non-deleted) attribute of the\n * payload is left alone: the caller already resolved it. When the renamed\n * target is not a string or text field (custom fields are resolved to their\n * underlying type), the uid is detached.\n */\nconst renameUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action !== 'update' || !Array.isArray(contentType.renames)) {\n return;\n }\n\n const finalNames = composeRenames(contentType.renames);\n const savedAttributes = contentType.attributes.filter((attr) => attr.action !== 'delete');\n const saved = new Set(savedAttributes.map((attr) => attr.name));\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action !== 'update') {\n return;\n }\n\n const { properties } = attribute;\n\n if (properties.type !== 'uid' || !properties.targetField) {\n return;\n }\n\n const finalName = finalNames.get(properties.targetField);\n\n if (!finalName || saved.has(properties.targetField)) {\n return;\n }\n\n const target = savedAttributes.find((attr) => attr.name === finalName);\n\n properties.targetField =\n target && isValidUidTarget(target.properties) ? finalName : undefined;\n });\n });\n};\n\ninterface CollectedRename {\n uid: string;\n oldName: string;\n newName: string;\n newAttribute?: RenameAttributeDefinition;\n}\n\nconst getAttributeRenameMigrationMode = (): AttributeRenameMigrationMode => {\n return strapi\n .plugin('content-type-builder')\n .config('renameMigrations.attributes', 'prompt-before-save');\n};\n\n/**\n * Collects attribute renames from the update-schema payload. The admin sends an\n * ordered `renames` array per updated content-type / component: the exact path\n * of rename hops the user performed (e.g. `a -> tmp`, `b -> a`, `tmp -> b` for a\n * swap). Order is preserved so the generated migration can replay each hop\n * verbatim — which is inherently collision-free because the Content-Type Builder\n * never allows two fields to share a name at any instant.\n */\nconst collectRenames = (schema: CTBSchema): CollectedRename[] => {\n const renames: CollectedRename[] = [];\n\n type RenameHop = { oldName?: string; newName?: string };\n type AttributeEntry = { action?: string; name?: string; properties?: RenameAttributeDefinition };\n type RenameAwareEntry = {\n action?: string;\n uid: string;\n renames?: RenameHop[];\n attributes?: AttributeEntry[];\n };\n\n const collectFrom = (entries: RenameAwareEntry[]) => {\n entries\n .filter((entry) => entry.action === 'update' && Array.isArray(entry.renames))\n .forEach((entry) => {\n // Only the last hop onto a name produces the field that carries the\n // final definition: in `a -> b, b -> c, x -> b` the first `b` is `a`'s\n // intermediate name and the final `b` is `x`'s field.\n const lastHopByNewName = new Map<string, number>();\n entry.renames!.forEach((hop, index) => {\n if (hop.newName) {\n lastHopByNewName.set(hop.newName, index);\n }\n });\n\n entry.renames!.forEach((hop, index) => {\n if (hop.oldName && hop.newName && hop.oldName !== hop.newName) {\n // The definition the field ends up with in this save, so the builder\n // can refuse hops that also change the field's storage (type,\n // relation target, component…). Intermediate hops of a chain get no\n // definition and are checked when the chain completes.\n const newAttribute =\n lastHopByNewName.get(hop.newName) === index\n ? entry.attributes?.find(\n (attribute) => attribute.action !== 'delete' && attribute.name === hop.newName\n )?.properties\n : undefined;\n\n renames.push({\n uid: entry.uid,\n oldName: hop.oldName,\n newName: hop.newName,\n newAttribute,\n });\n }\n });\n });\n };\n\n collectFrom(schema.contentTypes as unknown as RenameAwareEntry[]);\n collectFrom(schema.components as unknown as RenameAwareEntry[]);\n\n return renames;\n};\n\n/**\n * Drops renames whose final name is not an attribute after this save (it was\n * deleted in the same save), so no store is pointed at a field that is gone.\n */\nconst keepSavedAttributes = (\n schema: CTBSchema,\n mapping: AttributeRenamesMapping\n): AttributeRenamesMapping => {\n type Entry = { action?: string; uid: string; attributes?: { action?: string; name?: string }[] };\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n const result: AttributeRenamesMapping = {};\n\n for (const [uid, renames] of Object.entries(mapping)) {\n const entry = entries.find((candidate) => candidate.uid === uid);\n const saved = new Set(\n (entry?.attributes ?? [])\n .filter((attribute) => attribute.action !== 'delete' && attribute.name)\n .map((attribute) => attribute.name as string)\n );\n\n for (const [origin, final] of Object.entries(renames)) {\n if (saved.has(final)) {\n result[uid] ??= {};\n result[uid][origin] = final;\n }\n }\n }\n\n return result;\n};\n\nconst describeUnsupportedReason = (reason: UnsupportedRename['reason']): string => {\n switch (reason) {\n case 'type-changed':\n return 'the field type, relation or component also changed';\n case 'unsupported-type':\n return 'the field type cannot be migrated (e.g. polymorphic relation)';\n case 'attribute-not-found':\n return 'the field is not in the current schema';\n case 'target-occupied':\n return 'the target field still exists in the current schema';\n case 'model-not-found':\n default:\n return 'the type is not in the current schema';\n }\n};\n\n/**\n * Generates a single data-preserving rename migration for the accepted renames\n * in this save. Must run before the server reloads, while `strapi.db.metadata`\n * still reflects the old (pre-rename) schema. Resolves to the written file's\n * path (so a failed save can remove it), or `null` when nothing was written.\n */\nconst generateRenameMigrations = async (schema: CTBSchema): Promise<string | null> => {\n // In prompt modes the admin strips refused renames before sending the payload.\n if (getAttributeRenameMigrationMode() === 'never') {\n return null;\n }\n\n const renames = collectRenames(schema);\n if (renames.length === 0) {\n return null;\n }\n\n const migrationBuilder = createMigrationBuilder({ strapi });\n\n for (const { uid, oldName, newName, newAttribute } of renames) {\n migrationBuilder.addRenameAttribute(uid, { oldName, newName, newAttribute });\n }\n\n const attributeRenames = keepSavedAttributes(schema, migrationBuilder.attributeRenamesMapping());\n if (Object.keys(attributeRenames).length > 0) {\n migrationBuilder.addAttributeRenames(attributeRenames);\n }\n\n const unsupported = migrationBuilder.getUnsupported();\n if (unsupported.length > 0) {\n const fields = unsupported\n .map((u) => `${u.uid}.${u.oldName} (${describeUnsupportedReason(u.reason)})`)\n .join(', ');\n strapi.log.warn(\n `[content-type-builder] Could not generate a rename migration for ${unsupported.length} field(s): ${fields}. Data in these fields may not be preserved.`\n );\n }\n\n if (migrationBuilder.hasChanges()) {\n return migrationBuilder.writeFiles();\n }\n\n return null;\n};\n\n/**\n * Renames a single attribute on a content-type or component and generates the\n * data-preserving migration in one step. Used by the `strapi rename:field` CLI\n * command so scripted / non-UI workflows get the same behaviour as the admin.\n *\n * It reuses the regular `updateSchema` path (and therefore the same rename\n * resolver via `generateRenameMigrations`), so the migration is resolved against\n * the pre-reload `strapi.db.metadata` exactly like the admin save. The caller is\n * responsible for not reloading before this resolves (the CLI simply exits).\n *\n * Unlike the admin, there is no one to confirm a data-losing rename, so it\n * refuses before touching the schema when the rename cannot be migrated.\n */\nexport const renameAttribute = async (\n uid: string,\n oldName: string,\n newName: string\n): Promise<void> => {\n const { ApplicationError } = errors;\n\n if (!oldName || !newName) {\n throw new ApplicationError('Both an old and a new attribute name are required');\n }\n\n if (oldName === newName) {\n throw new ApplicationError(`Cannot rename \"${oldName}\" to itself`);\n }\n\n if (getAttributeRenameMigrationMode() === 'never') {\n throw new ApplicationError(\n 'Rename migrations are disabled (`renameMigrations.attributes: never`); rename the field in the Content-Type Builder instead'\n );\n }\n\n const contentType = (strapi.contentTypes as Record<string, any>)[uid];\n const component = (strapi.components as Record<string, any>)[uid];\n const model = contentType ?? component;\n\n if (!model) {\n throw new ApplicationError(`No content-type or component found for uid \"${uid}\"`);\n }\n\n if (!model.attributes?.[oldName]) {\n throw new ApplicationError(`Attribute \"${oldName}\" does not exist on \"${uid}\"`);\n }\n\n if (model.attributes?.[newName]) {\n throw new ApplicationError(`Attribute \"${newName}\" already exists on \"${uid}\"`);\n }\n\n // Reuse the formatted, CTB-visible attributes (same shape the admin sends) so\n // the schema edit matches an admin save and the renamed key is the only change.\n const formattedSchema = await getSchema();\n const isComponent = Boolean(component);\n const entry = isComponent\n ? (formattedSchema.components as Record<string, any>)[uid]\n : (formattedSchema.contentTypes as Record<string, any>)[uid];\n\n // Custom fields are exposed with their underlying type; the admin sends them\n // back as `customField` so the schema file keeps them as custom fields.\n const toPayloadProperties = (properties: Record<string, any>) =>\n properties.customField ? { ...properties, type: 'customField' } : properties;\n\n const attributes = entry.attributes.map(({ name, ...properties }: Record<string, any>) => ({\n action: 'update',\n name: name === oldName ? newName : name,\n properties: toPayloadProperties(properties),\n }));\n\n // Dry run: the field keeps its definition, so only the rename itself can be\n // refused (system attribute, unsupported relation, occupied target…).\n const { name: _name, ...oldProperties } = entry.attributes.find(\n (attribute: Record<string, any>) => attribute.name === oldName\n ) ?? { name: oldName };\n const probe = createMigrationBuilder({ strapi });\n probe.addRenameAttribute(uid, {\n oldName,\n newName,\n newAttribute: toPayloadProperties(oldProperties),\n });\n\n const refused = probe.getUnsupported();\n if (refused.length > 0) {\n throw new ApplicationError(\n `Cannot rename \"${oldName}\" on \"${uid}\" without losing its data: ${refused\n .map(({ reason }) => describeUnsupportedReason(reason))\n .join(', ')}`\n );\n }\n\n const renames = [{ oldName, newName }];\n\n const payload = isComponent\n ? {\n contentTypes: [],\n components: [\n {\n action: 'update',\n uid,\n category: model.category,\n displayName: model.info?.displayName,\n icon: model.info?.icon,\n description: model.info?.description,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n }\n : {\n contentTypes: [\n {\n action: 'update',\n uid,\n kind: model.kind,\n displayName: model.info?.displayName,\n description: model.info?.description,\n draftAndPublish: Boolean(model.options?.draftAndPublish),\n options: model.options,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n components: [],\n };\n\n // Same checks as an admin save (name rules, reserved names, snake-case\n // uniqueness: `fooBar` next to an existing `foo_bar` would share a column).\n const { data } = await validateUpdateSchema({ data: payload });\n\n await updateSchema(data as CTBSchema);\n};\n\nconst formatAttributes = (model: any) => {\n const { getVisibleAttributes } = contentTypesUtils;\n\n // only get attributes that can be seen in the CTB\n return getVisibleAttributes(model).map((key) => {\n return { ...formatAttribute(model.attributes[key]), name: key };\n });\n};\n\nexport const formatAttribute = (attribute: Schema.Attribute.AnyAttribute & Record<string, any>) => {\n if (attribute.type === 'relation') {\n return {\n ...attribute,\n targetAttribute: attribute.inversedBy || attribute.mappedBy || null,\n // Explicitly preserve conditions if they exist\n ...(attribute.conditions && { conditions: attribute.conditions }),\n };\n }\n\n return attribute;\n};\n\nexport const getSchema = async () => {\n const contentTypes = mapValues(strapi.contentTypes, (contentType) => {\n const {\n uid,\n options,\n globalId,\n pluginOptions,\n kind,\n modelName,\n plugin,\n collectionName,\n info,\n modelType,\n } = contentType;\n\n return {\n uid,\n modelName,\n kind,\n globalId,\n options,\n pluginOptions,\n plugin,\n collectionName,\n info,\n modelType,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n };\n });\n\n const components = mapValues(strapi.components, (component) => {\n const { uid, globalId, modelName, collectionName, info, category, modelType } = component;\n\n return {\n uid,\n modelName,\n globalId,\n modelType,\n collectionName,\n category,\n info,\n attributes: formatAttributes(component),\n };\n });\n\n const coreContentStructure: CoreContentStructureService = strapi.get('content-structure');\n const contentStructure = await coreContentStructure.getCleanedFile();\n\n return {\n contentStructure,\n contentTypes,\n components,\n settings: {\n renameMigrations: {\n attributes: getAttributeRenameMigrationMode(),\n },\n },\n };\n};\n\nexport const updateSchema = async (schema: CTBSchema) => {\n const builder = createBuilder();\n const apiHandler = getService('api-handler') as typeof import('./api-handler');\n\n const { components, contentTypes, contentStructure } = schema;\n\n // Reject protected/plugin deletes before builders, API backups, or folder reconciliation can\n // mutate anything. This is the server-side invariant for crafted update requests.\n contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .forEach((contentType) => assertCTBOwnedApplicationContentType(contentType.uid));\n\n // pre-process data\n removeEmptyDefaultsOnUpdates(schema);\n renameUIDTargetFieldsOnUpdates(schema);\n removeDeletedUIDTargetFieldsOnUpdates(schema);\n renameConditionVarsOnUpdates(schema);\n\n const upsertedUids = new Map<string, ContentTypeKind>();\n const deletedUids = new Set<string>();\n const generatedApiNames: string[] = [];\n const backedUpApiUids: string[] = [];\n let schemaAlreadyRolledBack = false;\n let migrationFilePath: string | null = null;\n const APIsToDelete = contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .map((contentType) => contentType.uid);\n\n try {\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n upsertedUids.set(contentType.uid, contentType.kind ?? 'collectionType');\n } else if (contentType.action === 'update' && contentType.kind) {\n // A kind switch in the same save must override the registry's stale kind,\n // otherwise a folder assignment into the new section fails validation.\n upsertedUids.set(contentType.uid, contentType.kind);\n } else if (contentType.action === 'delete') {\n deletedUids.add(contentType.uid);\n }\n }\n\n // Validate folder references before anything is written. This will throw if invalid.\n getService('content-structure').validateFromUpdate({\n incomingStructure: contentStructure,\n upsertedUids,\n deletedUids,\n });\n\n // we pre create empty typesk\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n builder.createContentType({\n ...contentType,\n attributes: {},\n });\n }\n }\n\n // we pre create empty types\n for (const component of components) {\n if (component.action === 'create') {\n builder.createComponent({\n ...component,\n attributes: {},\n });\n }\n }\n\n for (const contentType of contentTypes) {\n const { action, uid } = contentType;\n\n if (action === 'create') {\n builder.createContentTypeAttributes(\n uid,\n contentType.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n\n if (!contentType.plugin) {\n // Track before generation because a generator failure can leave a partial skeleton.\n generatedApiNames.push(contentType.singularName);\n await getService('content-types').generateAPI({\n displayName: contentType!.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n }\n }\n\n if (action === 'update') {\n builder.editContentType({\n ...contentType,\n attributes: contentType.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteContentType(uid);\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n }\n }\n\n for (const component of components) {\n const { action, uid } = component;\n\n if (action === 'create') {\n builder.createComponentAttributes(\n uid,\n component.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n }\n\n if (action === 'update') {\n builder.editComponent({\n ...component,\n attributes: component.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteComponent(uid);\n }\n }\n\n // run sanity checks on the schema\n // Relations target existing types\n // Bidirectional relation have their counterpart in the schema\n // Components target existing components\n // Nested components target existing components\n // Dynamic zones target existing components\n\n // Generate rename migrations before reloading, while strapi.db.metadata still\n // reflects the pre-rename schema (the controller triggers the reload after this).\n migrationFilePath = await generateRenameMigrations(schema);\n\n const schemaFilesWritten = await builder.writeFiles();\n\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new errors.ApplicationError('Invalid schema edition');\n }\n\n for (const uid of APIsToDelete) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n // Commit the single folder file last. Every preceding filesystem mutation can be restored.\n await getService('content-structure').commitFromUpdate({\n incomingStructure: contentStructure,\n deletedUids,\n });\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n generatedApiNames,\n schemaAlreadyRolledBack,\n migrationFilePath,\n });\n\n throw error;\n }\n\n // Backup cleanup is deliberately outside the compensating boundary: at this point all\n // user-visible artifacts, including groups.json, have committed.\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of contentTypes) {\n if (contentType.action === 'delete') {\n strapi.eventHub.emit('content-type.delete', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'update') {\n strapi.eventHub.emit('content-type.update', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'create') {\n strapi.eventHub.emit('content-type.create', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n }\n\n for (const component of components) {\n if (component.action === 'delete') {\n strapi.eventHub.emit('component.delete', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'update') {\n strapi.eventHub.emit('component.update', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'create') {\n strapi.eventHub.emit('component.create', {\n component: builder.components.get(component.uid),\n });\n }\n }\n};\n"],"names":["removeEmptyDefaultsOnUpdates","schema","components","forEach","component","action","attributes","attribute","properties","default","undefined","contentTypes","contentType","removeDeletedUIDTargetFieldsOnUpdates","type","targetField","some","attr","name","composeRenames","hops","originByName","Map","oldName","newName","origin","get","delete","set","map","renameConditionVarsOnUpdates","entries","entry","Array","isArray","renames","savedAttributes","filter","saved","Set","Object","values","conditions","visible","rule","fieldVar","var","has","finalName","renameUIDTargetFieldsOnUpdates","finalNames","target","find","isValidUidTarget","getAttributeRenameMigrationMode","strapi","plugin","config","collectRenames","collectFrom","lastHopByNewName","hop","index","newAttribute","push","uid","keepSavedAttributes","mapping","result","candidate","final","describeUnsupportedReason","reason","generateRenameMigrations","length","migrationBuilder","createMigrationBuilder","addRenameAttribute","attributeRenames","attributeRenamesMapping","keys","addAttributeRenames","unsupported","getUnsupported","fields","u","join","log","warn","hasChanges","writeFiles","renameAttribute","ApplicationError","errors","model","formattedSchema","getSchema","isComponent","Boolean","toPayloadProperties","customField","_name","oldProperties","probe","refused","payload","category","displayName","info","icon","description","pluginOptions","kind","draftAndPublish","options","data","validateUpdateSchema","updateSchema","formatAttributes","getVisibleAttributes","contentTypesUtils","key","formatAttribute","targetAttribute","inversedBy","mappedBy","mapValues","globalId","modelName","collectionName","modelType","isContentTypeVisible","restrictRelationsTo","getRestrictRelationsTo","coreContentStructure","contentStructure","getCleanedFile","settings","renameMigrations","builder","createBuilder","apiHandler","getService","assertCTBOwnedApplicationContentType","upsertedUids","deletedUids","generatedApiNames","backedUpApiUids","schemaAlreadyRolledBack","migrationFilePath","APIsToDelete","add","validateFromUpdate","incomingStructure","createContentType","createComponent","createContentTypeAttributes","reduce","acc","singularName","generateAPI","pluralName","editContentType","deleteContentType","backup","createComponentAttributes","editComponent","deleteComponent","schemaFilesWritten","clear","preserveBackup","commitFromUpdate","error","rollbackSchemaMutation","finalizeSchemaMutation","eventHub","emit"],"mappings":";;;;;;;;;;;;AA2BA,MAAMA,+BAA+B,CAACC,MAAAA,GAAAA;AACpCA,IAAAA,MAAAA,CAAOC,UAAU,CAACC,OAAO,CAAC,CAACC,SAAAA,GAAAA;QACzB,IAAIA,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC,YAAA;AACF,QAAA;AAEAD,QAAAA,SAAAA,CAAUE,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC5B,IAAIA,SAAAA,C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AAA,EAAU;AACjCkD,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;AACvC5K,gBAAAA,SAAAA,EAAWuI,QAAQzI,UAAU,CAACwB,GAAG,CAACtB,UAAU6D,GAAG;AACjD,aAAA,CAAA;AACF,QAAA;AACF,IAAA;AACF;;;;;;;"}
@@ -4,6 +4,7 @@ import createBuilder from './schema-builder/index.mjs';
4
4
  import { createMigrationBuilder } from './migration-builder/index.mjs';
5
5
  import { rollbackSchemaMutation, finalizeSchemaMutation } from './schema-mutation.mjs';
6
6
  import { getService } from '../utils/index.mjs';
7
+ import { isValidUidTarget } from '../utils/uid-target.mjs';
7
8
  import { validateUpdateSchema } from '../controllers/validation/schema.mjs';
8
9
  import { getRestrictRelationsTo, isContentTypeVisible, assertCTBOwnedApplicationContentType } from './content-types.mjs';
9
10
 
@@ -43,7 +44,7 @@ const removeDeletedUIDTargetFieldsOnUpdates = (schema)=>{
43
44
  contentType.attributes.forEach((attribute)=>{
44
45
  if (attribute.action === 'update') {
45
46
  const { properties } = attribute;
46
- if (properties.type === 'uid' && properties.targetField && !contentType.attributes.find((attr)=>attr.name === properties.targetField)) {
47
+ if (properties.type === 'uid' && properties.targetField && !contentType.attributes.some((attr)=>attr.action !== 'delete' && attr.name === properties.targetField)) {
47
48
  properties.targetField = undefined;
48
49
  }
49
50
  }
@@ -102,6 +103,37 @@ const removeDeletedUIDTargetFieldsOnUpdates = (schema)=>{
102
103
  });
103
104
  });
104
105
  };
106
+ /**
107
+ * Keeps a uid field attached to its target when that target is renamed in this
108
+ * save. A `targetField` that names a saved (non-deleted) attribute of the
109
+ * payload is left alone: the caller already resolved it. When the renamed
110
+ * target is not a string or text field (custom fields are resolved to their
111
+ * underlying type), the uid is detached.
112
+ */ const renameUIDTargetFieldsOnUpdates = (schema)=>{
113
+ schema.contentTypes.forEach((contentType)=>{
114
+ if (contentType.action !== 'update' || !Array.isArray(contentType.renames)) {
115
+ return;
116
+ }
117
+ const finalNames = composeRenames(contentType.renames);
118
+ const savedAttributes = contentType.attributes.filter((attr)=>attr.action !== 'delete');
119
+ const saved = new Set(savedAttributes.map((attr)=>attr.name));
120
+ contentType.attributes.forEach((attribute)=>{
121
+ if (attribute.action !== 'update') {
122
+ return;
123
+ }
124
+ const { properties } = attribute;
125
+ if (properties.type !== 'uid' || !properties.targetField) {
126
+ return;
127
+ }
128
+ const finalName = finalNames.get(properties.targetField);
129
+ if (!finalName || saved.has(properties.targetField)) {
130
+ return;
131
+ }
132
+ const target = savedAttributes.find((attr)=>attr.name === finalName);
133
+ properties.targetField = target && isValidUidTarget(target.properties) ? finalName : undefined;
134
+ });
135
+ });
136
+ };
105
137
  const getAttributeRenameMigrationMode = ()=>{
106
138
  return strapi.plugin('content-type-builder').config('renameMigrations.attributes', 'prompt-before-save');
107
139
  };
@@ -411,6 +443,7 @@ const updateSchema = async (schema)=>{
411
443
  contentTypes.filter((contentType)=>contentType.action === 'delete').forEach((contentType)=>assertCTBOwnedApplicationContentType(contentType.uid));
412
444
  // pre-process data
413
445
  removeEmptyDefaultsOnUpdates(schema);
446
+ renameUIDTargetFieldsOnUpdates(schema);
414
447
  removeDeletedUIDTargetFieldsOnUpdates(schema);
415
448
  renameConditionVarsOnUpdates(schema);
416
449
  const upsertedUids = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"schema.mjs","sources":["../../../server/src/services/schema.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport { mapValues } from 'lodash';\n\nimport type { Schema } from '@strapi/types';\n\nimport createBuilder from './schema-builder';\nimport { createMigrationBuilder } from './migration-builder';\nimport type {\n AttributeRenamesMapping,\n RenameAttributeDefinition,\n UnsupportedRename,\n} from './migration-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { getService } from '../utils';\nimport { validateUpdateSchema } from '../controllers/validation/schema';\nimport type { Schema as CTBSchema } from '../controllers/validation/schema';\nimport type { AttributeRenameMigrationMode } from '../config';\nimport {\n assertCTBOwnedApplicationContentType,\n getRestrictRelationsTo,\n isContentTypeVisible,\n} from './content-types';\nimport type { CoreContentStructureService } from './content-structure';\n\ntype ContentTypeKind = 'collectionType' | 'singleType';\n\nconst removeEmptyDefaultsOnUpdates = (schema: CTBSchema) => {\n schema.components.forEach((component) => {\n if (component.action === 'delete') {\n return;\n }\n\n component.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n};\n\nconst removeDeletedUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if (\n properties.type === 'uid' &&\n properties.targetField &&\n !contentType.attributes.find((attr) => attr.name === properties.targetField)\n ) {\n properties.targetField = undefined;\n }\n }\n });\n });\n};\n\n/**\n * Composes the ordered rename hops of an updated type into an origin -> final\n * name map (`a -> b, b -> c` gives `a -> c`).\n */\nconst composeRenames = (hops: { oldName?: string; newName?: string }[]): Map<string, string> => {\n const originByName = new Map<string, string>();\n\n hops.forEach(({ oldName, newName }) => {\n if (!oldName || !newName || oldName === newName) {\n return;\n }\n\n const origin = originByName.get(oldName) ?? oldName;\n originByName.delete(oldName);\n originByName.set(newName, origin);\n });\n\n return new Map([...originByName].map(([name, origin]) => [origin, name]));\n};\n\n/**\n * Makes field conditions follow the renames of this save: a condition whose\n * `var` still names the origin of a rename is pointed at the field's final name.\n *\n * A `var` that names an attribute of the saved type is left alone: the caller\n * already rewrote it, or (in a swap) it cannot be told apart from one that was.\n */\nconst renameConditionVarsOnUpdates = (schema: CTBSchema) => {\n type AttributeEntry = {\n action?: string;\n name?: string;\n properties?: { conditions?: { visible?: Record<string, unknown> } };\n };\n type Entry = {\n action?: string;\n renames?: { oldName?: string; newName?: string }[];\n attributes?: AttributeEntry[];\n };\n\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n entries.forEach((entry) => {\n if (entry.action !== 'update' || !Array.isArray(entry.renames)) {\n return;\n }\n\n const renames = composeRenames(entry.renames);\n const savedAttributes = (entry.attributes ?? []).filter(\n (attribute) => attribute.action !== 'delete'\n );\n const saved = new Set(savedAttributes.map((attribute) => attribute.name));\n\n savedAttributes.forEach((attribute) => {\n Object.values(attribute.properties?.conditions?.visible ?? {}).forEach((rule) => {\n const fieldVar: unknown = Array.isArray(rule) ? rule[0] : undefined;\n\n if (\n typeof fieldVar !== 'object' ||\n fieldVar === null ||\n !('var' in fieldVar) ||\n typeof fieldVar.var !== 'string' ||\n saved.has(fieldVar.var)\n ) {\n return;\n }\n\n const finalName = renames.get(fieldVar.var);\n\n if (finalName !== undefined && saved.has(finalName)) {\n fieldVar.var = finalName;\n }\n });\n });\n });\n};\n\ninterface CollectedRename {\n uid: string;\n oldName: string;\n newName: string;\n newAttribute?: RenameAttributeDefinition;\n}\n\nconst getAttributeRenameMigrationMode = (): AttributeRenameMigrationMode => {\n return strapi\n .plugin('content-type-builder')\n .config('renameMigrations.attributes', 'prompt-before-save');\n};\n\n/**\n * Collects attribute renames from the update-schema payload. The admin sends an\n * ordered `renames` array per updated content-type / component: the exact path\n * of rename hops the user performed (e.g. `a -> tmp`, `b -> a`, `tmp -> b` for a\n * swap). Order is preserved so the generated migration can replay each hop\n * verbatim — which is inherently collision-free because the Content-Type Builder\n * never allows two fields to share a name at any instant.\n */\nconst collectRenames = (schema: CTBSchema): CollectedRename[] => {\n const renames: CollectedRename[] = [];\n\n type RenameHop = { oldName?: string; newName?: string };\n type AttributeEntry = { action?: string; name?: string; properties?: RenameAttributeDefinition };\n type RenameAwareEntry = {\n action?: string;\n uid: string;\n renames?: RenameHop[];\n attributes?: AttributeEntry[];\n };\n\n const collectFrom = (entries: RenameAwareEntry[]) => {\n entries\n .filter((entry) => entry.action === 'update' && Array.isArray(entry.renames))\n .forEach((entry) => {\n // Only the last hop onto a name produces the field that carries the\n // final definition: in `a -> b, b -> c, x -> b` the first `b` is `a`'s\n // intermediate name and the final `b` is `x`'s field.\n const lastHopByNewName = new Map<string, number>();\n entry.renames!.forEach((hop, index) => {\n if (hop.newName) {\n lastHopByNewName.set(hop.newName, index);\n }\n });\n\n entry.renames!.forEach((hop, index) => {\n if (hop.oldName && hop.newName && hop.oldName !== hop.newName) {\n // The definition the field ends up with in this save, so the builder\n // can refuse hops that also change the field's storage (type,\n // relation target, component…). Intermediate hops of a chain get no\n // definition and are checked when the chain completes.\n const newAttribute =\n lastHopByNewName.get(hop.newName) === index\n ? entry.attributes?.find(\n (attribute) => attribute.action !== 'delete' && attribute.name === hop.newName\n )?.properties\n : undefined;\n\n renames.push({\n uid: entry.uid,\n oldName: hop.oldName,\n newName: hop.newName,\n newAttribute,\n });\n }\n });\n });\n };\n\n collectFrom(schema.contentTypes as unknown as RenameAwareEntry[]);\n collectFrom(schema.components as unknown as RenameAwareEntry[]);\n\n return renames;\n};\n\n/**\n * Drops renames whose final name is not an attribute after this save (it was\n * deleted in the same save), so no store is pointed at a field that is gone.\n */\nconst keepSavedAttributes = (\n schema: CTBSchema,\n mapping: AttributeRenamesMapping\n): AttributeRenamesMapping => {\n type Entry = { action?: string; uid: string; attributes?: { action?: string; name?: string }[] };\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n const result: AttributeRenamesMapping = {};\n\n for (const [uid, renames] of Object.entries(mapping)) {\n const entry = entries.find((candidate) => candidate.uid === uid);\n const saved = new Set(\n (entry?.attributes ?? [])\n .filter((attribute) => attribute.action !== 'delete' && attribute.name)\n .map((attribute) => attribute.name as string)\n );\n\n for (const [origin, final] of Object.entries(renames)) {\n if (saved.has(final)) {\n result[uid] ??= {};\n result[uid][origin] = final;\n }\n }\n }\n\n return result;\n};\n\nconst describeUnsupportedReason = (reason: UnsupportedRename['reason']): string => {\n switch (reason) {\n case 'type-changed':\n return 'the field type, relation or component also changed';\n case 'unsupported-type':\n return 'the field type cannot be migrated (e.g. polymorphic relation)';\n case 'attribute-not-found':\n return 'the field is not in the current schema';\n case 'target-occupied':\n return 'the target field still exists in the current schema';\n case 'model-not-found':\n default:\n return 'the type is not in the current schema';\n }\n};\n\n/**\n * Generates a single data-preserving rename migration for the accepted renames\n * in this save. Must run before the server reloads, while `strapi.db.metadata`\n * still reflects the old (pre-rename) schema. Resolves to the written file's\n * path (so a failed save can remove it), or `null` when nothing was written.\n */\nconst generateRenameMigrations = async (schema: CTBSchema): Promise<string | null> => {\n // In prompt modes the admin strips refused renames before sending the payload.\n if (getAttributeRenameMigrationMode() === 'never') {\n return null;\n }\n\n const renames = collectRenames(schema);\n if (renames.length === 0) {\n return null;\n }\n\n const migrationBuilder = createMigrationBuilder({ strapi });\n\n for (const { uid, oldName, newName, newAttribute } of renames) {\n migrationBuilder.addRenameAttribute(uid, { oldName, newName, newAttribute });\n }\n\n const attributeRenames = keepSavedAttributes(schema, migrationBuilder.attributeRenamesMapping());\n if (Object.keys(attributeRenames).length > 0) {\n migrationBuilder.addAttributeRenames(attributeRenames);\n }\n\n const unsupported = migrationBuilder.getUnsupported();\n if (unsupported.length > 0) {\n const fields = unsupported\n .map((u) => `${u.uid}.${u.oldName} (${describeUnsupportedReason(u.reason)})`)\n .join(', ');\n strapi.log.warn(\n `[content-type-builder] Could not generate a rename migration for ${unsupported.length} field(s): ${fields}. Data in these fields may not be preserved.`\n );\n }\n\n if (migrationBuilder.hasChanges()) {\n return migrationBuilder.writeFiles();\n }\n\n return null;\n};\n\n/**\n * Renames a single attribute on a content-type or component and generates the\n * data-preserving migration in one step. Used by the `strapi rename:field` CLI\n * command so scripted / non-UI workflows get the same behaviour as the admin.\n *\n * It reuses the regular `updateSchema` path (and therefore the same rename\n * resolver via `generateRenameMigrations`), so the migration is resolved against\n * the pre-reload `strapi.db.metadata` exactly like the admin save. The caller is\n * responsible for not reloading before this resolves (the CLI simply exits).\n *\n * Unlike the admin, there is no one to confirm a data-losing rename, so it\n * refuses before touching the schema when the rename cannot be migrated.\n */\nexport const renameAttribute = async (\n uid: string,\n oldName: string,\n newName: string\n): Promise<void> => {\n const { ApplicationError } = errors;\n\n if (!oldName || !newName) {\n throw new ApplicationError('Both an old and a new attribute name are required');\n }\n\n if (oldName === newName) {\n throw new ApplicationError(`Cannot rename \"${oldName}\" to itself`);\n }\n\n if (getAttributeRenameMigrationMode() === 'never') {\n throw new ApplicationError(\n 'Rename migrations are disabled (`renameMigrations.attributes: never`); rename the field in the Content-Type Builder instead'\n );\n }\n\n const contentType = (strapi.contentTypes as Record<string, any>)[uid];\n const component = (strapi.components as Record<string, any>)[uid];\n const model = contentType ?? component;\n\n if (!model) {\n throw new ApplicationError(`No content-type or component found for uid \"${uid}\"`);\n }\n\n if (!model.attributes?.[oldName]) {\n throw new ApplicationError(`Attribute \"${oldName}\" does not exist on \"${uid}\"`);\n }\n\n if (model.attributes?.[newName]) {\n throw new ApplicationError(`Attribute \"${newName}\" already exists on \"${uid}\"`);\n }\n\n // Reuse the formatted, CTB-visible attributes (same shape the admin sends) so\n // the schema edit matches an admin save and the renamed key is the only change.\n const formattedSchema = await getSchema();\n const isComponent = Boolean(component);\n const entry = isComponent\n ? (formattedSchema.components as Record<string, any>)[uid]\n : (formattedSchema.contentTypes as Record<string, any>)[uid];\n\n // Custom fields are exposed with their underlying type; the admin sends them\n // back as `customField` so the schema file keeps them as custom fields.\n const toPayloadProperties = (properties: Record<string, any>) =>\n properties.customField ? { ...properties, type: 'customField' } : properties;\n\n const attributes = entry.attributes.map(({ name, ...properties }: Record<string, any>) => ({\n action: 'update',\n name: name === oldName ? newName : name,\n properties: toPayloadProperties(properties),\n }));\n\n // Dry run: the field keeps its definition, so only the rename itself can be\n // refused (system attribute, unsupported relation, occupied target…).\n const { name: _name, ...oldProperties } = entry.attributes.find(\n (attribute: Record<string, any>) => attribute.name === oldName\n ) ?? { name: oldName };\n const probe = createMigrationBuilder({ strapi });\n probe.addRenameAttribute(uid, {\n oldName,\n newName,\n newAttribute: toPayloadProperties(oldProperties),\n });\n\n const refused = probe.getUnsupported();\n if (refused.length > 0) {\n throw new ApplicationError(\n `Cannot rename \"${oldName}\" on \"${uid}\" without losing its data: ${refused\n .map(({ reason }) => describeUnsupportedReason(reason))\n .join(', ')}`\n );\n }\n\n const renames = [{ oldName, newName }];\n\n const payload = isComponent\n ? {\n contentTypes: [],\n components: [\n {\n action: 'update',\n uid,\n category: model.category,\n displayName: model.info?.displayName,\n icon: model.info?.icon,\n description: model.info?.description,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n }\n : {\n contentTypes: [\n {\n action: 'update',\n uid,\n kind: model.kind,\n displayName: model.info?.displayName,\n description: model.info?.description,\n draftAndPublish: Boolean(model.options?.draftAndPublish),\n options: model.options,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n components: [],\n };\n\n // Same checks as an admin save (name rules, reserved names, snake-case\n // uniqueness: `fooBar` next to an existing `foo_bar` would share a column).\n const { data } = await validateUpdateSchema({ data: payload });\n\n await updateSchema(data as CTBSchema);\n};\n\nconst formatAttributes = (model: any) => {\n const { getVisibleAttributes } = contentTypesUtils;\n\n // only get attributes that can be seen in the CTB\n return getVisibleAttributes(model).map((key) => {\n return { ...formatAttribute(model.attributes[key]), name: key };\n });\n};\n\nexport const formatAttribute = (attribute: Schema.Attribute.AnyAttribute & Record<string, any>) => {\n if (attribute.type === 'relation') {\n return {\n ...attribute,\n targetAttribute: attribute.inversedBy || attribute.mappedBy || null,\n // Explicitly preserve conditions if they exist\n ...(attribute.conditions && { conditions: attribute.conditions }),\n };\n }\n\n return attribute;\n};\n\nexport const getSchema = async () => {\n const contentTypes = mapValues(strapi.contentTypes, (contentType) => {\n const {\n uid,\n options,\n globalId,\n pluginOptions,\n kind,\n modelName,\n plugin,\n collectionName,\n info,\n modelType,\n } = contentType;\n\n return {\n uid,\n modelName,\n kind,\n globalId,\n options,\n pluginOptions,\n plugin,\n collectionName,\n info,\n modelType,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n };\n });\n\n const components = mapValues(strapi.components, (component) => {\n const { uid, globalId, modelName, collectionName, info, category, modelType } = component;\n\n return {\n uid,\n modelName,\n globalId,\n modelType,\n collectionName,\n category,\n info,\n attributes: formatAttributes(component),\n };\n });\n\n const coreContentStructure: CoreContentStructureService = strapi.get('content-structure');\n const contentStructure = await coreContentStructure.getCleanedFile();\n\n return {\n contentStructure,\n contentTypes,\n components,\n settings: {\n renameMigrations: {\n attributes: getAttributeRenameMigrationMode(),\n },\n },\n };\n};\n\nexport const updateSchema = async (schema: CTBSchema) => {\n const builder = createBuilder();\n const apiHandler = getService('api-handler') as typeof import('./api-handler');\n\n const { components, contentTypes, contentStructure } = schema;\n\n // Reject protected/plugin deletes before builders, API backups, or folder reconciliation can\n // mutate anything. This is the server-side invariant for crafted update requests.\n contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .forEach((contentType) => assertCTBOwnedApplicationContentType(contentType.uid));\n\n // pre-process data\n removeEmptyDefaultsOnUpdates(schema);\n removeDeletedUIDTargetFieldsOnUpdates(schema);\n renameConditionVarsOnUpdates(schema);\n\n const upsertedUids = new Map<string, ContentTypeKind>();\n const deletedUids = new Set<string>();\n const generatedApiNames: string[] = [];\n const backedUpApiUids: string[] = [];\n let schemaAlreadyRolledBack = false;\n let migrationFilePath: string | null = null;\n const APIsToDelete = contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .map((contentType) => contentType.uid);\n\n try {\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n upsertedUids.set(contentType.uid, contentType.kind ?? 'collectionType');\n } else if (contentType.action === 'update' && contentType.kind) {\n // A kind switch in the same save must override the registry's stale kind,\n // otherwise a folder assignment into the new section fails validation.\n upsertedUids.set(contentType.uid, contentType.kind);\n } else if (contentType.action === 'delete') {\n deletedUids.add(contentType.uid);\n }\n }\n\n // Validate folder references before anything is written. This will throw if invalid.\n getService('content-structure').validateFromUpdate({\n incomingStructure: contentStructure,\n upsertedUids,\n deletedUids,\n });\n\n // we pre create empty typesk\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n builder.createContentType({\n ...contentType,\n attributes: {},\n });\n }\n }\n\n // we pre create empty types\n for (const component of components) {\n if (component.action === 'create') {\n builder.createComponent({\n ...component,\n attributes: {},\n });\n }\n }\n\n for (const contentType of contentTypes) {\n const { action, uid } = contentType;\n\n if (action === 'create') {\n builder.createContentTypeAttributes(\n uid,\n contentType.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n\n if (!contentType.plugin) {\n // Track before generation because a generator failure can leave a partial skeleton.\n generatedApiNames.push(contentType.singularName);\n await getService('content-types').generateAPI({\n displayName: contentType!.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n }\n }\n\n if (action === 'update') {\n builder.editContentType({\n ...contentType,\n attributes: contentType.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteContentType(uid);\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n }\n }\n\n for (const component of components) {\n const { action, uid } = component;\n\n if (action === 'create') {\n builder.createComponentAttributes(\n uid,\n component.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n }\n\n if (action === 'update') {\n builder.editComponent({\n ...component,\n attributes: component.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteComponent(uid);\n }\n }\n\n // run sanity checks on the schema\n // Relations target existing types\n // Bidirectional relation have their counterpart in the schema\n // Components target existing components\n // Nested components target existing components\n // Dynamic zones target existing components\n\n // Generate rename migrations before reloading, while strapi.db.metadata still\n // reflects the pre-rename schema (the controller triggers the reload after this).\n migrationFilePath = await generateRenameMigrations(schema);\n\n const schemaFilesWritten = await builder.writeFiles();\n\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new errors.ApplicationError('Invalid schema edition');\n }\n\n for (const uid of APIsToDelete) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n // Commit the single folder file last. Every preceding filesystem mutation can be restored.\n await getService('content-structure').commitFromUpdate({\n incomingStructure: contentStructure,\n deletedUids,\n });\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n generatedApiNames,\n schemaAlreadyRolledBack,\n migrationFilePath,\n });\n\n throw error;\n }\n\n // Backup cleanup is deliberately outside the compensating boundary: at this point all\n // user-visible artifacts, including groups.json, have committed.\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of contentTypes) {\n if (contentType.action === 'delete') {\n strapi.eventHub.emit('content-type.delete', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'update') {\n strapi.eventHub.emit('content-type.update', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'create') {\n strapi.eventHub.emit('content-type.create', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n }\n\n for (const component of components) {\n if (component.action === 'delete') {\n strapi.eventHub.emit('component.delete', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'update') {\n strapi.eventHub.emit('component.update', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'create') {\n strapi.eventHub.emit('component.create', {\n component: builder.components.get(component.uid),\n });\n }\n }\n};\n"],"names":["removeEmptyDefaultsOnUpdates","schema","components","forEach","component","action","attributes","attribute","properties","default","undefined","contentTypes","contentType","removeDeletedUIDTargetFieldsOnUpdates","type","targetField","find","attr","name","composeRenames","hops","originByName","Map","oldName","newName","origin","get","delete","set","map","renameConditionVarsOnUpdates","entries","entry","Array","isArray","renames","savedAttributes","filter","saved","Set","Object","values","conditions","visible","rule","fieldVar","var","has","finalName","getAttributeRenameMigrationMode","strapi","plugin","config","collectRenames","collectFrom","lastHopByNewName","hop","index","newAttribute","push","uid","keepSavedAttributes","mapping","result","candidate","final","describeUnsupportedReason","reason","generateRenameMigrations","length","migrationBuilder","createMigrationBuilder","addRenameAttribute","attributeRenames","attributeRenamesMapping","keys","addAttributeRenames","unsupported","getUnsupported","fields","u","join","log","warn","hasChanges","writeFiles","renameAttribute","ApplicationError","errors","model","formattedSchema","getSchema","isComponent","Boolean","toPayloadProperties","customField","_name","oldProperties","probe","refused","payload","category","displayName","info","icon","description","pluginOptions","kind","draftAndPublish","options","data","validateUpdateSchema","updateSchema","formatAttributes","getVisibleAttributes","contentTypesUtils","key","formatAttribute","targetAttribute","inversedBy","mappedBy","mapValues","globalId","modelName","collectionName","modelType","isContentTypeVisible","restrictRelationsTo","getRestrictRelationsTo","coreContentStructure","contentStructure","getCleanedFile","settings","renameMigrations","builder","createBuilder","apiHandler","getService","assertCTBOwnedApplicationContentType","upsertedUids","deletedUids","generatedApiNames","backedUpApiUids","schemaAlreadyRolledBack","migrationFilePath","APIsToDelete","add","validateFromUpdate","incomingStructure","createContentType","createComponent","createContentTypeAttributes","reduce","acc","singularName","generateAPI","pluralName","editContentType","deleteContentType","backup","createComponentAttributes","editComponent","deleteComponent","schemaFilesWritten","clear","preserveBackup","commitFromUpdate","error","rollbackSchemaMutation","finalizeSchemaMutation","eventHub","emit"],"mappings":";;;;;;;;;AA0BA,MAAMA,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AA,EAAU;AACjC6C,YAAAA,MAAAA,CAAOwH,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;AACvCvK,gBAAAA,SAAAA,EAAWkI,QAAQpI,UAAU,CAACwB,GAAG,CAACtB,UAAUwD,GAAG;AACjD,aAAA,CAAA;AACF,QAAA;AACF,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"schema.mjs","sources":["../../../server/src/services/schema.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport { mapValues } from 'lodash';\n\nimport type { Schema } from '@strapi/types';\n\nimport createBuilder from './schema-builder';\nimport { createMigrationBuilder } from './migration-builder';\nimport type {\n AttributeRenamesMapping,\n RenameAttributeDefinition,\n UnsupportedRename,\n} from './migration-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { getService } from '../utils';\nimport { isValidUidTarget } from '../utils/uid-target';\nimport { validateUpdateSchema } from '../controllers/validation/schema';\nimport type { Schema as CTBSchema } from '../controllers/validation/schema';\nimport type { AttributeRenameMigrationMode } from '../config';\nimport {\n assertCTBOwnedApplicationContentType,\n getRestrictRelationsTo,\n isContentTypeVisible,\n} from './content-types';\nimport type { CoreContentStructureService } from './content-structure';\n\ntype ContentTypeKind = 'collectionType' | 'singleType';\n\nconst removeEmptyDefaultsOnUpdates = (schema: CTBSchema) => {\n schema.components.forEach((component) => {\n if (component.action === 'delete') {\n return;\n }\n\n component.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if ('default' in properties && properties.default === '') {\n properties.default = undefined;\n }\n }\n });\n });\n};\n\nconst removeDeletedUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action === 'delete') {\n return;\n }\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action === 'update') {\n const { properties } = attribute;\n\n if (\n properties.type === 'uid' &&\n properties.targetField &&\n !contentType.attributes.some(\n (attr) => attr.action !== 'delete' && attr.name === properties.targetField\n )\n ) {\n properties.targetField = undefined;\n }\n }\n });\n });\n};\n\n/**\n * Composes the ordered rename hops of an updated type into an origin -> final\n * name map (`a -> b, b -> c` gives `a -> c`).\n */\nconst composeRenames = (hops: { oldName?: string; newName?: string }[]): Map<string, string> => {\n const originByName = new Map<string, string>();\n\n hops.forEach(({ oldName, newName }) => {\n if (!oldName || !newName || oldName === newName) {\n return;\n }\n\n const origin = originByName.get(oldName) ?? oldName;\n originByName.delete(oldName);\n originByName.set(newName, origin);\n });\n\n return new Map([...originByName].map(([name, origin]) => [origin, name]));\n};\n\n/**\n * Makes field conditions follow the renames of this save: a condition whose\n * `var` still names the origin of a rename is pointed at the field's final name.\n *\n * A `var` that names an attribute of the saved type is left alone: the caller\n * already rewrote it, or (in a swap) it cannot be told apart from one that was.\n */\nconst renameConditionVarsOnUpdates = (schema: CTBSchema) => {\n type AttributeEntry = {\n action?: string;\n name?: string;\n properties?: { conditions?: { visible?: Record<string, unknown> } };\n };\n type Entry = {\n action?: string;\n renames?: { oldName?: string; newName?: string }[];\n attributes?: AttributeEntry[];\n };\n\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n entries.forEach((entry) => {\n if (entry.action !== 'update' || !Array.isArray(entry.renames)) {\n return;\n }\n\n const renames = composeRenames(entry.renames);\n const savedAttributes = (entry.attributes ?? []).filter(\n (attribute) => attribute.action !== 'delete'\n );\n const saved = new Set(savedAttributes.map((attribute) => attribute.name));\n\n savedAttributes.forEach((attribute) => {\n Object.values(attribute.properties?.conditions?.visible ?? {}).forEach((rule) => {\n const fieldVar: unknown = Array.isArray(rule) ? rule[0] : undefined;\n\n if (\n typeof fieldVar !== 'object' ||\n fieldVar === null ||\n !('var' in fieldVar) ||\n typeof fieldVar.var !== 'string' ||\n saved.has(fieldVar.var)\n ) {\n return;\n }\n\n const finalName = renames.get(fieldVar.var);\n\n if (finalName !== undefined && saved.has(finalName)) {\n fieldVar.var = finalName;\n }\n });\n });\n });\n};\n\n/**\n * Keeps a uid field attached to its target when that target is renamed in this\n * save. A `targetField` that names a saved (non-deleted) attribute of the\n * payload is left alone: the caller already resolved it. When the renamed\n * target is not a string or text field (custom fields are resolved to their\n * underlying type), the uid is detached.\n */\nconst renameUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n schema.contentTypes.forEach((contentType) => {\n if (contentType.action !== 'update' || !Array.isArray(contentType.renames)) {\n return;\n }\n\n const finalNames = composeRenames(contentType.renames);\n const savedAttributes = contentType.attributes.filter((attr) => attr.action !== 'delete');\n const saved = new Set(savedAttributes.map((attr) => attr.name));\n\n contentType.attributes.forEach((attribute) => {\n if (attribute.action !== 'update') {\n return;\n }\n\n const { properties } = attribute;\n\n if (properties.type !== 'uid' || !properties.targetField) {\n return;\n }\n\n const finalName = finalNames.get(properties.targetField);\n\n if (!finalName || saved.has(properties.targetField)) {\n return;\n }\n\n const target = savedAttributes.find((attr) => attr.name === finalName);\n\n properties.targetField =\n target && isValidUidTarget(target.properties) ? finalName : undefined;\n });\n });\n};\n\ninterface CollectedRename {\n uid: string;\n oldName: string;\n newName: string;\n newAttribute?: RenameAttributeDefinition;\n}\n\nconst getAttributeRenameMigrationMode = (): AttributeRenameMigrationMode => {\n return strapi\n .plugin('content-type-builder')\n .config('renameMigrations.attributes', 'prompt-before-save');\n};\n\n/**\n * Collects attribute renames from the update-schema payload. The admin sends an\n * ordered `renames` array per updated content-type / component: the exact path\n * of rename hops the user performed (e.g. `a -> tmp`, `b -> a`, `tmp -> b` for a\n * swap). Order is preserved so the generated migration can replay each hop\n * verbatim — which is inherently collision-free because the Content-Type Builder\n * never allows two fields to share a name at any instant.\n */\nconst collectRenames = (schema: CTBSchema): CollectedRename[] => {\n const renames: CollectedRename[] = [];\n\n type RenameHop = { oldName?: string; newName?: string };\n type AttributeEntry = { action?: string; name?: string; properties?: RenameAttributeDefinition };\n type RenameAwareEntry = {\n action?: string;\n uid: string;\n renames?: RenameHop[];\n attributes?: AttributeEntry[];\n };\n\n const collectFrom = (entries: RenameAwareEntry[]) => {\n entries\n .filter((entry) => entry.action === 'update' && Array.isArray(entry.renames))\n .forEach((entry) => {\n // Only the last hop onto a name produces the field that carries the\n // final definition: in `a -> b, b -> c, x -> b` the first `b` is `a`'s\n // intermediate name and the final `b` is `x`'s field.\n const lastHopByNewName = new Map<string, number>();\n entry.renames!.forEach((hop, index) => {\n if (hop.newName) {\n lastHopByNewName.set(hop.newName, index);\n }\n });\n\n entry.renames!.forEach((hop, index) => {\n if (hop.oldName && hop.newName && hop.oldName !== hop.newName) {\n // The definition the field ends up with in this save, so the builder\n // can refuse hops that also change the field's storage (type,\n // relation target, component…). Intermediate hops of a chain get no\n // definition and are checked when the chain completes.\n const newAttribute =\n lastHopByNewName.get(hop.newName) === index\n ? entry.attributes?.find(\n (attribute) => attribute.action !== 'delete' && attribute.name === hop.newName\n )?.properties\n : undefined;\n\n renames.push({\n uid: entry.uid,\n oldName: hop.oldName,\n newName: hop.newName,\n newAttribute,\n });\n }\n });\n });\n };\n\n collectFrom(schema.contentTypes as unknown as RenameAwareEntry[]);\n collectFrom(schema.components as unknown as RenameAwareEntry[]);\n\n return renames;\n};\n\n/**\n * Drops renames whose final name is not an attribute after this save (it was\n * deleted in the same save), so no store is pointed at a field that is gone.\n */\nconst keepSavedAttributes = (\n schema: CTBSchema,\n mapping: AttributeRenamesMapping\n): AttributeRenamesMapping => {\n type Entry = { action?: string; uid: string; attributes?: { action?: string; name?: string }[] };\n const entries = [\n ...(schema.contentTypes as unknown as Entry[]),\n ...(schema.components as unknown as Entry[]),\n ];\n\n const result: AttributeRenamesMapping = {};\n\n for (const [uid, renames] of Object.entries(mapping)) {\n const entry = entries.find((candidate) => candidate.uid === uid);\n const saved = new Set(\n (entry?.attributes ?? [])\n .filter((attribute) => attribute.action !== 'delete' && attribute.name)\n .map((attribute) => attribute.name as string)\n );\n\n for (const [origin, final] of Object.entries(renames)) {\n if (saved.has(final)) {\n result[uid] ??= {};\n result[uid][origin] = final;\n }\n }\n }\n\n return result;\n};\n\nconst describeUnsupportedReason = (reason: UnsupportedRename['reason']): string => {\n switch (reason) {\n case 'type-changed':\n return 'the field type, relation or component also changed';\n case 'unsupported-type':\n return 'the field type cannot be migrated (e.g. polymorphic relation)';\n case 'attribute-not-found':\n return 'the field is not in the current schema';\n case 'target-occupied':\n return 'the target field still exists in the current schema';\n case 'model-not-found':\n default:\n return 'the type is not in the current schema';\n }\n};\n\n/**\n * Generates a single data-preserving rename migration for the accepted renames\n * in this save. Must run before the server reloads, while `strapi.db.metadata`\n * still reflects the old (pre-rename) schema. Resolves to the written file's\n * path (so a failed save can remove it), or `null` when nothing was written.\n */\nconst generateRenameMigrations = async (schema: CTBSchema): Promise<string | null> => {\n // In prompt modes the admin strips refused renames before sending the payload.\n if (getAttributeRenameMigrationMode() === 'never') {\n return null;\n }\n\n const renames = collectRenames(schema);\n if (renames.length === 0) {\n return null;\n }\n\n const migrationBuilder = createMigrationBuilder({ strapi });\n\n for (const { uid, oldName, newName, newAttribute } of renames) {\n migrationBuilder.addRenameAttribute(uid, { oldName, newName, newAttribute });\n }\n\n const attributeRenames = keepSavedAttributes(schema, migrationBuilder.attributeRenamesMapping());\n if (Object.keys(attributeRenames).length > 0) {\n migrationBuilder.addAttributeRenames(attributeRenames);\n }\n\n const unsupported = migrationBuilder.getUnsupported();\n if (unsupported.length > 0) {\n const fields = unsupported\n .map((u) => `${u.uid}.${u.oldName} (${describeUnsupportedReason(u.reason)})`)\n .join(', ');\n strapi.log.warn(\n `[content-type-builder] Could not generate a rename migration for ${unsupported.length} field(s): ${fields}. Data in these fields may not be preserved.`\n );\n }\n\n if (migrationBuilder.hasChanges()) {\n return migrationBuilder.writeFiles();\n }\n\n return null;\n};\n\n/**\n * Renames a single attribute on a content-type or component and generates the\n * data-preserving migration in one step. Used by the `strapi rename:field` CLI\n * command so scripted / non-UI workflows get the same behaviour as the admin.\n *\n * It reuses the regular `updateSchema` path (and therefore the same rename\n * resolver via `generateRenameMigrations`), so the migration is resolved against\n * the pre-reload `strapi.db.metadata` exactly like the admin save. The caller is\n * responsible for not reloading before this resolves (the CLI simply exits).\n *\n * Unlike the admin, there is no one to confirm a data-losing rename, so it\n * refuses before touching the schema when the rename cannot be migrated.\n */\nexport const renameAttribute = async (\n uid: string,\n oldName: string,\n newName: string\n): Promise<void> => {\n const { ApplicationError } = errors;\n\n if (!oldName || !newName) {\n throw new ApplicationError('Both an old and a new attribute name are required');\n }\n\n if (oldName === newName) {\n throw new ApplicationError(`Cannot rename \"${oldName}\" to itself`);\n }\n\n if (getAttributeRenameMigrationMode() === 'never') {\n throw new ApplicationError(\n 'Rename migrations are disabled (`renameMigrations.attributes: never`); rename the field in the Content-Type Builder instead'\n );\n }\n\n const contentType = (strapi.contentTypes as Record<string, any>)[uid];\n const component = (strapi.components as Record<string, any>)[uid];\n const model = contentType ?? component;\n\n if (!model) {\n throw new ApplicationError(`No content-type or component found for uid \"${uid}\"`);\n }\n\n if (!model.attributes?.[oldName]) {\n throw new ApplicationError(`Attribute \"${oldName}\" does not exist on \"${uid}\"`);\n }\n\n if (model.attributes?.[newName]) {\n throw new ApplicationError(`Attribute \"${newName}\" already exists on \"${uid}\"`);\n }\n\n // Reuse the formatted, CTB-visible attributes (same shape the admin sends) so\n // the schema edit matches an admin save and the renamed key is the only change.\n const formattedSchema = await getSchema();\n const isComponent = Boolean(component);\n const entry = isComponent\n ? (formattedSchema.components as Record<string, any>)[uid]\n : (formattedSchema.contentTypes as Record<string, any>)[uid];\n\n // Custom fields are exposed with their underlying type; the admin sends them\n // back as `customField` so the schema file keeps them as custom fields.\n const toPayloadProperties = (properties: Record<string, any>) =>\n properties.customField ? { ...properties, type: 'customField' } : properties;\n\n const attributes = entry.attributes.map(({ name, ...properties }: Record<string, any>) => ({\n action: 'update',\n name: name === oldName ? newName : name,\n properties: toPayloadProperties(properties),\n }));\n\n // Dry run: the field keeps its definition, so only the rename itself can be\n // refused (system attribute, unsupported relation, occupied target…).\n const { name: _name, ...oldProperties } = entry.attributes.find(\n (attribute: Record<string, any>) => attribute.name === oldName\n ) ?? { name: oldName };\n const probe = createMigrationBuilder({ strapi });\n probe.addRenameAttribute(uid, {\n oldName,\n newName,\n newAttribute: toPayloadProperties(oldProperties),\n });\n\n const refused = probe.getUnsupported();\n if (refused.length > 0) {\n throw new ApplicationError(\n `Cannot rename \"${oldName}\" on \"${uid}\" without losing its data: ${refused\n .map(({ reason }) => describeUnsupportedReason(reason))\n .join(', ')}`\n );\n }\n\n const renames = [{ oldName, newName }];\n\n const payload = isComponent\n ? {\n contentTypes: [],\n components: [\n {\n action: 'update',\n uid,\n category: model.category,\n displayName: model.info?.displayName,\n icon: model.info?.icon,\n description: model.info?.description,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n }\n : {\n contentTypes: [\n {\n action: 'update',\n uid,\n kind: model.kind,\n displayName: model.info?.displayName,\n description: model.info?.description,\n draftAndPublish: Boolean(model.options?.draftAndPublish),\n options: model.options,\n pluginOptions: model.pluginOptions,\n renames,\n attributes,\n },\n ],\n components: [],\n };\n\n // Same checks as an admin save (name rules, reserved names, snake-case\n // uniqueness: `fooBar` next to an existing `foo_bar` would share a column).\n const { data } = await validateUpdateSchema({ data: payload });\n\n await updateSchema(data as CTBSchema);\n};\n\nconst formatAttributes = (model: any) => {\n const { getVisibleAttributes } = contentTypesUtils;\n\n // only get attributes that can be seen in the CTB\n return getVisibleAttributes(model).map((key) => {\n return { ...formatAttribute(model.attributes[key]), name: key };\n });\n};\n\nexport const formatAttribute = (attribute: Schema.Attribute.AnyAttribute & Record<string, any>) => {\n if (attribute.type === 'relation') {\n return {\n ...attribute,\n targetAttribute: attribute.inversedBy || attribute.mappedBy || null,\n // Explicitly preserve conditions if they exist\n ...(attribute.conditions && { conditions: attribute.conditions }),\n };\n }\n\n return attribute;\n};\n\nexport const getSchema = async () => {\n const contentTypes = mapValues(strapi.contentTypes, (contentType) => {\n const {\n uid,\n options,\n globalId,\n pluginOptions,\n kind,\n modelName,\n plugin,\n collectionName,\n info,\n modelType,\n } = contentType;\n\n return {\n uid,\n modelName,\n kind,\n globalId,\n options,\n pluginOptions,\n plugin,\n collectionName,\n info,\n modelType,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n };\n });\n\n const components = mapValues(strapi.components, (component) => {\n const { uid, globalId, modelName, collectionName, info, category, modelType } = component;\n\n return {\n uid,\n modelName,\n globalId,\n modelType,\n collectionName,\n category,\n info,\n attributes: formatAttributes(component),\n };\n });\n\n const coreContentStructure: CoreContentStructureService = strapi.get('content-structure');\n const contentStructure = await coreContentStructure.getCleanedFile();\n\n return {\n contentStructure,\n contentTypes,\n components,\n settings: {\n renameMigrations: {\n attributes: getAttributeRenameMigrationMode(),\n },\n },\n };\n};\n\nexport const updateSchema = async (schema: CTBSchema) => {\n const builder = createBuilder();\n const apiHandler = getService('api-handler') as typeof import('./api-handler');\n\n const { components, contentTypes, contentStructure } = schema;\n\n // Reject protected/plugin deletes before builders, API backups, or folder reconciliation can\n // mutate anything. This is the server-side invariant for crafted update requests.\n contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .forEach((contentType) => assertCTBOwnedApplicationContentType(contentType.uid));\n\n // pre-process data\n removeEmptyDefaultsOnUpdates(schema);\n renameUIDTargetFieldsOnUpdates(schema);\n removeDeletedUIDTargetFieldsOnUpdates(schema);\n renameConditionVarsOnUpdates(schema);\n\n const upsertedUids = new Map<string, ContentTypeKind>();\n const deletedUids = new Set<string>();\n const generatedApiNames: string[] = [];\n const backedUpApiUids: string[] = [];\n let schemaAlreadyRolledBack = false;\n let migrationFilePath: string | null = null;\n const APIsToDelete = contentTypes\n .filter((contentType) => contentType.action === 'delete')\n .map((contentType) => contentType.uid);\n\n try {\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n upsertedUids.set(contentType.uid, contentType.kind ?? 'collectionType');\n } else if (contentType.action === 'update' && contentType.kind) {\n // A kind switch in the same save must override the registry's stale kind,\n // otherwise a folder assignment into the new section fails validation.\n upsertedUids.set(contentType.uid, contentType.kind);\n } else if (contentType.action === 'delete') {\n deletedUids.add(contentType.uid);\n }\n }\n\n // Validate folder references before anything is written. This will throw if invalid.\n getService('content-structure').validateFromUpdate({\n incomingStructure: contentStructure,\n upsertedUids,\n deletedUids,\n });\n\n // we pre create empty typesk\n for (const contentType of contentTypes) {\n if (contentType.action === 'create') {\n builder.createContentType({\n ...contentType,\n attributes: {},\n });\n }\n }\n\n // we pre create empty types\n for (const component of components) {\n if (component.action === 'create') {\n builder.createComponent({\n ...component,\n attributes: {},\n });\n }\n }\n\n for (const contentType of contentTypes) {\n const { action, uid } = contentType;\n\n if (action === 'create') {\n builder.createContentTypeAttributes(\n uid,\n contentType.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n\n if (!contentType.plugin) {\n // Track before generation because a generator failure can leave a partial skeleton.\n generatedApiNames.push(contentType.singularName);\n await getService('content-types').generateAPI({\n displayName: contentType!.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n }\n }\n\n if (action === 'update') {\n builder.editContentType({\n ...contentType,\n attributes: contentType.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteContentType(uid);\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n }\n }\n\n for (const component of components) {\n const { action, uid } = component;\n\n if (action === 'create') {\n builder.createComponentAttributes(\n uid,\n component.attributes.reduce((acc: any, attr: any) => {\n acc[attr.name] = attr.properties;\n return acc;\n }, {})\n );\n }\n\n if (action === 'update') {\n builder.editComponent({\n ...component,\n attributes: component.attributes.reduce((acc: any, attr: any) => {\n if (attr.action === 'delete') {\n return acc;\n }\n\n acc[attr.name] = attr.properties;\n return acc;\n }, {}),\n });\n }\n\n if (action === 'delete') {\n builder.deleteComponent(uid);\n }\n }\n\n // run sanity checks on the schema\n // Relations target existing types\n // Bidirectional relation have their counterpart in the schema\n // Components target existing components\n // Nested components target existing components\n // Dynamic zones target existing components\n\n // Generate rename migrations before reloading, while strapi.db.metadata still\n // reflects the pre-rename schema (the controller triggers the reload after this).\n migrationFilePath = await generateRenameMigrations(schema);\n\n const schemaFilesWritten = await builder.writeFiles();\n\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new errors.ApplicationError('Invalid schema edition');\n }\n\n for (const uid of APIsToDelete) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n // Commit the single folder file last. Every preceding filesystem mutation can be restored.\n await getService('content-structure').commitFromUpdate({\n incomingStructure: contentStructure,\n deletedUids,\n });\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n generatedApiNames,\n schemaAlreadyRolledBack,\n migrationFilePath,\n });\n\n throw error;\n }\n\n // Backup cleanup is deliberately outside the compensating boundary: at this point all\n // user-visible artifacts, including groups.json, have committed.\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of contentTypes) {\n if (contentType.action === 'delete') {\n strapi.eventHub.emit('content-type.delete', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'update') {\n strapi.eventHub.emit('content-type.update', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n\n if (contentType.action === 'create') {\n strapi.eventHub.emit('content-type.create', {\n contentType: builder.contentTypes.get(contentType.uid),\n });\n }\n }\n\n for (const component of components) {\n if (component.action === 'delete') {\n strapi.eventHub.emit('component.delete', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'update') {\n strapi.eventHub.emit('component.update', {\n component: builder.components.get(component.uid),\n });\n }\n\n if (component.action === 'create') {\n strapi.eventHub.emit('component.create', {\n component: builder.components.get(component.uid),\n });\n }\n }\n};\n"],"names":["removeEmptyDefaultsOnUpdates","schema","components","forEach","component","action","attributes","attribute","properties","default","undefined","contentTypes","contentType","removeDeletedUIDTargetFieldsOnUpdates","type","targetField","some","attr","name","composeRenames","hops","originByName","Map","oldName","newName","origin","get","delete","set","map","renameConditionVarsOnUpdates","entries","entry","Array","isArray","renames","savedAttributes","filter","saved","Set","Object","values","conditions","visible","rule","fieldVar","var","has","finalName","renameUIDTargetFieldsOnUpdates","finalNames","target","find","isValidUidTarget","getAttributeRenameMigrationMode","strapi","plugin","config","collectRenames","collectFrom","lastHopByNewName","hop","index","newAttribute","push","uid","keepSavedAttributes","mapping","result","candidate","final","describeUnsupportedReason","reason","generateRenameMigrations","length","migrationBuilder","createMigrationBuilder","addRenameAttribute","attributeRenames","attributeRenamesMapping","keys","addAttributeRenames","unsupported","getUnsupported","fields","u","join","log","warn","hasChanges","writeFiles","renameAttribute","ApplicationError","errors","model","formattedSchema","getSchema","isComponent","Boolean","toPayloadProperties","customField","_name","oldProperties","probe","refused","payload","category","displayName","info","icon","description","pluginOptions","kind","draftAndPublish","options","data","validateUpdateSchema","updateSchema","formatAttributes","getVisibleAttributes","contentTypesUtils","key","formatAttribute","targetAttribute","inversedBy","mappedBy","mapValues","globalId","modelName","collectionName","modelType","isContentTypeVisible","restrictRelationsTo","getRestrictRelationsTo","coreContentStructure","contentStructure","getCleanedFile","settings","renameMigrations","builder","createBuilder","apiHandler","getService","assertCTBOwnedApplicationContentType","upsertedUids","deletedUids","generatedApiNames","backedUpApiUids","schemaAlreadyRolledBack","migrationFilePath","APIsToDelete","add","validateFromUpdate","incomingStructure","createContentType","createComponent","createContentTypeAttributes","reduce","acc","singularName","generateAPI","pluralName","editContentType","deleteContentType","backup","createComponentAttributes","editComponent","deleteComponent","schemaFilesWritten","clear","preserveBackup","commitFromUpdate","error","rollbackSchemaMutation","finalizeSchemaMutation","eventHub","emit"],"mappings":";;;;;;;;;;AA2BA,MAAMA,+BAA+B,CAACC,MAAAA,GAAAA;AACpCA,IAAAA,MAAAA,CAAOC,UAAU,CAACC,OAAO,CAAC,CAACC,SAAAA,GAAAA;QACzB,IAAIA,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC,YAAA;AACF,QAAA;AAEAD,QAAAA,SAAAA,CAAUE,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC5B,IAAIA,SAAAA,CAAUF,MAAM,KAAK,QAAA,EAAU;gBACjC,MAAM,EAAEG,UAAU,EAAE,GAAGD,SAAAA;AAEvB,gBAAA,IAAI,SAAA,IAAaC,UAAAA,IAAcA,UAAAA,CAAWC,OAAO,KAAK,EAAA,EAAI;AACxDD,oBAAAA,UAAAA,CAAWC,OAAO,GAAGC,SAAAA;AACvB,gBAAA;AACF,YAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAA;AAEAT,IAAAA,MAAAA,CAAOU,YAAY,CAACR,OAAO,CAAC,CAACS,WAAAA,GAAAA;QAC3B,IAAIA,WAAAA,CAAYP,MAAM,KAAK,QAAA,EAAU;AACnC,YAAA;AACF,QAAA;AAEAO,QAAAA,WAAAA,CAAYN,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC9B,IAAIA,SAAAA,CAAUF,MAAM,KAAK,QAAA,EAAU;gBACjC,MAAM,EAAEG,UAAU,EAAE,GAAGD,SAAAA;AAEvB,gBAAA,IAAI,SAAA,IAAaC,UAAAA,IAAcA,UAAAA,CAAWC,OAAO,KAAK,EAAA,EAAI;AACxDD,oBAAAA,UAAAA,CAAWC,OAAO,GAAGC,SAAAA;AACvB,gBAAA;AACF,YAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA,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