@strapi/content-type-builder 5.43.0 → 5.45.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/lib/transforms/schemas/fromCTB.js +3 -0
- package/dist/admin/components/AIChat/lib/transforms/schemas/fromCTB.js.map +1 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/fromCTB.mjs +3 -0
- package/dist/admin/components/AIChat/lib/transforms/schemas/fromCTB.mjs.map +1 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.js +53 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.js.map +1 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.mjs +53 -1
- package/dist/admin/components/AIChat/lib/transforms/schemas/toCTB.mjs.map +1 -1
- package/dist/admin/src/components/AIChat/lib/types/schema.d.ts +2 -0
- package/dist/admin/translations/cs.json.js +158 -2
- package/dist/admin/translations/cs.json.js.map +1 -1
- package/dist/admin/translations/cs.json.mjs +158 -2
- package/dist/admin/translations/cs.json.mjs.map +1 -1
- package/dist/server/controllers/validation/content-type.js.map +1 -1
- package/dist/server/controllers/validation/content-type.mjs.map +1 -1
- package/dist/server/controllers/validation/schema.js +5 -2
- package/dist/server/controllers/validation/schema.js.map +1 -1
- package/dist/server/controllers/validation/schema.mjs +6 -3
- package/dist/server/controllers/validation/schema.mjs.map +1 -1
- package/dist/server/services/api-handler.js +8 -0
- package/dist/server/services/api-handler.js.map +1 -1
- package/dist/server/services/api-handler.mjs +8 -0
- package/dist/server/services/api-handler.mjs.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.js +3 -2
- package/dist/server/services/schema-builder/content-type-builder.js.map +1 -1
- package/dist/server/services/schema-builder/content-type-builder.mjs +3 -2
- package/dist/server/services/schema-builder/content-type-builder.mjs.map +1 -1
- package/dist/server/services/schema.js +8 -6
- package/dist/server/services/schema.js.map +1 -1
- package/dist/server/services/schema.mjs +8 -6
- package/dist/server/services/schema.mjs.map +1 -1
- package/dist/server/src/controllers/validation/content-type.d.ts +1 -0
- package/dist/server/src/controllers/validation/content-type.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/schema.d.ts +9 -1
- package/dist/server/src/controllers/validation/schema.d.ts.map +1 -1
- package/dist/server/src/services/api-handler.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.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -32,6 +32,9 @@ const transformCTBToChat = (schema)=>{
|
|
|
32
32
|
action: 'create',
|
|
33
33
|
name: schema.info.pluralName,
|
|
34
34
|
uid: schema.uid,
|
|
35
|
+
...schema.plugin ? {
|
|
36
|
+
plugin: schema.plugin
|
|
37
|
+
} : {},
|
|
35
38
|
attributes: transformAttributesFromCTBToChat(schema.attributes),
|
|
36
39
|
// @ts-expect-error - injected from previous ai messages
|
|
37
40
|
sources: schema.sources,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromCTB.js","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/fromCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst transformAttributesFromCTBToChat = (attributes: AnyAttribute[]) => {\n return attributes.reduce(\n (acc, attribute) => {\n const { name, ...rest } = attribute;\n\n return {\n ...acc,\n [name]: rest,\n };\n },\n {} as Record<string, Omit<AnyAttribute, 'name'>>\n );\n};\n\nexport const transformCTBToChat = (schema: ContentType | Component): Schema => {\n if (schema.modelType === 'component') {\n return {\n category: schema.category,\n kind: 'component',\n action: 'create',\n modelType: 'component',\n description: schema.info.description,\n name: schema.info.displayName,\n\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n } as any;\n }\n\n return {\n kind: schema.kind,\n modelType: schema.modelType,\n description: schema.info.description,\n action: 'create',\n name: schema.info.pluralName,\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n options: {\n draftAndPublish: schema.options?.draftAndPublish,\n localized: false,\n },\n } as any;\n};\n"],"names":["transformAttributesFromCTBToChat","attributes","reduce","acc","attribute","name","rest","transformCTBToChat","schema","modelType","category","kind","action","description","info","displayName","uid","sources","pluralName","options","draftAndPublish","localized"],"mappings":";;AAAA;AAKA,MAAMA,mCAAmC,CAACC,UAAAA,GAAAA;AACxC,IAAA,OAAOA,UAAAA,CAAWC,MAAM,CACtB,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJ,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGC,MAAM,GAAGF,SAAAA;QAE1B,OAAO;AACL,YAAA,GAAGD,GAAG;AACN,YAAA,CAACE,OAAOC;AACV,SAAA;AACF,IAAA,CAAA,EACA,EAAC,CAAA;AAEL,CAAA;AAEO,MAAMC,qBAAqB,CAACC,MAAAA,GAAAA;IACjC,IAAIA,MAAAA,CAAOC,SAAS,KAAK,WAAA,EAAa;QACpC,OAAO;AACLC,YAAAA,QAAAA,EAAUF,OAAOE,QAAQ;YACzBC,IAAAA,EAAM,WAAA;YACNC,MAAAA,EAAQ,QAAA;YACRH,SAAAA,EAAW,WAAA;YACXI,WAAAA,EAAaL,MAAAA,CAAOM,IAAI,CAACD,WAAW;YACpCR,IAAAA,EAAMG,MAAAA,CAAOM,IAAI,CAACC,WAAW;AAE7BC,YAAAA,GAAAA,EAAKR,OAAOQ,GAAG;YACff,UAAAA,EAAYD,gCAAAA,CAAiCQ,OAAOP,UAAU,CAAA;;AAE9DgB,YAAAA,OAAAA,EAAST,OAAOS;AAClB,SAAA;AACF,IAAA;IAEA,OAAO;AACLN,QAAAA,IAAAA,EAAMH,OAAOG,IAAI;AACjBF,QAAAA,SAAAA,EAAWD,OAAOC,SAAS;QAC3BI,WAAAA,EAAaL,MAAAA,CAAOM,IAAI,CAACD,WAAW;QACpCD,MAAAA,EAAQ,QAAA;QACRP,IAAAA,EAAMG,MAAAA,CAAOM,IAAI,CAACI,UAAU;AAC5BF,QAAAA,GAAAA,EAAKR,OAAOQ,GAAG;
|
|
1
|
+
{"version":3,"file":"fromCTB.js","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/fromCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst transformAttributesFromCTBToChat = (attributes: AnyAttribute[]) => {\n return attributes.reduce(\n (acc, attribute) => {\n const { name, ...rest } = attribute;\n\n return {\n ...acc,\n [name]: rest,\n };\n },\n {} as Record<string, Omit<AnyAttribute, 'name'>>\n );\n};\n\nexport const transformCTBToChat = (schema: ContentType | Component): Schema => {\n if (schema.modelType === 'component') {\n return {\n category: schema.category,\n kind: 'component',\n action: 'create',\n modelType: 'component',\n description: schema.info.description,\n name: schema.info.displayName,\n\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n } as any;\n }\n\n return {\n kind: schema.kind,\n modelType: schema.modelType,\n description: schema.info.description,\n action: 'create',\n name: schema.info.pluralName,\n uid: schema.uid as any,\n ...(schema.plugin ? { plugin: schema.plugin } : {}),\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n options: {\n draftAndPublish: schema.options?.draftAndPublish,\n localized: false,\n },\n } as any;\n};\n"],"names":["transformAttributesFromCTBToChat","attributes","reduce","acc","attribute","name","rest","transformCTBToChat","schema","modelType","category","kind","action","description","info","displayName","uid","sources","pluralName","plugin","options","draftAndPublish","localized"],"mappings":";;AAAA;AAKA,MAAMA,mCAAmC,CAACC,UAAAA,GAAAA;AACxC,IAAA,OAAO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AA,EAAS;YACPC,eAAAA,EAAiBb,MAAAA,CAAOY,OAAO,EAAEC,eAAAA;YACjCC,SAAAA,EAAW;AACb;AACF,KAAA;AACF;;;;"}
|
|
@@ -30,6 +30,9 @@ const transformCTBToChat = (schema)=>{
|
|
|
30
30
|
action: 'create',
|
|
31
31
|
name: schema.info.pluralName,
|
|
32
32
|
uid: schema.uid,
|
|
33
|
+
...schema.plugin ? {
|
|
34
|
+
plugin: schema.plugin
|
|
35
|
+
} : {},
|
|
33
36
|
attributes: transformAttributesFromCTBToChat(schema.attributes),
|
|
34
37
|
// @ts-expect-error - injected from previous ai messages
|
|
35
38
|
sources: schema.sources,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromCTB.mjs","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/fromCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst transformAttributesFromCTBToChat = (attributes: AnyAttribute[]) => {\n return attributes.reduce(\n (acc, attribute) => {\n const { name, ...rest } = attribute;\n\n return {\n ...acc,\n [name]: rest,\n };\n },\n {} as Record<string, Omit<AnyAttribute, 'name'>>\n );\n};\n\nexport const transformCTBToChat = (schema: ContentType | Component): Schema => {\n if (schema.modelType === 'component') {\n return {\n category: schema.category,\n kind: 'component',\n action: 'create',\n modelType: 'component',\n description: schema.info.description,\n name: schema.info.displayName,\n\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n } as any;\n }\n\n return {\n kind: schema.kind,\n modelType: schema.modelType,\n description: schema.info.description,\n action: 'create',\n name: schema.info.pluralName,\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n options: {\n draftAndPublish: schema.options?.draftAndPublish,\n localized: false,\n },\n } as any;\n};\n"],"names":["transformAttributesFromCTBToChat","attributes","reduce","acc","attribute","name","rest","transformCTBToChat","schema","modelType","category","kind","action","description","info","displayName","uid","sources","pluralName","options","draftAndPublish","localized"],"mappings":"AAAA;AAKA,MAAMA,mCAAmC,CAACC,UAAAA,GAAAA;AACxC,IAAA,OAAOA,UAAAA,CAAWC,MAAM,CACtB,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJ,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGC,MAAM,GAAGF,SAAAA;QAE1B,OAAO;AACL,YAAA,GAAGD,GAAG;AACN,YAAA,CAACE,OAAOC;AACV,SAAA;AACF,IAAA,CAAA,EACA,EAAC,CAAA;AAEL,CAAA;AAEO,MAAMC,qBAAqB,CAACC,MAAAA,GAAAA;IACjC,IAAIA,MAAAA,CAAOC,SAAS,KAAK,WAAA,EAAa;QACpC,OAAO;AACLC,YAAAA,QAAAA,EAAUF,OAAOE,QAAQ;YACzBC,IAAAA,EAAM,WAAA;YACNC,MAAAA,EAAQ,QAAA;YACRH,SAAAA,EAAW,WAAA;YACXI,WAAAA,EAAaL,MAAAA,CAAOM,IAAI,CAACD,WAAW;YACpCR,IAAAA,EAAMG,MAAAA,CAAOM,IAAI,CAACC,WAAW;AAE7BC,YAAAA,GAAAA,EAAKR,OAAOQ,GAAG;YACff,UAAAA,EAAYD,gCAAAA,CAAiCQ,OAAOP,UAAU,CAAA;;AAE9DgB,YAAAA,OAAAA,EAAST,OAAOS;AAClB,SAAA;AACF,IAAA;IAEA,OAAO;AACLN,QAAAA,IAAAA,EAAMH,OAAOG,IAAI;AACjBF,QAAAA,SAAAA,EAAWD,OAAOC,SAAS;QAC3BI,WAAAA,EAAaL,MAAAA,CAAOM,IAAI,CAACD,WAAW;QACpCD,MAAAA,EAAQ,QAAA;QACRP,IAAAA,EAAMG,MAAAA,CAAOM,IAAI,CAACI,UAAU;AAC5BF,QAAAA,GAAAA,EAAKR,OAAOQ,GAAG;
|
|
1
|
+
{"version":3,"file":"fromCTB.mjs","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/fromCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst transformAttributesFromCTBToChat = (attributes: AnyAttribute[]) => {\n return attributes.reduce(\n (acc, attribute) => {\n const { name, ...rest } = attribute;\n\n return {\n ...acc,\n [name]: rest,\n };\n },\n {} as Record<string, Omit<AnyAttribute, 'name'>>\n );\n};\n\nexport const transformCTBToChat = (schema: ContentType | Component): Schema => {\n if (schema.modelType === 'component') {\n return {\n category: schema.category,\n kind: 'component',\n action: 'create',\n modelType: 'component',\n description: schema.info.description,\n name: schema.info.displayName,\n\n uid: schema.uid as any,\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n } as any;\n }\n\n return {\n kind: schema.kind,\n modelType: schema.modelType,\n description: schema.info.description,\n action: 'create',\n name: schema.info.pluralName,\n uid: schema.uid as any,\n ...(schema.plugin ? { plugin: schema.plugin } : {}),\n attributes: transformAttributesFromCTBToChat(schema.attributes),\n // @ts-expect-error - injected from previous ai messages\n sources: schema.sources,\n options: {\n draftAndPublish: schema.options?.draftAndPublish,\n localized: false,\n },\n } as any;\n};\n"],"names":["transformAttributesFromCTBToChat","attributes","reduce","acc","attribute","name","rest","transformCTBToChat","schema","modelType","category","kind","action","description","info","displayName","uid","sources","pluralName","plugin","options","draftAndPublish","localized"],"mappings":"AAAA;AAKA,MAAMA,mCAAmC,CAACC,UAAAA,GAAAA;AACxC,IAAA,OAAOA,UAAAA,CAAWC,MAAM,CACtB,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJ,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGC,MAAM,GAAGF,SAAAA;QAE1B,OAAO;AACL,YAAA,GAAGD,GAAG;AACN,YAAA,CAACE,O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');
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
const isPluginContentTypeUid = (uid)=>uid.startsWith('plugin::');
|
|
9
|
+
/**
|
|
10
|
+
* Plugin / extension content-types use server-derived identity (globalId, collectionName, …).
|
|
11
|
+
* The AI chat uses a simplified shape that would otherwise overwrite those fields incorrectly.
|
|
12
|
+
*/ const isPluginContentType = (schema, oldSchema)=>{
|
|
13
|
+
if (schema.plugin || isPluginContentTypeUid(schema.uid)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (oldSchema && 'modelType' in oldSchema && oldSchema.modelType === 'contentType') {
|
|
17
|
+
const ct = oldSchema;
|
|
18
|
+
return Boolean(ct.plugin) || isPluginContentTypeUid(String(ct.uid));
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
8
22
|
const ACTION_TO_STATUS = {
|
|
9
23
|
create: 'NEW',
|
|
10
24
|
remove: 'REMOVED',
|
|
@@ -115,7 +129,7 @@ const ACTION_TO_STATUS = {
|
|
|
115
129
|
globalId: singularName
|
|
116
130
|
};
|
|
117
131
|
}
|
|
118
|
-
|
|
132
|
+
const contentTypeBase = {
|
|
119
133
|
uid: schema.uid,
|
|
120
134
|
modelType: schema.modelType,
|
|
121
135
|
modelName: singularName,
|
|
@@ -144,6 +158,44 @@ const ACTION_TO_STATUS = {
|
|
|
144
158
|
globalId: singularName,
|
|
145
159
|
restrictRelationsTo: null
|
|
146
160
|
};
|
|
161
|
+
if (isPluginContentType(schema, oldSchema) && oldSchema && oldSchema.modelType === 'contentType') {
|
|
162
|
+
const prev = oldSchema;
|
|
163
|
+
return {
|
|
164
|
+
...contentTypeBase,
|
|
165
|
+
plugin: prev.plugin ?? schema.plugin,
|
|
166
|
+
globalId: prev.globalId,
|
|
167
|
+
modelName: prev.modelName,
|
|
168
|
+
collectionName: prev.collectionName,
|
|
169
|
+
info: {
|
|
170
|
+
...contentTypeBase.info,
|
|
171
|
+
singularName: prev.info.singularName,
|
|
172
|
+
pluralName: prev.info.pluralName
|
|
173
|
+
},
|
|
174
|
+
options: {
|
|
175
|
+
...prev.options,
|
|
176
|
+
...contentTypeBase.options,
|
|
177
|
+
draftAndPublish: schema.options?.draftAndPublish ?? prev.options?.draftAndPublish ?? true
|
|
178
|
+
},
|
|
179
|
+
pluginOptions: {
|
|
180
|
+
...prev.pluginOptions,
|
|
181
|
+
...contentTypeBase.pluginOptions,
|
|
182
|
+
i18n: {
|
|
183
|
+
...prev.pluginOptions?.i18n ?? {},
|
|
184
|
+
...contentTypeBase.pluginOptions?.i18n ?? {},
|
|
185
|
+
localized: schema.options?.localized ?? prev.pluginOptions?.i18n?.localized ?? false
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
visible: prev.visible,
|
|
189
|
+
restrictRelationsTo: prev.restrictRelationsTo
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (isPluginContentType(schema, oldSchema) && schema.plugin) {
|
|
193
|
+
return {
|
|
194
|
+
...contentTypeBase,
|
|
195
|
+
plugin: schema.plugin
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return contentTypeBase;
|
|
147
199
|
};
|
|
148
200
|
|
|
149
201
|
exports.transformAttributesFromChatToCTB = transformAttributesFromChatToCTB;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCTB.js","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/toCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport isEqual from 'lodash/isEqual';\nimport omit from 'lodash/omit';\nimport pluralize from 'pluralize';\n\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst ACTION_TO_STATUS: Record<Schema['action'], ContentType['status']> = {\n create: 'NEW',\n remove: 'REMOVED',\n update: 'CHANGED',\n};\n\n/**\n * Creates a new attribute with the specified status\n */\nconst createAttributeWithStatus = (\n name: string,\n attributeData: Record<string, any>,\n status: AnyAttribute['status']\n): AnyAttribute =>\n ({\n ...attributeData,\n name,\n status,\n }) as AnyAttribute;\n\n/**\n * Determines the status of an attribute by comparing new and old versions\n */\nconst determineAttributeStatus = (\n newAttr: Record<string, any>,\n oldAttr?: AnyAttribute,\n oldSchema?: ContentType | Component\n): AnyAttribute['status'] => {\n if (!oldAttr) {\n return 'NEW';\n }\n\n // If the schema was already new, don't mark attributes as changed, keep them as new.\n if (oldSchema?.status === 'NEW') {\n return 'NEW';\n }\n\n // Compare attributes without the status field to determine if they've changed\n const newAttrWithoutStatus = omit(newAttr, ['status']);\n const oldAttrWithoutStatus = omit(oldAttr, ['status']);\n\n if (!isEqual(newAttrWithoutStatus, oldAttrWithoutStatus)) {\n return 'CHANGED';\n }\n\n // If unchanged, keep the previous status\n return oldAttr.status;\n};\n\n/**\n * Determines the status of a schema by comparing action and checking if oldSchema exists\n */\nconst transformStatusFromChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType['status'] => {\n // If schema has an action, use the mapped status\n if (schema.action) {\n return ACTION_TO_STATUS[schema.action];\n }\n\n // If oldSchema doesn't exist, it's a new schema\n if (!oldSchema) {\n return 'NEW';\n }\n\n // If no action is specified and oldSchema exists, keep the existing status\n return oldSchema.status;\n};\n\n/**\n * Transform attributes from Chat format to CTB format\n * Also performs a diff to determine the status of each attribute\n */\nexport const transformAttributesFromChatToCTB = (\n { action, attributes }: Schema,\n oldSchema?: ContentType | Component\n): AnyAttribute[] => {\n // If it's a new schema or no oldAttributes provided, all attributes are NEW\n if (action === 'create' || !oldSchema) {\n return Object.entries(attributes).map(([name, attribute]) =>\n createAttributeWithStatus(name, attribute, 'NEW')\n );\n }\n\n // Convert old attributes array to a lookup map for faster access\n const oldAttributesMap = oldSchema.attributes.reduce(\n (acc, attr) => ({ ...acc, [attr.name]: attr }),\n {} as Record<string, AnyAttribute>\n );\n\n // Process current attributes (new and changed)\n const processedAttributes = Object.entries(attributes).map(([name, attr]) => {\n const oldAttr = oldAttributesMap[name];\n const status = determineAttributeStatus({ ...attr, name }, oldAttr, oldSchema);\n\n return createAttributeWithStatus(name, attr, status);\n });\n\n // No need to mark removed attributes if the old schema is new, just remove it from the list\n // TODO: Else a validation error occurs on the backend side.\n if (oldSchema?.status === 'NEW') {\n return processedAttributes;\n }\n\n // Find removed attributes (exist in old but not in new)\n const removedAttributes = Object.entries(oldAttributesMap)\n .filter(([name]) => !attributes[name])\n .map(([name, oldAttr]) => createAttributeWithStatus(name, oldAttr, 'REMOVED'));\n\n // Combine both sets of attributes\n return [...processedAttributes, ...removedAttributes];\n};\n\n/**\n * Transform schema format\n * AI chat -> CTB\n *\n * The AI chat returns a simplified format, and this layer transforms it to be compatible with the CTB reducer.\n *\n * We need to keep track of which changes have been made\n */\nexport const transformChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType | Component => {\n const singularName = pluralize.singular(schema.name).toLowerCase().replace(/ /g, '-');\n const pluralName = pluralize.plural(schema.name).toLowerCase().replace(/ /g, '-');\n\n if (schema.modelType === 'component') {\n return {\n category: schema.category || 'default',\n modelName: singularName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n info: {\n displayName: schema.name,\n description: schema.description,\n // TODO\n // icon: schema.icon,\n },\n modelType: schema.modelType,\n uid: schema.uid as any,\n collectionName: pluralName,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n } satisfies Component;\n }\n\n return {\n uid: schema.uid as any,\n modelType: schema.modelType,\n modelName: singularName,\n kind: schema.kind!,\n info: {\n displayName: schema.name.charAt(0).toUpperCase() + schema.name.slice(1),\n // Always keep the old by default\n // @ts-expect-error - not in types\n singularName: oldSchema?.info?.singularName || singularName,\n // Always keep the old by default\n // @ts-expect-error - not in types\n pluralName: oldSchema?.info?.pluralName || pluralName,\n },\n collectionName: pluralName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n options: {\n draftAndPublish: schema.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n i18n: {\n localized: schema.options?.localized ?? false,\n },\n },\n visible: true,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n restrictRelationsTo: null, // TODO: not sure what this is about\n } satisfies ContentType;\n};\n"],"names":["ACTION_TO_STATUS","create","remove","update","createAttributeWithStatus","name","attributeData","status","determineAttributeStatus","newAttr","oldAttr","oldSchema","newAttrWithoutStatus","omit","oldAttrWithoutStatus","isEqual","transformStatusFromChatToCTB","schema","action","transformAttributesFromChatToCTB","attributes","Object","entries","map","attribute","oldAttributesMap","reduce","acc","attr","processedAttributes","removedAttributes","filter","transformChatToCTB","singularName","pluralize","singular","toLowerCase","replace","pluralName","plural","modelType","category","modelName","info","displayName","description","uid","collectionName","globalId","kind","charAt","toUpperCase","slice","options","draftAndPublish","pluginOptions","i18n","localized","visible","restrictRelationsTo"],"mappings":";;;;;;AAAA;AASA,MAAMA,gBAAAA,GAAoE;IACxEC,MAAAA,EAAQ,KAAA;IACRC,MAAAA,EAAQ,SAAA;IACRC,MAAAA,EAAQ;AACV,CAAA;AAEA;;AAEC,IACD,MAAMC,yBAAAA,GAA4B,CAChCC,IAAAA,EACAC,aAAAA,EACAC,UAEC;AACC,QAAA,GAAGD,aAAa;AAChBD,QAAAA,IAAAA;AACAE,QAAAA;KACF,CAAA;AAEF;;AAEC,IACD,MAAMC,wBAAAA,GAA2B,CAC/BC,OAAAA,EACAC,OAAAA,EACAC,SAAAA,GAAAA;AAEA,IAAA,IAAI,CAACD,OAAAA,EAAS;QACZ,OAAO,KAAA;AACT,IAAA;;IAGA,IAAIC,SAAAA,EAAWJ,WAAW,KAAA,EAAO;QAC/B,OAAO,KAAA;AACT,IAAA;;IAGA,MAAMK,oBAAAA,GAAuBC,KAAKJ,OAAAA,EAAS;AAAC,QAAA;AAAS,KAAA,CAAA;IACrD,MAAMK,oBAAAA,GAAuBD,KAAKH,OAAAA,EAAS;AAAC,QAAA;AAAS,KAAA,CAAA;IAEr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AA,EAAQS,6BAA6BC,MAAAA,EAAQN,SAAAA,CAAAA;QAC7CqC,QAAAA,EAAUf,YAAAA;QACV0B,mBAAAA,EAAqB;AACvB,KAAA;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"toCTB.js","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/toCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport isEqual from 'lodash/isEqual';\nimport omit from 'lodash/omit';\nimport pluralize from 'pluralize';\n\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst isPluginContentTypeUid = (uid: string) => uid.startsWith('plugin::');\n\n/**\n * Plugin / extension content-types use server-derived identity (globalId, collectionName, …).\n * The AI chat uses a simplified shape that would otherwise overwrite those fields incorrectly.\n */\nconst isPluginContentType = (schema: Schema, oldSchema?: ContentType | Component): boolean => {\n if (schema.plugin || isPluginContentTypeUid(schema.uid)) {\n return true;\n }\n if (oldSchema && 'modelType' in oldSchema && oldSchema.modelType === 'contentType') {\n const ct = oldSchema as ContentType;\n return Boolean(ct.plugin) || isPluginContentTypeUid(String(ct.uid));\n }\n return false;\n};\n\nconst ACTION_TO_STATUS: Record<Schema['action'], ContentType['status']> = {\n create: 'NEW',\n remove: 'REMOVED',\n update: 'CHANGED',\n};\n\n/**\n * Creates a new attribute with the specified status\n */\nconst createAttributeWithStatus = (\n name: string,\n attributeData: Record<string, any>,\n status: AnyAttribute['status']\n): AnyAttribute =>\n ({\n ...attributeData,\n name,\n status,\n }) as AnyAttribute;\n\n/**\n * Determines the status of an attribute by comparing new and old versions\n */\nconst determineAttributeStatus = (\n newAttr: Record<string, any>,\n oldAttr?: AnyAttribute,\n oldSchema?: ContentType | Component\n): AnyAttribute['status'] => {\n if (!oldAttr) {\n return 'NEW';\n }\n\n // If the schema was already new, don't mark attributes as changed, keep them as new.\n if (oldSchema?.status === 'NEW') {\n return 'NEW';\n }\n\n // Compare attributes without the status field to determine if they've changed\n const newAttrWithoutStatus = omit(newAttr, ['status']);\n const oldAttrWithoutStatus = omit(oldAttr, ['status']);\n\n if (!isEqual(newAttrWithoutStatus, oldAttrWithoutStatus)) {\n return 'CHANGED';\n }\n\n // If unchanged, keep the previous status\n return oldAttr.status;\n};\n\n/**\n * Determines the status of a schema by comparing action and checking if oldSchema exists\n */\nconst transformStatusFromChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType['status'] => {\n // If schema has an action, use the mapped status\n if (schema.action) {\n return ACTION_TO_STATUS[schema.action];\n }\n\n // If oldSchema doesn't exist, it's a new schema\n if (!oldSchema) {\n return 'NEW';\n }\n\n // If no action is specified and oldSchema exists, keep the existing status\n return oldSchema.status;\n};\n\n/**\n * Transform attributes from Chat format to CTB format\n * Also performs a diff to determine the status of each attribute\n */\nexport const transformAttributesFromChatToCTB = (\n { action, attributes }: Schema,\n oldSchema?: ContentType | Component\n): AnyAttribute[] => {\n // If it's a new schema or no oldAttributes provided, all attributes are NEW\n if (action === 'create' || !oldSchema) {\n return Object.entries(attributes).map(([name, attribute]) =>\n createAttributeWithStatus(name, attribute, 'NEW')\n );\n }\n\n // Convert old attributes array to a lookup map for faster access\n const oldAttributesMap = oldSchema.attributes.reduce(\n (acc, attr) => ({ ...acc, [attr.name]: attr }),\n {} as Record<string, AnyAttribute>\n );\n\n // Process current attributes (new and changed)\n const processedAttributes = Object.entries(attributes).map(([name, attr]) => {\n const oldAttr = oldAttributesMap[name];\n const status = determineAttributeStatus({ ...attr, name }, oldAttr, oldSchema);\n\n return createAttributeWithStatus(name, attr, status);\n });\n\n // No need to mark removed attributes if the old schema is new, just remove it from the list\n // TODO: Else a validation error occurs on the backend side.\n if (oldSchema?.status === 'NEW') {\n return processedAttributes;\n }\n\n // Find removed attributes (exist in old but not in new)\n const removedAttributes = Object.entries(oldAttributesMap)\n .filter(([name]) => !attributes[name])\n .map(([name, oldAttr]) => createAttributeWithStatus(name, oldAttr, 'REMOVED'));\n\n // Combine both sets of attributes\n return [...processedAttributes, ...removedAttributes];\n};\n\n/**\n * Transform schema format\n * AI chat -> CTB\n *\n * The AI chat returns a simplified format, and this layer transforms it to be compatible with the CTB reducer.\n *\n * We need to keep track of which changes have been made\n */\nexport const transformChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType | Component => {\n const singularName = pluralize.singular(schema.name).toLowerCase().replace(/ /g, '-');\n const pluralName = pluralize.plural(schema.name).toLowerCase().replace(/ /g, '-');\n\n if (schema.modelType === 'component') {\n return {\n category: schema.category || 'default',\n modelName: singularName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n info: {\n displayName: schema.name,\n description: schema.description,\n // TODO\n // icon: schema.icon,\n },\n modelType: schema.modelType,\n uid: schema.uid as any,\n collectionName: pluralName,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n } satisfies Component;\n }\n\n const contentTypeBase = {\n uid: schema.uid as any,\n modelType: schema.modelType,\n modelName: singularName,\n kind: schema.kind!,\n info: {\n displayName: schema.name.charAt(0).toUpperCase() + schema.name.slice(1),\n // Always keep the old by default\n // @ts-expect-error - not in types\n singularName: oldSchema?.info?.singularName || singularName,\n // Always keep the old by default\n // @ts-expect-error - not in types\n pluralName: oldSchema?.info?.pluralName || pluralName,\n },\n collectionName: pluralName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n options: {\n draftAndPublish: schema.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n i18n: {\n localized: schema.options?.localized ?? false,\n },\n },\n visible: true,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n restrictRelationsTo: null, // TODO: not sure what this is about\n } satisfies ContentType;\n\n if (\n isPluginContentType(schema, oldSchema) &&\n oldSchema &&\n oldSchema.modelType === 'contentType'\n ) {\n const prev = oldSchema as ContentType;\n return {\n ...contentTypeBase,\n plugin: prev.plugin ?? schema.plugin,\n globalId: prev.globalId,\n modelName: prev.modelName,\n collectionName: prev.collectionName,\n info: {\n ...contentTypeBase.info,\n singularName: prev.info.singularName,\n pluralName: prev.info.pluralName,\n },\n options: {\n ...prev.options,\n ...contentTypeBase.options,\n draftAndPublish: schema.options?.draftAndPublish ?? prev.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n ...prev.pluginOptions,\n ...contentTypeBase.pluginOptions,\n i18n: {\n ...((prev.pluginOptions?.i18n as Record<string, unknown> | undefined) ?? {}),\n ...((contentTypeBase.pluginOptions?.i18n as Record<string, unknown> | undefined) ?? {}),\n localized:\n schema.options?.localized ??\n (prev.pluginOptions?.i18n as { localized?: boolean } | undefined)?.localized ??\n false,\n },\n },\n visible: prev.visible,\n restrictRelationsTo: prev.restrictRelationsTo,\n } satisfies ContentType;\n }\n\n if (isPluginContentType(schema, oldSchema) && schema.plugin) {\n return {\n ...contentTypeBase,\n plugin: schema.plugin,\n } satisfies ContentType;\n }\n\n return contentTypeBase;\n};\n"],"names":["isPluginContentTypeUid","uid","startsWith","isPluginContentType","schema","oldSchema","plugin","modelType","ct","Boolean","String","ACTION_TO_STATUS","create","remove","update","createAttributeWithStatus","name","attributeData","status","determineAttributeStatus","newAttr","oldAttr","newAttrWithoutStatus","omit","oldAttrWithoutStatus","isEqual","transformStatusFromChatToCTB","action","transformAttributesFromChatToCTB","attributes","Object","entries","map","attribute","oldAttributesMap","reduce","acc","attr","processedAttributes","removedAttributes","filter","transformChatToCTB","singularName","pluralize","singular","toLowerCase","replace","pluralName","plural","category","modelName","info","displayName","description","collectionName","globalId","contentTypeBase","kind","charAt","toUpperCase","slice","options","draftAndPublish","pluginOptions","i18n","localized","visible","restrictRelationsTo","prev"],"mappings":";;;;;;AAAA;AASA,MAAMA,sBAAAA,GAAyB,CAACC,GAAAA,GAAgBA,GAAAA,CAAIC,UAAU,CAAC,UAAA,CAAA;AAE/D;;;IAIA,MAAMC,mBAAAA,GAAsB,CAACC,MAAAA,EAAgBC,SAAAA,GAAAA;AAC3C,IAAA,IAAID,OAAOE,MAAM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CAAoBC,MAAAA,EAAQC,SAAAA,CAAAA,IAAcD,MAAAA,CAAOE,MAAM,EAAE;QAC3D,OAAO;AACL,YAAA,GAAGkD,eAAe;AAClBlD,YAAAA,MAAAA,EAAQF,OAAOE;AACjB,SAAA;AACF,IAAA;IAEA,OAAOkD,eAAAA;AACT;;;;;"}
|
|
@@ -3,6 +3,20 @@ import omit from 'lodash/omit';
|
|
|
3
3
|
import pluralize from 'pluralize';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
const isPluginContentTypeUid = (uid)=>uid.startsWith('plugin::');
|
|
7
|
+
/**
|
|
8
|
+
* Plugin / extension content-types use server-derived identity (globalId, collectionName, …).
|
|
9
|
+
* The AI chat uses a simplified shape that would otherwise overwrite those fields incorrectly.
|
|
10
|
+
*/ const isPluginContentType = (schema, oldSchema)=>{
|
|
11
|
+
if (schema.plugin || isPluginContentTypeUid(schema.uid)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (oldSchema && 'modelType' in oldSchema && oldSchema.modelType === 'contentType') {
|
|
15
|
+
const ct = oldSchema;
|
|
16
|
+
return Boolean(ct.plugin) || isPluginContentTypeUid(String(ct.uid));
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
6
20
|
const ACTION_TO_STATUS = {
|
|
7
21
|
create: 'NEW',
|
|
8
22
|
remove: 'REMOVED',
|
|
@@ -113,7 +127,7 @@ const ACTION_TO_STATUS = {
|
|
|
113
127
|
globalId: singularName
|
|
114
128
|
};
|
|
115
129
|
}
|
|
116
|
-
|
|
130
|
+
const contentTypeBase = {
|
|
117
131
|
uid: schema.uid,
|
|
118
132
|
modelType: schema.modelType,
|
|
119
133
|
modelName: singularName,
|
|
@@ -142,6 +156,44 @@ const ACTION_TO_STATUS = {
|
|
|
142
156
|
globalId: singularName,
|
|
143
157
|
restrictRelationsTo: null
|
|
144
158
|
};
|
|
159
|
+
if (isPluginContentType(schema, oldSchema) && oldSchema && oldSchema.modelType === 'contentType') {
|
|
160
|
+
const prev = oldSchema;
|
|
161
|
+
return {
|
|
162
|
+
...contentTypeBase,
|
|
163
|
+
plugin: prev.plugin ?? schema.plugin,
|
|
164
|
+
globalId: prev.globalId,
|
|
165
|
+
modelName: prev.modelName,
|
|
166
|
+
collectionName: prev.collectionName,
|
|
167
|
+
info: {
|
|
168
|
+
...contentTypeBase.info,
|
|
169
|
+
singularName: prev.info.singularName,
|
|
170
|
+
pluralName: prev.info.pluralName
|
|
171
|
+
},
|
|
172
|
+
options: {
|
|
173
|
+
...prev.options,
|
|
174
|
+
...contentTypeBase.options,
|
|
175
|
+
draftAndPublish: schema.options?.draftAndPublish ?? prev.options?.draftAndPublish ?? true
|
|
176
|
+
},
|
|
177
|
+
pluginOptions: {
|
|
178
|
+
...prev.pluginOptions,
|
|
179
|
+
...contentTypeBase.pluginOptions,
|
|
180
|
+
i18n: {
|
|
181
|
+
...prev.pluginOptions?.i18n ?? {},
|
|
182
|
+
...contentTypeBase.pluginOptions?.i18n ?? {},
|
|
183
|
+
localized: schema.options?.localized ?? prev.pluginOptions?.i18n?.localized ?? false
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
visible: prev.visible,
|
|
187
|
+
restrictRelationsTo: prev.restrictRelationsTo
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (isPluginContentType(schema, oldSchema) && schema.plugin) {
|
|
191
|
+
return {
|
|
192
|
+
...contentTypeBase,
|
|
193
|
+
plugin: schema.plugin
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return contentTypeBase;
|
|
145
197
|
};
|
|
146
198
|
|
|
147
199
|
export { transformAttributesFromChatToCTB, transformChatToCTB };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCTB.mjs","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/toCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport isEqual from 'lodash/isEqual';\nimport omit from 'lodash/omit';\nimport pluralize from 'pluralize';\n\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst ACTION_TO_STATUS: Record<Schema['action'], ContentType['status']> = {\n create: 'NEW',\n remove: 'REMOVED',\n update: 'CHANGED',\n};\n\n/**\n * Creates a new attribute with the specified status\n */\nconst createAttributeWithStatus = (\n name: string,\n attributeData: Record<string, any>,\n status: AnyAttribute['status']\n): AnyAttribute =>\n ({\n ...attributeData,\n name,\n status,\n }) as AnyAttribute;\n\n/**\n * Determines the status of an attribute by comparing new and old versions\n */\nconst determineAttributeStatus = (\n newAttr: Record<string, any>,\n oldAttr?: AnyAttribute,\n oldSchema?: ContentType | Component\n): AnyAttribute['status'] => {\n if (!oldAttr) {\n return 'NEW';\n }\n\n // If the schema was already new, don't mark attributes as changed, keep them as new.\n if (oldSchema?.status === 'NEW') {\n return 'NEW';\n }\n\n // Compare attributes without the status field to determine if they've changed\n const newAttrWithoutStatus = omit(newAttr, ['status']);\n const oldAttrWithoutStatus = omit(oldAttr, ['status']);\n\n if (!isEqual(newAttrWithoutStatus, oldAttrWithoutStatus)) {\n return 'CHANGED';\n }\n\n // If unchanged, keep the previous status\n return oldAttr.status;\n};\n\n/**\n * Determines the status of a schema by comparing action and checking if oldSchema exists\n */\nconst transformStatusFromChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType['status'] => {\n // If schema has an action, use the mapped status\n if (schema.action) {\n return ACTION_TO_STATUS[schema.action];\n }\n\n // If oldSchema doesn't exist, it's a new schema\n if (!oldSchema) {\n return 'NEW';\n }\n\n // If no action is specified and oldSchema exists, keep the existing status\n return oldSchema.status;\n};\n\n/**\n * Transform attributes from Chat format to CTB format\n * Also performs a diff to determine the status of each attribute\n */\nexport const transformAttributesFromChatToCTB = (\n { action, attributes }: Schema,\n oldSchema?: ContentType | Component\n): AnyAttribute[] => {\n // If it's a new schema or no oldAttributes provided, all attributes are NEW\n if (action === 'create' || !oldSchema) {\n return Object.entries(attributes).map(([name, attribute]) =>\n createAttributeWithStatus(name, attribute, 'NEW')\n );\n }\n\n // Convert old attributes array to a lookup map for faster access\n const oldAttributesMap = oldSchema.attributes.reduce(\n (acc, attr) => ({ ...acc, [attr.name]: attr }),\n {} as Record<string, AnyAttribute>\n );\n\n // Process current attributes (new and changed)\n const processedAttributes = Object.entries(attributes).map(([name, attr]) => {\n const oldAttr = oldAttributesMap[name];\n const status = determineAttributeStatus({ ...attr, name }, oldAttr, oldSchema);\n\n return createAttributeWithStatus(name, attr, status);\n });\n\n // No need to mark removed attributes if the old schema is new, just remove it from the list\n // TODO: Else a validation error occurs on the backend side.\n if (oldSchema?.status === 'NEW') {\n return processedAttributes;\n }\n\n // Find removed attributes (exist in old but not in new)\n const removedAttributes = Object.entries(oldAttributesMap)\n .filter(([name]) => !attributes[name])\n .map(([name, oldAttr]) => createAttributeWithStatus(name, oldAttr, 'REMOVED'));\n\n // Combine both sets of attributes\n return [...processedAttributes, ...removedAttributes];\n};\n\n/**\n * Transform schema format\n * AI chat -> CTB\n *\n * The AI chat returns a simplified format, and this layer transforms it to be compatible with the CTB reducer.\n *\n * We need to keep track of which changes have been made\n */\nexport const transformChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType | Component => {\n const singularName = pluralize.singular(schema.name).toLowerCase().replace(/ /g, '-');\n const pluralName = pluralize.plural(schema.name).toLowerCase().replace(/ /g, '-');\n\n if (schema.modelType === 'component') {\n return {\n category: schema.category || 'default',\n modelName: singularName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n info: {\n displayName: schema.name,\n description: schema.description,\n // TODO\n // icon: schema.icon,\n },\n modelType: schema.modelType,\n uid: schema.uid as any,\n collectionName: pluralName,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n } satisfies Component;\n }\n\n return {\n uid: schema.uid as any,\n modelType: schema.modelType,\n modelName: singularName,\n kind: schema.kind!,\n info: {\n displayName: schema.name.charAt(0).toUpperCase() + schema.name.slice(1),\n // Always keep the old by default\n // @ts-expect-error - not in types\n singularName: oldSchema?.info?.singularName || singularName,\n // Always keep the old by default\n // @ts-expect-error - not in types\n pluralName: oldSchema?.info?.pluralName || pluralName,\n },\n collectionName: pluralName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n options: {\n draftAndPublish: schema.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n i18n: {\n localized: schema.options?.localized ?? false,\n },\n },\n visible: true,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n restrictRelationsTo: null, // TODO: not sure what this is about\n } satisfies ContentType;\n};\n"],"names":["ACTION_TO_STATUS","create","remove","update","createAttributeWithStatus","name","attributeData","status","determineAttributeStatus","newAttr","oldAttr","oldSchema","newAttrWithoutStatus","omit","oldAttrWithoutStatus","isEqual","transformStatusFromChatToCTB","schema","action","transformAttributesFromChatToCTB","attributes","Object","entries","map","attribute","oldAttributesMap","reduce","acc","attr","processedAttributes","removedAttributes","filter","transformChatToCTB","singularName","pluralize","singular","toLowerCase","replace","pluralName","plural","modelType","category","modelName","info","displayName","description","uid","collectionName","globalId","kind","charAt","toUpperCase","slice","options","draftAndPublish","pluginOptions","i18n","localized","visible","restrictRelationsTo"],"mappings":";;;;AAAA;AASA,MAAMA,gBAAAA,GAAoE;IACxEC,MAAAA,EAAQ,KAAA;IACRC,MAAAA,EAAQ,SAAA;IACRC,MAAAA,EAAQ;AACV,CAAA;AAEA;;AAEC,IACD,MAAMC,yBAAAA,GAA4B,CAChCC,IAAAA,EACAC,aAAAA,EACAC,UAEC;AACC,QAAA,GAAGD,aAAa;AAChBD,QAAAA,IAAAA;AACAE,QAAAA;KACF,CAAA;AAEF;;AAEC,IACD,MAAMC,wBAAAA,GAA2B,CAC/BC,OAAAA,EACAC,OAAAA,EACAC,SAAAA,GAAAA;AAEA,IAAA,IAAI,CAACD,OAAAA,EAAS;QACZ,OA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;QACrD0C,OAAAA,EAAS;YACPC,eAAAA,EAAiBrC,MAAAA,CAAOoC,OAAO,EAAEC,eAAAA,IAAmB;AACtD,SAAA;QACAC,aAAAA,EAAe;YACbC,IAAAA,EAAM;gBACJC,SAAAA,EAAWxC,MAAAA,CAAOoC,OAAO,EAAEI,SAAAA,IAAa;AAC1C;AACF,SAAA;QACAC,OAAAA,EAAS,IAAA;AACTnD,QAAAA,MAAAA,EAAQS,6BAA6BC,MAAAA,EAAQN,SAAAA,CAAAA;QAC7CqC,QAAAA,EAAUf,YAAAA;QACV0B,mBAAAA,EAAqB;AACvB,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"toCTB.mjs","sources":["../../../../../../../admin/src/components/AIChat/lib/transforms/schemas/toCTB.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\nimport isEqual from 'lodash/isEqual';\nimport omit from 'lodash/omit';\nimport pluralize from 'pluralize';\n\nimport { Schema } from '../../types/schema';\n\nimport type { ContentType, Component, AnyAttribute } from '../../../../../types';\n\nconst isPluginContentTypeUid = (uid: string) => uid.startsWith('plugin::');\n\n/**\n * Plugin / extension content-types use server-derived identity (globalId, collectionName, …).\n * The AI chat uses a simplified shape that would otherwise overwrite those fields incorrectly.\n */\nconst isPluginContentType = (schema: Schema, oldSchema?: ContentType | Component): boolean => {\n if (schema.plugin || isPluginContentTypeUid(schema.uid)) {\n return true;\n }\n if (oldSchema && 'modelType' in oldSchema && oldSchema.modelType === 'contentType') {\n const ct = oldSchema as ContentType;\n return Boolean(ct.plugin) || isPluginContentTypeUid(String(ct.uid));\n }\n return false;\n};\n\nconst ACTION_TO_STATUS: Record<Schema['action'], ContentType['status']> = {\n create: 'NEW',\n remove: 'REMOVED',\n update: 'CHANGED',\n};\n\n/**\n * Creates a new attribute with the specified status\n */\nconst createAttributeWithStatus = (\n name: string,\n attributeData: Record<string, any>,\n status: AnyAttribute['status']\n): AnyAttribute =>\n ({\n ...attributeData,\n name,\n status,\n }) as AnyAttribute;\n\n/**\n * Determines the status of an attribute by comparing new and old versions\n */\nconst determineAttributeStatus = (\n newAttr: Record<string, any>,\n oldAttr?: AnyAttribute,\n oldSchema?: ContentType | Component\n): AnyAttribute['status'] => {\n if (!oldAttr) {\n return 'NEW';\n }\n\n // If the schema was already new, don't mark attributes as changed, keep them as new.\n if (oldSchema?.status === 'NEW') {\n return 'NEW';\n }\n\n // Compare attributes without the status field to determine if they've changed\n const newAttrWithoutStatus = omit(newAttr, ['status']);\n const oldAttrWithoutStatus = omit(oldAttr, ['status']);\n\n if (!isEqual(newAttrWithoutStatus, oldAttrWithoutStatus)) {\n return 'CHANGED';\n }\n\n // If unchanged, keep the previous status\n return oldAttr.status;\n};\n\n/**\n * Determines the status of a schema by comparing action and checking if oldSchema exists\n */\nconst transformStatusFromChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType['status'] => {\n // If schema has an action, use the mapped status\n if (schema.action) {\n return ACTION_TO_STATUS[schema.action];\n }\n\n // If oldSchema doesn't exist, it's a new schema\n if (!oldSchema) {\n return 'NEW';\n }\n\n // If no action is specified and oldSchema exists, keep the existing status\n return oldSchema.status;\n};\n\n/**\n * Transform attributes from Chat format to CTB format\n * Also performs a diff to determine the status of each attribute\n */\nexport const transformAttributesFromChatToCTB = (\n { action, attributes }: Schema,\n oldSchema?: ContentType | Component\n): AnyAttribute[] => {\n // If it's a new schema or no oldAttributes provided, all attributes are NEW\n if (action === 'create' || !oldSchema) {\n return Object.entries(attributes).map(([name, attribute]) =>\n createAttributeWithStatus(name, attribute, 'NEW')\n );\n }\n\n // Convert old attributes array to a lookup map for faster access\n const oldAttributesMap = oldSchema.attributes.reduce(\n (acc, attr) => ({ ...acc, [attr.name]: attr }),\n {} as Record<string, AnyAttribute>\n );\n\n // Process current attributes (new and changed)\n const processedAttributes = Object.entries(attributes).map(([name, attr]) => {\n const oldAttr = oldAttributesMap[name];\n const status = determineAttributeStatus({ ...attr, name }, oldAttr, oldSchema);\n\n return createAttributeWithStatus(name, attr, status);\n });\n\n // No need to mark removed attributes if the old schema is new, just remove it from the list\n // TODO: Else a validation error occurs on the backend side.\n if (oldSchema?.status === 'NEW') {\n return processedAttributes;\n }\n\n // Find removed attributes (exist in old but not in new)\n const removedAttributes = Object.entries(oldAttributesMap)\n .filter(([name]) => !attributes[name])\n .map(([name, oldAttr]) => createAttributeWithStatus(name, oldAttr, 'REMOVED'));\n\n // Combine both sets of attributes\n return [...processedAttributes, ...removedAttributes];\n};\n\n/**\n * Transform schema format\n * AI chat -> CTB\n *\n * The AI chat returns a simplified format, and this layer transforms it to be compatible with the CTB reducer.\n *\n * We need to keep track of which changes have been made\n */\nexport const transformChatToCTB = (\n schema: Schema,\n oldSchema?: ContentType | Component\n): ContentType | Component => {\n const singularName = pluralize.singular(schema.name).toLowerCase().replace(/ /g, '-');\n const pluralName = pluralize.plural(schema.name).toLowerCase().replace(/ /g, '-');\n\n if (schema.modelType === 'component') {\n return {\n category: schema.category || 'default',\n modelName: singularName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n info: {\n displayName: schema.name,\n description: schema.description,\n // TODO\n // icon: schema.icon,\n },\n modelType: schema.modelType,\n uid: schema.uid as any,\n collectionName: pluralName,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n } satisfies Component;\n }\n\n const contentTypeBase = {\n uid: schema.uid as any,\n modelType: schema.modelType,\n modelName: singularName,\n kind: schema.kind!,\n info: {\n displayName: schema.name.charAt(0).toUpperCase() + schema.name.slice(1),\n // Always keep the old by default\n // @ts-expect-error - not in types\n singularName: oldSchema?.info?.singularName || singularName,\n // Always keep the old by default\n // @ts-expect-error - not in types\n pluralName: oldSchema?.info?.pluralName || pluralName,\n },\n collectionName: pluralName,\n attributes: transformAttributesFromChatToCTB(schema, oldSchema),\n options: {\n draftAndPublish: schema.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n i18n: {\n localized: schema.options?.localized ?? false,\n },\n },\n visible: true,\n status: transformStatusFromChatToCTB(schema, oldSchema),\n globalId: singularName,\n restrictRelationsTo: null, // TODO: not sure what this is about\n } satisfies ContentType;\n\n if (\n isPluginContentType(schema, oldSchema) &&\n oldSchema &&\n oldSchema.modelType === 'contentType'\n ) {\n const prev = oldSchema as ContentType;\n return {\n ...contentTypeBase,\n plugin: prev.plugin ?? schema.plugin,\n globalId: prev.globalId,\n modelName: prev.modelName,\n collectionName: prev.collectionName,\n info: {\n ...contentTypeBase.info,\n singularName: prev.info.singularName,\n pluralName: prev.info.pluralName,\n },\n options: {\n ...prev.options,\n ...contentTypeBase.options,\n draftAndPublish: schema.options?.draftAndPublish ?? prev.options?.draftAndPublish ?? true,\n },\n pluginOptions: {\n ...prev.pluginOptions,\n ...contentTypeBase.pluginOptions,\n i18n: {\n ...((prev.pluginOptions?.i18n as Record<string, unknown> | undefined) ?? {}),\n ...((contentTypeBase.pluginOptions?.i18n as Record<string, unknown> | undefined) ?? {}),\n localized:\n schema.options?.localized ??\n (prev.pluginOptions?.i18n as { localized?: boolean } | undefined)?.localized ??\n false,\n },\n },\n visible: prev.visible,\n restrictRelationsTo: prev.restrictRelationsTo,\n } satisfies ContentType;\n }\n\n if (isPluginContentType(schema, oldSchema) && schema.plugin) {\n return {\n ...contentTypeBase,\n plugin: schema.plugin,\n } satisfies ContentType;\n }\n\n return contentTypeBase;\n};\n"],"names":["isPluginContentTypeUid","uid","startsWith","isPluginContentType","schema","oldSchema","plugin","modelType","ct","Boolean","String","ACTION_TO_STATUS","create","remove","update","createAttributeWithStatus","name","attributeData","status","determineAttributeStatus","newAttr","oldAttr","newAttrWithoutStatus","omit","oldAttrWithoutStatus","isEqual","transformStatusFromChatToCTB","action","transformAttributesFromChatToCTB","attributes","Object","entries","map","attribute","oldAttributesMap","reduce","acc","attr","processedAttributes","removedAttributes","filter","transformChatToCTB","singularName","pluralize","singular","toLowerCase","replace","pluralName","plural","category","modelName","info","displayName","description","collectionName","globalId","contentTypeBase","kind","charAt","toUpperCase","slice","options","draftAndPublish","pluginOptions","i18n","localized","visible","restrictRelationsTo","prev"],"mappings":";;;;AAAA;AASA,MAAMA,sBAAAA,GAAyB,CAACC,GAAAA,GAAgBA,GAAAA,CAAIC,UAAU,CAAC,UAAA,CAAA;AAE/D;;;IAIA,MAAMC,mBAAAA,GAAsB,CAACC,MAAAA,EAAgBC,SAAAA,GAAAA;AAC3C,IAAA,IAAID,OAAOE,MAAM,IAAIN,sBAAAA,CAAuBI,MAAAA,CAAOH,GAAG,CAAA,EAAG;QACvD,OAAO,IAAA;AACT,IAAA;AACA,IAAA,IAAII,aAAa,WAAA,IAAeA,SAAAA,IAAaA,SAAAA,CAAUE,SAAS,KAAK,aAAA,EAAe;AAClF,QAAA,MAAMC,EAAAA,GAAKH,SAAAA;AACX,QAAA,OAAOI,QAAQD,EAAAA,CAAGF,MAAM,KAAKN,sBAAAA,CAAuBU,MAAAA,CAAOF,GAAGP,GAAG,CAAA,CAAA;AACnE,IAAA;IACA,OAAO,KAAA;AACT,CAAA;AAEA,MAAMU,gBAAAA,GAAoE;IACxEC,MAAAA,EAAQ,KAAA;IACRC,MAAAA,EAAQ,SAAA;IACRC,MAAAA,EAAQ;AACV,CAAA;AAEA;;AAEC,IACD,MAAMC,yBAAAA,GAA4B,CAChCC,IAAAA,EACAC,aAAAA,EACAC,UAEC;AACC,QAAA,GAAGD,aAAa;AAChBD,QAAAA,IAAAA;AACAE,QAAAA;KACF,CAAA;AAEF;;AAEC,IACD,MAAMC,wBAAAA,GAA2B,CAC/BC,OAAAA,EACAC,OAAAA,EACAhB,SAAAA,GAAAA;AAEA,IAAA,IAAI,CAACgB,OAAAA,EAAS;QACZ,OAAO,KAAA;AACT,IAAA;;IAGA,IAAIhB,SAAAA,EAAWa,WAAW,KAAA,EAAO;QAC/B,OAAO,KAAA;AACT,IAAA;;IAGA,MAAMI,oBAAAA,GAAuBC,KAAKH,OAAAA,EAAS;AAAC,QAAA;AAAS,KAAA,CAAA;IACrD,MAAMI,oBAA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gD,EAAE;oBACtFC,SAAAA,EACE7D,MAAAA,CAAOyD,OAAO,EAAEI,SAAAA,IACfG,KAAKL,aAAa,EAAEC,MAA8CC,SAAAA,IACnE;AACJ;AACF,aAAA;AACAC,YAAAA,OAAAA,EAASE,KAAKF,OAAO;AACrBC,YAAAA,mBAAAA,EAAqBC,KAAKD;AAC5B,SAAA;AACF,IAAA;AAEA,IAAA,IAAIhE,mBAAAA,CAAoBC,MAAAA,EAAQC,SAAAA,CAAAA,IAAcD,MAAAA,CAAOE,MAAM,EAAE;QAC3D,OAAO;AACL,YAAA,GAAGkD,eAAe;AAClBlD,YAAAA,MAAAA,EAAQF,OAAOE;AACjB,SAAA;AACF,IAAA;IAEA,OAAOkD,eAAAA;AACT;;;;"}
|
|
@@ -5,6 +5,8 @@ export type Schema = {
|
|
|
5
5
|
action: 'create' | 'update' | 'remove';
|
|
6
6
|
kind?: 'singleType' | 'collectionType';
|
|
7
7
|
uid: string;
|
|
8
|
+
/** Set for plugin content-types (`plugin::…`) */
|
|
9
|
+
plugin?: string;
|
|
8
10
|
modelType: 'component' | 'contentType';
|
|
9
11
|
category?: string;
|
|
10
12
|
description?: string;
|