@webiny/api-headless-cms 6.4.12-beta.4 → 6.5.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/crud/contentEntry/entryDataValidation.d.ts +1 -1
  2. package/crud/contentEntry/entryDataValidation.js +33 -18
  3. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  4. package/crud/contentEntry.crud.js +12 -39
  5. package/crud/contentEntry.crud.js.map +1 -1
  6. package/crud/contentModel/defaultFields.js +3 -2
  7. package/crud/contentModel/defaultFields.js.map +1 -1
  8. package/crud/contentModel/validate/endingAllowed.js +1 -1
  9. package/crud/contentModel/validate/endingAllowed.js.map +1 -1
  10. package/crud/contentModel/validate/pluralApiName.js +1 -1
  11. package/crud/contentModel/validate/pluralApiName.js.map +1 -1
  12. package/crud/contentModel/validate/singularApiName.js +1 -1
  13. package/crud/contentModel/validate/singularApiName.js.map +1 -1
  14. package/crud/contentModel/validation.js +2 -2
  15. package/crud/contentModel/validation.js.map +1 -1
  16. package/domain/contentModel/schemas.d.ts +4 -0
  17. package/domain/contentModel/schemas.js +5 -2
  18. package/domain/contentModel/schemas.js.map +1 -1
  19. package/domain/contentModel/validation/endingAllowed.js +1 -1
  20. package/domain/contentModel/validation/endingAllowed.js.map +1 -1
  21. package/domain/contentModel/validation/pluralApiName.js +1 -1
  22. package/domain/contentModel/validation/pluralApiName.js.map +1 -1
  23. package/domain/contentModel/validation/singularApiName.js +1 -1
  24. package/domain/contentModel/validation/singularApiName.js.map +1 -1
  25. package/export/crud/exporting.js +2 -2
  26. package/export/crud/exporting.js.map +1 -1
  27. package/export/crud/imports/importGroups.js +2 -1
  28. package/export/crud/imports/importGroups.js.map +1 -1
  29. package/export/crud/imports/validateModels.js +1 -1
  30. package/export/crud/imports/validateModels.js.map +1 -1
  31. package/exports/api/cms/model.d.ts +4 -1
  32. package/exports/api/cms/model.js +2 -0
  33. package/extension.d.ts +3 -0
  34. package/extension.js +19 -0
  35. package/extension.js.map +1 -0
  36. package/features/contentEntry/ContentEntriesFeature.js +2 -0
  37. package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
  38. package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +1 -2
  39. package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
  40. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
  41. package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +1 -0
  42. package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
  43. package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js +1 -3
  44. package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js.map +1 -1
  45. package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
  46. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.d.ts +14 -0
  47. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js +34 -0
  48. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js.map +1 -0
  49. package/features/contentEntry/UpdateRevision/abstractions.d.ts +10 -0
  50. package/features/contentEntry/UpdateRevision/abstractions.js +5 -0
  51. package/features/contentEntry/UpdateRevision/abstractions.js.map +1 -0
  52. package/features/contentEntry/UpdateRevision/feature.d.ts +4 -0
  53. package/features/contentEntry/UpdateRevision/feature.js +11 -0
  54. package/features/contentEntry/UpdateRevision/feature.js.map +1 -0
  55. package/features/contentEntry/UpdateRevision/index.d.ts +1 -0
  56. package/features/contentEntry/UpdateRevision/index.js +1 -0
  57. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts +2 -2
  58. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js +2 -2
  59. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map +1 -1
  60. package/features/contentEntry/ensureItemIds.d.ts +13 -0
  61. package/features/contentEntry/ensureItemIds.js +22 -0
  62. package/features/contentEntry/ensureItemIds.js.map +1 -0
  63. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts +3 -1
  64. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js +9 -3
  65. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
  66. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +3 -3
  67. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +10 -6
  68. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
  69. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +3 -1
  70. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +9 -3
  71. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
  72. package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
  73. package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
  74. package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.d.ts +14 -0
  75. package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js +32 -0
  76. package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js.map +1 -0
  77. package/features/contentModel/ComponentMapGenerator/abstractions.d.ts +8 -0
  78. package/features/contentModel/ComponentMapGenerator/abstractions.js +5 -0
  79. package/features/contentModel/ComponentMapGenerator/abstractions.js.map +1 -0
  80. package/features/contentModel/ComponentMapGenerator/feature.d.ts +4 -0
  81. package/features/contentModel/ComponentMapGenerator/feature.js +11 -0
  82. package/features/contentModel/ComponentMapGenerator/feature.js.map +1 -0
  83. package/features/contentModel/ComponentMapGenerator/index.d.ts +2 -0
  84. package/features/contentModel/ComponentMapGenerator/index.js +2 -0
  85. package/features/contentModel/ContentModelFeature.js +6 -0
  86. package/features/contentModel/ContentModelFeature.js.map +1 -1
  87. package/features/contentModel/CreateModel/CreateModelRepository.js +2 -1
  88. package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
  89. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +2 -1
  90. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
  91. package/features/contentModel/RefModelsGenerator/RefModelsGenerator.d.ts +19 -0
  92. package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js +56 -0
  93. package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js.map +1 -0
  94. package/features/contentModel/RefModelsGenerator/abstractions.d.ts +11 -0
  95. package/features/contentModel/RefModelsGenerator/abstractions.js +5 -0
  96. package/features/contentModel/RefModelsGenerator/abstractions.js.map +1 -0
  97. package/features/contentModel/RefModelsGenerator/feature.d.ts +4 -0
  98. package/features/contentModel/RefModelsGenerator/feature.js +11 -0
  99. package/features/contentModel/RefModelsGenerator/feature.js.map +1 -0
  100. package/features/contentModel/RefModelsGenerator/index.d.ts +2 -0
  101. package/features/contentModel/RefModelsGenerator/index.js +2 -0
  102. package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.d.ts +16 -0
  103. package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +54 -0
  104. package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -0
  105. package/features/contentModel/ValuesSelectionGenerator/abstractions.d.ts +8 -0
  106. package/features/contentModel/ValuesSelectionGenerator/abstractions.js +5 -0
  107. package/features/contentModel/ValuesSelectionGenerator/abstractions.js.map +1 -0
  108. package/features/contentModel/ValuesSelectionGenerator/feature.d.ts +4 -0
  109. package/features/contentModel/ValuesSelectionGenerator/feature.js +11 -0
  110. package/features/contentModel/ValuesSelectionGenerator/feature.js.map +1 -0
  111. package/features/contentModel/ValuesSelectionGenerator/index.d.ts +1 -0
  112. package/features/contentModel/ValuesSelectionGenerator/index.js +1 -0
  113. package/features/graphql/feature.js +2 -0
  114. package/features/graphql/feature.js.map +1 -1
  115. package/features/graphql/fields/base/AssetToGraphQL.d.ts +26 -0
  116. package/features/graphql/fields/base/AssetToGraphQL.js +148 -0
  117. package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -0
  118. package/features/graphql/fields/base/DynamicZoneToGraphQL.js +12 -2
  119. package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
  120. package/features/graphql/fields/base/ObjectToGraphQL.js +8 -5
  121. package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
  122. package/features/modelBuilder/abstractions.d.ts +9 -0
  123. package/features/modelBuilder/abstractions.js.map +1 -1
  124. package/features/modelBuilder/feature.js +2 -0
  125. package/features/modelBuilder/feature.js.map +1 -1
  126. package/features/modelBuilder/fields/AssetFieldType.d.ts +20 -0
  127. package/features/modelBuilder/fields/AssetFieldType.js +46 -0
  128. package/features/modelBuilder/fields/AssetFieldType.js.map +1 -0
  129. package/features/modelBuilder/fields/DataFieldBuilder.d.ts +62 -18
  130. package/features/modelBuilder/fields/DataFieldBuilder.js +8 -0
  131. package/features/modelBuilder/fields/DataFieldBuilder.js.map +1 -1
  132. package/features/modelBuilder/fields/DynamicZoneFieldType.d.ts +1 -0
  133. package/features/modelBuilder/fields/DynamicZoneFieldType.js +2 -6
  134. package/features/modelBuilder/fields/DynamicZoneFieldType.js.map +1 -1
  135. package/features/modelBuilder/fields/resolveAssetUrl.d.ts +35 -0
  136. package/features/modelBuilder/fields/resolveAssetUrl.js +26 -0
  137. package/features/modelBuilder/fields/resolveAssetUrl.js.map +1 -0
  138. package/features/modelBuilder/index.d.ts +1 -1
  139. package/features/modelBuilder/models/BaseModelBuilder.d.ts +3 -1
  140. package/features/modelBuilder/models/BaseModelBuilder.js +7 -0
  141. package/features/modelBuilder/models/BaseModelBuilder.js.map +1 -1
  142. package/features/modelBuilder/models/PrivateModelBuilder.js +2 -1
  143. package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
  144. package/features/modelBuilder/models/PublicModelBuilder.js +2 -1
  145. package/features/modelBuilder/models/PublicModelBuilder.js.map +1 -1
  146. package/features/sortMapper/SortMapper.js +2 -5
  147. package/features/sortMapper/SortMapper.js.map +1 -1
  148. package/features/storage/fields/CompressedTextStorageTransform.js +1 -1
  149. package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
  150. package/features/storage/fields/DateStorageTransform.js +4 -3
  151. package/features/storage/fields/DateStorageTransform.js.map +1 -1
  152. package/features/storage/fields/DynamicZoneStorageTransform.js +2 -2
  153. package/features/storage/fields/DynamicZoneStorageTransform.js.map +1 -1
  154. package/features/storage/fields/JsonStorageTransform.js +1 -1
  155. package/features/storage/fields/JsonStorageTransform.js.map +1 -1
  156. package/features/storage/fields/LongTextStorageTransform.js +1 -1
  157. package/features/storage/fields/LongTextStorageTransform.js.map +1 -1
  158. package/features/storage/fields/ObjectStorageTransform.js +27 -7
  159. package/features/storage/fields/ObjectStorageTransform.js.map +1 -1
  160. package/features/storage/fields/RichTextStorageTransform.js +1 -1
  161. package/features/storage/fields/RichTextStorageTransform.js.map +1 -1
  162. package/features/validation/validators/DateGteValidator.js +1 -1
  163. package/features/validation/validators/DateGteValidator.js.map +1 -1
  164. package/features/validation/validators/DateLteValidator.js +1 -1
  165. package/features/validation/validators/DateLteValidator.js.map +1 -1
  166. package/features/validation/validators/PatternValidator.js +1 -1
  167. package/features/validation/validators/PatternValidator.js.map +1 -1
  168. package/features/whereMapper/WhereMapper.js +10 -7
  169. package/features/whereMapper/WhereMapper.js.map +1 -1
  170. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +8 -2
  171. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  172. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
  173. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  174. package/fieldConverters/index.d.ts +1 -1
  175. package/graphql/getSchema/generateCacheKey.js +1 -1
  176. package/graphql/getSchema/generateCacheKey.js.map +1 -1
  177. package/graphql/scalars/RevisionId.js +1 -1
  178. package/graphql/scalars/RevisionId.js.map +1 -1
  179. package/graphql/schema/baseSchema.js +5 -25
  180. package/graphql/schema/baseSchema.js.map +1 -1
  181. package/graphql/schema/cms/getEntryResolver.js +3 -2
  182. package/graphql/schema/cms/getEntryResolver.js.map +1 -1
  183. package/graphql/schema/cms/getModelResolver.d.ts +35 -0
  184. package/graphql/schema/cms/getModelResolver.js +49 -0
  185. package/graphql/schema/cms/getModelResolver.js.map +1 -0
  186. package/graphql/schema/cms/helpers/buildFieldsSelection.js +9 -2
  187. package/graphql/schema/cms/helpers/buildFieldsSelection.js.map +1 -1
  188. package/graphql/schema/cms/helpers/expandFieldWildcards.d.ts +2 -0
  189. package/graphql/schema/cms/helpers/expandFieldWildcards.js +13 -0
  190. package/graphql/schema/cms/helpers/expandFieldWildcards.js.map +1 -0
  191. package/graphql/schema/cms/helpers/index.d.ts +1 -0
  192. package/graphql/schema/cms/helpers/index.js +1 -0
  193. package/graphql/schema/cms/helpers.d.ts +1 -0
  194. package/graphql/schema/cms/helpers.js +1 -0
  195. package/graphql/schema/cms/index.js +2 -1
  196. package/graphql/schema/cms/index.js.map +1 -1
  197. package/graphql/schema/cms/listEntriesResolver.js +3 -2
  198. package/graphql/schema/cms/listEntriesResolver.js.map +1 -1
  199. package/graphql/schema/cms/resolvers/getModel.d.ts +8 -0
  200. package/graphql/schema/cms/resolvers/getModel.js +18 -0
  201. package/graphql/schema/cms/resolvers/getModel.js.map +1 -0
  202. package/graphql/schema/cms/resolvers/index.d.ts +1 -0
  203. package/graphql/schema/cms/resolvers/index.js +1 -0
  204. package/graphql/schema/cms/typeDefs/query.js +1 -0
  205. package/graphql/schema/cms/typeDefs/query.js.map +1 -1
  206. package/graphql/schema/cms/typeDefs/responses.js +5 -0
  207. package/graphql/schema/cms/typeDefs/responses.js.map +1 -1
  208. package/graphql/schema/contentModels.js +40 -1
  209. package/graphql/schema/contentModels.js.map +1 -1
  210. package/graphql/schema/createFieldResolvers.js +1 -1
  211. package/graphql/schema/createFieldResolvers.js.map +1 -1
  212. package/index.d.ts +2 -5
  213. package/index.js +1 -21
  214. package/package.json +26 -29
  215. package/plugins/CmsModelPlugin.js +12 -10
  216. package/plugins/CmsModelPlugin.js.map +1 -1
  217. package/types/fields/dynamicZoneField.d.ts +1 -0
  218. package/types/model.d.ts +6 -0
  219. package/types/modelField.d.ts +13 -0
  220. package/types/types.d.ts +8 -4
  221. package/types/types.js.map +1 -1
  222. package/utils/caching/Cache.js +1 -1
  223. package/utils/caching/Cache.js.map +1 -1
  224. package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.d.ts +28 -0
  225. package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js +324 -0
  226. package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js.map +1 -0
  227. package/utils/contentModelToJsonSchema/index.d.ts +2 -0
  228. package/utils/contentModelToJsonSchema/index.js +1 -0
  229. package/utils/contentModelToJsonSchema/types.d.ts +24 -0
  230. package/utils/contentModelToJsonSchema/types.js +0 -0
  231. package/utils/createModelField.js +2 -1
  232. package/utils/createModelField.js.map +1 -1
  233. package/utils/date.js +1 -1
  234. package/utils/date.js.map +1 -1
  235. package/utils/entryStorage.js +1 -1
  236. package/utils/entryStorage.js.map +1 -1
  237. package/utils/index.d.ts +1 -0
  238. package/utils/index.js +1 -0
  239. package/utils/renderFields.js +1 -1
  240. package/utils/renderFields.js.map +1 -1
  241. package/index.js.map +0 -1
