@strapi/content-type-builder 5.59.0 → 5.61.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.
- package/dist/server/controllers/validation/common.js +1 -1
- package/dist/server/controllers/validation/common.js.map +1 -1
- package/dist/server/controllers/validation/common.mjs +1 -1
- package/dist/server/controllers/validation/common.mjs.map +1 -1
- package/dist/server/controllers/validation/model-schema.js +3 -1
- package/dist/server/controllers/validation/model-schema.js.map +1 -1
- package/dist/server/controllers/validation/model-schema.mjs +3 -1
- package/dist/server/controllers/validation/model-schema.mjs.map +1 -1
- package/dist/server/middlewares/index.js +6 -2
- package/dist/server/middlewares/index.js.map +1 -1
- package/dist/server/middlewares/index.mjs +9 -1
- package/dist/server/middlewares/index.mjs.map +1 -1
- package/dist/server/middlewares/is-development-mode.js +2 -2
- package/dist/server/middlewares/is-development-mode.js.map +1 -1
- package/dist/server/middlewares/is-development-mode.mjs +2 -2
- package/dist/server/middlewares/is-development-mode.mjs.map +1 -1
- package/dist/server/routes/admin.js.map +1 -1
- package/dist/server/routes/admin.mjs +10 -10
- package/dist/server/routes/admin.mjs.map +1 -1
- package/dist/server/services/components.js +4 -3
- package/dist/server/services/components.js.map +1 -1
- package/dist/server/services/components.mjs +4 -3
- package/dist/server/services/components.mjs.map +1 -1
- package/dist/server/services/content-types.js +59 -9
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/content-types.mjs +59 -10
- package/dist/server/services/content-types.mjs.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.js +5 -2
- package/dist/server/services/schema-builder/content-type-builder.js.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.mjs +5 -2
- package/dist/server/services/schema-builder/content-type-builder.mjs.map +1 -1
- package/dist/server/services/schema-builder/index.js +0 -1
- package/dist/server/services/schema-builder/index.js.map +1 -1
- package/dist/server/services/schema-builder/index.mjs +0 -1
- package/dist/server/services/schema-builder/index.mjs.map +1 -1
- package/dist/server/services/schema.js +15 -6
- package/dist/server/services/schema.js.map +1 -1
- package/dist/server/services/schema.mjs +16 -7
- package/dist/server/services/schema.mjs.map +1 -1
- package/dist/server/src/middlewares/index.d.ts +6 -1
- package/dist/server/src/middlewares/index.d.ts.map +1 -1
- package/dist/server/src/services/components.d.ts.map +1 -1
- package/dist/server/src/services/content-types.d.ts +4 -0
- package/dist/server/src/services/content-types.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/content-type-builder.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/index.d.ts.map +1 -1
- package/dist/server/src/services/schema.d.ts.map +1 -1
- package/dist/server/src/utils/events.d.ts +10 -0
- package/dist/server/src/utils/events.d.ts.map +1 -0
- package/dist/server/utils/events.js +52 -0
- package/dist/server/utils/events.js.map +1 -0
- package/dist/server/utils/events.mjs +50 -0
- package/dist/server/utils/events.mjs.map +1 -0
- package/package.json +9 -9
|
@@ -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,\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 ...infos.options,\n draftAndPublish: infos.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,kB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;gBAClB,CAAA,MAAO;AACLwF,oBAAAA,IAAAA,CAAKzE,UAAU,GAAGf,GAAAA;AACpB,gBAAA;AACA,gBAAA;AACF,YAAA;QACA,KAAK,WAAA;AAAa,YAAA;AAChBwF,gBAAAA,IAAAA,CAAK5D,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;;;;"}
|
|
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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ACjBwF,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;;;;"}
|
|
@@ -140,7 +140,7 @@ function createComponentBuilder() {
|
|
|
140
140
|
description: infos.description
|
|
141
141
|
}).set('options', {
|
|
142
142
|
...infos.options,
|
|
143
|
-
draftAndPublish: infos.draftAndPublish
|
|
143
|
+
draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish
|
|
144
144
|
}).set('pluginOptions', infos.pluginOptions).set('config', infos.config);
|
|
145
145
|
this.createContentTypeAttributes(uid, infos.attributes);
|
|
146
146
|
return contentType;
|
|
@@ -267,8 +267,11 @@ function createComponentBuilder() {
|
|
|
267
267
|
'info',
|
|
268
268
|
'description'
|
|
269
269
|
], infos.description).set('options', {
|
|
270
|
+
// Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)
|
|
271
|
+
...contentType.schema.options,
|
|
270
272
|
...infos.options,
|
|
271
|
-
draftAndPublish
|
|
273
|
+
// A payload that does not set draftAndPublish keeps the stored value
|
|
274
|
+
draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish ?? contentType.schema.options?.draftAndPublish
|
|
272
275
|
}).set('pluginOptions', infos.pluginOptions).setAttributes(this.convertAttributes(newAttributes));
|
|
273
276
|
return contentType;
|
|
274
277
|
},
|
|
@@ -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,\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 ...infos.options,\n draftAndPublish: infos.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,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,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,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AQ,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.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,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,4BAAAA,GAA+B,CACnCC,YAAAA,EACAC,YAAAA,GAAAA;AAEAC,IAAAA,CAAAA,CAAEC,QAA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/_interopDefault(_);
|
|
|
17
17
|
const components = Object.values(strapi.components).map((componentInput)=>({
|
|
18
18
|
category: componentInput.category,
|
|
19
19
|
modelName: componentInput.modelName,
|
|
20
|
-
plugin: componentInput.modelName,
|
|
21
20
|
uid: componentInput.uid,
|
|
22
21
|
filename: componentInput.__filename__,
|
|
23
22
|
dir: path.join(strapi.dirs.app.components, componentInput.category),
|
|
@@ -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 plugin: 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","plugin","uid","filename","__filename__","dir","join","dirs","app","schema","__schema__","config","contentTypes","contentTypeInput","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,CAAC,CAACC,cAAAA,IAAoB;AAC3EC,YAAAA,QAAAA,EAAUD,eAAeC,QAAQ;AACjCC,YAAAA,SAAAA,EAAWF,eAAeE,SAAS;AACnCC,YAAAA,MAAAA,EAAQH,eAAeE,SAAS;AAChCE,YAAAA,GAAAA,EAAKJ,eAAeI,GAAG;AACvBC,YAAAA,QAAAA,EAAUL,eAAeM,YAAY;YACrCC,GAAAA,EAAKC,SA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AAAA,CAAMC,IAAI,CAACrC,aAAAA,CAAczB,MAAM,EAAA,CAAA;mBAAQ6D,KAAAA,CAAMC,IAAI,CAACnC,eAAAA,CAAgB3B,MAAM,EAAA;AAAI,aAAA,CAACE,GAAG,CAClF,CAACY,MAAAA,GAAWA,OAAOwD,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';\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,CAAC,CAACC,cAAAA,IAAoB;AAC3EC,YAAAA,QAAAA,EAAUD,eAAeC,QAAQ;AACjCC,YAAAA,SAAAA,EAAWF,eAAeE,SAAS;AACnCC,YAAAA,GAAAA,EAAKH,eAAeG,GAAG;AACvBC,YAAAA,QAAAA,EAAUJ,eAAeK,YAAY;YACrCC,GAAAA,EAAKC,SAAAA,CAAKT,OAAOU,IAAI,CAACC,GAAG,CAACd,UAAU,EAAEK,cAAAA,CAAeC,QAA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AMC,IAAI,CAACnC,eAAAA,CAAgB3B,MAAM,EAAA;AAAI,aAAA,CAACE,GAAG,CAClF,CAACW,MAAAA,GAAWA,OAAOyD,QAAQ,EAAA,CAAA,CAAA;AAGjC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -11,7 +11,6 @@ import createComponentBuilder from './content-type-builder.mjs';
|
|
|
11
11
|
const components = Object.values(strapi.components).map((componentInput)=>({
|
|
12
12
|
category: componentInput.category,
|
|
13
13
|
modelName: componentInput.modelName,
|
|
14
|
-
plugin: componentInput.modelName,
|
|
15
14
|
uid: componentInput.uid,
|
|
16
15
|
filename: componentInput.__filename__,
|
|
17
16
|
dir: join(strapi.dirs.app.components, componentInput.category),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","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 plugin: 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","plugin","uid","filename","__filename__","dir","join","dirs","app","schema","__schema__","config","contentTypes","contentTypeInput","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,CAAC,CAACC,cAAAA,IAAoB;AAC3EC,YAAAA,QAAAA,EAAUD,eAAeC,QA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A,CAAAA;gBAEjB,MAAM,IAAIG,MAAAA,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,CAACY,MAAAA,GAAWA,OAAOwD,QAAQ,EAAA,CAAA,CAAA;AAGjC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","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,CAAC,CAACC,cAAAA,IAAoB;AAC3EC,YAAAA,QAAAA,EAAUD,eAAeC,QAAQ;AACjCC,YAAAA,SAAAA,EAAWF,eA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A,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;;;;"}
|
|
@@ -7,6 +7,7 @@ var index = require('./migration-builder/index.js');
|
|
|
7
7
|
var schemaMutation = require('./schema-mutation.js');
|
|
8
8
|
var index$2 = require('../utils/index.js');
|
|
9
9
|
var uidTarget = require('../utils/uid-target.js');
|
|
10
|
+
var events = require('../utils/events.js');
|
|
10
11
|
var schema = require('../controllers/validation/schema.js');
|
|
11
12
|
var contentTypes = require('./content-types.js');
|
|
12
13
|
|
|
@@ -443,6 +444,14 @@ const updateSchema = async (schema)=>{
|
|
|
443
444
|
// Reject protected/plugin deletes before builders, API backups, or folder reconciliation can
|
|
444
445
|
// mutate anything. This is the server-side invariant for crafted update requests.
|
|
445
446
|
contentTypes$1.filter((contentType)=>contentType.action === 'delete').forEach((contentType)=>contentTypes.assertCTBOwnedApplicationContentType(contentType.uid));
|
|
447
|
+
// Same guard as the edit content-type route, run before anything is written.
|
|
448
|
+
for (const contentType of contentTypes$1){
|
|
449
|
+
if (contentType.action === 'update' && contentType.kind === 'singleType') {
|
|
450
|
+
if (strapi.contentTypes[contentType.uid]?.kind === 'collectionType') {
|
|
451
|
+
await contentTypes.assertCanConvertToSingleType(contentType.uid);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
446
455
|
// pre-process data
|
|
447
456
|
removeEmptyDefaultsOnUpdates(schema);
|
|
448
457
|
renameUIDTargetFieldsOnUpdates(schema);
|
|
@@ -596,34 +605,34 @@ const updateSchema = async (schema)=>{
|
|
|
596
605
|
}
|
|
597
606
|
for (const contentType of contentTypes$1){
|
|
598
607
|
if (contentType.action === 'delete') {
|
|
599
|
-
|
|
608
|
+
await events.emitSchemaEvent('content-type.delete', {
|
|
600
609
|
contentType: builder.contentTypes.get(contentType.uid)
|
|
601
610
|
});
|
|
602
611
|
}
|
|
603
612
|
if (contentType.action === 'update') {
|
|
604
|
-
|
|
613
|
+
await events.emitSchemaEvent('content-type.update', {
|
|
605
614
|
contentType: builder.contentTypes.get(contentType.uid)
|
|
606
615
|
});
|
|
607
616
|
}
|
|
608
617
|
if (contentType.action === 'create') {
|
|
609
|
-
|
|
618
|
+
await events.emitSchemaEvent('content-type.create', {
|
|
610
619
|
contentType: builder.contentTypes.get(contentType.uid)
|
|
611
620
|
});
|
|
612
621
|
}
|
|
613
622
|
}
|
|
614
623
|
for (const component of components){
|
|
615
624
|
if (component.action === 'delete') {
|
|
616
|
-
|
|
625
|
+
await events.emitSchemaEvent('component.delete', {
|
|
617
626
|
component: builder.components.get(component.uid)
|
|
618
627
|
});
|
|
619
628
|
}
|
|
620
629
|
if (component.action === 'update') {
|
|
621
|
-
|
|
630
|
+
await events.emitSchemaEvent('component.update', {
|
|
622
631
|
component: builder.components.get(component.uid)
|
|
623
632
|
});
|
|
624
633
|
}
|
|
625
634
|
if (component.action === 'create') {
|
|
626
|
-
|
|
635
|
+
await events.emitSchemaEvent('component.create', {
|
|
627
636
|
component: builder.components.get(component.uid)
|
|
628
637
|
});
|
|
629
638
|
}
|