@strapi/content-type-builder 5.61.1 → 5.62.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 (120) hide show
  1. package/dist/admin/components/AIChat/FeedbackModal.js +3 -3
  2. package/dist/admin/components/AIChat/FeedbackModal.js.map +1 -1
  3. package/dist/admin/components/AIChat/FeedbackModal.mjs +5 -5
  4. package/dist/admin/components/AIChat/FeedbackModal.mjs.map +1 -1
  5. package/dist/admin/components/AIChat/UploadCodeModal.js +1 -0
  6. package/dist/admin/components/AIChat/UploadCodeModal.js.map +1 -1
  7. package/dist/admin/components/AIChat/UploadCodeModal.mjs +1 -0
  8. package/dist/admin/components/AIChat/UploadCodeModal.mjs.map +1 -1
  9. package/dist/admin/components/AIChat/UploadFigmaModal.js +2 -0
  10. package/dist/admin/components/AIChat/UploadFigmaModal.js.map +1 -1
  11. package/dist/admin/components/AIChat/UploadFigmaModal.mjs +2 -0
  12. package/dist/admin/components/AIChat/UploadFigmaModal.mjs.map +1 -1
  13. package/dist/admin/components/AIChat/components/StepModal.js +11 -8
  14. package/dist/admin/components/AIChat/components/StepModal.js.map +1 -1
  15. package/dist/admin/components/AIChat/components/StepModal.mjs +12 -9
  16. package/dist/admin/components/AIChat/components/StepModal.mjs.map +1 -1
  17. package/dist/admin/components/DataManager/useServerRestartWatcher.js +36 -25
  18. package/dist/admin/components/DataManager/useServerRestartWatcher.js.map +1 -1
  19. package/dist/admin/components/DataManager/useServerRestartWatcher.mjs +16 -25
  20. package/dist/admin/components/DataManager/useServerRestartWatcher.mjs.map +1 -1
  21. package/dist/admin/components/DataManager/watchServerRestart.js +52 -0
  22. package/dist/admin/components/DataManager/watchServerRestart.js.map +1 -0
  23. package/dist/admin/components/DataManager/watchServerRestart.mjs +50 -0
  24. package/dist/admin/components/DataManager/watchServerRestart.mjs.map +1 -0
  25. package/dist/admin/components/FormModal/FormModal.js +40 -50
  26. package/dist/admin/components/FormModal/FormModal.js.map +1 -1
  27. package/dist/admin/components/FormModal/FormModal.mjs +41 -51
  28. package/dist/admin/components/FormModal/FormModal.mjs.map +1 -1
  29. package/dist/admin/components/FormModal/reducer.js +18 -6
  30. package/dist/admin/components/FormModal/reducer.js.map +1 -1
  31. package/dist/admin/components/FormModal/reducer.mjs +18 -6
  32. package/dist/admin/components/FormModal/reducer.mjs.map +1 -1
  33. package/dist/admin/components/GenericInputs.js +26 -1
  34. package/dist/admin/components/GenericInputs.js.map +1 -1
  35. package/dist/admin/components/GenericInputs.mjs +26 -2
  36. package/dist/admin/components/GenericInputs.mjs.map +1 -1
  37. package/dist/admin/src/components/AIChat/components/StepModal.d.ts +6 -1
  38. package/dist/admin/src/components/DataManager/useServerRestartWatcher.d.ts +1 -1
  39. package/dist/admin/src/components/DataManager/watchServerRestart.d.ts +20 -0
  40. package/dist/admin/src/components/FormModal/reducer.d.ts +53 -1
  41. package/dist/admin/src/components/GenericInputs.d.ts +12 -2
  42. package/dist/server/controllers/component-categories.js +24 -11
  43. package/dist/server/controllers/component-categories.js.map +1 -1
  44. package/dist/server/controllers/component-categories.mjs +24 -11
  45. package/dist/server/controllers/component-categories.mjs.map +1 -1
  46. package/dist/server/controllers/components.js +9 -2
  47. package/dist/server/controllers/components.js.map +1 -1
  48. package/dist/server/controllers/components.mjs +9 -2
  49. package/dist/server/controllers/components.mjs.map +1 -1
  50. package/dist/server/controllers/content-types.js +10 -3
  51. package/dist/server/controllers/content-types.js.map +1 -1
  52. package/dist/server/controllers/content-types.mjs +10 -3
  53. package/dist/server/controllers/content-types.mjs.map +1 -1
  54. package/dist/server/controllers/schema.js +4 -0
  55. package/dist/server/controllers/schema.js.map +1 -1
  56. package/dist/server/controllers/schema.mjs +4 -0
  57. package/dist/server/controllers/schema.mjs.map +1 -1
  58. package/dist/server/services/component-categories.js.map +1 -1
  59. package/dist/server/services/component-categories.mjs.map +1 -1
  60. package/dist/server/services/components.js.map +1 -1
  61. package/dist/server/services/components.mjs.map +1 -1
  62. package/dist/server/services/content-types.js +17 -5
  63. package/dist/server/services/content-types.js.map +1 -1
  64. package/dist/server/services/content-types.mjs +17 -5
  65. package/dist/server/services/content-types.mjs.map +1 -1
  66. package/dist/server/services/schema-builder/component-builder.js +3 -1
  67. package/dist/server/services/schema-builder/component-builder.js.map +1 -1
  68. package/dist/server/services/schema-builder/component-builder.mjs +3 -1
  69. package/dist/server/services/schema-builder/component-builder.mjs.map +1 -1
  70. package/dist/server/services/schema-builder/content-type-builder.js +3 -1
  71. package/dist/server/services/schema-builder/content-type-builder.js.map +1 -1
  72. package/dist/server/services/schema-builder/content-type-builder.mjs +3 -1
  73. package/dist/server/services/schema-builder/content-type-builder.mjs.map +1 -1
  74. package/dist/server/services/schema-builder/index.js +57 -5
  75. package/dist/server/services/schema-builder/index.js.map +1 -1
  76. package/dist/server/services/schema-builder/index.mjs +57 -5
  77. package/dist/server/services/schema-builder/index.mjs.map +1 -1
  78. package/dist/server/services/schema-builder/rename-component-uids.js +70 -0
  79. package/dist/server/services/schema-builder/rename-component-uids.js.map +1 -0
  80. package/dist/server/services/schema-builder/rename-component-uids.mjs +68 -0
  81. package/dist/server/services/schema-builder/rename-component-uids.mjs.map +1 -0
  82. package/dist/server/services/schema-builder/schema-handler.js +10 -3
  83. package/dist/server/services/schema-builder/schema-handler.js.map +1 -1
  84. package/dist/server/services/schema-builder/schema-handler.mjs +10 -3
  85. package/dist/server/services/schema-builder/schema-handler.mjs.map +1 -1
  86. package/dist/server/services/schema.js +19 -5
  87. package/dist/server/services/schema.js.map +1 -1
  88. package/dist/server/services/schema.mjs +19 -5
  89. package/dist/server/services/schema.mjs.map +1 -1
  90. package/dist/server/src/controllers/component-categories.d.ts.map +1 -1
  91. package/dist/server/src/controllers/components.d.ts.map +1 -1
  92. package/dist/server/src/controllers/content-types.d.ts.map +1 -1
  93. package/dist/server/src/controllers/schema.d.ts.map +1 -1
  94. package/dist/server/src/services/component-categories.d.ts.map +1 -1
  95. package/dist/server/src/services/components.d.ts +2 -2
  96. package/dist/server/src/services/components.d.ts.map +1 -1
  97. package/dist/server/src/services/content-types.d.ts.map +1 -1
  98. package/dist/server/src/services/schema-builder/component-builder.d.ts +3 -2
  99. package/dist/server/src/services/schema-builder/component-builder.d.ts.map +1 -1
  100. package/dist/server/src/services/schema-builder/content-type-builder.d.ts +3 -2
  101. package/dist/server/src/services/schema-builder/content-type-builder.d.ts.map +1 -1
  102. package/dist/server/src/services/schema-builder/index.d.ts +48 -16
  103. package/dist/server/src/services/schema-builder/index.d.ts.map +1 -1
  104. package/dist/server/src/services/schema-builder/rename-component-uids.d.ts +34 -0
  105. package/dist/server/src/services/schema-builder/rename-component-uids.d.ts.map +1 -0
  106. package/dist/server/src/services/schema-builder/schema-handler.d.ts +21 -6
  107. package/dist/server/src/services/schema-builder/schema-handler.d.ts.map +1 -1
  108. package/dist/server/src/services/schema.d.ts.map +1 -1
  109. package/dist/server/src/utils/errors.d.ts +9 -0
  110. package/dist/server/src/utils/errors.d.ts.map +1 -0
  111. package/dist/server/src/utils/uid-target.d.ts.map +1 -1
  112. package/dist/server/utils/errors.js +26 -0
  113. package/dist/server/utils/errors.js.map +1 -0
  114. package/dist/server/utils/errors.mjs +24 -0
  115. package/dist/server/utils/errors.mjs.map +1 -0
  116. package/dist/server/utils/uid-target.js +2 -1
  117. package/dist/server/utils/uid-target.js.map +1 -1
  118. package/dist/server/utils/uid-target.mjs +2 -1
  119. package/dist/server/utils/uid-target.mjs.map +1 -1
  120. package/package.json +11 -13