@@ -1,7 +1,6 @@
1
1
  import { createImplementation } from "@webiny/feature/api";
2
2
  import { CreateEntryRevisionFromDataFactory } from "./abstractions.js";
3
3
  import { AccessControl, CmsContext } from "../../../shared/abstractions.js";
4
- import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
5
4
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
6
5
  import { getDate } from "../../../../utils/date.js";
7
6
  import { getIdentity } from "../../../../utils/identity.js";
@@ -13,6 +12,8 @@ import error from "@webiny/error";
13
12
  import { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from "../statuses.js";
14
13
  import { NotAuthorizedError } from "../../../../utils/errors.js";
15
14
  import { getSystem } from "../system.js";
15
+ import { ModelToAstConverter } from "../../../contentModel/ModelToAstConverter/abstractions.js";
16
+ import { ensureItemIds } from "../../ensureItemIds.js";
16
17
  const increaseEntryIdVersion = (id)=>{
17
18
  const { id: entryId, version } = parseIdentifier(id);
18
19
  if (!version) throw new error("Cannot increase version on the ID without the version part.", "WRONG_ID", {
@@ -28,23 +29,25 @@ const increaseEntryIdVersion = (id)=>{
28
29
  };
29
30
  };
30
31
  class CreateEntryRevisionFromDataFactoryImpl {
31
- constructor(cmsContext, identityContext, tenantContext, accessControl){
32
+ constructor(cmsContext, identityContext, accessControl, modelToAstConverter){
32
33
  this.cmsContext = cmsContext;
33
34
  this.identityContext = identityContext;
34
- this.tenantContext = tenantContext;
35
35
  this.accessControl = accessControl;
36
+ this.modelToAstConverter = modelToAstConverter;
36
37
  }
37
38
  async create(sourceId, model, rawInput, originalEntry, latestStorageEntry, options) {
38
39
  const initialValues = {
39
40
  ...originalEntry.values,
40
41
  ...mapAndCleanUpdatedInputData(model, rawInput.values)
41
42
  };
43
+ const modelAst = this.modelToAstConverter.toAst(model);
44
+ await ensureItemIds(modelAst, initialValues);
42
45
  await validateModelEntryDataOrThrow({
43
46
  context: this.cmsContext,
44
47
  model,
45
48
  values: initialValues,
46
49
  entry: originalEntry,
47
- skipValidators: options?.skipValidators
50
+ skipValidation: options?.skipValidation
48
51
  });
49
52
  const values = await referenceFieldsMapping({
50
53
  context: this.cmsContext,
@@ -116,6 +119,7 @@ class CreateEntryRevisionFromDataFactoryImpl {
116
119
  revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity),
117
120
  revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity),
118
121
  revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),
122
+ revisionDescription: void 0,
119
123
  ...revisionLevelPublishingMetaFields,
120
124
  locked,
121
125
  status,
@@ -142,8 +146,8 @@ const CreateEntryRevisionFromDataFactory_CreateEntryRevisionFromDataFactory = cr
142
146
  dependencies: [
143
147
  CmsContext,
144
148
  IdentityContext,
145
- TenantContext,
146
- AccessControl
149
+ AccessControl,
150
+ ModelToAstConverter
147
151
  ]
148
152
  });
149
153
  export { CreateEntryRevisionFromDataFactory_CreateEntryRevisionFromDataFactory as CreateEntryRevisionFromDataFactory };
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory,\n type ICreateEntryRevisionFromDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n latestStorageEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryRevisionFromDataResponse<TValues>> {\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","AccessControl"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAEA,MAAMI;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CACzD;aAJmBH,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,OACTC,QAAgB,EAChBC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,kBAAqC,EACrCC,OAAoC,EACkB;QACtD,MAAMC,gBAAgB;YAClB,GAAGH,cAAc,MAAM;YACvB,GAAGI,4BAAqCN,OAAOC,SAAS,MAAM,CAAC;QACnE;QAEA,MAAMM,8BAA8B;YAChC,SAAS,IAAI,CAAC,UAAU;YACxBP;YACA,QAAQK;YACR,OAAOH;YACP,gBAAgBE,SAAS;QAC7B;QAEA,MAAMI,SAAS,MAAMC,uBAAgC;YACjD,SAAS,IAAI,CAAC,UAAU;YACxBT;YACA,QAAQK;YACR,iBAA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AMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACHyB;YACA,OAAO;gBACH,GAAG1B,QAAQ;gBACX,QAAQ4B,gBAAgBrB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMsB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBtC;IAChB,cAAc;QAACuC;QAAYC;QAAiBC;QAAeC;KAAc;AAC7E"}
1
+ {"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory,\n type ICreateEntryRevisionFromDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly accessControl: AccessControl.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n latestStorageEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryRevisionFromDataResponse<TValues>> {\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, initialValues);\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionDescription: undefined,\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, AccessControl, ModelToAstConverter]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","accessControl","modelToAstConverter","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","modelAst","ensureItemIds","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","undefined","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","AccessControl","ModelToAstConverter"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAEA,MAAMI;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,aAAsC,EACtCC,mBAAkD,CACrE;aAJmBH,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;IAClB;IAEH,MAAa,OACTC,QAAgB,EAChBC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,kBAAqC,EACrCC,OAAoC,EACkB;QACtD,MAAMC,gBAAgB;YAClB,GAAGH,cAAc,MAAM;YACvB,GAAGI,4BAAqCN,OAAOC,SAAS,MAAM,CAAC;QACnE;QAEA,MAAMM,WAAW,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAACP;QAChD,MAAMQ,cAAcD,UAAUF;QAE9B,MAAMI,8BAA8B;YAChC,SAAS,IAAI,CAAC,UAAU;YACxBT;YACA,QAAQK;YACR,OAAOH;YACP,gBAAgBE,SAAS;QAC7B;QAEA,MAAMM,SAAS,MAAMC,uBAA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;YACpCD;YACAP;YACAP;YACA,QAAQqB,UAAU;gBACd,OAAO9B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACH2B;YACA,OAAO;gBACH,GAAG5B,QAAQ;gBACX,QAAQ+B,gBAAgBtB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMuB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBzC;IAChB,cAAc;QAAC0C;QAAYC;QAAiBC;QAAeC;KAAoB;AACnF"}
@@ -2,10 +2,12 @@ import { type IUpdateEntryDataFactory, type IUpdateEntryDataResponse } from "./a
2
2
  import { CmsContext } from "../../../../features/shared/abstractions.js";
3
3
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
4
  import type { CmsEntry, CmsEntryValues, CmsModel, UpdateCmsEntryInput, UpdateCmsEntryOptionsInput } from "../../../../types/index.js";
5
+ import { ModelToAstConverter } from "../../../../features/contentModel/ModelToAstConverter/abstractions.js";
5
6
  declare class UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {
6
7
  private readonly cmsContext;
7
8
  private readonly identityContext;
8
- constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface);
9
+ private readonly modelToAstConverter;
10
+ constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, modelToAstConverter: ModelToAstConverter.Interface);
9
11
  create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, rawInput: UpdateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: UpdateCmsEntryOptionsInput): Promise<IUpdateEntryDataResponse<TValues>>;
10
12
  }
11
13
  export declare const UpdateEntryDataFactory: import("@webiny/di").Implementation<typeof UpdateEntryDataFactoryImpl>;
@@ -9,6 +9,8 @@ import { referenceFieldsMapping } from "../../../../crud/contentEntry/referenceF
9
9
  import { mapAndCleanUpdatedInputData } from "../mapAndCleanUpdatedInputData.js";
10
10
  import { getSystem } from "../system.js";
11
11
  import { getExpiresAt } from "../expiresAt.js";
12
+ import { ModelToAstConverter } from "../../../contentModel/ModelToAstConverter/abstractions.js";
13
+ import { ensureItemIds } from "../../ensureItemIds.js";
12
14
  const allowedEntryStatus = [
13
15
  "draft",
14
16
  "published",
@@ -16,9 +18,10 @@ const allowedEntryStatus = [
16
18
  ];
17
19
  const transformEntryStatus = (status)=>allowedEntryStatus.includes(status) ? status : "draft";
18
20
  class UpdateEntryDataFactoryImpl {
19
- constructor(cmsContext, identityContext){
21
+ constructor(cmsContext, identityContext, modelToAstConverter){
20
22
  this.cmsContext = cmsContext;
21
23
  this.identityContext = identityContext;
24
+ this.modelToAstConverter = modelToAstConverter;
22
25
  }
23
26
  async create(model, rawInput, originalEntry, options) {
24
27
  const cleanedValues = mapAndCleanUpdatedInputData(model, rawInput?.values || {});
@@ -27,12 +30,14 @@ class UpdateEntryDataFactoryImpl {
27
30
  model,
28
31
  values: cleanedValues,
29
32
  entry: originalEntry,
30
- skipValidators: options?.skipValidators
33
+ skipValidation: options?.skipValidation
31
34
  });
32
35
  const mergedValues = {
33
36
  ...originalEntry.values,
34
37
  ...cleanedValues
35
38
  };
39
+ const modelAst = this.modelToAstConverter.toAst(model);
40
+ await ensureItemIds(modelAst, mergedValues);
36
41
  const values = await referenceFieldsMapping({
37
42
  context: this.cmsContext,
38
43
  model,
@@ -100,7 +105,8 @@ const UpdateEntryDataFactory_UpdateEntryDataFactory = createImplementation({
100
105
  implementation: UpdateEntryDataFactoryImpl,
101
106
  dependencies: [
102
107
  CmsContext,
103
- IdentityContext
108
+ IdentityContext,
109
+ ModelToAstConverter
104
110
  ]
105
111
  });
106
112
  export { UpdateEntryDataFactory_UpdateEntryDataFactory as UpdateEntryDataFactory };
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n type IUpdateEntryDataResponse,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>> {\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, currentIdentity),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionSavedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, originalEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),\n createdBy: getIdentity(rawInput.createdBy, originalEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n originalEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, originalEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","model","rawInput","originalEntry","options","cleanedValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","mergedValues","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext"],"mappings":";;;;;;;;;;;AAwBA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBAAmB,QAAQ,CAACE,UAAWA,SAA4B;AAG9E,MAAMC;IACF,YACqBC,UAAgC,EAChCC,eAA0C,CAC7D;aAFmBD,UAAU,GAAVA;aACAC,eAAe,GAAfA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAoC,EACM;QA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ASY,QAAQb,SAAS,OAAO,EAAEU;YACnC,YAAYG,QAAQb,SAAS,UAAU,EAAEU;YACzC,WAAWG,QAAQb,SAAS,SAAS,EAAE;YACvC,YAAYa,QAAQb,SAAS,UAAU,EAAE;YACzC,kBAAkBa,QAAQb,SAAS,gBAAgB,EAAEC,cAAc,gBAAgB;YACnF,iBAAiBY,QAAQb,SAAS,eAAe,EAAEC,cAAc,eAAe;YAChF,WAAWa,YAAYd,SAAS,SAAS,EAAEC,cAAc,SAAS;YAClE,SAASa,YAAYd,SAAS,OAAO,EAAES;YACvC,YAAYK,YAAYd,SAAS,UAAU,EAAES;YAC7C,WAAWK,YAAYd,SAAS,SAAS,EAAE;YAC3C,YAAYc,YAAYd,SAAS,UAAU,EAAE;YAC7C,kBAAkBc,YACdd,SAAS,gBAAgB,EACzBC,cAAc,gBAAgB;YAElC,iBAAiBa,YAAYd,SAAS,eAAe,EAAEC,cAAc,eAAe;YACpFM;YACA,QAAQb,qBAAqBO,cAAc,MAAM;YACjD,QAAQc,UAAU;gBACd,OAAOf;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAWe,aAAa;gBAAE,WAAWhB,SAAS,SAAS;YAAC,GAAGC;QAC/D;QAEA,MAAMgB,WAAWjB,SAAS,eAAe,EAAE;QAC3C,IAAIiB,UACAL,MAAM,QAAQ,GAAG;YACbK;QACJ;QAGJ,OAAO;YACHL;YACA,OAAO;gBACH,GAAGZ,QAAQ;gBACX,QAAQkB,gBAAgBX;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMY,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBzB;IAChB,cAAc;QAAC0B;QAAYC;KAAgB;AAC/C"}
1
+ {"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n type IUpdateEntryDataResponse,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>> {\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, mergedValues);\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, currentIdentity),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionSavedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, originalEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),\n createdBy: getIdentity(rawInput.createdBy, originalEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n originalEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, originalEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, ModelToAstConverter]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","modelToAstConverter","model","rawInput","originalEntry","options","cleanedValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","mergedValues","modelAst","ensureItemIds","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","ModelToAstConverter"],"mappings":";;;;;;;;;;;;;AA0BA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,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AAO;YACHL;YACA,OAAO;gBACH,GAAGd,QAAQ;gBACX,QAAQoB,gBAAgBX;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMY,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAYC;QAAiBC;KAAoB;AACpE"}
@@ -1,7 +1,7 @@
1
1
  const getExpiresAt = (input, original)=>{
2
2
  if (void 0 === input.expiresAt) return original?.expiresAt ?? null;
3
- else if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
4
- else if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
3
+ if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
4
+ if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
5
5
  return null;
6
6
  };
7
7
  export { getExpiresAt };
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;SAC3B,IAAID,MAAM,SAAS,YAAYG,MAClC,OAAOH,MAAM,SAAS,CAAC,OAAO,KAAK;SAChC,IACH,AAA2B,YAA3B,OAAOA,MAAM,SAAS,IACtB,CAACI,MAAMJ,MAAM,SAAS,KACtBA,MAAM,SAAS,GAAG,GAElB,OAAOA,MAAM,SAAS;IAE1B,OAAO;AACX"}
1
+ {"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;IAC3B,IAAID,MAAM,SAAS,YAAYG,MAClC,OAAOH,MAAM,SAAS,CAAC,OAAO,KAAK;IAChC,IACH,AAA2B,YAA3B,OAAOA,MAAM,SAAS,IACtB,CAACI,MAAMJ,MAAM,SAAS,KACtBA,MAAM,SAAS,GAAG,GAElB,OAAOA,MAAM,SAAS;IAE1B,OAAO;AACX"}
@@ -0,0 +1,14 @@
1
+ import { type IComponentMapGenerator } from "./abstractions.js";
2
+ import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
3
+ import type { CmsModel } from "../../../types/index.js";
4
+ declare class ComponentMapGeneratorImpl implements IComponentMapGenerator {
5
+ private readonly modelToAst;
6
+ constructor(modelToAst: ModelToAstConverter.Interface);
7
+ generate(model: CmsModel): Record<string, string>;
8
+ private walkNode;
9
+ private walkCollection;
10
+ }
11
+ export declare const ComponentMapGenerator: typeof ComponentMapGeneratorImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<IComponentMapGenerator>;
13
+ };
14
+ export {};
@@ -0,0 +1,32 @@
1
+ import { ComponentMapGenerator } from "./abstractions.js";
2
+ import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
3
+ class ComponentMapGeneratorImpl {
4
+ constructor(modelToAst){
5
+ this.modelToAst = modelToAst;
6
+ }
7
+ generate(model) {
8
+ const ast = this.modelToAst.toAst(model);
9
+ const map = {};
10
+ this.walkNode(ast, map);
11
+ return map;
12
+ }
13
+ walkNode(node, map) {
14
+ for (const child of node.children)if ("collection" === child.type) this.walkCollection(child, map);
15
+ else this.walkNode(child, map);
16
+ }
17
+ walkCollection(node, map) {
18
+ const { collection } = node;
19
+ if (collection.componentName && collection.id) map[collection.id] = collection.componentName;
20
+ for (const child of node.children)if ("collection" === child.type) this.walkCollection(child, map);
21
+ else this.walkNode(child, map);
22
+ }
23
+ }
24
+ const ComponentMapGenerator_ComponentMapGenerator = ComponentMapGenerator.createImplementation({
25
+ implementation: ComponentMapGeneratorImpl,
26
+ dependencies: [
27
+ ModelToAstConverter
28
+ ]
29
+ });
30
+ export { ComponentMapGenerator_ComponentMapGenerator as ComponentMapGenerator };
31
+
32
+ //# sourceMappingURL=ComponentMapGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js","sources":["../../../../src/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.ts"],"sourcesContent":["import {\n ComponentMapGenerator as Abstraction,\n type IComponentMapGenerator\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport type {\n CmsModel,\n CmsModelAst,\n CmsModelFieldAstNode,\n CmsModelFieldAstNodeCollection\n} from \"~/types/index.js\";\n\nclass ComponentMapGeneratorImpl implements IComponentMapGenerator {\n constructor(private readonly modelToAst: ModelToAstConverter.Interface) {}\n\n generate(model: CmsModel): Record<string, string> {\n const ast = this.modelToAst.toAst(model);\n const map: Record<string, string> = {};\n this.walkNode(ast, map);\n return map;\n }\n\n private walkNode(node: CmsModelAst | CmsModelFieldAstNode, map: Record<string, string>) {\n for (const child of node.children) {\n if (child.type === \"collection\") {\n this.walkCollection(child, map);\n } else {\n this.walkNode(child, map);\n }\n }\n }\n\n private walkCollection(node: CmsModelFieldAstNodeCollection, map: Record<string, string>) {\n const { collection } = node;\n if (collection.componentName && collection.id) {\n map[collection.id] = collection.componentName;\n }\n\n for (const child of node.children) {\n if (child.type === \"collection\") {\n this.walkCollection(child, map);\n } else {\n this.walkNode(child, map);\n }\n }\n }\n}\n\nexport const ComponentMapGenerator = Abstraction.createImplementation({\n implementation: ComponentMapGeneratorImpl,\n dependencies: [ModelToAstConverter]\n});\n"],"names":["ComponentMapGeneratorImpl","modelToAst","model","ast","map","node","child","collection","ComponentMapGenerator","Abstraction","ModelToAstConverter"],"mappings":";;AAYA,MAAMA;IACF,YAA6BC,UAAyC,CAAE;aAA3CA,UAAU,GAAVA;IAA4C;IAEzE,SAASC,KAAe,EAA0B;QAC9C,MAAMC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD;QAClC,MAAME,MAA8B,CAAC;QACrC,IAAI,CAAC,QAAQ,CAACD,KAAKC;QACnB,OAAOA;IACX;IAEQ,SAASC,IAAwC,EAAED,GAA2B,EAAE;QACpF,KAAK,MAAME,SAASD,KAAK,QAAQ,CAC7B,IAAIC,AAAe,iBAAfA,MAAM,IAAI,EACV,IAAI,CAAC,cAAc,CAACA,OAAOF;aAE3B,IAAI,CAAC,QAAQ,CAACE,OAAOF;IAGjC;IAEQ,eAAeC,IAAoC,EAAED,GAA2B,EAAE;QACtF,MAAM,EAAEG,UAAU,EAAE,GAAGF;QACvB,IAAIE,WAAW,aAAa,IAAIA,WAAW,EAAE,EACzCH,GAAG,CAACG,WAAW,EAAE,CAAC,GAAGA,WAAW,aAAa;QAGjD,KAAK,MAAMD,SAASD,KAAK,QAAQ,CAC7B,IAAIC,AAAe,iBAAfA,MAAM,IAAI,EACV,IAAI,CAAC,cAAc,CAACA,OAAOF;aAE3B,IAAI,CAAC,QAAQ,CAACE,OAAOF;IAGjC;AACJ;AAEO,MAAMI,8CAAwBC,sBAAAA,oBAAgC,CAAC;IAClE,gBAAgBT;IAChB,cAAc;QAACU;KAAoB;AACvC"}
@@ -0,0 +1,8 @@
1
+ import type { CmsModel } from "../../../types/index.js";
2
+ export interface IComponentMapGenerator {
3
+ generate(model: CmsModel): Record<string, string>;
4
+ }
5
+ export declare const ComponentMapGenerator: import("@webiny/di").Abstraction<IComponentMapGenerator>;
6
+ export declare namespace ComponentMapGenerator {
7
+ type Interface = IComponentMapGenerator;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ComponentMapGenerator = createAbstraction("ComponentMapGenerator");
3
+ export { ComponentMapGenerator };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentModel/ComponentMapGenerator/abstractions.js","sources":["../../../../src/features/contentModel/ComponentMapGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"~/types/index.js\";\n\nexport interface IComponentMapGenerator {\n generate(model: CmsModel): Record<string, string>;\n}\n\nexport const ComponentMapGenerator =\n createAbstraction<IComponentMapGenerator>(\"ComponentMapGenerator\");\n\nexport namespace ComponentMapGenerator {\n export type Interface = IComponentMapGenerator;\n}\n"],"names":["ComponentMapGenerator","createAbstraction"],"mappings":";AAOO,MAAMA,wBACTC,kBAA0C"}
@@ -0,0 +1,4 @@
1
+ export declare const ComponentMapGeneratorFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ComponentMapGenerator } from "./ComponentMapGenerator.js";
3
+ const ComponentMapGeneratorFeature = createFeature({
4
+ name: "CmsContentModel/ComponentMapGenerator",
5
+ register (container) {
6
+ container.register(ComponentMapGenerator);
7
+ }
8
+ });
9
+ export { ComponentMapGeneratorFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentModel/ComponentMapGenerator/feature.js","sources":["../../../../src/features/contentModel/ComponentMapGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ComponentMapGenerator } from \"./ComponentMapGenerator.js\";\n\nexport const ComponentMapGeneratorFeature = createFeature({\n name: \"CmsContentModel/ComponentMapGenerator\",\n register(container) {\n container.register(ComponentMapGenerator);\n }\n});\n"],"names":["ComponentMapGeneratorFeature","createFeature","container","ComponentMapGenerator"],"mappings":";;AAGO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { ComponentMapGenerator } from "./abstractions.js";
2
+ export { ComponentMapGeneratorFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { ComponentMapGenerator } from "./abstractions.js";
2
+ export { ComponentMapGeneratorFeature } from "./feature.js";
@@ -10,6 +10,9 @@ import { DeleteModelFeature } from "./DeleteModel/feature.js";
10
10
  import { GetModelFeature } from "./GetModel/feature.js";
11
11
  import { ListModelsFeature } from "./ListModels/feature.js";
12
12
  import { ModelToAstConverterFeature } from "./ModelToAstConverter/feature.js";
13
+ import { ValuesSelectionGeneratorFeature } from "./ValuesSelectionGenerator/feature.js";
14
+ import { ComponentMapGeneratorFeature } from "./ComponentMapGenerator/feature.js";
15
+ import { RefModelsGeneratorFeature } from "./RefModelsGenerator/feature.js";
13
16
  import { ModelFieldCompressionFeature } from "./ModelFieldCompression/feature.js";
14
17
  const ContentModelFeature = createFeature({
15
18
  name: "ContentModel",
@@ -18,6 +21,9 @@ const ContentModelFeature = createFeature({
18
21
  container.register(PluginModelsProvider).inSingletonScope();
19
22
  container.register(ModelsFetcher).inSingletonScope();
20
23
  ModelToAstConverterFeature.register(container);
24
+ ValuesSelectionGeneratorFeature.register(container);
25
+ ComponentMapGeneratorFeature.register(container);
26
+ RefModelsGeneratorFeature.register(container);
21
27
  ModelFieldCompressionFeature.register(container);
22
28
  GetModelFeature.register(container);
23
29
  ListModelsFeature.register(container);
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModel/ContentModelFeature.js","sources":["../../../src/features/contentModel/ContentModelFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport { PluginModelsProvider } from \"./shared/PluginModelsProvider.js\";\nimport { ModelCache } from \"./shared/abstractions.js\";\nimport { ModelsFetcher } from \"./shared/ModelsFetcher.js\";\nimport { CreateModelFeature } from \"./CreateModel/feature.js\";\nimport { CreateModelFromFeature } from \"./CreateModelFrom/feature.js\";\nimport { UpdateModelFeature } from \"./UpdateModel/feature.js\";\nimport { DeleteModelFeature } from \"./DeleteModel/feature.js\";\nimport { GetModelFeature } from \"./GetModel/feature.js\";\nimport { ListModelsFeature } from \"./ListModels/feature.js\";\nimport { ModelToAstConverterFeature } from \"./ModelToAstConverter/feature.js\";\nimport { ModelFieldCompressionFeature } from \"./ModelFieldCompression/feature.js\";\n\nexport const ContentModelFeature = createFeature({\n name: \"ContentModel\",\n register(container) {\n container.registerInstance(ModelCache, createMemoryCache());\n container.register(PluginModelsProvider).inSingletonScope();\n container.register(ModelsFetcher).inSingletonScope();\n\n ModelToAstConverterFeature.register(container);\n\n ModelFieldCompressionFeature.register(container);\n\n // Query features\n GetModelFeature.register(container);\n ListModelsFeature.register(container);\n\n // Command features\n CreateModelFeature.register(container);\n CreateModelFromFeature.register(container);\n UpdateModelFeature.register(container);\n DeleteModelFeature.register(container);\n }\n});\n"],"names":["ContentModelFeature","createFeature","container","ModelCache","createMemoryCache","PluginModelsProvider","ModelsFetcher","ModelToAstConverterFeature","ModelFieldCompressionFeature","GetModelFeature","ListModelsFeature","CreateModelFeature","CreateModelFromFeature","UpdateModelFeature","DeleteModelFeature"],"mappings":";;;;;;;;;;;;;AAcO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,gBAAgB,CAACC,YAAYC;QACvCF,UAAU,QAAQ,CAACG,sBAAsB,gBAAgB;QACzDH,UAAU,QAAQ,CAACI,eAAe,gBAAgB;QAElDC,2BAA2B,QAAQ,CAACL;QAEpCM,6BAA6B,QAAQ,CAACN;QAGtCO,gBAAgB,QAAQ,CAACP;QACzBQ,kBAAkB,QAAQ,CAACR;QAG3BS,mBAAmB,QAAQ,CAACT;QAC5BU,uBAAuB,QAAQ,CAACV;QAChCW,mBAAmB,QAAQ,CAACX;QAC5BY,mBAAmB,QAAQ,CAACZ;IAChC;AACJ"}
1
+ {"version":3,"file":"features/contentModel/ContentModelFeature.js","sources":["../../../src/features/contentModel/ContentModelFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport { PluginModelsProvider } from \"./shared/PluginModelsProvider.js\";\nimport { ModelCache } from \"./shared/abstractions.js\";\nimport { ModelsFetcher } from \"./shared/ModelsFetcher.js\";\nimport { CreateModelFeature } from \"./CreateModel/feature.js\";\nimport { CreateModelFromFeature } from \"./CreateModelFrom/feature.js\";\nimport { UpdateModelFeature } from \"./UpdateModel/feature.js\";\nimport { DeleteModelFeature } from \"./DeleteModel/feature.js\";\nimport { GetModelFeature } from \"./GetModel/feature.js\";\nimport { ListModelsFeature } from \"./ListModels/feature.js\";\nimport { ModelToAstConverterFeature } from \"./ModelToAstConverter/feature.js\";\nimport { ValuesSelectionGeneratorFeature } from \"./ValuesSelectionGenerator/feature.js\";\nimport { ComponentMapGeneratorFeature } from \"./ComponentMapGenerator/feature.js\";\nimport { RefModelsGeneratorFeature } from \"./RefModelsGenerator/feature.js\";\nimport { ModelFieldCompressionFeature } from \"./ModelFieldCompression/feature.js\";\n\nexport const ContentModelFeature = createFeature({\n name: \"ContentModel\",\n register(container) {\n container.registerInstance(ModelCache, createMemoryCache());\n container.register(PluginModelsProvider).inSingletonScope();\n container.register(ModelsFetcher).inSingletonScope();\n\n ModelToAstConverterFeature.register(container);\n ValuesSelectionGeneratorFeature.register(container);\n ComponentMapGeneratorFeature.register(container);\n RefModelsGeneratorFeature.register(container);\n\n ModelFieldCompressionFeature.register(container);\n\n // Query features\n GetModelFeature.register(container);\n ListModelsFeature.register(container);\n\n // Command features\n CreateModelFeature.register(container);\n CreateModelFromFeature.register(container);\n UpdateModelFeature.register(container);\n DeleteModelFeature.register(container);\n }\n});\n"],"names":["ContentModelFeature","createFeature","container","ModelCache","createMemoryCache","PluginModelsProvider","ModelsFetcher","ModelToAstConverterFeature","ValuesSelectionGeneratorFeature","ComponentMapGeneratorFeature","RefModelsGeneratorFeature","ModelFieldCompressionFeature","GetModelFeature","ListModelsFeature","CreateModelFeature","CreateModelFromFeature","UpdateModelFeature","DeleteModelFeature"],"mappings":";;;;;;;;;;;;;;;;AAiBO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,gBAAgB,CAACC,YAAYC;QACvCF,UAAU,QAAQ,CAACG,sBAAsB,gBAAgB;QACzDH,UAAU,QAAQ,CAACI,eAAe,gBAAgB;QAElDC,2BAA2B,QAAQ,CAACL;QACpCM,gCAAgC,QAAQ,CAACN;QACzCO,6BAA6B,QAAQ,CAACP;QACtCQ,0BAA0B,QAAQ,CAACR;QAEnCS,6BAA6B,QAAQ,CAACT;QAGtCU,gBAAgB,QAAQ,CAACV;QACzBW,kBAAkB,QAAQ,CAACX;QAG3BY,mBAAmB,QAAQ,CAACZ;QAC5Ba,uBAAuB,QAAQ,CAACb;QAChCc,mBAAmB,QAAQ,CAACd;QAC5Be,mBAAmB,QAAQ,CAACf;IAChC;AACJ"}
@@ -21,7 +21,8 @@ const getModelId = (model)=>{
21
21
  const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();
22
22
  if (isModelIdValid) return value;
23
23
  return camelCase(value);
24
- } else if (name) return camelCase(name.trim());
24
+ }
25
+ if (name) return camelCase(name.trim());
25
26
  throw new ModelValidationError('There is no "modelId" or "name" passed into the create model method.');
26
27
  };
27
28
  class CreateModelRepositoryImpl {
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModel/CreateModel/CreateModelRepository.js","sources":["../../../../src/features/contentModel/CreateModel/CreateModelRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ModelCache, PluginModelsProvider } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`\n );\n};\n\n/**\n * CreateModelRepository - Validates domain rules and persists a new model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly listModelsUseCase: ListModelsUseCase.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // TODO: this will eventually become part of the Model domain object.\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return pm.modelId === model.modelId;\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n // Get all models for further validation\n const modelsResult = await this.listModelsUseCase.execute();\n\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const models = modelsResult.value;\n\n try {\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // TODO: ideally, this will eventually be handled by the Model domain object\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n console.error(error, error.stack);\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ListModelsUseCase,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelRepositoryImpl","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","pluginModels","pluginModelConflict","pm","ModelAlreadyExistsError","modelsResult","ModelPersistenceError","models","existingModel","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","console","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","StorageOperations","Tenant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EAAE,OAAOmB,OAAO;YACZiB,QAAQ,KAAK,CAACjB,OAAOA,MAAM,KAAK;YAChC,OAAOC,OAAO,IAAI,CAAC,IAAIO,sBAAsBR;QACjD;IACJ;AACJ;AAEO,MAAMkB,8CAAwBC,sBAAAA,oBAA0C,CAAC;IAC5E,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModel/CreateModel/CreateModelRepository.js","sources":["../../../../src/features/contentModel/CreateModel/CreateModelRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ModelCache, PluginModelsProvider } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`\n );\n};\n\n/**\n * CreateModelRepository - Validates domain rules and persists a new model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly listModelsUseCase: ListModelsUseCase.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // TODO: this will eventually become part of the Model domain object.\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return pm.modelId === model.modelId;\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n // Get all models for further validation\n const modelsResult = await this.listModelsUseCase.execute();\n\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const models = modelsResult.value;\n\n try {\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // TODO: ideally, this will eventually be handled by the Model domain object\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n console.error(error, error.stack);\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ListModelsUseCase,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelRepositoryImpl","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","pluginModels","pluginModelConflict","pm","ModelAlreadyExistsError","modelsResult","ModelPersistenceError","models","existingModel","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","console","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,aAAa,CAACC;IAChB,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGF;IAC1B,MAAMG,QAAQF,UAAUA,QAAQ,IAAI,KAAK;IACzC,IAAIE,OAAO;QACP,MAAMC,iBAAiBC,UAAUF,OAAO,WAAW,OAAOA,MAAM,WAAW;QAC3E,IAAIC,gBACA,OAAOD;QAEX,OAAOE,UAAUF;IACrB;IAAO,IAAID,MACP,OAAOG,UAAUH,KAAK,IAAI;IAE9B,MAAM,IAAII,qBACN;AAER;AAgBA,MAAMC;IACF,YACqBC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,iBAA8C,EAC9CC,aAAsC,EACtCC,UAAgC,EAChCC,qBAAsD,EACtDC,aAAsC,CACzD;aARmBP,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,qBAAqB,GAArBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMhB,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACgB;QACxC,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMhB,UAAUF,WAAWC;YAC3BA,MAAM,OAAO,GAAGC;YAGhB,IAAI;gBACAiB,uBAAuB;oBAAElB;gBAAM;YACnC,EAAE,OAAOmB,OAAO;gBACZ,OAAOC,OAAO,IAAI,CACd,IAAId,qBAAqB;oBACrB,SAASa,MAAM,OAAO;oBACtB,MAAMA,MAAM,IAAI;gBACpB;YAER;YAGA,IAAI;gBACAE,sBAAsB;oBAAErB;gBAAM;YAClC,EAAE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,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOf,OAAO,EAAE,CAACpB;QACrB,EAAE,OAAOmB,OAAO;YACZiB,QAAQ,KAAK,CAACjB,OAAOA,MAAM,KAAK;YAChC,OAAOC,OAAO,IAAI,CAAC,IAAIO,sBAAsBR;QACjD;IACJ;AACJ;AAEO,MAAMkB,8CAAwBC,sBAAAA,oBAA0C,CAAC;IAC5E,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -20,7 +20,8 @@ const getModelId = (model)=>{
20
20
  const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();
21
21
  if (isModelIdValid) return value;
22
22
  return camelCase(value);
23
- } else if (name) return camelCase(name.trim());
23
+ }
24
+ if (name) return camelCase(name.trim());
24
25
  throw new ModelValidationError('There is no "modelId" or "name" passed into the create model from method.');
25
26
  };
26
27
  class CreateModelFromRepositoryImpl {
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromRepository.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n ModelCache,\n ModelsFetcher,\n PluginModelsProvider\n} from \"~/features/contentModel/shared/abstractions.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelFromRepositoryImpl","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","modelsResult","ModelPersistenceError","existingModel","m","ModelAlreadyExistsError","pluginModels","pluginModelConflict","pm","models","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","CreateModelFromRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ModelsFetcher","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAMA,aAAa,CAACC;IAChB,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGF;IAC1B,MAAMG,QAAQF,UAAUA,QAAQ,IAAI,KAAK;IACzC,IAAIE,OAAO;QACP,MAAMC,iBAAiBC,UAAUF,OAAO,WAAW,OAAOA,MAAM,WAAW;QAC3E,IAAIC,gBACA,OAAOD;QAEX,OAAOE,UAAUF;IACrB,OAAO,IAAID,MACP,OAAOG,UAAUH,KAAK,IAAI;IAE9B,MAAM,IAAII,qBACN;AAER;AAgBA,MAAMC;IACF,YACqBC,UAAgC,EAChCC,oBAAoD,EACpDC,aAAsC,EACtCC,iBAA8C,EAC9CC,aAAsC,EACtCC,UAAgC,EAChCC,qBAAsD,EACtDC,aAAsC,CACzD;aARmBP,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,aAAa,GAAbA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,qBAAqB,GAArBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAM,QAAQC,YAAsB,EAA0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rE;YAIR,MAAM6B,SAASR,aAAa,KAAK;YAEjC,IAAI;gBAEA,KAAK,MAAME,iBAAiBM,OAAQ;oBAChCC,wBAAwB;wBACpBP;wBACAxB;oBACJ;oBACAgC,wBAAwB;wBACpBR;wBACAxB;oBACJ;oBACAiC,sBAAsB;wBAClBT;wBACAxB;oBACJ;gBACJ;gBAGA,MAAMkC,oBAAoB;oBACtBJ;oBACA9B;oBACA,SAAS,IAAI,CAAC,UAAU;gBAC5B;YACJ,EAAE,OAAOmB,OAAO;gBACZ,OAAOC,OAAO,IAAI,CACd,IAAId,qBAAqB;oBAAE,SAASa,MAAM,OAAO;oBAAE,MAAMA,MAAM,IAAI;gBAAC;YAE5E;YAGAnB,MAAM,IAAI,GAAGmC,cAAcnC;YAE3B,MAAMoC,SAAS,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAACpC,MAAM,MAAM;YAGrE,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBACvC,OAAO;oBACH,GAAGA,KAAK;oBACRoC;gBACJ;YACJ;YAGA,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOhB,OAAO,EAAE,CAACpB;QACrB,EAAE,OAAOmB,OAAO;YACZ,OAAOC,OAAO,IAAI,CAAC,IAAIG,sBAAsBJ;QACjD;IACJ;AACJ;AAEO,MAAMkB,sDAA4BC,0BAAAA,oBAA0C,CAAC;IAChF,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromRepository.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n ModelCache,\n ModelsFetcher,\n PluginModelsProvider\n} from \"~/features/contentModel/shared/abstractions.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelFromRepositoryImpl","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","modelsResult","ModelPersistenceError","existingModel","m","ModelAlreadyExistsError","pluginModels","pluginModelConflict","pm","models","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","CreateModelFromRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ModelsFetcher","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAMA,aAAa,CAACC;IAChB,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGF;IAC1B,MAAMG,QAAQF,UAAUA,QAAQ,IAAI,KAAK;IACzC,IAAIE,OAAO;QACP,MAAMC,iBAAiBC,UAAUF,OAAO,WAAW,OAAOA,MAAM,WAAW;QAC3E,IAAIC,gBACA,OAAOD;QAEX,OAAOE,UAAUF;IACrB;IAAO,IAAID,MACP,OAAOG,UAAUH,KAAK,IAAI;IAE9B,MAAM,IAAII,qB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AC;IAChF,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -0,0 +1,19 @@
1
+ import { type IRefModelsGenerator, type RefModelMetadata } from "./abstractions.js";
2
+ import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
3
+ import { ValuesSelectionGenerator } from "../ValuesSelectionGenerator/abstractions.js";
4
+ import { ModelsFetcher } from "../shared/abstractions.js";
5
+ import type { CmsModel } from "../../../types/index.js";
6
+ declare class RefModelsGeneratorImpl implements IRefModelsGenerator {
7
+ private readonly modelToAst;
8
+ private readonly modelsFetcher;
9
+ private readonly valuesSelectionGenerator;
10
+ constructor(modelToAst: ModelToAstConverter.Interface, modelsFetcher: ModelsFetcher.Interface, valuesSelectionGenerator: ValuesSelectionGenerator.Interface);
11
+ generate(model: CmsModel): Promise<Record<string, RefModelMetadata>>;
12
+ private collectRefModelIds;
13
+ private collectFromFieldNode;
14
+ private collectFromCollectionNode;
15
+ }
16
+ export declare const RefModelsGenerator: typeof RefModelsGeneratorImpl & {
17
+ __abstraction: import("@webiny/di").Abstraction<IRefModelsGenerator>;
18
+ };
19
+ export {};