@strapi/core 0.0.0-experimental.80cf2c74a2003f3c0602abc81888dd9f36dc68a3 → 0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +6 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +6 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/core-api/controller/index.js +5 -5
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +6 -6
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/registries/policies.d.ts +22 -10
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +64 -18
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +65 -19
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +18 -0
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +27 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +27 -1
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +4 -0
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +4 -0
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +12 -2
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +13 -3
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/populate.js +1 -1
- package/dist/services/document-service/transform/populate.js.map +1 -1
- package/dist/services/document-service/transform/populate.mjs +1 -1
- package/dist/services/document-service/transform/populate.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/entity-service/components.d.ts.map +1 -1
- package/dist/services/entity-service/components.js +1 -4
- package/dist/services/entity-service/components.js.map +1 -1
- package/dist/services/entity-service/components.mjs +1 -4
- package/dist/services/entity-service/components.mjs.map +1 -1
- package/dist/services/entity-service/index.d.ts.map +1 -1
- package/dist/services/entity-service/index.js +14 -15
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs +15 -16
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/query-params.d.ts +7 -0
- package/dist/services/query-params.d.ts.map +1 -0
- package/dist/services/query-params.js +12 -0
- package/dist/services/query-params.js.map +1 -0
- package/dist/services/query-params.mjs +13 -0
- package/dist/services/query-params.mjs.map +1 -0
- package/dist/services/server/compose-endpoint.d.ts.map +1 -1
- package/dist/services/server/compose-endpoint.js +1 -2
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs +2 -3
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/policy.d.ts +2 -2
- package/dist/services/server/policy.d.ts.map +1 -1
- package/dist/services/server/policy.js +4 -4
- package/dist/services/server/policy.js.map +1 -1
- package/dist/services/server/policy.mjs +4 -4
- package/dist/services/server/policy.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +15 -15
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +77 -85
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +77 -85
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, utils, type MetadataOptions } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\nconst { identifiers } = utils;\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ],\n options\n );\n};\n\nexport const getDzJoinTableName = (collectionName: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentJoinColumnEntityName = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentJoinColumnInverseName = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentTypeColumn = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }], options);\n};\n\nexport const getComponentFkIndexName = (contentType: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ],\n options\n );\n};\n\nconst { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, options);\n const joinColumnEntityName = getComponentJoinColumnEntityName(options);\n const joinColumnInverseName = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n on: {\n field: name,\n },\n orderColumnName: order,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, compTypeColumn],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, options);\n const joinColumnEntityName = getComponentJoinColumnEntityName(options);\n const joinColumnInverseName = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, compTypeColumn],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n options\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, options);\n\n const entityId = getComponentJoinColumnEntityName(options);\n const componentId = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, options);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [id]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [field]: {\n type: 'string',\n },\n [order]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, field], options),\n columns: [field],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn], options),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName], options),\n columns: [entityId, componentId, field, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [id],\n referencedTable: identifiers.getTableName(contentType.collectionName, options),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n options: MetadataOptions\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', id];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, options);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [id]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, options),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["utils","createId","assert","_"],"mappings":";;;;;;;;;AAMA,MAAM,EAAE,YAAgB,IAAAA;AAeX,MAAA,4BAA4B,CAAC,gBAAwB,YAA6B;AAC7F,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,MAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,IAC/D;AAAA,IACA;AAAA,EAAA;AAEJ;AAEa,MAAA,qBAAqB,CAAC,gBAAwB,YAA6B;AACtF,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,MAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,IAC/D;AAAA,IACA;AAAA,EAAA;AAEJ;AAEa,MAAA,mCAAmC,CAAC,YAA6B;AAC5E,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,EAAE,MAAM,UAAU,cAAc,MAAM;AAAA,MACtC,EAAE,MAAM,MAAM,cAAc,MAAM;AAAA,IACpC;AAAA,IACA;AAAA,EAAA;AAEJ;AAEa,MAAA,oCAAoC,CAAC,YAA6B;AAC7E,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,EAAE,MAAM,aAAa,WAAW,OAAO,cAAc,MAAM;AAAA,MAC3D,EAAE,MAAM,MAAM,cAAc,MAAM;AAAA,IACpC;AAAA,IACA;AAAA,EAAA;AAEJ;AAEa,MAAA,yBAAyB,CAAC,YAA6B;AAC3D,SAAA,YAAY,kBAAkB,CAAC,EAAE,MAAM,kBAAkB,cAAc,MAAA,CAAO,GAAG,OAAO;AACjG;AAEa,MAAA,0BAA0B,CAAC,aAAqB,YAA6B;AACxF,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,E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ACT;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["createId","assert","_"],"mappings":";;;;;;;;AAmBa,MAAA,4BAA4B,CAAC,gBAAwB,gBAA6B;AAC7F,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,IAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,EAAA,CAC9D;AACH;AAEa,MAAA,qBAAqB,CAAC,gBAAwB,gBAA6B;AACtF,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,IAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,EAAA,CAC9D;AACH;AAEa,MAAA,mCAAmC,CAAC,gBAA6B;AAC5E,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,UAAU,cAAc,MAAM;AAAA,IACtC,EAAE,MAAM,MAAM,cAAc,MAAM;AAAA,EAAA,CACnC;AACH;AAEa,MAAA,oCAAoC,CAAC,gBAA6B;AAC7E,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,aAAa,WAAW,OAAO,cAAc,MAAM;AAAA,IAC3D,EAAE,MAAM,MAAM,cAAc,MAAM;AAAA,EAAA,CACnC;AACH;AAEa,MAAA,yBAAyB,CAAC,gBAA6B;AAC3D,SAAA,YAAY,kBAAkB,CAAC,EAAE,MAAM,kBAAkB,cAAc,MAAO,CAAA,CAAC;AACxF;AAEa,MAAA,0BAA0B,CAAC,aAAqB,gBAA6B;AACxF,SAAO,YAAY,kBAAkB;AAAA,IACnC,EA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AAA,EAAA,CAClB;AAEM,SAAA;AACT;;;;;;;;;;;;"}
|
|
@@ -1,59 +1,41 @@
|
|
|
1
|
-
import { utils } from "@strapi/database";
|
|
2
1
|
import { createId } from "@paralleldrive/cuid2";
|
|
3
2
|
import assert from "node:assert";
|
|
4
3
|
import _ from "lodash/fp";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{ name: "components", shortName: "cmps", compressible: false }
|
|
11
|
-
],
|
|
12
|
-
options
|
|
13
|
-
);
|
|
4
|
+
const getComponentJoinTableName = (collectionName, identifiers) => {
|
|
5
|
+
return identifiers.getNameFromTokens([
|
|
6
|
+
{ name: collectionName, compressible: true },
|
|
7
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
|
8
|
+
]);
|
|
14
9
|
};
|
|
15
|
-
const getDzJoinTableName = (collectionName,
|
|
16
|
-
return identifiers.getNameFromTokens(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
],
|
|
21
|
-
options
|
|
22
|
-
);
|
|
10
|
+
const getDzJoinTableName = (collectionName, identifiers) => {
|
|
11
|
+
return identifiers.getNameFromTokens([
|
|
12
|
+
{ name: collectionName, compressible: true },
|
|
13
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
|
14
|
+
]);
|
|
23
15
|
};
|
|
24
|
-
const getComponentJoinColumnEntityName = (
|
|
25
|
-
return identifiers.getNameFromTokens(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
],
|
|
30
|
-
options
|
|
31
|
-
);
|
|
16
|
+
const getComponentJoinColumnEntityName = (identifiers) => {
|
|
17
|
+
return identifiers.getNameFromTokens([
|
|
18
|
+
{ name: "entity", compressible: false },
|
|
19
|
+
{ name: "id", compressible: false }
|
|
20
|
+
]);
|
|
32
21
|
};
|
|
33
|
-
const getComponentJoinColumnInverseName = (
|
|
34
|
-
return identifiers.getNameFromTokens(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
],
|
|
39
|
-
options
|
|
40
|
-
);
|
|
22
|
+
const getComponentJoinColumnInverseName = (identifiers) => {
|
|
23
|
+
return identifiers.getNameFromTokens([
|
|
24
|
+
{ name: "component", shortName: "cmp", compressible: false },
|
|
25
|
+
{ name: "id", compressible: false }
|
|
26
|
+
]);
|
|
41
27
|
};
|
|
42
|
-
const getComponentTypeColumn = (
|
|
43
|
-
return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]
|
|
28
|
+
const getComponentTypeColumn = (identifiers) => {
|
|
29
|
+
return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]);
|
|
44
30
|
};
|
|
45
|
-
const getComponentFkIndexName = (contentType,
|
|
46
|
-
return identifiers.getNameFromTokens(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
],
|
|
52
|
-
options
|
|
53
|
-
);
|
|
31
|
+
const getComponentFkIndexName = (contentType, identifiers) => {
|
|
32
|
+
return identifiers.getNameFromTokens([
|
|
33
|
+
{ name: contentType, compressible: true },
|
|
34
|
+
{ name: "entity", compressible: false },
|
|
35
|
+
{ name: "fk", compressible: false }
|
|
36
|
+
]);
|
|
54
37
|
};
|
|
55
|
-
const
|
|
56
|
-
const transformAttribute = (name, attribute, contentType, options) => {
|
|
38
|
+
const transformAttribute = (name, attribute, contentType, identifiers) => {
|
|
57
39
|
switch (attribute.type) {
|
|
58
40
|
case "media": {
|
|
59
41
|
return {
|
|
@@ -64,10 +46,10 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
64
46
|
};
|
|
65
47
|
}
|
|
66
48
|
case "component": {
|
|
67
|
-
const joinTableName = getComponentJoinTableName(contentType.collectionName,
|
|
68
|
-
const joinColumnEntityName = getComponentJoinColumnEntityName(
|
|
69
|
-
const joinColumnInverseName = getComponentJoinColumnInverseName(
|
|
70
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
49
|
+
const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);
|
|
50
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
|
51
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
|
52
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
71
53
|
return {
|
|
72
54
|
type: "relation",
|
|
73
55
|
relation: attribute.repeatable === true ? "oneToMany" : "oneToOne",
|
|
@@ -78,28 +60,33 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
78
60
|
name: joinTableName,
|
|
79
61
|
joinColumn: {
|
|
80
62
|
name: joinColumnEntityName,
|
|
81
|
-
referencedColumn:
|
|
63
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
82
64
|
},
|
|
83
65
|
inverseJoinColumn: {
|
|
84
66
|
name: joinColumnInverseName,
|
|
85
|
-
referencedColumn:
|
|
67
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
86
68
|
},
|
|
87
69
|
on: {
|
|
88
70
|
field: name
|
|
89
71
|
},
|
|
90
|
-
orderColumnName:
|
|
72
|
+
orderColumnName: identifiers.ORDER_COLUMN,
|
|
91
73
|
orderBy: {
|
|
92
74
|
order: "asc"
|
|
93
75
|
},
|
|
94
|
-
pivotColumns: [
|
|
76
|
+
pivotColumns: [
|
|
77
|
+
joinColumnEntityName,
|
|
78
|
+
joinColumnInverseName,
|
|
79
|
+
identifiers.FIELD_COLUMN,
|
|
80
|
+
compTypeColumn
|
|
81
|
+
]
|
|
95
82
|
}
|
|
96
83
|
};
|
|
97
84
|
}
|
|
98
85
|
case "dynamiczone": {
|
|
99
|
-
const joinTableName = getDzJoinTableName(contentType.collectionName,
|
|
100
|
-
const joinColumnEntityName = getComponentJoinColumnEntityName(
|
|
101
|
-
const joinColumnInverseName = getComponentJoinColumnInverseName(
|
|
102
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
86
|
+
const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);
|
|
87
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
|
88
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
|
89
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
103
90
|
return {
|
|
104
91
|
type: "relation",
|
|
105
92
|
relation: "morphToMany",
|
|
@@ -109,12 +96,12 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
109
96
|
name: joinTableName,
|
|
110
97
|
joinColumn: {
|
|
111
98
|
name: joinColumnEntityName,
|
|
112
|
-
referencedColumn:
|
|
99
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
113
100
|
},
|
|
114
101
|
morphColumn: {
|
|
115
102
|
idColumn: {
|
|
116
103
|
name: joinColumnInverseName,
|
|
117
|
-
referencedColumn:
|
|
104
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
118
105
|
},
|
|
119
106
|
typeColumn: {
|
|
120
107
|
name: compTypeColumn
|
|
@@ -127,7 +114,12 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
127
114
|
orderBy: {
|
|
128
115
|
order: "asc"
|
|
129
116
|
},
|
|
130
|
-
pivotColumns: [
|
|
117
|
+
pivotColumns: [
|
|
118
|
+
joinColumnEntityName,
|
|
119
|
+
joinColumnInverseName,
|
|
120
|
+
identifiers.FIELD_COLUMN,
|
|
121
|
+
compTypeColumn
|
|
122
|
+
]
|
|
131
123
|
}
|
|
132
124
|
};
|
|
133
125
|
}
|
|
@@ -136,7 +128,7 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
136
128
|
}
|
|
137
129
|
}
|
|
138
130
|
};
|
|
139
|
-
const transformAttributes = (contentType,
|
|
131
|
+
const transformAttributes = (contentType, identifiers) => {
|
|
140
132
|
return Object.keys(contentType.attributes || {}).reduce((attrs, attrName) => {
|
|
141
133
|
return {
|
|
142
134
|
...attrs,
|
|
@@ -144,7 +136,7 @@ const transformAttributes = (contentType, options) => {
|
|
|
144
136
|
attrName,
|
|
145
137
|
contentType.attributes[attrName],
|
|
146
138
|
contentType,
|
|
147
|
-
|
|
139
|
+
identifiers
|
|
148
140
|
)
|
|
149
141
|
};
|
|
150
142
|
}, {});
|
|
@@ -155,19 +147,19 @@ const hasComponentsOrDz = (contentType) => {
|
|
|
155
147
|
);
|
|
156
148
|
};
|
|
157
149
|
const createDocumentId = createId;
|
|
158
|
-
const createCompoLinkModel = (contentType,
|
|
159
|
-
const name = getComponentJoinTableName(contentType.collectionName,
|
|
160
|
-
const entityId = getComponentJoinColumnEntityName(
|
|
161
|
-
const componentId = getComponentJoinColumnInverseName(
|
|
162
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
163
|
-
const fkIndex = getComponentFkIndexName(contentType.collectionName,
|
|
150
|
+
const createCompoLinkModel = (contentType, identifiers) => {
|
|
151
|
+
const name = getComponentJoinTableName(contentType.collectionName, identifiers);
|
|
152
|
+
const entityId = getComponentJoinColumnEntityName(identifiers);
|
|
153
|
+
const componentId = getComponentJoinColumnInverseName(identifiers);
|
|
154
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
155
|
+
const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);
|
|
164
156
|
return {
|
|
165
157
|
// TODO: make sure there can't be any conflicts with a prefix
|
|
166
158
|
singularName: name,
|
|
167
159
|
uid: name,
|
|
168
160
|
tableName: name,
|
|
169
161
|
attributes: {
|
|
170
|
-
[
|
|
162
|
+
[identifiers.ID_COLUMN]: {
|
|
171
163
|
type: "increments"
|
|
172
164
|
},
|
|
173
165
|
[entityId]: {
|
|
@@ -185,10 +177,10 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
185
177
|
[compTypeColumn]: {
|
|
186
178
|
type: "string"
|
|
187
179
|
},
|
|
188
|
-
[
|
|
180
|
+
[identifiers.FIELD_COLUMN]: {
|
|
189
181
|
type: "string"
|
|
190
182
|
},
|
|
191
|
-
[
|
|
183
|
+
[identifiers.ORDER_COLUMN]: {
|
|
192
184
|
type: "float",
|
|
193
185
|
column: {
|
|
194
186
|
unsigned: true,
|
|
@@ -198,11 +190,11 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
198
190
|
},
|
|
199
191
|
indexes: [
|
|
200
192
|
{
|
|
201
|
-
name: identifiers.getIndexName([contentType.collectionName,
|
|
202
|
-
columns: [
|
|
193
|
+
name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),
|
|
194
|
+
columns: [identifiers.FIELD_COLUMN]
|
|
203
195
|
},
|
|
204
196
|
{
|
|
205
|
-
name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]
|
|
197
|
+
name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),
|
|
206
198
|
columns: [compTypeColumn]
|
|
207
199
|
},
|
|
208
200
|
{
|
|
@@ -211,8 +203,8 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
211
203
|
},
|
|
212
204
|
{
|
|
213
205
|
// NOTE: since we don't include attribute names, we need to be careful not to create another unique index
|
|
214
|
-
name: identifiers.getUniqueIndexName([contentType.collectionName]
|
|
215
|
-
columns: [entityId, componentId,
|
|
206
|
+
name: identifiers.getUniqueIndexName([contentType.collectionName]),
|
|
207
|
+
columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],
|
|
216
208
|
type: "unique"
|
|
217
209
|
}
|
|
218
210
|
],
|
|
@@ -220,21 +212,21 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
220
212
|
{
|
|
221
213
|
name: fkIndex,
|
|
222
214
|
columns: [entityId],
|
|
223
|
-
referencedColumns: [
|
|
224
|
-
referencedTable: identifiers.getTableName(contentType.collectionName
|
|
215
|
+
referencedColumns: [identifiers.ID_COLUMN],
|
|
216
|
+
referencedTable: identifiers.getTableName(contentType.collectionName),
|
|
225
217
|
onDelete: "CASCADE"
|
|
226
218
|
}
|
|
227
219
|
]
|
|
228
220
|
};
|
|
229
221
|
};
|
|
230
|
-
const transformContentTypesToModels = (contentTypes,
|
|
222
|
+
const transformContentTypesToModels = (contentTypes, identifiers) => {
|
|
231
223
|
const models = [];
|
|
232
224
|
contentTypes.forEach((contentType) => {
|
|
233
225
|
assert(contentType.collectionName, 'Content type "collectionName" is required');
|
|
234
226
|
assert(contentType.modelName, 'Content type "modelName" is required');
|
|
235
227
|
assert(contentType.uid, 'Content type "uid" is required');
|
|
236
228
|
const documentIdAttribute = contentType.modelType === "contentType" ? { documentId: { type: "string", default: createDocumentId } } : {};
|
|
237
|
-
const reservedAttributeNames = ["document_id",
|
|
229
|
+
const reservedAttributeNames = ["document_id", identifiers.ID_COLUMN];
|
|
238
230
|
Object.keys(contentType.attributes || {}).forEach((attributeName) => {
|
|
239
231
|
const snakeCasedAttributeName = _.snakeCase(attributeName);
|
|
240
232
|
if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
|
|
@@ -244,7 +236,7 @@ const transformContentTypesToModels = (contentTypes, options) => {
|
|
|
244
236
|
}
|
|
245
237
|
});
|
|
246
238
|
if (hasComponentsOrDz(contentType)) {
|
|
247
|
-
const compoLinkModel = createCompoLinkModel(contentType,
|
|
239
|
+
const compoLinkModel = createCompoLinkModel(contentType, identifiers);
|
|
248
240
|
models.push(compoLinkModel);
|
|
249
241
|
}
|
|
250
242
|
const model = {
|
|
@@ -253,11 +245,11 @@ const transformContentTypesToModels = (contentTypes, options) => {
|
|
|
253
245
|
tableName: contentType.collectionName,
|
|
254
246
|
// This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice
|
|
255
247
|
attributes: {
|
|
256
|
-
[
|
|
248
|
+
[identifiers.ID_COLUMN]: {
|
|
257
249
|
type: "increments"
|
|
258
250
|
},
|
|
259
251
|
...documentIdAttribute,
|
|
260
|
-
...transformAttributes(contentType,
|
|
252
|
+
...transformAttributes(contentType, identifiers)
|
|
261
253
|
}
|
|
262
254
|
};
|
|
263
255
|
models.push(model);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, utils, type MetadataOptions } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\nconst { identifiers } = utils;\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ],\n options\n );\n};\n\nexport const getDzJoinTableName = (collectionName: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentJoinColumnEntityName = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentJoinColumnInverseName = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ],\n options\n );\n};\n\nexport const getComponentTypeColumn = (options: MetadataOptions) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }], options);\n};\n\nexport const getComponentFkIndexName = (contentType: string, options: MetadataOptions) => {\n return identifiers.getNameFromTokens(\n [\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ],\n options\n );\n};\n\nconst { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, options);\n const joinColumnEntityName = getComponentJoinColumnEntityName(options);\n const joinColumnInverseName = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n on: {\n field: name,\n },\n orderColumnName: order,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, compTypeColumn],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, options);\n const joinColumnEntityName = getComponentJoinColumnEntityName(options);\n const joinColumnInverseName = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, compTypeColumn],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n options\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n options: MetadataOptions\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, options);\n\n const entityId = getComponentJoinColumnEntityName(options);\n const componentId = getComponentJoinColumnInverseName(options);\n const compTypeColumn = getComponentTypeColumn(options);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, options);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [id]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [field]: {\n type: 'string',\n },\n [order]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, field], options),\n columns: [field],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn], options),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName], options),\n columns: [entityId, componentId, field, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [id],\n referencedTable: identifiers.getTableName(contentType.collectionName, options),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n options: MetadataOptions\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', id];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, options);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [id]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, options),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,EAAE,YAAgB,IAAA;AAeX,MAAA,4BAA4B,CAAC,gBAAwB,YAA6B;AAC7F,SAAO,YAAY;AAAA,IACjB;AAAA,MACE,E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AACvE,WAAA,YAAY,WAAW,sCAAsC;AAC7D,WAAA,YAAY,KAAK,gCAAgC;AAIxD,UAAM,sBACJ,YAAY,cAAc,gBACtB,EAAE,YAAY,EAAE,MAAM,UAAU,SAAS,iBAAiB,EAAA,IAC1D,CAAA;AAIA,UAAA,yBAAyB,CAAC,eAAe,EAAE;AAC1C,WAAA,KAAK,YAAY,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,kBAAkB;AAC7D,YAAA,0BAA0B,EAAE,UAAU,aAAa;AACrD,UAAA,uBAAuB,SAAS,uBAAuB,GAAG;AAC5D,cAAM,IAAI;AAAA,UACR,kBAAkB,aAAa,+DAA+D,YAAY,SAAS,gBAAgB,aAAa;AAAA,QAAA;AAAA,MAEpJ;AAAA,IAAA,CACD;AAEG,QAAA,kBAAkB,WAAW,GAAG;AAC5B,YAAA,iBAAiB,qBAAqB,aAAa,OAAO;AAChE,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,UAAM,QAAe;AAAA,MACnB,KAAK,YAAY;AAAA,MACjB,cAAc,YAAY;AAAA,MAC1B,WAAW,YAAY;AAAA;AAAA,MACvB,YAAY;AAAA,QACV,CAAC,EAAE,GAAG;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,QACA,GAAG;AAAA,QACH,GAAG,oBAAoB,aAAa,OAAO;AAAA,MAC7C;AAAA,IAAA;AAGF,WAAO,KAAK,KAAK;AAAA,EAAA,CAClB;AAEM,SAAA;AACT;"}
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":[],"mappings":";;;AAmBa,MAAA,4BAA4B,CAAC,gBAAwB,gBAA6B;AAC7F,SAAO,YAAY,kBAAkB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KAAK,gCAAgC;AAIxD,UAAM,sBACJ,YAAY,cAAc,gBACtB,EAAE,YAAY,EAAE,MAAM,UAAU,SAAS,iBAAiB,EAAA,IAC1D,CAAA;AAIN,UAAM,yBAAyB,CAAC,eAAe,YAAY,SAAS;AAC7D,WAAA,KAAK,YAAY,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,kBAAkB;AAC7D,YAAA,0BAA0B,EAAE,UAAU,aAAa;AACrD,UAAA,uBAAuB,SAAS,uBAAuB,GAAG;AAC5D,cAAM,IAAI;AAAA,UACR,kBAAkB,aAAa,+DAA+D,YAAY,SAAS,gBAAgB,aAAa;AAAA,QAAA;AAAA,MAEpJ;AAAA,IAAA,CACD;AAEG,QAAA,kBAAkB,WAAW,GAAG;AAC5B,YAAA,iBAAiB,qBAAqB,aAAa,WAAW;AACpE,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,UAAM,QAAe;AAAA,MACnB,KAAK,YAAY;AAAA,MACjB,cAAc,YAAY;AAAA,MAC1B,WAAW,YAAY;AAAA;AAAA,MACvB,YAAY;AAAA,QACV,CAAC,YAAY,SAAS,GAAG;AAAA,UACvB,MAAM;AAAA,QACR;AAAA,QACA,GAAG;AAAA,QACH,GAAG,oBAAoB,aAAa,WAAW;AAAA,MACjD;AAAA,IAAA;AAGF,WAAO,KAAK,KAAK;AAAA,EAAA,CAClB;AAEM,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/core",
|
|
3
|
-
"version": "0.0.0-experimental.
|
|
3
|
+
"version": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
4
4
|
"description": "Core of Strapi",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"@koa/cors": "3.4.3",
|
|
56
56
|
"@koa/router": "10.1.1",
|
|
57
57
|
"@paralleldrive/cuid2": "2.2.2",
|
|
58
|
-
"@strapi/admin": "0.0.0-experimental.
|
|
59
|
-
"@strapi/database": "0.0.0-experimental.
|
|
60
|
-
"@strapi/generate-new": "0.0.0-experimental.
|
|
61
|
-
"@strapi/generators": "0.0.0-experimental.
|
|
62
|
-
"@strapi/logger": "0.0.0-experimental.
|
|
63
|
-
"@strapi/pack-up": "0.0.0-experimental.
|
|
64
|
-
"@strapi/permissions": "0.0.0-experimental.
|
|
65
|
-
"@strapi/types": "0.0.0-experimental.
|
|
66
|
-
"@strapi/typescript-utils": "0.0.0-experimental.
|
|
67
|
-
"@strapi/utils": "0.0.0-experimental.
|
|
58
|
+
"@strapi/admin": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
59
|
+
"@strapi/database": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
60
|
+
"@strapi/generate-new": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
61
|
+
"@strapi/generators": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
62
|
+
"@strapi/logger": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
63
|
+
"@strapi/pack-up": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
64
|
+
"@strapi/permissions": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
65
|
+
"@strapi/types": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
66
|
+
"@strapi/typescript-utils": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
67
|
+
"@strapi/utils": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
68
68
|
"bcryptjs": "2.4.3",
|
|
69
69
|
"boxen": "5.1.2",
|
|
70
70
|
"chalk": "4.1.2",
|
|
@@ -122,13 +122,13 @@
|
|
|
122
122
|
"@types/node": "18.19.24",
|
|
123
123
|
"@types/node-schedule": "2.1.0",
|
|
124
124
|
"@types/statuses": "2.0.1",
|
|
125
|
-
"eslint-config-custom": "0.0.0-experimental.
|
|
125
|
+
"eslint-config-custom": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d",
|
|
126
126
|
"supertest": "6.3.3",
|
|
127
|
-
"tsconfig": "0.0.0-experimental.
|
|
127
|
+
"tsconfig": "0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d"
|
|
128
128
|
},
|
|
129
129
|
"engines": {
|
|
130
130
|
"node": ">=18.0.0 <=20.x.x",
|
|
131
131
|
"npm": ">=6.0.0"
|
|
132
132
|
},
|
|
133
|
-
"gitHead": "
|
|
133
|
+
"gitHead": "9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d"
|
|
134
134
|
}
|