@strapi/core 0.0.0-experimental.90ca9123352ed07e0a9cedaf4bcad1475e74137f → 0.0.0-experimental.e3e48deb89bd0a1b6cc69b698696566fa7854a95

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.
Files changed (254) hide show
  1. package/dist/Strapi.d.ts +5 -3
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +19 -7
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +19 -7
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/configuration/index.d.ts.map +1 -1
  8. package/dist/configuration/index.js +4 -4
  9. package/dist/configuration/index.js.map +1 -1
  10. package/dist/configuration/index.mjs +1 -1
  11. package/dist/configuration/index.mjs.map +1 -1
  12. package/dist/configuration/urls.d.ts +8 -0
  13. package/dist/configuration/urls.d.ts.map +1 -0
  14. package/dist/configuration/urls.js +68 -0
  15. package/dist/configuration/urls.js.map +1 -0
  16. package/dist/configuration/urls.mjs +66 -0
  17. package/dist/configuration/urls.mjs.map +1 -0
  18. package/dist/core-api/controller/collection-type.js.map +1 -1
  19. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  20. package/dist/core-api/controller/index.d.ts.map +1 -1
  21. package/dist/core-api/controller/index.js +6 -1
  22. package/dist/core-api/controller/index.js.map +1 -1
  23. package/dist/core-api/controller/index.mjs +6 -1
  24. package/dist/core-api/controller/index.mjs.map +1 -1
  25. package/dist/core-api/controller/single-type.js.map +1 -1
  26. package/dist/core-api/controller/single-type.mjs.map +1 -1
  27. package/dist/core-api/controller/transform.d.ts +8 -7
  28. package/dist/core-api/controller/transform.d.ts.map +1 -1
  29. package/dist/core-api/controller/transform.js +16 -7
  30. package/dist/core-api/controller/transform.js.map +1 -1
  31. package/dist/core-api/controller/transform.mjs +16 -7
  32. package/dist/core-api/controller/transform.mjs.map +1 -1
  33. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  34. package/dist/core-api/service/collection-type.js.map +1 -1
  35. package/dist/core-api/service/collection-type.mjs.map +1 -1
  36. package/dist/core-api/service/single-type.d.ts +3 -2
  37. package/dist/core-api/service/single-type.d.ts.map +1 -1
  38. package/dist/core-api/service/single-type.js +14 -3
  39. package/dist/core-api/service/single-type.js.map +1 -1
  40. package/dist/core-api/service/single-type.mjs +14 -3
  41. package/dist/core-api/service/single-type.mjs.map +1 -1
  42. package/dist/domain/content-type/index.d.ts.map +1 -1
  43. package/dist/domain/content-type/index.js +3 -0
  44. package/dist/domain/content-type/index.js.map +1 -1
  45. package/dist/domain/content-type/index.mjs +3 -0
  46. package/dist/domain/content-type/index.mjs.map +1 -1
  47. package/dist/domain/content-type/validator.d.ts.map +1 -1
  48. package/dist/domain/content-type/validator.js +1 -1
  49. package/dist/domain/content-type/validator.js.map +1 -1
  50. package/dist/domain/content-type/validator.mjs +2 -2
  51. package/dist/domain/content-type/validator.mjs.map +1 -1
  52. package/dist/domain/module/index.d.ts.map +1 -1
  53. package/dist/domain/module/index.js +2 -3
  54. package/dist/domain/module/index.js.map +1 -1
  55. package/dist/domain/module/index.mjs +2 -3
  56. package/dist/domain/module/index.mjs.map +1 -1
  57. package/dist/ee/index.js.map +1 -1
  58. package/dist/ee/index.mjs.map +1 -1
  59. package/dist/loaders/apis.js +1 -1
  60. package/dist/loaders/apis.js.map +1 -1
  61. package/dist/loaders/apis.mjs +2 -2
  62. package/dist/loaders/apis.mjs.map +1 -1
  63. package/dist/loaders/plugins/get-enabled-plugins.js +1 -1
  64. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  65. package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
  66. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  67. package/dist/middlewares/security.d.ts.map +1 -1
  68. package/dist/middlewares/security.js +2 -2
  69. package/dist/middlewares/security.js.map +1 -1
  70. package/dist/middlewares/security.mjs +2 -2
  71. package/dist/middlewares/security.mjs.map +1 -1
  72. package/dist/migrations/draft-publish.d.ts +17 -0
  73. package/dist/migrations/draft-publish.d.ts.map +1 -0
  74. package/dist/migrations/draft-publish.js +59 -0
  75. package/dist/migrations/draft-publish.js.map +1 -0
  76. package/dist/migrations/draft-publish.mjs +59 -0
  77. package/dist/migrations/draft-publish.mjs.map +1 -0
  78. package/dist/registries/config.d.ts +2 -2
  79. package/dist/registries/config.d.ts.map +1 -1
  80. package/dist/registries/config.js +14 -6
  81. package/dist/registries/config.js.map +1 -1
  82. package/dist/registries/config.mjs +15 -5
  83. package/dist/registries/config.mjs.map +1 -1
  84. package/dist/services/document-service/common.d.ts +2 -2
  85. package/dist/services/document-service/common.d.ts.map +1 -1
  86. package/dist/services/document-service/common.js.map +1 -1
  87. package/dist/services/document-service/common.mjs.map +1 -1
  88. package/dist/services/document-service/draft-and-publish.d.ts +9 -23
  89. package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
  90. package/dist/services/document-service/draft-and-publish.js +37 -9
  91. package/dist/services/document-service/draft-and-publish.js.map +1 -1
  92. package/dist/services/document-service/draft-and-publish.mjs +38 -10
  93. package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
  94. package/dist/services/document-service/index.d.ts.map +1 -1
  95. package/dist/services/document-service/index.js +4 -4
  96. package/dist/services/document-service/index.js.map +1 -1
  97. package/dist/services/document-service/index.mjs +2 -2
  98. package/dist/services/document-service/index.mjs.map +1 -1
  99. package/dist/services/document-service/internationalization.d.ts +2 -1
  100. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  101. package/dist/services/document-service/internationalization.js +14 -0
  102. package/dist/services/document-service/internationalization.js.map +1 -1
  103. package/dist/services/document-service/internationalization.mjs +15 -1
  104. package/dist/services/document-service/internationalization.mjs.map +1 -1
  105. package/dist/services/document-service/repository.d.ts +3 -0
  106. package/dist/services/document-service/repository.d.ts.map +1 -0
  107. package/dist/services/document-service/repository.js +295 -0
  108. package/dist/services/document-service/repository.js.map +1 -0
  109. package/dist/services/document-service/repository.mjs +295 -0
  110. package/dist/services/document-service/repository.mjs.map +1 -0
  111. package/dist/services/document-service/transform/fields.d.ts.map +1 -1
  112. package/dist/services/document-service/transform/fields.js +11 -10
  113. package/dist/services/document-service/transform/fields.js.map +1 -1
  114. package/dist/services/document-service/transform/fields.mjs +11 -10
  115. package/dist/services/document-service/transform/fields.mjs.map +1 -1
  116. package/dist/services/document-service/transform/id-map.d.ts +1 -1
  117. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  118. package/dist/services/document-service/transform/id-map.js +15 -9
  119. package/dist/services/document-service/transform/id-map.js.map +1 -1
  120. package/dist/services/document-service/transform/id-map.mjs +16 -10
  121. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  122. package/dist/services/document-service/transform/id-transform.d.ts +4 -25
  123. package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
  124. package/dist/services/document-service/transform/id-transform.js +19 -43
  125. package/dist/services/document-service/transform/id-transform.js.map +1 -1
  126. package/dist/services/document-service/transform/id-transform.mjs +20 -44
  127. package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
  128. package/dist/services/document-service/transform/populate.d.ts +5 -2
  129. package/dist/services/document-service/transform/populate.d.ts.map +1 -1
  130. package/dist/services/document-service/transform/populate.js +0 -10
  131. package/dist/services/document-service/transform/populate.js.map +1 -1
  132. package/dist/services/document-service/transform/populate.mjs +0 -10
  133. package/dist/services/document-service/transform/populate.mjs.map +1 -1
  134. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +1 -1
  135. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  136. package/dist/services/document-service/transform/relations/extract/data-ids.js +28 -14
  137. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  138. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +28 -14
  139. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  140. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +1 -1
  141. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  142. package/dist/services/document-service/transform/relations/transform/data-ids.js +65 -39
  143. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  144. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +66 -40
  145. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  146. package/dist/services/document-service/transform/relations/utils/data.d.ts +2 -4
  147. package/dist/services/document-service/transform/relations/utils/data.d.ts.map +1 -1
  148. package/dist/services/document-service/transform/relations/utils/data.js +1 -1
  149. package/dist/services/document-service/transform/relations/utils/data.js.map +1 -1
  150. package/dist/services/document-service/transform/relations/utils/data.mjs +1 -1
  151. package/dist/services/document-service/transform/relations/utils/data.mjs.map +1 -1
  152. package/dist/services/document-service/transform/relations/utils/dp.d.ts +10 -0
  153. package/dist/services/document-service/transform/relations/utils/dp.d.ts.map +1 -0
  154. package/dist/services/document-service/transform/relations/utils/dp.js +25 -0
  155. package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -0
  156. package/dist/services/document-service/transform/relations/utils/dp.mjs +25 -0
  157. package/dist/services/document-service/transform/relations/utils/dp.mjs.map +1 -0
  158. package/dist/services/document-service/transform/relations/utils/i18n.d.ts +2 -2
  159. package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
  160. package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
  161. package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
  162. package/dist/services/document-service/transform/relations/utils/types.d.ts +9 -2
  163. package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
  164. package/dist/services/document-service/transform/types.d.ts +1 -1
  165. package/dist/services/document-service/transform/types.d.ts.map +1 -1
  166. package/dist/services/document-service/utils/populate.d.ts +8 -1
  167. package/dist/services/document-service/utils/populate.d.ts.map +1 -1
  168. package/dist/services/document-service/utils/populate.js +5 -5
  169. package/dist/services/document-service/utils/populate.js.map +1 -1
  170. package/dist/services/document-service/utils/populate.mjs +5 -5
  171. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  172. package/dist/services/entity-service/components.d.ts +1 -4
  173. package/dist/services/entity-service/components.d.ts.map +1 -1
  174. package/dist/services/entity-service/components.js +13 -99
  175. package/dist/services/entity-service/components.js.map +1 -1
  176. package/dist/services/entity-service/components.mjs +14 -100
  177. package/dist/services/entity-service/components.mjs.map +1 -1
  178. package/dist/services/entity-service/index.d.ts +1 -3
  179. package/dist/services/entity-service/index.d.ts.map +1 -1
  180. package/dist/services/entity-service/index.js +34 -199
  181. package/dist/services/entity-service/index.js.map +1 -1
  182. package/dist/services/entity-service/index.mjs +27 -192
  183. package/dist/services/entity-service/index.mjs.map +1 -1
  184. package/dist/services/entity-service/params.d.ts +4 -4
  185. package/dist/services/entity-service/params.d.ts.map +1 -1
  186. package/dist/services/entity-service/params.js +1 -1
  187. package/dist/services/entity-service/params.js.map +1 -1
  188. package/dist/services/entity-service/params.mjs +1 -1
  189. package/dist/services/entity-service/params.mjs.map +1 -1
  190. package/dist/services/entity-validator/index.js +1 -1
  191. package/dist/services/entity-validator/index.js.map +1 -1
  192. package/dist/services/entity-validator/index.mjs +1 -1
  193. package/dist/services/entity-validator/index.mjs.map +1 -1
  194. package/dist/utils/is-initialized.js +1 -1
  195. package/dist/utils/is-initialized.js.map +1 -1
  196. package/dist/utils/is-initialized.mjs +1 -1
  197. package/dist/utils/is-initialized.mjs.map +1 -1
  198. package/dist/utils/load-config-file.js +1 -1
  199. package/dist/utils/load-config-file.js.map +1 -1
  200. package/dist/utils/load-config-file.mjs +2 -2
  201. package/dist/utils/load-config-file.mjs.map +1 -1
  202. package/dist/utils/transform-content-types-to-models.d.ts +174 -3
  203. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  204. package/dist/utils/transform-content-types-to-models.js +80 -41
  205. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  206. package/dist/utils/transform-content-types-to-models.mjs +79 -41
  207. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  208. package/package.json +14 -14
  209. package/dist/services/document-service/collection-type.d.ts +0 -4
  210. package/dist/services/document-service/collection-type.d.ts.map +0 -1
  211. package/dist/services/document-service/collection-type.js +0 -145
  212. package/dist/services/document-service/collection-type.js.map +0 -1
  213. package/dist/services/document-service/collection-type.mjs +0 -145
  214. package/dist/services/document-service/collection-type.mjs.map +0 -1
  215. package/dist/services/document-service/document-engine.d.ts +0 -8
  216. package/dist/services/document-service/document-engine.d.ts.map +0 -1
  217. package/dist/services/document-service/document-engine.js +0 -249
  218. package/dist/services/document-service/document-engine.js.map +0 -1
  219. package/dist/services/document-service/document-engine.mjs +0 -250
  220. package/dist/services/document-service/document-engine.mjs.map +0 -1
  221. package/dist/services/document-service/repository-factory.d.ts +0 -3
  222. package/dist/services/document-service/repository-factory.d.ts.map +0 -1
  223. package/dist/services/document-service/repository-factory.js +0 -12
  224. package/dist/services/document-service/repository-factory.js.map +0 -1
  225. package/dist/services/document-service/repository-factory.mjs +0 -12
  226. package/dist/services/document-service/repository-factory.mjs.map +0 -1
  227. package/dist/services/document-service/single-type.d.ts +0 -4
  228. package/dist/services/document-service/single-type.d.ts.map +0 -1
  229. package/dist/services/document-service/single-type.js +0 -92
  230. package/dist/services/document-service/single-type.js.map +0 -1
  231. package/dist/services/document-service/single-type.mjs +0 -92
  232. package/dist/services/document-service/single-type.mjs.map +0 -1
  233. package/dist/services/document-service/transform/filters.js +0 -49
  234. package/dist/services/document-service/transform/filters.js.map +0 -1
  235. package/dist/services/document-service/transform/filters.mjs +0 -49
  236. package/dist/services/document-service/transform/filters.mjs.map +0 -1
  237. package/dist/services/document-service/transform/relations/transform/output-ids.js +0 -26
  238. package/dist/services/document-service/transform/relations/transform/output-ids.js.map +0 -1
  239. package/dist/services/document-service/transform/relations/transform/output-ids.mjs +0 -26
  240. package/dist/services/document-service/transform/relations/transform/output-ids.mjs.map +0 -1
  241. package/dist/services/document-service/transform/sort.js +0 -44
  242. package/dist/services/document-service/transform/sort.js.map +0 -1
  243. package/dist/services/document-service/transform/sort.mjs +0 -44
  244. package/dist/services/document-service/transform/sort.mjs.map +0 -1
  245. package/dist/services/document-service/transform/utils.js +0 -23
  246. package/dist/services/document-service/transform/utils.js.map +0 -1
  247. package/dist/services/document-service/transform/utils.mjs +0 -23
  248. package/dist/services/document-service/transform/utils.mjs.map +0 -1
  249. package/dist/services/utils/upload-files.d.ts +0 -8
  250. package/dist/services/utils/upload-files.d.ts.map +0 -1
  251. package/dist/services/utils/upload-files.js +0 -64
  252. package/dist/services/utils/upload-files.js.map +0 -1
  253. package/dist/services/utils/upload-files.mjs +0 -63
  254. package/dist/services/utils/upload-files.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/services/entity-validator/index.ts"],"sourcesContent":["/**\n * Entity validator\n * Module that will validate input data for entity creation or edition\n */\n\nimport { uniqBy, castArray, isNil, isArray, mergeWith } from 'lodash';\nimport { has, prop, isObject, isEmpty } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport { EntityValidator, Common, Schema, Attribute, Shared, EntityService } from '@strapi/types';\nimport validators from './validators';\n\ntype CreateOrUpdate = 'creation' | 'update';\n\nconst { yup, validateYupSchema } = strapiUtils;\nconst { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUtils.contentTypes;\nconst { ValidationError } = strapiUtils.errors;\n\ntype Entity = {\n id: ID;\n [key: string]: unknown;\n} | null;\n\ntype ID = { id: string | number };\n\ntype RelationSource = string | number | ID;\n\ninterface ValidatorMeta<TAttribute = Attribute.Any> {\n attr: TAttribute;\n updatedAttribute: { name: string; value: any };\n}\n\ninterface ValidatorContext {\n isDraft?: boolean;\n locale?: string | null;\n}\n\ninterface AttributeValidatorMetas {\n attr: Attribute.Any;\n updatedAttribute: { name: string; value: unknown };\n model: Schema.ContentType | Schema.Component;\n entity?: Entity;\n}\n\ninterface ModelValidatorMetas {\n model: Schema.ContentType | Schema.Component;\n data: Record<string, unknown>;\n entity?: Entity;\n}\n\nconst isInteger = (value: unknown): value is number => Number.isInteger(value);\n\nconst addMinMax = <\n T extends {\n min(value: number): T;\n max(value: number): T;\n }\n>(\n validator: T,\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Any & Attribute.MinMaxOption<string | number>>\n): T => {\n let nextValidator: T = validator;\n\n if (\n isInteger(attr.min) &&\n (('required' in attr && attr.required) ||\n (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0))\n ) {\n nextValidator = nextValidator.min(attr.min);\n }\n if (isInteger(attr.max)) {\n nextValidator = nextValidator.max(attr.max);\n }\n return nextValidator;\n};\n\nconst addRequiredValidation = (createOrUpdate: CreateOrUpdate) => {\n return <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr: { required } }: ValidatorMeta<Partial<Attribute.Any & Attribute.RequiredOption>>\n ): T => {\n let nextValidator = validator;\n\n if (required) {\n if (createOrUpdate === 'creation') {\n nextValidator = nextValidator.notNil();\n } else if (createOrUpdate === 'update') {\n nextValidator = nextValidator.notNull();\n }\n } else {\n nextValidator = nextValidator.nullable();\n }\n return nextValidator;\n };\n};\n\nconst addDefault = (createOrUpdate: CreateOrUpdate) => {\n return (\n validator: strapiUtils.yup.BaseSchema,\n { attr }: ValidatorMeta<Attribute.Any & Attribute.DefaultOption<unknown>>\n ) => {\n let nextValidator = validator;\n\n if (createOrUpdate === 'creation') {\n if (\n ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&\n !attr.required\n ) {\n nextValidator = nextValidator.default([]);\n } else {\n nextValidator = nextValidator.default(attr.default);\n }\n } else {\n nextValidator = nextValidator.default(undefined);\n }\n\n return nextValidator;\n };\n};\n\nconst preventCast = (validator: strapiUtils.yup.AnySchema) =>\n validator.transform((val, originalVal) => originalVal);\n\nconst createComponentValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Component<Common.UID.Component, boolean>>,\n { isDraft }: ValidatorContext\n ) => {\n const model = strapi.getModel(attr.component);\n if (!model) {\n throw new Error('Validation failed: Model not found');\n }\n\n if (attr?.repeatable) {\n // FIXME: yup v1\n\n let validator = yup\n .array()\n .of(\n yup.lazy((item) =>\n createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }).notNull()\n ) as any\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n validator = addMinMax(validator, { attr, updatedAttribute });\n\n return validator;\n }\n\n // FIXME: v4 was broken\n let validator = createModelValidator(createOrUpdate)(\n { model, data: updatedAttribute.value },\n { isDraft }\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createDzValidator =\n (createOrUpdate: CreateOrUpdate) =>\n ({ attr, updatedAttribute }: ValidatorMeta, { isDraft }: ValidatorContext) => {\n let validator;\n\n validator = yup.array().of(\n yup.lazy((item) => {\n const model = strapi.getModel(prop('__component', item));\n const schema = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(strapi.components)),\n })\n .notNull();\n\n return model\n ? schema.concat(createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }))\n : schema;\n }) as any // FIXME: yup v1\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n validator = addMinMax(validator, { attr, updatedAttribute });\n\n return validator;\n };\n\nconst createRelationValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Relation>,\n { isDraft }: ValidatorContext\n ) => {\n let validator;\n\n if (Array.isArray(updatedAttribute.value)) {\n validator = yup.array().of(yup.mixed());\n } else {\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createScalarAttributeValidator =\n (createOrUpdate: CreateOrUpdate) => (metas: ValidatorMeta, options: ValidatorContext) => {\n let validator;\n\n if (has(metas.attr.type, validators)) {\n validator = (validators as any)[metas.attr.type](metas, options);\n } else {\n // No validators specified - fall back to mixed\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !options.isDraft && metas.attr.required },\n updatedAttribute: metas.updatedAttribute,\n });\n\n return validator;\n };\n\nconst createAttributeValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (metas: AttributeValidatorMetas, options: ValidatorContext) => {\n let validator = yup.mixed();\n\n if (isMediaAttribute(metas.attr)) {\n validator = yup.mixed();\n } else if (isScalarAttribute(metas.attr)) {\n validator = createScalarAttributeValidator(createOrUpdate)(metas, options);\n } else {\n if (metas.attr.type === 'component') {\n validator = createComponentValidator(createOrUpdate)(\n { attr: metas.attr, updatedAttribute: metas.updatedAttribute },\n options\n );\n } else if (metas.attr.type === 'dynamiczone') {\n validator = createDzValidator(createOrUpdate)(metas, options);\n } else if (metas.attr.type === 'relation') {\n validator = createRelationValidator(createOrUpdate)(\n {\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n }\n\n validator = preventCast(validator);\n }\n\n validator = addDefault(createOrUpdate)(validator, metas);\n\n return validator;\n };\n\nconst createModelValidator =\n (createOrUpdate: CreateOrUpdate) =>\n ({ model, data, entity }: ModelValidatorMetas, options: ValidatorContext) => {\n const writableAttributes = model ? getWritableAttributes(model as any) : [];\n\n const schema = writableAttributes.reduce((validators, attributeName) => {\n const metas = {\n attr: model.attributes[attributeName],\n updatedAttribute: { name: attributeName, value: prop(attributeName, data) },\n model,\n entity,\n };\n\n const validator = createAttributeValidator(createOrUpdate)(metas, options);\n\n validators[attributeName] = validator;\n\n return validators;\n }, {} as Record<string, strapiUtils.yup.BaseSchema>);\n\n return yup.object().shape(schema);\n };\n\nconst createValidateEntity = (createOrUpdate: CreateOrUpdate) => {\n return async <\n TUID extends Common.UID.ContentType,\n TData extends EntityService.Params.Data.Input<TUID>\n >(\n model: Shared.ContentTypes[TUID],\n data: TData | Partial<TData> | undefined,\n options?: ValidatorContext,\n entity?: Entity\n ): Promise<TData> => {\n if (!isObject(data)) {\n const { displayName } = model.info;\n\n throw new ValidationError(\n `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`\n );\n }\n\n const validator = createModelValidator(createOrUpdate)(\n { model, data, entity },\n {\n isDraft: options?.isDraft ?? false,\n locale: options?.locale ?? null,\n }\n )\n .test('relations-test', 'check that all relations exist', async function (data) {\n try {\n await checkRelationsExist(buildRelationsStore({ uid: model.uid, data }));\n } catch (e) {\n return this.createError({\n path: this.path,\n message: (e instanceof ValidationError && e.message) || 'Invalid relations',\n });\n }\n return true;\n })\n .required();\n\n return validateYupSchema(validator, {\n strict: false,\n abortEarly: false,\n })(data);\n };\n};\n\n/**\n * Builds an object containing all the media and relations being associated with an entity\n */\nconst buildRelationsStore = <TUID extends Common.UID.ContentType | Common.UID.Component>({\n uid,\n data,\n}: {\n uid: TUID;\n data: Record<string, unknown> | null;\n}): Record<string, ID[]> => {\n if (!uid) {\n throw new ValidationError(`Cannot build relations store: \"uid\" is undefined`);\n }\n\n if (isEmpty(data)) {\n return {};\n }\n\n const currentModel = strapi.getModel(uid);\n\n return Object.keys(currentModel.attributes).reduce((result, attributeName: string) => {\n const attribute = currentModel.attributes[attributeName];\n const value = data[attributeName];\n\n if (isNil(value)) {\n return result;\n }\n\n switch (attribute.type) {\n case 'relation':\n case 'media': {\n if (\n attribute.type === 'relation' &&\n (attribute.relation === 'morphToMany' || attribute.relation === 'morphToOne')\n ) {\n // TODO: handle polymorphic relations\n break;\n }\n\n const target =\n // eslint-disable-next-line no-nested-ternary\n attribute.type === 'media' ? 'plugin::upload.file' : attribute.target;\n // As there are multiple formats supported for associating relations\n // with an entity, the value here can be an: array, object or number.\n let source: RelationSource[];\n if (Array.isArray(value)) {\n source = value;\n } else if (isObject(value)) {\n if ('connect' in value && !isNil(value.connect)) {\n source = value.connect as RelationSource[];\n } else if ('set' in value && !isNil(value.set)) {\n source = value.set as RelationSource[];\n } else {\n source = [];\n }\n } else {\n source = castArray(value as RelationSource);\n }\n const idArray = source.map((v) => ({\n id: typeof v === 'object' ? v.id : v,\n }));\n\n // Update the relationStore to keep track of all associations being made\n // with relations and media.\n result[target] = result[target] || [];\n result[target].push(...idArray);\n break;\n }\n case 'component': {\n return castArray(value).reduce((relationsStore, componentValue) => {\n if (!attribute.component) {\n throw new ValidationError(\n `Cannot build relations store from component, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: attribute.component,\n data: componentValue as Record<string, unknown>,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n case 'dynamiczone': {\n return castArray(value).reduce((relationsStore, dzValue) => {\n const value = dzValue as Record<string, unknown>;\n if (!value.__component) {\n throw new ValidationError(\n `Cannot build relations store from dynamiczone, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: value.__component as Common.UID.Component,\n data: value,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n default:\n break;\n }\n\n return result;\n }, {} as Record<string, ID[]>);\n};\n\n/**\n * Iterate through the relations store and validates that every relation or media\n * mentioned exists\n */\nconst checkRelationsExist = async (relationsStore: Record<string, ID[]> = {}) => {\n const promises = [];\n\n for (const [key, value] of Object.entries(relationsStore)) {\n const evaluate = async () => {\n const uniqueValues = uniqBy(value, `id`);\n const count = await strapi.query(key as Common.UID.Schema).count({\n where: {\n id: {\n $in: uniqueValues.map((v) => v.id),\n },\n },\n });\n\n if (count !== uniqueValues.length) {\n throw new ValidationError(\n `${\n uniqueValues.length - count\n } relation(s) of type ${key} associated with this entity do not exist`\n );\n }\n };\n promises.push(evaluate());\n }\n\n return Promise.all(promises);\n};\n\nconst entityValidator: EntityValidator = {\n validateEntityCreation: createValidateEntity('creation'),\n validateEntityUpdate: createValidateEntity('update'),\n};\n\nexport default entityValidator;\n"],"names":["validator","validators","data","value"],"mappings":";;;;AAaA,MAAM,EAAE,KAAK,kBAAsB,IAAA;AACnC,MAAM,EAAE,kBAAkB,mBAAmB,sBAAA,IAA0B,YAAY;AACnF,MAAM,EAAE,gBAAgB,IAAI,YAAY;AAkCxC,MAAM,YAAY,CAAC,UAAoC,OAAO,UAAU,KAAK;AAE7E,MAAM,YAAY,CAMhB,WACA,EAAE,MAAM,uBACF;AACN,MAAI,gBAAmB;AAEvB,MACE,UAAU,KAAK,GAAG,MAChB,cAAc,QAAQ,KAAK,YAC1B,MAAM,QAAQ,iBAAiB,KAAK,KAAK,iBAAiB,MAAM,SAAS,IAC5E;AACgB,oBAAA,cAAc,IAAI,KAAK,GAAG;AAAA,EAC5C;AACI,MAAA,UAAU,KAAK,GAAG,GAAG;AACP,oBAAA,cAAc,IAAI,KAAK,GAAG;AAAA,EAC5C;AACO,SAAA;AACT;AAEA,MAAM,wBAAwB,CAAC,mBAAmC;AAChE,SAAO,CACL,WACA,EAAE,MAAM,EAAE,iBACJ;AACN,QAAI,gBAAgB;AAEpB,QAAI,UAAU;AACZ,UAAI,mBAAmB,YAAY;AACjC,wBAAgB,cAAc;MAAO,WAC5B,mBAAmB,UAAU;AACtC,wBAAgB,cAAc;MAChC;AAAA,IAAA,OACK;AACL,sBAAgB,cAAc;IAChC;AACO,WAAA;AAAA,EAAA;AAEX;AAEA,MAAM,aAAa,CAAC,mBAAmC;AACrD,SAAO,CACL,WACA,EAAE,WACC;AACH,QAAI,gBAAgB;AAEpB,QAAI,mBAAmB,YAAY;AAE7B,WAAA,KAAK,SAAS,eAAe,KAAK,cAAe,KAAK,SAAS,kBACjE,CAAC,KAAK,UACN;AACgB,wBAAA,cAAc,QAAQ,CAAA,CAAE;AAAA,MAAA,OACnC;AACW,wBAAA,cAAc,QAAQ,KAAK,OAAO;AAAA,MACpD;AAAA,IAAA,OACK;AACW,sBAAA,cA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Module that will validate input data for entity creation or edition\n */\n\nimport { uniqBy, castArray, isNil, isArray, mergeWith } from 'lodash';\nimport { has, prop, isObject, isEmpty } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport { EntityValidator, Common, Schema, Attribute, Shared, EntityService } from '@strapi/types';\nimport validators from './validators';\n\ntype CreateOrUpdate = 'creation' | 'update';\n\nconst { yup, validateYupSchema } = strapiUtils;\nconst { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUtils.contentTypes;\nconst { ValidationError } = strapiUtils.errors;\n\ntype Entity = {\n id: ID;\n [key: string]: unknown;\n} | null;\n\ntype ID = { id: string | number };\n\ntype RelationSource = string | number | ID;\n\ninterface ValidatorMeta<TAttribute = Attribute.Any> {\n attr: TAttribute;\n updatedAttribute: { name: string; value: any };\n}\n\ninterface ValidatorContext {\n isDraft?: boolean;\n locale?: string | null;\n}\n\ninterface AttributeValidatorMetas {\n attr: Attribute.Any;\n updatedAttribute: { name: string; value: unknown };\n model: Schema.ContentType | Schema.Component;\n entity?: Entity;\n}\n\ninterface ModelValidatorMetas {\n model: Schema.ContentType | Schema.Component;\n data: Record<string, unknown>;\n entity?: Entity;\n}\n\nconst isInteger = (value: unknown): value is number => Number.isInteger(value);\n\nconst addMinMax = <\n T extends {\n min(value: number): T;\n max(value: number): T;\n }\n>(\n validator: T,\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Any & Attribute.MinMaxOption<string | number>>\n): T => {\n let nextValidator: T = validator;\n\n if (\n isInteger(attr.min) &&\n (('required' in attr && attr.required) ||\n (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0))\n ) {\n nextValidator = nextValidator.min(attr.min);\n }\n if (isInteger(attr.max)) {\n nextValidator = nextValidator.max(attr.max);\n }\n return nextValidator;\n};\n\nconst addRequiredValidation = (createOrUpdate: CreateOrUpdate) => {\n return <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr: { required } }: ValidatorMeta<Partial<Attribute.Any & Attribute.RequiredOption>>\n ): T => {\n let nextValidator = validator;\n\n if (required) {\n if (createOrUpdate === 'creation') {\n nextValidator = nextValidator.notNil();\n } else if (createOrUpdate === 'update') {\n nextValidator = nextValidator.notNull();\n }\n } else {\n nextValidator = nextValidator.nullable();\n }\n return nextValidator;\n };\n};\n\nconst addDefault = (createOrUpdate: CreateOrUpdate) => {\n return (\n validator: strapiUtils.yup.BaseSchema,\n { attr }: ValidatorMeta<Attribute.Any & Attribute.DefaultOption<unknown>>\n ) => {\n let nextValidator = validator;\n\n if (createOrUpdate === 'creation') {\n if (\n ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&\n !attr.required\n ) {\n nextValidator = nextValidator.default([]);\n } else {\n nextValidator = nextValidator.default(attr.default);\n }\n } else {\n nextValidator = nextValidator.default(undefined);\n }\n\n return nextValidator;\n };\n};\n\nconst preventCast = (validator: strapiUtils.yup.AnySchema) =>\n validator.transform((val, originalVal) => originalVal);\n\nconst createComponentValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Component<Common.UID.Component, boolean>>,\n { isDraft }: ValidatorContext\n ) => {\n const model = strapi.getModel(attr.component);\n if (!model) {\n throw new Error('Validation failed: Model not found');\n }\n\n if (attr?.repeatable) {\n // FIXME: yup v1\n\n let validator = yup\n .array()\n .of(\n yup.lazy((item) =>\n createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }).notNull()\n ) as any\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n validator = addMinMax(validator, { attr, updatedAttribute });\n\n return validator;\n }\n\n // FIXME: v4 was broken\n let validator = createModelValidator(createOrUpdate)(\n { model, data: updatedAttribute.value },\n { isDraft }\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createDzValidator =\n (createOrUpdate: CreateOrUpdate) =>\n ({ attr, updatedAttribute }: ValidatorMeta, { isDraft }: ValidatorContext) => {\n let validator;\n\n validator = yup.array().of(\n yup.lazy((item) => {\n const model = strapi.getModel(prop('__component', item));\n const schema = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(strapi.components)),\n })\n .notNull();\n\n return model\n ? schema.concat(createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }))\n : schema;\n }) as any // FIXME: yup v1\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n validator = addMinMax(validator, { attr, updatedAttribute });\n\n return validator;\n };\n\nconst createRelationValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Attribute.Relation>,\n { isDraft }: ValidatorContext\n ) => {\n let validator;\n\n if (Array.isArray(updatedAttribute.value)) {\n validator = yup.array().of(yup.mixed());\n } else {\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createScalarAttributeValidator =\n (createOrUpdate: CreateOrUpdate) => (metas: ValidatorMeta, options: ValidatorContext) => {\n let validator;\n\n if (has(metas.attr.type, validators)) {\n validator = (validators as any)[metas.attr.type](metas, options);\n } else {\n // No validators specified - fall back to mixed\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !options.isDraft && metas.attr.required },\n updatedAttribute: metas.updatedAttribute,\n });\n\n return validator;\n };\n\nconst createAttributeValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (metas: AttributeValidatorMetas, options: ValidatorContext) => {\n let validator = yup.mixed();\n\n if (isMediaAttribute(metas.attr)) {\n validator = yup.mixed();\n } else if (isScalarAttribute(metas.attr)) {\n validator = createScalarAttributeValidator(createOrUpdate)(metas, options);\n } else {\n if (metas.attr.type === 'component') {\n validator = createComponentValidator(createOrUpdate)(\n { attr: metas.attr, updatedAttribute: metas.updatedAttribute },\n options\n );\n } else if (metas.attr.type === 'dynamiczone') {\n validator = createDzValidator(createOrUpdate)(metas, options);\n } else if (metas.attr.type === 'relation') {\n validator = createRelationValidator(createOrUpdate)(\n {\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n }\n\n validator = preventCast(validator);\n }\n\n validator = addDefault(createOrUpdate)(validator, metas);\n\n return validator;\n };\n\nconst createModelValidator =\n (createOrUpdate: CreateOrUpdate) =>\n ({ model, data, entity }: ModelValidatorMetas, options: ValidatorContext) => {\n const writableAttributes = model ? getWritableAttributes(model as any) : [];\n\n const schema = writableAttributes.reduce((validators, attributeName) => {\n const metas = {\n attr: model.attributes[attributeName],\n updatedAttribute: { name: attributeName, value: prop(attributeName, data) },\n model,\n entity,\n };\n\n const validator = createAttributeValidator(createOrUpdate)(metas, options);\n\n validators[attributeName] = validator;\n\n return validators;\n }, {} as Record<string, strapiUtils.yup.BaseSchema>);\n\n return yup.object().shape(schema);\n };\n\nconst createValidateEntity = (createOrUpdate: CreateOrUpdate) => {\n return async <\n TUID extends Common.UID.ContentType,\n TData extends EntityService.Params.Data.Input<TUID>\n >(\n model: Shared.ContentTypes[TUID],\n data: TData | Partial<TData> | undefined,\n options?: ValidatorContext,\n entity?: Entity\n ): Promise<TData> => {\n if (!isObject(data)) {\n const { displayName } = model.info;\n\n throw new ValidationError(\n `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`\n );\n }\n\n const validator = createModelValidator(createOrUpdate)(\n { model, data, entity },\n {\n isDraft: options?.isDraft ?? false,\n locale: options?.locale ?? null,\n }\n )\n .test('relations-test', 'check that all relations exist', async function (data) {\n try {\n await checkRelationsExist(buildRelationsStore({ uid: model.uid, data }));\n } catch (e) {\n return this.createError({\n path: this.path,\n message: (e instanceof ValidationError && e.message) || 'Invalid relations',\n });\n }\n return true;\n })\n .required();\n\n return validateYupSchema(validator, {\n strict: false,\n abortEarly: false,\n })(data);\n };\n};\n\n/**\n * Builds an object containing all the media and relations being associated with an entity\n */\nconst buildRelationsStore = <TUID extends Common.UID.ContentType | Common.UID.Component>({\n uid,\n data,\n}: {\n uid: TUID;\n data: Record<string, unknown> | null;\n}): Record<string, ID[]> => {\n if (!uid) {\n throw new ValidationError(`Cannot build relations store: \"uid\" is undefined`);\n }\n\n if (isEmpty(data)) {\n return {};\n }\n\n const currentModel = strapi.getModel(uid);\n\n return Object.keys(currentModel.attributes).reduce((result, attributeName: string) => {\n const attribute = currentModel.attributes[attributeName];\n const value = data[attributeName];\n\n if (isNil(value)) {\n return result;\n }\n\n switch (attribute.type) {\n case 'relation':\n case 'media': {\n if (\n attribute.type === 'relation' &&\n (attribute.relation === 'morphToMany' || attribute.relation === 'morphToOne')\n ) {\n // TODO: handle polymorphic relations\n break;\n }\n\n const target =\n // eslint-disable-next-line no-nested-ternary\n attribute.type === 'media' ? 'plugin::upload.file' : attribute.target;\n // As there are multiple formats supported for associating relations\n // with an entity, the value here can be an: array, object or number.\n let source: RelationSource[];\n if (Array.isArray(value)) {\n source = value;\n } else if (isObject(value)) {\n if ('connect' in value && !isNil(value.connect)) {\n source = value.connect as RelationSource[];\n } else if ('set' in value && !isNil(value.set)) {\n source = value.set as RelationSource[];\n } else {\n source = [];\n }\n } else {\n source = castArray(value as RelationSource);\n }\n const idArray = source.map((v) => ({\n id: typeof v === 'object' ? v.id : v,\n }));\n\n // Update the relationStore to keep track of all associations being made\n // with relations and media.\n result[target] = result[target] || [];\n result[target].push(...idArray);\n break;\n }\n case 'component': {\n return castArray(value).reduce((relationsStore, componentValue) => {\n if (!attribute.component) {\n throw new ValidationError(\n `Cannot build relations store from component, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: attribute.component,\n data: componentValue as Record<string, unknown>,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n case 'dynamiczone': {\n return castArray(value).reduce((relationsStore, dzValue) => {\n const value = dzValue as Record<string, unknown>;\n if (!value.__component) {\n throw new ValidationError(\n `Cannot build relations store from dynamiczone, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: value.__component as Common.UID.Component,\n data: value,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n default:\n break;\n }\n\n return result;\n }, {} as Record<string, ID[]>);\n};\n\n/**\n * Iterate through the relations store and validates that every relation or media\n * mentioned exists\n */\nconst checkRelationsExist = async (relationsStore: Record<string, ID[]> = {}) => {\n const promises = [];\n\n for (const [key, value] of Object.entries(relationsStore)) {\n const evaluate = async () => {\n const uniqueValues = uniqBy(value, `id`);\n const count = await strapi.db.query(key as Common.UID.Schema).count({\n where: {\n id: {\n $in: uniqueValues.map((v) => v.id),\n },\n },\n });\n\n if (count !== uniqueValues.length) {\n throw new ValidationError(\n `${\n uniqueValues.length - count\n } relation(s) of type ${key} associated with this entity do not exist`\n );\n }\n };\n promises.push(evaluate());\n }\n\n return Promise.all(promises);\n};\n\nconst entityValidator: EntityValidator = {\n validateEntityCreation: createValidateEntity('creation'),\n validateEntityUpdate: createValidateEntity('update'),\n};\n\nexport default entityValidator;\n"],"names":["validator","validators","data","value"],"mappings":";;;;AAaA,MAAM,EAAE,KAAK,kBAAsB,IAAA;AACnC,MAAM,EAAE,kBAAkB,mBAAmB,sBAAA,IAA0B,YAAY;AACnF,MAAM,EAAE,gBAAgB,IAAI,YAAY;AAkCxC,MAAM,YAAY,CAAC,UAAoC,OAAO,UAAU,KAAK;AAE7E,MAAM,YAAY,CAMhB,WACA,EAAE,MAAM,uBACF;AACN,MAAI,gBAAmB;AAEvB,MACE,UAAU,KAAK,GAAG,MAChB,cAAc,QAAQ,KAAK,YAC1B,MAAM,QAAQ,iBAAiB,KAAK,KAAK,iBAAiB,MAAM,SAAS,IAC5E;AAC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/B;AAMA,MAAM,sBAAsB,OAAO,iBAAuC,OAAO;AAC/E,QAAM,WAAW,CAAA;AAEjB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,cAAc,GAAG;AACzD,UAAM,WAAW,YAAY;AACrB,YAAA,eAAe,OAAO,OAAO,IAAI;AACvC,YAAM,QAAQ,MAAM,OAAO,GAAG,MAAM,GAAwB,EAAE,MAAM;AAAA,QAClE,OAAO;AAAA,UACL,IAAI;AAAA,YACF,KAAK,aAAa,IAAI,CAAC,MAAM,EAAE,EAAE;AAAA,UACnC;AAAA,QACF;AAAA,MAAA,CACD;AAEG,UAAA,UAAU,aAAa,QAAQ;AACjC,cAAM,IAAI;AAAA,UACR,GACE,aAAa,SAAS,KACxB,wBAAwB,GAAG;AAAA,QAAA;AAAA,MAE/B;AAAA,IAAA;AAEO,aAAA,KAAK,UAAU;AAAA,EAC1B;AAEO,SAAA,QAAQ,IAAI,QAAQ;AAC7B;AAEA,MAAM,kBAAmC;AAAA,EACvC,wBAAwB,qBAAqB,UAAU;AAAA,EACvD,sBAAsB,qBAAqB,QAAQ;AACrD;"}
@@ -6,7 +6,7 @@ const isInitialized = async (strapi) => {
6
6
  if (_.isEmpty(strapi.admin)) {
7
7
  return true;
8
8
  }
9
- const anyAdministrator = await strapi.query("admin::user").findOne({ select: ["id"] });
9
+ const anyAdministrator = await strapi.db.query("admin::user").findOne({ select: ["id"] });
10
10
  return !_.isNil(anyAdministrator);
11
11
  } catch (err) {
12
12
  strapi.stopWithError(err);
@@ -1 +1 @@
1
- {"version":3,"file":"is-initialized.js","sources":["../../src/utils/is-initialized.ts"],"sourcesContent":["import { isEmpty, isNil } from 'lodash/fp';\n\nimport type { Strapi } from '@strapi/types';\n\n/**\n * Test if the strapi application is considered as initialized (1st user has been created)\n */\nexport const isInitialized = async (strapi: Strapi): Promise<boolean> => {\n try {\n if (isEmpty(strapi.admin)) {\n return true;\n }\n\n // test if there is at least one admin\n const anyAdministrator = await strapi.query('admin::user').findOne({ select: ['id'] });\n\n return !isNil(anyAdministrator);\n } catch (err) {\n strapi.stopWithError(err);\n }\n};\n"],"names":["isEmpty","isNil"],"mappings":";;;AAOa,MAAA,gBAAgB,OAAO,WAAqC;AACnE,MAAA;AACE,QAAAA,EAAA,QAAQ,OAAO,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAGA,UAAM,mBAAmB,MAAM,OAAO,MAAM,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAG,CAAA;AAE9E,WAAA,CAACC,EAAAA,MAAM,gBAAgB;AAAA,WACvB,KAAK;AACZ,WAAO,cAAc,GAAG;AAAA,EAC1B;AACF;;"}
1
+ {"version":3,"file":"is-initialized.js","sources":["../../src/utils/is-initialized.ts"],"sourcesContent":["import { isEmpty, isNil } from 'lodash/fp';\n\nimport type { Strapi } from '@strapi/types';\n\n/**\n * Test if the strapi application is considered as initialized (1st user has been created)\n */\nexport const isInitialized = async (strapi: Strapi): Promise<boolean> => {\n try {\n if (isEmpty(strapi.admin)) {\n return true;\n }\n\n // test if there is at least one admin\n const anyAdministrator = await strapi.db.query('admin::user').findOne({ select: ['id'] });\n\n return !isNil(anyAdministrator);\n } catch (err) {\n strapi.stopWithError(err);\n }\n};\n"],"names":["isEmpty","isNil"],"mappings":";;;AAOa,MAAA,gBAAgB,OAAO,WAAqC;AACnE,MAAA;AACE,QAAAA,EAAA,QAAQ,OAAO,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAGA,UAAM,mBAAmB,MAAM,OAAO,GAAG,MAAM,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAG,CAAA;AAEjF,WAAA,CAACC,EAAAA,MAAM,gBAAgB;AAAA,WACvB,KAAK;AACZ,WAAO,cAAc,GAAG;AAAA,EAC1B;AACF;;"}
@@ -4,7 +4,7 @@ const isInitialized = async (strapi) => {
4
4
  if (isEmpty(strapi.admin)) {
5
5
  return true;
6
6
  }
7
- const anyAdministrator = await strapi.query("admin::user").findOne({ select: ["id"] });
7
+ const anyAdministrator = await strapi.db.query("admin::user").findOne({ select: ["id"] });
8
8
  return !isNil(anyAdministrator);
9
9
  } catch (err) {
10
10
  strapi.stopWithError(err);
@@ -1 +1 @@
1
- {"version":3,"file":"is-initialized.mjs","sources":["../../src/utils/is-initialized.ts"],"sourcesContent":["import { isEmpty, isNil } from 'lodash/fp';\n\nimport type { Strapi } from '@strapi/types';\n\n/**\n * Test if the strapi application is considered as initialized (1st user has been created)\n */\nexport const isInitialized = async (strapi: Strapi): Promise<boolean> => {\n try {\n if (isEmpty(strapi.admin)) {\n return true;\n }\n\n // test if there is at least one admin\n const anyAdministrator = await strapi.query('admin::user').findOne({ select: ['id'] });\n\n return !isNil(anyAdministrator);\n } catch (err) {\n strapi.stopWithError(err);\n }\n};\n"],"names":[],"mappings":";AAOa,MAAA,gBAAgB,OAAO,WAAqC;AACnE,MAAA;AACE,QAAA,QAAQ,OAAO,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAGA,UAAM,mBAAmB,MAAM,OAAO,MAAM,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAG,CAAA;AAE9E,WAAA,CAAC,MAAM,gBAAgB;AAAA,WACvB,KAAK;AACZ,WAAO,cAAc,GAAG;AAAA,EAC1B;AACF;"}
1
+ {"version":3,"file":"is-initialized.mjs","sources":["../../src/utils/is-initialized.ts"],"sourcesContent":["import { isEmpty, isNil } from 'lodash/fp';\n\nimport type { Strapi } from '@strapi/types';\n\n/**\n * Test if the strapi application is considered as initialized (1st user has been created)\n */\nexport const isInitialized = async (strapi: Strapi): Promise<boolean> => {\n try {\n if (isEmpty(strapi.admin)) {\n return true;\n }\n\n // test if there is at least one admin\n const anyAdministrator = await strapi.db.query('admin::user').findOne({ select: ['id'] });\n\n return !isNil(anyAdministrator);\n } catch (err) {\n strapi.stopWithError(err);\n }\n};\n"],"names":[],"mappings":";AAOa,MAAA,gBAAgB,OAAO,WAAqC;AACnE,MAAA;AACE,QAAA,QAAQ,OAAO,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAGA,UAAM,mBAAmB,MAAM,OAAO,GAAG,MAAM,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAG,CAAA;AAEjF,WAAA,CAAC,MAAM,gBAAgB;AAAA,WACvB,KAAK;AACZ,WAAO,cAAc,GAAG;AAAA,EAC1B;AACF;"}
@@ -22,7 +22,7 @@ const loadJsFile = (file) => {
22
22
  };
23
23
  const loadJSONFile = (file) => {
24
24
  try {
25
- return strapiUtils.templateConfiguration(JSON.parse(fs__default.default.readFileSync(file).toString()));
25
+ return JSON.parse(fs__default.default.readFileSync(file).toString());
26
26
  } catch (error) {
27
27
  if (error instanceof Error) {
28
28
  throw new Error(`Could not load json config file ${file}: ${error.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"load-config-file.js","sources":["../../src/utils/load-config-file.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\nimport { templateConfiguration, env, importDefault } from '@strapi/utils';\n\nconst loadJsFile = (file: string) => {\n try {\n const jsModule = importDefault(file);\n\n // call if function\n if (typeof jsModule === 'function') {\n return jsModule({ env });\n }\n\n return jsModule;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load js config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nconst loadJSONFile = (file: string) => {\n try {\n return templateConfiguration(JSON.parse(fs.readFileSync(file).toString()));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load json config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nexport const loadConfigFile = (file: string) => {\n const ext = path.extname(file);\n\n switch (ext) {\n case '.js':\n return loadJsFile(file);\n case '.json':\n return loadJSONFile(file);\n default:\n return {};\n }\n};\n"],"names":["importDefault","env","templateConfiguration","fs","path"],"mappings":";;;;;;;;AAIA,MAAM,aAAa,CAAC,SAAiB;AAC/B,MAAA;AACI,UAAA,WAAWA,0BAAc,IAAI;AAG/B,QAAA,OAAO,aAAa,YAAY;AAC3B,aAAA,SAAS,OAAEC,YAAA,IAAA,CAAK;AAAA,IACzB;AAEO,WAAA;AAAA,WACA,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC3E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEA,MAAM,eAAe,CAAC,SAAiB;AACjC,MAAA;AACK,WAAAC,YAAA,sBAAsB,KAAK,MAAMC,YAAA,QAAG,aAAa,IAAI,EAAE,SAAU,CAAA,CAAC;AAAA,WAClE,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,mCAAmC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC7E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEa,MAAA,iBAAiB,CAAC,SAAiB;AACxC,QAAA,MAAMC,cAAAA,QAAK,QAAQ,IAAI;AAE7B,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,WAAW,IAAI;AAAA,IACxB,KAAK;AACH,aAAO,aAAa,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
1
+ {"version":3,"file":"load-config-file.js","sources":["../../src/utils/load-config-file.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\nimport { env, importDefault } from '@strapi/utils';\n\nconst loadJsFile = (file: string) => {\n try {\n const jsModule = importDefault(file);\n\n // call if function\n if (typeof jsModule === 'function') {\n return jsModule({ env });\n }\n\n return jsModule;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load js config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nconst loadJSONFile = (file: string) => {\n try {\n return JSON.parse(fs.readFileSync(file).toString());\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load json config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nexport const loadConfigFile = (file: string) => {\n const ext = path.extname(file);\n\n switch (ext) {\n case '.js':\n return loadJsFile(file);\n case '.json':\n return loadJSONFile(file);\n default:\n return {};\n }\n};\n"],"names":["importDefault","env","fs","path"],"mappings":";;;;;;;;AAIA,MAAM,aAAa,CAAC,SAAiB;AAC/B,MAAA;AACI,UAAA,WAAWA,0BAAc,IAAI;AAG/B,QAAA,OAAO,aAAa,YAAY;AAC3B,aAAA,SAAS,OAAEC,YAAA,IAAA,CAAK;AAAA,IACzB;AAEO,WAAA;AAAA,WACA,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC3E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEA,MAAM,eAAe,CAAC,SAAiB;AACjC,MAAA;AACF,WAAO,KAAK,MAAMC,YAAA,QAAG,aAAa,IAAI,EAAE,UAAU;AAAA,WAC3C,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,mCAAmC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC7E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEa,MAAA,iBAAiB,CAAC,SAAiB;AACxC,QAAA,MAAMC,cAAAA,QAAK,QAAQ,IAAI;AAE7B,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,WAAW,IAAI;AAAA,IACxB,KAAK;AACH,aAAO,aAAa,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
- import { importDefault, env, templateConfiguration } from "@strapi/utils";
3
+ import { importDefault, env } from "@strapi/utils";
4
4
  const loadJsFile = (file) => {
5
5
  try {
6
6
  const jsModule = importDefault(file);
@@ -17,7 +17,7 @@ const loadJsFile = (file) => {
17
17
  };
18
18
  const loadJSONFile = (file) => {
19
19
  try {
20
- return templateConfiguration(JSON.parse(fs.readFileSync(file).toString()));
20
+ return JSON.parse(fs.readFileSync(file).toString());
21
21
  } catch (error) {
22
22
  if (error instanceof Error) {
23
23
  throw new Error(`Could not load json config file ${file}: ${error.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"load-config-file.mjs","sources":["../../src/utils/load-config-file.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\nimport { templateConfiguration, env, importDefault } from '@strapi/utils';\n\nconst loadJsFile = (file: string) => {\n try {\n const jsModule = importDefault(file);\n\n // call if function\n if (typeof jsModule === 'function') {\n return jsModule({ env });\n }\n\n return jsModule;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load js config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nconst loadJSONFile = (file: string) => {\n try {\n return templateConfiguration(JSON.parse(fs.readFileSync(file).toString()));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load json config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nexport const loadConfigFile = (file: string) => {\n const ext = path.extname(file);\n\n switch (ext) {\n case '.js':\n return loadJsFile(file);\n case '.json':\n return loadJSONFile(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,aAAa,CAAC,SAAiB;AAC/B,MAAA;AACI,UAAA,WAAW,cAAc,IAAI;AAG/B,QAAA,OAAO,aAAa,YAAY;AAC3B,aAAA,SAAS,EAAE,IAAA,CAAK;AAAA,IACzB;AAEO,WAAA;AAAA,WACA,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC3E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEA,MAAM,eAAe,CAAC,SAAiB;AACjC,MAAA;AACK,WAAA,sBAAsB,KAAK,MAAM,GAAG,aAAa,IAAI,EAAE,SAAU,CAAA,CAAC;AAAA,WAClE,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,mCAAmC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC7E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEa,MAAA,iBAAiB,CAAC,SAAiB;AACxC,QAAA,MAAM,KAAK,QAAQ,IAAI;AAE7B,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,WAAW,IAAI;AAAA,IACxB,KAAK;AACH,aAAO,aAAa,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
1
+ {"version":3,"file":"load-config-file.mjs","sources":["../../src/utils/load-config-file.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\nimport { env, importDefault } from '@strapi/utils';\n\nconst loadJsFile = (file: string) => {\n try {\n const jsModule = importDefault(file);\n\n // call if function\n if (typeof jsModule === 'function') {\n return jsModule({ env });\n }\n\n return jsModule;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load js config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nconst loadJSONFile = (file: string) => {\n try {\n return JSON.parse(fs.readFileSync(file).toString());\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Could not load json config file ${file}: ${error.message}`);\n }\n\n throw new Error('Unknown error');\n }\n};\n\nexport const loadConfigFile = (file: string) => {\n const ext = path.extname(file);\n\n switch (ext) {\n case '.js':\n return loadJsFile(file);\n case '.json':\n return loadJSONFile(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,aAAa,CAAC,SAAiB;AAC/B,MAAA;AACI,UAAA,WAAW,cAAc,IAAI;AAG/B,QAAA,OAAO,aAAa,YAAY;AAC3B,aAAA,SAAS,EAAE,IAAA,CAAK;AAAA,IACzB;AAEO,WAAA;AAAA,WACA,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC3E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEA,MAAM,eAAe,CAAC,SAAiB;AACjC,MAAA;AACF,WAAO,KAAK,MAAM,GAAG,aAAa,IAAI,EAAE,UAAU;AAAA,WAC3C,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,YAAM,IAAI,MAAM,mCAAmC,IAAI,KAAK,MAAM,OAAO,EAAE;AAAA,IAC7E;AAEM,UAAA,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;AAEa,MAAA,iBAAiB,CAAC,SAAiB;AACxC,QAAA,MAAM,KAAK,QAAQ,IAAI;AAE7B,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,WAAW,IAAI;AAAA,IACxB,KAAK;AACH,aAAO,aAAa,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
@@ -1,6 +1,177 @@
1
- import { Model } from '@strapi/database';
2
- import { Schema } from '@strapi/types';
1
+ import { type Model } from '@strapi/database';
2
+ import { Schema, Attribute } from '@strapi/types';
3
3
  import { createId } from '@paralleldrive/cuid2';
4
+ /**
5
+ * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them
6
+ * to a relations format that it recognizes
7
+ *
8
+ * Therefore we have to keep an additional set of helpers/extensions to the database naming methods
9
+ */
10
+ export declare const COMPONENT_JOIN_TABLE_SUFFIX = "components";
11
+ export declare const DZ_JOIN_TABLE_SUFFIX = "components";
12
+ export declare const COMPONENT_INVERSE_COLUMN_NAME = "component";
13
+ export declare const COMPONENT_TYPE_COLUMN = "component_type";
14
+ export declare const ENTITY = "entity";
15
+ export declare const getComponentJoinTableName: (collectionName: string) => string;
16
+ export declare const getDzJoinTableName: (collectionName: string) => string;
17
+ export type LoadedContentTypeModel = Schema.ContentType & Required<Pick<Schema.ContentType, 'collectionName' | 'uid' | 'modelName'>>;
18
+ export declare const transformAttribute: (name: string, attribute: Attribute.Any, contentType: LoadedContentTypeModel) => Attribute.BigInteger | (Attribute.OfType<"boolean"> & Attribute.ConfigurableOption & Attribute.DefaultOption<boolean> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption) | Attribute.Blocks | Attribute.DateTime | Attribute.Date | Attribute.Decimal | Attribute.Email | Attribute.Enumeration<string[]> | Attribute.Float | Attribute.Integer | Attribute.JSON | Attribute.Password | (Attribute.OfType<"relation"> & {
19
+ relation: "morphToOne";
20
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
21
+ relation: "morphToMany";
22
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
23
+ relation: "oneToOne";
24
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
25
+ } & import("@strapi/types/dist/types/utils").Without<{
26
+ inversedBy?: string | undefined;
27
+ }, {
28
+ mappedBy?: string | undefined;
29
+ }> & {
30
+ mappedBy?: string | undefined;
31
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
32
+ relation: "oneToOne";
33
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
34
+ } & import("@strapi/types/dist/types/utils").Without<{
35
+ mappedBy?: string | undefined;
36
+ }, {
37
+ inversedBy?: string | undefined;
38
+ }> & {
39
+ inversedBy?: string | undefined;
40
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
41
+ relation: "oneToMany";
42
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
43
+ } & import("@strapi/types/dist/types/utils").Without<{
44
+ inversedBy?: string | undefined;
45
+ }, {
46
+ mappedBy?: string | undefined;
47
+ }> & {
48
+ mappedBy?: string | undefined;
49
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
50
+ relation: "oneToMany";
51
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
52
+ } & import("@strapi/types/dist/types/utils").Without<{
53
+ mappedBy?: string | undefined;
54
+ }, {
55
+ inversedBy?: string | undefined;
56
+ }> & {
57
+ inversedBy?: string | undefined;
58
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
59
+ relation: "manyToOne";
60
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
61
+ } & import("@strapi/types/dist/types/utils").Without<{
62
+ inversedBy?: string | undefined;
63
+ }, {
64
+ mappedBy?: string | undefined;
65
+ }> & {
66
+ mappedBy?: string | undefined;
67
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
68
+ relation: "manyToOne";
69
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
70
+ } & import("@strapi/types/dist/types/utils").Without<{
71
+ mappedBy?: string | undefined;
72
+ }, {
73
+ inversedBy?: string | undefined;
74
+ }> & {
75
+ inversedBy?: string | undefined;
76
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
77
+ relation: "manyToMany";
78
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
79
+ } & import("@strapi/types/dist/types/utils").Without<{
80
+ inversedBy?: string | undefined;
81
+ }, {
82
+ mappedBy?: string | undefined;
83
+ }> & {
84
+ mappedBy?: string | undefined;
85
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
86
+ relation: "manyToMany";
87
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
88
+ } & import("@strapi/types/dist/types/utils").Without<{
89
+ mappedBy?: string | undefined;
90
+ }, {
91
+ inversedBy?: string | undefined;
92
+ }> & {
93
+ inversedBy?: string | undefined;
94
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
95
+ relation: "oneWay";
96
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
97
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
98
+ relation: "manyWay";
99
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
100
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
101
+ relation: "morphOne";
102
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
103
+ morphBy?: string | undefined;
104
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
105
+ relation: "morphMany";
106
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
107
+ morphBy?: string | undefined;
108
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | Attribute.RichText | (Attribute.OfType<"string"> & Attribute.StringProperties & Attribute.ConfigurableOption & Attribute.DefaultOption<string> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.UniqueOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption) | Attribute.Text | Attribute.Time | Attribute.Timestamp | Attribute.UID<string, Attribute.UIDOptions> | {
109
+ type: string;
110
+ relation: string;
111
+ target: string;
112
+ morphBy: string;
113
+ joinTable?: undefined;
114
+ } | {
115
+ type: string;
116
+ relation: string;
117
+ target: `${string}.${string}`;
118
+ joinTable: {
119
+ name: string;
120
+ joinColumn: {
121
+ name: string;
122
+ referencedColumn: string;
123
+ };
124
+ inverseJoinColumn: {
125
+ name: string;
126
+ referencedColumn: string;
127
+ };
128
+ on: {
129
+ field: string;
130
+ };
131
+ orderColumnName: string;
132
+ orderBy: {
133
+ order: string;
134
+ };
135
+ pivotColumns: string[];
136
+ morphColumn?: undefined;
137
+ };
138
+ morphBy?: undefined;
139
+ } | {
140
+ type: string;
141
+ relation: string;
142
+ joinTable: {
143
+ name: string;
144
+ joinColumn: {
145
+ name: string;
146
+ referencedColumn: string;
147
+ };
148
+ morphColumn: {
149
+ idColumn: {
150
+ name: string;
151
+ referencedColumn: string;
152
+ };
153
+ typeColumn: {
154
+ name: string;
155
+ };
156
+ typeField: string;
157
+ };
158
+ on: {
159
+ field: string;
160
+ };
161
+ orderBy: {
162
+ order: string;
163
+ };
164
+ pivotColumns: string[];
165
+ inverseJoinColumn?: undefined;
166
+ orderColumnName?: undefined;
167
+ };
168
+ target?: undefined;
169
+ morphBy?: undefined;
170
+ };
171
+ export declare const transformAttributes: (contentType: LoadedContentTypeModel) => {};
172
+ export declare const hasComponentsOrDz: (contentType: LoadedContentTypeModel) => contentType is Schema.ContentType & Required<Pick<Schema.ContentType, "uid" | "collectionName" | "modelName">> & {
173
+ type: 'dynamiczone' | 'component';
174
+ };
4
175
  export declare const createDocumentId: typeof createId;
5
- export declare const transformContentTypesToModels: (contentTypes: Schema.ContentType[]) => Model[];
176
+ export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[]) => Model[];
6
177
  //# sourceMappingURL=transform-content-types-to-models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAmGhD,eAAO,MAAM,gBAAgB,iBAAW,CAAC;AAuEzC,eAAO,MAAM,6BAA6B,iBAAkB,OAAO,WAAW,EAAE,KAAG,KAAK,EA8CvF,CAAC"}
1
+ {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD;;;;;GAKG;AAEH,eAAO,MAAM,2BAA2B,eAAe,CAAC;AACxD,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD,eAAO,MAAM,6BAA6B,cAAc,CAAC;AACzD,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,eAAO,MAAM,yBAAyB,mBAAoB,MAAM,WACmB,CAAC;AAEpF,eAAO,MAAM,kBAAkB,mBAAoB,MAAM,WACmB,CAAC;AAI7E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,WAAW,GACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC;AAG7E,eAAO,MAAM,kBAAkB,SACvB,MAAM,aACD,UAAU,GAAG,eACX,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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