@strapi/content-type-builder 5.59.0 → 5.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/controllers/validation/common.js +1 -1
- package/dist/server/controllers/validation/common.js.map +1 -1
- package/dist/server/controllers/validation/common.mjs +1 -1
- package/dist/server/controllers/validation/common.mjs.map +1 -1
- package/dist/server/controllers/validation/model-schema.js +3 -1
- package/dist/server/controllers/validation/model-schema.js.map +1 -1
- package/dist/server/controllers/validation/model-schema.mjs +3 -1
- package/dist/server/controllers/validation/model-schema.mjs.map +1 -1
- package/dist/server/middlewares/index.js +6 -2
- package/dist/server/middlewares/index.js.map +1 -1
- package/dist/server/middlewares/index.mjs +9 -1
- package/dist/server/middlewares/index.mjs.map +1 -1
- package/dist/server/middlewares/is-development-mode.js +2 -2
- package/dist/server/middlewares/is-development-mode.js.map +1 -1
- package/dist/server/middlewares/is-development-mode.mjs +2 -2
- package/dist/server/middlewares/is-development-mode.mjs.map +1 -1
- package/dist/server/routes/admin.js.map +1 -1
- package/dist/server/routes/admin.mjs +10 -10
- package/dist/server/routes/admin.mjs.map +1 -1
- package/dist/server/services/components.js +4 -3
- package/dist/server/services/components.js.map +1 -1
- package/dist/server/services/components.mjs +4 -3
- package/dist/server/services/components.mjs.map +1 -1
- package/dist/server/services/content-types.js +59 -9
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/content-types.mjs +59 -10
- package/dist/server/services/content-types.mjs.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.js +5 -2
- package/dist/server/services/schema-builder/content-type-builder.js.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.mjs +5 -2
- package/dist/server/services/schema-builder/content-type-builder.mjs.map +1 -1
- package/dist/server/services/schema-builder/index.js +0 -1
- package/dist/server/services/schema-builder/index.js.map +1 -1
- package/dist/server/services/schema-builder/index.mjs +0 -1
- package/dist/server/services/schema-builder/index.mjs.map +1 -1
- package/dist/server/services/schema.js +15 -6
- package/dist/server/services/schema.js.map +1 -1
- package/dist/server/services/schema.mjs +16 -7
- package/dist/server/services/schema.mjs.map +1 -1
- package/dist/server/src/middlewares/index.d.ts +6 -1
- package/dist/server/src/middlewares/index.d.ts.map +1 -1
- package/dist/server/src/services/components.d.ts.map +1 -1
- package/dist/server/src/services/content-types.d.ts +4 -0
- package/dist/server/src/services/content-types.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/content-type-builder.d.ts.map +1 -1
- package/dist/server/src/services/schema-builder/index.d.ts.map +1 -1
- package/dist/server/src/services/schema.d.ts.map +1 -1
- package/dist/server/src/utils/events.d.ts +10 -0
- package/dist/server/src/utils/events.d.ts.map +1 -0
- package/dist/server/utils/events.js +52 -0
- package/dist/server/utils/events.js.map +1 -0
- package/dist/server/utils/events.mjs +50 -0
- package/dist/server/utils/events.mjs.map +1 -0
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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
|
|
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 { emitSchemaEvent } from '../utils/events';\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 await emitSchemaEvent('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 await emitSchemaEvent('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 await emitSchemaEvent('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","emitSchemaEvent","updatedComponent","deleteComponent","deletedComponent"],"mappings":";;;;;AAQA;;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,EAAeb,UAAUa,aAAa;AACtCC,YAAAA,UAAAA,EAAYC,gBAAAA,CAAiBf,SAAAA;AAC/B;AACF,KAAA;AACF;AAEA;;UAGagB,eAAAA,GAAkB,OAAO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WQ,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;AAExB,IAAA,MAAMC,gBAAgB,kBAAA,EAAoB;QAAE7B,SAAAA,EAAW8B;AAAiB,KAAA,CAAA;IAExE,OAAOA,gBAAAA;AACT;AAEO,MAAMC,kBAAkB,OAAO9B,GAAAA,GAAAA;AACpC,IAAA,MAAMiB,OAAAA,GAAUC,aAAAA,EAAAA;IAEhB,MAAMa,gBAAAA,GAAmBd,OAAAA,CAAQa,eAAe,CAAC9B,GAAAA,CAAAA;AAEjD,IAAA,MAAMiB,QAAQU,UAAU,EAAA;AAExB,IAAA,MAAMC,gBAAgB,kBAAA,EAAoB;QAAE7B,SAAAA,EAAWgC;AAAiB,KAAA,CAAA;IAExE,OAAOA,gBAAAA;AACT;;;;"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var utils = require('@strapi/utils');
|
|
5
5
|
var attributes = require('../utils/attributes.js');
|
|
6
|
+
var events = require('../utils/events.js');
|
|
6
7
|
var index$1 = require('../utils/index.js');
|
|
7
8
|
var index = require('./schema-builder/index.js');
|
|
8
9
|
var schemaMutation = require('./schema-mutation.js');
|
|
@@ -91,7 +92,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
91
92
|
throw error;
|
|
92
93
|
}
|
|
93
94
|
for (const contentType of createdContentTypes){
|
|
94
|
-
|
|
95
|
+
await events.emitSchemaEvent('content-type.create', {
|
|
95
96
|
contentType
|
|
96
97
|
});
|
|
97
98
|
}
|
|
@@ -154,7 +155,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
154
155
|
throw error;
|
|
155
156
|
}
|
|
156
157
|
if (!options.deferEvent) {
|
|
157
|
-
|
|
158
|
+
await events.emitSchemaEvent('content-type.create', {
|
|
158
159
|
contentType: newContentType
|
|
159
160
|
});
|
|
160
161
|
}
|
|
@@ -178,10 +179,58 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
178
179
|
dir: strapi.dirs.app.root
|
|
179
180
|
});
|
|
180
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* A document can span several rows (draft and published versions, one per locale),
|
|
184
|
+
* so compare documentIds instead of counting rows.
|
|
185
|
+
* A row without documentId (raw SQL, imports) cannot be tied to any document, so it
|
|
186
|
+
* counts as another one. `$ne` alone would skip it, as SQL `<>` never matches NULL.
|
|
187
|
+
*/ const hasMultipleDocuments = async (uid)=>{
|
|
188
|
+
const firstEntry = await strapi.db.query(uid).findOne({
|
|
189
|
+
select: [
|
|
190
|
+
'documentId'
|
|
191
|
+
],
|
|
192
|
+
where: {
|
|
193
|
+
documentId: {
|
|
194
|
+
$notNull: true
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
if (firstEntry === null) {
|
|
199
|
+
const rowsCount = await strapi.db.query(uid).count();
|
|
200
|
+
return rowsCount > 1;
|
|
201
|
+
}
|
|
202
|
+
const otherDocumentsCount = await strapi.db.query(uid).count({
|
|
203
|
+
where: {
|
|
204
|
+
$or: [
|
|
205
|
+
{
|
|
206
|
+
documentId: {
|
|
207
|
+
$ne: firstEntry.documentId
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
documentId: {
|
|
212
|
+
$null: true
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return otherDocumentsCount > 0;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* A single type holds one document, so refuse the switch while several exist.
|
|
222
|
+
*/ const assertCanConvertToSingleType = async (uid)=>{
|
|
223
|
+
if (await hasMultipleDocuments(uid) === true) {
|
|
224
|
+
throw new ApplicationError('You cannot convert a collectionType to a singleType when having multiple entries in DB');
|
|
225
|
+
}
|
|
226
|
+
};
|
|
181
227
|
/**
|
|
182
228
|
* Edits a contentType and handle the nested contentTypes sent with it
|
|
183
229
|
*/ const editContentType = async (uid, { contentType, components = [] })=>{
|
|
184
230
|
const builder = index();
|
|
231
|
+
if (builder.contentTypes.has(uid) === false) {
|
|
232
|
+
throw new ApplicationError('contentType.notFound');
|
|
233
|
+
}
|
|
185
234
|
const previousSchema = builder.contentTypes.get(uid).schema;
|
|
186
235
|
const isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);
|
|
187
236
|
const previousKind = previousSchema.kind;
|
|
@@ -196,10 +245,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
196
245
|
}, {});
|
|
197
246
|
contentType.attributes = ___default.default.merge(prevNonVisibleAttributes, contentType.attributes);
|
|
198
247
|
if (newKind !== previousKind && newKind === 'singleType') {
|
|
199
|
-
|
|
200
|
-
if (entryCount > 1) {
|
|
201
|
-
throw new ApplicationError('You cannot convert a collectionType to a singleType when having multiple entries in DB');
|
|
202
|
-
}
|
|
248
|
+
await assertCanConvertToSingleType(uid);
|
|
203
249
|
}
|
|
204
250
|
const uidMap = builder.createNewComponentUIDMap(components);
|
|
205
251
|
const replaceTmpUIDs = attributes.replaceTemporaryUIDs(uidMap);
|
|
@@ -257,10 +303,13 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
257
303
|
}))){
|
|
258
304
|
strapi.log.error(error);
|
|
259
305
|
}
|
|
306
|
+
strapi.eventHub.emit('content-type.update', {
|
|
307
|
+
contentType: updatedContentType
|
|
308
|
+
});
|
|
260
309
|
return updatedContentType;
|
|
261
310
|
}
|
|
262
311
|
await builder.writeFiles();
|
|
263
|
-
|
|
312
|
+
await events.emitSchemaEvent('content-type.update', {
|
|
264
313
|
contentType: updatedContentType
|
|
265
314
|
});
|
|
266
315
|
return updatedContentType;
|
|
@@ -305,7 +354,7 @@ const deleteContentTypes = async (uids)=>{
|
|
|
305
354
|
strapi.log.error(error);
|
|
306
355
|
}
|
|
307
356
|
for (const contentType of deletedContentTypes){
|
|
308
|
-
|
|
357
|
+
await events.emitSchemaEvent('content-type.delete', {
|
|
309
358
|
contentType
|
|
310
359
|
});
|
|
311
360
|
}
|
|
@@ -357,7 +406,7 @@ const deleteContentTypes = async (uids)=>{
|
|
|
357
406
|
contentType = builder.deleteContentType(uid);
|
|
358
407
|
}
|
|
359
408
|
if (!defaultBuilder) {
|
|
360
|
-
|
|
409
|
+
await events.emitSchemaEvent('content-type.delete', {
|
|
361
410
|
contentType
|
|
362
411
|
});
|
|
363
412
|
}
|
|
@@ -365,6 +414,7 @@ const deleteContentTypes = async (uids)=>{
|
|
|
365
414
|
};
|
|
366
415
|
|
|
367
416
|
exports.assertCTBOwnedApplicationContentType = assertCTBOwnedApplicationContentType;
|
|
417
|
+
exports.assertCanConvertToSingleType = assertCanConvertToSingleType;
|
|
368
418
|
exports.createContentType = createContentType;
|
|
369
419
|
exports.createContentTypes = createContentTypes;
|
|
370
420
|
exports.deleteContentType = deleteContentType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _, { get } from 'lodash';\n\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport { getService } from '../utils';\nimport createBuilder from './schema-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isCTBOwnedApplicationContentType = (uid: UID.ContentType): boolean =>\n uid.startsWith('api::');\n\nexport const assertCTBOwnedApplicationContentType = (uid: UID.ContentType): void => {\n if (!isCTBOwnedApplicationContentType(uid)) {\n throw new ApplicationError(`Content type \"${uid}\" is not managed by CTB and cannot be deleted`);\n }\n};\n\nconst pruneFolderReferences = (uids: UID.ContentType[]) => {\n return getService('content-structure').commitFromUpdate({ deletedUids: new Set(uids) });\n};\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n get(model, 'pluginOptions.content-type-builder.visible', true) === 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 const generatedApiNames: string[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const contentType of contentTypes) {\n createdContentTypes.push(\n await createContentType(contentType, {\n defaultBuilder: builder,\n generatedApiNames,\n deferEvent: true,\n })\n );\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n } catch (error) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const contentType of createdContentTypes) {\n strapi.eventHub.emit('content-type.create', { contentType });\n }\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n generatedApiNames?: string[];\n deferEvent?: boolean;\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 const generatedApiNames = options.generatedApiNames ?? [];\n let schemaAlreadyRolledBack = false;\n\n try {\n // Generate before writing the schema so a successful mutation retains the existing layout.\n if (!contentType.plugin) {\n generatedApiNames.push(contentType.singularName);\n\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\n if (!options.defaultBuilder) {\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n }\n } catch (error) {\n if (!options.defaultBuilder) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n }\n\n throw error;\n }\n\n if (!options.deferEvent) {\n strapi.eventHub.emit('content-type.create', { contentType: newContentType });\n }\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 isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);\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 let schemaAlreadyRolledBack = false;\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid, { preserveBackup: true });\n\n if (!isPluginContentType) {\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\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\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 uids.forEach(assertCTBOwnedApplicationContentType);\n\n const builder = createBuilder();\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n\n const deletedContentTypes: any[] = [];\n const backedUpApiUids: UID.ContentType[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const uid of uids) {\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n deletedContentTypes.push(builder.deleteContentType(uid));\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n\n for (const uid of uids) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n await pruneFolderReferences(uids);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of deletedContentTypes) {\n strapi.eventHub.emit('content-type.delete', { contentType });\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 assertCTBOwnedApplicationContentType(uid);\n\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n let contentType;\n let schemaAlreadyRolledBack = false;\n\n if (!defaultBuilder) {\n try {\n contentType = builder.deleteContentType(uid);\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await apiHandler.clear(uid, { preserveBackup: true });\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n } else {\n contentType = builder.deleteContentType(uid);\n }\n\n if (!defaultBuilder) {\n strapi.eventHub.emit('content-type.delete', { contentType });\n }\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isCTBOwnedApplicationContentType","uid","startsWith","assertCTBOwnedApplicationContentType","pruneFolderReferences","uids","getService","commitFromUpdate","deletedUids","Set","isContentTypeVisible","model","get","getRestrictRelationsTo","contentType","coreUids","STRAPI_USER","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","generatedApiNames","schemaAlreadyRolledBack","push","createContentType","defaultBuilder","deferEvent","schemaFilesWritten","writeFiles","error","apiHandler","strapi","service","rollbackSchemaMutation","eventHub","emit","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","editContentType","previousSchema","isPluginContentType","Boolean","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","entryCount","db","query","count","updatedContentType","backup","clear","preserveBackup","backedUpApiUids","finalizeSchemaMutation","log","deleteContentTypes","deletedContentTypes","deleteContentType","undefined"],"mappings":";;;;;;;;;;;;;;AAUA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;MAEhBC,gCAAAA,GAAmC,CAACC,MAC/CA,GAAAA,CAAIC,UAAU,CAAC,OAAA;AAEV,MAAMC,uCAAuC,CAACF,GAAAA,GAAAA;IACnD,IAAI,CAACD,iCAAiCC,GAAAA,CAAAA,EAAM;AAC1C,QAAA,MAAM,IAAIH,gBAAAA,CAAiB,CAAC,cAAc,EAAEG,GAAAA,CAAI,6CAA6C,CAAC,CAAA;AAChG,IAAA;AACF;AAEA,MAAMG,wBAAwB,CAACC,IAAAA,GAAAA;IAC7B,OAAOC,kBAAAA,CAAW,mBAAA,CAAA,CAAqBC,gBAAgB,CAAC;AAAEC,QAAAA,WAAAA,EAAa,IAAIC,GAAAA,CAAIJ,IAAAA;AAAM,KAAA,CAAA;AACvF,CAAA;AAEO,MAAMK,uBAAuB,CAACC,KAAAA,GACnCC,MAAID,KAAAA,EAAO,4CAAA,EAA8C,UAAU;AAE9D,MAAME,yBAAyB,CAACC,WAAAA,GAAAA;IACrC,MAAM,EAAEb,GAAG,EAAE,GAAGa,WAAAA;IAChB,IAAIb,GAAAA,KAAQc,kBAAAA,C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":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _, { get } from 'lodash';\n\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport { emitSchemaEvent } from '../utils/events';\nimport { getService } from '../utils';\nimport createBuilder from './schema-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isCTBOwnedApplicationContentType = (uid: UID.ContentType): boolean =>\n uid.startsWith('api::');\n\nexport const assertCTBOwnedApplicationContentType = (uid: UID.ContentType): void => {\n if (!isCTBOwnedApplicationContentType(uid)) {\n throw new ApplicationError(`Content type \"${uid}\" is not managed by CTB and cannot be deleted`);\n }\n};\n\nconst pruneFolderReferences = (uids: UID.ContentType[]) => {\n return getService('content-structure').commitFromUpdate({ deletedUids: new Set(uids) });\n};\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n get(model, 'pluginOptions.content-type-builder.visible', true) === 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 const generatedApiNames: string[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const contentType of contentTypes) {\n createdContentTypes.push(\n await createContentType(contentType, {\n defaultBuilder: builder,\n generatedApiNames,\n deferEvent: true,\n })\n );\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n } catch (error) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const contentType of createdContentTypes) {\n await emitSchemaEvent('content-type.create', { contentType });\n }\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n generatedApiNames?: string[];\n deferEvent?: boolean;\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 const generatedApiNames = options.generatedApiNames ?? [];\n let schemaAlreadyRolledBack = false;\n\n try {\n // Generate before writing the schema so a successful mutation retains the existing layout.\n if (!contentType.plugin) {\n generatedApiNames.push(contentType.singularName);\n\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\n if (!options.defaultBuilder) {\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n }\n } catch (error) {\n if (!options.defaultBuilder) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n }\n\n throw error;\n }\n\n if (!options.deferEvent) {\n await emitSchemaEvent('content-type.create', { contentType: newContentType });\n }\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 * A document can span several rows (draft and published versions, one per locale),\n * so compare documentIds instead of counting rows.\n * A row without documentId (raw SQL, imports) cannot be tied to any document, so it\n * counts as another one. `$ne` alone would skip it, as SQL `<>` never matches NULL.\n */\nconst hasMultipleDocuments = async (uid: UID.ContentType) => {\n const firstEntry = await strapi.db.query(uid).findOne({\n select: ['documentId'],\n where: { documentId: { $notNull: true } },\n });\n if (firstEntry === null) {\n const rowsCount = await strapi.db.query(uid).count();\n return rowsCount > 1;\n }\n\n const otherDocumentsCount = await strapi.db.query(uid).count({\n where: {\n $or: [{ documentId: { $ne: firstEntry.documentId } }, { documentId: { $null: true } }],\n },\n });\n\n return otherDocumentsCount > 0;\n};\n\n/**\n * A single type holds one document, so refuse the switch while several exist.\n */\nexport const assertCanConvertToSingleType = async (uid: UID.ContentType) => {\n if ((await hasMultipleDocuments(uid)) === true) {\n throw new ApplicationError(\n 'You cannot convert a collectionType to a singleType when having multiple entries in DB'\n );\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 if (builder.contentTypes.has(uid) === false) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const previousSchema = builder.contentTypes.get(uid).schema;\n const isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);\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 await assertCanConvertToSingleType(uid);\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 let schemaAlreadyRolledBack = false;\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid, { preserveBackup: true });\n\n if (!isPluginContentType) {\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\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n\n strapi.eventHub.emit('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n }\n\n await builder.writeFiles();\n\n await emitSchemaEvent('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n};\n\nexport const deleteContentTypes = async (uids: UID.ContentType[]) => {\n uids.forEach(assertCTBOwnedApplicationContentType);\n\n const builder = createBuilder();\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n\n const deletedContentTypes: any[] = [];\n const backedUpApiUids: UID.ContentType[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const uid of uids) {\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n deletedContentTypes.push(builder.deleteContentType(uid));\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n\n for (const uid of uids) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n await pruneFolderReferences(uids);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of deletedContentTypes) {\n await emitSchemaEvent('content-type.delete', { contentType });\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 assertCTBOwnedApplicationContentType(uid);\n\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n let contentType;\n let schemaAlreadyRolledBack = false;\n\n if (!defaultBuilder) {\n try {\n contentType = builder.deleteContentType(uid);\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await apiHandler.clear(uid, { preserveBackup: true });\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n } else {\n contentType = builder.deleteContentType(uid);\n }\n\n if (!defaultBuilder) {\n await emitSchemaEvent('content-type.delete', { contentType });\n }\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isCTBOwnedApplicationContentType","uid","startsWith","assertCTBOwnedApplicationContentType","pruneFolderReferences","uids","getService","commitFromUpdate","deletedUids","Set","isContentTypeVisible","model","get","getRestrictRelationsTo","contentType","coreUids","STRAPI_USER","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","generatedApiNames","schemaAlreadyRolledBack","push","createContentType","defaultBuilder","deferEvent","schemaFilesWritten","writeFiles","error","apiHandler","strapi","service","rollbackSchemaMutation","emitSchemaEvent","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","hasMultipleDocuments","firstEntry","db","query","findOne","select","where","documentId","$notNull","rowsCount","count","otherDocumentsCount","$or","$ne","$null","assertCanConvertToSingleType","editContentType","previousSchema","isPluginContentType","Boolean","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","updatedContentType","backup","clear","preserveBackup","backedUpApiUids","finalizeSchemaMutation","log","eventHub","emit","deleteContentTypes","deletedContentTypes","deleteContentType","undefined"],"mappings":";;;;;;;;;;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;MAEhBC,gCAAAA,GAAmC,CAACC,MAC/CA,GAAAA,CAAIC,UAAU,CAAC,OAAA;AAEV,MAAMC,uCAAuC,CAACF,GAAAA,GAAAA;IACnD,IAAI,CAACD,iCAAiCC,GAAAA,CAAAA,EAAM;AAC1C,QAAA,MAAM,IAAIH,gBAAAA,CAAiB,CAAC,cAAc,EAAEG,GAAAA,CAAI,6CAA6C,CAAC,CAAA;AAChG,IAAA;AACF;AAEA,MAAMG,wBAAwB,CAACC,IAAAA,GAAAA;IAC7B,OAAOC,kBAAAA,CAAW,mBAAA,CAAA,CAAqBC,gBAAgB,CAAC;AAAEC,QAAAA,WAAAA,EAAa,IAAIC,GAAAA,CAAIJ,IAAAA;AAAM,KAAA,CAAA;AACvF,CAAA;AAEO,MAAMK,uBAAuB,CAACC,KAAAA,GACnCC,MAAID,KAAAA,EAAO,4CAAA,EAA8C,UAAU;AAE9D,MAAME,yBAAyB,CAACC,WAAAA,GAAAA;IACrC,MAAM,EAAEb,GAAG,EAAE,GAAGa,WAAAA;IAChB,IAAIb,GAAAA,KAAQc,kBAAAA,CAASC,WAAW,EAAE;;QAEhC,OAAO;AAAC,YAAA,QAAA;AAAU,YAAA;AAAU,SAAA;AAC9B,IAAA;AAEA,IAA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AC7B,YAAA;YACA,MAAMwD,UAAAA,CAAWgE,KAAK,CAACrH,GAAAA,EAAK;gBAAEsH,cAAAA,EAAgB;AAAK,aAAA,CAAA;AACnD,YAAA,MAAMnH,qBAAAA,CAAsB;AAACH,gBAAAA;AAAI,aAAA,CAAA;AACnC,QAAA,CAAA,CAAE,OAAOoD,KAAAA,EAAO;AACd,YAAA,MAAMI,qCAAAA,CAAuB;AAC3Bf,gBAAAA,OAAAA;AACAY,gBAAAA,UAAAA;gBACAkE,eAAAA,EAAiB;AAACvH,oBAAAA;AAAI,iBAAA;AACtB6C,gBAAAA;AACF,aAAA,CAAA;YAEA,MAAMO,KAAAA;AACR,QAAA;AAEA,QAAA,KAAK,MAAMA,KAAAA,KAAS,MAAMoE,qCAAAA,CAAuB;AAAEnE,YAAAA,UAAAA;YAAYkE,eAAAA,EAAiB;AAACvH,gBAAAA;AAAI;AAAC,SAAA,CAAC,EAAG;YACxFsD,MAAAA,CAAOmE,GAAG,CAACrE,KAAK,CAACA,KAAAA,CAAAA;AACnB,QAAA;IACF,CAAA,MAAO;QACLvC,WAAAA,GAAc4B,OAAAA,CAAQqF,iBAAiB,CAAC9H,GAAAA,CAAAA;AAC1C,IAAA;AAEA,IAAA,IAAI,CAACgD,cAAAA,EAAgB;AACnB,QAAA,MAAMS,uBAAgB,qBAAA,EAAuB;AAAE5C,YAAAA;AAAY,SAAA,CAAA;AAC7D,IAAA;IAEA,OAAOA,WAAAA;AACT;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _, { get } from 'lodash';
|
|
2
2
|
import { errors, contentTypes } from '@strapi/utils';
|
|
3
3
|
import { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes.mjs';
|
|
4
|
+
import { emitSchemaEvent } from '../utils/events.mjs';
|
|
4
5
|
import { getService } from '../utils/index.mjs';
|
|
5
6
|
import createBuilder from './schema-builder/index.mjs';
|
|
6
7
|
import { rollbackSchemaMutation, finalizeSchemaMutation } from './schema-mutation.mjs';
|
|
@@ -85,7 +86,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
85
86
|
throw error;
|
|
86
87
|
}
|
|
87
88
|
for (const contentType of createdContentTypes){
|
|
88
|
-
|
|
89
|
+
await emitSchemaEvent('content-type.create', {
|
|
89
90
|
contentType
|
|
90
91
|
});
|
|
91
92
|
}
|
|
@@ -148,7 +149,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
148
149
|
throw error;
|
|
149
150
|
}
|
|
150
151
|
if (!options.deferEvent) {
|
|
151
|
-
|
|
152
|
+
await emitSchemaEvent('content-type.create', {
|
|
152
153
|
contentType: newContentType
|
|
153
154
|
});
|
|
154
155
|
}
|
|
@@ -172,10 +173,58 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
172
173
|
dir: strapi.dirs.app.root
|
|
173
174
|
});
|
|
174
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* A document can span several rows (draft and published versions, one per locale),
|
|
178
|
+
* so compare documentIds instead of counting rows.
|
|
179
|
+
* A row without documentId (raw SQL, imports) cannot be tied to any document, so it
|
|
180
|
+
* counts as another one. `$ne` alone would skip it, as SQL `<>` never matches NULL.
|
|
181
|
+
*/ const hasMultipleDocuments = async (uid)=>{
|
|
182
|
+
const firstEntry = await strapi.db.query(uid).findOne({
|
|
183
|
+
select: [
|
|
184
|
+
'documentId'
|
|
185
|
+
],
|
|
186
|
+
where: {
|
|
187
|
+
documentId: {
|
|
188
|
+
$notNull: true
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
if (firstEntry === null) {
|
|
193
|
+
const rowsCount = await strapi.db.query(uid).count();
|
|
194
|
+
return rowsCount > 1;
|
|
195
|
+
}
|
|
196
|
+
const otherDocumentsCount = await strapi.db.query(uid).count({
|
|
197
|
+
where: {
|
|
198
|
+
$or: [
|
|
199
|
+
{
|
|
200
|
+
documentId: {
|
|
201
|
+
$ne: firstEntry.documentId
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
documentId: {
|
|
206
|
+
$null: true
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return otherDocumentsCount > 0;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* A single type holds one document, so refuse the switch while several exist.
|
|
216
|
+
*/ const assertCanConvertToSingleType = async (uid)=>{
|
|
217
|
+
if (await hasMultipleDocuments(uid) === true) {
|
|
218
|
+
throw new ApplicationError('You cannot convert a collectionType to a singleType when having multiple entries in DB');
|
|
219
|
+
}
|
|
220
|
+
};
|
|
175
221
|
/**
|
|
176
222
|
* Edits a contentType and handle the nested contentTypes sent with it
|
|
177
223
|
*/ const editContentType = async (uid, { contentType, components = [] })=>{
|
|
178
224
|
const builder = createBuilder();
|
|
225
|
+
if (builder.contentTypes.has(uid) === false) {
|
|
226
|
+
throw new ApplicationError('contentType.notFound');
|
|
227
|
+
}
|
|
179
228
|
const previousSchema = builder.contentTypes.get(uid).schema;
|
|
180
229
|
const isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);
|
|
181
230
|
const previousKind = previousSchema.kind;
|
|
@@ -190,10 +239,7 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
190
239
|
}, {});
|
|
191
240
|
contentType.attributes = _.merge(prevNonVisibleAttributes, contentType.attributes);
|
|
192
241
|
if (newKind !== previousKind && newKind === 'singleType') {
|
|
193
|
-
|
|
194
|
-
if (entryCount > 1) {
|
|
195
|
-
throw new ApplicationError('You cannot convert a collectionType to a singleType when having multiple entries in DB');
|
|
196
|
-
}
|
|
242
|
+
await assertCanConvertToSingleType(uid);
|
|
197
243
|
}
|
|
198
244
|
const uidMap = builder.createNewComponentUIDMap(components);
|
|
199
245
|
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
|
@@ -251,10 +297,13 @@ const createContentTypes = async (contentTypes)=>{
|
|
|
251
297
|
}))){
|
|
252
298
|
strapi.log.error(error);
|
|
253
299
|
}
|
|
300
|
+
strapi.eventHub.emit('content-type.update', {
|
|
301
|
+
contentType: updatedContentType
|
|
302
|
+
});
|
|
254
303
|
return updatedContentType;
|
|
255
304
|
}
|
|
256
305
|
await builder.writeFiles();
|
|
257
|
-
|
|
306
|
+
await emitSchemaEvent('content-type.update', {
|
|
258
307
|
contentType: updatedContentType
|
|
259
308
|
});
|
|
260
309
|
return updatedContentType;
|
|
@@ -299,7 +348,7 @@ const deleteContentTypes = async (uids)=>{
|
|
|
299
348
|
strapi.log.error(error);
|
|
300
349
|
}
|
|
301
350
|
for (const contentType of deletedContentTypes){
|
|
302
|
-
|
|
351
|
+
await emitSchemaEvent('content-type.delete', {
|
|
303
352
|
contentType
|
|
304
353
|
});
|
|
305
354
|
}
|
|
@@ -351,12 +400,12 @@ const deleteContentTypes = async (uids)=>{
|
|
|
351
400
|
contentType = builder.deleteContentType(uid);
|
|
352
401
|
}
|
|
353
402
|
if (!defaultBuilder) {
|
|
354
|
-
|
|
403
|
+
await emitSchemaEvent('content-type.delete', {
|
|
355
404
|
contentType
|
|
356
405
|
});
|
|
357
406
|
}
|
|
358
407
|
return contentType;
|
|
359
408
|
};
|
|
360
409
|
|
|
361
|
-
export { assertCTBOwnedApplicationContentType, createContentType, createContentTypes, deleteContentType, deleteContentTypes, editContentType, formatContentType, generateAPI, getRestrictRelationsTo, isCTBOwnedApplicationContentType, isContentTypeVisible };
|
|
410
|
+
export { assertCTBOwnedApplicationContentType, assertCanConvertToSingleType, createContentType, createContentTypes, deleteContentType, deleteContentTypes, editContentType, formatContentType, generateAPI, getRestrictRelationsTo, isCTBOwnedApplicationContentType, isContentTypeVisible };
|
|
362
411
|
//# sourceMappingURL=content-types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _, { get } from 'lodash';\n\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport { getService } from '../utils';\nimport createBuilder from './schema-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isCTBOwnedApplicationContentType = (uid: UID.ContentType): boolean =>\n uid.startsWith('api::');\n\nexport const assertCTBOwnedApplicationContentType = (uid: UID.ContentType): void => {\n if (!isCTBOwnedApplicationContentType(uid)) {\n throw new ApplicationError(`Content type \"${uid}\" is not managed by CTB and cannot be deleted`);\n }\n};\n\nconst pruneFolderReferences = (uids: UID.ContentType[]) => {\n return getService('content-structure').commitFromUpdate({ deletedUids: new Set(uids) });\n};\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n get(model, 'pluginOptions.content-type-builder.visible', true) === 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 const generatedApiNames: string[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const contentType of contentTypes) {\n createdContentTypes.push(\n await createContentType(contentType, {\n defaultBuilder: builder,\n generatedApiNames,\n deferEvent: true,\n })\n );\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n } catch (error) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const contentType of createdContentTypes) {\n strapi.eventHub.emit('content-type.create', { contentType });\n }\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n generatedApiNames?: string[];\n deferEvent?: boolean;\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 const generatedApiNames = options.generatedApiNames ?? [];\n let schemaAlreadyRolledBack = false;\n\n try {\n // Generate before writing the schema so a successful mutation retains the existing layout.\n if (!contentType.plugin) {\n generatedApiNames.push(contentType.singularName);\n\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\n if (!options.defaultBuilder) {\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n }\n } catch (error) {\n if (!options.defaultBuilder) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n }\n\n throw error;\n }\n\n if (!options.deferEvent) {\n strapi.eventHub.emit('content-type.create', { contentType: newContentType });\n }\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 isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);\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 let schemaAlreadyRolledBack = false;\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid, { preserveBackup: true });\n\n if (!isPluginContentType) {\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\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\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 uids.forEach(assertCTBOwnedApplicationContentType);\n\n const builder = createBuilder();\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n\n const deletedContentTypes: any[] = [];\n const backedUpApiUids: UID.ContentType[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const uid of uids) {\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n deletedContentTypes.push(builder.deleteContentType(uid));\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n\n for (const uid of uids) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n await pruneFolderReferences(uids);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of deletedContentTypes) {\n strapi.eventHub.emit('content-type.delete', { contentType });\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 assertCTBOwnedApplicationContentType(uid);\n\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n let contentType;\n let schemaAlreadyRolledBack = false;\n\n if (!defaultBuilder) {\n try {\n contentType = builder.deleteContentType(uid);\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await apiHandler.clear(uid, { preserveBackup: true });\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n } else {\n contentType = builder.deleteContentType(uid);\n }\n\n if (!defaultBuilder) {\n strapi.eventHub.emit('content-type.delete', { contentType });\n }\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isCTBOwnedApplicationContentType","uid","startsWith","assertCTBOwnedApplicationContentType","pruneFolderReferences","uids","getService","commitFromUpdate","deletedUids","Set","isContentTypeVisible","model","get","getRestrictRelationsTo","contentType","coreUids","STRAPI_USER","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","generatedApiNames","schemaAlreadyRolledBack","push","createContentType","defaultBuilder","deferEvent","schemaFilesWritten","writeFiles","error","apiHandler","strapi","service","rollbackSchemaMutation","eventHub","emit","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","editContentType","previousSchema","isPluginContentType","Boolean","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","entryCount","db","query","count","updatedContentType","backup","clear","preserveBackup","backedUpApiUids","finalizeSchemaMutation","log","deleteContentTypes","deletedContentTypes","deleteContentType","undefined"],"mappings":";;;;;;;;AAUA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;MAEhBC,gCAAAA,GAAmC,CAACC,MAC/CA,GAAAA,CAAIC,UAAU,CAAC,OAAA;AAEV,MAAMC,uCAAuC,CAACF,GAAAA,GAAAA;IACnD,IAAI,CAACD,iCAAiCC,GAAAA,CAAAA,EAAM;AAC1C,QAAA,MAAM,IAAIH,gBAAAA,CAAiB,CAAC,cAAc,EAAEG,GAAAA,CAAI,6CAA6C,CAAC,CAAA;AAChG,IAAA;AACF;AAEA,MAAMG,wBAAwB,CAACC,IAAAA,GAAAA;IAC7B,OAAOC,UAAAA,CAAW,mBAAA,CAAA,CAAqBC,gBAAgB,CAAC;AA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QwE,iBAAiB,CAACjH,GAAAA,CAAAA;AAC1C,IAAA;AAEA,IAAA,IAAI,CAACgD,cAAAA,EAAgB;AACnBM,QAAAA,MAAAA,CAAOG,QAAQ,CAACC,IAAI,CAAC,qBAAA,EAAuB;AAAE7C,YAAAA;AAAY,SAAA,CAAA;AAC5D,IAAA;IAEA,OAAOA,WAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _, { get } from 'lodash';\n\nimport { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport type { UID, Struct } from '@strapi/types';\nimport { formatAttributes, replaceTemporaryUIDs } from '../utils/attributes';\nimport { emitSchemaEvent } from '../utils/events';\nimport { getService } from '../utils';\nimport createBuilder from './schema-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { coreUids, pluginsUids } from './constants';\n\nconst { ApplicationError } = errors;\n\nexport const isCTBOwnedApplicationContentType = (uid: UID.ContentType): boolean =>\n uid.startsWith('api::');\n\nexport const assertCTBOwnedApplicationContentType = (uid: UID.ContentType): void => {\n if (!isCTBOwnedApplicationContentType(uid)) {\n throw new ApplicationError(`Content type \"${uid}\" is not managed by CTB and cannot be deleted`);\n }\n};\n\nconst pruneFolderReferences = (uids: UID.ContentType[]) => {\n return getService('content-structure').commitFromUpdate({ deletedUids: new Set(uids) });\n};\n\nexport const isContentTypeVisible = (model: Struct.ContentTypeSchema) =>\n get(model, 'pluginOptions.content-type-builder.visible', true) === 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 const generatedApiNames: string[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const contentType of contentTypes) {\n createdContentTypes.push(\n await createContentType(contentType, {\n defaultBuilder: builder,\n generatedApiNames,\n deferEvent: true,\n })\n );\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n } catch (error) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const contentType of createdContentTypes) {\n await emitSchemaEvent('content-type.create', { contentType });\n }\n\n return createdContentTypes;\n};\n\ntype CreateContentTypeOptions = {\n defaultBuilder?: any; // TODO\n generatedApiNames?: string[];\n deferEvent?: boolean;\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 const generatedApiNames = options.generatedApiNames ?? [];\n let schemaAlreadyRolledBack = false;\n\n try {\n // Generate before writing the schema so a successful mutation retains the existing layout.\n if (!contentType.plugin) {\n generatedApiNames.push(contentType.singularName);\n\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\n if (!options.defaultBuilder) {\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n }\n } catch (error) {\n if (!options.defaultBuilder) {\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n generatedApiNames,\n schemaAlreadyRolledBack,\n });\n }\n\n throw error;\n }\n\n if (!options.deferEvent) {\n await emitSchemaEvent('content-type.create', { contentType: newContentType });\n }\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 * A document can span several rows (draft and published versions, one per locale),\n * so compare documentIds instead of counting rows.\n * A row without documentId (raw SQL, imports) cannot be tied to any document, so it\n * counts as another one. `$ne` alone would skip it, as SQL `<>` never matches NULL.\n */\nconst hasMultipleDocuments = async (uid: UID.ContentType) => {\n const firstEntry = await strapi.db.query(uid).findOne({\n select: ['documentId'],\n where: { documentId: { $notNull: true } },\n });\n if (firstEntry === null) {\n const rowsCount = await strapi.db.query(uid).count();\n return rowsCount > 1;\n }\n\n const otherDocumentsCount = await strapi.db.query(uid).count({\n where: {\n $or: [{ documentId: { $ne: firstEntry.documentId } }, { documentId: { $null: true } }],\n },\n });\n\n return otherDocumentsCount > 0;\n};\n\n/**\n * A single type holds one document, so refuse the switch while several exist.\n */\nexport const assertCanConvertToSingleType = async (uid: UID.ContentType) => {\n if ((await hasMultipleDocuments(uid)) === true) {\n throw new ApplicationError(\n 'You cannot convert a collectionType to a singleType when having multiple entries in DB'\n );\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 if (builder.contentTypes.has(uid) === false) {\n throw new ApplicationError('contentType.notFound');\n }\n\n const previousSchema = builder.contentTypes.get(uid).schema;\n const isPluginContentType = Boolean(builder.contentTypes.get(uid).plugin);\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 await assertCanConvertToSingleType(uid);\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 let schemaAlreadyRolledBack = false;\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n try {\n await apiHandler.clear(uid, { preserveBackup: true });\n\n if (!isPluginContentType) {\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\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n\n strapi.eventHub.emit('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n }\n\n await builder.writeFiles();\n\n await emitSchemaEvent('content-type.update', { contentType: updatedContentType });\n\n return updatedContentType;\n};\n\nexport const deleteContentTypes = async (uids: UID.ContentType[]) => {\n uids.forEach(assertCTBOwnedApplicationContentType);\n\n const builder = createBuilder();\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n\n const deletedContentTypes: any[] = [];\n const backedUpApiUids: UID.ContentType[] = [];\n let schemaAlreadyRolledBack = false;\n\n try {\n for (const uid of uids) {\n await apiHandler.backup(uid);\n backedUpApiUids.push(uid);\n deletedContentTypes.push(builder.deleteContentType(uid));\n }\n\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n\n for (const uid of uids) {\n await apiHandler.clear(uid, { preserveBackup: true });\n }\n\n await pruneFolderReferences(uids);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids,\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n strapi.log.error(error);\n }\n\n for (const contentType of deletedContentTypes) {\n await emitSchemaEvent('content-type.delete', { contentType });\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 assertCTBOwnedApplicationContentType(uid);\n\n const builder = defaultBuilder || createBuilder();\n // make a backup\n const apiHandler = strapi\n .plugin('content-type-builder')\n .service('api-handler') as typeof import('./api-handler');\n await apiHandler.backup(uid);\n\n let contentType;\n let schemaAlreadyRolledBack = false;\n\n if (!defaultBuilder) {\n try {\n contentType = builder.deleteContentType(uid);\n const schemaFilesWritten = await builder.writeFiles();\n if (!schemaFilesWritten) {\n schemaAlreadyRolledBack = true;\n throw new ApplicationError('Invalid schema edition');\n }\n await apiHandler.clear(uid, { preserveBackup: true });\n await pruneFolderReferences([uid]);\n } catch (error) {\n await rollbackSchemaMutation({\n builder,\n apiHandler,\n backedUpApiUids: [uid],\n schemaAlreadyRolledBack,\n });\n\n throw error;\n }\n\n for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids: [uid] })) {\n strapi.log.error(error);\n }\n } else {\n contentType = builder.deleteContentType(uid);\n }\n\n if (!defaultBuilder) {\n await emitSchemaEvent('content-type.delete', { contentType });\n }\n\n return contentType;\n};\n"],"names":["ApplicationError","errors","isCTBOwnedApplicationContentType","uid","startsWith","assertCTBOwnedApplicationContentType","pruneFolderReferences","uids","getService","commitFromUpdate","deletedUids","Set","isContentTypeVisible","model","get","getRestrictRelationsTo","contentType","coreUids","STRAPI_USER","PREFIX","pluginsUids","UPLOAD_FILE","formatContentType","kind","modelName","plugin","collectionName","info","apiID","schema","contentTypesUtils","getOptions","displayName","singularName","pluralName","description","_","pluginOptions","attributes","formatAttributes","visible","restrictRelationsTo","createContentTypes","contentTypes","builder","createBuilder","createdContentTypes","generatedApiNames","schemaAlreadyRolledBack","push","createContentType","defaultBuilder","deferEvent","schemaFilesWritten","writeFiles","error","apiHandler","strapi","service","rollbackSchemaMutation","emitSchemaEvent","components","options","uidMap","createNewComponentUIDMap","replaceTmpUIDs","replaceTemporaryUIDs","newContentType","targetContentType","infos","Object","keys","forEach","key","target","component","has","createComponent","editComponent","generateAPI","strapiGenerators","require","generate","id","destination","bootstrapApi","dir","dirs","app","root","hasMultipleDocuments","firstEntry","db","query","findOne","select","where","documentId","$notNull","rowsCount","count","otherDocumentsCount","$or","$ne","$null","assertCanConvertToSingleType","editContentType","previousSchema","isPluginContentType","Boolean","previousKind","newKind","previousAttributes","prevNonVisibleAttributes","getNonVisibleAttributes","reduce","acc","merge","updatedContentType","backup","clear","preserveBackup","backedUpApiUids","finalizeSchemaMutation","log","eventHub","emit","deleteContentTypes","deletedContentTypes","deleteContentType","undefined"],"mappings":";;;;;;;;;AAWA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;MAEhBC,gCAAAA,GAAmC,CAACC,MAC/CA,GAAAA,CAAIC,UAAU,CAAC,OAAA;AAEV,MAAMC,uCAAuC,CAACF,GAAAA,GAAAA;IACnD,IAAI,CAACD,iCAAiCC,GAAAA,CAAAA,EAAM;AAC1C,QAAA,MAAM,IAAIH,gBAAAA,CAAiB,CAAC,cAAc,EAAEG,GAAAA,CAAI,6CAA6C,CAAC,CAAA;AAChG,IAAA;AACF;AAEA,MAAMG,wBAAwB,CAACC,IAAAA,GAAAA;IAC7B,OAAOC,UAAAA,CAAW,mBAAA,CAAA,CAAqBC,gBAAgB,CAAC;AAAEC,QAAAA,WAAAA,EAAa,IAAIC,GAAAA,CAAIJ,IAAAA;AAAM,KAAA,CAAA;AACvF,CAAA;AAEO,MAAMK,uBAAuB,CAACC,KAAAA,GACnC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
148
|
}).set('options', {
|
|
149
149
|
...infos.options,
|
|
150
|
-
draftAndPublish: infos.draftAndPublish
|
|
150
|
+
draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish
|
|
151
151
|
}).set('pluginOptions', infos.pluginOptions).set('config', infos.config);
|
|
152
152
|
this.createContentTypeAttributes(uid, infos.attributes);
|
|
153
153
|
return contentType;
|
|
@@ -274,8 +274,11 @@ function createComponentBuilder() {
|
|
|
274
274
|
'info',
|
|
275
275
|
'description'
|
|
276
276
|
], infos.description).set('options', {
|
|
277
|
+
// Payloads may omit options keys the CTB does not edit (e.g. populateCreatorFields)
|
|
278
|
+
...contentType.schema.options,
|
|
277
279
|
...infos.options,
|
|
278
|
-
draftAndPublish
|
|
280
|
+
// A payload that does not set draftAndPublish keeps the stored value
|
|
281
|
+
draftAndPublish: infos.draftAndPublish ?? infos.options?.draftAndPublish ?? contentType.schema.options?.draftAndPublish
|
|
279
282
|
}).set('pluginOptions', infos.pluginOptions).setAttributes(this.convertAttributes(newAttributes));
|
|
280
283
|
return contentType;
|
|
281
284
|
},
|