@@ -1 +1 @@
1
- {"version":3,"file":"content-type-builder.js","sources":["../../../../server/src/services/schema-builder/content-type-builder.ts"],"sourcesContent":["import path from 'path';\nimport _ from 'lodash';\n\nimport { strings, errors } from '@strapi/utils';\nimport type { Schema, Internal } from '@strapi/types';\nimport { isRelation, isConfigurable } from '../../utils/attributes';\nimport { typeKinds } from '../constants';\nimport createSchemaHandler from './schema-handler';\nimport { CreateContentTypeInput } from '../../controllers/validation/content-type';\nimport type { InternalRelationAttribute, InternalAttribute } from './types';\n\nconst { ApplicationError } = errors;\n\nconst reuseUnsetPreviousProperties = (\n newAttribute: Schema.Attribute.AnyAttribute,\n oldAttribute: Schema.Attribute.AnyAttribute\n) => {\n _.defaults(\n newAttribute,\n _.omit(oldAttribute, [\n 'configurable',\n 'required',\n 'private',\n 'unique',\n 'pluginOptions',\n 'inversedBy',\n 'mappedBy',\n 'conditions', // Don't automatically preserve conditions\n ])\n );\n};\n\n/**\n * Maps each attribute name produced by this save's rename hops to the name it\n * had before the save, by folding the hops in order (`a -> tmp, tmp -> b`\n * gives `b -> a`).\n */\nconst getRenameOrigins = (renames: unknown): Map<string, string> => {\n const originOf = new Map<string, string>();\n\n if (!Array.isArray(renames)) {\n return originOf;\n }\n\n for (const { oldName, newName } of renames as { oldName?: string; newName?: string }[]) {\n if (!oldName || !newName || oldName === newName) {\n continue;\n }\n\n const origin = originOf.get(oldName) ?? oldName;\n originOf.delete(oldName);\n originOf.set(newName, origin);\n }\n\n return originOf;\n};\n\nexport default function createComponentBuilder() {\n return {\n setRelation(\n this: any,\n { key, uid, attribute }: { key: string; uid: string; attribute: InternalRelationAttribute }\n ) {\n if (!_.has(attribute, 'target')) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n if (!targetCT) {\n throw new ApplicationError(`Content type ${attribute.target} not found`);\n }\n\n const targetAttribute = targetCT.getAttribute(attribute.targetAttribute);\n\n if (!attribute.targetAttribute) {\n return;\n }\n\n // When generating the inverse relation, preserve existing conditions if they exist\n // If the target attribute already exists and has conditions, preserve them\n const targetAttributeData = targetAttribute || {};\n\n // If the source doesn't have conditions but the target does, preserve target's conditions\n\n targetCT.setAttribute(\n attribute.targetAttribute,\n generateRelation({ key, attribute, uid, targetAttribute: targetAttributeData })\n );\n },\n\n unsetRelation(\n this: any,\n attribute: Schema.Attribute.Relation<Schema.Attribute.RelationKind.Any>\n ) {\n if (!('target' in attribute) || !attribute.target) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n const targetAttribute = targetCT.getAttribute(targetAttributeName);\n\n if (!targetAttribute) return;\n\n return targetCT.deleteAttribute(targetAttributeName);\n },\n\n createContentTypeAttributes(\n this: any,\n uid: string,\n attributes: CreateContentTypeInput['attributes']\n ) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n // support self referencing content type relation\n Object.keys(attributes).forEach((key) => {\n const { target } = attributes[key];\n if (target === '__self__') {\n attributes[key].target = uid;\n }\n });\n\n contentType.setAttributes(this.convertAttributes(attributes));\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = attributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n return contentType;\n },\n\n /**\n * Creates a content type in memory to be written to files later on\n */\n createContentType(this: any, infos: CreateContentTypeInput) {\n // TODO:: check for unique uid / singularName & pluralName & collectionName\n\n if (infos.uid && infos.uid !== createContentTypeUID(infos)) {\n throw new ApplicationError('contentType.invalidUID');\n }\n\n const uid = infos.uid ?? createContentTypeUID(infos);\n\n if (this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.alreadyExists');\n }\n\n const dir = infos.plugin\n ? path.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName)\n : path.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);\n\n const contentType = createSchemaHandler({\n modelName: infos.singularName,\n dir,\n filename: `schema.json`,\n });\n\n this.contentTypes.set(uid, contentType);\n\n contentType\n .setUID(uid)\n .set('kind', infos.kind || typeKinds.COLLECTION_TYPE)\n .set(\n 'collectionName',\n infos.collectionName || strings.nameToCollectionName(infos.pluralName)\n )\n .set('info', {\n singularName: infos.singularName,\n pluralName: infos.pluralName,\n displayName: infos.displayName,\n description: infos.description,\n })\n .set('options', {\n ...infos.options,\n draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n this.createContentTypeAttributes(uid, infos.attributes);\n\n return contentType;\n },\n\n editContentType(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n const oldAttributes = contentType.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n const newKeys = _.difference(Object.keys(newAttributes), Object.keys(oldAttributes));\n const deletedKeys = _.difference(Object.keys(oldAttributes), Object.keys(newAttributes));\n const remainingKeys = _.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));\n const renameOrigins = getRenameOrigins(infos.renames);\n\n // remove old relations\n deletedKeys.forEach((key) => {\n const attribute = oldAttributes[key];\n\n // if the old relation has a target attribute. we need to remove it in the target type\n if (isConfigurable(attribute) && isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n\n if (targetAttributeName !== null && targetAttributeName !== undefined) {\n this.unsetRelation(attribute);\n }\n }\n });\n\n remainingKeys.forEach((key) => {\n const oldAttribute = oldAttributes[key];\n const newAttribute = newAttributes[key] as InternalAttribute;\n\n if (!isRelation(oldAttribute) && isRelation(newAttribute)) {\n return this.setRelation({\n key,\n uid,\n attribute: newAttribute as InternalRelationAttribute,\n });\n }\n\n if (isRelation(oldAttribute) && !isRelation(newAttribute)) {\n return this.unsetRelation(oldAttribute);\n }\n\n if (isRelation(oldAttribute) && isRelation(newAttribute)) {\n const relationAttribute = newAttribute as InternalRelationAttribute;\n const oldRelationAttribute = oldAttribute as InternalRelationAttribute;\n const oldTargetAttributeName =\n oldRelationAttribute.inversedBy || oldRelationAttribute.mappedBy;\n\n const sameRelation = oldAttribute.relation === relationAttribute.relation;\n const targetAttributeHasChanged =\n oldTargetAttributeName !== relationAttribute.targetAttribute;\n\n if (!sameRelation || targetAttributeHasChanged) {\n this.unsetRelation(oldAttribute);\n }\n\n // keep extra options that were set manually on oldAttribute\n reuseUnsetPreviousProperties(relationAttribute, oldAttribute);\n\n // Handle conditions explicitly - only preserve if present and not undefined in new attribute\n const newAttributeFromInfos = newAttributes[key];\n const hasNewConditions =\n newAttributeFromInfos.conditions !== undefined &&\n newAttributeFromInfos.conditions !== null;\n\n if (oldAttribute.conditions) {\n if (hasNewConditions) {\n // Conditions are still present, keep them\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n } else {\n // Conditions were removed (undefined or null), ensure they're not preserved\n delete relationAttribute.conditions;\n }\n } else if (hasNewConditions) {\n // New conditions added\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n }\n\n if (oldRelationAttribute.inversedBy) {\n relationAttribute.dominant = true;\n } else if (oldRelationAttribute.mappedBy) {\n relationAttribute.dominant = false;\n }\n\n return this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n // add new relations\n newKeys.forEach((key) => {\n const attribute = newAttributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n // A renamed relation keeps the ownership of the attribute it was\n // renamed from (same rule as a remaining key), so the join table\n // stays with its owner and the rename migration can carry it.\n const origin = renameOrigins.get(key);\n const originAttribute =\n origin !== undefined && _.has(oldAttributes, origin)\n ? (oldAttributes[origin] as InternalRelationAttribute)\n : undefined;\n const originOwnership =\n originAttribute !== undefined &&\n isRelation(originAttribute) &&\n originAttribute.relation === relationAttribute.relation &&\n originAttribute.target === relationAttribute.target\n ? originAttribute\n : undefined;\n\n if (originOwnership?.inversedBy) {\n relationAttribute.dominant = true;\n } else if (originOwnership?.mappedBy) {\n relationAttribute.dominant = false;\n } else if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = newAttributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n contentType\n .set('kind', infos.kind || contentType.schema.kind)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'description'], infos.description)\n .set('options', {\n // Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)\n ...contentType.schema.options,\n ...infos.options,\n // A payload that does not set draftAndPublish keeps the stored value\n draftAndPublish:\n infos.draftAndPublish ??\n infos.options?.draftAndPublish ??\n contentType.schema.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n return contentType;\n },\n\n deleteContentType(this: any, uid: string) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeContentType(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeContentType(uid);\n });\n\n return this.contentTypes.get(uid).delete();\n },\n };\n}\n\n/**\n * Returns a uid from a content type infos\n *\n * @param {object} options options\n * @param {string} options.singularName content-type singularName\n * @returns {string} uid\n */\nconst createContentTypeUID = ({\n plugin,\n singularName,\n}: {\n plugin?: string;\n singularName: string;\n}): Internal.UID.ContentType =>\n `${plugin ? `plugin` : `api`}::${plugin || singularName}.${singularName}`;\n\nconst generateRelation = ({\n key,\n attribute,\n uid,\n targetAttribute = {},\n}: {\n key: string;\n attribute: InternalRelationAttribute;\n uid: string;\n targetAttribute?: Partial<InternalRelationAttribute>;\n}) => {\n const opts: any = {\n type: 'relation',\n target: uid,\n required: targetAttribute.required || undefined,\n private: targetAttribute.private || undefined,\n pluginOptions: targetAttribute.pluginOptions || undefined,\n // Preserve conditions from targetAttribute if they exist\n // This allows each side of the relation to maintain its own conditions\n ...(targetAttribute.conditions && { conditions: targetAttribute.conditions }),\n };\n\n switch (attribute.relation) {\n case 'oneToOne': {\n opts.relation = 'oneToOne';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n break;\n }\n case 'oneToMany': {\n opts.relation = 'manyToOne';\n opts.inversedBy = key;\n break;\n }\n case 'manyToOne': {\n opts.relation = 'oneToMany';\n opts.mappedBy = key;\n break;\n }\n case 'manyToMany': {\n opts.relation = 'manyToMany';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n\n break;\n }\n default:\n }\n\n // we do this just to make sure we have the same key order when writing to files\n const { type, relation, target, ...restOptions } = opts;\n\n const result = {\n type,\n relation,\n target,\n ...restOptions,\n };\n\n return result;\n};\n"],"names":["ApplicationError","errors","reuseUnsetPreviousProperties","newAttribute","oldAttribute","_","defaults","omit","getRenameOrigins","renames","originOf","Map","Array","isArray","oldName","newName","origin","get","delete","set","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","target","targetAttribute","getAttribute","targetAttributeData","setAttribute","generateRelation","unsetRelation","relationAttribute","targetAttributeName","inversedBy","mappedBy","deleteAttribute","createContentTypeAttributes","attributes","contentType","Object","keys","forEach","setAttributes","convertAttributes","isRelation","includes","relation","undefined","dominant","createContentType","infos","createContentTypeUID","dir","plugin","path","join","strapi","dirs","app","extensions","singularName","api","createSchemaHandler","modelName","filename","setUID","kind","typeKinds","COLLECTION_TYPE","collectionName","strings","nameToCollectionName","pluralName","displayName","description","options","draftAndPublish","pluginOptions","config","editContentType","oldAttributes","schema","newAttributes","omitBy","attr","isConfigurable","newKeys","difference","deletedKeys","remainingKeys","intersection","renameOrigins","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","originAttribute","originOwnership","deleteContentType","components","compo","removeContentType","ct","opts","type","required","private","restOptions","result"],"mappings":";;;;;;;;;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,MAAMC,4BAAAA,GAA+B,CACnCC,YAAAA,EACAC,YAAAA,GAAAA;AAEAC,IAAAA,kBAAAA,CAAEC,QAAQ,CACRH,YAAAA,EACAE,kBAAAA,CAAEE,IAAI,CAACH,YAAAA,EAAc;AACnB,QAAA,cAAA;AACA,QAAA,UAAA;AACA,QAAA,SAAA;AACA,QAAA,QAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA,UAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAEL,CAAA;AAEA;;;;IAKA,MAAMI,mBAAmB,CAACC,OAAAA,GAAAA;AACxB,IAAA,MAAMC,WAAW,IAAIC,GAAAA,EAAAA;AAErB,IAAA,IAAI,CAACC,KAAAA,CAAMC,OAAO,CAACJ,OAAAA,CAAAA,EAAU;QAC3B,OAAOC,QAAAA;AACT,IAAA;AAEA,IAAA,KAAK,MAAM,EAAEI,OAAO,EAAEC,OAAO,EAAE,IAAIN,OAAAA,CAAqD;AACtF,QAAA,IAAI,CAACK,OAAAA,IAAW,CAACC,OAAAA,IAAWD,YAAYC,OAAAA,EAAS;AAC/C,YAAA;AACF,QAAA;AAEA,QAAA,MAAMC,MAAAA,GAASN,QAAAA,CAASO,GAAG,CAACH,OAAAA,CAAAA,IAAYA,OAAAA;AACxCJ,QAAAA,QAAAA,CAASQ,MAAM,CAACJ,OAA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I1B,SAAAA,CAAU4B,QAAQ,EAAE;AACtB0D,oBAAAA,IAAAA,CAAKxE,QAAQ,GAAGhB,GAAAA;gBAClB,CAAA,MAAO;AACLwF,oBAAAA,IAAAA,CAAKzE,UAAU,GAAGf,GAAAA;AACpB,gBAAA;AAEA,gBAAA;AACF,YAAA;AAEF;;IAGA,MAAM,EAAEyF,IAAI,EAAE7D,QAAQ,EAAEtB,MAAM,EAAE,GAAGsF,WAAAA,EAAa,GAAGJ,IAAAA;AAEnD,IAAA,MAAMK,MAAAA,GAAS;AACbJ,QAAAA,IAAAA;AACA7D,QAAAA,QAAAA;AACAtB,QAAAA,MAAAA;AACA,QAAA,GAAGsF;AACL,KAAA;IAEA,OAAOC,MAAAA;AACT,CAAA;;;;"}
1
+ {"version":3,"file":"content-type-builder.js","sources":["../../../../server/src/services/schema-builder/content-type-builder.ts"],"sourcesContent":["import path from 'path';\nimport _ from 'lodash';\n\nimport { strings, errors } from '@strapi/utils';\nimport type { Schema, Internal } from '@strapi/types';\nimport { isRelation, isConfigurable } from '../../utils/attributes';\nimport { typeKinds } from '../constants';\nimport createSchemaHandler from './schema-handler';\nimport { CreateContentTypeInput } from '../../controllers/validation/content-type';\nimport type { InternalRelationAttribute, InternalAttribute } from './types';\n\nconst { ApplicationError } = errors;\n\nconst reuseUnsetPreviousProperties = (\n newAttribute: Schema.Attribute.AnyAttribute,\n oldAttribute: Schema.Attribute.AnyAttribute\n) => {\n _.defaults(\n newAttribute,\n _.omit(oldAttribute, [\n 'configurable',\n 'required',\n 'private',\n 'unique',\n 'pluginOptions',\n 'inversedBy',\n 'mappedBy',\n 'conditions', // Don't automatically preserve conditions\n ])\n );\n};\n\n/**\n * Maps each attribute name produced by this save's rename hops to the name it\n * had before the save, by folding the hops in order (`a -> tmp, tmp -> b`\n * gives `b -> a`).\n */\nconst getRenameOrigins = (renames: unknown): Map<string, string> => {\n const originOf = new Map<string, string>();\n\n if (!Array.isArray(renames)) {\n return originOf;\n }\n\n for (const { oldName, newName } of renames as { oldName?: string; newName?: string }[]) {\n if (!oldName || !newName || oldName === newName) {\n continue;\n }\n\n const origin = originOf.get(oldName) ?? oldName;\n originOf.delete(oldName);\n originOf.set(newName, origin);\n }\n\n return originOf;\n};\n\nexport default function createComponentBuilder() {\n return {\n setRelation(\n this: any,\n { key, uid, attribute }: { key: string; uid: string; attribute: InternalRelationAttribute }\n ) {\n if (!_.has(attribute, 'target')) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n if (!targetCT) {\n throw new ApplicationError(`Content type ${attribute.target} not found`);\n }\n\n const targetAttribute = targetCT.getAttribute(attribute.targetAttribute);\n\n if (!attribute.targetAttribute) {\n return;\n }\n\n // When generating the inverse relation, preserve existing conditions if they exist\n // If the target attribute already exists and has conditions, preserve them\n const targetAttributeData = targetAttribute || {};\n\n // If the source doesn't have conditions but the target does, preserve target's conditions\n\n targetCT.setAttribute(\n attribute.targetAttribute,\n generateRelation({ key, attribute, uid, targetAttribute: targetAttributeData })\n );\n },\n\n unsetRelation(\n this: any,\n attribute: Schema.Attribute.Relation<Schema.Attribute.RelationKind.Any>\n ) {\n if (!('target' in attribute) || !attribute.target) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n const targetAttribute = targetCT.getAttribute(targetAttributeName);\n\n if (!targetAttribute) return;\n\n return targetCT.deleteAttribute(targetAttributeName);\n },\n\n createContentTypeAttributes(\n this: any,\n uid: string,\n attributes: CreateContentTypeInput['attributes']\n ) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n // support self referencing content type relation\n Object.keys(attributes).forEach((key) => {\n const { target } = attributes[key];\n if (target === '__self__') {\n attributes[key].target = uid;\n }\n });\n\n contentType.setAttributes(this.convertAttributes(attributes));\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = attributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n return contentType;\n },\n\n /**\n * Creates a content type in memory to be written to files later on\n */\n createContentType(this: any, infos: CreateContentTypeInput) {\n // TODO:: check for unique uid / singularName & pluralName & collectionName\n\n if (infos.uid && infos.uid !== createContentTypeUID(infos)) {\n throw new ApplicationError('contentType.invalidUID');\n }\n\n const uid = infos.uid ?? createContentTypeUID(infos);\n\n if (this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.alreadyExists');\n }\n\n const dir = infos.plugin\n ? path.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName)\n : path.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);\n\n const contentType = createSchemaHandler({\n uid,\n isNew: true,\n modelName: infos.singularName,\n dir,\n filename: `schema.json`,\n });\n\n this.contentTypes.set(uid, contentType);\n\n contentType\n .set('kind', infos.kind || typeKinds.COLLECTION_TYPE)\n .set(\n 'collectionName',\n infos.collectionName || strings.nameToCollectionName(infos.pluralName)\n )\n .set('info', {\n singularName: infos.singularName,\n pluralName: infos.pluralName,\n displayName: infos.displayName,\n description: infos.description,\n })\n .set('options', {\n ...infos.options,\n draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n this.createContentTypeAttributes(uid, infos.attributes);\n\n return contentType;\n },\n\n editContentType(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n const oldAttributes = contentType.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n const newKeys = _.difference(Object.keys(newAttributes), Object.keys(oldAttributes));\n const deletedKeys = _.difference(Object.keys(oldAttributes), Object.keys(newAttributes));\n const remainingKeys = _.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));\n const renameOrigins = getRenameOrigins(infos.renames);\n\n // remove old relations\n deletedKeys.forEach((key) => {\n const attribute = oldAttributes[key];\n\n // if the old relation has a target attribute. we need to remove it in the target type\n if (isConfigurable(attribute) && isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n\n if (targetAttributeName !== null && targetAttributeName !== undefined) {\n this.unsetRelation(attribute);\n }\n }\n });\n\n remainingKeys.forEach((key) => {\n const oldAttribute = oldAttributes[key];\n const newAttribute = newAttributes[key] as InternalAttribute;\n\n if (!isRelation(oldAttribute) && isRelation(newAttribute)) {\n return this.setRelation({\n key,\n uid,\n attribute: newAttribute as InternalRelationAttribute,\n });\n }\n\n if (isRelation(oldAttribute) && !isRelation(newAttribute)) {\n return this.unsetRelation(oldAttribute);\n }\n\n if (isRelation(oldAttribute) && isRelation(newAttribute)) {\n const relationAttribute = newAttribute as InternalRelationAttribute;\n const oldRelationAttribute = oldAttribute as InternalRelationAttribute;\n const oldTargetAttributeName =\n oldRelationAttribute.inversedBy || oldRelationAttribute.mappedBy;\n\n const sameRelation = oldAttribute.relation === relationAttribute.relation;\n const targetAttributeHasChanged =\n oldTargetAttributeName !== relationAttribute.targetAttribute;\n\n if (!sameRelation || targetAttributeHasChanged) {\n this.unsetRelation(oldAttribute);\n }\n\n // keep extra options that were set manually on oldAttribute\n reuseUnsetPreviousProperties(relationAttribute, oldAttribute);\n\n // Handle conditions explicitly - only preserve if present and not undefined in new attribute\n const newAttributeFromInfos = newAttributes[key];\n const hasNewConditions =\n newAttributeFromInfos.conditions !== undefined &&\n newAttributeFromInfos.conditions !== null;\n\n if (oldAttribute.conditions) {\n if (hasNewConditions) {\n // Conditions are still present, keep them\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n } else {\n // Conditions were removed (undefined or null), ensure they're not preserved\n delete relationAttribute.conditions;\n }\n } else if (hasNewConditions) {\n // New conditions added\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n }\n\n if (oldRelationAttribute.inversedBy) {\n relationAttribute.dominant = true;\n } else if (oldRelationAttribute.mappedBy) {\n relationAttribute.dominant = false;\n }\n\n return this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n // add new relations\n newKeys.forEach((key) => {\n const attribute = newAttributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n // A renamed relation keeps the ownership of the attribute it was\n // renamed from (same rule as a remaining key), so the join table\n // stays with its owner and the rename migration can carry it.\n const origin = renameOrigins.get(key);\n const originAttribute =\n origin !== undefined && _.has(oldAttributes, origin)\n ? (oldAttributes[origin] as InternalRelationAttribute)\n : undefined;\n const originOwnership =\n originAttribute !== undefined &&\n isRelation(originAttribute) &&\n originAttribute.relation === relationAttribute.relation &&\n originAttribute.target === relationAttribute.target\n ? originAttribute\n : undefined;\n\n if (originOwnership?.inversedBy) {\n relationAttribute.dominant = true;\n } else if (originOwnership?.mappedBy) {\n relationAttribute.dominant = false;\n } else if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = newAttributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n contentType\n .set('kind', infos.kind || contentType.schema.kind)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'description'], infos.description)\n .set('options', {\n // Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)\n ...contentType.schema.options,\n ...infos.options,\n // A payload that does not set draftAndPublish keeps the stored value\n draftAndPublish:\n infos.draftAndPublish ??\n infos.options?.draftAndPublish ??\n contentType.schema.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n return contentType;\n },\n\n deleteContentType(this: any, uid: string) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeContentType(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeContentType(uid);\n });\n\n return this.contentTypes.get(uid).delete();\n },\n };\n}\n\n/**\n * Returns a uid from a content type infos\n *\n * @param {object} options options\n * @param {string} options.singularName content-type singularName\n * @returns {string} uid\n */\nconst createContentTypeUID = ({\n plugin,\n singularName,\n}: {\n plugin?: string;\n singularName: string;\n}): Internal.UID.ContentType =>\n `${plugin ? `plugin` : `api`}::${plugin || singularName}.${singularName}`;\n\nconst generateRelation = ({\n key,\n attribute,\n uid,\n targetAttribute = {},\n}: {\n key: string;\n attribute: InternalRelationAttribute;\n uid: string;\n targetAttribute?: Partial<InternalRelationAttribute>;\n}) => {\n const opts: any = {\n type: 'relation',\n target: uid,\n required: targetAttribute.required || undefined,\n private: targetAttribute.private || undefined,\n pluginOptions: targetAttribute.pluginOptions || undefined,\n // Preserve conditions from targetAttribute if they exist\n // This allows each side of the relation to maintain its own conditions\n ...(targetAttribute.conditions && { conditions: targetAttribute.conditions }),\n };\n\n switch (attribute.relation) {\n case 'oneToOne': {\n opts.relation = 'oneToOne';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n break;\n }\n case 'oneToMany': {\n opts.relation = 'manyToOne';\n opts.inversedBy = key;\n break;\n }\n case 'manyToOne': {\n opts.relation = 'oneToMany';\n opts.mappedBy = key;\n break;\n }\n case 'manyToMany': {\n opts.relation = 'manyToMany';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n\n break;\n }\n default:\n }\n\n // we do this just to make sure we have the same key order when writing to files\n const { type, relation, target, ...restOptions } = opts;\n\n const result = {\n type,\n relation,\n target,\n ...restOptions,\n };\n\n return result;\n};\n"],"names":["ApplicationError","errors","reuseUnsetPreviousProperties","newAttribute","oldAttribute","_","defaults","omit","getRenameOrigins","renames","originOf","Map","Array","isArray","oldName","newName","origin","get","delete","set","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","target","targetAttribute","getAttribute","targetAttributeData","setAttribute","generateRelation","unsetRelation","relationAttribute","targetAttributeName","inversedBy","mappedBy","deleteAttribute","createContentTypeAttributes","attributes","contentType","Object","keys","forEach","setAttributes","convertAttributes","isRelation","includes","relation","undefined","dominant","createContentType","infos","createContentTypeUID","dir","plugin","path","join","strapi","dirs","app","extensions","singularName","api","createSchemaHandler","isNew","modelName","filename","kind","typeKinds","COLLECTION_TYPE","collectionName","strings","nameToCollectionName","pluralName","displayName","description","options","draftAndPublish","pluginOptions","config","editContentType","oldAttributes","schema","newAttributes","omitBy","attr","isConfigurable","newKeys","difference","deletedKeys","remainingKeys","intersection","renameOrigins","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","originAttribute","originOwnership","deleteContentType","components","compo","removeContentType","ct","opts","type","required","private","restOptions","result"],"mappings":";;;;;;;;;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,MAAMC,4BAAAA,GAA+B,CACnCC,YAAAA,EACAC,YAAAA,GAAAA;AAEAC,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,CAAA;;;;"}
@@ -128,12 +128,14 @@ function createComponentBuilder() {
128
128
  }
