@strapi/content-type-builder 5.48.1 → 5.50.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/admin/components/AIChat/components/Messages/Message.js +5 -1
- package/dist/admin/components/AIChat/components/Messages/Message.js.map +1 -1
- package/dist/admin/components/AIChat/components/SimpleMenu.js +3 -2
- package/dist/admin/components/AIChat/components/SimpleMenu.js.map +1 -1
- package/dist/admin/components/AIChat/hooks/useCodeUpload.js +7 -2
- package/dist/admin/components/AIChat/hooks/useCodeUpload.js.map +1 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.js +11 -5
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.js.map +1 -1
- package/dist/admin/components/AllowedTypesSelect.js +5 -1
- package/dist/admin/components/AllowedTypesSelect.js.map +1 -1
- package/dist/admin/components/AttributeOptions/EmptyAttributes.js +3 -2
- package/dist/admin/components/AttributeOptions/EmptyAttributes.js.map +1 -1
- package/dist/admin/components/AttributeRow.js +10 -5
- package/dist/admin/components/AttributeRow.js.map +1 -1
- package/dist/admin/components/AutoReloadOverlayBlocker.js +3 -2
- package/dist/admin/components/AutoReloadOverlayBlocker.js.map +1 -1
- package/dist/admin/components/ComponentCard/ComponentCard.js +5 -1
- package/dist/admin/components/ComponentCard/ComponentCard.js.map +1 -1
- package/dist/admin/components/ComponentList.js +5 -1
- package/dist/admin/components/ComponentList.js.map +1 -1
- package/dist/admin/components/ContentTypeBuilderNav/useContentTypeBuilderMenu.js +5 -1
- package/dist/admin/components/ContentTypeBuilderNav/useContentTypeBuilderMenu.js.map +1 -1
- package/dist/admin/components/DataManager/DataManagerProvider.js +12 -6
- package/dist/admin/components/DataManager/DataManagerProvider.js.map +1 -1
- package/dist/admin/components/DataManager/reducer.js +7 -2
- package/dist/admin/components/DataManager/reducer.js.map +1 -1
- package/dist/admin/components/DataManager/utils/cleanData.js +10 -4
- package/dist/admin/components/DataManager/utils/cleanData.js.map +1 -1
- package/dist/admin/components/DataManager/utils/retrieveComponentsThatHaveComponents.js +5 -1
- package/dist/admin/components/DataManager/utils/retrieveComponentsThatHaveComponents.js.map +1 -1
- package/dist/admin/components/DataManager/utils/retrieveSpecificInfoFromComponents.js +5 -1
- package/dist/admin/components/DataManager/utils/retrieveSpecificInfoFromComponents.js.map +1 -1
- package/dist/admin/components/FormModal/FormModal.js +30 -22
- package/dist/admin/components/FormModal/FormModal.js.map +1 -1
- package/dist/admin/components/FormModal/attributes/ConditionForm.js +3 -2
- package/dist/admin/components/FormModal/attributes/ConditionForm.js.map +1 -1
- package/dist/admin/components/FormModal/attributes/types.js +7 -3
- package/dist/admin/components/FormModal/attributes/types.js.map +1 -1
- package/dist/admin/components/FormModal/attributes/validation/common.js +8 -4
- package/dist/admin/components/FormModal/attributes/validation/common.js.map +1 -1
- package/dist/admin/components/FormModal/component/createComponentSchema.js +4 -3
- package/dist/admin/components/FormModal/component/createComponentSchema.js.map +1 -1
- package/dist/admin/components/FormModal/component/createComponentSchema.mjs +1 -1
- package/dist/admin/components/FormModal/component/createComponentSchema.mjs.map +1 -1
- package/dist/admin/components/FormModal/contentType/createContentTypeSchema.js +3 -2
- package/dist/admin/components/FormModal/contentType/createContentTypeSchema.js.map +1 -1
- package/dist/admin/components/FormModal/forms/utils/createCollectionName.js +5 -1
- package/dist/admin/components/FormModal/forms/utils/createCollectionName.js.map +1 -1
- package/dist/admin/components/FormModal/reducer.js +32 -26
- package/dist/admin/components/FormModal/reducer.js.map +1 -1
- package/dist/admin/components/FormModalHeader.js +6 -2
- package/dist/admin/components/FormModalHeader.js.map +1 -1
- package/dist/admin/components/FormModalNavigation/FormModalNavigationContext.js +3 -2
- package/dist/admin/components/FormModalNavigation/FormModalNavigationContext.js.map +1 -1
- package/dist/admin/components/FormModalSubHeader.js +6 -2
- package/dist/admin/components/FormModalSubHeader.js.map +1 -1
- package/dist/admin/components/GenericInputs.js +9 -4
- package/dist/admin/components/GenericInputs.js.map +1 -1
- package/dist/admin/components/IconPicker/constants.js +4 -3
- package/dist/admin/components/IconPicker/constants.js.map +1 -1
- package/dist/admin/components/PluralName.js +5 -1
- package/dist/admin/components/PluralName.js.map +1 -1
- package/dist/admin/components/Relation/RelationNaturePicker/RelationNaturePicker.js +13 -7
- package/dist/admin/components/Relation/RelationNaturePicker/RelationNaturePicker.js.map +1 -1
- package/dist/admin/components/TabForm.js +7 -3
- package/dist/admin/components/TabForm.js.map +1 -1
- package/dist/admin/pages/ListView/ListView.js +5 -1
- package/dist/admin/pages/ListView/ListView.js.map +1 -1
- package/dist/admin/src/components/AIChat/components/AnimatedBox.d.ts +4 -5
- package/dist/admin/src/components/AIChat/components/Attachments/AttachmentPreview.d.ts +1 -1
- package/dist/admin/src/components/AIChat/components/Dropzone.d.ts +0 -1
- package/dist/admin/src/components/AIChat/components/FloatingPanel.d.ts +0 -1
- package/dist/admin/src/components/AIChat/components/Input.d.ts +2 -3
- package/dist/admin/src/components/AIChat/components/ResizableTextArea.d.ts +0 -1
- package/dist/admin/src/components/AIChat/components/SimpleMenu.d.ts +9 -9
- package/dist/admin/src/components/AIChat/components/icons/FigmaIcon.d.ts +0 -1
- package/dist/admin/src/components/AIChat/components/icons/StopIcon.d.ts +0 -1
- package/dist/admin/src/components/AIChat/hooks/useAIFetch.d.ts +5 -5
- package/dist/admin/src/components/AttributeOptions/OptionBoxWrapper.d.ts +2 -3
- package/dist/admin/src/components/AttributeRow.d.ts +7 -8
- package/dist/admin/src/components/CTBSession/sessionContext.d.ts +0 -1
- package/dist/admin/src/components/ComponentRow.d.ts +6 -7
- package/dist/admin/src/components/ContentTypeBuilderNav/useContentTypeBuilderMenu.d.ts +0 -1
- package/dist/admin/src/components/CustomRadioGroup/Styles.d.ts +3 -4
- package/dist/admin/src/components/DataManager/DataManagerContext.d.ts +0 -1
- package/dist/admin/src/components/DataManager/reducer.d.ts +2 -2
- package/dist/admin/src/components/DataManager/utils/cleanData.d.ts +56 -56
- package/dist/admin/src/components/FormModal/attributes/form.d.ts +3 -3
- package/dist/admin/src/components/FormModal/attributes/validation/common.d.ts +1 -1
- package/dist/admin/src/components/FormModal/forms/forms.d.ts +2 -2
- package/dist/admin/src/components/FormModalNavigation/FormModalNavigationProvider.d.ts +0 -1
- package/dist/admin/src/components/List.d.ts +2 -3
- package/dist/admin/src/components/Relation/RelationNaturePicker/Components.d.ts +6 -7
- package/dist/admin/src/pages/ListView/LinkToCMSettingsView.d.ts +0 -1
- package/dist/admin/src/utils/isAllowedContentTypesForRelations.d.ts +1 -1
- package/dist/admin/translations/en.json.js +1 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +1 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/translations/ja.json.js +109 -50
- package/dist/admin/translations/ja.json.js.map +1 -1
- package/dist/admin/translations/ja.json.mjs +109 -50
- package/dist/admin/translations/ja.json.mjs.map +1 -1
- package/dist/admin/utils/formAPI.js +11 -6
- package/dist/admin/utils/formAPI.js.map +1 -1
- package/dist/admin/utils/getMaxDepth.js.map +1 -1
- package/dist/admin/utils/getMaxDepth.mjs.map +1 -1
- package/dist/admin/utils/nameToSlug.js +5 -1
- package/dist/admin/utils/nameToSlug.js.map +1 -1
- package/dist/admin/utils/toRegressedEnumValue.js +5 -1
- package/dist/admin/utils/toRegressedEnumValue.js.map +1 -1
- package/dist/server/controllers/components.js +6 -2
- package/dist/server/controllers/components.js.map +1 -1
- package/dist/server/controllers/content-types.js +8 -4
- package/dist/server/controllers/content-types.js.map +1 -1
- package/dist/server/controllers/validation/common.js +6 -2
- 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/component.js +9 -5
- package/dist/server/controllers/validation/component.js.map +1 -1
- package/dist/server/controllers/validation/data-transform.js +6 -2
- package/dist/server/controllers/validation/data-transform.js.map +1 -1
- package/dist/server/controllers/validation/model-schema.js +6 -2
- package/dist/server/controllers/validation/model-schema.js.map +1 -1
- package/dist/server/controllers/validation/types.js +8 -4
- package/dist/server/controllers/validation/types.js.map +1 -1
- package/dist/server/routes/content-api.js +3 -2
- package/dist/server/routes/content-api.js.map +1 -1
- package/dist/server/services/api-handler.js +4 -3
- package/dist/server/services/api-handler.js.map +1 -1
- package/dist/server/services/api-handler.mjs.map +1 -1
- package/dist/server/services/components.js.map +1 -1
- package/dist/server/services/components.mjs.map +1 -1
- package/dist/server/services/content-types.js +8 -4
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/schema-builder/component-builder.js +11 -5
- package/dist/server/services/schema-builder/component-builder.js.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.js +13 -8
- package/dist/server/services/schema-builder/content-type-builder.js.map +1 -1
- package/dist/server/services/schema-builder/index.js +5 -1
- package/dist/server/services/schema-builder/index.js.map +1 -1
- package/dist/server/services/schema-builder/schema-handler.js +35 -29
- package/dist/server/services/schema-builder/schema-handler.js.map +1 -1
- package/dist/server/services/schema-builder/schema-handler.mjs.map +1 -1
- package/dist/server/services/schema.js +5 -1
- package/dist/server/services/schema.js.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/common.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/component-category.d.ts +1 -1
- package/dist/server/src/controllers/validation/component.d.ts +1 -1
- package/dist/server/src/controllers/validation/component.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/content-type.d.ts +1 -1
- package/dist/server/src/controllers/validation/content-type.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/data-transform.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/model-schema.d.ts +1 -1
- package/dist/server/src/controllers/validation/model-schema.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/schema.d.ts +1 -1
- package/dist/server/src/controllers/validation/types.d.ts.map +1 -1
- package/dist/server/src/middlewares/is-development-mode.d.ts.map +1 -1
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/services/builder.d.ts.map +1 -1
- package/dist/server/src/services/component-categories.d.ts.map +1 -1
- package/dist/server/src/services/components.d.ts +3 -26
- package/dist/server/src/services/components.d.ts.map +1 -1
- package/dist/server/src/services/content-types.d.ts +1 -1
- package/dist/server/src/services/content-types.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/component-builder.d.ts +12 -12
- package/dist/server/src/services/schema-builder/component-builder.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/content-type-builder.d.ts +14 -14
- 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 +27 -27
- package/dist/server/src/services/schema-builder/index.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/schema-handler.d.ts +13 -12
- package/dist/server/src/services/schema-builder/schema-handler.d.ts.map +1 -1
- package/dist/server/src/services/schema.d.ts +66 -66
- package/dist/server/src/services/schema.d.ts.map +1 -1
- package/dist/server/src/utils/attributes.d.ts +2 -2
- package/dist/server/src/utils/attributes.d.ts.map +1 -1
- package/dist/server/src/utils/helpers.d.ts.map +1 -1
- package/dist/server/src/utils/typeguards.d.ts.map +1 -1
- package/dist/server/utils/attributes.js +12 -7
- package/dist/server/utils/attributes.js.map +1 -1
- package/package.json +12 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.js","sources":["../../../server/src/services/api-handler.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Internal } from '@strapi/types';\n\n/**\n * Deletes the API folder of a contentType\n */\nexport async function clear(uid: Internal.UID.ContentType) {\n // TODO double check if this is the correct way to get the apiName\n const { apiName, modelName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n\n await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));\n await deleteBackup(uid);\n}\n\n/**\n * Backups the API folder of a contentType\n * @param {string} uid content type uid\n */\nexport async function backup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n // backup the api folder\n await fse.copy(apiFolder, backupFolder);\n}\n\n/**\n * Deletes an API backup folder\n */\nasync function deleteBackup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const backupFolder = path.join(strapi.dirs.app.api, '.backup');\n const apiBackupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n await fse.remove(apiBackupFolder);\n\n const list = await fse.readdir(backupFolder);\n if (list.length === 0) {\n await fse.remove(backupFolder);\n }\n}\n\n/**\n * Rollbacks the API folder of a contentType\n */\nexport async function rollback(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n try {\n await fse.access(backupFolder);\n } catch {\n throw new Error('Cannot rollback api that was not backed up');\n }\n\n await fse.remove(apiFolder);\n await fse.copy(backupFolder, apiFolder);\n await deleteBackup(uid);\n}\n\n/**\n * Creates a delete function to clear an api folder\n */\nconst createDeleteApiFunction = (baseName: string) => {\n /**\n * Delets a file in an api.\n * Will only update routes.json instead of deleting it if other routes are present\n */\n return async (filePath: string) => {\n const fileName = path.basename(filePath, path.extname(filePath));\n\n const isSchemaFile = filePath.endsWith(`${baseName}/schema.json`);\n if (fileName === baseName || isSchemaFile) {\n return fse.remove(filePath);\n }\n };\n};\n\n/**\n * Deletes a folder recursively using a delete function\n * @param {string} folder folder to delete\n */\nconst recursiveRemoveFiles = async (folder: string
|
|
1
|
+
{"version":3,"file":"api-handler.js","sources":["../../../server/src/services/api-handler.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Internal } from '@strapi/types';\n\n/**\n * Deletes the API folder of a contentType\n */\nexport async function clear(uid: Internal.UID.ContentType) {\n // TODO double check if this is the correct way to get the apiName\n const { apiName, modelName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n\n await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));\n await deleteBackup(uid);\n}\n\n/**\n * Backups the API folder of a contentType\n * @param {string} uid content type uid\n */\nexport async function backup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n // backup the api folder\n await fse.copy(apiFolder, backupFolder);\n}\n\n/**\n * Deletes an API backup folder\n */\nasync function deleteBackup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const backupFolder = path.join(strapi.dirs.app.api, '.backup');\n const apiBackupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n await fse.remove(apiBackupFolder);\n\n const list = await fse.readdir(backupFolder);\n if (list.length === 0) {\n await fse.remove(backupFolder);\n }\n}\n\n/**\n * Rollbacks the API folder of a contentType\n */\nexport async function rollback(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n try {\n await fse.access(backupFolder);\n } catch {\n throw new Error('Cannot rollback api that was not backed up');\n }\n\n await fse.remove(apiFolder);\n await fse.copy(backupFolder, apiFolder);\n await deleteBackup(uid);\n}\n\n/**\n * Creates a delete function to clear an api folder\n */\nconst createDeleteApiFunction = (baseName: string) => {\n /**\n * Delets a file in an api.\n * Will only update routes.json instead of deleting it if other routes are present\n */\n return async (filePath: string) => {\n const fileName = path.basename(filePath, path.extname(filePath));\n\n const isSchemaFile = filePath.endsWith(`${baseName}/schema.json`);\n if (fileName === baseName || isSchemaFile) {\n return fse.remove(filePath);\n }\n };\n};\n\n/**\n * Deletes a folder recursively using a delete function\n * @param {string} folder folder to delete\n */\nconst recursiveRemoveFiles = async (\n folder: string,\n deleteFn: (file: string) => unknown\n): Promise<void> => {\n const filesName = await fse.readdir(folder);\n\n for (const fileName of filesName) {\n const filePath = path.join(folder, fileName);\n\n const stat = await fse.stat(filePath);\n\n if (stat.isDirectory()) {\n await recursiveRemoveFiles(filePath, deleteFn);\n } else {\n await deleteFn(filePath);\n }\n }\n\n const files = await fse.readdir(folder);\n if (files.length === 0) {\n await fse.remove(folder);\n }\n};\n"],"names":["clear","uid","apiName","modelName","strapi","contentTypes","apiFolder","path","join","dirs","app","api","recursiveRemoveFiles","createDeleteApiFunction","deleteBackup","backup","backupFolder","fse","copy","apiBackupFolder","remove","list","readdir","length","rollback","access","Error","baseName","filePath","fileName","basename","extname","isSchemaFile","endsWith","folder","deleteFn","filesName","stat","isDirectory","files"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;IAGO,eAAeA,KAAAA,CAAMC,GAA6B,EAAA;;IAEvD,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGC,MAAAA,CAAOC,YAAY,CAACJ,GAAAA,CAAI;;AAGvD,IAAA,IAAI,CAACC,OAAAA,EAAS;IAEd,MAAMI,SAAAA,GAAYC,eAAAA,CAAKC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S,YAAY,CAAC,CAAA;QAChE,IAAIE,QAAAA,KAAaF,YAAYK,YAAAA,EAAc;YACzC,OAAOf,cAAAA,CAAIG,MAAM,CAACQ,QAAAA,CAAAA;AACpB,QAAA;AACF,IAAA,CAAA;AACF,CAAA;AAEA;;;IAIA,MAAMhB,oBAAAA,GAAuB,OAC3BsB,MAAAA,EACAC,QAAAA,GAAAA;AAEA,IAAA,MAAMC,SAAAA,GAAY,MAAMnB,cAAAA,CAAIK,OAAO,CAACY,MAAAA,CAAAA;IAEpC,KAAK,MAAML,YAAYO,SAAAA,CAAW;AAChC,QAAA,MAAMR,QAAAA,GAAWrB,eAAAA,CAAKC,IAAI,CAAC0B,MAAAA,EAAQL,QAAAA,CAAAA;AAEnC,QAAA,MAAMQ,IAAAA,GAAO,MAAMpB,cAAAA,CAAIoB,IAAI,CAACT,QAAAA,CAAAA;QAE5B,IAAIS,IAAAA,CAAKC,WAAW,EAAA,EAAI;AACtB,YAAA,MAAM1B,qBAAqBgB,QAAAA,EAAUO,QAAAA,CAAAA;QACvC,CAAA,MAAO;AACL,YAAA,MAAMA,QAAAA,CAASP,QAAAA,CAAAA;AACjB,QAAA;AACF,IAAA;AAEA,IAAA,MAAMW,KAAAA,GAAQ,MAAMtB,cAAAA,CAAIK,OAAO,CAACY,MAAAA,CAAAA;IAChC,IAAIK,KAAAA,CAAMhB,MAAM,KAAK,CAAA,EAAG;QACtB,MAAMN,cAAAA,CAAIG,MAAM,CAACc,MAAAA,CAAAA;AACnB,IAAA;AACF,CAAA;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.mjs","sources":["../../../server/src/services/api-handler.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Internal } from '@strapi/types';\n\n/**\n * Deletes the API folder of a contentType\n */\nexport async function clear(uid: Internal.UID.ContentType) {\n // TODO double check if this is the correct way to get the apiName\n const { apiName, modelName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n\n await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));\n await deleteBackup(uid);\n}\n\n/**\n * Backups the API folder of a contentType\n * @param {string} uid content type uid\n */\nexport async function backup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n // backup the api folder\n await fse.copy(apiFolder, backupFolder);\n}\n\n/**\n * Deletes an API backup folder\n */\nasync function deleteBackup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const backupFolder = path.join(strapi.dirs.app.api, '.backup');\n const apiBackupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n await fse.remove(apiBackupFolder);\n\n const list = await fse.readdir(backupFolder);\n if (list.length === 0) {\n await fse.remove(backupFolder);\n }\n}\n\n/**\n * Rollbacks the API folder of a contentType\n */\nexport async function rollback(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n try {\n await fse.access(backupFolder);\n } catch {\n throw new Error('Cannot rollback api that was not backed up');\n }\n\n await fse.remove(apiFolder);\n await fse.copy(backupFolder, apiFolder);\n await deleteBackup(uid);\n}\n\n/**\n * Creates a delete function to clear an api folder\n */\nconst createDeleteApiFunction = (baseName: string) => {\n /**\n * Delets a file in an api.\n * Will only update routes.json instead of deleting it if other routes are present\n */\n return async (filePath: string) => {\n const fileName = path.basename(filePath, path.extname(filePath));\n\n const isSchemaFile = filePath.endsWith(`${baseName}/schema.json`);\n if (fileName === baseName || isSchemaFile) {\n return fse.remove(filePath);\n }\n };\n};\n\n/**\n * Deletes a folder recursively using a delete function\n * @param {string} folder folder to delete\n */\nconst recursiveRemoveFiles = async (folder: string
|
|
1
|
+
{"version":3,"file":"api-handler.mjs","sources":["../../../server/src/services/api-handler.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Internal } from '@strapi/types';\n\n/**\n * Deletes the API folder of a contentType\n */\nexport async function clear(uid: Internal.UID.ContentType) {\n // TODO double check if this is the correct way to get the apiName\n const { apiName, modelName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n\n await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));\n await deleteBackup(uid);\n}\n\n/**\n * Backups the API folder of a contentType\n * @param {string} uid content type uid\n */\nexport async function backup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n // backup the api folder\n await fse.copy(apiFolder, backupFolder);\n}\n\n/**\n * Deletes an API backup folder\n */\nasync function deleteBackup(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const backupFolder = path.join(strapi.dirs.app.api, '.backup');\n const apiBackupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n await fse.remove(apiBackupFolder);\n\n const list = await fse.readdir(backupFolder);\n if (list.length === 0) {\n await fse.remove(backupFolder);\n }\n}\n\n/**\n * Rollbacks the API folder of a contentType\n */\nexport async function rollback(uid: Internal.UID.ContentType) {\n const { apiName } = strapi.contentTypes[uid] as any;\n\n // Opt out if the content type is not linked to an API (e.g. plugin content type)\n if (!apiName) return;\n\n const apiFolder = path.join(strapi.dirs.app.api, apiName);\n const backupFolder = path.join(strapi.dirs.app.api, '.backup', apiName);\n\n try {\n await fse.access(backupFolder);\n } catch {\n throw new Error('Cannot rollback api that was not backed up');\n }\n\n await fse.remove(apiFolder);\n await fse.copy(backupFolder, apiFolder);\n await deleteBackup(uid);\n}\n\n/**\n * Creates a delete function to clear an api folder\n */\nconst createDeleteApiFunction = (baseName: string) => {\n /**\n * Delets a file in an api.\n * Will only update routes.json instead of deleting it if other routes are present\n */\n return async (filePath: string) => {\n const fileName = path.basename(filePath, path.extname(filePath));\n\n const isSchemaFile = filePath.endsWith(`${baseName}/schema.json`);\n if (fileName === baseName || isSchemaFile) {\n return fse.remove(filePath);\n }\n };\n};\n\n/**\n * Deletes a folder recursively using a delete function\n * @param {string} folder folder to delete\n */\nconst recursiveRemoveFiles = async (\n folder: string,\n deleteFn: (file: string) => unknown\n): Promise<void> => {\n const filesName = await fse.readdir(folder);\n\n for (const fileName of filesName) {\n const filePath = path.join(folder, fileName);\n\n const stat = await fse.stat(filePath);\n\n if (stat.isDirectory()) {\n await recursiveRemoveFiles(filePath, deleteFn);\n } else {\n await deleteFn(filePath);\n }\n }\n\n const files = await fse.readdir(folder);\n if (files.length === 0) {\n await fse.remove(folder);\n }\n};\n"],"names":["clear","uid","apiName","modelName","strapi","contentTypes","apiFolder","path","join","dirs","app","api","recursiveRemoveFiles","createDeleteApiFunction","deleteBackup","backup","backupFolder","fse","copy","apiBackupFolder","remove","list","readdir","length","rollback","access","Error","baseName","filePath","fileName","basename","extname","isSchemaFile","endsWith","folder","deleteFn","filesName","stat","isDirectory","files"],"mappings":";;;AAIA;;IAGO,eAAeA,KAAAA,CAAMC,GAA6B,EAAA;;IAEvD,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGC,MAAAA,CAAOC,YAAY,CAACJ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,CAAAA,CAAAA;AAEtD,QAAA,MAAMI,eAAeJ,QAAAA,CAASK,QAAQ,CAAC,CAAA,EAAGN,QAAAA,CAAS,YAAY,CAAC,CAAA;QAChE,IAAIE,QAAAA,KAAaF,YAAYK,YAAAA,EAAc;YACzC,OAAOf,GAAAA,CAAIG,MAAM,CAACQ,QAAAA,CAAAA;AACpB,QAAA;AACF,IAAA,CAAA;AACF,CAAA;AAEA;;;IAIA,MAAMhB,oBAAAA,GAAuB,OAC3BsB,MAAAA,EACAC,QAAAA,GAAAA;AAEA,IAAA,MAAMC,SAAAA,GAAY,MAAMnB,GAAAA,CAAIK,OAAO,CAACY,MAAAA,CAAAA;IAEpC,KAAK,MAAML,YAAYO,SAAAA,CAAW;AAChC,QAAA,MAAMR,QAAAA,GAAWrB,IAAAA,CAAKC,IAAI,CAAC0B,MAAAA,EAAQL,QAAAA,CAAAA;AAEnC,QAAA,MAAMQ,IAAAA,GAAO,MAAMpB,GAAAA,CAAIoB,IAAI,CAACT,QAAAA,CAAAA;QAE5B,IAAIS,IAAAA,CAAKC,WAAW,EAAA,EAAI;AACtB,YAAA,MAAM1B,qBAAqBgB,QAAAA,EAAUO,QAAAA,CAAAA;QACvC,CAAA,MAAO;AACL,YAAA,MAAMA,QAAAA,CAASP,QAAAA,CAAAA;AACjB,QAAA;AACF,IAAA;AAEA,IAAA,MAAMW,KAAAA,GAAQ,MAAMtB,GAAAA,CAAIK,OAAO,CAACY,MAAAA,CAAAA;IAChC,IAAIK,KAAAA,CAAMhB,MAAM,KAAK,CAAA,EAAG;QACtB,MAAMN,GAAAA,CAAIG,MAAM,CAACc,MAAAA,CAAAA;AACnB,IAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import type { Internal, Struct } from '@strapi/types';\nimport { get, has } from 'lodash';\n\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\n\n/**\n * Formats a component attributes\n */\nexport const formatComponent = (component: any) => {\n const { uid, modelName, connection, collectionName, info, category } = component;\n\n return {\n uid,\n category,\n apiId: modelName,\n schema: {\n displayName: get(info, 'displayName'),\n description: get(info, 'description', ''),\n icon: get(info, 'icon'),\n connection,\n collectionName,\n pluginOptions: component.pluginOptions,\n attributes: formatAttributes(component),\n },\n };\n};\n\n/**\n * Creates a component and handle the nested components sent with it\n */\nexport const createComponent = async ({
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import type { Internal, Struct } from '@strapi/types';\nimport { get, has } from 'lodash';\n\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\nimport type { SchemaHandler } from './schema-builder/schema-handler';\n\n/**\n * Formats a component attributes\n */\nexport const formatComponent = (component: any) => {\n const { uid, modelName, connection, collectionName, info, category } = component;\n\n return {\n uid,\n category,\n apiId: modelName,\n schema: {\n displayName: get(info, 'displayName'),\n description: get(info, 'description', ''),\n icon: get(info, 'icon'),\n connection,\n collectionName,\n pluginOptions: component.pluginOptions,\n attributes: formatAttributes(component),\n },\n };\n};\n\n/**\n * Creates a component and handle the nested components sent with it\n */\nexport const createComponent = async ({\n component,\n components = [],\n}: any): Promise<SchemaHandler> => {\n const builder = createBuilder();\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const newComponent = builder.createComponent(replaceTmpUIDs(component));\n\n components.forEach((component: any) => {\n if (!has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.create', { component: newComponent });\n\n return newComponent;\n};\n\ntype ComponentToCreate = {\n component: Struct.ComponentSchema;\n components?: Struct.ComponentSchema[];\n};\n\nexport const editComponent = async (\n uid: Internal.UID.Component,\n { component, components = [] }: ComponentToCreate\n): Promise<SchemaHandler> => {\n const builder = createBuilder();\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const updatedComponent = builder.editComponent({\n uid,\n ...replaceTmpUIDs(component),\n });\n\n components.forEach((component) => {\n if (!has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.update', { component: updatedComponent });\n\n return updatedComponent;\n};\n\nexport const deleteComponent = async (uid: Internal.UID.Component) => {\n const builder = createBuilder();\n\n const deletedComponent = builder.deleteComponent(uid);\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.delete', { component: deletedComponent });\n\n return deletedComponent;\n};\n"],"names":["formatComponent","component","uid","modelName","connection","collectionName","info","category","apiId","schema","displayName","get","description","icon","pluginOptions","attributes","formatAttributes","createComponent","components","builder","createBuilder","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newComponent","forEach","has","editComponent","writeFiles","strapi","eventHub","emit","updatedComponent","deleteComponent","deletedComponent"],"mappings":";;;;;;AAOA;;IAGO,MAAMA,eAAAA,GAAkB,CAACC,SAAAA,GAAAA;AAC9B,IAAA,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,UAAU,EAAEC,cAAc,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGN,SAAAA;IAEvE,OAAO;AACLC,QAAAA,GAAAA;AACAK,QAAAA,QAAAA;QACAC,KAAAA,EAAOL,SAAAA;QACPM,MAAAA,EAAQ;AACNC,YAAAA,WAAAA,EAAaC,MAAIL,IAAAA,EAAM,aAAA,CAAA;YACvBM,WAAAA,EAAaD,KAAAA,CAAIL,MAAM,aAAA,EAAe,EAAA,CAAA;AACtCO,YAAAA,IAAAA,EAAMF,MAAIL,IAAAA,EAAM,MAAA,CAAA;AAChBF,YAAAA,UAAAA;AACAC,YAAAA,cAA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AA,CAAqBH,MAAAA,CAAAA;IAE5C,MAAMY,gBAAAA,GAAmBd,OAAAA,CAAQS,aAAa,CAAC;AAC7C1B,QAAAA,GAAAA;AACA,QAAA,GAAGqB,eAAetB,SAAAA;AACpB,KAAA,CAAA;IAEAiB,UAAAA,CAAWQ,OAAO,CAAC,CAACzB,SAAAA,GAAAA;QAClB,IAAI,CAAC0B,KAAAA,CAAI1B,SAAAA,EAAW,KAAA,CAAA,EAAQ;YAC1B,OAAOkB,OAAAA,CAAQF,eAAe,CAACM,cAAAA,CAAetB,SAAAA,CAAAA,CAAAA;AAChD,QAAA;QAEA,OAAOkB,OAAAA,CAAQS,aAAa,CAACL,cAAAA,CAAetB,SAAAA,CAAAA,CAAAA;AAC9C,IAAA,CAAA,CAAA;AAEA,IAAA,MAAMkB,QAAQU,UAAU,EAAA;AAExBC,IAAAA,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;QAAE/B,SAAAA,EAAWgC;AAAiB,KAAA,CAAA;IAEvE,OAAOA,gBAAAA;AACT;AAEO,MAAMC,kBAAkB,OAAOhC,GAAAA,GAAAA;AACpC,IAAA,MAAMiB,OAAAA,GAAUC,KAAAA,EAAAA;IAEhB,MAAMe,gBAAAA,GAAmBhB,OAAAA,CAAQe,eAAe,CAAChC,GAAAA,CAAAA;AAEjD,IAAA,MAAMiB,QAAQU,UAAU,EAAA;AAExBC,IAAAA,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;QAAE/B,SAAAA,EAAWkC;AAAiB,KAAA,CAAA;IAEvE,OAAOA,gBAAAA;AACT;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import type { Internal, Struct } from '@strapi/types';\nimport { get, has } from 'lodash';\n\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\n\n/**\n * Formats a component attributes\n */\nexport const formatComponent = (component: any) => {\n const { uid, modelName, connection, collectionName, info, category } = component;\n\n return {\n uid,\n category,\n apiId: modelName,\n schema: {\n displayName: get(info, 'displayName'),\n description: get(info, 'description', ''),\n icon: get(info, 'icon'),\n connection,\n collectionName,\n pluginOptions: component.pluginOptions,\n attributes: formatAttributes(component),\n },\n };\n};\n\n/**\n * Creates a component and handle the nested components sent with it\n */\nexport const createComponent = async ({
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import type { Internal, Struct } from '@strapi/types';\nimport { get, has } from 'lodash';\n\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\nimport type { SchemaHandler } from './schema-builder/schema-handler';\n\n/**\n * Formats a component attributes\n */\nexport const formatComponent = (component: any) => {\n const { uid, modelName, connection, collectionName, info, category } = component;\n\n return {\n uid,\n category,\n apiId: modelName,\n schema: {\n displayName: get(info, 'displayName'),\n description: get(info, 'description', ''),\n icon: get(info, 'icon'),\n connection,\n collectionName,\n pluginOptions: component.pluginOptions,\n attributes: formatAttributes(component),\n },\n };\n};\n\n/**\n * Creates a component and handle the nested components sent with it\n */\nexport const createComponent = async ({\n component,\n components = [],\n}: any): Promise<SchemaHandler> => {\n const builder = createBuilder();\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const newComponent = builder.createComponent(replaceTmpUIDs(component));\n\n components.forEach((component: any) => {\n if (!has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.create', { component: newComponent });\n\n return newComponent;\n};\n\ntype ComponentToCreate = {\n component: Struct.ComponentSchema;\n components?: Struct.ComponentSchema[];\n};\n\nexport const editComponent = async (\n uid: Internal.UID.Component,\n { component, components = [] }: ComponentToCreate\n): Promise<SchemaHandler> => {\n const builder = createBuilder();\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const updatedComponent = builder.editComponent({\n uid,\n ...replaceTmpUIDs(component),\n });\n\n components.forEach((component) => {\n if (!has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.update', { component: updatedComponent });\n\n return updatedComponent;\n};\n\nexport const deleteComponent = async (uid: Internal.UID.Component) => {\n const builder = createBuilder();\n\n const deletedComponent = builder.deleteComponent(uid);\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('component.delete', { component: deletedComponent });\n\n return deletedComponent;\n};\n"],"names":["formatComponent","component","uid","modelName","connection","collectionName","info","category","apiId","schema","displayName","get","description","icon","pluginOptions","attributes","formatAttributes","createComponent","components","builder","createBuilder","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newComponent","forEach","has","editComponent","writeFiles","strapi","eventHub","emit","updatedComponent","deleteComponent","deletedComponent"],"mappings":";;;;AAOA;;IAGO,MAAMA,eAAAA,GAAkB,CAACC,SAAAA,GAAAA;AAC9B,IAAA,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,UAAU,EAAEC,cAAc,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGN,SAAAA;IAEvE,OAAO;AACLC,QAAAA,GAAAA;AACAK,QAAAA,QAAAA;QACAC,KAAAA,EAAOL,SAAAA;QACPM,MAAAA,EAAQ;AACNC,YAAAA,WAAAA,EAAaC,IAAIL,IAAAA,EAAM,aAAA,CAAA;YACvBM,WAAAA,EAAaD,GAAAA,CAAIL,MAAM,aAAA,EAAe,EAAA,CAAA;AACtCO,YAAAA,IAAAA,EAAMF,IAAIL,IAAAA,EAAM,MAAA,CAAA;AAChBF,YAAAA,UAAAA;AACAC,YAAAA,cAAAA;AACAS,YAAAA,aAAAA,EAA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AE5C,MAAMY,gBAAAA,GAAmBd,OAAAA,CAAQS,aAAa,CAAC;AAC7C1B,QAAAA,GAAAA;AACA,QAAA,GAAGqB,eAAetB,SAAAA;AACpB,KAAA,CAAA;IAEAiB,UAAAA,CAAWQ,OAAO,CAAC,CAACzB,SAAAA,GAAAA;QAClB,IAAI,CAAC0B,GAAAA,CAAI1B,SAAAA,EAAW,KAAA,CAAA,EAAQ;YAC1B,OAAOkB,OAAAA,CAAQF,eAAe,CAACM,cAAAA,CAAetB,SAAAA,CAAAA,CAAAA;AAChD,QAAA;QAEA,OAAOkB,OAAAA,CAAQS,aAAa,CAACL,cAAAA,CAAetB,SAAAA,CAAAA,CAAAA;AAC9C,IAAA,CAAA,CAAA;AAEA,IAAA,MAAMkB,QAAQU,UAAU,EAAA;AAExBC,IAAAA,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;QAAE/B,SAAAA,EAAWgC;AAAiB,KAAA,CAAA;IAEvE,OAAOA,gBAAAA;AACT;AAEO,MAAMC,kBAAkB,OAAOhC,GAAAA,GAAAA;AACpC,IAAA,MAAMiB,OAAAA,GAAUC,aAAAA,EAAAA;IAEhB,MAAMe,gBAAAA,GAAmBhB,OAAAA,CAAQe,eAAe,CAAChC,GAAAA,CAAAA;AAEjD,IAAA,MAAMiB,QAAQU,UAAU,EAAA;AAExBC,IAAAA,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAAC,kBAAA,EAAoB;QAAE/B,SAAAA,EAAWkC;AAAiB,KAAA,CAAA;IAEvE,OAAOA,gBAAAA;AACT;;;;"}
|
|
@@ -7,6 +7,10 @@ var attributes = require('../utils/attributes.js');
|
|
|
7
7
|
var index = require('./schema-builder/index.js');
|
|
8
8
|
var constants = require('./constants.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
13
|
+
|
|
10
14
|
const { ApplicationError } = utils.errors;
|
|
11
15
|
const isContentTypeVisible = (model)=>fp.getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;
|
|
12
16
|
const getRestrictRelationsTo = (contentType)=>{
|
|
@@ -36,7 +40,7 @@ const getRestrictRelationsTo = (contentType)=>{
|
|
|
36
40
|
displayName: info.displayName,
|
|
37
41
|
singularName: info.singularName,
|
|
38
42
|
pluralName: info.pluralName,
|
|
39
|
-
description:
|
|
43
|
+
description: ___default.default.get(info, 'description', ''),
|
|
40
44
|
pluginOptions: contentType.pluginOptions,
|
|
41
45
|
kind: kind || 'collectionType',
|
|
42
46
|
collectionName,
|
|
@@ -76,7 +80,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
76
80
|
};
|
|
77
81
|
components?.forEach((component)=>{
|
|
78
82
|
const options = replaceTmpUIDs(targetContentType(component));
|
|
79
|
-
if (!
|
|
83
|
+
if (!___default.default.has(component, 'uid')) {
|
|
80
84
|
return builder.createComponent(options);
|
|
81
85
|
}
|
|
82
86
|
return builder.editComponent(options);
|
|
@@ -129,7 +133,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
129
133
|
}
|
|
130
134
|
return acc;
|
|
131
135
|
}, {});
|
|
132
|
-
contentType.attributes =
|
|
136
|
+
contentType.attributes = ___default.default.merge(prevNonVisibleAttributes, contentType.attributes);
|
|
133
137
|
if (newKind !== previousKind && newKind === 'singleType') {
|
|
134
138
|
const entryCount = await strapi.db.query(uid).count();
|
|
135
139
|
if (entryCount > 1) {
|
|
@@ -143,7 +147,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
143
147
|
...replaceTmpUIDs(contentType)
|
|
144
148
|
});
|
|
145
149
|
components.forEach((component)=>{
|
|
146
|
-
if (!
|
|
150
|
+
if (!___default.default.has(component, 'uid')) {
|
|
147
151
|
return builder.createComponent(replaceTmpUIDs(component));
|
|
148
152
|
}
|
|
149
153
|
return builder.editComponent(replaceTmpUIDs(component));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { getOr } from 'lodash/fp';\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;\n\nexport const getRestrictRelationsTo = (contentType: Struct.ContentTypeSchema) => {\n const { uid } = contentType;\n if (uid === coreUids.STRAPI_USER) {\n // TODO: replace with an obj { relation: 'x', bidirectional: true|false }\n return ['oneWay', 'manyWay'];\n }\n\n if (\n uid.startsWith(coreUids.PREFIX) ||\n uid === pluginsUids.UPLOAD_FILE ||\n !isContentTypeVisible(contentType)\n ) {\n return [];\n }\n\n return null;\n};\n\n/**\n * Format a contentType info to be used by the front-end\n */\nexport const formatContentType = (contentType: any) => {\n const { uid, kind, modelName, plugin, collectionName, info } = contentType;\n\n return {\n uid,\n plugin,\n apiID: modelName,\n schema: {\n ...contentTypesUtils.getOptions(contentType),\n displayName: info.displayName,\n singularName: info.singularName,\n pluralName: info.pluralName,\n description: _.get(info, 'description', ''),\n pluginOptions: contentType.pluginOptions,\n kind: kind || 'collectionType',\n collectionName,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n },\n };\n};\n\nexport const createContentTypes = async (contentTypes: any[]) => {\n const builder = createBuilder();\n const createdContentTypes: any[] = [];\n\n for (const contentType of contentTypes) {\n createdContentTypes.push(await createContentType(contentType, { defaultBuilder: builder }));\n }\n\n await builder.writeFiles();\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n};\n\n/**\n * Creates a content type and handle the nested components sent with it\n */\nexport const createContentType = async (\n { contentType, components }: any,\n options: CreateContentTypeOptions = {}\n) => {\n const builder = options.defaultBuilder || createBuilder();\n const uidMap = builder.createNewComponentUIDMap(components || []);\n\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const newContentType = builder.createContentType(replaceTmpUIDs(contentType));\n\n // allow components to target the new contentType\n const targetContentType = (infos: any) => {\n Object.keys(infos.attributes).forEach((key) => {\n const { target } = infos.attributes[key];\n if (target === '__contentType__') {\n infos.attributes[key].target = newContentType.uid;\n }\n });\n\n return infos;\n };\n\n components?.forEach((component: any) => {\n const options = replaceTmpUIDs(targetContentType(component));\n\n if (!_.has(component, 'uid')) {\n return builder.createComponent(options);\n }\n\n return builder.editComponent(options);\n });\n\n // generate api skeleton\n await generateAPI({\n displayName: contentType!.displayName || contentType!.info.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n\n if (!options.defaultBuilder) {\n await builder.writeFiles();\n }\n\n strapi.eventHub.emit('content-type.create', { contentType: newContentType });\n\n return newContentType;\n};\n\n/**\n * Generate an API skeleton\n */\nexport const generateAPI = ({\n singularName,\n kind = 'collectionType',\n pluralName,\n displayName,\n}: any) => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const strapiGenerators = require('@strapi/generators');\n return strapiGenerators.generate(\n 'content-type',\n {\n kind,\n singularName,\n id: singularName,\n pluralName,\n displayName,\n destination: 'new',\n bootstrapApi: true,\n attributes: [],\n },\n { dir: strapi.dirs.app.root }\n );\n};\n\n/**\n * Edits a contentType and handle the nested contentTypes sent with it\n */\nexport const editContentType = async (\n uid: UID.ContentType,\n { contentType, components = [] }: any\n) => {\n const builder = createBuilder();\n\n const previousSchema = builder.contentTypes.get(uid).schema;\n const previousKind = previousSchema.kind;\n const newKind = contentType.kind || previousKind;\n\n // Restore non-visible attributes from previous schema\n const previousAttributes = previousSchema.attributes;\n const prevNonVisibleAttributes = contentTypesUtils\n .getNonVisibleAttributes(previousSchema)\n .reduce((acc, key) => {\n if (key in previousAttributes) {\n acc[key] = previousAttributes[key];\n }\n\n return acc;\n }, {} as any);\n contentType.attributes = _.merge(prevNonVisibleAttributes, contentType.attributes);\n\n if (newKind !== previousKind && newKind === 'singleType') {\n const entryCount = await strapi.db.query(uid).count();\n if (entryCount > 1) {\n throw new ApplicationError(\n 'You cannot convert a collectionType to a singleType when having multiple entries in DB'\n );\n }\n }\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const updatedContentType = builder.editContentType({\n uid,\n ...replaceTmpUIDs(contentType),\n });\n\n components.forEach((component: any) => {\n if (!_.has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n if (newKind !== previousKind) {\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid);\n\n // generate new api skeleton\n await generateAPI({\n displayName: updatedContentType.schema.info.displayName,\n singularName: updatedContentType.schema.info.singularName,\n pluralName: updatedContentType.schema.info.pluralName,\n kind: updatedContentType.schema.kind,\n });\n\n await builder.writeFiles();\n } catch (error) {\n strapi.log.error(error);\n await apiHandler.rollback(uid);\n }\n\n return updatedContentType;\n }\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n};\n\nexport const deleteContentTypes = async (uids: UID.ContentType[]) => {\n const builder = createBuilder();\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n\n for (const uid of uids) {\n await deleteContentType(uid, builder);\n }\n\n await builder.writeFiles();\n for (const uid of uids) {\n try {\n await apiHandler.clear(uid);\n } catch (error) {\n strapi.log.error(error);\n await apiHandler.rollback(uid);\n }\n }\n};\n\n/**\n * Deletes a content type and the api files related to it\n */\nexport const deleteContentType = async (uid: UID.ContentType, defaultBuilder: any = undefined) => {\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n await apiHandler.backup(uid);\n\n const contentType = builder.deleteContentType(uid);\n\n if (!defaultBuilder) {\n try {\n await builder.writeFiles();\n await apiHandler.clear(uid);\n } catch (error) {\n await apiHandler.rollback(uid);\n }\n }\n\n strapi.eventHub.emit('content-type.delete', { contentType });\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isContentTypeVisible","model","getOr","getRestrictRelationsTo","contentType","uid","coreUids","STRAPI_USER","startsWith","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","get","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","push","createContentType","defaultBuilder","writeFiles","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapi","eventHub","emit","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","editContentType","previousSchema","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","entryCount","db","query","count","updatedContentType","apiHandler","service","backup","clear","error","log","rollback","deleteContentTypes","uids","deleteContentType","undefined"],"mappings":";;;;;;;;;AAQA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAEtB,MAAMC,uBAAuB,CAACC,KAAAA,GACnCC,SAAM,IAAA,EAAM,4CAAA,EAA8CD,WAAW;AAEhE,MAAME,yBAAyB,CAACC,WAAAA,GAAAA;IACrC,MAAM,EAAEC,GAAG,EAAE,GAAGD,WAAAA;IAChB,IAAIC,GAAAA,KAAQC,kBAAAA,CAASC,WAAW,EAAE;;QAEhC,OAAO;AAAC,YAAA,QAAA;AAAU,YAAA;AAAU,SAAA;AAC9B,IAAA;AAEA,IAA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AC,aAAA,CAAA;IACjE,MAAMD,UAAAA,CAAWE,MAAM,CAACtF,GAAAA,CAAAA;IAExB,MAAMD,WAAAA,GAAc+B,OAAAA,CAAQ+D,iBAAiB,CAAC7F,GAAAA,CAAAA;AAE9C,IAAA,IAAI,CAACmC,cAAAA,EAAgB;QACnB,IAAI;AACF,YAAA,MAAML,QAAQM,UAAU,EAAA;YACxB,MAAMgD,UAAAA,CAAWG,KAAK,CAACvF,GAAAA,CAAAA;AACzB,QAAA,CAAA,CAAE,OAAOwF,KAAAA,EAAO;YACd,MAAMJ,UAAAA,CAAWM,QAAQ,CAAC1F,GAAAA,CAAAA;AAC5B,QAAA;AACF,IAAA;AAEAwD,IAAAA,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAAC,qBAAA,EAAuB;AAAE3D,QAAAA;AAAY,KAAA,CAAA;IAE1D,OAAOA,WAAAA;AACT;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { getOr } from 'lodash/fp';\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport createBuilder from './schema-builder';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;\n\nexport const getRestrictRelationsTo = (contentType: Struct.ContentTypeSchema) => {\n const { uid } = contentType;\n if (uid === coreUids.STRAPI_USER) {\n // TODO: replace with an obj { relation: 'x', bidirectional: true|false }\n return ['oneWay', 'manyWay'];\n }\n\n if (\n uid.startsWith(coreUids.PREFIX) ||\n uid === pluginsUids.UPLOAD_FILE ||\n !isContentTypeVisible(contentType)\n ) {\n return [];\n }\n\n return null;\n};\n\n/**\n * Format a contentType info to be used by the front-end\n */\nexport const formatContentType = (contentType: any) => {\n const { uid, kind, modelName, plugin, collectionName, info } = contentType;\n\n return {\n uid,\n plugin,\n apiID: modelName,\n schema: {\n ...contentTypesUtils.getOptions(contentType),\n displayName: info.displayName,\n singularName: info.singularName,\n pluralName: info.pluralName,\n description: _.get(info, 'description', ''),\n pluginOptions: contentType.pluginOptions,\n kind: kind || 'collectionType',\n collectionName,\n attributes: formatAttributes(contentType),\n visible: isContentTypeVisible(contentType),\n restrictRelationsTo: getRestrictRelationsTo(contentType),\n },\n };\n};\n\nexport const createContentTypes = async (contentTypes: any[]) => {\n const builder = createBuilder();\n const createdContentTypes: any[] = [];\n\n for (const contentType of contentTypes) {\n createdContentTypes.push(await createContentType(contentType, { defaultBuilder: builder }));\n }\n\n await builder.writeFiles();\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n};\n\n/**\n * Creates a content type and handle the nested components sent with it\n */\nexport const createContentType = async (\n { contentType, components }: any,\n options: CreateContentTypeOptions = {}\n) => {\n const builder = options.defaultBuilder || createBuilder();\n const uidMap = builder.createNewComponentUIDMap(components || []);\n\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const newContentType = builder.createContentType(replaceTmpUIDs(contentType));\n\n // allow components to target the new contentType\n const targetContentType = (infos: any) => {\n Object.keys(infos.attributes).forEach((key) => {\n const { target } = infos.attributes[key];\n if (target === '__contentType__') {\n infos.attributes[key].target = newContentType.uid;\n }\n });\n\n return infos;\n };\n\n components?.forEach((component: any) => {\n const options = replaceTmpUIDs(targetContentType(component));\n\n if (!_.has(component, 'uid')) {\n return builder.createComponent(options);\n }\n\n return builder.editComponent(options);\n });\n\n // generate api skeleton\n await generateAPI({\n displayName: contentType!.displayName || contentType!.info.displayName,\n singularName: contentType!.singularName,\n pluralName: contentType!.pluralName,\n kind: contentType!.kind,\n });\n\n if (!options.defaultBuilder) {\n await builder.writeFiles();\n }\n\n strapi.eventHub.emit('content-type.create', { contentType: newContentType });\n\n return newContentType;\n};\n\n/**\n * Generate an API skeleton\n */\nexport const generateAPI = ({\n singularName,\n kind = 'collectionType',\n pluralName,\n displayName,\n}: any) => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const strapiGenerators = require('@strapi/generators');\n return strapiGenerators.generate(\n 'content-type',\n {\n kind,\n singularName,\n id: singularName,\n pluralName,\n displayName,\n destination: 'new',\n bootstrapApi: true,\n attributes: [],\n },\n { dir: strapi.dirs.app.root }\n );\n};\n\n/**\n * Edits a contentType and handle the nested contentTypes sent with it\n */\nexport const editContentType = async (\n uid: UID.ContentType,\n { contentType, components = [] }: any\n) => {\n const builder = createBuilder();\n\n const previousSchema = builder.contentTypes.get(uid).schema;\n const previousKind = previousSchema.kind;\n const newKind = contentType.kind || previousKind;\n\n // Restore non-visible attributes from previous schema\n const previousAttributes = previousSchema.attributes;\n const prevNonVisibleAttributes = contentTypesUtils\n .getNonVisibleAttributes(previousSchema)\n .reduce((acc, key) => {\n if (key in previousAttributes) {\n acc[key] = previousAttributes[key];\n }\n\n return acc;\n }, {} as any);\n contentType.attributes = _.merge(prevNonVisibleAttributes, contentType.attributes);\n\n if (newKind !== previousKind && newKind === 'singleType') {\n const entryCount = await strapi.db.query(uid).count();\n if (entryCount > 1) {\n throw new ApplicationError(\n 'You cannot convert a collectionType to a singleType when having multiple entries in DB'\n );\n }\n }\n\n const uidMap = builder.createNewComponentUIDMap(components);\n const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);\n\n const updatedContentType = builder.editContentType({\n uid,\n ...replaceTmpUIDs(contentType),\n });\n\n components.forEach((component: any) => {\n if (!_.has(component, 'uid')) {\n return builder.createComponent(replaceTmpUIDs(component));\n }\n\n return builder.editComponent(replaceTmpUIDs(component));\n });\n\n if (newKind !== previousKind) {\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid);\n\n // generate new api skeleton\n await generateAPI({\n displayName: updatedContentType.schema.info.displayName,\n singularName: updatedContentType.schema.info.singularName,\n pluralName: updatedContentType.schema.info.pluralName,\n kind: updatedContentType.schema.kind,\n });\n\n await builder.writeFiles();\n } catch (error) {\n strapi.log.error(error);\n await apiHandler.rollback(uid);\n }\n\n return updatedContentType;\n }\n\n await builder.writeFiles();\n\n strapi.eventHub.emit('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n};\n\nexport const deleteContentTypes = async (uids: UID.ContentType[]) => {\n const builder = createBuilder();\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n\n for (const uid of uids) {\n await deleteContentType(uid, builder);\n }\n\n await builder.writeFiles();\n for (const uid of uids) {\n try {\n await apiHandler.clear(uid);\n } catch (error) {\n strapi.log.error(error);\n await apiHandler.rollback(uid);\n }\n }\n};\n\n/**\n * Deletes a content type and the api files related to it\n */\nexport const deleteContentType = async (uid: UID.ContentType, defaultBuilder: any = undefined) => {\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi.plugin('content-type-builder').service('api-handler');\n await apiHandler.backup(uid);\n\n const contentType = builder.deleteContentType(uid);\n\n if (!defaultBuilder) {\n try {\n await builder.writeFiles();\n await apiHandler.clear(uid);\n } catch (error) {\n await apiHandler.rollback(uid);\n }\n }\n\n strapi.eventHub.emit('content-type.delete', { contentType });\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isContentTypeVisible","model","getOr","getRestrictRelationsTo","contentType","uid","coreUids","STRAPI_USER","startsWith","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","get","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","push","createContentType","defaultBuilder","writeFiles","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapi","eventHub","emit","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","editContentType","previousSchema","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","entryCount","db","query","count","updatedContentType","apiHandler","service","backup","clear","error","log","rollback","deleteContentTypes","uids","deleteContentType","undefined"],"mappings":";;;;;;;;;;;;;AAQA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAEtB,MAAMC,uBAAuB,CAACC,KAAAA,GACnCC,SAAM,IAAA,EAAM,4CAAA,EAA8CD,WAAW;AAEhE,MAAME,yBAAyB,CAACC,WAAAA,GAAAA;IACrC,MAAM,EAAEC,GAAG,EAAE,GAAGD,WAAAA;IAChB,IAAIC,GAAAA,KAAQC,kBAAAA,CAASC,WAAW,EAAE;;QAEhC,OAAO;AAAC,YAAA,QAAA;AAAU,YAAA;AAAU,SAAA;AAC9B,IAAA;AAEA,IAAA,IACEF,GAAAA,CAAIG,UAAU,CAACF,kBAAAA,CAASG,MAAM,CAAA,IAC9BJ,GAAAA,KAAQK,qBAAAA,CAAYC,WAAW,IAC/B,CAACX,oBAAAA,CAAqBI,WAAAA,CAAAA,EACtB;AACA,QAAA,OAAO,EAAE;AACX,IAAA;IAEA,OAAO,IAAA;AACT;AAEA;;IAGO,MAAMQ,iBAAAA,GAAoB,CAACR,WAAAA,GAAAA;AAChC,IAAA,MAAM,EAAEC,GAAG,EAAEQ,IAAI,EAAEC,SAAS,EAAEC,MAAM,EAAEC,cAAc,EAAEC,IAAI,EAAE,GAAGb,WAAAA;IAE/D,OAAO;AACLC,QAAAA,GAAAA;AACAU,QAAAA,MAAAA;QACAG,KAAAA,EAAOJ,SAAAA;QACPK,MAAAA,EAAQ;YACN,GAAGC,kBAAAA,CAAkBC,UAAU,CAACjB,WAAAA,CAAY;AAC5CkB,YAAAA,WAAAA,EAAaL,KAAKK,WAAW;AAC7BC,YAAAA,YAAAA,EAAcN,KAAKM,YAAY;AAC/BC,YAAAA,UAAAA,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
|
var schemaHandler = require('./schema-handler.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
14
|
+
var pluralize__default = /*#__PURE__*/_interopDefault(pluralize);
|
|
15
|
+
|
|
10
16
|
const { ApplicationError } = utils.errors;
|
|
11
17
|
function createComponentBuilder() {
|
|
12
18
|
return {
|
|
@@ -36,12 +42,12 @@ function createComponentBuilder() {
|
|
|
36
42
|
throw new ApplicationError('component.alreadyExists');
|
|
37
43
|
}
|
|
38
44
|
const handler = schemaHandler({
|
|
39
|
-
dir:
|
|
45
|
+
dir: path__default.default.join(strapi.dirs.app.components, utils.strings.nameToSlug(infos.category)),
|
|
40
46
|
filename: `${utils.strings.nameToSlug(infos.displayName)}.json`
|
|
41
47
|
});
|
|
42
48
|
// TODO: create a utility for this
|
|
43
49
|
// Duplicate in admin/src/components/FormModal/forms/utils/createCollectionName.ts
|
|
44
|
-
const collectionName = `components_${utils.strings.nameToCollectionName(infos.category)}_${utils.strings.nameToCollectionName(
|
|
50
|
+
const collectionName = `components_${utils.strings.nameToCollectionName(infos.category)}_${utils.strings.nameToCollectionName(pluralize__default.default(infos.displayName))}`;
|
|
45
51
|
this.components.forEach((compo)=>{
|
|
46
52
|
if (compo.schema.collectionName === collectionName) {
|
|
47
53
|
throw new ApplicationError('component.alreadyExists');
|
|
@@ -80,10 +86,10 @@ function createComponentBuilder() {
|
|
|
80
86
|
if (newUID !== uid && this.components.has(newUID)) {
|
|
81
87
|
throw new utils.errors.ApplicationError('component.edit.alreadyExists');
|
|
82
88
|
}
|
|
83
|
-
const newDir =
|
|
89
|
+
const newDir = path__default.default.join(strapi.dirs.app.components, newCategory);
|
|
84
90
|
const oldAttributes = component.schema.attributes;
|
|
85
|
-
const newAttributes =
|
|
86
|
-
return
|
|
91
|
+
const newAttributes = ___default.default.omitBy(infos.attributes, (attr, key)=>{
|
|
92
|
+
return ___default.default.has(oldAttributes, key) && !attributes.isConfigurable(oldAttributes[key]);
|
|
87
93
|
});
|
|
88
94
|
component.setUID(newUID).setDir(newDir).set([
|
|
89
95
|
'info',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-builder.js","sources":["../../../../server/src/services/schema-builder/component-builder.ts"],"sourcesContent":["import path from 'path';\nimport type { Internal } from '@strapi/types';\nimport _ from 'lodash';\nimport pluralize from 'pluralize';\n\nimport { strings, errors } from '@strapi/utils';\nimport { isConfigurable } from '../../utils/attributes';\nimport createSchemaHandler from './schema-handler';\n\nconst { ApplicationError } = errors;\n\nexport default function createComponentBuilder() {\n return {\n createComponentUID({ category, displayName }: any) {\n return `${strings.nameToSlug(category)}.${strings.nameToSlug(displayName)}`;\n },\n\n createNewComponentUIDMap(components: object[]) {\n return components.reduce((uidMap: any, component: any) => {\n uidMap[component.tmpUID] = this.createComponentUID(component);\n return uidMap;\n }, {});\n },\n\n createComponentAttributes(this: any, uid: string, attributes: any) {\n if (!this.components.has(uid)) {\n throw new ApplicationError('component.notFound');\n }\n\n return this.components.get(uid).setAttributes(this.convertAttributes(attributes));\n },\n\n /**\n * create a component in the tmpComponent map\n */\n createComponent(this: any, infos: any) {\n if (infos.uid && infos.uid !== this.createComponentUID(infos)) {\n throw new ApplicationError('component.invalidUID');\n }\n\n const uid = infos.uid ?? this.createComponentUID(infos);\n\n if (this.components.has(uid)) {\n throw new ApplicationError('component.alreadyExists');\n }\n\n const handler = createSchemaHandler({\n dir: path.join(strapi.dirs.app.components, strings.nameToSlug(infos.category)),\n filename: `${strings.nameToSlug(infos.displayName)}.json`,\n });\n\n // TODO: create a utility for this\n // Duplicate in admin/src/components/FormModal/forms/utils/createCollectionName.ts\n const collectionName = `components_${strings.nameToCollectionName(\n infos.category\n )}_${strings.nameToCollectionName(pluralize(infos.displayName))}`;\n\n this.components.forEach((compo: any) => {\n if (compo.schema.collectionName === collectionName) {\n throw new ApplicationError('component.alreadyExists');\n }\n });\n\n handler\n .setUID(uid)\n .set('collectionName', collectionName)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'icon'], infos.icon)\n .set(['info', 'description'], infos.description)\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n if (this.components.size === 0) {\n strapi.telemetry.send('didCreateFirstComponent');\n } else {\n strapi.telemetry.send('didCreateComponent');\n }\n\n this.components.set(uid, handler);\n\n this.createComponentAttributes(uid, infos.attributes);\n\n return handler;\n },\n\n /**\n * create a component in the tmpComponent map\n */\n editComponent(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.components.has(uid)) {\n throw new errors.ApplicationError('component.notFound');\n }\n\n const component = this.components.get(uid);\n\n const [, nameUID] = uid.split('.');\n\n const newCategory = strings.nameToSlug(infos.category);\n const newUID = `${newCategory}.${nameUID}`;\n\n if (newUID !== uid && this.components.has(newUID)) {\n throw new errors.ApplicationError('component.edit.alreadyExists');\n }\n\n const newDir = path.join(strapi.dirs.app.components, newCategory);\n\n const oldAttributes = component.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n component\n .setUID(newUID)\n .setDir(newDir)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'icon'], infos.icon)\n .set(['info', 'description'], infos.description)\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n if (newUID !== uid) {\n this.components.forEach((compo: any) => {\n compo.updateComponent(uid, newUID);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.updateComponent(uid, newUID);\n });\n }\n\n return component;\n },\n\n deleteComponent(this: any, uid: Internal.UID.Component) {\n if (!this.components.has(uid)) {\n throw new errors.ApplicationError('component.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeComponent(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeComponent(uid);\n });\n\n return this.components.get(uid).delete();\n },\n };\n}\n"],"names":["ApplicationError","errors","createComponentBuilder","createComponentUID","category","displayName","strings","nameToSlug","createNewComponentUIDMap","components","reduce","uidMap","component","tmpUID","createComponentAttributes","uid","attributes","has","get","setAttributes","convertAttributes","createComponent","infos","handler","createSchemaHandler","dir","path","join","strapi","dirs","app","filename","collectionName","nameToCollectionName","pluralize","forEach","compo","schema","setUID","set","icon","description","pluginOptions","config","size","telemetry","send","editComponent","nameUID","split","newCategory","newUID","newDir","oldAttributes","newAttributes","_","omitBy","attr","key","isConfigurable","setDir","updateComponent","contentTypes","ct","deleteComponent","removeComponent","delete"],"mappings":";;;;;;;;;AASA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAEd,SAASC,sBAAAA,GAAAA;IACtB,OAAO;AACLC,QAAAA,kBAAAA,CAAAA,CAAmB,EAAEC,QAAQ,EAAEC,WAAW,EAAO,EAAA;YAC/C,OAAO,CAAA,EAAGC,aAAAA,CAAQC,UAAU,CAACH,QAAAA,CAAAA,CAAU,CAAC,EAAEE,aAAAA,CAAQC,UAAU,CAACF,WAAAA,CAAAA,CAAAA,CAAc;AAC7E,QAAA,CAAA;AAEAG,QAAAA,wBAAAA,CAAAA,CAAyBC,UAAoB,EAAA;AAC3C,YAAA,OAAOA,UAAAA,CAAWC,MAAM,CAAC,CAACC,MAAAA,EAAaC,SAAAA,GAAAA;gBACrCD,MAAM,CAACC,UAAUC,MAAM,CAAC,GAAG,IAAI,CAACV,kBAAkB,CAACS,SAAAA,CAAAA;gBACnD,OAAOD,MAAAA;AACT,YAAA,CAAA,EAAG,EAAC,CAAA;AACN,QAAA,CAAA;QAEAG,yBAAAA,CAAAA,CAAqCC,GAAW,EAAEC,UAAe,EAAA;AAC/D,YAAA,IAAI,CAAC,IAAI,CAACP,UAAU,CAACQ,GAAG,CAACF,GAAAA,CAAAA,EAAM;AAC7B,gBAAA,MAAM,IAAIf,gBAAAA,CAAiB,oBAAA,CAAA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AAO,CAAC,CAAC4B,EAAAA,GAAAA;AACzBA,gBAAAA,EAAAA,CAAGE,eAAe,CAAClD,GAAAA,CAAAA;AACrB,YAAA,CAAA,CAAA;AAEA,YAAA,OAAO,IAAI,CAACN,UAAU,CAACS,GAAG,CAACH,KAAKmD,MAAM,EAAA;AACxC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"component-builder.js","sources":["../../../../server/src/services/schema-builder/component-builder.ts"],"sourcesContent":["import path from 'path';\nimport type { Internal } from '@strapi/types';\nimport _ from 'lodash';\nimport pluralize from 'pluralize';\n\nimport { strings, errors } from '@strapi/utils';\nimport { isConfigurable } from '../../utils/attributes';\nimport createSchemaHandler from './schema-handler';\n\nconst { ApplicationError } = errors;\n\nexport default function createComponentBuilder() {\n return {\n createComponentUID({ category, displayName }: any) {\n return `${strings.nameToSlug(category)}.${strings.nameToSlug(displayName)}`;\n },\n\n createNewComponentUIDMap(components: object[]) {\n return components.reduce((uidMap: any, component: any) => {\n uidMap[component.tmpUID] = this.createComponentUID(component);\n return uidMap;\n }, {});\n },\n\n createComponentAttributes(this: any, uid: string, attributes: any) {\n if (!this.components.has(uid)) {\n throw new ApplicationError('component.notFound');\n }\n\n return this.components.get(uid).setAttributes(this.convertAttributes(attributes));\n },\n\n /**\n * create a component in the tmpComponent map\n */\n createComponent(this: any, infos: any) {\n if (infos.uid && infos.uid !== this.createComponentUID(infos)) {\n throw new ApplicationError('component.invalidUID');\n }\n\n const uid = infos.uid ?? this.createComponentUID(infos);\n\n if (this.components.has(uid)) {\n throw new ApplicationError('component.alreadyExists');\n }\n\n const handler = createSchemaHandler({\n dir: path.join(strapi.dirs.app.components, strings.nameToSlug(infos.category)),\n filename: `${strings.nameToSlug(infos.displayName)}.json`,\n });\n\n // TODO: create a utility for this\n // Duplicate in admin/src/components/FormModal/forms/utils/createCollectionName.ts\n const collectionName = `components_${strings.nameToCollectionName(\n infos.category\n )}_${strings.nameToCollectionName(pluralize(infos.displayName))}`;\n\n this.components.forEach((compo: any) => {\n if (compo.schema.collectionName === collectionName) {\n throw new ApplicationError('component.alreadyExists');\n }\n });\n\n handler\n .setUID(uid)\n .set('collectionName', collectionName)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'icon'], infos.icon)\n .set(['info', 'description'], infos.description)\n .set('pluginOptions', infos.pluginOptions)\n .set('config', infos.config);\n\n if (this.components.size === 0) {\n strapi.telemetry.send('didCreateFirstComponent');\n } else {\n strapi.telemetry.send('didCreateComponent');\n }\n\n this.components.set(uid, handler);\n\n this.createComponentAttributes(uid, infos.attributes);\n\n return handler;\n },\n\n /**\n * create a component in the tmpComponent map\n */\n editComponent(this: any, infos: any) {\n const { uid } = infos;\n\n if (!this.components.has(uid)) {\n throw new errors.ApplicationError('component.notFound');\n }\n\n const component = this.components.get(uid);\n\n const [, nameUID] = uid.split('.');\n\n const newCategory = strings.nameToSlug(infos.category);\n const newUID = `${newCategory}.${nameUID}`;\n\n if (newUID !== uid && this.components.has(newUID)) {\n throw new errors.ApplicationError('component.edit.alreadyExists');\n }\n\n const newDir = path.join(strapi.dirs.app.components, newCategory);\n\n const oldAttributes = component.schema.attributes;\n\n const newAttributes = _.omitBy(infos.attributes, (attr, key) => {\n return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);\n });\n\n component\n .setUID(newUID)\n .setDir(newDir)\n .set(['info', 'displayName'], infos.displayName)\n .set(['info', 'icon'], infos.icon)\n .set(['info', 'description'], infos.description)\n .set('pluginOptions', infos.pluginOptions)\n .setAttributes(this.convertAttributes(newAttributes));\n\n if (newUID !== uid) {\n this.components.forEach((compo: any) => {\n compo.updateComponent(uid, newUID);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.updateComponent(uid, newUID);\n });\n }\n\n return component;\n },\n\n deleteComponent(this: any, uid: Internal.UID.Component) {\n if (!this.components.has(uid)) {\n throw new errors.ApplicationError('component.notFound');\n }\n\n this.components.forEach((compo: any) => {\n compo.removeComponent(uid);\n });\n\n this.contentTypes.forEach((ct: any) => {\n ct.removeComponent(uid);\n });\n\n return this.components.get(uid).delete();\n },\n };\n}\n"],"names":["ApplicationError","errors","createComponentBuilder","createComponentUID","category","displayName","strings","nameToSlug","createNewComponentUIDMap","components","reduce","uidMap","component","tmpUID","createComponentAttributes","uid","attributes","has","get","setAttributes","convertAttributes","createComponent","infos","handler","createSchemaHandler","dir","path","join","strapi","dirs","app","filename","collectionName","nameToCollectionName","pluralize","forEach","compo","schema","setUID","set","icon","description","pluginOptions","config","size","telemetry","send","editComponent","nameUID","split","newCategory","newUID","newDir","oldAttributes","newAttributes","_","omitBy","attr","key","isConfigurable","setDir","updateComponent","contentTypes","ct","deleteComponent","removeComponent","delete"],"mappings":";;;;;;;;;;;;;;;AASA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAEd,SAASC,sBAAAA,GAAAA;IACtB,OAAO;AACLC,QAAAA,kBAAAA,CAAAA,CAAmB,EAAEC,QAAQ,EAAEC,WAAW,EAAO,EAAA;YAC/C,OAAO,CAAA,EAAGC,aAAAA,CAAQC,UAAU,CAACH,QAAAA,CAAAA,CAAU,CAAC,EAAEE,aAAAA,CAAQC,UAAU,CAACF,WAAAA,CAAAA,CAAAA,CAAc;AAC7E,QAAA,CAAA;AAEAG,QAAAA,wBAAAA,CAAAA,CAAyBC,UAAoB,EAAA;AAC3C,YAAA,OAAOA,UAAAA,CAAWC,MAAM,CAAC,CAACC,MAAAA,EAAaC,SAAAA,GAAAA;gBACrCD,MAAM,CAACC,UAAUC,MAAM,CAAC,GAAG,IAAI,CAACV,kBAAkB,CAACS,SAAAA,CAAAA;gBACnD,OAAOD,MAAAA;AACT,YAAA,CAAA,EAAG,EAAC,CAAA;AACN,QAAA,CAAA;QAEAG,yBAAAA,CAAAA,CAAqCC,GAAW,EAAEC,UAAe,EAAA;AAC/D,YAAA,IAAI,CAAC,IAAI,CAACP,UAAU,CAACQ,GAAG,CAACF,GAAAA,CAAAA,EAAM;AAC7B,gB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AA,CAAA;AAEA,YAAA,IAAI,CAAC+C,YAAY,CAAC3B,OAAO,CAAC,CAAC4B,EAAAA,GAAAA;AACzBA,gBAAAA,EAAAA,CAAGE,eAAe,CAAClD,GAAAA,CAAAA;AACrB,YAAA,CAAA,CAAA;AAEA,YAAA,OAAO,IAAI,CAACN,UAAU,CAACS,GAAG,CAACH,KAAKmD,MAAM,EAAA;AACxC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -7,9 +7,14 @@ var attributes = require('../../utils/attributes.js');
|
|
|
7
7
|
var constants = require('../constants.js');
|
|
8
8
|
var schemaHandler = require('./schema-handler.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
14
|
+
|
|
10
15
|
const { ApplicationError } = utils.errors;
|
|
11
16
|
const reuseUnsetPreviousProperties = (newAttribute, oldAttribute)=>{
|
|
12
|
-
|
|
17
|
+
___default.default.defaults(newAttribute, ___default.default.omit(oldAttribute, [
|
|
13
18
|
'configurable',
|
|
14
19
|
'required',
|
|
15
20
|
'private',
|
|
@@ -23,7 +28,7 @@ const reuseUnsetPreviousProperties = (newAttribute, oldAttribute)=>{
|
|
|
23
28
|
function createComponentBuilder() {
|
|
24
29
|
return {
|
|
25
30
|
setRelation ({ key, uid, attribute }) {
|
|
26
|
-
if (!
|
|
31
|
+
if (!___default.default.has(attribute, 'target')) {
|
|
27
32
|
return;
|
|
28
33
|
}
|
|
29
34
|
const targetCT = this.contentTypes.get(attribute.target);
|
|
@@ -109,7 +114,7 @@ function createComponentBuilder() {
|
|
|
109
114
|
if (this.contentTypes.has(uid)) {
|
|
110
115
|
throw new ApplicationError('contentType.alreadyExists');
|
|
111
116
|
}
|
|
112
|
-
const dir = infos.plugin ?
|
|
117
|
+
const dir = infos.plugin ? path__default.default.join(strapi.dirs.app.extensions, infos.plugin, 'content-types', infos.singularName) : path__default.default.join(strapi.dirs.app.api, infos.singularName, 'content-types', infos.singularName);
|
|
113
118
|
const contentType = schemaHandler({
|
|
114
119
|
modelName: infos.singularName,
|
|
115
120
|
dir,
|
|
@@ -135,12 +140,12 @@ function createComponentBuilder() {
|
|
|
135
140
|
}
|
|
136
141
|
const contentType = this.contentTypes.get(uid);
|
|
137
142
|
const oldAttributes = contentType.schema.attributes;
|
|
138
|
-
const newAttributes =
|
|
139
|
-
return
|
|
143
|
+
const newAttributes = ___default.default.omitBy(infos.attributes, (attr, key)=>{
|
|
144
|
+
return ___default.default.has(oldAttributes, key) && !attributes.isConfigurable(oldAttributes[key]);
|
|
140
145
|
});
|
|
141
|
-
const newKeys =
|
|
142
|
-
const deletedKeys =
|
|
143
|
-
const remainingKeys =
|
|
146
|
+
const newKeys = ___default.default.difference(Object.keys(newAttributes), Object.keys(oldAttributes));
|
|
147
|
+
const deletedKeys = ___default.default.difference(Object.keys(oldAttributes), Object.keys(newAttributes));
|
|
148
|
+
const remainingKeys = ___default.default.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));
|
|
144
149
|
// remove old relations
|
|
145
150
|
deletedKeys.forEach((key)=>{
|
|
146
151
|
const attribute = oldAttributes[key];
|
|
@@ -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\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\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 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 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","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","get","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","set","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","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","deleteContentType","components","compo","removeContentType","ct","delete","opts","type","private","restOptions","result"],"mappings":";;;;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;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;AAEe,SAASI,sBAAAA,GAAAA;IACtB,OAAO;AACLC,QAAAA,WAAAA,CAAAA,CAEE,EAAEC,GAAG,EAAEC,GAAG,EAAEC,SAAS,EAAsE,EAAA;AAE3F,YAAA,IAAI,CAACP,CAAAA,CAAEQ,GAAG,CAACD,WAAW,QAAA,CAAA,EAAW;AAC/B,gBAAA;AACF,YAAA;YAEA,MAAME,QAAAA,GAAW,IAAI,CAACC,YAAY,CAACC,GAAG,CAACJ,UAAUK,MAAM,CAAA;AAEvD,YAAA,IAAI,CAACH,QAAAA,EAAU;gBACb,MAAM,IAAId,iBAAiB,CAAC,aAAa,EAAEY,S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,MAAMI,MAAAA,GAAS;AACbH,QAAAA,IAAAA;AACA5D,QAAAA,QAAAA;AACAtB,QAAAA,MAAAA;AACA,QAAA,GAAGoF;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\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\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 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 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","createComponentBuilder","setRelation","key","uid","attribute","has","targetCT","contentTypes","get","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","set","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","oldRelationAttribute","oldTargetAttributeName","sameRelation","targetAttributeHasChanged","newAttributeFromInfos","hasNewConditions","conditions","deleteContentType","components","compo","removeContentType","ct","delete","opts","type","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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AAA;AAClB,gBAAA;AACF,YAAA;QACA,KAAK,WAAA;AAAa,YAAA;AAChBwF,gBAAAA,IAAAA,CAAK3D,QAAQ,GAAG,WAAA;AAChB2D,gBAAAA,IAAAA,CAAKvE,QAAQ,GAAGjB,GAAAA;AAChB,gBAAA;AACF,YAAA;QACA,KAAK,YAAA;AAAc,YAAA;AACjBwF,gBAAAA,IAAAA,CAAK3D,QAAQ,GAAG,YAAA;gBAEhB,IAAI3B,SAAAA,CAAU6B,QAAQ,EAAE;AACtByD,oBAAAA,IAAAA,CAAKvE,QAAQ,GAAGjB,GAAAA;gBAClB,CAAA,MAAO;AACLwF,oBAAAA,IAAAA,CAAKxE,UAAU,GAAGhB,GAAAA;AACpB,gBAAA;AAEA,gBAAA;AACF,YAAA;AAEF;;IAGA,MAAM,EAAEyF,IAAI,EAAE5D,QAAQ,EAAEtB,MAAM,EAAE,GAAGoF,WAAAA,EAAa,GAAGH,IAAAA;AAEnD,IAAA,MAAMI,MAAAA,GAAS;AACbH,QAAAA,IAAAA;AACA5D,QAAAA,QAAAA;AACAtB,QAAAA,MAAAA;AACA,QAAA,GAAGoF;AACL,KAAA;IAEA,OAAOC,MAAAA;AACT,CAAA;;;;"}
|
|
@@ -7,6 +7,10 @@ var schemaHandler = require('./schema-handler.js');
|
|
|
7
7
|
var componentBuilder = require('./component-builder.js');
|
|
8
8
|
var contentTypeBuilder = require('./content-type-builder.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Creates a content type schema builder instance
|
|
12
16
|
*/ function createBuilder() {
|
|
@@ -86,7 +90,7 @@ function createSchemaBuilder({ components, contentTypes }) {
|
|
|
86
90
|
// if (target && !this.contentTypes.has(target)) {
|
|
87
91
|
// throw new errors.ApplicationError(`target: ${target} does not exist`);
|
|
88
92
|
// }
|
|
89
|
-
if (
|
|
93
|
+
if (___default.default.isNil(targetAttribute)) {
|
|
90
94
|
return attr;
|
|
91
95
|
}
|
|
92
96
|
if ([
|