129
129
  const dir = infos.plugin ? path__default.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName) : path__default.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);
130
130
  const contentType = createSchemaHandler({
131
+ uid,
132
+ isNew: true,
131
133
  modelName: infos.singularName,
132
134
  dir,
133
135
  filename: `schema.json`
134
136
  });
135
137
  this.contentTypes.set(uid, contentType);
136
- contentType.setUID(uid).set('kind', infos.kind || typeKinds.COLLECTION_TYPE).set('collectionName', infos.collectionName || strings.nameToCollectionName(infos.pluralName)).set('info', {
138
+ contentType.set('kind', infos.kind || typeKinds.COLLECTION_TYPE).set('collectionName', infos.collectionName || strings.nameToCollectionName(infos.pluralName)).set('info', {
137
139
  singularName: infos.singularName,
138
140
  pluralName: infos.pluralName,
139
141
  displayName: infos.displayName,
@@ -1 +1 @@
1
- {"version":3,"file":"content-type-builder.mjs","sources":["../../../../server/src/services/schema-builder/content-type-builder.ts"],"sourcesContent":["import path from 'path';\nimport _ from 'lodash';\n\nimport { strings, errors } from '@strapi/utils';\nimport type { Schema, Internal } from '@strapi/types';\nimport { isRelation, isConfigurable } from '../../utils/attributes';\nimport { typeKinds } from '../constants';\nimport createSchemaHandler from './schema-handler';\nimport { CreateContentTypeInput } from '../../controllers/validation/content-type';\nimport type { InternalRelationAttribute, InternalAttribute } from './types';\n\nconst { ApplicationError } = errors;\n\nconst reuseUnsetPreviousProperties = (\n newAttribute: Schema.Attribute.AnyAttribute,\n oldAttribute: Schema.Attribute.AnyAttribute\n) => {\n _.defaults(\n newAttribute,\n _.omit(oldAttribute, [\n 'configurable',\n 'required',\n 'private',\n 'unique',\n 'pluginOptions',\n 'inversedBy',\n 'mappedBy',\n 'conditions', // Don't automatically preserve conditions\n ])\n );\n};\n\n/**\n * Maps each attribute name produced by this save's rename hops to the name it\n * had before the save, by folding the hops in order (`a -> tmp, tmp -> b`\n * gives `b -> a`).\n */\nconst getRenameOrigins = (renames: unknown): Map<string, string> => {\n const originOf = new Map<string, string>();\n\n if (!Array.isArray(renames)) {\n return originOf;\n }\n\n for (const { oldName, newName } of renames as { oldName?: string; newName?: string }[]) {\n if (!oldName || !newName || oldName === newName) {\n continue;\n }\n\n const origin = originOf.get(oldName) ?? oldName;\n originOf.delete(oldName);\n originOf.set(newName, origin);\n }\n\n return originOf;\n};\n\nexport default function createComponentBuilder() {\n return {\n setRelation(\n this: any,\n { key, uid, attribute }: { key: string; uid: string; attribute: InternalRelationAttribute }\n ) {\n if (!_.has(attribute, 'target')) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n if (!targetCT) {\n throw new ApplicationError(`Content type ${attribute.target} not found`);\n }\n\n const targetAttribute = targetCT.getAttribute(attribute.targetAttribute);\n\n if (!attribute.targetAttribute) {\n return;\n }\n\n // When generating the inverse relation, preserve existing conditions if they exist\n // If the target attribute already exists and has conditions, preserve them\n const targetAttributeData = targetAttribute || {};\n\n // If the source doesn't have conditions but the target does, preserve target's conditions\n\n targetCT.setAttribute(\n attribute.targetAttribute,\n generateRelation({ key, attribute, uid, targetAttribute: targetAttributeData })\n );\n },\n\n unsetRelation(\n this: any,\n attribute: Schema.Attribute.Relation<Schema.Attribute.RelationKind.Any>\n ) {\n if (!('target' in attribute) || !attribute.target) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n const targetAttribute = targetCT.getAttribute(targetAttributeName);\n\n if (!targetAttribute) return;\n\n return targetCT.deleteAttribute(targetAttributeName);\n },\n\n createContentTypeAttributes(\n this: any,\n uid: string,\n attributes: CreateContentTypeInput['attributes']\n ) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n // support self referencing content type relation\n Object.keys(attributes).forEach((key) => {\n const { target } = attributes[key];\n if (target === '__self__') {\n attributes[key].target = uid;\n }\n });\n\n contentType.setAttributes(this.convertAttributes(attributes));\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = attributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n return contentType;\n },\n\n /**\n * Creates a content type in memory to be written to files later on\n */\n createContentType(this: any, infos: CreateContentTypeInput) {\n // TODO:: check for unique uid / singularName & pluralName & collectionName\n\n if (infos.uid && infos.uid !== createContentTypeUID(infos)) {\n throw new ApplicationError('contentType.invalidUID');\n }\n\n const uid = infos.uid ?? createContentTypeUID(infos);\n\n if (this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.alreadyExists');\n }\n\n const dir = infos.plugin\n ? path.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName)\n : path.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);\n\n const contentType = createSchemaHandler({\n modelName: infos.singularName,\n dir,\n filename: `schema.json`,\n });\n\n this.contentTypes.set(uid, contentType);\n\n contentType\n .setUID(uid)\n .set('kind', infos.kind || typeKinds.COLLECTION_TYPE)\n .set(\n 'collectionName',\n infos.collectionName || strings.nameToCollectionName(infos.pluralName)\n )\n .set('info', {\n singularName: infos.singularName,\n pluralName: infos.pluralName,\n displayName: infos.displayName,\n description: infos.description,\n })\n .set('options', {\n ...infos.options,\n draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n this.createContentTypeAttributes(uid, infos.attributes);\n\n return contentType;\n },\n\n editContentType(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n const oldAttributes = contentType.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n const newKeys = _.difference(Object.keys(newAttributes), Object.keys(oldAttributes));\n const deletedKeys = _.difference(Object.keys(oldAttributes), Object.keys(newAttributes));\n const remainingKeys = _.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));\n const renameOrigins = getRenameOrigins(infos.renames);\n\n // remove old relations\n deletedKeys.forEach((key) => {\n const attribute = oldAttributes[key];\n\n // if the old relation has a target attribute. we need to remove it in the target type\n if (isConfigurable(attribute) && isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n\n if (targetAttributeName !== null && targetAttributeName !== undefined) {\n this.unsetRelation(attribute);\n }\n }\n });\n\n remainingKeys.forEach((key) => {\n const oldAttribute = oldAttributes[key];\n const newAttribute = newAttributes[key] as InternalAttribute;\n\n if (!isRelation(oldAttribute) && isRelation(newAttribute)) {\n return this.setRelation({\n key,\n uid,\n attribute: newAttribute as InternalRelationAttribute,\n });\n }\n\n if (isRelation(oldAttribute) && !isRelation(newAttribute)) {\n return this.unsetRelation(oldAttribute);\n }\n\n if (isRelation(oldAttribute) && isRelation(newAttribute)) {\n const relationAttribute = newAttribute as InternalRelationAttribute;\n const oldRelationAttribute = oldAttribute as InternalRelationAttribute;\n const oldTargetAttributeName =\n oldRelationAttribute.inversedBy || oldRelationAttribute.mappedBy;\n\n const sameRelation = oldAttribute.relation === relationAttribute.relation;\n const targetAttributeHasChanged =\n oldTargetAttributeName !== relationAttribute.targetAttribute;\n\n if (!sameRelation || targetAttributeHasChanged) {\n this.unsetRelation(oldAttribute);\n }\n\n // keep extra options that were set manually on oldAttribute\n reuseUnsetPreviousProperties(relationAttribute, oldAttribute);\n\n // Handle conditions explicitly - only preserve if present and not undefined in new attribute\n const newAttributeFromInfos = newAttributes[key];\n const hasNewConditions =\n newAttributeFromInfos.conditions !== undefined &&\n newAttributeFromInfos.conditions !== null;\n\n if (oldAttribute.conditions) {\n if (hasNewConditions) {\n // Conditions are still present, keep them\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n } else {\n // Conditions were removed (undefined or null), ensure they're not preserved\n delete relationAttribute.conditions;\n }\n } else if (hasNewConditions) {\n // New conditions added\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n }\n\n if (oldRelationAttribute.inversedBy) {\n relationAttribute.dominant = true;\n } else if (oldRelationAttribute.mappedBy) {\n relationAttribute.dominant = false;\n }\n\n return this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n // add new relations\n newKeys.forEach((key) => {\n const attribute = newAttributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n // A renamed relation keeps the ownership of the attribute it was\n // renamed from (same rule as a remaining key), so the join table\n // stays with its owner and the rename migration can carry it.\n const origin = renameOrigins.get(key);\n const originAttribute =\n origin !== undefined && _.has(oldAttributes, origin)\n ? (oldAttributes[origin] as InternalRelationAttribute)\n : undefined;\n const originOwnership =\n originAttribute !== undefined &&\n isRelation(originAttribute) &&\n originAttribute.relation === relationAttribute.relation &&\n originAttribute.target === relationAttribute.target\n ? originAttribute\n : undefined;\n\n if (originOwnership?.inversedBy) {\n relationAttribute.dominant = true;\n } else if (originOwnership?.mappedBy) {\n relationAttribute.dominant = false;\n } else if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = newAttributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n contentType\n .set('kind', infos.kind || contentType.schema.kind)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'description'], infos.description)\n .set('options', {\n // Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)\n ...contentType.schema.options,\n ...infos.options,\n // A payload that does not set draftAndPublish keeps the stored value\n draftAndPublish:\n infos.draftAndPublish ??\n infos.options?.draftAndPublish ??\n contentType.schema.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n return contentType;\n },\n\n deleteContentType(this: any, uid: string) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeContentType(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeContentType(uid);\n });\n\n return this.contentTypes.get(uid).delete();\n },\n };\n}\n\n/**\n * Returns a uid from a content type infos\n *\n * @param {object} options options\n * @param {string} options.singularName content-type singularName\n * @returns {string} uid\n */\nconst createContentTypeUID = ({\n plugin,\n singularName,\n}: {\n plugin?: string;\n singularName: string;\n}): Internal.UID.ContentType =>\n `${plugin ? `plugin` : `api`}::${plugin || singularName}.${singularName}`;\n\nconst generateRelation = ({\n key,\n attribute,\n uid,\n targetAttribute = {},\n}: {\n key: string;\n attribute: InternalRelationAttribute;\n uid: string;\n targetAttribute?: Partial<InternalRelationAttribute>;\n}) => {\n const opts: any = {\n type: 'relation',\n target: uid,\n required: targetAttribute.required || undefined,\n private: targetAttribute.private || undefined,\n pluginOptions: targetAttribute.pluginOptions || undefined,\n // Preserve conditions from targetAttribute if they exist\n // This allows each side of the relation to maintain its own conditions\n ...(targetAttribute.conditions && { conditions: targetAttribute.conditions }),\n };\n\n switch (attribute.relation) {\n case 'oneToOne': {\n opts.relation = 'oneToOne';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n break;\n }\n case 'oneToMany': {\n opts.relation = 'manyToOne';\n opts.inversedBy = key;\n break;\n }\n case 'manyToOne': {\n opts.relation = 'oneToMany';\n opts.mappedBy = key;\n break;\n }\n case 'manyToMany': {\n opts.relation = 'manyToMany';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n\n break;\n }\n default:\n }\n\n // we do this just to make sure we have the same key order when writing to files\n const { type, relation, target, ...restOptions } = opts;\n\n const result = {\n type,\n relation,\n target,\n ...restOptions,\n };\n\n return result;\n};\n"],"names":["ApplicationError","errors","reuseUnsetPreviousProperties","newAttribute","oldAttribute","_","defaults","omit","getRenameOrigins","renames","originOf","Map","Array","isArray","oldName","newName","origin","get","delete","set","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","target","targetAttribute","getAttribute","targetAttributeData","setAttribute","generateRelation","unsetRelation","relationAttribute","targetAttributeName","inversedBy","mappedBy","deleteAttribute","createContentTypeAttributes","attributes","contentType","Object","keys","forEach","setAttributes","convertAttributes","isRelation","includes","relation","undefined","dominant","createContentType","infos","createContentTypeUID","dir","plugin","path","join","strapi","dirs","app","extensions","singularName","api","createSchemaHandler","modelName","filename","setUID","kind","typeKinds","COLLECTION_TYPE","collectionName","strings","nameToCollectionName","pluralName","displayName","description","options","draftAndPublish","pluginOptions","config","editContentType","oldAttributes","schema","newAttributes","omitBy","attr","isConfigurable","newKeys","difference","deletedKeys","remainingKeys","intersection","renameOrigins","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","originAttribute","originOwnership","deleteContentType","components","compo","removeContentType","ct","opts","type","required","private","restOptions","result"],"mappings":";;;;;;;AAWA,MAAM,EAAEA,gB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QAAAA,MAAAA;AACA,QAAA,GAAGsF;AACL,KAAA;IAEA,OAAOC,MAAAA;AACT,CAAA;;;;"}
1
+ {"version":3,"file":"content-type-builder.mjs","sources":["../../../../server/src/services/schema-builder/content-type-builder.ts"],"sourcesContent":["import path from 'path';\nimport _ from 'lodash';\n\nimport { strings, errors } from '@strapi/utils';\nimport type { Schema, Internal } from '@strapi/types';\nimport { isRelation, isConfigurable } from '../../utils/attributes';\nimport { typeKinds } from '../constants';\nimport createSchemaHandler from './schema-handler';\nimport { CreateContentTypeInput } from '../../controllers/validation/content-type';\nimport type { InternalRelationAttribute, InternalAttribute } from './types';\n\nconst { ApplicationError } = errors;\n\nconst reuseUnsetPreviousProperties = (\n newAttribute: Schema.Attribute.AnyAttribute,\n oldAttribute: Schema.Attribute.AnyAttribute\n) => {\n _.defaults(\n newAttribute,\n _.omit(oldAttribute, [\n 'configurable',\n 'required',\n 'private',\n 'unique',\n 'pluginOptions',\n 'inversedBy',\n 'mappedBy',\n 'conditions', // Don't automatically preserve conditions\n ])\n );\n};\n\n/**\n * Maps each attribute name produced by this save's rename hops to the name it\n * had before the save, by folding the hops in order (`a -> tmp, tmp -> b`\n * gives `b -> a`).\n */\nconst getRenameOrigins = (renames: unknown): Map<string, string> => {\n const originOf = new Map<string, string>();\n\n if (!Array.isArray(renames)) {\n return originOf;\n }\n\n for (const { oldName, newName } of renames as { oldName?: string; newName?: string }[]) {\n if (!oldName || !newName || oldName === newName) {\n continue;\n }\n\n const origin = originOf.get(oldName) ?? oldName;\n originOf.delete(oldName);\n originOf.set(newName, origin);\n }\n\n return originOf;\n};\n\nexport default function createComponentBuilder() {\n return {\n setRelation(\n this: any,\n { key, uid, attribute }: { key: string; uid: string; attribute: InternalRelationAttribute }\n ) {\n if (!_.has(attribute, 'target')) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n if (!targetCT) {\n throw new ApplicationError(`Content type ${attribute.target} not found`);\n }\n\n const targetAttribute = targetCT.getAttribute(attribute.targetAttribute);\n\n if (!attribute.targetAttribute) {\n return;\n }\n\n // When generating the inverse relation, preserve existing conditions if they exist\n // If the target attribute already exists and has conditions, preserve them\n const targetAttributeData = targetAttribute || {};\n\n // If the source doesn't have conditions but the target does, preserve target's conditions\n\n targetCT.setAttribute(\n attribute.targetAttribute,\n generateRelation({ key, attribute, uid, targetAttribute: targetAttributeData })\n );\n },\n\n unsetRelation(\n this: any,\n attribute: Schema.Attribute.Relation<Schema.Attribute.RelationKind.Any>\n ) {\n if (!('target' in attribute) || !attribute.target) {\n return;\n }\n\n const targetCT = this.contentTypes.get(attribute.target);\n\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n const targetAttribute = targetCT.getAttribute(targetAttributeName);\n\n if (!targetAttribute) return;\n\n return targetCT.deleteAttribute(targetAttributeName);\n },\n\n createContentTypeAttributes(\n this: any,\n uid: string,\n attributes: CreateContentTypeInput['attributes']\n ) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n // support self referencing content type relation\n Object.keys(attributes).forEach((key) => {\n const { target } = attributes[key];\n if (target === '__self__') {\n attributes[key].target = uid;\n }\n });\n\n contentType.setAttributes(this.convertAttributes(attributes));\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = attributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n return contentType;\n },\n\n /**\n * Creates a content type in memory to be written to files later on\n */\n createContentType(this: any, infos: CreateContentTypeInput) {\n // TODO:: check for unique uid / singularName & pluralName & collectionName\n\n if (infos.uid && infos.uid !== createContentTypeUID(infos)) {\n throw new ApplicationError('contentType.invalidUID');\n }\n\n const uid = infos.uid ?? createContentTypeUID(infos);\n\n if (this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.alreadyExists');\n }\n\n const dir = infos.plugin\n ? path.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName)\n : path.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);\n\n const contentType = createSchemaHandler({\n uid,\n isNew: true,\n modelName: infos.singularName,\n dir,\n filename: `schema.json`,\n });\n\n this.contentTypes.set(uid, contentType);\n\n contentType\n .set('kind', infos.kind || typeKinds.COLLECTION_TYPE)\n .set(\n 'collectionName',\n infos.collectionName || strings.nameToCollectionName(infos.pluralName)\n )\n .set('info', {\n singularName: infos.singularName,\n pluralName: infos.pluralName,\n displayName: infos.displayName,\n description: infos.description,\n })\n .set('options', {\n ...infos.options,\n draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n this.createContentTypeAttributes(uid, infos.attributes);\n\n return contentType;\n },\n\n editContentType(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const contentType = this.contentTypes.get(uid);\n\n const oldAttributes = contentType.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n const newKeys = _.difference(Object.keys(newAttributes), Object.keys(oldAttributes));\n const deletedKeys = _.difference(Object.keys(oldAttributes), Object.keys(newAttributes));\n const remainingKeys = _.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));\n const renameOrigins = getRenameOrigins(infos.renames);\n\n // remove old relations\n deletedKeys.forEach((key) => {\n const attribute = oldAttributes[key];\n\n // if the old relation has a target attribute. we need to remove it in the target type\n if (isConfigurable(attribute) && isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n const targetAttributeName = relationAttribute.inversedBy || relationAttribute.mappedBy;\n\n if (targetAttributeName !== null && targetAttributeName !== undefined) {\n this.unsetRelation(attribute);\n }\n }\n });\n\n remainingKeys.forEach((key) => {\n const oldAttribute = oldAttributes[key];\n const newAttribute = newAttributes[key] as InternalAttribute;\n\n if (!isRelation(oldAttribute) && isRelation(newAttribute)) {\n return this.setRelation({\n key,\n uid,\n attribute: newAttribute as InternalRelationAttribute,\n });\n }\n\n if (isRelation(oldAttribute) && !isRelation(newAttribute)) {\n return this.unsetRelation(oldAttribute);\n }\n\n if (isRelation(oldAttribute) && isRelation(newAttribute)) {\n const relationAttribute = newAttribute as InternalRelationAttribute;\n const oldRelationAttribute = oldAttribute as InternalRelationAttribute;\n const oldTargetAttributeName =\n oldRelationAttribute.inversedBy || oldRelationAttribute.mappedBy;\n\n const sameRelation = oldAttribute.relation === relationAttribute.relation;\n const targetAttributeHasChanged =\n oldTargetAttributeName !== relationAttribute.targetAttribute;\n\n if (!sameRelation || targetAttributeHasChanged) {\n this.unsetRelation(oldAttribute);\n }\n\n // keep extra options that were set manually on oldAttribute\n reuseUnsetPreviousProperties(relationAttribute, oldAttribute);\n\n // Handle conditions explicitly - only preserve if present and not undefined in new attribute\n const newAttributeFromInfos = newAttributes[key];\n const hasNewConditions =\n newAttributeFromInfos.conditions !== undefined &&\n newAttributeFromInfos.conditions !== null;\n\n if (oldAttribute.conditions) {\n if (hasNewConditions) {\n // Conditions are still present, keep them\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n } else {\n // Conditions were removed (undefined or null), ensure they're not preserved\n delete relationAttribute.conditions;\n }\n } else if (hasNewConditions) {\n // New conditions added\n relationAttribute.conditions = newAttributeFromInfos.conditions;\n }\n\n if (oldRelationAttribute.inversedBy) {\n relationAttribute.dominant = true;\n } else if (oldRelationAttribute.mappedBy) {\n relationAttribute.dominant = false;\n }\n\n return this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n // add new relations\n newKeys.forEach((key) => {\n const attribute = newAttributes[key] as InternalAttribute;\n\n if (isRelation(attribute)) {\n const relationAttribute = attribute as InternalRelationAttribute;\n if (['manyToMany', 'oneToOne'].includes(relationAttribute.relation)) {\n // A renamed relation keeps the ownership of the attribute it was\n // renamed from (same rule as a remaining key), so the join table\n // stays with its owner and the rename migration can carry it.\n const origin = renameOrigins.get(key);\n const originAttribute =\n origin !== undefined && _.has(oldAttributes, origin)\n ? (oldAttributes[origin] as InternalRelationAttribute)\n : undefined;\n const originOwnership =\n originAttribute !== undefined &&\n isRelation(originAttribute) &&\n originAttribute.relation === relationAttribute.relation &&\n originAttribute.target === relationAttribute.target\n ? originAttribute\n : undefined;\n\n if (originOwnership?.inversedBy) {\n relationAttribute.dominant = true;\n } else if (originOwnership?.mappedBy) {\n relationAttribute.dominant = false;\n } else if (\n relationAttribute.target === uid &&\n relationAttribute.targetAttribute !== undefined\n ) {\n // self referencing relation\n const targetAttribute = newAttributes[\n relationAttribute.targetAttribute\n ] as InternalRelationAttribute;\n\n if (targetAttribute.dominant === undefined) {\n relationAttribute.dominant = true;\n } else {\n relationAttribute.dominant = false;\n }\n } else {\n relationAttribute.dominant = true;\n }\n }\n\n this.setRelation({\n key,\n uid,\n attribute: relationAttribute,\n });\n }\n });\n\n contentType\n .set('kind', infos.kind || contentType.schema.kind)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'description'], infos.description)\n .set('options', {\n // Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)\n ...contentType.schema.options,\n ...infos.options,\n // A payload that does not set draftAndPublish keeps the stored value\n draftAndPublish:\n infos.draftAndPublish ??\n infos.options?.draftAndPublish ??\n contentType.schema.options?.draftAndPublish,\n })\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n return contentType;\n },\n\n deleteContentType(this: any, uid: string) {\n if (!this.contentTypes.has(uid)) {\n throw new ApplicationError('contentType.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeContentType(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeContentType(uid);\n });\n\n return this.contentTypes.get(uid).delete();\n },\n };\n}\n\n/**\n * Returns a uid from a content type infos\n *\n * @param {object} options options\n * @param {string} options.singularName content-type singularName\n * @returns {string} uid\n */\nconst createContentTypeUID = ({\n plugin,\n singularName,\n}: {\n plugin?: string;\n singularName: string;\n}): Internal.UID.ContentType =>\n `${plugin ? `plugin` : `api`}::${plugin || singularName}.${singularName}`;\n\nconst generateRelation = ({\n key,\n attribute,\n uid,\n targetAttribute = {},\n}: {\n key: string;\n attribute: InternalRelationAttribute;\n uid: string;\n targetAttribute?: Partial<InternalRelationAttribute>;\n}) => {\n const opts: any = {\n type: 'relation',\n target: uid,\n required: targetAttribute.required || undefined,\n private: targetAttribute.private || undefined,\n pluginOptions: targetAttribute.pluginOptions || undefined,\n // Preserve conditions from targetAttribute if they exist\n // This allows each side of the relation to maintain its own conditions\n ...(targetAttribute.conditions && { conditions: targetAttribute.conditions }),\n };\n\n switch (attribute.relation) {\n case 'oneToOne': {\n opts.relation = 'oneToOne';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n break;\n }\n case 'oneToMany': {\n opts.relation = 'manyToOne';\n opts.inversedBy = key;\n break;\n }\n case 'manyToOne': {\n opts.relation = 'oneToMany';\n opts.mappedBy = key;\n break;\n }\n case 'manyToMany': {\n opts.relation = 'manyToMany';\n\n if (attribute.dominant) {\n opts.mappedBy = key;\n } else {\n opts.inversedBy = key;\n }\n\n break;\n }\n default:\n }\n\n // we do this just to make sure we have the same key order when writing to files\n const { type, relation, target, ...restOptions } = opts;\n\n const result = {\n type,\n relation,\n target,\n ...restOptions,\n };\n\n return result;\n};\n"],"names":["ApplicationError","errors","reuseUnsetPreviousProperties","newAttribute","oldAttribute","_","defaults","omit","getRenameOrigins","renames","originOf","Map","Array","isArray","oldName","newName","origin","get","delete","set","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","target","targetAttribute","getAttribute","targetAttributeData","setAttribute","generateRelation","unsetRelation","relationAttribute","targetAttributeName","inversedBy","mappedBy","deleteAttribute","createContentTypeAttributes","attributes","contentType","Object","keys","forEach","setAttributes","convertAttributes","isRelation","includes","relation","undefined","dominant","createContentType","infos","createContentTypeUID","dir","plugin","path","join","strapi","dirs","app","extensions","singularName","api","createSchemaHandler","isNew","modelName","filename","kind","typeKinds","COLLECTION_TYPE","collectionName","strings","nameToCollectionName","pluralName","displayName","description","options","draftAndPublish","pluginOptions","config","editContentType","oldAttributes","schema","newAttributes","omitBy","attr","isConfigurable","newKeys","difference","deletedKeys","remainingKeys","intersection","renameOrigins","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","originAttribute","originOwnership","deleteContentType","components","compo","removeContentType","ct","opts","type","required","private","restOptions","result"],"mappings":";;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,4BAAAA,GAA+B,CACnCC,YAAAA,EACAC,YAAAA,GAAAA;AAEAC,IAAAA,CAAAA,CAAEC,QAAQ,CACRH,YAAAA,EACAE,CAAAA,CAAEE,IAAI,CAACH,YAAAA,EAAc;AACnB,QAAA,cAAA;AACA,QAAA,UAAA;AACA,QAAA,SAAA;AACA,QAAA,QAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA,UAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAEL,CAAA;AAEA;;;;IAKA,MAAMI,mBAAmB,CAACC,OAAAA,GAAAA;AACxB,IAAA,MAAMC,WAAW,IAAIC,GAAAA,EAAAA;AAErB,IAAA,IAAI,CAACC,KAAAA,CAAMC,OAAO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5D,QAAQ,GAAG,WAAA;AAChB4D,gBAAAA,IAAAA,CAAKzE,UAAU,GAAGf,GAAAA;AAClB,gBAAA;AACF,YAAA;QACA,KAAK,WAAA;AAAa,YAAA;AAChBwF,gBAAAA,IAAAA,CAAK5D,QAAQ,GAAG,WAAA;AAChB4D,gBAAAA,IAAAA,CAAKxE,QAAQ,GAAGhB,GAAAA;AAChB,gBAAA;AACF,YAAA;QACA,KAAK,YAAA;AAAc,YAAA;AACjBwF,gBAAAA,IAAAA,CAAK5D,QAAQ,GAAG,YAAA;gBAEhB,IAAI1B,SAAAA,CAAU4B,QAAQ,EAAE;AACtB0D,oBAAAA,IAAAA,CAAKxE,QAAQ,GAAGhB,GAAAA;gBAClB,CAAA,MAAO;AACLwF,oBAAAA,IAAAA,CAAKzE,UAAU,GAAGf,GAAAA;AACpB,gBAAA;AAEA,gBAAA;AACF,YAAA;AAEF;;IAGA,MAAM,EAAEyF,IAAI,EAAE7D,QAAQ,EAAEtB,MAAM,EAAE,GAAGsF,WAAAA,EAAa,GAAGJ,IAAAA;AAEnD,IAAA,MAAMK,MAAAA,GAAS;AACbJ,QAAAA,IAAAA;AACA7D,QAAAA,QAAAA;AACAtB,QAAAA,MAAAA;AACA,QAAA,GAAGsF;AACL,KAAA;IAEA,OAAOC,MAAAA;AACT,CAAA;;;;"}
@@ -6,6 +6,7 @@ var utils = require('@strapi/utils');
6
6
  var schemaHandler = require('./schema-handler.js');
7
7
  var componentBuilder = require('./component-builder.js');
8
8
  var contentTypeBuilder = require('./content-type-builder.js');
9
+ var renameComponentUids = require('./rename-component-uids.js');
9
10
 
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
12
 
@@ -123,15 +124,25 @@ function createSchemaBuilder({ components, contentTypes }) {
123
124
  ...componentBuilder(),
124
125
  ...contentTypeBuilder(),
125
126
  /**
126
- * Write all type to files
127
- * @returns boolean true if all files have been written correctly, false if an error occurred
128
- * @throws ApplicationError if an error occurred and rollback failed
129
- */ writeFiles () {
127
+ * Write all type to files, then rewrite the database rows that store a renamed
128
+ * component uid (see `renameComponentRows`).
129
+ *
130
+ * Pass `{ renameComponentRows: false }` to only write the files. The caller must then
131
+ * call `renameComponentRows` itself, before the reload, and roll the files back if it
132
+ * throws. Do that when a later step must succeed together with the rows: run that
133
+ * step through `renameComponentRows({ beforeCommit })`, so that its failure rolls the
134
+ * rows back too.
135
+ *
136
+ * @returns boolean true if all files have been written correctly, false if an error
137
+ * occurred while writing them (the files are rolled back)
138
+ * @throws ApplicationError if the row rewrite failed (the files are rolled back) or if
139
+ * a rollback failed
140
+ */ async writeFiles ({ renameComponentRows = true } = {}) {
130
141
  const schemas = [
131
142
  ...Array.from(tmpComponents.values()),
132
143
  ...Array.from(tmpContentTypes.values())
133
144
  ];
134
- return Promise.all(schemas.map((schema)=>schema.flush())).then(()=>true).catch((error)=>{
145
+ const written = await Promise.all(schemas.map((schema)=>schema.flush())).then(()=>true).catch((error)=>{
135
146
  strapi.log.error('Error writing schema files');
136
147
  strapi.log.error(error);
137
148
  return this.rollback().then(()=>false);
@@ -140,6 +151,47 @@ function createSchemaBuilder({ components, contentTypes }) {
140
151
  strapi.log.error(error);
141
152
  throw new utils.errors.ApplicationError('Invalid schema edition');
142
153
  });
154
+ if (!written || !renameComponentRows) {
155
+ return written;
156
+ }
157
+ try {
158
+ await this.renameComponentRows();
159
+ } catch (error) {
160
+ // The transaction already restored the rows. Restore the files too, or the next
161
+ // reload would load the new uids against rows still holding the old ones.
162
+ strapi.log.error('Error rewriting the rows of the renamed components');
163
+ strapi.log.error(error);
164
+ try {
165
+ await this.rollback();
166
+ } catch (rollbackError) {
167
+ strapi.log.error('Error rolling back schema files. You might need to fix your files manually');
168
+ strapi.log.error(rollbackError);
169
+ }
170
+ throw new utils.errors.ApplicationError('Invalid schema edition');
171
+ }
172
+ return true;
173
+ },
174
+ /**
175
+ * A component uid change (category move or rename) is also stored in the database:
176
+ * as `component_type` in the `*_cmps` join tables and as the type column of the
177
+ * polymorphic join tables (e.g. media in `files_related_mph`). Rewrites those rows in
178
+ * one transaction. Must run while the running process still holds the pre-rename
179
+ * metadata that locates them, i.e. before the reload.
180
+ *
181
+ * `beforeCommit` runs inside that transaction, after the rewrite and before the
182
+ * commit (also when no uid changed). If it rejects, the rows are rolled back. It must
183
+ * not use the database (see `renameComponentUIDs`).
184
+ *
185
+ * @throws if the rewrite or `beforeCommit` failed; the transaction has then restored
186
+ * the rows
187
+ */ async renameComponentRows ({ beforeCommit } = {}) {
188
+ const componentUIDRenames = Array.from(tmpComponents.values()).filter((component)=>component.initialUID && component.uid !== component.initialUID).map((component)=>({
189
+ oldUID: component.initialUID,
190
+ newUID: component.uid
191
+ }));
192
+ await renameComponentUids.renameComponentUIDs(strapi.db, componentUIDRenames, {
193
+ beforeCommit
194
+ });
143
195
  },
144
196
  /**
145
197
  * rollback all files
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../server/src/services/schema-builder/index.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\n\nimport { errors } from '@strapi/utils';\nimport createSchemaHandler from './schema-handler';\nimport createComponentBuilder from './component-builder';\nimport createContentTypeBuilder from './content-type-builder';\n\n/**\n * Creates a content type schema builder instance\n */\nexport default function createBuilder() {\n const components = Object.values(strapi.components).map((componentInput) => ({\n category: componentInput.category,\n modelName: componentInput.modelName,\n uid: componentInput.uid,\n filename: componentInput.__filename__,\n dir: join(strapi.dirs.app.components, componentInput.category),\n schema: componentInput.__schema__,\n config: componentInput.config,\n }));\n\n const contentTypes = Object.values<any>(strapi.contentTypes).map((contentTypeInput) => {\n const dir = contentTypeInput.plugin\n ? join(\n strapi.dirs.app.extensions,\n contentTypeInput.plugin,\n 'content-types',\n contentTypeInput.info.singularName\n )\n : join(\n strapi.dirs.app.api,\n contentTypeInput.apiName,\n 'content-types',\n contentTypeInput.info.singularName\n );\n\n return {\n modelName: contentTypeInput.modelName,\n plugin: contentTypeInput.plugin,\n uid: contentTypeInput.uid,\n filename: 'schema.json',\n dir,\n schema: contentTypeInput.__schema__,\n config: contentTypeInput.config,\n };\n });\n\n return createSchemaBuilder({\n components,\n contentTypes,\n });\n}\n\ntype SchemaBuilderOptions = {\n components: any;\n contentTypes: any;\n};\n\nfunction createSchemaBuilder({ components, contentTypes }: SchemaBuilderOptions) {\n const tmpComponents = new Map();\n const tmpContentTypes = new Map();\n\n // init temporary ContentTypes\n Object.keys(contentTypes).forEach((key) => {\n tmpContentTypes.set(contentTypes[key].uid, createSchemaHandler(contentTypes[key]));\n });\n\n // init temporary components\n Object.keys(components).forEach((key) => {\n tmpComponents.set(components[key].uid, createSchemaHandler(components[key]));\n });\n\n return {\n get components() {\n return tmpComponents;\n },\n get contentTypes() {\n return tmpContentTypes;\n },\n\n /**\n * Convert Attributes received from the API to the right syntax\n */\n convertAttributes(attributes: any) {\n return Object.keys(attributes).reduce(\n (acc, key) => {\n acc[key] = this.convertAttribute(attributes[key]);\n return acc;\n },\n {} as Record<string, unknown>\n );\n },\n\n convertAttribute(attribute: any) {\n const { configurable, private: isPrivate, conditions } = attribute;\n\n const baseProperties = {\n private: isPrivate === true ? true : undefined,\n configurable: configurable === false ? false : undefined,\n // IMPORTANT: Preserve conditions only if they exist and are not undefined/null\n ...(conditions !== undefined && conditions !== null && { conditions }),\n };\n\n if (attribute.type === 'relation') {\n const { target, relation, targetAttribute, dominant, ...restOfProperties } = attribute;\n\n const attr = {\n type: 'relation',\n relation,\n target,\n ...restOfProperties,\n ...baseProperties,\n };\n\n // TODO: uncomment this when we pre-create empty types and targets exists if we create multiple types at once\n // if (target && !this.contentTypes.has(target)) {\n // throw new errors.ApplicationError(`target: ${target} does not exist`);\n // }\n\n if (_.isNil(targetAttribute)) {\n return attr;\n }\n\n if (['oneToOne', 'manyToMany'].includes(relation) && dominant === true) {\n attr.inversedBy = targetAttribute;\n } else if (['oneToOne', 'manyToMany'].includes(relation) && dominant === false) {\n attr.mappedBy = targetAttribute;\n } else if (['oneToOne', 'manyToOne', 'manyToMany'].includes(relation)) {\n attr.inversedBy = targetAttribute;\n } else if (['oneToMany'].includes(relation)) {\n attr.mappedBy = targetAttribute;\n }\n\n return attr;\n }\n\n return {\n ...attribute,\n ...baseProperties,\n };\n },\n\n ...createComponentBuilder(),\n ...createContentTypeBuilder(),\n\n /**\n * Write all type to files\n * @returns boolean true if all files have been written correctly, false if an error occurred\n * @throws ApplicationError if an error occurred and rollback failed\n */\n writeFiles() {\n const schemas = [\n ...Array.from(tmpComponents.values()),\n ...Array.from(tmpContentTypes.values()),\n ];\n\n return Promise.all(schemas.map((schema) => schema.flush()))\n .then(() => true)\n .catch((error) => {\n strapi.log.error('Error writing schema files');\n strapi.log.error(error);\n return this.rollback().then(() => false);\n })\n .catch((error) => {\n strapi.log.error(\n 'Error rolling back schema files. You might need to fix your files manually'\n );\n strapi.log.error(error);\n\n throw new errors.ApplicationError('Invalid schema edition');\n });\n },\n\n /**\n * rollback all files\n */\n rollback() {\n return Promise.all(\n [...Array.from(tmpComponents.values()), ...Array.from(tmpContentTypes.values())].map(\n (schema) => schema.rollback()\n )\n );\n },\n };\n}\n"],"names":["createBuilder","components","Object","values","strapi","map","componentInput","category","modelName","uid","filename","__filename__","dir","join","dirs","app","schema","__schema__","config","contentTypes","contentTypeInput","plugin","extensions","info","singularName","api","apiName","createSchemaBuilder","tmpComponents","Map","tmpContentTypes","keys","forEach","key","set","createSchemaHandler","convertAttributes","attributes","reduce","acc","convertAttribute","attribute","configurable","private","isPrivate","conditions","baseProperties","undefined","type","target","relation","targetAttribute","dominant","restOfProperties","attr","_","isNil","includes","inversedBy","mappedBy","createComponentBuilder","createContentTypeBuilder","writeFiles","schemas","Array","from","Promise","all","flush","then","catch","error","log","rollback","errors","ApplicationError"],"mappings":";;;;;;;;;;;;;AAQA;;AAEC,IACc,SAASA,aAAAA,GAAAA;IACtB,MAAMC,UAAAA,GAAaC,MAAAA,CAAOC,MAAM,CAACC,MAAAA,CAAOH,UAAU,CAAA,CAAEI,GAAG,CA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AAK,CAACA,KAAAA,CAAAA;gBAEjB,MAAM,IAAIG,YAAAA,CAAOC,gBAAgB,CAAC,wBAAA,CAAA;AACpC,YAAA,CAAA,CAAA;AACJ,QAAA,CAAA;AAEA;;QAGAF,QAAAA,CAAAA,GAAAA;YACE,OAAOP,OAAAA,CAAQC,GAAG,CAChB;mBAAIH,KAAAA,CAAMC,IAAI,CAACrC,aAAAA,CAAczB,MAAM,EAAA,CAAA;mBAAQ6D,KAAAA,CAAMC,IAAI,CAACnC,eAAAA,CAAgB3B,MAAM,EAAA;AAAI,aAAA,CAACE,GAAG,CAClF,CAACW,MAAAA,GAAWA,OAAOyD,QAAQ,EAAA,CAAA,CAAA;AAGjC,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../server/src/services/schema-builder/index.ts"],"sourcesContent":["import { join } from 'path';\nimport _ from 'lodash';\nimport type { Internal } from '@strapi/types';\n\nimport { errors } from '@strapi/utils';\nimport createSchemaHandler, { type SchemaHandler } from './schema-handler';\nimport createComponentBuilder from './component-builder';\nimport createContentTypeBuilder from './content-type-builder';\nimport { renameComponentUIDs, type RenameComponentUIDsOptions } from './rename-component-uids';\n\n/**\n * Creates a content type schema builder instance\n */\nexport default function createBuilder() {\n const components = Object.values(strapi.components).map((componentInput) => ({\n category: componentInput.category,\n modelName: componentInput.modelName,\n uid: componentInput.uid,\n filename: componentInput.__filename__,\n dir: join(strapi.dirs.app.components, componentInput.category),\n schema: componentInput.__schema__,\n config: componentInput.config,\n }));\n\n const contentTypes = Object.values<any>(strapi.contentTypes).map((contentTypeInput) => {\n const dir = contentTypeInput.plugin\n ? join(\n strapi.dirs.app.extensions,\n contentTypeInput.plugin,\n 'content-types',\n contentTypeInput.info.singularName\n )\n : join(\n strapi.dirs.app.api,\n contentTypeInput.apiName,\n 'content-types',\n contentTypeInput.info.singularName\n );\n\n return {\n modelName: contentTypeInput.modelName,\n plugin: contentTypeInput.plugin,\n uid: contentTypeInput.uid,\n filename: 'schema.json',\n dir,\n schema: contentTypeInput.__schema__,\n config: contentTypeInput.config,\n };\n });\n\n return createSchemaBuilder({\n components,\n contentTypes,\n });\n}\n\ntype SchemaBuilderOptions = {\n components: any;\n contentTypes: any;\n};\n\nfunction createSchemaBuilder({ components, contentTypes }: SchemaBuilderOptions) {\n const tmpComponents = new Map<Internal.UID.Component, SchemaHandler<Internal.UID.Component>>();\n const tmpContentTypes = new Map();\n\n // init temporary ContentTypes\n Object.keys(contentTypes).forEach((key) => {\n tmpContentTypes.set(contentTypes[key].uid, createSchemaHandler(contentTypes[key]));\n });\n\n // init temporary components\n Object.keys(components).forEach((key) => {\n tmpComponents.set(\n components[key].uid,\n createSchemaHandler<Internal.UID.Component>(components[key])\n );\n });\n\n return {\n get components() {\n return tmpComponents;\n },\n get contentTypes() {\n return tmpContentTypes;\n },\n\n /**\n * Convert Attributes received from the API to the right syntax\n */\n convertAttributes(attributes: any) {\n return Object.keys(attributes).reduce(\n (acc, key) => {\n acc[key] = this.convertAttribute(attributes[key]);\n return acc;\n },\n {} as Record<string, unknown>\n );\n },\n\n convertAttribute(attribute: any) {\n const { configurable, private: isPrivate, conditions } = attribute;\n\n const baseProperties = {\n private: isPrivate === true ? true : undefined,\n configurable: configurable === false ? false : undefined,\n // IMPORTANT: Preserve conditions only if they exist and are not undefined/null\n ...(conditions !== undefined && conditions !== null && { conditions }),\n };\n\n if (attribute.type === 'relation') {\n const { target, relation, targetAttribute, dominant, ...restOfProperties } = attribute;\n\n const attr = {\n type: 'relation',\n relation,\n target,\n ...restOfProperties,\n ...baseProperties,\n };\n\n // TODO: uncomment this when we pre-create empty types and targets exists if we create multiple types at once\n // if (target && !this.contentTypes.has(target)) {\n // throw new errors.ApplicationError(`target: ${target} does not exist`);\n // }\n\n if (_.isNil(targetAttribute)) {\n return attr;\n }\n\n if (['oneToOne', 'manyToMany'].includes(relation) && dominant === true) {\n attr.inversedBy = targetAttribute;\n } else if (['oneToOne', 'manyToMany'].includes(relation) && dominant === false) {\n attr.mappedBy = targetAttribute;\n } else if (['oneToOne', 'manyToOne', 'manyToMany'].includes(relation)) {\n attr.inversedBy = targetAttribute;\n } else if (['oneToMany'].includes(relation)) {\n attr.mappedBy = targetAttribute;\n }\n\n return attr;\n }\n\n return {\n ...attribute,\n ...baseProperties,\n };\n },\n\n ...createComponentBuilder(),\n ...createContentTypeBuilder(),\n\n /**\n * Write all type to files, then rewrite the database rows that store a renamed\n * component uid (see `renameComponentRows`).\n *\n * Pass `{ renameComponentRows: false }` to only write the files. The caller must then\n * call `renameComponentRows` itself, before the reload, and roll the files back if it\n * throws. Do that when a later step must succeed together with the rows: run that\n * step through `renameComponentRows({ beforeCommit })`, so that its failure rolls the\n * rows back too.\n *\n * @returns boolean true if all files have been written correctly, false if an error\n * occurred while writing them (the files are rolled back)\n * @throws ApplicationError if the row rewrite failed (the files are rolled back) or if\n * a rollback failed\n */\n async writeFiles({ renameComponentRows = true }: { renameComponentRows?: boolean } = {}) {\n const schemas = [\n ...Array.from(tmpComponents.values()),\n ...Array.from(tmpContentTypes.values()),\n ];\n\n const written = await Promise.all(schemas.map((schema) => schema.flush()))\n .then(() => true)\n .catch((error) => {\n strapi.log.error('Error writing schema files');\n strapi.log.error(error);\n return this.rollback().then(() => false);\n })\n .catch((error) => {\n strapi.log.error(\n 'Error rolling back schema files. You might need to fix your files manually'\n );\n strapi.log.error(error);\n\n throw new errors.ApplicationError('Invalid schema edition');\n });\n\n if (!written || !renameComponentRows) {\n return written;\n }\n\n try {\n await this.renameComponentRows();\n } catch (error) {\n // The transaction already restored the rows. Restore the files too, or the next\n // reload would load the new uids against rows still holding the old ones.\n strapi.log.error('Error rewriting the rows of the renamed components');\n strapi.log.error(error);\n\n try {\n await this.rollback();\n } catch (rollbackError) {\n strapi.log.error(\n 'Error rolling back schema files. You might need to fix your files manually'\n );\n strapi.log.error(rollbackError);\n }\n\n throw new errors.ApplicationError('Invalid schema edition');\n }\n\n return true;\n },\n\n /**\n * A component uid change (category move or rename) is also stored in the database:\n * as `component_type` in the `*_cmps` join tables and as the type column of the\n * polymorphic join tables (e.g. media in `files_related_mph`). Rewrites those rows in\n * one transaction. Must run while the running process still holds the pre-rename\n * metadata that locates them, i.e. before the reload.\n *\n * `beforeCommit` runs inside that transaction, after the rewrite and before the\n * commit (also when no uid changed). If it rejects, the rows are rolled back. It must\n * not use the database (see `renameComponentUIDs`).\n *\n * @throws if the rewrite or `beforeCommit` failed; the transaction has then restored\n * the rows\n */\n async renameComponentRows({ beforeCommit }: RenameComponentUIDsOptions = {}) {\n const componentUIDRenames = Array.from(tmpComponents.values())\n .filter((component) => component.initialUID && component.uid !== component.initialUID)\n .map((component) => ({ oldUID: component.initialUID, newUID: component.uid }));\n\n await renameComponentUIDs(strapi.db, componentUIDRenames, { beforeCommit });\n },\n\n /**\n * rollback all files\n */\n rollback() {\n return Promise.all(\n [...Array.from(tmpComponents.values()), ...Array.from(tmpContentTypes.values())].map(\n (schema) => schema.rollback()\n )\n );\n },\n };\n}\n"],"names":["createBuilder","components","Object","values","strapi","map","componentInput","category","modelName","uid","filename","__filename__","dir","join","dirs","app","schema","__schema__","config","contentTypes","contentTypeInput","plugin","extensions","info","singularName","api","apiName","createSchemaBuilder","tmpComponents","Map","tmpContentTypes","keys","forEach","key","set","createSchemaHandler","convertAttributes","attributes","reduce","acc","convertAttribute","attribute","configurable","private","isPrivate","conditions","baseProperties","undefined","type","target","relation","targetAttribute","dominant","restOfProperties","attr","_","isNil","includes","inversedBy","mappedBy","createComponentBuilder","createContentTypeBuilder","writeFiles","renameComponentRows","schemas","Array","from","written","Promise","all","flush","then","catch","error","log","rollback","errors","ApplicationError","rollbackError","beforeCommit","componentUIDRenames","filter","component","initialUID","oldUID","newUID","renameComponentUIDs","db"],"mappings":";;;;;;;;;;;;;;AAUA;;AAEC,IACc,SAASA,aAAAA,GAAAA;IACtB,MAAMC,UAAAA,GAAaC,MAAAA,CAAOC,MAAM,CAACC,MAAAA,CAAOH,UAAU,CAAA,CAA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,UAAUC,UAAU;AAAEE,oBAAAA,MAAAA,EAAQH,UAAUzE;iBAAI,CAAA,CAAA;AAE7E,YAAA,MAAM6E,uCAAAA,CAAoBlF,MAAAA,CAAOmF,EAAE,EAAEP,mBAAAA,EAAqB;AAAED,gBAAAA;AAAa,aAAA,CAAA;AAC3E,QAAA,CAAA;AAEA;;QAGAJ,QAAAA,CAAAA,GAAAA;YACE,OAAOP,OAAAA,CAAQC,GAAG,CAChB;mBAAIJ,KAAAA,CAAMC,IAAI,CAACtC,aAAAA,CAAczB,MAAM,EAAA,CAAA;mBAAQ8D,KAAAA,CAAMC,IAAI,CAACpC,eAAAA,CAAgB3B,MAAM,EAAA;AAAI,aAAA,CAACE,GAAG,CAClF,CAACW,MAAAA,GAAWA,OAAO2D,QAAQ,EAAA,CAAA,CAAA;AAGjC,QAAA;AACF,KAAA;AACF;;;;"}
@@ -4,6 +4,7 @@ import { errors } from '@strapi/utils';
4
4
  import createSchemaHandler from './schema-handler.mjs';
5
5
  import createComponentBuilder$1 from './component-builder.mjs';
6
6
  import createComponentBuilder from './content-type-builder.mjs';
7
+ import { renameComponentUIDs } from './rename-component-uids.mjs';
7
8
 
8
9
  /**
9
10
  * Creates a content type schema builder instance
@@ -117,15 +118,25 @@ function createSchemaBuilder({ components, contentTypes }) {
117
118
  ...createComponentBuilder$1(),
118
119
  ...createComponentBuilder(),
119
120
  /**
120
- * Write all type to files
121
- * @returns boolean true if all files have been written correctly, false if an error occurred
122
- * @throws ApplicationError if an error occurred and rollback failed
123
- */ writeFiles () {
121
+ * Write all type to files, then rewrite the database rows that store a renamed
122
+ * component uid (see `renameComponentRows`).
123
+ *
124
+ * Pass `{ renameComponentRows: false }` to only write the files. The caller must then
125
+ * call `renameComponentRows` itself, before the reload, and roll the files back if it
126
+ * throws. Do that when a later step must succeed together with the rows: run that
127
+ * step through `renameComponentRows({ beforeCommit })`, so that its failure rolls the
128
+ * rows back too.
129
+ *
130
+ * @returns boolean true if all files have been written correctly, false if an error
131
+ * occurred while writing them (the files are rolled back)
132
+ * @throws ApplicationError if the row rewrite failed (the files are rolled back) or if
133
+ * a rollback failed
134
+ */ async writeFiles ({ renameComponentRows = true } = {}) {
124
135
  const schemas = [
125
136
  ...Array.from(tmpComponents.values()),
126
137
  ...Array.from(tmpContentTypes.values())
127
138
  ];
128
- return Promise.all(schemas.map((schema)=>schema.flush())).then(()=>true).catch((error)=>{
139
+ const written = await Promise.all(schemas.map((schema)=>schema.flush())).then(()=>true).catch((error)=>{
129
140
  strapi.log.error('Error writing schema files');
130
141
  strapi.log.error(error);
131
142
  return this.rollback().then(()=>false);
@@ -134,6 +145,47 @@ function createSchemaBuilder({ components, contentTypes }) {
134
145
  strapi.log.error(error);
135
146
  throw new errors.ApplicationError('Invalid schema edition');
136
147
  });
148
+ if (!written || !renameComponentRows) {
149
+ return written;
150
+ }
151
+ try {
152
+ await this.renameComponentRows();
153
+ } catch (error) {
154
+ // The transaction already restored the rows. Restore the files too, or the next
155
+ // reload would load the new uids against rows still holding the old ones.
156
+ strapi.log.error('Error rewriting the rows of the renamed components');
157
+ strapi.log.error(error);
158
+ try {
159
+ await this.rollback();
160
+ } catch (rollbackError) {
161
+ strapi.log.error('Error rolling back schema files. You might need to fix your files manually');
162
+ strapi.log.error(rollbackError);
163
+ }
164
+ throw new errors.ApplicationError('Invalid schema edition');
165
+ }
166
+ return true;
167
+ },
168
+ /**
169
+ * A component uid change (category move or rename) is also stored in the database:
170
+ * as `component_type` in the `*_cmps` join tables and as the type column of the
171
+ * polymorphic join tables (e.g. media in `files_related_mph`). Rewrites those rows in
172
+ * one transaction. Must run while the running process still holds the pre-rename
173
+ * metadata that locates them, i.e. before the reload.
174
+ *
175
+ * `beforeCommit` runs inside that transaction, after the rewrite and before the
176
+ * commit (also when no uid changed). If it rejects, the rows are rolled back. It must
177
+ * not use the database (see `renameComponentUIDs`).
178
+ *
179
+ * @throws if the rewrite or `beforeCommit` failed; the transaction has then restored
180
+ * the rows
181
+ */ async renameComponentRows ({ beforeCommit } = {}) {
182
+ const componentUIDRenames = Array.from(tmpComponents.values()).filter((component)=>component.initialUID && component.uid !== component.initialUID).map((component)=>({
183
+ oldUID: component.initialUID,
184
+ newUID: component.uid
185
+ }));
186
+ await renameComponentUIDs(strapi.db, componentUIDRenames, {
187
+ beforeCommit
188
+ });
137
189
  },
138
190
  /**
139
191
  * rollback all files